23 #include <csgeom/poly3d.h> 24 #include <csgfx/shadervar.h> 25 #include <csutil/scf_implementation.h> 26 #include <csutil/hash.h> 27 #include <csutil/threading/rwmutex.h> 28 #include <csutil/threadmanager.h> 29 #include <csutil/refcount.h> 30 #include <csutil/typetraits.h> 32 #include <iengine/engine.h> 33 #include <iengine/material.h> 34 #include <iengine/mesh.h> 35 #include <iengine/meshgen.h> 36 #include <iengine/sector.h> 37 #include <iengine/texture.h> 38 #include <iengine/movable.h> 39 #include <imesh/object.h> 40 #include <imesh/objmodel.h> 41 #include <imap/loader.h> 42 #include <iutil/objreg.h> 43 #include <iutil/vfs.h> 45 #include <ibgloader.h> 46 #include <iscenemanipulate.h> 49 #define LOADER_DEBUG_MESSAGE(...) csPrintf(__VA_ARGS__) 51 #define LOADER_DEBUG_MESSAGE(...) 56 #define CS_ASSERT_MSG(msg, x) if(!(x)) printf("ART ERROR: %s\n", msg) 59 struct iCollideSystem;
60 struct iEngineSequenceManager;
61 struct iSyntaxService;
69 extern const char texture[8];
70 extern const char material[9];
71 extern const char trigger[8];
72 extern const char sequence[9];
73 extern const char meshobj[5];
74 extern const char meshfact[13];
75 extern const char meshgen[8];
76 extern const char light[6];
77 extern const char portal[7];
78 extern const char sector[7];
99 struct iDelayedLoader;
108 bool Initialize(iObjectRegistry* _object_reg);
113 csPtr<iThreadReturn> LoadMaterial(
const char* name,
bool wait =
false);
118 csPtr<iThreadReturn> LoadFactory(
const char* name,
bool wait =
false);
128 void CloneFactory(
const char* name,
const char* newName,
bool* failed = NULL,
const csReversibleTransform& trans = csReversibleTransform());
136 THREADED_CALLABLE_DECL1(BgLoader, PrecacheData, csThreadReturn,
const char*, path, THREADEDL,
false,
false);
142 void ClearTemporaryData()
144 parserData.xmltokens.Empty();
145 parserData.textures.Clear();
146 parserData.meshes.Clear();
147 parserData.svstrings.Invalidate();
148 parserData.syntaxService.Invalidate();
160 void UpdatePosition(
const csVector3& pos,
const char* sectorName,
bool force);
172 void ContinueLoading(
bool waiting);
177 iThreadedLoader* GetLoader() {
return tloader; }
182 size_t GetLoadingCount() {
return loadList.GetSize(); }
187 iObjectRegistry* GetObjectRegistry()
const {
return object_reg; }
192 void SetLoadRange(
float r) { loadRange = r;
if (lastSector.IsValid()) UpdatePosition(lastPos, lastSector->GetName(),
true); }
198 bool HasValidPosition()
const {
return validPosition; }
206 bool InWaterArea(
const char* sector, csVector3* pos, csColor4** colour);
211 bool LoadZones(iStringArray* regions,
bool priority =
false);
217 bool LoadPriorityZones(iStringArray* regions);
224 csPtr<iStringArray> GetShaderName(
const char* usageType);
233 iMeshWrapper* CreateAndSelectMesh(
const char* factName,
const char* matName,
234 iCamera* camera,
const csVector2& pos);
241 iMeshWrapper* SelectMesh(iCamera* camera,
const csVector2& pos);
250 bool TranslateSelected(
bool vertical, iCamera* camera,
const csVector2& pos);
256 void RotateSelected(
const csVector2& pos);
264 void SetRotation(
int flags_h,
int flags_v);
269 void SetPosition(
const csVector2& pos) { previousPosition = pos; };
274 void RemoveSelected();
276 void GetPosition(csVector3 & pos, csVector3 & rot,
const csVector2& screenPos);
281 csRefArray<StartPosition> GetStartPositions()
283 csRefArray<StartPosition> array;
284 CS::Threading::ScopedReadLock lock(parserData.positions.lock);
285 LockedType<StartPosition>::HashType::GlobalIterator it(parserData.positions.hash.GetIterator());
288 array.Push(it.Next());
294 iEngine* GetEngine()
const 310 iThreadedLoader* GetLoader()
const 315 iCollideSystem* GetCDSys()
const 321 void RegisterPendingObject(Loadable* obj)
323 CS::Threading::RecursiveMutexScopedLock lock(loadLock);
328 void UnregisterPendingObject(Loadable* obj)
330 CS::Threading::RecursiveMutexScopedLock lock(loadLock);
331 size_t index = loadList.Find(obj);
334 if(index <= loadOffset)
338 loadList.DeleteIndex(index);
342 void RegisterDelayedLoader(iDelayedLoader* loader)
344 CS::Threading::RecursiveMutexScopedLock lock(loadLock);
345 delayedLoadList.Push(loader);
348 void UnregisterDelayedLoader(iDelayedLoader* loader)
350 CS::Threading::RecursiveMutexScopedLock lock(loadLock);
351 size_t index = delayedLoadList.Find(loader);
354 if(index <= delayedOffset)
358 delayedLoadList.DeleteIndex(index);
365 useLowestShaders = 0x1,
366 useLowShaders = 0x2 | useLowestShaders,
367 useMediumShaders = 0x4 | useLowShaders,
368 useHighShaders = 0x8 | useMediumShaders,
369 useHighestShaders = 0x10 | useHighShaders,
372 useAll = (useHighestShaders | useShadows | useMeshGen)
387 struct GlobalParserData;
392 template<
typename T>
struct CheckedLoad
397 CheckedLoad(
const csRef<T>& obj) : obj(obj), checked(
false)
401 CheckedLoad(
const CheckedLoad& other) : obj(other.obj), checked(
false)
409 template<
typename T,
bool check = true>
struct LockedType
412 typedef csHash<csRef<T>, csStringID> HashType;
414 csStringSet stringSet;
415 CS::Threading::ReadWriteMutex lock;
417 csPtr<T> Get(
const char* name)
420 CS::Threading::ScopedReadLock scopedLock(lock);
421 if(stringSet.Contains(name))
423 csStringID objectID = stringSet.Request(name);
424 object = hash.Get(objectID, csRef<T>());
426 return csPtr<T>(object);
430 void Put(
const csRef<T>& obj)
435 void Put(
const csRef<T>& obj,
const char* name)
437 CS::Threading::ScopedWriteLock scopedLock(lock);
441 objectID = stringSet.Request(name);
445 objectID = stringSet.Request(obj->GetName());
449 if(check && hash.Contains(objectID))
455 hash.Put(objectID, obj);
459 void Delete(
const char* name)
461 CS::Threading::ScopedWriteLock scopedLock(lock);
462 if(stringSet.Contains(name))
464 csStringID
id = stringSet.Request(name);
466 stringSet.Delete(
id);
483 inline bool InRange(
const csBox3& curBBox)
const 485 return curBBox.Overlap(bbox);
488 inline bool OutOfRange(
const csBox3& curBBox)
const 490 return !curBBox.Overlap(bbox);
498 inline bool InRange(
const csBox3& )
const 503 inline bool OutOfRange(
const csBox3& )
const 512 class Loadable :
public csObject
515 Loadable(BgLoader* parent) : parent(parent),
516 loading(
false), useCount(0)
520 Loadable(
const Loadable& other) : csObject(0), parent(other.parent),
521 loading(
false), useCount(0)
523 SetName(other.GetName());
533 bool Load(
bool wait =
false)
535 CS::Threading::RecursiveMutexScopedLock lock(busy);
544 GetParent()->RegisterPendingObject(
this);
551 GetParent()->UnregisterPendingObject(
this);
567 CS::Threading::RecursiveMutexScopedLock lock(busy);
579 GetParent()->UnregisterPendingObject(
this);
585 CS::Threading::RecursiveMutexScopedLock lock(busy);
592 CS_ASSERT_MSG(
"unloading currently loading object!", !loading);
601 virtual bool LoadObject(
bool wait) = 0;
602 virtual void UnloadObject() = 0;
603 virtual void FinishObject() {}
605 bool IsLoaded()
const 607 CS::Threading::RecursiveMutexScopedLock lock(busy);
611 inline BgLoader* GetParent()
const 618 CS::Threading::RecursiveMutexScopedLock lock(busy);
622 bool IsChecked()
const 624 CS::Threading::RecursiveMutexScopedLock lock(busy);
628 size_t GetLingerCount()
const 630 CS::Threading::RecursiveMutexScopedLock lock(busy);
634 void IncLingerCount()
636 CS::Threading::RecursiveMutexScopedLock lock(busy);
643 CS::Threading::RecursiveMutexScopedLock lock(busy);
647 template<
typename T, const
char* TypeName>
void CheckRemove(csRef<T>& ref)
651 csWeakRef<T> check(ref);
652 parent->GetEngine()->RemoveObject(ref);
662 mutable CS::Threading::RecursiveMutex busy;
671 struct iDelayedLoader :
public iThreadReturn
673 virtual void ContinueLoading(
bool wait) = 0;
680 target(target), finished(
false),
681 waitLock(0), waitCondition(0)
686 BgLoader* parent = target->GetParent();
687 parent->RegisterDelayedLoader(
this);
697 if(!target.IsValid())
713 BgLoader* parent = target->GetParent();
714 parent->UnregisterDelayedLoader(
this);
722 void ContinueLoading(
bool wait)
724 CS::Threading::MutexScopedLock lock(busy);
725 if(target.IsValid() && !finished && target->Load(wait))
730 BgLoader* parent = target->GetParent();
731 parent->UnregisterDelayedLoader(
this);
733 if(waitLock) waitLock->Lock();
737 csRef<typename T::ObjectType> ref = target->GetObject();
743 waitCondition->NotifyAll();
746 if(waitLock) waitLock->Unlock();
752 ContinueLoading(
true);
757 CS::Threading::MutexScopedLock lock(busy);
761 csRef<iBase> GetResultRefPtr()
763 CS::Threading::MutexScopedLock lock(busy);
769 CS::Threading::MutexScopedLock lock(busy);
775 CS::Threading::MutexScopedLock lock(busy);
776 return result.IsValid();
779 void SetWaitPtrs(CS::Threading::Condition* c, CS::Threading::Mutex* m)
781 CS::Threading::MutexScopedLock lock(busy);
787 void SetJob(iJob* newJob)
800 void MarkSuccessful() {}
801 void MarkFinished() {}
802 void SetResult(csRef<iBase> ) {}
803 void SetResult(
void* ) {}
804 void Copy(iThreadReturn* ) {}
807 CS::Threading::Mutex busy;
813 CS::Threading::Mutex* waitLock;
814 CS::Threading::Condition* waitCondition;
819 template<
typename T, const
char* TypeName>
class TrivialLoadable :
public Loadable
822 typedef T ObjectType;
824 TrivialLoadable(BgLoader* parent) : Loadable(parent)
828 TrivialLoadable(
const TrivialLoadable& other)
829 : Loadable(other.GetParent()), path(other.path),
834 bool LoadObject(
bool wait)
836 if(!status.IsValid())
843 status = GetParent()->GetLoader()->LoadNode(path, data);
851 if(status->IsFinished())
853 if(!status->WasSuccessful())
867 csRef<T> ref = GetObject();
869 Loadable::CheckRemove<T,TypeName>(ref);
874 if(status.IsValid() && status->IsFinished() && status->WasSuccessful())
876 csRef<iBase> rawObj = status->GetResultRefPtr();
879 return scfQueryInterface<T>(rawObj);
889 csRef<iDocumentNode> data;
892 csRef<iThreadReturn> status;
896 template<
typename T>
class ObjectLoader
899 typedef CheckedLoad<T> HashObjectType;
900 typedef csHash<HashObjectType, csString> HashType;
902 ObjectLoader() : objectCount(0)
906 ObjectLoader(
const ObjectLoader& other) : objectCount(0)
908 CS::Threading::RecursiveMutexScopedLock lock(other.busy);
909 typename HashType::ConstGlobalIterator it(other.objects.GetIterator());
913 HashObjectType obj(it.Next(key));
914 objects.Put(key, obj);
923 size_t GetObjectCount()
const 925 CS::Threading::RecursiveMutexScopedLock lock(busy);
932 return LoadObjects(
false);
937 bool LoadObjects(
bool wait)
939 CS::Threading::RecursiveMutexScopedLock lock(busy);
940 if(objectCount == objects.GetSize())
947 typename HashType::GlobalIterator it(objects.GetIterator());
950 HashObjectType& ref = it.Next();
953 ref.checked = ref.obj->Load(wait);
970 CS::Threading::RecursiveMutexScopedLock lock(busy);
977 typename HashType::GlobalIterator it(objects.GetIterator());
980 HashObjectType& ref = it.Next();
990 int UpdateObjects(
const csBox3& loadBox,
const csBox3& keepBox)
992 CS::Threading::RecursiveMutexScopedLock lock(busy);
993 int oldObjectCount = objectCount;
994 if(CS::Meta::IsBaseOf<RangeBased,T>::value)
996 typename HashType::GlobalIterator it(objects.GetIterator());
999 HashObjectType& ref = it.Next();
1002 if(ref.obj->OutOfRange(keepBox))
1005 ref.checked =
false;
1009 else if(ref.obj->InRange(loadBox))
1011 ref.checked = ref.obj->Load(
false);
1023 return (
int)objectCount - oldObjectCount;
1026 void AddDependency(T* obj)
1028 CS::Threading::RecursiveMutexScopedLock lock(busy);
1029 if(!objects.Contains(obj->GetName()))
1031 objects.Put(obj->GetName(), csRef<T>(obj));
1035 void RemoveDependency(
const T* obj)
1037 CS::Threading::RecursiveMutexScopedLock lock(busy);
1038 const HashObjectType& ref = objects.Get(obj->GetName(), HashObjectType(csRef<T>()));
1044 objects.DeleteAll(obj->GetName());
1048 const csRef<T>& GetDependency(
const char* name)
const 1050 return GetDependency(name, csRef<T>());
1053 const csRef<T>& GetDependency(
const char* name,
const csRef<T>& fallbackobj)
const 1055 CS::Threading::RecursiveMutexScopedLock lock(busy);
1056 const HashObjectType& ref = objects.Get(name,fallbackobj);
1060 bool HasDependency(
const char* name)
const 1062 CS::Threading::RecursiveMutexScopedLock lock(busy);
1063 return objects.Contains(name);
1066 HashType& GetDependencies()
1071 const HashType& GetDependencies()
const 1077 mutable CS::Threading::RecursiveMutex busy;
1091 class ShaderVar :
public CS::Utility::AtomicRefCount
1094 ShaderVar(BgLoader* parent, ObjectLoader<Texture>*
object) : parent(parent), object(
object)
1102 template<
bool check>
bool Parse(iDocumentNode* node, GlobalParserData& data);
1103 void LoadObject(csShaderVariable* var);
1104 CS::ShaderVarStringID GetID()
const 1110 CS::ShaderVarStringID nameID;
1111 csShaderVariable::VariableType type;
1119 ObjectLoader<Texture>* object;
1122 class Texture :
public TrivialLoadable<iTextureWrapper,ObjectNames::texture>
1125 Texture(BgLoader* parent) : TrivialLoadable<iTextureWrapper,ObjectNames::texture>(parent)
1129 bool Parse(iDocumentNode* node, ParserData& data);
1132 class Material :
public Loadable,
public ObjectLoader<Texture>
1135 typedef iMaterialWrapper ObjectType;
1137 using ObjectLoader<Texture>::AddDependency;
1139 Material(BgLoader* parent) : Loadable(parent)
1143 bool Parse(iDocumentNode* node, GlobalParserData& data);
1145 bool LoadObject(
bool wait);
1146 void UnloadObject();
1147 csPtr<iMaterialWrapper> GetObject()
1149 csRef<iMaterialWrapper> wrapper(materialWrapper);
1150 return csPtr<iMaterialWrapper>(wrapper);
1157 csRef<iShader> shader;
1160 csArray<Shader> shaders;
1161 csRefArray<ShaderVar> shadervars;
1164 csRef<iMaterialWrapper> materialWrapper;
1167 class MaterialLoader :
public ObjectLoader<Material>
1170 void ParseMaterialReference(GlobalParserData& data,
const char* name,
const char* parentName,
const char* type);
1173 class Trigger :
public ObjectLoader<Sequence>,
1174 public ObjectLoader<MeshObj>,
1175 public ObjectLoader<Light>,
1176 public TrivialLoadable<iSequenceTrigger,ObjectNames::trigger>,
1180 using ObjectLoader<Sequence>::AddDependency;
1181 using ObjectLoader<MeshObj>::AddDependency;
1182 using ObjectLoader<Light>::AddDependency;
1184 Trigger(BgLoader* parent) : TrivialLoadable<iSequenceTrigger,ObjectNames::trigger>(parent)
1188 bool LoadObject(
bool wait)
1190 bool ready = ObjectLoader<Sequence>::LoadObjects(
true);
1191 ready &= ObjectLoader<MeshObj>::LoadObjects(
true);
1192 ready &= ObjectLoader<Light>::LoadObjects(
true);
1193 ready &= TrivialLoadable<iSequenceTrigger,ObjectNames::trigger>::LoadObject(
true);
1200 TrivialLoadable<iSequenceTrigger,ObjectNames::trigger>::UnloadObject();
1201 ObjectLoader<Sequence>::UnloadObjects();
1202 ObjectLoader<MeshObj>::UnloadObjects();
1203 ObjectLoader<Light>::UnloadObjects();
1206 bool Parse(iDocumentNode* node, ParserData& data);
1209 class Sequence :
public ObjectLoader<Sequence>,
1210 public ObjectLoader<Trigger>,
1211 public ObjectLoader<Light>,
1212 public ObjectLoader<MeshObj>,
1213 public MaterialLoader,
1214 public TrivialLoadable<iSequenceWrapper,ObjectNames::sequence>,
1218 using ObjectLoader<Sequence>::AddDependency;
1219 using ObjectLoader<Trigger>::AddDependency;
1220 using ObjectLoader<Light>::AddDependency;
1221 using ObjectLoader<MeshObj>::AddDependency;
1223 Sequence(BgLoader* parent) : TrivialLoadable<iSequenceWrapper,ObjectNames::sequence>(parent)
1227 bool Parse(iDocumentNode* node, ParserData& data);
1229 bool LoadObject(
bool wait)
1237 ready = ObjectLoader<MeshObj>::LoadObjects(wait);
1242 ready = ObjectLoader<Sequence>::LoadObjects(wait);
1247 ready = TrivialLoadable<iSequenceWrapper,ObjectNames::sequence>::LoadObject(wait);
1252 ready = ObjectLoader<Trigger>::LoadObjects(wait);
1259 TrivialLoadable<iSequenceWrapper,ObjectNames::sequence>::UnloadObject();
1260 ObjectLoader<Sequence>::UnloadObjects();
1261 ObjectLoader<Trigger>::UnloadObjects();
1262 ObjectLoader<MeshObj>::UnloadObjects();
1266 class Light :
public Loadable,
public RangeBased
1269 typedef iLight ObjectType;
1271 Light(BgLoader* parent) : Loadable(parent)
1275 bool Parse(iDocumentNode* node, ParserData& data);
1277 bool LoadObject(
bool wait);
1278 void UnloadObject();
1280 csPtr<iLight> GetObject()
1282 return csPtr<iLight>(light);
1290 csLightDynamicType dynamic;
1291 csLightAttenuationMode attenuation;
1298 csRef<iLight> light;
1301 class MeshFact :
public TrivialLoadable<iMeshFactoryWrapper,ObjectNames::meshfact>,
1302 public MaterialLoader
1305 using ObjectLoader<Material>::AddDependency;
1307 MeshFact(BgLoader* parent) : TrivialLoadable<iMeshFactoryWrapper,ObjectNames::meshfact>(parent),
1312 bool Parse(iDocumentNode* node, ParserData& data);
1313 bool ParseCells(iDocumentNode* node, ParserData& data);
1315 csPtr<MeshFact> Clone(
const char* name)
1317 csRef<MeshFact> clone;
1318 clone.AttachNew(
new MeshFact(GetParent()));
1319 clone->SetName(name);
1321 clone->cloned =
true;
1322 clone->parentFactory = &*
this;
1323 return csPtr<MeshFact>(clone);
1328 if(cloned != other.cloned)
1330 if(parentFactory.IsValid())
1332 if(*parentFactory != other)
1339 if(*
this != *other.parentFactory)
1347 if(parentFactory != other.parentFactory)
1352 if(filename != other.filename)
1354 if((iDocumentNode*)data != (iDocumentNode*)other.data)
1365 return !(*
this == other);
1368 csPtr<iMeshFactoryWrapper> GetObject()
1370 csRef<iMeshFactoryWrapper> object;
1373 if(factory.IsValid())
1377 else if(parentFactory.IsValid())
1379 object = parentFactory->GetObject();
1384 object = TrivialLoadable<iMeshFactoryWrapper,ObjectNames::meshfact>::GetObject();
1386 return csPtr<iMeshFactoryWrapper>(object);
1389 void SetTransform(
const csReversibleTransform& transform)
1394 bool LoadObject(
bool wait);
1395 void UnloadObject();
1396 void FinishObject();
1398 bool FindSubmesh(
const csString& name)
const 1400 return submeshes.Find(name) != csArrayItemNotFound;
1403 const csArray<csVector3>& GetVertices()
const 1411 csRef<MeshFact> parentFactory;
1412 csRef<iMeshFactoryWrapper> factory;
1415 csReversibleTransform trans;
1419 csArray<csVector3> bboxvs;
1420 csStringArray submeshes;
1423 class MeshObj :
public TrivialLoadable<iMeshWrapper,ObjectNames::meshobj>,
1424 public RangeBased,
public ObjectLoader<Texture>,
1425 public MaterialLoader,
public ObjectLoader<MeshFact>
1428 using ObjectLoader<Texture>::AddDependency;
1429 using ObjectLoader<Material>::AddDependency;
1430 using ObjectLoader<MeshFact>::AddDependency;
1432 MeshObj(BgLoader* parent) : TrivialLoadable<iMeshWrapper,ObjectNames::meshobj>(parent)
1436 bool Parse(iDocumentNode* node, ParserData& data,
bool& alwaysLoaded);
1437 bool ParseTriMesh(iDocumentNode* node, ParserData& data,
bool& alwaysLoaded);
1439 bool LoadObject(
bool wait);
1440 void UnloadObject();
1441 void FinishObject();
1443 bool FindSubmesh(
const csString& name)
const 1445 typedef ObjectLoader<MeshFact>::HashType HashType;
1446 const HashType& factories = ObjectLoader<MeshFact>::GetDependencies();
1447 HashType::ConstGlobalIterator it(factories.GetIterator());
1449 while(it.HasNext() && !found)
1451 const csRef<MeshFact>& factory = it.Next().obj;
1452 found |= factory->FindSubmesh(name);
1459 bool dynamicLighting;
1463 csRefArray<ShaderVar> shadervars;
1466 class MeshGen :
public TrivialLoadable<iMeshGenerator,ObjectNames::meshgen>,
public RangeBased,
public MaterialLoader,
1467 public ObjectLoader<MeshFact>
1470 using ObjectLoader<MeshFact>::AddDependency;
1471 using ObjectLoader<Material>::AddDependency;
1473 MeshGen(BgLoader* parent) : TrivialLoadable<iMeshGenerator,ObjectNames::meshgen>(parent),
1478 bool Parse(iDocumentNode* node, ParserData& data);
1480 bool LoadObject(
bool wait);
1481 void UnloadObject();
1488 csRef<MeshObj> mesh;
1491 class Portal :
public Loadable,
public RangeBased
1493 friend class Sector;
1495 typedef iMeshWrapper ObjectType;
1497 Portal(BgLoader* parent,
float renderDist) : Loadable(parent), flags(0), renderDist(renderDist),
1498 warp(
false), ww_given(
false), wv(0.f), ww(0.f),
1499 autoresolve(0), targetSector(0), sector(0)
1503 bool Parse(iDocumentNode* node, ParserData& data);
1505 bool LoadObject(
bool wait);
1506 void UnloadObject();
1508 csPtr<iMeshWrapper> GetObject()
1510 csRef<iMeshWrapper> obj(mObject);
1511 return csPtr<iMeshWrapper>(obj);
1525 csReversibleTransform transform;
1529 Sector* targetSector;
1537 csRef<iMeshWrapper> mObject;
1540 class MissingSectorCallback :
public scfImplementation1<MissingSectorCallback, iPortalCallback>
1543 csRef<Sector> targetSector;
1547 MissingSectorCallback(Sector* target,
bool resolve) : scfImplementationType(
this),targetSector(target),autoresolve(resolve)
1551 virtual ~MissingSectorCallback()
1555 virtual bool Traverse(iPortal* p,
iBase* )
1557 csRef<iSector> target = targetSector->GetObject();
1558 if(target.IsValid())
1560 p->SetSector(target);
1569 p->RemoveMissingSectorCallback(
this);
1577 class Sector :
public Loadable,
1578 public ObjectLoader<MeshGen>,
public ObjectLoader<MeshObj>,
1579 public ObjectLoader<Portal>,
public ObjectLoader<Light>,
1580 public ObjectLoader<Sequence>,
public ObjectLoader<Trigger>
1583 using ObjectLoader<MeshGen>::AddDependency;
1584 using ObjectLoader<MeshObj>::AddDependency;
1585 using ObjectLoader<Portal>::AddDependency;
1586 using ObjectLoader<Light>::AddDependency;
1587 using ObjectLoader<Sequence>::AddDependency;
1588 using ObjectLoader<Trigger>::AddDependency;
1590 Sector(BgLoader* parent) : Loadable(parent), ambient(0.0f), objectCount(0),
1591 init(
false), isLoading(
false)
1599 bool Parse(iDocumentNode* node, ParserData& data);
1601 bool LoadObject(
bool wait);
1602 void UnloadObject();
1603 int UpdateObjects(
const csBox3& loadBox,
const csBox3& keepBox,
size_t recursions);
1606 void ForceUpdateObjectCount();
1607 void FindConnectedSectors(csSet<csPtrKey<Sector> >& connectedSectors);
1609 void AddPortal(Portal* p)
1611 CS::Threading::RecursiveMutexScopedLock lock(busy);
1612 activePortals.Add(p);
1615 void RemovePortal(Portal* p)
1617 CS::Threading::RecursiveMutexScopedLock lock(busy);
1618 activePortals.Delete(p);
1621 void AddAlwaysLoaded(MeshObj* mesh)
1623 alwaysLoaded.AddDependency(mesh);
1626 csPtr<iSector> GetObject()
1628 csRef<iSector> obj(
object);
1629 return csPtr<iSector>(obj);
1640 csArray<WaterArea> waterareas;
1641 ObjectLoader<MeshObj> alwaysLoaded;
1644 CS::Threading::RecursiveMutex busy;
1645 csRef<iSector> object;
1646 csSet<csPtrKey<Portal> > activePortals;
1652 class Zone :
public Loadable,
public ObjectLoader<Sector>
1655 using ObjectLoader<Sector>::AddDependency;
1657 Zone(BgLoader* parent,
const char* name)
1658 : Loadable(parent), priority(
false)
1660 Loadable::SetName(name);
1663 bool LoadObject(
bool wait)
1665 return ObjectLoader<Sector>::LoadObjects(wait);
1670 ObjectLoader<Sector>::UnloadObjects();
1673 void UpdatePriority(
bool newPriority)
1675 if(priority != newPriority)
1677 priority = newPriority;
1688 bool GetPriority()
const 1698 struct GlobalParserData
1701 csStringHash xmltokens;
1704 LockedType<Texture> textures;
1705 LockedType<MeshObj> meshes;
1706 csRef<iShaderVarStringSet> svstrings;
1709 csRef<iSyntaxService> syntaxService;
1710 iObjectRegistry* object_reg;
1713 csRef<iStringSet> strings;
1714 LockedType<Material> materials;
1715 LockedType<Sector> sectors;
1716 LockedType<MeshFact> factories;
1717 LockedType<Zone> zones;
1718 LockedType<StartPosition,false> positions;
1719 CS::Threading::ReadWriteMutex shaderLock;
1720 csHash<csString, csStringID> shadersByUsage;
1721 csStringArray shaders;
1722 csHash<csString, csString> shaderAliases;
1728 uint enabledGfxFeatures;
1732 bool blockShaderLoad;
1734 bool parseShaderVars;
1742 ParserData(GlobalParserData& data) : data(data)
1747 GlobalParserData& data;
1750 csRefArray<iThreadReturn> rets;
1752 csRef<Sector> currentSector;
1753 LockedType<Light> lights;
1754 LockedType<Sequence> sequences;
1755 LockedType<Trigger> triggers;
1759 bool parsedMeshFact;
1766 #define CS_TOKEN_ITEM_FILE "src/plugins/common/bgloader/parser.tok" 1767 #define CS_TOKEN_LIST_TOKEN_PREFIX PARSERTOKEN_ 1768 #include "cstool/tokenlist.h" 1769 #undef CS_TOKEN_ITEM_FILE 1770 #undef CS_TOKEN_LIST_TOKEN_PREFIX 1772 void ParseMaterials(iDocumentNode* materialsNode);
1775 void ParseShaders();
1778 void CleanDisconnectedSectors(Sector* sector);
1780 bool LoadSequencesAndTriggers (iDocumentNode* snode, iDocumentNode* tnode, ParserData& data);
1783 iObjectRegistry* object_reg;
1784 csRef<iEngine> engine;
1785 csRef<iGraphics2D> g2d;
1786 csRef<iThreadedLoader> tloader;
1787 csRef<iThreadManager> tman;
1789 csRef<iCollideSystem> cdsys;
1790 CS::Threading::RecursiveMutex vfsLock;
1793 ObjectLoader<Zone> loadedZones;
1796 CS::Threading::RecursiveMutex loadLock;
1798 size_t delayedOffset;
1799 csArray<csPtrKey<Loadable> > loadList;
1800 csArray<csPtrKey<iDelayedLoader> > delayedLoadList;
1809 uint maxPortalDepth;
1813 size_t maxLingerCount;
1816 csRef<Sector> lastSector;
1825 csRef<iMeshWrapper> selectedMesh;
1826 csRef<MeshFact> selectedFactory;
1827 csRef<Material> selectedMaterial;
1828 csVector2 previousPosition;
1829 csVector3 origTrans;
1832 csVector3 currRot_h;
1833 csVector3 currRot_v;
1837 CS_PLUGIN_NAMESPACE_END(bgLoader)
1839 #endif // __LOADER_H__ bool operator!=(T *p, const scoped_ptr< T > &b)
const char * GetName(int id)
CS_PLUGIN_NAMESPACE_BEGIN(bgLoader)
#define LOADER_DEBUG_MESSAGE(...)
#define CS_ASSERT_MSG(msg, x)
void void Initialize(iObjectRegistry *object_reg)
bool operator==(T *p, const scoped_ptr< T > &b)