Add SARL project with Guy

This commit is contained in:
Skia 2016-06-06 14:47:19 +02:00
parent 98ae4e3f33
commit 0d1182404b
218 changed files with 13711 additions and 4 deletions

View file

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path=""/>
<classpathentry kind="src" path="src/main/sarl"/>
<classpathentry kind="src" path="src/main/generated-sources/sarl">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="/home/skia/Documents/UTBM/GI04/VI51/TP2 - SARL/io.janusproject.kernel-2.0.3.1-with-dependencies.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -1,10 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>VI51-Project</name>
<name>VI51-TP5-Boids</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
@ -12,6 +17,8 @@
</buildCommand>
</buildSpec>
<natures>
<nature>io.sarl.eclipse.SARLProjectNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,4 @@
BuilderConfiguration.is_project_specific=true
eclipse.preferences.version=1
is_project_specific=true
outlet.DEFAULT_OUTPUT.cleanDirectory=true

View file

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

3
META-INF/MANIFEST.MF Normal file
View file

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Created-By: 1.8.0_91 (Oracle Corporation)

View file

@ -0,0 +1,468 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.eurock.agent;
import com.google.common.base.Objects;
import fr.utbm.info.vi51.framework.agent.AbstractAnimat;
import fr.utbm.info.vi51.framework.environment.PerceptionEvent;
import fr.utbm.info.vi51.framework.environment.SimulationAgentReady;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.AlignBehaviour;
import fr.utbm.info.vi51.motionbehavior.KinematicAlignBehaviour;
import fr.utbm.info.vi51.motionbehavior.KinematicSeekBehaviour;
import fr.utbm.info.vi51.motionbehavior.KinematicWanderBehaviour;
import fr.utbm.info.vi51.motionbehavior.SeekBehaviour;
import fr.utbm.info.vi51.motionbehavior.WanderBehaviour;
import io.sarl.core.AgentSpawned;
import io.sarl.core.DefaultContextInteractions;
import io.sarl.core.Initialize;
import io.sarl.core.Logging;
import io.sarl.lang.annotation.FiredEvent;
import io.sarl.lang.annotation.ImportedCapacityFeature;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.Address;
import io.sarl.lang.core.Agent;
import io.sarl.lang.core.AgentContext;
import io.sarl.lang.core.BuiltinCapacitiesProvider;
import io.sarl.lang.core.Event;
import io.sarl.lang.core.EventSpace;
import io.sarl.lang.core.Percept;
import io.sarl.lang.core.Scope;
import io.sarl.lang.core.Space;
import io.sarl.lang.core.SpaceID;
import java.io.Serializable;
import java.util.Random;
import java.util.UUID;
import javax.annotation.Generated;
import javax.inject.Inject;
@SarlSpecification("0.3")
@SuppressWarnings("all")
public class Guy extends AbstractAnimat {
protected SeekBehaviour seekBehaviour;
protected WanderBehaviour wanderBehaviour;
protected AlignBehaviour alignBehaviour;
@Percept
public void _handle_Initialize_0(final Initialize occurrence) {
super._handle_Initialize_0(occurrence);
SimulationAgentReady _simulationAgentReady = new SimulationAgentReady();
this.emit(_simulationAgentReady);
KinematicSeekBehaviour _kinematicSeekBehaviour = new KinematicSeekBehaviour();
this.seekBehaviour = _kinematicSeekBehaviour;
KinematicAlignBehaviour _kinematicAlignBehaviour = new KinematicAlignBehaviour();
this.alignBehaviour = _kinematicAlignBehaviour;
KinematicWanderBehaviour _kinematicWanderBehaviour = new KinematicWanderBehaviour();
this.wanderBehaviour = _kinematicWanderBehaviour;
}
@Percept
public void _handle_PerceptionEvent_1(final PerceptionEvent occurrence) {
fr.utbm.info.vi51.framework.environment.Percept body = occurrence.body;
Vector2f direction = new Vector2f();
Random random = new Random();
Vector2f barycenter = new Vector2f();
Vector2f f = new Vector2f();
int _size = occurrence.perceptions.size();
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
for (final fr.utbm.info.vi51.framework.environment.Percept o : occurrence.perceptions) {
Serializable _type = o.getType();
boolean _equals = Objects.equal(_type, "FISH");
if (_equals) {
Point2f _position = o.getPosition();
Point2f _position_1 = body.getPosition();
Vector2f _minus = _position.operator_minus(_position_1);
barycenter.operator_add(_minus);
Vector2f _direction = o.getDirection();
direction.operator_add(_direction);
Point2f _position_2 = body.getPosition();
Point2f _position_3 = o.getPosition();
Vector2f _minus_1 = _position_2.operator_minus(_position_3);
Vector2f _multiply = _minus_1.operator_multiply(4);
Point2f _position_4 = body.getPosition();
Point2f _position_5 = o.getPosition();
Vector2f _minus_2 = _position_4.operator_minus(_position_5);
float _length = _minus_2.length();
double _power = Math.pow(_length, 1);
double _plus = (_power + 1);
Vector2f _divide = _multiply.operator_divide(((float) _plus));
f.operator_add(_divide);
} else {
Serializable _type_1 = o.getType();
boolean _equals_1 = Objects.equal(_type_1, "TARGET");
if (_equals_1) {
Point2f _position_6 = o.getPosition();
Point2f _position_7 = body.getPosition();
Vector2f _minus_3 = _position_6.operator_minus(_position_7);
Vector2f _multiply_1 = _minus_3.operator_multiply(5);
barycenter.operator_add(_multiply_1);
Point2f _position_8 = o.getPosition();
Point2f _position_9 = body.getPosition();
Vector2f _minus_4 = _position_8.operator_minus(_position_9);
direction.operator_add(_minus_4);
Point2f _position_10 = body.getPosition();
Point2f _position_11 = o.getPosition();
Vector2f _minus_5 = _position_10.operator_minus(_position_11);
Vector2f _unitVector = _minus_5.toUnitVector();
Point2f _position_12 = body.getPosition();
Point2f _position_13 = o.getPosition();
Vector2f _minus_6 = _position_12.operator_minus(_position_13);
float _length_1 = _minus_6.length();
double _power_1 = Math.pow(_length_1, 8);
double _plus_1 = (_power_1 + 1);
Vector2f _divide_1 = _unitVector.operator_divide(((float) _plus_1));
f.operator_add(_divide_1);
}
}
}
Vector2f _barycenter = barycenter;
int _size_1 = occurrence.perceptions.size();
double _divide_2 = (1.0 / _size_1);
barycenter = _barycenter.operator_multiply(((float) _divide_2));
direction.operator_add(barycenter);
Vector2f _plus_2 = barycenter.operator_plus(f);
Vector2f _direction_1 = body.getDirection();
float _signedAngle = _direction_1.signedAngle(direction);
this.influenceKinematic(_plus_2, _signedAngle);
} else {
int _nextInt = random.nextInt();
int _nextInt_1 = random.nextInt();
Vector2f linear = new Vector2f(((float) _nextInt), ((float) _nextInt_1));
double _nextGaussian = random.nextGaussian();
float angular = ((float) _nextGaussian);
this.influenceKinematic(linear, angular);
}
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void emit(final Event arg0) {
getSkill(io.sarl.core.DefaultContextInteractions.class).emit(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event,io.sarl.lang.core.Scope<io.sarl.lang.core.Address>)}.
*
* @see io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event,io.sarl.lang.core.Scope<io.sarl.lang.core.Address>)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void emit(final Event arg0, final Scope<Address> arg1) {
getSkill(io.sarl.core.DefaultContextInteractions.class).emit(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultAddress()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultAddress()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected Address getDefaultAddress() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultAddress();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultContext()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultContext()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected AgentContext getDefaultContext() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultContext();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultSpace()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultSpace()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected EventSpace getDefaultSpace() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultSpace();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultContext(io.sarl.lang.core.AgentContext)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultContext(io.sarl.lang.core.AgentContext)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultContext(final AgentContext arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultContext(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultContext(java.util.UUID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultContext(java.util.UUID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultContext(final UUID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultContext(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.Space)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.Space)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final Space arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.SpaceID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.SpaceID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final SpaceID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(java.util.UUID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(java.util.UUID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final UUID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isInDefaultSpace(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#isInDefaultSpace(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isInDefaultSpace(final Event arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isInDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#receive(java.util.UUID,io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#receive(java.util.UUID,io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void receive(final UUID arg0, final Event arg1) {
getSkill(io.sarl.core.DefaultContextInteractions.class).receive(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#spawn(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.lang.Object[])}.
*
* @see io.sarl.core.DefaultContextInteractions#spawn(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected UUID spawn(final Class<? extends Agent> arg0, final Object... arg1) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).spawn(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.Logging#debug(java.lang.Object)}.
*
* @see io.sarl.core.Logging#debug(java.lang.Object)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected void debug(final Object arg0) {
getSkill(io.sarl.core.Logging.class).debug(arg0);
}
/**
* See the capacity {@link io.sarl.core.Logging#error(java.lang.Object)}.
*
* @see io.sarl.core.Logging#error(java.lang.Object)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected void error(final Object arg0) {
getSkill(io.sarl.core.Logging.class).error(arg0);
}
/**
* See the capacity {@link io.sarl.core.Logging#error(java.lang.Object,java.lang.Throwable)}.
*
* @see io.sarl.core.Logging#error(java.lang.Object,java.lang.Throwable)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected void error(final Object arg0, final Throwable arg1) {
getSkill(io.sarl.core.Logging.class).error(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.Logging#getLogLevel()}.
*
* @see io.sarl.core.Logging#getLogLevel()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected int getLogLevel() {
return getSkill(io.sarl.core.Logging.class).getLogLevel();
}
/**
* See the capacity {@link io.sarl.core.Logging#info(java.lang.Object)}.
*
* @see io.sarl.core.Logging#info(java.lang.Object)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected void info(final Object arg0) {
getSkill(io.sarl.core.Logging.class).info(arg0);
}
/**
* See the capacity {@link io.sarl.core.Logging#isDebugLogEnabled()}.
*
* @see io.sarl.core.Logging#isDebugLogEnabled()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected boolean isDebugLogEnabled() {
return getSkill(io.sarl.core.Logging.class).isDebugLogEnabled();
}
/**
* See the capacity {@link io.sarl.core.Logging#isErrorLogEnabled()}.
*
* @see io.sarl.core.Logging#isErrorLogEnabled()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected boolean isErrorLogEnabled() {
return getSkill(io.sarl.core.Logging.class).isErrorLogEnabled();
}
/**
* See the capacity {@link io.sarl.core.Logging#isInfoLogEnabled()}.
*
* @see io.sarl.core.Logging#isInfoLogEnabled()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected boolean isInfoLogEnabled() {
return getSkill(io.sarl.core.Logging.class).isInfoLogEnabled();
}
/**
* See the capacity {@link io.sarl.core.Logging#isWarningLogEnabled()}.
*
* @see io.sarl.core.Logging#isWarningLogEnabled()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected boolean isWarningLogEnabled() {
return getSkill(io.sarl.core.Logging.class).isWarningLogEnabled();
}
/**
* See the capacity {@link io.sarl.core.Logging#println(java.lang.Object)}.
*
* @see io.sarl.core.Logging#println(java.lang.Object)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected void println(final Object arg0) {
getSkill(io.sarl.core.Logging.class).println(arg0);
}
/**
* See the capacity {@link io.sarl.core.Logging#setLogLevel(int)}.
*
* @see io.sarl.core.Logging#setLogLevel(int)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected void setLogLevel(final int arg0) {
getSkill(io.sarl.core.Logging.class).setLogLevel(arg0);
}
/**
* See the capacity {@link io.sarl.core.Logging#setLoggingName(java.lang.String)}.
*
* @see io.sarl.core.Logging#setLoggingName(java.lang.String)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected void setLoggingName(final String arg0) {
getSkill(io.sarl.core.Logging.class).setLoggingName(arg0);
}
/**
* See the capacity {@link io.sarl.core.Logging#warning(java.lang.Object)}.
*
* @see io.sarl.core.Logging#warning(java.lang.Object)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected void warning(final Object arg0) {
getSkill(io.sarl.core.Logging.class).warning(arg0);
}
/**
* See the capacity {@link io.sarl.core.Logging#warning(java.lang.Object,java.lang.Throwable)}.
*
* @see io.sarl.core.Logging#warning(java.lang.Object,java.lang.Throwable)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Logging.class)
protected void warning(final Object arg0, final Throwable arg1) {
getSkill(io.sarl.core.Logging.class).warning(arg0, arg1);
}
/**
* Construct an agent.
* @param builtinCapacityProvider - provider of the built-in capacities.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
* @param agentID - identifier of the agent. If <code>null</code> the agent identifier will be computed randomly.
*/
@Inject
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public Guy(final BuiltinCapacitiesProvider builtinCapacityProvider, final UUID parentID, final UUID agentID) {
super(builtinCapacityProvider, parentID, agentID);
}
}

View file

@ -0,0 +1,328 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework;
import fr.utbm.info.vi51.framework.environment.AgentBody;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.environment.Environment;
import fr.utbm.info.vi51.framework.environment.EnvironmentAgent;
import fr.utbm.info.vi51.framework.environment.SimulationAgentReady;
import fr.utbm.info.vi51.framework.environment.StartSimulation;
import fr.utbm.info.vi51.framework.util.SpawnMapping;
import io.sarl.core.AgentKilled;
import io.sarl.core.AgentSpawned;
import io.sarl.core.DefaultContextInteractions;
import io.sarl.core.Destroy;
import io.sarl.core.Initialize;
import io.sarl.core.Lifecycle;
import io.sarl.lang.annotation.EarlyExit;
import io.sarl.lang.annotation.FiredEvent;
import io.sarl.lang.annotation.ImportedCapacityFeature;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.Address;
import io.sarl.lang.core.Agent;
import io.sarl.lang.core.AgentContext;
import io.sarl.lang.core.BuiltinCapacitiesProvider;
import io.sarl.lang.core.Event;
import io.sarl.lang.core.EventSpace;
import io.sarl.lang.core.Percept;
import io.sarl.lang.core.Scope;
import io.sarl.lang.core.Space;
import io.sarl.lang.core.SpaceID;
import io.sarl.util.OpenEventSpace;
import io.sarl.util.OpenEventSpaceSpecification;
import java.util.List;
import java.util.UUID;
import javax.annotation.Generated;
import javax.inject.Inject;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pure;
/**
* This agent is managing the simulator.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
*/
@SarlSpecification("0.3")
@SuppressWarnings("all")
public class SimulatorAgent extends Agent {
protected int waitingAgents = 0;
@Percept
public void _handle_Initialize_0(final Initialize occurrence) {
Object _get = occurrence.parameters[0];
Environment environment = ((Environment) _get);
Object _get_1 = occurrence.parameters[1];
UUID spaceId = ((UUID) _get_1);
Object _get_2 = occurrence.parameters[2];
SpawnMapping spawnMapping = ((SpawnMapping) _get_2);
Object _get_3 = occurrence.parameters[3];
DynamicType behaviorType = ((DynamicType) _get_3);
AgentContext _defaultContext = this.getDefaultContext();
OpenEventSpace space = _defaultContext.<OpenEventSpace>getOrCreateSpaceWithID(spaceId, OpenEventSpaceSpecification.class);
this.avoidUnusedVariableWarning(space);
Iterable<? extends AgentBody> _agentBodies = environment.getAgentBodies();
int _size = IterableExtensions.size(_agentBodies);
int _plus = (_size + 1);
this.waitingAgents = _plus;
UUID environmentId = this.spawn(EnvironmentAgent.class, environment, spaceId);
List<Object> agentParameters = CollectionLiterals.<Object>newArrayList(spaceId, environmentId, behaviorType);
for (int i = 4; (i < ((List<Object>)Conversions.doWrapArray(occurrence.parameters)).size()); i++) {
Object _get_4 = occurrence.parameters[i];
agentParameters.add(_get_4);
}
Iterable<? extends AgentBody> _agentBodies_1 = environment.getAgentBodies();
for (final AgentBody body : _agentBodies_1) {
{
Class<? extends Agent> agentType = spawnMapping.getAgentTypeForBody(body);
UUID _iD = body.getID();
AgentContext _defaultContext_1 = this.getDefaultContext();
Object[] _array = agentParameters.toArray();
this.spawnInContextWithID(agentType, _iD, _defaultContext_1, _array);
}
}
}
private void avoidUnusedVariableWarning(final Object o) {
}
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Pure
private boolean _eventhandler_guard_SimulationAgentReady_1(final SimulationAgentReady it, final SimulationAgentReady occurrence) {
boolean _isFromMe = this.isFromMe(occurrence);
boolean _not = (!_isFromMe);
return _not;
}
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
private void _eventhandler_body_SimulationAgentReady_1(final SimulationAgentReady occurrence) {
synchronized (this) {
this.waitingAgents--;
if ((this.waitingAgents <= 0)) {
StartSimulation _startSimulation = new StartSimulation();
this.emit(_startSimulation);
this.killMe();
}
}
}
@Percept
public void _handle_SimulationAgentReady_1(final SimulationAgentReady occurrence) {
if (_eventhandler_guard_SimulationAgentReady_1(occurrence, occurrence)) {
_eventhandler_body_SimulationAgentReady_1(occurrence);
}
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void emit(final Event arg0) {
getSkill(io.sarl.core.DefaultContextInteractions.class).emit(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event,io.sarl.lang.core.Scope<io.sarl.lang.core.Address>)}.
*
* @see io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event,io.sarl.lang.core.Scope<io.sarl.lang.core.Address>)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void emit(final Event arg0, final Scope<Address> arg1) {
getSkill(io.sarl.core.DefaultContextInteractions.class).emit(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultAddress()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultAddress()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected Address getDefaultAddress() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultAddress();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultContext()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultContext()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected AgentContext getDefaultContext() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultContext();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultSpace()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultSpace()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected EventSpace getDefaultSpace() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultSpace();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultContext(io.sarl.lang.core.AgentContext)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultContext(io.sarl.lang.core.AgentContext)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultContext(final AgentContext arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultContext(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultContext(java.util.UUID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultContext(java.util.UUID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultContext(final UUID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultContext(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.Space)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.Space)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final Space arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.SpaceID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.SpaceID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final SpaceID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(java.util.UUID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(java.util.UUID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final UUID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isInDefaultSpace(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#isInDefaultSpace(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isInDefaultSpace(final Event arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isInDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#receive(java.util.UUID,io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#receive(java.util.UUID,io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void receive(final UUID arg0, final Event arg1) {
getSkill(io.sarl.core.DefaultContextInteractions.class).receive(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#spawn(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.lang.Object[])}.
*
* @see io.sarl.core.DefaultContextInteractions#spawn(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected UUID spawn(final Class<? extends Agent> arg0, final Object... arg1) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).spawn(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.Lifecycle#killMe()}.
*
* @see io.sarl.core.Lifecycle#killMe()
*/
@EarlyExit
@FiredEvent({ AgentKilled.class, Destroy.class })
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Lifecycle.class)
protected void killMe() {
getSkill(io.sarl.core.Lifecycle.class).killMe();
}
/**
* See the capacity {@link io.sarl.core.Lifecycle#spawnInContext(java.lang.Class<? extends io.sarl.lang.core.Agent>,io.sarl.lang.core.AgentContext,java.lang.Object[])}.
*
* @see io.sarl.core.Lifecycle#spawnInContext(java.lang.Class<? extends io.sarl.lang.core.Agent>,io.sarl.lang.core.AgentContext,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Lifecycle.class)
protected UUID spawnInContext(final Class<? extends Agent> arg0, final AgentContext arg1, final Object... arg2) {
return getSkill(io.sarl.core.Lifecycle.class).spawnInContext(arg0, arg1, arg2);
}
/**
* See the capacity {@link io.sarl.core.Lifecycle#spawnInContextWithID(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.util.UUID,io.sarl.lang.core.AgentContext,java.lang.Object[])}.
*
* @see io.sarl.core.Lifecycle#spawnInContextWithID(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.util.UUID,io.sarl.lang.core.AgentContext,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Lifecycle.class)
protected UUID spawnInContextWithID(final Class<? extends Agent> arg0, final UUID arg1, final AgentContext arg2, final Object... arg3) {
return getSkill(io.sarl.core.Lifecycle.class).spawnInContextWithID(arg0, arg1, arg2, arg3);
}
/**
* Construct an agent.
* @param builtinCapacityProvider - provider of the built-in capacities.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
* @param agentID - identifier of the agent. If <code>null</code> the agent identifier will be computed randomly.
*/
@Inject
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public SimulatorAgent(final BuiltinCapacitiesProvider builtinCapacityProvider, final UUID parentID, final UUID agentID) {
super(builtinCapacityProvider, parentID, agentID);
}
}

View file

@ -0,0 +1,267 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.agent;
import com.google.common.base.Objects;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.agent.PhysicEnvironment;
import fr.utbm.info.vi51.framework.agent.StandardPhysicEnvironment;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.environment.Influence;
import fr.utbm.info.vi51.framework.environment.StopSimulation;
import fr.utbm.info.vi51.framework.math.Vector2f;
import io.sarl.core.AgentKilled;
import io.sarl.core.AgentSpawned;
import io.sarl.core.Destroy;
import io.sarl.core.Initialize;
import io.sarl.core.Lifecycle;
import io.sarl.lang.annotation.EarlyExit;
import io.sarl.lang.annotation.FiredEvent;
import io.sarl.lang.annotation.ImportedCapacityFeature;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.Agent;
import io.sarl.lang.core.AgentContext;
import io.sarl.lang.core.BuiltinCapacitiesProvider;
import io.sarl.lang.core.Percept;
import java.util.List;
import java.util.UUID;
import javax.annotation.Generated;
import javax.inject.Inject;
import org.eclipse.xtext.xbase.lib.Pure;
@SarlSpecification("0.3")
@SuppressWarnings("all")
public class AbstractAnimat extends Agent {
protected DynamicType behaviorType;
@Percept
public void _handle_Initialize_0(final Initialize occurrence) {
Object _get = occurrence.parameters[0];
Object _get_1 = occurrence.parameters[1];
StandardPhysicEnvironment physicSkill = new StandardPhysicEnvironment(
((UUID) _get),
((UUID) _get_1));
Object _get_2 = occurrence.parameters[2];
this.behaviorType = ((DynamicType) _get_2);
this.<StandardPhysicEnvironment>setSkill(PhysicEnvironment.class, physicSkill);
}
@Pure
protected float getMaxLinear(final fr.utbm.info.vi51.framework.environment.Percept p) {
float _xifexpression = (float) 0;
boolean _equals = Objects.equal(this.behaviorType, DynamicType.STEERING);
if (_equals) {
_xifexpression = p.getMaxLinearAcceleration();
} else {
_xifexpression = p.getMaxLinearSpeed();
}
return _xifexpression;
}
@Pure
protected float getMaxAngular(final fr.utbm.info.vi51.framework.environment.Percept p) {
float _xifexpression = (float) 0;
boolean _equals = Objects.equal(this.behaviorType, DynamicType.STEERING);
if (_equals) {
_xifexpression = p.getMaxAngularAcceleration();
} else {
_xifexpression = p.getMaxAngularSpeed();
}
return _xifexpression;
}
protected void emitInfluence(final BehaviourOutput output, final Influence... influences) {
if ((output != null)) {
DynamicType _type = output.getType();
boolean _tripleEquals = (_type == DynamicType.STEERING);
if (_tripleEquals) {
Vector2f _linear = output.getLinear();
float _angular = output.getAngular();
this.influenceSteering(_linear, _angular, influences);
} else {
Vector2f _linear_1 = output.getLinear();
float _angular_1 = output.getAngular();
this.influenceKinematic(_linear_1, _angular_1, influences);
}
} else {
Vector2f _vector2f = new Vector2f();
this.influenceSteering(_vector2f, 0f, influences);
}
}
protected void doNothing() {
Vector2f _vector2f = new Vector2f();
this.influenceKinematic(_vector2f, 0f);
}
protected fr.utbm.info.vi51.framework.environment.Percept first(final List<fr.utbm.info.vi51.framework.environment.Percept> list) {
fr.utbm.info.vi51.framework.environment.Percept _xifexpression = null;
boolean _isEmpty = list.isEmpty();
if (_isEmpty) {
_xifexpression = null;
} else {
_xifexpression = list.get(0);
}
return _xifexpression;
}
@Percept
public void _handle_StopSimulation_1(final StopSimulation occurrence) {
this.killMe();
}
/**
* See the capacity {@link fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceKinematic(fr.utbm.info.vi51.framework.environment.Influence[])}.
*
* @see fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceKinematic(fr.utbm.info.vi51.framework.environment.Influence[])
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(PhysicEnvironment.class)
protected void influenceKinematic(final Influence... otherInfluences) {
getSkill(fr.utbm.info.vi51.framework.agent.PhysicEnvironment.class).influenceKinematic(otherInfluences);
}
/**
* See the capacity {@link fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceKinematic(float,fr.utbm.info.vi51.framework.environment.Influence[])}.
*
* @see fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceKinematic(float,fr.utbm.info.vi51.framework.environment.Influence[])
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(PhysicEnvironment.class)
protected void influenceKinematic(final float angularInfluence, final Influence... otherInfluences) {
getSkill(fr.utbm.info.vi51.framework.agent.PhysicEnvironment.class).influenceKinematic(angularInfluence, otherInfluences);
}
/**
* See the capacity {@link fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceKinematic(fr.utbm.info.vi51.framework.math.Vector2f,fr.utbm.info.vi51.framework.environment.Influence[])}.
*
* @see fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceKinematic(fr.utbm.info.vi51.framework.math.Vector2f,fr.utbm.info.vi51.framework.environment.Influence[])
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(PhysicEnvironment.class)
protected void influenceKinematic(final Vector2f linearInfluence, final Influence... otherInfluences) {
getSkill(fr.utbm.info.vi51.framework.agent.PhysicEnvironment.class).influenceKinematic(linearInfluence, otherInfluences);
}
/**
* See the capacity {@link fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceKinematic(fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence[])}.
*
* @see fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceKinematic(fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence[])
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(PhysicEnvironment.class)
protected void influenceKinematic(final Vector2f linearInfluence, final float angularInfluence, final Influence... otherInfluences) {
getSkill(fr.utbm.info.vi51.framework.agent.PhysicEnvironment.class).influenceKinematic(linearInfluence, angularInfluence, otherInfluences);
}
/**
* See the capacity {@link fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceSteering(fr.utbm.info.vi51.framework.environment.Influence[])}.
*
* @see fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceSteering(fr.utbm.info.vi51.framework.environment.Influence[])
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(PhysicEnvironment.class)
protected void influenceSteering(final Influence... otherInfluences) {
getSkill(fr.utbm.info.vi51.framework.agent.PhysicEnvironment.class).influenceSteering(otherInfluences);
}
/**
* See the capacity {@link fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceSteering(float,fr.utbm.info.vi51.framework.environment.Influence[])}.
*
* @see fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceSteering(float,fr.utbm.info.vi51.framework.environment.Influence[])
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(PhysicEnvironment.class)
protected void influenceSteering(final float angularInfluence, final Influence... otherInfluences) {
getSkill(fr.utbm.info.vi51.framework.agent.PhysicEnvironment.class).influenceSteering(angularInfluence, otherInfluences);
}
/**
* See the capacity {@link fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceSteering(fr.utbm.info.vi51.framework.math.Vector2f,fr.utbm.info.vi51.framework.environment.Influence[])}.
*
* @see fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceSteering(fr.utbm.info.vi51.framework.math.Vector2f,fr.utbm.info.vi51.framework.environment.Influence[])
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(PhysicEnvironment.class)
protected void influenceSteering(final Vector2f linearInfluence, final Influence... otherInfluences) {
getSkill(fr.utbm.info.vi51.framework.agent.PhysicEnvironment.class).influenceSteering(linearInfluence, otherInfluences);
}
/**
* See the capacity {@link fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceSteering(fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence[])}.
*
* @see fr.utbm.info.vi51.framework.agent.PhysicEnvironment#influenceSteering(fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence[])
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(PhysicEnvironment.class)
protected void influenceSteering(final Vector2f linearInfluence, final float angularInfluence, final Influence... otherInfluences) {
getSkill(fr.utbm.info.vi51.framework.agent.PhysicEnvironment.class).influenceSteering(linearInfluence, angularInfluence, otherInfluences);
}
/**
* See the capacity {@link io.sarl.core.Lifecycle#killMe()}.
*
* @see io.sarl.core.Lifecycle#killMe()
*/
@EarlyExit
@FiredEvent({ AgentKilled.class, Destroy.class })
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Lifecycle.class)
protected void killMe() {
getSkill(io.sarl.core.Lifecycle.class).killMe();
}
/**
* See the capacity {@link io.sarl.core.Lifecycle#spawnInContext(java.lang.Class<? extends io.sarl.lang.core.Agent>,io.sarl.lang.core.AgentContext,java.lang.Object[])}.
*
* @see io.sarl.core.Lifecycle#spawnInContext(java.lang.Class<? extends io.sarl.lang.core.Agent>,io.sarl.lang.core.AgentContext,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Lifecycle.class)
protected UUID spawnInContext(final Class<? extends Agent> arg0, final AgentContext arg1, final Object... arg2) {
return getSkill(io.sarl.core.Lifecycle.class).spawnInContext(arg0, arg1, arg2);
}
/**
* See the capacity {@link io.sarl.core.Lifecycle#spawnInContextWithID(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.util.UUID,io.sarl.lang.core.AgentContext,java.lang.Object[])}.
*
* @see io.sarl.core.Lifecycle#spawnInContextWithID(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.util.UUID,io.sarl.lang.core.AgentContext,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Lifecycle.class)
protected UUID spawnInContextWithID(final Class<? extends Agent> arg0, final UUID arg1, final AgentContext arg2, final Object... arg3) {
return getSkill(io.sarl.core.Lifecycle.class).spawnInContextWithID(arg0, arg1, arg2, arg3);
}
/**
* Construct an agent.
* @param builtinCapacityProvider - provider of the built-in capacities.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
* @param agentID - identifier of the agent. If <code>null</code> the agent identifier will be computed randomly.
*/
@Inject
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public AbstractAnimat(final BuiltinCapacitiesProvider builtinCapacityProvider, final UUID parentID, final UUID agentID) {
super(builtinCapacityProvider, parentID, agentID);
}
}

View file

@ -0,0 +1,147 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.agent;
import fr.utbm.info.vi51.framework.environment.Influence;
import fr.utbm.info.vi51.framework.math.Vector2f;
import io.sarl.lang.annotation.DefaultValue;
import io.sarl.lang.annotation.DefaultValueSource;
import io.sarl.lang.annotation.DefaultValueUse;
import io.sarl.lang.annotation.SarlSourceCode;
import io.sarl.lang.core.Capacity;
import javax.annotation.Generated;
@SuppressWarnings("all")
public interface PhysicEnvironment extends Capacity {
/**
* Invoked to send the influence to the environment.
*
* @param linearInfluence is the linear influence to apply on the object.
* @param angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
@DefaultValueSource
public abstract void influenceKinematic(@DefaultValue("fr.utbm.info.vi51.framework.agent.PhysicEnvironment#INFLUENCEKINEMATIC_0") final Vector2f linearInfluence, @DefaultValue("fr.utbm.info.vi51.framework.agent.PhysicEnvironment#INFLUENCEKINEMATIC_1") final float angularInfluence, final Influence... otherInfluences);
/**
* Default value for the parameter linearInfluence
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@SarlSourceCode(" null")
public final static Vector2f ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCEKINEMATIC_0 = null;
/**
* Default value for the parameter angularInfluence
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@SarlSourceCode(" 0f")
public final static float ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCEKINEMATIC_1 = 0f;
/**
* Invoked to send the influence to the environment.
*
* @param linearInfluence is the linear influence to apply on the object.
* @param angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
@DefaultValueSource
public abstract void influenceSteering(@DefaultValue("fr.utbm.info.vi51.framework.agent.PhysicEnvironment#INFLUENCESTEERING_0") final Vector2f linearInfluence, @DefaultValue("fr.utbm.info.vi51.framework.agent.PhysicEnvironment#INFLUENCESTEERING_1") final float angularInfluence, final Influence... otherInfluences);
/**
* Default value for the parameter linearInfluence
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@SarlSourceCode(" null")
public final static Vector2f ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCESTEERING_0 = null;
/**
* Default value for the parameter angularInfluence
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@SarlSourceCode(" 0f")
public final static float ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCESTEERING_1 = 0f;
/**
* Invoked to send the influence to the environment.
*
* @optionalparam linearInfluence is the linear influence to apply on the object.
* @optionalparam angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public abstract void influenceKinematic(final Influence... otherInfluences);
/**
* Invoked to send the influence to the environment.
*
* @optionalparam linearInfluence is the linear influence to apply on the object.
* @param angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public abstract void influenceKinematic(final float angularInfluence, final Influence... otherInfluences);
/**
* Invoked to send the influence to the environment.
*
* @param linearInfluence is the linear influence to apply on the object.
* @optionalparam angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public abstract void influenceKinematic(final Vector2f linearInfluence, final Influence... otherInfluences);
/**
* Invoked to send the influence to the environment.
*
* @optionalparam linearInfluence is the linear influence to apply on the object.
* @optionalparam angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public abstract void influenceSteering(final Influence... otherInfluences);
/**
* Invoked to send the influence to the environment.
*
* @optionalparam linearInfluence is the linear influence to apply on the object.
* @param angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public abstract void influenceSteering(final float angularInfluence, final Influence... otherInfluences);
/**
* Invoked to send the influence to the environment.
*
* @param linearInfluence is the linear influence to apply on the object.
* @optionalparam angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public abstract void influenceSteering(final Vector2f linearInfluence, final Influence... otherInfluences);
}

View file

@ -0,0 +1,410 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.agent;
import fr.utbm.info.vi51.framework.agent.PhysicEnvironment;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.environment.Influence;
import fr.utbm.info.vi51.framework.environment.InfluenceEvent;
import fr.utbm.info.vi51.framework.environment.KillInfluence;
import fr.utbm.info.vi51.framework.environment.MotionInfluence;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.framework.util.AddressUUIDScope;
import io.sarl.core.AgentSpawned;
import io.sarl.core.Behaviors;
import io.sarl.core.DefaultContextInteractions;
import io.sarl.lang.annotation.DefaultValue;
import io.sarl.lang.annotation.DefaultValueSource;
import io.sarl.lang.annotation.DefaultValueUse;
import io.sarl.lang.annotation.FiredEvent;
import io.sarl.lang.annotation.ImportedCapacityFeature;
import io.sarl.lang.annotation.SarlSourceCode;
import io.sarl.lang.core.Address;
import io.sarl.lang.core.Agent;
import io.sarl.lang.core.AgentContext;
import io.sarl.lang.core.Behavior;
import io.sarl.lang.core.Event;
import io.sarl.lang.core.EventListener;
import io.sarl.lang.core.EventSpace;
import io.sarl.lang.core.Scope;
import io.sarl.lang.core.Skill;
import io.sarl.lang.core.Space;
import io.sarl.lang.core.SpaceID;
import io.sarl.util.OpenEventSpace;
import java.lang.reflect.Array;
import java.util.List;
import java.util.UUID;
import javax.annotation.Generated;
import org.eclipse.xtext.xbase.lib.Conversions;
@SuppressWarnings("all")
public class StandardPhysicEnvironment extends Skill implements PhysicEnvironment {
protected final UUID spaceID;
protected final UUID environmentID;
protected OpenEventSpace physicSpace;
protected Address myAdr;
public StandardPhysicEnvironment(final UUID spaceID, final UUID environmentID) {
this.environmentID = environmentID;
this.spaceID = spaceID;
}
@Override
public void install() {
do {
{
AgentContext _defaultContext = this.getDefaultContext();
OpenEventSpace _space = _defaultContext.<OpenEventSpace>getSpace(this.spaceID);
this.physicSpace = _space;
Thread.yield();
}
} while((this.physicSpace == null));
EventListener _asEventListener = this.asEventListener();
this.physicSpace.register(_asEventListener);
Agent _owner = this.getOwner();
UUID _iD = _owner.getID();
Address _address = this.physicSpace.getAddress(_iD);
this.myAdr = _address;
}
@Override
public void uninstall() {
KillInfluence _killInfluence = new KillInfluence();
InfluenceEvent event = new InfluenceEvent(_killInfluence);
event.setSource(this.myAdr);
AddressUUIDScope _addressUUIDScope = new AddressUUIDScope(this.environmentID);
this.physicSpace.emit(event, _addressUUIDScope);
this.physicSpace = null;
}
@DefaultValueSource
@Override
public void influenceKinematic(@DefaultValue("fr.utbm.info.vi51.framework.agent.StandardPhysicEnvironment#INFLUENCEKINEMATIC_0") final Vector2f linearInfluence, @DefaultValue("fr.utbm.info.vi51.framework.agent.StandardPhysicEnvironment#INFLUENCEKINEMATIC_1") final float angularInfluence, final Influence... otherInfluences) {
MotionInfluence mi = null;
boolean _tripleEquals = linearInfluence.operator_tripleEquals(null);
if (_tripleEquals) {
MotionInfluence _motionInfluence = new MotionInfluence(DynamicType.KINEMATIC, angularInfluence);
mi = _motionInfluence;
} else {
MotionInfluence _motionInfluence_1 = new MotionInfluence(DynamicType.KINEMATIC, linearInfluence, angularInfluence);
mi = _motionInfluence_1;
}
this.emitInfluences(mi, otherInfluences);
}
/**
* Default value for the parameter linearInfluence
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@SarlSourceCode(" null")
private final static Vector2f ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCEKINEMATIC_0 = null;
/**
* Default value for the parameter angularInfluence
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@SarlSourceCode(" 0f")
private final static float ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCEKINEMATIC_1 = 0f;
@DefaultValueSource
@Override
public void influenceSteering(@DefaultValue("fr.utbm.info.vi51.framework.agent.StandardPhysicEnvironment#INFLUENCESTEERING_0") final Vector2f linearInfluence, @DefaultValue("fr.utbm.info.vi51.framework.agent.StandardPhysicEnvironment#INFLUENCESTEERING_1") final float angularInfluence, final Influence... otherInfluences) {
MotionInfluence mi = null;
boolean _tripleEquals = linearInfluence.operator_tripleEquals(null);
if (_tripleEquals) {
MotionInfluence _motionInfluence = new MotionInfluence(DynamicType.STEERING, angularInfluence);
mi = _motionInfluence;
} else {
MotionInfluence _motionInfluence_1 = new MotionInfluence(DynamicType.STEERING, linearInfluence, angularInfluence);
mi = _motionInfluence_1;
}
this.emitInfluences(mi, otherInfluences);
}
/**
* Default value for the parameter linearInfluence
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@SarlSourceCode(" null")
private final static Vector2f ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCESTEERING_0 = null;
/**
* Default value for the parameter angularInfluence
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@SarlSourceCode(" 0f")
private final static float ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCESTEERING_1 = 0f;
public void emitInfluences(final MotionInfluence motionInfluence, final Influence... otherInfluences) {
Influence[] influences = null;
boolean _isEmpty = ((List<Influence>)Conversions.doWrapArray(otherInfluences)).isEmpty();
if (_isEmpty) {
Object _newInstance = Array.newInstance(Influence.class, 1);
influences = ((Influence[]) _newInstance);
influences[0] = motionInfluence;
} else {
int _length = otherInfluences.length;
int _plus = (_length + 1);
Object _newInstance_1 = Array.newInstance(Influence.class, _plus);
influences = ((Influence[]) _newInstance_1);
influences[0] = motionInfluence;
int _length_1 = otherInfluences.length;
System.arraycopy(otherInfluences, 0, influences, 1, _length_1);
}
InfluenceEvent event = new InfluenceEvent(influences);
event.setSource(this.myAdr);
AddressUUIDScope _addressUUIDScope = new AddressUUIDScope(this.environmentID);
this.physicSpace.emit(event, _addressUUIDScope);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void emit(final Event arg0) {
getSkill(io.sarl.core.DefaultContextInteractions.class).emit(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event,io.sarl.lang.core.Scope<io.sarl.lang.core.Address>)}.
*
* @see io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event,io.sarl.lang.core.Scope<io.sarl.lang.core.Address>)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void emit(final Event arg0, final Scope<Address> arg1) {
getSkill(io.sarl.core.DefaultContextInteractions.class).emit(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultAddress()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultAddress()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected Address getDefaultAddress() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultAddress();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultContext()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultContext()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected AgentContext getDefaultContext() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultContext();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultSpace()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultSpace()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected EventSpace getDefaultSpace() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultSpace();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultContext(io.sarl.lang.core.AgentContext)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultContext(io.sarl.lang.core.AgentContext)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultContext(final AgentContext arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultContext(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultContext(java.util.UUID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultContext(java.util.UUID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultContext(final UUID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultContext(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.Space)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.Space)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final Space arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.SpaceID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.SpaceID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final SpaceID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(java.util.UUID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(java.util.UUID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final UUID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isInDefaultSpace(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#isInDefaultSpace(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isInDefaultSpace(final Event arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isInDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#receive(java.util.UUID,io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#receive(java.util.UUID,io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void receive(final UUID arg0, final Event arg1) {
getSkill(io.sarl.core.DefaultContextInteractions.class).receive(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#spawn(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.lang.Object[])}.
*
* @see io.sarl.core.DefaultContextInteractions#spawn(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected UUID spawn(final Class<? extends Agent> arg0, final Object... arg1) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).spawn(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.Behaviors#asEventListener()}.
*
* @see io.sarl.core.Behaviors#asEventListener()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Behaviors.class)
protected EventListener asEventListener() {
return getSkill(io.sarl.core.Behaviors.class).asEventListener();
}
/**
* See the capacity {@link io.sarl.core.Behaviors#registerBehavior(io.sarl.lang.core.Behavior)}.
*
* @see io.sarl.core.Behaviors#registerBehavior(io.sarl.lang.core.Behavior)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Behaviors.class)
protected Behavior registerBehavior(final Behavior arg0) {
return getSkill(io.sarl.core.Behaviors.class).registerBehavior(arg0);
}
/**
* See the capacity {@link io.sarl.core.Behaviors#unregisterBehavior(io.sarl.lang.core.Behavior)}.
*
* @see io.sarl.core.Behaviors#unregisterBehavior(io.sarl.lang.core.Behavior)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Behaviors.class)
protected Behavior unregisterBehavior(final Behavior arg0) {
return getSkill(io.sarl.core.Behaviors.class).unregisterBehavior(arg0);
}
/**
* See the capacity {@link io.sarl.core.Behaviors#wake(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.Behaviors#wake(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Behaviors.class)
protected void wake(final Event arg0) {
getSkill(io.sarl.core.Behaviors.class).wake(arg0);
}
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Override
public final void influenceKinematic(final Influence... otherInfluences) {
influenceKinematic(___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCEKINEMATIC_0, ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCEKINEMATIC_1, otherInfluences);
}
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Override
public final void influenceKinematic(final float angularInfluence, final Influence... otherInfluences) {
influenceKinematic(___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCEKINEMATIC_0, angularInfluence, otherInfluences);
}
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Override
public final void influenceKinematic(final Vector2f linearInfluence, final Influence... otherInfluences) {
influenceKinematic(linearInfluence, ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCEKINEMATIC_1, otherInfluences);
}
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Override
public final void influenceSteering(final Influence... otherInfluences) {
influenceSteering(___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCESTEERING_0, ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCESTEERING_1, otherInfluences);
}
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Override
public final void influenceSteering(final float angularInfluence, final Influence... otherInfluences) {
influenceSteering(___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCESTEERING_0, angularInfluence, otherInfluences);
}
@DefaultValueUse("fr.utbm.info.vi51.framework.math.Vector2f,float,fr.utbm.info.vi51.framework.environment.Influence*")
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Override
public final void influenceSteering(final Vector2f linearInfluence, final Influence... otherInfluences) {
influenceSteering(linearInfluence, ___FORMAL_PARAMETER_DEFAULT_VALUE_INFLUENCESTEERING_1, otherInfluences);
}
}

View file

@ -0,0 +1,428 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.environment;
import fr.utbm.info.vi51.framework.environment.AgentBody;
import fr.utbm.info.vi51.framework.environment.Environment;
import fr.utbm.info.vi51.framework.environment.Influence;
import fr.utbm.info.vi51.framework.environment.InfluenceEvent;
import fr.utbm.info.vi51.framework.environment.PerceptionEvent;
import fr.utbm.info.vi51.framework.environment.SimulationAgentReady;
import fr.utbm.info.vi51.framework.environment.StartSimulation;
import fr.utbm.info.vi51.framework.environment.StopSimulation;
import fr.utbm.info.vi51.framework.time.TimeManager;
import fr.utbm.info.vi51.framework.time.TimePercept;
import fr.utbm.info.vi51.framework.util.AddressUUIDScope;
import io.sarl.core.AgentKilled;
import io.sarl.core.AgentSpawned;
import io.sarl.core.Behaviors;
import io.sarl.core.DefaultContextInteractions;
import io.sarl.core.Destroy;
import io.sarl.core.Initialize;
import io.sarl.core.Lifecycle;
import io.sarl.lang.annotation.EarlyExit;
import io.sarl.lang.annotation.FiredEvent;
import io.sarl.lang.annotation.ImportedCapacityFeature;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.Address;
import io.sarl.lang.core.Agent;
import io.sarl.lang.core.AgentContext;
import io.sarl.lang.core.Behavior;
import io.sarl.lang.core.BuiltinCapacitiesProvider;
import io.sarl.lang.core.Event;
import io.sarl.lang.core.EventListener;
import io.sarl.lang.core.EventSpace;
import io.sarl.lang.core.Percept;
import io.sarl.lang.core.Scope;
import io.sarl.lang.core.Space;
import io.sarl.lang.core.SpaceID;
import io.sarl.util.OpenEventSpace;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Generated;
import javax.inject.Inject;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Pure;
/**
* This agent is managing the physic space.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
*/
@SarlSpecification("0.3")
@SuppressWarnings("all")
public class EnvironmentAgent extends Agent {
protected Environment environment;
protected OpenEventSpace space;
protected Address myAdr;
protected int influences = 0;
protected final AtomicBoolean freeze = new AtomicBoolean(false);
@Percept
public void _handle_Initialize_0(final Initialize occurrence) {
Object _get = occurrence.parameters[0];
this.environment = ((Environment) _get);
Object _get_1 = occurrence.parameters[1];
UUID spaceId = ((UUID) _get_1);
AgentContext _defaultContext = this.getDefaultContext();
OpenEventSpace _space = _defaultContext.<OpenEventSpace>getSpace(spaceId);
this.space = _space;
EventListener _asEventListener = this.asEventListener();
this.space.register(_asEventListener);
UUID _iD = this.getID();
Address _address = this.space.getAddress(_iD);
this.myAdr = _address;
SimulationAgentReady _simulationAgentReady = new SimulationAgentReady();
this.emit(_simulationAgentReady);
}
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Pure
private boolean _eventhandler_guard_InfluenceEvent_1(final InfluenceEvent it, final InfluenceEvent occurrence) {
boolean _get = this.freeze.get();
boolean _not = (!_get);
return _not;
}
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
private void _eventhandler_body_InfluenceEvent_1(final InfluenceEvent occurrence) {
for (final Influence influence : occurrence.influences) {
{
UUID id = influence.getEmitter();
if ((id == null)) {
Address _source = occurrence.getSource();
UUID _uUID = _source.getUUID();
id = _uUID;
}
AgentBody body = this.environment.getAgentBodyFor(id);
body.influence(influence);
}
}
this.influences++;
int _agentBodyNumber = this.environment.getAgentBodyNumber();
boolean _greaterEqualsThan = (this.influences >= _agentBodyNumber);
if (_greaterEqualsThan) {
this.runEnvironmentBehavior();
}
}
@Percept
public void _handle_InfluenceEvent_1(final InfluenceEvent occurrence) {
if (_eventhandler_guard_InfluenceEvent_1(occurrence, occurrence)) {
_eventhandler_body_InfluenceEvent_1(occurrence);
}
}
@Percept
public void _handle_StopSimulation_2(final StopSimulation occurrence) {
this.killMe();
}
@Percept
public void _handle_StartSimulation_3(final StartSimulation occurrence) {
this.runEnvironmentBehavior();
}
protected void runEnvironmentBehavior() {
try {
this.freeze.set(true);
this.influences = 0;
this.environment.runBehaviour();
TimeManager _timeManager = this.environment.getTimeManager();
float _simulationDelay = _timeManager.getSimulationDelay();
long delay = ((long) _simulationDelay);
if ((delay > 0)) {
Thread.sleep(delay);
}
this.freeze.set(false);
this.notifyAgentsOrDie();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
protected void notifyAgentsOrDie() {
boolean run = false;
TimeManager _timeManager = this.environment.getTimeManager();
float _currentTime = _timeManager.getCurrentTime();
TimeManager _timeManager_1 = this.environment.getTimeManager();
float _lastStepDuration = _timeManager_1.getLastStepDuration();
final TimePercept timePercept = new TimePercept(_currentTime, _lastStepDuration);
Iterable<? extends AgentBody> _agentBodies = this.environment.getAgentBodies();
for (final AgentBody body : _agentBodies) {
{
run = true;
List<fr.utbm.info.vi51.framework.environment.Percept> _perceivedObjects = body.getPerceivedObjects();
fr.utbm.info.vi51.framework.environment.Percept _percept = new fr.utbm.info.vi51.framework.environment.Percept(body);
PerceptionEvent event = new PerceptionEvent(_perceivedObjects, _percept, timePercept);
event.setSource(this.myAdr);
UUID _iD = body.getID();
AddressUUIDScope _addressUUIDScope = new AddressUUIDScope(_iD);
this.space.emit(event, _addressUUIDScope);
}
}
if ((!run)) {
this.killMe();
}
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void emit(final Event arg0) {
getSkill(io.sarl.core.DefaultContextInteractions.class).emit(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event,io.sarl.lang.core.Scope<io.sarl.lang.core.Address>)}.
*
* @see io.sarl.core.DefaultContextInteractions#emit(io.sarl.lang.core.Event,io.sarl.lang.core.Scope<io.sarl.lang.core.Address>)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void emit(final Event arg0, final Scope<Address> arg1) {
getSkill(io.sarl.core.DefaultContextInteractions.class).emit(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultAddress()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultAddress()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected Address getDefaultAddress() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultAddress();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultContext()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultContext()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected AgentContext getDefaultContext() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultContext();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#getDefaultSpace()}.
*
* @see io.sarl.core.DefaultContextInteractions#getDefaultSpace()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected EventSpace getDefaultSpace() {
return getSkill(io.sarl.core.DefaultContextInteractions.class).getDefaultSpace();
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultContext(io.sarl.lang.core.AgentContext)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultContext(io.sarl.lang.core.AgentContext)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultContext(final AgentContext arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultContext(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultContext(java.util.UUID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultContext(java.util.UUID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultContext(final UUID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultContext(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.Space)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.Space)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final Space arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.SpaceID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(io.sarl.lang.core.SpaceID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final SpaceID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isDefaultSpace(java.util.UUID)}.
*
* @see io.sarl.core.DefaultContextInteractions#isDefaultSpace(java.util.UUID)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isDefaultSpace(final UUID arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#isInDefaultSpace(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#isInDefaultSpace(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected boolean isInDefaultSpace(final Event arg0) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).isInDefaultSpace(arg0);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#receive(java.util.UUID,io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.DefaultContextInteractions#receive(java.util.UUID,io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected void receive(final UUID arg0, final Event arg1) {
getSkill(io.sarl.core.DefaultContextInteractions.class).receive(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.DefaultContextInteractions#spawn(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.lang.Object[])}.
*
* @see io.sarl.core.DefaultContextInteractions#spawn(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(DefaultContextInteractions.class)
protected UUID spawn(final Class<? extends Agent> arg0, final Object... arg1) {
return getSkill(io.sarl.core.DefaultContextInteractions.class).spawn(arg0, arg1);
}
/**
* See the capacity {@link io.sarl.core.Lifecycle#killMe()}.
*
* @see io.sarl.core.Lifecycle#killMe()
*/
@EarlyExit
@FiredEvent({ AgentKilled.class, Destroy.class })
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Lifecycle.class)
protected void killMe() {
getSkill(io.sarl.core.Lifecycle.class).killMe();
}
/**
* See the capacity {@link io.sarl.core.Lifecycle#spawnInContext(java.lang.Class<? extends io.sarl.lang.core.Agent>,io.sarl.lang.core.AgentContext,java.lang.Object[])}.
*
* @see io.sarl.core.Lifecycle#spawnInContext(java.lang.Class<? extends io.sarl.lang.core.Agent>,io.sarl.lang.core.AgentContext,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Lifecycle.class)
protected UUID spawnInContext(final Class<? extends Agent> arg0, final AgentContext arg1, final Object... arg2) {
return getSkill(io.sarl.core.Lifecycle.class).spawnInContext(arg0, arg1, arg2);
}
/**
* See the capacity {@link io.sarl.core.Lifecycle#spawnInContextWithID(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.util.UUID,io.sarl.lang.core.AgentContext,java.lang.Object[])}.
*
* @see io.sarl.core.Lifecycle#spawnInContextWithID(java.lang.Class<? extends io.sarl.lang.core.Agent>,java.util.UUID,io.sarl.lang.core.AgentContext,java.lang.Object[])
*/
@FiredEvent(AgentSpawned.class)
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Lifecycle.class)
protected UUID spawnInContextWithID(final Class<? extends Agent> arg0, final UUID arg1, final AgentContext arg2, final Object... arg3) {
return getSkill(io.sarl.core.Lifecycle.class).spawnInContextWithID(arg0, arg1, arg2, arg3);
}
/**
* See the capacity {@link io.sarl.core.Behaviors#asEventListener()}.
*
* @see io.sarl.core.Behaviors#asEventListener()
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Behaviors.class)
protected EventListener asEventListener() {
return getSkill(io.sarl.core.Behaviors.class).asEventListener();
}
/**
* See the capacity {@link io.sarl.core.Behaviors#registerBehavior(io.sarl.lang.core.Behavior)}.
*
* @see io.sarl.core.Behaviors#registerBehavior(io.sarl.lang.core.Behavior)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Behaviors.class)
protected Behavior registerBehavior(final Behavior arg0) {
return getSkill(io.sarl.core.Behaviors.class).registerBehavior(arg0);
}
/**
* See the capacity {@link io.sarl.core.Behaviors#unregisterBehavior(io.sarl.lang.core.Behavior)}.
*
* @see io.sarl.core.Behaviors#unregisterBehavior(io.sarl.lang.core.Behavior)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Behaviors.class)
protected Behavior unregisterBehavior(final Behavior arg0) {
return getSkill(io.sarl.core.Behaviors.class).unregisterBehavior(arg0);
}
/**
* See the capacity {@link io.sarl.core.Behaviors#wake(io.sarl.lang.core.Event)}.
*
* @see io.sarl.core.Behaviors#wake(io.sarl.lang.core.Event)
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@ImportedCapacityFeature(Behaviors.class)
protected void wake(final Event arg0) {
getSkill(io.sarl.core.Behaviors.class).wake(arg0);
}
/**
* Construct an agent.
* @param builtinCapacityProvider - provider of the built-in capacities.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
* @param agentID - identifier of the agent. If <code>null</code> the agent identifier will be computed randomly.
*/
@Inject
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public EnvironmentAgent(final BuiltinCapacitiesProvider builtinCapacityProvider, final UUID parentID, final UUID agentID) {
super(builtinCapacityProvider, parentID, agentID);
}
}

View file

@ -0,0 +1,87 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.environment;
import fr.utbm.info.vi51.framework.environment.Influence;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.Event;
import java.util.List;
import javax.annotation.Generated;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Pure;
/**
* This event contains an influence
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
*/
@SarlSpecification("0.3")
@SuppressWarnings("all")
public class InfluenceEvent extends Event {
public final List<Influence> influences;
public InfluenceEvent(final Influence... e) {
this.influences = ((List<Influence>)Conversions.doWrapArray(e));
}
@Override
@Pure
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
InfluenceEvent other = (InfluenceEvent) obj;
if (this.influences == null) {
if (other.influences != null)
return false;
} else if (!this.influences.equals(other.influences))
return false;
return super.equals(obj);
}
@Override
@Pure
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.influences== null) ? 0 : this.influences.hashCode());
return result;
}
/**
* Returns a String representation of the InfluenceEvent event's attributes only.
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Pure
protected String attributesToString() {
StringBuilder result = new StringBuilder(super.attributesToString());
result.append("influences = ").append(this.influences);
return result.toString();
}
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
private final static long serialVersionUID = 5240104421L;
}

View file

@ -0,0 +1,107 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.environment;
import fr.utbm.info.vi51.framework.environment.Percept;
import fr.utbm.info.vi51.framework.time.TimePercept;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.Event;
import java.util.List;
import javax.annotation.Generated;
import org.eclipse.xtext.xbase.lib.Pure;
/**
* This event contains percepts.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
*/
@SarlSpecification("0.3")
@SuppressWarnings("all")
public class PerceptionEvent extends Event {
public final Percept body;
public final TimePercept time;
public final List<Percept> perceptions;
public PerceptionEvent(final List<Percept> p, final Percept b, final TimePercept t) {
this.perceptions = p;
this.body = b;
this.time = t;
}
@Override
@Pure
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PerceptionEvent other = (PerceptionEvent) obj;
if (this.body == null) {
if (other.body != null)
return false;
} else if (!this.body.equals(other.body))
return false;
if (this.time == null) {
if (other.time != null)
return false;
} else if (!this.time.equals(other.time))
return false;
if (this.perceptions == null) {
if (other.perceptions != null)
return false;
} else if (!this.perceptions.equals(other.perceptions))
return false;
return super.equals(obj);
}
@Override
@Pure
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.body== null) ? 0 : this.body.hashCode());
result = prime * result + ((this.time== null) ? 0 : this.time.hashCode());
result = prime * result + ((this.perceptions== null) ? 0 : this.perceptions.hashCode());
return result;
}
/**
* Returns a String representation of the PerceptionEvent event's attributes only.
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
@Pure
protected String attributesToString() {
StringBuilder result = new StringBuilder(super.attributesToString());
result.append("body = ").append(this.body);
result.append("time = ").append(this.time);
result.append("perceptions = ").append(this.perceptions);
return result.toString();
}
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
private final static long serialVersionUID = 2892685776L;
}

View file

@ -0,0 +1,55 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.environment;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.Address;
import io.sarl.lang.core.Event;
import javax.annotation.Generated;
/**
* This event is fired when a simulation agent is ready.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
*/
@SarlSpecification("0.3")
@SuppressWarnings("all")
public class SimulationAgentReady extends Event {
/**
* Construct an event. The source of the event is unknown.
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public SimulationAgentReady() {
super();
}
/**
* Construct an event.
* @param source - address of the agent that is emitting this event.
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public SimulationAgentReady(final Address source) {
super(source);
}
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
private final static long serialVersionUID = 588368462L;
}

View file

@ -0,0 +1,55 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.environment;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.Address;
import io.sarl.lang.core.Event;
import javax.annotation.Generated;
/**
* This event is for starting the simulation.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
*/
@SarlSpecification("0.3")
@SuppressWarnings("all")
public class StartSimulation extends Event {
/**
* Construct an event. The source of the event is unknown.
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public StartSimulation() {
super();
}
/**
* Construct an event.
* @param source - address of the agent that is emitting this event.
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public StartSimulation(final Address source) {
super(source);
}
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
private final static long serialVersionUID = 588368462L;
}

View file

@ -0,0 +1,55 @@
/**
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.environment;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.Address;
import io.sarl.lang.core.Event;
import javax.annotation.Generated;
/**
* This event is for stopping the simulation.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
*/
@SarlSpecification("0.3")
@SuppressWarnings("all")
public class StopSimulation extends Event {
/**
* Construct an event. The source of the event is unknown.
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public StopSimulation() {
super();
}
/**
* Construct an event.
* @param source - address of the agent that is emitting this event.
*/
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
public StopSimulation(final Address source) {
super(source);
}
@Generated("io.sarl.lang.jvmmodel.SARLJvmModelInferrer")
private final static long serialVersionUID = 588368462L;
}

View file

@ -0,0 +1,23 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.math.MathUtil;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.AlignBehaviour;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class KinematicAlignBehaviour implements AlignBehaviour {
@Override
public BehaviourOutput runAlign(final Vector2f orientation, final float angularSpeed, final float maxAngularSpeed, final Vector2f target) {
final float angle = orientation.signedAngle(target);
BehaviourOutput _behaviourOutput = new BehaviourOutput(DynamicType.KINEMATIC);
final Procedure1<BehaviourOutput> _function = (BehaviourOutput it) -> {
float _clamp = MathUtil.clamp(angle, (-maxAngularSpeed), maxAngularSpeed);
it.setAngular(_clamp);
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput, _function);
}
}

View file

@ -0,0 +1,26 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.EvadeBehaviour;
import fr.utbm.info.vi51.motionbehavior.KinematicFleeBehaviour;
@SuppressWarnings("all")
public class KinematicEvadeBehaviour implements EvadeBehaviour {
private final KinematicFleeBehaviour flee;
private final float predictionDuration;
public KinematicEvadeBehaviour(final KinematicFleeBehaviour flee, final float predictionDuration) {
this.flee = flee;
this.predictionDuration = predictionDuration;
}
@Override
public BehaviourOutput runEvade(final Point2f position, final float linearSpeed, final float maxLinearSpeed, final Point2f targetPosition, final Vector2f targetLinearMotion) {
Vector2f _multiply = targetLinearMotion.operator_multiply(this.predictionDuration);
Point2f fleeTarget = targetPosition.operator_plus(_multiply);
return this.flee.runFlee(position, linearSpeed, maxLinearSpeed, fleeTarget);
}
}

View file

@ -0,0 +1,22 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.FaceBehaviour;
import fr.utbm.info.vi51.motionbehavior.KinematicAlignBehaviour;
@SuppressWarnings("all")
public class KinematicFaceBehaviour implements FaceBehaviour {
private final KinematicAlignBehaviour align;
public KinematicFaceBehaviour(final KinematicAlignBehaviour align) {
this.align = align;
}
@Override
public BehaviourOutput runFace(final Point2f position, final Vector2f orientation, final float angularSpeed, final float maxAngularSpeed, final Point2f target) {
Vector2f alignTarget = target.operator_minus(position);
return this.align.runAlign(orientation, angularSpeed, maxAngularSpeed, alignTarget);
}
}

View file

@ -0,0 +1,23 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.FleeBehaviour;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class KinematicFleeBehaviour implements FleeBehaviour {
@Override
public BehaviourOutput runFlee(final Point2f position, final float linearSpeed, final float maxLinearSpeed, final Point2f target) {
final Vector2f direction = position.operator_minus(target);
direction.setLength(maxLinearSpeed);
BehaviourOutput _behaviourOutput = new BehaviourOutput(DynamicType.KINEMATIC);
final Procedure1<BehaviourOutput> _function = (BehaviourOutput it) -> {
it.setLinear(direction);
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput, _function);
}
}

View file

@ -0,0 +1,26 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.KinematicSeekBehaviour;
import fr.utbm.info.vi51.motionbehavior.PursueBehaviour;
@SuppressWarnings("all")
public class KinematicPursueBehaviour implements PursueBehaviour {
private final KinematicSeekBehaviour seek;
private final float predictionDuration;
public KinematicPursueBehaviour(final KinematicSeekBehaviour seek, final float predictionDuration) {
this.seek = seek;
this.predictionDuration = predictionDuration;
}
@Override
public BehaviourOutput runPursue(final Point2f position, final float linearSpeed, final float maxLinearSpeed, final Point2f targetPosition, final Vector2f targetLinearMotion) {
Vector2f _multiply = targetLinearMotion.operator_multiply(this.predictionDuration);
Point2f seekTarget = targetPosition.operator_plus(_multiply);
return this.seek.runSeek(position, linearSpeed, maxLinearSpeed, seekTarget);
}
}

View file

@ -0,0 +1,23 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.SeekBehaviour;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class KinematicSeekBehaviour implements SeekBehaviour {
@Override
public BehaviourOutput runSeek(final Point2f position, final float linearSpeed, final float maxLinearSpeed, final Point2f target) {
final Vector2f direction = target.operator_minus(position);
direction.setLength(maxLinearSpeed);
BehaviourOutput _behaviourOutput = new BehaviourOutput(DynamicType.KINEMATIC);
final Procedure1<BehaviourOutput> _function = (BehaviourOutput it) -> {
it.setLinear(direction);
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput, _function);
}
}

View file

@ -0,0 +1,28 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.WanderBehaviour;
import java.util.Random;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class KinematicWanderBehaviour implements WanderBehaviour {
private final Random random = new Random();
@Override
public BehaviourOutput runWander(final Point2f position, final Vector2f orientation, final float linearSpeed, final float maxLinearSpeed, final float angularSpeed, final float maxAngularSpeed) {
final Vector2f v = orientation.toColinearVector(maxLinearSpeed);
double _nextGaussian = this.random.nextGaussian();
final double rotation = (_nextGaussian * maxAngularSpeed);
BehaviourOutput _behaviourOutput = new BehaviourOutput(DynamicType.KINEMATIC);
final Procedure1<BehaviourOutput> _function = (BehaviourOutput it) -> {
it.setLinear(v);
it.setAngular(((float) rotation));
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput, _function);
}
}

View file

@ -0,0 +1,52 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.AlignBehaviour;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class SteeringAlignBehaviour implements AlignBehaviour {
private final float stopAngle;
private final float decelerateAngle;
private final float timeToReachTarget;
public SteeringAlignBehaviour(final float stopAngle, final float decelerateAngle, final float timeToReachTarget) {
this.stopAngle = stopAngle;
this.decelerateAngle = decelerateAngle;
this.timeToReachTarget = timeToReachTarget;
}
@Override
public BehaviourOutput runAlign(final Vector2f orientation, final float angularSpeed, final float maxAngularAcceleration, final Vector2f target) {
final float sAngle = orientation.signedAngle(target);
final float angle = Math.abs(sAngle);
if ((angle <= this.stopAngle)) {
BehaviourOutput _behaviourOutput = new BehaviourOutput(DynamicType.STEERING);
final Procedure1<BehaviourOutput> _function = (BehaviourOutput it) -> {
it.setAngular(((-angularSpeed) / 1));
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput, _function);
}
if ((angle > this.decelerateAngle)) {
BehaviourOutput _behaviourOutput_1 = new BehaviourOutput(DynamicType.STEERING);
final Procedure1<BehaviourOutput> _function_1 = (BehaviourOutput it) -> {
float _signum = Math.signum(sAngle);
float _multiply = (_signum * maxAngularAcceleration);
it.setAngular(_multiply);
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput_1, _function_1);
}
BehaviourOutput _behaviourOutput_2 = new BehaviourOutput(DynamicType.STEERING);
final Procedure1<BehaviourOutput> _function_2 = (BehaviourOutput it) -> {
double _power = Math.pow(this.timeToReachTarget, 2);
double _divide = (sAngle / _power);
it.setAngular(((float) _divide));
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput_2, _function_2);
}
}

View file

@ -0,0 +1,26 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.EvadeBehaviour;
import fr.utbm.info.vi51.motionbehavior.SteeringFleeBehaviour;
@SuppressWarnings("all")
public class SteeringEvadeBehaviour implements EvadeBehaviour {
private final SteeringFleeBehaviour flee;
private final float predictionDuration;
public SteeringEvadeBehaviour(final SteeringFleeBehaviour flee, final float predictionDuration) {
this.flee = flee;
this.predictionDuration = predictionDuration;
}
@Override
public BehaviourOutput runEvade(final Point2f position, final float linearSpeed, final float maxLinearAcceleration, final Point2f targetPosition, final Vector2f targetLinearMotion) {
Vector2f _multiply = targetLinearMotion.operator_multiply(this.predictionDuration);
Point2f fleeTarget = targetPosition.operator_plus(_multiply);
return this.flee.runFlee(position, linearSpeed, maxLinearAcceleration, fleeTarget);
}
}

View file

@ -0,0 +1,22 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.FaceBehaviour;
import fr.utbm.info.vi51.motionbehavior.SteeringAlignBehaviour;
@SuppressWarnings("all")
public class SteeringFaceBehaviour implements FaceBehaviour {
private final SteeringAlignBehaviour align;
public SteeringFaceBehaviour(final SteeringAlignBehaviour align) {
this.align = align;
}
@Override
public BehaviourOutput runFace(final Point2f position, final Vector2f orientation, final float angularSpeed, final float maxAngularAcceleration, final Point2f target) {
Vector2f alignTarget = target.operator_minus(position);
return this.align.runAlign(orientation, angularSpeed, maxAngularAcceleration, alignTarget);
}
}

View file

@ -0,0 +1,23 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.FleeBehaviour;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class SteeringFleeBehaviour implements FleeBehaviour {
@Override
public BehaviourOutput runFlee(final Point2f position, final float linearSpeed, final float maxLinearAcceleration, final Point2f target) {
final Vector2f direction = position.operator_minus(target);
direction.setLength(maxLinearAcceleration);
BehaviourOutput _behaviourOutput = new BehaviourOutput(DynamicType.KINEMATIC);
final Procedure1<BehaviourOutput> _function = (BehaviourOutput it) -> {
it.setLinear(direction);
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput, _function);
}
}

View file

@ -0,0 +1,26 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.PursueBehaviour;
import fr.utbm.info.vi51.motionbehavior.SteeringSeekBehaviour;
@SuppressWarnings("all")
public class SteeringPursueBehaviour implements PursueBehaviour {
private final SteeringSeekBehaviour seek;
private final float predictionDuration;
public SteeringPursueBehaviour(final SteeringSeekBehaviour seek, final float predictionDuration) {
this.seek = seek;
this.predictionDuration = predictionDuration;
}
@Override
public BehaviourOutput runPursue(final Point2f position, final float linearSpeed, final float maxLinearAcceleration, final Point2f targetPosition, final Vector2f targetLinearMotion) {
Vector2f _multiply = targetLinearMotion.operator_multiply(this.predictionDuration);
Point2f seekTarget = targetPosition.operator_plus(_multiply);
return this.seek.runSeek(position, linearSpeed, maxLinearAcceleration, seekTarget);
}
}

View file

@ -0,0 +1,23 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.SeekBehaviour;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class SteeringSeekBehaviour implements SeekBehaviour {
@Override
public BehaviourOutput runSeek(final Point2f position, final float linearSpeed, final float maxLinearAcceleration, final Point2f target) {
final Vector2f direction = target.operator_minus(position);
direction.setLength(maxLinearAcceleration);
BehaviourOutput _behaviourOutput = new BehaviourOutput(DynamicType.KINEMATIC);
final Procedure1<BehaviourOutput> _function = (BehaviourOutput it) -> {
it.setLinear(direction);
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput, _function);
}
}

View file

@ -0,0 +1,62 @@
package fr.utbm.info.vi51.motionbehavior;
import fr.utbm.info.vi51.framework.agent.BehaviourOutput;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.SteeringFaceBehaviour;
import fr.utbm.info.vi51.motionbehavior.SteeringSeekBehaviour;
import fr.utbm.info.vi51.motionbehavior.WanderBehaviour;
import java.util.Random;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class SteeringWanderBehaviour implements WanderBehaviour {
private final float circleDistance;
private final float circleRadius;
private final float maxRotation;
private final SteeringFaceBehaviour faceBehaviour;
private final SteeringSeekBehaviour seekBehaviour;
private final Random random = new Random();
private float rotation = 0f;
public SteeringWanderBehaviour(final float circleDistance, final float circleRadius, final float maxRotation, final SteeringFaceBehaviour faceBehaviour, final SteeringSeekBehaviour seekBehaviour) {
this.circleDistance = circleDistance;
this.circleRadius = circleRadius;
this.maxRotation = maxRotation;
this.faceBehaviour = faceBehaviour;
this.seekBehaviour = seekBehaviour;
}
@Override
public BehaviourOutput runWander(final Point2f position, final Vector2f orientation, final float linearSpeed, final float maxLinearAcceleration, final float angularSpeed, final float maxAngularAcceleration) {
Vector2f circleCenter = orientation.toColinearVector(this.circleDistance);
Vector2f displacement = circleCenter.toColinearVector(this.circleRadius);
displacement.turn(this.rotation);
float _rotation = this.rotation;
float _nextFloat = this.random.nextFloat();
float _multiply = (_nextFloat * 2f);
float _minus = (_multiply - 1f);
float _multiply_1 = (_minus * this.maxRotation);
this.rotation = (_rotation + _multiply_1);
Point2f circleCenterPosition = position.operator_plus(circleCenter);
Point2f faceTarget = circleCenterPosition.operator_plus(displacement);
final BehaviourOutput faceOutput = this.faceBehaviour.runFace(position, orientation, angularSpeed, maxAngularAcceleration, faceTarget);
final BehaviourOutput seekOutput = this.seekBehaviour.runSeek(position, linearSpeed, maxLinearAcceleration, circleCenterPosition);
BehaviourOutput _behaviourOutput = new BehaviourOutput(DynamicType.KINEMATIC);
final Procedure1<BehaviourOutput> _function = (BehaviourOutput it) -> {
Vector2f _linear = seekOutput.getLinear();
it.setLinear(_linear);
float _angular = faceOutput.getAngular();
it.setAngular(_angular);
};
return ObjectExtensions.<BehaviourOutput>operator_doubleArrow(_behaviourOutput, _function);
}
}

View file

@ -0,0 +1,4 @@
PROGRAM_NAME = VI51 LW5
INTRO_MESSAGE = VI51 Lab work #5\nCopyright (c) 2007-2016 Stéphane GALLAND\nThanks to Julia Nikolaeva aka. Flameia for the icons <flameia@zerobias.com>
USE_STEERING_MESSAGE = Do you want to run the steering behaviours in place of the kinematic behaviours?
USE_STEERING_TITLE = Steering or Kinematic Behaviours

View file

@ -0,0 +1,4 @@
PROGRAM_NAME = TP5 VI51
INTRO_MESSAGE = Travaux Pratiques #5\nCopyright (c) 2007-2016 Stéphane GALLAND\nMerci à Julia Nikolaeva aka. Flameia pour ses icônes <flameia@zerobias.com>
USE_STEERING_MESSAGE = Voulez-vous exécuter les comportements steerings à la place des comportements cinématiques ?
USE_STEERING_TITLE = Comportements Steerings ou Cinématiques

View file

@ -0,0 +1,3 @@
SHOW_ICONS = Draw the icons of the rabbits.
SHOW_POSITIONS = Draw the positions.
SHOW_FORMATIONS = Draw the formation.

View file

@ -0,0 +1,3 @@
SHOW_ICONS = Dessine les icônes des lapins.
SHOW_POSITIONS = Dessine les positions.
SHOW_FORMATIONS = Dessine la formation.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View file

@ -0,0 +1,2 @@
INVALID_ROTATION = **** INVALID ROTATION (NaN); object with name ''{0}''.
INVALID_DURATION = **** INVALID DURATION (NaN); object with name ''{0}''.

View file

@ -0,0 +1,2 @@
INVALID_ROTATION = **** ROTATION INVALIDE (NaN); objet avec le nom ''{0}''.
INVALID_DURATION = **** DUREE INVALIDE (NaN); objet avec le nom ''{0}''.

View file

@ -0,0 +1 @@
INVALID_POSITION = **** INVALID POSITION (NaN); object with name '{0}'.

View file

@ -0,0 +1 @@
INVALID_POSITION = **** POSITION INVALIDE (NaN); objet avec le nom '{0}'.

View file

@ -0,0 +1 @@
BODY_OF = Body of {0}

View file

@ -0,0 +1 @@
BODY_OF = Corps de {0}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -0,0 +1,3 @@
QUIT = Quit
TARGET_POSITION = Target: ({0,number,#.#}; {1,number,#.#})
SLIDER_LABEL = Change the simulation speed

View file

@ -0,0 +1,3 @@
QUIT = Quitter
TARGET_POSITION = Objectif : ({0,number,#.#}; {1,number,#.#})
SLIDER_LABEL = Modification de la vitesse de simulation

View file

@ -0,0 +1,3 @@
KINEMATIC_BUTTON = Kinematic Behavior (speed)
STEERING_BUTTON = Steering Behavior (acceleration)
TITLE = Behavior Type Selection

View file

@ -0,0 +1,3 @@
KINEMATIC_BUTTON = Comportement Cinematique (vitesse)
STEERING_BUTTON = Comportement directeur (acceleration)
TITLE = Sélection du type des comportement

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View file

@ -0,0 +1,85 @@
/*
* $Id$
*
* Copyright (c) 2011-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.eurock;
import fr.utbm.info.vi51.eurock.agent.Guy;
import fr.utbm.info.vi51.eurock.environment.WorldModel;
import fr.utbm.info.vi51.eurock.gui.GUI;
import fr.utbm.info.vi51.framework.FrameworkLauncher;
import fr.utbm.info.vi51.framework.environment.AgentBody;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.gui.FrameworkGUI;
import fr.utbm.info.vi51.framework.util.LocalizedString;
import fr.utbm.info.vi51.framework.util.SpawnMapping;
import io.sarl.lang.core.Agent;
/**
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
public class MainProgram {
private static float WORLD_SIZE_X = 500;
private static float WORLD_SIZE_Y = 500;
private static int AGENT_COUNT = 300;
/** Main program.
*
* @param argv are the command line arguments.
* @throws Exception
*/
public static void main(String[] argv) throws Exception {
System.out.println(LocalizedString.getString(MainProgram.class, "INTRO_MESSAGE")); //$NON-NLS-1$
WorldModel environment = new WorldModel(WORLD_SIZE_X, WORLD_SIZE_Y);
for (int i = 0; i < AGENT_COUNT; ++i) {
environment.createFish();
}
FrameworkGUI gui = new GUI(WORLD_SIZE_X, WORLD_SIZE_Y, environment.getTimeManager());
FrameworkLauncher.launchSimulation(
environment,
new ApplicationMapping(),
DynamicType.STEERING,
gui);
}
/**
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
private static class ApplicationMapping extends SpawnMapping {
@Override
public Class<? extends Agent> getAgentTypeForBody(AgentBody body) {
Object type = body.getType();
if ("FISH".equals(type)) {
return Guy.class;
}
throw new IllegalArgumentException();
}
}
}

View file

@ -0,0 +1,86 @@
/*
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.eurock.^agent
import fr.utbm.info.vi51.framework.^agent.AbstractAnimat
import fr.utbm.info.vi51.framework.^agent.PhysicEnvironment
import fr.utbm.info.vi51.framework.environment.PerceptionEvent
import fr.utbm.info.vi51.framework.environment.SimulationAgentReady
import fr.utbm.info.vi51.framework.math.Vector2f
import fr.utbm.info.vi51.motionbehavior.AlignBehaviour
import fr.utbm.info.vi51.motionbehavior.KinematicAlignBehaviour
import fr.utbm.info.vi51.motionbehavior.KinematicSeekBehaviour
import fr.utbm.info.vi51.motionbehavior.KinematicWanderBehaviour
import fr.utbm.info.vi51.motionbehavior.SeekBehaviour
import fr.utbm.info.vi51.motionbehavior.WanderBehaviour
import io.sarl.core.DefaultContextInteractions
import io.sarl.core.Initialize
import io.sarl.core.Lifecycle
import io.sarl.core.Logging
import java.util.Random
agent Guy extends AbstractAnimat {
uses PhysicEnvironment, Lifecycle, DefaultContextInteractions, Logging
var seekBehaviour : SeekBehaviour
var wanderBehaviour : WanderBehaviour
var alignBehaviour : AlignBehaviour
on Initialize {
super._handle_Initialize_0(occurrence)
emit(new SimulationAgentReady)
this.seekBehaviour = new KinematicSeekBehaviour
this.alignBehaviour = new KinematicAlignBehaviour
this.wanderBehaviour = new KinematicWanderBehaviour
}
on PerceptionEvent {
var body = occurrence.body
var direction = new Vector2f
var random = new Random
var barycenter = new Vector2f
var f = new Vector2f
if (occurrence.perceptions.size > 0) {
for ( o : occurrence.perceptions ) {
if (o.type == "FISH") {
barycenter += o.position - body.position
direction += o.direction;
f += (body.position - o.position) * 4 / ((body.position - o.position).length ** 1 + 1) as float
} else if(o.type == "TARGET") {
barycenter += (o.position - body.position) * 5
direction += (o.position - body.position)
f += (body.position - o.position).toUnitVector() / ((body.position - o.position).length ** 8 + 1) as float
}
}
barycenter *= (1.0 / occurrence.perceptions.size) as float
direction += barycenter
influenceKinematic(barycenter+f, body.direction.signedAngle(direction))
} else {
var linear = new Vector2f(random.nextInt() as float, random.nextInt() as float)
var angular = random.nextGaussian() as float
influenceKinematic(linear, angular)
}
}
}

View file

@ -0,0 +1,28 @@
package fr.utbm.info.vi51.eurock.environment;
import java.util.UUID;
import fr.utbm.info.vi51.framework.environment.AbstractFrustum;
import fr.utbm.info.vi51.framework.math.Circle2f;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Shape2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
public class CircleFrustrum extends AbstractFrustum {
private float distance;
public CircleFrustrum(UUID owner, float distance) {
super(owner);
this.distance = distance;
}
@Override
public Shape2f<?> toShape(Point2f position, Vector2f orientation) {
return new Circle2f(position, distance);
}
}

View file

@ -0,0 +1,59 @@
/*
* $Id$
*
* Copyright (c) 2011-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.eurock.environment;
import java.util.UUID;
import fr.utbm.info.vi51.framework.environment.AbstractSituatedObject;
import fr.utbm.info.vi51.framework.math.Circle2f;
/**
* Situated object representing the mouse position.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
public final class MouseTarget extends AbstractSituatedObject {
private static final long serialVersionUID = 3960871126454165695L;
/**
* @param x
* @param y
*/
public MouseTarget(float x, float y) {
super(UUID.randomUUID(), new Circle2f(0, 0, 5f), x, y);
setType("TARGET");
}
/** Set the position of the mouse target.
*
* @param x
* @param y
*/
public void setMousePosition(float x, float y) {
// *** CAUTION ***
// Changing directly the position of the target without going through the influence
// solver may cause collision between the target and the agents.
setPosition(x, y);
}
}

View file

@ -0,0 +1,49 @@
/*
* $Id$
*
* Copyright (c) 2011-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.eurock.environment;
import java.util.UUID;
import fr.utbm.info.vi51.framework.environment.AbstractSituatedObject;
import fr.utbm.info.vi51.framework.math.Rectangle2f;
/**
* Situated object representing the mouse position.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
public final class WallObject extends AbstractSituatedObject {
private static final long serialVersionUID = 3960871126454165695L;
/**
* @param x
* @param y
* @param width
* @param height
*/
public WallObject(float x, float y, float width, float height) {
super(UUID.randomUUID(), new Rectangle2f(0 - width / 2, 0 - height / 2, width, height), x + width / 2, y + height / 2);
setType("WALL");
}
}

View file

@ -0,0 +1,285 @@
/*
* $Id$
*
* Copyright (c) 2011-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.eurock.environment;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import fr.utbm.info.vi51.framework.environment.AbstractEnvironment;
import fr.utbm.info.vi51.framework.environment.AgentBody;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.environment.Frustum;
import fr.utbm.info.vi51.framework.environment.Influence;
import fr.utbm.info.vi51.framework.environment.MotionInfluence;
import fr.utbm.info.vi51.framework.environment.Percept;
import fr.utbm.info.vi51.framework.environment.SituatedObject;
import fr.utbm.info.vi51.framework.gui.WorldModelStateProvider;
import fr.utbm.info.vi51.framework.math.Circle2f;
import fr.utbm.info.vi51.framework.math.MathUtil;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Shape2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.framework.time.StepTimeManager;
import fr.utbm.info.vi51.framework.time.TimeManager;
import fr.utbm.info.vi51.framework.util.CollectionUtil;
import fr.utbm.info.vi51.framework.util.LocalizedString;
/**
* Model of the world.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
public class WorldModel extends AbstractEnvironment implements WorldModelStateProvider {
private final static float FISH_SIZE = 2f;
private final static float RADIUS = 60f;
private MouseTarget mouseTarget = null;
private final WallObject northWall;
private final WallObject eastWall;
private final WallObject westWall;
private final WallObject southWall;
/**
* @param width is the width of the world.
* @param height is the height of the world.
*/
public WorldModel(float width, float height) {
super(width, height, new StepTimeManager(500));
this.northWall = new WallObject(0, -1, width, 1);
this.southWall = new WallObject(0, height, width, 1);
this.westWall = new WallObject(-1, 0, height, 1);
this.eastWall = new WallObject(0, width, height, 1);
}
/** {@inheritDoc}
*/
public void setMouseTarget(Point2f target) {
if (target==null) this.mouseTarget = null;
else this.mouseTarget = new MouseTarget(target.getX(), target.getY());
}
/**
* {@inheritDoc}
*/
@Override
protected List<Percept> computePerceptionsFor(AgentBody agent) {
List<Percept> allPercepts = new ArrayList<Percept>();
if (agent!=null) {
Frustum frustum = agent.getFrustum();
Shape2f<?> frustumShape = frustum.toShape(agent.getPosition(), agent.getDirection());
// add mouse target in perceptions
MouseTarget p = this.mouseTarget;
if (p!=null && frustumShape.intersects(new Circle2f(p.getPosition(), 1))) {
allPercepts.add(new Percept(p));
}
// Add other agents
for(AgentBody b1 : getAgentBodies()) {
if (b1!=agent && frustumShape.intersects(b1.getShape())) {
allPercepts.add(new Percept(b1));
}
}
// Add walls.
if (frustumShape.intersects(this.northWall.getShape())) {
allPercepts.add(new Percept(this.northWall));
}
if (frustumShape.intersects(this.southWall.getShape())) {
allPercepts.add(new Percept(this.southWall));
}
if (frustumShape.intersects(this.eastWall.getShape())) {
allPercepts.add(new Percept(this.eastWall));
}
if (frustumShape.intersects(this.westWall.getShape())) {
allPercepts.add(new Percept(this.westWall));
}
}
return allPercepts;
}
/**
* {@inheritDoc}
*/
@Override
protected void applyInfluences(Collection<MotionInfluence> motionInfluences,
Collection<Influence> otherInfluences, TimeManager timeManager) {
List<MotionInfluence> influenceList = new ArrayList<MotionInfluence>(motionInfluences);
List<AnimatAction> actions = new ArrayList<AnimatAction>(influenceList.size());
// Compute actions
for(int index1=0; index1<influenceList.size(); index1++) {
MotionInfluence inf1 = influenceList.get(index1);
AgentBody body1 = getAgentBodyFor(inf1.getEmitter());
if (body1!=null) {
Vector2f move;
float rotation;
if (inf1.getType()==DynamicType.STEERING) {
move = computeSteeringTranslation(body1, inf1.getLinearInfluence(), timeManager);
rotation = computeSteeringRotation(body1, inf1.getAngularInfluence(), timeManager);
}
else {
move = computeKinematicTranslation(body1, inf1.getLinearInfluence(), timeManager);
rotation = computeKinematicRotation(body1, inf1.getAngularInfluence(), timeManager);
}
Shape2f<?> body1Bounds = body1.getShape();
// Trivial collision detection
for(int index2=index1+1; index2<influenceList.size(); index2++) {
MotionInfluence inf2 = influenceList.get(index2);
AgentBody body2 = getAgentBodyFor(inf2.getEmitter());
if (body2!=null) {
Shape2f<?> body2Bounds = body2.getShape();
if (body1Bounds.intersects(body2Bounds)) {
move.set(0,0);
break;
}
}
}
actions.add(new AnimatAction(body1, move, rotation));
}
}
// Apply the actions
for(AnimatAction action : actions) {
AgentBody body = action.getObjectToMove();
if (body!=null) {
move(
body,
action.getTranslation(),
action.getRotation());
}
}
}
@Override
public Iterable<? extends SituatedObject> getAllObjects() {
if (this.mouseTarget != null) {
return CollectionUtil.newIterable(getAgentBodies(), this.mouseTarget);
}
return getAgentBodies();
}
@Override
protected List<Influence> computeEndogenousBehaviorInfluences() {
return Collections.emptyList();
}
private void createBody(String type) {
UUID id = UUID.randomUUID();
AgentBody body = new AgentBody(
id,
new Circle2f(0f, 0f, FISH_SIZE), // body
5f, // max linear speed m/s
.5f, // max linear acceleration (m/s)/s
MathUtil.PI/4f, // max angular speed r/s
MathUtil.PI/10f, // max angular acceleration (r/s)/s
new CircleFrustrum(id, RADIUS));
body.setName(LocalizedString.getString(WorldModel.class, type, getAgentBodyNumber() + 1));
body.setType(type);
addAgentBody(
body,
randomPosition(),
(float) Math.random() * MathUtil.TWO_PI);
}
/** Create the body of a fish.
*/
public void createFish() {
createBody("FISH");
}
protected Point2f randomPosition() {
float x = (float) Math.random() * getWidth() - FISH_SIZE;
float y = (float) Math.random() * getHeight() - FISH_SIZE;
return new Point2f(x, y);
}
@Override
protected void onAgentBodyCreated(AgentBody body) {
//
}
@Override
protected void onAgentBodyDestroyed(AgentBody body) {
//
}
/**
* Real action to apply in the world.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
private static class AnimatAction {
private final AgentBody body;
private final Vector2f move;
private final float rotation;
/**
* @param object is the animat body.
* @param move is the translation.
* @param rotation is the rotation.
*/
public AnimatAction(AgentBody object, Vector2f move, float rotation) {
this.body = object;
this.move = move;
this.rotation = rotation;
}
/** Replies the moved object.
*
* @return the moved object.
*/
public AgentBody getObjectToMove() {
return this.body;
}
/** Replies the translation.
*
* @return the translation.
*/
public Vector2f getTranslation() {
return this.move;
}
/** Replies the rotation.
*
* @return the rotation.
*/
public float getRotation() {
return this.rotation;
}
}
}

View file

@ -0,0 +1,170 @@
/*
* $Id$
*
* Copyright (c) 2011-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.eurock.gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Line2D;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JSlider;
import fr.utbm.info.vi51.eurock.MainProgram;
import fr.utbm.info.vi51.framework.gui.AbstractFrameworkGUI;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.framework.time.TimeManager;
import fr.utbm.info.vi51.framework.util.LocalizedString;
import fr.utbm.info.vi51.framework.util.Resources;
/** UI for the rabbits.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
public class GUI extends AbstractFrameworkGUI {
private static final long serialVersionUID = 7958401897774129069L;
/** Size of the direction vector (in pixels).
*/
private static final float DIRECTION_RADIUS = 30f;
private JCheckBox showPositions;
/**
* @param worldWidth
* @param worldHeight
* @param formations
*/
public GUI(float worldWidth, float worldHeight, TimeManager timeManager) {
super(
LocalizedString.getString(MainProgram.class, "PROGRAM_NAME"), //$NON-NLS-1$
worldWidth,
worldHeight,
Resources.getResource(GUI.class, "icon.png"), //$NON-NLS-1$
timeManager);
}
@Override
protected boolean isMouseCursorHidden() {
// Hide the mouse cursor since a carrot icon is displayed at the same location.
return false;
}
@Override
protected JComponent createBottomPanel(JSlider speedSlider, JComponent closeButton, JComponent messageBox) {
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new GridLayout(6, 1));
this.showPositions = new JCheckBox(LocalizedString.getString(getClass(), "SHOW_POSITIONS")); //$NON-NLS-1$
this.showPositions.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
repaint();
}
});
bottomPanel.add(speedSlider);
bottomPanel.add(this.showPositions);
bottomPanel.add(closeButton);
bottomPanel.add(messageBox);
return bottomPanel;
}
@Override
protected void paintAgentBody(Graphics2D g2d,
Point2f positionOnScreen,
Vector2f orientationOnScreen,
Shape shape, Serializable type, String name,
Point2f positionInMAS,
Shape frustum) {
Rectangle bounds = shape.getBounds();
g2d.setColor(Color.BLUE);
orientationOnScreen.scale(DIRECTION_RADIUS);
g2d.draw(new Line2D.Float(
positionOnScreen.getX(),
positionOnScreen.getY(),
positionOnScreen.getX() + orientationOnScreen.getX(),
positionOnScreen.getY() + orientationOnScreen.getY()));
g2d.fill(shape);
if (this.showPositions.isSelected()) {
Font oldFont = g2d.getFont();
Font f = oldFont.deriveFont(6);
g2d.setColor(g2d.getBackground().darker());
g2d.setFont(f);
NumberFormat fmt = new DecimalFormat("#.#");
g2d.drawString(
"(" + fmt.format(positionInMAS.getX()) + ";" + fmt.format(positionInMAS.getY()) + ")",
(float) bounds.getMaxX() + 2,
(float) bounds.getMaxY() + 2);
g2d.setFont(oldFont);
}
}
@Override
protected void paintSituatedObject(Graphics2D g2d,
Point2f positionOnScreen,
Vector2f orientationOnScreen,
Shape shape, Serializable type, String name,
Point2f positionInMAS) {
Rectangle bounds = shape.getBounds();
g2d.setColor(Color.GREEN);
if ("TARGET".equals(type)) {
g2d.setColor(Color.RED);
}
g2d.fill(shape);
if (orientationOnScreen != null) {
g2d.setColor(g2d.getBackground());
Vector2f v = orientationOnScreen.operator_multiply(
(float) Math.max(bounds.getWidth(), bounds.getHeight()));
g2d.draw(new Line2D.Float(
positionOnScreen.getX(),
positionOnScreen.getY(),
positionOnScreen.getX() + v.getX(),
positionOnScreen.getY() + v.getY()));
}
if (this.showPositions.isSelected()) {
Font oldFont = g2d.getFont();
Font f = oldFont.deriveFont(6);
g2d.setColor(g2d.getBackground().darker());
g2d.setFont(f);
NumberFormat fmt = new DecimalFormat("#.#");
g2d.drawString(
"(" + fmt.format(positionInMAS.getX()) + ";" + fmt.format(positionInMAS.getY()) + ")",
(float) bounds.getMaxX() + 2,
(float) bounds.getMaxY() + 2);
g2d.setFont(oldFont);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -0,0 +1,122 @@
/*
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.environment.Environment;
import fr.utbm.info.vi51.framework.environment.StopSimulation;
import fr.utbm.info.vi51.framework.gui.FrameworkGUI;
import fr.utbm.info.vi51.framework.util.SpawnMapping;
import io.janusproject.Boot;
import io.janusproject.JanusConfig;
import io.janusproject.services.contextspace.ContextSpaceService;
import io.janusproject.util.LoggerCreator;
import io.sarl.lang.core.Address;
import io.sarl.lang.core.AgentContext;
import io.sarl.lang.core.EventSpace;
/**
* Launcher of the simulation framework.
*
* This launcher needs the {@link http://www.janusproject.io Janus platform}.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
public class FrameworkLauncher {
private static UUID environmentInteractionSpace = null;
private static Environment environmentSingleton = null;
private static FrameworkGUI uiSingleton = null;
private static io.janusproject.kernel.Kernel kernel = null;
private static final AtomicBoolean canStop = new AtomicBoolean(false);
/** Launch the simulation and its associated UI.
*
* @param environment is the environment to use.
* @param spawnMapping the mapping from body to agent type.
* @param behaviorType the type of the agent behaviors.
* @param gui is the GUI to launch.
* @param parameters the parameters to give to every agent.
* @throws Exception if the Janus platform cannot be started.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void launchSimulation(Environment environment, SpawnMapping spawnMapping,
DynamicType behaviorType, FrameworkGUI gui, Object... parameters) throws Exception {
Boot.setOffline(true);
Boot.setVerboseLevel(LoggerCreator.toInt(Level.INFO));
Boot.showJanusLogo();
environmentInteractionSpace = UUID.randomUUID();
uiSingleton = gui;
environmentSingleton = environment;
Object[] params = new Object[4 + parameters.length];
params[0] = environmentSingleton;
params[1] = environmentInteractionSpace;
params[2] = spawnMapping;
params[3] = behaviorType;
System.arraycopy(parameters, 0, params, 4, parameters.length);
kernel = Boot.startJanus(
(Class) null,
SimulatorAgent.class,
params);
if (uiSingleton != null) {
if (environmentSingleton != null) {
environmentSingleton.addEnvironmentListener(uiSingleton);
}
uiSingleton.setVisible(true);
}
canStop.set(true);
}
/** Stop the simulation right now.
*/
public static void stopSimulation() {
if (!canStop.get()) {
throw new IllegalStateException("You must call startSimulation() before stopSimulation().");
}
AgentContext context = kernel.getService(ContextSpaceService.class).getContext(
UUID.fromString(JanusConfig.DEFAULT_CONTEXT_ID_VALUE));
EventSpace space = context.getDefaultSpace();
Address adr = new Address(space.getID(), UUID.randomUUID());
StopSimulation sSimulation = new StopSimulation(adr);
context.getDefaultSpace().emit(sSimulation);
if (uiSingleton!=null) {
uiSingleton.setVisible(false);
if (environmentSingleton != null) {
environmentSingleton.removeEnvironmentListener(uiSingleton);
}
uiSingleton.dispose();
}
environmentSingleton = null;
environmentInteractionSpace = null;
uiSingleton = null;
kernel = null;
}
}

View file

@ -0,0 +1,154 @@
/*
* $Id$
*
* Copyright (c) 2011-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.agent;
import java.io.Serializable;
import fr.utbm.info.vi51.framework.environment.DynamicType;
import fr.utbm.info.vi51.framework.math.Vector2f;
/**
* Output of a behaviour.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
public class BehaviourOutput implements Serializable {
private static final long serialVersionUID = 1243172129345360316L;
private final DynamicType type;
private final Vector2f linear = new Vector2f();
private float angular = 0;
/**
* @param type is the type of the output.
*/
public BehaviourOutput(DynamicType type) {
this.type = type;
}
/**
* @param outputToCopy is the output tp copy.
*/
public BehaviourOutput(BehaviourOutput outputToCopy) {
assert(outputToCopy!=null);
this.type = outputToCopy.getType();
this.linear.set(outputToCopy.getLinear());
this.angular = outputToCopy.getAngular();
}
/** Replies the type of the output.
*
* @return the type of the output.
*/
public DynamicType getType() {
return this.type;
}
/** Replies the linear output.
*
* @return the linear output.
*/
public Vector2f getLinear() {
return this.linear;
}
/** Replies the angular output.
*
* @return the angular output.
*/
public float getAngular() {
return this.angular;
}
/** Set the linear output.
*
* @param linear
*/
public void setLinear(Vector2f linear) {
assert(linear!=null);
this.linear.set(linear);
}
/** Set the linear output.
*
* @param dx
* @param dy
*/
public void setLinear(float dx, float dy) {
this.linear.set(dx, dy);
}
/** Set the angular output.
*
* @param angular
*/
public void setAngular(float angular) {
this.angular = angular;
}
/** Set the linear output.
*
* @param outputToCopy
*/
public void setLinear(BehaviourOutput outputToCopy) {
if (outputToCopy!=null) {
if (outputToCopy.getType()!=getType()) {
throw new IllegalArgumentException();
}
this.linear.set(outputToCopy.getLinear());
}
}
/** Set the angular output.
*
* @param outputToCopy
*/
public void setAngular(BehaviourOutput outputToCopy) {
if (outputToCopy!=null) {
if (outputToCopy.getType()!=getType()) {
throw new IllegalArgumentException();
}
this.angular = outputToCopy.getAngular();
}
}
/** Set the linear and angular output.
*
* @param outputToCopy
*/
public void set(BehaviourOutput outputToCopy) {
if (outputToCopy!=null) {
if (outputToCopy.getType()!=getType()) {
throw new IllegalArgumentException();
}
this.linear.set(outputToCopy.getLinear());
this.angular = outputToCopy.getAngular();
}
}
@Override
public String toString() {
return "l=" + this.linear.toString() + "; a=" + this.angular;
}
}

View file

@ -0,0 +1,78 @@
/*
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.^agent
import fr.utbm.info.vi51.framework.environment.DynamicType
import fr.utbm.info.vi51.framework.environment.Influence
import fr.utbm.info.vi51.framework.environment.Percept
import fr.utbm.info.vi51.framework.environment.StopSimulation
import fr.utbm.info.vi51.framework.math.Vector2f
import io.sarl.core.Initialize
import io.sarl.core.Lifecycle
import java.util.List
import java.util.UUID
agent AbstractAnimat {
uses PhysicEnvironment, Lifecycle
var behaviorType : DynamicType
on Initialize {
var physicSkill = new StandardPhysicEnvironment(
occurrence.parameters.get(0) as UUID,
occurrence.parameters.get(1) as UUID)
this.behaviorType = occurrence.parameters.get(2) as DynamicType
setSkill(PhysicEnvironment, physicSkill)
}
def getMaxLinear(p : Percept) : float {
if (this.behaviorType == DynamicType::STEERING) p.maxLinearAcceleration else p.maxLinearSpeed
}
def getMaxAngular(p : Percept) : float {
if (this.behaviorType == DynamicType::STEERING) p.maxAngularAcceleration else p.maxAngularSpeed
}
def emitInfluence(output : BehaviourOutput , influences : Influence*) {
if (output !== null) {
if (output.getType() === DynamicType::STEERING)
influenceSteering(output.linear, output.angular, influences)
else
influenceKinematic(output.linear, output.angular, influences);
} else {
influenceSteering(new Vector2f, 0f, influences)
}
}
def doNothing {
influenceKinematic(new Vector2f, 0f)
}
def first(list : List<Percept>) : Percept {
if (list.isEmpty) null else list.get(0)
}
on StopSimulation {
killMe
}
}

View file

@ -0,0 +1,45 @@
/*
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.^agent
import fr.utbm.info.vi51.framework.math.Vector2f
import fr.utbm.info.vi51.framework.environment.Influence
capacity PhysicEnvironment {
/** Invoked to send the influence to the environment.
*
* @param linearInfluence is the linear influence to apply on the object.
* @param angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
def influenceKinematic(linearInfluence : Vector2f = null, angularInfluence : float = 0f, otherInfluences : Influence*)
/** Invoked to send the influence to the environment.
*
* @param linearInfluence is the linear influence to apply on the object.
* @param angularInfluence is the angular influence to apply on the object.
* @param otherInfluences other influences to emit in parallel to the motion influence.
*/
def influenceSteering(linearInfluence : Vector2f = null, angularInfluence : float = 0f, otherInfluences : Influence*)
}

View file

@ -0,0 +1,102 @@
/*
* $Id$
*
* Copyright (c) 2014-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.^agent
import fr.utbm.info.vi51.framework.environment.DynamicType
import fr.utbm.info.vi51.framework.environment.Influence
import fr.utbm.info.vi51.framework.environment.InfluenceEvent
import fr.utbm.info.vi51.framework.environment.KillInfluence
import fr.utbm.info.vi51.framework.environment.MotionInfluence
import fr.utbm.info.vi51.framework.math.Vector2f
import fr.utbm.info.vi51.framework.util.AddressUUIDScope
import io.sarl.core.Behaviors
import io.sarl.core.DefaultContextInteractions
import io.sarl.lang.core.Address
import io.sarl.util.OpenEventSpace
import java.lang.reflect.Array
import java.util.UUID
skill StandardPhysicEnvironment implements PhysicEnvironment {
uses DefaultContextInteractions, Behaviors
val spaceID : UUID
val environmentID : UUID
var physicSpace : OpenEventSpace
var myAdr : Address
new (spaceID : UUID, environmentID : UUID) {
this.environmentID = environmentID
this.spaceID = spaceID
}
override install {
do {
this.physicSpace = defaultContext.getSpace(this.spaceID)
Thread::yield
} while (this.physicSpace === null)
this.physicSpace.register(asEventListener)
this.myAdr = this.physicSpace.getAddress(owner.ID)
}
override uninstall() {
var ^event = new InfluenceEvent(new KillInfluence)
^event.source = this.myAdr
this.physicSpace.emit(^event, new AddressUUIDScope(this.environmentID))
this.physicSpace = null
}
override influenceKinematic(linearInfluence : Vector2f = null, angularInfluence : float = 0f, otherInfluences : Influence*) {
var mi : MotionInfluence
if (linearInfluence === null) {
mi = new MotionInfluence(DynamicType::KINEMATIC, angularInfluence)
} else {
mi = new MotionInfluence(DynamicType::KINEMATIC, linearInfluence, angularInfluence)
}
emitInfluences(mi, otherInfluences)
}
override influenceSteering(linearInfluence : Vector2f = null, angularInfluence : float = 0f, otherInfluences : Influence*) {
var mi : MotionInfluence
if (linearInfluence === null) {
mi = new MotionInfluence(DynamicType::STEERING, angularInfluence)
} else {
mi = new MotionInfluence(DynamicType::STEERING, linearInfluence, angularInfluence)
}
emitInfluences(mi, otherInfluences)
}
def emitInfluences(motionInfluence : MotionInfluence, otherInfluences : Influence*) {
var influences : Influence[]
if (otherInfluences.isEmpty) {
influences = Array::newInstance(typeof(Influence), 1) as Influence[]
influences.set(0, motionInfluence)
} else {
influences = Array::newInstance(typeof(Influence), otherInfluences.length + 1) as Influence[]
influences.set(0, motionInfluence)
System::arraycopy(otherInfluences, 0, influences, 1, otherInfluences.length)
}
var ^event = new InfluenceEvent(influences)
^event.source = this.myAdr
this.physicSpace.emit(^event, new AddressUUIDScope(this.environmentID))
}
}

View file

@ -0,0 +1,351 @@
/*
* $Id$
*
* Copyright (c) 2011-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.environment;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.framework.time.TimeManager;
/**
* Abstract implementation of a situated environment.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
public abstract class AbstractEnvironment implements Environment {
private final Map<UUID,AgentBody> agentBodies = new TreeMap<UUID,AgentBody>();
private final TimeManager timeManager;
private final float width;
private final float height;
private final Collection<EnvironmentListener> listeners = new ArrayList<EnvironmentListener>();
private final AtomicBoolean stateChanged = new AtomicBoolean();
private final AtomicBoolean init = new AtomicBoolean(true);
/**
* @param width is the width of the environment.
* @param height is the height of the environment.
* @param timeManager is the time manager to use.
*/
public AbstractEnvironment(float width, float height, TimeManager timeManager) {
this.width = width;
this.height = height;
this.timeManager = timeManager;
}
/** Mark the state of the environment as changed.
*/
protected void stateChanged() {
this.stateChanged.set(true);
}
/** {@inheritDoc}
*/
public void addEnvironmentListener(EnvironmentListener listener) {
synchronized(this.listeners) {
this.listeners.add(listener);
}
}
/** {@inheritDoc}
*/
public void removeEnvironmentListener(EnvironmentListener listener) {
synchronized(this.listeners) {
this.listeners.remove(listener);
}
}
/** Invoked to create an environment event.
*
* @return an environment event.
*/
protected EnvironmentEvent createEnvironmentEvent() {
return new EnvironmentEvent(this);
}
/** Notifies listeners about changes in environment.
*/
protected void fireEnvironmentChange() {
EnvironmentListener[] list;
synchronized(this.listeners) {
list = new EnvironmentListener[this.listeners.size()];
this.listeners.toArray(list);
}
EnvironmentEvent event = createEnvironmentEvent();
for(EnvironmentListener listener : list) {
listener.environmentChanged(event);
}
}
/**
* {@inheritDoc}
*/
public TimeManager getTimeManager() {
return this.timeManager;
}
/**
* {@inheritDoc}
*/
public float getWidth() {
return this.width;
}
/**
* {@inheritDoc}
*/
public float getHeight() {
return this.height;
}
/** Add an agent body.
* This function could be call before the simulation is started.
*
* @param body - the body.
* @param position - the position of the body.
* @param direction - the direction of the body.
*/
protected synchronized void addAgentBody(AgentBody body, Point2f position, float direction) {
if (this.init.get()) {
this.agentBodies.put(body.getID(), body);
body.setPosition(position.getX(), position.getY());
body.setAngle(direction);
onAgentBodyCreated(body);
} else {
throw new IllegalStateException("You cannot call this function after the start of the simulation");
}
}
/** Invoked when an agent body is created.
*
* @param body the body.
*/
protected abstract void onAgentBodyCreated(AgentBody body);
/** Invoked when an agent body is destroyed.
*
* @param body the body.
*/
protected abstract void onAgentBodyDestroyed(AgentBody body);
/**
* {@inheritDoc}
*/
public WorldModelState getState() {
return new WorldModelState(this);
}
/** Replies the bodies in the environment.
*
* The replied collection is unmodifiable.
*
* @return the bodies in the environment.
*/
public Iterable<AgentBody> getAgentBodies() {
return Collections.unmodifiableCollection(this.agentBodies.values());
}
@Override
public int getAgentBodyNumber() {
return this.agentBodies.size();
}
/**
* {@inheritDoc}
*/
public AgentBody getAgentBodyFor(UUID agentId) {
return this.agentBodies.get(agentId);
}
/**
* {@inheritDoc}
*/
public void runBehaviour() {
if (this.init.getAndSet(false)) {
fireEnvironmentChange();
}
this.stateChanged.set(false);
Collection<MotionInfluence> motionInfluences = new ArrayList<>();
Collection<Influence> otherInfluences = new ArrayList<>();
for(AgentBody body : this.agentBodies.values()) {
MotionInfluence mi = body.consumeMotionInfluence();
if (mi != null) {
motionInfluences.add(mi);
}
for (Influence i : body.consumeOtherInfluences()) {
if (i instanceof KillInfluence) {
stateChanged();
AgentBody rbody = this.agentBodies.remove(i.getEmitter());
if (rbody != null) {
onAgentBodyDestroyed(rbody);
}
} else {
otherInfluences.add(i);
}
}
}
for(Influence i : computeEndogenousBehaviorInfluences()) {
if (i instanceof MotionInfluence) {
motionInfluences.add((MotionInfluence) i);
} else if (!(i instanceof KillInfluence)) {
otherInfluences.add(i);
}
}
if (!motionInfluences.isEmpty() || !otherInfluences.isEmpty()) {
applyInfluences(
motionInfluences,
otherInfluences,
this.timeManager);
}
if (this.stateChanged.get()) {
fireEnvironmentChange();
}
this.timeManager.increment();
List<Percept> list;
for(AgentBody body : this.agentBodies.values()) {
list = computePerceptionsFor(body);
if (list==null) list = Collections.emptyList();
body.setPerceptions(list);
}
}
/** Compute the influences for the endogenous behavior of the environment.
*
* @return the list of the environment influences.
*/
protected abstract List<Influence> computeEndogenousBehaviorInfluences();
/** Compute the perceptions for an agent body.
*
* @param agent is the body of the perceiver.
* @return the list of the perceived object, never <code>null</code>
*/
protected abstract List<Percept> computePerceptionsFor(AgentBody agent);
/** Detects conflicts between influences and applied resulting actions.
*
* @param motionInfluences are the motion influences to apply.
* @param otherInfluences are the other influences to apply.
* @param timeManager is the time manager of the environment.
*/
protected abstract void applyInfluences(Collection<MotionInfluence> motionInfluences,
Collection<Influence> otherInfluences, TimeManager timeManager);
/** Compute a steering move according to the linear move and to
* the internal attributes of this object.
*
* @param obj is the object to move.
* @param move is the requested motion.
* @param clock is the simulation time manager
* @return the linear instant motion.
*/
protected final Vector2f computeSteeringTranslation(MobileObject obj, Vector2f move, TimeManager clock) {
if (obj instanceof AbstractMobileObject) {
AbstractMobileObject o = (AbstractMobileObject)obj;
return o.computeSteeringTranslation(move, clock);
}
throw new IllegalArgumentException("obj"); //$NON-NLS-1$
}
/** Compute a kinematic move according to the linear move and to
* the internal attributes of this object.
*
* @param obj is the object to move.
* @param move is the requested motion.
* @param clock is the simulation time manager
* @return the linear instant motion.
*/
protected final Vector2f computeKinematicTranslation(MobileObject obj, Vector2f move, TimeManager clock) {
if (obj instanceof AbstractMobileObject) {
AbstractMobileObject o = (AbstractMobileObject)obj;
return o.computeKinematicTranslation(move, clock);
}
throw new IllegalArgumentException("obj"); //$NON-NLS-1$
}
/** Compute a kinematic move according to the angular move and to
* the internal attributes of this object.
*
* @param obj is the object to move.
* @param move is the requested motion.
* @param clock is the simulation time manager
* @return the angular instant motion.
*/
protected final float computeKinematicRotation(MobileObject obj, float move, TimeManager clock) {
if (obj instanceof AbstractMobileObject) {
AbstractMobileObject o = (AbstractMobileObject)obj;
return o.computeKinematicRotation(move, clock);
}
throw new IllegalArgumentException("obj"); //$NON-NLS-1$
}
/** Compute a steering move according to the angular move and to
* the internal attributes of this object.
*
* @param obj is the object to move.
* @param move is the requested motion.
* @param clock is the simulation time manager
* @return the angular instant motion.
*/
protected final float computeSteeringRotation(MobileObject obj, float move, TimeManager clock) {
if (obj instanceof AbstractMobileObject) {
AbstractMobileObject o = (AbstractMobileObject)obj;
return o.computeSteeringRotation(move, clock);
}
throw new IllegalArgumentException("obj"); //$NON-NLS-1$
}
/** Move the given object.
*
* @param obj is the object to move.
* @param instantTranslation is the linear motion in m
* @param instantRotation is the angular motion in r
*/
protected final void move(MobileObject obj, Vector2f instantTranslation, float instantRotation) {
if (obj instanceof AbstractMobileObject) {
AbstractMobileObject o = (AbstractMobileObject)obj;
float duration = this.timeManager.getLastStepDuration();
o.move(instantTranslation.getX(), instantTranslation.getY(), duration, getWidth(), getHeight());
o.rotate(instantRotation, duration);
stateChanged();
}
else {
throw new IllegalArgumentException("obj"); //$NON-NLS-1$
}
}
}

View file

@ -0,0 +1,105 @@
/*
* $Id$
*
* Copyright (c) 2011-15 Stephane GALLAND <stephane.galland@utbm.fr>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* This program is free software; you can redistribute it and/or modify
*/
package fr.utbm.info.vi51.framework.environment;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.UUID;
/**
* Abstract implementation of a field-of-view.
* This implementation provides the default filtering behavior: remove the perceiver's body
* from the perception.
*
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
public abstract class AbstractFrustum implements Frustum {
private static final long serialVersionUID = -6917303628628755437L;
private final UUID owner;
/**
* @param owner the identifier of the owner of this frustum.
*/
public AbstractFrustum(UUID owner) {
this.owner = owner;
}
@Override
public UUID getOwner() {
return this.owner;
}
@Override
public <D extends SituatedObject> Iterator<D> filter(Iterator<D> iterator) {
return new PerceiverBodyFilter<>(iterator);
}
/**
* @author St&eacute;phane GALLAND &lt;stephane.galland@utbm.fr&gt;
* @version $Name$ $Revision$ $Date$
*/
private class PerceiverBodyFilter<D extends SituatedObject> implements Iterator<D> {
private final Iterator<D> original;
private D next;
public PerceiverBodyFilter(Iterator<D> original) {
this.original = original;
searchNext();
}
private void searchNext() {
this.next = null;
while (this.next == null && this.original.hasNext()) {
D candidate = this.original.next();
if (!Objects.equals(candidate.getID(), getOwner())) {
this.next = candidate;
}
}
}
@Override
public boolean hasNext() {
return this.next != null;
}
@Override
public D next() {
D n = this.next;
if (n == null) {
throw new NoSuchElementException();
}
searchNext();
return n;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
}

Some files were not shown because too many files have changed in this diff Show more