+ * Extend this class and override {@link BaseGame#update update}, + * {@link BaseGame#render render}, {@link BaseGame#renderPre renderPre}, + * and/or {@link BaseGame#render3D render3D} to add functionality. Then instance + * and call {@link BaseGame#run run}. + *
+ * Automatic timing (by default 60fps), resizing(with various scalers), 2d + * and 3d rendering, and audio playback. + */ @SuppressWarnings("SameParameterValue") public abstract class BaseGame { protected final AudioEngine audioEngine; @@ -22,6 +33,12 @@ public abstract class BaseGame { protected final SamplePlayer samplePlayer; protected final IWindow window; + /** + * Create with given window size and title + * + * @param windowSize the size of the game's window + * @param windowTitle the title of the game's window + */ public BaseGame(Vec2i windowSize, String windowTitle) { audioEngine = new AudioEngine(44100, 256, 8); mixer = new Mixer(audioEngine, 2); @@ -34,43 +51,91 @@ public abstract class BaseGame { //todo: load from .jar debugFont = window.loadFontTileset("fonts/ega-8x14.png"); rootNode = new NodeRoot(); - init(); - } - - protected void init() { - } + /** + * Load sample from path + * + * @param path file path to the sample + * @return the loaded sample + */ protected ISample loadSample(String path) { return audioEngine.loadSample(path); } + /** + * Load image from path and prepare as gpu texture + * + * @param path file path to the image file + * @return the loaded texture + */ protected ITexture loadTexture(String path) { return window.loadTexture(path); } + /** + * Play sample once + * + * @param sample the sample to be played + */ protected void playSample(ISample sample) { samplePlayer.play(sample); } + /** + * Play sample once or looped + * + * @param sample the sample to be played + * @param looping loops forever if true, otherwise play once + */ protected void playSample(ISample sample, boolean looping) { samplePlayer.play(sample, looping); } + /** + * Render Callback + *
+ * This method will be called after {@link BaseGame#render3D render3D}, + * when the engine is ready for 2d rendering. Override this method to + * render 2d things on screen. + * + * @param rc the render context with all the render functions + */ protected void render(IRenderContext rc) { - //rc.drawString(new Vec2i(8, 8), "Welcome to Skunkworks, please - // overide the render method to get started", debugFont, Color - // .LIGHT_GRAY); + //to be overriden by child class } + /** + * 3D Render Callback + *
+ * This method will be called when the engine is ready for 3d rendering. + * Override this method to render 3d things on screen. + * + * @param rc3d the render context with all the render functions + */ protected void render3D(IRenderContext3D rc3d) { //to be overriden by child class } + /** + * Early Render Callback + *
+ * This method will be called before {@link BaseGame#render3D render3D}, + * when the engine is ready for 2d rendering. Override this method to + * render 2d things on screen underneath 3d content. + * + * @param rc the render context with all the render functions + */ protected void renderPre(IRenderContext rc) { //to be overriden by child class } + /** + * Runs the game + *
+ * This will transfer the control to Skunkworks until the game window + * closes. + */ public void run() { double lastTime, currentTime, delta; @@ -98,6 +163,14 @@ public abstract class BaseGame { } } + /** + * Update Callback + *
+ * This method will be called periodically, either in a fixed(by default) + * or variable period. Can be changed by setting {@link Timestep} + * + * @param delta time that passed since last update in seconds + */ protected void update(double delta) { } diff --git a/com/danitheskunk/skunkworks/gfx/Color.java b/com/danitheskunk/skunkworks/gfx/Color.java index bf36b2c..0d54fde 100644 --- a/com/danitheskunk/skunkworks/gfx/Color.java +++ b/com/danitheskunk/skunkworks/gfx/Color.java @@ -1,21 +1,67 @@ package com.danitheskunk.skunkworks.gfx; +/** + * 32bit RGBA Color + */ public final class Color { + /** + * #000000 + */ public final static Color BLACK = new Color(0, 0, 0); + /** + * #0000FF + */ public final static Color BLUE = new Color(0, 0, 255); + /** + * #00FFFF + */ public final static Color CYAN = new Color(0, 255, 255); + /** + * #404040 + */ public final static Color DARK_GRAY = new Color(64, 64, 64); + /** + * #808080 + */ public final static Color GRAY = new Color(128, 128, 128); + /** + * #00FF00 + */ public final static Color GREEN = new Color(0, 255, 0); + /** + * #C0C0C0 + */ public final static Color LIGHT_GRAY = new Color(192, 192, 192); + /** + * #FF00FF + */ public final static Color MAGENTA = new Color(255, 0, 255); + /** + * #FF0000 + */ public final static Color RED = new Color(255, 0, 0); + /** + * #000000 (with alpha=0) + */ public final static Color TRANS_BLACK = new Color(0, 0, 0, 0); + /** + * #FFFFFF + */ public final static Color WHITE = new Color(255, 255, 255); + /** + * #FFFF00 + */ public final static Color YELLOW = new Color(255, 255, 0); private final int r, g, b, a; + /** + * Creates a color (with alpha=255) + * + * @param r the red component 0-255 + * @param g the green component 0-255 + * @param b the blue component 0-255 + */ public Color(int r, int g, int b) { this.r = r; this.g = g; @@ -23,6 +69,14 @@ public final class Color { a = 0xff; } + /** + * Creates a color + * + * @param r the red component 0-255 + * @param g the green component 0-255 + * @param b the blue component 0-255 + * @param a the alpha component 0-255 + */ public Color(int r, int g, int b, int a) { this.r = r; this.g = g; @@ -30,18 +84,38 @@ public final class Color { this.a = a; } + /** + * Returns the alpha component 0-255 + * + * @return the alpha component 0-255 + */ public int getA() { return a; } + /** + * Returns the blue component 0-255 + * + * @return the blue component 0-255 + */ public int getB() { return b; } + /** + * Return the green component 0-255 + * + * @return the green component 0-255 + */ public int getG() { return g; } + /** + * Return the red component 0-255 + * + * @return the red component 0-255 + */ public int getR() { return r; }