Merge branch 'develop'

This commit is contained in:
2014-07-01 10:16:23 -04:30
6 changed files with 86 additions and 27 deletions

View File

@@ -24,7 +24,7 @@ import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.RobotArmRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase;
import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem;
@@ -154,7 +154,7 @@ public abstract class ScenarioGlobals{
gameWorld.setSystem(gameLogicSystem);
gameWorld.setSystem(playerSystem, true);
gameWorld.setSystem(new MarkerRenderingSystem(modelBatch), true);
gameWorld.setSystem(new ObjectRenderingSystem(modelBatch), true);
gameWorld.setSystem(new RobotArmRenderingSystem(modelBatch), true);
gameWorld.setSystem(new FadeEffectRenderingSystem(), true);
gameWorld.initialize();

View File

@@ -33,8 +33,7 @@ import com.badlogic.gdx.Gdx;
public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBase {
private static final String TAG = "BOMB_GAME_AUTO_PERFORMER";
private static final String CLASS_NAME = BombGameAutomaticActionPerformer.class.getSimpleName();
private static final int GOAL_FLOOR_MIN_LUMINANCE = 75;
private static final int MARKER_NEARBY_FLOOR_MIN_LUMINANCE = 45;
private static final int MARKER_NEARBY_FLOOR_MIN_LUMINANCE = 50;
private enum action_state_t{
START, WALK_FORWARD, DETECT_MARKER, FINISHING, END;
@@ -44,6 +43,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
private int numCombinationBombs;
private int numInclinationBombs;
private int numWireBombs;
private int totalBombs;
public BombGameAutomaticActionSummary(){
reset();
@@ -63,14 +63,21 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
public void addCombinationBomb(){
numCombinationBombs++;
totalBombs++;
}
public void addInclinationBomb(){
numInclinationBombs++;
totalBombs++;
}
public void addWireBomb(){
numWireBombs++;
totalBombs++;
}
public int getBombsSeen(){
return totalBombs;
}
@Override
@@ -78,6 +85,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
this.numCombinationBombs = 0;
this.numInclinationBombs = 0;
this.numWireBombs = 0;
this.totalBombs = 0;
}
}
@@ -86,6 +94,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
private List<Integer> detectedMarkers;
private float then;
private float now;
private int stops;
private GroupManager manager;
private BombGameAutomaticActionSummary summary;
@@ -103,7 +112,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
public boolean performAutomaticAction(int lightSensorReading, MarkerData markers) throws IllegalStateException, IllegalArgumentException{
BombComponent bomb;
boolean finish = false;
boolean markerDetected = false;
boolean markerAlreadyDetected = false;
int detectedCode = -1;
ImmutableBag<Entity> entities = null;
float deltaT;
@@ -125,7 +134,8 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
switch(state){
case START:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is START.");
summary.reset();
// Reset everything, then look to the left and start moving forward.
this.reset();
nextAction = automatic_action_t.ROTATE_90;
state = action_state_t.WALK_FORWARD;
finish = false;
@@ -133,17 +143,22 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
case WALK_FORWARD:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is WALK_FORWARD.");
if(lightSensorReading >= GOAL_FLOOR_MIN_LUMINANCE){
// Check if all stops have been found.
if(stops >= BombGameEntityCreator.NUM_BOMBS){
// If all stops have been found then stop the robot and finish the automatic action.
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Found goal.");
nextAction = automatic_action_t.STOP;
state = action_state_t.FINISHING;
}else{
if(lightSensorReading >= MARKER_NEARBY_FLOOR_MIN_LUMINANCE && lightSensorReading < GOAL_FLOOR_MIN_LUMINANCE){
// If there are stops to be found yet then check if the light sensor found a stop.
if(lightSensorReading >= MARKER_NEARBY_FLOOR_MIN_LUMINANCE){
// If a stop have been found then check if there is a marker nearby.
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): There is a marker nearby.");
nextAction = automatic_action_t.STOP;
state = action_state_t.DETECT_MARKER;
then = Gdx.graphics.getDeltaTime();
}else{
// If the light sensor didn't find a stop the keep moving.
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Walking.");
nextAction = automatic_action_t.GO_FORWARD;
}
@@ -153,18 +168,18 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
case DETECT_MARKER:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is DETECT_MARKER.");
for(int i = 0; !markerDetected && i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
for(int i = 0; !markerAlreadyDetected && i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
// Check if this marker has not been detected already.
for(Integer code : detectedMarkers){
if(markers.markerCodes[i] == code){
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Marker already detected.");
markerDetected = true;
markerAlreadyDetected = true;
break;
}
}
// If the marker has not been detected before then examine it.
if(!markerDetected){
if(!markerAlreadyDetected){
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): New marker detected.");
detectedCode = markers.markerCodes[i];
entities = manager.getEntities(Integer.toString(detectedCode));
@@ -197,17 +212,21 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
}
}
if(!markerDetected && detectedCode != -1)
// If found a marker and it has not been detected before then add it to the detected markers list.
if(!markerAlreadyDetected && detectedCode != -1)
detectedMarkers.add(detectedCode);
if(lightSensorReading < MARKER_NEARBY_FLOOR_MIN_LUMINANCE){
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Switching to WALK_FORWARD.");
// If cleared the stop mark on the floor then start moving is search for the next mark.
state = action_state_t.WALK_FORWARD;
nextAction = automatic_action_t.STOP;
then = 0.0f;
now = 0.0f;
stops++;
}else{
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Clearing MARKER_NEARBY_FLOOR.");
// Wait for two seconds to make sure the marker can be correctly detected.
now += Gdx.graphics.getDeltaTime();
deltaT = now - then;
if(deltaT >= 2.0f){
@@ -223,6 +242,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
case FINISHING:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is FINISHING.");
// Recenter the camera.
state = action_state_t.END;
nextAction = automatic_action_t.RECENTER;
finish = false;
@@ -230,12 +250,10 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
case END:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is END.");
// Finish the automatic action.
nextAction = automatic_action_t.NO_ACTION;
state = action_state_t.START;
finish = true;
now = 0.0f;
then = 0.0f;
detectedMarkers.clear();
break;
default:
@@ -277,5 +295,6 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
state = action_state_t.START;
nextAction = automatic_action_t.NO_ACTION;
then = 0.0f;
stops = 0;
}
}

View File

@@ -126,6 +126,9 @@ public class BombGameAutomaticActionSummaryOverlay extends SummaryOverlayBase{
font.draw(batch, String.format("Combination bombs: %d", bombGameSummary.getNumCombinationBombs()), combinationX, combinationY);
font.draw(batch, String.format("Wire bombs: %d", bombGameSummary.getNumWireBombs()), wireX, wireY);
font.draw(batch, "Bombs found: " + bombGameSummary.getBombsSeen(), wireX, inclinationY + inclinationBomb.getHeight() + font.getCapHeight() + 20.0f);
font.draw(batch, "Bombs expected: " + BombGameEntityCreator.NUM_BOMBS, wireX, inclinationY + inclinationBomb.getHeight() + 10.0f);
if(!Ouya.runningOnOuya)
titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
else

View File

@@ -32,7 +32,7 @@ import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.RobotArmRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase;
import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -98,7 +98,7 @@ public class InGameState extends BaseState{
// Game related fields.
private World gameWorld;
private MarkerRenderingSystem markerRenderingSystem;
private ObjectRenderingSystem objectRenderingSystem;
private RobotArmRenderingSystem robotArmRenderingSystem;
private RobotArmPositioningSystem robotArmPositioningSystem;
private FadeEffectRenderingSystem fadeEffectRenderingSystem;
private PlayerSystemBase playerSystem;
@@ -249,11 +249,11 @@ public class InGameState extends BaseState{
robotArmPositioningSystem = gameWorld.getSystem(RobotArmPositioningSystem.class);
markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class);
objectRenderingSystem = gameWorld.getSystem(ObjectRenderingSystem.class);
robotArmRenderingSystem = gameWorld.getSystem(RobotArmRenderingSystem.class);
fadeEffectRenderingSystem = gameWorld.getSystem(FadeEffectRenderingSystem.class);
playerSystem = ScenarioGlobals.getPlayerSystem();
if(robotArmPositioningSystem == null || markerRenderingSystem == null || objectRenderingSystem == null || fadeEffectRenderingSystem == null)
if(robotArmPositioningSystem == null || markerRenderingSystem == null || robotArmRenderingSystem == null || fadeEffectRenderingSystem == null)
throw new IllegalStateException("One or more essential systems are null.");
}
@@ -357,9 +357,9 @@ public class InGameState extends BaseState{
markerRenderingSystem.end();
if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue() || Ouya.runningOnOuya){
objectRenderingSystem.begin(perspectiveCamera);
objectRenderingSystem.process();
objectRenderingSystem.end();
robotArmRenderingSystem.begin(perspectiveCamera);
robotArmRenderingSystem.process();
robotArmRenderingSystem.end();
}
}frameBuffer.end();

View File

@@ -39,8 +39,8 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
private static final float INTERPOLATION_STEP = 0.05f;
private static final float STEP_SIZE = 0.05f;
private static final float MAX_Z = -4.5f;
private static final float MIN_Z = -1.0f;
public static final float MAX_Z = -4.5f;
public static final float MIN_Z = -1.0f;
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
@Mapper ComponentMapper<AutomaticMovementComponent> autoMapper;

View File

@@ -16,6 +16,7 @@
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
@@ -25,27 +26,49 @@ import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Disposable;
/**
* <p>Entity processing system in charge of rendering 3D objects using OpenGL. The
* entities to be rendered must have a geometry, shader and mesh component associated.</p>
*/
public class ObjectRenderingSystem extends EntityProcessingSystem {
public class RobotArmRenderingSystem extends EntityProcessingSystem implements Disposable{
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
@Mapper ComponentMapper<RenderModelComponent> modelMapper;
@Mapper ComponentMapper<EnvironmentComponent> environmentMapper;
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
private PerspectiveCamera camera;
private ModelBatch batch;
private ModelBatch batch;
private Model lineModel;
private ModelInstance lineInstance;
private Vector3 temp;
@SuppressWarnings("unchecked")
public ObjectRenderingSystem(ModelBatch batch) {
public RobotArmRenderingSystem(ModelBatch batch) {
super(Aspect.getAspectForAll(ShaderComponent.class, RenderModelComponent.class, EnvironmentComponent.class).exclude(MarkerCodeComponent.class));
camera = null;
this.batch = batch;
// MeshBuilder builder = new MeshBuilder();
// builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 4, "a_position"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_LINES);{
// builder.line(new Vector3(0.0f, 0.0f, RobotArmPositioningSystem.MIN_Z), Color.YELLOW, new Vector3(0.0f, 0.0f, RobotArmPositioningSystem.MAX_Z), Color.YELLOW);
// }lineMesh = builder.end();
// lineModel = ModelBuilder.createFromMesh(lineMesh, GL20.GL_LINES, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.YELLOW)));
// lineModel = new ModelBuilder().createArrow(new Vector3(0.0f, 0.0f, RobotArmPositioningSystem.MIN_Z), new Vector3(0.0f, 0.0f, RobotArmPositioningSystem.MAX_Z), new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.YELLOW)), Usage.Position | Usage.Color | Usage.Normal);
lineModel = new ModelBuilder().createBox(0.01f, 0.01f, 3.5f, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.YELLOW)), Usage.Position | Usage.Color | Usage.Normal);
lineInstance = new ModelInstance(lineModel);
temp = new Vector3();
}
public void begin(PerspectiveCamera camera) throws RuntimeException{
@@ -66,13 +89,27 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
EnvironmentComponent environment;
ShaderComponent shaderComponent;
RenderModelComponent renderModelComponent;
GeometryComponent geometry;
// Get the necessary components.
renderModelComponent = modelMapper.get(e);
shaderComponent = shaderMapper.get(e);
environment = environmentMapper.get(e);
geometry = geometryMapper.getSafe(e);
if(geometry != null){
temp.set(geometry.position.x, geometry.position.y, -2.5f);
lineInstance.transform.idt().setToTranslation(temp);
}
// Render this entity.
batch.render(renderModelComponent.instance, environment.environment, shaderComponent.shader);
batch.render(lineInstance, environment.environment, shaderComponent.shader);
}
@Override
public void dispose() {
if(lineModel != null)
lineModel.dispose();
}
}