Skip to content

Commit

Permalink
Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
macbury committed Nov 10, 2014
1 parent 468f2b9 commit ad967d0
Show file tree
Hide file tree
Showing 26 changed files with 320 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.war
*.ear
hs_err_pid*

*.db
## GWT
war/
html/war/gwt_bree/
Expand Down
9 changes: 9 additions & 0 deletions ForgE.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<component inheritJdk="true">
<output-test url="file://$MODULE_DIR$/build"/>
<exclude-output/>
<contentEntry url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle"/>
<excludeFolder url="file://$MODULE_DIR$/build"/>
</contentEntry>
</component>
53 changes: 28 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

buildscript {
repositories {
mavenCentral()
Expand All @@ -7,14 +8,15 @@ buildscript {
}

allprojects {
apply plugin: "eclipse"
apply plugin: "idea"

version = '1.0'
apply plugin: "eclipse"
version = '0.01'
ext {
appName = 'ForgE'
gdxVersion = '1.4.1'
roboVMVersion = '1.0.0-alpha-04'
appName = 'ForgE'
gdxVersion = '1.4.0'
roboVMVersion = '1.0.0-alpha-04'
aiVersion = '1.4.0'
ashleyVersion = '1.3.1'
}

repositories {
Expand All @@ -26,27 +28,27 @@ allprojects {
}

project(":editor") {
apply plugin: "java"

apply plugin: "java"

dependencies {
compile project(":desktop")
compile 'net.contentobjects.jnotify:jnotify:0.94+'
compile 'org.nuiton.thirdparty:l2fprod-common:0.1'
}
dependencies {
compile project(":desktop")
compile 'net.contentobjects.jnotify:jnotify:0.94+'
compile 'org.nuiton.thirdparty:l2fprod-common:0.1'
}
}

project(":desktop") {
apply plugin: "java"
apply plugin: "java"


dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
}
}

project(":core") {
Expand All @@ -55,10 +57,11 @@ project(":core") {

dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.badlogicgames.ashley:ashley:1.3.1"
compile 'com.esotericsoftware.kryo:kryo:2.10'
//compile "com.badlogicgames.gdx:gdx-ai:1.4"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
compile 'com.esotericsoftware:kryo-shaded:3.0.0'
}
}

Expand Down
4 changes: 0 additions & 4 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ sourceCompatibility = 1.6

sourceSets.main.java.srcDirs = [ "src/" ]


eclipse.project {
name = appName + "-core"
}
21 changes: 21 additions & 0 deletions core/core.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<component inheritJdk="true">
<output-test url="file://$MODULE_DIR$/build/classes/test"/>
<exclude-output/>
<contentEntry url="file://$MODULE_DIR$">
<testFolder url="file://$MODULE_DIR$/src/test/java"/>
<testFolder url="file://$MODULE_DIR$/src/test/resources"/>
<excludeFolder url="file://$MODULE_DIR$/.gradle"/>
<excludeFolder url="file://$MODULE_DIR$/build"/>
</contentEntry>
<levels>
<level name="Gradle: com.badlogicgames.ashley:ashley:1.3.1" value="project"/>
<level name="Gradle: com.esotericsoftware.kryo:kryo:2.10" value="project"/>
<level name="Gradle: com.esotericsoftware.reflectasm:reflectasm:1.03" value="project"/>
<level name="Gradle: com.esotericsoftware.minlog:minlog:1.2" value="project"/>
<level name="Gradle: org.objenesis:objenesis:1.2" value="project"/>
<level name="Gradle: org.ow2.asm:asm:4.0" value="project"/>
<level name="Gradle: com.badlogicgames.gdx:gdx:1.4.1" value="project"/>
<level name="Gradle: com.badlogicgames.gdx:gdx-freetype:1.4.1" value="project"/>
</levels>
</component>
8 changes: 6 additions & 2 deletions core/src/macbury/forge/ForgE.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.badlogic.gdx.Gdx;
import macbury.forge.assets.AssetsManager;
import macbury.forge.db.GameDatabase;
import macbury.forge.storage.StorageManager;
import macbury.forge.graphics.GraphicsUtils;
import macbury.forge.input.InputManager;
import macbury.forge.screens.ScreenManager;
Expand All @@ -15,25 +16,28 @@ public class ForgE extends Game {
public static AssetsManager assets;
public static ShadersManager shaders;
public static Config config;
public static StorageManager storage;
public static GameDatabase db;

public static InputManager input;
private ForgEBootListener bootListener;


public ForgE(Config config) {
super();
this.config = config;
}

@Override
public void create () {
db = new GameDatabase();
storage = new StorageManager();

db = storage.loadOrInitializeDB();
graphics = new GraphicsUtils();
screens = new ScreenManager(this);
assets = new AssetsManager();
shaders = new ShadersManager();
input = new InputManager();

Gdx.input.setInputProcessor(input);
if (bootListener != null) {
bootListener.afterEngineCreate(this);
Expand Down
23 changes: 20 additions & 3 deletions core/src/macbury/forge/db/GameDatabase.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
package macbury.forge.db;

import com.esotericsoftware.kryo.Kryo;

/**
* Created by macbury on 07.11.14.
*/
public class GameDatabase extends Kryo {
public class GameDatabase {
public static final String FILE_NAME = "game.db";
public String title;
public int currentyUID = 0;

/**
* Create int uuid
* @return unique id
*/
public int uid() {
return currentyUID += 1;
}

/**
* Bootstrap db with default values
*/
public void bootstrap() {
title = "ForgE Project";
currentyUID = 0;
}
}
46 changes: 2 additions & 44 deletions core/src/macbury/forge/level/LevelState.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package macbury.forge.level;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import macbury.forge.voxel.VoxelMaterial;
import macbury.forge.ForgE;
import macbury.forge.voxel.ChunkMap;

/**
Expand All @@ -12,7 +9,6 @@
*/
public class LevelState {
private static final String MAP_NAME_PREFIX = "MAP_";
private static int uid = 0;

public LevelEnv env;
public ChunkMap terrainMap;
Expand All @@ -25,50 +21,12 @@ public class LevelState {
public static LevelState blank(int width, int height, int depth) {
LevelState state = new LevelState();
state.terrainMap = new ChunkMap(ChunkMap.TERRAIN_TILE_SIZE);
state.id = uid();
state.id = ForgE.db.uid();
state.name = MAP_NAME_PREFIX + state.id;
state.env = new LevelEnv();
state.terrainMap.initialize(width,height,depth);
state.terrainMap.buildFloor();
return state;
}

public static LevelState heightMapTest() {
LevelState state = new LevelState();
state.terrainMap = new ChunkMap(ChunkMap.TERRAIN_TILE_SIZE);
state.id = uid();
state.name = MAP_NAME_PREFIX + state.id;

state.terrainMap.initialize(250,50,250);
state.terrainMap.buildFloor();

Pixmap pixmap = new Pixmap(Gdx.files.internal("heightmap.png"));
Color color = new Color();

for (int x = 0; x < state.terrainMap.getWidth(); x++) {
for (int z = 0; z < state.terrainMap.getDepth(); z++) {
int rawColor = pixmap.getPixel(x, z);
color.set(rawColor);
int height = (int)Math.floor(color.r * (state.terrainMap.getHeight() - 5));

for (int y = 1; y < height; y++) {
VoxelMaterial mat = state.terrainMap.materials.get(Math.max((int)Math.round((state.terrainMap.materials.size-1) * Math.random()), 1));
state.terrainMap.setMaterialForPosition(mat, x,y,z);
}
}
}

pixmap.dispose();

return state;
}

/**
* Create uid for level.
* @return
*/
public static int uid() {
//TODO: After increase save uid to disk
return uid += 1;
}
}
47 changes: 47 additions & 0 deletions core/src/macbury/forge/storage/StorageManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package macbury.forge.storage;

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.db.GameDatabase;
import macbury.forge.storage.serializers.GameDatabseSerializer;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
* Created by macbury on 07.11.14.
*/
public class StorageManager extends Kryo {
public StorageManager() {
super();
register(GameDatabase.class, new GameDatabseSerializer());
}

public GameDatabase loadOrInitializeDB() {
FileHandle dbFile = Gdx.files.internal(GameDatabase.FILE_NAME);
GameDatabase db = null;
if (dbFile.exists()) {
db = readObject(new Input(dbFile.read()), GameDatabase.class);
} else {
db = new GameDatabase();
db.bootstrap();
saveDB(db);
}

return db;
}

public void saveDB(GameDatabase db) {
FileHandle dbFile = Gdx.files.internal(GameDatabase.FILE_NAME);
try {
Output output = new Output(new FileOutputStream(dbFile.file(), false));
writeObject(output, db);
output.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package macbury.forge.storage.serializers;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import macbury.forge.db.GameDatabase;

/**
* Created by macbury on 10.11.14.
*/
public class GameDatabseSerializer extends Serializer<GameDatabase> {
@Override
public void write(Kryo kryo, Output output, GameDatabase gameDatabase) {
output.writeInt(gameDatabase.currentyUID);
output.writeString(gameDatabase.title);
}

@Override
public GameDatabase read(Kryo kryo, Input input, Class<GameDatabase> type) {
GameDatabase db = new GameDatabase();
db.bootstrap();
db.currentyUID = input.readInt();
db.title = input.readString();
return db;
}

}
17 changes: 0 additions & 17 deletions desktop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,3 @@ task dist(type: Jar) {

dist.dependsOn classes

eclipse {
project {
name = appName + "-desktop"
linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
}
}

task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
doLast {
def classpath = new XmlParser().parse(file(".classpath"))
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
def writer = new FileWriter(file(".classpath"))
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.setPreserveWhitespace(true)
printer.print(classpath)
}
}
Loading

0 comments on commit ad967d0

Please sign in to comment.