20 package net.sf.gridarta.model.mapmodel;
22 import java.awt.Point;
27 import org.jetbrains.annotations.NotNull;
53 private final Point
point =
new Point();
59 private final Point
point2 =
new Point();
75 final int newWidth = newSize.getWidth();
76 final int oldWidth = oldSize.getWidth();
77 final int newHeight = newSize.getHeight();
78 final int oldHeight = oldSize.getHeight();
79 for (point.x = newWidth; point.x < oldWidth; point.x++) {
80 for (point.y = 0; point.y < oldHeight; point.y++) {
85 for (point.x = 0; point.x < newWidth; point.x++) {
86 for (point.y = newHeight; point.y < newHeight; point.y++) {
109 int maxLightRadius = 0;
110 for (
final G gameObject : mapSquare) {
111 final int lightRadius = gameObject.getLightRadius();
112 if (maxLightRadius < lightRadius) {
113 maxLightRadius = lightRadius;
116 setLightRadius(mapSquare, Math.min(maxLightRadius, MAX_LIGHT_RADIUS));
126 final int prevLightRadius = mapSquare.getLightRadius();
127 if (lightRadius == prevLightRadius) {
130 mapSquare.setLightRadius(lightRadius);
131 if (lightRadius < prevLightRadius) {
133 for (
int dx = -prevLightRadius; dx <= prevLightRadius; dx++) {
134 for (
int dy = -prevLightRadius; dy <= prevLightRadius; dy++) {
135 if (dx < -lightRadius || dx > lightRadius || dy < -lightRadius || dy > lightRadius || lightRadius == 0) {
136 point2.x = mapSquare.getMapX() + dx;
137 point2.y = mapSquare.getMapY() + dy;
141 }
catch (
final IndexOutOfBoundsException ignored) {
149 for (
int dx = -lightRadius; dx <= lightRadius; dx++) {
150 for (
int dy = -lightRadius; dy <= lightRadius; dy++) {
151 if (dx < -prevLightRadius || dx > prevLightRadius || dy < -prevLightRadius || dy > prevLightRadius || prevLightRadius == 0) {
152 point2.x = mapSquare.getMapX() + dx;
153 point2.y = mapSquare.getMapY() + dy;
156 }
catch (
final IndexOutOfBoundsException ignored) {
static final int MAX_LIGHT_RADIUS
The maximal supported light radius.
void addLightSource(@NotNull final MapSquare< G, A, R > mapSquare)
Adds a light emitting game object that affects this map square.
LightMapModelTracker(@NotNull final MapModel< G, A, R > mapModel)
Creates a new instance.
void removeLightSource(@NotNull final MapSquare< G, A, R > mapSquare)
Removes a light emitting game object that affects this map square.
final Point point2
A temporary point.
final Point point
A temporary point.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
void mapSizeChanging(@NotNull final Size2D newSize, @NotNull final Size2D oldSize)
Called whenever the tracked map is about to change size.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
GameObjects are the objects based on Archetypes found on maps.
void mapSquaresChanged(@NotNull final Iterable< MapSquare< G, A, R >> mapSquares)
Called whenever some game objects have changed.
final MapModel< G, A, R > mapModel
The tracked MapModel.
void updateLightRadius(@NotNull final MapSquare< G, A, R > mapSquare)
Recalculates information about light emitting game objects in a map square.
void setLightRadius(@NotNull final MapSquare< G, A, R > mapSquare, final int lightRadius)
Updates the light radius of a map square.
Tracks a MapModel for light emitting game objects.
Interface for MapArchObjects.
The class Size2D represents a 2d rectangular area.