-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor screen handling, networking & game simulation (#37)
- Loading branch information
Showing
243 changed files
with
6,257 additions
and
8,153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "pancake"] | ||
path = pancake | ||
url = https://github.com/eskalon/pancake.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
desktop/src/main/java/de/eskalon/gg/desktop/DesktopLauncher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.eskalon.gg.desktop; | ||
|
||
import com.badlogic.gdx.Files.FileType; | ||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; | ||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; | ||
|
||
import de.damios.guacamole.gdx.StartOnFirstThreadHelper; | ||
import de.eskalon.commons.core.EskalonApplicationStarter; | ||
import de.eskalon.commons.core.StartArguments; | ||
import de.eskalon.commons.core.StartArguments.StartArgumentsBuilder; | ||
import de.eskalon.gg.core.ProjektGGApplication; | ||
|
||
/** | ||
* Starts the application for the desktop-based builds. | ||
*/ | ||
public class DesktopLauncher { | ||
|
||
public static void main(String[] args) { | ||
StartOnFirstThreadHelper.executeOnValidJVM(() -> { | ||
/* Start arguments */ | ||
StartArgumentsBuilder startArgs = StartArguments.create(); | ||
|
||
if (args != null) { | ||
for (int i = 0; i < args.length; i++) { | ||
if (args[i].equalsIgnoreCase("--debug")) { | ||
startArgs.enableDebugLogging(); | ||
continue; | ||
} | ||
|
||
if (args[i].equalsIgnoreCase("--trace")) { | ||
startArgs.enableTraceLogging(); | ||
continue; | ||
} | ||
|
||
if (args[i].equalsIgnoreCase("--skip")) { | ||
startArgs.skipSplashScreen(); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
/* libGDX config */ | ||
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); | ||
config.setTitle(ProjektGGApplication.GAME_NAME); | ||
config.setWindowedMode(1280, 720); | ||
config.setResizable(false); | ||
config.useVsync(false); | ||
config.setForegroundFPS(120); | ||
config.setWindowIcon(FileType.Internal, "icon16.png", "icon32.png", | ||
"icon48.png"); | ||
|
||
/* Start the app */ | ||
try { | ||
new Lwjgl3Application( | ||
new EskalonApplicationStarter( | ||
ProjektGGApplication.GAME_NAME, | ||
ProjektGGApplication.class, startArgs.build()), | ||
config); | ||
} catch (Exception e) { | ||
System.err.println( | ||
"An unexpected error occurred while starting the game:"); | ||
e.printStackTrace(); | ||
System.exit(-1); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
engine/src/main/java/de/eskalon/commons/net/LockstepGameClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package de.eskalon.commons.net; | ||
|
||
import java.util.List; | ||
|
||
import com.esotericsoftware.kryonet.Listener.TypeListener; | ||
|
||
import de.eskalon.commons.net.packets.data.IPlayerAction; | ||
import de.eskalon.commons.net.packets.data.IReadyable; | ||
import de.eskalon.commons.net.packets.data.PlayerActionsWrapper; | ||
import de.eskalon.commons.net.packets.lockstep.C2SSendPlayerActionsPacket; | ||
import de.eskalon.commons.net.packets.lockstep.S2CActionsDistributionPacket; | ||
|
||
public abstract class LockstepGameClient<G, S, P extends IReadyable> | ||
extends ReadyableGameClient<G, S, P> { | ||
|
||
public LockstepGameClient() { | ||
super(); | ||
|
||
TypeListener typeListener = new TypeListener(); | ||
typeListener.addTypeHandler(S2CActionsDistributionPacket.class, | ||
(con, msg) -> { | ||
onAllActionsReceived(msg.getTurn(), msg.getActions()); | ||
}); | ||
client.addListener(typeListener); | ||
} | ||
|
||
public void sendActions(int turn, List<IPlayerAction> actions) { | ||
client.sendTCP(new C2SSendPlayerActionsPacket(turn, actions)); | ||
} | ||
|
||
/* --- METHODS FOR CHILD CLASSES --- */ | ||
public abstract void onAllActionsReceived(int turn, | ||
List<PlayerActionsWrapper> list); | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
engine/src/main/java/de/eskalon/commons/net/LockstepGameServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package de.eskalon.commons.net; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import com.badlogic.gdx.utils.IntMap; | ||
import com.esotericsoftware.kryonet.Listener.TypeListener; | ||
|
||
import de.damios.guacamole.gdx.log.Logger; | ||
import de.damios.guacamole.gdx.log.LoggerService; | ||
import de.eskalon.commons.net.data.ServerSettings; | ||
import de.eskalon.commons.net.packets.data.IReadyable; | ||
import de.eskalon.commons.net.packets.data.LobbyData; | ||
import de.eskalon.commons.net.packets.data.PlayerActionsWrapper; | ||
import de.eskalon.commons.net.packets.lockstep.C2SSendPlayerActionsPacket; | ||
import de.eskalon.commons.net.packets.lockstep.S2CActionsDistributionPacket; | ||
|
||
public abstract class LockstepGameServer<G, S, P extends IReadyable> | ||
extends ReadyableGameServer<G, S, P> { | ||
|
||
private static final Logger LOG = LoggerService | ||
.getLogger(LockstepGameServer.class); | ||
|
||
IntMap<List<PlayerActionsWrapper>> commandsForTurn = new IntMap<>(); | ||
|
||
public LockstepGameServer(ServerSettings serverSettings, | ||
LobbyData lobbyData) { | ||
super(serverSettings, lobbyData); | ||
|
||
TypeListener typeListener = new TypeListener(); | ||
typeListener.addTypeHandler(C2SSendPlayerActionsPacket.class, | ||
(con, msg) -> { | ||
PlayerActionsWrapper actionsWrapper = new PlayerActionsWrapper( | ||
(short) con.getArbitraryData(), msg.getCommands()); | ||
|
||
List<PlayerActionsWrapper> list = commandsForTurn | ||
.get(msg.getTurn()); | ||
if (list == null) { | ||
list = new ArrayList<>(); | ||
commandsForTurn.put(msg.getTurn(), list); | ||
} | ||
|
||
list.add(actionsWrapper); | ||
|
||
if (LoggerService.isTraceEnabled()) { | ||
LOG.trace( | ||
"[SERVER] Received actions of player %d for turn %d: %s", | ||
actionsWrapper.getPlayerId(), msg.getTurn(), | ||
actionsWrapper.getActions().stream().map( | ||
(o) -> o.getClass().getSimpleName()) | ||
.collect(Collectors.joining(", "))); | ||
} | ||
|
||
if (list.size() == lobbyData.getPlayers().size) { | ||
LOG.trace("[SERVER] All actions received for turn %d", | ||
msg.getTurn()); | ||
|
||
server.sendToAllTCP(new S2CActionsDistributionPacket( | ||
msg.getTurn(), list)); | ||
onAllActionsReceived(msg.getTurn(), list); | ||
commandsForTurn.remove(msg.getTurn()); | ||
} | ||
}); | ||
server.addListener(typeListener); | ||
} | ||
|
||
/* --- METHODS FOR CHILD CLASSES --- */ | ||
public abstract void onAllActionsReceived(int turn, | ||
List<PlayerActionsWrapper> list); | ||
|
||
} |
Oops, something went wrong.