Added a queue to the saving system to prevent world corruption from

chunks saving without the player. This also removes possibility for a
saving based duplication glitch. Started adding more wood items.
This commit is contained in:
jsrobson10 2020-09-22 12:11:40 +10:00
parent 8ca2fe6b91
commit 02355bfedc
33 changed files with 571 additions and 365 deletions

View File

@ -35,7 +35,7 @@ import projectzombie.settings.Environment;
import projectzombie.settings.Settings; import projectzombie.settings.Settings;
import projectzombie.time.GameTimer; import projectzombie.time.GameTimer;
import projectzombie.time.NoSleep; import projectzombie.time.NoSleep;
import projectzombie.util.FileHelpers; import projectzombie.util.SaveSystem;
import projectzombie.worker.WorkerTasks; import projectzombie.worker.WorkerTasks;
import projectzombie.worker.WorkerLighting; import projectzombie.worker.WorkerLighting;
import projectzombie.world.World; import projectzombie.world.World;
@ -108,7 +108,7 @@ public class Main
LayerGenerators.init(); LayerGenerators.init();
Recipes.init(); Recipes.init();
bdf_saves = FileHelpers.readBDF("./saves.bdf.gz"); bdf_saves = SaveSystem.readBDF("./saves.bdf.gz");
// Create the display // Create the display
window = new DisplayWindow(); window = new DisplayWindow();

View File

@ -60,6 +60,7 @@ public class EntityPlayer extends Entity implements
private Vec2i break_pos = new Vec2i(0, 0); private Vec2i break_pos = new Vec2i(0, 0);
public boolean dead = false; public boolean dead = false;
public boolean in_animation = false; public boolean in_animation = false;
public int attackedCooldown = 0;
private ArrayList<Task> tasks; private ArrayList<Task> tasks;
private Inventory inventory; private Inventory inventory;
@ -88,9 +89,8 @@ public class EntityPlayer extends Entity implements
angle = nl.get("angle").getDouble(); angle = nl.get("angle").getDouble();
temperature = nl.get("temperature").getDouble(); temperature = nl.get("temperature").getDouble();
hydration = nl.get("hydration").getDouble(); hydration = nl.get("hydration").getDouble();
in_animation = nl.get("inAnimation").getBoolean();
moving = nl.get("moving").getBoolean();
inventory_hand = nl.get("hand").getInteger(); inventory_hand = nl.get("hand").getInteger();
attackedCooldown = nl.get("attackedCooldown").getInteger();
tasks = new ArrayList<Task>(); tasks = new ArrayList<Task>();
@ -122,9 +122,8 @@ public class EntityPlayer extends Entity implements
nl.set("temperature", bdf.newObject().setDouble(temperature)); nl.set("temperature", bdf.newObject().setDouble(temperature));
nl.set("hydration", bdf.newObject().setDouble(hydration)); nl.set("hydration", bdf.newObject().setDouble(hydration));
nl.set("tasks", Task.saveTasks(bdf.newObject(), tasks.toArray(new Task[0]))); nl.set("tasks", Task.saveTasks(bdf.newObject(), tasks.toArray(new Task[0])));
nl.set("inAnimation", bdf.newObject().setBoolean(in_animation));
nl.set("moving", bdf.newObject().setBoolean(moving));
nl.set("hand", bdf.newObject().setInteger(inventory_hand)); nl.set("hand", bdf.newObject().setInteger(inventory_hand));
nl.set("attackedCooldown", bdf.newObject().setInteger(attackedCooldown));
} }
public EntityPlayer() { public EntityPlayer() {
@ -201,6 +200,10 @@ public class EntityPlayer extends Entity implements
// Call super // Call super
super.tick(chunk, layer); super.tick(chunk, layer);
if(attackedCooldown > 0) {
attackedCooldown -= 1;
}
double temp_diff = MathHelpers.biggest( double temp_diff = MathHelpers.biggest(
layer.layergen.getTemperature(layer, getPos().xz()), layer.layergen.getTemperature(layer, getPos().xz()),
chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature; chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature;
@ -210,15 +213,22 @@ public class EntityPlayer extends Entity implements
if(temperature < 0.3) { if(temperature < 0.3) {
health -= 2 * (0.3 - temperature); health -= 2 * (0.3 - temperature);
resetAttackTimer();
} }
if(temperature > 0.7) { else if(temperature > 0.7) {
health -= 4 * (temperature - 0.7); health -= 4 * (temperature - 0.7);
resetAttackTimer();
}
else if(attackedCooldown == 0 && health < health_max) {
health += 0.1;
} }
if(hydration <= 0) { if(hydration <= 0) {
hydration = 0; hydration = 0;
health -= 0.1; health -= 0.1;
resetAttackTimer();
} }
// Rotate left // Rotate left
@ -350,8 +360,12 @@ public class EntityPlayer extends Entity implements
@Override @Override
public void addDamage(double amount) { public void addDamage(double amount) {
//amount = amount / (defence_level / 2.5 + 1);
health -= amount; health -= amount;
resetAttackTimer();
}
public void resetAttackTimer() {
attackedCooldown = 3000; // Don't heal for 30 seconds
} }
@Override @Override
@ -425,7 +439,8 @@ public class EntityPlayer extends Entity implements
Model model_place = holding.item.getPlaceModel(holding); Model model_place = holding.item.getPlaceModel(holding);
Model model_spawn = holding.item.getSpawnModel(holding); Model model_spawn = holding.item.getSpawnModel(holding);
Vec2d pos = ppos.xz().add(MathHelpers.moveTowards2(1, Math.toRadians(angle))); Vec2d pos = ppos.xz().add(MathHelpers.moveTowards2(1, Math.toRadians(angle)));
boolean render_place_model = model_place != null && layer.getFrontTile(pos.toInt()).tile == Tiles.VOID; boolean render_place_model = model_place != null &&
holding.item.showPlaceModel(layer, pos.toInt(), holding);
if(render_place_model || model_spawn != null) if(render_place_model || model_spawn != null)
{ {
@ -434,13 +449,13 @@ public class EntityPlayer extends Entity implements
if(render_place_model) if(render_place_model)
{ {
model_place.setModel(Matrix4.translate(Math.floor(pos.x) - ppos.x + 0.5, 0, Math.floor(pos.y) - ppos.z + 0.5)); model_place.setModel(Matrix4.translate(Math.floor(pos.x) - ppos.x + 0.5, 0.001, Math.floor(pos.y) - ppos.z + 0.5));
model_place.render(); model_place.render();
} }
if(model_spawn != null) if(model_spawn != null)
{ {
model_spawn.setModel(Matrix4.translate(pos.x - ppos.x, 0, pos.y - ppos.z)); model_spawn.setModel(Matrix4.translate(pos.x - ppos.x, 0.001, pos.y - ppos.z));
model_spawn.render(); model_spawn.render();
} }

View File

@ -31,6 +31,7 @@ import projectzombie.items.ItemStonePick;
import projectzombie.items.ItemStoneShovel; import projectzombie.items.ItemStoneShovel;
import projectzombie.items.ItemTnt; import projectzombie.items.ItemTnt;
import projectzombie.items.ItemTorch; import projectzombie.items.ItemTorch;
import projectzombie.items.ItemWoodPlanks;
import projectzombie.items.ItemWorkbench; import projectzombie.items.ItemWorkbench;
import projectzombie.items.spawner.ItemSpawnDummy; import projectzombie.items.spawner.ItemSpawnDummy;
import projectzombie.items.spawner.ItemSpawnZombie; import projectzombie.items.spawner.ItemSpawnZombie;
@ -78,6 +79,7 @@ public class Items
register(CLAY_POT_WET); register(CLAY_POT_WET);
register(TORCH); register(TORCH);
register(COAL); register(COAL);
register(WOOD_PLANKS);
} }
public static final Item AMMO = new ItemAmmo(); public static final Item AMMO = new ItemAmmo();
@ -111,4 +113,5 @@ public class Items
public static final Item CLAY_POT_WET = new ItemClayPotWet(); public static final Item CLAY_POT_WET = new ItemClayPotWet();
public static final Item TORCH = new ItemTorch(); public static final Item TORCH = new ItemTorch();
public static final Item COAL = new ItemCoal(); public static final Item COAL = new ItemCoal();
public static final Item WOOD_PLANKS = new ItemWoodPlanks();
} }

View File

@ -18,6 +18,7 @@ import projectzombie.model.ModelTile;
import projectzombie.model.ModelTree; import projectzombie.model.ModelTree;
import projectzombie.model.ModelTreeSnow; import projectzombie.model.ModelTreeSnow;
import projectzombie.model.ModelVertical; import projectzombie.model.ModelVertical;
import projectzombie.model.ModelWall;
public class Models public class Models
{ {
@ -89,6 +90,19 @@ public class Models
public static final Model TILE_ROCK_COAL = new ModelRock(Resources.ATLAS.get("/tile/rock_coal.png")); public static final Model TILE_ROCK_COAL = new ModelRock(Resources.ATLAS.get("/tile/rock_coal.png"));
public static final Model TILE_ROCK_URANIUM = new ModelRock(Resources.ATLAS.get("/tile/rock_uranium.png")); public static final Model TILE_ROCK_URANIUM = new ModelRock(Resources.ATLAS.get("/tile/rock_uranium.png"));
public static final Model TILE_WOOD_FLOOR = new ModelTile(Resources.ATLAS.get("/tile/wood_floor.png"));
public static final Model TILE_WOOD_SNOW_FLOOR = new ModelTile(Resources.ATLAS.get("/tile/wood_snow_floor.png"));
public static final Model[] TILE_WOOD_WALL = ModelWall.rotationArray(
Resources.ATLAS.get("/tile/wood_wall_front.png"),
Resources.ATLAS.get("/tile/wood_wall_top.png"),
Resources.ATLAS.get("/tile/wood_wall_side.png"));
public static final Model[] TILE_WOOD_SNOW_WALL = ModelWall.rotationArray(
Resources.ATLAS.get("/tile/wood_snow_wall_front.png"),
Resources.ATLAS.get("/tile/wood_snow_wall_top.png"),
Resources.ATLAS.get("/tile/wood_snow_wall_side.png"));
public static final Model ENTITY_BOSS_IDLE = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_still.png"), new Vec2d(4, 4)); public static final Model ENTITY_BOSS_IDLE = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_still.png"), new Vec2d(4, 4));
public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 50); public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 50);
public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 50); public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 50);
@ -199,6 +213,10 @@ public class Models
public static final ModelItem ITEM_LOG_SNOW = new ModelItem(Resources.ATLAS.get("/item/log_snow.png")); public static final ModelItem ITEM_LOG_SNOW = new ModelItem(Resources.ATLAS.get("/item/log_snow.png"));
public static final ModelItem ITEM_CHARCOAL = new ModelItem(Resources.ATLAS.get("/item/charcoal.png")); public static final ModelItem ITEM_CHARCOAL = new ModelItem(Resources.ATLAS.get("/item/charcoal.png"));
public static final ModelItem ITEM_ASH = new ModelItem(Resources.ATLAS.get("/item/ash.png")); public static final ModelItem ITEM_ASH = new ModelItem(Resources.ATLAS.get("/item/ash.png"));
public static final ModelItem ITEM_WOOD_FLOOR = new ModelItem(Resources.ATLAS.get("/item/wood_floor.png"));
public static final ModelItem ITEM_WOOD_SNOW_FLOOR = new ModelItem(Resources.ATLAS.get("/item/wood_snow_floor.png"));
public static final ModelItem ITEM_WOOD_PLANKS = new ModelItem(Resources.ATLAS.get("/item/wood_planks.png"));
public static final ModelItem ITEM_WOOD_SNOW_PLANKS = new ModelItem(Resources.ATLAS.get("/item/wood_snow_planks.png"));
// Player varients // Player varients
public static final ModelPlayer ENTITY_PLAYER_W = new ModelPlayer( public static final ModelPlayer ENTITY_PLAYER_W = new ModelPlayer(

View File

@ -41,6 +41,13 @@ public class Recipes
// Basic crafting items // Basic crafting items
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.LOG, 1),
}, new Crafting[] {
Crafting.BASIC,
}, new ItemStack(Items.WOOD_PLANKS, 2)));
recipies.add(new RecipeBasic( recipies.add(new RecipeBasic(
new ItemStack[] { new ItemStack[] {
new ItemStack(Items.FLINT, 2), new ItemStack(Items.FLINT, 2),

View File

@ -3,10 +3,12 @@ package projectzombie.items;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i; import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.entity.Entity; import projectzombie.entity.Entity;
import projectzombie.entity.EntityHasInventory; import projectzombie.entity.EntityHasInventory;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.init.Tiles;
import projectzombie.inventory.IInventory; import projectzombie.inventory.IInventory;
import projectzombie.items.modifier.ItemModifierDamage; import projectzombie.items.modifier.ItemModifierDamage;
import projectzombie.model.Model; import projectzombie.model.Model;
@ -36,6 +38,10 @@ public abstract class Item
return null; return null;
} }
public boolean showPlaceModel(Layer layer, Vec2i pos, ItemStack stack) {
return layer.getFrontTile(pos).tile == Tiles.VOID;
}
public Model getSpawnModel(ItemStack stack) { public Model getSpawnModel(ItemStack stack) {
return null; return null;
} }

View File

@ -0,0 +1,40 @@
package projectzombie.items;
import gl_engine.vec.Vec2i;
import projectzombie.init.Models;
import projectzombie.items.modifier.ItemModifierMeta;
import projectzombie.model.Model;
import projectzombie.model.ModelItem;
import projectzombie.util.ItemStack;
import projectzombie.world.layer.Layer;
public class ItemWoodPlanks extends Item
{
@Override
public ModelItem getModel(ItemStack stack)
{
switch(ItemModifierMeta.getStackMeta(stack))
{
case 0: return Models.ITEM_WOOD_PLANKS;
case 1: return Models.ITEM_WOOD_SNOW_PLANKS;
default: return Models.ITEM_EMPTY;
}
}
@Override
public boolean showPlaceModel(Layer layer, Vec2i pos, ItemStack stack) {
return true;
}
@Override
public Model getPlaceModel(ItemStack stack) {
return Models.TILE_WOOD_FLOOR;
}
@Override
public String getName(ItemStack stack) {
return "Wood Planks";
}
}

View File

@ -21,7 +21,6 @@ import projectzombie.menu.gui.GUIContainerSlider;
import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.GUILabel;
import projectzombie.menu.gui.GUISavesCard; import projectzombie.menu.gui.GUISavesCard;
import projectzombie.model.ModelGui; import projectzombie.model.ModelGui;
import projectzombie.util.FileHelpers;
import projectzombie.worker.WorkerTasks; import projectzombie.worker.WorkerTasks;
import projectzombie.world.World; import projectzombie.world.World;

View File

@ -24,7 +24,6 @@ import projectzombie.menu.gui.GUIBackToMenu;
import projectzombie.menu.gui.GUIButtonBasic; import projectzombie.menu.gui.GUIButtonBasic;
import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.GUILabel;
import projectzombie.menu.gui.GUITextBox; import projectzombie.menu.gui.GUITextBox;
import projectzombie.util.FileHelpers;
import projectzombie.worker.WorkerTasks; import projectzombie.worker.WorkerTasks;
public class MenuWorldDelete extends Menu public class MenuWorldDelete extends Menu

View File

@ -6,7 +6,6 @@ import java.util.Random;
import bdf.types.BdfArray; import bdf.types.BdfArray;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import bdf.types.BdfReader;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.init.Models; import projectzombie.init.Models;
@ -17,7 +16,6 @@ import projectzombie.menu.gui.GUIBackToMenu;
import projectzombie.menu.gui.GUIButtonBasic; import projectzombie.menu.gui.GUIButtonBasic;
import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.GUILabel;
import projectzombie.menu.gui.GUITextBox; import projectzombie.menu.gui.GUITextBox;
import projectzombie.util.FileHelpers;
import projectzombie.worker.WorkerTasks; import projectzombie.worker.WorkerTasks;
import projectzombie.world.World; import projectzombie.world.World;

View File

@ -0,0 +1,113 @@
package projectzombie.model;
import gl_engine.texture.TextureRef3D;
public class ModelWall extends Model
{
private int rotation;
private TextureRef3D front;
private TextureRef3D side;
private TextureRef3D top;
public ModelWall(TextureRef3D front, TextureRef3D top, TextureRef3D side, int rotation) {
this.rotation = rotation;
this.front = front;
this.side = side;
this.top = top;
}
public static ModelWall[] rotationArray(TextureRef3D front, TextureRef3D top, TextureRef3D side) {
return new ModelWall[] {
new ModelWall(front, top, side, 0),
new ModelWall(front, top, side, 1),
new ModelWall(front, top, side, 2),
new ModelWall(front, top, side, 3),
};
}
@Override
public int[] getIndicies() {
return new int[] {
0, 1, 2,
2, 3, 0,
4, 5, 6,
6, 7, 4,
8, 9, 10,
10, 11, 8,
12, 13, 14,
14, 15, 12,
16, 17, 18,
18, 19, 16,
};
}
@Override
public float[] getVerticies()
{
float x1 = 0.5f, z1 = 0.5f, x2 = 0.25f, z2 = -0.5f;
return new float[]
{
x1, 0, z1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 0, z2, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 0, z1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 0, z2, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 1, z2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 1, z1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 0, z1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 0, z1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 1, z1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 0, z2, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 0, z2, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 1, z2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z2, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 1, z1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 1, z2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z2, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
};
}
@Override
public TextureRef3D[] getTextures() {
return new TextureRef3D[] {
front, front, front, front,
front, front, front, front,
side, side, side, side,
side, side, side, side,
top, top, top, top,
};
}
@Override
public double getWidth() {
return 1;
}
@Override
public double getHeight() {
return 1;
}
@Override
public int getIndexSize() {
return 30;
}
@Override
public int getSize() {
return 20;
}
}

View File

@ -1,7 +1,7 @@
package projectzombie.settings; package projectzombie.settings;
import projectzombie.util.ClassBdf; import projectzombie.util.ClassBdf;
import projectzombie.util.FileHelpers; import projectzombie.util.SaveSystem;
import projectzombie.worker.WorkerTasks; import projectzombie.worker.WorkerTasks;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
@ -122,7 +122,7 @@ public class Settings implements ClassBdf
} }
public static void init() { public static void init() {
READER = FileHelpers.readBDF("./settings.bdf.gz"); READER = SaveSystem.readBDF("./settings.bdf.gz");
SETTINGS.BdfClassLoad(READER.getObject()); SETTINGS.BdfClassLoad(READER.getObject());
} }

View File

@ -24,7 +24,7 @@ public class TileHemp extends Tile
public void tickRandomly(Layer layer, Chunk chunk, TileState state, Vec2i pos) { public void tickRandomly(Layer layer, Chunk chunk, TileState state, Vec2i pos) {
super.tickRandomly(layer, chunk, state, pos); super.tickRandomly(layer, chunk, state, pos);
if(Math.random() > 0.9) { if(Math.random() > 0.96) {
if(state.meta < 7) { if(state.meta < 7) {
layer.setFrontTile(new TileState(this, state.meta + 1), pos); layer.setFrontTile(new TileState(this, state.meta + 1), pos);
} }

View File

@ -1,37 +0,0 @@
package projectzombie.util;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
import bdf.types.BdfReader;
import projectzombie.settings.Environment;
public class FileHelpers
{
public static BdfReader readBDF(String path)
{
try
{
InputStream in = new GZIPInputStream(new FileInputStream(Environment.gdir + path));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte buffer[] = new byte[1024];
int size;
while((size = in.read(buffer)) != -1) {
out.write(buffer, 0, size);
}
in.close();
return new BdfReader(out.toByteArray());
}
catch(IOException e) {
return new BdfReader();
}
}
}

View File

@ -0,0 +1,87 @@
package projectzombie.util;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.zip.GZIPInputStream;
import bdf.types.BdfReader;
import projectzombie.Main;
import projectzombie.settings.Environment;
import projectzombie.worker.WorkerTasks;
import projectzombie.world.chunk.Chunk;
public class SaveSystem
{
private static HashMap<String, BdfReader> map = new HashMap<String, BdfReader>();
public static BdfReader readBDF(String path)
{
try
{
InputStream in = new GZIPInputStream(new FileInputStream(Environment.gdir + path));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte buffer[] = new byte[1024];
int size;
while((size = in.read(buffer)) != -1) {
out.write(buffer, 0, size);
}
in.close();
return new BdfReader(out.toByteArray());
}
catch(IOException e) {
return new BdfReader();
}
}
public synchronized static void save(String path, BdfReader reader) {
map.put(path, reader);
}
public synchronized static void saveChunk(Chunk chunk)
{
String path = Main.world.getSavePath();
if(path == null) {
return;
}
path = "./saves/" + path + "/c_" + chunk.layer.id + "_" + chunk.c_pos.x + "_" + chunk.c_pos.y + ".bdf.gz";
BdfReader reader = new BdfReader();
chunk.BdfClassSave(reader.getObject());
map.put(path, reader);
}
public synchronized static BdfReader load(String path)
{
if(map.containsKey(path)) {
return map.get(path);
}
else {
return readBDF(path);
}
}
public synchronized static void saveAll()
{
for(String path : map.keySet())
{
BdfReader reader = map.get(path);
WorkerTasks.saveToFile(path, reader);
}
map.clear();
}
}

View File

@ -4,7 +4,7 @@ import java.util.Vector;
import bdf.types.BdfReader; import bdf.types.BdfReader;
import gl_engine.vec.Vec2i; import gl_engine.vec.Vec2i;
import projectzombie.util.FileHelpers; import projectzombie.util.SaveSystem;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;
@ -29,7 +29,7 @@ public class WorkerTaskChunkLoad extends WorkerTaskChunk
String path = "./saves/" + this.path + "/c_" + layer.id + "_" + pos.x + "_" + pos.y + ".bdf.gz"; String path = "./saves/" + this.path + "/c_" + layer.id + "_" + pos.x + "_" + pos.y + ".bdf.gz";
BdfReader reader = FileHelpers.readBDF(path); BdfReader reader = SaveSystem.load(path);
Chunk chunk = new Chunk(layer, pos, reader.getObject()); Chunk chunk = new Chunk(layer, pos, reader.getObject());

View File

@ -1,54 +0,0 @@
package projectzombie.worker;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector;
import java.util.zip.GZIPOutputStream;
import bdf.types.BdfReader;
import gl_engine.vec.Vec2i;
import projectzombie.settings.Environment;
import projectzombie.util.FileHelpers;
import projectzombie.world.chunk.Chunk;
public class WorkerTaskChunkSave extends WorkerTaskChunk
{
Chunk chunk;
String path;
int id;
public WorkerTaskChunkSave(String path, Vec2i pos, Chunk chunk, int id) {
this.path = path;
this.pos = pos;
this.chunk = chunk;
this.id = id;
}
@Override
public void run()
{
if(path == null) {
return;
}
String path = "./saves/" + this.path + "/c_" + id + "_" + pos.x + "_" + pos.y + ".bdf.gz";
BdfReader reader = new BdfReader();
chunk.BdfClassSave(reader.getObject());
try
{
OutputStream out = new GZIPOutputStream(new FileOutputStream(Environment.gdir + path));
reader.serialize().writeToStream(out);
out.close();
}
catch(IOException e) {
e.printStackTrace();
}
}
}

View File

@ -25,10 +25,6 @@ public class WorkerTasks extends Thread
public static void loadChunk(String path, Layer layer, Vec2i pos) { public static void loadChunk(String path, Layer layer, Vec2i pos) {
tasks_in.add(new WorkerTaskChunkLoad(path, layer, pos.copy())); tasks_in.add(new WorkerTaskChunkLoad(path, layer, pos.copy()));
} }
public static void saveChunk(String path, Vec2i pos, Chunk chunk, int id) {
tasks_in.add(new WorkerTaskChunkSave(path, pos.copy(), chunk, id));
}
public static void saveToFile(String path, BdfReader reader) { public static void saveToFile(String path, BdfReader reader) {
tasks_in.add(new WorkerTaskFile(path, reader)); tasks_in.add(new WorkerTaskFile(path, reader));

View File

@ -9,7 +9,7 @@ import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL33; import org.lwjgl.opengl.GL33;
import projectzombie.util.ClassBdf; import projectzombie.util.ClassBdf;
import projectzombie.util.FileHelpers; import projectzombie.util.SaveSystem;
import bdf.types.BdfArray; import bdf.types.BdfArray;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
@ -62,7 +62,7 @@ public class World implements ClassBdf
} }
if(file_dir.exists()) { if(file_dir.exists()) {
BdfReader reader = FileHelpers.readBDF(path + "world.bdf.gz"); BdfReader reader = SaveSystem.load(path + "world.bdf.gz");
BdfClassLoad(reader.getObject()); BdfClassLoad(reader.getObject());
} }
} }
@ -270,10 +270,10 @@ public class World implements ClassBdf
} }
BdfReader reader = new BdfReader(); BdfReader reader = new BdfReader();
BdfObject bdf = reader.getObject(); BdfClassSave(reader.getObject());
BdfClassSave(bdf);
WorkerTasks.saveToFile("./saves/" + path + "/world.bdf.gz", reader); SaveSystem.save("./saves/" + path + "/world.bdf.gz", reader);
SaveSystem.saveAll();
} }
} }

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import projectzombie.util.ClassBdf; import projectzombie.util.ClassBdf;
import projectzombie.util.SaveSystem;
import projectzombie.util.TileState; import projectzombie.util.TileState;
import bdf.types.BdfArray; import bdf.types.BdfArray;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
@ -316,7 +317,7 @@ public class Layer implements ClassBdf
Chunk chunk = chunks.get(pos); Chunk chunk = chunks.get(pos);
if(chunk.isDirty()) if(chunk.isDirty())
{ {
WorkerTasks.saveChunk(Main.world.getSavePath(), pos, chunk, id); SaveSystem.saveChunk(chunk);
if(!hasSavedChunk(pos)) { if(!hasSavedChunk(pos)) {
chunks_saved.add(pos); chunks_saved.add(pos);
@ -405,7 +406,7 @@ public class Layer implements ClassBdf
{ {
if(chunk.o.isDirty()) if(chunk.o.isDirty())
{ {
WorkerTasks.saveChunk(Main.world.getSavePath(), chunk.pos, chunk.o, id); SaveSystem.saveChunk(chunk.o);
if(!hasSavedChunk(chunk.pos)) { if(!hasSavedChunk(chunk.pos)) {
chunks_saved.add(chunk.pos); chunks_saved.add(chunk.pos);

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -1,259 +1,274 @@
./text/char_question.png ./tile/hemp6.png
./text/char_l_a.png ./tile/rock_gold.png
./text/char_u_j.png ./tile/hemp7.png
./text/char_l_u.png ./tile/hemp1.png
./text/char_u_s.png ./tile/rock.png
./text/char_l_s.png ./tile/rock_ice.png
./text/char_apostrophe.png ./tile/sapling3.png
./text/char_plus.png ./tile/ladder.png
./text/char_l_e.png ./tile/tree_leaves_snow.png
./text/char_7.png ./tile/wood_wall_front.png
./text/char_minus.png ./tile/ice_wall.png
./text/char_u_r.png ./tile/water.png
./text/char_u_l.png ./tile/sandstone_wall.png
./text/char_obracket.png ./tile/ladder_up.png
./text/char_pow.png ./tile/rock_copper.png
./text/char_u_m.png ./tile/cactus4.png
./text/char_l_t.png ./tile/tall_grass.png
./text/char_percent.png ./tile/wood_snow_floor.png
./text/char_l_y.png ./tile/cactus2.png
./text/char_0.png ./tile/grass_infested.png
./text/char_4.png ./tile/tree_branch_leaves.png
./text/char_l_r.png ./tile/dirt.png
./text/char_l_m.png ./tile/wall.png
./text/char_cbracket.png ./tile/rock_tin.png
./text/char_u_g.png ./tile/tree_base.png
./text/char_u_q.png ./tile/cactus1.png
./text/char_u_i.png ./tile/sapling4.png
./text/char_tilde.png ./tile/hemp3.png
./text/char_l_w.png ./tile/wood_floor.png
./text/char_l_v.png ./tile/cactus_top.png
./text/char_fslash.png ./tile/tunnel_down.png
./text/char_u_p.png ./tile/stone.png
./text/char_gthan.png ./tile/snow.png
./text/char_8.png ./tile/boss_portal.png
./text/char_unknown.png ./tile/rock_coal.png
./text/char_and.png ./tile/hemp4.png
./text/char_osbracket.png ./tile/sand.png
./text/char_u_n.png ./tile/rock_iron.png
./text/char_l_i.png ./tile/lantern.png
./text/char_u_y.png ./tile/ice.png
./text/char_l_p.png ./tile/rock_uranium.png
./text/char_lthan.png ./tile/sapling1.png
./text/char_l_g.png ./tile/campfire_lit.png
./text/char_bslash.png ./tile/grass_burnt.png
./text/char_1.png ./tile/chest.png
./text/char_u_z.png ./tile/hemp2.png
./text/char_l_f.png ./tile/hemp8.png
./text/char_u_w.png ./tile/cactus3.png
./text/char_9.png ./tile/lava.png
./text/char_l_x.png ./tile/wood_wall_top.png
./text/char_ccbracket.png ./tile/tree_leaves.png
./text/char_l_o.png ./tile/hemp5.png
./text/char_equals.png ./tile/campfire_unlit.png
./text/char_l_d.png ./tile/lava_flow.png
./text/char_dollar.png ./tile/wood_snow_wall_side.png
./text/char_hashtag.png ./tile/grass.png
./text/char_l_q.png ./tile/tree_branch.png
./text/char_u_o.png ./tile/wood_snow_wall_front.png
./text/char_6.png ./tile/wood_snow_wall_top.png
./text/char_u_d.png ./tile/sandstone.png
./text/char_u_e.png ./tile/tree_branch_leaves_snow.png
./text/char_exclamation.png ./tile/rock_sandstone.png
./text/char_vertical.png ./tile/wood_wall_side.png
./text/char_ocbracket.png ./tile/sapling2.png
./text/char_u_k.png
./text/char_u_c.png
./text/char_l_n.png
./text/char_semicolon.png
./text/char_u_b.png
./text/char_u_f.png
./text/char_l_h.png
./text/char_l_k.png
./text/char_u_t.png
./text/char_3.png
./text/char_u_v.png
./text/char_u_h.png
./text/char_quotation.png
./text/char_u_a.png
./text/char_l_b.png
./text/char_underscore.png
./text/char_u_x.png
./text/char_comma.png
./text/char_csbracket.png
./text/char_l_l.png
./text/char_5.png
./text/char_star.png
./text/char_colon.png
./text/char_l_z.png
./text/char_space.png
./text/char_2.png
./text/char_at.png
./text/char_grave.png
./text/char_l_j.png
./text/char_fullstop.png
./text/char_l_c.png
./text/char_u_u.png
./list.txt ./list.txt
./player/player_white_front_moving.png ./item/rock_gold.png
./player/player_white_back_moving.png ./item/log.png
./player/player_black_back_moving.png ./item/rock.png
./player/player_black_back_still.png ./item/stone_shovel.png
./item/wood_snow_planks.png
./item/coal.png
./item/rock_copper.png
./item/acorn.png
./item/iron_pick.png
./item/clay.png
./item/stone_pick.png
./item/rock_tin.png
./item/charcoal.png
./item/ammo_box.png
./item/plant_fibre.png
./item/wood_snow_wall.png
./item/iron_hatchet.png
./item/torch_lit.png
./item/rock_iron.png
./item/stone_hatchet.png
./item/flint_hatchet.png
./item/rock_uranium.png
./item/hemp_seed.png
./item/shield_upgrade.png
./item/grappling_hook.png
./item/log_snow.png
./item/wood_planks.png
./item/iron_shovel.png
./item/wood_wall.png
./item/health_potion.png
./item/ash.png
./item/snow_pile.png
./item/torch_unlit.png
./item/gun_upgrade.png
./item/sandstone.png
./item/flint.png
./player/player_white_back_still.png ./player/player_white_back_still.png
./player/player_white_front_still.png ./player/player_white_front_still.png
./player/player_black_front_moving.png ./player/player_black_front_moving.png
./player/player_black_front_still.png ./player/player_black_front_still.png
./particle/smoke_trail.png ./player/player_black_back_moving.png
./particle/water.png ./player/player_black_back_still.png
./particle/smoke_0.png ./player/player_white_back_moving.png
./particle/smoke_1.png ./player/player_white_front_moving.png
./particle/blood.png ./gui/selection_box_wide.png
./particle/lava.png
./particle/bullet.png
./particle/smoke_2.png
./particle/snow.png
./particle/rain.png
./particle/smoke_4.png
./particle/smoke_3.png
./particle/smoke_5.png
./gui/temperature.png
./gui/slot_armor_chest.png
./gui/health_empty.png
./gui/button_hover.png
./gui/item_slot_storage.png ./gui/item_slot_storage.png
./gui/text_box.png
./gui/pixel_white.png
./gui/water.png ./gui/water.png
./gui/gun.png
./gui/selection_box_storage.png
./gui/button_delete.png
./gui/button_delete_hover.png
./gui/slot_armor_chest.png
./gui/pixel_black.png
./gui/slot_clothing_shirt.png
./gui/button_play.png
./gui/slot_armor_legs.png ./gui/slot_armor_legs.png
./gui/button_normal.png ./gui/inventory.png
./gui/label.png ./gui/label.png
./gui/hotbar.png ./gui/slot_clothing_pants.png
./gui/health_empty.png
./gui/label_recipe.png
./gui/hotbar_selected.png
./gui/health_full.png
./gui/temperature.png
./gui/button_play_hover.png
./gui/text_cursor.png
./gui/slot_armor_helmet.png ./gui/slot_armor_helmet.png
./gui/selection_box_crafting.png ./gui/selection_box_crafting.png
./gui/button_delete.png
./gui/text_cursor.png
./gui/inventory.png
./gui/button_delete_hover.png
./gui/button_play_hover.png
./gui/health_full.png
./gui/hotbar_selected.png
./gui/slot_clothing_shirt.png
./gui/selection_box_storage.png
./gui/pixel_white.png
./gui/pixel_black.png
./gui/slot_clothing_pants.png
./gui/text_box.png
./gui/shield.png
./gui/label_recipe.png
./gui/slot_clothing_boots.png ./gui/slot_clothing_boots.png
./gui/selection_box_wide.png ./gui/hotbar.png
./gui/gun.png ./gui/button_normal.png
./gui/button_play.png ./gui/shield.png
./tile/cactus4.png ./gui/button_hover.png
./tile/hemp1.png ./text/char_bslash.png
./tile/campfire_lit.png ./text/char_dollar.png
./tile/dirt.png ./text/char_l_w.png
./tile/lantern.png ./text/char_u_d.png
./tile/hemp8.png ./text/char_u_t.png
./tile/campfire_unlit.png ./text/char_space.png
./tile/rock_gold.png ./text/char_l_x.png
./tile/wall.png ./text/char_l_k.png
./tile/cactus_top.png ./text/char_6.png
./tile/cactus2.png ./text/char_unknown.png
./tile/rock.png ./text/char_comma.png
./tile/water.png ./text/char_obracket.png
./tile/hemp4.png ./text/char_u_w.png
./tile/stone.png ./text/char_7.png
./tile/tree_leaves.png ./text/char_l_f.png
./tile/sapling2.png ./text/char_vertical.png
./tile/ladder_up.png ./text/char_plus.png
./tile/sapling3.png ./text/char_u_a.png
./tile/lava_flow.png ./text/char_star.png
./tile/ice_wall.png ./text/char_9.png
./tile/rock_iron.png ./text/char_u_k.png
./tile/grass.png ./text/char_grave.png
./tile/chest.png ./text/char_u_n.png
./tile/sapling4.png ./text/char_percent.png
./tile/lava.png ./text/char_u_m.png
./tile/rock_coal.png ./text/char_exclamation.png
./tile/tall_grass.png ./text/char_1.png
./tile/rock_uranium.png ./text/char_l_q.png
./tile/rock_tin.png ./text/char_l_z.png
./tile/hemp5.png ./text/char_l_h.png
./tile/sapling1.png ./text/char_u_c.png
./tile/snow.png ./text/char_l_g.png
./tile/sandstone_wall.png ./text/char_l_s.png
./tile/rock_sandstone.png ./text/char_fullstop.png
./tile/hemp6.png ./text/char_u_j.png
./tile/cactus1.png ./text/char_l_m.png
./tile/tree_branch_leaves.png ./text/char_l_t.png
./tile/tunnel_down.png ./text/char_u_v.png
./tile/tree_branch_leaves_snow.png ./text/char_colon.png
./tile/tree_leaves_snow.png ./text/char_l_i.png
./tile/rock_ice.png ./text/char_l_y.png
./tile/boss_portal.png ./text/char_semicolon.png
./tile/ladder.png ./text/char_u_l.png
./tile/grass_burnt.png ./text/char_apostrophe.png
./tile/hemp7.png ./text/char_u_e.png
./tile/grass_infested.png ./text/char_5.png
./tile/tree_branch.png ./text/char_2.png
./tile/sand.png ./text/char_3.png
./tile/tree_base.png ./text/char_l_p.png
./tile/cactus3.png ./text/char_and.png
./tile/sandstone.png ./text/char_fslash.png
./tile/rock_copper.png ./text/char_l_u.png
./tile/hemp3.png ./text/char_u_f.png
./tile/hemp2.png ./text/char_u_u.png
./tile/ice.png ./text/char_at.png
./entity/flare.png ./text/char_l_e.png
./entity/grappling_hook.png ./text/char_l_l.png
./entity/zombie_back_moving.png ./text/char_u_g.png
./entity/tnt.png ./text/char_u_q.png
./text/char_u_b.png
./text/char_l_o.png
./text/char_csbracket.png
./text/char_osbracket.png
./text/char_minus.png
./text/char_l_v.png
./text/char_lthan.png
./text/char_u_s.png
./text/char_equals.png
./text/char_8.png
./text/char_ccbracket.png
./text/char_underscore.png
./text/char_u_x.png
./text/char_0.png
./text/char_l_d.png
./text/char_l_c.png
./text/char_l_j.png
./text/char_u_z.png
./text/char_u_h.png
./text/char_pow.png
./text/char_hashtag.png
./text/char_gthan.png
./text/char_cbracket.png
./text/char_u_i.png
./text/char_question.png
./text/char_u_o.png
./text/char_u_y.png
./text/char_l_r.png
./text/char_l_b.png
./text/char_ocbracket.png
./text/char_l_a.png
./text/char_quotation.png
./text/char_l_n.png
./text/char_u_p.png
./text/char_tilde.png
./text/char_u_r.png
./text/char_4.png
./entity/armored_zombie_back_moving.png ./entity/armored_zombie_back_moving.png
./entity/armored_zombie_front_moving.png ./entity/zombie_front_still.png
./entity/player/hair_side.png ./entity/tnt.png
./entity/player/head_top.png ./entity/flare.png
./entity/player/head_side.png ./entity/boss1/boss_walking.png
./entity/player/head_back.png
./entity/player/head_bottom.png
./entity/player/hair_front.png
./entity/player/head_front.png
./entity/player/hair_back.png
./entity/player/hair_top.png
./entity/dummy.png
./entity/armored_zombie_front_still.png
./entity/armored_zombie_back_still.png
./entity/zombie_front_moving.png
./entity/boss1/boss_walking_firing.png
./entity/boss1/boss_firing.png ./entity/boss1/boss_firing.png
./entity/boss1/boss_still.png ./entity/boss1/boss_still.png
./entity/boss1/boss_walking.png ./entity/boss1/boss_walking_firing.png
./entity/armored_zombie_back_still.png
./entity/armored_zombie_front_moving.png
./entity/player/head_back.png
./entity/player/hair_top.png
./entity/player/head_front.png
./entity/player/head_top.png
./entity/player/hair_side.png
./entity/player/head_side.png
./entity/player/hair_back.png
./entity/player/hair_front.png
./entity/player/head_bottom.png
./entity/grappling_hook.png
./entity/zombie_back_still.png ./entity/zombie_back_still.png
./entity/zombie_front_still.png ./entity/dummy.png
./item/acorn.png ./entity/zombie_back_moving.png
./item/clay.png ./entity/armored_zombie_front_still.png
./item/stone_hatchet.png ./entity/zombie_front_moving.png
./item/grappling_hook.png ./particle/smoke_1.png
./item/gun_upgrade.png ./particle/water.png
./item/shield_upgrade.png ./particle/rain.png
./item/rock_gold.png ./particle/blood.png
./item/rock.png ./particle/snow.png
./item/flint_hatchet.png ./particle/smoke_3.png
./item/rock_iron.png ./particle/smoke_4.png
./item/log.png ./particle/smoke_2.png
./item/ash.png ./particle/smoke_0.png
./item/charcoal.png ./particle/bullet.png
./item/torch_unlit.png ./particle/lava.png
./item/log_snow.png ./particle/smoke_trail.png
./item/hemp_seed.png ./particle/smoke_5.png
./item/stone_shovel.png
./item/rock_uranium.png
./item/rock_tin.png
./item/ammo_box.png
./item/plant_fibre.png
./item/health_potion.png
./item/snow_pile.png
./item/coal.png
./item/flint.png
./item/sandstone.png
./item/rock_copper.png
./item/stone_pick.png
./item/torch_lit.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B