mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
reformat code
- fix color identity - service pool is working good on android now so use it on generating map
This commit is contained in:
@@ -46,16 +46,15 @@ public class World implements Disposable, SaveFileContent {
|
||||
private boolean worldDataLoaded = false;
|
||||
private Texture globalTexture = null;
|
||||
|
||||
public Random getRandom()
|
||||
{
|
||||
public Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
static public int highestBiome(long biome) {
|
||||
return (int) (Math.log(Long.highestOneBit(biome)) / Math.log(2));
|
||||
}
|
||||
|
||||
public boolean collidingTile(Rectangle boundingRect)
|
||||
{
|
||||
public boolean collidingTile(Rectangle boundingRect) {
|
||||
|
||||
int xLeft = (int) boundingRect.getX() / getTileSize();
|
||||
int yTop = (int) boundingRect.getY() / getTileSize();
|
||||
@@ -73,6 +72,7 @@ public class World implements Disposable, SaveFileContent {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void loadWorldData() {
|
||||
if (worldDataLoaded)
|
||||
return;
|
||||
@@ -105,7 +105,6 @@ public class World implements Disposable, SaveFileContent {
|
||||
terrainMap = (int[][]) saveFileData.readObject("terrainMap");
|
||||
|
||||
|
||||
|
||||
width = saveFileData.readInt("width");
|
||||
height = saveFileData.readInt("height");
|
||||
mapObjectIds = new SpritesDataMap(getChunkSize(), this.data.tileSize, this.data.width / getChunkSize());
|
||||
@@ -137,6 +136,7 @@ public class World implements Disposable, SaveFileContent {
|
||||
public BiomeSpriteData getObject(int id) {
|
||||
return mapObjectIds.get(id);
|
||||
}
|
||||
|
||||
private class DrawingInformation {
|
||||
|
||||
private int neighbors;
|
||||
@@ -154,6 +154,7 @@ public class World implements Disposable, SaveFileContent {
|
||||
regions.drawPixmapOn(terrain, neighbors, drawingPixmap);
|
||||
}
|
||||
}
|
||||
|
||||
public Pixmap getBiomeSprite(int x, int y) {
|
||||
if (x < 0 || y <= 0 || x >= width || y > height)
|
||||
return new Pixmap(data.tileSize, data.tileSize, Pixmap.Format.RGBA8888);
|
||||
@@ -188,8 +189,7 @@ public class World implements Disposable, SaveFileContent {
|
||||
bitIndex--;
|
||||
}
|
||||
}
|
||||
if(biomeTerrain!=0&&neighbors!=0b111_111_111)
|
||||
{
|
||||
if (biomeTerrain != 0 && neighbors != 0b111_111_111) {
|
||||
bitIndex = 8;
|
||||
int baseNeighbors = 0;
|
||||
for (int ny = 1; ny > -2; ny--) {
|
||||
@@ -206,8 +206,7 @@ public class World implements Disposable, SaveFileContent {
|
||||
}
|
||||
int lastFullNeighbour = -1;
|
||||
int counter = 0;
|
||||
for(DrawingInformation info:information)
|
||||
{
|
||||
for (DrawingInformation info : information) {
|
||||
if (info.neighbors == 0b111_111_111)
|
||||
lastFullNeighbour = counter;
|
||||
counter++;
|
||||
@@ -216,10 +215,8 @@ public class World implements Disposable, SaveFileContent {
|
||||
counter = 0;
|
||||
if (lastFullNeighbour < 0 && information.size() != 0)
|
||||
information.get(0).neighbors = 0b111_111_111;
|
||||
for(DrawingInformation info:information)
|
||||
{
|
||||
if(counter<lastFullNeighbour)
|
||||
{
|
||||
for (DrawingInformation info : information) {
|
||||
if (counter < lastFullNeighbour) {
|
||||
counter++;
|
||||
continue;
|
||||
}
|
||||
@@ -236,6 +233,7 @@ public class World implements Disposable, SaveFileContent {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isStructure(int x, int y) {
|
||||
try {
|
||||
return (terrainMap[x][height - y - 1] & ~isStructureBit) != 0;
|
||||
@@ -259,31 +257,30 @@ public class World implements Disposable, SaveFileContent {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public WorldData getData() {
|
||||
return data;
|
||||
}
|
||||
private void clearTerrain(int x,int y,int size)
|
||||
{
|
||||
|
||||
private void clearTerrain(int x, int y, int size) {
|
||||
|
||||
for (int xclear = -size; xclear < size; xclear++)
|
||||
for(int yclear=-size;yclear<size;yclear++)
|
||||
{
|
||||
for (int yclear = -size; yclear < size; yclear++) {
|
||||
try {
|
||||
|
||||
terrainMap[x + xclear][height - 1 - (y + yclear)] = 0;
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e)
|
||||
{
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
private long measureGenerationTime(String msg,long lastTime)
|
||||
{
|
||||
|
||||
private long measureGenerationTime(String msg, long lastTime) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
System.out.print("\n" + msg + " :\t\t" + ((currentTime - lastTime) / 1000f) + " s");
|
||||
return currentTime;
|
||||
}
|
||||
|
||||
public World generateNew(long seed) {
|
||||
if (GuiBase.isAndroid())
|
||||
GuiBase.getInterface().preventSystemSleep(true);
|
||||
@@ -328,15 +325,6 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
int biomeHeight = (int) Math.round(biome.height * (double) height);
|
||||
for (BiomeStructureData data : biome.structures) {
|
||||
long localSeed = seed;
|
||||
if (GuiBase.isAndroid()) {
|
||||
FThreads.invokeInEdtNowOrLater(() -> {
|
||||
long threadStartTime = System.currentTimeMillis();
|
||||
BiomeStructure structure = new BiomeStructure(data, localSeed, biomeWidth, biomeHeight);
|
||||
structure.initialize();
|
||||
structureDataMap.put(data, structure);
|
||||
measureGenerationTime("wavefunctioncollapse " + data.sourcePath, threadStartTime);
|
||||
});
|
||||
} else {
|
||||
ThreadUtil.getServicePool().submit(() -> {
|
||||
long threadStartTime = System.currentTimeMillis();
|
||||
BiomeStructure structure = new BiomeStructure(data, localSeed, biomeWidth, biomeHeight);
|
||||
@@ -347,7 +335,6 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FThreads.invokeInEdtNowOrLater(() -> {
|
||||
for (BiomeData biome : data.GetBiomes()) {
|
||||
|
||||
@@ -387,13 +374,10 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
biomeMap[x][y] |= (1L << biomeIndex[0]);
|
||||
int terrainCounter = 1;
|
||||
terrainMap[x][y] = 0;
|
||||
if(biome.terrain!=null)
|
||||
{
|
||||
for(BiomeTerrainData terrain:biome.terrain)
|
||||
{
|
||||
if (biome.terrain != null) {
|
||||
for (BiomeTerrainData terrain : biome.terrain) {
|
||||
float terrainNoise = ((float) noise.eval(x / (float) width * (noiseZoom * terrain.resolution), y / (float) height * (noiseZoom * terrain.resolution)) + 1) / 2;
|
||||
if(terrainNoise>=terrain.min&&terrainNoise<=terrain.max)
|
||||
{
|
||||
if (terrainNoise >= terrain.min && terrainNoise <= terrain.max) {
|
||||
terrainMap[x][y] = terrainCounter;
|
||||
}
|
||||
terrainCounter++;
|
||||
@@ -401,10 +385,8 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
}
|
||||
if (biome.collision)
|
||||
terrainMap[x][y] |= collisionBit;
|
||||
if(biome.structures!=null)
|
||||
{
|
||||
for(BiomeStructureData data:biome.structures)
|
||||
{
|
||||
if (biome.structures != null) {
|
||||
for (BiomeStructureData data : biome.structures) {
|
||||
while (!structureDataMap.containsKey(data)) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
@@ -418,8 +400,7 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
int structureYStart = y - (biomeYStart - biomeHeight / 2) - (int) ((data.y * biomeHeight) - (data.height * biomeHeight / 2));
|
||||
|
||||
int structureIndex = structure.objectID(structureXStart, structureYStart);
|
||||
if(structureIndex>=0)
|
||||
{
|
||||
if (structureIndex >= 0) {
|
||||
pix.setColor(data.mappingInfo[structureIndex].getColor());
|
||||
pix.drawPixel(x, y);
|
||||
terrainMap[x][y] = terrainCounter + structureIndex;
|
||||
@@ -462,8 +443,7 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
y *= (biome.height * height / 2);
|
||||
y += (height - (biome.startPointY * height));
|
||||
|
||||
if((int)x<0||(int)y<=0||(int)y>=height||(int)x>=width|| biomeIndex2!= highestBiome(getBiome((int)x,(int)y)))
|
||||
{
|
||||
if ((int) x < 0 || (int) y <= 0 || (int) y >= height || (int) x >= width || biomeIndex2 != highestBiome(getBiome((int) x, (int) y))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -477,36 +457,29 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (breakNextLoop)
|
||||
{
|
||||
if (breakNextLoop) {
|
||||
boolean foundSolution = false;
|
||||
boolean noSolution = false;
|
||||
breakNextLoop = false;
|
||||
for(int xi=-1;xi<2&&!foundSolution;xi++)
|
||||
{
|
||||
for(int yi=-1;yi<2&&!foundSolution;yi++)
|
||||
{
|
||||
for (int xi = -1; xi < 2 && !foundSolution; xi++) {
|
||||
for (int yi = -1; yi < 2 && !foundSolution; yi++) {
|
||||
for (Rectangle rect : otherPoints) {
|
||||
if (rect.contains(x + xi * data.tileSize, y + yi * data.tileSize)) {
|
||||
noSolution = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!noSolution)
|
||||
{
|
||||
if (!noSolution) {
|
||||
foundSolution = true;
|
||||
x = x + xi * data.tileSize;
|
||||
y = y + yi * data.tileSize;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!foundSolution)
|
||||
{
|
||||
if(counter==499)
|
||||
{
|
||||
if (!foundSolution) {
|
||||
if (counter == 499) {
|
||||
System.err.print("Can not place POI " + poi.name + "\n");
|
||||
}
|
||||
continue;
|
||||
@@ -525,9 +498,7 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
|
||||
if (poi.type != null && poi.type.equals("town")) {
|
||||
towns.add(newPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
notTowns.add(newPoint);
|
||||
}
|
||||
break;
|
||||
@@ -610,8 +581,7 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
int sy = startY < y1 ? 1 : -1;
|
||||
int err = dx - dy;
|
||||
int e2;
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
if (startX < 0 || startY <= 0 || startX >= width || startY > height) continue;
|
||||
if ((terrainMap[startX][height - startY] & collisionBit) != 0)//clear terrain if it has collision
|
||||
terrainMap[startX][height - startY] = 0;
|
||||
@@ -620,13 +590,10 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
if (startX == x1 && startY == y1)
|
||||
break;
|
||||
e2 = 2 * err;
|
||||
if (e2 > -dy)
|
||||
{
|
||||
if (e2 > -dy) {
|
||||
err = err - dy;
|
||||
startX = startX + sx;
|
||||
}
|
||||
else if (e2 < dx)
|
||||
{
|
||||
} else if (e2 < dx) {
|
||||
err = err + dx;
|
||||
startY = startY + sy;
|
||||
}
|
||||
@@ -655,8 +622,7 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
int sy = startY < y1 ? 1 : -1;
|
||||
int err = dx - dy;
|
||||
int e2;
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
if (startX < 0 || startY <= 0 || startX >= width || startY > height) continue;
|
||||
biomeMap[startX][height - startY] |= (1L << biomeIndex[0]);
|
||||
terrainMap[startX][height - startY] = 0;
|
||||
@@ -665,13 +631,10 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
if (startX == x1 && startY == y1)
|
||||
break;
|
||||
e2 = 2 * err;
|
||||
if (e2 > -dy)
|
||||
{
|
||||
if (e2 > -dy) {
|
||||
err = err - dy;
|
||||
startX = startX + sx;
|
||||
}
|
||||
else if (e2 < dx)
|
||||
{
|
||||
} else if (e2 < dx) {
|
||||
err = err + dx;
|
||||
startY = startY + sy;
|
||||
}
|
||||
@@ -768,6 +731,7 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
public PointOfInterest findPointsOfInterest(String name) {
|
||||
return mapPoiIds.findPointsOfInterest(name);
|
||||
}
|
||||
|
||||
public int getChunkSize() {
|
||||
return (Scene.getIntendedWidth() > Scene.getIntendedHeight() ? Scene.getIntendedWidth() : Scene.getIntendedHeight()) / data.tileSize;
|
||||
}
|
||||
|
||||
@@ -35,21 +35,19 @@ public class WorldSave {
|
||||
|
||||
private final SignalList onLoadList = new SignalList();
|
||||
|
||||
public final World getWorld()
|
||||
{
|
||||
public final World getWorld() {
|
||||
return world;
|
||||
}
|
||||
public AdventurePlayer getPlayer()
|
||||
{
|
||||
|
||||
public AdventurePlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void onLoad(Runnable run)
|
||||
{
|
||||
public void onLoad(Runnable run) {
|
||||
onLoadList.add(run);
|
||||
}
|
||||
public PointOfInterestChanges getPointOfInterestChanges(String id)
|
||||
{
|
||||
|
||||
public PointOfInterestChanges getPointOfInterestChanges(String id) {
|
||||
if (!pointOfInterestChanges.containsKey(id))
|
||||
pointOfInterestChanges.put(id, new PointOfInterestChanges());
|
||||
return pointOfInterestChanges.get(id);
|
||||
@@ -64,8 +62,7 @@ public class WorldSave {
|
||||
try {
|
||||
try (FileInputStream fos = new FileInputStream(fileName);
|
||||
InflaterInputStream inf = new InflaterInputStream(fos);
|
||||
ObjectInputStream oos = new ObjectInputStream(inf))
|
||||
{
|
||||
ObjectInputStream oos = new ObjectInputStream(inf)) {
|
||||
currentSave.header = (WorldSaveHeader) oos.readObject();
|
||||
SaveFileData mainData = (SaveFileData) oos.readObject();
|
||||
currentSave.player.load(mainData.readSubData("player"));
|
||||
@@ -89,9 +86,11 @@ public class WorldSave {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isSafeFile(String name) {
|
||||
return filenameToSlot(name) != INVALID_SAVE_SLOT;
|
||||
}
|
||||
|
||||
static public int filenameToSlot(String name) {
|
||||
if (name.equals("auto_save.sav"))
|
||||
return AUTO_SAVE_SLOT;
|
||||
@@ -133,6 +132,7 @@ public class WorldSave {
|
||||
identity = dp.getColorIdentityforAdventure();
|
||||
} else {
|
||||
starterDeck = isFantasy ? DeckgenUtil.getRandomOrPreconOrThemeDeck("", false, false, false) : Config.instance().starterDecks()[startingColorIdentity];
|
||||
identity = DeckProxy.getColorIdentityforAdventure(starterDeck);
|
||||
}
|
||||
currentSave.player.create(name, startingColorIdentity, starterDeck, male, race, avatarIndex, isFantasy, diff);
|
||||
currentSave.player.setWorldPosY((int) (currentSave.world.getData().playerStartPosY * currentSave.world.getData().height * currentSave.world.getTileSize()));
|
||||
@@ -148,12 +148,15 @@ public class WorldSave {
|
||||
public boolean autoSave() {
|
||||
return save("auto save", AUTO_SAVE_SLOT);
|
||||
}
|
||||
|
||||
public boolean quickSave() {
|
||||
return save("quick save", QUICK_SAVE_SLOT);
|
||||
}
|
||||
|
||||
public boolean quickLoad() {
|
||||
return load(QUICK_SAVE_SLOT);
|
||||
}
|
||||
|
||||
public boolean save(String text, int currentSlot) {
|
||||
header.name = text;
|
||||
|
||||
@@ -163,8 +166,7 @@ public class WorldSave {
|
||||
try {
|
||||
try (FileOutputStream fos = new FileOutputStream(fileName);
|
||||
DeflaterOutputStream def = new DeflaterOutputStream(fos);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(def))
|
||||
{
|
||||
ObjectOutputStream oos = new ObjectOutputStream(def)) {
|
||||
header.saveDate = new Date();
|
||||
oos.writeObject(header);
|
||||
SaveFileData mainData = new SaveFileData();
|
||||
|
||||
Reference in New Issue
Block a user