Class AbstractCompositeEntity
- java.lang.Object
-
- de.extio.spacecraft.shared.model.entity.AbstractCompositeEntity
-
- All Implemented Interfaces:
HasPosition2
,HasPositionAndDimension2
,SpatialIndex2Capable
- Direct Known Subclasses:
DarkMatter
,DefaultCompositeEntity
,GenericRestrictedCompositeEntity
,ImageSurfaceCompositeEntity
,InfoCompositeEntity
,LootContainerCompositeEntity
,SpaceCraft
,SpaceObject
public abstract class AbstractCompositeEntity extends Object implements HasPositionAndDimension2, SpatialIndex2Capable
AbstractCompositeEntity is the root of all composite entities, providing full functionality to interact with the game world. Composite entities are managed by WorldManager and are populating the game world. A composite entity consists of several entities and forms a single unit in the game world.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractCompositeEntity.CollisionCalculationResult
Result of a collision calculationstatic class
AbstractCompositeEntity.DefaultDamageWaveDamageHandler
Implements default damage handling on a single tile.
-
Field Summary
Fields Modifier and Type Field Description protected CoordD2
accelerationVector
protected static Map<Integer,RgbaColor>
DAMAGE_COLORS
static Integer
DAMAGE_CONSUMER_BOTH
static Integer
DAMAGE_CONSUMER_ENTITY
static Integer
DAMAGE_CONSUMER_SHIELD
protected static CoordI2[]
DAMAGEWAVE_DIRECTIONS
protected CoordI2
dimension
protected boolean
dirty
protected EntityManager
entityManager
protected Fields
fields
protected boolean
fresh
protected int
lastMovement
protected static org.apache.logging.log4j.Logger
LOGGER
protected Map<UUID,Mesh>
meshes
protected CoordI2
position
protected boolean
positionDirty
protected CoordD2
precisePosition
protected CoordI2
prevPosition
protected CoordD2
prevVelocityVector
protected static RgbaColor
ROTATE_COLLISION_COLOR
protected boolean
splitEntityGroups
protected double
sumMassCached
protected int
sumMassCachedTurn
protected UUID
uuid
protected CoordD2
velocityVector
protected static double
VMAX_M_LB
protected static double
VMAX_M_UB
protected static double
VMAX_VEL_MAX
protected static double
VMAX_VEL_MIN
protected static double
VMAX_VEL_VAR
-
Constructor Summary
Constructors Constructor Description AbstractCompositeEntity()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accelerate(CoordD2 a)
Accelerates composite entity.AbstractCompositeEntity.CollisionCalculationResult
calculateCollision(Map.Entry<AbstractCompositeEntity,List<AbstractEntity>> collisionPartner)
Calculates the outcome of a collision between this composite and one or more other compositesdouble
calculateVMax()
Calculates the speed limit for this compositeCoordI2
compressDimension()
Compresses the dimension of this composite.void
create(UUID uuid, CoordI2 position, CoordI2 dimension)
Called upon initial creation of this composite entity.void
damageWave(GameSession gameSession, DamageWaveOptions damageWaveOptions, List<AbstractEntity> damagedEntities)
Distributes incoming damage on entities.
There are certain aspects relevant for the calculation:
* A tiles consists of several layered entities
* An entity only absorbs a certain amount of damage (plateaus), which is also dependent on the weapon
* A tile can be protected by shields
* Also shields have plateaus
* Damage that is not absorbed propagates to nearby tiles
* Damage cannot propagate through some tiles in certain directions, i.e.void
excludeDynamicSerializationPropertiesPermanentStorage(Map<String,Object> dynamicSerializationProperties)
This method provide the possibility to reset certain dynamic properties that are relevant at runtime but not relevant for storing it permanently to disk.CoordD2
getAccelerationVector()
CoordD2
getAnimationOffset()
String
getCompositeEntityFactoryClassName()
CoordI2
getDimension()
Spatial dimension of this compositeMap<String,Object>
getDynamicSerializationProperties(boolean incremental, UUID recipient)
Dynamic serialization properties are created when transferring data from server to client (or vice versa) as well as when persisting a composite to disk.Map<String,Object>
getDynamicSerializationPropertiesForSeparateTransfer(boolean incremental, UUID recipient)
Same concept as for getDynamicSerializationProperties(), but these properties are transferred separately.EntityManager
getEntityManager()
org.apache.commons.lang3.tuple.MutablePair<List<PhysicalEntity>,List<PhysicalEntity>>
getEntityNetworkConsolesCache()
Fields
getFields()
String
getLastEdited()
int
getLastRotation()
Edge2
getLastRotationDirection()
Map<UUID,Mesh>
getMeshes()
CoordI2
getPosition()
CoordD2
getPrecisePosition()
CoordI2
getPrevPosition()
UUID
getSceneTag()
Map<UUID,Integer>
getServerFieldsLastPublished()
Map<UUID,Integer>
getServerLastInViewPort()
Map<UUID,Integer>
getServerMeshesLastPublished()
Map<UUID,Integer>
getServerScannedBy()
UUID
getUuid()
UUID of this compositeCoordD2
getVelocityVector()
protected void
handleMove(GameSession gameSession)
Server side: Called on every turn twice (pass0 and pass1) to handle movement of this compositeprotected void
handleMoveApply(GameSession gameSession, CoordD2 newPositionPrecise)
Applies a new spatial position on this composite entityvoid
includeInSpatialIndex2ResultSet(long session)
boolean
isDirty()
boolean
isFresh()
boolean
isInSpatialIndex2ResultSet(long session)
boolean
isLocalInit()
boolean
isPositionDirty()
boolean
isRemoved()
boolean
isShadowed()
boolean
isSplitEntityGroups()
void
localCopy(AbstractCompositeEntity other)
Local copy of all fields that are not covered by update()void
localInit(EntityManager entityManager)
Local initialization of transient fields.void
onClientActionMessage(GameActionMessage message)
Client side: Callback when a GameActionMessage has been received that is addressed to this compositevoid
onClientDraw(List<RenderingBo> renderingBo)
Client side: Draw effects related to this composite entity.void
onClientFrame()
Client side: Called on each framevoid
onRemove()
This callback is called when this composite is removed from world manager.void
onServerActionMessage(GameSession gameSession, UUID sender, GameActionMessage message)
Server side: Callback when a GameActionMessage has been received that is addressed to this compositeprotected boolean
onServerCollision(GameSession gameSession, Map<AbstractCompositeEntity,List<AbstractEntity>> entityLevelCollisions)
Server side: Callback for additional logic when a collision happenedvoid
onServerTurnPass0(GameSession gameSession)
Server side: Called every turn to contain any logic related to this entitiy.void
onServerTurnPass1(GameSession gameSession)
Server side: Called every turn to contain any logic related to this entitiy.void
onServerTurnPass2(GameSession gameSession)
Server side: Called every turn to contain any logic related to this entitiy.protected AbstractCompositeEntity.CollisionCalculationResult
priorityCalculateCollision(Map.Entry<AbstractCompositeEntity,List<AbstractEntity>> collisionPartner)
Overrides the regular collision calculationvoid
resetFieldsForPermanentStorage()
This method provide the possibility to reset certain non-transient fields that are relevant at runtime but not relevant for storing it permanently to disk.void
resetStatic()
Resets static fields when a new game is initialized.void
restoreFieldsFromPermanentStorage()
Counterpart of resetFieldsForPermanentStorage() to initialize certain fields again after loading from disk.boolean
rotate(GameSession gameSession, Edge2 direction)
Rotates this composite entityvoid
setAccelerationVector(CoordD2 accelerationVector)
void
setCompositeEntityFactoryClassName(String compositeEntityFactoryClassName)
void
setDimension(CoordI2 dimension)
void
setDirty(boolean dirty)
void
setDynamicSerializationProperties(Map<String,Object> properties)
This is the counterpart of getDynamicSerializationProperties(), see the description there.void
setEntityManager(EntityManager entityManager)
void
setFresh(boolean fresh)
void
setLastEdited(String version)
void
setPosition(CoordI2 position)
Only use this setter to set the initial position right after WorldManager#create before the first Worldmanager#put.void
setPositionDirty(boolean positionDirty)
void
setPrecisePosition(CoordD2 precisePosition)
void
setPrevPosition(CoordI2 prevPosition)
void
setSceneTag(UUID sceneTag)
void
setServerFieldsLastPublished(Map<UUID,Integer> serverFieldsLastPublished)
void
setServerMeshesLastPublished(Map<UUID,Integer> meshesLastPublished)
void
setShadowed(boolean shadowed)
void
setSplitEntityGroups(boolean splitEntityGroups)
void
setUuid(UUID uuid)
void
setVelocityVector(CoordD2 velocityVector)
protected void
splitEntityGroups(GameSession gameSession)
Splits this composite entity by connected areas to several separated copies, e.g.double
sumMass()
Sums up the total mass of this compositevoid
update(AbstractCompositeEntity other)
Updates non-transient fields (i.e.
-
-
-
Field Detail
-
LOGGER
protected static final org.apache.logging.log4j.Logger LOGGER
-
DAMAGEWAVE_DIRECTIONS
protected static final CoordI2[] DAMAGEWAVE_DIRECTIONS
-
DAMAGE_CONSUMER_ENTITY
public static final Integer DAMAGE_CONSUMER_ENTITY
-
DAMAGE_CONSUMER_SHIELD
public static final Integer DAMAGE_CONSUMER_SHIELD
-
DAMAGE_CONSUMER_BOTH
public static final Integer DAMAGE_CONSUMER_BOTH
-
VMAX_VEL_MIN
protected static final double VMAX_VEL_MIN
- See Also:
- Constant Field Values
-
VMAX_VEL_MAX
protected static final double VMAX_VEL_MAX
- See Also:
- Constant Field Values
-
VMAX_VEL_VAR
protected static final double VMAX_VEL_VAR
- See Also:
- Constant Field Values
-
VMAX_M_LB
protected static final double VMAX_M_LB
- See Also:
- Constant Field Values
-
VMAX_M_UB
protected static final double VMAX_M_UB
- See Also:
- Constant Field Values
-
ROTATE_COLLISION_COLOR
protected static final RgbaColor ROTATE_COLLISION_COLOR
-
uuid
protected UUID uuid
-
position
protected CoordI2 position
-
dimension
protected CoordI2 dimension
-
velocityVector
protected CoordD2 velocityVector
-
accelerationVector
protected CoordD2 accelerationVector
-
precisePosition
protected CoordD2 precisePosition
-
prevPosition
protected CoordI2 prevPosition
-
splitEntityGroups
protected boolean splitEntityGroups
-
entityManager
protected transient EntityManager entityManager
-
fresh
protected transient boolean fresh
-
dirty
protected transient boolean dirty
-
positionDirty
protected transient boolean positionDirty
-
fields
protected transient Fields fields
-
prevVelocityVector
protected transient CoordD2 prevVelocityVector
-
lastMovement
protected transient int lastMovement
-
sumMassCached
protected transient double sumMassCached
-
sumMassCachedTurn
protected transient int sumMassCachedTurn
-
-
Method Detail
-
resetStatic
public void resetStatic()
Resets static fields when a new game is initialized. This method is not static to enable subclasses to add own logic (as java does not support overriding static methods)
-
localInit
public void localInit(EntityManager entityManager)
Local initialization of transient fields. See also create() and update()
-
localCopy
public void localCopy(AbstractCompositeEntity other)
Local copy of all fields that are not covered by update()
-
create
public void create(UUID uuid, CoordI2 position, CoordI2 dimension)
Called upon initial creation of this composite entity. This method is not called locally (i.e. when the composite has been transferred from server to client), so only initialize non-transient fields here. See also localInit()
-
update
public void update(AbstractCompositeEntity other)
Updates non-transient fields (i.e. when receiving an entity update from server or copying a composite entity)
-
getDynamicSerializationProperties
public Map<String,Object> getDynamicSerializationProperties(boolean incremental, UUID recipient)
Dynamic serialization properties are created when transferring data from server to client (or vice versa) as well as when persisting a composite to disk. These properties provide a way to implement complex serialization logic (i.e. views) and to distinguish between incremental and full updates.
-
getDynamicSerializationPropertiesForSeparateTransfer
public Map<String,Object> getDynamicSerializationPropertiesForSeparateTransfer(boolean incremental, UUID recipient)
Same concept as for getDynamicSerializationProperties(), but these properties are transferred separately. Use case are large data like thumbnails.
-
setDynamicSerializationProperties
public void setDynamicSerializationProperties(Map<String,Object> properties)
This is the counterpart of getDynamicSerializationProperties(), see the description there.
-
resetFieldsForPermanentStorage
public void resetFieldsForPermanentStorage()
This method provide the possibility to reset certain non-transient fields that are relevant at runtime but not relevant for storing it permanently to disk.
-
restoreFieldsFromPermanentStorage
public void restoreFieldsFromPermanentStorage()
Counterpart of resetFieldsForPermanentStorage() to initialize certain fields again after loading from disk.
-
excludeDynamicSerializationPropertiesPermanentStorage
public void excludeDynamicSerializationPropertiesPermanentStorage(Map<String,Object> dynamicSerializationProperties)
This method provide the possibility to reset certain dynamic properties that are relevant at runtime but not relevant for storing it permanently to disk.
-
onRemove
public void onRemove()
This callback is called when this composite is removed from world manager.
-
onClientFrame
public void onClientFrame()
Client side: Called on each frame
-
onClientDraw
public void onClientDraw(List<RenderingBo> renderingBo)
Client side: Draw effects related to this composite entity. All entities are already drawn separately by the game core.
-
onClientActionMessage
public void onClientActionMessage(GameActionMessage message)
Client side: Callback when a GameActionMessage has been received that is addressed to this composite
-
onServerActionMessage
public void onServerActionMessage(GameSession gameSession, UUID sender, GameActionMessage message)
Server side: Callback when a GameActionMessage has been received that is addressed to this composite- Parameters:
sender
- Player id of the sender or null if the message was sent on server side
-
onServerTurnPass0
public void onServerTurnPass0(GameSession gameSession)
Server side: Called every turn to contain any logic related to this entitiy. Pass0 is called at the beginning of the cycle before entity callbacks have been called.
-
onServerTurnPass1
public void onServerTurnPass1(GameSession gameSession)
Server side: Called every turn to contain any logic related to this entitiy. Pass1 is called after both entity callback passes have been called for all composites.
-
onServerTurnPass2
public void onServerTurnPass2(GameSession gameSession)
Server side: Called every turn to contain any logic related to this entitiy. Pass2 is called after pass1 was called on all composites.
-
sumMass
public double sumMass()
Sums up the total mass of this composite
-
handleMove
protected void handleMove(GameSession gameSession)
Server side: Called on every turn twice (pass0 and pass1) to handle movement of this composite
-
handleMoveApply
protected void handleMoveApply(GameSession gameSession, CoordD2 newPositionPrecise)
Applies a new spatial position on this composite entity
-
calculateCollision
public AbstractCompositeEntity.CollisionCalculationResult calculateCollision(Map.Entry<AbstractCompositeEntity,List<AbstractEntity>> collisionPartner)
Calculates the outcome of a collision between this composite and one or more other composites
-
priorityCalculateCollision
protected AbstractCompositeEntity.CollisionCalculationResult priorityCalculateCollision(Map.Entry<AbstractCompositeEntity,List<AbstractEntity>> collisionPartner)
Overrides the regular collision calculation
-
onServerCollision
protected boolean onServerCollision(GameSession gameSession, Map<AbstractCompositeEntity,List<AbstractEntity>> entityLevelCollisions)
Server side: Callback for additional logic when a collision happened
-
damageWave
public void damageWave(GameSession gameSession, DamageWaveOptions damageWaveOptions, List<AbstractEntity> damagedEntities)
Distributes incoming damage on entities.
There are certain aspects relevant for the calculation:
* A tiles consists of several layered entities
* An entity only absorbs a certain amount of damage (plateaus), which is also dependent on the weapon
* A tile can be protected by shields
* Also shields have plateaus
* Damage that is not absorbed propagates to nearby tiles
* Damage cannot propagate through some tiles in certain directions, i.e. walls, unless the entity is destroyed
* Propagated damage is dampened
* Damage handlers for tiles are pluggable
-
accelerate
public void accelerate(CoordD2 a)
Accelerates composite entity. Implements a speed limit based on mass. (I'm aware that in reality there is nothing like that in space well below relativistic levels - this is purely implemented because of gameplay considerations. Almost no space game allows to accelerate indefinitely!)- Parameters:
a
- Acceleration vector
-
calculateVMax
public double calculateVMax()
Calculates the speed limit for this composite
-
compressDimension
public CoordI2 compressDimension()
Compresses the dimension of this composite. A compressed composite has no unoccupied space around it's borders.
-
rotate
public boolean rotate(GameSession gameSession, Edge2 direction)
Rotates this composite entity
-
splitEntityGroups
protected void splitEntityGroups(GameSession gameSession)
Splits this composite entity by connected areas to several separated copies, e.g. breaking down a composite after some entities have been destroyed
-
getUuid
public UUID getUuid()
UUID of this composite
-
setUuid
public void setUuid(UUID uuid)
-
getPosition
public CoordI2 getPosition()
- Specified by:
getPosition
in interfaceHasPosition2
-
setPosition
public void setPosition(CoordI2 position)
Only use this setter to set the initial position right after WorldManager#create before the first Worldmanager#put. Directly setting the position in any other circumstance will make WorldManager inconsistent and will lead to errors. Use WorldManager#move instead.
-
getDimension
public CoordI2 getDimension()
Spatial dimension of this composite- Specified by:
getDimension
in interfaceHasPositionAndDimension2
-
setDimension
public void setDimension(CoordI2 dimension)
-
getVelocityVector
public CoordD2 getVelocityVector()
-
setVelocityVector
public void setVelocityVector(CoordD2 velocityVector)
-
getPrecisePosition
public CoordD2 getPrecisePosition()
-
setPrecisePosition
public void setPrecisePosition(CoordD2 precisePosition)
-
getEntityManager
public EntityManager getEntityManager()
-
setEntityManager
public void setEntityManager(EntityManager entityManager)
-
isFresh
public boolean isFresh()
-
setFresh
public void setFresh(boolean fresh)
-
isDirty
public boolean isDirty()
-
setDirty
public void setDirty(boolean dirty)
-
isLocalInit
public boolean isLocalInit()
-
isInSpatialIndex2ResultSet
public boolean isInSpatialIndex2ResultSet(long session)
- Specified by:
isInSpatialIndex2ResultSet
in interfaceSpatialIndex2Capable
-
includeInSpatialIndex2ResultSet
public void includeInSpatialIndex2ResultSet(long session)
- Specified by:
includeInSpatialIndex2ResultSet
in interfaceSpatialIndex2Capable
-
isSplitEntityGroups
public boolean isSplitEntityGroups()
-
setSplitEntityGroups
public void setSplitEntityGroups(boolean splitEntityGroups)
-
getAnimationOffset
public CoordD2 getAnimationOffset()
-
isRemoved
public boolean isRemoved()
-
getFields
public Fields getFields()
-
getPrevPosition
public CoordI2 getPrevPosition()
-
setPrevPosition
public void setPrevPosition(CoordI2 prevPosition)
-
getAccelerationVector
public CoordD2 getAccelerationVector()
-
setAccelerationVector
public void setAccelerationVector(CoordD2 accelerationVector)
-
isShadowed
public boolean isShadowed()
-
setShadowed
public void setShadowed(boolean shadowed)
-
isPositionDirty
public boolean isPositionDirty()
-
setPositionDirty
public void setPositionDirty(boolean positionDirty)
-
getLastRotation
public int getLastRotation()
-
getLastRotationDirection
public Edge2 getLastRotationDirection()
-
setServerMeshesLastPublished
public void setServerMeshesLastPublished(Map<UUID,Integer> meshesLastPublished)
-
getCompositeEntityFactoryClassName
public String getCompositeEntityFactoryClassName()
-
setCompositeEntityFactoryClassName
public void setCompositeEntityFactoryClassName(String compositeEntityFactoryClassName)
-
setServerFieldsLastPublished
public void setServerFieldsLastPublished(Map<UUID,Integer> serverFieldsLastPublished)
-
getLastEdited
public String getLastEdited()
-
setLastEdited
public void setLastEdited(String version)
-
getSceneTag
public UUID getSceneTag()
-
setSceneTag
public void setSceneTag(UUID sceneTag)
-
getEntityNetworkConsolesCache
public org.apache.commons.lang3.tuple.MutablePair<List<PhysicalEntity>,List<PhysicalEntity>> getEntityNetworkConsolesCache()
-
-