Browse Source

Refactor application to split into application class and separate game bootloader

master
C. J. Howard 4 years 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_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies # Determine dependencies
set(STATIC_LIBS set(STATIC_LIBS
dr_wav dr_wav

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

@ -26,7 +26,6 @@
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <unordered_map> #include <unordered_map>
#include <iostream>
/** /**
* Abstract base class for animations. * 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_duration = static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>(frame_end - frame_start).count()) / 1000000.0;
frame_start = frame_end; 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. * Schedules fixed-timestep update calls and variable timestep render calls.
*
* @see https://gafferongames.com/post/fix_your_timestep/
*/ */
class frame_scheduler 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 #ifndef ANTKEEPER_APPLICATION_HPP
#define ANTKEEPER_APPLICATION_HPP #define ANTKEEPER_APPLICATION_HPP
// STL
#include <fstream>
#include <array>
#include <functional> #include <functional>
#include <list> #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 // 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 class application
{ {
public: 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. * Creates and initializes an application.
*/ */
application(int argc, char** argv);
application();
/** /**
* Destroys an application. * Destroys an application.
@ -139,345 +59,211 @@ public:
~application(); ~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. * @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. * 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. * @param status Status to be returned by application::execute() upon execution loop termination.
*/ */
void close(int status); 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(); 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 update(double t, double dt);
void render(double alpha); void render(double alpha);
void translate_sdl_events(); void translate_sdl_events();
void set_relative_mouse_mode(bool enabled);
void toggle_fullscreen();
void window_resized(); void window_resized();
static void save_image(const std::string& filename, int w, int h, const unsigned char* pixels); 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; bool closed;
int exit_status; 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; 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 timing
frame_scheduler frame_scheduler;
performance_sampler performance_sampler;
tween<double> time;
frame_scheduler* frame_scheduler;
performance_sampler* performance_sampler;
// Events // Events
event_dispatcher event_dispatcher;
input_event_router input_event_router;
input_mapper input_mapper;
event_dispatcher* event_dispatcher;
// Input devices // 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() 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 #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) if (os)
{ {
std::string message = "";
// Prepend timestamp // Prepend timestamp
if (timestamp_enabled) if (timestamp_enabled)
{ {
(*os) << timestamp() << ": ";
message += timestamp();
message += ": ";
} }
// Prepend indentation // Prepend indentation
for (std::size_t i = 0; i < tasks.size(); ++i) 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 // Append newline
if (auto_newline) if (auto_newline)
{
(*os) << "\n";
}
message += "\n";
// Add message to log history
history += message;
// Output message
(*os) << message;
// Flush output stream
os->flush(); 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. * @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); void pop_task(int status);
const std::string& get_history() const;
private: private:
std::ostream* os; std::ostream* os;
@ -110,7 +112,13 @@ private:
std::string success_prefix; std::string success_prefix;
std::string success_postfix; std::string success_postfix;
std::stack<std::string> tasks; std::stack<std::string> tasks;
std::string history;
}; };
inline const std::string& logger::get_history() const
{
return history;
}
#endif // ANTKEEPER_LOGGER_HPP #endif // ANTKEEPER_LOGGER_HPP

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

@ -18,9 +18,9 @@
*/ */
#include "entity-commands.hpp" #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 { namespace ecs {

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

@ -67,8 +67,11 @@ public:
/// Destroys an event /// Destroys an event
virtual ~event() = default; virtual ~event() = default;
/// @copydoc event_base::get_event_type_id() const
virtual const std::size_t get_event_type_id() const final; virtual const std::size_t get_event_type_id() const final;
/// @copydoc event_base::clone() const
virtual event_base* clone() const = 0; 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/>. * 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" #include "event/event.hpp"
@ -169,5 +169,5 @@ public:
float value; 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/>. * 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> #include <iostream>
using namespace ecs; using namespace ecs;

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

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_EBT_HPP #ifndef ANTKEEPER_EBT_HPP
#define ANTKEEPER_EBT_HPP #define ANTKEEPER_EBT_HPP
#include "behavior/behavior-tree.hpp"
#include "game/behavior/behavior-tree.hpp"
#include <entt/entt.hpp> #include <entt/entt.hpp>
/// Entity Behavior Tree /// 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 #ifndef ANTKEEPER_ECS_BEHAVIOR_COMPONENT_HPP
#define ANTKEEPER_ECS_BEHAVIOR_COMPONENT_HPP #define ANTKEEPER_ECS_BEHAVIOR_COMPONENT_HPP
#include "behavior/ebt.hpp"
#include "game/behavior/ebt.hpp"
namespace ecs { 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 "console-commands.hpp"
#include "application.hpp" #include "application.hpp"
#include "animation/timeline.hpp" #include "animation/timeline.hpp"
#include "game/game-context.hpp"
#include "debug/cli.hpp" #include "debug/cli.hpp"
namespace cc namespace cc
@ -30,22 +31,22 @@ std::string echo(std::string text)
return 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(); 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"); 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))}); 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> #include <string>
class application;
struct game_context;
namespace cc namespace cc
{ {
std::string echo(std::string text); 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 } // 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/>. * 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/>. * 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 "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->push_task("Entering loading state");
logger->pop_task(EXIT_SUCCESS); 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->push_task("Exiting loading state");
logger->pop_task(EXIT_SUCCESS); 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/>. * 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/>. * 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 "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 "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 "entity/entity-commands.hpp"
#include "nest.hpp"
#include "game/game-context.hpp"
#include "game/states/game-states.hpp"
#include "math/math.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 "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"); logger->push_task("Entering play state");
// Enable sky pass // 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 // Load entity archetypes
ecs::archetype* ant_hill_archetype = resource_manager->load<ecs::archetype>("ant-hill.ent"); 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 // 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->attach(camera);
orbit_cam->set_target_focal_point({0, 0, 0}); orbit_cam->set_target_focal_point({0, 0, 0});
orbit_cam->set_target_focal_distance(15.0f); orbit_cam->set_target_focal_distance(15.0f);
@ -173,7 +174,7 @@ void enter_play_state(application* app)
forceps_tool_component.active = true; forceps_tool_component.active = true;
ecs_registry.assign<ecs::tool_component>(forceps_entity, forceps_tool_component); ecs_registry.assign<ecs::tool_component>(forceps_entity, forceps_tool_component);
app->get_scene().update_tweens();
ctx->overworld_scene->update_tweens();
// Allocate a nest // Allocate a nest
nest* nest = new ::nest(); nest* nest = new ::nest();
@ -239,20 +240,20 @@ void enter_play_state(application* app)
//transform.transform.translation.y -= 1.0f; //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->update(0.0f);
control_system->set_nest(nest); control_system->set_nest(nest);
orbit_cam->update(0.0f); orbit_cam->update(0.0f);
// Start fade in // 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); 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->push_task("Exiting play state");
logger->pop_task(EXIT_SUCCESS); 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/>. * 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/ease.hpp"
#include "animation/screen-transition.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 "renderer/passes/sky-pass.hpp"
#include "scene/billboard.hpp"
#include "scene/scene.hpp"
#include <functional> #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"); logger->push_task("Entering splash state");
// Disable sky pass // Disable sky pass
app->get_sky_pass()->set_enabled(false);
ctx->overworld_sky_pass->set_enabled(false);
// Add splash billboard to UI scene // 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 // Setup timing
const float splash_fade_in_duration = 0.5f; 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; const float splash_fade_out_duration = 0.5f;
// Start fade in // 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 // Crate fade out function
auto fade_out = [app, splash_fade_out_duration]()
auto fade_out = [ctx, splash_fade_out_duration]()
{ {
app->get_fade_transition()->transition(splash_fade_out_duration, false, ease<float>::out_quad);
ctx->fade_transition->transition(splash_fade_out_duration, false, ease<float>::out_quad);
}; };
// Create change state function // Create change state function
auto change_state = [app]()
auto change_state = [ctx]()
{ {
app->get_state_machine()->change_state(app->get_play_state());
ctx->app->change_state({std::bind(play_state_enter, ctx), std::bind(play_state_exit, ctx)});
}; };
// Schedule fade out and change state events // Schedule fade out and change state events
timeline* timeline = app->get_timeline();
timeline* timeline = ctx->timeline;
float t = timeline->get_position(); float t = timeline->get_position();
timeline::sequence splash_sequence = timeline::sequence splash_sequence =
{ {
@ -75,13 +73,13 @@ void enter_splash_state(application* app)
logger->pop_task(EXIT_SUCCESS); logger->pop_task(EXIT_SUCCESS);
} }
void exit_splash_state(application* app)
void splash_state_exit(game_context* ctx)
{ {
logger* logger = app->get_logger();
logger* logger = ctx->logger;
logger->push_task("Exiting splash state"); logger->push_task("Exiting splash state");
// Remove splash billboard from UI scene // Remove splash billboard from UI scene
app->get_ui_scene()->remove_object(app->get_splash_billboard());
ctx->ui_scene->remove_object(ctx->splash_billboard);
logger->pop_task(EXIT_SUCCESS); logger->pop_task(EXIT_SUCCESS);
} }

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

@ -17,16 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "application-states.hpp"
#include "application.hpp"
#include "game/states/game-states.hpp"
#include "game/game-context.hpp"
#include "debug/logger.hpp"
#include "animation/timeline.hpp"
void enter_title_state(application* app)
void title_state_enter(game_context* ctx)
{ {
logger* logger = app->get_logger();
logger* logger = ctx->logger;
logger->push_task("Entering title state"); logger->push_task("Entering title state");
// Get timeline // Get timeline
timeline* timeline = app->get_timeline();
timeline* timeline = ctx->timeline;
// Create title sequence // Create title sequence
float t = timeline->get_position(); float t = timeline->get_position();
@ -44,11 +46,10 @@ void enter_title_state(application* app)
logger->pop_task(EXIT_SUCCESS); logger->pop_task(EXIT_SUCCESS);
} }
void exit_title_state(application* app)
void title_state_exit(game_context* ctx)
{ {
logger* logger = app->get_logger();
logger* logger = ctx->logger;
logger->push_task("Exiting title state"); logger->push_task("Exiting title state");
logger->pop_task(EXIT_SUCCESS); logger->pop_task(EXIT_SUCCESS);
} }

src/systems/behavior-system.cpp → src/game/systems/behavior-system.cpp View File

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

src/systems/behavior-system.hpp → src/game/systems/behavior-system.hpp View File


src/systems/camera-system.cpp → src/game/systems/camera-system.cpp View File

@ -18,9 +18,9 @@
*/ */
#include "camera-system.hpp" #include "camera-system.hpp"
#include "entity/components/collision-component.hpp"
#include "entity/components/tool-component.hpp"
#include "entity/components/transform-component.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/tool-component.hpp"
#include "game/components/transform-component.hpp"
#include "scene/camera.hpp" #include "scene/camera.hpp"
#include "orbit-cam.hpp" #include "orbit-cam.hpp"
#include "geometry/mesh.hpp" #include "geometry/mesh.hpp"

src/systems/camera-system.hpp → src/game/systems/camera-system.hpp View File

@ -22,7 +22,7 @@
#include "entity-system.hpp" #include "entity-system.hpp"
#include "event/event-handler.hpp" #include "event/event-handler.hpp"
#include "input/input-events.hpp"
#include "event/input-events.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
class camera; class camera;

src/systems/collision-system.cpp → src/game/systems/collision-system.cpp View File

@ -18,7 +18,7 @@
*/ */
#include "collision-system.hpp" #include "collision-system.hpp"
#include "entity/components/transform-component.hpp"
#include "game/components/transform-component.hpp"
using namespace ecs; using namespace ecs;

src/systems/collision-system.hpp → src/game/systems/collision-system.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_COLLISION_SYSTEM_HPP #define ANTKEEPER_COLLISION_SYSTEM_HPP
#include "entity-system.hpp" #include "entity-system.hpp"
#include "entity/components/collision-component.hpp"
#include "game/components/collision-component.hpp"
/** /**
* Maintains a spatially partitioned set of collision meshes. The set of collision meshes isnot owned by the collision system, so it can be accessed by other systems as well. * Maintains a spatially partitioned set of collision meshes. The set of collision meshes isnot owned by the collision system, so it can be accessed by other systems as well.

src/systems/constraint-system.cpp → src/game/systems/constraint-system.cpp View File

@ -18,11 +18,11 @@
*/ */
#include "constraint-system.hpp" #include "constraint-system.hpp"
#include "entity/components/copy-translation-component.hpp"
#include "entity/components/copy-rotation-component.hpp"
#include "entity/components/copy-scale-component.hpp"
#include "entity/components/copy-transform-component.hpp"
#include "entity/components/transform-component.hpp"
#include "game/components/copy-translation-component.hpp"
#include "game/components/copy-rotation-component.hpp"
#include "game/components/copy-scale-component.hpp"
#include "game/components/copy-transform-component.hpp"
#include "game/components/transform-component.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
using namespace ecs; using namespace ecs;

src/systems/constraint-system.hpp → src/game/systems/constraint-system.hpp View File


src/systems/control-system.cpp → src/game/systems/control-system.cpp View File


src/systems/control-system.hpp → src/game/systems/control-system.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_CONTROL_SYSTEM_HPP #define ANTKEEPER_CONTROL_SYSTEM_HPP
#include "event/event-handler.hpp" #include "event/event-handler.hpp"
#include "input/input-events.hpp"
#include "event/input-events.hpp"
#include "input/control.hpp" #include "input/control.hpp"
#include "input/control-set.hpp" #include "input/control-set.hpp"
#include "scene/model-instance.hpp" #include "scene/model-instance.hpp"

src/systems/entity-system.cpp → src/game/systems/entity-system.cpp View File


src/systems/entity-system.hpp → src/game/systems/entity-system.hpp View File


src/systems/locomotion-system.cpp → src/game/systems/locomotion-system.cpp View File

@ -18,9 +18,9 @@
*/ */
#include "locomotion-system.hpp" #include "locomotion-system.hpp"
#include "entity/components/collision-component.hpp"
#include "entity/components/locomotion-component.hpp"
#include "entity/components/transform-component.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/locomotion-component.hpp"
#include "game/components/transform-component.hpp"
using namespace ecs; using namespace ecs;

src/systems/locomotion-system.hpp → src/game/systems/locomotion-system.hpp View File


src/systems/nest-system.cpp → src/game/systems/nest-system.cpp View File


src/systems/nest-system.hpp → src/game/systems/nest-system.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_NEST_SYSTEM_HPP #define ANTKEEPER_NEST_SYSTEM_HPP
#include "entity-system.hpp" #include "entity-system.hpp"
#include "entity/components/nest-component.hpp"
#include "game/components/nest-component.hpp"
class nest; class nest;
class resource_manager; class resource_manager;

src/systems/placement-system.cpp → src/game/systems/placement-system.cpp View File

@ -18,10 +18,10 @@
*/ */
#include "placement-system.hpp" #include "placement-system.hpp"
#include "entity/components/collision-component.hpp"
#include "entity/components/placement-component.hpp"
#include "entity/components/transform-component.hpp"
#include "entity/components/terrain-component.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/placement-component.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/terrain-component.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
using namespace ecs; using namespace ecs;

src/systems/placement-system.hpp → src/game/systems/placement-system.hpp View File


src/systems/render-system.cpp → src/game/systems/render-system.cpp View File

@ -18,13 +18,14 @@
*/ */
#include "render-system.hpp" #include "render-system.hpp"
#include "entity/components/transform-component.hpp"
#include <algorithm>
#include "game/components/transform-component.hpp"
#include "renderer/renderer.hpp"
using namespace ecs; using namespace ecs;
render_system::render_system(entt::registry& registry): render_system::render_system(entt::registry& registry):
entity_system(registry)
entity_system(registry),
renderer(nullptr)
{ {
registry.on_construct<model_component>().connect<&render_system::on_model_construct>(this); registry.on_construct<model_component>().connect<&render_system::on_model_construct>(this);
registry.on_replace<model_component>().connect<&render_system::on_model_replace>(this); registry.on_replace<model_component>().connect<&render_system::on_model_replace>(this);
@ -51,6 +52,17 @@ void render_system::update(double t, double dt)
); );
} }
void render_system::render(double alpha)
{
if (renderer)
{
for (const scene* scene: layers)
{
renderer->render(alpha, *scene);
}
}
}
void render_system::add_layer(::scene* layer) void render_system::add_layer(::scene* layer)
{ {
layers.push_back(layer); layers.push_back(layer);
@ -61,6 +73,11 @@ void render_system::remove_layers()
layers.clear(); layers.clear();
} }
void render_system::set_renderer(::renderer* renderer)
{
this->renderer = renderer;
}
void render_system::update_model_and_materials(entt::entity entity, model_component& model) void render_system::update_model_and_materials(entt::entity entity, model_component& model)
{ {
if (auto model_it = model_instances.find(entity); model_it != model_instances.end()) if (auto model_it = model_instances.find(entity); model_it != model_instances.end())

src/systems/render-system.hpp → src/game/systems/render-system.hpp View File

@ -23,18 +23,25 @@
#include "entity-system.hpp" #include "entity-system.hpp"
#include "scene/scene.hpp" #include "scene/scene.hpp"
#include "scene/model-instance.hpp" #include "scene/model-instance.hpp"
#include "entity/components/model-component.hpp"
#include "game/components/model-component.hpp"
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
class renderer;
class render_system: public entity_system class render_system: public entity_system
{ {
public: public:
render_system(entt::registry& registry); render_system(entt::registry& registry);
virtual void update(double t, double dt); virtual void update(double t, double dt);
void render(double alpha);
void add_layer(::scene* layer); void add_layer(::scene* layer);
void remove_layers(); void remove_layers();
void set_renderer(::renderer* renderer);
private: private:
void update_model_and_materials(entt::entity entity, ecs::model_component& model); void update_model_and_materials(entt::entity entity, ecs::model_component& model);
@ -43,6 +50,7 @@ private:
void on_model_replace(entt::registry& registry, entt::entity entity, ecs::model_component& model); void on_model_replace(entt::registry& registry, entt::entity entity, ecs::model_component& model);
void on_model_destroy(entt::registry& registry, entt::entity entity); void on_model_destroy(entt::registry& registry, entt::entity entity);
renderer* renderer;
std::vector<scene*> layers; std::vector<scene*> layers;
std::unordered_map<entt::entity, model_instance*> model_instances; std::unordered_map<entt::entity, model_instance*> model_instances;
}; };

src/systems/samara-system.cpp → src/game/systems/samara-system.cpp View File

@ -18,8 +18,8 @@
*/ */
#include "samara-system.hpp" #include "samara-system.hpp"
#include "entity/components/transform-component.hpp"
#include "entity/components/samara-component.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/samara-component.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"

src/systems/samara-system.hpp → src/game/systems/samara-system.hpp View File


src/systems/subterrain-system.cpp → src/game/systems/subterrain-system.cpp View File

@ -18,8 +18,8 @@
*/ */
#include "subterrain-system.hpp" #include "subterrain-system.hpp"
#include "entity/components/model-component.hpp"
#include "entity/components/cavity-component.hpp"
#include "game/components/model-component.hpp"
#include "game/components/cavity-component.hpp"
#include "renderer/model.hpp" #include "renderer/model.hpp"
#include "renderer/material.hpp" #include "renderer/material.hpp"
#include "geometry/mesh-functions.hpp" #include "geometry/mesh-functions.hpp"
@ -34,7 +34,6 @@
#include "scene/model-instance.hpp" #include "scene/model-instance.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
#include <array> #include <array>
#include <iostream>
#include <limits> #include <limits>
using namespace ecs; using namespace ecs;
@ -285,13 +284,14 @@ void subterrain_system::update(double t, double dt)
if (digging) if (digging)
{ {
std::cout << "regenerating subterrain mesh...\n";
//std::cout << "regenerating subterrain mesh...\n";
regenerate_subterrain_mesh(); regenerate_subterrain_mesh();
std::cout << "regenerating subterrain mesh... done\n";
//std::cout << "regenerating subterrain mesh... done\n";
std::cout << "regenerating subterrain model...\n";
//std::cout << "regenerating subterrain model...\n";
regenerate_subterrain_model(); regenerate_subterrain_model();
std::cout << "regenerating subterrain model... done\n";
//std::cout << "regenerating subterrain model... done\n";
} }
} }
@ -308,18 +308,18 @@ void subterrain_system::regenerate_subterrain_mesh()
subterrain_triangles.clear(); subterrain_triangles.clear();
subterrain_vertex_map.clear(); subterrain_vertex_map.clear();
std::cout << "marching...\n";
//std::cout << "marching...\n";
merged = 0; merged = 0;
march(cube_tree); march(cube_tree);
std::cout << "merged " << merged << " vertices\n";
std::cout << "marching...done\n";
//std::cout << "merged " << merged << " vertices\n";
//std::cout << "marching...done\n";
std::cout << "vertex count: " << subterrain_vertices.size() << std::endl;
std::cout << "triangle count: " << subterrain_triangles.size() << std::endl;
//std::cout << "vertex count: " << subterrain_vertices.size() << std::endl;
//std::cout << "triangle count: " << subterrain_triangles.size() << std::endl;
std::cout << "creating mesh...\n";
//std::cout << "creating mesh...\n";
create_triangle_mesh(*subterrain_mesh, subterrain_vertices, subterrain_triangles); create_triangle_mesh(*subterrain_mesh, subterrain_vertices, subterrain_triangles);
std::cout << "creating mesh... done\n";
//std::cout << "creating mesh... done\n";
} }
void subterrain_system::march(::cube_tree* node) void subterrain_system::march(::cube_tree* node)

src/systems/subterrain-system.hpp → src/game/systems/subterrain-system.hpp View File


src/systems/terrain-system.cpp → src/game/systems/terrain-system.cpp View File

@ -18,9 +18,9 @@
*/ */
#include "terrain-system.hpp" #include "terrain-system.hpp"
#include "entity/components/model-component.hpp"
#include "entity/components/collision-component.hpp"
#include "entity/components/transform-component.hpp"
#include "game/components/model-component.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/transform-component.hpp"
#include "renderer/model.hpp" #include "renderer/model.hpp"
#include "geometry/mesh.hpp" #include "geometry/mesh.hpp"
#include "geometry/mesh-functions.hpp" #include "geometry/mesh-functions.hpp"

src/systems/terrain-system.hpp → src/game/systems/terrain-system.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_TERRAIN_SYSTEM_HPP #define ANTKEEPER_TERRAIN_SYSTEM_HPP
#include "entity-system.hpp" #include "entity-system.hpp"
#include "entity/components/terrain-component.hpp"
#include "game/components/terrain-component.hpp"
class terrain; class terrain;
class resource_manager; class resource_manager;

src/systems/tool-system.cpp → src/game/systems/tool-system.cpp View File

@ -18,9 +18,9 @@
*/ */
#include "tool-system.hpp" #include "tool-system.hpp"
#include "entity/components/collision-component.hpp"
#include "entity/components/tool-component.hpp"
#include "entity/components/transform-component.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/tool-component.hpp"
#include "game/components/transform-component.hpp"
#include "scene/camera.hpp" #include "scene/camera.hpp"
#include "orbit-cam.hpp" #include "orbit-cam.hpp"
#include "geometry/mesh.hpp" #include "geometry/mesh.hpp"

src/systems/tool-system.hpp → src/game/systems/tool-system.hpp View File

@ -22,7 +22,7 @@
#include "entity-system.hpp" #include "entity-system.hpp"
#include "event/event-handler.hpp" #include "event/event-handler.hpp"
#include "input/input-events.hpp"
#include "event/input-events.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
class camera; class camera;

src/systems/ui-system.cpp → src/game/systems/ui-system.cpp View File

@ -23,11 +23,10 @@
ui_system::ui_system(::resource_manager* resource_manager): ui_system::ui_system(::resource_manager* resource_manager):
resource_manager(resource_manager), resource_manager(resource_manager),
tool_menu_control(nullptr)
tool_menu_control(nullptr),
camera(nullptr),
scene(nullptr)
{ {
// Setup camera
camera.look_at({0.0f, 0.0f, 500.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f});
// Setup lighting // Setup lighting
indirect_light.set_intensity(0.25f); indirect_light.set_intensity(0.25f);
indirect_light.update_tweens(); indirect_light.update_tweens();
@ -60,10 +59,10 @@ ui_system::ui_system(::resource_manager* resource_manager):
energy_symbol.set_active(false); energy_symbol.set_active(false);
// Setup scene // Setup scene
scene.add_object(&camera);
scene.add_object(&indirect_light);
scene.add_object(&direct_light);
scene.add_object(&energy_symbol);
//scene.add_object(&camera);
//scene.add_object(&indirect_light);
//scene.add_object(&direct_light);
//scene.add_object(&energy_symbol);
} }
void ui_system::update(float dt) void ui_system::update(float dt)
@ -77,14 +76,8 @@ void ui_system::set_viewport(const float4& viewport)
viewport_center[0] = (viewport[2] - viewport[0]) * 0.5f; viewport_center[0] = (viewport[2] - viewport[0]) * 0.5f;
viewport_center[1] = (viewport[3] - viewport[1]) * 0.5f; viewport_center[1] = (viewport[3] - viewport[1]) * 0.5f;
// Recalculate orthographic projection
float clip_left = -viewport[2] * 0.5f;
float clip_right = viewport[2] * 0.5f;
float clip_top = -viewport[3] * 0.5f;
float clip_bottom = viewport[3] * 0.5f;
float clip_near = 0.0f;
float clip_far = 1000.0f;
camera.set_orthographic(clip_left, clip_right, clip_top, clip_bottom, clip_near, clip_far);
energy_symbol.set_translation({viewport[2] * 0.25f, 0.0f, 0.0f}); energy_symbol.set_translation({viewport[2] * 0.25f, 0.0f, 0.0f});
energy_symbol.update_tweens(); energy_symbol.update_tweens();
@ -92,6 +85,8 @@ void ui_system::set_viewport(const float4& viewport)
// Resize modal BG // Resize modal BG
modal_bg.set_scale({viewport[2] * 0.5f, viewport[3] * 0.5f, 1.0f}); modal_bg.set_scale({viewport[2] * 0.5f, viewport[3] * 0.5f, 1.0f});
modal_bg.update_tweens(); modal_bg.update_tweens();
update_projection();
} }
void ui_system::set_tool_menu_control(control* control) void ui_system::set_tool_menu_control(control* control)
@ -101,6 +96,22 @@ void ui_system::set_tool_menu_control(control* control)
tool_menu_control->set_deactivated_callback(std::bind(&ui_system::close_tool_menu, this)); tool_menu_control->set_deactivated_callback(std::bind(&ui_system::close_tool_menu, this));
} }
void ui_system::set_camera(::camera* camera)
{
this->camera = camera;
if (camera)
{
camera->look_at({0.0f, 0.0f, 500.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f});
update_projection();
}
}
void ui_system::set_scene(::scene* scene)
{
this->scene = scene;
}
void ui_system::handle_event(const mouse_moved_event& event) void ui_system::handle_event(const mouse_moved_event& event)
{ {
if (tool_menu_control->is_active()) if (tool_menu_control->is_active())
@ -142,19 +153,39 @@ void ui_system::handle_event(const mouse_moved_event& event)
mouse_position[1] = event.y; mouse_position[1] = event.y;
} }
void ui_system::update_projection()
{
if (camera)
{
float clip_left = -viewport[2] * 0.5f;
float clip_right = viewport[2] * 0.5f;
float clip_top = -viewport[3] * 0.5f;
float clip_bottom = viewport[3] * 0.5f;
float clip_near = 0.0f;
float clip_far = 1000.0f;
camera->set_orthographic(clip_left, clip_right, clip_top, clip_bottom, clip_near, clip_far);
}
}
void ui_system::open_tool_menu() void ui_system::open_tool_menu()
{ {
scene.add_object(&modal_bg);
scene.add_object(&tool_selector_bg);
scene.add_object(&tool_selector_ant);
if (scene)
{
scene->add_object(&modal_bg);
scene->add_object(&tool_selector_bg);
scene->add_object(&tool_selector_ant);
}
tool_selection_vector = {0, 0}; tool_selection_vector = {0, 0};
} }
void ui_system::close_tool_menu() void ui_system::close_tool_menu()
{ {
scene.remove_object(&modal_bg);
scene.remove_object(&tool_selector_bg);
scene.remove_object(&tool_selector_ant);
if (scene)
{
scene->remove_object(&modal_bg);
scene->remove_object(&tool_selector_bg);
scene->remove_object(&tool_selector_ant);
}
} }
void ui_system::open_elevator_menu() void ui_system::open_elevator_menu()

