diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-11-27 04:22:53 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-11-27 05:55:00 +0100 |
commit | d0c5819fb141f5cb174f47616d7c5ea4116e871c (patch) | |
tree | 58773bb73dd65e0181de1c4e5a799d76e2ec85e5 | |
parent | 55ae5202de17fb7f7d1d00fc76defa194d7f9b06 (diff) |
Changed format of RoundState again.
-rw-r--r-- | common/message.cpp | 22 | ||||
-rw-r--r-- | common/message.h | 25 | ||||
-rw-r--r-- | server/client.cpp | 4 | ||||
-rw-r--r-- | server/client.h | 4 | ||||
-rw-r--r-- | server/game.cpp | 41 | ||||
-rw-r--r-- | server/game.h | 8 |
6 files changed, 58 insertions, 46 deletions
diff --git a/common/message.cpp b/common/message.cpp index 08c2cdd..4552f2e 100644 --- a/common/message.cpp +++ b/common/message.cpp @@ -136,28 +136,22 @@ Message::RoundState::RoundState() : BoostBase(Types::RoundState) { } -Message::RoundState::RoundState(State state) : BoostBase(Types::RoundState) { - // Compatibility constructor. To be removed. - for(std::size_t i = 0; i < 4; i++) { - hand[i] = state.players[i].hand; - open[i] = state.players[i].open; - pond[i] = state.players[i].pond; - possible_actions = state.possible_actions; - } +Message::RoundState::RoundState(const Player& pl_d, const Player& pl_r, const Player& pl_u, const Player& pl_l, const Tiles& d, const Actions& a) + : BoostBase(Types::RoundState), dora(d), possible_actions(a) { + players[0] = pl_d; + players[1] = pl_d; + players[2] = pl_d; + players[3] = pl_d; } void Message::RoundState::serialize(boost::archive::text_oarchive& ar) { - ar & hand; - ar & open; - ar & pond; + ar & players; ar & dora; ar & possible_actions; } void Message::RoundState::deserialize(boost::archive::text_iarchive& ar) { - ar & hand; - ar & open; - ar & pond; + ar & players; ar & dora; ar & possible_actions; } diff --git a/common/message.h b/common/message.h index cb709af..6f48742 100644 --- a/common/message.h +++ b/common/message.h @@ -13,7 +13,7 @@ using boost::dynamic_pointer_cast; #include <vector> #include <string> -#include "state.h" +#include "action.h" #include "tile.h" namespace Message { @@ -139,12 +139,27 @@ namespace Message { public: typedef boost::shared_ptr<RoundState> p; + // Player contents. + struct Player { + //! Concealed tiles in hand. + Tiles hand; + //! Open tiles in hand. + Tiles open; + //! Discarded tiles. + Tiles pond; + + template<class Archive> + void serialize(Archive & ar, const unsigned int version) { + ar & hand; + ar & open; + ar & pond; + } + }; + RoundState(); - RoundState(State state); + RoundState(const Player& pl_d, const Player& pl_r, const Player& pl_u, const Player& pl_l, const Tiles& d, const Actions& a); - Tiles hand[4]; - Tiles open[4]; - Tiles pond[4]; + Player players[4]; Tiles dora; diff --git a/server/client.cpp b/server/client.cpp index 465da3b..3977b53 100644 --- a/server/client.cpp +++ b/server/client.cpp @@ -84,8 +84,8 @@ void Client::round_start() { connection->send(make_shared<Message::RoundStart>()); } -void Client::round_state(State state) { - connection->send(make_shared<Message::RoundState>(state)); +void Client::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a) { + connection->send(make_shared<Message::RoundState>(pl_d, pl_r, pl_u, pl_l, d, a)); } void Client::round_end() { diff --git a/server/client.h b/server/client.h index ec22e85..b8e11c2 100644 --- a/server/client.h +++ b/server/client.h @@ -46,8 +46,10 @@ class Client : public boost::enable_shared_from_this<Client> { //! Notify client of a round start. void round_start(); + typedef Message::RoundState::Player PlayerState; + //! Send round state. - void round_state(State state); + void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a); //! Send round end. void round_end(); diff --git a/server/game.cpp b/server/game.cpp index 1f43e9b..26d0ce4 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -101,18 +101,19 @@ void Game::round_update_draw() { // Construct and send state to each client. for(int i = 0; i < 4; i++) { - State state; + Player::State state[4]; - state.players[0] = players[i].get_state(); - state.players[1] = players[(i + 1) % 4].get_state_filtered(); - state.players[2] = players[(i + 2) % 4].get_state_filtered(); - state.players[3] = players[(i + 3) % 4].get_state_filtered(); + state[0] = players[i].get_state(); + state[1] = players[(i + 1) % 4].get_state_filtered(); + state[2] = players[(i + 2) % 4].get_state_filtered(); + state[3] = players[(i + 3) % 4].get_state_filtered(); + Actions a; if(i == current_player) { - state.possible_actions = possible_actions; + a = possible_actions; } - players[i].client->round_state(state); + players[i].client->round_state(state[0], state[1], state[2], state[3], Tiles(), a); } // Await action from client. @@ -126,21 +127,21 @@ void Game::round_update_discard() { // Construct and send state to each client. for(int i = 0; i < 4; i++) { - State state; + Player::State state[4]; - state.players[0] = players[i].get_state(); - state.players[1] = players[(i + 1) % 4].get_state_filtered(); - state.players[2] = players[(i + 2) % 4].get_state_filtered(); - state.players[3] = players[(i + 3) % 4].get_state_filtered(); + state[0] = players[i].get_state(); + state[1] = players[(i + 1) % 4].get_state_filtered(); + state[2] = players[(i + 2) % 4].get_state_filtered(); + state[3] = players[(i + 3) % 4].get_state_filtered(); + Actions a; if(i != current_player) { - Actions a = players[i].get_actions_discard(discarded_tile); - if(a) { - state.possible_actions = possible_actions[i] = a; + if(a = players[i].get_actions_discard(discarded_tile)) { + possible_actions[i] = a; } } - players[i].client->round_state(state); + players[i].client->round_state(state[0], state[1], state[2], state[3], Tiles(), a); } preceding_action = Action::Pass; @@ -275,13 +276,13 @@ void Game::Player::round_start() { client->round_start(); } -State::Player Game::Player::get_state() { - State::Player state = {hand, open, pond}; +Game::Player::State Game::Player::get_state() { + State state = {hand, open, pond}; return state; } -State::Player Game::Player::get_state_filtered() { - State::Player state = {hand, open, pond}; +Game::Player::State Game::Player::get_state_filtered() { + State state = {hand, open, pond}; return state; } diff --git a/server/game.h b/server/game.h index 3eaac77..5fd85fd 100644 --- a/server/game.h +++ b/server/game.h @@ -9,8 +9,6 @@ #include "wall.h" #include "client.h" #include "../common/action.h" -#include "../common/state.h" - class Game : public boost::enable_shared_from_this<Game> { public: @@ -33,11 +31,13 @@ class Game : public boost::enable_shared_from_this<Game> { //! Prepare for a new round. void round_start(); + typedef Client::PlayerState State; + //! Get a state snapshot. - State::Player get_state(); + State get_state(); //! Get a state snapshot, with concealed tiles filtered. - State::Player get_state_filtered(); + State get_state_filtered(); //! Get possible actions after a draw. Actions get_actions_draw(); |