-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb96f9e
commit 7216193
Showing
33 changed files
with
2,028 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.orin; | ||
|
||
import net.orin.glfw.LWJGL3; | ||
import net.orin.graphics.Camera; | ||
import net.orin.graphics.Color; | ||
import net.orin.graphics.Game; | ||
import net.orin.opengl.Batch; | ||
import net.orin.opengl.GL; | ||
import net.orin.opengl.textures.Texture; | ||
|
||
public class Demonstration extends Game { | ||
|
||
private Batch batch; | ||
private Camera camera; | ||
|
||
private Texture tex; | ||
|
||
@Override | ||
public void init() { | ||
this.batch = new Batch(); | ||
this.camera = new Camera(Orin.graphics.getWidth(), Orin.graphics.getHeight()); | ||
} | ||
|
||
@Override | ||
public void tick(float deltaTime) { | ||
|
||
} | ||
|
||
@Override | ||
public void render() { | ||
Orin.gl.clear(GL.COLOR); | ||
Orin.gl.clearColor(Color.BLACK); | ||
|
||
this.batch.begin(); | ||
this.batch.setCamera(this.camera); | ||
this.batch.drawTexture(this.tex, 0.0F, 0.0F, 32.0F, 32.0F); | ||
this.batch.end(); | ||
} | ||
|
||
@Override | ||
public void exit() { | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
LWJGL3 app = new LWJGL3(); | ||
app.setFPS(60); | ||
app.create(new Demonstration()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.orin; | ||
|
||
import net.orin.file.*; | ||
import net.orin.glfw.input.*; | ||
import net.orin.graphics.*; | ||
import net.orin.opengl.*; | ||
import net.orin.system.*; | ||
import net.orin.util.*; | ||
|
||
public class Orin { | ||
|
||
private static final String RUNNING_VERSION = "0.0.1a"; | ||
|
||
public static Input input = new Input(); | ||
public static Graphics graphics = new Graphics(); | ||
public static OperatingSystem os = new OperatingSystem(); | ||
public static Files files = new Files(); | ||
public static Logger log = new Logger(); | ||
public static App app = new App(); | ||
public static GL gl = new GL(); | ||
|
||
public static String getVersion() { | ||
return RUNNING_VERSION; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.orin.file; | ||
|
||
public class FileData { | ||
|
||
private String resourceName; | ||
private FileType type; | ||
|
||
public FileData(FileType type, String resourceName) { | ||
this.type = type; | ||
this.resourceName = resourceName; | ||
} | ||
|
||
public String getPath() { | ||
return this.type.getPath() + this.resourceName; | ||
} | ||
|
||
public String getResourceName() { | ||
return this.resourceName; | ||
} | ||
|
||
public FileType getType() { | ||
return this.type; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.orin.file; | ||
|
||
public enum FileType { | ||
|
||
Internal("internal"), External("external"), Local("local"), Temp("temp"); | ||
|
||
private String path; | ||
|
||
FileType(String path) { | ||
switch (path) { | ||
case "internal": | ||
path = "/"; | ||
break; | ||
case "external": | ||
path = System.getProperty("user.home") + "/"; | ||
break; | ||
case "local": | ||
path = System.getProperty("user.dir") + "/"; | ||
break; | ||
case "temp": | ||
path = System.getProperty("java.io.tmpdir") + "/"; | ||
break; | ||
default: | ||
path = "/"; | ||
break; | ||
} | ||
this.path = path; | ||
} | ||
|
||
public String getPath() { | ||
return this.path; | ||
} | ||
|
||
public boolean equals(FileType other) { | ||
if (other != null) { | ||
if (other.hashCode() == hashCode()) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.orin.file; | ||
|
||
public class Files { | ||
|
||
public FileData internal(String resourceName) { | ||
return new FileData(FileType.Internal, resourceName); | ||
} | ||
|
||
public FileData external(String resourceName) { | ||
return new FileData(FileType.External, resourceName); | ||
} | ||
|
||
public FileData local(String resourceName) { | ||
return new FileData(FileType.Local, resourceName); | ||
} | ||
|
||
public FileData temp(String resourceName) { | ||
return new FileData(FileType.Temp, resourceName); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package net.orin.glfw; | ||
|
||
import static org.lwjgl.glfw.GLFW.*; | ||
import static org.lwjgl.opengl.GL11.*; | ||
|
||
import org.lwjgl.opengl.GL; | ||
|
||
import net.orin.Orin; | ||
import net.orin.file.FileData; | ||
import net.orin.graphics.Game; | ||
import net.orin.graphics.window.Window; | ||
import net.orin.opengl.textures.Textures; | ||
import net.orin.util.OrinError; | ||
|
||
public class LWJGL3 { | ||
|
||
private int fps = 60; | ||
|
||
private FileData iconData; | ||
|
||
public LWJGL3() { | ||
this("Game"); | ||
} | ||
|
||
public LWJGL3(String title) { | ||
Window.setTitle(title); | ||
Window.setSize(854, 480); | ||
} | ||
|
||
public void setTitle(String title) { | ||
Window.setTitle(title); | ||
} | ||
|
||
public void setIcon(FileData fileData) { | ||
this.iconData = fileData; | ||
} | ||
|
||
public void setSize(int width, int height) { | ||
Window.setSize(width, height); | ||
} | ||
|
||
public void setFPS(int fps) { | ||
this.fps = fps; | ||
} | ||
|
||
public void create(Game game) { | ||
Orin.log.info("startup", "Orin Engine " + Orin.getVersion() + " initialized"); | ||
Orin.log.info("startup", "Operating system: " + Orin.os.getFamily()); | ||
|
||
Orin.log.info("startup", "Creating window"); | ||
Window.create(); | ||
Orin.log.info("startup", "Creating OpenGL capabilities"); | ||
GL.createCapabilities(); | ||
|
||
Orin.log.info("startup", "OpenGL version: " + Orin.graphics.getGLVersion()); | ||
|
||
Orin.log.info("startup", "Setting OpenGL defaults"); | ||
glEnable(GL_TEXTURE_2D); | ||
glEnable(GL_BLEND); | ||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
|
||
if (this.iconData != null) | ||
Window.setIcon(this.iconData); | ||
|
||
Orin.log.info("startup", "Starting the game..."); | ||
start(game); | ||
} | ||
|
||
public void start(Game game) { | ||
glfwSetTime(0); | ||
|
||
game.init(); | ||
|
||
long lastTime = System.nanoTime(); | ||
double nsPerTick = 1000000000.0 / this.fps; | ||
double unprocessed = 0; | ||
|
||
try { | ||
while (!Window.shouldClose()) { | ||
long now = System.nanoTime(); | ||
unprocessed += (now - lastTime) / nsPerTick; | ||
lastTime = now; | ||
|
||
while (unprocessed >= 1) { | ||
double deltaTime = glfwGetTime(); | ||
glfwSetTime(0); | ||
|
||
game.tick((float) deltaTime); | ||
game.render(); | ||
|
||
Window.update(); | ||
|
||
unprocessed -= 1; | ||
} | ||
} | ||
} catch (OrinError e) { | ||
Orin.log.fatal("loop", e.toString()); | ||
} catch (OutOfMemoryError e) { | ||
Orin.app.freeMemory(); | ||
} finally { | ||
game.exit(); | ||
|
||
Textures.dispose(); | ||
Window.terminate(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package net.orin.glfw.input; | ||
|
||
import static org.lwjgl.glfw.GLFW.*; | ||
|
||
import org.lwjgl.glfw.GLFWCursorPosCallback; | ||
import org.lwjgl.glfw.GLFWKeyCallback; | ||
import org.lwjgl.glfw.GLFWMouseButtonCallback; | ||
|
||
public class Input extends GLFWKeyCallback { | ||
|
||
private static int x; | ||
private static int y; | ||
|
||
private static boolean[] keys = new boolean[GLFW_KEY_LAST]; | ||
private static boolean[] keysJustPressed = new boolean[GLFW_KEY_LAST]; | ||
|
||
private static boolean[] buttons = new boolean[GLFW_MOUSE_BUTTON_LAST]; | ||
private static boolean[] buttonsJustPressed = new boolean[GLFW_MOUSE_BUTTON_LAST]; | ||
|
||
@Override | ||
public void invoke(long window, int key, int scancode, int action, int mods) { | ||
if (key >= 0 && key < GLFW_KEY_LAST) { | ||
keys[key] = action != GLFW_RELEASE; | ||
keysJustPressed[key] = action == GLFW_PRESS; | ||
} | ||
} | ||
|
||
public boolean isKeyPressed(int key) { | ||
if (key > 0 && key < GLFW_KEY_LAST) { | ||
return keys[key]; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean isKeyJustPressed(int key) { | ||
if (key > 0 && key < GLFW_KEY_LAST) { | ||
boolean result = keysJustPressed[key]; | ||
keysJustPressed[key] = false; | ||
return result; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean isButtonPressed(int button) { | ||
if (button >= 0 && button < GLFW_MOUSE_BUTTON_LAST) { | ||
return buttons[button]; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean isButtonJustPressed(int button) { | ||
if (button >= 0 && button < GLFW_MOUSE_BUTTON_LAST) { | ||
boolean result = buttonsJustPressed[button]; | ||
buttonsJustPressed[button] = false; | ||
return result; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean isTouched() { | ||
return isButtonPressed(0); | ||
} | ||
|
||
public boolean isJustTouched() { | ||
return isButtonJustPressed(0); | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
public static class MousePos extends GLFWCursorPosCallback { | ||
|
||
@Override | ||
public void invoke(long window, double x, double y) { | ||
Input.x = (int) x; | ||
Input.y = (int) y; | ||
} | ||
|
||
} | ||
|
||
public static class MouseButton extends GLFWMouseButtonCallback { | ||
|
||
@Override | ||
public void invoke(long window, int button, int action, int mods) { | ||
if (button >= 0 && button < GLFW_MOUSE_BUTTON_LAST) { | ||
buttons[button] = action != GLFW_RELEASE; | ||
buttonsJustPressed[button] = action == GLFW_PRESS; | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.