1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
28 #include "pacs_client.h"
29 #include "user_entity.h"
30 #include "ig_callback.h"
31 #include "ig_client.h"
40 using namespace NLMISC
;
41 using namespace NLPACS
;
47 UMoveContainer
*PACS
= 0;
48 UGlobalRetriever
*GR
= 0;
49 URetrieverBank
*RB
= 0;
50 const float LRRefeshRadius
= 400.f
;
51 CIGCallback
*IGCallbacks
= 0;
53 const uint8 staticWI
= 0; // Static World Image
54 const uint8 dynamicWI
= 1; // Dynamic World Image
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;
72 //-----------------------------------------------
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
);
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);
98 nlwarning("Could not create global retriever for %s, %s", rbank
, gr
);
101 // Try to create a PACS with another method.
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.
107 PACS
->setAsStatic(staticWI
);
109 nlwarning("initPACS: cannot create PACS at all.");
112 //-----------------------------------------------
115 //-----------------------------------------------
118 // Move container presents ?
121 UMoveContainer::deleteMoveContainer (PACS
);
124 // Global retriever presents ?
127 UGlobalRetriever::deleteGlobalRetriever (GR
);
130 // Retriever bank loader ?
133 URetrieverBank::deleteRetrieverBank (RB
);
138 //-----------------------------------------------
140 // Get the cluster from a global position.
141 //-----------------------------------------------
142 UInstanceGroup
*getCluster(const UGlobalPosition
&gp
)
144 // Cannot find the cluster if GR is Null.
148 const string
&strPos
= GR
->getIdentifier(gp
);
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())
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"];
173 nlwarning("getCluster : %s : unknown Identifier.", strPos
.c_str());
178 //-----------------------------------------------
179 void initLandscapeIGCallbacks()
181 releaseLandscapeIGCallbacks();
182 nlassert(IGCallbacks
== NULL
); // should be initilized only once!
183 IGCallbacks
= new CIGCallback();
187 //-----------------------------------------------
188 void releaseLandscapeIGCallbacks()
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());
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
)
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
);
236 NLMISC::CIFile inputFile
;
237 if(!inputFile
.open(lookupPathPrimList
, false))
239 nlwarning("Couldn't open %s", primitiveListFile
);
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());
260 nlwarning("Couldn't find %s", tmpBuff
);