mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-07 21:56:44 +01:00
Blue Screen of Death
This commit is contained in:
parent
b39ec719be
commit
dd29fc6f5b
8 changed files with 111 additions and 47 deletions
|
@ -79,7 +79,7 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game *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") );
|
||||
data->sample = al_load_sample( GetDataFilePath(game, "about/about.flac") );
|
||||
(*progress)(game);
|
||||
|
||||
data->music = al_create_sample_instance(data->sample);
|
||||
|
@ -88,7 +88,7 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game *game)) {
|
|||
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 );
|
||||
data->font = al_load_ttf_font(GetDataFilePath(game, "fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.035,0 );
|
||||
(*progress)(game);
|
||||
data->x = -0.1;
|
||||
if (!data->sample){
|
||||
|
|
|
@ -48,9 +48,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 );
|
||||
data->font_small = al_load_ttf_font(GetDataFilePath(game, "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 );
|
||||
data->font = al_load_ttf_font(GetDataFilePath(game, "fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.065,0 );
|
||||
(*progress)(game);
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ void FillPage(struct Game *game, struct IntroResources *data, int page) {
|
|||
char filename[30] = { };
|
||||
sprintf(filename, "intro/%d.flac", page);
|
||||
|
||||
data->audiostream = al_load_audio_stream(GetDataFilePath(filename), 4, 1024);
|
||||
data->audiostream = al_load_audio_stream(GetDataFilePath(game, filename), 4, 1024);
|
||||
al_attach_audio_stream_to_mixer(data->audiostream, game->audio.voice);
|
||||
al_set_audio_stream_playing(data->audiostream, false);
|
||||
al_set_audio_stream_gain(data->audiostream, 1.75);
|
||||
|
@ -231,7 +231,7 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct 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") );
|
||||
data->sample = al_load_sample( GetDataFilePath(game, "intro/intro.flac") );
|
||||
(*progress)(game);
|
||||
|
||||
data->music = al_create_sample_instance(data->sample);
|
||||
|
@ -247,7 +247,7 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
|
|||
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 );
|
||||
data->font = al_load_ttf_font(GetDataFilePath(game, "fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.04,0 );
|
||||
(*progress)(game);
|
||||
|
||||
return data;
|
||||
|
|
|
@ -110,12 +110,12 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
|
|||
data->highlight = LoadScaledBitmap(game, filename, game->viewport.height*1.6, game->viewport.height);
|
||||
(*progress)(game);
|
||||
|
||||
data->arrow = al_load_bitmap( GetDataFilePath("map/arrow.png") );
|
||||
data->arrow = al_load_bitmap( GetDataFilePath(game, "map/arrow.png") );
|
||||
(*progress)(game);
|
||||
|
||||
data->click_sample = al_load_sample( GetDataFilePath("menu/click.flac") );
|
||||
data->click_sample = al_load_sample( GetDataFilePath(game, "menu/click.flac") );
|
||||
(*progress)(game);
|
||||
data->sample = al_load_sample( GetDataFilePath("map/map.flac") );
|
||||
data->sample = al_load_sample( GetDataFilePath(game, "map/map.flac") );
|
||||
(*progress)(game);
|
||||
|
||||
data->music = al_create_sample_instance(data->sample);
|
||||
|
|
|
@ -219,17 +219,17 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
|
|||
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") );
|
||||
data->rain = al_load_bitmap( GetDataFilePath(game, "menu/rain.png") );
|
||||
(*progress)(game);
|
||||
data->pie = al_load_bitmap( GetDataFilePath("menu/pie.png") );
|
||||
data->pie = al_load_bitmap( GetDataFilePath(game, "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") );
|
||||
data->sample = al_load_sample( GetDataFilePath(game, "menu/menu.flac") );
|
||||
(*progress)(game);
|
||||
data->rain_sample = al_load_sample( GetDataFilePath("menu/rain.flac") );
|
||||
data->rain_sample = al_load_sample( GetDataFilePath(game, "menu/rain.flac") );
|
||||
(*progress)(game);
|
||||
data->click_sample = al_load_sample( GetDataFilePath("menu/click.flac") );
|
||||
data->click_sample = al_load_sample( GetDataFilePath(game, "menu/click.flac") );
|
||||
(*progress)(game);
|
||||
data->mountain_position = game->viewport.width*0.7;
|
||||
(*progress)(game);
|
||||
|
@ -249,13 +249,13 @@ void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) {
|
|||
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 );
|
||||
data->font_title = al_load_ttf_font(GetDataFilePath(game, "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 );
|
||||
data->font_subtitle = al_load_ttf_font(GetDataFilePath(game, "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 );
|
||||
data->font = al_load_ttf_font(GetDataFilePath(game, "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 );
|
||||
data->font_selected = al_load_ttf_font(GetDataFilePath(game, "fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.065,0 );
|
||||
(*progress)(game);
|
||||
|
||||
if (!data->sample){
|
||||
|
|
40
src/main.c
40
src/main.c
|
@ -116,16 +116,10 @@ void SetupViewport(struct Game *game) {
|
|||
}
|
||||
|
||||
int Console_Load(struct Game *game) {
|
||||
game->_priv.font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.09,0 );
|
||||
if(!game->_priv.font) {
|
||||
fprintf(stderr, "failed to load game font!\n");
|
||||
return -1;
|
||||
}
|
||||
game->_priv.font_console = al_load_ttf_font(GetDataFilePath("fonts/DejaVuSansMono.ttf"),game->viewport.height*0.018,0 );
|
||||
if(!game->_priv.font_console) {
|
||||
fprintf(stderr, "failed to load console font!\n");
|
||||
return -1;
|
||||
}
|
||||
game->_priv.font_console = NULL;
|
||||
game->_priv.console = NULL;
|
||||
game->_priv.font_console = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"),game->viewport.height*0.018,0 );
|
||||
game->_priv.font = al_load_ttf_font(GetDataFilePath(game, "fonts/ShadowsIntoLight.ttf"),game->viewport.height*0.09,0 );
|
||||
game->_priv.console = al_create_bitmap(game->viewport.width, game->viewport.height*0.12);
|
||||
al_set_target_bitmap(game->_priv.console);
|
||||
al_clear_to_color(al_map_rgba(0,0,0,80));
|
||||
|
@ -223,7 +217,14 @@ int main(int argc, char **argv){
|
|||
return -1;
|
||||
}
|
||||
|
||||
ALLEGRO_BITMAP *icon = al_load_bitmap(GetDataFilePath("icons/superderpy.png"));
|
||||
SetupViewport(&game);
|
||||
|
||||
int ret = Console_Load(&game);
|
||||
if (ret!=0) return ret;
|
||||
|
||||
PrintConsole(&game, "Viewport %dx%d", game.viewport.width, game.viewport.height);
|
||||
|
||||
ALLEGRO_BITMAP *icon = al_load_bitmap(GetDataFilePath(&game, "icons/superderpy.png"));
|
||||
al_set_window_title(game.display, "Super Derpy: Muffin Attack");
|
||||
al_set_display_icon(game.display, icon);
|
||||
al_destroy_bitmap(icon);
|
||||
|
@ -231,20 +232,13 @@ int main(int argc, char **argv){
|
|||
if (game.config.fullscreen) al_hide_mouse_cursor(game.display);
|
||||
al_inhibit_screensaver(true);
|
||||
|
||||
SetupViewport(&game);
|
||||
|
||||
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
|
||||
|
||||
int ret = Console_Load(&game);
|
||||
if (ret!=0) return ret;
|
||||
|
||||
PrintConsole(&game, "Viewport %dx%d", game.viewport.width, game.viewport.height);
|
||||
|
||||
game._priv.gamestates = NULL;
|
||||
|
||||
game._priv.event_queue = al_create_event_queue();
|
||||
if(!game._priv.event_queue) {
|
||||
fprintf(stderr, "failed to create event_queue!\n");
|
||||
FatalError(&game, true, "Failed to create event queue.");
|
||||
al_destroy_display(game.display);
|
||||
return -1;
|
||||
}
|
||||
|
@ -272,7 +266,7 @@ int main(int argc, char **argv){
|
|||
al_wait_for_vsync();
|
||||
game._priv.timer = al_create_timer(ALLEGRO_BPS_TO_SECS(60)); // logic timer
|
||||
if(!game._priv.timer) {
|
||||
fprintf(stderr, "failed to create timer!\n");
|
||||
FatalError(&game, true, "Failed to create logic timer.");
|
||||
return -1;
|
||||
}
|
||||
al_register_event_source(game._priv.event_queue, al_get_timer_event_source(game._priv.timer));
|
||||
|
@ -354,13 +348,15 @@ int main(int argc, char **argv){
|
|||
sprintf(libname, "libsuperderpy-%s-%s.so", "muffinattack", tmp->name);
|
||||
tmp->handle = dlopen(libname,RTLD_NOW);
|
||||
if (!tmp->handle) {
|
||||
PrintConsole(&game, "Error while loading gamestate \"%s\": %s", tmp->name, dlerror());
|
||||
//PrintConsole(&game, "Error while loading gamestate \"%s\": %s", tmp->name, dlerror());
|
||||
FatalError(&game, true, "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());
|
||||
FatalError(&game, true, "Error on resolving gamestate symbol: %s", dlerror());
|
||||
tmp->pending_load = false;
|
||||
tmp->pending_start = false;
|
||||
tmp=tmp->next;
|
||||
|
|
76
src/utils.c
76
src/utils.c
|
@ -132,7 +132,7 @@ ALLEGRO_BITMAP* LoadScaledBitmap(struct Game *game, char* filename, int width, i
|
|||
ALLEGRO_BITMAP *source, *target = al_create_bitmap(width, height);
|
||||
al_set_target_bitmap(target);
|
||||
al_clear_to_color(al_map_rgba(0,0,0,0));
|
||||
char* origfn = GetDataFilePath(filename);
|
||||
char* origfn = GetDataFilePath(game, filename);
|
||||
void GenerateBitmap() {
|
||||
if (memoryscale) al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
|
||||
|
||||
|
@ -162,7 +162,73 @@ ALLEGRO_BITMAP* LoadScaledBitmap(struct Game *game, char* filename, int width, i
|
|||
return target;*/
|
||||
}
|
||||
|
||||
char* GetDataFilePath(char* filename) {
|
||||
void FatalError(struct Game *game, bool fatal, char* format, ...) {
|
||||
char text[1024] = {};
|
||||
if (!game->_priv.console) {
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
vsprintf(text, format, vl);
|
||||
va_end(vl);
|
||||
printf("%s\n", text);
|
||||
if (!game->_priv.font_console) exit(1);
|
||||
} else {
|
||||
PrintConsole(game, "Fatal Error, displaying BSOD...");
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
vsprintf(text, format, vl);
|
||||
va_end(vl);
|
||||
PrintConsole(game, text);
|
||||
}
|
||||
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
ALLEGRO_KEYBOARD_STATE kb;
|
||||
al_get_keyboard_state(&kb);
|
||||
|
||||
int i;
|
||||
for (i=0; i<ALLEGRO_KEY_MAX; i++) {
|
||||
if (al_key_down(&kb, i)) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
al_set_target_backbuffer(game->display);
|
||||
al_clear_to_color(al_map_rgb(0,0,170));
|
||||
|
||||
char *header = "SUPER DERPY";
|
||||
|
||||
al_draw_filled_rectangle(game->viewport.width/2 - al_get_text_width(game->_priv.font_console, header)/2 - 4, (int)(game->viewport.height * 0.32), 4 + game->viewport.width/2 + al_get_text_width(game->_priv.font_console, header)/2, (int)(game->viewport.height * 0.32) + al_get_font_line_height(game->_priv.font_console), al_map_rgb(170,170,170));
|
||||
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(0, 0, 170), game->viewport.width/2, (int)(game->viewport.height * 0.32), ALLEGRO_ALIGN_CENTRE, header);
|
||||
|
||||
char *header2 = "A fatal exception 0xD3RP has occured at 0028:M00F11NZ in GST SD(01) +";
|
||||
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2, (int)(game->viewport.height * 0.32+2*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_CENTRE, header2);
|
||||
al_draw_textf(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2 - al_get_text_width(game->_priv.font_console, header2)/2, (int)(game->viewport.height * 0.32+3*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_LEFT, "%p and system just doesn't know what went wrong.", game);
|
||||
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2, (int)(game->viewport.height * 0.32+5*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_CENTRE, text);
|
||||
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2 - al_get_text_width(game->_priv.font_console, header2)/2, (int)(game->viewport.height * 0.32+7*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_LEFT, "* Press any key to terminate this error.");
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2 - al_get_text_width(game->_priv.font_console, header2)/2, (int)(game->viewport.height * 0.32+8*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_LEFT, "* Press any key to destroy all muffins in the world.");
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2 - al_get_text_width(game->_priv.font_console, header2)/2, (int)(game->viewport.height * 0.32+9*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_LEFT, "* Just kidding, please press any key anyway.");
|
||||
|
||||
|
||||
if (fatal) {
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2 - al_get_text_width(game->_priv.font_console, header2)/2, (int)(game->viewport.height * 0.32+11*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_LEFT, "This is fatal error. My bad.");
|
||||
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2, (int)(game->viewport.height * 0.32+13*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_CENTRE, "Press any key to quit _");
|
||||
} else {
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2 - al_get_text_width(game->_priv.font_console, header2)/2, (int)(game->viewport.height * 0.32+11*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_LEFT, "Anything I can do to help?");
|
||||
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width/2, (int)(game->viewport.height * 0.32+13*al_get_font_line_height(game->_priv.font_console)*1.25), ALLEGRO_ALIGN_CENTRE, "Press any key to continue _");
|
||||
}
|
||||
|
||||
al_flip_display();
|
||||
}
|
||||
}
|
||||
|
||||
char* GetDataFilePath(struct Game *game, char* filename) {
|
||||
|
||||
//TODO: support for current game
|
||||
|
||||
|
@ -199,7 +265,7 @@ char* GetDataFilePath(char* filename) {
|
|||
TestPath("data/");
|
||||
|
||||
if (!result) {
|
||||
printf("FATAL: Could not find data file: %s!\n", filename);
|
||||
FatalError(game, true, "Could not find data file: %s!", filename);
|
||||
exit(1);
|
||||
}
|
||||
return result;
|
||||
|
@ -216,8 +282,8 @@ void PrintConsole(struct Game *game, char* format, ...) {
|
|||
ALLEGRO_BITMAP *con = al_create_bitmap(al_get_bitmap_width(game->_priv.console), al_get_bitmap_height(game->_priv.console));
|
||||
al_set_target_bitmap(con);
|
||||
al_clear_to_color(al_map_rgba(0,0,0,80));
|
||||
al_draw_bitmap_region(game->_priv.console, 0, al_get_bitmap_height(game->_priv.console)*0.2, al_get_bitmap_width(game->_priv.console), al_get_bitmap_height(game->_priv.console)*0.8, 0, 0, 0);
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), game->viewport.width*0.005, al_get_bitmap_height(game->_priv.console)*0.81, ALLEGRO_ALIGN_LEFT, text);
|
||||
al_draw_bitmap_region(game->_priv.console, 0, (int)(al_get_bitmap_height(game->_priv.console)*0.2), al_get_bitmap_width(game->_priv.console), (int)(al_get_bitmap_height(game->_priv.console)*0.8), 0, 0, 0);
|
||||
al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), (int)(game->viewport.width*0.005), (int)(al_get_bitmap_height(game->_priv.console)*0.81), ALLEGRO_ALIGN_LEFT, text);
|
||||
al_set_target_bitmap(game->_priv.console);
|
||||
al_clear_to_color(al_map_rgba(0,0,0,0));
|
||||
al_draw_bitmap(con, 0, 0, 0);
|
||||
|
|
|
@ -40,7 +40,7 @@ ALLEGRO_BITMAP* LoadScaledBitmap(struct Game *game, char* filename, int width, i
|
|||
void FadeGamestate(struct Game *game, bool in);
|
||||
|
||||
/*! \brief Finds path for data file. */
|
||||
char* GetDataFilePath(char* filename);
|
||||
char* GetDataFilePath(struct Game *game, char* filename);
|
||||
|
||||
/*! \brief Print some message on game console.
|
||||
*
|
||||
|
@ -49,3 +49,5 @@ char* GetDataFilePath(char* filename);
|
|||
* It needs to be called in printf style.
|
||||
*/
|
||||
void PrintConsole(struct Game *game, char* format, ...);
|
||||
|
||||
void FatalError(struct Game *game, bool exit, char* format, ...);
|
||||
|
|
Loading…
Reference in a new issue