ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/item-worldmap.ext
(Generate patch)

Comparing deliantra/server/ext/item-worldmap.ext (file contents):
Revision 1.8 by root, Mon Jul 23 21:02:50 2007 UTC vs.
Revision 1.23 by root, Fri Feb 3 03:01:44 2012 UTC

1#! perl # depends=widget mandatory 1#! perl # depends=widget mandatory
2 2
3# this module implements a rather fancy worldmap 3# this module implements a rather fancy worldmap
4 4
5our $WORLDMAP_UPDATE_INTERVAL = $cf::CFG{worldmap_update_interval} || 2; 5CONF WORLDMAP_UPDATE_INTERVAL = 2;
6 6
7our $GENCOUNT = 0; 7our $GENCOUNT = 0;
8our %PLAYERINFO; 8our %PLAYERINFO;
9 9
10our ($MAPW, $MAPH) = (1024, 1024); # it's useful to know the map width/height in pixels 10our ($MAPW, $MAPH) = (1024, 1024); # it's useful to know the map width/height in pixels
23 while (my ($k, $v) = each %PLAYERINFO) { 23 while (my ($k, $v) = each %PLAYERINFO) {
24 my $label = (delete $old->{$k}) || do { 24 my $label = (delete $old->{$k}) || do {
25 my $label = $ws->new (Label => 25 my $label = $ws->new (Label =>
26 text => $k, 26 text => $k,
27 fontsize => 0.2, 27 fontsize => 0.2,
28 );
29
30 my $marker = $ws->new (Face =>
31 face => $ws->{ns}->need_face ("res/map-arrow"),
32 );
33 my $children = [$label, $marker];
34
35 $ws->{canvas}->add (my $vbox = $ws->new (VBox =>
36 children => $children,
28 c_halign => -.5, 37 c_halign => -.5,
29 c_valign => -1, 38 c_valign => -1,
30 ); 39 ));
31 $ws->{canvas}->add ($label); 40 $vbox->{children} = $children;
41
32 $label 42 $vbox
33 }; 43 };
34 44
35 $new->{$k} = $label; 45 $new->{$k} = $label;
36 46
37 if ($v != $label->{prevpos}) { 47 if ($v != $label->{prevpos}) {
41 if $k eq $name; 51 if $k eq $name;
42 } 52 }
43 } 53 }
44 54
45 $ws->{labels} = $new; 55 $ws->{labels} = $new;
46
47 #$_->destroy for values %$old;#d#
48} 56}
49 57
50sub create_widgets { 58sub create_widgets {
51 my ($ns) = @_; 59 my ($ns) = @_;
52 60
65 $_[0]{visibility} = $_[1]; 73 $_[0]{visibility} = $_[1];
66 update_worldmap $_[0]{ws} if $_[1]; 74 update_worldmap $_[0]{ws} if $_[1];
67 }, 75 },
68 ); 76 );
69 77
70 my $face = cf::face::find "res/worldmap.jpg";
71 $ns->send_face ($face);
72 $ns->flush_fx;
73
74 $w->add (my $sw = $ws->{window} = $ws->new (ScrolledWindow => scroll_x => 1, scroll_y => 1)); 78 $w->add (my $sw = $ws->{window} = $ws->new (ScrolledWindow => scroll_x => 1, scroll_y => 1));
75 $sw->add (my $canvas = $ws->{canvas} = $ws->new (Canvas => expand => 1)); 79 $sw->add (my $canvas = $ws->{canvas} = $ws->new (Canvas => expand => 1));
76 80
77 $ws->{mapface} = $ws->new (Face => 81 $ws->{mapface} = $ws->new (Face =>
78 expand => 1,
79 size_w => undef, 82 size_w => undef,
80 size_h => undef, 83 size_h => undef,
81 face => $face, 84 face => $ws->{ns}->need_face ("res/worldmap"),
82 ); 85 );
83 86
84 $ws->{canvas}->add ($ws->{mapface}); 87 $ws->{canvas}->add ($ws->{mapface});
85 88
86 $ws 89 $ws
94 97
95 if ($ns->{can_widget}) { 98 if ($ns->{can_widget}) {
96 my $ws = $ns->{ws_worldmap} ||= create_widgets $ns; 99 my $ws = $ns->{ws_worldmap} ||= create_widgets $ns;
97 $ws->{toplevel}->toggle_visibility; 100 $ws->{toplevel}->toggle_visibility;
98 } else { 101 } else {
99 $ns->send_msg ("log", "Your client doesn't support the (required) widget extension. Try CFPlus at http://crossfire.schmorp.de/.", cf::NDI_RED); 102 $ns->send_msg ("log", "Your client doesn't support the (required) widget extension. Try the deliantra client at http://www.deliantra.net/.", cf::NDI_RED);
100 } 103 }
101 104
102 cf::override 1; 105 cf::override 1;
103 }, 106 },
104; 107;
105 108
106cf::async_ext { 109cf::post_init {
107 my $schedule_interval = Coro::Event->timer (after => 1); 110 our $UPDATER = cf::async_ext {
111 $Coro::current->{desc} = "worldmap updater";
108 112
109 while () { 113 while () {
110 $schedule_interval->interval ($WORLDMAP_UPDATE_INTERVAL); 114 Coro::AnyEvent::sleep $WORLDMAP_UPDATE_INTERVAL;
111 $schedule_interval->next;
112 115
113 cf::get_slot 0.01, -50, "worldmap update"; 116 cf::get_slot 0.01, -50, "worldmap update";
114 117
115 ++$GENCOUNT; 118 ++$GENCOUNT;
116 119
117 # recalculate player info 120 # recalculate player info
118 my %new; 121 my %new;
119 for (values %cf::PLAYER) { 122 for (values %cf::PLAYER) {
120 my $map = $_->ob->map 123 my $map = $_->ob->map
121 or next; 124 or next;
122 $map =~ /^\/world\/world_(\d\d\d)_(\d\d\d)/ 125 $map =~ /^\/world\/world_(\d\d\d)_(\d\d\d)/
123 or next; 126 or next;
124 127
125 my $ob = $_->ob; 128 my $ob = $_->ob;
126 my $x = ($1 - 100) * 50 + $ob->x; 129 my $x = ($1 - 100) * 50 + $ob->x;
127 my $y = ($2 - 100) * 50 + $ob->y; 130 my $y = ($2 - 100) * 50 + $ob->y;
128 131
129 0 <= $x && 0 <= $y && $x < 1500 && $y < 1500 132 0 <= $x && 0 <= $y && $x < 1500 && $y < 1500
130 or next; 133 or next;
131 134
132 $x = int $x * $MAPW / 1500; 135 $x = int $x * $MAPW / 1500;
133 $y = int $y * $MAPH / 1500; 136 $y = int $y * $MAPH / 1500;
134 137
135 my $name = $ob->name; 138 my $name = $ob->name;
136 139
137 if (my $pi = delete $PLAYERINFO{$name}) { 140 if (my $pi = delete $PLAYERINFO{$name}) {
138 if ($pi->[0] == $x && $pi->[1] == $y) { 141 if ($pi->[0] == $x && $pi->[1] == $y) {
139 $new{$name} = $pi; 142 $new{$name} = $pi;
140 next; 143 next;
144 }
141 } 145 }
146
147 $new{$name} = [$x, $y];
142 } 148 }
149
150 *PLAYERINFO = \%new;
151
152 cf::get_slot 0.03, -50, "worldmap socket update";
153 for (values %cf::PLAYER) {
154 my $ns = $_->ns
143 155 or next;
144 $new{$name} = [$x, $y]; 156
157 update_worldmap $ns->{ws_worldmap}
158 if $ns->{ws_worldmap} && $ns->{ws_worldmap}{toplevel}{visibility};
159 }
145 } 160 }
146
147 *PLAYERINFO = \%new;
148
149 cf::get_slot 0.03, -50, "worldmap socket update";
150 for (values %cf::PLAYER) {
151 my $ns = $_->ns
152 or next;
153
154 update_worldmap $ns->{ws_worldmap}
155 if $ns->{ws_worldmap} && $ns->{ws_worldmap}{toplevel}{visibility};
156 }
157 } 161 };
158}; 162};
159 163

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines