<?php

include_once("internal/tracker.php");
include_once("internal/log.php");

// --------------------------------------------

class AutoSaver extends Tracker {
	protected $metagame = NULL;

	protected $AUTOSAVE_TIME = 300.0;
	protected $autosave_timer = 0.0;

	// --------------------------------------------
	function __construct($metagame) {
		$this->metagame = $metagame;

		$this->autosave_timer = $this->AUTOSAVE_TIME;
	}
	
	// --------------------------------------------
	public function update($time) {
		$this->autosave_timer -= $time;
		if ($this->autosave_timer < 0.0) {
			_log("autosaving");
			$this->metagame->save();
			$this->autosave_timer = $this->AUTOSAVE_TIME;
		}
	}

	// --------------------------------------------
	function has_ended() {
			// always on
			return false;
	}

	// --------------------------------------------
	function has_started() {
			// always on
			return true;
	}

}


?>