Browse Source

Remove active paramter from scene objects

master
C. J. Howard 1 year ago
parent
commit
356a4a2f89
17 changed files with 54 additions and 83 deletions
  1. +11
    -11
      src/engine/animation/screen-transition.cpp
  2. +1
    -6
      src/engine/render/passes/material-pass.cpp
  3. +0
    -6
      src/engine/render/passes/shadow-map-pass.cpp
  4. +0
    -6
      src/engine/render/renderer.cpp
  5. +2
    -2
      src/engine/render/stages/culling-stage.cpp
  6. +2
    -4
      src/engine/scene/directional-light.cpp
  7. +4
    -3
      src/engine/scene/directional-light.hpp
  8. +1
    -16
      src/engine/scene/object.hpp
  9. +2
    -3
      src/game/game.cpp
  10. +2
    -2
      src/game/game.hpp
  11. +2
    -2
      src/game/graphics.cpp
  12. +1
    -2
      src/game/states/main-menu-state.cpp
  13. +21
    -13
      src/game/states/nest-selection-state.cpp
  14. +2
    -0
      src/game/states/nest-selection-state.hpp
  15. +0
    -4
      src/game/states/nuptial-flight-state.cpp
  16. +2
    -2
      src/game/states/pause-menu-state.cpp
  17. +1
    -1
      src/game/world.cpp

+ 11
- 11
src/engine/animation/screen-transition.cpp View File

@ -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<float>::interpolator_type interpolator, bool hide, const std::function<void()>& callback)
@ -94,7 +94,7 @@ void screen_transition::transition(float duration, bool reverse, ::animation
(
[this]()
{
this->billboard.set_active(false);
//this->billboard.set_active(false);
if (this->callback)
this->callback();
}

+ 1
- 6
src/engine/render/passes/material-pass.cpp View File

@ -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<const scene::light&>(*object);
switch (light.get_light_type())
{
// Add ambient light

+ 0
- 6
src/engine/render/passes/shadow-map-pass.cpp View File

@ -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<const scene::light&>(*object);
if (light.get_light_type() != scene::light_type::directional)

+ 0
- 6
src/engine/render/renderer.cpp View File

@ -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<scene::camera&>(*camera_object);
// Skip cameras with no compositors

+ 2
- 2
src/engine/render/stages/culling-stage.cpp View File

@ -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;
}

+ 2
- 4
src/engine/scene/directional-light.cpp View File

@ -18,8 +18,6 @@
*/
#include <engine/scene/directional-light.hpp>
#include <engine/math/quaternion.hpp>
#include <engine/math/interpolation.hpp>
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<gl::framebuffer> framebuffer) noexcept
{
m_shadow_framebuffer = framebuffer;
m_shadow_framebuffer = std::move(framebuffer);
}
void directional_light::set_shadow_bias(float bias) noexcept

+ 4
- 3
src/engine/scene/directional-light.hpp View File

@ -23,6 +23,7 @@
#include <engine/scene/light.hpp>
#include <engine/gl/texture-2d.hpp>
#include <engine/utility/fundamental-types.hpp>
#include <memory>
#include <vector>
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<gl::framebuffer> 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<gl::framebuffer>& get_shadow_framebuffer() const noexcept
{
return m_shadow_framebuffer;
}
@ -182,7 +183,7 @@ private:
math::vector<float, 3> m_illuminance{0.0f, 0.0f, 0.0f};
math::vector<float, 3> m_direction{0.0f, 0.0f, -1.0f};
bool m_shadow_caster{false};
const gl::framebuffer* m_shadow_framebuffer{nullptr};
std::shared_ptr<gl::framebuffer> m_shadow_framebuffer{nullptr};
float m_shadow_bias{0.005f};
unsigned int m_shadow_cascade_count{4};
float m_shadow_cascade_coverage{1.0f};

+ 1
- 16
src/engine/scene/object.hpp View File

@ -26,7 +26,7 @@
#include <engine/math/transform-type.hpp>
#include <engine/render/context.hpp>
#include <atomic>
#include <cstddef>
#include <cstdint>
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};
};

+ 2
- 3
src/game/game.cpp View File

@ -893,7 +893,6 @@ void game::setup_ui()
// Menu BG billboard
menu_bg_billboard = std::make_unique<scene::billboard>();
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);
}
);
}

+ 2
- 2
src/game/game.hpp View File

