an update :D

This commit is contained in:
Magnus Auvinen 2007-07-29 22:09:15 +00:00
parent 0dd86dd084
commit 8233a44b60
14 changed files with 65 additions and 15 deletions

Binary file not shown.

Binary file not shown.

View file

@ -601,6 +601,15 @@ void client::run(const char *direct_connect_server)
// panic button // panic button
if(input::pressed(input::lctrl) && input::pressed('Q')) if(input::pressed(input::lctrl) && input::pressed('Q'))
break; break;
if(input::pressed(input::f5))
{
// ack snapshot
msg_pack_start_system(NETMSG_SNAPACK, 0);
msg_pack_int(-1);
msg_pack_end();
client_send_msg();
}
// pump the network // pump the network
pump_network(); pump_network();
@ -794,7 +803,7 @@ void client::process_packet(NETPACKET *packet)
error("failure to load map"); error("failure to load map");
} }
} }
else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPSMALL || msg == NETMSG_SNAPEMPTY) else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPEMPTY) //|| msg == NETMSG_SNAPSMALL || msg == NETMSG_SNAPEMPTY)
{ {
//dbg_msg("client/network", "got snapshot"); //dbg_msg("client/network", "got snapshot");
int game_tick = msg_unpack_int(); int game_tick = msg_unpack_int();
@ -802,15 +811,19 @@ void client::process_packet(NETPACKET *packet)
int num_parts = 1; int num_parts = 1;
int part = 0; int part = 0;
int part_size = 0; int part_size = 0;
int crc = 0;
if(msg == NETMSG_SNAP) //if(msg == NETMSG_SNAP)
{ {
num_parts = msg_unpack_int(); //num_parts = msg_unpack_int();
part = msg_unpack_int(); //part = msg_unpack_int();
} }
if(msg != NETMSG_SNAPEMPTY) if(msg != NETMSG_SNAPEMPTY)
{
part_size = msg_unpack_int(); part_size = msg_unpack_int();
crc = msg_unpack_int();
}
if(snapshot_part == part) if(snapshot_part == part)
{ {
@ -831,6 +844,8 @@ void client::process_packet(NETPACKET *packet)
unsigned char tmpbuffer2[MAX_SNAPSHOT_SIZE]; unsigned char tmpbuffer2[MAX_SNAPSHOT_SIZE];
if(part_size) if(part_size)
{ {
if(msg == NETMSG_SNAPEMPTY)
dbg_msg("client", "FAILURE!");
int compsize = zerobit_decompress(snapshot_incomming_data, part_size, tmpbuffer); int compsize = zerobit_decompress(snapshot_incomming_data, part_size, tmpbuffer);
int intsize = intpack_decompress(tmpbuffer, compsize, tmpbuffer2); int intsize = intpack_decompress(tmpbuffer, compsize, tmpbuffer2);
deltadata = tmpbuffer2; deltadata = tmpbuffer2;
@ -857,6 +872,8 @@ void client::process_packet(NETPACKET *packet)
dbg_msg("client", "error, couldn't find the delta snapshot"); dbg_msg("client", "error, couldn't find the delta snapshot");
} }
} }
//dbg_msg("UNPACK", "%d unpacked with %d", game_tick, delta_tick);
unsigned char tmpbuffer3[MAX_SNAPSHOT_SIZE]; unsigned char tmpbuffer3[MAX_SNAPSHOT_SIZE];
int snapsize = snapshot_unpack_delta(deltashot, (snapshot*)tmpbuffer3, deltadata, deltasize); int snapsize = snapshot_unpack_delta(deltashot, (snapshot*)tmpbuffer3, deltadata, deltasize);
@ -873,6 +890,10 @@ void client::process_packet(NETPACKET *packet)
// add new // add new
snapshot_info *snap = client_snapshot_add(game_tick, time_get(), tmpbuffer3, snapsize); snapshot_info *snap = client_snapshot_add(game_tick, time_get(), tmpbuffer3, snapsize);
//int ncrc = snapshot_crc((snapshot*)tmpbuffer3);
//if(crc != ncrc)
//dbg_msg("client", "client snapshot crc failure %d %d", crc, ncrc);
// apply snapshot, cycle pointers // apply snapshot, cycle pointers
recived_snapshots++; recived_snapshots++;
@ -908,10 +929,13 @@ void client::process_packet(NETPACKET *packet)
snapshot_part = 0; snapshot_part = 0;
// ack snapshot // ack snapshot
msg_pack_start_system(NETMSG_SNAPACK, 0); //if((rand()%10)==0)
msg_pack_int(game_tick); {
msg_pack_end(); msg_pack_start_system(NETMSG_SNAPACK, 0);
client_send_msg(); msg_pack_int(game_tick);
msg_pack_end();
client_send_msg();
}
} }
} }
else else

View file

@ -175,7 +175,8 @@ bool gfx_init()
indecies[i*6 + 5] = i+2; indecies[i*6 + 5] = i+2;
}*/ }*/
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// create null texture, will get id=0 // create null texture, will get id=0
gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data); gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data);

View file

@ -164,10 +164,12 @@ public:
void *new_item(int type, int id, int size) void *new_item(int type, int id, int size)
{ {
snapshot::item *obj = (snapshot::item *)(data+data_size); snapshot::item *obj = (snapshot::item *)(data+data_size);
mem_zero(obj, sizeof(snapshot::item) + size);
obj->type_and_id = (type<<16)|id; obj->type_and_id = (type<<16)|id;
offsets[num_items] = data_size; offsets[num_items] = data_size;
data_size += sizeof(snapshot::item) + size; data_size += sizeof(snapshot::item) + size;
num_items++; num_items++;
dbg_assert(data_size < MAX_SNAPSHOT_SIZE, "too much data"); dbg_assert(data_size < MAX_SNAPSHOT_SIZE, "too much data");
dbg_assert(num_items < MAX_ITEMS, "too many items"); dbg_assert(num_items < MAX_ITEMS, "too many items");

View file

@ -300,10 +300,13 @@ public:
delta_tick = clients[i].last_acked_snapshot; delta_tick = clients[i].last_acked_snapshot;
deltashot = (snapshot *)delta_data; deltashot = (snapshot *)delta_data;
} }
else
dbg_msg("server", "no delta, sending full snapshot");
} }
// create delta // create delta
int deltasize = snapshot_create_delta(deltashot, (snapshot*)data, deltadata); int deltasize = snapshot_create_delta(deltashot, (snapshot*)data, deltadata);
//dbg_msg("PACK", "%d unpacked with %d", current_tick, delta_tick);
if(deltasize) if(deltasize)
{ {
@ -327,13 +330,14 @@ public:
int chunk = left < max_size ? left : max_size; int chunk = left < max_size ? left : max_size;
left -= chunk; left -= chunk;
if(numpackets == 1) //if(numpackets == 1)
msg_pack_start_system(NETMSG_SNAPSMALL, 0); // msg_pack_start_system(NETMSG_SNAPSMALL, 0);
else //else
msg_pack_start_system(NETMSG_SNAP, 0); msg_pack_start_system(NETMSG_SNAP, 0);
msg_pack_int(current_tick); msg_pack_int(current_tick);
msg_pack_int(current_tick-delta_tick); // compressed with msg_pack_int(current_tick-delta_tick); // compressed with
msg_pack_int(chunk); msg_pack_int(chunk);
msg_pack_int(snapshot_crc((snapshot*)data));
msg_pack_raw(&compdata[n*max_size], chunk); msg_pack_raw(&compdata[n*max_size], chunk);
msg_pack_end(); msg_pack_end();
//const msg_info *info = msg_get_info(); //const msg_info *info = msg_get_info();

View file

@ -27,6 +27,21 @@ void *snapshot_empty_delta()
return &empty; return &empty;
} }
int snapshot_crc(snapshot *snap)
{
int crc = 0;
for(int i = 0; i < snap->num_items; i++)
{
snapshot::item *item = snap->get_item(i);
int size = snap->get_item_datasize(i);
for(int b = 0; b < size/4; b++)
crc += item->data()[b];
}
return crc;
}
static int diff_item(int *past, int *current, int *out, int size) static int diff_item(int *past, int *current, int *out, int size)
{ {
/* /*

View file

@ -41,6 +41,7 @@ struct snapshot
}; };
void *snapshot_empty_delta(); void *snapshot_empty_delta();
int snapshot_crc(snapshot *snap);
int snapshot_create_delta(snapshot *from, snapshot *to, void *data); int snapshot_create_delta(snapshot *from, snapshot *to, void *data);
int snapshot_unpack_delta(snapshot *from, snapshot *to, void *data, int data_size); int snapshot_unpack_delta(snapshot *from, snapshot *to, void *data, int data_size);

View file

@ -46,7 +46,7 @@ void tilemap_render(float scale, int fg)
int endy = (int)(screen_y1/scale)+1; int endy = (int)(screen_y1/scale)+1;
int endx = (int)(screen_x1/scale)+1; int endx = (int)(screen_x1/scale)+1;
float frac = (1.0f/1024.0f);//2.0f; //2.0f; float frac = (1.25f/1024.0f);//2.0f; //2.0f;
float texsize = 1024.0f; float texsize = 1024.0f;
float nudge = 0.5f/texsize; float nudge = 0.5f/texsize;
for(int y = starty; y < endy; y++) for(int y = starty; y < endy; y++)

View file

@ -40,6 +40,9 @@ int run(int port, netaddr4 dest)
int bytes = socket.recv(&from, buffer, 1024*2); int bytes = socket.recv(&from, buffer, 1024*2);
if(bytes <= 0) if(bytes <= 0)
break; break;
if((rand()%10) == 0) // drop the packet
continue;
// create new packet // create new packet
packet *p = (packet *)mem_alloc(sizeof(packet)+bytes, 1); packet *p = (packet *)mem_alloc(sizeof(packet)+bytes, 1);

View file

@ -75,7 +75,7 @@ int main(int argc, char **argv)
tilemap_borderfix(w, h, buffer[0], buffer[1]); tilemap_borderfix(w, h, buffer[0], buffer[1]);
// save here // save here
png_open_file_write(&png, "output.png"); png_open_file_write(&png, argv[1]);
png_set_data(&png, w, h, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)buffer[1]); png_set_data(&png, w, h, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)buffer[1]);
png_close_file(&png); png_close_file(&png);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 21 KiB