Planeshift
|
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_MANAGER_HEADER 00021 #define PS_EFFECT_MANAGER_HEADER 00022 00023 00024 // CS includes 00025 #include <csutil/csstring.h> 00026 #include <csutil/array.h> 00027 #include <csutil/parray.h> 00028 #include <csutil/ref.h> 00029 #include <iengine/collection.h> 00030 #include <iutil/virtclk.h> 00031 #include <csutil/hash.h> 00032 #include <imap/reader.h> 00033 #include <ivideo/graph3d.h> 00034 #include <csutil/scf_implementation.h> 00035 #include <csutil/threading/rwmutex.h> 00036 00037 #include "effects/pseffect2drenderer.h" 00038 00039 struct iLight; 00040 struct iMeshWrapper; 00041 struct iMovable; 00042 struct iSector; 00043 struct iSectorList; 00044 struct iThreadReturn; 00045 struct iView; 00046 class psEffect; 00047 class psLight; 00048 00049 class psEffectManager; 00050 00055 class psEffectGroup 00056 { 00057 public: 00058 csString name; 00059 csArray<csString> effects; 00060 }; 00061 00062 00066 class psEffectLoader : public scfImplementation1<psEffectLoader,iLoaderPlugin> 00067 { 00068 public: 00069 psEffectLoader(); 00070 00072 void SetManager(psEffectManager* manager); 00073 00074 // used to handle and parse the <addon> tags. 00075 csPtr<iBase> Parse(iDocumentNode* node, iStreamSource*, iLoaderContext* ldr_context, iBase* context); 00076 00077 bool IsThreadSafe() 00078 { 00079 return true; 00080 } 00081 00082 private: 00083 psEffectManager* manager; 00084 CS::Threading::ReadWriteMutex parseLock; 00085 }; 00086 00087 00088 class psEffectManager : public csRefCount 00089 { 00090 public: 00091 psEffectManager(iObjectRegistry* objReg); 00092 virtual ~psEffectManager(); 00093 00101 csPtr<iThreadReturn> LoadEffects(const csString &fileName, iView* parentView); 00102 00110 bool LoadFromEffectsList(const csString &fileName, iView* parentView); 00111 00120 bool LoadFromDirectory(const csString &path, bool includeSubDirs, iView* parentView); 00121 00128 bool DeleteEffect(unsigned int effectID); 00129 00143 unsigned int RenderEffect(const csString &effectName, const csVector3 &offset, iMeshWrapper* attachPos, 00144 iMeshWrapper* attachTarget=0, const csVector3 &up=csVector3(0,1,0), 00145 const unsigned int uniqueIDOverride = 0, bool rotateWithMesh = false, const float* scale = NULL); 00146 00159 unsigned int RenderEffect(const csString &effectName, iSector* sector, const csVector3 &pos, 00160 iMeshWrapper* attachTarget, const csVector3 &up=csVector3(0,1,0), 00161 const unsigned int uniqueIDOverride = 0, const float* scale = NULL); 00162 00175 unsigned int RenderEffect(const csString &effectName, iSectorList* sectors, const csVector3 &pos, 00176 iMeshWrapper* attachTarget=0, const csVector3 &up=csVector3(0,1,0), 00177 const unsigned int uniqueIDOverride = 0, const float* scale = NULL); 00178 00179 unsigned int AttachLight(const char* name, const csVector3 &pos, 00180 float radius, const csColor &colour, iMeshWrapper* mw); 00181 void DetachLight(unsigned int lightID); 00182 00188 void Update(csTicks elapsed = 0); 00189 00193 void Clear(); 00194 00201 psEffect* FindEffect(unsigned int ID) const; 00202 00209 psEffect* FindEffect(const csString &name) const; 00210 00216 csHash<psEffect*, csString>::GlobalIterator GetEffectsIterator(); 00217 00218 00225 void ShowEffect(unsigned int id,bool value = true); 00226 00227 void AddEffect(const char* name, psEffect* effect); 00228 00229 iView* GetView() const 00230 { 00231 return view; 00232 } 00233 00234 void Render2D(iGraphics3D* g3d, iGraphics2D* g2d); 00235 00236 psEffect2DRenderer* Get2DRenderer() const 00237 { 00238 return effect2DRenderer; 00239 } 00240 00241 private: 00242 00243 iObjectRegistry* object_reg; 00244 00246 csRef<iVirtualClock> vc; 00247 00252 csHash<psEffect*, csString> effectFactories; 00253 00255 csHash<psEffect*, unsigned int> actualEffects; 00256 00258 csRef<iCollection> effectsCollection; 00259 00260 iView* view; 00261 00263 csRef<psEffectLoader> effectLoader; 00264 00265 psEffect2DRenderer* effect2DRenderer; 00266 00267 csHash<psLight*, unsigned int> lightList; 00268 }; 00269 00272 #endif