netObject.cpp

Engine/source/sim/netObject.cpp

More...

Public Functions

ConsoleDocClass(NetObject , "@brief Superclass <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> all ghostable networked <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">objects.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Networking\n</a>" )
DefineEngineMethod(NetObject , clearScopeAlways , void , () , "@brief Clears the scope always flag on this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" )
DefineEngineMethod(NetObject , clearScopeToClient , void , (NetConnection *client) , "@brief Undo the effects of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> scopeToClient() <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">call.\n\n</a>" "@param client The connection <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> remove this object's scoping from \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@see scopeToClient()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" )
DefineEngineMethod(NetObject , getClientObject , S32 , () , "@brief Returns <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aae1f8d263916ad71bd415381591549c0">pointer</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the client object when on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> local <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connection.\n\n</a>" "Short-Circuit-Networking: this is only valid <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> local-client / singleplayer <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">situation.\n\n</a>" "@returns the <a href="/coding/class/classsimobject/">SimObject</a> ID of the client <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Psuedo- code)
DefineEngineMethod(NetObject , getGhostID , S32 , () )
DefineEngineMethod(NetObject , getServerObject , S32 , () , "@brief Returns <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aae1f8d263916ad71bd415381591549c0">pointer</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the client object when on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> local <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connection.\n\n</a>" "Short-Circuit-Netorking: this is only valid <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> local-client / singleplayer <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">situation.\n\n</a>" "@returns The <a href="/coding/class/classsimobject/">SimObject</a> ID of the server <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Psuedo- code)
DefineEngineMethod(NetObject , isClientObject , bool , () , "@brief Called <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> check <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> an object resides on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clientside.\n\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the object resides on the client, false otherwise." )
DefineEngineMethod(NetObject , isServerObject , bool , () , "@brief Checks <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> an object resides on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">server.\n\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the object resides on the server, false otherwise." )
DefineEngineMethod(NetObject , scopeToClient , void , (NetConnection *client) , "@brief Cause the <a href="/coding/class/classnetobject/">NetObject</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be forced as scoped on the specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">NetConnection.\n\n</a>" "@param client The connection this object will always be scoped <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Called <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> create <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> cameras in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">TorqueScript\n</a>" "// %this - The active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GameConnection\n</a>" "// %spawnPoint - The spawn point location where we creat the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera\n</a>" "function GameConnection::spawnCamera(%this, %spawnPoint)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	// If this connection's camera <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">exists\n</a>" "	<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a>(isObject(%this.camera))\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "		// Add it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the mission group <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be cleaned up <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">later\n</a>" "		MissionCleanup.add( %this.camera );\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "		// Force it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> scope <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the client <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">side\n</a>" "		%this.camera.scopeToClient(%this);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see clearScopeToClient()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" )
DefineEngineMethod(NetObject , setScopeAlways , void , () , "@brief Always scope this object on all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connections.\n\n</a>" "The object is marked as ScopeAlways and is immediately ghosted <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "all active connections. This function has no effect <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the object " "is not marked as <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Ghostable.\n\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(NetObject , "@brief Superclass <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> all ghostable networked <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">objects.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Networking\n</a>" )

DefineEngineMethod(NetObject , clearScopeAlways , void , () , "@brief Clears the scope always flag on this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" )

DefineEngineMethod(NetObject , clearScopeToClient , void , (NetConnection *client) , "@brief Undo the effects of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> scopeToClient() <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">call.\n\n</a>" "@param client The connection <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> remove this object's scoping from \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@see scopeToClient()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" )

DefineEngineMethod(NetObject , getClientObject , S32 , () , "@brief Returns <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aae1f8d263916ad71bd415381591549c0">pointer</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the client object when on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> local <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connection.\n\n</a>" "Short-Circuit-Networking: this is only valid <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> local-client / singleplayer <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">situation.\n\n</a>" "@returns the <a href="/coding/class/classsimobject/">SimObject</a> ID of the client <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Psuedo- code)

DefineEngineMethod(NetObject , getGhostID , S32 , () )

DefineEngineMethod(NetObject , getServerObject , S32 , () , "@brief Returns <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aae1f8d263916ad71bd415381591549c0">pointer</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the client object when on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> local <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connection.\n\n</a>" "Short-Circuit-Netorking: this is only valid <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> local-client / singleplayer <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">situation.\n\n</a>" "@returns The <a href="/coding/class/classsimobject/">SimObject</a> ID of the server <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Psuedo- code)

DefineEngineMethod(NetObject , isClientObject , bool , () , "@brief Called <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> check <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> an object resides on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clientside.\n\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the object resides on the client, false otherwise." )

DefineEngineMethod(NetObject , isServerObject , bool , () , "@brief Checks <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> an object resides on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">server.\n\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the object resides on the server, false otherwise." )

DefineEngineMethod(NetObject , scopeToClient , void , (NetConnection *client) , "@brief Cause the <a href="/coding/class/classnetobject/">NetObject</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be forced as scoped on the specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">NetConnection.\n\n</a>" "@param client The connection this object will always be scoped <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Called <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> create <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> cameras in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">TorqueScript\n</a>" "// %this - The active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GameConnection\n</a>" "// %spawnPoint - The spawn point location where we creat the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera\n</a>" "function GameConnection::spawnCamera(%this, %spawnPoint)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	// If this connection's camera <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">exists\n</a>" "	<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a>(isObject(%this.camera))\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "		// Add it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the mission group <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be cleaned up <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">later\n</a>" "		MissionCleanup.add( %this.camera );\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "		// Force it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> scope <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the client <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">side\n</a>" "		%this.camera.scopeToClient(%this);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see clearScopeToClient()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" )

DefineEngineMethod(NetObject , setScopeAlways , void , () , "@brief Always scope this object on all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connections.\n\n</a>" "The object is marked as ScopeAlways and is immediately ghosted <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "all active connections. This function has no effect <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the object " "is not marked as <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Ghostable.\n\n</a>" )

IMPLEMENT_CONOBJECT(NetObject )

  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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
 26// Copyright (C) 2015 Faust Logic, Inc.
 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 28
 29#include "platform/platform.h"
 30#include "console/simBase.h"
 31#include "core/dnet.h"
 32#include "sim/netConnection.h"
 33#include "sim/netObject.h"
 34#include "console/consoleTypes.h"
 35#include "console/engineAPI.h"
 36
 37#ifdef TORQUE_AFX_ENABLED
 38#include "afx/arcaneFX.h"
 39#endif
 40
 41IMPLEMENT_CONOBJECT(NetObject);
 42
 43// More information can be found in the Torque Manual (CHM)
 44ConsoleDocClass( NetObject,
 45            "@brief Superclass for all ghostable networked objects.\n\n"
 46            "@ingroup Networking\n");
 47
 48//----------------------------------------------------------------------------
 49NetObject *NetObject::mDirtyList = NULL;
 50
 51NetObject::NetObject()
 52{
 53   // netFlags will clear itself to 0
 54   mNetIndex = U32(-1);
 55   mFirstObjectRef = NULL;
 56   mPrevDirtyList = NULL;
 57   mNextDirtyList = NULL;
 58   mDirtyMaskBits = 0;
 59#ifdef TORQUE_AFX_ENABLED
 60   mScope_id = 0;
 61   mScope_refs = 0;
 62   mScope_registered = false;
 63#endif
 64}
 65
 66NetObject::~NetObject()
 67{
 68   if(mDirtyMaskBits)
 69   {
 70      if(mPrevDirtyList)
 71         mPrevDirtyList->mNextDirtyList = mNextDirtyList;
 72      else
 73         mDirtyList = mNextDirtyList;
 74      if(mNextDirtyList)
 75         mNextDirtyList->mPrevDirtyList = mPrevDirtyList;
 76   }
 77}
 78
 79String NetObject::describeSelf() const
 80{
 81   String desc = Parent::describeSelf();
 82
 83   if( isClientObject() )
 84      desc += "|net: client";
 85   else
 86      desc += "|net: server";
 87
 88   return desc;
 89}
 90
 91void NetObject::setMaskBits(U32 orMask)
 92{
 93   AssertFatal(orMask != 0, "Invalid net mask bits set.");
 94   AssertFatal(mDirtyMaskBits == 0 || (mPrevDirtyList != NULL || mNextDirtyList != NULL || mDirtyList == this), "Invalid dirty list state.");
 95   if(!mDirtyMaskBits)
 96   {
 97      AssertFatal(mNextDirtyList == NULL && mPrevDirtyList == NULL, "Object with zero mask already in list.");
 98      if(mDirtyList)
 99      {
100         mNextDirtyList = mDirtyList;
101         mDirtyList->mPrevDirtyList = this;
102      }
103      mDirtyList = this;
104   }
105   mDirtyMaskBits |= orMask;
106   AssertFatal(mDirtyMaskBits == 0 || (mPrevDirtyList != NULL || mNextDirtyList != NULL || mDirtyList == this), "Invalid dirty list state.");
107}
108
109void NetObject::clearMaskBits(U32 orMask)
110{
111   if(isDeleted())
112      return;
113   if(mDirtyMaskBits)
114   {
115      mDirtyMaskBits &= ~orMask;
116      if(!mDirtyMaskBits)
117      {
118         if(mPrevDirtyList)
119            mPrevDirtyList->mNextDirtyList = mNextDirtyList;
120         else
121            mDirtyList = mNextDirtyList;
122         if(mNextDirtyList)
123            mNextDirtyList->mPrevDirtyList = mPrevDirtyList;
124         mNextDirtyList = mPrevDirtyList = NULL;
125      }
126   }
127
128   for(GhostInfo *walk = mFirstObjectRef; walk; walk = walk->nextObjectRef)
129   {
130      if(walk->updateMask && walk->updateMask == orMask)
131      {
132         walk->updateMask = 0;
133         walk->connection->ghostPushToZero(walk);
134      }
135      else
136         walk->updateMask &= ~orMask;
137   }
138}
139
140void NetObject::collapseDirtyList()
141{
142#ifdef TORQUE_DEBUG
143   Vector<NetObject*> tempV;
144   for(NetObject *t = mDirtyList; t; t = t->mNextDirtyList)
145      tempV.push_back(t);
146#endif
147
148   for(NetObject *obj = mDirtyList; obj; )
149   {
150      NetObject *next = obj->mNextDirtyList;
151      U32 dirtyMask = obj->mDirtyMaskBits;
152
153      obj->mNextDirtyList = NULL;
154      obj->mPrevDirtyList = NULL;
155      obj->mDirtyMaskBits = 0;
156
157      if(!obj->isDeleted() && dirtyMask)
158      {
159         for(GhostInfo *walk = obj->mFirstObjectRef; walk; walk = walk->nextObjectRef)
160         {
161            U32 orMask = obj->filterMaskBits(dirtyMask,walk->connection);
162            if(!walk->updateMask && orMask)
163            {
164               walk->updateMask = orMask;
165               walk->connection->ghostPushNonZero(walk);
166            }
167            else
168               walk->updateMask |= orMask;
169         }
170      }
171      obj = next;
172   }
173   mDirtyList = NULL;
174#ifdef TORQUE_DEBUG
175   for(U32 i = 0; i < tempV.size(); i++)
176   {
177      AssertFatal(tempV[i]->mNextDirtyList == NULL && tempV[i]->mPrevDirtyList == NULL && tempV[i]->mDirtyMaskBits == 0, "Error in collapse");
178   }
179#endif
180}
181
182//-----------------------------------------------------------------------------
183DefineEngineMethod( NetObject, scopeToClient, void, ( NetConnection* client),,
184   "@brief Cause the NetObject to be forced as scoped on the specified NetConnection.\n\n"
185
186   "@param client The connection this object will always be scoped to\n\n"
187
188   "@tsexample\n"
189      "// Called to create new cameras in TorqueScript\n"
190      "// %this - The active GameConnection\n"
191      "// %spawnPoint - The spawn point location where we creat the camera\n"
192      "function GameConnection::spawnCamera(%this, %spawnPoint)\n"
193      "{\n"
194      "  // If this connection's camera exists\n"
195      "  if(isObject(%this.camera))\n"
196      "  {\n"
197      "     // Add it to the mission group to be cleaned up later\n"
198      "     MissionCleanup.add( %this.camera );\n\n"
199      "     // Force it to scope to the client side\n"
200      "     %this.camera.scopeToClient(%this);\n"
201      "  }\n"
202      "}\n"
203   "@endtsexample\n\n"
204   
205   "@see clearScopeToClient()\n")
206{
207   if(!client)
208   {
209      Con::errorf(ConsoleLogEntry::General, "NetObject::scopeToClient: Couldn't find connection %s", client);
210      return;
211   }
212   client->objectLocalScopeAlways(object);
213}
214
215//ConsoleMethod(NetObject,scopeToClient,void,3,3,"(NetConnection %client)"
216//              "Cause the NetObject to be forced as scoped on the specified NetConnection.")
217//{
218//   TORQUE_UNUSED(argc);
219//   NetConnection *conn;
220//   if(!Sim::findObject(argv[2], conn))
221//   {
222//      Con::errorf(ConsoleLogEntry::General, "NetObject::scopeToClient: Couldn't find connection %s", argv[2]);
223//      return;
224//   }
225//   conn->objectLocalScopeAlways(object);
226//}
227
228DefineEngineMethod( NetObject, clearScopeToClient, void, ( NetConnection* client),,
229   "@brief Undo the effects of a scopeToClient() call.\n\n"
230
231   "@param client The connection to remove this object's scoping from \n\n"
232   
233   "@see scopeToClient()\n")
234{
235   if(!client)
236   {
237      Con::errorf(ConsoleLogEntry::General, "NetObject::clearScopeToClient: Couldn't find connection %s", client);
238      return;
239   }
240   client->objectLocalClearAlways(object);
241}
242
243//ConsoleMethod(NetObject,clearScopeToClient,void,3,3,"clearScopeToClient(%client)"
244//              "Undo the effects of a scopeToClient() call.")
245//{
246//   TORQUE_UNUSED(argc);
247//   NetConnection *conn;
248//   if(!Sim::findObject(argv[2], conn))
249//   {
250//      Con::errorf(ConsoleLogEntry::General, "NetObject::clearScopeToClient: Couldn't find connection %s", argv[2]);
251//      return;
252//   }
253//   conn->objectLocalClearAlways(object);
254//}
255
256DefineEngineMethod( NetObject, setScopeAlways, void, (),,
257   "@brief Always scope this object on all connections.\n\n"
258
259   "The object is marked as ScopeAlways and is immediately ghosted to "
260   "all active connections.  This function has no effect if the object "
261   "is not marked as Ghostable.\n\n")
262{
263   object->setScopeAlways();
264}
265
266//ConsoleMethod(NetObject,setScopeAlways,void,2,2,"Always scope this object on all connections.")
267//{
268//   TORQUE_UNUSED(argc); TORQUE_UNUSED(argv);
269//   object->setScopeAlways();
270//}
271
272void NetObject::setScopeAlways()
273{
274   if(mNetFlags.test(Ghostable) && !mNetFlags.test(IsGhost))
275   {
276      mNetFlags.set(ScopeAlways);
277
278      // if it's a ghost always object, add it to the ghost always set
279      // for ClientReps created later.
280
281      Sim::getGhostAlwaysSet()->addObject(this);
282
283      // add it to all Connections that already exist.
284
285      SimGroup *clientGroup = Sim::getClientGroup();
286      SimGroup::iterator i;
287      for(i = clientGroup->begin(); i != clientGroup->end(); i++)
288      {
289         NetConnection *con = (NetConnection *) (*i);
290         if(con->isGhosting())
291            con->objectInScope(this);
292      }
293   }
294}
295
296void NetObject::clearScopeAlways()
297{
298   if(!mNetFlags.test(IsGhost))
299   {
300      mNetFlags.clear(ScopeAlways);
301      Sim::getGhostAlwaysSet()->removeObject(this);
302
303      // Un ghost this object from all the connections
304      while(mFirstObjectRef)
305         mFirstObjectRef->connection->detachObject(mFirstObjectRef);
306   }
307}
308
309bool NetObject::onAdd()
310{
311   if(mNetFlags.test(ScopeAlways))
312      setScopeAlways();
313
314   return Parent::onAdd();
315}
316
317void NetObject::onRemove()
318{
319   while(mFirstObjectRef)
320      mFirstObjectRef->connection->detachObject(mFirstObjectRef);
321
322   Parent::onRemove();
323}
324
325//-----------------------------------------------------------------------------
326
327F32 NetObject::getUpdatePriority(CameraScopeQuery*, U32, S32 updateSkips)
328{
329   return F32(updateSkips) * 0.1;
330}
331
332U32 NetObject::packUpdate(NetConnection* conn, U32 mask, BitStream* stream)
333{
334   return 0;
335}
336
337void NetObject::unpackUpdate(NetConnection*, BitStream*)
338{
339}
340
341void NetObject::onCameraScopeQuery(NetConnection *cr, CameraScopeQuery* /*camInfo*/)
342{
343   // default behavior -
344   // ghost everything that is ghostable
345
346   for (SimSetIterator obj(Sim::getRootGroup()); *obj; ++obj)
347   {
348      NetObject* nobj = dynamic_cast<NetObject*>(*obj);
349      if (nobj)
350      {
351         AssertFatal(!nobj->mNetFlags.test(NetObject::Ghostable) || !nobj->mNetFlags.test(NetObject::IsGhost),
352            "NetObject::onCameraScopeQuery: object marked both ghostable and as ghost");
353
354         // Some objects don't ever want to be ghosted
355         if (!nobj->mNetFlags.test(NetObject::Ghostable))
356            continue;
357         if (!nobj->mNetFlags.test(NetObject::ScopeAlways))
358         {
359            // it's in scope...
360            cr->objectInScope(nobj);
361         }
362      }
363   }
364}
365
366//-----------------------------------------------------------------------------
367
368void NetObject::initPersistFields()
369{
370   Parent::initPersistFields();
371}
372
373DefineEngineMethod( NetObject, getGhostID, S32, (),,
374   "@brief Get the ghost index of this object from the server.\n\n"
375
376   "@returns The ghost ID of this NetObject on the server\n"
377
378   "@tsexample\n"
379      "%ghostID = LocalClientConnection.getGhostId( %serverObject );\n"
380   "@endtsexample\n\n")
381{
382   return object->getNetIndex();
383}
384
385//ConsoleMethod( NetObject, getGhostID, S32, 2, 2, "")
386//{
387//   return object->getNetIndex();
388//}
389
390DefineEngineMethod( NetObject, getClientObject, S32, (),,
391   "@brief Returns a pointer to the client object when on a local connection.\n\n"
392
393   "Short-Circuit-Networking: this is only valid for a local-client / singleplayer situation.\n\n"
394
395   "@returns the SimObject ID of the client object.\n"
396
397   "@tsexample\n"
398      "// Psuedo-code, some values left out for this example\n"
399      "%node = new ParticleEmitterNode(){};\n"
400      "%clientObject = %node.getClientObject();\n"
401      "if(isObject(%clientObject)\n"
402      "  %clientObject.setTransform(\"0 0 0\");\n\n"
403   "@endtsexample\n\n"
404   
405   "@see @ref local_connections")
406{
407   NetObject *obj = object->getClientObject();
408   if ( obj )
409      return obj->getId();
410   
411   return NULL;
412}
413
414//ConsoleMethod( NetObject, getClientObject, S32, 2, 2, "Short-Circuit-Netorking: this is only valid for a local-client / singleplayer situation." )
415//{
416//   NetObject *obj = object->getClientObject();
417//   if ( obj )
418//      return obj->getId();
419//
420//   return NULL;
421//}
422
423DefineEngineMethod( NetObject, getServerObject, S32, (),,
424   "@brief Returns a pointer to the client object when on a local connection.\n\n"
425
426   "Short-Circuit-Netorking: this is only valid for a local-client / singleplayer situation.\n\n"
427   
428   "@returns The SimObject ID of the server object.\n"
429   "@tsexample\n"
430      "// Psuedo-code, some values left out for this example\n"
431      "%node = new ParticleEmitterNode(){};\n"
432      "%serverObject = %node.getServerObject();\n"
433      "if(isObject(%serverObject)\n"
434      "  %serverObject.setTransform(\"0 0 0\");\n\n"
435   "@endtsexample\n\n"
436   
437   "@see @ref local_connections")
438{
439   NetObject *obj = object->getServerObject();
440   if ( obj )
441      return obj->getId();
442   
443   return NULL;
444}
445
446//ConsoleMethod( NetObject, getServerObject, S32, 2, 2, "Short-Circuit-Netorking: this is only valid for a local-client / singleplayer situation." )
447//{
448//   NetObject *obj = object->getServerObject();
449//   if ( obj )
450//      return obj->getId();
451//
452//   return NULL;
453//}
454
455DefineEngineMethod( NetObject, isClientObject, bool, (),,
456   "@brief Called to check if an object resides on the clientside.\n\n"
457   "@return True if the object resides on the client, false otherwise.")
458{
459   return object->isClientObject();
460}
461
462//ConsoleMethod( NetObject, isClientObject, bool, 2, 2, "Return true for client-side objects." )
463//{
464//   return object->isClientObject();
465//}
466
467DefineEngineMethod( NetObject, isServerObject, bool, (),,
468   "@brief Checks if an object resides on the server.\n\n"
469   "@return True if the object resides on the server, false otherwise.")
470{
471   return object->isServerObject();
472}
473
474//ConsoleMethod( NetObject, isServerObject, bool, 2, 2, "Return true for client-side objects." )
475//{
476//   return object->isServerObject();
477//}
478
479#ifdef TORQUE_AFX_ENABLED
480U16 NetObject::addScopeRef() 
481{ 
482   if (mScope_refs == 0)
483   {
484      mScope_id = arcaneFX::generateScopeId();
485      onScopeIdChange();
486   }
487   mScope_refs++;
488   return mScope_id;
489}
490
491void NetObject::removeScopeRef() 
492{ 
493   if (mScope_refs == 0)
494      return;
495   mScope_refs--;
496   if (mScope_refs == 0)
497   {
498      mScope_id = 0;
499      onScopeIdChange();
500   }
501}
502#endif
503
504//Networked fields
505//------------------------------------------------------------------
506void NetObject::addNetworkedField(const char*  in_pFieldname,
507   const U32 in_fieldType,
508   const dsize_t in_fieldOffset,
509   const char* in_pFieldDocs,
510   U32 flags,
511   U32 networkMask)
512{
513   addNetworkedField(
514      in_pFieldname,
515      in_fieldType,
516      in_fieldOffset,
517      1,
518      in_pFieldDocs,
519      flags,
520      networkMask);
521}
522
523void NetObject::addNetworkedField(const char*  in_pFieldname,
524   const U32 in_fieldType,
525   const dsize_t in_fieldOffset,
526   AbstractClassRep::WriteDataNotify in_writeDataFn,
527   const char* in_pFieldDocs,
528   U32 flags,
529   U32 networkMask)
530{
531   addNetworkedField(
532      in_pFieldname,
533      in_fieldType,
534      in_fieldOffset,
535      in_writeDataFn,
536      1,
537      in_pFieldDocs,
538      flags,
539      networkMask);
540}
541
542void NetObject::addNetworkedField(const char*  in_pFieldname,
543   const U32 in_fieldType,
544   const dsize_t in_fieldOffset,
545   const U32 in_elementCount,
546   const char* in_pFieldDocs,
547   U32 flags,
548   U32 networkMask)
549{
550   addNetworkedField(in_pFieldname,
551      in_fieldType,
552      in_fieldOffset,
553      &defaultProtectedWriteFn,
554      in_elementCount,
555      in_pFieldDocs,
556      flags,
557      networkMask);
558}
559
560void NetObject::addNetworkedField(const char*  in_pFieldname,
561   const U32 in_fieldType,
562   const dsize_t in_fieldOffset,
563   AbstractClassRep::WriteDataNotify in_writeDataFn,
564   const U32 in_elementCount,
565   const char* in_pFieldDocs,
566   U32 flags,
567   U32 networkMask)
568{
569   AbstractClassRep::Field f;
570   f.pFieldname = StringTable->insert(in_pFieldname);
571
572   if (in_pFieldDocs)
573      f.pFieldDocs = in_pFieldDocs;
574
575   f.type = in_fieldType;
576   f.offset = in_fieldOffset;
577   f.elementCount = in_elementCount;
578   f.validator = NULL;
579   f.flag = flags;
580
581   f.setDataFn = &defaultProtectedSetFn;
582   f.getDataFn = &defaultProtectedGetFn;
583   f.writeDataFn = in_writeDataFn;
584
585   f.networkMask = networkMask;
586
587   ConsoleBaseType* conType = ConsoleBaseType::getType(in_fieldType);
588   AssertFatal(conType, "ConsoleObject::addField - invalid console type");
589   f.table = conType->getEnumTable();
590
591   sg_tempFieldList.push_back(f);
592}
593
594DefineEngineMethod(NetObject, clearScopeAlways, void, (), ,
595   "@brief Clears the scope always flag on this object.\n\n")
596{
597   object->clearScopeAlways();
598}
599