--- deliantra/server/lib/cf.pm 2010/01/05 16:16:37 1.498 +++ deliantra/server/lib/cf.pm 2010/01/30 23:50:16 1.504 @@ -1,7 +1,7 @@ # # This file is part of Deliantra, the Roguelike Realtime MMORPG. # -# Copyright (©) 2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team +# Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team # # Deliantra is free software: you can redistribute it and/or modify it under # the terms of the Affero GNU General Public License as published by the @@ -425,24 +425,29 @@ our @SLOT_QUEUE; our $SLOT_QUEUE; +our $SLOT_DECAY = 0.9; $SLOT_QUEUE->cancel if $SLOT_QUEUE; $SLOT_QUEUE = Coro::async { $Coro::current->desc ("timeslot manager"); my $signal = new Coro::Signal; + my $busy; while () { next_job: + my $avail = cf::till_tick; - if ($avail > 0.01) { - for (0 .. $#SLOT_QUEUE) { - if ($SLOT_QUEUE[$_][0] < $avail) { - my $job = splice @SLOT_QUEUE, $_, 1, (); - $job->[2]->send; - Coro::cede; - goto next_job; - } + + for (0 .. $#SLOT_QUEUE) { + if ($SLOT_QUEUE[$_][0] <= $avail) { + $busy = 0; + my $job = splice @SLOT_QUEUE, $_, 1, (); + $job->[2]->send; + Coro::cede; + goto next_job; + } else { + $SLOT_QUEUE[$_][0] *= $SLOT_DECAY; } } @@ -451,6 +456,7 @@ push @cf::WAIT_FOR_TICK, $signal; $signal->wait; } else { + $busy = 0; Coro::schedule; } } @@ -461,7 +467,8 @@ my ($time, $pri, $name) = @_; - $time = $TICK * .6 if $time > $TICK * .6; + $time = clamp $time, 0.01, $TICK * .6; + my $sig = new Coro::Signal; push @SLOT_QUEUE, [$time, $pri, $sig, $name]; @@ -2011,8 +2018,8 @@ } } -sub pre_load { } -sub post_load { } +sub pre_load { } +#sub post_load { } # XS sub load { my ($self) = @_; @@ -3205,8 +3212,8 @@ %vars = (_dummy => 0) unless %vars; + my @res; local $_; - local @safe::cf::_safe_eval_args = values %vars; my $eval = "do {\n" @@ -3216,9 +3223,15 @@ . "\n}" ; - sub_generation_inc; - my @res = wantarray ? $safe->reval ($eval) : scalar $safe->reval ($eval); - sub_generation_inc; + if ($CFG{safe_eval}) { + sub_generation_inc; + local @safe::cf::_safe_eval_args = values %vars; + @res = wantarray ? $safe->reval ($eval) : scalar $safe->reval ($eval); + sub_generation_inc; + } else { + local @cf::_safe_eval_args = values %vars; + @res = wantarray ? eval eval : scalar eval $eval; + } if ($@) { warn "$@"; @@ -3247,8 +3260,8 @@ sub register_script_function { my ($fun, $cb) = @_; - no strict 'refs'; - *{"safe::$fun"} = $safe_hole->wrap ($cb); + $fun = "safe::$fun" if $CFG{safe_eval}; + *$fun = $safe_hole->wrap ($cb); } =back @@ -3279,9 +3292,11 @@ or cf::cleanup "$path: version mismatch, cannot proceed."; # patch in the exptable + my $exp_table = $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]); $facedata->{resource}{"res/exp_table"} = { type => FT_RSRC, - data => $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]), + data => $exp_table, + hash => (Digest::MD5::md5 $exp_table), }; cf::cede_to_tick; @@ -3906,6 +3921,8 @@ cf::server_tick; # one server iteration + #for(1..3e6){} EV::now_update; $NOW=EV::now; # generate load #d# + if ($NOW >= $NEXT_RUNTIME_WRITE) { $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; Coro::async_pool { @@ -3937,7 +3954,7 @@ { # configure BDB - BDB::min_parallel 8; + BDB::min_parallel 16; BDB::max_poll_reqs $TICK * 0.1; $AnyEvent::BDB::WATCHER->priority (1);