Skip to content

Commit

Permalink
Fix transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
minecraft8997 committed Nov 22, 2023
1 parent 96fc12c commit 0e34110
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
4 changes: 2 additions & 2 deletions core/src/ru/mclord/classic/InGameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -109,7 +109,7 @@ public void resume() {

@Override
public void hide() {

dispose();
}

@Override
Expand Down
13 changes: 9 additions & 4 deletions core/src/ru/mclord/classic/LoadingScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -48,6 +49,7 @@ public void setProgress(byte progress) {
@Override
public void show() {
setProgress((byte) 0);
i = (int) (Math.random() * TextureManager.getInstance().getTextureCount());
}

@Override
Expand All @@ -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);
}
Expand Down Expand Up @@ -89,7 +94,7 @@ public void resume() {

@Override
public void hide() {

dispose();
}

@Override
Expand Down
27 changes: 13 additions & 14 deletions core/src/ru/mclord/classic/McLordClassic.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -64,24 +63,14 @@ public enum GameStage {
/* package-private */ final Thread mainThread;
private Properties gameProperties;
/* package-private */ final Queue<TaskContainer> 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;
/* package-private */ String disconnectReason;

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() {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions core/src/ru/mclord/classic/Skybox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
22 changes: 15 additions & 7 deletions core/src/ru/mclord/classic/TextureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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) {
Expand Down Expand Up @@ -83,24 +92,23 @@ 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];

Pixmap emptyPixmap = new Pixmap(textureSize, textureSize, Pixmap.Format.RGBA8888);
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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0e34110

Please sign in to comment.