merge: refresh ng_compare for logical game clock
This commit is contained in:
@@ -26,13 +26,19 @@ class TurnExecutionHelper
|
||||
ksort(self::$comparisonActionGeneralIds, SORT_STRING);
|
||||
return self::$comparisonActionGeneralIds;
|
||||
}
|
||||
|
||||
/** @var General*/
|
||||
protected $generalObj;
|
||||
|
||||
public function __construct(General $general)
|
||||
public function __construct(General $general)
|
||||
{
|
||||
$this->generalObj = $general;
|
||||
}
|
||||
}
|
||||
|
||||
public static function monotonicCompletionTick(int $completedTick, int $candidateTick): int
|
||||
{
|
||||
return max($completedTick, $candidateTick);
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -233,14 +239,13 @@ class TurnExecutionHelper
|
||||
$general->rebirth();
|
||||
}
|
||||
|
||||
$turntime = addTurn($general->getTurnTime(), $gameStor->turnterm);
|
||||
$turntime = addTurn($general->getTurnTick(), $gameStor->turnterm);
|
||||
|
||||
$nextTurnTimeBase = $general->getAuxVar('nextTurnTimeBase');
|
||||
if($nextTurnTimeBase !== null){
|
||||
$turntime = cutTurn($turntime, $gameStor->turnterm);
|
||||
$turntimeObj = new \DateTimeImmutable($turntime);
|
||||
$turntimeObj = $turntimeObj->add(TimeUtil::secondsToDateInterval($nextTurnTimeBase));
|
||||
$turntime = TimeUtil::format($turntimeObj, true);
|
||||
$clock = GameClock::fromStorage($gameStor);
|
||||
$turntime += $clock->ticksFromSeconds($nextTurnTimeBase);
|
||||
$general->setAuxVar('nextTurnTimeBase', null);
|
||||
}
|
||||
|
||||
@@ -248,7 +253,7 @@ class TurnExecutionHelper
|
||||
}
|
||||
|
||||
|
||||
static public function executeGeneralCommandUntil(string $date, \DateTimeInterface $limitActionTime, int $year, int $month)
|
||||
static public function executeGeneralCommandUntil(int $date, \DateTimeInterface $limitActionTime, int $year, int $month)
|
||||
{
|
||||
$db = DB::db();
|
||||
$generalsTodo = $db->query(
|
||||
@@ -258,8 +263,9 @@ class TurnExecutionHelper
|
||||
|
||||
$currentTurn = null;
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$autorun_user = $gameStor->autorun_user;
|
||||
|
||||
$traceCityChanges = PHP_SAPI === 'cli'
|
||||
&& getenv('REF_DETERMINISTIC_INSTALL_ENABLED') === '1'
|
||||
&& getenv('REF_AI_TRACE_CITY_CHANGES') === '1';
|
||||
@@ -278,20 +284,15 @@ class TurnExecutionHelper
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($generalsTodo as $rawGeneral) {
|
||||
// The comparison harness fixes the logical clock. A real wall-clock
|
||||
// timeout here made the final post-month drain depend on host load,
|
||||
// so identical seeds processed a variable number of new generals.
|
||||
// Preserve the production timeout unless deterministic comparison
|
||||
// mode was explicitly enabled.
|
||||
if (getenv('REF_DETERMINISTIC_INSTALL_ENABLED') !== '1') {
|
||||
$currActionTime = new \DateTimeImmutable();
|
||||
$currActionTime = GameClock::readWallTime();
|
||||
if ($currActionTime > $limitActionTime) {
|
||||
return [true, $currentTurn];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$general = General::createObjFromDB($rawGeneral['no']);
|
||||
if (
|
||||
PHP_SAPI === 'cli'
|
||||
@@ -392,7 +393,7 @@ class TurnExecutionHelper
|
||||
$resultNationTurn = $turnObj->processNationCommand(
|
||||
$rng,
|
||||
$nationCommandObj
|
||||
);
|
||||
);
|
||||
$nationStor->setValue($lastNationTurnKey, $resultNationTurn->toRaw());
|
||||
if (
|
||||
PHP_SAPI === 'cli'
|
||||
@@ -414,8 +415,8 @@ class TurnExecutionHelper
|
||||
$hasReservedTurn = true;
|
||||
}
|
||||
|
||||
if ($ai) {
|
||||
$newGeneralCommandObj = $ai->chooseGeneralTurn($generalCommandObj); // npc AI 처리
|
||||
if ($ai) {
|
||||
$newGeneralCommandObj = $ai->chooseGeneralTurn($generalCommandObj); // npc AI 처리
|
||||
if ($generalCommandObj !== $newGeneralCommandObj) {
|
||||
$autorunMode = true;
|
||||
$generalCommandObj = $newGeneralCommandObj;
|
||||
@@ -551,7 +552,7 @@ class TurnExecutionHelper
|
||||
pullNationCommand($general->getVar('nation'), $general->getVar('officer_level'));
|
||||
pullGeneralCommand($general->getID());
|
||||
|
||||
$currentTurn = $general->getTurnTime();
|
||||
$currentTurn = $general->getTurnTick();
|
||||
$general->increaseVarWithLimit('myset', GameConst::$incDefSettingChange, null, GameConst::$maxDefSettingChange);
|
||||
|
||||
if (($autorun_user['limit_minutes'] ?? false) && $general->getNPCType() < 2 && $hasReservedTurn) {
|
||||
@@ -614,13 +615,14 @@ class TurnExecutionHelper
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function executeAllCommand(&$executed = false, &$locked = false): string
|
||||
static public function executeAllCommand(&$executed = false, &$locked = false): int
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
if (TimeUtil::now(true) < $gameStor->turntime) {
|
||||
$clock = GameClock::fromStorage($gameStor);
|
||||
if ($clock->nowTick() < $gameStor->turntime) {
|
||||
//턴 시각 이전이면 아무것도 하지 않음
|
||||
return $gameStor->turntime;
|
||||
}
|
||||
@@ -644,7 +646,7 @@ class TurnExecutionHelper
|
||||
//접속자 수 따라서 갱신제한 변경
|
||||
CheckOverhead();
|
||||
|
||||
$date = TimeUtil::now(true);
|
||||
$date = $clock->nowTick();
|
||||
// 최종 처리 월턴의 다음 월턴시간 구함
|
||||
//$lastExecuted = $gameStor->turntime;
|
||||
$prevTurn = cutTurn($gameStor->turntime, $gameStor->turnterm);
|
||||
@@ -657,7 +659,7 @@ class TurnExecutionHelper
|
||||
$maxActionTime = max($maxActionTime * 2 / 3, $maxActionTime - 10);
|
||||
}
|
||||
|
||||
$limitActionTime = (new \DateTimeImmutable())->add(TimeUtil::secondsToDateInterval($maxActionTime));
|
||||
$limitActionTime = GameClock::readWallTime()->add(TimeUtil::secondsToDateInterval($maxActionTime));
|
||||
|
||||
// 현재 턴 이전 월턴까지 모두처리.
|
||||
//최종 처리 이후 다음 월턴이 현재 시간보다 전이라면
|
||||
@@ -674,18 +676,21 @@ class TurnExecutionHelper
|
||||
updateTraffic();
|
||||
|
||||
if ($executionOver) {
|
||||
if ($currentTurn !== null) {
|
||||
$executed = true;
|
||||
$gameStor->turntime = $currentTurn;
|
||||
if ($currentTurn !== null) {
|
||||
$executed = true;
|
||||
$gameStor->turntime = self::monotonicCompletionTick(
|
||||
Util::toInt($gameStor->turntime),
|
||||
$currentTurn,
|
||||
);
|
||||
}
|
||||
unlock();
|
||||
return $gameStor->turntime;
|
||||
}
|
||||
|
||||
$monthlyRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||
UniqueConst::$hiddenSeed,
|
||||
'monthly',
|
||||
$gameStor->year,
|
||||
UniqueConst::$hiddenSeed,
|
||||
'monthly',
|
||||
$gameStor->year,
|
||||
$gameStor->month
|
||||
)));
|
||||
|
||||
@@ -715,7 +720,7 @@ class TurnExecutionHelper
|
||||
static::runEventHandler($db, $gameStor, EventTarget::PreMonth);
|
||||
$traceMonthlyGeneral('after-pre-month-event');
|
||||
if (!preUpdateMonthly()) {
|
||||
unlock();
|
||||
unlock();
|
||||
throw new \RuntimeException('preUpdateMonthly() 처리 에러');
|
||||
}
|
||||
$traceMonthlyGeneral('after-pre-update');
|
||||
@@ -725,7 +730,7 @@ class TurnExecutionHelper
|
||||
// 분기계산. 장수들 턴보다 먼저 있다면 먼저처리
|
||||
if ($gameStor->month == 1) {
|
||||
checkStatistic();
|
||||
}
|
||||
}
|
||||
static::runEventHandler($db, $gameStor, EventTarget::Month);
|
||||
$traceMonthlyGeneral('after-month-event');
|
||||
postUpdateMonthly($monthlyRng);
|
||||
@@ -748,10 +753,16 @@ class TurnExecutionHelper
|
||||
$gameStor->month
|
||||
);
|
||||
|
||||
if ($currentTurn !== null) {
|
||||
$executed = true;
|
||||
$gameStor->turntime = $currentTurn;
|
||||
}
|
||||
if ($currentTurn !== null) {
|
||||
$executed = true;
|
||||
// A general's sub-tick can be just before the monthly boundary that
|
||||
// was completed above. Never move the global completion cursor back
|
||||
// behind an already-applied monthly event.
|
||||
$gameStor->turntime = self::monotonicCompletionTick(
|
||||
Util::toInt($gameStor->turntime),
|
||||
$currentTurn,
|
||||
);
|
||||
}
|
||||
|
||||
//토너먼트 처리
|
||||
processTournament();
|
||||
|
||||
Reference in New Issue
Block a user