summary refs log tree commit diff stats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp index 62c8b16..bc7832d 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -42,22 +42,24 @@ int main()
42 curGameState = new MapView(m, 100, 100); 42 curGameState = new MapView(m, 100, 100);
43 43
44 Texture* buffer = createTexture(GAME_WIDTH, GAME_HEIGHT); 44 Texture* buffer = createTexture(GAME_WIDTH, GAME_HEIGHT);
45 //Texture* buffer = loadTextureFromBMP("../res/title.png");
45 46
46 double lastTime = glfwGetTime(); 47 double lastTime = glfwGetTime();
47 double accum = 0.0; 48 int nbFrames = 0;
48 49
49 while (!(quit || glfwWindowShouldClose(window))) 50 while (!(quit || glfwWindowShouldClose(window)))
50 { 51 {
51 // Tick! 52 double currentTime = glfwGetTime();
52 accum += (glfwGetTime() - lastTime); 53 nbFrames++;
53 if (accum < 0) accum = 0; 54 if (currentTime - lastTime >= 1.0)
54 while (accum > SECONDS_PER_FRAME)
55 { 55 {
56 curGameState->tick(); 56 // printf and reset timer
57 accum -= SECONDS_PER_FRAME; 57 printf("%f ms/frame\n", 1000.0/double(nbFrames));
58 nbFrames = 0;
59 lastTime += 1.0;
58 } 60 }
59 61
60 lastTime = glfwGetTime(); 62 curGameState->tick();
61 63
62 // Do rendering 64 // Do rendering
63 curGameState->render(buffer); 65 curGameState->render(buffer);