Planeshift

pseffect.h

Go to the documentation of this file.
00001 /*
00002  * Author: Andrew Robberts
00003  *
00004  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef PS_EFFECT_HEADER
00021 #define PS_EFFECT_HEADER
00022 
00023 #include <iutil/document.h>
00024 #include <csutil/csstring.h>
00025 #include <csutil/array.h>
00026 #include <csgeom/matrix3.h>
00027 #include <iengine/movable.h>
00028 #include <csutil/ref.h>
00029 #include <csutil/scf.h>
00030 #include <iutil/virtclk.h>
00031 #include <iengine/movable.h>
00032 #include <iengine/objwatch.h>
00033 #include <csutil/parray.h>
00034 
00035 struct iDocumentNode;
00036 struct iLoaderContext;
00037 struct iView;
00038 
00039 class psEffectAnchor;
00040 class psEffectObj;
00041 class psEffect2DRenderer;
00042 class psEffectObjTextable;
00043 
00051 class psEffect
00052 {
00053 public:
00057     psEffect();
00058 
00062     ~psEffect();
00063 
00076     psEffectAnchor* CreateAnchor(const csString &type);
00077 
00084     size_t AddAnchor(psEffectAnchor* anchor);
00085 
00095     bool Load(iDocumentNode* node, iView* parentView, psEffect2DRenderer* renderer2d,
00096               iLoaderContext* ldr_context);
00097 
00110     unsigned int Render(iSectorList* sectors, const csVector3 &offset, iMeshWrapper* attachPos,
00111                         iMeshWrapper* attachTarget, const csVector3 &up, const unsigned int uniqueIDOverride = 0,
00112                         bool rotateWithMesh = false);
00113 
00125     unsigned int Render(iSector* sector, const csVector3 &offset, iMeshWrapper* attachPos,
00126                         iMeshWrapper* attachTarget, const csVector3 &up, const unsigned int uniqueIDOverride = 0);
00127 
00134     bool Update(csTicks elapsed);
00135 
00139     psEffect* Clone() const;
00140 
00146     unsigned int GetUniqueID() const;
00147 
00154     void SetKillTime(const int newKillTime);
00155 
00159     int GetKillTime() const;
00160 
00164     bool SetFrameParamScalings(const float* scale);
00165 
00171     float GetAnimLength() const;
00172 
00178     size_t GetAnchorCount() const;
00179 
00186     psEffectAnchor* GetAnchor(size_t idx) const;
00187 
00194     psEffectAnchor* FindAnchor(const csString &anchorName) const;
00195 
00201     size_t GetObjCount() const;
00202 
00209     psEffectObj* GetObj(size_t idx) const;
00210 
00217     psEffectObj* FindObj(const csString &objName) const;
00218 
00224     const csString &GetName() const;
00225 
00229     psEffectObjTextable* GetMainTextObj() const;
00230 
00234     bool IsVisible();
00235 
00239     void Show();
00240 
00244     void Hide();
00245 
00249     void SetScaling(float scale, float aspect);
00250 
00251 private:
00255     class psEffectMovableListener : public scfImplementation1<psEffectMovableListener,iMovableListener>
00256     {
00257     private:
00258         bool movableDead;
00259         bool movableChanged;
00260         iMovable* movable;
00261 
00262     public:
00263         psEffectMovableListener()
00264             : scfImplementationType(this)
00265         {
00266             movableDead = false;
00267             movableChanged = false;
00268             movable = 0;
00269         }
00270 
00271         virtual ~psEffectMovableListener() {}
00272 
00276         virtual void MovableChanged(iMovable* movable)
00277         {
00278             movableChanged = true;
00279             this->movable = movable;
00280         }
00281 
00285         virtual void MovableDestroyed(iMovable* /*movable*/)
00286         {
00287             movableDead = true;
00288             this->movable = 0;
00289             movableChanged = false;
00290         }
00291 
00297         bool IsMovableDead() const
00298         {
00299             return movableDead;
00300         }
00301 
00310         bool GrabNewData(iSectorList* &newSectors, csVector3 &newPos, csMatrix3 &newTransf)
00311         {
00312             if(!movableChanged || !movable)
00313                 return false;
00314 
00315             newPos = movable->GetFullPosition();
00316             newSectors = movable->GetSectors();
00317             newTransf = movable->GetFullTransform().GetT2O();
00318 
00319             movableChanged = false;
00320             return true;
00321         }
00322 
00330         bool GrabNewData(csVector3 &newPos, csMatrix3 &newTransf)
00331         {
00332             if(!movableChanged || !movable)
00333                 return false;
00334 
00335             newPos = movable->GetFullPosition();
00336             newTransf = movable->GetFullTransform().GetT2O();
00337             movableChanged = false;
00338             return true;
00339         }
00340 
00341         csVector3 GetPosition()
00342         {
00343             if(movable)
00344                 return movable->GetFullPosition();
00345             else
00346                 return csVector3(0, 0, 0);
00347         }
00348     };
00349 
00350     csRef<psEffectMovableListener> positionListener;
00351     csRef<psEffectMovableListener> targetListener;
00352 
00353     bool visible;
00354     unsigned int uniqueID;
00355     csString name;
00356 
00357     csPDelArray<psEffectAnchor> effectAnchors;
00358     csPDelArray<psEffectObj> effectObjs;
00359 
00360     size_t mainTextObj;
00361     psEffect2DRenderer* renderer2d;
00362 };
00363 
00366 #endif