PDA

View Full Version : function Now()



jansoft
24-01-2005, 08:04 AM
when I want to measure some timing, i used function Now() and I was surprised, that it returns always same value !

Instead of, I used GetTickCount() and It works.
How it is possible ?

Traveler
24-01-2005, 08:42 AM
The function now() returns the current date and time. It shouldn't return always the same value, unless you check it every millisecond.

GetTickCount() is much better, asuming you're using it for your gameloop and sprite movements.

jansoft
24-01-2005, 09:03 AM
I was calling the function in AsphyreTimer.OnRender event.
Simple drawing current time to screen and it doesn't changed !
Maybe there is something wrong with my computer...

LP
24-01-2005, 12:44 PM
Now value should be changed every second (based on manual, that's its precision). However, GetTickCount() might not be that precise also, for timing applications you should consider using QueryPerformanceCounter (as an example, check TAsphyreTimer source code).

jansoft
25-01-2005, 09:40 AM
I do some exploration of the problem and result is, that if i am using Direct3D renderer, value of Now() DOES NOT CHANGE, if used any else renderer, it is OK and value DOES CHANGE. Try this with plasma demo - i added one marked line:

procedure TMainForm.TimerRender(Sender: TObject);
var
i, j: Integer;
begin
with PowerDraw.Device do
begin
Clear($FFFF0000);
BeginScene();

for j:= 0 to (PowerDraw.Height div 256) do
for i:= 0 to (PowerDraw.Width div 256) do
RenderEffect(Images[0], (i * 256), (j * 256), 0, effectNone);

Fonts[0].TextOut('FPS: ' + IntToStr(Timer.FrameRate), 4, 4, $FFFFFFFF, effectNone);
{added line} Fonts[0].TextOut('Time: ' + FormatDateTime('HH:MM:SS.ZZZ', Now()), 4, 40, $FFFFFFFF, effectNone);

EndScene();
Present();
end;
end;


second mystery is, that on my computer in Direct3D mode minutes are 3 minutes sooner than right time (and of course doesnt change) :?:

Finch
26-01-2005, 03:49 PM
Notify that function Now() returns time AND date (help says "Now returns the current date and time, corresponding to Date + Time"), so if you try to convert it to HH:MM:SS value, convert error comes up. Result is clear - value which is rendered on screen is still same (beacause of date included in outcome Double value). To avoid that, use only Time() function to get current time, or Date() to get current date, or Now() to get time and date together.
I hope that I explained it cleary. If I didn't, I'm sorry ;)

jansoft
26-01-2005, 04:30 PM
I dont understand, why convert error may occur when PowerDraw is switched into Direct3D mode and NOT when it is switched to Software mode.
Now() returns TDateTime, it can be converted by function FormatDateTime, i dont see any problem in this....

Finch
26-01-2005, 04:57 PM
I dont understand, why convert error may occur when PowerDraw is switched into Direct3D mode and NOT when it is switched to Software mode.
Now() returns TDateTime, it can be converted by function FormatDateTime, i dont see any problem in this....
Yes, it is strange, but when I used Time instead of now, it worked :?

jansoft
27-01-2005, 02:55 PM
It seems that problem is somewhere in adding
time and date part.
I was trying this part of code:

var
ttt:Double=0;
procedure TMainForm.DoIt;
var
t4:Double;
begin
ttt:=ttt+1/10000;
t4:=10000000+ttt;
end;
{...call this procedure from AsphyreTimer.OnRender...}

and again, in Direct3D value of t4 is "jumping", in Software mode its OK.

My favorite victim is some flag of FPU is set to some wrong value
(MMX instructions are sharing registers of FPU, so maybe it is a problem; but my home PC has no MMX and problem is there also)

Lifepower should know more ? :roll: