Game Development Reference
In-Depth Information
Its companion function does the opposite and converts a std::string back to a
std::wstring .
std::wstring s2ws(const std::string &s)
{
int slength = (int)s.length() + 1;
int len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0)-1;
std::wstring r(len,
);
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, &r[0], len);
return r;
'
\0
'
}
Now you can take a look at the OpenLevel() function, which converts the filename
sent by C# to something the EditorLogic class can load.
void OpenLevel( BSTR fullPathLevelFile )
{
std::string levelFile = ws2s(std::wstring(fullPathLevelFile,
SysStringLen(fullPathLevelFile)));
EditorLogic* pEditorLogic = (EditorLogic*)g_pApp->m_pGame;
if (pEditorLogic)
{
std::string assetsDir =
;
int projDirLength = pEditorLogic->GetProjectDirectory().length()
+ assetsDir.length();
g_pApp->m_Options.m_Level =
levelFile.substr(projDirLength, levelFile.length()-projDirLength);
pEditorLogic->VChangeState(BGS_LoadingGameEnvironment);
\\Assets\\
}
}
Note again the assumption of a specific directory structure. I
ve taken a cue from
other commercial editors that assume where all their game assets are stored, and in
truth, it makes sense to store them all under a commonly structured directory hier-
archy. Once the filename has been constructed from the input parameter, it is copied
into the game option
'
s current state is set to BGS_
LoadingGameEnvironment . This will start the loading process.
'
s object, and the editor logic
'
Actor Accessor Functions
There are five functions the editor uses to access actor data so that it can be pre-
sented in the editors user interface: The first two retrieve the number of actors in
the actor list and an array of their IDs.
 
Search WWH ::




Custom Search