[Opentnl-cvs] tnl/test server.cpp,1.2,1.3 testGame.cpp,1.7,1.8 testGame.h,1.4,1.5 testGameRender.cpp
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2004-08-19 21:20:26
|
Update of /cvsroot/opentnl/tnl/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25378/test Modified Files: server.cpp testGame.cpp testGame.h testGameRender.cpp testWindow.cpp Log Message: Made TNLTest not using namespace TNL Fixed RPC parser code to accept TNL:: prefixes to RPC arguments Index: testGame.h =================================================================== RCS file: /cvsroot/opentnl/tnl/test/testGame.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** testGame.h 19 Aug 2004 20:24:51 -0000 1.4 --- testGame.h 19 Aug 2004 21:20:14 -0000 1.5 *************** *** 33,38 **** #include "../tnl/tnlRPC.h" - using namespace TNL; - /// TNL Graphical Test Application. /// --- 33,36 ---- *************** *** 60,65 **** struct Position { ! F32 x; ///< X position of the object, from 0 ... 1 ! F32 y; ///< Y position of the object, from 0 ... 1 }; --- 58,63 ---- struct Position { ! TNL::F32 x; ///< X position of the object, from 0 ... 1 ! TNL::F32 y; ///< Y position of the object, from 0 ... 1 }; *************** *** 69,80 **** /// Client users click on the game window, which generates an event to the server to /// move that client's player to the desired point. ! class Player : public NetObject { ! typedef NetObject Parent; public: Position startPos, endPos; ///< All players move along a line from startPos to endPos. Position renderPos; ///< Position at which to render the player - computed during update(). ! F32 t; ///< Parameter of how far the player is along the line from startPos to endPos. ! F32 tDelta; ///< Change in t per second (ie, velocity). TestGame *game; ///< The game object this player is associated with --- 67,78 ---- /// Client users click on the game window, which generates an event to the server to /// move that client's player to the desired point. ! class Player : public TNL::NetObject { ! typedef TNL::NetObject Parent; public: Position startPos, 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 *************** *** 106,118 **** /// 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. ! void performScopeQuery(GhostConnection *connection); /// 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. ! U32 packUpdate(GhostConnection *connection, U32 updateMask, BitStream *stream); /// unpackUpdate reads the data the server wrote in packUpdate from the packet. ! void unpackUpdate(GhostConnection *connection, BitStream *stream); /// serverSetPosition is called on the server when it receives notice from a client --- 104,116 ---- /// 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. ! void performScopeQuery(TNL::GhostConnection *connection); /// 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. ! TNL::U32 packUpdate(TNL::GhostConnection *connection, TNL::U32 updateMask, TNL::BitStream *stream); /// unpackUpdate reads the data the server wrote in packUpdate from the packet. ! void unpackUpdate(TNL::GhostConnection *connection, TNL::BitStream *stream); /// serverSetPosition is called on the server when it receives notice from a client *************** *** 120,129 **** /// setMaskBits(PositionMask) to notify the network system that this object has /// changed state. ! void serverSetPosition(Position startPos, Position endPos, F32 t, F32 tDelta); /// Move this object along its path. /// /// If it hits the end point, and it's an AI, it will generate a new destination. ! void update(F32 timeDelta); /// onGhostAvailable is called on the server when it knows that this Player has been --- 118,127 ---- /// setMaskBits(PositionMask) to notify the network system that this object has /// changed state. ! void serverSetPosition(Position startPos, Position endPos, TNL::F32 t, TNL::F32 tDelta); /// Move this object along its path. /// /// If it hits the end point, and it's an AI, it will generate a new destination. ! void update(TNL::F32 timeDelta); /// onGhostAvailable is called on the server when it knows that this Player has been *************** *** 132,136 **** /// NetObject subclasses by calling rpcPlayerIsInScope on the Player ghost on /// the specified connection. ! void onGhostAvailable(GhostConnection *theConnection); /// onGhostAdd is called for every NetObject on the client after the ghost has --- 130,134 ---- /// NetObject subclasses by calling rpcPlayerIsInScope on the Player ghost on /// the specified connection. ! void onGhostAvailable(TNL::GhostConnection *theConnection); /// onGhostAdd is called for every NetObject on the client after the ghost has *************** *** 138,142 **** /// false from this function would indicate than an error had occured, notifying the /// network system that the connection should be terminated. ! bool onGhostAdd(GhostConnection *theConnection); /// Adds this Player to the list of Player instances in the specified game. --- 136,140 ---- /// false from this function would indicate than an error had occured, notifying the /// network system that the connection should be terminated. ! bool onGhostAdd(TNL::GhostConnection *theConnection); /// Adds this Player to the list of Player instances in the specified game. *************** *** 150,154 **** /// 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. ! TNL_DECLARE_RPC(rpcPlayerDidMove, (Float<6> x, Float<6> y)); /// rpcPlayerIsInScope is the RPC method called by onGhostAvailable to demonstrate --- 148,152 ---- /// 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. ! TNL_DECLARE_RPC(rpcPlayerDidMove, (TNL::Float<6> x, TNL::Float<6> y)); /// rpcPlayerIsInScope is the RPC method called by onGhostAvailable to demonstrate *************** *** 156,160 **** /// 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. ! TNL_DECLARE_RPC(rpcPlayerIsInScope, (Float<6> x, Float<6> y)); /// This macro invocation declares the Player class to be known --- 154,158 ---- /// 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. ! TNL_DECLARE_RPC(rpcPlayerIsInScope, (TNL::Float<6> x, TNL::Float<6> y)); /// This macro invocation declares the Player class to be known *************** *** 168,174 **** /// for them or not. The "buildings" are represented by red rectangles on the /// playing field, and are constructed with random position and extents. ! class Building : public NetObject { ! typedef NetObject Parent; public: /// Mask bits used to determine what states are out of date for this --- 166,172 ---- /// for them or not. The "buildings" are represented by red rectangles on the /// playing field, and are constructed with random position and extents. ! class Building : public TNL::NetObject { ! typedef TNL::NetObject Parent; public: /// Mask bits used to determine what states are out of date for this *************** *** 190,194 **** /// client and its first unpackUpdate has been called. onGhostAdd adds /// the building to the client game. ! bool onGhostAdd(GhostConnection *theConnection); /// addToGame is a helper function called by onGhostAdd and on the server --- 188,192 ---- /// client and its first unpackUpdate has been called. onGhostAdd adds /// the building to the client game. ! bool onGhostAdd(TNL::GhostConnection *theConnection); /// addToGame is a helper function called by onGhostAdd and on the server *************** *** 200,207 **** /// mask bit state and never calls setMaskBits, this method will only be invoked when /// the ghost is being created on the client. ! U32 packUpdate(GhostConnection *connection, U32 updateMask, BitStream *stream); /// Reads the update information about the building from the specified packet BitStream. ! void unpackUpdate(GhostConnection *connection, BitStream *stream); /// This macro declares Building to be a part of the TNL network class management system. --- 198,205 ---- /// mask bit state and never calls setMaskBits, this method will only be invoked when /// the ghost is being created on the client. ! TNL::U32 packUpdate(TNL::GhostConnection *connection, TNL::U32 updateMask, TNL::BitStream *stream); /// Reads the update information about the building from the specified packet BitStream. ! void unpackUpdate(TNL::GhostConnection *connection, TNL::BitStream *stream); /// This macro declares Building to be a part of the TNL network class management system. *************** *** 219,225 **** /// TestConnection notifies the network interface that it should begin /// searching for a new server to join. ! class TestConnection : public GhostConnection { ! typedef GhostConnection Parent; public: --- 217,223 ---- /// TestConnection notifies the network interface that it should begin /// searching for a new server to join. ! class TestConnection : public TNL::GhostConnection { ! typedef TNL::GhostConnection Parent; public: *************** *** 229,233 **** /// The player object associated with this connection. ! SafePtr<Player> myPlayer; /// onConnectTerminated is called when the connection request to the server --- 227,231 ---- /// The player object associated with this connection. ! TNL::SafePtr<Player> myPlayer; /// onConnectTerminated is called when the connection request to the server *************** *** 235,239 **** /// When a TestConnection connect request to a server is terminated, the client's network interface /// is notified so it can begin searching for another server to connect to. ! void onConnectTerminated(NetConnection::TerminationReason reason, const char *rejectionString); /// onConnectionTerminated is called when an established connection is terminated, whether --- 233,237 ---- /// When a TestConnection connect request to a server is terminated, the client's network interface /// is notified so it can begin searching for another server to connect to. ! void onConnectTerminated(TNL::NetConnection::TerminationReason reason, const char *rejectionString); /// onConnectionTerminated is called when an established connection is terminated, whether *************** *** 241,245 **** /// When a TestConnection to a server is disconnected, the client's network interface /// is notified so it can begin searching for another server to connect to. ! void onConnectionTerminated(NetConnection::TerminationReason reason, const char *string); /// onConnectionEstablished is called on both ends of a connection when the connection is established. --- 239,243 ---- /// When a TestConnection to a server is disconnected, the client's network interface /// is notified so it can begin searching for another server to connect to. ! void onConnectionTerminated(TNL::NetConnection::TerminationReason reason, const char *string); /// onConnectionEstablished is called on both ends of a connection when the connection is established. *************** *** 254,258 **** /// Remote function that client calls to set the position of the player on the server. ! TNL_DECLARE_RPC(rpcSetPlayerPos, (F32 x, F32 y)); /// Enumeration constant used to specify the size field of Float<> parameters in the rpcGotPlayerPos method. --- 252,256 ---- /// Remote function that client calls to set the position of the player on the server. ! TNL_DECLARE_RPC(rpcSetPlayerPos, (TNL::F32 x, TNL::F32 y)); /// Enumeration constant used to specify the size field of Float<> parameters in the rpcGotPlayerPos method. *************** *** 265,269 **** /// that's possible using TNL's RPC. This RPC also sends bool and StringTableEntry data, /// as well as showing the use of the TNL_DECLARE_RPC_ENUM macro. ! TNL_DECLARE_RPC(rpcGotPlayerPos, (bool b1, bool b2, StringTableEntryRef string, Float<PlayerPosReplyBitSize> x, Float<PlayerPosReplyBitSize> y)); /// TNL_DECLARE_NETCONNECTION is used to declare that TestConnection is a valid connection class to the --- 263,267 ---- /// that's possible using TNL's RPC. This RPC also sends bool and StringTableEntry data, /// as well as showing the use of the TNL_DECLARE_RPC_ENUM macro. ! TNL_DECLARE_RPC(rpcGotPlayerPos, (bool b1, bool b2, TNL::StringTableEntryRef string, TNL::Float<PlayerPosReplyBitSize> x, TNL::Float<PlayerPosReplyBitSize> y)); /// TNL_DECLARE_NETCONNECTION is used to declare that TestConnection is a valid connection class to the *************** *** 282,288 **** /// When the connection or connection attempt to that server is terminated, the /// TestNetInterface resumes pinging for available TNLTest servers. ! class TestNetInterface : public NetInterface { ! typedef NetInterface Parent; public: /// Constants used in this NetInterface --- 280,286 ---- /// When the connection or connection attempt to that server is terminated, the /// TestNetInterface resumes pinging for available TNLTest servers. ! class TestNetInterface : public TNL::NetInterface { ! typedef TNL::NetInterface Parent; public: /// Constants used in this NetInterface *************** *** 294,302 **** bool pingingServers; ///< True if this is a client that is pinging for active servers. ! U32 lastPingTime; ///< The last platform time that a GamePingRequest was sent from this network interface. bool isServer; ///< True if this network interface is a server, false if it is a client. ! SafePtr<TestConnection> connectionToServer; ///< A safe pointer to the current connection to the server, if this is a client. ! Address pingAddress; ///< Network address to ping in searching for a server. This can be a specific host address or it can be a LAN broadcast address. TestGame *game; ///< The game object associated with this network interface. --- 292,300 ---- bool pingingServers; ///< True if this is a client that is pinging for active servers. ! TNL::U32 lastPingTime; ///< The last platform time that a GamePingRequest was sent from this network interface. bool isServer; ///< True if this network interface is a server, false if it is a client. ! TNL::SafePtr<TestConnection> connectionToServer; ///< A safe pointer to the current connection to the server, if this is a client. ! TNL::Address pingAddress; ///< Network address to ping in searching for a server. This can be a specific host address or it can be a LAN broadcast address. TestGame *game; ///< The game object associated with this network interface. *************** *** 304,312 **** /// The constructor initializes and binds the network interface, as well as sets /// parameters for the associated game and whether or not it is a server. ! TestNetInterface(TestGame *theGame, bool server, const Address &bindAddress, const Address &pingAddr); /// handleInfoPacket overrides the method in the NetInterface class to handle processing /// of the GamePingRequest and GamePingResponse packet types. ! void handleInfoPacket(const Address &address, U8 packetType, BitStream *stream); /// sendPing sends a GamePingRequest packet to pingAddress of this TestNetInterface. --- 302,310 ---- /// The constructor initializes and binds the network interface, as well as sets /// parameters for the associated game and whether or not it is a server. ! TestNetInterface(TestGame *theGame, bool server, const TNL::Address &bindAddress, const TNL::Address &pingAddr); /// handleInfoPacket overrides the method in the NetInterface class to handle processing /// of the GamePingRequest and GamePingResponse packet types. ! void handleInfoPacket(const TNL::Address &address, TNL::U8 packetType, TNL::BitStream *stream); /// sendPing sends a GamePingRequest packet to pingAddress of this TestNetInterface. *************** *** 324,334 **** class TestGame { public: ! Vector<Player *> players; ///< vector of player objects in the game ! Vector<Building *> buildings; ///< vector of buildings in the game bool isServer; ///< was this game created to be a server? TestNetInterface *myNetInterface; ///< network interface for this game ! U32 lastTime; ///< last time that tick() was called ! SafePtr<Player> serverPlayer; ///< the player that the server controls ! SafePtr<Player> clientPlayer; ///< the player that this client controls, if this game is a client /// Constructor for TestGame, determines whether this game will be a client --- 322,332 ---- class TestGame { public: ! TNL::Vector<Player *> players; ///< vector of player objects in the game ! TNL::Vector<Building *> buildings; ///< vector of buildings in the game bool isServer; ///< was this game created to be a server? TestNetInterface *myNetInterface; ///< network interface for this game ! TNL::U32 lastTime; ///< last time that tick() was called ! TNL::SafePtr<Player> serverPlayer; ///< the player that the server controls ! TNL::SafePtr<Player> clientPlayer; ///< the player that this client controls, if this game is a client /// Constructor for TestGame, determines whether this game will be a client *************** *** 337,341 **** /// populate the "world" with. TestGame also constructs an AsymmetricKey to /// demonstrate establishing secure connections with clients and servers. ! TestGame(bool server, const Address &bindAddress, const Address &pingAddress); /// Destroys a game, freeing all Player and Building objects associated with it. --- 335,339 ---- /// populate the "world" with. TestGame also constructs an AsymmetricKey to /// demonstrate establishing secure connections with clients and servers. ! TestGame(bool server, const TNL::Address &bindAddress, const TNL::Address &pingAddress); /// Destroys a game, freeing all Player and Building objects associated with it. Index: testGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/test/testGame.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** testGame.cpp 19 Aug 2004 20:24:51 -0000 1.7 --- testGame.cpp 19 Aug 2004 21:20:14 -0000 1.8 *************** *** 46,51 **** { // assign a random starting position for the player. ! startPos.x = Random::readF(); ! startPos.y = Random::readF(); endPos.x = startPos.x; endPos.y = startPos.y; --- 46,51 ---- { // assign a random starting position for the player. ! startPos.x = TNL::Random::readF(); ! startPos.y = TNL::Random::readF(); endPos.x = startPos.x; endPos.y = startPos.y; *************** *** 69,73 **** // remove the player from the list of players in the game. ! for( S32 i = 0; i < game->players.size(); i++) { if(game->players[i] == this) --- 69,73 ---- // remove the player from the list of players in the game. ! for( TNL::S32 i = 0; i < game->players.size(); i++) { if(game->players[i] == this) *************** *** 93,97 **** } ! bool Player::onGhostAdd(GhostConnection *theConnection) { addToGame(((TestNetInterface *) theConnection->getInterface())->game); --- 93,97 ---- } ! bool Player::onGhostAdd(TNL::GhostConnection *theConnection) { addToGame(((TestNetInterface *) theConnection->getInterface())->game); *************** *** 99,103 **** } ! void Player::performScopeQuery(GhostConnection *connection) { // find all the objects that are "in scope" - for the purposes --- 99,103 ---- } ! void Player::performScopeQuery(TNL::GhostConnection *connection) { // find all the objects that are "in scope" - for the purposes *************** *** 106,118 **** // 0.25 around the scope object, or a radius squared of 0.0625 ! for(S32 i = 0; i < game->buildings.size(); i++) connection->objectInScope(game->buildings[i]); ! for(S32 i = 0; i < game->players.size(); i++) { Position playerP = game->players[i]->renderPos; ! F32 dx = playerP.x - renderPos.x; ! F32 dy = playerP.y - renderPos.y; ! F32 distSquared = dx * dx + dy * dy; if(distSquared < 0.0625) connection->objectInScope(game->players[i]); --- 106,118 ---- // 0.25 around the scope object, or a radius squared of 0.0625 ! for(TNL::S32 i = 0; i < game->buildings.size(); i++) connection->objectInScope(game->buildings[i]); ! for(TNL::S32 i = 0; i < game->players.size(); i++) { Position playerP = game->players[i]->renderPos; ! TNL::F32 dx = playerP.x - renderPos.x; ! TNL::F32 dy = playerP.y - renderPos.y; ! TNL::F32 distSquared = dx * dx + dy * dy; if(distSquared < 0.0625) connection->objectInScope(game->players[i]); *************** *** 120,124 **** } ! U32 Player::packUpdate(GhostConnection *connection, U32 updateMask, BitStream *stream) { // if this is the initial update, write out some static --- 120,124 ---- } ! TNL::U32 Player::packUpdate(TNL::GhostConnection *connection, TNL::U32 updateMask, TNL::BitStream *stream) { // if this is the initial update, write out some static *************** *** 167,171 **** } ! void Player::unpackUpdate(GhostConnection *connection, BitStream *stream) { // see if the initial packet data was written: --- 167,171 ---- } ! void Player::unpackUpdate(TNL::GhostConnection *connection, TNL::BitStream *stream) { // see if the initial packet data was written: *************** *** 197,201 **** } ! void Player::serverSetPosition(Position inStartPos, Position inEndPos, F32 inT, F32 inTDelta) { // update the instance variables of the object --- 197,201 ---- } ! void Player::serverSetPosition(Position inStartPos, Position inEndPos, TNL::F32 inT, TNL::F32 inTDelta) { // update the instance variables of the object *************** *** 212,216 **** } ! void Player::update(F32 timeDelta) { t += tDelta * timeDelta; --- 212,216 ---- } ! void Player::update(TNL::F32 timeDelta) { t += tDelta * timeDelta; *************** *** 225,231 **** startPos = renderPos; t = 0; ! endPos.x = Random::readF(); ! endPos.y = Random::readF(); ! tDelta = 0.2f + Random::readF() * 0.1f; setMaskBits(PositionMask); // notify the network system that the network state has been updated } --- 225,231 ---- startPos = renderPos; t = 0; ! endPos.x = TNL::Random::readF(); ! endPos.y = TNL::Random::readF(); ! tDelta = 0.2f + TNL::Random::readF() * 0.1f; setMaskBits(PositionMask); // notify the network system that the network state has been updated } *************** *** 235,239 **** } ! void Player::onGhostAvailable(GhostConnection *theConnection) { // this function is called every time a ghost of this object is known --- 235,239 ---- } ! void Player::onGhostAvailable(TNL::GhostConnection *theConnection) { // this function is called every time a ghost of this object is known *************** *** 247,251 **** // the RPC macros create a RPCNAME_construct function that returns // a NetEvent that encapsulates the RPC. ! NetEvent *theRPCEvent = TNL_RPC_CONSTRUCT_NETEVENT(this, rpcPlayerIsInScope, (renderPos.x, renderPos.y)); // then we can just post the event to whatever connections we want to have --- 247,251 ---- // the RPC macros create a RPCNAME_construct function that returns // a NetEvent that encapsulates the RPC. ! TNL::NetEvent *theRPCEvent = TNL_RPC_CONSTRUCT_NETEVENT(this, rpcPlayerIsInScope, (renderPos.x, renderPos.y)); // then we can just post the event to whatever connections we want to have *************** *** 256,277 **** } ! TNL_IMPLEMENT_NETOBJECT_RPC(Player, rpcPlayerIsInScope, (Float<6> x, Float<6> y), ! NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0) { ! F32 fx = x, fy = y; ! logprintf("A player is now in scope at %g, %g", fx, fy); } TNL_IMPLEMENT_NETOBJECT_RPC(Player, rpcPlayerWillMove, (const char *testString), ! NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhostParent, 0) { ! logprintf("Expecting a player move from the connection: %s", testString); } ! TNL_IMPLEMENT_NETOBJECT_RPC(Player, rpcPlayerDidMove, (Float<6> x, Float<6> y), ! NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0) { ! F32 fx = x, fy = y; ! logprintf("A player moved to %g, %g", fx, fy); } --- 256,277 ---- } ! TNL_IMPLEMENT_NETOBJECT_RPC(Player, rpcPlayerIsInScope, (TNL::Float<6> x, TNL::Float<6> y), ! TNL::NetClassGroupGameMask, TNL::RPCGuaranteedOrdered, TNL::RPCToGhost, 0) { ! TNL::F32 fx = x, fy = y; ! TNL::logprintf("A player is now in scope at %g, %g", fx, fy); } TNL_IMPLEMENT_NETOBJECT_RPC(Player, rpcPlayerWillMove, (const char *testString), ! TNL::NetClassGroupGameMask, TNL::RPCGuaranteedOrdered, TNL::RPCToGhostParent, 0) { ! TNL::logprintf("Expecting a player move from the connection: %s", testString); } ! TNL_IMPLEMENT_NETOBJECT_RPC(Player, rpcPlayerDidMove, (TNL::Float<6> x, TNL::Float<6> y), ! TNL::NetClassGroupGameMask, TNL::RPCGuaranteedOrdered, TNL::RPCToGhost, 0) { ! TNL::F32 fx = x, fy = y; ! TNL::logprintf("A player moved to %g, %g", fx, fy); } *************** *** 282,290 **** { // place the "building" in a random position on the screen ! upperLeft.x = Random::readF(); ! upperLeft.y = Random::readF(); ! lowerRight.x = upperLeft.x + Random::readF() * 0.1f + 0.025f; ! lowerRight.y = upperLeft.y + Random::readF() * 0.1f + 0.025f; game = NULL; --- 282,290 ---- { // place the "building" in a random position on the screen ! upperLeft.x = TNL::Random::readF(); ! upperLeft.y = TNL::Random::readF(); ! lowerRight.x = upperLeft.x + TNL::Random::readF() * 0.1f + 0.025f; ! lowerRight.y = upperLeft.y + TNL::Random::readF() * 0.1f + 0.025f; game = NULL; *************** *** 300,304 **** // remove the building from the list of buildings in the game. ! for( S32 i = 0; i < game->buildings.size(); i++) { if(game->buildings[i] == this) --- 300,304 ---- // remove the building from the list of buildings in the game. ! for( TNL::S32 i = 0; i < game->buildings.size(); i++) { if(game->buildings[i] == this) *************** *** 317,321 **** } ! bool Building::onGhostAdd(GhostConnection *theConnection) { addToGame(((TestNetInterface *) theConnection->getInterface())->game); --- 317,321 ---- } ! bool Building::onGhostAdd(TNL::GhostConnection *theConnection) { addToGame(((TestNetInterface *) theConnection->getInterface())->game); *************** *** 323,327 **** } ! U32 Building::packUpdate(GhostConnection *connection, U32 updateMask, BitStream *stream) { if(stream->writeFlag(updateMask & InitialMask)) --- 323,327 ---- } ! TNL::U32 Building::packUpdate(TNL::GhostConnection *connection, TNL::U32 updateMask, TNL::BitStream *stream) { if(stream->writeFlag(updateMask & InitialMask)) *************** *** 343,347 **** } ! void Building::unpackUpdate(GhostConnection *connection, BitStream *stream) { if(stream->readFlag()) --- 343,347 ---- } ! void Building::unpackUpdate(TNL::GhostConnection *connection, TNL::BitStream *stream) { if(stream->readFlag()) *************** *** 356,372 **** //--------------------------------------------------------------------------------- ! TNL_IMPLEMENT_NETCONNECTION(TestConnection, NetClassGroupGame, true); TNL_DECLARE_MEMBER_ENUM(TestConnection, PlayerPosReplyBitSize); ! TNL_IMPLEMENT_RPC(TestConnection, rpcGotPlayerPos, (bool b1, bool b2, StringTableEntryRef string, Float<TestConnection::PlayerPosReplyBitSize> x, Float<TestConnection::PlayerPosReplyBitSize> y), ! NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirAny, 0) { ! F32 xv = x, yv = y; ! logprintf("Server acknowledged position update - %d %d %s %g %g", b1, b2, string.getString(), xv, yv); } ! TNL_IMPLEMENT_RPC(TestConnection, rpcSetPlayerPos, (F32 x, F32 y), ! NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0) { Position newPosition; --- 356,372 ---- //--------------------------------------------------------------------------------- ! TNL_IMPLEMENT_NETCONNECTION(TestConnection, TNL::NetClassGroupGame, true); TNL_DECLARE_MEMBER_ENUM(TestConnection, PlayerPosReplyBitSize); ! TNL_IMPLEMENT_RPC(TestConnection, rpcGotPlayerPos, (bool b1, bool b2, TNL::StringTableEntryRef string, TNL::Float<TestConnection::PlayerPosReplyBitSize> x, TNL::Float<TestConnection::PlayerPosReplyBitSize> y), ! TNL::NetClassGroupGameMask, TNL::RPCGuaranteedOrdered, TNL::RPCDirAny, 0) { ! TNL::F32 xv = x, yv = y; ! TNL::logprintf("Server acknowledged position update - %d %d %s %g %g", b1, b2, string.getString(), xv, yv); } ! TNL_IMPLEMENT_RPC(TestConnection, rpcSetPlayerPos, (TNL::F32 x, TNL::F32 y), ! TNL::NetClassGroupGameMask, TNL::RPCGuaranteedOrdered, TNL::RPCDirClientToServer, 0) { Position newPosition; *************** *** 374,378 **** newPosition.y = y; ! logprintf("%s - received new position (%g, %g) from client", getNetAddressString(), newPosition.x, newPosition.y); --- 374,378 ---- newPosition.y = y; ! TNL::logprintf("%s - received new position (%g, %g) from client", getNetAddressString(), newPosition.x, newPosition.y); *************** *** 381,385 **** // send an RPC back the other way! ! StringTableEntry helloString("Hello World!!"); rpcGotPlayerPos(true, false, helloString, x, y); }; --- 381,385 ---- // send an RPC back the other way! ! TNL::StringTableEntry helloString("Hello World!!"); rpcGotPlayerPos(true, false, helloString, x, y); }; *************** *** 429,433 **** setGhostFrom(false); setGhostTo(true); ! logprintf("%s - connected to server.", getNetAddressString()); ((TestNetInterface *) getInterface())->connectionToServer = this; } --- 429,433 ---- setGhostFrom(false); setGhostTo(true); ! TNL::logprintf("%s - connected to server.", getNetAddressString()); ((TestNetInterface *) getInterface())->connectionToServer = this; } *************** *** 443,447 **** setGhostTo(false); activateGhosting(); ! logprintf("%s - client connected.", getNetAddressString()); } } --- 443,447 ---- setGhostTo(false); activateGhosting(); ! TNL::logprintf("%s - client connected.", getNetAddressString()); } } *************** *** 449,453 **** //--------------------------------------------------------------------------------- ! TestNetInterface::TestNetInterface(TestGame *theGame, bool server, const Address &bindAddress, const Address &pingAddr) : NetInterface(bindAddress) { game = theGame; --- 449,453 ---- //--------------------------------------------------------------------------------- ! TestNetInterface::TestNetInterface(TestGame *theGame, bool server, const TNL::Address &bindAddress, const TNL::Address &pingAddr) : NetInterface(bindAddress) { game = theGame; *************** *** 460,476 **** void TestNetInterface::sendPing() { ! PacketStream writeStream; // the ping packet right now just has one byte for packet type ! writeStream.write(U8(GamePingRequest)); writeStream.sendto(mSocket, pingAddress); ! logprintf("%s - sending ping.", pingAddress.toString()); } void TestNetInterface::tick() { ! U32 currentTime = Platform::getRealMilliseconds(); if(pingingServers && (lastPingTime + PingDelayTime < currentTime)) --- 460,476 ---- void TestNetInterface::sendPing() { ! TNL::PacketStream writeStream; // the ping packet right now just has one byte for packet type ! writeStream.write(TNL::U8(GamePingRequest)); writeStream.sendto(mSocket, pingAddress); ! TNL::logprintf("%s - sending ping.", pingAddress.toString()); } void TestNetInterface::tick() { ! TNL::U32 currentTime = TNL::Platform::getRealMilliseconds(); if(pingingServers && (lastPingTime + PingDelayTime < currentTime)) *************** *** 489,505 **** // and more. ! void TestNetInterface::handleInfoPacket(const Address &address, U8 packetType, BitStream *stream) { ! PacketStream writeStream; if(packetType == GamePingRequest && isServer) { ! logprintf("%s - received ping.", address.toString()); // we're a server, and we got a ping packet from a client, // so send back a GamePingResponse to let the client know it // has found a server. ! writeStream.write(U8(GamePingResponse)); writeStream.sendto(mSocket, address); ! logprintf("%s - sending ping response.", address.toString()); } else if(packetType == GamePingResponse && pingingServers) --- 489,505 ---- // and more. ! void TestNetInterface::handleInfoPacket(const TNL::Address &address, TNL::U8 packetType, TNL::BitStream *stream) { ! TNL::PacketStream writeStream; if(packetType == GamePingRequest && isServer) { ! TNL::logprintf("%s - received ping.", address.toString()); // we're a server, and we got a ping packet from a client, // so send back a GamePingResponse to let the client know it // has found a server. ! writeStream.write(TNL::U8(GamePingResponse)); writeStream.sendto(mSocket, address); ! TNL::logprintf("%s - sending ping response.", address.toString()); } else if(packetType == GamePingResponse && pingingServers) *************** *** 508,517 **** // pinging, and try to connect to the server. ! logprintf("%s - received ping response.", address.toString()); TestConnection *connection = new TestConnection; connection->connect(this, address); // connect to the server through the game's network interface ! logprintf("Connecting to server: %s", address.toString()); pingingServers = false; --- 508,517 ---- // pinging, and try to connect to the server. ! TNL::logprintf("%s - received ping response.", address.toString()); TestConnection *connection = new TestConnection; connection->connect(this, address); // connect to the server through the game's network interface ! TNL::logprintf("Connecting to server: %s", address.toString()); pingingServers = false; *************** *** 522,544 **** //--------------------------------------------------------------------------------- ! TestGame::TestGame(bool server, const Address &interfaceBindAddr, const Address &pingAddress) { isServer = server; myNetInterface = new TestNetInterface(this, isServer, interfaceBindAddr, pingAddress); ! AsymmetricKey *theKey = new AsymmetricKey(32); myNetInterface->setPrivateKey(theKey); myNetInterface->setRequiresKeyExchange(true); ! lastTime = Platform::getRealMilliseconds(); if(isServer) { // generate some buildings and AIs: ! for(S32 i = 0; i < 50; i ++) { Building *building = new Building; building->addToGame(this); } ! for(S32 i = 0; i < 15; i ++) { Player *aiPlayer = new Player(Player::PlayerTypeAI); --- 522,544 ---- //--------------------------------------------------------------------------------- ! TestGame::TestGame(bool server, const TNL::Address &interfaceBindAddr, const TNL::Address &pingAddress) { isServer = server; myNetInterface = new TestNetInterface(this, isServer, interfaceBindAddr, pingAddress); ! TNL::AsymmetricKey *theKey = new TNL::AsymmetricKey(32); myNetInterface->setPrivateKey(theKey); myNetInterface->setRequiresKeyExchange(true); ! lastTime = TNL::Platform::getRealMilliseconds(); if(isServer) { // generate some buildings and AIs: ! for(TNL::S32 i = 0; i < 50; i ++) { Building *building = new Building; building->addToGame(this); } ! for(TNL::S32 i = 0; i < 15; i ++) { Player *aiPlayer = new Player(Player::PlayerTypeAI); *************** *** 549,553 **** } ! logprintf("Created a %s...", (server ? "server" : "client")); } --- 549,553 ---- } ! TNL::logprintf("Created a %s...", (server ? "server" : "client")); } *************** *** 555,564 **** { delete myNetInterface; ! for(S32 i = 0; i < buildings.size(); i++) delete buildings[i]; ! for(S32 i = 0; i < players.size(); i++) delete players[i]; ! logprintf("Destroyed a %s...", (this->isServer ? "server" : "client")); } --- 555,564 ---- { delete myNetInterface; ! for(TNL::S32 i = 0; i < buildings.size(); i++) delete buildings[i]; ! for(TNL::S32 i = 0; i < players.size(); i++) delete players[i]; ! TNL::logprintf("Destroyed a %s...", (this->isServer ? "server" : "client")); } *************** *** 572,581 **** void TestGame::tick() { ! U32 currentTime = Platform::getRealMilliseconds(); if(currentTime == lastTime) return; ! F32 timeDelta = (currentTime - lastTime) / 1000.0f; ! for(S32 i = 0; i < players.size(); i++) players[i]->update(timeDelta); myNetInterface->tick(); --- 572,581 ---- void TestGame::tick() { ! TNL::U32 currentTime = TNL::Platform::getRealMilliseconds(); if(currentTime == lastTime) return; ! TNL::F32 timeDelta = (currentTime - lastTime) / 1000.0f; ! for(TNL::S32 i = 0; i < players.size(); i++) players[i]->update(timeDelta); myNetInterface->tick(); *************** *** 591,595 **** else if(!myNetInterface->connectionToServer.isNull()) { ! logprintf("posting new position (%g, %g) to server", newPosition.x, newPosition.y); if(!clientPlayer.isNull()) clientPlayer->rpcPlayerWillMove("Whee! Foo!"); --- 591,595 ---- else if(!myNetInterface->connectionToServer.isNull()) { ! TNL::logprintf("posting new position (%g, %g) to server", newPosition.x, newPosition.y); if(!clientPlayer.isNull()) clientPlayer->rpcPlayerWillMove("Whee! Foo!"); Index: testGameRender.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/test/testGameRender.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testGameRender.cpp 20 Apr 2004 04:27:18 -0000 1.1 --- testGameRender.cpp 19 Aug 2004 21:20:15 -0000 1.2 *************** *** 61,65 **** glBegin(GL_POLYGON); glColor4f(0.5f, 0.5f, 0.5f, 0.65f); ! for(F32 r = 0; r < 3.1415 * 2; r += 0.1f) { glVertex2f(p.x + 0.25f * cos(r), p.y + 0.25f * sin(r)); --- 61,65 ---- glBegin(GL_POLYGON); glColor4f(0.5f, 0.5f, 0.5f, 0.65f); ! for(TNL::F32 r = 0; r < 3.1415 * 2; r += 0.1f) { glVertex2f(p.x + 0.25f * cos(r), p.y + 0.25f * sin(r)); *************** *** 71,75 **** // then draw all the buildings. ! for(S32 i = 0; i < buildings.size(); i++) { Building *b = buildings[i]; --- 71,75 ---- // then draw all the buildings. ! for(TNL::S32 i = 0; i < buildings.size(); i++) { Building *b = buildings[i]; *************** *** 84,88 **** // last, draw all the players in the game. ! for(S32 i = 0; i < players.size(); i++) { Player *p = players[i]; --- 84,88 ---- // last, draw all the players in the game. ! for(TNL::S32 i = 0; i < players.size(); i++) { Player *p = players[i]; Index: server.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/test/server.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** server.cpp 20 May 2004 22:49:03 -0000 1.2 --- server.cpp 19 Aug 2004 21:20:14 -0000 1.3 *************** *** 32,35 **** --- 32,37 ---- #include "../tnl/tnlBitStream.h" + using namespace TNL; + //#define TNLTest_SERVER #define TNL_TEST_RPC Index: testWindow.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/test/testWindow.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** testWindow.cpp 27 May 2004 22:41:16 -0000 1.2 --- testWindow.cpp 19 Aug 2004 21:20:15 -0000 1.3 *************** *** 44,48 **** // create a client, by default pinging the LAN broadcast on port 28999 ! clientGame = new TestGame(false,Address(IPProtocol, Address::Any, 0),Address(pingLocalHost ? localHostAddress : localBroadcastAddress)); serverGame = NULL; } --- 44,48 ---- // create a client, by default pinging the LAN broadcast on port 28999 ! clientGame = new TestGame(false,TNL::Address(TNL::IPProtocol, TNL::Address::Any, 0),TNL::Address(pingLocalHost ? localHostAddress : localBroadcastAddress)); serverGame = NULL; } *************** *** 55,59 **** clientGame = NULL; // create a server, listening on port 28999. ! serverGame = new TestGame(true,Address(IPProtocol,Address::Any, 28999),Address(localBroadcastAddress)); } --- 55,59 ---- clientGame = NULL; // create a server, listening on port 28999. ! serverGame = new TestGame(true,TNL::Address(TNL::IPProtocol,TNL::Address::Any, 28999),TNL::Address(localBroadcastAddress)); } *************** *** 65,70 **** // construct two local games, one client and one server, and have the client game ping the localhost // loopback address. ! clientGame = new TestGame(false,Address(IPProtocol, Address::Any, 0),Address(localHostAddress)); ! serverGame = new TestGame(true,Address(IPProtocol,Address::Any, 28999),Address(localBroadcastAddress)); // If the following line is commented out, the local games will create a normal (network) connection. --- 65,70 ---- // construct two local games, one client and one server, and have the client game ping the localhost // loopback address. ! clientGame = new TestGame(false,TNL::Address(TNL::IPProtocol, TNL::Address::Any, 0),TNL::Address(localHostAddress)); ! serverGame = new TestGame(true,TNL::Address(TNL::IPProtocol,TNL::Address::Any, 28999),TNL::Address(localBroadcastAddress)); // If the following line is commented out, the local games will create a normal (network) connection. *************** *** 97,102 **** { Position p; ! p.x = x / F32(gWindowWidth); ! p.y = y / F32(gWindowHeight); if(clientGame) --- 97,102 ---- { Position p; ! p.x = x / TNL::F32(gWindowWidth); ! p.y = y / TNL::F32(gWindowHeight); if(clientGame) *************** *** 147,151 **** #include <stdio.h> ! class StdoutLogConsumer : public LogConsumer { public: --- 147,151 ---- #include <stdio.h> ! class StdoutLogConsumer : public TNL::LogConsumer { public: |