Skip to content

Commit

Permalink
Fixing map and world rendering issues (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
guidota authored May 14, 2019
1 parent 2f2ed53 commit e486947
Show file tree
Hide file tree
Showing 27 changed files with 311 additions and 258 deletions.
108 changes: 4 additions & 104 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,12 @@ buildscript {
}
}

plugins {
id 'java'
}

group 'ao-java'
version '1.0-SNAPSHOT'
apply plugin: 'kotlin'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

allprojects {
apply plugin: "idea"

group 'ao-java'
version = '0.1-SNAPSHOT'

ext {
appName = 'ao-java'
gdxVersion = '1.9.9'
Expand All @@ -50,95 +39,6 @@ allprojects {
}
}

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

dependencies {
compile project(":client")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
}
}

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

configurations {
provided
}

sourceSets {
// run the annotation processor compile time.
main { compileClasspath += configurations.provided }
}

dependencies {
compile project(":shared")
implementation 'org.ini4j:ini4j:0.5.1'
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
}

project(":design") {
apply plugin: "java"
apply plugin: "kotlin"

dependencies {
compile project(":client")
compile "com.soywiz:kaifu2x:0.4.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.2.1"
}
}

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

configurations {
provided
}

sourceSets {
// run the annotation processor compile time.
main { compileClasspath += configurations.provided }
}

dependencies {
compile project(":shared")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
}
}

project(":shared") {
subprojects {
apply plugin: "java"

configurations {
provided
}

sourceSets {
main { compileClasspath += configurations.provided }
}

dependencies {
compile project(":components")
compile 'org.ini4j:ini4j:0.5.1'

// common
compile "net.mostlyoriginal.artemis-odb:contrib-core:$artemisContribVersion"
compile "net.mostlyoriginal.artemis-odb:contrib-jam:$artemisContribVersion"
compile "net.mostlyoriginal.artemis-odb:contrib-eventbus:$artemisContribVersion"
compile "net.mostlyoriginal.artemis-odb:contrib-network:$artemisContribVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}

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

dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "net.onedaybeard.artemis:artemis-odb:$artemisVersion"
}
}
7 changes: 6 additions & 1 deletion client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
apply plugin: "java"

sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = ["src/"]
sourceSets {
main.java.srcDirs = ["src/"]
}

dependencies {
compile project(":shared")
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
1 change: 1 addition & 0 deletions client/src/game/AOGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import game.handlers.AssetHandler;
import game.handlers.MapHandler;
import game.handlers.StateHandler;
import game.screens.ScreenEnum;
import game.screens.ScreenManager;
Expand Down
15 changes: 11 additions & 4 deletions client/src/game/handlers/MapHandler.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package game.handlers;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Json;
import com.esotericsoftware.minlog.Log;
import game.managers.MapManager;
import shared.model.map.Map;
import shared.util.MapUtils;
import shared.util.MapHelper;

import java.util.HashMap;

public class MapHandler {

private static HashMap<Integer, Map> maps = new HashMap();

private static MapHelper helper = MapHelper.instance();

static {
load(1);
}

public static Map get(int map) {
if (!has(map)) {
return load(map);
Expand All @@ -26,11 +30,14 @@ public static boolean has(int map) {

public static Map load(int mapNumber) {
long start = System.currentTimeMillis();
Map map = MapUtils.getMap(mapNumber);
Map map = helper.getMap(mapNumber);
Log.debug("Map " + mapNumber + ".json successfully loaded in " + (System.currentTimeMillis() - start) + "ms");
MapManager.initialize(map);
maps.put(mapNumber, map);
return map;
}

public static MapHelper getHelper() {
return helper;
}
}
43 changes: 24 additions & 19 deletions client/src/game/managers/MapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,33 @@ public static void renderLayer(Map map, SpriteBatch batch, float delta, int laye
}
for (int y = minY; y <= maxY; y++) {
for (int x = minX; x <= maxX; x++) {
int graphic = map.getTile(x, y).getGraphic(layer);
if (graphic == 0) {
continue;
}

BundledAnimation animation = AnimationHandler.getGraphicAnimation(graphic);
TextureRegion tileRegion = animation.isAnimated() ? animation.getAnimatedGraphic(true) : animation.getGraphic();

if (animation != null && animation.isAnimated()) {
animation.setAnimationTime(animation.getAnimationTime() + delta);
}

if (tileRegion != null) {
final float mapPosX = (x * Tile.TILE_PIXEL_WIDTH);
final float mapPosY = (y * Tile.TILE_PIXEL_HEIGHT);
final float tileOffsetX = mapPosX - (tileRegion.getRegionWidth() * 0.5f) - (16.0f);
final float tileOffsetY = mapPosY - tileRegion.getRegionHeight();
batch.draw(tileRegion, tileOffsetX, tileOffsetY);
}
drawTile(map, batch, delta, layer, y, x);
}
}
}

private static void drawTile(Map map, SpriteBatch batch, float delta, int layer, int y, int x) {
int graphic = map.getTile(x, y).getGraphic(layer);
if (graphic == 0) {
return;
}

BundledAnimation animation = AnimationHandler.getGraphicAnimation(graphic);
TextureRegion tileRegion = animation.isAnimated() ? animation.getAnimatedGraphic(true) : animation.getGraphic();

if (animation.isAnimated()) {
animation.setAnimationTime(animation.getAnimationTime() + delta);
}

if (tileRegion != null) {
final float mapPosX = (x * Tile.TILE_PIXEL_WIDTH);
final float mapPosY = (y * Tile.TILE_PIXEL_HEIGHT);
final float tileOffsetX = mapPosX + (Tile.TILE_PIXEL_WIDTH - tileRegion.getRegionWidth()) / 2;
final float tileOffsetY = mapPosY - tileRegion.getRegionHeight();
batch.draw(tileRegion, tileOffsetX, tileOffsetY);
}
}

public static boolean isLoaded(Map map) {
return bufferedLayers.containsKey(map);
}
Expand All @@ -107,4 +111,5 @@ public static Texture getBufferedLayer(Map map) {
public static void initialize(Map map) {
renderLayerToBuffer(map);
}

}
35 changes: 19 additions & 16 deletions client/src/game/screens/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import game.systems.camera.CameraFocusSystem;
import game.systems.camera.CameraMovementSystem;
import game.systems.camera.CameraSystem;
import game.systems.map.CaveSystem;
import game.systems.map.TiledMapSystem;
import game.systems.network.ClientSystem;
import game.systems.network.TimeSync;
Expand All @@ -39,7 +38,10 @@

public class GameScreen extends ScreenAdapter {

private static final int FONTS_PRIORITY = WorldConfigurationBuilder.Priority.NORMAL - 1;
private static final int DECORATIONS = WorldConfigurationBuilder.Priority.NORMAL - 1;
public static final int RENDER_PRE_ENTITIES = WorldConfigurationBuilder.Priority.NORMAL + 3;
public static final int RENDER_POST_ENTITIES = WorldConfigurationBuilder.Priority.NORMAL + 1;
public static final int RENDER_ENTITIES = WorldConfigurationBuilder.Priority.NORMAL + 2;
public static World world;
public static int player = -1;
private static GUI gui = new GUI();
Expand Down Expand Up @@ -103,20 +105,21 @@ private void initWorld() {
.with(new SoundSytem())
.with(new TiledMapSystem())
// Rendering
.with(WorldConfigurationBuilder.Priority.NORMAL + 3, new MapLowerLayerRenderingSystem(spriteBatch))
.with(WorldConfigurationBuilder.Priority.NORMAL + 3, new GroundFXsRenderingSystem(spriteBatch))
.with(WorldConfigurationBuilder.Priority.NORMAL + 3, new TargetRenderingSystem(spriteBatch))
.with(WorldConfigurationBuilder.Priority.NORMAL + 2, new CharacterRenderingSystem(spriteBatch))
.with(WorldConfigurationBuilder.Priority.NORMAL + 3, new NameRenderingSystem(spriteBatch))
.with(WorldConfigurationBuilder.Priority.NORMAL + 1, new ObjectRenderingSystem(spriteBatch))
.with(WorldConfigurationBuilder.Priority.NORMAL + 1, new ParticleRenderingSystem(spriteBatch))
.with(WorldConfigurationBuilder.Priority.NORMAL + 1, new FXsRenderingSystem(spriteBatch))
.with(WorldConfigurationBuilder.Priority.NORMAL + 1, new MapUpperLayerRenderingSystem(spriteBatch))
.with(FONTS_PRIORITY, new StateRenderingSystem(spriteBatch))
.with(FONTS_PRIORITY, new CombatRenderingSystem(spriteBatch))
.with(FONTS_PRIORITY, new DialogRenderingSystem(spriteBatch))
.with(FONTS_PRIORITY, new CharacterStatesRenderingSystem(spriteBatch))
.with(FONTS_PRIORITY - 1, new LightRenderingSystem(spriteBatch))
.with(RENDER_PRE_ENTITIES, new MapGroundRenderingSystem(spriteBatch))
.with(RENDER_PRE_ENTITIES, new GroundFXsRenderingSystem(spriteBatch))
.with(RENDER_PRE_ENTITIES, new TargetRenderingSystem(spriteBatch))
.with(RENDER_POST_ENTITIES, new ObjectRenderingSystem(spriteBatch))
.with(RENDER_PRE_ENTITIES, new NameRenderingSystem(spriteBatch))
.with(RENDER_ENTITIES, new CharacterRenderingSystem(spriteBatch))
.with(RENDER_ENTITIES, new WorldRenderingSystem(spriteBatch))
.with(RENDER_POST_ENTITIES, new MapUpperLayerRenderingSystem(spriteBatch))
.with(RENDER_POST_ENTITIES, new LightRenderingSystem(spriteBatch))
.with(RENDER_POST_ENTITIES, new ParticleRenderingSystem(spriteBatch))
.with(RENDER_POST_ENTITIES, new FXsRenderingSystem(spriteBatch))
.with(DECORATIONS, new StateRenderingSystem(spriteBatch))
.with(DECORATIONS, new CombatRenderingSystem(spriteBatch))
.with(DECORATIONS, new DialogRenderingSystem(spriteBatch))
.with(DECORATIONS, new CharacterStatesRenderingSystem(spriteBatch))
.with(WorldConfigurationBuilder.Priority.NORMAL, new CoordinatesRenderingSystem(spriteBatch))
// Other
.with(new TagManager())
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/systems/map/TiledMapSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class TiledMapSystem extends IteratingSystem {

public Map map;
public long mapNumber = -1;
public int mapNumber = -1;

public TiledMapSystem() {
super(Aspect.all(Focused.class, WorldPos.class));
Expand Down
6 changes: 3 additions & 3 deletions client/src/game/systems/physics/MovementProcessorSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import shared.model.map.Map;
import shared.network.interaction.MeditateRequest;
import shared.network.movement.MovementRequest;
import shared.util.MapUtils;
import shared.util.MapHelper;
import shared.util.Util;

import java.util.Optional;
Expand Down Expand Up @@ -93,8 +93,8 @@ protected void process(int entity) {
nearEntities.remove(entity);
nearEntities.forEach(near -> Log.debug("Validating entity: " + near + " is not occuping the position"));
Map map = MapHandler.get(expectedPos.map);
boolean blocked = MapUtils.isBlocked(map, expectedPos);
boolean occupied = MapUtils.hasEntity(nearEntities, expectedPos);
boolean blocked = MapHandler.getHelper().isBlocked(map, expectedPos);
boolean occupied = MapHandler.getHelper().hasEntity(nearEntities, expectedPos);
boolean valid = !(blocked ||
occupied ||
player.hasImmobile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
public class CharacterRenderingSystem extends RenderingSystem {

public static final float SHADOW_ALPHA = 0.15f;
public static final Aspect.Builder CHAR_ASPECT = Aspect.all(Character.class, WorldPos.class, Body.class, Heading.class);
private static Texture shadow = new Texture(Gdx.files.local("data/ui/images/shadow22.png"));

public CharacterRenderingSystem(SpriteBatch batch) {
super(Aspect.all(Character.class, WorldPos.class, Body.class, Heading.class), batch, CameraKind.WORLD);
super(CHAR_ASPECT, batch, CameraKind.WORLD);
}

private static float getMovementOffset(BundledAnimation bodyAnimation) {
Expand All @@ -50,6 +51,13 @@ private static float getMovementOffset(BundledAnimation bodyAnimation) {

@Override
protected void process(E player) {
}

public Aspect.Builder getAspect() {
return CHAR_ASPECT;
}

public void drawPlayer(E player) {
Pos2D currentPos = player.worldPosPos2D();
Pos2D screenPos = Util.toScreen(currentPos);
final Heading heading = player.getHeading();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import camera.Focused;
import com.artemis.Aspect;
import com.artemis.E;
import com.artemis.Entity;
import com.artemis.annotations.Wire;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
Expand All @@ -13,17 +12,11 @@
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import game.screens.GameScreen;
import game.systems.OrderedEntityProcessingSystem;
import game.systems.camera.CameraSystem;
import game.utils.Resources;
import position.Pos2D;
import shared.model.map.Tile;
import shared.util.Util;

import java.util.Comparator;

import static com.artemis.E.E;
import static game.utils.Resources.GAME_SHADERS_LIGHT;

@Wire(injectInherited=true)
Expand Down
Loading

0 comments on commit e486947

Please sign in to comment.