Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/game/MapSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author ArchDemon
*/
public final class MapSelector {

private static final Logger logger = System.getLogger(MapSelector.class.getName());

private final List<GameMapContainer> skirmishMaps = new ArrayList<>();
Expand Down
584 changes: 199 additions & 385 deletions src/toniarts/openkeeper/game/controller/GameController.java

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions src/toniarts/openkeeper/game/controller/GameTimeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2014-2025 OpenKeeper
*
* OpenKeeper is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenKeeper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
package toniarts.openkeeper.game.controller;

import toniarts.openkeeper.utils.GameTimeCounter;

/**
*
* @author ArchDemon
*/
public final class GameTimeController extends GameTimeCounter implements IGameTimer {

private long ticks;

@Override
public void start() {
ticks = 0;
timeElapsed = 0.0;
}

@Override
public void stop() {
// nope
}

@Override
public void processTick(float tpf) {
super.processTick(tpf);
ticks++;
}

@Override
public double getGameTime() {
return timeElapsed;
}
}
37 changes: 19 additions & 18 deletions src/toniarts/openkeeper/game/controller/GameWorldController.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.SequencedMap;
import java.util.Set;
import java.util.SortedMap;
import java.util.stream.Collectors;
Expand All @@ -91,13 +92,12 @@
* @author Toni Helenius <helenius.toni@gmail.com>
*/
public final class GameWorldController implements IGameWorldController, IPlayerActions {

private static final System.Logger logger = System.getLogger(GameWorldController.class.getName());

/**
* When dealing with gold... We currently better lock it. Logic stuff
* happens in single thread. But player actions are prosessed in real time
* by possibly other threads. We must not lose any gold from the world.
* When dealing with gold... We currently better lock it. Logic stuff happens in single thread. But player
* actions are prosessed in real time by possibly other threads. We must not lose any gold from the world.
*/
public static final Object GOLD_LOCK = new Object();

Expand All @@ -110,23 +110,28 @@ public final class GameWorldController implements IGameWorldController, IPlayerA
private IShotsController shotsController;
private IEntityPositionLookup entityPositionLookup;
private final Map<Short, IPlayerController> playerControllers;
private final SortedMap<Short, Keeper> players;
private final Map<Short, Keeper> players;
private final IGameTimer gameTimer;

private IMapController mapController;
private final Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings;
private final SafeArrayList<PlayerActionListener> listeners = new SafeArrayList<>(PlayerActionListener.class);

public GameWorldController(KwdFile kwdFile, EntityData entityData, Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings, SortedMap<Short, Keeper> players, Map<Short, IPlayerController> playerControllers, IGameTimer gameTimer) {
this.kwdFile = kwdFile;
public GameWorldController(IGameController gameController, ILevelInfo levelInfo, EntityData entityData,
Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings,
Map<Short, IPlayerController> playerControllers, IGameTimer gameTimer) {

this.kwdFile = levelInfo.getLevelData();
this.entityData = entityData;
this.gameSettings = gameSettings;
this.gameTimer = gameTimer;
this.playerControllers = playerControllers;
this.players = players;
this.players = levelInfo.getPlayers();

this.createNewGame(gameController, levelInfo);
}

public void createNewGame(IGameController gameController, ILevelInfo levelInfo) {
private void createNewGame(IGameController gameController, ILevelInfo levelInfo) {

// Load objects
objectsController = new ObjectsController(kwdFile, entityData, gameSettings, gameTimer, gameController, levelInfo);
Expand Down Expand Up @@ -189,8 +194,7 @@ private void initPlayerRooms() {
}

/**
* Add a lump sum of gold to a player, distributes the gold to the available
* rooms
* Add a lump sum of gold to a player, distributes the gold to the available rooms
*
* @param playerId for the player
* @param sum the gold sum
Expand All @@ -204,8 +208,7 @@ public int addGold(short playerId, int sum) {
}

/**
* Add a lump sum of gold to a player, distributes the gold to the available
* rooms
* Add a lump sum of gold to a player, distributes the gold to the available rooms
*
* @param playerId for the player
* @param p a point where to drop the gold, can be {@code null}
Expand Down Expand Up @@ -598,11 +601,9 @@ private void putToKeeperHand(PlayerHandControl playerHandControl, EntityId entit
playerHandControl.push(entity);

/**
* TODO: Basically here we can have a concurrency problem, especially
* visible with things that have AI. The AI or other systems may be
* still processing and manipulating stuff. One way to fix would be to
* add this to game loop queue to be executed. That would introduce a
* delay though...
* TODO: Basically here we can have a concurrency problem, especially visible with things that have
* AI. The AI or other systems may be still processing and manipulating stuff. One way to fix would be
* to add this to game loop queue to be executed. That would introduce a delay though...
*/
// Lose the position component on the entity, do it here since we have the knowledge on locations etc. keep the "hand" simple
// And also no need to create a system for this which saves resources
Expand Down
8 changes: 5 additions & 3 deletions src/toniarts/openkeeper/game/controller/IGameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

import com.simsilica.es.EntityId;
import java.util.Collection;
import java.util.Map;
import toniarts.openkeeper.game.data.GameResult;
import toniarts.openkeeper.game.logic.IEntityPositionLookup;
import toniarts.openkeeper.game.navigation.INavigationService;
import toniarts.openkeeper.game.task.ITaskManager;
import toniarts.openkeeper.tools.convert.map.Variable;

/**
* Game controller. Controls the game
Expand Down Expand Up @@ -50,13 +52,13 @@ public interface IGameController {

IPlayerController getPlayerController(short playerId);

Collection<IPlayerController> getPlayerControllers();
Map<Short, IPlayerController> getPlayerControllers();

ITaskManager getTaskManager();

void pauseGame();
ILevelInfo getLevelInfo();

void resumeGame();
float getLevelVariable(Variable.MiscVariable.MiscType variable);

/**
* End the game (for one player)
Expand Down
3 changes: 2 additions & 1 deletion src/toniarts/openkeeper/game/controller/ILevelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Map;
import toniarts.openkeeper.game.data.ActionPoint;
import toniarts.openkeeper.game.data.GameTimer;
import toniarts.openkeeper.game.data.Keeper;
Expand All @@ -39,7 +40,7 @@ public interface ILevelInfo {

Keeper getPlayer(short playerId);

Collection<Keeper> getPlayers();
Map<Short, Keeper> getPlayers();

int getFlag(int id);

Expand Down
39 changes: 18 additions & 21 deletions src/toniarts/openkeeper/game/controller/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,24 @@ public final class MapController extends Container implements IMapController {
/**
* Load map data from a KWD file straight (new game)
*
* @param kwdFile the KWD file
* @param kwdFile the KWD file
* @param objectsController objects controller
* @param gameSettings the game settings
* @param gameSettings the game settings
* @param gameTimer
* @param entityData
* @param levelInfo
*/
public MapController(KwdFile kwdFile, IObjectsController objectsController, Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings,
public MapController(KwdFile kwdFile, IObjectsController objectsController,
Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings,
IGameTimer gameTimer, EntityData entityData, ILevelInfo levelInfo) {

this.kwdFile = kwdFile;
this.objectsController = objectsController;
this.mapData = new MapData(kwdFile, entityData, levelInfo.getPlayers());
this.mapData = new MapData(kwdFile, entityData, levelInfo.getPlayers().values());
this.gameSettings = gameSettings;
this.gameTimer = gameTimer;
this.entityData = entityData;
this.mapInformation = new MapInformation(mapData, kwdFile, levelInfo.getPlayers());
this.mapInformation = new MapInformation(mapData, kwdFile, levelInfo.getPlayers().values());
this.levelInfo = levelInfo;

// Load rooms
Expand Down Expand Up @@ -145,19 +147,16 @@ private void loadRoom(Point p) {

// TODO: A bit of a design problem here
/**
* Unclear responsibilities between the world and map controller.
* Also a result of how we handle the building and selling by
* destroying rooms.
* But at least keep anyone who is listening intact
* Unclear responsibilities between the world and map controller. Also a result of how we handle the
* building and selling by destroying rooms. But at least keep anyone who is listening intact
*/
notifyOnBuild(roomController.getRoomInstance().getOwnerId(), roomController);
}

/**
* Find the room starting from a certain point, rooms are never diagonally
* attached
* Find the room starting from a certain point, rooms are never diagonally attached
*
* @param p starting point
* @param p starting point
* @param roomInstance the room instance
*/
private void findRoom(Point p, RoomInstance roomInstance) {
Expand Down Expand Up @@ -342,7 +341,7 @@ public Collection<IRoomController> getRoomControllers() {
@Override
public IRoomController getRoomControllerByCoordinates(Point p) {
IMapTileInformation tile = getMapData().getTile(p);
if(tile == null) {
if (tile == null) {
return null;
}

Expand Down Expand Up @@ -373,10 +372,8 @@ public void removeRoomInstances(EntityId... instances) {

// TODO: A bit of a design problem here
/**
* Unclear responsibilities between the world and map controller.
* Also a result of how we handle the building and selling by
* destroying rooms.
* But at least keep anyone who is listening intact
* Unclear responsibilities between the world and map controller. Also a result of how we handle
* the building and selling by destroying rooms. But at least keep anyone who is listening intact
*/
notifyOnSold(roomController.getRoomInstance().getOwnerId(), roomController);
}
Expand All @@ -386,7 +383,7 @@ public void removeRoomInstances(EntityId... instances) {
* Get rooms by function.<br> FIXME: Should the player have ready lists?
*
* @param objectType the function
* @param playerId the player id, can be null
* @param playerId the player id, can be null
* @return list of rooms that match the criteria
*/
@Override
Expand Down Expand Up @@ -532,7 +529,7 @@ public int damageTile(Point point, short playerId, ICreatureController creature)
/**
* Heal a tile
*
* @param point the point
* @param point the point
* @param playerId the player applying the healing
*/
@Override
Expand Down Expand Up @@ -593,7 +590,7 @@ public void healTile(Point point, short playerId) {
/**
* Damage a room
*
* @param point tile coordinate
* @param point tile coordinate
* @param playerId for the player
*/
private void damageRoom(Point point, short playerId) {
Expand Down Expand Up @@ -760,7 +757,7 @@ public void stop() {
}

@Override
public void processTick(float tpf, double gameTime) {
public void processTick(float tpf) {
this.update(tpf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @author Toni Helenius <helenius.toni@gmail.com>
*/
public final class ChickenController extends EntityController implements IChickenController {

private static final Logger logger = System.getLogger(ChickenController.class.getName());

private final INavigationService navigationService;
Expand Down Expand Up @@ -158,7 +158,7 @@ public void start() {
}

@Override
public void processTick(float tpf, double gameTime) {
public void processTick(float tpf) {

/**
* Hmm, I'm not sure how to do this, this is not ideal either, how to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ public void start() {
}

@Override
public void processTick(float tpf, double gameTime) {
public void processTick(float tpf) {

/**
* Hmm, I'm not sure how to do this, this is not ideal either, how to
Expand Down
6 changes: 2 additions & 4 deletions src/toniarts/openkeeper/game/logic/ChickenAiSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,16 @@ public ChickenAiSystem(EntityData entityData, IObjectsController objectsControll
}

@Override
public void processTick(float tpf, double gameTime) {

public void processTick(float tpf) {
// Add new & remove old
if (chickenEntities.applyChanges()) {
processDeletedEntities(chickenEntities.getRemovedEntities());

processAddedEntities(chickenEntities.getAddedEntities());
}

// Process ticks
for (IChickenController creatureController : chickenControllers.getArray()) {
creatureController.processTick(tpf, gameTime);
creatureController.processTick(tpf);
}

// This is shorthand for managing also the view state.... Not sure if smart or not
Expand Down
Loading
Loading