Class LocationTracker
- java.lang.Object
-
- ch.sahits.game.openpatrician.engine.sea.LocationTracker
-
- All Implemented Interfaces:
ILocationTracker
@Component @Lazy public class LocationTracker extends java.lang.Object implements ILocationTracker
Component that helps split up the amount of ships into segements of the navigable map. This reduces the omount of ships that need to be checked if a ship nearby is searched.- Author:
- Andi Hotz, (c) Sahits GmbH, 2015 Created on Dec 13, 2015
-
-
Field Summary
Fields Modifier and Type Field Description private AIPlayerList
aiPlayers
private com.google.common.eventbus.AsyncEventBus
clientServerEventBus
private static org.slf4j.Logger
LOGGER
private IMap
map
private javafx.geometry.Dimension2D
mapDimension
private PlayerList
players
protected com.google.common.collect.Interner<javafx.geometry.Point2D>
pointInterner
private double
segmentEdgeHeigth
private double
segmentEdgeWidth
private java.util.List<java.lang.ref.WeakReference<INavigableVessel>>[][]
segments
private com.google.common.eventbus.EventBus
syncServerClientEventBus
-
Constructor Summary
Constructors Constructor Description LocationTracker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(INavigableVessel ship)
Add a shipt to the location tracker.(package private) int[]
calculateIndices(javafx.geometry.Point2D location)
(package private) int[]
calculateRowsAndColumnsNeeded(int numberOfImages, javafx.geometry.Dimension2D containerSize)
Calculate the number of segments the image is partitioned intoprivate javafx.geometry.Point2D
getPointOnMap(double x, double y)
Ensure that the point is on the map.java.util.List<INavigableVessel>
getShipsInSegment(javafx.geometry.Point2D location)
java.util.List<INavigableVessel>
getShipsInSegments(javafx.geometry.Point2D location, int radius)
void
handleGameLoad(GameStateChange gameStateChange)
void
handleShipMove(ShipPositionUpdateEvent event)
(package private) void
initialize()
void
remove(INavigableVessel ship)
private void
unregister()
void
updateSegmentSize(int nbShips)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
map
@Autowired private IMap map
-
clientServerEventBus
@Autowired @Qualifier("serverClientEventBus") private com.google.common.eventbus.AsyncEventBus clientServerEventBus
-
syncServerClientEventBus
@Autowired @Qualifier("syncServerClientEventBus") private com.google.common.eventbus.EventBus syncServerClientEventBus
-
pointInterner
@Autowired protected com.google.common.collect.Interner<javafx.geometry.Point2D> pointInterner
-
aiPlayers
@Autowired private AIPlayerList aiPlayers
-
players
@Autowired private PlayerList players
-
mapDimension
private javafx.geometry.Dimension2D mapDimension
-
segmentEdgeWidth
private double segmentEdgeWidth
-
segmentEdgeHeigth
private double segmentEdgeHeigth
-
segments
private java.util.List<java.lang.ref.WeakReference<INavigableVessel>>[][] segments
-
-
Method Detail
-
initialize
@PostConstruct void initialize()
-
unregister
@PreDestroy private void unregister()
-
updateSegmentSize
public void updateSegmentSize(int nbShips)
-
calculateIndices
int[] calculateIndices(javafx.geometry.Point2D location)
-
add
public void add(INavigableVessel ship)
Description copied from interface:ILocationTracker
Add a shipt to the location tracker.- Specified by:
add
in interfaceILocationTracker
- Parameters:
ship
- to be added.
-
remove
public void remove(INavigableVessel ship)
-
getShipsInSegment
public java.util.List<INavigableVessel> getShipsInSegment(javafx.geometry.Point2D location)
-
getShipsInSegments
public java.util.List<INavigableVessel> getShipsInSegments(javafx.geometry.Point2D location, int radius)
-
getPointOnMap
private javafx.geometry.Point2D getPointOnMap(double x, double y)
Ensure that the point is on the map.- Parameters:
x
- coordinate on the mapy
- coordinate on the map- Returns:
- Point representing the point on the map.
-
handleShipMove
public void handleShipMove(ShipPositionUpdateEvent event)
-
calculateRowsAndColumnsNeeded
int[] calculateRowsAndColumnsNeeded(int numberOfImages, javafx.geometry.Dimension2D containerSize)
Calculate the number of segments the image is partitioned into- Parameters:
numberOfImages
- target number of segmentscontainerSize
- dimension of the image- Returns:
- array of length: index 0: nbRows, index 1: nbCols
-
handleGameLoad
public void handleGameLoad(GameStateChange gameStateChange)
-
-