Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (756)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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: Subclassing Graphics Class : Possible ? on: 2003-07-28 15:03:52
I think it is pretty clear that when we try to measure the performance of an application in terms of speed of execution, there are a lot of errors generated by the probing method we are using to get the data. This is a basis of performance analysis.

I think that the problem I am experiencing is not in that area : the problem seems to be related to the high amount of short life object created (mainly Rectangles) periodically. I am only talking about memory usage, and not speed of execution (even though any excessive temporary object allocation will lead to high GC).

2  Java Game APIs & Engines / Java 2D / Re: Subclassing Graphics Class : Possible ? on: 2003-07-28 14:34:14

I have around 50 leds flashing on my screen.

As you can see on the OptimizeIT graph, the GC activity is pretty high and you can see the memory usage growing up and down in a periodic manner.


So, the main problem seems to be the high amount of Rectangle creation, followed by a high GC activity.

Does anyone have seen this kind of excessive Rectangle object creation before ?


3  Java Game APIs & Engines / Java 2D / Re: Subclassing Graphics Class : Possible ? on: 2003-07-28 12:26:16

Thanks for your answer !

I am using jdk1.3.1 under Windows 2000 with a Pentium 2.4ghz with 1gig Ram.

My application is a 2D equipment simulator composed of switches, toggles and leds. All my components are based on a generic class that is a JPanel on which I can draw back images. All the components are placed in a layered fashion and the top component window is a JFrame.

The memory problem I have was reported by the OptimizeIt profiler during a repaint operation where many leds (50) were flashing at the same time. It looks like the sunGraphics2D.transformShape() method is the one allocating the most Rectangles, followed by the graphics.hitclip() method (the overall Rectangle object allocation is around 2 megs/sec !) .

OptimizeIt screeenshot:

So, my question is, there must be a way to limit the amount of Rectangle generated by the repaint operation ?

PS : I also tried to subclass the Graphics class, and I clearly saw that it was not meant to be subclassed because a lot of the double buffering mechanism was bypassed.

4  Java Game APIs & Engines / Java 2D / Subclassing Graphics Class : Possible ? on: 2003-07-25 10:48:11

While looking for memory leaks in my application using a profiler, I just find out that the Graphics class was one of the problem !

The methods Graphics.hitClip() and Graphics.getClipBounds(r) are creating a huge amount of Rectangle objects. These methods are called from the paintchildren() of JComponent.

The distressing part is the comment I found in the Graphics class source code in the hitClip() method :

public boolean hitClip(int x, int y, int width, int height) 
   // Note, this implementation is not very efficient.
   // Subclasses should override this method and calculate
   // the results more directly.
   Rectangle clipRect = getClipBounds();
   if (clipRect == null) {
        return true;
   return clipRect.intersects(x, y, width, height);

How do we subclass the Graphics class ?

The only information I found so far was the following class hierarchy :

  • public java.lang.Object
  • public abstract java.awt.Graphics
  • public abstract java.awt.Graphics2D
  • public abstract sun.java2d.SunGraphics2D
  • public

There are way too many abstract methods to implement in the Graphics class...

My Goal is to optimize the Graphics class for less Rectangle object creation ? Any ideas ?


5  Game Development / Performance Tuning / Swing Frame Rate / Custom RepaintManager on: 2003-07-23 12:02:02

I am writing a visual 2d equipment simulator using jdk1.3.1 under windows 2000.

I use Swing and AWT as renderer because I take advantage of the Design Time builder (bean box) to allow a fast and easy construction of simulations.

The simulations are mainly composed of reusable objects. The base class for all objects is a custom panel (JPanel) on which Images can be drawn.

Here are my questions :

1) When there are a lot of animation on screen (lets say many led objects that flashes), the memory usage of the simulation grows very fast.
I have pin pointed the problem with a Profiler (OptimizeIT) and I have discovered that the paintChildren() method of JComponent creates a lot of RECTANGLE objects to calculate the cliping area.
Is there a way to control that ?

2)  I have tried to create my own RepaintManager by subclassing the RepaintManager class. I have managed to catch all repaint() calls in the application, and force a repaint on the main application frame every 50ms using a timer, to simulate a fix frame rate. This seems to have free some of the CPU because the EventDispatcher is not longer flooded with repaint() request from all the objects. Is there anything else we can do with a Custom RepaintManager ?

3) One of the main item I have also discovered is that I am drawing all my components in a panel where cousins (siblings) components can lie on different layer on the same panel (i.e. components are added using the .add(c, 3) where 3 is a layer in JPanel).
This has a huge effect on performance since the JPanel Swing OptimizedDrawing feature (isOptimizedDrawing flag) must be set to false for the siblings components to be painted correctly. The result is that each time Swing wants to repaint a component, it must calculate the clipping area from the bottom of the hierarchy (frame) to the top (leaf component).
Is there a way to optimize the drawing without forcing swing to redraw the entire object tree ?

Any comments would be appreciated,


Pages: [1]
DesertCoockie (52 views)
2018-05-13 18:23:11

nelsongames (83 views)
2018-04-24 18:15:36

nelsongames (74 views)
2018-04-24 18:14:32

ivj94 (759 views)
2018-03-24 14:47:39

ivj94 (87 views)
2018-03-24 14:46:31

ivj94 (643 views)
2018-03-24 14:43:53

Solater (102 views)
2018-03-17 05:04:08

nelsongames (184 views)
2018-03-05 17:56:34

Gornova (426 views)
2018-03-02 22:15:33

buddyBro (1086 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!