297 lines
6.4 KiB
C++
297 lines
6.4 KiB
C++
#include "stdafx.h"
|
|
#include "SSoundResourceDB.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;
|
|
|
|
SResourceDB* SResourceDB::m_pThis = NULL;
|
|
SResourceDB & GetResourceDB()
|
|
{
|
|
if( NULL == SResourceDB::m_pThis )
|
|
SResourceDB::m_pThis = new SResourceDB;
|
|
|
|
return *SResourceDB::m_pThis;
|
|
// static SResourceDB resource;
|
|
// return resource;
|
|
}
|
|
|
|
SResourceDB::SResourceDB()
|
|
{
|
|
}
|
|
|
|
SResourceDB::~SResourceDB()
|
|
{
|
|
}
|
|
|
|
const char* SResourceDB::GetSoundResourceName( int nSoundID )
|
|
{
|
|
return m_SoundResDB.GetSoundResourceName( nSoundID );
|
|
}
|
|
|
|
const char* SResourceDB::GetEffectResourceName( int nEffectID )
|
|
{
|
|
return m_EffectResDB.GetEffectResourceName( nEffectID );
|
|
}
|
|
|
|
const char* SResourceDB::GetTextureResourceName( int nTextureID )
|
|
{
|
|
return m_TextureResDB.GetTextureResourceName( nTextureID );
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
//
|
|
SSoundResourceDB::SSoundResourceDB()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
SSoundResourceDB::~SSoundResourceDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void SSoundResourceDB::Init()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void SSoundResourceDB::Destroy()
|
|
{
|
|
SoundResource* pSoundResource = NULL;
|
|
bool res;
|
|
res = m_hashSoundResource.get_first_value( pSoundResource );
|
|
while ( res )
|
|
{
|
|
if ( pSoundResource != NULL )
|
|
{
|
|
delete pSoundResource;
|
|
}
|
|
res = m_hashSoundResource.get_next_value( pSoundResource );
|
|
}
|
|
m_hashSoundResource.clear();
|
|
}
|
|
|
|
void SSoundResourceDB::Load()
|
|
{
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_SoundResource.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(SoundResource) * 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++ )
|
|
{
|
|
SoundResource * pItem = new SoundResource;
|
|
memset( pItem, 0, sizeof(SoundResource) );
|
|
|
|
pRes->Read( pItem, sizeof(SoundResource) );
|
|
|
|
SoundResource* pFindItem = NULL;
|
|
if( m_hashSoundResource.lookup( pItem->sound_ID, pFindItem ) == false )
|
|
{
|
|
m_hashSoundResource.add( pItem->sound_ID, pItem );
|
|
}
|
|
else
|
|
{
|
|
_oprint( "!!!!Data Error SSoundResource Code 가 중복되었습니다.!!!! \n" );
|
|
assert(0); //기획팀에 알려 주세여. 바로 수정 해야 합니다.
|
|
|
|
delete pItem;
|
|
}
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
}
|
|
|
|
const char* SSoundResourceDB::GetSoundResourceName( int nSoundID )
|
|
{
|
|
SoundResource* pFindItem = NULL;
|
|
if( m_hashSoundResource.lookup( nSoundID, pFindItem ) )
|
|
{
|
|
return pFindItem->sound_Name;
|
|
}
|
|
|
|
return "NotFound_Sound";
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
//
|
|
SEffectResourceDB::SEffectResourceDB()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
SEffectResourceDB::~SEffectResourceDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void SEffectResourceDB::Init()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void SEffectResourceDB::Destroy()
|
|
{
|
|
EffectResource* pEffectResource = NULL;
|
|
bool res;
|
|
res = m_hashEffectResource.get_first_value( pEffectResource );
|
|
while ( res )
|
|
{
|
|
if ( pEffectResource != NULL )
|
|
{
|
|
delete pEffectResource;
|
|
}
|
|
res = m_hashEffectResource.get_next_value( pEffectResource );
|
|
}
|
|
m_hashEffectResource.clear();
|
|
}
|
|
|
|
void SEffectResourceDB::Load()
|
|
{
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_EffectResource.rdb" );
|
|
if( !pRes ) return;
|
|
GAME_DB db_hdr;
|
|
|
|
pRes->Read( &db_hdr, sizeof(db_hdr) );
|
|
for( int i(0); db_hdr.nCount>i; i++ )
|
|
{
|
|
EffectResource * pItem = new EffectResource;
|
|
memset( pItem, 0, sizeof(EffectResource) );
|
|
|
|
pRes->Read( pItem, sizeof(EffectResource) );
|
|
|
|
EffectResource* pFindItem = NULL;
|
|
if( m_hashEffectResource.lookup( pItem->resource_effect_file_id, pFindItem ) == false )
|
|
{
|
|
m_hashEffectResource.add( pItem->resource_effect_file_id, pItem );
|
|
}
|
|
else
|
|
{
|
|
_oprint( "!!!!Data Error SEffectResourceDB Code 가 중복되었습니다.!!!! \n" );
|
|
assert(0); //기획팀에 알려 주세여. 바로 수정 해야 합니다.
|
|
|
|
delete pItem;
|
|
}
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
}
|
|
|
|
const char* SEffectResourceDB::GetEffectResourceName( int nEffectID )
|
|
{
|
|
EffectResource* pFindItem = NULL;
|
|
if( m_hashEffectResource.lookup( nEffectID, pFindItem ) )
|
|
{
|
|
return pFindItem->resource_effect_file_name;
|
|
}
|
|
|
|
return "NotFound_Sound";
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
//
|
|
STextureResourceDB::STextureResourceDB()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
STextureResourceDB::~STextureResourceDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void STextureResourceDB::Init()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void STextureResourceDB::Destroy()
|
|
{
|
|
TextureResource* pTextureResource = NULL;
|
|
bool res;
|
|
res = m_hashTextureResource.get_first_value( pTextureResource );
|
|
while ( res )
|
|
{
|
|
if ( pTextureResource != NULL )
|
|
{
|
|
delete pTextureResource;
|
|
}
|
|
res = m_hashTextureResource.get_next_value( pTextureResource );
|
|
}
|
|
m_hashTextureResource.clear();
|
|
}
|
|
|
|
void STextureResourceDB::Load()
|
|
{
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_TextureResource.rdb" );
|
|
if( !pRes ) return;
|
|
GAME_DB db_hdr;
|
|
|
|
pRes->Read( &db_hdr, sizeof(db_hdr) );
|
|
for( int i(0); db_hdr.nCount>i; i++ )
|
|
{
|
|
TextureResource * pItem = new TextureResource;
|
|
memset( pItem, 0, sizeof(TextureResource) );
|
|
|
|
pRes->Read( pItem, sizeof(TextureResource) );
|
|
|
|
TextureResource* pFindItem = NULL;
|
|
if( m_hashTextureResource.lookup( pItem->resource_texture_file_id, pFindItem ) == false )
|
|
{
|
|
m_hashTextureResource.add( pItem->resource_texture_file_id, pItem );
|
|
}
|
|
else
|
|
{
|
|
_oprint( "!!!!Data Error STextureResourceDB Code 가 중복되었습니다.!!!! \n" );
|
|
assert(0); //기획팀에 알려 주세여. 바로 수정 해야 합니다.
|
|
|
|
delete pItem;
|
|
}
|
|
}
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
}
|
|
|
|
const char* STextureResourceDB::GetTextureResourceName( int nTextureID )
|
|
{
|
|
TextureResource* pFindItem = NULL;
|
|
if( m_hashTextureResource.lookup( nTextureID, pFindItem ) )
|
|
{
|
|
return pFindItem->resource_texture_file_name;
|
|
}
|
|
|
|
return "NotFound_Sound";
|
|
} |