From: <mg...@us...> - 2008-12-21 20:55:00
|
Revision: 2734 http://planeshift.svn.sourceforge.net/planeshift/?rev=2734&view=rev Author: mgist Date: 2008-12-21 20:54:57 +0000 (Sun, 21 Dec 2008) Log Message: ----------- - Wrote a background loader. Still fairly buggy, so disabled by default. Modified Paths: -------------- trunk/psclient.cfg trunk/src/client/charapp.cpp trunk/src/client/clientcachemanager.cpp trunk/src/client/pscelclient.cpp trunk/src/client/psengine.cpp trunk/src/client/psengine.h trunk/src/client/weather.cpp trunk/src/client/zonehandler.cpp trunk/src/common/paws/pawsobjectview.cpp Added Paths: ----------- trunk/src/common/engine/loader.cpp trunk/src/common/engine/loader.h Removed Paths: ------------- trunk/src/common/engine/materialmanager.cpp trunk/src/common/engine/materialmanager.h Modified: trunk/psclient.cfg =================================================================== --- trunk/psclient.cfg 2008-12-21 18:12:36 UTC (rev 2733) +++ trunk/psclient.cfg 2008-12-21 20:54:57 UTC (rev 2734) @@ -157,6 +157,9 @@ Engine.RenderManager.Default = crystalspace.rendermanager.unshadowed ;Engine.RenderManager.Default = crystalspace.rendermanager.shadow_pssm +;RenderManager.Unshadowed.Layers = /data/renderlayers/lighting_basic.xml + + ; ****************** ; * Part 3: Game * ; ****************** @@ -211,3 +214,4 @@ Planeshift.Loading.AllMaps = false Planeshift.Loading.KeepMaps = false Planeshift.Loading.PreloadModels = false +ThreadManager.AlwaysRunNow = true \ No newline at end of file Modified: trunk/src/client/charapp.cpp =================================================================== --- trunk/src/client/charapp.cpp 2008-12-21 18:12:36 UTC (rev 2733) +++ trunk/src/client/charapp.cpp 2008-12-21 20:54:57 UTC (rev 2734) @@ -18,7 +18,7 @@ #include "util/psstring.h" #include "effects/pseffect.h" #include "effects/pseffectmanager.h" -#include "engine/materialmanager.h" +#include "engine/loader.h" //============================================================================= // Local Includes @@ -85,7 +85,7 @@ csString materialParsed = ParseStrings("", faceMaterial); csString textureParsed = ParseStrings("", faceTexture); - iMaterialWrapper* material = MaterialManager::GetSingletonPtr()->LoadMaterial(materialParsed, textureParsed); + iMaterialWrapper* material = Loader::GetSingleton().LoadMaterial(materialParsed, textureParsed); if ( !material ) { @@ -281,7 +281,7 @@ csString materialNameParsed = ParseStrings(part, material); csString textureNameParsed = ParseStrings(part, texture); - iMaterialWrapper* material = MaterialManager::GetSingletonPtr()->LoadMaterial(materialNameParsed, textureNameParsed ); + iMaterialWrapper* material = Loader::GetSingleton().LoadMaterial(materialNameParsed, textureNameParsed ); if ( !material ) { // Not necisarily an error; this texture may just not exist for this character, yet @@ -471,7 +471,7 @@ csString meshNameParsed = ParseStrings(part, meshName); csString textureNameParsed = ParseStrings(part, textureName); - iMaterialWrapper* material = MaterialManager::GetSingletonPtr()->LoadMaterial( meshNameParsed, textureNameParsed ); + iMaterialWrapper* material = Loader::GetSingleton().LoadMaterial( meshNameParsed, textureNameParsed ); if ( !material ) { // Not necisarily an error; this texture may just not exist for this character, yet Modified: trunk/src/client/clientcachemanager.cpp =================================================================== --- trunk/src/client/clientcachemanager.cpp 2008-12-21 18:12:36 UTC (rev 2733) +++ trunk/src/client/clientcachemanager.cpp 2008-12-21 20:54:57 UTC (rev 2734) @@ -30,7 +30,7 @@ //============================================================================= #include "util/psxmlparser.h" -#include "engine/materialmanager.h" +#include "engine/loader.h" #include "engine/psworld.h" //============================================================================= @@ -146,7 +146,7 @@ } } - indexEntry->result = psengine->GetLoader()->LoadNode(root, cache); + indexEntry->result = Loader::GetSingleton().GetLoader()->LoadNode(root, cache); } return indexEntry; Modified: trunk/src/client/pscelclient.cpp =================================================================== --- trunk/src/client/pscelclient.cpp 2008-12-21 18:12:36 UTC (rev 2733) +++ trunk/src/client/pscelclient.cpp 2008-12-21 20:54:57 UTC (rev 2734) @@ -25,6 +25,7 @@ #include <csutil/scf.h> #include <csutil/csstring.h> #include <cstool/collider.h> +#include <iutil/cfgmgr.h> #include <iutil/objreg.h> #include <iutil/vfs.h> #include <ivaria/collider.h> @@ -53,6 +54,7 @@ #include "engine/psworld.h" #include "engine/solid.h" #include "engine/linmove.h" +#include "engine/loader.h" #include "engine/colldet.h" #include "net/messages.h" @@ -204,7 +206,8 @@ bool psCelClient::IsReady() { - if ( local_player == NULL || gameWorld == NULL ) + if ( local_player == NULL || + (!psengine->ThreadedLoading() && gameWorld == NULL)) return false; else return true; @@ -212,21 +215,19 @@ void psCelClient::HandleWorld( MsgEntry* me ) { - psPersistWorld mesg( me ); + if(!psengine->ThreadedLoading()) + { + psPersistWorld mesg( me ); + gameWorld = new psWorld; + gameWorld->Initialize(object_reg, psengine->UnloadingLast(), psengine->GetGFXFeatures()); + zonehandler->SetWorld(gameWorld); + zonehandler->LoadZone(mesg.sector); + } - gameWorld = new psWorld; - gameWorld->Initialize( object_reg ); - - zonehandler->SetWorld(gameWorld); - // Tell the user that we are loading the world - psengine->AddLoadingWindowMsg( "Loading world" ); + psengine->AddLoadingWindowMsg("Loading world"); - gameWorld->Initialize(object_reg, psengine->UnloadingLast(), psengine->GetGFXFeatures()); - - zonehandler->LoadZone(mesg.sector); - requeststatus = 0; RequestActor(); } @@ -282,6 +283,9 @@ local_player = actor; SetMainActor( local_player ); + // Now that we know where we are, trigger a world load around us. + Loader::GetSingleton().UpdatePosition(mesg.pos, mesg.sectorName); + // This triggers the server to update our proxlist local_player->SendDRUpdate(PRIORITY_LOW,GetClientDR()->GetMsgStrings()); } @@ -785,6 +789,13 @@ GEMClientActor* actor = dynamic_cast<GEMClientActor*>(entities[i]); } + // Update loader. + if(local_player) + { + Loader::GetSingleton().UpdatePosition(local_player->Pos(), + local_player->GetSector()->QueryObject()->GetName()); + } + shadowManager->UpdateShadows(); } Modified: trunk/src/client/psengine.cpp =================================================================== --- trunk/src/client/psengine.cpp 2008-12-21 18:12:36 UTC (rev 2733) +++ trunk/src/client/psengine.cpp 2008-12-21 20:54:57 UTC (rev 2734) @@ -112,7 +112,7 @@ #include "util/log.h" #include "util/strutil.h" #include "engine/psworld.h" -#include "engine/materialmanager.h" +#include "engine/loader.h" #include "util/psutil.h" #include "util/consoleout.h" #include "entitylabels.h" @@ -229,6 +229,7 @@ paws = NULL; mainWidget = NULL; inventoryCache = NULL; + loader = NULL; loadtimeout = 10; // Default load timeout @@ -302,6 +303,7 @@ delete mouseBinds; delete guiHandler; delete inventoryCache; + delete loader; // Effect manager needs to be destroyed before the soundmanager. effectManager.Invalidate(); @@ -309,8 +311,6 @@ object_reg->Unregister ((iSoundManager*)soundmanager, "iSoundManager"); delete options; - - delete materialmanager; } // ---------------------------------------------------------------------------- @@ -339,7 +339,6 @@ PS_QUERY_PLUGIN (engine, iEngine, "iEngine"); PS_QUERY_PLUGIN (cfgmgr, iConfigManager, "iConfigManager"); PS_QUERY_PLUGIN (g3d, iGraphics3D, "iGraphics3D"); - PS_QUERY_PLUGIN (loader, iThreadedLoader, "crystalspace.level.loader.threaded"); PS_QUERY_PLUGIN (vc, iVirtualClock, "iVirtualClock"); PS_QUERY_PLUGIN (cmdline, iCommandLineParser, "iCommandLineParser"); @@ -568,11 +567,25 @@ unloadLast = GetConfig()->GetBool("PlaneShift.Client.Loading.UnloadLast", true); - materialmanager = new MaterialManager(object_reg, preloadModels, GetGFXFeatures()); + threadedLoading = !psengine->GetConfig()->GetBool("ThreadManager.AlwaysRunNow"); - if(preloadModels) + Loader* loader = new Loader(); + Loader::GetSingleton().Init(object_reg, preloadModels, gfxFeatures, 100); + + if(threadedLoading) { - materialmanager->PreloadTextures(); + csString path; + csRef<iStringArray> maps = vfs->FindFiles("/planeshift/world/"); + for(size_t i=0; i<maps->GetSize(); i++) + { + vfs->PushDir(maps->Get(i)); + csRef<iDataBuffer> tmp = vfs->GetRealPath(maps->Get(i)); + path.AppendFmt("%s, ", tmp->GetData()); + Loader::GetSingleton().PrecacheData("world"); + vfs->PopDir(); + } + vfs->SetSyncDir("/planeshift/maps/"); + vfs->Mount("/planeshift/maps/", path); } if (!celclient->Initialize(object_reg, GetMsgHandler(), zonehandler)) @@ -1490,7 +1503,6 @@ if (modelnames.GetSize()-1 < modelToLoad) { BuildFactoryList(); - engine->SyncEngineListsNow(loader); cachemanager->Precache(); Debug1(LOG_ADMIN,0, "Preloading complete"); Modified: trunk/src/client/psengine.h =================================================================== --- trunk/src/client/psengine.h 2008-12-21 18:12:36 UTC (rev 2733) +++ trunk/src/client/psengine.h 2008-12-21 20:54:57 UTC (rev 2734) @@ -45,7 +45,6 @@ struct iEngine; struct iEvent; struct iEventQueue; -struct iLoader; struct iMeshFactoryWrapper; struct iThreadedLoader; struct iSoundManager; @@ -64,7 +63,7 @@ class ClientCacheManager; class psQuestionClient; class psOptions; -class MaterialManager; +class Loader; // Networking classes class psNetConnection; @@ -174,7 +173,6 @@ iVFS* GetVFS() { return vfs; } iVirtualClock* GetVirtualClock() { return vc; } iDocumentSystem* GetXMLParser() { return xmlparser; } - iThreadedLoader* GetLoader() { return loader; } iSoundManager* GetSoundManager() { return soundmanager; } iConfigManager* GetConfig() { return cfgmgr; } ///< config file @@ -339,6 +337,8 @@ /// The graphics features that are enabled/disabled. uint GetGFXFeatures() { return gfxFeatures; } + bool ThreadedLoading() { return threadedLoading; } + void RegisterDelayedLoader(DelayedLoader* obj) { delayedLoaders.PushSmart(obj); } void UnregisterDelayedLoader(DelayedLoader* obj) { delayedLoaders.Delete(obj); } @@ -370,7 +370,6 @@ csRef<iEventQueue> queue; ///< Event Queue csRef<iVirtualClock> vc; ///< Clock csRef<iDocumentSystem> xmlparser; ///< XML Parser - csRef<iThreadedLoader> loader; ///< Loader csRef<iCommandLineParser> cmdline; ///< Command line parser csRef<iStringSet> stringset; csRandomGen random; @@ -382,7 +381,6 @@ csRef<ActionHandler> actionhandler; csRef<ZoneHandler> zonehandler; ///< Region/map file memory manager. csRef<psCal3DCallbackLoader> cal3DCallbackLoader; - MaterialManager* materialmanager; ///< Handles loading of materials/textures. psClientCharManager* charmanager; ///< Holds the charactermanager GUIHandler* guiHandler; psCharController* charController; @@ -396,6 +394,7 @@ PawsManager* paws; ///< Hold the ps AWS manager psMainWidget* mainWidget; ///< Hold the ps overridden version of the desktop psInventoryCache* inventoryCache;///< inventory cache for client + Loader* loader; /* status, misc. vars */ bool gameLoaded; ///< determines if the game is loaded or not @@ -466,6 +465,8 @@ /// Define what kind of loading we want to do; unload first or unload last. bool unloadLast; + bool threadedLoading; + // Event ID cache csEventID event_frame; csEventID event_canvashidden; Modified: trunk/src/client/weather.cpp =================================================================== --- trunk/src/client/weather.cpp 2008-12-21 18:12:36 UTC (rev 2733) +++ trunk/src/client/weather.cpp 2008-12-21 20:54:57 UTC (rev 2734) @@ -38,7 +38,7 @@ #include <iutil/plugin.h> #include "iclient/isoundmngr.h" -#include "engine/materialmanager.h" +#include "engine/loader.h" #include "pscelclient.h" #include "globals.h" #include "weather.h" @@ -214,7 +214,7 @@ float speed = 5; // Attempt to fetch material. - iMaterialWrapper* mat = MaterialManager::GetSingletonPtr()->LoadMaterial(matname, "/planeshift/art/effects/raindrop.dds"); + iMaterialWrapper* mat = Loader::GetSingleton().LoadMaterial(matname, "/planeshift/art/effects/raindrop.dds"); if (!mat) { Bug2("Can't find material '%s' in memory for rain!", matname); @@ -374,7 +374,7 @@ float speed = 1.5f; // Attempt to fetch material. - iMaterialWrapper* mat = MaterialManager::GetSingletonPtr()->LoadMaterial(matname, "/planeshift/art/effects/snow.dds"); + iMaterialWrapper* mat = Loader::GetSingleton().LoadMaterial(matname, "/planeshift/art/effects/snow.dds"); if (!mat) { Bug2("Can't find material '%s' in memory for snow!", matname); Modified: trunk/src/client/zonehandler.cpp =================================================================== --- trunk/src/client/zonehandler.cpp 2008-12-21 18:12:36 UTC (rev 2733) +++ trunk/src/client/zonehandler.cpp 2008-12-21 20:54:57 UTC (rev 2734) @@ -21,6 +21,7 @@ // Crystal Space Includes //============================================================================= #include <csutil/objreg.h> +#include <iutil/cfgmgr.h> #include <iutil/object.h> #include <iengine/engine.h> #include <iengine/sector.h> @@ -49,6 +50,7 @@ #include "gui/pawsloading.h" +#include "engine/loader.h" #include "engine/psworld.h" #include "iclient/isoundmngr.h" @@ -118,7 +120,7 @@ ZoneLoadInfo* zone = zonelist.Get(sector, NULL); if (zone == NULL) - Error2("Fatal error: Could not find zone info for sector %s!\n",sector); + Error2("Error: Could not find zone info for sector %s!\n",sector); return zone; } @@ -193,16 +195,19 @@ // We don't load the maps here: we just remember that we need to do it and we show LoadingWindow // If we began to load the maps immediately at this place, the LoadingWindow would not have a chance to be drawn - ZoneLoadInfo * zone = FindZone(msg.newSector); + ZoneLoadInfo* zone = FindZone(msg.newSector); if (zone == NULL) { - psengine->FatalError("The sector you have entered couldn't be loaded.\nPlease check your logs for details."); + Error1("The sector you have entered couldn't be loaded.\nPlease check your logs for details."); return; } - FlagRegions(zone); + if(!psengine->ThreadedLoading()) + { + FlagRegions(zone); + } - if (world->NeedsLoading(zone->transitional)) + if (psengine->ThreadedLoading() || world->NeedsLoading(zone->transitional)) { SetMapLoadNeeded(true); sectorToLoad = msg.newSector; @@ -273,7 +278,6 @@ { if(ExecuteFlaggedRegions(sectorToLoad)) { - SetMapLoadNeeded(false); psengine->SetLoadedMap(true); @@ -360,22 +364,30 @@ bool ZoneHandler::ExecuteFlaggedRegions(const csString & sector) { ZoneLoadInfo* found = FindZone(sector); + bool background = true; + if(!psengine->ThreadedLoading()) + { + background = false; + } if (found) { - // If the sector has a loading screen, display it - if (found->loadImage && FindLoadWindow()) + if(!background) { - Debug2(LOG_LOAD, 0, "Setting background %s", found->loadImage.GetData()); - loadWindow->SetBackground(found->loadImage.GetData()); - psengine->ForceRefresh(); - } + // If the sector has a loading screen, display it + if (found->loadImage && FindLoadWindow()) + { + Debug2(LOG_LOAD, 0, "Setting background %s", found->loadImage.GetData()); + loadWindow->SetBackground(found->loadImage.GetData()); + psengine->ForceRefresh(); + } - if(!found->transitional) - { - csArray<iCollection*> deletedRegions; - world->GetNotNeededRegions(deletedRegions); - celclient->OnRegionsDeleted(deletedRegions); + if(!found->transitional) + { + csArray<iCollection*> deletedRegions; + world->GetNotNeededRegions(deletedRegions); + celclient->OnRegionsDeleted(deletedRegions); + } } // Before the first map is loaded, we want to refresh the screen to get the loading background. @@ -386,7 +398,20 @@ } // Load a map. - int executed = world->ExecuteFlaggedRegions(found->transitional, psengine->UnloadingLast()); + int executed = 2; + if(background) + { + if(Loader::GetSingleton().GetLoadingCount() == 0) + { + executed = 0; + psengine->GetEngine()->PrecacheDraw(); + } + } + else + { + executed = world->ExecuteFlaggedRegions(found->transitional, psengine->UnloadingLast()); + } + switch(executed) { case 1: Added: trunk/src/common/engine/loader.cpp =================================================================== --- trunk/src/common/engine/loader.cpp (rev 0) +++ trunk/src/common/engine/loader.cpp 2008-12-21 20:54:57 UTC (rev 2734) @@ -0,0 +1,872 @@ +/* + * loader.cpp - Author: Mike Gist + * + * 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> + +#include <cstool/collider.h> +#include <iengine/movable.h> +#include <iengine/portal.h> +#include <iutil/stringarray.h> +#include <iutil/object.h> +#include <ivaria/collider.h> +#include <ivideo/material.h> + +#include "loader.h" +#include "util/strutil.h" +#include "globals.h" + +void Loader::Init(iObjectRegistry* object_reg, bool keepModels, uint gfxFeatures, float loadRange) +{ + this->object_reg = object_reg; + this->keepModels = keepModels; + this->gfxFeatures = gfxFeatures; + this->loadRange = loadRange; + + engine = csQueryRegistry<iEngine> (object_reg); + tloader = csQueryRegistry<iThreadedLoader> (object_reg); + vfs = csQueryRegistry<iVFS> (object_reg); + svstrings = csQueryRegistryTagInterface<iShaderVarStringSet>(object_reg, "crystalspace.shader.variablenameset"); + strings = csQueryRegistryTagInterface<iStringSet>(object_reg, "crystalspace.shared.stringset"); + + csRef<iGraphics3D> g3d = csQueryRegistry<iGraphics3D> (object_reg); + txtmgr = g3d->GetTextureManager(); + + engine->SetClearZBuf(true); + + if(keepModels) + { + PreloadTextures(); + } +} + +void Loader::PrecacheData(const char* path) +{ + if(vfs->Exists(path)) + { + csRef<iDocumentSystem> docsys = csQueryRegistry<iDocumentSystem>(object_reg); + csRef<iDocument> doc = docsys->CreateDocument(); + csRef<iDataBuffer> data = vfs->ReadFile(path); + + doc->Parse(data, true); + + csRef<iDocumentNode> root = doc->GetRoot()->GetNode("library"); + if(!root.IsValid()) + { + root = doc->GetRoot()->GetNode("world"); + } + + if(root.IsValid()) + { + csRef<iDocumentNode> node; + csRef<iDocumentNodeIterator> nodeItr; + + nodeItr = root->GetNodes("library"); + while(nodeItr->HasNext()) + { + node = nodeItr->Next(); + PrecacheData(node->GetContentsValue()); + } + + node = root->GetNode("plugins"); + if(node.IsValid()) + { + csRef<iThreadReturn> itr = tloader->LoadNode(node); + itr->Wait(); + } + + node = root->GetNode("shaders"); + if(node.IsValid()) + { + nodeItr = root->GetNodes("shader"); + while(nodeItr->HasNext()) + { + node = nodeItr->Next(); + node = node->GetNode("file"); + tloader->LoadShader(node->GetContentsValue()); + } + } + + node = root->GetNode("textures"); + if(node.IsValid()) + { + nodeItr = node->GetNodes("texture"); + while(nodeItr->HasNext()) + { + node = nodeItr->Next(); + csRef<Texture> t = csPtr<Texture>(new Texture()); + textures.Push(t); + t->name = node->GetAttributeValue("name"); + t->data = node; + } + } + + node = root->GetNode("materials"); + if(node.IsValid()) + { + nodeItr = node->GetNodes("material"); + while(nodeItr->HasNext()) + { + node = nodeItr->Next(); + csRef<Material> m = csPtr<Material>(new Material(node->GetAttributeValue("name"))); + materials.Push(m); + + if(node->GetNode("texture")) + { + node = node->GetNode("texture"); + m->shadervars.Push(ShaderVar("tex diffuse", csShaderVariable::TEXTURE, node->GetContentsValue())); + + for(size_t i=0; i<textures.GetSize(); i++) + { + if(textures[i]->name.Compare(node->GetContentsValue())) + { + m->textures.Push(textures[i]); + } + } + + node = node->GetParent(); + } + + csRef<iDocumentNodeIterator> nodeItr2 = node->GetNodes("shader"); + while(nodeItr2->HasNext()) + { + node = nodeItr2->Next(); + m->shaders.Push(Shader(node->GetAttributeValue("type"), node->GetContentsValue())); + node = node->GetParent(); + } + + nodeItr2 = node->GetNodes("shadervar"); + while(nodeItr2->HasNext()) + { + node = nodeItr2->Next(); + if(csString("texture").Compare(node->GetAttributeValue("type"))) + { + m->shadervars.Push(ShaderVar(node->GetAttributeValue("name"), csShaderVariable::TEXTURE, node->GetContentsValue())); + for(size_t i=0; i<textures.GetSize(); i++) + { + if(textures[i]->name.Compare(node->GetContentsValue())) + { + m->textures.Push(textures[i]); + } + } + } + node = node->GetParent(); + } + } + } + + nodeItr = root->GetNodes("meshfact"); + while(nodeItr->HasNext()) + { + node = nodeItr->Next(); + csRef<MeshFact> mf = csPtr<MeshFact>(new MeshFact(node->GetAttributeValue("name"), node)); + csRef<iDocumentNodeIterator> nodeItr3 = node->GetNode("params")->GetNodes("submesh"); + while(nodeItr3->HasNext()) + { + node = nodeItr3->Next(); + if(node->GetNode("material")) + { + for(size_t i=0; i<materials.GetSize(); i++) + { + if(materials[i]->name.Compare(node->GetNode("material")->GetContentsValue())) + { + mf->materials.PushSmart(materials[i]); + } + } + } + + node = node->GetParent()->GetParent(); + } + meshfacts.Push(mf); + } + + nodeItr = root->GetNodes("sector"); + while(nodeItr->HasNext()) + { + node = nodeItr->Next(); + + csRef<Sector> s; + csString sectorName = node->GetAttributeValue("name"); + for(size_t i=0; i<sectors.GetSize(); i++) + { + if(sectors[i]->name.Compare(sectorName)) + { + s = sectors[i]; + break; + } + } + + if(!s.IsValid()) + { + s = csPtr<Sector>(new Sector(sectorName)); + sectors.Push(s); + } + + s->culler = node->GetNode("cullerp")->GetContentsValue(); + if(node->GetNode("ambient")) + { + node = node->GetNode("ambient"); + s->ambient = csColor(node->GetAttributeValueAsFloat("red"), + node->GetAttributeValueAsFloat("green"), node->GetAttributeValueAsFloat("blue")); + node = node->GetParent(); + } + + csRef<iDocumentNodeIterator> nodeItr2 = node->GetNodes("meshobj"); + while(nodeItr2->HasNext()) + { + csRef<iDocumentNode> node2 = nodeItr2->Next(); + csRef<MeshObj> m = csPtr<MeshObj>(new MeshObj(node2->GetAttributeValue("name"), node2)); + + if(node2->GetNode("move")) + { + node2 = node2->GetNode("move")->GetNode("v"); + m->pos = csVector3(node2->GetAttributeValueAsFloat("x"), + node2->GetAttributeValueAsFloat("y"), node2->GetAttributeValueAsFloat("z")); + node2 = node2->GetParent()->GetParent(); + } + + if(node2->GetNode("paramsfile")) + { + csRef<iDocument> pdoc = docsys->CreateDocument(); + csRef<iDataBuffer> pdata = vfs->ReadFile(node2->GetNode("paramsfile")->GetContentsValue()); + pdoc->Parse(pdata, true); + node2 = pdoc->GetRoot(); + } + + csRef<iDocumentNodeIterator> nodeItr3 = node2->GetNode("params")->GetNodes("submesh"); + while(nodeItr3->HasNext()) + { + csRef<iDocumentNode> node3 = nodeItr3->Next(); + if(node3->GetNode("material")) + { + for(size_t i=0; i<materials.GetSize(); i++) + { + if(materials[i]->name.Compare(node3->GetNode("material")->GetContentsValue())) + { + m->materials.PushSmart(materials[i]); + } + } + } + + csRef<iDocumentNodeIterator> nodeItr4 = node3->GetNodes("shadervar"); + while(nodeItr4->HasNext()) + { + node3 = nodeItr4->Next(); + if(csString("texture").Compare(node3->GetAttributeValue("type"))) + { + for(size_t i=0; i<textures.GetSize(); i++) + { + if(textures[i]->name.Compare(node3->GetContentsValue())) + { + m->textures.PushSmart(textures[i]); + } + } + } + } + } + + node2 = node2->GetNode("params")->GetNode("factory"); + for(size_t i=0; i<meshfacts.GetSize(); i++) + { + if(meshfacts[i]->name.Compare(node2->GetContentsValue())) + { + m->meshfacts.PushSmart(meshfacts[i]); + } + } + + node2 = node2->GetParent()->GetNode("material"); + if(node2.IsValid()) + { + for(size_t i=0; i<materials.GetSize(); i++) + { + if(materials[i]->name.Compare(node2->GetContentsValue())) + { + m->materials.PushSmart(materials[i]); + } + } + } + + s->meshes.Push(m); + } + + if(node->GetNode("portals")) + { + nodeItr2 = node->GetNode("portals")->GetNodes("portal"); + while(nodeItr2->HasNext()) + { + csRef<iDocumentNode> node2 = nodeItr2->Next(); + csRef<Portal> p = csPtr<Portal>(new Portal(node2->GetAttributeValue("name"))); + + if(node2->GetNode("ww")) + { + node2 = node2->GetNode("ww"); + p->ww = csVector3(node2->GetAttributeValueAsFloat("x"), + node2->GetAttributeValueAsFloat("y"), node2->GetAttributeValueAsFloat("z")); + node2 = node2->GetParent(); + } + + csRef<iDocumentNodeIterator> nodeItr3 = node2->GetNodes("v"); + p->num_vertices = (int)nodeItr3->GetEndPosition(); + p->vertices = new csVector3[p->num_vertices]; + int i = 0; + while(nodeItr3->HasNext()) + { + node2 = nodeItr3->Next(); + p->vertices[i++] = csVector3(node2->GetAttributeValueAsFloat("x"), + node2->GetAttributeValueAsFloat("y"), node2->GetAttributeValueAsFloat("z")); + node2 = node2->GetParent(); + } + + csString targetSector = node2->GetNode("sector")->GetContentsValue(); + for(size_t i=0; i<sectors.GetSize(); i++) + { + if(targetSector == sectors[i]->name) + { + p->targetSector = sectors[i]; + break; + } + } + + if(!p->targetSector.IsValid()) + { + p->targetSector = csPtr<Sector>(new Sector(targetSector)); + sectors.Push(p->targetSector); + } + + s->portals.Push(p); + } + } + + nodeItr2 = node->GetNodes("light"); + while(nodeItr2->HasNext()) + { + node = nodeItr2->Next(); + csRef<Light> l = csPtr<Light>(new Light(node->GetAttributeValue("name"))); + + if(node->GetNode("attenuation")) + { + node = node->GetNode("attenuation"); + if(csString("none").Compare(node->GetContentsValue())) + { + l->attenuation = CS_ATTN_NONE; + } + else if(csString("linear").Compare(node->GetContentsValue())) + { + l->attenuation = CS_ATTN_LINEAR; + } + else if(csString("inverse").Compare(node->GetContentsValue())) + { + l->attenuation = CS_ATTN_INVERSE; + } + else if(csString("realistic").Compare(node->GetContentsValue())) + { + l->attenuation = CS_ATTN_REALISTIC; + } + else if(csString("clq").Compare(node->GetContentsValue())) + { + l->attenuation = CS_ATTN_CLQ; + } + + node = node->GetParent(); + } + else + { + l->attenuation = CS_ATTN_LINEAR; + } + + if(node->GetNode("dynamic")) + { + l->dynamic = CS_LIGHT_DYNAMICTYPE_PSEUDO; + } + else + { + l->dynamic = CS_LIGHT_DYNAMICTYPE_STATIC; + } + + l->type = CS_LIGHT_POINTLIGHT; + + node = node->GetNode("center"); + l->pos = csVector3(node->GetAttributeValueAsFloat("x"), + node->GetAttributeValueAsFloat("y"), node->GetAttributeValueAsFloat("z")); + node = node->GetParent(); + + l->radius = node->GetNode("radius")->GetContentsValueAsFloat(); + + node = node->GetNode("color"); + l->colour = csColor(node->GetAttributeValueAsFloat("red"), + node->GetAttributeValueAsFloat("green"), node->GetAttributeValueAsFloat("blue")); + node = node->GetParent(); + + s->lights.Push(l); + node = node->GetParent(); + } + } + } + } +} + +void Loader::UpdatePosition(csVector3& pos, const char* sectorName) +{ + csRef<Sector> sector; + for(size_t i=0; i<sectors.GetSize(); i++) + { + if(sectors[i]->name.Compare(sectorName)) + { + sector = sectors[i]; + break; + } + } + + if(sector.IsValid()) + LoadSector(pos, sector); +} + +void Loader::LoadSector(csVector3& pos, Sector* sector) +{ + sector->isLoading = true; + + if(!sector->object.IsValid()) + { + sector->object = engine->CreateSector(sector->name); + sector->object->SetDynamicAmbientLight(sector->ambient); + sector->object->SetVisibilityCullerPlugin(sector->culler); + } + + // Check already loading meshes. + for(size_t i=0; i<loadingMeshes.GetSize(); i++) + { + LoadMesh(sector, loadingMeshes[i]); + } + + for(size_t i=0; i<sector->meshes.GetSize(); i++) + { + if(!sector->meshes[i]->loading) + { + if(!sector->meshes[i]->object.IsValid() && csVector3(sector->meshes[i]->pos - pos).Norm() <= loadRange) + { + sector->meshes[i]->loading = true; + loadingMeshes.Push(sector->meshes[i]); + LoadMesh(sector, sector->meshes[i]); + ++sector->objectCount; + } + else if(sector->meshes[i]->object.IsValid() && csVector3(sector->meshes[i]->pos - pos).Norm() > loadRange*1.5) + { + sector->object->GetMeshes()->Remove(sector->meshes[i]->object); + engine->GetMeshes()->Remove(sector->meshes[i]->object); + sector->meshes[i]->object.Invalidate(); + --sector->objectCount; + } + } + } + + for(size_t i=0; i<sector->portals.GetSize(); i++) + { + if(!sector->portals[i]->mObject.IsValid() && sector->portals[i]->InRange(pos)) + { + if(!sector->portals[i]->targetSector->isLoading) + { + LoadSector(pos, sector->portals[i]->targetSector); + } + + sector->portals[i]->mObject = engine->CreatePortal(sector->portals[i]->name, sector->object, + csVector3(0), sector->portals[i]->targetSector->object, sector->portals[i]->vertices, + sector->portals[i]->num_vertices, sector->portals[i]->pObject); + ++sector->objectCount; + } + else if(sector->portals[i]->mObject.IsValid() && sector->portals[i]->OutOfRange(pos)) + { + if(!sector->portals[i]->targetSector->isLoading) + { + LoadSector(pos, sector->portals[i]->targetSector); + } + + engine->GetMeshes()->Remove(sector->portals[i]->mObject); + sector->portals[i]->pObject = NULL; + sector->portals[i]->mObject.Invalidate(); + --sector->objectCount; + } + } + + for(size_t i=0; i<sector->lights.GetSize(); i++) + { + if(!sector->lights[i]->object.IsValid() && csVector3(sector->lights[i]->pos - pos).Norm() <= loadRange) + { + sector->lights[i]->object = engine->CreateLight(sector->lights[i]->name, sector->lights[i]->pos, + sector->lights[i]->radius, sector->lights[i]->colour, sector->lights[i]->dynamic); + sector->lights[i]->object->SetAttenuationMode(sector->lights[i]->attenuation); + sector->lights[i]->object->SetType(sector->lights[i]->type); + sector->object->AddLight(sector->lights[i]->object); + ++sector->objectCount; + } + else if(sector->lights[i]->object.IsValid() && csVector3(sector->lights[i]->pos - pos).Norm() > loadRange*1.5) + { + engine->RemoveLight(sector->lights[i]->object); + sector->lights[i]->object.Invalidate(); + --sector->objectCount; + } + } + + if(sector->objectCount == 0 && sector->object.IsValid()) + { + engine->GetSectors()->Remove(sector->object); + sector->object.Invalidate(); + } + + sector->isLoading = false; +} + +void Loader::LoadMesh(Sector* sector, MeshObj* mesh) +{ + bool ready = true; + for(size_t i=0; i<mesh->meshfacts.GetSize(); i++) + { + ready &= LoadMeshFact(mesh->meshfacts[i]); + } + + for(size_t i=0; i<mesh->materials.GetSize(); i++) + { + ready &= LoadMaterial(mesh->materials[i]); + } + + for(size_t i=0; i<mesh->textures.GetSize(); i++) + { + ready &= LoadTexture(mesh->textures[i]); + } + + if(ready && !mesh->status) + { + mesh->status = tloader->LoadNode(mesh->data); + } + + if(mesh->status && mesh->status->IsFinished()) + { + mesh->object = scfQueryInterface<iMeshWrapper>(mesh->status->GetResultRefPtr()); + mesh->object->GetMovable()->SetSector(sector->object); + mesh->object->GetMovable()->UpdateMove(); + csRef<iCollideSystem> cdsys = csQueryRegistry<iCollideSystem> (object_reg); + csRef<csColliderWrapper> cw = csColliderHelper::InitializeCollisionWrapper(cdsys, mesh->object); + if(cw) + { + mesh->object->QueryObject()->ObjAdd(cw); + cw->SetObjectParent(mesh->object->QueryObject()); + } + loadingMeshes.Delete(mesh); + mesh->loading = false; + } +} + +bool Loader::LoadMeshFact(MeshFact* meshfact) +{ + if(meshfact->loaded) + { + return true; + } + + bool ready = true; + for(size_t i=0; i<meshfact->materials.GetSize(); i++) + { + ready &= LoadMaterial(meshfact->materials[i]); + } + + if(ready && !meshfact->status) + { + meshfact->status = tloader->LoadNode(meshfact->data); + return false; + } + + if(meshfact->status && meshfact->status->IsFinished()) + { + meshfact->loaded = true; + return true; + } + + return false; +} + +bool Loader::LoadMaterial(Material* material) +{ + if(material->loaded) + { + return true; + } + + bool ready = true; + for(size_t i=0; i<material->textures.GetSize(); i++) + { + ready &= LoadTexture(material->textures[i]); + } + + if(ready) + { + csArray<csStringID> shadertypes; + csArray<iShader*> shaderptrs; + csRefArray<csShaderVariable> shadervars; + + csRef<iMaterial> mat (engine->CreateBaseMaterial(0)); + iMaterialWrapper* mw = engine->GetMaterialList()->NewMaterial(mat, material->name); + + for(size_t i=0; i<material->shaders.GetSize(); i++) + { + csRef<iShaderManager> shaderMgr = csQueryRegistry<iShaderManager> (object_reg); + iShader* shader = shaderMgr->GetShader(material->shaders[i].name); + csStringID type = strings->Request(material->shaders[i].type); + mat->SetShader(type, shader); + } + + for(size_t i=0; i<material->shadervars.GetSize(); i++) + { + for(size_t j=0; j<material->textures.GetSize(); j++) + { + if(material->textures[j]->name.Compare(material->shadervars[i].value)) + { + csShaderVariable* var = mat->GetVariableAdd(svstrings->Request(material->shadervars[i].name)); + var->SetType(material->shadervars[i].type); + csRef<iTextureWrapper> tex = scfQueryInterface<iTextureWrapper>(material->textures[j]->status->GetResultRefPtr()); + var->SetValue(tex); + break; + } + } + } + + material->loaded = true; + return true; + } + + return false; +} + +bool Loader::LoadTexture(Texture* texture) +{ + if(texture->loaded) + { + return true; + } + + if(!texture->status.IsValid()) + { + texture->status = tloader->LoadNode(texture->data); + return false; + } + + if(!texture->status->IsFinished()) + { + return false; + } + + texture->loaded = true; + return true; +} + +iMaterialWrapper* Loader::LoadMaterial(const char *name, const char *filename) +{ + iMaterialWrapper* materialWrap = engine->GetMaterialList()->FindByName(name); + if(!materialWrap) + { + // Check that the texture exists. + if(!vfs->Exists(filename)) + return NULL; + + // Load base texture. + iTextureWrapper* texture = LoadTexture(name, filename); + + // Load base material. + csRef<iMaterial> material (engine->CreateBaseMaterial(texture)); + materialWrap = engine->GetMaterialList()->NewMaterial(material, name); + + // Check for shader maps. + if(gfxFeatures & useAdvancedShaders) + { + csString shadermapBase = filename; + shadermapBase.Truncate(shadermapBase.Length()-4); + + // Normal map + csString shadermap = shadermapBase; + shadermap.Append("_n.dds"); + if(vfs->Exists(shadermap)) + { + iTextureWrapper* t = LoadTexture(shadermap, shadermap, "normalmap"); + csShaderVariable* shadervar = new csShaderVariable(); + shadervar->SetName(svstrings->Request("tex normal compressed")); + shadervar->SetValue(t); + material->AddVariable(shadervar); + } + + // Height map + shadermap = shadermapBase; + shadermap.Append("_h.dds"); + if(vfs->Exists(shadermap)) + { + iTextureWrapper* t = LoadTexture(shadermap, shadermap); + csShaderVariable* shadervar = new csShaderVariable(); + shadervar->SetName(svstrings->Request("tex height")); + shadervar->SetValue(t); + material->AddVariable(shadervar); + } + + // Spec map + shadermap = shadermapBase; + shadermap.Append("_s.dds"); + if(vfs->Exists(shadermap)) + { + iTextureWrapper* t = LoadTexture(shadermap, shadermap); + csShaderVariable* shadervar = new csShaderVariable(); + shadervar->SetName(svstrings->Request("tex specular")); + shadervar->SetValue(t); + material->AddVariable(shadervar); + } + + // Gloss map + shadermap = shadermapBase; + shadermap.Append("_sgdds"); + if(vfs->Exists(shadermap)) + { + iTextureWrapper* t = LoadTexture(shadermap, shadermap); + csShaderVariable* shadervar = new csShaderVariable(); + shadervar->SetName(svstrings->Request("tex gloss")); + shadervar->SetValue(t); + material->AddVariable(shadervar); + } + + // AO map + shadermap = shadermapBase; + shadermap.Append("_ao.dds"); + if(vfs->Exists(shadermap)) + { + iTextureWrapper* t = LoadTexture(shadermap, shadermap); + csShaderVariable* shadervar = new csShaderVariable(); + shadervar->SetName(svstrings->Request("tex ambient occlusion")); + shadervar->SetValue(t); + material->AddVariable(shadervar); + } + } + } + return materialWrap; +} + +iTextureWrapper* Loader::LoadTexture(const char *name, const char *filename, const char* className) +{ + // name is the material name; blah.dds + // filename will be /planeshift/blah/blah.dds + csString tempName; + if(!name) + { + tempName = filename; + size_t last = tempName.FindLast('/'); + tempName.DeleteAt(0, last+1); + name = tempName.GetData(); + } + + csRef<iTextureWrapper> texture = engine->GetTextureList()->FindByName(name); + + if(!texture) + { + csRef<iThreadReturn> itr = tloader->LoadTexture(name, filename, CS_TEXTURE_3D, txtmgr, true, false); + itr->Wait(); + texture = scfQueryInterfaceSafe<iTextureWrapper>(itr->GetResultRefPtr()); + if(className) + { + texture->SetTextureClass(className); + } + engine->SyncEngineListsNow(tloader); + } + + if (!texture) + { + csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, + "planeshift.engine.celbase", + "Error loading texture '%s'!", + name); + return false; + } + return texture; +} + +bool Loader::LoadTextureDir(const char *dir) +{ + csRef<iDataBuffer> xpath = vfs->ExpandPath(dir); + csRef<iStringArray> files = vfs->FindFiles( **xpath ); + + if (!files) + return false; + + for (size_t i=0; i < files->GetSize(); i++) + { + const char* filename = files->Get(i); + if (strcmp (filename + strlen(filename) - 4, ".png") && + strcmp (filename + strlen(filename) - 4, ".tga") && + strcmp (filename + strlen(filename) - 4, ".gif") && + strcmp (filename + strlen(filename) - 4, ".bmp") && + strcmp (filename + strlen(filename) - 4, ".jpg") && + strcmp (filename + strlen(filename) - 4, ".dds")) + continue; + + // If this is an icon or shader map texture then we don't load as a material. + if(strstr(filename, "_icon" ) || strstr(filename, "_n." ) || strstr(filename, "_h." ) || + strstr(filename, "_s." ) || strstr(filename, "_g." ) || strstr(filename, "_ao." )) + continue; + + const char* name = csStrNew(filename); + const char* onlyname = PS_GetFileName(name); + + if (!LoadMaterial(onlyname,filename)) + { + delete[] name; + return false; + } + delete[] name; + } + return true; +} + +bool Loader::PreloadTextures() +{ + // characters + if (!LoadTextureDir("/planeshift/models/")) + return false; + + // Load the textures for the weapons. + if (!LoadTextureDir("/planeshift/weapons/")) + return false; + + if (!LoadTextureDir("/planeshift/shields/")) + return false; + + // Load the textures for the items. + if (!LoadTextureDir("/planeshift/items/")) + return false; + + // Load the textures for the spell effects + if (!LoadTextureDir("/planeshift/art/effects/")) + return false; + + // Load the textures for the resources items + if (!LoadTextureDir("/planeshift/naturalres/")) + return false; + + // Load the textures for the tools items + if (!LoadTextureDir("/planeshift/tools/")) + return false; + + // Load the textures for the food items + if (!LoadTextureDir("/planeshift/food/")) + return false; + + engine->SyncEngineListsNow(tloader); + + return true; +} Property changes on: trunk/src/common/engine/loader.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/src/common/engine/loader.h =================================================================== --- trunk/src/common/engine/loader.h (rev 0) +++ trunk/src/common/engine/loader.h 2008-12-21 20:54:57 UTC (rev 2734) @@ -0,0 +1,261 @@ +/* + * loader.h - Author: Mike Gist + * + * 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 __LOADER_H__ +#define __LOADER_H__ + +#include <csgfx/shadervar.h> +#include <csutil/scf_implementation.h> + +#include <iengine/engine.h> +#include <iengine/material.h> +#include <iengine/mesh.h> +#include <iengine/sector.h> +#include <iengine/texture.h> +#include <imap/loader.h> +#include <iutil/objreg.h> +#include <iutil/vfs.h> + +#include "util/singleton.h" + +struct iObjectRegistry; + +class Loader : public Singleton<Loader> +{ +public: + void Init(iObjectRegistry* _object_reg, bool _keepModels, uint gfxFeatures, float loadRange); + + iMaterialWrapper* LoadMaterial (const char* name, const char* filename); + + iTextureWrapper* LoadTexture (const char* name, const char* filename, const char* className = 0); + + void PrecacheData(const char* path); + void UpdatePosition(csVector3& pos, const char* sectorName); + + bool PreloadTextures(); + bool KeepModels() { return keepModels; } + + iThreadedLoader* GetLoader() { return tloader; } + + size_t GetLoadingCount() { return loadingMeshes.GetSize(); } + +private: + class Texture; + class Material; + class MeshFact; + class Sector; + class MeshObj; + class Portal; + class Light; + + void LoadSector(csVector3& pos, Sector* sector); + void LoadMesh(Sector* sector, MeshObj* mesh); + bool LoadMeshFact(MeshFact* meshfact); + bool LoadMaterial(Material* material); + bool LoadTexture(Texture* texture); + + bool LoadTextureDir(const char *dir); + bool keepModels; + float loadRange; + + iObjectRegistry* object_reg; + csRef<iEngine> engine; + csRef<iTextureManager> txtmgr; + csRef<iThreadedLoader> tloader; + csRef<iVFS> vfs; + csRef<iShaderVarStringSet> svstrings; + csRef<iStringSet> strings; + uint gfxFeatures; + + csVector3 curPos; + csString curSector; + + csRefArray<MeshObj> loadingMeshes; + + csRefArray<Texture> textures; + csRefArray<Material> materials; + csRefArray<MeshFact> meshfacts; + csRefArray<Sector> sectors; + + struct Shader + { + csString type; + csString name; + + Shader(const char* type, const char* name) + : type(type), name(name) + { + } + }; + + struct ShaderVar + { + csString name; + csShaderVariable::VariableType type; + csString value; + + ShaderVar(const char* name, csShaderVariable::VariableType type, const char* value) + : name(name), type(type), value(value) + { + } + }; + + class Texture : public CS::Utility::FastRefCount<Texture> + { + public: + Texture(const char* name = "") + : name(name), loaded(false) + { + } + + bool loaded; + csRef<iThreadReturn> status; + csString name; + csRef<iDocumentNode> data; + }; + + class Material : public CS::Utility::FastRefCount<Material> + { + public: + Material(const char* name = "") + : name(name), loaded(false) + { + } + + bool loaded; + csString name; + csArray<Shader> shaders; + csArray<ShaderVar> shadervars; + csRefArray<Texture> textures; + }; + + class MeshFact : public CS::Utility::FastRefCount<MeshFact> + { + public: + MeshFact(const char* name, iDocumentNode* data) : name(name), data(data), loaded(false) + { + } + + bool loaded; + csRef<iThreadReturn> status; + csString name; + csRef<iDocumentNode> data; + csRefArray<Material> materials; + }; + + class Sector : public CS::Utility::FastRefCount<Sector> + { + public: + Sector(const char* name) : name(name), isLoading(false) + { + ambient = csColor(0.0f); + } + + bool isLoading; + csString name; + csString culler; + csColor ambient; + size_t objectCount; + csRef<iSector> object; + csRefArray<MeshObj> meshes; + csRefArray<Portal> portals; + csRefArray<Light> lights; + }; + + class MeshObj : public CS::Utility::FastRefCount<MeshObj> + { + public: + MeshObj(const char* name, iDocumentNode* data) : name(name), data(data), loading(false) + { + } + + csString name; + csRef<iDocumentNode> data; + csVector3 pos; + + bool loading; + csRef<iThreadReturn> status; + csRef<iMeshWrapper> object; + csRefArray<Texture> textures; + csRefArray<Material> materials; + csRefArray<MeshFact> meshfacts; + }; + + class Portal : public CS::Utility::FastRefCount<Portal> + { + public: + Portal(const char* name) : name(name) + { + } + + bool InRange(csVector3& pos) + { + for(int i=0; i<num_vertices; i++) + { + if(csVector3(vertices[i] - pos).Norm() <= Loader::GetSingleton().loadRange) + { + return true; + } + } + + return false; + } + + bool OutOfRange(csVector3& pos) + { + for(int i=0; i<num_vertices; i++) + { + if(csVector3(vertices[i] - pos).Norm() <= Loader::GetSingleton().loadRange*1.5) + { + return false; + } + } + + return true; + } + + csString name; + csVector3* vertices; + csVector3 ww; + int num_vertices; + + csRef<Sector> targetSector; + iPortal* pObject; + csRef<iMeshWrapper> mObject; + }; + + class Light : public CS::Utility::FastRefCount<Light> + { + public: + Light(const char* name) : name(name) + { + } + + csRef<iLight> object; + csString name; + csVector3 pos; + float radius; + csColor colour; + csLightDynamicType dynamic; + csLightAttenuationMode attenuation; + csLightType type; + }; +}; + +#endif // __LOADER_H__ Property changes on: trunk/src/common/engine/loader.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Deleted: trunk/src/common/engine/materialmanager.cpp =================================================================== --- trunk/src/common/engine/materialmanager.cpp 2008-12-21 18:12:36 UTC (rev 2733) +++ trunk/src/common/engine/materialmanager.cpp 2008-12-21 20:54:57 UTC (rev 2734) @@ -1,227 +0,0 @@ -/* - * materialmanager.cpp - Author: Mike Gist - * - * Copyright (C) 2007 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> - -#include <iutil/stringarray.h> -#include <iutil/object.h> -#include <ivideo/material.h> - -#include "materialmanager.h" -#include "util/strutil.h" -#include "globals.h" - -MaterialManager::MaterialManager(iObjectRegistry* _object_reg, bool _keepModels, uint gfxFeatures) : gfxFeatures(gfxFeatures) -{ - object_reg = _object_reg; - csRef<iGraphics3D> g3d = csQueryRegistry<iGraphics3D> (object_reg); - txtmgr = g3d->GetTextureManager(); - engine = csQueryRegistry<iEngine> (object_reg); - loader = csQueryRegistry<iThreadedLoader> (object_reg); - vfs = csQueryRegistry<iVFS> (object_reg); - keepModels = _keepModels; - strings = csQueryRegistryTagInterface<iShaderVarStringSet>(object_reg, "crystalspace.shader.variablenameset"); -} - -iMaterialWrapper* MaterialManager::LoadMaterial(const char *name, const char *filename) -{ - iMaterialWrapper* materialWrap = engine->GetMaterialList()->FindByName(name); - if(!materialWrap) - { - // Check that the texture exists. - if(!vfs->Exists(filename)) - return NULL; - - // Load base texture. - iTextureWrapper* texture = LoadTexture(name, filename); - - // Load base material. - csRef<iMaterial> material (engine->CreateBaseMaterial(textu... [truncated message content] |