Allow disabling paletted hunks

This commit is contained in:
cyberpwn 2021-09-23 05:50:38 -04:00
parent 846b4faefa
commit ecc09a710a
6 changed files with 14 additions and 42 deletions

View File

@ -54,7 +54,6 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
} }
protected IrisObject loadFile(File j, String name) { protected IrisObject loadFile(File j, String name) {
lock.lock();
try { try {
PrecisionStopwatch p = PrecisionStopwatch.start(); PrecisionStopwatch p = PrecisionStopwatch.start();
IrisObject t = new IrisObject(0, 0, 0); IrisObject t = new IrisObject(0, 0, 0);
@ -63,12 +62,10 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
t.setLoader(manager); t.setLoader(manager);
t.setLoadFile(j); t.setLoadFile(j);
logLoad(j, t); logLoad(j, t);
lock.unlock();
tlt.addAndGet(p.getMilliseconds()); tlt.addAndGet(p.getMilliseconds());
return t; return t;
} catch (Throwable e) { } catch (Throwable e) {
Iris.reportError(e); Iris.reportError(e);
lock.unlock();
Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage()); Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage());
return null; return null;
} }
@ -108,11 +105,9 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
} }
public File findFile(String name) { public File findFile(String name) {
lock.lock();
for (File i : getFolders(name)) { for (File i : getFolders(name)) {
for (File j : i.listFiles()) { for (File j : i.listFiles()) {
if (j.isFile() && j.getName().endsWith(".iob") && j.getName().split("\\Q.\\E")[0].equals(name)) { if (j.isFile() && j.getName().endsWith(".iob") && j.getName().split("\\Q.\\E")[0].equals(name)) {
lock.unlock();
return j; return j;
} }
} }
@ -120,14 +115,12 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
File file = new File(i, name + ".iob"); File file = new File(i, name + ".iob");
if (file.exists()) { if (file.exists()) {
lock.unlock();
return file; return file;
} }
} }
Iris.warn("Couldn't find " + resourceTypeName + ": " + name); Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
lock.unlock();
return null; return null;
} }
@ -136,11 +129,9 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
} }
private IrisObject loadRaw(String name){ private IrisObject loadRaw(String name){
lock.lock();
for (File i : getFolders(name)) { for (File i : getFolders(name)) {
for (File j : i.listFiles()) { for (File j : i.listFiles()) {
if (j.isFile() && j.getName().endsWith(".iob") && j.getName().split("\\Q.\\E")[0].equals(name)) { if (j.isFile() && j.getName().endsWith(".iob") && j.getName().split("\\Q.\\E")[0].equals(name)) {
lock.unlock();
return loadFile(j, name); return loadFile(j, name);
} }
} }
@ -148,14 +139,12 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
File file = new File(i, name + ".iob"); File file = new File(i, name + ".iob");
if (file.exists()) { if (file.exists()) {
lock.unlock();
return loadFile(file, name); return loadFile(file, name);
} }
} }
Iris.warn("Couldn't find " + resourceTypeName + ": " + name); Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
lock.unlock();
return null; return null;
} }

View File

