Game Development Reference
In-Depth Information
Obviously, another thing that speeds up the compilation/conversion process is multithreading. 2 In a first
phase, you can schedule groups of files to be converted on separate threads. Then, when you convert a few files, the
converters could spawn several threads to take care of a single asset. You must be sure, however, that the available
cores are used/spread evenly, whether on a CPU or GPU.
Multithreading asset compilation can be a little tricky when dependencies are involved, so for this process to be
safe, and to avoid problems arising from two threads concurrently modifying the same resource, you should build a
dependency tree and put each main branch and its sub-branches and/or leaves on their own thread. Various methods
for thread synchronization can be used, like mutexes and semaphores, each operating system having its own API for
that. The main compiler class would look like Listing 1-3.
Listing 1-3. The Asset Compiler Class
class AssetCompiler
{
public:
AssetCompiler();
virtual ~AssetCompiler();
bool compile(const Args& rArgs);
void compileFolder(
AssetConverter::EType aConverterType,
const char* pMask,
const char* pExcludeMask,
const char* pCompileFolder,
const char* pDestFolder);
protected:
vector<AssetCompilerWorker> m_workerThreads;
.......................
};
The main asset compiler class has the compile(...) method (synchronous call; it will wait until every asset
compile thread finishes), which will take the actual command-line arguments. The compileFolder(...) method
(asynchronous call; it will just start the threads) will process a given folder for a specific converter type, with a
filename mask, an excluding mask, the actual compile folder, and destination folder for the output files. The class also
has some worker threads for multithreaded processing of the input assets.
Example
The code in Listing 1-4 shows an example—a texture converter/compiler plug-in.
Listing 1-4. The Texture Converter and Compiler
class TextureConverter : public AssetConverter
{
public:
TextureConverter();
~TextureConverter();
2 “Multithreading.” http://en.wikipedia.org/wiki/Multithreading_(computer_architecture ) .
 
Search WWH ::




Custom Search