Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3
  ignore  |  Print  
  Game loops!  (Read 93143 times)
0 Members and 2 Guests are viewing this topic.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #30 - Posted 2012-03-05 23:49:19 »

It works in any circumstance. All drawing is one frame behind so that you can interpolate everything.

See my work:
OTC Software
Offline ra4king

JGO Kernel


Medals: 340
Projects: 2
Exp: 5 years


I'm the King!


« Reply #31 - Posted 2012-03-06 00:35:29 »

Wut?

Offline sproingie

JGO Kernel


Medals: 202



« Reply #32 - Posted 2012-03-06 00:37:33 »

Welcome to page 2, ra4king.

I really don't know why we even have article format.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 340
Projects: 2
Exp: 5 years


I'm the King!


« Reply #33 - Posted 2012-03-06 00:43:25 »

O___O I didn't notice that this was page two! I thought this a whole new article by some random n00b Tongue

Offline ManIkWeet

Senior Newbie





« Reply #34 - Posted 2012-03-06 10:49:35 »

If all drawing is one frame behind, don't you notice input lag?
Online Roquen
« Reply #35 - Posted 2012-03-06 15:39:38 »

I've only done a quick skim, but don't use floating point for digital counters.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #36 - Posted 2012-03-06 22:41:48 »

Which counter are you referring to? If it's the timer then it doesn't matter, any precision lost will be so minute.

See my work:
OTC Software
Offline ManIkWeet

Senior Newbie





« Reply #37 - Posted 2012-03-07 21:02:14 »

I have a new issue with the fixed timestep, it seems that for alot of computers the game is very choppy (game herz 30 with 60 fps)...
This happens on my desktop very rarely and I have a hard time finding the fix, anyone knowing about this?
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #38 - Posted 2012-03-07 23:01:54 »

Remove the Thread.sleep() call in there, and use Thread.yield() only.

See my work:
OTC Software
Offline ManIkWeet

Senior Newbie





« Reply #39 - Posted 2012-03-08 18:32:32 »

Didn't work, the weird thing is that when I print on render and tick, the output is:
tick
render
render
tick
render
render
tick...

So it should work, maybe there's a problem calculating the interpolation?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ManIkWeet

Senior Newbie





« Reply #40 - Posted 2012-03-08 20:42:42 »

This forums has serious issues with the EDIT button...

It's not the interpolation either
Online Roquen
« Reply #41 - Posted 2012-03-09 16:22:23 »

Quote
If it's the timer then it doesn't matter, any precision lost will be so minute.

Actually it can be very significant.  The lines I'm talking about are ones like these:

1  
double X = System.nanoTime();


Which when the counter get big will start to drop least sig bits (up to 11) of the input, which are the most important and keeps the high bits, which we don't really care about.
Offline ManIkWeet

Senior Newbie





« Reply #42 - Posted 2012-03-11 13:14:14 »

New update: when I unlimit the FPS, I still get choppy spikes, which means there's some sort of inprecision in the tick management...
Please investigate Cheesy
Offline ManIkWeet

Senior Newbie





« Reply #43 - Posted 2012-03-11 16:37:33 »

OR there's something wrong with canvas/bufferedstrategy...
OR interpolation still, but when printing that I see no differences
Online Roquen
« Reply #44 - Posted 2012-03-11 16:42:12 »

If you're printing all the time..well that takes forever in nanotime.

(EDIT) Unless your rendering the text yourself.  (not some outputstream kinda thing)
Offline ManIkWeet

Senior Newbie





« Reply #45 - Posted 2012-03-12 20:47:31 »

first calculating the interpolation, then System.out it
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #46 - Posted 2012-05-11 19:59:27 »

I added a pause button to the fixed timestep so you can test out catch-up behavior, and I also fixed a bug there (thanks roland for pointing it out) where the catchup was being calculated incorrectly.

See my work:
OTC Software
Offline wolfcall

Junior Newbie





« Reply #47 - Posted 2012-06-02 04:47:07 »

I just wanted to say thanks this is exactly what I needed for a project of mine.  Grin
Online Danny02
« Reply #48 - Posted 2012-06-02 12:06:16 »

just read this
Quote
Which counter are you referring to? If it's the timer then it doesn't matter, any precision lost will be so minute.

