diff --git a/src/main/java/basewindow/BaseFontRenderer.java b/src/main/java/basewindow/BaseFontRenderer.java index a066a697..0f1fd36a 100755 --- a/src/main/java/basewindow/BaseFontRenderer.java +++ b/src/main/java/basewindow/BaseFontRenderer.java @@ -2,11 +2,11 @@ public abstract class BaseFontRenderer { - public BaseWindow home; + public BaseWindow window; public BaseFontRenderer(BaseWindow h) { - this.home = h; + this.window = h; } public abstract void drawString(double x, double y, double z, double sX, double sY, String s); diff --git a/src/main/java/basewindow/BaseShapeRenderer.java b/src/main/java/basewindow/BaseShapeRenderer.java new file mode 100755 index 00000000..31822573 --- /dev/null +++ b/src/main/java/basewindow/BaseShapeRenderer.java @@ -0,0 +1,74 @@ +package basewindow; + +public abstract class BaseShapeRenderer +{ + public boolean supportsBatching = false; + + public abstract void fillOval(double x, double y, double sX, double sY); + + public abstract void fillOval(double x, double y, double z, double sX, double sY, boolean depthTest); + + public abstract void fillPartialOval(double x, double y, double sX, double sY, double start, double end); + + public abstract void fillFacingOval(double x, double y, double z, double sX, double sY, boolean depthTest); + + public abstract void fillGlow(double x, double y, double sX, double sY); + + public abstract void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest); + + public abstract void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest); + + public abstract void fillGlow(double x, double y, double sX, double sY, boolean shade); + + public abstract void fillGlow(double x, double y, double sX, double sY, boolean shade, boolean light); + + public abstract void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade); + + public abstract void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light); + + public abstract void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade); + + public abstract void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light); + + public abstract void drawOval(double x, double y, double sX, double sY); + + public abstract void drawOval(double x, double y, double z, double sX, double sY); + + public abstract void fillRect(double x, double y, double sX, double sY); + + public abstract void fillBox(double x, double y, double z, double sX, double sY, double sZ); + + public abstract void fillBox(double x, double y, double z, double sX, double sY, double sZ, byte options); + + public abstract void fillQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4); + + public abstract void fillQuadBox(double x1, double y1, + double x2, double y2, + double x3, double y3, + double x4, double y4, + double z, double sZ, + byte options); + + public abstract void drawRect(double x, double y, double sX, double sY); + + public abstract void drawImage(double x, double y, double sX, double sY, String image, boolean scaled); + + public abstract void drawImage(double x, double y, double z, double sX, double sY, String image, boolean scaled); + + public abstract void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled); + + public abstract void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled); + + public abstract void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled, boolean depthtest); + + public abstract void drawImage(double x, double y, double sX, double sY, String image, double rotation, boolean scaled); + + public abstract void drawImage(double x, double y, double z, double sX, double sY, String image, double rotation, boolean scaled); + + public abstract void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled); + + public abstract void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled); + + public abstract void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled, boolean depthtest); + +} diff --git a/src/main/java/basewindow/BaseWindow.java b/src/main/java/basewindow/BaseWindow.java index 1b398c4a..558b40db 100755 --- a/src/main/java/basewindow/BaseWindow.java +++ b/src/main/java/basewindow/BaseWindow.java @@ -1,7 +1,7 @@ package basewindow; import basewindow.transformation.*; -import lwjglwindow.ShadowMap; +import lwjglwindow.ImmediateModeModelPart; import java.net.URL; import java.util.ArrayList; @@ -9,6 +9,7 @@ public abstract class BaseWindow { + public BaseShapeRenderer shapeRenderer; public BaseFontRenderer fontRenderer; public boolean angled = false; @@ -23,6 +24,12 @@ public abstract class BaseWindow public double absoluteMouseX; public double absoluteMouseY; + public double colorR; + public double colorG; + public double colorB; + public double colorA; + public double glow; + public boolean fullscreen; public HashMap touchPoints = new HashMap(); @@ -89,6 +96,8 @@ public abstract class BaseWindow public BasePlatformHandler platformHandler; + public ModelPart.ShapeDrawer shapeDrawer; + public BaseWindow(String name, int x, int y, int z, IUpdater u, IDrawer d, IWindowHandler w, boolean vsync, boolean showMouse) { this.name = name; @@ -100,6 +109,7 @@ public BaseWindow(String name, int x, int y, int z, IUpdater u, IDrawer d, IWind this.vsync = vsync; this.windowHandler = w; this.showMouseOnLaunch = showMouse; + this.shapeDrawer = new ImmediateModeModelPart.ImmediateModeShapeDrawer(this); if (System.getProperties().toString().contains("Mac OS X")) mac = true; @@ -164,85 +174,18 @@ public void stopTiming() public abstract void setIcon(String icon); - public abstract void fillOval(double x, double y, double sX, double sY); - - public abstract void fillOval(double x, double y, double z, double sX, double sY, boolean depthTest); - - public abstract void fillPartialOval(double x, double y, double sX, double sY, double start, double end); - - public abstract void fillFacingOval(double x, double y, double z, double sX, double sY, boolean depthTest); - - public abstract void fillGlow(double x, double y, double sX, double sY); - - public abstract void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest); - - public abstract void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest); - - public abstract void fillGlow(double x, double y, double sX, double sY, boolean shade); - - public abstract void fillGlow(double x, double y, double sX, double sY, boolean shade, boolean light); - - public abstract void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade); - - public abstract void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light); - - public abstract void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade); - - public abstract void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light); - public abstract void setColor(double r, double g, double b, double a, double glow); public abstract void setColor(double r, double g, double b, double a); public abstract void setColor(double r, double g, double b); - public abstract void drawOval(double x, double y, double sX, double sY); - - public abstract void drawOval(double x, double y, double z, double sX, double sY); - - public abstract void fillRect(double x, double y, double sX, double sY); - - public abstract void fillBox(double x, double y, double z, double sX, double sY, double sZ); - - public abstract void fillBox(double x, double y, double z, double sX, double sY, double sZ, byte options); - - public abstract void fillQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4); - - public abstract void fillQuadBox(double x1, double y1, - double x2, double y2, - double x3, double y3, - double x4, double y4, - double z, double sZ, - byte options); - - public abstract void drawRect(double x, double y, double sX, double sY); - public abstract void setUpPerspective(); public abstract void applyTransformations(); public abstract void loadPerspective(); - public abstract void drawImage(double x, double y, double sX, double sY, String image, boolean scaled); - - public abstract void drawImage(double x, double y, double z, double sX, double sY, String image, boolean scaled); - - public abstract void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled); - - public abstract void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled); - - public abstract void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled, boolean depthtest); - - public abstract void drawImage(double x, double y, double sX, double sY, String image, double rotation, boolean scaled); - - public abstract void drawImage(double x, double y, double z, double sX, double sY, String image, double rotation, boolean scaled); - - public abstract void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled); - - public abstract void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled); - - public abstract void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled, boolean depthtest); - public abstract String getClipboard(); public abstract void setClipboard(String s); @@ -271,6 +214,12 @@ public abstract void fillQuadBox(double x1, double y1, public abstract void setBatchMode(boolean enabled, boolean quads, boolean depth, boolean glow, boolean depthMask); + public abstract void setTextureCoords(double u, double v); + + public abstract void setTexture(String image); + + public abstract void stopTexture(); + public abstract void addVertex(double x, double y, double z); public abstract void addVertex(double x, double y); @@ -283,6 +232,12 @@ public abstract void fillQuadBox(double x1, double y1, public abstract void setLighting(double light, double glowLight, double shadow, double glowShadow); + public abstract ModelPart createModelPart(); + + public abstract ModelPart createModelPart(Model model, ArrayList shapes, Model.Material material); + + public abstract PosedModel createPosedModel(Model m); + public void setupKeyCodes() { keyNames.put(InputCodes.KEY_UNKNOWN, "Unknown key"); diff --git a/src/main/java/basewindow/ComputerFileManager.java b/src/main/java/basewindow/ComputerFileManager.java index 79efdf0b..9021c8e7 100755 --- a/src/main/java/basewindow/ComputerFileManager.java +++ b/src/main/java/basewindow/ComputerFileManager.java @@ -1,5 +1,6 @@ package basewindow; +import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Scanner; @@ -15,7 +16,12 @@ public BaseFile getFile(String file) @Override public ArrayList getInternalFileContents(String file) { - Scanner s = new Scanner(new InputStreamReader(getClass().getResourceAsStream(file))); + InputStream st = getClass().getResourceAsStream(file); + + if (st == null) + return null; + + Scanner s = new Scanner(new InputStreamReader(st)); ArrayList al = new ArrayList(); while (s.hasNext()) diff --git a/src/main/java/basewindow/IModel.java b/src/main/java/basewindow/IModel.java new file mode 100755 index 00000000..b65c13fc --- /dev/null +++ b/src/main/java/basewindow/IModel.java @@ -0,0 +1,7 @@ +package basewindow; + +public interface IModel +{ + void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll, boolean depthTest); + void draw(double posX, double posY, double sX, double sY, double yaw); +} diff --git a/src/main/java/basewindow/Model.java b/src/main/java/basewindow/Model.java new file mode 100755 index 00000000..0ec8253c --- /dev/null +++ b/src/main/java/basewindow/Model.java @@ -0,0 +1,351 @@ +package basewindow; + +import java.util.ArrayList; +import java.util.HashMap; + +public class Model +{ + public static Material defaultMaterial = new Material(""); + + public ArrayList points; + public ArrayList texCoords; + public ArrayList normals; + public ArrayList colors; + public HashMap materials; + public ArrayList bones; + + public ModelPart[] models; + public BaseWindow window; + + public double[] bonesMatrix = new double[]{1, 0, 0, 0, 1, 0, 0, 0, 1}; + + public Model(BaseWindow window, BaseFileManager fileManager, String dir) + { + this(window, dir, getModelFilesContent(fileManager, dir)); + } + + public static ArrayList getModelFilesContent(BaseFileManager fileManager, String dir) + { + ArrayList lines = fileManager.getInternalFileContents(dir + "model.mtl"); + + if (lines == null) + lines = fileManager.getInternalFileContents(dir + "model.obj"); + else + lines.addAll(fileManager.getInternalFileContents(dir + "model.obj")); + + return lines; + } + + public Model(BaseWindow window, String dir, ArrayList lines) + { + this(); + + this.window = window; + + Material current = null; + this.materials.put("default", Model.defaultMaterial); + + int bones = 0; + for (String s : lines) + { + if (s.startsWith("newmtl ")) + { + String n = s.split(" ")[1]; + current = new Material(n); + materials.put(n, current); + } + + if (s.startsWith("map_Ka ")) + { + if (current != null) + current.texture = dir + s.split(" ")[1]; + } + + if (s.startsWith("dm ")) + { + if (current != null) + { + current.depthMask = Boolean.parseBoolean(s.split(" ")[1]); + current.useDefaultDepthMask = false; + } + } + + if (s.startsWith("col ")) + { + if (current != null) + { + String[] parts = s.split(" "); + current.colorR = Double.parseDouble(parts[1]); + current.colorG = Double.parseDouble(parts[2]); + current.colorB = Double.parseDouble(parts[3]); + + if (parts.length >= 5) + current.colorA = Double.parseDouble(parts[4]); + } + } + + if (s.startsWith("glow ")) + { + if (current != null) + { + current.glow = Boolean.parseBoolean(s.split(" ")[1]); + } + } + + if (s.startsWith("gm ")) + { + String[] sections = s.split(" "); + + for (int i = 0; i < 9; i++) + { + this.bonesMatrix[i] = Double.parseDouble(sections[i + 1]); + } + } + + if (s.startsWith("g ")) + { + String[] sections = s.split(" "); + this.bones.add(new Bone(sections[1], this.bonesMatrix, bones, Double.parseDouble(sections[2]), -Double.parseDouble(sections[3]), Double.parseDouble(sections[4]))); + bones++; + } + + if (s.startsWith("gp ")) + { + String[] sections = s.split(" "); + this.bones.get(Integer.parseInt(sections[1]) - 1).setParent(this.bones.get(Integer.parseInt(sections[2]) - 1)); + } + + if (s.startsWith("v ")) + { + String[] sections = s.split(" "); + this.points.add(new ModelPart.Point(Double.parseDouble(sections[1]), -Double.parseDouble(sections[2]), Double.parseDouble(sections[3]))); + } + + if (s.startsWith("vt ")) + { + String[] sections = s.split(" "); + this.texCoords.add(new ModelPart.Point(Double.parseDouble(sections[1]), 1 - Double.parseDouble(sections[2]), 0)); + } + + if (s.startsWith("vn ")) + { + String[] sections = s.split(" "); + this.normals.add(new ModelPart.Point(Double.parseDouble(sections[1]), Double.parseDouble(sections[2]), Double.parseDouble(sections[3]))); + } + + if (s.startsWith("vc ")) + { + String[] sections = s.split(" "); + this.colors.add(new double[]{Double.parseDouble(sections[1]), Double.parseDouble(sections[2]), Double.parseDouble(sections[3]), Double.parseDouble(sections[4])}); + } + + if (s.startsWith("vg ")) + { + String[] sections = s.split(" "); + + ModelPart.Point p = this.points.get(Integer.parseInt(sections[1])); + int l = sections.length / 2 - 1; + + p.bones = new Bone[l]; + p.boneWeights = new double[l]; + + int in = 0; + double sum = 0; + + for (int i = 2; i < sections.length; i += 2) + { + p.bones[in] = this.bones.get(Integer.parseInt(sections[i]) - 1); + p.boneWeights[in] = Double.parseDouble(sections[i + 1]); + sum += p.boneWeights[in]; + in++; + } + } + } + + ArrayList parts = new ArrayList<>(); + ArrayList shapes = new ArrayList<>(); + current = Model.defaultMaterial; + + boolean facesAdded = false; + + for (String s : lines) + { + if (s.startsWith("usemtl ")) + { + if (facesAdded) + { + ModelPart m = window.createModelPart(this, shapes, current); + parts.add(m); + m.processShapes(); + shapes.clear(); + } + + current = materials.get(s.split(" ")[1]); + } + + if (s.startsWith("f ")) + { + facesAdded = true; + String[] sections = s.split(" "); + if (sections.length == 5) + { + int[] v1 = objToIndex(sections[1].split("/")); + int[] v2 = objToIndex(sections[2].split("/")); + int[] v3 = objToIndex(sections[3].split("/")); + int[] v4 = objToIndex(sections[4].split("/")); + this.addTriangle(shapes, v1, v2, v3); + this.addTriangle(shapes, v1, v4, v3); + } + else if (sections.length == 4) + { + int[] v1 = objToIndex(sections[1].split("/")); + int[] v2 = objToIndex(sections[2].split("/")); + int[] v3 = objToIndex(sections[3].split("/")); + this.addTriangle(shapes, v1, v2, v3); + } + } + } + + ModelPart m = window.createModelPart(this, shapes, current); + parts.add(m); + m.processShapes(); + + this.models = new ModelPart[parts.size()]; + + int index = 0; + + for (ModelPart mo: parts) + { + if (mo.material == null || mo.material.depthMask) + { + this.models[index] = mo; + index++; + } + } + + for (ModelPart mo: parts) + { + if (mo.material != null && !mo.material.depthMask) + { + this.models[index] = mo; + index++; + } + } + } + + public Model() + { + this.materials = new HashMap<>(); + + this.points = new ArrayList<>(); + this.texCoords = new ArrayList<>(); + this.normals = new ArrayList<>(); + this.colors = new ArrayList<>(); + this.bones = new ArrayList<>(); + + this.points.add(new ModelPart.Point(0, 0, 0)); + this.texCoords.add(new ModelPart.Point(0, 0, 0)); + this.normals.add(new ModelPart.Point(0, 0, 0)); + this.colors.add(new double[]{1, 1, 1, 1}); + } + + public static int[] objToIndex(String[] s) + { + int[] i = new int[]{0, 0, 0, 0}; + + for (int n = 0; n < s.length; n++) + { + if (!s[n].equals("")) + i[n] = Integer.parseInt(s[n]); + } + + return i; + } + + public void addTriangle(ArrayList shapes, int[] v1, int[] v2, int[] v3) + { + shapes.add(new ModelPart.Triangle(this.points.get(v1[0]), this.points.get(v2[0]), this.points.get(v3[0]), + this.texCoords.get(v1[1]), this.texCoords.get(v2[1]), this.texCoords.get(v3[1]), + this.normals.get(v1[2]), this.normals.get(v2[2]), this.normals.get(v3[2]), + this.colors.get(v1[3]), this.colors.get(v2[3]), this.colors.get(v3[3]))); + } + + public void draw(double posX, double posY, double sX, double sY, double yaw) + { + for (ModelPart m: this.models) + m.draw(posX, posY, sX, sY, yaw); + } + + public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll, boolean depthTest) + { + for (ModelPart m: this.models) + m.draw(posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll, depthTest); + } + + public static class Material + { + public String name; + public String texture; + public boolean depthMask = true; + public boolean useDefaultDepthMask = true; + public boolean glow = false; + + public double colorR = 1; + public double colorG = 1; + public double colorB = 1; + public double colorA = 1; + + public Material(String name) + { + this.name = name; + } + } + + public static class Bone + { + public double posX; + public double posY; + public double posZ; + + public double offX; + public double offY; + public double offZ; + + public Bone parent; + public String name; + + public int index; + + public Bone(String name, int index, double x, double y, double z) + { + this.name = name; + this.index = index; + this.posX = x; + this.posY = -y; + this.posZ = z; + this.offX = x; + this.offY = -y; + this.offZ = z; + } + + public Bone(String name, double[] matrix, int index, double x, double y, double z) + { + this.name = name; + this.index = index; + this.posX = matrix[0] * x + matrix[1] * y + matrix[2] * z; + this.posY = matrix[3] * x + matrix[4] * y + matrix[5] * z; + this.posZ = matrix[6] * x + matrix[7] * y + matrix[8] * z; + this.offX = posX; + this.offY = posY; + this.offZ = posZ; + } + + public void setParent(Bone b) + { + this.parent = b; + this.offX = this.posX - b.posX; + this.offY = this.posY - b.posY; + this.offZ = this.posZ - b.posZ; + } + } +} diff --git a/src/main/java/basewindow/ModelPart.java b/src/main/java/basewindow/ModelPart.java new file mode 100755 index 00000000..2de4886f --- /dev/null +++ b/src/main/java/basewindow/ModelPart.java @@ -0,0 +1,150 @@ +package basewindow; + +import java.util.ArrayList; + +public abstract class ModelPart implements IModel +{ + public Model.Material material = null; + public Shape[] shapes; + public Model parent; + + public static abstract class Shape + { + public double brightness = 1; + public Point[] points; + public Point[] texCoords; + public Point[] normals; + public double[][] colors; + } + + public static class Point + { + public double x; + public double y; + public double z; + + public Model.Bone[] bones; + public double[] boneWeights; + + public Point(double x, double y, double z) + { + this.x = x; + this.y = y; + this.z = z; + } + } + + public static class Triangle extends Shape + { + public Triangle(Point a, Point b, Point c, double brightness) + { + this.points = new Point[3]; + this.points[0] = a; + this.points[1] = b; + this.points[2] = c; + this.brightness = brightness; + } + + public Triangle(Point a, Point b, Point c, Point ta, Point tb, Point tc, Point na, Point nb, Point nc, double[] ca, double[] cb, double[] cc) + { + this.points = new Point[3]; + this.points[0] = a; + this.points[1] = b; + this.points[2] = c; + + this.texCoords = new Point[3]; + this.texCoords[0] = ta; + this.texCoords[1] = tb; + this.texCoords[2] = tc; + + this.normals = new Point[3]; + this.normals[0] = na; + this.normals[1] = nb; + this.normals[2] = nc; + + this.colors = new double[3][]; + this.colors[0] = ca; + this.colors[1] = cb; + this.colors[2] = cc; + } + } + + public abstract static class ShapeDrawer + { + public abstract void drawShape(ModelPart m, Shape s, double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll); + + public abstract void drawShape(ModelPart m, Shape s, double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw); + + public abstract void drawShape(ModelPart m, Shape s, double posX, double posY, double sX, double sY, double yaw); + } + + @Deprecated + public static class Quad extends Shape + { + public Quad(Point a, Point b, Point c, Point d, double brightness) + { + this.points = new Point[4]; + this.points[0] = a; + this.points[1] = b; + this.points[2] = c; + this.points[3] = d; + this.brightness = brightness; + } + + public Quad(Point a, Point b, Point c, Point d, Point ta, Point tb, Point tc, Point td) + { + this.points = new Point[4]; + this.points[0] = a; + this.points[1] = b; + this.points[2] = c; + this.points[3] = d; + + this.texCoords = new Point[4]; + this.texCoords[0] = ta; + this.texCoords[1] = tb; + this.texCoords[2] = tc; + this.texCoords[3] = td; + } + } + + @Deprecated + public static class LegacySquare extends Shape + { + public double width; + public double height; + + public LegacySquare(double width, double height) + { + this.width = width; + this.height = height; + } + } + + public ModelPart(BaseWindow window) + { + this.setWindow(window); + } + + public ModelPart(BaseWindow window, Model model, ArrayList shapes, Model.Material material) + { + this.setWindow(window); + this.parent = model; + this.shapes = new Shape[shapes.size()]; + this.material = material; + + for (int i = 0; i < shapes.size(); i++) + { + this.shapes[i] = shapes.get(i); + } + } + + public void setWindow(BaseWindow w) + { + + } + + public void processShapes() + { + + } +} diff --git a/src/main/java/basewindow/PosedModel.java b/src/main/java/basewindow/PosedModel.java new file mode 100755 index 00000000..8130d3db --- /dev/null +++ b/src/main/java/basewindow/PosedModel.java @@ -0,0 +1,134 @@ +package basewindow; + +import java.util.HashMap; + +public abstract class PosedModel implements IModel +{ + protected static double[] tempMatrix = new double[16]; + + public Model model; + public PoseBone[] bones; + public HashMap boneMap = new HashMap<>(); + public HashMap bonesByName = new HashMap<>(); + + public PosedModel(Model model) + { + this.model = model; + this.bones = new PoseBone[this.model.bones.size()]; + + for (int i = 0; i < this.model.bones.size(); i++) + { + this.bones[i] = new PoseBone(this, this.model.bones.get(i)); + this.boneMap.put(this.model.bones.get(i), this.bones[i]); + this.bonesByName.put(this.bones[i].bone.name, this.bones[i]); + } + } + + public static class PoseBone + { + public PosedModel posedModel; + public Model.Bone bone; + + public double yaw; + public double pitch; + public double roll; + + public double offX; + public double offY; + public double offZ; + + public double[] matrix = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + public double[] compiledMatrix = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + + public PoseBone(PosedModel p, Model.Bone b) + { + this.posedModel = p; + this.bone = b; + } + + public void computeMatrix() + { + for (int i = 0; i < this.matrix.length; i++) + { + if (i % 5 == 0) + this.matrix[i] = 1; + else + this.matrix[i] = 0; + } + + multiply(this.matrix, tempMatrix(Math.cos(roll), -Math.sin(roll), 0, 0, Math.sin(roll), Math.cos(roll), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)); + multiply(this.matrix, tempMatrix(1, 0, 0, 0, 0, Math.cos(pitch), -Math.sin(pitch), 0, 0, Math.sin(pitch), Math.cos(pitch), 0, 0, 0, 0, 1)); + multiply(this.matrix, tempMatrix(Math.cos(yaw), 0, -Math.sin(yaw), 0, 0, 1, 0, 0, Math.sin(yaw), 0, Math.cos(yaw), 0, 0, 0, 0, 1)); + + multiply(this.matrix, tempMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, offX, offY, offZ, 1)); + } + + public void compileMatrix() + { + if (this.bone.parent == null) + { + System.arraycopy(this.matrix, 0, this.compiledMatrix, 0, this.matrix.length); + } + else + { + for (int i = 0; i < this.compiledMatrix.length; i++) + this.compiledMatrix[i] = this.posedModel.boneMap.get(this.bone.parent).compiledMatrix[i]; + + multiply(this.compiledMatrix, tempMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -this.bone.posX, -this.bone.posY, -this.bone.posZ, 1)); + multiply(this.compiledMatrix, this.matrix); + multiply(this.compiledMatrix, tempMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, this.bone.posX, this.bone.posY, this.bone.posZ, 1)); + } + } + } + + public static void multiply(double[] matrix, double[] multiplier) + { + double[] result = new double[16]; + + for (int n = 0; n < result.length; n++) + { + int j = n % 4; + int i = n / 4; + + for (int m = 0; m < 4; m++) + { + result[n] += matrix[m * 4 + j] * multiplier[m + i * 4]; + } + + result[0] = matrix[0] * multiplier[0] + matrix[4] * multiplier[1] + matrix[8] * multiplier[2] + matrix[12] * multiplier[3]; + } + + for (int i = 0; i < result.length; i++) + { + matrix[i] = result[i]; + } + } + + public static double[] tempMatrix(double a1, double a2, double a3, double a4, + double b1, double b2, double b3, double b4, + double c1, double c2, double c3, double c4, + double d1, double d2, double d3, double d4) + { + tempMatrix[0] = a1; + tempMatrix[1] = a2; + tempMatrix[2] = a3; + tempMatrix[3] = a4; + + tempMatrix[4] = b1; + tempMatrix[5] = b2; + tempMatrix[6] = b3; + tempMatrix[7] = b4; + + tempMatrix[8] = c1; + tempMatrix[9] = c2; + tempMatrix[10] = c3; + tempMatrix[11] = c4; + + tempMatrix[12] = d1; + tempMatrix[13] = d2; + tempMatrix[14] = d3; + tempMatrix[15] = d4; + + return tempMatrix; + } +} diff --git a/src/main/java/basewindow/PosedModelAnimation.java b/src/main/java/basewindow/PosedModelAnimation.java new file mode 100755 index 00000000..b5eb5db8 --- /dev/null +++ b/src/main/java/basewindow/PosedModelAnimation.java @@ -0,0 +1,308 @@ +package basewindow; + +import java.util.ArrayList; +import java.util.HashMap; + +public class PosedModelAnimation +{ + public double duration; + public boolean looped; + public boolean cubic = true; + + public HashMap bones = new HashMap<>(); + + public PosedModelAnimation(BaseFileManager fileManager, String file) + { + this(fileManager.getInternalFileContents(file)); + } + + public PosedModelAnimation(ArrayList lines) + { + double time = 0; + + for (String line : lines) + { + if (line.startsWith("duration ")) + { + duration = 100 * Double.parseDouble(line.split(" ")[1]); + looped = line.contains("looped"); + } + else if (line.startsWith("time ")) + time = 100 * Double.parseDouble(line.split(" ")[1]); + else if (line.startsWith("rotation ")) + { + String[] s = line.split(" "); + + this.getBone(s[1]).rotationFrames.add(new AnimatedBone.AnimatedBoneRotationFrame + (time, Math.toRadians(Double.parseDouble(s[2])), Math.toRadians(Double.parseDouble(s[3])), Math.toRadians(Double.parseDouble(s[4])))); + } + else if (line.startsWith("translation ")) + { + String[] s = line.split(" "); + + this.getBone(s[1]).translationFrames.add(new AnimatedBone.AnimatedBoneTranslationFrame + (time, Double.parseDouble(s[2]), -Double.parseDouble(s[3]), Double.parseDouble(s[4]))); + } + else if (line.startsWith("interpolation ")) + { + String[] s = line.split(" "); + + if (s[1].equals("linear")) + cubic = false; + else if (s[1].equals("cubic")) + cubic = true; + } + } + } + + protected AnimatedBone getBone(String name) + { + if (!this.bones.containsKey(name)) + this.bones.put(name, new AnimatedBone(this, name)); + + return this.bones.get(name); + } + + public void apply(PosedModel m, double time, double frac) + { + if (this.looped) + time %= this.duration; + + for (AnimatedBone b: this.bones.values()) + b.apply(m, time, frac); + } + + public static class AnimatedBone + { + public static AnimatedBoneRotationFrame defaultRotation = new AnimatedBoneRotationFrame(0, 0, 0, 0); + public static AnimatedBoneTranslationFrame defaultTranslation = new AnimatedBoneTranslationFrame(0, 0, 0, 0); + + public PosedModelAnimation animation; + public String name; + public ArrayList rotationFrames = new ArrayList<>(); + public ArrayList translationFrames = new ArrayList<>(); + + public AnimatedBone(PosedModelAnimation anim, String name) + { + this.name = name; + this.animation = anim; + } + + public void apply(PosedModel m, double time, double frac) + { + PosedModel.PoseBone b = m.bonesByName.get(this.name); + this.applyRotation(b, time, frac); + this.applyTranslation(b, time, frac); + } + + public void applyRotation(PosedModel.PoseBone b, double time, double frac) + { + if (this.rotationFrames.size() <= 0) + return; + + int index = 0; + int lastIndex = 0; + + AnimatedBoneRotationFrame last = defaultRotation; + + for (AnimatedBoneRotationFrame f : this.rotationFrames) + { + if (f.time <= time) + { + last = f; + lastIndex = index; + } + else + break; + + index++; + } + + AnimatedBoneRotationFrame next = this.rotationFrames.get(getIndex(lastIndex + 1, this.rotationFrames.size()));; + + if (next == last) + last.apply(b, frac); + else + { + double time1 = last.time; + double time2 = next.time; + + double loopedTime = time; + + if (animation.looped) + { + while (time2 < time1) + time2 += animation.duration; + + while (loopedTime < time1) + loopedTime += animation.duration; + } + + double frac2 = (loopedTime - time1) / (time2 - time1); + + if (this.animation.cubic) + { + AnimatedBoneRotationFrame beforeLast = this.rotationFrames.get(getIndex(lastIndex - 1, this.rotationFrames.size())); + AnimatedBoneRotationFrame afterNext = this.rotationFrames.get(getIndex(lastIndex + 2, this.rotationFrames.size()));; + + beforeLast.applyCubic(b, frac2 * frac, 0); + last.applyCubic(b, frac2 * frac, 1); + next.applyCubic(b, frac2 * frac, 2); + afterNext.applyCubic(b, frac2 * frac, 3); + } + else + { + last.apply(b, frac * (1 - frac2)); + next.apply(b, frac * frac2); + } + } + } + + public void applyTranslation(PosedModel.PoseBone b, double time, double frac) + { + if (this.translationFrames.size() <= 0) + return; + + int index = 0; + int lastIndex = 0; + + AnimatedBoneTranslationFrame last = defaultTranslation; + + for (AnimatedBoneTranslationFrame f : this.translationFrames) + { + if (f.time <= time) + { + last = f; + lastIndex = index; + } + else + break; + + index++; + } + + AnimatedBoneTranslationFrame next = this.translationFrames.get(getIndex(lastIndex + 1, this.translationFrames.size()));; + + if (next == last) + last.apply(b, frac); + else + { + double time1 = last.time; + double time2 = next.time; + + double loopedTime = time; + + if (animation.looped) + { + while (time2 < time1) + time2 += animation.duration; + + while (loopedTime < time1) + loopedTime += animation.duration; + } + + double frac2 = (loopedTime - time1) / (time2 - time1); + + if (this.animation.cubic) + { + AnimatedBoneTranslationFrame beforeLast = this.translationFrames.get(getIndex(lastIndex - 1, this.translationFrames.size())); + AnimatedBoneTranslationFrame afterNext = this.translationFrames.get(getIndex(lastIndex + 2, this.translationFrames.size()));; + + beforeLast.applyCubic(b, frac2 * frac, 0); + last.applyCubic(b, frac2 * frac, 1); + next.applyCubic(b, frac2 * frac, 2); + afterNext.applyCubic(b, frac2 * frac, 3); + } + else + { + last.apply(b, frac * (1 - frac2)); + next.apply(b, frac * frac2); + } + } + } + + public static int getIndex(int in, int l) + { + if (l == 0) + return 0; + + while (in < 0) + in += l; + + while (in >= l) + in -= l; + + return in; + } + + public static abstract class AnimatedBoneFrame + { + public double time; + + public AnimatedBoneFrame(double time) + { + this.time = time; + } + + public abstract void apply(PosedModel.PoseBone b, double frac); + + public void applyCubic(PosedModel.PoseBone b, double frac, int index) + { + if (index == 0) + this.apply(b, -0.5 * Math.pow(frac, 3) + Math.pow(frac, 2) - 0.5 * frac); + else if (index == 1) + this.apply(b, 1.5 * Math.pow(frac, 3) - 2.5 * Math.pow(frac, 2) + 1); + else if (index == 2) + this.apply(b, -1.5 * Math.pow(frac, 3) + 2 * Math.pow(frac, 2) + 0.5 * frac); + else if (index == 3) + this.apply(b, 0.5 * Math.pow(frac, 3) - 0.5 * Math.pow(frac, 2)); + } + } + + public static class AnimatedBoneRotationFrame extends AnimatedBoneFrame + { + public double yaw; + public double pitch; + public double roll; + + public AnimatedBoneRotationFrame(double time, double yaw, double pitch, double roll) + { + super(time); + this.yaw = yaw; + this.pitch = pitch; + this.roll = roll; + } + + @Override + public void apply(PosedModel.PoseBone b, double frac) + { + b.yaw += this.yaw * frac; + b.pitch += this.pitch * frac; + b.roll += this.roll * frac; + } + } + + public static class AnimatedBoneTranslationFrame extends AnimatedBoneFrame + { + public double offX; + public double offY; + public double offZ; + + public AnimatedBoneTranslationFrame(double time, double x, double y, double z) + { + super(time); + this.offX = x; + this.offY = y; + this.offZ = z; + } + + @Override + public void apply(PosedModel.PoseBone b, double frac) + { + b.offX += this.offX * frac; + b.offY += this.offY * frac; + b.offZ += this.offZ * frac; + } + } + } +} diff --git a/src/main/java/basewindow/PosedModelPose.java b/src/main/java/basewindow/PosedModelPose.java new file mode 100755 index 00000000..50f45179 --- /dev/null +++ b/src/main/java/basewindow/PosedModelPose.java @@ -0,0 +1,137 @@ +package basewindow; + +import java.util.ArrayList; +import java.util.HashMap; + +public class PosedModelPose +{ + public double duration; + public boolean looped; + public boolean cubic = true; + + public HashMap bones = new HashMap<>(); + + public PosedModelPose(BaseFileManager fileManager, String file) + { + this(fileManager.getInternalFileContents(file)); + } + + public PosedModelPose(ArrayList lines) + { + double time = 0; + + for (String line : lines) + { + if (line.startsWith("rotation ")) + { + String[] s = line.split(" "); + + this.getBone(s[1]).rotation = new PosedBone.BoneRotationPose + (time, Math.toRadians(Double.parseDouble(s[2])), Math.toRadians(Double.parseDouble(s[3])), Math.toRadians(Double.parseDouble(s[4]))); + } + else if (line.startsWith("translation ")) + { + String[] s = line.split(" "); + + this.getBone(s[1]).translation = new PosedBone.BoneTranslationPose + (time, Double.parseDouble(s[2]), Double.parseDouble(s[3]), Double.parseDouble(s[4])); + } + } + } + + protected PosedBone getBone(String name) + { + if (!this.bones.containsKey(name)) + this.bones.put(name, new PosedBone(this, name)); + + return this.bones.get(name); + } + + public void apply(PosedModel m, double frac) + { + for (PosedBone b: this.bones.values()) + b.apply(m, frac); + } + + public static class PosedBone + { + public static BoneRotationPose defaultRotation = new BoneRotationPose(0, 0, 0, 0); + public static BoneTranslationPose defaultTranslation = new BoneTranslationPose(0, 0, 0, 0); + + public PosedModelPose animation; + public String name; + public BoneRotationPose rotation = defaultRotation; + public BoneTranslationPose translation = defaultTranslation; + + public PosedBone(PosedModelPose anim, String name) + { + this.name = name; + this.animation = anim; + } + + public void apply(PosedModel m, double frac) + { + PosedModel.PoseBone b = m.bonesByName.get(this.name); + this.rotation.apply(b, frac); + this.translation.apply(b, frac); + } + + public static abstract class BonePose + { + public double time; + + public BonePose(double time) + { + this.time = time; + } + + public abstract void apply(PosedModel.PoseBone b, double frac); + } + + public static class BoneRotationPose extends BonePose + { + public double yaw; + public double pitch; + public double roll; + + public BoneRotationPose(double time, double yaw, double pitch, double roll) + { + super(time); + this.yaw = yaw; + this.pitch = pitch; + this.roll = roll; + } + + @Override + public void apply(PosedModel.PoseBone b, double frac) + { + b.yaw += this.yaw * frac; + b.pitch += this.pitch * frac; + b.roll += this.roll * frac; + } + } + + public static class BoneTranslationPose extends BonePose + { + public double offX; + public double offY; + public double offZ; + + public BoneTranslationPose(double time, double offX, double offY, double offZ) + { + super(time); + this.offX = offX; + this.offY = offY; + this.offZ = offZ; + } + + @Override + public void apply(PosedModel.PoseBone b, double frac) + { + b.offX += this.offX * frac; + b.offY += this.offY * frac; + b.offZ += this.offZ * frac; + } + } + } +} diff --git a/src/main/java/lwjglwindow/FontRenderer.java b/src/main/java/lwjglwindow/FontRenderer.java index 48a75859..95c39aed 100755 --- a/src/main/java/lwjglwindow/FontRenderer.java +++ b/src/main/java/lwjglwindow/FontRenderer.java @@ -47,7 +47,7 @@ protected int drawChar(double x, double y, double z, double sX, double sY, char int col = (int) (i % size); int row = (int) (i / size); int width = charSizes[i]; - this.home.drawImage(x, y, z, sX * 32 * size, sY * 32 * size, + this.window.shapeRenderer.drawImage(x, y, z, sX * 32 * size, sY * 32 * size, col / size, (row * hSpace) / size, (col + width / 8f) / size, (row * hSpace + 1) / size, image, false, depthtest); @@ -71,7 +71,7 @@ else if (c[i] == '\u00A7') int g = Integer.parseInt(c[i + 4] + "" + c[i + 5] + "" + c[i + 6]); int b = Integer.parseInt(c[i + 7] + "" + c[i + 8] + "" + c[i + 9]); int a = Integer.parseInt(c[i + 10] + "" + c[i + 11] + "" + c[i + 12]); - this.home.setColor(r, g, b, a); + this.window.setColor(r, g, b, a); i += 12; } @@ -97,7 +97,7 @@ else if (c[i] == '\u00A7') int g = Integer.parseInt(c[i + 4] + "" + c[i + 5] + "" + c[i + 6]); int b = Integer.parseInt(c[i + 7] + "" + c[i + 8] + "" + c[i + 9]); int a = Integer.parseInt(c[i + 10] + "" + c[i + 11] + "" + c[i + 12]); - this.home.setColor(r, g, b, a); + this.window.setColor(r, g, b, a); i += 12; } diff --git a/src/main/java/lwjglwindow/ImmediateModeModelPart.java b/src/main/java/lwjglwindow/ImmediateModeModelPart.java new file mode 100755 index 00000000..99d9cbc6 --- /dev/null +++ b/src/main/java/lwjglwindow/ImmediateModeModelPart.java @@ -0,0 +1,220 @@ +package lwjglwindow; + +import basewindow.BaseWindow; +import basewindow.Model; +import basewindow.ModelPart; + +import java.util.ArrayList; + +public class ImmediateModeModelPart extends ModelPart +{ + public BaseWindow window; + + @Override + public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll, boolean depthTest) + { + window.setBatchMode(true, false, depthTest); + + double r = window.colorR * 255; + double g = window.colorG * 255; + double b = window.colorB * 255; + + boolean depthMask = true; + for (Shape shape : this.shapes) + { + if (this.material != null) + { + if (this.material.depthMask != depthMask) + { + window.setBatchMode(false, false, true); + window.setBatchMode(true, false, true, false, this.material.depthMask); + depthMask = this.material.depthMask; + } + + window.setTexture(this.material.texture); + } + else + window.stopTexture(); + + window.setColor(r * shape.brightness, g * shape.brightness, b * shape.brightness, window.colorA * 255, window.glow * 255); + window.shapeDrawer.drawShape(this, shape, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); + } + + window.setBatchMode(false, false, true); + } + + @Override + public void draw(double posX, double posY, double sX, double sY, double yaw) + { + window.setBatchMode(true, false, false); + + double r = window.colorR * 255; + double g = window.colorG * 255; + double b = window.colorB * 255; + + boolean depthMask = true; + for (Shape shape : this.shapes) + { + if (this.material != null) + { + if (this.material.depthMask != depthMask) + { + window.setBatchMode(false, false, true); + window.setBatchMode(true, false, true, false, this.material.depthMask); + depthMask = this.material.depthMask; + } + + window.setTexture(this.material.texture); + } + else + window.stopTexture(); + + window.setColor(r * shape.brightness, g * shape.brightness, b * shape.brightness, window.colorA * 255, window.glow * 255); + window.shapeDrawer.drawShape(this, shape, posX, posY, sX, sY, yaw); + } + + window.setBatchMode(false, false, false); + } + + public static class ImmediateModeShapeDrawer extends ShapeDrawer + { + public BaseWindow window; + + public ImmediateModeShapeDrawer(BaseWindow w) + { + this.window = w; + } + + public void addVertex(ModelPart m, Shape s, int index, double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw) + { + if (m.material != null) + window.setTextureCoords(s.texCoords[index].x, s.texCoords[index].y); + + window.addVertex( + (s.points[index].x * Math.cos(yaw) * sX - s.points[index].y * Math.sin(yaw) * sY) + posX, + (s.points[index].y * Math.cos(yaw) * sY + s.points[index].x * Math.sin(yaw) * sX) + posY, + s.points[index].z * sZ + posZ); + } + + public void addVertex(ModelPart m, Shape s, int index, double posX, double posY, double sX, double sY, double yaw) + { + if (m.material != null) + window.setTextureCoords(s.texCoords[index].x, s.texCoords[index].y); + + window.addVertex( + (s.points[index].x * Math.cos(yaw) * sX - s.points[index].y * Math.sin(yaw) * sY) + posX, + (s.points[index].y * Math.cos(yaw) * sY + s.points[index].x * Math.sin(yaw) * sX) + posY); + } + + public void addVertex(ModelPart m, Shape s, int index, double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll) + { + double a = Math.cos(-yaw); + double b = Math.sin(-yaw); + double c = Math.cos(-roll); + double d = Math.sin(-roll); + double e = Math.cos(-pitch); + double f = Math.sin(-pitch); + + double x1 = e * a - b * d * f; + double y1 = -a * d * f - e * b; + double z1 = -c * f; + double x2 = b * c; + double y2 = a * c; + double z2 = -d; + double x3 = a * f + e * b * d; + double y3 = e * a * d - b * f; + double z3 = e * c; + + double ox = s.points[index].x * sX; + double oy = s.points[index].y * sY; + double oz = s.points[index].z * sZ; + + if (m.material != null) + window.setTextureCoords(s.texCoords[index].x, s.texCoords[index].y); + + window.addVertex(posX + ox * x1 + oy * x2 + oz * x3, posY + ox * y1 + oy * y2 + oz * y3, posZ + ox * z1 + oy * z2 + oz * z3); + } + + @Override + public void drawShape(ModelPart m, Shape s, double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll) + { + if (s instanceof Triangle) + { + for (int i = 0; i < s.points.length; i++) + { + this.addVertex(m, s, i, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); + } + } + else if (s instanceof Quad) + { + this.addVertex(m, s, 0, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); + this.addVertex(m, s, 1, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); + this.addVertex(m, s, 2, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); + + this.addVertex(m, s, 0, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); + this.addVertex(m, s, 3, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); + this.addVertex(m, s, 2, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); + } + } + + @Override + public void drawShape(ModelPart m, Shape s, double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw) + { + if (s instanceof Triangle) + { + for (int i = 0; i < s.points.length; i++) + { + this.addVertex(m, s, i, posX, posY, posZ, sX, sY, sZ, yaw); + } + } + else if (s instanceof Quad) + { + this.addVertex(m, s, 0, posX, posY, posZ, sX, sY, sZ, yaw); + this.addVertex(m, s, 1, posX, posY, posZ, sX, sY, sZ, yaw); + this.addVertex(m, s, 2, posX, posY, posZ, sX, sY, sZ, yaw); + + this.addVertex(m, s, 0, posX, posY, posZ, sX, sY, sZ, yaw); + this.addVertex(m, s, 3, posX, posY, posZ, sX, sY, sZ, yaw); + this.addVertex(m, s, 2, posX, posY, posZ, sX, sY, sZ, yaw); + } + } + + @Override + public void drawShape(ModelPart m, Shape s, double posX, double posY, double sX, double sY, double yaw) + { + if (s instanceof Triangle) + { + for (int i = 0; i < s.points.length; i++) + { + this.addVertex(m, s, i, posX, posY, sX, sY, yaw); + } + } + else if (s instanceof Quad) + { + this.addVertex(m, s, 0, posX, posY, sX, sY, yaw); + this.addVertex(m, s, 1, posX, posY, sX, sY, yaw); + this.addVertex(m, s, 2, posX, posY, sX, sY, yaw); + + this.addVertex(m, s, 0, posX, posY, sX, sY, yaw); + this.addVertex(m, s, 3, posX, posY, sX, sY, yaw); + this.addVertex(m, s, 2, posX, posY, sX, sY, yaw); + } + } + } + + public ImmediateModeModelPart(BaseWindow window) + { + super(window); + } + + public ImmediateModeModelPart(BaseWindow window, Model model, ArrayList shapes, Model.Material material) + { + super(window, model, shapes, material); + } + + @Override + public void setWindow(BaseWindow w) + { + this.window = w; + } +} diff --git a/src/main/java/lwjglwindow/ImmediateModeShapeRenderer.java b/src/main/java/lwjglwindow/ImmediateModeShapeRenderer.java new file mode 100755 index 00000000..cb65df21 --- /dev/null +++ b/src/main/java/lwjglwindow/ImmediateModeShapeRenderer.java @@ -0,0 +1,823 @@ +package lwjglwindow; + +import basewindow.BaseShapeRenderer; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; + +import static org.lwjgl.opengl.GL11.*; + +public class ImmediateModeShapeRenderer extends BaseShapeRenderer +{ + public LWJGLWindow window; + + public ImmediateModeShapeRenderer(LWJGLWindow window) + { + this.window = window; + this.supportsBatching = true; + } + + public void fillOval(double x, double y, double sX, double sY) + { + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY) / 4 + 5; + + glBegin(GL_TRIANGLE_FAN); + for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) + { + glVertex2d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2); + } + + glEnd(); + } + + public void fillGlow(double x, double y, double sX, double sY, boolean shade) + { + this.fillGlow(x, y, sX, sY, shade, false); + } + + public void fillGlow(double x, double y, double sX, double sY, boolean shade, boolean light) + { + if (this.window.drawingShadow) + return; + + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY) / 16 + 5; + + if (!shade) + this.window.setGlowBlendFunc(); + + if (light) + this.window.setLightBlendFunc(); + + glBegin(GL_TRIANGLES); + double step = Math.PI * 2 / sides; + + double pX = x + Math.cos(0) * sX / 2; + double pY = y + Math.sin(0) * sY / 2; + double d = 0; + for (int n = 0; n < sides; n++) + { + d += step; + + if (!shade) + glColor3d(0, 0, 0); + else + glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, 0); + + glVertex2d(pX, pY); + pX = x + Math.cos(d) * sX / 2; + pY = y + Math.sin(d) * sY / 2; + glVertex2d(pX, pY); + + if (!shade) + glColor3d(this.window.colorR * this.window.colorA, this.window.colorG * this.window.colorA, this.window.colorB * this.window.colorA); + else + glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, this.window.colorA); + + glVertex2d(x, y); + } + + glEnd(); + + if (!shade) + this.window.setTransparentBlendFunc(); + } + + @Override + public void fillOval(double x, double y, double z, double sX, double sY, boolean depthTest) + { + if (depthTest) + { + this.window.enableDepthtest(); + + if (this.window.colorA < 1) + glDepthMask(false); + } + + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 4 + 5; + + glBegin(GL_TRIANGLE_FAN); + for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) + { + glVertex3d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2, z); + } + + glEnd(); + + if (depthTest) + { + glDepthMask(true); + this.window.disableDepthtest(); + } + } + + @Override + public void fillPartialOval(double x, double y, double sX, double sY, double start, double end) + { + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY) / 4 + 5; + + glBegin(GL_TRIANGLES); + for (double i = start; i < end; i += (end - start) / sides) + { + glVertex2d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2); + glVertex2d(x + Math.cos(i + 1) * sX / 2, y + Math.sin(i + 1) * sY / 2); + glVertex2d(x, y); + } + + glEnd(); + } + + public void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade) + { + this.fillGlow(x, y, z, sX, sY, depthTest, shade, false); + } + + public void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light) + { + if (this.window.drawingShadow) + return; + + if (depthTest) + { + this.window.enableDepthtest(); + glDepthMask(false); + } + + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 16 + 5; + + if (!shade) + this.window.setGlowBlendFunc(); + + if (light) + this.window.setLightBlendFunc(); + + glBegin(GL_TRIANGLES); + double step = Math.PI * 2 / sides; + + double pX = x + Math.cos(0) * sX / 2; + double pY = y + Math.sin(0) * sY / 2; + double d = 0; + for (int n = 0; n < sides; n++) + { + d += step; + + if (!shade) + glColor3d(0, 0, 0); + else + glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, 0); + + glVertex3d(pX, pY, z); + pX = x + Math.cos(d) * sX / 2; + pY = y + Math.sin(d) * sY / 2; + glVertex3d(pX, pY, z); + + if (!shade) + glColor3d(this.window.colorR * this.window.colorA, this.window.colorG * this.window.colorA, this.window.colorB * this.window.colorA); + else + glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, this.window.colorA); + + glVertex3d(x, y, z); + } + + glEnd(); + + if (!shade) + this.window.setTransparentBlendFunc(); + + if (depthTest) + { + glDepthMask(true); + this.window.disableDepthtest(); + } + } + + public void fillFacingOval(double x, double y, double z, double sX, double sY, boolean depthTest) + { + if (depthTest) + { + this.window.enableDepthtest(); + + if (this.window.colorA < 1) + glDepthMask(false); + } + + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 4 + 5; + + glBegin(GL_TRIANGLE_FAN); + for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) + { + double ox = Math.cos(i) * sX / 2; + double oy = Math.sin(i) * sY / 2; + glVertex3d(x + ox * this.window.bbx1 + oy * this.window.bbx2, y + ox * this.window.bby1 + oy * this.window.bby2, z + ox * this.window.bbz1 + oy * this.window.bbz2); + } + + glEnd(); + + if (depthTest) + { + glDepthMask(true); + this.window.disableDepthtest(); + } + } + + @Override + public void fillGlow(double x, double y, double sX, double sY) + { + this.fillGlow(x, y, sX, sY, false); + } + + @Override + public void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest) + { + this.fillGlow(x, y, z, sX, sY, false, false); + } + + @Override + public void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest) + { + this.fillFacingGlow(x, y, z, sX, sY, depthTest,false); + } + + public void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade) + { + this.fillFacingGlow(x, y, z, sX, sY, depthTest, shade,false); + } + + public void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light) + { + if (this.window.drawingShadow) + return; + + if (depthTest) + { + this.window.enableDepthtest(); + glDepthMask(false); + } + + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 16 + 5; + + if (!shade) + this.window.setGlowBlendFunc(); + + if (light) + this.window.setLightBlendFunc(); + + glBegin(GL_TRIANGLES); + double step = Math.PI * 2 / sides; + + double ox = Math.cos(0) * sX / 2; + double oy = Math.sin(0) * sY / 2; + double d = 0; + for (int n = 0; n < sides; n++) + { + d += step; + + if (!shade) + glColor3d(0, 0, 0); + else + glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, 0); + + glVertex3d(x + ox * this.window.bbx1 + oy * this.window.bbx2, y + ox * this.window.bby1 + oy * this.window.bby2, z + ox * this.window.bbz1 + oy * this.window.bbz2); + ox = Math.cos(d) * sX / 2; + oy = Math.sin(d) * sY / 2; + glVertex3d(x + ox * this.window.bbx1 + oy * this.window.bbx2, y + ox * this.window.bby1 + oy * this.window.bby2, z + ox * this.window.bbz1 + oy * this.window.bbz2); + + if (!shade) + glColor3d(this.window.colorR * this.window.colorA, this.window.colorG * this.window.colorA, this.window.colorB * this.window.colorA); + else + glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, this.window.colorA); + + glVertex3d(x, y, z); + } + + glEnd(); + + if (!shade) + this.window.setTransparentBlendFunc(); + + if (depthTest) + { + glDepthMask(true); + this.window.disableDepthtest(); + } + } + + public void drawOval(double x, double y, double sX, double sY) + { + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY) / 4 + 5; + + for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) + { + glBegin(GL_LINES); + glVertex2d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2); + glVertex2d(x + Math.cos(i + Math.PI * 2 / sides) * sX / 2, y + Math.sin(i + Math.PI * 2 / sides) * sY / 2); + glEnd(); + } + } + + public void drawOval(double x, double y, double z, double sX, double sY) + { + x += sX / 2; + y += sY / 2; + + int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 4 + 5; + + for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) + { + glBegin(GL_LINES); + glVertex3d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2, z); + glVertex3d(x + Math.cos(i + Math.PI * 2 / sides) * sX / 2, y + Math.sin(i + Math.PI * 2 / sides) * sY / 2, z); + glEnd(); + } + } + + public void fillRect(double x, double y, double sX, double sY) + { + glBegin(GL_TRIANGLE_FAN); + + glVertex2d(x, y); + glVertex2d(x + sX, y); + glVertex2d(x + sX, y + sY); + glVertex2d(x, y + sY); + + glEnd(); + } + + public void fillBox(double x, double y, double z, double sX, double sY, double sZ) + { + fillBox(x, y, z, sX, sY, sZ, (byte) 0); + } + + /** + * Options byte: + * + * 0: default + * + * +1 hide behind face + * +2 hide front face + * +4 hide bottom face + * +8 hide top face + * +16 hide left face + * +32 hide right face + * + * +64 draw on top + * */ + public void fillBox(double x, double y, double z, double sX, double sY, double sZ, byte options) + { + if (!this.window.batchMode) + { + this.window.enableDepthtest(); + + if (this.window.colorA < 1) + glDepthMask(false); + + if ((options >> 6) % 2 == 0) + glDepthFunc(GL_LEQUAL); + else + glDepthFunc(GL_ALWAYS); + + GL11.glBegin(GL11.GL_QUADS); + } + + if (options % 2 == 0) + { + GL11.glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, this.window.colorA); + GL11.glVertex3d(x + sX, y, z); + GL11.glVertex3d(x, y, z); + GL11.glVertex3d(x, y + sY, z); + GL11.glVertex3d(x + sX, y + sY, z); + } + + if ((options >> 2) % 2 == 0) + { + GL11.glColor4d(this.window.colorR * 0.8, this.window.colorG * 0.8, this.window.colorB * 0.8, this.window.colorA); + GL11.glVertex3d(x + sX, y + sY, z + sZ); + GL11.glVertex3d(x, y + sY, z + sZ); + GL11.glVertex3d(x, y + sY, z); + GL11.glVertex3d(x + sX, y + sY, z); + } + + if ((options >> 3) % 2 == 0) + { + GL11.glColor4d(this.window.colorR * 0.8, this.window.colorG * 0.8, this.window.colorB * 0.8, this.window.colorA); + GL11.glVertex3d(x + sX, y , z + sZ); + GL11.glVertex3d(x, y, z + sZ); + GL11.glVertex3d(x, y, z); + GL11.glVertex3d(x + sX, y, z); + } + + if ((options >> 4) % 2 == 0) + { + GL11.glColor4d(this.window.colorR * 0.6, this.window.colorG * 0.6, this.window.colorB * 0.6, this.window.colorA); + GL11.glVertex3d(x, y + sY, z + sZ); + GL11.glVertex3d(x, y + sY, z); + GL11.glVertex3d(x, y, z); + GL11.glVertex3d(x, y, z + sZ); + } + + if ((options >> 5) % 2 == 0) + { + GL11.glColor4d(this.window.colorR * 0.6, this.window.colorG * 0.6, this.window.colorB * 0.6, this.window.colorA); + GL11.glVertex3d(x + sX, y + sY, z); + GL11.glVertex3d(x + sX, y + sY, z + sZ); + GL11.glVertex3d(x + sX, y, z + sZ); + GL11.glVertex3d(x + sX, y, z); + } + + if ((options >> 1) % 2 == 0) + { + GL11.glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, this.window.colorA); + GL11.glVertex3d(x + sX, y + sY, z + sZ); + GL11.glVertex3d(x, y + sY, z + sZ); + GL11.glVertex3d(x, y, z + sZ); + GL11.glVertex3d(x + sX, y, z + sZ); + } + + if (!this.window.batchMode) + { + GL11.glEnd(); + this.window.disableDepthtest(); + glDepthMask(true); + } + } + + public void fillQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) + { + glBegin(GL_TRIANGLE_FAN); + + glVertex2d(x1, y1); + glVertex2d(x2, y2); + glVertex2d(x3, y3); + glVertex2d(x4, y4); + + glEnd(); + } + + public void fillQuadBox(double x1, double y1, + double x2, double y2, + double x3, double y3, + double x4, double y4, + double z, double sZ, + byte options) + { + this.window.enableDepthtest(); + + if ((options >> 6) % 2 == 0) + glDepthFunc(GL_LEQUAL); + else + glDepthFunc(GL_ALWAYS); + + if (options % 2 == 0) + { + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + GL11.glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, this.window.colorA); + GL11.glVertex3d(x1, y1, z); + GL11.glVertex3d(x2, y2, z); + GL11.glVertex3d(x3, y3, z); + GL11.glVertex3d(x4, y4, z); + GL11.glEnd(); + } + + if ((options >> 2) % 2 == 0) + { + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + GL11.glColor4d(this.window.colorR * 0.6, this.window.colorG * 0.6, this.window.colorB * 0.6, this.window.colorA); + GL11.glVertex3d(x1, y1, z + sZ); + GL11.glVertex3d(x2, y2, z + sZ); + GL11.glVertex3d(x2, y2, z); + GL11.glVertex3d(x1, y1, z); + GL11.glEnd(); + } + + if ((options >> 3) % 2 == 0) + { + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + GL11.glColor4d(this.window.colorR * 0.6, this.window.colorG * 0.6, this.window.colorB * 0.6, this.window.colorA); + GL11.glVertex3d(x3, y3, z + sZ); + GL11.glVertex3d(x4, y4, z + sZ); + GL11.glVertex3d(x4, y4, z); + GL11.glVertex3d(x3, y3, z); + GL11.glEnd(); + } + + if ((options >> 4) % 2 == 0) + { + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + GL11.glColor4d(this.window.colorR * 0.8, this.window.colorG * 0.8, this.window.colorB * 0.8, this.window.colorA); + GL11.glVertex3d(x1, y1, z + sZ); + GL11.glVertex3d(x4, y4, z + sZ); + GL11.glVertex3d(x4, y4, z); + GL11.glVertex3d(x1, y1, z); + GL11.glEnd(); + } + + if ((options >> 5) % 2 == 0) + { + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + GL11.glColor4d(this.window.colorR * 0.6, this.window.colorG * 0.6, this.window.colorB * 0.6, this.window.colorA); + GL11.glVertex3d(x3, y3, z + sZ); + GL11.glVertex3d(x2, y2, z + sZ); + GL11.glVertex3d(x2, y2, z); + GL11.glVertex3d(x3, y3, z); + GL11.glEnd(); + } + + if ((options >> 1) % 2 == 0) + { + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + GL11.glColor4d(this.window.colorR, this.window.colorG, this.window.colorB, this.window.colorA); + GL11.glVertex3d(x1, y1, z + sZ); + GL11.glVertex3d(x2, y2, z + sZ); + GL11.glVertex3d(x3, y3, z + sZ); + GL11.glVertex3d(x4, y4, z + sZ); + GL11.glEnd(); + } + + this.window.disableDepthtest(); + } + + public void drawRect(double x, double y, double sX, double sY) + { + glBegin(GL_LINES); + glVertex2d(x, y); + glVertex2d(x + sX, y); + glEnd(); + + glBegin(GL_LINES); + glVertex2d(x, y); + glVertex2d(x, y + sY); + glEnd(); + + glBegin(GL_LINES); + glVertex2d(x, y + sY); + glVertex2d(x + sX, y + sY); + glEnd(); + + glBegin(GL_LINES); + glVertex2d(x + sX, y); + glVertex2d(x + sX, y + sY); + glEnd(); + } + + public void drawImage(double x, double y, double sX, double sY, String image, boolean scaled) + { + drawImage(x, y, sX, sY, 0, 0, 1, 1, image, scaled); + } + + public void drawImage(double x, double y, double z, double sX, double sY, String image, boolean scaled) + { + drawImage(x, y, z, sX, sY, 0, 0, 1, 1, image, scaled); + } + + public void drawImage(double x, double y, double sX, double sY, String image, double rotation, boolean scaled) + { + drawImage(x, y, sX, sY, 0, 0, 1, 1, image, rotation, scaled); + } + + public void drawImage(double x, double y, double z, double sX, double sY, String image, double rotation, boolean scaled) + { + drawImage(x, y, z, sX, sY, 0, 0, 1, 1, image, rotation, scaled); + } + + public void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled) + { + if (this.window.drawingShadow) + return; + + if (!this.window.textures.containsKey(image)) + this.window.createImage(image); + + //loadPerspective(); + + glMatrixMode(GL_MODELVIEW); + this.window.enableTexture(); + + glEnable(GL_BLEND); + this.window.setTransparentBlendFunc(); + + glBindTexture(GL_TEXTURE_2D, this.window.textures.get(image)); + + double width = sX * (u2 - u1); + double height = sY * (v2 - v1); + + if (scaled) + { + width *= this.window.textureSX.get(image); + height *= this.window.textureSY.get(image); + } + + glBegin(GL_TRIANGLE_FAN); + glTexCoord2d(u1, v1); + glVertex2d(x, y); + glTexCoord2d(u1, v2); + glVertex2d(x, y + height); + glTexCoord2d(u2, v2); + glVertex2d(x + width, y + height); + glTexCoord2d(u2, v1); + glVertex2d(x + width, y); + + glEnd(); + + glMatrixMode(GL_PROJECTION); + this.window.disableTexture(); + + if (!this.window.drawingShadow) + GL20.glUniform1i(this.window.textureFlag, 0); + } + + public void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled) + { + if (this.window.drawingShadow) + return; + + if (!this.window.textures.containsKey(image)) + this.window.createImage(image); + + //loadPerspective(); + + glMatrixMode(GL_MODELVIEW); + this.window.enableTexture(); + + glEnable(GL_BLEND); + this.window.setTransparentBlendFunc(); + + glBindTexture(GL_TEXTURE_2D, this.window.textures.get(image)); + + double width = sX * (u2 - u1); + double height = sY * (v2 - v1); + + if (scaled) + { + width *= this.window.textureSX.get(image); + height *= this.window.textureSY.get(image); + } + + glBegin(GL_TRIANGLE_FAN); + glTexCoord2d(u1, v1); + glVertex2d(rotateX(-width / 2, -height / 2, x, rotation), rotateY(-width / 2, -height / 2, y, rotation)); + glTexCoord2d(u1, v2); + glVertex2d(rotateX(width / 2, -height / 2, x, rotation), rotateY(width / 2, -height / 2, y, rotation)); + glTexCoord2d(u2, v2); + glVertex2d(rotateX(width / 2, height / 2, x, rotation), rotateY(width / 2, height / 2, y, rotation)); + glTexCoord2d(u2, v1); + glVertex2d(rotateX(-width / 2, height / 2, x, rotation), rotateY(-width / 2, height / 2, y, rotation)); + + glEnd(); + + glMatrixMode(GL_PROJECTION); + this.window.disableTexture(); + } + + public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled) + { + this.drawImage(x, y, z, sX, sY, u1, v1, u2, v2, image, scaled, true); + } + + public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled, boolean depthtest) + { + if (this.window.drawingShadow) + return; + + if (!this.window.textures.containsKey(image)) + this.window.createImage(image); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + if (depthtest) + this.window.enableDepthtest(); + + this.window.loadPerspective(); + + glMatrixMode(GL_MODELVIEW); + + this.window.enableTexture(); + glEnable(GL_BLEND); + this.window.setTransparentBlendFunc(); + + glDepthMask(false); + + glBindTexture(GL_TEXTURE_2D, this.window.textures.get(image)); + + double width = sX * (u2 - u1); + double height = sY * (v2 - v1); + + if (scaled) + { + width *= this.window.textureSX.get(image); + height *= this.window.textureSY.get(image); + } + + glBegin(GL_TRIANGLE_FAN); + glTexCoord2d(u1, v1); + glVertex3d(x, y, z); + glTexCoord2d(u1, v2); + glVertex3d(x, y + height, z); + glTexCoord2d(u2, v2); + glVertex3d(x + width, y + height, z); + glTexCoord2d(u2, v1); + glVertex3d(x + width, y, z); + + glEnd(); + + glMatrixMode(GL_PROJECTION); + this.window.disableTexture(); + + glDepthMask(true); + + if (depthtest) + this.window.disableDepthtest(); + } + + public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled) + { + this.drawImage(x, y, z, sX, sY, u1, v1, u2, v2, image, rotation, scaled, true); + } + + public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled, boolean depthtest) + { + if (this.window.drawingShadow) + return; + + if (!this.window.textures.containsKey(image)) + this.window.createImage(image); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + if (depthtest) + this.window.enableDepthtest(); + + this.window.loadPerspective(); + glMatrixMode(GL_MODELVIEW); + + this.window.enableTexture(); + glEnable(GL_BLEND); + this.window.setTransparentBlendFunc(); + + glDepthMask(false); + + glBindTexture(GL_TEXTURE_2D, this.window.textures.get(image)); + + double width = sX * (u2 - u1); + double height = sY * (v2 - v1); + + if (scaled) + { + width *= this.window.textureSX.get(image); + height *= this.window.textureSY.get(image); + } + + glBegin(GL_TRIANGLE_FAN); + glTexCoord2d(u1, v1); + glVertex3d(rotateX(-width / 2, -height / 2, x, rotation), rotateY(-width / 2, -height / 2, y, rotation), z); + glTexCoord2d(u1, v2); + glVertex3d(rotateX(width / 2, -height / 2, x, rotation), rotateY(width / 2, -height / 2, y, rotation), z); + glTexCoord2d(u2, v2); + glVertex3d(rotateX(width / 2, height / 2, x, rotation), rotateY(width / 2, height / 2, y, rotation), z); + glTexCoord2d(u2, v1); + glVertex3d(rotateX(-width / 2, height / 2, x, rotation), rotateY(-width / 2, height / 2, y, rotation), z); + + glEnd(); + + glMatrixMode(GL_PROJECTION); + this.window.disableTexture(); + + glDepthMask(true); + + if (depthtest) + this.window.disableDepthtest(); + } + + public double rotateX(double px, double py, double posX, double rotation) + { + return (px * Math.cos(rotation) - py * Math.sin(rotation)) + posX; + } + + public double rotateY(double px, double py, double posY, double rotation) + { + return (py * Math.cos(rotation) + px * Math.sin(rotation)) + posY; + } +} diff --git a/src/main/java/lwjglwindow/LWJGLWindow.java b/src/main/java/lwjglwindow/LWJGLWindow.java index 3effdc22..4ea9bac8 100755 --- a/src/main/java/lwjglwindow/LWJGLWindow.java +++ b/src/main/java/lwjglwindow/LWJGLWindow.java @@ -9,7 +9,6 @@ import org.lwjgl.glfw.GLFWImage; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.openal.AL10; -import org.lwjgl.openal.ALC10; import org.lwjgl.openal.ALC11; import org.lwjgl.opengl.*; import org.lwjgl.system.MemoryStack; @@ -19,6 +18,7 @@ import java.io.InputStreamReader; import java.net.URL; import java.nio.ByteBuffer; +import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.ArrayList; import java.util.HashMap; @@ -26,11 +26,8 @@ import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks; import static org.lwjgl.glfw.GLFW.*; -import static org.lwjgl.openal.AL10.AL_PITCH; -import static org.lwjgl.openal.AL10.alSourcef; import static org.lwjgl.opengl.GL11.*; -import static org.lwjgl.opengl.GL14.GL_ONE_MINUS_CONSTANT_COLOR; -import static org.lwjgl.opengl.GL20.glUniformMatrix4fv; +import static org.lwjgl.opengl.GL20.*; import static org.lwjgl.system.MemoryStack.stackPush; import static org.lwjgl.system.MemoryUtil.NULL; @@ -41,12 +38,6 @@ public class LWJGLWindow extends BaseWindow protected String audioDevice; - public double colorR; - public double colorG; - public double colorB; - public double colorA; - public double glow; - protected double[] mx = new double[1]; protected double[] my = new double[1]; @@ -64,19 +55,34 @@ public class LWJGLWindow extends BaseWindow protected HashMap textureSY = new HashMap(); public boolean batchMode = false; + public boolean batchQuads = false; + public boolean batchDepth = false; + public boolean batchDepthMask = false; + public boolean batchGlow = false; - protected boolean useShader = false; + protected boolean shadowsEnabled = false; protected int textureFlag; protected int depthFlag; protected int glowFlag; - public int lightFlag; - public int glowLightFlag; - public int shadowFlag; - public int glowShadowFlag; + protected int lightFlag; + protected int glowLightFlag; + protected int shadeFlag; + protected int glowShadeFlag; + + protected int vboFlag; + protected int vboColorFlag; + + protected int bonesEnabledFlag; + protected int boneMatricesFlag; + + protected int shadowFlag; - public ShadowMap shadowMap; + protected int shadowMapBonesEnabledFlag; + protected int shadowMapBoneMatricesFlag; + + public ShaderHandler shaderHandler; double bbx1 = 1; double bby1 = 0; @@ -88,6 +94,8 @@ public class LWJGLWindow extends BaseWindow double bby3 = 0; double bbz3 = 1; + public String currentTexture = null; + public LWJGLWindow(String name, int x, int y, int z, IUpdater u, IDrawer d, IWindowHandler w, boolean vsync, boolean showMouse) { super(name, x, y, z, u, d, w, vsync, showMouse); @@ -311,12 +319,12 @@ protected String readFileAsString(String filename) throws Exception return source.toString(); } - protected void loop() { GL.createCapabilities(); - this.shadowMap = new ShadowMap(this); + this.shaderHandler = new ShaderHandler(this); + this.shapeRenderer = new ImmediateModeShapeRenderer(this); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); @@ -382,19 +390,10 @@ protected void loop() glfwGetFramebufferSize(window, w, h); - if (useShader) - { - this.shadowMap.renderShadowMap(); - this.shadowMap.renderNormal(); - } - else - { - if (!mac) - glViewport(0, 0, (int) absoluteWidth, (int) absoluteHeight); + if (shadowsEnabled) + this.shaderHandler.renderShadowMap(); - loadPerspective(); - this.drawer.draw(); - } + this.shaderHandler.renderNormal(); glfwSwapBuffers(window); glfwPollEvents(); @@ -452,1077 +451,271 @@ public void setFullscreen(boolean enabled) this.setVsync(this.vsync); } - public void fillOval(double x, double y, double sX, double sY) + public void setColor(double r, double g, double b, double a, double glow) { - x += sX / 2; - y += sY / 2; - - int sides = (int) (sX + sY) / 4 + 5; + this.colorR = r / 255; + this.colorG = g / 255; + this.colorB = b / 255; + this.colorA = a / 255; + this.glow = glow; - glBegin(GL_TRIANGLE_FAN); - for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) - { - glVertex2d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2); - } + glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); - glEnd(); + if (!drawingShadow) + GL20.glUniform1f(glowFlag, (float) glow); } - public void fillGlow(double x, double y, double sX, double sY, boolean shade) + public void setColor(double r, double g, double b, double a) { - this.fillGlow(x, y, sX, sY, shade, false); + this.colorR = r / 255; + this.colorG = g / 255; + this.colorB = b / 255; + this.colorA = a / 255; + glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); + + if (!drawingShadow) + GL20.glUniform1f(glowFlag, 0); } - public void fillGlow(double x, double y, double sX, double sY, boolean shade, boolean light) + public void setColor(double r, double g, double b) { - if (this.drawingShadow) - return; + this.colorR = r / 255; + this.colorG = g / 255; + this.colorB = b / 255; + this.colorA = 1; + glColor3d(this.colorR, this.colorG, this.colorB); - x += sX / 2; - y += sY / 2; + if (!drawingShadow) + GL20.glUniform1f(glowFlag, 0); + } - int sides = (int) (sX + sY) / 16 + 5; + protected void createImage(String image) + { + try + { + InputStream in; - if (!shade) - this.setGlowBlendFunc(); + in = getClass().getResourceAsStream(image); - if (light) - this.setLightBlendFunc(); + if (in == null) + in = getClass().getResourceAsStream("/missing.png"); - glBegin(GL_TRIANGLES); - double step = Math.PI * 2 / sides; + try + { + PNGDecoder decoder = new PNGDecoder(in); - double pX = x + Math.cos(0) * sX / 2; - double pY = y + Math.sin(0) * sY / 2; - double d = 0; - for (int n = 0; n < sides; n++) - { - d += step; + ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); + decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); + buf.flip(); - if (!shade) - glColor3d(0, 0, 0); - else - glColor4d(this.colorR, this.colorG, this.colorB, 0); + enableTexture(); + glEnable(GL_BLEND); + this.setTransparentBlendFunc(); + int id = glGenTextures(); - glVertex2d(pX, pY); - pX = x + Math.cos(d) * sX / 2; - pY = y + Math.sin(d) * sY / 2; - glVertex2d(pX, pY); + glBindTexture(GL_TEXTURE_2D, id); - if (!shade) - glColor3d(this.colorR * this.colorA, this.colorG * this.colorA, this.colorB * this.colorA); - else - glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glVertex2d(x, y); - } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - glEnd(); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); + in.close(); - if (!shade) - this.setTransparentBlendFunc(); + textures.put(image, id); + textureSX.put(image, decoder.getWidth()); + textureSY.put(image, decoder.getHeight()); + } + finally + { + in.close(); + } + } + catch (Exception e) + { + e.printStackTrace(); + } } - @Override - public void fillOval(double x, double y, double z, double sX, double sY, boolean depthTest) + public void setIcon(String icon) { - if (depthTest) - { - enableDepthtest(); - - if (colorA < 1) - glDepthMask(false); - } + InputStream in; - x += sX / 2; - y += sY / 2; + in = getClass().getResourceAsStream(icon); - int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 4 + 5; + if (in == null) + in = getClass().getResourceAsStream("/missing.png"); - glBegin(GL_TRIANGLE_FAN); - for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) + try { - glVertex3d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2, z); - } + PNGDecoder decoder = new PNGDecoder(in); - glEnd(); + ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); + decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); + buf.flip(); - if (depthTest) + GLFWImage image = GLFWImage.malloc(); + GLFWImage.Buffer imagebuf = GLFWImage.malloc(1); + image.set(decoder.getWidth(), decoder.getHeight(), buf); + imagebuf.put(0, image); + glfwSetWindowIcon(window, imagebuf); + } + catch (Exception e) { - glDepthMask(true); - disableDepthtest(); + e.printStackTrace(); } } - @Override - public void fillPartialOval(double x, double y, double sX, double sY, double start, double end) + protected String loadResource(String fileName) { - x += sX / 2; - y += sY / 2; - - int sides = (int) (sX + sY) / 4 + 5; - - glBegin(GL_TRIANGLES); - for (double i = start; i < end; i += (end - start) / sides) + String result = null; + try (InputStream in = getClass().getResourceAsStream(fileName); + Scanner scanner = new Scanner(in, java.nio.charset.StandardCharsets.UTF_8.name())) { - glVertex2d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2); - glVertex2d(x + Math.cos(i + 1) * sX / 2, y + Math.sin(i + 1) * sY / 2); - glVertex2d(x, y); + result = scanner.useDelimiter("\\A").next(); + } + catch (Exception e) + { + e.printStackTrace(); } - glEnd(); + return result; } - public void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade) + public void setUpPerspective() { - this.fillGlow(x, y, z, sX, sY, depthTest, shade, false); - } + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); - public void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light) - { if (this.drawingShadow) - return; - - if (depthTest) - { - enableDepthtest(); - glDepthMask(false); - } - - x += sX / 2; - y += sY / 2; - - int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 16 + 5; - - if (!shade) - this.setGlowBlendFunc(); - - if (light) - this.setLightBlendFunc(); - - glBegin(GL_TRIANGLES); - double step = Math.PI * 2 / sides; - - double pX = x + Math.cos(0) * sX / 2; - double pY = y + Math.sin(0) * sY / 2; - double d = 0; - for (int n = 0; n < sides; n++) - { - d += step; - - if (!shade) - glColor3d(0, 0, 0); - else - glColor4d(this.colorR, this.colorG, this.colorB, 0); - - glVertex3d(pX, pY, z); - pX = x + Math.cos(d) * sX / 2; - pY = y + Math.sin(d) * sY / 2; - glVertex3d(pX, pY, z); - - if (!shade) - glColor3d(this.colorR * this.colorA, this.colorG * this.colorA, this.colorB * this.colorA); - else - glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); + glOrtho(0, absoluteWidth, absoluteHeight, 0, -absoluteDepth, absoluteDepth); + else + glFrustum(-absoluteWidth / (absoluteDepth * 2.0), absoluteWidth / (absoluteDepth * 2.0), absoluteHeight / (absoluteDepth * 2.0), -absoluteHeight / (absoluteDepth * 2.0), 1, absoluteDepth * 100); - glVertex3d(x, y, z); - } + this.angled = false; - glEnd(); + this.yaw = 0; + this.pitch = 0; + this.roll = 0; + this.xOffset = 0; + this.yOffset = 0; + this.zOffset = 0; - if (!shade) - this.setTransparentBlendFunc(); + this.bbx1 = 1; + this.bby1 = 0; + this.bbz1 = 0; + this.bbx2 = 0; + this.bby2 = 1; + this.bbz2 = 0; + this.bbx3 = 0; + this.bby3 = 0; + this.bbz3 = 1; + } - if (depthTest) + public void applyTransformations() + { + for (int i = this.transformations.size() - 1; i >= 0; i--) { - glDepthMask(true); - disableDepthtest(); + this.transformations.get(i).apply(); } } - public void fillFacingOval(double x, double y, double z, double sX, double sY, boolean depthTest) + public void applyShadowTransformations() { - if (depthTest) + for (int i = this.transformations.size() - 1; i >= 0; i--) { - enableDepthtest(); + Transformation t = this.transformations.get(i); - if (colorA < 1) - glDepthMask(false); + if (t.applyAsShadow) + t.apply(); + else + t.applyToWindow(); } + } - x += sX / 2; - y += sY / 2; - - int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 4 + 5; + public void loadPerspective() + { + setUpPerspective(); - glBegin(GL_TRIANGLE_FAN); - for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) + if (this.drawingShadow) { - double ox = Math.cos(i) * sX / 2; - double oy = Math.sin(i) * sY / 2; - glVertex3d(x + ox * bbx1 + oy * bbx2, y + ox * bby1 + oy * bby2, z + ox * bbz1 + oy * bbz2); + applyShadowTransformations(); + for (Transformation t: this.lightBaseTransformation) + t.apply(); } + else + { + applyTransformations(); + for (Transformation t: this.baseTransformations) + t.apply(); - glEnd(); + if (!drawingShadow) + { + float[] projMatrix = new float[16]; + glGetFloatv(GL_PROJECTION_MATRIX, projMatrix); - if (depthTest) - { - glDepthMask(true); - disableDepthtest(); + glUniformMatrix4fv(this.shaderHandler.normalProgramVPUniform, false, projMatrix); + } } } @Override - public void fillGlow(double x, double y, double sX, double sY) + public String getClipboard() { - this.fillGlow(x, y, sX, sY, false); + String s = GLFW.glfwGetClipboardString(window); + + if (s != null) + return s; + else + return ""; } @Override - public void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest) + public void setClipboard(String s) { - this.fillGlow(x, y, z, sX, sY, false, false); + GLFW.glfwSetClipboardString(window, s); } @Override - public void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest) + public void setVsync(boolean enable) { - this.fillFacingGlow(x, y, z, sX, sY, depthTest,false); + if (enable) + GLFW.glfwSwapInterval(1); + else + GLFW.glfwSwapInterval(0); } - public void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade) + @Override + public ArrayList getRawTextKeys() { - this.fillFacingGlow(x, y, z, sX, sY, depthTest, shade,false); + return this.textValidPressedKeys; } - public void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light) + @Override + public String getKeyText(int key) { - if (this.drawingShadow) - return; - - if (depthTest) - { - enableDepthtest(); - glDepthMask(false); - } - - x += sX / 2; - y += sY / 2; - - int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 16 + 5; - - if (!shade) - this.setGlowBlendFunc(); - - if (light) - this.setLightBlendFunc(); + return getTextKeyText(key); + } - glBegin(GL_TRIANGLES); - double step = Math.PI * 2 / sides; + @Override + public String getTextKeyText(int key) + { + String s = glfwGetKeyName(key, 0); - double ox = Math.cos(0) * sX / 2; - double oy = Math.sin(0) * sY / 2; - double d = 0; - for (int n = 0; n < sides; n++) + if (s == null || (key >= InputCodes.KEY_KP_0 && key <= InputCodes.KEY_KP_EQUAL)) { - d += step; - - if (!shade) - glColor3d(0, 0, 0); - else - glColor4d(this.colorR, this.colorG, this.colorB, 0); - - glVertex3d(x + ox * bbx1 + oy * bbx2, y + ox * bby1 + oy * bby2, z + ox * bbz1 + oy * bbz2); - ox = Math.cos(d) * sX / 2; - oy = Math.sin(d) * sY / 2; - glVertex3d(x + ox * bbx1 + oy * bbx2, y + ox * bby1 + oy * bby2, z + ox * bbz1 + oy * bbz2); - - if (!shade) - glColor3d(this.colorR * this.colorA, this.colorG * this.colorA, this.colorB * this.colorA); + String s2 = BaseWindow.keyNames.get(key); + if (s2 == null) + return "Key " + key; else - glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); - - glVertex3d(x, y, z); + return s2; } - - glEnd(); - - if (!shade) - this.setTransparentBlendFunc(); - - if (depthTest) - { - glDepthMask(true); - disableDepthtest(); - } - } - - public void setColor(double r, double g, double b, double a, double glow) - { - this.colorR = r / 255; - this.colorG = g / 255; - this.colorB = b / 255; - this.colorA = a / 255; - this.glow = glow; - - glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); - - if (useShader) - GL20.glUniform1f(glowFlag, (float) glow); - } - - public void setColor(double r, double g, double b, double a) - { - this.colorR = r / 255; - this.colorG = g / 255; - this.colorB = b / 255; - this.colorA = a / 255; - glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); - - if (useShader) - GL20.glUniform1f(glowFlag, 0); - } - - public void setColor(double r, double g, double b) - { - this.colorR = r / 255; - this.colorG = g / 255; - this.colorB = b / 255; - this.colorA = 1; - glColor3d(this.colorR, this.colorG, this.colorB); - - if (useShader) - GL20.glUniform1f(glowFlag, 0); - } - - public void drawOval(double x, double y, double sX, double sY) - { - x += sX / 2; - y += sY / 2; - - int sides = (int) (sX + sY) / 4 + 5; - - for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) - { - glBegin(GL_LINES); - glVertex2d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2); - glVertex2d(x + Math.cos(i + Math.PI * 2 / sides) * sX / 2, y + Math.sin(i + Math.PI * 2 / sides) * sY / 2); - glEnd(); - } - } - - public void drawOval(double x, double y, double z, double sX, double sY) - { - x += sX / 2; - y += sY / 2; - - int sides = (int) (sX + sY + Math.max(z / 20, 0)) / 4 + 5; - - for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / sides) - { - glBegin(GL_LINES); - glVertex3d(x + Math.cos(i) * sX / 2, y + Math.sin(i) * sY / 2, z); - glVertex3d(x + Math.cos(i + Math.PI * 2 / sides) * sX / 2, y + Math.sin(i + Math.PI * 2 / sides) * sY / 2, z); - glEnd(); - } - } - - public void fillRect(double x, double y, double sX, double sY) - { - glBegin(GL_TRIANGLE_FAN); - - glVertex2d(x, y); - glVertex2d(x + sX, y); - glVertex2d(x + sX, y + sY); - glVertex2d(x, y + sY); - - glEnd(); - } - - public void fillBox(double x, double y, double z, double sX, double sY, double sZ) - { - fillBox(x, y, z, sX, sY, sZ, (byte) 0); - } - - /** - * Options byte: - * - * 0: default - * - * +1 hide behind face - * +2 hide front face - * +4 hide bottom face - * +8 hide top face - * +16 hide left face - * +32 hide right face - * - * +64 draw on top - * */ - public void fillBox(double x, double y, double z, double sX, double sY, double sZ, byte options) - { - if (!batchMode) - { - enableDepthtest(); - - if (colorA < 1) - glDepthMask(false); - - if ((options >> 6) % 2 == 0) - glDepthFunc(GL_LEQUAL); - else - glDepthFunc(GL_ALWAYS); - - GL11.glBegin(GL11.GL_QUADS); - } - - if (options % 2 == 0) - { - GL11.glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); - GL11.glVertex3d(x + sX, y, z); - GL11.glVertex3d(x, y, z); - GL11.glVertex3d(x, y + sY, z); - GL11.glVertex3d(x + sX, y + sY, z); - } - - if ((options >> 2) % 2 == 0) - { - GL11.glColor4d(this.colorR * 0.8, this.colorG * 0.8, this.colorB * 0.8, this.colorA); - GL11.glVertex3d(x + sX, y + sY, z + sZ); - GL11.glVertex3d(x, y + sY, z + sZ); - GL11.glVertex3d(x, y + sY, z); - GL11.glVertex3d(x + sX, y + sY, z); - } - - if ((options >> 3) % 2 == 0) - { - GL11.glColor4d(this.colorR * 0.8, this.colorG * 0.8, this.colorB * 0.8, this.colorA); - GL11.glVertex3d(x + sX, y , z + sZ); - GL11.glVertex3d(x, y, z + sZ); - GL11.glVertex3d(x, y, z); - GL11.glVertex3d(x + sX, y, z); - } - - if ((options >> 4) % 2 == 0) - { - GL11.glColor4d(this.colorR * 0.6, this.colorG * 0.6, this.colorB * 0.6, this.colorA); - GL11.glVertex3d(x, y + sY, z + sZ); - GL11.glVertex3d(x, y + sY, z); - GL11.glVertex3d(x, y, z); - GL11.glVertex3d(x, y, z + sZ); - } - - if ((options >> 5) % 2 == 0) - { - GL11.glColor4d(this.colorR * 0.6, this.colorG * 0.6, this.colorB * 0.6, this.colorA); - GL11.glVertex3d(x + sX, y + sY, z); - GL11.glVertex3d(x + sX, y + sY, z + sZ); - GL11.glVertex3d(x + sX, y, z + sZ); - GL11.glVertex3d(x + sX, y, z); - } - - if ((options >> 1) % 2 == 0) - { - GL11.glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); - GL11.glVertex3d(x + sX, y + sY, z + sZ); - GL11.glVertex3d(x, y + sY, z + sZ); - GL11.glVertex3d(x, y, z + sZ); - GL11.glVertex3d(x + sX, y, z + sZ); - } - - if (!batchMode) - { - GL11.glEnd(); - disableDepthtest(); - glDepthMask(true); - } - } - - public void fillQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) - { - glBegin(GL_TRIANGLE_FAN); - - glVertex2d(x1, y1); - glVertex2d(x2, y2); - glVertex2d(x3, y3); - glVertex2d(x4, y4); - - glEnd(); - } - - public void fillQuadBox(double x1, double y1, - double x2, double y2, - double x3, double y3, - double x4, double y4, - double z, double sZ, - byte options) - { - enableDepthtest(); - - if ((options >> 6) % 2 == 0) - glDepthFunc(GL_LEQUAL); - else - glDepthFunc(GL_ALWAYS); - - if (options % 2 == 0) - { - GL11.glBegin(GL11.GL_TRIANGLE_FAN); - GL11.glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); - GL11.glVertex3d(x1, y1, z); - GL11.glVertex3d(x2, y2, z); - GL11.glVertex3d(x3, y3, z); - GL11.glVertex3d(x4, y4, z); - GL11.glEnd(); - } - - if ((options >> 2) % 2 == 0) - { - GL11.glBegin(GL11.GL_TRIANGLE_FAN); - GL11.glColor4d(this.colorR * 0.6, this.colorG * 0.6, this.colorB * 0.6, this.colorA); - GL11.glVertex3d(x1, y1, z + sZ); - GL11.glVertex3d(x2, y2, z + sZ); - GL11.glVertex3d(x2, y2, z); - GL11.glVertex3d(x1, y1, z); - GL11.glEnd(); - } - - if ((options >> 3) % 2 == 0) - { - GL11.glBegin(GL11.GL_TRIANGLE_FAN); - GL11.glColor4d(this.colorR * 0.6, this.colorG * 0.6, this.colorB * 0.6, this.colorA); - GL11.glVertex3d(x3, y3, z + sZ); - GL11.glVertex3d(x4, y4, z + sZ); - GL11.glVertex3d(x4, y4, z); - GL11.glVertex3d(x3, y3, z); - GL11.glEnd(); - } - - if ((options >> 4) % 2 == 0) - { - GL11.glBegin(GL11.GL_TRIANGLE_FAN); - GL11.glColor4d(this.colorR * 0.8, this.colorG * 0.8, this.colorB * 0.8, this.colorA); - GL11.glVertex3d(x1, y1, z + sZ); - GL11.glVertex3d(x4, y4, z + sZ); - GL11.glVertex3d(x4, y4, z); - GL11.glVertex3d(x1, y1, z); - GL11.glEnd(); - } - - if ((options >> 5) % 2 == 0) - { - GL11.glBegin(GL11.GL_TRIANGLE_FAN); - GL11.glColor4d(this.colorR * 0.6, this.colorG * 0.6, this.colorB * 0.6, this.colorA); - GL11.glVertex3d(x3, y3, z + sZ); - GL11.glVertex3d(x2, y2, z + sZ); - GL11.glVertex3d(x2, y2, z); - GL11.glVertex3d(x3, y3, z); - GL11.glEnd(); - } - - if ((options >> 1) % 2 == 0) - { - GL11.glBegin(GL11.GL_TRIANGLE_FAN); - GL11.glColor4d(this.colorR, this.colorG, this.colorB, this.colorA); - GL11.glVertex3d(x1, y1, z + sZ); - GL11.glVertex3d(x2, y2, z + sZ); - GL11.glVertex3d(x3, y3, z + sZ); - GL11.glVertex3d(x4, y4, z + sZ); - GL11.glEnd(); - } - - disableDepthtest(); - } - - public void drawRect(double x, double y, double sX, double sY) - { - glBegin(GL_LINES); - glVertex2d(x, y); - glVertex2d(x + sX, y); - glEnd(); - - glBegin(GL_LINES); - glVertex2d(x, y); - glVertex2d(x, y + sY); - glEnd(); - - glBegin(GL_LINES); - glVertex2d(x, y + sY); - glVertex2d(x + sX, y + sY); - glEnd(); - - glBegin(GL_LINES); - glVertex2d(x + sX, y); - glVertex2d(x + sX, y + sY); - glEnd(); - } - - protected void createImage(String image) - { - try - { - InputStream in; - - - in = getClass().getResourceAsStream(image); - - if (in == null) - in = getClass().getResourceAsStream("/missing.png"); - - try - { - PNGDecoder decoder = new PNGDecoder(in); - - ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); - decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); - buf.flip(); - - enableTexture(); - glEnable(GL_BLEND); - this.setTransparentBlendFunc(); - int id = glGenTextures(); - - glBindTexture(GL_TEXTURE_2D, id); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); - in.close(); - - textures.put(image, id); - textureSX.put(image, decoder.getWidth()); - textureSY.put(image, decoder.getHeight()); - } - finally - { - in.close(); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public void setIcon(String icon) - { - InputStream in; - - in = getClass().getResourceAsStream(icon); - - if (in == null) - in = getClass().getResourceAsStream("/missing.png"); - - try - { - PNGDecoder decoder = new PNGDecoder(in); - - ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); - decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); - buf.flip(); - - GLFWImage image = GLFWImage.malloc(); - GLFWImage.Buffer imagebuf = GLFWImage.malloc(1); - image.set(decoder.getWidth(), decoder.getHeight(), buf); - imagebuf.put(0, image); - glfwSetWindowIcon(window, imagebuf); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - protected String loadResource(String fileName) - { - String result = null; - try (InputStream in = getClass().getResourceAsStream(fileName); - Scanner scanner = new Scanner(in, java.nio.charset.StandardCharsets.UTF_8.name())) - { - result = scanner.useDelimiter("\\A").next(); - } - catch (Exception e) - { - e.printStackTrace(); - } - - return result; - } - - public void setUpPerspective() - { - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - if (this.drawingShadow) - glOrtho(0, absoluteWidth, absoluteHeight, 0, -absoluteDepth, absoluteDepth); - else - glFrustum(-absoluteWidth / (absoluteDepth * 2.0), absoluteWidth / (absoluteDepth * 2.0), absoluteHeight / (absoluteDepth * 2.0), -absoluteHeight / (absoluteDepth * 2.0), 1, absoluteDepth * 100); - - this.angled = false; - - this.yaw = 0; - this.pitch = 0; - this.roll = 0; - this.xOffset = 0; - this.yOffset = 0; - this.zOffset = 0; - - this.bbx1 = 1; - this.bby1 = 0; - this.bbz1 = 0; - this.bbx2 = 0; - this.bby2 = 1; - this.bbz2 = 0; - this.bbx3 = 0; - this.bby3 = 0; - this.bbz3 = 1; - } - - public void applyTransformations() - { - for (int i = this.transformations.size() - 1; i >= 0; i--) - { - this.transformations.get(i).apply(); - } - } - - public void applyShadowTransformations() - { - for (int i = this.transformations.size() - 1; i >= 0; i--) - { - Transformation t = this.transformations.get(i); - - if (t.applyAsShadow) - t.apply(); - else - t.applyToWindow(); - } - } - - public void loadPerspective() - { - setUpPerspective(); - - if (this.drawingShadow) - { - applyShadowTransformations(); - for (Transformation t: this.lightBaseTransformation) - t.apply(); - } - else - { - applyTransformations(); - for (Transformation t: this.baseTransformations) - t.apply(); - - if (this.useShader) - { - float[] projMatrix = new float[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projMatrix); - - glUniformMatrix4fv(this.shadowMap.normalProgramVPUniform, false, projMatrix); - } - } - } - - public void drawImage(double x, double y, double sX, double sY, String image, boolean scaled) - { - drawImage(x, y, sX, sY, 0, 0, 1, 1, image, scaled); - } - - public void drawImage(double x, double y, double z, double sX, double sY, String image, boolean scaled) - { - drawImage(x, y, z, sX, sY, 0, 0, 1, 1, image, scaled); - } - - public void drawImage(double x, double y, double sX, double sY, String image, double rotation, boolean scaled) - { - drawImage(x, y, sX, sY, 0, 0, 1, 1, image, rotation, scaled); - } - - public void drawImage(double x, double y, double z, double sX, double sY, String image, double rotation, boolean scaled) - { - drawImage(x, y, z, sX, sY, 0, 0, 1, 1, image, rotation, scaled); - } - - public void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled) - { - if (this.drawingShadow) - return; - - if (!textures.containsKey(image)) - createImage(image); - - loadPerspective(); - - glMatrixMode(GL_MODELVIEW); - enableTexture(); - - glEnable(GL_BLEND); - this.setTransparentBlendFunc(); - - glBindTexture(GL_TEXTURE_2D, textures.get(image)); - - double width = sX * (u2 - u1); - double height = sY * (v2 - v1); - - if (scaled) - { - width *= textureSX.get(image); - height *= textureSY.get(image); - } - - glBegin(GL_TRIANGLE_FAN); - glTexCoord2d(u1, v1); - glVertex2d(x, y); - glTexCoord2d(u1, v2); - glVertex2d(x, y + height); - glTexCoord2d(u2, v2); - glVertex2d(x + width, y + height); - glTexCoord2d(u2, v1); - glVertex2d(x + width, y); - - glEnd(); - - glMatrixMode(GL_PROJECTION); - disableTexture(); - - if (useShader) - GL20.glUniform1i(textureFlag, 0); - } - - public void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled) - { - if (this.drawingShadow) - return; - - if (!textures.containsKey(image)) - createImage(image); - - loadPerspective(); - - glMatrixMode(GL_MODELVIEW); - enableTexture(); - - glEnable(GL_BLEND); - this.setTransparentBlendFunc(); - - glBindTexture(GL_TEXTURE_2D, textures.get(image)); - - double width = sX * (u2 - u1); - double height = sY * (v2 - v1); - - if (scaled) - { - width *= textureSX.get(image); - height *= textureSY.get(image); - } - - glBegin(GL_TRIANGLE_FAN); - glTexCoord2d(u1, v1); - glVertex2d(rotateX(-width / 2, -height / 2, x, rotation), rotateY(-width / 2, -height / 2, y, rotation)); - glTexCoord2d(u1, v2); - glVertex2d(rotateX(width / 2, -height / 2, x, rotation), rotateY(width / 2, -height / 2, y, rotation)); - glTexCoord2d(u2, v2); - glVertex2d(rotateX(width / 2, height / 2, x, rotation), rotateY(width / 2, height / 2, y, rotation)); - glTexCoord2d(u2, v1); - glVertex2d(rotateX(-width / 2, height / 2, x, rotation), rotateY(-width / 2, height / 2, y, rotation)); - - glEnd(); - - glMatrixMode(GL_PROJECTION); - disableTexture(); - } - - public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled) - { - this.drawImage(x, y, z, sX, sY, u1, v1, u2, v2, image, scaled, true); - } - - public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled, boolean depthtest) - { - if (this.drawingShadow) - return; - - if (!textures.containsKey(image)) - createImage(image); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - if (depthtest) - enableDepthtest(); - - loadPerspective(); - - glMatrixMode(GL_MODELVIEW); - - enableTexture(); - glEnable(GL_BLEND); - this.setTransparentBlendFunc(); - - glDepthMask(false); - - glBindTexture(GL_TEXTURE_2D, textures.get(image)); - - double width = sX * (u2 - u1); - double height = sY * (v2 - v1); - - if (scaled) - { - width *= textureSX.get(image); - height *= textureSY.get(image); - } - - glBegin(GL_TRIANGLE_FAN); - glTexCoord2d(u1, v1); - glVertex3d(x, y, z); - glTexCoord2d(u1, v2); - glVertex3d(x, y + height, z); - glTexCoord2d(u2, v2); - glVertex3d(x + width, y + height, z); - glTexCoord2d(u2, v1); - glVertex3d(x + width, y, z); - - glEnd(); - - glMatrixMode(GL_PROJECTION); - disableTexture(); - - glDepthMask(true); - - if (depthtest) - disableDepthtest(); - } - - public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled) - { - this.drawImage(x, y, z, sX, sY, u1, v1, u2, v2, image, rotation, scaled, true); - } - - public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled, boolean depthtest) - { - if (this.drawingShadow) - return; - - if (!textures.containsKey(image)) - createImage(image); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - if (depthtest) - enableDepthtest(); - - loadPerspective(); - glMatrixMode(GL_MODELVIEW); - - enableTexture(); - glEnable(GL_BLEND); - this.setTransparentBlendFunc(); - - glDepthMask(false); - - glBindTexture(GL_TEXTURE_2D, textures.get(image)); - - double width = sX * (u2 - u1); - double height = sY * (v2 - v1); - - if (scaled) - { - width *= textureSX.get(image); - height *= textureSY.get(image); - } - - glBegin(GL_TRIANGLE_FAN); - glTexCoord2d(u1, v1); - glVertex3d(rotateX(-width / 2, -height / 2, x, rotation), rotateY(-width / 2, -height / 2, y, rotation), z); - glTexCoord2d(u1, v2); - glVertex3d(rotateX(width / 2, -height / 2, x, rotation), rotateY(width / 2, -height / 2, y, rotation), z); - glTexCoord2d(u2, v2); - glVertex3d(rotateX(width / 2, height / 2, x, rotation), rotateY(width / 2, height / 2, y, rotation), z); - glTexCoord2d(u2, v1); - glVertex3d(rotateX(-width / 2, height / 2, x, rotation), rotateY(-width / 2, height / 2, y, rotation), z); - - glEnd(); - - glMatrixMode(GL_PROJECTION); - disableTexture(); - - glDepthMask(true); - - if (depthtest) - disableDepthtest(); - } - - public double rotateX(double px, double py, double posX, double rotation) - { - return (px * Math.cos(rotation) - py * Math.sin(rotation)) + posX; - } - - public double rotateY(double px, double py, double posY, double rotation) - { - return (py * Math.cos(rotation) + px * Math.sin(rotation)) + posY; - } - - @Override - public String getClipboard() - { - String s = GLFW.glfwGetClipboardString(window); - - if (s != null) - return s; - else - return ""; - } - - @Override - public void setClipboard(String s) - { - GLFW.glfwSetClipboardString(window, s); - } - - @Override - public void setVsync(boolean enable) - { - if (enable) - GLFW.glfwSwapInterval(1); - else - GLFW.glfwSwapInterval(0); - } - - @Override - public ArrayList getRawTextKeys() - { - return this.textValidPressedKeys; - } - - @Override - public String getKeyText(int key) - { - return getTextKeyText(key); - } - - @Override - public String getTextKeyText(int key) - { - String s = glfwGetKeyName(key, 0); - - if (s == null || (key >= InputCodes.KEY_KP_0 && key <= InputCodes.KEY_KP_EQUAL)) - { - String s2 = BaseWindow.keyNames.get(key); - if (s2 == null) - return "Key " + key; - else - return s2; - } - else - return s; - } + else + return s; + } @Override public int translateKey(int key) @@ -1587,6 +780,10 @@ public void setBatchMode(boolean enabled, boolean quads, boolean depth, boolean public void setBatchMode(boolean enabled, boolean quads, boolean depth, boolean glow, boolean depthMask) { this.batchMode = enabled; + this.batchQuads = quads; + this.batchDepth = depth; + this.batchGlow = glow; + this.batchDepthMask = depthMask; if (enabled) { @@ -1618,6 +815,96 @@ public void setBatchMode(boolean enabled, boolean quads, boolean depth, boolean } } + public void setDrawOptions(boolean depth, boolean glow) + { + this.batchDepth = depth; + this.batchGlow = glow; + + if (depth) + { + enableDepthtest(); + glDepthFunc(GL_LEQUAL); + } + else + disableDepthtest(); + + if (glow) + this.setGlowBlendFunc(); + else + this.setTransparentBlendFunc(); + } + + public void setDrawOptions(boolean depth, boolean glow, boolean depthMask) + { + this.batchDepth = depth; + this.batchGlow = glow; + this.batchDepthMask = depthMask; + + glDepthMask(depthMask); + + if (depth) + { + enableDepthtest(); + glDepthFunc(GL_LEQUAL); + } + else + disableDepthtest(); + + if (glow) + this.setGlowBlendFunc(); + else + this.setTransparentBlendFunc(); + } + + public void setTexture(String image) + { + this.setTexture(image, true); + } + + public void setTexture(String image, boolean batch) + { + if (image.equals(this.currentTexture)) + return; + + if (batch) + this.setBatchMode(false, this.batchQuads, this.batchDepth, this.batchGlow, this.batchDepthMask); + + this.currentTexture = image; + + if (!textures.containsKey(image)) + createImage(image); + + glMatrixMode(GL_MODELVIEW); + enableTexture(); + + glEnable(GL_BLEND); + this.setTransparentBlendFunc(); + + glBindTexture(GL_TEXTURE_2D, textures.get(image)); + + if (batch) + this.setBatchMode(true, this.batchQuads, this.batchDepth, this.batchGlow, this.batchDepthMask); + } + + public void setTextureCoords(double u, double v) + { + glTexCoord2d(u, v); + } + + public void stopTexture() + { + if (this.currentTexture == null) + return; + + this.currentTexture = null; + glMatrixMode(GL_PROJECTION); + + this.setBatchMode(false, this.batchQuads, this.batchDepth, this.batchGlow, this.batchDepthMask); + this.setBatchMode(true, this.batchQuads, this.batchDepth, this.batchGlow, this.batchDepthMask); + + disableTexture(); + } + @Override public void addVertex(double x, double y, double z) { @@ -1657,42 +944,57 @@ public void setShadowQuality(double quality) { if (quality <= 0) { - this.shadowMap.quality = 1; - this.useShader = false; + this.shaderHandler.quality = 1; + this.shadowsEnabled = false; } else { - this.shadowMap.quality = quality; - this.useShader = true; + this.shaderHandler.quality = quality; + this.shadowsEnabled = true; } } @Override public double getShadowQuality() { - if (!this.useShader) + if (!this.shadowsEnabled) return 0; else - return this.shadowMap.quality; + return this.shaderHandler.quality; } @Override public void setLighting(double light, double glowLight, double shadow, double glowShadow) { - if (useShader) - { - GL20.glUniform1f(this.lightFlag, (float) light); - GL20.glUniform1f(this.glowLightFlag, (float) glowLight); - GL20.glUniform1f(this.shadowFlag, (float) shadow); - GL20.glUniform1f(this.glowShadowFlag, (float) glowShadow); - } + GL20.glUniform1f(this.lightFlag, (float) light); + GL20.glUniform1f(this.glowLightFlag, (float) glowLight); + GL20.glUniform1f(this.shadeFlag, (float) shadow); + GL20.glUniform1f(this.glowShadeFlag, (float) glowShadow); + } + + @Override + public ModelPart createModelPart() + { + return new ImmediateModeModelPart(this); + } + + @Override + public ModelPart createModelPart(Model model, ArrayList shapes, Model.Material material) + { + return new VBOModelPart(this, model, shapes, material); + } + + @Override + public PosedModel createPosedModel(Model m) + { + return new VBOPosedModel(m); } public void enableTexture() { glEnable(GL_TEXTURE_2D); - if (useShader) + if (!drawingShadow) { GL20.glUniform1i(textureFlag, 1); GL20.glActiveTexture(GL13.GL_TEXTURE0); @@ -1701,15 +1003,16 @@ public void enableTexture() public void disableTexture() { + this.currentTexture = null; glDisable(GL_TEXTURE_2D); - if (useShader) + if (!drawingShadow) { GL20.glUniform1i(textureFlag, 0); glEnable(GL_TEXTURE_2D); GL20.glActiveTexture(GL13.GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, this.shadowMap.depthTexture); + glBindTexture(GL_TEXTURE_2D, this.shaderHandler.depthTexture); } } @@ -1717,7 +1020,7 @@ public void enableDepthtest() { glEnable(GL_DEPTH_TEST); - if (useShader) + if (!drawingShadow) GL20.glUniform1i(depthFlag, 1); } @@ -1725,7 +1028,7 @@ public void disableDepthtest() { glDisable(GL_DEPTH_TEST); - if (useShader) + if (!drawingShadow) GL20.glUniform1i(depthFlag, 0); } @@ -1743,4 +1046,110 @@ public void setTransparentBlendFunc() { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } + + public int createVBO() + { + return GL15.glGenBuffers(); + } + + public void vertexBufferData(int id, FloatBuffer buffer) + { + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, id); + GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); + } + + public void renderVBO(int vertexBufferID, int colorBufferID, int texBufferID, int numberIndices) + { + if (!this.drawingShadow) + { + glUniform1i(this.vboFlag, 1); + glUniform4f(this.vboColorFlag, (float) this.colorR, (float) this.colorG, (float) this.colorB, (float) this.colorA); + } + + GL11.glEnableClientState(GL_COLOR_ARRAY); + GL11.glEnableClientState(GL_VERTEX_ARRAY); + + if (texBufferID != 0) + GL11.glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferID); + GL11.glVertexPointer(3, GL_FLOAT, 0, 0); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, colorBufferID); + GL11.glColorPointer(4, GL_FLOAT, 0, 0); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + + if (texBufferID != 0) + { + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texBufferID); + GL11.glTexCoordPointer(2, GL_FLOAT, 0, 0); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + } + + GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, numberIndices); + + GL11.glDisableClientState(GL_TEXTURE_COORD_ARRAY); + GL11.glDisableClientState(GL_VERTEX_ARRAY); + GL11.glDisableClientState(GL_COLOR_ARRAY); + + if (!this.drawingShadow) + { + glUniform1i(this.vboFlag, 0); + } + } + + public void renderPosedVBO(int vertexBufferID, int colorBufferID, int texBufferID, int boneBufferID, int numberIndices) + { + if (!this.drawingShadow) + { + glUniform1i(this.vboFlag, 1); + glUniform1i(this.bonesEnabledFlag, 1); + glUniform4f(this.vboColorFlag, (float) this.colorR, (float) this.colorG, (float) this.colorB, (float) this.colorA); + } + else + glUniform1i(this.shadowMapBonesEnabledFlag, 1); + + GL11.glEnableClientState(GL_COLOR_ARRAY); + GL11.glEnableClientState(GL_VERTEX_ARRAY); + + if (texBufferID != 0) + GL11.glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferID); + GL11.glVertexPointer(3, GL_FLOAT, 0, 0); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, colorBufferID); + GL11.glColorPointer(4, GL_FLOAT, 0, 0); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + + glBindBuffer(GL_ARRAY_BUFFER, boneBufferID); + glEnableVertexAttribArray(6); + GL20.glVertexAttribPointer(6, 4, GL_FLOAT, false, 0, 0); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + + if (texBufferID != 0) + { + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texBufferID); + GL11.glTexCoordPointer(2, GL_FLOAT, 0, 0); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + } + + GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, numberIndices); + + GL11.glDisableClientState(GL_TEXTURE_COORD_ARRAY); + GL11.glDisableClientState(GL_VERTEX_ARRAY); + GL11.glDisableClientState(GL_COLOR_ARRAY); + + if (!this.drawingShadow) + { + glUniform1i(this.vboFlag, 0); + glUniform1i(this.bonesEnabledFlag, 0); + } + else + glUniform1i(this.shadowMapBonesEnabledFlag, 0); + + glDisableVertexAttribArray(6); + } } \ No newline at end of file diff --git a/src/main/java/lwjglwindow/ShadowMap.java b/src/main/java/lwjglwindow/ShaderHandler.java similarity index 82% rename from src/main/java/lwjglwindow/ShadowMap.java rename to src/main/java/lwjglwindow/ShaderHandler.java index 174c8fc5..9b3b97d8 100755 --- a/src/main/java/lwjglwindow/ShadowMap.java +++ b/src/main/java/lwjglwindow/ShaderHandler.java @@ -2,13 +2,14 @@ import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL20; +import org.lwjgl.opengl.GL30; import java.nio.ByteBuffer; import static org.lwjgl.opengl.EXTFramebufferObject.*; import static org.lwjgl.opengl.GL20.*; -public class ShadowMap +public class ShaderHandler { public int size = 2048; public double quality = 1.25; @@ -38,7 +39,7 @@ public class ShadowMap 0.5f, 0.5f, 0.5f, 1.0f }; - public ShadowMap(LWJGLWindow window) + public ShaderHandler(LWJGLWindow window) { try { @@ -93,7 +94,7 @@ public void createShadowProgram() throws Exception glAttachShader(shadowProgram, vshader); glAttachShader(shadowProgram, fshader); - //glBindAttribLocation(shadowProgram, 0, "position"); + GL20.glBindAttribLocation(shadowProgram, 6, "bones"); glLinkProgram(shadowProgram); int linked = glGetProgrami(shadowProgram, GL_LINK_STATUS); @@ -112,6 +113,10 @@ public void initShadowProgram() { glUseProgram(shadowProgram); shadowProgramVPUniform = glGetUniformLocation(shadowProgram, "viewProjectionMatrix"); + + this.window.shadowMapBonesEnabledFlag = GL20.glGetUniformLocation(shadowProgram, "bonesEnabled"); + this.window.shadowMapBoneMatricesFlag = GL20.glGetUniformLocation(shadowProgram, "boneMatrices"); + glUseProgram(0); } @@ -119,13 +124,12 @@ public void createNormalProgram() throws Exception { normalProgram = glCreateProgram(); - int vshader = window.createShader("/shaders/shadow_shade.vert", GL_VERTEX_SHADER); - int fshader = window.createShader("/shaders/shadow_shade.frag", GL_FRAGMENT_SHADER); + int vshader = window.createShader("/shaders/main.vert", GL_VERTEX_SHADER); + int fshader = window.createShader("/shaders/main.frag", GL_FRAGMENT_SHADER); glAttachShader(normalProgram, vshader); glAttachShader(normalProgram, fshader); - //glBindAttribLocation(normalProgram, 0, "position"); - //glBindAttribLocation(normalProgram, 1, "normal"); + GL20.glBindAttribLocation(normalProgram, 6, "bones"); glLinkProgram(normalProgram); int linked = glGetProgrami(normalProgram, GL_LINK_STATUS); @@ -157,8 +161,15 @@ public void initNormalProgram() this.window.lightFlag = GL20.glGetUniformLocation(normalProgram, "light"); this.window.glowLightFlag = GL20.glGetUniformLocation(normalProgram, "glowLight"); + this.window.shadeFlag = GL20.glGetUniformLocation(normalProgram, "shade"); + this.window.glowShadeFlag = GL20.glGetUniformLocation(normalProgram, "glowShade"); + this.window.shadowFlag = GL20.glGetUniformLocation(normalProgram, "shadow"); - this.window.glowShadowFlag = GL20.glGetUniformLocation(normalProgram, "glowShadow"); + this.window.vboFlag = GL20.glGetUniformLocation(normalProgram, "vbo"); + this.window.vboColorFlag = GL20.glGetUniformLocation(normalProgram, "originalColor"); + + this.window.bonesEnabledFlag = GL20.glGetUniformLocation(normalProgram, "bonesEnabled"); + this.window.boneMatricesFlag = GL20.glGetUniformLocation(normalProgram, "boneMatrices"); glUseProgram(0); } @@ -198,6 +209,11 @@ public void renderNormal() glUseProgram(normalProgram); glUniform1i(this.resolutionFlag, this.size); + if (this.window.shadowsEnabled) + glUniform1i(this.window.shadowFlag, 1); + else + glUniform1i(this.window.shadowFlag, 0); + if (!this.initialized) { this.initialized = true; diff --git a/src/main/java/lwjglwindow/VBOModelPart.java b/src/main/java/lwjglwindow/VBOModelPart.java new file mode 100755 index 00000000..f34dc529 --- /dev/null +++ b/src/main/java/lwjglwindow/VBOModelPart.java @@ -0,0 +1,134 @@ +package lwjglwindow; + +import basewindow.BaseWindow; +import basewindow.Model; +import basewindow.ModelPart; +import basewindow.transformation.Rotation; +import basewindow.transformation.Scale; +import basewindow.transformation.Translation; +import org.lwjgl.BufferUtils; + +import java.nio.FloatBuffer; +import java.util.ArrayList; + +import static org.lwjgl.opengl.GL11.*; + +public class VBOModelPart extends ModelPart +{ + public LWJGLWindow window; + + protected int colorVBO; + + protected int vertexVBO; + protected int texVBO; + + @Override + public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll, boolean depthTest) + { + if (this.material.useDefaultDepthMask) + window.setDrawOptions(depthTest, this.material.glow); + else + window.setDrawOptions(depthTest, this.material.glow, this.material.depthMask); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + Translation.transform(window, posX / window.absoluteWidth, posY / window.absoluteHeight, posZ / window.absoluteDepth); + Rotation.transform(window, yaw, pitch, roll); + Scale.transform(window, sX, sY, sZ); + + if (this.material.texture != null) + window.setTexture(this.material.texture, false); + + window.renderVBO(this.vertexVBO, this.colorVBO, this.texVBO, this.shapes.length * 3); + window.disableTexture(); + + glPopMatrix(); + } + + @Override + public void draw(double posX, double posY, double sX, double sY, double yaw) + { + if (this.material.useDefaultDepthMask) + window.setDrawOptions(false, this.material.glow); + else + window.setDrawOptions(false, this.material.glow, this.material.depthMask); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + Translation.transform(window, posX / window.absoluteWidth, posY / window.absoluteHeight, 0); + Rotation.transform(window, yaw, 0, 0); + Scale.transform(window, sX, sY, 0); + + if (this.material.texture != null) + window.setTexture(this.material.texture, false); + + window.renderVBO(this.vertexVBO, this.colorVBO, this.texVBO, this.shapes.length * 3); + window.disableTexture(); + + glPopMatrix(); + } + + @Override + public void processShapes() + { + FloatBuffer vert = BufferUtils.createFloatBuffer(this.shapes.length * 9); + FloatBuffer color = BufferUtils.createFloatBuffer(this.shapes.length * 12); + FloatBuffer tex = BufferUtils.createFloatBuffer(this.shapes.length * 6); + + for (Shape s : this.shapes) + { + for (Point p : s.points) + { + vert.put((float) p.x); + vert.put((float) p.y); + vert.put((float) p.z); + } + + for (Point p : s.texCoords) + { + tex.put((float) p.x); + tex.put((float) p.y); + } + + for (double[] p : s.colors) + { + color.put((float) (p[0] * this.material.colorR)); + color.put((float) (p[1] * this.material.colorG)); + color.put((float) (p[2] * this.material.colorB)); + color.put((float) (p[3] * this.material.colorA)); + } + } + + vert.flip(); + color.flip(); + tex.flip(); + + this.vertexVBO = window.createVBO(); + this.colorVBO = window.createVBO(); + + window.vertexBufferData(this.vertexVBO, vert); + window.vertexBufferData(this.colorVBO, color); + + if (this.material.texture != null) + { + this.texVBO = window.createVBO(); + window.vertexBufferData(this.texVBO, tex); + } + } + + public VBOModelPart(LWJGLWindow window) + { + super(window); + } + + public VBOModelPart(BaseWindow window, Model model, ArrayList shapes, Model.Material material) + { + super(window, model, shapes, material); + } + + @Override + public void setWindow(BaseWindow w) + { + this.window = (LWJGLWindow) w; + } +} diff --git a/src/main/java/lwjglwindow/VBOPosedModel.java b/src/main/java/lwjglwindow/VBOPosedModel.java new file mode 100755 index 00000000..b23c6bdd --- /dev/null +++ b/src/main/java/lwjglwindow/VBOPosedModel.java @@ -0,0 +1,133 @@ +package lwjglwindow; + +import basewindow.Model; +import basewindow.ModelPart; +import basewindow.PosedModel; +import basewindow.transformation.Rotation; +import basewindow.transformation.Scale; +import basewindow.transformation.Translation; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL20; + +import java.nio.FloatBuffer; +import java.util.HashMap; + +import static org.lwjgl.opengl.GL11.*; + +public class VBOPosedModel extends PosedModel +{ + public HashMap bonesVBOs = new HashMap<>(); + public float[] matrices; + + public VBOPosedModel(Model model) + { + super(model); + + for (ModelPart m: this.model.models) + { + int vbo = ((LWJGLWindow) this.model.window).createVBO(); + this.bonesVBOs.put(m, vbo); + + FloatBuffer bones = BufferUtils.createFloatBuffer(m.shapes.length * 12); + + for (ModelPart.Shape s : m.shapes) + { + for (ModelPart.Point p : s.points) + { + for (int i = 0; i < 4; i++) + { + if (p.bones != null && i < p.bones.length) + bones.put((float) p.boneWeights[i] + p.bones[i].index); + else + bones.put((float) 0); + } + } + } + + bones.flip(); + + ((LWJGLWindow) this.model.window).vertexBufferData(vbo, bones); + } + + this.matrices = new float[this.model.bones.size() * 16]; + } + + @Override + public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll, boolean depthTest) + { + for (PoseBone b: this.bones) + { + b.computeMatrix(); + b.compileMatrix(); + } + + int in = 0; + for (PoseBone bone : this.bones) + { + for (double v : bone.compiledMatrix) + { + this.matrices[in] = (float) v; + in++; + } + } + + if (!this.model.window.drawingShadow) + GL20.glUniformMatrix4fv(((LWJGLWindow)this.model.window).boneMatricesFlag, false, this.matrices); + else + GL20.glUniformMatrix4fv(((LWJGLWindow)this.model.window).shadowMapBoneMatricesFlag, false, this.matrices); + + for (ModelPart mo: this.model.models) + { + VBOModelPart m = (VBOModelPart) mo; + LWJGLWindow window = (LWJGLWindow) this.model.window; + + if (m.material.useDefaultDepthMask) + window.setDrawOptions(depthTest, m.material.glow); + else + window.setDrawOptions(depthTest, m.material.glow, m.material.depthMask); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + Translation.transform(window, posX / window.absoluteWidth, posY / window.absoluteHeight, posZ / window.absoluteDepth); + Rotation.transform(window, yaw, pitch, roll); + Scale.transform(window, sX, sY, sZ); + + if (m.material.texture != null) + window.setTexture(m.material.texture, false); + + window.renderPosedVBO(m.vertexVBO, m.colorVBO, m.texVBO, this.bonesVBOs.get(m), m.shapes.length * 3); + window.disableTexture(); + + glPopMatrix(); + } + } + + @Override + public void draw(double posX, double posY, double sX, double sY, double yaw) + { + for (ModelPart mo: this.model.models) + { + VBOModelPart m = (VBOModelPart) mo; + LWJGLWindow window = (LWJGLWindow) this.model.window; + + if (m.material.useDefaultDepthMask) + window.setDrawOptions(false, m.material.glow); + else + window.setDrawOptions(false, m.material.glow, m.material.depthMask); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + Translation.transform(window, posX / window.absoluteWidth, posY / window.absoluteHeight, 0); + Rotation.transform(window, yaw, 0, 0); + Scale.transform(window, sX, sY, 0); + + if (m.material.texture != null) + window.setTexture(m.material.texture, false); + + window.renderPosedVBO(m.vertexVBO, m.colorVBO, m.texVBO, this.bonesVBOs.get(m), m.shapes.length * 3); + window.disableTexture(); + + glPopMatrix(); + } + } +} diff --git a/src/main/java/main/Tanks.java b/src/main/java/main/Tanks.java index b3148178..deb4964f 100755 --- a/src/main/java/main/Tanks.java +++ b/src/main/java/main/Tanks.java @@ -2,7 +2,6 @@ import basewindow.ComputerFileManager; import lwjglwindow.LWJGLWindow; -import swingwindow.SwingWindow; import tanks.*; import tanks.extension.Extension; import tanksonline.CommandExecutor; @@ -10,7 +9,6 @@ import tanksonline.TanksOnlineServer; import java.io.File; -import java.util.ArrayList; public class Tanks { @@ -29,9 +27,6 @@ public static void main(String[] args) if (args[i].startsWith("port=")) port = Integer.parseInt(args[i].split("=")[1]); - if (args[i].equals("swing")) - Game.framework = Game.Framework.swing; - if (args[i].equals("debug")) Game.debug = true; @@ -61,7 +56,7 @@ public static void main(String[] args) } } - if (Game.framework == Game.Framework.lwjgl || Game.framework == Game.Framework.swing) + if (Game.framework == Game.Framework.lwjgl) Game.game.fileManager = new ComputerFileManager(); Game.initScript(); @@ -71,8 +66,6 @@ public static void main(String[] args) Game.game.window = new LWJGLWindow("Tanks", 1400, 900 + Drawing.drawing.statsHeight, Game.absoluteDepthBase, new GameUpdater(), new GameDrawer(), new GameWindowHandler(), Game.vsync, !Panel.showMouseTarget); ((LWJGLWindow)Game.game.window).antialiasingEnabled = Game.antialiasing; } - else if (Game.framework == Game.Framework.swing) - Game.game.window = new SwingWindow("Tanks", 1400, 900 + Drawing.drawing.statsHeight, Game.absoluteDepthBase, new GameUpdater(), new GameDrawer(), new GameWindowHandler(), Game.vsync, !Panel.showMouseTarget); Game.game.window.run(); } diff --git a/src/main/java/main/TanksMacApp.java b/src/main/java/main/TanksMacApp.java index 165853bf..b81f789a 100755 --- a/src/main/java/main/TanksMacApp.java +++ b/src/main/java/main/TanksMacApp.java @@ -2,7 +2,6 @@ import basewindow.ComputerFileManager; import lwjglwindow.LWJGLWindow; -import swingwindow.SwingWindow; import tanks.*; import tanksonline.CommandExecutor; import tanksonline.PlayerMap; @@ -25,16 +24,13 @@ public static void main(String[] args) if (args[i].startsWith("port=")) port = Integer.parseInt(args[i].split("=")[1]); - if (args[i].equals("swing")) - Game.framework = Game.Framework.swing; - if (args[i].equals("debug")) Game.debug = true; } if (!Game.isOnlineServer) { - if (Game.framework == Game.Framework.lwjgl || Game.framework == Game.Framework.swing) + if (Game.framework == Game.Framework.lwjgl) Game.game.fileManager = new ComputerFileManager(); Game.initScript(); @@ -44,8 +40,6 @@ public static void main(String[] args) Game.game.window = new LWJGLWindow("Tanks", 1400, 900 + Drawing.drawing.statsHeight, Game.absoluteDepthBase, new GameUpdater(), new GameDrawer(), new GameWindowHandler(), Game.vsync, !Panel.showMouseTarget); ((LWJGLWindow)Game.game.window).antialiasingEnabled = Game.antialiasing; } - else if (Game.framework == Game.Framework.swing) - Game.game.window = new SwingWindow("Tanks", 1400, 900 + Drawing.drawing.statsHeight, Game.absoluteDepthBase, new GameUpdater(), new GameDrawer(), new GameWindowHandler(), Game.vsync, !Panel.showMouseTarget); Game.game.window.run(); } diff --git a/src/main/java/swingwindow/SwingDrawing.java b/src/main/java/swingwindow/SwingDrawing.java deleted file mode 100755 index bacf65c8..00000000 --- a/src/main/java/swingwindow/SwingDrawing.java +++ /dev/null @@ -1,26 +0,0 @@ -package swingwindow; - -import swingwindow.input.InputKeyboard; - -import javax.swing.*; -import java.awt.*; - -public class SwingDrawing extends JFrame -{ - public SwingDrawing(SwingWindow w, int sizeX, int sizeY) - { - this.addKeyListener(new InputKeyboard(w)); - - Container contentPane = this.getContentPane(); - w.panel.setPreferredSize(new Dimension(sizeX, sizeY)); - contentPane.add(w.panel); - contentPane.setSize(sizeX, sizeY); - - this.pack(); - this.setVisible(true); - - this.setResizable(true); - this.setMinimumSize(new Dimension(350, 265)); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - } -} diff --git a/src/main/java/swingwindow/SwingFontRenderer.java b/src/main/java/swingwindow/SwingFontRenderer.java deleted file mode 100755 index a67ec5ae..00000000 --- a/src/main/java/swingwindow/SwingFontRenderer.java +++ /dev/null @@ -1,57 +0,0 @@ -package swingwindow; - -import basewindow.BaseFontRenderer; - -import java.awt.*; -import java.awt.font.FontRenderContext; - -public class SwingFontRenderer extends BaseFontRenderer -{ - public FontRenderContext frc = new FontRenderContext(null, true, true); - - public SwingFontRenderer(SwingWindow h) - { - super(h); - } - - @Override - public void drawString(double x, double y, double z, double sX, double sY, String s) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void drawString(double x, double y, double sX, double sY, String s) - { - SwingWindow home = (SwingWindow) this.home; - home.graphics.setFont(home.graphics.getFont().deriveFont(Font.BOLD, (float) sX * 32)); - home.graphics.drawString(process(s), (int)(x - 1 * sX), (int)(y + 17 * sY)); - } - - @Override - public double getStringSizeX(double sX, String s) - { - SwingWindow home = (SwingWindow) this.home; - home.graphics.setFont(home.graphics.getFont().deriveFont(Font.BOLD, (float) sX * 32)); - return ((SwingWindow) this.home).graphics.getFont().getStringBounds(process(s), frc).getWidth(); - } - - @Override - public double getStringSizeY(double sY, String s) - { - SwingWindow home = (SwingWindow) this.home; - home.graphics.setFont(home.graphics.getFont().deriveFont(Font.BOLD, (float) sY * 32)); - return ((SwingWindow) this.home).graphics.getFont().getSize() / 3.0; - } - - public String process(String s) - { - while (s.contains("\u00A7")) - { - int in = s.indexOf("\u00A7"); - s = s.substring(0, in) + s.substring(in + 13); - } - - return s; - } -} diff --git a/src/main/java/swingwindow/SwingPanel.java b/src/main/java/swingwindow/SwingPanel.java deleted file mode 100755 index 72b56233..00000000 --- a/src/main/java/swingwindow/SwingPanel.java +++ /dev/null @@ -1,57 +0,0 @@ -package swingwindow; - -import swingwindow.input.InputMouse; -import swingwindow.input.InputScroll; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -public class SwingPanel extends JPanel -{ - public Timer timer; - public SwingWindow window; - - public SwingPanel(SwingWindow w) - { - this.window = w; - - this.addMouseListener(new InputMouse(w)); - this.addMouseWheelListener(new InputScroll()); - this.addMouseMotionListener(new InputMouse(w)); - - timer = new Timer(0, new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent e) - { - w.startTiming(); - - w.absoluteWidth = getWidth(); - w.absoluteHeight = getHeight(); - - w.updater.update(); - - repaint(); - - w.stopTiming(); - } - - }); - } - - public void startTimer() - { - timer.start(); - //new SoundThread().execute(); - } - - @Override - public void paint(Graphics g) - { - window.graphics = g; - window.drawer.draw(); - } -} diff --git a/src/main/java/swingwindow/SwingWindow.java b/src/main/java/swingwindow/SwingWindow.java deleted file mode 100755 index d51a24c2..00000000 --- a/src/main/java/swingwindow/SwingWindow.java +++ /dev/null @@ -1,446 +0,0 @@ -package swingwindow; - -import basewindow.*; -import swingwindow.input.InputKeyboard; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.KeyEvent; -import java.net.URL; -import java.util.ArrayList; - -public class SwingWindow extends BaseWindow -{ - public SwingDrawing drawing; - - public SwingPanel panel; - - public Graphics graphics; - - public SwingWindow self; - - public TextClipboard clipboard; - - public ArrayList rawTextInput = new ArrayList(); - - public SwingWindow(String name, int x, int y, int z, IUpdater u, IDrawer d, IWindowHandler w, boolean vsync, boolean showMouse) - { - super(name, x, y, z, u, d, w, vsync, showMouse); - this.self = this; - this.fontRenderer = new SwingFontRenderer(this); - this.clipboard = new TextClipboard(); - - if (System.getProperty("os.name").toLowerCase().contains("mac")) - this.mac = true; - - this.os = System.getProperty("os.name").toLowerCase(); - } - - @Override - public void run() - { - panel = new SwingPanel(self); - drawing = new SwingDrawing(self, (int) self.absoluteWidth, (int) self.absoluteHeight); - - SwingUtilities.invokeLater( - new Runnable() - { - @Override - public void run() - { - drawing.setTitle(self.name); - drawing.add(panel); - - panel.startTimer(); - } - }); - } - - @Override - public void setShowCursor(boolean show) - { - - } - - @Override - public void setCursorLocked(boolean locked) - { - - } - - @Override - public void setCursorPos(double x, double y) - { - - } - - @Override - public void setFullscreen(boolean enabled) - { - - } - - @Override - public void setIcon(String icon) - { - drawing.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(icon))); - } - - @Override - public void fillOval(double x, double y, double sX, double sY) - { - this.graphics.fillOval((int) x, (int) y, (int) sX, (int) sY); - } - - @Override - public void fillOval(double x, double y, double z, double sX, double sY, boolean depthTest) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void fillPartialOval(double x, double y, double sX, double sY, double start, double end) - { - - } - - @Override - public void fillFacingOval(double x, double y, double z, double sX, double sY, boolean depthTest) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void fillGlow(double x, double y, double sX, double sY) - { - - } - - @Override - public void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest) - { - - } - - @Override - public void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest) - { - - } - - @Override - public void fillGlow(double x, double y, double sX, double sY, boolean shade) - { - - } - - @Override - public void fillGlow(double x, double y, double sX, double sY, boolean shade, boolean light) - { - - } - - @Override - public void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade) - { - - } - - @Override - public void fillGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light) - { - - } - - @Override - public void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade) - { - - } - - @Override - public void fillFacingGlow(double x, double y, double z, double sX, double sY, boolean depthTest, boolean shade, boolean light) - { - - } - - @Override - public void setColor(double r, double g, double b, double a, double glow) - { - this.setColor(r, g, b, a); - } - - @Override - public void setColor(double r, double g, double b, double a) - { - this.graphics.setColor(new Color((int) Math.max(0, Math.min(255, r)), (int) Math.max(0, Math.min(255, g)), (int) Math.max(0, Math.min(255, b)), (int) Math.max(0, Math.min(255, a)))); - } - - @Override - public void setColor(double r, double g, double b) - { - this.graphics.setColor(new Color((int) Math.max(0, Math.min(255, r)), (int) Math.max(0, Math.min(255, g)), (int) Math.max(0, Math.min(255, b)))); - } - - @Override - public void drawOval(double x, double y, double sX, double sY) - { - this.graphics.drawOval((int) x, (int) y, (int) sX, (int) sY); - } - - @Override - public void drawOval(double x, double y, double z, double sX, double sY) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void fillRect(double x, double y, double sX, double sY) - { - this.graphics.fillRect((int) x, (int) y, (int) sX, (int) sY); - } - - @Override - public void fillBox(double x, double y, double z, double sX, double sY, double sZ) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void fillBox(double x, double y, double z, double sX, double sY, double sZ, byte options) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void fillQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) - { - throw new UnsupportedOperationException("The Swing renderer does not support quads!"); - } - - @Override - public void fillQuadBox(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double z, double sZ, byte options) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void drawRect(double x, double y, double sX, double sY) - { - this.graphics.drawRect((int) x, (int) y, (int) sX, (int) sY); - } - - @Override - public void drawImage(double x, double y, double sX, double sY, String image, boolean scaled) - { - this.graphics.drawImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(image)), (int) x, (int) y, (int) sX, (int) sY, null); - } - - @Override - public void drawImage(double x, double y, double z, double sX, double sY, String image, boolean scaled) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void setUpPerspective() - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void applyTransformations() - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void loadPerspective() - { - //throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled) - { - throw new UnsupportedOperationException("The Swing renderer does not support UV!"); - } - - @Override - public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, boolean scaled, boolean depthtest) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void drawImage(double x, double y, double sX, double sY, String image, double rotation, boolean scaled) - { - this.drawImage(x - sX / 2, y - sY / 2, sX, sY, image, scaled); - } - - @Override - public void drawImage(double x, double y, double z, double sX, double sY, String image, double rotation, boolean scaled) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void drawImage(double x, double y, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled) - { - throw new UnsupportedOperationException("The Swing renderer does not support UV!"); - } - - @Override - public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public void drawImage(double x, double y, double z, double sX, double sY, double u1, double v1, double u2, double v2, String image, double rotation, boolean scaled, boolean depthtest) - { - throw new UnsupportedOperationException("The Swing renderer does not support 3D!"); - } - - @Override - public String getClipboard() - { - return this.clipboard.getClipboard(); - } - - @Override - public void setClipboard(String s) - { - this.clipboard.setClipboard(s); - } - - @Override - public void setVsync(boolean enable) - { - - } - - @Override - public ArrayList getRawTextKeys() - { - return this.rawTextInput; - } - - @Override - public String getKeyText(int key) - { - return KeyEvent.getKeyText(InputKeyboard.untranslate(key)).toLowerCase(); - } - - @Override - public String getTextKeyText(int key) - { - return KeyEvent.getKeyText(key).toLowerCase(); - } - - @Override - public int translateKey(int key) - { - return InputKeyboard.translate(key); - } - - @Override - public int translateTextKey(int key) - { - return InputKeyboard.translate(key); - } - - @Override - public void transform(double[] matrix) - { - throw new UnsupportedOperationException("The Swing renderer does not support transformations!"); - } - - @Override - public void calculateBillboard() - { - - } - - @Override - public double getEdgeBounds() - { - return 0; - } - - @Override - public void setBatchMode(boolean enabled, boolean quads, boolean depth) - { - - } - - @Override - public void setBatchMode(boolean enabled, boolean quads, boolean depth, boolean glow) - { - - } - - @Override - public void setBatchMode(boolean enabled, boolean quads, boolean depth, boolean glow, boolean depthMask) - { - - } - - @Override - public void addVertex(double x, double y, double z) - { - - } - - @Override - public void addVertex(double x, double y) - { - - } - - @Override - public void openLink(URL url) throws Exception - { - String[] cmd; - - if (os.contains("win")) - cmd = new String[]{"rundll32", "url.dll,FileProtocolHandler", url.toString()}; - else if (os.contains("mac")) - cmd = new String[]{"open", url.toString()}; - else - { - String s = url.toString(); - - if ("file".equals(url.getProtocol())) - s = s.replace("file:", "file://"); - - cmd = new String[]{"xdg-open", s}; - } - - Runtime.getRuntime().exec(cmd); - } - - @Override - public void setShadowQuality(double quality) - { - - } - - @Override - public double getShadowQuality() - { - return 0; - } - - @Override - public void setLighting(double light, double glowLight, double shadow, double glowShadow) - { - - } -} diff --git a/src/main/java/swingwindow/TextClipboard.java b/src/main/java/swingwindow/TextClipboard.java deleted file mode 100755 index 1874ae13..00000000 --- a/src/main/java/swingwindow/TextClipboard.java +++ /dev/null @@ -1,43 +0,0 @@ -package swingwindow; - -import java.awt.*; -import java.awt.datatransfer.*; - -public class TextClipboard implements ClipboardOwner -{ - @Override - public void lostOwnership(Clipboard clipboard, Transferable contents) - { - - } - - public void setClipboard(String string) - { - StringSelection stringSelection = new StringSelection(string); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - clipboard.setContents(stringSelection, this); - } - - public String getClipboard() - { - String result = ""; - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - - Transferable contents = clipboard.getContents(null); - boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor); - if (hasTransferableText) - { - try - { - result = (String) contents.getTransferData(DataFlavor.stringFlavor); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - return result; - } - -} \ No newline at end of file diff --git a/src/main/java/swingwindow/input/InputKeyboard.java b/src/main/java/swingwindow/input/InputKeyboard.java deleted file mode 100755 index 30b2c159..00000000 --- a/src/main/java/swingwindow/input/InputKeyboard.java +++ /dev/null @@ -1,120 +0,0 @@ -package swingwindow.input; - -import swingwindow.SwingWindow; - -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.util.HashMap; - -import static java.awt.event.KeyEvent.*; -import static org.lwjgl.glfw.GLFW.*; - -public class InputKeyboard implements KeyListener -{ - public static final HashMap key_translations = new HashMap<>(); - public static final HashMap key_untranslations = new HashMap<>(); - - public SwingWindow window; - public InputKeyboard(SwingWindow w) - { - this.window = w; - this.setupKeyMap(); - } - - @Override - public void keyTyped(KeyEvent e) - { - - } - - @Override - public void keyPressed(KeyEvent e) - { - if (e.getKeyCode() == 0) - return; - - if (!window.rawTextInput.contains(e.getKeyCode())) - window.rawTextInput.add(e.getKeyCode()); - - int code = translate(e.getKeyCode()); - - if (!window.pressedKeys.contains(code)) - { - window.pressedKeys.add(code); - window.validPressedKeys.add(code); - } - - if (!window.textPressedKeys.contains(code)) - { - window.textPressedKeys.add(code); - window.textValidPressedKeys.add(code); - } - } - - @Override - public void keyReleased(KeyEvent e) - { - window.rawTextInput.remove((Integer) e.getKeyCode()); - - Integer code = translate(e.getKeyCode()); - - window.pressedKeys.remove(code); - window.validPressedKeys.remove(code); - - window.textPressedKeys.remove(code); - window.textValidPressedKeys.remove(code); - } - - public void setupKeyMap() - { - registerTranslation(VK_ESCAPE, GLFW_KEY_ESCAPE); - registerTranslation(VK_F1, GLFW_KEY_F1); - registerTranslation(VK_F2, GLFW_KEY_F2); - registerTranslation(VK_F3, GLFW_KEY_F3); - registerTranslation(VK_F4, GLFW_KEY_F4); - registerTranslation(VK_F5, GLFW_KEY_F5); - registerTranslation(VK_F6, GLFW_KEY_F6); - registerTranslation(VK_F7, GLFW_KEY_F7); - registerTranslation(VK_F8, GLFW_KEY_F8); - registerTranslation(VK_F9, GLFW_KEY_F9); - registerTranslation(VK_F10, GLFW_KEY_F10); - registerTranslation(VK_F11, GLFW_KEY_F11); - registerTranslation(VK_F12, GLFW_KEY_F12); - registerTranslation(VK_BACK_QUOTE, GLFW_KEY_GRAVE_ACCENT); - registerTranslation(VK_BACK_SPACE, GLFW_KEY_BACKSPACE); - registerTranslation(VK_TAB, GLFW_KEY_TAB); - registerTranslation(VK_ENTER, GLFW_KEY_ENTER); - registerTranslation(VK_SHIFT, GLFW_KEY_LEFT_SHIFT); - registerTranslation(VK_CONTROL, GLFW_KEY_LEFT_CONTROL); - registerTranslation(VK_ALT, GLFW_KEY_LEFT_ALT); - registerTranslation(VK_META, GLFW_KEY_LEFT_SUPER); - registerTranslation(VK_CONTEXT_MENU, GLFW_KEY_MENU); - registerTranslation(VK_UP, GLFW_KEY_UP); - registerTranslation(VK_DOWN, GLFW_KEY_DOWN); - registerTranslation(VK_LEFT, GLFW_KEY_LEFT); - registerTranslation(VK_RIGHT, GLFW_KEY_RIGHT); - registerTranslation(VK_SPACE, GLFW_KEY_SPACE); - } - - public void registerTranslation(Integer a, Integer b) - { - key_translations.put(a, b); - key_untranslations.put(b, a); - } - - public static int translate(int key) - { - Integer code = key_translations.get(key); - if (code == null) - code = key; - return code; - } - - public static int untranslate(int key) - { - Integer code = key_untranslations.get(key); - if (code == null) - code = key; - return code; - } -} diff --git a/src/main/java/swingwindow/input/InputMouse.java b/src/main/java/swingwindow/input/InputMouse.java deleted file mode 100755 index 24618763..00000000 --- a/src/main/java/swingwindow/input/InputMouse.java +++ /dev/null @@ -1,62 +0,0 @@ -package swingwindow.input; - -import swingwindow.SwingWindow; - -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; - -public class InputMouse implements MouseListener, MouseMotionListener -{ - public SwingWindow window; - public InputMouse(SwingWindow w) - { - this.window = w; - } - - @Override - public void mouseClicked(MouseEvent e) - { - - } - - @Override - public void mousePressed(MouseEvent e) - { - window.pressedButtons.add(e.getButton() - 1); - window.validPressedButtons.add(e.getButton() - 1); - } - - @Override - public void mouseReleased(MouseEvent e) - { - window.pressedButtons.remove((Integer)(e.getButton() - 1)); - window.validPressedButtons.remove((Integer)(e.getButton() - 1)); - } - - @Override - public void mouseEntered(MouseEvent e) - { - - } - - @Override - public void mouseExited(MouseEvent e) - { - - } - - @Override - public void mouseDragged(MouseEvent e) - { - this.window.absoluteMouseX = e.getPoint().getX(); - this.window.absoluteMouseY = e.getPoint().getY(); - } - - @Override - public void mouseMoved(MouseEvent e) - { - this.window.absoluteMouseX = e.getPoint().getX(); - this.window.absoluteMouseY = e.getPoint().getY(); - } -} diff --git a/src/main/java/swingwindow/input/InputScroll.java b/src/main/java/swingwindow/input/InputScroll.java deleted file mode 100755 index a5d0389d..00000000 --- a/src/main/java/swingwindow/input/InputScroll.java +++ /dev/null @@ -1,20 +0,0 @@ -package swingwindow.input; - -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; - -public class InputScroll implements MouseWheelListener -{ - static boolean validScrollUp = false; - static boolean validScrollDown = false; - - @Override - public void mouseWheelMoved(MouseWheelEvent e) - { - if (e.getPreciseWheelRotation() > 0) - validScrollDown = true; - else if (e.getPreciseWheelRotation() < 0) - validScrollUp = true; - } - -} diff --git a/src/main/java/tanks/AreaEffectFreeze.java b/src/main/java/tanks/AreaEffectFreeze.java index dee6faa9..ba8e4acd 100755 --- a/src/main/java/tanks/AreaEffectFreeze.java +++ b/src/main/java/tanks/AreaEffectFreeze.java @@ -23,9 +23,9 @@ public AreaEffectFreeze(double x, double y) @Override public void imbueEffects() { - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int i = 0; i < 200; i++) + for (int i = 0; i < 100 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); double var = 50; diff --git a/src/main/java/tanks/Drawing.java b/src/main/java/tanks/Drawing.java index 5988e6f5..0b95819e 100755 --- a/src/main/java/tanks/Drawing.java +++ b/src/main/java/tanks/Drawing.java @@ -1,10 +1,12 @@ package tanks; +import basewindow.IModel; +import basewindow.ModelPart; +import basewindow.Model; import tanks.event.EventPlaySound; import tanks.gui.Button; import tanks.gui.Joystick; import tanks.gui.screen.ScreenGame; -import tanks.obstacle.Obstacle; import tanks.tank.TankPlayer; import java.util.ArrayList; @@ -83,7 +85,7 @@ public class Drawing public static final double track_offset = 20; - public static Model rotatedRect = new Model(); + public static ModelPart rotatedRect; private Drawing() { @@ -177,7 +179,7 @@ public void fillOval(double x, double y, double sizeX, double sizeY) double drawSizeX = (sizeX * scale); double drawSizeY = (sizeY * scale); - Game.game.window.fillOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.fillOval(drawX, drawY, drawSizeX, drawSizeY); } public void fillGlow(double x, double y, double sizeX, double sizeY) @@ -201,7 +203,7 @@ public void fillGlow(double x, double y, double sizeX, double sizeY, boolean sha double drawSizeX = (sizeX * scale); double drawSizeY = (sizeY * scale); - Game.game.window.fillGlow(drawX, drawY, drawSizeX, drawSizeY, shade, light); + Game.game.window.shapeRenderer.fillGlow(drawX, drawY, drawSizeX, drawSizeY, shade, light); } public void fillOval(double x, double y, double z, double sizeX, double sizeY) @@ -223,9 +225,9 @@ public void fillOval(double x, double y, double z, double sizeX, double sizeY, b double dZ = z * scale; if (Game.game.window.angled && facing) - Game.game.window.fillFacingOval(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest); + Game.game.window.shapeRenderer.fillFacingOval(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest); else - Game.game.window.fillOval(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest); + Game.game.window.shapeRenderer.fillOval(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest); } public void fillForcedOval(double x, double y, double z, double sizeX, double sizeY, boolean depthTest, boolean facing) @@ -239,9 +241,9 @@ public void fillForcedOval(double x, double y, double z, double sizeX, double si double dZ = z * scale; if (Game.game.window.angled && facing) - Game.game.window.fillFacingOval(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest); + Game.game.window.shapeRenderer.fillFacingOval(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest); else - Game.game.window.fillOval(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest); + Game.game.window.shapeRenderer.fillOval(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest); } public void fillGlow(double x, double y, double z, double sizeX, double sizeY) @@ -278,9 +280,9 @@ public void fillGlow(double x, double y, double z, double sizeX, double sizeY, b double dZ = z * scale; if (Game.game.window.angled && facing) - Game.game.window.fillFacingGlow(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest, shade, light); + Game.game.window.shapeRenderer.fillFacingGlow(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest, shade, light); else - Game.game.window.fillGlow(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest, shade, light); + Game.game.window.shapeRenderer.fillGlow(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest, shade, light); } public void fillForcedGlow(double x, double y, double z, double sizeX, double sizeY, boolean depthTest, boolean facing, boolean shade, boolean light) @@ -294,9 +296,9 @@ public void fillForcedGlow(double x, double y, double z, double sizeX, double si double dZ = z * scale; if (Game.game.window.angled && facing) - Game.game.window.fillFacingGlow(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest, shade, light); + Game.game.window.shapeRenderer.fillFacingGlow(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest, shade, light); else - Game.game.window.fillGlow(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest, shade, light); + Game.game.window.shapeRenderer.fillGlow(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest, shade, light); } public void fillForcedOval(double x, double y, double sizeX, double sizeY) @@ -307,7 +309,7 @@ public void fillForcedOval(double x, double y, double sizeX, double sizeY) double drawSizeX = (sizeX * scale); double drawSizeY = (sizeY * scale); - Game.game.window.fillOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.fillOval(drawX, drawY, drawSizeX, drawSizeY); } public void drawOval(double x, double y, double sizeX, double sizeY) @@ -321,7 +323,7 @@ public void drawOval(double x, double y, double sizeX, double sizeY) double drawSizeX = (sizeX * scale); double drawSizeY = (sizeY * scale); - Game.game.window.drawOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.drawOval(drawX, drawY, drawSizeX, drawSizeY); } public void fillRect(double x, double y, double sizeX, double sizeY) @@ -335,7 +337,7 @@ public void fillRect(double x, double y, double sizeX, double sizeY) double drawSizeX = (sizeX * scale); double drawSizeY = (sizeY * scale); - Game.game.window.fillRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.fillRect(drawX, drawY, drawSizeX, drawSizeY); } public void drawImage(String img, double x, double y, double sizeX, double sizeY) @@ -349,7 +351,7 @@ public void drawImage(String img, double x, double y, double sizeX, double sizeY double drawSizeX = (sizeX * scale); double drawSizeY = (sizeY * scale); - Game.game.window.drawImage(drawX, drawY, drawSizeX, drawSizeY, "/images/" + img, false); + Game.game.window.shapeRenderer.drawImage(drawX, drawY, drawSizeX, drawSizeY, "/images/" + img, false); } public void drawImage(double rotation, String img, double x, double y, double sizeX, double sizeY) @@ -363,7 +365,7 @@ public void drawImage(double rotation, String img, double x, double y, double si double drawSizeX = (sizeX * scale); double drawSizeY = (sizeY * scale); - Game.game.window.drawImage(drawX, drawY, drawSizeX, drawSizeY, "/images/" + img, rotation, false); + Game.game.window.shapeRenderer.drawImage(drawX, drawY, drawSizeX, drawSizeY, "/images/" + img, rotation, false); } public void drawImage(String img, double x, double y, double z, double sizeX, double sizeY) @@ -379,7 +381,7 @@ public void drawImage(String img, double x, double y, double z, double sizeX, do double drawZ = z * scale; - Game.game.window.drawImage(drawX, drawY, drawZ, drawSizeX, drawSizeY, "/images/" + img, false); + Game.game.window.shapeRenderer.drawImage(drawX, drawY, drawZ, drawSizeX, drawSizeY, "/images/" + img, false); } public void drawImage(double rotation, String img, double x, double y, double z, double sizeX, double sizeY) @@ -395,7 +397,7 @@ public void drawImage(double rotation, String img, double x, double y, double z, double drawZ = z * scale; - Game.game.window.drawImage(drawX, drawY, drawZ, drawSizeX, drawSizeY, "/images/" + img, rotation, false); + Game.game.window.shapeRenderer.drawImage(drawX, drawY, drawZ, drawSizeX, drawSizeY, "/images/" + img, rotation, false); } @@ -411,7 +413,7 @@ public void fillQuad(double x1, double y1, double x2, double y2, double x3, doub double dY3 = getPointY(y3); double dY4 = getPointY(y4); - Game.game.window.fillQuad(dX1, dY1, dX2, dY2, dX3, dY3, dX4, dY4); + Game.game.window.shapeRenderer.fillQuad(dX1, dY1, dX2, dY2, dX3, dY3, dX4, dY4); } public void fillQuadBox(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double z, double sZ) @@ -434,7 +436,7 @@ public void fillQuadBox(double x1, double y1, double x2, double y2, double x3, d double dZ = z * scale; double dsZ = sZ * scale; - Game.game.window.fillQuadBox(dX1, dY1, dX2, dY2, dX3, dY3, dX4, dY4, dZ, dsZ, options); + Game.game.window.shapeRenderer.fillQuadBox(dX1, dY1, dX2, dY2, dX3, dY3, dX4, dY4, dZ, dsZ, options); } public void fillInterfaceQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) @@ -449,7 +451,7 @@ public void fillInterfaceQuad(double x1, double y1, double x2, double y2, double double dY3 = getInterfacePointY(y3); double dY4 = getInterfacePointY(y4); - Game.game.window.fillQuad(dX1, dY1, dX2, dY2, dX3, dY3, dX4, dY4); + Game.game.window.shapeRenderer.fillQuad(dX1, dY1, dX2, dY2, dX3, dY3, dX4, dY4); } public double getPointX(double x) @@ -486,7 +488,7 @@ public void fillBackgroundRect(double x, double y, double sizeX, double sizeY) double drawSizeY = (sizeY * scale); Game.game.window.setBatchMode(true, true, true, false, false); - Game.game.window.fillRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.fillRect(drawX, drawY, drawSizeX, drawSizeY); Game.game.window.setBatchMode(false, true, true, false, false); } @@ -537,7 +539,7 @@ public void fillBox(double x, double y, double z, double sizeX, double sizeY, do options = (byte) (options | 4); } - Game.game.window.fillBox(drawX, drawY, drawZ, drawSizeX, drawSizeY, drawSizeZ, options); + Game.game.window.shapeRenderer.fillBox(drawX, drawY, drawZ, drawSizeX, drawSizeY, drawSizeZ, options); } public void fillForcedBox(double x, double y, double z, double sizeX, double sizeY, double sizeZ, byte options) @@ -550,10 +552,10 @@ public void fillForcedBox(double x, double y, double z, double sizeX, double siz double drawSizeY = sizeY * scale; double drawSizeZ = sizeZ * scale; - Game.game.window.fillBox(drawX, drawY, drawZ, drawSizeX, drawSizeY, drawSizeZ, options); + Game.game.window.shapeRenderer.fillBox(drawX, drawY, drawZ, drawSizeX, drawSizeY, drawSizeZ, options); } - public void drawModel(Model m, double x, double y, double width, double height, double angle) + public void drawModel(IModel m, double x, double y, double width, double height, double angle) { double drawX = gameToAbsoluteX(x, 0); double drawY = gameToAbsoluteY(y, 0); @@ -567,7 +569,7 @@ public void drawModel(Model m, double x, double y, double width, double height, m.draw(drawX, drawY, drawSizeX, drawSizeY, angle); } - public void drawModel(Model m, double x, double y, double z, double width, double height, double depth, double angle) + public void drawModel(IModel m, double x, double y, double z, double width, double height, double depth, double angle) { double drawX = gameToAbsoluteX(x, 0); double drawY = gameToAbsoluteY(y, 0); @@ -580,10 +582,10 @@ public void drawModel(Model m, double x, double y, double z, double width, doubl double drawSizeY = height * scale; double drawSizeZ = depth * scale; - m.draw(drawX, drawY, drawZ, drawSizeX, drawSizeY, drawSizeZ, angle); + m.draw(drawX, drawY, drawZ, drawSizeX, drawSizeY, drawSizeZ, angle, 0, 0, true); } - public void drawInterfaceModel(Model m, double x, double y, double width, double height, double angle) + public void drawInterfaceModel(IModel m, double x, double y, double width, double height, double angle) { double drawX = (interfaceScale * x + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2); double drawY = (interfaceScale * y + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); @@ -593,7 +595,7 @@ public void drawInterfaceModel(Model m, double x, double y, double width, double m.draw(drawX, drawY, drawSizeX, drawSizeY, angle); } - public void drawModel(Model m, double x, double y, double z, double width, double height, double depth, double yaw, double pitch, double roll) + public void drawModel(IModel m, double x, double y, double z, double width, double height, double depth, double yaw, double pitch, double roll) { double drawX = gameToAbsoluteX(x, 0); double drawY = gameToAbsoluteY(y, 0); @@ -606,7 +608,7 @@ public void drawModel(Model m, double x, double y, double z, double width, doubl double drawSizeY = height * scale; double drawSizeZ = depth * scale; - m.draw(drawX, drawY, drawZ, drawSizeX, drawSizeY, drawSizeZ, yaw, pitch, roll); + m.draw(drawX, drawY, drawZ, drawSizeX, drawSizeY, drawSizeZ, yaw, pitch, roll, true); } public void drawRect(double x, double y, double sizeX, double sizeY) @@ -620,7 +622,7 @@ public void drawRect(double x, double y, double sizeX, double sizeY) double drawSizeX = (sizeX * scale); double drawSizeY = (sizeY * scale); - Game.game.window.drawRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.drawRect(drawX, drawY, drawSizeX, drawSizeY); } public void fillInterfaceOval(double x, double y, double sizeX, double sizeY) @@ -630,7 +632,7 @@ public void fillInterfaceOval(double x, double y, double sizeX, double sizeY) double drawSizeX = (sizeX * interfaceScale); double drawSizeY = (sizeY * interfaceScale); - Game.game.window.fillOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.fillOval(drawX, drawY, drawSizeX, drawSizeY); } public void fillInterfaceOval(double x, double y, double z, double sizeX, double sizeY) @@ -641,7 +643,7 @@ public void fillInterfaceOval(double x, double y, double z, double sizeX, double double drawSizeY = (sizeY * interfaceScale); double drawZ = z * interfaceScale; - Game.game.window.fillOval(drawX, drawY, drawZ, drawSizeX, drawSizeY, false); + Game.game.window.shapeRenderer.fillOval(drawX, drawY, drawZ, drawSizeX, drawSizeY, false); } @@ -652,7 +654,7 @@ public void fillInterfaceGlow(double x, double y, double sizeX, double sizeY) double drawSizeX = (sizeX * interfaceScale); double drawSizeY = (sizeY * interfaceScale); - Game.game.window.fillGlow(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.fillGlow(drawX, drawY, drawSizeX, drawSizeY); } public void fillInterfaceGlow(double x, double y, double z, double sizeX, double sizeY) @@ -663,7 +665,7 @@ public void fillInterfaceGlow(double x, double y, double z, double sizeX, double double drawSizeY = (sizeY * interfaceScale); double drawZ = interfaceScale * z; - Game.game.window.fillGlow(drawX, drawY, drawZ, drawSizeX, drawSizeY, false); + Game.game.window.shapeRenderer.fillGlow(drawX, drawY, drawZ, drawSizeX, drawSizeY, false); } public void fillInterfaceGlow(double x, double y, double sizeX, double sizeY, boolean shade) @@ -673,7 +675,7 @@ public void fillInterfaceGlow(double x, double y, double sizeX, double sizeY, bo double drawSizeX = (sizeX * interfaceScale); double drawSizeY = (sizeY * interfaceScale); - Game.game.window.fillGlow(drawX, drawY, drawSizeX, drawSizeY, shade); + Game.game.window.shapeRenderer.fillGlow(drawX, drawY, drawSizeX, drawSizeY, shade); } public void drawInterfaceOval(double x, double y, double sizeX, double sizeY) @@ -683,7 +685,7 @@ public void drawInterfaceOval(double x, double y, double sizeX, double sizeY) double drawSizeX = (sizeX * interfaceScale); double drawSizeY = (sizeY * interfaceScale); - Game.game.window.drawOval(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.drawOval(drawX, drawY, drawSizeX, drawSizeY); } public void fillInterfaceRect(double x, double y, double sizeX, double sizeY) @@ -693,7 +695,7 @@ public void fillInterfaceRect(double x, double y, double sizeX, double sizeY) double drawSizeX = (sizeX * interfaceScale); double drawSizeY = (sizeY * interfaceScale); - Game.game.window.fillRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.fillRect(drawX, drawY, drawSizeX, drawSizeY); } public void fillShadedInterfaceRect(double x, double y, double sizeX, double sizeY) @@ -704,7 +706,7 @@ public void fillShadedInterfaceRect(double x, double y, double sizeX, double siz double drawSizeY = (sizeY * interfaceScale); Game.game.window.setBatchMode(true, true, true, false, false); - Game.game.window.fillBox(drawX, drawY, 0, drawSizeX, drawSizeY, 0, (byte) 61); + Game.game.window.shapeRenderer.fillBox(drawX, drawY, 0, drawSizeX, drawSizeY, 0, (byte) 61); Game.game.window.setBatchMode(false, true, true, false, false); } @@ -715,7 +717,7 @@ public void fillInterfaceProgressRect(double x, double y, double sizeX, double s double drawSizeX = (sizeX * interfaceScale * progress); double drawSizeY = (sizeY * interfaceScale); - Game.game.window.fillRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.fillRect(drawX, drawY, drawSizeX, drawSizeY); } public void drawInterfaceImage(String img, double x, double y, double sizeX, double sizeY) @@ -725,7 +727,7 @@ public void drawInterfaceImage(String img, double x, double y, double sizeX, dou double drawSizeX = (sizeX * interfaceScale); double drawSizeY = (sizeY * interfaceScale); - Game.game.window.drawImage(drawX, drawY, drawSizeX, drawSizeY, "/images/" + img, false); + Game.game.window.shapeRenderer.drawImage(drawX, drawY, drawSizeX, drawSizeY, "/images/" + img, false); } public void drawInterfaceRect(double x, double y, double sizeX, double sizeY) @@ -735,7 +737,7 @@ public void drawInterfaceRect(double x, double y, double sizeX, double sizeY) double drawSizeX = Math.round(sizeX * interfaceScale); double drawSizeY = Math.round(sizeY * interfaceScale); - Game.game.window.drawRect(drawX, drawY, drawSizeX, drawSizeY); + Game.game.window.shapeRenderer.drawRect(drawX, drawY, drawSizeX, drawSizeY); } public void drawText(double x, double y, String text) @@ -1293,4 +1295,14 @@ else if (Game.game.window.fontRenderer.getStringSizeX(Drawing.drawing.fontSize, return lines; } + + public ModelPart createModel() + { + return Game.game.window.createModelPart(); + } + + public Model createModel(String dir) + { + return new Model(Game.game.window, Game.game.fileManager, dir); + } } diff --git a/src/main/java/tanks/Effect.java b/src/main/java/tanks/Effect.java index ae6a4b33..febb50f6 100755 --- a/src/main/java/tanks/Effect.java +++ b/src/main/java/tanks/Effect.java @@ -122,7 +122,7 @@ else if (type.equals(EffectType.charge)) else if (type == EffectType.tread) { this.maxAge = 510; - if (Game.fancyGraphics) + if (Game.effectsEnabled) this.maxAge *= 2; } else if (type == EffectType.darkFire) @@ -321,7 +321,7 @@ else if (this.type == EffectType.obstaclePiece) } else if (this.type == EffectType.obstaclePiece3d) { - double size = 1 + (Bullet.bullet_size * (1 - this.age / this.maxAge)); + double size = 1 + (12.5 * (1 - this.age / this.maxAge)); drawing.setColor(this.colR, this.colG, this.colB); drawing.fillBox(this.posX, this.posY, this.posZ, size, size, size); @@ -340,7 +340,7 @@ else if (this.type == EffectType.tread) { double opacityFactor = 2; - if (Game.fancyGraphics) + if (Game.effectsEnabled) { opacityFactor = 4; } @@ -477,7 +477,7 @@ else if (this.type == EffectType.boostLight) Drawing.drawing.setColor(255, 255, 255, 255, 1); Game.game.window.setBatchMode(true, true, true, true, false); - double max = (this.size + 100) / 2; + double max = (this.size); for (int i = 0; i < max; i++) { double a = (max - i) / 400; diff --git a/src/main/java/tanks/Game.java b/src/main/java/tanks/Game.java index bbd2309e..862e632b 100755 --- a/src/main/java/tanks/Game.java +++ b/src/main/java/tanks/Game.java @@ -1,8 +1,7 @@ package tanks; -import basewindow.BaseFile; -import basewindow.BaseFileManager; -import basewindow.BaseWindow; +import basewindow.*; +import basewindow.Model; import tanks.bullet.*; import tanks.event.*; import tanks.event.online.*; @@ -34,7 +33,7 @@ public class Game { - public enum Framework {lwjgl, swing, libgdx} + public enum Framework {lwjgl, libgdx} public static Framework framework; public static final double tile_size = 50; @@ -86,8 +85,8 @@ public enum Framework {lwjgl, swing, libgdx} public static double[][] tilesDepth = new double[28][18]; //Remember to change the version in android's build.gradle and ios's robovm.properties - public static final String version = "Tanks v1.1.0"; - public static final int network_protocol = 30; + public static final String version = "Tanks v1.1.1"; + public static final int network_protocol = 31; public static boolean debug = false; public static boolean traceAllRays = false; public static final boolean cinematic = false; @@ -135,8 +134,16 @@ public enum Framework {lwjgl, swing, libgdx} public static String ip = ""; - public static boolean fancyGraphics = true; - public static boolean superGraphics = true; + //public static boolean fancyGraphics = true; + //public static boolean superGraphics = true; + + public static boolean fancyTerrain = true; + public static boolean effectsEnabled = true; + public static boolean bulletTrails = true; + public static boolean fancyBulletTrails = true; + public static boolean glowEnabled = true; + + public static double effectMultiplier = 1; public static boolean shadowsEnabled = false; public static int shadowQuality = 10; @@ -197,6 +204,7 @@ public enum Framework {lwjgl, swing, libgdx} public static boolean isOnlineServer; public static boolean connectedToOnline = false; + public static PosedModel triangle; private Game() { @@ -289,12 +297,14 @@ public static void registerEvents() public static void registerObstacle(Class obstacle, String name) { - new RegistryObstacle.ObstacleEntry(Game.registryObstacle, obstacle, name); + if (Game.registryObstacle.getEntry(name).obstacle == ObstacleUnknown.class) + new RegistryObstacle.ObstacleEntry(Game.registryObstacle, obstacle, name); } public static void registerTank(Class tank, String name, double weight) { - new RegistryTank.TankEntry(Game.registryTank, tank, name, weight); + if (Game.registryTank.getEntry(name).tank == TankUnknown.class) + new RegistryTank.TankEntry(Game.registryTank, tank, name, weight); } public static void registerBullet(Class bullet, String name, String icon) @@ -511,303 +521,295 @@ public void run() game.input.file = game.fileManager.getFile(Game.homedir + Game.controlsPath); game.input.load(); - - createModels(); } public static void createModels() { - if (Game.framework == Framework.swing) - { - double centerFrac = 0.8; - - Tank.base_model.shapes = new Model.Shape[1]; - Tank.base_model.shapes[0] = new Model.LegacySquare(1, 1); - - Tank.color_model.shapes = new Model.Shape[1]; - Tank.color_model.shapes[0] = new Model.LegacySquare(centerFrac, centerFrac); - - Drawing.rotatedRect.shapes = new Model.Shape[1]; - Drawing.rotatedRect.shapes[0] = new Model.LegacySquare(1, 1); - } - else - { - Tank.base_model.shapes = new Model.Shape[10]; - - double size = 0.5; - double longSize = size + 0.1; - double height = size; - double halfHeight = height / 2; - double colorEdge = 0.35; - double colorMargin = 0.05; - double colorMarginEdge = colorMargin / 2; - - Tank.base_model.shapes[0] = new Model.Quad( - new Model.Point(-size, -size, 0), - new Model.Point(size, -size, 0), - new Model.Point(size, size, 0), - new Model.Point(-size, size, 0), 0.4); - Tank.base_model.shapes[1] = new Model.Quad( - new Model.Point(-longSize, -size, halfHeight), - new Model.Point(-size, -size, 0), - new Model.Point(-size, size, 0), - new Model.Point(-longSize, size, halfHeight), 0.4); - Tank.base_model.shapes[2] = new Model.Quad( - new Model.Point(size, -size, 0), - new Model.Point(longSize, -size, halfHeight), - new Model.Point(longSize, size, halfHeight), - new Model.Point(size, size, 0), 0.4); - Tank.base_model.shapes[3] = new Model.Quad( - new Model.Point(-longSize, -size, halfHeight), - new Model.Point(-size, -size, height), - new Model.Point(-size, size, height), - new Model.Point(-longSize, size, halfHeight), 0.8); - Tank.base_model.shapes[4] = new Model.Quad( - new Model.Point(size, -size, height), - new Model.Point(longSize, -size, halfHeight), - new Model.Point(longSize, size, halfHeight), - new Model.Point(size, size, height), 0.8); - Tank.base_model.shapes[5] = new Model.Quad( - new Model.Point(-longSize, -size, halfHeight), - new Model.Point(-size, -size, height), - new Model.Point(size, -size, height), - new Model.Point(longSize, -size, halfHeight), 0.6); - Tank.base_model.shapes[6] = new Model.Quad( - new Model.Point(-longSize, -size, halfHeight), - new Model.Point(-size, -size, 0), - new Model.Point(size, -size, 0), - new Model.Point(longSize, -size, halfHeight), 0.6); - Tank.base_model.shapes[7] = new Model.Quad( - new Model.Point(-longSize, size, halfHeight), - new Model.Point(-size, size, height), - new Model.Point(size, size, height), - new Model.Point(longSize, size, halfHeight), 0.6); - Tank.base_model.shapes[8] = new Model.Quad( - new Model.Point(-longSize, size, halfHeight), - new Model.Point(-size, size, 0), - new Model.Point(size, size, 0), - new Model.Point(longSize, size, halfHeight), 0.6); - Tank.base_model.shapes[9] = new Model.Quad( - new Model.Point(-size, -size, height), - new Model.Point(size, -size, height), - new Model.Point(size, size, height), - new Model.Point(-size, size, height), 1); - - - Tank.color_model.shapes = new Model.Shape[10]; - Tank.color_model.shapes[0] = new Model.Quad( - new Model.Point(-size, -colorEdge, -colorMargin), - new Model.Point(size, -colorEdge, -colorMargin), - new Model.Point(size, colorEdge, -colorMargin), - new Model.Point(-size, colorEdge, -colorMargin), 0.4); - Tank.color_model.shapes[1] = new Model.Quad( - new Model.Point(-(longSize + colorMarginEdge), -colorEdge, halfHeight), - new Model.Point(-size, -colorEdge, -colorMargin), - new Model.Point(-size, colorEdge, -colorMargin), - new Model.Point(-(longSize + colorMarginEdge), colorEdge, halfHeight), 0.4); - Tank.color_model.shapes[2] = new Model.Quad( - new Model.Point(size, -colorEdge, -colorMargin), - new Model.Point((longSize + colorMarginEdge), -colorEdge, halfHeight), - new Model.Point((longSize + colorMarginEdge), colorEdge, halfHeight), - new Model.Point(size, colorEdge, -colorMargin), 0.4); - Tank.color_model.shapes[3] = new Model.Quad( - new Model.Point(-(longSize + colorMarginEdge), -colorEdge, halfHeight), - new Model.Point(-size, -colorEdge, height + colorMargin), - new Model.Point(-size, colorEdge, height + colorMargin), - new Model.Point(-(longSize + colorMarginEdge), colorEdge, halfHeight), 0.8); - Tank.color_model.shapes[4] = new Model.Quad( - new Model.Point(size, -colorEdge, height + colorMargin), - new Model.Point((longSize + colorMarginEdge), -colorEdge, halfHeight), - new Model.Point((longSize + colorMarginEdge), colorEdge, halfHeight), - new Model.Point(size, colorEdge, height + colorMargin), 0.8); - Tank.color_model.shapes[5] = new Model.Quad( - new Model.Point(-(longSize + colorMarginEdge), -colorEdge, halfHeight), - new Model.Point(-size, -colorEdge, height + colorMargin), - new Model.Point(size, -colorEdge, height + colorMargin), - new Model.Point((longSize + colorMarginEdge), -colorEdge, halfHeight), 0.6); - Tank.color_model.shapes[6] = new Model.Quad( - new Model.Point(-(longSize + colorMarginEdge), -colorEdge, halfHeight), - new Model.Point(-size, -colorEdge, -colorMargin), - new Model.Point(size, -colorEdge, -colorMargin), - new Model.Point((longSize + colorMarginEdge), -colorEdge, halfHeight), 0.6); - Tank.color_model.shapes[7] = new Model.Quad( - new Model.Point(-(longSize + colorMarginEdge), colorEdge, halfHeight), - new Model.Point(-size, colorEdge, height + colorMargin), - new Model.Point(size, colorEdge, height + colorMargin), - new Model.Point((longSize + colorMarginEdge), colorEdge, halfHeight), 0.6); - Tank.color_model.shapes[8] = new Model.Quad( - new Model.Point(-(longSize + colorMarginEdge), colorEdge, halfHeight), - new Model.Point(-size, colorEdge, -colorMargin), - new Model.Point(size, colorEdge, -colorMargin), - new Model.Point((longSize + colorMarginEdge), colorEdge, halfHeight), 0.6); - Tank.color_model.shapes[9] = new Model.Quad( - new Model.Point(-size, -colorEdge, height + colorMargin), - new Model.Point(size, -colorEdge, height + colorMargin), - new Model.Point(size, colorEdge, height + colorMargin), - new Model.Point(-size, colorEdge, height + colorMargin), 1); - - double turretThickness = 0.08; - double turretLength = 1.00; - Turret.turret_model.shapes = new Model.Shape[6]; - Turret.turret_model.shapes[0] = new Model.Quad( - new Model.Point(-turretThickness, -turretThickness, -turretThickness), - new Model.Point(turretLength + turretThickness, -turretThickness, -turretThickness), - new Model.Point(turretLength + turretThickness, turretThickness, -turretThickness), - new Model.Point(-turretThickness, turretThickness, -turretThickness), 0.4); - Turret.turret_model.shapes[1] = new Model.Quad( - new Model.Point(-turretThickness, -turretThickness, turretThickness), - new Model.Point(turretLength + turretThickness, -turretThickness, turretThickness), - new Model.Point(turretLength + turretThickness, -turretThickness, -turretThickness), - new Model.Point(-turretThickness, -turretThickness, -turretThickness), 0.8); - Turret.turret_model.shapes[2] = new Model.Quad( - new Model.Point(-turretThickness, -turretThickness, turretThickness), - new Model.Point(-turretThickness, -turretThickness, turretThickness), - new Model.Point(-turretThickness, turretThickness, -turretThickness), - new Model.Point(-turretThickness, turretThickness, -turretThickness), 0.6); - Turret.turret_model.shapes[3] = new Model.Quad( - new Model.Point(-turretThickness, turretThickness, turretThickness), - new Model.Point(turretLength + turretThickness, turretThickness, turretThickness), - new Model.Point(turretLength + turretThickness, turretThickness, -turretThickness), - new Model.Point(-turretThickness, turretThickness, -turretThickness), 0.8); - Turret.turret_model.shapes[4] = new Model.Quad( - new Model.Point(turretLength + turretThickness, -turretThickness, -turretThickness), - new Model.Point(turretLength + turretThickness, -turretThickness, turretThickness), - new Model.Point(turretLength + turretThickness, turretThickness, turretThickness), - new Model.Point(turretLength + turretThickness, turretThickness, -turretThickness), 0.6); - Turret.turret_model.shapes[5] = new Model.Quad( - new Model.Point(-turretThickness, -turretThickness, turretThickness), - new Model.Point(turretLength + turretThickness, -turretThickness, turretThickness), - new Model.Point(turretLength + turretThickness, turretThickness, turretThickness), - new Model.Point(-turretThickness, turretThickness, turretThickness), 1); - - double turretTopSize = 0.25; - double turretBaseSize = 0.30; - double turretDepth = 0.30; - - Turret.base_model.shapes = new Model.Shape[5]; - Turret.base_model.shapes[0] = new Model.Quad( - new Model.Point(-turretTopSize, -turretTopSize, turretDepth), - new Model.Point(turretTopSize, -turretTopSize, turretDepth), - new Model.Point(turretTopSize, turretTopSize, turretDepth), - new Model.Point(-turretTopSize, turretTopSize, turretDepth), 1); - Turret.base_model.shapes[1] = new Model.Quad( - new Model.Point(-turretTopSize, -turretTopSize, turretDepth), - new Model.Point(turretTopSize, -turretTopSize, turretDepth), - new Model.Point(turretBaseSize, -turretBaseSize, 0), - new Model.Point(-turretBaseSize, -turretBaseSize, 0), 0.8); - Turret.base_model.shapes[2] = new Model.Quad( - new Model.Point(turretTopSize, -turretTopSize, turretDepth), - new Model.Point(turretTopSize, turretTopSize, turretDepth), - new Model.Point(turretBaseSize, turretBaseSize, 0), - new Model.Point(turretBaseSize, -turretBaseSize, 0), 0.6); - Turret.base_model.shapes[3] = new Model.Quad( - new Model.Point(-turretTopSize, turretTopSize, turretDepth), - new Model.Point(turretTopSize, turretTopSize, turretDepth), - new Model.Point(turretBaseSize, turretBaseSize, 0), - new Model.Point(-turretBaseSize, turretBaseSize, 0), 0.8); - Turret.base_model.shapes[4] = new Model.Quad( - new Model.Point(-turretTopSize, -turretTopSize, turretDepth), - new Model.Point(-turretTopSize, turretTopSize, turretDepth), - new Model.Point(-turretBaseSize, turretBaseSize, 0), - new Model.Point(-turretBaseSize, -turretBaseSize, 0), 0.6); - - Drawing.rotatedRect.shapes = new Model.Shape[1]; - Drawing.rotatedRect.shapes[0] = new Model.Quad( - new Model.Point(-0.5, -0.5, 0), - new Model.Point(0.5, -0.5, 0), - new Model.Point(0.5, 0.5, 0), - new Model.Point(-0.5, 0.5, 0), 1); - - double innerHealthEdge = 0.55; - double outerHealthEdge = 0.575; - double lengthMul = 1.2; - double healthHeight = 0.025; - Tank.health_model.shapes = new Model.Shape[16]; - - Tank.health_model.shapes[0] = new Model.Quad( - new Model.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, 0), - new Model.Point(-innerHealthEdge * lengthMul, -outerHealthEdge, 0), - new Model.Point(-innerHealthEdge * lengthMul, innerHealthEdge, 0), - new Model.Point(-outerHealthEdge * lengthMul, innerHealthEdge, 0), 0.4); - Tank.health_model.shapes[1] = new Model.Quad( - new Model.Point(innerHealthEdge * lengthMul, -innerHealthEdge, 0), - new Model.Point(outerHealthEdge * lengthMul, -innerHealthEdge, 0), - new Model.Point(outerHealthEdge * lengthMul, outerHealthEdge, 0), - new Model.Point(innerHealthEdge * lengthMul, outerHealthEdge, 0), 0.4); - Tank.health_model.shapes[2] = new Model.Quad( - new Model.Point(-innerHealthEdge * lengthMul, -outerHealthEdge, 0), - new Model.Point(outerHealthEdge * lengthMul, -outerHealthEdge, 0), - new Model.Point(outerHealthEdge * lengthMul, -innerHealthEdge, 0), - new Model.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, 0), 0.4); - Tank.health_model.shapes[3] = new Model.Quad( - new Model.Point(-outerHealthEdge * lengthMul, innerHealthEdge, 0), - new Model.Point(innerHealthEdge * lengthMul, innerHealthEdge, 0), - new Model.Point(innerHealthEdge * lengthMul, outerHealthEdge, 0), - new Model.Point(-outerHealthEdge * lengthMul, outerHealthEdge, 0), 0.4); - - Tank.health_model.shapes[4] = new Model.Quad( - new Model.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, 0), - new Model.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), - new Model.Point(-outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), - new Model.Point(-outerHealthEdge * lengthMul, outerHealthEdge, 0), 0.6); - Tank.health_model.shapes[5] = new Model.Quad( - new Model.Point(outerHealthEdge * lengthMul, -outerHealthEdge, 0), - new Model.Point(outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, outerHealthEdge, 0), 0.6); - Tank.health_model.shapes[6] = new Model.Quad( - new Model.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, 0), - new Model.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, -outerHealthEdge, 0), 0.8); - Tank.health_model.shapes[7] = new Model.Quad( - new Model.Point(-outerHealthEdge * lengthMul, outerHealthEdge, 0), - new Model.Point(-outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, outerHealthEdge, 0), 0.8); - - Tank.health_model.shapes[8] = new Model.Quad( - new Model.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, 0), - new Model.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), - new Model.Point(-innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), - new Model.Point(-innerHealthEdge * lengthMul, innerHealthEdge, 0), 0.6); - Tank.health_model.shapes[9] = new Model.Quad( - new Model.Point(innerHealthEdge * lengthMul, -innerHealthEdge, 0), - new Model.Point(innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), - new Model.Point(innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), - new Model.Point(innerHealthEdge * lengthMul, innerHealthEdge, 0), 0.6); - Tank.health_model.shapes[10] = new Model.Quad( - new Model.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, 0), - new Model.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), - new Model.Point(innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), - new Model.Point(innerHealthEdge * lengthMul, -innerHealthEdge, 0), 0.8); - Tank.health_model.shapes[11] = new Model.Quad( - new Model.Point(-innerHealthEdge * lengthMul, innerHealthEdge, 0), - new Model.Point(-innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), - new Model.Point(innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), - new Model.Point(innerHealthEdge * lengthMul, innerHealthEdge, 0), 0.8); - - Tank.health_model.shapes[12] = new Model.Quad( - new Model.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), - new Model.Point(-innerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), - new Model.Point(-innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), - new Model.Point(-outerHealthEdge * lengthMul, innerHealthEdge, healthHeight), 1); - Tank.health_model.shapes[13] = new Model.Quad( - new Model.Point(innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), - new Model.Point(innerHealthEdge * lengthMul, outerHealthEdge, healthHeight), 1); - Tank.health_model.shapes[14] = new Model.Quad( - new Model.Point(-innerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), - new Model.Point(outerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), - new Model.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), 1); - Tank.health_model.shapes[15] = new Model.Quad( - new Model.Point(-outerHealthEdge * lengthMul, innerHealthEdge, healthHeight), - new Model.Point(innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), - new Model.Point(innerHealthEdge * lengthMul, outerHealthEdge, healthHeight), - new Model.Point(-outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), 1); - } + Tank.base_model = Drawing.drawing.createModel(); + Tank.color_model = Drawing.drawing.createModel(); + Tank.health_model = Drawing.drawing.createModel(); + Turret.base_model = Drawing.drawing.createModel(); + Turret.turret_model = Drawing.drawing.createModel(); + Drawing.rotatedRect = Drawing.drawing.createModel(); + + Model m2 = Drawing.drawing.createModel("/models/triangle/"); + triangle = Game.game.window.createPosedModel(m2); + + Tank.base_model.shapes = new ModelPart.Shape[10]; + + double size = 0.5; + double longSize = size + 0.1; + double height = size; + double halfHeight = height / 2; + double colorEdge = 0.35; + double colorMargin = 0.05; + double colorMarginEdge = colorMargin / 2; + + Tank.base_model.shapes[0] = new ModelPart.Quad( + new ModelPart.Point(-size, -size, 0), + new ModelPart.Point(size, -size, 0), + new ModelPart.Point(size, size, 0), + new ModelPart.Point(-size, size, 0), 0.4); + Tank.base_model.shapes[1] = new ModelPart.Quad( + new ModelPart.Point(-longSize, -size, halfHeight), + new ModelPart.Point(-size, -size, 0), + new ModelPart.Point(-size, size, 0), + new ModelPart.Point(-longSize, size, halfHeight), 0.4); + Tank.base_model.shapes[2] = new ModelPart.Quad( + new ModelPart.Point(size, -size, 0), + new ModelPart.Point(longSize, -size, halfHeight), + new ModelPart.Point(longSize, size, halfHeight), + new ModelPart.Point(size, size, 0), 0.4); + Tank.base_model.shapes[3] = new ModelPart.Quad( + new ModelPart.Point(-longSize, -size, halfHeight), + new ModelPart.Point(-size, -size, height), + new ModelPart.Point(-size, size, height), + new ModelPart.Point(-longSize, size, halfHeight), 0.8); + Tank.base_model.shapes[4] = new ModelPart.Quad( + new ModelPart.Point(size, -size, height), + new ModelPart.Point(longSize, -size, halfHeight), + new ModelPart.Point(longSize, size, halfHeight), + new ModelPart.Point(size, size, height), 0.8); + Tank.base_model.shapes[5] = new ModelPart.Quad( + new ModelPart.Point(-longSize, -size, halfHeight), + new ModelPart.Point(-size, -size, height), + new ModelPart.Point(size, -size, height), + new ModelPart.Point(longSize, -size, halfHeight), 0.6); + Tank.base_model.shapes[6] = new ModelPart.Quad( + new ModelPart.Point(-longSize, -size, halfHeight), + new ModelPart.Point(-size, -size, 0), + new ModelPart.Point(size, -size, 0), + new ModelPart.Point(longSize, -size, halfHeight), 0.6); + Tank.base_model.shapes[7] = new ModelPart.Quad( + new ModelPart.Point(-longSize, size, halfHeight), + new ModelPart.Point(-size, size, height), + new ModelPart.Point(size, size, height), + new ModelPart.Point(longSize, size, halfHeight), 0.6); + Tank.base_model.shapes[8] = new ModelPart.Quad( + new ModelPart.Point(-longSize, size, halfHeight), + new ModelPart.Point(-size, size, 0), + new ModelPart.Point(size, size, 0), + new ModelPart.Point(longSize, size, halfHeight), 0.6); + Tank.base_model.shapes[9] = new ModelPart.Quad( + new ModelPart.Point(-size, -size, height), + new ModelPart.Point(size, -size, height), + new ModelPart.Point(size, size, height), + new ModelPart.Point(-size, size, height), 1); + + + Tank.color_model.shapes = new ModelPart.Shape[10]; + Tank.color_model.shapes[0] = new ModelPart.Quad( + new ModelPart.Point(-size, -colorEdge, -colorMargin), + new ModelPart.Point(size, -colorEdge, -colorMargin), + new ModelPart.Point(size, colorEdge, -colorMargin), + new ModelPart.Point(-size, colorEdge, -colorMargin), 0.4); + Tank.color_model.shapes[1] = new ModelPart.Quad( + new ModelPart.Point(-(longSize + colorMarginEdge), -colorEdge, halfHeight), + new ModelPart.Point(-size, -colorEdge, -colorMargin), + new ModelPart.Point(-size, colorEdge, -colorMargin), + new ModelPart.Point(-(longSize + colorMarginEdge), colorEdge, halfHeight), 0.4); + Tank.color_model.shapes[2] = new ModelPart.Quad( + new ModelPart.Point(size, -colorEdge, -colorMargin), + new ModelPart.Point((longSize + colorMarginEdge), -colorEdge, halfHeight), + new ModelPart.Point((longSize + colorMarginEdge), colorEdge, halfHeight), + new ModelPart.Point(size, colorEdge, -colorMargin), 0.4); + Tank.color_model.shapes[3] = new ModelPart.Quad( + new ModelPart.Point(-(longSize + colorMarginEdge), -colorEdge, halfHeight), + new ModelPart.Point(-size, -colorEdge, height + colorMargin), + new ModelPart.Point(-size, colorEdge, height + colorMargin), + new ModelPart.Point(-(longSize + colorMarginEdge), colorEdge, halfHeight), 0.8); + Tank.color_model.shapes[4] = new ModelPart.Quad( + new ModelPart.Point(size, -colorEdge, height + colorMargin), + new ModelPart.Point((longSize + colorMarginEdge), -colorEdge, halfHeight), + new ModelPart.Point((longSize + colorMarginEdge), colorEdge, halfHeight), + new ModelPart.Point(size, colorEdge, height + colorMargin), 0.8); + Tank.color_model.shapes[5] = new ModelPart.Quad( + new ModelPart.Point(-(longSize + colorMarginEdge), -colorEdge, halfHeight), + new ModelPart.Point(-size, -colorEdge, height + colorMargin), + new ModelPart.Point(size, -colorEdge, height + colorMargin), + new ModelPart.Point((longSize + colorMarginEdge), -colorEdge, halfHeight), 0.6); + Tank.color_model.shapes[6] = new ModelPart.Quad( + new ModelPart.Point(-(longSize + colorMarginEdge), -colorEdge, halfHeight), + new ModelPart.Point(-size, -colorEdge, -colorMargin), + new ModelPart.Point(size, -colorEdge, -colorMargin), + new ModelPart.Point((longSize + colorMarginEdge), -colorEdge, halfHeight), 0.6); + Tank.color_model.shapes[7] = new ModelPart.Quad( + new ModelPart.Point(-(longSize + colorMarginEdge), colorEdge, halfHeight), + new ModelPart.Point(-size, colorEdge, height + colorMargin), + new ModelPart.Point(size, colorEdge, height + colorMargin), + new ModelPart.Point((longSize + colorMarginEdge), colorEdge, halfHeight), 0.6); + Tank.color_model.shapes[8] = new ModelPart.Quad( + new ModelPart.Point(-(longSize + colorMarginEdge), colorEdge, halfHeight), + new ModelPart.Point(-size, colorEdge, -colorMargin), + new ModelPart.Point(size, colorEdge, -colorMargin), + new ModelPart.Point((longSize + colorMarginEdge), colorEdge, halfHeight), 0.6); + Tank.color_model.shapes[9] = new ModelPart.Quad( + new ModelPart.Point(-size, -colorEdge, height + colorMargin), + new ModelPart.Point(size, -colorEdge, height + colorMargin), + new ModelPart.Point(size, colorEdge, height + colorMargin), + new ModelPart.Point(-size, colorEdge, height + colorMargin), 1); + + double turretThickness = 0.08; + double turretLength = 1.00; + Turret.turret_model.shapes = new ModelPart.Shape[6]; + Turret.turret_model.shapes[0] = new ModelPart.Quad( + new ModelPart.Point(-turretThickness, -turretThickness, -turretThickness), + new ModelPart.Point(turretLength + turretThickness, -turretThickness, -turretThickness), + new ModelPart.Point(turretLength + turretThickness, turretThickness, -turretThickness), + new ModelPart.Point(-turretThickness, turretThickness, -turretThickness), 0.4); + Turret.turret_model.shapes[1] = new ModelPart.Quad( + new ModelPart.Point(-turretThickness, -turretThickness, turretThickness), + new ModelPart.Point(turretLength + turretThickness, -turretThickness, turretThickness), + new ModelPart.Point(turretLength + turretThickness, -turretThickness, -turretThickness), + new ModelPart.Point(-turretThickness, -turretThickness, -turretThickness), 0.8); + Turret.turret_model.shapes[2] = new ModelPart.Quad( + new ModelPart.Point(-turretThickness, -turretThickness, turretThickness), + new ModelPart.Point(-turretThickness, -turretThickness, turretThickness), + new ModelPart.Point(-turretThickness, turretThickness, -turretThickness), + new ModelPart.Point(-turretThickness, turretThickness, -turretThickness), 0.6); + Turret.turret_model.shapes[3] = new ModelPart.Quad( + new ModelPart.Point(-turretThickness, turretThickness, turretThickness), + new ModelPart.Point(turretLength + turretThickness, turretThickness, turretThickness), + new ModelPart.Point(turretLength + turretThickness, turretThickness, -turretThickness), + new ModelPart.Point(-turretThickness, turretThickness, -turretThickness), 0.8); + Turret.turret_model.shapes[4] = new ModelPart.Quad( + new ModelPart.Point(turretLength + turretThickness, -turretThickness, -turretThickness), + new ModelPart.Point(turretLength + turretThickness, -turretThickness, turretThickness), + new ModelPart.Point(turretLength + turretThickness, turretThickness, turretThickness), + new ModelPart.Point(turretLength + turretThickness, turretThickness, -turretThickness), 0.6); + Turret.turret_model.shapes[5] = new ModelPart.Quad( + new ModelPart.Point(-turretThickness, -turretThickness, turretThickness), + new ModelPart.Point(turretLength + turretThickness, -turretThickness, turretThickness), + new ModelPart.Point(turretLength + turretThickness, turretThickness, turretThickness), + new ModelPart.Point(-turretThickness, turretThickness, turretThickness), 1); + + double turretTopSize = 0.25; + double turretBaseSize = 0.30; + double turretDepth = 0.30; + + Turret.base_model.shapes = new ModelPart.Shape[5]; + Turret.base_model.shapes[0] = new ModelPart.Quad( + new ModelPart.Point(-turretTopSize, -turretTopSize, turretDepth), + new ModelPart.Point(turretTopSize, -turretTopSize, turretDepth), + new ModelPart.Point(turretTopSize, turretTopSize, turretDepth), + new ModelPart.Point(-turretTopSize, turretTopSize, turretDepth), 1); + Turret.base_model.shapes[1] = new ModelPart.Quad( + new ModelPart.Point(-turretTopSize, -turretTopSize, turretDepth), + new ModelPart.Point(turretTopSize, -turretTopSize, turretDepth), + new ModelPart.Point(turretBaseSize, -turretBaseSize, 0), + new ModelPart.Point(-turretBaseSize, -turretBaseSize, 0), 0.8); + Turret.base_model.shapes[2] = new ModelPart.Quad( + new ModelPart.Point(turretTopSize, -turretTopSize, turretDepth), + new ModelPart.Point(turretTopSize, turretTopSize, turretDepth), + new ModelPart.Point(turretBaseSize, turretBaseSize, 0), + new ModelPart.Point(turretBaseSize, -turretBaseSize, 0), 0.6); + Turret.base_model.shapes[3] = new ModelPart.Quad( + new ModelPart.Point(-turretTopSize, turretTopSize, turretDepth), + new ModelPart.Point(turretTopSize, turretTopSize, turretDepth), + new ModelPart.Point(turretBaseSize, turretBaseSize, 0), + new ModelPart.Point(-turretBaseSize, turretBaseSize, 0), 0.8); + Turret.base_model.shapes[4] = new ModelPart.Quad( + new ModelPart.Point(-turretTopSize, -turretTopSize, turretDepth), + new ModelPart.Point(-turretTopSize, turretTopSize, turretDepth), + new ModelPart.Point(-turretBaseSize, turretBaseSize, 0), + new ModelPart.Point(-turretBaseSize, -turretBaseSize, 0), 0.6); + + Drawing.rotatedRect.shapes = new ModelPart.Shape[1]; + Drawing.rotatedRect.shapes[0] = new ModelPart.Quad( + new ModelPart.Point(-0.5, -0.5, 0), + new ModelPart.Point(0.5, -0.5, 0), + new ModelPart.Point(0.5, 0.5, 0), + new ModelPart.Point(-0.5, 0.5, 0), 1); + + double innerHealthEdge = 0.55; + double outerHealthEdge = 0.575; + double lengthMul = 1.2; + double healthHeight = 0.025; + Tank.health_model.shapes = new ModelPart.Shape[16]; + + Tank.health_model.shapes[0] = new ModelPart.Quad( + new ModelPart.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, 0), + new ModelPart.Point(-innerHealthEdge * lengthMul, -outerHealthEdge, 0), + new ModelPart.Point(-innerHealthEdge * lengthMul, innerHealthEdge, 0), + new ModelPart.Point(-outerHealthEdge * lengthMul, innerHealthEdge, 0), 0.4); + Tank.health_model.shapes[1] = new ModelPart.Quad( + new ModelPart.Point(innerHealthEdge * lengthMul, -innerHealthEdge, 0), + new ModelPart.Point(outerHealthEdge * lengthMul, -innerHealthEdge, 0), + new ModelPart.Point(outerHealthEdge * lengthMul, outerHealthEdge, 0), + new ModelPart.Point(innerHealthEdge * lengthMul, outerHealthEdge, 0), 0.4); + Tank.health_model.shapes[2] = new ModelPart.Quad( + new ModelPart.Point(-innerHealthEdge * lengthMul, -outerHealthEdge, 0), + new ModelPart.Point(outerHealthEdge * lengthMul, -outerHealthEdge, 0), + new ModelPart.Point(outerHealthEdge * lengthMul, -innerHealthEdge, 0), + new ModelPart.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, 0), 0.4); + Tank.health_model.shapes[3] = new ModelPart.Quad( + new ModelPart.Point(-outerHealthEdge * lengthMul, innerHealthEdge, 0), + new ModelPart.Point(innerHealthEdge * lengthMul, innerHealthEdge, 0), + new ModelPart.Point(innerHealthEdge * lengthMul, outerHealthEdge, 0), + new ModelPart.Point(-outerHealthEdge * lengthMul, outerHealthEdge, 0), 0.4); + + Tank.health_model.shapes[4] = new ModelPart.Quad( + new ModelPart.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, 0), + new ModelPart.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), + new ModelPart.Point(-outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), + new ModelPart.Point(-outerHealthEdge * lengthMul, outerHealthEdge, 0), 0.6); + Tank.health_model.shapes[5] = new ModelPart.Quad( + new ModelPart.Point(outerHealthEdge * lengthMul, -outerHealthEdge, 0), + new ModelPart.Point(outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, outerHealthEdge, 0), 0.6); + Tank.health_model.shapes[6] = new ModelPart.Quad( + new ModelPart.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, 0), + new ModelPart.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, -outerHealthEdge, 0), 0.8); + Tank.health_model.shapes[7] = new ModelPart.Quad( + new ModelPart.Point(-outerHealthEdge * lengthMul, outerHealthEdge, 0), + new ModelPart.Point(-outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, outerHealthEdge, 0), 0.8); + + Tank.health_model.shapes[8] = new ModelPart.Quad( + new ModelPart.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, 0), + new ModelPart.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), + new ModelPart.Point(-innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), + new ModelPart.Point(-innerHealthEdge * lengthMul, innerHealthEdge, 0), 0.6); + Tank.health_model.shapes[9] = new ModelPart.Quad( + new ModelPart.Point(innerHealthEdge * lengthMul, -innerHealthEdge, 0), + new ModelPart.Point(innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), + new ModelPart.Point(innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), + new ModelPart.Point(innerHealthEdge * lengthMul, innerHealthEdge, 0), 0.6); + Tank.health_model.shapes[10] = new ModelPart.Quad( + new ModelPart.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, 0), + new ModelPart.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), + new ModelPart.Point(innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), + new ModelPart.Point(innerHealthEdge * lengthMul, -innerHealthEdge, 0), 0.8); + Tank.health_model.shapes[11] = new ModelPart.Quad( + new ModelPart.Point(-innerHealthEdge * lengthMul, innerHealthEdge, 0), + new ModelPart.Point(-innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), + new ModelPart.Point(innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), + new ModelPart.Point(innerHealthEdge * lengthMul, innerHealthEdge, 0), 0.8); + + Tank.health_model.shapes[12] = new ModelPart.Quad( + new ModelPart.Point(-outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), + new ModelPart.Point(-innerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), + new ModelPart.Point(-innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), + new ModelPart.Point(-outerHealthEdge * lengthMul, innerHealthEdge, healthHeight), 1); + Tank.health_model.shapes[13] = new ModelPart.Quad( + new ModelPart.Point(innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), + new ModelPart.Point(innerHealthEdge * lengthMul, outerHealthEdge, healthHeight), 1); + Tank.health_model.shapes[14] = new ModelPart.Quad( + new ModelPart.Point(-innerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, -outerHealthEdge, healthHeight), + new ModelPart.Point(outerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), + new ModelPart.Point(-innerHealthEdge * lengthMul, -innerHealthEdge, healthHeight), 1); + Tank.health_model.shapes[15] = new ModelPart.Quad( + new ModelPart.Point(-outerHealthEdge * lengthMul, innerHealthEdge, healthHeight), + new ModelPart.Point(innerHealthEdge * lengthMul, innerHealthEdge, healthHeight), + new ModelPart.Point(innerHealthEdge * lengthMul, outerHealthEdge, healthHeight), + new ModelPart.Point(-outerHealthEdge * lengthMul, outerHealthEdge, healthHeight), 1); } public static boolean usernameInvalid(String username) @@ -1036,7 +1038,7 @@ public static double sampleGroundHeight(double px, double py) int x = (int) (px / Game.tile_size); int y = (int) (py / Game.tile_size); - if (!Game.fancyGraphics || !Game.enable3d || x < 0 || x >= Game.currentSizeX || y < 0 || y >= Game.currentSizeY) + if (!Game.fancyTerrain || !Game.enable3d || x < 0 || x >= Game.currentSizeX || y < 0 || y >= Game.currentSizeY) return 0; else return Game.tilesDepth[x][y] + 0; @@ -1047,7 +1049,7 @@ public static double sampleObstacleHeight(double px, double py) int x = (int) (px / Game.tile_size); int y = (int) (py / Game.tile_size); - if (!Game.fancyGraphics || !Game.enable3d || x < 0 || x >= Game.currentSizeX || y < 0 || y >= Game.currentSizeY) + if (!Game.fancyTerrain || !Game.enable3d || x < 0 || x >= Game.currentSizeX || y < 0 || y >= Game.currentSizeY) return 0; else return Game.game.heightGrid[x][y]; diff --git a/src/main/java/tanks/Model.java b/src/main/java/tanks/Model.java deleted file mode 100755 index d4e2fef7..00000000 --- a/src/main/java/tanks/Model.java +++ /dev/null @@ -1,249 +0,0 @@ -package tanks; - -public class Model -{ - public Shape[] shapes; - - public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw) - { - Game.game.window.setBatchMode(true, false, true); - - for (int i = 0; i < this.shapes.length; i++) - { - Game.game.window.setColor( - Drawing.drawing.currentColorR * this.shapes[i].brightness, - Drawing.drawing.currentColorG * this.shapes[i].brightness, - Drawing.drawing.currentColorB * this.shapes[i].brightness, - Drawing.drawing.currentColorA, Drawing.drawing.currentGlow); - - this.shapes[i].draw(posX, posY, posZ, sX, sY, sZ, yaw); - } - - Game.game.window.setBatchMode(false, false, true); - } - - public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll) - { - Game.game.window.setBatchMode(true, false, true); - - for (int i = 0; i < this.shapes.length; i++) - { - Game.game.window.setColor( - Drawing.drawing.currentColorR * this.shapes[i].brightness, - Drawing.drawing.currentColorG * this.shapes[i].brightness, - Drawing.drawing.currentColorB * this.shapes[i].brightness, - Drawing.drawing.currentColorA, Drawing.drawing.currentGlow); - - this.shapes[i].draw(posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); - } - - Game.game.window.setBatchMode(false, false, true); - } - - public void draw(double posX, double posY, double sX, double sY, double yaw) - { - Game.game.window.setBatchMode(true, false, false); - - for (int i = 0; i < this.shapes.length; i++) - { - Game.game.window.setColor( - Drawing.drawing.currentColorR * this.shapes[i].brightness, - Drawing.drawing.currentColorG * this.shapes[i].brightness, - Drawing.drawing.currentColorB * this.shapes[i].brightness, - Drawing.drawing.currentColorA, Drawing.drawing.currentGlow); - - this.shapes[i].draw(posX, posY, sX, sY, yaw); - } - - Game.game.window.setBatchMode(false, false, false); - } - - - public static abstract class Shape - { - public double brightness = 1; - - public abstract void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw); - public abstract void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll); - public abstract void draw(double posX, double posY, double sX, double sY, double yaw); - } - - public static class Point - { - public double x; - public double y; - public double z; - - public Point(double x, double y, double z) - { - this.x = x; - this.y = y; - this.z = z; - } - } - - public abstract static class ShapeWithPoints extends Shape - { - public Point[] points; - - public void addVertex(int index, double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw) - { - Game.game.window.addVertex( - (this.points[index].x * Math.cos(yaw) * sX - this.points[index].y * Math.sin(yaw) * sY) + posX, - (this.points[index].y * Math.cos(yaw) * sY + this.points[index].x * Math.sin(yaw) * sX) + posY, - this.points[index].z * sZ + posZ); - } - - public void addVertex(int index, double posX, double posY, double sX, double sY, double yaw) - { - Game.game.window.addVertex( - (this.points[index].x * Math.cos(yaw) * sX - this.points[index].y * Math.sin(yaw) * sY) + posX, - (this.points[index].y * Math.cos(yaw) * sY + this.points[index].x * Math.sin(yaw) * sX) + posY); - } - - public void addVertex(int index, double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll) - { - double a = Math.cos(-yaw); - double b = Math.sin(-yaw); - double c = Math.cos(-roll); - double d = Math.sin(-roll); - double e = Math.cos(-pitch); - double f = Math.sin(-pitch); - - double x1 = e * a - b * d * f; - double y1 = -a * d * f - e * b; - double z1 = -c * f; - double x2 = b * c; - double y2 = a * c; - double z2 = -d; - double x3 = a * f + e * b * d; - double y3 = e * a * d - b * f; - double z3 = e * c; - - double ox = this.points[index].x * sX; - double oy = this.points[index].y * sY; - double oz = this.points[index].z * sZ; - - Game.game.window.addVertex(posX + ox * x1 + oy * x2 + oz * x3, posY + ox * y1 + oy * y2 + oz * y3, posZ + ox * z1 + oy * z2 + oz * z3); - } - } - - public static class Triangle extends ShapeWithPoints - { - public Triangle(Point a, Point b, Point c, double brightness) - { - this.points = new Point[3]; - this.points[0] = a; - this.points[1] = b; - this.points[2] = c; - this.brightness = brightness; - } - - @Override - public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll) - { - for (int i = 0; i < this.points.length; i++) - { - this.addVertex(i, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); - } - } - - @Override - public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw) - { - for (int i = 0; i < this.points.length; i++) - { - this.addVertex(i, posX, posY, posZ, sX, sY, sZ, yaw); - } - } - - @Override - public void draw(double posX, double posY, double sX, double sY, double yaw) - { - for (int i = 0; i < this.points.length; i++) - { - this.addVertex(i, posX, posY, sX, sY, yaw); - } - } - } - - public static class Quad extends ShapeWithPoints - { - public Quad(Point a, Point b, Point c, Point d, double brightness) - { - this.points = new Point[4]; - this.points[0] = a; - this.points[1] = b; - this.points[2] = c; - this.points[3] = d; - this.brightness = brightness; - } - - @Override - public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw) - { - this.addVertex(0, posX, posY, posZ, sX, sY, sZ, yaw); - this.addVertex(1, posX, posY, posZ, sX, sY, sZ, yaw); - this.addVertex(2, posX, posY, posZ, sX, sY, sZ, yaw); - - this.addVertex(0, posX, posY, posZ, sX, sY, sZ, yaw); - this.addVertex(3, posX, posY, posZ, sX, sY, sZ, yaw); - this.addVertex(2, posX, posY, posZ, sX, sY, sZ, yaw); - } - - @Override - public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll) - { - this.addVertex(0, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); - this.addVertex(1, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); - this.addVertex(2, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); - - this.addVertex(0, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); - this.addVertex(3, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); - this.addVertex(2, posX, posY, posZ, sX, sY, sZ, yaw, pitch, roll); - } - - @Override - public void draw(double posX, double posY, double sX, double sY, double yaw) - { - this.addVertex(0, posX, posY, sX, sY, yaw); - this.addVertex(1, posX, posY, sX, sY, yaw); - this.addVertex(2, posX, posY, sX, sY, yaw); - - this.addVertex(0, posX, posY, sX, sY, yaw); - this.addVertex(3, posX, posY, sX, sY, yaw); - this.addVertex(2, posX, posY, sX, sY, yaw); - } - } - - public static class LegacySquare extends Shape - { - public double width; - public double height; - - public LegacySquare(double width, double height) - { - this.width = width; - this.height = height; - } - - @Override - public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw) - { - Game.game.window.fillRect(posX - sX * width / 2, posY - sY * height / 2, sX * width, sY * height); - } - - @Override - public void draw(double posX, double posY, double posZ, double sX, double sY, double sZ, double yaw, double pitch, double roll) - { - Game.game.window.fillRect(posX - sX * width / 2, posY - sY * height / 2, sX * width, sY * height); - } - - @Override - public void draw(double posX, double posY, double sX, double sY, double yaw) - { - Game.game.window.fillRect(posX - sX * width / 2, posY - sY * height / 2, sX * width, sY * height); - } - } - -} diff --git a/src/main/java/tanks/Panel.java b/src/main/java/tanks/Panel.java index 8568885c..b32b0f41 100755 --- a/src/main/java/tanks/Panel.java +++ b/src/main/java/tanks/Panel.java @@ -98,6 +98,7 @@ public void update() { boolean tutorial = false; + Game.createModels(); Game.game.window.setIcon("/images/icon.png"); double scale = 1; @@ -239,7 +240,7 @@ public void update() double introTime = 1000; double introAnimationTime = 500; - if (Game.fancyGraphics && Game.enable3d) + if (Game.fancyTerrain && Game.enable3d) introAnimationTime = 1000; if (System.currentTimeMillis() - startTime < introTime + introAnimationTime) @@ -425,7 +426,7 @@ else if (((ScreenGame) Game.screen).spectatingTank instanceof TankPlayerRemote) Client.handler.reply(); } - if (forceRefreshMusic || (prevScreen != null && prevScreen != Game.screen && !Game.stringsEqual(prevScreen.music, Game.screen.music) && !(Game.screen instanceof IOnlineScreen))) + if (forceRefreshMusic || (prevScreen != null && prevScreen != Game.screen && Game.screen != null && !Game.stringsEqual(prevScreen.music, Game.screen.music) && !(Game.screen instanceof IOnlineScreen))) { if (Game.stringsEqual(prevScreen.musicID, Game.screen.musicID)) this.playScreenMusic(500); @@ -452,7 +453,7 @@ public void draw() double introTime = 1000; double introAnimationTime = 500; - if (Game.fancyGraphics && Game.enable3d) + if (Game.fancyTerrain && Game.enable3d) introAnimationTime = 1000; if (Game.cinematic) @@ -462,7 +463,7 @@ public void draw() { double frac = ((this.frameStartTime - startTime - introTime) / introAnimationTime); - if (Game.enable3d && Game.fancyGraphics) + if (Game.enable3d && Game.fancyTerrain) { zoomTranslation.z = -0.08 * frac; Game.game.window.transformations.add(zoomTranslation); @@ -574,7 +575,7 @@ public void drawMouseTarget(boolean force) { if (Level.isDark()) { - if (Game.superGraphics) + if (Game.glowEnabled) { Drawing.drawing.setColor(0, 0, 0, 128); Drawing.drawing.fillInterfaceGlow(mx, my, 64, 64, true); @@ -584,7 +585,7 @@ public void drawMouseTarget(boolean force) } else { - if (Game.superGraphics) + if (Game.glowEnabled) { Drawing.drawing.setColor(255, 255, 255, 128); Drawing.drawing.fillInterfaceGlow(mx, my, 64, 64); @@ -608,7 +609,7 @@ public void drawBar(double offset) return; Drawing.drawing.setColor(87, 46, 8); - Game.game.window.fillRect(0, offset + (int) (Panel.windowHeight - 40), (int) (Panel.windowWidth), 40); + Game.game.window.shapeRenderer.fillRect(0, offset + (int) (Panel.windowHeight - 40), (int) (Panel.windowWidth), 40); Drawing.drawing.setColor(255, 227, 186); diff --git a/src/main/java/tanks/bullet/Bullet.java b/src/main/java/tanks/bullet/Bullet.java index fafc6728..e32f2a34 100755 --- a/src/main/java/tanks/bullet/Bullet.java +++ b/src/main/java/tanks/bullet/Bullet.java @@ -470,7 +470,7 @@ else if (!down && dy >= 0 && dy < bound && horizontalDist < verticalDist) double bound = this.size / 2 + t.size * t.hitboxSize / 2; - if (horizontalDist < bound && verticalDist < bound) + if (horizontalDist < bound && verticalDist < bound && t.size > 0) { this.collisionX = this.posX; this.collisionY = this.posY; @@ -600,9 +600,9 @@ public void update() this.onDestroy(); } - if (this.destroyTimer <= 0 && Game.fancyGraphics && !(this instanceof BulletFlame)) + if (this.destroyTimer <= 0 && Game.effectsEnabled && !(this instanceof BulletFlame)) { - for (int i = 0; i < this.size * 4; i++) + for (int i = 0; i < this.size * 4 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.piece); double var = 50; @@ -634,20 +634,16 @@ public void update() if (this.autoZ) this.posZ = this.iPosZ * frac + (Game.tile_size / 4) * (1 - frac); - this.ageFrac += Panel.frameFrequency; - this.halfAgeFrac += Panel.frameFrequency; - this.quarterAgeFrac += Panel.frameFrequency; + this.ageFrac += Panel.frameFrequency * Game.effectMultiplier; + this.halfAgeFrac += Panel.frameFrequency * Game.effectMultiplier; + this.quarterAgeFrac += Panel.frameFrequency * Game.effectMultiplier; - if (Game.fancyGraphics) + if (Game.bulletTrails) { while (this.ageFrac >= 1) { this.ageFrac -= 1; - if (Game.framework == Game.Framework.swing) - if (this.effect.equals(BulletEffect.trail) || this.effect.equals(BulletEffect.fire) || this.effect.equals(BulletEffect.darkFire)) - Game.effects.add(Effect.createNewEffect(this.posX - lastFinalVX * ageFrac, this.posY - lastFinalVY * ageFrac, this.posZ - lastFinalVZ, Effect.EffectType.trail, ageFrac)); - if (this.effect.equals(BulletEffect.ice) || this.effect.equals(BulletEffect.ember)) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.piece); @@ -684,7 +680,7 @@ public void update() Game.effects.add(e); } - else if (Game.superGraphics && this.effect.equals(BulletEffect.darkFire)) + else if (Game.fancyBulletTrails && this.effect.equals(BulletEffect.darkFire)) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.piece); double var = 50; @@ -702,7 +698,7 @@ else if (Game.superGraphics && this.effect.equals(BulletEffect.darkFire)) Game.effects.add(e); } - else if (Game.superGraphics && (this.effect.equals(BulletEffect.fire) || this.effect.equals(BulletEffect.fireTrail))) + else if (Game.fancyBulletTrails && (this.effect.equals(BulletEffect.fire) || this.effect.equals(BulletEffect.fireTrail))) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.piece); double var = 50; @@ -724,27 +720,11 @@ else if (Game.superGraphics && (this.effect.equals(BulletEffect.fire) || this.ef while (this.quarterAgeFrac >= 0.25) { this.quarterAgeFrac -= 0.25; - - //if (this.effect.equals(BulletEffect.fireTrail)) - // Game.effects.add(Effect.createNewEffect(this.posX - lastFinalVX * quarterAgeFrac, this.posY - lastFinalVY * quarterAgeFrac, this.posZ - lastFinalVZ, Effect.EffectType.smokeTrail, quarterAgeFrac)); - - if (Game.framework == Game.Framework.swing) - { - if (this.effect.equals(BulletEffect.fire) || this.effect.equals(BulletEffect.fireTrail)) - Game.effects.add(Effect.createNewEffect(this.posX - lastFinalVX * quarterAgeFrac, this.posY - lastFinalVY * quarterAgeFrac, this.posZ - lastFinalVZ, Effect.EffectType.fire, quarterAgeFrac)); - - if (this.effect.equals(BulletEffect.darkFire)) - Game.effects.add(Effect.createNewEffect(this.posX - lastFinalVX * quarterAgeFrac, this.posY - lastFinalVY * quarterAgeFrac, this.posZ - lastFinalVZ, Effect.EffectType.darkFire, quarterAgeFrac)); - } } while (this.halfAgeFrac >= 0.5) { this.halfAgeFrac -= 0.5; - - if (Game.framework == Game.Framework.swing) - if (this.effect.equals(BulletEffect.fireTrail)) - Game.effects.add(Effect.createNewEffect(this.posX - lastFinalVX * halfAgeFrac, this.posY - lastFinalVY * halfAgeFrac, this.posZ - lastFinalVZ, Effect.EffectType.smokeTrail, halfAgeFrac)); } } } @@ -767,7 +747,7 @@ else if (Game.superGraphics && (this.effect.equals(BulletEffect.fire) || this.ef public void addTrail() { - if (!Game.fancyGraphics) + if (!Game.bulletTrails) return; double speed = Math.sqrt(this.vX * this.vX + this.vY * this.vY); @@ -819,7 +799,7 @@ public void draw() } } - if (Game.superGraphics) + if (Game.glowEnabled) { Drawing.drawing.setColor(this.outlineColorR * glow * 2, this.outlineColorG * glow * 2, this.outlineColorB * glow * 2, 255, 1); @@ -838,12 +818,15 @@ else if (this.effect == BulletEffect.darkFire) shade = true; } - sizeMul *= 1 - destroyTimer / 60.0; + if (this.destroyTimer < 60.0) + { + sizeMul *= 1 - destroyTimer / 60.0; - if (Game.enable3d) - Drawing.drawing.fillGlow(this.posX, this.posY, this.posZ, this.size * 4 * sizeMul, this.size * 4 * sizeMul, true, true, shade); - else - Drawing.drawing.fillGlow(this.posX, this.posY, this.size * 4 * sizeMul, this.size * 4 * sizeMul, shade); + if (Game.enable3d) + Drawing.drawing.fillGlow(this.posX, this.posY, this.posZ, this.size * 4 * sizeMul, this.size * 4 * sizeMul, true, true, shade); + else + Drawing.drawing.fillGlow(this.posX, this.posY, this.size * 4 * sizeMul, this.size * 4 * sizeMul, shade); + } } for (int i = 0; i < this.trails.length; i++) diff --git a/src/main/java/tanks/bullet/BulletArc.java b/src/main/java/tanks/bullet/BulletArc.java index 03d4835e..79503ff0 100755 --- a/src/main/java/tanks/bullet/BulletArc.java +++ b/src/main/java/tanks/bullet/BulletArc.java @@ -85,7 +85,10 @@ public void update() this.vX = 0; this.vY = 0; this.vZ = 0; - this.checkCollision(); + + if (!this.tank.isRemote) + this.checkCollision(); + this.checkCollisionLocal(); this.destroy = true; Drawing.drawing.playSound("bullet_explode.ogg", (float) (Bullet.bullet_size / this.size)); @@ -114,7 +117,7 @@ public void draw() if (!Game.enable3d) this.posY -= this.posZ - Game.tile_size / 2; - if (Game.fancyGraphics) + if (Game.bulletTrails) { boolean stop = false; double length = 100; diff --git a/src/main/java/tanks/bullet/BulletBoost.java b/src/main/java/tanks/bullet/BulletBoost.java index 7e228fd6..32a68f08 100755 --- a/src/main/java/tanks/bullet/BulletBoost.java +++ b/src/main/java/tanks/bullet/BulletBoost.java @@ -68,9 +68,10 @@ public void collidedWithTank(Tank t) @Override public void draw() { - if (Game.superGraphics) + if (Game.glowEnabled) { - Drawing.drawing.setColor(255, 180, 0, 180, 1); + double frac = Math.min(1, this.destroyTimer / 60); + Drawing.drawing.setColor(255, 180, 0, 180 * frac, 1); if (Game.enable3d) Drawing.drawing.fillGlow(this.posX, this.posY, this.posZ, this.size * 8, this.size * 8); @@ -86,9 +87,9 @@ public void onDestroy() { Drawing.drawing.playSound("boost.ogg", (float) (10.0 / this.size)); - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int i = 0; i < 50; i++) + for (int i = 0; i < 25 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, Game.tile_size / 2, Effect.EffectType.piece); double var = 50; diff --git a/src/main/java/tanks/bullet/BulletElectric.java b/src/main/java/tanks/bullet/BulletElectric.java index d4a9f77a..06390f75 100755 --- a/src/main/java/tanks/bullet/BulletElectric.java +++ b/src/main/java/tanks/bullet/BulletElectric.java @@ -215,11 +215,11 @@ public void collided(Movable movable) if (movable instanceof Tank && !this.tank.isRemote) { - Game.eventsOut.add(new EventBulletElectricStunEffect(this.posX, this.posY, this.posZ)); + Game.eventsOut.add(new EventBulletElectricStunEffect(this.posX, this.posY, this.posZ, 1)); - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int i = 0; i < 25; i++) + for (int i = 0; i < 25 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.stun); double var = 50; @@ -238,9 +238,9 @@ public void collided(Movable movable) @Override public void addDestroyEffect() { - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int i = 0; i < this.size * 4; i++) + for (int i = 0; i < this.size * 4 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.piece); double var = 50; diff --git a/src/main/java/tanks/bullet/BulletExplosive.java b/src/main/java/tanks/bullet/BulletExplosive.java old mode 100644 new mode 100755 diff --git a/src/main/java/tanks/bullet/BulletFreeze.java b/src/main/java/tanks/bullet/BulletFreeze.java index b89ca48d..5eb518fa 100755 --- a/src/main/java/tanks/bullet/BulletFreeze.java +++ b/src/main/java/tanks/bullet/BulletFreeze.java @@ -43,7 +43,7 @@ public void onDestroy() @Override public void draw() { - if (Game.fancyGraphics) + if (Game.bulletTrails) { for (int i = 0; i < 30 - 10 * Math.sin(this.age / 12.0); i++) { diff --git a/src/main/java/tanks/bullet/BulletHealing.java b/src/main/java/tanks/bullet/BulletHealing.java index 5823117d..d2ae2bb9 100755 --- a/src/main/java/tanks/bullet/BulletHealing.java +++ b/src/main/java/tanks/bullet/BulletHealing.java @@ -102,9 +102,9 @@ public void collidedWithObject(Movable o) @Override public void addDestroyEffect() { - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int i = 0; i < this.size / 4; i++) + for (int i = 0; i < this.size / 4 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.piece); double var = 50; diff --git a/src/main/java/tanks/bullet/BulletLaser.java b/src/main/java/tanks/bullet/BulletLaser.java index b173fe3a..dba6af01 100755 --- a/src/main/java/tanks/bullet/BulletLaser.java +++ b/src/main/java/tanks/bullet/BulletLaser.java @@ -54,9 +54,9 @@ public void collidedWithObject(Movable m) @Override public void addDestroyEffect() { - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int i = 0; i < this.size * 4; i++) + for (int i = 0; i < this.size * 4 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.piece); double var = 50; diff --git a/src/main/java/tanks/bullet/Laser.java b/src/main/java/tanks/bullet/Laser.java index 11077022..4ae14a7b 100755 --- a/src/main/java/tanks/bullet/Laser.java +++ b/src/main/java/tanks/bullet/Laser.java @@ -58,59 +58,46 @@ public void draw() { Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 255, 1); - if (Game.framework == Game.Framework.swing) + if (frontCircle || showOutsides) { - double dist = Math.sqrt(Math.pow(this.frontX - this.backX, 2) + Math.pow(this.frontY - this.backY, 2)); + Game.game.window.setBatchMode(true, false, depth); - for (int i = 0; i < dist; i++) + for (int i = 10; i < 30; i++) { - double f = i / dist; - Drawing.drawing.fillOval(this.frontX * f + this.backX * (1 - f), this.frontY * f + this.backY * (1 - f), (1 - frac) * 2 * width, (1 - frac) * 2 * width); + Drawing.drawing.addFacingVertex(this.frontX, this.frontY, this.frontZ, Math.cos(i / 20.0 * Math.PI + angle) * width * (1 - frac), Math.sin(i / 20.0 * Math.PI + angle) * width * (1 - frac), 0); + Drawing.drawing.addFacingVertex(this.frontX, this.frontY, this.frontZ, Math.cos((i + 1) / 20.0 * Math.PI + angle) * width * (1 - frac), Math.sin((i + 1) / 20.0 * Math.PI + angle) * width * (1 - frac), 0); + Drawing.drawing.addVertex(this.frontX, this.frontY, this.frontZ); } - } - else - { - if (frontCircle || showOutsides) - { - Game.game.window.setBatchMode(true, false, depth); - for (int i = 10; i < 30; i++) - { - Drawing.drawing.addFacingVertex(this.frontX, this.frontY, this.frontZ, Math.cos(i / 20.0 * Math.PI + angle) * width * (1 - frac), Math.sin(i / 20.0 * Math.PI + angle) * width * (1 - frac), 0); - Drawing.drawing.addFacingVertex(this.frontX, this.frontY, this.frontZ, Math.cos((i + 1) / 20.0 * Math.PI + angle) * width * (1 - frac), Math.sin((i + 1) / 20.0 * Math.PI + angle) * width * (1 - frac), 0); - Drawing.drawing.addVertex(this.frontX, this.frontY, this.frontZ); - } + Game.game.window.setBatchMode(false, false, depth); + } - Game.game.window.setBatchMode(false, false, depth); - } + Game.game.window.setBatchMode(true, true, depth); - Game.game.window.setBatchMode(true, true, depth); + Drawing.drawing.addFacingVertex(this.frontX, this.frontY, this.frontZ, ox * width * (1 - frac), oy * width * (1 - frac), 0); + Drawing.drawing.addFacingVertex(this.frontX, this.frontY, this.frontZ, -ox * width * (1 - frac), -oy * width * (1 - frac), 0); - Drawing.drawing.addFacingVertex(this.frontX, this.frontY, this.frontZ, ox * width * (1 - frac), oy * width * (1 - frac), 0); - Drawing.drawing.addFacingVertex(this.frontX, this.frontY, this.frontZ, -ox * width * (1 - frac), -oy * width * (1 - frac), 0); + Drawing.drawing.addFacingVertex(this.backX, this.backY, this.backZ, -ox * width * (1 - frac), -oy * width * (1 - frac), 0); + Drawing.drawing.addFacingVertex(this.backX, this.backY, this.backZ, ox * width * (1 - frac), oy * width * (1 - frac), 0); - Drawing.drawing.addFacingVertex(this.backX, this.backY, this.backZ, -ox * width * (1 - frac), -oy * width * (1 - frac), 0); - Drawing.drawing.addFacingVertex(this.backX, this.backY, this.backZ, ox * width * (1 - frac), oy * width * (1 - frac), 0); + Game.game.window.setBatchMode(false, true, depth); - Game.game.window.setBatchMode(false, true, depth); + if (backCircle || showOutsides) + { + Game.game.window.setBatchMode(true, false, depth); - if (backCircle || showOutsides) + for (int i = 30; i < 50; i++) { - Game.game.window.setBatchMode(true, false, depth); - - for (int i = 30; i < 50; i++) - { - Drawing.drawing.addFacingVertex(this.backX, this.backY, this.backZ, Math.cos(i / 20.0 * Math.PI + angle) * width * (1 - frac), Math.sin(i / 20.0 * Math.PI + angle) * width * (1 - frac), 0); - Drawing.drawing.addFacingVertex(this.backX, this.backY, this.backZ, Math.cos((i + 1) / 20.0 * Math.PI + angle) * width * (1 - frac), Math.sin((i + 1) / 20.0 * Math.PI + angle) * width * (1 - frac), 0); - Drawing.drawing.addVertex(this.backX, this.backY, this.backZ); - } - - Game.game.window.setBatchMode(false, false, depth); + Drawing.drawing.addFacingVertex(this.backX, this.backY, this.backZ, Math.cos(i / 20.0 * Math.PI + angle) * width * (1 - frac), Math.sin(i / 20.0 * Math.PI + angle) * width * (1 - frac), 0); + Drawing.drawing.addFacingVertex(this.backX, this.backY, this.backZ, Math.cos((i + 1) / 20.0 * Math.PI + angle) * width * (1 - frac), Math.sin((i + 1) / 20.0 * Math.PI + angle) * width * (1 - frac), 0); + Drawing.drawing.addVertex(this.backX, this.backY, this.backZ); } + + Game.game.window.setBatchMode(false, false, depth); } } - if (Game.superGraphics) + if (Game.glowEnabled) drawGlow(); } diff --git a/src/main/java/tanks/event/EventBulletElectricStunEffect.java b/src/main/java/tanks/event/EventBulletElectricStunEffect.java index b9676a25..31f7c367 100755 --- a/src/main/java/tanks/event/EventBulletElectricStunEffect.java +++ b/src/main/java/tanks/event/EventBulletElectricStunEffect.java @@ -9,25 +9,27 @@ public class EventBulletElectricStunEffect extends PersonalEvent public double posX; public double posY; public double posZ; + public double length; public EventBulletElectricStunEffect() { } - public EventBulletElectricStunEffect(double x, double y, double z) + public EventBulletElectricStunEffect(double x, double y, double z, double length) { this.posX = x; this.posY = y; this.posZ = z; + this.length = length; } @Override public void execute() { - if (Game.fancyGraphics && this.clientID == null) + if (Game.effectsEnabled && this.clientID == null) { - for (int i = 0; i < 25; i++) + for (int i = 0; i < 25 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.stun); double var = 50; @@ -37,6 +39,7 @@ public void execute() e.glowR = 0; e.glowG = 128; e.glowB = 128; + e.maxAge *= length; Game.effects.add(e); } } @@ -48,6 +51,7 @@ public void write(ByteBuf b) b.writeDouble(this.posX); b.writeDouble(this.posY); b.writeDouble(this.posZ); + b.writeDouble(this.length); } @Override @@ -56,5 +60,6 @@ public void read(ByteBuf b) this.posX = b.readDouble(); this.posY = b.readDouble(); this.posZ = b.readDouble(); + this.length = b.readDouble(); } } diff --git a/src/main/java/tanks/event/EventObstacleHit.java b/src/main/java/tanks/event/EventObstacleHit.java old mode 100644 new mode 100755 diff --git a/src/main/java/tanks/event/EventTankControllerUpdateS.java b/src/main/java/tanks/event/EventTankControllerUpdateS.java index 72d94afc..81a3355c 100755 --- a/src/main/java/tanks/event/EventTankControllerUpdateS.java +++ b/src/main/java/tanks/event/EventTankControllerUpdateS.java @@ -49,9 +49,6 @@ public void execute() { if (t instanceof TankPlayerController && Game.clientID.equals(((TankPlayerController) t).clientID)) { - Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.laser)); - Game.effects.add(Effect.createNewEffect(t.posX, t.posY, Effect.EffectType.healing)); - TankPlayerController p = (TankPlayerController) t; p.interpolatedOffX = this.posX - (t.posX - p.interpolatedOffX * (TankPlayerController.interpolationTime - p.interpolatedProgress) / TankPlayerController.interpolationTime); p.interpolatedOffY = this.posY - (t.posY - p.interpolatedOffY * (TankPlayerController.interpolationTime - p.interpolatedProgress) / TankPlayerController.interpolationTime); diff --git a/src/main/java/tanks/event/EventTankRedUpdateCharge.java b/src/main/java/tanks/event/EventTankRedUpdateCharge.java index 9dc27ceb..63a6dbfd 100755 --- a/src/main/java/tanks/event/EventTankRedUpdateCharge.java +++ b/src/main/java/tanks/event/EventTankRedUpdateCharge.java @@ -36,7 +36,7 @@ public void execute() t.colorG = charge * 100; t.colorB = charge * 100; - if (Math.random() < charge && Game.fancyGraphics) + if (Math.random() * Game.effectMultiplier < charge && Game.effectsEnabled) { Effect e = Effect.createNewEffect(t.posX, t.posY, t.size / 4, Effect.EffectType.charge); diff --git a/src/main/java/tanks/event/EventTankUpdateColor.java b/src/main/java/tanks/event/EventTankUpdateColor.java old mode 100644 new mode 100755 diff --git a/src/main/java/tanks/extension/Extension.java b/src/main/java/tanks/extension/Extension.java old mode 100644 new mode 100755 diff --git a/src/main/java/tanks/extension/ExtensionRegistry.java b/src/main/java/tanks/extension/ExtensionRegistry.java index 58981aed..60c142a5 100755 --- a/src/main/java/tanks/extension/ExtensionRegistry.java +++ b/src/main/java/tanks/extension/ExtensionRegistry.java @@ -67,7 +67,7 @@ public void loadRegistry() for (String file : files) { - loadExtension(file.substring(file.lastIndexOf("/") + 1), null); + loadExtension(file.substring(file.replace("\\", "/").lastIndexOf("/") + 1), null); } } } diff --git a/src/main/java/tanks/gui/Button.java b/src/main/java/tanks/gui/Button.java index 6d0ff4d5..f62251ec 100755 --- a/src/main/java/tanks/gui/Button.java +++ b/src/main/java/tanks/gui/Button.java @@ -8,6 +8,7 @@ import tanks.gui.screen.ScreenPartyHost; import tanks.gui.screen.ScreenPartyLobby; +import java.net.URL; import java.util.ArrayList; public class Button implements IDrawable, ITrigger @@ -145,7 +146,7 @@ public void draw() //drawing.fillInterfaceRect(posX, posY, sizeX, sizeY); - if (Game.superGraphics) + if (Game.glowEnabled) { if (!enabled) drawGlow(this.posX, this.posY + 3.5, this.sizeX, this.sizeY, 0.55, 0, 0, 0, 160, false); @@ -193,7 +194,7 @@ else if (selected && !Game.game.window.touchscreen) if (enableHover) { - if (Game.superGraphics && !fullInfo) + if (Game.glowEnabled && !fullInfo) { if (infoSelected && !Game.game.window.touchscreen) { @@ -267,7 +268,7 @@ public void update() } } - if (Game.superGraphics && !Game.game.window.drawingShadow) + if (Game.glowEnabled && !Game.game.window.drawingShadow) { if (this.lastFrame < Panel.panel.ageFrames - 1) this.glowEffects.clear(); @@ -288,7 +289,7 @@ public void update() if (this.selected && this.enabled && !Game.game.window.touchscreen) { - this.effectTimer += 0.25 * (this.sizeX + this.sizeY) / 400 * Math.random(); + this.effectTimer += 0.25 * (this.sizeX + this.sizeY) / 400 * Math.random() * Game.effectMultiplier; while (this.effectTimer >= 0.4 / Panel.frameFrequency) { diff --git a/src/main/java/tanks/gui/ChatBox.java b/src/main/java/tanks/gui/ChatBox.java index a594e844..addc6be8 100755 --- a/src/main/java/tanks/gui/ChatBox.java +++ b/src/main/java/tanks/gui/ChatBox.java @@ -276,12 +276,6 @@ else if (Game.game.window.touchscreen) public void drawBox() { - if (Game.framework == Game.Framework.swing) - { - Drawing.drawing.fillInterfaceRect(this.posX, this.posY, this.sizeX, this.sizeY); - return; - } - double xPad = -40; Drawing.drawing.fillInterfaceRect(this.posX, this.posY, this.sizeX + xPad, this.sizeY); diff --git a/src/main/java/tanks/gui/ImageSelector.java b/src/main/java/tanks/gui/ImageSelector.java index 8e50d746..fd50cdca 100755 --- a/src/main/java/tanks/gui/ImageSelector.java +++ b/src/main/java/tanks/gui/ImageSelector.java @@ -41,7 +41,7 @@ public void draw() drawing.setInterfaceFontSize(this.sizeY * 0.6); - if (Game.superGraphics) + if (Game.glowEnabled) TextBox.drawTallGlow(this.posX, this.posY + 5, this.sizeX, this.sizeY, sizeY * 3 / 4, 0.6, 0, 0, 0, 100, false); drawing.setColor(this.bgColorR, this.bgColorG, this.bgColorB); @@ -57,7 +57,7 @@ public void draw() double m = 0.8; - if (Game.superGraphics) + if (Game.glowEnabled) { if (selected && !Game.game.window.touchscreen) TextBox.drawTallGlow(this.posX - sizeX / 2 + sizeY * 7 / 8, this.posY + 5, this.sizeY * (3.0 / 4 + m), this.sizeY * m, sizeY * 3 / 4, 0.65, 0, 0, 0, 80, false); @@ -96,7 +96,7 @@ public void draw() if (enableHover) { - if (Game.superGraphics) + if (Game.glowEnabled) { if (infoSelected && !Game.game.window.touchscreen) { diff --git a/src/main/java/tanks/gui/InputSelector.java b/src/main/java/tanks/gui/InputSelector.java index 9dcc8315..0081f618 100755 --- a/src/main/java/tanks/gui/InputSelector.java +++ b/src/main/java/tanks/gui/InputSelector.java @@ -77,7 +77,7 @@ public void draw() drawing.setInterfaceFontSize(this.sizeY * 0.6); - if (Game.superGraphics) + if (Game.glowEnabled) TextBox.drawTallGlow(this.posX, this.posY + 5, this.sizeX, this.sizeY, sizeY * 3 / 4, 0.6, 0, 0, 0, 100, false); drawing.setColor(this.bgColorR, this.bgColorG, this.bgColorB); @@ -93,7 +93,7 @@ public void draw() double m = 0.8; - if (Game.superGraphics) + if (Game.glowEnabled) { if (selected && !right && !Game.game.window.touchscreen) Button.drawGlow(q1, this.posY + 5, this.sizeX / 2 - this.sizeY * (1 - m), this.sizeY * m, 0.65, 0, 0, 0, 80, false); @@ -153,7 +153,7 @@ public void draw() if (enableHover) { - if (Game.superGraphics) + if (Game.glowEnabled) { if (infoSelected && !Game.game.window.touchscreen) { @@ -223,7 +223,7 @@ public void update() } } - if (Game.superGraphics && !Game.game.window.drawingShadow) + if (Game.glowEnabled && !Game.game.window.drawingShadow) { if (this.lastFrame < Panel.panel.ageFrames - 1) this.glowEffects.clear(); @@ -244,7 +244,7 @@ public void update() if (this.selected && !Game.game.window.touchscreen) { - this.effectTimer += 0.25 * (this.sizeX + this.sizeY) / 400 * Math.random(); + this.effectTimer += 0.25 * (this.sizeX + this.sizeY) / 400 * Math.random() * Game.effectMultiplier; while (this.effectTimer >= 0.4 / Panel.frameFrequency) { diff --git a/src/main/java/tanks/gui/Selector.java b/src/main/java/tanks/gui/Selector.java index 6c202cbb..0cfeb328 100755 --- a/src/main/java/tanks/gui/Selector.java +++ b/src/main/java/tanks/gui/Selector.java @@ -119,7 +119,7 @@ public void draw() drawing.setInterfaceFontSize(this.sizeY * 0.6); - if (Game.superGraphics) + if (Game.glowEnabled) TextBox.drawTallGlow(this.posX, this.posY + 5, this.sizeX, this.sizeY, sizeY * 3 / 4, 0.6, 0, 0, 0, 100, false); drawing.setColor(this.bgColorR, this.bgColorG, this.bgColorB); @@ -135,7 +135,7 @@ public void draw() double m = 0.8; - if (Game.superGraphics) + if (Game.glowEnabled) { if (selected && !Game.game.window.touchscreen) Button.drawGlow(this.posX, this.posY + 5, this.sizeX - this.sizeY * (1 - m), this.sizeY * m, 0.65, 0, 0, 0, 80, false); @@ -172,7 +172,7 @@ public void draw() if (enableHover) { - if (Game.superGraphics) + if (Game.glowEnabled) { if (infoSelected && !Game.game.window.touchscreen) { @@ -241,7 +241,7 @@ public void update() } } - if (Game.superGraphics) + if (Game.glowEnabled) { if (this.lastFrame < Panel.panel.ageFrames - 1) this.glowEffects.clear(); @@ -262,7 +262,7 @@ public void update() if (this.selected && this.enabled && !Game.game.window.touchscreen) { - this.effectTimer += 0.25 * (this.sizeX + this.sizeY) / 400 * Math.random(); + this.effectTimer += 0.25 * (this.sizeX + this.sizeY) / 400 * Math.random() * Game.effectMultiplier; while (this.effectTimer >= 0.4 / Panel.frameFrequency) { diff --git a/src/main/java/tanks/gui/SpeedrunTimer.java b/src/main/java/tanks/gui/SpeedrunTimer.java index ca0e29db..20364a6f 100755 --- a/src/main/java/tanks/gui/SpeedrunTimer.java +++ b/src/main/java/tanks/gui/SpeedrunTimer.java @@ -13,7 +13,7 @@ public static void draw() if (!(Game.screen instanceof ScreenGame) || ScreenGame.finishedQuick) alpha += 64 + 64 * Math.sin(System.currentTimeMillis() / 1000.0 * Math.PI * 4); - if (Level.isDark() || (Game.screen instanceof IDarkScreen && Panel.win && Game.fancyGraphics)) + if (Level.isDark() || (Game.screen instanceof IDarkScreen && Panel.win && Game.effectsEnabled)) Drawing.drawing.setColor(255, 255, 255, alpha); else Drawing.drawing.setColor(0, 0, 0, alpha); diff --git a/src/main/java/tanks/gui/TextBox.java b/src/main/java/tanks/gui/TextBox.java index b4c55897..558e47e5 100755 --- a/src/main/java/tanks/gui/TextBox.java +++ b/src/main/java/tanks/gui/TextBox.java @@ -114,7 +114,7 @@ public void draw() drawing.setInterfaceFontSize(this.sizeY * 0.6); - if (Game.superGraphics) + if (Game.glowEnabled) drawTallGlow(this.posX, this.posY + 5, this.sizeX, this.sizeY, sizeY * 3 / 4, 0.6, 0, 0, 0, 100, false); drawing.setColor(this.bgColorR, this.bgColorG, this.bgColorB); @@ -130,7 +130,7 @@ public void draw() double m = 0.8; - if (Game.superGraphics) + if (Game.glowEnabled) { if (selected) Button.drawGlow(this.posX, this.posY + 3.5, this.sizeX - this.sizeY * (1 - m), this.sizeY * m, 0.55, 0, 0, 0, 160, false); @@ -173,7 +173,7 @@ else if (hover && !Game.game.window.touchscreen) if (enableHover) { - if (Game.superGraphics && !Game.game.window.drawingShadow) + if (Game.glowEnabled && !Game.game.window.drawingShadow) { if (infoSelected && !Game.game.window.touchscreen) { @@ -210,7 +210,7 @@ else if (hover && !Game.game.window.touchscreen) if (selected && inputText.length() > 0) { - if (Game.superGraphics) + if (Game.glowEnabled) { if (clearSelected && !Game.game.window.touchscreen) { @@ -297,7 +297,7 @@ public void update() this.checkKeys(); } - if (Game.superGraphics && !Game.game.window.drawingShadow) + if (Game.glowEnabled && !Game.game.window.drawingShadow) { if (this.lastFrame < Panel.panel.ageFrames - 1) this.glowEffects.clear(); @@ -318,7 +318,7 @@ public void update() if (this.shouldAddEffect()) { - this.effectTimer += 0.25 * (this.sizeX + this.sizeY) / 400 * Math.random(); + this.effectTimer += 0.25 * (this.sizeX + this.sizeY) / 400 * Math.random() * Game.effectMultiplier; while (this.effectTimer >= 0.4 / Panel.frameFrequency) { @@ -457,9 +457,9 @@ public void submit() Game.game.window.showKeyboard = false; Panel.selectedTextBox = null; - if (Game.superGraphics) + if (Game.glowEnabled) { - for (int i = 0; i < 0.2 * (this.sizeX + this.sizeY); i++) + for (int i = 0; i < 0.2 * (this.sizeX + this.sizeY) * Game.effectMultiplier; i++) Button.addEffect(this.posX, this.posY, this.sizeX - this.sizeY * (1 - 0.8), this.sizeY * 0.8, this.glowEffects, Math.random() * 4, 0.8, 0.25); } } diff --git a/src/main/java/tanks/gui/TextBoxSlider.java b/src/main/java/tanks/gui/TextBoxSlider.java index b9a8061f..c4feb31e 100755 --- a/src/main/java/tanks/gui/TextBoxSlider.java +++ b/src/main/java/tanks/gui/TextBoxSlider.java @@ -53,7 +53,7 @@ public void draw() drawing.setInterfaceFontSize(this.sizeY * 0.6); - if (Game.superGraphics) + if (Game.glowEnabled) drawTallGlow(this.posX, this.posY + 5, this.sizeX, this.sizeY, sizeY * 3 / 4, 0.6, 0, 0, 0, 100, false); drawing.setColor(this.bgColorR, this.bgColorG, this.bgColorB); @@ -81,7 +81,7 @@ public void draw() double frac = Math.max(Math.min((this.value - this.min) / (this.max - this.min), 1), 0); double x = start1 * (1 - frac) + end1 * frac; - if (Game.superGraphics) + if (Game.glowEnabled) { if (selected) Button.drawGlow(mid2, this.posY + 3.5, end2 - start2 - this.sizeY * (- m), this.sizeY * m, 0.55, 0, 0, 0, 160, false); @@ -122,7 +122,7 @@ else if (sliderHover) Drawing.drawing.addInterfaceVertex(end1, posY - sizeY * m / 2, 0); Game.game.window.setBatchMode(false, true, false, false); - if (Game.superGraphics) + if (Game.glowEnabled) Button.drawGlow(x, this.posY + 2.5, this.sizeY * m, this.sizeY * m, 0.6, 0, 0, 0, 100, false); if (selected) @@ -146,7 +146,7 @@ else if (hover && !Game.game.window.touchscreen) drawing.fillInterfaceOval(x, this.posY, this.sizeY * m * m, this.sizeY * m * m); //drawing.setColor(this.colorR, this.colorG, this.colorB); - if (Game.superGraphics) + if (Game.glowEnabled) Button.drawGlow(x, this.posY + 1.5, this.sizeY * m * m, this.sizeY * m * m, 0.6, 0, 0, 0, 100, false); drawing.setColor(this.r1 * (1 - frac) + this.r2 * frac, this.g1 * (1 - frac) + this.g2 * frac, this.b1 * (1 - frac) + this.b2 * frac); diff --git a/src/main/java/tanks/gui/screen/Screen.java b/src/main/java/tanks/gui/screen/Screen.java index 936edbbc..750469ba 100755 --- a/src/main/java/tanks/gui/screen/Screen.java +++ b/src/main/java/tanks/gui/screen/Screen.java @@ -1,5 +1,6 @@ package tanks.gui.screen; +import lwjglwindow.ImmediateModeShapeRenderer; import tanks.*; import tanks.obstacle.Obstacle; @@ -93,11 +94,11 @@ public void drawDefaultBackground(double size) Drawing.drawing.fillBackgroundRect(Drawing.drawing.sizeX / 2, Drawing.drawing.sizeY / 2, Drawing.drawing.sizeX, Drawing.drawing.sizeY); } - if (Game.fancyGraphics) + if (Game.fancyTerrain) { Drawing.drawing.setColor(Level.currentColorR, Level.currentColorG, Level.currentColorB); - if (Game.framework != Game.Framework.libgdx) + if (Game.game.window.shapeRenderer.supportsBatching) Game.game.window.setBatchMode(true, true, true); if (Game.currentSizeX != Game.tilesR.length || Game.currentSizeY != Game.tilesR[0].length) @@ -202,14 +203,8 @@ public void drawDefaultBackground(double size) } } - if (Game.framework != Game.Framework.libgdx) + if (Game.game.window.shapeRenderer.supportsBatching) Game.game.window.setBatchMode(false, true, true); - - if (this.drawDarkness) - { - Drawing.drawing.setColor(0, 0, 0, Math.max(0, Panel.darkness)); - Game.game.window.fillRect(0, 0, Game.game.window.absoluteWidth, Game.game.window.absoluteHeight - Drawing.drawing.statsHeight); - } } else if (Game.enable3d && !(Game.screen instanceof ScreenExit)) { @@ -222,7 +217,9 @@ else if (Game.enable3d && !(Game.screen instanceof ScreenExit)) if (Game.tileDrawables[i][j] != null) { Game.tileDrawables[i][j].drawTile(Level.currentColorR, Level.currentColorG, Level.currentColorB, 0); - Game.tileDrawables[i][j] = null; + + if (!Game.game.window.drawingShadow) + Game.tileDrawables[i][j] = null; } else { @@ -235,6 +232,12 @@ else if (Game.enable3d && !(Game.screen instanceof ScreenExit)) } } } + + if (this.drawDarkness) + { + Drawing.drawing.setColor(0, 0, 0, Math.max(0, Panel.darkness)); + Game.game.window.shapeRenderer.fillRect(0, 0, Game.game.window.absoluteWidth, Game.game.window.absoluteHeight - Drawing.drawing.statsHeight); + } } public double getOffsetX() diff --git a/src/main/java/tanks/gui/screen/ScreenChangelog.java b/src/main/java/tanks/gui/screen/ScreenChangelog.java index 0bf39cc0..54866f07 100755 --- a/src/main/java/tanks/gui/screen/ScreenChangelog.java +++ b/src/main/java/tanks/gui/screen/ScreenChangelog.java @@ -229,7 +229,15 @@ public static void setupLogs() "Bullets harmless to you (friendly fire off) now flash\n" + "Added a new extension API\n" + "...and the usual bug fixes and various minor improvements" + }); + new Changelog("v1.1.1", new String[] + { + "*What's new in Tanks v1.1.1:\n\n" + + "Split fast/fancy/super graphics setting into multiple options\n" + + "Reduced certain particle effects to improve performance\n" + + "New option to change intensity of particle effects\n" + + "Several bug fixes and minor improvements" }); } } diff --git a/src/main/java/tanks/gui/screen/ScreenCrashed.java b/src/main/java/tanks/gui/screen/ScreenCrashed.java index d2c55036..24fe968d 100755 --- a/src/main/java/tanks/gui/screen/ScreenCrashed.java +++ b/src/main/java/tanks/gui/screen/ScreenCrashed.java @@ -48,7 +48,7 @@ public void draw() { Drawing drawing = Drawing.drawing; drawing.setColor(0, 0, 255); - Game.game.window.fillRect(0, 0, Game.game.window.absoluteWidth, Game.game.window.absoluteHeight - Drawing.drawing.statsHeight); + Game.game.window.shapeRenderer.fillRect(0, 0, Game.game.window.absoluteWidth, Game.game.window.absoluteHeight - Drawing.drawing.statsHeight); drawing.setColor(255, 255, 255); drawing.setInterfaceFontSize(100); diff --git a/src/main/java/tanks/gui/screen/ScreenCrusadeEditLevel.java b/src/main/java/tanks/gui/screen/ScreenCrusadeEditLevel.java index 10253c6e..fb526b18 100755 --- a/src/main/java/tanks/gui/screen/ScreenCrusadeEditLevel.java +++ b/src/main/java/tanks/gui/screen/ScreenCrusadeEditLevel.java @@ -188,6 +188,15 @@ public void drawLevel() ((Movable) d).drawTeam(); } + if (Game.glowEnabled) + { + for (IDrawable d : this.drawables[i]) + { + if (d instanceof IDrawableWithGlow && ((IDrawableWithGlow) d).isGlowEnabled()) + ((IDrawableWithGlow) d).drawGlow(); + } + } + drawables[i].clear(); } } diff --git a/src/main/java/tanks/gui/screen/ScreenCrusadePreviewLevel.java b/src/main/java/tanks/gui/screen/ScreenCrusadePreviewLevel.java index fe99de99..61559518 100755 --- a/src/main/java/tanks/gui/screen/ScreenCrusadePreviewLevel.java +++ b/src/main/java/tanks/gui/screen/ScreenCrusadePreviewLevel.java @@ -151,6 +151,15 @@ public void drawLevel() ((Movable) d).drawTeam(); } + if (Game.glowEnabled) + { + for (IDrawable d : this.drawables[i]) + { + if (d instanceof IDrawableWithGlow && ((IDrawableWithGlow) d).isGlowEnabled()) + ((IDrawableWithGlow) d).drawGlow(); + } + } + drawables[i].clear(); } } diff --git a/src/main/java/tanks/gui/screen/ScreenDebug.java b/src/main/java/tanks/gui/screen/ScreenDebug.java index fb97943c..351fc198 100755 --- a/src/main/java/tanks/gui/screen/ScreenDebug.java +++ b/src/main/java/tanks/gui/screen/ScreenDebug.java @@ -41,7 +41,7 @@ public void run() } ); - Button keyboardTest = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 120, this.objWidth, this.objHeight, "Test keyboard", new Runnable() + Button keyboardTest = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 150, this.objWidth, this.objHeight, "Test keyboard", new Runnable() { @Override public void run() @@ -51,7 +51,7 @@ public void run() } ); - Button textboxTest = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 60, this.objWidth, this.objHeight, "Test text boxes", new Runnable() + Button textboxTest = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 90, this.objWidth, this.objHeight, "Test text boxes", new Runnable() { @Override public void run() @@ -61,7 +61,17 @@ public void run() } ); - Button traceAllRays = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 0, this.objWidth, this.objHeight, "", new Runnable() + Button modelTest = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 30, this.objWidth, this.objHeight, "Test models", new Runnable() + { + @Override + public void run() + { + Game.screen = new ScreenTestModel(Game.triangle); + } + } + ); + + Button traceAllRays = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 30, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() @@ -75,7 +85,7 @@ public void run() } }); - Button firstPerson = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 120, this.objWidth, this.objHeight, "", new Runnable() + Button firstPerson = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 150, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() @@ -89,7 +99,7 @@ public void run() } }); - Button followingCam = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 60, this.objWidth, this.objHeight, "", new Runnable() + Button followingCam = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + 90, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() @@ -108,6 +118,7 @@ public void update() { keyboardTest.update(); textboxTest.update(); + modelTest.update(); traceAllRays.update(); followingCam.update(); firstPerson.update(); @@ -124,6 +135,7 @@ public void draw() firstPerson.draw(); followingCam.draw(); + modelTest.draw(); keyboardTest.draw(); textboxTest.draw(); traceAllRays.draw(); diff --git a/src/main/java/tanks/gui/screen/ScreenDownloadLevel.java b/src/main/java/tanks/gui/screen/ScreenDownloadLevel.java index c3d593e5..ad607f60 100755 --- a/src/main/java/tanks/gui/screen/ScreenDownloadLevel.java +++ b/src/main/java/tanks/gui/screen/ScreenDownloadLevel.java @@ -140,6 +140,15 @@ public void drawLevel() ((Movable) d).drawTeam(); } + if (Game.glowEnabled) + { + for (IDrawable d : this.drawables[i]) + { + if (d instanceof IDrawableWithGlow && ((IDrawableWithGlow) d).isGlowEnabled()) + ((IDrawableWithGlow) d).drawGlow(); + } + } + drawables[i].clear(); } } diff --git a/src/main/java/tanks/gui/screen/ScreenExit.java b/src/main/java/tanks/gui/screen/ScreenExit.java index e3966cdf..93bd5497 100755 --- a/src/main/java/tanks/gui/screen/ScreenExit.java +++ b/src/main/java/tanks/gui/screen/ScreenExit.java @@ -15,7 +15,7 @@ public class ScreenExit extends Screen public ScreenExit() { - if (Game.fancyGraphics && Game.enable3d) + if (Game.fancyTerrain && Game.enable3d) outroAnimationTime = 1000; } diff --git a/src/main/java/tanks/gui/screen/ScreenGame.java b/src/main/java/tanks/gui/screen/ScreenGame.java index 88423d18..1f35fae6 100755 --- a/src/main/java/tanks/gui/screen/ScreenGame.java +++ b/src/main/java/tanks/gui/screen/ScreenGame.java @@ -1649,7 +1649,7 @@ public void draw() int x = (int) (o.posX / Game.tile_size); int y = (int) (o.posY / Game.tile_size); - if (!(!Game.fancyGraphics || !Game.enable3d || x < 0 || x >= Game.currentSizeX || y < 0 || y >= Game.currentSizeY)) + if (!(!Game.fancyTerrain || !Game.enable3d || x < 0 || x >= Game.currentSizeX || y < 0 || y >= Game.currentSizeY)) Game.game.heightGrid[x][y] = Math.max(o.getTileHeight(), Game.game.heightGrid[x][y]); } @@ -1709,7 +1709,7 @@ public void draw() d.draw(); } - if (Game.superGraphics) + if (Game.glowEnabled) { for (int j = 0; j < this.drawables[i].size(); j++) { @@ -1783,7 +1783,7 @@ public void draw() if (Panel.darkness > 0) { Drawing.drawing.setColor(0, 0, 0, Math.max(0, Panel.darkness)); - Game.game.window.fillRect(0, 0, Game.game.window.absoluteWidth, Game.game.window.absoluteHeight - Drawing.drawing.statsHeight); + Game.game.window.shapeRenderer.fillRect(0, 0, Game.game.window.absoluteWidth, Game.game.window.absoluteHeight - Drawing.drawing.statsHeight); } if (Game.game.window.touchscreen && TankPlayer.shootStickEnabled) @@ -1838,7 +1838,7 @@ public void draw() if (shopScreen) { Drawing.drawing.setColor(127, 178, 228, 64); - Game.game.window.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); + Game.game.window.shapeRenderer.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); Drawing.drawing.setInterfaceFontSize(this.titleSize); @@ -1987,7 +1987,7 @@ else if (ScreenPartyLobby.isClient) Drawing.drawing.setColor(255, 127, 0); Drawing.drawing.fillInterfaceProgressRect(play.posX, play.posY + play.sizeY / 2 - 5, play.sizeX * 32 / 35, 3, Math.max(Game.startTime / 400, 0)); - if (Game.superGraphics) + if (Game.glowEnabled) { Drawing.drawing.fillInterfaceGlow(play.posX + ((Game.startTime / 400 - 0.5) * (play.sizeX * 32 / 35)), play.posY + play.sizeY / 2 - 5, 20, 20); } @@ -2019,7 +2019,7 @@ else if (ScreenPartyLobby.isClient) if (paused && !screenshotMode) { Drawing.drawing.setColor(127, 178, 228, 64); - Game.game.window.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); + Game.game.window.shapeRenderer.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); if (ScreenPartyLobby.isClient) { diff --git a/src/main/java/tanks/gui/screen/ScreenInfo.java b/src/main/java/tanks/gui/screen/ScreenInfo.java index 837550d8..a57b87d5 100755 --- a/src/main/java/tanks/gui/screen/ScreenInfo.java +++ b/src/main/java/tanks/gui/screen/ScreenInfo.java @@ -54,7 +54,7 @@ public void draw() this.previous.draw(); Drawing.drawing.setColor(0, 0, 0, 64); - Game.game.window.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); + Game.game.window.shapeRenderer.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); Drawing.drawing.setColor(0, 0, 0, 127); Drawing.drawing.fillInterfaceRect(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2, 700 * this.objWidth / 350, 400 * this.objHeight / 40); diff --git a/src/main/java/tanks/gui/screen/ScreenInterlevel.java b/src/main/java/tanks/gui/screen/ScreenInterlevel.java index a38bda19..6018fc99 100755 --- a/src/main/java/tanks/gui/screen/ScreenInterlevel.java +++ b/src/main/java/tanks/gui/screen/ScreenInterlevel.java @@ -307,7 +307,7 @@ public ScreenInterlevel() this.music = "lose_music.ogg"; } - if (Panel.win && Game.fancyGraphics) + if (Panel.win && Game.effectsEnabled) { for (int i = 0; i < 5; i++) { @@ -325,11 +325,11 @@ public void draw() { this.drawDefaultBackground(); - if (Panel.win && Game.fancyGraphics && !Game.game.window.drawingShadow) + if (Panel.win && Game.effectsEnabled && !Game.game.window.drawingShadow) { ArrayList fireworks = getFireworkArray(); - if (Math.random() < ScreenInterlevel.firework_frequency * Panel.frameFrequency) + if (Math.random() < ScreenInterlevel.firework_frequency * Panel.frameFrequency * Game.effectMultiplier) { Firework f = new Firework(Firework.FireworkType.rocket, (Math.random() * 0.6 + 0.2) * Drawing.drawing.interfaceSizeX, Drawing.drawing.interfaceSizeY, fireworks); f.setRandomColor(); @@ -342,7 +342,7 @@ public void draw() fireworks.get(i).drawUpdate(fireworks, getOtherFireworkArray()); } - if (Game.superGraphics) + if (Game.glowEnabled) { for (int i = 0; i < getFireworkArray().size(); i++) { @@ -420,7 +420,7 @@ else if (skip) if (Game.showSpeedrunTimer) SpeedrunTimer.draw(); - if ((Panel.win && Game.fancyGraphics) || (Level.currentColorR + Level.currentColorG + Level.currentColorB) / 3.0 < 127) + if ((Panel.win && Game.effectsEnabled) || Level.isDark()) Drawing.drawing.setColor(255, 255, 255); else Drawing.drawing.setColor(0, 0, 0); @@ -463,7 +463,7 @@ else if (Crusade.currentCrusade.lose) } } - if (Panel.win && Game.fancyGraphics) + if (Panel.win && Game.effectsEnabled) Panel.darkness = Math.min(Panel.darkness + Panel.frameFrequency * 1.5, 191); } diff --git a/src/main/java/tanks/gui/screen/ScreenLevelBuilder.java b/src/main/java/tanks/gui/screen/ScreenLevelBuilder.java index 601822da..ec2a9dd7 100755 --- a/src/main/java/tanks/gui/screen/ScreenLevelBuilder.java +++ b/src/main/java/tanks/gui/screen/ScreenLevelBuilder.java @@ -2926,7 +2926,7 @@ public boolean[] handlePlace(boolean[] handled, boolean left, boolean right, boo { Drawing.drawing.playVibration("click"); - for (int z = 0; z < 100; z++) + for (int z = 0; z < 100 * Game.effectMultiplier; z++) { Effect e = Effect.createNewEffect(m.posX, m.posY, ((Tank) m).size / 2, Effect.EffectType.piece); double var = 50; @@ -3458,7 +3458,7 @@ public void draw() ((Movable) d).drawTeam(); } - if (Game.superGraphics) + if (Game.glowEnabled) { for (int j = 0; j < this.drawables[i].size(); j++) { @@ -3579,7 +3579,7 @@ else if (currentPlaceable == Placeable.obstacle) if (Game.screen instanceof IOverlayScreen) { Drawing.drawing.setColor(127, 178, 228, 64); - Game.game.window.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); + Game.game.window.shapeRenderer.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); } if (this.paused && !(Game.screen instanceof IOverlayScreen)) @@ -3587,7 +3587,7 @@ else if (currentPlaceable == Placeable.obstacle) Drawing.drawing.setColor(127, 178, 228, 64); //Drawing.drawing.setColor(0, 0, 0, 127); - Game.game.window.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); + Game.game.window.shapeRenderer.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); if (this.confirmDeleteMenu) { diff --git a/src/main/java/tanks/gui/screen/ScreenOptions.java b/src/main/java/tanks/gui/screen/ScreenOptions.java index a10450e6..329c840a 100755 --- a/src/main/java/tanks/gui/screen/ScreenOptions.java +++ b/src/main/java/tanks/gui/screen/ScreenOptions.java @@ -63,7 +63,6 @@ public void run() "Game version---" + "Framerate---" + "Network latency (if in a party)---" + - "Screen hints---" + "Memory usage"); @@ -179,8 +178,12 @@ public static void saveOptions(String homedir) f.startWriting(); f.println("# This file stores game settings that you have set"); f.println("username=" + Game.player.username); - f.println("fancy_graphics=" + Game.fancyGraphics); - f.println("super_graphics=" + Game.superGraphics); + f.println("fancy_terrain=" + Game.fancyTerrain); + f.println("effects=" + Game.effectsEnabled); + f.println("effect_multiplier=" + (int) Math.round(Game.effectMultiplier * 100)); + f.println("bullet_trails=" + Game.bulletTrails); + f.println("fancy_bullet_trails=" + Game.fancyBulletTrails); + f.println("glow=" + Game.glowEnabled); f.println("3d=" + Game.enable3d); f.println("3d_ground=" + Game.enable3dBg); f.println("shadows_enabled=" + Game.shadowsEnabled); @@ -250,11 +253,23 @@ public static void loadOptions(String homedir) else Game.player.username = ""; break; - case "fancy_graphics": - Game.fancyGraphics = Boolean.parseBoolean(optionLine[1]); + case "fancy_terrain": + Game.fancyTerrain = Boolean.parseBoolean(optionLine[1]); break; - case "super_graphics": - Game.superGraphics = Boolean.parseBoolean(optionLine[1]); + case "effects": + Game.effectsEnabled = Boolean.parseBoolean(optionLine[1]); + break; + case "effect_multiplier": + Game.effectMultiplier = Integer.parseInt(optionLine[1]) / 100.0; + break; + case "bullet_trails": + Game.bulletTrails = Boolean.parseBoolean(optionLine[1]); + break; + case "fancy_bullet_trails": + Game.fancyBulletTrails = Boolean.parseBoolean(optionLine[1]); + break; + case "glow": + Game.glowEnabled = Boolean.parseBoolean(optionLine[1]); break; case "3d": Game.enable3d = Boolean.parseBoolean(optionLine[1]); @@ -372,15 +387,6 @@ public static void loadOptions(String homedir) } f.stopReading(); - if (Game.framework == Game.Framework.swing) - { - Game.vsync = false; - Game.angledView = false; - Game.enable3d = false; - Game.enable3dBg = false; - Game.superGraphics = false; - } - if (Game.framework == Game.Framework.libgdx) { Game.angledView = false; diff --git a/src/main/java/tanks/gui/screen/ScreenOptionsEffects.java b/src/main/java/tanks/gui/screen/ScreenOptionsEffects.java new file mode 100755 index 00000000..0aa17fd3 --- /dev/null +++ b/src/main/java/tanks/gui/screen/ScreenOptionsEffects.java @@ -0,0 +1,93 @@ +package tanks.gui.screen; + +import tanks.Drawing; +import tanks.Game; +import tanks.gui.Button; +import tanks.gui.TextBoxSlider; + +public class ScreenOptionsEffects extends Screen +{ + public static final String effectsText = "Particle effects: "; + + Button effects = new Button(this.centerX, this.centerY - this.objYSpace * 0.75, this.objWidth, this.objHeight, "", new Runnable() + { + @Override + public void run() + { + Game.effectsEnabled = !Game.effectsEnabled; + + if (Game.effectsEnabled) + effects.text = effectsText + ScreenOptions.onText; + else + effects.text = effectsText + ScreenOptions.offText; + } + }, + "Particle effects may significantly impact performance"); + + + TextBoxSlider effectMultiplier = new TextBoxSlider(this.centerX, this.centerY + this.objYSpace * 0.75, this.objWidth, this.objHeight, "Particle percentage", new Runnable() + { + @Override + public void run() + { + if (effectMultiplier.inputText.length() <= 0) + effectMultiplier.inputText = effectMultiplier.previousInputText; + + Game.effectMultiplier = Integer.parseInt(effectMultiplier.inputText) / 100.0; + } + } + , (int) Math.round(Game.effectMultiplier * 100), 10, 100, 10); + + Button back = new Button(this.centerX, this.centerY + this.objYSpace * 3.5, this.objWidth, this.objHeight, "Back", new Runnable() + { + @Override + public void run() + { + Game.screen = new ScreenOptionsGraphics(); + } + } + ); + + public ScreenOptionsEffects() + { + this.music = "tomato_feast_1_options.ogg"; + this.musicID = "menu"; + + effectMultiplier.allowLetters = false; + effectMultiplier.allowSpaces = false; + effectMultiplier.maxChars = 2; + effectMultiplier.checkMaxValue = true; + effectMultiplier.checkMinValue = true; + effectMultiplier.integer = true; + + effectMultiplier.r1 = 210; + effectMultiplier.g1 = 210; + effectMultiplier.b1 = 210; + + if (Game.effectsEnabled) + effects.text = effectsText + ScreenOptions.onText; + else + effects.text = effectsText + ScreenOptions.offText; + } + + @Override + public void update() + { + effectMultiplier.update(); + effects.update(); + back.update(); + } + + @Override + public void draw() + { + this.drawDefaultBackground(); + effectMultiplier.draw(); + effects.draw(); + back.draw(); + + Drawing.drawing.setInterfaceFontSize(this.titleSize); + Drawing.drawing.setColor(0, 0, 0); + Drawing.drawing.drawInterfaceText(this.centerX, this.centerY - this.objYSpace * 3.5, "Effect options"); + } +} diff --git a/src/main/java/tanks/gui/screen/ScreenOptionsGraphics.java b/src/main/java/tanks/gui/screen/ScreenOptionsGraphics.java index 6ffa3b20..6339b7e2 100755 --- a/src/main/java/tanks/gui/screen/ScreenOptionsGraphics.java +++ b/src/main/java/tanks/gui/screen/ScreenOptionsGraphics.java @@ -3,40 +3,49 @@ import tanks.Drawing; import tanks.Game; import tanks.gui.Button; -import tanks.gui.TextBoxSlider; public class ScreenOptionsGraphics extends Screen { - public static final String graphicsText = "Graphics: "; + public static final String terrainText = "Terrain: "; + public static final String trailsText = "Bullet trails: "; + public static final String glowText = "Glow effects: "; public static final String vsyncText = "V-Sync: "; + public static final String graphics3dText = "3D graphics: "; public static final String ground3dText = "3D ground: "; public static final String perspectiveText = "View: "; + public static final String antialiasingText = "Antialiasing: "; - public static final String superText = "\u00A7200000200255super"; public static final String fancyText = "\u00A7000100200255fancy"; public static final String fastText = "\u00A7200100000255fast"; public static final String birdsEyeText = "\u00A7000100200255bird's-eye"; public static final String angledText = "\u00A7200100000255angled"; - public static final String antialiasingText = "Antialiasing: "; - - public ScreenOptionsGraphics() { this.music = "tomato_feast_1_options.ogg"; this.musicID = "menu"; - if (Game.fancyGraphics) + if (Game.fancyTerrain) + terrain.text = terrainText + fancyText; + else + terrain.text = terrainText + fastText; + + if (Game.bulletTrails) { - if (Game.superGraphics) - graphics.text = graphicsText + superText; + if (Game.fancyBulletTrails) + bulletTrails.text = trailsText + fancyText; else - graphics.text = graphicsText + fancyText; + bulletTrails.text = trailsText + fastText; } else - graphics.text = graphicsText + fastText; + bulletTrails.text = trailsText + ScreenOptions.offText; + + if (Game.glowEnabled) + glow.text = glowText + ScreenOptions.onText; + else + glow.text = glowText + ScreenOptions.offText; if (Game.vsync) vsync.text = vsyncText + ScreenOptions.onText; @@ -55,19 +64,6 @@ public ScreenOptionsGraphics() else altPerspective.text = perspectiveText + birdsEyeText; - if (Game.framework == Game.Framework.swing) - { - vsync.enabled = false; - altPerspective.enabled = false; - graphics3d.enabled = false; - ground3d.enabled = false; - - vsync.hoverText = new String[]{"Unavailable in Swing mode"}; - altPerspective.hoverText = new String[]{"Unavailable in Swing mode"}; - graphics3d.hoverText = new String[]{"Unavailable in Swing mode"}; - ground3d.hoverText = new String[]{"Unavailable in Swing mode"}; - } - if (!Game.antialiasing) antialiasing.text = antialiasingText + ScreenOptions.offText; else @@ -85,11 +81,27 @@ public ScreenOptionsGraphics() antialiasing.text = antialiasingText + ScreenOptions.offText; antialiasing.enabled = false; } + + shadows.text = "Fancy lighting: "; + + if (!Game.shadowsEnabled) + shadows.text += ScreenOptions.offText; + else + shadows.text += "\u00A7000200000255" + Game.shadowQuality; + + effects.text = "Particle effects: "; + + if (!Game.effectsEnabled) + effects.text += ScreenOptions.offText; + else if (Game.effectMultiplier < 1) + effects.text += "\u00A7200100000255" + (int) Math.round(Game.effectMultiplier * 100) + "%"; + else + effects.text += ScreenOptions.onText; } protected void update3dGroundButton() { - if (Game.fancyGraphics && Game.enable3d) + if (Game.fancyTerrain && Game.enable3d) { ground3d.enabled = true; @@ -106,37 +118,66 @@ protected void update3dGroundButton() } } - Button graphics = new Button(this.centerX - this.objXSpace / 2, this.centerY - this.objYSpace * 1.5, this.objWidth, this.objHeight, "", new Runnable() + Button terrain = new Button(this.centerX - this.objXSpace / 2, this.centerY - this.objYSpace * 2, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() { - if (!Game.fancyGraphics) - Game.fancyGraphics = true; - else if (!Game.superGraphics && Game.framework != Game.Framework.swing) - Game.superGraphics = true; + Game.fancyTerrain = !Game.fancyTerrain; + + if (Game.fancyTerrain) + terrain.text = terrainText + fancyText; + else + terrain.text = terrainText + fastText; + + update3dGroundButton(); + } + }, + "Fancy terrain enables varied block---and ground colors------May impact performance on larger levels"); + + Button bulletTrails = new Button(this.centerX - this.objXSpace / 2, this.centerY - this.objYSpace, this.objWidth, this.objHeight, "", new Runnable() + { + @Override + public void run() + { + if (!Game.bulletTrails) + Game.bulletTrails = true; + else if (!Game.fancyBulletTrails) + Game.fancyBulletTrails = true; else { - Game.fancyGraphics = false; - Game.superGraphics = false; + Game.fancyBulletTrails = false; + Game.bulletTrails = false; } - if (Game.fancyGraphics) + if (Game.bulletTrails) { - if (Game.superGraphics) - graphics.text = graphicsText + superText; + if (Game.fancyBulletTrails) + bulletTrails.text = trailsText + fancyText; else - graphics.text = graphicsText + fancyText; + bulletTrails.text = trailsText + fastText; } else - graphics.text = graphicsText + fastText; + bulletTrails.text = trailsText + ScreenOptions.offText; + } + }, "Bullet trails show the paths of bullets------Fancy bullet trails enable some extra particle---effects for certain bullet types"); - update3dGroundButton(); + Button glow = new Button(this.centerX - this.objXSpace / 2, this.centerY, this.objWidth, this.objHeight, "", new Runnable() + { + @Override + public void run() + { + Game.glowEnabled = !Game.glowEnabled; + + if (Game.glowEnabled) + glow.text = glowText + ScreenOptions.onText; + else + glow.text = glowText + ScreenOptions.offText; } }, - "Fast graphics disable most graphical effects---and use solid colors for the background------Fancy graphics enable these effects but---may significantly reduce framerate------Super graphics enable glow and shadow---effects but may further reduce framerate"); + "Glow effects may significantly impact performance"); - Button graphics3d = new Button(this.centerX - this.objXSpace / 2, this.centerY - this.objYSpace * 0.5, this.objWidth, this.objHeight, "", new Runnable() + Button graphics3d = new Button(this.centerX + this.objXSpace / 2, this.centerY - this.objYSpace * 2, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() @@ -153,7 +194,7 @@ public void run() }, "3D graphics may impact performance"); - Button ground3d = new Button(this.centerX - this.objXSpace / 2, this.centerY + this.objYSpace * 0.5, this.objWidth, this.objHeight, "", new Runnable() + Button ground3d = new Button(this.centerX + this.objXSpace / 2, this.centerY - this.objYSpace, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() @@ -169,7 +210,7 @@ public void run() "Enabling 3D ground may impact---performance in large levels"); - Button altPerspective = new Button(this.centerX + this.objXSpace / 2, this.centerY - this.objYSpace * 1.5, this.objWidth, this.objHeight, "", new Runnable() + Button altPerspective = new Button(this.centerX + this.objXSpace / 2, this.centerY, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() @@ -186,7 +227,7 @@ public void run() "Changes the angle at which---you view the game field"); - Button vsync = new Button(this.centerX + this.objXSpace / 2, this.centerY - this.objYSpace * 0.5, this.objWidth, this.objHeight, "", new Runnable() + Button vsync = new Button(this.centerX - this.objXSpace / 2, this.centerY + this.objYSpace * 2, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() @@ -202,7 +243,7 @@ public void run() }, "Limits framerate to your---screen's refresh rate------May decrease battery---consumption------Also, might fix issues with---inconsistent game speed"); - Button antialiasing = new Button(this.centerX + this.objXSpace / 2, this.centerY + this.objYSpace * 0.5, this.objWidth, this.objHeight, "", new Runnable() + Button antialiasing = new Button(this.centerX + this.objXSpace / 2, this.centerY + this.objYSpace * 2, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() @@ -232,26 +273,41 @@ public void run() } ); - Button shadows = new Button(this.centerX, this.centerY + this.objYSpace * 1.5, this.objWidth, this.objHeight, "Lighting", new Runnable() + Button shadows = new Button(this.centerX + this.objXSpace / 2, this.centerY + this.objYSpace * 1, this.objWidth, this.objHeight, "", new Runnable() { @Override public void run() { Game.screen = new ScreenOptionsShadows(); } - } + }, "Fancy lighting enables shadows and---allows for custom lighting in levels------Fancy lighting is quite graphically intense---and may significantly reduce framerate" + ); + + Button effects = new Button(this.centerX - this.objXSpace / 2, this.centerY + this.objYSpace * 1, this.objWidth, this.objHeight, "", new Runnable() + { + @Override + public void run() + { + Game.screen = new ScreenOptionsEffects(); + } + }, "Particle effects may significantly impact performance" ); @Override public void update() { - graphics.update(); + terrain.update(); + bulletTrails.update(); + glow.update(); + effects.update(); + vsync.update(); + graphics3d.update(); ground3d.update(); altPerspective.update(); - vsync.update(); - antialiasing.update(); shadows.update(); + antialiasing.update(); + back.update(); if (Game.antialiasing != Game.game.window.antialiasingEnabled) @@ -272,13 +328,18 @@ public void draw() this.drawDefaultBackground(); back.draw(); - shadows.draw(); + antialiasing.draw(); - ground3d.draw(); - vsync.draw(); + shadows.draw(); altPerspective.draw(); + ground3d.draw(); graphics3d.draw(); - graphics.draw(); + + vsync.draw(); + effects.draw(); + glow.draw(); + bulletTrails.draw(); + terrain.draw(); Drawing.drawing.setInterfaceFontSize(this.titleSize); Drawing.drawing.setColor(0, 0, 0); diff --git a/src/main/java/tanks/gui/screen/ScreenOptionsShadows.java b/src/main/java/tanks/gui/screen/ScreenOptionsShadows.java old mode 100644 new mode 100755 diff --git a/src/main/java/tanks/gui/screen/ScreenOverlayChat.java b/src/main/java/tanks/gui/screen/ScreenOverlayChat.java index 4d3a5740..eb973dee 100755 --- a/src/main/java/tanks/gui/screen/ScreenOverlayChat.java +++ b/src/main/java/tanks/gui/screen/ScreenOverlayChat.java @@ -42,7 +42,7 @@ else if (ScreenPartyHost.isServer) if (chatbox != null) { - if ((Panel.win && Game.fancyGraphics && Game.screen instanceof IDarkScreen) || (Level.isDark())) + if ((Panel.win && Game.effectsEnabled && Game.screen instanceof IDarkScreen) || (Level.isDark())) chatbox.defaultTextColor = "\u00A7255255255255"; chatbox.draw(persistent); @@ -72,17 +72,14 @@ else if (ScreenPartyHost.isServer) double height = 22 * c.lines.size() + 8 * (c.lines.size() - 1); double radius = 13.5; - if ((Panel.win && Game.fancyGraphics && Game.screen instanceof IDarkScreen) || (Level.isDark())) + if ((Panel.win && Game.effectsEnabled && Game.screen instanceof IDarkScreen) || (Level.isDark())) Drawing.drawing.setColor(0, 0, 0, 127); else Drawing.drawing.setColor(255, 255, 255, 127); - if (Game.framework != Game.Framework.swing) - { - Drawing.drawing.fillInterfaceRect(width / 2 + xStart, Drawing.drawing.interfaceSizeY - i * 30 - 70 + radius / 2, width + xPad, radius); - Drawing.drawing.fillInterfaceRect(width / 2 + xStart, Drawing.drawing.interfaceSizeY - (i + (c.lines.size() - 1)) * 30 - 70 - radius / 2, width + xPad, radius); - Drawing.drawing.fillInterfaceRect(width / 2 + xStart, Drawing.drawing.interfaceSizeY - (i + (c.lines.size() - 1) / 2.0) * 30 - 70, width + xPad + radius * 2, height + yPad - radius * 2); - } + Drawing.drawing.fillInterfaceRect(width / 2 + xStart, Drawing.drawing.interfaceSizeY - i * 30 - 70 + radius / 2, width + xPad, radius); + Drawing.drawing.fillInterfaceRect(width / 2 + xStart, Drawing.drawing.interfaceSizeY - (i + (c.lines.size() - 1)) * 30 - 70 - radius / 2, width + xPad, radius); + Drawing.drawing.fillInterfaceRect(width / 2 + xStart, Drawing.drawing.interfaceSizeY - (i + (c.lines.size() - 1) / 2.0) * 30 - 70, width + xPad + radius * 2, height + yPad - radius * 2); Game.game.window.setBatchMode(true, false, false); @@ -138,16 +135,10 @@ else if (ScreenPartyHost.isServer) Drawing.drawing.setColor(c.r2, c.g2, c.b2); - if (Game.framework != Game.Framework.swing) - { - Drawing.drawing.drawInterfaceModel(Turret.turret_model, x, y, size, size, 0); - - Drawing.drawing.setColor((c.r1 + c.r2) / 2, (c.g1 + c.g2) / 2, (c.b1 + c.b2) / 2); - Drawing.drawing.drawInterfaceModel(Turret.base_model, x, y, size, size, 0); - } - else - Drawing.drawing.fillInterfaceRect(x + size / 2, y, size + size * 4 / 25, size * 4 / 25); + Drawing.drawing.drawInterfaceModel(Turret.turret_model, x, y, size, size, 0); + Drawing.drawing.setColor((c.r1 + c.r2) / 2, (c.g1 + c.g2) / 2, (c.b1 + c.b2) / 2); + Drawing.drawing.drawInterfaceModel(Turret.base_model, x, y, size, size, 0); } for (int j = c.lines.size() - 1; j >= 0; j--) @@ -155,7 +146,7 @@ else if (ScreenPartyHost.isServer) double mx = 20; double my = Drawing.drawing.interfaceSizeY - i * 30 - 70; - if ((Panel.win && Game.fancyGraphics && Game.screen instanceof IDarkScreen) || (Level.isDark())) + if ((Panel.win && Game.effectsEnabled && Game.screen instanceof IDarkScreen) || (Level.isDark())) Drawing.drawing.setColor(255, 255, 255); else Drawing.drawing.setColor(0, 0, 0); @@ -168,7 +159,7 @@ else if (ScreenPartyHost.isServer) } } - if ((Panel.win && Game.fancyGraphics && Game.screen instanceof IDarkScreen) || (Level.isDark())) + if ((Panel.win && Game.effectsEnabled && Game.screen instanceof IDarkScreen) || (Level.isDark())) chatbox.defaultTextColor = "\u00A7127127127255"; } } diff --git a/src/main/java/tanks/gui/screen/ScreenOverlayOnline.java b/src/main/java/tanks/gui/screen/ScreenOverlayOnline.java index e1bbd8cd..052e1c95 100755 --- a/src/main/java/tanks/gui/screen/ScreenOverlayOnline.java +++ b/src/main/java/tanks/gui/screen/ScreenOverlayOnline.java @@ -67,7 +67,7 @@ public void draw() this.drawDefaultBackground(); Drawing.drawing.setColor(127, 178, 228, 64); - Game.game.window.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); + Game.game.window.shapeRenderer.fillRect(0, 0, Game.game.window.absoluteWidth + 1, Game.game.window.absoluteHeight + 1); double lowest = -1; for (int i = 0; i < max_button_count; i++) diff --git a/src/main/java/tanks/gui/screen/ScreenPartyCrusadeInterlevel.java b/src/main/java/tanks/gui/screen/ScreenPartyCrusadeInterlevel.java index d5a4abe4..673154aa 100755 --- a/src/main/java/tanks/gui/screen/ScreenPartyCrusadeInterlevel.java +++ b/src/main/java/tanks/gui/screen/ScreenPartyCrusadeInterlevel.java @@ -145,7 +145,7 @@ public ScreenPartyCrusadeInterlevel(boolean win) if (win) this.music = "win_crusade.ogg"; - if (Panel.win && Game.fancyGraphics) + if (Panel.win && Game.effectsEnabled) { for (int i = 0; i < 5; i++) { @@ -160,7 +160,7 @@ public ScreenPartyCrusadeInterlevel(boolean win) @Override public void update() { - if (Panel.win && Game.fancyGraphics) + if (Panel.win && Game.effectsEnabled) Panel.darkness = Math.min(Panel.darkness + Panel.frameFrequency * 1.5, 191); if (ScreenPartyLobby.isClient) @@ -193,10 +193,10 @@ public void draw() { this.drawDefaultBackground(); - if (Panel.win && Game.fancyGraphics && !Game.game.window.drawingShadow) + if (Panel.win && Game.effectsEnabled && !Game.game.window.drawingShadow) { ArrayList fireworks = getFireworkArray(); - if (Math.random() < ScreenInterlevel.firework_frequency * Panel.frameFrequency) + if (Math.random() < ScreenInterlevel.firework_frequency * Panel.frameFrequency * Game.effectMultiplier) { Firework f = new Firework(Firework.FireworkType.rocket, (Math.random() * 0.6 + 0.2) * Drawing.drawing.interfaceSizeX, Drawing.drawing.interfaceSizeY, fireworks); f.setRandomColor(); @@ -209,7 +209,7 @@ public void draw() fireworks.get(i).drawUpdate(fireworks, getOtherFireworkArray()); } - if (Game.superGraphics) + if (Game.glowEnabled) { for (int i = 0; i < getFireworkArray().size(); i++) { @@ -225,7 +225,7 @@ public void draw() odd = !odd; } - if (Panel.win && Game.fancyGraphics) + if (Panel.win && Game.effectsEnabled) Panel.darkness = Math.min(Panel.darkness + Panel.frameFrequency * 1.5, 191); if (ScreenPartyLobby.isClient) @@ -255,7 +255,7 @@ public void draw() if (Game.showSpeedrunTimer) SpeedrunTimer.draw(); - if ((Panel.win && Game.fancyGraphics) || (Level.currentColorR + Level.currentColorG + Level.currentColorB) / 3.0 < 127) + if ((Panel.win && Game.effectsEnabled) || Level.isDark()) Drawing.drawing.setColor(255, 255, 255); else Drawing.drawing.setColor(0, 0, 0); diff --git a/src/main/java/tanks/gui/screen/ScreenPartyInterlevel.java b/src/main/java/tanks/gui/screen/ScreenPartyInterlevel.java index ef3de2ff..2b9df32a 100755 --- a/src/main/java/tanks/gui/screen/ScreenPartyInterlevel.java +++ b/src/main/java/tanks/gui/screen/ScreenPartyInterlevel.java @@ -112,7 +112,7 @@ public ScreenPartyInterlevel() this.music = "lose_music.ogg"; } - if (Panel.win && Game.fancyGraphics) + if (Panel.win && Game.effectsEnabled) { for (int i = 0; i < 5; i++) { @@ -128,7 +128,7 @@ public ScreenPartyInterlevel() @Override public void update() { - if (Panel.win && Game.fancyGraphics) + if (Panel.win && Game.effectsEnabled) Panel.darkness = Math.min(Panel.darkness + Panel.frameFrequency * 1.5, 191); if (ScreenPartyLobby.isClient) @@ -153,10 +153,10 @@ public void draw() { this.drawDefaultBackground(); - if (Panel.win && Game.fancyGraphics && !Game.game.window.drawingShadow) + if (Panel.win && Game.effectsEnabled && !Game.game.window.drawingShadow) { ArrayList fireworks = getFireworkArray(); - if (Math.random() < Panel.frameFrequency * ScreenInterlevel.firework_frequency) + if (Math.random() < Panel.frameFrequency * ScreenInterlevel.firework_frequency * Game.effectMultiplier) { Firework f = new Firework(Firework.FireworkType.rocket, (Math.random() * 0.6 + 0.2) * Drawing.drawing.interfaceSizeX, Drawing.drawing.interfaceSizeY, fireworks); f.setRandomColor(); @@ -169,7 +169,7 @@ public void draw() fireworks.get(i).drawUpdate(fireworks, getOtherFireworkArray()); } - if (Game.superGraphics) + if (Game.glowEnabled) { for (int i = 0; i < getFireworkArray().size(); i++) { @@ -185,7 +185,7 @@ public void draw() odd = !odd; } - if (Panel.win && Game.fancyGraphics) + if (Panel.win && Game.effectsEnabled) Panel.darkness = Math.min(Panel.darkness + Panel.frameFrequency * 1.5, 191); if (ScreenPartyLobby.isClient) @@ -207,7 +207,7 @@ else if (ScreenInterlevel.fromSavedLevels) if (Game.showSpeedrunTimer) SpeedrunTimer.draw(); - if ((Panel.win && Game.fancyGraphics) || (Level.currentColorR + Level.currentColorG + Level.currentColorB) / 3.0 < 127) + if ((Panel.win && Game.effectsEnabled) || Level.isDark()) Drawing.drawing.setColor(255, 255, 255); else Drawing.drawing.setColor(0, 0, 0); diff --git a/src/main/java/tanks/gui/screen/ScreenPreviewShareLevel.java b/src/main/java/tanks/gui/screen/ScreenPreviewShareLevel.java index 1e54cb50..1e22ad45 100755 --- a/src/main/java/tanks/gui/screen/ScreenPreviewShareLevel.java +++ b/src/main/java/tanks/gui/screen/ScreenPreviewShareLevel.java @@ -125,6 +125,15 @@ public void drawLevel() ((Movable) d).drawTeam(); } + if (Game.glowEnabled) + { + for (IDrawable d : this.drawables[i]) + { + if (d instanceof IDrawableWithGlow && ((IDrawableWithGlow) d).isGlowEnabled()) + ((IDrawableWithGlow) d).drawGlow(); + } + } + drawables[i].clear(); } } diff --git a/src/main/java/tanks/gui/screen/ScreenPreviewUploadLevel.java b/src/main/java/tanks/gui/screen/ScreenPreviewUploadLevel.java index 9550a28a..467cd7db 100755 --- a/src/main/java/tanks/gui/screen/ScreenPreviewUploadLevel.java +++ b/src/main/java/tanks/gui/screen/ScreenPreviewUploadLevel.java @@ -106,6 +106,15 @@ public void drawLevel() ((Movable) d).drawTeam(); } + if (Game.glowEnabled) + { + for (IDrawable d : this.drawables[i]) + { + if (d instanceof IDrawableWithGlow && ((IDrawableWithGlow) d).isGlowEnabled()) + ((IDrawableWithGlow) d).drawGlow(); + } + } + drawables[i].clear(); } } diff --git a/src/main/java/tanks/gui/screen/ScreenSaveSharedLevel.java b/src/main/java/tanks/gui/screen/ScreenSaveSharedLevel.java index 493bfbc8..e27d1586 100755 --- a/src/main/java/tanks/gui/screen/ScreenSaveSharedLevel.java +++ b/src/main/java/tanks/gui/screen/ScreenSaveSharedLevel.java @@ -157,6 +157,15 @@ public void drawLevel() ((Movable) d).drawTeam(); } + if (Game.glowEnabled) + { + for (IDrawable d : this.drawables[i]) + { + if (d instanceof IDrawableWithGlow && ((IDrawableWithGlow) d).isGlowEnabled()) + ((IDrawableWithGlow) d).drawGlow(); + } + } + drawables[i].clear(); } } diff --git a/src/main/java/tanks/gui/screen/ScreenTestModel.java b/src/main/java/tanks/gui/screen/ScreenTestModel.java new file mode 100755 index 00000000..7fab26fc --- /dev/null +++ b/src/main/java/tanks/gui/screen/ScreenTestModel.java @@ -0,0 +1,103 @@ +package tanks.gui.screen; + +import basewindow.InputCodes; +import basewindow.PosedModel; +import basewindow.PosedModelAnimation; +import basewindow.PosedModelPose; +import tanks.Drawing; +import tanks.Game; +import tanks.Panel; + +public class ScreenTestModel extends Screen +{ + public PosedModel model; + public double yaw; + public double pitch; + public double roll; + public double scale = 50; + + public double posX = Drawing.drawing.sizeX / 2; + public double posY = Drawing.drawing.sizeY / 2; + public double posZ = 0; + + //PosedModelAnimation animation; + //PosedModelPose pose; + + public ScreenTestModel(PosedModel m) + { + this.music = "tomato_feast_1_options.ogg"; + this.musicID = "menu"; + this.model = m; + + //animation = new PosedModelAnimation(Game.game.fileManager, "/models/mustard-test/walk.pma"); + //pose = new PosedModelPose(Game.game.fileManager, "/models/mustard-test/idlehands.pmp"); + } + + @Override + public void update() + { + double frac = 0.02; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_RIGHT)) + this.yaw += Panel.frameFrequency * frac; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_LEFT)) + this.yaw -= Panel.frameFrequency * frac; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_UP)) + this.pitch += Panel.frameFrequency * frac; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_DOWN)) + this.pitch -= Panel.frameFrequency * frac; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_9)) + this.roll += Panel.frameFrequency * frac; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_0)) + this.roll -= Panel.frameFrequency * frac; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_EQUAL)) + this.scale += Panel.frameFrequency; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_MINUS)) + this.scale -= Panel.frameFrequency; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_W)) + this.posY -= Panel.frameFrequency; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_S)) + this.posY += Panel.frameFrequency; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_A)) + this.posX -= Panel.frameFrequency; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_D)) + this.posX += Panel.frameFrequency; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_Q)) + this.posZ -= Panel.frameFrequency; + + if (Game.game.window.pressedKeys.contains(InputCodes.KEY_R)) + this.posZ += Panel.frameFrequency; + + for (PosedModel.PoseBone b: model.bones) + { + b.yaw = 0; + b.pitch = 0; + b.roll = 0; + b.offX = 0; + b.offY = 0; + b.offZ = 0; + } + + //animation.apply(model, System.currentTimeMillis() / 10.0, 1); + //pose.apply(model, 1); + } + + @Override + public void draw() + { + Drawing.drawing.setColor(255, 255, 255); + Drawing.drawing.drawModel(this.model, this.posX, this.posY, this.posZ, scale, scale, scale, this.yaw, this.pitch, this.roll); + } +} diff --git a/src/main/java/tanks/gui/screen/ScreenTitle.java b/src/main/java/tanks/gui/screen/ScreenTitle.java index b4c24b28..fc014853 100755 --- a/src/main/java/tanks/gui/screen/ScreenTitle.java +++ b/src/main/java/tanks/gui/screen/ScreenTitle.java @@ -28,7 +28,6 @@ public class ScreenTitle extends Screen implements ISeparateBackgroundScreen @Override public void run() { - Game.exitToCrash(new RuntimeException("Lmao this is a crash screen")); if (Game.framework == Game.Framework.libgdx) Game.screen = new ScreenExit(); else diff --git a/src/main/java/tanks/gui/screen/Tutorial.java b/src/main/java/tanks/gui/screen/Tutorial.java index 7d323320..c4b93cfc 100755 --- a/src/main/java/tanks/gui/screen/Tutorial.java +++ b/src/main/java/tanks/gui/screen/Tutorial.java @@ -1,5 +1,6 @@ package tanks.gui.screen; +import basewindow.ModelPart; import tanks.*; import tanks.tank.*; @@ -17,7 +18,7 @@ public class Tutorial public TankBrown brown; - public Model arrow; + public ModelPart arrow; public void loadTutorial(boolean initial, boolean touchscreen) @@ -52,10 +53,10 @@ public void loadTutorial(boolean initial, boolean touchscreen) this.brown.team = Game.enemyTeam; Game.movables.add(this.brown); - arrow = new Model(); - arrow.shapes = new Model.Shape[2]; - arrow.shapes[0] = new Model.Triangle(new Model.Point(-1, 0, 0), new Model.Point(-1.75, 0, 0), new Model.Point(-2, 0.25, 0), 1); - arrow.shapes[1] = new Model.Triangle(new Model.Point(-1, 0, 0), new Model.Point(-1.75, 0, 0), new Model.Point(-2, -0.25, 0), 1); + arrow = Drawing.drawing.createModel(); + arrow.shapes = new ModelPart.Shape[2]; + arrow.shapes[0] = new ModelPart.Triangle(new ModelPart.Point(-1, 0, 0), new ModelPart.Point(-1.75, 0, 0), new ModelPart.Point(-2, 0.25, 0), 1); + arrow.shapes[1] = new ModelPart.Triangle(new ModelPart.Point(-1, 0, 0), new ModelPart.Point(-1.75, 0, 0), new ModelPart.Point(-2, -0.25, 0), 1); } public void update() diff --git a/src/main/java/tanks/hotbar/Hotbar.java b/src/main/java/tanks/hotbar/Hotbar.java index fd268e00..e6b0d2cc 100755 --- a/src/main/java/tanks/hotbar/Hotbar.java +++ b/src/main/java/tanks/hotbar/Hotbar.java @@ -206,7 +206,7 @@ public void draw() { int count = 0; - for (Movable m: Game.movables) + for (Movable m : Game.movables) { if (m instanceof Tank && !Team.isAllied(Game.playerTank, m) && !m.destroy) count++; @@ -223,15 +223,10 @@ public void draw() Drawing.drawing.setColor(159, 32, 32, (100 - this.percentHidden) * 2.55); - if (Game.framework != Game.Framework.swing) - { - Drawing.drawing.drawInterfaceModel(Turret.turret_model, x, y, Game.tile_size / 2, Game.tile_size / 2, 0); + Drawing.drawing.drawInterfaceModel(Turret.turret_model, x, y, Game.tile_size / 2, Game.tile_size / 2, 0); - Drawing.drawing.setColor(207, 16, 16, (100 - this.percentHidden) * 2.55); - Drawing.drawing.drawInterfaceModel(Turret.base_model, x, y, Game.tile_size / 2, Game.tile_size / 2, 0); - } - else - Drawing.drawing.fillInterfaceRect(x + Game.tile_size / 4, y, Game.tile_size / 2 + 4, 4); + Drawing.drawing.setColor(207, 16, 16, (100 - this.percentHidden) * 2.55); + Drawing.drawing.drawInterfaceModel(Turret.base_model, x, y, Game.tile_size / 2, Game.tile_size / 2, 0); Drawing.drawing.setColor(255, 0, 0, (100 - this.percentHidden) * 2.55); Drawing.drawing.setInterfaceFontSize(24); diff --git a/src/main/java/tanks/obstacle/Obstacle.java b/src/main/java/tanks/obstacle/Obstacle.java index 045a7f0c..c2ae08df 100755 --- a/src/main/java/tanks/obstacle/Obstacle.java +++ b/src/main/java/tanks/obstacle/Obstacle.java @@ -275,7 +275,7 @@ public static double[] getRandomColor() double colorMul = Math.random() * 0.5 + 0.5; double[] col = new double[3]; - if (Game.fancyGraphics) + if (Game.fancyTerrain) { col[0] = (colorMul * (176 - Math.random() * 70)); col[1] = (colorMul * (111 - Math.random() * 34)); @@ -367,7 +367,7 @@ public void onDestroy() public void playDestroyAnimation(double posX, double posY, double radius) { - if (Game.fancyGraphics) + if (Game.effectsEnabled) { Effect.EffectType effect = this.destroyEffect; double freq = Math.min((Math.sqrt(Math.pow(posX - this.posX, 2) + Math.pow(posY - this.posY, 2)) + Game.tile_size * 2.5) / radius, 1); @@ -377,18 +377,19 @@ public void playDestroyAnimation(double posX, double posY, double radius) if (effect == Effect.EffectType.obstaclePiece) effect = Effect.EffectType.obstaclePiece3d; - for (int j = 0; j < Game.tile_size; j += 10) + double s = 12.5; + for (double j = 0; j < Game.tile_size; j += s) { - for (int k = 0; k < Game.tile_size; k += 10) + for (double k = 0; k < Game.tile_size; k += s) { - for (int l = 0; l < Game.tile_size * this.stackHeight; l += 10) + for (double l = 0; l < Game.tile_size * this.stackHeight; l += s) { - if (Math.random() > this.destroyEffectAmount * freq * freq) + if (Math.random() > this.destroyEffectAmount * freq * freq * Game.effectMultiplier) continue; - Effect e = Effect.createNewEffect(this.posX + j + 5 - Game.tile_size / 2, this.posY + k + 5 - Game.tile_size / 2, l, effect); + Effect e = Effect.createNewEffect(this.posX + j + s / 2 - Game.tile_size / 2, this.posY + k + s / 2 - Game.tile_size / 2, l, effect); - int block = (int) ((this.stackHeight * Game.tile_size - (l + 10)) / Game.tile_size); + int block = (int) ((this.stackHeight * Game.tile_size - (l + s)) / Game.tile_size); if (this.enableStacking) { @@ -421,6 +422,9 @@ public void playDestroyAnimation(double posX, double posY, double radius) { for (int k = 0; k < Game.tile_size - 6; k += 4) { + if (Math.random() > this.destroyEffectAmount * freq * freq * Game.effectMultiplier) + continue; + Effect e = Effect.createNewEffect(this.posX + j + 5 - Game.tile_size / 2, this.posY + k + 5 - Game.tile_size / 2, effect); e.colR = this.colorR; diff --git a/src/main/java/tanks/obstacle/ObstacleBoostPanel.java b/src/main/java/tanks/obstacle/ObstacleBoostPanel.java old mode 100644 new mode 100755 index 5645c3f0..2601a85c --- a/src/main/java/tanks/obstacle/ObstacleBoostPanel.java +++ b/src/main/java/tanks/obstacle/ObstacleBoostPanel.java @@ -1,6 +1,7 @@ package tanks.obstacle; import tanks.*; +import tanks.bullet.Bullet; import tanks.gui.screen.ScreenGame; import tanks.tank.Tank; @@ -45,19 +46,19 @@ public void onObjectEntryLocal(Movable m) effect = false; } - if (effect) + if (effect && !(m instanceof Bullet && !((Bullet) m).playPopSound)) Drawing.drawing.playSound("boost.ogg"); - if (Game.fancyGraphics && !ScreenGame.finished) + if (Game.effectsEnabled && !ScreenGame.finished && !(m instanceof Bullet && !((Bullet) m).playPopSound)) { if (effect) { - for (int i = 0; i < 50; i++) + for (int i = 0; i < 25 * Game.effectMultiplier; i++) { this.addEffect(m.posX, m.posY, 0.5); } } - else + else if (Math.random() < Panel.frameFrequency * Game.effectMultiplier * 0.25) this.addEffect(m.posX, m.posY, 0); } } @@ -93,7 +94,7 @@ public void draw() { double offset = 0; - if (Game.fancyGraphics) + if (Game.fancyTerrain) offset = Math.sin((this.posX + this.posY + System.currentTimeMillis() / 50.0) / 10) * 40 + 40; if (!Game.enable3d) @@ -106,7 +107,7 @@ public void draw() Drawing.drawing.setColor(this.colorR - offset / 2, Math.min(this.colorG - offset + this.brightness, 255), this.colorB + this.brightness, 255, 1.0); Drawing.drawing.fillBox(this.posX, this.posY, 0, Obstacle.draw_size, Obstacle.draw_size, 10); - if (Game.superGraphics) + if (Game.glowEnabled) { glow.posX = this.posX; glow.posY = this.posY; diff --git a/src/main/java/tanks/obstacle/ObstacleBouncy.java b/src/main/java/tanks/obstacle/ObstacleBouncy.java index c6bf7a01..35fb4e85 100755 --- a/src/main/java/tanks/obstacle/ObstacleBouncy.java +++ b/src/main/java/tanks/obstacle/ObstacleBouncy.java @@ -19,7 +19,7 @@ public ObstacleBouncy(String name, double posX, double posY) stackColorG[i] = 0; stackColorB[i] = 255; - if (!Game.fancyGraphics) + if (!Game.fancyTerrain) stackColorR[i] = 191; } @@ -27,7 +27,7 @@ public ObstacleBouncy(String name, double posX, double posY) stackColorG[0] = colorG; stackColorB[0] = colorB; - if (!Game.fancyGraphics) + if (!Game.fancyTerrain) this.colorR = 191; this.description = "A destructible block which---allows bullets to bounce more"; diff --git a/src/main/java/tanks/obstacle/ObstacleBreakable.java b/src/main/java/tanks/obstacle/ObstacleBreakable.java old mode 100644 new mode 100755 index 506064eb..f01f6b7b --- a/src/main/java/tanks/obstacle/ObstacleBreakable.java +++ b/src/main/java/tanks/obstacle/ObstacleBreakable.java @@ -17,9 +17,13 @@ public ObstacleBreakable(String name, double posX, double posY) double frac = Math.random() * 0.2 + 0.8; + if (!Game.fancyTerrain) + frac = 0.9; + this.colorR = 246 * frac; this.colorG = 206 * frac; this.colorB = 135 * frac; + this.checkForObjects = true; this.update = true; @@ -27,6 +31,9 @@ public ObstacleBreakable(String name, double posX, double posY) { double frac2 = Math.random() * 0.2 + 0.8; + if (!Game.fancyTerrain) + frac2 = 0.9; + this.stackColorR[i] = 246 * frac2; this.stackColorG[i] = 206 * frac2; this.stackColorB[i] = 135 * frac2; @@ -52,7 +59,28 @@ public void reactToHit(double bx, double by) this.fallAnimation = 100; this.stackHeight = Math.min(this.stackHeight, 1); + + double r = this.stackColorR[0]; + double g = this.stackColorG[0]; + double b = this.stackColorB[0]; + + this.stackColorR[0] = this.stackColorR[this.stackColorR.length - 1]; + this.stackColorG[0] = this.stackColorG[this.stackColorR.length - 1]; + this.stackColorB[0] = this.stackColorB[this.stackColorR.length - 1]; + this.playDestroyAnimation(bx - (this.posX - bx) * 2, by - (this.posY - by) * 2, Game.tile_size); + + this.stackColorR[0] = r; + this.stackColorG[0] = g; + this.stackColorB[0] = b; + + for (int i = this.stackColorR.length - 1; i > 0; i--) + { + this.stackColorR[i] = this.stackColorR[i - 1]; + this.stackColorG[i] = this.stackColorG[i - 1]; + this.stackColorB[i] = this.stackColorB[i - 1]; + } + this.stackHeight = height - 1; if (this.stackHeight <= 0) @@ -82,7 +110,7 @@ public void draw() { for (int i = 0; i < Math.min(this.stackHeight, 4); i++) { - int in = (int) (default_max_height - this.stackHeight + i); + int in = default_max_height - 1 - i; drawing.setColor(this.stackColorR[in], this.stackColorG[in], this.stackColorB[in], this.colorA); byte option = 0; diff --git a/src/main/java/tanks/obstacle/ObstacleExplosive.java b/src/main/java/tanks/obstacle/ObstacleExplosive.java old mode 100644 new mode 100755 index fe65a092..d8d8fc3d --- a/src/main/java/tanks/obstacle/ObstacleExplosive.java +++ b/src/main/java/tanks/obstacle/ObstacleExplosive.java @@ -20,11 +20,17 @@ public ObstacleExplosive(String name, double posX, double posY) this.colorG = Math.random() * 40 + 80; this.colorB = 0; + if (!Game.fancyTerrain) + this.colorG = 100; + for (int i = 0; i < default_max_height; i++) { this.stackColorR[i] = 255; this.stackColorG[i] = Math.random() * 40 + 80; this.stackColorB[i] = 0; + + if (!Game.fancyTerrain) + this.stackColorG[i] = 100; } this.destroyEffectAmount = 0; diff --git a/src/main/java/tanks/obstacle/ObstacleHole.java b/src/main/java/tanks/obstacle/ObstacleHole.java index 5a5c5ba3..b6e697e2 100755 --- a/src/main/java/tanks/obstacle/ObstacleHole.java +++ b/src/main/java/tanks/obstacle/ObstacleHole.java @@ -44,7 +44,7 @@ public void drawForInterface(double x, double y) @Override public void drawTile(double r, double g, double b, double d) { - if (Game.fancyGraphics) + if (Game.fancyTerrain) { double mul = 0.4 + 0.6 * (1 - draw_size / Game.tile_size); Drawing.drawing.setColor(r * mul, g * mul, b * mul); diff --git a/src/main/java/tanks/obstacle/ObstacleMud.java b/src/main/java/tanks/obstacle/ObstacleMud.java index d5427a7e..c9dd755b 100755 --- a/src/main/java/tanks/obstacle/ObstacleMud.java +++ b/src/main/java/tanks/obstacle/ObstacleMud.java @@ -45,7 +45,7 @@ public void onObjectEntry(Movable m) @Override public void onObjectEntryLocal(Movable m) { - if (Game.fancyGraphics && m instanceof Tank && !ScreenGame.finished && Math.random() * Panel.frameFrequency <= 0.1) + if (Game.effectsEnabled && m instanceof Tank && !ScreenGame.finished && Math.random() * Panel.frameFrequency <= 0.1 * Game.effectMultiplier) { Tank t = (Tank) m; double a = m.getPolarDirection(); diff --git a/src/main/java/tanks/obstacle/ObstacleShrubbery.java b/src/main/java/tanks/obstacle/ObstacleShrubbery.java index 7b1f0e16..ad70ca0d 100755 --- a/src/main/java/tanks/obstacle/ObstacleShrubbery.java +++ b/src/main/java/tanks/obstacle/ObstacleShrubbery.java @@ -34,7 +34,7 @@ public ObstacleShrubbery(String name, double posX, double posY) this.colorB = (Math.random() * 20); this.enableStacking = false; - if (!Game.fancyGraphics) + if (!Game.fancyTerrain) { this.colorR = 10; this.colorG = 175; diff --git a/src/main/java/tanks/obstacle/ObstacleSnow.java b/src/main/java/tanks/obstacle/ObstacleSnow.java index b92f17c1..fe08e375 100755 --- a/src/main/java/tanks/obstacle/ObstacleSnow.java +++ b/src/main/java/tanks/obstacle/ObstacleSnow.java @@ -39,7 +39,7 @@ public ObstacleSnow(String name, double posX, double posY) double darkness = Math.random() * 20; - if (!Game.fancyGraphics) + if (!Game.fancyTerrain) darkness = 10; this.colorR = 255 - darkness; @@ -84,13 +84,13 @@ public void onObjectEntry(Movable m) @Override public void onObjectEntryLocal(Movable m) { - if (Game.fancyGraphics && !ScreenGame.finished) + if (Game.effectsEnabled && !ScreenGame.finished) { double speed = Math.sqrt((Math.pow(m.vX, 2) + Math.pow(m.vY, 2))); double mul = 0.0625 / 4; - double amt = speed * mul * Panel.frameFrequency; + double amt = speed * mul * Panel.frameFrequency * Game.effectMultiplier; if (amt < 1 && Math.random() < amt % 1) amt += 1; @@ -154,7 +154,7 @@ public void draw() double g = Game.tilesG[x][y]; double b = Game.tilesB[x][y]; - if (!Game.fancyGraphics) + if (!Game.fancyTerrain) { r = Level.currentColorR; g = Level.currentColorG; diff --git a/src/main/java/tanks/obstacle/ObstacleTeleporter.java b/src/main/java/tanks/obstacle/ObstacleTeleporter.java index e8a6184b..32cd90e0 100755 --- a/src/main/java/tanks/obstacle/ObstacleTeleporter.java +++ b/src/main/java/tanks/obstacle/ObstacleTeleporter.java @@ -65,7 +65,7 @@ public void draw() { Drawing.drawing.setColor(this.colorR * (2 - this.brightness) / 2, this.colorG * (2 - this.brightness) / 2, this.colorB * (2 - this.brightness) / 2, 255, 1); - if (Game.superGraphics) + if (Game.glowEnabled) Drawing.drawing.fillGlow(this.posX, this.posY, height + 7, draw_size * 20 / 8, draw_size * 20 / 8, true, false); Drawing.drawing.setColor(this.colorR * (2 - this.brightness) / 2, this.colorG * (2 - this.brightness) / 2, this.colorB * (2 - this.brightness) / 2, 255, (2 - this.brightness) / 2); @@ -73,7 +73,7 @@ public void draw() Drawing.drawing.setColor(this.brightness * this.colorR + 255 * (1 - this.brightness), this.brightness * this.colorG + 255 * (1 - this.brightness), this.brightness * this.colorB + 255 * (1 - this.brightness), 255, (2 - this.brightness) / 2); Drawing.drawing.fillOval(this.posX, this.posY, height + 7, draw_size / 2, draw_size / 2, true, false); - if (Game.fancyGraphics) + if (Game.fancyTerrain) { glow.posX = this.posX; glow.posY = this.posY; @@ -88,7 +88,7 @@ public void draw() { Drawing.drawing.setColor(this.colorR * (2 - this.brightness) / 2, this.colorG * (2 - this.brightness) / 2, this.colorB * (2 - this.brightness) / 2, 255, 1); - if (Game.superGraphics) + if (Game.glowEnabled) Drawing.drawing.fillGlow(this.posX, this.posY, draw_size * 20 / 8, draw_size * 20 / 8); Drawing.drawing.setColor(this.colorR * (2 - this.brightness) / 2, this.colorG * (2 - this.brightness) / 2, this.colorB * (2 - this.brightness) / 2, 255, (2 - this.brightness) / 2); diff --git a/src/main/java/tanks/tank/Mine.java b/src/main/java/tanks/tank/Mine.java index 79f2b520..191e22f8 100755 --- a/src/main/java/tanks/tank/Mine.java +++ b/src/main/java/tanks/tank/Mine.java @@ -91,7 +91,7 @@ public void draw() { Drawing.drawing.setColor(this.outlineColorR, this.outlineColorG, this.outlineColorB, 255, 0.5); - if (Game.enable3d && Game.enable3dBg && Game.fancyGraphics) + if (Game.enable3d && Game.enable3dBg && Game.fancyTerrain) { this.height = Math.max(this.height, Game.sampleGroundHeight(this.posX - this.size / 2, this.posY - this.size / 2)); this.height = Math.max(this.height, Game.sampleGroundHeight(this.posX + this.size / 2, this.posY - this.size / 2)); @@ -110,14 +110,14 @@ public void draw() Drawing.drawing.setColor(this.outlineColorR, this.outlineColorG, this.outlineColorB, 255, 1); - if (Game.superGraphics) + if (Game.glowEnabled) Drawing.drawing.fillGlow(this.posX, this.posY, height + 1, this.size * 4, this.size * 4, true, false); } else { Drawing.drawing.fillOval(this.posX, this.posY, this.size, this.size); - if (Game.superGraphics) + if (Game.glowEnabled) Drawing.drawing.fillGlow(this.posX, this.posY, this.size * 4, this.size * 4); } @@ -184,9 +184,9 @@ public void explode() Drawing.drawing.playSound("explosion.ogg", (float) (mine_size / this.size)); this.exploded = true; - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int j = 0; j < 400 * this.radius / 125; j++) + for (int j = 0; j < 200 * this.radius / 125 * Game.effectMultiplier; j++) { double random = Math.random(); Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); diff --git a/src/main/java/tanks/tank/Ray.java b/src/main/java/tanks/tank/Ray.java index d2cb7bcb..e205d7ef 100755 --- a/src/main/java/tanks/tank/Ray.java +++ b/src/main/java/tanks/tank/Ray.java @@ -425,6 +425,9 @@ else if (this.posY - this.size/2 < 0) { return (int) this.age; } + + if (Double.isNaN(this.posX) || Double.isNaN(this.posY)) + return (int) this.age; } } diff --git a/src/main/java/tanks/tank/Tank.java b/src/main/java/tanks/tank/Tank.java index 04aa77e8..0743010b 100755 --- a/src/main/java/tanks/tank/Tank.java +++ b/src/main/java/tanks/tank/Tank.java @@ -1,5 +1,6 @@ package tanks.tank; +import basewindow.ModelPart; import tanks.*; import tanks.event.EventTankAddAttributeModifier; import tanks.event.EventTankUpdate; @@ -82,10 +83,10 @@ public abstract class Tank extends Movable implements ISolidObject public Face[] horizontalFaces; public Face[] verticalFaces; - public static Model base_model = new Model(); - public static Model color_model = new Model(); + public static ModelPart base_model; + public static ModelPart color_model; - public static Model health_model = new Model(); + public static ModelPart health_model; public Tank(String name, double x, double y, double size, double r, double g, double b, boolean countID) { @@ -299,9 +300,9 @@ public void update() this.onDestroy(); - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int i = 0; i < this.size * 4; i++) + for (int i = 0; i < this.size * 2 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.size / 4, Effect.EffectType.piece); double var = 50; @@ -359,7 +360,7 @@ else if (a.name.equals("boost_effect")) boost = a.getValue(boost); } - if (Math.random() * Panel.frameFrequency < boost && Game.fancyGraphics) + if (Math.random() * Panel.frameFrequency < boost * Game.effectMultiplier && Game.effectsEnabled) { Effect e = Effect.createNewEffect(this.posX, this.posY, Game.tile_size / 2, Effect.EffectType.piece); double var = 50; @@ -469,9 +470,6 @@ public void drawTank(boolean forInterface) Drawing drawing = Drawing.drawing; double[] teamColor = Team.getObjectColor(this.turret.colorR, this.turret.colorG, this.turret.colorB, this); - if (Game.framework == Game.Framework.swing) - teamColor = Team.getObjectColor(this.colorR, this.colorG, this.colorB, this); - for (int i = 0; i < this.attributes.size(); i++) { AttributeModifier a = this.attributes.get(i); @@ -483,7 +481,7 @@ public void drawTank(boolean forInterface) Drawing.drawing.setColor(teamColor[0] * glow * 2, teamColor[1] * glow * 2, teamColor[2] * glow * 2, 255, 1); - if (Game.superGraphics) + if (Game.glowEnabled) { double size = 4 * s; if (forInterface) @@ -552,9 +550,7 @@ else if (!Game.enable3d) double size = s; for (int i = 1; i < Math.min(health, 6); i++) { - if (Game.framework == Game.Framework.swing) - drawing.drawRect(this.posX, this.posY, size * 1.2, size * 1.2); - else if (Game.enable3d) + if (Game.enable3d) drawing.drawModel(health_model, this.posX, this.posY, s / 4, size, size, s, @@ -702,7 +698,7 @@ public Face[] getVerticalFaces() public void setEffectHeight(Effect e) { - if (Game.enable3d && Game.enable3dBg && Game.fancyGraphics) + if (Game.enable3d && Game.enable3dBg && Game.glowEnabled) { e.posZ = Math.max(e.posZ, Game.sampleGroundHeight(e.posX - e.size / 2, e.posY - e.size / 2)); e.posZ = Math.max(e.posZ, Game.sampleGroundHeight(e.posX + e.size / 2, e.posY - e.size / 2)); diff --git a/src/main/java/tanks/tank/TankAIControlled.java b/src/main/java/tanks/tank/TankAIControlled.java index caa162ae..5a868b2f 100755 --- a/src/main/java/tanks/tank/TankAIControlled.java +++ b/src/main/java/tanks/tank/TankAIControlled.java @@ -246,6 +246,9 @@ public void update() { this.vX *= Math.pow(1 - (0.15 * this.frictionModifier), Panel.frameFrequency); this.vY *= Math.pow(1 - (0.15 * this.frictionModifier), Panel.frameFrequency); + + if (this.enableDefensiveFiring) + this.checkForBulletThreats(); } if (!ScreenGame.finished) diff --git a/src/main/java/tanks/tank/TankMini.java b/src/main/java/tanks/tank/TankMini.java index 32a7ed37..8a00bdab 100755 --- a/src/main/java/tanks/tank/TankMini.java +++ b/src/main/java/tanks/tank/TankMini.java @@ -70,7 +70,6 @@ public void postUpdate() this.setAccelerationInDirection(this.tank.posX, this.tank.posY, this.acceleration); } } - } } diff --git a/src/main/java/tanks/tank/TankOrangeRed.java b/src/main/java/tanks/tank/TankOrangeRed.java old mode 100644 new mode 100755 diff --git a/src/main/java/tanks/tank/TankRed.java b/src/main/java/tanks/tank/TankRed.java index 745ed6d5..db961f5b 100755 --- a/src/main/java/tanks/tank/TankRed.java +++ b/src/main/java/tanks/tank/TankRed.java @@ -73,7 +73,7 @@ public void shoot() if (this.cooldown > 0) { this.idleTime = 0; - if (Math.random() * maxCooldown > cooldown && Game.fancyGraphics) + if (Math.random() * maxCooldown * Game.effectMultiplier > cooldown && Game.effectsEnabled) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.size / 4, Effect.EffectType.charge); diff --git a/src/main/java/tanks/tank/TankRemote.java b/src/main/java/tanks/tank/TankRemote.java index 2a0cb576..97860cfb 100755 --- a/src/main/java/tanks/tank/TankRemote.java +++ b/src/main/java/tanks/tank/TankRemote.java @@ -53,6 +53,9 @@ public TankRemote(Tank t) this.tank = t; this.turret.length = t.turret.length; this.turret.size = t.turret.size; + this.turret.colorR = t.turret.colorR; + this.turret.colorG = t.turret.colorG; + this.turret.colorB = t.turret.colorB; this.invulnerable = true; this.networkID = t.networkID; this.texture = t.texture; @@ -95,9 +98,9 @@ public void draw() { this.vanished = true; - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int i = 0; i < 50; i++) + for (int i = 0; i < 50 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); double var = 50; diff --git a/src/main/java/tanks/tank/TankWhite.java b/src/main/java/tanks/tank/TankWhite.java index 271f7015..6ed86b33 100755 --- a/src/main/java/tanks/tank/TankWhite.java +++ b/src/main/java/tanks/tank/TankWhite.java @@ -46,9 +46,9 @@ public void draw() { this.vanish = true; - if (Game.fancyGraphics) + if (Game.effectsEnabled) { - for (int i = 0; i < 50; i++) + for (int i = 0; i < 50 * Game.effectMultiplier; i++) { Effect e = Effect.createNewEffect(this.posX, this.posY, this.size / 4, Effect.EffectType.piece); double var = 50; diff --git a/src/main/java/tanks/tank/TeleporterOrb.java b/src/main/java/tanks/tank/TeleporterOrb.java index 81cea676..b56c57ef 100755 --- a/src/main/java/tanks/tank/TeleporterOrb.java +++ b/src/main/java/tanks/tank/TeleporterOrb.java @@ -48,7 +48,9 @@ public TeleporterOrb(double x, double y, double iX, double iY, double destX, dou public void draw() { Drawing.drawing.setColor(255, 255, 255); - Drawing.drawing.fillOval(this.posX, this.posY, this.posZ, (this.size - this.tank.size) / 2, (this.size - this.tank.size) / 2, true, true); + + if (Game.enable3d) + Drawing.drawing.fillOval(this.posX, this.posY, this.posZ, (this.size - this.tank.size) / 2, (this.size - this.tank.size) / 2, true, true); for (int i = 0; i < this.size - this.tank.size; i++) { @@ -85,7 +87,7 @@ public void update() this.tank.inControlOfMotion = true; this.tank.positionLock = false; - for (int i = 0; i < 100; i++) + for (int i = 0; i < 100 * Game.effectMultiplier; i++) { this.createEffect(); } @@ -144,14 +146,15 @@ else if (this.age >= this.maxAge) this.tank.disabled = this.tank.size <= 0; - this.createEffect(); + if (Math.random() < Panel.frameFrequency * Game.effectMultiplier) + this.createEffect(); super.update(); } public void createEffect() { - if (!Game.fancyGraphics) + if (!Game.effectsEnabled) return; Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.teleporterPiece); diff --git a/src/main/java/tanks/tank/Turret.java b/src/main/java/tanks/tank/Turret.java index 90bcc983..48d09ad6 100755 --- a/src/main/java/tanks/tank/Turret.java +++ b/src/main/java/tanks/tank/Turret.java @@ -1,5 +1,6 @@ package tanks.tank; +import basewindow.ModelPart; import tanks.*; public class Turret extends Movable @@ -12,8 +13,8 @@ public class Turret extends Movable Tank tank; - public static Model base_model = new Model(); - public static Model turret_model = new Model(); + public static ModelPart base_model; + public static ModelPart turret_model; public Turret(Tank t) { @@ -41,71 +42,36 @@ public void draw(double angle, boolean forInterface, boolean in3d, boolean trans this.posX = tank.posX; this.posY = tank.posY; - if (Game.framework != Game.Framework.swing) - { - double s = (this.tank.size * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size) * Math.min(this.tank.drawAge / Game.tile_size, 1); - - double l = length * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size - Math.max(Game.tile_size - tank.drawAge, 0) / Game.tile_size * length; - - if (forInterface) - l = Math.min(length, Game.tile_size * 1.5); - - if (transparent) - Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 127, glow); - else - Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 255, glow); - - if (forInterface) - Drawing.drawing.drawInterfaceModel(turret_model, this.posX, this.posY, l, l * size / 8, angle); - else if (!in3d) - Drawing.drawing.drawModel(turret_model, this.posX, this.posY, l, l * size / 8, angle); - else - Drawing.drawing.drawModel(turret_model, this.posX, this.posY, (s * 1.3) / 2 , l, l * size / 8, l * size / 8, angle); - - if (transparent) - Drawing.drawing.setColor((this.colorR + this.tank.colorR) / 2, (this.colorG + this.tank.colorG) / 2, (this.colorB + this.tank.colorB) / 2, 127, glow); - else - Drawing.drawing.setColor((this.colorR + this.tank.colorR) / 2, (this.colorG + this.tank.colorG) / 2, (this.colorB + this.tank.colorB) / 2, 255, glow); - - if (forInterface) - Drawing.drawing.drawInterfaceModel(base_model, this.posX, this.posY, l, l, angle); - else if (!in3d) - Drawing.drawing.drawModel(base_model, this.posX, this.posY, l, l, angle); - else - Drawing.drawing.drawModel(base_model, this.posX, this.posY, s / 2, l, l, l, angle); - } + double s = (this.tank.size * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size) * Math.min(this.tank.drawAge / Game.tile_size, 1); + + double l = length * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size - Math.max(Game.tile_size - tank.drawAge, 0) / Game.tile_size * length; + + if (forInterface) + l = Math.min(length, Game.tile_size * 1.5); + + if (transparent) + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 127, glow); else - { - double amount = 1; - if (Game.fancyGraphics) - amount = 0.25; + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 255, glow); - this.setPolarMotion(angle, 1); + if (forInterface) + Drawing.drawing.drawInterfaceModel(turret_model, this.posX, this.posY, l, l * size / 8, angle); + else if (!in3d) + Drawing.drawing.drawModel(turret_model, this.posX, this.posY, l, l * size / 8, angle); + else + Drawing.drawing.drawModel(turret_model, this.posX, this.posY, (s * 1.3) / 2, l, l * size / 8, l * size / 8, angle); - double l = length * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size - Math.max(Game.tile_size - tank.drawAge, 0); - if (forInterface) - l = Math.min(length, Game.tile_size * 1.5); + if (transparent) + Drawing.drawing.setColor((this.colorR + this.tank.colorR) / 2, (this.colorG + this.tank.colorG) / 2, (this.colorB + this.tank.colorB) / 2, 127, glow); + else + Drawing.drawing.setColor((this.colorR + this.tank.colorR) / 2, (this.colorG + this.tank.colorG) / 2, (this.colorB + this.tank.colorB) / 2, 255, glow); - for (double i = 0; i < l; i += amount) - { - //p.setColor(new Color(75, 40, 0)); - Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB); - int s = (int) (size * (Game.tile_size - this.tank.destroyTimer - Math.max(Game.tile_size - tank.drawAge, 0)) / Game.tile_size * l / Game.tile_size); - - if (forInterface) - { - s = Math.min((int) size, 12); - Drawing.drawing.fillInterfaceOval(this.posX, this.posY, s, s); - } - else - { - Drawing.drawing.fillOval(this.posX, this.posY, s, s); - } - - this.posX += this.vX * amount; - this.posY += this.vY * amount; - } - } + if (forInterface) + Drawing.drawing.drawInterfaceModel(base_model, this.posX, this.posY, l, l, angle); + else if (!in3d) + Drawing.drawing.drawModel(base_model, this.posX, this.posY, l, l, angle); + else + Drawing.drawing.drawModel(base_model, this.posX, this.posY, s / 2, l, l, l, angle); } @Override diff --git a/src/main/java/tanks/tank/TurretAngled.java b/src/main/java/tanks/tank/TurretAngled.java old mode 100644 new mode 100755 index 84ef4bff..9749628f --- a/src/main/java/tanks/tank/TurretAngled.java +++ b/src/main/java/tanks/tank/TurretAngled.java @@ -15,69 +15,35 @@ public void draw(double yaw, double pitch, boolean forInterface, boolean in3d, b this.posX = tank.posX; this.posY = tank.posY; - if (Game.framework != Game.Framework.swing) - { - double s = (this.tank.size * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size) * Math.min(this.tank.drawAge / Game.tile_size, 1); + double s = (this.tank.size * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size) * Math.min(this.tank.drawAge / Game.tile_size, 1); - double l = length * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size - Math.max(Game.tile_size - tank.drawAge, 0) / Game.tile_size * length; + double l = length * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size - Math.max(Game.tile_size - tank.drawAge, 0) / Game.tile_size * length; - if (forInterface) - l = Math.min(length, Game.tile_size * 1.5); + if (forInterface) + l = Math.min(length, Game.tile_size * 1.5); - if (transparent) - Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 127, 0.5); - else - Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 255, 0.5); - - if (forInterface) - Drawing.drawing.drawInterfaceModel(turret_model, this.posX, this.posY, l, l * size / 8, yaw); - else if (!in3d) - Drawing.drawing.drawModel(turret_model, this.posX, this.posY, l, l * size / 8, yaw); - else - Drawing.drawing.drawModel(turret_model, this.posX, this.posY, (s * 1.3) / 2 , l, l * size / 8, l * size / 8, yaw, pitch, 0); - - if (transparent) - Drawing.drawing.setColor((this.colorR + this.tank.colorR) / 2, (this.colorG + this.tank.colorG) / 2, (this.colorB + this.tank.colorB) / 2, 127, 0.5); - else - Drawing.drawing.setColor((this.colorR + this.tank.colorR) / 2, (this.colorG + this.tank.colorG) / 2, (this.colorB + this.tank.colorB) / 2, 255, 0.5); - - if (forInterface) - Drawing.drawing.drawInterfaceModel(base_model, this.posX, this.posY, l, l, yaw); - else if (!in3d) - Drawing.drawing.drawModel(base_model, this.posX, this.posY, l, l, yaw); - else - Drawing.drawing.drawModel(base_model, this.posX, this.posY, s / 2, l, l, l, yaw); - } + if (transparent) + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 127, 0.5); else - { - double amount = 1; - if (Game.fancyGraphics) - amount = 0.25; - - this.setPolarMotion(yaw, 1); + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, 255, 0.5); - double l = length * (Game.tile_size - this.tank.destroyTimer) / Game.tile_size - Math.max(Game.tile_size - tank.drawAge, 0); - if (forInterface) - l = Math.min(length, Game.tile_size * 1.5); - - for (double i = 0; i < l; i += amount) - { - Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB); - int s = (int) (size * (Game.tile_size - this.tank.destroyTimer - Math.max(Game.tile_size - tank.drawAge, 0)) / Game.tile_size * l / Game.tile_size); + if (forInterface) + Drawing.drawing.drawInterfaceModel(turret_model, this.posX, this.posY, l, l * size / 8, yaw); + else if (!in3d) + Drawing.drawing.drawModel(turret_model, this.posX, this.posY, l, l * size / 8, yaw); + else + Drawing.drawing.drawModel(turret_model, this.posX, this.posY, (s * 1.3) / 2, l, l * size / 8, l * size / 8, yaw, pitch, 0); - if (forInterface) - { - s = Math.min((int) size, 12); - Drawing.drawing.fillInterfaceOval(this.posX, this.posY, s, s); - } - else - { - Drawing.drawing.fillOval(this.posX, this.posY, s, s); - } + if (transparent) + Drawing.drawing.setColor((this.colorR + this.tank.colorR) / 2, (this.colorG + this.tank.colorG) / 2, (this.colorB + this.tank.colorB) / 2, 127, 0.5); + else + Drawing.drawing.setColor((this.colorR + this.tank.colorR) / 2, (this.colorG + this.tank.colorG) / 2, (this.colorB + this.tank.colorB) / 2, 255, 0.5); - this.posX += this.vX * amount; - this.posY += this.vY * amount; - } - } + if (forInterface) + Drawing.drawing.drawInterfaceModel(base_model, this.posX, this.posY, l, l, yaw); + else if (!in3d) + Drawing.drawing.drawModel(base_model, this.posX, this.posY, l, l, yaw); + else + Drawing.drawing.drawModel(base_model, this.posX, this.posY, s / 2, l, l, l, yaw); } } diff --git a/src/main/resources/images/bullet_arc.png b/src/main/resources/images/bullet_arc.png old mode 100644 new mode 100755 diff --git a/src/main/resources/images/bullet_boost.png b/src/main/resources/images/bullet_boost.png old mode 100644 new mode 100755 diff --git a/src/main/resources/images/bullet_explosive.png b/src/main/resources/images/bullet_explosive.png old mode 100644 new mode 100755 diff --git a/src/main/resources/images/img.png b/src/main/resources/images/img.png old mode 100644 new mode 100755 diff --git a/src/main/resources/models/triangle/model.obj b/src/main/resources/models/triangle/model.obj new file mode 100755 index 00000000..a4a87dc3 --- /dev/null +++ b/src/main/resources/models/triangle/model.obj @@ -0,0 +1,22 @@ +g 1 0 0 0 +g 2 0 0 0 +gp 2 1 +v -0.5 -0.5 0 +v 0.5 -0.5 0 +v 0 0.5 0 +v -0.5 -0.5 1 +v 0.5 -0.5 1 +v 0 0.5 1 +vg 1 1 1 +vg 2 1 1 +vg 3 1 1 +vg 4 2 1 +vg 5 2 1 +vg 6 2 1 +vt 0 0 +vn 0 0 0 +vc 1 0 0 1 +vc 0 1 0 1 +vc 0 0 1 1 +f 1/1/1/1 2/1/1/2 3/1/1/3 +f 4/1/1/1 5/1/1/2 6/1/1/3 diff --git a/src/main/resources/music/battle_timed_paused.ogg b/src/main/resources/music/battle_timed_paused.ogg old mode 100644 new mode 100755 diff --git a/src/main/resources/shaders/main.frag b/src/main/resources/shaders/main.frag new file mode 100755 index 00000000..eda0d4f2 --- /dev/null +++ b/src/main/resources/shaders/main.frag @@ -0,0 +1,63 @@ +#define DEPTH_OFFSET 0.0005 + +uniform sampler2D depthTexture; +uniform vec3 lightPosition; + +varying vec4 lightBiasedClipPosition; + +uniform sampler2D tex; + +uniform bool texture; +uniform bool depthtest; +uniform float glow; + +uniform float light; +uniform float glowLight; +uniform float shade; +uniform float glowShade; + +uniform int shadowres; +varying vec4 vertexColor; + +uniform bool shadow; + +uniform bool vbo; +uniform vec4 originalColor; + +void main(void) +{ + vec4 color = texture2D(tex, gl_TexCoord[0].st); + + if (texture) + gl_FragColor = color * vertexColor; + else + gl_FragColor = vertexColor; + + if (vbo) + gl_FragColor *= originalColor; + + if (shadow) + { + vec4 lightNDCPosition = lightBiasedClipPosition / lightBiasedClipPosition.w; + + vec4 depth = texture2D(depthTexture, lightNDCPosition.xy); + + if (!depthtest) + gl_FragColor *= vec4(1.0, 1.0, 1.0, 1.0); + else + { + bool lit = depth.z >= lightNDCPosition.z - DEPTH_OFFSET * 2048.0 / float(shadowres); + + if (lit) + { + float col = light * (1.0 - glow) + glowLight * glow; + gl_FragColor *= vec4(col, col, col, 1.0); + } + else + { + float col = shade * (1.0 - glow) + glowShade * glow; + gl_FragColor *= vec4(col, col, col, 1.0); + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/shaders/main.vert b/src/main/resources/shaders/main.vert new file mode 100755 index 00000000..fa3c5e7f --- /dev/null +++ b/src/main/resources/shaders/main.vert @@ -0,0 +1,58 @@ +uniform mat4 viewProjectionMatrix; +uniform mat4 lightViewProjectionMatrix; +uniform mat4 biasMatrix; + +varying vec4 lightBiasedClipPosition; + +uniform sampler2D tex; + +uniform bool texture; +uniform bool depthtest; +uniform float glow; + +uniform float light; +uniform float glowLight; +uniform float shade; +uniform float glowShade; + +uniform int shadowres; +varying vec4 vertexColor; + +uniform bool shadow; + +uniform bool vbo; +uniform vec4 originalColor; + +uniform bool bonesEnabled; +uniform mat4 boneMatrices[128]; +attribute vec4 bones; + +void main(void) +{ + vertexColor = vec4(gl_Color.r, gl_Color.g, gl_Color.b, gl_Color.a); + + vec4 pos; + + if (bonesEnabled) + { + int bone1 = int(bones.x - 0.0001); + int bone2 = int(bones.y - 0.0001); + int bone3 = int(bones.z - 0.0001); + int bone4 = int(bones.w - 0.0001); + float bone1w = bones.x - float(bone1); + float bone2w = bones.y - float(bone2); + float bone3w = bones.z - float(bone3); + float bone4w = bones.w - float(bone4); + + pos = (boneMatrices[bone1] * bone1w + boneMatrices[bone2] * bone2w + boneMatrices[bone3] * bone3w + boneMatrices[bone4] * bone4w) * gl_Vertex; + } + else + pos = gl_Vertex; + + gl_Position = gl_ModelViewProjectionMatrix * pos; + lightBiasedClipPosition = biasMatrix * lightViewProjectionMatrix * gl_ModelViewMatrix * vec4(pos.xyz, 1.0); + + gl_TexCoord[0] = gl_MultiTexCoord0; + gl_TexCoord[1] = gl_MultiTexCoord1; +} + diff --git a/src/main/resources/shaders/shadow_map.vert b/src/main/resources/shaders/shadow_map.vert index aa72003c..3fd554f9 100755 --- a/src/main/resources/shaders/shadow_map.vert +++ b/src/main/resources/shaders/shadow_map.vert @@ -1,8 +1,27 @@ uniform mat4 viewProjectionMatrix; +uniform bool bonesEnabled; +uniform mat4 boneMatrices[128]; +attribute vec4 bones; + void main(void) { - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + if (bonesEnabled) + { + int bone1 = int(bones.x - 0.0001); + int bone2 = int(bones.y - 0.0001); + int bone3 = int(bones.z - 0.0001); + int bone4 = int(bones.w - 0.0001); + float bone1w = bones.x - float(bone1); + float bone2w = bones.y - float(bone2); + float bone3w = bones.z - float(bone3); + float bone4w = bones.w - float(bone4); + + gl_Position = gl_ModelViewProjectionMatrix * (boneMatrices[bone1] * bone1w + boneMatrices[bone2] * bone2w + boneMatrices[bone3] * bone3w + boneMatrices[bone4] * bone4w) * gl_Vertex; + } + else + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_MultiTexCoord1; } \ No newline at end of file diff --git a/src/main/resources/shaders/shadow_shade.frag b/src/main/resources/shaders/shadow_shade.frag deleted file mode 100755 index 32ce29df..00000000 --- a/src/main/resources/shaders/shadow_shade.frag +++ /dev/null @@ -1,52 +0,0 @@ -#define DEPTH_OFFSET 0.0005 - -uniform sampler2D depthTexture; -uniform vec3 lightPosition; - -varying vec4 lightBiasedClipPosition; - -uniform sampler2D tex; - -uniform bool texture; -uniform bool depthtest; -uniform float glow; - -uniform float light; -uniform float glowLight; -uniform float shadow; -uniform float glowShadow; - -uniform int shadowres; -varying vec4 vertexColor; - -void main(void) -{ - vec4 color = texture2D(tex, gl_TexCoord[0].st); - - if (texture) - gl_FragColor = color * vertexColor; - else - gl_FragColor = vertexColor; - - vec4 lightNDCPosition = lightBiasedClipPosition / lightBiasedClipPosition.w; - - vec4 depth = texture2D(depthTexture, lightNDCPosition.xy); - - if (!depthtest) - gl_FragColor *= vec4(1.0, 1.0, 1.0, 1.0); - else - { - bool lit = depth.z >= lightNDCPosition.z - DEPTH_OFFSET * 2048.0 / float(shadowres); - - if (lit) - { - float col = light * (1.0 - glow) + glowLight * glow; - gl_FragColor *= vec4(col, col, col, 1.0); - } - else - { - float col = shadow * (1.0 - glow) + glowShadow * glow; - gl_FragColor *= vec4(col, col, col, 1.0); - } - } -} \ No newline at end of file diff --git a/src/main/resources/shaders/shadow_shade.vert b/src/main/resources/shaders/shadow_shade.vert deleted file mode 100755 index 1035680a..00000000 --- a/src/main/resources/shaders/shadow_shade.vert +++ /dev/null @@ -1,31 +0,0 @@ -uniform mat4 viewProjectionMatrix; -uniform mat4 lightViewProjectionMatrix; -uniform mat4 biasMatrix; - -varying vec4 lightBiasedClipPosition; - -uniform sampler2D tex; - -uniform bool texture; -uniform bool depthtest; -uniform float glow; - -uniform float light; -uniform float glowLight; -uniform float shadow; -uniform float glowShadow; - -uniform int shadowres; -varying vec4 vertexColor; - -void main(void) -{ - vec3 worldPosition = gl_Vertex.xyz; - - lightBiasedClipPosition = biasMatrix * lightViewProjectionMatrix * vec4(worldPosition, 1.0); - gl_Position = viewProjectionMatrix * vec4(worldPosition, 1.0); - - vertexColor = vec4(gl_Color.r, gl_Color.g, gl_Color.b, gl_Color.a); - gl_TexCoord[0] = gl_MultiTexCoord0; - gl_TexCoord[1] = gl_MultiTexCoord1; -} \ No newline at end of file diff --git a/src/main/resources/sounds/boost.ogg b/src/main/resources/sounds/boost.ogg old mode 100644 new mode 100755