mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-21 15:43:45 +00:00
Initial Implementation of the Taml, Asset and Modules systems.
Only has example and shape assets currently.
This commit is contained in:
parent
2044b2691e
commit
7a3b40a86d
123 changed files with 30435 additions and 181 deletions
52
Engine/source/module/moduleCallbacks.h
Normal file
52
Engine/source/module/moduleCallbacks.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _MODULE_CALLBACKS_H_
|
||||
#define _MODULE_CALLBACKS_H_
|
||||
|
||||
#ifndef _MODULE_DEFINITION_H
|
||||
#include "moduleDefinition.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// @ingroup moduleGroup
|
||||
/// @see moduleGroup
|
||||
class ModuleCallbacks
|
||||
{
|
||||
friend class ModuleManager;
|
||||
|
||||
private:
|
||||
// Called when a module is about to be loaded.
|
||||
virtual void onModulePreLoad( ModuleDefinition* pModuleDefinition ) {}
|
||||
|
||||
// Called when a module has been loaded.
|
||||
virtual void onModulePostLoad( ModuleDefinition* pModuleDefinition ) {}
|
||||
|
||||
// Called when a module is about to be unloaded.
|
||||
virtual void onModulePreUnload( ModuleDefinition* pModuleDefinition ) {}
|
||||
|
||||
// Called when a module has been unloaded.
|
||||
virtual void onModulePostUnload( ModuleDefinition* pModuleDefinition ) {}
|
||||
};
|
||||
|
||||
#endif // _MODULE_CALLBACKS_H_
|
||||
209
Engine/source/module/moduleDefinition.cpp
Normal file
209
Engine/source/module/moduleDefinition.cpp
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "moduleDefinition.h"
|
||||
|
||||
#ifndef _MODULE_MANAGER_H
|
||||
#include "moduleManager.h"
|
||||
#endif
|
||||
|
||||
// Script bindings.
|
||||
#include "moduleDefinition_ScriptBinding.h"
|
||||
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TAML_H_
|
||||
#include "persistence/taml/taml.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT( ModuleDefinition );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ModuleDefinition::ModuleDefinition() :
|
||||
mModuleId(StringTable->EmptyString()),
|
||||
mVersionId( 0 ),
|
||||
mBuildId( 0 ),
|
||||
mEnabled( true ),
|
||||
mSynchronized( false ),
|
||||
mDeprecated( false ),
|
||||
mCriticalMerge( false ),
|
||||
mModuleDescription( StringTable->EmptyString() ),
|
||||
mAuthor(StringTable->EmptyString()),
|
||||
mModuleGroup(StringTable->EmptyString()),
|
||||
mModuleType(StringTable->EmptyString()),
|
||||
mScriptFile(StringTable->EmptyString()),
|
||||
mCreateFunction(StringTable->EmptyString()),
|
||||
mDestroyFunction(StringTable->EmptyString()),
|
||||
mAssetTagsManifest(StringTable->EmptyString()),
|
||||
mModulePath(StringTable->EmptyString()),
|
||||
mModuleFile(StringTable->EmptyString()),
|
||||
mModuleFilePath(StringTable->EmptyString()),
|
||||
mModuleScriptFilePath(StringTable->EmptyString()),
|
||||
mSignature(StringTable->EmptyString()),
|
||||
mLoadCount( 0 ),
|
||||
mLocked( false ),
|
||||
mScopeSet( 0 ),
|
||||
mpModuleManager( NULL )
|
||||
{
|
||||
// Set Vector Associations.
|
||||
VECTOR_SET_ASSOCIATION( mDependencies );
|
||||
VECTOR_SET_ASSOCIATION( mModuleAssets );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ModuleDefinition::initPersistFields()
|
||||
{
|
||||
// Call parent.
|
||||
Parent::initPersistFields();
|
||||
|
||||
addProtectedField("ModuleId", TypeString, Offset(mModuleId, ModuleDefinition), &defaultProtectedSetFn, &defaultProtectedGetFn, "");
|
||||
|
||||
/// Module configuration.
|
||||
addProtectedField( "ModuleId", TypeString, Offset(mModuleId, ModuleDefinition), &setModuleId, &defaultProtectedGetFn, "A unique string Id for the module. It can contain any characters except a comma or semi-colon (the asset scope character)." );
|
||||
addProtectedField( "VersionId", TypeS32, Offset(mVersionId, ModuleDefinition), &setVersionId, &defaultProtectedGetFn, "The version Id. Breaking changes to a module should use a higher version Id." );
|
||||
addProtectedField( "BuildId", TypeS32, Offset(mBuildId, ModuleDefinition), &setBuildId, &defaultProtectedGetFn, &writeBuildId, "The build Id. Non-breaking changes to a module should use a higher build Id. Optional: If not specified then the build Id will be zero." );
|
||||
addProtectedField( "Enabled", TypeBool, Offset(mEnabled, ModuleDefinition), &setEnabled, &defaultProtectedGetFn, &writeEnabled, "Whether the module is enabled or not. When disabled, it is effectively ignored. Optional: If not specified then the module is enabled." );
|
||||
addProtectedField( "Synchronized", TypeBool, Offset(mSynchronized, ModuleDefinition), &setSynchronized, &defaultProtectedGetFn, &writeSynchronized, "Whether the module should be synchronized or not. Optional: If not specified then the module is not synchronized." );
|
||||
addProtectedField( "Deprecated", TypeBool, Offset(mDeprecated, ModuleDefinition), &setDeprecated, &defaultProtectedGetFn, &writeDeprecated, "Whether the module is deprecated or not. Optional: If not specified then the module is not deprecated." );
|
||||
addProtectedField( "CriticalMerge", TypeBool, Offset(mCriticalMerge, ModuleDefinition), &setDeprecated, &defaultProtectedGetFn, &writeCriticalMerge, "Whether the merging of a module prior to a restart is critical or not. Optional: If not specified then the module is not merge critical." );
|
||||
addProtectedField( "Description", TypeString, Offset(mModuleDescription, ModuleDefinition), &setModuleDescription, &defaultProtectedGetFn, &writeModuleDescription, "The description typically used for debugging purposes but can be used for anything." );
|
||||
addProtectedField( "Author", TypeString, Offset(mAuthor, ModuleDefinition), &setAuthor, &defaultProtectedGetFn, &writeAuthor, "The author of the module." );
|
||||
addProtectedField( "Group", TypeString, Offset(mModuleGroup, ModuleDefinition), &setModuleGroup, &defaultProtectedGetFn, "The module group used typically when loading modules as a group." );
|
||||
addProtectedField( "Type", TypeString, Offset(mModuleType, ModuleDefinition), &setModuleType, &defaultProtectedGetFn, &writeModuleType, "The module type typically used to distinguish modules during module enumeration. Optional: If not specified then the type is empty although this can still be used as a pseudo 'global' type for instance." );
|
||||
addProtectedField( "Dependencies", TypeString, Offset(mDependencies, ModuleDefinition), &setDependencies, &getDependencies, &writeDependencies, "A comma-separated list of module Ids/VersionIds (<ModuleId>=<VersionId>,<ModuleId>=<VersionId>,etc) which this module depends upon. Optional: If not specified then no dependencies are assumed." );
|
||||
addProtectedField( "ScriptFile", TypeString, Offset(mScriptFile, ModuleDefinition), &setScriptFile, &defaultProtectedGetFn, &writeScriptFile, "The name of the script file to compile when loading the module. Optional." );
|
||||
addProtectedField( "CreateFunction", TypeString, Offset(mCreateFunction, ModuleDefinition), &setCreateFunction, &defaultProtectedGetFn, &writeCreateFunction, "The name of the function used to create the module. Optional: If not specified then no create function is called." );
|
||||
addProtectedField( "DestroyFunction", TypeString, Offset(mDestroyFunction, ModuleDefinition), &setDestroyFunction, &defaultProtectedGetFn, &writeDestroyFunction, "The name of the function used to destroy the module. Optional: If not specified then no destroy function is called." );
|
||||
addProtectedField( "AssetTagsManifest", TypeString, Offset(mAssetTagsManifest, ModuleDefinition), &setAssetTagsManifest, &defaultProtectedGetFn, &writeAssetTagsManifest, "The name of tags asset manifest file if this module contains asset tags. Optional: If not specified then no asset tags will be found for this module. Currently, only a single asset tag manifest should exist." );
|
||||
addProtectedField( "ScopeSet", TypeS32, Offset( mScopeSet, ModuleDefinition ), &defaultProtectedNotSetFn, &getScopeSet, &defaultProtectedNotWriteFn, "The scope set used to control the lifetime scope of objects that the module uses. Objects added to this set are destroyed automatically when the module is unloaded." );
|
||||
|
||||
/// Module location (Read-only).
|
||||
addProtectedField( "ModulePath", TypeString, Offset(mModulePath, ModuleDefinition), &defaultProtectedNotSetFn, &defaultProtectedGetFn, &defaultProtectedNotWriteFn, "The path of the module. This is read-only and is available only after the module has been registered by a module manager." );
|
||||
addProtectedField( "ModuleFile", TypeString, Offset(mModuleFile, ModuleDefinition), &defaultProtectedNotSetFn, &defaultProtectedGetFn, &defaultProtectedNotWriteFn, "The file of the module. This is read-only and is available only after the module has been registered by a module manager." );
|
||||
addProtectedField( "ModuleFilePath", TypeString, Offset(mModuleFilePath, ModuleDefinition), &defaultProtectedNotSetFn, &defaultProtectedGetFn, &defaultProtectedNotWriteFn, "The file-path of the module definition. This is read-only and is available only after the module has been registered by a module manager." );
|
||||
addProtectedField( "ModuleScriptFilePath", TypeString, Offset(mModuleScriptFilePath, ModuleDefinition), &defaultProtectedNotSetFn, &defaultProtectedGetFn, &defaultProtectedNotWriteFn, "The file-path of the script-file referenced in the module definition. This is read-only and is available only after the module has been registered by a module manager." );
|
||||
|
||||
/// Misc.
|
||||
addProtectedField( "Signature", TypeString, 0, &defaultProtectedNotSetFn, &getSignature, &defaultProtectedNotWriteFn, "A unique signature of the module definition based upon its Id, version and build. This is read-only and is available only after the module has been registered by a module manager." );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool ModuleDefinition::getDependency( const U32 dependencyIndex, ModuleDependency& dependency ) const
|
||||
{
|
||||
// Is dependency index out of bounds?
|
||||
if ( dependencyIndex >= (U32)mDependencies.size() )
|
||||
{
|
||||
// Yes, so warn.
|
||||
Con::warnf("Could not get module dependency '%d' as it is out of range.", dependencyIndex);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fetch module dependency.
|
||||
dependency = mDependencies[dependencyIndex];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool ModuleDefinition::addDependency( const char* pModuleId, const U32 versionId )
|
||||
{
|
||||
// Fetch module Id.
|
||||
StringTableEntry moduleId = StringTable->insert( pModuleId );
|
||||
|
||||
// Do we have any existing dependencies?
|
||||
if ( mDependencies.size() > 0 )
|
||||
{
|
||||
// Yes, so is the module Id already a dependency?
|
||||
for( typeModuleDependencyVector::iterator dependencyItr = mDependencies.begin(); dependencyItr != mDependencies.end(); ++dependencyItr )
|
||||
{
|
||||
// Skip if not the same module Id.
|
||||
if ( dependencyItr->mModuleId != moduleId )
|
||||
continue;
|
||||
|
||||
// Dependency already exists so warn.
|
||||
Con::warnf("Could not add dependency of module Id '%s' at version Id '%d' as the module Id is already a dependency.", pModuleId, versionId );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Populate module dependency.
|
||||
ModuleDefinition::ModuleDependency dependency( moduleId, versionId );
|
||||
|
||||
// Store dependency.
|
||||
mDependencies.push_back( dependency );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool ModuleDefinition::removeDependency( const char* pModuleId )
|
||||
{
|
||||
// Fetch module Id.
|
||||
StringTableEntry moduleId = StringTable->insert( pModuleId );
|
||||
|
||||
// Do we have any existing dependencies?
|
||||
if ( mDependencies.size() > 0 )
|
||||
{
|
||||
// Yes, so is the module Id a dependency?
|
||||
for( typeModuleDependencyVector::iterator dependencyItr = mDependencies.begin(); dependencyItr != mDependencies.end(); ++dependencyItr )
|
||||
{
|
||||
// Skip if not the same module Id.
|
||||
if ( dependencyItr->mModuleId != moduleId )
|
||||
continue;
|
||||
|
||||
// Remove dependency.
|
||||
mDependencies.erase( dependencyItr );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// No, so warn.
|
||||
Con::warnf("Could not remove dependency of module Id '%s' as the module Id is not a dependency.", pModuleId );
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool ModuleDefinition::save( void )
|
||||
{
|
||||
// Does the module have a file-path yet?
|
||||
if (mModuleFilePath == StringTable->EmptyString())
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("Save() - Cannot save module definition '%s' as it does not have a file-path.", mModuleId );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save the module file.
|
||||
Taml taml;
|
||||
return taml.write( this, mModuleFilePath );
|
||||
}
|
||||
329
Engine/source/module/moduleDefinition.h
Normal file
329
Engine/source/module/moduleDefinition.h
Normal file
|
|
@ -0,0 +1,329 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _MODULE_DEFINITION_H
|
||||
#define _MODULE_DEFINITION_H
|
||||
|
||||
#ifndef _ASSET_DEFINITION_H_
|
||||
#include "assets/assetDefinition.h"
|
||||
#endif
|
||||
|
||||
#ifndef _SIMSET_H_
|
||||
#include "console/simSet.h"
|
||||
#endif
|
||||
|
||||
#ifndef _SIMBASE_H_
|
||||
#include "console/simBase.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TVECTOR_H_
|
||||
#include "core/util/tVector.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STRINGUNIT_H_
|
||||
#include "core/strings/stringUnit.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class ModuleManager;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// @ingroup moduleGroup
|
||||
/// @see moduleGroup
|
||||
class ModuleDefinition : public SimSet
|
||||
{
|
||||
friend class ModuleManager;
|
||||
|
||||
private:
|
||||
typedef SimSet Parent;
|
||||
|
||||
public:
|
||||
/// Module dependency.
|
||||
struct ModuleDependency
|
||||
{
|
||||
ModuleDependency() :
|
||||
mModuleId( StringTable->EmptyString() ),
|
||||
mVersionId( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
ModuleDependency( StringTableEntry moduleId, const U32 versionId ) :
|
||||
mModuleId( moduleId ),
|
||||
mVersionId( versionId )
|
||||
{
|
||||
}
|
||||
|
||||
StringTableEntry mModuleId;
|
||||
U32 mVersionId;
|
||||
};
|
||||
typedef Vector<ModuleDependency> typeModuleDependencyVector;
|
||||
typedef Vector<AssetDefinition*> typeModuleAssetsVector;
|
||||
|
||||
private:
|
||||
/// Module definition.
|
||||
StringTableEntry mModuleId;
|
||||
U32 mVersionId;
|
||||
U32 mBuildId;
|
||||
bool mEnabled;
|
||||
bool mSynchronized;
|
||||
bool mDeprecated;
|
||||
bool mCriticalMerge;
|
||||
StringTableEntry mModuleDescription;
|
||||
StringTableEntry mAuthor;;
|
||||
StringTableEntry mModuleGroup;
|
||||
StringTableEntry mModuleType;
|
||||
typeModuleDependencyVector mDependencies;
|
||||
StringTableEntry mScriptFile;
|
||||
StringTableEntry mCreateFunction;
|
||||
StringTableEntry mDestroyFunction;
|
||||
|
||||
/// Modules assets.
|
||||
StringTableEntry mAssetTagsManifest;
|
||||
typeModuleAssetsVector mModuleAssets;
|
||||
|
||||
/// Module location.
|
||||
StringTableEntry mModulePath;
|
||||
StringTableEntry mModuleFile;
|
||||
StringTableEntry mModuleFilePath;
|
||||
StringTableEntry mModuleScriptFilePath;
|
||||
|
||||
/// Miscellaneous.
|
||||
StringTableEntry mSignature;
|
||||
S32 mLoadCount;
|
||||
SimObjectId mScopeSet;
|
||||
bool mLocked;
|
||||
ModuleManager* mpModuleManager;
|
||||
|
||||
private:
|
||||
inline bool checkUnlocked( void ) const { if ( mLocked ) { Con::warnf("Ignoring changes for locked module definition."); } return !mLocked; }
|
||||
inline void setModuleManager( ModuleManager* pModuleManager ) { mpModuleManager = pModuleManager; }
|
||||
|
||||
public:
|
||||
ModuleDefinition();
|
||||
virtual ~ModuleDefinition() {}
|
||||
|
||||
/// Engine.
|
||||
static void initPersistFields();
|
||||
|
||||
/// Module definition.
|
||||
inline void setModuleId( const char* pModuleId ) { if ( checkUnlocked() ) { mModuleId = StringTable->insert(pModuleId); } }
|
||||
inline StringTableEntry getModuleId( void ) const { return mModuleId; }
|
||||
inline void setVersionId( const U32 versionId ) { if ( checkUnlocked() ) { mVersionId = versionId; } }
|
||||
inline U32 getVersionId( void ) const { return mVersionId; }
|
||||
inline void setBuildId( const U32 buildId ) { if ( checkUnlocked() ) { mBuildId = buildId; } }
|
||||
inline U32 getBuildId( void ) const { return mBuildId; }
|
||||
inline void setEnabled( const bool enabled ) { if ( checkUnlocked() ) { mEnabled = enabled; } }
|
||||
inline bool getEnabled( void ) const { return mEnabled; }
|
||||
inline void setSynchronized( const bool synchronized ) { if ( checkUnlocked() ) { mSynchronized = synchronized; } }
|
||||
inline bool getSynchronized( void ) const { return mSynchronized; }
|
||||
inline void setDeprecated( const bool deprecated ) { if ( checkUnlocked() ) { mDeprecated = deprecated; } }
|
||||
inline bool getDeprecated( void ) const { return mDeprecated; }
|
||||
inline void setCriticalMerge( const bool mergeCritical ) { if ( checkUnlocked() ) { mCriticalMerge = mergeCritical; } }
|
||||
inline bool getCriticalMerge( void ) const { return mCriticalMerge; }
|
||||
inline void setModuleDescription( const char* pModuleDescription ) { if ( checkUnlocked() ) { mModuleDescription = StringTable->insert(pModuleDescription); } }
|
||||
inline StringTableEntry getModuleDescription( void ) const { return mModuleDescription; }
|
||||
inline void setAuthor( const char* pAuthor ) { if ( checkUnlocked() ) { mAuthor = StringTable->insert(pAuthor); } }
|
||||
inline StringTableEntry getAuthor( void ) const { return mAuthor; }
|
||||
inline void setModuleGroup( const char* pModuleGroup ) { if ( checkUnlocked() ) { mModuleGroup = StringTable->insert(pModuleGroup); } }
|
||||
inline StringTableEntry getModuleGroup( void ) const { return mModuleGroup; }
|
||||
inline void setModuleType( const char* pModuleType ) { if ( checkUnlocked() ) { mModuleType = StringTable->insert(pModuleType); } }
|
||||
inline StringTableEntry getModuleType( void ) const { return mModuleType; }
|
||||
inline void setDependencies( const typeModuleDependencyVector& dependencies ) { if ( checkUnlocked() ) { mDependencies.clear(); mDependencies.merge(dependencies); } }
|
||||
inline const typeModuleDependencyVector& getDependencies( void ) const { return mDependencies; }
|
||||
inline void setScriptFile( const char* pScriptFile ) { if ( checkUnlocked() ) { mScriptFile = StringTable->insert(pScriptFile); } }
|
||||
inline StringTableEntry getScriptFile( void ) const { return mScriptFile; }
|
||||
inline void setCreateFunction( const char* pCreateFunction ) { if ( checkUnlocked() ) { mCreateFunction = StringTable->insert(pCreateFunction); } }
|
||||
inline StringTableEntry getCreateFunction( void ) const { return mCreateFunction; }
|
||||
inline void setDestroyFunction( const char* pDestroyFunction ) { if ( checkUnlocked() ) { mDestroyFunction = StringTable->insert(pDestroyFunction); } }
|
||||
inline StringTableEntry getDestroyFunction( void ) const { return mDestroyFunction; }
|
||||
inline SimObjectId getScopeSet( void ) const { return mScopeSet; }
|
||||
|
||||
/// Module assets.
|
||||
inline void setAssetTagsManifest( const char* pTagsAssetManifest ) { if ( checkUnlocked() ) { mAssetTagsManifest = StringTable->insert(pTagsAssetManifest); } }
|
||||
inline StringTableEntry getAssetTagsManifest( void ) const { return mAssetTagsManifest; }
|
||||
inline typeModuleAssetsVector& getModuleAssets( void ) { return mModuleAssets; }
|
||||
|
||||
/// Module location.
|
||||
inline void setModulePath( const char* pModulePath ) { if ( checkUnlocked() ) { mModulePath = StringTable->insert(pModulePath); } }
|
||||
inline StringTableEntry getModulePath( void ) const { return mModulePath; }
|
||||
inline void setModuleFile( const char* pModuleDefinitionFile ) { if ( checkUnlocked() ) { mModuleFile = StringTable->insert(pModuleDefinitionFile); } }
|
||||
inline StringTableEntry getModuleFile( void ) const { return mModuleFile; }
|
||||
inline void setModuleFilePath( const char* pModuleDefinitionFilePath ) { if ( checkUnlocked() ) { mModuleFilePath = StringTable->insert(pModuleDefinitionFilePath); } }
|
||||
inline StringTableEntry getModuleFilePath( void ) const { return mModuleFilePath; }
|
||||
inline void setModuleScriptFilePath( const char* pModuleScriptFilePath ) { if ( checkUnlocked() ) { mModuleScriptFilePath = StringTable->insert(pModuleScriptFilePath); } }
|
||||
inline StringTableEntry getModuleScriptFilePath( void ) const { return mModuleScriptFilePath; }
|
||||
|
||||
/// Specialized dependency control.
|
||||
inline U32 getDependencyCount( void ) const { return mDependencies.size(); }
|
||||
bool getDependency( const U32 dependencyIndex, ModuleDependency& dependency ) const;
|
||||
bool addDependency( const char* pModuleId, const U32 versionId );
|
||||
bool removeDependency( const char* pModuleId );
|
||||
|
||||
/// Miscellaneous.
|
||||
inline void setSignature( const char* pSignature ) { if ( checkUnlocked() ) { mSignature = StringTable->insert(pSignature); } }
|
||||
inline StringTableEntry getSignature( void ) const { return mSignature; }
|
||||
inline void increaseLoadCount( void ) { ++mLoadCount; }
|
||||
inline void reduceLoadCount( void ) { --mLoadCount; }
|
||||
inline S32 getLoadCount( void ) const { return mLoadCount; }
|
||||
inline void setLocked( const bool status ) { mLocked = status; }
|
||||
inline bool getLocked( void ) const { return mLocked; }
|
||||
inline ModuleManager* getModuleManager( void ) const { return mpModuleManager; }
|
||||
bool save( void );
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT( ModuleDefinition );
|
||||
|
||||
protected:
|
||||
static bool setModuleId(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setModuleId( data ); return false; }
|
||||
static bool setVersionId(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setVersionId((U32)dAtoi(data)); return false; }
|
||||
static bool setBuildId(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setBuildId((U32)dAtoi(data)); return false; }
|
||||
static bool writeBuildId( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getBuildId() != 0; }
|
||||
static bool setEnabled(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setEnabled(dAtob(data)); return false; }
|
||||
static bool writeEnabled( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getEnabled() == false; }
|
||||
static bool setSynchronized(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setSynchronized(dAtob(data)); return false; }
|
||||
static bool writeSynchronized( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getSynchronized() == true; }
|
||||
static bool setDeprecated(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setDeprecated(dAtob(data)); return false; }
|
||||
static bool writeDeprecated( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getDeprecated() == true; }
|
||||
static bool writeCriticalMerge( void* obj, StringTableEntry pFieldName ){ return static_cast<ModuleDefinition*>(obj)->getCriticalMerge() == true; }
|
||||
static bool setModuleDescription(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setModuleDescription(data); return false; }
|
||||
static bool writeModuleDescription( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getModuleDescription() != StringTable->EmptyString(); }
|
||||
static bool setAuthor(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setAuthor(data); return false; }
|
||||
static bool writeAuthor(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getAuthor() != StringTable->EmptyString(); }
|
||||
static bool setModuleGroup(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setModuleGroup(data); return false; }
|
||||
static bool setModuleType(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setModuleType(data); return false; }
|
||||
static bool writeModuleType(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getModuleType() != StringTable->EmptyString(); }
|
||||
static bool setScriptFile(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setScriptFile(data); return false; }
|
||||
static bool writeScriptFile(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getScriptFile() != StringTable->EmptyString(); }
|
||||
static bool setCreateFunction(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setCreateFunction(data); return false; }
|
||||
static bool writeCreateFunction(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getCreateFunction() != StringTable->EmptyString(); }
|
||||
static bool setDestroyFunction(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setDestroyFunction(data); return false; }
|
||||
static bool writeDestroyFunction(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getDestroyFunction() != StringTable->EmptyString(); }
|
||||
|
||||
/// Asset manifest.
|
||||
static bool setAssetTagsManifest(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setAssetTagsManifest(data); return false; }
|
||||
static bool writeAssetTagsManifest(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getAssetTagsManifest() != StringTable->EmptyString(); }
|
||||
static const char* getScopeSet(void* obj, const char* data) { return Con::getIntArg(static_cast<ModuleDefinition*>(obj)->getScopeSet()); }
|
||||
|
||||
static bool setDependencies(void* obj, const char* index, const char* data)
|
||||
{
|
||||
// Fetch module dependencies.
|
||||
ModuleDefinition::typeModuleDependencyVector moduleDependencies;
|
||||
|
||||
// Fetch dependency value.
|
||||
const char* pDependencyValue = data;
|
||||
|
||||
char slotUnit[256];
|
||||
char slotName[256];
|
||||
char slotValue[256];
|
||||
|
||||
// Fetch definition word count.
|
||||
const U32 dependencyWordCount = StringUnit::getUnitCount( pDependencyValue, "," );
|
||||
|
||||
// Do we have any dependencies specified?
|
||||
if ( dependencyWordCount > 0 )
|
||||
{
|
||||
// Yes, so iterate dependencies.
|
||||
for ( U32 dependencyIndex = 0; dependencyIndex < dependencyWordCount; ++dependencyIndex )
|
||||
{
|
||||
// Fetch slot.
|
||||
dStrcpy( slotUnit, StringUnit::getUnit( pDependencyValue, dependencyIndex, "," ) );
|
||||
|
||||
// Fetch slot name and value.
|
||||
dStrcpy( slotName, StringUnit::getUnit( slotUnit, 0, "=" ) );
|
||||
dStrcpy( slotValue, StringUnit::getUnit( slotUnit, 1, "=" ) );
|
||||
|
||||
// Fetch module Id.
|
||||
StringTableEntry moduleId = StringTable->insert( slotName );
|
||||
|
||||
// Fetch version Id.
|
||||
const U32 versionId = slotValue[0] == '*' ? 0 : dAtoi(slotValue);
|
||||
|
||||
// Populate module dependency.
|
||||
ModuleDefinition::ModuleDependency dependency( moduleId, versionId );
|
||||
|
||||
// Store dependency.
|
||||
moduleDependencies.push_back( dependency );
|
||||
}
|
||||
}
|
||||
|
||||
// Set dependencies.
|
||||
static_cast<ModuleDefinition*>(obj)->setDependencies( moduleDependencies );
|
||||
|
||||
return false;
|
||||
}
|
||||
static const char* getDependencies(void* obj, const char* data)
|
||||
{
|
||||
// Fetch module dependencies.
|
||||
const ModuleDefinition::typeModuleDependencyVector& moduleDependencies = static_cast<ModuleDefinition*>(obj)->getDependencies();
|
||||
|
||||
// Finish if no dependencies.
|
||||
if ( moduleDependencies.size() == 0 )
|
||||
return StringTable->EmptyString();
|
||||
|
||||
// Get a return buffer.
|
||||
const S32 bufferSize = 1024;
|
||||
char* pReturnBuffer = Con::getReturnBuffer(bufferSize);
|
||||
pReturnBuffer[0] = '\0';
|
||||
|
||||
// Set buffer limits.
|
||||
char* pValueBuffer = pReturnBuffer;
|
||||
S32 bufferLeft = bufferSize;
|
||||
U32 used;
|
||||
|
||||
// Iterate module dependencies.
|
||||
for ( ModuleDefinition::typeModuleDependencyVector::const_iterator dependencyItr = moduleDependencies.begin(); dependencyItr < moduleDependencies.end(); ++dependencyItr )
|
||||
{
|
||||
// Fetch module dependency.
|
||||
const ModuleDefinition::ModuleDependency* pDependency = dependencyItr;
|
||||
|
||||
// Fetch version Id.
|
||||
const char* pVersionId = pDependency->mVersionId == 0 ? "*" : avar("%d", pDependency->mVersionId );
|
||||
|
||||
if ( dependencyItr == moduleDependencies.begin() )
|
||||
{
|
||||
// Write out a field/value pair
|
||||
used = dSprintf( pValueBuffer, bufferLeft, "%s=%s", pDependency->mModuleId, pVersionId );
|
||||
pValueBuffer += used;
|
||||
bufferLeft -= used;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write out a field/value pair
|
||||
used = dSprintf( pValueBuffer, bufferLeft, ",%s=%s", pDependency->mModuleId, pVersionId );
|
||||
pValueBuffer += used;
|
||||
bufferLeft -= used;
|
||||
}
|
||||
|
||||
// Sanity.
|
||||
AssertFatal( bufferLeft > 0, "Cannot format module dependencies as we ran out of buffer." );
|
||||
}
|
||||
|
||||
return pReturnBuffer;
|
||||
}
|
||||
static bool writeDependencies( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getDependencies().size() > 0; }
|
||||
static const char* getSignature(void* obj, const char* data) { return static_cast<ModuleDefinition*>(obj)->getSignature(); }
|
||||
};
|
||||
|
||||
#endif // _MODULE_DEFINITION_H
|
||||
|
||||
96
Engine/source/module/moduleDefinition_ScriptBinding.h
Normal file
96
Engine/source/module/moduleDefinition_ScriptBinding.h
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "console/engineAPI.h"
|
||||
#include "moduleDefinition.h"
|
||||
#include "moduleManager.h"
|
||||
|
||||
DefineEngineMethod(ModuleDefinition, save, bool, (),,
|
||||
"Saves the module definition to the file it was loaded from (if any).\n"
|
||||
"@return (bool success) Whether the module definition was saved or not.\n")
|
||||
{
|
||||
// Save.
|
||||
return object->save();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleDefinition, getModuleManager, S32, (),,
|
||||
"Gets the module manager which this module definition is registered with (if any).\n"
|
||||
"@return (moduleManager) The module manager which this module definition is registered with (zero if not registered).\n")
|
||||
{
|
||||
// Fetch module manager.
|
||||
ModuleManager* pModuleManager = object->getModuleManager();
|
||||
|
||||
return pModuleManager != NULL ? pModuleManager->getId() : 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleDefinition, getDependencyCount, S32, (), ,
|
||||
"Gets the number of module dependencies this module definition has.\n"
|
||||
"@return (int count) The number of module dependencies this module definition has.\n")
|
||||
{
|
||||
// Get module dependency count.
|
||||
return object->getDependencyCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleDefinition, getDependency, String, (U32 dependencyIndex), (0),
|
||||
"Gets the module dependency at the specified index.\n"
|
||||
"@param dependencyIndex The module dependency index.\n"
|
||||
"@return (module - dependency) The module dependency at the specified index.")
|
||||
{
|
||||
// Get module dependency.
|
||||
ModuleDefinition::ModuleDependency dependency;
|
||||
if ( object->getDependency( dependencyIndex, dependency ) == false )
|
||||
return StringTable->EmptyString();
|
||||
|
||||
// Format module dependency.
|
||||
char* pReturnBuffer = Con::getReturnBuffer( 256 );
|
||||
dSprintf( pReturnBuffer, 256, "%s %d", dependency.mModuleId, dependency.mVersionId );
|
||||
|
||||
return pReturnBuffer;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleDefinition, addDependency, bool, (const char* pModuleId, U32 versionId), ("", 0),
|
||||
"Adds the specified moduleId and vesionId as a dependency.\n"
|
||||
"@param moduleId The module Id to add as a dependency.\n"
|
||||
"@param versionId The version Id to add as a dependency. Using zero indicates any version."
|
||||
"@return (bool success) Whether the module dependency was added or not.")
|
||||
{
|
||||
// Add dependency.
|
||||
return object->addDependency( pModuleId, versionId );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleDefinition, removeDependency, bool, (const char* pModuleId), (""),
|
||||
"Removes the specified moduleId as a dependency.\n"
|
||||
"@param moduleId The module Id to remove as a dependency.\n"
|
||||
"@return (bool success) Whether the module dependency was removed or not.")
|
||||
{
|
||||
// Remove dependency.
|
||||
return object->removeDependency( pModuleId );
|
||||
}
|
||||
2513
Engine/source/module/moduleManager.cpp
Normal file
2513
Engine/source/module/moduleManager.cpp
Normal file
File diff suppressed because it is too large
Load diff
215
Engine/source/module/moduleManager.h
Normal file
215
Engine/source/module/moduleManager.h
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _MODULE_MANAGER_H
|
||||
#define _MODULE_MANAGER_H
|
||||
|
||||
#ifndef _SIMBASE_H_
|
||||
#include "console/simBase.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TVECTOR_H_
|
||||
#include "core/util/tvector.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TDICTIONARY_H_
|
||||
#include "core/util/tDictionary.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TAML_H_
|
||||
#include "persistence/taml/taml.h"
|
||||
#endif
|
||||
|
||||
#ifndef _MODULE_DEFINITION_H
|
||||
#include "moduleDefinition.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define MODULE_MANAGER_MERGE_FILE "module.merge"
|
||||
#define MODULE_MANAGER_MODULE_DEFINITION_EXTENSION "module.taml"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// @ingroup moduleGroup
|
||||
/// @see moduleGroup
|
||||
class ModuleManager : public SimObject
|
||||
{
|
||||
private:
|
||||
typedef SimObject Parent;
|
||||
|
||||
public:
|
||||
/// Module definitions.
|
||||
typedef Vector<ModuleDefinition*> typeModuleDefinitionVector;
|
||||
typedef Vector<const ModuleDefinition*> typeConstModuleDefinitionVector;
|
||||
|
||||
private:
|
||||
/// Database locking.
|
||||
struct LockDatabase
|
||||
{
|
||||
public:
|
||||
LockDatabase( ModuleManager* pManager ) :
|
||||
mpManager( pManager )
|
||||
{
|
||||
mpManager->mDatabaseLocks++;
|
||||
}
|
||||
|
||||
~LockDatabase()
|
||||
{
|
||||
mpManager->mDatabaseLocks--;
|
||||
|
||||
// Sanity!
|
||||
AssertFatal( mpManager->mDatabaseLocks >= 0, "Module Manager: Cannot unlock database as it is already unlocked." );
|
||||
}
|
||||
|
||||
private:
|
||||
ModuleManager* mpManager;
|
||||
};
|
||||
|
||||
/// Loaded module entry.
|
||||
struct ModuleLoadEntry
|
||||
{
|
||||
ModuleLoadEntry( ModuleDefinition* pModuleDefinition, const bool strictVersionId ) :
|
||||
mpModuleDefinition( pModuleDefinition ),
|
||||
mStrictVersionId( strictVersionId )
|
||||
{
|
||||
}
|
||||
|
||||
ModuleLoadEntry()
|
||||
{
|
||||
mpModuleDefinition = NULL;
|
||||
mStrictVersionId = false;
|
||||
}
|
||||
|
||||
ModuleDefinition* mpModuleDefinition;
|
||||
bool mStrictVersionId;
|
||||
};
|
||||
|
||||
/// Module loading.
|
||||
typedef Vector<StringTableEntry> typeModuleIdVector;
|
||||
typedef Vector<StringTableEntry> typeGroupVector;
|
||||
typedef HashMap<StringTableEntry, typeModuleIdVector*> typeGroupModuleHash;
|
||||
typedef Vector<ModuleLoadEntry> typeModuleLoadEntryVector;
|
||||
typeGroupModuleHash mGroupModules;
|
||||
typeGroupVector mGroupsLoaded;
|
||||
typeModuleLoadEntryVector mModulesLoaded;
|
||||
|
||||
/// Miscellaneous.
|
||||
bool mEnforceDependencies;
|
||||
bool mEchoInfo;
|
||||
S32 mDatabaseLocks;
|
||||
char mModuleExtension[256];
|
||||
Taml mTaml;
|
||||
SimSet mNotificationListeners;
|
||||
|
||||
// Module definition entry.
|
||||
struct ModuleDefinitionEntry : public typeModuleDefinitionVector
|
||||
{
|
||||
public:
|
||||
ModuleDefinitionEntry( StringTableEntry moduleId, StringTableEntry moduleGroup, StringTableEntry moduleType ) :
|
||||
mModuleId( moduleId ),
|
||||
mModuleGroup( moduleGroup ),
|
||||
mModuleType( moduleType )
|
||||
{
|
||||
}
|
||||
|
||||
const StringTableEntry mModuleId;
|
||||
const StringTableEntry mModuleGroup;
|
||||
const StringTableEntry mModuleType;
|
||||
};
|
||||
|
||||
/// Module databases.
|
||||
typedef HashMap<StringTableEntry, ModuleDefinitionEntry*> typeModuleIdDatabaseHash;
|
||||
typeModuleIdDatabaseHash mModuleIdDatabase;
|
||||
|
||||
public:
|
||||
ModuleManager();
|
||||
virtual ~ModuleManager() {}
|
||||
|
||||
/// SimObject overrides
|
||||
virtual bool onAdd();
|
||||
virtual void onRemove();
|
||||
virtual void onDeleteNotify( SimObject *object );
|
||||
static void initPersistFields();
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT( ModuleManager );
|
||||
|
||||
/// Module definitions.
|
||||
bool setModuleExtension( const char* pExtension );
|
||||
|
||||
/// Module discovery.
|
||||
bool scanModules( const char* pPath, const bool rootOnly = false );
|
||||
|
||||
/// Module unregister.
|
||||
bool unregisterModule( const char* pModuleId, const U32 versionId );
|
||||
|
||||
/// Module (un)loading.
|
||||
bool loadModuleGroup( const char* pModuleGroup );
|
||||
bool unloadModuleGroup( const char* pModuleGroup );
|
||||
bool loadModuleExplicit( const char* pModuleId, const U32 versionId = 0 );
|
||||
bool unloadModuleExplicit( const char* pModuleId );
|
||||
|
||||
/// Module type enumeration.
|
||||
ModuleDefinition* findModule( const char* pModuleId, const U32 versionId );
|
||||
ModuleDefinition* findLoadedModule( const char* pModuleId );
|
||||
void findModules( const bool loadedOnly, typeConstModuleDefinitionVector& moduleDefinitions );
|
||||
void findModuleTypes( const char* pModuleType, const bool loadedOnly, typeConstModuleDefinitionVector& moduleDefinitions );
|
||||
|
||||
/// Module synchronization.
|
||||
StringTableEntry copyModule( ModuleDefinition* pSourceModuleDefinition, const char* pTargetModuleId, const char* pTargetPath, const bool useVersionPathing );
|
||||
bool synchronizeDependencies( ModuleDefinition* pRootModuleDefinition, const char* pTargetDependencyPath );
|
||||
|
||||
/// Module updates.
|
||||
inline bool isModuleMergeAvailable( void ) const { return Platform::isFile( getModuleMergeFilePath() ); }
|
||||
bool canMergeModules( const char* pMergeSourcePath );
|
||||
bool mergeModules( const char* pMergeTargetPath, const bool removeMergeDefinition, const bool registerNewModules );
|
||||
|
||||
/// Module notifications.
|
||||
void addListener( SimObject* pListener );
|
||||
void removeListener( SimObject* pListener );
|
||||
|
||||
private:
|
||||
void clearDatabase( void );
|
||||
bool removeModuleDefinition( ModuleDefinition* pModuleDefinition );
|
||||
bool registerModule( const char* pModulePath, const char* pModuleFile );
|
||||
|
||||
void raiseModulePreLoadNotifications( ModuleDefinition* pModuleDefinition );
|
||||
void raiseModulePostLoadNotifications( ModuleDefinition* pModuleDefinition );
|
||||
void raiseModulePreUnloadNotifications( ModuleDefinition* pModuleDefinition );
|
||||
void raiseModulePostUnloadNotifications( ModuleDefinition* pModuleDefinition );
|
||||
|
||||
ModuleDefinitionEntry* findModuleId( StringTableEntry moduleId );
|
||||
ModuleDefinitionEntry::iterator findModuleDefinition( StringTableEntry moduleId, const U32 versionId );
|
||||
bool resolveModuleDependencies( StringTableEntry moduleId, const U32 versionId, StringTableEntry moduleGroup, bool synchronizedOnly, typeModuleLoadEntryVector& moduleResolvingQueue, typeModuleLoadEntryVector& moduleReadyQueue );
|
||||
ModuleLoadEntry* findModuleResolving( StringTableEntry moduleId, typeModuleLoadEntryVector& moduleResolvingQueue );
|
||||
ModuleLoadEntry* findModuleReady( StringTableEntry moduleId, typeModuleLoadEntryVector& moduleReadyQueue );
|
||||
typeModuleLoadEntryVector::iterator findModuleLoaded( StringTableEntry moduleId, const U32 versionId = 0 );
|
||||
typeGroupVector::iterator findGroupLoaded( StringTableEntry moduleGroup );
|
||||
StringTableEntry getModuleMergeFilePath( void ) const;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern ModuleManager ModuleDatabase;
|
||||
|
||||
#endif // _MODULE_MANAGER_H
|
||||
344
Engine/source/module/moduleManager_ScriptBinding.h
Normal file
344
Engine/source/module/moduleManager_ScriptBinding.h
Normal file
|
|
@ -0,0 +1,344 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "console/engineAPI.h"
|
||||
#include "moduleDefinition.h"
|
||||
#include "moduleManager.h"
|
||||
|
||||
DefineEngineMethod(ModuleManager, setModuleExtension, bool, (const char* moduleExtension), (""),
|
||||
"Set the module extension used to scan for modules. The default is 'module'.\n"
|
||||
"@param moduleExtension The module extension used to scan for modules.Do not use a period character.\n"
|
||||
"@return Whether setting the module extension was successful or not.\n")
|
||||
{
|
||||
// Set module extension.
|
||||
return object->setModuleExtension(moduleExtension);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, scanModules, bool, (const char* pRootPath, bool rootOnly), ("", false),
|
||||
"Scans for modules which are sub-directories of the specified path.\n"
|
||||
"@param moduleRootPath The root directory to scan for sub - directories containing modules.\n"
|
||||
"@param rootOnly[Optional] - Specifies whether to only scan the root path or not when searching for modules.\n"
|
||||
"@return Whether the scan was successful or not.A successful scan can still find zero modules.\n")
|
||||
{
|
||||
// Scan modules.
|
||||
return object->scanModules( pRootPath, rootOnly );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, unregisterModule, bool, (const char* pModuleId, bool versionId), ("", false),
|
||||
"Unregister the specified module.\n"
|
||||
"@param moduleId The module Id to unregister.\n"
|
||||
"@param versionId The version Id to unregister.\n"
|
||||
"@return Whether the module was unregister or not.\n")
|
||||
{
|
||||
// Unregister the module.
|
||||
return object->unregisterModule( pModuleId, versionId );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, loadGroup, bool, (const char* pModuleGroup), (""),
|
||||
"Load the specified module group.\n"
|
||||
"@param moduleGroup The module group to load.\n"
|
||||
"@return Whether the module group was loaded or not.\n")
|
||||
{
|
||||
// Load module group.
|
||||
return object->loadModuleGroup(pModuleGroup);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, unloadGroup, bool, (const char* pModuleGroup), (""),
|
||||
"Unload the specified module group.\n"
|
||||
"@param moduleGroup The module group to unload.\n"
|
||||
"@return Whether the module group was unloaded or not.\n")
|
||||
{
|
||||
// Unload module group.
|
||||
return object->unloadModuleGroup(pModuleGroup);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, loadExplicit, bool, (const char* pModuleId, S32 pVersionId), ("", -1),
|
||||
"Load the specified module explicitly.\n"
|
||||
"@param moduleId The module Id to load.\n"
|
||||
"@param versionId The version Id to load.Optional: Will load the latest version.\n"
|
||||
"@return Whether the module Id was loaded or not.\n")
|
||||
{
|
||||
if (pVersionId == -1)
|
||||
return object->loadModuleExplicit(pModuleId);
|
||||
else
|
||||
return object->loadModuleExplicit(pModuleId, pVersionId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, unloadExplicit, bool, (const char* pModuleId), (""),
|
||||
"Unload the specified module explicitly.\n"
|
||||
"@param moduleId The module Id to unload.\n"
|
||||
"@return Whether the module Id was unloaded or not.\n")
|
||||
{
|
||||
// Unload module Id explicitly.
|
||||
return object->unloadModuleExplicit(pModuleId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, findModule, String, (const char* pModuleId, U32 pVersionId), ("", 0),
|
||||
"Find the specific module Id optionally at the specified version Id.\n"
|
||||
"@param moduleId The module Id to find.\n"
|
||||
"@param versionId The version Id to find.\n"
|
||||
"@return The module definition object or NULL if not found.\n")
|
||||
{
|
||||
// Find module definition.
|
||||
ModuleDefinition* pModuleDefinition = object->findModule(pModuleId, pVersionId);
|
||||
|
||||
// Return nothing if not found.
|
||||
if ( pModuleDefinition == NULL )
|
||||
return StringTable->EmptyString();
|
||||
|
||||
return pModuleDefinition->getIdString();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, findModules, String, (bool loadedOnly), (false),
|
||||
"Find all the modules registered with the specified loaded state.\n"
|
||||
"@param loadedOnly Whether to return only modules that are loaded or not.\n"
|
||||
"@return A list of space - separated module definition object Ids.\n")
|
||||
{
|
||||
// Find module type definitions.
|
||||
Vector<const ModuleDefinition*> moduleDefinitions;
|
||||
|
||||
// Find modules.
|
||||
object->findModules( loadedOnly, moduleDefinitions );
|
||||
|
||||
// Fetch module definition count.
|
||||
const U32 moduleDefinitionCount = (U32)moduleDefinitions.size();
|
||||
|
||||
// Finish if no module definition were found.
|
||||
if ( moduleDefinitionCount == 0 )
|
||||
return StringTable->EmptyString();
|
||||
|
||||
// Create a return buffer.
|
||||
S32 bufferSize = 4096;
|
||||
char* pReturnBuffer = Con::getReturnBuffer( bufferSize );
|
||||
char* pBufferWrite = pReturnBuffer;
|
||||
|
||||
// Iterate module definitions.
|
||||
for ( ModuleManager::typeConstModuleDefinitionVector::const_iterator moduleDefinitionItr = moduleDefinitions.begin(); moduleDefinitionItr != moduleDefinitions.end(); ++moduleDefinitionItr )
|
||||
{
|
||||
// Fetch module definition.
|
||||
const ModuleDefinition* pModuleDefinition = *moduleDefinitionItr;
|
||||
|
||||
// Format module definition.
|
||||
const U32 offset = dSprintf( pBufferWrite, bufferSize, "%d ", pModuleDefinition->getId() );
|
||||
pBufferWrite += offset;
|
||||
bufferSize -= offset;
|
||||
|
||||
// Are we out of buffer space?
|
||||
if ( bufferSize <= 0 )
|
||||
{
|
||||
// Yes, so warn.
|
||||
Con::warnf( "ModuleManager::findModules() - Ran out of buffer space." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pReturnBuffer;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, findModuleTypes, String, (const char* pModuleType, bool loadedOnly), ("", false),
|
||||
"Find the modules registered with the specified module type.\n"
|
||||
"@param moduleType The module type to search for.\n"
|
||||
"@param loadedOnly Whether to return only modules that are loaded or not.\n"
|
||||
"@return A list of space - separated module definition object Ids.\n")
|
||||
{
|
||||
// Find module type definitions.
|
||||
Vector<const ModuleDefinition*> moduleDefinitions;
|
||||
|
||||
// Find module types.
|
||||
object->findModuleTypes( pModuleType, loadedOnly, moduleDefinitions );
|
||||
|
||||
// Fetch module definition count.
|
||||
const U32 moduleDefinitionCount = (U32)moduleDefinitions.size();
|
||||
|
||||
// Finish if no module definition were found.
|
||||
if ( moduleDefinitionCount == 0 )
|
||||
return StringTable->EmptyString();
|
||||
|
||||
// Create a return buffer.
|
||||
S32 bufferSize = 4096;
|
||||
char* pReturnBuffer = Con::getReturnBuffer( bufferSize );
|
||||
char* pBufferWrite = pReturnBuffer;
|
||||
|
||||
// Iterate module definitions.
|
||||
for ( ModuleManager::typeConstModuleDefinitionVector::const_iterator moduleDefinitionItr = moduleDefinitions.begin(); moduleDefinitionItr != moduleDefinitions.end(); ++moduleDefinitionItr )
|
||||
{
|
||||
// Fetch module definition.
|
||||
const ModuleDefinition* pModuleDefinition = *moduleDefinitionItr;
|
||||
|
||||
// Format module definition.
|
||||
const U32 offset = dSprintf( pBufferWrite, bufferSize, "%d ", pModuleDefinition->getId() );
|
||||
pBufferWrite += offset;
|
||||
bufferSize -= offset;
|
||||
|
||||
// Are we out of buffer space?
|
||||
if ( bufferSize <= 0 )
|
||||
{
|
||||
// Yes, so warn.
|
||||
Con::warnf( "ModuleManager::findTypes() - Ran out of buffer space." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pReturnBuffer;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, copyModule, String, (const char* sourceModuleDefinition, const char* pTargetModuleId, const char* pTargetPath, const bool useVersionPathing),
|
||||
("", "", "", false),
|
||||
"Copy the module to a new location with a new module Id.\n"
|
||||
"@param sourceModuleDefinition The module definition to copy.\n"
|
||||
"@param targetModuleId The module Id to rename the copied module to including all references to the source module Id.It is valid to specifiy the source module Id to produce an identical copy.\n"
|
||||
"@param targetPath The target path to copy the module to.Addition folders will be created depending on whether 'useVersionPathing' is used or not.\n"
|
||||
"@param useVersionPathing Whether to add a '/targetModuleId/versionId' folder to the target path or not.This allows copying multiple versions of the same module Id.\n"
|
||||
"@return The new module definition file if copy was successful or NULL if not.\n")
|
||||
{
|
||||
// Find the source module definition.
|
||||
ModuleDefinition* pSourceModuleDefinition = dynamic_cast<ModuleDefinition*>(Sim::findObject(sourceModuleDefinition));
|
||||
|
||||
// Was the module definition found?
|
||||
if ( pSourceModuleDefinition == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("ModuleManager::copyModule() - Could not find source module definition '%s'.", sourceModuleDefinition);
|
||||
return "";
|
||||
}
|
||||
|
||||
// Copy module.
|
||||
return object->copyModule( pSourceModuleDefinition, pTargetModuleId, pTargetPath, useVersionPathing );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, synchronizeDependencies, bool, (const char* rootModuleDefinition, const char* pTargetDependencyFolder), ("", ""),
|
||||
"Synchronize the module dependencies of a module definition to a target dependency folder.\n"
|
||||
"@param rootModuleDefinition The module definition used to determine dependencies.\n"
|
||||
"@param targetDependencyPath The target dependency folder to copy dependencies to.\n"
|
||||
"@return Whether the module dependencies were synchronized correctly or not.\n")
|
||||
{
|
||||
// Find the root module definition.
|
||||
ModuleDefinition* pRootModuleDefinition = dynamic_cast<ModuleDefinition*>(Sim::findObject(rootModuleDefinition));
|
||||
|
||||
// Was the module definition found?
|
||||
if ( pRootModuleDefinition == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("ModuleManager::synchronizeModules() - Could not find root module definition '%s'.", rootModuleDefinition);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Synchronize dependencies.
|
||||
return object->synchronizeDependencies( pRootModuleDefinition, pTargetDependencyFolder );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, isModuleMergeAvailable, bool, (),,
|
||||
"Checks whether a module merge definition file is available or not.\n"
|
||||
"@return Whether a module merge definition file is available or not.\n")
|
||||
{
|
||||
// Check if module merge is available or not.
|
||||
return object->isModuleMergeAvailable();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, canMergeModules, bool, (const char* mergeSourcePath), (""),
|
||||
"Checks whether a module merge using the modules in the source path can current happen or not.\n"
|
||||
"@param mergeSourcePath The path where modules to be merged are located.\n"
|
||||
"@return Whether a module merge using the modules in the source path can current happen or not.\n")
|
||||
{
|
||||
// Check whether the merge modules can current happen or not.
|
||||
return object->canMergeModules(mergeSourcePath);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, mergeModules, bool, (const char* pMergeTargetPath, bool removeMergeDefinition, bool registerNewModules), ("", false, false),
|
||||
"Performs a module merge into the selected target path.\n"
|
||||
"@param mergeTargetPath The path where modules will be merged into.\n"
|
||||
"@param removeMergeDefinition Whether to remove any merge definition found or not if merge is successful.\n"
|
||||
"@param registerNewModules Whether new (not replaced or updated) modules should be registered or not.\n"
|
||||
"@return Whether the module merge was successful or not.Failure here could result in a corrupt module state.Reinstall is recommended or at least advised to the user is recommended.\n")
|
||||
{
|
||||
// Merge modules.
|
||||
return object->mergeModules( pMergeTargetPath, removeMergeDefinition, registerNewModules );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, addListener, void, (const char* listenerObject), (""),
|
||||
"Registers the specified object as a listener for module notifications.\n"
|
||||
"@param listenerObject The object to start receiving module notifications.\n"
|
||||
"@return No return value.\n")
|
||||
{
|
||||
// Find object.
|
||||
SimObject* pListener = Sim::findObject(listenerObject);
|
||||
|
||||
// Did we find the listener object?
|
||||
if ( pListener == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("ModuleManager::addNotifications() - Could not find the listener object '%s'.", listenerObject);
|
||||
return;
|
||||
}
|
||||
|
||||
object->addListener( pListener );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(ModuleManager, removeListener, void, (const char* listenerObject), (""),
|
||||
"Unregisters the specified object as a listener for module notifications.\n"
|
||||
"@param listenerObject The object to stop receiving module notifications.\n"
|
||||
"@return No return value.\n")
|
||||
{
|
||||
// Find object.
|
||||
SimObject* pListener = Sim::findObject(listenerObject);
|
||||
|
||||
// Did we find the listener object?
|
||||
if ( pListener == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("ModuleManager::removeNotifications() - Could not find the listener object '%s'.", listenerObject);
|
||||
return;
|
||||
}
|
||||
|
||||
object->removeListener( pListener );
|
||||
}
|
||||
49
Engine/source/module/moduleMergeDefinition.cpp
Normal file
49
Engine/source/module/moduleMergeDefinition.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "moduleMergeDefinition.h"
|
||||
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT( ModuleMergeDefinition );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ModuleMergeDefinition::ModuleMergeDefinition() :
|
||||
mModuleMergePath( StringTable->EmptyString() )
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ModuleMergeDefinition::initPersistFields()
|
||||
{
|
||||
// Call parent.
|
||||
Parent::initPersistFields();
|
||||
|
||||
/// Module merge.
|
||||
addField( "MergePath", TypeString, Offset(mModuleMergePath, ModuleMergeDefinition), "The path where the modules to be merged can be found." );
|
||||
}
|
||||
56
Engine/source/module/moduleMergeDefinition.h
Normal file
56
Engine/source/module/moduleMergeDefinition.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _MODULE_MERGE_DEFINITION_H
|
||||
#define _MODULE_MERGE_DEFINITION_H
|
||||
|
||||
#ifndef _SIMBASE_H_
|
||||
#include "console/simBase.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class ModuleMergeDefinition : public SimObject
|
||||
{
|
||||
private:
|
||||
typedef SimObject Parent;
|
||||
|
||||
/// Module update
|
||||
StringTableEntry mModuleMergePath;
|
||||
|
||||
public:
|
||||
ModuleMergeDefinition();
|
||||
virtual ~ModuleMergeDefinition() {}
|
||||
|
||||
/// Engine.
|
||||
static void initPersistFields();
|
||||
|
||||
/// Module merge.
|
||||
inline void setModuleMergePath( const char* pModuleMergePath ) { mModuleMergePath = StringTable->insert(pModuleMergePath); }
|
||||
inline StringTableEntry getModuleMergePath( void ) const { return mModuleMergePath; }
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT( ModuleMergeDefinition );
|
||||
};
|
||||
|
||||
#endif // _MODULE_MERGE_DEFINITION_H
|
||||
|
||||
133
Engine/source/module/tamlModuleIdUpdateVisitor.h
Normal file
133
Engine/source/module/tamlModuleIdUpdateVisitor.h
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _TAML_MODULE_ID_UPDATE_VISITOR_H_
|
||||
#define _TAML_MODULE_ID_UPDATE_VISITOR_H_
|
||||
|
||||
#ifndef _TAML_VISITOR_H_
|
||||
#include "persistence/taml/tamlVisitor.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TAML_PARSER_H_
|
||||
#include "persistence/taml/tamlParser.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_FIELD_TYPES_H_
|
||||
#include "assets/assetFieldTypes.h"
|
||||
#endif
|
||||
|
||||
#include "platform/profiler.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TamlModuleIdUpdateVisitor : public TamlVisitor
|
||||
{
|
||||
private:
|
||||
StringTableEntry mModuleIdFrom;
|
||||
StringTableEntry mModuleIdTo;
|
||||
U32 mModuleIdFromLength;
|
||||
U32 mModuleIdToLength;
|
||||
|
||||
public:
|
||||
TamlModuleIdUpdateVisitor() :
|
||||
mModuleIdFrom( StringTable->EmptyString() ),
|
||||
mModuleIdTo(StringTable->EmptyString()),
|
||||
mModuleIdFromLength( 0 ),
|
||||
mModuleIdToLength( 0 )
|
||||
{}
|
||||
virtual ~TamlModuleIdUpdateVisitor() {}
|
||||
|
||||
virtual bool wantsPropertyChanges( void ) { return true; }
|
||||
virtual bool wantsRootOnly( void ) { return true; }
|
||||
|
||||
virtual bool visit( const TamlParser& parser, TamlVisitor::PropertyState& propertyState )
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(TamlModuleIdUpdateVisitor_Visit);
|
||||
|
||||
// Fetch property value.
|
||||
const char* pPropertyValue = propertyState.getPropertyValue();
|
||||
|
||||
// Fetch value length.
|
||||
const U32 valueLenth = dStrlen(pPropertyValue);
|
||||
|
||||
char newAttributeValueBuffer[1024];
|
||||
|
||||
// Is this an expando?
|
||||
if ( *pPropertyValue == '^' )
|
||||
{
|
||||
// Yes, so finish if it's not the correct length.
|
||||
if ( valueLenth < mModuleIdFromLength+1 )
|
||||
return true;
|
||||
|
||||
// Is this the module Id?
|
||||
if ( dStrnicmp( pPropertyValue+1, mModuleIdFrom, mModuleIdFromLength ) == 0 )
|
||||
{
|
||||
// Yes, so format a new value.
|
||||
dSprintf( newAttributeValueBuffer, sizeof(newAttributeValueBuffer), "^%s%s",
|
||||
mModuleIdTo, pPropertyValue+1+mModuleIdFromLength );
|
||||
|
||||
// Assign new value.
|
||||
propertyState.updatePropertyValue( newAttributeValueBuffer );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Does the field start with the module Id?
|
||||
if ( dStrnicmp( pPropertyValue, mModuleIdFrom, mModuleIdFromLength ) == 0 )
|
||||
{
|
||||
// Yes, so format a new value.
|
||||
dSprintf( newAttributeValueBuffer, sizeof(newAttributeValueBuffer), "%s%s",
|
||||
mModuleIdTo, pPropertyValue+mModuleIdFromLength );
|
||||
|
||||
// Assign new value.
|
||||
propertyState.updatePropertyValue( newAttributeValueBuffer );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void setModuleIdFrom( const char* pModuleIdFrom )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pModuleIdFrom != NULL, "Module Id from cannot be NULL." );
|
||||
|
||||
// Set module Id.
|
||||
mModuleIdFrom = StringTable->insert( pModuleIdFrom );
|
||||
mModuleIdFromLength = dStrlen(mModuleIdFrom);
|
||||
}
|
||||
StringTableEntry getModuleIdFrom( void ) const { return mModuleIdFrom; }
|
||||
|
||||
void setModuleIdTo( const char* pModuleIdTo )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pModuleIdTo != NULL, "Module Id to cannot be NULL." );
|
||||
|
||||
// Set module Id.
|
||||
mModuleIdTo = StringTable->insert( pModuleIdTo );
|
||||
mModuleIdToLength = dStrlen(mModuleIdTo);
|
||||
}
|
||||
const char* getModuleIdTo( void ) const { return mModuleIdTo; }
|
||||
};
|
||||
|
||||
#endif // _TAML_MODULE_ID_UPDATE_VISITOR_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue