0

I need a clock which shows sped up time. That is, in that clock 100 milliseconds of real time = 1 minute in program clock or something like it.

Basically I want to simulate a football match. So I need a clock, which starts every time from 0 and runs to 90 minutes. but as 90 minutes in real world is too long, I need a sped up the clock.

Also I need to display the clock every time as it runs.

I am new to methods of seeding time from system and using functions like clock().

Matt Way
  • 32,319
  • 10
  • 79
  • 85
mohanagr
  • 1
  • 1
  • As a general note on simulation, the actual *simulation step* should be completely decoupled from the *visualization step* . in other words, there should always be the same number of simulation calculations done, regaurdless of how quickly/slowly you decide to show time to the user. Otherwise varying the 'length of the game' will drastically affect its outcome, which is not what you want assuming a non-interactive simulation. – aruisdante Jun 23 '14 at 14:32

1 Answers1

3

As noted in this answer, you can use a timer event to sleep a certain amount of time. You will need to map your sleep duration to real-world time, e.g., if your thread sleeps for 1 second, that represents 1 minute of play time.

Using this casting, you can ensure that 90 seconds of simulation time represents 90 minutes of gameplay.

Some pseudocode to get you started:

count = 1
interval = 1
max_time = 90
while true        
    if count++ == max_time
        break
    end

    perform_simulation_function()

    sleep interval
end
Community
  • 1
  • 1
Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47