Torque3D Documentation / _generateds / gameProcess.cpp

gameProcess.cpp

Engine/source/T3D/gameBase/gameProcess.cpp

More...

Public Variables

Public Functions

DefineEngineFunction(dumpProcessList , void , () , "Dumps all ProcessObjects in <a href="/coding/class/classserverprocesslist/">ServerProcessList</a> and <a href="/coding/class/classclientprocesslist/">ClientProcessList</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console." )

Detailed Description

Public Variables

U32 gNetOrderNextId 

Public Functions

DefineEngineFunction(dumpProcessList , void , () , "Dumps all ProcessObjects in <a href="/coding/class/classserverprocesslist/">ServerProcessList</a> and <a href="/coding/class/classclientprocesslist/">ClientProcessList</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console." )

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