Skip to content

Commit 7062442

Browse files
committed
Temp work for 1.5.6
1 parent 7c429da commit 7062442

16 files changed

Lines changed: 499 additions & 113 deletions

File tree

build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ mc_version=1.12.2
22
forge_version=14.23.0.2544
33
mcp_mappings=snapshot_20171120
44

5-
mod_version=1.5.5
5+
mod_version=1.5.6-pre.1

src/main/java/alexiil/mc/mod/load/ClsManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public class ClsManager {
5757
private static IResourceManager resManager;
5858

5959
static {
60+
FUNC_CTX.putConstantBoolean("dark_mode", CustomLoadingScreen.darkMode);
61+
6062
FUNC_CTX.put_l("forge_progress_bar_count", forgeProgressBarTitles::size);
6163
FUNC_CTX.put_l_o("forge_progress_bar_title", String.class, (index) -> {
6264
if (index < 0 || index >= forgeProgressBarTitles.size()) {

src/main/java/alexiil/mc/mod/load/CustomLoadingScreen.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ public class CustomLoadingScreen {
2828

2929
private static final Property PROP_FRAME;
3030
private static final Property PROP_USE_CUSTOM;
31+
// private static final Property PROP_DARK_MODE;
3132
private static final Property PROP_CONFIG;
3233
private static final Property PROP_CONFIG_RANDOMS;
3334
private static final Property PROP_WAIT;
3435
private static final Property PROP_FPS_LIMIT;
36+
private static final Property PROP_DEBUG_RESOURCE_LOADING;
3537

3638
public static final boolean shouldWait;
3739
public static final boolean useFrame;
3840
public static final boolean useCustom;
41+
public static final boolean darkMode;
42+
public static final boolean debugResourceLoading;
3943
public static final String customConfigPath;
4044
public static final int fpsLimit;
4145

@@ -62,6 +66,13 @@ public class CustomLoadingScreen {
6266
"Sleep for a tiny amount of time each mod progress stage to make configs that rely on receiving all mod load stages work a bit better."
6367
);
6468

69+
// PROP_DARK_MODE = CONFIG.get("general", "dark_mode", false);
70+
// PROP_DARK_MODE.setComment("Use dark-mode for loading screens rather than light.");
71+
darkMode = false;// PROP_DARK_MODE.getBoolean();
72+
73+
PROP_DEBUG_RESOURCE_LOADING = CONFIG.get("debug", "resource_loading", false);
74+
debugResourceLoading = PROP_DEBUG_RESOURCE_LOADING.getBoolean();
75+
6576
PROP_FPS_LIMIT = CONFIG.get("general", "fps_limit", 75);
6677
PROP_FPS_LIMIT.setComment(
6778
"The maximum fps to target for the loading screen. The default is 75. Values between 2 and 300 are allowed."

src/main/java/alexiil/mc/mod/load/baked/render/BakedImageRender.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import alexiil.mc.mod.load.render.MinecraftDisplayerRenderer;
1111
import alexiil.mc.mod.load.render.TextureLoader;
12+
import alexiil.mc.mod.load.render.TextureLoader.PreScannedImageData;
1213

1314
import buildcraft.lib.expression.node.value.NodeVariableDouble;
1415

@@ -24,6 +25,8 @@ public class BakedImageRender extends BakedRenderPositioned {
2425
protected final ResourceLocation res;
2526
private final BakedArea pos, tex;
2627

28+
PreScannedImageData preScanned = null;
29+
2730
public BakedImageRender(
2831
NodeVariableDouble varWidth, NodeVariableDouble varHeight, String res, BakedArea pos, BakedArea tex
2932
) {
@@ -37,8 +40,7 @@ public BakedImageRender(
3740
public void preLoad(MinecraftDisplayerRenderer renderer) {
3841
super.preLoad(renderer);
3942

40-
// TODO: Replace this with loading the texture data to bind on the correct thread.
41-
// bindTexture(renderer);
43+
preScanned = TextureLoader.preScan(res);
4244
}
4345

4446
@Override
@@ -62,7 +64,11 @@ public void render(MinecraftDisplayerRenderer renderer) {
6264
}
6365

6466
public void bindTexture(MinecraftDisplayerRenderer renderer) {
65-
TextureLoader.bindTexture(renderer.textureManager, res);
67+
if (preScanned != null) {
68+
preScanned.bind(renderer.textureManager);
69+
} else {
70+
TextureLoader.bindTexture(renderer.textureManager, res);
71+
}
6672
}
6773

6874
@Override

src/main/java/alexiil/mc/mod/load/json/JsonConfigurable.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,18 @@ public final B bake(FunctionContext context) throws InvalidExpressionException {
6666

6767
// These are helper methods to make deserialisation one-liners
6868

69-
protected static <O> O deserialiseObject(JsonObject obj, String memeber, JsonDeserializationContext ctx,
70-
Class<O> clazz) {
69+
protected static <O> O deserialiseObject(
70+
JsonObject obj, String memeber, JsonDeserializationContext ctx, Class<O> clazz
71+
) {
7172
if (obj.has(memeber)) {
7273
return ctx.deserialize(obj.get(memeber), clazz);
7374
}
7475
return null;
7576
}
7677

77-
protected static String consolidateFunction(JsonObject obj, String memeber, JsonDeserializationContext ctx,
78-
String parent, String defaultF) {
78+
protected static String consolidateFunction(
79+
JsonObject obj, String memeber, JsonDeserializationContext ctx, String parent, String defaultF
80+
) {
7981
return consolidateFunction(deserialiseObject(obj, memeber, ctx, String.class), parent, defaultF);
8082
}
8183

@@ -95,16 +97,18 @@ protected static String consolidateFunction(String in, String parent, String def
9597

9698
/** This will override the parents version of the object if in is not null. If in is null and the parent is null,
9799
* then the default is returned. */
98-
protected static <O> O overrideObject(JsonObject obj, String memeber, JsonDeserializationContext ctx,
99-
Class<O> clazz, O parent, O defaultO) {
100+
protected static <O> O overrideObject(
101+
JsonObject obj, String memeber, JsonDeserializationContext ctx, Class<O> clazz, O parent, O defaultO
102+
) {
100103
O in = deserialiseObject(obj, memeber, ctx, clazz);
101104
if (in != null) return in;
102105
if (parent != null) return parent;
103106
return defaultO;
104107
}
105108

106-
protected static JsonVariable[] overrideVariables(JsonObject obj, String memeber, JsonDeserializationContext ctx,
107-
JsonVariable[] parent) {
109+
protected static JsonVariable[] overrideVariables(
110+
JsonObject obj, String memeber, JsonDeserializationContext ctx, JsonVariable[] parent
111+
) {
108112
JsonVariable[] in = deserialiseObject(obj, memeber, ctx, JsonVariable[].class);
109113
if (in == null) {
110114
return parent == null ? new JsonVariable[0] : parent;

src/main/java/alexiil/mc/mod/load/json/JsonRender.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ public JsonRender(String image, String colour) {
2323
}
2424

2525
public JsonRender(JsonRender parent, JsonObject json, JsonDeserializationContext context) {
26-
this.image = overrideObject(json, "image", context, String.class, parent == null ? null : parent.image, "missingno");
27-
this.colour = overrideObject(json, "colour", context, String.class, parent == null ? null : parent.colour, "0xFFFFFFFF");
26+
this.image
27+
= overrideObject(json, "image", context, String.class, parent == null ? null : parent.image, "missingno");
28+
29+
this.colour = overrideObject(
30+
json, "colour", context, String.class, parent == null ? null : parent.colour, "0xFFFFFFFF"
31+
);
2832
}
2933

3034
public List<BakedInsn> bakeInstructions(FunctionContext context) throws InvalidExpressionException {

src/main/java/alexiil/mc/mod/load/json/subtypes/JsonRenderSlideshow.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.FileNotFoundException;
44
import java.io.IOException;
5+
import java.io.InputStream;
56
import java.util.ArrayList;
67
import java.util.List;
78

@@ -52,13 +53,15 @@ protected BakedRender actuallyBake(FunctionContext context) throws InvalidExpres
5253

5354
ResourceLocation r = new ResourceLocation(l);
5455
try {
55-
if (TextureLoader.loadTexture(r) == null) {
56+
InputStream stream = TextureLoader.openResourceStream(r);
57+
if (stream == null) {
5658
if (i == 0) {
5759
continue;
5860
} else {
5961
break;
6062
}
6163
}
64+
stream.close();
6265
} catch (FileNotFoundException fnfe) {
6366
if (i == 0) {
6467
continue;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package alexiil.mc.mod.load.render;
2+
3+
import java.awt.image.BufferedImage;
4+
import java.io.FileNotFoundException;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
8+
import org.lwjgl.opengl.GL11;
9+
import org.lwjgl.opengl.GLContext;
10+
import org.lwjgl.opengl.KHRDebug;
11+
12+
import net.minecraft.client.renderer.texture.SimpleTexture;
13+
import net.minecraft.client.renderer.texture.TextureUtil;
14+
import net.minecraft.client.resources.IResourceManager;
15+
import net.minecraft.util.ResourceLocation;
16+
17+
import net.minecraftforge.fml.client.SplashProgress;
18+
19+
public class ClsTexture extends SimpleTexture {
20+
21+
private BufferedImage image;
22+
private boolean blur;
23+
private boolean clamp;
24+
25+
public ClsTexture(ResourceLocation location) {
26+
super(location);
27+
}
28+
29+
public ResourceLocation location() {
30+
return textureLocation;
31+
}
32+
33+
@Override
34+
public int getGlTextureId() {
35+
36+
if (glTextureId == -1) {
37+
glTextureId = GL11.glGenTextures();
38+
}
39+
return glTextureId;
40+
}
41+
42+
@Override
43+
public void deleteGlTexture() {
44+
if (glTextureId != -1) {
45+
GL11.glDeleteTextures(glTextureId);
46+
glTextureId = -1;
47+
}
48+
}
49+
50+
public void loadImage(IResourceManager resourceManager) throws IOException {
51+
52+
try (InputStream is = TextureLoader.openResourceStream(location())) {
53+
54+
if (is == null) {
55+
throw new FileNotFoundException(location().toString());
56+
}
57+
58+
image = TextureUtil.readBufferedImage(is);
59+
blur = false;
60+
clamp = false;
61+
62+
// if (m.exists()) {
63+
// try {
64+
// TextureMetadataSection meta = (TextureMetadataSection) iresource.getMetadata("texture");
65+
//
66+
// if (meta != null) {
67+
// blur = meta.getTextureBlur();
68+
// clamp = meta.getTextureClamp();
69+
// }
70+
// } catch (RuntimeException runtimeexception) {
71+
// LOGGER.warn("Failed reading metadata of: {}", this.textureLocation, runtimeexception);
72+
// }
73+
// }
74+
}
75+
}
76+
77+
@Override
78+
public void loadTexture(IResourceManager resourceManager) throws IOException {
79+
deleteGlTexture();
80+
81+
if (image == null) {
82+
loadImage(resourceManager);
83+
}
84+
85+
synchronized (SplashProgress.class) {
86+
TextureUtil.uploadTextureImageAllocate(getGlTextureId(), image, blur, clamp);
87+
}
88+
89+
if (GLContext.getCapabilities().GL_KHR_debug) {
90+
KHRDebug.glObjectLabel(GL11.GL_TEXTURE, getGlTextureId(), "CLS_custom_tex_'" + location() + "'");
91+
}
92+
}
93+
}

src/main/java/alexiil/mc/mod/load/render/MainSplashRenderer.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ public static void run() {
190190
start = System.currentTimeMillis();
191191

192192
while (!transitionOutDone) {
193-
GL11.glClearColor(1, 1, 1, 1);
193+
if (CustomLoadingScreen.darkMode) {
194+
GL11.glClearColor(0, 0, 0, 1);
195+
} else {
196+
GL11.glClearColor(1, 1, 1, 1);
197+
}
194198
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
195199

196200
// matrix setup -- similar as SplashProgress
@@ -304,24 +308,26 @@ private static void renderFrame() {
304308
GL11.glScalef(2, 2, 1);
305309
GL11.glEnable(GL11.GL_TEXTURE_2D);
306310

311+
int fontColour = CustomLoadingScreen.darkMode ? 0xFF_FF_FF_FF : 0;
312+
307313
String s = ((diff / 100L) / 10.0) + "s";
308-
fontRenderer.drawString(s, 0, -10, 0);
314+
fontRenderer.drawString(s, 0, -10, fontColour);
309315

310316
s = status + " - " + subStatus;
311-
fontRenderer.drawString(s, -fontRenderer.getStringWidth(s) / 2, -40, 0);
317+
fontRenderer.drawString(s, -fontRenderer.getStringWidth(s) / 2, -40, fontColour);
312318
String bar = getProgress(12, progress);
313-
fontRenderer.drawString(bar, -fontRenderer.getStringWidth(bar) / 2, -30, 0);
319+
fontRenderer.drawString(bar, -fontRenderer.getStringWidth(bar) / 2, -30, fontColour);
314320

315321
Iterator<ProgressBar> i = ProgressManager.barIterator();
316322
while (i.hasNext()) {
317323
ProgressBar b = i.next();
318324

319325
int startWidth = fontRenderer.getStringWidth(b.getTitle() + " ");
320326

321-
fontRenderer.drawString(b.getTitle() + " ", -startWidth, y, 0);
322-
fontRenderer.drawString("- " + b.getMessage(), 0, y, 0);
327+
fontRenderer.drawString(b.getTitle() + " ", -startWidth, y, fontColour);
328+
fontRenderer.drawString("- " + b.getMessage(), 0, y, fontColour);
323329
bar = getProgress(b);
324-
fontRenderer.drawString(bar, -fontRenderer.getStringWidth(bar) / 2, y + 14, 0);
330+
fontRenderer.drawString(bar, -fontRenderer.getStringWidth(bar) / 2, y + 14, fontColour);
325331

326332
y += 30;
327333
}
@@ -342,7 +348,7 @@ private static void renderFrame() {
342348
int x = -w / 4;
343349
y = -h / 4;
344350
for (String s2 : list) {
345-
fontRenderer.drawString(s2, x, y, 0);
351+
fontRenderer.drawString(s2, x, y, fontColour);
346352
y += 20;
347353
}
348354

src/main/java/alexiil/mc/mod/load/render/TextureAnimator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void bindFrame(int frame, boolean loop) {
7979
} else {
8080
ids[frame] = GL11.glGenTextures();
8181
uploadTextureImage(ids[frame], images[frame]);
82-
GL11.glBindTexture(GL11.GL_TEXTURE_2D,ids[frame]);
82+
GL11.glBindTexture(GL11.GL_TEXTURE_2D, ids[frame]);
8383
}
8484
lastUsed[frame] = now;
8585
uploadFramesAhead(frame, TEXTURE_UPLOAD_AHEAD);
@@ -129,7 +129,7 @@ private void tick() {
129129
public static boolean isAnimated(String resourceLocation) {
130130
ResourceLocation location = new ResourceLocation(resourceLocation);
131131
try {
132-
final InputStream stream = TextureLoader.loadTexture(location);
132+
final InputStream stream = TextureLoader.openResourceStream(location);
133133
if (stream == null) {
134134
return false;
135135
}
@@ -139,12 +139,14 @@ public static boolean isAnimated(String resourceLocation) {
139139
reader.setInput(imageStream);
140140
boolean animated = reader.getNumImages(true) > 1;
141141
reader.dispose();
142+
stream.close();
142143
return animated;
143144
} catch (IOException ignored) {} finally {
144145
reader.dispose();
145146
}
146147
}
147148
}
149+
stream.close();
148150
} catch (IOException ignored) {}
149151
return false;
150152
}
@@ -155,7 +157,7 @@ public TextureAnimator(BakedConfig images) {
155157
String resource = render.render.getLocation();
156158
if (resource != null) {
157159
try {
158-
final InputStream stream = TextureLoader.loadTexture(new ResourceLocation(resource));
160+
final InputStream stream = TextureLoader.openResourceStream(new ResourceLocation(resource));
159161
if (stream == null) {
160162
continue;
161163
}
@@ -183,6 +185,7 @@ public TextureAnimator(BakedConfig images) {
183185
frames = Arrays.copyOf(frames, read);
184186
}
185187
if (frames.length < 2) {
188+
stream.close();
186189
continue;
187190
}
188191
CLSLog.info("Number of Frames = " + read);
@@ -196,6 +199,7 @@ public TextureAnimator(BakedConfig images) {
196199
}
197200
}
198201
}
202+
stream.close();
199203
} catch (IOException e) {
200204
// TODO: do something about this!
201205
}

0 commit comments

Comments
 (0)