?? servermem.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 + -