Skip to content

Commit

Permalink
Bug isolation
Browse files Browse the repository at this point in the history
Family is not picking up entities when recreating engine to swithc
contexts. Possibly related to issue 214:
libgdx/ashley#214

-ignore local properties
  • Loading branch information
0XDE57 committed Nov 23, 2017
1 parent 95bf123 commit 012bd0b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 44 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ build/
##SpaceProject
android/assets/config/
android/assets/save/
save/stars.txt
save/stars.txt

##apparently not supposed to be synced
local.properties
32 changes: 2 additions & 30 deletions core/src/com/spaceproject/SpaceProject.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
package com.spaceproject;

import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.math.Vector3;
import com.spaceproject.components.CameraFocusComponent;
import com.spaceproject.components.ControllableComponent;
import com.spaceproject.components.PlanetComponent;
import com.spaceproject.config.CelestialConfig;
import com.spaceproject.config.KeyConfig;
import com.spaceproject.config.LandConfig;
import com.spaceproject.generation.EntityFactory;
import com.spaceproject.screens.GameScreen;
import com.spaceproject.screens.SpaceScreen;
import com.spaceproject.screens.TestNoiseScreen;
import com.spaceproject.screens.WorldScreen;
import com.spaceproject.screens.*;
import com.spaceproject.utility.MyScreenAdapter;

