… | |
… | |
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; |
… | |
… | |
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 $status = load_resource_file_ $_[0]; |
|
|
3319 | get_slot 0.1, 100; |
|
|
3320 | cf::arch::commit_load; |
|
|
3321 | $status |
|
|
3322 | } |
|
|
3323 | |
3317 | sub reload_regions { |
3324 | sub reload_regions { |
3318 | # HACK to clear player env face cache, we need some signal framework |
3325 | # HACK to clear player env face cache, we need some signal framework |
3319 | # for this (global event?) |
3326 | # for this (global event?) |
3320 | %ext::player_env::MUSIC_FACE_CACHE = (); |
3327 | %ext::player_env::MUSIC_FACE_CACHE = (); |
3321 | |
3328 | |
… | |
… | |
3334 | } |
3341 | } |
3335 | |
3342 | |
3336 | sub reload_archetypes { |
3343 | sub reload_archetypes { |
3337 | load_resource_file "$DATADIR/archetypes" |
3344 | load_resource_file "$DATADIR/archetypes" |
3338 | or die "unable to load archetypes\n"; |
3345 | 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 | } |
3346 | } |
3345 | |
3347 | |
3346 | sub reload_treasures { |
3348 | sub reload_treasures { |
3347 | load_resource_file "$DATADIR/treasures" |
3349 | load_resource_file "$DATADIR/treasures" |
3348 | or die "unable to load treasurelists\n"; |
3350 | or die "unable to load treasurelists\n"; |
3349 | } |
3351 | } |
3350 | |
3352 | |
3351 | sub reload_resources { |
3353 | sub reload_resources { |
3352 | warn "reloading resource files...\n"; |
3354 | warn "reloading resource files...\n"; |
3353 | |
3355 | |
|
|
3356 | reload_facedata; |
|
|
3357 | reload_archetypes; |
3354 | reload_regions; |
3358 | reload_regions; |
3355 | reload_facedata; |
|
|
3356 | #reload_archetypes;#d# |
|
|
3357 | reload_archetypes; |
|
|
3358 | reload_treasures; |
3359 | reload_treasures; |
3359 | |
3360 | |
3360 | warn "finished reloading resource files\n"; |
3361 | warn "finished reloading resource files\n"; |
3361 | } |
3362 | } |
3362 | |
3363 | |
3363 | sub init { |
3364 | sub init { |
|
|
3365 | my $guard = freeze_mainloop; |
|
|
3366 | |
3364 | reload_resources; |
3367 | reload_resources; |
3365 | } |
3368 | } |
3366 | |
3369 | |
3367 | sub reload_config { |
3370 | sub reload_config { |
3368 | open my $fh, "<:utf8", "$CONFDIR/config" |
3371 | open my $fh, "<:utf8", "$CONFDIR/config" |
… | |
… | |
3393 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3396 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3394 | EV::loop EV::LOOP_ONESHOT; |
3397 | EV::loop EV::LOOP_ONESHOT; |
3395 | })->prio (Coro::PRIO_MAX); |
3398 | })->prio (Coro::PRIO_MAX); |
3396 | }; |
3399 | }; |
3397 | |
3400 | |
|
|
3401 | { |
|
|
3402 | my $guard = freeze_mainloop; |
3398 | reload_config; |
3403 | reload_config; |
3399 | db_init; |
3404 | db_init; |
3400 | load_extensions; |
3405 | load_extensions; |
3401 | |
3406 | |
3402 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3407 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3403 | evthread_start IO::AIO::poll_fileno; |
3408 | evthread_start IO::AIO::poll_fileno; |
|
|
3409 | } |
|
|
3410 | |
3404 | EV::loop; |
3411 | EV::loop; |
3405 | } |
3412 | } |
3406 | |
3413 | |
3407 | ############################################################################# |
3414 | ############################################################################# |
3408 | # initialisation and cleanup |
3415 | # initialisation and cleanup |
… | |
… | |
3690 | |
3697 | |
3691 | our @WAIT_FOR_TICK; |
3698 | our @WAIT_FOR_TICK; |
3692 | our @WAIT_FOR_TICK_BEGIN; |
3699 | our @WAIT_FOR_TICK_BEGIN; |
3693 | |
3700 | |
3694 | sub wait_for_tick { |
3701 | sub wait_for_tick { |
3695 | return if tick_inhibit; |
|
|
3696 | return if $Coro::current == $Coro::main; |
3702 | return if tick_inhibit || $Coro::current == $Coro::main; |
3697 | |
3703 | |
3698 | my $signal = new Coro::Signal; |
3704 | my $signal = new Coro::Signal; |
3699 | push @WAIT_FOR_TICK, $signal; |
3705 | push @WAIT_FOR_TICK, $signal; |
3700 | $signal->wait; |
3706 | $signal->wait; |
3701 | } |
3707 | } |
3702 | |
3708 | |
3703 | sub wait_for_tick_begin { |
3709 | sub wait_for_tick_begin { |
3704 | return if tick_inhibit; |
|
|
3705 | return if $Coro::current == $Coro::main; |
3710 | return if tick_inhibit || $Coro::current == $Coro::main; |
3706 | |
3711 | |
3707 | my $signal = new Coro::Signal; |
3712 | my $signal = new Coro::Signal; |
3708 | push @WAIT_FOR_TICK_BEGIN, $signal; |
3713 | push @WAIT_FOR_TICK_BEGIN, $signal; |
3709 | $signal->wait; |
3714 | $signal->wait; |
3710 | } |
3715 | } |