Skip to content

Commit

Permalink
Removed dungeons from RAM
Browse files Browse the repository at this point in the history
- Made Schematics load into RAM as byte arrays at the start of game instead of as NBT (saves +- 1GB of RAM) (SH)
- Added checks for non-default schematics to make sure they contain valid NBT at game start (SH)
- Made sure that invalid templates/schematics aren't even added to the array (SH)
- Made sure that PocketTemplate loads Schematic from byte array before it tries to place it (PT)
- Made sure that PocketTemplate unloads Schematic after placinf it (PT)
- Made sure that TileEntityRift doesn't check its Location while PocketTemplate is replacing placeholders in Schematics (otherwise it will try to use null worlds and shizzle) (TER and PT)
- Added functionality when saving a Schematic, this should put the Schematic in memory as a byte array (SH)

- Fixed little bug, where Schematics that would be too big, would only be loaded when configured not to (SH)

- Added functionality to keep the Schematics that are placed most loaded in RAM as NBT (combination of usageList and usageMap) (SH and PT)
- Added config option to set the maximum number of Schematics that will be cached as NBT (MC and SH)

- Made sure that Dimdoors.log is consistently used (SH)

- Added check for .json file extension for files in the json config folder (SH)

- Schematic files in the jar have had the .schem extension for a while now. Generalised a bit. (SH)
  • Loading branch information
Robijnvogel committed Jun 18, 2018
1 parent d905340 commit 5b84baf
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 34 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/dimdev/dimdoors/shared/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public static class Pockets {
@Name("loadAllSchematics")
@LangKey("dimdoors.pockets.loadAllSchematics")
public boolean loadAllSchematics = false;

@Name("cachedSchematics")
@LangKey("dimdoors.pockets.cachedSchematics") //TODO add lang key to lang file
public int cachedSchematics = 10;
}

public static class World {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static Pocket generatePocketFromTemplate(int dim, PocketTemplate pocketTe

PocketRegistry registry = PocketRegistry.instance(dim);
Pocket pocket = registry.newPocket();
pocketTemplate.place(pocket);
pocketTemplate.place(pocket, setup);
pocket.setVirtualLocation(virtualLocation);
if (setup) pocketTemplate.setup(pocket, null, null);
return pocket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public class PocketTemplate {
@Getter private final String name;
@Getter private final String author;
@Getter @Setter private Schematic schematic;
@Setter private byte[] schematicBytecode;
@Getter private final int size; // number of chunks (16 blocks) on each side - 1
@Getter private final int baseWeight;
@Getter private static boolean isReplacingPlaceholders = false;

public float getWeight(int depth) {
//noinspection IfStatementWithIdenticalBranches
Expand All @@ -59,6 +61,7 @@ public float getWeight(int depth) {

public static void replacePlaceholders(Schematic schematic) { // TODO: rift inheritance rather than placeholders
// Replace placeholders (some schematics will contain them)
isReplacingPlaceholders = true;
List<NBTTagCompound> tileEntities = new ArrayList<>();
for (NBTTagCompound tileEntityNBT : schematic.tileEntities) {
if (tileEntityNBT.hasKey("placeholder")) {
Expand Down Expand Up @@ -149,20 +152,34 @@ public static void replacePlaceholders(Schematic schematic) { // TODO: rift inhe
}
}
schematic.entities = entities;
isReplacingPlaceholders = false;
}

public void place(Pocket pocket) {
public void place(Pocket pocket, boolean setup) {
pocket.setSize(size);
int gridSize = PocketRegistry.instance(pocket.getDim()).getGridSize();
int dim = pocket.getDim();
WorldServer world = WorldUtils.getWorld(dim);
int xBase = pocket.getX() * gridSize * 16;
int yBase = 0;
int zBase = pocket.getZ() * gridSize * 16;

//Converting the schematic from bytearray if needed
if (schematic == null) {
DimDoors.log.debug("Schematic is null, trying to reload from byteArray.");
schematic = SchematicHandler.INSTANCE.loadSchematicFromByteArray(schematicBytecode);
replacePlaceholders(schematic);
}

// Place the schematic
//Place the schematic
DimDoors.log.info("Placing new pocket using schematic " + id + " at x = " + xBase + ", z = " + zBase);
schematic.place(world, xBase, yBase, zBase);

SchematicHandler.INSTANCE.incrementUsage(this);
if (!setup && !SchematicHandler.INSTANCE.isUsedOftenEnough(this)) {
//remove schematic from "cache"
schematic = null;
}
}

public void setup(Pocket pocket, VirtualTarget linkTo, LinkProperties linkProperties) {
Expand Down Expand Up @@ -258,5 +275,10 @@ public void setup(Pocket pocket, VirtualTarget linkTo, LinkProperties linkProper
rift.register();
rift.markDirty();
}

if (!SchematicHandler.INSTANCE.isUsedOftenEnough(this)) {
//remove schematic from "cache"
schematic = null;
}
}
}
Loading

0 comments on commit 5b84baf

Please sign in to comment.