mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 07:04:36 +00:00
Asset data management
Added functions to AssetManager to pack/unpack assets using an id hash instead of their id string this cuts down how much data is sent across the network for assets All asset macros updated to use this new functionality.
This commit is contained in:
parent
563c0266e4
commit
74638c0f2c
4 changed files with 115 additions and 173 deletions
|
|
@ -964,6 +964,55 @@ bool AssetManager::renameReferencedAsset( const char* pAssetIdFrom, const char*
|
|||
return true;
|
||||
}
|
||||
|
||||
void AssetManager::packDataAsset(BitStream* stream, const char* pAssetId)
|
||||
{
|
||||
if(stream->writeFlag(isDeclaredAsset(pAssetId)))
|
||||
{
|
||||
stream->write(mAssetToNetId.find(pAssetId)->value);
|
||||
}
|
||||
}
|
||||
|
||||
const char* AssetManager::unpackDataAsset(BitStream* stream)
|
||||
{
|
||||
if (stream->readFlag())
|
||||
{
|
||||
typeAssetNetId netId;
|
||||
stream->read(&netId);
|
||||
|
||||
typeNetIdToAssetMap::iterator netChar = mNetIdToAsset.find(netId);
|
||||
if (netChar != mNetIdToAsset.end())
|
||||
{
|
||||
return netChar->value;
|
||||
}
|
||||
}
|
||||
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
void AssetManager::packUpdateAsset(NetConnection* con, U32 mask, BitStream* stream, const char* pAssetId)
|
||||
{
|
||||
if (stream->writeFlag(isDeclaredAsset(pAssetId)))
|
||||
{
|
||||
stream->write(mAssetToNetId.find(pAssetId)->value);
|
||||
}
|
||||
}
|
||||
|
||||
const char* AssetManager::unpackUpdateAsset(NetConnection* con, BitStream* stream)
|
||||
{
|
||||
if (stream->readFlag())
|
||||
{
|
||||
typeAssetNetId netId;
|
||||
stream->read(&netId);
|
||||
|
||||
typeNetIdToAssetMap::iterator netChar = mNetIdToAsset.find(netId);
|
||||
if (netChar != mNetIdToAsset.end())
|
||||
{
|
||||
return netChar->value;
|
||||
}
|
||||
}
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
bool AssetManager::compileAllAssets(const bool compressed, const bool includeUnloaded)
|
||||
{
|
||||
// Debug Profiling.
|
||||
|
|
@ -2642,6 +2691,17 @@ const char* AssetManager::getAssetLooseFile(const char* pAssetId, const S32& ind
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static U32 HashAssetId(const char* str)
|
||||
{
|
||||
U32 hash = 2166136261u;
|
||||
while (*str)
|
||||
{
|
||||
hash ^= (U8)*str++;
|
||||
hash *= 16777619u;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension, const bool recurse, ModuleDefinition* pModuleDefinition )
|
||||
{
|
||||
// Debug Profiling.
|
||||
|
|
@ -2763,6 +2823,24 @@ bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension
|
|||
continue;
|
||||
}
|
||||
|
||||
U32 netId = HashAssetId(assetIdBuffer);
|
||||
|
||||
// Collision detection
|
||||
typeNetIdToAssetMap::iterator netIterator = mNetIdToAsset.find(netId);
|
||||
if (netIterator != mNetIdToAsset.end())
|
||||
{
|
||||
Con::errorf(
|
||||
"AssetManager: Hash collision for '%s' and '%s'",
|
||||
assetIdBuffer,
|
||||
mNetIdToAsset.find(netId)->value
|
||||
);
|
||||
|
||||
AssertFatal(false, "Asset hash collision detected.");
|
||||
}
|
||||
|
||||
mNetIdToAsset.insert(netId, foundAssetDefinition.mAssetId);
|
||||
mAssetToNetId.insert(foundAssetDefinition.mAssetId, netId);
|
||||
|
||||
// Create new asset definition.
|
||||
AssetDefinition* pAssetDefinition = new AssetDefinition( foundAssetDefinition );
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@
|
|||
#include "assets/assetFieldTypes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _NETCONNECTION_H_
|
||||
#include "sim/netConnection.h"
|
||||
#endif
|
||||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
|
||||
|
|
@ -84,6 +88,11 @@ public:
|
|||
typedef HashTable<typeAssetId, typeAssetId> typeAssetIsDependedOnHash;
|
||||
typedef HashMap<AssetPtrBase*, AssetPtrCallback*> typeAssetPtrRefreshHash;
|
||||
|
||||
// ASSET NETWORK PACK
|
||||
typedef U32 typeAssetNetId;
|
||||
typedef HashMap<typeAssetNetId, typeAssetId> typeNetIdToAssetMap;
|
||||
typedef HashMap<typeAssetId, typeAssetNetId> typeAssetToNetIdMap;
|
||||
// ASSET NETWORK PACK END
|
||||
private:
|
||||
/// Declared assets.
|
||||
typeDeclaredAssetsHash mDeclaredAssets;
|
||||
|
|
@ -91,6 +100,11 @@ private:
|
|||
/// Referenced assets.
|
||||
typeReferencedAssetsHash mReferencedAssets;
|
||||
|
||||
// ASSET NETWORK PACK
|
||||
typeNetIdToAssetMap mNetIdToAsset;
|
||||
typeAssetToNetIdMap mAssetToNetId;
|
||||
// ASSET NETWORK PACK END
|
||||
|
||||
/// Asset dependencies.
|
||||
typeAssetDependsOnHash mAssetDependsOn;
|
||||
typeAssetIsDependedOnHash mAssetIsDependedOn;
|
||||
|
|
@ -151,6 +165,14 @@ public:
|
|||
bool isReferencedAsset( const char* pAssetId );
|
||||
bool renameReferencedAsset( const char* pAssetIdFrom, const char* pAssetIdTo );
|
||||
|
||||
// ASSET NETWORK PACK
|
||||
void packDataAsset(BitStream* stream, const char* pAssetId);
|
||||
const char* unpackDataAsset(BitStream* stream);
|
||||
|
||||
void packUpdateAsset(NetConnection* con, U32 mask, BitStream* stream, const char* pAssetId);
|
||||
const char* unpackUpdateAsset(NetConnection* con, BitStream* stream);
|
||||
// ASSET NETWORK PACK END
|
||||
|
||||
/// <summary>
|
||||
/// Compile all assets.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue