[Change] Some cleanup with loading.

This commit is contained in:
Allanis 2013-03-26 17:04:42 +00:00
parent 2dc53af39c
commit f63605d605
3 changed files with 44 additions and 16 deletions

View File

@ -54,6 +54,8 @@ int indjoystick = -1;
char* namjoystick = NULL; char* namjoystick = NULL;
// Prototypes. // Prototypes.
static void load_all(void);
static void unload_all(void);
void main_loop(void); void main_loop(void);
static void display_fps(const double dt); static void display_fps(const double dt);
static void window_caption(void); static void window_caption(void);
@ -153,13 +155,7 @@ int main(int argc, char** argv) {
toolkit_init(); // Init the toolkit. toolkit_init(); // Init the toolkit.
// Data loading. // Data loading.
commodity_load(); load_all();
factions_load();
spfx_load();
outfit_load();
ships_load();
fleet_load();
space_load();
menu_main(); menu_main();
@ -180,18 +176,18 @@ int main(int argc, char** argv) {
main_loop(); main_loop();
} }
// Unload data. // Clean up some stuff.
player_cleanup(); // Cleans up the player stuff. player_cleanup(); // Cleans up the player stuff.
gui_free(); // Free up the gui.
weapon_exit(); // Destroy all active weapons. weapon_exit(); // Destroy all active weapons.
space_exit(); // Clean up the universe!!! space_exit(); // Clean up the universe!!!
pilots_free(); // Free the pilots, they where locked up D: pilots_free(); // Free the pilots, they where locked up D:
gui_free(); // Free up the gui. space_exit(); // Cleans up the universe itself.
fleet_free();
ships_free(); // Unload data.
outfit_free(); unload_all();
spfx_free(); // Remove the special effects.
factions_free(); // Cleanup opengl fonts.
commodity_free();
gl_freeFont(NULL); gl_freeFont(NULL);
gl_freeFont(&gl_smallFont); gl_freeFont(&gl_smallFont);
@ -208,6 +204,27 @@ int main(int argc, char** argv) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
void load_all(void) {
// Ordering of these is very important as they are interdependent.
commodity_load();
factions_load();
spfx_load();
outfit_load();
ships_load();
fleet_load();
space_load();
}
void unload_all(void) {
// Data unloading - order should not matter, but inverse load_all is good.
fleet_free();
ships_free();
outfit_free();
spfx_free(); // Remove the special effects.
factions_free();
commodity_free();
}
// Slip main loop from main() for secondary loop hack in toolkit.c. // Slip main loop from main() for secondary loop hack in toolkit.c.
void main_loop(void) { void main_loop(void) {
sound_update(); // Do sound stuff. sound_update(); // Do sound stuff.

View File

@ -138,11 +138,15 @@ void player_destroyed(void);
// Prompt player name. // Prompt player name.
void player_new(void) { void player_new(void) {
int i;
// Let's not seg fault due to a lack of environment. // Let's not seg fault due to a lack of environment.
player_setFlag(PLAYER_DESTROYED); player_setFlag(PLAYER_DESTROYED);
vectnull(&player_cam); vectnull(&player_cam);
gl_bindCamera(&player_cam); gl_bindCamera(&player_cam);
for(i = 0; i < msg_max; i++)
memset(msg_stack[i].str, '\0', MSG_SIZE_MAX);
// Cleanup player stuff if we'll be re-creating. // Cleanup player stuff if we'll be re-creating.
player_cleanup(); player_cleanup();
@ -318,11 +322,12 @@ void player_message(const char* fmt, ...) {
if(fmt == NULL) return; // Message not valid. if(fmt == NULL) return; // Message not valid.
// Copy old messages back. // Copy old messages back.
for(i = 1; i < msg_max; i++) for(i = 1; i < msg_max; i++) {
if(msg_stack[msg_max-i-1].str[0] != '\0') { if(msg_stack[msg_max-i-1].str[0] != '\0') {
strcpy(msg_stack[msg_max-i].str, msg_stack[msg_max-i-1].str); strcpy(msg_stack[msg_max-i].str, msg_stack[msg_max-i-1].str);
msg_stack[msg_max-i].t = msg_stack[msg_max-i-1].t; msg_stack[msg_max-i].t = msg_stack[msg_max-i-1].t;
} }
}
// Add the new one. // Add the new one.
va_start(ap, fmt); va_start(ap, fmt);
vsprintf(msg_stack[0].str, fmt, ap); vsprintf(msg_stack[0].str, fmt, ap);

View File

@ -739,6 +739,12 @@ void space_exit(void) {
free(systems_stack[i].planets); free(systems_stack[i].planets);
} }
free(systems_stack); free(systems_stack);
systems_stack = NULL;
systems_nstack = 0;
if(stars) free(stars); if(stars) free(stars);
stars = NULL;
nstars = 0;
} }