Changed wb::manager::net_buffer_.
Instead of just one buffer for all network data, ...there is now one separate buffer for each team's whiteboard network data.
This commit is contained in:
parent
99a9f77410
commit
d31e8eb8f2
4 changed files with 30 additions and 22 deletions
|
@ -61,7 +61,7 @@ manager::manager():
|
|||
fake_unit_(),
|
||||
key_poller_(new CKey),
|
||||
hidden_unit_hex_(),
|
||||
net_buffer_()
|
||||
net_buffer_(resources::teams->size())
|
||||
{
|
||||
LOG_WB << "Manager initialized.\n";
|
||||
}
|
||||
|
@ -409,20 +409,26 @@ void manager::on_gamestate_change()
|
|||
|
||||
void manager::send_network_data()
|
||||
{
|
||||
if(net_buffer_.empty())
|
||||
return;
|
||||
size_t size = net_buffer_.size();
|
||||
for(size_t team_index=0; team_index<size; ++team_index)
|
||||
{
|
||||
config& buf_cfg = net_buffer_[team_index];
|
||||
|
||||
if(buf_cfg.empty())
|
||||
continue;
|
||||
|
||||
config packet;
|
||||
config& wb_cfg = packet.add_child("whiteboard",net_buffer_);
|
||||
wb_cfg["side"] = viewer_side();
|
||||
wb_cfg["team_name"] = resources::teams->at(viewer_team()).team_name();
|
||||
config& wb_cfg = packet.add_child("whiteboard",buf_cfg);
|
||||
wb_cfg["side"] = static_cast<int>(team_index+1);
|
||||
wb_cfg["team_name"] = resources::teams->at(team_index).team_name();
|
||||
|
||||
net_buffer_ = config();
|
||||
buf_cfg = config();
|
||||
|
||||
network::send_data(packet,0,"whiteboard");
|
||||
|
||||
size_t count = wb_cfg.child_count("net_cmd");
|
||||
LOG_WB << "Sent wb data (" << count << ").\n";
|
||||
LOG_WB << "Side " << (team_index+1) << " sent wb data (" << count << " cmds).\n";
|
||||
}
|
||||
}
|
||||
|
||||
void manager::process_network_data(config const& cfg)
|
||||
|
@ -438,9 +444,9 @@ void manager::process_network_data(config const& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void manager::queue_net_cmd(side_actions::net_cmd const& cmd)
|
||||
void manager::queue_net_cmd(size_t team_index, side_actions::net_cmd const& cmd)
|
||||
{
|
||||
net_buffer_.add_child("net_cmd",cmd);
|
||||
net_buffer_[team_index].add_child("net_cmd",cmd);
|
||||
}
|
||||
|
||||
void manager::create_temp_move()
|
||||
|
|
|
@ -79,8 +79,8 @@ public:
|
|||
void send_network_data();
|
||||
/// Called by turn_info::process_network_data() when network data needs to be processed
|
||||
void process_network_data(config const&);
|
||||
/// Adds a side_actions::net_cmd to net_buffer_, whereupon it will be sent to all allies
|
||||
void queue_net_cmd(side_actions::net_cmd const&);
|
||||
/// Adds a side_actions::net_cmd to net_buffer_[team_index], whereupon it will (later) be sent to all allies
|
||||
void queue_net_cmd(size_t team_index, side_actions::net_cmd const&);
|
||||
|
||||
/// Whether the current side has actions in its planned actions queue
|
||||
static bool current_side_has_actions();
|
||||
|
@ -185,7 +185,8 @@ private:
|
|||
|
||||
map_location hidden_unit_hex_;
|
||||
|
||||
config net_buffer_;
|
||||
///net_buffer_[i] = whiteboard network data to be sent "from" teams[i].
|
||||
std::vector<config> net_buffer_;
|
||||
};
|
||||
|
||||
/** Applies the planned unit map for the duration of the struct's life.
|
||||
|
|
|
@ -166,7 +166,7 @@ bool side_actions::execute(side_actions::iterator position)
|
|||
try {
|
||||
exec_result = action->execute();
|
||||
} catch (end_turn_exception&) {
|
||||
resources::whiteboard->queue_net_cmd(make_net_cmd_remove(position));
|
||||
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_remove(position));
|
||||
actions_.erase(position);
|
||||
LOG_WB << "End turn exception caught during execution, deleting action. " << *this << "\n";
|
||||
validate_actions();
|
||||
|
@ -178,11 +178,11 @@ bool side_actions::execute(side_actions::iterator position)
|
|||
|
||||
if(exec_result!=action::FAIL)
|
||||
{
|
||||
resources::whiteboard->queue_net_cmd(make_net_cmd_remove(position));
|
||||
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_remove(position));
|
||||
actions_.erase(position);
|
||||
}
|
||||
else //action may have revised itself; let's tell our allies.
|
||||
resources::whiteboard->queue_net_cmd(make_net_cmd_replace(position,*position));
|
||||
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_replace(position,*position));
|
||||
|
||||
switch(exec_result)
|
||||
{
|
||||
|
@ -270,7 +270,7 @@ side_actions::iterator side_actions::insert_action(iterator position, action_ptr
|
|||
ERR_WB << "Modifying action queue while temp modifiers are applied!!!\n";
|
||||
}
|
||||
assert(position >= begin() && position <= end());
|
||||
resources::whiteboard->queue_net_cmd(make_net_cmd_insert(position, action));
|
||||
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_insert(position, action));
|
||||
iterator valid_position = actions_.insert(position, action);
|
||||
LOG_WB << "Inserted at position #" << std::distance(begin(), valid_position) + 1
|
||||
<< " : " << action <<"\n";
|
||||
|
@ -359,7 +359,7 @@ side_actions::iterator side_actions::bump_earlier(side_actions::iterator positio
|
|||
<< " to position #" << action_number - 1 << "/" << last_position << ".\n";
|
||||
|
||||
action_ptr action = *position;
|
||||
resources::whiteboard->queue_net_cmd(make_net_cmd_bump_later(position-1));
|
||||
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_bump_later(position-1));
|
||||
action_queue::iterator after = actions_.erase(position);
|
||||
//be careful, previous iterators have just been invalidated by erase()
|
||||
action_queue::iterator destination = after - 1;
|
||||
|
@ -447,7 +447,7 @@ side_actions::iterator side_actions::bump_later(side_actions::iterator position)
|
|||
<< " to position #" << action_number + 1 << "/" << last_position << ".\n";
|
||||
|
||||
action_ptr action = *position;
|
||||
resources::whiteboard->queue_net_cmd(make_net_cmd_bump_later(position));
|
||||
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_bump_later(position));
|
||||
action_queue::iterator after = actions_.erase(position);
|
||||
//be careful, previous iterators have just been invalidated by erase()
|
||||
DBG_WB << "Action temp. removed, position after is #" << after - begin() + 1 << "/" << actions_.size() << ".\n";
|
||||
|
@ -474,7 +474,7 @@ side_actions::iterator side_actions::remove_action(side_actions::iterator positi
|
|||
{
|
||||
LOG_WB << "Erasing action at position #" << distance + 1 << "\n";
|
||||
|
||||
resources::whiteboard->queue_net_cmd(make_net_cmd_remove(position));
|
||||
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_remove(position));
|
||||
safe_erase(position);
|
||||
|
||||
if (validate_after_delete)
|
||||
|
|
|
@ -132,7 +132,8 @@ validate_visitor::VALIDITY validate_visitor::evaluate_move_validity(move_ptr m_p
|
|||
if(new_route.steps.empty() || new_route.move_cost >= pathfind::cost_calculator::getNoPathValue())
|
||||
return OBSTRUCTED; //no path exists
|
||||
|
||||
if(m.team_index() == viewer_team()) //< Don't mess with any other team's queue -- only our own
|
||||
size_t viewing_team = viewer_team();
|
||||
if(m.team_index() == viewing_team) //< Don't mess with any other team's queue -- only our own
|
||||
{
|
||||
if(new_route.steps != m.get_route().steps || new_route.move_cost != m.get_route().move_cost)
|
||||
{
|
||||
|
@ -140,7 +141,7 @@ validate_visitor::VALIDITY validate_visitor::evaluate_move_validity(move_ptr m_p
|
|||
m.set_route(new_route);
|
||||
|
||||
//send updated path to allies
|
||||
resources::whiteboard->queue_net_cmd(viewer_actions_.make_net_cmd_replace(arg_itor_,m_ptr));
|
||||
resources::whiteboard->queue_net_cmd(viewing_team,viewer_actions_.make_net_cmd_replace(arg_itor_,m_ptr));
|
||||
|
||||
//@todo: Since this might lengthen the path, we probably need a special conflict state
|
||||
// to warn the player that the initial path is no longer possible.
|
||||
|
|
Loading…
Add table
Reference in a new issue