From: <mg...@us...> - 2008-12-24 00:47:32
|
Revision: 2759 http://planeshift.svn.sourceforge.net/planeshift/?rev=2759&view=rev Author: mgist Date: 2008-12-24 00:47:29 +0000 (Wed, 24 Dec 2008) Log Message: ----------- - Added attribute for meshes which should always be loaded while the sector is loaded. Modified Paths: -------------- trunk/src/common/engine/loader.cpp trunk/src/common/engine/loader.h Modified: trunk/src/common/engine/loader.cpp =================================================================== --- trunk/src/common/engine/loader.cpp 2008-12-23 21:35:57 UTC (rev 2758) +++ trunk/src/common/engine/loader.cpp 2008-12-24 00:47:29 UTC (rev 2759) @@ -307,6 +307,12 @@ csRef<MeshObj> m = csPtr<MeshObj>(new MeshObj(node2->GetAttributeValue("name"), node2)); m->sector = s; + if(node2->GetAttributeValueAsBool("alwaysloaded")) + { + ++s->alwaysLoadedCount; + m->alwaysLoaded = true; + } + if(node2->GetNode("move")) { node2 = node2->GetNode("move")->GetNode("v"); @@ -706,14 +712,14 @@ { if(!sector->meshes[i]->loading) { - if(!sector->meshes[i]->object.IsValid() && csVector3(sector->meshes[i]->pos - pos).Norm() <= loadRange) + if(sector->meshes[i]->InRange(pos)) { sector->meshes[i]->loading = true; loadingMeshes.Push(sector->meshes[i]); LoadMesh(sector->meshes[i]); ++sector->objectCount; } - else if(sector->meshes[i]->object.IsValid() && csVector3(sector->meshes[i]->pos - pos).Norm() > loadRange*1.5) + else if(sector->meshes[i]->OutOfRange(pos)) { sector->meshes[i]->object->GetMovable()->ClearSectors(); sector->meshes[i]->object->GetMovable()->UpdateMove(); @@ -726,7 +732,7 @@ for(size_t i=0; i<sector->portals.GetSize(); i++) { - if(!sector->portals[i]->mObject.IsValid() && sector->portals[i]->InRange(pos)) + if(sector->portals[i]->InRange(pos)) { if(!sector->portals[i]->targetSector->isLoading) { @@ -760,7 +766,7 @@ sector->activePortals.Push(sector->portals[i]); ++sector->objectCount; } - else if(sector->portals[i]->mObject.IsValid() && sector->portals[i]->OutOfRange(pos)) + else if(sector->portals[i]->OutOfRange(pos)) { if(!sector->portals[i]->targetSector->isLoading) { @@ -794,8 +800,20 @@ } } - if(sector->objectCount == 0 && sector->object.IsValid()) + if(sector->objectCount == sector->alwaysLoadedCount && sector->object.IsValid()) { + for(size_t i=0; i<sector->meshes.GetSize(); i++) + { + if(sector->meshes[i]->alwaysLoaded) + { + sector->meshes[i]->object->GetMovable()->ClearSectors(); + sector->meshes[i]->object->GetMovable()->UpdateMove(); + engine->GetMeshes()->Remove(sector->meshes[i]->object); + sector->meshes[i]->object.Invalidate(); + --sector->objectCount; + } + } + engine->GetSectors()->Remove(sector->object); sector->object.Invalidate(); } Modified: trunk/src/common/engine/loader.h =================================================================== --- trunk/src/common/engine/loader.h 2008-12-23 21:35:57 UTC (rev 2758) +++ trunk/src/common/engine/loader.h 2008-12-24 00:47:29 UTC (rev 2759) @@ -179,7 +179,7 @@ class Sector : public CS::Utility::FastRefCount<Sector> { public: - Sector(const char* name) : name(name), isLoading(false), objectCount(0) + Sector(const char* name) : name(name), isLoading(false), objectCount(0), alwaysLoadedCount(0) { ambient = csColor(0.0f); } @@ -189,6 +189,7 @@ csString culler; csColor ambient; size_t objectCount; + size_t alwaysLoadedCount; csRef<iSector> object; csRefArray<MeshObj> meshes; csRefArray<Portal> portals; @@ -199,15 +200,27 @@ class MeshObj : public CS::Utility::FastRefCount<MeshObj> { public: - MeshObj(const char* name, iDocumentNode* data) : name(name), data(data), loading(false) + MeshObj(const char* name, iDocumentNode* data) : name(name), data(data), + loading(false), alwaysLoaded(false) { } + bool InRange(const csVector3& curpos) + { + return !object.IsValid() && (alwaysLoaded || csVector3(pos - curpos).Norm() <= Loader::GetSingleton().loadRange); + } + + bool OutOfRange(const csVector3& curpos) + { + return !alwaysLoaded && object.IsValid() && csVector3(pos - curpos).Norm() > Loader::GetSingleton().loadRange*1.5; + } + csString name; csRef<iDocumentNode> data; csVector3 pos; bool loading; + bool alwaysLoaded; csRef<iThreadReturn> status; csRef<iMeshWrapper> object; csRefArray<Texture> textures; @@ -225,6 +238,11 @@ bool InRange(const csVector3& pos) { + if(mObject.IsValid()) + { + return false; + } + for(size_t i=0; i<poly.GetVertexCount(); i++) { if(csVector3(poly.GetVertices()[i] - pos).Norm() <= Loader::GetSingleton().loadRange) @@ -238,6 +256,11 @@ bool OutOfRange(const csVector3& pos) { + if(!mObject.IsValid()) + { + return false; + } + for(size_t i=0; i<poly.GetVertexCount(); i++) { if(csVector3(poly.GetVertices()[i] - pos).Norm() <= Loader::GetSingleton().loadRange*1.5) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |