Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / pacs_client.cpp
blobd7b2674c4eae7b6cfec04482606951b2e5e27be5
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) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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 /////////////
24 // INCLUDE //
25 /////////////
26 #include "stdpch.h"
27 // Client.
28 #include "pacs_client.h"
29 #include "user_entity.h"
30 #include "ig_callback.h"
31 #include "ig_client.h"
33 #ifdef DEBUG_NEW
34 #define new DEBUG_NEW
35 #endif
37 ///////////
38 // USING //
39 ///////////
40 using namespace NLMISC;
41 using namespace NLPACS;
44 ////////////
45 // GLOBAL //
46 ////////////
47 UMoveContainer *PACS = 0;
48 UGlobalRetriever *GR = 0;
49 URetrieverBank *RB = 0;
50 const float LRRefeshRadius = 400.f;
51 CIGCallback *IGCallbacks = 0;
52 // World Images
53 const uint8 staticWI = 0; // Static World Image
54 const uint8 dynamicWI = 1; // Dynamic World Image
55 // Collision Masks.
56 const UMovePrimitive::TCollisionMask MaskColNone = 0x00000000;
57 const UMovePrimitive::TCollisionMask MaskColPlayer = 0x00000001;
58 const UMovePrimitive::TCollisionMask MaskColNpc = 0x00000002;
59 const UMovePrimitive::TCollisionMask MaskColDoor = 0x00000004;
60 const UMovePrimitive::TCollisionMask MaskColAll = 0xFFFFFFFF;
61 TPacsPrimMap PacsPrims;
63 const uint16 UserDataTree = 0;
64 const uint16 UserDataLift = 1;
65 const uint16 UserDataDoor = 2;
66 const uint16 UserDataEntity = 3;
69 ///////////////
70 // FUNCTIONS //
71 ///////////////
72 //-----------------------------------------------
73 // initPACS :
74 // Initialize PACS.
75 //-----------------------------------------------
76 void initPACS(const char* rbank, const char* gr, NLMISC::IProgressCallback &/* progress */)
78 // Check old PACS is well released.
79 nlassertex(RB==0, ("RB should be Null before the init."));
80 nlassertex(GR==0, ("GR should be Null before the init."));
81 nlassertex(PACS==0, ("PACS should be Null before the init."));
83 if(rbank != 0 && gr != 0)
85 RB = NLPACS::URetrieverBank::createRetrieverBank(rbank, false);
86 GR = NLPACS::UGlobalRetriever::createGlobalRetriever(gr, RB);
87 if (GR)
89 CAABBox cbox = GR->getBBox();
91 uint gw = (uint)(cbox.getHalfSize().x*2.0 / RYZOM_ENTITY_SIZE_MAX) + 1;
92 uint gh = (uint)(cbox.getHalfSize().y*2.0 / RYZOM_ENTITY_SIZE_MAX) + 1;
95 PACS = UMoveContainer::createMoveContainer(GR, gw, gh, RYZOM_ENTITY_SIZE_MAX, 2);
97 else
98 nlwarning("Could not create global retriever for %s, %s", rbank, gr);
101 // Try to create a PACS with another method.
102 if(PACS == 0)
103 PACS = UMoveContainer::createMoveContainer(15000.0, -25000.0, 20000.0, -20000.0, 16, 16, RYZOM_ENTITY_SIZE_MAX, 2);
105 // Set the static world image.
106 if(PACS)
107 PACS->setAsStatic(staticWI);
108 else
109 nlwarning("initPACS: cannot create PACS at all.");
110 }// initPACS //
112 //-----------------------------------------------
113 // releasePACS :
114 // Initialize PACS.
115 //-----------------------------------------------
116 void releasePACS ()
118 // Move container presents ?
119 if (PACS)
121 UMoveContainer::deleteMoveContainer (PACS);
122 PACS = NULL;
124 // Global retriever presents ?
125 if (GR)
127 UGlobalRetriever::deleteGlobalRetriever (GR);
128 GR = NULL;
130 // Retriever bank loader ?
131 if (RB)
133 URetrieverBank::deleteRetrieverBank (RB);
134 RB = NULL;
136 }// initPACS //
138 //-----------------------------------------------
139 // getCluster :
140 // Get the cluster from a global position.
141 //-----------------------------------------------
142 UInstanceGroup *getCluster(const UGlobalPosition &gp)
144 // Cannot find the cluster if GR is Null.
145 if(GR==0)
146 return 0;
148 const string &strPos = GR->getIdentifier(gp);
149 if(strPos.empty())
150 return 0;
151 // try to find the ig in the loaded ig map
152 std::map<std::string, UInstanceGroup *>::const_iterator igIt = IGLoaded.find(toLowerAscii(strPos));
153 if (igIt != IGLoaded.end())
155 return igIt->second;
158 // searh in the fyros city igs
159 if(strPos == "col_appart")
160 return IGCity["apart.ig"];
161 else if(strPos == "col_forge")
162 return IGCity["forge.ig"];
163 else if(strPos == "col_mairie")
164 return IGCity["mairie.ig"];
165 else if(strPos == "col_taverne")
166 return IGCity["taverne.ig"];
167 else if(strPos == "col_warschool")
168 return IGCity["warschool.ig"];
169 else if("col_street_1" || "col_street_2")
170 return IGCity["street.ig"];
171 else
173 nlwarning("getCluster : %s : unknown Identifier.", strPos.c_str());
174 return 0;
176 }// getCluster //
178 //-----------------------------------------------
179 void initLandscapeIGCallbacks()
181 releaseLandscapeIGCallbacks();
182 nlassert(IGCallbacks == NULL); // should be initilized only once!
183 IGCallbacks = new CIGCallback();
187 //-----------------------------------------------
188 void releaseLandscapeIGCallbacks()
190 delete IGCallbacks;
191 IGCallbacks = NULL;
194 ///===================================================================================
196 void addPacsPrim(const std::string &fileName)
198 std::string ppName = NLMISC::toLowerAscii(NLMISC::CFile::getFilenameWithoutExtension(fileName));
199 if (PacsPrims.find(ppName) != PacsPrims.end())
201 nlwarning(("Pacs primitive " + ppName + " already has been inserted").c_str());
202 return;
204 CUniquePtr<NLPACS::UPrimitiveBlock> pb(NLPACS::UPrimitiveBlock::createPrimitiveBlockFromFile(fileName));
205 PacsPrims[ppName] = pb.release();
208 ///===================================================================================
210 void deletePrimitiveBlocks()
212 for(TPacsPrimMap::iterator it = PacsPrims.begin(); it != PacsPrims.end(); ++it)
214 delete it->second;
216 PacsPrims.clear();
219 ///===================================================================================
221 void initPrimitiveBlocks()
223 //-----------------------------
224 // load pacs landscape collisions
225 //-----------------------------
227 static const char primitiveListFile[] = "landscape_col_prim_pacs_list.txt";
228 std::string lookupPathPrimList = CPath::lookup(primitiveListFile, false, true);
229 if (lookupPathPrimList.empty())
231 nlwarning("Unable to find the file containing pacs primitives list : %s", primitiveListFile);
232 return;
235 char tmpBuff[300];
236 NLMISC::CIFile inputFile;
237 if(!inputFile.open(lookupPathPrimList, false))
239 nlwarning("Couldn't open %s", primitiveListFile);
240 return;
243 while(!inputFile.eof())
245 inputFile.getline(tmpBuff, 300);
246 std::string primFile = CPath::lookup(tmpBuff, false, true);
247 if (!primFile.empty())
251 addPacsPrim(primFile);
253 catch (const NLMISC::Exception &)
255 nlwarning("Error while loading %s", primFile.c_str());
258 else
260 nlwarning("Couldn't find %s", tmpBuff);
264 inputFile.close();