Browse Source

Replace hard-coded controls with string-mapped controls

master
C. J. Howard 3 years ago
parent
commit
fc9d4f1b76
6 changed files with 229 additions and 287 deletions
  1. +2
    -197
      src/game/bootloader.cpp
  2. +2
    -35
      src/game/context.hpp
  3. +42
    -39
      src/game/states/brood.cpp
  4. +183
    -0
      src/game/states/loading.cpp
  5. +0
    -10
      src/renderer/passes/material-pass.cpp
  6. +0
    -6
      src/renderer/passes/material-pass.hpp

+ 2
- 197
src/game/bootloader.cpp View File

@ -95,7 +95,6 @@
#include <functional> #include <functional>
#include <string> #include <string>
#include <vector> #include <vector>
#include "utility/timestamp.hpp"
static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0; static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0;
@ -705,15 +704,7 @@ void setup_scenes(game::context* ctx)
// Setup surface scene // Setup surface scene
{ {
ctx->surface_scene = new scene::collection(); ctx->surface_scene = new scene::collection();
ctx->lens_spot_light = new scene::spot_light();
ctx->lens_spot_light->set_color({1, 1, 1});
ctx->lens_spot_light->set_intensity(20.0f);
ctx->lens_spot_light->set_attenuation({1.0f, 0.0f, 0.0f});
ctx->lens_spot_light->set_cutoff({math::radians(1.25f), math::radians(1.8f)});
ctx->surface_scene->add_object(ctx->surface_camera); ctx->surface_scene->add_object(ctx->surface_camera);
//ctx->surface_scene->add_object(ctx->lens_spot_light);
} }
// Clear active scene // Clear active scene
@ -755,17 +746,11 @@ void setup_animation(game::context* ctx)
ctx->ui_scene->add_object(ctx->radial_transition_outer->get_billboard()); ctx->ui_scene->add_object(ctx->radial_transition_outer->get_billboard());
ctx->animator->add_animation(ctx->radial_transition_outer->get_animation()); ctx->animator->add_animation(ctx->radial_transition_outer->get_animation());
// Setup tweens
ctx->focal_point_tween = new tween<float3>();
ctx->focal_point_tween->set_interpolator(math::lerp<float3, float>);
// Set material pass tweens // Set material pass tweens
ctx->common_final_pass->set_time_tween(ctx->time_tween); ctx->common_final_pass->set_time_tween(ctx->time_tween);
ctx->surface_sky_pass->set_time_tween(ctx->time_tween); ctx->surface_sky_pass->set_time_tween(ctx->time_tween);
ctx->surface_material_pass->set_time_tween(ctx->time_tween); ctx->surface_material_pass->set_time_tween(ctx->time_tween);
ctx->surface_material_pass->set_focal_point_tween(ctx->focal_point_tween);
ctx->underground_material_pass->set_time_tween(ctx->time_tween); ctx->underground_material_pass->set_time_tween(ctx->time_tween);
ctx->underground_material_pass->set_focal_point_tween(ctx->focal_point_tween);
ctx->ui_material_pass->set_time_tween(ctx->time_tween); ctx->ui_material_pass->set_time_tween(ctx->time_tween);
} }
@ -773,16 +758,6 @@ void setup_entities(game::context* ctx)
{ {
// Create entity registry // Create entity registry
ctx->entity_registry = new entt::registry(); ctx->entity_registry = new entt::registry();
// Reserve named entities
ctx->brush_entity = ctx->entity_registry->create();
ctx->flashlight_entity = ctx->entity_registry->create();
ctx->forceps_entity = ctx->entity_registry->create();
ctx->lens_entity = ctx->entity_registry->create();
ctx->marker_entity = ctx->entity_registry->create();
ctx->container_entity = ctx->entity_registry->create();
ctx->twig_entity = ctx->entity_registry->create();
ctx->focal_point_entity = ctx->entity_registry->create();
} }
void setup_systems(game::context* ctx) void setup_systems(game::context* ctx)
@ -912,85 +887,6 @@ void setup_controls(game::context* ctx)
ctx->input_listener = new input::listener(); ctx->input_listener = new input::listener();
ctx->input_listener->set_event_dispatcher(event_dispatcher); ctx->input_listener->set_event_dispatcher(event_dispatcher);
// Create toggle fullscreen control
ctx->toggle_fullscreen_control = new input::control();
ctx->toggle_fullscreen_control->set_activated_callback
(
[ctx]()
{
bool fullscreen = !ctx->app->is_fullscreen();
ctx->app->set_fullscreen(fullscreen);
if (!fullscreen)
{
int2 resolution = ctx->config->get<int2>("windowed_resolution");
ctx->app->resize_window(resolution.x, resolution.y);
}
ctx->config->set<int>("fullscreen", (fullscreen) ? 1 : 0);
}
);
// Create screenshot control
ctx->screenshot_control = new input::control();
ctx->screenshot_control->set_activated_callback
(
[ctx]()
{
std::string path = ctx->screenshots_path + "antkeeper-" + timestamp() + ".png";
ctx->app->save_frame(path);
}
);
// Create menu back control
ctx->menu_back_control = new input::control();
ctx->menu_back_control->set_activated_callback
(
std::bind(&application::close, ctx->app, 0)
);
// Create menu select control
ctx->menu_select_control = new input::control();
// Create application control set
ctx->application_controls = new input::control_set();
ctx->application_controls->add_control(ctx->toggle_fullscreen_control);
ctx->application_controls->add_control(ctx->screenshot_control);
// Create menu control set
ctx->menu_controls = new input::control_set();
ctx->menu_controls->add_control(ctx->menu_back_control);
ctx->menu_controls->add_control(ctx->menu_select_control);
// Create camera controls
ctx->camera_control_slow_modifier = new input::control();
ctx->camera_control_fast_modifier = new input::control();
ctx->camera_control_mouse_rotate = new input::control();
ctx->camera_control_mouse_left = new input::control();
ctx->camera_control_mouse_right = new input::control();
ctx->camera_control_mouse_down = new input::control();
ctx->camera_control_mouse_up = new input::control();
ctx->camera_control_dolly_forward = new input::control();
ctx->camera_control_dolly_backward = new input::control();
ctx->camera_control_truck_left = new input::control();
ctx->camera_control_truck_right = new input::control();
ctx->camera_control_pedestal_up = new input::control();
ctx->camera_control_pedestal_down = new input::control();
ctx->camera_control_pan_left = new input::control();
ctx->camera_control_pan_right = new input::control();
ctx->camera_control_tilt_up = new input::control();
ctx->camera_control_tilt_down = new input::control();
// Application control mappings
ctx->input_event_router->add_mapping(input::key_mapping(ctx->toggle_fullscreen_control, nullptr, input::scancode::f11));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->screenshot_control, nullptr, input::scancode::f12));
// UI controls
ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_back_control, nullptr, input::scancode::escape));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_back_control, nullptr, input::scancode::backspace));
/* /*
// Add menu control mappings // Add menu control mappings
@ -1038,41 +934,6 @@ void setup_controls(game::context* ctx)
} }
}); });
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_move_forward_control(), nullptr, input::scancode::w));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_move_forward_control(), nullptr, input::game_controller_axis::left_y, true));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_move_back_control(), nullptr, input::scancode::s));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_move_back_control(), nullptr, input::game_controller_axis::left_y, false));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_move_left_control(), nullptr, input::scancode::a));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_move_left_control(), nullptr, input::game_controller_axis::left_x, true));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_move_right_control(), nullptr, input::scancode::d));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_move_right_control(), nullptr, input::game_controller_axis::left_x, false));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_rotate_ccw_control(), nullptr, input::game_controller_axis::right_x, false));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_rotate_cw_control(), nullptr, input::game_controller_axis::right_x, true));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_tilt_up_control(), nullptr, input::game_controller_axis::right_y, false));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_tilt_down_control(), nullptr, input::game_controller_axis::right_y, true));
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->control_system->get_zoom_in_control(), nullptr, input::mouse_wheel_axis::positive_y));
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->control_system->get_zoom_out_control(), nullptr, input::mouse_wheel_axis::negative_y));
//ctx->input_event_router->add_mapping(input::mouse_button_mapping(ctx->control_system->get_adjust_camera_control(), nullptr, 3));
ctx->input_event_router->add_mapping(input::game_controller_button_mapping(ctx->control_system->get_ascend_control(), nullptr, input::game_controller_button::y));
ctx->input_event_router->add_mapping(input::game_controller_button_mapping(ctx->control_system->get_descend_control(), nullptr, input::game_controller_button::a));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_zoom_out_control(), nullptr, input::game_controller_axis::trigger_left, false));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_zoom_in_control(), nullptr, input::game_controller_axis::trigger_right, false));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_rotate_ccw_control(), nullptr, input::scancode::q));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_rotate_cw_control(), nullptr, input::scancode::e));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_fast_forward_control(), nullptr, input::scancode::dot));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_rewind_control(), nullptr, input::scancode::comma));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_exposure_increase_control(), nullptr, input::scancode::right_brace));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_exposure_decrease_control(), nullptr, input::scancode::left_brace));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_brush_control(), nullptr, input::scancode::one));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_twig_control(), nullptr, input::scancode::two));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_forceps_control(), nullptr, input::scancode::three));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_container_control(), nullptr, input::scancode::four));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_lens_control(), nullptr, input::scancode::five));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_marker_control(), nullptr, input::scancode::six));
float time_scale = ctx->config->get<float>("time_scale"); float time_scale = ctx->config->get<float>("time_scale");
ctx->control_system->get_fast_forward_control()->set_activated_callback ctx->control_system->get_fast_forward_control()->set_activated_callback
( (
@ -1107,35 +968,6 @@ void setup_controls(game::context* ctx)
} }
); );
*/ */
ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_slow_modifier, nullptr, input::scancode::left_ctrl));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_fast_modifier, nullptr, input::scancode::left_shift));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_dolly_forward, nullptr, input::scancode::w));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_dolly_forward, nullptr, input::game_controller_axis::left_y, true));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_dolly_backward, nullptr, input::scancode::s));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_dolly_backward, nullptr, input::game_controller_axis::left_y, false));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_truck_left, nullptr, input::scancode::a));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_truck_left, nullptr, input::game_controller_axis::left_x, true));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_truck_right, nullptr, input::scancode::d));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_truck_right, nullptr, input::game_controller_axis::left_x, false));
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->camera_control_pedestal_up, nullptr, input::mouse_wheel_axis::positive_y));
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->camera_control_pedestal_down, nullptr, input::mouse_wheel_axis::negative_y));
ctx->input_event_router->add_mapping(input::mouse_button_mapping(ctx->camera_control_mouse_rotate, nullptr, 3));
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_left, nullptr, input::mouse_motion_axis::negative_x));
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_right, nullptr, input::mouse_motion_axis::positive_x));
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_down, nullptr, input::mouse_motion_axis::positive_y));
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_up, nullptr, input::mouse_motion_axis::negative_y));
// Make lens tool's model instance unculled, so its shadow is always visible.
scene::model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
if (lens_model_instance)
{
lens_model_instance->set_culling_mask(&ctx->no_cull);
}
} }
void setup_cli(game::context* ctx) void setup_cli(game::context* ctx)
@ -1158,25 +990,8 @@ void setup_callbacks(game::context* ctx)
[ctx](double t, double dt) [ctx](double t, double dt)
{ {
// Update controls // Update controls
ctx->application_controls->update();
ctx->menu_controls->update();
ctx->camera_control_slow_modifier->update();
ctx->camera_control_fast_modifier->update();
ctx->camera_control_mouse_rotate->update();
ctx->camera_control_mouse_left->update();
ctx->camera_control_mouse_right->update();
ctx->camera_control_mouse_down->update();
ctx->camera_control_mouse_up->update();
ctx->camera_control_dolly_forward->update();
ctx->camera_control_dolly_backward->update();
ctx->camera_control_truck_left->update();
ctx->camera_control_truck_right->update();
ctx->camera_control_pedestal_up->update();
ctx->camera_control_pedestal_down->update();
ctx->camera_control_pan_left->update();
ctx->camera_control_pan_right->update();
ctx->camera_control_tilt_up->update();
ctx->camera_control_tilt_down->update();
for (const auto& control: ctx->controls)
control.second->update();
// Update tweens // Update tweens
ctx->time_tween->update(); ctx->time_tween->update();
@ -1184,7 +999,6 @@ void setup_callbacks(game::context* ctx)
ctx->surface_scene->update_tweens(); ctx->surface_scene->update_tweens();
ctx->underground_scene->update_tweens(); ctx->underground_scene->update_tweens();
ctx->ui_scene->update_tweens(); ctx->ui_scene->update_tweens();
ctx->focal_point_tween->update();
// Set time tween time // Set time tween time
(*ctx->time_tween)[1] = t; (*ctx->time_tween)[1] = t;
@ -1216,15 +1030,6 @@ void setup_callbacks(game::context* ctx)
ctx->painting_system->update(t, dt); ctx->painting_system->update(t, dt);
ctx->proteome_system->update(t, dt); ctx->proteome_system->update(t, dt);
//(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point();
auto xf = entity::command::get_world_transform(*ctx->entity_registry, ctx->lens_entity);
//ctx->lens_spot_light->look_at(xf.translation, xf.translation + ctx->sun_direct->get_direction(), {0, 1, 0});
xf = entity::command::get_world_transform(*ctx->entity_registry, ctx->flashlight_entity);
//ctx->flashlight_spot_light->set_transform(xf);
ctx->flashlight_spot_light->look_at(xf.translation, xf.translation + xf.rotation * float3{0, 0, 1}, {0, 0, -1});
ctx->ui_system->update(dt); ctx->ui_system->update(dt);
ctx->render_system->update(t, dt); ctx->render_system->update(t, dt);
ctx->animator->animate(dt); ctx->animator->animate(dt);

+ 2
- 35
src/game/context.hpp View File

@ -192,7 +192,6 @@ struct context
// Surface scene // Surface scene
scene::collection* surface_scene; scene::collection* surface_scene;
scene::camera* surface_camera; scene::camera* surface_camera;
scene::spot_light* lens_spot_light;
// Underground scene // Underground scene
scene::collection* underground_scene; scene::collection* underground_scene;
@ -204,7 +203,6 @@ struct context
timeline* timeline; timeline* timeline;
animator* animator; animator* animator;
tween<double>* time_tween; tween<double>* time_tween;
tween<float3>* focal_point_tween;
animation<float>* radial_transition_in; animation<float>* radial_transition_in;
animation<float>* radial_transition_out; animation<float>* radial_transition_out;
screen_transition* fade_transition; screen_transition* fade_transition;
@ -218,42 +216,11 @@ struct context
input::event_router* input_event_router; input::event_router* input_event_router;
input::mapper* input_mapper; input::mapper* input_mapper;
input::listener* input_listener; input::listener* input_listener;
input::control_set* application_controls;
input::control_set* camera_controls;
input::control_set* menu_controls;
input::control* menu_back_control;
input::control* menu_select_control;
input::control* screenshot_control;
input::control* toggle_fullscreen_control;
input::control* camera_control_mouse_rotate;
input::control* camera_control_mouse_left;
input::control* camera_control_mouse_right;
input::control* camera_control_mouse_down;
input::control* camera_control_mouse_up;
input::control* camera_control_dolly_forward;
input::control* camera_control_dolly_backward;
input::control* camera_control_truck_left;
input::control* camera_control_truck_right;
input::control* camera_control_pedestal_up;
input::control* camera_control_pedestal_down;
input::control* camera_control_pan_left;
input::control* camera_control_pan_right;
input::control* camera_control_tilt_up;
input::control* camera_control_tilt_down;
input::control* camera_control_slow_modifier;
input::control* camera_control_fast_modifier;
std::unordered_map<std::string, input::control*> controls;
// Entities // Entities
entity::registry* entity_registry; entity::registry* entity_registry;
entity::id brush_entity;
entity::id flashlight_entity;
entity::id forceps_entity;
entity::id lens_entity;
entity::id marker_entity;
entity::id container_entity;
entity::id twig_entity;
entity::id focal_point_entity;
std::unordered_map<std::string, entity::id> entities;
// Systems // Systems
entity::system::behavior* behavior_system; entity::system::behavior* behavior_system;

+ 42
- 39
src/game/states/brood.cpp View File

@ -239,14 +239,17 @@ void setup_controls(game::context* ctx)
const float pan_speed = math::radians(8.0f); const float pan_speed = math::radians(8.0f);
const float tilt_speed = pan_speed; const float tilt_speed = pan_speed;
// Dolly forward
ctx->camera_control_dolly_forward->set_active_callback
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"];
ctx->controls["dolly_forward"]->set_active_callback
( (
[ctx, target_eid, three_dof_eid, truck_speed](float value)
[ctx, target_eid, three_dof_eid, truck_speed, move_slow, move_fast](float value)
{ {
if (ctx->camera_control_slow_modifier->is_active())
if (move_slow->is_active())
value *= 0.5f; value *= 0.5f;
if (ctx->camera_control_fast_modifier->is_active())
if (move_fast->is_active())
value *= 2.0f; value *= 2.0f;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
@ -258,13 +261,13 @@ void setup_controls(game::context* ctx)
); );
// Dolly backward // Dolly backward
ctx->camera_control_dolly_backward->set_active_callback
ctx->controls["dolly_backward"]->set_active_callback
( (
[ctx, target_eid, three_dof_eid, truck_speed](float value)
[ctx, target_eid, three_dof_eid, truck_speed, move_slow, move_fast](float value)
{ {
if (ctx->camera_control_slow_modifier->is_active())
if (move_slow->is_active())
value *= 0.5f; value *= 0.5f;
if (ctx->camera_control_fast_modifier->is_active())
if (move_fast->is_active())
value *= 2.0f; value *= 2.0f;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
@ -276,13 +279,13 @@ void setup_controls(game::context* ctx)
); );
// Truck right // Truck right
ctx->camera_control_truck_right->set_active_callback
ctx->controls["truck_right"]->set_active_callback
( (
[ctx, target_eid, three_dof_eid, truck_speed](float value)
[ctx, target_eid, three_dof_eid, truck_speed, move_slow, move_fast](float value)
{ {
if (ctx->camera_control_slow_modifier->is_active())
if (move_slow->is_active())
value *= 0.5f; value *= 0.5f;
if (ctx->camera_control_fast_modifier->is_active())
if (move_fast->is_active())
value *= 2.0f; value *= 2.0f;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
@ -294,13 +297,13 @@ void setup_controls(game::context* ctx)
); );
// Truck left // Truck left
ctx->camera_control_truck_left->set_active_callback
ctx->controls["truck_left"]->set_active_callback
( (
[ctx, target_eid, three_dof_eid, truck_speed](float value)
[ctx, target_eid, three_dof_eid, truck_speed, move_slow, move_fast](float value)
{ {
if (ctx->camera_control_slow_modifier->is_active())
if (move_slow->is_active())
value *= 0.5f; value *= 0.5f;
if (ctx->camera_control_fast_modifier->is_active())
if (move_fast->is_active())
value *= 2.0f; value *= 2.0f;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
@ -312,13 +315,13 @@ void setup_controls(game::context* ctx)
); );
// Pedestal up // Pedestal up
ctx->camera_control_pedestal_up->set_active_callback
ctx->controls["pedestal_up"]->set_active_callback
( (
[ctx, target_eid, pedestal_speed](float value)
[ctx, target_eid, pedestal_speed, move_slow, move_fast](float value)
{ {
if (ctx->camera_control_slow_modifier->is_active())
if (move_slow->is_active())
value *= 0.5f; value *= 0.5f;
if (ctx->camera_control_fast_modifier->is_active())
if (move_fast->is_active())
value *= 2.0f; value *= 2.0f;
const float3 movement = {0.0f, pedestal_speed * value * (1.0f / 60.0f), 0.0f}; const float3 movement = {0.0f, pedestal_speed * value * (1.0f / 60.0f), 0.0f};
@ -327,13 +330,13 @@ void setup_controls(game::context* ctx)
); );
// Pedestal down // Pedestal down
ctx->camera_control_pedestal_down->set_active_callback
ctx->controls["pedestal_down"]->set_active_callback
( (
[ctx, target_eid, pedestal_speed](float value)
[ctx, target_eid, pedestal_speed, move_slow, move_fast](float value)
{ {
if (ctx->camera_control_slow_modifier->is_active())
if (move_slow->is_active())
value *= 0.5f; value *= 0.5f;
if (ctx->camera_control_fast_modifier->is_active())
if (move_fast->is_active())
value *= 2.0f; value *= 2.0f;
const float3 movement = {0.0f, -pedestal_speed * value * (1.0f / 60.0f), 0.0f}; const float3 movement = {0.0f, -pedestal_speed * value * (1.0f / 60.0f), 0.0f};
@ -342,14 +345,14 @@ void setup_controls(game::context* ctx)
); );
// Mouse rotate // Mouse rotate
ctx->camera_control_mouse_rotate->set_activated_callback
ctx->controls["mouse_rotate"]->set_activated_callback
( (
[ctx]() [ctx]()
{ {
ctx->app->set_relative_mouse_mode(true); ctx->app->set_relative_mouse_mode(true);
} }
); );
ctx->camera_control_mouse_rotate->set_deactivated_callback
ctx->controls["mouse_rotate"]->set_deactivated_callback
( (
[ctx]() [ctx]()
{ {
@ -358,11 +361,11 @@ void setup_controls(game::context* ctx)
); );
// Pan left // Pan left
ctx->camera_control_mouse_left->set_active_callback
ctx->controls["mouse_left"]->set_active_callback
( (
[ctx, three_dof_eid, pan_speed](float value)
[ctx, three_dof_eid, pan_speed, mouse_rotate](float value)
{ {
if (!ctx->camera_control_mouse_rotate->is_active())
if (!mouse_rotate->is_active())
return; return;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
@ -371,11 +374,11 @@ void setup_controls(game::context* ctx)
); );
// Pan right // Pan right
ctx->camera_control_mouse_right->set_active_callback
ctx->controls["mouse_right"]->set_active_callback
( (
[ctx, three_dof_eid, pan_speed](float value)
[ctx, three_dof_eid, pan_speed, mouse_rotate](float value)
{ {
if (!ctx->camera_control_mouse_rotate->is_active())
if (!mouse_rotate->is_active())
return; return;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
@ -384,11 +387,11 @@ void setup_controls(game::context* ctx)
); );
// Tilt up // Tilt up
ctx->camera_control_mouse_up->set_active_callback
ctx->controls["mouse_up"]->set_active_callback
( (
[ctx, three_dof_eid, tilt_speed](float value)
[ctx, three_dof_eid, tilt_speed, mouse_rotate](float value)
{ {
if (!ctx->camera_control_mouse_rotate->is_active())
if (!mouse_rotate->is_active())
return; return;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
@ -398,11 +401,11 @@ void setup_controls(game::context* ctx)
); );
// Tilt down // Tilt down
ctx->camera_control_mouse_down->set_active_callback
ctx->controls["mouse_down"]->set_active_callback
( (
[ctx, three_dof_eid, tilt_speed](float value)
[ctx, three_dof_eid, tilt_speed, mouse_rotate](float value)
{ {
if (!ctx->camera_control_mouse_rotate->is_active())
if (!mouse_rotate->is_active())
return; return;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);

+ 183
- 0
src/game/states/loading.cpp View File

@ -46,11 +46,16 @@
#include "resources/resource-manager.hpp" #include "resources/resource-manager.hpp"
#include "scene/ambient-light.hpp" #include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp" #include "scene/directional-light.hpp"
#include "resources/config-file.hpp"
#include "utility/timestamp.hpp"
namespace game { namespace game {
namespace state { namespace state {
namespace loading { namespace loading {
/// Creates or loads control configuration
static void load_controls(game::context* ctx);
/// Creates the universe and solar system. /// Creates the universe and solar system.
static void cosmogenesis(game::context* ctx); static void cosmogenesis(game::context* ctx);
@ -71,6 +76,18 @@ static void colonigenesis(game::context* ctx);
void enter(game::context* ctx) void enter(game::context* ctx)
{ {
// Load controls
ctx->logger->push_task("Loading controls");
try
{
load_controls(ctx);
}
catch (...)
{
ctx->logger->pop_task(EXIT_FAILURE);
}
ctx->logger->pop_task(EXIT_SUCCESS);
// Create universe // Create universe
ctx->logger->push_task("Creating the universe"); ctx->logger->push_task("Creating the universe");
try try
@ -106,6 +123,172 @@ void enter(game::context* ctx)
void exit(game::context* ctx) void exit(game::context* ctx)
{} {}
void load_controls(game::context* ctx)
{
// Toggle fullscreen
if (ctx->controls.find("toggle_fullscreen") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::f11));
ctx->controls["toggle_fullscreen"] = control;
}
ctx->controls["toggle_fullscreen"]->set_activated_callback
(
[ctx]()
{
bool fullscreen = !ctx->app->is_fullscreen();
ctx->app->set_fullscreen(fullscreen);
if (!fullscreen)
{
int2 resolution = ctx->config->get<int2>("windowed_resolution");
ctx->app->resize_window(resolution.x, resolution.y);
}
ctx->config->set<int>("fullscreen", (fullscreen) ? 1 : 0);
}
);
// Screenshot
if (ctx->controls.find("screenshot") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::f12));
ctx->controls["screenshot"] = control;
}
ctx->controls["screenshot"]->set_activated_callback
(
[ctx]()
{
std::string path = ctx->screenshots_path + "antkeeper-" + timestamp() + ".png";
ctx->app->save_frame(path);
}
);
// Menu back
if (ctx->controls.find("menu_back") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::escape));
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::backspace));
ctx->controls["menu_back"] = control;
}
ctx->controls["menu_back"]->set_activated_callback
(
std::bind(&application::close, ctx->app, 0)
);
// Dolly forward
if (ctx->controls.find("dolly_forward") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::w));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(control, nullptr, input::game_controller_axis::left_y, true));
ctx->controls["dolly_forward"] = control;
}
// Dolly backward
if (ctx->controls.find("dolly_backward") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::s));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(control, nullptr, input::game_controller_axis::left_y, false));
ctx->controls["dolly_backward"] = control;
}
// Truck left
if (ctx->controls.find("truck_left") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::a));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(control, nullptr, input::game_controller_axis::left_x, true));
ctx->controls["truck_left"] = control;
}
// Truck right
if (ctx->controls.find("truck_right") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::d));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(control, nullptr, input::game_controller_axis::left_x, false));
ctx->controls["truck_right"] = control;
}
// Pedestal up
if (ctx->controls.find("pedestal_up") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(control, nullptr, input::mouse_wheel_axis::positive_y));
ctx->controls["pedestal_up"] = control;
}
// Pedestal down
if (ctx->controls.find("pedestal_down") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(control, nullptr, input::mouse_wheel_axis::negative_y));
ctx->controls["pedestal_down"] = control;
}
// Move slow
if (ctx->controls.find("move_slow") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::left_ctrl));
ctx->controls["move_slow"] = control;
}
// Move fast
if (ctx->controls.find("move_fast") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::left_shift));
ctx->controls["move_fast"] = control;
}
// Mouse rotate
if (ctx->controls.find("mouse_rotate") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_button_mapping(control, nullptr, 3));
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::left_alt));
ctx->controls["mouse_rotate"] = control;
}
// Mouse left
if (ctx->controls.find("mouse_left") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(control, nullptr, input::mouse_motion_axis::negative_x));
ctx->controls["mouse_left"] = control;
}
// Mouse right
if (ctx->controls.find("mouse_right") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(control, nullptr, input::mouse_motion_axis::positive_x));
ctx->controls["mouse_right"] = control;
}
// Mouse up
if (ctx->controls.find("mouse_up") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(control, nullptr, input::mouse_motion_axis::negative_y));
ctx->controls["mouse_up"] = control;
}
// Mouse down
if (ctx->controls.find("mouse_down") == ctx->controls.end())
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(control, nullptr, input::mouse_motion_axis::positive_y));
ctx->controls["mouse_down"] = control;
}
}
void cosmogenesis(game::context* ctx) void cosmogenesis(game::context* ctx)
{ {
// Init time // Init time

+ 0
- 10
src/renderer/passes/material-pass.cpp View File

@ -55,7 +55,6 @@ material_pass::material_pass(gl::rasterizer* rasterizer, const gl::framebuffer*
fallback_material(nullptr), fallback_material(nullptr),
time_tween(nullptr), time_tween(nullptr),
mouse_position({0.0f, 0.0f}), mouse_position({0.0f, 0.0f}),
focal_point_tween(nullptr),
shadow_map_pass(nullptr), shadow_map_pass(nullptr),
shadow_map(nullptr) shadow_map(nullptr)
{ {
@ -122,7 +121,6 @@ void material_pass::render(render_context* context) const
float time = time_tween->interpolate(context->alpha); float time = time_tween->interpolate(context->alpha);
const float3& camera_position = context->camera_transform.translation; const float3& camera_position = context->camera_transform.translation;
float3 focal_point = (focal_point_tween) ? focal_point_tween->interpolate(context->alpha) : float3{0, 0, 0};
float4x4 view = context->camera->get_view_tween().interpolate(context->alpha); float4x4 view = context->camera->get_view_tween().interpolate(context->alpha);
float4x4 projection = context->camera->get_projection_tween().interpolate(context->alpha); float4x4 projection = context->camera->get_projection_tween().interpolate(context->alpha);
float4x4 view_projection = projection * view; float4x4 view_projection = projection * view;
@ -492,8 +490,6 @@ void material_pass::render(render_context* context) const
parameters->spot_light_attenuations->upload(0, spot_light_attenuations, spot_light_count); parameters->spot_light_attenuations->upload(0, spot_light_attenuations, spot_light_count);
if (parameters->spot_light_cutoffs) if (parameters->spot_light_cutoffs)
parameters->spot_light_cutoffs->upload(0, spot_light_cutoffs, spot_light_count); parameters->spot_light_cutoffs->upload(0, spot_light_cutoffs, spot_light_count);
if (parameters->focal_point)
parameters->focal_point->upload(focal_point);
if (parameters->shadow_map_directional && shadow_map) if (parameters->shadow_map_directional && shadow_map)
parameters->shadow_map_directional->upload(shadow_map); parameters->shadow_map_directional->upload(shadow_map);
@ -548,11 +544,6 @@ void material_pass::set_time_tween(const tween* time)
this->time_tween = time; this->time_tween = time;
} }
void material_pass::set_focal_point_tween(const tween<float3>* focal_point)
{
this->focal_point_tween = focal_point;
}
const material_pass::parameter_set* material_pass::load_parameter_set(const gl::shader_program* program) const const material_pass::parameter_set* material_pass::load_parameter_set(const gl::shader_program* program) const
{ {
// Allocate a new parameter set // Allocate a new parameter set
@ -592,7 +583,6 @@ const material_pass::parameter_set* material_pass::load_parameter_set(const gl::
parameters->spot_light_directions = program->get_input("spot_light_directions"); parameters->spot_light_directions = program->get_input("spot_light_directions");
parameters->spot_light_attenuations = program->get_input("spot_light_attenuations"); parameters->spot_light_attenuations = program->get_input("spot_light_attenuations");
parameters->spot_light_cutoffs = program->get_input("spot_light_cutoffs"); parameters->spot_light_cutoffs = program->get_input("spot_light_cutoffs");
parameters->focal_point = program->get_input("focal_point");
parameters->shadow_map_directional = program->get_input("shadow_map_directional"); parameters->shadow_map_directional = program->get_input("shadow_map_directional");
parameters->shadow_splits_directional = program->get_input("shadow_splits_directional"); parameters->shadow_splits_directional = program->get_input("shadow_splits_directional");
parameters->shadow_matrices_directional = program->get_input("shadow_matrices_directional"); parameters->shadow_matrices_directional = program->get_input("shadow_matrices_directional");

+ 0
- 6
src/renderer/passes/material-pass.hpp View File

@ -52,8 +52,6 @@ public:
/// Sets the time tween, which is interpolated between updates /// Sets the time tween, which is interpolated between updates
void set_time_tween(const tween<double>* time); void set_time_tween(const tween<double>* time);
void set_focal_point_tween(const tween<float3>* focal_point);
const ::shadow_map_pass* shadow_map_pass; const ::shadow_map_pass* shadow_map_pass;
const gl::texture_2d* shadow_map; const gl::texture_2d* shadow_map;
@ -100,8 +98,6 @@ private:
const gl::shader_input* spot_light_attenuations; const gl::shader_input* spot_light_attenuations;
const gl::shader_input* spot_light_cutoffs; const gl::shader_input* spot_light_cutoffs;
const gl::shader_input* focal_point;
const gl::shader_input* shadow_map_directional; const gl::shader_input* shadow_map_directional;
const gl::shader_input* shadow_splits_directional; const gl::shader_input* shadow_splits_directional;
const gl::shader_input* shadow_matrices_directional; const gl::shader_input* shadow_matrices_directional;
@ -113,7 +109,6 @@ private:
const material* fallback_material; const material* fallback_material;
const tween<double>* time_tween; const tween<double>* time_tween;
float2 mouse_position; float2 mouse_position;
const tween<float3>* focal_point_tween;
int max_ambient_light_count; int max_ambient_light_count;
int max_point_light_count; int max_point_light_count;
@ -142,4 +137,3 @@ private:
}; };
#endif // ANTKEEPER_MATERIAL_PASS_HPP #endif // ANTKEEPER_MATERIAL_PASS_HPP

Loading…
Cancel
Save