Hey guys,
I’m trying to write a high-performance Java 1.1 renderer for a 2d game and am having some frustrations. Things run okay, but I’m convinced there are more efficient ways to push image data around within Java.
Here’s what the renderer does:
DirectColorModel cm = new DirectColorModel(24,0x00ff0000,0x0000ff00,0x000000ff);
mis = new MemoryImageSource(m_width, m_height, cm, m_pixels, 0, m_width);
mis.setAnimated(true);
m_image = GetAppInstance().createImage(mis);
Then, for every frame, the renderer writes to the m_pixels int array, calls mis.newPixels() and repaint()s. When Applet.paint() is called, it does a g.drawImage(mis, 0, 0, null).
The problem is that, in 550x400 at 25 fps, the newPixels() call takes 1/3 of a frame, and the drawImage() takes about 1/2. This only leaves a 1/6 of a frame for the game to do its real work. Does anyone know if this is normal? Is it possible to combine these two calls? This is a painful overhead.
Thanks for your help.