153 lines
3.3 KiB
C++
153 lines
3.3 KiB
C++
#include "stdafx.h"
|
|
#include "SDungeonResourceDB.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"
|
|
|
|
|
|
extern HWND g_hWnd;
|
|
|
|
|
|
const DungeonResource* DUNGEONRESOURCE_INFO::Find( int nLocalFlag )
|
|
{
|
|
DungeonResource* pItem(NULL);
|
|
if( m_hashDungeonRes.lookup( nLocalFlag, pItem ) )
|
|
return pItem;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
/////
|
|
SDungeonResourceDB* SDungeonResourceDB::m_pThis = NULL;
|
|
SDungeonResourceDB & GetDungeonResDB()
|
|
{
|
|
if( NULL == SDungeonResourceDB::m_pThis )
|
|
SDungeonResourceDB::m_pThis = new SDungeonResourceDB;
|
|
|
|
return *SDungeonResourceDB::m_pThis;
|
|
// static SDungeonResourceDB DungeonResDB;
|
|
// return DungeonResDB;
|
|
}
|
|
|
|
SDungeonResourceDB::SDungeonResourceDB()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
SDungeonResourceDB::~SDungeonResourceDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void SDungeonResourceDB::Init()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void SDungeonResourceDB::Destroy()
|
|
{
|
|
DUNGEONRESOURCE_INFO* pDungeonResInfo = NULL;
|
|
bool res;
|
|
res = m_hashDungeonResInfo.get_first_value( pDungeonResInfo );
|
|
while ( res )
|
|
{
|
|
if ( pDungeonResInfo != NULL )
|
|
{
|
|
delete pDungeonResInfo;
|
|
}
|
|
res = m_hashDungeonResInfo.get_next_value( pDungeonResInfo );
|
|
}
|
|
m_hashDungeonResInfo.clear();
|
|
}
|
|
|
|
void SDungeonResourceDB::Load()
|
|
{
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_DungeonResource.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(DungeonResource) * 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++ )
|
|
{
|
|
DungeonResource * pItem = new DungeonResource;
|
|
memset( pItem, 0, sizeof(DungeonResource) );
|
|
|
|
pRes->Read( pItem, sizeof(DungeonResource) );
|
|
|
|
DUNGEONRESOURCE_INFO* pFindItem = NULL;
|
|
if( m_hashDungeonResInfo.lookup( pItem->id, pFindItem ) == false )
|
|
{
|
|
pFindItem = new DUNGEONRESOURCE_INFO;
|
|
pFindItem->m_nDungeonID = pItem->id;
|
|
pFindItem->m_hashDungeonRes.add( pItem->local_flag, pItem );
|
|
|
|
m_hashDungeonResInfo.add( pItem->id, pFindItem );
|
|
}
|
|
else
|
|
{
|
|
pFindItem->m_hashDungeonRes.add( pItem->local_flag, pItem );
|
|
}
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
}
|
|
|
|
const DungeonResource* SDungeonResourceDB::GetDungeonRes( int nID, int nLocalFlag )
|
|
{
|
|
DUNGEONRESOURCE_INFO* pItem = NULL;
|
|
DungeonResource* pDungeon = NULL;
|
|
|
|
if (m_hashDungeonResInfo.lookup( nID, pItem ))
|
|
{
|
|
bool res = pItem->m_hashDungeonRes.get_first_value( pDungeon );
|
|
while ( res )
|
|
{
|
|
if ( pDungeon != NULL )
|
|
{
|
|
if ( pDungeon->local_flag & nLocalFlag )
|
|
{
|
|
return pDungeon;
|
|
}
|
|
}
|
|
res = pItem->m_hashDungeonRes.get_next_value( pDungeon );
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
const int SDungeonResourceDB::GetDungeonNameID( int nID )
|
|
{
|
|
return nID + 70000000;
|
|
}
|