Made chunkloading even faster by removing texture location from EVERY SINGLE BLOCK

This commit is contained in:
2020-04-12 01:16:51 -06:00
parent fabd9bcb82
commit 0a53564650
14 changed files with 423 additions and 31 deletions

View File

@@ -1,3 +1,4 @@
import org.gradle.internal.os.OperatingSystem
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
eclipse.project.name = appName + '-core'
@@ -21,3 +22,33 @@ dependencies {
api "com.underwaterapps.overlap2druntime:overlap2d-runtime-libgdx:$overlap2dVersion"
api "com.github.ykrasik:jaci-libgdx-cli-java:$jaciVersion"
}
dependencies {
switch (OperatingSystem.current()) {
case OperatingSystem.WINDOWS:
ext.lwjglNatives = "natives-windows"
break
case OperatingSystem.LINUX:
ext.lwjglNatives = "natives-linux"
break
case OperatingSystem.MAC_OS:
ext.lwjglNatives = "natives-macos"
break
}
// Look up which modules and versions of LWJGL are required and add setup the approriate natives.
configurations.compile.resolvedConfiguration.getResolvedArtifacts().forEach {
if (it.moduleVersion.id.group == "org.lwjgl") {
runtime "org.lwjgl:${it.moduleVersion.id.name}:${it.moduleVersion.id.version}:${lwjglNatives}"
}
}
implementation 'com.github.kotlin-graphics.imgui:imgui:v1.75'
implementation 'com.github.kotlin-graphics.imgui:imgui-bgfx:v1.75'
implementation 'com.github.kotlin-graphics.imgui:imgui-core:v1.75'
implementation 'com.github.kotlin-graphics.imgui:imgui-gl:v1.75'
implementation 'com.github.kotlin-graphics.imgui:imgui-glfw:v1.75'
implementation 'com.github.kotlin-graphics.imgui:imgui-jogl:v1.75'
implementation 'com.github.kotlin-graphics.imgui:imgui-openjfx:v1.75'
implementation 'com.github.kotlin-graphics.imgui:imgui-vk:v1.75'
}

View File

@@ -2,38 +2,16 @@ package Collector.Dimension;
import com.badlogic.gdx.graphics.Texture;
import java.util.HashMap;
public class Block {
private final String name;
private final Boolean harvestable;
private final Boolean breakable;
private final Boolean passable;
private final Texture texture;
public Block(String name) {
this.name = name;
this.texture = new Texture("assets/" + name + ".png");
this.harvestable = true;
this.breakable = true;
this.passable = false;
}
public String getName() {
return name;
}
public Texture getTexture() {
return texture;
}
public Boolean getPassable() {
return passable;
}
public Boolean getBreakable() {
return breakable;
}
public Boolean getHarvestable() {
return harvestable;
}
}

View File

@@ -1,9 +1,12 @@
package Collector.Dimension;
import com.badlogic.gdx.graphics.Texture;
import java.util.HashMap;
public class BlockMaterials {
public static HashMap<String,Block> materials = new HashMap<>();
public static HashMap<String,Texture> textures = new HashMap<>();
//Private so the singleton can't be instantiated
private BlockMaterials() {}
@@ -18,5 +21,9 @@ public class BlockMaterials {
materials.put("air",new Block("air"));
materials.put("roof",new Block("roof"));
materials.put("wall",new Block("wall"));
for (String s:BlockMaterials.materials.keySet()) {
textures.put(s,new Texture("assets/" + s + ".png"));
}
}
}

View File

@@ -2,7 +2,6 @@ package Collector.Dimension;
import Collector.Character.Player;
import Collector.Main;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.github.czyzby.kiwi.util.tuple.immutable.Triple;
@@ -10,8 +9,6 @@ import Collector.Character.InputController;
import Collector.Character.Mouse;
import Collector.Restrictions;
import static Collector.Character.Player.getX;
public class WorldRenderer implements Restrictions {
private final Mouse mouse;
private final InputController inputController;
@@ -25,7 +22,7 @@ public class WorldRenderer implements Restrictions {
for (Triple<Integer, Integer, Integer> chunkpair : Chunks.blocks.keySet()) {
if (chunkpair.getThird() == layer) {
batch.draw(
Chunks.blocks.get(chunkpair).getTexture(),
BlockMaterials.textures.get(Chunks.blocks.get(chunkpair).getName()),
chunkpair.getFirst() << TILE_SHIFT,
chunkpair.getSecond() << TILE_SHIFT
);

View File

@@ -11,6 +11,8 @@ import Collector.Character.InputController;
import Collector.Character.Mouse;
import Collector.Character.Player;
import Collector.UI.GUI;
import imgui.ImGui;
import static Collector.Restrictions.*;

View File

@@ -7,7 +7,7 @@ public interface Restrictions {
float VIEWPORT_WIDTH = 16/2f;
int MOVEMENT_SPEED = 16;
int KEY_DELAY = 1;
int KEY_DELAY = 0;
int TILE_SIZE = 16;
int CHUNK_SIZE = 8;

View File

@@ -1,10 +1,13 @@
package Collector.UI;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.viewport.FitViewport;
import Collector.Restrictions;