diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
@@ -256,9 +256,11 @@ int main(int argc, char *argv[]){ if(Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0){ std::cout << "SDL_mixer could not initialize! Error: " << Mix_GetError() << std::endl; + return -1; } // Run Mix_Quit when main returns + atexit(Mix_CloseAudio); atexit(Mix_Quit); /* @@ -439,6 +441,7 @@ int main(int argc, char *argv[]){ /************************** **** GAMELOOP **** **************************/ + gameRunning=true; while(gameRunning){ mainLoop(); @@ -452,6 +455,11 @@ int main(int argc, char *argv[]){ * Close the window and free resources */ + Mix_HaltMusic(); + Mix_FreeMusic(music); + + Mix_FreeChunk(horn); + fclose(names); SDL_GL_DeleteContext(mainGLContext); @@ -483,7 +491,6 @@ void mainLoop(void){ currentTime=millis(); prevPrevTime=currentTime; } - /* * Update timing values. This is crucial to calling logic and updating the window (basically * the entire game). @@ -496,8 +503,8 @@ void mainLoop(void){ /* * Run the logic handler if MSEC_PER_TICK milliseconds have passed. */ - - if(prevPrevTime + MSEC_PER_TICK >= currentTime){ + ui::handleEvents(); + if(prevPrevTime + MSEC_PER_TICK <= currentTime){ logic(); prevPrevTime = currentTime; } @@ -511,7 +518,6 @@ void mainLoop(void){ /* * Update debug variables if necessary */ - if(++debugDiv==20){ debugDiv=0; @@ -522,7 +528,6 @@ void mainLoop(void){ } render(); // Call the render loop - } extern bool fadeEnable; @@ -773,7 +778,6 @@ void render(){ /* * Here we draw a black overlay if it's been requested. */ - if(fadeIntensity){ glColor4ub(0,0,0,fadeIntensity); glRectf(offset.x-SCREEN_WIDTH /2, @@ -784,7 +788,6 @@ void render(){ ui::importantText("The screen is black."); } }else if(ui::fontSize != 16) ui::setFontSize(16); - /************************** **** END RENDERING **** **************************/ @@ -805,7 +808,6 @@ void render(){ } void logic(){ - /* * NPCSelected is used to insure that only one NPC is made interactable with the mouse * if, for example, multiple entities are occupying one space. @@ -816,14 +818,12 @@ void logic(){ /* * Handle user input (keyboard & mouse). */ - - ui::handleEvents(); + //ui::handleEvents(); /* * Run the world's detect function. This handles the physics of the player and any entities * that exist in this world. */ - currentWorld->detect(player); if(player->loc.y<.02)gameRunning=false; @@ -833,7 +833,6 @@ void logic(){ * click detection is done as well for NPC/player interaction. * */ - if((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) && !ui::dialogBoxExists)player->inv->useItem(); for(auto &n : currentWorld->npc){ @@ -907,7 +906,6 @@ void logic(){ }else n->near=false; } } - for(auto &m : currentWorld->mob){ if(m->alive){ @@ -929,7 +927,6 @@ void logic(){ } } } - unsigned int i = 0; for(auto &o : currentWorld->object){ if(o->alive){ @@ -960,7 +957,6 @@ void logic(){ /* * Switch between day and night (SUNNY and DARK) if necessary. */ - if(!(tickCount%DAY_CYCLE)||!tickCount){ if(weather==SUNNY){ weather=DARK; @@ -978,7 +974,6 @@ void logic(){ /* * Transition to and from black if necessary. */ - if(fadeEnable){ if(fadeIntensity < 160)fadeIntensity+=5; else if(fadeIntensity < 255)fadeIntensity+=1; |