#include <testGame.h>
Inheritance diagram for TNLTest::Player:
Each client in the server controls a Player instance constructed for it upon joining the game. Client users click on the game window, which generates an event to the server to move that client's player to the desired point.
Public Types | |
enum | PlayerType { PlayerTypeAI, PlayerTypeAIDummy, PlayerTypeClient, PlayerTypeMyClient } |
Enumeration of possible player types in the game. More... | |
enum | MaskBits { InitialMask = (1 << 0), PositionMask = (1 << 1) } |
Mask bits used for determining which object states need to be updated to all the clients. More... | |
Public Member Functions | |
Player (PlayerType pt=PlayerTypeClient) | |
Player constructor, assigns a random position in the playing field to the player, and if it is AI controlled will pick a first destination point. | |
~Player () | |
Player destructor removes the player from the game. | |
void | performScopeQuery (TNL::GhostConnection *connection) |
performScopeQuery is called to determine which objects are "in scope" for the client that controls this Player instance. | |
TNL::U32 | packUpdate (TNL::GhostConnection *connection, TNL::U32 updateMask, TNL::BitStream *stream) |
packUpdate writes the Player's ghost update from the server to the client. | |
void | unpackUpdate (TNL::GhostConnection *connection, TNL::BitStream *stream) |
unpackUpdate reads the data the server wrote in packUpdate from the packet. | |
void | serverSetPosition (Position startPos, Position endPos, TNL::F32 t, TNL::F32 tDelta) |
serverSetPosition is called on the server when it receives notice from a client to change the position of the player it controls. | |
void | update (TNL::F32 timeDelta) |
Move this object along its path. | |
void | onGhostAvailable (TNL::GhostConnection *theConnection) |
onGhostAvailable is called on the server when it knows that this Player has been constructed on the specified client as a result of being "in scope". | |
bool | onGhostAdd (TNL::GhostConnection *theConnection) |
onGhostAdd is called for every NetObject on the client after the ghost has been constructed and its initial unpackUpdate is called. | |
void | addToGame (TestGame *theGame) |
Adds this Player to the list of Player instances in the specified game. | |
TNL_DECLARE_RPC (rpcPlayerWillMove,(TNL::StringPtr testString)) | |
rpcPlayerWillMove is used in TNLTest to demonstrate ghost->parent NetObject RPCs. | |
TNL_DECLARE_RPC (rpcPlayerDidMove,(TNL::Float< 6 > x, TNL::Float< 6 > y)) | |
rpcPlayerDidMove is used in TNLTest to demostrate a broadcast RPC from the server to all of the ghosts on clients scoping this object. | |
TNL_DECLARE_RPC (rpcPlayerIsInScope,(TNL::Float< 6 > x, TNL::Float< 6 > y)) | |
rpcPlayerIsInScope is the RPC method called by onGhostAvailable to demonstrate targeted NetObject RPCs. | |
TNL_DECLARE_CLASS (Player) | |
This macro invocation declares the Player class to be known to the TNL class management system. | |
Data Fields | |
Position | startPos |
Position | endPos |
All players move along a line from startPos to endPos. | |
Position | renderPos |
Position at which to render the player - computed during update(). | |
TNL::F32 | t |
Parameter of how far the player is along the line from startPos to endPos. | |
TNL::F32 | tDelta |
Change in t per second (ie, velocity). | |
TestGame * | game |
The game object this player is associated with. | |
PlayerType | myPlayerType |
What type of player is this? | |
Private Types | |
typedef TNL::NetObject | Parent |
|
Reimplemented from TNL::NetObject. |
|
|
Mask bits used for determining which object states need to be updated to all the clients.
|
|
Player constructor, assigns a random position in the playing field to the player, and if it is AI controlled will pick a first destination point.
|
|
Player destructor removes the player from the game.
|
|
performScopeQuery is called to determine which objects are "in scope" for the client that controls this Player instance. In the TNLTest program, all objects in a circle of radius 0.25 around the scope object are considered to be in scope. Reimplemented from TNL::NetObject. |
|
packUpdate writes the Player's ghost update from the server to the client. This function takes advantage of the fact that the InitialMask is only ever set for the first update of the object to send once-only state to the client. Reimplemented from TNL::NetObject. |
|
unpackUpdate reads the data the server wrote in packUpdate from the packet.
Reimplemented from TNL::NetObject. |
|
serverSetPosition is called on the server when it receives notice from a client to change the position of the player it controls. serverSetPosition will call setMaskBits(PositionMask) to notify the network system that this object has changed state. |
|
Move this object along its path. If it hits the end point, and it's an AI, it will generate a new destination. |
|
onGhostAvailable is called on the server when it knows that this Player has been constructed on the specified client as a result of being "in scope". In TNLTest this method call is used to test the per-ghost targeted RPC functionality of NetObject subclasses by calling rpcPlayerIsInScope on the Player ghost on the specified connection. Reimplemented from TNL::NetObject. |
|
onGhostAdd is called for every NetObject on the client after the ghost has been constructed and its initial unpackUpdate is called. A return value of false from this function would indicate than an error had occured, notifying the network system that the connection should be terminated. Reimplemented from TNL::NetObject. |
|
Adds this Player to the list of Player instances in the specified game.
|
|
rpcPlayerWillMove is used in TNLTest to demonstrate ghost->parent NetObject RPCs.
|
|
rpcPlayerDidMove is used in TNLTest to demostrate a broadcast RPC from the server to all of the ghosts on clients scoping this object. It also demonstrates the usage of the Float<> template argument, in this case using 6 bits for each X and Y position. Float arguments to RPCs are between 0 and 1. |
|
rpcPlayerIsInScope is the RPC method called by onGhostAvailable to demonstrate targeted NetObject RPCs. onGhostAvailable uses the TNL_RPC_CONSTRUCT_NETEVENT macro to construct a NetEvent from the RPC invocation and then posts it only to the client for which the object just came into scope. |
|
This macro invocation declares the Player class to be known to the TNL class management system.
|
|
|
|
All players move along a line from startPos to endPos.
|
|
Position at which to render the player - computed during update().
|
|
Parameter of how far the player is along the line from startPos to endPos.
|
|
Change in t per second (ie, velocity).
|
|
The game object this player is associated with.
|
|
What type of player is this?
|