From 7374f8de8c56e8bdb6ffdf56771b504f85eb3f38 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Mon, 11 Mar 2024 21:48:24 -0400 Subject: [PATCH] Some more cleanup --- src/engine/CMakeLists.txt | 2 -- src/engine/EngineContext.cpp | 7 +++--- src/engine/allocators/globalAllocator.cpp | 26 +++++++++++++++++++++ src/engine/systems/EntityRendererSystem.cpp | 6 +++-- src/engine/tree/octtree/OctTreeNode.cpp | 3 ++- src/engine/tree/octtree/OctTreeNode.hpp | 2 +- 6 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 src/engine/allocators/globalAllocator.cpp diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index 147fb9d..ba20840 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -49,8 +49,6 @@ if (FORCE_DISABLE_IMGUI EQUAL 0) endif () endif () -target_compile_definitions(FGLEngine PRIVATE GLM_FORCE_INLINE=1) - #GLM settings # GLM_FORCE_NO_CTOR_INIT target_compile_definitions(FGLEngine PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE GLM_FORCE_LEFT_HANDED) diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index 7627a5a..70769fe 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -505,7 +505,7 @@ namespace fgl::engine model->syncBuffers( command_buffer ); - constexpr int val { 16 }; + constexpr int val { 4 }; constexpr float x_offset { -( static_cast< float >( val ) * 30.0f ) / 2.0f }; constexpr float y_offset { -( static_cast< float >( val ) * 20.0f ) / 2.0f }; @@ -519,14 +519,15 @@ namespace fgl::engine sponza.m_transform.translation = WorldCoordinate( x_offset + ( static_cast< float >( y ) * 30.0f ), y_offset + ( static_cast< float >( x ) * 20.0f ), - 0.0f ); + float( rand() % 120 ) - 60.0f ); sponza.m_transform.scale = { 0.007f, 0.007f, 0.007f }; sponza.m_transform.rotation = Rotation( 0.0f, 0.0f, 0.0f ); m_game_objects_root.addGameObject( std::move( sponza ) ); - m_game_objects_root.recalculateBoundingBoxes(); + std::cout << "(" << x << "," << y << ")" << std::endl; } } + m_game_objects_root.recalculateBoundingBoxes(); /* { diff --git a/src/engine/allocators/globalAllocator.cpp b/src/engine/allocators/globalAllocator.cpp new file mode 100644 index 0000000..5cb00e4 --- /dev/null +++ b/src/engine/allocators/globalAllocator.cpp @@ -0,0 +1,26 @@ +// +// Created by kj16609 on 3/11/24. +// + +#if TRACY_ENABLE + +void* operator new( std::size_t count ) +{ + auto ptr = malloc( count ); + TracyAlloc( ptr, count ); + return ptr; +} + +void operator delete( void* ptr ) noexcept +{ + TracyFree( ptr ); + free( ptr ); +} + +void operator delete( void* ptr, [[maybe_unused]] std::size_t size ) noexcept +{ + TracyFree( ptr ); + free( ptr ); +} + +#endif diff --git a/src/engine/systems/EntityRendererSystem.cpp b/src/engine/systems/EntityRendererSystem.cpp index 6497603..22a3a2e 100644 --- a/src/engine/systems/EntityRendererSystem.cpp +++ b/src/engine/systems/EntityRendererSystem.cpp @@ -113,7 +113,9 @@ namespace fgl::engine std::uint64_t object_counter { 0 }; std::uint64_t primitive_counter { 0 }; - for ( auto* node : info.game_objects.getAllLeafsInFrustum( info.camera_frustum ) ) + const auto in_view_leafs { info.game_objects.getAllLeafsInFrustum( info.camera_frustum ) }; + + for ( auto* node : in_view_leafs ) { ZoneScopedN( "Process leaf" ); for ( const auto& obj : *node ) @@ -159,7 +161,7 @@ namespace fgl::engine cmd.instanceCount = 1; std::vector< ModelMatrixInfo > matrix_infos {}; - matrix_infos.reserve( 1024 ); + matrix_infos.reserve( 128 ); matrix_infos.emplace_back( matrix_info ); draw_pairs.emplace( key, std::make_pair( cmd, std::move( matrix_infos ) ) ); } diff --git a/src/engine/tree/octtree/OctTreeNode.cpp b/src/engine/tree/octtree/OctTreeNode.cpp index dd9e2c8..475c48c 100644 --- a/src/engine/tree/octtree/OctTreeNode.cpp +++ b/src/engine/tree/octtree/OctTreeNode.cpp @@ -32,7 +32,6 @@ namespace fgl::engine std::vector< NodeLeaf* > OctTreeNode::getAllLeafsInFrustum( const Frustum< CoordinateSpace::World >& frustum ) { - ZoneScoped; std::vector< NodeLeaf* > leafs {}; //Check if we are inside of the frustum. @@ -159,6 +158,8 @@ namespace fgl::engine new_nodes[ RIGHT ][ BACK ][ BOTTOM ] = std::make_unique< OctTreeNode >( WorldCoordinate( right_x, backward_y, bottom_z ), half_span, this ); + [[assume( game_objects.size() <= MAX_NODES_IN_LEAF )]]; + for ( GameObject& obj : game_objects ) { const auto& obj_coordinate { obj.m_transform.translation }; diff --git a/src/engine/tree/octtree/OctTreeNode.hpp b/src/engine/tree/octtree/OctTreeNode.hpp index ad942bf..95ce7ed 100644 --- a/src/engine/tree/octtree/OctTreeNode.hpp +++ b/src/engine/tree/octtree/OctTreeNode.hpp @@ -13,7 +13,7 @@ namespace fgl::engine { constexpr std::size_t MAX_NODES_IN_LEAF { 32 }; constexpr std::size_t STARTING_DEPTH { 4 }; - constexpr float ROOT_SPAN { 1000.0f }; + constexpr float ROOT_SPAN { std::numeric_limits< float >::max() }; template < CoordinateSpace CType > struct Frustum;