deleted ITileThing, added depth shader :)
parent
10d86c45ab
commit
7afa863ee8
|
|
@ -9,9 +9,11 @@ attribute vec2 TexCoord;
|
||||||
//"out" varyings to our fragment shader
|
//"out" varyings to our fragment shader
|
||||||
varying vec4 vColor;
|
varying vec4 vColor;
|
||||||
varying vec2 vTexCoord;
|
varying vec2 vTexCoord;
|
||||||
|
varying float vDepth;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vColor = uColor;
|
vColor = uColor;
|
||||||
vTexCoord = TexCoord;
|
vTexCoord = TexCoord;
|
||||||
gl_Position = uProjection * vec4(Position, 1.0);
|
gl_Position = uProjection * vec4(Position, 1.0);
|
||||||
|
vDepth = Position.z;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
//SpriteBatch will use texture unit 0
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
|
//"in" varyings from our vertex shader
|
||||||
|
varying vec4 vColor;
|
||||||
|
varying vec2 vTexCoord;
|
||||||
|
varying float vDepth;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 texColor = texture2D(u_texture, vTexCoord);
|
||||||
|
if(texColor == vec4(1, 0, 1, 1) || texColor == vec4(1, 0, 0, 1) || texColor.w == 0.0) {
|
||||||
|
discard;
|
||||||
|
} else {
|
||||||
|
gl_FragColor = texColor * vColor;
|
||||||
|
gl_FragColor = vec4(vDepth / 20.0, vDepth / 20.0, vDepth / 20.0, gl_FragColor.w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ uniform sampler2D u_texture;
|
||||||
//"in" varyings from our vertex shader
|
//"in" varyings from our vertex shader
|
||||||
varying vec4 vColor;
|
varying vec4 vColor;
|
||||||
varying vec2 vTexCoord;
|
varying vec2 vTexCoord;
|
||||||
|
varying float vDepth;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 texColor = texture2D(u_texture, vTexCoord);
|
vec4 texColor = texture2D(u_texture, vTexCoord);
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ public class Drawing {
|
||||||
public static void drawSprite(Sprite sprite, int x, int y, int width, int height) {
|
public static void drawSprite(Sprite sprite, int x, int y, int width, int height) {
|
||||||
// lazy texture binding
|
// lazy texture binding
|
||||||
if(bound != sprite.atlas) {
|
if(bound != sprite.atlas) {
|
||||||
if(bound != null) bound.unbind();
|
if(bound != null) bound.unbind();
|
||||||
sprite.atlas.bind();
|
sprite.atlas.bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ package xyz.valnet.engine.math;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class TileBox implements Serializable {
|
public class TileBox implements Serializable {
|
||||||
public final int x, y;
|
public final int x, y;
|
||||||
|
|
|
||||||
|
|
@ -100,4 +100,8 @@ public class GameObject implements IRenderable, ITickable, Serializable {
|
||||||
protected void onRemoveGameObject(GameObjectCallback listener) {
|
protected void onRemoveGameObject(GameObjectCallback listener) {
|
||||||
scene.registerRemoveListener(listener);
|
scene.registerRemoveListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void beforeRemoved() {}
|
||||||
|
|
||||||
|
protected void afterRemoved() {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -216,9 +216,11 @@ public abstract class SceneGraph implements IScene {
|
||||||
|
|
||||||
public void remove(GameObject obj) {
|
public void remove(GameObject obj) {
|
||||||
removeObjects.add(obj);
|
removeObjects.add(obj);
|
||||||
|
obj.beforeRemoved();
|
||||||
for(GameObjectCallback listener : onRemoveListeners) {
|
for(GameObjectCallback listener : onRemoveListeners) {
|
||||||
listener.apply(obj);
|
listener.apply(obj);
|
||||||
}
|
}
|
||||||
|
obj.afterRemoved();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean inScene(GameObject gameObject) {
|
public boolean inScene(GameObject gameObject) {
|
||||||
|
|
@ -332,7 +334,6 @@ public abstract class SceneGraph implements IScene {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void keyPress(int key) {
|
public final void keyPress(int key) {
|
||||||
DebugTab.log("keyCode: " + key);
|
|
||||||
keys.add(key);
|
keys.add(key);
|
||||||
for(IKeyboardListener ikbl : getAll(IKeyboardListener.class)) {
|
for(IKeyboardListener ikbl : getAll(IKeyboardListener.class)) {
|
||||||
ikbl.keyPress(key);
|
ikbl.keyPress(key);
|
||||||
|
|
|
||||||
|
|
@ -15,137 +15,137 @@ import xyz.valnet.engine.math.Vector3f;
|
||||||
import xyz.valnet.engine.math.Vector4f;
|
import xyz.valnet.engine.math.Vector4f;
|
||||||
|
|
||||||
public class Shader {
|
public class Shader {
|
||||||
|
|
||||||
private boolean enabled = false;
|
private boolean enabled = false;
|
||||||
|
|
||||||
public final int handle;
|
public final int handle;
|
||||||
|
|
||||||
public final static int POSITION = 0;
|
public final static int POSITION = 0;
|
||||||
|
|
||||||
private Map<String, Integer> locationCache = new HashMap<String, Integer>();
|
private Map<String, Integer> locationCache = new HashMap<String, Integer>();
|
||||||
|
|
||||||
public Shader(String vertPath, String fragPath) {
|
public Shader(String vertPath, String fragPath) {
|
||||||
handle = load(vertPath, fragPath);
|
handle = load(vertPath, fragPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String loadAsString(String file) {
|
private static String loadAsString(String file) {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||||
String buffer = "";
|
String buffer = "";
|
||||||
while ((buffer = reader.readLine()) != null) {
|
while ((buffer = reader.readLine()) != null) {
|
||||||
result.append(buffer + '\n');
|
result.append(buffer + '\n');
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int load(String vertPath, String fragPath) {
|
public int load(String vertPath, String fragPath) {
|
||||||
String vert = Shader.loadAsString(vertPath);
|
String vert = Shader.loadAsString(vertPath);
|
||||||
String frag = Shader.loadAsString(fragPath);
|
String frag = Shader.loadAsString(fragPath);
|
||||||
return create(vert, frag);
|
return create(vert, frag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int create(String vert, String frag) {
|
public int create(String vert, String frag) {
|
||||||
int program = glCreateProgram();
|
int program = glCreateProgram();
|
||||||
int vertID = glCreateShader(GL_VERTEX_SHADER);
|
int vertID = glCreateShader(GL_VERTEX_SHADER);
|
||||||
int fragID = glCreateShader(GL_FRAGMENT_SHADER);
|
int fragID = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
glShaderSource(vertID, vert);
|
glShaderSource(vertID, vert);
|
||||||
glShaderSource(fragID, frag);
|
glShaderSource(fragID, frag);
|
||||||
|
|
||||||
glCompileShader(vertID);
|
glCompileShader(vertID);
|
||||||
if (glGetShaderi(vertID, GL_COMPILE_STATUS) == GL_FALSE) {
|
if (glGetShaderi(vertID, GL_COMPILE_STATUS) == GL_FALSE) {
|
||||||
System.err.println("Failed to compile vertex shader!");
|
System.err.println("Failed to compile vertex shader!");
|
||||||
System.err.println(glGetShaderInfoLog(vertID));
|
System.err.println(glGetShaderInfoLog(vertID));
|
||||||
return -1;
|
throw new Error("Failed to compile vertex shader!");
|
||||||
}
|
}
|
||||||
|
|
||||||
glCompileShader(fragID);
|
glCompileShader(fragID);
|
||||||
if (glGetShaderi(fragID, GL_COMPILE_STATUS) == GL_FALSE) {
|
if (glGetShaderi(fragID, GL_COMPILE_STATUS) == GL_FALSE) {
|
||||||
System.err.println("Failed to compile fragment shader!");
|
System.err.println("Failed to compile fragment shader!");
|
||||||
System.err.println(glGetShaderInfoLog(fragID));
|
System.err.println(glGetShaderInfoLog(fragID));
|
||||||
return -1;
|
throw new Error("Failed to compile fragment shader!");
|
||||||
}
|
}
|
||||||
|
|
||||||
bindAttributes(program);
|
bindAttributes(program);
|
||||||
|
|
||||||
glAttachShader(program, vertID);
|
glAttachShader(program, vertID);
|
||||||
glAttachShader(program, fragID);
|
glAttachShader(program, fragID);
|
||||||
glLinkProgram(program);
|
glLinkProgram(program);
|
||||||
glValidateProgram(program);
|
glValidateProgram(program);
|
||||||
|
|
||||||
glDeleteShader(vertID);
|
glDeleteShader(vertID);
|
||||||
glDeleteShader(fragID);
|
glDeleteShader(fragID);
|
||||||
|
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void bindAttributes(int program) {
|
protected void bindAttributes(int program) {
|
||||||
glBindAttribLocation(program, POSITION, "Position");
|
glBindAttribLocation(program, POSITION, "Position");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUniform(String name) {
|
public int getUniform(String name) {
|
||||||
if (locationCache.containsKey(name))
|
if (locationCache.containsKey(name))
|
||||||
return locationCache.get(name);
|
return locationCache.get(name);
|
||||||
|
|
||||||
int result = glGetUniformLocation(handle, name);
|
int result = glGetUniformLocation(handle, name);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
System.err.println("Could not find uniform variable '" + name + "'!");
|
System.err.println("Could not find uniform variable '" + name + "'!");
|
||||||
else
|
else
|
||||||
locationCache.put(name, result);
|
locationCache.put(name, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUniform1i(String name, int value) {
|
public void setUniform1i(String name, int value) {
|
||||||
if (!enabled) enable();
|
if (!enabled) enable();
|
||||||
glUniform1i(getUniform(name), value);
|
glUniform1i(getUniform(name), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUniform1f(String name, float value) {
|
public void setUniform1f(String name, float value) {
|
||||||
if (!enabled) enable();
|
if (!enabled) enable();
|
||||||
glUniform1f(getUniform(name), value);
|
glUniform1f(getUniform(name), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUniform2f(String name, float x, float y) {
|
public void setUniform2f(String name, float x, float y) {
|
||||||
if (!enabled) enable();
|
if (!enabled) enable();
|
||||||
glUniform2f(getUniform(name), x, y);
|
glUniform2f(getUniform(name), x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUniform3f(String name, Vector3f vector) {
|
public void setUniform3f(String name, Vector3f v) {
|
||||||
if (!enabled) enable();
|
if (!enabled) enable();
|
||||||
glUniform3f(getUniform(name), vector.x, vector.y, vector.z);
|
glUniform3f(getUniform(name), v.x, v.y, v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUniform4f(String name, Vector4f vector) {
|
public void setUniform4f(String name, Vector4f v) {
|
||||||
if (!enabled) enable();
|
if (!enabled) enable();
|
||||||
glUniform4f(getUniform(name), vector.x, vector.y, vector.z, vector.w);
|
glUniform4f(getUniform(name), v.x, v.y, v.z, v.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUniform4f(String name, Color c) {
|
public void setUniform4f(String name, Color c) {
|
||||||
if (!enabled) enable();
|
if (!enabled) enable();
|
||||||
glUniform4f(getUniform(name), c.r, c.g, c.b, c.a);
|
glUniform4f(getUniform(name), c.r, c.g, c.b, c.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUniformMat4f(String name, Matrix4f matrix) {
|
public void setUniformMat4f(String name, Matrix4f matrix) {
|
||||||
if (!enabled) enable();
|
if (!enabled) enable();
|
||||||
glUniformMatrix4fv(getUniform(name), false, matrix.toFloatBuffer());
|
glUniformMatrix4fv(getUniform(name), false, matrix.toFloatBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMatrices (Matrix4f projection) {
|
public void setMatrices (Matrix4f projection) {
|
||||||
setUniformMat4f("uProjection", projection);
|
setUniformMat4f("uProjection", projection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enable() {
|
public void enable() {
|
||||||
glUseProgram(handle);
|
glUseProgram(handle);
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable() {
|
public void disable() {
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public class Job extends GameObject {
|
||||||
|
|
||||||
// pickup and dropoff should be all in one step, as each step should
|
// pickup and dropoff should be all in one step, as each step should
|
||||||
// only need state tracked for the job, not the worker.
|
// only need state tracked for the job, not the worker.
|
||||||
// workers can change between steps.
|
// workers can change between steps.
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class PickupItem extends JobStep {
|
public class PickupItem extends JobStep {
|
||||||
public Item item;
|
public Item item;
|
||||||
|
|
@ -73,7 +73,7 @@ public class Job extends GameObject {
|
||||||
|
|
||||||
// pickup and dropoff should be all in one step, as each step should
|
// pickup and dropoff should be all in one step, as each step should
|
||||||
// only need state tracked for the job, not the worker.
|
// only need state tracked for the job, not the worker.
|
||||||
// workers can change between steps.
|
// workers can change between steps.
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class PickupItemByPredicate extends JobStep {
|
public class PickupItemByPredicate extends JobStep {
|
||||||
public IItemPredicate predicate;
|
public IItemPredicate predicate;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
package xyz.valnet.hadean.gameobjects.terrain;
|
package xyz.valnet.hadean.gameobjects.terrain;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import xyz.valnet.engine.graphics.Color;
|
import xyz.valnet.engine.graphics.Color;
|
||||||
|
|
@ -17,8 +15,8 @@ import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||||
import xyz.valnet.hadean.gameobjects.worldobjects.zones.FarmPlot;
|
import xyz.valnet.hadean.gameobjects.worldobjects.zones.FarmPlot;
|
||||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||||
import xyz.valnet.hadean.interfaces.IPingable;
|
import xyz.valnet.hadean.interfaces.IPingable;
|
||||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
|
||||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||||
|
import xyz.valnet.hadean.interfaces.IWorldObject;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
import xyz.valnet.hadean.util.Assets;
|
||||||
import xyz.valnet.hadean.util.Layers;
|
import xyz.valnet.hadean.util.Layers;
|
||||||
|
|
||||||
|
|
@ -32,11 +30,7 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
private final int tileSelector = (int)Math.floor(Math.random() * 4);
|
private final int tileSelector = (int)Math.floor(Math.random() * 4);
|
||||||
private boolean rocks = false;
|
private boolean rocks = false;
|
||||||
|
|
||||||
private Set<ITileThing> stuff = new HashSet<ITileThing>();
|
private Set<IWorldObject> stuff = new HashSet<IWorldObject>();
|
||||||
// TODO remove remove queue, cause like, we dont iterate over
|
|
||||||
// things? so why remove queue them? that just leads to unneccesary
|
|
||||||
// timing issues. you dumb fuck.
|
|
||||||
private List<ITileThing> toRemove = new ArrayList<ITileThing>();
|
|
||||||
|
|
||||||
public Tile(int x, int y) {
|
public Tile(int x, int y) {
|
||||||
setPosition(x, y);
|
setPosition(x, y);
|
||||||
|
|
@ -75,14 +69,14 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
|
|
||||||
public boolean isTileFree() {
|
public boolean isTileFree() {
|
||||||
if(!isWalkable()) return false;
|
if(!isWalkable()) return false;
|
||||||
for(ITileThing thing : stuff) {
|
for(var thing : stuff) {
|
||||||
if(thing instanceof Item) return false;
|
if(thing instanceof Item) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item pickupByItemPredicate(IItemPredicate itemPredicate) {
|
public Item pickupByItemPredicate(IItemPredicate itemPredicate) {
|
||||||
for(ITileThing thing : stuff) {
|
for(var thing : stuff) {
|
||||||
if(thing instanceof Item) {
|
if(thing instanceof Item) {
|
||||||
Item item = (Item) thing;
|
Item item = (Item) thing;
|
||||||
if(item.matches(itemPredicate)) {
|
if(item.matches(itemPredicate)) {
|
||||||
|
|
@ -94,7 +88,9 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pingThings() {
|
public void pingThings() {
|
||||||
for(ITileThing thing : stuff) {
|
// TODO this is a quick lil workaround for a concurerncy issue.
|
||||||
|
// just clone the items
|
||||||
|
for(var thing : new HashSet<IWorldObject>(stuff)) {
|
||||||
if(thing instanceof IPingable) {
|
if(thing instanceof IPingable) {
|
||||||
((IPingable)thing).ping();
|
((IPingable)thing).ping();
|
||||||
}
|
}
|
||||||
|
|
@ -113,12 +109,13 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
if(west != null) west.pingThings();
|
if(west != null) west.pingThings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void placeThing(ITileThing thing) {
|
public void placeThing(IWorldObject thing) {
|
||||||
|
if(thing == this) return;
|
||||||
|
|
||||||
stuff.add(thing);
|
stuff.add(thing);
|
||||||
if(thing instanceof GameObject) {
|
if(thing instanceof GameObject) {
|
||||||
add((GameObject)thing);
|
add((GameObject)thing);
|
||||||
}
|
}
|
||||||
thing.onPlaced(this);
|
|
||||||
|
|
||||||
pingThings();
|
pingThings();
|
||||||
pingNeighbors();
|
pingNeighbors();
|
||||||
|
|
@ -128,11 +125,12 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends ITileThing> T removeThing(T thing) {
|
public <T extends IWorldObject> T removeThing(T thing) {
|
||||||
if(!(stuff.contains(thing))) return null;
|
if(thing == this) return null;
|
||||||
if(toRemove.contains(thing)) return null;
|
|
||||||
|
|
||||||
toRemove.add(thing);
|
if(!(stuff.contains(thing))) return null;
|
||||||
|
|
||||||
|
stuff.remove(thing);
|
||||||
|
|
||||||
pingThings();
|
pingThings();
|
||||||
pingNeighbors();
|
pingNeighbors();
|
||||||
|
|
@ -141,21 +139,7 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float dTime) {
|
public void update(float dTime) {}
|
||||||
for(ITileThing thing : stuff) {
|
|
||||||
if(thing.shouldRemove()) {
|
|
||||||
toRemove.add(thing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(ITileThing thing : toRemove) {
|
|
||||||
stuff.remove(thing);
|
|
||||||
thing.onRemove();
|
|
||||||
if(thing instanceof GameObject) {
|
|
||||||
remove((GameObject)thing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
toRemove.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
|
|
@ -174,7 +158,7 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWalkable() {
|
public boolean isWalkable() {
|
||||||
for(ITileThing thing : stuff) {
|
for(var thing : stuff) {
|
||||||
if(!thing.isWalkable()) return false;
|
if(!thing.isWalkable()) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -222,14 +206,14 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
public String toThingsString() {
|
public String toThingsString() {
|
||||||
if(stuff.size() == 0) return " - Nothing";
|
if(stuff.size() == 0) return " - Nothing";
|
||||||
String str = "";
|
String str = "";
|
||||||
for(ITileThing thing : stuff) {
|
for(var thing : stuff) {
|
||||||
str += " - " + thing + "\n";
|
str += " - " + thing + "\n";
|
||||||
}
|
}
|
||||||
return str.stripTrailing();
|
return str.stripTrailing();
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> boolean has(Class<T> clazz) {
|
public <T> boolean has(Class<T> clazz) {
|
||||||
for(ITileThing thing : stuff) {
|
for(var thing : stuff) {
|
||||||
if(clazz.isInstance(thing)) {
|
if(clazz.isInstance(thing)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
||||||
BuildTab.registerBuildable(Wall.class);
|
BuildTab.registerBuildable(Wall.class);
|
||||||
|
|
||||||
BuildTab.registerBuildable(Quarry.class);
|
BuildTab.registerBuildable(Quarry.class);
|
||||||
|
|
||||||
BuildTab.registerBuildable(FarmPlot.class);
|
BuildTab.registerBuildable(FarmPlot.class);
|
||||||
BuildTab.registerBuildable(Stockpile.class);
|
BuildTab.registerBuildable(Stockpile.class);
|
||||||
BuildTab.registerBuildable(MasonWorkshop.class);
|
BuildTab.registerBuildable(MasonWorkshop.class);
|
||||||
|
|
|
||||||
|
|
@ -76,10 +76,20 @@ public class DebugTab extends Tab implements IKeyboardListener {
|
||||||
log(obj.toString());
|
log(obj.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean keyTest = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPress(int code) {
|
public void keyPress(int code) {
|
||||||
|
if(keyTest) {
|
||||||
|
DebugTab.log("Key Code:" + code);
|
||||||
|
keyTest = false;
|
||||||
|
}
|
||||||
if(code == 96) { // tilde
|
if(code == 96) { // tilde
|
||||||
evoke();
|
evoke();
|
||||||
|
} else if(code == 281) { // insert? top row second to last
|
||||||
|
keyTest = true;
|
||||||
|
} else if(code == 301) { // f12
|
||||||
|
HadeanGame.debugView = !HadeanGame.debugView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,34 @@
|
||||||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||||
|
|
||||||
import xyz.valnet.engine.math.TileBox;
|
import xyz.valnet.engine.math.TileBox;
|
||||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
import xyz.valnet.hadean.gameobjects.ui.Popup;
|
||||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
|
||||||
import xyz.valnet.hadean.util.Action;
|
import xyz.valnet.hadean.util.Action;
|
||||||
import xyz.valnet.hadean.util.detail.Detail;
|
import xyz.valnet.hadean.util.detail.Detail;
|
||||||
|
|
||||||
public abstract class Buildable extends WorldObject implements IBuildable, ITileThing, ISelectable {
|
// Buildable, means its in the build menu
|
||||||
|
public abstract class Buildable extends WorldObject implements IBuildable, ISelectable {
|
||||||
|
|
||||||
|
public static Action CANCEL = new Action("Cancel");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildAt(TileBox box) {
|
public void buildAt(TileBox box) {
|
||||||
setPosition(box.asBox());
|
setPosition(box.asBox());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlaced(Tile tile) {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action[] getActions() {
|
public Action[] getActions() {
|
||||||
return new Action[] {};
|
return new Action[] {
|
||||||
|
CANCEL
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runAction(Action action) {
|
public void runAction(Action action) {
|
||||||
|
if(action == CANCEL) {
|
||||||
|
add(new Popup());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Log;
|
import xyz.valnet.hadean.gameobjects.worldobjects.items.Log;
|
||||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
|
||||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||||
import xyz.valnet.hadean.util.Action;
|
import xyz.valnet.hadean.util.Action;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
import xyz.valnet.hadean.util.Assets;
|
||||||
|
|
@ -16,7 +15,7 @@ import xyz.valnet.hadean.util.detail.BooleanDetail;
|
||||||
import xyz.valnet.hadean.util.detail.Detail;
|
import xyz.valnet.hadean.util.detail.Detail;
|
||||||
import xyz.valnet.hadean.util.detail.PercentDetail;
|
import xyz.valnet.hadean.util.detail.PercentDetail;
|
||||||
|
|
||||||
public class Tree extends WorldObject implements ITileThing, ISelectable, IWorkable {
|
public class Tree extends WorldObject implements ISelectable, IWorkable {
|
||||||
|
|
||||||
private Job chopJob = null;
|
private Job chopJob = null;
|
||||||
|
|
||||||
|
|
@ -85,6 +84,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
|
||||||
@Override
|
@Override
|
||||||
public boolean doWork(float dTime) {
|
public boolean doWork(float dTime) {
|
||||||
choppage += dTime;
|
choppage += dTime;
|
||||||
|
if(getProgress() >= 1.0) remove(this);
|
||||||
return getProgress() >= 1;
|
return getProgress() >= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,12 +110,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldRemove() {
|
protected void beforeRemoved() {
|
||||||
return getProgress() >= 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemove() {
|
|
||||||
Vector2i pos = getWorldPosition().xy();
|
Vector2i pos = getWorldPosition().xy();
|
||||||
add(new Log(pos.x, pos.y));
|
add(new Log(pos.x, pos.y));
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +124,4 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Tree";
|
return "Tree";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlaced(Tile tile) {}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,10 @@ import xyz.valnet.engine.scenegraph.GameObject;
|
||||||
import xyz.valnet.hadean.gameobjects.Camera;
|
import xyz.valnet.hadean.gameobjects.Camera;
|
||||||
import xyz.valnet.hadean.gameobjects.terrain.Terrain;
|
import xyz.valnet.hadean.gameobjects.terrain.Terrain;
|
||||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
|
||||||
import xyz.valnet.hadean.interfaces.IWorldObject;
|
import xyz.valnet.hadean.interfaces.IWorldObject;
|
||||||
|
|
||||||
public abstract class WorldObject extends GameObject implements IWorldObject {
|
public abstract class WorldObject extends GameObject implements IWorldObject {
|
||||||
|
|
||||||
// TODO make it just a box lawl
|
// TODO make it just a box lawl
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
|
|
@ -40,11 +39,11 @@ public abstract class WorldObject extends GameObject implements IWorldObject {
|
||||||
@Override
|
@Override
|
||||||
protected void start() {
|
protected void start() {
|
||||||
setPosition(x, y, w, h);
|
setPosition(x, y, w, h);
|
||||||
|
getTile().placeThing(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTileLinks(Set<Tile> tiles) {
|
private void updateTileLinks(Set<Tile> tiles) {
|
||||||
if(tiles == null || tiles.size() == 0) return;
|
if(tiles == null || tiles.size() == 0) return;
|
||||||
if(!(this instanceof ITileThing)) return;
|
|
||||||
|
|
||||||
Set<Tile> removeTiles = new HashSet<Tile>();
|
Set<Tile> removeTiles = new HashSet<Tile>();
|
||||||
Set<Tile> addTiles = new HashSet<Tile>();
|
Set<Tile> addTiles = new HashSet<Tile>();
|
||||||
|
|
@ -61,16 +60,12 @@ public abstract class WorldObject extends GameObject implements IWorldObject {
|
||||||
|
|
||||||
for(Tile tile : removeTiles) {
|
for(Tile tile : removeTiles) {
|
||||||
linkedTiles.remove(tile);
|
linkedTiles.remove(tile);
|
||||||
if(this instanceof ITileThing) {
|
tile.removeThing(this);
|
||||||
tile.removeThing((ITileThing) this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Tile tile : addTiles) {
|
for(Tile tile : addTiles) {
|
||||||
linkedTiles.add(tile);
|
linkedTiles.add(tile);
|
||||||
if(this instanceof ITileThing) {
|
tile.placeThing(this);
|
||||||
tile.placeThing((ITileThing) this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(linkedTiles.size() == 0 && inScene()) {
|
if(linkedTiles.size() == 0 && inScene()) {
|
||||||
|
|
|
||||||
|
|
@ -236,4 +236,10 @@ public class Pawn extends Agent {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Item> inventory = new ArrayList<Item>();
|
private List<Item> inventory = new ArrayList<Item>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWalkable() {
|
||||||
|
// TODO thiss could be an interesting mechanic, but it may be bad
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,6 @@ public class Bed extends Construction {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRemove() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemove() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IItemPredicate getBuildingMaterial() {
|
protected IItemPredicate getBuildingMaterial() {
|
||||||
return Log.LOG_PREDICATE;
|
return Log.LOG_PREDICATE;
|
||||||
|
|
|
||||||
|
|
@ -103,16 +103,6 @@ public abstract class Construction extends Buildable {
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean isWalkable();
|
public abstract boolean isWalkable();
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRemove() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemove() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
|
|
@ -159,9 +149,6 @@ public abstract class Construction extends Buildable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action[] getActions() {
|
public Action[] getActions() {
|
||||||
return new Action[0];
|
return super.getActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void runAction(Action action) {}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,15 +54,6 @@ public class Quarry extends Construction {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRemove() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemove() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Quarry";
|
return "Quarry";
|
||||||
|
|
|
||||||
|
|
@ -41,16 +41,6 @@ public class Wall extends Construction implements IPingable {
|
||||||
return !isBuilt();
|
return !isBuilt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRemove() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemove() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private EnumSet<Direction> wallSides = EnumSet.noneOf(Direction.class);
|
private EnumSet<Direction> wallSides = EnumSet.noneOf(Direction.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -30,14 +30,6 @@ public class Boulder extends Item {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRemove() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemove() {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Detail[] getDetails() {
|
public Detail[] getDetails() {
|
||||||
return new Detail[] {};
|
return new Detail[] {};
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,14 @@ import xyz.valnet.engine.math.Vector2i;
|
||||||
import xyz.valnet.engine.math.Vector4i;
|
import xyz.valnet.engine.math.Vector4i;
|
||||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
|
||||||
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
||||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
|
||||||
import xyz.valnet.hadean.util.Action;
|
import xyz.valnet.hadean.util.Action;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
import xyz.valnet.hadean.util.Assets;
|
||||||
import xyz.valnet.hadean.util.Layers;
|
import xyz.valnet.hadean.util.Layers;
|
||||||
|
|
||||||
public abstract class Item extends WorldObject implements ISelectable, ITileThing {
|
public abstract class Item extends WorldObject implements ISelectable {
|
||||||
protected JobBoard jobboard;
|
protected JobBoard jobboard;
|
||||||
|
|
||||||
private Job haulJob = null;
|
private Job haulJob = null;
|
||||||
|
|
@ -84,17 +82,10 @@ public abstract class Item extends WorldObject implements ISelectable, ITileThin
|
||||||
jobboard.postJob(haulJob);
|
jobboard.postJob(haulJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlaced(Tile tile) {
|
|
||||||
setPosition(tile.getWorldPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(IItemPredicate itemPredicate) {
|
public boolean matches(IItemPredicate itemPredicate) {
|
||||||
return itemPredicate.matches(this);
|
return itemPredicate.matches(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setPosition(Vector4i vector) {
|
public void setPosition(Vector4i vector) {
|
||||||
super.setPosition(vector);
|
super.setPosition(vector);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,14 +30,6 @@ public class Log extends Item {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRemove() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemove() {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Detail[] getDetails() {
|
public Detail[] getDetails() {
|
||||||
return new Detail[] {};
|
return new Detail[] {};
|
||||||
|
|
|
||||||
|
|
@ -46,24 +46,11 @@ public class FarmPlot extends Zone {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRemove() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemove() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Farm Plot";
|
return "Farm Plot";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlaced(Tile tile) {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ISelectable.Priority getSelectPriority() {
|
public ISelectable.Priority getSelectPriority() {
|
||||||
return ISelectable.Priority.LOW;
|
return ISelectable.Priority.LOW;
|
||||||
|
|
|
||||||
|
|
@ -61,24 +61,11 @@ public class Stockpile extends Zone {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRemove() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemove() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Stockpile";
|
return "Stockpile";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlaced(Tile tile) {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ISelectable.Priority getSelectPriority() {
|
public ISelectable.Priority getSelectPriority() {
|
||||||
return ISelectable.Priority.LOW;
|
return ISelectable.Priority.LOW;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
package xyz.valnet.hadean.interfaces;
|
|
||||||
|
|
||||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
|
||||||
|
|
||||||
public interface ITileThing {
|
|
||||||
public boolean isWalkable();
|
|
||||||
public boolean shouldRemove();
|
|
||||||
public void onRemove();
|
|
||||||
public void onPlaced(Tile tile);
|
|
||||||
}
|
|
||||||
|
|
@ -4,4 +4,5 @@ import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||||
|
|
||||||
public interface IWorldObject {
|
public interface IWorldObject {
|
||||||
public Tile getTile(int x, int y);
|
public Tile getTile(int x, int y);
|
||||||
|
public boolean isWalkable();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package xyz.valnet.hadean.util;
|
package xyz.valnet.hadean.util;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO consider making this an enum?
|
||||||
public class Action {
|
public class Action {
|
||||||
public final String name;
|
public final String name;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,12 @@ public class Assets {
|
||||||
|
|
||||||
|
|
||||||
public static final SimpleShader flat;
|
public static final SimpleShader flat;
|
||||||
|
public static final SimpleShader depth;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
DebugTab.log("=== [ LOADING ASSETS ] ===");
|
DebugTab.log("=== [ LOADING ASSETS ] ===");
|
||||||
flat = new SimpleShader("res/shaders/flat.vert", "res/shaders/flat.frag");
|
flat = new SimpleShader("res/shaders/base.vert", "res/shaders/flat.frag");
|
||||||
|
depth = new SimpleShader("res/shaders/base.vert", "res/shaders/depth.frag");
|
||||||
|
|
||||||
atlas = new Texture("res/textures.png");
|
atlas = new Texture("res/textures.png");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue