_getSelfMysql(), 't_dyndata', array( 'account_id' => myself()->_getAccountId(), ) ); foreach ($rows as $row) { $key = self::calcKey($row['x'], $row['y']); self::$dynData[$key] = $row['val']; } } } public static function getV($x, $y, $defVal = 0) { $key = self::calcKey($x, $y); if (self::$dynData) { return getXVal(self::$dynData, $key, $defVal); } else { ++self::$hitCount; if (self::$hitCount > 5) { self::preload(); return self::getV($x, $y, $defVal); } else { $row = SqlHelper::ormSelectOne( myself()->_getSelfMysql(), 't_dyndata', array( 'account_id' => myself()->_getAccountId(), 'x' => $x, 'y' => $y, ) ); return $row ? $row['val'] : $defVal; } } } public static function setV($x, $y, $defVal) { $key = self::calcKey($x, $y); self::internalSetV($x, $y, $defVal); } public static function incV($x, $y, $val) { $key = self::calcKey($x, $y); $oldVal = self::getV($x, $y); self::internalSetV($x, $y, $oldVal + $val); } public static function decV($x, $y, $val) { self::incV($x, $y, 0 - $val); } public static function calcKey($x, $y) { $low32 = (int)$x; $high32 = (int)$y; $key = $low32 + ($high32 << 32); return $key; } private static function internalSetV($x, $y, $val) { if (!is_int($x) || !is_int($y)) { die('internalSet type error'); return; } if (abs($x) > 0xFFFFFFFF) { die('internalSet x error'); return; } if (abs($y) > 0xFFFFFFFF) { die('internalSet y error'); return; } $key = self::calcKey($x, $y); SqlHelper::upsert (myself()->_getSelfMysql(), 't_dyndata', array( 'account_id' => myself()->_getAccountId(), 'x' => $x, 'y' => $y ), array( 'val' => $val, 'modifytime' => myself()->_getNowTime() ), array( 'account_id' => myself()->_getAccountId(), 'x' => $x, 'y' => $y, 'val' => $val, 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ) ); if (self::$dynData) { self::$dynData[$key] = $defVal; } } private static $dynData = null; private static $hitCount = 0; }