Planeshift
pseffectmanager.h
Go to the documentation of this file.
1 /*
2  * Author: Andrew Robberts
3  *
4  * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef PS_EFFECT_MANAGER_HEADER
21 #define PS_EFFECT_MANAGER_HEADER
22 
23 
24 // CS includes
25 #include <csutil/csstring.h>
26 #include <csutil/array.h>
27 #include <csutil/parray.h>
28 #include <csutil/ref.h>
29 #include <iengine/collection.h>
30 #include <iutil/virtclk.h>
31 #include <csutil/hash.h>
32 #include <imap/reader.h>
33 #include <ivideo/graph3d.h>
34 #include <csutil/scf_implementation.h>
35 #include <csutil/threading/rwmutex.h>
36 
38 
39 struct iLight;
40 struct iMeshWrapper;
41 struct iMovable;
42 struct iSector;
43 struct iSectorList;
44 struct iThreadReturn;
45 struct iView;
46 class psEffect;
47 class psLight;
48 
49 class psEffectManager;
50 
56 {
57 public:
58  csString name;
59  csArray<csString> effects;
60 };
61 
62 
66 class psEffectLoader : public scfImplementation1<psEffectLoader,iLoaderPlugin>
67 {
68 public:
70 
72  void SetManager(psEffectManager* manager);
73 
74  // used to handle and parse the <addon> tags.
75  csPtr<iBase> Parse(iDocumentNode* node, iStreamSource*, iLoaderContext* ldr_context, iBase* context);
76 
77  bool IsThreadSafe()
78  {
79  return true;
80  }
81 
82 private:
83  psEffectManager* manager;
84  CS::Threading::ReadWriteMutex parseLock;
85 };
86 
87 
89 {
90 public:
91  psEffectManager(iObjectRegistry* objReg);
92  virtual ~psEffectManager();
93 
101  csPtr<iThreadReturn> LoadEffects(const csString &fileName, iView* parentView);
102 
110  bool LoadFromEffectsList(const csString &fileName, iView* parentView);
111 
120  bool LoadFromDirectory(const csString &path, bool includeSubDirs, iView* parentView);
121 
128  bool DeleteEffect(unsigned int effectID);
129 
143  unsigned int RenderEffect(const csString &effectName, const csVector3 &offset, iMeshWrapper* attachPos,
144  iMeshWrapper* attachTarget=0, const csVector3 &up=csVector3(0,1,0),
145  const unsigned int uniqueIDOverride = 0, bool rotateWithMesh = false, const float* scale = NULL);
146 
159  unsigned int RenderEffect(const csString &effectName, iSector* sector, const csVector3 &pos,
160  iMeshWrapper* attachTarget, const csVector3 &up=csVector3(0,1,0),
161  const unsigned int uniqueIDOverride = 0, const float* scale = NULL);
162 
175  unsigned int RenderEffect(const csString &effectName, iSectorList* sectors, const csVector3 &pos,
176  iMeshWrapper* attachTarget=0, const csVector3 &up=csVector3(0,1,0),
177  const unsigned int uniqueIDOverride = 0, const float* scale = NULL);
178 
179  unsigned int AttachLight(const char* name, const csVector3 &pos,
180  float radius, const csColor &colour, iMeshWrapper* mw);
181  void DetachLight(unsigned int lightID);
182 
188  void Update(csTicks elapsed = 0);
189 
193  void Clear();
194 
201  psEffect* FindEffect(unsigned int ID) const;
202 
209  psEffect* FindEffect(const csString &name) const;
210 
216  csHash<psEffect*, csString>::GlobalIterator GetEffectsIterator();
217 
218 
225  void ShowEffect(unsigned int id,bool value = true);
226 
227  void AddEffect(const char* name, psEffect* effect);
228 
229  iView* GetView() const
230  {
231  return view;
232  }
233 
234  void Render2D(iGraphics3D* g3d, iGraphics2D* g2d);
235 
237  {
238  return effect2DRenderer;
239  }
240 
241 private:
242 
243  iObjectRegistry* object_reg;
244 
246  csRef<iVirtualClock> vc;
247 
252  csHash<psEffect*, csString> effectFactories;
253 
255  csHash<psEffect*, unsigned int> actualEffects;
256 
258  csRef<iCollection> effectsCollection;
259 
260  iView* view;
261 
263  csRef<psEffectLoader> effectLoader;
264 
265  psEffect2DRenderer* effect2DRenderer;
266 
267  csHash<psLight*, unsigned int> lightList;
268 };
269 
272 #endif
The manager of all 2D effect elements.
psEffect2DRenderer * Get2DRenderer() const
csArray< csString > effects
The effect class.
Definition: pseffect.h:51
Loader plugin for loading PS effects.
iView * GetView() const