src/systems/ui-system.hpp → src/game/systems/ui-system.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_UI_SYSTEM_HPP #define ANTKEEPER_UI_SYSTEM_HPP
#include "event/event-handler.hpp" #include "event/event-handler.hpp"
#include "input/input-events.hpp"
#include "event/input-events.hpp"
#include "scene/scene.hpp" #include "scene/scene.hpp"
#include "scene/camera.hpp" #include "scene/camera.hpp"
#include "scene/directional-light.hpp" #include "scene/directional-light.hpp"
@ -46,23 +46,23 @@ public:
void set_viewport(const float4& viewport); void set_viewport(const float4& viewport);
void set_tool_menu_control(control* control); void set_tool_menu_control(control* control);
const ::scene* get_scene() const;
::scene* get_scene();
const ::camera* get_camera() const;
::camera* get_camera();
void set_camera(::camera* camera);
void set_scene(::scene* scene);
private: private:
virtual void handle_event(const mouse_moved_event& event); virtual void handle_event(const mouse_moved_event& event);
void update_projection();
void open_tool_menu(); void open_tool_menu();
void close_tool_menu(); void close_tool_menu();
void open_elevator_menu(); void open_elevator_menu();
void close_elevator_menu(); void close_elevator_menu();
::resource_manager* resource_manager;
::scene scene;
::camera camera;
resource_manager* resource_manager;
scene* scene;
camera* camera;
ambient_light indirect_light; ambient_light indirect_light;
directional_light direct_light; directional_light direct_light;
model_instance tool_selector_ant; model_instance tool_selector_ant;
@ -81,25 +81,5 @@ private:
control* tool_menu_control; control* tool_menu_control;
}; };
inline const scene* ui_system::get_scene() const
{
return &scene;
}
inline scene* ui_system::get_scene()
{
return &scene;
}
inline const camera* ui_system::get_camera() const
{
return &camera;
}
inline camera* ui_system::get_camera()
{
return &camera;
}
#endif // ANTKEEPER_UI_SYSTEM_HPP #endif // ANTKEEPER_UI_SYSTEM_HPP

