Add custom formatter for regen text
[ryzomcore.git] / ryzom / client / src / pacs_client.cpp
blob7bf4a0195ec8b79f36b39b13414ae30c901d10a9
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/>.
20 /////////////
21 // INCLUDE //
22 /////////////
23 #include "stdpch.h"
24 // Client.
25 #include "pacs_client.h"
26 #include "user_entity.h"
27 #include "ig_callback.h"
28 #include "ig_client.h"
30 #ifdef DEBUG_NEW
31 #define new DEBUG_NEW
32 #endif
34 ///////////
35 // USING //
36 ///////////
37 using namespace NLMISC;
38 using namespace NLPACS;
41 ////////////
42 // GLOBAL //
43 ////////////
44 UMoveContainer *PACS = 0;
45 UGlobalRetriever *GR = 0;
46 URetrieverBank *RB = 0;
47 const float LRRefeshRadius = 400.f;
48 CIGCallback *IGCallbacks = 0;
49 // World Images
50 const uint8 staticWI = 0; // Static World Image
51 const uint8 dynamicWI = 1; // Dynamic World Image
52 // Collision Masks.
53 const UMovePrimitive::TCollisionMask MaskColNone = 0x00000000;
54 const UMovePrimitive::TCollisionMask MaskColPlayer = 0x00000001;
55 const UMovePrimitive::TCollisionMask MaskColNpc = 0x00000002;
56 const UMovePrimitive::TCollisionMask MaskColDoor = 0x00000004;
57 const UMovePrimitive::TCollisionMask MaskColAll = 0xFFFFFFFF;
58 TPacsPrimMap PacsPrims;
60 const uint16 UserDataTree = 0;
61 const uint16 UserDataLift = 1;
62 const uint16 UserDataDoor = 2;
63 const uint16 UserDataEntity = 3;
66 ///////////////
67 // FUNCTIONS //
68 ///////////////
69 //-----------------------------------------------
70 // initPACS :
71 // Initialize PACS.
72 //-----------------------------------------------
73 void initPACS(const char* rbank, const char* gr, NLMISC::IProgressCallback &/* progress */)
75 // Check old PACS is well released.
76 nlassertex(RB==0, ("RB should be Null before the init."));
77 nlassertex(GR==0, ("GR should be Null before the init."));
78 nlassertex(PACS==0, ("PACS should be Null before the init."));
80 if(rbank != 0 && gr != 0)
82 RB = NLPACS::URetrieverBank::createRetrieverBank(rbank, false);
83 GR = NLPACS::UGlobalRetriever::createGlobalRetriever(gr, RB);
84 if (GR)
86 CAABBox cbox = GR->getBBox();
88 uint gw = (uint)(cbox.getHalfSize().x*2.0 / RYZOM_ENTITY_SIZE_MAX) + 1;
89 uint gh = (uint)(cbox.getHalfSize().y*2.0 / RYZOM_ENTITY_SIZE_MAX) + 1;
92 PACS = UMoveContainer::createMoveContainer(GR, gw, gh, RYZOM_ENTITY_SIZE_MAX, 2);
94 else
95 nlwarning("Could not create global retriever for %s, %s", rbank, gr);
98 // Try to create a PACS with another method.
99 if(PACS == 0)
100 PACS = UMoveContainer::createMoveContainer(15000.0, -25000.0, 20000.0, -20000.0, 16, 16, RYZOM_ENTITY_SIZE_MAX, 2);
102 // Set the static world image.
103 if(PACS)
104 PACS->setAsStatic(staticWI);
105 else
106 nlwarning("initPACS: cannot create PACS at all.");
107 }// initPACS //
109 //-----------------------------------------------
110 // releasePACS :
111 // Initialize PACS.
112 //-----------------------------------------------
113 void releasePACS ()
115 // Move container presents ?
116 if (PACS)
118 UMoveContainer::deleteMoveContainer (PACS);
119 PACS = NULL;
121 // Global retriever presents ?
122 if (GR)
124 UGlobalRetriever::deleteGlobalRetriever (GR);
125 GR = NULL;
127 // Retriever bank loader ?
128 if (RB)
130 URetrieverBank::deleteRetrieverBank (RB);
131 RB = NULL;
133 }// initPACS //
135 //-----------------------------------------------
136 // getCluster :
137 // Get the cluster from a global position.
138 //-----------------------------------------------
139 UInstanceGroup *getCluster(const UGlobalPosition &gp)
141 // Cannot find the cluster if GR is Null.
142 if(GR==0)
143 return 0;
145 const string &strPos = GR->getIdentifier(gp);
146 if(strPos.empty())
147 return 0;
148 // try to find the ig in the loaded ig map
149 std::map<std::string, UInstanceGroup *>::const_iterator igIt = IGLoaded.find(toLowerAscii(strPos));
150 if (igIt != IGLoaded.end())
152 return igIt->second;
155 // searh in the fyros city igs
156 if(strPos == "col_appart")
157 return IGCity["apart.ig"];
158 else if(strPos == "col_forge")
159 return IGCity["forge.ig"];
160 else if(strPos == "col_mairie")
161 return IGCity["mairie.ig"];
162 else if(strPos == "col_taverne")
163 return IGCity["taverne.ig"];
164 else if(strPos == "col_warschool")
165 return IGCity["warschool.ig"];
166 else if("col_street_1" || "col_street_2")
167 return IGCity["street.ig"];
168 else
170 nlwarning("getCluster : %s : unknown Identifier.", strPos.c_str());
171 return 0;
173 }// getCluster //
175 //-----------------------------------------------
176 void initLandscapeIGCallbacks()
178 releaseLandscapeIGCallbacks();
179 nlassert(IGCallbacks == NULL); // should be initilized only once!
180 IGCallbacks = new CIGCallback();
184 //-----------------------------------------------
185 void releaseLandscapeIGCallbacks()
187 delete IGCallbacks;
188 IGCallbacks = NULL;
191 ///===================================================================================
193 void addPacsPrim(const std::string &fileName)
195 std::string ppName = NLMISC::toLowerAscii(NLMISC::CFile::getFilenameWithoutExtension(fileName));
196 if (PacsPrims.find(ppName) != PacsPrims.end())
198 nlwarning(("Pacs primitive " + ppName + " already has been inserted").c_str());
199 return;
201 CUniquePtr<NLPACS::UPrimitiveBlock> pb(NLPACS::UPrimitiveBlock::createPrimitiveBlockFromFile(fileName));
202 PacsPrims[ppName] = pb.release();
205 ///===================================================================================
207 void deletePrimitiveBlocks()
209 for(TPacsPrimMap::iterator it = PacsPrims.begin(); it != PacsPrims.end(); ++it)
211 delete it->second;
213 PacsPrims.clear();
216 ///===================================================================================
218 void initPrimitiveBlocks()
220 //-----------------------------
221 // load pacs landscape collisions
222 //-----------------------------
224 static const char primitiveListFile[] = "landscape_col_prim_pacs_list.txt";
225 std::string lookupPathPrimList = CPath::lookup(primitiveListFile, false, true);
226 if (lookupPathPrimList.empty())
228 nlwarning("Unable to find the file containing pacs primitives list : %s", primitiveListFile);
229 return;
232 char tmpBuff[300];
233 NLMISC::CIFile inputFile;
234 if(!inputFile.open(lookupPathPrimList, false))
236 nlwarning("Couldn't open %s", primitiveListFile);
237 return;
240 while(!inputFile.eof())
242 inputFile.getline(tmpBuff, 300);
243 std::string primFile = CPath::lookup(tmpBuff, false, true);
244 if (!primFile.empty())
248 addPacsPrim(primFile);
250 catch (const NLMISC::Exception &)
252 nlwarning("Error while loading %s", primFile.c_str());
255 else
257 nlwarning("Couldn't find %s", tmpBuff);
261 inputFile.close();