Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/nomadrealms/app/context/MainContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import engine.visuals.lwjgl.render.framebuffer.DefaultFrameBuffer;
import nomadrealms.context.game.GameState;
import nomadrealms.context.game.event.InputEvent;
import nomadrealms.context.game.world.map.generation.MainWorldGenerationStrategy;
import nomadrealms.context.game.world.map.generation.OverworldGenerationStrategy;
import nomadrealms.context.game.zone.Deck;
import nomadrealms.render.RenderingEnvironment;
import nomadrealms.render.ui.custom.game.GameInterface;
Expand Down Expand Up @@ -61,7 +61,7 @@ public MainContext() {
}

public MainContext(Deck deck1, Deck deck2, Deck deck3, Deck deck4) {
gameState = new GameState("New World", stateToUiEventChannel, new MainWorldGenerationStrategy(123456789));
gameState = new GameState("New World", stateToUiEventChannel, new OverworldGenerationStrategy(123456789));
gameState.world.nomad.deckCollection().importDecks(deck1, deck2, deck3, deck4);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nomadrealms/context/game/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import nomadrealms.context.game.world.World;
import nomadrealms.context.game.world.map.area.Tile;
import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate;
import nomadrealms.context.game.world.map.generation.MainWorldGenerationStrategy;
import nomadrealms.context.game.world.map.generation.MapGenerationStrategy;
import nomadrealms.context.game.world.map.generation.OverworldGenerationStrategy;
import nomadrealms.context.game.world.weather.Weather;
import nomadrealms.render.RenderingEnvironment;
import nomadrealms.render.ui.Camera;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class GameState {
* No-arg constructor for serialization.
*/
protected GameState() {
this("Default World", new LinkedList<>(), new MainWorldGenerationStrategy(123456789));
this("Default World", new LinkedList<>(), new OverworldGenerationStrategy(123456789));
}

public GameState(String name, Queue<InputEvent> uiEventChannel, MapGenerationStrategy mapGenerationStrategy) {
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/nomadrealms/context/game/GameStateSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@
import nomadrealms.context.game.world.map.area.Zone;
import nomadrealms.context.game.world.map.area.coordinate.Coordinate;
import nomadrealms.context.game.world.map.generation.MapGenerationStrategy;
import nomadrealms.context.game.world.map.generation.status.GenerationStep;
import nomadrealms.context.game.world.map.generation.status.GenerationStepStatus;
import nomadrealms.context.game.world.map.generation.status.biome.BiomeParameters;
import nomadrealms.context.game.world.map.generation.status.biome.noise.BiomeNoiseGenerator;
import nomadrealms.context.game.world.map.generation.status.biome.noise.BiomeNoiseGeneratorCluster;
import nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeCategory;
import nomadrealms.context.game.world.map.generation.status.biome.nomenclature.BiomeVariantType;
import nomadrealms.context.game.world.map.generation.status.biome.nomenclature.ContinentType;
import nomadrealms.context.game.world.map.generation.status.points.point.PointOfInterest;
import nomadrealms.context.game.world.map.generation.overworld.GenerationProcess;
import nomadrealms.context.game.world.map.generation.overworld.GenerationStep;
import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeParameters;
import nomadrealms.context.game.world.map.generation.overworld.biome.noise.BiomeNoiseGenerator;
import nomadrealms.context.game.world.map.generation.overworld.biome.noise.BiomeNoiseGeneratorCluster;
import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeCategory;
import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.BiomeVariantType;
import nomadrealms.context.game.world.map.generation.overworld.biome.nomenclature.ContinentType;
import nomadrealms.context.game.world.map.generation.overworld.points.point.PointOfInterest;
import nomadrealms.context.game.world.map.generation.overworld.structure.StructureGenerationConfig;
import nomadrealms.context.game.world.map.tile.factory.TileType;
import nomadrealms.context.game.world.weather.Weather;
import nomadrealms.context.game.zone.CardStack;
Expand Down Expand Up @@ -134,7 +135,7 @@ private void registerClasses() {
kryo.register(TileType[].class);
kryo.register(TileType[][].class);
kryo.register(Weather.class);
kryo.register(GenerationStepStatus.class);
kryo.register(GenerationProcess.class);
kryo.register(BiomeNoiseGenerator.class);
kryo.register(BiomeNoiseGeneratorCluster.class);
kryo.register(PointOfInterest.class);
Expand All @@ -155,20 +156,22 @@ private void registerClasses() {
kryo.register(DropItemEvent.class);
kryo.register(CardZoneEventChannel.class);
kryo.register(CardZoneListener.class);
kryo.register(Structure[].class);
kryo.register(Structure[][].class);

Reflections reflections = new Reflections(new ConfigurationBuilder().forPackage("nomadrealms"));
List<Class<?>> superclasses = Arrays.asList(
Event.class,
CardExpression.class,
Actor.class,
Structure.class,
CardPlayerAI.class,
Tile.class,
Coordinate.class,
MapGenerationStrategy.class,
GenerationStep.class,
StructureGenerationConfig.class,
Card.class,
Action.class,
GenerationStep.class,
Constraint.class);
for (Class<?> superclass : superclasses) {
for (Class<?> clazz : reflections.getSubTypesOf(superclass)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Structure implements Actor {
private Inventory inventory;

private final String name;
private final String image;
protected final String image;
private final int constructionTime;
private final int maxHealth;
private int health;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class TreeStructure extends Structure {

public TreeStructure() {
super("tree", "tree_1", 1, 50);
}
public TreeStructure() {
super("tree", "oak_tree", 1, 50);
}

}
4 changes: 3 additions & 1 deletion src/main/java/nomadrealms/context/game/world/GameMap.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package nomadrealms.context.game.world;

import static nomadrealms.context.game.world.map.area.coordinate.RegionCoordinate.regionCoordinateOf;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -40,7 +42,7 @@ public GameMap(World world, MapGenerationStrategy strategy) {
}

public void render(RenderingEnvironment re, Vector2f origin) {
RegionCoordinate regionCoord = RegionCoordinate.regionCoordinateOf(origin);
RegionCoordinate regionCoord = regionCoordinateOf(origin);
getRegion(regionCoord).render(re, origin);
}

Expand Down
40 changes: 32 additions & 8 deletions src/main/java/nomadrealms/context/game/world/World.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package nomadrealms.context.game.world;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static nomadrealms.context.game.item.Item.OAK_LOG;
import static nomadrealms.context.game.item.Item.WHEAT_SEED;
import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.chunkCoordinateOf;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -66,30 +68,45 @@ public World(GameState state, MapGenerationStrategy mapGenerationStrategy) {
Farmer farmer = new Farmer("Fred",
getTile(new TileCoordinate(new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0),
0, 1), 0, 0)));
addActor(nomad);
addActor(farmer);
addActor(nomad, true);
addActor(farmer, true);
addActor(new FeralMonkey("bob", getTile(new TileCoordinate(
new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0), 0, 0), 6, 6))));
new ChunkCoordinate(new ZoneCoordinate(new RegionCoordinate(0, 0), 0, 0), 0, 0), 6, 6))), true);
}

public void renderMap(RenderingEnvironment re) {
map.render(re, re.camera.position().vector());

}

public void renderActors(RenderingEnvironment re) {
for (Actor entity : new ArrayList<>(actors)) {
if (entity.isDestroyed()) {
continue;
// TODO: eventually remove destroyed entities after a delay
ChunkCoordinate chunkCoord = chunkCoordinateOf(re.camera.position().vector());
List<Chunk> chunksToRender = asList(
getChunk(chunkCoord),
getChunk(chunkCoord.up()),
getChunk(chunkCoord.down()),
getChunk(chunkCoord.left()),
getChunk(chunkCoord.right()),
getChunk(chunkCoord.down().right()),
getChunk(chunkCoord.right().right()),
getChunk(chunkCoord.down().down())
);
Comment on lines +84 to +93

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logic for selecting chunks to render appears to be flawed. It doesn't select a complete 3x3 grid of chunks around the camera's current chunk, which could lead to actors at the edges of the screen not being rendered. The current implementation includes chunks like chunkCoord.right().right() and chunkCoord.down().down(), which are outside the immediate 3x3 area, while missing corner chunks like up().left().

To ensure all visible actors are rendered correctly, I suggest using a proper 3x3 grid of chunks centered on the camera's position.

List<Chunk> chunksToRender = asList(
				getChunk(chunkCoord.up().left()),
				getChunk(chunkCoord.up()),
				getChunk(chunkCoord.up().right()),
				getChunk(chunkCoord.left()),
				getChunk(chunkCoord),
				getChunk(chunkCoord.right()),
				getChunk(chunkCoord.down().left()),
				getChunk(chunkCoord.down()),
				getChunk(chunkCoord.down().right())
		);

for (Chunk chunk : chunksToRender) {
for (Tile tile : chunk.tiles()) {
// TODO: eventually remove destroyed entities after a delay. not here, but in update()
if (tile.actor() != null && !tile.actor().isDestroyed()) {
tile.actor().render(re);
}
}
entity.render(re);
}
}

int x = 0;
int i = 0;

public void update(InputEventFrame inputEventFrame) {
// TODO: this actually does not update actors that werent added using addActor(), i.e. actors loaded from
// zone generation
List<Actor> currentActors = new ArrayList<>(this.actors); // Prevent concurrent modification for added actors
i++;
if (i % 10 == 0) {
Expand Down Expand Up @@ -146,10 +163,17 @@ public void addAllProcChains(List<ProcChain> chains) {
}

public void addActor(Actor actor) {
addActor(actor, false);
}

public void addActor(Actor actor, boolean forced) {
actors.add(actor);
if (actor instanceof Structure) {
structures.add((Structure) actor);
}
if (forced) {
actor.tile().clearActor();
}
// TODO: figure out to do when tile is already occupied
actor.tile().actor(actor);
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/nomadrealms/context/game/world/map/area/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import static nomadrealms.context.game.world.map.area.Tile.TILE_VERTICAL_SPACING;
import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.CHUNK_SIZE;

import java.util.ArrayList;
import java.util.List;

import engine.common.math.Vector2f;
import engine.visuals.constraint.box.ConstraintPair;
import nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate;
Expand Down Expand Up @@ -82,6 +85,16 @@ public void replace(Tile tile) {
tiles[tile.coord().x()][tile.coord().y()] = tile;
}

public List<Tile> tiles() {
List<Tile> tiles = new ArrayList<>();
for (int x = 0; x < CHUNK_SIZE; x++) {
for (int y = 0; y < CHUNK_SIZE; y++) {
tiles.add(this.tiles[x][y]);
}
}
return tiles;
}

public void tiles(Tile[][] tiles) {
this.tiles = tiles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void actor(Actor actor) {
throw new IllegalStateException("Tile " + coord + " is already occupied by " + this.actor);
}
this.actor = actor;
actor.tile(this);
}

public void clearActor() {
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/nomadrealms/context/game/world/map/area/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.CHUNK_SIZE;
import static nomadrealms.context.game.world.map.area.coordinate.ChunkCoordinate.chunkCoordinateOf;
import static nomadrealms.context.game.world.map.area.coordinate.ZoneCoordinate.ZONE_SIZE;
import static nomadrealms.context.game.world.map.generation.status.GenerationStepStatus.EMPTY;

import java.util.Random;

Expand All @@ -16,10 +15,11 @@
import nomadrealms.context.game.world.map.area.coordinate.TileCoordinate;
import nomadrealms.context.game.world.map.area.coordinate.ZoneCoordinate;
import nomadrealms.context.game.world.map.generation.MapGenerationStrategy;
import nomadrealms.context.game.world.map.generation.status.GenerationStepStatus;
import nomadrealms.context.game.world.map.generation.status.biome.BiomeGenerationStep;
import nomadrealms.context.game.world.map.generation.status.points.PointsGenerationStep;
import nomadrealms.context.game.world.map.generation.status.points.point.PointOfInterest;
import nomadrealms.context.game.world.map.generation.overworld.GenerationProcess;
import nomadrealms.context.game.world.map.generation.overworld.biome.BiomeGenerationStep;
import nomadrealms.context.game.world.map.generation.overworld.points.PointsGenerationStep;
import nomadrealms.context.game.world.map.generation.overworld.points.point.PointOfInterest;
import nomadrealms.context.game.world.map.generation.overworld.structure.StructureGenerationStep;
import nomadrealms.render.RenderingEnvironment;

/**
Expand All @@ -35,13 +35,11 @@
public class Zone {

private transient Region region;
private ZoneCoordinate coord;
private final ZoneCoordinate coord;

private Chunk[][] chunks;
private final Chunk[][] chunks;

private GenerationStepStatus generationStatus = EMPTY;
private BiomeGenerationStep biomeGenerationStep;
private PointsGenerationStep pointsGenerationStep;
private GenerationProcess generationProcess;

private transient Random rng;
private int rngCounter = 0;
Expand Down Expand Up @@ -70,11 +68,8 @@ public void initRNG() {
public Zone(World world, ZoneCoordinate coord, MapGenerationStrategy strategy) {
this.region = world.getRegion(coord.region());
this.coord = coord;

initRNG();

biomeGenerationStep = new BiomeGenerationStep(this, world.generation().seed());
pointsGenerationStep = new PointsGenerationStep(this, world.generation().seed());
generationProcess = new GenerationProcess(this, strategy);

this.chunks = strategy.generateZone(world, this);
}
Expand All @@ -95,7 +90,7 @@ public void render(RenderingEnvironment re, Vector2f origin) {
region.world().getChunk(chunkCoord.down().down()).render(re);

if (re.showDebugInfo) {
for (PointOfInterest poi : pointsGenerationStep.points()) {
for (PointOfInterest poi : generationProcess.points().points()) {
poi.render(this, re);
}
}
Expand Down Expand Up @@ -128,11 +123,15 @@ public Zone[][] getSurroundingZones(World world, int range) {
}

public BiomeGenerationStep biomeGenerationStep() {
return biomeGenerationStep;
return generationProcess.biome();
}

public PointsGenerationStep pointsGenerationStep() {
return pointsGenerationStep;
return generationProcess.points();
}

public StructureGenerationStep structureGenerationStep() {
return generationProcess.structure();
}

private ConstraintPair indexPosition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public FileBasedGenerationStrategy() {
this.worldData = loadWorldData();
}

@Override
public MapGenerationParameters parameters() {
return new MapGenerationParameters()
.seed(0);
}

@Override
public Tile[][] generateChunk(Zone zone, Chunk chunk, ChunkCoordinate coord) {
TileType[][] chunkTileTypes = new TileType[CHUNK_SIZE][CHUNK_SIZE];
Expand Down Expand Up @@ -64,11 +70,6 @@ public Chunk[][] generateZone(World world, Zone zone) {
return chunks;
}

@Override
public long seed() {
return 0;
}

private List<String> loadWorldData() {
List<String> lines = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(getFile()))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package nomadrealms.context.game.world.map.generation;

import nomadrealms.context.game.world.map.generation.overworld.biome.noise.BiomeNoiseGeneratorCluster;

public class MapGenerationParameters {

private long seed;
private BiomeNoiseGeneratorCluster biomeNoise;

public MapGenerationParameters() {
}

public MapGenerationParameters seed(long seed) {
this.seed = seed;
return this;
}

public long seed() {
return seed;
}

public MapGenerationParameters biomeNoise(BiomeNoiseGeneratorCluster biomeNoise) {
this.biomeNoise = biomeNoise;
return this;
}

public BiomeNoiseGeneratorCluster biomeNoise() {
return biomeNoise;
}


}
Loading