rendered paste bodyIndex: src/common/engine/psworld.cpp
===================================================================
--- src/common/engine/psworld.cpp (revision 966)
+++ src/common/engine/psworld.cpp (working copy)
@@ -435,7 +435,85 @@
Unload();
}
+bool psRegion::LoadCD()
+{
+ 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 + "_cd").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");
+
+ // Clean the world file to remove all textures/meshes/models
+ Debug1(LOG_LOAD, 0,"Cleaning map file.");
+ worldNode = Clean(worldNode);
+
+ // Create a new region with the given name, or select it if already there
+ iRegion* cur_region = engine->CreateRegion (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,cur_region, CS_LOADER_ACROSS_REGIONS, false, 0, MaterialManager::GetSingletonPtr()))
+ {
+ 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);
+ SetupWorldColliders(engine,cur_region);
+ Debug2(LOG_LOAD, 0,"After SetupWorldColliders, %dms elapsed\n", csGetTicks()-start);
+
+ VFS->ChDir("/planeshift");
+ engine->SetCacheManager(NULL);
+ engine->GetCacheManager();
+
+ printf("Map %s loaded successfully in %dms\n", (const char *)regionname, csGetTicks()-start);
+ return true;
+}
+
bool psRegion::Load(bool loadMeshes)
{
if (loaded)
@@ -489,9 +567,6 @@
// Create a new region with the given name, or select it if already there
iRegion* cur_region = engine->CreateRegion (regionname);
- // Clear it out if it already existed
- cur_region->DeleteAll ();
-
// Now load the map into the selected region
csRef<iLoader> loader ( csQueryRegistry<iLoader> (object_reg));
CS_ASSERT (loader != NULL);
@@ -503,7 +578,7 @@
csTicks start = csGetTicks();
Debug2(LOG_LOAD, 0,"Loading map file %s", worlddir.GetData());
- if (!loader->LoadMap(worldNode, CS_LOADER_KEEP_WORLD,cur_region, CS_LOADER_ACROSS_REGIONS, true, 0, MaterialManager::GetSingletonPtr()))
+ if (!loader->LoadMap(worldNode, CS_LOADER_KEEP_WORLD,cur_region, CS_LOADER_ACROSS_REGIONS, false, 0, MaterialManager::GetSingletonPtr()))
{
Error3("loader->LoadMapFile(%s,%s) failed.",worlddir.GetData(),worldfile.GetData() );
Error2("Region name was: %s", regionname.GetData() );
@@ -523,13 +598,11 @@
engine->PrecacheDraw (cur_region);
Debug2(LOG_LOAD, 0,"After Precache, %dms elapsed", csGetTicks()-start);
}
-
if (loadMeshes)
{
- SetupWorldColliders(engine,cur_region);
- Debug2(LOG_LOAD, 0,"After SetupWorldColliders, %dms elapsed\n", csGetTicks()-start);
+ //SetupWorldColliders(engine,cur_region);
+ LoadCD();
}
-
loaded = true;
VFS->ChDir("/planeshift");
Index: src/common/engine/psworld.h
===================================================================
--- src/common/engine/psworld.h (revision 966)
+++ src/common/engine/psworld.h (working copy)
@@ -73,6 +73,8 @@
*/
bool Load(bool loadMeshes = true);
+ bool LoadCD();
+
/**
* Unloads the region from the CS engine, deleting all objects
* in that region.