Browse Source

Rename scene class to collection and move all scene-related classes into the scene namespace

master
C. J. Howard 1 week ago
parent
commit
978ad7add6
58 changed files with 474 additions and 375 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +1
    -2
      src/animation/camera-rig.cpp
  3. +5
    -5
      src/animation/camera-rig.hpp
  4. +2
    -2
      src/animation/screen-transition.cpp
  5. +3
    -3
      src/animation/screen-transition.hpp
  6. +17
    -22
      src/game/bootloader.cpp
  7. +17
    -23
      src/game/game-context.hpp
  8. +0
    -1
      src/game/states/map-state.cpp
  9. +2
    -2
      src/game/states/play-state.cpp
  10. +1
    -1
      src/game/states/splash-state.cpp
  11. +1
    -3
      src/game/systems/camera-system.cpp
  12. +3
    -3
      src/game/systems/camera-system.hpp
  13. +2
    -3
      src/game/systems/control-system.cpp
  14. +5
    -5
      src/game/systems/control-system.hpp
  15. +5
    -7
      src/game/systems/painting-system.cpp
  16. +5
    -5
      src/game/systems/painting-system.hpp
  17. +6
    -6
      src/game/systems/render-system.cpp
  18. +5
    -5
      src/game/systems/render-system.hpp
  19. +4
    -6
      src/game/systems/subterrain-system.cpp
  20. +5
    -5
      src/game/systems/subterrain-system.hpp
  21. +1
    -2
      src/game/systems/tool-system.cpp
  22. +3
    -3
      src/game/systems/tool-system.hpp
  23. +6
    -6
      src/game/systems/tracking-system.cpp
  24. +9
    -5
      src/game/systems/tracking-system.hpp
  25. +10
    -10
      src/game/systems/ui-system.cpp
  26. +11
    -12
      src/game/systems/ui-system.hpp
  27. +8
    -8
      src/game/systems/vegetation-system.cpp
  28. +7
    -3
      src/game/systems/vegetation-system.hpp
  29. +11
    -12
      src/renderer/passes/material-pass.cpp
  30. +2
    -4
      src/renderer/passes/shadow-map-pass.cpp
  31. +3
    -4
      src/renderer/passes/shadow-map-pass.hpp
  32. +1
    -3
      src/renderer/passes/sky-pass.cpp
  33. +2
    -3
      src/renderer/passes/ui-pass.cpp
  34. +4
    -5
      src/renderer/render-context.hpp
  35. +26
    -26
      src/renderer/renderer.cpp
  36. +16
    -12
      src/renderer/renderer.hpp
  37. +7
    -3
      src/scene/ambient-light.hpp
  38. +5
    -1
      src/scene/billboard.cpp
  39. +9
    -5
      src/scene/billboard.hpp
  40. +4
    -1
      src/scene/camera.cpp
  41. +10
    -6
      src/scene/camera.hpp
  42. +11
    -10
      src/scene/collection.cpp
  43. +84
    -0
      src/scene/collection.hpp
  44. +3
    -0
      src/scene/directional-light.cpp
  45. +8
    -4
      src/scene/directional-light.hpp
  46. +5
    -1
      src/scene/light.cpp
  47. +10
    -6
      src/scene/light.hpp
  48. +7
    -3
      src/scene/lod-group.cpp
  49. +15
    -11
      src/scene/lod-group.hpp
  50. +5
    -1
      src/scene/model-instance.cpp
  51. +9
    -5
      src/scene/model-instance.hpp
  52. +12
    -8
      src/scene/object.cpp
  53. +23
    -19
      src/scene/object.hpp
  54. +4
    -0
      src/scene/point-light.cpp
  55. +8
    -4
      src/scene/point-light.hpp
  56. +14
    -56
      src/scene/scene.hpp
  57. +3
    -0
      src/scene/spotlight.cpp
  58. +8
    -4
      src/scene/spotlight.hpp

+ 1
- 0
CMakeLists.txt View File

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

+ 1
- 2
src/animation/camera-rig.cpp View File

@ -18,7 +18,6 @@
*/
#include "animation/camera-rig.hpp"
#include "scene/camera.hpp"
#include "math/constants.hpp"
#include "configuration.hpp"
#include <algorithm>
@ -32,7 +31,7 @@ camera_rig::camera_rig():
up(global_up)
{}
void camera_rig::attach(::camera* camera)
void camera_rig::attach(scene::camera* camera)
{
this->camera = camera;
if (camera != nullptr)

+ 5
- 5
src/animation/camera-rig.hpp View File

@ -22,9 +22,9 @@
#include "math/quaternion-type.hpp"
#include "math/transform-type.hpp"
#include "scene/camera.hpp"
#include "utility/fundamental-types.hpp"
class camera;
/**
* Abstract base class for camera rigs which control the movement of cameras.
@ -49,7 +49,7 @@ public:
*
* @param camera Camera to attach.
*/
void attach(::camera* camera);
void attach(scene::camera* camera);
/**
* Detaches the camera from the rig.
@ -61,7 +61,7 @@ public:
/**
* Returns the attached camera.
*/
const ::camera* get_camera() const;
const scene::camera* get_camera() const;
const float3& get_translation() const;
const quaternion_type& get_rotation() const;
@ -79,14 +79,14 @@ protected:
void update_projection(float clip_left, float clip_right, float clip_bottom, float clip_top, float clip_near, float clip_far);
private:
camera* camera;
scene::camera* camera;
transform_type transform;
float3 forward;
float3 right;
float3 up;
};
inline const camera* camera_rig::get_camera() const
inline const scene::camera* camera_rig::get_camera() const
{
return camera;
}

+ 2
- 2
src/animation/screen-transition.cpp View File

@ -37,13 +37,13 @@ screen_transition::screen_transition()
// Setup animation start callback to show transition billboard
animation.set_start_callback
(
std::bind(&scene_object_base::set_active, &billboard, true)
std::bind(&scene::object_base::set_active, &billboard, true)
);
// Setup animation end callback to hide transition billboard
animation.set_end_callback
(
std::bind(&scene_object_base::set_active, &billboard, false)
std::bind(&scene::object_base::set_active, &billboard, false)
);
// Setup animation frame callback to update transition progress material property

+ 3
- 3
src/animation/screen-transition.hpp View File

@ -35,19 +35,19 @@ public:
void transition(float duration, bool reverse, animation<float>::interpolator_type interpolator);
::billboard* get_billboard();
scene::billboard* get_billboard();
::material* get_material();
::animation<float>* get_animation();
private:
::billboard billboard;
scene::billboard billboard;
::material material;
material_property<float>* progress;
::animation<float> animation;
::animation<float>::channel* channel;
};
inline billboard* screen_transition::get_billboard()
inline scene::billboard* screen_transition::get_billboard()
{
return &billboard;
}

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

@ -53,12 +53,7 @@
#include "resources/config-file.hpp"
#include "resources/resource-manager.hpp"
#include "resources/resource-manager.hpp"
#include "scene/billboard.hpp"
#include "scene/model-instance.hpp"
#include "scene/point-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/ambient-light.hpp"
#include "scene/spotlight.hpp"
#include "scene/scene.hpp"
#include "game/states/game-states.hpp"
#include "game/systems/behavior-system.hpp"
#include "game/systems/camera-system.hpp"
@ -625,14 +620,14 @@ void setup_scenes(game_context* ctx)
ctx->no_cull = {{-inf, -inf, -inf}, {inf, inf, inf}};
// Setup overworld camera
ctx->overworld_camera = new camera();
ctx->overworld_camera = new scene::camera();
ctx->overworld_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
ctx->overworld_camera->set_compositor(ctx->overworld_compositor);
ctx->overworld_camera->set_composite_index(0);
ctx->overworld_camera->set_active(true);
// Setup underworld camera
ctx->underworld_camera = new camera();
ctx->underworld_camera = new scene::camera();
ctx->underworld_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
ctx->underworld_camera->look_at({0, 50, 0}, {0, 0, 0}, {0, 0, -1});
ctx->underworld_camera->set_compositor(ctx->underworld_compositor);
@ -640,40 +635,40 @@ void setup_scenes(game_context* ctx)
ctx->underworld_camera->set_active(false);
// Setup UI camera
ctx->ui_camera = new camera();
ctx->ui_camera = new scene::camera();
ctx->ui_camera->set_compositor(ctx->ui_compositor);
// Setup lights
ctx->sun_indirect = new ambient_light();
ctx->sun_indirect = new scene::ambient_light();
ctx->sun_indirect->set_intensity(0.0f);
ctx->sun_indirect->update_tweens();
ctx->sun_direct = new directional_light();
ctx->sun_direct = new scene::directional_light();
ctx->sun_direct->set_intensity(0.0f);
ctx->sun_direct->update_tweens();
ctx->moon_light = new directional_light();
ctx->moon_light = new scene::directional_light();
ctx->moon_light->set_intensity(0.0f);
ctx->moon_light->update_tweens();
ctx->subterrain_light = new point_light();
ctx->subterrain_light = new scene::point_light();
ctx->subterrain_light->set_color({1, 1, 1});
ctx->subterrain_light->set_intensity(1.0f);
ctx->subterrain_light->set_attenuation({1.0f, 0.09f, 0.032f});
ctx->subterrain_light->update_tweens();
ctx->underworld_ambient_light = new ambient_light();
ctx->underworld_ambient_light = new scene::ambient_light();
ctx->underworld_ambient_light->set_color({1, 1, 1});
ctx->underworld_ambient_light->set_intensity(0.1f);
ctx->underworld_ambient_light->update_tweens();
ctx->lens_spotlight = new spotlight();
ctx->lens_spotlight = new scene::spotlight();
ctx->lens_spotlight->set_color({1, 1, 1});
ctx->lens_spotlight->set_intensity(20.0f);
ctx->lens_spotlight->set_attenuation({1.0f, 0.0f, 0.0f});
ctx->lens_spotlight->set_cutoff({math::radians(1.25f), math::radians(1.8f)});
ctx->flashlight_spotlight = new spotlight();
ctx->flashlight_spotlight = new scene::spotlight();
ctx->flashlight_spotlight->set_color({1, 1, 1});
ctx->flashlight_spotlight->set_intensity(1.0f);
ctx->flashlight_spotlight->set_attenuation({1.0f, 0.0f, 0.0f});
@ -688,7 +683,7 @@ void setup_scenes(game_context* ctx)
ctx->splash_billboard_material->add_property<const texture_2d*>("background")->set_value(splash_texture);
ctx->splash_billboard_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
ctx->splash_billboard_material->update_tweens();
ctx->splash_billboard = new billboard();
ctx->splash_billboard = new scene::billboard();
ctx->splash_billboard->set_material(ctx->splash_billboard_material);
ctx->splash_billboard->set_scale({(float)std::get<0>(splash_dimensions) * 0.5f, (float)std::get<1>(splash_dimensions) * 0.5f, 1.0f});
ctx->splash_billboard->set_translation({0.0f, 0.0f, 0.0f});
@ -710,7 +705,7 @@ void setup_scenes(game_context* ctx)
*/
// Setup overworld scene
ctx->overworld_scene = new scene();
ctx->overworld_scene = new scene::collection();
ctx->overworld_scene->add_object(ctx->overworld_camera);
ctx->overworld_scene->add_object(ctx->sun_indirect);
ctx->overworld_scene->add_object(ctx->sun_direct);
@ -718,17 +713,17 @@ void setup_scenes(game_context* ctx)
//ctx->overworld_scene->add_object(ctx->spotlight);
// Setup underworld scene
ctx->underworld_scene = new scene();
ctx->underworld_scene = new scene::collection();
ctx->underworld_scene->add_object(ctx->underworld_camera);
ctx->underworld_scene->add_object(ctx->underworld_ambient_light);
//ctx->underworld_scene->add_object(ctx->lantern);
//ctx->underworld_scene->add_object(ctx->subterrain_light);
//ctx->underworld_scene->add_object(ctx->portal_billboard);
//model_instance* larva = new model_instance(ctx->resource_manager->load<model>("larva.mdl"));
//model_instance* larva = new scene::model_instance(ctx->resource_manager->load<model>("larva.mdl"));
//ctx->underworld_scene->add_object(larva);
// Setup UI scene
ctx->ui_scene = new scene();
ctx->ui_scene = new scene::collection();
ctx->ui_scene->add_object(ctx->ui_camera);
ctx->overworld_scene->add_object(ctx->lens_spotlight);
@ -1232,7 +1227,7 @@ void setup_controls(game_context* ctx)
);
// Make lens tool's model instance unculled, so its shadow is always visible.
model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
scene::model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
if (lens_model_instance)
{
lens_model_instance->set_culling_mask(&ctx->no_cull);

+ 17
- 23
src/game/game-context.hpp View File

@ -29,13 +29,10 @@
#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;
@ -45,7 +42,6 @@ class constraint_system;
class control;
class control_set;
class control_system;
class directional_light;
class final_pass;
class framebuffer;
class locomotion_system;
@ -56,17 +52,14 @@ class nest_system;
class orbit_cam;
class pheromone_matrix;
class snapping_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;
@ -78,7 +71,6 @@ class vegetation_system;
class vertex_array;
class vertex_buffer;
class renderer;
class model_instance;
class input_event_router;
class input_mapper;
class outline_pass;
@ -98,6 +90,8 @@ namespace debug
class logger;
}
#include "scene/scene.hpp"
/**
*
*/
@ -177,22 +171,22 @@ struct game_context
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;
directional_light* moon_light;
point_light* subterrain_light;
ambient_light* underworld_ambient_light;
billboard* splash_billboard;
scene::collection* active_scene;
scene::collection* overworld_scene;
scene::collection* underworld_scene;
scene::collection* ui_scene;
scene::camera* overworld_camera;
scene::camera* underworld_camera;
scene::camera* ui_camera;
scene::ambient_light* sun_indirect;
scene::directional_light* sun_direct;
scene::directional_light* moon_light;
scene::point_light* subterrain_light;
scene::ambient_light* underworld_ambient_light;
scene::billboard* splash_billboard;
scene::spotlight* lens_spotlight;
scene::spotlight* flashlight_spotlight;
aabb<float> no_cull;
spotlight* lens_spotlight;
spotlight* flashlight_spotlight;
// Animation
timeline* timeline;

+ 0
- 1
src/game/states/map-state.cpp View File

@ -29,7 +29,6 @@
#include "game/states/game-states.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "scene/billboard.hpp"
#include "scene/scene.hpp"
#include <functional>
void map_state_enter(game_context* ctx)

+ 2
- 2
src/game/states/play-state.cpp View File

@ -46,7 +46,7 @@
#include "renderer/passes/sky-pass.hpp"
#include "resources/resource-manager.hpp"
#include "scene/model-instance.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/camera.hpp"
#include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp"
@ -200,7 +200,7 @@ void play_state_enter(game_context* ctx)
ec::assign_render_layers(ecs_registry, ctx->flashlight_entity, 2);
// Make lens tool's model instance unculled, so its shadow is always visible.
model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
scene::model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
if (lens_model_instance)
{
lens_model_instance->set_culling_mask(&ctx->no_cull);

+ 1
- 1
src/game/states/splash-state.cpp View File

@ -29,7 +29,7 @@
#include "game/states/game-states.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "scene/billboard.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include <functional>
void splash_state_enter(game_context* ctx)

+ 1
- 3
src/game/systems/camera-system.cpp View File

@ -20,11 +20,9 @@
#include "camera-system.hpp"
#include "game/components/camera-follow-component.hpp"
#include "game/components/transform-component.hpp"
#include "scene/camera.hpp"
#include "math/math.hpp"
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace ecs;
@ -96,7 +94,7 @@ void camera_system::zoom(float factor)
orbit_cam.zoom(factor);
}
void camera_system::set_camera(::camera* camera)
void camera_system::set_camera(scene::camera* camera)
{
this->camera = camera;
if (camera)

+ 3
- 3
src/game/systems/camera-system.hpp View File

@ -28,8 +28,8 @@
#include "math/quaternion-type.hpp"
#include "math/transform-type.hpp"
#include "animation/orbit-cam.hpp"
#include "scene/camera.hpp"
class camera;
class orbit_cam;
class camera_system:
@ -48,7 +48,7 @@ public:
void tilt(float angle);
void zoom(float factor);
void set_camera(::camera* camera);
void set_camera(scene::camera* camera);
void set_viewport(const float4& viewport);
const orbit_cam* get_orbit_cam() const;
@ -58,7 +58,7 @@ private:
virtual void handle_event(const mouse_moved_event& event);
virtual void handle_event(const window_resized_event& event);
camera* camera;
scene::camera* camera;
float4 viewport;
float2 mouse_position;

+ 2
- 3
src/game/systems/control-system.cpp View File

@ -19,7 +19,6 @@
#include "control-system.hpp"
#include "input/control.hpp"
#include "scene/camera.hpp"
#include "geometry/intersection.hpp"
#include "animation/ease.hpp"
#include "nest.hpp"
@ -182,7 +181,7 @@ void control_system::set_nest(::nest* nest)
this->nest = nest;
}
void control_system::set_tool(model_instance* tool)
void control_system::set_tool(scene::model_instance* tool)
{
this->tool = tool;
}
@ -202,7 +201,7 @@ void control_system::set_viewport(const float4& viewport)
this->viewport = viewport;
}
void control_system::set_underworld_camera(::camera* camera)
void control_system::set_underworld_camera(scene::camera* camera)
{
this->underworld_camera = camera;
}

+ 5
- 5
src/game/systems/control-system.hpp View File

@ -28,9 +28,9 @@
#include "input/control-set.hpp"
#include "scene/model-instance.hpp"
#include "utility/fundamental-types.hpp"
#include "scene/camera.hpp"
class nest;
class camera;
class camera_system;
class control_system:
@ -48,12 +48,12 @@ public:
void set_camera_system(camera_system* camera_system);
void set_nest(::nest* nest);
void set_tool(model_instance* tool);
void set_tool(scene::model_instance* tool);
void set_flashlight(entt::entity eid);
void set_camera_subject(entt::entity eid);
void set_viewport(const float4& viewport);
void set_underworld_camera(::camera* camera);
void set_underworld_camera(scene::camera* camera);
control_set* get_control_set();
control* get_move_forward_control();
@ -133,13 +133,13 @@ private:
float zoom;
camera_system* camera_system;
::nest* nest;
model_instance* tool;
scene::model_instance* tool;
float2 mouse_position;
float4 viewport;
entt::entity flashlight_eid;
entt::entity camera_subject_eid;
camera* underworld_camera;
scene::camera* underworld_camera;
float mouse_angle;
float old_mouse_angle;

+ 5
- 7
src/game/systems/painting-system.cpp View File

@ -23,8 +23,6 @@
#include "game/components/tool-component.hpp"
#include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp"
#include "scene/scene.hpp"
#include "scene/model-instance.hpp"
#include "math/math.hpp"
#include "renderer/material.hpp"
#include "renderer/model.hpp"
@ -44,7 +42,7 @@ painting_system::painting_system(entt::registry& registry, ::event_dispatcher* e
entity_system(registry),
event_dispatcher(event_dispatcher),
resource_manager(resource_manager),
scene(nullptr),
scene_collection(nullptr),
painting(false)
{
event_dispatcher->subscribe<tool_pressed_event>(this);
@ -75,7 +73,7 @@ painting_system::painting_system(entt::registry& registry, ::event_dispatcher* e
stroke_model->get_vertex_array()->bind_attribute(VERTEX_TANGENT_LOCATION, *stroke_vbo, 4, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * 9);
// Create stroke model instance
stroke_model_instance = new model_instance();
stroke_model_instance = new scene::model_instance();
stroke_model_instance->set_model(stroke_model);
stroke_model_instance->update_tweens();
@ -267,10 +265,10 @@ void painting_system::update(double t, double dt)
}
}
void painting_system::set_scene(::scene* scene)
void painting_system::set_scene(scene::collection* collection)
{
this->scene = scene;
scene->add_object(stroke_model_instance);
this->scene_collection = collection;
scene_collection->add_object(stroke_model_instance);
}
void painting_system::handle_event(const tool_pressed_event& event)

+ 5
- 5
src/game/systems/painting-system.hpp View File

@ -24,15 +24,15 @@
#include "event/event-handler.hpp"
#include "game/events/tool-events.hpp"
#include "utility/fundamental-types.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include <vector>
#include <optional>
class material;
class event_dispatcher;
class resource_manager;
class scene;
class model;
class model_instance;
class model_group;
class vertex_buffer;
@ -45,7 +45,7 @@ public:
virtual ~painting_system();
virtual void update(double t, double dt);
void set_scene(scene* scene);
void set_scene(scene::collection* collection);
private:
virtual void handle_event(const tool_pressed_event& event);
@ -55,7 +55,7 @@ private:
event_dispatcher* event_dispatcher;
resource_manager* resource_manager;
scene* scene;
scene::collection* scene_collection;
bool painting;
entt::entity brush_entity;
@ -83,7 +83,7 @@ private:
vertex_buffer* stroke_vbo;
bool midstroke;
model_instance* stroke_model_instance;
scene::model_instance* stroke_model_instance;
};
#endif // ANTKEEPER_PAINTING_SYSTEM_HPP

+ 6
- 6
src/game/systems/render-system.cpp View File

@ -38,7 +38,7 @@ void render_system::update(double t, double dt)
(
[this](auto entity, auto& transform, auto& model)
{
model_instance* instance = model_instances[entity];
scene::model_instance* instance = model_instances[entity];
instance->set_transform(transform.world);
@ -56,14 +56,14 @@ void render_system::render(double alpha)
{
if (renderer)
{
for (const scene* scene: layers)
for (const scene::collection* collection: layers)
{
renderer->render(alpha, *scene);
renderer->render(alpha, *collection);
}
}
}
void render_system::add_layer(::scene* layer)
void render_system::add_layer(scene::collection* layer)
{
layers.push_back(layer);
}
@ -78,7 +78,7 @@ void render_system::set_renderer(::renderer* renderer)
this->renderer = renderer;
}
model_instance* render_system::get_model_instance(entt::entity entity)
scene::model_instance* render_system::get_model_instance(entt::entity entity)
{
if (auto it = model_instances.find(entity); it != model_instances.end())
return it->second;
@ -112,7 +112,7 @@ void render_system::update_model_and_materials(entt::entity entity, model_compon
void render_system::on_model_construct(entt::registry& registry, entt::entity entity, model_component& model)
{
::model_instance* model_instance = new ::model_instance();
scene::model_instance* model_instance = new scene::model_instance();
model_instances[entity] = model_instance;
update_model_and_materials(entity, model);
}

+ 5
- 5
src/game/systems/render-system.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_RENDER_SYSTEM_HPP
#include "entity-system.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "game/components/model-component.hpp"
#include "game/components/render-component.hpp"
@ -39,12 +39,12 @@ public:
void render(double alpha);
void add_layer(::scene* layer);
void add_layer(scene::collection* layer);
void remove_layers();
void set_renderer(::renderer* renderer);
model_instance* get_model_instance(entt::entity entity);
scene::model_instance* get_model_instance(entt::entity entity);
private:
void update_model_and_materials(entt::entity entity, ecs::model_component& model);
@ -58,8 +58,8 @@ private:
void on_component_destroy(entt::registry& registry, entt::entity entity);
renderer* renderer;
std::vector<scene*> layers;
std::unordered_map<entt::entity, model_instance*> model_instances;
std::vector<scene::collection*> layers;
std::unordered_map<entt::entity, scene::model_instance*> model_instances;
};
#endif // ANTKEEPER_RENDER_SYSTEM_HPP

+ 4
- 6
src/game/systems/subterrain-system.cpp View File

@ -30,8 +30,6 @@
#include "resources/resource-manager.hpp"
#include "geometry/marching-cubes.hpp"
#include "geometry/intersection.hpp"
#include "scene/scene.hpp"
#include "scene/model-instance.hpp"
#include "utility/fundamental-types.hpp"
#include <array>
#include <limits>
@ -267,8 +265,8 @@ void subterrain_system::update(double t, double dt)
//auto subterrain_entity = registry.create();
//registry.assign<model_component>(subterrain_entity, subterrain_model);
subterrain_model_instance = new model_instance(subterrain_model);
scene->add_object(subterrain_model_instance);
subterrain_model_instance = new scene::model_instance(subterrain_model);
collection->add_object(subterrain_model_instance);
}
bool digging = false;
@ -295,9 +293,9 @@ void subterrain_system::update(double t, double dt)
}
}
void subterrain_system::set_scene(::scene* scene)
void subterrain_system::set_scene(scene::collection* collection)
{
this->scene = scene;
this->collection = collection;
}
void subterrain_system::regenerate_subterrain_mesh()

+ 5
- 5
src/game/systems/subterrain-system.hpp View File

@ -23,6 +23,8 @@
#include "entity-system.hpp"
#include "geometry/mesh.hpp"
#include "geometry/aabb.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "utility/fundamental-types.hpp"
#include <unordered_map>
@ -31,8 +33,6 @@ class model;
class model_group;
class material;
struct cube_tree;
class scene;
class model_instance;
template <std::int64_t Mantissa, std::int64_t Exponent>
struct epsilon
@ -89,7 +89,7 @@ public:
~subterrain_system();
virtual void update(double t, double dt);
void set_scene(::scene* scene);
void set_scene(scene::collection* collection);
private:
void regenerate_subterrain_mesh();
@ -121,8 +121,8 @@ private:
vector_hasher<epsilon_1en5, float, 3>,
vector_equals<epsilon_1en5, float, 3>> subterrain_vertex_map;
::scene* scene;
model_instance* subterrain_model_instance;
scene::collection* collection;
scene::model_instance* subterrain_model_instance;
};
#endif // ANTKEEPER_SUBTERRAIN_SYSTEM_HPP

+ 1
- 2
src/game/systems/tool-system.cpp View File

@ -23,7 +23,6 @@
#include "game/components/transform-component.hpp"
#include "event/event-dispatcher.hpp"
#include "game/events/tool-events.hpp"
#include "scene/camera.hpp"
#include "animation/orbit-cam.hpp"
#include "animation/ease.hpp"
#include "geometry/mesh.hpp"
@ -223,7 +222,7 @@ void tool_system::update(double t, double dt)
was_pick_enabled = pick_enabled;
}
void tool_system::set_camera(const ::camera* camera)
void tool_system::set_camera(const scene::camera* camera)
{
this->camera = camera;
}

+ 3
- 3
src/game/systems/tool-system.hpp View File

@ -27,8 +27,8 @@
#include "utility/fundamental-types.hpp"
#include "animation/spring.hpp"
#include "animation/animation.hpp"
#include "scene/camera.hpp"
class camera;
class orbit_cam;
class event_dispatcher;
@ -42,7 +42,7 @@ public:
virtual ~tool_system();
virtual void update(double t, double dt);
void set_camera(const camera* camera);
void set_camera(const scene::camera* camera);
void set_orbit_cam(const orbit_cam* camera);
void set_viewport(const float4& viewport);
void set_pick(bool enabled);
@ -59,7 +59,7 @@ private:
virtual void handle_event(const window_resized_event& event);
event_dispatcher* event_dispatcher;
const camera* camera;
const scene::camera* camera;
const orbit_cam* orbit_cam;
float4 viewport;
float2 mouse_position;

+ 6
- 6
src/game/systems/tracking-system.cpp View File

@ -22,7 +22,7 @@
#include "game/components/marker-component.hpp"
#include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "math/math.hpp"
#include "renderer/material.hpp"
@ -36,7 +36,7 @@ tracking_system::tracking_system(entt::registry& registry, ::event_dispatcher* e
entity_system(registry),
event_dispatcher(event_dispatcher),
resource_manager(resource_manager),
scene(nullptr)
scene_collection(nullptr)
{
registry.on_construct<trackable_component>().connect<&tracking_system::on_component_construct>(this);
registry.on_destroy<trackable_component>().connect<&tracking_system::on_component_destroy>(this);
@ -92,9 +92,9 @@ void tracking_system::update(double t, double dt)
}
}
void tracking_system::set_scene(::scene* scene)
void tracking_system::set_scene(scene::collection* collection)
{
this->scene = scene;
this->scene_collection = collection;
}
void tracking_system::on_component_construct(entt::registry& registry, entt::entity entity, trackable_component& component)
@ -132,7 +132,7 @@ void tracking_system::handle_event(const tool_pressed_event& event)
const float tracker_scale = 1.0f;
// Create tracker model instance
model_instance* instance = new model_instance();
scene::model_instance* instance = new scene::model_instance();
instance->set_model(tracker_model);
instance->set_translation(transform.translation);
instance->set_scale(float3{tracker_scale, tracker_scale, tracker_scale});
@ -146,7 +146,7 @@ void tracking_system::handle_event(const tool_pressed_event& event)
instance->update_tweens();
scene->add_object(instance);
scene_collection->add_object(instance);
}
}
}

+ 9
- 5
src/game/systems/tracking-system.hpp View File

@ -29,9 +29,13 @@
class material;
class event_dispatcher;
class resource_manager;
class scene;
class model;
class model_instance;
namespace scene
{
class collection;
class model_instance;
}
class tracking_system: public entity_system,
public event_handler<tool_pressed_event>,
@ -42,7 +46,7 @@ public:
virtual ~tracking_system();
virtual void update(double t, double dt);
void set_scene(scene* scene);
void set_scene(scene::collection* collection);
void set_viewport(const float4& viewport);
private:
@ -53,11 +57,11 @@ private:
event_dispatcher* event_dispatcher;
resource_manager* resource_manager;
scene* scene;
scene::collection* scene_collection;
model* tracker_model;
model* paint_ball_model;
material** paint_ball_materials;
std::unordered_map<entt::entity, model_instance*> trackers;
std::unordered_map<entt::entity, scene::model_instance*> trackers;
};
#endif // ANTKEEPER_TRACKING_SYSTEM_HPP

+ 10
- 10
src/game/systems/ui-system.cpp View File

@ -25,7 +25,7 @@ ui_system::ui_system(::resource_manager* resource_manager):
resource_manager(resource_manager),
tool_menu_control(nullptr),
camera(nullptr),
scene(nullptr)
scene_collection(nullptr)
{
// Setup lighting
indirect_light.set_intensity(0.25f);
@ -90,7 +90,7 @@ void ui_system::set_tool_menu_control(control* control)
tool_menu_control->set_deactivated_callback(std::bind(&ui_system::close_tool_menu, this));
}
void ui_system::set_camera(::camera* camera)
void ui_system::set_camera(scene::camera* camera)
{
this->camera = camera;
@ -101,9 +101,9 @@ void ui_system::set_camera(::camera* camera)
}
}
void ui_system::set_scene(::scene* scene)
void ui_system::set_scene(scene::collection* collection)
{
this->scene = scene;
this->scene_collection = collection;
}
void ui_system::handle_event(const mouse_moved_event& event)
@ -167,20 +167,20 @@ void ui_system::update_projection()
void ui_system::open_tool_menu()
{
if (scene)
if (scene_collection)
{
scene->add_object(&modal_bg);
scene->add_object(&tool_selector_bg);
scene_collection->add_object(&modal_bg);
scene_collection->add_object(&tool_selector_bg);
}
tool_selection_vector = {0, 0};
}
void ui_system::close_tool_menu()
{
if (scene)
if (scene_collection)
{
scene->remove_object(&modal_bg);
scene->remove_object(&tool_selector_bg);
scene_collection->remove_object(&modal_bg);
scene_collection->remove_object(&tool_selector_bg);
}
}

+ 11
- 12
src/game/systems/ui-system.hpp View File

@ -23,7 +23,7 @@
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "event/window-events.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/camera.hpp"
#include "scene/directional-light.hpp"
#include "scene/ambient-light.hpp"
@ -33,7 +33,6 @@
#include "math/math.hpp"
class control;
class scene;
class resource_manager;
class ui_system:
@ -48,8 +47,8 @@ public:
void set_viewport(const float4& viewport);
void set_tool_menu_control(control* control);
void set_camera(::camera* camera);
void set_scene(::scene* scene);
void set_camera(scene::camera* camera);
void set_scene(scene::collection* collection);
private:
virtual void handle_event(const mouse_moved_event& event);
@ -64,17 +63,17 @@ private:
void close_elevator_menu();
resource_manager* resource_manager;
scene* scene;
camera* camera;
ambient_light indirect_light;
directional_light direct_light;
billboard tool_selector_bg;
scene::collection* scene_collection;
scene::camera* camera;
scene::ambient_light indirect_light;
scene::directional_light direct_light;
scene::billboard tool_selector_bg;
material modal_bg_material;
billboard modal_bg;
scene::billboard modal_bg;
billboard underground_bg;
scene::billboard underground_bg;
model_instance energy_symbol;
scene::model_instance energy_symbol;
float2 mouse_position;
float4 viewport;

+ 8
- 8
src/game/systems/vegetation-system.cpp View File

@ -22,7 +22,7 @@
#include "game/components/transform-component.hpp"
#include "scene/model-instance.hpp"
#include "scene/lod-group.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "renderer/material.hpp"
#include "geometry/aabb.hpp"
#include "utility/fundamental-types.hpp"
@ -73,9 +73,9 @@ void vegetation_system::set_vegetation_model(::model* model)
vegetation_model = model;
}
void vegetation_system::set_scene(::scene* scene)
void vegetation_system::set_scene(scene::collection* collection)
{
this->scene = scene;
this->scene_collection = collection;
}
void vegetation_system::on_terrain_construct(entt::registry& registry, entt::entity entity, terrain_component& component)
@ -132,7 +132,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
static_cast<material_property<int>*>(lod2_material->get_property("instance_multiplier"))->set_value(4);
// Create LOD 0
model_instance* patch_lod0 = new model_instance();
scene::model_instance* patch_lod0 = new scene::model_instance();
patch_lod0->set_model(vegetation_model);
patch_lod0->set_translation(translation);
patch_lod0->set_instanced(true, instance_count_lod0);
@ -140,7 +140,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
patch_lod0->update_tweens();
// Create LOD 1
model_instance* patch_lod1 = new model_instance();
scene::model_instance* patch_lod1 = new scene::model_instance();
patch_lod1->set_model(vegetation_model);
patch_lod1->set_material(0, lod1_material);
patch_lod1->set_translation(translation);
@ -149,7 +149,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
patch_lod1->update_tweens();
// Create LOD 2
model_instance* patch_lod2 = new model_instance();
scene::model_instance* patch_lod2 = new scene::model_instance();
patch_lod2->set_model(vegetation_model);
patch_lod2->set_material(0, lod2_material);
patch_lod2->set_translation(translation);
@ -158,7 +158,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
patch_lod2->update_tweens();
// Create LOD group
::lod_group* lod_group = new ::lod_group(lod_count);
scene::lod_group* lod_group = new scene::lod_group(lod_count);
lod_group->add_object(0, patch_lod0);
lod_group->add_object(1, patch_lod1);
lod_group->add_object(2, patch_lod2);
@ -166,7 +166,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
lod_group->update_tweens();
// Add LOD group to scene
scene->add_object(lod_group);
scene_collection->add_object(lod_group);
}
}
}

+ 7
- 3
src/game/systems/vegetation-system.hpp View File

@ -24,7 +24,11 @@
#include "game/components/terrain-component.hpp"
class model;
class scene;
namespace scene
{
class collection;
}
/**
* Places vegetation patches on terrain.
@ -54,7 +58,7 @@ public:
void set_vegetation_model(::model* model);
void set_scene(::scene* scene);
void set_scene(scene::collection* collection);
private:
void on_terrain_construct(entt::registry& registry, entt::entity entity, ecs::terrain_component& component);
@ -66,7 +70,7 @@ private:
int vegetation_patch_rows;
float vegetation_density;
model* vegetation_model;
::scene* scene;
scene::collection* scene_collection;
};
#endif // ANTKEEPER_VEGETATION_SYSTEM_HPP

+ 11
- 12
src/renderer/passes/material-pass.cpp View File

@ -38,12 +38,11 @@
#include "renderer/model.hpp"
#include "renderer/render-context.hpp"
#include "scene/camera.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/point-light.hpp"
#include "scene/spotlight.hpp"
#include "scene/scene.hpp"
#include "configuration.hpp"
#include "math/math.hpp"
#include <cmath>
@ -148,18 +147,18 @@ void material_pass::render(render_context* context) const
spotlight_count = 0;
// Collect lights
const std::list<scene_object_base*>* lights = context->scene->get_objects(light::object_type_id);
for (const scene_object_base* object: *lights)
const std::list<scene::object_base*>* lights = context->collection->get_objects(scene::light::object_type_id);
for (const scene::object_base* object: *lights)
{
// Skip inactive lights
if (!object->is_active())
continue;
const ::light* light = static_cast<const ::light*>(object);
const scene::light* light = static_cast<const scene::light*>(object);
switch (light->get_light_type())
{
// Add ambient light
case light_type::ambient:
case scene::light_type::ambient:
{
if (ambient_light_count < max_ambient_light_count)
{
@ -170,7 +169,7 @@ void material_pass::render(render_context* context) const
}
// Add point light
case light_type::point:
case scene::light_type::point:
{
if (point_light_count < max_point_light_count)
{
@ -181,21 +180,21 @@ void material_pass::render(render_context* context) const
float3 view_space_position = math::resize<3>(view * float4{position.x, position.y, position.z, 1.0f});
point_light_positions[point_light_count] = view_space_position;
point_light_attenuations[point_light_count] = static_cast<const point_light*>(light)->get_attenuation_tween().interpolate(context->alpha);
point_light_attenuations[point_light_count] = static_cast<const scene::point_light*>(light)->get_attenuation_tween().interpolate(context->alpha);
++point_light_count;
}
break;
}
// Add directional light
case light_type::directional:
case scene::light_type::directional:
{
if (directional_light_count < max_directional_light_count)
{
directional_light_colors[directional_light_count] = light->get_scaled_color_tween().interpolate(context->alpha);
// Transform direction into view-space
float3 direction = static_cast<const directional_light*>(light)->get_direction_tween().interpolate(context->alpha);
float3 direction = static_cast<const scene::directional_light*>(light)->get_direction_tween().interpolate(context->alpha);
float3 view_space_direction = math::normalize(math::resize<3>(view * math::resize<4>(-direction)));
directional_light_directions[directional_light_count] = view_space_direction;
@ -205,7 +204,7 @@ void material_pass::render(render_context* context) const
}
// Add spotlight
case light_type::spot:
case scene::light_type::spot:
{
if (spotlight_count < max_spotlight_count)
{
@ -216,7 +215,7 @@ void material_pass::render(render_context* context) const
float3 view_space_position = math::resize<3>(view * float4{position.x, position.y, position.z, 1.0f});
spotlight_positions[spotlight_count] = view_space_position;
const ::spotlight* spotlight = static_cast<const ::spotlight*>(light);
const scene::spotlight* spotlight = static_cast<const scene::spotlight*>(light);
// Transform direction into view-space
float3 direction = spotlight->get_direction_tween().interpolate(context->alpha);

+ 2
- 4
src/renderer/passes/shadow-map-pass.cpp View File

@ -28,9 +28,7 @@
#include "renderer/material.hpp"
#include "renderer/material-flags.hpp"
#include "scene/camera.hpp"
#include "scene/scene.hpp"
#include "scene/light.hpp"
#include "scene/directional-light.hpp"
#include "geometry/view-frustum.hpp"
#include "geometry/aabb.hpp"
#include "configuration.hpp"
@ -111,7 +109,7 @@ void shadow_map_pass::render(render_context* context) const
//glDepthRange(-1.0f, 1.0f);
// Get camera
const ::camera& camera = *context->camera;
const scene::camera& camera = *context->camera;
// Calculate distances to the depth clipping planes of each frustum split
float clip_near = camera.get_clip_near_tween().interpolate(context->alpha);
@ -256,7 +254,7 @@ void shadow_map_pass::set_split_scheme_weight(float weight)
split_scheme_weight = weight;
}
void shadow_map_pass::set_light(const directional_light* light)
void shadow_map_pass::set_light(const scene::directional_light* light)
{
this->light = light;
}

+ 3
- 4
src/renderer/passes/shadow-map-pass.hpp View File

@ -22,12 +22,11 @@
#include "renderer/render-pass.hpp"
#include "utility/fundamental-types.hpp"
#include "scene/directional-light.hpp"
class shader_program;
class shader_input;
class camera;
class resource_manager;
class directional_light;
/**
*
@ -46,7 +45,7 @@ public:
*/
void set_split_scheme_weight(float weight);
void set_light(const directional_light* light);
void set_light(const scene::directional_light* light);
const float4x4* get_shadow_matrices() const;
const float* get_split_distances() const;
@ -73,7 +72,7 @@ private:
mutable float4x4 shadow_matrices[4];
float4x4 bias_tile_matrices[4];
float split_scheme_weight;
const directional_light* light;
const scene::directional_light* light;
};
inline const float4x4* shadow_map_pass::get_shadow_matrices() const

+ 1
- 3
src/renderer/passes/sky-pass.cpp View File

@ -35,8 +35,6 @@
#include "renderer/model.hpp"
#include "renderer/material.hpp"
#include "scene/camera.hpp"
#include "scene/scene.hpp"
#include "scene/scene.hpp"
#include "utility/fundamental-types.hpp"
#include <cmath>
#include <glad/glad.h>
@ -76,7 +74,7 @@ void sky_pass::render(render_context* context) const
float time = (time_tween) ? time_tween->interpolate(context->alpha) : 0.0f;
float2 resolution = {static_cast<float>(std::get<0>(viewport)), static_cast<float>(std::get<1>(viewport))};
const ::camera& camera = *context->camera;
const scene::camera& camera = *context->camera;
float clip_near = camera.get_clip_near_tween().interpolate(context->alpha);
float clip_far = camera.get_clip_far_tween().interpolate(context->alpha);
float3 model_scale = float3{1.0f, 1.0f, 1.0f} * (clip_near + clip_far) * 0.5f;

+ 2
- 3
src/renderer/passes/ui-pass.cpp View File