Show Posts
|
|
Pages: [1]
|
|
1
|
Java Game APIs & Engines / Java 2D / Re: CPU usage in a pure Java2D game
|
on: 2007-02-26 15:25:55
|
I understood (but if not please tell me) that: is it a bug in the BufferCapabilities class? But if I use a library such as Java3D or LWOGL or another, do I solve my problem? Another question: 1 2 3 4 5 6 7
| bufferStrategy.getCapabilities().getFrontBufferCapabilities().isAccelerated() returns true bufferStrategy.getCapabilities().getBackBufferCapabilities().isAccelerated() returns true bufferStrategy.getCapabilities().getFrontBufferCapabilities().isTrueVolatile() returns false bufferStrategy.getCapabilities().getBackBufferCapabilities().isTrueVolatile() returns false
And: GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getAvailableAcceleratedMemory() returns (more or less) 119000000 |
Is it right? Or not? I mean I understood that the first 4 methods if Java uses Accelerated Memory they must return true, is it right? But in my case the third one and the forth one return false. Last strange thing is the result of the fifth method because it returns 119000000 so it seems that my graphic card has almost 128Mb RAM but in reality my ATi Mobility Radeon 9600 has only 64Mb RAM on my notebook... Did I misunderstand something? 
|
|
|
|
|
2
|
Java Game APIs & Engines / Java 2D / Re: CPU usage in a pure Java2D game
|
on: 2007-02-23 19:25:32
|
|
I already tried this method but nothing doing. I also tried to search something about this problem and I found a bug report concerning this error, in Java 1.6.0 it is fixed but for my graphic card the problem still remains.
It's very probably that the created graphics drivers for my notebook (an ASUS As2500D) have some problems with OpenGL. It's only an assuption, because I do not find anything about that.
|
|
|
|
|
3
|
Java Game APIs & Engines / Java 2D / Re: CPU usage in a pure Java2D game
|
on: 2007-02-23 14:51:34
|
I also tried your method Kova, but at this point it seems there is some problems with accelerated images on my machine (a notebook with a Mobility Radeon 9600 and 64Mb VRam)...  Perhaps do I have to put some command flags? Such as opengl-pipeline or something like that? UPDATE: Great Gaia! Every time I run my application with this flag -Dsun.java2d.opengl=true I got this error: # # An unexpected error has been detected by HotSpot Virtual Machine: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x694085d0, pid=1952, tid=516 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_11-b03 mixed mode, sharing) # Problematic frame: # C [atioglxx.dll+0x4085d0] # # An error report file with more information is saved as hs_err_pid1952.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # 
|
|
|
|
|
4
|
Java Game APIs & Engines / Java 2D / Re: CPU usage in a pure Java2D game
|
on: 2007-02-23 10:55:28
|
Well before the game loop I do this: 1 2 3
| frame.setVisible(true); frame.createBufferStrategy(2); graphics = (Graphics2D) frame.getBufferStrategy().getDrawGraphics(); |
and I use the object 'graphics' to draw everything and then when I finished I call frame.getBufferStrategy().show(). I think it's right or not? I tried to hide all the unnecessary code for the drawing operation, but the CPU usage is still high. Uh! Last thing I use Java 1.5.0 u11, I began with this version and I want to wait some time to pass to 1.6.0. Thanx a lot to everybody! ^____^
|
|
|
|
|
5
|
Java Game APIs & Engines / Java 2D / Re: CPU usage in a pure Java2D game
|
on: 2007-02-22 14:53:15
|
Great...  I thought to have solved this problem in my code, so it seems there is still something wrong. Mmh... maybe when I load the Images? In your opinion is it better to load images with ImageIO? I said that because I load my images with ImageIcon and then I convert them in BufferedImage in this way: 1 2 3 4 5 6 7
| public static BufferedImage loadBufferedImage(String path) { ... ImageIcon i = new ImageIcon(path); BufferedImage bi = new BufferedImage(i.getIconWidth(), i.getIconHeight()); bi.getImage().getGraphics().drawImage(i.getImage(), 0, 0, null); return bi; } |
but maybe it's not the right method...
|
|
|
|
|
6
|
Java Game APIs & Engines / Java 2D / Re: CPU usage in a pure Java2D game
|
on: 2007-02-21 17:07:22
|
Whoa!  I don't understand anything, but if for you it's a help to understand... 388750 calls to sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, "D3D texture destination") 2 calls to sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, IntArgb) 765 calls to DXFillRect 1 call to GDIFillRect 760 calls to sun.awt.windows.Win32BlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw") 389293 calls to sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb) 2 calls to sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntArgb) 780116 total calls to 7 different primitives
So what is that? 
|
|
|
|
|
7
|
Java Game APIs & Engines / Java 2D / CPU usage in a pure Java2D game
|
on: 2007-02-21 16:46:08
|
|
Hi all. I would talk about the CPU usage in a pure Java2D game (developed using only BufferStrategy or VolatileImage/BufferedImage). In these months I'm developing a sort of wrapper library to simplify the implementation of 2D-games, but I got some problems concerning the CPU usage. For the creation of a Animation I instancied an ArrayList with the sequence of BufferedImages, every N milliseconds I change the index of the ArrayList to simulate the animation. Therefore in the Game Loop there is an update of Animation and a getCurrentImage method to show the animation on the screen (to do this I used a BufferStrategy).
With 50 Animations (composed by Images of 60 pixels by 60 pixels, more or less) and a 640 by 480 resolution with 32 bit of colors (full-screen mode) the CPU ratio (I watched it with TaskManager) is about 5%-10%; with 100 animations I got 50%-60%; with 150 animations I got 75%-85% and with more than 150 I always have 100%. The Animation is updated every 80 milliseconds.
The "engine" goes well and it's faster enough, but I would like to know if there is a way to decrease the CPU usage. I mean for example there is the way to show the Sprites and the rest splitting the Images in tiles, but this helps? Other methods?
|
|
|
|
|
9
|
Game Development / Newbie & Debugging Questions / Re: A JCanvas
|
on: 2006-10-19 16:32:40
|
Uuh... well I tried to use JPanel and it does not work with me, but it doesn't matter, I found the bug in my class...  How can I check if a component has a peer or not? I mean when I create for example a JPanel obj and I add it in the pane of a JFrame obj, there is a way to check the ComponentPeer of JPanel?
|
|
|
|
|
10
|
Game Development / Newbie & Debugging Questions / A JCanvas
|
on: 2006-10-19 14:18:57
|
Hi all. A simple question for a difficult answer (maybe). What is the best way to create a JCanvas? I mean in java.awt package there is the Canvas object but it is a Heavyweight object and it isn't a good idea to mix Lightweight objects with HW objs (do not respect the z-order). How can I do? I tried to create a new one which extends JComponent and implements some methods for the creation of a BufferStrategy, but I got some problems to show images (they blink). I show you what I've done: 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| public class JCanvas extends JComponent [INNER CLASSES]
private static final long serialVersionUID = 123456789L; private static final Dimension MINIMUM_SIZE = new Dimension(320, 200); transient ComponentPeer peer; private static VolatileImage vImage; private BufferStrategy strategy = null; public JCanvas() { super(); } public void initStrategy() { if (this.getMinimumSize().height >= MINIMUM_SIZE.height && this.getMinimumSize().width >= MINIMUM_SIZE.width) { this.createBufferStrategy(2); this.strategy = this.getBufferStrategy(); } } public BufferStrategy getBufferStrategy() { if (this.strategy == null) { createBufferStrategy(1); } return this.strategy; } public Graphics getBufferedGraphics() { return this.strategy != null ? this.strategy.getDrawGraphics() : this.getGraphics(); } public void paintComponent(Graphics g) { super.paintComponent(g); } void createBufferStrategy(int numBuffers) { BufferCapabilities bufferCaps; if (numBuffers > 1) { bufferCaps = new BufferCapabilities( new ImageCapabilities(true), new ImageCapabilities(true), BufferCapabilities.FlipContents.UNDEFINED); try { createBufferStrategy(numBuffers, bufferCaps); return; } catch (AWTException e) { } } bufferCaps = new BufferCapabilities( new ImageCapabilities(true), new ImageCapabilities(true), null); try { createBufferStrategy(numBuffers, bufferCaps); return; } catch (AWTException e) { } bufferCaps = new BufferCapabilities( new ImageCapabilities(false), new ImageCapabilities(false), null); try { createBufferStrategy(numBuffers, bufferCaps); return; } catch (AWTException e) { } throw new InternalError("Could not create a buffer strategy"); } public void createBufferStrategy(int numBuffers, BufferCapabilities caps) throws AWTException { if (numBuffers < 1) { throw new IllegalArgumentException("Number of buffers must be at least 1"); } if (caps == null) { throw new IllegalArgumentException("No capabilities specified"); } if (this.strategy instanceof FlipBufferStrategy) { ((FlipBufferStrategy) this.strategy).destroyBuffers(); } if (numBuffers == 1) { this.strategy = new SingleBufferStrategy(caps); } else { if (caps.isPageFlipping()) { this.strategy = new FlipBufferStrategy(numBuffers, caps); } else { this.strategy = new BltBufferStrategy(numBuffers, caps); } } } protected void destroyBuffers() { if (peer != null) { peer.destroyBuffers(); } else { throw new IllegalStateException("Component must have a valid peer"); } } } |
|
|
|
|
|
12
|
Game Development / Game Play & Game Design / Re: A new game library: Aries!
|
on: 2006-10-04 20:39:05
|
|
Well I got some problems when I want to extend a Singleton Class. AriesGame is a Singleton Class and if you want to add the events (in the method events()) you must extend the super class AriesGame. Or are there other ways to do that? That is, are there other ways to extend a Singleton Class?
|
|
|
|
|
14
|
Game Development / Game Play & Game Design / Re: A new game library: Aries!
|
on: 2006-09-28 01:13:34
|
@SluX: I wish I had!  I have a lot of questions about optimization...  Hiya, Your project sounds almost exactly like an existing mature java 2D games library which is targeted toward begginers and java programs with no game development experience. http://www.goldenstudios.or.id/You might want to see if this project satisfies your wants. Well I know it, but I think there are some steps of the creation of a game that could be easier than those of GTGE. It's a my personal opinion! For example the creation of an Animated Sprite in my library is more logical than GTGE (if you think the contrary just tell me!  ): AriesSprite is a class that contains a group of AriesAnimation but each AriesAnimation contains an another group of sub-type of animations, AriesAnim. Why? Well think about an isometric game like Ultima or Syndacate, you know that the main character can turn right, left, up and down (and half-positions: left/up, right/down, etc...), ok? When you create an AriesAnimation you define an animation for all these positions and each single position has an AriesAnim. The creation of the sprite is more articulate, but when you will understand its logic you will have no problems. I show you an example (I'm gonna use some AriesClasses): 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
| ... AriesAnim walkright = new AriesAnim(AriesTools.loadImage("c:\images\walkright01.png"), AriesTools.loadImage("c:\images\walkright02.png")); walkright.setSpeed(200); walkright.setRepeat(true);
AriesAnim walkleft = new AriesAnim(AriesTools.loadImage("c:\images\walkleft01.png"), AriesTools.loadImage("c:\images\walkleft02.png")); walkright.setSpeed(200); walkright.setRepeat(true);
AriesAnim stand = new AriesAnim(AriesTools.loadImage("c:\images\stand"));
AriesAnimation walking = new AriesAnimation(4); walking.addAnim(AriesDirections.EAST, walkright); walking.addAnim(AriesDirections.WEST, walkleft);
AriesAnimation standing = new AriesAnimation(4); standing.addAnim(stand);
AriesSprite mario = new AriesSprite(); mario.addAnimation("walking", walking); mario.addAnimation("standing", standing); ... game.store.addObject("mario", mario); ...
public void events() { if (keyboard.isPressed(keyboard.KEY_RIGHT)) { game.store.getSprite("mario").setDirection(AriesDirections.EAST); game.store.getSprite("mario").setAnimation("walking").startAnimation(); }
if (keyboard.isPressed(keyboard.KEY_LEFT)) { game.store.getSprite("mario").setDirection(AriesDirections.WEST); game.store.getSprite("mario").setAnimation("walking").startAnimation(); }
if (keyboard.notTouched) { game.store.getSprite("mario").setAnimation("standing").startAnimation(); } }
|
So what do you think? If the final user must worry only for the events and not to draw the graphics or other is better or not?  In Aries library the final user do not have to learn the logic of the creation of game, his own only one worry is his creative mind! ^___^ (I hope to have written right... I'm not an english user...  )
|
|
|
|
|
15
|
Game Development / Game Play & Game Design / Re: A new game library: Aries!
|
on: 2006-09-27 20:59:01
|
Well nothing special, but an opinion if the library could be useful for someone, for example  The structure of the project is big, maybe if I post a Class Diagram (or something like that) and I explain what the library does I will receive a feedback... 
|
|
|
|
|
17
|
Game Development / Game Play & Game Design / Re: A new game library: Aries!
|
on: 2006-09-27 16:30:38
|
Obviously here we have a simple example there are other objects that you can create/use: AriesBackground, AriesSprite and AriesTimer (I know they are not many but be patient!  ). If you are interested about this project I will show you other kind of examples!
|
|
|
|
|
18
|
Game Development / Game Play & Game Design / A new game library: Aries!
|
on: 2006-09-27 16:20:55
|
Hi all! I'm developing a new library for the creation of 2D games in Java. The main goal of the project is to give anyone the opportunity to create a game, without the need to spend a lot of time learning how game programming works. The only prerequisite is some basic java programming knowledge. The libray do not use any particular technology or other libraries (ie LWJGL, JME, ecc...), but only pure Java. The library is not ready for a release yet, but I want to know if the project might be interesting for you or not! I give you an example what Aries can do: 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
| public class MyGame extends AriesGame { private AriesPicture p1 = new AriesPicture(200, 200);
public MyGame() { game = this; game.set(AriesGame.S_640BY480, AriesGame.FULLSCREEN); p1.drawString(0, 10, "A simple java game!"); p1.drawRectangle(0, 0, 199, 199, false); p1.setPosition(100, 150); game.store.addObject("p1", p1); game.start(); }
public void events() { if (keyboard.isTyped(keyboard.KEY_SPACE)) { game.store.getPicture("p1").clear(); game.store.getPicture("p1").drawString(0, 10, "You hit the Space Key"); }
if (mouse.isWheelUp()) { game.store.getPicture("p1").move(0, -150); }
if (keyboard.isPressed(keyboard.KEY_SHIFT) && mouse.isClicked(mouse.BUTTON1)) { game.store.getPicture("p1").move(50, 30); } } public static void main(String[] args) { new MyGame(); } } |
this is the result:
|
|
|
|
|
20
|
Java Game APIs & Engines / Java 2D / Some problems about GIF images...
|
on: 2006-09-11 15:34:22
|
|
Hi there! I got some problems with GIF images format. In my J2D application (a simple game) I load some PNG images (24 bit colors), but since the execution was slow I switched the format of images in GIF format (8 bit colors). Here I met the problems. Before the switching, all the PNG images were loaded on the screen without problems, now the GIF images are loaded sometimes yes sometimes no. And I do not understand why. The method to load the images is the same:
public static Image loadImage(URL path) { try { return new ImageIcon(path).getImage(); } catch (Exception e) { Log.errln(ERROR + "exception: " + e); } return null; }
public static BufferedImage toBufferedImage(Image image) { BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); bi.getGraphics().drawImage(image, 0, 0, null); bi.getGraphics().dispose(); return bi; }
I load the image in Image Object after I convert it in BufferedImage. Are the methods right or not?
|
|
|
|
|
22
|
Java Game APIs & Engines / Java 2D / Re: clip an image
|
on: 2006-08-30 05:00:08
|
|
Hi! I come from Italy and I'm working on a project about Java2D for university. I'm developing a game and I want to know if my "drawing-engine" is good or not.
I do not know how you create a Sprite but in my case I create an ArrayList of BufferedImage and each element is a Frame of this Sprite. Every n milliseconds the Frame changes and is drawn with drawImage(...) of a Graphics with a double-buffering strategy. The game with 640 by 480 resolution goes well, but can I do something else to increase the performance? Ah I also use the getSubImage() method to draw parts of the sprites (always using drawImage() in this way g.drawImage(image.getSubImage(0, 0, 20, 20), 0, 12, null)).
Thanks in advance for all replies!
|
|
|
|
|
23
|
Java Game APIs & Engines / JInput / A simple keyboard manager
|
on: 2006-07-01 18:26:08
|
|
Hi! I'm new. I have a simple question: where may I find a tutorial that explains how to make a simple keyboard manager? I asked that because I am able to find tutorial about gamepad and joystick only.
Thanks in advance! Alexian
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|