src/systems/updatable-system.cpp → src/game/systems/updatable-system.cpp View File


src/systems/updatable-system.hpp → src/game/systems/updatable-system.hpp View File


src/systems/vegetation-system.cpp → src/game/systems/vegetation-system.cpp View File

@ -18,8 +18,8 @@
*/ */
#include "vegetation-system.hpp" #include "vegetation-system.hpp"
#include "entity/components/model-component.hpp"
#include "entity/components/transform-component.hpp"
#include "game/components/model-component.hpp"
#include "game/components/transform-component.hpp"
#include "scene/model-instance.hpp" #include "scene/model-instance.hpp"
#include "scene/lod-group.hpp" #include "scene/lod-group.hpp"
#include "scene/scene.hpp" #include "scene/scene.hpp"

src/systems/vegetation-system.hpp → src/game/systems/vegetation-system.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_VEGETATION_SYSTEM_HPP #define ANTKEEPER_VEGETATION_SYSTEM_HPP
#include "entity-system.hpp" #include "entity-system.hpp"
#include "entity/components/terrain-component.hpp"
#include "game/components/terrain-component.hpp"
class model; class model;
class scene; class scene;

+ 3
- 6
src/geometry/mesh-accelerator.cpp View File

@ -17,10 +17,9 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "mesh-accelerator.hpp"
#include "mesh-functions.hpp"
#include "morton.hpp"
#include <iostream>
#include "geometry/mesh-accelerator.hpp"
#include "geometry/mesh-functions.hpp"
#include "geometry/morton.hpp"
#include <bitset> #include <bitset>
mesh_accelerator::mesh_accelerator() mesh_accelerator::mesh_accelerator()
@ -107,8 +106,6 @@ void mesh_accelerator::query_nearest_recursive(float& nearest_t, ::mesh::face*&
{ {
const std::list<mesh::face*>& faces = it->second; const std::list<mesh::face*>& faces = it->second;
//std::cout << std::bitset<32>(node) << " has " << faces.size() << " faces\n";
for (mesh::face* face: faces) for (mesh::face* face: faces)
{ {
// Get triangle coordinates // Get triangle coordinates

+ 23
- 2
src/input/game-controller.cpp View File

@ -18,11 +18,12 @@
*/ */
#include "game-controller.hpp" #include "game-controller.hpp"
#include "input-events.hpp"
#include "event/input-events.hpp"
#include "event/event-dispatcher.hpp" #include "event/event-dispatcher.hpp"
#include <cmath> #include <cmath>
game_controller::game_controller()
game_controller::game_controller():
connected(true)
{} {}
void game_controller::press(game_controller_button button) void game_controller::press(game_controller_button button)
@ -68,3 +69,23 @@ void game_controller::move(game_controller_axis axis, float value)
input_device::event_dispatcher->queue(event); input_device::event_dispatcher->queue(event);
} }
void game_controller::connect(bool reconnected)
{
connected = true;
game_controller_connected_event event;
event.game_controller = this;
event.reconnected = reconnected;
input_device::event_dispatcher->queue(event);
}
void game_controller::disconnect()
{
connected = false;
game_controller_disconnected_event event;
event.game_controller = this;
input_device::event_dispatcher->queue(event);
}

+ 21
- 0
src/input/game-controller.hpp View File

@ -89,7 +89,28 @@ public:
* @param value Normalized degree of movement. * @param value Normalized degree of movement.
*/ */
void move(game_controller_axis axis, float value); void move(game_controller_axis axis, float value);
/**
* Simulates a game controller being connected.
*
* @param reconnected `true` if the controller is being reconnected, or `false` if the controller is being connected for the first time.
*/
void connect(bool reconnnected);
/// Simulates a game controller being disconnected.
void disconnect();
/// Returns `true` if the controller is currently connected.
bool is_connected() const;
private:
bool connected;
}; };
inline bool game_controller::is_connected() const
{
return connected;
}
#endif // ANTKEEPER_GAME_CONTROLLER_HPP #endif // ANTKEEPER_GAME_CONTROLLER_HPP

+ 1
- 1
src/input/input-event-router.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEER_INPUT_EVENT_ROUTER_HPP #ifndef ANTKEEER_INPUT_EVENT_ROUTER_HPP
#define ANTKEEER_INPUT_EVENT_ROUTER_HPP #define ANTKEEER_INPUT_EVENT_ROUTER_HPP
#include "input-events.hpp"
#include "event/input-events.hpp"
#include "event/event-handler.hpp" #include "event/event-handler.hpp"
#include <list> #include <list>
#include <map> #include <map>

+ 2
- 2
src/input/input-mapper.hpp View File

@ -20,8 +20,8 @@
#ifndef ANTKEEPER_INPUT_MAPPER_HPP #ifndef ANTKEEPER_INPUT_MAPPER_HPP
#define ANTKEEPER_INPUT_MAPPER_HPP #define ANTKEEPER_INPUT_MAPPER_HPP
#include "input-events.hpp"
#include "input-mapping.hpp"
#include "input/input-mapping.hpp"
#include "event/input-events.hpp"
#include "event/event-handler.hpp" #include "event/event-handler.hpp"
#include <functional> #include <functional>

+ 1
- 1
src/input/keyboard.cpp View File

@ -20,7 +20,7 @@
#include "keyboard.hpp" #include "keyboard.hpp"
#include "scancode.hpp" #include "scancode.hpp"
#include "event/event-dispatcher.hpp" #include "event/event-dispatcher.hpp"
#include "input-events.hpp"
#include "event/input-events.hpp"
const char* keyboard::get_scancode_name(scancode scancode) const char* keyboard::get_scancode_name(scancode scancode)
{ {

+ 1
- 1
src/input/mouse.cpp View File

@ -18,7 +18,7 @@
*/ */
#include "mouse.hpp" #include "mouse.hpp"
#include "input-events.hpp"
#include "event/input-events.hpp"
#include "event/event-dispatcher.hpp" #include "event/event-dispatcher.hpp"
mouse::mouse() mouse::mouse()

+ 6
- 3
src/main.cpp View File

@ -18,20 +18,23 @@
*/ */
#include "application.hpp" #include "application.hpp"
#include "game/bootloader.hpp"
#include <functional>
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
auto wrapped_bootloader = std::bind(bootloader, std::placeholders::_1, argc, argv);
try try
{ {
return application(argc, argv).execute();
return application().execute(wrapped_bootloader);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
std::cerr << "Unhandled exception: \"" << e.what() << "\"" << std::endl; std::cerr << "Unhandled exception: \"" << e.what() << "\"" << std::endl;
} }
return EXIT_FAILURE; return EXIT_FAILURE;
} }

+ 64
- 1
src/math/stream-operators.hpp View File

@ -61,6 +61,36 @@ std::ostream& operator<<(std::ostream& os, const matrix& m);
template <class T> template <class T>
std::ostream& operator<<(std::ostream& os, const quaternion<T>& q); std::ostream& operator<<(std::ostream& os, const quaternion<T>& q);
/**
* Reads the elements of a vector from an input stream, with each element delimeted by a space.
*
* @param is Input stream.
* @param v Vector.
* @return Input stream.
*/
template <class T, std::size_t N>
std::istream& operator>>(std::istream& is, vector<T, N>& v);
/**
* Reads the elements of a matrix from an input stream, with each element delimeted by a space.
*
* @param is Input stream.
* @param m Matrix.
* @return Input stream.
*/
template <class T, std::size_t N, std::size_t M>
std::istream& operator>>(std::istream& is, matrix<T, N, M>& m);
/**
* Reads the real and imaginary parts of a quaternion from an input stream, with each number delimeted by a space.
*
* @param is Input stream.
* @param q Quaternion.
* @return Input stream.
*/
template <class T>
std::istream& operator>>(std::istream& is, const quaternion<T>& q);
template <class T, std::size_t N> template <class T, std::size_t N>
std::ostream& operator<<(std::ostream& os, const vector<T, N>& v) std::ostream& operator<<(std::ostream& os, const vector<T, N>& v)
{ {
@ -99,10 +129,43 @@ std::ostream& operator<<(std::ostream& os, const matrix& m)
template <class T> template <class T>
std::ostream& operator<<(std::ostream& os, const quaternion<T>& q) std::ostream& operator<<(std::ostream& os, const quaternion<T>& q)
{ {
os << std::get<0>(q) << ' ' << std::get<1>(q)[0] << ' ' << std::get<1>(q)[1] << ' ' << std::get<1>(q)[2];
os << q.w << ' ' << q.x << ' ' << q.y << ' ' << q.z;
return os; return os;
} }
template <class T, std::size_t N>
std::istream& operator>>(std::istream& is, vector<T, N>& v)
{
for (std::size_t i = 0; i < N; ++i)
is >> v[i];
return is;
}
template <class T, std::size_t N, std::size_t M>
std::istream& operator>>(std::istream& is, matrix<T, N, M>& m)
{
for (std::size_t i = 0; i < N * M; ++i)
{
std::size_t j = i / M;
std::size_t k = i % M;
is >> m[j][k];
}
return is;
}
template <class T>
std::istream& operator>>(std::istream& is, const quaternion<T>& q)
{
is >> q.w;
is >> q.x;
is >> q.y;
is >> q.z;
return is;
}
/// @} /// @}
} // namespace stream_operators } // namespace stream_operators

+ 3
- 2
src/rasterizer/framebuffer.cpp View File

@ -40,6 +40,7 @@ framebuffer::framebuffer(int width, int height):
framebuffer::framebuffer(): framebuffer::framebuffer():
gl_framebuffer_id(0), gl_framebuffer_id(0),
dimensions({0, 0}),
color_attachment(nullptr), color_attachment(nullptr),
depth_attachment(nullptr), depth_attachment(nullptr),
stencil_attachment(nullptr) stencil_attachment(nullptr)
@ -53,9 +54,9 @@ framebuffer::~framebuffer()
} }
} }
void framebuffer::resize(int width, int height)
void framebuffer::resize(const std::array<int, 2>& dimensions)
{ {
dimensions = {width, height};
this->dimensions = dimensions;
} }
void framebuffer::attach(framebuffer_attachment_type attachment_type, texture_2d* texture) void framebuffer::attach(framebuffer_attachment_type attachment_type, texture_2d* texture)

