Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interface_v3 / animal_position_state.cpp
bloba99788c8dfc3e59e76ed3be544a010763ce2c913
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "stdpch.h"
24 #include "animal_position_state.h"
25 #include "../entities.h"
26 #include "interface_manager.h"
27 #include "group_compas.h"
28 #include "game_share/animal_status.h"
30 using NLMISC::CCDBNodeLeaf;
32 // ***************************************************************************
33 // CPositionState
34 // ***************************************************************************
38 // ***************************************************************************
39 bool CPositionState::getPos(sint32 &px, sint32 &py)
41 // only if the animal is spawned
42 if (dbOk())
44 CEntityCL *entity = getEntity();
45 // If the entity is not in vision, take Database position
46 if(!entity)
48 return getDbPos(px, py);
50 // else take VisualProp more precise position
51 else
53 px = (sint32)((float)entity->lastFramePos().x * 1000);
54 py = (sint32)((float)entity->lastFramePos().y * 1000);
57 return true;
59 else
61 px= py= 0;
62 return false;
67 // ***************************************************************************
68 void CPositionState::serialNodeLeaf(NLMISC::IStream &f, CCDBNodeLeaf *&dbNode)
70 f.serialCheck(NELID("NL__"));
71 f.serialVersion(0);
72 std::string dbPath;
73 if (f.isReading())
75 f.serial(dbPath);
76 dbNode = NULL;
77 if (!dbPath.empty())
79 CInterfaceManager *im = CInterfaceManager::getInstance();
80 dbNode = NLGUI::CDBManager::getInstance()->getDbProp(dbPath, false);
83 else
85 if (dbNode)
87 dbPath = dbNode->getFullName();
89 f.serial(dbPath);
91 f.serialCheck(NELID("END_"));
95 // ***************************************************************************
96 void CUIDEntityPositionState::serial(NLMISC::IStream &f)
98 f.serialCheck(NELID("UIDE"));
99 f.serialVersion(0);
100 serialNodeLeaf(f, _DBPos);
101 serialNodeLeaf(f, _Uid);
102 f.serialCheck(NELID("_END"));
105 // ***************************************************************************
106 CEntityCL *CUIDEntityPositionState::getEntity()
108 if (!dbOk()) return NULL;
109 CLFECOMMON::TClientDataSetIndex uid= _Uid->getValue32();
110 // If the _EntitySlot is not set, try to acquire the animal in vision.
111 if(_EntitySlot == CLFECOMMON::INVALID_SLOT)
113 // O(n=256)
114 CEntityCL *entity= EntitiesMngr.getEntityByCompressedIndex(uid);
115 // the entity position must be valid, else don't take it.
116 if((entity != NULL) && entity->firstPositionReceived())
117 _EntitySlot = entity->slot();
120 // else check that the cache slot is OK with this UID
121 else
123 // O(1)
124 CEntityCL *entity= EntitiesMngr.entity(_EntitySlot);
125 // Is data slot changed ? animal no more in vision -> try to acquire it at next pass
126 if((entity == NULL) || ((entity != NULL) && (entity->dataSetId() != uid)))
127 _EntitySlot= CLFECOMMON::INVALID_SLOT;
129 CEntityCL *entity= EntitiesMngr.entity(_EntitySlot);
130 return entity;
134 // ***************************************************************************
135 bool CUIDEntityPositionState::getDbPos(sint32 &px, sint32 &py)
137 if (!dbOk()) return false;
138 px = (sint32) (_DBPos->getValue64() >> 32);
139 py = _DBPos->getValue32();
140 return true;
144 // ***************************************************************************
145 // CUIDEntityPositionState
146 // ***************************************************************************
149 // ***************************************************************************
150 CUIDEntityPositionState::CUIDEntityPositionState()
152 _DBPos= NULL;
153 _Uid= NULL;
154 _EntitySlot= CLFECOMMON::INVALID_SLOT;
157 // ***************************************************************************
158 void CUIDEntityPositionState::build(const std::string &baseDB)
160 CInterfaceManager *pIM= CInterfaceManager::getInstance();
162 _DBPos= NLGUI::CDBManager::getInstance()->getDbProp(baseDB+":POS", false);
163 _Uid= NLGUI::CDBManager::getInstance()->getDbProp(baseDB+":UID", false);
164 // reset
165 _EntitySlot= CLFECOMMON::INVALID_SLOT;
168 // ***************************************************************************
169 // CTeammatePositionState
170 // ***************************************************************************
172 // ***************************************************************************
173 CTeammatePositionState::CTeammatePositionState() : CUIDEntityPositionState()
175 _Present= NULL;
179 // ***************************************************************************
180 void CTeammatePositionState::build(const std::string &baseDB)
182 CInterfaceManager *pIM= CInterfaceManager::getInstance();
183 _Present = NLGUI::CDBManager::getInstance()->getDbProp(baseDB+":NAME", false);
185 CUIDEntityPositionState::build(baseDB);
189 // ***************************************************************************
190 bool CTeammatePositionState::getPos(sint32 &px, sint32 &py)
193 CEntityCL *entity = getEntity();
195 // only if the animal is spawned
196 if( dbOk() && (_Present->getValue32() != 0))
198 return CPositionState::getPos(px, py);
200 else
202 px= py= 0;
203 return false;
208 // ***************************************************************************
209 // CAnimalPositionState
210 // ***************************************************************************
212 // ***************************************************************************
213 CAnimalPositionState::CAnimalPositionState() : CUIDEntityPositionState()
215 _Status= NULL;
219 // ***************************************************************************
220 void CAnimalPositionState::build(const std::string &baseDB)
222 CInterfaceManager *pIM= CInterfaceManager::getInstance();
223 _Status= NLGUI::CDBManager::getInstance()->getDbProp(baseDB+":STATUS", false);
225 CUIDEntityPositionState::build(baseDB);
229 // ***************************************************************************
230 bool CAnimalPositionState::getPos(sint32 &px, sint32 &py)
232 // only if the animal is spawned
233 if( dbOk() && ANIMAL_STATUS::isSpawned((ANIMAL_STATUS::EAnimalStatus)_Status->getValue32()))
235 return CPositionState::getPos(px, py);
237 else
239 px= py= 0;
240 return false;
244 // ***************************************************************************
245 void CAnimalPositionState::serial(NLMISC::IStream &f)
247 f.serialCheck(NELID("APS_"));
248 f.serialVersion(0);
249 CUIDEntityPositionState::serial(f);
250 serialNodeLeaf(f, _Status);
251 f.serialCheck(NELID("END_"));
255 // ***************************************************************************
256 // CNamedEntityPositionState
257 // ***************************************************************************
260 // ***************************************************************************
261 CEntityCL *CNamedEntityPositionState::getEntity()
263 if (!dbOk()) return NULL;
264 return EntitiesMngr.getEntityByName(_Name->getValue32());
267 // ***************************************************************************
268 bool CNamedEntityPositionState::getDbPos(sint32 &px, sint32 &py)
270 if (!dbOk()) return false;
271 px = _X->getValue32();
272 py = _Y->getValue32();
273 return true;
276 // ***************************************************************************
277 void CNamedEntityPositionState::build(CCDBNodeLeaf *name, CCDBNodeLeaf *x, CCDBNodeLeaf *y)
279 _Name = name;
280 _X = x;
281 _Y = y;
285 // ***************************************************************************
286 CEntityCL *CDialogEntityPositionState::getEntity()
288 if ( CCompassDialogsManager::getInstance().getEntries().size() >= _DialogIndex )
289 return NULL;
290 return EntitiesMngr.getEntityByName(CCompassDialogsManager::getInstance().getEntries()[_DialogIndex].Text);
293 bool CDialogEntityPositionState::getDbPos(sint32 &px, sint32 &py)
295 if ( CCompassDialogsManager::getInstance().getEntries().size() < _DialogIndex )
296 return false;
297 px = CCompassDialogsManager::getInstance().getEntries()[_DialogIndex].X;
298 py = CCompassDialogsManager::getInstance().getEntries()[_DialogIndex].Y;
299 return true;
302 // ***************************************************************************
303 void CNamedEntityPositionState::serial(NLMISC::IStream &f)
305 f.serialCheck(NELID("NEPS"));
306 f.serialVersion(0);
307 serialNodeLeaf(f, _Name);
308 serialNodeLeaf(f, _X);
309 serialNodeLeaf(f, _Y);
310 f.serialCheck(NELID("END_"));