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

📄 servermem.cpp

📁 韩国英雄王座倒闭后流出来部分源代码
💻 CPP
字号:
//	ServerMem.cpp: implementation of the ServerMem class.
//
//
//
//	Server俊辑 荤侩登绰	Memory甫 包府
////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ServerMem.h"

#include "npc.h"

////////////////////////////////////////////////////////////////////////////////////////
// Construction/Destruction
////////////////////////////////////////////////////////////////////////////////////////
ServerMem::ServerMem()
{
	//	--------------------------------------------------------------------------------
	//	Map Server侩 Memory甫 积己矫糯 - MAX_SOCKET_CONTEXT俺 积己
	//	--------------------------------------------------------------------------------
	m_listZemiPacket.RemoveAll();
#ifdef DEF_NEWREGISTRY 
	for( int i=0; i < _Module.m_dwMaxUser / 2 ; i ++ )
#else
	for( int i=0; i < MAX_SOCKET_CONTEXT / 2 ; i ++ )
#endif
	{
		_LPZEMIPACKET pZemiPacket	=	 new _ZEMIPACKET  ;

		m_listZemiPacket.AddTail( pZemiPacket );
	}

	//	--------------------------------------------------------------------------------
	//	World Server侩 Memory甫 积己 矫糯
	//	--------------------------------------------------------------------------------
	m_listWorldPacket.RemoveAll();

	//	--------------------------------------------------------------------------------
	//	Active Quest侩 Memory甫 积己 矫糯 - MAX_SOCKET_CONTEXT * 5俺 积己
	//	--------------------------------------------------------------------------------
	m_listActiveQuest.RemoveAll();

#ifdef DEF_NEWREGISTRY 
	for(  i=0; i < (_Module.m_dwMaxUser / 10) ; i ++ )
#else
	for(  i=0; i < (MAX_SOCKET_CONTEXT / 10) ; i ++ )
#endif
	{
		CActiveQuest  *pAtiveQuest = new CActiveQuest;

		m_listActiveQuest.AddTail( pAtiveQuest );
	}


#ifdef DEF_CHECK_QUESTDONE
	m_listQuestDoneInfo.RemoveAll();

#ifdef DEF_NEWREGISTRY 
	for(  i=0; i < (_Module.m_dwMaxUser / 10) ; i ++ )
#else
	for(  i=0; i < (MAX_SOCKET_CONTEXT / 10) ; i ++ )
#endif
	{
		_QUEST_SUCCESS_INFO  *pQuestDone = new _QUEST_SUCCESS_INFO;

		m_listQuestDoneInfo.AddTail( pQuestDone );
	}
#endif

	
	//	--------------------------------------------------------------------------------
	//	概流/饭绢狼 何窍 棺 家券 Monster俊 荤侩瞪 POOL阑 积己 矫糯
	//	--------------------------------------------------------------------------------
	m_PoolMonster.Clear();

	for( i=0; i < MAX_MONSTERPOOL_NUM; i ++ )
	{
		NPC	*pNPC	=	new NPC;

		if( !pNPC )	return;

		m_PoolMonster.Insert( pNPC );
	}
	
#ifdef DEF_NEWREGISTRY 
	m_AIMsgPool = new CMemPool<CAIMsg>(_Module.m_dwMaxUser);
#else
	m_AIMsgPool = new CMemPool<CAIMsg>(MAX_SOCKET_CONTEXT);
#endif


#ifdef DEF_NEWREGISTRY 
	m_GuildSkillPool = new CMemPool<CGuildSkill>(_Module.m_dwMaxUser/50 + 2);
#else
	m_GuildSkillPool = new CMemPool<CGuildSkill>(MAX_SOCKET_CONTEXT/50  + 2);
#endif



}


ServerMem::~ServerMem()
{
	//	--------------------------------------------------------------------------------
	//	Map Server侩 Memory甫 昏力矫糯
	//	--------------------------------------------------------------------------------
	for(POSITION pos = m_listZemiPacket.GetHeadPosition(); pos != NULL;)
	{
		_LPZEMIPACKET pZemiPacket = (_LPZEMIPACKET) m_listZemiPacket.GetNext(pos);

		if( pZemiPacket)
		{
			delete pZemiPacket ;
			pZemiPacket	=	NULL;
		}	
	}
	m_listZemiPacket.RemoveAll();


	//	--------------------------------------------------------------------------------
	//	World Packet侩 Memory甫 昏力矫糯
	//	--------------------------------------------------------------------------------
	for( pos = m_listWorldPacket.GetHeadPosition(); pos != NULL;)
	{
		_LPDBPACKET	 pWorldPacket = (_LPDBPACKET ) m_listWorldPacket.GetNext(pos);

		if( pWorldPacket)
		{
			delete pWorldPacket ;
			pWorldPacket	=	NULL;
		}	
	}
	m_listWorldPacket.RemoveAll();


	//	--------------------------------------------------------------------------------
	//	Active Quest侩 Memory甫 昏力矫糯
	//	--------------------------------------------------------------------------------
	for(  pos = m_listActiveQuest.GetHeadPosition(); pos != NULL;)
	{

		// 夸扒 肋给登辑 绊魔 -- define巩 昏力..
		CActiveQuest	*pAtiveQuest = (CActiveQuest *) m_listActiveQuest.GetNext(pos);
				
		if( pAtiveQuest )
		{
			delete pAtiveQuest;
			pAtiveQuest	=	NULL;
		}			
	}
	m_listActiveQuest.RemoveAll();

#ifdef DEF_CHECK_QUESTDONE
	for(  pos = m_listQuestDoneInfo.GetHeadPosition(); pos != NULL;)
	{
		_QUEST_SUCCESS_INFO	*pQuestDone = (_QUEST_SUCCESS_INFO *) m_listQuestDoneInfo.GetNext(pos);
		
		if( pQuestDone )
		{
			delete pQuestDone;
			pQuestDone	=	NULL;
		}			
	}
	m_listQuestDoneInfo.RemoveAll();
#endif


	//	--------------------------------------------------------------------------------
	//	Active Quest侩 Memory甫 昏力矫糯
	//	--------------------------------------------------------------------------------
	LIST_VOIDPTR::iterator	itEnd = m_PoolMonster.End() ;
	for (LIST_VOIDPTR::iterator it = m_PoolMonster.Begin(); it != itEnd; it++)
	{	
		NPC *pNPC = (NPC *)*it;			

		if( pNPC )
		{
			delete pNPC;
			pNPC = NULL;
		}
	}	
	
	m_PoolMonster.Clear();

	SAFE_DELETE< CMemPool<CAIMsg> > (&m_AIMsgPool) ;
	SAFE_DELETE<CMemPool<CGuildSkill> > (&m_GuildSkillPool) ;


}


////////////////////////////////////////////////////////////////////////////////////////
//	ZEMIPACKET Memory甫 掘澜
////////////////////////////////////////////////////////////////////////////////////////
_LPZEMIPACKET ServerMem::ZemiPacket_Pop()
{	
	_LPZEMIPACKET pZemiPacket	= (_LPZEMIPACKET)m_listZemiPacket.RemoveHead();
	
	if( pZemiPacket )
	{
		memset( pZemiPacket, 0x00, sizeof(_ZEMIPACKET) );
	}
	else
	{
		pZemiPacket	= new  _ZEMIPACKET  ;
		memset( pZemiPacket, 0x00, sizeof(_ZEMIPACKET) );
	}
	
	return pZemiPacket;
}

////////////////////////////////////////////////////////////////////////////////////////
//	ZEMIPACKET Memory甫 馆券
////////////////////////////////////////////////////////////////////////////////////////
void ServerMem::ZemiPacket_Push(_LPZEMIPACKET pZemiPacket)
{
	if( pZemiPacket )
		m_listZemiPacket.AddTail( pZemiPacket );
}

////////////////////////////////////////////////////////////////////////////////////////
//	Active Quest甫 掘澜
//
//	
////////////////////////////////////////////////////////////////////////////////////////
CActiveQuest* ServerMem::ActiveQuest_Pop()
{	
	CActiveQuest *pActiveQuest = (CActiveQuest *)m_listActiveQuest.RemoveHead();
	
	if(!pActiveQuest)
	{
		pActiveQuest = new CActiveQuest;
	}

	//		
	pActiveQuest->SetPoolUse( true );

	return pActiveQuest;
}

////////////////////////////////////////////////////////////////////////////////////////
//	Active Quest甫 馆券
////////////////////////////////////////////////////////////////////////////////////////
void ServerMem::ActiveQuest_Push(CActiveQuest *pActiveQuest)
{	
	if( !pActiveQuest )	return;

	//
	//	秦寸 Active Quest啊 馆券等 版快 
	//	
	if( !pActiveQuest->GetPoolUse() )
	{
		//apLog("(X) (%d) Pool_Monster_Push Debug Code=(%d)", _Module.m_nMapSeq ) ;
		ErrorMsg( "(X) ServerMem : Active Quest Push Error" ) ;
		return;
	}

	m_listActiveQuest.AddTail( pActiveQuest );
	pActiveQuest->SetPoolUse( false );
}


#ifdef DEF_CHECK_QUESTDONE

_QUEST_SUCCESS_INFO* ServerMem::QuestSuccessInfo_Pop()
{	
	_QUEST_SUCCESS_INFO *pQuestDone = (_QUEST_SUCCESS_INFO *)m_listQuestDoneInfo.RemoveHead();
	
	if(!pQuestDone)
	{
		pQuestDone = new _QUEST_SUCCESS_INFO;
	}

	//		
	pQuestDone->SetPoolUse( true );

	return pQuestDone;
}


void ServerMem::QuestSuccessInfo_Push(_QUEST_SUCCESS_INFO *pQuestDone)
{	
	if( !pQuestDone )	return;

	//
	//	秦寸 Active Quest啊 馆券等 版快 
	//	
	if( !pQuestDone->GetPoolUse() )
	{		
		ErrorMsg( "(X) ServerMem : QuestSuccessInfo Push Error" ) ;
		return;
	}

	m_listQuestDoneInfo.AddTail( pQuestDone );
	pQuestDone->SetPoolUse( false );
}


#endif

////////////////////////////////////////////////////////////////////////////////////////
//	DBPACKET Memory甫 掘澜
////////////////////////////////////////////////////////////////////////////////////////
_LPDBPACKET ServerMem::WorldPacket_Pop()
{
	_LPDBPACKET	 pWorldPacket	= (_LPDBPACKET)m_listWorldPacket.RemoveHead();
	
	if( pWorldPacket )
	{
		memset( pWorldPacket, 0x00, sizeof(_DBPACKET) );
	}
	else
	{
		pWorldPacket	=	new   _DBPACKET ;
		memset( pWorldPacket, 0x00, sizeof(_DBPACKET) );
	}
	
	return pWorldPacket;
}

////////////////////////////////////////////////////////////////////////////////////////
//	DBPACKET Memory甫 馆券
////////////////////////////////////////////////////////////////////////////////////////
void ServerMem::WorldPacket_Push(_LPDBPACKET pWorldPacket)
{
	if( pWorldPacket )
		m_listWorldPacket.AddTail( pWorldPacket );
}

////////////////////////////////////////////////////////////////////////////////////////
//	NPC Mempry POP
////////////////////////////////////////////////////////////////////////////////////////
NPC* ServerMem::Pool_Monster_Pop()
{
	NPC *pNPC = (NPC *)m_PoolMonster.RemoveHead();

	if( NULL == pNPC )
	{
		pNPC = new NPC ;
	}

	//	Item Pool	荤侩
	pNPC->m_bPoolUse	=	true;		

	return pNPC;
}

////////////////////////////////////////////////////////////////////////////////////////
//	NPC memory Push
////////////////////////////////////////////////////////////////////////////////////////
void ServerMem::Pool_Monster_Push(void *pNPC, int pDebugCode )
{	
	if( !((NPC *)pNPC)->m_bPoolUse	)
	{
		MapLog("(X) (%d) Pool_Monster_Push Debug Code=(%d)", _Module.m_nMapSeq, pDebugCode ) ;
		return;
	}

	//	Item Pool	馆券
	((NPC *)pNPC)->m_bPoolUse =	false;

	m_PoolMonster.Insert( pNPC );
}

⌨️ 快捷键说明

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