@ -56,14 +56,12 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
protected KList<File> folderCache; protected KList<File> folderCache;
protected Class<? extends T> objectClass; protected Class<? extends T> objectClass;
protected String cname; protected String cname;
protected IrisLock lock;
protected String[] possibleKeys = null; protected String[] possibleKeys = null;
protected IrisData manager; protected IrisData manager;
protected AtomicInteger loads; protected AtomicInteger loads;
protected ChronoLatch sec; protected ChronoLatch sec;
public ResourceLoader(File root, IrisData manager, String folderName, String resourceTypeName, Class<? extends T> objectClass) { public ResourceLoader(File root, IrisData manager, String folderName, String resourceTypeName, Class<? extends T> objectClass) {
lock = new IrisLock("Res");
this.manager = manager; this.manager = manager;
sec = new ChronoLatch(5000); sec = new ChronoLatch(5000);
loads = new AtomicInteger(); loads = new AtomicInteger();
@ -95,11 +93,9 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
} }
public File findFile(String name) { public File findFile(String name) {
lock.lock();
for (File i : getFolders(name)) { for (File i : getFolders(name)) {
for (File j : i.listFiles()) { for (File j : i.listFiles()) {
if (j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(name)) { if (j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(name)) {
lock.unlock();
return j; return j;
} }
} }
@ -107,14 +103,12 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
File file = new File(i, name + ".json"); File file = new File(i, name + ".json");
if (file.exists()) { if (file.exists()) {
lock.unlock();
return file; return file;
} }
} }
Iris.warn("Couldn't find " + resourceTypeName + ": " + name); Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
lock.unlock();
return null; return null;
} }
@ -195,12 +189,10 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
t.setLoader(manager); t.setLoader(manager);
getManager().preprocessObject(t); getManager().preprocessObject(t);
logLoad(j, t); logLoad(j, t);
lock.unlock();
tlt.addAndGet(p.getMilliseconds()); tlt.addAndGet(p.getMilliseconds());
return t; return t;
} catch (Throwable e) { } catch (Throwable e) {
Iris.reportError(e); Iris.reportError(e);
lock.unlock();
failLoad(j, e); failLoad(j, e);
return null; return null;
} }
@ -248,7 +240,6 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
private T loadRaw(String name) private T loadRaw(String name)
{ {
lock.lock();
for (File i : getFolders(name)) { for (File i : getFolders(name)) {
//noinspection ConstantConditions //noinspection ConstantConditions
for (File j : i.listFiles()) { for (File j : i.listFiles()) {
@ -264,7 +255,6 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
} }
} }
lock.unlock();
return null; return null;
} }
@ -281,7 +271,6 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
} }
public KList<File> getFolders() { public KList<File> getFolders() {
lock.lock();
if (folderCache == null) { if (folderCache == null) {
folderCache = new KList<>(); folderCache = new KList<>();
@ -295,8 +284,6 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
} }
} }
lock.unlock();
if (folderCache == null) { if (folderCache == null) {
synchronized (this) { synchronized (this) {
return getFolderCache(); return getFolderCache();
@ -321,11 +308,9 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
} }
public void clearCache() { public void clearCache() {
lock.lock();
possibleKeys = null; possibleKeys = null;
loadCache.invalidate(); loadCache.invalidate();
folderCache = null; folderCache = null;
lock.unlock();
} }
public File fileFor(T b) { public File fileFor(T b) {
@ -351,10 +336,8 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
} }
public void clearList() { public void clearList() {
lock.lock();
folderCache = null; folderCache = null;
possibleKeys = null; possibleKeys = null;
lock.unlock();
} }
public KList<String> getPossibleKeys(String arg) { public KList<String> getPossibleKeys(String arg) {

View File

@ -44,7 +44,6 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
} }
protected IrisScript loadFile(File j, String name) { protected IrisScript loadFile(File j, String name) {
lock.lock();
try { try {
PrecisionStopwatch p = PrecisionStopwatch.start(); PrecisionStopwatch p = PrecisionStopwatch.start();
IrisScript t = new IrisScript(IO.readAll(j)); IrisScript t = new IrisScript(IO.readAll(j));
@ -52,12 +51,10 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
t.setLoader(manager); t.setLoader(manager);
t.setLoadFile(j); t.setLoadFile(j);
logLoad(j, t); logLoad(j, t);
lock.unlock();
tlt.addAndGet(p.getMilliseconds()); tlt.addAndGet(p.getMilliseconds());
return t; return t;
} catch (Throwable e) { } catch (Throwable e) {
Iris.reportError(e); Iris.reportError(e);
lock.unlock();
Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage()); Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage());
return null; return null;
} }
@ -97,11 +94,9 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
} }
public File findFile(String name) { public File findFile(String name) {
lock.lock();
for (File i : getFolders(name)) { for (File i : getFolders(name)) {
for (File j : i.listFiles()) { for (File j : i.listFiles()) {
if (j.isFile() && j.getName().endsWith(".js") && j.getName().split("\\Q.\\E")[0].equals(name)) { if (j.isFile() && j.getName().endsWith(".js") && j.getName().split("\\Q.\\E")[0].equals(name)) {
lock.unlock();
return j; return j;
} }
} }
@ -109,24 +104,20 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
File file = new File(i, name + ".js"); File file = new File(i, name + ".js");
if (file.exists()) { if (file.exists()) {
lock.unlock();
return file; return file;
} }
} }
Iris.warn("Couldn't find " + resourceTypeName + ": " + name); Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
lock.unlock();
return null; return null;
} }
private IrisScript loadRaw(String name) private IrisScript loadRaw(String name)
{ {
lock.lock();
for (File i : getFolders(name)) { for (File i : getFolders(name)) {
for (File j : i.listFiles()) { for (File j : i.listFiles()) {
if (j.isFile() && j.getName().endsWith(".js") && j.getName().split("\\Q.\\E")[0].equals(name)) { if (j.isFile() && j.getName().endsWith(".js") && j.getName().split("\\Q.\\E")[0].equals(name)) {
lock.unlock();
return loadFile(j, name); return loadFile(j, name);
} }
} }
@ -134,14 +125,12 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
File file = new File(i, name + ".js"); File file = new File(i, name + ".js");
if (file.exists()) { if (file.exists()) {
lock.unlock();
return loadFile(file, name); return loadFile(file, name);
} }
} }
Iris.warn("Couldn't find " + resourceTypeName + ": " + name); Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
lock.unlock();
return null; return null;
} }

