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

Comparing deliantra/server/socket/image.C (file contents):
Revision 1.67 by root, Tue Jan 3 11:25:37 2012 UTC vs.
Revision 1.78 by root, Sun Nov 18 00:37:11 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001 Mark Wedel 6 * Copyright (©) 2001 Mark Wedel
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 10 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25/** \file 26/*
26 * Image related communication 27 * Image related communication
27 *
28 * \date 2003-12-02
29 * 28 *
30 * This file deals with the image related communication to the 29 * This file deals with the image related communication to the
31 * client. I've located all the functions in this file - this 30 * client. I've located all the functions in this file - this
32 * localizes it more, and means that we don't need to declare 31 * localizes it more, and means that we don't need to declare
33 * things like all the structures as globals. 32 * things like all the structures as globals.
51 50
52 sscanf (buf, "%d %d", &idx, &pri); 51 sscanf (buf, "%d %d", &idx, &pri);
53 52
54 //TODO: somehow fetch default priority from send_fx here 53 //TODO: somehow fetch default priority from send_fx here
55 54
56 const facedata *d = face_data (idx, ns->faceset); 55 const faceinfo *f = face_info (idx);
57 56
58 if (!d) 57 if (!f)
59 return; // doh 58 return; // doh
60 59
60 int set = ns->tileset;
61
62 if (!f->face [set].chksum_len)
63 set = 0;
64
65 /* cfperl_ix calls cf::face::ix which loads the data */
66 /* and then calls cf::client::send_ix to actually queue the ix */
67 cfperl_ix (ns, set, idx, pri);
68}
69
70void
71client::ix_send (faceidx idx, sint16 pri, SV *data_sv)
72{
73 STRLEN size;
74 char *data = SvPVbyte (data_sv, size);
61 client::ixsend ix; 75 ixsend ix;
62 76
63 ix.pri = pri; 77 ix.pri = pri;
64 ix.idx = idx; 78 ix.idx = idx;
65 ix.ofs = d->data.size (); 79 ix.ofs = size;
80 ix.data = (uint8 *)data;
81 ix.data_sv = SvREFCNT_inc (data_sv);
66 82
67 auto (pos, ns->ixface.end ()); 83 auto (pos, ixface.end ());
68 84
69 // the by far most common case will be to insert 85 // the by far most common case will be to insert
70 // near the end, so little looping. 86 // near the end, so little looping.
71 while (pos != ns->ixface.begin ()) 87 while (pos != ixface.begin ())
72 { 88 {
73 --pos; 89 --pos;
74 90
75 // sort within 2k bins, to slightly prefer smaller images 91 // sort within 2k bins, to slightly prefer smaller images
76 if (pri > pos->pri || (pri == pos->pri && (ix.ofs >> 11) <= (pos->ofs >> 11))) 92 if (pri > pos->pri || (pri == pos->pri && (ix.ofs >> 11) <= (pos->ofs >> 11)))
78 ++pos; 94 ++pos;
79 break; 95 break;
80 } 96 }
81 } 97 }
82 98
83 ns->ixface.insert (pos, ix); 99 ixface.insert (pos, ix);
84 100
85#if 0 101#if 0
86 for (auto (i, ns->ixface.begin ()); i != ns->ixface.end (); ++i) 102 for (auto &&i : ixface)
87 fprintf (stderr, "<%d,%d> ", i->pri, i->ofs); 103 fprintf (stderr, "<%d,%d> ", i.pri, i.ofs);
88 fprintf (stderr, "\n"); 104 fprintf (stderr, "\n");
89#endif 105#endif
90} 106}
91 107
108void
109client::ix_pop ()
110{
111 ixsend &ix = ixface.back ();
112
113 SvREFCNT_dec (ix.data_sv);
114
115 ixface.pop_back ();
116}
117
92/** 118/**
93 * Sends a face to a client if they are in pixmap mode 119 * Sends a face offer (fx) to a client.
94 * nothing gets sent in bitmap mode.
95 * If nocache is true (nonzero), ignore the cache setting from the client - 120 * If nocache is true (nonzero), ignore the cache setting from the client -
96 * this is needed for the askface, in which we really do want to send the 121 * this is needed for the askface, in which we really do want to send the
97 * face (and askface is the only place that should be setting it). Otherwise, 122 * face (and askface is the only place that should be setting it). Otherwise,
98 * we look at the facecache, and if set, send the image name. 123 * we look at the facecache, and if set, send the image name.
99 */ 124 */
110 { 135 {
111 LOG (llevError | logBacktrace, "client::send_face (%d) out of bounds??\n", facenum); 136 LOG (llevError | logBacktrace, "client::send_face (%d) out of bounds??\n", facenum);
112 return; 137 return;
113 } 138 }
114 139
115 // refuse to send non-image faces 140 // refuse to send non-image faces unless requested
116 if (!fx_want [f->type]) 141 if (!fx_want [f->type])
117 return; 142 return;
118 143
119 if (faces_sent [facenum]) 144 if (faces_sent [facenum])
120 return; 145 return;
121 146
122 faces_sent[facenum] = true; 147 faces_sent [facenum] = true;
123 148
124 fxface.push_back (facenum); 149 fxface.push_back (facenum);
125} 150}
126 151
127void client::flush_fx () 152void client::flush_fx ()
144 169
145 fx << ber32 (0) 170 fx << ber32 (0)
146 << uint8 (1) << uint8 (type); 171 << uint8 (1) << uint8 (type);
147 } 172 }
148 173
149 const facedata *d = f->data (faceset); 174 const facedata *d = f->data (tileset);
150 175
151 fx << ber32 (facenum) 176 fx << ber32 (facenum)
152 << data8 (d->chksum, d->chksum_len); 177 << data8 (d->chksum, d->chksum_len);
153 178
154 if (smoothing) 179 if (smoothing)
233} 258}
234 259
235void 260void
236client::invalidate_face (faceidx idx) 261client::invalidate_face (faceidx idx)
237{ 262{
263 if (!faces_sent [idx])
264 return;
265
238 faces_sent [idx] = false; 266 faces_sent [idx] = false;
239 force_newmap = true; 267 send_face (idx);
268 //TODO: check for active ix and abort it.
240} 269}
241 270
242void 271void
243client::invalidate_all_faces () 272client::invalidate_all_faces ()
244{ 273{
245 faces_sent.reset (); 274 for (faceidx i = 0; i < faces_sent.size (); ++i)
246 force_newmap = true; 275 invalidate_face (i);
247} 276}
248 277

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines