From 978ad7add605c07104926c0d4a853b7a5bd7fbfa Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Mon, 11 Jan 2021 22:31:58 +0800 Subject: [PATCH] Rename scene class to collection and move all scene-related classes into the scene namespace --- CMakeLists.txt | 1 + src/animation/camera-rig.cpp | 3 +- src/animation/camera-rig.hpp | 10 +-- src/animation/screen-transition.cpp | 4 +- src/animation/screen-transition.hpp | 6 +- src/game/bootloader.cpp | 39 +++++----- src/game/game-context.hpp | 40 +++++------ src/game/states/map-state.cpp | 1 - src/game/states/play-state.cpp | 4 +- src/game/states/splash-state.cpp | 2 +- src/game/systems/camera-system.cpp | 4 +- src/game/systems/camera-system.hpp | 6 +- src/game/systems/control-system.cpp | 5 +- src/game/systems/control-system.hpp | 10 +-- src/game/systems/painting-system.cpp | 12 ++-- src/game/systems/painting-system.hpp | 10 +-- src/game/systems/render-system.cpp | 12 ++-- src/game/systems/render-system.hpp | 10 +-- src/game/systems/subterrain-system.cpp | 10 ++- src/game/systems/subterrain-system.hpp | 10 +-- src/game/systems/tool-system.cpp | 3 +- src/game/systems/tool-system.hpp | 6 +- src/game/systems/tracking-system.cpp | 12 ++-- src/game/systems/tracking-system.hpp | 14 ++-- src/game/systems/ui-system.cpp | 20 +++--- src/game/systems/ui-system.hpp | 23 +++--- src/game/systems/vegetation-system.cpp | 16 ++--- src/game/systems/vegetation-system.hpp | 10 ++- src/renderer/passes/material-pass.cpp | 23 +++--- src/renderer/passes/shadow-map-pass.cpp | 6 +- src/renderer/passes/shadow-map-pass.hpp | 7 +- src/renderer/passes/sky-pass.cpp | 4 +- src/renderer/passes/ui-pass.cpp | 5 +- src/renderer/render-context.hpp | 9 ++- src/renderer/renderer.cpp | 52 +++++++------- src/renderer/renderer.hpp | 28 ++++---- src/scene/ambient-light.hpp | 10 ++- src/scene/billboard.cpp | 6 +- src/scene/billboard.hpp | 14 ++-- src/scene/camera.cpp | 5 +- src/scene/camera.hpp | 16 +++-- src/scene/{scene.cpp => collection.cpp} | 21 +++--- src/scene/collection.hpp | 84 ++++++++++++++++++++++ src/scene/directional-light.cpp | 3 + src/scene/directional-light.hpp | 12 ++-- src/scene/light.cpp | 6 +- src/scene/light.hpp | 16 +++-- src/scene/lod-group.cpp | 10 ++- src/scene/lod-group.hpp | 26 ++++--- src/scene/model-instance.cpp | 6 +- src/scene/model-instance.hpp | 14 ++-- src/scene/{scene-object.cpp => object.cpp} | 20 +++--- src/scene/{scene-object.hpp => object.hpp} | 42 ++++++----- src/scene/point-light.cpp | 4 ++ src/scene/point-light.hpp | 12 ++-- src/scene/scene.hpp | 70 ++++-------------- src/scene/spotlight.cpp | 3 + src/scene/spotlight.hpp | 12 ++-- 58 files changed, 474 insertions(+), 375 deletions(-) rename src/scene/{scene.cpp => collection.cpp} (74%) create mode 100644 src/scene/collection.hpp rename src/scene/{scene-object.cpp => object.cpp} (71%) rename src/scene/{scene-object.hpp => object.hpp} (76%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4aa351..bc40e61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/animation/camera-rig.cpp b/src/animation/camera-rig.cpp index 3c8f86a..dc05789 100644 --- a/src/animation/camera-rig.cpp +++ b/src/animation/camera-rig.cpp @@ -18,7 +18,6 @@ */ #include "animation/camera-rig.hpp" -#include "scene/camera.hpp" #include "math/constants.hpp" #include "configuration.hpp" #include @@ -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) diff --git a/src/animation/camera-rig.hpp b/src/animation/camera-rig.hpp index 8836a6a..09b248e 100644 --- a/src/animation/camera-rig.hpp +++ b/src/animation/camera-rig.hpp @@ -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; } diff --git a/src/animation/screen-transition.cpp b/src/animation/screen-transition.cpp index 6d0c774..fd2ed7c 100644 --- a/src/animation/screen-transition.cpp +++ b/src/animation/screen-transition.cpp @@ -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 diff --git a/src/animation/screen-transition.hpp b/src/animation/screen-transition.hpp index f9b2d4b..75b150a 100644 --- a/src/animation/screen-transition.hpp +++ b/src/animation/screen-transition.hpp @@ -35,19 +35,19 @@ public: void transition(float duration, bool reverse, animation::interpolator_type interpolator); - ::billboard* get_billboard(); + scene::billboard* get_billboard(); ::material* get_material(); ::animation* get_animation(); private: - ::billboard billboard; + scene::billboard billboard; ::material material; material_property* progress; ::animation animation; ::animation::channel* channel; }; -inline billboard* screen_transition::get_billboard() +inline scene::billboard* screen_transition::get_billboard() { return &billboard; } diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 715481d..07bf5e8 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -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(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(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("background")->set_value(splash_texture); ctx->splash_billboard_material->add_property("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("larva.mdl")); + //model_instance* larva = new scene::model_instance(ctx->resource_manager->load("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); diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index ac88f55..51a6977 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -29,13 +29,10 @@ #include // 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 no_cull; - spotlight* lens_spotlight; - spotlight* flashlight_spotlight; // Animation timeline* timeline; diff --git a/src/game/states/map-state.cpp b/src/game/states/map-state.cpp index c3e690d..71726ed 100644 --- a/src/game/states/map-state.cpp +++ b/src/game/states/map-state.cpp @@ -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 void map_state_enter(game_context* ctx) diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index 457692e..287d754 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -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); diff --git a/src/game/states/splash-state.cpp b/src/game/states/splash-state.cpp index 80410a3..45e790b 100644 --- a/src/game/states/splash-state.cpp +++ b/src/game/states/splash-state.cpp @@ -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 void splash_state_enter(game_context* ctx) diff --git a/src/game/systems/camera-system.cpp b/src/game/systems/camera-system.cpp index 93ba2f7..2081c77 100644 --- a/src/game/systems/camera-system.cpp +++ b/src/game/systems/camera-system.cpp @@ -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 #include -#include 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) diff --git a/src/game/systems/camera-system.hpp b/src/game/systems/camera-system.hpp index e0a1374..6d46395 100644 --- a/src/game/systems/camera-system.hpp +++ b/src/game/systems/camera-system.hpp @@ -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; diff --git a/src/game/systems/control-system.cpp b/src/game/systems/control-system.cpp index 7f23f1e..6b98fba 100644 --- a/src/game/systems/control-system.cpp +++ b/src/game/systems/control-system.cpp @@ -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; } diff --git a/src/game/systems/control-system.hpp b/src/game/systems/control-system.hpp index 2208423..ae0993f 100644 --- a/src/game/systems/control-system.hpp +++ b/src/game/systems/control-system.hpp @@ -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; diff --git a/src/game/systems/painting-system.cpp b/src/game/systems/painting-system.cpp index f4e3d5b..f6c0951 100644 --- a/src/game/systems/painting-system.cpp +++ b/src/game/systems/painting-system.cpp @@ -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(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) diff --git a/src/game/systems/painting-system.hpp b/src/game/systems/painting-system.hpp index 00feeee..e4e2aba 100644 --- a/src/game/systems/painting-system.hpp +++ b/src/game/systems/painting-system.hpp @@ -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 #include 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 diff --git a/src/game/systems/render-system.cpp b/src/game/systems/render-system.cpp index 8d73264..81ee074 100644 --- a/src/game/systems/render-system.cpp +++ b/src/game/systems/render-system.cpp @@ -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); } diff --git a/src/game/systems/render-system.hpp b/src/game/systems/render-system.hpp index 5c39d07..5f5851a 100644 --- a/src/game/systems/render-system.hpp +++ b/src/game/systems/render-system.hpp @@ -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 layers; - std::unordered_map model_instances; + std::vector layers; + std::unordered_map model_instances; }; #endif // ANTKEEPER_RENDER_SYSTEM_HPP diff --git a/src/game/systems/subterrain-system.cpp b/src/game/systems/subterrain-system.cpp index b8e1384..341349e 100644 --- a/src/game/systems/subterrain-system.cpp +++ b/src/game/systems/subterrain-system.cpp @@ -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 #include @@ -267,8 +265,8 @@ void subterrain_system::update(double t, double dt) //auto subterrain_entity = registry.create(); //registry.assign(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() diff --git a/src/game/systems/subterrain-system.hpp b/src/game/systems/subterrain-system.hpp index 3a8b16c..a925606 100644 --- a/src/game/systems/subterrain-system.hpp +++ b/src/game/systems/subterrain-system.hpp @@ -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 @@ -31,8 +33,6 @@ class model; class model_group; class material; struct cube_tree; -class scene; -class model_instance; template 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, vector_equals> subterrain_vertex_map; - ::scene* scene; - model_instance* subterrain_model_instance; + scene::collection* collection; + scene::model_instance* subterrain_model_instance; }; #endif // ANTKEEPER_SUBTERRAIN_SYSTEM_HPP diff --git a/src/game/systems/tool-system.cpp b/src/game/systems/tool-system.cpp index 3ca93f3..e37164d 100644 --- a/src/game/systems/tool-system.cpp +++ b/src/game/systems/tool-system.cpp @@ -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; } diff --git a/src/game/systems/tool-system.hpp b/src/game/systems/tool-system.hpp index 974b78f..fdca6a6 100644 --- a/src/game/systems/tool-system.hpp +++ b/src/game/systems/tool-system.hpp @@ -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; diff --git a/src/game/systems/tracking-system.cpp b/src/game/systems/tracking-system.cpp index 9d68561..0cb8918 100644 --- a/src/game/systems/tracking-system.cpp +++ b/src/game/systems/tracking-system.cpp @@ -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().connect<&tracking_system::on_component_construct>(this); registry.on_destroy().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); } } } diff --git a/src/game/systems/tracking-system.hpp b/src/game/systems/tracking-system.hpp index e1edfc3..caefacf 100644 --- a/src/game/systems/tracking-system.hpp +++ b/src/game/systems/tracking-system.hpp @@ -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, @@ -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 trackers; + std::unordered_map trackers; }; #endif // ANTKEEPER_TRACKING_SYSTEM_HPP diff --git a/src/game/systems/ui-system.cpp b/src/game/systems/ui-system.cpp index 10a7721..6001f8a 100644 --- a/src/game/systems/ui-system.cpp +++ b/src/game/systems/ui-system.cpp @@ -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); } } diff --git a/src/game/systems/ui-system.hpp b/src/game/systems/ui-system.hpp index df57177..63e1544 100644 --- a/src/game/systems/ui-system.hpp +++ b/src/game/systems/ui-system.hpp @@ -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; diff --git a/src/game/systems/vegetation-system.cpp b/src/game/systems/vegetation-system.cpp index 1449aac..b639b96 100644 --- a/src/game/systems/vegetation-system.cpp +++ b/src/game/systems/vegetation-system.cpp @@ -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*>(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); } } } diff --git a/src/game/systems/vegetation-system.hpp b/src/game/systems/vegetation-system.hpp index 107e294..86ab979 100644 --- a/src/game/systems/vegetation-system.hpp +++ b/src/game/systems/vegetation-system.hpp @@ -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 diff --git a/src/renderer/passes/material-pass.cpp b/src/renderer/passes/material-pass.cpp index 4643511..42b651f 100644 --- a/src/renderer/passes/material-pass.cpp +++ b/src/renderer/passes/material-pass.cpp @@ -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 @@ -148,18 +147,18 @@ void material_pass::render(render_context* context) const spotlight_count = 0; // Collect lights - const std::list* lights = context->scene->get_objects(light::object_type_id); - for (const scene_object_base* object: *lights) + const std::list* 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(object); + const scene::light* light = static_cast(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(light)->get_attenuation_tween().interpolate(context->alpha); + point_light_attenuations[point_light_count] = static_cast(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(light)->get_direction_tween().interpolate(context->alpha); + float3 direction = static_cast(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(light); + const scene::spotlight* spotlight = static_cast(light); // Transform direction into view-space float3 direction = spotlight->get_direction_tween().interpolate(context->alpha); diff --git a/src/renderer/passes/shadow-map-pass.cpp b/src/renderer/passes/shadow-map-pass.cpp index d87a331..3050d7a 100644 --- a/src/renderer/passes/shadow-map-pass.cpp +++ b/src/renderer/passes/shadow-map-pass.cpp @@ -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; } diff --git a/src/renderer/passes/shadow-map-pass.hpp b/src/renderer/passes/shadow-map-pass.hpp index 1547f28..0f908ca 100644 --- a/src/renderer/passes/shadow-map-pass.hpp +++ b/src/renderer/passes/shadow-map-pass.hpp @@ -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 diff --git a/src/renderer/passes/sky-pass.cpp b/src/renderer/passes/sky-pass.cpp index 6df8357..67322fe 100644 --- a/src/renderer/passes/sky-pass.cpp +++ b/src/renderer/passes/sky-pass.cpp @@ -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 #include @@ -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(std::get<0>(viewport)), static_cast(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; diff --git a/src/renderer/passes/ui-pass.cpp b/src/renderer/passes/ui-pass.cpp index 8048aa8..19db104 100644 --- a/src/renderer/passes/ui-pass.cpp +++ b/src/renderer/passes/ui-pass.cpp @@ -36,10 +36,9 @@ #include "renderer/material-flags.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/scene.hpp" #include "scene/billboard.hpp" #include "math/math.hpp" #include @@ -69,7 +68,7 @@ void ui_pass::render(render_context* context) const float4x4 model_view_projection; // Collect billboards - std::list billboards = *context->scene->get_objects(billboard::object_type_id); + std::list billboards = *context->collection->get_objects(scene::billboard::object_type_id); // Sort billboards diff --git a/src/renderer/render-context.hpp b/src/renderer/render-context.hpp index 2e21b1f..bdc4f68 100644 --- a/src/renderer/render-context.hpp +++ b/src/renderer/render-context.hpp @@ -24,21 +24,20 @@ #include "geometry/plane.hpp" #include "geometry/bounding-volume.hpp" #include "utility/fundamental-types.hpp" +#include "scene/camera.hpp" +#include "scene/collection.hpp" #include -class camera; -class scene; - struct render_context { - const camera* camera; + const scene::camera* camera; math::transform camera_transform; float3 camera_forward; float3 camera_up; const bounding_volume* camera_culling_volume; plane clip_near; - const scene* scene; + const scene::collection* collection; std::list operations; float alpha; }; diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index 66d55d7..1d76108 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -20,7 +20,7 @@ #include "renderer/renderer.hpp" #include "renderer/render-context.hpp" #include "renderer/compositor.hpp" -#include "scene/scene.hpp" +#include "scene/collection.hpp" #include "scene/camera.hpp" #include "scene/model-instance.hpp" #include "scene/billboard.hpp" @@ -44,30 +44,30 @@ renderer::renderer() billboard_op.instance_count = 0; } -void renderer::render(float alpha, const scene& scene) const +void renderer::render(float alpha, const scene::collection& collection) const { - // Get list of all objects in the scene - const std::list* objects = scene.get_objects(); + // Get list of all objects in the collection + const std::list* objects = collection.get_objects(); // Build list of cameras to be sorted - const std::list* cameras = scene.get_objects(camera::object_type_id); - std::list sorted_cameras; - for (scene_object_base* object: *cameras) + const std::list* cameras = collection.get_objects(scene::camera::object_type_id); + std::list sorted_cameras; + for (scene::object_base* object: *cameras) { - sorted_cameras.push_back(static_cast(object)); + sorted_cameras.push_back(static_cast(object)); } // Sort cameras according to their respective compositing indices sorted_cameras.sort ( - [](const camera* a, const camera* b) -> bool + [](const scene::camera* a, const scene::camera* b) -> bool { return a->get_composite_index() < b->get_composite_index(); } ); // Process cameras in order - for (const camera* camera: sorted_cameras) + for (const scene::camera* camera: sorted_cameras) { // Skip inactive cameras if (!camera->is_active()) @@ -89,7 +89,7 @@ void renderer::render(float alpha, const scene& scene) const context.camera_forward = context.camera_transform.rotation * global_forward; context.camera_up = context.camera_transform.rotation * global_up; context.clip_near = camera->get_view_frustum().get_near(); ///< TODO: tween this - context.scene = &scene; + context.collection = &collection; context.alpha = alpha; // Get camera culling volume @@ -98,7 +98,7 @@ void renderer::render(float alpha, const scene& scene) const context.camera_culling_volume = &camera->get_bounds(); // Generate render operations for each visible scene object - for (const scene_object_base* object: *objects) + for (const scene::object_base* object: *objects) { // Skip inactive objects if (!object->is_active()) @@ -118,19 +118,19 @@ void renderer::set_billboard_vao(vertex_array* vao) billboard_op.vertex_array = vao; } -void renderer::process_object(render_context& context, const scene_object_base* object) const +void renderer::process_object(render_context& context, const scene::object_base* object) const { std::size_t type = object->get_object_type_id(); - if (type == model_instance::object_type_id) - process_model_instance(context, static_cast(object)); - else if (type == billboard::object_type_id) - process_billboard(context, static_cast(object)); - else if (type == lod_group::object_type_id) - process_lod_group(context, static_cast(object)); + if (type == scene::model_instance::object_type_id) + process_model_instance(context, static_cast(object)); + else if (type == scene::billboard::object_type_id) + process_billboard(context, static_cast(object)); + else if (type == scene::lod_group::object_type_id) + process_lod_group(context, static_cast(object)); } -void renderer::process_model_instance(render_context& context, const ::model_instance* model_instance) const +void renderer::process_model_instance(render_context& context, const scene::model_instance* model_instance) const { const model* model = model_instance->get_model(); if (!model) @@ -173,7 +173,7 @@ void renderer::process_model_instance(render_context& context, const ::model_ins } } -void renderer::process_billboard(render_context& context, const ::billboard* billboard) const +void renderer::process_billboard(render_context& context, const scene::billboard* billboard) const { // Get object culling volume const bounding_volume* object_culling_volume = billboard->get_culling_mask(); @@ -189,11 +189,11 @@ void renderer::process_billboard(render_context& context, const ::billboard* bil billboard_op.depth = context.clip_near.signed_distance(math::resize<3>(billboard_transform.translation)); // Align billboard - if (billboard->get_billboard_type() == billboard_type::spherical) + if (billboard->get_billboard_type() == scene::billboard_type::spherical) { billboard_transform.rotation = math::normalize(math::look_rotation(context.camera_forward, context.camera_up) * billboard_transform.rotation); } - else if (billboard->get_billboard_type() == billboard_type::cylindrical) + else if (billboard->get_billboard_type() == scene::billboard_type::cylindrical) { const float3& alignment_axis = billboard->get_alignment_axis(); float3 look = math::normalize(project_on_plane(billboard_transform.translation - context.camera_transform.translation, {0.0f, 0.0f, 0.0f}, alignment_axis)); @@ -208,14 +208,14 @@ void renderer::process_billboard(render_context& context, const ::billboard* bil context.operations.push_back(billboard_op); } -void renderer::process_lod_group(render_context& context, const ::lod_group* lod_group) const +void renderer::process_lod_group(render_context& context, const scene::lod_group* lod_group) const { // Select level of detail std::size_t level = lod_group->select_lod(*context.camera); // Process all objects in the group with the selected level of detail - const std::list& objects = lod_group->get_objects(level); - for (const scene_object_base* object: objects) + const std::list& objects = lod_group->get_objects(level); + for (const scene::object_base* object: objects) { process_object(context, object); } diff --git a/src/renderer/renderer.hpp b/src/renderer/renderer.hpp index f8988ea..4247aeb 100644 --- a/src/renderer/renderer.hpp +++ b/src/renderer/renderer.hpp @@ -23,12 +23,16 @@ #include "render-operation.hpp" struct render_context; -class scene; -class scene_object_base; class vertex_array; -class model_instance; -class billboard; -class lod_group; + +namespace scene +{ + class collection; + class object_base; + class model_instance; + class billboard; + class lod_group; +} /* # Pipeline @@ -50,12 +54,12 @@ public: renderer(); /** - * Renders a scene. + * Renders a collection of scene objects. * * @param alpha Subframe interpolation factor. - * @parma scene Scene to render. + * @parma collection Collection of scene objects to render. */ - void render(float alpha, const scene& scene) const; + void render(float alpha, const scene::collection& collection) const; /** * Sets the VAO to be used when generating render operations for billboards. @@ -63,10 +67,10 @@ public: void set_billboard_vao(vertex_array* vao); private: - void process_object(render_context& context, const scene_object_base* object) const; - void process_model_instance(render_context& context, const ::model_instance* model_instance) const; - void process_billboard(render_context& context, const ::billboard* billboard) const; - void process_lod_group(render_context& context, const ::lod_group* lod_group) const; + void process_object(render_context& context, const scene::object_base* object) const; + void process_model_instance(render_context& context, const scene::model_instance* model_instance) const; + void process_billboard(render_context& context, const scene::billboard* billboard) const; + void process_lod_group(render_context& context, const scene::lod_group* lod_group) const; mutable render_operation billboard_op; }; diff --git a/src/scene/ambient-light.hpp b/src/scene/ambient-light.hpp index 587a910..3f7dc9c 100644 --- a/src/scene/ambient-light.hpp +++ b/src/scene/ambient-light.hpp @@ -17,11 +17,13 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_AMBIENT_LIGHT_HPP -#define ANTKEEPER_AMBIENT_LIGHT_HPP +#ifndef ANTKEEPER_SCENE_AMBIENT_LIGHT_HPP +#define ANTKEEPER_SCENE_AMBIENT_LIGHT_HPP #include "scene/light.hpp" +namespace scene { + class ambient_light: public light { public: @@ -34,5 +36,7 @@ inline light_type ambient_light::get_light_type() const return light_type::ambient; } -#endif // ANTKEEPER_AMBIENT_LIGHT_HPP +} // namespace scene + +#endif // ANTKEEPER_SCENE_AMBIENT_LIGHT_HPP diff --git a/src/scene/billboard.cpp b/src/scene/billboard.cpp index 426e60c..91d7a77 100644 --- a/src/scene/billboard.cpp +++ b/src/scene/billboard.cpp @@ -21,6 +21,8 @@ #include "renderer/material.hpp" #include "configuration.hpp" +namespace scene { + const aabb billboard::untransformed_bounds = {{-1, -1, -1}, {1, 1, 1}}; billboard::billboard(): @@ -66,9 +68,11 @@ void billboard::transformed() void billboard::update_tweens() { - scene_object_base::update_tweens(); + object_base::update_tweens(); if (material) { material->update_tweens(); } } + +} // namespace scene diff --git a/src/scene/billboard.hpp b/src/scene/billboard.hpp index ffd8eaf..d19ca8f 100644 --- a/src/scene/billboard.hpp +++ b/src/scene/billboard.hpp @@ -17,15 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_BILLBOARD_HPP -#define ANTKEEPER_BILLBOARD_HPP +#ifndef ANTKEEPER_SCENE_BILLBOARD_HPP +#define ANTKEEPER_SCENE_BILLBOARD_HPP -#include "scene/scene-object.hpp" +#include "scene/object.hpp" #include "geometry/aabb.hpp" #include "utility/fundamental-types.hpp" class material; +namespace scene { + /// Enumerates billboard types. enum class billboard_type { @@ -42,7 +44,7 @@ enum class billboard_type /** * A 2D unit quad with one material. */ -class billboard: public scene_object +class billboard: public object { public: billboard(); @@ -97,5 +99,7 @@ inline const float3& billboard::get_alignment_axis() const return alignment_axis; } -#endif // ANTKEEPER_BILLBOARD_HPP +} // namespace scene + +#endif // ANTKEEPER_SCENE_BILLBOARD_HPP diff --git a/src/scene/camera.cpp b/src/scene/camera.cpp index cd06eba..afa3dea 100644 --- a/src/scene/camera.cpp +++ b/src/scene/camera.cpp @@ -23,6 +23,8 @@ #include "math/constants.hpp" #include "math/interpolation.hpp" +namespace scene { + static float4x4 interpolate_view(const camera* camera, const float4x4& x, const float4x4& y, float a) { math::transform transform = camera->get_transform_tween().interpolate(a); @@ -153,7 +155,7 @@ void camera::set_composite_index(int index) void camera::update_tweens() { - scene_object_base::update_tweens(); + object_base::update_tweens(); clip_left.update(); clip_right.update(); clip_bottom.update(); @@ -179,3 +181,4 @@ void camera::transformed() view_frustum.set_matrix(view_projection[1]); } +} // namespace scene diff --git a/src/scene/camera.hpp b/src/scene/camera.hpp index cf0051b..abedbca 100644 --- a/src/scene/camera.hpp +++ b/src/scene/camera.hpp @@ -17,19 +17,21 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_CAMERA_HPP -#define ANTKEEPER_CAMERA_HPP +#ifndef ANTKEEPER_SCENE_CAMERA_HPP +#define ANTKEEPER_SCENE_CAMERA_HPP -#include "scene/scene-object.hpp" +#include "scene/object.hpp" #include "geometry/view-frustum.hpp" #include "utility/fundamental-types.hpp" class compositor; +namespace scene { + /** * */ -class camera: public scene_object +class camera: public object { public: camera(); @@ -117,7 +119,7 @@ public: const tween& get_projection_tween() const; const tween& get_view_projection_tween() const; - /// @copydoc scene_object_base::update_tweens(); + /// @copydoc object_base::update_tweens(); virtual void update_tweens(); private: @@ -280,5 +282,7 @@ inline const tween& camera::get_view_projection_tween() const return view_projection; } -#endif // ANTKEEPER_CAMERA_HPP +} // namespace scene + +#endif // ANTKEEPER_SCENE_CAMERA_HPP diff --git a/src/scene/scene.cpp b/src/scene/collection.cpp similarity index 74% rename from src/scene/scene.cpp rename to src/scene/collection.cpp index 6b0586d..69a193b 100644 --- a/src/scene/scene.cpp +++ b/src/scene/collection.cpp @@ -17,34 +17,35 @@ * along with Antkeeper source code. If not, see . */ -#include "scene/scene.hpp" -#include "scene/scene-object.hpp" -#include "scene/light.hpp" -#include "scene/camera.hpp" -#include "scene/model-instance.hpp" +#include "scene/collection.hpp" +#include "scene/object.hpp" -void scene::add_object(scene_object_base* object) +namespace scene { + +void collection::add_object(object_base* object) { objects.push_back(object); object_map[object->get_object_type_id()].push_back(object); } -void scene::remove_object(scene_object_base* object) +void collection::remove_object(object_base* object) { objects.remove(object); object_map[object->get_object_type_id()].remove(object); } -void scene::remove_objects() +void collection::remove_objects() { objects.clear(); object_map.clear(); } -void scene::update_tweens() +void collection::update_tweens() { - for (scene_object_base* object: objects) + for (object_base* object: objects) { object->update_tweens(); } } + +} // namespace scene diff --git a/src/scene/collection.hpp b/src/scene/collection.hpp new file mode 100644 index 0000000..e0fb596 --- /dev/null +++ b/src/scene/collection.hpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_SCENE_COLLECTION_HPP +#define ANTKEEPER_SCENE_COLLECTION_HPP + +#include +#include + +namespace scene { + +class object_base; + +/** + * Collection of scene objects. + */ +class collection +{ +public: + /** + * Adds an object to the collection. + * + * @param object Object to add. + */ + void add_object(object_base* object); + + /** + * Removes an object from the collection. + * + * @param object Object to remove. + */ + void remove_object(object_base* object); + + /// Removes all objects from the collection. + void remove_objects(); + + /// Updates the tweens of all objects in the collection. + void update_tweens(); + + /// Returns a list of all objects in the collection. + const std::list* get_objects() const; + + /** + * Returns a list of all objects in the collection with the specified type ID. + * + * @param type_id Scene object type ID. + * @return List of scene objects with the specified type ID. + */ + const std::list* get_objects(std::size_t type_id) const; + +private: + std::list objects; + mutable std::unordered_map> object_map; +}; + +inline const std::list* collection::get_objects() const +{ + return &objects; +} + +inline const std::list* collection::get_objects(std::size_t type_id) const +{ + return &object_map[type_id]; +} + +} // namespace scene + +#endif // ANTKEEPER_SCENE_COLLECTION_HPP diff --git a/src/scene/directional-light.cpp b/src/scene/directional-light.cpp index f9e84c5..6ff082f 100644 --- a/src/scene/directional-light.cpp +++ b/src/scene/directional-light.cpp @@ -21,6 +21,8 @@ #include "configuration.hpp" #include "math/math.hpp" +namespace scene { + static float3 interpolate_direction(const float3& x, const float3& y, float a) { math::quaternion q0 = math::rotation(global_forward, x); @@ -43,3 +45,4 @@ void directional_light::transformed() direction[1] = math::normalize(get_transform().rotation * global_forward); } +} // namespace scene diff --git a/src/scene/directional-light.hpp b/src/scene/directional-light.hpp index 8440802..4d22243 100644 --- a/src/scene/directional-light.hpp +++ b/src/scene/directional-light.hpp @@ -17,12 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_DIRECTIONAL_LIGHT_HPP -#define ANTKEEPER_DIRECTIONAL_LIGHT_HPP +#ifndef ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP +#define ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP #include "scene/light.hpp" #include "utility/fundamental-types.hpp" +namespace scene { + class directional_light: public light { public: @@ -35,7 +37,7 @@ public: const tween& get_direction_tween() const; - /// @copydoc scene_object_base::update_tweens(); + /// @copydoc object_base::update_tweens(); virtual void update_tweens(); private: @@ -59,5 +61,7 @@ inline const tween& directional_light::get_direction_tween() const return direction; } -#endif // ANTKEEPER_DIRECTIONAL_LIGHT_HPP +} // namespace scene + +#endif // ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP diff --git a/src/scene/light.cpp b/src/scene/light.cpp index 3d2f757..248ff3b 100644 --- a/src/scene/light.cpp +++ b/src/scene/light.cpp @@ -21,6 +21,8 @@ #include "animation/ease.hpp" #include "math/interpolation.hpp" +namespace scene { + light::light(): bounds(get_translation(), 0.0f), color(float3{1.0f, 1.0f, 1.0f}, math::lerp), @@ -42,7 +44,7 @@ void light::set_intensity(float intensity) void light::update_tweens() { - scene_object_base::update_tweens(); + object_base::update_tweens(); color.update(); intensity.update(); scaled_color.update(); @@ -52,3 +54,5 @@ void light::transformed() { bounds = sphere(get_translation(), 0.0f); } + +} // namespace scene diff --git a/src/scene/light.hpp b/src/scene/light.hpp index 7771c54..c860fc4 100644 --- a/src/scene/light.hpp +++ b/src/scene/light.hpp @@ -17,13 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_LIGHT_HPP -#define ANTKEEPER_LIGHT_HPP +#ifndef ANTKEEPER_SCENE_LIGHT_HPP +#define ANTKEEPER_SCENE_LIGHT_HPP -#include "scene/scene-object.hpp" +#include "scene/object.hpp" #include "geometry/sphere.hpp" #include "utility/fundamental-types.hpp" +namespace scene { + enum class light_type { ambient, @@ -32,7 +34,7 @@ enum class light_type spot }; -class light: public scene_object +class light: public object { public: light(); @@ -52,7 +54,7 @@ public: const tween& get_intensity_tween() const; const tween& get_scaled_color_tween() const; - /// @copydoc scene_object_base::update_tweens(); + /// @copydoc object_base::update_tweens(); virtual void update_tweens(); private: @@ -99,5 +101,7 @@ inline const tween& light::get_scaled_color_tween() const return scaled_color; } -#endif // ANTKEEPER_LIGHT_HPP +} // namespace scene + +#endif // ANTKEEPER_SCENE_LIGHT_HPP diff --git a/src/scene/lod-group.cpp b/src/scene/lod-group.cpp index 670bef9..64b57f6 100644 --- a/src/scene/lod-group.cpp +++ b/src/scene/lod-group.cpp @@ -20,6 +20,8 @@ #include "scene/lod-group.hpp" #include "scene/camera.hpp" +namespace scene { + lod_group::lod_group(std::size_t level_count): bounds(get_translation(), get_translation()) { @@ -35,7 +37,7 @@ void lod_group::resize(std::size_t level_count) levels.resize(level_count); } -std::size_t lod_group::select_lod(const ::camera& camera) const +std::size_t lod_group::select_lod(const camera& camera) const { float distance = camera.get_view_frustum().get_near().signed_distance(get_translation()); @@ -49,12 +51,12 @@ std::size_t lod_group::select_lod(const ::camera& camera) const return 3; } -void lod_group::add_object(std::size_t level, scene_object_base* object) +void lod_group::add_object(std::size_t level, object_base* object) { levels[level].push_back(object); } -void lod_group::remove_object(std::size_t level, scene_object_base* object) +void lod_group::remove_object(std::size_t level, object_base* object) { levels[level].remove(object); } @@ -73,3 +75,5 @@ void lod_group::transformed() { update_bounds(); } + +} // namespace scene diff --git a/src/scene/lod-group.hpp b/src/scene/lod-group.hpp index 9f0cf82..1f80c09 100644 --- a/src/scene/lod-group.hpp +++ b/src/scene/lod-group.hpp @@ -17,17 +17,19 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_LOD_GROUP_HPP -#define ANTKEEPER_LOD_GROUP_HPP +#ifndef ANTKEEPER_SCENE_LOD_GROUP_HPP +#define ANTKEEPER_SCENE_LOD_GROUP_HPP -#include "scene/scene-object.hpp" +#include "scene/object.hpp" #include "geometry/aabb.hpp" #include #include +namespace scene { + class camera; -class lod_group: public scene_object +class lod_group: public object { public: /** @@ -53,7 +55,7 @@ public: * @param camera Camera for which the LOD should be selected. * @return Selected level of detail. */ - std::size_t select_lod(const ::camera& camera) const; + std::size_t select_lod(const camera& camera) const; /** * Adds an object to the LOD group. @@ -61,7 +63,7 @@ public: * @param level Level of detail of the object to add. * @param object Object to add. */ - void add_object(std::size_t level, scene_object_base* object); + void add_object(std::size_t level, object_base* object); /** * Removes an object from the LOD group. @@ -69,7 +71,7 @@ public: * @param level Level of detail of the object to remove. * @param object Object to remove. */ - void remove_object(std::size_t level, scene_object_base* object); + void remove_object(std::size_t level, object_base* object); /** * Removes all objects with the specified level of detail. @@ -89,14 +91,14 @@ public: * @param level Level of detail. * @return List of all objects in the group with the specified detail level. */ - const std::list& get_objects(std::size_t level) const; + const std::list& get_objects(std::size_t level) const; private: void update_bounds(); virtual void transformed(); aabb bounds; - std::vector> levels; + std::vector> levels; }; inline const bounding_volume& lod_group::get_bounds() const @@ -109,10 +111,12 @@ inline std::size_t lod_group::get_level_count() const return levels.size(); } -inline const std::list& lod_group::get_objects(std::size_t level) const +inline const std::list& lod_group::get_objects(std::size_t level) const { return levels[level]; } -#endif // ANTKEEPER_LOD_GROUP_HPP +} // namespace scene + +#endif // ANTKEEPER_SCENE_LOD_GROUP_HPP diff --git a/src/scene/model-instance.cpp b/src/scene/model-instance.cpp index e14f301..80600e5 100644 --- a/src/scene/model-instance.cpp +++ b/src/scene/model-instance.cpp @@ -21,6 +21,8 @@ #include "renderer/model.hpp" #include "renderer/material.hpp" +namespace scene { + model_instance::model_instance(::model* model): model(nullptr), pose(nullptr), @@ -102,7 +104,7 @@ void model_instance::transformed() void model_instance::update_tweens() { - scene_object_base::update_tweens(); + object_base::update_tweens(); // Update model material tweens if (model) @@ -126,3 +128,5 @@ void model_instance::update_tweens() } } } + +} // namespace scene diff --git a/src/scene/model-instance.hpp b/src/scene/model-instance.hpp index 5e01392..0e73427 100644 --- a/src/scene/model-instance.hpp +++ b/src/scene/model-instance.hpp @@ -17,10 +17,10 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MODEL_INSTANCE_HPP -#define ANTKEEPER_MODEL_INSTANCE_HPP +#ifndef ANTKEEPER_SCENE_MODEL_INSTANCE_HPP +#define ANTKEEPER_SCENE_MODEL_INSTANCE_HPP -#include "scene/scene-object.hpp" +#include "scene/object.hpp" #include "geometry/aabb.hpp" #include @@ -28,7 +28,9 @@ class material; class model; class pose; -class model_instance: public scene_object +namespace scene { + +class model_instance: public object { public: explicit model_instance(model* model); @@ -129,5 +131,7 @@ inline std::size_t model_instance::get_instance_count() const return instance_count; } -#endif // ANTKEEPER_MODEL_INSTANCE_HPP +} // namespace scene + +#endif // ANTKEEPER_SCENE_MODEL_INSTANCE_HPP diff --git a/src/scene/scene-object.cpp b/src/scene/object.cpp similarity index 71% rename from src/scene/scene-object.cpp rename to src/scene/object.cpp index 91fbb3f..6e95365 100644 --- a/src/scene/scene-object.cpp +++ b/src/scene/object.cpp @@ -17,10 +17,12 @@ * along with Antkeeper source code. If not, see . */ -#include "scene/scene-object.hpp" +#include "scene/object.hpp" #include "math/math.hpp" -typename scene_object_base::transform_type scene_object_base::interpolate_transforms(const transform_type& x, const transform_type& y, float a) +namespace scene { + +typename object_base::transform_type object_base::interpolate_transforms(const transform_type& x, const transform_type& y, float a) { return { @@ -30,34 +32,36 @@ typename scene_object_base::transform_type scene_object_base::interpolate_transf }; } -scene_object_base::scene_object_base(): +object_base::object_base(): active(true), transform(math::identity_transform, interpolate_transforms), culling_mask(nullptr) {} -void scene_object_base::set_culling_mask(const bounding_volume_type* culling_mask) +void object_base::set_culling_mask(const bounding_volume_type* culling_mask) { this->culling_mask = culling_mask; } -std::size_t scene_object_base::next_object_type_id() +std::size_t object_base::next_object_type_id() { static std::atomic id{0}; return id++; } -void scene_object_base::update_tweens() +void object_base::update_tweens() { transform.update(); } -void scene_object_base::look_at(const vector_type& position, const vector_type& target, const vector_type& up) +void object_base::look_at(const vector_type& position, const vector_type& target, const vector_type& up) { transform[1].translation = position; transform[1].rotation = math::look_rotation(math::normalize(math::sub(target, position)), up); transformed(); } -void scene_object_base::transformed() +void object_base::transformed() {} + +} // namespace scene diff --git a/src/scene/scene-object.hpp b/src/scene/object.hpp similarity index 76% rename from src/scene/scene-object.hpp rename to src/scene/object.hpp index d4c3eb2..ff05332 100644 --- a/src/scene/scene-object.hpp +++ b/src/scene/object.hpp @@ -28,10 +28,12 @@ #include #include +namespace scene { + /** * Internal base class for scene objects. */ -class scene_object_base +class object_base { public: typedef math::vector vector_type; @@ -45,12 +47,12 @@ public: /** * Creates a scene object base. */ - scene_object_base(); + object_base(); /** * Destroys a scene object base. */ - virtual ~scene_object_base() = default; + virtual ~object_base() = default; /** * Updates all tweens in the scene object. @@ -148,71 +150,71 @@ private: const bounding_volume_type* culling_mask; }; -inline void scene_object_base::set_active(bool active) +inline void object_base::set_active(bool active) { this->active = active; } -inline void scene_object_base::set_transform(const transform_type& transform) +inline void object_base::set_transform(const transform_type& transform) { this->transform[1] = transform; transformed(); } -inline void scene_object_base::set_translation(const vector_type& translation) +inline void object_base::set_translation(const vector_type& translation) { transform[1].translation = translation; transformed(); } -inline void scene_object_base::set_rotation(const quaternion_type& rotation) +inline void object_base::set_rotation(const quaternion_type& rotation) { transform[1].rotation = rotation; transformed(); } -inline void scene_object_base::set_scale(const vector_type& scale) +inline void object_base::set_scale(const vector_type& scale) { transform[1].scale = scale; transformed(); } -inline bool scene_object_base::is_active() const +inline bool object_base::is_active() const { return active; } -inline const typename scene_object_base::transform_type& scene_object_base::get_transform() const +inline const typename object_base::transform_type& object_base::get_transform() const { return transform[1]; } -inline const typename scene_object_base::vector_type& scene_object_base::get_translation() const +inline const typename object_base::vector_type& object_base::get_translation() const { return get_transform().translation; } -inline const typename scene_object_base::quaternion_type& scene_object_base::get_rotation() const +inline const typename object_base::quaternion_type& object_base::get_rotation() const { return get_transform().rotation; } -inline const typename scene_object_base::vector_type& scene_object_base::get_scale() const +inline const typename object_base::vector_type& object_base::get_scale() const { return get_transform().scale; } -inline const tween& scene_object_base::get_transform_tween() const +inline const tween& object_base::get_transform_tween() const { return transform; } -inline tween& scene_object_base::get_transform_tween() +inline tween& object_base::get_transform_tween() { return transform; } -inline const typename scene_object_base::bounding_volume_type* scene_object_base::get_culling_mask() const +inline const typename object_base::bounding_volume_type* object_base::get_culling_mask() const { return culling_mask; } @@ -223,7 +225,7 @@ inline const typename scene_object_base::bounding_volume_type* scene_object_base * @tparam T This should be the same class that's inheriting from the scene object, in order to give it a valid type-specific ID. */ template -class scene_object: public scene_object_base +class object: public object_base { public: /// Unique type ID for this scene object type. @@ -233,13 +235,15 @@ public: }; template -const std::atomic scene_object::object_type_id{scene_object_base::next_object_type_id()}; +const std::atomic object::object_type_id{object_base::next_object_type_id()}; template -inline const std::size_t scene_object::get_object_type_id() const +inline const std::size_t object::get_object_type_id() const { return object_type_id; } +} // namespace scene + #endif // ANTKEEPER_SCENE_OBJECT_HPP diff --git a/src/scene/point-light.cpp b/src/scene/point-light.cpp index 3ed28c2..1211320 100644 --- a/src/scene/point-light.cpp +++ b/src/scene/point-light.cpp @@ -20,6 +20,8 @@ #include "point-light.hpp" #include "math/interpolation.hpp" +namespace scene { + point_light::point_light(): attenuation(float3{1, 0, 0}, math::lerp) {} @@ -34,3 +36,5 @@ void point_light::update_tweens() light::update_tweens(); attenuation.update(); } + +} // namespace scene diff --git a/src/scene/point-light.hpp b/src/scene/point-light.hpp index c71e9c1..f78745d 100644 --- a/src/scene/point-light.hpp +++ b/src/scene/point-light.hpp @@ -17,12 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_POINT_LIGHT_HPP -#define ANTKEEPER_POINT_LIGHT_HPP +#ifndef ANTKEEPER_SCENE_POINT_LIGHT_HPP +#define ANTKEEPER_SCENE_POINT_LIGHT_HPP #include "scene/light.hpp" #include "utility/fundamental-types.hpp" +namespace scene { + class point_light: public light { public: @@ -44,7 +46,7 @@ public: /// Returns the attenuation tween. const tween& get_attenuation_tween() const; - /// @copydoc scene_object_base::update_tweens(); + /// @copydoc object_base::update_tweens(); virtual void update_tweens(); private: @@ -66,5 +68,7 @@ inline const tween& point_light::get_attenuation_tween() const return attenuation; } -#endif // ANTKEEPER_POINT_LIGHT_HPP +} // namespace scene + +#endif // ANTKEEPER_SCENE_POINT_LIGHT_HPP diff --git a/src/scene/scene.hpp b/src/scene/scene.hpp index 94e6a71..0682496 100644 --- a/src/scene/scene.hpp +++ b/src/scene/scene.hpp @@ -20,61 +20,19 @@ #ifndef ANTKEEPER_SCENE_HPP #define ANTKEEPER_SCENE_HPP -#include -#include - -class scene_object_base; - -/** - * Container for scene objects. - */ -class scene -{ -public: - /** - * Adds an object to the scene. - * - * @param object Object to add. - */ - void add_object(scene_object_base* object); - - /** - * Removes an object from the scene. - * - * @param object Object to remove. - */ - void remove_object(scene_object_base* object); - - /// Removes all objects from the scene. - void remove_objects(); - - /// Updates the tweens of all objects in the scene. - void update_tweens(); - - /// Returns a list of all objects in the scene. - const std::list* get_objects() const; - - /** - * Returns a list of all objects in the scene with the specified type ID. - * - * @param type_id Scene object type ID. - * @return List of scene ibjects with the specified type ID. - */ - const std::list* get_objects(std::size_t type_id) const; - -private: - std::list objects; - mutable std::unordered_map> object_map; -}; - -inline const std::list* scene::get_objects() const -{ - return &objects; -} - -inline const std::list* scene::get_objects(std::size_t type_id) const -{ - return &object_map[type_id]; -} +/// 3D scene +namespace scene {} + +#include "ambient-light.hpp" +#include "billboard.hpp" +#include "camera.hpp" +#include "collection.hpp" +#include "directional-light.hpp" +#include "light.hpp" +#include "lod-group.hpp" +#include "model-instance.hpp" +#include "object.hpp" +#include "point-light.hpp" +#include "spotlight.hpp" #endif // ANTKEEPER_SCENE_HPP diff --git a/src/scene/spotlight.cpp b/src/scene/spotlight.cpp index 15facb9..e0febdc 100644 --- a/src/scene/spotlight.cpp +++ b/src/scene/spotlight.cpp @@ -22,6 +22,8 @@ #include "math/math.hpp" #include +namespace scene { + static float3 interpolate_direction(const float3& x, const float3& y, float a) { math::quaternion q0 = math::rotation(global_forward, x); @@ -61,3 +63,4 @@ void spotlight::transformed() direction[1] = math::normalize(get_transform().rotation * global_forward); } +} // namespace scene diff --git a/src/scene/spotlight.hpp b/src/scene/spotlight.hpp index d7f8162..7033812 100644 --- a/src/scene/spotlight.hpp +++ b/src/scene/spotlight.hpp @@ -17,12 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_SPOTLIGHT_HPP -#define ANTKEEPER_SPOTLIGHT_HPP +#ifndef ANTKEEPER_SCENE_SPOTLIGHT_HPP +#define ANTKEEPER_SCENE_SPOTLIGHT_HPP #include "scene/light.hpp" #include "utility/fundamental-types.hpp" +namespace scene { + class spotlight: public light { public: @@ -69,7 +71,7 @@ public: /// Returns the cosine cutoff tween. const tween& get_cosine_cutoff_tween() const; - /// @copydoc scene_object_base::update_tweens(); + /// @copydoc object_base::update_tweens(); virtual void update_tweens(); private: @@ -126,5 +128,7 @@ inline const tween& spotlight::get_cosine_cutoff_tween() const return cosine_cutoff; } -#endif // ANTKEEPER_SPOTLIGHT_HPP +} // namespace scene + +#endif // ANTKEEPER_SCENE_SPOTLIGHT_HPP