Browse Source

Fix nuptial flight camera jumping on state enter

master
C. J. Howard 2 years ago
parent
commit
75a983e97d
6 changed files with 116 additions and 30 deletions
  1. +3
    -9
      src/game/state/main-menu.cpp
  2. +67
    -20
      src/game/state/nuptial-flight.cpp
  3. +1
    -0
      src/game/state/nuptial-flight.hpp
  4. +2
    -1
      src/game/state/splash.cpp
  5. +36
    -0
      src/game/system/constraint.cpp
  6. +7
    -0
      src/game/system/constraint.hpp

+ 3
- 9
src/game/state/main-menu.cpp View File

@ -259,7 +259,7 @@ main_menu::main_menu(game::context& ctx, bool fade_in):
const float ev100_sunny16 = physics::light::ev::from_settings(16.0f, 1.0f / 100.0f, 100.0f);
ctx.surface_camera->set_exposure(15.5f);
ctx.surface_camera->look_at({-55, 36, 10}, {0, 100, 0}, {0, 1, 0});
ctx.surface_camera->look_at({0, 10, 0}, {0, 0, 0}, {0, 0, 1});
ctx.surface_camera->update_tweens();
// Setup and enable sky and ground passes
@ -269,11 +269,8 @@ main_menu::main_menu(game::context& ctx, bool fade_in):
// Disable UI color clear
ctx.ui_clear_pass->set_cleared_buffers(false, true, false);
// Create mating swarm
swarm_eid = game::ant::create_swarm(ctx);
if (!ctx.menu_bg_billboard->is_active())
game::menu::fade_in_bg(ctx);
//if (!ctx.menu_bg_billboard->is_active())
// game::menu::fade_in_bg(ctx);
ctx.logger->pop_task(EXIT_SUCCESS);
@ -299,9 +296,6 @@ main_menu::~main_menu()
// Destruct title text
ctx.ui_scene->remove_object(&title_text);
// Destroy swarm
game::ant::destroy_swarm(ctx, swarm_eid);
ctx.logger->pop_task(EXIT_SUCCESS);
}

+ 67
- 20
src/game/state/nuptial-flight.cpp View File

