Class BasicEntity
- java.lang.Object
-
- de.unistuttgart.informatik.fius.icge.simulation.entity.BasicEntity
-
- All Implemented Interfaces:
Entity
- Direct Known Subclasses:
MovableEntity
public abstract class BasicEntity extends Object implements Entity
A basic implementation ofEntity- Author:
- Tim Neumann
-
-
Field Summary
Fields Modifier and Type Field Description protected CompletableFuture<Void>endOfLastEnqueuedOperationThe completable future representing the completion of the last enqueued operation.
-
Constructor Summary
Constructors Constructor Description BasicEntity()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidenqueueToPerformNewOperation(CompletableFuture<Void> endOfNewOperation)Wait for the last enqueued long running operation to finish before allowing the new Operation to perform.DrawablegetDrawInformation()protected PlayfieldgetPlayfield()Get the playfield of this entity.PositiongetPosition()protected SimulationgetSimulation()Get the simulation of this entity.protected abstract StringgetTextureHandle()Get the texture handle, with which to get the texture for this entity.protected abstract intgetZPosition()Get the z position of this entity.voidinitOnPlayfield(Playfield playfield)Method to initialize this entity after being added to the playfield.booleanisOnPlayfield()Check whether this entity is on a playfieldvoidsleep(int ticks)Prevent this entity from performing any long running operation fortickssimulation ticks.StringtoString()
-
-
-
Field Detail
-
endOfLastEnqueuedOperation
protected CompletableFuture<Void> endOfLastEnqueuedOperation
The completable future representing the completion of the last enqueued operation.
-
-
Method Detail
-
getPosition
@InspectionAttribute(readOnly=true) public Position getPosition()
- Specified by:
getPositionin interfaceEntity- Returns:
- the position of this entity
- Throws:
EntityNotOnFieldException- if this entity is not on a playfield
-
getTextureHandle
protected abstract String getTextureHandle()
Get the texture handle, with which to get the texture for this entity.- Returns:
- the texture handle for the texture of this entity
-
getZPosition
protected abstract int getZPosition()
Get the z position of this entity.The z position is used to order entities on the same field.
- Returns:
- the z position of this entity.
-
getDrawInformation
public Drawable getDrawInformation()
- Specified by:
getDrawInformationin interfaceEntity- Returns:
- the information required to draw this entity; must not be null
- Throws:
EntityNotOnFieldException- if this entity is not on a playfield
-
initOnPlayfield
public void initOnPlayfield(Playfield playfield)
Description copied from interface:EntityMethod to initialize this entity after being added to the playfield.This method needs to be called by the playfield directly after the entity was added.
- Specified by:
initOnPlayfieldin interfaceEntity- Parameters:
playfield- The playfield this entity was added to; must not be null
-
isOnPlayfield
public boolean isOnPlayfield()
Check whether this entity is on a playfield- Returns:
- true if and only if this entity is on a playfield
-
getPlayfield
protected Playfield getPlayfield()
Get the playfield of this entity.- Returns:
- the playfield
- Throws:
EntityNotOnFieldException- if this entity is not on a playfield
-
getSimulation
protected Simulation getSimulation()
Get the simulation of this entity.- Returns:
- the simulation
- Throws:
EntityNotOnFieldException- if this entity is not on a playfieldIllegalStateException- if the playfield of this entity is not part of any simulation
-
sleep
public void sleep(int ticks)
Prevent this entity from performing any long running operation fortickssimulation ticks.Only operations that take
>= 1clock ticks to execute will be affected by this sleep.- Parameters:
ticks- numberof simulation ticks to pause; must be> 0- Throws:
IllegalArgumentException- if ticks is<= 0
-
enqueueToPerformNewOperation
protected void enqueueToPerformNewOperation(CompletableFuture<Void> endOfNewOperation)
Wait for the last enqueued long running operation to finish before allowing the new Operation to perform.Use this method only if you know what you are doing!
Due to the possibility of using an entity from multiple threads, it would be possible for an entity to have multiple long running operations (e.g. turning, walking) at once. To make sure that does not happen it is necessary to only allow one thread per entity to schedule an operation via the simulation clock. This method helps with that.
Call this method before scheduling an operation with the simulation clock.
This method synchronizes on the
operationQueueLockto make sure that only one thread can pass.The field
endOfLastEnqueuedOperationkeeps track of the operation that is currently performed by this entity.- Parameters:
endOfNewOperation- The completable future representing the operation to be performed (must be completed when the operation is completed)
-
-