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,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
10 | * |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
15 | * |
15 | * |
16 | * You should have received a copy of the Affero GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
17 | * and the GNU General Public License along with this program. If not, see |
17 | * and the GNU General Public License along with this program. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
18 | * <http://www.gnu.org/licenses/>. |
19 | * |
19 | * |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | */ |
21 | */ |
22 | |
22 | |
23 | /** |
23 | /** |
24 | * \file |
24 | * \file |
… | |
… | |
113 | } |
113 | } |
114 | |
114 | |
115 | void |
115 | void |
116 | client::tick () |
116 | client::tick () |
117 | { |
117 | { |
118 | if (!pl || destroyed ()) |
118 | if (destroyed ()) |
119 | return; |
119 | return; |
120 | |
120 | |
|
|
121 | if (pl) |
|
|
122 | { |
121 | pl->dirty = true; |
123 | pl->dirty = true; |
122 | |
124 | |
123 | /* Update the players stats once per tick. More efficient than |
125 | /* Update the players stats once per tick. More efficient than |
124 | * sending them whenever they change, and probably just as useful |
126 | * sending them whenever they change, and probably just as useful |
125 | */ |
127 | */ |
126 | pl->need_updated_stats (); |
128 | pl->need_updated_stats (); |
127 | esrv_update_stats (pl); |
129 | esrv_update_stats (pl); |
128 | |
130 | |
129 | if (pl->ns->update_spells) |
131 | if (pl->ns->update_spells) |
130 | esrv_update_spells (pl); |
132 | esrv_update_spells (pl); |
131 | |
133 | |
132 | sint32 weight = pl->ob->client_weight (); |
134 | sint32 weight = pl->ob->client_weight (); |
133 | |
135 | |
134 | if (last_weight != weight) |
136 | if (last_weight != weight) |
135 | { |
137 | { |
136 | pl->ob->update_stats (); |
138 | pl->ob->update_stats (); |
137 | esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); |
139 | esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); |
138 | } |
140 | } |
139 | |
141 | |
140 | draw_client_map (pl); |
142 | draw_client_map (pl); |
141 | |
143 | |
142 | if (update_look) |
144 | if (update_look) |
143 | esrv_draw_look (pl); |
145 | esrv_draw_look (pl); |
144 | |
146 | |
145 | mapinfo_queue_run (); |
147 | mapinfo_queue_run (); |
|
|
148 | } |
146 | |
149 | |
147 | #if HAVE_TCP_INFO |
150 | #if HAVE_TCP_INFO |
148 | // check time of last ack, and, if too old, kill connection |
151 | // check time of last ack, and, if too old, kill connection |
149 | socklen_t len = sizeof (tcpi); |
152 | socklen_t len = sizeof (tcpi); |
150 | |
153 | |
… | |
… | |
224 | if (avail <= 0) |
227 | if (avail <= 0) |
225 | break; |
228 | break; |
226 | |
229 | |
227 | ixsend &ix = ixface.back (); |
230 | ixsend &ix = ixface.back (); |
228 | |
231 | |
229 | if (facedata *d = face_data (ix.idx, faceset)) |
|
|
230 | { |
|
|
231 | // estimate the packet header overhead "ix " + idx + (new)ofs |
232 | // estimate the packet header overhead "ix " + idx + (new)ofs |
232 | int pktlen = 3 + ber32::encoded_size (ix.idx) + ber32::encoded_size (ix.ofs); |
233 | int pktlen = 3 + ber32::encoded_size (ix.idx) + ber32::encoded_size (ix.ofs); |
233 | int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen; |
234 | int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen; |
234 | |
235 | |
235 | // only transfer something if the amount of data transferred |
236 | // only transfer something if the amount of data transferred |
236 | // has a healthy relation to the header overhead |
237 | // has a healthy relation to the header overhead |
237 | if (chunk < 64) |
238 | if (chunk < 64) |
238 | break; |
239 | break; |
239 | |
240 | |
240 | chunk = min (chunk, (int)ix.ofs); |
241 | chunk = min (chunk, (int)ix.ofs); |
241 | |
242 | |
242 | ix.ofs -= chunk; |
243 | ix.ofs -= chunk; |
243 | |
244 | |
244 | //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D |
245 | //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D |
245 | |
246 | |
246 | packet sl ("ix"); |
247 | packet sl ("ix"); |
247 | |
248 | |
248 | sl << ber32 (ix.idx) |
249 | sl << ber32 (ix.idx) |
249 | << ber32 (ix.ofs) |
250 | << ber32 (ix.ofs) |
250 | << data (d->data + ix.ofs, chunk); |
251 | << data (ix.data.data + ix.ofs, chunk); |
251 | |
252 | |
252 | send_packet (sl); |
253 | send_packet (sl); |
253 | } |
|
|
254 | else |
|
|
255 | ix.ofs = 0; |
|
|
256 | |
254 | |
257 | if (!ix.ofs) |
255 | if (!ix.ofs) |
258 | { |
256 | { |
259 | ixface.pop_back (); |
257 | ixface.pop_back (); |
260 | |
258 | |