Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Re: FPS too low or just normal? on: 2012-04-19 18:29:51
On top of that, even if you use vsync to lock a framerate, you may still want to have a different "update rate". I like to sample input device state more often than I update world state / rendering frame for example.

  That sounds interesting... what do you do that for? So you get more accurate response to your input? I've always been concerned about creating a "smooth flow" between your brain ordering your fingers to press a key and getting an immediate reaction in the game, I think it's one of the keys of making a good game... at least that's what I want games to feel like Smiley
2  Java Game APIs & Engines / Java 2D / Re: FPS too low or just normal? on: 2012-04-18 18:14:44
Well, yes, but I was wondering if maybe as I get more and more logic into the game will that mean that those 110 FPS will remain?

In the sleep I'm calculating the remaining msecs to get to those 10ms per loop, so with more update/drawing operations it'll just sleep for the rest of the msecs needed...
3  Java Game APIs & Engines / Java 2D / [SOLVED] FPS too low or just normal? on: 2012-04-18 18:06:05
Hi all!

  I've added some debug messages on my "little creature" to test FPS. I don't know if this is normal, but when I comment the "thread.sleep" part in my main loop I get about 8200 fps which I guess is not a bad signal... But, when I toggle Thread.sleep (10ms per iteration), it goes down to an average of 105-110 fps.

This is the code of the game main loop (thanks ra4king for your good advices!!):

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  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
public abstract class Game {

   ...blah blah blah...

   public final void run() {
     
      //debug:
     int currFPS = 0;
      int avgFPS = 0;
      double currTime = HiresTimer.getTime();
      graphics.setDrawColor(Color.white);  
           
      while ( gameRunning ) {
         
         deltaMsecs = HiresTimer.getTime() - lastLoopMsecs; //don't mind this.. it's used elsewhere
        lastLoopMsecs = HiresTimer.getTime();

         update();
         
         do {
           
            do {
               
               Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
               render();
               
               //debug: show fps
              graphics.drawText("FPS: " + avgFPS, 10, 10);
               
               g.dispose();
               
            } while ( strategy.contentsRestored() );

            strategy.show();
           
            try {
               //Take exactly (hopefully) 10ms per loop
              Thread.sleep( (long) lastLoopMsecs + 10 - (long) HiresTimer.getTime() );
            } catch (Exception e) {}
           
           
         } while ( strategy.contentsLost() );
         
         //debug:
        currFPS++;
         if ( HiresTimer.getTime() - currTime >= 1000 ) {
            avgFPS = currFPS;
            currFPS = 0;
            currTime = HiresTimer.getTime();
         }
      }      
   }


Right now I'm only drawing an animated sprite that moves and jumps depending on keyboard input and showing the fps message...

To me it looks that it should be more than just 110 FPS, but maybe that's normal... or maybe it's just a wrong FPS calculation method???

Thanks in advance for your comments!
4  Java Game APIs & Engines / Java 2D / Re: Rotational Collsion Detection on: 2012-04-17 14:44:53
I have a friend who made a game engine in Delphi and the other day he showed me how he deals with this type of collisions:

 On every frame he calculates a "bounding polygon" of the sprite and uses it as a sort of bounding box, checking if it overlaps with other sprites. The result was amazingly precise... You don't have to make a perfect silouette of the sprite for the sake of performance, but calculating the relevant points that cover the current frame and joining them would be enough. Maybe on Android it's too much calculation per frame, I don't know, but you could try that approach.
5  Java Game APIs & Engines / Java 2D / Re: About "Thread.sleep" on my main loop on: 2012-04-15 22:59:41
Thanks Tim! I'll check this when implementing the FPS control part
6  Java Game APIs & Engines / Java 2D / Re: About "Thread.sleep" on my main loop on: 2012-04-15 22:58:32
You're disposing of the resources that Graphics2D uses. While it's not absolutely necessary to dispose it, it wouldn't hurt to add that line in.

The problem with my "screen.dispose()" is that I initialized only once, when creating the instance, instead of doing it inside the loop as you do.
 
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
 do{
     do{
         Graphics2D g = (Graphics2D)strategy.getDrawGraphics();                
         render(g);
                   
         g.dispose();
     }while(strategy.contentsRestored());
               
  strategy.show();
  }while(strategy.contentsLost());


   That's why it didn't work and I commented it... and that's why I introduced "strategy.getDrawGraphics().dispose()" before doing strategy.show() without noticing that it has to be called before rendering. I'll have to change some things in my design because right now my Graphics class is separated from the rendering and "strategy" is out of the scope of the rendering loop

Anyway, I think it's time for some code refactoring... hehe  

Again, thanks for your replies, they're really helpful
7  Java Game APIs & Engines / Java 2D / Re: About "Thread.sleep" on my main loop on: 2012-04-15 22:10:52
Hi there! Thanks for your reply!

What is this "screen" object? Graphics2D? What exactly "doesn't work"? You're supposed to dispose of it after you're not done. Every time you call getDrawGraphics(), it gives you the Graphics2D object of another backbuffer, on that line "strategy.getDrawGraphics().dispose()", you're wasting a back buffer. Remove it!

  Sorry, my bad... that line was from an earlier version of the game, since this is the first time I'm using Java2D I didn't understand well why I had to call "dispose" so I did some tests... But anyway, I still don't get it. If I remove that line, when do I have to call dispose? Because now I've just commented it and everything works fine even if a don't call it anywhere else o_O... Does it mean that "show" takes care of swapping buffers automatically?

For the rest, thanks a lot for the tips on sleeping!! I'll try them
8  Java Game APIs & Engines / Java 2D / [SOLVED] About "Thread.sleep" on my main loop on: 2012-04-15 20:11:14
Hi everyone!

  I'm new here and finally I've decided to sign in because I found this is the best place to learn java gaming techniques!! I hope I can help others too...

Well, here's my question:

  I'm building a "mini-engine" for a tribute game to "Monty" (from the C64 versions of "Monty on the run" and "Auf wiedersehen Monty"), and recently I solved a problem I had with some tear effects or glitches (I don't know how to call it...) in my animation code. Basically what happened was that in my computer everything went smooth but when I ran the tests on my laptop I noticed this issues. I'm using page flipping and in my "flip" method I had this:

public class MyGraphicsClass implements MyGraphicsInterface() {

  ... some methods here

   public void flip() {
      //screen.dispose();   <-- doesn't work. once disposed it has to be retrieved again?
      strategy.getDrawGraphics().dispose();
      strategy.show();
      
      try {
         Thread.sleep(10);
      } catch (Exception e) {}

   }
}

Now, instead of sleeping for 10 ms I try to make the loop take exactly 10ms so I changed it to this:

      try {
         Thread.sleep( game.getLastLoopMsecs() + 10 - HiresTimer.getTime() );
      } catch (Exception e) {}


Is this a good solution? Or is it better to keep a constant sleep time to let the OS "breathe" for a while? As I said, with a fix value is not so smooth in my laptop (Dell XPS)

Besides, I thought that as the game grows, every loop will take more time and the sleep time will be less and I don't know if that's ok or bad Smiley

Btw, for now I'm using Sun's Perf class in my HiresTimer (Eventually I'll have to use another system I guess... but atm I'm interested in getting the basics done)

Oh, and another thing: I'm using UPS instead of FPS, should I change to FPS for better performance or is UPS ok?

9  Discussions / Miscellaneous Topics / Re: So I'm Doing This Research Paper... on: 2012-04-14 20:33:32
I think this might help... and it's from 2004, so imagine the situation now with better JVMs and faster CPU's

http://scribblethink.org/Computer/javaCbenchmark.html
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (27 views)
2014-09-07 01:11:22

Longarmx (26 views)
2014-09-07 01:10:19

mitcheeb (34 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!