Browse Source

Merge pull request #444 from Hoikas/stl-ize

Nuke some hsTArray
Darryl Pogue 10 years ago
parent
commit
0ed1fd6f75
  1. 41
      Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp
  2. 7
      Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.h
  3. 155
      Sources/Plasma/PubUtilLib/plScene/plSceneNode.cpp
  4. 17
      Sources/Plasma/PubUtilLib/plScene/plSceneNode.h

41
Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp

@ -41,6 +41,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/ *==LICENSE==*/
#include "HeadSpin.h" #include "HeadSpin.h"
#include <algorithm>
#include "plPageTreeMgr.h" #include "plPageTreeMgr.h"
#include "plDrawable/plSpaceTreeMaker.h" #include "plDrawable/plSpaceTreeMaker.h"
#include "plDrawable/plSpaceTree.h" #include "plDrawable/plSpaceTree.h"
@ -85,21 +87,21 @@ void plPageTreeMgr::AddNode(plSceneNode* node)
node->Init(); node->Init();
fNodes.Append(node); fNodes.push_back(node);
} }
void plPageTreeMgr::RemoveNode(plSceneNode* node) void plPageTreeMgr::RemoveNode(plSceneNode* node)
{ {
ITrashSpaceTree(); ITrashSpaceTree();
int idx = fNodes.Find(node); auto it = std::find(fNodes.begin(), fNodes.end(), node);
if( idx != fNodes.kMissingIndex ) if (it != fNodes.end())
fNodes.Remove(idx); fNodes.erase(it);
} }
void plPageTreeMgr::Reset() void plPageTreeMgr::Reset()
{ {
fNodes.Reset(); fNodes.clear();
ITrashSpaceTree(); ITrashSpaceTree();
} }
@ -474,16 +476,13 @@ bool plPageTreeMgr::IRenderSortingSpans(plPipeline* pipe, hsTArray<plDrawVisList
bool plPageTreeMgr::IBuildSpaceTree() bool plPageTreeMgr::IBuildSpaceTree()
{ {
if( !fNodes.GetCount() ) if (fNodes.empty())
return false; return false;
plSpaceTreeMaker maker; plSpaceTreeMaker maker;
maker.Reset(); maker.Reset();
int i; for (plSceneNode* node : fNodes)
for( i = 0; i < fNodes.GetCount(); i++ ) maker.AddLeaf(node->GetSpaceTree()->GetWorldBounds(), node->GetSpaceTree()->IsEmpty());
{
maker.AddLeaf(fNodes[i]->GetSpaceTree()->GetWorldBounds(), fNodes[i]->GetSpaceTree()->IsEmpty());
}
fSpaceTree = maker.MakeTree(); fSpaceTree = maker.MakeTree();
return true; return true;
@ -491,18 +490,17 @@ bool plPageTreeMgr::IBuildSpaceTree()
bool plPageTreeMgr::IRefreshTree(plPipeline* pipe) bool plPageTreeMgr::IRefreshTree(plPipeline* pipe)
{ {
int i; for (size_t i = 0; i < fNodes.size(); ++i)
for( i = 0; i < fNodes.GetCount(); i++ )
{ {
if( fNodes[i]->GetSpaceTree()->IsDirty() ) plSceneNode* node = fNodes[i];
if (node->GetSpaceTree()->IsDirty())
{ {
fNodes[i]->GetSpaceTree()->Refresh(); node->GetSpaceTree()->Refresh();
GetSpaceTree()->MoveLeaf(i, fNodes[i]->GetSpaceTree()->GetWorldBounds()); GetSpaceTree()->MoveLeaf(i, node->GetSpaceTree()->GetWorldBounds());
if( !fNodes[i]->GetSpaceTree()->IsEmpty() && fSpaceTree->HasLeafFlag(i, plSpaceTreeNode::kDisabled) ) if (!node->GetSpaceTree()->IsEmpty() && fSpaceTree->HasLeafFlag(i, plSpaceTreeNode::kDisabled) )
fSpaceTree->SetLeafFlag(i, plSpaceTreeNode::kDisabled, false); fSpaceTree->SetLeafFlag(i, plSpaceTreeNode::kDisabled, false);
} }
} }
@ -679,11 +677,8 @@ bool plPageTreeMgr::IGetOcclusion(plPipeline* pipe, hsTArray<int16_t>& list)
fCullPolys.SetCount(0); fCullPolys.SetCount(0);
fOccluders.SetCount(0); fOccluders.SetCount(0);
int i; for (plSceneNode* node : fNodes)
for( i = 0; i < fNodes.GetCount(); i++ ) node->SubmitOccluders(this);
{
fNodes[i]->SubmitOccluders(this);
}
if( !IGetCullPolys(pipe) ) if( !IGetCullPolys(pipe) )
{ {

7
Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.h

@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plPageTreeMgr_inc #define plPageTreeMgr_inc
#include "hsTemplates.h" #include "hsTemplates.h"
#include <vector>
class plSceneNode; class plSceneNode;
class plSpaceTree; class plSpaceTree;
@ -79,7 +80,7 @@ public:
class plPageTreeMgr class plPageTreeMgr
{ {
protected: protected:
hsTArray<plSceneNode*> fNodes; std::vector<plSceneNode*> fNodes;
plSpaceTree* fSpaceTree; plSpaceTree* fSpaceTree;
plVisMgr* fVisMgr; plVisMgr* fVisMgr;
@ -108,12 +109,12 @@ public:
plPageTreeMgr(); plPageTreeMgr();
virtual ~plPageTreeMgr(); virtual ~plPageTreeMgr();
const hsTArray<plSceneNode*>& GetNodes() const { return fNodes; } const std::vector<plSceneNode*>& GetNodes() const { return fNodes; }
void AddNode(plSceneNode* node); void AddNode(plSceneNode* node);
void RemoveNode(plSceneNode* node); void RemoveNode(plSceneNode* node);
virtual void Reset(); // remove all nodes, nuke the space tree virtual void Reset(); // remove all nodes, nuke the space tree
virtual bool Empty() const { return !fNodes.GetCount(); } virtual bool Empty() const { return fNodes.empty(); }
virtual int Render(plPipeline* pipe); virtual int Render(plPipeline* pipe);

155
Sources/Plasma/PubUtilLib/plScene/plSceneNode.cpp

@ -42,6 +42,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include <algorithm>
#include "plSceneNode.h" #include "plSceneNode.h"
#include "pnDispatch/plDispatch.h" #include "pnDispatch/plDispatch.h"
#include "plMessage/plNodeCleanupMsg.h" #include "plMessage/plNodeCleanupMsg.h"
@ -100,7 +102,7 @@ void plSceneNode::Read(hsStream* s, hsResMgr* mgr)
int i; int i;
n = s->ReadLE32(); n = s->ReadLE32();
fSceneObjects.Reset(); fSceneObjects.clear();
for( i = 0; i < n; i++ ) for( i = 0; i < n; i++ )
{ {
plNodeRefMsg* refMsg = new plNodeRefMsg(GetKey(), plRefMsg::kOnCreate, i, plNodeRefMsg::kObject); plNodeRefMsg* refMsg = new plNodeRefMsg(GetKey(), plRefMsg::kOnCreate, i, plNodeRefMsg::kObject);
@ -108,7 +110,7 @@ void plSceneNode::Read(hsStream* s, hsResMgr* mgr)
} }
n = s->ReadLE32(); n = s->ReadLE32();
fGenericPool.Reset(); fGenericPool.clear();
for( i = 0; i < n; i++ ) for( i = 0; i < n; i++ )
{ {
plNodeRefMsg* refMsg = new plNodeRefMsg(GetKey(), plRefMsg::kOnCreate, -1, plNodeRefMsg::kGeneric); plNodeRefMsg* refMsg = new plNodeRefMsg(GetKey(), plRefMsg::kOnCreate, -1, plNodeRefMsg::kGeneric);
@ -122,12 +124,12 @@ void plSceneNode::Write(hsStream* s, hsResMgr* mgr)
int i; int i;
s->WriteLE32(fSceneObjects.GetCount()); s->WriteLE32(fSceneObjects.size());
for( i = 0; i < fSceneObjects.GetCount(); i++ ) for( i = 0; i < fSceneObjects.size(); i++ )
mgr->WriteKey(s,fSceneObjects[i]); mgr->WriteKey(s,fSceneObjects[i]);
s->WriteLE32(fGenericPool.GetCount()); s->WriteLE32(fGenericPool.size());
for( i = 0; i < fGenericPool.GetCount(); i++ ) for( i = 0; i < fGenericPool.size(); i++ )
mgr->WriteKey(s, fGenericPool[i]); mgr->WriteKey(s, fGenericPool[i]);
} }
@ -189,7 +191,7 @@ plSpaceTree* plSceneNode::IBuildSpaceTree()
bnd.Reset(&zero); bnd.Reset(&zero);
int i; int i;
for( i = 0; i < fDrawPool.GetCount(); i++ ) for( i = 0; i < fDrawPool.size(); i++ )
{ {
if( fDrawPool[i] ) if( fDrawPool[i] )
maker.AddLeaf(fDrawPool[i]->GetSpaceTree()->GetWorldBounds()); maker.AddLeaf(fDrawPool[i]->GetSpaceTree()->GetWorldBounds());
@ -211,23 +213,21 @@ plSpaceTree* plSceneNode::ITrashSpaceTree()
void plSceneNode::IDirtySpaceTree() void plSceneNode::IDirtySpaceTree()
{ {
int i; for (size_t i = 0; i < fDrawPool.size(); ++i)
for( i = 0; i < fDrawPool.GetCount(); i++ )
{ {
if( fDrawPool[i] && fDrawPool[i]->GetSpaceTree()->IsDirty() ) plDrawable* drawable = fDrawPool[i];
if (drawable && drawable->GetSpaceTree()->IsDirty() )
{ {
fDrawPool[i]->GetSpaceTree()->Refresh(); drawable->GetSpaceTree()->Refresh();
fSpaceTree->MoveLeaf(i, fDrawPool[i]->GetSpaceTree()->GetWorldBounds()); fSpaceTree->MoveLeaf(i, drawable->GetSpaceTree()->GetWorldBounds());
} }
} }
} }
plSpaceTree* plSceneNode::GetSpaceTree() plSpaceTree* plSceneNode::GetSpaceTree()
{ {
if( !fSpaceTree ) if (!fSpaceTree)
{
IBuildSpaceTree(); IBuildSpaceTree();
}
IDirtySpaceTree(); IDirtySpaceTree();
return fSpaceTree; return fSpaceTree;
} }
@ -237,12 +237,10 @@ void plSceneNode::ISetDrawable(plDrawable* d)
if( !d ) if( !d )
return; return;
if (fDrawPool.Find(d) == fDrawPool.kMissingIndex) if (std::find(fDrawPool.begin(), fDrawPool.end(), d) == fDrawPool.end()) {
{ fDrawPool.push_back(d);
fDrawPool.Append(d); ITrashSpaceTree();
} }
ITrashSpaceTree();
} }
void plSceneNode::ISetAudible(plAudible* a) void plSceneNode::ISetAudible(plAudible* a)
@ -250,10 +248,8 @@ void plSceneNode::ISetAudible(plAudible* a)
if( !a ) if( !a )
return; return;
if( fAudioPool.kMissingIndex == fAudioPool.Find(a) ) if (std::find(fAudioPool.begin(), fAudioPool.end(), a) == fAudioPool.end())
{ fAudioPool.push_back(a);
fAudioPool.Append(a);
}
} }
void plSceneNode::ISetPhysical(plPhysical* p) void plSceneNode::ISetPhysical(plPhysical* p)
@ -261,31 +257,29 @@ void plSceneNode::ISetPhysical(plPhysical* p)
if( !p ) if( !p )
return; return;
if( fSimulationPool.kMissingIndex == fSimulationPool.Find(p) ) if (std::find(fSimulationPool.begin(), fSimulationPool.end(), p) == fSimulationPool.end())
{ fSimulationPool.push_back(p);
fSimulationPool.Append(p);
}
} }
void plSceneNode::ISetObject(plSceneObject* o) void plSceneNode::ISetObject(plSceneObject* o)
{ {
if( o && (fSceneObjects.kMissingIndex == fSceneObjects.Find(o)) ) if (!o)
{ return;
fSceneObjects.Append(o);
if (std::find(fSceneObjects.begin(), fSceneObjects.end(), o) == fSceneObjects.end())
fSceneObjects.push_back(o);
// MF_NET_GROUPS_TEST // MF_NET_GROUPS_TEST
// This will have no effect on members of NetGroupConstants // This will have no effect on members of NetGroupConstants
o->SetNetGroup(o->SelectNetGroup(GetKey())); o->SetNetGroup(o->SelectNetGroup(GetKey()));
o->SetSceneNode(GetKey()); o->SetSceneNode(GetKey());
}
} }
void plSceneNode::ISetLight(plLightInfo* l) void plSceneNode::ISetLight(plLightInfo* l)
{ {
if( fLightPool.kMissingIndex == fLightPool.Find(l) ) if (std::find(fLightPool.begin(), fLightPool.end(), l) == fLightPool.end())
fLightPool.Append( l ); fLightPool.push_back(l);
} }
void plSceneNode::ISetOccluder(plOccluder* o) void plSceneNode::ISetOccluder(plOccluder* o)
@ -298,25 +292,24 @@ void plSceneNode::ISetOccluder(plOccluder* o)
void plSceneNode::ISetGeneric(hsKeyedObject* k) void plSceneNode::ISetGeneric(hsKeyedObject* k)
{ {
if( fGenericPool.kMissingIndex == fGenericPool.Find(k) ) if (std::find(fGenericPool.begin(), fGenericPool.end(), k) == fGenericPool.end())
fGenericPool.Append(k); fGenericPool.push_back(k);
} }
void plSceneNode::IRemoveDrawable(plDrawable* d) void plSceneNode::IRemoveDrawable(plDrawable* d)
{ {
int idx = fDrawPool.Find(d); auto it = std::find(fDrawPool.begin(), fDrawPool.end(), d);
if( idx != fDrawPool.kMissingIndex ) if (it != fDrawPool.end()) {
fDrawPool.Remove(idx); fDrawPool.erase(it);
ITrashSpaceTree();
ITrashSpaceTree(); }
} }
void plSceneNode::IRemoveAudible(plAudible* a) void plSceneNode::IRemoveAudible(plAudible* a)
{ {
int idx = fAudioPool.Find(a); auto it = std::find(fAudioPool.begin(), fAudioPool.end(), a);
if( idx != fAudioPool.kMissingIndex ) if (it != fAudioPool.end())
fAudioPool.Remove(idx); fAudioPool.erase(it);
} }
void plSceneNode::IRemovePhysical(plPhysical* p) void plSceneNode::IRemovePhysical(plPhysical* p)
@ -337,27 +330,25 @@ void plSceneNode::IRemovePhysical(plPhysical* p)
} }
#endif #endif
int idx = fSimulationPool.Find(p); auto it = std::find(fSimulationPool.begin(), fSimulationPool.end(), p);
if( idx != fSimulationPool.kMissingIndex ) if (it != fSimulationPool.end())
fSimulationPool.Remove(idx); fSimulationPool.erase(it);
} }
void plSceneNode::IRemoveObject(plSceneObject* o) void plSceneNode::IRemoveObject(plSceneObject* o)
{ {
int idx = fSceneObjects.Find(o); auto it = std::find(fSceneObjects.begin(), fSceneObjects.end(), o);
if( idx != fSceneObjects.kMissingIndex ) if (it != fSceneObjects.end())
fSceneObjects.Remove(idx); fSceneObjects.erase(it);
} }
void plSceneNode::IRemoveLight(plLightInfo* l) void plSceneNode::IRemoveLight(plLightInfo* l)
{ {
hsAssert(l, "Removing nil light"); hsAssert(l, "Removing nil light");
int idx = fLightPool.Find(l); auto it = std::find(fLightPool.begin(), fLightPool.end(), l);
if( idx != fLightPool.kMissingIndex ) if (it != fLightPool.end())
{ fLightPool.erase(it);
fLightPool.Remove(idx);
}
} }
void plSceneNode::IRemoveOccluder(plOccluder* o) void plSceneNode::IRemoveOccluder(plOccluder* o)
@ -369,9 +360,9 @@ void plSceneNode::IRemoveOccluder(plOccluder* o)
void plSceneNode::IRemoveGeneric(hsKeyedObject* k) void plSceneNode::IRemoveGeneric(hsKeyedObject* k)
{ {
int idx = fGenericPool.Find(k); auto it = std::find(fGenericPool.begin(), fGenericPool.end(), k);
if( idx != fGenericPool.kMissingIndex ) if (it != fGenericPool.end())
fGenericPool.Remove(idx); fGenericPool.erase(it);
} }
bool plSceneNode::IOnRemove(plNodeRefMsg* refMsg) bool plSceneNode::IOnRemove(plNodeRefMsg* refMsg)
@ -466,26 +457,24 @@ bool plSceneNode::MsgReceive(plMessage* msg)
void plSceneNode::ICleanUp( void ) void plSceneNode::ICleanUp( void )
{ {
int i;
/// Go find drawables to delete /// Go find drawables to delete
for( i = 0; i < fDrawPool.GetCount(); i++ ) for (auto draw : fDrawPool)
fDrawPool[ i ]->Optimize(); draw->Optimize();
if (fFilterGenerics) if (fFilterGenerics)
{ {
for( i = fSceneObjects.GetCount() - 1; i >= 0; i--) ssize_t i;
for ( i = fSceneObjects.size() - 1; i >= 0; i--)
GetKey()->Release(fSceneObjects[i]->GetKey()); GetKey()->Release(fSceneObjects[i]->GetKey());
for( i = fDrawPool.GetCount() - 1; i >= 0; i--) for ( i = fDrawPool.size() - 1; i >= 0; i--)
GetKey()->Release(fDrawPool[i]->GetKey()); GetKey()->Release(fDrawPool[i]->GetKey());
for( i = fSimulationPool.GetCount() - 1; i >= 0; i--) for ( i = fSimulationPool.size() - 1; i >= 0; i--)
GetKey()->Release(fSimulationPool[i]->GetKey()); GetKey()->Release(fSimulationPool[i]->GetKey());
for( i = fAudioPool.GetCount() - 1; i >= 0; i--) for ( i = fAudioPool.size() - 1; i >= 0; i--)
GetKey()->Release(fAudioPool[i]->GetKey()); GetKey()->Release(fAudioPool[i]->GetKey());
for( i = fOccluders.GetCount() - 1; i >= 0; i--) for ( i = fOccluders.GetCount() - 1; i >= 0; i--)
GetKey()->Release(fOccluders[i]->GetKey()); GetKey()->Release(fOccluders[i]->GetKey());
for( i = fLightPool.GetCount() - 1; i >= 0; i--) for ( i = fLightPool.size() - 1; i >= 0; i--)
GetKey()->Release(fLightPool[i]->GetKey()); GetKey()->Release(fLightPool[i]->GetKey());
} }
@ -497,16 +486,11 @@ void plSceneNode::ICleanUp( void )
plDrawable *plSceneNode::GetMatchingDrawable( const plDrawableCriteria& crit ) plDrawable *plSceneNode::GetMatchingDrawable( const plDrawableCriteria& crit )
{ {
int i; for (auto draw : fDrawPool) {
if (draw->DoIMatch(crit))
return draw;
for( i = 0; i < fDrawPool.GetCount(); i++ )
{
if( fDrawPool[ i ]->DoIMatch( crit ) )
return fDrawPool[ i ];
} }
return nullptr;
return nil;
} }
//// OptimizeDrawables /////////////////////////////////////////////////////// //// OptimizeDrawables ///////////////////////////////////////////////////////
@ -515,10 +499,7 @@ plDrawable *plSceneNode::GetMatchingDrawable( const plDrawableCriteria& crit )
void plSceneNode::OptimizeDrawables( void ) void plSceneNode::OptimizeDrawables( void )
{ {
int i; for (auto draw : fDrawPool)
draw->Optimize();
for( i = 0; i < fDrawPool.GetCount(); i++ )
fDrawPool[ i ]->Optimize();
} }

17
Sources/Plasma/PubUtilLib/plScene/plSceneNode.h

@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnKeyedObject/hsKeyedObject.h" #include "pnKeyedObject/hsKeyedObject.h"
#include "hsTemplates.h" #include "hsTemplates.h"
#include <vector>
class plSceneObject; class plSceneObject;
@ -76,17 +77,17 @@ protected:
int16_t fDepth; int16_t fDepth;
hsTArray<plSceneObject*> fSceneObjects; std::vector<plSceneObject*> fSceneObjects;
hsTArray<plDrawable*> fDrawPool; std::vector<plDrawable*> fDrawPool;
hsTArray<plPhysical*> fSimulationPool; std::vector<plPhysical*> fSimulationPool;
hsTArray<plAudible*> fAudioPool; std::vector<plAudible*> fAudioPool;
hsTArray<plOccluder*> fOccluders; hsTArray<plOccluder*> fOccluders;
hsTArray<plLightInfo*> fLightPool; std::vector<plLightInfo*> fLightPool;
hsTArray<hsKeyedObject*> fGenericPool; std::vector<hsKeyedObject*> fGenericPool;
plSpaceTree* fSpaceTree; plSpaceTree* fSpaceTree;
@ -149,7 +150,7 @@ public:
void SetFilterGenericsOnly(bool b) { fFilterGenerics = b; } void SetFilterGenericsOnly(bool b) { fFilterGenerics = b; }
const hsTArray<plDrawable*>& GetDrawPool() const { return fDrawPool; } const std::vector<plDrawable*>& GetDrawPool() const { return fDrawPool; }
}; };
#endif // plSceneNode_inc #endif // plSceneNode_inc

Loading…
Cancel
Save