#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
// '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);
// 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();
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() {
"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"
};
canMove = false;
maxHealth = health = 1;
-
+
inv = NULL;
}
#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 {
}
bool tickHasPassed(void) {
- if (prevPrevTime + MSEC_PER_TICK <= currentTime) {
- prevPrevTime = currentTime;
+ accum += deltaTime;
+ if (accum > MSEC_PER_TICK) {
+ accum = 0.0f;
return true;
}