Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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 2110 times)
0 Members and 1 Guest are viewing this topic.
Offline vrm

Junior Member




where I should sign ?


« Posted 2003-02-21 16: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 Member




Nothing more that... Java games are cool !


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

I think the only way to limit FPS is to use Thread.sleep()....
Online princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #2 - Posted 2003-02-21 19: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 Member




where I should sign ?


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

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

what is the 'then' variable in your code ?
Online princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #4 - Posted 2003-02-22 09: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 Member




where I should sign ?


« Reply #5 - Posted 2003-02-22 10: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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (102 views)
2013-05-17 21:29:12

alaslipknot (112 views)
2013-05-16 21:24:48

gouessej (140 views)
2013-05-16 00:53:38

gouessej (136 views)
2013-05-16 00:17:58

theagentd (147 views)
2013-05-15 15:01:13

theagentd (133 views)
2013-05-15 15:00:54

StreetDoggy (176 views)
2013-05-14 15:56:26

kutucuk (198 views)
2013-05-12 17:10:36

kutucuk (200 views)
2013-05-12 15:36:09

UnluckyDevil (206 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.174 seconds with 21 queries.