58 #include <engine/config.hpp>
74 selected_picking_flag = std::uint32_t{1} << (
sizeof(std::uint32_t) * 8 - 1);
75 selected_eid = entt::null;
104 std::uniform_int_distribution<> name_pool_distribution(0,
static_cast<int>(name_pool->lines.size() - 1));
112 name_pool->lines[name_pool_distribution(
ctx.
rng)]
121 const auto& viewport_size =
ctx.
window->get_viewport_size();
122 const float aspect_ratio =
static_cast<float>(viewport_size[0]) /
static_cast<float>(viewport_size[1]);
125 camera_rig_near_distance = 1.0f;
126 camera_rig_far_distance = 150.0f;
129 camera_rig_zoom_speed = 4.0f;
133 camera_rig_focus_ease_to_duration = 1.0f;
140 selection_text.
set_color({1.0f, 1.0f, 1.0f, 1.0f});
142 const auto& text_aabb = selection_text.
get_bounds();
143 float text_w = text_aabb.
max.
x() - text_aabb.min.x();
144 float text_h = text_aabb.max.y() - text_aabb.min.y();
154 [&](
entity::id entity_id,
auto& transform,
auto& steering)
156 random_alate_eid = entity_id;
159 select_entity(random_alate_eid);
162 satisfy_camera_rig_constraints();
197 select_entity(entt::null);
200 destroy_camera_rig();
206 void nuptial_flight_state::create_camera_rig()
210 camera_rig_focus_ease_to.
target = selected_eid;
211 camera_rig_focus_ease_to.
start = {0, 0, 0};
212 camera_rig_focus_ease_to.
duration = camera_rig_focus_ease_to_duration;
213 camera_rig_focus_ease_to.
t = camera_rig_focus_ease_to.
duration;
216 camera_rig_focus_ease_to_node.
active =
true;
217 camera_rig_focus_ease_to_node.
weight = 1.0f;
218 camera_rig_focus_ease_to_node.
next = entt::null;
225 camera_rig_focus_constraint_stack.
priority = 1;
226 camera_rig_focus_constraint_stack.head = camera_rig_focus_ease_to_eid;
231 camera_rig_focus_transform.
world = camera_rig_focus_transform.
local;
240 camera_rig_pivot.
target = camera_rig_focus_eid;
241 camera_rig_pivot.offset = {0, 0, 0};
243 camera_rig_pivot_node.
active =
true;
244 camera_rig_pivot_node.
weight = 1.0f;
245 camera_rig_pivot_node.
next = entt::null;
252 camera_rig_copy_translation.
target = camera_rig_focus_eid;
253 camera_rig_copy_translation.copy_x =
true;
254 camera_rig_copy_translation.copy_y =
true;
255 camera_rig_copy_translation.copy_z =
true;
256 camera_rig_copy_translation.invert_x =
false;
257 camera_rig_copy_translation.invert_y =
false;
258 camera_rig_copy_translation.invert_z =
false;
259 camera_rig_copy_translation.offset =
true;
261 camera_rig_copy_translation_node.
active =
true;
262 camera_rig_copy_translation_node.
weight = 1.0f;
263 camera_rig_copy_translation_node.
next = camera_rig_pivot_eid;
270 camera_rig_spring_rotation.
spring.set_angular_frequency(camera_rig_rotation_spring_angular_frequency);
272 camera_rig_spring_rotation_node.
active =
true;
273 camera_rig_spring_rotation_node.
weight = 1.0f;
274 camera_rig_spring_rotation_node.
next = camera_rig_copy_translation_eid;
281 camera_rig_spring_translation.
spring.set_angular_frequency(camera_rig_translation_spring_angular_frequency);
283 camera_rig_spring_translation_node.
active =
true;
284 camera_rig_spring_translation_node.
weight = 1.0f;
285 camera_rig_spring_translation_node.
next = camera_rig_spring_rotation_eid;
292 camera_rig_constraint_stack.
priority = 2;
293 camera_rig_constraint_stack.head = camera_rig_spring_translation_eid;
298 camera_rig_transform.
world = camera_rig_transform.
local;
310 set_camera_rig_zoom(0.25f);
313 void nuptial_flight_state::destroy_camera_rig()
327 void nuptial_flight_state::set_camera_rig_zoom(
float zoom)
332 void nuptial_flight_state::satisfy_camera_rig_constraints()
337 void nuptial_flight_state::setup_controls()
342 void nuptial_flight_state::enable_controls()
347 void nuptial_flight_state::disable_controls()
352 void nuptial_flight_state::select_entity(
entity::id entity_id)
354 if (entity_id != selected_eid)
364 component.flags &= ~selected_picking_flag;
370 selected_eid = entity_id;
380 component.flags |= selected_picking_flag;
388 camera_rig_focus_ease_to_eid,
391 component.
target = selected_eid;
409 std::string format_string;
412 case ::ant_caste_type::queen:
416 case ::ant_caste_type::worker:
420 case ::ant_caste_type::soldier:
424 case ::ant_caste_type::male:
433 selection_text.
set_content(std::vformat(format_string, std::make_format_args(name)));
439 case ::ant_caste_type::queen:
443 case ::ant_caste_type::worker:
447 case ::ant_caste_type::soldier:
451 case ::ant_caste_type::male:
461 const auto& viewport_size =
ctx.
window->get_viewport_size();
462 const auto& text_aabb = selection_text.
get_bounds();
463 float text_w = text_aabb.
max.
x() - text_aabb.min.x();
464 float text_h = text_aabb.max.y() - text_aabb.min.y();
470 void nuptial_flight_state::select_nearest_entity(
const math::fvec3& direction)
476 if (!selected_eid_transform)
485 if (picked_eid != entt::null)
487 select_entity(picked_eid);
entity::id create_ant_swarm(::game &ctx)
void destroy_ant_swarm(::game &ctx, entity::id swarm_eid)
void refresh() noexcept
Resets the accumulated time (at) and frame timer, but not the elapsed fixed-rate update time.
Abstract base class for game states.
std::unique_ptr< scene::collection > ui_scene
::frame_scheduler frame_scheduler
std::unique_ptr< screen_transition > fade_transition
std::shared_ptr< scene::camera > surface_camera
type::bitmap_font menu_font
std::unique_ptr<::collision_system > collision_system
std::unique_ptr< resource_manager > resource_manager
std::unique_ptr< render::sky_pass > sky_pass
std::shared_ptr< app::window > window
std::queue< std::function< void()> > function_queue
std::shared_ptr< render::matvar_fvec3 > fade_transition_color
std::shared_ptr< render::material > menu_font_material
std::unique_ptr< entity::registry > entity_registry
std::unordered_map< hash::fnv1a32_t, entity::id > entities
nuptial_flight_state(::game &ctx)
virtual ~nuptial_flight_state()
void set_translation(const vector_type &translation)
Sets the translation of the object.
void set_content(const std::string &content)
Sets the text content.
void set_color(const math::fvec4 &color)
Sets the text color.
const aabb_type & get_bounds() const noexcept override
Returns the bounds of the object.
void set_material(std::shared_ptr< render::material > material)
Sets the text material.
void set_font(const type::bitmap_font *font)
Sets the text font.
void transition(float duration, bool reverse, animation< float >::interpolator_type interpolator, bool hide=true, const std::function< void()> &callback=nullptr)
const font_metrics & get_font_metrics() const
Returns metrics describing the font.
void enable_game_controls(::game &ctx)
void disable_game_controls(::game &ctx)
log_message< log_message_severity::trace, Args... > log_trace
Formats and logs a trace message.
entt::entity id
Entity ID type.
User-defined literals for compile-time string hashing.
T vertical_fov(T h, T r)
Calculates a vertical FoV given a horizontal FoV and aspect ratio.
constexpr vector< T, N > round(const vector< T, N > &x)
Performs a element-wise round operation.
quaternion< T > normalize(const quaternion< T > &q)
Normalizes a quaternion.
constexpr T radians(T degrees) noexcept
Converts an angle given in degrees to radians.
T from_settings(T n, T t, T s)
Exposure value from exposure settings.
constexpr T s_to_rads(T t) noexcept
Converts oscillation period to angular frequency.
void cosmogenesis(::game &ctx)
Creates the cosmos.
void create_observer(::game &ctx)
Creates the observer.
void enter_ecoregion(::game &ctx, const ecoregion &ecoregion)
Enters a ecoregion.
void set_time_scale(::game &ctx, double scale)
Sets rate at which time passes.
void set_time(::game &ctx, double t)
Sets the current time.
std::string get_string(const ::game &ctx, hash::fnv1a32_t key)
Returns a localized string.
Causes an ordered stack of constraints to be applied to an entity.
int priority
Priority number, with lower priorities evaluated first.
Single node in a constraint stack.
float weight
Controls the amount of influence the constraint has on the final result.
bool active
Enables or disables the constraint.
entity::id next
ID of the entity containing the next constraint in the constraint stack.
Copies the translation of a target entity.
entity::id target
Target entity ID.
Eases toward a target entity.
entity::id target
Target entity ID.
math::fvec3 start
Start position.
float duration
Total duration of the ease.
float t
Elapsed time since ease began.
math::fvec3(* function)(const math::fvec3 &, const math::fvec3 &, float)
Pointer to the interpolation function.
Container for templated easing functions.
vector_type max
Maximum extent of the hyperrectangle.
constexpr element_type & x() noexcept
Returns a reference to the first element.
Supplies a human-readable name.
Pivots around a target entity.
entity::id target
Target entity ID.
std::shared_ptr< scene::object_base > object
physics::numeric_spring< math::fvec3, float > spring
Yaw, pitch, and roll angle spring.
physics::numeric_spring< math::fvec3, float > spring
Translation spring.
float size
Vertical size of the font.