[Add] Fancy ass loading screen.

This commit is contained in:
Allanis 2014-01-07 20:35:17 +00:00
parent cc580f9b7a
commit 378f924366

View File

@ -66,9 +66,10 @@
#define LEPHISTO_INIT_DELAY 3000 /**< Minimum amount of time to wait with loading screen. */ #define LEPHISTO_INIT_DELAY 3000 /**< Minimum amount of time to wait with loading screen. */
static int quit = 0; /**< For primary loop. */ static int quit = 0; /**< For primary loop. */
unsigned int time = 0; /**< USed to calculate FPS and movement, in pause.c */ static unsigned int time = 0; /**< Used to calculate FPS and movement, in pause.c */
static char version[VERSION_LEN]; static char version[VERSION_LEN]; /**< Contains version. */
static glTexture* loading; /**< Loading screen. */
/* Just some default crap. */ /* Just some default crap. */
char* data = NULL; /**< Path to datafile. */ char* data = NULL; /**< Path to datafile. */
@ -80,8 +81,11 @@ int indjoystick = -1; /**< Index of joystick to use, -1 is none. *
char* namjoystick = NULL; /**< Name of joystick to use, NULL is none. */ char* namjoystick = NULL; /**< Name of joystick to use, NULL is none. */
/* Prototypes. */ /* Prototypes. */
/* Loading. */
static void print_SDLversion(void); static void print_SDLversion(void);
static void load_screen(void); static void loadscreen_load(void);
static void loadscreen_render(double done, const char* msg);
static void loadscreen_unload(void);
static void load_all(void); static void load_all(void);
static void unload_all(void); static void unload_all(void);
static void display_fps(const double dt); static void display_fps(const double dt);
@ -158,8 +162,14 @@ int main(int argc, char** argv) {
SDL_Quit(); SDL_Quit();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
gl_fontInit(NULL, NULL, FONT_SIZE); /* Initializes default font size. */
gl_fontInit(&gl_smallFont, NULL, FONT_SIZE_SMALL); /* Small font. */
window_caption(); window_caption();
load_screen();
/* Display the load screen. */
loadscreen_load();
loadscreen_render(0., "Initializing subsystems...");
time = SDL_GetTicks(); time = SDL_GetTicks();
/* OpenAL sound. */ /* OpenAL sound. */
@ -201,14 +211,15 @@ int main(int argc, char** argv) {
ERR("Unable to init the Nebulae subsystem!"); ERR("Unable to init the Nebulae subsystem!");
/* Weirdness will accur. */ /* Weirdness will accur. */
} }
gl_fontInit(NULL, NULL, FONT_SIZE); /* Init default font size. */
gl_fontInit(&gl_smallFont, NULL, FONT_SIZE_SMALL); /* Small font. */
gui_init(); /* Init the GUI crap. */ gui_init(); /* Init the GUI crap. */
toolkit_init(); /* Init the toolkit. */ toolkit_init(); /* Init the toolkit. */
/* Data loading. */ /* Data loading. */
load_all(); load_all();
/* Unload load screen. */
loadscreen_unload();
/* Start menu. */ /* Start menu. */
menu_main(); menu_main();
@ -261,13 +272,12 @@ int main(int argc, char** argv) {
} }
/** /**
* @fn void load_scren(void) * @fn void loadscreen_load(void)
* *
* @brief Display a loading screen. * @brief Display a loading screen.
*/ */
void load_screen(void) { void loadscreen_load(void) {
int i; int i;
glTexture* tex;
char file_path[PATH_MAX]; char file_path[PATH_MAX];
char** files; char** files;
uint32_t nfiles; uint32_t nfiles;
@ -292,15 +302,65 @@ void load_screen(void) {
/* Load the texture. */ /* Load the texture. */
snprintf(file_path, PATH_MAX, "../gfx/loading%03d.png", RNG(0, nload-1)); snprintf(file_path, PATH_MAX, "../gfx/loading%03d.png", RNG(0, nload-1));
tex = gl_newImage(file_path); loading = gl_newImage(file_path);
}
/* Draw once, won't be redrawn. */ /**
* @fn static void loadscreen_render(double done, const char* msg)
*
* @brief Render the load screen with message.
* @param done Amount done (1. == completed).
* @param msg Loading screen message.
*/
static void loadscreen_render(double done, const char* msg) {
double x, y, w, h, rh;
/* Clear background. */
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
gl_blitScale(tex, 0., 0., SCREEN_W, SCREEN_H, NULL);
SDL_GL_SwapBuffers();
/* Draw loading screen image. */
gl_blitScale(loading, 0., 0., SCREEN_W, SCREEN_H, NULL);
/* Draw progress bar. */
w = gl_screen.w * 0.4;
h = gl_screen.h * 0.02;
rh = h + gl_defFont.h + 4.;
x = -w/2.;
y = -h/2.;
/* BG. */
ACOLOUR(cBlack, 0.7);
glBegin(GL_QUADS);
glVertex2d(x-2., y-2. + 0.);
glVertex2d(x-2., y+2. + rh);
glVertex2d(x-2. + w+4., y+2. + rh);
glVertex2d(x-2. + w+4., y-2. + 0.);
glEnd();
/* FG. */
ACOLOUR(cConsole, 0.7);
glBegin(GL_QUADS);
glVertex2d(x, y + 0.);
glVertex2d(x, y + h);
glVertex2d(x + done*w, y + h);
glVertex2d(x + done*w, y + 0.);
glEnd();
/* Draw text. */
gl_print(&gl_defFont, x + gl_screen.w/2., y + gl_screen.h/2 + 2. + h,
&cConsole, msg);
/* Flip buffers. */
SDL_GL_SwapBuffers();
}
/**
* @fn static void loadscreen_unload(void)
*
* @brief Frees the loading screen.
*/
static void loadscreen_unload(void) {
/* Free the textures. */ /* Free the textures. */
gl_freeTexture(tex); gl_freeTexture(loading);
loading = NULL;
} }
/** /**
@ -308,16 +368,26 @@ void load_screen(void) {
* *
* @brief Load all the data, makes main() simpler. * @brief Load all the data, makes main() simpler.
*/ */
#define LOADING_STAGES 9. /**< Amount of loading stages. */
void load_all(void) { void load_all(void) {
/* Ordering of these is very important as they are interdependent. */ /* Ordering of these is very important as they are interdependent. */
loadscreen_render(1./LOADING_STAGES, "Loading the pilot's food surplus...");
commodity_load(); commodity_load();
loadscreen_render(2./LOADING_STAGES, "Loading the powers that be...");
factions_load(); /* Dep for fleet, space, missions. */ factions_load(); /* Dep for fleet, space, missions. */
loadscreen_render(3./LOADING_STAGES, "Loading things to do...");
missions_load(); /* No dep. */ missions_load(); /* No dep. */
loadscreen_render(4./LOADING_STAGES, "Loading firework displays...");
spfx_load(); spfx_load();
loadscreen_render(5./LOADING_STAGES, "Loading laser beams...");
outfit_load(); outfit_load();
loadscreen_render(6./LOADING_STAGES, "Loading floating homes...");
ships_load(); ships_load();
loadscreen_render(7./LOADING_STAGES, "Loading rich snobs...");
fleet_load(); fleet_load();
loadscreen_render(8./LOADING_STAGES, "Loading the entire universe");
space_load(); space_load();
loadscreen_render(1./LOADING_STAGES, "Load Complete!!");
xmlCleanupParser(); /* Only needed to be run after all the loading is done. */ xmlCleanupParser(); /* Only needed to be run after all the loading is done. */
} }