From 364ac730501cde2c786a0fc97c7cd4907a6f88d2 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 20:35:09 -0800 Subject: [PATCH] Replace NetLinkingMgr LIST with std::list. --- .../plNetClient/plNetLinkingMgr.cpp | 72 +++++++++---------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index 03112b49..a6015300 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetCliAgeJoiner.h" #include "plNetCliAgeLeaver.h" +#include + #include "plNetTransport/plNetTransportMember.h" // OfferLinkToPlayer() #include "plgDispatch.h" @@ -70,8 +72,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com * ***/ -struct NlmOpNode; - enum ENlmOp { kNlmOpNoOp, kNlmOpWaitOp, @@ -82,7 +82,6 @@ enum ENlmOp { struct NlmOp { ENlmOp opcode; - NlmOpNode * node; NlmOp (const ENlmOp & op) : opcode(op) { } @@ -114,12 +113,6 @@ struct NlmLeaveAgeOp : NlmOp { { } }; -struct NlmOpNode { - LINK(NlmOpNode) link; - NlmOp * op; - ~NlmOpNode () { delete op; } -}; - /***************************************************************************** * @@ -129,7 +122,7 @@ struct NlmOpNode { static plNCAgeJoiner * s_ageJoiner; static plNCAgeLeaver * s_ageLeaver; -static LISTDECL(NlmOpNode, link) s_oplist; +static std::list s_opqueue; /***************************************************************************** @@ -140,10 +133,11 @@ static LISTDECL(NlmOpNode, link) s_oplist; //============================================================================ static void QueueOp (NlmOp * op, bool front = false) { - NlmOpNode * node = NEWZERO(NlmOpNode); - node->op = op; - op->node = node; - s_oplist.Link(node, front ? kListHead : kListTail); + if (front) { + s_opqueue.push_front(op); + } else { + s_opqueue.push_back(op); + } } @@ -186,8 +180,10 @@ void plNetLinkingMgr::NCAgeJoinerCallback ( lm->SetEnabled(true); // Pull our wait op off exec queue - if (NlmOpWaitOp * waitOp = (NlmOpWaitOp *) userState) - delete waitOp->node; + if (NlmOpWaitOp * waitOp = (NlmOpWaitOp *) userState) { + s_opqueue.remove(waitOp); + delete waitOp; + } } break; @@ -208,8 +204,10 @@ void plNetLinkingMgr::NCAgeLeaverCallback ( s_ageLeaver = nil; // Pull our wait op off exec queue - if (NlmOpWaitOp * waitOp = (NlmOpWaitOp *) userState) - delete waitOp->node; + if (NlmOpWaitOp * waitOp = (NlmOpWaitOp *) userState) { + s_opqueue.remove(waitOp); + delete waitOp; + } } break; @@ -221,28 +219,27 @@ void plNetLinkingMgr::NCAgeLeaverCallback ( void plNetLinkingMgr::ExecNextOp () { plNetLinkingMgr * lm = plNetLinkingMgr::GetInstance(); - NlmOpNode * opNode = s_oplist.Head(); - if (!opNode) + if (!s_opqueue.size()) return; - - switch (opNode->op->opcode) { - case kNlmOpNoOp: { - } - break; - - case kNlmOpWaitOp: { - } - return; // don't allow wait op to be unlinked/deleted from list - + + NlmOp* op = s_opqueue.front(); + + switch (op->opcode) { + case kNlmOpNoOp: + break; + + case kNlmOpWaitOp: + return; // don't allow wait op to be unlinked/deleted from list + case kNlmOpJoinAgeOp: { ASSERT(!s_ageJoiner); ASSERT(!s_ageLeaver); - + // Insert a wait operation into the exec queue NlmOpWaitOp * waitOp = NEWZERO(NlmOpWaitOp); QueueOp(waitOp, true); - - NlmJoinAgeOp * joinAgeOp = (NlmJoinAgeOp *) opNode->op; + + NlmJoinAgeOp * joinAgeOp = (NlmJoinAgeOp *)op; NCAgeJoinerCreate( &s_ageJoiner, joinAgeOp->age, @@ -251,7 +248,7 @@ void plNetLinkingMgr::ExecNextOp () { ); } break; - + case kNlmOpLeaveAgeOp: { ASSERT(!s_ageJoiner); ASSERT(!s_ageLeaver); @@ -263,7 +260,7 @@ void plNetLinkingMgr::ExecNextOp () { lm->SetEnabled(false); lm->fLinkedIn = false; - NlmLeaveAgeOp * leaveAgeOp = (NlmLeaveAgeOp *) opNode->op; + NlmLeaveAgeOp * leaveAgeOp = (NlmLeaveAgeOp *)op; NCAgeLeaverCreate( &s_ageLeaver, leaveAgeOp->quitting, @@ -273,8 +270,9 @@ void plNetLinkingMgr::ExecNextOp () { } break; } - - delete opNode; + + s_opqueue.pop_front(); + delete op; }