mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Core/Cleanup
* try to give included files a logical structure * move objects from Util and Game to their own files * make non-essential files auto-loaded
This commit is contained in:
39
includes/setup/timer.class.php
Normal file
39
includes/setup/timer.class.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Aowow;
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('illegal access');
|
||||
|
||||
|
||||
class Timer
|
||||
{
|
||||
private $t_cur = 0;
|
||||
private $t_new = 0;
|
||||
private $intv = 0;
|
||||
|
||||
public function __construct(int $intervall)
|
||||
{
|
||||
$this->intv = $intervall / 1000; // in msec
|
||||
$this->t_cur = microtime(true);
|
||||
}
|
||||
|
||||
public function update() : bool
|
||||
{
|
||||
$this->t_new = microtime(true);
|
||||
if ($this->t_new > $this->t_cur + $this->intv)
|
||||
{
|
||||
$this->t_cur = $this->t_cur + $this->intv;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function reset() : void
|
||||
{
|
||||
$this->t_cur = microtime(true) - $this->intv;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user