From d2c87f7bf7f850957ee7b6620496d5919f04cb79 Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 31 Jan 2008 21:07:25 +0000 Subject: [PATCH] Moved VolumeResource, VolumeSerializer, and VolumeManager to main application. --- CMakeLists.txt | 8 +-- include/PolyVoxSceneManager.h | 1 - include/VolumeManager.h | 30 ----------- include/VolumeResource.h | 92 --------------------------------- include/VolumeSerializer.h | 21 -------- source/PolyVoxSceneManager.cpp | 1 - source/Volume.cpp | 2 - source/VolumeManager.cpp | 59 --------------------- source/VolumeResource.cpp | 93 ---------------------------------- source/VolumeSerializer.cpp | 85 ------------------------------- 10 files changed, 1 insertion(+), 391 deletions(-) delete mode 100644 include/VolumeManager.h delete mode 100644 include/VolumeResource.h delete mode 100644 include/VolumeSerializer.h delete mode 100644 source/VolumeManager.cpp delete mode 100644 source/VolumeResource.cpp delete mode 100644 source/VolumeSerializer.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 435bab62..1d2ab837 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,9 +12,6 @@ SET(SRC_FILES source/SurfaceVertex.cpp source/Volume.cpp source/VolumeIterator.cpp - source/VolumeManager.cpp - source/VolumeResource.cpp - source/VolumeSerializer.cpp ) #Projects headers files @@ -33,10 +30,7 @@ SET(INC_FILES include/SurfaceVertex.h include/TypeDef.h include/Volume.h - include/VolumeIterator.h - include/VolumeManager.h - include/VolumeResource.h - include/VolumeSerializer.h + include/VolumeIterator.h ) ADD_DEFINITIONS(-DVOXEL_SCENE_MANAGER_EXPORT) #Export symbols in the .dll diff --git a/include/PolyVoxSceneManager.h b/include/PolyVoxSceneManager.h index 5fa54247..d9018d36 100644 --- a/include/PolyVoxSceneManager.h +++ b/include/PolyVoxSceneManager.h @@ -31,7 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "Volume.h" #include "SurfaceVertex.h" #include "RegionGeometry.h" -#include "VolumeResource.h" #include diff --git a/include/VolumeManager.h b/include/VolumeManager.h deleted file mode 100644 index 96bc09ea..00000000 --- a/include/VolumeManager.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __VOLUMEMANAGER_H__ -#define __VOLUMEMANAGER_H__ - -#include -#include "VolumeResource.h" - -namespace Ogre -{ - class VOXEL_SCENE_MANAGER_API VolumeManager : public Ogre::ResourceManager, public Ogre::Singleton - { - protected: - - // must implement this from ResourceManager's interface - Ogre::Resource *createImpl(const Ogre::String &name, Ogre::ResourceHandle handle, - const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader, - const Ogre::NameValuePairList *createParams); - - public: - - VolumeManager (); - virtual ~VolumeManager (); - - virtual VolumeResourcePtr load (const Ogre::String &name, const Ogre::String &group); - - static VolumeManager &getSingleton (); - static VolumeManager *getSingletonPtr (); - }; -} - -#endif diff --git a/include/VolumeResource.h b/include/VolumeResource.h deleted file mode 100644 index 9989a4e5..00000000 --- a/include/VolumeResource.h +++ /dev/null @@ -1,92 +0,0 @@ -/****************************************************************************** -This file is part of a voxel plugin for OGRE -Copyright (C) 2006 David Williams - -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; either version 2 -of the License, or (at your option) any later version. - -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -******************************************************************************/ -#ifndef __VolumeResource_H__ -#define __VolumeResource_H__ - -#include "OgrePrerequisites.h" -#include "OgreSharedPtr.h" - -#include "Block.h" -#include "Constants.h" -#include "TypeDef.h" -#include "IntegralVector3.h" -#include "Volume.h" - -#include - -namespace Ogre -{ - class VOXEL_SCENE_MANAGER_API VolumeResource : public Ogre::Resource - { - public: - VolumeResource (Ogre::ResourceManager *creator, const Ogre::String &name, - Ogre::ResourceHandle handle, const Ogre::String &group, bool isManual = false, - Ogre::ManualResourceLoader *loader = 0); - ~VolumeResource(); - - Volume* volume; - - protected: - - // must implement these from the Ogre::Resource interface - void loadImpl (); - void unloadImpl (); - size_t calculateSize () const; - }; - - class VolumeResourcePtr : public Ogre::SharedPtr - { - public: - VolumeResourcePtr () : Ogre::SharedPtr () {} - explicit VolumeResourcePtr (VolumeResource *rep) : Ogre::SharedPtr (rep) {} - VolumeResourcePtr (const VolumeResourcePtr &r) : Ogre::SharedPtr (r) {} - VolumeResourcePtr (const Ogre::ResourcePtr &r) : Ogre::SharedPtr () - { - // lock & copy other mutex pointer - OGRE_LOCK_MUTEX (*r.OGRE_AUTO_MUTEX_NAME) - OGRE_COPY_AUTO_SHARED_MUTEX (r.OGRE_AUTO_MUTEX_NAME) - pRep = static_cast (r.getPointer ()); - pUseCount = r.useCountPointer (); - if (pUseCount) - { - ++ (*pUseCount); - } - } - - /// Operator used to convert a ResourcePtr to a VolumeResourcePtr - VolumeResourcePtr& operator=(const Ogre::ResourcePtr& r) - { - if (pRep == static_cast (r.getPointer ())) - return *this; - release (); - // lock & copy other mutex pointer - OGRE_LOCK_MUTEX (*r.OGRE_AUTO_MUTEX_NAME) - OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) - pRep = static_cast (r.getPointer()); - pUseCount = r.useCountPointer (); - if (pUseCount) - { - ++ (*pUseCount); - } - return *this; - } - }; -} - -#endif diff --git a/include/VolumeSerializer.h b/include/VolumeSerializer.h deleted file mode 100644 index 82618faa..00000000 --- a/include/VolumeSerializer.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __VOLUMESERIALIZER_H__ -#define __VOLUMESERIALIZER_H__ - -#include - -namespace Ogre -{ - class Volume; // forward declaration - - class VolumeSerializer : public Ogre::Serializer - { - public: - VolumeSerializer (); - virtual ~VolumeSerializer (); - - //void exportVolume (const Volume *pText, const Ogre::String &fileName); - void importVolume (Ogre::DataStreamPtr &stream, Volume *pDest); - }; -} - -#endif diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index 59743786..0e1e09af 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "IndexedSurfacePatch.h" #include "PolyVoxSceneManager.h" #include "VolumeIterator.h" -#include "VolumeManager.h" #include "OgreStringConverter.h" #include "OgreLogManager.h" diff --git a/source/Volume.cpp b/source/Volume.cpp index 032dd290..abeaed7e 100644 --- a/source/Volume.cpp +++ b/source/Volume.cpp @@ -21,8 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "Volume.h" #include "VolumeIterator.h" -#include "VolumeSerializer.h" - #include "OgreVector3.h" #include "OgreLogManager.h" #include "OgreStringConverter.h" diff --git a/source/VolumeManager.cpp b/source/VolumeManager.cpp deleted file mode 100644 index 453c0e3b..00000000 --- a/source/VolumeManager.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "VolumeManager.h" - -#include "OgreLogManager.h" //FIXME - shouldn't realy need this in this class?' - -namespace Ogre -{ - template<> VolumeManager *Ogre::Singleton::ms_Singleton = 0; - - VolumeManager *VolumeManager::getSingletonPtr () - { - return ms_Singleton; - } - - VolumeManager &VolumeManager::getSingleton () - { - assert (ms_Singleton); - return (*ms_Singleton); - } - - VolumeManager::VolumeManager () - { - mResourceType = "Volume"; - - // low, because it will likely reference other resources - mLoadOrder = 30.0f; - - // this is how we register the ResourceManager with OGRE - Ogre::ResourceGroupManager::getSingleton ()._registerResourceManager (mResourceType, this); - } - - VolumeManager::~VolumeManager() - { - // and this is how we unregister it - Ogre::ResourceGroupManager::getSingleton ()._unregisterResourceManager (mResourceType); - } - - VolumeResourcePtr VolumeManager::load (const Ogre::String &name, const Ogre::String &group) - { - Ogre::LogManager::getSingleton().logMessage("DAVID - calling getByName"); - VolumeResourcePtr textf = getByName (name); - Ogre::LogManager::getSingleton().logMessage("DAVID - done getByName"); - - if (textf.isNull ()) - { - textf = create (name, group); - } - - textf->load (); - - return textf; - } - - Ogre::Resource *VolumeManager::createImpl (const Ogre::String &name, Ogre::ResourceHandle handle, - const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader, - const Ogre::NameValuePairList *createParams) - { - return new VolumeResource (this, name, handle, group, isManual, loader); - } -} diff --git a/source/VolumeResource.cpp b/source/VolumeResource.cpp deleted file mode 100644 index 4d45183f..00000000 --- a/source/VolumeResource.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/****************************************************************************** -This file is part of a voxel plugin for OGRE -Copyright (C) 2006 David Williams - -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; either version 2 -of the License, or (at your option) any later version. - -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -******************************************************************************/ - -#include "IntegralVector3.h" -#include "VolumeResource.h" -#include "VolumeIterator.h" - -#include "VolumeSerializer.h" - -#include "OgreVector3.h" -#include "OgreLogManager.h" -#include "OgreStringConverter.h" - -#include //FIXME - remove this... - -namespace Ogre -{ - VolumeResource::VolumeResource (Ogre::ResourceManager* creator, const Ogre::String &name, - Ogre::ResourceHandle handle, const Ogre::String &group, bool isManual, - Ogre::ManualResourceLoader *loader) : - Ogre::Resource (creator, name, handle, group, isManual, loader) - { - /* If you were storing a pointer to an object, then you would set that pointer to NULL here. - */ - - /* For consistency with StringInterface, but we don't add any parameters here - That's because the Resource implementation of StringInterface is to - list all the options that need to be set before loading, of which - we have none as such. Full details can be set through scripts. - */ - createParamDictionary ("Volume"); - - volume = new Volume(); - } - - VolumeResource::~VolumeResource() - { - unload (); - } - - // farm out to VolumeSerializer - void VolumeResource::loadImpl () - { - /* If you were storing a pointer to an object, then you would create that object with 'new' here. - */ - - VolumeSerializer serializer; - Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton ().openResource (mName, mGroup, true, this); - serializer.importVolume (stream, this->volume); - } - - void VolumeResource::unloadImpl () - { - /* If you were storing a pointer to an object, then you would check the pointer here, - and if it is not NULL, you would destruct the object and set its pointer to NULL again. - */ - - //mString.clear (); - } - - size_t VolumeResource::calculateSize () const - { - //NOTE - I don't really know what this function is for, so am therefore - //a bit vague on how to implement it. But here's my best guess... - ulong uNonHomogeneousBlocks = 0; - for(uint i = 0; i < OGRE_NO_OF_BLOCKS_IN_VOLUME; ++i) - { - //I think this is OK... If a block is in the homogeneous array it's ref count will be greater - //than 1 as there will be the pointer in the volume and the pointer in the static homogeneous array. - if(volume->mBlocks[i].unique()) - { - ++uNonHomogeneousBlocks; - } - } - return uNonHomogeneousBlocks * OGRE_NO_OF_VOXELS_IN_BLOCK; - } -} diff --git a/source/VolumeSerializer.cpp b/source/VolumeSerializer.cpp deleted file mode 100644 index 72df3a95..00000000 --- a/source/VolumeSerializer.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "VolumeSerializer.h" -#include "Volume.h" - -#include "VolumeIterator.h" - -#include "OgreLogManager.h" -#include "OgreStringConverter.h" - -namespace Ogre -{ - VolumeSerializer::VolumeSerializer () - { - - } - - VolumeSerializer::~VolumeSerializer () - { - - } - - /*void VolumeSerializer::exportVolume (const Volume *pText, const Ogre::String &fileName) - { - std::ofstream outFile; - outFile.open (fileName.c_str(), std::ios::out); - outFile << pText->getString (); - outFile.close (); - }*/ - - void VolumeSerializer::importVolume (Ogre::DataStreamPtr &stream, Volume *pDest) - { - //pDest->setString (stream->getAsString ()); - //Volume vol; - - //Read volume dimensions - uchar volumeWidth = 0; - uchar volumeHeight = 0; - uchar volumeDepth = 0; - stream->read(reinterpret_cast(&volumeWidth), sizeof(volumeWidth)); - stream->read(reinterpret_cast(&volumeHeight), sizeof(volumeHeight)); - stream->read(reinterpret_cast(&volumeDepth), sizeof(volumeDepth)); - /*if(stream->fail()) - { - LogManager::getSingleton().logMessage("Failed to read dimentions"); - return false; - } */ - - //Read data - VolumeIterator volIter(*pDest); - for(uint z = 0; z < OGRE_VOLUME_SIDE_LENGTH; ++z) - { - for(uint y = 0; y < OGRE_VOLUME_SIDE_LENGTH; ++y) - { - for(uint x = 0; x < OGRE_VOLUME_SIDE_LENGTH; ++x) - { - uchar value = 0; - stream->read(reinterpret_cast(&value), sizeof(value)); //FIXME - check for error here - /*if(value != 0) - { - LogManager::getSingleton().logMessage("Value is " + StringConverter::toString(int(value))); - }*/ - volIter.setVoxelAt(x,y,z,value); - /*if(z < 24) - { - if(x % 32 < 16) - volIter.setVoxelAt(x,y,z,5); - else - volIter.setVoxelAt(x,y,z,5); - } - else - volIter.setVoxelAt(x,y,z,0);*/ - } - } - //volIter.setVoxelAt(130,130,23,0); - - //Periodically see if we can tidy the memory to avoid excessive usage during loading. - if(z%OGRE_BLOCK_SIDE_LENGTH == OGRE_BLOCK_SIDE_LENGTH-1) - { - pDest->tidy(); //FIXME - we don't actually have to tidy the whole volume here - just the part we loaded since the last call to tidy. - } - } - - /*vol.load(stream->getName());*/ - //pDest->setVolume(vol); - } -}