Browse Source

Remove obsolete control system

master
C. J. Howard 3 years ago
parent
commit
c2b1058f55
14 changed files with 34 additions and 1165 deletions
  1. +0
    -77
      src/animation/camera-rig.cpp
  2. +0
    -120
      src/animation/camera-rig.hpp
  3. +0
    -224
      src/animation/orbit-cam.cpp
  4. +0
    -125
      src/animation/orbit-cam.hpp
  5. +0
    -242
      src/entity/systems/control.cpp
  6. +0
    -270
      src/entity/systems/control.hpp
  7. +2
    -12
      src/entity/systems/tool.cpp
  8. +0
    -3
      src/entity/systems/tool.hpp
  9. +7
    -3
      src/entity/systems/ui.cpp
  10. +22
    -38
      src/game/bootloader.cpp
  11. +0
    -3
      src/game/context.hpp
  12. +3
    -45
      src/game/states/brood.cpp
  13. +0
    -2
      src/game/states/forage.cpp
  14. +0
    -1
      src/game/states/nuptial-flight.cpp

+ 0
- 77
src/animation/camera-rig.cpp View File

@ -1,77 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "animation/camera-rig.hpp"
#include "math/constants.hpp"
#include "configuration.hpp"
#include <algorithm>
#include <cmath>
camera_rig::camera_rig():
camera(nullptr),
transform(math::identity_transform<float>),
forward(global_forward),
right(global_right),
up(global_up)
{}
void camera_rig::attach(scene::camera* camera)
{
this->camera = camera;
if (camera != nullptr)
{
camera->set_transform(transform);
}
}
void camera_rig::detach()
{
camera = nullptr;
}
void camera_rig::update_transform(const transform_type& transform)
{
this->transform = transform;
// Calculate orthonormal basis
forward = transform.rotation * global_forward;
up = transform.rotation * global_up;
right = transform.rotation * global_right;
if (camera != nullptr)
{
camera->set_transform(transform);
}
}
void camera_rig::update_projection(float fov, float aspect_ratio, float clip_near, float clip_far)
{
if (camera != nullptr)
{
camera->set_perspective(fov, aspect_ratio, clip_near, clip_far);
}
}
void camera_rig::update_projection(float clip_left, float clip_right, float clip_bottom, float clip_top, float clip_near, float clip_far)
{
if (camera != nullptr)
{
camera->set_orthographic(clip_left, clip_right, clip_bottom, clip_top, clip_near, clip_far);
}
}

+ 0
- 120
src/animation/camera-rig.hpp View File

@ -1,120 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CAMERA_RIG_HPP
#define ANTKEEPER_CAMERA_RIG_HPP
#include "math/quaternion-type.hpp"
#include "math/transform-type.hpp"
#include "scene/camera.hpp"
#include "utility/fundamental-types.hpp"
/**
* Abstract base class for camera rigs which control the movement of cameras.
*/
class camera_rig
{
public:
typedef math::quaternion<float> quaternion_type;
typedef math::transform<float> transform_type;
camera_rig();
/**
* Updates the rig.
*
* @param dt Delta time.
*/
virtual void update(float dt) = 0;
/**
* Attaches a camera to the rig.
*
* @param camera Camera to attach.
*/
void attach(scene::camera* camera);
/**
* Detaches the camera from the rig.
*/
void detach();
/**
* Returns the attached camera.
*/
const scene::camera* get_camera() const;
const float3& get_translation() const;
const quaternion_type& get_rotation() const;
const float3& get_forward() const;
const float3& get_right() const;
const float3& get_up() const;
protected:
/**
* Updates the transform of the camera
*/
void update_transform(const transform_type& transform);
void update_projection(float fov, float aspect_ratio, float clip_near, float clip_far);
void update_projection(float clip_left, float clip_right, float clip_bottom, float clip_top, float clip_near, float clip_far);
private:
scene::camera* camera;
transform_type transform;
float3 forward;
float3 right;
float3 up;
};
inline const scene::camera* camera_rig::get_camera() const
{
return camera;
}
inline const float3& camera_rig::get_translation() const
{
return transform.translation;
}
inline const typename camera_rig::quaternion_type& camera_rig::get_rotation() const
{
return transform.rotation;
}
inline const float3& camera_rig::get_forward() const
{
return forward;
}
inline const float3& camera_rig::get_right() const
{
return right;
}
inline const float3& camera_rig::get_up() const
{
return up;
}
#endif // ANTKEEPER_CAMERA_RIG_HPP

+ 0
- 224
src/animation/orbit-cam.cpp View File

