129 lines
2.9 KiB
C++
129 lines
2.9 KiB
C++
#include "stdafx.h"
|
|
#include "SGroundMaterialResDB.h"
|
|
|
|
#include <Windows.h>
|
|
#include "KTypes.h"
|
|
#include <kfile/KStream.h>
|
|
#include <kfile/KFileManager.h>
|
|
#include <toolkit/XStringUtil.h>
|
|
#include "SkillBaseFile.h"
|
|
#include "ContentStruct.h"
|
|
|
|
#include "SDebug_Util.h"
|
|
|
|
extern HWND g_hWnd;
|
|
|
|
|
|
SGroundMaterialResDB & GetGroundMaterialResDB()
|
|
{
|
|
static SGroundMaterialResDB GroundMaterialResDB;
|
|
return GroundMaterialResDB;
|
|
}
|
|
|
|
SGroundMaterialResDB::SGroundMaterialResDB()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
SGroundMaterialResDB::~SGroundMaterialResDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void SGroundMaterialResDB::Init()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void SGroundMaterialResDB::Destroy()
|
|
{
|
|
GroundMaterialResource* pGroundMaterialRes = NULL;
|
|
bool res;
|
|
res = m_hashGroundMaterialRes.get_first_value( pGroundMaterialRes );
|
|
while ( res )
|
|
{
|
|
if ( pGroundMaterialRes != NULL )
|
|
{
|
|
delete pGroundMaterialRes;
|
|
}
|
|
res = m_hashGroundMaterialRes.get_next_value( pGroundMaterialRes );
|
|
}
|
|
m_hashGroundMaterialRes.clear();
|
|
}
|
|
|
|
void SGroundMaterialResDB::Load()
|
|
{
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_GroundMaterialRes.rdb" );
|
|
if( !pRes ) return;
|
|
GAME_DB db_hdr;
|
|
|
|
pRes->Read( &db_hdr, sizeof(db_hdr) );
|
|
|
|
#ifdef _DEV_RDB_
|
|
// RDB 와 Header의 사이즈 비교.
|
|
int fileSize = pRes->Size() - ( STR_DATE_BUFFER + sizeof( int ) );
|
|
int headerSize = sizeof(GroundMaterialResource) * db_hdr.nCount;
|
|
|
|
if( fileSize != headerSize )
|
|
{
|
|
char str[512] = { NULL, };
|
|
sprintf( str, "*** RDB Error !!! ***\n\n생성날짜%s\n파일:%s\n파일사이즈:%d\n헤더사이즈:%d\n ",
|
|
db_hdr.szDate,
|
|
__FILE__,
|
|
fileSize,
|
|
headerSize
|
|
);
|
|
|
|
::MessageBox( g_hWnd, str, "Error", MB_OK );
|
|
|
|
if( ::MessageBox( g_hWnd, "RDB와 클라이언트가 맞지않습니다. 강제종료하시겠습니까?", "Error", MB_YESNO ) == IDYES )
|
|
{
|
|
exit( 1 );
|
|
}
|
|
}
|
|
#endif
|
|
|
|
|
|
for( int i(0); db_hdr.nCount>i; i++ )
|
|
{
|
|
GroundMaterialResource * pItem = new GroundMaterialResource;
|
|
memset( pItem, 0, sizeof(GroundMaterialResource) );
|
|
|
|
pRes->Read( pItem, sizeof(GroundMaterialResource) );
|
|
|
|
GroundMaterialResource* pFindItem = NULL;
|
|
if( m_hashGroundMaterialRes.lookup( pItem->tile_id, pFindItem ) == false )
|
|
{
|
|
m_hashGroundMaterialRes.add( pItem->tile_id, pItem );
|
|
}
|
|
else
|
|
{
|
|
_oprint( "!!!!Data Error SGroundMaterialResDB::Load() Code 가 중복되었습니다.!!!! %d\n", pItem->tile_id );
|
|
assert(0); //기획팀에 알려 주세여. 바로 수정 해야 합니다.
|
|
|
|
delete pItem;
|
|
}
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
}
|
|
|
|
int SGroundMaterialResDB::GetGroundMaterialID( int nTileID )
|
|
{
|
|
GroundMaterialResource* pGroundMaterial = GetGroundMaterialRes( nTileID );
|
|
if( pGroundMaterial )
|
|
{
|
|
return pGroundMaterial->ground_material_id;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
GroundMaterialResource* SGroundMaterialResDB::GetGroundMaterialRes( int nTileID )
|
|
{
|
|
GroundMaterialResource* pFindItem = NULL;
|
|
if( m_hashGroundMaterialRes.lookup( nTileID, pFindItem ))
|
|
return pFindItem;
|
|
|
|
return NULL;
|
|
} |