mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-17 23:39:18 +02:00
Instanced object grouping
This commit is contained in:
@@ -374,6 +374,13 @@ basic_cell::insert( TAnimModel *Instance ) {
|
||||
if( alpha & flags & 0x1F1F001F ) {
|
||||
// opaque pieces
|
||||
m_instancesopaque.emplace_back( Instance );
|
||||
// additionally route instanceable nodes into a per-pModel bucket so the
|
||||
// renderer can amortise material/state setup across all instances of the
|
||||
// same TModel3d. The flat list is kept too for fallback paths
|
||||
// (picking, reflections at low fidelity, etc.).
|
||||
if( Instance->m_instanceable && Instance->Model() != nullptr ) {
|
||||
m_instancebuckets_opaque[ Instance->Model() ].emplace_back( Instance );
|
||||
}
|
||||
}
|
||||
// re-calculate cell bounding area, in case model extends outside the cell's boundaries
|
||||
enclose_area( Instance );
|
||||
@@ -438,6 +445,18 @@ basic_cell::erase( TAnimModel *Instance ) {
|
||||
[=]( TAnimModel *instance ) {
|
||||
return instance == Instance; } ),
|
||||
std::end( m_instancesopaque ) );
|
||||
// also remove from the per-pModel instance bucket if present
|
||||
if( Instance->m_instanceable && Instance->Model() != nullptr ) {
|
||||
auto bucket = m_instancebuckets_opaque.find( Instance->Model() );
|
||||
if( bucket != m_instancebuckets_opaque.end() ) {
|
||||
bucket->second.erase(
|
||||
std::remove( std::begin( bucket->second ), std::end( bucket->second ), Instance ),
|
||||
std::end( bucket->second ) );
|
||||
if( bucket->second.empty() ) {
|
||||
m_instancebuckets_opaque.erase( bucket );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: update cell bounding area
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <array>
|
||||
#include <stack>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
#include "utilities/parser.h"
|
||||
@@ -179,6 +180,7 @@ public:
|
||||
using linesnode_sequence = std::vector<lines_node>;
|
||||
using traction_sequence = std::vector<TTraction *>;
|
||||
using instance_sequence = std::vector<TAnimModel *>;
|
||||
using instance_bucket_map = std::unordered_map< TModel3d *, std::vector<TAnimModel *> >;
|
||||
using sound_sequence = std::vector<sound_source *>;
|
||||
using eventlauncher_sequence = std::vector<TEventLauncher *>;
|
||||
using memorycell_sequence = std::vector<TMemCell *>;
|
||||
@@ -196,6 +198,10 @@ public:
|
||||
path_sequence m_paths; // path pieces
|
||||
instance_sequence m_instancesopaque;
|
||||
instance_sequence m_instancetranslucent;
|
||||
// batched instance buckets keyed by shared TModel3d*; populated alongside
|
||||
// m_instancesopaque for nodes whose TAnimModel::m_instanceable == true.
|
||||
// The renderer uses these to amortise per-model state setup across many instances.
|
||||
instance_bucket_map m_instancebuckets_opaque;
|
||||
traction_sequence m_traction;
|
||||
sound_sequence m_sounds;
|
||||
eventlauncher_sequence m_eventlaunchers;
|
||||
|
||||
Reference in New Issue
Block a user