Begin refactoring mod sprite packing

This commit is contained in:
Anuken
2026-09-21 15:15:33 -04:00
parent 6a9b816f84
commit 13597bc402
19 changed files with 33 additions and 64 deletions
@@ -160,15 +160,15 @@ public abstract class UnlockableContent extends MappableContent{
* No regions are loaded at this point; grab pixmaps from the packer.
* */
@CallSuper
public void createIcons(MultiPacker packer){
public void packSprites(PackContext packer){
}
protected void makeOutline(MultiPacker packer, TextureRegion region, boolean makeNew, Color outlineColor, int outlineRadius){
protected void makeOutline(PackContext packer, TextureRegion region, boolean makeNew, Color outlineColor, int outlineRadius){
makeOutline(packer, region, makeNew, outlineColor, outlineRadius, 0);
}
protected void makeOutline(MultiPacker packer, TextureRegion region, boolean makeNew, Color outlineColor, int outlineRadius, int padding){
protected void makeOutline(PackContext packer, TextureRegion region, boolean makeNew, Color outlineColor, int outlineRadius, int padding){
if(region instanceof AtlasRegion at && region.found()){
String name = at.name;
if(!makeNew || !packer.has(name + "-outline")){
@@ -184,7 +184,7 @@ public abstract class UnlockableContent extends MappableContent{
}
}
protected void makeOutline(MultiPacker packer, TextureRegion region, String name, Color outlineColor, int outlineRadius){
protected void makeOutline(PackContext packer, TextureRegion region, String name, Color outlineColor, int outlineRadius){
if(region.found() && packer.registerOutlined(name)){
PixmapRegion base = packer.get(region);
var result = Pixmaps.outline(base, outlineColor, outlineRadius);
@@ -194,7 +194,7 @@ public abstract class UnlockableContent extends MappableContent{
}
}
protected void makeOutline(MultiPacker packer, TextureRegion region, String name, Color outlineColor){
protected void makeOutline(PackContext packer, TextureRegion region, String name, Color outlineColor){
makeOutline(packer, region, name, outlineColor, 4);
}
+4 -4
View File
@@ -6,7 +6,7 @@ import arc.util.*;
import mindustry.core.GameState.*;
import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.graphics.MultiPacker;
import mindustry.graphics.PackContext;
import mindustry.mod.data.*;
import mindustry.net.*;
import mindustry.net.Packets.*;
@@ -88,10 +88,10 @@ public class EventType{
public static class ContentInitEvent{}
/** Called *after* all content has been added to the atlas, but before its pixmaps are disposed. */
public static class AtlasPackEvent{
public final MultiPacker multiPacker;
public final PackContext packContext;
public AtlasPackEvent(MultiPacker multiPacker){
this.multiPacker = multiPacker;
public AtlasPackEvent(PackContext packContext){
this.packContext = packContext;
}
}
/** Called *after* all mod content has been loaded, but before it has been initialized. */
@@ -7,12 +7,11 @@ import arc.struct.*;
import arc.util.*;
import arc.util.Log.*;
//TODO: this needs to pack to a texture array
public class MultiPacker implements Disposable{
public class PackContext implements Disposable{
private PixmapPacker packer;
private ObjectSet<String> outlined = new ObjectSet<>();
public MultiPacker(int size){
public PackContext(int size){
if(size > 0){
packer = new PixmapPacker(size, size, 2, true);
}
+2 -2
View File
@@ -80,7 +80,7 @@ public class DataManager{
UnlockableContent[] currentContent = {null};
String[] currentHash = {null};
MultiPacker saver = new MultiPacker(0){
PackContext saver = new PackContext(0){
@Override
public void add(String name, PixmapRegion region, int[] splits, int[] pads){
try{
@@ -137,7 +137,7 @@ public class DataManager{
currentHash[0] = hashes.get(content);
try{
content.createIcons(saver);
content.packSprites(saver);
}catch(Throwable e){
Log.err(e);
}
+1 -1
View File
@@ -28,7 +28,7 @@ public abstract class Mod{
}
/** Called during sprite packing to allow adding custom textures */
public void packSprites(MultiPacker packer){
public void packSprites(PackContext packer){
}
+3 -3
View File
@@ -156,7 +156,7 @@ public class Mods implements Loadable{
long startTime = Time.millis();
//TODO this should estimate sprite sizes per page
MultiPacker packer = new MultiPacker(4096);
PackContext packer = new PackContext(4096);
var textureResize = new ObjectFloatMap<String>();
int[] totalSprites = {0};
//all packing tasks to await
@@ -244,7 +244,7 @@ public class Mods implements Loadable{
u.load();
u.loadIcon();
if(u.generateIcons && !c.minfo.mod.meta.pregenerated){
u.createIcons(packer);
u.packSprites(packer);
}
}
});
@@ -301,7 +301,7 @@ public class Mods implements Loadable{
}
}
private void packSprites(MultiPacker packer, Seq<Fi> sprites, LoadedMod mod, boolean prefix, Seq<Future<Runnable>> tasks, ObjectFloatMap<String> textureResize){
private void packSprites(PackContext packer, Seq<Fi> sprites, LoadedMod mod, boolean prefix, Seq<Future<Runnable>> tasks, ObjectFloatMap<String> textureResize){
boolean bleed = Core.settings.getBool("linear", true) && !mod.meta.pregenerated;
float textureScale = mod.meta.texturescale;
+2 -2
View File
@@ -119,8 +119,8 @@ public class Item extends UnlockableContent implements Senseable{
}
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);
public void packSprites(PackContext packer){
super.packSprites(packer);
//create transitions
if(frames > 0 && transitionFrames > 0){
+2 -2
View File
@@ -119,8 +119,8 @@ public class SectorPreset extends UnlockableContent{
}
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);
public void packSprites(PackContext packer){
super.packSprites(packer);
if(outline && Core.atlas.has("sector-" + name)){
makeOutline(packer, Core.atlas.find("sector-" + name), false, outlineColor, outlineRadius, outlineRadius);
+2 -2
View File
@@ -231,8 +231,8 @@ public class StatusEffect extends UnlockableContent{
}
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);
public void packSprites(PackContext packer){
super.packSprites(packer);
if(outline){
makeOutline(packer, uiIcon, false, Pal.gray, 3);
+2 -2
View File
@@ -1219,8 +1219,8 @@ public class UnitType extends UnlockableContent implements Senseable{
}
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);
public void packSprites(PackContext packer){
super.packSprites(packer);
if(constructor == null) throw new IllegalArgumentException("No constructor set up for unit '" + name + "', add this argument to your units field: `constructor = UnitEntity::create`");
+2 -7
View File
@@ -977,11 +977,6 @@ public class Block extends UnlockableContent implements Senseable{
}
}
/** @return special icons to outline and save with an -outline variant. Vanilla only. */
public TextureRegion[] makeIconRegions(){
return new TextureRegion[0];
}
protected TextureRegion[] icons(){
//use team region in vanilla team blocks
TextureRegion r = variants > 0 ? Core.atlas.find(name + "1") : region;
@@ -1551,8 +1546,8 @@ public class Block extends UnlockableContent implements Senseable{
}
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);
public void packSprites(PackContext packer){
super.packSprites(packer);
if(!synthetic()){
PixmapRegion image = packer.get(fullIcon);
@@ -221,8 +221,8 @@ public class Floor extends Block{
}
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);
public void packSprites(PackContext packer){
super.packSprites(packer);
if(blendGroup != this){
return;
@@ -41,7 +41,7 @@ public class OreBlock extends OverlayFloor{
@Override
@OverrideCallSuper
public void createIcons(MultiPacker packer){
public void packSprites(PackContext packer){
for(int i = 0; i < variants; i++){
//use name (e.g. "ore-copper1"), fallback to "copper1" as per the old naming system
PixmapRegion shadow = Core.atlas.has(name + (i + 1)) ?
@@ -30,7 +30,7 @@ public class ShallowLiquid extends Floor{
}
@Override
public void createIcons(MultiPacker packer){
public void packSprites(PackContext packer){
//TODO might not be necessary at all, but I am not sure yet
//super.createIcons(packer);