-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add debug arg to dump all texture sizes in a csv file
- Loading branch information
Showing
4 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/com/gtnewhorizon/gtnhlib/debug/TexturesDebug.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.gtnewhorizon.gtnhlib.debug; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
|
||
import net.minecraft.client.Minecraft; | ||
|
||
public class TexturesDebug { | ||
|
||
private static boolean initSpriteLogger = false; | ||
private static PrintStream logAtlasSprite = null; | ||
private static boolean initDynamicLogger = false; | ||
private static PrintStream logDynamic = null; | ||
|
||
public static void logTextureAtlasSprite(String iconName, int width, int height, int frames, int sizeBytes) { | ||
logTextureAtlasSprite(iconName + "," + width + "," + height + "," + frames + "," + sizeBytes); | ||
} | ||
|
||
private static void logTextureAtlasSprite(String message) { | ||
if (!initSpriteLogger) { | ||
logAtlasSprite = initLogger("TexturesDebug.csv"); | ||
initSpriteLogger = true; | ||
logTextureAtlasSprite("iconName,width,height,frames,sizeBytes"); | ||
} | ||
if (logAtlasSprite != null) { | ||
logAtlasSprite.println(message); | ||
} | ||
} | ||
|
||
public static void logDynamicTexture(int width, int height) { | ||
if (!initDynamicLogger) { | ||
logDynamic = initLogger("DynamicTextures.txt"); | ||
initDynamicLogger = true; | ||
} | ||
if (logDynamic != null) { | ||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); | ||
logDynamic.println("Created texture of width " + width + " height " + height); | ||
for (int i = 0; i < stackTrace.length; i++) { | ||
StackTraceElement element = stackTrace[i]; | ||
if (i == 4 || i == 5) { | ||
logDynamic.println("at " + element); | ||
break; | ||
} | ||
} | ||
logDynamic.println(" "); | ||
} | ||
} | ||
|
||
private static PrintStream initLogger(String file) { | ||
final File logFile = new File(Minecraft.getMinecraft().mcDataDir, file); | ||
if (logFile.exists()) { | ||
// noinspection ResultOfMethodCallIgnored | ||
logFile.delete(); | ||
} | ||
if (!logFile.exists()) { | ||
try { | ||
// noinspection ResultOfMethodCallIgnored | ||
logFile.createNewFile(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
try { | ||
return new PrintStream(new FileOutputStream(logFile, true)); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/gtnewhorizon/gtnhlib/mixins/early/debug/MixinDynamicTexture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.gtnewhorizon.gtnhlib.mixins.early.debug; | ||
|
||
import net.minecraft.client.renderer.texture.DynamicTexture; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.gtnewhorizon.gtnhlib.debug.TexturesDebug; | ||
|
||
@Mixin(DynamicTexture.class) | ||
public class MixinDynamicTexture { | ||
|
||
@Inject(method = "<init>(II)V", at = @At("RETURN")) | ||
private void gtnhlib$debug(int width, int height, CallbackInfo ci) { | ||
if (width > 16 || height > 16) { | ||
TexturesDebug.logDynamicTexture(width, height); | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/gtnewhorizon/gtnhlib/mixins/early/debug/MixinTextureAtlasSprite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.gtnewhorizon.gtnhlib.mixins.early.debug; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.util.List; | ||
|
||
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | ||
import net.minecraft.client.resources.data.AnimationMetadataSection; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.gtnewhorizon.gtnhlib.debug.TexturesDebug; | ||
|
||
@Mixin(TextureAtlasSprite.class) | ||
public class MixinTextureAtlasSprite { | ||
|
||
@Shadow | ||
protected List<int[][]> framesTextureData; | ||
|
||
@Shadow | ||
@Final | ||
private String iconName; | ||
|
||
@Shadow | ||
protected int width; | ||
|
||
@Shadow | ||
protected int height; | ||
|
||
@Inject(method = "loadSprite", at = @At("RETURN")) | ||
private void gtnhlib$debug(BufferedImage[] buff, AnimationMetadataSection anim, boolean p_147964_3_, | ||
CallbackInfo ci) { | ||
int sizeBytes = 0; | ||
for (int[][] ints : framesTextureData) { | ||
for (int[] pixels : ints) { | ||
if (pixels != null) { | ||
sizeBytes += pixels.length * 4; | ||
} | ||
} | ||
} | ||
TexturesDebug.logTextureAtlasSprite(iconName, width, height, framesTextureData.size(), sizeBytes); | ||
} | ||
|
||
} |