View Single Post
  #45  
Old 10-18-2011, 05:04 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Quote:
I did not try using Stopwatch() yet. Is it a part of C# or CloD only?
Stopwatch is part of the .Net-Framework, it provides the most accurate time measurement. So it's very usefull if you need accurate timing.
you need to include the namespace System.Diagnostics for usage.

For the query time can be for example (MissionTimer1 is the stop watch)
MissionTimer1.Elapsed.Days
MissionTimer1.Elapsed.Hours
MissionTimer1.Elapsed.Minutes
MissionTimer1.Elapsed.Seconds
MissionTimer1.Elapsed.Milliseconds
MissionTimer1.Elapsed.Ticks
MissionTimer1.Elapsed.TotalDays
MissionTimer1.Elapsed.TotalHours
MissionTimer1.Elapsed.TotalMinutes
MissionTimer1.Elapsed.TotalSeconds
MissionTimer1.Elapsed.TotalMilliseconds

There is a difference between for example Minutes and TotalMinutes etc.:
MissionTimer1.Elapsed.Minutes has e.g. the range -59 to 59 minutes, only indicates the minute proportion of the total time. at 2h 43m 12s would be the 43rd
MissionTimer1.Elapsed.TotalMinutes provides e.g. the total number of minutes since launch. 2h 43m 12s min at 163.12 then.


Methods
MissionTimer1.Start () / / Starts the timer
MissionTimer1.Stop () / / Pauses the timer can be resume with Start ()
MissionTimer1.Restart () / / Starts the timer at 0 newly
MissionTimer1.Reset () / / Resets the timer to 0 and stops the time measurement
MissionTimer1.IsRunning / / bool indicates whether the timer is running (true) or not (false)

Quote:
Can it be used inside the onTickGame method only or in any other method as well?
Its depend not on OnTickGame.
You can for example measure the time between two events etc.
You need to declare a Stopwatch global and start it once, normaly OnBattleStarted(). Then you can use it in every way you like.

Quote:
If it is placed inside the onTickGame method won't the "if" statement checked every tick, i.e. 30 times a second?
Yes, but this is no problem, normaly.
Don't know whats faster, a modulo calculation or a simple stopwatch request. But stopwatch is much more accurate.

Last edited by FG28_Kodiak; 10-18-2011 at 05:09 AM.
Reply With Quote