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/>.
25 #include "pacs_client.h"
26 #include "user_entity.h"
27 #include "ig_callback.h"
28 #include "ig_client.h"
37 using namespace NLMISC
;
38 using namespace NLPACS
;
44 UMoveContainer
*PACS
= 0;
45 UGlobalRetriever
*GR
= 0;
46 URetrieverBank
*RB
= 0;
47 const float LRRefeshRadius
= 400.f
;
48 CIGCallback
*IGCallbacks
= 0;
50 const uint8 staticWI
= 0; // Static World Image
51 const uint8 dynamicWI
= 1; // Dynamic World Image
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;
69 //-----------------------------------------------
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
);
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);
95 nlwarning("Could not create global retriever for %s, %s", rbank
, gr
);
98 // Try to create a PACS with another method.
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.
104 PACS
->setAsStatic(staticWI
);
106 nlwarning("initPACS: cannot create PACS at all.");
109 //-----------------------------------------------
112 //-----------------------------------------------
115 // Move container presents ?
118 UMoveContainer::deleteMoveContainer (PACS
);
121 // Global retriever presents ?
124 UGlobalRetriever::deleteGlobalRetriever (GR
);
127 // Retriever bank loader ?
130 URetrieverBank::deleteRetrieverBank (RB
);
135 //-----------------------------------------------
137 // Get the cluster from a global position.
138 //-----------------------------------------------
139 UInstanceGroup
*getCluster(const UGlobalPosition
&gp
)
141 // Cannot find the cluster if GR is Null.
145 const string
&strPos
= GR
->getIdentifier(gp
);
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())
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"];
170 nlwarning("getCluster : %s : unknown Identifier.", strPos
.c_str());
175 //-----------------------------------------------
176 void initLandscapeIGCallbacks()
178 releaseLandscapeIGCallbacks();
179 nlassert(IGCallbacks
== NULL
); // should be initilized only once!
180 IGCallbacks
= new CIGCallback();
184 //-----------------------------------------------
185 void releaseLandscapeIGCallbacks()
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());
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
)
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
);
233 NLMISC::CIFile inputFile
;
234 if(!inputFile
.open(lookupPathPrimList
, false))
236 nlwarning("Couldn't open %s", primitiveListFile
);
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());
257 nlwarning("Couldn't find %s", tmpBuff
);