Integrate async loading infrastructure
- Initialize FileLoaderThreadPool and TextureCache - Route file requests through thread pool - Handle pre-decoded images from worker threads - Reduce loading delay from 20ms to 1ms - 512MB texture cache (up from 256MB)
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "ResourceManager.h"
|
#include "ResourceManager.h"
|
||||||
#include "GrpImage.h"
|
#include "GrpImage.h"
|
||||||
|
#include "TextureCache.h"
|
||||||
|
#include "DecodedImageData.h"
|
||||||
|
|
||||||
int g_iLoadingDelayTime = 1; // Reduced from 20ms to 1ms for faster async loading
|
int g_iLoadingDelayTime = 1; // Reduced from 20ms to 1ms for faster async loading
|
||||||
|
|
||||||
@@ -68,7 +70,16 @@ void CResourceManager::ProcessBackgroundLoading()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//printf("REQ %s\n", stFileName.c_str());
|
//printf("REQ %s\n", stFileName.c_str());
|
||||||
ms_loadingThread.Request(stFileName);
|
|
||||||
|
if (m_pLoaderThreadPool)
|
||||||
|
{
|
||||||
|
m_pLoaderThreadPool->Request(stFileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ms_loadingThread.Request(stFileName);
|
||||||
|
}
|
||||||
|
|
||||||
m_WaitingMap.insert(TResourceRequestMap::value_type(dwFileCRC, stFileName));
|
m_WaitingMap.insert(TResourceRequestMap::value_type(dwFileCRC, stFileName));
|
||||||
itor = m_RequestMap.erase(itor);
|
itor = m_RequestMap.erase(itor);
|
||||||
//break; // NOTE: 여기서 break 하면 천천히 로딩 된다.
|
//break; // NOTE: 여기서 break 하면 천천히 로딩 된다.
|
||||||
@@ -76,6 +87,44 @@ void CResourceManager::ProcessBackgroundLoading()
|
|||||||
|
|
||||||
DWORD dwCurrentTime = ELTimer_GetMSec();
|
DWORD dwCurrentTime = ELTimer_GetMSec();
|
||||||
|
|
||||||
|
if (m_pLoaderThreadPool)
|
||||||
|
{
|
||||||
|
CFileLoaderThreadPool::TLoadResult result;
|
||||||
|
while (m_pLoaderThreadPool->Fetch(result))
|
||||||
|
{
|
||||||
|
CResource * pResource = GetResourcePointer(result.stFileName.c_str());
|
||||||
|
|
||||||
|
if (pResource)
|
||||||
|
{
|
||||||
|
if (pResource->IsEmpty())
|
||||||
|
{
|
||||||
|
if (result.hasDecodedImage)
|
||||||
|
{
|
||||||
|
CGraphicImage* pImage = dynamic_cast<CGraphicImage*>(pResource);
|
||||||
|
if (pImage)
|
||||||
|
{
|
||||||
|
pImage->OnLoadFromDecodedData(result.decodedImage);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pResource->OnLoad(result.File.size(), result.File.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pResource->OnLoad(result.File.size(), result.File.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
pResource->AddReferenceOnly();
|
||||||
|
m_pResRefDecreaseWaitingMap.insert(TResourceRefDecreaseWaitingMap::value_type(dwCurrentTime, pResource));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_WaitingMap.erase(GetCRC32(result.stFileName.c_str(), result.stFileName.size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process old thread results
|
||||||
CFileLoaderThread::TData * pData;
|
CFileLoaderThread::TData * pData;
|
||||||
while (ms_loadingThread.Fetch(&pData))
|
while (ms_loadingThread.Fetch(&pData))
|
||||||
{
|
{
|
||||||
@@ -528,12 +577,36 @@ void CResourceManager::ReserveDeletingResource(CResource * pResource)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CResourceManager::CResourceManager()
|
CResourceManager::CResourceManager()
|
||||||
|
: m_pLoaderThreadPool(nullptr)
|
||||||
|
, m_pTextureCache(nullptr)
|
||||||
{
|
{
|
||||||
ms_loadingThread.Create(0);
|
ms_loadingThread.Create(0);
|
||||||
|
|
||||||
|
m_pLoaderThreadPool = new CFileLoaderThreadPool();
|
||||||
|
if (!m_pLoaderThreadPool->Initialize())
|
||||||
|
{
|
||||||
|
TraceError("CResourceManager: Failed to initialize FileLoaderThreadPool");
|
||||||
|
delete m_pLoaderThreadPool;
|
||||||
|
m_pLoaderThreadPool = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pTextureCache = new CTextureCache(512);
|
||||||
}
|
}
|
||||||
|
|
||||||
CResourceManager::~CResourceManager()
|
CResourceManager::~CResourceManager()
|
||||||
{
|
{
|
||||||
Destroy();
|
Destroy();
|
||||||
ms_loadingThread.Shutdown();
|
ms_loadingThread.Shutdown();
|
||||||
|
|
||||||
|
if (m_pLoaderThreadPool)
|
||||||
|
{
|
||||||
|
delete m_pLoaderThreadPool;
|
||||||
|
m_pLoaderThreadPool = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_pTextureCache)
|
||||||
|
{
|
||||||
|
delete m_pTextureCache;
|
||||||
|
m_pTextureCache = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
#include "FileLoaderThread.h"
|
#include "FileLoaderThread.h"
|
||||||
|
#include "FileLoaderThreadPool.h"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
class CTextureCache;
|
||||||
|
|
||||||
class CResourceManager : public CSingleton<CResourceManager>
|
class CResourceManager : public CSingleton<CResourceManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -42,6 +45,9 @@ class CResourceManager : public CSingleton<CResourceManager>
|
|||||||
void ProcessBackgroundLoading();
|
void ProcessBackgroundLoading();
|
||||||
void PushBackgroundLoadingSet(std::set<std::string> & LoadingSet);
|
void PushBackgroundLoadingSet(std::set<std::string> & LoadingSet);
|
||||||
|
|
||||||
|
CTextureCache* GetTextureCache() { return m_pTextureCache; }
|
||||||
|
CFileLoaderThreadPool* GetLoaderThreadPool() { return m_pLoaderThreadPool; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void __DestroyDeletingResourceMap();
|
void __DestroyDeletingResourceMap();
|
||||||
void __DestroyResourceMap();
|
void __DestroyResourceMap();
|
||||||
@@ -68,6 +74,8 @@ class CResourceManager : public CSingleton<CResourceManager>
|
|||||||
TResourceRefDecreaseWaitingMap m_pResRefDecreaseWaitingMap;
|
TResourceRefDecreaseWaitingMap m_pResRefDecreaseWaitingMap;
|
||||||
|
|
||||||
static CFileLoaderThread ms_loadingThread;
|
static CFileLoaderThread ms_loadingThread;
|
||||||
|
CFileLoaderThreadPool* m_pLoaderThreadPool;
|
||||||
|
CTextureCache* m_pTextureCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int g_iLoadingDelayTime;
|
extern int g_iLoadingDelayTime;
|
||||||
Reference in New Issue
Block a user