Browse Source

Refactor application to split into application class and separate game bootloader

master
C. J. Howard 1 year ago
parent
commit
924cde00e5
104 changed files with 2402 additions and 1834 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +0
    -1
      src/animation/animation.hpp
  3. +0
    -1
      src/animation/frame-scheduler.cpp
  4. +2
    -0
      src/animation/frame-scheduler.hpp
  5. +275
    -1035
      src/application.cpp
  6. +166
    -380
      src/application.hpp
  7. +17
    -9
      src/debug/logger.cpp
  8. +8
    -0
      src/debug/logger.hpp
  9. +3
    -3
      src/entity/entity-commands.cpp
  10. +4
    -1
      src/event/event.hpp
  11. +0
    -0
      src/event/input-events.cpp
  12. +3
    -3
      src/event/input-events.hpp
  13. +28
    -0
      src/event/window-events.cpp
  14. +38
    -0
      src/event/window-events.hpp
  15. +0
    -0
      src/game/behavior/behavior-tree.hpp
  16. +2
    -2
      src/game/behavior/ebt.cpp
  17. +1
    -1
      src/game/behavior/ebt.hpp
  18. +1028
    -0
      src/game/bootloader.cpp
  19. +25
    -0
      src/game/bootloader.hpp
  20. +1
    -1
      src/game/components/behavior-component.hpp
  21. +0
    -0
      src/game/components/cavity-component.hpp
  22. +0
    -0
      src/game/components/chamber-component.hpp
  23. +0
    -0
      src/game/components/collision-component.hpp
  24. +0
    -0
      src/game/components/copy-rotation-component.hpp
  25. +0
    -0
      src/game/components/copy-scale-component.hpp
  26. +0
    -0
      src/game/components/copy-transform-component.hpp
  27. +0
    -0
      src/game/components/copy-translation-component.hpp
  28. +0
    -0
      src/game/components/locomotion-component.hpp
  29. +0
    -0
      src/game/components/model-component.hpp
  30. +0
    -0
      src/game/components/nest-component.hpp
  31. +0
    -0
      src/game/components/placement-component.hpp
  32. +0
    -0
      src/game/components/samara-component.hpp
  33. +0
    -0
      src/game/components/terrain-component.hpp
  34. +0
    -0
      src/game/components/tool-component.hpp
  35. +0
    -0
      src/game/components/transform-component.hpp
  36. +8
    -7
      src/game/console-commands.cpp
  37. +4
    -4
      src/game/console-commands.hpp
  38. +224
    -0
      src/game/game-context.hpp
  39. +38
    -0
      src/game/states/game-states.hpp
  40. +4
    -5
      src/game/states/language-select-state.cpp
  41. +9
    -8
      src/game/states/loading-state.cpp
  42. +4
    -5
      src/game/states/pause-state.cpp
  43. +35
    -34
      src/game/states/play-state.cpp
  44. +20
    -22
      src/game/states/splash-state.cpp
  45. +9
    -8
      src/game/states/title-state.cpp
  46. +2
    -2
      src/game/systems/behavior-system.cpp
  47. +0
    -0
      src/game/systems/behavior-system.hpp
  48. +3
    -3
      src/game/systems/camera-system.cpp
  49. +1
    -1
      src/game/systems/camera-system.hpp
  50. +1
    -1
      src/game/systems/collision-system.cpp
  51. +1
    -1
      src/game/systems/collision-system.hpp
  52. +5
    -5
      src/game/systems/constraint-system.cpp
  53. +0
    -0
      src/game/systems/constraint-system.hpp
  54. +0
    -0
      src/game/systems/control-system.cpp
  55. +1
    -1
      src/game/systems/control-system.hpp
  56. +0
    -0
      src/game/systems/entity-system.cpp
  57. +0
    -0
      src/game/systems/entity-system.hpp
  58. +3
    -3
      src/game/systems/locomotion-system.cpp
  59. +0
    -0
      src/game/systems/locomotion-system.hpp
  60. +0
    -0
      src/game/systems/nest-system.cpp
  61. +1
    -1
      src/game/systems/nest-system.hpp
  62. +4
    -4
      src/game/systems/placement-system.cpp
  63. +0
    -0
      src/game/systems/placement-system.hpp
  64. +20
    -3
      src/game/systems/render-system.cpp
  65. +9
    -1
      src/game/systems/render-system.hpp
  66. +2
    -2
      src/game/systems/samara-system.cpp
  67. +0
    -0
      src/game/systems/samara-system.hpp
  68. +14
    -14
      src/game/systems/subterrain-system.cpp
  69. +0
    -0
      src/game/systems/subterrain-system.hpp
  70. +3
    -3
      src/game/systems/terrain-system.cpp
  71. +1
    -1
      src/game/systems/terrain-system.hpp
  72. +3
    -3
      src/game/systems/tool-system.cpp
  73. +1
    -1
      src/game/systems/tool-system.hpp
  74. +53
    -22
      src/game/systems/ui-system.cpp
  75. +8
    -28
      src/game/systems/ui-system.hpp
  76. +0
    -0
      src/game/systems/updatable-system.cpp
  77. +0
    -0
      src/game/systems/updatable-system.hpp
  78. +2
    -2
      src/game/systems/vegetation-system.cpp
  79. +1
    -1
      src/game/systems/vegetation-system.hpp
  80. +3
    -6
      src/geometry/mesh-accelerator.cpp
  81. +23
    -2
      src/input/game-controller.cpp
  82. +21
    -0
      src/input/game-controller.hpp
  83. +1
    -1
      src/input/input-event-router.hpp
  84. +2
    -2
      src/input/input-mapper.hpp
  85. +1
    -1
      src/input/keyboard.cpp
  86. +1
    -1
      src/input/mouse.cpp
  87. +6
    -3
      src/main.cpp
  88. +64
    -1
      src/math/stream-operators.hpp
  89. +3
    -2
      src/rasterizer/framebuffer.cpp
  90. +5
    -5
      src/rasterizer/framebuffer.hpp
  91. +1
    -1
      src/rasterizer/rasterizer.cpp
  92. +1
    -1
      src/rasterizer/rasterizer.hpp
  93. +0
    -1
      src/rasterizer/shader-input.cpp
  94. +0
    -1
      src/renderer/passes/material-pass.cpp
  95. +2
    -2
      src/resources/behavior-tree-loader.cpp
  96. +53
    -0
      src/resources/config-file-loader.cpp
  97. +64
    -0
      src/resources/config-file.hpp
  98. +7
    -7
      src/resources/entity-archetype-loader.cpp
  99. +44
    -7
      src/resources/resource-manager.cpp
  100. +4
    -4
      src/resources/resource-manager.hpp

+ 1
- 0
CMakeLists.txt View File

@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies
set(STATIC_LIBS
dr_wav

+ 0
- 1
src/animation/animation.hpp View File

@ -26,7 +26,6 @@
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <iostream>
/**
* Abstract base class for animations.

+ 0
- 1
src/animation/frame-scheduler.cpp View File

@ -82,4 +82,3 @@ void frame_scheduler::tick()
frame_duration = static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>(frame_end - frame_start).count()) / 1000000.0;
frame_start = frame_end;
}

+ 2
- 0
src/animation/frame-scheduler.hpp View File

@ -25,6 +25,8 @@
/**
* Schedules fixed-timestep update calls and variable timestep render calls.
*
* @see https://gafferongames.com/post/fix_your_timestep/
*/
class frame_scheduler
{

+ 275
- 1035
src/application.cpp
File diff suppressed because it is too large
View File


+ 166
- 380
src/application.hpp View File

@ -20,118 +20,38 @@
#ifndef ANTKEEPER_APPLICATION_HPP
#define ANTKEEPER_APPLICATION_HPP
// STL
#include <fstream>
#include <array>
#include <functional>
#include <list>
#include <map>
#include <string>
// External
#include <entt/entt.hpp>
// Debug
#include "debug/logger.hpp"
#include "debug/performance-sampler.hpp"
#include "debug/cli.hpp"
// Input
#include "input/control.hpp"
#include "input/control-set.hpp"
#include "input/keyboard.hpp"
#include "input/mouse.hpp"
#include "input/game-controller.hpp"
#include "input/input-event-router.hpp"
#include "input/input-mapper.hpp"
// Event
#include "event/event-dispatcher.hpp"
// Renderer
#include "renderer/compositor.hpp"
#include "renderer/renderer.hpp"
// Scene
#include "scene/scene.hpp"
#include "scene/camera.hpp"
#include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/point-light.hpp"
#include "scene/spotlight.hpp"
#include "scene/model-instance.hpp"
// Animation
#include "animation/frame-scheduler.hpp"
#include "animation/timeline.hpp"
#include "animation/tween.hpp"
#include "animation/animation.hpp"
// Misc
#include "state/fsm.hpp"
#include "pheromone-matrix.hpp"
#include "orbit-cam.hpp"
#include <unordered_map>
// Forward declarations
//{
// SDL
typedef struct SDL_Window SDL_Window;
typedef void* SDL_GLContext;
// Resources
class resource_manager;
// Rasterizer
class rasterizer;
class framebuffer;
class vertex_buffer;
class vertex_array;
class texture_2d;
// Renderer
class clear_pass;
class shadow_map_pass;
class material_pass;
class sky_pass;
class bloom_pass;
class final_pass;
class simple_render_pass;
template <class T>
class material_property;
// Animation
class animator;
template <class T>
class animation;
class screen_transition;
// Systems
class behavior_system;
class camera_system;
class collision_system;
class locomotion_system;
class render_system;
class nest_system;
class placement_system;
class samara_system;
class subterrain_system;
class terrain_system;
class vegetation_system;
class tool_system;
class control_system;
class constraint_system;
class ui_system;
// Scene
class billboard;
//}
typedef struct SDL_Window SDL_Window;
typedef void* SDL_GLContext;
class event_dispatcher;
class frame_scheduler;
class game_controller;
class keyboard;
class logger;
class mouse;
class performance_sampler;
class rasterizer;
/**
*
*/
class application
{
public:
typedef std::array<std::function<void()>, 2> state_type;
typedef std::function<int(application*)> bootloader_type;
typedef std::function<void(double, double)> update_callback_type;
typedef std::function<void(double)> render_callback_type;
/**
* Creates and initializes an application.
*/
application(int argc, char** argv);
application();
/**
* Destroys an application.
@ -139,345 +59,211 @@ public:
~application();
/**
* Executes the application, causing it to enter the execution loop until closed.
* Executes the application, causing it to run the bootloader then enter the execution loop until closed.
*
* @param bootloader Function which will be executed immediately before the execution loop is entered. The bootloader will be passed a pointer to this application and should return an exit status code.
*
* @return Exit status code.
*/
int execute();
int execute(bootloader_type bootloader);
/**
* Requests the application's execution loop to cleanly terminate, and specifies its exit status code.
*
* @param status Status to be returned by application::execute() upon execution loop termination.
*/
void close(int status);
logger* get_logger();
cli* get_cli();
resource_manager* get_resource_manager();
fsm::machine* get_state_machine();
const fsm::state& get_loading_state() const;
const fsm::state& get_language_select_state() const;
const fsm::state& get_splash_state() const;
const fsm::state& get_title_state() const;
const fsm::state& get_play_state() const;
const fsm::state& get_pause_state() const;
timeline* get_timeline();
animator* get_animator();
camera* get_overworld_camera();
camera* get_underworld_camera();
orbit_cam* get_orbit_cam();
control_system* get_control_system();
entt::registry& get_ecs_registry();
scene& get_scene();
/**
* Changes the applications state, resulting in the execution of the current state's exit function (if any), followed by the new state's enter function (if any).
*
* @param state A pair of enter and exit functions, respectively, which define the state.
*/
void change_state(const state_type& state);
/**
* Sets the update callback, which is executed at regular intervals until the application is closed. The update callback expects two parameters, the first being the total time in seconds since the application was executed (t), and the second being the time in seconds since the last update (dt). dt will always be a fixed value, and is determined by the user-specified update rate.
*
* @see application::set_update_rate()
*/
void set_update_callback(const update_callback_type& callback);
/**
* Sets the render callback, which is executed as many times as possible between update callbacks. The render callback expects one parameter, alpha, which is always between 0 and 1 and can be used to interpolate between update states.
*/
void set_render_callback(const render_callback_type& callback);
/**
* Sets the frequency with which the update callback should be called.
*
* @param frequency Number of times per second the update callback should be called.
*/
void set_update_rate(double frequency);
/**
* Sets the application window's title.
*
* @param title Window title.
*/
void set_title(const std::string& title);
/**
* Sets the cursor visibility.
*
* @param visible `true` if the cursor should be visible, `false` otherwise.
*/
void set_cursor_visible(bool visible);
/**
* Enables or disables relative mouse mode, in which only relative mouse movement events are generated.
*
* @param enabled `true` if relative mouse mode should be enabled, `false` otherwise.
*/
void set_relative_mouse_mode(bool enabled);
/**
* Resizes the application window.
*
* @param width Width of the window, in pixels.
* @param height Height of the window, in pixels.
*/
void resize_window(int width, int height);
/**
* Puts the application window into either fullscreen or windowed mode.
*
* @param fullscreen `true` if the window should be fullscreen, `false` if it should be windowed.
*/
void set_fullscreen(bool fullscreen);
/**
* Enables or disables v-sync mode.
*
* @param vsync `true` if v-sync should be enabled, `false` otherwise.
*/
void set_vsync(bool vsync);
void take_screenshot();
// UI
scene* get_ui_scene();
billboard* get_splash_billboard();
/// Returns the dimensions of the current display.
const std::array<int, 2>& get_display_dimensions() const;
::sky_pass* get_sky_pass();
/// Returns the dimensions of the window.
const std::array<int, 2>& get_window_dimensions() const;
screen_transition* get_fade_transition();
screen_transition* get_radial_transition_inner();
screen_transition* get_radial_transition_outer();
private:
void setup_fsm();
void load_config();
void parse_options(int argc, char** argv);
/// Returns the dimensions of the window's drawable viewport.
const std::array<int, 2>& get_viewport_dimensions() const;
/// Returns `true` if the window is in fullscreen mode, `false` otherwise.
bool is_fullscreen() const;
/// Returns the rasterizer for the window.
::rasterizer* get_rasterizer();
/// Returns the application logger.
::logger* get_logger();
/// Returns the virtual keyboard.
::keyboard* get_keyboard();
/// Returns the virtual mouse.
::mouse* get_mouse();
/// Returns the list of virtual game controllers.
const std::list<game_controller*>& get_game_controllers();
/// Returns the application's event dispatcher.
event_dispatcher* get_event_dispatcher();
private:
void update(double t, double dt);
void render(double alpha);
void translate_sdl_events();
void set_relative_mouse_mode(bool enabled);
void toggle_fullscreen();
void window_resized();
static void save_image(const std::string& filename, int w, int h, const unsigned char* pixels);
bool fullscreen;
bool vsync;
std::tuple<int, int> saved_mouse_position;
std::tuple<int, int> window_dimensions;
std::tuple<int, int> window_position;
std::tuple<int, int> display_dimensions;
float4 viewport;
// Debugging
std::ofstream log_filestream;
::logger logger;
::cli cli;
// Paths
std::string data_path;
std::string data_package_path;
std::string config_path;
std::string mods_path;
std::string saves_path;
std::string screenshots_path;
// Resources
resource_manager* resource_manager;
SDL_Window* window;
SDL_GLContext context;
bool closed;
int exit_status;
// Updatable systems
timeline timeline;
animator* animator;
animation<float>* radial_transition_in;
animation<float>* radial_transition_out;
std::list<std::function<void(double, double)>> systems;
int shadow_map_resolution;
framebuffer* shadow_map_framebuffer;
texture_2d* shadow_map_depth_texture;
framebuffer* framebuffer_hdr;
texture_2d* framebuffer_hdr_color;
texture_2d* framebuffer_hdr_depth;
framebuffer* framebuffer_bloom; // General purpose framebuffer A
texture_2d* bloom_texture;
state_type state;
update_callback_type update_callback;
render_callback_type render_callback;
bool fullscreen;
bool vsync;
std::array<int, 2> display_dimensions;
std::array<int, 2> window_dimensions;
std::array<int, 2> viewport_dimensions;
std::array<int, 2> mouse_position;
double update_rate;
logger* logger;
SDL_Window* sdl_window;
SDL_GLContext sdl_gl_context;
// Rendering
rasterizer* rasterizer;
material* fallback_material;
ambient_light sun_indirect;
directional_light sun_direct;
point_light subterrain_light;
ambient_light underworld_ambient_light;
model_instance lantern;
model_instance cloud;
model_instance* grass_patches;
::spotlight spotlight;
vertex_buffer* billboard_vbo;
vertex_array* billboard_vao;
::renderer renderer;
scene* active_scene;
// Overworld
scene overworld_scene;
camera overworld_camera;
::clear_pass* clear_pass;
::sky_pass* sky_pass;
::material_pass* material_pass;
::clear_pass* shadow_map_clear_pass;
::shadow_map_pass* shadow_map_pass;
::bloom_pass* bloom_pass;
::final_pass* final_pass;
compositor overworld_compositor;
// Underworld
scene underworld_scene;
camera underworld_camera;
::clear_pass* underworld_clear_pass;
::material_pass* underworld_material_pass;
simple_render_pass* underworld_final_pass;
material_property<const texture_2d*>* underground_color_texture_property;
compositor underworld_compositor;
// FSM
fsm::machine state_machine;
fsm::state loading_state;
fsm::state language_select_state;
fsm::state splash_state;
fsm::state title_state;
fsm::state play_state;
fsm::state pause_state;
fsm::state* initial_state;
// Frame timing
frame_scheduler frame_scheduler;
performance_sampler performance_sampler;
tween<double> time;
frame_scheduler* frame_scheduler;
performance_sampler* performance_sampler;
// Events
event_dispatcher event_dispatcher;
input_event_router input_event_router;
input_mapper input_mapper;
event_dispatcher* event_dispatcher;
// Input devices
keyboard keyboard;
mouse mouse;
game_controller game_controller;
// Controls
control_set menu_controls;
control menu_back_control;
control menu_select_control;
control_set* camera_controls;
// System controls
control_set application_controls;
control toggle_fullscreen_control;
control screenshot_control;
control dig_control;
// Game
orbit_cam orbit_cam;
pheromone_matrix pheromones;
control_system* control_system;
// ECS
entt::registry ecs_registry;
behavior_system* behavior_system;
camera_system* camera_system;
collision_system* collision_system;
locomotion_system* locomotion_system;
render_system* render_system;
nest_system* nest_system;
placement_system* placement_system;
samara_system* samara_system;
subterrain_system* subterrain_system;
terrain_system* terrain_system;
vegetation_system* vegetation_system;
tool_system* tool_system;
constraint_system* constraint_system;
// UI
ui_system* ui_system;
compositor ui_compositor;
::clear_pass* ui_clear_pass;
::material_pass* ui_material_pass;
billboard* splash_billboard;
material* splash_billboard_material;
// Animation
tween<float3> focal_point_tween;
screen_transition* fade_transition;
screen_transition* radial_transition_inner;
screen_transition* radial_transition_outer;
// Entities
entt::entity forceps_entity;
entt::entity lens_entity;
entt::entity brush_entity;
entt::entity flashlight_entity;
keyboard* keyboard;
mouse* mouse;
std::list<game_controller*> game_controllers;
std::unordered_map<int, game_controller*> game_controller_map;
};
inline logger* application::get_logger()
{
return &logger;
}
inline cli* application::get_cli()
{
return &cli;
}
inline resource_manager* application::get_resource_manager()
{
return resource_manager;
}
inline fsm::machine* application::get_state_machine()
{
return &state_machine;
}
inline const fsm::state& application::get_loading_state() const
{
return loading_state;
}
inline const fsm::state& application::get_language_select_state() const
{
return language_select_state;
}
inline const fsm::state& application::get_splash_state() const
{
return splash_state;
}
inline const fsm::state& application::get_title_state() const
{
return title_state;
}
inline const fsm::state& application::get_play_state() const
{
return play_state;
}
inline const fsm::state& application::get_pause_state() const
{
return pause_state;
}
inline timeline* application::get_timeline()
{
return &timeline;
}
inline animator* application::get_animator()
{
return animator;
}
inline camera* application::get_overworld_camera()
{
return &overworld_camera;
}
inline camera* application::get_underworld_camera()
{
return &underworld_camera;
return logger;
}
inline orbit_cam* application::get_orbit_cam()
inline const std::array<int, 2>& application::get_display_dimensions() const
{
return &orbit_cam;
return display_dimensions;
}
inline control_system* application::get_control_system()
inline const std::array<int, 2>& application::get_window_dimensions() const
{
return control_system;
return window_dimensions;
}
inline entt::registry& application::get_ecs_registry()
inline const std::array<int, 2>& application::get_viewport_dimensions() const
{
return ecs_registry;
return viewport_dimensions;
}
inline scene& application::get_scene()
inline bool application::is_fullscreen() const
{
return overworld_scene;
return fullscreen;
}
inline billboard* application::get_splash_billboard()
inline rasterizer* application::get_rasterizer()
{
return splash_billboard;
return rasterizer;
}
inline sky_pass* application::get_sky_pass()
inline keyboard* application::get_keyboard()
{
return sky_pass;
return keyboard;
}
inline screen_transition* application::get_fade_transition()
inline mouse* application::get_mouse()
{
return fade_transition;
return mouse;
}
inline screen_transition* application::get_radial_transition_inner()
inline const std::list<game_controller*>& application::get_game_controllers()
{
return radial_transition_inner;
return game_controllers;
}
inline screen_transition* application::get_radial_transition_outer()
inline event_dispatcher* application::get_event_dispatcher()
{
return radial_transition_outer;
return event_dispatcher;
}
#endif // ANTKEEPER_APPLICATION_HPP

+ 17
- 9
src/debug/logger.cpp View File

@ -48,25 +48,33 @@ void logger::log(const std::string& text)
{
if (os)
{
std::string message = "";
// Prepend timestamp
if (timestamp_enabled)
{
(*os) << timestamp() << ": ";
message += timestamp();
message += ": ";
}
// Prepend indentation
for (std::size_t i = 0; i < tasks.size(); ++i)
(*os) << indent;
// Output text
(*os) << (log_prefix + text + log_postfix);
message += indent;
// Append text
message += (log_prefix + text + log_postfix);
// Append newline
if (auto_newline)
{
(*os) << "\n";
}
message += "\n";
// Add message to log history
history += message;
// Output message
(*os) << message;
// Flush output stream
os->flush();
}
}

+ 8
- 0
src/debug/logger.hpp View File

@ -95,6 +95,8 @@ public:
* @param status Exit status of the task. A value of `0` or `EXIT_SUCCESS` indicates the task exited successfully. A non-zero exit status indicates the task failed.
*/
void pop_task(int status);
const std::string& get_history() const;
private:
std::ostream* os;
@ -110,7 +112,13 @@ private:
std::string success_prefix;
std::string success_postfix;
std::stack<std::string> tasks;
std::string history;
};
inline const std::string& logger::get_history() const
{
return history;
}
#endif // ANTKEEPER_LOGGER_HPP

+ 3
- 3
src/entity/entity-commands.cpp View File

@ -18,9 +18,9 @@
*/
#include "entity-commands.hpp"
#include "entity/components/model-component.hpp"
#include "entity/components/transform-component.hpp"
#include "entity/components/copy-transform-component.hpp"
#include "game/components/model-component.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/copy-transform-component.hpp"
namespace ecs {

+ 4
- 1
src/event/event.hpp View File

@ -67,8 +67,11 @@ public:
/// Destroys an event
virtual ~event() = default;
/// @copydoc event_base::get_event_type_id() const
virtual const std::size_t get_event_type_id() const final;
/// @copydoc event_base::clone() const
virtual event_base* clone() const = 0;
};

src/input/input-events.cpp → src/event/input-events.cpp View File


src/input/input-events.hpp → src/event/input-events.hpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_INPUT_EVENT_HPP
#define ANTKEEPER_INPUT_EVENT_HPP
#ifndef ANTKEEPER_INPUT_EVENTS_HPP
#define ANTKEEPER_INPUT_EVENTS_HPP
#include "event/event.hpp"
@ -169,5 +169,5 @@ public:
float value;
};
#endif // ANTKEEPER_INPUT_EVENT_HPP
#endif // ANTKEEPER_INPUT_EVENTS_HPP

+ 28
- 0
src/event/window-events.cpp View File

@ -0,0 +1,28 @@
/*
* Copyright (C) 2020 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 "event/window-events.hpp"
event_base* window_resized_event::clone() const
{
window_resized_event* event = new window_resized_event();
event->w = w;
event->h = h;
return event;
}

+ 38
- 0
src/event/window-events.hpp View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2020 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_WINDOW_EVENTS_HPP
#define ANTKEEPER_WINDOW_EVENTS_HPP
#include "event/event.hpp"
/**
* Input event which indicates a mouse button has been pressed.
*/
class window_resized_event: public event<window_resized_event>
{
public:
virtual event_base* clone() const;
int w;
int h;
};
#endif // ANTKEEPER_WINDOW_EVENTS_HPP

src/behavior/behavior-tree.hpp → src/game/behavior/behavior-tree.hpp View File


src/behavior/ebt.cpp → src/game/behavior/ebt.cpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "behavior/ebt.hpp"
#include "entity/components/transform-component.hpp"
#include "game/behavior/ebt.hpp"
#include "game/components/transform-component.hpp"
#include <iostream>
using namespace ecs;

src/behavior/ebt.hpp → src/game/behavior/ebt.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_EBT_HPP
#define ANTKEEPER_EBT_HPP
#include "behavior/behavior-tree.hpp"
#include "game/behavior/behavior-tree.hpp"
#include <entt/entt.hpp>
/// Entity Behavior Tree

+ 1028
- 0
src/game/bootloader.cpp
File diff suppressed because it is too large
View File


+ 25
- 0
src/game/bootloader.hpp View File

@ -0,0 +1,25 @@
/*
* Copyright (C) 2020 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_BOOTLOADER_HPP
#define ANTKEEPER_BOOTLOADER_HPP
int bootloader(application* app, int argc, char** argv);
#endif // ANTKEEPER_BOOTLOADER_HPP

src/entity/components/behavior-component.hpp → src/game/components/behavior-component.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_ECS_BEHAVIOR_COMPONENT_HPP
#define ANTKEEPER_ECS_BEHAVIOR_COMPONENT_HPP
#include "behavior/ebt.hpp"
#include "game/behavior/ebt.hpp"
namespace ecs {

src/entity/components/cavity-component.hpp → src/game/components/cavity-component.hpp View File


src/entity/components/chamber-component.hpp → src/game/components/chamber-component.hpp View File


src/entity/components/collision-component.hpp → src/game/components/collision-component.hpp View File


src/entity/components/copy-rotation-component.hpp → src/game/components/copy-rotation-component.hpp View File


src/entity/components/copy-scale-component.hpp → src/game/components/copy-scale-component.hpp View File


src/entity/components/copy-transform-component.hpp → src/game/components/copy-transform-component.hpp View File


src/entity/components/copy-translation-component.hpp → src/game/components/copy-translation-component.hpp View File


src/entity/components/locomotion-component.hpp → src/game/components/locomotion-component.hpp View File


src/entity/components/model-component.hpp → src/game/components/model-component.hpp View File


src/entity/components/nest-component.hpp → src/game/components/nest-component.hpp View File


src/entity/components/placement-component.hpp → src/game/components/placement-component.hpp View File


src/entity/components/samara-component.hpp → src/game/components/samara-component.hpp View File


src/entity/components/terrain-component.hpp → src/game/components/terrain-component.hpp View File


src/entity/components/tool-component.hpp → src/game/components/tool-component.hpp View File


src/entity/components/transform-component.hpp → src/game/components/transform-component.hpp View File


src/debug/console-commands.cpp → src/game/console-commands.cpp View File

@ -20,6 +20,7 @@
#include "console-commands.hpp"
#include "application.hpp"
#include "animation/timeline.hpp"
#include "game/game-context.hpp"
#include "debug/cli.hpp"
namespace cc
@ -30,22 +31,22 @@ std::string echo(std::string text)
return text;
}
std::string exit(application* app)
std::string exit(game_context* ctx)
{
app->close(EXIT_SUCCESS);
ctx->app->close(EXIT_SUCCESS);
return std::string();
}
std::string scrot(application* app)
std::string scrot(game_context* ctx)
{
app->take_screenshot();
//ctx->app->take_screenshot();
return std::string("screenshot saved");
}
std::string cue(application* app, float t, std::string command)
std::string cue(game_context* ctx, float t, std::string command)
{
::timeline* timeline = app->get_timeline();
::cli* cli = app->get_cli();
::timeline* timeline = ctx->timeline;
::cli* cli = ctx->cli;
timeline->add_cue({timeline->get_position() + t, std::function<void()>(std::bind(&::cli::interpret, cli, command))});

src/debug/console-commands.hpp → src/game/console-commands.hpp View File

@ -22,18 +22,18 @@
#include <string>
class application;
struct game_context;
namespace cc
{
std::string echo(std::string text);
std::string exit(application* app);
std::string exit(game_context* ctx);
std::string scrot(application* app);
std::string scrot(game_context* ctx);
std::string cue(application* app, float t, std::string command);
std::string cue(game_context* ctx, float t, std::string command);
} // namespace cc

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

@ -0,0 +1,224 @@
/*
* Copyright (C) 2020 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_GAME_CONTEXT_HPP
#define ANTKEEPER_GAME_CONTEXT_HPP
#include "utility/fundamental-types.hpp"
#include <optional>
#include <entt/entt.hpp>
#include <fstream>
#include <string>
// Forward declarations
class ambient_light;
class animator;
class application;
class behavior_system;
class billboard;
class bloom_pass;
class camera;
class camera_system;
class clear_pass;
class collision_system;
class compositor;
class config_file;
class constraint_system;
class control;
class control_set;
class control_system;
class directional_light;
class final_pass;
class framebuffer;
class locomotion_system;
class logger;
class material;
class material_pass;
class nest_system;
class orbit_cam;
class pheromone_matrix;
class placement_system;
class point_light;
class rasterizer;
class render_system;
class resource_manager;
class samara_system;
class scene;
class screen_transition;
class shadow_map_pass;
class simple_render_pass;
class sky_pass;
class spotlight;
class subterrain_system;
class terrain_system;
class texture_2d;
class timeline;
class tool_system;
class ui_system;
class vegetation_system;
class vertex_array;
class vertex_buffer;
class renderer;
class model_instance;
class input_event_router;
class input_mapper;
class cli;
template <typename T> class animation;
template <typename T> class material_property;
template <typename T> class tween;
/**
*
*/
struct game_context
{
application* app;
logger* logger;
std::ofstream log_filestream;
// Command-line options
std::optional<bool> option_continue;
std::optional<std::string> option_data;
std::optional<bool> option_fullscreen;
std::optional<bool> option_new_game;
std::optional<bool> option_quick_start;
std::optional<bool> option_reset;
std::optional<int> option_vsync;
std::optional<bool> option_windowed;
// Paths
std::string data_path;
std::string config_path;
std::string mods_path;
std::string saves_path;
std::string screenshots_path;
std::string data_package_path;
// Config
config_file* config;
// Resources
resource_manager* resource_manager;
// Framebuffers
framebuffer* shadow_map_framebuffer;
texture_2d* shadow_map_depth_texture;
framebuffer* framebuffer_hdr;
texture_2d* framebuffer_hdr_color;
texture_2d* framebuffer_hdr_depth;
framebuffer* framebuffer_bloom; // General purpose framebuffer A
texture_2d* bloom_texture;
// Rendering
rasterizer* rasterizer;
renderer* renderer;
vertex_buffer* billboard_vbo;
vertex_array* billboard_vao;
material* fallback_material;
material* splash_billboard_material;
// Compositing
bloom_pass* overworld_bloom_pass;
clear_pass* overworld_clear_pass;
clear_pass* overworld_shadow_map_clear_pass;
clear_pass* ui_clear_pass;
clear_pass* underworld_clear_pass;
final_pass* overworld_final_pass;
material_pass* overworld_material_pass;
material_pass* ui_material_pass;
material_pass* underworld_material_pass;
shadow_map_pass* overworld_shadow_map_pass;
simple_render_pass* underworld_final_pass;
sky_pass* overworld_sky_pass;
material_property<const texture_2d*>* underground_color_texture_property;
compositor* overworld_compositor;
compositor* underworld_compositor;
compositor* ui_compositor;
// Scene
scene* active_scene;
scene* overworld_scene;
scene* underworld_scene;
scene* ui_scene;
camera* overworld_camera;
camera* underworld_camera;
camera* ui_camera;
ambient_light* sun_indirect;
directional_light* sun_direct;
point_light* subterrain_light;
ambient_light* underworld_ambient_light;
model_instance* cloud;
spotlight* spotlight;
billboard* splash_billboard;
// Animation
timeline* timeline;
animator* animator;
tween<double>* time_tween;
tween<float3>* focal_point_tween;
animation<float>* radial_transition_in;
animation<float>* radial_transition_out;
screen_transition* fade_transition;
screen_transition* radial_transition_inner;
screen_transition* radial_transition_outer;
// Controls
input_event_router* input_event_router;
input_mapper* input_mapper;
control_set* application_controls;
control_set* camera_controls;
control_set* menu_controls;
control* menu_back_control;
control* menu_select_control;
control* screenshot_control;
control* toggle_fullscreen_control;
// Entities
entt::registry* ecs_registry;
entt::entity brush_entity;
entt::entity flashlight_entity;
entt::entity forceps_entity;
entt::entity lens_entity;
// Systems
behavior_system* behavior_system;
camera_system* camera_system;
collision_system* collision_system;
constraint_system* constraint_system;
control_system* control_system;
locomotion_system* locomotion_system;
nest_system* nest_system;
placement_system* placement_system;
render_system* render_system;
samara_system* samara_system;
subterrain_system* subterrain_system;
terrain_system* terrain_system;
tool_system* tool_system;
ui_system* ui_system;
vegetation_system* vegetation_system;
// Debug
cli* cli;
// Misc
orbit_cam* orbit_cam;
pheromone_matrix* pheromones;
};
#endif // ANTKEEPER_GAME_CONTEXT_HPP

+ 38
- 0
src/game/states/game-states.hpp View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2020 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_GAME_STATES_HPP
#define ANTKEEPER_GAME_STATES_HPP
struct game_context;
void loading_state_enter(game_context* ctx);
void loading_state_exit(game_context* ctx);
void language_select_state_enter(game_context* ctx);
void language_select_state_exit(game_context* ctx);
void splash_state_enter(game_context* ctx);
void splash_state_exit(game_context* ctx);
void title_state_enter(game_context* ctx);
void title_state_exit(game_context* ctx);
void play_state_enter(game_context* ctx);
void play_state_exit(game_context* ctx);
void pause_state_enter(game_context* ctx);
void pause_state_exit(game_context* ctx);
#endif // ANTKEEPER_GAME_STATES_HPP

src/state/language-select-state.cpp → src/game/states/language-select-state.cpp View File

@ -17,15 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "application-states.hpp"
#include "application.hpp"
#include <iostream>
#include "game/states/game-states.hpp"
#include "game/game-context.hpp"
void enter_language_select_state(application* app)
void language_select_state_enter(game_context* ctx)
{
}
void exit_language_select_state(application* app)
void language_select_state_exit(game_context* ctx)
{
}

src/state/loading-state.cpp → src/game/states/loading-state.cpp View File

