Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StaticFileの非同期読み込みを実装中。メモリ管理などの解説ドキュメントを追加
- Loading branch information
1 parent
eec849c
commit bbca1f4
Showing
33 changed files
with
953 additions
and
558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "AsyncStaticFileFactory.h" | ||
#include "../asd.StaticFile_Imp.h" | ||
|
||
namespace asd | ||
{ | ||
AsyncStaticFileFactory::AsyncStaticFileFactory(File_Imp * file, Synchronizer::Ptr sync) | ||
: file(file) | ||
, sync(sync) | ||
{ | ||
} | ||
|
||
StaticFile_Imp * AsyncStaticFileFactory::LoadFromBaseFile( | ||
BaseFile::Ptr & baseFile, | ||
const astring & cacheKey) | ||
{ | ||
return new StaticFile_Imp(file, sync, cacheKey, baseFile); | ||
} | ||
|
||
StaticFile_Imp * AsyncStaticFileFactory::LoadFromPackedFile( | ||
const astring & cacheKey, | ||
const BaseFile::Ptr & packedFile, | ||
PackFileInternalHeader & internalHeader, | ||
std::shared_ptr<Decryptor> decryptor) | ||
{ | ||
return new StaticFile_Imp(file, sync, cacheKey, packedFile, internalHeader, decryptor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include "StaticFileFactoryBase.h" | ||
#include "../../Utils/asd.Synchronizer.h" | ||
|
||
namespace asd | ||
{ | ||
class AsyncStaticFileFactory | ||
: public StaticFileFactoryBase | ||
{ | ||
private: | ||
File_Imp* file; | ||
Synchronizer::Ptr sync; | ||
|
||
public: | ||
AsyncStaticFileFactory(File_Imp* file, Synchronizer::Ptr sync); | ||
virtual ~AsyncStaticFileFactory(){} | ||
|
||
virtual StaticFile_Imp* LoadFromBaseFile(BaseFile::Ptr& baseFile, | ||
const astring& cacheKey); | ||
virtual StaticFile_Imp* LoadFromPackedFile(const astring& cacheKey, | ||
const BaseFile::Ptr& packedFile, | ||
PackFileInternalHeader& internalHeader, | ||
std::shared_ptr<Decryptor> decryptor); | ||
}; | ||
} |
25 changes: 25 additions & 0 deletions
25
Dev/asd_cpp/core/IO/StaticFile/BlockingStaticFileFactory.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "BlockingStaticFileFactory.h" | ||
#include "../asd.StaticFile_Imp.h" | ||
#include "../asd.File_Imp.h" | ||
|
||
namespace asd | ||
{ | ||
BlockingStaticFileFactory::BlockingStaticFileFactory(File_Imp * file) | ||
: file(file) | ||
{ | ||
} | ||
|
||
BlockingStaticFileFactory::~BlockingStaticFileFactory() | ||
{ | ||
} | ||
|
||
StaticFile_Imp * BlockingStaticFileFactory::LoadFromBaseFile(BaseFile::Ptr & baseFile, const astring & cacheKey) | ||
{ | ||
return new StaticFile_Imp(file, cacheKey, baseFile); | ||
} | ||
|
||
StaticFile_Imp * BlockingStaticFileFactory::LoadFromPackedFile(const astring & cacheKey, const BaseFile::Ptr & packedFile, PackFileInternalHeader & internalHeader, std::shared_ptr<Decryptor> decryptor) | ||
{ | ||
return new StaticFile_Imp(file, cacheKey, packedFile, internalHeader, decryptor); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Dev/asd_cpp/core/IO/StaticFile/BlockingStaticFileFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
#include "StaticFileFactoryBase.h" | ||
#include "../../Utils/asd.Synchronizer.h" | ||
|
||
namespace asd | ||
{ | ||
class BlockingStaticFileFactory | ||
: public StaticFileFactoryBase | ||
{ | ||
private: | ||
File_Imp* file; | ||
|
||
public: | ||
typedef std::shared_ptr<BlockingStaticFileFactory> Ptr; | ||
|
||
BlockingStaticFileFactory(File_Imp* file); | ||
virtual ~BlockingStaticFileFactory(); | ||
|
||
virtual StaticFile_Imp* LoadFromBaseFile(BaseFile::Ptr& baseFile, | ||
const astring& cacheKey) override; | ||
virtual StaticFile_Imp* LoadFromPackedFile(const astring& cacheKey, | ||
const BaseFile::Ptr& packedFile, | ||
PackFileInternalHeader& internalHeader, | ||
std::shared_ptr<Decryptor> decryptor) override; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include "../../asd.Core.Base.h" | ||
|
||
#include "../asd.FileRoot.h" | ||
#include "../asd.File.h" | ||
#include <memory> | ||
|
||
namespace asd | ||
{ | ||
class StaticFileFactoryBase | ||
{ | ||
public: | ||
typedef std::shared_ptr<StaticFileFactoryBase> Ptr; | ||
|
||
virtual ~StaticFileFactoryBase(){} | ||
|
||
virtual StaticFile_Imp* LoadFromBaseFile(BaseFile::Ptr& baseFile, const astring& cacheKey) = 0; | ||
virtual StaticFile_Imp* LoadFromPackedFile(const astring& cacheKey, const BaseFile::Ptr& packedFile, | ||
PackFileInternalHeader& internalHeader, std::shared_ptr<Decryptor> decryptor) = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include "StaticFileLoader.h" | ||
#include "../asd.StaticFile_Imp.h" | ||
#include "../asd.File_Imp.h" | ||
|
||
namespace asd | ||
{ | ||
StaticFileLoader::StaticFileLoader(File_Imp* file, StaticFileFactoryBase::Ptr factory) | ||
: file(file) | ||
, factory(factory) | ||
{ | ||
} | ||
|
||
StaticFileLoader::~StaticFileLoader() | ||
{ | ||
} | ||
|
||
StaticFile* StaticFileLoader::LoadFromAbsolutePath(const char16_t * path) | ||
{ | ||
std::lock_guard<std::recursive_mutex> lock(mtx_); | ||
|
||
auto cacheKey = astring(path); | ||
auto cache = LoadFromCache(cacheKey); | ||
if (cache != nullptr) | ||
{ | ||
return cache; | ||
} | ||
|
||
auto file = CreateSharedPtr(new BaseFile(path)); | ||
if (file->IsValid()) | ||
{ | ||
auto staticFile = factory->LoadFromBaseFile(file, cacheKey); | ||
staticFiles[cacheKey] = staticFile; | ||
return staticFile; | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
StaticFile* StaticFileLoader::LoadFromPackedRoot(const char16_t * path, astring packedPath, | ||
FileRoot::Ptr root) | ||
{ | ||
std::lock_guard<std::recursive_mutex> lock(mtx_); | ||
|
||
auto cacheKey = astring(path); | ||
auto cache = LoadFromCache(path); | ||
if (cache != nullptr) | ||
{ | ||
return cache; | ||
} | ||
|
||
auto packFile = root->GetPackFile(); | ||
|
||
if (packFile->HaveFile(packedPath)) | ||
{ | ||
const auto& internalHeader = packFile->GetInternalHeader(packedPath); | ||
|
||
StaticFile_Imp* staticFile = nullptr; | ||
|
||
{ | ||
staticFile = factory->LoadFromPackedFile(astring(packedPath), packFile->RawFile(), | ||
*internalHeader, root->decryptor); | ||
staticFiles[cacheKey] = staticFile; | ||
return staticFile; | ||
} | ||
} | ||
} | ||
|
||
StaticFile* StaticFileLoader::LoadFromNonPackedRoot(const char16_t * path, FileRoot::Ptr root) | ||
{ | ||
std::lock_guard<std::recursive_mutex> lock(mtx_); | ||
|
||
auto combinedPath = FileHelper::CombineRootPath(root->m_path, path); | ||
|
||
auto cacheKey = astring(path); | ||
auto cache = LoadFromCache(path); | ||
if (cache != nullptr) | ||
{ | ||
return cache; | ||
} | ||
|
||
StaticFile_Imp* staticFile = nullptr; | ||
|
||
auto file = CreateSharedPtr(new BaseFile(combinedPath)); | ||
if (file->IsValid()) | ||
{ | ||
auto staticFile = factory->LoadFromBaseFile(file, astring(combinedPath)); | ||
staticFiles[cacheKey] = staticFile; | ||
return staticFile; | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
void StaticFileLoader::UnregisterStaticFile(const astring & key) | ||
{ | ||
std::lock_guard<std::recursive_mutex> lock(mtx_); | ||
|
||
staticFiles.erase(key); | ||
} | ||
|
||
StaticFile* StaticFileLoader::LoadFromCache(astring cacheKey) | ||
{ | ||
auto it = staticFiles.find(cacheKey); | ||
if (it != staticFiles.end()) | ||
{ | ||
auto ret = it->second; | ||
SafeAddRef(ret); | ||
return ret; | ||
} | ||
return nullptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
#include "../../asd.Core.Base.h" | ||
|
||
#include "../asd.FileRoot.h" | ||
#include "../asd.File.h" | ||
#include "../asd.PackFile.h" | ||
#include "../asd.FileHelper.h" | ||
#include "StaticFileFactoryBase.h" | ||
#include <unordered_map> | ||
#include <mutex> | ||
|
||
namespace asd | ||
{ | ||
class StaticFileLoader | ||
{ | ||
private: | ||
std::unordered_map<astring, StaticFile_Imp*> staticFiles; | ||
File_Imp* file; | ||
StaticFileFactoryBase::Ptr factory; | ||
std::recursive_mutex mtx_; | ||
|
||
StaticFile* LoadFromCache(astring cacheKey); | ||
|
||
public: | ||
typedef std::shared_ptr<StaticFileLoader> Ptr; | ||
|
||
StaticFileLoader(File_Imp* file, StaticFileFactoryBase::Ptr factory); | ||
virtual ~StaticFileLoader(); | ||
|
||
StaticFile* LoadFromAbsolutePath(const char16_t* path); | ||
StaticFile* LoadFromPackedRoot(const char16_t* path, astring packedPath, FileRoot::Ptr root); | ||
StaticFile* LoadFromNonPackedRoot(const char16_t* path, FileRoot::Ptr root); | ||
|
||
#ifndef SWIG | ||
void UnregisterStaticFile(const astring& key); | ||
#endif | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.