Initial Implementation of the Taml, Asset and Modules systems.

Only has example and shape assets currently.
This commit is contained in:
Areloch 2015-10-13 15:19:36 -05:00
parent 2044b2691e
commit 7a3b40a86d
123 changed files with 30435 additions and 181 deletions

View file

@ -0,0 +1,86 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2013 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _FACTORY_CACHE_H_
#define _FACTORY_CACHE_H_
#ifndef _TVECTOR_H_
#include "core/util/tVector.h"
#endif
//-----------------------------------------------------------------------------
class IFactoryObjectReset
{
public:
virtual void resetState( void ) = 0;
};
//-----------------------------------------------------------------------------
template<class T>
class FactoryCache : private Vector<T*>
{
public:
FactoryCache()
{
}
virtual ~FactoryCache()
{
purgeCache();
}
T* createObject( void )
{
// Create a new object if cache is empty.
if ( this->size() == 0 )
return new T();
// Return a cached object.
T* pObject = this->back();
this->pop_back();
return pObject;
}
void cacheObject( T* pObject )
{
// Cache object.
this->push_back( pObject );
// Reset object state if available.
IFactoryObjectReset* pResetStateObject = dynamic_cast<IFactoryObjectReset*>( pObject );
if ( pResetStateObject != NULL )
pResetStateObject->resetState();
}
void purgeCache( void )
{
while( this->size() > 0 )
{
delete this->back();
this->pop_back();
}
}
};
#endif // _FACTORY_CACHE_H_

View file

@ -46,14 +46,14 @@ bool Module::_constrainedToComeBefore( Module* module, Mode mode )
Module* depModule = dependency->mModule;
if( !depModule )
{
depModule = ModuleManager::findModule( dependency->mModuleName );
depModule = EngineModuleManager::findModule( dependency->mModuleName );
if( !depModule )
{
// Module does not exist. Only emit a warning here so that modules
// can be omitted from a link without requiring the module definitions
// to be adapted.
Platform::outputDebugString( "[ModuleManager] Module %s of '%s' depends on module '%s' which does not exist",
Platform::outputDebugString( "[EngineModuleManager] Module %s of '%s' depends on module '%s' which does not exist",
mode == Module::ModeInitialize ? "init" : "shutdown",
module->getName(), dependency->mModuleName );
continue;
@ -86,14 +86,14 @@ bool Module::_constrainedToComeAfter( Module* module, Mode mode )
Module* depModule = dependency->mModule;
if( !depModule )
{
depModule = ModuleManager::findModule( dependency->mModuleName );
depModule = EngineModuleManager::findModule( dependency->mModuleName );
if( !depModule )
{
// Module does not exist. Only emit a warning here so that modules
// can be omitted from a link without requiring the module definitions
// to be adapted.
Platform::outputDebugString( "[ModuleManager] Module %s of '%s' depends on module '%s' which does not exist",
Platform::outputDebugString( "[EngineModuleManager] Module %s of '%s' depends on module '%s' which does not exist",
mode == Module::ModeInitialize ? "init" : "shutdown",
module->getName(), dependency->mModuleName );
continue;
@ -115,7 +115,7 @@ bool Module::_constrainedToComeAfter( Module* module, Mode mode )
//-----------------------------------------------------------------------------
String ModuleManager::_moduleListToString( Vector< Module* >& moduleList )
String EngineModuleManager::_moduleListToString( Vector< Module* >& moduleList )
{
StringBuilder str;
@ -136,14 +136,14 @@ String ModuleManager::_moduleListToString( Vector< Module* >& moduleList )
//-----------------------------------------------------------------------------
void ModuleManager::_printModuleList( Vector< Module* >& moduleList )
void EngineModuleManager::_printModuleList( Vector< Module* >& moduleList )
{
Platform::outputDebugString( _moduleListToString( moduleList ) );
}
//-----------------------------------------------------------------------------
void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >& moduleList, Module* module )
void EngineModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >& moduleList, Module* module )
{
// If this module is being overridden, switch over to
// the module overriding it.
@ -168,7 +168,7 @@ void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >&
if( !module->_getDependencies( mode ) )
{
#if defined( DEBUG_SPEW ) && DEBUG_SPEW_LEVEL > 1
Platform::outputDebugString( "[ModuleManager] Appending '%s' to '%s'",
Platform::outputDebugString( "[EngineModuleManager] Appending '%s' to '%s'",
module->getName(), _moduleListToString( moduleList ).c_str() );
#endif
@ -179,7 +179,7 @@ void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >&
// First make sure that all 'after' dependencies are in the list.
#if defined( DEBUG_SPEW ) && DEBUG_SPEW_LEVEL > 1
Platform::outputDebugString( "[ModuleManager] Resolving %s dependencies of '%s'",
Platform::outputDebugString( "[EngineModuleManager] Resolving %s dependencies of '%s'",
mode == Module::ModeInitialize ? "init" : "shutdown",
module->getName() );
#endif
@ -199,7 +199,7 @@ void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >&
}
AssertFatal( _getIndexOfModuleInList( moduleList, module ) == -1,
avar( "ModuleManager::_insertModuleIntoList - Cycle in 'after' %s dependency chain of '%s'",
avar( "EngineModuleManager::_insertModuleIntoList - Cycle in 'after' %s dependency chain of '%s'",
mode == Module::ModeInitialize ? "init" : "shutdown",
module->getName() ) );
@ -212,7 +212,7 @@ void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >&
const bool currentAfterThis = moduleList[ i ]->_constrainedToComeAfter( module, mode );
AssertFatal( !( thisBeforeCurrent && currentAfterThis ),
avar( "ModuleManager::_insertModuleIntoList - Ambiguous %s placement of module '%s' relative to '%s'",
avar( "EngineModuleManager::_insertModuleIntoList - Ambiguous %s placement of module '%s' relative to '%s'",
mode == Module::ModeInitialize ? "init" : "shutdown",
module->getName(), moduleList[ i ]->getName() ) );
@ -232,7 +232,7 @@ void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >&
if( thisBeforeCurrent && !moduleList[ i ]->_getDependencies( mode ) && i != numModules - 1 )
{
#if defined( DEBUG_SPEW ) && DEBUG_SPEW_LEVEL > 1
Platform::outputDebugString( "[ModuleManager] Pushing '%s' to back end of chain for resolving '%s'",
Platform::outputDebugString( "[EngineModuleManager] Pushing '%s' to back end of chain for resolving '%s'",
moduleList[ i ]->getName(), module->getName() );
#endif
@ -251,7 +251,7 @@ void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >&
for( U32 n = i + 1; n < numModules; ++ n )
AssertFatal( !( moduleList[ n ]->_constrainedToComeBefore( module, mode )
|| module->_constrainedToComeAfter( moduleList[ n ], mode ) ),
avar( "ModuleManager::_insertModuleIntoList - Ambiguous %s constraint on module '%s' to come before '%s' yet after '%s'",
avar( "EngineModuleManager::_insertModuleIntoList - Ambiguous %s constraint on module '%s' to come before '%s' yet after '%s'",
mode == Module::ModeInitialize ? "init" : "shutdown",
module->getName(),
moduleList[ i ]->getName(),
@ -260,7 +260,7 @@ void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >&
// Add the module at this position.
#if defined( DEBUG_SPEW ) && DEBUG_SPEW_LEVEL > 1
Platform::outputDebugString( "[ModuleManager] Inserting '%s' at index %i into '%s'",
Platform::outputDebugString( "[EngineModuleManager] Inserting '%s' at index %i into '%s'",
module->getName(), i, _moduleListToString( moduleList ).c_str() );
#endif
@ -271,7 +271,7 @@ void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >&
// No constraint-based position. Just append.
#if defined( DEBUG_SPEW ) && DEBUG_SPEW_LEVEL > 1
Platform::outputDebugString( "[ModuleManager] Appending '%s' to '%s'",
Platform::outputDebugString( "[EngineModuleManager] Appending '%s' to '%s'",
module->getName(), _moduleListToString( moduleList ).c_str() );
#endif
@ -280,7 +280,7 @@ void ModuleManager::_insertIntoModuleList( Module::Mode mode, Vector< Module* >&
//-----------------------------------------------------------------------------
Module* ModuleManager::_findOverrideFor( Module* module )
Module* EngineModuleManager::_findOverrideFor( Module* module )
{
const char* name = module->getName();
@ -294,7 +294,7 @@ Module* ModuleManager::_findOverrideFor( Module* module )
//-----------------------------------------------------------------------------
S32 ModuleManager::_getIndexOfModuleInList( Vector< Module* >& moduleList, Module* module )
S32 EngineModuleManager::_getIndexOfModuleInList( Vector< Module* >& moduleList, Module* module )
{
const U32 numModules = moduleList.size();
for( U32 i = 0; i < numModules; ++ i )
@ -306,7 +306,7 @@ S32 ModuleManager::_getIndexOfModuleInList( Vector< Module* >& moduleList, Modul
//-----------------------------------------------------------------------------
S32 ModuleManager::_getIndexOfModuleInList( Vector< Module* >& moduleList, const char* moduleName )
S32 EngineModuleManager::_getIndexOfModuleInList( Vector< Module* >& moduleList, const char* moduleName )
{
const U32 numModules = moduleList.size();
for( U32 i = 0; i < numModules; ++ i )
@ -318,7 +318,7 @@ S32 ModuleManager::_getIndexOfModuleInList( Vector< Module* >& moduleList, const
//-----------------------------------------------------------------------------
void ModuleManager::_createModuleList( Module::Mode mode, Vector< Module* >& moduleList )
void EngineModuleManager::_createModuleList( Module::Mode mode, Vector< Module* >& moduleList )
{
for( Module* module = Module::smFirst; module != NULL; module = module->mNext )
_insertIntoModuleList( mode, moduleList, module );
@ -326,7 +326,7 @@ void ModuleManager::_createModuleList( Module::Mode mode, Vector< Module* >& mod
//-----------------------------------------------------------------------------
void ModuleManager::initializeSystem()
void EngineModuleManager::initializeSystem()
{
Vector< Module* > modules;
@ -339,7 +339,7 @@ void ModuleManager::initializeSystem()
if( !module->mIsInitialized )
{
#ifdef DEBUG_SPEW
Platform::outputDebugString( "[ModuleManager] Initializing %s",
Platform::outputDebugString( "[EngineModuleManager] Initializing %s",
module->getName() );
#endif
@ -351,7 +351,7 @@ void ModuleManager::initializeSystem()
//-----------------------------------------------------------------------------
void ModuleManager::shutdownSystem()
void EngineModuleManager::shutdownSystem()
{
Vector< Module* > modules;
@ -363,7 +363,7 @@ void ModuleManager::shutdownSystem()
if( modules[ i ]->mIsInitialized )
{
#ifdef DEBUG_SPEW
Platform::outputDebugString( "[ModuleManager] Shutting down %s",
Platform::outputDebugString( "[EngineModuleManager] Shutting down %s",
modules[ i ]->getName() );
#endif
@ -375,7 +375,7 @@ void ModuleManager::shutdownSystem()
//-----------------------------------------------------------------------------
Module* ModuleManager::findModule( const char* name )
Module* EngineModuleManager::findModule( const char* name )
{
for( Module* module = Module::smFirst; module != NULL; module = module->mNext )
if( dStricmp( module->getName(), name ) == 0 )

View file

@ -42,7 +42,7 @@ class Module
public:
typedef void Parent;
friend struct ModuleManager;
friend struct EngineModuleManager;
protected:
@ -333,7 +333,7 @@ class Module
void _AfterModuleInit::initialize()
struct ModuleManager
struct EngineModuleManager
{
/// Initialize all modules registered with the system.
static void initializeSystem();

View file

@ -123,6 +123,19 @@ void Stream::writeString(const char *string, S32 maxLen)
write(len, string);
}
bool Stream::writeFormattedBuffer(const char *format, ...)
{
char buffer[4096];
va_list args;
va_start(args, format);
const S32 length = vsprintf(buffer, format, args);
// Sanity!
AssertFatal(length <= sizeof(buffer), "writeFormattedBuffer - String format exceeded buffer size. This will cause corruption.");
return write(length, buffer);
}
void Stream::readString(char buf[256])
{
U8 len;

View file

@ -29,7 +29,9 @@
#ifndef _ENDIAN_H_
#include "core/util/endian.h"
#endif
#ifndef _STRINGFUNCTIONS_H_
#include "core/strings/stringFunctions.h"
#endif
/// @defgroup stream_overload Primitive Type Stream Operation Overloads
/// These macros declare the read and write functions for all primitive types.
@ -130,12 +132,21 @@ public:
/// writeString is safer.
void writeLongString(U32 maxStringLen, const char *string);
inline bool Put(char character) { return write(character); }
/// Write raw text to the stream
void writeText(const char *text);
/// Writes a string to the stream.
virtual void writeString(const char *stringBuf, S32 maxLen=255);
/// Writes a formatted buffer to the stream.
/// NOTE: A maximum string length of 4K is allowed.
bool writeFormattedBuffer(const char *format, ...);
/// Writes a NULL terminated string buffer.
bool writeStringBuffer(const char* buffer) { return write(dStrlen(buffer), buffer); }
// read/write real strings
void write(const String & str) { _write(str); }
void read(String * str) { _read(str); }

View file

@ -863,5 +863,167 @@ inline Value& Map<Key,Value,Sequence>::operator[](const Key& key)
return mMap.findOrInsert(key)->value;
}
//-----------------------------------------------------------------------------
// iterator class
/// A HashMap template class.
/// The map class maps between a key and an associated value. Keys
/// are unique.
/// The hash table class is used as the default implementation so the
/// the key must be hashable, see util/hash.h for details.
/// @ingroup UtilContainers
template<typename Key, typename Value, class Sequence = HashTable<Key, Value> >
class HashMap : private Sequence
{
typedef HashTable<Key, Value> Parent;
private:
Sequence mHashMap;
public:
// types
typedef typename Parent::Pair Pair;
typedef Pair ValueType;
typedef Pair& Reference;
typedef const Pair& ConstReference;
typedef typename Parent::Iterator iterator;
typedef typename Parent::ConstIterator const_iterator;
typedef S32 DifferenceType;
typedef U32 SizeType;
// initialization
HashMap() {}
~HashMap() {}
HashMap(const HashMap& p);
// management
U32 size() const; ///< Return the number of elements
void clear(); ///< Empty the HashMap
bool isEmpty() const; ///< Returns true if the map is empty
// insert & erase elements
iterator insert(const Key& key, const Value&); // Documented below...
void erase(iterator); ///< Erase the given entry
void erase(const Key& key); ///< Erase the key from the map
// HashMap lookup
iterator find(const Key&); ///< Find entry for the given key
const_iterator find(const Key&) const; ///< Find entry for the given key
bool contains(const Key&a)
{
return mHashMap.count(a) > 0;
}
// forward iterator access
iterator begin(); ///< iterator to first element
const_iterator begin() const; ///< iterator to first element
iterator end(); ///< IIterator to last element + 1
const_iterator end() const; ///< iterator to last element + 1
// operators
Value& operator[](const Key&); ///< Index using the given key. If the key is not currently in the map it is added.
};
template<typename Key, typename Value, class Sequence> HashMap<Key, Value, Sequence>::HashMap(const HashMap& p)
{
*this = p;
}
//-----------------------------------------------------------------------------
// management
template<typename Key, typename Value, class Sequence>
inline U32 HashMap<Key, Value, Sequence>::size() const
{
return mHashMap.size();
}
template<typename Key, typename Value, class Sequence>
inline void HashMap<Key, Value, Sequence>::clear()
{
mHashMap.clear();
}
template<typename Key, typename Value, class Sequence>
inline bool HashMap<Key, Value, Sequence>::isEmpty() const
{
return mHashMap.isEmpty();
}
//-----------------------------------------------------------------------------
// add & remove elements
/// Insert the key value pair but don't allow duplicates.
/// The map class does not allow duplicates keys. If the key already exists in
/// the map the function will fail and return end().
template<typename Key, typename Value, class Sequence>
typename HashMap<Key, Value, Sequence>::iterator HashMap<Key, Value, Sequence>::insert(const Key& key, const Value& x)
{
return mHashMap.insertUnique(key, x);
}
template<typename Key, typename Value, class Sequence>
void HashMap<Key, Value, Sequence>::erase(const Key& key)
{
mHashMap.erase(key);
}
template<typename Key, typename Value, class Sequence>
void HashMap<Key, Value, Sequence>::erase(iterator node)
{
mHashMap.erase(node);
}
//-----------------------------------------------------------------------------
// Searching
template<typename Key, typename Value, class Sequence>
typename HashMap<Key, Value, Sequence>::iterator HashMap<Key, Value, Sequence>::find(const Key& key)
{
return mHashMap.find(key);
}
//-----------------------------------------------------------------------------
// iterator access
template<typename Key, typename Value, class Sequence>
inline typename HashMap<Key, Value, Sequence>::iterator HashMap<Key, Value, Sequence>::begin()
{
return mHashMap.begin();
}
template<typename Key, typename Value, class Sequence>
inline typename HashMap<Key, Value, Sequence>::const_iterator HashMap<Key, Value, Sequence>::begin() const
{
return mHashMap.begin();
}
template<typename Key, typename Value, class Sequence>
inline typename HashMap<Key, Value, Sequence>::iterator HashMap<Key, Value, Sequence>::end()
{
return mHashMap.end();
}
template<typename Key, typename Value, class Sequence>
inline typename HashMap<Key, Value, Sequence>::const_iterator HashMap<Key, Value, Sequence>::end() const
{
return mHashMap.end();
}
//-----------------------------------------------------------------------------
// operators
template<typename Key, typename Value, class Sequence>
inline Value& HashMap<Key, Value, Sequence>::operator[](const Key& key)
{
return mHashMap.findOrInsert(key)->value;
}
#endif