[MERGED] patch to set temporary directory

tdev

16-12-2008 16:43:52

since vista tries to make the application folder read-only you should write all your data into the users folder. This patch add a method to specify the path where the impostor images should be written to.

patch:

Index: include/ImpostorPage.h
===================================================================
--- include/ImpostorPage.h (revision 1634)
+++ include/ImpostorPage.h (working copy)
@@ -311,6 +311,7 @@
Ogre::SceneManager *sceneMgr;
Ogre::Entity *entity;
Ogre::String entityKey;
+ ImpostorPage *group;

Ogre::MaterialPtr material[IMPOSTOR_PITCH_ANGLES][IMPOSTOR_YAW_ANGLES];
Ogre::TexturePtr texture;
Index: include/PagedGeometry.h
===================================================================
--- include/PagedGeometry.h (revision 1634)
+++ include/PagedGeometry.h (working copy)
@@ -179,6 +179,8 @@
*/
void setCamera(Ogre::Camera *cam);

+ void setTempDir(Ogre::String dir);
+
/**
\brief Gets the camera which is used to calculate levels of detail.
\returns The camera assigned to this PagedGeometry object.
@@ -613,6 +615,8 @@
/** INTERNAL FUNCTION - DO NOT USE */
Ogre::Vector3 _convertToLocal(const Ogre::Vector3 &globalVec);

+ Ogre::String getTempdir() { return this->tempdir; };
+
protected:
//Internal function - do not use
void _addDetailLevel(GeometryPageManager *mgr, Ogre::Real maxRange, Ogre::Real transitionLength);
@@ -645,6 +649,8 @@
//Time-related data
Ogre::Timer timer;
unsigned long lastTime;
+
+ Ogre::String tempdir;
};


Index: source/ImpostorPage.cpp
===================================================================
--- source/ImpostorPage.cpp (revision 1634)
+++ source/ImpostorPage.cpp (working copy)
@@ -321,6 +321,7 @@
{
//Store scene manager and entity
ImpostorTexture::sceneMgr = group->sceneMgr;
+ ImpostorTexture::group = group;
ImpostorTexture::entity = entity;

//Add self to list of ImpostorTexture's
@@ -529,7 +530,8 @@
for (i = 0; i < sizeof(key); ++i)
key[i] = (key[i] % 26) + 'A';

- ResourceGroupManager::getSingleton().addResourceLocation(".", "FileSystem", "BinFolder");
+ String tempdir = this->group->geom->getTempdir();
+ ResourceGroupManager::getSingleton().addResourceLocation(tempdir, "FileSystem", "BinFolder");
String fileName = "Impostor." + String(key, sizeof(key)) + '.' + StringConverter::toString(textureSize) + ".png";

//Attempt to load the pre-render file if allowed
@@ -569,7 +571,7 @@

#if IMPOSTOR_FILE_SAVE
//Save RTT to file
- renderTarget->writeContentsToFile(fileName);
+ renderTarget->writeContentsToFile(tempdir + fileName);

//Load the render into the appropriate texture view
texture = TextureManager::getSingleton().load(fileName, "BinFolder", TEX_TYPE_2D, MIP_UNLIMITED);
Index: source/PagedGeometry.cpp
===================================================================
--- source/PagedGeometry.cpp (revision 1634)
+++ source/PagedGeometry.cpp (working copy)
@@ -59,6 +59,8 @@

//Misc.
pageLoader = NULL;
+
+ this->tempdir = ".";
}

PagedGeometry::~PagedGeometry()
@@ -73,6 +75,11 @@
removeDetailLevels();
}

+void PagedGeometry::setTempDir(Ogre::String dir)
+{
+ this->tempdir = dir;
+}
+
void PagedGeometry::setPageLoader(PageLoader *loader)
{
pageLoader = loader;



usage:

PagedGeometry *p = new PagedGeometry();
// you should look up the MSDN how to get some system path
p->setTempDir(yourWindowsUserPath);

tdev

23-02-2009 10:42:47

i just tried to update to latest SVN HEAD version, and have not found a feature that would enable to set the temp directory? Have i overlooked it or was the functionality not integrated?

This is really needed, since we cannot save the impostor images in just any directory ...

luke

26-02-2009 13:00:49

And is it necessary to save render target to file? How about use http://www.ogre3d.org/docs/api/html/classOgre_1_1RenderTarget.html#6277cd30654d93dbfa7bb07275bbceb4 and create texture from pixelbox... ?

tdev

26-02-2009 13:33:08

And is it necessary to save render target to file? How about use http://www.ogre3d.org/docs/api/html/classOgre_1_1RenderTarget.html#6277cd30654d93dbfa7bb07275bbceb4 and create texture from pixelbox... ?
i think the point to save the texture to file is the speed on the second start. If you have a terrain with ~10 imposters it can take some time. So after the first start it will re-use the already present ones from the filesystem.

So in my opinion it really makes sense, just not in the application directory :(

tdev

29-06-2009 10:40:51

merged with svn