Finished optimizations for now

This commit is contained in:
2020-04-11 05:33:06 -06:00
parent af0bacc46f
commit d6c54921d8
5 changed files with 54 additions and 56 deletions

View File

@@ -10,7 +10,11 @@ import com.mygdx.game.Restrictions;
import static com.mygdx.game.Main.cam;
public class Mouse implements Restrictions {
Texture crosshair = new Texture("core/assets/crosshair.png");
Texture crosshair;
public Mouse() {
this.crosshair = new Texture("core/assets/crosshair.png");
}
public void selectedTile(SpriteBatch batch) {
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);

View File

@@ -8,16 +8,13 @@ import com.badlogic.gdx.utils.Array;
import com.mygdx.game.Main;
import com.mygdx.game.Restrictions;
import java.util.HashMap;
public class Player implements Restrictions {
private static int x;
private static int y;
private OrthographicCamera cam;
private String spriteName;
private final String spriteName;
public TextureAtlas textureAtlas;
private Animation<TextureAtlas.AtlasRegion> animation;
private HashMap<String, Animation> animations = new HashMap<>();
public Player(OrthographicCamera cam, int x, int y) {
Player.x = x<<TILE_SHIFT;

View File

@@ -7,13 +7,14 @@ import com.mygdx.game.OpenSimplexNoise;
import java.util.HashMap;
import static com.mygdx.game.Dimension.BlockMaterials.*;
import static com.mygdx.game.Dimension.BlockMaterials.materials;
import static com.mygdx.game.Restrictions.*;
public class Chunks {
OpenSimplexNoise gen1 = new OpenSimplexNoise(SEED+1);
OpenSimplexNoise gen2 = new OpenSimplexNoise(SEED);
public static HashMap<Triple<Integer, Integer, Integer>, Block> blocks = new HashMap<>();
public static HashMap<Pair<Integer, Integer>, Block> buildings = new HashMap<>();
public static OpenSimplexNoise gen1 = new OpenSimplexNoise(SEED + 1);
public static OpenSimplexNoise gen2 = new OpenSimplexNoise(SEED);
public static void create() {
int i = 10;
@@ -24,7 +25,7 @@ public class Chunks{
}
public static void setBlock(int x, int y, String name) {
buildings.put(new Pair<>(x,y),new Block(name));
buildings.put(new Pair<>(x, y), materials.get(name));
}
public static void placeBlock(int x, int y, String name){
@@ -41,11 +42,7 @@ public class Chunks{
}
}
public static HashMap<Triple<Integer, Integer,Integer>, Block> blocks = new HashMap<>();
public static HashMap<Pair<Integer,Integer>, Block> buildings = new HashMap<>();
public void ungenerateChunk(int x, int y) {
public static void ungenerateChunk(int x, int y) {
int startX = x << CHUNK_SHIFT;
int startY = y << CHUNK_SHIFT;
int endX = startX + CHUNK_SIZE;
@@ -66,7 +63,7 @@ public class Chunks{
}
}
public void generateChunk(int x, int y){
public static void generateChunk(int x, int y) {
int startX = x << CHUNK_SHIFT;
int startY = y << CHUNK_SHIFT;
int endX = startX + CHUNK_SIZE;
@@ -88,19 +85,19 @@ public class Chunks{
}
}
public Block getBuildings(int x, int y) {
public static Block getBuildings(int x, int y) {
return buildings.getOrDefault(new Pair<>(x, y), new Block("air"));
}
public double noise1(double nx, double ny) {
public static double noise1(double nx, double ny) {
return gen1.eval(nx, ny) / 2 + 0.5;
}
public double noise2(double nx, double ny) {
public static double noise2(double nx, double ny) {
return gen2.eval(nx, ny) / 2 + 0.5;
}
public Block getTerrain(int x, int y) {
public static Block getTerrain(int x, int y) {
double moisture, elevation, nx, ny;
double scale = 0.01;
nx = x * scale;
@@ -124,7 +121,7 @@ public class Chunks{
return getBiomeBlock(moisture, elevation);
}
public Block getBiomeBlock(double moisture, double elevation) {
public static Block getBiomeBlock(double moisture, double elevation) {
String biome = getBiome(moisture, elevation);
if (biome.equals("Tundra")) return materials.get("snow");
if (biome.equals("Taiga")) return materials.get("snow");
@@ -148,7 +145,7 @@ public class Chunks{
return materials.get("water");
}
public String getBiome(double moisture,double elevation){
public static String getBiome(double moisture, double elevation) {
if (elevation < 0.1) return "Ocean";
if (elevation < 0.12) return "Beach";

View File

@@ -6,16 +6,14 @@ import static com.mygdx.game.Restrictions.*;
public class World {
public static void generateWorld(int x, int y) {
Chunks chunks = new Chunks();
if (chunks.isEmpty(x, y)) {
chunks.generateChunk(x, y);
if (Chunks.isEmpty(x, y)) {
Chunks.generateChunk(x, y);
}
}
public static void ungenerateWorld(int x, int y) {
Chunks chunks = new Chunks();
if (!chunks.isEmpty(x, y)) {
chunks.ungenerateChunk(x, y);
if (!Chunks.isEmpty(x, y)) {
Chunks.ungenerateChunk(x, y);
}
}

View File

@@ -11,19 +11,21 @@ import com.mygdx.game.Character.Mouse;
import com.mygdx.game.Restrictions;
public class GUI implements Restrictions {
private Stage stage;
private Label label;
private Mouse mouse;
private BitmapFont font = new BitmapFont();
private FitViewport fitViewport;
private final Stage stage;
private final Label label;
private final Mouse mouse;
private final BitmapFont font;
private final FitViewport fitViewport;
public GUI(Mouse mouse, FitViewport fitViewport) {
font = new BitmapFont();
stage = new Stage(fitViewport);
label = new Label("Start", new Label.LabelStyle(font, new Color(Color.WHITE)));
this.mouse = mouse;
this.fitViewport = fitViewport;
stage = new Stage(fitViewport);
Gdx.input.setInputProcessor(stage);
label = new Label("Hello",new Label.LabelStyle(font,new Color(Color.WHITE)));
stage.addActor(label);
}