mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 02:56:43 +01:00
bring back loading screen
This commit is contained in:
parent
06639404d8
commit
c8356b815b
5 changed files with 75 additions and 84 deletions
|
@ -14,7 +14,12 @@ GAMESTATE("menu")
|
|||
GAMESTATE("disclaimer")
|
||||
GAMESTATE("intro")
|
||||
GAMESTATE("map")
|
||||
#GAMESTATE("level")
|
||||
#GAMESTATE("level1")
|
||||
#GAMESTATE("level2")
|
||||
#GAMESTATE("level3")
|
||||
#GAMESTATE("level4")
|
||||
#GAMESTATE("level5")
|
||||
#GAMESTATE("level6")
|
||||
GAMESTATE("about")
|
||||
#GAMESTATE("pause")
|
||||
#GAMESTATE("loading")
|
||||
GAMESTATE("loading")
|
||||
|
|
|
@ -18,81 +18,42 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <allegro5/allegro_primitives.h>
|
||||
#include "../utils.h"
|
||||
#include "loading.h"
|
||||
|
||||
void Progress(struct Game *game, float p) {
|
||||
if (game->debug) { printf("%f\n", p); fflush(stdout); }
|
||||
void Progress(struct Game *game, struct LoadingResources *data, float p) {
|
||||
al_set_target_bitmap(al_get_backbuffer(game->display));
|
||||
al_draw_bitmap(game->loading.loading_bitmap,0,0,0);
|
||||
al_draw_filled_rectangle(0, game->viewportHeight*0.985, p*game->viewportWidth, game->viewportHeight, al_map_rgba(255,255,255,255));
|
||||
DrawConsole(game);
|
||||
al_flip_display();
|
||||
al_draw_bitmap(data->loading_bitmap,0,0,0);
|
||||
al_draw_filled_rectangle(0, game->viewport.height*0.985, p*game->viewport.width, game->viewport.height, al_map_rgba(255,255,255,255));
|
||||
}
|
||||
|
||||
void Loading_Draw(struct Game *game) {
|
||||
float fadeloop=0;
|
||||
while (fadeloop<256) {
|
||||
ALLEGRO_EVENT ev;
|
||||
al_wait_for_event(game->event_queue, &ev);
|
||||
if ((ev.type == ALLEGRO_EVENT_TIMER) && (ev.timer.source == game->timer)) {
|
||||
fadeloop+=10;
|
||||
}
|
||||
if (al_is_event_queue_empty(game->event_queue)) {
|
||||
al_draw_tinted_bitmap(game->loading.loading_bitmap,al_map_rgba_f(fadeloop/255.0,fadeloop/255.0,fadeloop/255.0,1),0,0,0);
|
||||
DrawConsole(game);
|
||||
al_flip_display();
|
||||
}
|
||||
}
|
||||
|
||||
al_draw_bitmap(game->loading.loading_bitmap,0,0,0);
|
||||
|
||||
al_stop_timer(game->timer);
|
||||
|
||||
LoadGamestate(game, "");
|
||||
|
||||
al_wait_for_vsync();
|
||||
al_start_timer(game->timer);
|
||||
|
||||
fadeloop=0;
|
||||
while (fadeloop<256) {
|
||||
ALLEGRO_EVENT ev;
|
||||
al_wait_for_event(game->event_queue, &ev);
|
||||
if ((ev.type == ALLEGRO_EVENT_TIMER) && (ev.timer.source == game->timer)) {
|
||||
fadeloop+=10;
|
||||
}
|
||||
if (al_is_event_queue_empty(game->event_queue)) {
|
||||
al_draw_bitmap(game->loading.loading_bitmap,0,0,0);
|
||||
al_draw_filled_rectangle(0, game->viewportHeight*0.985, game->viewportWidth, game->viewportHeight, al_map_rgba(255,255,255,255));
|
||||
al_draw_filled_rectangle(0, 0, game->viewportWidth, game->viewportHeight, al_map_rgba_f(0,0,0,fadeloop/255.0));
|
||||
|
||||
DrawConsole(game);
|
||||
al_flip_display();
|
||||
}
|
||||
}
|
||||
al_clear_to_color(al_map_rgb(0,0,0));
|
||||
DrawConsole(game);
|
||||
al_flip_display();
|
||||
StartGamestate(game, "");
|
||||
void Draw(struct Game *game, struct LoadingResources *data, float p) {
|
||||
al_draw_bitmap(data->loading_bitmap,0,0,0);
|
||||
Progress(game, data, p);
|
||||
}
|
||||
|
||||
void Loading_Load(struct Game *game) {
|
||||
void* Load(struct Game *game) {
|
||||
struct LoadingResources *data = malloc(sizeof(struct LoadingResources));
|
||||
al_clear_to_color(al_map_rgb(0,0,0));
|
||||
|
||||
game->loading.loading_bitmap = al_create_bitmap(game->viewportWidth, game->viewportHeight);
|
||||
data->loading_bitmap = al_create_bitmap(game->viewport.width, game->viewport.height);
|
||||
|
||||
game->loading.image = LoadScaledBitmap("loading.png", game->viewportHeight*2, game->viewportHeight);
|
||||
data->image = LoadScaledBitmap(game, "loading.png", game->viewport.height*2, game->viewport.height);
|
||||
|
||||
al_set_target_bitmap(game->loading.loading_bitmap);
|
||||
al_set_target_bitmap(data->loading_bitmap);
|
||||
al_clear_to_color(al_map_rgb(193,225,218));
|
||||
al_draw_bitmap(game->loading.image, game->viewportWidth-al_get_bitmap_width(game->loading.image), 0, 0);
|
||||
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), game->viewportWidth*0.0234, game->viewportHeight*0.84, ALLEGRO_ALIGN_LEFT, "Loading...");
|
||||
al_draw_filled_rectangle(0, game->viewportHeight*0.985, game->viewportWidth, game->viewportHeight, al_map_rgba(128,128,128,128));
|
||||
al_draw_bitmap(data->image, game->viewport.width-al_get_bitmap_width(data->image), 0, 0);
|
||||
DrawTextWithShadow(game->_priv.font, al_map_rgb(255,255,255), game->viewport.width*0.0234, game->viewport.height*0.84, ALLEGRO_ALIGN_LEFT, "Loading...");
|
||||
al_draw_filled_rectangle(0, game->viewport.height*0.985, game->viewport.width, game->viewport.height, al_map_rgba(128,128,128,128));
|
||||
al_set_target_bitmap(al_get_backbuffer(game->display));
|
||||
al_destroy_bitmap(game->loading.image);
|
||||
al_destroy_bitmap(data->image);
|
||||
return data;
|
||||
}
|
||||
|
||||
int Loading_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { return 0; }
|
||||
void Loading_Preload(struct Game *game, void (*progress)(struct Game*, float)) {}
|
||||
void Loading_Unload(struct Game *game) { al_destroy_bitmap(game->loading.loading_bitmap); }
|
||||
void Start(struct Game *game, struct LoadingResources *data) {}
|
||||
void Stop(struct Game *game, struct LoadingResources *data) {}
|
||||
void Unload(struct Game *game, struct LoadingResources *data) {
|
||||
al_destroy_bitmap(data->loading_bitmap);
|
||||
free(data);
|
||||
}
|
||||
|
|
|
@ -18,10 +18,13 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "../main.h"
|
||||
|
||||
void Loading_Draw(struct Game *game);
|
||||
void Loading_Preload(struct Game *game, void (*progress)(struct Game*, float));
|
||||
void Loading_Unload(struct Game *game);
|
||||
void Loading_Load(struct Game *game);
|
||||
int Loading_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
|
||||
#include <allegro5/allegro.h>
|
||||
#include <allegro5/allegro_font.h>
|
||||
|
||||
/*! \brief Resources used by Loading state. */
|
||||
struct LoadingResources {
|
||||
ALLEGRO_BITMAP *loading_bitmap; /*!< Rendered loading bitmap. */
|
||||
ALLEGRO_BITMAP *image; /*!< Loading background. */
|
||||
};
|
||||
|
|
39
src/main.c
39
src/main.c
|
@ -298,6 +298,29 @@ int main(int argc, char **argv){
|
|||
StartGamestate(&game, gamestate);
|
||||
free(gamestate);
|
||||
|
||||
char libname[1024] = {};
|
||||
sprintf(libname, "libsuperderpy-%s-loading.so", "muffinattack");
|
||||
void *handle = dlopen(libname,RTLD_NOW);
|
||||
if (!handle) {
|
||||
FatalError(&game, true, "Error while initializing loading screen %s", dlerror());
|
||||
exit(1);
|
||||
} else {
|
||||
|
||||
void gs_error() {
|
||||
FatalError(&game, true, "Error on resolving loading symbol: %s", dlerror());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!(game._priv.loading.Draw = dlsym(handle, "Draw"))) { gs_error(); }
|
||||
|
||||
if (!(game._priv.loading.Load = dlsym(handle, "Load"))) { gs_error(); }
|
||||
if (!(game._priv.loading.Start = dlsym(handle, "Start"))) { gs_error(); }
|
||||
if (!(game._priv.loading.Stop = dlsym(handle, "Stop"))) { gs_error(); }
|
||||
if (!(game._priv.loading.Unload = dlsym(handle, "Unload"))) { gs_error(); }
|
||||
}
|
||||
|
||||
game._priv.loading.data = (*game._priv.loading.Load)(&game);
|
||||
|
||||
bool redraw = false;
|
||||
|
||||
while(1) {
|
||||
|
@ -312,9 +335,6 @@ int main(int argc, char **argv){
|
|||
while (tmp) {
|
||||
if ((tmp->pending_start) && (tmp->started)) {
|
||||
PrintConsole(&game, "Stopping gamestate \"%s\"...", tmp->name);
|
||||
al_clear_to_color(al_map_rgb(255,255,0));
|
||||
DrawConsole(&game);
|
||||
al_flip_display();
|
||||
(*tmp->api.Gamestate_Stop)(&game, tmp->data);
|
||||
tmp->started = false;
|
||||
tmp->pending_start = false;
|
||||
|
@ -331,9 +351,6 @@ int main(int argc, char **argv){
|
|||
while (tmp) {
|
||||
if ((tmp->pending_load) && (tmp->loaded)) {
|
||||
PrintConsole(&game, "Unloading gamestate \"%s\"...", tmp->name);
|
||||
al_clear_to_color(al_map_rgb(255,0,0));
|
||||
DrawConsole(&game);
|
||||
al_flip_display();
|
||||
tmp->loaded = false;
|
||||
tmp->pending_load = false;
|
||||
(*tmp->api.Gamestate_Unload)(&game, tmp->data);
|
||||
|
@ -341,9 +358,6 @@ int main(int argc, char **argv){
|
|||
tmp->handle = NULL;
|
||||
} else if ((tmp->pending_load) && (!tmp->loaded)) {
|
||||
PrintConsole(&game, "Loading gamestate \"%s\"...", tmp->name);
|
||||
al_clear_to_color(al_map_rgb(0,0,255));
|
||||
DrawConsole(&game);
|
||||
al_flip_display();
|
||||
// TODO: take proper game name
|
||||
char libname[1024];
|
||||
sprintf(libname, "libsuperderpy-%s-%s.so", "muffinattack", tmp->name);
|
||||
|
@ -382,9 +396,9 @@ int main(int argc, char **argv){
|
|||
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));
|
||||
if (game->config.debug) PrintConsole(game, "[%s] Progress: %d% (%d/%d)", tmp->name, (int)(progress*100), p, *(tmp->api.Gamestate_ProgressCount));
|
||||
(*game->_priv.loading.Draw)(game, game->_priv.loading.data, progress);
|
||||
DrawConsole(game);
|
||||
al_flip_display();
|
||||
}
|
||||
|
@ -407,9 +421,6 @@ int main(int argc, char **argv){
|
|||
|
||||
if ((tmp->pending_start) && (!tmp->started) && (tmp->loaded)) {
|
||||
PrintConsole(&game, "Starting gamestate \"%s\"...", tmp->name);
|
||||
al_clear_to_color(al_map_rgb(0,255,255));
|
||||
DrawConsole(&game);
|
||||
al_flip_display();
|
||||
(*tmp->api.Gamestate_Start)(&game, tmp->data);
|
||||
tmp->started = true;
|
||||
tmp->pending_start = false;
|
||||
|
|
11
src/main.h
11
src/main.h
|
@ -76,6 +76,17 @@ struct Game {
|
|||
|
||||
ALLEGRO_CONFIG *config;
|
||||
|
||||
struct {
|
||||
void (*Draw)(struct Game *game, void* data, float p);
|
||||
|
||||
void* (*Load)(struct Game *game);
|
||||
void (*Start)(struct Game *game, void* data);
|
||||
void (*Stop)(struct Game *game, void* data);
|
||||
void (*Unload)(struct Game *game, void* data);
|
||||
|
||||
void* data;
|
||||
} loading;
|
||||
|
||||
} _priv; /*!< Private resources. Do not use in gamestates! */
|
||||
|
||||
bool shuttingdown; /*!< If true then shut down of the game is pending. */
|
||||
|
|
Loading…
Reference in a new issue