@ -1,224 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "animation/orbit-cam.hpp"
#include "scene/camera.hpp"
#include "math/math.hpp"
#include <algorithm>
#include <cmath>
#include <limits>
#include <iostream>
orbit_cam::orbit_cam():
azimuth_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}),
elevation_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}),
focal_distance_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}),
fov_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}),
clip_near_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}),
clip_far_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()})
{
// Make all springs critically-damped
focal_point_spring.z = 1.0f;
azimuth_spring.z = 1.0f;
elevation_spring.z = 1.0f;
zoom_spring.z = 1.0f;
// Init spring oscillation frequencies to 1 rad/s
focal_point_spring.w = math::two_pi<float>;
azimuth_spring.w = math::two_pi<float>;
elevation_spring.w = math::two_pi<float>;
zoom_spring.w = math::two_pi<float>;
// Zero spring values and velocities
focal_point_spring.x1 = {0.0f, 0.0f, 0.0f};
azimuth_spring.x1 = 0.0f;
elevation_spring.x1 = 0.0f;
zoom_spring.x1 = 0.0f;
reset_springs();
}
orbit_cam::~orbit_cam()
{}
void orbit_cam::update(float dt)
{
if (!get_camera())
{
return;
}
// Solve springs
solve_numeric_spring<float3, float>(focal_point_spring, dt);
solve_numeric_spring<float, float>(azimuth_spring, dt);
solve_numeric_spring<float, float>(elevation_spring, dt);
solve_numeric_spring<float, float>(zoom_spring, dt);
// Calculate zoom-dependent variables
float focal_distance = math::log_lerp<float>(focal_distance_limits[1], focal_distance_limits[0], zoom_spring.x0);
float fov = math::log_lerp<float>(fov_limits[1], fov_limits[0], zoom_spring.x0);
float clip_near = math::log_lerp<float>(clip_near_limits[1], clip_near_limits[0], zoom_spring.x0);
float clip_far = math::log_lerp<float>(clip_far_limits[1], clip_far_limits[0], zoom_spring.x0);
// Calculate camera transform
transform_type transform = math::identity_transform<float>;
// Determine rotation
azimuth_rotation = math::angle_axis(azimuth_spring.x0, float3{0.0f, 1.0f, 0.0f});
elevation_rotation = math::angle_axis(elevation_spring.x0, float3{-1.0f, 0.0f, 0.0f});
transform.rotation = math::normalize(azimuth_rotation * elevation_rotation);
// Determine translation
transform.translation = focal_point_spring.x0 + transform.rotation * float3{0.0f, 0.0f, focal_distance};
// Update camera transform
update_transform(transform);
// Update camera projection
update_projection(fov, aspect_ratio, clip_near, clip_far);
}
void orbit_cam::move(const float3& translation)
{
set_target_focal_point(focal_point_spring.x1 + translation);
}
void orbit_cam::pan(float angle)
{
set_target_azimuth(azimuth_spring.x1 + angle);
}
void orbit_cam::tilt(float angle)
{
set_target_elevation(elevation_spring.x1 + angle);
}
void orbit_cam::zoom(float factor)
{
set_target_zoom(zoom_spring.x1 + factor);
}
void orbit_cam::reset_springs()
{
// Reset values
focal_point_spring.x0 = focal_point_spring.x1;
azimuth_spring.x0 = azimuth_spring.x1;
elevation_spring.x0 = elevation_spring.x1;
zoom_spring.x0 = zoom_spring.x1;
// Reset velocities
focal_point_spring.v = {0.0f, 0.0f, 0.0f};
azimuth_spring.v = 0.0f;
elevation_spring.v = 0.0f;
zoom_spring.v = 0.0f;
}
void orbit_cam::set_aspect_ratio(float ratio)
{
aspect_ratio = ratio;
}
void orbit_cam::set_focal_point(const float3& point)
{
focal_point_spring.x0 = point;
}
void orbit_cam::set_azimuth(float angle)
{
azimuth_spring.x0 = std::max<float>(azimuth_limits[0], std::min<float>(azimuth_limits[1], angle));
}
void orbit_cam::set_elevation(float angle)
{
elevation_spring.x0 = std::max<float>(elevation_limits[0], std::min<float>(elevation_limits[1], angle));
}
void orbit_cam::set_zoom(float factor)
{
zoom_spring.x0 = std::max<float>(0.0f, std::min<float>(1.0f, factor));
}
void orbit_cam::set_target_focal_point(const float3& point)
{
focal_point_spring.x1 = point;
}
void orbit_cam::set_target_azimuth(float angle)
{
azimuth_spring.x1 = std::max<float>(azimuth_limits[0], std::min<float>(azimuth_limits[1], angle));
}
void orbit_cam::set_target_elevation(float angle)
{
elevation_spring.x1 = std::max<float>(elevation_limits[0], std::min<float>(elevation_limits[1], angle));
}
void orbit_cam::set_target_zoom(float factor)
{
zoom_spring.x1 = std::max<float>(0.0f, std::min<float>(1.0f, factor));
}
void orbit_cam::set_azimuth_limits(const std::array<float, 2>& limits)
{
azimuth_limits = limits;
}
void orbit_cam::set_elevation_limits(const std::array<float, 2>& limits)
{
elevation_limits = limits;
}
void orbit_cam::set_focal_distance_limits(const std::array<float, 2>& limits)
{
focal_distance_limits = limits;
}
void orbit_cam::set_fov_limits(const std::array<float, 2>& limits)
{
fov_limits = limits;
}
void orbit_cam::set_clip_near_limits(const std::array<float, 2>& limits)
{
clip_near_limits = limits;
}
void orbit_cam::set_clip_far_limits(const std::array<float, 2>& limits)
{
clip_far_limits = limits;
}
void orbit_cam::set_focal_point_oscillation(float frequency)
{
focal_point_spring.w = frequency;
}
void orbit_cam::set_azimuth_oscillation(float frequency)
{
azimuth_spring.w = frequency;
}
void orbit_cam::set_elevation_oscillation(float frequency)
{
elevation_spring.w = frequency;
}
void orbit_cam::set_zoom_oscillation(float frequency)
{
zoom_spring.w = frequency;
}

