Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (682)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (750)
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 3608 times)
0 Members and 1 Guest are viewing this topic.
Offline vrm

Junior Devvie




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 Devvie




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 Spiffy Duke »


Medals: 782
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 Devvie




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 Spiffy Duke »


Medals: 782
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 Devvie




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.

 
orrenravid (146 views)
2016-07-16 03:57:23

theagentd (215 views)
2016-07-11 14:28:54

Hydroque (298 views)
2016-07-06 05:56:57

Hydroque (446 views)
2016-07-03 08:52:54

GrandCastle (333 views)
2016-07-01 09:13:47

GrandCastle (325 views)
2016-07-01 09:09:45

CopyableCougar4 (381 views)
2016-06-25 16:56:52

Hydroque (366 views)
2016-06-22 02:17:53

SwampChicken (333 views)
2016-06-20 13:22:57

SwampChicken (287 views)
2016-06-20 13:22:49
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17
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!