1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
19 #ifndef RY_GPM_UTILITIES_H
20 #define RY_GPM_UTILITIES_H
22 #include "nel/misc/types_nl.h"
23 #include "nel/misc/time_nl.h"
24 #include "nel/misc/block_memory.h"
25 #include "nel/pacs/u_move_container.h"
26 #include "nel/pacs/u_move_primitive.h"
27 #include "nel/pacs/u_collision_desc.h"
28 #include "nel/pacs/u_global_retriever.h"
29 #include "nel/net/message.h"
31 #include "game_share/ryzom_entity_id.h"
32 #include "game_share/player_vision_delta.h"
41 class CWorldPositionManager
;
42 class ConstIteratorType
;
47 * Misc. data structures (essentially vision data)
51 * Front end vision data to be sent
56 CFrontEndData() : Message("",false),
59 CurrentVisionsAtTick(0),
67 NLNET::CMessage Message
;
68 sint32 MessageHeaderSize
;
70 sint32 CurrentVisionsAtTick
;
71 sint32 MaxVisionsPerTick
;
78 * Entities around vision data to be sent
82 CServiceData() : Message("",false) {} // always an output message
83 NLNET::CMessage Message
;
84 sint32 MessageHeaderSize
;
87 typedef std::map
<NLNET::TServiceId
, CFrontEndData
> TMapFrontEndData
;
88 typedef std::map
<NLNET::TServiceId
, CServiceData
> TMapServiceData
;
90 typedef std::list
< CPlayerInfos
* > TPlayerList
;
98 * A list of object that must have Next and Previous pointers
99 * \param T the type of item
100 * \param TPtr a pointer to T to use in list (useful for smartpointer)
102 template<class T
, class TPtr
= T
*>
109 CObjectList() : Head(NULL
), Tail(NULL
) {}
111 void insertAtHead(T
*object
)
113 nlassert(object
->Next
== NULL
);
114 nlassert(object
->Previous
== NULL
);
117 if (object
->Next
!= NULL
)
118 object
->Next
->Previous
= object
;
122 void insertAtTail(T
*object
)
124 nlassert(object
->Next
== NULL
);
125 nlassert(object
->Previous
== NULL
);
127 object
->Previous
= Tail
;
128 if (object
->Previous
!= NULL
)
129 object
->Previous
->Next
= object
;
133 void remove(T
*object
)
136 if (object
->Previous
== NULL
)
139 object
->Previous
->Next
= object
->Next
;
142 if (object
->Next
== NULL
)
143 Tail
= object
->Previous
;
145 object
->Next
->Previous
= object
->Previous
;
147 object
->Previous
= NULL
;
151 T
*getHead() { return (T
*)Head
; }
152 T
*getTail() { return (T
*)Tail
; }
156 * A little stack implementation, for really fast push_back/pop_back
158 template<class T
, uint stackSize
>
159 class CUnsafeConstantSizeStack
166 CUnsafeConstantSizeStack() { _Top
= _Array
; }
168 void push_back(const T
&o
= T()) { *(_Top
++) = o
; }
169 void pop_back() { nlassert(_Top
> _Array
); --_Top
; }
170 //T &front() { return _Array[0]; }
171 T
&back() { nlassert(_Top
> _Array
); return *(_Top
-1); }
172 uint
size() { return (uint
)(_Top
-_Array
); }
173 bool empty() { return _Top
== _Array
; }
174 void clear() { _Top
= _Array
; }
178 * The same class, but uses stl vectors instead, and should be saffer
180 template<class T
, uint stackSize
>
181 class CSafeConstantSizeStack
: public std::vector
<T
>
184 CSafeConstantSizeStack() { this->reserve(stackSize
); }
191 * Simple smart pointers, doesn't delete object when no reference
192 * Instanciation class T must have a RefCounter attribute
195 class CSimpleSmartPointer
201 CSimpleSmartPointer() : _Ptr(NULL
) {}
202 CSimpleSmartPointer(T
* ptr
) : _Ptr(NULL
) { *this = ptr
; }
203 CSimpleSmartPointer(const CSimpleSmartPointer
&ptr
) : _Ptr(NULL
) { *this = ptr
; }
204 ~CSimpleSmartPointer() { *this = NULL
; }
206 T
* operator = (T
*ptr
)
212 nlassert(_Ptr
->RefCounter
> 0);
213 --(_Ptr
->RefCounter
);
219 T
* operator = (const CSimpleSmartPointer
&ptr
)
225 T
& operator * () { return *_Ptr
; }
226 T
* operator -> () { return _Ptr
; }
227 const T
& operator * () const { return *_Ptr
; }
228 const T
* operator -> () const { return _Ptr
; }
229 bool operator == (const T
*ptr
) const { return ptr
== _Ptr
; }
230 bool operator != (const T
*ptr
) const { return ptr
!= _Ptr
; }
231 bool operator == (const CSimpleSmartPointer
&ptr
) const { return ptr
._Ptr
== _Ptr
; }
232 bool operator != (const CSimpleSmartPointer
&ptr
) const { return ptr
._Ptr
!= _Ptr
; }
233 operator T
* () const { return _Ptr
; }
238 #endif // RY_GPM_UTILITIES_H
240 /* End of gpm_utilities.h */