From 0e34110a59d76fcd4b18399a93b3c761d0fcbc10 Mon Sep 17 00:00:00 2001 From: minecraft8997 <35162137+minecraft8997@users.noreply.github.com> Date: Wed, 22 Nov 2023 12:28:19 +0300 Subject: [PATCH] Fix transparency --- core/src/ru/mclord/classic/InGameScreen.java | 4 +-- core/src/ru/mclord/classic/LoadingScreen.java | 13 ++++++--- core/src/ru/mclord/classic/McLordClassic.java | 27 +++++++++---------- core/src/ru/mclord/classic/Skybox.java | 3 +-- .../src/ru/mclord/classic/TextureManager.java | 22 ++++++++++----- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/core/src/ru/mclord/classic/InGameScreen.java b/core/src/ru/mclord/classic/InGameScreen.java index 0ac1cc1..0c74806 100644 --- a/core/src/ru/mclord/classic/InGameScreen.java +++ b/core/src/ru/mclord/classic/InGameScreen.java @@ -54,7 +54,7 @@ public void show() { environment = new Environment(); if (!EventManager.getInstance() .fireEvent(CustomizeEnvironmentEvent.create(environment))) { - environment = new Environment(); + environment = null; } Player player = McLordClassic.getPlayer(); @@ -109,7 +109,7 @@ public void resume() { @Override public void hide() { - + dispose(); } @Override diff --git a/core/src/ru/mclord/classic/LoadingScreen.java b/core/src/ru/mclord/classic/LoadingScreen.java index 88edb2f..b5e9cd8 100644 --- a/core/src/ru/mclord/classic/LoadingScreen.java +++ b/core/src/ru/mclord/classic/LoadingScreen.java @@ -18,6 +18,7 @@ public class LoadingScreen implements Screen { private volatile byte progress; private int width; private int height; + private int i; private LoadingScreen() { font = new BitmapFont(); @@ -48,6 +49,7 @@ public void setProgress(byte progress) { @Override public void show() { setProgress((byte) 0); + i = (int) (Math.random() * TextureManager.getInstance().getTextureCount()); } @Override @@ -56,10 +58,13 @@ public void render(float delta) { batch.begin(); font.draw(batch, (status != null ? status : "Loading"), 32, height - 32); - for (int i = 0; i < TextureManager.getInstance().getTextureCount(); i++) { - Texture blockTexture = TextureManager.getInstance().getTexture(i); - int x = i * TextureManager.getInstance().getTextureSize(); + int textureCount = TextureManager.getInstance().getTextureCount(); + for (int c = 0; ; c++) { + Texture blockTexture = TextureManager.getInstance() + .getTexture((i + c) % textureCount); + + int x = c * TextureManager.getInstance().getTextureSize(); if (x >= width) break; batch.draw(blockTexture, x, PROGRESS_BAR_HEIGHT); } @@ -89,7 +94,7 @@ public void resume() { @Override public void hide() { - + dispose(); } @Override diff --git a/core/src/ru/mclord/classic/McLordClassic.java b/core/src/ru/mclord/classic/McLordClassic.java index d5001d5..14f670c 100644 --- a/core/src/ru/mclord/classic/McLordClassic.java +++ b/core/src/ru/mclord/classic/McLordClassic.java @@ -1,7 +1,6 @@ package ru.mclord.classic; import com.badlogic.gdx.Game; -import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader; import ru.mclord.classic.events.DisconnectEvent; import ru.mclord.classic.events.LevelDownloadingFinishedEvent; import ru.mclord.classic.events.PlayerSpawnEvent; @@ -64,7 +63,7 @@ public enum GameStage { /* package-private */ final Thread mainThread; private Properties gameProperties; /* package-private */ final Queue taskList = new ArrayDeque<>(); - /* package-private */ GameStage stage = GameStage.INTERNAL_INITIALIZATION; + /* package-private */ GameStage stage; /* package-private */ volatile NetworkingThread networkingThread; /* package-private */ Level level; private boolean levelDownloadFinishedForTheFirstTime = true; @@ -72,16 +71,6 @@ public enum GameStage { private McLordClassic() { this.mainThread = Thread.currentThread(); - - if (DEBUG) GameParameters.setupDebugProperties(); - GameParameters.collectAndVerify(); - - EventManager.getInstance().registerEventHandler( - DisconnectEvent.class, this::handleDisconnect); - EventManager.getInstance().registerEventHandler( - LevelDownloadingFinishedEvent.class, this::handleLevelDownloadingFinished); - EventManager.getInstance().registerEventHandler( - PlayerSpawnEvent.class, this::handlePlayerSpawn); } public static McLordClassic game() { @@ -129,6 +118,18 @@ public Object addTask(Runnable task, boolean subscribe) { @Override public void create() { + setStage(GameStage.INTERNAL_INITIALIZATION); + + if (DEBUG) GameParameters.setupDebugProperties(); + GameParameters.collectAndVerify(); + + EventManager.getInstance().registerEventHandler( + DisconnectEvent.class, this::handleDisconnect); + EventManager.getInstance().registerEventHandler( + LevelDownloadingFinishedEvent.class, this::handleLevelDownloadingFinished); + EventManager.getInstance().registerEventHandler( + PlayerSpawnEvent.class, this::handlePlayerSpawn); + System.out.println("Loading texture pack"); String configTexturePack = gameProperties.getProperty("texturePack"); if (configTexturePack == null || configTexturePack.isEmpty()) { @@ -172,12 +173,10 @@ public void render() { System.exit(-1); } if (container.subscribed) { - System.out.println("Attempting to notify"); synchronized (container) { container.finished = true; container.notifyAll(); } - System.out.println("Notified"); } if (task instanceof NetworkingRunnable) { synchronized (networkingThread) { diff --git a/core/src/ru/mclord/classic/Skybox.java b/core/src/ru/mclord/classic/Skybox.java index b267ecb..5998ec2 100644 --- a/core/src/ru/mclord/classic/Skybox.java +++ b/core/src/ru/mclord/classic/Skybox.java @@ -55,7 +55,6 @@ public void render(ModelBatch batch, Camera camera) { @Override public void dispose() { - Helper.dispose(modelInstance.model); - modelInstance = null; + Helper.dispose(modelInstance.model); modelInstance = null; } } diff --git a/core/src/ru/mclord/classic/TextureManager.java b/core/src/ru/mclord/classic/TextureManager.java index 10aef71..98c251e 100644 --- a/core/src/ru/mclord/classic/TextureManager.java +++ b/core/src/ru/mclord/classic/TextureManager.java @@ -22,6 +22,7 @@ default boolean shouldWalk(int i) { } } + private static int TEXTURE_COUNT_IN_A_ROW = 16; public static final String DEFAULT_TEXTURE_PACK = "https://static.classicube.net/default.zip"; @@ -45,6 +46,14 @@ public static TextureManager getInstance() { return INSTANCE; } + public static void setTextureCountInARow(int textureCountInARow) { + if (McLordClassic.game().stage != null) { + throw new IllegalStateException(); + } + + TextureManager.TEXTURE_COUNT_IN_A_ROW = textureCountInARow; + } + @SuppressWarnings("unchecked") @ShouldBeCalledBy(thread = "main") public void load(String path, boolean allowNet, boolean allowFileSystem) { @@ -83,15 +92,14 @@ public void load(String path, boolean allowNet, boolean allowFileSystem) { } catch (IOException e) { throw new RuntimeException(e); } - int width = image.getWidth(); int height = image.getHeight(); int textureCount; - if (width % 16 != 0) illegalTerrainDimensions(); - textureSize = width / 16; + if (width % TextureManager.TEXTURE_COUNT_IN_A_ROW != 0) illegalTerrainDimensions(); + textureSize = width / TextureManager.TEXTURE_COUNT_IN_A_ROW; if (height % textureSize != 0) illegalTerrainDimensions(); - textureCount = (height / textureSize) * 16; + textureCount = (height / textureSize) * TextureManager.TEXTURE_COUNT_IN_A_ROW; textures = new Texture[textureCount]; @@ -99,8 +107,8 @@ public void load(String path, boolean allowNet, boolean allowFileSystem) { emptyTexture = new Texture(emptyPixmap); temporaryPixmaps.add(emptyPixmap); - walk(textures, temporaryPixmaps, textures.length, textureSize, - textureSize, 16, (pixmap, xOffset, yOffset, x, y) -> { + walk(textures, temporaryPixmaps, textures.length, textureSize, textureSize, + TEXTURE_COUNT_IN_A_ROW, (pixmap, xOffset, yOffset, x, y) -> { int color; int realX = xOffset + x; @@ -162,7 +170,7 @@ private static void illegalTerrainDimensions() { public static int textureColorFrom(int bufferedImageColor) { byte alpha = (byte) ((bufferedImageColor >> 24) & 0xFF); bufferedImageColor <<= 8; - bufferedImageColor += alpha; + bufferedImageColor |= ((int) alpha) & 0xFF; // might be it's possible to optimize this? return bufferedImageColor;