⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zonemanager.cpp

📁 奇迹世界 部分源代码奇迹世界 部分源代码奇迹世界 部分源代码
💻 CPP
字号:
#include "StdAfx.h"
#include ".\zonemanager.h"

#include "Zone.h"
#include "Village.h"
#include "Lobby.h"
#include "Hunting.h"
#include "Mission.h"

ZoneManager g_ZoneManager;
KEYTYPE ZoneManager::s_ZoneKeyIndex = 0;

ZoneManager::ZoneManager(void):
m_pZoneHashTable ( NULL )
{
}

ZoneManager::~ZoneManager(void)
{
	Release();
}

VOID ZoneManager::Release()
{
	if( m_pZoneHashTable )
	{	
		Zone * pZone = NULL;
		m_pZoneHashTable->SetFirst();
		while( ( pZone = m_pZoneHashTable->GetNext() ) != NULL )
		{
			DestroyZone(pZone);
		}
		m_pZoneHashTable->RemoveAll();
		delete m_pZoneHashTable;
		m_pZoneHashTable = NULL;
	}
}

Village * ZoneManager::CreateVillage( CODETYPE MapCode )
{
	Village * pNewVillage = Village::Create();
	pNewVillage->Init( MapCode );
	addZone( pNewVillage );

	return pNewVillage;

}
VOID ZoneManager::DestroyZone( Zone * pZone )
{
	pZone->Release();

	switch(pZone->GetType())
	{
	case Zone::eZONE_VILLAGE:
		Village::Destroy( (Village *)pZone ); break;
	case Zone::eZONE_LOBBY:
		Lobby::Destroy( (Lobby *)pZone ); break;
	case Zone::eZONE_HUNTING:
		Hunting::Destroy( (Hunting *)pZone ); break;
	case Zone::eZONE_MISSION:
		Mission::Destroy( (Mission *)pZone ); break;
	default:
		{
			SASSERT( NULL, "肋给等 粮 鸥涝" );
		}
	}
}

VOID ZoneManager::Init( DWORD dwZonePoolSize )
{
	ASSERT( !m_pZoneHashTable );
	m_pZoneHashTable = new util::SolarHashTable<Zone *>;
	m_pZoneHashTable->Initialize( dwZonePoolSize );
}

VOID ZoneManager::addZone( Zone * pZone )
{
	ASSERT( pZone->GetKey() != 0 );
	ASSERT( NULL == m_pZoneHashTable->GetData( pZone->GetKey() ) );
	m_pZoneHashTable->Add( pZone, pZone->GetKey() );
}

VOID ZoneManager::removeZone( KEYTYPE Key )
{
	ASSERT( Key != 0 );
	ASSERT( NULL != m_pZoneHashTable->GetData( Key ) );
	m_pZoneHashTable->Remove( Key );
}

KEYTYPE ZoneManager::generateZoneKey()
{
	return s_ZoneKeyIndex++;
}

VOID ZoneManager::Update( DWORD dwDeltaTick )
{
	Zone * pZone = NULL;
	m_pZoneHashTable->SetFirst();
	while( ( pZone = m_pZoneHashTable->GetNext() ) != NULL )
	{
		if( !pZone->Update( dwDeltaTick ) )
		{
			// 颇鲍
			removeZone( pZone->GetKey() );
			DestroyZone( pZone );
		}
	}
}

VOID ZoneManager::zone_print()
{
	DWORD village = 0;
	DWORD lobby = 0;
	DWORD mission = 0;
	DWORD hunting = 0;


	Zone * pZone = NULL;
	m_pZoneHashTable->SetFirst();
	while( ( pZone = m_pZoneHashTable->GetNext() ) != NULL )
	{
		switch(pZone->GetType())
		{
		case Zone::eZONE_VILLAGE:
			++village; break;
		case Zone::eZONE_LOBBY:
			++lobby; break;
		case Zone::eZONE_MISSION:
			++mission; break;
		case Zone::eZONE_HUNTING:
			++hunting; break;			
		}
	}

	DISPMSG( "==============\n" );
	DISPMSG( "Village : %d\n", village );
	DISPMSG( "Lobby   : %d\n", lobby );
	DISPMSG( "Mission : %d\n", mission );
	DISPMSG( "Hunting : %d\n", hunting );
	DISPMSG( "==============\n" );

}

VOID ZoneManager::zone_print( KEYTYPE Key )
{
	Zone * pZone = m_pZoneHashTable->GetData( Key );
	if( !pZone ) return;

	DISPMSG( "==============\n" );
	switch(pZone->GetType())
	{
	case Zone::eZONE_VILLAGE:
		DISPMSG( "Village\n" );
	case Zone::eZONE_LOBBY:
		DISPMSG( "Lobbyn\n" );
	case Zone::eZONE_MISSION:
		DISPMSG( "Mission\n" );
	case Zone::eZONE_HUNTING:
		DISPMSG( "Hunting\n" );
	}
	DISPMSG( "Player's Num:%d\n", pZone->GetNumberOfPlayers() );
	DISPMSG( "==============\n" );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -