networkobjectfactorymgr.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. ** Command & Conquer Renegade(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWSaveLoad *
  23. * *
  24. * $Archive:: /Commando/Code/wwnet/networkobjectfactorymgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 5/18/01 2:35p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "networkobjectfactorymgr.h"
  36. #include "networkobjectfactory.h"
  37. #include "wwdebug.h"
  38. #include <string.h>
  39. ////////////////////////////////////////////////////////////////////////////
  40. // Static member initialization
  41. ////////////////////////////////////////////////////////////////////////////
  42. NetworkObjectFactoryClass *NetworkObjectFactoryMgrClass::_FactoryListHead = 0;
  43. ////////////////////////////////////////////////////////////////////////////
  44. //
  45. // Find_Factory
  46. //
  47. ////////////////////////////////////////////////////////////////////////////
  48. NetworkObjectFactoryClass *
  49. NetworkObjectFactoryMgrClass::Find_Factory (uint32 class_id)
  50. {
  51. NetworkObjectFactoryClass *factory = 0;
  52. //
  53. // Loop through all the factories and see if we can
  54. // find the one who owns the corresponding class-id.
  55. //
  56. for ( NetworkObjectFactoryClass *curr_factory = _FactoryListHead;
  57. (factory == 0) && (curr_factory != 0);
  58. curr_factory = curr_factory->NextFactory) {
  59. //
  60. // Is this the factory we were looking for?
  61. //
  62. if (curr_factory->Get_Class_ID () == class_id) {
  63. factory = curr_factory;
  64. }
  65. }
  66. return factory;
  67. }
  68. ////////////////////////////////////////////////////////////////////////////
  69. //
  70. // Get_First
  71. //
  72. ////////////////////////////////////////////////////////////////////////////
  73. NetworkObjectFactoryClass *
  74. NetworkObjectFactoryMgrClass::Get_First (void)
  75. {
  76. return _FactoryListHead;
  77. }
  78. ////////////////////////////////////////////////////////////////////////////
  79. //
  80. // Get_Next
  81. //
  82. ////////////////////////////////////////////////////////////////////////////
  83. NetworkObjectFactoryClass *
  84. NetworkObjectFactoryMgrClass::Get_Next (NetworkObjectFactoryClass *curr_factory)
  85. {
  86. NetworkObjectFactoryClass *factory = 0;
  87. //
  88. // Simply return the next factory in the chain
  89. //
  90. if (curr_factory != NULL) {
  91. factory = curr_factory->NextFactory;
  92. }
  93. return factory;
  94. }
  95. ////////////////////////////////////////////////////////////////////////////
  96. //
  97. // Register_Factory
  98. //
  99. ////////////////////////////////////////////////////////////////////////////
  100. void
  101. NetworkObjectFactoryMgrClass::Register_Factory (NetworkObjectFactoryClass *factory)
  102. {
  103. WWASSERT (factory->NextFactory == 0);
  104. WWASSERT (factory->PrevFactory == 0);
  105. Link_Factory (factory);
  106. return ;
  107. }
  108. ////////////////////////////////////////////////////////////////////////////
  109. //
  110. // Unregister_Factory
  111. //
  112. ////////////////////////////////////////////////////////////////////////////
  113. void
  114. NetworkObjectFactoryMgrClass::Unregister_Factory (NetworkObjectFactoryClass *factory)
  115. {
  116. WWASSERT (factory != 0);
  117. Unlink_Factory (factory);
  118. return ;
  119. }
  120. ////////////////////////////////////////////////////////////////////////////
  121. //
  122. // Link_Factory
  123. //
  124. ////////////////////////////////////////////////////////////////////////////
  125. void
  126. NetworkObjectFactoryMgrClass::Link_Factory (NetworkObjectFactoryClass *factory)
  127. {
  128. WWASSERT (factory->NextFactory == 0);
  129. WWASSERT (factory->PrevFactory == 0);
  130. // Adding this factory in front of the current head of the list
  131. factory->NextFactory = _FactoryListHead;
  132. // If the list wasn't empty, link the next factory back to this factory
  133. if (factory->NextFactory != 0) {
  134. factory->NextFactory->PrevFactory = factory;
  135. }
  136. // Point the head of the list at this factory now
  137. _FactoryListHead = factory;
  138. return ;
  139. }
  140. ////////////////////////////////////////////////////////////////////////////
  141. //
  142. // Unlink_Factory
  143. //
  144. ////////////////////////////////////////////////////////////////////////////
  145. void
  146. NetworkObjectFactoryMgrClass::Unlink_Factory (NetworkObjectFactoryClass *factory)
  147. {
  148. WWASSERT(factory != 0);
  149. // Handle the factory's prev pointer:
  150. if (factory->PrevFactory == 0) {
  151. // this factory is the head
  152. WWASSERT (_FactoryListHead == factory);
  153. _FactoryListHead = factory->NextFactory;
  154. } else {
  155. // link it's prev with it's next
  156. factory->PrevFactory->NextFactory = factory->NextFactory;
  157. }
  158. // Handle the factory's next pointer if its not at the end of the list:
  159. if (factory->NextFactory != 0) {
  160. factory->NextFactory->PrevFactory = factory->PrevFactory;
  161. }
  162. // factory is now un-linked
  163. factory->NextFactory = 0;
  164. factory->PrevFactory = 0;
  165. return ;
  166. }