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

Comparing deliantra/server/ext/map-tags.ext (file contents):
Revision 1.2 by root, Tue Sep 11 13:27:53 2007 UTC vs.
Revision 1.5 by root, Thu Sep 13 08:35:24 2007 UTC

1#! perl # mandatory 1#! perl # mandatory
2 2
3our $SCHEDULE_INTERVAL = $cf::CFG{extractor_schedule_interval} || 3600; 3our $SCHEDULE_INTERVAL = $cf::CFG{extractor_schedule_interval} || 3600;
4 4
5use JSON::XS; 5use JSON::XS;
6 6
7my $db_mapinfo = cf::sync_job { cf::db_table "tag-mapinfo" }; # info/cache for maps 7my $db_mapinfo = cf::sync_job { cf::db_table "tag-mapinfo" }; # info/cache for maps
8my $db_target = cf::sync_job { cf::db_table "tag-target" }; # tag => maps 8my $db_target = cf::sync_job { cf::db_table "tag-target" }; # tag => maps
100 100
101 &scan_static ("$dir/$_", "$map$_/") 101 &scan_static ("$dir/$_", "$map$_/")
102 for @$dirs; 102 for @$dirs;
103} 103}
104 104
105cf::async_ext { 105sub reload {
106 $Coro::current->prio (Coro::PRIO_MIN); 106 my $start = Event::time;
107 107
108 while () { 108 # 1. check for maps no longer existing
109 my $start = Event::time;
110 109
111 # 1. check for maps no longer existing 110 # 2. scan all static maps
111 scan_static $cf::MAPDIR, "/";
112 112
113 # 2. scan all static maps
114 scan_static $cf::MAPDIR, "/";
115
116 # 3. scan all dynamic maps 113 # 3. scan all dynamic maps
117 for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { 114 for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) {
118# my $map = cf::map::find $path; 115# my $map = cf::map::find $path;
119# extract_map_tags "t/$map", $path; 116# extract_map_tags "t/$map", $path;
120 } 117 }
121 118
122 # now hunt for all per-player maps 119 # now hunt for all per-player maps
123# scan_dir $cf::PLAYERDIR 120# scan_dir $cf::PLAYERDIR
124# for my $login (@{ cf::player::list_logins or [] }) { 121# for my $login (@{ cf::player::list_logins or [] }) {
125# for my $path (@{ cf::player::maps $login or [] }) { 122# for my $path (@{ cf::player::maps $login or [] }) {
126# cf::cede_to_tick; 123# cf::cede_to_tick;
144# delete $map->{deny_reset}; 141# delete $map->{deny_reset};
145# } 142# }
146# } 143# }
147# } 144# }
148 145
149 warn sprintf "map-tag scan (%fs)", Event::time - $start; 146 warn sprintf "map-tag scan (%fs)", Event::time - $start;
150 Coro::Timer::sleep $SCHEDULE_INTERVAL; 147}
151 }
152};
153 148
149our $RELOAD_SCHEDULER = Event->timer (
150 after => 0,
151 interval => $SCHEDULE_INTERVAL,
152 data => cf::WF_AUTOCANCEL,
153 cb => Coro::unblock_sub {
154 $Coro::current->prio (Coro::PRIO_MIN);
155 reload;
156 },
157);
158
159# find all objects with the given tag, or at least try to
154sub find($) { 160sub find($) {
155 my ($tag) = @_; 161 my ($tag) = @_;
156 162
157 my @res;
158
159 utf8::encode $tag; 163 utf8::encode (my $key = $tag);
160 BDB::db_get $db_target, undef, $tag, my $data; 164 BDB::db_get $db_target, undef, $key, my $data;
161 utf8::decode $data; 165 utf8::decode $data;
162 166
163 for my $map ( 167 map { $_->load; $_->find_tagged_objects ($tag) }
164 grep $_, 168 grep $_,
165 map { cf::map::find $_ } 169 map { cf::map::find $_ }
166 grep s/^s//, 170 grep s/^s//,
167 split /\x00/, $data 171 split /\x00/, $data
168 ) {
169 $map->load;
170
171 warn "tag<$tag>map<$map>\n";#d#
172 }
173
174 @res
175} 172}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines