GameMessageParser.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  24. #include "GameNetwork/GameMessageParser.h"
  25. //----------------------------------------------------------------------------
  26. GameMessageParser::GameMessageParser()
  27. {
  28. m_first = NULL;
  29. m_argTypeCount = 0;
  30. }
  31. //----------------------------------------------------------------------------
  32. GameMessageParser::GameMessageParser(GameMessage *msg)
  33. {
  34. m_first = NULL;
  35. m_argTypeCount = 0;
  36. UnsignedByte argCount = msg->getArgumentCount();
  37. GameMessageArgumentDataType lasttype = ARGUMENTDATATYPE_UNKNOWN;
  38. Int thisTypeCount = 0;
  39. for (UnsignedByte i = 0; i < argCount; ++i) {
  40. GameMessageArgumentDataType type = msg->getArgumentDataType(i);
  41. if (type != lasttype) {
  42. if (thisTypeCount > 0) {
  43. addArgType(lasttype, thisTypeCount);
  44. ++m_argTypeCount;
  45. }
  46. lasttype = type;
  47. thisTypeCount = 0;
  48. }
  49. ++thisTypeCount;
  50. }
  51. if (thisTypeCount > 0) {
  52. addArgType(lasttype, thisTypeCount);
  53. ++m_argTypeCount;
  54. }
  55. }
  56. //----------------------------------------------------------------------------
  57. GameMessageParser::~GameMessageParser()
  58. {
  59. GameMessageParserArgumentType *temp = NULL;
  60. while (m_first != NULL) {
  61. temp = m_first->getNext();
  62. m_first->deleteInstance();
  63. m_first = temp;
  64. }
  65. }
  66. //----------------------------------------------------------------------------
  67. void GameMessageParser::addArgType(GameMessageArgumentDataType type, Int argCount)
  68. {
  69. if (m_first == NULL) {
  70. m_first = newInstance(GameMessageParserArgumentType)(type, argCount);
  71. m_last = m_first;
  72. return;
  73. }
  74. m_last->setNext(newInstance(GameMessageParserArgumentType)(type, argCount));
  75. m_last = m_last->getNext();
  76. }
  77. //----------------------------------------------------------------------------
  78. GameMessageParserArgumentType::GameMessageParserArgumentType(GameMessageArgumentDataType type, Int argCount)
  79. {
  80. m_next = NULL;
  81. m_type = type;
  82. m_argCount = argCount;
  83. }
  84. //----------------------------------------------------------------------------
  85. GameMessageParserArgumentType::~GameMessageParserArgumentType()
  86. {
  87. }