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/>.
20 #ifndef CL_IG_CALLBACK
21 #define CL_IG_CALLBACK
23 #include "nel/3d/u_instance_group.h"
24 #include "nel/misc/debug.h"
27 #include "timed_fx_manager.h"
41 class UPrimitiveBlock
;
47 /** A class to manage callback (collisions, constructions ..) with igs of the landscape.
48 * Its purpose is to create pacs primitive for objects of the landscape that need them.
49 * The matching primitive for an instance is deduced from its shape name.
50 * Pacs primitives must be loaded at startup.
51 * \author Nicolas Vizerie
52 * \author Nevrax France
55 class CIGCallback
: public CIGNotifier
68 /** Add an ig. Its callbacks primitive will be created when it has been added
71 void addIG(NL3D::UInstanceGroup
*ig
);
72 /** Add an ig with his num ZC. Its callbacks primitive will be created when it has been added
75 void addIGWithNumZC(NL3D::UInstanceGroup
*ig
, sint numZC
);
77 /** Add a vector of instance groups
79 void addIGs(const std::vector
<NL3D::UInstanceGroup
*> &igs
);
80 /** Add a vector of instance groups with the num ZC associated.
82 void addIGsWithNumZC(std::vector
<std::pair
<NL3D::UInstanceGroup
*, sint
> > &igs
);
85 /// Force creation of all zones (not to be used in client side..)
91 /** Set the move container that should be used for collision. This MUST
92 * be called once and only once, unless it is reseted
94 void setMoveContainer(NLPACS::UMoveContainer
*mc
);
95 // Get the move container associated with that object, or NULL if none.
96 NLPACS::UMoveContainer
*getMoveContainer() const { return _MoveContainer
; }
98 /** Add a pacs primitive from its file name.
99 * This may raise an exception if loading failed.
101 void addPacsPrim(const std::string
&fileName
);
102 /** Add all pacs primitives from the given directory.
104 void resetContainer();
109 /** enumerate all currently loaded zone igs
110 * \return false if the enumeration has been stopped
112 bool enumIGs(IIGEnum
*callback
);
115 ///\name Season change
117 // apply change of season on iug (for now, only change the fxs to match the season)
122 ///////////////////////////////////////////////////////////////////////////////////////////////////
123 ///////////////////////////////////////////////////////////////////////////////////////////////////
126 friend class CIGInstance
;
128 typedef std::vector
<CIGInstance
*> TIGInstanceList
;
130 * An instanciated ig and its matching collisions primitives
132 class CIGInstance
: public NL3D::IAddRemoveInstance
,
133 public NL3D::ITransformName
,
134 public NL3D::IIGAddBegin
138 CIGInstance(NL3D::UInstanceGroup
*ig
, CIGCallback
*owner
);
141 * -This release move primitives from the move container
144 /// force this instance to be added
145 void forceAdd() { instanceGroupAdded(); }
146 void numZC(sint num
) {_NumZC
= num
;}
147 NL3D::UInstanceGroup
*getIG() const { return _IG
; }
148 void updateManagedFXs();
150 bool hasManagedFXs() const { return _HasManagedFXs
; }
151 // force to rebuild the sheet vector
152 void buildSheetVector();
153 // earse the sheet vector
154 void eraseSheetVector();
156 typedef std::vector
<NLPACS::UMovePrimitive
*> TMovePrimitiveVect
;
157 typedef std::vector
<CEntitySheet
*> TEntitySheetVect
;
159 void releaseMovePrimitives();
160 ///\name from NL3D::IAddRemoveInstance
162 virtual void instanceGroupAdded();
163 virtual void instanceGroupRemoved();
165 ///\name from NL3D::ITransformName
167 virtual std::string
transformName (uint index
, const std::string
&instanceName
, const std::string
&shapeName
);
169 ///\name from NL3D::IIGAddBegin
171 virtual void startAddingIG(uint numInstances
);
173 /** Called after all instance have been added, and when their sheets have been retrieved.
174 * This is the place to setup parameters from sheets
176 void updateFromSheets();
180 TMovePrimitiveVect _MovePrimitives
;
181 TEntitySheetVect _EntitySheets
; // matching sheets for each instance (or NULL), they are used only after the instance have been added to the scene
183 NL3D::UInstanceGroup
*_IG
; // the IG we're looking at
184 sint _NumZC
; // >= 0 if valid.
185 bool _HasManagedFXs
; // true if there are managed fx in the group, otherwise, _ManagedFXHandle is not used
186 CTimedFXManager::TFXGroupHandle _ManagedFXHandle
;
190 NLPACS::UMoveContainer
*_MoveContainer
;
191 TIGInstanceList _IGInstances
;
198 /** Debug purpose only: create instances in a scene from the content of a move container.
199 * The created instances are static. Their pointer can be retrieved in a pointer
200 * The following shapes must be available :
201 * unit_box.shape : a box of 1 x 1 x 1 centered at the origin
202 * unit_cylinder.shape : a cylinder of height 1, radius 1
204 void createInstancesFromMoveContainer(NL3D::UScene
*scene
, NLPACS::UMoveContainer
*mc
, std::vector
<NL3D::UInstance
> *instances
= NULL
);