and got remembered to this
http://en.wikipedia.org/wiki/MIM-104_Patriot#Failure_at_Dhahran

so boys and girls, incrementing time with floating point numbers cost lives!!
Online Roquen
« Reply #49 - Posted 2012-06-02 13:30:18 »

I'm not sure if this is the failure in question...but I know that one problem early versions had was that the programmer didn't understand that 1/10 of a second (the logic rate it ran at) isn't a representable number.
Offline wolfcall

Junior Newbie





« Reply #50 - Posted 2012-06-02 23:36:00 »

I should say thanks again because this also fixed a second problem I didn't get to fix yet. so thanks twice over  Grin Grin
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #51 - Posted 2012-06-03 02:30:57 »

Nope, Danny, I think you're wrong. You're not keeping a running total added, you're keeping a total that is refreshed multiple times per second. So any lost precision is going to be completely impossible to notice. If you were adding the time every single frame to store the game time or something, I could see that being an issue. But in this case, no.

See my work:
OTC Software
Online Roquen
« Reply #52 - Posted 2012-06-03 12:30:21 »

You're both right in the context you're talking about.
Offline The Cure

Senior Newbie





« Reply #53 - Posted 2012-07-31 19:29:57 »

Quote from: Gingerious
So I noticed when I added 15 instead of 10 to the sleep on the variable timestep, it didn't error out on me.  Did it error out on anyone else?

The error was that the time to sleep was a negative value, but it look like it's only for the first time the loop runs.  Every time after that it's between 8 and 10.  Any ideas?

I think i solved that error just adding Math.abs(); to the Thread.sleep calculation (making the result be always positive):

1  
Thread.sleep(Math.abs(lastLoopTime - System.nanoTime()) / 1000000 + 10);


For now i didn't have any problems, but i really don't know if my solution is the correct one, and if it affects the logic behind the variable timestep loop. Maybe someone could tell me if i'm doing something stupid...


"A candle loses nothing by lighting another candle" - Erin Majors
Offline ra4king

JGO Kernel


Medals: 340
Projects: 2
Exp: 5 years


I'm the King!


« Reply #54 - Posted 2012-07-31 19:44:25 »

That's because it's supposed to be the other way around: System.nanoTime() - lastLoopTime. No need for Math.abs Wink

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #55 - Posted 2012-08-04 03:13:20 »

I don't think so. You're trying to wait for 10ms, and if the last loop time was slower than that you wait for less time. See Kev explain below.

From Kev's (since update) tutorial:

Quote
To do this we're going to want each cycle round the game loop to take exactly 10 milliseconds. We know at what time the cycle started (lastLoopTime) and we know what time it is now, so with a small amount of maths we can sleep for the right amount of time like this:

1  
2  
3  
4  
5  
// we want each frame to take 10 milliseconds, to do this
// we've recorded when we started the frame. We add 10 milliseconds
// to this and then factor in the current time to give
// us our final value to wait for
SystemTimer.sleep(lastLoopTime+10-SystemTimer.getTime());

Note: GAGE Timer actually supports a "sleepUntil()" method that could be used here. However, since the SystemTimer is trying to allow us to change between timing mechanisms we should try to rely on simply sleeping for the right amount of time.

The only difference is the division, that's because we're using nanoTime here and Kev is only using ms.

See my work:
OTC Software
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #56 - Posted 2012-08-04 03:17:32 »

Although actually the +10 should be there if we were shooting for 100 fps, and we're going for 60. I should change that to 16.

See my work:
OTC Software
Offline SHC
« Reply #57 - Posted 2012-11-03 02:26:55 »

Could you please say me what's GAME_HERTZ? Is it the required number of updates per second?

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #58 - Posted 2012-11-03 06:15:08 »

Correct. It's like FPS but in game updates, not frame updates.

See my work:
OTC Software
Offline KittenKoder

Senior Member


Medals: 7



« Reply #59 - Posted 2012-11-03 06:35:57 »

I can't believe your "bad" examples, I actually see people using them in full games as well. You'd think that with all the information out there which says "don't do it" or the throttling of your CPU would be enough. lol

I hope more people find this thread.

I am no one else.
Pages: 1 [2] 3
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (7 views)
2014-07-30 21:08:39

Riven (20 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (28 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!