Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  limiting FPS  (Read 2834 times)
0 Members and 1 Guest are viewing this topic.
Offline vrm

Junior Duke




where I should sign ?


« Posted 2003-02-21 15:19:00 »

there is a way for limit FPS ( to somthing like 50 ~ 60 FPS) for free some CPU (example : for network thread or gc) ?
Offline Chman

Junior Duke




Nothing more that... Java games are cool !


« Reply #1 - Posted 2003-02-21 18:25:40 »

I think the only way to limit FPS is to use Thread.sleep()....
Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2003-02-21 18:45:00 »

This snatch of code from Alien Flux is what I use:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
                        if (!GL.WGL_EXT_swap_control) {
                              float elapsed = 0.0f;
                              frameTime = 0.0f;
                              do {
                                    long now = Sys.getTime();
                                    elapsed = (float)(now - then) / (float)Sys.getTimerResolution();
                                    if (frameTime == 0.0f)
                                          frameTime = elapsed;
                                    if (elapsed < FRAME_TIME)
                                          Thread.sleep(1);
                              } while (elapsed < FRAME_TIME);
                              gl.swapBuffers();
                        } else {
                              long now = Sys.getTime();
                              frameTime = (float)(now - then) / (float)Sys.getTimerResolution();
                              gl.swapBuffers();
                        }


If it can't get WGL_EXT_swap_control I've found that doing loads of tiny sleeps is lighter on the CPU than a processor-hogging busy loop. Especially as I run at high priority.

Cas Smiley

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

Junior Duke




where I should sign ?


« Reply #3 - Posted 2003-02-22 07:18:21 »

trying that
BTW :
FRAME_TIME , got an advise on this value ?

what is the 'then' variable in your code ?
Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2003-02-22 08:48:58 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
/** How many frames per second we want */
public static final int DESIRED_FPS = 60;

/** The duration of one frame, in seconds */
public static final float FRAME_TIME = 1.0f / (float) DESIRED_FPS;

...

                        long then = Sys.getTime();

                        // Do drawing here

                        // Then cap frame rate as above here


Cas Smiley

Offline vrm

Junior Duke




where I should sign ?


« Reply #5 - Posted 2003-02-22 09:46:56 »


Thanks ! it works very well Grin

no more GC lags cause there is plenty free CPU times Smiley

btw about GC :
java -server -Xms512m -Xmx512m -XX:NewSize=64m -XX:MaxNewSize=64m -XX:SurvivorRatio=2 -XX:+UseConcMarkSweepGC

I tryed to use new 1.4.1 GC, it's really nice, reduce the GC lag effect

for reference: http://wireless.java.sun.com/midp/articles/garbagecollection2/#4.3
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.

Longarmx (41 views)
2014-10-17 03:59:02

Norakomi (33 views)
2014-10-16 15:22:06

Norakomi (26 views)
2014-10-16 15:20:20

lcass (30 views)
2014-10-15 16:18:58

TehJavaDev (59 views)
2014-10-14 00:39:48

TehJavaDev (60 views)
2014-10-14 00:35:47

TehJavaDev (50 views)
2014-10-14 00:32:37

BurntPizza (66 views)
2014-10-11 23:24:42

BurntPizza (38 views)
2014-10-11 23:10:45

BurntPizza (80 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!