From 356a4a2f895c53c9d4b4bea3f3670def90caec83 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Wed, 22 Mar 2023 15:30:55 +0800 Subject: [PATCH] Remove active paramter from scene objects --- src/engine/animation/screen-transition.cpp | 22 ++++++------- src/engine/render/passes/material-pass.cpp | 7 +--- src/engine/render/passes/shadow-map-pass.cpp | 6 ---- src/engine/render/renderer.cpp | 6 ---- src/engine/render/stages/culling-stage.cpp | 4 +-- src/engine/scene/directional-light.cpp | 6 ++-- src/engine/scene/directional-light.hpp | 7 ++-- src/engine/scene/object.hpp | 17 +--------- src/game/game.cpp | 5 ++- src/game/game.hpp | 4 +-- src/game/graphics.cpp | 4 +-- src/game/states/main-menu-state.cpp | 3 +- src/game/states/nest-selection-state.cpp | 34 ++++++++++++-------- src/game/states/nest-selection-state.hpp | 2 ++ src/game/states/nuptial-flight-state.cpp | 4 --- src/game/states/pause-menu-state.cpp | 4 +-- src/game/world.cpp | 2 +- 17 files changed, 54 insertions(+), 83 deletions(-) diff --git a/src/engine/animation/screen-transition.cpp b/src/engine/animation/screen-transition.cpp index f8d4697..fd6f454 100644 --- a/src/engine/animation/screen-transition.cpp +++ b/src/engine/animation/screen-transition.cpp @@ -32,22 +32,22 @@ screen_transition::screen_transition() // Setup billboard billboard.set_material(material); - billboard.set_active(false); + //billboard.set_active(false); // Add single channel to transition animation channel = animation.add_channel(0); // Setup animation start callback to show transition billboard - animation.set_start_callback - ( - std::bind(&scene::object_base::set_active, &billboard, true) - ); + // animation.set_start_callback + // ( + // 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) - ); + // animation.set_end_callback + // ( + // std::bind(&scene::object_base::set_active, &billboard, false) + // ); // Setup animation frame callback to update transition progress material property animation.set_frame_callback @@ -70,7 +70,7 @@ screen_transition::screen_transition() void screen_transition::set_visible(bool visible) { - billboard.set_active(visible); + //billboard.set_active(visible); } void screen_transition::transition(float duration, bool reverse, ::animation::interpolator_type interpolator, bool hide, const std::function& callback) @@ -94,7 +94,7 @@ void screen_transition::transition(float duration, bool reverse, ::animationbillboard.set_active(false); + //this->billboard.set_active(false); if (this->callback) this->callback(); } diff --git a/src/engine/render/passes/material-pass.cpp b/src/engine/render/passes/material-pass.cpp index 832da7a..9eba3a9 100644 --- a/src/engine/render/passes/material-pass.cpp +++ b/src/engine/render/passes/material-pass.cpp @@ -318,13 +318,8 @@ void material_pass::evaluate_lighting(const render::context& ctx) const auto& lights = ctx.collection->get_objects(scene::light::object_type_id); for (const scene::object_base* object: lights) { - // Ignore inactive lights - if (!object->is_active()) - { - continue; - } - const scene::light& light = static_cast(*object); + switch (light.get_light_type()) { // Add ambient light diff --git a/src/engine/render/passes/shadow-map-pass.cpp b/src/engine/render/passes/shadow-map-pass.cpp index 9f4eec8..70074d9 100644 --- a/src/engine/render/passes/shadow-map-pass.cpp +++ b/src/engine/render/passes/shadow-map-pass.cpp @@ -79,12 +79,6 @@ void shadow_map_pass::render(render::context& ctx) const auto& lights = ctx.collection->get_objects(scene::light::object_type_id); for (const scene::object_base* object: lights) { - // Ignore inactive lights - if (!object->is_active()) - { - continue; - } - // Ignore non-directional lights const scene::light& light = static_cast(*object); if (light.get_light_type() != scene::light_type::directional) diff --git a/src/engine/render/renderer.cpp b/src/engine/render/renderer.cpp index 1743b13..3ec2bb6 100644 --- a/src/engine/render/renderer.cpp +++ b/src/engine/render/renderer.cpp @@ -57,12 +57,6 @@ void renderer::render(float t, float dt, float alpha, const scene::collection& c // Process cameras in order for (scene::object_base* camera_object: cameras) { - // Skip inactive cameras - if (!camera_object->is_active()) - { - continue; - } - scene::camera& camera = static_cast(*camera_object); // Skip cameras with no compositors diff --git a/src/engine/render/stages/culling-stage.cpp b/src/engine/render/stages/culling-stage.cpp index 77b44ef..bab656e 100644 --- a/src/engine/render/stages/culling-stage.cpp +++ b/src/engine/render/stages/culling-stage.cpp @@ -45,8 +45,8 @@ void culling_stage::execute(render::context& ctx) std::end(objects), [&](scene::object_base* object) { - // Ignore inactive objects and cameras - if (!object->is_active() || object->get_object_type_id() == scene::camera::object_type_id) + // Ignore cameras + if (object->get_object_type_id() == scene::camera::object_type_id) { return; } diff --git a/src/engine/scene/directional-light.cpp b/src/engine/scene/directional-light.cpp index 1240f9b..aae8538 100644 --- a/src/engine/scene/directional-light.cpp +++ b/src/engine/scene/directional-light.cpp @@ -18,8 +18,6 @@ */ #include -#include -#include namespace scene { @@ -33,9 +31,9 @@ void directional_light::set_shadow_caster(bool caster) noexcept m_shadow_caster = caster; } -void directional_light::set_shadow_framebuffer(const gl::framebuffer* framebuffer) noexcept +void directional_light::set_shadow_framebuffer(std::shared_ptr framebuffer) noexcept { - m_shadow_framebuffer = framebuffer; + m_shadow_framebuffer = std::move(framebuffer); } void directional_light::set_shadow_bias(float bias) noexcept diff --git a/src/engine/scene/directional-light.hpp b/src/engine/scene/directional-light.hpp index f43bea8..57390bf 100644 --- a/src/engine/scene/directional-light.hpp +++ b/src/engine/scene/directional-light.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace scene { @@ -84,7 +85,7 @@ public: * * @param framebuffer Pointer to a shadow map framebuffer. */ - void set_shadow_framebuffer(const gl::framebuffer* framebuffer) noexcept; + void set_shadow_framebuffer(std::shared_ptr framebuffer) noexcept; /** * Sets the shadow bias factor for reducing self-shadowing. @@ -121,7 +122,7 @@ public: } /// Returns the shadow map framebuffer, of `nullptr` if no shadow map framebuffer is set. - [[nodiscard]] inline const gl::framebuffer* get_shadow_framebuffer() const noexcept + [[nodiscard]] inline const std::shared_ptr& get_shadow_framebuffer() const noexcept { return m_shadow_framebuffer; } @@ -182,7 +183,7 @@ private: math::vector m_illuminance{0.0f, 0.0f, 0.0f}; math::vector m_direction{0.0f, 0.0f, -1.0f}; bool m_shadow_caster{false}; - const gl::framebuffer* m_shadow_framebuffer{nullptr}; + std::shared_ptr m_shadow_framebuffer{nullptr}; float m_shadow_bias{0.005f}; unsigned int m_shadow_cascade_count{4}; float m_shadow_cascade_coverage{1.0f}; diff --git a/src/engine/scene/object.hpp b/src/engine/scene/object.hpp index 03ecb1e..4efffbb 100644 --- a/src/engine/scene/object.hpp +++ b/src/engine/scene/object.hpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include namespace scene { @@ -51,14 +51,6 @@ public: */ inline virtual void render(render::context& ctx) const {} - /** - * Activates or deactivates the scene object. - */ - inline void set_active(bool active) noexcept - { - m_active = active; - } - /** * */ @@ -99,12 +91,6 @@ public: m_transform.scale = scale; transformed(); } - - /// Returns whether the scene object is active. - [[nodiscard]] inline bool is_active() const noexcept - { - return m_active; - } /** * Returns the transform. @@ -155,7 +141,6 @@ private: */ inline virtual void transformed() {} - bool m_active{true}; transform_type m_transform{transform_type::identity}; }; diff --git a/src/game/game.cpp b/src/game/game.cpp index 0c7e318..7d7a08b 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -893,7 +893,6 @@ void game::setup_ui() // Menu BG billboard menu_bg_billboard = std::make_unique(); - menu_bg_billboard->set_active(false); menu_bg_billboard->set_material(menu_bg_material); menu_bg_billboard->set_scale({std::ceil(viewport_size.x() * 0.5f), std::ceil(viewport_size.y() * 0.5f), 1.0f}); menu_bg_billboard->set_translation({std::floor(viewport_size.x() * 0.5f), std::floor(viewport_size.y() * 0.5f), -100.0f}); @@ -935,7 +934,7 @@ void game::setup_ui() ui_scene->add_object(*menu_bg_billboard); menu_bg_tint->set(float4{0.0f, 0.0f, 0.0f, 0.0f}); - menu_bg_billboard->set_active(true); + //menu_bg_billboard->set_active(true); } ); } @@ -953,7 +952,7 @@ void game::setup_ui() [&]() { ui_scene->remove_object(*menu_bg_billboard); - menu_bg_billboard->set_active(false); + //menu_bg_billboard->set_active(false); } ); } diff --git a/src/game/game.hpp b/src/game/game.hpp index 86cce1e..7a769ea 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -258,8 +258,8 @@ public: std::unique_ptr ldr_framebuffer_a; std::unique_ptr ldr_color_texture_b; std::unique_ptr ldr_framebuffer_b; - std::unique_ptr shadow_map_depth_texture; - std::unique_ptr shadow_map_framebuffer; + std::shared_ptr shadow_map_depth_texture; + std::shared_ptr shadow_map_framebuffer; // Rendering //gl::rasterizer* rasterizer; diff --git a/src/game/graphics.cpp b/src/game/graphics.cpp index aad086a..359aba6 100644 --- a/src/game/graphics.cpp +++ b/src/game/graphics.cpp @@ -77,11 +77,11 @@ void create_framebuffers(::game& ctx) ctx.ldr_framebuffer_b->attach(gl::framebuffer_attachment_type::color, ctx.ldr_color_texture_b.get()); // Create shadow map framebuffer - ctx.shadow_map_depth_texture = std::make_unique(ctx.shadow_map_resolution, ctx.shadow_map_resolution, gl::pixel_type::float_32, gl::pixel_format::d); + ctx.shadow_map_depth_texture = std::make_shared(ctx.shadow_map_resolution, ctx.shadow_map_resolution, gl::pixel_type::float_32, gl::pixel_format::d); ctx.shadow_map_depth_texture->set_wrapping(gl::texture_wrapping::extend, gl::texture_wrapping::extend); ctx.shadow_map_depth_texture->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear); ctx.shadow_map_depth_texture->set_max_anisotropy(0.0f); - ctx.shadow_map_framebuffer = std::make_unique(ctx.shadow_map_resolution, ctx.shadow_map_resolution); + ctx.shadow_map_framebuffer = std::make_shared(ctx.shadow_map_resolution, ctx.shadow_map_resolution); ctx.shadow_map_framebuffer->attach(gl::framebuffer_attachment_type::depth, ctx.shadow_map_depth_texture.get()); debug::log::trace("Created framebuffers"); diff --git a/src/game/states/main-menu-state.cpp b/src/game/states/main-menu-state.cpp index d098b7f..eeaaa42 100644 --- a/src/game/states/main-menu-state.cpp +++ b/src/game/states/main-menu-state.cpp @@ -262,7 +262,6 @@ main_menu_state::main_menu_state(::game& ctx, bool fade_in): // Set world time scale ::world::set_time_scale(ctx, 0.0); - ctx.surface_camera->set_active(true); const float ev100_sunny16 = physics::light::ev::from_settings(16.0f, 1.0f / 100.0f, 100.0f); ctx.surface_camera->set_exposure_value(ev100_sunny16); @@ -315,7 +314,7 @@ main_menu_state::~main_menu_state() ::menu::delete_text(ctx); // Hide menu BG - ctx.menu_bg_billboard->set_active(false); + //ctx.menu_bg_billboard->set_active(false); // Destruct title animation ctx.animator->remove_animation(&title_fade_animation); diff --git a/src/game/states/nest-selection-state.cpp b/src/game/states/nest-selection-state.cpp index 6a7172d..1586418 100644 --- a/src/game/states/nest-selection-state.cpp +++ b/src/game/states/nest-selection-state.cpp @@ -99,7 +99,7 @@ nest_selection_state::nest_selection_state(::game& ctx): debug::log::trace("Built worker phenome..."); debug::log::trace("Generating worker model..."); - std::shared_ptr worker_model = ant_morphogenesis(worker_phenome); + worker_model = ant_morphogenesis(worker_phenome); debug::log::trace("Generated worker model"); // Create floor plane @@ -134,10 +134,21 @@ nest_selection_state::nest_selection_state(::game& ctx): ctx.entity_registry->emplace(worker_ant_eid, worker_transform_component); ctx.entity_registry->emplace(worker_ant_eid, std::make_unique(worker_model), std::uint8_t{1}); - // auto worker_body = std::make_unique(); - // worker_body->set_mass(0.005f); - // worker_body->set_collider(std::make_shared(1.0f)); - //ctx.entity_registry->emplace(worker_ant_eid, std::move(worker_body)); + + + auto worker_collider = std::make_shared(float3{-1.0f, -1.0f, -1.0f}, float3{1.0f, 1.0f, 1.0f}); + //auto worker_collider = std::make_shared(1.0f); + worker_collider->set_material(std::make_shared(0.4f, 0.1f, 0.2f)); + + auto worker_body = std::make_unique(); + worker_body->set_position(worker_transform_component.local.translation); + worker_body->set_previous_position(worker_transform_component.local.translation); + worker_body->set_mass(0.1f); + worker_body->set_inertia(0.05f); + worker_body->set_angular_damping(0.5f); + worker_body->set_collider(std::move(worker_collider)); + + ctx.entity_registry->emplace(worker_ant_eid, std::move(worker_body)); // Disable UI color clear ctx.ui_clear_pass->set_cleared_buffers(false, true, false); @@ -155,10 +166,6 @@ nest_selection_state::nest_selection_state(::game& ctx): ctx.sky_pass->set_enabled(true); ctx.ground_pass->set_enabled(true); - // Switch to surface camera - ctx.underground_camera->set_active(false); - ctx.surface_camera->set_active(true); - // Set camera exposure const float ev100_sunny16 = physics::light::ev::from_settings(16.0f, 1.0f / 100.0f, 100.0f); ctx.surface_camera->set_exposure_value(ev100_sunny16); @@ -673,8 +680,9 @@ void nest_selection_state::setup_controls() const auto& camera_transform = ctx.entity_registry->get(first_person_camera_rig_eid); scene_component projectile_scene; - projectile_scene.object = std::make_shared(ctx.resource_manager->load("sphere.mdl")); - //projectile_scene.object = std::make_shared(ctx.resource_manager->load("cube.mdl")); + //projectile_scene.object = std::make_shared(worker_model); + //projectile_scene.object = std::make_shared(ctx.resource_manager->load("sphere.mdl")); + projectile_scene.object = std::make_shared(ctx.resource_manager->load("cube.mdl")); transform_component projectile_transform; projectile_transform.local = camera_transform.world; @@ -687,8 +695,8 @@ void nest_selection_state::setup_controls() projectile_body->set_inertia(0.05f); projectile_body->set_angular_damping(0.5f); - //auto projectile_collider = std::make_shared(float3{-1.0f, -1.0f, -1.0f}, float3{1.0f, 1.0f, 1.0f}); - auto projectile_collider = std::make_shared(1.0f); + auto projectile_collider = std::make_shared(float3{-1.0f, -1.0f, -1.0f}, float3{1.0f, 1.0f, 1.0f}); + //auto projectile_collider = std::make_shared(1.0f); projectile_collider->set_material(std::make_shared(0.4f, 0.1f, 0.2f)); diff --git a/src/game/states/nest-selection-state.hpp b/src/game/states/nest-selection-state.hpp index f055a2d..5f73355 100644 --- a/src/game/states/nest-selection-state.hpp +++ b/src/game/states/nest-selection-state.hpp @@ -23,6 +23,7 @@ #include "game/states/game-state.hpp" #include #include +#include class nest_selection_state: public game_state @@ -44,6 +45,7 @@ private: std::vector> action_subscriptions; std::shared_ptr<::event::subscription> mouse_motion_subscription; + std::shared_ptr worker_model; bool mouse_look{false}; diff --git a/src/game/states/nuptial-flight-state.cpp b/src/game/states/nuptial-flight-state.cpp index f953640..0b43a16 100644 --- a/src/game/states/nuptial-flight-state.cpp +++ b/src/game/states/nuptial-flight-state.cpp @@ -134,10 +134,6 @@ nuptial_flight_state::nuptial_flight_state(::game& ctx): } ); - // Switch to surface camera - ctx.underground_camera->set_active(false); - ctx.surface_camera->set_active(true); - // Set camera exposure const float ev100_sunny16 = physics::light::ev::from_settings(16.0f, 1.0f / 100.0f, 100.0f); ctx.surface_camera->set_exposure_value(ev100_sunny16); diff --git a/src/game/states/pause-menu-state.cpp b/src/game/states/pause-menu-state.cpp index b87bcd4..2001df6 100644 --- a/src/game/states/pause-menu-state.cpp +++ b/src/game/states/pause-menu-state.cpp @@ -136,7 +136,7 @@ pause_menu_state::pause_menu_state(::game& ctx): ( [&ctx]() { - ctx.menu_bg_billboard->set_active(false); + //ctx.menu_bg_billboard->set_active(false); ctx.state_machine.pop(); ctx.state_machine.pop(); ctx.state_machine.emplace(std::make_unique(ctx, true)); @@ -200,7 +200,7 @@ pause_menu_state::pause_menu_state(::game& ctx): // Fade in menu and menu BG ::menu::fade_in(ctx, nullptr); - if (!ctx.menu_bg_billboard->is_active()) + //if (!ctx.menu_bg_billboard->is_active()) ::menu::fade_in_bg(ctx); // Save colony diff --git a/src/game/world.cpp b/src/game/world.cpp index 7db4713..5c6ad87 100644 --- a/src/game/world.cpp +++ b/src/game/world.cpp @@ -363,7 +363,7 @@ void create_sun(::game& ctx) ctx.sun_light = std::make_unique(); ctx.sun_light->set_illuminance({0, 0, 0}); ctx.sun_light->set_shadow_caster(true); - ctx.sun_light->set_shadow_framebuffer(ctx.shadow_map_framebuffer.get()); + ctx.sun_light->set_shadow_framebuffer(ctx.shadow_map_framebuffer); ctx.sun_light->set_shadow_bias(0.005f); ctx.sun_light->set_shadow_cascade_count(4); ctx.sun_light->set_shadow_cascade_coverage(0.15f);