… | |
… | |
17 | use base 'Crossfire::Protocol::Base'; |
17 | use base 'Crossfire::Protocol::Base'; |
18 | |
18 | |
19 | sub new { |
19 | sub new { |
20 | my $class = shift; |
20 | my $class = shift; |
21 | |
21 | |
22 | my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 }); |
22 | my $self = $class->SUPER::new (@_, |
|
|
23 | setup_req => { |
|
|
24 | extmap => 1, |
|
|
25 | smoothing => 1, |
|
|
26 | }, |
|
|
27 | ); |
23 | |
28 | |
24 | $self->{map_widget}->clr_commands; |
29 | $self->{map_widget}->clr_commands; |
25 | |
30 | |
26 | my @cmd_help = map { |
31 | my @cmd_help = map { |
27 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
32 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
… | |
… | |
402 | |
407 | |
403 | $self->{map}->clear; |
408 | $self->{map}->clear; |
404 | delete $self->{map_widget}{magicmap}; |
409 | delete $self->{map_widget}{magicmap}; |
405 | } |
410 | } |
406 | |
411 | |
|
|
412 | sub bg_fetch { |
|
|
413 | my ($self) = @_; |
|
|
414 | |
|
|
415 | my $id; |
|
|
416 | |
|
|
417 | do { |
|
|
418 | $id = pop @{$self->{bg_fetch}} |
|
|
419 | or return; |
|
|
420 | } while $self->{texture}[$id]; |
|
|
421 | |
|
|
422 | CFPlus::DB::get tilecache => $id, sub { |
|
|
423 | my ($data) = @_; |
|
|
424 | |
|
|
425 | return unless $self->{map}; # stop when destroyed |
|
|
426 | |
|
|
427 | $self->set_texture ($id => $data) |
|
|
428 | if defined $data; |
|
|
429 | |
|
|
430 | $self->bg_fetch; |
|
|
431 | }; |
|
|
432 | } |
407 | |
433 | |
408 | sub load_map($$$) { |
434 | sub load_map($$$) { |
409 | my ($self, $hash, $x, $y) = @_; |
435 | my ($self, $hash, $x, $y) = @_; |
410 | |
436 | |
411 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
437 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
412 | my ($data) = @_; |
438 | my ($data) = @_; |
413 | |
439 | |
414 | if (defined $data) { |
440 | if (defined $data) { |
415 | $data = Compress::LZF::decompress $data; |
441 | $data = Compress::LZF::decompress $data; |
416 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
442 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
417 | for my $id ($self->{map}->set_rect ($x, $y, $data)) { |
|
|
418 | CFPlus::DB::get tilecache => $id, sub { |
|
|
419 | my ($data) = @_; |
|
|
420 | |
443 | |
421 | $self->set_texture ($id => $data) |
444 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
422 | if defined $data; |
445 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
423 | }; |
446 | $self->bg_fetch unless $inprogress; |
424 | } |
|
|
425 | } |
447 | } |
426 | }; |
448 | }; |
427 | } |
449 | } |
428 | |
450 | |
429 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
451 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
… | |
… | |
568 | if $changed; |
590 | if $changed; |
569 | |
591 | |
570 | $self->set_texture ($face->{id} => delete $face->{image}); |
592 | $self->set_texture ($face->{id} => delete $face->{image}); |
571 | } |
593 | } |
572 | |
594 | |
|
|
595 | sub smooth_update { |
|
|
596 | my ($self, $facenum, $face) = @_; |
|
|
597 | |
|
|
598 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
|
|
599 | } |
|
|
600 | |
573 | sub set_texture { |
601 | sub set_texture { |
574 | my ($self, $id, $data) = @_; |
602 | my ($self, $id, $data) = @_; |
575 | |
603 | |
576 | $self->{texture}[$id] ||= do { |
604 | $self->{texture}[$id] = my $tex = |
577 | my $tex = |
|
|
578 | new_from_image CFPlus::Texture |
605 | new_from_image CFPlus::Texture |
579 | $data, minify => 1, mipmap => 1; |
606 | $data, minify => 1, mipmap => 1; |
580 | |
607 | |
581 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
608 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
582 | $self->{map_widget}->update; |
609 | $self->{map_widget}->update; |
583 | |
|
|
584 | $tex |
|
|
585 | }; |
|
|
586 | } |
610 | } |
587 | |
611 | |
588 | sub sound_play { |
612 | sub sound_play { |
589 | my ($self, $x, $y, $soundnum, $type) = @_; |
613 | my ($self, $x, $y, $soundnum, $type) = @_; |
590 | |
614 | |