Finally fixed restart problem. Basic inclination bombs.

This commit is contained in:
2014-06-11 17:28:26 -04:30
parent 95bb97536c
commit 6c63ebf907
8 changed files with 116 additions and 15 deletions

View File

@@ -405,8 +405,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
public void pause(){
if(videoThread != null)
videoThread.pause();
// TODO: Ignore pausing paused threads.
// TODO: Pause the other threads.
}
/**
@@ -416,8 +414,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
public void resume(){
if(videoThread != null)
videoThread.play();
// TODO: Ignore resuming resumed threads.
// TODO: Resume the other threads.
}
/**
@@ -429,6 +425,9 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
videoThread.finish();
robotThread.finish();
sensorThread.finish();
videoThread = null;
robotThread = null;
sensorThread = null;
ServiceDiscoveryThread.freeInstance();
VideoStreamingThread.freeInstance();
RobotControlThread.freeInstance();

View File

@@ -27,6 +27,7 @@ public class BombGameObjectTypeComponent extends Component {
public static final int COM_BUTTON_3 = 32;
public static final int COM_BUTTON_4 = 33;
public static final int DOOR = 40;
public static final int DOOR_FRAME = 41;
public int type;

View File

@@ -52,6 +52,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private static final boolean DEBUG_RENDER_BOMB_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
public static final String DOORS_GROUP = "DOORS";
private class EntityParameters{
public Environment environment;
@@ -281,7 +282,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
// Add the bomb and increase the id for the next one.
groupManager.add(bomb, CollisionDetectionSystem.COLLIDABLE_OBJECT);
//groupManager.add(bomb, CollisionDetectionSystem.COLLIDABLE_OBJECT);
bomb.addToWorld();
currentBombId++;
}
@@ -342,7 +343,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
thing.addComponent(new VisibilityComponent());
thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
thing.addComponent(new CollisionDetectionComponent());
groupManager.add(thing, CollisionDetectionSystem.COLLIDABLE_OBJECT);
groupManager.add(thing, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
groupManager.add(thing, Integer.toString(parameters.markerCode));
if(DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS)
addDebugCollisionModelRenderingEntity(collisionModel, parameters, false);
@@ -358,10 +360,13 @@ public class BombGameEntityCreator extends EntityCreatorBase{
frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
frame.addComponent(new RenderModelComponent(doorFrameModel));
frame.addComponent(new CollisionModelComponent(doorFrameCollisionModel));
frame.addComponent(new CollisionDetectionComponent());
frame.addComponent(new EnvironmentComponent(parameters.environment));
frame.addComponent(new ShaderComponent(parameters.shader));
frame.addComponent(new VisibilityComponent());
frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
frame.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.DOOR_FRAME));
groupManager.add(frame, Integer.toString(parameters.markerCode));
frame.addToWorld();
door = world.createEntity();
@@ -377,7 +382,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation, doorColInstance));
door.addComponent(new CollisionDetectionComponent());
door.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.DOOR));
groupManager.add(door, CollisionDetectionSystem.COLLIDABLE_OBJECT);
groupManager.add(door, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
groupManager.add(door, Integer.toString(parameters.markerCode));
groupManager.add(door, DOORS_GROUP);
door.addToWorld();
if(DEBUG_RENDER_DOOR_COLLISION_MODELS){

View File

@@ -96,6 +96,11 @@ public class RobotControlThread extends Thread {
public void finish(){
done = true;
try{
server.close();
}catch(IOException io){
Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error closing client: " + io.getMessage(), io);
}
}
@Override
@@ -177,7 +182,6 @@ public class RobotControlThread extends Thread {
}
}
try{
client.close();
}catch(IOException io){

View File

@@ -90,6 +90,11 @@ public class SensorReportThread extends Thread {
public void finish(){
done = true;
try{
server.close();
}catch(IOException io){
Gdx.app.error(TAG, CLASS_NAME + ".run() :: IOException closing sockets: " + io.getMessage(), io);
}
}
public byte getLightSensorReading(){
@@ -131,5 +136,13 @@ public class SensorReportThread extends Thread {
lightReading = reading[0];
}
}
try{
reader.close();
client.close();
server.close();
}catch(IOException io){
Gdx.app.error(TAG, CLASS_NAME + ".run() :: IOException closing sockets: " + io.getMessage(), io);
}
}
}

View File

@@ -41,6 +41,8 @@ public class AnimationSystem extends EntityProcessingSystem {
int loopCount = animation.loop ? -1 : 1;
if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){
animation.current = animation.next;
if(animation.controller.current == null){
animation.controller.setAnimation(animation.animationsIds.get(animation.next), loopCount, 1, null);
}else{

View File

@@ -20,11 +20,14 @@ import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Mapper;
import com.artemis.managers.GroupManager;
import com.artemis.utils.ImmutableBag;
import com.badlogic.gdx.Gdx;
public class BombGameLogicSystem extends GameLogicSystemBase {
@@ -37,6 +40,9 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
@Mapper ComponentMapper<CollisionDetectionComponent> collisionMapper;
private MarkerCodeComponent tempMarker;
private BombGameObjectTypeComponent tempType;
@SuppressWarnings("unchecked")
public BombGameLogicSystem(){
super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class));
@@ -56,6 +62,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
case BombGameObjectTypeComponent.BOMB_WIRE_3:
break;
case BombGameObjectTypeComponent.BIG_BUTTON:
processInclinationBomb(e);
break;
case BombGameObjectTypeComponent.COM_BUTTON_1:
break;
@@ -68,12 +75,50 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
case BombGameObjectTypeComponent.DOOR:
processDoor(e);
break;
case BombGameObjectTypeComponent.DOOR_FRAME:
break;
default:
Gdx.app.debug(TAG, CLASS_NAME + ".process(): Unrecognized object type.");
break;
}
}
private void processInclinationBomb(Entity b){
CollisionDetectionComponent collision = collisionMapper.getSafe(b);
MarkerCodeComponent marker = markerMapper.getSafe(b);
GroupManager manager = world.getManager(GroupManager.class);
ImmutableBag<Entity> related;
if(marker == null || collision == null ){
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb is missing some components.");
return;
}
if(isDoorOpen(marker.code, manager) && marker.enabled && collision.colliding){
marker.enabled = false;
manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
// Disable all related entities.
related = manager.getEntities(Integer.toString(marker.code));
for(int i = 0; i < related.size(); i++){
tempMarker = markerMapper.getSafe(related.get(i));
tempType = typeMapper.getSafe(related.get(i));
// Enable collisions with the door frame. Disable collisions with other related objects.
if(tempMarker != null) tempMarker.enabled = false;
if(tempType != null){
if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME){
manager.remove(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
}else{
manager.add(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
}
}
}
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Disabling inclination bomb.");
}
}
private void processDoor(Entity d){
CollisionDetectionComponent collision = collisionMapper.getSafe(d);
AnimationComponent animation = animationMapper.getSafe(d);
@@ -85,12 +130,42 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
return;
}
if(marker.enabled && visibility.visible && collision.colliding && animation.current != 1){
if(visibility.visible){
if(marker.enabled){
if(collision.colliding){
animation.next = 1;
animation.loop = false;
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Animating door.");
collision.colliding = false;
world.getManager(GroupManager.class).remove(d, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Opening door.");
}
}else{
if(animation.current != 0){
animation.next = 0;
animation.loop = false;
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Closing door.");
}
}
}
}
return;
private boolean isDoorOpen(int markerCode, GroupManager manager){
AnimationComponent animation;
boolean doorOpen = false;
ImmutableBag<Entity> doors = manager.getEntities(BombGameEntityCreator.DOORS_GROUP);
for(int i = 0; i < doors.size(); i++){
tempMarker = markerMapper.getSafe(doors.get(i));
animation = animationMapper.getSafe(doors.get(i));
if(animation == null || tempMarker == null) return false;
if(tempMarker.code == markerCode && animation.current == 1 && animation.controller.current.loopCount == 0){
doorOpen = true;
break;
}
}
return doorOpen;
}
}

View File

@@ -31,7 +31,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.collision.BoundingBox;
public class CollisionDetectionSystem extends EntityProcessingSystem {
public static final String COLLIDABLE_OBJECT = "COLLIDABLE";
public static final String COLLIDABLE_OBJECTS_GROUP = "COLLIDABLE";
@Mapper ComponentMapper<CollisionModelComponent> collisionModelMapper;
@Mapper ComponentMapper<CollisionDetectionComponent> collisionDetectionMapper;
@@ -63,7 +63,7 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
// Get all other entities this entity can collide with.
groupManager = this.world.getManager(GroupManager.class);
collidables = groupManager.getEntities(COLLIDABLE_OBJECT);
collidables = groupManager.getEntities(COLLIDABLE_OBJECTS_GROUP);
for(int i = 0; i < collidables.size(); ++i){
// Try to get the necessary components for the collidable entity.