View File

@ -399,6 +399,17 @@ public class B {
public static BlockData getOrNull(String bdxf) { public static BlockData getOrNull(String bdxf) {
try { try {
String bd = bdxf.trim(); String bd = bdxf.trim();
if(bd.startsWith("minecraft:cauldron[level="))
{
bd = bd.replaceAll("\\Q:cauldron[\\E", ":water_cauldron[");
}
if(bd.equals("minecraft:grass_path"))
{
return DIRT_PATH.createBlockData();
}
BlockData bdx = parseBlockData(bd); BlockData bdx = parseBlockData(bd);
if (bdx == null) { if (bdx == null) {

View File

@ -29,9 +29,9 @@ import java.util.function.Supplier;
public class PaletteOrHunk<T> extends StorageHunk<T> implements Hunk<T> { public class PaletteOrHunk<T> extends StorageHunk<T> implements Hunk<T> {
private final Hunk<T> hunk; private final Hunk<T> hunk;
public PaletteOrHunk(int width, int height, int depth, Supplier<Hunk<T>> factory) { public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory) {
super(width, height, depth); super(width, height, depth);
hunk = width == 16 && height == 16 && depth == 16 ? new PaletteHunk<>() : factory.get(); hunk = (width == 16 && height == 16 && depth == 16 && allow) ? new PaletteHunk<>() : factory.get();
} }
public PalettedContainer<T> palette() public PalettedContainer<T> palette()

View File

@ -37,7 +37,7 @@ public abstract class RawMatter<T> extends PaletteOrHunk<T> implements MatterSli
private final Class<T> type; private final Class<T> type;
public RawMatter(int width, int height, int depth, Class<T> type) { public RawMatter(int width, int height, int depth, Class<T> type) {
super(width, height, depth, () -> new MappedHunk<>(width, height, depth)); super(width, height, depth, true, () -> new MappedHunk<>(width, height, depth));
writers = new KMap<>(); writers = new KMap<>();
readers = new KMap<>(); readers = new KMap<>();
this.type = type; this.type = type;