started writing documentation
This commit is contained in:
parent
77197b6004
commit
44f5325f4e
|
@ -6,6 +6,15 @@
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
<inspection_tool class="ClassCanBeRecord" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
<inspection_tool class="ClassCanBeRecord" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="EmptyMethod" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="EmptyMethod" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="MissingJavadoc" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="METHOD_SETTINGS">
|
||||||
|
<Options>
|
||||||
|
<option name="MINIMAL_VISIBILITY" value="protected" />
|
||||||
|
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||||
|
</Options>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="MissingPackageInfo" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||||
<option name="processCode" value="true" />
|
<option name="processCode" value="true" />
|
||||||
<option name="processLiterals" value="true" />
|
<option name="processLiterals" value="true" />
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
<pattern value="com.danitheskunk.skunkworks.GLRenderContext" method="drawTextureRectangle" />
|
<pattern value="com.danitheskunk.skunkworks.GLRenderContext" method="drawTextureRectangle" />
|
||||||
<pattern value="com.danitheskunk.skunkworks.GLWindow" method="loadTextureArray" />
|
<pattern value="com.danitheskunk.skunkworks.GLWindow" method="loadTextureArray" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="JavadocGenerationManager">
|
||||||
|
<option name="OUTPUT_DIRECTORY" value="$PROJECT_DIR$/javadoc" />
|
||||||
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -12,6 +12,17 @@ import com.danitheskunk.skunkworks.gfx.font.IFont;
|
||||||
import com.danitheskunk.skunkworks.nodes.NodeRoot;
|
import com.danitheskunk.skunkworks.nodes.NodeRoot;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main class to extend to write a game in Skunkworks
|
||||||
|
* <p>
|
||||||
|
* 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}.
|
||||||
|
* <p>
|
||||||
|
* Automatic timing (by default 60fps), resizing(with various scalers), 2d
|
||||||
|
* and 3d rendering, and audio playback.
|
||||||
|
*/
|
||||||
@SuppressWarnings("SameParameterValue")
|
@SuppressWarnings("SameParameterValue")
|
||||||
public abstract class BaseGame {
|
public abstract class BaseGame {
|
||||||
protected final AudioEngine audioEngine;
|
protected final AudioEngine audioEngine;
|
||||||
|
@ -22,6 +33,12 @@ public abstract class BaseGame {
|
||||||
protected final SamplePlayer samplePlayer;
|
protected final SamplePlayer samplePlayer;
|
||||||
protected final IWindow window;
|
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) {
|
public BaseGame(Vec2i windowSize, String windowTitle) {
|
||||||
audioEngine = new AudioEngine(44100, 256, 8);
|
audioEngine = new AudioEngine(44100, 256, 8);
|
||||||
mixer = new Mixer(audioEngine, 2);
|
mixer = new Mixer(audioEngine, 2);
|
||||||
|
@ -34,43 +51,91 @@ public abstract class BaseGame {
|
||||||
//todo: load from .jar
|
//todo: load from .jar
|
||||||
debugFont = window.loadFontTileset("fonts/ega-8x14.png");
|
debugFont = window.loadFontTileset("fonts/ega-8x14.png");
|
||||||
rootNode = new NodeRoot();
|
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) {
|
protected ISample loadSample(String path) {
|
||||||
return audioEngine.loadSample(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) {
|
protected ITexture loadTexture(String path) {
|
||||||
return window.loadTexture(path);
|
return window.loadTexture(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play sample once
|
||||||
|
*
|
||||||
|
* @param sample the sample to be played
|
||||||
|
*/
|
||||||
protected void playSample(ISample sample) {
|
protected void playSample(ISample sample) {
|
||||||
samplePlayer.play(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) {
|
protected void playSample(ISample sample, boolean looping) {
|
||||||
samplePlayer.play(sample, looping);
|
samplePlayer.play(sample, looping);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render Callback
|
||||||
|
* <p>
|
||||||
|
* 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) {
|
protected void render(IRenderContext rc) {
|
||||||
//rc.drawString(new Vec2i(8, 8), "Welcome to Skunkworks, please
|
//to be overriden by child class
|
||||||
// overide the render method to get started", debugFont, Color
|
|
||||||
// .LIGHT_GRAY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3D Render Callback
|
||||||
|
* <p>
|
||||||
|
* 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) {
|
protected void render3D(IRenderContext3D rc3d) {
|
||||||
//to be overriden by child class
|
//to be overriden by child class
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Early Render Callback
|
||||||
|
* <p>
|
||||||
|
* 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) {
|
protected void renderPre(IRenderContext rc) {
|
||||||
//to be overriden by child class
|
//to be overriden by child class
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the game
|
||||||
|
* <p>
|
||||||
|
* This will transfer the control to Skunkworks until the game window
|
||||||
|
* closes.
|
||||||
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
double lastTime, currentTime, delta;
|
double lastTime, currentTime, delta;
|
||||||
|
|
||||||
|
@ -98,6 +163,14 @@ public abstract class BaseGame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Callback
|
||||||
|
* <p>
|
||||||
|
* 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) {
|
protected void update(double delta) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,67 @@
|
||||||
package com.danitheskunk.skunkworks.gfx;
|
package com.danitheskunk.skunkworks.gfx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 32bit RGBA Color
|
||||||
|
*/
|
||||||
public final class Color {
|
public final class Color {
|
||||||
|
/**
|
||||||
|
* #000000
|
||||||
|
*/
|
||||||
public final static Color BLACK = new Color(0, 0, 0);
|
public final static Color BLACK = new Color(0, 0, 0);
|
||||||
|
/**
|
||||||
|
* #0000FF
|
||||||
|
*/
|
||||||
public final static Color BLUE = new Color(0, 0, 255);
|
public final static Color BLUE = new Color(0, 0, 255);
|
||||||
|
/**
|
||||||
|
* #00FFFF
|
||||||
|
*/
|
||||||
public final static Color CYAN = new Color(0, 255, 255);
|
public final static Color CYAN = new Color(0, 255, 255);
|
||||||
|
/**
|
||||||
|
* #404040
|
||||||
|
*/
|
||||||
public final static Color DARK_GRAY = new Color(64, 64, 64);
|
public final static Color DARK_GRAY = new Color(64, 64, 64);
|
||||||
|
/**
|
||||||
|
* #808080
|
||||||
|
*/
|
||||||
public final static Color GRAY = new Color(128, 128, 128);
|
public final static Color GRAY = new Color(128, 128, 128);
|
||||||
|
/**
|
||||||
|
* #00FF00
|
||||||
|
*/
|
||||||
public final static Color GREEN = new Color(0, 255, 0);
|
public final static Color GREEN = new Color(0, 255, 0);
|
||||||
|
/**
|
||||||
|
* #C0C0C0
|
||||||
|
*/
|
||||||
public final static Color LIGHT_GRAY = new Color(192, 192, 192);
|
public final static Color LIGHT_GRAY = new Color(192, 192, 192);
|
||||||
|
/**
|
||||||
|
* #FF00FF
|
||||||
|
*/
|
||||||
public final static Color MAGENTA = new Color(255, 0, 255);
|
public final static Color MAGENTA = new Color(255, 0, 255);
|
||||||
|
/**
|
||||||
|
* #FF0000
|
||||||
|
*/
|
||||||
public final static Color RED = new Color(255, 0, 0);
|
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);
|
public final static Color TRANS_BLACK = new Color(0, 0, 0, 0);
|
||||||
|
/**
|
||||||
|
* #FFFFFF
|
||||||
|
*/
|
||||||
public final static Color WHITE = new Color(255, 255, 255);
|
public final static Color WHITE = new Color(255, 255, 255);
|
||||||
|
/**
|
||||||
|
* #FFFF00
|
||||||
|
*/
|
||||||
public final static Color YELLOW = new Color(255, 255, 0);
|
public final static Color YELLOW = new Color(255, 255, 0);
|
||||||
private final int r, g, b, a;
|
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) {
|
public Color(int r, int g, int b) {
|
||||||
this.r = r;
|
this.r = r;
|
||||||
this.g = g;
|
this.g = g;
|
||||||
|
@ -23,6 +69,14 @@ public final class Color {
|
||||||
a = 0xff;
|
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) {
|
public Color(int r, int g, int b, int a) {
|
||||||
this.r = r;
|
this.r = r;
|
||||||
this.g = g;
|
this.g = g;
|
||||||
|
@ -30,18 +84,38 @@ public final class Color {
|
||||||
this.a = a;
|
this.a = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the alpha component 0-255
|
||||||
|
*
|
||||||
|
* @return the alpha component 0-255
|
||||||
|
*/
|
||||||
public int getA() {
|
public int getA() {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the blue component 0-255
|
||||||
|
*
|
||||||
|
* @return the blue component 0-255
|
||||||
|
*/
|
||||||
public int getB() {
|
public int getB() {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the green component 0-255
|
||||||
|
*
|
||||||
|
* @return the green component 0-255
|
||||||
|
*/
|
||||||
public int getG() {
|
public int getG() {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the red component 0-255
|
||||||
|
*
|
||||||
|
* @return the red component 0-255
|
||||||
|
*/
|
||||||
public int getR() {
|
public int getR() {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue