Merge branch 'startIntegratingSQL' into dev
This commit is contained in:
commit
5e2f3d457b
5
Diagrams/MyDiagram.erd
Normal file
5
Diagrams/MyDiagram.erd
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<diagram version="1" name="MyDiagram">
|
||||
<entities/>
|
||||
<relations/>
|
||||
</diagram>
|
||||
35
Scripts/clearTables.sql
Normal file
35
Scripts/clearTables.sql
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
--main Table
|
||||
DROP TABLE IF EXISTS mainTable;
|
||||
|
||||
--charas
|
||||
--positions
|
||||
DROP TABLE IF EXISTS charaWorldPositions;
|
||||
DROP INDEX IF EXISTS charaWorldPositionsIDIndex;
|
||||
DROP INDEX IF EXISTS charaWorldPositionsPosIndex;
|
||||
--data
|
||||
DROP TABLE IF EXISTS charaData;
|
||||
DROP INDEX IF EXISTS charaDataIDIndex;
|
||||
DROP INDEX IF EXISTS charaDataPosIndex;
|
||||
|
||||
--towns
|
||||
--positions
|
||||
DROP TABLE IF EXISTS townWorldPositions;
|
||||
DROP INDEX IF EXISTS townWorldPositionsIDIndex;
|
||||
DROP INDEX IF EXISTS townWorldPositionsPosIndex;
|
||||
|
||||
--data
|
||||
DROP TABLE IF EXISTS townData;
|
||||
DROP INDEX IF EXISTS townDataIDIndex;
|
||||
DROP INDEX IF EXISTS townDataPosIndex;
|
||||
|
||||
--structs
|
||||
--positions
|
||||
DROP TABLE IF EXISTS structWorldPositions;
|
||||
DROP INDEX IF EXISTS structWorldPositionsIDIndex;
|
||||
DROP INDEX IF EXISTS structWorldPositionsPosIndex;
|
||||
|
||||
--data
|
||||
DROP TABLE IF EXISTS structData;
|
||||
DROP INDEX IF EXISTS structDataIDIndex;
|
||||
DROP INDEX IF EXISTS structDataPosIndex;
|
||||
38
Scripts/createTables.sql
Normal file
38
Scripts/createTables.sql
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
--main table
|
||||
CREATE TABLE mainTable (propName VARCHAR PRIMARY KEY, propValue VARCHAR);
|
||||
INSERT INTO mainTable (propName, propValue) VALUES ("ver","1");
|
||||
|
||||
--characters
|
||||
--positions
|
||||
CREATE TABLE charaWorldPositions (id INTEGER PRIMARY KEY, charID INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX charaWorldPositionsIDIndex ON charaWorldPositions (charID);
|
||||
CREATE INDEX charaWorldPositionsPosIndex ON charaWorldPositions (posX, posY);
|
||||
|
||||
--data
|
||||
CREATE TABLE charaData (id INTEGER PRIMARY KEY, charID INTEGER, dataVal VARCHAR);
|
||||
CREATE INDEX charaDataIDIndex ON charaData (charID);
|
||||
|
||||
|
||||
|
||||
--towns
|
||||
--positions
|
||||
CREATE TABLE townWorldPositions (id INTEGER PRIMARY KEY, townID INTEGER, posX INTEGER, posY INTEGER, bbRadiusX INTEGER, bbRadiusY INTEGER);
|
||||
CREATE INDEX townWorldPositionsIDIndex ON townWorldPositions (townID);
|
||||
CREATE INDEX townWorldPositionsPosIndex ON townWorldPositions (posX, posY);
|
||||
|
||||
--data
|
||||
CREATE TABLE townData (id INTEGER PRIMARY KEY, townID INTEGER, dataVal VARCHAR);
|
||||
CREATE INDEX townDataIDIndex ON townData (townID);
|
||||
|
||||
|
||||
--structures
|
||||
--positions
|
||||
CREATE TABLE structWorldPositions (id INTEGER PRIMARY KEY, structID INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX structWorldPositionsIDIndex ON structWorldPositions (structID);
|
||||
CREATE INDEX structWorldPositionsPosIndex ON structWorldPositions (posX, posY);
|
||||
|
||||
--data
|
||||
CREATE TABLE structData (id INTEGER PRIMARY KEY, structID INTEGER, dataVal VARCHAR);
|
||||
CREATE INDEX structDataIDIndex ON structData (structID);
|
||||
|
||||
6
Scripts/structs/createStruct.sql
Normal file
6
Scripts/structs/createStruct.sql
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
--positions
|
||||
INSERT INTO structWorldPositions (structID,posX,posY) VALUES (0,10,10);
|
||||
|
||||
--data
|
||||
INSERT INTO structData(structID,dataVal) VALUES(0,'{"localX"=10,"localY"=10}');
|
||||
6
Scripts/structs/deleteStruct.sql
Normal file
6
Scripts/structs/deleteStruct.sql
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
--positions
|
||||
DELETE FROM structWorldPositions WHERE structID=0;
|
||||
|
||||
--data
|
||||
DELETE FROM structData WHERE structID=0;
|
||||
1
Scripts/structs/getStructDataByID.sql
Normal file
1
Scripts/structs/getStructDataByID.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT * FROM structData WHERE structID IN (1, 2);
|
||||
1
Scripts/structs/getStructLocalPos.sql
Normal file
1
Scripts/structs/getStructLocalPos.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT * FROM structData WHERE structID=0;
|
||||
1
Scripts/structs/getStructsAtWorldPos.sql
Normal file
1
Scripts/structs/getStructsAtWorldPos.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT * FROM structWorldPositions WHERE posX = 10 AND posY = 10;
|
||||
6
Scripts/towns/createTown.sql
Normal file
6
Scripts/towns/createTown.sql
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
--positions
|
||||
INSERT INTO townWorldPositions (townID,posX,posY,bbRadiusX,bbRadiusY) VALUES (0,10,10,1,1);
|
||||
|
||||
--data
|
||||
INSERT INTO townData(townID,propName,propValue) VALUES(0,"name","someTown");
|
||||
6
Scripts/towns/deleteTown.sql
Normal file
6
Scripts/towns/deleteTown.sql
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
--positions
|
||||
DELETE FROM townWorldPositions WHERE townID=0;
|
||||
|
||||
--data
|
||||
DELETE FROM townData WHERE townID=0;
|
||||
1
Scripts/towns/getTownsAtWorldPos.sql
Normal file
1
Scripts/towns/getTownsAtWorldPos.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT * FROM townWorldPositions WHERE posX = 10 AND posY = 10;
|
||||
2
pom.xml
2
pom.xml
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>electrosphere</groupId>
|
||||
<groupId>studiorailgun</groupId>
|
||||
<artifactId>Renderer</artifactId>
|
||||
<version>0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
BIN
saves/world_testing/central.db
Normal file
BIN
saves/world_testing/central.db
Normal file
Binary file not shown.
1
saves/world_testing/terrain.json
Normal file
1
saves/world_testing/terrain.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,90 @@
|
||||
package electrosphere.game.server.db;
|
||||
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class DatabaseController {
|
||||
|
||||
Connection conn;
|
||||
|
||||
public DatabaseController(){
|
||||
|
||||
}
|
||||
|
||||
public void connect(String path){
|
||||
String dbms = "sqlite";
|
||||
Properties connectionProps = new Properties();
|
||||
String fullAddress = "jdbc:" + dbms + ":" + path;
|
||||
try {
|
||||
conn = DriverManager.getConnection(fullAddress, connectionProps);
|
||||
} catch (SQLException ex) {
|
||||
LoggerInterface.loggerFileIO.ERROR("Failure to connect to db", ex);
|
||||
}
|
||||
}
|
||||
|
||||
// public boolean executeStatement(String statementRaw){
|
||||
// boolean rVal = false;
|
||||
// try {
|
||||
// PreparedStatement statement = conn.prepareStatement(statementRaw);
|
||||
// rVal = statement.execute();
|
||||
// } catch (SQLException ex) {
|
||||
// LoggerInterface.loggerFileIO.ERROR("SQL statement execution error", ex);
|
||||
// }
|
||||
// return rVal;
|
||||
// }
|
||||
|
||||
public DatabaseResult executeStatement(String statementRaw){
|
||||
DatabaseResult rVal = DatabaseResult.createStatement(statementRaw);
|
||||
try {
|
||||
PreparedStatement statement = conn.prepareStatement(statementRaw);
|
||||
statement.execute();
|
||||
ResultSet results = statement.getResultSet();
|
||||
if(results != null){
|
||||
rVal.addResultSet(results);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
rVal.succeeded = false;
|
||||
rVal.hasResultSet = false;
|
||||
LoggerInterface.loggerFileIO.ERROR("SQL statement execution error", ex);
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public DatabaseResult executeQuery(String statementRaw){
|
||||
DatabaseResult rVal = DatabaseResult.createStatement(statementRaw);
|
||||
try {
|
||||
PreparedStatement statement = conn.prepareStatement(statementRaw);
|
||||
ResultSet results = statement.executeQuery();
|
||||
if(results != null){
|
||||
rVal.addResultSet(results);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
rVal.succeeded = false;
|
||||
rVal.hasResultSet = false;
|
||||
LoggerInterface.loggerFileIO.ERROR("SQL query execution error", ex);
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public boolean isConnected(){
|
||||
boolean rVal = false;
|
||||
try {
|
||||
rVal = conn.isValid(100);
|
||||
} catch (SQLException ex) {
|
||||
LoggerInterface.loggerFileIO.ERROR("SQL error validating status of db", ex);
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
package electrosphere.game.server.db;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class DatabaseResult {
|
||||
boolean isQuery = false;
|
||||
boolean isStatement = false;
|
||||
boolean succeeded = false;
|
||||
boolean hasResultSet = false;
|
||||
String code;
|
||||
ResultSet rs;
|
||||
private static Gson deserializer;
|
||||
|
||||
static {
|
||||
deserializer = new Gson();
|
||||
}
|
||||
|
||||
|
||||
public static DatabaseResult createQuery(String code){
|
||||
DatabaseResult rVal = new DatabaseResult();
|
||||
rVal.isQuery = true;
|
||||
rVal.code = code;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static DatabaseResult createStatement(String code){
|
||||
DatabaseResult rVal = new DatabaseResult();
|
||||
rVal.isStatement = true;
|
||||
rVal.code = code;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public void addResultSet(ResultSet rs){
|
||||
this.rs = rs;
|
||||
}
|
||||
|
||||
public ResultSet getResultSet(){
|
||||
return rs;
|
||||
}
|
||||
|
||||
public boolean hasResultSet(){
|
||||
return hasResultSet;
|
||||
}
|
||||
|
||||
public boolean isQuery(){
|
||||
return isQuery;
|
||||
}
|
||||
|
||||
public boolean isStatement(){
|
||||
return isStatement;
|
||||
}
|
||||
|
||||
public boolean success(){
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
public <T>T deserializeFirstResult(Class<T> className){
|
||||
T rVal = null;
|
||||
try {
|
||||
rs.getString(0);
|
||||
rVal = deserializer.fromJson(rs.getString(0), className);
|
||||
} catch (SQLException ex) {
|
||||
LoggerInterface.loggerFileIO.ERROR("Failure to deserialize result", ex);
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
public void logRawResult(){
|
||||
}
|
||||
}
|
||||
@ -5,16 +5,28 @@ package electrosphere.game.server.structure.virtual;
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class Structure {
|
||||
int worldX;
|
||||
int worldY;
|
||||
float locationX;
|
||||
float locationY;
|
||||
String type;
|
||||
|
||||
public Structure(float locationX, float locationY, String type) {
|
||||
public Structure(int worldX, int worldY, float locationX, float locationY, String type) {
|
||||
this.worldX = worldX;
|
||||
this.worldY = worldY;
|
||||
this.locationX = locationX;
|
||||
this.locationY = locationY;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getWorldX() {
|
||||
return worldX;
|
||||
}
|
||||
|
||||
public int getWorldY() {
|
||||
return worldY;
|
||||
}
|
||||
|
||||
public float getLocationX() {
|
||||
return locationX;
|
||||
}
|
||||
|
||||
@ -0,0 +1,75 @@
|
||||
package electrosphere.game.server.structure.virtual;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import electrosphere.game.server.db.DatabaseResult;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class StructureManager {
|
||||
|
||||
static Gson serializer;
|
||||
|
||||
static {
|
||||
serializer = new Gson();
|
||||
}
|
||||
|
||||
static int structIDIterator = 0;
|
||||
|
||||
|
||||
public static Structure createStructure(int worldX, int worldY, float localX, float localY, String type){
|
||||
int id = structIDIterator;
|
||||
structIDIterator++;
|
||||
Structure rVal = new Structure(worldX, worldY, localX, localY, type);
|
||||
Globals.dbController.executeStatement("INSERT INTO structWorldPositions (structID,posX,posY) VALUES (" + structIDIterator + "," + worldX + "," + worldY + ");");
|
||||
Globals.dbController.executeStatement("INSERT INTO structData(structID,propName,propValue) VALUES(" + structIDIterator + ",'localX','" + localX + "');");
|
||||
Globals.dbController.executeStatement("INSERT INTO structData(structID,propName,propValue) VALUES(" + structIDIterator + ",'localY','" + localY + "');");
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static List<Structure> getStructuresInChunk(int worldX, int worldY){
|
||||
List<Structure> rVal = new LinkedList();
|
||||
DatabaseResult result = Globals.dbController.executeStatement("SELECT * FROM structWorldPositions WHERE posX = " + worldX + " AND posY = " + worldY + ";");
|
||||
List<Integer> returnedIDs = new LinkedList();
|
||||
if(result.hasResultSet()){
|
||||
ResultSet positionSet = result.getResultSet();
|
||||
try {
|
||||
while(positionSet.next()){
|
||||
returnedIDs.add(positionSet.getInt("structID"));
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LoggerInterface.loggerEngine.ERROR("Error looping through positions returned in StructureManager.getStructuresInChunk", ex);
|
||||
}
|
||||
}
|
||||
if(returnedIDs.size() > 0){
|
||||
String ids = "";
|
||||
for(int ID : returnedIDs){
|
||||
ids = ids + ID + ",";
|
||||
}
|
||||
ids = ids.substring(0, ids.length() - 1);
|
||||
result = Globals.dbController.executeStatement("SELECT * FROM structData WHERE structID IN (" + ids + ");");
|
||||
if(result.success() && result.hasResultSet()){
|
||||
ResultSet rs = result.getResultSet();
|
||||
try {
|
||||
while(rs.next()){
|
||||
String rawData = rs.getString("dataVal");
|
||||
Structure newStruct = serializer.fromJson(rawData, Structure.class);
|
||||
rVal.add(newStruct);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LoggerInterface.loggerEngine.ERROR("Error looping through structures returned in StructureManager.getStructuresInChunk", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
}
|
||||
@ -14,7 +14,9 @@ public class StructurePlacer {
|
||||
|
||||
|
||||
public static Structure placeStructureAtPoint(float posX, float posY, String type){
|
||||
Structure rVal = new Structure(posX,posY,type);
|
||||
int worldX = Globals.serverWorldData.convertRealToChunkSpace(posX);
|
||||
int worldY = Globals.serverWorldData.convertRealToChunkSpace(posY);
|
||||
Structure rVal = new Structure(worldX,worldY,posX,posY,type);
|
||||
|
||||
double centerHeight = Globals.serverTerrainManager.getHeightAtPosition(posX, posY);
|
||||
StructureType currentTypeObject = Globals.gameConfigCurrent.getStructureTypeMap().getType(type);
|
||||
|
||||
@ -24,7 +24,9 @@ import electrosphere.game.server.character.Character;
|
||||
import electrosphere.game.config.creature.type.model.CreatureTypeMap;
|
||||
import electrosphere.game.config.item.type.model.ItemTypeMap;
|
||||
import electrosphere.game.config.structure.type.model.StructureTypeMap;
|
||||
import electrosphere.game.server.db.DatabaseController;
|
||||
import electrosphere.game.server.structure.virtual.Structure;
|
||||
import electrosphere.game.server.structure.virtual.StructureManager;
|
||||
import electrosphere.game.state.MacroSimulation;
|
||||
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
||||
import electrosphere.game.server.town.Town;
|
||||
@ -114,6 +116,11 @@ public class Globals {
|
||||
public static electrosphere.game.config.Config gameConfigDefault;
|
||||
public static electrosphere.game.config.Config gameConfigCurrent;
|
||||
|
||||
//
|
||||
// Database stuff
|
||||
//
|
||||
public static DatabaseController dbController = new DatabaseController();
|
||||
|
||||
//
|
||||
//current world
|
||||
//
|
||||
@ -236,6 +243,9 @@ public class Globals {
|
||||
//collision world data
|
||||
public static CommonWorldData commonWorldData;
|
||||
|
||||
//structure manager
|
||||
public static StructureManager structureManager;
|
||||
|
||||
|
||||
//the player camera entity
|
||||
public static Entity playerCamera;
|
||||
|
||||
@ -786,7 +786,9 @@ public class Mesh {
|
||||
// }
|
||||
for(Texture texture : textureList){
|
||||
// System.out.println(texture.getPath() + " => groundTextures[" + i + "]" + "=>" + (i));
|
||||
texture.bind(5+i);
|
||||
if(texture != null){
|
||||
texture.bind(5+i);
|
||||
}
|
||||
glUniform1i(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "groundTextures[" + i + "]"),5+i);
|
||||
i++;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user