Moved VolumeResource, VolumeSerializer, and VolumeManager to main application.
This commit is contained in:
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user