私はDirectXベースのアプリケーションを持っています。そして、最近私は、Now()
関数は、私のグラフィックスエンジンのメインループ内から呼び出されたときに間違った値を返すことを発見しました。これは、エンジンが初期化される前に呼び出される1つの値と、グラフィックスが開始されたときにアプリケーションで呼び出されるときに異なる値(通常、2-3分前または前に異なる)を与えます。Delphi Now()関数が間違った値を返します
私は、Now()
関数がWindows API GetLocalTime()
関数のラッパーであることがわかりました。誰でも、この非常に機能の戻り値に影響を与える可能性があることを指摘できますか?私は頻繁に私のアプリのメインループでtimeGetTime()
機能を使用して、それは問題の原因になることができますか?また、メインループでCheckSyncronize()
機能を使用する必要があります...
アイデア?今
procedure Td2dCore.System_Run;
var
l_Msg: TMsg;
l_Point: TPoint;
l_Rect : TRect;
l_Finish: Boolean;
begin
if f_WHandle = 0 then
begin
System_Log('Engine was not started!');
Exit;
end;
if not Assigned(f_OnFrame) then
begin
System_Log('Frame function is not assigned!');
Exit;
end;
// MAIN LOOP
l_Finish := False;
while not l_Finish do
begin
// dispatch messages
if PeekMessage(l_Msg, 0, 0, 0, PM_REMOVE) then
begin
if l_Msg.message = WM_QUIT then
l_Finish := True;
DispatchMessage(l_Msg);
Continue;
end;
GetCursorPos(l_Point);
GetClientRect(f_WHandle, l_Rect);
MapWindowPoints(f_WHandle, 0, l_Rect, 2);
f_MouseOver := f_MouseCaptured or (PtInRect(l_Rect, l_Point) and (WindowFromPoint(l_Point) = f_WHandle));
if f_Active or f_DontSuspend then
begin
repeat
f_DeltaTicks := timeGetTime - f_Time0;
if f_DeltaTicks <= f_FixedDelta then
Sleep(1);
until f_DeltaTicks > f_FixedDelta;
//if f_DeltaTicks >= f_FixedDelta then
begin
f_DeltaTime := f_DeltaTicks/1000.0;
// if delay was too big, count it as if where was no delay
// (return from suspended state for instance)
if f_DeltaTime > 0.2 then
if f_FixedDelta > 0 then
f_DeltaTime := f_FixedDelta/1000.0
else
f_DeltaTime := 0.01;
f_Time := f_Time + f_DeltaTime;
f_Time0 := timeGetTime;
if(f_Time0 - f_Time0FPS < 1000) then
Inc(f_FPSCount)
else
begin
f_FPS := f_FPSCount;
f_FPSCount := 0;
f_Time0FPS := f_Time0;
end;
f_OnFrame(f_DeltaTime, l_Finish);
if Assigned(f_OnRender) then
f_OnRender();
ClearQueue;
{
if (not f_Windowed) and (f_FixedFPS = D2D_FPS_VSYNC) then
Sleep(1);
}
end;
{
else
if (f_FixedDelta > 0) and (f_DeltaTicks+3 < f_FixedDelta) then
Sleep(1);
}
end
else
Sleep(1);
CheckSynchronize;
end;
end;
()f_OnFrame()
機能のどこかに呼ばれ
それはすべてのマシン上で不正な動作をしていますか?小さなサンプルプログラムでこれを再現できますか? –
はい。実際に私はこのエラーをバグレポートとして受け取りました。私は小さなプログラムを作ることができると思うが、それは私のグラフィックエンジンのリンクを含むだろう... –
私はトップメッセージにメインループコードを掲示しました。 –