Tracking time spent on the debugger

[[EDIT 2x] I think I didn’t formulate my original question correctly, so I removed it below and rewrote exactly what I am trying to get for future readers. ]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
[New, brilliant, clear question with better wording]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~

I have a loop that works for a simulation / game environment. This cycle has several places in it where it needs to find out how much time has passed - in fact - so that the logic in these special places - in particular, rendering and updating - can work correctly. It has the ability to be a fixed time step ( unfixed[update/render]is false) or not.

The problem arises when breakpoint-based debugging is performed at any point in the application, since it uses a stopwatch to determine how much has passed in real time (for the purpose of physical and animation moving at a realistic speed, and not based on how many frames the computer can pump out )

It looks something like this, using several stopwatch for each "part" of the application cycle, which should know how much time has passed since the last "part":

while ( RunningTheSimulation ) {
    /* ... Events and other fun awesome stuff */

    TimeSpan updatedifference = new TimeSpan( updatestopwatch.ElapsedTicks );

    if ( unfixedupdate || updatedifference > updateinterval ) {

        Time = new GameTime( updatedifference,
                                    new TimeSpan( gamestopwatch.ElapsedTicks ) );
        Update( Time );
        ++updatecount;
        updatestopwatch.Reset( );
        updatestopwatch.Start( );
    }

    TimeSpan renderdifference = new TimeSpan( renderstopwatch.ElapsedTicks );

    if ( unfixedrender || renderdifference > renderinterval ) {

        Time = new GameTime( renderdifference,
                                 new TimeSpan( gamestopwatch.ElapsedTicks ) );
        Render( Time );
        ++rendercount;
        renderstopwatch.Reset( );
        renderstopwatch.Start( );

    }
}   

Variable Information:

updatestopwatchis a Stopwatch for the time spent outside the Update () function,

renderstopwatchis a Stopwatch for time spent outside the Render () function, and

gamestopwatch - Stopwatch /.

. , , , , . Stopwatches : Update, Render , . , Update(), Render() , .

, , , , , , , , , . = [

, , , : Render Update ( ' , while), , PerformanceCounter.Increment() .

System.Diagnostics .NET, , "" , ...

- ?

[[EDITS 5x] , . . ]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[, ]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

, #, . , . , , - ( while (true) { ... }:

if ( unfixedupdate || updatedifference > updateinterval ) 
{
    Time = new GameTime( updatedifference, 
                        new TimeSpan( gamestopwatch.ElapsedTicks ) );
    Update( Time );
    ++updatecount;
    updatestopwatch.Reset( );
    updatestopwatch.Start( );
}

, - , . , , 17 updatestopwatch.Reset(), - , 1 - , .

- , , , ? , .NET # , , Visual Studio, .

[EDIT] , ( , ). Update() , , . , , Update() Render() Input() .. , Timing Timing ( GameTime, Upper, Render ...) , , 13 , 13 ( , ); , , 13 . , .

+5
2

. ( , ) .

+2

( , ) Debug.WriteLine().

0

All Articles