Planeshift
pseffect.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_HEADER
21 #define PS_EFFECT_HEADER
22 
23 #include <iutil/document.h>
24 #include <csutil/csstring.h>
25 #include <csutil/array.h>
26 #include <csgeom/matrix3.h>
27 #include <iengine/movable.h>
28 #include <csutil/ref.h>
29 #include <csutil/scf.h>
30 #include <iutil/virtclk.h>
31 #include <iengine/movable.h>
32 #include <iengine/objwatch.h>
33 #include <csutil/parray.h>
34 
35 struct iDocumentNode;
36 struct iLoaderContext;
37 struct iView;
38 
39 class psEffectAnchor;
40 class psEffectObj;
41 class psEffect2DRenderer;
43 
51 class psEffect
52 {
53 public:
57  psEffect();
58 
62  ~psEffect();
63 
76  psEffectAnchor* CreateAnchor(const csString &type);
77 
84  size_t AddAnchor(psEffectAnchor* anchor);
85 
95  bool Load(iDocumentNode* node, iView* parentView, psEffect2DRenderer* renderer2d,
96  iLoaderContext* ldr_context);
97 
110  unsigned int Render(iSectorList* sectors, const csVector3 &offset, iMeshWrapper* attachPos,
111  iMeshWrapper* attachTarget, const csVector3 &up, const unsigned int uniqueIDOverride = 0,
112  bool rotateWithMesh = false);
113 
125  unsigned int Render(iSector* sector, const csVector3 &offset, iMeshWrapper* attachPos,
126  iMeshWrapper* attachTarget, const csVector3 &up, const unsigned int uniqueIDOverride = 0);
127 
134  bool Update(csTicks elapsed);
135 
139  psEffect* Clone() const;
140 
146  unsigned int GetUniqueID() const;
147 
154  void SetKillTime(const int newKillTime);
155 
159  int GetKillTime() const;
160 
164  bool SetFrameParamScalings(const float* scale);
165 
171  float GetAnimLength() const;
172 
178  size_t GetAnchorCount() const;
179 
186  psEffectAnchor* GetAnchor(size_t idx) const;
187 
194  psEffectAnchor* FindAnchor(const csString &anchorName) const;
195 
201  size_t GetObjCount() const;
202 
209  psEffectObj* GetObj(size_t idx) const;
210 
217  psEffectObj* FindObj(const csString &objName) const;
218 
224  const csString &GetName() const;
225 
230 
234  bool IsVisible();
235 
239  void Show();
240 
244  void Hide();
245 
249  void SetScaling(float scale, float aspect);
250 
251 private:
255  class psEffectMovableListener : public scfImplementation1<psEffectMovableListener,iMovableListener>
256  {
257  private:
258  bool movableDead;
259  bool movableChanged;
260  iMovable* movable;
261 
262  public:
263  psEffectMovableListener()
264  : scfImplementationType(this)
265  {
266  movableDead = false;
267  movableChanged = false;
268  movable = 0;
269  }
270 
271  virtual ~psEffectMovableListener() {}
272 
276  virtual void MovableChanged(iMovable* movable)
277  {
278  movableChanged = true;
279  this->movable = movable;
280  }
281 
285  virtual void MovableDestroyed(iMovable* /*movable*/)
286  {
287  movableDead = true;
288  this->movable = 0;
289  movableChanged = false;
290  }
291 
297  bool IsMovableDead() const
298  {
299  return movableDead;
300  }
301 
310  bool GrabNewData(iSectorList* &newSectors, csVector3 &newPos, csMatrix3 &newTransf)
311  {
312  if(!movableChanged || !movable)
313  return false;
314 
315  newPos = movable->GetFullPosition();
316  newSectors = movable->GetSectors();
317  newTransf = movable->GetFullTransform().GetT2O();
318 
319  movableChanged = false;
320  return true;
321  }
322 
330  bool GrabNewData(csVector3 &newPos, csMatrix3 &newTransf)
331  {
332  if(!movableChanged || !movable)
333  return false;
334 
335  newPos = movable->GetFullPosition();
336  newTransf = movable->GetFullTransform().GetT2O();
337  movableChanged = false;
338  return true;
339  }
340 
341  csVector3 GetPosition()
342  {
343  if(movable)
344  return movable->GetFullPosition();
345  else
346  return csVector3(0, 0, 0);
347  }
348  };
349 
350  csRef<psEffectMovableListener> positionListener;
351  csRef<psEffectMovableListener> targetListener;
352 
353  bool visible;
354  unsigned int uniqueID;
355  csString name;
356 
357  csPDelArray<psEffectAnchor> effectAnchors;
358  csPDelArray<psEffectObj> effectObjs;
359 
360  size_t mainTextObj;
361  psEffect2DRenderer* renderer2d;
362 };
363 
366 #endif
psEffectObj * FindObj(const csString &objName) const
Finds an effect obj of the given name.
~psEffect()
Destructor.
psEffect()
Constructor.
psEffect * Clone() const
Clones the effect.
psEffectAnchor * GetAnchor(size_t idx) const
Returns the effect anchor at the given index.
bool Update(csTicks elapsed)
Updates the spell effect – called every frame.
The manager of all 2D effect elements.
int GetKillTime() const
Returns the time after which this effect will be killed.
size_t GetObjCount() const
Returns the number of effect objs in this effect.
unsigned int GetUniqueID() const
Returns the uniqueID of this effect.
void Hide()
Hides the effect.
psEffectAnchor * CreateAnchor(const csString &type)
Creates an effect anchor given a type string.
The effect class.
Definition: pseffect.h:51
psEffectAnchor * FindAnchor(const csString &anchorName) const
Finds an effect anchor of the given name.
size_t GetAnchorCount() const
Returns the number of effect anchors in this effect.
void SetKillTime(const int newKillTime)
Sets the time after which this effect will be killed.
psEffectObj * GetObj(size_t idx) const
Returns the effect obj at the given index.
bool Load(iDocumentNode *node, iView *parentView, psEffect2DRenderer *renderer2d, iLoaderContext *ldr_context)
Loads the effect from an xml node.
psEffectObjTextable * GetMainTextObj() const
An effect is not much more than a collection of effect objects.
Definition: pseffectobj.h:207
const csString & GetName() const
Gets the name of the effect.
void Show()
Shows the effect.
void SetScaling(float scale, float aspect)
Some effects use these scaling parameters to scale the object.
unsigned int Render(iSectorList *sectors, const csVector3 &offset, iMeshWrapper *attachPos, iMeshWrapper *attachTarget, const csVector3 &up, const unsigned int uniqueIDOverride=0, bool rotateWithMesh=false)
Renders the effect.
bool SetFrameParamScalings(const float *scale)
Set the scalings for each frame parameter.
bool IsVisible()
Returns visibility value.
float GetAnimLength() const
Returns the animation length of the effect.
Effect anchors provide a base location / anchor point for all effect objs.
size_t AddAnchor(psEffectAnchor *anchor)
Adds an effect anchor to this effect.