mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 14:44:36 +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
352
Engine/source/assets/assetBase.cpp
Normal file
352
Engine/source/assets/assetBase.cpp
Normal file
|
|
@ -0,0 +1,352 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_BASE_H_
|
||||
#include "assetBase.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_MANAGER_H_
|
||||
#include "assetManager.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
// Script bindings.
|
||||
#include "assetBase_ScriptBinding.h"
|
||||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT(AssetBase);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry assetNameField = StringTable->insert("AssetName");
|
||||
StringTableEntry assetDescriptionField = StringTable->insert("AssetDescription");
|
||||
StringTableEntry assetCategoryField = StringTable->insert("AssetCategory");
|
||||
StringTableEntry assetAutoUnloadField = StringTable->insert("AssetAutoUnload");
|
||||
StringTableEntry assetInternalField = StringTable->insert("AssetInternal");
|
||||
StringTableEntry assetPrivateField = StringTable->insert("AssetPrivate");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
AssetBase::AssetBase() :
|
||||
mAcquireReferenceCount(0),
|
||||
mpOwningAssetManager(NULL),
|
||||
mAssetInitialized(false)
|
||||
{
|
||||
// Generate an asset definition.
|
||||
mpAssetDefinition = new AssetDefinition();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
AssetBase::~AssetBase()
|
||||
{
|
||||
// If the asset manager does not own the asset then we own the
|
||||
// asset definition so delete it.
|
||||
if (!getOwned())
|
||||
delete mpAssetDefinition;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetBase::initPersistFields()
|
||||
{
|
||||
// Call parent.
|
||||
Parent::initPersistFields();
|
||||
|
||||
// Asset configuration.
|
||||
addProtectedField(assetNameField, TypeString, 0, &setAssetName, &getAssetName, &writeAssetName, "The name of the asset. The is not a unique identification like an asset Id.");
|
||||
addProtectedField(assetDescriptionField, TypeString, 0, &setAssetDescription, &getAssetDescription, &writeAssetDescription, "The simple description of the asset contents.");
|
||||
addProtectedField(assetCategoryField, TypeString, 0, &setAssetCategory, &getAssetCategory, &writeAssetCategory, "An arbitrary category that can be used to categorized assets.");
|
||||
addProtectedField(assetAutoUnloadField, TypeBool, 0, &setAssetAutoUnload, &getAssetAutoUnload, &writeAssetAutoUnload, "Whether the asset is automatically unloaded when an asset is released and has no other acquisitions or not.");
|
||||
addProtectedField(assetInternalField, TypeBool, 0, &setAssetInternal, &getAssetInternal, &writeAssetInternal, "Whether the asset is used internally only or not.");
|
||||
addProtectedField(assetPrivateField, TypeBool, 0, &defaultProtectedNotSetFn, &getAssetPrivate, &defaultProtectedNotWriteFn, "Whether the asset is private or not.");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void AssetBase::copyTo(SimObject* object)
|
||||
{
|
||||
// Call to parent.
|
||||
Parent::copyTo(object);
|
||||
|
||||
// Cast to asset.
|
||||
AssetBase* pAsset = static_cast<AssetBase*>(object);
|
||||
|
||||
// Sanity!
|
||||
AssertFatal(pAsset != NULL, "AssetBase::copyTo() - Object is not the correct type.");
|
||||
|
||||
// Copy state.
|
||||
pAsset->setAssetName(getAssetName());
|
||||
pAsset->setAssetDescription(getAssetDescription());
|
||||
pAsset->setAssetCategory(getAssetCategory());
|
||||
pAsset->setAssetAutoUnload(getAssetAutoUnload());
|
||||
pAsset->setAssetInternal(getAssetInternal());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetBase::setAssetDescription(const char* pAssetDescription)
|
||||
{
|
||||
// Fetch asset description.
|
||||
StringTableEntry assetDescription = StringTable->insert(pAssetDescription);
|
||||
|
||||
// Ignore no change.
|
||||
if (mpAssetDefinition->mAssetDescription == assetDescription)
|
||||
return;
|
||||
|
||||
// Update.
|
||||
mpAssetDefinition->mAssetDescription = assetDescription;
|
||||
|
||||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetBase::setAssetCategory(const char* pAssetCategory)
|
||||
{
|
||||
// Fetch asset category.
|
||||
StringTableEntry assetCategory = StringTable->insert(pAssetCategory);
|
||||
|
||||
// Ignore no change.
|
||||
if (mpAssetDefinition->mAssetCategory == assetCategory)
|
||||
return;
|
||||
|
||||
// Update.
|
||||
mpAssetDefinition->mAssetCategory = assetCategory;
|
||||
|
||||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetBase::setAssetAutoUnload(const bool autoUnload)
|
||||
{
|
||||
// Ignore no change.
|
||||
if (mpAssetDefinition->mAssetAutoUnload == autoUnload)
|
||||
return;
|
||||
|
||||
// Update.
|
||||
mpAssetDefinition->mAssetAutoUnload = autoUnload;
|
||||
|
||||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetBase::setAssetInternal(const bool assetInternal)
|
||||
{
|
||||
// Ignore no change,
|
||||
if (mpAssetDefinition->mAssetInternal == assetInternal)
|
||||
return;
|
||||
|
||||
// Update.
|
||||
mpAssetDefinition->mAssetInternal = assetInternal;
|
||||
|
||||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry AssetBase::expandAssetFilePath(const char* pAssetFilePath) const
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(AssetBase_ExpandAssetFilePath);
|
||||
|
||||
// Sanity!
|
||||
AssertFatal(pAssetFilePath != NULL, "Cannot expand a NULL asset path.");
|
||||
|
||||
// Fetch asset file-path length.
|
||||
const U32 assetFilePathLength = dStrlen(pAssetFilePath);
|
||||
|
||||
// Are there any characters in the path?
|
||||
if (assetFilePathLength == 0)
|
||||
{
|
||||
// No, so return empty.
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
// Fetch the asset base-path hint.
|
||||
StringTableEntry assetBasePathHint;
|
||||
if (getOwned() && !getAssetPrivate())
|
||||
{
|
||||
assetBasePathHint = mpOwningAssetManager->getAssetPath(getAssetId());
|
||||
}
|
||||
else
|
||||
{
|
||||
assetBasePathHint = NULL;
|
||||
}
|
||||
|
||||
// Expand the path with the asset base-path hint.
|
||||
char assetFilePathBuffer[1024];
|
||||
Con::expandPath(assetFilePathBuffer, sizeof(assetFilePathBuffer), pAssetFilePath, assetBasePathHint);
|
||||
return StringTable->insert(assetFilePathBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry AssetBase::collapseAssetFilePath(const char* pAssetFilePath) const
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(AssetBase_CollapseAssetFilePath);
|
||||
|
||||
// Sanity!
|
||||
AssertFatal(pAssetFilePath != NULL, "Cannot collapse a NULL asset path.");
|
||||
|
||||
// Fetch asset file-path length.
|
||||
const U32 assetFilePathLength = dStrlen(pAssetFilePath);
|
||||
|
||||
// Are there any characters in the path?
|
||||
if (assetFilePathLength == 0)
|
||||
{
|
||||
// No, so return empty.
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
char assetFilePathBuffer[1024];
|
||||
|
||||
// Is the asset not owned or private?
|
||||
if (!getOwned() || getAssetPrivate())
|
||||
{
|
||||
// Yes, so we can only collapse the path using the platform layer.
|
||||
Con::collapsePath(assetFilePathBuffer, sizeof(assetFilePathBuffer), pAssetFilePath);
|
||||
return StringTable->insert(assetFilePathBuffer);
|
||||
}
|
||||
|
||||
// Fetch asset base-path.
|
||||
StringTableEntry assetBasePath = mpOwningAssetManager->getAssetPath(getAssetId());
|
||||
|
||||
// Is the asset file-path location within the asset base-path?
|
||||
if (Con::isBasePath(pAssetFilePath, assetBasePath))
|
||||
{
|
||||
// Yes, so fetch path relative to the asset base-path.
|
||||
StringTableEntry relativePath = Platform::makeRelativePathName(pAssetFilePath, assetBasePath);
|
||||
|
||||
// Format the collapsed path.
|
||||
dSprintf(assetFilePathBuffer, sizeof(assetFilePathBuffer), "%s", relativePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, so we can collapse the path using the platform layer.
|
||||
Con::collapsePath(assetFilePathBuffer, sizeof(assetFilePathBuffer), pAssetFilePath);
|
||||
}
|
||||
|
||||
return StringTable->insert(assetFilePathBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetBase::refreshAsset(void)
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(AssetBase_RefreshAsset);
|
||||
|
||||
// Finish if asset is not owned or is not initialized.
|
||||
if (mpOwningAssetManager == NULL || !mAssetInitialized)
|
||||
return;
|
||||
|
||||
// Yes, so refresh the asset via the asset manager.
|
||||
mpOwningAssetManager->refreshAsset(getAssetId());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetBase::acquireAssetReference(void)
|
||||
{
|
||||
// Acquired the acquired reference count.
|
||||
if (mpOwningAssetManager != NULL)
|
||||
mpOwningAssetManager->acquireAcquiredReferenceCount();
|
||||
|
||||
mAcquireReferenceCount++;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool AssetBase::releaseAssetReference(void)
|
||||
{
|
||||
// Are there any acquisition references?
|
||||
if (mAcquireReferenceCount == 0)
|
||||
{
|
||||
// Return "unload" unless auto unload is off.
|
||||
return mpAssetDefinition->mAssetAutoUnload;
|
||||
}
|
||||
|
||||
// Release the acquired reference count.
|
||||
if (mpOwningAssetManager != NULL)
|
||||
mpOwningAssetManager->releaseAcquiredReferenceCount();
|
||||
|
||||
// Release reference.
|
||||
mAcquireReferenceCount--;
|
||||
|
||||
// Are there any acquisition references?
|
||||
if (mAcquireReferenceCount == 0)
|
||||
{
|
||||
// No, so return "unload" unless auto unload is off.
|
||||
return mpAssetDefinition->mAssetAutoUnload;
|
||||
}
|
||||
|
||||
// Return "don't unload".
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetBase::setOwned(AssetManager* pAssetManager, AssetDefinition* pAssetDefinition)
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(AssetBase_setOwned);
|
||||
|
||||
// Sanity!
|
||||
AssertFatal(pAssetManager != NULL, "Cannot set asset ownership with NULL asset manager.");
|
||||
AssertFatal(mpOwningAssetManager == NULL, "Cannot set asset ownership if it is already owned.");
|
||||
AssertFatal(pAssetDefinition != NULL, "Cannot set asset ownership with a NULL asset definition.");
|
||||
AssertFatal(mpAssetDefinition != NULL, "Asset ownership assigned but has a NULL asset definition.");
|
||||
AssertFatal(mpAssetDefinition->mAssetName == pAssetDefinition->mAssetName, "Asset ownership differs by asset name.");
|
||||
AssertFatal(mpAssetDefinition->mAssetDescription == pAssetDefinition->mAssetDescription, "Asset ownership differs by asset description.");
|
||||
AssertFatal(mpAssetDefinition->mAssetCategory == pAssetDefinition->mAssetCategory, "Asset ownership differs by asset category.");
|
||||
AssertFatal(mpAssetDefinition->mAssetAutoUnload == pAssetDefinition->mAssetAutoUnload, "Asset ownership differs by asset auto-unload flag.");
|
||||
AssertFatal(mpAssetDefinition->mAssetInternal == pAssetDefinition->mAssetInternal, "Asset ownership differs by asset internal flag.");
|
||||
|
||||
// Transfer asset definition ownership state.
|
||||
delete mpAssetDefinition;
|
||||
mpAssetDefinition = pAssetDefinition;
|
||||
|
||||
// Flag as owned.
|
||||
// NOTE: This must be done prior to initializing the asset so any initialization can assume ownership.
|
||||
mpOwningAssetManager = pAssetManager;
|
||||
|
||||
// Initialize the asset.
|
||||
initializeAsset();
|
||||
|
||||
// Flag asset as initialized.
|
||||
mAssetInitialized = true;
|
||||
}
|
||||
145
Engine/source/assets/assetBase.h
Normal file
145
Engine/source/assets/assetBase.h
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_BASE_H_
|
||||
#define _ASSET_BASE_H_
|
||||
|
||||
#ifndef _ASSET_DEFINITION_H_
|
||||
#include "assetDefinition.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STRINGUNIT_H_
|
||||
#include "string/stringUnit.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_FIELD_TYPES_H_
|
||||
#include "assets/assetFieldTypes.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AssetManager;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern StringTableEntry assetNameField;
|
||||
extern StringTableEntry assetDescriptionField;
|
||||
extern StringTableEntry assetCategoryField;
|
||||
extern StringTableEntry assetInternalField;
|
||||
extern StringTableEntry assetPrivateField;
|
||||
extern StringTableEntry assetAutoUnloadField;
|
||||
|
||||
//#define ASSET_BASE_ASSETNAME_FIELD "AssetName"
|
||||
//#define ASSET_BASE_ASSETDESCRIPTION_FIELD "AssetDescription"
|
||||
//#define ASSET_BASE_ASSETCATEGORY_FIELD "AssetCategory"
|
||||
//#define ASSET_BASE_ASSETINTERNAL_FIELD "AssetInternal"
|
||||
//#define ASSET_BASE_ASSETPRIVATE_FIELD "AssetPrivate"
|
||||
//#define ASSET_BASE_AUTOUNLOAD_FIELD "AssetAutoUnload"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AssetBase : public SimObject
|
||||
{
|
||||
friend class AssetManager;
|
||||
|
||||
typedef SimObject Parent;
|
||||
|
||||
AssetManager* mpOwningAssetManager;
|
||||
bool mAssetInitialized;
|
||||
AssetDefinition* mpAssetDefinition;
|
||||
U32 mAcquireReferenceCount;
|
||||
|
||||
public:
|
||||
AssetBase();
|
||||
virtual ~AssetBase();
|
||||
|
||||
/// Engine.
|
||||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
||||
/// Asset configuration.
|
||||
inline void setAssetName(const char* pAssetName) { if (mpOwningAssetManager == NULL) mpAssetDefinition->mAssetName = StringTable->insert(pAssetName); }
|
||||
inline StringTableEntry getAssetName(void) const { return mpAssetDefinition->mAssetName; }
|
||||
void setAssetDescription(const char* pAssetDescription);
|
||||
inline StringTableEntry getAssetDescription(void) const { return mpAssetDefinition->mAssetDescription; }
|
||||
void setAssetCategory(const char* pAssetCategory);
|
||||
inline StringTableEntry getAssetCategory(void) const { return mpAssetDefinition->mAssetCategory; }
|
||||
void setAssetAutoUnload(const bool autoUnload);
|
||||
inline bool getAssetAutoUnload(void) const { return mpAssetDefinition->mAssetAutoUnload; }
|
||||
void setAssetInternal(const bool assetInternal);
|
||||
inline bool getAssetInternal(void) const { return mpAssetDefinition->mAssetInternal; }
|
||||
inline bool getAssetPrivate(void) const { return mpAssetDefinition->mAssetPrivate; }
|
||||
inline StringTableEntry getAssetType(void) const { return mpAssetDefinition->mAssetType; }
|
||||
|
||||
inline S32 getAcquiredReferenceCount(void) const { return mAcquireReferenceCount; }
|
||||
inline bool getOwned(void) const { return mpOwningAssetManager != NULL; }
|
||||
|
||||
// Asset Id is only available once registered with the asset manager.
|
||||
inline StringTableEntry getAssetId(void) const { return mpAssetDefinition->mAssetId; }
|
||||
|
||||
/// Expanding/Collapsing asset paths is only available once registered with the asset manager.
|
||||
StringTableEntry expandAssetFilePath(const char* pAssetFilePath) const;
|
||||
StringTableEntry collapseAssetFilePath(const char* pAssetFilePath) const;
|
||||
|
||||
virtual bool isAssetValid(void) const { return true; }
|
||||
|
||||
void refreshAsset(void);
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(AssetBase);
|
||||
|
||||
protected:
|
||||
virtual void initializeAsset(void) {}
|
||||
virtual void onAssetRefresh(void) {}
|
||||
|
||||
protected:
|
||||
static bool setAssetName(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetName(data); return false; }
|
||||
static const char* getAssetName(void* obj, const char* data) { return static_cast<AssetBase*>(obj)->getAssetName(); }
|
||||
static bool writeAssetName(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetName() != StringTable->EmptyString(); }
|
||||
|
||||
static bool setAssetDescription(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetDescription(data); return false; }
|
||||
static const char* getAssetDescription(void* obj, const char* data) { return static_cast<AssetBase*>(obj)->getAssetDescription(); }
|
||||
static bool writeAssetDescription(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetDescription() != StringTable->EmptyString(); }
|
||||
|
||||
static bool setAssetCategory(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetCategory(data); return false; }
|
||||
static const char* getAssetCategory(void* obj, const char* data) { return static_cast<AssetBase*>(obj)->getAssetCategory(); }
|
||||
static bool writeAssetCategory(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetCategory() != StringTable->EmptyString(); }
|
||||
|
||||
static bool setAssetAutoUnload(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetAutoUnload(dAtob(data)); return false; }
|
||||
static const char* getAssetAutoUnload(void* obj, const char* data) { return Con::getBoolArg(static_cast<AssetBase*>(obj)->getAssetAutoUnload()); }
|
||||
static bool writeAssetAutoUnload(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetAutoUnload() == false; }
|
||||
|
||||
static bool setAssetInternal(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetInternal(dAtob(data)); return false; }
|
||||
static const char* getAssetInternal(void* obj, const char* data) { return Con::getBoolArg(static_cast<AssetBase*>(obj)->getAssetInternal()); }
|
||||
static bool writeAssetInternal(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetInternal() == true; }
|
||||
|
||||
static const char* getAssetPrivate(void* obj, const char* data) { return Con::getBoolArg(static_cast<AssetBase*>(obj)->getAssetPrivate()); }
|
||||
|
||||
private:
|
||||
void acquireAssetReference(void);
|
||||
bool releaseAssetReference(void);
|
||||
|
||||
/// Set asset manager ownership.
|
||||
void setOwned(AssetManager* pAssetManager, AssetDefinition* pAssetDefinition);
|
||||
};
|
||||
|
||||
#endif // _ASSET_BASE_H_
|
||||
|
||||
41
Engine/source/assets/assetBase_ScriptBinding.h
Normal file
41
Engine/source/assets/assetBase_ScriptBinding.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 "assetBase.h"
|
||||
#include "assetManager.h"
|
||||
|
||||
|
||||
DefineEngineMethod(AssetBase, refreshAsset, void, (), ,
|
||||
"Refresh the asset.\n"
|
||||
"@return No return value.\n")
|
||||
{
|
||||
object->refreshAsset();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetBase, getAssetId, String, (), ,
|
||||
"Gets the assets' Asset Id. This is only available if the asset was acquired from the asset manager.\n"
|
||||
"@return The assets' Asset Id.\n")
|
||||
{
|
||||
return object->getAssetId();
|
||||
}
|
||||
102
Engine/source/assets/assetDefinition.h
Normal file
102
Engine/source/assets/assetDefinition.h
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_DEFINITION_H_
|
||||
#define _ASSET_DEFINITION_H_
|
||||
|
||||
#ifndef _STRINGTABLE_H_
|
||||
#include "core/stringTable.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STRINGUNIT_H_
|
||||
#include "core/strings/stringUnit.h"
|
||||
#endif
|
||||
|
||||
#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 AssetBase;
|
||||
class ModuleDefinition;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct AssetDefinition
|
||||
{
|
||||
public:
|
||||
AssetDefinition() { reset(); }
|
||||
virtual ~AssetDefinition() {}
|
||||
|
||||
virtual void reset( void )
|
||||
{
|
||||
mAssetLoading = false;
|
||||
mpModuleDefinition = NULL;
|
||||
mpAssetBase = NULL;
|
||||
mAssetBaseFilePath = StringTable->EmptyString();
|
||||
mAssetId = StringTable->EmptyString();
|
||||
mAssetLoadedCount = 0;
|
||||
mAssetUnloadedCount = 0;
|
||||
mAssetRefreshEnable = true;
|
||||
mAssetLooseFiles.clear();
|
||||
|
||||
// Reset persisted state.
|
||||
mAssetName = StringTable->EmptyString();
|
||||
mAssetDescription = StringTable->EmptyString();
|
||||
mAssetAutoUnload = true;
|
||||
mAssetInternal = false;
|
||||
mAssetPrivate = false;
|
||||
mAssetType = StringTable->EmptyString();
|
||||
mAssetCategory = StringTable->EmptyString();
|
||||
}
|
||||
|
||||
ModuleDefinition* mpModuleDefinition;
|
||||
AssetBase* mpAssetBase;
|
||||
StringTableEntry mAssetBaseFilePath;
|
||||
StringTableEntry mAssetId;
|
||||
U32 mAssetLoadedCount;
|
||||
U32 mAssetUnloadedCount;
|
||||
bool mAssetRefreshEnable;
|
||||
Vector<StringTableEntry> mAssetLooseFiles;
|
||||
|
||||
/// Persisted state.
|
||||
StringTableEntry mAssetName;
|
||||
StringTableEntry mAssetDescription;
|
||||
bool mAssetAutoUnload;
|
||||
bool mAssetInternal;
|
||||
bool mAssetPrivate;
|
||||
bool mAssetLoading;
|
||||
StringTableEntry mAssetType;
|
||||
StringTableEntry mAssetCategory;
|
||||
};
|
||||
|
||||
#endif // _ASSET_DEFINITION_H_
|
||||
|
||||
114
Engine/source/assets/assetFieldTypes.cpp
Normal file
114
Engine/source/assets/assetFieldTypes.cpp
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_FIELD_TYPES_H_
|
||||
#include "assetFieldTypes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_PTR_H_
|
||||
#include "assetPtr.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_BASE_H_
|
||||
#include "assetBase.h"
|
||||
#endif
|
||||
|
||||
/*#ifndef _AUDIO_ASSET_H_
|
||||
#include "audio/AudioAsset.h"
|
||||
#endif*/
|
||||
|
||||
#ifndef _STRINGUNIT_H_
|
||||
#include "string/stringUnit.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry assetLooseIdSignature = StringTable->insert( ASSET_ID_SIGNATURE );
|
||||
StringTableEntry assetLooseFileSignature = StringTable->insert( ASSET_LOOSEFILE_SIGNATURE );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleType( assetLooseFilePath, TypeAssetLooseFilePath, String, ASSET_LOOSE_FILE_FIELD_PREFIX )
|
||||
ConsoleType(assetIdString, TypeAssetId, String, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleGetType( TypeAssetLooseFilePath )
|
||||
{
|
||||
// Fetch asset loose file-path.
|
||||
return *((StringTableEntry*)dptr);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleSetType( TypeAssetLooseFilePath )
|
||||
{
|
||||
// Was a single argument specified?
|
||||
if( argc == 1 )
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset loose file-path.
|
||||
StringTableEntry* assetLooseFilePath = (StringTableEntry*)(dptr);
|
||||
|
||||
// Update asset loose file-path value.
|
||||
*assetLooseFilePath = StringTable->insert(pFieldValue);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Warn.
|
||||
Con::warnf( "(TypeAssetLooseFilePath) - Cannot set multiple args to a single asset loose-file." );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleGetType( TypeAssetId )
|
||||
{
|
||||
// Fetch asset Id.
|
||||
return *((StringTableEntry*)dptr);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleSetType( TypeAssetId )
|
||||
{
|
||||
// Was a single argument specified?
|
||||
if( argc == 1 )
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry* assetId = (StringTableEntry*)(dptr);
|
||||
|
||||
// Update asset value.
|
||||
*assetId = StringTable->insert(pFieldValue);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Warn.
|
||||
Con::warnf( "(TypeAssetId) - Cannot set multiple args to a single asset." );
|
||||
}
|
||||
|
||||
56
Engine/source/assets/assetFieldTypes.h
Normal file
56
Engine/source/assets/assetFieldTypes.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 _ASSET_FIELD_TYPES_H_
|
||||
#define _ASSET_FIELD_TYPES_H_
|
||||
|
||||
#ifndef _CONSOLE_BASE_TYPE_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineConsoleType( TypeAssetId, S32 )
|
||||
DefineConsoleType( TypeAssetLooseFilePath, String )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Asset scope.
|
||||
#define ASSET_SCOPE_TOKEN ":"
|
||||
|
||||
/// Asset assignment.
|
||||
#define ASSET_ASSIGNMENT_TOKEN "="
|
||||
|
||||
/// Asset Id.
|
||||
#define ASSET_ID_SIGNATURE "@asset"
|
||||
#define ASSET_ID_FIELD_PREFIX "@asset="
|
||||
|
||||
/// Asset loose file.
|
||||
#define ASSET_LOOSEFILE_SIGNATURE "@assetFile"
|
||||
#define ASSET_LOOSE_FILE_FIELD_PREFIX "@assetFile="
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern StringTableEntry assetLooseIdSignature;
|
||||
extern StringTableEntry assetLooseFileSignature;
|
||||
|
||||
#endif // _ASSET_FIELD_TYPES_H_
|
||||
3017
Engine/source/assets/assetManager.cpp
Normal file
3017
Engine/source/assets/assetManager.cpp
Normal file
File diff suppressed because it is too large
Load diff
395
Engine/source/assets/assetManager.h
Normal file
395
Engine/source/assets/assetManager.h
Normal file
|
|
@ -0,0 +1,395 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_MANAGER_H_
|
||||
#define _ASSET_MANAGER_H_
|
||||
|
||||
#ifndef _SIMBASE_H_
|
||||
#include "console/sim.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TAML_H_
|
||||
#include "persistence/taml/taml.h"
|
||||
#endif
|
||||
|
||||
#ifndef _MODULE_DEFINITION_H
|
||||
#include "module/moduleDefinition.h"
|
||||
#endif
|
||||
|
||||
#ifndef _MODULE_CALLBACKS_H_
|
||||
#include "module/moduleCallbacks.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_BASE_H_
|
||||
#include "assets/assetBase.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_DEFINITION_H_
|
||||
#include "assets/assetDefinition.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_TAGS_MANIFEST_H_
|
||||
#include "assets/assetTagsManifest.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_QUERY_H_
|
||||
#include "assets/assetQuery.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_FIELD_TYPES_H_
|
||||
#include "assets/assetFieldTypes.h"
|
||||
#endif
|
||||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AssetPtrCallback;
|
||||
class AssetPtrBase;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AssetManager : public SimObject, public ModuleCallbacks
|
||||
{
|
||||
private:
|
||||
typedef SimObject Parent;
|
||||
typedef StringTableEntry typeAssetId;
|
||||
typedef StringTableEntry typeAssetName;
|
||||
typedef StringTableEntry typeReferenceFilePath;
|
||||
typedef HashMap<typeAssetId, AssetDefinition*> typeDeclaredAssetsHash;
|
||||
typedef HashTable<typeAssetId, typeReferenceFilePath> typeReferencedAssetsHash;
|
||||
typedef HashTable<typeAssetId, typeAssetId> typeAssetDependsOnHash;
|
||||
typedef HashTable<typeAssetId, typeAssetId> typeAssetIsDependedOnHash;
|
||||
typedef HashMap<AssetPtrBase*, AssetPtrCallback*> typeAssetPtrRefreshHash;
|
||||
|
||||
/// Declared assets.
|
||||
typeDeclaredAssetsHash mDeclaredAssets;
|
||||
|
||||
/// Referenced assets.
|
||||
typeReferencedAssetsHash mReferencedAssets;
|
||||
|
||||
/// Asset dependencies.
|
||||
typeAssetDependsOnHash mAssetDependsOn;
|
||||
typeAssetIsDependedOnHash mAssetIsDependedOn;
|
||||
|
||||
/// Asset tags.
|
||||
SimObjectPtr<AssetTagsManifest> mAssetTagsManifest;
|
||||
SimObjectPtr<ModuleDefinition> mAssetTagsModuleDefinition;
|
||||
|
||||
/// Asset pointer refresh notifications.
|
||||
typeAssetPtrRefreshHash mAssetPtrRefreshNotifications;
|
||||
|
||||
/// Miscellaneous.
|
||||
bool mEchoInfo;
|
||||
bool mIgnoreAutoUnload;
|
||||
U32 mLoadedInternalAssetsCount;
|
||||
U32 mLoadedExternalAssetsCount;
|
||||
U32 mLoadedPrivateAssetsCount;
|
||||
U32 mAcquiredReferenceCount;
|
||||
U32 mMaxLoadedInternalAssetsCount;
|
||||
U32 mMaxLoadedExternalAssetsCount;
|
||||
U32 mMaxLoadedPrivateAssetsCount;
|
||||
Taml mTaml;
|
||||
|
||||
public:
|
||||
AssetManager();
|
||||
virtual ~AssetManager() {}
|
||||
|
||||
/// SimObject overrides
|
||||
virtual bool onAdd();
|
||||
virtual void onRemove();
|
||||
static void initPersistFields();
|
||||
|
||||
/// Declared assets.
|
||||
bool addModuleDeclaredAssets( ModuleDefinition* pModuleDefinition );
|
||||
bool addDeclaredAsset( ModuleDefinition* pModuleDefinition, const char* pAssetFilePath );
|
||||
StringTableEntry addPrivateAsset( AssetBase* pAssetBase );
|
||||
bool removeDeclaredAssets( ModuleDefinition* pModuleDefinition );
|
||||
bool removeDeclaredAsset( const char* pAssetId );
|
||||
bool renameDeclaredAsset( const char* pAssetIdFrom, const char* pAssetIdTo );
|
||||
StringTableEntry getAssetName( const char* pAssetId );
|
||||
StringTableEntry getAssetDescription( const char* pAssetId );
|
||||
StringTableEntry getAssetCategory( const char* pAssetId );
|
||||
StringTableEntry getAssetType( const char* pAssetId );
|
||||
StringTableEntry getAssetFilePath( const char* pAssetId );
|
||||
StringTableEntry getAssetPath( const char* pAssetId );
|
||||
ModuleDefinition* getAssetModuleDefinition( const char* pAssetId );
|
||||
bool isAssetInternal( const char* pAssetId );
|
||||
bool isAssetPrivate( const char* pAssetId );
|
||||
bool isAssetAutoUnload( const char* pAssetId );
|
||||
bool isAssetLoaded( const char* pAssetId );
|
||||
bool isDeclaredAsset( const char* pAssetId );
|
||||
bool doesAssetDependOn( const char* pAssetId, const char* pDependsOnAssetId );
|
||||
bool isAssetDependedOn( const char* pAssetId, const char* pDependedOnByAssetId );
|
||||
|
||||
/// Referenced assets.
|
||||
bool compileReferencedAssets( ModuleDefinition* pModuleDefinition );
|
||||
bool isReferencedAsset( const char* pAssetId );
|
||||
bool renameReferencedAsset( const char* pAssetIdFrom, const char* pAssetIdTo );
|
||||
|
||||
/// Public asset acquisition.
|
||||
template<typename T> T* acquireAsset( const char* pAssetId )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetId != NULL, "Cannot acquire NULL asset Id." );
|
||||
|
||||
// Is this an empty asset Id?
|
||||
if ( *pAssetId == 0 )
|
||||
{
|
||||
// Yes, so return nothing.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Find asset.
|
||||
AssetDefinition* pAssetDefinition = findAsset( pAssetId );
|
||||
|
||||
// Did we find the asset?
|
||||
if ( pAssetDefinition == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "Asset Manager: Failed to acquire asset Id '%s' as it does not exist.", pAssetId );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Is asset loading?
|
||||
if ( pAssetDefinition->mAssetLoading == true )
|
||||
{
|
||||
// Yes, so we've got a circular loop which we cannot resolve!
|
||||
Con::warnf( "Asset Manager: Failed to acquire asset Id '%s' as loading it involves a cyclic dependency on itself which cannot be resolved.", pAssetId );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Info.
|
||||
if ( mEchoInfo )
|
||||
{
|
||||
Con::printSeparator();
|
||||
Con::printf( "Asset Manager: Started acquiring Asset Id '%s'...", pAssetId );
|
||||
}
|
||||
|
||||
// Is the asset already loaded?
|
||||
if ( pAssetDefinition->mpAssetBase == NULL )
|
||||
{
|
||||
// No, so info
|
||||
if ( mEchoInfo )
|
||||
{
|
||||
// Fetch asset Id.
|
||||
StringTableEntry assetId = StringTable->insert( pAssetId );
|
||||
|
||||
// Find any asset dependencies.
|
||||
typeAssetDependsOnHash::Iterator assetDependenciesItr = mAssetDependsOn.find( assetId );
|
||||
|
||||
// Does the asset have any dependencies?
|
||||
if ( assetDependenciesItr != mAssetDependsOn.end() )
|
||||
{
|
||||
// Yes, so show all dependency assets.
|
||||
Con::printf( "Asset Manager: > Found dependencies:" );
|
||||
|
||||
// Iterate all dependencies.
|
||||
while( assetDependenciesItr != mAssetDependsOn.end() && assetDependenciesItr->key == assetId )
|
||||
{
|
||||
// Info.
|
||||
Con::printf( "Asset Manager: > Asset Id '%s'", assetDependenciesItr->value );
|
||||
|
||||
// Next dependency.
|
||||
assetDependenciesItr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Flag asset as loading.
|
||||
pAssetDefinition->mAssetLoading = true;
|
||||
|
||||
// Generate primary asset.
|
||||
pAssetDefinition->mpAssetBase = mTaml.read<T>( pAssetDefinition->mAssetBaseFilePath );
|
||||
|
||||
// Flag asset as finished loading.
|
||||
pAssetDefinition->mAssetLoading = false;
|
||||
|
||||
// Did we generate the asset?
|
||||
if ( pAssetDefinition->mpAssetBase == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "Asset Manager: > Failed to acquire asset Id '%s' as loading the asset file failed to return the asset or the correct asset type: '%s'.",
|
||||
pAssetId, pAssetDefinition->mAssetBaseFilePath );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Increase loaded count.
|
||||
pAssetDefinition->mAssetLoadedCount++;
|
||||
|
||||
// Info.
|
||||
if ( mEchoInfo )
|
||||
{
|
||||
Con::printf( "Asset Manager: > Loading asset into memory as object Id '%d' from file '%s'.",
|
||||
pAssetDefinition->mpAssetBase->getId(), pAssetDefinition->mAssetBaseFilePath );
|
||||
}
|
||||
|
||||
// Set ownership by asset manager.
|
||||
pAssetDefinition->mpAssetBase->setOwned( this, pAssetDefinition );
|
||||
|
||||
// Is the asset internal?
|
||||
if ( pAssetDefinition->mAssetInternal )
|
||||
{
|
||||
// Yes, so increase internal loaded asset count.
|
||||
if ( ++mLoadedInternalAssetsCount > mMaxLoadedInternalAssetsCount )
|
||||
mMaxLoadedInternalAssetsCount = mLoadedInternalAssetsCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, so increase external loaded assets count.
|
||||
if ( ++mLoadedExternalAssetsCount > mMaxLoadedExternalAssetsCount )
|
||||
mMaxLoadedExternalAssetsCount = mLoadedExternalAssetsCount;
|
||||
}
|
||||
}
|
||||
else if ( pAssetDefinition->mpAssetBase->getAcquiredReferenceCount() == 0 )
|
||||
{
|
||||
// Info.
|
||||
if ( mEchoInfo )
|
||||
{
|
||||
Con::printf( "Asset Manager: > Acquiring from idle state." );
|
||||
}
|
||||
}
|
||||
|
||||
// Set acquired asset.
|
||||
T* pAcquiredAsset = dynamic_cast<T*>( (AssetBase*)pAssetDefinition->mpAssetBase );
|
||||
|
||||
// Is asset the correct type?
|
||||
if ( pAcquiredAsset == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "Asset Manager: > Failed to acquire asset Id '%s' as it was not the required asset type: '%s'.", pAssetId, pAssetDefinition->mAssetBaseFilePath );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Acquire asset reference.
|
||||
pAcquiredAsset->acquireAssetReference();
|
||||
|
||||
// Info.
|
||||
if ( mEchoInfo )
|
||||
{
|
||||
Con::printf( "Asset Manager: > Finished acquiring asset. Reference count now '%d'.", pAssetDefinition->mpAssetBase->getAcquiredReferenceCount() );
|
||||
Con::printSeparator();
|
||||
}
|
||||
|
||||
return pAcquiredAsset;
|
||||
}
|
||||
|
||||
/// Private asset acquisition.
|
||||
template<typename T> T* acquireAsPrivateAsset( const char* pAssetId )
|
||||
{
|
||||
// Acquire the asset normally.
|
||||
T* pAsset = acquireAsset<T>( pAssetId );
|
||||
|
||||
// Finish if the asset was not acquired.
|
||||
if ( pAsset == NULL )
|
||||
return NULL;
|
||||
|
||||
// Clone the asset.
|
||||
T* pAssetClone = dynamic_cast<T*>( pAsset->clone() );
|
||||
|
||||
// Sanity!
|
||||
AssertFatal( pAssetClone != NULL, "acquireAsPrivateAsset() - Failed to clone asset type." );
|
||||
|
||||
// Release the public asset.
|
||||
releaseAsset( pAssetId );
|
||||
|
||||
// Add as a private asset.
|
||||
addPrivateAsset( pAssetClone );
|
||||
|
||||
return pAssetClone;
|
||||
}
|
||||
|
||||
bool releaseAsset( const char* pAssetId );
|
||||
void purgeAssets( void );
|
||||
|
||||
/// Asset deletion.
|
||||
bool deleteAsset( const char* pAssetId, const bool deleteLooseFiles, const bool deleteDependencies );
|
||||
|
||||
// Asset refresh notification.
|
||||
bool refreshAsset( const char* pAssetId );
|
||||
void refreshAllAssets( const bool includeUnloaded = false );
|
||||
void registerAssetPtrRefreshNotify( AssetPtrBase* pAssetPtrBase, AssetPtrCallback* pCallback );
|
||||
void unregisterAssetPtrRefreshNotify( AssetPtrBase* pAssetPtrBase );
|
||||
|
||||
/// Asset tags.
|
||||
bool loadAssetTags( ModuleDefinition* pModuleDefinition );
|
||||
bool saveAssetTags( void );
|
||||
bool restoreAssetTags( void );
|
||||
inline AssetTagsManifest* getAssetTags( void ) const { return mAssetTagsManifest; }
|
||||
|
||||
/// Info.
|
||||
inline U32 getDeclaredAssetCount( void ) const { return (U32)mDeclaredAssets.size(); }
|
||||
inline U32 getReferencedAssetCount( void ) const { return (U32)mReferencedAssets.size(); }
|
||||
inline U32 getLoadedInternalAssetCount( void ) const { return mLoadedInternalAssetsCount; }
|
||||
inline U32 getLoadedExternalAssetCount( void ) const { return mLoadedExternalAssetsCount; }
|
||||
inline U32 getLoadedPrivateAssetCount( void ) const { return mLoadedPrivateAssetsCount; }
|
||||
inline U32 getMaxLoadedInternalAssetCount( void ) const { return mMaxLoadedInternalAssetsCount; }
|
||||
inline U32 getMaxLoadedExternalAssetCount( void ) const { return mMaxLoadedExternalAssetsCount; }
|
||||
inline U32 getMaxLoadedPrivateAssetCount( void ) const { return mMaxLoadedPrivateAssetsCount; }
|
||||
void dumpDeclaredAssets( void ) const;
|
||||
|
||||
/// Total acquired asset references.
|
||||
inline void acquireAcquiredReferenceCount( void ) { mAcquiredReferenceCount++; }
|
||||
inline void releaseAcquiredReferenceCount( void ) { AssertFatal( mAcquiredReferenceCount != 0, "AssetManager: Invalid acquired reference count." ); mAcquiredReferenceCount--; }
|
||||
inline U32 getAcquiredReferenceCount( void ) const { return mAcquiredReferenceCount; }
|
||||
|
||||
/// Asset queries.
|
||||
S32 findAllAssets( AssetQuery* pAssetQuery, const bool ignoreInternal = true, const bool ignorePrivate = true );
|
||||
S32 findAssetName( AssetQuery* pAssetQuery, const char* pAssetName, const bool partialName = false );
|
||||
S32 findAssetCategory( AssetQuery* pAssetQuery, const char* pAssetCategory, const bool assetQueryAsSource = false );
|
||||
S32 findAssetAutoUnload( AssetQuery* pAssetQuery, const bool assetAutoUnload, const bool assetQueryAsSource = false );
|
||||
S32 findAssetInternal( AssetQuery* pAssetQuery, const bool assetInternal, const bool assetQueryAsSource = false );
|
||||
S32 findAssetPrivate( AssetQuery* pAssetQuery, const bool assetPrivate, const bool assetQueryAsSource = false );
|
||||
S32 findAssetType( AssetQuery* pAssetQuery, const char* pAssetType, const bool assetQueryAsSource = false );
|
||||
S32 findAssetDependsOn( AssetQuery* pAssetQuery, const char* pAssetId );
|
||||
S32 findAssetIsDependedOn( AssetQuery* pAssetQuery, const char* pAssetId );
|
||||
S32 findInvalidAssetReferences( AssetQuery* pAssetQuery );
|
||||
S32 findTaggedAssets( AssetQuery* pAssetQuery, const char* pAssetTagNames, const bool assetQueryAsSource = false );
|
||||
S32 findAssetLooseFile( AssetQuery* pAssetQuery, const char* pLooseFile, const bool assetQueryAsSource = false );
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT( AssetManager );
|
||||
|
||||
private:
|
||||
bool scanDeclaredAssets( const char* pPath, const char* pExtension, const bool recurse, ModuleDefinition* pModuleDefinition );
|
||||
bool scanReferencedAssets( const char* pPath, const char* pExtension, const bool recurse );
|
||||
AssetDefinition* findAsset( const char* pAssetId );
|
||||
void addReferencedAsset( StringTableEntry assetId, StringTableEntry referenceFilePath );
|
||||
void renameAssetReferences( StringTableEntry assetIdFrom, StringTableEntry assetIdTo );
|
||||
void removeAssetReferences( StringTableEntry assetId );
|
||||
void renameAssetDependencies( StringTableEntry assetIdFrom, StringTableEntry assetIdTo );
|
||||
void removeAssetDependencies( const char* pAssetId );
|
||||
void removeAssetLooseFiles( const char* pAssetId );
|
||||
void unloadAsset( AssetDefinition* pAssetDefinition );
|
||||
|
||||
/// Module callbacks.
|
||||
virtual void onModulePreLoad( ModuleDefinition* pModuleDefinition );
|
||||
virtual void onModulePreUnload( ModuleDefinition* pModuleDefinition );
|
||||
virtual void onModulePostUnload( ModuleDefinition* pModuleDefinition );
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern AssetManager AssetDatabase;
|
||||
|
||||
#endif // _ASSET_MANAGER_H_
|
||||
811
Engine/source/assets/assetManager_ScriptBinding.h
Normal file
811
Engine/source/assets/assetManager_ScriptBinding.h
Normal file
|
|
@ -0,0 +1,811 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 "assetBase.h"
|
||||
#include "assetManager.h"
|
||||
#include "module/moduleDefinition.h"
|
||||
#include "console/sim.h"
|
||||
|
||||
DefineEngineMethod(AssetManager, compileReferencedAssets, bool, (const char* moduleDefinition), (""),
|
||||
"Compile the referenced assets determined by the specified module definition.\n"
|
||||
"@param moduleDefinition The module definition specifies the asset manifest.\n"
|
||||
"@return Whether the compilation was successful or not.\n")
|
||||
{
|
||||
// Fetch module definition.
|
||||
ModuleDefinition* pModuleDefinition;
|
||||
Sim::findObject(moduleDefinition, pModuleDefinition);
|
||||
|
||||
// Did we find the module definition?
|
||||
if ( pModuleDefinition == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::compileReferencedAssets() - Could not find the module definition '%s'.", moduleDefinition);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compile referenced assets.
|
||||
return object->compileReferencedAssets( pModuleDefinition );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, addModuleDeclaredAssets, bool, (const char* moduleDefinition), (""),
|
||||
"Add any the declared assets specified by the module definition.\n"
|
||||
"@param moduleDefinition The module definition specifies the asset manifest.\n"
|
||||
"@return Whether adding declared assets was successful or not.\n")
|
||||
{
|
||||
// Fetch module definition.
|
||||
ModuleDefinition* pModuleDefinition;
|
||||
Sim::findObject(moduleDefinition, pModuleDefinition);
|
||||
|
||||
// Did we find the module definition?
|
||||
if ( pModuleDefinition == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::addDeclaredAssets() - Could not find the module definition '%s'.", moduleDefinition);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add module declared assets.
|
||||
return object->addModuleDeclaredAssets( pModuleDefinition );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, addDeclaredAsset, bool, (const char* moduleDefinition, const char* assetFilePath), ("", ""),
|
||||
"Add the specified asset against the specified module definition.\n"
|
||||
"@param moduleDefinition The module definition that may contain declared assets.\n"
|
||||
"@return Whether adding declared assets was successful or not.\n")
|
||||
{
|
||||
// Fetch module definition.
|
||||
ModuleDefinition* pModuleDefinition;
|
||||
Sim::findObject(moduleDefinition, pModuleDefinition);
|
||||
|
||||
// Did we find the module definition?
|
||||
if ( pModuleDefinition == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::addDeclaredAsset() - Could not find the module definition '%s'.", moduleDefinition);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fetch asset file-path.
|
||||
const char* pAssetFilePath = assetFilePath;
|
||||
|
||||
// Add declared asset.
|
||||
return object->addDeclaredAsset( pModuleDefinition, pAssetFilePath );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, addPrivateAsset, String, (const char* assetObject), (""),
|
||||
"Adds a private asset object.\n"
|
||||
"@param assetObject The asset object to add as a private asset.\n"
|
||||
"@return The allocated private asset Id.\n")
|
||||
{
|
||||
// Fetch asset.
|
||||
AssetBase* pAssetBase;
|
||||
Sim::findObject(assetObject, pAssetBase);
|
||||
|
||||
// Did we find the asset?
|
||||
if ( pAssetBase == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::addPrivateAsset() - Could not find the asset '%s'.", assetObject);
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
// Add private asset.
|
||||
return object->addPrivateAsset( pAssetBase );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, removeDeclaredAssets, bool, (const char* moduleDefinition), (""),
|
||||
"Remove any the declared assets specified by the module definition.\n"
|
||||
"@param moduleDefinition The module definition that may contain declared assets.\n"
|
||||
"@return Whether removing declared assets was successful or not.\n")
|
||||
{
|
||||
// Fetch module definition.
|
||||
ModuleDefinition* pModuleDefinition;
|
||||
Sim::findObject(moduleDefinition, pModuleDefinition);
|
||||
|
||||
// Did we find the module definition?
|
||||
if ( pModuleDefinition == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::removeDeclaredAssets() - Could not find the module definition '%s'.", moduleDefinition);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove declared assets.
|
||||
return object->removeDeclaredAssets( pModuleDefinition );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, removeDeclaredAsset, bool, (const char* assetId), (""),
|
||||
"Remove the specified declared asset Id.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return Whether removing the declared asset was successful or not.\n")
|
||||
{
|
||||
// Remove the declared asset Id.
|
||||
return object->removeDeclaredAsset(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getAssetName, String, (const char* assetId), (""),
|
||||
"Gets the asset name from the specified asset Id.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return The asset name from the specified asset Id.\n")
|
||||
{
|
||||
return object->getAssetName(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getAssetDescription, String, (const char* assetId), (""),
|
||||
"Gets the asset description from the specified asset Id.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return The asset description from the specified asset Id.\n")
|
||||
{
|
||||
return object->getAssetDescription(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getAssetCategory, String, (const char* assetId), (""),
|
||||
"Gets the asset category from the specified asset Id.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return The asset category from the specified asset Id.\n")
|
||||
{
|
||||
return object->getAssetCategory(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getAssetType, String, (const char* assetId), (""),
|
||||
"Gets the asset type from the specified asset Id.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return The asset type from the specified asset Id.\n")
|
||||
{
|
||||
return object->getAssetType(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getAssetFilePath, String, (const char* assetId), (""),
|
||||
"Gets the asset file-path from the specified asset Id.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return The asset file - path from the specified asset Id.\n")
|
||||
{
|
||||
return object->getAssetFilePath(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getAssetPath, String, (const char* assetId), (""),
|
||||
"Gets the asset path (not including the asset file) from the specified asset Id.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return The asset path(not including the asset file) from the specified asset Id.\n")
|
||||
{
|
||||
return object->getAssetPath(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getAssetModule, String, (const char* assetId), (""),
|
||||
"Gets the module definition where the the specified asset Id is located.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return The module definition where the the specified asset Id is located.\n")
|
||||
{
|
||||
// Fetch module definition.
|
||||
ModuleDefinition* pModuleDefinition = object->getAssetModuleDefinition(assetId);
|
||||
|
||||
return pModuleDefinition == NULL ? StringTable->EmptyString() : pModuleDefinition->getIdString();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, isAssetInternal, bool, (const char* assetId), (""),
|
||||
"Check whether the specified asset Id is internal or not.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return Whether the specified asset Id is internal or not.\n")
|
||||
{
|
||||
return object->isAssetInternal(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, isAssetPrivate, bool, (const char* assetId), (""),
|
||||
"Check whether the specified asset Id is private or not.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return Whether the specified asset Id is private or not.\n")
|
||||
{
|
||||
return object->isAssetPrivate(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, isAssetAutoUnload, bool, (const char* assetId), (""),
|
||||
"Check whether the specified asset Id is auto - unload or not.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return Whether the specified asset Id is auto-unload or not.\n")
|
||||
{
|
||||
return object->isAssetAutoUnload(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, isAssetLoaded, bool, (const char* assetId), (""),
|
||||
"Check whether the specified asset Id is loaded or not.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return Whether the specified asset Id is loaded or not.\n")
|
||||
{
|
||||
return object->isAssetLoaded(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, isDeclaredAsset, bool, (const char* assetId), (""),
|
||||
"Check whether the specified asset Id is declared or not.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return Whether the specified asset Id is declared or not.\n")
|
||||
{
|
||||
return object->isDeclaredAsset(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, isReferencedAsset, bool, (const char* assetId), (""),
|
||||
"Check whether the specified asset Id is referenced or not.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return Whether the specified asset Id is referenced or not.\n")
|
||||
{
|
||||
return object->isReferencedAsset(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, renameDeclaredAsset, bool, (const char* assetIdFrom, const char* assetIdTo), ("", ""),
|
||||
"Rename declared asset Id.\n"
|
||||
"@param assetIdFrom The selected asset Id to rename from.\n"
|
||||
"@param assetIdFrom The selected asset Id to rename to.\n"
|
||||
"@return Whether the rename was successful or not.\n")
|
||||
{
|
||||
return object->renameDeclaredAsset(assetIdFrom, assetIdTo);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, renameReferencedAsset, bool, (const char* assetIdFrom, const char* assetIdTo), ("", ""),
|
||||
"Rename referenced asset Id. \n"
|
||||
"@param assetIdFrom The selected asset Id to rename from.\n"
|
||||
"@param assetIdFrom The selected asset Id to rename to.\n"
|
||||
"@return Whether the rename was successful or not.\n")
|
||||
{
|
||||
return object->renameReferencedAsset(assetIdFrom, assetIdTo);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, acquireAsset, String, (const char* assetId, bool asPrivate), ("", false),
|
||||
"Acquire the specified asset Id.\n"
|
||||
"You must release the asset once you're finish with it using 'releaseAsset'.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@param asPrivate Whether to acquire the asset Id as a private asset.\n"
|
||||
"@return The acquired asset or NULL if not acquired.\n")
|
||||
{
|
||||
// Fetch asset Id.
|
||||
const char* pAssetId = assetId;
|
||||
|
||||
// Reset asset reference.
|
||||
AssetBase* pAssetBase = NULL;
|
||||
|
||||
// Acquire private asset?
|
||||
if ( asPrivate )
|
||||
{
|
||||
// Acquire private asset.
|
||||
pAssetBase = object->acquireAsPrivateAsset<AssetBase>( pAssetId );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Acquire public asset.
|
||||
pAssetBase = object->acquireAsset<AssetBase>( pAssetId );
|
||||
}
|
||||
|
||||
return pAssetBase != NULL ? pAssetBase->getIdString() : StringTable->EmptyString();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, releaseAsset, bool, (const char* assetId), (""),
|
||||
"Release the specified asset Id.\n"
|
||||
"The asset should have been acquired using 'acquireAsset'.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return Whether the asset was released or not.\n")
|
||||
{
|
||||
// Release asset.
|
||||
return object->releaseAsset(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, purgeAssets, void, (),,
|
||||
"Purge all assets that are not referenced even if they are set to not auto-unload.\n"
|
||||
"Assets can be in this state because they are either set to not auto-unload or the asset manager has/is disabling auto-unload.\n"
|
||||
"@return No return value.\n")
|
||||
{
|
||||
// Purge assets.
|
||||
object->purgeAssets();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, deleteAsset, bool, (const char* assetId, bool deleteLooseFiles, bool deleteDependencies), ("", false, false),
|
||||
"Deletes the specified asset Id and optionally its loose files and asset dependencies.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@param deleteLooseFiles Whether to delete an assets loose files or not.\n"
|
||||
"@param deleteDependencies Whether to delete assets that depend on this asset or not.\n"
|
||||
"@return Whether the asset deletion was successful or not. A failure only indicates that the specified asset was not deleted but dependent assets and their loose files may have being deleted.\n")
|
||||
{
|
||||
// Fetch asset Id.
|
||||
const char* pAssetId = assetId;
|
||||
|
||||
// Delete asset.
|
||||
return object->deleteAsset( pAssetId, deleteLooseFiles, deleteDependencies );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, refreshAsset, void, (const char* assetId), (""),
|
||||
"Refresh the specified asset Id.\n"
|
||||
"@param assetId The selected asset Id.\n"
|
||||
"@return No return value.\n")
|
||||
{
|
||||
object->refreshAsset(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, refreshAllAssets, void, (bool includeUnloaded), (false),
|
||||
"Refresh all declared assets.\n"
|
||||
"@param Whether to include currently unloaded assets in the refresh or not. Optional: Defaults to false.\n"
|
||||
"Refreshing all assets can be an expensive (time-consuming) operation to perform.\n"
|
||||
"@return No return value.\n")
|
||||
{
|
||||
// Refresh assets
|
||||
object->refreshAllAssets(includeUnloaded);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, saveAssetTags, bool, (),,
|
||||
"Save the currently loaded asset tags manifest.\n"
|
||||
"@return Whether the save was successful or not.\n")
|
||||
{
|
||||
// Save asset tags.
|
||||
return object->saveAssetTags();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, restoreAssetTags, bool, (),,
|
||||
"Restore the currently loaded asset tags manifest from disk (replace anything in memory).\n"
|
||||
"@return Whether the restore was successful or not.\n")
|
||||
{
|
||||
// Restore asset tags.
|
||||
return object->restoreAssetTags();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getAssetTags, S32, (), ,
|
||||
"Gets the currently loaded asset tags manifest.\n"
|
||||
"@return The currently loaded asset tags manifest or zero if not loaded.\n")
|
||||
{
|
||||
// Fetch the asset tags manifest.
|
||||
AssetTagsManifest* pAssetTagsManifest = object->getAssetTags();
|
||||
|
||||
return pAssetTagsManifest == NULL ? 0 : pAssetTagsManifest->getId();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAllAssets, S32, (const char* assetQuery, bool ignoreInternal, bool ignorePrivate), ("", true, true),
|
||||
"Performs an asset query searching for all assets optionally ignoring internal assets.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param ignoreInternal Whether to ignore internal assets or not. Optional: Defaults to true.\n"
|
||||
"@param ignorePrivate Whether to ignore private assets or not. Optional: Defaults to true.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAllAssets() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Perform query.
|
||||
return object->findAllAssets( pAssetQuery, ignoreInternal, ignorePrivate );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAssetName, S32, (const char* assetQuery, const char* assetName, bool partialName), ("", "", false),
|
||||
"Performs an asset query searching for the specified asset name.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetName The asset name to search for. This may be a partial name if 'partialName' is true.\n"
|
||||
"@param partialName Whether the asset name is to be used as a partial name or not. Optional: Defaults to false.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAssetName() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Fetch asset name.
|
||||
const char* pAssetName = assetName;
|
||||
|
||||
// Perform query.
|
||||
return object->findAssetName( pAssetQuery, pAssetName, partialName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAssetCategory, S32, (const char* assetQuery, const char* assetCategory, bool assetQueryAsSource), ("", "", false),
|
||||
"Performs an asset query searching for the specified asset category.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetCategory The asset category to search for.\n"
|
||||
"@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAssetCategory() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Fetch asset category.
|
||||
const char* pAssetCategory = assetCategory;
|
||||
|
||||
// Perform query.
|
||||
return object->findAssetCategory( pAssetQuery, pAssetCategory, assetQueryAsSource );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAssetAutoUnload, S32, (const char* assetQuery, bool assetAutoUnload, bool assetQueryAsSource), ("", false, false),
|
||||
"Performs an asset query searching for the specified asset auto-unload flag.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetInternal The asset internal flag to search for.\n"
|
||||
"@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAssetAutoUnload() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Perform query.
|
||||
return object->findAssetAutoUnload( pAssetQuery, assetAutoUnload, assetQueryAsSource );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAssetInternal, S32, (const char* assetQuery, bool assetInternal, bool assetQueryAsSource), ("", false, false),
|
||||
"Performs an asset query searching for the specified asset internal flag.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetInternal The asset internal flag to search for.\n"
|
||||
"@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAssetInternal() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Perform query.
|
||||
return object->findAssetInternal( pAssetQuery, assetInternal, assetQueryAsSource );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAssetPrivate, S32, (const char* assetQuery, bool assetPrivate, bool assetQueryAsSource), ("", false, false),
|
||||
"Performs an asset query searching for the specified asset private flag.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetPrivate The asset private flag to search for.\n"
|
||||
"@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAssetPrivate() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Perform query.
|
||||
return object->findAssetInternal( pAssetQuery, assetPrivate, assetQueryAsSource );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAssetType, S32, (const char* assetQuery, const char* assetType, bool assetQueryAsSource), ("", "", false),
|
||||
"Performs an asset query searching for the specified asset type.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetType The asset type to search for.\n"
|
||||
"@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAssetType() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Fetch asset type.
|
||||
const char* pAssetType = assetType;
|
||||
|
||||
// Perform query.
|
||||
return object->findAssetType( pAssetQuery, pAssetType, assetQueryAsSource );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAssetDependsOn, S32, (const char* assetQuery, const char* assetId), ("", ""),
|
||||
"Performs an asset query searching for asset Ids that the specified asset Id depends on.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetId The asset Id to query for any asset Ids that it depends on.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAssetDependsOn() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Fetch asset Id.
|
||||
const char* pAssetId = assetId;
|
||||
|
||||
// Perform query.
|
||||
return object->findAssetDependsOn( pAssetQuery, pAssetId );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAssetIsDependedOn, S32, (const char* assetQuery, const char* assetId), ("", ""),
|
||||
"Performs an asset query searching for asset Ids that depend on the specified asset Id.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetId The asset Id to query for any asset Ids that may depend on it.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAssetIsDependedOn() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Fetch asset Id.
|
||||
const char* pAssetId = assetId;
|
||||
|
||||
// Perform query.
|
||||
return object->findAssetIsDependedOn( pAssetQuery, pAssetId );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findInvalidAssetReferences, S32, (const char* assetQuery), (""),
|
||||
"Performs an asset query searching for invalid asset references.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@return The number of asset Ids found that are invalid or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findInvalidAssetReferences() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Perform query.
|
||||
return object->findInvalidAssetReferences( pAssetQuery );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findTaggedAssets, S32, (const char* assetQuery, const char* assetTagNames, bool assetQueryAsSource), ("", "", false),
|
||||
"Performs an asset query searching for the specified asset tag name(s).\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetTagNames The asset tag name or names to search for. Multiple names can be specified using comma, space, tab or newline separation. Tags use an OR operation i.e. only assets tagged with ANY of the specified tags will be returned.\n"
|
||||
"@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findTaggedAssets() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Fetch asset tag name(s).
|
||||
const char* pAssetTagNames = assetTagNames;
|
||||
|
||||
// Perform query.
|
||||
return object->findTaggedAssets( pAssetQuery, pAssetTagNames, assetQueryAsSource );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, findAssetLooseFile, S32, (const char* assetQuery, const char* assetLooseFile, bool assetQueryAsSource), ("", "", false),
|
||||
"Performs an asset query searching for the specified loose file.\n"
|
||||
"@param assetQuery The asset query object that will be populated with the results.\n"
|
||||
"@param assetLooseFile The loose-file used by the asset to search for.\n"
|
||||
"@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
|
||||
"@return The number of asset Ids found or (-1) if an error occurred.\n")
|
||||
{
|
||||
// Fetch asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
Sim::findObject(assetQuery, pAssetQuery);
|
||||
|
||||
// Did we find the asset query?
|
||||
if ( pAssetQuery == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetManager::findAssetLooseFile() - Could not find the asset query object '%s'.", assetQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Fetch asset loose file.
|
||||
const char* pAssetLooseFile = assetLooseFile;
|
||||
|
||||
// Perform query.
|
||||
return object->findAssetLooseFile( pAssetQuery, pAssetLooseFile, assetQueryAsSource );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getDeclaredAssetCount, bool, (),,
|
||||
"Gets the number of declared assets.\n"
|
||||
"@return Returns the number of declared assets.\n")
|
||||
{
|
||||
return object->getDeclaredAssetCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getReferencedAssetCount, bool, (), ,
|
||||
"Gets the number of asset referenced.\n"
|
||||
"@return Returns the number of asset references.\n")
|
||||
{
|
||||
return object->getReferencedAssetCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getLoadedInternalAssetCount, bool, (), ,
|
||||
"Gets the number of loaded internal assets.\n"
|
||||
"@return Returns the number of loaded internal assets.\n")
|
||||
{
|
||||
return object->getLoadedInternalAssetCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getMaxLoadedInternalAssetCount, bool, (), ,
|
||||
"Gets the maximum number of loaded internal assets.\n"
|
||||
"@return Returns the maximum number of loaded internal assets.\n")
|
||||
{
|
||||
return object->getMaxLoadedInternalAssetCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getLoadedExternalAssetCount, bool, (), ,
|
||||
"Gets the number of loaded external assets.\n"
|
||||
"@return Returns the number of loaded external assets.\n")
|
||||
{
|
||||
return object->getLoadedExternalAssetCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, getMaxLoadedExternalAssetCount, bool, (), ,
|
||||
"Gets the maximum number of loaded external assets.\n"
|
||||
"@return Returns the maximum number of loaded external assets.\n")
|
||||
{
|
||||
return object->getMaxLoadedExternalAssetCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetManager, dumpDeclaredAssets, void, (), ,
|
||||
"Dumps a breakdown of all declared assets.\n"
|
||||
"@return No return value.\n")
|
||||
{
|
||||
return object->dumpDeclaredAssets();
|
||||
}
|
||||
184
Engine/source/assets/assetPtr.h
Normal file
184
Engine/source/assets/assetPtr.h
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_PTR_H_
|
||||
#define _ASSET_PTR_H_
|
||||
|
||||
#ifndef _ASSET_MANAGER_H_
|
||||
#include "assetManager.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AssetPtrCallback
|
||||
{
|
||||
friend class AssetManager;
|
||||
|
||||
protected:
|
||||
virtual void onAssetRefreshed( AssetPtrBase* pAssetPtrBase ) = 0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AssetPtrBase
|
||||
{
|
||||
public:
|
||||
AssetPtrBase() {};
|
||||
virtual ~AssetPtrBase()
|
||||
{
|
||||
// Un-register any notifications.
|
||||
unregisterRefreshNotify();
|
||||
};
|
||||
|
||||
/// Referencing.
|
||||
virtual void clear( void ) = 0;
|
||||
virtual void setAssetId( const char* pAssetId ) = 0;
|
||||
virtual StringTableEntry getAssetId( void ) const = 0;
|
||||
virtual StringTableEntry getAssetType( void ) const = 0;
|
||||
virtual bool isAssetId( const char* pAssetId ) const = 0;
|
||||
|
||||
/// Validity.
|
||||
virtual bool isNull( void ) const = 0;
|
||||
virtual bool notNull( void ) const = 0;
|
||||
|
||||
/// Notification.
|
||||
inline void registerRefreshNotify( AssetPtrCallback* pCallback )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( AssetDatabase.isProperlyAdded(), "AssetPtrBase::registerRefreshNotify() - Cannot register an asset pointer with the asset system." );
|
||||
|
||||
// register refresh notify.
|
||||
AssetDatabase.registerAssetPtrRefreshNotify( this, pCallback );
|
||||
}
|
||||
|
||||
void unregisterRefreshNotify( void )
|
||||
{
|
||||
// Un-register the refresh notify if the asset system is available.
|
||||
if ( AssetDatabase.isProperlyAdded() )
|
||||
AssetDatabase.unregisterAssetPtrRefreshNotify( this );
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<typename T> class AssetPtr : public AssetPtrBase
|
||||
{
|
||||
private:
|
||||
SimObjectPtr<T> mpAsset;
|
||||
|
||||
public:
|
||||
AssetPtr() {}
|
||||
AssetPtr( const char* pAssetId )
|
||||
{
|
||||
// Finish if this is an invalid asset Id.
|
||||
if ( pAssetId == NULL || *pAssetId == 0 )
|
||||
return;
|
||||
|
||||
// Acquire asset.
|
||||
mpAsset = AssetDatabase.acquireAsset<T>( pAssetId );
|
||||
}
|
||||
AssetPtr( const AssetPtr<T>& assetPtr )
|
||||
{
|
||||
// Does the asset pointer have an asset?
|
||||
if ( assetPtr.notNull() )
|
||||
{
|
||||
// Yes, so acquire the asset.
|
||||
mpAsset = AssetDatabase.acquireAsset<T>( assetPtr->getAssetId() );
|
||||
}
|
||||
}
|
||||
virtual ~AssetPtr()
|
||||
{
|
||||
// Do we have an asset?
|
||||
if ( notNull() )
|
||||
{
|
||||
// Yes, so release it.
|
||||
AssetDatabase.releaseAsset( mpAsset->getAssetId() );
|
||||
}
|
||||
}
|
||||
|
||||
/// Assignment.
|
||||
AssetPtr<T>& operator=( const char* pAssetId )
|
||||
{
|
||||
// Do we have an asset?
|
||||
if ( notNull() )
|
||||
{
|
||||
// Yes, so finish if the asset Id is already assigned.
|
||||
if ( isAssetId( pAssetId ) )
|
||||
return *this;
|
||||
|
||||
// No, so release it.
|
||||
AssetDatabase.releaseAsset( mpAsset->getAssetId() );
|
||||
}
|
||||
|
||||
// Is the asset Id at least okay to attempt to acquire the asset?
|
||||
if ( pAssetId != NULL && *pAssetId != 0 )
|
||||
{
|
||||
// Yes, so acquire the asset.
|
||||
mpAsset = AssetDatabase.acquireAsset<T>( pAssetId );
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, so remove reference.
|
||||
mpAsset = NULL;
|
||||
}
|
||||
|
||||
// Return Reference.
|
||||
return *this;
|
||||
}
|
||||
|
||||
AssetPtr<T>& operator=( const AssetPtr<T>& assetPtr )
|
||||
{
|
||||
// Set asset pointer.
|
||||
*this = assetPtr->getAssetId();
|
||||
|
||||
// Return Reference.
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Referencing.
|
||||
virtual void clear( void )
|
||||
{
|
||||
// Do we have an asset?
|
||||
if ( notNull() )
|
||||
{
|
||||
// Yes, so release it.
|
||||
AssetDatabase.releaseAsset( mpAsset->getAssetId() );
|
||||
}
|
||||
|
||||
// Reset the asset reference.
|
||||
mpAsset = NULL;
|
||||
}
|
||||
|
||||
T* operator->( void ) const { return mpAsset; }
|
||||
T& operator*( void ) const { return *mpAsset; }
|
||||
operator T*( void ) const { return mpAsset; }
|
||||
virtual void setAssetId( const char* pAssetId ) { *this = pAssetId; }
|
||||
virtual StringTableEntry getAssetId( void ) const { return isNull() ? StringTable->EmptyString() : mpAsset->getAssetId(); }
|
||||
virtual StringTableEntry getAssetType(void) const { return isNull() ? StringTable->EmptyString() : mpAsset->getClassName(); }
|
||||
virtual bool isAssetId( const char* pAssetId ) const { return pAssetId == NULL ? isNull() : getAssetId() == StringTable->insert(pAssetId); }
|
||||
|
||||
/// Validity.
|
||||
virtual bool isNull( void ) const { return mpAsset.isNull(); }
|
||||
virtual bool notNull( void ) const { return !mpAsset.isNull(); }
|
||||
};
|
||||
|
||||
#endif // _ASSET_PTR_H_
|
||||
121
Engine/source/assets/assetQuery.cpp
Normal file
121
Engine/source/assets/assetQuery.cpp
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_QUERY_H_
|
||||
#include "assetQuery.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TAML_CUSTOM_H_
|
||||
#include "persistence/taml/tamlCustom.h"
|
||||
#endif
|
||||
|
||||
// Script bindings.
|
||||
#include "assetQuery_ScriptBinding.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT( AssetQuery );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetQuery::initPersistFields()
|
||||
{
|
||||
// Call parent.
|
||||
Parent::initPersistFields();
|
||||
|
||||
addProtectedField("Count", TypeS32, 0, &defaultProtectedSetFn, &getCount, &writeCount, "Gets the number of results in the asset query.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetQuery::onTamlCustomWrite( TamlCustomNodes& customNodes )
|
||||
{
|
||||
// Call parent.
|
||||
Parent::onTamlCustomWrite( customNodes );
|
||||
|
||||
// Add node.
|
||||
TamlCustomNode* pCustomNode = customNodes.addNode( ASSETQUERY_RESULTS_NODE_NAME );
|
||||
|
||||
// Finish if no assets.
|
||||
if (mAssetList.size() == 0)
|
||||
return;
|
||||
|
||||
// Iterate asset.
|
||||
for (Vector<StringTableEntry>::iterator assetItr = mAssetList.begin(); assetItr != mAssetList.end(); ++assetItr)
|
||||
{
|
||||
// Add asset node.
|
||||
TamlCustomNode* pAssetNode = pCustomNode->addNode( ASSETQUERY_ASSETNODE_NAME );
|
||||
|
||||
// Add field.
|
||||
pAssetNode->addField( ASSETQUERY_ASSETID_FIELD_NAME, *assetItr );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetQuery::onTamlCustomRead( const TamlCustomNodes& customNodes )
|
||||
{
|
||||
// Call parent.
|
||||
Parent::onTamlCustomRead( customNodes );
|
||||
|
||||
// Find custom node name.
|
||||
const TamlCustomNode* pResultsNode = customNodes.findNode( ASSETQUERY_RESULTS_NODE_NAME );
|
||||
|
||||
// Finish if we don't have a results name.
|
||||
if ( pResultsNode == NULL )
|
||||
return;
|
||||
|
||||
// Fetch node name.
|
||||
StringTableEntry assetNodeName = StringTable->insert( ASSETQUERY_ASSETNODE_NAME );
|
||||
|
||||
// Fetch children asset nodes.
|
||||
const TamlCustomNodeVector& assetNodes = pResultsNode->getChildren();
|
||||
|
||||
// Iterate asset nodes.
|
||||
for( TamlCustomNodeVector::const_iterator assetNodeItr = assetNodes.begin(); assetNodeItr != assetNodes.end(); ++assetNodeItr )
|
||||
{
|
||||
// Fetch asset node.
|
||||
const TamlCustomNode* pAssetNode = *assetNodeItr;
|
||||
|
||||
// Skip if an unknown node name.
|
||||
if ( pAssetNode->getNodeName() != assetNodeName )
|
||||
continue;
|
||||
|
||||
// Fetch field.
|
||||
const TamlCustomField* pField = pAssetNode->findField( ASSETQUERY_ASSETID_FIELD_NAME );
|
||||
|
||||
// Do we find the field?
|
||||
if ( pField == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "AssetQuery::onTamlCustomRead() - Could not find '%s' field.", ASSETQUERY_ASSETID_FIELD_NAME );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Store asset.
|
||||
mAssetList.push_back(pField->getFieldValue());
|
||||
}
|
||||
}
|
||||
90
Engine/source/assets/assetQuery.h
Normal file
90
Engine/source/assets/assetQuery.h
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_QUERY_H_
|
||||
#define _ASSET_QUERY_H_
|
||||
|
||||
#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
|
||||
|
||||
#ifndef _TAML_CUSTOM_H_
|
||||
#include "persistence/taml/tamlCustom.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define ASSETQUERY_RESULTS_NODE_NAME "Results"
|
||||
#define ASSETQUERY_ASSETNODE_NAME "Asset"
|
||||
#define ASSETQUERY_ASSETID_FIELD_NAME "AssetId"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AssetQuery : public SimObject
|
||||
{
|
||||
private:
|
||||
typedef SimObject Parent;
|
||||
|
||||
protected:
|
||||
virtual void onTamlCustomWrite( TamlCustomNodes& customNodes );
|
||||
virtual void onTamlCustomRead( const TamlCustomNodes& customNodes );
|
||||
|
||||
static const char* getCount(void* obj, const char* data) { return Con::getIntArg(static_cast<AssetQuery*>(obj)->mAssetList.size()); }
|
||||
static bool writeCount( void* obj, StringTableEntry pFieldName ) { return false; }
|
||||
|
||||
public:
|
||||
AssetQuery() {}
|
||||
virtual ~AssetQuery() {}
|
||||
|
||||
/// SimObject overrides
|
||||
static void initPersistFields();
|
||||
|
||||
Vector<StringTableEntry> mAssetList;
|
||||
|
||||
/// Whether asset is contained or not.
|
||||
inline bool containsAsset( StringTableEntry assetId )
|
||||
{
|
||||
for (Vector<StringTableEntry>::const_iterator assetItr = mAssetList.begin(); assetItr != mAssetList.end(); ++assetItr)
|
||||
{
|
||||
if ( *assetItr == assetId )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Set assets.
|
||||
inline void set( const AssetQuery& assetQuery ) { this->mAssetList = assetQuery.mAssetList; }
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT( AssetQuery );
|
||||
};
|
||||
|
||||
#endif // _ASSET_QUERY_H_
|
||||
|
||||
85
Engine/source/assets/assetQuery_ScriptBinding.h
Normal file
85
Engine/source/assets/assetQuery_ScriptBinding.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_QUERY_H_
|
||||
#include "assets/assetQuery.h"
|
||||
#endif
|
||||
|
||||
#include "console/engineAPI.h"
|
||||
|
||||
DefineConsoleMethod(AssetQuery, clear, void, (),,"Clears all asset Id results."
|
||||
"Clears all asset Id results.\n"
|
||||
"@return () No return value.\n")
|
||||
{
|
||||
object->mAssetList.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
DefineConsoleMethod(AssetQuery, set, bool, (S32 queryId), ,
|
||||
"Sets the asset query to a copy of the specified asset query.\n"
|
||||
"@param assetQuery The asset query to copy.\n"
|
||||
"@return Whether the operation succeeded or not.\n")
|
||||
{
|
||||
// Find asset query.
|
||||
AssetQuery* pAssetQuery;
|
||||
|
||||
if (!Sim::findObject(queryId, pAssetQuery))
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetQuery::set() - Could not find asset query '%i'.", queryId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set asset query.
|
||||
object->set( *pAssetQuery );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineConsoleMethod(AssetQuery, getCount, S32, (), ,
|
||||
"Gets the count of asset Id results.\n"
|
||||
"@return (int)The count of asset Id results.\n")
|
||||
{
|
||||
return object->mAssetList.size();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineConsoleMethod(AssetQuery, getAsset, const char*, (S32 resultIndex), (-1),
|
||||
"Gets the asset Id at the specified query result index.\n"
|
||||
"@param resultIndex The query result index to use.\n"
|
||||
"@return (assetId)The asset Id at the specified index or NULL if not valid.\n")
|
||||
{
|
||||
// Is index within bounds?
|
||||
if (resultIndex >= object->mAssetList.size())
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetQuery::getAsset() - Result index '%s' is out of bounds.", resultIndex);
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
return object->mAssetList[resultIndex];
|
||||
}
|
||||
564
Engine/source/assets/assetTagsManifest.cpp
Normal file
564
Engine/source/assets/assetTagsManifest.cpp
Normal file
|
|
@ -0,0 +1,564 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_TAGS_MANIFEST_H_
|
||||
#include "assetTagsManifest.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_MANAGER_H_
|
||||
#include "assetManager.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
// Script binding.
|
||||
#include "assetTagsManifest_ScriptBinding.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT( AssetTagsManifest );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
AssetTagsManifest::AssetTagsManifest()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
AssetTagsManifest::~AssetTagsManifest()
|
||||
{
|
||||
// Iterate tags.
|
||||
for( typeTagNameHash::iterator tagNameItr = mTagNameDatabase.begin(); tagNameItr != mTagNameDatabase.end(); ++tagNameItr )
|
||||
{
|
||||
// Delete asset tag.
|
||||
delete tagNameItr->value;
|
||||
}
|
||||
|
||||
// Clear database.
|
||||
mTagNameDatabase.clear();
|
||||
mAssetToTagDatabase.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry AssetTagsManifest::fetchTagName( const char* pTagName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pTagName != NULL, "Cannot use a NULL tag name." );
|
||||
|
||||
return StringTable->insert( pTagName, true );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
AssetTagsManifest::AssetTag* AssetTagsManifest::findAssetTag( const char* pTagName )
|
||||
{
|
||||
// Fetch tag name.
|
||||
StringTableEntry tagName = fetchTagName( pTagName );
|
||||
|
||||
// Finish if the tag already exists.
|
||||
typeTagNameHash::iterator tagNameItr = mTagNameDatabase.find( tagName );
|
||||
|
||||
return tagNameItr == mTagNameDatabase.end() ? NULL : tagNameItr->value;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetTagsManifest::renameAssetId( const char* pAssetIdFrom, const char* pAssetIdTo )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetIdFrom != NULL, "Cannot rename from NULL asset Id." );
|
||||
AssertFatal( pAssetIdTo != NULL, "Cannot rename to NULL asset Id." );
|
||||
|
||||
// Fetch asset Ids.
|
||||
StringTableEntry assetIdFrom = StringTable->insert( pAssetIdFrom );
|
||||
StringTableEntry assetIdTo = StringTable->insert( pAssetIdTo );
|
||||
|
||||
while( true )
|
||||
{
|
||||
// Find asset Id.
|
||||
typeAssetToTagHash::Iterator assetIdItr = mAssetToTagDatabase.find( assetIdFrom );
|
||||
|
||||
// Finish if no asset Id to rename.
|
||||
if ( assetIdItr == mAssetToTagDatabase.end() )
|
||||
return;
|
||||
|
||||
// Fetch asset tag.
|
||||
AssetTag* pAssetTag = assetIdItr->value;
|
||||
|
||||
// Untag old asset Id.
|
||||
untag( assetIdFrom, pAssetTag->mTagName );
|
||||
|
||||
// Tag new asset Id.
|
||||
tag( assetIdTo, pAssetTag->mTagName );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetTagsManifest::onTamlCustomWrite( TamlCustomNodes& customNodes )
|
||||
{
|
||||
// Call parent.
|
||||
Parent::onTamlCustomWrite( customNodes );
|
||||
|
||||
// Finish if no tags.
|
||||
if ( mTagNameDatabase.size() == 0 )
|
||||
return;
|
||||
|
||||
// Add node.
|
||||
TamlCustomNode* pTagsNode = customNodes.addNode( ASSETTAGS_TAGS_NODE_NAME );
|
||||
|
||||
// Iterate tags.
|
||||
for( typeTagNameHash::iterator tagItr = mTagNameDatabase.begin(); tagItr != mTagNameDatabase.end(); ++tagItr )
|
||||
{
|
||||
// Add tag node.
|
||||
TamlCustomNode* pTagNode = pTagsNode->addNode( ASSETTAGS_TAGS_TYPE_NAME );
|
||||
|
||||
// Add fields.
|
||||
pTagNode->addField( ASSETTAGS_TAGS_NAME_FIELD, tagItr->key );
|
||||
}
|
||||
|
||||
// Add node.
|
||||
TamlCustomNode* pAssetTagsNode = customNodes.addNode( ASSETTAGS_ASSETS_NODE_NAME );
|
||||
|
||||
// Iterate asset locations.
|
||||
for( typeAssetToTagHash::Iterator assetTagItr = mAssetToTagDatabase.begin(); assetTagItr != mAssetToTagDatabase.end(); ++assetTagItr )
|
||||
{
|
||||
// Add asset tag node.
|
||||
TamlCustomNode* pAssetNode = pAssetTagsNode->addNode( ASSETTAGS_ASSETS_TYPE_NAME );
|
||||
|
||||
// Add fields.
|
||||
pAssetNode->addField( ASSETTAGS_ASSETS_ASSETID_FIELD, assetTagItr->key );
|
||||
pAssetNode->addField( ASSETTAGS_ASSETS_TAG_FIELD, assetTagItr->value->mTagName );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AssetTagsManifest::onTamlCustomRead( const TamlCustomNodes& customNodes )
|
||||
{
|
||||
// Call parent.
|
||||
Parent::onTamlCustomRead( customNodes );
|
||||
|
||||
// Find tags nodes.
|
||||
const TamlCustomNode* pTagProperty = customNodes.findNode( ASSETTAGS_TAGS_NODE_NAME );
|
||||
|
||||
// Finish if we don't have a tags node name.
|
||||
if ( pTagProperty == NULL )
|
||||
return;
|
||||
|
||||
// Fetch node name.
|
||||
StringTableEntry tagNodeName = StringTable->insert( ASSETTAGS_TAGS_TYPE_NAME );
|
||||
|
||||
// Fetch children asset nodes.
|
||||
const TamlCustomNodeVector& tagNodes = pTagProperty->getChildren();
|
||||
|
||||
// Iterate tag nodes.
|
||||
for( TamlCustomNodeVector::const_iterator tagNodeItr = tagNodes.begin(); tagNodeItr != tagNodes.end(); ++tagNodeItr )
|
||||
{
|
||||
// Fetch tag node.
|
||||
const TamlCustomNode* pTagNode = *tagNodeItr;
|
||||
|
||||
// Skip if an unknown node name.
|
||||
if ( pTagNode->getNodeName() != tagNodeName )
|
||||
continue;
|
||||
|
||||
// Fetch "Name" field.
|
||||
const TamlCustomField* pTagNameField = pTagNode->findField( ASSETTAGS_TAGS_NAME_FIELD );
|
||||
|
||||
// Do we find the field?
|
||||
if ( pTagNameField == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "AssetTagsManifest::onTamlCustomRead() - Could not find '%s' field.", ASSETTAGS_TAGS_NAME_FIELD );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create the tag.
|
||||
createTag( pTagNameField->getFieldValue() );
|
||||
}
|
||||
|
||||
// Find asset tags node.
|
||||
const TamlCustomNode* pAssetTagProperty = customNodes.findNode( ASSETTAGS_ASSETS_NODE_NAME );
|
||||
|
||||
// Finish if we don't have an asset tags node name.
|
||||
if ( pAssetTagProperty == NULL )
|
||||
return;
|
||||
|
||||
// Fetch node name.
|
||||
StringTableEntry assetTagNodeName = StringTable->insert( ASSETTAGS_ASSETS_TYPE_NAME );
|
||||
|
||||
// Fetch children asset tag nodes.
|
||||
const TamlCustomNodeVector& assetTagNodes = pAssetTagProperty->getChildren();
|
||||
|
||||
// Iterate property alias.
|
||||
for( TamlCustomNodeVector::const_iterator assetTagNodeItr = assetTagNodes.begin(); assetTagNodeItr != assetTagNodes.end(); ++assetTagNodeItr )
|
||||
{
|
||||
// Fetch asset node.
|
||||
const TamlCustomNode* pAssetTagNode = *assetTagNodeItr;
|
||||
|
||||
// Skip if an unknown node name.
|
||||
if ( pAssetTagNode->getNodeName() != assetTagNodeName )
|
||||
continue;
|
||||
|
||||
// Fetch "AssetId" field.
|
||||
const TamlCustomField* pAssetIdField = pAssetTagNode->findField( ASSETTAGS_ASSETS_ASSETID_FIELD );
|
||||
|
||||
// Do we find the field?
|
||||
if ( pAssetIdField == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "AssetTagsManifest::onTamlCustomRead() - Could not find '%s' field.", ASSETTAGS_ASSETS_ASSETID_FIELD );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch "Tag" field.
|
||||
const TamlCustomField* pTagField = pAssetTagNode->findField( ASSETTAGS_ASSETS_TAG_FIELD );
|
||||
|
||||
// Do we find the field?
|
||||
if ( pTagField == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "AssetTagsManifest::onTamlCustomRead() - Could not find '%s' field.", ASSETTAGS_ASSETS_TAG_FIELD );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Tag the asset.
|
||||
tag( pAssetIdField->getFieldValue(), pTagField->getFieldValue() );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const AssetTagsManifest::AssetTag* AssetTagsManifest::createTag( const char* pTagName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pTagName != NULL, "Cannot use a NULL tag name." );
|
||||
|
||||
// Finish if the tag already exists.
|
||||
AssetTag* pAssetTag = findAssetTag( pTagName );
|
||||
|
||||
// Return asset tag if already created.
|
||||
if ( pAssetTag != NULL )
|
||||
return pAssetTag;
|
||||
|
||||
// Fetch tag name.
|
||||
StringTableEntry tagName = fetchTagName( pTagName );
|
||||
|
||||
// Generate the asset tag.
|
||||
pAssetTag = new AssetTag( tagName );
|
||||
|
||||
// Add the tag.
|
||||
mTagNameDatabase.insert( tagName, pAssetTag );
|
||||
|
||||
return pAssetTag;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool AssetTagsManifest::renameTag( const char* pOldTagName, const char* pNewTagName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pOldTagName != NULL, "Cannot use a NULL tag name." );
|
||||
AssertFatal( pNewTagName != NULL, "Cannot use a NULL tag name." );
|
||||
|
||||
// Find old asset tags.
|
||||
AssetTag* pOldAssetTag = findAssetTag( pOldTagName );
|
||||
|
||||
// Did we find the asset tag?
|
||||
if ( pOldAssetTag == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "AssetTagsManifest: Cannot rename tag '%s' as it does not exist.", pOldTagName );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Are the old and new tags the same?
|
||||
if ( pOldAssetTag->mTagName == fetchTagName( pNewTagName ) )
|
||||
{
|
||||
// Yes, so warn.
|
||||
Con::warnf( "AssetTagsManifest: Cannot rename tag '%s' to tag '%s' as they are the same.", pOldTagName, pNewTagName );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create new tag.
|
||||
AssetTag* pNewAssetTag = const_cast<AssetTag*>( createTag( pNewTagName ) );
|
||||
|
||||
// Transfer asset tags.
|
||||
for ( Vector<typeAssetId>::iterator assetIdItr = pOldAssetTag->mAssets.begin(); assetIdItr != pOldAssetTag->mAssets.end(); ++assetIdItr )
|
||||
{
|
||||
pNewAssetTag->mAssets.push_back( *assetIdItr );
|
||||
}
|
||||
|
||||
// Delete old tag.
|
||||
deleteTag( pOldTagName );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool AssetTagsManifest::deleteTag( const char* pTagName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pTagName != NULL, "Cannot use a NULL tag name." );
|
||||
|
||||
// Find asset tag.
|
||||
AssetTag* pAssetTag = findAssetTag( pTagName );
|
||||
|
||||
// Did we find the asset tag?
|
||||
if ( pAssetTag == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "AssetTagsManifest: Cannot delete tag '%s' as it does not exist.", pTagName );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the tag.
|
||||
mTagNameDatabase.erase( pAssetTag->mTagName );
|
||||
|
||||
// Remove the asset tags.
|
||||
for ( Vector<typeAssetId>::iterator assetIdItr = pAssetTag->mAssets.begin(); assetIdItr != pAssetTag->mAssets.end(); ++assetIdItr )
|
||||
{
|
||||
// Find asset Id tag.
|
||||
typeAssetToTagHash::Iterator assetItr = mAssetToTagDatabase.find( *assetIdItr );
|
||||
|
||||
// Iterate asset Id tags.
|
||||
while( assetItr != mAssetToTagDatabase.end() && assetItr->key == *assetIdItr )
|
||||
{
|
||||
// Is this the asset tag?
|
||||
if ( assetItr->value == pAssetTag )
|
||||
{
|
||||
// Yes, so erase it.
|
||||
mAssetToTagDatabase.erase( assetItr );
|
||||
break;
|
||||
}
|
||||
|
||||
// Next entry.
|
||||
assetItr++;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the asset tag.
|
||||
delete pAssetTag;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool AssetTagsManifest::isTag( const char* pTagName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pTagName != NULL, "Cannot use a NULL tag name." );
|
||||
|
||||
// Check whether tag exists or not.
|
||||
return findAssetTag( pTagName ) != NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry AssetTagsManifest::getTag( const U32 tagIndex )
|
||||
{
|
||||
// Finish if invalid tag count.
|
||||
AssertFatal( tagIndex < getTagCount(), "Tag index is out of bounds." );
|
||||
|
||||
// Fetch tag iterator.
|
||||
typeTagNameHash::iterator tagItr = mTagNameDatabase.begin();
|
||||
|
||||
// Find asset tag by index.
|
||||
// NOTE: Unfortunately this is slow as it's not the natural access method.
|
||||
for( U32 index = 0; index < tagIndex; ++index, ++tagItr ) {};
|
||||
|
||||
// Return tag name.
|
||||
return tagItr->value->mTagName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
U32 AssetTagsManifest::getAssetTagCount( const char* pAssetId )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetId != NULL, "Cannot use a NULL asset Id." );
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry assetId = StringTable->insert( pAssetId );
|
||||
|
||||
return (U32)mAssetToTagDatabase.count( assetId );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry AssetTagsManifest::getAssetTag( const char* pAssetId, const U32 tagIndex )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetId != NULL, "Cannot use a NULL asset Id." );
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry assetId = StringTable->insert( pAssetId );
|
||||
|
||||
// Sanity!
|
||||
AssertFatal( tagIndex < (U32)mAssetToTagDatabase.count( assetId ), "Asset tag index is out of bounds." );
|
||||
|
||||
// Find asset tag.
|
||||
typeAssetToTagHash::Iterator assetItr = mAssetToTagDatabase.find( assetId );
|
||||
|
||||
// Find asset tag by index.
|
||||
// NOTE: Unfortunately this is slow as it's not the natural access method.
|
||||
for( U32 index = 0; index < tagIndex; ++index, ++assetItr ) {};
|
||||
|
||||
// Return tag name.
|
||||
return assetItr->value->mTagName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool AssetTagsManifest::tag( const char* pAssetId, const char* pTagName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetId != NULL, "Cannot use a NULL asset Id." );
|
||||
AssertFatal( pTagName != NULL, "Cannot use a NULL tag name." );
|
||||
|
||||
// Find asset tag.
|
||||
AssetTag* pAssetTag = findAssetTag( pTagName );
|
||||
|
||||
// Does the tag exist?
|
||||
if ( pAssetTag == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetTagsManifest: Cannot tag asset Id '%s' with tag name '%s' as tag name does not exist.", pAssetId, pTagName );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is the asset Id valid?
|
||||
if ( !AssetDatabase.isDeclaredAsset( pAssetId ) )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "AssetTagsManifest::onTamlCustomRead() - Ignoring asset Id '%s' mapped to tag name '%s' as it is not a declared asset Id.", pAssetId, pTagName );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fetch asset Id.
|
||||
typeAssetId assetId = StringTable->insert( pAssetId );
|
||||
|
||||
// Find asset Id tag.
|
||||
typeAssetToTagHash::Iterator assetItr = mAssetToTagDatabase.find(assetId);
|
||||
|
||||
// Iterate asset Id tags.
|
||||
while( assetItr != mAssetToTagDatabase.end() && assetItr->key == assetId )
|
||||
{
|
||||
// Is the asset already tagged appropriately?
|
||||
if ( assetItr->value == pAssetTag )
|
||||
return true;
|
||||
|
||||
// Next entry.
|
||||
assetItr++;
|
||||
}
|
||||
|
||||
// No, so add tag.
|
||||
mAssetToTagDatabase.insertEqual( assetId, pAssetTag );
|
||||
|
||||
// Add to asset tag.
|
||||
pAssetTag->mAssets.push_back( assetId );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool AssetTagsManifest::untag( const char* pAssetId, const char* pTagName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetId != NULL, "Cannot use a NULL asset Id." );
|
||||
AssertFatal( pTagName != NULL, "Cannot use a NULL tag name." );
|
||||
|
||||
// Find asset tag.
|
||||
AssetTag* pAssetTag = findAssetTag( pTagName );
|
||||
|
||||
// Does the tag exist?
|
||||
if ( pAssetTag == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetTagsManifest: Cannot untag asset Id '%s' from tag name '%s' as tag name does not exist.", pAssetId, pTagName );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fetch asset Id.
|
||||
typeAssetId assetId = StringTable->insert( pAssetId );
|
||||
|
||||
// Is the asset tagged?
|
||||
if ( !pAssetTag->containsAsset( assetId ) )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetTagsManifest: Cannot untag asset Id '%s' from tag name '%s' as the asset is not tagged with the tag name.", pAssetId, pTagName );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove asset from assert tag.
|
||||
pAssetTag->removeAsset( assetId );
|
||||
|
||||
// Find asset Id tag.
|
||||
typeAssetToTagHash::Iterator assetItr = mAssetToTagDatabase.find(assetId);
|
||||
|
||||
// Iterate asset Id tags.
|
||||
while( assetItr != mAssetToTagDatabase.end() && assetItr->key == assetId )
|
||||
{
|
||||
// Is this the asset tag?
|
||||
if ( assetItr->value == pAssetTag )
|
||||
{
|
||||
// Yes, so remove it.
|
||||
mAssetToTagDatabase.erase( assetItr );
|
||||
break;
|
||||
}
|
||||
|
||||
// Next entry.
|
||||
assetItr++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool AssetTagsManifest::hasTag( const char* pAssetId, const char* pTagName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetId != NULL, "Cannot use a NULL asset Id." );
|
||||
AssertFatal( pTagName != NULL, "Cannot use a NULL tag name." );
|
||||
|
||||
// Find asset tag.
|
||||
AssetTag* pAssetTag = findAssetTag( pTagName );
|
||||
|
||||
// Does the tag exist?
|
||||
if ( pAssetTag == NULL )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("AssetTagsManifest: Cannot check if asset Id '%s' has tag name '%s' as tag name does not exist.", pAssetId, pTagName );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return whether asset Id is tagged.
|
||||
return pAssetTag->containsAsset( StringTable->insert( pAssetId ) );
|
||||
}
|
||||
148
Engine/source/assets/assetTagsManifest.h
Normal file
148
Engine/source/assets/assetTagsManifest.h
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _ASSET_TAGS_MANIFEST_H_
|
||||
#define _ASSET_TAGS_MANIFEST_H_
|
||||
|
||||
#ifndef _SIMBASE_H_
|
||||
#include "console/simBase.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TDICTIONARY_H_
|
||||
#include "core/util/tDictionary.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TVECTOR_H_
|
||||
#include "core/util/tvector.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STRINGUNIT_H_
|
||||
#include "core/strings/stringUnit.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define ASSETTAGS_TAGS_NODE_NAME "Tags"
|
||||
#define ASSETTAGS_TAGS_TYPE_NAME "Tag"
|
||||
#define ASSETTAGS_TAGS_NAME_FIELD "Name"
|
||||
|
||||
#define ASSETTAGS_ASSETS_NODE_NAME "Assets"
|
||||
#define ASSETTAGS_ASSETS_TYPE_NAME "Tag"
|
||||
#define ASSETTAGS_ASSETS_ASSETID_FIELD "AssetId"
|
||||
#define ASSETTAGS_ASSETS_TAG_FIELD "Name"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AssetManager;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AssetTagsManifest : public SimObject
|
||||
{
|
||||
friend class AssetManager;
|
||||
|
||||
private:
|
||||
typedef SimObject Parent;
|
||||
typedef StringTableEntry typeAssetId;
|
||||
typedef StringTableEntry typeAssetTagName;
|
||||
|
||||
public:
|
||||
/// Asset location.
|
||||
class AssetTag
|
||||
{
|
||||
public:
|
||||
AssetTag( StringTableEntry tagName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( tagName != NULL, "Cannot use a NULL tag name." );
|
||||
|
||||
// Case sensitive tag name.
|
||||
mTagName = tagName;
|
||||
}
|
||||
|
||||
bool containsAsset( typeAssetId assetId )
|
||||
{
|
||||
for ( Vector<typeAssetId>::iterator assetIdItr = mAssets.begin(); assetIdItr != mAssets.end(); ++assetIdItr )
|
||||
{
|
||||
if ( *assetIdItr == assetId )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void removeAsset( typeAssetId assetId )
|
||||
{
|
||||
for ( Vector<typeAssetId>::iterator assetIdItr = mAssets.begin(); assetIdItr != mAssets.end(); ++assetIdItr )
|
||||
{
|
||||
if ( *assetIdItr == assetId )
|
||||
{
|
||||
mAssets.erase( assetIdItr );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typeAssetTagName mTagName;
|
||||
Vector<typeAssetId> mAssets;
|
||||
};
|
||||
|
||||
/// Asset/Tag database.
|
||||
typedef HashMap<typeAssetTagName, AssetTag*> typeTagNameHash;
|
||||
typedef HashTable<typeAssetId, AssetTag*> typeAssetToTagHash;
|
||||
|
||||
private:
|
||||
typeTagNameHash mTagNameDatabase;
|
||||
typeAssetToTagHash mAssetToTagDatabase;
|
||||
|
||||
private:
|
||||
StringTableEntry fetchTagName( const char* pTagName );
|
||||
AssetTag* findAssetTag( const char* pTagName );
|
||||
void renameAssetId( const char* pAssetIdFrom, const char* pAssetIdTo );
|
||||
|
||||
protected:
|
||||
virtual void onTamlCustomWrite( TamlCustomNodes& customNodes );
|
||||
virtual void onTamlCustomRead( const TamlCustomNodes& customNodes );
|
||||
|
||||
public:
|
||||
AssetTagsManifest();
|
||||
virtual ~AssetTagsManifest();
|
||||
|
||||
/// Tagging.
|
||||
const AssetTag* createTag( const char* pTagName );
|
||||
bool renameTag( const char* pOldTagName, const char* pNewTagName );
|
||||
bool deleteTag( const char* pTagName );
|
||||
bool isTag( const char* pTagName );
|
||||
inline U32 getTagCount( void ) const { return (U32)mTagNameDatabase.size(); }
|
||||
StringTableEntry getTag( const U32 tagIndex );
|
||||
U32 getAssetTagCount( const char* pAssetId );
|
||||
StringTableEntry getAssetTag( const char* pAssetId, const U32 tagIndex );
|
||||
bool tag( const char* pAssetId, const char* pTagName );
|
||||
bool untag( const char* pAssetId, const char* pTagName );
|
||||
bool hasTag( const char* pAssetId, const char* pTagName );
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT( AssetTagsManifest );
|
||||
};
|
||||
|
||||
#endif // _ASSET_TAGS_MANIFEST_H_
|
||||
|
||||
151
Engine/source/assets/assetTagsManifest_ScriptBinding.h
Normal file
151
Engine/source/assets/assetTagsManifest_ScriptBinding.h
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 "assetTagsManifest.h"
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, createTag, void, (const char* tagName), (""),
|
||||
"Creates an asset tag.\n"
|
||||
"@param tagName The tag name to create.\n"
|
||||
"@return No return value.\n")
|
||||
{
|
||||
object->createTag(tagName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, renameTag, bool, (const char* oldTagName, const char* newTagName),,
|
||||
"Renames an existing asset tag.\n"
|
||||
"@param tagName The tag name to rename.\n"
|
||||
"@param newTagName The new tag name to assign.\n"
|
||||
"@return Whether the asset tag was renamed or not.\n")
|
||||
{
|
||||
return object->renameTag(oldTagName, newTagName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, deleteTag, bool, (const char* tagName),,
|
||||
"Deletes an asset tag.\n"
|
||||
"@param tagName The tag name to delete.\n"
|
||||
"@return Whether the asset tag was deleted or not.\n")
|
||||
{
|
||||
return object->deleteTag(tagName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, isTag, bool, (const char* tagName),,
|
||||
"Checks whether the specified asset tag exists or not.\n"
|
||||
"@param tagName The tag name to check.\n"
|
||||
"@return Whether the specified asset tag exists or not.\n")
|
||||
{
|
||||
return object->isTag(tagName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, getTagCount, S32, (),,
|
||||
"Gets the total asset tag count.\n"
|
||||
"@return The total asset tag count.\n")
|
||||
{
|
||||
return object->getTagCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, getTag, const char*, (S32 tagIndex),,
|
||||
"Gets the asset tag at the specified index.\n"
|
||||
"@param tagIndex The asset tag index.This must be 0 to the asset tag count less one.\n"
|
||||
"@return The asset tag at the specified index or NULL if invalid.\n")
|
||||
{
|
||||
// Is the tag index out-of-bounds?
|
||||
if ( tagIndex >= object->getTagCount() )
|
||||
{
|
||||
// Yes, so warn.
|
||||
Con::warnf( "AssetTagsManifest: Asset tag index '%d' is out of bounds. Asset tag count is '%d'", tagIndex, object->getTagCount() );
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
return object->getTag( tagIndex );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, getAssetTagCount, S32, (const char* assetId),,
|
||||
"Gets the asset tag count on the specified asset Id.\n"
|
||||
"@param assetId The asset Id to count tags on.\n"
|
||||
"@return The asset tag count on the specified asset Id.\n")
|
||||
{
|
||||
return object->getAssetTagCount(assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, getAssetTag, const char*, (const char* assetId, S32 tagIndex), ,
|
||||
"Gets the asset tag on the specified asset Id at the specified index.\n"
|
||||
"@param assetId The asset Id to count tags on.\n"
|
||||
"@param tagIndex The asset tag index.This must be 0 to the asset tag count less one.\n"
|
||||
"@return The asset tag on the specified asset Id at the specified index or NULL if invalid.\n")
|
||||
{
|
||||
// Is the tag index out-of-bounds?
|
||||
if (tagIndex >= object->getAssetTagCount(assetId))
|
||||
{
|
||||
// Yes, so warn.
|
||||
Con::warnf("AssetTagsManifest: Asset tag index '%d' is out of bounds. Asset tag count is '%d'", tagIndex, object->getAssetTagCount(assetId));
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
return object->getAssetTag(assetId, tagIndex);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, tag, bool, (const char* assetId, const char* tagName),,
|
||||
"Tags the asset Id with the specified asset tag.\n"
|
||||
"@param assetId The asset Id to tag.\n"
|
||||
"@param tagName The tag name to assign.\n"
|
||||
"@return Whether the tag operation was successful or not.\n")
|
||||
{
|
||||
return object->tag(assetId, tagName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, untag, bool, (const char* assetId, const char* tagName),,
|
||||
"Un-tags the asset Id from the specified asset tag.\n"
|
||||
"@param assetId The asset Id to un - tag.\n"
|
||||
"@param tagName The tag name to un - assign.\n"
|
||||
"@return Whether the un - tag operation was successful or not.\n")
|
||||
{
|
||||
return object->untag(assetId, tagName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod(AssetTagsManifest, hasTag, bool, (const char* assetId, const char* tagName), ,
|
||||
"Checks whether the asset Id is tagged with the specified asset tag.\n"
|
||||
"@param assetId The asset Id to check.\n"
|
||||
"@param tagName The tag name to check.\n"
|
||||
"@return Whether the asset Id is tagged with the specified asset tag or not.\n")
|
||||
{
|
||||
return object->hasTag(assetId, tagName);
|
||||
}
|
||||
12
Engine/source/assets/core.h
Normal file
12
Engine/source/assets/core.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef _ASSET_CORE_H_
|
||||
#define _ASSET_CORE_H_
|
||||
|
||||
#ifndef _ASSET_BASE_H_
|
||||
#include "assetBase.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_DEFINITION_H_
|
||||
#include "assetDefinition.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
45
Engine/source/assets/declaredAssets.cpp
Normal file
45
Engine/source/assets/declaredAssets.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 _DECLARED_ASSETS_H_
|
||||
#include "assets/declaredAssets.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT( DeclaredAssets );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void DeclaredAssets::initPersistFields()
|
||||
{
|
||||
// Call Parent.
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField("Path", TypeString, Offset(mPath, DeclaredAssets), "" );
|
||||
addField("Extension", TypeString, Offset(mExtension, DeclaredAssets), "" );
|
||||
addField("Recurse", TypeBool, Offset(mRecurse, DeclaredAssets), "" );
|
||||
}
|
||||
73
Engine/source/assets/declaredAssets.h
Normal file
73
Engine/source/assets/declaredAssets.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _DECLARED_ASSETS_H_
|
||||
#define _DECLARED_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 DeclaredAssets : public SimObject
|
||||
{
|
||||
friend class AssetManager;
|
||||
|
||||
private:
|
||||
typedef SimObject Parent;
|
||||
|
||||
StringTableEntry mPath;
|
||||
StringTableEntry mExtension;
|
||||
bool mRecurse;
|
||||
|
||||
public:
|
||||
DeclaredAssets() :
|
||||
mPath( StringTable->EmptyString() ),
|
||||
mExtension(StringTable->EmptyString()),
|
||||
mRecurse( false )
|
||||
{}
|
||||
virtual ~DeclaredAssets() {}
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
inline void setPath( const char* pPath ) { mPath = StringTable->insert( pPath ); }
|
||||
inline StringTableEntry getPath( void ) const { return mPath; }
|
||||
inline void setExtension( const char* pPath ) { mExtension = StringTable->insert( pPath ); }
|
||||
inline StringTableEntry getExtension( void ) const { return mExtension; }
|
||||
inline void setRecurse( const bool recurse ) { mRecurse = recurse; }
|
||||
inline bool getRecurse( void ) const { return mRecurse; }
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT( DeclaredAssets );
|
||||
};
|
||||
|
||||
#endif // _DECLARED_ASSETS_H_
|
||||
|
||||
45
Engine/source/assets/referencedAssets.cpp
Normal file
45
Engine/source/assets/referencedAssets.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 _REFERENCED_ASSETS_H_
|
||||
#include "assets/referencedAssets.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT( ReferencedAssets );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ReferencedAssets::initPersistFields()
|
||||
{
|
||||
// Call Parent.
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField("Path", TypeString, Offset(mPath, ReferencedAssets), "" );
|
||||
addField("Extension", TypeString, Offset(mExtension, ReferencedAssets), "" );
|
||||
addField("Recurse", TypeBool, Offset(mRecurse, ReferencedAssets), "" );
|
||||
}
|
||||
73
Engine/source/assets/referencedAssets.h
Normal file
73
Engine/source/assets/referencedAssets.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _REFERENCED_ASSETS_H_
|
||||
#define _REFERENCED_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 ReferencedAssets : public SimObject
|
||||
{
|
||||
friend class AssetManager;
|
||||
|
||||
private:
|
||||
typedef SimObject Parent;
|
||||
|
||||
StringTableEntry mPath;
|
||||
StringTableEntry mExtension;
|
||||
bool mRecurse;
|
||||
|
||||
public:
|
||||
ReferencedAssets() :
|
||||
mPath( StringTable->EmptyString() ),
|
||||
mExtension(StringTable->EmptyString()),
|
||||
mRecurse( false )
|
||||
{}
|
||||
virtual ~ReferencedAssets() {}
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
inline void setPath( const char* pPath ) { mPath = StringTable->insert( pPath ); }
|
||||
inline StringTableEntry getPath( void ) const { return mPath; }
|
||||
inline void setExtension( const char* pPath ) { mExtension = StringTable->insert( pPath ); }
|
||||
inline StringTableEntry getExtension( void ) const { return mExtension; }
|
||||
inline void setRecurse( const bool recurse ) { mRecurse = recurse; }
|
||||
inline bool getRecurse( void ) const { return mRecurse; }
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT( ReferencedAssets );
|
||||
};
|
||||
|
||||
#endif // _REFERENCED_ASSETS_H_
|
||||
|
||||
132
Engine/source/assets/tamlAssetDeclaredUpdateVisitor.h
Normal file
132
Engine/source/assets/tamlAssetDeclaredUpdateVisitor.h
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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_ASSET_DECLARED_UPDATE_VISITOR_H_
|
||||
#define _TAML_ASSET_DECLARED_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
|
||||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TamlAssetDeclaredUpdateVisitor : public TamlVisitor
|
||||
{
|
||||
private:
|
||||
StringTableEntry mAssetIdFrom;
|
||||
StringTableEntry mAssetIdTo;
|
||||
StringTableEntry mAssetNameFrom;
|
||||
StringTableEntry mAssetNameTo;
|
||||
|
||||
public:
|
||||
TamlAssetDeclaredUpdateVisitor() {}
|
||||
virtual ~TamlAssetDeclaredUpdateVisitor() {}
|
||||
|
||||
void setAssetIdFrom( const char* pAssetIdFrom )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetIdFrom != NULL, "Asset Id from cannot be NULL." );
|
||||
|
||||
// Reset asset Id.
|
||||
mAssetIdFrom = StringTable->EmptyString();
|
||||
mAssetNameFrom = StringTable->EmptyString();
|
||||
|
||||
// Is asset Id the correct format?
|
||||
if ( StringUnit::getUnitCount( pAssetIdFrom, ASSET_SCOPE_TOKEN ) != 2 )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "TamlAssetDeclaredUpdateVisitor::setAssetIdFrom() - Cannot use asset Id '%s' as it is not the correct format.", pAssetIdFrom );
|
||||
return;
|
||||
}
|
||||
|
||||
// Set asset Id.
|
||||
mAssetIdFrom = StringTable->insert( pAssetIdFrom );
|
||||
mAssetNameFrom = StringTable->insert( StringUnit::getUnit( pAssetIdFrom, 1, ASSET_SCOPE_TOKEN ) );
|
||||
}
|
||||
StringTableEntry getAssetIdFrom( void ) const { return mAssetIdFrom; }
|
||||
|
||||
void setAssetIdTo( const char* pAssetIdTo )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetIdTo != NULL, "Asset Id to cannot be NULL." );
|
||||
|
||||
// Reset asset Id.
|
||||
mAssetIdTo = StringTable->EmptyString();
|
||||
mAssetNameTo = StringTable->EmptyString();
|
||||
|
||||
// Is asset Id the correct format?
|
||||
if ( StringUnit::getUnitCount( pAssetIdTo, ASSET_SCOPE_TOKEN ) != 2 )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf( "TamlAssetDeclaredUpdateVisitor::setAssetIdTo() - Cannot use asset Id '%s' as it is not the correct format.", pAssetIdTo );
|
||||
return;
|
||||
}
|
||||
|
||||
// Set asset Id.
|
||||
mAssetIdTo = StringTable->insert( pAssetIdTo );
|
||||
mAssetNameTo = StringTable->insert( StringUnit::getUnit( pAssetIdTo, 1, ASSET_SCOPE_TOKEN ) );
|
||||
}
|
||||
const char* getAssetIdTo( void ) const { return mAssetIdTo; }
|
||||
|
||||
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(TamlAssetDeclaredUpdateVisitor_Visit);
|
||||
|
||||
// Finish if not the asset name field.
|
||||
if ( propertyState.getPropertyName() != assetNameField )
|
||||
return true;
|
||||
|
||||
// Is this the asset Id we're looking for?
|
||||
if ( dStricmp( propertyState.getPropertyValue(), mAssetNameFrom ) != 0 )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("Cannot rename asset Name '%s' to asset Name '%s' as the declared asset Name was %s",
|
||||
mAssetNameFrom, mAssetNameTo, propertyState.getPropertyValue() );
|
||||
|
||||
// Stop processing!
|
||||
return false;
|
||||
}
|
||||
|
||||
// Assign new value.
|
||||
propertyState.updatePropertyValue( mAssetNameTo );
|
||||
|
||||
// Stop processing!
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _TAML_ASSET_DECLARED_UPDATE_VISITOR_H_
|
||||
189
Engine/source/assets/tamlAssetDeclaredVisitor.h
Normal file
189
Engine/source/assets/tamlAssetDeclaredVisitor.h
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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_ASSET_DECLARED_VISITOR_H_
|
||||
#define _TAML_ASSET_DECLARED_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
|
||||
|
||||
#ifndef _ASSET_DEFINITION_H_
|
||||
#include "assetDefinition.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_BASE_H_
|
||||
#include "assetBase.h"
|
||||
#endif
|
||||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TamlAssetDeclaredVisitor : public TamlVisitor
|
||||
{
|
||||
public:
|
||||
typedef StringTableEntry typeAssetId;
|
||||
typedef Vector<typeAssetId> typeAssetIdVector;
|
||||
typedef Vector<StringTableEntry> typeLooseFileVector;
|
||||
|
||||
private:
|
||||
AssetDefinition mAssetDefinition;
|
||||
typeAssetIdVector mAssetDependencies;
|
||||
typeLooseFileVector mAssetLooseFiles;
|
||||
|
||||
public:
|
||||
TamlAssetDeclaredVisitor() { mAssetDefinition.reset(); }
|
||||
virtual ~TamlAssetDeclaredVisitor() {}
|
||||
|
||||
|
||||
inline AssetDefinition& getAssetDefinition( void ) { return mAssetDefinition; }
|
||||
inline typeAssetIdVector& getAssetDependencies( void ) { return mAssetDependencies; }
|
||||
inline typeLooseFileVector& getAssetLooseFiles( void ) { return mAssetLooseFiles; }
|
||||
|
||||
void clear( void ) { mAssetDefinition.reset(); mAssetDependencies.clear(); mAssetLooseFiles.clear(); }
|
||||
|
||||
virtual bool wantsPropertyChanges( void ) { return false; }
|
||||
virtual bool wantsRootOnly( void ) { return false; }
|
||||
|
||||
virtual bool visit( const TamlParser& parser, TamlVisitor::PropertyState& propertyState )
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(TamlAssetDeclaredVisitor_Visit);
|
||||
|
||||
// Fetch property name and value.
|
||||
StringTableEntry propertyName = propertyState.getPropertyName();
|
||||
const char* pPropertyValue = propertyState.getPropertyValue();
|
||||
|
||||
// Is this the root object?
|
||||
if ( propertyState.isRootObject() )
|
||||
{
|
||||
// Yes, so is the asset type set yet?
|
||||
if ( mAssetDefinition.mAssetType == StringTable->EmptyString() )
|
||||
{
|
||||
// No, set set asset type and base file-path.
|
||||
mAssetDefinition.mAssetType = propertyState.getObjectName();
|
||||
mAssetDefinition.mAssetBaseFilePath = parser.getParsingFilename();
|
||||
}
|
||||
|
||||
// Asset name?
|
||||
if ( propertyName == assetNameField )
|
||||
{
|
||||
// Yes, so assign it.
|
||||
mAssetDefinition.mAssetName = StringTable->insert( pPropertyValue );
|
||||
return true;
|
||||
}
|
||||
// Asset description?
|
||||
else if ( propertyName == assetDescriptionField )
|
||||
{
|
||||
// Yes, so assign it.
|
||||
mAssetDefinition.mAssetDescription = StringTable->insert( pPropertyValue );
|
||||
return true;
|
||||
}
|
||||
// Asset description?
|
||||
else if ( propertyName == assetCategoryField )
|
||||
{
|
||||
// Yes, so assign it.
|
||||
mAssetDefinition.mAssetCategory = StringTable->insert( pPropertyValue );
|
||||
return true;
|
||||
}
|
||||
// Asset auto-unload?
|
||||
else if ( propertyName == assetAutoUnloadField )
|
||||
{
|
||||
// Yes, so assign it.
|
||||
mAssetDefinition.mAssetAutoUnload = dAtob( pPropertyValue );
|
||||
return true;
|
||||
}
|
||||
// Asset internal?
|
||||
else if ( propertyName == assetInternalField )
|
||||
{
|
||||
// Yes, so assign it.
|
||||
mAssetDefinition.mAssetInternal = dAtob( pPropertyValue );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch property word count.
|
||||
const U32 propertyWordCount = StringUnit::getUnitCount( pPropertyValue, ASSET_ASSIGNMENT_TOKEN );
|
||||
|
||||
// Finish if there's not two words.
|
||||
if ( propertyWordCount != 2 )
|
||||
return true;
|
||||
|
||||
// Fetch the asset signature.
|
||||
StringTableEntry assetSignature = StringTable->insert( StringUnit::getUnit( pPropertyValue, 0, ASSET_ASSIGNMENT_TOKEN ) );
|
||||
|
||||
// Is this an asset Id signature?
|
||||
if ( assetSignature == assetLooseIdSignature )
|
||||
{
|
||||
// Yes, so get asset Id.
|
||||
typeAssetId assetId = StringTable->insert( StringUnit::getUnit( pPropertyValue, 1, ASSET_ASSIGNMENT_TOKEN ) );
|
||||
|
||||
// Finish if the dependency is itself!
|
||||
if ( mAssetDefinition.mAssetId == assetId )
|
||||
return true;
|
||||
|
||||
// Iterate existing dependencies.
|
||||
for( typeAssetIdVector::iterator dependencyItr = mAssetDependencies.begin(); dependencyItr != mAssetDependencies.end(); ++dependencyItr )
|
||||
{
|
||||
// Finish if asset Id is already a dependency.
|
||||
if ( *dependencyItr == assetId )
|
||||
return true;
|
||||
}
|
||||
|
||||
// Insert asset reference.
|
||||
mAssetDependencies.push_back( assetId );
|
||||
}
|
||||
// Is this a loose-file signature?
|
||||
else if ( assetSignature == assetLooseFileSignature )
|
||||
{
|
||||
// Yes, so get loose-file reference.
|
||||
const char* pAssetLooseFile = StringUnit::getUnit( pPropertyValue, 1, ASSET_ASSIGNMENT_TOKEN );
|
||||
|
||||
// Fetch asset path only.
|
||||
char assetBasePathBuffer[1024];
|
||||
dSprintf( assetBasePathBuffer, sizeof(assetBasePathBuffer), "%s", mAssetDefinition.mAssetBaseFilePath );
|
||||
char* pFinalSlash = dStrrchr( assetBasePathBuffer, '/' );
|
||||
if ( pFinalSlash != NULL ) *pFinalSlash = 0;
|
||||
|
||||
// Expand the path in the usual way.
|
||||
char assetFilePathBuffer[1024];
|
||||
Con::expandPath( assetFilePathBuffer, sizeof(assetFilePathBuffer), pAssetLooseFile, assetBasePathBuffer );
|
||||
|
||||
// Insert asset loose-file.
|
||||
mAssetLooseFiles.push_back( StringTable->insert( assetFilePathBuffer ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _TAML_ASSET_DECLARED_VISITOR_H_
|
||||
127
Engine/source/assets/tamlAssetReferencedUpdateVisitor.h
Normal file
127
Engine/source/assets/tamlAssetReferencedUpdateVisitor.h
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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_ASSET_REFERENCED_UPDATE_VISITOR_H_
|
||||
#define _TAML_ASSET_REFERENCED_UPDATE_VISITOR_H_
|
||||
|
||||
#ifndef _TAML_VISITOR_H_
|
||||
#include "persistence/taml/tamlVisitor.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TAML_PARSER_H_
|
||||
#include "persistence\/taml/tamlParser.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STRINGUNIT_H_
|
||||
#include "string/stringUnit.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STRINGTABLE_H_
|
||||
#include "string/stringTable.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ASSET_FIELD_TYPES_H_
|
||||
#include "assets/assetFieldTypes.h"
|
||||
#endif
|
||||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TamlAssetReferencedUpdateVisitor : public TamlVisitor
|
||||
{
|
||||
private:
|
||||
StringTableEntry mAssetIdFrom;
|
||||
StringTableEntry mAssetIdTo;
|
||||
|
||||
public:
|
||||
TamlAssetReferencedUpdateVisitor() {}
|
||||
virtual ~TamlAssetReferencedUpdateVisitor() {}
|
||||
|
||||
void setAssetIdFrom( const char* pAssetIdFrom )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetIdFrom != NULL, "Asset Id from cannot be NULL." );
|
||||
|
||||
mAssetIdFrom = StringTable->insert( pAssetIdFrom );
|
||||
}
|
||||
StringTableEntry getAssetIdFrom( void ) const { return mAssetIdFrom; }
|
||||
|
||||
void setAssetIdTo( const char* pAssetIdTo )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pAssetIdTo != NULL, "Asset Id to cannot be NULL." );
|
||||
|
||||
mAssetIdTo = StringTable->insert( pAssetIdTo );
|
||||
}
|
||||
const char* getAssetIdTo( void ) const { return mAssetIdTo; }
|
||||
|
||||
virtual bool wantsPropertyChanges( void ) { return true; }
|
||||
virtual bool wantsRootOnly( void ) { return false; }
|
||||
|
||||
virtual bool visit( const TamlParser& parser, TamlVisitor::PropertyState& propertyState )
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(TamlAssetReferencedUpdateVisitor_Visit);
|
||||
|
||||
// Fetch the property value.
|
||||
const char* pPropertyValue = propertyState.getPropertyValue();
|
||||
|
||||
// Fetch property value word count.
|
||||
const U32 valueWordCount = StringUnit::getUnitCount( pPropertyValue, ASSET_ASSIGNMENT_TOKEN );
|
||||
|
||||
// Finish if not two words.
|
||||
if ( valueWordCount != 2 )
|
||||
return true;
|
||||
|
||||
// Finish if this is not an asset signature.
|
||||
if ( dStricmp( StringUnit::getUnit( pPropertyValue, 0, ASSET_ASSIGNMENT_TOKEN), assetLooseIdSignature ) != 0 )
|
||||
return true;
|
||||
|
||||
// Get the asset value.
|
||||
const char* pAssetValue = StringUnit::getUnit( pPropertyValue, 1, ASSET_ASSIGNMENT_TOKEN );
|
||||
|
||||
// Finish if not the asset Id we're looking for.
|
||||
if ( dStricmp( pAssetValue, mAssetIdFrom ) != 0 )
|
||||
return true;
|
||||
|
||||
// Is the target asset empty?
|
||||
if ( mAssetIdTo == StringTable->EmptyString() )
|
||||
{
|
||||
// Yes, so update the property as empty.
|
||||
propertyState.updatePropertyValue(StringTable->EmptyString());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Format asset.
|
||||
char assetBuffer[1024];
|
||||
dSprintf( assetBuffer, sizeof(assetBuffer), "%s%s%s", assetLooseIdSignature, ASSET_ASSIGNMENT_TOKEN, mAssetIdTo );
|
||||
|
||||
// Assign new value.
|
||||
propertyState.updatePropertyValue( assetBuffer );
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _TAML_ASSET_REFERENCED_UPDATE_VISITOR_H_
|
||||
96
Engine/source/assets/tamlAssetReferencedVisitor.h
Normal file
96
Engine/source/assets/tamlAssetReferencedVisitor.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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TAML_ASSET_REFERENCED_VISITOR_H_
|
||||
#define _TAML_ASSET_REFERENCED_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
|
||||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TamlAssetReferencedVisitor : public TamlVisitor
|
||||
{
|
||||
public:
|
||||
typedef StringTableEntry typeAssetId;
|
||||
typedef HashMap<typeAssetId, StringTableEntry> typeAssetReferencedHash;
|
||||
|
||||
private:
|
||||
typeAssetReferencedHash mAssetReferenced;
|
||||
|
||||
public:
|
||||
TamlAssetReferencedVisitor() {}
|
||||
virtual ~TamlAssetReferencedVisitor() {}
|
||||
|
||||
const typeAssetReferencedHash& getAssetReferencedMap( void ) const { return mAssetReferenced; }
|
||||
|
||||
void clear( void ) { mAssetReferenced.clear(); }
|
||||
|
||||
virtual bool wantsPropertyChanges( void ) { return false; }
|
||||
virtual bool wantsRootOnly( void ) { return false; }
|
||||
|
||||
virtual bool visit( const TamlParser& parser, TamlVisitor::PropertyState& propertyState )
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(TamlAssetReferencedVisitor_Visit);
|
||||
|
||||
// Fetch property value.
|
||||
const char* pPropertyValue = propertyState.getPropertyValue();
|
||||
|
||||
// Fetch property word count.
|
||||
const U32 propertyWordCount = StringUnit::getUnitCount( pPropertyValue, ASSET_ASSIGNMENT_TOKEN );
|
||||
|
||||
// Finish if there's not two words.
|
||||
if ( propertyWordCount != 2 )
|
||||
return true;
|
||||
|
||||
// Finish if the first word is not an asset signature.
|
||||
if ( StringTable->insert( StringUnit::getUnit( pPropertyValue, 0, ASSET_ASSIGNMENT_TOKEN ) ) != assetLooseIdSignature )
|
||||
return true;
|
||||
|
||||
// Get asset Id.
|
||||
typeAssetId assetId = StringTable->insert( StringUnit::getUnit( pPropertyValue, 1, ASSET_ASSIGNMENT_TOKEN ) );
|
||||
|
||||
// Finish if we already have this asset Id.
|
||||
if ( mAssetReferenced.contains( assetId ) )
|
||||
return true;
|
||||
|
||||
// Insert asset reference.
|
||||
mAssetReferenced.insert( assetId, StringTable->EmptyString() );
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _TAML_ASSET_REFERENCED_VISITOR_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue