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/>.
23 using namespace NLMISC
;
24 using namespace NLPACS
;
27 /****************************************************************\
28 ****************************************************************
30 ****************************************************************
31 \****************************************************************/
33 // Static cell allocator
34 CBlockMemory
<CCell
> CCell::_CellAllocator
;
40 * Adds an entity to the cell
42 void CCell::add(CWorldEntity
* entity
)
44 // check entity is not null
45 nlassert(entity
!= NULL
);
47 // check entity no longer linked
48 nlassert(entity
->CellPtr
== NULL
);
49 nlassert(entity
->Previous
== NULL
);
50 nlassert(entity
->Next
== NULL
);
52 // insert entity in good list, depending on if it is an object or not
53 if (entity
->getType() == CWorldEntity::Object
)
55 _ObjectsList
.insertAtHead(entity
);
59 _EntitiesList
.insertAtHead(entity
);
61 if (entity
->getType() == CWorldEntity::Player
&& entity
->PlayerInfos
!= NULL
)
63 _PlayersList
.insertAtHead(entity
->PlayerInfos
);
67 // set CellPtr and Cell id
68 entity
->CellPtr
= this;
69 entity
->Cell
= _CellId
;
75 * Removes an entity from the cell
77 void CCell::remove(CWorldEntity
* entity
)
79 // check entity is not null
80 nlassert(entity
!= NULL
);
82 // check entity points to this cell
83 nlassert(entity
->CellPtr
== this);
85 // remove entity from good list, depending on if it is an object or not
86 if (entity
->getType() == CWorldEntity::Object
)
88 _ObjectsList
.remove(entity
);
92 _EntitiesList
.remove(entity
);
94 if (entity
->getType() == CWorldEntity::Player
&& entity
->PlayerInfos
!= NULL
)
96 _PlayersList
.remove(entity
->PlayerInfos
);
100 // reset CellPtr and Cell id
101 entity
->CellPtr
= NULL
;
102 //entity->Cell = 0; // not set at this time, perhaps user somewhere else (CellId 0 might crash!)
110 /****************************************************************\
112 \****************************************************************/
114 void CCell::updateCell( CWorldEntity* pWorldEntity )
116 // updateCell should not be called for objects
117 nlassert(pWorldEntity != NULL && !pWorldEntity->IsStaticObject);
119 // if entity didn't changed cell, no update
120 if (pWorldEntity->CellPtr == this)
123 // if previously was in a cell, remove it
124 if( pWorldEntity->CellPtr != NULL )
125 pWorldEntity->CellPtr->removeEntity( pWorldEntity );
127 addEntity(pWorldEntity);
133 /****************************************************************\
135 \****************************************************************/
137 void CCell::addEntity( CWorldEntity* pWorldEntity )
139 nlassert(pWorldEntity != NULL && pWorldEntity->CellPtr == NULL);
141 // if entity has vision, update vision stats of the cell
142 if (pWorldEntity->HasVision)
144 nlassert(pWorldEntity->PlayerInfos != NULL);
146 // add player to players list
147 _PlayersList.insertAtHead(pWorldEntity->PlayerInfos);
150 _EntitiesList.insertAtHead(pWorldEntity);
152 // if (pWorldEntity->IsInvisible)
153 // _InvisiblesList.insertAtHead(pWorldEntity);
155 // _EntitiesList.insertAtHead(pWorldEntity);
157 pWorldEntity->CellPtr = this;
158 pWorldEntity->Cell = _CellId;
159 //CWorldPositionManager::cellUpdated( this );
163 /****************************************************************\
165 \****************************************************************/
167 void CCell::addObject( CWorldEntity* pWorldEntity )
169 nlassert(pWorldEntity->CellPtr == NULL);
171 _ObjectsList.insertAtHead(pWorldEntity);
173 pWorldEntity->CellPtr = this;
174 pWorldEntity->Cell = _CellId;
175 //CWorldPositionManager::cellUpdated( this );
179 /****************************************************************\
181 \****************************************************************/
183 void CCell::removeEntity( CWorldEntity* pWorldEntity )
185 nlassert(pWorldEntity != NULL && pWorldEntity->CellPtr == this);
187 // if entity has vision
188 if (pWorldEntity->HasVision)
190 nlassert(pWorldEntity->PlayerInfos != NULL);
192 // removes player from players list
193 _PlayersList.remove(pWorldEntity->PlayerInfos);
196 // finds the entity in entities list, and remove it
197 pWorldEntity->removeFromCellAsEntity();
199 //CWorldPositionManager::cellUpdated( this );
203 /****************************************************************\
205 \****************************************************************/
207 void CCell::removeObject( CWorldEntity* pWorldEntity )
209 nlassert(pWorldEntity != NULL && pWorldEntity->CellPtr == this);
211 // finds the entity in entities list, and remove it
212 pWorldEntity->removeFromCellAsObject();
214 //CWorldPositionManager::cellUpdated( this );