ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra/Deliantra/Protocol.pm (file contents):
Revision 1.13 by root, Sat Apr 8 22:08:26 2006 UTC vs.
Revision 1.14 by root, Sun Apr 9 17:36:09 2006 UTC

80 $data =~ s/^(\S+)(?:\s|$)// 80 $data =~ s/^(\S+)(?:\s|$)//
81 or return; 81 or return;
82 82
83 my $command = "feed_$1"; 83 my $command = "feed_$1";
84 84
85# warn "$command\n";#d#]
85 $self->$command ($data); 86 $self->$command ($data);
86} 87}
87 88
88sub feed_version { 89sub feed_version {
89 my ($self, $version) = @_; 90 my ($self, $version) = @_;
115sub feed_addme_failure { 116sub feed_addme_failure {
116 my ($self, $data) = @_; 117 my ($self, $data) = @_;
117 # maybe should notify user 118 # maybe should notify user
118} 119}
119 120
121=back
122
123=head2 METHODS THAT CAN/MUST BE OVERWRITTEN
124
125=over 4
126
127=cut
128
129sub feed_face1 {
130 my ($self, $data) = @_;
131
132 my ($num, $chksum, $name) = unpack "nNa*", $data;
133
134 my $face = $self->{face}[$num] = { name => $name, chksum => $chksum };
135
136 if (my $data = $self->face_find ($face)) {
137 $face->{image} = $data;
138 $self->face_update ($face);
139 } else {
140 $self->send ("askface $num");
141 }
142}
143
144=item $conn->anim_update ($num) [OVERWRITE]
145
146=cut
147
148sub anim_update { }
149
150sub feed_anim {
151 my ($self, $data) = @_;
152
153 my ($num, @faces) = unpack "n*", $data;
154
155 $self->{anim}[$num] = \@faces;
156
157 $self->anim_update ($num);
158}
159
120=item $conn->play_sound ($x, $y, $soundnum, $type) [OVERWRITE] 160=item $conn->play_sound ($x, $y, $soundnum, $type)
121 161
122=cut 162=cut
123 163
124sub sound_play { } 164sub sound_play { }
125 165
127 my ($self, $data) = @_; 167 my ($self, $data) = @_;
128 168
129 $self->sound_play (unpack "CCnC", $data); 169 $self->sound_play (unpack "CCnC", $data);
130} 170}
131 171
132=item $conn->query ($flags, $prompt) [OVERWRITE] 172=item $conn->query ($flags, $prompt)
133 173
134=cut 174=cut
135 175
136sub query { die "query is abstract" } 176sub query { }
137 177
138sub feed_query { 178sub feed_query {
139 my ($self, $data) = @_; 179 my ($self, $data) = @_;
140 180
141 my ($flags, $prompt) = split /\s+/, $data, 2; 181 my ($flags, $prompt) = split /\s+/, $data, 2;
149 } else { 189 } else {
150 $self->query ($flags, $prompt); 190 $self->query ($flags, $prompt);
151 } 191 }
152} 192}
153 193
194=item $conn->drawinfo ($color, $text)
195
196=cut
197
198sub drawinfo { }
199
200sub feed_drawinfo {
201 my ($self, $data) = @_;
202
203 $self->drawinfo (split / /, $data, 2);
204}
205
154=item $conn->player_update ($player) [OVERWRITE] 206=item $conn->player_update ($player)
155 207
156tag, weight, face, name 208tag, weight, face, name
157 209
158=cut 210=cut
159 211
170 face => $face, 222 face => $face,
171 name => $name, 223 name => $name,
172 }); 224 });
173} 225}
174 226
175=item $conn->stats_update ($stats) [OVERWRITE] 227=item $conn->stats_update ($stats)
176 228
177=cut 229=cut
178 230
179sub stats_update { } 231sub stats_update { }
180 232
206 } 258 }
207 259
208 $self->stats_update ($self->{stat}); 260 $self->stats_update ($self->{stat});
209} 261}
210 262
211sub feed_face1 { 263=item $conn->inventory_clear ($id)
212 my ($self, $data) = @_;
213 264
214 my ($num, $chksum, $name) = unpack "nNa*", $data;
215
216 my $face = $self->{face}[$num] = { name => $name, chksum => $chksum };
217
218 if (my $data = $self->face_find ($face)) {
219 $face->{image} = $data;
220 $self->face_update ($face);
221 } else {
222 $self->send ("askface $num");
223 }
224}
225
226=item $conn->anim_update ($num) [OVERWRITE]
227
228=cut 265=cut
229 266
230sub anim_update { } 267sub inventory_clear { }
231
232sub feed_anim {
233 my ($self, $data) = @_;
234
235 my ($num, @faces) = unpack "n*", $data;
236
237 $self->{anim}[$num] = \@faces;
238
239 $self->anim_update ($num);
240}
241
242sub feed_drawinfo {
243 my ($self, $data) = @_;
244# warn "<$data>\n";
245}
246 268
247sub feed_delinv { 269sub feed_delinv {
248 my ($self, $data) = @_; 270 my ($self, $data) = @_;
271
272 $self->inventory_clear ($data);
273
274 delete $self->{inventory}[$data];
275}
276
277=item $conn->items_delete ($tag...)
278
279=cut
280
281sub items_delete { }
282
283sub feed_delitem {
284 my ($self, $data) = @_;
285
286 $self->items_delete (unpack "n*", $data);
287}
288
289=item $conn->inventory_add ($id, [\%item...])
290
291=cut
292
293sub inventory_add {
249} 294}
250 295
251sub feed_item2 { 296sub feed_item2 {
252 my ($self, $data) = @_; 297 my ($self, $data) = @_;
298
299 my ($location, @values) = unpack "N (NNNN C/a* nC Nn)*", $data;
300
301 my @items;
302
303 while (@values) {
304 my ($tag, $flags, $weight, $face, $names, $anim, $animspeed, $nrof, $type) =
305 splice @values, 0, 9, ();
306
307 my ($name, $name_pl) = split /\x000/, $names;
308
309 push @items, {
310 tag => $tag,
311 flags => $flags,
312 weight => $weight,
313 face => $face,
314 name => $name,
315 name_pl => $name_pl,
316 anim => $anim,
317 animspeed => $animspeed * 0.120, #???
318 nrof => $nrof,
319 type => $type,
320 };
321 }
322
323 $self->inventory_add ($location, \@items);
324}
325
326=item $conn->item_update ($tag)
327
328=cut
329
330sub item_update { }
331
332sub feed_upditem {
333 #todo
253} 334}
254 335
255sub feed_map1a { 336sub feed_map1a {
256 my ($self, $data) = @_; 337 my ($self, $data) = @_;
257 338
258 my $map = $self->{map} ||= []; 339 my $map = $self->{map} ||= [];
340
341 my ($dx, $dy) = delete @$self{qw(delayed_scroll_x delayed_scroll_y)};
342
343 if ($dx || $dy) {
344 my ($mx, $my, $mw, $mh) = @$self{qw(mapx mapy mapw maph)};
345
346 # TODO: optimise this a lot, or maybe just do it on c-level
347 # set flag to -1 for spaces we scroll out
348 {
349 my @darkness;
350
351 if ($dx > 0) {
352 push @darkness, [$mx, $my, $dx - 1, $mh];
353 } elsif ($dx < 0) {
354 push @darkness, [$mx + $mw + $dx + 1, $my, 1 - $dx, $mh];
355 }
356
357 if ($dy > 0) {
358 push @darkness, [$mx, $my, $mw, $dy - 1];
359 } elsif ($dy < 0) {
360 push @darkness, [$mx, $my + $mh + $dy + 1, $mw, 1 - $dy];
361 }
362
363 for (@darkness) {
364 my ($x0, $y0, $w, $h) = @$_;
365 for my $x ($x0 .. $x0 + $w) {
366 for my $y ($y0 .. $y0 + $h) {
367
368 my $cell = $map->[$x][$y]
369 or next;
370
371 $cell->[0] = -1;
372 }
373 }
374 }
375 }
376
377 # now scroll
378
379 $self->{mapx} += $dx;
380 $self->{mapy} += $dy;
381
382 # shift in new space if moving to "negative indices"
383 if ($self->{mapy} < 0) {
384 unshift @$_, ([]) x -$self->{mapy} for @$map;
385 $self->{mapy} = 0;
386 }
387
388 if ($self->{mapx} < 0) {
389 unshift @$map, ([]) x -$self->{mapx};
390 $self->{mapx} = 0;
391 }
392
393 $self->map_scroll ($dx, $dy);
394 }
259 395
260 my @dirty; 396 my @dirty;
261 my ($coord, $x, $y, $darkness, $fa, $fb, $fc, $cell); 397 my ($coord, $x, $y, $darkness, $fa, $fb, $fc, $cell);
262 398
263 while (length $data) { 399 while (length $data) {
267 $y = (($coord >> 4) & 63) + $self->{mapy}; 403 $y = (($coord >> 4) & 63) + $self->{mapy};
268 404
269 $cell = $map->[$x][$y] ||= []; 405 $cell = $map->[$x][$y] ||= [];
270 406
271 if ($coord & 15) { 407 if ($coord & 15) {
408 @$cell = () if $cell->[0] < 0;
409
272 $cell->[0] = $coord & 8 410 $cell->[0] = $coord & 8
273 ? unpack "C", substr $data, 0, 1, "" 411 ? unpack "C", substr $data, 0, 1, ""
274 : 255; 412 : 255;
275 413
276 $cell->[1] = unpack "n", substr $data, 0, 2, "" 414 $cell->[1] = unpack "n", substr $data, 0, 2, ""
279 if $coord & 2; 417 if $coord & 2;
280 $cell->[3] = unpack "n", substr $data, 0, 2, "" 418 $cell->[3] = unpack "n", substr $data, 0, 2, ""
281 if $coord & 1; 419 if $coord & 1;
282 } else { 420 } else {
283 $cell->[0] = -1; 421 $cell->[0] = -1;
284 $cell->[2] = undef;
285 $cell->[3] = undef;
286 } 422 }
287 423
288 push @dirty, [$x, $y]; 424 push @dirty, [$x, $y];
289 } 425 }
290 426
294sub feed_map_scroll { 430sub feed_map_scroll {
295 my ($self, $data) = @_; 431 my ($self, $data) = @_;
296 432
297 my ($dx, $dy) = split / /, $data; 433 my ($dx, $dy) = split / /, $data;
298 434
299 my $map = $self->{map} ||= []; 435 $self->{delayed_scroll_x} += $dx;
300 436 $self->{delayed_scroll_y} += $dy;
301 my ($mx, $my, $mw, $mh) = @$self{qw(mapx mapy mapw maph)};
302
303 # TODO: optimise this a lot, or maybe just do it on c-level
304 # set flag to -1 for spaces we scroll out
305 {
306 my @darkness;
307
308 if ($dx > 0) {
309 push @darkness, [$mx, $my, $dx - 1, $mh];
310 } elsif ($dx < 0) {
311 push @darkness, [$mx + $mw + $dx + 1, $my, 1 - $dx, $mh];
312 }
313
314 if ($dy > 0) {
315 push @darkness, [$mx, $my, $mw, $dy - 1];
316 } elsif ($dy < 0) {
317 push @darkness, [$mx, $my + $mh + $dy + 1, $mw, 1 - $dy];
318 }
319
320 for (@darkness) {
321 my ($x0, $y0, $w, $h) = @$_;
322 for my $x ($x0 .. $x0 + $w) {
323 for my $y ($y0 .. $y0 + $h) {
324
325 my $cell = $map->[$x][$y]
326 or next;
327
328 $cell->[0] = -1; $cell->[2] = 0; $cell->[3] = 0;
329 }
330 }
331 }
332 }
333
334 # now scroll
335
336 $self->{mapx} += $dx;
337 $self->{mapy} += $dy;
338
339 # shift in new space if moving to "negative indices"
340 if ($self->{mapy} < 0) {
341 unshift @$_, ([]) x -$self->{mapy} for @$map;
342 $self->{mapy} = 0;
343 }
344
345 if ($self->{mapx} < 0) {
346 unshift @$map, ([]) x -$self->{mapx};
347 $self->{mapx} = 0;
348 }
349
350 $self->map_scroll ($dx, $dy);
351} 437}
352 438
353sub feed_newmap { 439sub feed_newmap {
354 my ($self) = @_; 440 my ($self) = @_;
355 441
356 $self->{map} = []; 442 $self->{map} = [];
357 $self->{mapx} = 0; 443 $self->{mapx} = 0;
358 $self->{mapy} = 0; 444 $self->{mapy} = 0;
445
446 delete $self->{delayed_scroll_x};
447 delete $self->{delayed_scroll_y};
359 448
360 $self->map_clear; 449 $self->map_clear;
361} 450}
362 451
363sub feed_image { 452sub feed_image {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines