mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +00:00
Implements support of autoloaded assets.
This commit is contained in:
parent
efbd5fb451
commit
4e03f07e8e
5 changed files with 184 additions and 0 deletions
|
|
@ -54,6 +54,14 @@
|
|||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _AUTOLOAD_ASSETS_H_
|
||||
#include "assets/autoloadAssets.h"
|
||||
#endif
|
||||
|
||||
#ifndef COMPONENTASSET_H
|
||||
#include "T3D/assets/ComponentAsset.h"
|
||||
#endif
|
||||
|
||||
// Script bindings.
|
||||
#include "assetManager_ScriptBinding.h"
|
||||
|
||||
|
|
@ -202,6 +210,57 @@ bool AssetManager::addModuleDeclaredAssets( ModuleDefinition* pModuleDefinition
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AssetManager::loadModuleAutoLoadAssets(ModuleDefinition* pModuleDefinition)
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(AssetManager_loadModuleAutoLoadAssets);
|
||||
|
||||
// Sanity!
|
||||
AssertFatal(pModuleDefinition != NULL, "Cannot auto load assets using a NULL module definition");
|
||||
|
||||
// Does the module have any assets associated with it?
|
||||
if (pModuleDefinition->getModuleAssets().empty())
|
||||
{
|
||||
// Yes, so warn.
|
||||
Con::warnf("Asset Manager: Cannot auto load assets to module '%s' as it has no existing assets.", pModuleDefinition->getSignature());
|
||||
return false;
|
||||
}
|
||||
|
||||
U32 assetCount = pModuleDefinition->getModuleAssets().size();
|
||||
|
||||
// Iterate the module definition children.
|
||||
for (SimSet::iterator itr = pModuleDefinition->begin(); itr != pModuleDefinition->end(); ++itr)
|
||||
{
|
||||
// Fetch the declared assets.
|
||||
AutoloadAssets* pAutoloadAssets = dynamic_cast<AutoloadAssets*>(*itr);
|
||||
|
||||
// Skip if it's not a declared assets location.
|
||||
if (pAutoloadAssets == NULL)
|
||||
continue;
|
||||
|
||||
for (U32 i = 0; i < assetCount; ++i)
|
||||
{
|
||||
AssetDefinition* assetDef = pModuleDefinition->getModuleAssets()[i];
|
||||
|
||||
if (assetDef->mAssetType == pAutoloadAssets->getAssetType())
|
||||
{
|
||||
//TODO: this is stupid and ugly, need to properly automagically parse the class for registration
|
||||
AssetBase* assetBase = nullptr;
|
||||
|
||||
if (assetDef->mAssetType == StringTable->insert("ComponentAsset"))
|
||||
{
|
||||
assetBase = mTaml.read<ComponentAsset>(assetDef->mAssetBaseFilePath);
|
||||
}
|
||||
|
||||
//load the asset now if valid
|
||||
if (assetBase)
|
||||
addPrivateAsset(assetBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool AssetManager::addDeclaredAsset( ModuleDefinition* pModuleDefinition, const char* pAssetFilePath )
|
||||
|
|
@ -2974,6 +3033,9 @@ void AssetManager::onModulePreLoad( ModuleDefinition* pModuleDefinition )
|
|||
// Add module declared assets.
|
||||
addModuleDeclaredAssets( pModuleDefinition );
|
||||
|
||||
// Load any auto-loaded asset types
|
||||
loadModuleAutoLoadAssets(pModuleDefinition);
|
||||
|
||||
// Is an asset tags manifest specified?
|
||||
if ( pModuleDefinition->getAssetTagsManifest() != StringTable->EmptyString() )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ public:
|
|||
bool removeDeclaredAssets( ModuleDefinition* pModuleDefinition );
|
||||
bool removeDeclaredAsset( const char* pAssetId );
|
||||
bool renameDeclaredAsset( const char* pAssetIdFrom, const char* pAssetIdTo );
|
||||
bool loadModuleAutoLoadAssets(ModuleDefinition* pModuleDefinition);
|
||||
StringTableEntry getAssetName( const char* pAssetId );
|
||||
StringTableEntry getAssetDescription( const char* pAssetId );
|
||||
StringTableEntry getAssetCategory( const char* pAssetId );
|
||||
|
|
|
|||
45
Engine/source/assets/autoloadAssets.cpp
Normal file
45
Engine/source/assets/autoloadAssets.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _AUTOLOAD_ASSETS_H_
|
||||
#include "assets/autoloadAssets.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT(AutoloadAssets);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AutoloadAssets::initPersistFields()
|
||||
{
|
||||
// Call Parent.
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField("Path", TypeString, Offset(mPath, AutoloadAssets), "");
|
||||
addField("AssetType", TypeString, Offset(mAssetType, AutoloadAssets), "");
|
||||
addField("Recurse", TypeBool, Offset(mRecurse, AutoloadAssets), "");
|
||||
}
|
||||
74
Engine/source/assets/autoloadAssets.h
Normal file
74
Engine/source/assets/autoloadAssets.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _AUTOLOAD_ASSETS_H_
|
||||
#define _AUTOLOAD_ASSETS_H_
|
||||
|
||||
#ifndef _SIM_H_
|
||||
#include "console/sim.h"
|
||||
#endif
|
||||
|
||||
#ifndef _SIMOBJECT_H_
|
||||
#include "console/simObject.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CONSOLEOBJECT_H_
|
||||
#include "console/consoleObject.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AutoloadAssets : public SimObject
|
||||
{
|
||||
friend class AssetManager;
|
||||
|
||||
private:
|
||||
typedef SimObject Parent;
|
||||
|
||||
StringTableEntry mPath;
|
||||
StringTableEntry mAssetType;
|
||||
bool mRecurse;
|
||||
|
||||
public:
|
||||
AutoloadAssets() :
|
||||
mPath(StringTable->EmptyString()),
|
||||
mAssetType(StringTable->EmptyString()),
|
||||
mRecurse(false)
|
||||
{}
|
||||
virtual ~AutoloadAssets() {}
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
inline void setPath(const char* pPath) { mPath = StringTable->insert(pPath); }
|
||||
inline StringTableEntry getPath(void) const { return mPath; }
|
||||
inline void setAssetType(const char* pPath) { mAssetType = StringTable->insert(pPath); }
|
||||
inline StringTableEntry getAssetType(void) const { return mAssetType; }
|
||||
inline void setRecurse(const bool recurse) { mRecurse = recurse; }
|
||||
inline bool getRecurse(void) const { return mRecurse; }
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(AutoloadAssets);
|
||||
};
|
||||
|
||||
#endif // _DECLARED_ASSETS_H_
|
||||
|
||||
#pragma once
|
||||
|
|
@ -166,6 +166,8 @@ public:
|
|||
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; }
|
||||
void addDeclaredAsset(AssetDefinition* asset) { mModuleAssets.push_back(asset); }
|
||||
|
||||
|
||||
/// Module location.
|
||||
inline void setModulePath( const char* pModulePath ) { if ( checkUnlocked() ) { mModulePath = StringTable->insert(pModulePath); } }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue