I'm using a modified version of LockFPS and it only ever works properly while I'm stepping through the code.. as soon as I remove the break points, it stop working properly.
[pascal]{$OPTIMIZATION OFF}
function TSDLTicks.LockFPS(targetFPS: Byte): single;
var
currentTime : UInt32;
TargetTime : UInt32;
begin
if (targetFPS = 0) then
targetFPS := 1;
// delay to maintain a constant frame rate
currentTime :=SDL_GetTicks();
if currentTime >m_FrameStartTime then
begin
TargetTime := m_FrameStartTime + (targetFPS *m_ticksPerSecond ) ;
while true do
begin
currentTime :=SDL_GetTicks();
if m_FrameStartTime - currentTime = 0 then
begin
SDL_Delay(1);
end;
if (currentTime<m_FrameStartTime) then
begin
result := 1;
Break;
end;
result := currentTime / m_ticksPerSecond;
if (TargetTime < currentTime) then
begin
result := 2;
Break;
end;
end;
end;
m_FrameStartTime := currentTime;
result := 0;
end;[/pascal]
I've been working on this all bloody day and I can't get it to work.
FrameStartTime is set at the beginning of each cycle by calling a funciton on the class containing the LockFPS function.
The LockFPS function is called at the end to eat up any spare CPU cycles and keep the game running at 30fps.
I don't know WTF is happening and why it works perfectly when I step through, yet as soon as I remove the breakpoint and continue, it never exits the loop.
I thought perhaps it was an optimization issue so I put the Optimization Off directive at the top of the unit and then at the top of the function, but it doesn't make any difference.
This is also a problem when this is compiled using FPC.
Any clues?
Bookmarks