From: <mg...@us...> - 2008-05-02 12:28:44
|
Revision: 1440 http://planeshift.svn.sourceforge.net/planeshift/?rev=1440&view=rev Author: mgist Date: 2008-05-02 05:28:48 -0700 (Fri, 02 May 2008) Log Message: ----------- - Refactored parts of psRegion. - More warning fixes. Modified Paths: -------------- trunk/docs/history.txt trunk/src/client/pscelclient.cpp trunk/src/common/effects/pseffectmanager.h trunk/src/common/engine/psworld.cpp trunk/src/common/engine/psworld.h trunk/src/common/paws/pawsmanager.h trunk/src/eedit/eeditapp.cpp trunk/src/npcclient/gem.cpp trunk/src/npcclient/npcbehave.cpp trunk/src/npcclient/npcclient.cpp trunk/src/npcclient/pathfind.cpp trunk/src/npcclient/pathfind.h trunk/src/server/database/mysql/dal.cpp trunk/src/server/gem.cpp Added Paths: ----------- trunk/src/common/engine/psregion.cpp trunk/src/common/engine/psregion.h Modified: trunk/docs/history.txt =================================================================== --- trunk/docs/history.txt 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/docs/history.txt 2008-05-02 12:28:48 UTC (rev 1440) @@ -5,6 +5,7 @@ - Replaced regions with collections. - Added initial (currently expensive) support for character shaders. - Some code cleanups and warning fixes. +- Refactored parts of psRegion. *** 2008-05-01 by Dave Bentham - Fixed FS#1425 - cannot reward personalised items in events. Modified: trunk/src/client/pscelclient.cpp =================================================================== --- trunk/src/client/pscelclient.cpp 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/client/pscelclient.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -32,6 +32,7 @@ #include <iengine/mesh.h> #include <iengine/region.h> #include <iengine/movable.h> +#include <iengine/sector.h> #include <iengine/scenenode.h> #include <imesh/object.h> #include <imesh/spritecal3d.h> Modified: trunk/src/common/effects/pseffectmanager.h =================================================================== --- trunk/src/common/effects/pseffectmanager.h 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/common/effects/pseffectmanager.h 2008-05-02 12:28:48 UTC (rev 1440) @@ -35,11 +35,12 @@ #include "effects/pseffect2drenderer.h" +struct iLight; +struct iMeshWrapper; +struct iMovable; struct iSector; struct iSectorList; -struct iMeshWrapper; struct iView; -struct iMovable; class psEffect; class psLight; Added: trunk/src/common/engine/psregion.cpp =================================================================== --- trunk/src/common/engine/psregion.cpp (rev 0) +++ trunk/src/common/engine/psregion.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -0,0 +1,447 @@ +/* + * psregion.cpp + * + * Copyright (C) 2008 Atomic Blue (in...@pl..., http://www.atomicblue.org) + * + * + * 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 <psconfig.h> +//============================================================================= +// Crystal Space Includes +//============================================================================= +#include <cstool/collider.h> +#include <csutil/sysfunc.h> +#include <iengine/engine.h> +#include <iengine/collection.h> +#include <iengine/mesh.h> +#include <imap/loader.h> +#include <iutil/document.h> +#include <iutil/object.h> +#include <ivaria/collider.h> +#include <ivideo/graph3d.h> + +//============================================================================= +// Project Includes +//============================================================================= +#include "util/log.h" +#include "util/psconst.h" + +//============================================================================= +// Local Includes +//============================================================================= +#include "psregion.h" + +psRegion::psRegion(iObjectRegistry *obj_reg, const char *file, uint _gfxFeatures) +{ + object_reg = obj_reg; + + worlddir.Format("/planeshift/world/%s", file); + colldetworlddir.Format("/planeshift/world/cd_%s", file); + worldfile = "world"; + regionName = file; + loaded = false; + gfxFeatures = _gfxFeatures; + needToFilter = gfxFeatures != useAll; + + engine = csQueryRegistry<iEngine> (object_reg); + vfs = csQueryRegistry<iVFS>(object_reg); + xml = csQueryRegistry<iDocumentSystem>(object_reg); + loader = csQueryRegistry<iLoader>(object_reg); +} + +psRegion::~psRegion() +{ + Unload(); +} + + +bool psRegion::Load(bool loadMeshes) +{ + if (loaded) + return true; + + bool using3D; + + // Find out if we are ever going to render 3D + csRef<iGraphics3D> g3d = csQueryRegistry<iGraphics3D> (object_reg); + csRef<iFactory> factory = scfQueryInterface<iFactory> (g3d); + + using3D = (strcmp("crystalspace.graphics3d.null", factory->QueryClassID()) ? true : false); + + csString target; + target.Format("%s/world", worlddir.GetData()); + + csRef<iDataBuffer> buf (vfs->ReadFile (target.GetData())); + if (!buf || !buf->GetSize ()) + { + Error2("Error loading world file. %s\n", target.GetData()); + return false; + } + + csRef<iDocument> doc = xml->CreateDocument(); + + const char* error = doc->Parse( buf ); + + if( error ) + { + Error3("Error %s loading file to be cleaned. %s\n",error, target.GetData()); + return false; + } + + csRef<iDocumentNode> worldNode = doc->GetRoot()->GetNode("world"); + + if(!loadMeshes) + { + // Clean the world file to remove all textures/meshes/models + Debug1(LOG_LOAD, 0,"Cleaning map file."); + worldNode = Clean(worldNode); + } + else if(needToFilter) + { + // Filter the world file to get the correct settings. + worldNode = Filter(worldNode, using3D); + } + + // Create a new region with the given name, or select it if already there + collection = engine->CreateCollection (regionName); + + // Now load the map into the selected region + vfs->ChDir (worlddir); + + csTicks start = csGetTicks(); + Debug2(LOG_LOAD, 0,"Loading map file %s", worlddir.GetData()); + + if (!loader->LoadMap(worldNode, CS_LOADER_KEEP_WORLD, collection, CS_LOADER_ACROSS_REGIONS, true, 0, 0, KEEP_USED)) + { + Error3("LoadMap failed: %s, %s.",worlddir.GetData(),worldfile.GetData() ); + Error2("Region name was: %s", regionName.GetData()); + return false; + } + + Debug2(LOG_LOAD, 0,"After LoadMapFile, %dms elapsed", csGetTicks()-start); + + // Successfully loaded. Now get textures ready, etc. and return. + if (using3D) + { + engine->PrecacheDraw (collection); + Debug2(LOG_LOAD, 0,"After Precache, %dms elapsed", csGetTicks()-start); + } + + if (loadMeshes) + { + csRef<iCollideSystem> cdsys = csQueryRegistry<iCollideSystem> (object_reg); + + csString target; + target.Format("%s/%s", colldetworlddir.GetData(), worldfile.GetData()); + + csRef<iDataBuffer> buf = vfs->ReadFile(target.GetData()); + if (!buf || !buf->GetSize()) + { + SetupWorldColliders(engine); + } + else + { + const char* error = doc->Parse(buf); + if(error) + { + Error3("Error %s while loading colldet world file: %s.\nFalling back to normal colldet, please report this error.\n", error, target.GetData()); + SetupWorldColliders(engine); + } + else + { + + csRef<iDocumentNode> worldNodeCD = doc->GetRoot()->GetNode("world"); + + iCollection* colldetCol = engine->CreateCollection("colldetPS"); + + vfs->ChDir(colldetworlddir); + + if(!loader->LoadMap(worldNodeCD, CS_LOADER_KEEP_WORLD, colldetCol, CS_LOADER_ACROSS_REGIONS, false)) + { + Error3("LoadMap failed: %s, %s.\n", colldetworlddir.GetData(), worldfile.GetData() ); + Error2("Region name was: %s\nFalling back to normal colldet, please report this error.\n", regionName.GetData()); + SetupWorldColliders(engine); + } + else + { + SetupWorldCollidersCD(engine, colldetCol); + } + + engine->RemoveCollection("colldetPS"); + } + } + Debug2(LOG_LOAD, 0,"After SetupWorldColliders, %dms elapsed\n", csGetTicks()-start); + } + + loaded = true; + + vfs->ChDir("/planeshift"); + engine->SetVFSCacheManager(); + + printf("Map %s loaded successfully in %dms\n", regionName.GetData(), csGetTicks()-start); + return true; +} + +csRef<iDocumentNode> psRegion::Clean(csRef<iDocumentNode> world) +{ + csRef<iDocumentSystem> xml ( + csQueryRegistry<iDocumentSystem> (object_reg)); + + csRef<iDocument> doc = xml->CreateDocument(); + csRef<iDocumentNode> node = doc->CreateRoot(); + + // Copy the world node + csRef<iDocumentNode> cleanedWorld = node->CreateNodeBefore(CS_NODE_ELEMENT); + + cleanedWorld->SetValue("world"); + + // Copy the sector node + csRef<iDocumentNodeIterator> sectors = world->GetNodes("sector"); + while ( sectors->HasNext() ) + { + csRef<iDocumentNode> sector = sectors->Next(); + + csRef<iDocumentNode> cleanedSector = cleanedWorld->CreateNodeBefore(CS_NODE_ELEMENT); + cleanedSector->SetValue(sector->GetValue()); + + // Copy the sector attributes + csRef<iDocumentAttributeIterator> attrs = sector->GetAttributes(); + while(attrs->HasNext()) + { + csRef<iDocumentAttribute> attr = attrs->Next(); + cleanedSector->SetAttribute(attr->GetName(), attr->GetValue()); + } + + // Copy the portal + csRef<iDocumentNodeIterator> nodes = sector->GetNodes("portal"); + + while(nodes->HasNext()) + { + csRef<iDocumentNode> portal = nodes->Next(); + csRef<iDocumentNode> cleanedportal = cleanedSector->CreateNodeBefore(CS_NODE_ELEMENT); + CloneNode(portal, cleanedportal); + } + + // Copy the portals + csRef<iDocumentNodeIterator> portalsItr = sector->GetNodes("portals"); + + while(portalsItr->HasNext()) + { + csRef<iDocumentNode> portals = portalsItr->Next(); + csRef<iDocumentNode> cleanedportals = cleanedSector->CreateNodeBefore(CS_NODE_ELEMENT); + CloneNode(portals, cleanedportals); + } + + + } + + // Copy the start node + csRef<iDocumentNodeIterator> startLocations = world->GetNodes("start"); + while (startLocations->HasNext()) + { + csRef<iDocumentNode> start = startLocations->Next(); + csRef<iDocumentNode> cleanedStart = cleanedWorld->CreateNodeBefore(CS_NODE_ELEMENT); + CloneNode(start, cleanedStart); + } + + return cleanedWorld; +} + +csRef<iDocumentNode> psRegion::Filter(csRef<iDocumentNode> world, bool using3D) +{ + if(!using3D) + { + if(world->GetNode("shaders")) + world->RemoveNode(world->GetNode("shaders")); + + if(world->GetNode("textures")) + world->RemoveNode(world->GetNode("textures")); + + if(world->GetNode("materials")) + world->RemoveNode(world->GetNode("materials")); + + csRef<iDocumentNodeIterator> meshfacts = world->GetNodes("meshfact"); + while(meshfacts->HasNext()) + { + csRef<iDocumentNode> meshfact = meshfacts->Next(); + csRef<iDocumentNode> params = meshfact->GetNode("params"); + if(params) + { + params->RemoveNodes(params->GetNodes("n")); + csRef<iDocumentNodeIterator> submeshes = params->GetNodes("submesh"); + while(submeshes->HasNext()) + { + csRef<iDocumentNode> submesh = submeshes->Next(); + if(submesh->GetNode("material")) + { + submesh->RemoveNode(submesh->GetNode("material")); + } + } + } + } + + csRef<iDocumentNodeIterator> sectors = world->GetNodes("sector"); + while(sectors->HasNext()) + { + csRef<iDocumentNode> sector = sectors->Next(); + csRef<iDocumentNodeIterator> meshobjs = sector->GetNodes("meshobj"); + while(meshobjs->HasNext()) + { + csRef<iDocumentNode> meshobj = meshobjs->Next(); + csRef<iDocumentNode> params = meshobj->GetNode("params"); + if(params) + { + if(params->GetNode("material")) + { + params->RemoveNode(params->GetNode("material")); + } + if(params->GetNode("materialpalette")) + { + params->RemoveNode(params->GetNode("materialpalette")); + } + csRef<iDocumentNodeIterator> submeshes = params->GetNodes("submesh"); + while(submeshes->HasNext()) + { + csRef<iDocumentNode> submesh = submeshes->Next(); + if(submesh->GetNode("material")) + { + submesh->RemoveNode(submesh->GetNode("material")); + } + + } + } + } + } + } + else + { + if(!(gfxFeatures & useNormalMaps)) + { + csRef<iDocumentNodeIterator> sectors = world->GetNodes("sector"); + while(sectors->HasNext()) + { + csRef<iDocumentNode> sector = sectors->Next(); + csRef<iDocumentNode> rloop = sector->GetNode("renderloop"); + if(rloop.IsValid()) + { + csString value = rloop->GetContentsValue(); + if(value.Compare("std_rloop_diffuse")) + { + sector->RemoveNode(rloop); + } + } + } + } + + if(!(gfxFeatures & useMeshGen)) + { + csRef<iDocumentNodeIterator> sectors = world->GetNodes("sector"); + while(sectors->HasNext()) + { + csRef<iDocumentNode> sector = sectors->Next(); + csRef<iDocumentNodeIterator> meshgen = sector->GetNodes("meshgen"); + sector->RemoveNodes(meshgen); + } + } + } + + return world; +} + +void psRegion::CloneNode (iDocumentNode* from, iDocumentNode* to) +{ + to->SetValue (from->GetValue ()); + csRef<iDocumentNodeIterator> it = from->GetNodes (); + while (it->HasNext ()) + { + csRef<iDocumentNode> child = it->Next (); + csRef<iDocumentNode> child_clone = to->CreateNodeBefore ( + child->GetType (), 0); + CloneNode (child, child_clone); + } + csRef<iDocumentAttributeIterator> atit = from->GetAttributes (); + while (atit->HasNext ()) + { + csRef<iDocumentAttribute> attr = atit->Next (); + to->SetAttribute (attr->GetName (), attr->GetValue ()); + } +} + +void psRegion::Unload() +{ + if(loaded) + { + loaded = false; + + // Remove all objects from the region. +#ifndef CS_DEBUG + GetRegion()->ReleaseAllObjects(); +#else + printf("Unloading %s\n", regionName.GetData()); + engine->RemoveCollection(collection); +#endif + } +} + +void psRegion::SetupWorldColliders(iEngine *engine) +{ + csRef<iCollideSystem> cdsys = + csQueryRegistry<iCollideSystem> (object_reg); + csRef<iObjectIterator> iter = collection->QueryObject()->GetIterator(); + + iObject *curr; + while ( iter->HasNext() ) + { + curr = iter->Next(); + // regions hold many objects, but only meshes are collide-able + csRef<iMeshWrapper> sp = scfQueryInterface<iMeshWrapper> (curr); + if (sp && sp->GetMeshObject() ) + { + csColliderHelper::InitializeCollisionWrapper(cdsys, sp); + } + } +} + +void psRegion::SetupWorldCollidersCD(iEngine *engine, iCollection *cd_col) +{ + csRef<iCollideSystem> cdsys = + csQueryRegistry<iCollideSystem> (object_reg); + csRef<iObjectIterator> iter = cd_col->QueryObject()->GetIterator(); + + iObject *curr; + while (iter->HasNext()) + { + curr = iter->Next(); + // regions hold many objects, but only meshes are collide-able + csRef<iMeshWrapper> sp = scfQueryInterface<iMeshWrapper> (curr); + if (sp && sp->GetMeshObject()) + { + csRef<csColliderWrapper> cw = csColliderHelper::InitializeCollisionWrapper(cdsys, sp); + if(cw) + { + csRef<iMeshWrapper> mw = collection->FindMeshObject(cw->GetObjectParent()->GetName()); + if(mw) + { + mw->QueryObject()->ObjAdd(cw); + cw->SetObjectParent(mw->QueryObject()); + } + else + { + printf("Mesh Wrapper %s doesn't exist for collision!!\n", cw->GetObjectParent()->GetName()); + } + } + } + } +} Added: trunk/src/common/engine/psregion.h =================================================================== --- trunk/src/common/engine/psregion.h (rev 0) +++ trunk/src/common/engine/psregion.h 2008-05-02 12:28:48 UTC (rev 1440) @@ -0,0 +1,139 @@ +/* + * psregion.h + * + * Copyright (C) 2008 Atomic Blue (in...@pl..., http://www.atomicblue.org) + * + * + * 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 __PSREGION_H__ +#define __PSREGION_H__ + +//============================================================================= +// Crystal Space Includes +//============================================================================= +#include <csutil/csstring.h> + +//============================================================================= +// Project Includes +//============================================================================= + +//============================================================================= +// Local Includes +//============================================================================= + +struct iCollection; +struct iDocumentNode; +struct iDocumentSystem; +struct iEngine; +struct iLoader; +struct iVFS; + +// Feature defines. +#define useNormalMaps 0x01 +#define useMeshGen 0x02 +#define useAll (useNormalMaps | useMeshGen) + +/** +* Replacement class for iPcRegion from CEL. +* This is more versatile for dynamic loading +* and unloading of multiple maps than iPcRegion. +*/ +class psRegion +{ +public: + /** + * Creates an entry representing a single region + * but does not load it. + */ + psRegion(iObjectRegistry *obj_reg, const char *file, uint gfxFeatures = useAll); + + /** + * Dtor unloads region if loaded + */ + ~psRegion(); + + /** + * Loads the file "world" from /planeshift/art/world/<name>.zip + * into the region called <name>. + */ + bool Load(bool loadMeshes = true); + + /** + * Unloads the region from the CS engine, deleting all objects + * in that region. + */ + void Unload(); + + bool IsLoaded() + { return loaded; } + + iCollection *GetCollection() { return collection; } + + /** + * Sets up the collision detection blockers for all meshes in + * the region. + */ + void SetupWorldColliders(iEngine *engine); + void SetupWorldCollidersCD(iEngine *engine, iCollection *cd_col); + + /** + * The retain flag is used by psWorld owner to manage the list + * of loaded and unloaded regions efficiently. See psWorld class + * def for details on how this is done. + */ + void SetNeededFlag(bool flag) + { isNeeded = flag; } + bool IsNeeded() + { return isNeeded; } + + const char *GetName() + { return regionName; } + + /// Cleans the given file and removes all meshes, lights, etc. not needed on the server. + csRef<iDocumentNode> Clean(csRef<iDocumentNode> worldNode); + + /** + * Filters the world file to remove features which have been marked + * as disabled by the user (post proc effects for example). + */ + csRef<iDocumentNode> Filter(csRef<iDocumentNode> worldNode, bool using3D); + +private: + /** + * True if we need to filter the world file. + */ + bool needToFilter; + + // Graphics features we want to use. + uint gfxFeatures; + + iObjectRegistry* object_reg; + iCollection* collection; + csString regionName; + csString worlddir; + csString colldetworlddir; + csString worldfile; + bool loaded; + bool isNeeded; + + csRef<iEngine> engine; + csRef<iVFS> vfs; + csRef<iDocumentSystem> xml; + csRef<iLoader> loader; + + static void CloneNode(iDocumentNode* from, iDocumentNode* to); +}; + +#endif // __PSREGION_H__ Modified: trunk/src/common/engine/psworld.cpp =================================================================== --- trunk/src/common/engine/psworld.cpp 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/common/engine/psworld.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -19,40 +19,29 @@ */ #include <psconfig.h> -// CS -#include <iengine/rview.h> -#include <iengine/portal.h> -#include <iengine/portalcontainer.h> -#include <csutil/snprintf.h> -#include <csutil/sysfunc.h> -#include <iengine/collection.h> -#include <iutil/vfs.h> -#include <csutil/csstring.h> +//============================================================================= +// Crystal Space Includes +//============================================================================= #include <cstool/collider.h> -#include <ivaria/collider.h> -#include <igeom/trimesh.h> -#include <imesh/objmodel.h> +#include <iengine/engine.h> #include <iengine/mesh.h> -#include <imesh/object.h> -#include <imesh/thing.h> -#include <csutil/databuf.h> -#include <iengine/renderloop.h> -#include <csutil/xmltiny.h> #include <iengine/movable.h> -#include <iutil/objreg.h> -#include <iengine/collection.h> -#include <csutil/csobject.h> +#include <iengine/portal.h> +#include <iengine/portalcontainer.h> +#include <imesh/object.h> -// PS -#include "engine/materialmanager.h" -#include "engine/psworld.h" -#include "util/psconst.h" +//============================================================================= +// Project Includes +//============================================================================= +#include "util/consoleout.h" #include "util/log.h" #include "util/strutil.h" -#include "util/consoleout.h" -#include "globals.h" -#define SHARED_REGION_NAME "SharedDataRegion" +//============================================================================= +// Local Includes +//============================================================================= +#include "psregion.h" +#include "psworld.h" psWorld::psWorld() { @@ -90,7 +79,7 @@ return rgn; } - psRegion *newregion = new psRegion(object_reg, this, mapfile, gfxFeatures); + psRegion *newregion = new psRegion(object_reg, mapfile, gfxFeatures); if (load && !newregion->Load(loadMeshes)) { delete newregion; @@ -260,7 +249,7 @@ { for (unsigned i=0; i < regions.GetSize(); i++) if (!regions[i]->IsNeeded() ) - regs.Push(regions[i]->GetRegion()); + regs.Push(regions[i]->GetCollection()); } void psWorld::BuildWarpCache() @@ -418,425 +407,3 @@ return angle; } - -//-------------------------------------------------------------------------- - -psRegion::psRegion(iObjectRegistry *obj_reg, psWorld * world, const char *file, uint _gfxFeatures) -{ - object_reg = obj_reg; - this->world = world; - - worlddir.Format("/planeshift/world/%s", file); - colldetworlddir.Format("/planeshift/world/cd_%s", file); - worldfile = "world"; - regionname = file; - loaded = false; - gfxFeatures = _gfxFeatures; - needToFilter = gfxFeatures != useAll; -} - -psRegion::~psRegion() -{ - Unload(); -} - - -bool psRegion::Load(bool loadMeshes) -{ - if (loaded) - return true; - - bool using3D; - - csRef<iEngine> engine = csQueryRegistry<iEngine> (object_reg); - - // Find out if we are ever going to render 3D - csRef<iGraphics3D> g3d = csQueryRegistry<iGraphics3D> (object_reg); - csRef<iFactory> factory = - scfQueryInterface<iFactory> (g3d); - - const char* g3Dname = factory->QueryClassID(); - using3D = (strcmp("crystalspace.graphics3d.null", g3Dname)? true: false); - - csString target; - target.Format("%s/world", worlddir.GetData()); - csRef<iVFS> vfs = csQueryRegistry<iVFS > ( object_reg); - - csRef<iDocumentSystem> xml ( - csQueryRegistry<iDocumentSystem> (object_reg)); - - csRef<iDocument> doc = xml->CreateDocument(); - - csRef<iDataBuffer> buf (vfs->ReadFile (target.GetData())); - if (!buf || !buf->GetSize ()) - { - Error2("Error loading world file. %s\n", target.GetData()); - return false; - } - - const char* error = doc->Parse( buf ); - - if( error ) - { - Error3("Error %s loading file to be cleaned. %s\n",error, target.GetData()); - return false; - } - - csRef<iDocumentNode> worldNode = doc->GetRoot()->GetNode("world"); - - if(!loadMeshes) - { - // Clean the world file to remove all textures/meshes/models - Debug1(LOG_LOAD, 0,"Cleaning map file."); - worldNode = Clean(worldNode); - } - else if(needToFilter) - { - // Filter the world file to get the correct settings. - worldNode = Filter(worldNode, using3D); - } - - // Create a new region with the given name, or select it if already there - iCollection* col = engine->CreateCollection (regionname); - - // Now load the map into the selected region - csRef<iLoader> loader ( csQueryRegistry<iLoader> (object_reg)); - CS_ASSERT (loader != NULL); - csRef<iVFS> VFS ( csQueryRegistry<iVFS> (object_reg)); - CS_ASSERT (VFS != NULL); - VFS->ChDir (worlddir); - engine->SetCacheManager(NULL); - - csTicks start = csGetTicks(); - Debug2(LOG_LOAD, 0,"Loading map file %s", worlddir.GetData()); - - if (!loader->LoadMap(worldNode, CS_LOADER_KEEP_WORLD, col, CS_LOADER_ACROSS_REGIONS, true, 0, 0, KEEP_USED)) - { - Error3("loader->LoadMapFile(%s,%s) failed.",worlddir.GetData(),worldfile.GetData() ); - Error2("Region name was: %s", regionname.GetData() ); - return false; - } - Debug2(LOG_LOAD, 0,"After LoadMapFile, %dms elapsed", csGetTicks()-start); - - // Successfully loaded. Now get textures ready, etc. and return. - if (using3D) - { - engine->ShineLights(col); - Debug2(LOG_LOAD, 0,"After ShineLights, %dms elapsed", csGetTicks()-start); - engine->PrecacheDraw (col); - Debug2(LOG_LOAD, 0,"After Precache, %dms elapsed", csGetTicks()-start); - } - - if (loadMeshes) - { - csRef<iCollideSystem> cdsys = csQueryRegistry<iCollideSystem> (object_reg); - - csString target; - target.Format("%s/%s", colldetworlddir.GetData(), worldfile.GetData()); - - csRef<iDataBuffer> buf = vfs->ReadFile(target.GetData()); - if (!buf || !buf->GetSize()) - { - SetupWorldColliders(engine, col); - } - else - { - const char* error = doc->Parse(buf); - if(error) - { - Error3("Error %s while loading colldet world file: %s.\nFalling back to normal colldet, please report this error.\n", error, target.GetData()); - SetupWorldColliders(engine, col); - } - else - { - - csRef<iDocumentNode> worldNodeCD = doc->GetRoot()->GetNode("world"); - - iCollection* colldetCol = engine->CreateCollection("colldetPS"); - - vfs->ChDir(colldetworlddir); - - if(!loader->LoadMap(worldNodeCD, CS_LOADER_KEEP_WORLD, colldetCol, CS_LOADER_ACROSS_REGIONS, false)) - { - Error3("LoadMap failed: %s, %s.\n", colldetworlddir.GetData(), worldfile.GetData() ); - Error2("Region name was: %s\nFalling back to normal colldet, please report this error.\n", regionname.GetData()); - SetupWorldColliders(engine, col); - } - else - { - SetupWorldCollidersCD(engine, col, colldetCol); - } - - engine->RemoveCollection("colldetPS"); - } - } - Debug2(LOG_LOAD, 0,"After SetupWorldColliders, %dms elapsed\n", csGetTicks()-start); - } - - loaded = true; - - VFS->ChDir("/planeshift"); - engine->SetCacheManager(NULL); - engine->GetCacheManager(); - - printf("Map %s loaded successfully in %dms\n", (const char *)regionname, csGetTicks()-start); - return true; -} - -csRef<iDocumentNode> psRegion::Clean(csRef<iDocumentNode> world) -{ - csRef<iDocumentSystem> xml ( - csQueryRegistry<iDocumentSystem> (object_reg)); - - csRef<iDocument> doc = xml->CreateDocument(); - csRef<iDocumentNode> node = doc->CreateRoot(); - - // Copy the world node - csRef<iDocumentNode> cleanedWorld = node->CreateNodeBefore(CS_NODE_ELEMENT); - - cleanedWorld->SetValue("world"); - - // Copy the sector node - csRef<iDocumentNodeIterator> sectors = world->GetNodes("sector"); - while ( sectors->HasNext() ) - { - csRef<iDocumentNode> sector = sectors->Next(); - - csRef<iDocumentNode> cleanedSector = cleanedWorld->CreateNodeBefore(CS_NODE_ELEMENT); - cleanedSector->SetValue(sector->GetValue()); - - // Copy the sector attributes - csRef<iDocumentAttributeIterator> attrs = sector->GetAttributes(); - while(attrs->HasNext()) - { - csRef<iDocumentAttribute> attr = attrs->Next(); - cleanedSector->SetAttribute(attr->GetName(), attr->GetValue()); - } - - // Copy the portal - csRef<iDocumentNodeIterator> nodes = sector->GetNodes("portal"); - - while(nodes->HasNext()) - { - csRef<iDocumentNode> portal = nodes->Next(); - csRef<iDocumentNode> cleanedportal = cleanedSector->CreateNodeBefore(CS_NODE_ELEMENT); - CloneNode(portal, cleanedportal); - } - - // Copy the portals - csRef<iDocumentNodeIterator> portalsItr = sector->GetNodes("portals"); - - while(portalsItr->HasNext()) - { - csRef<iDocumentNode> portals = portalsItr->Next(); - csRef<iDocumentNode> cleanedportals = cleanedSector->CreateNodeBefore(CS_NODE_ELEMENT); - CloneNode(portals, cleanedportals); - } - - - } - - // Copy the start node - csRef<iDocumentNodeIterator> startLocations = world->GetNodes("start"); - while (startLocations->HasNext()) - { - csRef<iDocumentNode> start = startLocations->Next(); - csRef<iDocumentNode> cleanedStart = cleanedWorld->CreateNodeBefore(CS_NODE_ELEMENT); - CloneNode(start, cleanedStart); - } - - return cleanedWorld; -} - -csRef<iDocumentNode> psRegion::Filter(csRef<iDocumentNode> world, bool using3D) -{ - if(!using3D) - { - if(world->GetNode("shaders")) - world->RemoveNode(world->GetNode("shaders")); - - if(world->GetNode("textures")) - world->RemoveNode(world->GetNode("textures")); - - if(world->GetNode("materials")) - world->RemoveNode(world->GetNode("materials")); - - csRef<iDocumentNodeIterator> meshfacts = world->GetNodes("meshfact"); - while(meshfacts->HasNext()) - { - csRef<iDocumentNode> meshfact = meshfacts->Next(); - csRef<iDocumentNode> params = meshfact->GetNode("params"); - if(params) - { - params->RemoveNodes(params->GetNodes("n")); - csRef<iDocumentNodeIterator> submeshes = params->GetNodes("submesh"); - while(submeshes->HasNext()) - { - csRef<iDocumentNode> submesh = submeshes->Next(); - if(submesh->GetNode("material")) - { - submesh->RemoveNode(submesh->GetNode("material")); - } - } - } - } - - csRef<iDocumentNodeIterator> sectors = world->GetNodes("sector"); - while(sectors->HasNext()) - { - csRef<iDocumentNode> sector = sectors->Next(); - csRef<iDocumentNodeIterator> meshobjs = sector->GetNodes("meshobj"); - while(meshobjs->HasNext()) - { - csRef<iDocumentNode> meshobj = meshobjs->Next(); - csRef<iDocumentNode> params = meshobj->GetNode("params"); - if(params) - { - if(params->GetNode("material")) - { - params->RemoveNode(params->GetNode("material")); - } - if(params->GetNode("materialpalette")) - { - params->RemoveNode(params->GetNode("materialpalette")); - } - csRef<iDocumentNodeIterator> submeshes = params->GetNodes("submesh"); - while(submeshes->HasNext()) - { - csRef<iDocumentNode> submesh = submeshes->Next(); - if(submesh->GetNode("material")) - { - submesh->RemoveNode(submesh->GetNode("material")); - } - - } - } - } - } - } - else - { - if(!(gfxFeatures & useNormalMaps)) - { - csRef<iDocumentNodeIterator> sectors = world->GetNodes("sector"); - while(sectors->HasNext()) - { - csRef<iDocumentNode> sector = sectors->Next(); - csRef<iDocumentNode> rloop = sector->GetNode("renderloop"); - if(rloop.IsValid()) - { - csString value = rloop->GetContentsValue(); - if(value.Compare("std_rloop_diffuse")) - { - sector->RemoveNode(rloop); - } - } - } - } - - if(!(gfxFeatures & useMeshGen)) - { - csRef<iDocumentNodeIterator> sectors = world->GetNodes("sector"); - while(sectors->HasNext()) - { - csRef<iDocumentNode> sector = sectors->Next(); - csRef<iDocumentNodeIterator> meshgen = sector->GetNodes("meshgen"); - sector->RemoveNodes(meshgen); - } - } - } - - return world; -} - -void psRegion::CloneNode (iDocumentNode* from, iDocumentNode* to) -{ - to->SetValue (from->GetValue ()); - csRef<iDocumentNodeIterator> it = from->GetNodes (); - while (it->HasNext ()) - { - csRef<iDocumentNode> child = it->Next (); - csRef<iDocumentNode> child_clone = to->CreateNodeBefore ( - child->GetType (), 0); - CloneNode (child, child_clone); - } - csRef<iDocumentAttributeIterator> atit = from->GetAttributes (); - while (atit->HasNext ()) - { - csRef<iDocumentAttribute> attr = atit->Next (); - to->SetAttribute (attr->GetName (), attr->GetValue ()); - } -} - -void psRegion::Unload() -{ - if(loaded) - { - loaded = false; - - // Remove all objects from the region. -#ifndef CS_DEBUG - GetRegion()->ReleaseAllObjects(); -#else - printf("Unloading %s\n", regionname.GetData()); - GetRegion()->ReleaseAllObjects(true); -#endif - } -} - -void psRegion::SetupWorldColliders(iEngine *engine, iCollection* col) -{ - csRef<iCollideSystem> cdsys = - csQueryRegistry<iCollideSystem> (object_reg); - csRef<iObjectIterator> iter = col->QueryObject()->GetIterator(); - - iObject *curr; - while ( iter->HasNext() ) - { - curr = iter->Next(); - // regions hold many objects, but only meshes are collide-able - csRef<iMeshWrapper> sp = scfQueryInterface<iMeshWrapper> (curr); - if (sp && sp->GetMeshObject() ) - { - csColliderHelper::InitializeCollisionWrapper(cdsys, sp); - } - } -} - -void psRegion::SetupWorldCollidersCD(iEngine *engine, iCollection *cur_col, iCollection *cd_col) -{ - csRef<iCollideSystem> cdsys = - csQueryRegistry<iCollideSystem> (object_reg); - csRef<iObjectIterator> iter = cd_col->QueryObject()->GetIterator(); - - iObject *curr; - while (iter->HasNext()) - { - curr = iter->Next(); - // regions hold many objects, but only meshes are collide-able - csRef<iMeshWrapper> sp = scfQueryInterface<iMeshWrapper> (curr); - if (sp && sp->GetMeshObject()) - { - csRef<csColliderWrapper> cw = csColliderHelper::InitializeCollisionWrapper(cdsys, sp); - if(cw) - { - csRef<iMeshWrapper> mw = cur_col->FindMeshObject(cw->GetObjectParent()->GetName()); - if(mw) - { - mw->QueryObject()->ObjAdd(cw); - cw->SetObjectParent(mw->QueryObject()); - } - else - { - printf("Mesh Wrapper %s doesn't exist for collision!!\n", cw->GetObjectParent()->GetName()); - } - } - } - } -} - -iCollection * psRegion::GetRegion() -{ - csRef<iEngine> engine = csQueryRegistry<iEngine> (object_reg); - return engine->GetCollection(regionname); -} Modified: trunk/src/common/engine/psworld.h =================================================================== --- trunk/src/common/engine/psworld.h 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/common/engine/psworld.h 2008-05-02 12:28:48 UTC (rev 1440) @@ -20,119 +20,27 @@ #ifndef __PSWORLD_H__ #define __PSWORLD_H__ -#include <csutil/ref.h> -#include <csutil/weakref.h> -#include <csutil/weakrefarr.h> -#include <csutil/hash.h> -#include <iengine/sector.h> +//============================================================================= +// Crystal Space Includes +//============================================================================= #include <csgeom/transfrm.h> +#include <csutil/parray.h> +#include <csutil/weakref.h> -#include "csutil/parray.h" -#include "csutil/csstring.h" +//============================================================================= +// Project Includes +//============================================================================= -class CelBase; -struct iSector; -struct iObjectRegistry; -struct iEngine; +//============================================================================= +// Local Includes +//============================================================================= + struct iCollection; -class psWorld; +struct iEngine; +class psRegion; -// Feature defines. -#define useNormalMaps 0x01 -#define useMeshGen 0x02 -#define useAll (useNormalMaps | useMeshGen) - /** - * Replacement class for iPcRegion from CEL. - * This is more versatile for dynamic loading - * and unloading of multiple maps than iPcRegion. - */ -class psRegion -{ -protected: - iObjectRegistry* object_reg; - csString worlddir; - csString colldetworlddir; - csString worldfile; - csString regionname; - bool loaded; - bool isNeeded; - psWorld * world; - - static void CloneNode(iDocumentNode* from, iDocumentNode* to); - -public: - /** - * Creates an entry representing a single region - * but does not load it. - */ - psRegion(iObjectRegistry *obj_reg, psWorld * world, const char *file, uint gfxFeatures = useAll); - - /** - * Dtor unloads region if loaded - */ - ~psRegion(); - - /** - * Loads the file "world" from /planeshift/art/world/<name>.zip - * into the region called <name>. - */ - bool Load(bool loadMeshes = true); - - /** - * Unloads the region from the CS engine, deleting all objects - * in that region. - */ - void Unload(); - - bool IsLoaded() - { return loaded; } - - iCollection * GetRegion(); - - /** - * Sets up the collision detection blockers for all meshes in - * the region. - */ - void SetupWorldColliders(iEngine *engine, iCollection *cur_col); - void SetupWorldCollidersCD(iEngine *engine, iCollection *cur_col, iCollection *cd_col); - - /** - * The retain flag is used by psWorld owner to manage the list - * of loaded and unloaded regions efficiently. See psWorld class - * def for details on how this is done. - */ - void SetNeededFlag(bool flag) - { isNeeded = flag; } - bool IsNeeded() - { return isNeeded; } - - const char *GetName() - { return regionname; } - - /// Cleans the given file and removes all meshes, lights, etc. not needed on the server. - csRef<iDocumentNode> Clean(csRef<iDocumentNode> worldNode); - - /** - * Filters the world file to remove features which have been marked - * as disabled by the user (post proc effects for example). - */ - csRef<iDocumentNode> Filter(csRef<iDocumentNode> worldNode, bool using3D); - - /** - * True if we need to filter the world file. - */ - bool needToFilter; - - // Graphics features we want to use. - uint gfxFeatures; -}; - -struct iObject; - -/** - * - * It is in charge of managing all regions (zone map files) + * psWorld is in charge of managing all regions (zone map files) * and loading/unloading them as needed. The main users * of this class are EntityManager and on the client, ZoneHandler. */ Modified: trunk/src/common/paws/pawsmanager.h =================================================================== --- trunk/src/common/paws/pawsmanager.h 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/common/paws/pawsmanager.h 2008-05-02 12:28:48 UTC (rev 1440) @@ -39,7 +39,7 @@ #include "isndsys/ss_source.h" #include "isndsys/ss_renderer.h" -#include "engine/psworld.h" +#include "engine/psregion.h" #include "util/scriptvar.h" #include "util/log.h" Modified: trunk/src/eedit/eeditapp.cpp =================================================================== --- trunk/src/eedit/eeditapp.cpp 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/eedit/eeditapp.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -453,12 +453,6 @@ ((EEditErrorToolbox *)toolboxManager->GetToolbox(EEditToolbox::T_ERROR))->SetLoadingEffects(true); effectManager->Clear(); effectManager->LoadEffects(currEffectLoc, editWindow->GetView()); - if (!effectManager->Prepare()) - { - csReport (object_reg, CS_REPORTER_SEVERITY_NOTIFY, APP_NAME, - "Warning: Could not successfully prepare effects!"); - return false; - } ((EEditErrorToolbox *)toolboxManager->GetToolbox(EEditToolbox::T_ERROR))->SetLoadingEffects(false); Modified: trunk/src/npcclient/gem.cpp =================================================================== --- trunk/src/npcclient/gem.cpp 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/npcclient/gem.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -169,8 +169,7 @@ } csRef<iLoader> loader (csQueryRegistry<iLoader> (npcclient->GetObjectReg())); - iBase* result; - loader->Load(root, result); + loader->Load(root); mesh = npcclient->GetEngine()->GetMeshFactories()->FindByName(factname)->CreateMeshWrapper(); failed = !mesh; break; Modified: trunk/src/npcclient/npcbehave.cpp =================================================================== --- trunk/src/npcclient/npcbehave.cpp 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/npcclient/npcbehave.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -730,7 +730,7 @@ bool Behavior::RunScript(NPC *npc, EventManager *eventmgr, bool interrupted) { - unsigned int start_step = current_step; + size_t start_step = current_step; while (true) { if (current_step < sequence.GetSize() ) Modified: trunk/src/npcclient/npcclient.cpp =================================================================== --- trunk/src/npcclient/npcclient.cpp 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/npcclient/npcclient.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -913,7 +913,7 @@ void psNPCClient::UnattachNPC(iCelEntity *entity, NPC *npc) { csRef<iObject> object ( scfQueryInterface<iObject> (entity)); - csRef<NPCFinder> cef (CS_GET_CHILD_OBJECT (object, NPCFinder)); + csRef<NPCFinder> cef (CS::GetChildObject<NPCFinder>(object)); if (cef) { if (cef->GetNPC () != npc) @@ -926,7 +926,7 @@ NPC* psNPCClient::FindAttachedNPC(iCelEntity *entity) { csRef<iObject> object ( scfQueryInterface<iObject> (entity)); - csRef<NPCFinder> cef (CS_GET_CHILD_OBJECT (object, NPCFinder)); + csRef<NPCFinder> cef (CS::GetChildObject<NPCFinder>(object)); if (cef) return cef->GetNPC(); return 0; Modified: trunk/src/npcclient/pathfind.cpp =================================================================== --- trunk/src/npcclient/pathfind.cpp 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/npcclient/pathfind.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -19,7 +19,6 @@ #include <psconfig.h> #include <math.h> -#include <iengine/region.h> #include <csutil/databuf.h> #include <iutil/object.h> @@ -1040,12 +1039,12 @@ engine = csQueryRegistry<iEngine> (objReg); } -iRegion * psPFMaps::GetCSRegionOfSector(const csString & sectorName) +iCollection * psPFMaps::GetCSRegionOfSector(const csString & sectorName) { - iRegionList * list = engine->GetRegions(); - for (int regionNum = 0; regionNum < list->GetCount(); regionNum++) + csRef<iCollectionArray> list = engine->GetCollections(); + for (size_t regionNum = 0; regionNum < list->GetSize(); regionNum++) { - iRegion * r = list->Get(regionNum); + iCollection * r = list->Get(regionNum); if (r->FindSector(sectorName) != NULL) return r; } @@ -1073,7 +1072,7 @@ psPFMap * psPFMaps::GetRegionBySector(const csString & sectorName) { psPFMap * region; - iRegion * CSregion; + iCollection * CSregion; csString regionName; const bool dbg = false; Modified: trunk/src/npcclient/pathfind.h =================================================================== --- trunk/src/npcclient/pathfind.h 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/npcclient/pathfind.h 2008-05-02 12:28:48 UTC (rev 1440) @@ -35,7 +35,7 @@ class psAMap; struct iVFS; struct iSector; -struct iRegion; +struct iCollection; struct iEngine; struct iDocumentNode; @@ -46,7 +46,7 @@ { public: csString name; - iRegion * region; + iCollection * region; psWalkPolyMap * wpMap; psAMap * aMap; }; @@ -60,7 +60,7 @@ psPFMap * FindRegionByName(const csString & regionName); protected: - iRegion * GetCSRegionOfSector(const csString & sectorName); + iCollection * GetCSRegionOfSector(const csString & sectorName); csList<psPFMap*> regions; Modified: trunk/src/server/database/mysql/dal.cpp =================================================================== --- trunk/src/server/database/mysql/dal.cpp 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/server/database/mysql/dal.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -649,7 +649,7 @@ //command.FormatPush("%s='%s'", fname, escape.GetData()); AddToStatement(fname); temp[index].string = sValue; - temp[index].length = temp[index].string.Length(); + temp[index].length = (unsigned long)temp[index].string.Length(); bind[index].buffer_type = MYSQL_TYPE_STRING; bind[index].buffer = const_cast<char *> (temp[index].string.GetData()); @@ -704,7 +704,7 @@ statement.Append(")"); - prepared = (mysql_stmt_prepare(stmt, statement, statement.Length()) == 0); + prepared = (mysql_stmt_prepare(stmt, statement, (unsigned long)statement.Length()) == 0); return prepared; } @@ -726,7 +726,7 @@ // field count is the idfield statement.Append("= ?"); - prepared = (mysql_stmt_prepare(stmt, statement, statement.Length()) == 0); + prepared = (mysql_stmt_prepare(stmt, statement, (unsigned long)statement.Length()) == 0); return prepared; } Modified: trunk/src/server/gem.cpp =================================================================== --- trunk/src/server/gem.cpp 2008-05-02 11:35:16 UTC (rev 1439) +++ trunk/src/server/gem.cpp 2008-05-02 12:28:48 UTC (rev 1440) @@ -799,8 +799,7 @@ } csRef<iLoader> loader (csQueryRegistry<iLoader> (psserver->GetObjectReg())); - iBase* result; - loader->Load(root, result); + loader->Load(root); mesh = engine->GetMeshFactories()->FindByName(factname)->CreateMeshWrapper(); failed = !mesh; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |