Increase default TPS

This commit is contained in:
SeanOMik 2022-10-16 15:42:19 -04:00
parent 0a5dc66e4c
commit 1e7e9a4f9e
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
3 changed files with 17 additions and 19 deletions

View File

@ -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::RotatingComponent>();
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));
game.add_event(light);

View File

@ -66,10 +66,9 @@ namespace simpleengine {
int fps_limit = -1;
bool enable_vsync = true;
int max_engine_tps = 60; // The maximum engine TPS
double tps_accumulator = 0.f;
//int engine_ticks_second = 0; // The amount of ticks in a second
//double last_sec_engine_tick; // The time of the last second
int max_engine_tps = 120; // The maximum engine TPS
float fixed_delta_time = 1.f / (float) max_engine_tps; // The delta time from fixed timestep
float tps_accumulator = 0.f;
float get_delta_time();

View File

@ -158,33 +158,31 @@ void simpleengine::Game::limit_framerate(const float& delta_time) const {
int simpleengine::Game::run() {
while (!glfwWindowShouldClose(window)) {
// Get delta time first thing
float delta_time = get_delta_time();
//std::cout << "Delta time: " << delta_time << std::endl;
float frame_time = get_delta_time();
// Poll input events
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);
while (tps_accumulator >= max_delta_time) {
update(max_delta_time);
tps_accumulator -= max_delta_time;
tps_accumulator -= fixed_delta_time;
}
const double interpolate_alpha = tps_accumulator / max_delta_time;
// Alpha used for interpolating objects in rendering
float interpolate_alpha = tps_accumulator / fixed_delta_time;
render_window(interpolate_alpha, delta_time);
render_window(interpolate_alpha, frame_time);
// End draw
glfwSwapBuffers(window);
glFlush();
limit_framerate(delta_time);
limit_framerate(frame_time);
}
return 0;