The simulation time is an abstract time used in important parts of the Massiv Core (event scheduling, RPC) and it can be used also by a programmer. It has nothing to do with a real time. When new simulation is started, the simulation time (also called "the massiv time") is simply zero. When the simulation is started from an archive, the simulation time is set to the time stored in the archive.
The simulation time is a decimal number that expresses number of seconds elapsed since the moment when a simulation was started. In the actual implementation, the precision of the simulation time is in miliseconds. Example: simulation time 130.435 means 130 second and 435 miliseconds since the simulation start.
To obtain the actual simulation time, call Massiv::System::time() method. Important fact is that the simulation time doesn't change during one Massiv tick. Thus calling a method above more times during one tick will return the same value of simulation time.
The aim is that the simulation time should be "as fast as" the real time. This means when one hour elapses measured in the real time, one hour (3600.000 seconds) elapses in the simulation time. However, the hardware clock of computers will run a little differently. The simulation time is computed on the basis of the hardware clock, so a simulation time synchronization is needed among Massiv servers, and clients' simulation time must be adapted to according to the synchronized simulation time. This solution leads to the fact that the simulation time is not "as fast as" real time, but "as fast as" the fastest hardware clock among massiv serves.
The class Massiv::Core::TimeManager manages the time synchronization.
Sometimes a programmer needs to have an access to the operating system time to be able to measure time with a high accuracy. Call method Massiv::System::system_time() to get an actual value of the system time - this value is a decimal number with the same meaning as simulation time. The following example shows a typical use of the system time:
SystemTime old_time = Massiv::System::system_time(); while( Massiv::System::system_time() - old_time < 0.020f ) ) // 20ms { // do some work within 20ms } |
![]() | Note |
---|---|
Unlike the simulation time, the value of the system time changes during one massiv tick. |