bring back support for loading progress

This commit is contained in:
Sebastian Krzyszkowiak 2012-12-28 00:00:37 +01:00
parent 3d44b4abbf
commit b39ec719be
7 changed files with 82 additions and 13 deletions

View file

@ -24,7 +24,7 @@
#include "../utils.h"
#include "about.h"
int Gamestate_ProgressCount = 0;
int Gamestate_ProgressCount = 7;
void Gamestate_Logic(struct Game *game, struct AboutResources* data) {
if (al_get_sample_instance_position(data->music)<700000) { return; }
@ -75,16 +75,21 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game *game)) {
struct AboutResources *data = malloc(sizeof(struct AboutResources));
data->image =LoadScaledBitmap(game, "table.png", game->viewport.width, game->viewport.height);
(*progress)(game);
data->letter = LoadScaledBitmap(game, "about/letter.png", game->viewport.height*1.3, game->viewport.height*1.3 );
(*progress)(game);
data->sample = al_load_sample( GetDataFilePath("about/about.flac") );
(*progress)(game);
data->music = al_create_sample_instance(data->sample);
al_attach_sample_instance_to_mixer(data->music, game->audio.music);
al_set_sample_instance_playmode(data->music, ALLEGRO_PLAYMODE_LOOP);
al_set_sample_instance_position(data->music, game->config.music ? 420000 : 700000);
(*progress)(game);
data->font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.035,0 );
(*progress)(game);
data->x = -0.1;
if (!data->sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
@ -95,7 +100,8 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game *game)) {
al_clear_to_color(al_map_rgba(0,0,0,0));
al_draw_text(data->font, al_map_rgb(0,0,0), 0.5*al_get_bitmap_width(data->text_bitmap), 0.015*al_get_bitmap_height(data->text_bitmap), ALLEGRO_ALIGN_CENTRE, "Super Derpy: Muffin Attack");
al_draw_text(data->font, al_map_rgb(0,0,0), 0.5*al_get_bitmap_width(data->text_bitmap), 0.035*al_get_bitmap_height(data->text_bitmap), ALLEGRO_ALIGN_CENTRE, "Version 0.1a (Development Preview)");
(*progress)(game);
float y=0.07;
void draw_text(char* text) {
al_draw_text(data->font, al_map_rgb(0,0,0), 0, y*al_get_bitmap_height(data->text_bitmap), ALLEGRO_ALIGN_LEFT, text);
@ -182,6 +188,7 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game *game)) {
draw_text("or its associates.");
draw_text("");
draw_text("http://www.superderpy.com/");
(*progress)(game);
al_set_target_backbuffer(game->display);
return data;

View file

@ -23,7 +23,7 @@
#include "../utils.h"
#include "disclaimer.h"
int Gamestate_ProgressCount = 0;
int Gamestate_ProgressCount = 2;
void Gamestate_Logic(struct Game *game, struct DisclaimerResources* data) {}
@ -49,8 +49,9 @@ void Gamestate_ProcessEvent(struct Game *game, struct DisclaimerResources* data,
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
struct DisclaimerResources *data = malloc(sizeof(struct DisclaimerResources));
data->font_small = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.05,0 );
(*progress)(game);
data->font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.065,0 );
if (progress) (*progress)(game);
(*progress)(game);
return data;
}

View file

@ -24,7 +24,7 @@
#include "../utils.h"
#include "intro.h"
int Gamestate_ProgressCount = 0;
int Gamestate_ProgressCount = 11;
void AnimPage(struct Game *game, struct IntroResources *data, int page, ALLEGRO_COLOR tint) {
int offset = 0;
@ -216,28 +216,39 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
struct IntroResources *data = malloc(sizeof(struct IntroResources));
data->animsprites[0] = LoadScaledBitmap(game, "intro/1.png", (int)(game->viewport.height*1.6*0.3125)*2, game->viewport.height*0.63*2);
(*progress)(game);
data->animsprites[1] = LoadScaledBitmap(game, "intro/2.png", (int)(game->viewport.height*1.7*0.3125)*4, game->viewport.height*0.47*3);
(*progress)(game);
data->animsprites[2] = LoadScaledBitmap(game, "intro/3.png", (int)(game->viewport.height*1.6*0.3125)*3, game->viewport.height*0.63*3);
(*progress)(game);
data->animsprites[3] = LoadScaledBitmap(game, "intro/4.png", (int)(game->viewport.height*1.6*0.3125)*2, game->viewport.height*0.63*2);
(*progress)(game);
data->animsprites[4] = LoadScaledBitmap(game, "intro/5.png", (int)(game->viewport.height*1.6*0.3125)*5, game->viewport.height*0.63*3);
(*progress)(game);
data->table_bitmap =LoadScaledBitmap(game, "intro/paper.png", game->viewport.width, game->viewport.height);
(*progress)(game);
data->frame =LoadScaledBitmap(game, "intro/frame.png", game->viewport.width, game->viewport.height);
(*progress)(game);
data->sample = al_load_sample( GetDataFilePath("intro/intro.flac") );
(*progress)(game);
data->music = al_create_sample_instance(data->sample);
al_attach_sample_instance_to_mixer(data->music, game->audio.music);
al_set_sample_instance_gain(data->music, 0.75);
al_set_sample_instance_playmode(data->music, ALLEGRO_PLAYMODE_LOOP);
(*progress)(game);
if (!data->sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
exit(-1);
}
data->table = al_create_bitmap(game->viewport.width*2, game->viewport.height);
(*progress)(game);
data->font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.04,0 );
(*progress)(game);
return data;
}

View file

@ -24,7 +24,7 @@
#include "../config.h"
#include "map.h"
int Gamestate_ProgressCount = 0;
int Gamestate_ProgressCount = 10;
void Gamestate_Draw(struct Game *game, struct MapResources* data) {
al_draw_bitmap(data->map, 0, 0, 0);
@ -101,24 +101,32 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
data->selected = data->available;
PrintConsole(game, "Last level available: %d", data->selected);
data->arrowpos = 0;
(*progress)(game);
data->map_bg = LoadScaledBitmap(game, "map/background.png", game->viewport.height*1.6, game->viewport.height);
(*progress)(game);
char filename[30] = { };
sprintf(filename, "map/highlight%d.png", data->available);
data->highlight = LoadScaledBitmap(game, filename, game->viewport.height*1.6, game->viewport.height);
(*progress)(game);
data->arrow = al_load_bitmap( GetDataFilePath("map/arrow.png") );
(*progress)(game);
data->click_sample = al_load_sample( GetDataFilePath("menu/click.flac") );
(*progress)(game);
data->sample = al_load_sample( GetDataFilePath("map/map.flac") );
(*progress)(game);
data->music = al_create_sample_instance(data->sample);
al_attach_sample_instance_to_mixer(data->music, game->audio.music);
al_set_sample_instance_playmode(data->music, ALLEGRO_PLAYMODE_LOOP);
(*progress)(game);
data->click = al_create_sample_instance(data->click_sample);
al_attach_sample_instance_to_mixer(data->click, game->audio.fx);
al_set_sample_instance_playmode(data->click, ALLEGRO_PLAYMODE_ONCE);
(*progress)(game);
if (!data->sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
@ -130,10 +138,12 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
}
data->map = LoadScaledBitmap(game, "table.png", game->viewport.width, game->viewport.height);
(*progress)(game);
al_set_target_bitmap(data->map);
al_draw_bitmap(data->map_bg, (game->viewport.width-game->viewport.height*1.6)/2, 0 ,0);
al_draw_bitmap(data->highlight, (game->viewport.width-game->viewport.height*1.6)/2, 0 ,0);
al_set_target_bitmap(al_get_backbuffer(game->display));
(*progress)(game);
return data;
}

View file

@ -25,7 +25,7 @@
#include "../utils.h"
#include "menu.h"
int Gamestate_ProgressCount = 0;
int Gamestate_ProgressCount = 24;
void DrawMenuState(struct Game *game, struct MenuResources *data) {
ALLEGRO_FONT *font;
@ -186,15 +186,20 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
data->options.fps = game->config.fps;
data->options.width = game->config.width;
data->options.height = game->config.height;
data->loaded = true;
(*progress)(game);
data->image = LoadScaledBitmap(game, "menu/menu.png", game->viewport.width, game->viewport.width*(1240.0/3910.0));
(*progress)(game);
data->mountain = LoadScaledBitmap(game, "menu/mountain.png", game->viewport.height*1.6*0.055, game->viewport.height/9 );
(*progress)(game);
data->cloud = LoadScaledBitmap(game, "menu/cloud.png", game->viewport.height*1.6*0.5, game->viewport.height*0.25 );
(*progress)(game);
data->cloud2 = LoadScaledBitmap(game, "menu/cloud2.png", game->viewport.height*1.6*0.2, game->viewport.height*0.1 );
(*progress)(game);
data->logo = LoadScaledBitmap(game, "menu/logo.png", game->viewport.height*1.6*0.3, game->viewport.height*0.35 );
data->blurbg = al_create_bitmap(game->viewport.height*1.6*0.3, game->viewport.height*0.35);
data->blurbg2 = al_create_bitmap(game->viewport.height*1.6*0.3, game->viewport.height*0.35);
data->logoblur = al_create_bitmap(game->viewport.height*1.6*0.3+4, game->viewport.height*0.35+4);
(*progress)(game);
al_set_target_bitmap(data->logoblur);
al_clear_to_color(al_map_rgba(0,0,0,0));
float alpha = (1.0/40.0);
@ -206,36 +211,52 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
al_draw_tinted_bitmap(data->logo, color, bx, by, 0);
}
}
(*progress)(game);
al_set_target_bitmap(al_get_backbuffer(game->display));
data->glass = LoadScaledBitmap(game, "menu/glass.png", game->viewport.height*1.6*0.3, game->viewport.height*0.35 );
(*progress)(game);
//data->pinkcloud = LoadScaledBitmap(game, "menu/pinkcloud.png", game->viewport.width*0.33125, game->viewport.height*0.8122);
data->pinkcloud = LoadScaledBitmap(game, "menu/pinkcloud.png", game->viewport.height*0.8122*(1171.0/2218.0), game->viewport.height*0.8122);
(*progress)(game);
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
data->rain = al_load_bitmap( GetDataFilePath("menu/rain.png") );
(*progress)(game);
data->pie = al_load_bitmap( GetDataFilePath("menu/pie.png") );
(*progress)(game);
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
data->sample = al_load_sample( GetDataFilePath("menu/menu.flac") );
(*progress)(game);
data->rain_sample = al_load_sample( GetDataFilePath("menu/rain.flac") );
(*progress)(game);
data->click_sample = al_load_sample( GetDataFilePath("menu/click.flac") );
(*progress)(game);
data->mountain_position = game->viewport.width*0.7;
(*progress)(game);
data->music = al_create_sample_instance(data->sample);
al_attach_sample_instance_to_mixer(data->music, game->audio.music);
al_set_sample_instance_playmode(data->music, ALLEGRO_PLAYMODE_LOOP);
(*progress)(game);
data->rain_sound = al_create_sample_instance(data->rain_sample);
al_attach_sample_instance_to_mixer(data->rain_sound, game->audio.fx);
al_set_sample_instance_playmode(data->rain_sound, ALLEGRO_PLAYMODE_LOOP);
(*progress)(game);
data->click = al_create_sample_instance(data->click_sample);
al_attach_sample_instance_to_mixer(data->click, game->audio.fx);
al_set_sample_instance_playmode(data->click, ALLEGRO_PLAYMODE_ONCE);
(*progress)(game);
data->font_title = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.16,0 );
(*progress)(game);
data->font_subtitle = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.08,0 );
(*progress)(game);
data->font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.05,0 );
(*progress)(game);
data->font_selected = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.065,0 );
(*progress)(game);
if (!data->sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
@ -261,6 +282,7 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
al_draw_scaled_bitmap(data->pie, 0, 0, al_get_bitmap_width(data->pie), al_get_bitmap_height(data->pie), al_get_bitmap_width(data->pie_bitmap)*0.1, al_get_bitmap_height(data->pie_bitmap)*0.3, game->viewport.height*1.6*0.09, game->viewport.height*0.06, ALLEGRO_FLIP_HORIZONTAL);
al_draw_scaled_bitmap(data->pie, 0, 0, al_get_bitmap_width(data->pie), al_get_bitmap_height(data->pie), al_get_bitmap_width(data->pie_bitmap)*0.3, al_get_bitmap_height(data->pie_bitmap)*0.6, game->viewport.height*1.6*0.13, game->viewport.height*0.1, 0);
al_destroy_bitmap(data->pie);
(*progress)(game);
al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
data->rain_bitmap = al_create_bitmap(al_get_bitmap_width(data->pinkcloud_bitmap)*0.5, al_get_bitmap_height(data->pinkcloud_bitmap)*0.1);
@ -269,6 +291,7 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
al_clear_to_color(al_map_rgba(0,0,0,0));
al_draw_scaled_bitmap(data->rain,0, 0, al_get_bitmap_width(data->rain), al_get_bitmap_height(data->rain), 0, 0, al_get_bitmap_width(data->rain_bitmap), al_get_bitmap_height(data->rain_bitmap),0);
al_destroy_bitmap(data->rain);
(*progress)(game);
al_set_target_backbuffer(game->display);
return data;
@ -510,6 +533,6 @@ void Gamestate_ProcessEvent(struct Game *game, struct MenuResources* data, ALLEG
}
void Gamestate_Pause(struct Game *game, struct IntroResources* data) {}
void Gamestate_Resume(struct Game *game, struct IntroResources* data) {}
void Gamestate_Reload(struct Game *game, struct IntroResources* data) {}
void Gamestate_Pause(struct Game *game, struct MenuResources* data) {}
void Gamestate_Resume(struct Game *game, struct MenuResources* data) {}
void Gamestate_Reload(struct Game *game, struct MenuResources* data) {}

View file

@ -310,6 +310,8 @@ int main(int argc, char **argv){
if (redraw && al_is_event_queue_empty(game._priv.event_queue)) {
struct Gamestate *tmp = game._priv.gamestates;
int toLoad = 0, loaded = 0;
// FIXME: move to function
// TODO: support dependences
while (tmp) {
@ -323,12 +325,14 @@ int main(int argc, char **argv){
tmp->pending_start = false;
}
if ((tmp->pending_load) && (!tmp->loaded)) toLoad++;
tmp=tmp->next;
}
tmp = game._priv.gamestates;
// FIXME: move to function
// TODO: support dependences
while (tmp) {
if ((tmp->pending_load) && (tmp->loaded)) {
PrintConsole(&game, "Unloading gamestate \"%s\"...", tmp->name);
@ -352,11 +356,13 @@ int main(int argc, char **argv){
if (!tmp->handle) {
PrintConsole(&game, "Error while loading gamestate \"%s\": %s", tmp->name, dlerror());
tmp->pending_load = false;
tmp->pending_start = false;
} else {
void gs_error() {
PrintConsole(&game, "Error on resolving gamestate symbol: %s", dlerror());
tmp->pending_load = false;
tmp->pending_start = false;
tmp=tmp->next;
}
@ -375,7 +381,19 @@ int main(int argc, char **argv){
if (!(tmp->api.Gamestate_ProgressCount = dlsym(tmp->handle, "Gamestate_ProgressCount"))) { gs_error(); continue; }
tmp->data = (*tmp->api.Gamestate_Load)(&game, NULL);
int p = 0;
void progress(struct Game *game) {
p++;
al_set_target_backbuffer(game->display);
al_clear_to_color(al_map_rgb(0,0,255));
float progress = ((p / (*(tmp->api.Gamestate_ProgressCount) ? (float)*(tmp->api.Gamestate_ProgressCount) : 1))/(float)toLoad)+(loaded/(float)toLoad);
PrintConsole(game, "[%s] Progress: %d% (%d/%d)", tmp->name, (int)(progress*100), p, *(tmp->api.Gamestate_ProgressCount));
DrawConsole(game);
al_flip_display();
}
tmp->data = (*tmp->api.Gamestate_Load)(&game, &progress);
loaded++;
tmp->loaded = true;
tmp->pending_load = false;

View file

@ -162,7 +162,6 @@ ALLEGRO_BITMAP* LoadScaledBitmap(struct Game *game, char* filename, int width, i
return target;*/
}
char* GetDataFilePath(char* filename) {
//TODO: support for current game