This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.

I have a doubt about the period rate, I buy a book Killer programming game in java and I don´t understanding about the period what value i have in period in this formula - Sleeptime = period - timediff - oversleeptime, I know the value of sleeptime, i know the value about the timediff and i know the value of oversleeptime, but i don´t have the value of period, how can i found this value - i know the period is the same fps in ms.

you say you know the value of three of the four. Basic algebra lets you find the last. At 'T' and O to both sides:

S + T + O= P - T + T- O + O

S + T + O = P.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Fernando hiar
Greenhorn

Joined: Jan 11, 2008
Posts: 29

posted

0

I know this formula, but this book put a condition if sleeptime > 0 so the timediff took a longer time , how can i say if the sleeptime is negative if i don´t know the period : sleeptime = period - timediff - oversleeptime. I don´t know the value of period, how can i know sleeptime become negative?

maybe i'm just not understanding what you're asking... but...

S = P - T - O

is the same as

S = P - (T+O)

From here, it should be easy to see that S will be negative if (T+O) is greater than P.

Now, if you only have one equation with four variables, you CAN'T solve it if you only know the value of 2 of them. You have to have at least one equation for each unknown variable.

Fernando hiar
Greenhorn

Joined: Jan 11, 2008
Posts: 29

posted

0

So.....
Are you trying to ask me is when sleeptime > or < 0 the program knows the value of period period = sleeptime + timediff + oversleeptime or the program knows if timediff take a long time the sleeptime becomes negative even don´t know the value of period? It is i want to know I understood what you teaching me, but still stay this doubt.

Fernando, You'll get your answer a lot faster if you posted a small piece of code so we can see exactly where the problem is. I'm still having a hard time figuring out what variables you know the value of, which ones you don't, and what the problem is exactly. Please post some code and put a comment in as to where you should be getting a value that you can't seem to get.

Sleeptime = period - timediff - oversleeptime, I know the value of sleeptime, i know the value about the timediff and i know the value of oversleeptime, but i don´t have the value of period

I took this to mean you have this formula:

Sleeptime = period - timediff - oversleeptime

You then said you "know the value of sleeptime", and that you "know the value of oversleeptime".

I'm not sure what you mean by you "know the value about the timediff" - it's that word 'about' that is confusing. do you know the value of timediff or not?

If you DO know it, getting the value of period is trivial.

If you DO NOT know it, you CAN'T get the value of period without more information.

Fernando hiar
Greenhorn

Joined: Jan 11, 2008
Posts: 29

posted

0

I want to know one thing, if i have the value of all variables less one the period sleeptime = period - timediff - oversleeptime, the jvm can get the period value and use this value and each cycle???