Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In my project, I call nanoTime and use that to get a deltaTime which I pass to my entities and animations.

However, while debugging (for example, stepping through my code), the system time on my phone is happily chugging along, so it's impossible to look at, say, two sequential frames of data in the debugger (since by the time I'm done looking at the first frame, the system time has continued to move ahead by seconds or even minutes).

Is there a programming practice or method to pause the system clock (or a way for my code to intercept and fake my deltaTime) whenever I pause execution from the debugger?

Additional Information:

  • I'm using Eclipse Classic with the ADT plugin and a Samsung SII, coding in Java.
  • My code invoking nanoTime: http://pastebin.com/0ZciyBtN
  • I do all display via a Canvas object (2D sprites and animations).
share|improve this question
    
A friend mentioned manually editing the deltaTime in the debugger before I pass it to the rest of my game in the next frame. If I could detect that the debugger is attached, I could set the deltaTime to an artificial amount each frame if I'm debugging. –  TheMaster42 Sep 6 '12 at 0:29
add comment

1 Answer 1

up vote 4 down vote accepted

Instead of grabbing the system time and calculating the delta time each frame, just keep the delta frame time constant in the debug build (deltaTime is just always 16ms, for example). This way each simulation frame has a fixed time step regardless of how much debugging you did in between frames. Of course this should only be done in your debug build.

share|improve this answer
1  
You could modify that technique slightly and say each frame has a maximum delta time (33ms, perhaps). By doing this, you will lose time, but you will never gain time. –  stephelton Sep 6 '12 at 2:27
    
Is there a way to make this automatically change in my debug build, as opposed to changing a "global" variable each time I switch between Debug/Run? –  TheMaster42 Sep 6 '12 at 9:27
    
As far as I know Java doesn't have support for conditional build statements (like #ifdef), but then again I'm not a Java developer. You could always ask that on StackOverflow.com and get a real answer. –  SomeWritesReserved Sep 6 '12 at 13:14
    
This apparently is a real terror... stackoverflow.com/questions/12296762/… –  TheMaster42 Sep 6 '12 at 20:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.