ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/loop.C
(Generate patch)

Comparing deliantra/server/socket/loop.C (file contents):
Revision 1.70 by root, Thu Nov 8 19:43:30 2007 UTC vs.
Revision 1.78 by root, Sat Dec 27 01:25:00 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002-2003,2007 Mark Wedel & The Crossfire Development Team 5 * Copyright (©) 2002-2003,2007 Mark Wedel & The Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
50 50
51#define MAX_QUEUE_DEPTH 50 51#define MAX_QUEUE_DEPTH 50
52#define MAX_QUEUE_BACKLOG 3. 52#define MAX_QUEUE_BACKLOG 3.
53 53
54// disconnect a socket after this many seconds without an ack 54// disconnect a socket after this many seconds without an ack
55#define SOCKET_TIMEOUT 8. 55#define SOCKET_TIMEOUT 16.
56 56
57void 57void
58client::reset_state () 58client::reset_state ()
59{ 59{
60 if (!pl) 60 if (!pl)
75 reset_state (); 75 reset_state ();
76 send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); 76 send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED);
77 } 77 }
78 else 78 else
79 { 79 {
80 cmd_queue.push_back (command ()); 80 cmd_queue.resize (cmd_queue.size () + 1);
81 command &cmd = cmd_queue.back (); 81 command &cmd = cmd_queue.back ();
82 cmd.stamp = stamp; 82 cmd.stamp = stamp;
83 cmd.handler = handler; 83 cmd.handler = handler;
84 cmd.data = salloc<char> (datalen + 1, data); 84 cmd.data = salloc<char> (datalen + 1, data);
85 cmd.datalen = datalen; 85 cmd.datalen = datalen;
101 send_packet_printf ("drawinfo %d ignoring delayed commands.", NDI_RED); 101 send_packet_printf ("drawinfo %d ignoring delayed commands.", NDI_RED);
102 } 102 }
103 else 103 else
104 execute (cmd.handler, cmd.data, cmd.datalen); 104 execute (cmd.handler, cmd.data, cmd.datalen);
105 105
106 sfree<char> (cmd.data, cmd.datalen + 1);
106 cmd_queue.pop_front (); 107 cmd_queue.pop_front ();
107 return true; 108 return true;
108 } 109 }
109 else 110 else
110 return false; 111 return false;
113void 114void
114client::tick () 115client::tick ()
115{ 116{
116 if (!pl || destroyed ()) 117 if (!pl || destroyed ())
117 return; 118 return;
119
120 pl->dirty = true;
118 121
119 /* Update the players stats once per tick. More efficient than 122 /* Update the players stats once per tick. More efficient than
120 * sending them whenever they change, and probably just as useful 123 * sending them whenever they change, and probably just as useful
121 */ 124 */
122 esrv_update_stats (pl); 125 esrv_update_stats (pl);
123 126
124 if (last_weight != -1 && last_weight != WEIGHT (pl->ob)) 127 sint32 weight = pl->ob->client_weight ();
128
129 if (last_weight != weight)
125 { 130 {
131 pl->ob->update_stats ();
126 esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); 132 esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob);
127 if (last_weight != WEIGHT (pl->ob))
128 LOG (llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n",
129 (unsigned long) last_weight, WEIGHT (pl->ob));
130 } 133 }
131 134
132 draw_client_map (pl); 135 draw_client_map (pl);
133 136
134 if (update_look) 137 if (update_look)
179#if HAVE_TCP_INFO 182#if HAVE_TCP_INFO
180 // further restrict the available bandwidth by the excess bandwidth available 183 // further restrict the available bandwidth by the excess bandwidth available
181 max_send = min (max_send, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss); 184 max_send = min (max_send, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss);
182#endif 185#endif
183 186
184 // if we can split images, round to next-lowest mss 187 // round to next-lowest mss
185 if (fxix) max_send -= max_send % mss; 188 max_send -= max_send % mss;
186 189
187 if (ixface.empty ()) 190 if (ixface.empty ())
188 { 191 {
189 // regularly send a new face when queue is empty 192 // regularly send a new face when queue is empty
190 if (bg_scrub && !--bg_scrub && enable_bg_scrub) 193 if (bg_scrub && !--bg_scrub)
191 while (scrub_idx < faces.size () - 1) 194 while (scrub_idx < faces.size () - 1)
192 { 195 {
193 ++scrub_idx; 196 ++scrub_idx;
194 197
195 if (!faces_sent [scrub_idx]) 198 if (!faces_sent [scrub_idx])
217 220
218 ixsend &ix = ixface.back (); 221 ixsend &ix = ixface.back ();
219 222
220 if (facedata *d = face_data (ix.idx, faceset)) 223 if (facedata *d = face_data (ix.idx, faceset))
221 { 224 {
222 if (fxix)
223 {
224 // estimate the packet header overhead "ix " + idx + (new)ofs 225 // estimate the packet header overhead "ix " + idx + (new)ofs
225 int pktlen = 3 + ber32::encoded_size (ix.idx) + ber32::encoded_size (ix.ofs); 226 int pktlen = 3 + ber32::encoded_size (ix.idx) + ber32::encoded_size (ix.ofs);
226 int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen; 227 int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen;
227 228
228 // only transfer something if the amount of data transferred 229 // only transfer something if the amount of data transferred
229 // has a healthy relation to the header overhead 230 // has a healthy relation to the header overhead
230 if (chunk < 64) 231 if (chunk < 64)
231 break; 232 break;
232 233
233 chunk = min (chunk, (int)ix.ofs); 234 chunk = min (chunk, (int)ix.ofs);
234 235
235 ix.ofs -= chunk; 236 ix.ofs -= chunk;
236 237
237 //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D 238 //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D
238 239
239 packet sl ("ix"); 240 packet sl ("ix");
240 241
241 sl << ber32 (ix.idx) 242 sl << ber32 (ix.idx)
242 << ber32 (ix.ofs) 243 << ber32 (ix.ofs)
243 << data (d->data.data () + ix.ofs, chunk); 244 << data (d->data.data () + ix.ofs, chunk);
244 245
245 send_packet (sl); 246 send_packet (sl);
246 }
247 else
248 {
249 send_image (ix.idx);
250 ix.ofs = 0;
251 }
252 } 247 }
253 else 248 else
254 ix.ofs = 0; 249 ix.ofs = 0;
255 250
256 if (!ix.ofs) 251 if (!ix.ofs)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines