gameProcess.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 "platform/platform.h"
  23. #include "T3D/gameBase/gameProcess.h"
  24. #include "T3D/gameBase/gameBase.h"
  25. #include "T3D/gameBase/gameConnection.h"
  26. #include "T3D/gameBase/moveList.h"
  27. //----------------------------------------------------------------------------
  28. ClientProcessList* ClientProcessList::smClientProcessList = NULL;
  29. ServerProcessList* ServerProcessList::smServerProcessList = NULL;
  30. static U32 gNetOrderNextId = 0;
  31. ConsoleFunction( dumpProcessList, void, 1, 1,
  32. "Dumps all ProcessObjects in ServerProcessList and ClientProcessList to the console." )
  33. {
  34. Con::printf( "client process list:" );
  35. ClientProcessList::get()->dumpToConsole();
  36. Con::printf( "server process list:" );
  37. ServerProcessList::get()->dumpToConsole();
  38. }
  39. //--------------------------------------------------------------------------
  40. // ClientProcessList
  41. //--------------------------------------------------------------------------
  42. ClientProcessList::ClientProcessList()
  43. {
  44. }
  45. void ClientProcessList::addObject( ProcessObject *pobj )
  46. {
  47. AssertFatal( static_cast<SceneObject*>( pobj )->isClientObject(), "Tried to add server object to ClientProcessList." );
  48. GameBase *obj = getGameBase( pobj );
  49. if ( obj && obj->isNetOrdered() )
  50. {
  51. if ( ( gNetOrderNextId & 0xFFFF ) == 0 )
  52. // don't let it be zero
  53. gNetOrderNextId++;
  54. pobj->mOrderGUID = ( gNetOrderNextId++ ) & 0xFFFF; // 16 bits should be enough
  55. pobj->plLinkBefore( &mHead );
  56. mDirty = true;
  57. }
  58. else if ( obj && obj->isTickLast() )
  59. {
  60. pobj->mOrderGUID = 0xFFFFFFFF;
  61. pobj->plLinkBefore( &mHead );
  62. // not dirty
  63. }
  64. else
  65. {
  66. pobj->plLinkAfter( &mHead );
  67. // not dirty
  68. }
  69. }
  70. bool ClientProcessList::doBacklogged( SimTime timeDelta )
  71. {
  72. #ifdef TORQUE_DEBUG
  73. static bool backlogged = false;
  74. static U32 backloggedTime = 0;
  75. #endif
  76. // See if the control object has pending moves.
  77. GameConnection *connection = GameConnection::getConnectionToServer();
  78. if ( connection )
  79. {
  80. // If the connection to the server is backlogged
  81. // the simulation is frozen.
  82. if ( connection->mMoveList->isBacklogged() )
  83. {
  84. #ifdef TORQUE_DEBUG
  85. if ( !backlogged )
  86. {
  87. Con::printf( "client is backlogged, time is frozen" );
  88. backlogged = true;
  89. }
  90. backloggedTime += timeDelta;
  91. #endif
  92. return true;
  93. }
  94. }
  95. #ifdef TORQUE_DEBUG
  96. if ( backlogged )
  97. {
  98. Con::printf( "client is no longer backlogged, time is unfrozen (%i ms elapsed)", backloggedTime );
  99. backlogged = false;
  100. backloggedTime = 0;
  101. }
  102. #endif
  103. return false;
  104. }
  105. void ClientProcessList::onPreTickObject( ProcessObject *pobj )
  106. {
  107. // reset to tick boundary
  108. pobj->interpolateTick( 0.0f );
  109. }
  110. //--------------------------------------------------------------------------
  111. // ServerProcessList
  112. //--------------------------------------------------------------------------
  113. ServerProcessList::ServerProcessList()
  114. {
  115. }
  116. void ServerProcessList::addObject( ProcessObject *pobj )
  117. {
  118. AssertFatal( static_cast<SceneObject*>( pobj )->isServerObject(), "Tried to add client object to ServerProcessList." );
  119. GameBase *obj = getGameBase( pobj );
  120. if ( obj && obj->isNetOrdered() )
  121. {
  122. if ( ( gNetOrderNextId & 0xFFFF ) == 0)
  123. // don't let it be zero
  124. gNetOrderNextId++;
  125. pobj->mOrderGUID = ( gNetOrderNextId++ ) & 0xFFFF; // 16 bits should be enough
  126. pobj->plLinkBefore( &mHead );
  127. mDirty = true;
  128. }
  129. else if ( obj && obj->isTickLast() )
  130. {
  131. pobj->mOrderGUID = 0xFFFFFFFF;
  132. pobj->plLinkBefore( &mHead );
  133. // not dirty
  134. }
  135. else
  136. {
  137. pobj->plLinkAfter( &mHead );
  138. // not dirty
  139. }
  140. }
  141. void ServerProcessList::advanceObjects()
  142. {
  143. #ifdef TORQUE_DEBUG_NET_MOVES
  144. Con::printf("Advance server time...");
  145. #endif
  146. Parent::advanceObjects();
  147. #ifdef TORQUE_DEBUG_NET_MOVES
  148. Con::printf("---------");
  149. #endif
  150. }
  151. void ServerProcessList::onPreTickObject( ProcessObject *pobj )
  152. {
  153. }