+ 5
- 5
src/rasterizer/framebuffer.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_FRAMEBUFFER_HPP #ifndef ANTKEEPER_FRAMEBUFFER_HPP
#define ANTKEEPER_FRAMEBUFFER_HPP #define ANTKEEPER_FRAMEBUFFER_HPP
#include <tuple>
#include <array>
class rasterizer; class rasterizer;
class texture_2d; class texture_2d;
@ -49,7 +49,7 @@ public:
* @param width New width of the framebuffer. * @param width New width of the framebuffer.
* @param height New height of the framebuffer. * @param height New height of the framebuffer.
*/ */
void resize(int width, int height);
void resize(const std::array<int, 2>& dimensions);
/** /**
* Attaches a color, depth, or stencil texture to the framebuffer. * Attaches a color, depth, or stencil texture to the framebuffer.
@ -59,7 +59,7 @@ public:
void attach(framebuffer_attachment_type attachment_type, texture_2d* texture); void attach(framebuffer_attachment_type attachment_type, texture_2d* texture);
/// Returns the dimensions of the framebuffer, in pixels. /// Returns the dimensions of the framebuffer, in pixels.
const std::tuple<int, int>& get_dimensions() const;
const std::array<int, 2>& get_dimensions() const;
const texture_2d* get_color_attachment() const; const texture_2d* get_color_attachment() const;
texture_2d* get_color_attachment(); texture_2d* get_color_attachment();
@ -74,13 +74,13 @@ private:
framebuffer(); framebuffer();
unsigned int gl_framebuffer_id; unsigned int gl_framebuffer_id;
std::tuple<int, int> dimensions;
std::array<int, 2> dimensions;
texture_2d* color_attachment; texture_2d* color_attachment;
texture_2d* depth_attachment; texture_2d* depth_attachment;
texture_2d* stencil_attachment; texture_2d* stencil_attachment;
}; };
inline const std::tuple<int, int>& framebuffer::get_dimensions() const
inline const std::array<int, 2>& framebuffer::get_dimensions() const
{ {
return dimensions; return dimensions;
} }

+ 1
- 1
src/rasterizer/rasterizer.cpp View File

@ -67,7 +67,7 @@ rasterizer::~rasterizer()
delete default_framebuffer; delete default_framebuffer;
} }
void rasterizer::window_resized(int width, int height)
void rasterizer::context_resized(int width, int height)
{ {
default_framebuffer->dimensions = {width, height}; default_framebuffer->dimensions = {width, height};
} }

+ 1
- 1
src/rasterizer/rasterizer.hpp View File

@ -45,7 +45,7 @@ public:
/** /**
* This should be called when the window associated with the OpenGL context is resized, and will effectively changed the reported dimensions of the default framebuffer. * This should be called when the window associated with the OpenGL context is resized, and will effectively changed the reported dimensions of the default framebuffer.
*/ */
void window_resized(int width, int height);
void context_resized(int width, int height);
/** /**
* Sets the active framebuffer. * Sets the active framebuffer.

+ 0
- 1
src/rasterizer/shader-input.cpp View File

@ -209,7 +209,6 @@ bool shader_input::upload(const float4x4& value) const
return true; return true;
} }
#include <iostream>
bool shader_input::upload(const texture_2d* value) const bool shader_input::upload(const texture_2d* value) const
{ {
if (gl_uniform_location == -1) if (gl_uniform_location == -1)

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

@ -48,7 +48,6 @@
#include "math/math.hpp" #include "math/math.hpp"
#include <cmath> #include <cmath>
#include <glad/glad.h> #include <glad/glad.h>
#include <iostream>
#include "shadow-map-pass.hpp" #include "shadow-map-pass.hpp"

+ 2
- 2
src/resources/behavior-tree-loader.cpp View File

@ -19,8 +19,8 @@
#include "resource-loader.hpp" #include "resource-loader.hpp"
#include "resource-manager.hpp" #include "resource-manager.hpp"
#include "behavior/ebt.hpp"
#include "nlohmann/json.hpp"
#include "game/behavior/ebt.hpp"
#include <nlohmann/json.hpp>
#include <functional> #include <functional>
#include <map> #include <map>
#include <stdexcept> #include <stdexcept>

+ 53
- 0
src/resources/config-file-loader.cpp View File

@ -0,0 +1,53 @@
/*
* 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 "resources/resource-loader.hpp"
#include "resources/resource-manager.hpp"
#include "resources/config-file.hpp"
#include "resources/text-file.hpp"
template <>
config_file* resource_loader<config_file>::load(resource_manager* resource_manager, PHYSFS_File* file)
{
// Load as text file
text_file* text = resource_loader<text_file>::load(resource_manager, file);
config_file* config = new config_file();
for (const std::string& line: *text)
{
if (line[0] == '#')
continue;
std::size_t delimeter = line.find_first_of('=');
if (delimeter == std::string::npos)
continue;
std::string name = line.substr(0, delimeter);
std::string value = line.substr(delimeter + 1, line.length() - delimeter - 1);
if (name.empty() || value.empty())
continue;
config->set<std::string>(name, value);
}
delete text;
return config;
}

+ 64
- 0
src/resources/config-file.hpp View File

@ -0,0 +1,64 @@
/*
* 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 CONFIG_FILE_HPP
#define CONFIG_FILE_HPP
#include <sstream>
#include <string>
#include <unordered_map>
class config_file
{
public:
template <typename T>
void set(const std::string& name, const T& value);
template <typename T>
T get(const std::string& name) const;
bool has(const std::string& name) const;
private:
std::unordered_map<std::string, std::string> variables;
};
template <typename T>
void config_file::set(const std::string& name, const T& value)
{
std::stringstream stream;
stream << value;
variables[name] = stream.str();
}
template <typename T>
T config_file::get(const std::string& name) const
{
T value;
if (auto it = variables.find(name); it != variables.end())
std::stringstream(it->second) >> value;
return value;
}
inline bool config_file::has(const std::string& name) const
{
return (variables.find(name) != variables.end());
}
#endif // CONFIG_FILE_HPP

+ 7
- 7
src/resources/entity-archetype-loader.cpp View File

@ -21,14 +21,14 @@
#include "resource-manager.hpp" #include "resource-manager.hpp"
#include "string-table.hpp" #include "string-table.hpp"
#include "renderer/model.hpp" #include "renderer/model.hpp"
#include "entity/components/behavior-component.hpp"
#include "entity/components/collision-component.hpp"
#include "entity/components/terrain-component.hpp"
#include "entity/components/transform-component.hpp"
#include "entity/components/model-component.hpp"
#include "entity/components/nest-component.hpp"
#include "game/components/behavior-component.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/terrain-component.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/model-component.hpp"
#include "game/components/nest-component.hpp"
#include "entity/archetype.hpp" #include "entity/archetype.hpp"
#include "behavior/ebt.hpp"
#include "game/behavior/ebt.hpp"
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>

+ 44
- 7
src/resources/resource-manager.cpp View File

@ -19,16 +19,57 @@
#include "resources/resource-manager.hpp" #include "resources/resource-manager.hpp"
resource_manager::resource_manager():
logger(nullptr)
{}
resource_manager::resource_manager(::logger* logger):
logger(logger)
{
// Init PhysicsFS
logger->push_task("Initializing PhysicsFS");
if (!PHYSFS_init(nullptr))
{
logger->error(std::string("PhysicsFS error: ") + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
logger->pop_task(EXIT_FAILURE);
}
else
{
logger->pop_task(EXIT_SUCCESS);
}
}
resource_manager::~resource_manager() resource_manager::~resource_manager()
{ {
// Delete cached resources
for (auto it = resource_cache.begin(); it != resource_cache.end(); ++it) for (auto it = resource_cache.begin(); it != resource_cache.end(); ++it)
{ {
delete it->second; delete it->second;
} }
// Deinit PhysicsFS
logger->push_task("Deinitializing PhysicsFS");
if (!PHYSFS_deinit())
{
logger->error(std::string("PhysicsFS error: ") + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
logger->pop_task(EXIT_FAILURE);
}
else
{
logger->pop_task(EXIT_SUCCESS);
}
}
bool resource_manager::mount(const std::string& path)
{
logger->push_task("Mounting path \"" + path + "\"");
if (!PHYSFS_mount(path.c_str(), nullptr, 1))
{
logger->error(std::string("PhysicsFS error: ") + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
logger->pop_task(EXIT_FAILURE);
return false;
}
else
{
logger->pop_task(EXIT_SUCCESS);
return true;
}
} }
void resource_manager::unload(const std::string& name) void resource_manager::unload(const std::string& name)
@ -66,7 +107,3 @@ void resource_manager::include(const std::string& search_path)
search_paths.push_back(search_path); search_paths.push_back(search_path);
} }
void resource_manager::set_logger(::logger* logger)
{
this->logger = logger;
}

+ 4
- 4
src/resources/resource-manager.hpp View File

@ -40,12 +40,14 @@ public:
/** /**
* Creates a resource manager. * Creates a resource manager.
*/ */
resource_manager();
resource_manager(::logger* logger);
/** /**
* Destroys a resource manager and frees all of its resources. * Destroys a resource manager and frees all of its resources.
*/ */
~resource_manager(); ~resource_manager();
bool mount(const std::string& path);
/** /**
* Adds a path to be searched when a resource is requested. * Adds a path to be searched when a resource is requested.
@ -82,14 +84,12 @@ public:
void save(const T* resource, const std::string& path); void save(const T* resource, const std::string& path);
entt::registry& get_archetype_registry(); entt::registry& get_archetype_registry();
void set_logger(::logger* logger);
private: private:
std::map<std::string, resource_handle_base*> resource_cache; std::map<std::string, resource_handle_base*> resource_cache;
std::list<std::string> search_paths; std::list<std::string> search_paths;
entt::registry archetype_registry; entt::registry archetype_registry;
::logger* logger;
logger* logger;
}; };
template <typename T> template <typename T>

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save