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]
  ignore  |  Print  
  How should I change my GameLoop?  (Read 1853 times)
0 Members and 1 Guest are viewing this topic.
Offline SHC
« Posted 2012-09-30 04:50:06 »

I've got a serious issue with my GameLoop. This loop varies in time with the platform and with the same hardware. This is a list of FPS achieved.

  • Windows          ======= 140 to 150
  • Linux               ======= 120 to 125
  • Windows(WINE) ======= 125 to 135
And since my game loop is fixed timestep, the speed of the game is not stable. Here's my GameLoop.

[size=15pt]GameLoop[/size]

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
public final void run(){
    // Initialize the resources
   Map.initMap();
    initResources();
    // Start the timer
   GTimer.startTimer();
    GTimer.refresh();
    long elapsedTime = 0;
    // The game loop
   while (running) {
        // Update the game
       update(elapsedTime);
        if (state == GameState.GAME_PLAYING) {
            Map.updateObjects(elapsedTime);
        }
        // Show or hide the cursor
       if (Global.HIDE_CURSOR) {
            setCursor(GInput.INVISIBLE_CURSOR);
        } else {
            setCursor(Cursor.getDefaultCursor());
        }
        // Repaint the game and sync
       repaint();
        elapsedTime = GTimer.sync();
        Toolkit.getDefaultToolkit().sync();
    }
}


Here are the two classes of the timer package.

https://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/timer/GTimer.java
https://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/timer/GFrameRateCalculator.java

How could I improve it?

Offline ReBirth
« Reply #1 - Posted 2012-09-30 04:54:16 »

It's really common to have different FPS results on many OSes.

Offline SHC
« Reply #2 - Posted 2012-09-30 04:56:07 »

But the game speed is not consistant. On windows it's much faster...

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-09-30 05:02:31 »

How about cap/limit the FPS to certain value, like 30 or 60? I always do this for quick solution (when you're on jam/compo) and only have time to test on windows. I never hear problem from linux users by this.

Offline Phased
« Reply #4 - Posted 2012-09-30 05:06:31 »

I agree just cap at 60, human eye can't see any more frames then 30-40 so 60 will always appear to be smooth.
Offline SHC
« Reply #5 - Posted 2012-09-30 05:19:22 »

Could anybody show an example?

Offline ReBirth
« Reply #6 - Posted 2012-09-30 05:26:02 »

Your GTimer.sync() should already do it, but I can't find place where you set the desired number.

Offline SHC
« Reply #7 - Posted 2012-09-30 05:28:24 »

See this class https://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/core/Global.java

Offline ReBirth
« Reply #8 - Posted 2012-09-30 05:33:01 »

I never use those classes before, but it looks like you just need to specify the time. For 60fps I think it'll be 1000/FPS = 1000/60 = 16.67 ~ 16ms.

Offline theagentd
« Reply #9 - Posted 2012-09-30 17:22:14 »

I never use those classes before, but it looks like you just need to specify the time. For 60fps I think it'll be 1000/FPS = 1000/60 = 16.67 ~ 16ms.
inb4 my game is stuttering because it's running at 62 FPS on a 60 hertz monitor.

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

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #10 - Posted 2012-10-01 23:37:14 »

The human eye can see many more frames than 60 per second...it's the timings of the screens that cap it at 60, 75 or 120Hz to ensure a smooth experience. It's more like 2500fps for the human eye, although we don't process all of them.

- Jonas
Offline sproingie

JGO Kernel


Medals: 202



« Reply #11 - Posted 2012-10-02 21:05:08 »

The eye processes pretty much continuously, and its ability to distinguish discrete events ranges, depending on light conditions, the type of stimulus, and physical and mental state.  It's just that 60fps just happens to be good enough most of the time for the sort of motion commonly rendered on a computer screen.  It's not really based on any advanced study of perception, it's just good enough.  Do a fast pan with high contrast on a 50" screen without any motion blur and you'll still ruin the illusion with a big trail of distinct after-images.

Now the job of the brain is to smooth out all the data from the eye, and it really does some amazing things.  Google "stopped clock illusion" sometime for one really mind-bendy example -- your perception of time itself is largely a trick your brain is pulling on you.
Offline theagentd
« Reply #12 - Posted 2012-10-02 21:07:03 »

You got me wrong. People were using an old flawed version of Display.sync() to sync to 60 FPS, but since it rounded the wait time it synced to 62 FPS, and people saw that as "stuttering" when one frame was dropped two or three times a second. This in turn spawned a huge thread with people trying to fix all kinds of stuttering using Java magic and rituals in a futile attempt to make the graphics pipeline that is OpenGL not behave like a graphics pipeline.

Myomyomyo.
Offline georgek

Junior Newbie





« Reply #13 - Posted 2012-10-03 06:24:53 »

The OPer might want to read up on stuff here,

http://www.koonsolo.com/news/dewitters-gameloop/

It explains things well IMO.
Pages: [1]
  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.

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

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

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

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

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

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

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

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

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
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!