Increase default TPS
This commit is contained in:
parent
0a5dc66e4c
commit
1e7e9a4f9e
|
@ -96,7 +96,8 @@ int main(int argc, char *argv[]) {
|
||||||
brick_e.add_component<se::ModelComponent>("examples/dev_testing/resources/bricks/bricks.fbx");
|
brick_e.add_component<se::ModelComponent>("examples/dev_testing/resources/bricks/bricks.fbx");
|
||||||
brick_e.add_component<se::RotatingComponent>();
|
brick_e.add_component<se::RotatingComponent>();
|
||||||
auto &brick_transf = brick_e.add_component<se::TransformComponent>();
|
auto &brick_transf = brick_e.add_component<se::TransformComponent>();
|
||||||
brick_transf.translate(6.f, -0.5f, 1.f);
|
brick_transf.translate(6.f, 0.f, 0.f);
|
||||||
|
//brick_transf.translate(6.f, -0.5f, 1.f);
|
||||||
|
|
||||||
auto light = std::make_shared<se::gfx::Light>(core_shader, glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f));
|
auto light = std::make_shared<se::gfx::Light>(core_shader, glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f));
|
||||||
game.add_event(light);
|
game.add_event(light);
|
||||||
|
|
|
@ -66,10 +66,9 @@ namespace simpleengine {
|
||||||
int fps_limit = -1;
|
int fps_limit = -1;
|
||||||
bool enable_vsync = true;
|
bool enable_vsync = true;
|
||||||
|
|
||||||
int max_engine_tps = 60; // The maximum engine TPS
|
int max_engine_tps = 120; // The maximum engine TPS
|
||||||
double tps_accumulator = 0.f;
|
float fixed_delta_time = 1.f / (float) max_engine_tps; // The delta time from fixed timestep
|
||||||
//int engine_ticks_second = 0; // The amount of ticks in a second
|
float tps_accumulator = 0.f;
|
||||||
//double last_sec_engine_tick; // The time of the last second
|
|
||||||
|
|
||||||
float get_delta_time();
|
float get_delta_time();
|
||||||
|
|
||||||
|
|
26
src/game.cpp
26
src/game.cpp
|
@ -158,33 +158,31 @@ void simpleengine::Game::limit_framerate(const float& delta_time) const {
|
||||||
int simpleengine::Game::run() {
|
int simpleengine::Game::run() {
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
// Get delta time first thing
|
// Get delta time first thing
|
||||||
float delta_time = get_delta_time();
|
float frame_time = get_delta_time();
|
||||||
//std::cout << "Delta time: " << delta_time << std::endl;
|
|
||||||
|
|
||||||
// Poll input events
|
// Poll input events
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
input_update(frame_time); // Update input on varying timestep
|
||||||
|
|
||||||
const double max_delta_time = 0.25;
|
tps_accumulator += frame_time;
|
||||||
|
|
||||||
tps_accumulator += delta_time;
|
// https://gafferongames.com/post/fix_your_timestep/
|
||||||
|
while (tps_accumulator >= fixed_delta_time) {
|
||||||
|
update(fixed_delta_time);
|
||||||
|
|
||||||
input_update(delta_time);
|
tps_accumulator -= fixed_delta_time;
|
||||||
|
|
||||||
while (tps_accumulator >= max_delta_time) {
|
|
||||||
update(max_delta_time);
|
|
||||||
|
|
||||||
tps_accumulator -= max_delta_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const double interpolate_alpha = tps_accumulator / max_delta_time;
|
|
||||||
|
|
||||||
render_window(interpolate_alpha, delta_time);
|
// Alpha used for interpolating objects in rendering
|
||||||
|
float interpolate_alpha = tps_accumulator / fixed_delta_time;
|
||||||
|
|
||||||
|
render_window(interpolate_alpha, frame_time);
|
||||||
|
|
||||||
// End draw
|
// End draw
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
limit_framerate(delta_time);
|
limit_framerate(frame_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue