… | |
… | |
427 | } |
427 | } |
428 | } |
428 | } |
429 | }; |
429 | }; |
430 | |
430 | |
431 | sub get_slot($;$$) { |
431 | sub get_slot($;$$) { |
432 | return if tick_inhibit; |
432 | return if tick_inhibit || $Coro::current == $Coro::main; |
433 | |
433 | |
434 | my ($time, $pri, $name) = @_; |
434 | my ($time, $pri, $name) = @_; |
435 | |
435 | |
436 | $time = $TICK * .6 if $time > $TICK * .6; |
436 | $time = $TICK * .6 if $time > $TICK * .6; |
437 | my $sig = new Coro::Signal; |
437 | my $sig = new Coro::Signal; |
… | |
… | |
2699 | $rmp->{origin_y} = $exit->y; |
2699 | $rmp->{origin_y} = $exit->y; |
2700 | } |
2700 | } |
2701 | |
2701 | |
2702 | $rmp->{random_seed} ||= $exit->random_seed; |
2702 | $rmp->{random_seed} ||= $exit->random_seed; |
2703 | |
2703 | |
2704 | my $data = cf::encode_json $rmp; |
2704 | my $data = JSON::XS->new->utf8->pretty->canonical->encode ($rmp); |
2705 | my $md5 = Digest::MD5::md5_hex $data; |
2705 | my $md5 = Digest::MD5::md5_hex $data; |
2706 | my $meta = "$RANDOMDIR/$md5.meta"; |
2706 | my $meta = "$RANDOMDIR/$md5.meta"; |
2707 | |
2707 | |
2708 | if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) { |
2708 | if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) { |
2709 | aio_write $fh, 0, (length $data), $data, 0; |
2709 | aio_write $fh, 0, (length $data), $data, 0; |
… | |
… | |
3078 | |
3078 | |
3079 | The following functions and methods are available within a safe environment: |
3079 | The following functions and methods are available within a safe environment: |
3080 | |
3080 | |
3081 | cf::object |
3081 | cf::object |
3082 | contr pay_amount pay_player map x y force_find force_add destroy |
3082 | contr pay_amount pay_player map x y force_find force_add destroy |
3083 | insert remove name archname title slaying race decrease_ob_nr |
3083 | insert remove name archname title slaying race decrease split |
3084 | |
3084 | |
3085 | cf::object::player |
3085 | cf::object::player |
3086 | player |
3086 | player |
3087 | |
3087 | |
3088 | cf::player |
3088 | cf::player |
… | |
… | |
3094 | =cut |
3094 | =cut |
3095 | |
3095 | |
3096 | for ( |
3096 | for ( |
3097 | ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y |
3097 | ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y |
3098 | insert remove inv name archname title slaying race |
3098 | insert remove inv name archname title slaying race |
3099 | decrease_ob_nr destroy)], |
3099 | decrease split destroy)], |
3100 | ["cf::object::player" => qw(player)], |
3100 | ["cf::object::player" => qw(player)], |
3101 | ["cf::player" => qw(peaceful)], |
3101 | ["cf::player" => qw(peaceful)], |
3102 | ["cf::map" => qw(trigger)], |
3102 | ["cf::map" => qw(trigger)], |
3103 | ) { |
3103 | ) { |
3104 | no strict 'refs'; |
3104 | no strict 'refs'; |
… | |
… | |
3312 | while (my ($k, $v) = each %$want) { |
3312 | while (my ($k, $v) = each %$want) { |
3313 | $ns->fx_want ($k, $v); |
3313 | $ns->fx_want ($k, $v); |
3314 | } |
3314 | } |
3315 | }; |
3315 | }; |
3316 | |
3316 | |
|
|
3317 | sub load_resource_file($) { |
|
|
3318 | my $guard = lock_acquire "load_resource_file"; |
|
|
3319 | |
|
|
3320 | my $status = load_resource_file_ $_[0]; |
|
|
3321 | get_slot 0.1, 100; |
|
|
3322 | cf::arch::commit_load; |
|
|
3323 | |
|
|
3324 | $status |
|
|
3325 | } |
|
|
3326 | |
3317 | sub reload_regions { |
3327 | sub reload_regions { |
3318 | # HACK to clear player env face cache, we need some signal framework |
3328 | # HACK to clear player env face cache, we need some signal framework |
3319 | # for this (global event?) |
3329 | # for this (global event?) |
3320 | %ext::player_env::MUSIC_FACE_CACHE = (); |
3330 | %ext::player_env::MUSIC_FACE_CACHE = (); |
3321 | |
3331 | |
… | |
… | |
3334 | } |
3344 | } |
3335 | |
3345 | |
3336 | sub reload_archetypes { |
3346 | sub reload_archetypes { |
3337 | load_resource_file "$DATADIR/archetypes" |
3347 | load_resource_file "$DATADIR/archetypes" |
3338 | or die "unable to load archetypes\n"; |
3348 | or die "unable to load archetypes\n"; |
3339 | #d# NEED to laod twice to resolve forward references |
|
|
3340 | # this really needs to be done in an extra post-pass |
|
|
3341 | # (which needs to be synchronous, so solve it differently) |
|
|
3342 | load_resource_file "$DATADIR/archetypes" |
|
|
3343 | or die "unable to load archetypes\n"; |
|
|
3344 | } |
3349 | } |
3345 | |
3350 | |
3346 | sub reload_treasures { |
3351 | sub reload_treasures { |
3347 | load_resource_file "$DATADIR/treasures" |
3352 | load_resource_file "$DATADIR/treasures" |
3348 | or die "unable to load treasurelists\n"; |
3353 | or die "unable to load treasurelists\n"; |
3349 | } |
3354 | } |
3350 | |
3355 | |
3351 | sub reload_resources { |
3356 | sub reload_resources { |
3352 | warn "reloading resource files...\n"; |
3357 | warn "reloading resource files...\n"; |
3353 | |
3358 | |
|
|
3359 | reload_facedata; |
|
|
3360 | reload_archetypes; |
3354 | reload_regions; |
3361 | reload_regions; |
3355 | reload_facedata; |
|
|
3356 | #reload_archetypes;#d# |
|
|
3357 | reload_archetypes; |
|
|
3358 | reload_treasures; |
3362 | reload_treasures; |
3359 | |
3363 | |
3360 | warn "finished reloading resource files\n"; |
3364 | warn "finished reloading resource files\n"; |
3361 | } |
3365 | } |
3362 | |
3366 | |
3363 | sub init { |
3367 | sub init { |
|
|
3368 | my $guard = freeze_mainloop; |
|
|
3369 | |
3364 | reload_resources; |
3370 | reload_resources; |
3365 | } |
3371 | } |
3366 | |
3372 | |
3367 | sub reload_config { |
3373 | sub reload_config { |
3368 | open my $fh, "<:utf8", "$CONFDIR/config" |
3374 | open my $fh, "<:utf8", "$CONFDIR/config" |
… | |
… | |
3393 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3399 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3394 | EV::loop EV::LOOP_ONESHOT; |
3400 | EV::loop EV::LOOP_ONESHOT; |
3395 | })->prio (Coro::PRIO_MAX); |
3401 | })->prio (Coro::PRIO_MAX); |
3396 | }; |
3402 | }; |
3397 | |
3403 | |
|
|
3404 | { |
|
|
3405 | my $guard = freeze_mainloop; |
3398 | reload_config; |
3406 | reload_config; |
3399 | db_init; |
3407 | db_init; |
3400 | load_extensions; |
3408 | load_extensions; |
3401 | |
3409 | |
3402 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3410 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3403 | evthread_start IO::AIO::poll_fileno; |
3411 | evthread_start IO::AIO::poll_fileno; |
|
|
3412 | } |
|
|
3413 | |
3404 | EV::loop; |
3414 | EV::loop; |
3405 | } |
3415 | } |
3406 | |
3416 | |
3407 | ############################################################################# |
3417 | ############################################################################# |
3408 | # initialisation and cleanup |
3418 | # initialisation and cleanup |
… | |
… | |
3690 | |
3700 | |
3691 | our @WAIT_FOR_TICK; |
3701 | our @WAIT_FOR_TICK; |
3692 | our @WAIT_FOR_TICK_BEGIN; |
3702 | our @WAIT_FOR_TICK_BEGIN; |
3693 | |
3703 | |
3694 | sub wait_for_tick { |
3704 | sub wait_for_tick { |
3695 | return if tick_inhibit; |
|
|
3696 | return if $Coro::current == $Coro::main; |
3705 | return if tick_inhibit || $Coro::current == $Coro::main; |
3697 | |
3706 | |
3698 | my $signal = new Coro::Signal; |
3707 | my $signal = new Coro::Signal; |
3699 | push @WAIT_FOR_TICK, $signal; |
3708 | push @WAIT_FOR_TICK, $signal; |
3700 | $signal->wait; |
3709 | $signal->wait; |
3701 | } |
3710 | } |
3702 | |
3711 | |
3703 | sub wait_for_tick_begin { |
3712 | sub wait_for_tick_begin { |
3704 | return if tick_inhibit; |
|
|
3705 | return if $Coro::current == $Coro::main; |
3713 | return if tick_inhibit || $Coro::current == $Coro::main; |
3706 | |
3714 | |
3707 | my $signal = new Coro::Signal; |
3715 | my $signal = new Coro::Signal; |
3708 | push @WAIT_FOR_TICK_BEGIN, $signal; |
3716 | push @WAIT_FOR_TICK_BEGIN, $signal; |
3709 | $signal->wait; |
3717 | $signal->wait; |
3710 | } |
3718 | } |