--- deliantra/server/ext/item-worldmap.ext 2007/07/23 23:38:17 1.9 +++ deliantra/server/ext/item-worldmap.ext 2010/05/14 22:56:47 1.21 @@ -27,13 +27,8 @@ fontsize => 0.2, ); - my $marker = cf::face::find "res/map-arrow.png"; - $ws->{ns}->send_face ($marker); - $ws->{ns}->flush_fx; - $marker = $ws->new (Face => - size_w => undef, - size_h => undef, - face => $marker, + my $marker = $ws->new (Face => + face => $ws->{ns}->need_face ("res/map-arrow"), ); my $children = [$label, $marker]; @@ -75,24 +70,18 @@ has_close_button => 1, on_delete => sub { shift->hide }, on_visibility_change => sub { - warn "VCHANGE <@_>\n";#d# $_[0]{visibility} = $_[1]; update_worldmap $_[0]{ws} if $_[1]; }, ); - my $face = cf::face::find "res/worldmap.jpg"; - $ns->send_face ($face); - $ns->flush_fx; - $w->add (my $sw = $ws->{window} = $ws->new (ScrolledWindow => scroll_x => 1, scroll_y => 1)); $sw->add (my $canvas = $ws->{canvas} = $ws->new (Canvas => expand => 1)); $ws->{mapface} = $ws->new (Face => - expand => 1, size_w => undef, size_h => undef, - face => $face, + face => $ws->{ns}->need_face ("res/worldmap"), ); $ws->{canvas}->add ($ws->{mapface}); @@ -110,64 +99,65 @@ my $ws = $ns->{ws_worldmap} ||= create_widgets $ns; $ws->{toplevel}->toggle_visibility; } else { - $ns->send_msg ("log", "Your client doesn't support the (required) widget extension. Try CFPlus at http://crossfire.schmorp.de/.", cf::NDI_RED); + $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); } cf::override 1; }, ; -cf::async_ext { - my $schedule_interval = Coro::Event->timer (after => 1); - - while () { - $schedule_interval->interval ($WORLDMAP_UPDATE_INTERVAL); - $schedule_interval->next; - - cf::get_slot 0.01, -50, "worldmap update"; - - ++$GENCOUNT; - - # recalculate player info - my %new; - for (values %cf::PLAYER) { - my $map = $_->ob->map - or next; - $map =~ /^\/world\/world_(\d\d\d)_(\d\d\d)/ - or next; - - my $ob = $_->ob; - my $x = ($1 - 100) * 50 + $ob->x; - my $y = ($2 - 100) * 50 + $ob->y; - - 0 <= $x && 0 <= $y && $x < 1500 && $y < 1500 - or next; - - $x = int $x * $MAPW / 1500; - $y = int $y * $MAPH / 1500; - - my $name = $ob->name; - - if (my $pi = delete $PLAYERINFO{$name}) { - if ($pi->[0] == $x && $pi->[1] == $y) { - $new{$name} = $pi; - next; +cf::post_init { + our $UPDATER = cf::async_ext { + $Coro::current->{desc} = "worldmap updater"; + + while () { + Coro::EV::timer_once $WORLDMAP_UPDATE_INTERVAL; + + cf::get_slot 0.01, -50, "worldmap update"; + + ++$GENCOUNT; + + # recalculate player info + my %new; + for (values %cf::PLAYER) { + my $map = $_->ob->map + or next; + $map =~ /^\/world\/world_(\d\d\d)_(\d\d\d)/ + or next; + + my $ob = $_->ob; + my $x = ($1 - 100) * 50 + $ob->x; + my $y = ($2 - 100) * 50 + $ob->y; + + 0 <= $x && 0 <= $y && $x < 1500 && $y < 1500 + or next; + + $x = int $x * $MAPW / 1500; + $y = int $y * $MAPH / 1500; + + my $name = $ob->name; + + if (my $pi = delete $PLAYERINFO{$name}) { + if ($pi->[0] == $x && $pi->[1] == $y) { + $new{$name} = $pi; + next; + } } + + $new{$name} = [$x, $y]; } - - $new{$name} = [$x, $y]; - } - *PLAYERINFO = \%new; + *PLAYERINFO = \%new; - cf::get_slot 0.03, -50, "worldmap socket update"; - for (values %cf::PLAYER) { - my $ns = $_->ns - or next; + cf::get_slot 0.03, -50, "worldmap socket update"; + for (values %cf::PLAYER) { + my $ns = $_->ns + or next; - update_worldmap $ns->{ws_worldmap} - if $ns->{ws_worldmap} && $ns->{ws_worldmap}{toplevel}{visibility}; + update_worldmap $ns->{ws_worldmap} + if $ns->{ws_worldmap} && $ns->{ws_worldmap}{toplevel}{visibility}; + } } - } + }; };