@@ -88,12 +88,8 @@ Int NetCommandMsg::getSortNumber() const {
8888 * Constructor with no argument, sets everything to default values.
8989 */
9090NetGameCommandMsg::NetGameCommandMsg () {
91- m_argSize = 0 ;
92- m_numArgs = 0 ;
9391 m_type = (GameMessage::Type)0 ;
9492 m_commandType = NETCOMMANDTYPE_GAMECOMMAND ;
95- m_argList = nullptr ;
96- m_argTail = nullptr ;
9793}
9894
9995/* *
@@ -102,23 +98,24 @@ NetGameCommandMsg::NetGameCommandMsg() {
10298 */
10399NetGameCommandMsg::NetGameCommandMsg (GameMessage *msg) {
104100 m_commandType = NETCOMMANDTYPE_GAMECOMMAND ;
105-
106101 m_type = msg->getType ();
107- Int count = msg->getArgumentCount ();
108- for (Int i = 0 ; i < count; ++i) {
109- addArgument (msg->getArgumentDataType (i), *(msg->getArgument (i)));
102+
103+ const size_t argsCount = msg->getArgumentCount ();
104+ m_argList.reserve (argsCount);
105+
106+ for (size_t i = 0 ; i < argsCount; ++i) {
107+ GameMessageArgumentDataType argType = msg->getArgumentDataType (i);
108+ const GameMessageArgumentType* arg = msg->getArgument (i);
109+ addArgument (argType, *arg);
110110 }
111111}
112112
113113/* *
114114 * Destructor
115115 */
116116NetGameCommandMsg::~NetGameCommandMsg () {
117- GameMessageArgument *arg = m_argList;
118- while (arg != nullptr ) {
119- m_argList = m_argList->m_next ;
120- deleteInstance (arg);
121- arg = m_argList;
117+ for (size_t i = 0 ; i < m_argList.size (); ++i) {
118+ deleteInstance (m_argList[i]);
122119 }
123120}
124121
@@ -127,21 +124,10 @@ NetGameCommandMsg::~NetGameCommandMsg() {
127124 */
128125void NetGameCommandMsg::addArgument (const GameMessageArgumentDataType type, GameMessageArgumentType arg)
129126{
130- if (m_argTail == nullptr ) {
131- m_argList = newInstance (GameMessageArgument);
132- m_argTail = m_argList;
133- m_argList->m_data = arg;
134- m_argList->m_type = type;
135- m_argList->m_next = nullptr ;
136- return ;
137- }
138-
139127 GameMessageArgument *newArg = newInstance (GameMessageArgument);
140128 newArg->m_data = arg;
141129 newArg->m_type = type;
142- newArg->m_next = nullptr ;
143- m_argTail->m_next = newArg;
144- m_argTail = newArg;
130+ m_argList.push_back (newArg);
145131}
146132
147133// here's where we figure out which slot corresponds to which player
@@ -171,9 +157,8 @@ GameMessage *NetGameCommandMsg::constructGameMessage() const
171157 name.format (" player%d" , getPlayerID ());
172158 retval->friend_setPlayerIndex ( ThePlayerList->findPlayerWithNameKey (TheNameKeyGenerator->nameToKey (name))->getPlayerIndex ());
173159
174- GameMessageArgument *arg = m_argList;
175- while (arg != nullptr ) {
176-
160+ for (size_t i = 0 ; i < m_argList.size (); ++i) {
161+ const GameMessageArgument* arg = m_argList[i];
177162 switch (arg->m_type ) {
178163
179164 case ARGUMENTDATATYPE_INTEGER :
@@ -211,8 +196,6 @@ GameMessage *NetGameCommandMsg::constructGameMessage() const
211196 break ;
212197
213198 }
214-
215- arg = arg->m_next ;
216199 }
217200 return retval;
218201}
0 commit comments