diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 42 |
1 files changed, 15 insertions, 27 deletions
@@ -3,8 +3,9 @@ The main game loop contains all of the global variables the game uses, and it runs the main game loop, the render loop, and the logic loop that control all of the entities. */ -#include <cstdio> // fopen -#include <chrono> // see millis() +#include <fstream> +#include <istream> +#include <thread> #include <common.h> #include <world.h> @@ -123,7 +124,7 @@ Mix_Chunk *crickets; * referenced in src/entities.cpp for getting random names. */ -FILE *names; +std::istream *names; /* * loops is used for texture animation. It is believed to be passed to entity @@ -188,25 +189,6 @@ std::string readFile(const char *filePath) { vec2 offset; /* OFFSET!!!!!!!!!!!!!!!!!!!! */ -/** - * millis - * - * We've encountered many problems when attempting to create delays for triggering - * the logic function. As a result, we decided on using the timing libraries given - * by <chrono> in the standard C++ library. This function simply returns the amount - * of milliseconds that have passed sine the epoch. - * -**/ - -#ifdef __WIN32__ -#define millis() SDL_GetTicks() -#else -unsigned int millis(void){ - std::chrono::system_clock::time_point now=std::chrono::system_clock::now(); - return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count(); -} -#endif - extern WEATHER weather; extern bool fadeEnable; @@ -217,10 +199,11 @@ extern int fadeIntensity; /******************************************************************************* * MAIN ************************************************************************ *******************************************************************************/ - + int main(/*int argc, char *argv[]*/){ //*argv = (char *)argc; gameRunning=false; + /*! * (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually * make openGL calls. Exit if there was an error. @@ -405,7 +388,10 @@ int main(/*int argc, char *argv[]*/){ * */ - names = fopen("assets/names_en-us", "r+"); + static std::filebuf fb; + fb.open("assets/names_en-us",std::ios::in); + names = new std::istream(&fb); + crickets=Mix_LoadWAV("assets/sounds/crickets.wav"); //Mix_Volume(2,25); @@ -445,7 +431,7 @@ int main(/*int argc, char *argv[]*/){ Mix_HaltMusic(); - fclose(names); + fb.close(); SDL_GL_DeleteContext(mainGLContext); SDL_DestroyWindow(window); @@ -473,7 +459,7 @@ void mainLoop(void){ if(!currentTime){ // Initialize currentTime if it hasn't been currentTime=millis(); - prevPrevTime=currentTime; + //prevPrevTime=currentTime; } /* @@ -514,7 +500,8 @@ void mainLoop(void){ if(++debugDiv==20){ debugDiv=0; - fps=1000/deltaTime; + if(deltaTime) + fps=1000/deltaTime; }else if(!(debugDiv%10)){ debugY = player->loc.y; } @@ -918,6 +905,7 @@ void logic(){ m->wander((rand()%240 + 15)); // Make the mob wander :) break; case MS_TRIGGER: + case MS_PAGE: m->wander(0); break; case MS_DOOR: |