+ 0
- 125
src/animation/orbit-cam.hpp View File

@ -1,125 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ORBIT_CAM_HPP
#define ANTKEEPER_ORBIT_CAM_HPP
#include "camera-rig.hpp"
#include "animation/spring.hpp"
#include <array>
/**
* Rig which orbits around a focal point.
*/
class orbit_cam: public camera_rig
{
public:
orbit_cam();
virtual ~orbit_cam();
virtual void update(float dt);
/// @param direction Specifies the movement direction and speed scale on the XZ plane
void move(const float3& translation);
void pan(float angle);
void tilt(float angle);
void zoom(float factor);
void reset_springs();
void set_aspect_ratio(float ratio);
void set_focal_point(const float3& point);
void set_azimuth(float angle);
void set_elevation(float angle);
void set_zoom(float factor);
void set_target_focal_point(const float3& point);
void set_target_azimuth(float angle);
void set_target_elevation(float angle);
void set_target_zoom(float factor);
void set_azimuth_limits(const std::array<float, 2>& limits);
void set_elevation_limits(const std::array<float, 2>& limits);
void set_focal_distance_limits(const std::array<float, 2>& limits);
void set_fov_limits(const std::array<float, 2>& limits);
void set_clip_near_limits(const std::array<float, 2>& limits);
void set_clip_far_limits(const std::array<float, 2>& limits);
void set_focal_point_oscillation(float frequency);
void set_azimuth_oscillation(float frequency);
void set_elevation_oscillation(float frequency);
void set_zoom_oscillation(float frequency);
const float3& get_focal_point() const;
float get_azimuth() const;
float get_elevation() const;
float get_zoom() const;
const quaternion_type& get_azimuth_rotation() const;
const quaternion_type& get_elevation_rotation() const;
private:
float aspect_ratio;
numeric_spring<float3, float> focal_point_spring;
numeric_spring<float, float> azimuth_spring;
numeric_spring<float, float> elevation_spring;
numeric_spring<float, float> zoom_spring;
std::array<float, 2> azimuth_limits;
std::array<float, 2> elevation_limits;
std::array<float, 2> focal_distance_limits;
std::array<float, 2> fov_limits;
std::array<float, 2> clip_near_limits;
std::array<float, 2> clip_far_limits;
quaternion_type azimuth_rotation;
quaternion_type elevation_rotation;
};
inline const float3& orbit_cam::get_focal_point() const
{
return focal_point_spring.x0;
}
inline float orbit_cam::get_azimuth() const
{
return azimuth_spring.x0;
}
inline float orbit_cam::get_elevation() const
{
return elevation_spring.x0;
}
inline float orbit_cam::get_zoom() const
{
return zoom_spring.x0;
}
inline const typename camera_rig::quaternion_type& orbit_cam::get_azimuth_rotation() const
{
return azimuth_rotation;
}
inline const typename camera_rig::quaternion_type& orbit_cam::get_elevation_rotation() const
{
return elevation_rotation;
}
#endif // ANTKEEPER_ORBIT_CAM_HPP

+ 0
- 242
src/entity/systems/control.cpp View File

