Browse Source

add a max delta time

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
aa3b7ffa87
3 changed files with 16 additions and 13 deletions
  1. 1
    1
      core.mod/src/entities/EntPlayer.cc
  2. 1
    0
      libswan/include/swan/Entity.h
  3. 14
    12
      src/main.cc

+ 1
- 1
core.mod/src/entities/EntPlayer.cc View File

@@ -51,7 +51,7 @@ void EntPlayer::update(const Swan::Context &ctx, float dt) {
anims_[(int)state_].reset();
anims_[(int)state_].tick(dt);

//Swan::PhysicsEntity::update(ctx, dt);
Swan::PhysicsEntity::update(ctx, dt);
}

void EntPlayer::readSRF(const Swan::Context &ctx, const Swan::SRF &srf) {

+ 1
- 0
libswan/include/swan/Entity.h View File

@@ -4,6 +4,7 @@
#include <optional>

#include "common.h"
#include "log.h"
#include "SRF.h"
#include "BoundingBox.h"
#include "Body.h"

+ 14
- 12
src/main.cc View File

@@ -105,24 +105,26 @@ int main() {
fcount = 0;
}

game.update(dt);

if (dt > 0.1) {
if (slowFrames == 0)
warn << "Delta time too high! (" << dt << "s)";
slowFrames += 1;
} else {
if (slowFrames > 0) {
if (slowFrames > 1)
warn << slowFrames << " consecutive slow frames.";
slowFrames = 0;
}
dt = 0.1;
}

tickAcc += dt;
while (tickAcc >= 1.0 / TICK_RATE) {
tickAcc -= 1.0 / TICK_RATE;
game.tick(1.0 / TICK_RATE);
}
game.update(dt);

if (slowFrames > 0) {
if (slowFrames > 1)
warn << slowFrames << " consecutive slow frames.";
slowFrames = 0;
}

tickAcc += dt;
while (tickAcc >= 1.0 / TICK_RATE) {
tickAcc -= 1.0 / TICK_RATE;
game.tick(1.0 / TICK_RATE);
}

SDL_RenderClear(renderer.get());

Loading…
Cancel
Save