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.198 by root, Tue May 20 02:49:56 2008 UTC vs.
Revision 1.213 by root, Mon Dec 21 23:52:34 2009 UTC

1package DC::Protocol; 1package DC::Protocol;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5
6use Guard ();
5 7
6use Deliantra::Protocol::Constants; 8use Deliantra::Protocol::Constants;
7 9
8use DC; 10use DC;
9use DC::DB; 11use DC::DB;
11use DC::Pod; 13use DC::Pod;
12use DC::Macro; 14use DC::Macro;
13use DC::Item; 15use DC::Item;
14 16
15use base 'Deliantra::Protocol::Base'; 17use base 'Deliantra::Protocol::Base';
18
19our $TEX_DIALOGUE = new_from_resource DC::Texture
20 "dialogue.png", minify => 1, mipmap => 1;
21
22our $TEX_NOFACE = new_from_resource DC::Texture
23 "noface.png", minify => 1, mipmap => 1, wrap => 1;
24
25our $TEX_HIDDEN = new_from_resource DC::Texture # MUST be POT
26 "hidden-0.png", minify => 1, mipmap => 1, wrap => 1;
27
28sub MIN_TEXTURE_UNUSED() { 1 }#d#
16 29
17sub new { 30sub new {
18 my ($class, %arg) = @_; 31 my ($class, %arg) = @_;
19 32
20 my $self = $class->SUPER::new (%arg, 33 my $self = $class->SUPER::new (%arg,
67 for values %{delete $ws->{w} || {}}; 80 for values %{delete $ws->{w} || {}};
68 } 81 }
69 82
70 delete $self->{items}; 83 delete $self->{items};
71 $::INV->clear; 84 $::INV->clear;
85 $::INVR->clear;
72 $::INVR_HB->clear; 86 $::INVR_HB->clear;
73 $::FLOORBOX->clear; 87 $::FLOORBOX->clear;
74 }); 88 });
75 89
76 $self->{map_widget}->add_command (@$_) 90 $self->{map_widget}->add_command (@$_)
77 for @cmd_help; 91 for @cmd_help;
78 92
79 { 93 {
80 $self->{dialogue} = my $tex = new_from_file DC::Texture 94 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
81 DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
82 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 95 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
83 } 96 }
84 97
85 { 98 {
86 $self->{noface} = my $tex = new_from_file DC::Texture 99 $self->{noface} = my $tex = $TEX_NOFACE;
87 DC::find_rcfile "noface.png", minify => 1, mipmap => 1;
88 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 100 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
89 } 101 }
102
103 {
104 $self->{hidden} = my $tex = $TEX_HIDDEN;
105 $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}});
106 $self->{map_widget}{hidden_tex} = $tex;#d#
107 }
108
109# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
110# $self->{expire_w} = EV::timer 1, 1, sub {
111# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
112#
113# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
114# warn DC::SvREFCNT $self->{texture}[$_];
115# $self->{texture}[$_]->unload;
116# warn "expire texture $_\n";#d#
117# }
118#
119# ($self->{expire_count} += $count) < @{ $self->{texture} }
120# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
121# warn "count is $count\n";#d#
122# };
90 123
91 $self->{open_container} = 0; 124 $self->{open_container} = 0;
92 125
93 # per server 126 # per server
94 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 127 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
255 my %wkw = ( 288 my %wkw = (
256 root => $DC::UI::ROOT, 289 root => $DC::UI::ROOT,
257 tooltip => $DC::UI::TOOLTIP, 290 tooltip => $DC::UI::TOOLTIP,
258 291
259 mapwidget => $::MAPWIDGET, 292 mapwidget => $::MAPWIDGET,
293 menubar => $::MENUBAR,
294 menupopup => $::MENUPOPUP,
295 pickup_enable => $::PICKUP_ENABLE,
260 buttonbar => $::BUTTONBAR, 296 buttonbar => $::BUTTONBAR,
261 metaserver => $::METASERVER, 297 metaserver => $::METASERVER,
262 buttonbar => $::BUTTONBAR, 298 buttonbar => $::BUTTONBAR,
263 login_button => $::LOGIN_BUTTON, 299 login_button => $::LOGIN_BUTTON,
264 quit_dialog => $::QUIT_DIALOG, 300 quit_dialog => $::QUIT_DIALOG,
281 317
282 floorbox => $::FLOORBOX, 318 floorbox => $::FLOORBOX,
283 help_window => $::HELP_WINDOW, 319 help_window => $::HELP_WINDOW,
284 message_window => $::MESSAGE_WINDOW, 320 message_window => $::MESSAGE_WINDOW,
285 message_dist => $::MESSAGE_DIST, 321 message_dist => $::MESSAGE_DIST,
286 statusbox => $::SDTATUSBOX, 322 statusbox => $::STATUSBOX,
287 323
288 inv => $::INV, 324 inv => $::INV,
289 invr => $::INVR, 325 invr => $::INVR,
290 invr_hb => $::INVR_HB, 326 invr_hb => $::INVR_HB,
291 ); 327 );
375 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 411 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
376 : () 412 : ()
377 } 413 }
378 sort { $a <=> $b } keys %{$self->{spell_paths}}; 414 sort { $a <=> $b } keys %{$self->{spell_paths}};
379 415
380 join "", @diff 416 "\u$name: " . (join ", ", @diff)
381} 417}
382 418
383# all stats that are chacked against changes 419# all stats that are chacked against changes
384my @statchange = ( 420my @statchange = (
385 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 421 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
440 } 476 }
441 477
442 if ( 478 if (
443 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 479 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
444 ) { 480 ) {
445 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 481 my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs);
446 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); 482 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
447 } 483 }
448 484
449 $self->update_stats_window ($stats, $prev); 485 $self->update_stats_window ($stats, $prev);
450 486
488 524
489 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 525 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
490 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 526 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
491 $::GAUGES->{food} ->set_value ($fo, $fo_m); 527 $::GAUGES->{food} ->set_value ($fo, $fo_m);
492 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 528 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
493 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 529 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
494 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 530 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
495 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); 531 $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
496 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 532 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
497 my $title = $stats->{+CS_STAT_TITLE}; 533 my $title = $stats->{+CS_STAT_TITLE};
498 $title =~ s/^Player: //; 534 $title =~ s/^Player: //;
499 $::STATWIDS->{title} ->set_text ("Title: " . $title); 535 $::STATWIDS->{title} ->set_text ("Title: " . $title);
500 536
541 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 577 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
542 ]; 578 ];
543 579
544 my @add = @$sw; 580 my @add = @$sw;
545 581
546 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 582 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
547 583
548 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 584 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
549 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 585 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
550 586
551 my ($x, $y) = (0, 1); 587 my ($x, $y) = (0, 1);
613 my $sw = $self->{skillwid}{$idx}; 649 my $sw = $self->{skillwid}{$idx};
614 $sw->[0]->set_text (::formsep ($val->[1])); 650 $sw->[0]->set_text (::formsep ($val->[1]));
615 $sw->[1]->set_text ($val->[0] * 1); 651 $sw->[1]->set_text ($val->[0] * 1);
616 $sw->[2]->set_value (@$val); 652 $sw->[2]->set_value (@$val);
617 653
618 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 654 $::GAUGES->{skillexp}->set_label ("$name %d%%");
619 $::GAUGES->{sklprg}->set_value (@$val); 655 $::GAUGES->{skillexp}->set_value (@$val);
620 } 656 }
621} 657}
622 658
623sub user_send { 659sub user_send {
624 my ($self, $command) = @_; 660 my ($self, $command) = @_;
637} 673}
638 674
639sub map_scroll { 675sub map_scroll {
640 my ($self, $dx, $dy) = @_; 676 my ($self, $dx, $dy) = @_;
641 677
642 $self->{map}->scroll ($dx, $dy); 678 $self->{map_widget}->scroll ($dx, $dy);
643} 679}
644 680
645sub feed_map1a { 681sub feed_map1a {
646 my ($self, $data) = @_; 682 my ($self, $data) = @_;
647 683
651 for my $tile (@$missing) { 687 for my $tile (@$missing) {
652 next if $self->{delay}{$tile}; 688 next if $self->{delay}{$tile};
653 689
654 $delay = 1; 690 $delay = 1;
655 691
656 if (my $tex = $::CONN->{texture}[$tile]) { 692 if (my $tex = $self->{texture}[$tile]) {
657 $tex->upload; 693 $tex->upload;
658 } else { 694 } else {
659 $self->{delay}{$tile} = 1; 695 $self->{delay}{$tile} = 1;
660 696
661 # we assume the face is in-flight and will eventually come 697 # we assume the face is in-flight and will eventually arrive
662 push @{$self->{tile_cb}{$tile}}, sub { 698 push @{$self->{tile_cb}{$tile}}, sub {
663 delete $self->{delay}{$tile}; 699 delete $self->{delay}{$tile};
664 $_[0]->upload; 700 $_[0]->upload;
665 }; 701 };
666 } 702 }
667 } 703 }
668 704
669 if ($delay) { 705 if ($delay) {
670 # delay the map drawing a tiny bit in the hope of getting the missing fetched 706 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
671 EV::once undef, 0, 0.03, sub { 707 EV::once undef, 0, 0.03, sub {
672 $self->{map_widget}->update 708 $self->{map_widget}->update
673 if $self->{map_widget}; 709 if $self->{map_widget};
674 }; 710 };
675 } else { 711 } else {
963 999
964 my $tex = $self->{texture}[$tile] ||= 1000 my $tex = $self->{texture}[$tile] ||=
965 new DC::Texture 1001 new DC::Texture
966 tile => $tile, 1002 tile => $tile,
967 image => $data, delete_image => 1, 1003 image => $data, delete_image => 1,
968 minify => 1, mipmap => 1; 1004 minify => 1;
969 1005
970 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1006 if (my $cbs = delete $self->{tile_cb}{$tile}) {
971 $_->($tex) for @$cbs; 1007 $_->($tex) for @$cbs;
972 } 1008 }
973} 1009}
978 my ($self, $num, $cb) = @_; 1014 my ($self, $num, $cb) = @_;
979 1015
980 push @{$self->{face_cb}{$num}}, $cb; 1016 push @{$self->{face_cb}{$num}}, $cb;
981 1017
982 defined wantarray 1018 defined wantarray
983 ? DC::guard { 1019 ? Guard::guard {
984 @{$self->{face_cb}{$num}} 1020 @{$self->{face_cb}{$num}}
985 = grep $_ != $cb, 1021 = grep $_ != $cb,
986 @{$self->{face_cb}{$num}}; 1022 @{$self->{face_cb}{$num}};
987 } 1023 }
988 : () 1024 : ()
1092 1128
1093 ## try to create single paragraphs of multiple lines sent by the server 1129 ## try to create single paragraphs of multiple lines sent by the server
1094 # no longer neecssary with TRT servers 1130 # no longer neecssary with TRT servers
1095 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1131 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1096 1132
1097 for (split /\n/, $text) {
1098 ::message ({ 1133 ::message ({
1099 fg => $fg, 1134 fg => $fg,
1100 markup => $_, 1135 markup => $text,
1101 type => $type, 1136 type => $type,
1102 extra => [@extra], 1137 extra => [@extra],
1103 color_flags => $color, #d# ugly, kill 1138 color_flags => $color, #d# ugly, kill
1104 }); 1139 });
1105 1140
1106 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1141# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1107 # actually, this is an ugly design. _we_ should control the channels, 1142# # actually, this is an ugly design. _we_ should control the channels,
1108 # not some random other widget, as the channels are clearly protocol-specific. 1143# # not some random other widget, as the channels are clearly protocol-specific.
1109 # then we could also react to flags such as CLEAR without resorting to 1144# # then we could also react to flags such as CLEAR without resorting to
1110 # hacks such as color_flags, above. 1145# # hacks such as color_flags, above.
1111 }
1112 1146
1113 $self->{statusbox}->add ($text, 1147 $self->{statusbox}->add ($text,
1114 group => $text, 1148 group => $text,
1115 fg => $fg, 1149 fg => $fg,
1116 timeout => $color >= 2 ? 180 : 10, 1150 timeout => $color >= 2 ? 180 : 10,
1363 }); 1397 });
1364 1398
1365 $self->update_server_info; 1399 $self->update_server_info;
1366 1400
1367 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1401 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1368 $self->send_command ("pickup $::CFG->{pickup}"); 1402 $self->send_pickup ($::CFG->{pickup});
1403
1404 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1405 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1369} 1406}
1370 1407
1371sub lookat { 1408sub lookat {
1372 my ($self, $x, $y) = @_; 1409 my ($self, $x, $y) = @_;
1373 1410
1537} 1574}
1538 1575
1539sub send { 1576sub send {
1540 my ($self, $msg) = @_; 1577 my ($self, $msg) = @_;
1541 1578
1542 $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); 1579 $self->{textview}->add_paragraph ({
1580 markup =>
1581 "\n<span foreground='#ffff00'><b>"
1582 . (DC::asxml $msg)
1583 . "</b></span>"
1584 });
1543 $self->{textview}->scroll_to_bottom; 1585 $self->{textview}->scroll_to_bottom;
1544 1586
1545 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1587 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1546} 1588}
1547 1589

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines