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

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.155 by root, Fri Aug 17 21:18:01 2007 UTC vs.
Revision 1.158 by root, Tue Aug 21 11:23:04 2007 UTC

58 $self->connect_ext (capabilities => sub { 58 $self->connect_ext (capabilities => sub {
59 my (%cap) = @_; 59 my (%cap) = @_;
60 60
61 #$self->send ("setup sound 0"); # we use a different protocol 61 #$self->send ("setup sound 0"); # we use a different protocol
62 $self->update_fx_want; 62 $self->update_fx_want;
63
64 $self->send_exti_req (resource => "exp_table", sub {
65 my ($exp_table) = @_;
66
67 $self->register_face_handler ($exp_table, sub {
68 my ($face) = @_;
69
70 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
71 $_->() for values %{ $self->{on_exp_update} || {} };
72 });
73
74 ()
75 });
63 76
64 if (my $ts = $cap{tileset}) { 77 if (my $ts = $cap{tileset}) {
65 if (my ($default) = grep $_->[2] & 1, @$ts) { 78 if (my ($default) = grep $_->[2] & 1, @$ts) {
66 $self->{tileset} = $default; 79 $self->{tileset} = $default;
67 $self->{tilesize} = $default->[3]; 80 $self->{tilesize} = $default->[3];
161 statusbox => $::SDTATUSBOX, 174 statusbox => $::SDTATUSBOX,
162 175
163 inv => $::INV, 176 inv => $::INV,
164 invr => $::INVR, 177 invr => $::INVR,
165 invr_hb => $::INVR_HB, 178 invr_hb => $::INVR_HB,
166
167 ); 179 );
168 180
169 while (my ($id, $name) = each %ass) { 181 while (my ($id, $name) = each %ass) {
170 $self->widget_associate (undef, $id => $wkw{$name}) 182 $self->widget_associate (undef, $id => $wkw{$name})
171 or warn "server failed to associate non-existent well-known widget $name\n"; 183 or warn "server failed to associate non-existent well-known widget $name\n";
284 my ($self) = @_; 296 my ($self) = @_;
285 297
286 $self->send_exti_msg (fx_want => { 298 $self->send_exti_msg (fx_want => {
287 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 299 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
288 5 => !!$::CFG->{audio_enable}, # FT_SOUND 300 5 => !!$::CFG->{audio_enable}, # FT_SOUND
301 6 => 1, # FT_RSRC
289 }); 302 });
290} 303}
291 304
292sub logprint { 305sub logprint {
293 my ($self, @a) = @_; 306 my ($self, @a) = @_;
433 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 446 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
434 $::GAUGES->{food} ->set_value ($fo, $fo_m); 447 $::GAUGES->{food} ->set_value ($fo, $fo_m);
435 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 448 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
436 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 449 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))
437 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 450 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
451 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
438 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 452 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
439 my $title = $stats->{+CS_STAT_TITLE}; 453 my $title = $stats->{+CS_STAT_TITLE};
440 $title =~ s/^Player: //; 454 $title =~ s/^Player: //;
441 $::STATWIDS->{title} ->set_text ("Title: " . $title); 455 $::STATWIDS->{title} ->set_text ("Title: " . $title);
442 456
463 my @skills = keys %{ $self->{skill_info} }; 477 my @skills = keys %{ $self->{skill_info} };
464 478
465 if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { 479 if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) {
466 $sktbl->clear; 480 $sktbl->clear;
467 481
468 my @add; 482 my $sw = $self->{skillwid}{""} ||= [
469
470 push @add,
471 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 483 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
472 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 484 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
485 2, 0, (new CFPlus::UI::Label text => "Progress", align => 0),
473 2, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 486 3, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
474 3, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 487 4, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
475 4, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 488 5, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
489 6, 0, (new CFPlus::UI::Label text => "Progress", align => 0),
476 5, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 490 7, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
477 ; 491 ];
492
493 my @add = @$sw;
478 494
479 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 495 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>";
480 496
481 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 497 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
482 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 498 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
510 } 526 }
511 527
512 1 528 1
513 }; 529 };
514 530
531 my $sw = $self->{skillwid}{$idx} ||= [
532 # exp
533 (new CFPlus::UI::Label
534 align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP),
535
536 # level
537 (new CFPlus::UI::Label
538 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL),
539
540 # progress
541 (new CFPlus::UI::ExperienceProgress),
542
543 # label
544 (new CFPlus::UI::Label text => $name, on_button_down => $spell_cb,
545 can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL),
546 ];
547
515 push @add, 548 push @add,
516 $x * 3 + 0, $y, ($self->{stat_widget_exp}{$idx} = new CFPlus::UI::Label 549 $x * 4 + 0, $y, $sw->[0],
517 align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP), 550 $x * 4 + 1, $y, $sw->[1],
518 $x * 3 + 1, $y, ($self->{stat_widget_lvl}{$idx} = new CFPlus::UI::Label 551 $x * 4 + 2, $y, $sw->[2],
519 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL), 552 $x * 4 + 3, $y, $sw->[3],
520 $x * 3 + 2, $y, (new CFPlus::UI::Label text => $name, on_button_down => $spell_cb,
521 can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL),
522 ; 553 ;
523 554
524 $x++ and ($x, $y) = (0, $y + 1); 555 $x++ and ($x, $y) = (0, $y + 1);
525 } 556 }
526 557
527 $sktbl->add_at (@add); 558 $sktbl->add_at (@add);
528 } 559 }
529 560
530 for (grep exists $stats->{$_}, @skills) { 561 for (grep exists $stats->{$_}, @skills) {
562 my $sw = $self->{skillwid}{$_};
531 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 563 $sw->[0]->set_text (::formsep ($stats->{$_}[1]));
532 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 564 $sw->[1]->set_text ($stats->{$_}[0] * 1);
565 $sw->[2]->set_value (@{$stats->{$_}});
533 } 566 }
534} 567}
535 568
536sub macro_send { 569sub macro_send {
537 my ($self, $macro) = @_; 570 my ($self, $macro) = @_;
579 $tex->upload; 612 $tex->upload;
580 } else { 613 } else {
581 $self->{delay}{$tile} = 1; 614 $self->{delay}{$tile} = 1;
582 615
583 # we assume the face is in-flight and will eventually come 616 # we assume the face is in-flight and will eventually come
584 push @{$self->{face_cb}{$tile}}, sub { 617 push @{$self->{tile_cb}{$tile}}, sub {
585 delete $self->{delay}{$tile}; 618 delete $self->{delay}{$tile};
586 $_[0]->upload; 619 $_[0]->upload;
587 }; 620 };
588 } 621 }
589 } 622 }
629} 662}
630 663
631sub bg_fetch { 664sub bg_fetch {
632 my ($self) = @_; 665 my ($self) = @_;
633 666
634 my $id; 667 my $tile;
635 668
636 do { 669 do {
637 $id = pop @{$self->{bg_fetch}} 670 $tile = pop @{$self->{bg_fetch}}
638 or return; 671 or return;
639 } while $self->{texture}[$id]; 672 } while $self->{texture}[$tile];
640 673
641 CFPlus::DB::exists tilecache => $id, sub { 674 CFPlus::DB::get tilecache => $tile, sub {
642 my ($exists) = @_; 675 my ($data) = @_;
643 676
644 return unless $self->{map}; # stop when destroyed 677 return unless $self->{map}; # stop when destroyed
645 678
646 if ($exists) { 679 if (defined $data) {
647 $self->have_tile ($id); 680 $self->have_tile ($tile, $data);
648 $self->{texture}[$id]->upload; 681 $self->{texture}[$tile]->upload;
649 } 682 }
650 683
651 $self->bg_fetch; 684 $self->bg_fetch;
652 }; 685 };
653} 686}
810 my ($self, $facenum, $face, $cb) = @_; 843 my ($self, $facenum, $face, $cb) = @_;
811 844
812 if ($face->{type} == 0) { # FT_FACE 845 if ($face->{type} == 0) { # FT_FACE
813 my $id = CFPlus::DB::get_tile_id_sync $face->{name}; 846 my $id = CFPlus::DB::get_tile_id_sync $face->{name};
814 847
815 $face->{id} = $id; 848 $face->{id} = $id;
816 $self->{faceid}[$facenum] = $id;
817
818 $self->{map}->set_tileid ($facenum => $id); 849 $self->{map}->set_tileid ($facenum => $id);
819 850
820 CFPlus::DB::get tilecache => $id, $cb; 851 CFPlus::DB::get tilecache => $id, $cb;
821 852
822 } elsif ($face->{type} & 1) { # with metadata 853 } elsif ($face->{type} & 1) { # with metadata
823 CFPlus::DB::get res_meta => $face->{name}, $cb; 854 CFPlus::DB::get res_meta => $face->{name}, $cb;
855
856 } else { # no metadata
857 CFPlus::DB::get res_data => $face->{name}, $cb;
824 } 858 }
825} 859}
826 860
827sub face_update { 861sub face_update {
828 my ($self, $facenum, $face, $changed) = @_; 862 my ($self, $facenum, $face, $changed) = @_;
829 863
830 if ($face->{type} == 0) { # FT_FACE 864 if ($face->{type} == 0) {
865 # image, FT_FACE
831 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } 866 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { }
832 if $changed; 867 if $changed;
833 868
834 $self->have_tile ($face->{id}); 869 $self->have_tile ($face->{id}, delete $face->{data});
835 870
836 } elsif ($face->{type} & 1) { # split metadata 871 } elsif ($face->{type} & 1) {
872 # split metadata case, FT_MUSIC, FT_SOUND
837 if ($changed) { # new data 873 if ($changed) { # new data
838 my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; 874 my ($meta, $data) = unpack "(w/a*)*", $face->{data};
839 $face->{meta} = $self->{json_coder}->decode ($meta_json); 875 $face->{data} = $meta;
840 876
841 CFPlus::DB::put res_data => $face->{name} => $data, sub { }; 877 CFPlus::DB::put res_data => $face->{name} => $data, sub { };
842 CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { }; 878 CFPlus::DB::put res_meta => $face->{name} => $meta, sub { };
843 } else { 879 }
880
844 $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); 881 $face->{data} = $self->{json_coder}->decode ($face->{data});
845 }
846 882
847 ::add_license ($face); 883 ::add_license ($face);
848 884
849 if ($face->{type} == 3) { # FT_MUSIC 885 if ($face->{type} == 3) { # FT_MUSIC
850 $self->{music_meta}{$facenum} = $face;
851
852 ::message ({ markup => "downloaded song #$facenum" }) 886 ::message ({ markup => "downloaded song #$facenum" })
853 if $changed; 887 if $changed;
854 888
855 &::audio_music_push ($facenum); 889 &::audio_music_push ($facenum);
856 } elsif ($face->{type} == 5) { # FT_SOUND 890 } elsif ($face->{type} == 5) { # FT_SOUND
857 $self->{sound_meta}{$facenum} = $face;
858
859 ::message ({ markup => "downloaded sound #$facenum" }) 891 ::message ({ markup => "downloaded sound #$facenum" })
860 if $changed; 892 if $changed;
861 893
862 &::audio_sound_push ($facenum); 894 &::audio_sound_push ($facenum);
863 } 895 }
864 896
897 } else {
898 # flat resource case, FT_RSRC
899 CFPlus::DB::put res_data => $face->{name} => $face->{data}, sub { }
900 if $changed;
901 }
902
903 if (my $cbs = $self->{face_cb}{$facenum}) {
904 $_->($face, $changed) for @$cbs;
865 } 905 }
866} 906}
867 907
868sub smooth_update { 908sub smooth_update {
869 my ($self, $facenum, $face) = @_; 909 my ($self, $facenum, $face) = @_;
870 910
871 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); 911 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
872} 912}
873 913
874sub have_tile { 914sub have_tile {
875 my ($self, $tile) = @_; 915 my ($self, $tile, $data) = @_;
876 916
877 return unless $self->{map}; 917 return unless $self->{map};
878 918
879 my $tex = $self->{texture}[$tile] ||= 919 my $tex = $self->{texture}[$tile] ||=
880 new CFPlus::Texture 920 new CFPlus::Texture
881 tile => $tile, minify => 1, mipmap => 1, delay => 1; 921 tile => $tile,
922 image => $data, delete_image => 1,
923 minify => 1, mipmap => 1;
882 924
883 $_->($tex) for @{(delete $self->{face_cb}{$tile}) || []}; 925 if (my $cbs = delete $self->{tile_cb}{$tile}) {
926 $_->($tex) for @$cbs;
927 }
884} 928}
885 929
886sub connect_face_update { 930# call in non-void context registers a temporary
931# hook with handle, otherwise its permanent
932sub on_face_change {
887 my ($self, $id, $cb) = @_; 933 my ($self, $num, $cb) = @_;
888 934
889 push @{$self->{face_cb}{$id}}, $cb; 935 push @{$self->{face_cb}{$num}}, $cb;
890 936
937 defined wantarray
891 CFPlus::guard { 938 ? CFPlus::guard {
892 @{$self->{face_cb}{$id}} 939 @{$self->{face_cb}{$num}}
893 = grep $_ != $cb, 940 = grep $_ != $cb,
894 @{$self->{face_cb}{$id}}; 941 @{$self->{face_cb}{$num}};
895 } 942 }
943 : ()
944}
945
946# call in non-void context registers a temporary
947# hook with handle, otherwise its permanent
948sub register_face_handler {
949 my ($self, $num, $cb) = @_;
950
951 return unless $num;
952
953 # invoke if available right now
954 $cb->($self->{face}[$num], 0)
955 unless exists $self->{face}[$num]{loading};
956
957 # future changes
958 $self->on_face_change ($num => $cb)
896} 959}
897 960
898sub sound_play { 961sub sound_play {
899 my ($self, $type, $face, $dx, $dy, $vol) = @_; 962 my ($self, $type, $face, $dx, $dy, $vol) = @_;
900 963

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines