Compare commits

..

No commits in common. "007be3e9f31aea87c10b92742edbbd645418a84c" and "107e0a5c9156afceabf542ff720f1220572dce42" have entirely different histories.

14 changed files with 63 additions and 336 deletions

View File

@ -6,7 +6,6 @@ import com.danitheskunk.skunkworks.audio.nodes.Mixer;
import com.danitheskunk.skunkworks.audio.nodes.Node;
import com.danitheskunk.skunkworks.audio.nodes.SamplePlayer;
import com.danitheskunk.skunkworks.audio.nodes.TTS;
import com.danitheskunk.skunkworks.backends.gl.Gamepad;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.font.IFont;
@ -35,7 +34,6 @@ public abstract class BaseGame {
protected final SamplePlayer samplePlayer;
protected final TTS tts;
protected final IWindow window;
protected final BaseGamepad gamepad;
/**
* Create with given window size and title
@ -54,7 +52,6 @@ public abstract class BaseGame {
engine = new Engine();
window = engine.openWindow(windowSize, windowTitle);
gamepad = window.getGamepad(0);
//todo: load from .jar
debugFont = window.loadFontTileset("fonts/ega-8x14.png");
rootNode = new NodeRoot();
@ -156,7 +153,6 @@ public abstract class BaseGame {
currentFrameTime += delta;
engine.tick();
window.tick();
gamepad.tick();
//todo: frame rate control
if(currentFrameTime >= 1.0 / 60.0) {
rootNode.tick();

View File

@ -1,57 +0,0 @@
package com.danitheskunk.skunkworks;
public abstract class BaseGamepad {
protected final float[] axes;
protected final boolean[] buttonDown;
protected final boolean[] buttonPressed;
protected final int axesCount;
protected final int buttonCount;
public BaseGamepad(int axesCount, int buttonCount) {
this.axesCount = axesCount;
this.buttonCount = buttonCount;
axes = new float[axesCount];
buttonDown = new boolean[buttonCount];
buttonPressed = new boolean[buttonCount];
}
public int getAxesCount() {
return axesCount;
}
public int getButtonCount() {
return buttonCount;
}
public float getAxis(int i) {
return axes[i];
}
public boolean getButtonDown(int i) {
return buttonDown[i];
}
public boolean getButtonPressed(int i) {
return buttonPressed[i];
}
public void setAxis(int i, float value) {
axes[i] = value;
}
public void setButtonDown(int i, boolean value) {
buttonDown[i] = value;
}
public void setButtonPressed(int i, boolean value) {
buttonPressed[i] = value;
}
public void clearButtonPressed() {
for(int i = 0; i < buttonCount; ++i) {
buttonPressed[i] = false;
}
}
public abstract void tick();
}

View File

@ -1,10 +1,6 @@
package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.backends.gl.Gamepad;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.Image;
import com.danitheskunk.skunkworks.gfx.NineSlice;
import com.danitheskunk.skunkworks.gfx.*;
import com.danitheskunk.skunkworks.gfx.font.IFont;
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
@ -13,8 +9,6 @@ import java.util.List;
public interface IWindow {
Engine getEngine();
BaseGamepad getGamepad(int id);
Vec2i getMousePos();
boolean isMouseClicked(int button);

View File

@ -1,12 +1,8 @@
package com.danitheskunk.skunkworks;
import org.lwjgl.assimp.AIMatrix4x4;
public final class Mat4f {
private final double[] data;
public static Mat4f IDENTITY = new Mat4f();
public Mat4f() {
data = new double[16];
set(0, 0, 1.0);
@ -15,32 +11,6 @@ public final class Mat4f {
set(3, 3, 1.0);
}
public static Mat4f fromAiMat(AIMatrix4x4 aiMat) {
var mat = new Mat4f();
mat.set(0, 0, aiMat.a1());
mat.set(1, 0, aiMat.a2());
mat.set(2, 0, aiMat.a3());
mat.set(3, 0, aiMat.a4());
mat.set(0, 1, aiMat.b1());
mat.set(1, 1, aiMat.b2());
mat.set(2, 1, aiMat.b3());
mat.set(3, 1, aiMat.b4());
mat.set(0, 2, aiMat.c1());
mat.set(1, 2, aiMat.c2());
mat.set(2, 2, aiMat.c3());
mat.set(3, 2, aiMat.c4());
mat.set(0, 3, aiMat.d1());
mat.set(1, 3, aiMat.d2());
mat.set(2, 3, aiMat.d3());
mat.set(3, 3, aiMat.d4());
return mat;
}
public static Mat4f perspective(
double fovy, double aspect, double zNear, double zFar
) {

View File

@ -15,6 +15,14 @@ public class Test extends BaseGame {
public Test() {
super(new Vec2i(40 * 12, 22 * 12), "Skunkworks");
var path = "C:\\Program Files (x86)" +
"\\Steam\\steamapps\\common\\Unreal " +
"Tournament\\System\\UnrealTournament.ini";
var data = engine.loadDataWatched(path);
data.onReload(() -> System.out.println(data.get("URL", "Host")));
var fontThin = window.loadFontTileset("fonts\\thin-6x12.png");
var fontThin2 = window.loadFontTileset("fonts\\thin-12x12.png");
term = new Terminal(new Vec2i(40, 22), fontThin2, fontThin);

View File

@ -2,12 +2,10 @@ package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.audio.ISample;
import com.danitheskunk.skunkworks.nodes.NodeSprite;
import org.lwjgl.glfw.GLFW;
public class TestNode extends BaseGame {
private final ISample kick;
private final NodeSprite sprite;
float[] axes;
public TestNode() {
super(new Vec2i(1280, 720), "Skunkworks");
@ -17,26 +15,13 @@ public class TestNode extends BaseGame {
sprite.setTexture(loadTexture("demoassets/test.png"));
sprite.setPos(new Vec2f(100, 100));
rootNode.add(sprite);
//doThing();
}
void doThing() {
sprite.tweenPos(new Vec2f(800, 400), 120).delay(60).then(() -> {
System.out.println("yay! got there! now lets go home");
sprite.tweenPos(new Vec2f(100, 100), 120).then(this::doThing);
sprite.tweenPos(new Vec2f(100, 100), 120);
playSample(kick);
});
}
@Override
protected void update(double delta) {
sprite.setPos(new Vec2f(640 + 640 * gamepad.getAxis(0), 360 + 360 * gamepad.getAxis(1)));
if(gamepad.getButtonPressed(0)) {
playSample(kick);
}
}
public static void main(String[] args) {
new TestNode().run();
}

View File

@ -1,5 +0,0 @@
package com.danitheskunk.skunkworks.backends.gl;
public class BasePipeline {
}

View File

@ -1,69 +0,0 @@
package com.danitheskunk.skunkworks.backends.gl;
import com.danitheskunk.skunkworks.Vec2i;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL30.*;
import static org.lwjgl.opengl.GL32.glFramebufferTexture;
public class Framebuffer {
private final int framebuffer;
private final int framebufferTex;
public Framebuffer(Vec2i size) {
framebuffer = glGenFramebuffers();
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
framebufferTex = glGenTextures();
glBindTexture(GL_TEXTURE_2D, framebufferTex);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
size.getX(),
size.getY(),
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
0
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
framebufferTex,
0
);
int framebufferDepthTex = glGenTextures();
glBindTexture(GL_TEXTURE_2D, framebufferDepthTex);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_DEPTH_COMPONENT,
size.getX(),
size.getY(),
0,
GL_DEPTH_COMPONENT,
GL_UNSIGNED_BYTE,
0
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT,
framebufferDepthTex,
0
);
}
public void bind() {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
}
public void bindTexture() {
glBindTexture(GL_TEXTURE_2D, framebufferTex);
}
public static void unbind() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
}

View File

@ -1,31 +0,0 @@
package com.danitheskunk.skunkworks.backends.gl;
import com.danitheskunk.skunkworks.BaseGamepad;
import org.lwjgl.glfw.GLFW;
public class Gamepad extends BaseGamepad {
private final int jid;
public Gamepad(int jid) {
super(GLFW.glfwGetJoystickAxes(jid).limit(), GLFW.glfwGetJoystickButtons(jid).limit());
if(!GLFW.glfwJoystickPresent(jid) || !GLFW.glfwJoystickIsGamepad(jid)) {
throw new RuntimeException("gamepad not found");
}
this.jid = jid;
}
@Override
public void tick() {
var axesBuf = GLFW.glfwGetJoystickAxes(jid);
var buttonBuf = GLFW.glfwGetJoystickButtons(jid);
for(int i = 0; i < axesCount; ++i) {
axes[i] = axesBuf.get(i);
}
for(int i = 0; i < buttonCount; ++i) {
var val = buttonBuf.get() != 0;
buttonPressed[i] = !buttonDown[i] && val;
buttonDown[i] = val;
}
}
}

View File

@ -98,7 +98,8 @@ public class Window extends BaseWindow {
out_texCoord = texCoord;
}
""";
private final Framebuffer framebuffer;
private final int framebuffer;
private final int framebufferTex;
private final Program program;
private final Program program3D;
private final Program programScaler;
@ -139,6 +140,7 @@ public class Window extends BaseWindow {
GL.createCapabilities();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(0.0f, size.getX(), size.getY(), 0.0f, 0.0f, 1.0f);
glEnable(GL_COLOR);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -148,7 +150,51 @@ public class Window extends BaseWindow {
glfwSetWindowSizeCallback(window, this::windowSizeCallback);
glfwSetMouseButtonCallback(window, this::mouseButtonCallback);
framebuffer = new Framebuffer(size);
framebuffer = glGenFramebuffers();
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
framebufferTex = glGenTextures();
glBindTexture(GL_TEXTURE_2D, framebufferTex);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
size.getX(),
size.getY(),
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
0
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
framebufferTex,
0
);
int framebufferDepthTex = glGenTextures();
glBindTexture(GL_TEXTURE_2D, framebufferDepthTex);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_DEPTH_COMPONENT,
size.getX(),
size.getY(),
0,
GL_DEPTH_COMPONENT,
GL_UNSIGNED_BYTE,
0
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT,
framebufferDepthTex,
0
);
glDrawBuffers(GL_COLOR_ATTACHMENT0);
textureAtlas = new TextureAtlas();
program = new Program(vertexSource, fragmentSource);
program3D = new Program(vertexSource3D, fragmentSource3D);
@ -180,13 +226,9 @@ public class Window extends BaseWindow {
System.out.println(GL11.glGetInteger(GL_MAX_TEXTURE_SIZE));
}
@Override
public BaseGamepad getGamepad(int id) {
return new Gamepad(id);
}
@Override
public Vec2i getMousePos() {
//todo: scale mouse to stretchMode
double[] x = {0.0};
double[] y = {0.0};
glfwGetCursorPos(window, x, y);
@ -300,7 +342,7 @@ public class Window extends BaseWindow {
public IRenderContext renderStart() {
program.use();
textureAtlas.bind();
framebuffer.bind();
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, size.getX(), size.getY());
textureAtlas.update();
glClearColor(0.f, 0.f, 0.f, 0.0f);
@ -314,7 +356,7 @@ public class Window extends BaseWindow {
public IRenderContext3D renderStart3D() {
program3D.use();
textureAtlas.bind();
framebuffer.bind();
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, size.getX(), size.getY());
textureAtlas.update();
glClearColor(0.f, 0.f, 0.f, 0.0f);
@ -334,14 +376,14 @@ public class Window extends BaseWindow {
//glEnd();
Framebuffer.unbind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, windowSize.getX(), windowSize.getY());
programScaler.use();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
framebuffer.bindTexture();
glBindTexture(GL_TEXTURE_2D, framebufferTex);
glProgramUniform2f(programScaler.getProgram(),
programScaler.getUniformLocation("windowSize"),
windowSize.getX(),

View File

@ -1,47 +0,0 @@
package com.danitheskunk.skunkworks.gfx.threedee;
import com.danitheskunk.skunkworks.Mat4f;
import org.lwjgl.assimp.AIBone;
import java.util.ArrayList;
import java.util.List;
public class Bone {
private String name;
private List<VertexWeight> vertexWeights;
private Mat4f offsetMatrix;
public Bone() {
vertexWeights = new ArrayList<>();
offsetMatrix = Mat4f.IDENTITY;
}
public static Bone fromAIBone(AIBone aiBone) {
var bone = new Bone();
var weightBuffer = aiBone.mWeights();
bone.name = aiBone.mName().dataString();
while(weightBuffer.hasRemaining()) {
var weight = VertexWeight.fromAiWeight(weightBuffer.get());
bone.vertexWeights.add(weight);
}
bone.offsetMatrix = Mat4f.fromAiMat(aiBone.mOffsetMatrix());
var node = aiBone.mNode();
if(node.address() != 0) {
System.out.println(node.mName().dataString());
}
return bone;
}
public VertexWeight getVertexWeight(int i) {
return vertexWeights.get(i);
}
public int getVertexWeightCount() {
return vertexWeights.size();
}
}

View File

@ -4,7 +4,6 @@ import com.danitheskunk.skunkworks.Vec2f;
import com.danitheskunk.skunkworks.Vec3f;
import com.danitheskunk.skunkworks.Vec3i;
import com.danitheskunk.skunkworks.gfx.ITexture;
import org.lwjgl.assimp.AIBone;
import org.lwjgl.assimp.AIMesh;
import java.util.ArrayList;
@ -28,7 +27,6 @@ public class Mesh {
var vertexBuffer = aiMesh.mVertices();
var faceBuffer = aiMesh.mFaces();
var texCoordsBuffer = aiMesh.mTextureCoords(0);
var boneBuffer = aiMesh.mBones();
while(vertexBuffer.remaining() > 0) {
var vert = vertexBuffer.get();
@ -53,13 +51,6 @@ public class Mesh {
mesh.addUV(new Vec2f(x, 1.0 - y));
}
while(boneBuffer.remaining() > 0) {
var aiBone = AIBone.create(boneBuffer.get());
var bone = Bone.fromAIBone(aiBone);
//System.out.printf("bone: %s\n", bone.mName().dataString());
}
return mesh;
}

View File

@ -58,9 +58,6 @@ public class Model {
System.out.printf("tex %dx%d\n", img.getWidth(), img.getHeight());
}
var node = ai.mRootNode();
walkNodes(node);
var numMeshes = ai.mNumMeshes();
var meshPB = ai.mMeshes();
@ -78,16 +75,6 @@ public class Model {
faces += aiMesh.mNumFaces();
}
/*
var animationBuffer = ai.mAnimations();
while(animationBuffer.hasRemaining()) {
var aiAnim = AIAnimation.create(animationBuffer.get());
System.out.printf("anim: %s\n", aiAnim.mName().dataString());
}
*/
//window.setDebug(true);
System.out.printf("numMeshes: %d, faces: %d, textures: %d\n",
@ -97,18 +84,6 @@ public class Model {
);
}
private void walkNodes(AINode node) {
System.out.println(node.mName().dataString());
var childBuffer = node.mChildren();
if(childBuffer == null) {
return;
}
while(childBuffer.hasRemaining()) {
var child = AINode.create(childBuffer.get());
walkNodes(child);
}
}
public int getMeshCount() {
return meshes.length;
}

View File

@ -1,25 +0,0 @@
package com.danitheskunk.skunkworks.gfx.threedee;
import org.lwjgl.assimp.AIVertexWeight;
public class VertexWeight {
private final int index;
private final float weight;
public VertexWeight(int index, float weight) {
this.index = index;
this.weight = weight;
}
public static VertexWeight fromAiWeight(AIVertexWeight aiWeight) {
return new VertexWeight(aiWeight.mVertexId(), aiWeight.mWeight());
}
public int getIndex() {
return index;
}
public float getWeight() {
return weight;
}
}