Moved VolumeResource, VolumeSerializer, and VolumeManager to main application.

This commit is contained in:
David Williams
2008-01-31 21:07:25 +00:00
parent 4438660440
commit d2c87f7bf7
10 changed files with 1 additions and 391 deletions

View File

@ -12,9 +12,6 @@ SET(SRC_FILES
source/SurfaceVertex.cpp source/SurfaceVertex.cpp
source/Volume.cpp source/Volume.cpp
source/VolumeIterator.cpp source/VolumeIterator.cpp
source/VolumeManager.cpp
source/VolumeResource.cpp
source/VolumeSerializer.cpp
) )
#Projects headers files #Projects headers files
@ -34,9 +31,6 @@ SET(INC_FILES
include/TypeDef.h include/TypeDef.h
include/Volume.h include/Volume.h
include/VolumeIterator.h include/VolumeIterator.h
include/VolumeManager.h
include/VolumeResource.h
include/VolumeSerializer.h
) )
ADD_DEFINITIONS(-DVOXEL_SCENE_MANAGER_EXPORT) #Export symbols in the .dll ADD_DEFINITIONS(-DVOXEL_SCENE_MANAGER_EXPORT) #Export symbols in the .dll

View File

@ -31,7 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "Volume.h" #include "Volume.h"
#include "SurfaceVertex.h" #include "SurfaceVertex.h"
#include "RegionGeometry.h" #include "RegionGeometry.h"
#include "VolumeResource.h"
#include <set> #include <set>

View File

@ -1,30 +0,0 @@
#ifndef __VOLUMEMANAGER_H__
#define __VOLUMEMANAGER_H__
#include <OgreResourceManager.h>
#include "VolumeResource.h"
namespace Ogre
{
class VOXEL_SCENE_MANAGER_API VolumeManager : public Ogre::ResourceManager, public Ogre::Singleton<VolumeManager>
{
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

View File

@ -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 <OgreResourceManager.h>
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<VolumeResource>
{
public:
VolumeResourcePtr () : Ogre::SharedPtr<VolumeResource> () {}
explicit VolumeResourcePtr (VolumeResource *rep) : Ogre::SharedPtr<VolumeResource> (rep) {}
VolumeResourcePtr (const VolumeResourcePtr &r) : Ogre::SharedPtr<VolumeResource> (r) {}
VolumeResourcePtr (const Ogre::ResourcePtr &r) : Ogre::SharedPtr<VolumeResource> ()
{
// 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<VolumeResource*> (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<VolumeResource*> (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<VolumeResource*> (r.getPointer());
pUseCount = r.useCountPointer ();
if (pUseCount)
{
++ (*pUseCount);
}
return *this;
}
};
}
#endif

View File

@ -1,21 +0,0 @@
#ifndef __VOLUMESERIALIZER_H__
#define __VOLUMESERIALIZER_H__
#include <OgreSerializer.h>
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

View File

@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "IndexedSurfacePatch.h" #include "IndexedSurfacePatch.h"
#include "PolyVoxSceneManager.h" #include "PolyVoxSceneManager.h"
#include "VolumeIterator.h" #include "VolumeIterator.h"
#include "VolumeManager.h"
#include "OgreStringConverter.h" #include "OgreStringConverter.h"
#include "OgreLogManager.h" #include "OgreLogManager.h"

View File

@ -21,8 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "Volume.h" #include "Volume.h"
#include "VolumeIterator.h" #include "VolumeIterator.h"
#include "VolumeSerializer.h"
#include "OgreVector3.h" #include "OgreVector3.h"
#include "OgreLogManager.h" #include "OgreLogManager.h"
#include "OgreStringConverter.h" #include "OgreStringConverter.h"

View File

@ -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<VolumeManager>::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);
}
}

View File

@ -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 <iostream> //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;
}
}

View File

@ -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<void*>(&volumeWidth), sizeof(volumeWidth));
stream->read(reinterpret_cast<void*>(&volumeHeight), sizeof(volumeHeight));
stream->read(reinterpret_cast<void*>(&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<void*>(&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);
}
}