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

📄 userfactory.cpp

📁 奇迹世界 部分源代码奇迹世界 部分源代码奇迹世界 部分源代码
💻 CPP
字号:
#include "stdafx.h"
#include ".\userfactory.h"
#include ".\User.h"
#include "TempUser.h"
#include "ActiveUser.h"

UserFactory::UserFactory()
{
	m_pTempUserPool		= new util::CMemoryPoolFactory<TempUser>;
	m_pActiveUserPool	= new util::CMemoryPoolFactory<ActiveUser>;
}

UserFactory::~UserFactory()
{
	delete m_pTempUserPool;
	delete m_pActiveUserPool;
}

VOID UserFactory::Release()
{
	m_pTempUserPool->Release();
	m_pActiveUserPool->Release();
}

VOID UserFactory::Init( DWORD dwUserSIze )
{
	m_pTempUserPool->Initialize( dwUserSIze, dwUserSIze/2+1 );
	m_pActiveUserPool->Initialize( dwUserSIze, dwUserSIze/2+1 );
}

User* UserFactory::Alloc( eUSER_TYPE type )
{
	User *pUser = NULL;

	switch( type )
	{
	case TEMP_USER:
		pUser = m_pTempUserPool->Alloc();
		break;
	case ACTIVE_USER:
		pUser = m_pActiveUserPool->Alloc();
		break;
	default:
		assert( !"肋给等 蜡廉 鸥涝 Alloc" );
	}
	
	pUser->Init();
	pUser->SetUserType( type );

	return pUser;
}

VOID UserFactory::Free( User* pUser )
{
	pUser->Release();

	switch( pUser->GetUserType() )
	{
	case TEMP_USER:
		m_pTempUserPool->Free( (TempUser*)pUser );
		break;
	case ACTIVE_USER:
		m_pActiveUserPool->Free( (ActiveUser*)pUser );
		break;
	default:
		assert( !"肋给等 蜡廉 鸥涝 Free" );
	}
}

⌨️ 快捷键说明

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