]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Fixed some stuff
authordrumsetmonkey <abelleisle@roadrunner.com>
Sun, 1 May 2016 21:52:44 +0000 (17:52 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Sun, 1 May 2016 21:52:44 +0000 (17:52 -0400)
Makefile
include/common.hpp
main.cpp
src/entities.cpp
src/gametime.cpp

index eb38b521db5cd5f588af35017b4bf24339a74496..d742643c7094daa5bae984c5b6f6a71e9d6a5271 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,7 @@ $(EXEC): $(CXXOUTDIR)/$(CXXOBJ) main.cpp
        @echo "  CXX/LD  main"
        @$(CXX) $(CXXFLAGS) $(CXXINC) $(CXXWARN) -o $(EXEC) main.cpp out/*.o $(LIBS)
        @rm -rf xml/*.dat
+       @rm -rf storyXML/*.dat
 
 $(CXXOUTDIR)/%.o: $(CXXSRCDIR)/%.cpp
        @echo "  CXX    " $<
index 3712f62fa53c77a4b23c0c209a5df5a8615e3e19..e607c12b50d19c9e435698658327c92330edd649 100644 (file)
@@ -32,10 +32,10 @@ typedef unsigned int uint;
 #endif
 
 // the number of ticks that should occur in one second
-constexpr const unsigned int TICKS_PER_SEC = 20;
+const unsigned int TICKS_PER_SEC = 20;
 
 // the number of milliseconds inbetween each tick
-constexpr const float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC;
+const float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC;
 
 // segfault-debugging output
 //#define SEGFAULT
index 6de7c038fda49f7f80933cd508e55af5e53f55e9..4db0579493fbfb281e417b39d8b114a2cb55c940 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -132,7 +132,7 @@ int main(int argc, char *argv[]){
 
        // 'basic' OpenGL setup
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-       SDL_GL_SetSwapInterval(0); // v-sync
+       SDL_GL_SetSwapInterval(1); // v-sync
        SDL_ShowCursor(SDL_DISABLE); // hide the mouse
        glViewport(0, 0, game::SCREEN_WIDTH, game::SCREEN_HEIGHT);
        glEnable(GL_BLEND);
@@ -224,8 +224,12 @@ int main(int argc, char *argv[]){
 
        // the main loop, in all of its gloriousness..
        gameRunning = true;
-       while (gameRunning)
+       std::thread([&]{while (gameRunning)
                mainLoop();
+       }).detach();
+
+       while(gameRunning)
+               render();
 
     // free library resources
     Mix_HaltMusic();
@@ -262,33 +266,32 @@ void mainLoop(void){
 
        game::time::mainLoopHandler();
 
-       if (currentMenu)
-               goto MENU;
-
-       // handle keypresses - currentWorld could change here
-       prev = currentWorld;
-       ui::handleEvents();
+       if (currentMenu) {
+               return;
+       } else {
+               // handle keypresses - currentWorld could change here
+               prev = currentWorld;
+               ui::handleEvents();
 
-       if(prev != currentWorld){
-               currentWorld->bgmPlay(prev);
-               ui::dialogBoxExists = false;
-       }
+               if(prev != currentWorld){
+                       currentWorld->bgmPlay(prev);
+                       ui::dialogBoxExists = false;
+               }
 
-       if (game::time::tickHasPassed())
-               logic();
+               if (game::time::tickHasPassed())
+                       logic();
 
-       currentWorld->update(player, game::time::getDeltaTime());
-       currentWorld->detect(player);
+               currentWorld->update(player, game::time::getDeltaTime());
+               currentWorld->detect(player);
 
-       if (++debugDiv == 20) {
-               debugDiv=0;
+               if (++debugDiv == 20) {
+                       debugDiv=0;
 
-               fps = 1000 / game::time::getDeltaTime();
-               if (!(debugDiv % 10))
-                       debugY = player->loc.y;
+                       fps = 1000 / game::time::getDeltaTime();
+                       if (!(debugDiv % 10))
+                               debugY = player->loc.y;
+               }
        }
-MENU:
-       render();
 }
 
 void render() {
index c90650e7d499e315c2bb365c34be03d136258938..d5d9af208649ca2c4e8c967d9f38ba0e26bbe207 100644 (file)
@@ -37,7 +37,7 @@ const char *randomDialog[RAND_DIALOG_COUNT] = {
        "You know, if anyone ever asked me who I wanted to be when I grow up, I would say Abby Ross.",
        "I want to have the wallpaper in our house changed. It doesn\'t really fit the environment.",
        "Frig.",
-       "The sine of theta equals the opposite over the hypotenuese.",
+       "The sine of theta equals the opposite over the hdaypotenuese.",
        "Did you know the developers spelt brazier as brazzier.",
        "What's a bagel? I don't know because I'm mormon"
 };
@@ -263,7 +263,7 @@ Object::Object() {
        canMove = false;
 
        maxHealth = health = 1;
-       
+
        inv = NULL;
 }
 
index 598cd4fc1dd43221719f62c9e86ba8766e9d5232..1005d84580117d71eca4656633f100c6a40edc5a 100644 (file)
@@ -3,11 +3,13 @@
 #include <common.hpp>
 
 static unsigned int tickCount = 0;
-static unsigned int deltaTime = 1;
+static float deltaTime = 1;
 
 // millisecond timers
 static unsigned int currentTime = 0;
-static unsigned int prevTime, prevPrevTime;
+static unsigned int prevTime;
+
+static float accum = 0.0f;
 
 namespace game {
     namespace time {
@@ -41,8 +43,9 @@ namespace game {
         }
 
         bool tickHasPassed(void) {
-            if (prevPrevTime + MSEC_PER_TICK <= currentTime) {
-                       prevPrevTime = currentTime;
+            accum += deltaTime;
+            if (accum > MSEC_PER_TICK) {
+                       accum = 0.0f;
                 return true;
                }