1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
/******************************************************************************
* Warmux is a convivial mass murder game.
* Copyright (C) 2001-2011 Warmux Team.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
******************************************************************************
* Handle the game time. The game can be paused.
*****************************************************************************/
#ifndef TIME_H
#define TIME_H
#include <string>
#include <WARMUX_base.h>
#include <WARMUX_singleton.h>
#include "game/stopwatch.h"
// XXX uint wrap-around (or at least system timer) not handled
class GameTime : public Singleton<GameTime>
{
private:
Stopwatch stopwatch;
bool waiting_for_network;
bool waiting_for_user;
uint current_time;
uint delta_t;
Stopwatch network_wait_time_stopwatch;
protected:
friend class Singleton<GameTime>;
GameTime();
public:
void Reset();
uint Read() const { return current_time; }
uint ReadSec() const { return Read() / 1000; }
uint ReadMin() const { return ReadSec() / 60; }
void SetPause(bool pause) { stopwatch.SetPause(pause); }
bool IsPaused() const { return stopwatch.IsPaused(); }
void SetSpeed(const Double& speed);
const Double& GetSpeed() const { return stopwatch.GetSpeed(); }
void Increase();
bool CanBeIncreased() const { return stopwatch.GetValue() >= current_time; }
bool CanDraw() const { return stopwatch.GetValue()<current_time+20 || IsWaiting(); }
void LetRealTimePassUntilFrameEnd();
void Resynch() { stopwatch.Resynch(current_time); }
bool IsWaiting() const { return waiting_for_user || waiting_for_network; }
bool IsWaitingForUser() const { return waiting_for_user; }
void SetWaitingForUser(bool value);
bool IsWaitingForNetwork() const { return waiting_for_network; }
void SetWaitingForNetwork(bool value);
uint GetMSWaitingForNetwork();
uint GetDelta() const { return delta_t; };
// Read the clock time
uint ClockSec() const { return ReadSec() % 60; };
uint ClockMin() const { return ReadMin() % 60; };
std::string GetString() const;
};
#endif
|