I'm not sure whether this question should be posted here. I'm trying to make a basic generic game engine in Java. Here's what I have so far.
public abstract class Device {
public abstract void startDevice();
public abstract void closeDevice();
public abstract int getWidth();
public abstract int getHeight();
public abstract void displayImage(Image im);
}
public class Game {
public final Device device;
public synchronized void gameStart() { ... }
}
public abstract class GameEntity implements Serializable {
public abstract void create(Game g);
public abstract void updateAndDraw(Game g, Graphics2D g2d);
public abstract void destroy(Game g);
}
So far, I have implemented two concrete classes for Device, SwingDevice and J2meDevice, and it's working fine. Now the problem is I want to implement AndroidDevice. Everything will work just fine except for that I have enforced using java.awt.Image and java.awt.Graphics2D to paint Game's graphics offline. Then I forward this Image to the device for rendering.
Is there any way I can absolutely decouple the Device's graphics from the rest of the engine?
I have two solutions but I doubt they'll fully achieve what I need:
- Stick with the java.awt.Image. Devices that support OpenGL will not fully utilize their hardware capabilities as drawing is done on CPU. And it might not work on platforms on which can't import java.awt (I doubt their existence).
- Create my Graphics2D-like interface. This will make defining new devices harder and again it might hide some of the device's features.