diff --git a/.gitignore b/.gitignore index 58bb19b..da45aaa 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ html/war/WEB-INF/classes/ gwt-unitCache/ www-test/ .gwt-tmp/ - +game.config ## Android Studio and Intellij and Android in general android/libs/armeabi/ android/libs/armeabi-v7a/ diff --git a/core/assets/db/entities/barell.json b/core/assets/db/entities/barell.json index 7a4b161..9875db0 100644 --- a/core/assets/db/entities/barell.json +++ b/core/assets/db/entities/barell.json @@ -8,7 +8,7 @@ }, { class: "renderable", - path: "raw-models/barell.g3db" + path: "graphics/models/barell.g3db" }, { diff --git a/core/assets/db/entities/crate.json b/core/assets/db/entities/crate.json index 93e2b15..7f5ff45 100644 --- a/core/assets/db/entities/crate.json +++ b/core/assets/db/entities/crate.json @@ -8,7 +8,7 @@ }, { class: "renderable", - path: "raw-models/Crate.g3db" + path: "graphics/models/Crate.g3db" }, { diff --git a/core/assets/db/entities/ham.json b/core/assets/db/entities/ham.json index 084f2b1..9c2da2b 100644 --- a/core/assets/db/entities/ham.json +++ b/core/assets/db/entities/ham.json @@ -8,7 +8,7 @@ }, { class: "renderable", - path: "raw-models/Ham.g3db" + path: "graphics/models/Ham.g3db" }, { diff --git a/core/assets/graphics/models/Barrel texture.png b/core/assets/graphics/models/Barrel texture.png new file mode 100644 index 0000000..320d7c8 Binary files /dev/null and b/core/assets/graphics/models/Barrel texture.png differ diff --git a/core/assets/graphics/models/Crate Texture.png b/core/assets/graphics/models/Crate Texture.png new file mode 100644 index 0000000..17169ea Binary files /dev/null and b/core/assets/graphics/models/Crate Texture.png differ diff --git a/core/assets/graphics/models/Crate.g3db b/core/assets/graphics/models/Crate.g3db new file mode 100644 index 0000000..f5c399e Binary files /dev/null and b/core/assets/graphics/models/Crate.g3db differ diff --git a/core/assets/graphics/models/Ham Texture.png b/core/assets/graphics/models/Ham Texture.png new file mode 100644 index 0000000..5ebf207 Binary files /dev/null and b/core/assets/graphics/models/Ham Texture.png differ diff --git a/core/assets/graphics/models/Ham.g3db b/core/assets/graphics/models/Ham.g3db new file mode 100644 index 0000000..bf5182f Binary files /dev/null and b/core/assets/graphics/models/Ham.g3db differ diff --git a/core/assets/graphics/models/barell.g3db b/core/assets/graphics/models/barell.g3db new file mode 100644 index 0000000..896c082 Binary files /dev/null and b/core/assets/graphics/models/barell.g3db differ diff --git a/core/src/macbury/forge/db/GameDatabase.java b/core/src/macbury/forge/db/GameDatabase.java index fee0ad0..a8fcd49 100644 --- a/core/src/macbury/forge/db/GameDatabase.java +++ b/core/src/macbury/forge/db/GameDatabase.java @@ -1,21 +1,30 @@ package macbury.forge.db; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; +import com.esotericsoftware.kryo.Kryo; +import com.esotericsoftware.kryo.io.Input; +import com.esotericsoftware.kryo.io.Output; import macbury.forge.ForgE; -import macbury.forge.db.models.PlayerStartPosition; +import macbury.forge.db.models.BaseModel; +import macbury.forge.db.models.Teleport; import macbury.forge.utils.Vector3i; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; + /** * Created by macbury on 07.11.14. */ public class GameDatabase { - public static final String FILE_NAME = "game.db"; + public static final String FILE_NAME = "db/game.config"; private static final String TAG = "GameDatabase"; public String title; public int currentyUID = 0; public long build = 0; public int lastOpenedMapId = -1; - public PlayerStartPosition startPosition; + public Teleport startPosition; + /** * Create int uuid * @return unique id @@ -34,11 +43,21 @@ public void bootstrap() { public void setStartPosition(int levelId, Vector3i voxelPosition) { Gdx.app.log(TAG, "New player start position: " + levelId + " at " + voxelPosition.toString()); - startPosition = new PlayerStartPosition(); - startPosition.mapId = levelId; - startPosition.voxelPosition = new Vector3i(voxelPosition); + this.startPosition = new Teleport(voxelPosition, levelId); + save(); + } - ForgE.storage.saveDB(this); + public void save(BaseModel model) { + Kryo kryo = ForgE.storage.begin(); { + FileHandle modelFile = model.getFileHandle(); + try { + Output output = new Output(new FileOutputStream(modelFile.file(), false)); + kryo.writeObject(output, model); + output.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } ForgE.storage.end(kryo); } public void save() { diff --git a/core/src/macbury/forge/db/models/BaseModel.java b/core/src/macbury/forge/db/models/BaseModel.java new file mode 100644 index 0000000..8bc1573 --- /dev/null +++ b/core/src/macbury/forge/db/models/BaseModel.java @@ -0,0 +1,18 @@ +package macbury.forge.db.models; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; + +/** + * Created by macbury on 11.05.15. + */ +public abstract class BaseModel { + private static final String DB_PATH = "db/"; + + public abstract String getFilename(); + public abstract String getStorageDir(); + + public FileHandle getFileHandle() { + return Gdx.files.internal(DB_PATH+ getStorageDir() + getFilename()); + } +} diff --git a/core/src/macbury/forge/db/models/PlayerStartPosition.java b/core/src/macbury/forge/db/models/PlayerStartPosition.java deleted file mode 100644 index 8f71cee..0000000 --- a/core/src/macbury/forge/db/models/PlayerStartPosition.java +++ /dev/null @@ -1,16 +0,0 @@ -package macbury.forge.db.models; - -import com.badlogic.gdx.math.Vector3; -import macbury.forge.utils.Vector3i; - -/** - * Created by macbury on 24.03.15. - */ -public class PlayerStartPosition { - public Vector3i voxelPosition; - public int mapId; - - public Teleport toTeleport() { - return new Teleport(voxelPosition, mapId); - } -} diff --git a/core/src/macbury/forge/db/models/Teleport.java b/core/src/macbury/forge/db/models/Teleport.java index 2d892e4..e53fcde 100644 --- a/core/src/macbury/forge/db/models/Teleport.java +++ b/core/src/macbury/forge/db/models/Teleport.java @@ -5,12 +5,13 @@ /** * Created by macbury on 24.03.15. */ -public class Teleport { +public class Teleport { public final Vector3i voxelPosition; public final int mapId; public Teleport(Vector3i voxelPosition, int mapId) { - this.voxelPosition = voxelPosition; + this.voxelPosition = new Vector3i(voxelPosition); this.mapId = mapId; } + } diff --git a/core/src/macbury/forge/screens/LoadingScreen.java b/core/src/macbury/forge/screens/LoadingScreen.java index 3ac9f7d..5fb8b53 100644 --- a/core/src/macbury/forge/screens/LoadingScreen.java +++ b/core/src/macbury/forge/screens/LoadingScreen.java @@ -11,7 +11,6 @@ import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.PerformanceCounter; import macbury.forge.ForgE; -import macbury.forge.db.models.PlayerStartPosition; import macbury.forge.db.models.Teleport; import macbury.forge.level.loader.AsyncLevelLoader; import macbury.forge.level.Level; @@ -37,10 +36,6 @@ public class LoadingScreen extends AbstractScreen implements Promise { private Matrix4 boxTransMat; private float indicatorRotation; - public LoadingScreen(PlayerStartPosition startPosition) { - this(startPosition.toTeleport()); - } - public LoadingScreen(Teleport teleport) { super(); this.teleport = teleport; diff --git a/core/src/macbury/forge/storage/StorageManager.java b/core/src/macbury/forge/storage/StorageManager.java index 1cc65d3..e7a83d6 100644 --- a/core/src/macbury/forge/storage/StorageManager.java +++ b/core/src/macbury/forge/storage/StorageManager.java @@ -18,7 +18,7 @@ import macbury.forge.assets.assets.ModelAsset; import macbury.forge.assets.assets.TextureAsset; import macbury.forge.db.GameDatabase; -import macbury.forge.db.models.PlayerStartPosition; +import macbury.forge.db.models.Teleport; import macbury.forge.graphics.batch.renderable.VoxelChunkRenderable; import macbury.forge.level.LevelEnv; import macbury.forge.level.LevelState; @@ -62,7 +62,7 @@ public Kryo create () { kryo.register(VoxelChunkRenderable.class, new VoxelFaceRenderableSerializer()); kryo.register(Matrix4.class, new Matrix4Serializer()); kryo.register(Vector3i.class, new Vector3iSerializer()); - kryo.register(PlayerStartPosition.class, new PlayerStartPositionSerializer()); + kryo.register(Teleport.class, new PlayerStartPositionSerializer()); kryo.register(TextureAsset.class, new AssetSerializer()); kryo.register(ModelAsset.class, new AssetSerializer()); kryo.setDefaultSerializer(TaggedFieldSerializer.class); @@ -104,4 +104,11 @@ public void saveDB(GameDatabase db) { } + public Kryo begin() { + return pool.borrow(); + } + + public void end(Kryo kryo) { + pool.release(kryo); + } } diff --git a/core/src/macbury/forge/storage/serializers/db/GameDatabaseSerializer.java b/core/src/macbury/forge/storage/serializers/db/GameDatabaseSerializer.java index c515273..76799c0 100644 --- a/core/src/macbury/forge/storage/serializers/db/GameDatabaseSerializer.java +++ b/core/src/macbury/forge/storage/serializers/db/GameDatabaseSerializer.java @@ -5,7 +5,7 @@ import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; import macbury.forge.db.GameDatabase; -import macbury.forge.db.models.PlayerStartPosition; +import macbury.forge.db.models.Teleport; /** * Created by macbury on 10.11.14. @@ -17,7 +17,7 @@ public void write(Kryo kryo, Output output, GameDatabase gameDatabase) { output.writeInt(gameDatabase.currentyUID); output.writeString(gameDatabase.title); output.writeLong(gameDatabase.build++); - kryo.writeObjectOrNull(output, gameDatabase.startPosition, PlayerStartPosition.class); + kryo.writeObjectOrNull(output, gameDatabase.startPosition, Teleport.class); output.writeInt(gameDatabase.lastOpenedMapId); } @@ -28,7 +28,7 @@ public GameDatabase read(Kryo kryo, Input input, Class type) { db.currentyUID = input.readInt(); db.title = input.readString(); db.build = input.readLong(); - db.startPosition = kryo.readObjectOrNull(input, PlayerStartPosition.class); + db.startPosition = kryo.readObjectOrNull(input, Teleport.class); db.lastOpenedMapId = input.readInt(); return db; } diff --git a/core/src/macbury/forge/storage/serializers/db/models/PlayerStartPositionSerializer.java b/core/src/macbury/forge/storage/serializers/db/models/PlayerStartPositionSerializer.java index 9725657..8692b7c 100644 --- a/core/src/macbury/forge/storage/serializers/db/models/PlayerStartPositionSerializer.java +++ b/core/src/macbury/forge/storage/serializers/db/models/PlayerStartPositionSerializer.java @@ -4,24 +4,22 @@ import com.esotericsoftware.kryo.Serializer; import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; -import macbury.forge.db.models.PlayerStartPosition; +import macbury.forge.db.models.Teleport; import macbury.forge.utils.Vector3i; /** * Created by macbury on 24.03.15. */ -public class PlayerStartPositionSerializer extends Serializer { +public class PlayerStartPositionSerializer extends Serializer { @Override - public void write(Kryo kryo, Output output, PlayerStartPosition object) { + public void write(Kryo kryo, Output output, Teleport object) { kryo.writeObject(output, object.voxelPosition); output.writeInt(object.mapId, true); } @Override - public PlayerStartPosition read(Kryo kryo, Input input, Class type) { - PlayerStartPosition startPosition = new PlayerStartPosition(); - startPosition.voxelPosition = kryo.readObject(input, Vector3i.class); - startPosition.mapId = input.readInt(true); + public Teleport read(Kryo kryo, Input input, Class type) { + Teleport startPosition = new Teleport(kryo.readObject(input, Vector3i.class), input.readInt(true)); return startPosition; } }