/// ***** Private Method Headers *****
-void init();
+void mainInit();
+void mainClean();
+
+void updatesInit();
+void updatesClean();
+
+void drawInit();
+void drawClean();
void sighandler( int sig );
void update(float);
void draw();
+int startUpdateThread(void*);
+int startDrawThread(void*);
+
/// ***** Private Variables *****
// variable used to determine if it is time to shutdown
const int min_wait_micro = min_wait_milli * 1000;
const float game_step = 10;
-int startUpdateThread(void*);
-int startDrawThread(void*);
+bool updateInitialized = false;
+bool drawInitialized = false;
/// ***** MAIN Method *****
int main(int argc, char** args)
{
- init();
+ mainInit();
run();
- clean();
+ mainClean();
return 0;
}
/// ***** Initializers/Cleaners *****
-void init()
+void mainInit()
{
installSignal();
- graphics::init();
- DPF(0, "Graphics initialized");
+ debug::init();
+}
+
+void mainClean()
+{
+ debug::clean();
+}
+
+void updatesInit()
+{
+ while(!drawInitialized)
+ SDL_Delay(100);
game::init();
DPF(0, "Game initialized");
DPF(0, "Configs initialized");
DPF(0, "Initialization Complete");
+
+ updateInitialized = true;
}
-void clean()
+void updatesClean()
{
- DPF(0, "Cleaning up");
+ DPF(0, "Update Thread Cleaning");
cfg::clean();
input::clean();
game::clean();
+}
+
+void drawInit()
+{
+ graphics::init();
+ DPF(0, "Graphics initialized");
+
+ drawInitialized = true;
+
+ while(!updateInitialized)
+ SDL_Delay(100);
+}
+
+void drawClean()
+{
+ DPF(0, "Draw Thread Cleaning");
graphics::clean();
}
/// ***** Private Methods *****
+SDL_Thread* updatesThread = NULL;
+SDL_Thread* drawThread = NULL;
void run()
{
is_Running = true;
- SDL_Thread* updates = SDL_CreateThread(startUpdateThread, NULL);
+ updatesThread = SDL_CreateThread(startUpdateThread, NULL);
+ drawThread = SDL_CreateThread(startDrawThread, NULL);
- // for some reason this needs to be on the main thread ...?
- startDrawThread(NULL);
-
- SDL_WaitThread(updates, NULL);
+ SDL_WaitThread(updatesThread, NULL);
+ SDL_WaitThread(drawThread, NULL);
}
void updateFPSCounters()
int startUpdateThread(void*)
{
+ updatesInit();
+
last_Second = tickCountMicro();
while(is_Running)
}
}
+ updatesClean();
+
return 0;
}
int startDrawThread(void*)
{
+ drawInit();
+
while(is_Running)
{
draw();
}
+ drawClean();
+
return 0;
}