Finally fixed restart problem. Basic inclination bombs.
This commit is contained in:
@@ -405,8 +405,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
|||||||
public void pause(){
|
public void pause(){
|
||||||
if(videoThread != null)
|
if(videoThread != null)
|
||||||
videoThread.pause();
|
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(){
|
public void resume(){
|
||||||
if(videoThread != null)
|
if(videoThread != null)
|
||||||
videoThread.play();
|
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();
|
videoThread.finish();
|
||||||
robotThread.finish();
|
robotThread.finish();
|
||||||
sensorThread.finish();
|
sensorThread.finish();
|
||||||
|
videoThread = null;
|
||||||
|
robotThread = null;
|
||||||
|
sensorThread = null;
|
||||||
ServiceDiscoveryThread.freeInstance();
|
ServiceDiscoveryThread.freeInstance();
|
||||||
VideoStreamingThread.freeInstance();
|
VideoStreamingThread.freeInstance();
|
||||||
RobotControlThread.freeInstance();
|
RobotControlThread.freeInstance();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class BombGameObjectTypeComponent extends Component {
|
|||||||
public static final int COM_BUTTON_3 = 32;
|
public static final int COM_BUTTON_3 = 32;
|
||||||
public static final int COM_BUTTON_4 = 33;
|
public static final int COM_BUTTON_4 = 33;
|
||||||
public static final int DOOR = 40;
|
public static final int DOOR = 40;
|
||||||
|
public static final int DOOR_FRAME = 41;
|
||||||
|
|
||||||
public int type;
|
public int type;
|
||||||
|
|
||||||
|
|||||||
@@ -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_BOMB_COLLISION_MODELS = false;
|
||||||
private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
|
private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
|
||||||
private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
|
private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
|
||||||
|
public static final String DOORS_GROUP = "DOORS";
|
||||||
|
|
||||||
private class EntityParameters{
|
private class EntityParameters{
|
||||||
public Environment environment;
|
public Environment environment;
|
||||||
@@ -281,7 +282,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
|||||||
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
|
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
|
||||||
|
|
||||||
// Add the bomb and increase the id for the next one.
|
// 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();
|
bomb.addToWorld();
|
||||||
currentBombId++;
|
currentBombId++;
|
||||||
}
|
}
|
||||||
@@ -342,7 +343,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
|||||||
thing.addComponent(new VisibilityComponent());
|
thing.addComponent(new VisibilityComponent());
|
||||||
thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
|
thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
|
||||||
thing.addComponent(new CollisionDetectionComponent());
|
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)
|
if(DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS)
|
||||||
addDebugCollisionModelRenderingEntity(collisionModel, parameters, false);
|
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 GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
|
||||||
frame.addComponent(new RenderModelComponent(doorFrameModel));
|
frame.addComponent(new RenderModelComponent(doorFrameModel));
|
||||||
frame.addComponent(new CollisionModelComponent(doorFrameCollisionModel));
|
frame.addComponent(new CollisionModelComponent(doorFrameCollisionModel));
|
||||||
|
frame.addComponent(new CollisionDetectionComponent());
|
||||||
frame.addComponent(new EnvironmentComponent(parameters.environment));
|
frame.addComponent(new EnvironmentComponent(parameters.environment));
|
||||||
frame.addComponent(new ShaderComponent(parameters.shader));
|
frame.addComponent(new ShaderComponent(parameters.shader));
|
||||||
frame.addComponent(new VisibilityComponent());
|
frame.addComponent(new VisibilityComponent());
|
||||||
frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
|
frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
|
||||||
|
frame.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.DOOR_FRAME));
|
||||||
|
groupManager.add(frame, Integer.toString(parameters.markerCode));
|
||||||
frame.addToWorld();
|
frame.addToWorld();
|
||||||
|
|
||||||
door = world.createEntity();
|
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 AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation, doorColInstance));
|
||||||
door.addComponent(new CollisionDetectionComponent());
|
door.addComponent(new CollisionDetectionComponent());
|
||||||
door.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.DOOR));
|
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();
|
door.addToWorld();
|
||||||
|
|
||||||
if(DEBUG_RENDER_DOOR_COLLISION_MODELS){
|
if(DEBUG_RENDER_DOOR_COLLISION_MODELS){
|
||||||
|
|||||||
@@ -96,6 +96,11 @@ public class RobotControlThread extends Thread {
|
|||||||
|
|
||||||
public void finish(){
|
public void finish(){
|
||||||
done = true;
|
done = true;
|
||||||
|
try{
|
||||||
|
server.close();
|
||||||
|
}catch(IOException io){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error closing client: " + io.getMessage(), io);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -177,7 +182,6 @@ public class RobotControlThread extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
client.close();
|
client.close();
|
||||||
}catch(IOException io){
|
}catch(IOException io){
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ public class SensorReportThread extends Thread {
|
|||||||
|
|
||||||
public void finish(){
|
public void finish(){
|
||||||
done = true;
|
done = true;
|
||||||
|
try{
|
||||||
|
server.close();
|
||||||
|
}catch(IOException io){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: IOException closing sockets: " + io.getMessage(), io);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getLightSensorReading(){
|
public byte getLightSensorReading(){
|
||||||
@@ -131,5 +136,13 @@ public class SensorReportThread extends Thread {
|
|||||||
lightReading = reading[0];
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ public class AnimationSystem extends EntityProcessingSystem {
|
|||||||
int loopCount = animation.loop ? -1 : 1;
|
int loopCount = animation.loop ? -1 : 1;
|
||||||
|
|
||||||
if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){
|
if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){
|
||||||
|
animation.current = animation.next;
|
||||||
|
|
||||||
if(animation.controller.current == null){
|
if(animation.controller.current == null){
|
||||||
animation.controller.setAnimation(animation.animationsIds.get(animation.next), loopCount, 1, null);
|
animation.controller.setAnimation(animation.animationsIds.get(animation.next), loopCount, 1, null);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -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.CollisionDetectionComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
|
||||||
|
|
||||||
import com.artemis.Aspect;
|
import com.artemis.Aspect;
|
||||||
import com.artemis.ComponentMapper;
|
import com.artemis.ComponentMapper;
|
||||||
import com.artemis.Entity;
|
import com.artemis.Entity;
|
||||||
import com.artemis.annotations.Mapper;
|
import com.artemis.annotations.Mapper;
|
||||||
|
import com.artemis.managers.GroupManager;
|
||||||
|
import com.artemis.utils.ImmutableBag;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
|
||||||
public class BombGameLogicSystem extends GameLogicSystemBase {
|
public class BombGameLogicSystem extends GameLogicSystemBase {
|
||||||
@@ -37,6 +40,9 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
|
|||||||
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
|
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
|
||||||
@Mapper ComponentMapper<CollisionDetectionComponent> collisionMapper;
|
@Mapper ComponentMapper<CollisionDetectionComponent> collisionMapper;
|
||||||
|
|
||||||
|
private MarkerCodeComponent tempMarker;
|
||||||
|
private BombGameObjectTypeComponent tempType;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public BombGameLogicSystem(){
|
public BombGameLogicSystem(){
|
||||||
super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class));
|
super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class));
|
||||||
@@ -56,6 +62,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
|
|||||||
case BombGameObjectTypeComponent.BOMB_WIRE_3:
|
case BombGameObjectTypeComponent.BOMB_WIRE_3:
|
||||||
break;
|
break;
|
||||||
case BombGameObjectTypeComponent.BIG_BUTTON:
|
case BombGameObjectTypeComponent.BIG_BUTTON:
|
||||||
|
processInclinationBomb(e);
|
||||||
break;
|
break;
|
||||||
case BombGameObjectTypeComponent.COM_BUTTON_1:
|
case BombGameObjectTypeComponent.COM_BUTTON_1:
|
||||||
break;
|
break;
|
||||||
@@ -68,12 +75,50 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
|
|||||||
case BombGameObjectTypeComponent.DOOR:
|
case BombGameObjectTypeComponent.DOOR:
|
||||||
processDoor(e);
|
processDoor(e);
|
||||||
break;
|
break;
|
||||||
|
case BombGameObjectTypeComponent.DOOR_FRAME:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".process(): Unrecognized object type.");
|
Gdx.app.debug(TAG, CLASS_NAME + ".process(): Unrecognized object type.");
|
||||||
break;
|
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){
|
private void processDoor(Entity d){
|
||||||
CollisionDetectionComponent collision = collisionMapper.getSafe(d);
|
CollisionDetectionComponent collision = collisionMapper.getSafe(d);
|
||||||
AnimationComponent animation = animationMapper.getSafe(d);
|
AnimationComponent animation = animationMapper.getSafe(d);
|
||||||
@@ -85,12 +130,42 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(marker.enabled && visibility.visible && collision.colliding && animation.current != 1){
|
if(visibility.visible){
|
||||||
animation.next = 1;
|
if(marker.enabled){
|
||||||
animation.loop = false;
|
if(collision.colliding){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Animating door.");
|
animation.next = 1;
|
||||||
|
animation.loop = false;
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
return doorOpen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.math.collision.BoundingBox;
|
import com.badlogic.gdx.math.collision.BoundingBox;
|
||||||
|
|
||||||
public class CollisionDetectionSystem extends EntityProcessingSystem {
|
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<CollisionModelComponent> collisionModelMapper;
|
||||||
@Mapper ComponentMapper<CollisionDetectionComponent> collisionDetectionMapper;
|
@Mapper ComponentMapper<CollisionDetectionComponent> collisionDetectionMapper;
|
||||||
@@ -63,7 +63,7 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
|
|||||||
|
|
||||||
// Get all other entities this entity can collide with.
|
// Get all other entities this entity can collide with.
|
||||||
groupManager = this.world.getManager(GroupManager.class);
|
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){
|
for(int i = 0; i < collidables.size(); ++i){
|
||||||
// Try to get the necessary components for the collidable entity.
|
// Try to get the necessary components for the collidable entity.
|
||||||
|
|||||||
Reference in New Issue
Block a user