Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
158 user(s) are online (140 user(s) are browsing Forums)

Members: 0
Guests: 158

more...

Support us!

Headlines

 
  Register To Post  

need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
Trying to port some nasty demo, source of which i got from the authors, and while i already remove Cocoa and Fmod parts (replaced it by SDL/OpenGl/Sdl_mixer), i have stuck a bit on such lame/little fucntion:

Quote:

AbsoluteTime gStartTime;

static int timeGetTime (void)
{
float deltaTime = (float) AbsoluteDeltaToDuration (UpTime(), gStartTime);

if(deltaTime<0)deltaTime*=-1;

return deltaTime;
}


Need something which will works on OS4, and will return the same "float deltaTime" as expected.

Thanks for.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
@kas1e

if (deltaTime// if negative microseconds
deltaTime /= -1000000.0;
else 
// else milliseconds
deltaTime /= 1000.0;


I found this on the net...

So all you need to do now is to calculate the float value from struct TimeVal

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
@LiveForIt

I suck with all of this, working function will be awesome :) Maybe it possible just get current system time by some aos4/posix function, then again and delta = starttime - endtime , or kind of.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
@kas1e


Maybe this.. works

float TimeVal_to_float(struct TimeVal *tm)
{
    
float ret;

    if (
tm -> Seconds)
    {
        
ret tm -> Seconds 1000;
    }
    else
    {
        
ret tm -> Microseconds * -1000;
    }
    
    return 
ret;
}

float_to_TimeVal(float value,struct TimeVal *tm)
{
    
int micro;

    if (
value// if negative microseconds
    
{
        
tm -> Microseconds value / -1000;
    }
    else
    {
        
tm -> Microseconds value;
        
tm -> Seconds value 1000;
    }
}

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
@LiveForIt

Maybe, but i need it exactly like that (to avoid any other changes in code):
Quote:

static int timeGetTime (void)
{
float deltaTime;
...everything_here...
return deltaTime;
}


I do something like this some time ago, but completely forget how i do it , and where is these sources :(

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
@kas1e

Timer.device has this commands.

AddTime
SubTime
CmpTime
GetUpTime

You should be able to implement some kind of AbsoluteDeltaToDuration() function from this, if you combine it whit the TimeVal_to_float() and float_to_TimeVal() functions.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: need some help to rewrite little, macos based, timer function
Quite a regular
Quite a regular


See User information
@kas1e

It would be easy if only we knew what the original is supposed to do. Is it returning the current time, the time since the system was turned on, or what?

cheers
tony
Go to top
Re: need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
@tonyw

Quote:

It would be easy if only we knew what the original is supposed to do. Is it returning the current time, the time since the system was turned on, or what?


That function should calculate FPS (and return a Float value)

That what i found in net (in the macos docs).

Uptime() and AbsoluteTime data structure

Quote:

The function UpTime() returns the amount of elapsed time since the computer started up. It returns the elapsed time in an AbsoluteTime data structure, which is a 64-bit integer. You can’t directly do anything with the AbsoluteTime data structure. You must use one of the two conversion functions Apple supplies. The first function is AbsoluteToDuration(), which tells you the number of milliseconds (1000 milliseconds = 1 second) that elapsed since the computer was turned on. The advantage of using the Duration data structure is that the structure is a 32-bit integer. You don’t have to convert it to a double. For games millisecond accuracy is usually sufficient.


AbsoluteDeltaToDuration

Quote:

Subtracts one absolute time from another and returns the difference as a duration value.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: need some help to rewrite little, macos based, timer function
Quite a regular
Quite a regular


See User information
@kas1e

Is the "gStartTime" initialised somewhere? When the program starts, perhaps? Or is it merely loaded with zero and counted as an "UpTime"?

Do you really need a result in FPS, or is it something you will calculate later?

If you just want a result that is the UpTime(), that is easily read from ITimer->GetUpTime(). But you have to open the Timer device beforehand. I can give you some example code if you like, but you'll have to call an Init function when your program starts (and before timeGetTime() is called).

cheers
tony
Go to top
Re: need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
@tonyw

gStartTime initialized only for that fucntion, like i show in first post:

AbsoluteTime gStartTime;

(where AbsoluteTime its just data structure, but cant found what exactly it have inside, its in core sources of macos).

Quote:

Do you really need a result in FPS, or is it something you will calculate later?

Its not that i need it very much, its just done like that in the demo (not my), which heavy based on it. So, i just should rewrite it to aos4, to make return float DeltaTime (ie the same input, the same output, but different inside, just to make it works the same by logic). Because rewiritng the whole demo timing-fps-part related (which done not by me) its much harder if just rewrite one function.

As i point in the first port, its just static int fucntion, without any input, its just calcualte FPS speed, and then, return Float value (deltaTime), which are used by whole demo in all the effects.

Quote:

If you just want a result that is the UpTime(), that is easily read from ITimer->GetUpTime(). But you have to open the Timer device beforehand. I can give you some example code if you like, but you'll have to call an Init function when your program starts (and before timeGetTime() is called).


All what i need its just working replacement fucntion, just because a trying to works on other project right now, and will be cool, if someone can just write me ready-to-use fucntion, which have no input (static void), and return float DeltaTime. Which i can just put inside the code, and recompile the demo. I can of course start to read documenations, docs, ask on other forums, but that will take time (which i can spend on more important aos4-related stuff), and for sure will be better if someone who know about all of this already, can just write ready-to-insert function.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
@kas1e

You can define AbsoluteTime as

#ifdef __AMIGAOS4__
typedef struct TimeVal  AbsoluteTime;
#endif


This will also make it easier for you to use AmigaOS timer.device functions.

Quote:
if someone can just write me ready-to-use fucntion


What's the fun in that.


Edited by LiveForIt on 2010/10/21 20:10:44
Edited by LiveForIt on 2010/10/21 20:11:28
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: need some help to rewrite little, macos based, timer function
Home away from home
Home away from home


See User information
@LiveForIt

There is code which give me Alain Thellier:

Quote:

ULONG gStartTime; //global
ULONG StartTime=0;

ULONG LibMilliTimer(void)
{
struct timeval tv;
ULONG MilliFrequence1=1000;
ULONG MilliFrequence2=1000000/MilliFrequence1;
ULONG MilliTime;

GetSysTime(&tv);
if(StartTime==0) StartTime=tv.tv_secs;
MilliTime = (tv.tv_secs-StartTime) * MilliFrequence1 + tv.tv_micro/MilliFrequence2;
return(MilliTime);
}


float timeGetTime (void)
{
ULONG MilliTime;
float deltaTime;

MilliTime=LibMilliTimer();
deltaTime=(float) (MilliTime - gStartTime);
gStartTime= MilliTime;
deltaTime=1000.0*deltaTime; /convert to seconds*/
return(deltaTime);
}


Looks like its what i need it for (imho)

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project