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 SummaryFields Modifier and Type Field Description protected CompletableFuture<Void>endOfLastEnqueuedOperationThe completable future representing the completion of the last enqueued operation.
 - 
Constructor SummaryConstructors Constructor Description BasicEntity()
 - 
Method SummaryAll 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- 
endOfLastEnqueuedOperationprotected 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 interface- Entity
- Returns:
- the position of this entity
- Throws:
- EntityNotOnFieldException- if this entity is not on a playfield
 
 - 
getTextureHandleprotected 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
 
 - 
getZPositionprotected 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.
 
 - 
getDrawInformationpublic Drawable getDrawInformation() - Specified by:
- getDrawInformationin interface- Entity
- Returns:
- the information required to draw this entity; must not be null
- Throws:
- EntityNotOnFieldException- if this entity is not on a playfield
 
 - 
initOnPlayfieldpublic void initOnPlayfield(Playfield playfield) Description copied from interface:EntityMethod to initialize this entity after being added to the playfield.This method should not be called from anywhere other than the playfield implementation. This method needs to be called by the playfield directly before adding the entity to the field. - Specified by:
- initOnPlayfieldin interface- Entity
- Parameters:
- playfield- The playfield this entity was added to; must not be null
 
 - 
isOnPlayfieldpublic boolean isOnPlayfield() Check whether this entity is on a playfield- Returns:
- true if and only if this entity is on a playfield
 
 - 
getPlayfieldprotected Playfield getPlayfield() Get the playfield of this entity.- Returns:
- the playfield
- Throws:
- EntityNotOnFieldException- if this entity is not on a playfield
 
 - 
getSimulationprotected Simulation getSimulation() Get the simulation of this entity.- Returns:
- the simulation
- Throws:
- EntityNotOnFieldException- if this entity is not on a playfield
- IllegalStateException- if the playfield of this entity is not part of any simulation
 
 - 
sleeppublic 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
 
 - 
enqueueToPerformNewOperationprotected 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)
 
 
- 
 
-