fix some more compiler errors...
--- a/src/proto2/GameState.cc Tue Nov 18 19:05:35 2008 +0000
+++ b/src/proto2/GameState.cc Tue Nov 18 19:17:56 2008 +0000
@@ -5,16 +5,16 @@
int dx = 0, dy = 0;
// handle up/down/left/right
- if (input & MOVE_UP)
+ if (input & INPUT_MOVE_UP)
dy -= 3;
- if (input & MOVE_DOWN)
+ if (input & INPUT_MOVE_DOWN)
dy += 3;
- if (input & MOVE_LEFT)
+ if (input & INPUT_MOVE_LEFT)
dx -= 3;
- if (input & MOVE_RIGHT)
+ if (input & INPUT_MOVE_RIGHT)
dx += 3;
// apply force
--- a/src/proto2/Graphics.cc Tue Nov 18 19:05:35 2008 +0000
+++ b/src/proto2/Graphics.cc Tue Nov 18 19:17:56 2008 +0000
@@ -17,7 +17,7 @@
void Graphics::check_input (void) {
LocalPlayer *player;
- enum PlayerInput_Move input_move;
+ PlayerInput_Move input_move;
// stop on escape
if (keyboard.get_keycode(CL_KEY_ESCAPE)) {
@@ -32,16 +32,16 @@
// handle up/down/left/right
if (keyboard.get_keycode(CL_KEY_UP))
- input_move |= MOVE_UP;
+ input_move |= INPUT_MOVE_UP;
if (keyboard.get_keycode(CL_KEY_DOWN))
- input_move |= MOVE_DOWN;
+ input_move |= INPUT_MOVE_DOWN;
if (keyboard.get_keycode(CL_KEY_LEFT))
- input_move |= MOVE_LEFT;
+ input_move |= INPUT_MOVE_LEFT;
if (keyboard.get_keycode(CL_KEY_RIGHT))
- input_move |= MOVE_RIGHT;
+ input_move |= INPUT_MOVE_RIGHT;
// apply movement if applicable
if (input_move)
--- a/src/proto2/Input.hh Tue Nov 18 19:05:35 2008 +0000
+++ b/src/proto2/Input.hh Tue Nov 18 19:17:56 2008 +0000
@@ -1,11 +1,13 @@
#ifndef INPUT_HH
#define INPUT_HH
-enum PlayerInput_Move {
- MOVE_UP = 0x01,
- MOVE_DOWN = 0x02,
- MOVE_LEFT = 0x04,
- MOVE_RIGHT = 0x08,
+enum {
+ INPUT_MOVE_UP = 0x01,
+ INPUT_MOVE_DOWN = 0x02,
+ INPUT_MOVE_LEFT = 0x04,
+ INPUT_MOVE_RIGHT = 0x08,
};
+typedef uint16_t PlayerInput_Move;
+
#endif
--- a/src/proto2/NetworkClient.cc Tue Nov 18 19:05:35 2008 +0000
+++ b/src/proto2/NetworkClient.cc Tue Nov 18 19:17:56 2008 +0000
@@ -41,7 +41,7 @@
uint32_t x = pkt.input.read_uint32();
uint32_t y = pkt.input.read_uint32();
- Coordinate initial_position(x, y);
+ Vector initial_position(x, y);
Engine::log(INFO, "client.on_server_hello") << "obj=" << obj << ", pos=" << initial_position;
@@ -57,7 +57,7 @@
uint32_t x = pkt.input.read_uint32();
uint32_t y = pkt.input.read_uint32();
- Coordinate initial_position(x, y);
+ Vector initial_position(x, y);
Engine::log(INFO, "client.on_player_info") << "obj=" << obj << ", pos=" << initial_position;
@@ -74,7 +74,7 @@
uint32_t x = pkt.input.read_uint32();
uint32_t y = pkt.input.read_uint32();
- Coordinate initial_position(x, y);
+ Vector initial_position(x, y);
Engine::log(INFO, "client.on_player_join") << "obj=" << obj << ", pos=" << initial_position;
@@ -94,38 +94,38 @@
// 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 initial_position) :
+ LocalPlayer(initial_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) {
+bool NetworkClientLocalPlayer::handleMove (PlayerInput_Move move) {
// always send move, in all cases
CL_NetPacket pkt;
- pkt.output.write_int32(d.dx);
- pkt.output.write_int32(d.dy);
+ pkt.output.write_uint16(move);
obj.send(NETMSG_CLIENT_MOVE, pkt, false);
-
- // return validity
- return LocalPlayer::move(d);
+
+ // handle locally
+ return LocalPlayer::handleMove(move);
}
void NetworkClientLocalPlayer::on_position (CL_NetPacket &pkt) {
uint32_t x = pkt.input.read_uint32();
uint32_t y = pkt.input.read_uint32();
- Coordinate pos (x, y);
+ Vector pos (x, y);
Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", pos=" << pos;
- assert(updatePosition(pos));
+ // XXX: transmit velocity/force
+ updatePhysics(pos, Vector(0, 0), Vector(0, 0));
}
-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 initial_position) :
+ RemotePlayer(initial_position, true), client(client), obj(obj) {
// receive messages
slots.connect(obj.sig_received_message(NETMSG_PLAYER_POSITION), this, &NetworkClientRemotePlayer::on_position);
@@ -136,11 +136,12 @@
uint32_t x = pkt.input.read_uint32();
uint32_t y = pkt.input.read_uint32();
- Coordinate pos (x, y);
+ Vector pos (x, y);
Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", pos=" << pos;
- assert(updatePosition(pos));
+ // XXX: transmit velocity/force
+ updatePhysics(pos, Vector(0, 0), Vector(0, 0));
}
void NetworkClientRemotePlayer::on_quit (CL_NetPacket &pkt) {
--- a/src/proto2/NetworkClient.hh Tue Nov 18 19:05:35 2008 +0000
+++ b/src/proto2/NetworkClient.hh Tue Nov 18 19:17:56 2008 +0000
@@ -38,9 +38,9 @@
CL_NetObject_Client obj;
public:
- NetworkClientLocalPlayer (NetworkClient &client, CL_NetObject_Client &obj, Coordinate initial_position);
+ NetworkClientLocalPlayer (NetworkClient &client, CL_NetObject_Client &obj, Vector initial_position);
- virtual bool move (PositionDelta d);
+ virtual bool handleMove (PlayerInput_Move input);
private:
void on_position (CL_NetPacket &pkt);
@@ -55,7 +55,7 @@
CL_NetObject_Client obj;
public:
- NetworkClientRemotePlayer (NetworkClient &client, CL_NetObject_Client &obj, Coordinate initial_position);
+ NetworkClientRemotePlayer (NetworkClient &client, CL_NetObject_Client &obj, Vector initial_position);
private:
void on_position (CL_NetPacket &pkt);
--- a/src/proto2/NetworkServer.cc Tue Nov 18 19:05:35 2008 +0000
+++ b/src/proto2/NetworkServer.cc Tue Nov 18 19:17:56 2008 +0000
@@ -48,7 +48,7 @@
}
NetworkServerPlayer::NetworkServerPlayer (NetworkServer &server, CL_NetComputer &computer, uint16_t pid) :
- RemotePlayer(server.state, Coordinate(100, 100), true), server(server), computer(computer), obj(&server.netobjs), pid(pid) {
+ RemotePlayer(Vector(100, 100), true), server(server), computer(computer), obj(&server.netobjs), pid(pid) {
// log
Engine::log(INFO, "server_player.connected") << "computer=" << computer << ", obj=" << obj;
@@ -100,7 +100,7 @@
int32_t dy = pkt.input.read_int32();
// movement delta
- PositionDelta delta(dx, dy);
+ Vector delta(dx, dy);
Engine::log(INFO, "server_player.on_move") << "obj=" << obj << ", old_pos=" << position << ", delta=" << delta;
--- a/src/proto2/Physics.cc Tue Nov 18 19:05:35 2008 +0000
+++ b/src/proto2/Physics.cc Tue Nov 18 19:17:56 2008 +0000
@@ -5,9 +5,9 @@
PhysicsWorld::PhysicsWorld (Vector dimensions)
- : dimensions(dimensions), tick_timer(PHYSICS_TICK_MS) {
+ : tick_timer(PHYSICS_TICK_MS), dimensions(dimensions) {
- slots.connect(tick_timer.sig_timer(), this, PhysicsWorld::tick);
+ slots.connect(tick_timer.sig_timer(), this, &PhysicsWorld::tick);
tick_timer.enable();
}
@@ -34,8 +34,8 @@
//TODO Handle the object as a square or a polygon
- if(newPosition.x() < 0 || (newPosition.x() > PHYSICS_WORLD_WIDTH)
- || (newPosition.y() < 0) || (newPosition.y() >= PHYSICS_WORLD_HEIGHT)) {
+ if(newPosition.x < 0 || (newPosition.x > PHYSICS_WORLD_WIDTH)
+ || (newPosition.y < 0) || (newPosition.y >= PHYSICS_WORLD_HEIGHT)) {
// CRASH!
this->velocity *= -1;
@@ -50,7 +50,7 @@
// It should be scaled somehow.
}
-void PhysicsObjectu::updatePhysics (Vector position, Vector velocity, Vector force) {
+void PhysicsObject::updatePhysics (Vector position, Vector velocity, Vector force) {
this->position = position;
this->velocity = velocity;
this->force = force;
--- a/src/proto2/Physics.hh Tue Nov 18 19:05:35 2008 +0000
+++ b/src/proto2/Physics.hh Tue Nov 18 19:17:56 2008 +0000
@@ -33,10 +33,10 @@
class PhysicsObject {
protected:
+ uint16_t mass;
Vector position;
Vector velocity;
Vector force;
- uint16_t mass;
PhysicsObject (uint16_t mass, Vector position, Vector velocity, Vector force);
--- a/src/proto2/Vector.hh Tue Nov 18 19:05:35 2008 +0000
+++ b/src/proto2/Vector.hh Tue Nov 18 19:17:56 2008 +0000
@@ -33,7 +33,6 @@
x += c.x;
y += c.y;
}
-
coor operator * (const double d) {
return coor(x*d, y*d);
}