📄 mapallocator.cpp
字号:
#include "stdafx.h"
#include ".\mapallocator.h"
#include "Map.h"
#include "MapInfoLoader.h"
#include "FieldInfo.h"
#include "Field.h"
#include "Sector.h"
#include "SectorGroup.h"
MapAllocator g_MapAllocator;
MapAllocator::MapAllocator()
{
m_pMapPool = new CMemoryPoolFactory<Map>;
m_pFieldPool = new CMemoryPoolFactory<Field>;
m_pSectorPool = new CMemoryPoolFactory<Sector>;
m_pSectorGroupPool = new CMemoryPoolFactory<SectorGroup>;
m_pMapInfoLoader = new MapInfoLoader;
}
MapAllocator::~MapAllocator()
{
SAFE_DELETE( m_pMapInfoLoader );
SAFE_DELETE( m_pSectorPool );
SAFE_DELETE( m_pFieldPool );
SAFE_DELETE( m_pSectorGroupPool );
SAFE_DELETE( m_pMapPool );
}
VOID MapAllocator::Init( DWORD MapPoolSize, DWORD SectorPoolSize, WORD wVillageSectorSize, WORD wRoomSectorSize )
{
m_pMapPool->Initialize( MapPoolSize, MapPoolSize/2+1 );
m_pFieldPool->Initialize( MapPoolSize, MapPoolSize/2+1 );
m_pSectorPool->Initialize( SectorPoolSize, SectorPoolSize/2+1 );
m_pSectorGroupPool->Initialize( SectorPoolSize/25, SectorPoolSize/50+1 );
m_pMapInfoLoader->EstablishInfo( wVillageSectorSize, wRoomSectorSize );
}
VOID MapAllocator::Release()
{
m_pMapInfoLoader->UnloadInfo();
m_pSectorPool->Release();
m_pSectorGroupPool->Release();
m_pFieldPool->Release();
m_pMapPool->Release();
}
Map * MapAllocator::AllocMap( MAPID sid, int iFieldIndex )
{
MapInfo * pMapInfo = m_pMapInfoLoader->GetMapInfo( sid );
SASSERT( pMapInfo != NULL, VSTR("[%d]锅甘捞 绝促.", sid) );
if( !pMapInfo ) return NULL;
Map * pNewMap = m_pMapPool->Alloc();
pNewMap->Init( pMapInfo, iFieldIndex, m_pFieldPool, m_pSectorGroupPool, m_pSectorPool );
return pNewMap;
}
VOID MapAllocator::FreeMap( Map * pMap )
{
pMap->Release( m_pFieldPool, m_pSectorGroupPool, m_pSectorPool );
m_pMapPool->Free( pMap );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -