OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4TimeMilliseconds Class Reference

#include <C4TimeMilliseconds.h>

Public Types

enum  Infinity { NegativeInfinity = -1, NoInfinity = 0, PositiveInfinity = 1 }
 

Public Member Functions

 C4TimeMilliseconds ()=default
 
 C4TimeMilliseconds (uint32_t millis)
 
 C4TimeMilliseconds (C4TimeMilliseconds::Infinity infinity)
 
 C4TimeMilliseconds (const C4TimeMilliseconds &rhs)=default
 
 ~C4TimeMilliseconds ()=default
 
uint32_t AsInt () const
 
bool IsInfinite () const
 
StdCopyStrBuf AsString () const
 
C4TimeMillisecondsoperator= (const C4TimeMilliseconds &rhs)
 
C4TimeMillisecondsoperator-= (const uint32_t &rhs)
 
C4TimeMillisecondsoperator+= (const uint32_t &rhs)
 

Static Public Member Functions

static C4TimeMilliseconds Now ()
 

Friends

bool operator== (const C4TimeMilliseconds &lhs, const C4TimeMilliseconds &rhs)
 
bool operator< (const C4TimeMilliseconds &lhs, const C4TimeMilliseconds &rhs)
 
int32_t operator- (const C4TimeMilliseconds &lhs, const C4TimeMilliseconds &rhs)
 

Detailed Description

Definition at line 34 of file C4TimeMilliseconds.h.

Member Enumeration Documentation

Enumerator
NegativeInfinity 
NoInfinity 
PositiveInfinity 

Definition at line 37 of file C4TimeMilliseconds.h.

Constructor & Destructor Documentation

C4TimeMilliseconds::C4TimeMilliseconds ( )
default

Referenced by Now().

Here is the caller graph for this function:

C4TimeMilliseconds::C4TimeMilliseconds ( uint32_t  millis)
inline

Definition at line 53 of file C4TimeMilliseconds.h.

53 : time(millis) { }
C4TimeMilliseconds::C4TimeMilliseconds ( C4TimeMilliseconds::Infinity  infinity)
inline

Definition at line 54 of file C4TimeMilliseconds.h.

54 : inf(infinity) { }
C4TimeMilliseconds::C4TimeMilliseconds ( const C4TimeMilliseconds rhs)
default
C4TimeMilliseconds::~C4TimeMilliseconds ( )
default

Member Function Documentation

uint32_t C4TimeMilliseconds::AsInt ( ) const
inline

Definition at line 60 of file C4TimeMilliseconds.h.

Referenced by C4ScriptShader::Add(), C4PacketPing::CompileFunc(), and C4ScriptShader::Remove().

60 { return time; }

Here is the caller graph for this function:

StdCopyStrBuf C4TimeMilliseconds::AsString ( ) const

Definition at line 57 of file C4TimeMilliseconds.cpp.

References StdStrBuf::Format(), NegativeInfinity, and PositiveInfinity.

58 {
59  if (inf == PositiveInfinity)
60  {
61  return StdCopyStrBuf("POSITIVE INFINITY");
62  }
63  if (inf == NegativeInfinity)
64  {
65  return StdCopyStrBuf("NEGATIVE INFINITY");
66  }
67  StdCopyStrBuf string;
68  string.Format("%u:%02u:%02u:%03u:",time / 1000 / 60 / 60, (time / 1000 / 60) % 60, (time / 1000) % 60, time % 1000);
69  return StdCopyStrBuf(string);
70 }
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174

Here is the call graph for this function:

bool C4TimeMilliseconds::IsInfinite ( ) const
inline

Definition at line 63 of file C4TimeMilliseconds.h.

References NoInfinity.

Referenced by C4GameControlNetwork::CalcPerformance(), C4Network2::Execute(), and C4NetIOUDP::GetNextTick().

Here is the caller graph for this function:

C4TimeMilliseconds C4TimeMilliseconds::Now ( )
static

Definition at line 39 of file C4TimeMilliseconds.cpp.

References C4TimeMilliseconds().

Referenced by C4ScriptShader::Add(), C4NetIOUDP::Peer::Check(), CStdTimerProc::CheckAndReset(), C4GameControlNetwork::CheckCompleteCtrl(), C4SoundInstance::CheckStart(), C4NetIOUDP::Peer::CheckTimeout(), C4SoundInstance::Create(), C4FoWAmbient::CreateFromLandscape(), C4GUI::Edit::DeleteSelection(), C4NetIOUDP::DoCheck(), C4GUI::WoodenLabel::DrawElement(), C4GUI::Edit::DrawElement(), C4GUI::Tabular::DrawElement(), C4MusicSystem::Execute(), C4GameControlNetwork::Execute(), C4ApplicationGameTimer::Execute(), C4Network2IO::Execute(), C4Network2HTTPClient::Execute(), C4PlayerControl::Execute(), C4NetIOUDP::Execute(), StdSchedulerProc::ExecuteUntil(), C4MusicSystem::FadeOut(), C4GraphicsSystem::FinishDrawing(), C4Network2IOConnection::getLag(), C4Network2HTTPClient::GetNextTick(), C4PacketPing::getTravelTime(), C4Network2IO::HandlePacket(), C4GameControlNetwork::Init(), C4Network2IO::Init(), C4Shader::Init(), C4NetIOUDP::Init(), C4GUI::Edit::InsertText(), C4PlayerControlAssignment::IsComboMatched(), C4GUI::CMouse::IsMouseStill(), MyCBClass::OnConn(), C4Network2IO::OnConn(), C4Network2IO::OnDisconn(), C4GUI::Edit::OnGetFocus(), MyCBClass::OnPacket(), C4Network2IO::OnPacket(), C4Network2IOConnection::OnPing(), C4GameControlNetwork::PackCompleteCtrl(), C4MusicSystem::Play(), C4InteractiveThread::PushEvent(), C4Network2HTTPClient::Query(), C4Shader::Refresh(), C4ScriptShader::Remove(), C4Network2::RequestActivate(), C4GUI::CMouse::ResetToolTipTime(), C4Network2::RetrieveRes(), C4AbstractApp::Run(), StdScheduler::ScheduleProcs(), C4MusicSystem::ScheduleWaitTime(), C4Network2IOConnection::SetPingTime(), C4MusicSystem::SetPlayList(), C4NetIOUDP::Peer::SetTimeout(), C4Stat::Start(), C4ShaderCall::Start(), C4AulExec::StartDirectExec(), C4GraphicsSystem::StartDrawing(), C4Stat::Stop(), and C4AulExec::StopDirectExec().

40 {
41 #ifdef __APPLE__
42  static time_t sec_offset;
43  timeval tv;
44  gettimeofday(&tv, 0);
45  if (!sec_offset) sec_offset = tv.tv_sec;
46  return C4TimeMilliseconds((tv.tv_sec - sec_offset) * 1000 + tv.tv_usec / 1000);
47 #else
48  timespec tv;
49  clock_gettime(CLOCK_MONOTONIC, &tv);
50  static time_t sec_offset = tv.tv_sec;
51  return C4TimeMilliseconds((tv.tv_sec - sec_offset) * 1000 + tv.tv_nsec / 1000000);
52 #endif
53 }
C4TimeMilliseconds()=default

Here is the call graph for this function:

Here is the caller graph for this function:

C4TimeMilliseconds& C4TimeMilliseconds::operator+= ( const uint32_t &  rhs)
inline

Definition at line 70 of file C4TimeMilliseconds.h.

70 { time += rhs; return *this; }
C4TimeMilliseconds& C4TimeMilliseconds::operator-= ( const uint32_t &  rhs)
inline

Definition at line 69 of file C4TimeMilliseconds.h.

69 { time -= rhs; return *this; }
C4TimeMilliseconds & C4TimeMilliseconds::operator= ( const C4TimeMilliseconds rhs)
default

Friends And Related Function Documentation

int32_t operator- ( const C4TimeMilliseconds lhs,
const C4TimeMilliseconds rhs 
)
friend

Definition at line 90 of file C4TimeMilliseconds.cpp.

91 {
92  // if infinity is set, nothing else than infinity matters (infinity + 100 == infinity)
93  if (lhs.inf != C4TimeMilliseconds::NoInfinity ||
95  {
96  int infinityTo = lhs.inf - rhs.inf;
97 
98  if (infinityTo < 0) return std::numeric_limits<int32_t>::min();
99  if (infinityTo > 0) return std::numeric_limits<int32_t>::max();
100  return 0;
101  }
102  // otherwise, as usual
103  return int32_t(lhs.time - rhs.time);
104 }
bool operator< ( const C4TimeMilliseconds lhs,
const C4TimeMilliseconds rhs 
)
friend

Definition at line 80 of file C4TimeMilliseconds.cpp.

81 {
82  if (lhs.inf != C4TimeMilliseconds::NoInfinity ||
84  {
85  return lhs.inf < rhs.inf;
86  }
87  return int32_t(lhs.time - rhs.time) < 0;
88 }
bool operator== ( const C4TimeMilliseconds lhs,
const C4TimeMilliseconds rhs 
)
friend

Definition at line 74 of file C4TimeMilliseconds.cpp.

75 {
76  return lhs.inf == rhs.inf &&
77  lhs.time == rhs.time;
78 }

The documentation for this class was generated from the following files: