Archived

This topic is now archived and is closed to further replies.

Date Time - FPU - DirectX

This topic is 4952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i ran into a bug dealing with date time. I usealy just use the build in functions in (pascal) called 'Date' and 'Time', both functions simply encodes the windows.GetLocalTime into a Double. So to get the current system time you just Add 'Date' + 'Time'. This works just fine, BUT after making a call to D3D9.CreateDevice , the result of 'Date' + 'Time' is ALLWAYS the same ??? This is the "fun" part (ex) : Be4 calling CreateDevice the Date is : 05-19-2004 00:00:00 After calling CreateDevice the Date is : 05-18-2004 23:59:19 The result from Time is correct, both be4 and after the call. Anyone have an idea of what the bug is ? (I asume that c/c++ have simular functions for dealing with date/time) [edited by - Mythar on May 25, 2004 3:01:22 PM]

Share this post


Link to post
Share on other sites
Not sure if this is related but Direct3D resets the precision flag on creation, so you may find you are using single precision instead of double. To fix this there is a flag you can set to get Direct3D to not set single precision.

Share this post


Link to post
Share on other sites
I found that flag, you need to set it in the behaviour flags when creating the device. It is D3DCREATE_FPU_PRESERVE. I am pretty sure this is why your problem is occuring. From the DX help file:

D3DCREATE_FPU_PRESERVE - Indicates that the application needs either double-precision floating-point unit (FPU) or FPU exceptions enabled. Direct3D sets the FPU state each time it is called.
By default, the pipeline uses single precision. Be sure to use this flag to get double precision. Setting the flag will reduce Direct3D performance

Share this post


Link to post
Share on other sites
Thx that fixed the bug

Dose reduce performance, so i guess i need to rewrite the pascal
functions, into using non-floating point values.

Oh the joy of working in DX...

Share this post


Link to post
Share on other sites
I did some more research about the FPU and came up with this :

Insted of rewriting the pascal DateTime functions and not setting the D3DCREATE_FPU_PRESERVE flag, i came up with another way of doing it.

while DirectX running :

DoDirectXStuff;

Set8087CW($1332); - Enable Double-precision

... do calcs that needs Double

Set8087CW($133f); - Disable all fpu exceptions

DoMoreDirectXStuff;


This sems to work fine, I do lose about 10 frames per sec.

Question is now ; is $133f - the correct value to set, according to DirectX single-precision ?

Share this post


Link to post
Share on other sites
This may not be what you want to hear, but calling a Date/Time function every frame doesn''t seem to make sense.

If you''re using it for some sort of timing, then there has to be a way for you to access better timers (even GetTickCount would be far superior).


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
I do need the date / time functions, as the 'time' controls day/night enviroment in game.

It functions something like this :

When a server is first created, a TimeNull and TimeStart is saved on the server ex :

TimeNull : RL time, 19-12-2003 20:37:00
TimeStart : Game time, 01-01-0204 00:00:00
ServerSync : RL time, 'now'

When a client logs in he resives these 3 values from the server,
and uses them to adjust the in Game Time like this :
GameTime = TimeStart+((TimeNull+(TimeSync+(LocalTime)))*10);

TimeSync = LocalTime - ServerSync.
LocalTime = RL time, windows.GetLocalTime

This meens that it dose not matter were in the 'RL' world the
player is, the GameTime will allways be the same.
So if a player is in Rome,NewYork,Russia ; they will all have eighter a day or night enviorment.

It also meens that even if the server is offline, the GameTime keeps moving on.

Hope this makes any sence to you



[edited by - Mythar on May 26, 2004 1:16:00 PM]

Share this post


Link to post
Share on other sites