Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / village.cpp
blob41d698782e9191091c6a3786791ba634e968d51f
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/>.
19 #include "stdpch.h"
22 #include "village.h"
23 #include "nel/georges/u_form.h"
24 #include "nel/georges/u_form_elm.h"
25 #include "nel/misc/vector.h"
26 #include "nel/misc/vector_2f.h"
27 #include "client_sheets/village_sheet.h"
28 #include "client_sheets/entity_sheet.h"
29 #include "zone_util.h"
30 #include "ig_enum.h"
31 #include "ingame_database_manager.h"
32 #include "sheet_manager.h"
33 #include "pacs_client.h"
34 #include "client_cfg.h"
36 #ifdef DEBUG_NEW
37 #define new DEBUG_NEW
38 #endif
40 using namespace NLMISC;
41 using namespace std;
43 //===================================================================================
44 CVillage::CVillage() : _Scene(NULL)
46 // Not an output
47 _IsOutpost = false;
49 // Init buildings
50 for (uint i=0; i<RZ_MAX_BUILDING_PER_OUTPOST; i++)
52 _Buildings[i].Id = i;
56 //===================================================================================
57 CVillage::~CVillage()
61 //===================================================================================
62 /*virtual*/ bool CVillage::needCompleteLoading(const NLMISC::CVector &pos) const
64 nlassert(_Scene); // should call built
65 return _IG.needCompleteLoading(pos);
68 //===================================================================================
69 /*virtual*/ void CVillage::update(const NLMISC::CVector &pos)
71 nlassert(_Scene); // should call built
72 _IG.update(pos);
75 //===================================================================================
76 /*virtual*/ void CVillage::forceUpdate(const NLMISC::CVector &pos, NLMISC::IProgressCallback &progress)
78 nlassert(_Scene); // should call built
79 _IG.forceUpdate(pos, progress);
82 //===================================================================================
83 bool CVillage::setupFromSheet(NL3D::UScene *scene, const CVillageSheet &sheet, CStreamableIG::TString2IG *loadedIGMap /*=NULL*/)
85 nlassert(!_Scene); // should be built only once
86 nlassert(scene);
91 NLMISC::CVector pos;
92 pos.z = sheet.Altitude;
93 std::string zoneName;
95 NLMISC::CVector2f zonePos;
96 if (!getPosFromZoneName(sheet.Zone, zonePos))
98 nlwarning("Village : invalid zone name (%s)", sheet.Zone.c_str());
99 return false;
101 pos.x = zonePos.x + sheet.CenterX;
102 pos.y = zonePos.y + sheet.CenterY;
104 _IG.init(scene, pos, sheet.ForceLoadDist, sheet.LoadDist, sheet.UnloadDist);
105 _IG.setLoadedIGMap(loadedIGMap);
108 _IG.reserve((uint)sheet.IGs.size());
110 _IG.Name = sheet.Name;
112 // For each children
113 for(uint k = 0; k < sheet.IGs.size(); ++k)
115 _IG.addIG(sheet.IGs[k].IgName, sheet.IGs[k].ParentName, CVector::Null, CQuat::Identity);
117 _Scene = scene;
118 _IsOutpost= false;
119 return true;
122 //===================================================================================
123 void CVillage::forceUnload()
125 _IG.forceUnload();
128 //===================================================================================
129 void CVillage::registerObserver(IIGObserver *obs)
131 _IG.registerObserver(obs);
135 //===================================================================================
136 void CVillage::removeObserver(IIGObserver *obs)
138 _IG.removeObserver(obs);
142 //===================================================================================
143 bool CVillage::isObserver(IIGObserver *obs) const
145 return _IG.isObserver(obs);
148 //===================================================================================
149 bool CVillage::enumIGs(IIGEnum *callback)
151 return _IG.enumIGs(callback);
155 // ***************************************************************************
156 // ***************************************************************************
157 // OUTPOST
158 // ***************************************************************************
159 // ***************************************************************************
162 //===================================================================================
163 bool CVillage::setupOutpost(NL3D::UScene *scene, const CContinentParameters::CZC &zone, sint32 /* outpost */, CStreamableIG::TString2IG *loadedIGMap)
165 nlassert(!_Scene); // should be built only once
166 nlassert(scene);
168 // Get the zone position (for async loading)
169 NLMISC::CVector pos;
170 NLMISC::CVector2f zonePos;
171 if (!getPosFromZoneName(zone.Name, zonePos))
173 nlwarning("Outpost : invalid zone name (%s)", zone.Name.c_str());
174 return false;
176 pos.x = zonePos.x;
177 pos.y = zonePos.y;
178 pos.z = 0;
180 // Setup the IG
181 _IG.init(scene, pos, zone.ForceLoadDist, zone.LoadDist, zone.UnloadDist);
182 _IG.setLoadedIGMap(loadedIGMap);
183 _IG.reserve(RZ_MAX_BUILDING_PER_OUTPOST);
185 _Scene = scene;
186 _IsOutpost = true;
187 return true;
190 //===================================================================================
191 void CVillage::setBuildingPosition (uint building, const NLMISC::CQuat &rot, const NLMISC::CVector &pos)
193 // Set the building position and rotation
194 if (building<RZ_MAX_BUILDING_PER_OUTPOST)
196 _Buildings[building].Rotation = rot;
197 _Buildings[building].Position = pos;
201 //===================================================================================
202 void CVillage::initOutpost ()
204 if (_IsOutpost)
206 // Init the ZC with ruins
207 CSheetId ruins ("ruins.building");
208 for (uint i=0; i<RZ_MAX_BUILDING_PER_OUTPOST; i++)
210 updateBuilding(i, ruins);
215 //===================================================================================
216 void CVillage::removeOutpost ()
218 if (_IsOutpost)
220 // Force form to be reseted so next time outpost is reloaded
221 for (uint i=0; i<RZ_MAX_BUILDING_PER_OUTPOST; i++)
223 _Buildings[i].CurrentSheetId = CSheetId::Unknown;
228 //===================================================================================
229 void CVillage::updateBuilding(uint buildingId, NLMISC::CSheetId newForm)
231 if(buildingId>=RZ_MAX_BUILDING_PER_OUTPOST)
232 return;
233 CBuilding &building= _Buildings[buildingId];
235 // Form has changed ?
236 if (building.CurrentSheetId != newForm)
238 // Resize the streamable ig, if needed
239 for (uint i=_IG.getIGNum(); i<RZ_MAX_BUILDING_PER_OUTPOST; i++)
241 // todo hulud add rotation
242 _IG.addIG("", "", _Buildings[i].Position, _Buildings[i].Rotation);
245 // Ig name for this building
246 string igName;
248 // If the Sheet id is unknown, just remove the old building if there was one.
249 if(newForm != CSheetId::Unknown)
251 // Get a pointer on the converted sheet into the client.
252 CEntitySheet *entitySheet = SheetMngr.get(newForm);
253 const CBuildingSheet *bldSh = dynamic_cast<const CBuildingSheet *>(entitySheet);
254 if (bldSh)
256 // todo hulud here, manage multi igs for multi building state
257 igName = bldSh->BuildedIg;
261 // Set the building IG
262 _IG.setIG(building.Id, igName, "");
263 building.CurrentSheetId = newForm;