in app.h, define stringc variables for all of the needed directories
in my case, i use some defines to make it easier to read
Code: Select all
#define ADD_VARIABLE_SETGET(x,y) private : x m_##y; public : virtual void set##y(x value) { m_##y = value; } virtual x get##y() { return m_##y; }
// game resource directory structure
ADD_VARIABLE_SET2GET(stringc,WorkingDirectory);
ADD_VARIABLE_SETGET(stringc,GameDataDirectory);
ADD_VARIABLE_SETGET(stringc,GameSaveDirectory);
ADD_VARIABLE_SETGET(stringc,MediaDirectory);
ADD_VARIABLE_SETGET(stringc,ObjectsDirectory);
ADD_VARIABLE_SETGET(stringc,PrefabDirectory);
ADD_VARIABLE_SETGET(stringc,ActionTableDirectory);
Code: Select all
// setup the directory structure
int drive;
char path[_MAX_PATH];
drive = _getdrive();
if( _getdcwd( drive, path, _MAX_PATH ) != NULL ) setWorkingDirectory(path);
Code: Select all
// setup the directory paths
void CSApplication::setWorkingDirectory(stringc path)
{
path.replace("\\","/");
m_WorkingDirectory = path;
m_GameDataDirectory = path + stringc("/GameData/");
m_GameSaveDirectory = path + stringc("/SaveGames/");
m_MediaDirectory = path + stringc("/Media/");
m_ObjectsDirectory = path + stringc("/CSObjects/");
m_PrefabDirectory = path + stringc("/Prefabs/");
m_ActionTableDirectory = path + stringc("/ActionTables/");
// log all of the directories to the logger
CS_LOG("settting working directory structure");
CS_LOG2(" Working Directory - ",getWorkingDirectory());
CS_LOG2(" Game Data Directory - ",getGameDataDirectory());
CS_LOG2(" Save Data Directory - ",getGameSaveDirectory());
CS_LOG2(" Media Directory - ",getMediaDirectory());
CS_LOG2(" Objects Directory - ",getObjectsDirectory());
CS_LOG2(" Prefab Directory - ",getPrefabDirectory());
CS_LOG2(" Action Table Directory - ",getActionTableDirectory());
}
so what we have done is define the directory variables and created simple set/get functions for each.
then we created the setWorkingDirectory(path) function which adds the working directory to each sub directory
and stores that new string.
now we need to be able to use just the base filename (for saving the levels) OR
use the long filename to load the file
Code: Select all
#define CLIPTOMEDIAFILENAME(x) CLIPSTRING(x,getMediaDirectory())
#define MEDIAFILENAME(x) stringc(getMediaDirectory()+x)
#define CLIPTOACTIOTABLEFILENAME(x) CLIPSTRING(x,getActionTableDirectory())
#define ACTIONTABLEFILENAME(x) stringc(getActionTableDirectory()+x)
#define CLIPTOGAMEDATAFILENAME(x) CLIPSTRING(x,getGameDataDirectory())
#define GAMEDATAFILENAME(x) stringc(getGameDataDirectory()+x)
#define CLIPTOGAMESAVEFILENAME(x) CLIPSTRING(x,getGameSaveDirectory())
#define GAMESAVEFILENAME(x) stringc(getGameSaveDirectory()+x)
#define CLIPTOOBJECTSFILENAME(x) CLIPSTRING(x,getObjectsDirectory())
#define OBJECTSFILENAME(x) stringc(getObjectsDirectory()+x)
#define CLIPTOPREFABFILENAME(x) CLIPSTRING(x,getPreFabDirectory())
#define PREFABFILENAME(x) stringc(getPrefabDirectory()+x)
stringc CLIPSTRING(stringc s,stringc s2)
{
s.make_lower();
s2.make_lower();
stringc temp(s);
temp.remove(s2.c_str());
return temp;
}
now, anytime we want to load an actor file, we simply use it like this
Code: Select all
..
old way : IAnimatedMesh* mesh = getSmgr()->getMesh("media/mymodel.x");
..
new way : IAnimatedMesh* mesh = getSmgr()->getMesh(MEDIAFILENAME("mymodel.x"));