public class SpaceProject extends Game {
Expand All @@ -31,26 +21,8 @@ public void create() {
loadConfigs();


//load test default values
LandConfig landCFG = new LandConfig();
landCFG.position = new Vector3();//start player at 0,0
Entity player = EntityFactory.createCharacter(landCFG.position.x, landCFG.position.y);
Entity playerTESTSHIP = EntityFactory.createShip3(landCFG.position.x, landCFG.position.y, landCFG.shipSeed, player);
//playerTESTSHIP.add(new CameraFocusComponent());
//playerTESTSHIP.add(new ControllableComponent());
landCFG.ship = playerTESTSHIP;

//test values for world
PlanetComponent planet = new PlanetComponent();
planet.mapSize = 128;
planet.scale = 100;
planet.octaves = 4;
planet.persistence = 0.68f;
planet.lacunarity = 2.6f;
landCFG.planet = planet;

boolean inSpace = true;
setScreen(new GameScreen(landCFG, inSpace));
setScreen(new GameScreen(null, inSpace));
//setScreen(new SpaceScreen(landCFG));
//setScreen(new WorldScreen(landCFG));
//setScreen(new TestShipGenerationScreen(this));
Expand Down
60 changes: 48 additions & 12 deletions core/src/com/spaceproject/screens/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableArray;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Disposable;
import com.spaceproject.components.AIComponent;
import com.spaceproject.components.CameraFocusComponent;
import com.spaceproject.components.ControllableComponent;
import com.spaceproject.components.PlanetComponent;
import com.spaceproject.components.ControlFocusComponent;
import com.spaceproject.components.TextureComponent;
import com.spaceproject.components.TransformComponent;
Expand Down Expand Up @@ -37,14 +41,32 @@

public class GameScreen extends MyScreenAdapter {

public static Engine engine;
public Engine engine;
public static boolean inSpace;
public static LandConfig landCFG = null;
public static boolean transition;

public GameScreen(LandConfig landCFG, boolean inSpace) {
//inSpace = true;
//inSpace = false;
inSpace = false;

// load test default values
landCFG = new LandConfig();
landCFG.position = new Vector3();// start player at 0,0
Entity player = EntityFactory.createCharacter(landCFG.position.x, landCFG.position.y);
Entity playerTESTSHIP = EntityFactory.createShip3(landCFG.position.x, landCFG.position.y, landCFG.shipSeed, player);
// playerTESTSHIP.add(new CameraFocusComponent());
// playerTESTSHIP.add(new ControllableComponent());
landCFG.ship = playerTESTSHIP;

// test values for world
PlanetComponent planet = new PlanetComponent();
planet.mapSize = 128;
planet.scale = 100;
planet.octaves = 4;
planet.persistence = 0.68f;
planet.lacunarity = 2.6f;
landCFG.planet = planet;

GameScreen.inSpace = inSpace;

Expand All @@ -66,6 +88,7 @@ private void initSpace(LandConfig landCFG) {


//===============ENTITIES===============
/*
//test ships
engine.addEntity(EntityFactory.createShip3(-100, 400));
engine.addEntity(EntityFactory.createShip3(-200, 400));
Expand All @@ -75,7 +98,7 @@ private void initSpace(LandConfig landCFG) {
Entity aiTest = EntityFactory.createCharacter(0, 400);
aiTest.add(new AIComponent());
aiTest.add(new ControllableComponent());
engine.addEntity(aiTest);
engine.addEntity(aiTest);*/

//add player
Entity ship = landCFG.ship;
Expand All @@ -98,7 +121,7 @@ private void initSpace(LandConfig landCFG) {
engine.addSystem(new AISystem());

//loading
engine.addSystem(new SpaceLoadingSystem());
//engine.addSystem(new SpaceLoadingSystem());
engine.addSystem(new SpaceParallaxSystem());
//Ai...

Expand All @@ -119,6 +142,7 @@ private void initSpace(LandConfig landCFG) {
engine.addSystem(new DebugUISystem());

DebugUISystem.printEntities(engine);
DebugUISystem.printSystems(engine);
}


Expand All @@ -143,6 +167,8 @@ private void initWorld(LandConfig landCFG) {
engine.addEntity(ship);
System.out.println("ship: " + String.format("%X", ship.hashCode()));


/*
// test ships near player
engine.addEntity(EntityFactory.createShip3(position + 100, position + 300));
engine.addEntity(EntityFactory.createShip3(position - 100, position + 300));
Expand All @@ -152,11 +178,8 @@ private void initWorld(LandConfig landCFG) {
aiTest.add(new ControllableComponent());
//aiTest.add(new CameraFocusComponent());
engine.addEntity(aiTest);
// engine.addEntity(Misc.copyEntity(aiTest));
// engine.addEntity(Misc.copyEntity(aiTest));
// engine.addEntity(Misc.copyEntity(aiTest));
// engine.addEntity(Misc.copyEntity(aiTest));

*/

// ===============SYSTEMS===============
// input
if (Gdx.app.getType() == ApplicationType.Android || Gdx.app.getType() == ApplicationType.iOS) {
Expand Down Expand Up @@ -185,6 +208,7 @@ private void initWorld(LandConfig landCFG) {


DebugUISystem.printEntities(engine);
DebugUISystem.printSystems(engine);
}

@Override
Expand All @@ -194,15 +218,27 @@ public void render(float delta) {
// update engine
engine.update(delta);

if (Gdx.input.isKeyJustPressed(Keys.H)){
transition = true;
}

if (Gdx.input.isKeyJustPressed(Keys.U)) {
//DebugUISystem.printEntities(engine);
System.out.println("Engine: " + engine + " - " + engine.getEntities().size());
for (Entity e : engine.getEntitiesFor(Family.all(CameraFocusComponent.class, TransformComponent.class).get())) {
System.out.println("-->"+e);
}
}
if (transition) {
dispose();
//ImmutableArray<Entity> player = engine.getEntitiesFor(Family.all(CameraFocusComponent.class, TransformComponent.class).get());
//landCFG.ship = player.first();
//dispose();
if (inSpace) {
initWorld(landCFG);
} else {
initSpace(landCFG);
}
transition = false;

transition = false;
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/com/spaceproject/systems/CameraSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public CameraSystem() {
public CameraSystem(OrthographicCamera camera) {
super(Family.all(CameraFocusComponent.class, TransformComponent.class).get());
cam = camera;
System.out.println(this.getFamily());
}

public void processEntity(Entity entity, float delta) {
TransformComponent transform = Mappers.transform.get(entity);
//System.out.println(String.format("%X", entity.hashCode()));

//set camera position to entity
cam.position.x = transform.pos.x;
Expand Down
18 changes: 17 additions & 1 deletion core/src/com/spaceproject/systems/DebugUISystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.badlogic.ashley.core.Component;
import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.badlogic.ashley.utils.ImmutableArray;
Expand Down Expand Up @@ -177,9 +178,22 @@ public static void printEntities(Engine eng) {
}
}

public void printEntities() {
private void printEntities() {
printEntities(engine);
}

public static void printSystems(Engine eng) {
for (EntitySystem sys : eng.getSystems()) {
System.out.println(sys + " (" + sys.priority + ")");

}

}

private void printSystems() {
printSystems(engine);
}


private void updateKeyToggles() {
//toggle debug
Expand Down Expand Up @@ -482,5 +496,7 @@ public void dispose() {
C [atio6axx.dll+0x3c4370]
*/
}



}

0 comments on commit 012bd0b

Please sign in to comment.