Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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  
  Active FPS counter  (Read 2569 times)
0 Members and 1 Guest are viewing this topic.
Offline DarkMortar

Junior Devvie




Java Padawan


« Posted 2007-01-24 02:45:10 »

Hey, I currently use an FPS counter that works pretty good, yet I want a more active fps counter. You see a basic fps counter seems to only update you with the fps every second, but i want it to tell you per frame or something, like how fraps is an active counter etc, or kevGlass 2d physics demo has active fps counter. So how do i get a cool fps counter?

Offline ravenger

Senior Newbie





« Reply #1 - Posted 2007-01-26 11:06:53 »

i think the most easy way is to time how long a frame lasted, and then translate it into fps. For example, if you have a frame which lasted 10ms, thats would be 100 frames per second.  Wink
Offline Kova

Senior Devvie





« Reply #2 - Posted 2007-01-26 16:49:05 »

note that you must use some kind of arithmetic middle calculation (sorry don't know how math term is called in english) to show on the screen, or you would show every frame different number and that would be unreadable. I think best solution is to update FPS number like 5 times a second but based on arithmetic middle of last ~20 values.

EDIT: oh yeah I agree with ravenger: this_frame_fps = 1000 \ (game_update_time + render_time + sleep_time)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline woogley
« Reply #3 - Posted 2007-01-26 18:01:49 »

note that you must use some kind of arithmetic middle calculation (sorry don't know how math term is called in english)

I think you mean "average" .. just for the next time you're looking for the word Smiley
Offline Kova

Senior Devvie





« Reply #4 - Posted 2007-01-26 18:36:31 »

Sorry for OT.

I think you mean "average" .. just for the next time you're looking for the word Smiley

Thank you. I could say "average of last 20 values" but I wanted to use mathematical term that is more precise Smiley Here we have a mathematical term for that, literal translation would be "arithmetic middle". Let's say X is set of numbers you chose, then you would say "arithmetic middle of X".
Offline woogley
« Reply #5 - Posted 2007-01-26 18:42:56 »

only thing I can think of is "mean" which is pretty much synonymous with "average" .. I cant think of any other clever words. ah well, at least we know what you meant Wink

edit: or.. "median"! or.. it doesn't matter. ignore me. Tongue
Offline darkprophet

Senior Devvie




Go Go Gadget Arms


« Reply #6 - Posted 2007-01-26 23:21:12 »

median is different from the mean which is different from the mode.

Mean was the correct word Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline DarkMortar

Junior Devvie




Java Padawan


« Reply #7 - Posted 2007-01-30 01:48:08 »

I feel like an idiot, the counter is off, i use Fraps to verify, before it seemed accuate, it was past 1k fps, and frap said 999, but now fraps still says 999, and my program says like 700-800 fps. So somethings wrong. For now i am updating it once a second, but i think my currentFramefps is wrong:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
if (lastFpsTime >= oneNanoSecond) {
            fpsWrite = fps;  // this integer will be drawn with the "Fps: " string
            lastFpsTime = 0; // resets delta modifyer
            fps = 0;         // fps count reset
         }

//later... the end of  game loop
if (fpsFrameCount>=19) {
           
            for (int i = 0; i <= 19; i++) {
               totalFps += fpsLog[i];
            }
            fps = (int) (totalFps/20);
            totalFps = 0;
            fpsFrameCount=0;
         }
         
         currentFrameFps = (afterTime-startTime)/1000;
         
         fpsLog[fpsFrameCount] = currentFrameFps;
         
         //System.out.println("Fps: " + fps);
         fpsFrameCount++;


i was logging 20 numbers, and finding the mean, i print it on the counter the average every second. Well its wrong! Help!



Offline Kova

Senior Devvie





« Reply #8 - Posted 2007-01-30 23:45:07 »

I don't understand what exactly are you trying in your code, but here's how I wrote it:

fps variable is the one you print on the screen

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
while (running) {        
    long start_time = System.nanoTime();
           
    gameUpdate();
    gameRender();
    paintScreen();
    sleep();
           
    used_time = (System.nanoTime() - start_time) / 1000000;
    if (used_time > 0)
        fps_store[j] = (int)(1000/used_time);
    else
        fps_store[j] = 999;
     j++;
     fps = 0;
     for (int fps1: fps_store) {
         fps += fps1;
    }
    fps /= fps_store.length;
    if (j > fps_store.length-1) j=0;
}

Offline DarkMortar

Junior Devvie




Java Padawan


« Reply #9 - Posted 2007-01-31 00:25:13 »

I have never, ever seen a for-loop like this, and i cant get it to work:

for (int fps1: fps_store) {
         fps += fps1;
    }

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

Junior Devvie




Java Padawan


« Reply #10 - Posted 2007-01-31 00:38:47 »

nvm, i had to make the fpsl; a type long, because my logs are using long data type. i think its working, it says 999 max, so i think ill just say what the fps is instead.

but what if i want the fps to say something over 999? I need accuracy to see if i loose loop performance.

EDIT: its also giving me strange values like 500 straight sometimes, and sometimes it says 1k exact, when it 'shouldnt' also it onlu updates per second.
under lower fps, the counter is quite accurate with the fraps one, but when u go above 999 its destroyed and says 1k and its messed up, i donno! sometimes it says lower fps like 600 when its really 999 on fraps.

Offline DarkMortar

Junior Devvie




Java Padawan


« Reply #11 - Posted 2007-01-31 01:16:35 »

Ok, i think it works great now, i did it like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
currentFrameFps = (System.nanoTime()-startTime);
         
         if (currentFrameFps > 0) {
            fpsLog[fpsFrameCount] = (int) (1000000000/currentFrameFps);
         }
         else {
            fpsLog[fpsFrameCount] = 0;
         }
         fpsFrameCount++;
         fps = 0;
         for (long fps1: fpsLog) {
            fps += fps1;
          }
         fps /= fpsLog.length;
         if (fpsFrameCount >= fpsLog.length) { fpsFrameCount=0; }


it doesnt limit at 999, because i dont cap fps with sleep in my game. It seems accurate, along with fraps, deadly accurate it is now. I divided it up differently, and if u see any possible bugs let me know!

Offline Kova

Senior Devvie





« Reply #12 - Posted 2007-01-31 23:52:56 »

it doesnt limit at 999, because i dont cap fps with sleep in my game. It seems accurate, along with fraps, deadly accurate it is now. I divided it up differently, and if u see any possible bugs let me know!

not actually a bug, but if you don't cap it to 999 then that else isn't neccessary anymore, no loop will end in less then one ns and even if it does it shouldn't store zero as a value:

1  
2  
3  
    else {
        fpsLog[fpsFrameCount] = 0;
    }
Offline DarkMortar

Junior Devvie




Java Padawan


« Reply #13 - Posted 2007-02-01 03:28:40 »

fixed Smiley

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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!