@ -109,6 +109,7 @@ nuptial_flight::nuptial_flight(game::context& ctx):
// Create camera rig
create_camera_rig();
// Select random alate
ctx.entity_registry->view<component::transform, component::steering>().each
(
[&](entity::id alate_eid, auto& transform, auto& steering)
@ -117,6 +118,9 @@ nuptial_flight::nuptial_flight(game::context& ctx):
}
);
// Satisfy camera rig constraints
satisfy_camera_rig_constraints();
// Queue fade in
ctx.fade_transition_color->set_value({1, 1, 1});
ctx.function_queue.push(std::bind(&screen_transition::transition, ctx.fade_transition, config::nuptial_flight_fade_in_duration, true, ease<float>::out_sine, true, nullptr));
@ -260,7 +264,7 @@ void nuptial_flight::create_camera_rig()
ctx.entity_registry->emplace<component::transform>(camera_rig_eid, camera_rig_transform);
ctx.entity_registry->emplace<component::constraint_stack>(camera_rig_eid, camera_rig_constraint_stack);
set_camera_rig_zoom(0.5f);
set_camera_rig_zoom(0.25f);
}
void nuptial_flight::destroy_camera_rig()
@ -293,27 +297,62 @@ void nuptial_flight::set_camera_rig_zoom(float zoom)
);
}
void nuptial_flight::satisfy_camera_rig_constraints()
{
// Warp camera rig focus ease to
ctx.entity_registry->patch<component::constraint::ease_to>
(
camera_rig_focus_ease_to_eid,
[&](auto& component)
{
component.t = component.duration;
}
);
// Warp camera rig spring translation
ctx.entity_registry->patch<component::constraint::spring_translation>
(
camera_rig_spring_translation_eid,
[&](auto& component)
{
component.spring.x0 = component.spring.x1;
component.spring.v *= 0.0f;
}
);
// Warp camera rig spring rotation
ctx.entity_registry->patch<component::constraint::spring_rotation>
(
camera_rig_spring_rotation_eid,
[&](auto& component)
{
component.spring.x0 = component.spring.x1;
component.spring.v *= 0.0f;
}
);
}
void nuptial_flight::enable_controls()
{
// Reset mouse look
mouse_look = false;
float slow_modifier = 0.25f;
float fast_modifier = 4.0f;
float dolly_speed = 5.0f;
float truck_speed = dolly_speed;
float pedestal_speed = 5.0f;
double time_scale = 0.0;
double ff_time_scale = 60.0 * 200.0;
const float dolly_zoom_speed = 4.0f;
// Init control settings
float mouse_tilt_sensitivity = 1.0f;
float mouse_pan_sensitivity = 1.0f;
bool mouse_invert_tilt = false;
bool mouse_invert_pan = false;
bool mouse_look_toggle = false;
float gamepad_tilt_sensitivity = 1.0f;
float gamepad_pan_sensitivity = 1.0f;
bool gamepad_invert_tilt = false;
bool gamepad_invert_pan = false;
bool mouse_look_toggle = false;
double time_scale = 0.0;
double ff_time_scale = 60.0 * 200.0;
// Read control settings
if (ctx.config->contains("mouse_tilt_sensitivity"))
mouse_tilt_sensitivity = math::radians((*ctx.config)["mouse_tilt_sensitivity"].get<float>());
if (ctx.config->contains("mouse_pan_sensitivity"))
@ -324,7 +363,6 @@ void nuptial_flight::enable_controls()
mouse_invert_pan = (*ctx.config)["mouse_invert_pan"].get<bool>();
if (ctx.config->contains("mouse_look_toggle"))
mouse_look_toggle = (*ctx.config)["mouse_look_toggle"].get<bool>();
if (ctx.config->contains("gamepad_tilt_sensitivity"))
gamepad_tilt_sensitivity = math::radians((*ctx.config)["gamepad_tilt_sensitivity"].get<float>());
if (ctx.config->contains("gamepad_pan_sensitivity"))
@ -334,13 +372,12 @@ void nuptial_flight::enable_controls()
if (ctx.config->contains("gamepad_invert_pan"))
gamepad_invert_pan = (*ctx.config)["gamepad_invert_pan"].get<bool>();
// Determine tilt and pan factors according to sensitivity and inversion
const float mouse_tilt_factor = mouse_tilt_sensitivity * (mouse_invert_tilt ? -1.0f : 1.0f);
const float mouse_pan_factor = mouse_pan_sensitivity * (mouse_invert_pan ? -1.0f : 1.0f);
const float gamepad_tilt_factor = gamepad_tilt_sensitivity * (gamepad_invert_tilt ? -1.0f : 1.0f);
const float gamepad_pan_factor = gamepad_pan_sensitivity * (gamepad_invert_pan ? -1.0f : 1.0f);
const float dolly_zoom_speed = 4.0f;
// Mouse look
ctx.controls["mouse_look"]->set_activated_callback
(
@ -367,7 +404,7 @@ void nuptial_flight::enable_controls()
);
// Arc left control
ctx.controls["look_left_mouse"]->set_active_callback
ctx.controls["look_right_mouse"]->set_active_callback
(
[&, mouse_pan_factor](float value)
{
@ -384,7 +421,7 @@ void nuptial_flight::enable_controls()
);
}
);
ctx.controls["look_left_gamepad"]->set_active_callback
ctx.controls["look_right_gamepad"]->set_active_callback
(
[&, gamepad_pan_factor](float value)
{
@ -400,7 +437,7 @@ void nuptial_flight::enable_controls()
);
// Arc right control
ctx.controls["look_right_mouse"]->set_active_callback
ctx.controls["look_left_mouse"]->set_active_callback
(
[&, mouse_pan_factor](float value)
{
@ -417,7 +454,7 @@ void nuptial_flight::enable_controls()
);
}
);
ctx.controls["look_right_gamepad"]->set_active_callback
ctx.controls["look_left_gamepad"]->set_active_callback
(
[&, gamepad_pan_factor](float value)
{
@ -433,7 +470,7 @@ void nuptial_flight::enable_controls()
);
// Arc down control
ctx.controls["look_down_mouse"]->set_active_callback
ctx.controls["look_up_mouse"]->set_active_callback
(
[&, mouse_tilt_factor](float value)
{
@ -451,7 +488,7 @@ void nuptial_flight::enable_controls()
);
}
);
ctx.controls["look_down_gamepad"]->set_active_callback
ctx.controls["look_up_gamepad"]->set_active_callback
(
[&, gamepad_tilt_factor](float value)
{
@ -468,7 +505,7 @@ void nuptial_flight::enable_controls()
);
// Arc up control
ctx.controls["look_up_mouse"]->set_active_callback
ctx.controls["look_down_mouse"]->set_active_callback
(
[&, mouse_tilt_factor](float value)
{
@ -486,7 +523,7 @@ void nuptial_flight::enable_controls()
);
}
);
ctx.controls["look_up_gamepad"]->set_active_callback
ctx.controls["look_down_gamepad"]->set_active_callback
(
[&, gamepad_tilt_factor](float value)
{
@ -586,6 +623,15 @@ void nuptial_flight::enable_controls()
}
);
// Action control
ctx.controls["action"]->set_activated_callback
(
[&]()
{
}
);
// Fast-forward
ctx.controls["fast_forward"]->set_activated_callback
(
@ -752,6 +798,7 @@ void nuptial_flight::disable_controls()
ctx.controls["look_down_gamepad"]->set_active_callback(nullptr);
ctx.controls["look_down_mouse"]->set_active_callback(nullptr);
ctx.controls["select_mouse"]->set_activated_callback(nullptr);
ctx.controls["action"]->set_activated_callback(nullptr);
ctx.controls["switch_pov"]->set_activated_callback(nullptr);
ctx.controls["fast_forward"]->set_activated_callback(nullptr);
ctx.controls["rewind"]->set_activated_callback(nullptr);

+ 1
- 0
src/game/state/nuptial-flight.hpp View File

@ -38,6 +38,7 @@ private:
void destroy_camera_rig();
void set_camera_rig_zoom(float zoom);
void satisfy_camera_rig_constraints();
void enable_controls();
void disable_controls();

+ 2
- 1
src/game/state/splash.cpp View File

@ -146,7 +146,8 @@ splash::splash(game::context& ctx):
// Change to main menu state
ctx.state_machine.pop();
ctx.state_machine.emplace(new game::state::nuptial_flight(ctx));
ctx.state_machine.emplace(new game::state::main_menu(ctx, true));
//ctx.state_machine.emplace(new game::state::nuptial_flight(ctx));
}
}
);

+ 36
- 0
src/game/system/constraint.cpp View File

@ -72,6 +72,42 @@ void constraint::update(double t, double dt)
);
}
void constraint::evaluate(entity::id entity_id)
{
if (!registry.valid(entity_id))
return;
// Get transform and constraint stack components of the entity
const auto [transform, stack] = registry.try_get<component::transform, component::constraint_stack>(entity_id);
if (!transform || !stack)
return;
// Init world-space transform
transform->world = transform->local;
// Get entity ID of first constraint
entity::id constraint_eid = stack->head;
// Consecutively apply constraints
while (registry.valid(constraint_eid))
{
// Get constraint stack node of the constraint
const component::constraint_stack_node* node = registry.try_get<component::constraint_stack_node>(constraint_eid);
// Abort if constraint is missing a constraint stack node
if (!node)
break;
// Apply constraint if enabled
if (node->active)
handle_constraint(*transform, constraint_eid, 0.0f);
// Get entity ID of next constraint in the stack
constraint_eid = node->next;
}
}
void constraint::on_constraint_stack_update(entity::registry& registry, entity::id constraint_stack_eid)
{
registry.sort<component::constraint_stack>

+ 7
- 0
src/game/system/constraint.hpp View File

@ -44,6 +44,13 @@ public:
virtual void update(double t, double dt);
/**
* Manually evaluates an entity's constraints.
*
* @param entity_id ID of a constrained entity.
*/
void evaluate(entity::id entity_id);
private:
void on_constraint_stack_update(entity::registry& registry, entity::id constraint_stack_eid);

Loading…
Cancel
Save