Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / streamable_entity.h
blob87623ab1092c2ab13b0718ef1b8d9e8706deb735
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_ENTITY_H
21 #define CL_STREAMABLE_ENTITY_H
23 #include "nel/misc/vector.h"
24 #include "nel/misc/smart_ptr.h"
27 /** Base interface for streamable entities
29 struct IStreamableEntity : public NLMISC::CRefCount
31 /** Given a pos, test whether the entity needs to be loaded now.
32 * It it returns false, it means that the entity is too far or that asynchronous loading suffice.
33 * It it returns true, the next call to update will return only when the loading is completed.
35 virtual bool needCompleteLoading(const NLMISC::CVector &pos) const = 0;
36 /** Test that entity against the player position, and load / unload it (using synchronous or asynchronous loading)
38 virtual void update(const NLMISC::CVector &pos) = 0;
39 // The same as 'update', but force synchronous loading all the time
40 virtual void forceUpdate(const NLMISC::CVector &pos, class NLMISC::IProgressCallback &progress) = 0;
41 /// Force unloading of all entitie
42 virtual void forceUnload() = 0;
43 // dtor
44 virtual ~IStreamableEntity() {}
48 /** Streamable entity, which uses distance to a point.
49 * Such an entity is streamed when it is near the user, or its loading is forced when it is too near.
50 * The derivers may choose what kind of object must be loaded
52 class CStreamableEntity : public IStreamableEntity
54 public:
55 //\name Object
56 //@{
57 // ctor
58 CStreamableEntity();
59 // dtor
60 virtual ~CStreamableEntity() {}
61 //@}
63 //\name Attributes
64 //@{
65 // Get the position of the entity.
66 const NLMISC::CVector &getPos() const { return _Pos; }
67 // Get the radius (in meter) at which async loading must begin.
68 float getLoadRadius() const { return _LoadRadius; }
69 // Get the radius (in meter) at which loading is forced (user must wait)
70 float getForceLoadRadius() const { return _ForceLoadRadius; }
71 // Get the radius (in meter) at which the entity must be unloaded
72 float getUnloadRadius() const { return _UnloadRadius; }
73 //@}
75 //\name From IStreamableEntity
76 //@{
77 /** Given a pos, test whether the entity needs to be loaded now.
78 * It it returns false, it means that the entity is too far or that asynchronous loading suffice.
79 * It it returns true, the next call to update will return only when the loading is completed.
81 virtual bool needCompleteLoading(const NLMISC::CVector &pos) const
83 nlassert(_UnloadRadius >= _LoadRadius && _LoadRadius >= _ForceLoadRadius);
84 return (pos - _Pos).norm() < _ForceLoadRadius;
86 /** Test that entity against the player position, and load / unload it (using synchronous or asynchronous loading)
88 virtual void update(const NLMISC::CVector &pos);
89 /** The same as 'update', but force synchronous update all the time
91 virtual void forceUpdate(const NLMISC::CVector &pos, NLMISC::IProgressCallback &progress);
92 //@}
94 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95 protected:
96 // for derivers : set attributes.
97 void setPos(const NLMISC::CVector &pos)
99 _Pos = pos;
101 void setLoadRadius(float loadRadius)
103 nlassert(loadRadius >= 0);
104 _LoadRadius = loadRadius;
106 void setForceLoadRadius(float forceLoadRadius)
108 nlassert(forceLoadRadius >= 0);
109 _ForceLoadRadius = forceLoadRadius;
111 void setUnloadRadius(float unloadRadius)
113 nlassert(unloadRadius >= 0);
114 _UnloadRadius = unloadRadius;
117 //\name Derivers methods.
118 //@{
119 /** Force async loading of this object.
120 * Maybe called even if currently loading async
122 virtual void loadAsync() = 0;
124 /** Force complete loading of that object. If an async loading was started, it must be finished.
126 virtual void load(NLMISC::IProgressCallback &progress) = 0;
128 /** Unload that object.
129 * Maybe be called even if currently loading
131 virtual void unload() = 0;
132 //@}
134 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
135 private:
136 NLMISC::CVector _Pos;
137 float _LoadRadius;
138 float _ForceLoadRadius;
139 float _UnloadRadius;
142 #endif // CL_STREAMABLE_ENTITY_H