Torque3D Documentation / _generateds / moduleDefinition.h

moduleDefinition.h

Engine/source/module/moduleDefinition.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2013 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _MODULE_DEFINITION_H
 25#define _MODULE_DEFINITION_H
 26
 27#ifndef _ASSET_DEFINITION_H_
 28#include "assets/assetDefinition.h"
 29#endif
 30
 31#ifndef _SIMSET_H_
 32#include "console/simSet.h"
 33#endif
 34
 35#ifndef _SIMBASE_H_
 36#include "console/simBase.h"
 37#endif
 38
 39#ifndef _TVECTOR_H_
 40#include "core/util/tVector.h"
 41#endif
 42
 43#ifndef _STRINGUNIT_H_
 44#include "core/strings/stringUnit.h"
 45#endif
 46
 47//-----------------------------------------------------------------------------
 48
 49class ModuleManager;
 50
 51//-----------------------------------------------------------------------------
 52
 53/// @ingroup moduleGroup
 54/// @see moduleGroup
 55class ModuleDefinition : public SimSet
 56{
 57    friend class ModuleManager;
 58
 59private:
 60    typedef SimSet Parent;
 61
 62public:
 63    /// Module dependency.
 64    struct ModuleDependency
 65    {
 66        ModuleDependency() :
 67            mModuleId( StringTable->EmptyString() ),
 68            mVersionId( 0 )        
 69        {
 70        }
 71
 72        ModuleDependency( StringTableEntry moduleId, const U32 versionId ) :
 73            mModuleId( moduleId ),
 74            mVersionId( versionId )
 75        {
 76        }
 77
 78        StringTableEntry    mModuleId;
 79        U32                 mVersionId;
 80    };
 81    typedef Vector<ModuleDependency> typeModuleDependencyVector;
 82    typedef Vector<AssetDefinition*> typeModuleAssetsVector;
 83
 84private:
 85    /// Module definition.
 86    StringTableEntry                mModuleId;
 87    U32                             mVersionId;
 88    U32                             mBuildId;
 89    bool                            mEnabled;
 90    bool                            mSynchronized;
 91    bool                            mDeprecated;
 92    bool                            mCriticalMerge;
 93    bool                            mOverrideExistingObjects;
 94    StringTableEntry                mModuleDescription;
 95    StringTableEntry                mAuthor;;
 96    StringTableEntry                mModuleGroup;
 97    StringTableEntry                mModuleType;
 98    typeModuleDependencyVector      mDependencies;
 99    StringTableEntry                mScriptFile;
100    StringTableEntry                mCreateFunction;
101    StringTableEntry                mDestroyFunction;
102
103    /// Modules assets.
104    StringTableEntry                mAssetTagsManifest;
105    typeModuleAssetsVector          mModuleAssets;
106
107    /// Module location.
108    StringTableEntry                mModulePath;
109    StringTableEntry                mModuleFile;
110    StringTableEntry                mModuleFilePath;
111    StringTableEntry                mModuleScriptFilePath;
112
113    /// Miscellaneous.
114    StringTableEntry                mSignature;
115    S32                             mLoadCount;
116    SimObjectId                     mScopeSet;
117    bool                            mLocked;
118    ModuleManager*                  mpModuleManager;
119
120private:
121    inline bool             checkUnlocked( void ) const { if ( mLocked )        { Con::warnf("Ignoring changes for locked module definition."); } return !mLocked; }
122    inline void             setModuleManager( ModuleManager* pModuleManager )   { mpModuleManager = pModuleManager; }
123
124public:
125    ModuleDefinition();
126    virtual ~ModuleDefinition() {}
127
128    /// Engine.
129    static void             initPersistFields();
130
131    /// Module definition.
132    inline void             setModuleId( const char* pModuleId )                { if ( checkUnlocked() ) { mModuleId = StringTable->insert(pModuleId); } }
133    inline StringTableEntry getModuleId( void ) const                           { return mModuleId; }
134    inline void             setVersionId( const U32 versionId )                 { if ( checkUnlocked() ) { mVersionId = versionId; } }
135    inline U32              getVersionId( void ) const                          { return mVersionId; }
136    inline void             setBuildId( const U32 buildId )                     { if ( checkUnlocked() ) { mBuildId = buildId; } }
137    inline U32              getBuildId( void ) const                            { return mBuildId; }
138    inline void             setEnabled( const bool enabled )                    { if ( checkUnlocked() ) { mEnabled = enabled; } }
139    inline bool             getEnabled( void ) const                            { return mEnabled; }
140    inline void             setSynchronized( const bool synchronized )          { if ( checkUnlocked() ) { mSynchronized = synchronized; } }
141    inline bool             getSynchronized( void ) const                       { return mSynchronized; }
142    inline void             setDeprecated( const bool deprecated )              { if ( checkUnlocked() ) { mDeprecated = deprecated; } }
143    inline bool             getDeprecated( void ) const                         { return mDeprecated; }
144    inline void             setCriticalMerge( const bool mergeCritical )        { if ( checkUnlocked() ) { mCriticalMerge = mergeCritical; } }
145    inline bool             getCriticalMerge( void ) const                      { return mCriticalMerge; }
146    inline void             setOverrideExistingObjects(const bool overrideExistingObj) { if (checkUnlocked()) { mOverrideExistingObjects = overrideExistingObj; } }
147    inline bool             getOverrideExistingObjects(void) const              { return mOverrideExistingObjects; }
148    inline void             setModuleDescription( const char* pModuleDescription ) { if ( checkUnlocked() ) { mModuleDescription = StringTable->insert(pModuleDescription); } }
149    inline StringTableEntry getModuleDescription( void ) const                  { return mModuleDescription; }
150    inline void             setAuthor( const char* pAuthor )                    { if ( checkUnlocked() ) { mAuthor = StringTable->insert(pAuthor); } }
151    inline StringTableEntry getAuthor( void ) const                             { return mAuthor; }
152    inline void             setModuleGroup( const char* pModuleGroup )          { if ( checkUnlocked() ) { mModuleGroup = StringTable->insert(pModuleGroup); } }
153    inline StringTableEntry getModuleGroup( void ) const                        { return mModuleGroup; }
154    inline void             setModuleType( const char* pModuleType )            { if ( checkUnlocked() ) { mModuleType = StringTable->insert(pModuleType); } }
155    inline StringTableEntry getModuleType( void ) const                         { return mModuleType; }
156    inline void             setDependencies( const typeModuleDependencyVector& dependencies ) { if ( checkUnlocked() ) { mDependencies.clear(); mDependencies.merge(dependencies); } }
157    inline const typeModuleDependencyVector& getDependencies( void ) const      { return mDependencies; }
158    inline void             setScriptFile( const char* pScriptFile )            { if ( checkUnlocked() ) { mScriptFile = StringTable->insert(pScriptFile); } }
159    inline StringTableEntry getScriptFile( void ) const                         { return mScriptFile; }
160    inline void             setCreateFunction( const char* pCreateFunction )    { if ( checkUnlocked() ) { mCreateFunction = StringTable->insert(pCreateFunction); } }
161    inline StringTableEntry getCreateFunction( void ) const                     { return mCreateFunction; }
162    inline void             setDestroyFunction( const char* pDestroyFunction )  { if ( checkUnlocked() ) { mDestroyFunction = StringTable->insert(pDestroyFunction); } }
163    inline StringTableEntry getDestroyFunction( void ) const                    { return mDestroyFunction; }
164    inline SimObjectId      getScopeSet( void ) const                           { return mScopeSet; }
165
166    /// Module assets.
167    inline void             setAssetTagsManifest( const char* pTagsAssetManifest ) { if ( checkUnlocked() ) { mAssetTagsManifest = StringTable->insert(pTagsAssetManifest); } }
168    inline StringTableEntry getAssetTagsManifest( void ) const                  { return mAssetTagsManifest; }
169    inline typeModuleAssetsVector& getModuleAssets( void )                      { return mModuleAssets; }
170    void                    addDeclaredAsset(AssetDefinition* asset)            { mModuleAssets.push_back(asset); }
171
172
173    /// Module location.
174    inline void             setModulePath( const char* pModulePath )            { if ( checkUnlocked() ) { mModulePath = StringTable->insert(pModulePath); } }
175    inline StringTableEntry getModulePath( void ) const                         { return mModulePath; }
176    inline void             setModuleFile( const char* pModuleDefinitionFile )  { if ( checkUnlocked() ) { mModuleFile = StringTable->insert(pModuleDefinitionFile); } }
177    inline StringTableEntry getModuleFile( void ) const                         { return mModuleFile; }
178    inline void             setModuleFilePath( const char* pModuleDefinitionFilePath ) { if ( checkUnlocked() ) { mModuleFilePath = StringTable->insert(pModuleDefinitionFilePath); } }
179    inline StringTableEntry getModuleFilePath( void ) const                     { return mModuleFilePath; }
180    inline void             setModuleScriptFilePath( const char* pModuleScriptFilePath ) { if ( checkUnlocked() ) { mModuleScriptFilePath = StringTable->insert(pModuleScriptFilePath); } }
181    inline StringTableEntry getModuleScriptFilePath( void ) const               { return mModuleScriptFilePath; }
182
183    /// Specialized dependency control.
184    inline U32              getDependencyCount( void ) const                    { return mDependencies.size(); }
185    bool                    getDependency( const U32 dependencyIndex, ModuleDependency& dependency ) const;
186    bool                    addDependency( const char* pModuleId, const U32 versionId );
187    bool                    removeDependency( const char* pModuleId );
188
189    /// Miscellaneous.
190    inline void             setSignature( const char* pSignature )              { if ( checkUnlocked() ) { mSignature = StringTable->insert(pSignature); } }
191    inline StringTableEntry getSignature( void ) const                          { return mSignature; }
192    inline void             increaseLoadCount( void )                           { ++mLoadCount; }
193    inline void             reduceLoadCount( void )                             { --mLoadCount; }
194    inline S32              getLoadCount( void ) const                          { return mLoadCount; }
195    inline void             setModuleLocked( const bool status )                { mLocked = status; }
196    inline bool             getModuleLocked( void ) const                       { return mLocked; }
197    inline ModuleManager*   getModuleManager( void ) const                      { return mpModuleManager; }
198    bool                    save( void );
199
200    /// Declare Console Object.
201    DECLARE_CONOBJECT( ModuleDefinition );
202
203protected:
204    static bool             setModuleId(void* obj, const char* index, const char* data)                    { static_cast<ModuleDefinition*>(obj)->setModuleId( data ); return false; }
205    static bool             setVersionId(void* obj, const char* index, const char* data)                   { static_cast<ModuleDefinition*>(obj)->setVersionId((U32)dAtoi(data)); return false; }
206    static bool             setBuildId(void* obj, const char* index, const char* data)                     { static_cast<ModuleDefinition*>(obj)->setBuildId((U32)dAtoi(data)); return false; }
207    static bool             writeBuildId( void* obj, StringTableEntry pFieldName )      { return static_cast<ModuleDefinition*>(obj)->getBuildId() != 0; }
208    static bool             setEnabled(void* obj, const char* index, const char* data)                     { static_cast<ModuleDefinition*>(obj)->setEnabled(dAtob(data)); return false; }
209    static bool             writeEnabled( void* obj, StringTableEntry pFieldName )      { return static_cast<ModuleDefinition*>(obj)->getEnabled() == false; }
210    static bool             setSynchronized(void* obj, const char* index, const char* data)                { static_cast<ModuleDefinition*>(obj)->setSynchronized(dAtob(data)); return false; }
211    static bool             writeSynchronized( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getSynchronized() == true; }
212    static bool             setDeprecated(void* obj, const char* index, const char* data)                  { static_cast<ModuleDefinition*>(obj)->setDeprecated(dAtob(data)); return false; }
213    static bool             writeDeprecated( void* obj, StringTableEntry pFieldName )   { return static_cast<ModuleDefinition*>(obj)->getDeprecated() == true; }
214    static bool             writeCriticalMerge( void* obj, StringTableEntry pFieldName ){ return static_cast<ModuleDefinition*>(obj)->getCriticalMerge() == true; }    
215    static bool             setOverrideExistingObjects(void* obj, const char* index, const char* data)     { static_cast<ModuleDefinition*>(obj)->setOverrideExistingObjects(dAtob(data)); return false; }
216    static bool             writeOverrideExistingObjects(void* obj, StringTableEntry pFieldName)           { return static_cast<ModuleDefinition*>(obj)->getOverrideExistingObjects() == true; }
217    static bool             setModuleDescription(void* obj, const char* index, const char* data)           { static_cast<ModuleDefinition*>(obj)->setModuleDescription(data); return false; }
218    static bool             writeModuleDescription( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getModuleDescription() != StringTable->EmptyString(); }
219    static bool             setAuthor(void* obj, const char* index, const char* data)                      { static_cast<ModuleDefinition*>(obj)->setAuthor(data); return false; }
220    static bool             writeAuthor(void* obj, StringTableEntry pFieldName)       { return static_cast<ModuleDefinition*>(obj)->getAuthor() != StringTable->EmptyString(); }
221    static bool             setModuleGroup(void* obj, const char* index, const char* data)                 { static_cast<ModuleDefinition*>(obj)->setModuleGroup(data); return false; }
222    static bool             setModuleType(void* obj, const char* index, const char* data)                  { static_cast<ModuleDefinition*>(obj)->setModuleType(data); return false; }
223    static bool             writeModuleType(void* obj, StringTableEntry pFieldName)   { return static_cast<ModuleDefinition*>(obj)->getModuleType() != StringTable->EmptyString(); }
224    static bool             setScriptFile(void* obj, const char* index, const char* data)                  { static_cast<ModuleDefinition*>(obj)->setScriptFile(data); return false; }
225    static bool             writeScriptFile(void* obj, StringTableEntry pFieldName)   { return static_cast<ModuleDefinition*>(obj)->getScriptFile() != StringTable->EmptyString(); }
226    static bool             setCreateFunction(void* obj, const char* index, const char* data)              { static_cast<ModuleDefinition*>(obj)->setCreateFunction(data); return false; }
227    static bool             writeCreateFunction(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getCreateFunction() != StringTable->EmptyString(); }
228    static bool             setDestroyFunction(void* obj, const char* index, const char* data)             { static_cast<ModuleDefinition*>(obj)->setDestroyFunction(data); return false; }
229    static bool             writeDestroyFunction(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getDestroyFunction() != StringTable->EmptyString(); }
230
231    /// Asset manifest.
232    static bool             setAssetTagsManifest(void* obj, const char* index, const char* data)     { static_cast<ModuleDefinition*>(obj)->setAssetTagsManifest(data); return false; }
233    static bool             writeAssetTagsManifest(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getAssetTagsManifest() != StringTable->EmptyString(); }
234    static const char*      getScopeSet(void* obj, const char* data)                    { return Con::getIntArg(static_cast<ModuleDefinition*>(obj)->getScopeSet()); }
235
236    static bool             setDependencies(void* obj, const char* index, const char* data)
237    {
238        // Fetch module dependencies.
239        ModuleDefinition::typeModuleDependencyVector moduleDependencies;
240
241        // Fetch dependency value.
242        const char* pDependencyValue = data;
243
244        char slotUnit[256];
245        char slotName[256];
246        char slotValue[256];
247
248        // Fetch definition word count.
249        const U32 dependencyWordCount = StringUnit::getUnitCount( pDependencyValue, "," );
250
251        // Do we have any dependencies specified?
252        if ( dependencyWordCount > 0 )
253        {
254            // Yes, so iterate dependencies.
255            for ( U32 dependencyIndex = 0; dependencyIndex < dependencyWordCount; ++dependencyIndex )
256            {
257                // Fetch slot.
258                dStrcpy( slotUnit, StringUnit::getUnit( pDependencyValue, dependencyIndex, "," ), 256 );
259        
260                // Fetch slot name and value.
261                dStrcpy( slotName, StringUnit::getUnit( slotUnit, 0, "=" ), 256 );
262                dStrcpy( slotValue, StringUnit::getUnit( slotUnit, 1, "=" ), 256 );
263
264                // Fetch module Id.
265                StringTableEntry moduleId = StringTable->insert( slotName );
266
267                // Fetch version Id.
268                const U32 versionId = slotValue[0] == '*' ? 0 : dAtoi(slotValue);
269
270                // Populate module dependency.
271                ModuleDefinition::ModuleDependency dependency( moduleId, versionId );
272
273                // Store dependency.
274                moduleDependencies.push_back( dependency );
275            }
276        }
277
278        // Set dependencies.
279        static_cast<ModuleDefinition*>(obj)->setDependencies( moduleDependencies );
280
281        return false;
282    }
283    static const char*      getDependencies(void* obj, const char* data)
284    {
285        // Fetch module dependencies.
286        const ModuleDefinition::typeModuleDependencyVector& moduleDependencies = static_cast<ModuleDefinition*>(obj)->getDependencies();
287
288        // Finish if no dependencies.
289        if ( moduleDependencies.size() == 0 )
290            return StringTable->EmptyString();
291
292        // Get a return buffer.
293        const S32 bufferSize = 1024;
294        char* pReturnBuffer = Con::getReturnBuffer(bufferSize);
295        pReturnBuffer[0] = '\0';
296
297        // Set buffer limits.
298        char* pValueBuffer = pReturnBuffer;
299        S32 bufferLeft = bufferSize;
300        U32 used;
301
302        // Iterate module dependencies.
303        for ( ModuleDefinition::typeModuleDependencyVector::const_iterator dependencyItr = moduleDependencies.begin(); dependencyItr < moduleDependencies.end(); ++dependencyItr )
304        {
305            // Fetch module dependency.
306            const ModuleDefinition::ModuleDependency* pDependency = dependencyItr;
307
308            // Fetch version Id.
309            const char* pVersionId = pDependency->mVersionId == 0 ? "*" : avar("%d", pDependency->mVersionId );
310           
311            if ( dependencyItr == moduleDependencies.begin() )
312            {
313                // Write out a field/value pair
314                used = dSprintf( pValueBuffer, bufferLeft, "%s=%s", pDependency->mModuleId, pVersionId );
315                pValueBuffer += used;
316                bufferLeft -= used;
317            }
318            else
319            {
320                // Write out a field/value pair
321                used = dSprintf( pValueBuffer, bufferLeft, ",%s=%s", pDependency->mModuleId, pVersionId );
322                pValueBuffer += used;
323                bufferLeft -= used;
324            }
325
326            // Sanity.
327            AssertFatal( bufferLeft > 0, "Cannot format module dependencies as we ran out of buffer." );      
328        }
329
330        return pReturnBuffer;
331    }
332    static bool             writeDependencies( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getDependencies().size() > 0; }
333    static const char*      getSignature(void* obj, const char* data)                   { return static_cast<ModuleDefinition*>(obj)->getSignature(); }
334};
335
336#endif // _MODULE_DEFINITION_H
337
338