gameProcess.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/engineAPI.h"
  23. #include "platform/platform.h"
  24. #include "T3D/gameBase/gameProcess.h"
  25. #include "T3D/gameBase/gameBase.h"
  26. #include "T3D/gameBase/gameConnection.h"
  27. #include "T3D/gameBase/moveList.h"
  28. //----------------------------------------------------------------------------
  29. ClientProcessList* ClientProcessList::smClientProcessList = NULL;
  30. ServerProcessList* ServerProcessList::smServerProcessList = NULL;
  31. static U32 gNetOrderNextId = 0;
  32. DefineEngineFunction( dumpProcessList, void, ( ), ,
  33. "Dumps all ProcessObjects in ServerProcessList and ClientProcessList to the console." )
  34. {
  35. Con::printf( "client process list:" );
  36. ClientProcessList::get()->dumpToConsole();
  37. Con::printf( "server process list:" );
  38. ServerProcessList::get()->dumpToConsole();
  39. }
  40. //--------------------------------------------------------------------------
  41. // ClientProcessList
  42. //--------------------------------------------------------------------------
  43. ClientProcessList::ClientProcessList()
  44. {
  45. }
  46. void ClientProcessList::addObject( ProcessObject *pobj )
  47. {
  48. AssertFatal( static_cast<SceneObject*>( pobj )->isClientObject(), "Tried to add server object to ClientProcessList." );
  49. GameBase *obj = getGameBase( pobj );
  50. if ( obj && obj->isNetOrdered() )
  51. {
  52. if ( ( gNetOrderNextId & 0xFFFF ) == 0 )
  53. // don't let it be zero
  54. gNetOrderNextId++;
  55. pobj->mOrderGUID = ( gNetOrderNextId++ ) & 0xFFFF; // 16 bits should be enough
  56. pobj->plLinkBefore( &mHead );
  57. mDirty = true;
  58. }
  59. else if ( obj && obj->isTickLast() )
  60. {
  61. pobj->mOrderGUID = 0xFFFFFFFF;
  62. pobj->plLinkBefore( &mHead );
  63. // not dirty
  64. }
  65. else
  66. {
  67. pobj->plLinkAfter( &mHead );
  68. // not dirty
  69. }
  70. }
  71. bool ClientProcessList::doBacklogged( SimTime timeDelta )
  72. {
  73. #ifdef TORQUE_DEBUG
  74. static bool backlogged = false;
  75. static U32 backloggedTime = 0;
  76. #endif
  77. // See if the control object has pending moves.
  78. GameConnection *connection = GameConnection::getConnectionToServer();
  79. if ( connection )
  80. {
  81. // If the connection to the server is backlogged
  82. // the simulation is frozen.
  83. if ( connection->mMoveList->isBacklogged() )
  84. {
  85. #ifdef TORQUE_DEBUG
  86. if ( !backlogged )
  87. {
  88. Con::printf( "client is backlogged, time is frozen" );
  89. backlogged = true;
  90. }
  91. backloggedTime += timeDelta;
  92. #endif
  93. return true;
  94. }
  95. }
  96. #ifdef TORQUE_DEBUG
  97. if ( backlogged )
  98. {
  99. Con::printf( "client is no longer backlogged, time is unfrozen (%i ms elapsed)", backloggedTime );
  100. backlogged = false;
  101. backloggedTime = 0;
  102. }
  103. #endif
  104. return false;
  105. }
  106. void ClientProcessList::onPreTickObject( ProcessObject *pobj )
  107. {
  108. // reset to tick boundary
  109. pobj->interpolateTick( 0.0f );
  110. }
  111. //--------------------------------------------------------------------------
  112. // ServerProcessList
  113. //--------------------------------------------------------------------------
  114. ServerProcessList::ServerProcessList()
  115. {
  116. }
  117. void ServerProcessList::addObject( ProcessObject *pobj )
  118. {
  119. AssertFatal( static_cast<SceneObject*>( pobj )->isServerObject(), "Tried to add client object to ServerProcessList." );
  120. GameBase *obj = getGameBase( pobj );
  121. if ( obj && obj->isNetOrdered() )
  122. {
  123. if ( ( gNetOrderNextId & 0xFFFF ) == 0)
  124. // don't let it be zero
  125. gNetOrderNextId++;
  126. pobj->mOrderGUID = ( gNetOrderNextId++ ) & 0xFFFF; // 16 bits should be enough
  127. pobj->plLinkBefore( &mHead );
  128. mDirty = true;
  129. }
  130. else if ( obj && obj->isTickLast() )
  131. {
  132. pobj->mOrderGUID = 0xFFFFFFFF;
  133. pobj->plLinkBefore( &mHead );
  134. // not dirty
  135. }
  136. else
  137. {
  138. pobj->plLinkAfter( &mHead );
  139. // not dirty
  140. }
  141. }
  142. void ServerProcessList::advanceObjects()
  143. {
  144. #ifdef TORQUE_DEBUG_NET_MOVES
  145. Con::printf("Advance server time...");
  146. #endif
  147. Parent::advanceObjects();
  148. #ifdef TORQUE_DEBUG_NET_MOVES
  149. Con::printf("---------");
  150. #endif
  151. }
  152. void ServerProcessList::onPreTickObject( ProcessObject *pobj )
  153. {
  154. }