diff --git a/src/animation/frame-scheduler.cpp b/src/animation/frame-scheduler.cpp index 42140f8..7894b3e 100644 --- a/src/animation/frame-scheduler.cpp +++ b/src/animation/frame-scheduler.cpp @@ -21,8 +21,8 @@ #include frame_scheduler::frame_scheduler(): - update_callback(nullptr), - render_callback(nullptr), + update_callback([](double, double){}), + render_callback([](double){}), update_rate(60.0), update_timestep(1.0 / update_rate), max_frame_duration(update_timestep) diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 01fffe5..57ed91d 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -150,6 +150,12 @@ int bootloader(application* app, int argc, char** argv) logger->pop_task(EXIT_SUCCESS); + // Set update rate + if (ctx->config->contains("update_rate")) + { + app->set_update_rate((*ctx->config)["update_rate"].get()); + } + // Setup initial application state application::state initial_state; initial_state.name = "loading"; diff --git a/src/game/states/forage.cpp b/src/game/states/forage.cpp index ae7c63b..57e40f1 100644 --- a/src/game/states/forage.cpp +++ b/src/game/states/forage.cpp @@ -271,18 +271,36 @@ void setup_controls(game::context* ctx) const float dolly_speed = 20.0f; const float truck_speed = dolly_speed; const float pedestal_speed = 30.0f; - float mouse_sensitivity = 1.0f; - float gamepad_sensitivity = 1.0f; - - if (ctx->config->contains("mouse_sensitivity")) - mouse_sensitivity = math::radians((*ctx->config)["mouse_sensitivity"].get()); - if (ctx->config->contains("gamepad_sensitivity")) - gamepad_sensitivity = math::radians((*ctx->config)["gamepad_sensitivity"].get()); + float mouse_look_sensitivity = 1.0f; + bool mouse_invert_tilt = false; + bool mouse_invert_pan = false; + float gamepad_look_sensitivity = 1.0f; + bool gamepad_invert_tilt = false; + bool gamepad_invert_pan = false; + + if (ctx->config->contains("mouse_look_sensitivity")) + mouse_look_sensitivity = math::radians((*ctx->config)["mouse_look_sensitivity"].get()); + if (ctx->config->contains("mouse_invert_tilt")) + mouse_invert_tilt = math::radians((*ctx->config)["mouse_invert_tilt"].get()); + if (ctx->config->contains("mouse_invert_pan")) + mouse_invert_pan = math::radians((*ctx->config)["mouse_invert_pan"].get()); + + if (ctx->config->contains("gamepad_look_sensitivity")) + gamepad_look_sensitivity = math::radians((*ctx->config)["gamepad_look_sensitivity"].get()); + if (ctx->config->contains("gamepad_invert_tilt")) + gamepad_invert_tilt = math::radians((*ctx->config)["gamepad_invert_tilt"].get()); + if (ctx->config->contains("gamepad_invert_pan")) + gamepad_invert_pan = math::radians((*ctx->config)["gamepad_invert_pan"].get()); const input::control* move_slow = ctx->controls["move_slow"]; const input::control* move_fast = ctx->controls["move_fast"]; const input::control* mouse_rotate = ctx->controls["mouse_rotate"]; + float mouse_tilt_factor = mouse_look_sensitivity * (mouse_invert_tilt ? -1.0f : 1.0f); + float mouse_pan_factor = mouse_look_sensitivity * (mouse_invert_pan ? -1.0f : 1.0f); + float gamepad_tilt_factor = gamepad_look_sensitivity * (gamepad_invert_tilt ? -1.0f : 1.0f); + float gamepad_pan_factor = gamepad_look_sensitivity * (gamepad_invert_pan ? -1.0f : 1.0f); + ctx->controls["dolly_forward"]->set_active_callback ( [ctx, target_eid, three_dof_eid, truck_speed, move_slow, move_fast](float value) @@ -403,64 +421,64 @@ void setup_controls(game::context* ctx) // Pan left ctx->controls["pan_left_gamepad"]->set_active_callback ( - [ctx, three_dof_eid, gamepad_sensitivity](float value) + [ctx, three_dof_eid, gamepad_pan_factor](float value) { auto& three_dof = ctx->entity_registry->get(three_dof_eid); - three_dof.yaw += gamepad_sensitivity * value * (1.0f / 60.0f); + three_dof.yaw += gamepad_pan_factor * value * (1.0f / 60.0f); } ); ctx->controls["pan_left_mouse"]->set_active_callback ( - [ctx, three_dof_eid, mouse_sensitivity, mouse_rotate](float value) + [ctx, three_dof_eid, mouse_pan_factor, mouse_rotate](float value) { if (!mouse_rotate->is_active()) return; auto& three_dof = ctx->entity_registry->get(three_dof_eid); - three_dof.yaw += mouse_sensitivity * value * (1.0f / 60.0f); + three_dof.yaw += mouse_pan_factor * value * (1.0f / 60.0f); } ); // Pan right ctx->controls["pan_right_gamepad"]->set_active_callback ( - [ctx, three_dof_eid, gamepad_sensitivity](float value) + [ctx, three_dof_eid, gamepad_pan_factor](float value) { auto& three_dof = ctx->entity_registry->get(three_dof_eid); - three_dof.yaw -= gamepad_sensitivity * value * (1.0f / 60.0f); + three_dof.yaw -= gamepad_pan_factor * value * (1.0f / 60.0f); } ); ctx->controls["pan_right_mouse"]->set_active_callback ( - [ctx, three_dof_eid, mouse_sensitivity, mouse_rotate](float value) + [ctx, three_dof_eid, mouse_pan_factor, mouse_rotate](float value) { if (!mouse_rotate->is_active()) return; auto& three_dof = ctx->entity_registry->get(three_dof_eid); - three_dof.yaw -= mouse_sensitivity * value * (1.0f / 60.0f); + three_dof.yaw -= mouse_pan_factor * value * (1.0f / 60.0f); } ); // Tilt up ctx->controls["tilt_up_gamepad"]->set_active_callback ( - [ctx, three_dof_eid, gamepad_sensitivity](float value) + [ctx, three_dof_eid, gamepad_tilt_factor](float value) { auto& three_dof = ctx->entity_registry->get(three_dof_eid); - three_dof.pitch -= gamepad_sensitivity * value * (1.0f / 60.0f); + three_dof.pitch -= gamepad_tilt_factor * value * (1.0f / 60.0f); three_dof.pitch = std::max(math::radians(-90.0f), three_dof.pitch); } ); ctx->controls["tilt_up_mouse"]->set_active_callback ( - [ctx, three_dof_eid, mouse_sensitivity, mouse_rotate](float value) + [ctx, three_dof_eid, mouse_tilt_factor, mouse_rotate](float value) { if (!mouse_rotate->is_active()) return; auto& three_dof = ctx->entity_registry->get(three_dof_eid); - three_dof.pitch -= mouse_sensitivity * value * (1.0f / 60.0f); + three_dof.pitch -= mouse_tilt_factor * value * (1.0f / 60.0f); three_dof.pitch = std::max(math::radians(-90.0f), three_dof.pitch); } ); @@ -468,22 +486,22 @@ void setup_controls(game::context* ctx) // Tilt down ctx->controls["tilt_down_gamepad"]->set_active_callback ( - [ctx, three_dof_eid, gamepad_sensitivity](float value) + [ctx, three_dof_eid, gamepad_tilt_factor](float value) { auto& three_dof = ctx->entity_registry->get(three_dof_eid); - three_dof.pitch += gamepad_sensitivity * value * (1.0f / 60.0f); + three_dof.pitch += gamepad_tilt_factor * value * (1.0f / 60.0f); three_dof.pitch = std::min(math::radians(90.0f), three_dof.pitch); } ); ctx->controls["tilt_down_mouse"]->set_active_callback ( - [ctx, three_dof_eid, mouse_sensitivity, mouse_rotate](float value) + [ctx, three_dof_eid, mouse_tilt_factor, mouse_rotate](float value) { if (!mouse_rotate->is_active()) return; auto& three_dof = ctx->entity_registry->get(three_dof_eid); - three_dof.pitch += mouse_sensitivity * value * (1.0f / 60.0f); + three_dof.pitch += mouse_tilt_factor * value * (1.0f / 60.0f); three_dof.pitch = std::min(math::radians(90.0f), three_dof.pitch); } );