Update of /cvsroot/planeshift/planeshift/src/client/effects In directory sc8-pr-cvs1:/tmp/cvs-serv12850/src/client/effects Added Files: pseffectobject.cpp pseffectobject.h psspelleffectmanager.cpp psspelleffectmanager.h psspelleffectsloader.cpp psspelleffectsloader.h Log Message: To many question marks did show up on my last commit. Inserted missing files. --- NEW FILE: pseffectobject.cpp --- /* * pseffectobject.cpp by Chen Yue Feng <hel...@si...> * * Copyright (C) 2003 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include <config.h> #include "pseffectobject.h" psEffectObject::psEffectObject(void) { } psEffectObject::~psEffectObject(void) { } void psEffectObject::Copy(psEffectObject* object) { animation = object->animation; delay=object->delay; duration = object->duration; name = object->name; mesh = object->mesh; sound = object->sound; } --- NEW FILE: pseffectobject.h --- /* * pseffectobject.h by Chen Yue Feng <hel...@si...> * * Copyright (C) 2003 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef PS_EFFECTS_OBJECT_H #define PS_EFFECTS_OBJECT_H #include <iengine/mesh.h> #include <csutil/csstring.h> #include "csutil/csobject.h" class psEffectObject: public csObject { public: psEffectObject(void); virtual ~psEffectObject(void); void Copy(psEffectObject* object); csString name; //delay take effect csTicks delay; //effect time csTicks duration; // csString animation; csString sound; csRef<iMeshWrapper> mesh; }; #endif --- NEW FILE: psspelleffectmanager.cpp --- /* * psspelleffectmanager.cpp by Chen Yue Feng <hel...@si...> * * Copyright (C) 2003 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include <config.h> #include <iengine/mesh.h> #include <imesh/object.h> #include <iutil/objreg.h> #include <imesh/partsys.h> #include <imesh/ball.h> #include "util/log.h" #include <iutil/plugin.h> #include "imap/reader.h" #include "psspelleffectmanager.h" psSpellEffectManager::psSpellEffectManager(void) { } psSpellEffectManager::~psSpellEffectManager(void) { // if(ld_context) // delete ld_context; } void psSpellEffectManager::Update(csTicks elapsed_time) { for (int i =spellEffects.Length()-1; i >= 0; i--) { if (!spellEffects[i]->Update(elapsed_time)) { spellEffects.DeleteIndex(i); } } } bool psSpellEffectManager::Load(const char* xmlfile) { return this->loader.LoadSpellEffects(xmlfile); } bool psSpellEffectManager::Initialize(iObjectRegistry *objectReg) { engine = CS_QUERY_REGISTRY(objectReg,iEngine); //PS_QUERY_PLUGIN(loader, iLoader, "iLoader"); this->objectReg = objectReg; loader.Initialize(objectReg); return true; } bool psSpellEffectManager::StartSpellEffect (iCelEntity * entity, iSector* sector, const csVector3& center, csTicks duration, csString& effectName, csString& effectOverrides) { csRef<psSpellEffect> original = loader.FindEffect(effectName); csRef<psSpellEffect> spellEffect = new psSpellEffect(original->GetName()); spellEffect->CopyEffect(original); if(spellEffect==NULL) { return false; } if (!spellEffect->StartEffect(entity,sector,center,duration,objectReg)) { return false; } spellEffects.Push(spellEffect); return true; } --- NEW FILE: psspelleffectmanager.h --- /* * psspelleffectmanager.h by Chen Yue Feng <hel...@si...> * * Copyright (C) 2003 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef PS_SPELL_EFFECT_MANAGER_H #define PS_SPELL_EFFECT_MANAGER_H #include <csutil/refcount.h> #include <iutil/document.h> #include <iutil/objreg.h> #include <csutil/csstring.h> #include <csgeom/vector3.h> #include "pscelclient.h" #include "psspelleffectsloader.h" struct iSector; struct iDocumentNode; class StdLoaderContext; class psSpellEffectManager : public csRefCount { public: psSpellEffectManager(void); virtual ~psSpellEffectManager(void); bool Initialize(iObjectRegistry *objectReg); bool StartSpellEffect(iCelEntity * entity, iSector* sector, const csVector3& bottom, csTicks duration, csString& effectName, csString& effectOverride); void Update(csTicks elapsed_time); bool Load(const char* xmlfile); csStringHash xmltokens; csRef<iEngine> engine; iObjectRegistry *objectReg; csRefArray<psSpellEffect> spellEffects; psSpellEffectsLoader loader; /// List of loaded plugins // csLoadedPluginVector loaded_plugins; }; #endif --- NEW FILE: psspelleffectsloader.cpp --- /* * psspelleffectsloader.cpp by Chen Yue Feng <hel...@si...> * * Copyright (C) 2003 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include <config.h> #include <iengine/mesh.h> #include <imesh/object.h> #include <iutil/objreg.h> #include <iutil/vfs.h> #include <iutil/databuff.h> #include <csutil/xmltiny.h> #include <iutil/plugin.h> #include "imap/reader.h" #include "psengine.h" #include "psspelleffectsloader.h" class SpellEffectLoaderContext : public iLoaderContext { private: csRef<iEngine> Engine; public: SpellEffectLoaderContext (csRef<iEngine> Engine); virtual ~SpellEffectLoaderContext (); SCF_DECLARE_IBASE; virtual iSector* FindSector (const char* name); virtual iMaterialWrapper* FindMaterial (const char* name); virtual iMeshFactoryWrapper* FindMeshFactory (const char* name); virtual iMeshWrapper* FindMeshObject (const char* name); virtual iTextureWrapper* FindTexture (const char* name); virtual iLight *FindLight (const char* name); virtual bool CheckDupes () const { return false; } virtual iRegion* GetRegion () const { return 0; } virtual bool CurrentRegionOnly () const { return false; } }; SCF_IMPLEMENT_IBASE(SpellEffectLoaderContext); SCF_IMPLEMENTS_INTERFACE(iLoaderContext); SCF_IMPLEMENT_IBASE_END; SpellEffectLoaderContext::SpellEffectLoaderContext (csRef<iEngine> Engine) { SCF_CONSTRUCT_IBASE (0); SpellEffectLoaderContext::Engine = Engine; } SpellEffectLoaderContext::~SpellEffectLoaderContext () { } iSector* SpellEffectLoaderContext::FindSector (const char* /*name*/) { return 0; } iMaterialWrapper* SpellEffectLoaderContext::FindMaterial (const char* name) { return Engine->GetMaterialList ()->FindByName (name); } iMeshFactoryWrapper* SpellEffectLoaderContext::FindMeshFactory (const char* name) { return Engine->GetMeshFactories ()->FindByName(name); } iMeshWrapper* SpellEffectLoaderContext::FindMeshObject (const char* /*name*/) { return 0; } iTextureWrapper* SpellEffectLoaderContext::FindTexture (const char* /*name*/) { return 0; } iLight* SpellEffectLoaderContext::FindLight(const char *name) { // TODO: Implement this. return 0; } psSpellEffectsLoader::psSpellEffectsLoader(void) { } psSpellEffectsLoader::~psSpellEffectsLoader(void) { //if(ldr_context) // delete ldr_context; } bool psSpellEffectsLoader::Initialize(iObjectRegistry *objectReg) { engine = CS_QUERY_REGISTRY(objectReg,iEngine); ldr_context= new SpellEffectLoaderContext(engine); csRef<iLoader> loader = CS_QUERY_REGISTRY (objectReg,iLoader); this->objectReg = objectReg; VFS=CS_QUERY_REGISTRY(objectReg, iVFS); xmltokens.Register ("params", XMLTOKEN_PARAMS); xmltokens.Register ("plugin", XMLTOKEN_PLUGIN); xmltokens.Register ("effectobj", XMLTOKEN_EFFECTOBJ); xmltokens.Register ("priority", XMLTOKEN_PRIORITY); xmltokens.Register ("move", XMLTOKEN_MOVE); xmltokens.Register ("ztest", XMLTOKEN_ZTEST); xmltokens.Register ("factory", XMLTOKEN_FACTORY); xmltokens.Register ("duration", XMLTOKEN_DURATION); xmltokens.Register ("delay", XMLTOKEN_DELAY); return true; } bool psSpellEffectsLoader::LoadSpellEffects(const char *xmlfile) { if (!engine) return false; csRef<iDocumentSystem> xml = csPtr<iDocumentSystem>(new csTinyDocumentSystem); csRef<iVFS> vfs = CS_QUERY_REGISTRY(objectReg, iVFS); csRef<iDataBuffer> buff = vfs->ReadFile( xmlfile ); if ( !buff || !buff->GetSize() ) { // Error2("Failed to open spell effect file: %s",xmlfile); return false; } csRef<iDocument> doc = xml->CreateDocument(); const char* error = doc->Parse( buff ); if ( error ) { // Error3("While parsing effect file %s. %s",xmlfile,error); return false; } csRef<iDocumentNode> root = doc->GetRoot(); csRef<iDocumentNode> topNode = root->GetNode("effects"); csRef<iDocumentNodeIterator> iter = topNode->GetNodes(); while ( iter->HasNext() ) { csRef<iDocumentNode> node = iter->Next(); if ( node->GetType() != CS_NODE_ELEMENT ) continue; if ( strcmp( node->GetValue(), "effect" ) == 0 ) { csString name = node->GetAttributeValue ("name"); psSpellEffect* spellEffect = new psSpellEffect(name); bool ret = LoadSpellEffect(node,spellEffect); if(ret) { effects.Push(spellEffect); } else { delete spellEffect; } } else if(strcmp( node->GetValue(), "test" ) == 0 ) { // loader.Load(node); } } return true; } bool psSpellEffectsLoader::LoadSpellEffect(iDocumentNode *node,csRef<psSpellEffect> spellEffect) { csRef<iMeshWrapper> mesh; csString name = node->GetAttributeValue("name"); if ( name.Length() == 0 ) { return false; } csString animation = node->GetAttributeValue("animation"); csString sound = node->GetAttributeValue("sound"); printf("Loading effect: %s\n Animation : %s\n Sound : %s\n", name.GetData(),animation.GetData(),sound.GetData()); spellEffect->animation = animation; spellEffect->sound = sound; // Now read in effect csRef<iDocumentNodeIterator> iter = node->GetNodes(); while ( iter->HasNext() ) { csRef<iDocumentNode> node = iter->Next(); if ( node->GetType() != CS_NODE_ELEMENT ) continue; csString name = node->GetAttributeValue ("name"); mesh = engine->CreateMeshWrapper (name); psEffectObject* tmp =new psEffectObject(); tmp->name = name; tmp->animation=animation; tmp->sound=sound; tmp->mesh = mesh; if (LoadSpellEffectObject (ldr_context,tmp, 0, node)) { spellEffect->effectobjects.Push(tmp); } else { mesh = 0; } } this->test=mesh; return true; } bool psSpellEffectsLoader::LoadSpellEffectObject(iLoaderContext* ldr_context, psEffectObject* effectobj, iMeshWrapper* parent, iDocumentNode* node) { csRef<iDocumentNodeIterator> it = node->GetNodes (); csRef<iLoaderPlugin> plug; const char* priority = '\0'; iMeshWrapper* mesh = effectobj->mesh; while (it->HasNext ()) { csRef<iDocumentNode> child = it->Next (); if (child->GetType () != CS_NODE_ELEMENT) continue; const char* value = child->GetValue (); csStringID id = xmltokens.Request (value); switch (id) { case XMLTOKEN_DURATION: effectobj->duration = child->GetContentsValueAsInt(); break; case XMLTOKEN_DELAY: effectobj->delay = child->GetContentsValueAsInt(); break; case XMLTOKEN_PRIORITY: priority = child->GetContentsValue (); break; case XMLTOKEN_EFFECTOBJ: break; case XMLTOKEN_PARAMS: LoadEffectParams(plug,mesh,child,ldr_context); break; case XMLTOKEN_PLUGIN: { // Load the emitter_factory csRef<iPluginManager> plugin_mgr = CS_QUERY_REGISTRY (objectReg,iPluginManager); const char* plugname = child->GetContentsValue(); plug = CS_QUERY_PLUGIN_CLASS (plugin_mgr,plugname, iLoaderPlugin); if (!plug) plug = CS_LOAD_PLUGIN (plugin_mgr,plugname, iLoaderPlugin); } break; case XMLTOKEN_FACTORY: { csRef<iPluginManager> plugin_mgr = CS_QUERY_REGISTRY (objectReg,iPluginManager); const char* plugname = child->GetContentsValue(); csRef<iMeshObjectType> type =( CS_QUERY_PLUGIN_CLASS (plugin_mgr,plugname, iMeshObjectType)); if (!type) type = CS_LOAD_PLUGIN (plugin_mgr,plugname, iMeshObjectType); csRef<iMeshFactoryWrapper> t = engine->CreateMeshFactory (plugname); csRef<iMeshObjectFactory> tmp =type->NewFactory (); t->SetMeshObjectFactory(tmp); } break; default: // SyntaxService->ReportBadToken (child); break; } } if (!priority) priority = "object"; mesh->SetRenderPriority (engine->GetRenderPriority (priority)); return true; } bool psSpellEffectsLoader::LoadEffectParams(iLoaderPlugin* plug,iMeshWrapper* mesh,iDocumentNode* child,iLoaderContext* ldr_context) { if (!plug) { return false; } csRef<iBase> mo (plug->Parse (child, ldr_context, 0)); if (mo) { csRef<iMeshObject> mo2 (SCF_QUERY_INTERFACE (mo, iMeshObject)); if (!mo2) { return false; } mesh->SetMeshObject (mo2); mo2->SetLogicalParent (mesh); /* if (mo2->GetFactory () && mo2->GetFactory ()->GetLogicalParent ()) { iBase* lp = mo2->GetFactory ()->GetLogicalParent (); csRef<iMeshFactoryWrapper> mfw (SCF_QUERY_INTERFACE (lp, iMeshFactoryWrapper)); if (mfw) mesh->SetFactory (mfw); }*/ } else { // Error is reported by plug->Parse(). return false; } return true; } csRef<psSpellEffect> psSpellEffectsLoader::FindEffect(csString & name) { for (int i = 0; i < effects.Length(); i++) { if (effects[i]->GetName()==name) { return effects[i]; } } return NULL; } --- NEW FILE: psspelleffectsloader.h --- /* * psspelleffectsloader.h by Chen Yue Feng <hel...@si...> * * Copyright (C) 2003 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef PS_SPELL_EFFECTS_LOADER_H #define PS_SPELL_EFFECTS_LOADER_H #include <csutil/refcount.h> #include <iutil/document.h> #include <iutil/objreg.h> #include <csutil/csstring.h> #include <csgeom/vector3.h> #include "pscelclient.h" #include "imap/ldrctxt.h" #include "imap/reader.h" #include "psspelleffect.h" enum { XMLTOKEN_EFFECTOBJ = 1, XMLTOKEN_PARAMS, XMLTOKEN_PLUGIN, XMLTOKEN_FACTORY, XMLTOKEN_MOVE, XMLTOKEN_ZTEST, XMLTOKEN_PRIORITY, XMLTOKEN_DELAY, XMLTOKEN_DURATION }; class psSpellEffectsLoader { public: psSpellEffectsLoader(void); ~psSpellEffectsLoader(void); csRef<iEngine> engine; iObjectRegistry *objectReg; bool Initialize(iObjectRegistry *objectReg); bool LoadSpellEffects(const char *xmlfile); bool LoadSpellEffect(iDocumentNode *node,csRef<psSpellEffect> spellEffect); bool LoadSpellEffectObject(iLoaderContext* ldr_context,psEffectObject* effectobj, iMeshWrapper* parent, iDocumentNode* node); bool LoadEffectParams(iLoaderPlugin* plug,iMeshWrapper* mesh,iDocumentNode* child,iLoaderContext* ldr_context); csRef<psSpellEffect> FindEffect(csString & name); csRef<iLoaderContext> ldr_context; // virtual file system csRef<iVFS> VFS; csStringHash xmltokens; csRef<iMeshWrapper> test; csRefArray<psSpellEffect> effects; }; #endif |