src/proto2/NetworkClient.cc
branchno-netsession
changeset 35 e21cfda0edde
parent 28 3da59a3bc92e
child 36 785d220fc6b7
--- a/src/proto2/NetworkClient.cc	Mon Nov 10 21:58:38 2008 +0000
+++ b/src/proto2/NetworkClient.cc	Tue Nov 18 22:58:50 2008 +0000
@@ -38,15 +38,12 @@
         
 void NetworkClient::on_server_hello (CL_NetObject_Client &obj, CL_NetPacket &pkt) {
     // read the packet
-    uint32_t x = pkt.input.read_uint32();
-    uint32_t y = pkt.input.read_uint32();
-
-    Coordinate initial_position(x, y);
+    Vector position = readVector(pkt);
     
-    Engine::log(INFO, "client.on_server_hello") << "obj=" << obj << ", pos=" << initial_position;
+    Engine::log(INFO, "client.on_server_hello") << "obj=" << obj << ", pos=" << position;
 
     // create the LocalPlayer object
-    NetworkClientLocalPlayer *player = new NetworkClientLocalPlayer(*this, obj, initial_position);
+    NetworkClientLocalPlayer *player = new NetworkClientLocalPlayer(*this, obj, position);
 
     // inform state
     state.newLocalPlayer(player);
@@ -54,15 +51,12 @@
         
 void NetworkClient::on_player_info (CL_NetObject_Client &obj, CL_NetPacket &pkt) {
     // read the packet
-    uint32_t x = pkt.input.read_uint32();
-    uint32_t y = pkt.input.read_uint32();
+    Vector position = readVector(pkt);
     
-    Coordinate initial_position(x, y);
-    
-    Engine::log(INFO, "client.on_player_info") << "obj=" << obj << ", pos=" << initial_position;
+    Engine::log(INFO, "client.on_player_info") << "obj=" << obj << ", pos=" << position;
 
     // create the LocalPlayer object
-    NetworkClientRemotePlayer *player = new NetworkClientRemotePlayer(*this, obj, initial_position);
+    NetworkClientRemotePlayer *player = new NetworkClientRemotePlayer(*this, obj, position);
 
     // inform state
     state.newRemotePlayer(player);
@@ -71,15 +65,12 @@
         
 void NetworkClient::on_player_join (CL_NetObject_Client &obj, CL_NetPacket &pkt) {
     // read the packet
-    uint32_t x = pkt.input.read_uint32();
-    uint32_t y = pkt.input.read_uint32();
+    Vector position = readVector(pkt);
     
-    Coordinate initial_position(x, y);
-    
-    Engine::log(INFO, "client.on_player_join") << "obj=" << obj << ", pos=" << initial_position;
+    Engine::log(INFO, "client.on_player_join") << "obj=" << obj << ", pos=" << position;
     
     // create the RemotePlayer object
-    NetworkClientRemotePlayer *player = new NetworkClientRemotePlayer(*this, obj, initial_position);
+    NetworkClientRemotePlayer *player = new NetworkClientRemotePlayer(*this, obj, position);
 
     // inform state
     state.newRemotePlayer(player);
@@ -94,38 +85,36 @@
     //  delete player;
 }
 
-NetworkClientLocalPlayer::NetworkClientLocalPlayer (NetworkClient &client, CL_NetObject_Client &obj, Coordinate initial_position) :
-    LocalPlayer(client.state, initial_position, true), client(client), obj(obj) {
+NetworkClientLocalPlayer::NetworkClientLocalPlayer (NetworkClient &client, CL_NetObject_Client &obj, Vector position) :
+    LocalPlayer(client.state, position, true), client(client), obj(obj) {
     
     // receive messages
     slots.connect(obj.sig_received_message(NETMSG_PLAYER_POSITION), this, &NetworkClientLocalPlayer::on_position);
 }
         
-bool NetworkClientLocalPlayer::move (PositionDelta d) {
+void NetworkClientLocalPlayer::applyForce (Vector force, uint16_t dt) {
     // always send move, in all cases
     CL_NetPacket pkt;
-    pkt.output.write_int32(d.dx);
-    pkt.output.write_int32(d.dy);
+    writeVector(pkt, force);
+    pkt.output.write_uint16(dt);
 
     obj.send(NETMSG_CLIENT_MOVE, pkt, false);
-
-    // return validity
-    return LocalPlayer::move(d);
+    
+    // do not handle locally
 }
         
 void NetworkClientLocalPlayer::on_position (CL_NetPacket &pkt) {
-    uint32_t x = pkt.input.read_uint32();
-    uint32_t y = pkt.input.read_uint32();
+    Vector position = readVector(pkt);
+    Vector velocity = readVector(pkt);
 
-    Coordinate pos (x, y);
-
-    Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", pos=" << pos;
+    Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", position=" << position << ", velocity=" << velocity;
     
-    assert(updatePosition(pos));
+    // just update... 
+    updatePhysics(position, velocity);
 }
         
-NetworkClientRemotePlayer::NetworkClientRemotePlayer (NetworkClient &client, CL_NetObject_Client &obj, Coordinate initial_position) :
-    RemotePlayer(client.state, initial_position, true), client(client), obj(obj) {
+NetworkClientRemotePlayer::NetworkClientRemotePlayer (NetworkClient &client, CL_NetObject_Client &obj, Vector position) :
+    RemotePlayer(client.state, position, true), client(client), obj(obj) {
     
     // receive messages
     slots.connect(obj.sig_received_message(NETMSG_PLAYER_POSITION), this, &NetworkClientRemotePlayer::on_position);
@@ -133,14 +122,13 @@
 }
 
 void NetworkClientRemotePlayer::on_position (CL_NetPacket &pkt) {
-    uint32_t x = pkt.input.read_uint32();
-    uint32_t y = pkt.input.read_uint32();
+    Vector position = readVector(pkt);
+    Vector velocity = readVector(pkt);
+
+    Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", position=" << position << ", velocity=" << velocity;
     
-    Coordinate pos (x, y);
-
-    Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", pos=" << pos;
-    
-    assert(updatePosition(pos));
+    // just update... 
+    updatePhysics(position, velocity);
 }
 
 void NetworkClientRemotePlayer::on_quit (CL_NetPacket &pkt) {