@ -17,23 +17,24 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "application-states.hpp"
#include "game/states/game-states.hpp"
#include "game/game-context.hpp"
#include "debug/logger.hpp"
#include "application.hpp"
#include <iostream>
void enter_loading_state(application* app)
void loading_state_enter(game_context* ctx)
{
logger* logger = app->get_logger();
logger* logger = ctx->logger;
logger->push_task("Entering loading state");
logger->pop_task(EXIT_SUCCESS);
app->get_state_machine()->change_state(app->get_title_state());
ctx->app->change_state({std::bind(title_state_enter, ctx), std::bind(title_state_exit, ctx)});
}
void exit_loading_state(application* app)
void loading_state_exit(game_context* ctx)
{
logger* logger = app->get_logger();
logger* logger = ctx->logger;
logger->push_task("Exiting loading state");
logger->pop_task(EXIT_SUCCESS);

src/state/pause-state.cpp → src/game/states/pause-state.cpp View File

@ -17,15 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "application-states.hpp"
#include "application.hpp"
#include <iostream>
#include "game/states/game-states.hpp"
#include "game/game-context.hpp"
void enter_pause_state(application* app)
void pause_state_enter(game_context* ctx)
{
}
void exit_pause_state(application* app)
void pause_state_exit(game_context* ctx)
{
}

src/state/play-state.cpp → src/game/states/play-state.cpp View File

@ -17,44 +17,45 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "application-states.hpp"
#include "configuration.hpp"
#include "application.hpp"
#include "animation/ease.hpp"
#include "animation/screen-transition.hpp"
#include "scene/model-instance.hpp"
#include "resources/resource-manager.hpp"
#include "renderer/model.hpp"
#include "renderer/material.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "systems/control-system.hpp"
#include "entity/components/model-component.hpp"
#include "entity/components/transform-component.hpp"
#include "entity/components/terrain-component.hpp"
#include "entity/components/samara-component.hpp"
#include "entity/components/cavity-component.hpp"
#include "entity/components/tool-component.hpp"
#include "entity/components/placement-component.hpp"
#include "entity/components/copy-transform-component.hpp"
#include "entity/components/copy-translation-component.hpp"
#include "configuration.hpp"
#include "debug/logger.hpp"
#include "entity/archetype.hpp"
#include "game/components/cavity-component.hpp"
#include "game/components/copy-transform-component.hpp"
#include "game/components/copy-translation-component.hpp"
#include "game/components/model-component.hpp"
#include "game/components/placement-component.hpp"
#include "game/components/samara-component.hpp"
#include "game/components/terrain-component.hpp"
#include "game/components/tool-component.hpp"
#include "game/components/transform-component.hpp"
#include "entity/entity-commands.hpp"
#include "nest.hpp"
#include "game/game-context.hpp"
#include "game/states/game-states.hpp"
#include "math/math.hpp"
#include "nest.hpp"
#include "orbit-cam.hpp"
#include "renderer/material.hpp"
#include "renderer/model.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "resources/resource-manager.hpp"
#include "scene/model-instance.hpp"
#include "scene/scene.hpp"
#include "game/systems/control-system.hpp"
#include "utility/fundamental-types.hpp"
#include "geometry/mesh-accelerator.hpp"
#include "behavior/ebt.hpp"
#include "animation/ease.hpp"
void enter_play_state(application* app)
void play_state_enter(game_context* ctx)
{
logger* logger = app->get_logger();
logger* logger = ctx->logger;
logger->push_task("Entering play state");
// Enable sky pass
app->get_sky_pass()->set_enabled(true);
ctx->overworld_sky_pass->set_enabled(true);
resource_manager* resource_manager = app->get_resource_manager();
entt::registry& ecs_registry = app->get_ecs_registry();
resource_manager* resource_manager = ctx->resource_manager;
entt::registry& ecs_registry = *ctx->ecs_registry;
// Load entity archetypes
ecs::archetype* ant_hill_archetype = resource_manager->load<ecs::archetype>("ant-hill.ent");
@ -152,8 +153,8 @@ void enter_play_state(application* app)
*/
// Setup overworld camera
camera* camera = app->get_overworld_camera();
orbit_cam* orbit_cam = app->get_orbit_cam();
camera* camera = ctx->overworld_camera;
orbit_cam* orbit_cam = ctx->orbit_cam;
orbit_cam->attach(camera);
orbit_cam->set_target_focal_point({0, 0, 0});
orbit_cam->set_target_focal_distance(15.0f);
@ -173,7 +174,7 @@ void enter_play_state(application* app)
forceps_tool_component.active = true;
ecs_registry.assign<ecs::tool_component>(forceps_entity, forceps_tool_component);
app->get_scene().update_tweens();
ctx->overworld_scene->update_tweens();
// Allocate a nest
nest* nest = new ::nest();
@ -239,20 +240,20 @@ void enter_play_state(application* app)
//transform.transform.translation.y -= 1.0f;
}
control_system* control_system = app->get_control_system();
control_system* control_system = ctx->control_system;
control_system->update(0.0f);
control_system->set_nest(nest);
orbit_cam->update(0.0f);
// Start fade in
app->get_fade_transition()->transition(1.0f, true, ease<float>::in_quad);
ctx->fade_transition->transition(1.0f, true, ease<float>::in_quad);
logger->pop_task(EXIT_SUCCESS);
}
void exit_play_state(application* app)
void play_state_exit(game_context* ctx)
{
logger* logger = app->get_logger();
logger* logger = ctx->logger;
logger->push_task("Exiting play state");
logger->pop_task(EXIT_SUCCESS);

src/state/splash-state.cpp → src/game/states/splash-state.cpp View File

@ -17,30 +17,28 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "application-states.hpp"
#include "application.hpp"
#include "scene/billboard.hpp"
#include "renderer/material.hpp"
#include "renderer/material-property.hpp"
#include "animation/animation.hpp"
#include "animation/animator.hpp"
#include "animation/ease.hpp"
#include "animation/screen-transition.hpp"
#include "animation/timeline.hpp"
#include "application.hpp"
#include "debug/logger.hpp"
#include "game/game-context.hpp"
#include "game/states/game-states.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "scene/billboard.hpp"
#include "scene/scene.hpp"
#include <functional>
#include <iostream>
void enter_splash_state(application* app)
void splash_state_enter(game_context* ctx)
{
logger* logger = app->get_logger();
logger* logger = ctx->logger;
logger->push_task("Entering splash state");
// Disable sky pass
app->get_sky_pass()->set_enabled(false);
ctx->overworld_sky_pass->set_enabled(false);
// Add splash billboard to UI scene
app->get_ui_scene()->add_object(app->get_splash_billboard());
ctx->ui_scene->add_object(ctx->splash_billboard);
// Setup timing
const float splash_fade_in_duration = 0.5f;
@ -48,22 +46,22 @@ void enter_splash_state(application* app)
const float splash_fade_out_duration = 0.5f;
// Start fade in
app->get_fade_transition()->transition(splash_fade_in_duration, true, ease<float>::in_quad);
ctx->fade_transition->transition(splash_fade_in_duration, true, ease<float>::in_quad);
// Crate fade out function
auto fade_out = [app, splash_fade_out_duration]()