@ -1,242 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "control.hpp"
#include "input/control.hpp"
#include "geom/intersection.hpp"
#include "animation/ease.hpp"
#include "math/math.hpp"
#include "entity/commands.hpp"
#include "entity/systems/camera.hpp"
#include "animation/orbit-cam.hpp"
#include "../../nest.hpp"
#include <iostream>
namespace entity {
namespace system {
control::control(entity::registry& registry):
updatable(registry)
{
control_set.add_control(&move_forward_control);
control_set.add_control(&move_back_control);
control_set.add_control(&move_right_control);
control_set.add_control(&move_left_control);
control_set.add_control(&rotate_ccw_control);
control_set.add_control(&rotate_cw_control);
control_set.add_control(&tilt_up_control);
control_set.add_control(&tilt_down_control);
control_set.add_control(&zoom_in_control);
control_set.add_control(&zoom_out_control);
control_set.add_control(&adjust_camera_control);
control_set.add_control(&ascend_control);
control_set.add_control(&descend_control);
control_set.add_control(&toggle_view_control);
control_set.add_control(&tool_menu_control);
control_set.add_control(&equip_lens_control);
control_set.add_control(&equip_brush_control);
control_set.add_control(&equip_forceps_control);
control_set.add_control(&equip_marker_control);
control_set.add_control(&equip_container_control);
control_set.add_control(&equip_twig_control);
control_set.add_control(&next_marker_control);
control_set.add_control(&previous_marker_control);
control_set.add_control(&use_tool_control);
control_set.add_control(&fast_forward_control);
control_set.add_control(&rewind_control);
control_set.add_control(&exposure_increase_control);
control_set.add_control(&exposure_decrease_control);
// Set deadzone at 15% for all controls
const std::list<input::control*>* controls = control_set.get_controls();
for (input::control* control: *controls)
{
control->set_deadzone(0.15f);
}
/*
zoom_speed = 5.0f; //1
min_elevation = math::radians(-85.0f);
max_elevation = math::radians(85.0f);
near_focal_distance = 2.0f;
far_focal_distance = 200.0f;
near_movement_speed = 10.0f;
far_movement_speed = 80.0f;
near_fov = math::radians(80.0f);
far_fov = math::radians(35.0f);
near_clip_near = 0.1f;
far_clip_near = 5.0f;
near_clip_far = 100.0f;
far_clip_far = 2000.0f;
nest = nullptr;
mouse_angle = 0.0f;
old_mouse_angle = mouse_angle;
flashlight_turns = 0.0f;
flashlight_turns_i = 0;
flashlight_turns_f = 0.0f;
*/
}
void control::update(double t, double dt)
{
/*
// Zoom camera
if (zoom_in_control.is_active())
camera_system->zoom(zoom_speed * dt);
if (zoom_out_control.is_active())
camera_system->zoom(-zoom_speed * dt);
// Rotate camera
const float rotation_speed = math::radians(270.0f);
if (rotate_ccw_control.is_active())
camera_system->pan(rotation_speed * dt * std::min<float>(1.0f, rotate_ccw_control.get_current_value()));
if (rotate_cw_control.is_active())
camera_system->pan(-rotation_speed * dt * std::min<float>(1.0f, rotate_cw_control.get_current_value()));
// Exposure
if (camera_system->get_camera())
{
const float exposure = camera_system->get_camera()->get_exposure();
const float exposure_rate = 0.1f;
if (exposure_increase_control.is_active())
{
camera_system->get_camera()->set_exposure(exposure + exposure_rate);
std::cout << "exposure: " << (exposure + exposure_rate) << std::endl;
}
if (exposure_decrease_control.is_active())
{
camera_system->get_camera()->set_exposure(exposure - exposure_rate);
std::cout << "exposure: " << (exposure - exposure_rate) << std::endl;
}
}
// Move camera
float3 movement{0.0f, 0.0f, 0.0f};
if (move_right_control.is_active())
movement.x += move_right_control.get_current_value();
if (move_left_control.is_active())
movement.x -= move_left_control.get_current_value();
if (move_forward_control.is_active())
movement.z -= move_forward_control.get_current_value();
if (move_back_control.is_active())
movement.z += move_back_control.get_current_value();
if (math::length_squared(movement) != 0.0f)
{
std::array<float, 2> speed_limits = {15.0f, 100.0f};
float zoom = camera_system->get_orbit_cam()->get_zoom();
float max_speed = math::log_lerp(speed_limits[1], speed_limits[0], zoom) * dt;
float speed = std::min<float>(max_speed, math::length(movement * max_speed));
movement = math::normalize(movement) * speed;
const math::quaternion<float>& azimuth_rotation = camera_system->get_orbit_cam()->get_azimuth_rotation();
movement = azimuth_rotation * movement;
command::translate(registry, camera_subject_entity, movement);
}
// Turn flashlight
float2 viewport_center = {(viewport[0] + viewport[2]) * 0.5f, (viewport[1] + viewport[3]) * 0.5f};
float2 mouse_direction = math::normalize(mouse_position - viewport_center);
old_mouse_angle = mouse_angle;
mouse_angle = std::atan2(-mouse_direction.y, mouse_direction.x);
if (mouse_angle - old_mouse_angle != 0.0f)
{
if (mouse_angle - old_mouse_angle <= -math::pi<float>)
flashlight_turns_i -= 1;
else if (mouse_angle - old_mouse_angle >= math::pi<float>)
flashlight_turns_i += 1;
flashlight_turns_f = (mouse_angle) / math::two_pi<float>;
flashlight_turns = flashlight_turns_i - flashlight_turns_f;
if (flashlight_entity != entt::null && nest)
{
math::transform<float> flashlight_transform = math::identity_transform<float>;
float flashlight_depth = nest->get_shaft_depth(*nest->get_central_shaft(), flashlight_turns);
flashlight_transform.translation = {0.0f, -flashlight_depth, 0.0f};
flashlight_transform.rotation = math::angle_axis(-flashlight_turns * math::two_pi<float> + math::half_pi<float>, {0, 1, 0});
command::set_transform(registry, flashlight_entity, flashlight_transform, false);
if (underground_camera)
{
underground_camera->look_at({0, -flashlight_depth + 50.0f, 0}, {0, -flashlight_depth, 0}, {0, 0, -1});
}
}
}
*/
}
void control::set_viewport(const float4& viewport)
{
this->viewport = viewport;
}
void control::handle_event(const mouse_moved_event& event)
{
/*
if (adjust_camera_control.is_active())
{
bool invert_x = true;
bool invert_y = false;
float rotation_factor = event.dx;
float elevation_factor = event.dy;
if (invert_x)
{
rotation_factor *= -1.0f;
}
if (invert_y)
{
elevation_factor *= -1.0f;
}
float rotation = math::radians(15.0f) * rotation_factor * timestep;
float tilt = math::radians(15.0f) * elevation_factor * timestep;
camera_system->pan(rotation);
camera_system->tilt(tilt);
}
else if (!adjust_camera_control.was_active())
{
mouse_position[0] = event.x;
mouse_position[1] = event.y;
}
*/
}
void control::handle_event(const window_resized_event& event)
{
set_viewport({0.0f, 0.0f, static_cast<float>(event.w), static_cast<float>(event.h)});
}
} // namespace system
} // namespace entity

+ 0
- 270
src/entity/systems/control.hpp View File

@ -1,270 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ENTITY_SYSTEM_CONTROL_HPP
#define ANTKEEPER_ENTITY_SYSTEM_CONTROL_HPP
#include "entity/systems/updatable.hpp"
#include "entity/id.hpp"
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "event/window-events.hpp"
#include "input/control.hpp"
#include "input/control-set.hpp"
#include "scene/model-instance.hpp"
#include "utility/fundamental-types.hpp"
#include "scene/camera.hpp"
class nest;
namespace entity {
namespace system {
class camera;
class control:
public updatable,
public event_handler<mouse_moved_event>,
public event_handler<window_resized_event>
{
public:
control(entity::registry& registry);
virtual void update(double t, double dt);
void set_viewport(const float4& viewport);
input::control_set* get_control_set();
input::control* get_move_forward_control();
input::control* get_move_back_control();
input::control* get_move_left_control();
input::control* get_move_right_control();
input::control* get_rotate_ccw_control();
input::control* get_rotate_cw_control();
input::control* get_tilt_up_control();
input::control* get_tilt_down_control();
input::control* get_zoom_in_control();
input::control* get_zoom_out_control();
input::control* get_adjust_camera_control();
input::control* get_ascend_control();
input::control* get_descend_control();
input::control* get_toggle_view_control();
input::control* get_tool_menu_control();
input::control* get_equip_lens_control();
input::control* get_equip_brush_control();
input::control* get_equip_forceps_control();
input::control* get_equip_marker_control();
input::control* get_equip_container_control();
input::control* get_equip_twig_control();
input::control* get_next_marker_control();
input::control* get_previous_marker_control();
input::control* get_use_tool_control();
input::control* get_fast_forward_control();
input::control* get_rewind_control();
input::control* get_exposure_increase_control();
input::control* get_exposure_decrease_control();
private:
virtual void handle_event(const mouse_moved_event& event);
virtual void handle_event(const window_resized_event& event);
input::control_set control_set;
input::control move_forward_control;
input::control move_back_control;
input::control move_left_control;
input::control move_right_control;
input::control rotate_ccw_control;
input::control rotate_cw_control;
input::control tilt_up_control;
input::control tilt_down_control;
input::control zoom_in_control;
input::control zoom_out_control;
input::control adjust_camera_control;
input::control ascend_control;
input::control descend_control;
input::control toggle_view_control;
input::control tool_menu_control;
input::control equip_lens_control;
input::control equip_brush_control;
input::control equip_forceps_control;
input::control equip_marker_control;
input::control equip_container_control;
input::control equip_twig_control;
input::control next_marker_control;
input::control previous_marker_control;
input::control use_tool_control;
input::control fast_forward_control;
input::control rewind_control;
input::control exposure_increase_control;
input::control exposure_decrease_control;
float2 mouse_position;
float4 viewport;
};
inline input::control_set* control::get_control_set()
{
return &control_set;
}
inline input::control* control::get_move_forward_control()
{
return &move_forward_control;
}
inline input::control* control::get_move_back_control()
{
return &move_back_control;
}
inline input::control* control::get_move_left_control()
{
return &move_left_control;
}
inline input::control* control::get_move_right_control()
{
return &move_right_control;
}
inline input::control* control::get_rotate_ccw_control()
{
return &rotate_ccw_control;
}
inline input::control* control::get_rotate_cw_control()
{
return &rotate_cw_control;
}
inline input::control* control::get_tilt_up_control()
{
return &tilt_up_control;
}
inline input::control* control::get_tilt_down_control()
{
return &tilt_down_control;
}
inline input::control* control::get_zoom_in_control()
{
return &zoom_in_control;
}
inline input::control* control::get_zoom_out_control()
{
return &zoom_out_control;
}
inline input::control* control::get_adjust_camera_control()
{
return &adjust_camera_control;
}
inline input::control* control::get_ascend_control()
{
return &ascend_control;
}
inline input::control* control::get_descend_control()
{
return &descend_control;
}
inline input::control* control::get_toggle_view_control()
{
return &toggle_view_control;
}
inline input::control* control::get_tool_menu_control()
{
return &tool_menu_control;
}
inline input::control* control::get_equip_lens_control()
{
return &equip_lens_control;
}
inline input::control* control::get_equip_brush_control()
{
return &equip_brush_control;
}
inline input::control* control::get_equip_forceps_control()
{
return &equip_forceps_control;
}
inline input::control* control::get_equip_marker_control()
{
return &equip_marker_control;
}
inline input::control* control::get_equip_container_control()
{
return &equip_container_control;
}
inline input::control* control::get_equip_twig_control()
{
return &equip_twig_control;
}
inline input::control* control::get_next_marker_control()
{
return &next_marker_control;
}
inline input::control* control::get_previous_marker_control()
{
return &previous_marker_control;
}
inline input::control* control::get_use_tool_control()
{
return &use_tool_control;
}
inline input::control* control::get_fast_forward_control()
{
return &fast_forward_control;
}
inline input::control* control::get_rewind_control()
{
return &rewind_control;
}
inline input::control* control::get_exposure_increase_control()
{
return &exposure_increase_control;
}
inline input::control* control::get_exposure_decrease_control()
{
return &exposure_decrease_control;
}
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ENTITY_SYSTEM_CONTROL_HPP

+ 2
- 12
src/entity/systems/tool.cpp View File

@ -23,7 +23,6 @@
#include "entity/components/transform.hpp"
#include "event/event-dispatcher.hpp"
#include "game/events/tool-events.hpp"
#include "animation/orbit-cam.hpp"
#include "animation/ease.hpp"
#include "geom/mesh.hpp"
#include "geom/intersection.hpp"
@ -37,7 +36,6 @@ tool::tool(entity::registry& registry, ::event_dispatcher* event_dispatcher):
updatable(registry),
event_dispatcher(event_dispatcher),
camera(nullptr),
orbit_cam(orbit_cam),
viewport{0, 0, 0, 0},
mouse_position{0, 0},
pick_enabled(true),
@ -95,6 +93,7 @@ tool::~tool()
void tool::update(double t, double dt)
{
/*
if (active_tool == entt::null)
return;
@ -174,11 +173,6 @@ void tool::update(double t, double dt)
registry.view<component::tool, component::transform>().each(
[&](entity::id entity_id, auto& tool, auto& transform)
{
/*
if (registry.has<component::model>(entity_id))
{
}*/
if (!tool.active)
return;
@ -221,6 +215,7 @@ void tool::update(double t, double dt)
});
was_pick_enabled = pick_enabled;
*/
}
void tool::set_camera(const scene::camera* camera)
@ -228,11 +223,6 @@ void tool::set_camera(const scene::camera* camera)
this->camera = camera;
}
void tool::set_orbit_cam(const ::orbit_cam* orbit_cam)
{
this->orbit_cam = orbit_cam;
}
void tool::set_viewport(const float4& viewport)
{
this->viewport = viewport;

+ 0
- 3
src/entity/systems/tool.hpp View File

@ -30,7 +30,6 @@
#include "animation/animation.hpp"
#include "scene/camera.hpp"
class orbit_cam;
class event_dispatcher;
namespace entity {
@ -47,7 +46,6 @@ public:
virtual void update(double t, double dt);
void set_camera(const scene::camera* camera);
void set_orbit_cam(const orbit_cam* camera);
void set_viewport(const float4& viewport);
void set_pick(bool enabled);
void set_sun_direction(const float3& direction);
@ -64,7 +62,6 @@ private:
event_dispatcher* event_dispatcher;
const scene::camera* camera;
const orbit_cam* orbit_cam;
float4 viewport;
float2 mouse_position;
bool was_pick_enabled;

+ 7
- 3
src/entity/systems/ui.cpp View File

@ -76,8 +76,12 @@ void ui::set_viewport(const float4& viewport)
void ui::set_tool_menu_control(input::control* control)
{
tool_menu_control = control;
tool_menu_control->set_activated_callback(std::bind(&ui::open_tool_menu, this));
tool_menu_control->set_deactivated_callback(std::bind(&ui::close_tool_menu, this));
if (tool_menu_control)
{
tool_menu_control->set_activated_callback(std::bind(&ui::open_tool_menu, this));
tool_menu_control->set_deactivated_callback(std::bind(&ui::close_tool_menu, this));
}
}
void ui::set_camera(scene::camera* camera)
@ -98,7 +102,7 @@ void ui::set_scene(scene::collection* collection)
void ui::handle_event(const mouse_moved_event& event)
{
if (tool_menu_control->is_active())
if (tool_menu_control && tool_menu_control->is_active())
{
tool_selection_vector.x += event.dx;
tool_selection_vector.y += event.dy;

+ 22
- 38
src/game/bootloader.cpp View File

@ -59,7 +59,6 @@
#include "entity/systems/camera.hpp"
#include "entity/systems/collision.hpp"
#include "entity/systems/constraint.hpp"
#include "entity/systems/control.hpp"
#include "entity/systems/locomotion.hpp"
#include "entity/systems/nest.hpp"
#include "entity/systems/snapping.hpp"
@ -903,20 +902,11 @@ void setup_systems(game::context* ctx)
ctx->render_system->add_layer(ctx->ui_scene);
ctx->render_system->set_renderer(ctx->renderer);
// Setup control system
ctx->control_system = new entity::system::control(*ctx->entity_registry);
ctx->control_system->set_viewport(viewport);
ctx->control_system->get_adjust_camera_control()->set_activated_callback([ctx](){ ctx->app->set_relative_mouse_mode(true); ctx->tool_system->set_pick(false); });
ctx->control_system->get_adjust_camera_control()->set_deactivated_callback([ctx](){ ctx->app->set_relative_mouse_mode(false); ctx->tool_system->set_pick(true); });
event_dispatcher->subscribe<mouse_moved_event>(ctx->control_system);
event_dispatcher->subscribe<window_resized_event>(ctx->control_system);
// Setup UI system
ctx->ui_system = new entity::system::ui(ctx->resource_manager);
ctx->ui_system->set_camera(ctx->ui_camera);
ctx->ui_system->set_scene(ctx->ui_scene);
ctx->ui_system->set_viewport(viewport);
ctx->ui_system->set_tool_menu_control(ctx->control_system->get_tool_menu_control());
event_dispatcher->subscribe<mouse_moved_event>(ctx->ui_system);
event_dispatcher->subscribe<window_resized_event>(ctx->ui_system);
}
@ -1006,12 +996,12 @@ void setup_controls(game::context* ctx)
ctx->camera_control_tilt_up = new input::control();
ctx->camera_control_tilt_down = new input::control();
ctx->camera_controls = ctx->control_system->get_control_set();
// 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));
/*
// Add menu control mappings
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));
@ -1094,31 +1084,6 @@ void setup_controls(game::context* ctx)
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));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_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));
//ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_next_marker_control(), nullptr, input::scancode::right_brace));
//ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_previous_marker_control(), nullptr, input::scancode::left_brace));
float time_scale = ctx->config->get<float>("time_scale");
ctx->control_system->get_fast_forward_control()->set_activated_callback
(
@ -1152,7 +1117,28 @@ void setup_controls(game::context* ctx)
ctx->astronomy_system->set_time_scale(time_scale / seconds_per_day);
}
);
*/
ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_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)
@ -1184,8 +1170,6 @@ void setup_callbacks(game::context* ctx)
// Update controls
ctx->application_controls->update();
ctx->menu_controls->update();
ctx->camera_controls->update();
ctx->control_system->update(t, dt);
ctx->camera_control_modifier->update();
ctx->camera_control_mouse_rotate->update();
ctx->camera_control_mouse_left->update();

+ 0
- 3
src/game/context.hpp View File

@ -53,7 +53,6 @@ class config_file;
class final_pass;
class material;
class material_pass;
class orbit_cam;
class pheromone_matrix;
class resource_manager;
class screen_transition;
@ -94,7 +93,6 @@ namespace entity
class collision;
class constraint;
class locomotion;
class control;
class snapping;
class camera;
class nest;
@ -262,7 +260,6 @@ struct context
entity::system::camera* camera_system;
entity::system::collision* collision_system;
entity::system::constraint* constraint_system;
entity::system::control* control_system;
entity::system::locomotion* locomotion_system;
entity::system::nest* nest_system;
entity::system::snapping* snapping_system;

+ 3
- 45
src/game/states/brood.cpp View File

@ -28,9 +28,6 @@
#include "entity/components/constraints/spring-to.hpp"
#include "entity/components/constraints/three-dof.hpp"
#include "entity/components/constraint-stack.hpp"
#include "entity/systems/control.hpp"
#include "entity/systems/camera.hpp"
#include "entity/systems/tool.hpp"
#include "animation/screen-transition.hpp"
#include "animation/ease.hpp"
#include "resources/resource-manager.hpp"
@ -164,26 +161,6 @@ void setup_camera(game::context* ctx)
target_transform.world = target_transform.local;
target_transform.warp = true;
ctx->entity_registry->assign<entity::component::transform>(target_eid, target_transform);
/*
// 3DOF constraint
entity::id three_dof_eid = entity::command::create(*ctx->entity_registry, "underground_cam_3dof");
entity::component::constraint::three_dof three_dof;
three_dof.yaw = 0.0f;
three_dof.pitch = 0.0f;
three_dof.roll = 0.0f;
ctx->entity_registry->assign<entity::component::constraint::three_dof>(three_dof_eid, three_dof);
entity::component::constraint_stack_node node;
node.active = true;
node.weight = 1.0f;
node.next = entt::null;
ctx->entity_registry->assign<entity::component::constraint_stack_node>(three_dof_eid, node);
// Create target constraint stack component
entity::component::constraint_stack constraint_stack;
constraint_stack.head = three_dof_eid;
ctx->entity_registry->assign<entity::component::constraint_stack>(target_eid, constraint_stack);
*/
}
// Create camera entity
@ -228,9 +205,6 @@ void setup_camera(game::context* ctx)
spring.translation = {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, 1.0f, math::two_pi<float>};
spring.translation.w = hz_to_rads(8.0f);
//spring.rotation = {{1.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}, 1.0f, math::two_pi<float>};
//spring.rotation.w = hz_to_rads(5.0f);
spring.spring_translation = true;
spring.spring_rotation = false;
ctx->entity_registry->assign<entity::component::constraint::spring_to>(spring_constraint_eid, spring);
@ -249,22 +223,6 @@ void setup_camera(game::context* ctx)
ctx->entity_registry->assign<entity::component::constraint_stack>(camera_eid, constraint_stack);
}
/*
entity::component::orbit_rig orbit;
orbit.azimuth_min = -std::numeric_limits<float>::infinity();
orbit.azimuth_max = std::numeric_limits<float>::infinity();
orbit.elevation_min = math::radians(-89.0f);
orbit.elevation_max = math::radians(89.0f);
orbit.dolly_min = 2.0f;
orbit.dolly_max = 200.0f;
orbit.fov_near = math::radians(80.0f);
orbit.fov_far = math::radians(35.0f);
orbit.clip_near_min = 0.1f;
orbit.clip_near_max = 5.0f;
orbit.clip_far_min = 100.0f;
orbit.clip_far_max = 5000.0f;
*/
ctx->underground_camera->set_exposure(0.0f);
}
@ -277,7 +235,7 @@ void setup_controls(game::context* ctx)
const float dolly_speed = 10.0f;
const float truck_speed = dolly_speed;
const float pedestal_speed = 20.0f;
const float pedestal_speed = 30.0f;
const float pan_speed = math::radians(8.0f);
const float tilt_speed = pan_speed;
@ -431,7 +389,7 @@ void setup_controls(game::context* ctx)
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
three_dof.pitch -= tilt_speed * value * (1.0f / 60.0f);
three_dof.pitch = std::max<float>(math::radians(-89.9f), three_dof.pitch);
three_dof.pitch = std::max<float>(math::radians(-90.0f), three_dof.pitch);
}
);
@ -445,7 +403,7 @@ void setup_controls(game::context* ctx)
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
three_dof.pitch += tilt_speed * value * (1.0f / 60.0f);
three_dof.pitch = std::min<float>(math::radians(89.9f), three_dof.pitch);
three_dof.pitch = std::min<float>(math::radians(90.0f), three_dof.pitch);
}
);
}

+ 0
- 2
src/game/states/forage.cpp View File

@ -24,8 +24,6 @@
#include "entity/components/terrain.hpp"
#include "entity/components/transform.hpp"
#include "entity/systems/astronomy.hpp"
#include "entity/systems/control.hpp"
#include "entity/systems/camera.hpp"
#include "animation/screen-transition.hpp"
#include "animation/ease.hpp"
#include "resources/resource-manager.hpp"

+ 0
- 1
src/game/states/nuptial-flight.cpp View File

@ -21,7 +21,6 @@
#include "entity/archetype.hpp"
#include "entity/systems/astronomy.hpp"
#include "entity/systems/orbit.hpp"
#include "entity/systems/control.hpp"
#include "entity/systems/camera.hpp"
#include "entity/components/observer.hpp"
#include "entity/components/transform.hpp"

Loading…
Cancel
Save