Terrain streaming, begin work on world gen/sim
This commit is contained in:
parent
c13f137f68
commit
2926f8b49b
@ -76,7 +76,7 @@ public class DrawCell {
|
||||
Model terrainModel = ModelUtils.createTerrainModelPrecomputedShader(heightmap, program, stride);
|
||||
String terrainModelPath = Globals.assetManager.registerModel(terrainModel);
|
||||
modelEntity = EntityUtils.spawnDrawableEntity(terrainModelPath);
|
||||
// System.out.println("New cell @ " + cellX * cellWidth + "," + cellY * cellWidth);
|
||||
System.out.println("New cell @ " + cellX * dynamicInterpolationRatio + "," + cellY * dynamicInterpolationRatio);
|
||||
EntityUtils.getEntityPosition(modelEntity).set(new Vector3f(cellX * dynamicInterpolationRatio, 0.01f, cellY * dynamicInterpolationRatio));
|
||||
}
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ public class DrawCellManager {
|
||||
|
||||
|
||||
|
||||
public DrawCellManager(ClientWorldData clientWorldData, ClientTerrainManager clientTerrainManager, float realX, float realY){
|
||||
public DrawCellManager(ClientWorldData clientWorldData, ClientTerrainManager clientTerrainManager, int discreteX, int discreteY){
|
||||
this.clientWorldData = clientWorldData;
|
||||
this.clientTerrainManager = clientTerrainManager;
|
||||
this.miniCellWidth = miniCellWidth;
|
||||
@ -75,8 +75,8 @@ public class DrawCellManager {
|
||||
hasRequested[x][y] = false;
|
||||
}
|
||||
}
|
||||
cellX = transformRealSpaceToCellSpace(realX);
|
||||
cellY = transformRealSpaceToCellSpace(realY);
|
||||
cellX = discreteX;
|
||||
cellY = discreteY;
|
||||
|
||||
program = Globals.defaultMeshShader;
|
||||
|
||||
@ -120,7 +120,7 @@ public class DrawCellManager {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(found){
|
||||
int currentCellX = cellX - drawRadius + targetX;
|
||||
int currentCellY = cellY - drawRadius + targetY;
|
||||
@ -187,11 +187,13 @@ public class DrawCellManager {
|
||||
currentCellY >= 0 &&
|
||||
currentCellY < clientWorldData.getWorldDiscreteSize()
|
||||
){
|
||||
//calculation for stride
|
||||
int dist = (int)Math.sqrt((targetX - drawRadius)*(targetX - drawRadius) + (targetY - drawRadius) * (targetY - drawRadius));//Math.abs(targetX - drawRadius) * Math.abs(targetY - drawRadius);
|
||||
int stride = Math.min(clientWorldData.getDynamicInterpolationRatio()/2, Math.max(1, dist / drawStepdownInterval * drawStepdownValue));
|
||||
while(clientWorldData.getDynamicInterpolationRatio() % stride != 0){
|
||||
stride = stride + 1;
|
||||
}
|
||||
//make drawable entity
|
||||
cells[targetX][targetY].generateDrawableEntity(stride);
|
||||
}
|
||||
drawable[targetX][targetY] = true;
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package electrosphere.game.client.player;
|
||||
|
||||
public class ClientPlayerData {
|
||||
int initialDiscretePositionX;
|
||||
int initialDiscretePositionY;
|
||||
|
||||
boolean loaded = false;
|
||||
|
||||
public ClientPlayerData(){
|
||||
}
|
||||
|
||||
public boolean hasLoaded(){
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public void setInitialDiscretePosition(int x, int y){
|
||||
initialDiscretePositionX = x;
|
||||
initialDiscretePositionY = y;
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public int getInitialDiscretePositionX() {
|
||||
return initialDiscretePositionX;
|
||||
}
|
||||
|
||||
public int getInitialDiscretePositionY() {
|
||||
return initialDiscretePositionY;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package electrosphere.game.server.character;
|
||||
|
||||
public class AdvancedPersonality {
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package electrosphere.game.server.character;
|
||||
|
||||
public class BasicPersonality {
|
||||
|
||||
}
|
||||
@ -1,9 +1,15 @@
|
||||
package electrosphere.game.server.character;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
import electrosphere.game.server.character.diety.Diety;
|
||||
|
||||
public class Character {
|
||||
boolean isDiety;
|
||||
Diety diety;
|
||||
boolean hasBasicPersonality;
|
||||
BasicPersonality basicPersonality;
|
||||
boolean hasAdvancedPersonality;
|
||||
AdvancedPersonality advancedPersonality;
|
||||
int discreteX;
|
||||
int discreteY;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package electrosphere.game.server.character;
|
||||
|
||||
import electrosphere.game.server.culture.Culture;
|
||||
import electrosphere.game.server.character.Character;
|
||||
import electrosphere.game.server.creature.type.CreatureType;
|
||||
|
||||
public class CharacterGenerator {
|
||||
|
||||
public static Character generateCharacter(CreatureType creature, Culture culture){
|
||||
Character character = new Character();
|
||||
|
||||
return character;
|
||||
}
|
||||
|
||||
public static void positionCharacter(Character c, int x, int y){
|
||||
c.discreteX = x;
|
||||
c.discreteY = y;
|
||||
}
|
||||
|
||||
|
||||
public static Character generateDietyOfArchetype(){
|
||||
Character character = new Character();
|
||||
|
||||
return character;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
package electrosphere.game.server.character.diety;
|
||||
|
||||
public class Diety {
|
||||
|
||||
int godlyPower;
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package electrosphere.game.server.civilization;
|
||||
|
||||
public class Civilization {
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package electrosphere.game.server.civilization.model;
|
||||
|
||||
public class CivilizationMap {
|
||||
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
package electrosphere.game.server.creature.type;
|
||||
|
||||
public class BodyPart {
|
||||
int bodyPartClass;
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package electrosphere.game.server.creature.type;
|
||||
|
||||
public class CreatureType {
|
||||
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
package electrosphere.game.server.creature.type.model;
|
||||
|
||||
public class CreatureTypeMap {
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package electrosphere.game.server.culture;
|
||||
|
||||
public class Culture {
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package electrosphere.game.server.culture;
|
||||
|
||||
public class Ritual {
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package electrosphere.game.server.culture.religion;
|
||||
|
||||
public class Religion {
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package electrosphere.game.server.settlement;
|
||||
|
||||
public class Settlement {
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package electrosphere.game.server.simulation;
|
||||
|
||||
import electrosphere.game.server.civilization.Civilization;
|
||||
import electrosphere.game.server.civilization.model.CivilizationMap;
|
||||
import electrosphere.game.server.creature.type.CreatureType;
|
||||
import electrosphere.game.server.creature.type.model.CreatureTypeMap;
|
||||
import electrosphere.game.server.culture.Culture;
|
||||
import electrosphere.game.server.culture.religion.Religion;
|
||||
import electrosphere.util.Utilities;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Simulation {
|
||||
|
||||
List<Civilization> civilizationList = new LinkedList();
|
||||
List<Culture> cultureList = new LinkedList();
|
||||
List<Religion> religionList = new LinkedList();
|
||||
List<CreatureType> creatureList = new LinkedList();
|
||||
List<Character> characterList = new LinkedList();
|
||||
|
||||
public Simulation(){
|
||||
init();
|
||||
}
|
||||
|
||||
void init(){
|
||||
CreatureTypeMap creatureTypeMap = Utilities.loadObjectFromBakedJsonFile("Data/creatures.json", CreatureTypeMap.class);
|
||||
CivilizationMap civilizationMap = Utilities.loadObjectFromBakedJsonFile("Data/civilization.json", CivilizationMap.class);
|
||||
}
|
||||
|
||||
public void simulate(){
|
||||
|
||||
}
|
||||
}
|
||||
@ -14,9 +14,9 @@ class InterpolationDisplay extends JPanel{
|
||||
if(TerrainGen.display_toggle == 0) {
|
||||
for (int x = 0; x < TerrainGen.DIMENSION; x++) {
|
||||
for (int y = 0; y < TerrainGen.DIMENSION; y++) {
|
||||
if (TerrainGen.mountain_parsed[x][y] > TerrainGen.mountain_Threshold - 1) {
|
||||
if (TerrainGen.mountainParsed[x][y] > TerrainGen.MOUNTAIN_THRESHOLD - 1) {
|
||||
g.setColor(new Color((int) (TerrainGen.elevation[x][y] / 100.0 * 254 * (TerrainGen.brightness / 100.0)), 1, 1));
|
||||
} else if (TerrainGen.ocean_parsed[x][y] > TerrainGen.ocean_Threshold - 1) {
|
||||
} else if (TerrainGen.oceanParsed[x][y] > TerrainGen.OCEAN_THRESHOLD - 1) {
|
||||
g.setColor(
|
||||
new Color(
|
||||
1,
|
||||
@ -33,7 +33,7 @@ class InterpolationDisplay extends JPanel{
|
||||
} else if(TerrainGen.display_toggle == 1){
|
||||
for (int x = 0; x < TerrainGen.DIMENSION; x++) {
|
||||
for (int y = 0; y < TerrainGen.DIMENSION; y++) {
|
||||
if (TerrainGen.precipitation_Chart[x][y] > 0) {
|
||||
if (TerrainGen.precipitationChart[x][y] > 0) {
|
||||
g.setColor(
|
||||
new Color(
|
||||
1,
|
||||
@ -53,7 +53,7 @@ class InterpolationDisplay extends JPanel{
|
||||
// if (TerrainInterpolator.precipitation_Chart[x][y] > 0) {
|
||||
g.setColor(
|
||||
new Color(
|
||||
(int) ((TerrainGen.temperature_Chart[x][y]) / 100.0 * 254 * (TerrainGen.brightness / 100.0)),
|
||||
(int) ((TerrainGen.temperatureChart[x][y]) / 100.0 * 254 * (TerrainGen.brightness / 100.0)),
|
||||
(int) ((TerrainGen.elevation[x][y]) / 100.0 * 254 * (TerrainGen.brightness / 100.0)),
|
||||
1
|
||||
)
|
||||
@ -67,7 +67,7 @@ class InterpolationDisplay extends JPanel{
|
||||
} else if(TerrainGen.display_toggle == 3){
|
||||
for (int x = 0; x < TerrainGen.DIMENSION; x++) {
|
||||
for (int y = 0; y < TerrainGen.DIMENSION; y++) {
|
||||
if (TerrainGen.climate_category[x][y] == 0) {
|
||||
if (TerrainGen.climateCategory[x][y] == 0) {
|
||||
g.setColor(Color.BLUE);
|
||||
// g.setColor(
|
||||
// new Color(
|
||||
@ -76,7 +76,7 @@ class InterpolationDisplay extends JPanel{
|
||||
// (int) ((TerrainInterpolator.elevation[x][y]) / 100.0 * 254 * (TerrainInterpolator.brightness / 100.0))
|
||||
// )
|
||||
// );
|
||||
} else if(TerrainGen.climate_category[x][y] == 1){
|
||||
} else if(TerrainGen.climateCategory[x][y] == 1){
|
||||
g.setColor(Color.RED);
|
||||
// g.setColor(
|
||||
// new Color(
|
||||
@ -85,7 +85,7 @@ class InterpolationDisplay extends JPanel{
|
||||
// 1
|
||||
// )
|
||||
// );
|
||||
} else if(TerrainGen.climate_category[x][y] == 2){
|
||||
} else if(TerrainGen.climateCategory[x][y] == 2){
|
||||
g.setColor(Color.GREEN);
|
||||
// g.setColor(
|
||||
// new Color(
|
||||
@ -94,7 +94,7 @@ class InterpolationDisplay extends JPanel{
|
||||
// 1
|
||||
// )
|
||||
// );
|
||||
} else if(TerrainGen.climate_category[x][y] == 3){
|
||||
} else if(TerrainGen.climateCategory[x][y] == 3){
|
||||
g.setColor(Color.YELLOW);
|
||||
// g.setColor(
|
||||
// new Color(
|
||||
@ -103,7 +103,7 @@ class InterpolationDisplay extends JPanel{
|
||||
// (int) ((TerrainInterpolator.elevation[x][y]) / 100.0 * 254 * (TerrainInterpolator.brightness / 100.0))
|
||||
// )
|
||||
// );
|
||||
} else if(TerrainGen.climate_category[x][y] == 4){
|
||||
} else if(TerrainGen.climateCategory[x][y] == 4){
|
||||
g.setColor(
|
||||
new Color(
|
||||
(int) ((TerrainGen.elevation[x][y]) / 100.0 * 254 * (TerrainGen.brightness / 100.0)),
|
||||
@ -112,7 +112,7 @@ class InterpolationDisplay extends JPanel{
|
||||
)
|
||||
);
|
||||
g.setColor(Color.ORANGE);
|
||||
} else if(TerrainGen.climate_category[x][y] == 5){
|
||||
} else if(TerrainGen.climateCategory[x][y] == 5){
|
||||
g.setColor(
|
||||
new Color(
|
||||
(int) ((TerrainGen.elevation[x][y]) / 100.0 * 254 * (TerrainGen.brightness / 100.0)),
|
||||
@ -121,7 +121,7 @@ class InterpolationDisplay extends JPanel{
|
||||
)
|
||||
);
|
||||
g.setColor(Color.BLACK);
|
||||
} else if(TerrainGen.climate_category[x][y] == 6){
|
||||
} else if(TerrainGen.climateCategory[x][y] == 6){
|
||||
g.setColor(
|
||||
new Color(
|
||||
(int) ((TerrainGen.elevation[x][y]) / 100.0 * 254 * (TerrainGen.brightness / 100.0)),
|
||||
@ -138,23 +138,23 @@ class InterpolationDisplay extends JPanel{
|
||||
} else if(TerrainGen.display_toggle == 4){
|
||||
for (int x = 0; x < TerrainGen.DIMENSION; x++) {
|
||||
for (int y = 0; y < TerrainGen.DIMENSION; y++) {
|
||||
if (TerrainGen.continent_Number[x][y] > 8) {
|
||||
if (TerrainGen.continentIdField[x][y] > 8) {
|
||||
g.setColor(Color.PINK);
|
||||
} else if (TerrainGen.continent_Number[x][y] > 7) {
|
||||
} else if (TerrainGen.continentIdField[x][y] > 7) {
|
||||
g.setColor(Color.DARK_GRAY);
|
||||
} else if (TerrainGen.continent_Number[x][y] > 6) {
|
||||
} else if (TerrainGen.continentIdField[x][y] > 6) {
|
||||
g.setColor(Color.CYAN);
|
||||
} else if (TerrainGen.continent_Number[x][y] > 5) {
|
||||
} else if (TerrainGen.continentIdField[x][y] > 5) {
|
||||
g.setColor(Color.GRAY);
|
||||
} else if (TerrainGen.continent_Number[x][y] > 4) {
|
||||
} else if (TerrainGen.continentIdField[x][y] > 4) {
|
||||
g.setColor(Color.orange);
|
||||
} else if (TerrainGen.continent_Number[x][y] > 3) {
|
||||
} else if (TerrainGen.continentIdField[x][y] > 3) {
|
||||
g.setColor(Color.green);
|
||||
} else if (TerrainGen.continent_Number[x][y] > 2) {
|
||||
} else if (TerrainGen.continentIdField[x][y] > 2) {
|
||||
g.setColor(Color.yellow);
|
||||
} else if (TerrainGen.continent_Number[x][y] > 1) {
|
||||
} else if (TerrainGen.continentIdField[x][y] > 1) {
|
||||
g.setColor(Color.blue);
|
||||
} else if (TerrainGen.continent_Number[x][y] > 0) {
|
||||
} else if (TerrainGen.continentIdField[x][y] > 0) {
|
||||
g.setColor(Color.red);
|
||||
} else {
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
package electrosphere.game.server.terrain.generation;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author satellite
|
||||
*/
|
||||
class MidoceanicRidge {
|
||||
|
||||
}
|
||||
@ -37,19 +37,19 @@ public class TerrainGen {
|
||||
public static int display_toggle = 0;
|
||||
static final int max_Display_Toggle = 6;
|
||||
|
||||
public static int mountain_parsed[][];
|
||||
static final int mountain_Threshold = 75;
|
||||
static final int mountain_Range_Size_Minimum = 10;
|
||||
public static int[][] mountainParsed;
|
||||
static final int MOUNTAIN_THRESHOLD = 75;
|
||||
static final int MOUNTAIN_RANGE_SIZE_MINIMUM = 10;
|
||||
|
||||
public static int ocean_parsed[][];
|
||||
static final int ocean_Threshold = 25;
|
||||
public static int[][] oceanParsed;
|
||||
static final int OCEAN_THRESHOLD = 25;
|
||||
|
||||
static Vector wind_field[][];
|
||||
|
||||
public static int[][] precipitation_Chart;
|
||||
static final int rain_Shadow_Blocker_Height = 80;
|
||||
public static int[][] precipitationChart;
|
||||
static final int RAIN_SHADOW_BLOCKER_HEIGHT = 80;
|
||||
|
||||
public static int[][] temperature_Chart;
|
||||
public static int[][] temperatureChart;
|
||||
|
||||
public static long[][] chunkRandomizer;
|
||||
|
||||
@ -62,10 +62,10 @@ public class TerrainGen {
|
||||
5 - polar
|
||||
6 - mountainous
|
||||
*/
|
||||
public static int[][] climate_category;
|
||||
public static int[][] climateCategory;
|
||||
|
||||
public static int num_Continents = 0;
|
||||
public static int[][] continent_Number;
|
||||
public static int numberContinents = 0;
|
||||
public static int[][] continentIdField;
|
||||
|
||||
public static ArrayList<Continent> continents = new ArrayList();
|
||||
|
||||
@ -100,21 +100,21 @@ public class TerrainGen {
|
||||
elevation = land_exponential_filter(elevation);
|
||||
elevation = land_exponential_filter(elevation);
|
||||
|
||||
mountain_parsed = new int[DIMENSION][DIMENSION];
|
||||
ocean_parsed = new int[DIMENSION][DIMENSION];
|
||||
continent_Number = new int[DIMENSION][DIMENSION];
|
||||
mountainParsed = new int[DIMENSION][DIMENSION];
|
||||
oceanParsed = new int[DIMENSION][DIMENSION];
|
||||
continentIdField = new int[DIMENSION][DIMENSION];
|
||||
|
||||
mountain_parsed = parse_Mountainscapes(elevation);
|
||||
mountainParsed = parse_Mountainscapes(elevation);
|
||||
|
||||
ocean_parsed = parse_Oceans(elevation);
|
||||
oceanParsed = parse_Oceans(elevation);
|
||||
|
||||
wind_field = map_Wind_Field();
|
||||
|
||||
precipitation_Chart = calculate_Rain_Shadows(elevation,ocean_parsed,wind_field);
|
||||
precipitationChart = calculate_Rain_Shadows(elevation,oceanParsed,wind_field);
|
||||
|
||||
temperature_Chart = generate_Temperature_Chart();
|
||||
temperatureChart = generate_Temperature_Chart();
|
||||
|
||||
climate_category = infer_Climate_Category();
|
||||
climateCategory = infer_Climate_Category();
|
||||
|
||||
determine_Continents();
|
||||
|
||||
@ -177,22 +177,24 @@ public class TerrainGen {
|
||||
elevation = land_exponential_filter(elevation);
|
||||
elevation = land_exponential_filter(elevation);
|
||||
elevation = land_exponential_filter(elevation);
|
||||
elevation = land_exponential_filter(elevation);
|
||||
elevation = land_exponential_filter(elevation);
|
||||
|
||||
mountain_parsed = new int[DIMENSION][DIMENSION];
|
||||
ocean_parsed = new int[DIMENSION][DIMENSION];
|
||||
continent_Number = new int[DIMENSION][DIMENSION];
|
||||
mountainParsed = new int[DIMENSION][DIMENSION];
|
||||
oceanParsed = new int[DIMENSION][DIMENSION];
|
||||
continentIdField = new int[DIMENSION][DIMENSION];
|
||||
|
||||
mountain_parsed = parse_Mountainscapes(elevation);
|
||||
mountainParsed = parse_Mountainscapes(elevation);
|
||||
|
||||
ocean_parsed = parse_Oceans(elevation);
|
||||
oceanParsed = parse_Oceans(elevation);
|
||||
|
||||
wind_field = map_Wind_Field();
|
||||
|
||||
precipitation_Chart = calculate_Rain_Shadows(elevation,ocean_parsed,wind_field);
|
||||
precipitationChart = calculate_Rain_Shadows(elevation,oceanParsed,wind_field);
|
||||
|
||||
temperature_Chart = generate_Temperature_Chart();
|
||||
temperatureChart = generate_Temperature_Chart();
|
||||
|
||||
climate_category = infer_Climate_Category();
|
||||
climateCategory = infer_Climate_Category();
|
||||
|
||||
determine_Continents();
|
||||
|
||||
@ -204,7 +206,14 @@ public class TerrainGen {
|
||||
|
||||
chunkRandomizer = getChunkRandomizer(modelInput, DIMENSION);
|
||||
|
||||
rVal = new TerrainModel(DIMENSION,modelInput,chunkRandomizer,dynamicInterpRatio);
|
||||
rVal = new TerrainModel(
|
||||
DIMENSION,
|
||||
modelInput,
|
||||
chunkRandomizer,
|
||||
OCEAN_THRESHOLD * verticalInterpolationRatio,
|
||||
MOUNTAIN_THRESHOLD * verticalInterpolationRatio,
|
||||
dynamicInterpRatio
|
||||
);
|
||||
|
||||
return rVal;
|
||||
}
|
||||
@ -359,7 +368,7 @@ public class TerrainGen {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
static int sum_Array(int[][] arr, int dim_x, int dim_y){
|
||||
static int sumIntegerArray(int[][] arr, int dim_x, int dim_y){
|
||||
int sum = 0;
|
||||
for(int x = 0; x < dim_x; x++){
|
||||
for(int y = 0; y < dim_y; y++){
|
||||
@ -631,7 +640,7 @@ public class TerrainGen {
|
||||
}
|
||||
|
||||
static void fill_Continents(){
|
||||
for(int i = 1; i < num_Continents + 1; i++){
|
||||
for(int i = 1; i < numberContinents + 1; i++){
|
||||
Continent current = new Continent();
|
||||
continents.add(current);
|
||||
//find dimensions
|
||||
@ -641,7 +650,7 @@ public class TerrainGen {
|
||||
int max_y = -1;
|
||||
for(int x = 0; x < DIMENSION; x++){
|
||||
for(int y = 0; y < DIMENSION; y++){
|
||||
if(continent_Number[x][y] == i){
|
||||
if(continentIdField[x][y] == i){
|
||||
if(min_x == -1){
|
||||
min_x = x;
|
||||
min_y = y;
|
||||
@ -686,12 +695,12 @@ public class TerrainGen {
|
||||
//fill continent level arrays
|
||||
for(int x = 0; x < DIMENSION; x++){
|
||||
for(int y = 0; y < DIMENSION; y++){
|
||||
if(continent_Number[x][y] == i){
|
||||
if(continentIdField[x][y] == i){
|
||||
current.size++;
|
||||
current.elevation[x-min_x][y-min_y] = elevation[x][y];
|
||||
current.chart_Climate[x-min_x][y-min_y] = climate_category[x][y];
|
||||
current.chart_Precipitation[x-min_x][y-min_y] = precipitation_Chart[x][y];
|
||||
current.chart_Temperature[x-min_x][y-min_y] = temperature_Chart[x][y];
|
||||
current.chart_Climate[x-min_x][y-min_y] = climateCategory[x][y];
|
||||
current.chart_Precipitation[x-min_x][y-min_y] = precipitationChart[x][y];
|
||||
current.chart_Temperature[x-min_x][y-min_y] = temperatureChart[x][y];
|
||||
current.chart_Wind_Macro[x-min_x][y-min_y] = wind_field[x][y].x;
|
||||
}
|
||||
}
|
||||
@ -700,7 +709,7 @@ public class TerrainGen {
|
||||
current.regions = new Region[dim_x][dim_y];
|
||||
for(int x = 0; x < dim_x; x++){
|
||||
for(int y = 0; y < dim_y; y++){
|
||||
if(continent_Number[x+min_x][y+min_y] == i){
|
||||
if(continentIdField[x+min_x][y+min_y] == i){
|
||||
current.regions[x][y] = new Region();
|
||||
current.regions[x][y].elevation_Goal = current.elevation[x][y];
|
||||
} else {
|
||||
@ -713,14 +722,14 @@ public class TerrainGen {
|
||||
}
|
||||
|
||||
static void floodfill_Continent_Number(int x, int y, int number){
|
||||
continent_Number[x][y] = number;
|
||||
continentIdField[x][y] = number;
|
||||
int offset_X[] = {0,-1,0,1};
|
||||
int offset_Y[] = {1,0,-1,0};
|
||||
for(int i = 0; i < 4; i++){
|
||||
if(x + offset_X[i] >= 0 && x + offset_Y[i] < DIMENSION){
|
||||
if(y + offset_Y[i] >= 0 && y + offset_Y[i] < DIMENSION){
|
||||
if(ocean_parsed[x + offset_X[i]][y + offset_Y[i]] < 25){
|
||||
if(continent_Number[x + offset_X[i]][y + offset_Y[i]] == 0){
|
||||
if(oceanParsed[x + offset_X[i]][y + offset_Y[i]] < 25){
|
||||
if(continentIdField[x + offset_X[i]][y + offset_Y[i]] == 0){
|
||||
floodfill_Continent_Number(x + offset_X[i], y + offset_Y[i], number);
|
||||
}
|
||||
}
|
||||
@ -732,10 +741,10 @@ public class TerrainGen {
|
||||
static void determine_Continents(){
|
||||
for(int x = 0; x < DIMENSION; x++){
|
||||
for(int y = 0; y < DIMENSION; y++){
|
||||
if(ocean_parsed[x][y] < 25){
|
||||
if(continent_Number[x][y] == 0){
|
||||
num_Continents++;
|
||||
floodfill_Continent_Number(x,y,num_Continents);
|
||||
if(oceanParsed[x][y] < 25){
|
||||
if(continentIdField[x][y] == 0){
|
||||
numberContinents++;
|
||||
floodfill_Continent_Number(x,y,numberContinents);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -755,26 +764,26 @@ public class TerrainGen {
|
||||
int rVal[][] = new int[DIMENSION][DIMENSION];
|
||||
for(int x = 0; x < DIMENSION; x++){
|
||||
for(int y = 0; y < DIMENSION; y++) {
|
||||
if (elevation[x][y] > ocean_Threshold) {
|
||||
if (elevation[x][y] > mountain_Threshold) {
|
||||
if (elevation[x][y] > OCEAN_THRESHOLD) {
|
||||
if (elevation[x][y] > MOUNTAIN_THRESHOLD) {
|
||||
rVal[x][y] = 6;
|
||||
} else {
|
||||
if (precipitation_Chart[x][y] > 0) {
|
||||
if (temperature_Chart[x][y] > 94) {
|
||||
if (precipitationChart[x][y] > 0) {
|
||||
if (temperatureChart[x][y] > 94) {
|
||||
rVal[x][y] = 1;
|
||||
} else if (temperature_Chart[x][y] > 80) {
|
||||
} else if (temperatureChart[x][y] > 80) {
|
||||
rVal[x][y] = 2;
|
||||
} else if (temperature_Chart[x][y] > 40) {
|
||||
} else if (temperatureChart[x][y] > 40) {
|
||||
rVal[x][y] = 3;
|
||||
} else {
|
||||
rVal[x][y] = 5;
|
||||
}
|
||||
} else {
|
||||
if (temperature_Chart[x][y] > 75) {
|
||||
if (temperatureChart[x][y] > 75) {
|
||||
rVal[x][y] = 4;
|
||||
} else if (temperature_Chart[x][y] > 40) {
|
||||
} else if (temperatureChart[x][y] > 40) {
|
||||
rVal[x][y] = 4;
|
||||
} else if (temperature_Chart[x][y] > 25) {
|
||||
} else if (temperatureChart[x][y] > 25) {
|
||||
rVal[x][y] = 5;
|
||||
} else {
|
||||
rVal[x][y] = 5;
|
||||
@ -782,11 +791,11 @@ public class TerrainGen {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (temperature_Chart[x][y] > 75) {
|
||||
if (temperatureChart[x][y] > 75) {
|
||||
rVal[x][y] = 0;
|
||||
} else if (temperature_Chart[x][y] > 40) {
|
||||
} else if (temperatureChart[x][y] > 40) {
|
||||
rVal[x][y] = 0;
|
||||
} else if (temperature_Chart[x][y] > 25) {
|
||||
} else if (temperatureChart[x][y] > 25) {
|
||||
rVal[x][y] = 0;
|
||||
} else {
|
||||
rVal[x][y] = 5;
|
||||
@ -829,21 +838,21 @@ public class TerrainGen {
|
||||
if (rain_Particles[x][y] >= 1) {
|
||||
if (wind_field[x][y].x == -1) {
|
||||
if (x > 0) {
|
||||
if (elevation_raws[x - 1][y] < rain_Shadow_Blocker_Height) {
|
||||
if (elevation_raws[x - 1][y] < RAIN_SHADOW_BLOCKER_HEIGHT) {
|
||||
rain_Particles[x - 1][y] = 1;
|
||||
rVal[x - 1][y] = 1;
|
||||
} else {
|
||||
}
|
||||
if (wind_field[x][y].y == -1) {
|
||||
if (y > 0) {
|
||||
if (elevation_raws[x - 1][y - 1] < rain_Shadow_Blocker_Height) {
|
||||
if (elevation_raws[x - 1][y - 1] < RAIN_SHADOW_BLOCKER_HEIGHT) {
|
||||
rain_Particles[x - 1][y - 1] = 1;
|
||||
rVal[x - 1][y - 1] = 1;
|
||||
}
|
||||
}
|
||||
} else if (wind_field[x][y].y == 1) {
|
||||
if (y < DIMENSION - 1) {
|
||||
if (elevation_raws[x - 1][y + 1] < rain_Shadow_Blocker_Height) {
|
||||
if (elevation_raws[x - 1][y + 1] < RAIN_SHADOW_BLOCKER_HEIGHT) {
|
||||
rain_Particles[x - 1][y + 1] = 1;
|
||||
rVal[x - 1][y + 1] = 1;
|
||||
}
|
||||
@ -853,21 +862,21 @@ public class TerrainGen {
|
||||
}
|
||||
} else {
|
||||
if (x < DIMENSION - 1) {
|
||||
if (elevation_raws[x + 1][y] < rain_Shadow_Blocker_Height) {
|
||||
if (elevation_raws[x + 1][y] < RAIN_SHADOW_BLOCKER_HEIGHT) {
|
||||
rain_Particles[x + 1][y] = 1;
|
||||
rVal[x + 1][y] = 1;
|
||||
} else {
|
||||
}
|
||||
if (wind_field[x][y].y == -1) {
|
||||
if (y > 0) {
|
||||
if (elevation_raws[x + 1][y - 1] < rain_Shadow_Blocker_Height) {
|
||||
if (elevation_raws[x + 1][y - 1] < RAIN_SHADOW_BLOCKER_HEIGHT) {
|
||||
rain_Particles[x + 1][y - 1] = 1;
|
||||
rVal[x + 1][y - 1] = 1;
|
||||
}
|
||||
}
|
||||
} else if (wind_field[x][y].y == 1) {
|
||||
if (y < DIMENSION - 1) {
|
||||
if (elevation_raws[x + 1][y + 1] < rain_Shadow_Blocker_Height) {
|
||||
if (elevation_raws[x + 1][y + 1] < RAIN_SHADOW_BLOCKER_HEIGHT) {
|
||||
rain_Particles[x + 1][y + 1] = 1;
|
||||
rVal[x + 1][y + 1] = 1;
|
||||
}
|
||||
@ -931,8 +940,8 @@ public class TerrainGen {
|
||||
int rVal[][] = new int[DIMENSION][DIMENSION];
|
||||
for(int x = 0; x < DIMENSION; x++){
|
||||
for(int y = 0; y < DIMENSION; y++){
|
||||
if(data[x][y] < ocean_Threshold){
|
||||
rVal[x][y] = ocean_Threshold;
|
||||
if(data[x][y] < OCEAN_THRESHOLD){
|
||||
rVal[x][y] = OCEAN_THRESHOLD;
|
||||
} else {
|
||||
rVal[x][y] = 0;
|
||||
}
|
||||
@ -945,8 +954,8 @@ public class TerrainGen {
|
||||
int rVal[][] = new int[DIMENSION][DIMENSION];
|
||||
for(int x = 0; x < DIMENSION; x++){
|
||||
for(int y = 0; y < DIMENSION; y++){
|
||||
if(data[x][y] > mountain_Threshold){
|
||||
rVal[x][y] = mountain_Threshold;
|
||||
if(data[x][y] > MOUNTAIN_THRESHOLD){
|
||||
rVal[x][y] = MOUNTAIN_THRESHOLD;
|
||||
} else {
|
||||
rVal[x][y] = 0;
|
||||
}
|
||||
@ -990,7 +999,7 @@ public class TerrainGen {
|
||||
for (int x = 0; x < DIMENSION; x++) {
|
||||
for (int y = 0; y < DIMENSION; y++) {
|
||||
rVal[x][y] = data[x][y];
|
||||
if (data[x][y] > mountain_Threshold) {
|
||||
if (data[x][y] > MOUNTAIN_THRESHOLD) {
|
||||
rVal[x][y] = rVal[x][y] - 5;
|
||||
// closed_Set = new int[DIMENSION][DIMENSION];
|
||||
// if (floodfill_Reach_Threshold(rVal, closed_Set, x, y, mountain_Threshold, 101) < mountain_Range_Size_Minimum) {
|
||||
@ -1194,16 +1203,16 @@ public class TerrainGen {
|
||||
int rVal[][] = new int[DIMENSION][DIMENSION];
|
||||
for(int x = 0; x < DIMENSION; x++){
|
||||
for(int y = 0; y < DIMENSION; y++){
|
||||
if(data[x][y] > TerrainGen.ocean_Threshold && data[x][y] < 90){
|
||||
if(data[x][y] > TerrainGen.OCEAN_THRESHOLD && data[x][y] < 90){
|
||||
|
||||
// System.out.print((data[x][y] - ocean_Threshold) + "/" + (100.0 - ocean_Threshold) + "=" + ((data[x][y] - ocean_Threshold) / (100.0 - ocean_Threshold)) + " ");
|
||||
// System.out.print(data[x][y] + "->");
|
||||
rVal[x][y] = (int)(data[x][y] * Math.exp(-(1.0 - ((data[x][y] - ocean_Threshold) / (100.0 - ocean_Threshold)))) * 0.2f + data[x][y] * 0.8f);
|
||||
if(rVal[x][y] < TerrainGen.ocean_Threshold){
|
||||
rVal[x][y] = TerrainGen.ocean_Threshold + 1;
|
||||
rVal[x][y] = (int)(data[x][y] * Math.exp(-(1.0 - ((data[x][y] - OCEAN_THRESHOLD) / (100.0 - OCEAN_THRESHOLD)))) * 0.2f + data[x][y] * 0.8f);
|
||||
if(rVal[x][y] < TerrainGen.OCEAN_THRESHOLD){
|
||||
rVal[x][y] = TerrainGen.OCEAN_THRESHOLD + 1;
|
||||
}
|
||||
// System.out.println(rVal[x][y]);
|
||||
if(Math.exp(-(1.0 - ((data[x][y] - ocean_Threshold) / (100.0 - ocean_Threshold)))) > 1.0){
|
||||
if(Math.exp(-(1.0 - ((data[x][y] - OCEAN_THRESHOLD) / (100.0 - OCEAN_THRESHOLD)))) > 1.0){
|
||||
System.out.println("WARNING!!");
|
||||
}
|
||||
} else {
|
||||
@ -1377,12 +1386,12 @@ public class TerrainGen {
|
||||
|
||||
public static void increment_Current_Continent(){
|
||||
current_Continent++;
|
||||
if (current_Continent > num_Continents - 1) {
|
||||
if (current_Continent > numberContinents - 1) {
|
||||
current_Continent = 0;
|
||||
}
|
||||
while(continents.get(current_Continent).size < 50){
|
||||
current_Continent++;
|
||||
if(current_Continent > num_Continents - 1){
|
||||
if(current_Continent > numberContinents - 1){
|
||||
current_Continent = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,9 @@ public class ServerTerrainManager {
|
||||
|
||||
int dynamicInterpolationRatio;
|
||||
|
||||
float randomDampener;
|
||||
float interpolationRandomDampener;
|
||||
|
||||
long seed;
|
||||
|
||||
TerrainModel model;
|
||||
|
||||
@ -41,13 +43,14 @@ public class ServerTerrainManager {
|
||||
|
||||
|
||||
|
||||
public ServerTerrainManager(int worldSizeDiscrete, int verticalInterpolationRatio, int dynamicInterpolationRatio, float randomDampener){
|
||||
public ServerTerrainManager(int worldSizeDiscrete, int verticalInterpolationRatio, int dynamicInterpolationRatio, float interpolationRandomDampener, long seed){
|
||||
this.worldSizeDiscrete = worldSizeDiscrete;
|
||||
this.verticalInterpolationRatio = verticalInterpolationRatio;
|
||||
this.dynamicInterpolationRatio = dynamicInterpolationRatio;
|
||||
this.elevationMapCache = new HashMap();
|
||||
this.elevationMapCacheContents = new ArrayList();
|
||||
this.randomDampener = randomDampener;
|
||||
this.interpolationRandomDampener = interpolationRandomDampener;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
ServerTerrainManager(){
|
||||
@ -61,7 +64,7 @@ public class ServerTerrainManager {
|
||||
rVal.dynamicInterpolationRatio = 100;
|
||||
rVal.elevationMapCache = new HashMap();
|
||||
rVal.elevationMapCacheContents = new ArrayList();
|
||||
rVal.randomDampener = 0.0f;
|
||||
rVal.interpolationRandomDampener = 0.0f;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -70,9 +73,9 @@ public class ServerTerrainManager {
|
||||
terrainGen.setInterpolationRatio(worldSizeDiscrete/200);
|
||||
terrainGen.setVerticalInterpolationRatio(verticalInterpolationRatio);
|
||||
terrainGen.setDynamicInterpolationRatio(dynamicInterpolationRatio);
|
||||
terrainGen.setRandomSeed(0);
|
||||
terrainGen.setRandomSeed(seed);
|
||||
model = terrainGen.generateModel();
|
||||
model.setRandomDampener(randomDampener);
|
||||
model.setInterpolationRandomDampener(interpolationRandomDampener);
|
||||
}
|
||||
|
||||
public void save(){
|
||||
@ -219,5 +222,9 @@ public class ServerTerrainManager {
|
||||
return new long[3][3];
|
||||
}
|
||||
}
|
||||
|
||||
public TerrainModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,25 +5,35 @@ import java.util.Random;
|
||||
public class TerrainModel {
|
||||
|
||||
int dynamicInterpolationRatio;
|
||||
float interpolationRandomDampener = 0.4f;
|
||||
|
||||
int discreteArrayDimension;
|
||||
|
||||
float[][] elevation;
|
||||
|
||||
long[][] chunkRandomizer;
|
||||
|
||||
float randomDampener = 0.4f;
|
||||
float realMountainThreshold;
|
||||
float realOceanThreshold;
|
||||
|
||||
|
||||
TerrainModel() {
|
||||
|
||||
}
|
||||
|
||||
public TerrainModel(int dimension, float[][] elevation, long[][] chunkRandomizer, int dynamicInterpolationRatio){
|
||||
public TerrainModel(
|
||||
int dimension,
|
||||
float[][] elevation,
|
||||
long[][] chunkRandomizer,
|
||||
float realOceanThreshold,
|
||||
float realMountainThreshold,
|
||||
int dynamicInterpolationRatio
|
||||
){
|
||||
|
||||
this.dynamicInterpolationRatio = dynamicInterpolationRatio;
|
||||
this.discreteArrayDimension = dimension;
|
||||
this.elevation = elevation;
|
||||
this.chunkRandomizer = chunkRandomizer;
|
||||
this.realMountainThreshold = realMountainThreshold;
|
||||
this.realOceanThreshold = realOceanThreshold;
|
||||
|
||||
}
|
||||
|
||||
@ -38,8 +48,8 @@ public class TerrainModel {
|
||||
return elevation;
|
||||
}
|
||||
|
||||
public void setRandomDampener(float f){
|
||||
randomDampener = f;
|
||||
public void setInterpolationRandomDampener(float f){
|
||||
interpolationRandomDampener = f;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,11 +316,19 @@ public class TerrainModel {
|
||||
}
|
||||
|
||||
public float getRandomDampener(){
|
||||
return randomDampener;
|
||||
return interpolationRandomDampener;
|
||||
}
|
||||
|
||||
public int getDynamicInterpolationRatio(){
|
||||
return dynamicInterpolationRatio;
|
||||
}
|
||||
|
||||
public float getRealMountainThreshold() {
|
||||
return realMountainThreshold;
|
||||
}
|
||||
|
||||
public float getRealOceanThreshold() {
|
||||
return realOceanThreshold;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import electrosphere.game.collision.CollisionEngine;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.game.client.drawcell.DrawCellManager;
|
||||
import electrosphere.game.client.player.ClientPlayerData;
|
||||
import electrosphere.game.client.terrain.manager.ClientTerrainManager;
|
||||
import electrosphere.game.client.world.ClientWorldData;
|
||||
import electrosphere.game.collision.CommonWorldData;
|
||||
@ -106,6 +107,7 @@ public class LoadingThread extends Thread {
|
||||
//initialize the client thread (client)
|
||||
if(FLAG_INIT_CLIENT){
|
||||
initClientThread();
|
||||
stallForClientPlayerData();
|
||||
}
|
||||
|
||||
//init client terrain manager
|
||||
@ -168,6 +170,7 @@ public class LoadingThread extends Thread {
|
||||
//initialize the client thread (client)
|
||||
if(FLAG_INIT_CLIENT){
|
||||
initClientThread();
|
||||
stallForClientPlayerData();
|
||||
}
|
||||
|
||||
//init client terrain manager
|
||||
@ -233,7 +236,7 @@ public class LoadingThread extends Thread {
|
||||
Actually initialize the terrain manager
|
||||
*/
|
||||
float[][] elevation;
|
||||
Globals.serverTerrainManager = new ServerTerrainManager(2000,200,100,0.25f);
|
||||
Globals.serverTerrainManager = new ServerTerrainManager(2000,200,100,0.25f,0);
|
||||
if(Globals.mainConfig.runServer){
|
||||
if(Globals.mainConfig.loadTerrain){
|
||||
Globals.serverTerrainManager.load();
|
||||
@ -331,15 +334,23 @@ public class LoadingThread extends Thread {
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void stallForClientPlayerData(){
|
||||
while(!Globals.clientPlayerData.hasLoaded()){
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(5);
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void initDynamicCellManager(){
|
||||
Globals.drawCellManager = new DrawCellManager(
|
||||
Globals.clientWorldData,
|
||||
Globals.clientTerrainManager,
|
||||
Globals.spawnPoint.x,
|
||||
Globals.spawnPoint.z
|
||||
Globals.clientPlayerData.getInitialDiscretePositionX(),
|
||||
Globals.clientPlayerData.getInitialDiscretePositionY()
|
||||
// Globals.terrainManager.getDynamicInterpolationRatio(),
|
||||
// Globals.terrainManager.getRandomDampener()
|
||||
);
|
||||
|
||||
@ -18,6 +18,7 @@ import electrosphere.entity.types.creature.creaturemap.CreatureType;
|
||||
import electrosphere.entity.types.creature.creaturemap.CreatureTypeList;
|
||||
import electrosphere.entity.types.hitbox.HitboxManager;
|
||||
import electrosphere.game.client.drawcell.DrawCellManager;
|
||||
import electrosphere.game.client.player.ClientPlayerData;
|
||||
import electrosphere.game.client.terrain.manager.ClientTerrainManager;
|
||||
import electrosphere.game.client.world.ClientWorldData;
|
||||
import electrosphere.game.collision.CommonWorldData;
|
||||
@ -182,6 +183,9 @@ public class Globals {
|
||||
//client terrain manager
|
||||
public static ClientTerrainManager clientTerrainManager;
|
||||
|
||||
//client player data
|
||||
public static ClientPlayerData clientPlayerData = new ClientPlayerData();
|
||||
|
||||
//chunk stuff
|
||||
//constant for how far in game units you have to move to load chunks
|
||||
public static DrawCellManager drawCellManager;
|
||||
|
||||
@ -113,7 +113,7 @@ public class Main {
|
||||
Globals.initGlobals();
|
||||
|
||||
//debug: create terrain/world viewer
|
||||
TerrainViewer.runViewer();
|
||||
// TerrainViewer.runViewer();
|
||||
|
||||
//create the drawing context
|
||||
Globals.renderingEngine = new RenderingEngine();
|
||||
|
||||
@ -86,6 +86,9 @@ public class ClientProtocol {
|
||||
Main.playerId = message.getplayerID();
|
||||
System.out.println("Player ID is " + Main.playerId);
|
||||
break;
|
||||
case SETINITIALDISCRETEPOSITION:
|
||||
Globals.clientPlayerData.setInitialDiscretePosition(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -74,6 +74,11 @@ ENTITY_MESSAGE,
|
||||
rVal = PlayerMessage.parseSet_IDMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.PLAYER_MESSAGE_TYPE_SETINITIALDISCRETEPOSITION:
|
||||
if(PlayerMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = PlayerMessage.parseSetInitialDiscretePositionMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TypeBytes.MESSAGE_TYPE_ENTITY:
|
||||
|
||||
@ -7,10 +7,13 @@ public class PlayerMessage extends NetworkMessage {
|
||||
|
||||
public enum PlayerMessageType {
|
||||
SET_ID,
|
||||
SETINITIALDISCRETEPOSITION,
|
||||
}
|
||||
|
||||
PlayerMessageType messageType;
|
||||
int playerID;
|
||||
int initialDiscretePositionX;
|
||||
int initialDiscretePositionY;
|
||||
|
||||
PlayerMessage(PlayerMessageType messageType){
|
||||
this.type = MessageType.PLAYER_MESSAGE;
|
||||
@ -29,6 +32,22 @@ public class PlayerMessage extends NetworkMessage {
|
||||
this.playerID = playerID;
|
||||
}
|
||||
|
||||
public int getinitialDiscretePositionX() {
|
||||
return initialDiscretePositionX;
|
||||
}
|
||||
|
||||
public void setinitialDiscretePositionX(int initialDiscretePositionX) {
|
||||
this.initialDiscretePositionX = initialDiscretePositionX;
|
||||
}
|
||||
|
||||
public int getinitialDiscretePositionY() {
|
||||
return initialDiscretePositionY;
|
||||
}
|
||||
|
||||
public void setinitialDiscretePositionY(int initialDiscretePositionY) {
|
||||
this.initialDiscretePositionY = initialDiscretePositionY;
|
||||
}
|
||||
|
||||
static void stripPacketHeader(List<Byte> byteStream){
|
||||
byteStream.remove(0);
|
||||
byteStream.remove(0);
|
||||
@ -42,6 +61,12 @@ public class PlayerMessage extends NetworkMessage {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
case TypeBytes.PLAYER_MESSAGE_TYPE_SETINITIALDISCRETEPOSITION:
|
||||
if(byteStream.size() >= TypeBytes.PLAYER_MESSAGE_TYPE_SETINITIALDISCRETEPOSITION_SIZE){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -60,6 +85,22 @@ public class PlayerMessage extends NetworkMessage {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static PlayerMessage parseSetInitialDiscretePositionMessage(List<Byte> byteStream){
|
||||
PlayerMessage rVal = new PlayerMessage(PlayerMessageType.SETINITIALDISCRETEPOSITION);
|
||||
stripPacketHeader(byteStream);
|
||||
rVal.setinitialDiscretePositionX(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
rVal.setinitialDiscretePositionY(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static PlayerMessage constructSetInitialDiscretePositionMessage(int initialDiscretePositionX,int initialDiscretePositionY){
|
||||
PlayerMessage rVal = new PlayerMessage(PlayerMessageType.SETINITIALDISCRETEPOSITION);
|
||||
rVal.setinitialDiscretePositionX(initialDiscretePositionX);
|
||||
rVal.setinitialDiscretePositionY(initialDiscretePositionY);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
void serialize(){
|
||||
byte[] intValues = new byte[8];
|
||||
@ -75,6 +116,21 @@ public class PlayerMessage extends NetworkMessage {
|
||||
rawBytes[2+i] = intValues[i];
|
||||
}
|
||||
break;
|
||||
case SETINITIALDISCRETEPOSITION:
|
||||
rawBytes = new byte[TypeBytes.PLAYER_MESSAGE_TYPE_SETINITIALDISCRETEPOSITION_SIZE];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_PLAYER;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.PLAYER_MESSAGE_TYPE_SETINITIALDISCRETEPOSITION;
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(initialDiscretePositionX);
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[2+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(initialDiscretePositionY);
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[6+i] = intValues[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
serialized = true;
|
||||
}
|
||||
|
||||
@ -35,10 +35,12 @@ Message categories
|
||||
Player subcategories
|
||||
*/
|
||||
public static final byte PLAYER_MESSAGE_TYPE_SET_ID = 0;
|
||||
public static final byte PLAYER_MESSAGE_TYPE_SETINITIALDISCRETEPOSITION = 1;
|
||||
/*
|
||||
Player packet sizes
|
||||
*/
|
||||
public static final byte PLAYER_MESSAGE_TYPE_SET_ID_SIZE = 6;
|
||||
public static final byte PLAYER_MESSAGE_TYPE_SETINITIALDISCRETEPOSITION_SIZE = 10;
|
||||
/*
|
||||
Entity subcategories
|
||||
*/
|
||||
|
||||
@ -14,11 +14,11 @@ public class ByteStreamUtils {
|
||||
public static int popIntFromByteQueue(List<Byte> queue){
|
||||
int rVal = -1;
|
||||
integerCompactor.clear();
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.flip();
|
||||
integerCompactor.put(0,queue.remove(0));
|
||||
integerCompactor.put(1,queue.remove(0));
|
||||
integerCompactor.put(2,queue.remove(0));
|
||||
integerCompactor.put(3,queue.remove(0));
|
||||
integerCompactor.position(0);
|
||||
rVal = integerCompactor.getInt();
|
||||
return rVal;
|
||||
}
|
||||
@ -26,11 +26,11 @@ public class ByteStreamUtils {
|
||||
public static float popFloatFromByteQueue(List<Byte> queue){
|
||||
float rVal = -1;
|
||||
integerCompactor.clear();
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.flip();
|
||||
integerCompactor.put(0,queue.remove(0));
|
||||
integerCompactor.put(1,queue.remove(0));
|
||||
integerCompactor.put(2,queue.remove(0));
|
||||
integerCompactor.put(3,queue.remove(0));
|
||||
integerCompactor.position(0);
|
||||
rVal = integerCompactor.getFloat();
|
||||
return rVal;
|
||||
}
|
||||
@ -38,15 +38,15 @@ public class ByteStreamUtils {
|
||||
public static long popLongFromByteQueue(List<Byte> queue){
|
||||
long rVal = -1;
|
||||
integerCompactor.clear();
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.put(queue.remove(0));
|
||||
integerCompactor.flip();
|
||||
integerCompactor.put(0,queue.remove(0));
|
||||
integerCompactor.put(1,queue.remove(0));
|
||||
integerCompactor.put(2,queue.remove(0));
|
||||
integerCompactor.put(3,queue.remove(0));
|
||||
integerCompactor.put(4,queue.remove(0));
|
||||
integerCompactor.put(5,queue.remove(0));
|
||||
integerCompactor.put(6,queue.remove(0));
|
||||
integerCompactor.put(7,queue.remove(0));
|
||||
integerCompactor.position(0);
|
||||
rVal = integerCompactor.getLong();
|
||||
return rVal;
|
||||
}
|
||||
@ -55,11 +55,11 @@ public class ByteStreamUtils {
|
||||
byte[] rVal = new byte[4];
|
||||
integerCompactor.clear();
|
||||
integerCompactor.putInt(i);
|
||||
integerCompactor.flip();
|
||||
rVal[0] = integerCompactor.get();
|
||||
rVal[1] = integerCompactor.get();
|
||||
rVal[2] = integerCompactor.get();
|
||||
rVal[3] = integerCompactor.get();
|
||||
integerCompactor.position(0);
|
||||
rVal[0] = integerCompactor.get(0);
|
||||
rVal[1] = integerCompactor.get(1);
|
||||
rVal[2] = integerCompactor.get(2);
|
||||
rVal[3] = integerCompactor.get(3);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -67,11 +67,11 @@ public class ByteStreamUtils {
|
||||
byte[] rVal = new byte[4];
|
||||
integerCompactor.clear();
|
||||
integerCompactor.putFloat(i);
|
||||
integerCompactor.flip();
|
||||
rVal[0] = integerCompactor.get();
|
||||
rVal[1] = integerCompactor.get();
|
||||
rVal[2] = integerCompactor.get();
|
||||
rVal[3] = integerCompactor.get();
|
||||
integerCompactor.position(0);
|
||||
rVal[0] = integerCompactor.get(0);
|
||||
rVal[1] = integerCompactor.get(1);
|
||||
rVal[2] = integerCompactor.get(2);
|
||||
rVal[3] = integerCompactor.get(3);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -79,15 +79,15 @@ public class ByteStreamUtils {
|
||||
byte[] rVal = new byte[8];
|
||||
integerCompactor.clear();
|
||||
integerCompactor.putLong(i);
|
||||
integerCompactor.flip();
|
||||
rVal[0] = integerCompactor.get();
|
||||
rVal[1] = integerCompactor.get();
|
||||
rVal[2] = integerCompactor.get();
|
||||
rVal[3] = integerCompactor.get();
|
||||
rVal[4] = integerCompactor.get();
|
||||
rVal[5] = integerCompactor.get();
|
||||
rVal[6] = integerCompactor.get();
|
||||
rVal[7] = integerCompactor.get();
|
||||
integerCompactor.position(0);
|
||||
rVal[0] = integerCompactor.get(0);
|
||||
rVal[1] = integerCompactor.get(1);
|
||||
rVal[2] = integerCompactor.get(2);
|
||||
rVal[3] = integerCompactor.get(3);
|
||||
rVal[4] = integerCompactor.get(4);
|
||||
rVal[5] = integerCompactor.get(5);
|
||||
rVal[6] = integerCompactor.get(6);
|
||||
rVal[7] = integerCompactor.get(7);
|
||||
return rVal;
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,6 +114,13 @@ public class ServerConnectionHandler implements Runnable {
|
||||
(int)Globals.serverWorldData.getWorldBoundMax().z
|
||||
)
|
||||
);
|
||||
//set client initial discrete position
|
||||
networkParser.addOutgoingMessage(
|
||||
PlayerMessage.constructSetInitialDiscretePositionMessage(
|
||||
Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x),
|
||||
Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z)
|
||||
)
|
||||
);
|
||||
//tell them what player stats they are
|
||||
networkParser.addOutgoingMessage(PlayerMessage.constructSet_IDMessage(playerID));
|
||||
//figure out what chunk they're in
|
||||
|
||||
@ -1,12 +1,21 @@
|
||||
package electrosphere.util.worldviewer;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import electrosphere.game.server.simulation.Simulation;
|
||||
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
||||
import electrosphere.game.server.terrain.models.TerrainModel;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.main.Main;
|
||||
import electrosphere.util.Utilities;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@ -21,20 +30,30 @@ public class TerrainViewer {
|
||||
|
||||
|
||||
public static void runViewer(){
|
||||
TerrainModel terrainModel = Utilities.loadObjectFromBakedJsonFile("/Config/terrain.json", TerrainModel.class);
|
||||
float[][] elevationMacro = terrainModel.getElevation();
|
||||
|
||||
TerrainModel terrainModel;
|
||||
|
||||
// ServerTerrainManager terrainManager = new ServerTerrainManager(2000, 1000, 100, 0.05f, new Random().nextLong());
|
||||
// terrainManager.generate();
|
||||
// terrainModel = terrainManager.getModel();
|
||||
|
||||
// Utilities.saveObjectToBakedJsonFile("/Config/testingTerrain.json", terrainModel);
|
||||
terrainModel = Utilities.loadObjectFromBakedJsonFile("/Config/testingTerrain.json", TerrainModel.class);
|
||||
|
||||
Simulation simulation = new Simulation();
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
TerrainViewerJComponent jComponent = new TerrainViewerJComponent(elevationMacro);
|
||||
TerrainViewerJComponent jComponent = new TerrainViewerJComponent(terrainModel);
|
||||
frame.add(jComponent);
|
||||
frame.addKeyListener(new TerrainViewerKeyListener(jComponent));
|
||||
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setBounds(0, 0, 600, 600);
|
||||
frame.setBounds(0, 0, 1050, 1050);
|
||||
frame.setVisible(true);
|
||||
|
||||
while(true){
|
||||
frame.repaint();
|
||||
simulation.simulate();
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(10);
|
||||
} catch (InterruptedException ex) {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package electrosphere.util.worldviewer;
|
||||
|
||||
import electrosphere.game.server.terrain.models.TerrainModel;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.JComponent;
|
||||
@ -10,39 +11,61 @@ import javax.swing.JComponent;
|
||||
*/
|
||||
public class TerrainViewerJComponent extends JComponent {
|
||||
|
||||
TerrainModel model;
|
||||
float elevationMap[][];
|
||||
float maxHeight = 0;
|
||||
int dimX;
|
||||
int dimY;
|
||||
|
||||
float oceanThreshold;
|
||||
float mountainThreshold;
|
||||
|
||||
int viewerOffsetX = 0;
|
||||
int viewerOffsetY = 0;
|
||||
|
||||
public TerrainViewerJComponent(float[][] elevationMap){
|
||||
this.elevationMap = elevationMap;
|
||||
public TerrainViewerJComponent(TerrainModel model){
|
||||
this.model = model;
|
||||
this.elevationMap = model.getElevation();
|
||||
dimX = elevationMap.length;
|
||||
dimY = elevationMap[0].length;
|
||||
|
||||
float counter = 0;
|
||||
float average = 0;
|
||||
for(int x = 0; x < dimX; x++){
|
||||
for(int y = 0; y < dimY; y++){
|
||||
counter++;
|
||||
if(elevationMap[x][y] > maxHeight){
|
||||
maxHeight = elevationMap[x][y];
|
||||
}
|
||||
average = average + elevationMap[x][y] * 1.0f / counter;
|
||||
}
|
||||
}
|
||||
|
||||
this.oceanThreshold = model.getRealOceanThreshold();
|
||||
this.mountainThreshold = model.getRealMountainThreshold();
|
||||
|
||||
System.out.println("Ocean Threshold: " + oceanThreshold);
|
||||
System.out.println("Mountain Threshold: " + mountainThreshold);
|
||||
System.out.println("Average: " + average);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g){
|
||||
g.clearRect(0, 0, 600, 600);
|
||||
for(int x = 0; x < dimX/4; x++){
|
||||
for(int y = 0; y < dimY/4; y++){
|
||||
g.clearRect(0, 0, 1050, 1050);
|
||||
for(int x = 0; x < dimX/2; x++){
|
||||
for(int y = 0; y < dimY/2; y++){
|
||||
g.setColor(new Color(
|
||||
(int)(255 * elevationMap[x*4][y*4] / maxHeight),
|
||||
(int)(255 * elevationMap[x*4][y*4] / maxHeight),
|
||||
(int)(255 * elevationMap[x*4][y*4] / maxHeight)
|
||||
(int)(50 + 205 * elevationMap[x*2][y*2] / maxHeight),
|
||||
(int)(100 + 155 * elevationMap[x*2][y*2] / maxHeight),
|
||||
(int)(255 * elevationMap[x*2][y*2] / maxHeight)
|
||||
));
|
||||
if(elevationMap[x*2][y*2] <= oceanThreshold){
|
||||
g.setColor(new Color(
|
||||
(int)(255 * elevationMap[x*2][y*2] / maxHeight),
|
||||
(int)(100 + 155 * elevationMap[x*2][y*2] / maxHeight),
|
||||
(int)(150 + 105 * elevationMap[x*2][y*2] / maxHeight)
|
||||
));
|
||||
}
|
||||
g.drawRect(x - viewerOffsetX, y - viewerOffsetY, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
1
src/main/resources/Config/testingTerrain.json
Normal file
1
src/main/resources/Config/testingTerrain.json
Normal file
File diff suppressed because one or more lines are too long
10
src/main/resources/Data/civilizations.json
Normal file
10
src/main/resources/Data/civilizations.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"Civilizations" : [
|
||||
{
|
||||
"name" : "Humans",
|
||||
"allowedCreatures" : [
|
||||
"Human"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
39
src/main/resources/Data/creatures.json
Normal file
39
src/main/resources/Data/creatures.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"creatures" : [
|
||||
{
|
||||
"name" : "Human",
|
||||
"bodyParts" : [
|
||||
{
|
||||
"name" : "Head",
|
||||
"type" : "Head",
|
||||
"size" : 1
|
||||
},
|
||||
{
|
||||
"name" : "Torso",
|
||||
"type" : "Torso",
|
||||
"size" : 1
|
||||
},
|
||||
{
|
||||
"name" : "ArmLeft",
|
||||
"type" : "Arm",
|
||||
"size" : 1
|
||||
},
|
||||
{
|
||||
"name" : "ArmRight",
|
||||
"type" : "Arm",
|
||||
"size" : 1
|
||||
},
|
||||
{
|
||||
"name" : "LegLeft",
|
||||
"type" : "Leg",
|
||||
"size" : 1
|
||||
},
|
||||
{
|
||||
"name" : "LegRight",
|
||||
"type" : "Leg",
|
||||
"size" : 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -220,6 +220,14 @@
|
||||
{
|
||||
"name" : "playerID",
|
||||
"type" : "FIXED_INT"
|
||||
},
|
||||
{
|
||||
"name" : "initialDiscretePositionX",
|
||||
"type" : "FIXED_INT"
|
||||
},
|
||||
{
|
||||
"name" : "initialDiscretePositionY",
|
||||
"type" : "FIXED_INT"
|
||||
}
|
||||
],
|
||||
"messageTypes" : [
|
||||
@ -228,8 +236,14 @@
|
||||
"data" : [
|
||||
"playerID"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "SetInitialDiscretePosition",
|
||||
"data" : [
|
||||
"initialDiscretePositionX",
|
||||
"initialDiscretePositionY"
|
||||
]
|
||||
}
|
||||
|
||||
]
|
||||
},
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user