So, I demoed my game on battery power.. and it sucked. Interestingly whenever windows showed a tooltip, the game ran at full pelt.. something fishy there.
But anyway, I introduced a Δt (delta t for the unicode (or greek) unaware) into my calculations.
The first stumbling block was that I was using the tick counter, which sucks a bit. The thing is, even though it has damn good accuracy, it is only updated every now and then. Which is a bit odd.
I managed to hack it into working by doing the following:
private void Physics()
{
while (System.DateTime.Now.Ticks == Tick) { }
//time interval
long thisTick = System.DateTime.Now.Ticks;
float dt = (Tick - thisTick) / 100000.0f;
Tick = thisTick;
But that really feels dirty. All that hanging around waiting for the tick. - Spoon!
So, anyways. After a bit of ferreting, I found the
Coding4Fun: Beginning Game Development article I'd been reading, which contains a section "All about timers". In summary, I grabbed the dxmutmisc.cs file from the sample code (in DirectX SDK\Samples\Managed\Common), commented out everything but NativeMethods and FrameworkTimer, called
FrameworkTimer.Start()
before starting the Main loop, then did
private void Physics()
{
dt = (float)(FrameworkTimer.GetElapsedTime()*1000);
to get the time interval since the last physics call. The *1000 is just to get the number into something I could count on my fingers-and-toes.
And, with a little tweaking of cosmological constants, all was working again.
Posted on Tuesday, May 01, 2007
by
Unknown
0 comments:
Post a Comment