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/>.
22 #include "nel/misc/types_nl.h"
23 #include "nel/misc/debug.h"
25 #include "world_entity.h"
28 * CCell contained entity in this cell and updated entity
29 * \author Alain Saffray
30 * \author Nevrax France
36 /// default constructor
37 CCell() : _LastVisionUpdate(0) {}
40 void init( sint32 cellId
)
42 _LastVisionUpdate
= 0;
47 void init( uint16 x
, uint16 y
)
52 _LastVisionUpdate
= 0;
53 _CellId
= (x
<<16) + y
;
57 /// \name CCell content management
61 * Adds an entity to the cell
63 * \param entity pointer to the entity to add
65 void add(CWorldEntity
* entity
);
68 * Removes an entity from the cell
70 * \param entity pointer to the entity to remove
72 void remove(CWorldEntity
* entity
);
78 * Remove entity of cell
80 * \param pWorldEntity is pointer of entity's removed from cell
82 // void removeEntity( CWorldEntity* pWorldEntity );
85 * Add an entity in the cell
87 // void addEntity(CWorldEntity* pWorldEntity);
90 * Add an object in the cell
92 // void addObject(CWorldEntity* pWorldEntity);
95 * Add an object in the cell
97 // void removeObject(CWorldEntity* pWorldEntity);
100 * Update cell content
102 * \param pWorldEntity is updated entity
103 * \param pWorldPositionManager is entity position manager in world
105 // void updateCell( CWorldEntity* pWorldEntity );
109 /// Get a pointer on the first entity in cell
110 CWorldEntity
*getEntitiesList() { return _EntitiesList
.getHead(); }
112 /// Get a pointer on the first object in cell
113 CWorldEntity
*getObjectsList() { return _ObjectsList
.getHead(); }
115 /// Get a pointer to the first player in cell
116 CPlayerInfos
*getPlayersList() { return _PlayersList
.getHead(); }
119 /// Gets at maximum MAX_SEEN_ENTITIES entities contained in the cell
120 CVisionEntry
* addEntities(CVisionEntry
* fillPtr
, CVisionEntry
* endPtr
, uint32 cellMask
, uint32 distance
, bool indoor
, CWorldEntity
*player
)
122 CWorldEntity
*ent
= _EntitiesList
.getHead();
123 while (ent
!= NULL
&& fillPtr
< endPtr
)
125 sint32 mask
= cellMask
& (sint32
)(ent
->WhoSeesMe
);
126 if (mask
&& indoor
&& (float)(player
->X()-ent
->X())*(float)(player
->X()-ent
->X()) + (float)(player
->Y()-ent
->Y())*(float)(player
->Y()-ent
->Y()) > 15625000000)
129 //if (!ent->IsInvisibleToPlayer && mask != 0)
132 fillPtr
->Entity
= ent
;
133 fillPtr
->Mask
= mask
;
134 fillPtr
->Distance
= distance
;
141 /// Gets at maximum MAX_SEEN_ENTITIES entities contained in the cell
142 CVisionEntry
* addObjects(CVisionEntry
* fillPtr
, CVisionEntry
* endPtr
, uint32 cellMask
, uint32 distance
, bool indoor
, CWorldEntity
*player
)
144 CWorldEntity
*ent
= _ObjectsList
.getHead();
145 while (ent
!= NULL
&& fillPtr
< endPtr
)
147 sint32 mask
= cellMask
& (sint32
)(ent
->WhoSeesMe
);
148 if (mask
&& indoor
&& (float)(player
->X()-ent
->X())*(float)(player
->X()-ent
->X()) + (float)(player
->Y()-ent
->Y())*(float)(player
->Y()-ent
->Y()) > 15625000000)
151 //if (!ent->IsInvisibleToPlayer && mask != 0)
154 fillPtr
->Entity
= ent
;
155 fillPtr
->Mask
= mask
;
156 fillPtr
->Distance
= distance
;
164 void setVisionUpdateCycle(NLMISC::TGameCycle gc
) { _LastVisionUpdate
= gc
; }
165 NLMISC::TGameCycle
visionUpdateCycle() { return _LastVisionUpdate
; }
167 inline uint16
x() const { return (uint16
)(_CellId
>>16); };
168 inline uint16
y() const { return (uint16
)(_CellId
&0xffff); };
169 inline sint32
id() const { return _CellId
; }
170 inline bool isIndoor() const { return _CellId
< 0; }
172 //static TVisionCellContainer &getVisionCells() { return _VisionCells; }
175 //friend void CWorldEntity::removeFromCellAsEntity();
176 //friend void CWorldEntity::removeFromCellAsObject();
177 friend class CWorldPositionManager
;
181 TEntityList _EntitiesList
; // visible moving entities in cell
182 TEntityList _ObjectsList
; // objects in cell
183 CObjectList
<CPlayerInfos
> _PlayersList
; // players in cell
184 // TEntityList _InvisiblesList; // invisible entities in cell
186 /// last vision update tick for this cell
187 NLMISC::TGameCycle _LastVisionUpdate
;
190 /// Creates a new entity (new equivalent). This must be initialised later using init();
191 static CCell
*create() { return _CellAllocator
.allocate(); }
193 /// Removes an entity (delete equivalent).
194 static void remove(CCell
*cell
) { _CellAllocator
.freeBlock(cell
); }
198 /// Static cell allocator
199 static NLMISC::CBlockMemory
<CCell
> _CellAllocator
;