Fixes and code cleanup for Flax Storage types
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
#include "Engine/Core/Math/Math.h"
|
||||
#include "Engine/Platform/FileSystem.h"
|
||||
#include "Engine/Content/Storage/ContentStorageManager.h"
|
||||
#if USE_EDITOR
|
||||
#include "Engine/Content/Storage/FlaxFile.h"
|
||||
#endif
|
||||
#include "Engine/Content/Upgraders/BinaryAssetUpgrader.h"
|
||||
|
||||
bool BinaryAssetFactoryBase::Init(BinaryAsset* asset)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "ContentStorageManager.h"
|
||||
#include "FlaxFile.h"
|
||||
#include "FlaxPackage.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Engine/EngineService.h"
|
||||
#include "Engine/Platform/FileSystem.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
|
||||
namespace ContentStorageManagerImpl
|
||||
namespace
|
||||
{
|
||||
CriticalSection Locker;
|
||||
#if USE_EDITOR
|
||||
@@ -14,13 +16,11 @@ namespace ContentStorageManagerImpl
|
||||
Array<FlaxPackage*> Packages;
|
||||
#else
|
||||
Array<FlaxFile*> Files;
|
||||
Array<FlaxPackage*> Packages(32);
|
||||
Array<FlaxPackage*> Packages(64);
|
||||
#endif
|
||||
Dictionary<String, FlaxStorage*> StorageMap(2048);
|
||||
}
|
||||
|
||||
using namespace ContentStorageManagerImpl;
|
||||
|
||||
class ContentStorageManagerService : public EngineService
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "FlaxFile.h"
|
||||
#include "FlaxPackage.h"
|
||||
#include "FlaxStorageReference.h"
|
||||
|
||||
class FlaxFile;
|
||||
class FlaxPackage;
|
||||
|
||||
/// <summary>
|
||||
/// Content Storage Manager is responsible for content data management
|
||||
/// </summary>
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
/// </summary>
|
||||
class FLAXENGINE_API FlaxFile : public FlaxStorage
|
||||
{
|
||||
friend ContentStorageManager;
|
||||
|
||||
protected:
|
||||
|
||||
Entry _asset;
|
||||
@@ -21,91 +19,24 @@ public:
|
||||
/// Initializes a new instance of the <see cref="FlaxFile"/> class.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
FlaxFile(const StringView& path)
|
||||
: FlaxStorage(path)
|
||||
{
|
||||
_asset.ID = Guid::Empty;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="FlaxFile"/> class.
|
||||
/// </summary>
|
||||
~FlaxFile()
|
||||
{
|
||||
}
|
||||
FlaxFile(const StringView& path);
|
||||
|
||||
public:
|
||||
|
||||
// [FlaxStorage]
|
||||
String ToString() const override
|
||||
{
|
||||
return String::Format(TEXT("Asset \'{0}\'"), _path);
|
||||
}
|
||||
|
||||
bool IsPackage() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AllowDataModifications() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HasAsset(const Guid& id) const override
|
||||
{
|
||||
return _asset.ID == id;
|
||||
}
|
||||
|
||||
bool HasAsset(const AssetInfo& info) const override
|
||||
{
|
||||
#if USE_EDITOR
|
||||
if (_path != info.Path)
|
||||
return false;
|
||||
#endif
|
||||
return _asset.ID == info.ID && _asset.TypeName == info.TypeName;
|
||||
}
|
||||
|
||||
int32 GetEntriesCount() const override
|
||||
{
|
||||
return _asset.ID.IsValid() ? 1 : 0;
|
||||
}
|
||||
|
||||
void GetEntry(int32 index, Entry& output) const override
|
||||
{
|
||||
ASSERT(index == 0);
|
||||
output = _asset;
|
||||
}
|
||||
|
||||
void GetEntries(Array<Entry>& output) const override
|
||||
{
|
||||
if (_asset.ID.IsValid())
|
||||
output.Add(_asset);
|
||||
}
|
||||
|
||||
void Dispose() override
|
||||
{
|
||||
// Base
|
||||
FlaxStorage::Dispose();
|
||||
|
||||
// Clean
|
||||
_asset.ID = Guid::Empty;
|
||||
}
|
||||
String ToString() const override;
|
||||
bool IsPackage() const override;
|
||||
bool AllowDataModifications() const override;
|
||||
bool HasAsset(const Guid& id) const override;
|
||||
bool HasAsset(const AssetInfo& info) const override;
|
||||
int32 GetEntriesCount() const override;
|
||||
void GetEntry(int32 index, Entry& output) const override;
|
||||
void GetEntries(Array<Entry>& output) const override;
|
||||
void Dispose() override;
|
||||
|
||||
protected:
|
||||
|
||||
// [FlaxStorage]
|
||||
bool GetEntry(const Guid& id, Entry& e) override
|
||||
{
|
||||
e = _asset;
|
||||
return id != _asset.ID;
|
||||
}
|
||||
|
||||
void AddEntry(Entry& e) override
|
||||
{
|
||||
ASSERT(_asset.ID.IsValid() == false);
|
||||
_asset = e;
|
||||
}
|
||||
bool GetEntry(const Guid& id, Entry& e) override;
|
||||
void AddEntry(Entry& e) override;
|
||||
};
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "FlaxPackage.h"
|
||||
|
||||
bool FlaxPackage::HasAsset(const AssetInfo& info) const
|
||||
{
|
||||
ASSERT(_path == info.Path);
|
||||
|
||||
Entry* e = _entries.TryGet(info.ID);
|
||||
return e && e->TypeName == info.TypeName;
|
||||
}
|
||||
|
||||
bool FlaxPackage::GetEntry(const Guid& id, Entry& e)
|
||||
{
|
||||
return !_entries.TryGet(id, e);
|
||||
}
|
||||
|
||||
void FlaxPackage::AddEntry(Entry& e)
|
||||
{
|
||||
ASSERT(HasAsset(e.ID) == false);
|
||||
_entries.Add(e.ID, e);
|
||||
}
|
||||
|
||||
void FlaxPackage::Dispose()
|
||||
{
|
||||
// Base
|
||||
FlaxStorage::Dispose();
|
||||
|
||||
// Clean
|
||||
_entries.Clear();
|
||||
}
|
||||
@@ -20,67 +20,19 @@ public:
|
||||
/// Initializes a new instance of the <see cref="FlaxPackage"/> class.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
FlaxPackage(const StringView& path)
|
||||
: FlaxStorage(path)
|
||||
, _entries(256)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="FlaxPackage"/> class.
|
||||
/// </summary>
|
||||
~FlaxPackage()
|
||||
{
|
||||
}
|
||||
FlaxPackage(const StringView& path);
|
||||
|
||||
public:
|
||||
|
||||
// [FlaxStorage]
|
||||
String ToString() const override
|
||||
{
|
||||
return String::Format(TEXT("Package \'{0}\'"), _path);
|
||||
}
|
||||
|
||||
bool IsPackage() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AllowDataModifications() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HasAsset(const Guid& id) const override
|
||||
{
|
||||
return _entries.ContainsKey(id);
|
||||
}
|
||||
|
||||
String ToString() const override;
|
||||
bool IsPackage() const override;
|
||||
bool AllowDataModifications() const override;
|
||||
bool HasAsset(const Guid& id) const override;
|
||||
bool HasAsset(const AssetInfo& info) const override;
|
||||
|
||||
int32 GetEntriesCount() const override
|
||||
{
|
||||
return _entries.Count();
|
||||
}
|
||||
|
||||
void GetEntry(int32 index, Entry& output) const override
|
||||
{
|
||||
ASSERT(index >= 0 && index < _entries.Count());
|
||||
for (auto i = _entries.Begin(); i.IsNotEnd(); ++i)
|
||||
{
|
||||
if (index-- <= 0)
|
||||
{
|
||||
output = i->Value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetEntries(Array<Entry>& output) const override
|
||||
{
|
||||
_entries.GetValues(output);
|
||||
}
|
||||
|
||||
int32 GetEntriesCount() const override;
|
||||
void GetEntry(int32 index, Entry& output) const override;
|
||||
void GetEntries(Array<Entry>& output) const override;
|
||||
void Dispose() override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "FlaxStorage.h"
|
||||
#include "FlaxFile.h"
|
||||
#include "FlaxPackage.h"
|
||||
#include "ContentStorageManager.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Platform/File.h"
|
||||
@@ -1319,3 +1321,152 @@ void FlaxStorage::OnRename(const StringView& newPath)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
FlaxFile::FlaxFile(const StringView& path)
|
||||
: FlaxStorage(path)
|
||||
{
|
||||
_asset.ID = Guid::Empty;
|
||||
}
|
||||
|
||||
String FlaxFile::ToString() const
|
||||
{
|
||||
return String::Format(TEXT("Asset \'{0}\'"), _path);
|
||||
}
|
||||
|
||||
bool FlaxFile::IsPackage() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FlaxFile::AllowDataModifications() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FlaxFile::HasAsset(const Guid& id) const
|
||||
{
|
||||
return _asset.ID == id;
|
||||
}
|
||||
|
||||
bool FlaxFile::HasAsset(const AssetInfo& info) const
|
||||
{
|
||||
#if USE_EDITOR
|
||||
if (_path != info.Path)
|
||||
return false;
|
||||
#endif
|
||||
return _asset.ID == info.ID && _asset.TypeName == info.TypeName;
|
||||
}
|
||||
|
||||
int32 FlaxFile::GetEntriesCount() const
|
||||
{
|
||||
return _asset.ID.IsValid() ? 1 : 0;
|
||||
}
|
||||
|
||||
void FlaxFile::GetEntry(int32 index, Entry& output) const
|
||||
{
|
||||
ASSERT(index == 0);
|
||||
output = _asset;
|
||||
}
|
||||
|
||||
void FlaxFile::GetEntries(Array<Entry>& output) const
|
||||
{
|
||||
if (_asset.ID.IsValid())
|
||||
output.Add(_asset);
|
||||
}
|
||||
|
||||
void FlaxFile::Dispose()
|
||||
{
|
||||
// Base
|
||||
FlaxStorage::Dispose();
|
||||
|
||||
// Clean
|
||||
_asset.ID = Guid::Empty;
|
||||
}
|
||||
|
||||
bool FlaxFile::GetEntry(const Guid& id, Entry& e)
|
||||
{
|
||||
e = _asset;
|
||||
return id != _asset.ID;
|
||||
}
|
||||
|
||||
void FlaxFile::AddEntry(Entry& e)
|
||||
{
|
||||
ASSERT(_asset.ID.IsValid() == false);
|
||||
_asset = e;
|
||||
}
|
||||
|
||||
FlaxPackage::FlaxPackage(const StringView& path)
|
||||
: FlaxStorage(path)
|
||||
, _entries(256)
|
||||
{
|
||||
}
|
||||
|
||||
String FlaxPackage::ToString() const
|
||||
{
|
||||
return String::Format(TEXT("Package \'{0}\'"), _path);
|
||||
}
|
||||
|
||||
bool FlaxPackage::IsPackage() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FlaxPackage::AllowDataModifications() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FlaxPackage::HasAsset(const Guid& id) const
|
||||
{
|
||||
return _entries.ContainsKey(id);
|
||||
}
|
||||
|
||||
bool FlaxPackage::HasAsset(const AssetInfo& info) const
|
||||
{
|
||||
ASSERT(_path == info.Path);
|
||||
Entry* e = _entries.TryGet(info.ID);
|
||||
return e && e->TypeName == info.TypeName;
|
||||
}
|
||||
|
||||
int32 FlaxPackage::GetEntriesCount() const
|
||||
{
|
||||
return _entries.Count();
|
||||
}
|
||||
|
||||
void FlaxPackage::GetEntry(int32 index, Entry& output) const
|
||||
{
|
||||
ASSERT(index >= 0 && index < _entries.Count());
|
||||
for (auto i = _entries.Begin(); i.IsNotEnd(); ++i)
|
||||
{
|
||||
if (index-- <= 0)
|
||||
{
|
||||
output = i->Value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FlaxPackage::GetEntries(Array<Entry>& output) const
|
||||
{
|
||||
_entries.GetValues(output);
|
||||
}
|
||||
|
||||
void FlaxPackage::Dispose()
|
||||
{
|
||||
// Base
|
||||
FlaxStorage::Dispose();
|
||||
|
||||
// Clean
|
||||
_entries.Clear();
|
||||
}
|
||||
|
||||
bool FlaxPackage::GetEntry(const Guid& id, Entry& e)
|
||||
{
|
||||
return !_entries.TryGet(id, e);
|
||||
}
|
||||
|
||||
void FlaxPackage::AddEntry(Entry& e)
|
||||
{
|
||||
ASSERT(HasAsset(e.ID) == false);
|
||||
_entries.Add(e.ID, e);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="FlaxStorage"/> class.
|
||||
/// </summary>
|
||||
~FlaxStorage();
|
||||
virtual ~FlaxStorage();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user