ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.169 by root, Sun Jan 14 01:09:46 2007 UTC vs.
Revision 1.174 by root, Sun Jan 14 19:55:37 2007 UTC

503our @CB_TYPE = (); # registry for type (cf-object class) based events 503our @CB_TYPE = (); # registry for type (cf-object class) based events
504our @CB_MAP = (); 504our @CB_MAP = ();
505 505
506my %attachment; 506my %attachment;
507 507
508sub cf::attachable::thawer_merge {
509 # simply override everything except _meta
510 local $_[0]{_meta};
511 %{$_[0]} = %{$_[1]};
512}
513
508sub _attach_cb($$$$) { 514sub _attach_cb($$$$) {
509 my ($registry, $event, $prio, $cb) = @_; 515 my ($registry, $event, $prio, $cb) = @_;
510 516
511 use sort 'stable'; 517 use sort 'stable';
512 518
1107 1113
1108use Fcntl; 1114use Fcntl;
1109use Coro::AIO; 1115use Coro::AIO;
1110 1116
1111use overload 1117use overload
1112 '""' => \&as_string; 1118 '""' => \&as_string,
1119 fallback => 1;
1113 1120
1114our $MAX_RESET = 3600; 1121our $MAX_RESET = 3600;
1115our $DEFAULT_RESET = 3000; 1122our $DEFAULT_RESET = 3000;
1116 1123
1117sub generate_random_map { 1124sub generate_random_map {
1144} 1151}
1145 1152
1146# also paths starting with '/' 1153# also paths starting with '/'
1147$EXT_MAP{"cf::map"} = qr{^(?=/)}; 1154$EXT_MAP{"cf::map"} = qr{^(?=/)};
1148 1155
1156sub thawer_merge {
1157 my ($self, $merge) = @_;
1158
1159 # we have to keep some variables in memory intact
1160 local $self->{path};
1161 local $self->{load_path};
1162 local $self->{deny_save};
1163 local $self->{deny_reset};
1164
1165 $self->SUPER::thawer_merge ($merge);
1166}
1167
1149sub normalise { 1168sub normalise {
1150 my ($path, $base) = @_; 1169 my ($path, $base) = @_;
1151 1170
1152 # map plan: 1171 # map plan:
1153 # 1172 #
1249 1268
1250sub unlink_save { 1269sub unlink_save {
1251 my ($self) = @_; 1270 my ($self) = @_;
1252 1271
1253 utf8::encode (my $save = $self->save_path); 1272 utf8::encode (my $save = $self->save_path);
1254 IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink $save; 1273 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save;
1255 IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink "$save.pst"; 1274 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink "$save.pst";
1256} 1275}
1257 1276
1258sub load_header_from($) { 1277sub load_header_from($) {
1259 my ($self, $path) = @_; 1278 my ($self, $path) = @_;
1260 1279
1321 1340
1322 $map->load_header 1341 $map->load_header
1323 or return; 1342 or return;
1324 1343
1325 if ($map->should_reset) { 1344 if ($map->should_reset) {
1345 $cf::WAIT_FOR_TICK->wait;
1326 $map->reset; 1346 $map->reset;
1327 undef $guard; 1347 undef $guard;
1328 $map = find $path 1348 $map = find $path
1329 or return; 1349 or return;
1330 } 1350 }
1515 my ($self) = @_; 1535 my ($self) = @_;
1516 1536
1517 $self->reset_at <= $cf::RUNTIME 1537 $self->reset_at <= $cf::RUNTIME
1518} 1538}
1519 1539
1520sub rename {
1521 my ($self, $new_path) = @_;
1522
1523 normalise $new_path;
1524
1525 $self->unlink_save;
1526
1527 delete $cf::MAP{$self->path};
1528 $self->{path} = $new_path; $self->path ($self->{path});
1529 $cf::MAP{$self->path} = $self;
1530
1531 $self->save;
1532}
1533
1534sub reset { 1540sub reset {
1535 my ($self) = @_; 1541 my ($self) = @_;
1536 1542
1537 my $lock = cf::lock_acquire "map_data:$self->{path}"; 1543 my $lock = cf::lock_acquire "map_data:$self->{path}";
1538 1544
1555my $nuke_counter = "aaaa"; 1561my $nuke_counter = "aaaa";
1556 1562
1557sub nuke { 1563sub nuke {
1558 my ($self) = @_; 1564 my ($self) = @_;
1559 1565
1566 delete $cf::MAP{$self->path};
1567
1568 $self->unlink_save;
1569
1570 bless $self, "cf::map";
1571 delete $self->{deny_reset};
1560 $self->{deny_save} = 1; 1572 $self->{deny_save} = 1;
1561 $self->reset_timeout (1); 1573 $self->reset_timeout (1);
1562 $self->rename ("{nuke}/" . ($nuke_counter++)); 1574 $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++));
1575
1576 $cf::MAP{$self->path} = $self;
1577
1563 $self->reset; # polite request, might not happen 1578 $self->reset; # polite request, might not happen
1564} 1579}
1565 1580
1566=item cf::map::unique_maps 1581=item cf::map::unique_maps
1567 1582

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines