fixes to networking problems.

cut down on bandwidth usage by out-of-sync diagnostics
This commit is contained in:
Dave White 2004-04-06 19:17:17 +00:00
parent c5f7209712
commit 33eebb5837
5 changed files with 33 additions and 12 deletions

View File

@ -1189,6 +1189,10 @@ void display::draw_unit_on_tile(int x, int y, SDL_Surface* unit_image_override,
sprintf(buf,"misc/ellipse-%d-top.png",it->second.side()); sprintf(buf,"misc/ellipse-%d-top.png",it->second.side());
const scoped_sdl_surface surf(image::get_image(buf)); const scoped_sdl_surface surf(image::get_image(buf));
if(surf == NULL) {
std::cerr << "could not open ellipse: '" << buf << "'\n";
}
if(surf != NULL) { if(surf != NULL) {
SDL_Surface* const dst = screen_.getSurface(); SDL_Surface* const dst = screen_.getSurface();
SDL_Rect rect = {xpos,ypos - height_adjust,surf->w,surf->h}; SDL_Rect rect = {xpos,ypos - height_adjust,surf->w,surf->h};

View File

@ -16,7 +16,14 @@ SDLNet_SocketSet socket_set = 0;
typedef std::vector<network::connection> sockets_list; typedef std::vector<network::connection> sockets_list;
sockets_list sockets; sockets_list sockets;
std::map<network::connection,compression_schema> schemas; struct schema_pair
{
compression_schema incoming, outgoing;
};
typedef std::map<network::connection,schema_pair> schema_map;
schema_map schemas;
struct partial_buffer { struct partial_buffer {
partial_buffer() : upto(0) {} partial_buffer() : upto(0) {}
@ -129,7 +136,7 @@ connection connect(const std::string& host, int port)
assert(sock != server_socket); assert(sock != server_socket);
sockets.push_back(sock); sockets.push_back(sock);
schemas.insert(std::pair<network::connection,compression_schema>(sock,compression_schema())); schemas.insert(std::pair<network::connection,schema_pair>(sock,schema_pair()));
} }
return sock; return sock;
@ -150,7 +157,7 @@ connection accept_connection()
assert(sock != server_socket); assert(sock != server_socket);
sockets.push_back(sock); sockets.push_back(sock);
schemas.insert(std::pair<network::connection,compression_schema>(sock,compression_schema())); schemas.insert(std::pair<network::connection,schema_pair>(sock,schema_pair()));
} }
return sock; return sock;
@ -268,10 +275,10 @@ connection receive_data(config& cfg, connection connection_num, int timeout)
throw network::error("sanity check on incoming data failed",*i); throw network::error("sanity check on incoming data failed",*i);
} }
const std::map<network::connection,compression_schema>::iterator schema = schemas.find(*i); const schema_map::iterator schema = schemas.find(*i);
assert(schema != schemas.end()); assert(schema != schemas.end());
cfg.read_compressed(buffer,schema->second); cfg.read_compressed(buffer,schema->second.incoming);
return *i; return *i;
} }
} }
@ -321,11 +328,11 @@ void send_data(const config& cfg, connection connection_num, size_t max_size)
assert(connection_num != server_socket); assert(connection_num != server_socket);
const std::map<network::connection,compression_schema>::iterator schema = schemas.find(connection_num); const schema_map::iterator schema = schemas.find(connection_num);
assert(schema != schemas.end()); assert(schema != schemas.end());
std::string value(4,'x'); std::string value(4,'x');
value += cfg.write_compressed(schema->second); value += cfg.write_compressed(schema->second.outgoing);
char buf[4]; char buf[4];
SDLNet_Write32(value.size()+1-4,buf); SDLNet_Write32(value.size()+1-4,buf);

View File

@ -2029,7 +2029,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
//throw e; //throw e;
} }
recorder.add_config(*cfg.child("turn")); recorder.add_config(*cfg.child("turn"),replay::MARK_AS_SENT);
} }
return turn_end ? PROCESS_END_TURN : PROCESS_CONTINUE; return turn_end ? PROCESS_END_TURN : PROCESS_CONTINUE;

View File

@ -105,7 +105,13 @@ namespace {
for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) { for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
config u; config u;
i->first.write(u); i->first.write(u);
i->second.write(u);
static const std::string fields[] = {"type","hitpoints","experience","side",""};
config tmp;
i->second.write(tmp);
for(const std::string* f = fields; f->empty() == false; ++f) {
u[*f] = tmp[*f];
}
res.add_child("unit",u); res.add_child("unit",u);
} }
@ -501,11 +507,14 @@ bool replay::empty()
return commands().empty(); return commands().empty();
} }
void replay::add_config(const config& cfg) void replay::add_config(const config& cfg, MARK_SENT mark)
{ {
for(config::const_child_itors i = cfg.child_range("command"); for(config::const_child_itors i = cfg.child_range("command");
i.first != i.second; ++i.first) { i.first != i.second; ++i.first) {
cfg_.add_child("command",**i.first); config& cfg = cfg_.add_child("command",**i.first);
if(mark == MARK_AS_SENT) {
cfg["sent"] = "yes";
}
} }
} }

View File

@ -83,7 +83,8 @@ public:
void clear(); void clear();
bool empty(); bool empty();
void add_config(const config& cfg); enum MARK_SENT { MARK_AS_UNSENT, MARK_AS_SENT };
void add_config(const config& cfg, MARK_SENT mark=MARK_AS_UNSENT);
int ncommands(); int ncommands();