1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
21 #include <nel/misc/types_nl.h>
25 #include <nel/pacs/u_retriever_bank.h>
26 #include <nel/pacs/u_global_retriever.h>
27 #include <nel/pacs/u_move_container.h>
28 #include <nel/pacs/u_move_primitive.h>
30 #include <nel/3d/u_scene.h>
31 #include <nel/3d/u_instance_group.h>
32 #include <nel/3d/u_visual_collision_manager.h>
34 #include <nel/3d/u_instance.h>
36 #include <nel/misc/vectord.h>
37 #include <nel/misc/config_file.h>
39 #include "snowballs_client.h"
40 #include "landscape.h"
49 using namespace NLMISC
;
51 using namespace NLPACS
;
55 extern ULandscape
*Landscape
;
57 /*******************************************************************
59 *******************************************************************/
61 // The retriever bank used in the world
62 URetrieverBank
*RetrieverBank
= NULL
;
63 // The global retriever used for pacs
64 UGlobalRetriever
*GlobalRetriever
= NULL
;
65 // The move container used for dynamic collisions
66 UMoveContainer
*MoveContainer
= NULL
;
68 // The collision manager for ground snapping
69 UVisualCollisionManager
*VisualCollisionManager
= NULL
;
71 /*******************************************************************
73 *******************************************************************/
75 // The collision primitive for the instances in the landscape
76 static vector
<UMovePrimitive
*> _InstancesMovePrimitives
;
84 // check stuff we need for this to init correctly
89 // check stuff we can't have yet
90 nlassert(!RetrieverBank
);
91 nlassert(!GlobalRetriever
);
92 nlassert(!MoveContainer
);
93 nlassert(!VisualCollisionManager
);
95 // init the global retriever
96 RetrieverBank
= URetrieverBank::createRetrieverBank(ConfigFile
->getVar("RetrieverBankName").asString().c_str());
97 nlassert(RetrieverBank
);
99 // create the retriever bank
100 GlobalRetriever
= UGlobalRetriever::createGlobalRetriever(ConfigFile
->getVar("GlobalRetrieverName").asString().c_str(), RetrieverBank
);
101 nlassert(GlobalRetriever
);
103 // create the move primitive
104 MoveContainer
= UMoveContainer::createMoveContainer(GlobalRetriever
, 100, 100, 6.0);
105 nlassert(MoveContainer
);
107 // create a visual collision manager
108 // this should not be in pacs, but this is too close to pacs to be put elsewhere
109 // -- -- put it elsewhere anyways, the other code in this page can be made re-usable
110 // to share between the client and the collision service.
111 VisualCollisionManager
= Scene
->createVisualCollisionManager();
112 nlassert(VisualCollisionManager
);
113 VisualCollisionManager
->setLandscape(Landscape
);
115 // -- -- move this to snowballs specific game task
116 // create a move primitive for each instance in the instance group
117 for (uint j
= 0; j
< InstanceGroups
.size(); ++j
)
119 for (uint i
= 0; i
< InstanceGroups
[j
]->getNumInstance(); ++i
)
121 UMovePrimitive
*primitive
= MoveContainer
->addCollisionablePrimitive(0, 1);
122 primitive
->setPrimitiveType(UMovePrimitive::_2DOrientedCylinder
);
123 primitive
->setReactionType(UMovePrimitive::DoNothing
);
124 primitive
->setTriggerType(UMovePrimitive::NotATrigger
);
125 primitive
->setCollisionMask(OtherCollisionBit
+SelfCollisionBit
+SnowballCollisionBit
);
126 primitive
->setOcclusionMask(StaticCollisionBit
);
127 primitive
->setObstacle(true);
129 // setup the radius of each mesh in the instance group
130 string name
= InstanceGroups
[j
]->getShapeName(i
);
133 // -- -- improve this
134 if (strlwr(name
) == "pi_po_igloo_a") rad
= 4.5f
;
135 else if (strlwr(name
) == "pi_po_snowman_a") rad
= 1.0f
;
136 else if (strlwr(name
) == "pi_po_pinetree_a") rad
= 2.0f
;
137 else if (strlwr(name
) == "pi_po_tree_a") rad
= 2.0f
;
138 else if (strlwr(name
) == "pi_po_pingoo_stat_a") rad
= 1.0f
;
139 else if (strlwr(name
) == "pi_po_gnu_stat_a") rad
= 1.0f
;
143 nlwarning ("Instance name '%s' doesn't have a good radius for collision", name
.c_str());
146 primitive
->setRadius(rad
);
147 primitive
->setHeight(6.0f
);
149 primitive
->insertInWorldImage(0);
150 CVector pos
= InstanceGroups
[j
]->getInstancePos(i
);
151 primitive
->setGlobalPosition(CVectorD(pos
.x
, pos
.y
, pos
.z
-1.5f
), 0);
152 _InstancesMovePrimitives
.push_back(primitive
);
159 // delete all move primitives
160 if (!MoveContainer
) nlwarning("_InstancesMovePrimitives: !MoveContainer");
163 vector
<UMovePrimitive
*>::iterator
it(_InstancesMovePrimitives
.begin()), end(_InstancesMovePrimitives
.end());
164 for (; it
!= end
; ++it
) MoveContainer
->removePrimitive(*it
);
165 _InstancesMovePrimitives
.clear();
168 // delete all allocated objects
169 if (!GlobalRetriever
) nlwarning("GlobalRetriever: !GlobalRetriever");
170 else { UGlobalRetriever::deleteGlobalRetriever(GlobalRetriever
); GlobalRetriever
= NULL
; }
171 if (!RetrieverBank
) nlwarning("RetrieverBank: !RetrieverBank");
172 else { URetrieverBank::deleteRetrieverBank(RetrieverBank
); RetrieverBank
= NULL
; }
173 if (!MoveContainer
) nlwarning("MoveContainer: !MoveContainer");
174 else { UMoveContainer::deleteMoveContainer(MoveContainer
); MoveContainer
= NULL
; }
176 // delete the visual collision manager
177 if (!Scene
) nlwarning("VisualCollisionManager: !Scene");
178 else if (!VisualCollisionManager
) nlwarning("VisualCollisionManager: !VisualCollisionManager");
179 else { Scene
->deleteVisualCollisionManager(VisualCollisionManager
); VisualCollisionManager
= NULL
; }
182 } /* namespace SBCLIENT */