From: <mg...@us...> - 2010-02-02 20:00:15
|
Revision: 5435 http://planeshift.svn.sourceforge.net/planeshift/?rev=5435&view=rev Author: mgist Date: 2010-02-02 20:00:09 +0000 (Tue, 02 Feb 2010) Log Message: ----------- - Probably fixed model scaling. Needs testing. Modified Paths: -------------- trunk/src/client/iclient/ibgloader.h trunk/src/client/pscelclient.cpp trunk/src/common/bgloader/loader.cpp trunk/src/common/bgloader/loader.h Modified: trunk/src/client/iclient/ibgloader.h =================================================================== --- trunk/src/client/iclient/ibgloader.h 2010-02-02 13:26:43 UTC (rev 5434) +++ trunk/src/client/iclient/ibgloader.h 2010-02-02 20:00:09 UTC (rev 5435) @@ -45,7 +45,7 @@ */ struct iBgLoader : public virtual iBase { - SCF_INTERFACE(iBgLoader, 1, 5, 0); + SCF_INTERFACE(iBgLoader, 1, 6, 0); /** * Start loading a material into the engine. Returns 0 if the material is not yet loaded. @@ -59,6 +59,15 @@ */ virtual csPtr<iMeshFactoryWrapper> LoadFactory(const char* name, bool* failed = NULL, bool wait = false) = 0; + /** + * Clone a mesh factory. + * @param name The name of the mesh factory to clone. + * @param newName The name of the new cloned mesh factory. + * @param load Begin loading the cloned mesh factory. + * @param failed Pass a boolean to be able to manually handle a failed clone. + */ + virtual void CloneFactory(const char* name, const char* newName, bool load = false, bool* failed = NULL) = 0; + /** * Pass a data file to be cached. This method will parse your data and add it to it's * internal world representation. You may then request that these objects are loaded. Modified: trunk/src/client/pscelclient.cpp =================================================================== --- trunk/src/client/pscelclient.cpp 2010-02-02 13:26:43 UTC (rev 5434) +++ trunk/src/client/pscelclient.cpp 2010-02-02 20:00:09 UTC (rev 5435) @@ -1368,6 +1368,46 @@ else cel->HandleUnresolvedPos(this, mesg.pos, mesg.yrot, mesg.sectorName); + // Check whether we need to use a clone of our meshfact. + // This is needed when we have to scale. + if(scale > 0.0f) + { + bool failed = false; + csString newFactName = factName+race; + + psengine->GetLoader()->CloneFactory(factName, newFactName, true, &failed); + + if(failed) + { + Error2("Failed to clone mesh factory: %s\n", factName.GetData()); + scale = 0.0f; + } + else + { + factName = newFactName; + } + } + + if(mountScale > 0.0f) + { + bool failed = false; + csString newFactName = mountFactname; + newFactName.AppendFmt("%f", mountScale); + + psengine->GetLoader()->CloneFactory(mountFactname, newFactName, true, &failed); + + if(failed) + { + Error2("Failed to clone mesh factory: %s\n", mountFactname.GetData()); + mountScale = 0.0f; + } + else + { + mountFactname = newFactName; + } + } + + LoadMesh(); DRcounter = 0; // mesg.counter cannot be trusted as it may have changed while the object was gone Modified: trunk/src/common/bgloader/loader.cpp =================================================================== --- trunk/src/common/bgloader/loader.cpp 2010-02-02 13:26:43 UTC (rev 5434) +++ trunk/src/common/bgloader/loader.cpp 2010-02-02 20:00:09 UTC (rev 5435) @@ -1270,6 +1270,36 @@ return csPtr<iMeshFactoryWrapper>(0); } +void BgLoader::CloneFactory(const char* name, const char* newName, bool load, bool* failed) +{ + // Find meshfact to clone. + csRef<MeshFact> meshfact = meshfacts.Get(mfStringSet.Request(name), csRef<MeshFact>()); + { + if(!failed) + { + // Validation. + csString msg; + msg.Format("Invalid factory reference '%s' passed for cloning.", name); + CS_ASSERT_MSG(msg.GetData(), meshfact.IsValid()); + } + else if(!meshfact.IsValid()) + { + *failed = true; + return; + } + } + + // Create a clone. + csRef<MeshFact> newMeshFact = meshfact->Clone(newName); + meshfacts.Put(mfStringSet.Request(newName), newMeshFact); + + // Optionally begin loading. + if(load) + { + LoadMeshFact(newMeshFact); + } +} + csPtr<iMaterialWrapper> BgLoader::LoadMaterial(const char* name, bool* failed, bool wait) { csRef<Material> material = materials.Get(mStringSet.Request(name), csRef<Material>()); Modified: trunk/src/common/bgloader/loader.h =================================================================== --- trunk/src/common/bgloader/loader.h 2010-02-02 13:26:43 UTC (rev 5434) +++ trunk/src/common/bgloader/loader.h 2010-02-02 20:00:09 UTC (rev 5435) @@ -73,6 +73,15 @@ */ csPtr<iMeshFactoryWrapper> LoadFactory(const char* name, bool* failed = NULL, bool wait = false); + /** + * Clone a mesh factory. + * @param name The name of the mesh factory to clone. + * @param newName The name of the new cloned mesh factory. + * @param load Begin loading the cloned mesh factory. + * @param failed Pass a boolean to be able to manually handle a failed clone. + */ + void CloneFactory(const char* name, const char* newName, bool load = false, bool* failed = NULL); + /** * Pass a data file to be cached. This method will parse your data and add it to it's * internal world representation. You may then request that these objects are loaded. @@ -304,6 +313,19 @@ { } + csPtr<MeshFact> Clone(const char* clonedName) + { + csRef<MeshFact> meshfact; + meshfact.AttachNew(new MeshFact(clonedName, path, data)); + + meshfact->filename = filename; + meshfact->materials = materials; + meshfact->bboxvs = bboxvs; + meshfact->submeshes = submeshes; + + return csPtr<MeshFact>(meshfact); + } + csString name; csString filename; csString path; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |