Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / streamable_ig.h
blob45cbe20fe1b6327b291e2bb6acda5a7468fde1ac
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef CL_STREAMABLE_IG
21 #define CL_STREAMABLE_IG
23 #include "streamable_entity.h"
24 #include "ig_enum.h"
26 #include "nel/3d/u_scene.h"
28 #include <string>
29 #include <map>
32 namespace NL3D
34 class UScene;
35 class UInstanceGroup;
38 namespace NLMISC
40 class CVector;
43 class CStreamableIG;
45 /** A streamable IG hierarchy (hierarchy is used to build clusters hierarchy). It may be loaded synchronously or asynchronously depending on the distance.
47 class CStreamableIG : public CStreamableEntity, public CIGNotifier
49 public:
50 typedef std::map<std::string, NL3D::UInstanceGroup *> TString2IG;
51 // for debug
52 std::string Name;
53 public:
54 // default ctor
55 CStreamableIG();
56 // dtor
57 ~CStreamableIG();
58 /** Init this streamable ig
59 * \param owningScene the scene in which that ig should be inserted
60 * \param pos center of the testing volume
61 * \param forceLoadRadius the radius at which loading should be forced
62 * \param loadRadius the radius at which asynchronous loading should start
63 * \param unloadRadius the radius at which the ig should be unloaded
65 void init(
66 NL3D::UScene *owningScene,
67 const NLMISC::CVector &pos,
68 float forceLoadRadius,
69 float loadRadius,
70 float unloadRadius
72 NL3D::UScene *getScene() const { return _Scene; }
74 /// Optimisation purpose. If you know how many calls to addIG will be done, you can call this
75 void reserve(uint size);
76 /** Add an ig and the name of its parent ig (for clusters linking), or an empty name it no linking is done
78 void addIG(const std::string &name, const std::string &parentName, const NLMISC::CVector &pos, const NLMISC::CQuat &rot);
79 /** Set an additionnal map (ig name -> ig pointer) that will be filled with loaded igs.
80 * Setting that pointer to NULL will remove currently loaded igs from the map and will disable it.
81 * By default, no map is used
83 void setLoadedIGMap(TString2IG *igMap);
85 virtual void forceUnload();
86 /** enum all currently instanciated IGs
87 * \return false if the enumeration has been stopped
89 bool enumIGs(IIGEnum *callback);
91 // Change one ig
92 bool setIG(uint ig, const std::string &name, const std::string &parentName);
94 // Get num of IG in the streamable IG..
95 uint getIGNum() const
97 return (uint)_IGs.size();
100 /////////////////////////////////////////////////////////////////////////////////////////////////////////
101 /////////////////////////////////////////////////////////////////////////////////////////////////////////
102 private:
103 class CCallback : public NL3D::IAsyncLoadCallback
105 public:
106 CStreamableIG *Owner;
107 virtual void InstanceGroupCreated(NL3D::UInstanceGroup *newVal)
109 Owner->notifyIGLoaded(newVal);
113 struct CIGNode
115 std::string Name;
116 std::string ParentName;
117 NL3D::UInstanceGroup *IG;
118 bool Loading;
119 NLMISC::CVector Pos;
120 NLMISC::CQuat Rot;
123 typedef std::vector<CIGNode> TIGArray;
125 private:
127 NL3D::UScene *_Scene;
128 TIGArray _IGs;
129 bool _Linked; // instance are linked in a tree of cluster
130 TString2IG *_IGMap;
131 EGSPD::CSeason::TSeason _Season;
133 CCallback _Callback;
137 private:
139 //\name From CStreamableEntity
140 //@{
141 virtual void loadAsync();
142 virtual void load(NLMISC::IProgressCallback &progress);
143 virtual void unload();
144 //@}
145 void linkInstances();
146 void addLoadedIGToMap();
147 void removeLoadedIGFromMap();
151 #endif