Gorgon Game Engine
Timer.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <sstream>
6 
7 #include "../Time.h"
8 
9 namespace Gorgon { namespace Time {
10 
32  class Timer {
33  friend std::ostream &operator <<(std::ostream &output, const Timer &timer);
34  public:
35 
40  Timer(unsigned passed=0) : passed(passed) {
41  lasttick=GetTime();
42  }
43 
46  void Start() {
47  lasttick=GetTime();
48  }
49 
54  Timer &Tick() {
55  unsigned current=GetTime();
56 
57  passed+=current-lasttick;
58  lasttick=current;
59 
60  return *this;
61  }
62 
66  unsigned Get() const {
67  return passed;
68  }
69 
71  void Set(unsigned passed) {
72  this->passed=passed;
73  lasttick=GetTime();
74  }
75 
79  operator unsigned() const {
80  return passed;
81  }
82 
84  void Reset() {
85  Set(0);
86  }
87 
94  void ShowDialog(const std::string &name ="Time passed",
95  const std::string &title="Performance timer") const;
96 
97  private:
98  unsigned lasttick;
99  unsigned passed;
100  };
101 
103  inline std::ostream &operator <<(std::ostream &output, const Timer &timer) {
104  output<<timer.Get();
105 
106  return output;
107  }
108 
109 } }
Gorgon::Time::Date::AddMonths
void AddMonths(int months)
Adds specified amount of months to the date.
Definition: Time.cpp:359
Gorgon::Time::Timer::Get
unsigned Get() const
Returns total time passed.
Definition: Timer.h:66
Gorgon::Time::Date::Saturday
@ Saturday
Definition: Time.h:36
Gorgon::Time::totm
tm totm(const Date &d)
Definition: Time.cpp:20
Gorgon::Time::Timer::Tick
Timer & Tick()
Counts the time since the last Start, Tick, Set, Reset or from the contruction of the timer and adds ...
Definition: Timer.h:54
Gorgon::Time::internal::framestart
unsigned long framestart
Definition: Time.cpp:406
Gorgon::Time::Date::ISODate
std::string ISODate() const
ISO compliant date format. Contains only date.
Definition: Time.cpp:147
Gorgon::Time::GetTime
unsigned long GetTime()
Returns current time in milliseconds.
Definition: Linux.cpp:34
Gorgon::Time::Date::WeekdayType
WeekdayType
Days of week. Starts from sunday.
Definition: Time.h:29
Gorgon::Time::Date::ShortWeekdayName_En
const std::string & ShortWeekdayName_En() const
Returns currently stored week day's int name in English.
Definition: Time.cpp:233
Gorgon::Time::operator<<
std::ostream & operator<<(std::ostream &out, const Date &date)
Output stream operator overload.
Definition: Time.h:228
Gorgon::Time::internal::deltatime
unsigned long deltatime
Definition: Time.cpp:407
Gorgon::Time::Date::operator-
double operator-(const Date &other)
Gives the difference between two dates.
Definition: Time.cpp:332
Gorgon::Time::Timer::Set
void Set(unsigned passed)
Changes the passed time. Adjusts starting time of the timer.
Definition: Timer.h:71
Gorgon::Time::Date::LocalTimezone
static int LocalTimezone()
Returns the system timezone in minutes. Might be negative.
Definition: Time.cpp:306
Gorgon::Time::Date::Millisecond
unsigned int Millisecond
This value is from the last second tick.
Definition: Time.h:220
Gorgon::Time::Date::Hour
unsigned int Hour
Hour in 24 hour format.
Definition: Time.h:211
Gorgon::Time::Date::ShortTime
std::string ShortTime() const
Returns stored time in hour:minute format.
Definition: Time.cpp:274
Gorgon::Time::Date::ShortMonthName_En
const std::string & ShortMonthName_En() const
Returns currently stored month's int name in English.
Definition: Time.cpp:202
Gorgon::Time::Date::Minute
unsigned int Minute
Minute.
Definition: Time.h:214
Timer.h
contains timer
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Time::Date::Load
bool Load(std::istream &source)
Loads date object from a binary stream.
Definition: Time.cpp:83
Gorgon::Time::Date::Month
MonthType Month
Month starts from jan = 1.
Definition: Time.h:202
Gorgon::Time::Date::Save
bool Save(std::ostream &target)
Writes date object to a binary stream.
Definition: Time.cpp:112
Gorgon::String::Trim
std::string Trim(std::string str, const std::string &chars=" \t\n\r")
Strips whitespace around the given string both from start and end.
Definition: String.h:370
Gorgon::Time::Date::Dec
@ Dec
Definition: Time.h:53
Gorgon::Time::Date::ISODateTime
std::string ISODateTime(bool timezone=true) const
ISO compliant date/time. This format should be used to serialize as text.
Definition: Time.cpp:160
Gorgon::Time::Date::ShortDate_En
std::string ShortDate_En() const
Returns stored date in day intmonthname year format with English names for month.
Definition: Time.cpp:256
Gorgon::Time::Timer::ShowDialog
void ShowDialog(const std::string &name="Time passed", const std::string &title="Performance timer") const
Shows a UI dialog displaying the amount of time passed.
Definition: Time.cpp:410
Gorgon::Time::Date::Timezone_GMT
std::string Timezone_GMT() const
Returns stored timezone.
Definition: Time.cpp:284
Gorgon::Time::Date::Day
unsigned int Day
Day in month.
Definition: Time.h:205
Gorgon::Time::Date::MonthType
MonthType
Months, january is 1.
Definition: Time.h:40
Gorgon::Time::Date::Timezone
int Timezone
Timezone in minutes, can be negative.
Definition: Time.h:224
Gorgon::Time::Timer::Start
void Start()
Starts the timer from this instant.
Definition: Timer.h:46
Gorgon::Time::Timer
Millisecond based timer.
Definition: Timer.h:32
Gorgon::Time::Date::Parse
bool Parse(std::string isodate)
Creates a new date object from the given ISO-8601 date string.
Definition: Time.cpp:44
Gorgon::Time::Date
This class represents a specific date including time information.
Definition: Time.h:26
Gorgon::Byte
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
Gorgon::Time::Date::AddSeconds
void AddSeconds(int seconds)
Adds specified amount of seconds to the date.
Definition: Time.cpp:395
Gorgon::Time::Date::Weekday
WeekdayType Weekday
Day of the week, starts from sunday = 0.
Definition: Time.h:208
Gorgon::Time::fromtm
void fromtm(Date &ret, tm timeinfo)
Definition: Time.cpp:34
Gorgon::Time::Date::Time
std::string Time() const
Returns stored time in hour:minute:second format.
Definition: Time.cpp:264
Gorgon::Time::Date::Second
unsigned int Second
Second.
Definition: Time.h:217
Gorgon::Time::Timer::Timer
Timer(unsigned passed=0)
Default constructor.
Definition: Timer.h:40
Gorgon::Time::Timer::operator<<
friend std::ostream & operator<<(std::ostream &output, const Timer &timer)
Allows Timer to be printed.
Definition: Timer.h:103
Gorgon::Time::Initialize
void Initialize()
Initializes Time module.
Definition: Time.cpp:15
Gorgon::Time::Timer::Reset
void Reset()
Resets the passed time. Adjusts starting time of the timer.
Definition: Timer.h:84
Gorgon::Time::Date::WeekdayName_En
const std::string & WeekdayName_En() const
Returns currently stored week day's name in English.
Definition: Time.cpp:219
Gorgon::Time::Date::AddDays
void AddDays(int days)
Adds specified amount of days to the date.
Definition: Time.cpp:368
Gorgon::Time::Date::DetermineWeekday
bool DetermineWeekday()
Determines the weekday from the stored date.
Definition: Time.cpp:319
Gorgon::Time::Date::MonthName_En
const std::string & MonthName_En() const
Returns currently stored month's name in English.
Definition: Time.cpp:185
Gorgon::Time::Date::operator==
bool operator==(const Date &other) const
Compares 2 dates.
Definition: Time.cpp:341
Gorgon::Time::Date::AddYears
void AddYears(int years)
Adds specified amount of years to the date.
Definition: Time.cpp:350
Gorgon::Time::Date::Date_En
std::string Date_En() const
Returns stored date in day monthname year, weekday format with English names for month and weekday.
Definition: Time.cpp:247
Gorgon::Time::Date::Year
unsigned int Year
Full year.
Definition: Time.h:199
Gorgon::Time::Date::AddHours
void AddHours(int hours)
Adds specified amount of hours to the date.
Definition: Time.cpp:377
Gorgon::Time::Date::AddMinutes
void AddMinutes(int minutes)
Adds specified amount of minutes to the date.
Definition: Time.cpp:386