|
@@ -52,35 +52,37 @@ void application::input()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-double application::syncAndDeltatime()
|
|
|
+void application::syncAndDeltatime()
|
|
|
{
|
|
|
+ waitTime.start();
|
|
|
+
|
|
|
/* Let's make sure we are running at the expected framerate */
|
|
|
uint32_t now = SDL_GetTicks();
|
|
|
+
|
|
|
int32_t timeToWait = MILLISECS_PER_FRAME - (now - this->millisecsPreviousFrame);
|
|
|
if ((timeToWait > 0) && (timeToWait <= MILLISECS_PER_FRAME))
|
|
|
{
|
|
|
SDL_Delay(timeToWait);
|
|
|
}
|
|
|
- double deltaTime = (SDL_GetTicks() - this->millisecsPreviousFrame) / 1000.0;
|
|
|
+ this->deltaTime = (SDL_GetTicks() - this->millisecsPreviousFrame) / 1000.0;
|
|
|
|
|
|
/* clamp maximum deltatime to avoid weird behaviours */
|
|
|
- if (deltaTime > 0.016)
|
|
|
+ if (this->deltaTime > 0.016)
|
|
|
{
|
|
|
- deltaTime = 0.016;
|
|
|
+ this->deltaTime = 0.016;
|
|
|
}
|
|
|
this->millisecsPreviousFrame = SDL_GetTicks();
|
|
|
|
|
|
- return deltaTime;
|
|
|
+ waitTime.stop();
|
|
|
}
|
|
|
|
|
|
|
|
|
void application::update()
|
|
|
{
|
|
|
vec2 wind = vec2(0.2 * PIXELS_PER_METER, 0);
|
|
|
+ this->syncAndDeltatime();
|
|
|
|
|
|
- double deltaTime = this->syncAndDeltatime();
|
|
|
-
|
|
|
- this->part->addForce(wind);
|
|
|
+ updateTime.start();
|
|
|
|
|
|
for (auto part:this->particles)
|
|
|
{
|
|
@@ -102,25 +104,27 @@ void application::update()
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( ((this->part->position.x - this->part->radius) <= 0) ||
|
|
|
- ((this->part->position.x + this->part->radius) >= graphics::width()))
|
|
|
- {
|
|
|
- this->part->velocity.x = -this->part->velocity.x;
|
|
|
- }
|
|
|
-
|
|
|
+ updateTime.stop();
|
|
|
}
|
|
|
|
|
|
void application::render()
|
|
|
{
|
|
|
+ renderTime.start();
|
|
|
+
|
|
|
graphics::clearScreen(0xFF056263);
|
|
|
for (auto part:this->particles)
|
|
|
{
|
|
|
graphics::draw::fillCircle(part->position.x, part->position.y, part->radius, 0xFFFFFFFF);
|
|
|
}
|
|
|
|
|
|
- graphics::draw::fillCircle(this->part->position.x, this->part->position.y, 4, 0xFFFFFFFF);
|
|
|
+ graphics::draw::text(5, 5, 0x11FF22, "Wait time: %02.2f ms", waitTime.get());
|
|
|
+ graphics::draw::text(5, 17, 0x11FF22, "Update time: %02.2f ms", updateTime.get());
|
|
|
+ graphics::draw::text(5, 29, 0x11FF22, "Render time: %02.2f ms", renderTime.get());
|
|
|
+ graphics::draw::text(5, 41, 0x11FF22, "FPS: %.1f | dT: %.3f", 1000 / (waitTime.get() + updateTime.get() + renderTime.get()), deltaTime);
|
|
|
|
|
|
graphics::renderFrame();
|
|
|
+
|
|
|
+ renderTime.stop();
|
|
|
}
|
|
|
|
|
|
void application::destroy()
|
|
@@ -131,6 +135,5 @@ void application::destroy()
|
|
|
delete part;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
graphics::closeWindow();
|
|
|
}
|