@@ -69,18 +69,18 @@ class CModelDrawerDataBase : public CModelDrawerDataConcept
6969
7070 void ClearPreviousDrawFlags () { for (auto object : unsortedObjects) object->previousDrawFlag = 0 ; }
7171
72- const ScopedMatricesMemAlloc& GetObjectMatricesMemAlloc (const T* o) const {
73- const auto it = matricesMemAllocs .find (const_cast <T*>(o));
74- return (it != matricesMemAllocs .end ()) ? it->second : ScopedMatricesMemAlloc ::Dummy ();
72+ const auto & GetObjectTransformMemAlloc (const T* o) const {
73+ const auto it = scTransMemAllocMap .find (const_cast <T*>(o));
74+ return (it != scTransMemAllocMap .end ()) ? it->second : ScopedTransformMemAlloc ::Dummy ();
7575 }
76- ScopedMatricesMemAlloc& GetObjectMatricesMemAlloc (const T* o) { return matricesMemAllocs [const_cast <T*>(o)]; }
76+ auto & GetObjectTransformMemAlloc (const T* o) { return scTransMemAllocMap [const_cast <T*>(o)]; }
7777private:
7878 static constexpr int MMA_SIZE0 = 2 << 16 ;
7979protected:
8080 std::array<ModelRenderContainer<T>, MODELTYPE_CNT> modelRenderers;
8181
8282 std::vector<T*> unsortedObjects;
83- std::unordered_map<T*, ScopedMatricesMemAlloc> matricesMemAllocs ;
83+ std::unordered_map<T*, ScopedTransformMemAlloc> scTransMemAllocMap ;
8484
8585 bool & mtModelDrawer;
8686};
@@ -100,15 +100,15 @@ inline CModelDrawerDataBase<T>::CModelDrawerDataBase(const std::string& ecName,
100100 : CModelDrawerDataConcept(ecName, ecOrder)
101101 , mtModelDrawer(mtModelDrawer_)
102102{
103- matricesMemAllocs .reserve (MMA_SIZE0);
103+ scTransMemAllocMap .reserve (MMA_SIZE0);
104104 for (auto & mr : modelRenderers) { mr.Clear (); }
105105}
106106
107107template <typename T>
108108inline CModelDrawerDataBase<T>::~CModelDrawerDataBase ()
109109{
110110 unsortedObjects.clear ();
111- matricesMemAllocs .clear ();
111+ scTransMemAllocMap .clear ();
112112}
113113
114114template <typename T>
@@ -126,9 +126,9 @@ inline void CModelDrawerDataBase<T>::AddObject(const T* co, bool add)
126126 unsortedObjects.emplace_back (o);
127127
128128 const uint32_t numMatrices = (o->model ? o->model ->numPieces : 0 ) + 1u ;
129- matricesMemAllocs .emplace (o, ScopedMatricesMemAlloc (numMatrices));
129+ scTransMemAllocMap .emplace (o, ScopedTransformMemAlloc (numMatrices));
130130
131- modelsUniformsStorage. GetObjOffset (co);
131+ modelUniformsStorage. AddObject (co);
132132}
133133
134134template <typename T>
@@ -141,8 +141,8 @@ inline void CModelDrawerDataBase<T>::DelObject(const T* co, bool del)
141141 }
142142
143143 if (del && spring::VectorErase (unsortedObjects, o)) {
144- matricesMemAllocs .erase (o);
145- modelsUniformsStorage. GetObjOffset (co);
144+ scTransMemAllocMap .erase (o);
145+ modelUniformsStorage. DelObject (co);
146146 }
147147}
148148
@@ -157,15 +157,13 @@ inline void CModelDrawerDataBase<T>::UpdateObject(const T* co, bool init)
157157template <typename T>
158158inline void CModelDrawerDataBase<T>::UpdateObjectSMMA(const T* o)
159159{
160- ScopedMatricesMemAlloc & smma = GetObjectMatricesMemAlloc (o);
160+ ScopedTransformMemAlloc & smma = GetObjectTransformMemAlloc (o);
161161
162- const auto tmNew = o->GetTransformMatrix ();
163- const auto & tmOld = const_cast <const ScopedMatricesMemAlloc&>(smma)[0 ];
162+ const auto tmNew = Transform::FromMatrix (o->GetTransformMatrix ());
164163
165164 // from one point it doesn't worth the comparison, cause units usually move
166- // but having not updated smma[0] allows for longer solid no-update areas in ModelsUniformsUploader::UpdateDerived()
167- if (tmNew != tmOld)
168- smma[0 ] = tmNew;
165+ // but having not updated smma[0] allows for longer solid no-update areas in ModelUniformsUploader::UpdateDerived()
166+ smma.UpdateIfChanged (0 , tmNew);
169167
170168 for (int i = 0 ; i < o->localModel .pieces .size (); ++i) {
171169 const LocalModelPiece& lmp = o->localModel .pieces [i];
@@ -175,22 +173,25 @@ inline void CModelDrawerDataBase<T>::UpdateObjectSMMA(const T* o)
175173 continue ;
176174
177175 if unlikely (!lmp.GetScriptVisible ()) {
178- smma[i + 1 ] = CMatrix44f::Zero ();
176+ // smma[i + 1] = CMatrix44f::Zero();
177+ smma.UpdateForced (i + 1 , Transform::Zero ());
179178 continue ;
180179 }
181180
182- smma[i + 1 ] = lmp.GetModelSpaceMatrix ();
181+ // UpdateIfChanged is not needed, wasCustomDirty takes that role
182+ smma.UpdateForced (i + 1 , lmp.GetModelSpaceTransform ());
183183 }
184184}
185185
186186template <typename T>
187187inline void CModelDrawerDataBase<T>::UpdateObjectUniforms(const T* o)
188188{
189- auto & uni = modelsUniformsStorage .GetObjUniformsArray (o);
189+ auto & uni = modelUniformsStorage .GetObjUniformsArray (o);
190190 uni.drawFlag = o->drawFlag ;
191191
192192 if (gu->spectatingFullView || o->IsInLosForAllyTeam (gu->myAllyTeam )) {
193193 uni.id = o->id ;
194+ // TODO remove drawPos, replace with pos
194195 uni.drawPos = float4{ o->drawPos , o->heading * math::PI / SPRING_MAX_HEADING };
195196 uni.speed = o->speed ;
196197 uni.maxHealth = o->maxHealth ;
0 commit comments