Fix bugs with previous commit

This commit is contained in:
Lukas 2020-11-23 16:36:23 +01:00
parent 38cdf8e1bb
commit 122eeaaf3a
6 changed files with 84 additions and 52 deletions

View File

@ -28,6 +28,7 @@ public class GameWindow {
private static final Object waiter = new Object(); private static final Object waiter = new Object();
private static final LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(); private static final LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
private static Connection currentConnection; private static Connection currentConnection;
private static boolean running;
public static void prepare() { public static void prepare() {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
@ -46,12 +47,21 @@ public class GameWindow {
} }
private static void mainLoop() { private static void mainLoop() {
while (!running) {
try { try {
queue.take().run(); queue.take().run();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
}
while (!glfwWindowShouldClose(openGLWindow.getWindowId())) { while (!glfwWindowShouldClose(openGLWindow.getWindowId())) {
if (queue.size() > 0) {
try {
queue.take().run();
} catch (Exception e) {
e.printStackTrace();
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); glLoadIdentity();
glfwPollEvents(); glfwPollEvents();
@ -77,13 +87,12 @@ public class GameWindow {
return openGLWindow; return openGLWindow;
} }
public static Connection getCurrentConnection() {
return currentConnection;
}
public static void setCurrentConnection(Connection currentConnection) { public static void setCurrentConnection(Connection currentConnection) {
if (GameWindow.currentConnection == null) { if (GameWindow.currentConnection == null) {
queue.add(openGLWindow::start); queue.add(() -> {
running = true;
openGLWindow.start();
});
} }
openGLWindow.setCurrentConnection(currentConnection); openGLWindow.setCurrentConnection(currentConnection);
GameWindow.currentConnection = currentConnection; GameWindow.currentConnection = currentConnection;
@ -91,4 +100,8 @@ public class GameWindow {
waiter.notifyAll(); waiter.notifyAll();
} }
} }
public static void queue(Runnable runnable) {
queue.add(runnable);
}
} }

View File

@ -92,10 +92,8 @@ public class BlockModelLoader {
} }
} }
private static HashMap<String, float[]> readTints(JsonObject json) { private static HashMap<String, float[]> readTints(JsonObject textures) {
HashMap<String, float[]> result = new HashMap<>(); HashMap<String, float[]> result = new HashMap<>();
if (json.has("tinted_textures")) {
JsonObject textures = json.get("tinted_textures").getAsJsonObject();
for (String textureName : textures.keySet()) { for (String textureName : textures.keySet()) {
ArrayFloatList colorValues = new ArrayFloatList(); ArrayFloatList colorValues = new ArrayFloatList();
for (JsonElement colorValue : textures.get(textureName).getAsJsonArray()) { for (JsonElement colorValue : textures.get(textureName).getAsJsonArray()) {
@ -104,7 +102,6 @@ public class BlockModelLoader {
float[] color = colorValues.toArray(); float[] color = colorValues.toArray();
result.put(textureName, color); result.put(textureName, color);
} }
}
return result; return result;
} }
} }

View File

@ -129,7 +129,7 @@ public class SubBlock {
} }
private ArrayFloatList prepareFace(FaceOrientation faceDirection, BlockPosition position) { private ArrayFloatList prepareFace(FaceOrientation faceDirection, BlockPosition position) {
if (! uv.get(faceDirection).exists()) { if (!uv.containsKey(faceDirection) || !uv.get(faceDirection).exists()) {
return null; return null;
} }
ArrayFloatList result = new ArrayFloatList(); ArrayFloatList result = new ArrayFloatList();

View File

@ -14,7 +14,6 @@
package de.bixilon.minosoft.render.texture; package de.bixilon.minosoft.render.texture;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants; import de.bixilon.minosoft.render.blockModels.Face.RenderConstants;
import org.apache.commons.collections.primitives.ArrayFloatList; import org.apache.commons.collections.primitives.ArrayFloatList;
@ -73,6 +72,6 @@ public class InFaceUV {
} }
public boolean exists() { public boolean exists() {
return realU1 == -1; return realU1 >= 0;
} }
} }

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.render.texture;
import de.bixilon.minosoft.config.StaticConfiguration; import de.bixilon.minosoft.config.StaticConfiguration;
import de.bixilon.minosoft.data.assets.AssetsManager; import de.bixilon.minosoft.data.assets.AssetsManager;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.render.GameWindow;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants; import de.bixilon.minosoft.render.blockModels.Face.RenderConstants;
import de.matthiasmann.twl.utils.PNGDecoder; import de.matthiasmann.twl.utils.PNGDecoder;
@ -29,6 +30,7 @@ import java.nio.ByteBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL30.glGenerateMipmap; import static org.lwjgl.opengl.GL30.glGenerateMipmap;
@ -39,8 +41,10 @@ public class TextureLoader {
private int textureID; private int textureID;
private float step; private float step;
private int totalTextures = 0; private int totalTextures = 0;
private final CountDownLatch countDownLatch;
public TextureLoader(HashSet<String> textures, HashMap<String, float[]> tints) { public TextureLoader(HashSet<String> textures, HashMap<String, float[]> tints) {
countDownLatch = new CountDownLatch(1);
textureCoordinates = new HashMap<>(); textureCoordinates = new HashMap<>();
loadTextures(textures, tints); loadTextures(textures, tints);
combineTextures(); combineTextures();
@ -48,7 +52,7 @@ public class TextureLoader {
PNGDecoder decoder = new PNGDecoder(new FileInputStream(StaticConfiguration.HOME_DIRECTORY + "assets/allTextures.png")); PNGDecoder decoder = new PNGDecoder(new FileInputStream(StaticConfiguration.HOME_DIRECTORY + "assets/allTextures.png"));
ByteBuffer buf = ByteBuffer.allocateDirect(decoder.getWidth() * decoder.getHeight() * 4); ByteBuffer buf = ByteBuffer.allocateDirect(decoder.getWidth() * decoder.getHeight() * 4);
decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.Format.RGBA); decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
textureID = bindTexture(buf, decoder.getWidth(), decoder.getHeight()); bindTexture(buf, decoder.getWidth(), decoder.getHeight());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
System.exit(5); System.exit(5);
@ -116,8 +120,9 @@ public class TextureLoader {
step = (float) 1 / (float) imageLength * RenderConstants.TEXTURE_PACK_RESOLUTION; step = (float) 1 / (float) imageLength * RenderConstants.TEXTURE_PACK_RESOLUTION;
} }
private int bindTexture(ByteBuffer buf, int width, int height) { private void bindTexture(ByteBuffer buf, int width, int height) {
buf.flip(); buf.flip();
GameWindow.queue(() -> {
int textureID = glGenTextures(); int textureID = glGenTextures();
glBindTexture(GL_TEXTURE_2D, textureID); glBindTexture(GL_TEXTURE_2D, textureID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@ -126,7 +131,14 @@ public class TextureLoader {
//disable smoothing out of textures //disable smoothing out of textures
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 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_MAG_FILTER, GL_NEAREST);
return textureID; this.textureID = textureID;
countDownLatch.countDown();
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
public float getTexture(String textureName) { public float getTexture(String textureName) {

View File

@ -1,17 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="BranchesTreeState">
<expand>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
</path>
</expand>
<select />
</component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="34edf7e9-254a-4d39-b77b-418e1a3041e3" name="Default Changelist" comment=""> <list default="true" id="34edf7e9-254a-4d39-b77b-418e1a3041e3" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java" beforeDir="false" afterPath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/WorldRenderer.java" beforeDir="false" afterPath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/WorldRenderer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java" beforeDir="false" afterPath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/blockModels/BlockModelLoader.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlock.java" beforeDir="false" afterPath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/blockModels/subBlocks/SubBlock.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/movement/CollisionHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/movement/CollisionHandler.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/texture/InFaceUV.java" beforeDir="false" afterPath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/texture/InFaceUV.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/utility/AdditionalMath.java" beforeDir="false" afterPath="$PROJECT_DIR$/../src/main/java/de/bixilon/minosoft/render/utility/AdditionalMath.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/blockModelCombinder.py" beforeDir="false" afterPath="$PROJECT_DIR$/blockModelGenerator.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/version_mappings_generator.py" beforeDir="false" afterPath="$PROJECT_DIR$/version_mappings_generator.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -47,6 +56,7 @@
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" /> <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="TERMINAL_CUSTOM_COMMANDS_GOT_IT" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="android.sdk.path" value="/opt/AndroidSDK" /> <property name="android.sdk.path" value="/opt/AndroidSDK" />
<property name="aspect.path.notification.shown" value="true" /> <property name="aspect.path.notification.shown" value="true" />
@ -146,6 +156,7 @@
</entry> </entry>
</map> </map>
</option> </option>
<option name="oldMeFiltersMigrated" value="true" />
</component> </component>
<component name="WindowStateProjectService"> <component name="WindowStateProjectService">
<state x="444" y="1168" key="#Project_Structure" timestamp="1605462076420"> <state x="444" y="1168" key="#Project_Structure" timestamp="1605462076420">
@ -156,25 +167,25 @@
<screen x="0" y="1050" width="1920" height="1080" /> <screen x="0" y="1050" width="1920" height="1080" />
</state> </state>
<state x="419" y="1248" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462499568" /> <state x="419" y="1248" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462499568" />
<state width="1259" height="329" key="GridCell.Tab.0.bottom" timestamp="1605648137613"> <state width="1259" height="267" key="GridCell.Tab.0.bottom" timestamp="1605907262411">
<screen x="0" y="0" width="1280" height="994" /> <screen x="0" y="0" width="1280" height="994" />
</state> </state>
<state width="1259" height="329" key="GridCell.Tab.0.bottom/-1360.107.1360.738/0.0.1280.994@0.0.1280.994" timestamp="1605648137613" /> <state width="1259" height="267" key="GridCell.Tab.0.bottom/-1360.107.1360.738/0.0.1280.994@0.0.1280.994" timestamp="1605907262411" />
<state width="1874" height="281" key="GridCell.Tab.0.bottom/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462580595" /> <state width="1874" height="281" key="GridCell.Tab.0.bottom/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462580595" />
<state width="1259" height="329" key="GridCell.Tab.0.center" timestamp="1605648137613"> <state width="1259" height="267" key="GridCell.Tab.0.center" timestamp="1605907262411">
<screen x="0" y="0" width="1280" height="994" /> <screen x="0" y="0" width="1280" height="994" />
</state> </state>
<state width="1259" height="329" key="GridCell.Tab.0.center/-1360.107.1360.738/0.0.1280.994@0.0.1280.994" timestamp="1605648137613" /> <state width="1259" height="267" key="GridCell.Tab.0.center/-1360.107.1360.738/0.0.1280.994@0.0.1280.994" timestamp="1605907262411" />
<state width="1874" height="281" key="GridCell.Tab.0.center/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462580595" /> <state width="1874" height="281" key="GridCell.Tab.0.center/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462580595" />
<state width="1259" height="329" key="GridCell.Tab.0.left" timestamp="1605648137613"> <state width="1259" height="267" key="GridCell.Tab.0.left" timestamp="1605907262410">
<screen x="0" y="0" width="1280" height="994" /> <screen x="0" y="0" width="1280" height="994" />
</state> </state>
<state width="1259" height="329" key="GridCell.Tab.0.left/-1360.107.1360.738/0.0.1280.994@0.0.1280.994" timestamp="1605648137613" /> <state width="1259" height="267" key="GridCell.Tab.0.left/-1360.107.1360.738/0.0.1280.994@0.0.1280.994" timestamp="1605907262410" />
<state width="1874" height="281" key="GridCell.Tab.0.left/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462580595" /> <state width="1874" height="281" key="GridCell.Tab.0.left/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462580595" />
<state width="1259" height="329" key="GridCell.Tab.0.right" timestamp="1605648137613"> <state width="1259" height="267" key="GridCell.Tab.0.right" timestamp="1605907262411">
<screen x="0" y="0" width="1280" height="994" /> <screen x="0" y="0" width="1280" height="994" />
</state> </state>
<state width="1259" height="329" key="GridCell.Tab.0.right/-1360.107.1360.738/0.0.1280.994@0.0.1280.994" timestamp="1605648137613" /> <state width="1259" height="267" key="GridCell.Tab.0.right/-1360.107.1360.738/0.0.1280.994@0.0.1280.994" timestamp="1605907262411" />
<state width="1874" height="281" key="GridCell.Tab.0.right/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462580595" /> <state width="1874" height="281" key="GridCell.Tab.0.right/0.40.1680.1010/0.1050.1920.1080/1680.26.1280.1024@0.1050.1920.1080" timestamp="1605462580595" />
<state width="1259" height="329" key="GridCell.Tab.1.bottom" timestamp="1605648130133"> <state width="1259" height="329" key="GridCell.Tab.1.bottom" timestamp="1605648130133">
<screen x="0" y="0" width="1280" height="994" /> <screen x="0" y="0" width="1280" height="994" />
@ -202,7 +213,7 @@
<breakpoints> <breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/version_mappings_generator.py</url> <url>file://$PROJECT_DIR$/version_mappings_generator.py</url>
<line>281</line> <line>305</line>
<option name="timeStamp" value="1" /> <option name="timeStamp" value="1" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>