@@ -56,9 +56,6 @@ GameMessage::GameMessage( GameMessage::Type type )
5656{
5757 m_playerIndex = ThePlayerList->getLocalPlayer ()->getPlayerIndex ();
5858 m_type = type;
59- m_argList = nullptr ;
60- m_argTail = nullptr ;
61- m_argCount = 0 ;
6259 m_list = nullptr ;
6360}
6461
@@ -69,12 +66,8 @@ GameMessage::GameMessage( GameMessage::Type type )
6966GameMessage::~GameMessage ()
7067{
7168 // free all arguments
72- GameMessageArgument *arg, *nextArg;
73-
74- for ( arg = m_argList; arg; arg=nextArg )
75- {
76- nextArg = arg->m_next ;
77- deleteInstance (arg);
69+ for ( size_t i = 0 ; i < m_argList.size (); ++i ) {
70+ deleteInstance (m_argList[i]);
7871 }
7972
8073 // detach message from list
@@ -84,14 +77,11 @@ GameMessage::~GameMessage()
8477
8578/* *
8679 * Return the given argument union.
87- * @todo This should be a more list-like interface. Very inefficient.
8880 */
8981const GameMessageArgumentType *GameMessage::getArgument ( Int argIndex ) const
9082{
91- int i=0 ;
92- for ( GameMessageArgument *a = m_argList; a; a=a->m_next , i++ )
93- if (i == argIndex)
94- return &a->m_data ;
83+ if (static_cast <size_t >(argIndex) < m_argList.size ())
84+ return &m_argList[argIndex]->m_data ;
9585
9686 DEBUG_CRASH ((" argument not found" ));
9787 static const GameMessageArgumentType zero = { 0 };
@@ -103,17 +93,9 @@ const GameMessageArgumentType *GameMessage::getArgument( Int argIndex ) const
10393 */
10494GameMessageArgumentDataType GameMessage::getArgumentDataType ( Int argIndex ) const
10595{
106- if (argIndex >= m_argCount) {
107- return ARGUMENTDATATYPE_UNKNOWN ;
108- }
109- int i=0 ;
110- GameMessageArgument *a = m_argList;
111- for (; a && (i < argIndex); a=a->m_next , ++i );
96+ if (static_cast <size_t >(argIndex) < m_argList.size ())
97+ return m_argList[argIndex]->m_type ;
11298
113- if (a != nullptr )
114- {
115- return a->m_type ;
116- }
11799 return ARGUMENTDATATYPE_UNKNOWN ;
118100}
119101
@@ -124,21 +106,12 @@ GameMessageArgument *GameMessage::allocArg()
124106{
125107 // allocate a new argument
126108 GameMessageArgument *arg = newInstance (GameMessageArgument);
109+ m_argList.push_back (arg);
127110
128- // add to end of argument list
129- if (m_argTail)
130- m_argTail->m_next = arg;
131- else
132- {
133- m_argList = arg;
134- m_argTail = arg;
135- }
136-
137- arg->m_next = nullptr ;
138- m_argTail = arg;
139-
140- m_argCount++;
141-
111+ DEBUG_ASSERTCRASH (
112+ m_argList.size () <= 255 ,
113+ (" If a GameMessage needs more than 255 arguments, it needs to be split up into multiple GameMessage's." )
114+ );
142115 return arg;
143116}
144117
0 commit comments