Files
Leviathan/Client/Game/engine/Renderer/KThreadLoader.h
T
2026-06-01 12:46:52 +02:00

86 lines
1.9 KiB
C++

/////////////////////////////////////////
// 쓰레드 리소스 로더
#pragma once
//#include <string>
#include <toolkit/XBossWorker.h>
/*
사용 예 :
class RESOURCE : public KThreadResource
{
virtual bool CopyFrom( KThreadResource* pResource )
{
memcpy( data, static_cast< RESOURCE* >( pResource )->data, sizeof(data) );
return true;
}
virtual bool doLoading()
{
FILE *fp = fopen( GetResourceName(), "rb" );
fread( data, sizeof(data), 1, fp );
fclose( fp );
return true;
}
int data[4096];
};
.
.
RESOURCE *pRes = new RESOURCE;
KThreadResource::StartThreadLoading( pRes, "data.dat" );
*/
class KThreadResource : XBossWorker::XWorker
{
public:
KThreadResource();
virtual ~KThreadResource();
virtual bool doLoading() = 0;
const char* GetResourceName() const { return m_strResourceName.c_str(); }
inline bool IsThreadLoadingComplete() const { return m_bIsThreadLoadingComplete; }
inline bool IsThreadLoading() const { return m_bIsLoading; }
inline bool IsPending() const { return m_bIsLoadingRequested; }
static int GetPendingWork();
static void StartThreadLoading( KThreadResource * pWork, const char *szName );
static bool CancelThreadLoading( KThreadResource * pWork );
static bool PendWorkToThreadPool( XBossWorker::XWorker * pWork );
static void CancelAllWork();
protected:
virtual bool CopyFrom( KThreadResource* pResource ) = 0;
////////////////////////////////////////////
// 이하는 인터페이스 아니므로 모듈 자체를 디버깅할것이 아니라면 볼 필요가 없음.
protected:
void onThreadLoadingComplete();
virtual bool onProcess( int nThreadNum );
virtual void onEnd( bool bIsCancel )
{
m_bIsLoading = false;
if( !bIsCancel ) m_bIsThreadLoadingComplete = true;
}
volatile bool m_bIsLoadingRequested;
volatile bool m_bIsLoading;
volatile bool m_bIsThreadLoadingComplete;
std::string m_strResourceName;
};