package uk.org.floop.epq3d; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import java.awt.*; import java.awt.image.BufferedImage; import java.io.FileReader; import java.io.IOException; import java.util.Objects; /** * Stores variables which are required for drawing. Settings, Drawing images etc. */ public class drawData { // config public int scrX; public int scrY; public int delay; public int FOV; // debug public boolean debugHud; public boolean backfaceCullingDisabled; public boolean drawZBuffer; public int frustumCullingOverridePercent; public boolean drawLines; // player public double playerSpeed; public double playerSprintModifier; // draw onto BufferedImage bufImg; public int[][] drawImg; public int[][] zBuf; public BufferedImage debugImg; // draw data public Matrix camMatrix; public double lastFrameTime; // measured in seconds public Point3D playerPos; public double FPDis; public Plane[] frustumPlanes = new Plane[6]; public Point2D mouseRel; public drawData(String filePath){ Object obj; try { JSONParser parser = new JSONParser(); obj = parser.parse(new FileReader(filePath)); } catch (IOException | ParseException e) { throw new RuntimeException(e); } // save config JSONObject file = (JSONObject)obj; scrX = (int) (long) file.get("screenWidth"); scrY = (int) (long) file.get("screenHeight"); delay = (int) ( 1000*(1/((double) (long) file.get("maxFPS")))); FOV = (int) (long) file.get("FOV"); playerSpeed = (double) file.get("playerSpeed"); playerSprintModifier = (double) file.get("playerSprintModifier"); // debug JSONObject debugFile = (JSONObject) file.get("debug"); if(toBoolean(debugFile.get("masterDebugToggle"))){ debugHud = toBoolean(debugFile.get("drawDebugHud")); backfaceCullingDisabled = toBoolean(debugFile.get("overrideBackFaceCulling")); frustumCullingOverridePercent = (int)(long)debugFile.get("frustumCullingOverridePercent"); drawZBuffer = toBoolean(debugFile.get("drawZBuffer")); drawLines = toBoolean(debugFile.get("drawLines")); } bufImg = new BufferedImage(scrX, scrY, BufferedImage.TYPE_INT_ARGB); drawImg = new int[scrX][scrY]; zBuf = new int[scrX][scrY]; debugImg = new BufferedImage(scrX, scrY, BufferedImage.TYPE_INT_ARGB); debugImg.createGraphics(); debugImg.getGraphics().setColor(new Color(0,0,0,255)); } private Boolean toBoolean(Object obj){ if(Objects.equals(obj.toString(), "enabled")){ return true; } else { return false; } } }