@ -258,8 +258,8 @@ public:
std::unique_ptr<gl::framebuffer> ldr_framebuffer_a;
std::unique_ptr<gl::texture_2d> ldr_color_texture_b;
std::unique_ptr<gl::framebuffer> ldr_framebuffer_b;
std::unique_ptr<gl::texture_2d> shadow_map_depth_texture;
std::unique_ptr<gl::framebuffer> shadow_map_framebuffer;
std::shared_ptr<gl::texture_2d> shadow_map_depth_texture;
std::shared_ptr<gl::framebuffer> shadow_map_framebuffer;
// Rendering
//gl::rasterizer* rasterizer;

+ 2
- 2
src/game/graphics.cpp View File

@ -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<gl::texture_2d>(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<gl::texture_2d>(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<gl::framebuffer>(ctx.shadow_map_resolution, ctx.shadow_map_resolution);
ctx.shadow_map_framebuffer = std::make_shared<gl::framebuffer>(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");

+ 1
- 2
src/game/states/main-menu-state.cpp View File

@ -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);

+ 21
- 13
src/game/states/nest-selection-state.cpp View File

@ -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<render::model> 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<transform_component>(worker_ant_eid, worker_transform_component);
ctx.entity_registry->emplace<scene_component>(worker_ant_eid, std::make_unique<scene::static_mesh>(worker_model), std::uint8_t{1});
// auto worker_body = std::make_unique<physics::rigid_body>();
// worker_body->set_mass(0.005f);
// worker_body->set_collider(std::make_shared<physics::sphere_collider>(1.0f));
//ctx.entity_registry->emplace<rigid_body_component>(worker_ant_eid, std::move(worker_body));
auto worker_collider = std::make_shared<physics::box_collider>(float3{-1.0f, -1.0f, -1.0f}, float3{1.0f, 1.0f, 1.0f});
//auto worker_collider = std::make_shared<physics::sphere_collider>(1.0f);
worker_collider->set_material(std::make_shared<physics::collider_material>(0.4f, 0.1f, 0.2f));
auto worker_body = std::make_unique<physics::rigid_body>();
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<rigid_body_component>(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<transform_component>(first_person_camera_rig_eid);
scene_component projectile_scene;
projectile_scene.object = std::make_shared<scene::static_mesh>(ctx.resource_manager->load<render::model>("sphere.mdl"));
//projectile_scene.object = std::make_shared<scene::static_mesh>(ctx.resource_manager->load<render::model>("cube.mdl"));
//projectile_scene.object = std::make_shared<scene::static_mesh>(worker_model);
//projectile_scene.object = std::make_shared<scene::static_mesh>(ctx.resource_manager->load<render::model>("sphere.mdl"));
projectile_scene.object = std::make_shared<scene::static_mesh>(ctx.resource_manager->load<render::model>("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<physics::box_collider>(float3{-1.0f, -1.0f, -1.0f}, float3{1.0f, 1.0f, 1.0f});
auto projectile_collider = std::make_shared<physics::sphere_collider>(1.0f);
auto projectile_collider = std::make_shared<physics::box_collider>(float3{-1.0f, -1.0f, -1.0f}, float3{1.0f, 1.0f, 1.0f});
//auto projectile_collider = std::make_shared<physics::sphere_collider>(1.0f);
projectile_collider->set_material(std::make_shared<physics::collider_material>(0.4f, 0.1f, 0.2f));

+ 2
- 0
src/game/states/nest-selection-state.hpp View File

@ -23,6 +23,7 @@
#include "game/states/game-state.hpp"
#include <engine/entity/id.hpp>
#include <engine/utility/fundamental-types.hpp>
#include <engine/render/model.hpp>
class nest_selection_state: public game_state
@ -44,6 +45,7 @@ private:
std::vector<std::shared_ptr<::event::subscription>> action_subscriptions;
std::shared_ptr<::event::subscription> mouse_motion_subscription;
std::shared_ptr<render::model> worker_model;
bool mouse_look{false};

+ 0
- 4
src/game/states/nuptial-flight-state.cpp View File

@ -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);

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

@ -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<main_menu_state>(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

+ 1
- 1
src/game/world.cpp View File

@ -363,7 +363,7 @@ void create_sun(::game& ctx)
ctx.sun_light = std::make_unique<scene::directional_light>();
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);

Loading…
Cancel
Save