Moving Torque system files to bin/ subdirectory (Windows)
by Ben Beshara · 04/09/2015 (8:54 am) · 1 comments
So I added Awesomeium (It's amazing, thank you Mr. Lundmark) to my Torque project and was a little annoyed that I now had a very messy looking file structure in the root directory of my game. If you look at the file structure of, say, Dark Athena, Left 4 Dead 2 or almost any Unity or Unreal Engine game you will see the root directory usually only contains a handful of files, or even just the executable, with the rest loaded from a subdirectory. I've done my best (I've been in web-code land for a while please forgive the lack of polish) to emulate this in Torque, with the debug build loading DLL's from the bin/debug subdirectory. I've also renamed the log file and main.cs to match the TORQUE_APP_NAME definition.
This is totally a vanity thing but I feel that it makes the game seem more polished.
Step 1, include <string> at the top of mainLoop.cpp (because I'm a sucker for lazy coding). You can probably rewrite this to not use the std::string class fairly easily but as far as I know there's not real downside to using it--I'm assuming the reason C-style pointers are used is either because the code is from a legacy codebase (IDK when std::string was not a thing?) or it is somehow more memory efficient? Any light that can be shed on this would be very educational to me.
Secondly, In StandardMainLooop::HandleCommandLine, I've replaced the main.cs loading script (line 414 to 557 in my build) with:
This was modified from Thoman Huehn's suggstion in the comments of this resource. It's the simplest solution I can think of for this, I know I've ham-fistedly massacred a chunk of code but for my purposes, it's what I needed.
Thirdly, include the string class in console.cpp and at about line 251-ish, replace the defLogFilename definition with:
Then lastly in main.cpp (no need to include the string class here, it already is) add the following on in getDllName() after the line 'dllName = std::wstring(filenameBuf);':
Now you can simply set your DLL(s) to build into the game/bin/ directory and move your main.cs (renamed to your project name!) there as well.
This is really hacky and I have no idea what effect it will have on multi-platform builds so I offer no confidence in either it or my coding ability.
Enjoy! ^_^
This is totally a vanity thing but I feel that it makes the game seem more polished.
Step 1, include <string> at the top of mainLoop.cpp (because I'm a sucker for lazy coding). You can probably rewrite this to not use the std::string class fairly easily but as far as I know there's not real downside to using it--I'm assuming the reason C-style pointers are used is either because the code is from a legacy codebase (IDK when std::string was not a thing?) or it is somehow more memory efficient? Any light that can be shed on this would be very educational to me.
Secondly, In StandardMainLooop::HandleCommandLine, I've replaced the main.cs loading script (line 414 to 557 in my build) with:
std::string initScript;
size_t scriptNameSize = strlen(TORQUE_APP_NAME) + 17;
char *script = new char[scriptNameSize];
script[scriptNameSize] = 0;
initScript = "exec("bin/";
initScript += TORQUE_APP_NAME;
initScript += ".cs");";
dStrcpy(script, initScript.c_str());
Con::evaluatef(script);
delete[] script;This was modified from Thoman Huehn's suggstion in the comments of this resource. It's the simplest solution I can think of for this, I know I've ham-fistedly massacred a chunk of code but for my purposes, it's what I needed.
Thirdly, include the string class in console.cpp and at about line 251-ish, replace the defLogFilename definition with:
std::string logDir = "bin/"; std::string logName = TORQUE_APP_NAME; std::string logExtension = ".log"; std::string cppLogName = logDir + logName + logExtension; static const char *defLogFileName = cppLogName.c_str();
Then lastly in main.cpp (no need to include the string class here, it already is) add the following on in getDllName() after the line 'dllName = std::wstring(filenameBuf);':
// Load our DLL from a subdirectory std::wstring binDir = std::wstring(); // Are we debug? If so, put them in the Debug subdirectory #ifdef TORQUE_DEBUG binDir = L"binDebug"; #else binDir = L"bin"; #endif size_t lastDSPos = dllName.find_last_of(L""); dllName.insert(lastDSPos, binDir); std::wstring dllDir = dllName; size_t dllDirDSPos = dllDir.find_last_of(L""); dllDir.resize(dllDirDSPos); // Make this our DLL Directory SetDllDirectory(dllDir.c_str());
Now you can simply set your DLL(s) to build into the game/bin/ directory and move your main.cs (renamed to your project name!) there as well.
This is really hacky and I have no idea what effect it will have on multi-platform builds so I offer no confidence in either it or my coding ability.
Enjoy! ^_^
About the author
I've been a Torque user since 2004 and as a previous user have worked with 1.3, 1.4, the TLK and TGEA ('TAT' lmao). I've come back under a fresh account to distance myself from my youthful history.

adamcharles
https://essaypaperreviews.com/