jadex.extension.envsupport.environment.DefaultObjectCreationProcess Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-kernel-extension-envsupport Show documentation
Show all versions of jadex-kernel-extension-envsupport Show documentation
The Jadex kernel extension envsupport allows for using 2D spaces in concert with components.
package jadex.extension.envsupport.environment;
import java.util.HashMap;
import java.util.Map;
import jadex.bridge.service.types.clock.IClockService;
import jadex.commons.SimplePropertyObject;
import jadex.javaparser.IParsedExpression;
import jadex.javaparser.SimpleValueFetcher;
/**
* Process for continuously creating objects in the space.
* The following properties are supported:
*
* type
: The type of the object to be created (String, required).
* properties
: The initial properties of the object (Map, optional).
* condition
: A condition to enable/disable object creation (boolean, optional).
* tickrate
: Number of ticks between object creation (double, optional, 0 == off).
* timerate
: Number of milliseconds between object creation (double, optional, 0 == off).
*
* Properties may be dynamic and refer to the environment space using $space
* and to the clock service using $clock
.
*/
public class DefaultObjectCreationProcess extends SimplePropertyObject implements ISpaceProcess
{
//-------- attributes --------
/** The last executed tick. */
protected double lasttick;
/** The last executed time. */
protected double lasttime;
/** The last rate. */
protected double lastrate;
/** The fetcher. */
protected SimpleValueFetcher fetcher;
//-------- constructors --------
/**
* Create a new create food process.
*/
public DefaultObjectCreationProcess()
{
}
//-------- ISpaceProcess interface --------
/**
* This method will be executed by the object before the process gets added
* to the execution queue.
* @param clock The clock.
* @param space The space this process is running in.
*/
public void start(IClockService clock, IEnvironmentSpace space)
{
this.lasttick = clock.getTick();
this.lasttime = clock.getTime();
this.fetcher = new SimpleValueFetcher();
fetcher.setValue("$space", space);
fetcher.setValue("$clock", clock);
// Set back counters to trigger immediate object creation at startup.
if(getProperty("tickrate")!=null)
{
this.lastrate = ((Number)getProperty("tickrate")).doubleValue();
lasttick -= lastrate;
}
else if(getProperty("timerate")!=null)
{
this.lastrate = ((Number)getProperty("timerate")).doubleValue();
lasttime -= lastrate;
}
}
/**
* This method will be executed by the object before the process is removed
* from the execution queue.
* @param clock The clock.
* @param space The space this process is running in.
*/
public void shutdown(IEnvironmentSpace space)
{
}
/**
* Executes the environment process
* @param clock The clock.
* @param space The space this process is running in.
*/
public void execute(IClockService clock, IEnvironmentSpace space)
{
if(getProperty("tickrate")!=null)
{
// double rate = ((Number)getProperty("tickrate")).doubleValue();
double current = clock.getTick();
while(lastrate>0 && lasttick+lastrate0 && lasttime+lastrate