Class PhysicsEngine

java.lang.Object
fr.r1r0r0.deltaengine.model.engines.PhysicsEngine
All Implemented Interfaces:
Engine, java.lang.Runnable

final class PhysicsEngine
extends java.lang.Object
implements Engine
A physical engine
  • Field Summary

    Fields
    Modifier and Type Field Description
    private MapLevel mapLevel  
    private long maxRunDelta  
    private double maxRunDeltaRatio  
    private int physicalRate  
    private static CollisionPositions[] POSITIONS_CHECK
    Explication de la mise en place des collisions entre une source et une target : la source est une entitite qui posssede une liste de points de collision qui par defaut correspondent aux points : topleft, topright, botleft, botright, center, centerleft, centerright, centertop, centerbot puis on va tester l appartenance d un de ces points dans la hitbox de la cible qui correspond a un minX maxX minY maxY
    private long previousRunTime  
  • Constructor Summary

    Constructors
    Constructor Description
    PhysicsEngine()
    Constructor
  • Method Summary

    Modifier and Type Method Description
    private Coordinates<java.lang.Double> calcNextPosition​(Coordinates<java.lang.Double> topLeft, Direction direction, double speed, double timeRatio)
    Return the next position of the object describe by a topLeft, a direction, a speed, and a delta of time
    boolean canGoToNextCell​(Entity entity, Direction direction)
    Return if the entity is able to move with the direction given
    private java.util.Set<Event> checkCollisions​(java.util.ArrayList<Entity> entities)
    Return a list of event providing from collisions between all entities in the collection given If there is a collision between 2 entity A and B, the list of event that will be return will contain the event from A to B and the event from B to A.
    void clearMap()
    Clear the current mapLevel
    private boolean fitOnCell​(Entity entity)
    Return if the entity fit on a cell
    void init()
    Initializer
    boolean isAvailableDirection​(Entity entity, Direction direction)
    Return if the entity can move with the direction given in argument
    private boolean isOnTarget​(Coordinates<java.lang.Double> topLeft, Dimension dimension, Coordinates<java.lang.Integer> target)  
    private boolean isValidNextPosition​(Entity entity, Coordinates<java.lang.Double> nextPosition)
    Returns if the next position of the entity is in a valid position in the mapLevel
    void run()
    Update the coordinate of all entity in the current mapLevel
    void setMap​(MapLevel mapLevel)
    Replace the current mapLevel with another
    void setMaxRunDelta​(int fps)
    Setter for the attribute maxRunDelta The new value of the attribute is calc by using the number of fps
    void setPhysicalRate​(int physicalRate)
    Setter for the attribute physicalRate
    private void updateCoordinates​(java.util.Collection<Entity> entities, double timeRatio)
    Update the coordinates of each entity in a collection of entity If the coordinates can not be update, because of an illegal movement, the direction of the entity is set to IDLE

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • POSITIONS_CHECK

      private static final CollisionPositions[] POSITIONS_CHECK
      Explication de la mise en place des collisions entre une source et une target : la source est une entitite qui posssede une liste de points de collision qui par defaut correspondent aux points : topleft, topright, botleft, botright, center, centerleft, centerright, centertop, centerbot puis on va tester l appartenance d un de ces points dans la hitbox de la cible qui correspond a un minX maxX minY maxY
    • mapLevel

      private MapLevel mapLevel
    • previousRunTime

      private long previousRunTime
    • maxRunDelta

      private long maxRunDelta
    • maxRunDeltaRatio

      private double maxRunDeltaRatio
    • physicalRate

      private int physicalRate
  • Constructor Details

    • PhysicsEngine

      public PhysicsEngine()
      Constructor
  • Method Details

    • init

      public void init()
      Initializer
      Specified by:
      init in interface Engine
    • run

      public void run()
      Update the coordinate of all entity in the current mapLevel
      Specified by:
      run in interface java.lang.Runnable
    • checkCollisions

      private java.util.Set<Event> checkCollisions​(java.util.ArrayList<Entity> entities)
      Return a list of event providing from collisions between all entities in the collection given If there is a collision between 2 entity A and B, the list of event that will be return will contain the event from A to B and the event from B to A.
      Parameters:
      entities - a collection of entity
    • updateCoordinates

      private void updateCoordinates​(java.util.Collection<Entity> entities, double timeRatio)
      Update the coordinates of each entity in a collection of entity If the coordinates can not be update, because of an illegal movement, the direction of the entity is set to IDLE
      Parameters:
      entities - a collection of entity
      timeRatio - a ratio of time used to calc the movement
    • isOnTarget

      private boolean isOnTarget​(Coordinates<java.lang.Double> topLeft, Dimension dimension, Coordinates<java.lang.Integer> target)
    • isAvailableDirection

      public boolean isAvailableDirection​(Entity entity, Direction direction)
      Return if the entity can move with the direction given in argument
      Parameters:
      entity - an entity
      direction - a direction
      Returns:
      if the entity can move with the direction given
    • calcNextPosition

      private Coordinates<java.lang.Double> calcNextPosition​(Coordinates<java.lang.Double> topLeft, Direction direction, double speed, double timeRatio)
      Return the next position of the object describe by a topLeft, a direction, a speed, and a delta of time
      Parameters:
      topLeft - a position topLeft of the object
      direction - the direction of the object
      speed - the speed of the object
      timeRatio - a ratio of time
      Returns:
      the next position of the object describe
    • canGoToNextCell

      public boolean canGoToNextCell​(Entity entity, Direction direction)
      Return if the entity is able to move with the direction given
      Parameters:
      entity - an entity
      direction - a direction
      Returns:
      if the entity is able to move with the direction given
    • fitOnCell

      private boolean fitOnCell​(Entity entity)
      Return if the entity fit on a cell
      Parameters:
      entity - an entity
      Returns:
      if the entity fit on a cell
    • isValidNextPosition

      private boolean isValidNextPosition​(Entity entity, Coordinates<java.lang.Double> nextPosition)
      Returns if the next position of the entity is in a valid position in the mapLevel
      Parameters:
      entity - an entity
      nextPosition - the next position of the entity
      Returns:
      if the position of the rectangle is valid in the mapLevel
    • setMap

      public void setMap​(MapLevel mapLevel)
      Replace the current mapLevel with another
      Parameters:
      mapLevel - a mapLevel
    • clearMap

      public void clearMap()
      Clear the current mapLevel
    • setMaxRunDelta

      public void setMaxRunDelta​(int fps)
      Setter for the attribute maxRunDelta The new value of the attribute is calc by using the number of fps
      Parameters:
      fps - the number of fps
    • setPhysicalRate

      public void setPhysicalRate​(int physicalRate)
      Setter for the attribute physicalRate
      Parameters:
      physicalRate - a physicalRate