Initial implementation of NetworkActions multiplayer structure
After Width: | Height: | Size: 67 KiB |
After Width: | Height: | Size: 8.3 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.3 KiB |
After Width: | Height: | Size: 59 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 10 KiB |
|
@ -3,8 +3,8 @@ apply plugin: "java"
|
|||
sourceCompatibility = 1.7
|
||||
|
||||
dependencies {
|
||||
compile files("lib/voxel_engine_lib.jar")
|
||||
implementation files("lib/kryonet-2.21-all.jar")
|
||||
compile files("./lib/voxel_engine_lib.jar")
|
||||
implementation files("./lib/kryonet-2.21-all.jar")
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.badlogic.gdx.Gdx;
|
|||
import com.badlogic.gdx.InputMultiplexer;
|
||||
import com.badlogic.gdx.graphics.FPSLogger;
|
||||
import com.badlogic.gdx.physics.bullet.Bullet;
|
||||
import com.emamaker.amazeing.manager.managers.GameManager;
|
||||
import com.emamaker.amazeing.manager.GameManager;
|
||||
import com.emamaker.amazeing.manager.managers.GameManagerLocal;
|
||||
import com.emamaker.amazeing.manager.network.GameClient;
|
||||
import com.emamaker.amazeing.manager.network.GameServer;
|
||||
|
@ -51,7 +51,7 @@ public class AMazeIng extends Game {
|
|||
Bullet.init();
|
||||
|
||||
// Set windowed resolution
|
||||
Gdx.graphics.setWindowedMode(640, 480);
|
||||
Gdx.graphics.setWindowedMode(1280, 720);
|
||||
|
||||
// Enable on-screen keyboard for mobile devices
|
||||
// Gdx.input.setOnscreenKeyboardVisible(true);
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
package com.emamaker.amazeing.manager.managers;
|
||||
package com.emamaker.amazeing.manager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
|
@ -6,7 +10,6 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
|
|||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.AMazeIng.Platform;
|
||||
import com.emamaker.amazeing.manager.GameType;
|
||||
import com.emamaker.amazeing.maze.MazeGenerator;
|
||||
import com.emamaker.amazeing.maze.settings.MazeSettings;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
|
@ -16,13 +19,9 @@ import com.emamaker.amazeing.player.powerups.PowerUps;
|
|||
import com.emamaker.voxelengine.block.CellId;
|
||||
import com.emamaker.voxelengine.player.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class GameManager {
|
||||
|
||||
AMazeIng main;
|
||||
protected AMazeIng main;
|
||||
public MazeGenerator mazeGen;
|
||||
|
||||
public boolean gameStarted = false;
|
||||
|
@ -71,8 +70,6 @@ public class GameManager {
|
|||
if (!players.contains(p))
|
||||
players.add(p);
|
||||
|
||||
// Finally delete players. A separated step is needed to remove the risk of a
|
||||
// ConcurrentModificationException
|
||||
for (MazePlayer p : toDelete) {
|
||||
p.dispose();
|
||||
players.remove(p);
|
||||
|
@ -102,20 +99,19 @@ public class GameManager {
|
|||
}
|
||||
|
||||
public void addTouchScreenInput() {
|
||||
if (getShowGame()) {
|
||||
stage.clear();
|
||||
if (AMazeIng.PLATFORM == Platform.ANDROID)
|
||||
for (MazePlayer p : players) {
|
||||
if (p instanceof MazePlayerLocal)
|
||||
stage.addActor(((MazePlayerLocal) p).tctrl);
|
||||
if (getShowGame() && AMazeIng.isMobile()) {
|
||||
for (MazePlayer p : players) {
|
||||
if (p instanceof MazePlayerLocal) {
|
||||
stage.addActor(((MazePlayerLocal) p).tctrl);
|
||||
stage.addActor(((MazePlayerLocal) p).touchpadPowerUp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hudUpdate() {
|
||||
resetCamera();
|
||||
setCamera(new Vector3(MazeSettings.MAZEX / 2, (MazeSettings.MAZEX + MazeSettings.MAZEZ) * 0.45f,
|
||||
setCamera(new Vector3((MazeSettings.MAZEX + 1) / 2, (MazeSettings.MAZEX + MazeSettings.MAZEZ) * 0.45f,
|
||||
MazeSettings.MAZEZ / 2 - 1), new Vector3(0, -90, 0));
|
||||
|
||||
stage.act();
|
||||
|
@ -184,6 +180,10 @@ public class GameManager {
|
|||
public void setFinished() {
|
||||
anyoneWon = true;
|
||||
gameStarted = false;
|
||||
|
||||
for (MazePlayer p : players)
|
||||
p.disablePowerUp();
|
||||
|
||||
}
|
||||
|
||||
public boolean getFinished() {
|
|
@ -3,50 +3,63 @@ package com.emamaker.amazeing.manager.managers;
|
|||
import java.util.Set;
|
||||
|
||||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.GameManager;
|
||||
import com.emamaker.amazeing.manager.GameType;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.emamaker.amazeing.ui.screens.PreGameScreen;
|
||||
|
||||
public class GameManagerClient extends GameManager {
|
||||
public class GameManagerClient extends GameManager {
|
||||
|
||||
public GameManagerClient() {
|
||||
super(AMazeIng.getMain(), GameType.CLIENT);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateMaze(Set<MazePlayer> pl, int todraw[][]) {
|
||||
super.generateMaze(pl, todraw);
|
||||
addTouchScreenInput();
|
||||
showed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void inGameUpdate() {
|
||||
super.inGameUpdate();
|
||||
|
||||
|
||||
renderWorld();
|
||||
hudUpdate();
|
||||
|
||||
|
||||
main.world.modelBatch.begin(main.world.cam);
|
||||
|
||||
renderPlayers();
|
||||
renderPowerUps();
|
||||
|
||||
main.world.modelBatch.end();
|
||||
}
|
||||
|
||||
boolean showed = false;
|
||||
|
||||
@Override
|
||||
public void generalUpdate() {
|
||||
super.generalUpdate();
|
||||
if (getFinished() && !showed) {
|
||||
System.out.println("Game finished on client!");
|
||||
if (main.server.isRunning())
|
||||
((PreGameScreen) main.uiManager.preGameScreen).setGameType(GameType.SERVER);
|
||||
else
|
||||
((PreGameScreen) main.uiManager.preGameScreen).setGameType(GameType.CLIENT);
|
||||
|
||||
if (getFinished()) {
|
||||
main.setScreen(main.uiManager.preGameScreen);
|
||||
showed = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Protecting against myself since this feature doesn't exist yet
|
||||
// Protecting against myself since this feature doesn't exist yet
|
||||
@Override
|
||||
public void assignPowerUps() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkWin() { }
|
||||
|
||||
public void checkWin() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.emamaker.amazeing.manager.managers;
|
|||
import java.util.Set;
|
||||
|
||||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.GameManager;
|
||||
import com.emamaker.amazeing.manager.GameType;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
|
||||
|
@ -20,28 +21,38 @@ public class GameManagerLocal extends GameManager {
|
|||
mazeGen.setupEndPoint();
|
||||
clearPowerUps();
|
||||
spawnPowerUps();
|
||||
addTouchScreenInput();
|
||||
|
||||
if (todraw != null && getShowGame())
|
||||
mazeGen.show(todraw);
|
||||
|
||||
showed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inGameUpdate() {
|
||||
super.inGameUpdate();
|
||||
|
||||
assignPowerUps();
|
||||
|
||||
|
||||
renderWorld();
|
||||
hudUpdate();
|
||||
|
||||
|
||||
main.world.modelBatch.begin(main.world.cam);
|
||||
|
||||
renderPlayers();
|
||||
renderPowerUps();
|
||||
|
||||
main.world.modelBatch.end();
|
||||
|
||||
if (getFinished())
|
||||
|
||||
}
|
||||
|
||||
boolean showed = false;
|
||||
|
||||
@Override
|
||||
public void generalUpdate() {
|
||||
if (getFinished() && !showed) {
|
||||
main.setScreen(main.uiManager.playersScreen);
|
||||
showed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,12 @@ package com.emamaker.amazeing.manager.managers;
|
|||
import java.util.Set;
|
||||
|
||||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.GameManager;
|
||||
import com.emamaker.amazeing.manager.GameType;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.emamaker.amazeing.ui.screens.PreGameScreen;
|
||||
|
||||
public class GameManagerServer extends GameManager {
|
||||
|
||||
|
||||
public GameManagerServer() {
|
||||
super(AMazeIng.getMain(), GameType.SERVER);
|
||||
}
|
||||
|
@ -23,30 +22,24 @@ public class GameManagerServer extends GameManager {
|
|||
clearPowerUps();
|
||||
spawnPowerUps();
|
||||
|
||||
if (todraw != null && getShowGame())
|
||||
if (todraw != null)
|
||||
mazeGen.show(todraw);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void inGameUpdate() {
|
||||
super.inGameUpdate();
|
||||
|
||||
assignPowerUps();
|
||||
|
||||
if (getFinished()) {
|
||||
((PreGameScreen) main.uiManager.preGameScreen).setGameType(GameType.SERVER);
|
||||
main.setScreen(main.uiManager.preGameScreen);
|
||||
}
|
||||
assignPowerUps();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void assignPowerUps() {
|
||||
if (players != null && !players.isEmpty())
|
||||
for (MazePlayer p : players) {
|
||||
main.server.removePowerUp(assignPowerUp(p));
|
||||
}
|
||||
// if (players != null && !players.isEmpty())
|
||||
// for (MazePlayer p : players) {
|
||||
// main.server.removePowerUp(assignPowerUp(p));
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,42 +3,35 @@ package com.emamaker.amazeing.manager.network;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.badlogic.gdx.math.Quaternion;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
|
||||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.managers.GameManagerClient;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.AddNewPlayer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.AddPowerUp;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.LoginAO;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.LoginAO2;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.RemovePlayer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.RemovePowerUp;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.StartGame;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdatePlayerTransform;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdatePlayerTransformServer;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.game.NACGameStatusUpdate;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.game.NACServerClosed;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.game.NACUpdateMap;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.login.NACLoginAO;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.login.NACLoginAO2;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.login.NACRemovePlayer;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.player.NACUpdateOtherPlayerPos;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.player.NACUpdatePlayerPosForced;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.player.NACUpdatePlayersPos;
|
||||
import com.emamaker.amazeing.maze.settings.MazeSettings;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.emamaker.amazeing.player.MazePlayerLocal;
|
||||
import com.emamaker.amazeing.player.MazePlayerRemote;
|
||||
import com.emamaker.amazeing.player.PlayerUtils;
|
||||
import com.emamaker.amazeing.player.powerups.PowerUp;
|
||||
import com.emamaker.amazeing.player.powerups.PowerUps;
|
||||
import com.esotericsoftware.kryonet.Client;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class GameClient extends NetworkHandler {
|
||||
|
||||
Client client;
|
||||
public Client client;
|
||||
String addr;
|
||||
|
||||
boolean updateMobilePlayers = false;
|
||||
|
||||
boolean startGame = false;
|
||||
String map = "";
|
||||
|
||||
ArrayList<String> localPlayers = new ArrayList<String>();
|
||||
public CopyOnWriteArrayList<String> localPlayers = new CopyOnWriteArrayList<String>();
|
||||
|
||||
// Returns true if the server started successfully
|
||||
public boolean start(String addr_, int port_) {
|
||||
|
@ -52,14 +45,15 @@ public class GameClient extends NetworkHandler {
|
|||
// registered by the same method for both the client and server.
|
||||
NetworkCommon.register(client);
|
||||
client.start();
|
||||
client.addListener(connectionListener);
|
||||
client.connect(5000, addr, port, port + 1);
|
||||
|
||||
gameManager = new GameManagerClient();
|
||||
|
||||
if (AMazeIng.isMobile())
|
||||
updateMobilePlayers = false;
|
||||
updateMobilePlayers = true;
|
||||
|
||||
registerActions();
|
||||
startDefaultActions();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -67,145 +61,74 @@ public class GameClient extends NetworkHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerActions() {
|
||||
super.registerActions();
|
||||
actions.add(new NACLoginAO(this));
|
||||
actions.add(new NACLoginAO2(this));
|
||||
actions.add(new NACRemovePlayer(this));
|
||||
actions.add(new NACGameStatusUpdate(this));
|
||||
actions.add(new NACUpdateMap(this));
|
||||
actions.add(new NACUpdatePlayerPosForced(this));
|
||||
actions.add(new NACUpdatePlayersPos(this));
|
||||
actions.add(new NACUpdateOtherPlayerPos(this));
|
||||
actions.add(new NACServerClosed(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDefaultActions() {
|
||||
getActionByClass(NACUpdatePlayersPos.class).startAction(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
|
||||
if (gameManager != null) {
|
||||
if (gameManager.gameStarted) {
|
||||
} else {
|
||||
checkForNewPlayers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startGame() {
|
||||
if (!players.isEmpty()) {
|
||||
this.gameManager.generateMaze(new HashSet<MazePlayer>(players.values()));
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (running) {
|
||||
for (String s : players.keySet()) {
|
||||
if (players.get(s) instanceof MazePlayerLocal) {
|
||||
RemovePlayer request = new RemovePlayer();
|
||||
request.uuid = s;
|
||||
client.sendTCP(request);
|
||||
}
|
||||
players.get(s).dispose();
|
||||
for (String s : localPlayers) {
|
||||
((NACRemovePlayer) getActionByClass(NACRemovePlayer.class)).startAction(null, null, s);
|
||||
}
|
||||
|
||||
for (MazePlayer p : players.values())
|
||||
p.dispose();
|
||||
players.clear();
|
||||
|
||||
for (NetworkAction n : pendingActions)
|
||||
n.onParentClosing();
|
||||
|
||||
while (!pendingActions.isEmpty())
|
||||
update();
|
||||
|
||||
client.stop();
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onLoginAO(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoginAO2(Connection c) {
|
||||
String uuid = ((LoginAO2) message).uuid;
|
||||
System.out.println(
|
||||
"Server has responded with uuid " + uuid + ", assigning it to the first local player in queue");
|
||||
|
||||
// Accept uuid
|
||||
if (!localPlrQueue.isEmpty()) {
|
||||
players.put(uuid, localPlrQueue.get(0));
|
||||
players.get(uuid).uuid = uuid;
|
||||
localPlrQueue.remove(0);
|
||||
localPlayers.add(uuid);
|
||||
|
||||
// Resend message to notify that uuid has been accepted
|
||||
client.sendTCP(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionRefused(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddNewPlayer(Connection c) {
|
||||
String uuid = ((AddNewPlayer) message).uuid;
|
||||
if (!players.containsKey(uuid)) {
|
||||
MazePlayerRemote player = new MazePlayerRemote(uuid);
|
||||
players.put(uuid, player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemovePlayer(Connection c) {
|
||||
String uuid = ((RemovePlayer) message).uuid;
|
||||
// Remove the player from the server
|
||||
if (players.containsKey(uuid)) {
|
||||
players.remove(uuid);
|
||||
System.out.println("Player with UUID " + uuid + " is leaving the game :(");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateTransform(Connection c) {
|
||||
String uuid = ((UpdatePlayerTransform) message).uuid;
|
||||
if (players.containsKey(uuid) && !localPlayers.contains(uuid)) {
|
||||
|
||||
players.get(uuid).setPos(((UpdatePlayerTransform) message).tx, ((UpdatePlayerTransform) message).ty,
|
||||
((UpdatePlayerTransform) message).tz);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateTransformServer(Connection c) {
|
||||
String uuid = ((UpdatePlayerTransformServer) message).uuid;
|
||||
if (players.containsKey(uuid)) {
|
||||
players.get(uuid).setPos(((UpdatePlayerTransformServer) message).tx,
|
||||
((UpdatePlayerTransformServer) message).ty, ((UpdatePlayerTransformServer) message).tz);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartGame(Connection c) {
|
||||
startGame = true;
|
||||
map = ((StartGame) message).map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndGame(Connection c) {
|
||||
gameManager.setFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateMap(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateSettings(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
if (gameManager != null) {
|
||||
if (!gameManager.gameStarted) {
|
||||
checkForNewPlayers();
|
||||
|
||||
if (startGame) {
|
||||
gameManager.generateMaze(new HashSet<MazePlayer>(players.values()));
|
||||
startGame = false;
|
||||
}
|
||||
} else {
|
||||
if (!gameManager.anyoneWon) {
|
||||
if (!map.equals("")) {
|
||||
gameManager.mazeGen.show(gameManager.mazeGen.runLenghtDecode(map));
|
||||
map = "";
|
||||
}
|
||||
for (String s : players.keySet())
|
||||
if (localPlayers.contains(s))
|
||||
updateLocalPlayerToServer((MazePlayerLocal) players.get(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* CHECKING FOR NEW PLAYERS */
|
||||
MazePlayerLocal p;
|
||||
ArrayList<MazePlayerLocal> localPlrQueue = new ArrayList<MazePlayerLocal>();
|
||||
public ArrayList<MazePlayerLocal> localPlrQueue = new ArrayList<MazePlayerLocal>();
|
||||
|
||||
private void checkForNewPlayers() {
|
||||
checkForNewPlayersDesktop();
|
||||
|
@ -215,27 +138,24 @@ public class GameClient extends NetworkHandler {
|
|||
private void checkForNewPlayersDesktop() {
|
||||
if (AMazeIng.isDesktop()) {
|
||||
// Search for keyboard players (WASD and ARROWS) on Desktop
|
||||
if (PlayerUtils.wasdPressed()) {
|
||||
|
||||
if (PlayerUtils.wasdJustPressed()) {
|
||||
p = PlayerUtils.getPlayerWithKeys(new HashSet<>(players.values()), PlayerUtils.WASDKEYS);
|
||||
if (p != null) {
|
||||
RemovePlayer msg = new RemovePlayer();
|
||||
msg.uuid = p.uuid;
|
||||
client.sendTCP(msg);
|
||||
((NACRemovePlayer) getActionByClass(NACRemovePlayer.class)).startAction(null, null, p.uuid);
|
||||
} else {
|
||||
localPlrQueue.add(new MazePlayerLocal(PlayerUtils.WASDKEYS));
|
||||
client.sendTCP(new LoginAO());
|
||||
getActionByClass(NACLoginAO.class).startAction(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (PlayerUtils.arrowsPressed()) {
|
||||
if (PlayerUtils.arrowsJustPressed()) {
|
||||
p = PlayerUtils.getPlayerWithKeys(new HashSet<>(players.values()), PlayerUtils.ARROWKEYS);
|
||||
if (p != null) {
|
||||
RemovePlayer msg = new RemovePlayer();
|
||||
msg.uuid = p.uuid;
|
||||
client.sendTCP(msg);
|
||||
((NACRemovePlayer) getActionByClass(NACRemovePlayer.class)).startAction(null, null, p.uuid);
|
||||
} else {
|
||||
localPlrQueue.add(new MazePlayerLocal(PlayerUtils.ARROWKEYS));
|
||||
client.sendTCP(new LoginAO());
|
||||
getActionByClass(NACLoginAO.class).startAction(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -248,17 +168,15 @@ public class GameClient extends NetworkHandler {
|
|||
for (int i = 0; i < MazeSettings.MAXPLAYERS; i++) {
|
||||
p = PlayerUtils.getPlayerWithTouchCtrl(i, new HashSet<>(players.values()));
|
||||
if (i < MazeSettings.MAXPLAYERS_MOBILE) {
|
||||
// if yhe player wasn't there before, but wants to join: add it
|
||||
// if the player wasn't there before, but wants to join: add it
|
||||
if (p == null) {
|
||||
localPlrQueue.add(new MazePlayerLocal(new Touchpad(0f, main.uiManager.skin), i));
|
||||
client.sendTCP(new NetworkCommon.LoginAO());
|
||||
getActionByClass(NACLoginAO.class).addToQueue();
|
||||
}
|
||||
} else {
|
||||
// The player was there before, but has left: remove it
|
||||
if (p != null && players.containsValue(p)) {
|
||||
NetworkCommon.RemovePlayer msg = new NetworkCommon.RemovePlayer();
|
||||
msg.uuid = p.uuid;
|
||||
client.sendTCP(msg);
|
||||
((NACRemovePlayer) getActionByClass(NACRemovePlayer.class)).startAction(null, null, p.uuid);
|
||||
}
|
||||
// Otherwise just do nothing
|
||||
}
|
||||
|
@ -268,55 +186,8 @@ public class GameClient extends NetworkHandler {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddPowerUp(Connection c) {
|
||||
PowerUp pu = PowerUps.pickByName(((AddPowerUp) message).name);
|
||||
if (pu != null) {
|
||||
if (!gameManager.thereIsPowerUpInPos((int) ((AddPowerUp) message).x, (int) ((AddPowerUp) message).z)) {
|
||||
gameManager.spawnPowerUp(((AddPowerUp) message).x, ((AddPowerUp) message).z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemovePowerUp(Connection c) {
|
||||
System.out.println("Remove power-up received");
|
||||
gameManager.removePowerUp(
|
||||
gameManager.getPowerUpByPos((int) ((RemovePowerUp) message).x, (int) ((RemovePowerUp) message).z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAssignPowerUp(Connection c) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartUsingPowerUp(Connection c) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndUsingPowerUp(Connection c) {
|
||||
}
|
||||
|
||||
public void updateLocalPlayerToServer(MazePlayerLocal p) {
|
||||
if (this.gameManager != null && this.gameManager.gameStarted) {
|
||||
UpdatePlayerTransform pu = new UpdatePlayerTransform();
|
||||
Vector3 pos = p.ghostObject.getWorldTransform().getTranslation(new Vector3());
|
||||
Quaternion rot = p.ghostObject.getWorldTransform().getRotation(new Quaternion());
|
||||
pu.tx = pos.x;
|
||||
pu.ty = pos.y;
|
||||
pu.tz = pos.z;
|
||||
pu.rx = rot.x;
|
||||
pu.ry = rot.y;
|
||||
pu.rz = rot.z;
|
||||
pu.rw = rot.w;
|
||||
pu.uuid = p.uuid;
|
||||
|
||||
client.sendUDP(pu);
|
||||
}
|
||||
public void setUpdateMobilePlayers() {
|
||||
updateMobilePlayers = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,31 +1,27 @@
|
|||
package com.emamaker.amazeing.manager.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.emamaker.amazeing.manager.managers.GameManagerServer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.AddNewPlayer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.AddPowerUp;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.EndGame;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.LoginAO2;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.RemovePlayer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.RemovePowerUp;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.StartGame;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdateMap;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdatePlayerTransform;
|
||||
import com.emamaker.amazeing.maze.settings.MazeSettings;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.game.NASGameStatusUpdate;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.game.NASServerClosed;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.game.NASUpdateMap;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.login.NASLoginAO2;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.login.NASLoginUUID;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.login.NASRemovePlayer;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.player.NASUpdatePlayerPos;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.player.NASUpdatePlayerPosForced;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.emamaker.amazeing.player.MazePlayerRemote;
|
||||
import com.emamaker.amazeing.player.powerups.PowerUp;
|
||||
import com.emamaker.amazeing.utils.MathUtils;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
import com.esotericsoftware.kryonet.Server;
|
||||
|
||||
public class GameServer extends NetworkHandler {
|
||||
|
||||
Server server;
|
||||
public Server server;
|
||||
|
||||
public ConcurrentHashMap<String, Boolean> positionUpdate = new ConcurrentHashMap<String, Boolean>();
|
||||
|
||||
// Returns true if the server started successfully
|
||||
public boolean start(int port_) {
|
||||
|
@ -36,12 +32,14 @@ public class GameServer extends NetworkHandler {
|
|||
// For consistency, the classes to be sent over the network are
|
||||
// registered by the same method for both the client and server.
|
||||
NetworkCommon.register(server);
|
||||
server.addListener(connectionListener);
|
||||
server.bind(port, port + 1);
|
||||
server.start();
|
||||
|
||||
gameManager = new GameManagerServer();
|
||||
|
||||
registerActions();
|
||||
startDefaultActions();
|
||||
|
||||
System.out.println("Server registered and running on port " + port);
|
||||
return true;
|
||||
|
||||
|
@ -52,87 +50,47 @@ public class GameServer extends NetworkHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoginAO(Connection c) {
|
||||
if (players.size() < MazeSettings.MAXPLAYERS) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
System.out.println("Client requested adding new player, giving it uuid " + uuid);
|
||||
LoginAO2 response = new LoginAO2();
|
||||
response.uuid = uuid;
|
||||
c.sendTCP(response);
|
||||
}
|
||||
public void registerActions() {
|
||||
super.registerActions();
|
||||
actions.add(new NASLoginUUID(this));
|
||||
actions.add(new NASLoginAO2(this));
|
||||
actions.add(new NASRemovePlayer(this));
|
||||
actions.add(new NASGameStatusUpdate(this));
|
||||
actions.add(new NASUpdateMap(this));
|
||||
actions.add(new NASUpdatePlayerPosForced(this));
|
||||
actions.add(new NASUpdatePlayerPos(this));
|
||||
actions.add(new NASServerClosed(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoginAO2(Connection c) {
|
||||
String uuid = ((LoginAO2) message).uuid;
|
||||
if (!players.containsKey(uuid)) {
|
||||
MazePlayerRemote player = new MazePlayerRemote(uuid);
|
||||
players.put(uuid, player);
|
||||
|
||||
// Update everyone about the new player
|
||||
AddNewPlayer response = new AddNewPlayer();
|
||||
response.uuid = uuid;
|
||||
server.sendToAllTCP(response);
|
||||
}
|
||||
public void startDefaultActions() {
|
||||
getActionByClass(NASGameStatusUpdate.class).startAction(null, null);
|
||||
// getActionByClass(NAServerUpdatePlayers.class).startAction(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionRefused(Connection c) {
|
||||
public void periodicNonGameUpdate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddNewPlayer(Connection c) {
|
||||
public void periodicGameUpdate() {
|
||||
getActionByClass(NASUpdateMap.class).startAction(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemovePlayer(Connection c) {
|
||||
String uuid = ((RemovePlayer) message).uuid;
|
||||
// Remove the player from the server
|
||||
if (players.containsKey(uuid)) {
|
||||
players.remove(uuid);
|
||||
System.out.println("Player with UUID " + uuid + " is leaving the game :(");
|
||||
// And update everyone about it
|
||||
server.sendToAllTCP(message);
|
||||
}
|
||||
}
|
||||
public boolean startGame() {
|
||||
System.out.println("Starting game. Players are: " + Arrays.toString(players.values().toArray()));
|
||||
if (!players.isEmpty()) {
|
||||
this.gameManager.generateMaze(new HashSet<MazePlayer>(players.values()));
|
||||
|
||||
Vector3 newPos = Vector3.Zero;
|
||||
|
||||
@Override
|
||||
public void onUpdateTransform(Connection c) {
|
||||
String uuid = ((UpdatePlayerTransform) message).uuid;
|
||||
if (players.containsKey(uuid)) {
|
||||
// Check if the position is in a possible one, or if the player has teleported
|
||||
// from one spot to another
|
||||
newPos.set(((UpdatePlayerTransform) message).tx, ((UpdatePlayerTransform) message).ty,
|
||||
((UpdatePlayerTransform) message).tz);
|
||||
if (MathUtils.vectorDistance(players.get(uuid).getPos(), newPos) < 10) {
|
||||
players.get(uuid).setPos(newPos);
|
||||
server.sendToAllUDP(message);
|
||||
} else {
|
||||
server.sendToAllUDP(updatePlayer(uuid, players.get(uuid), true));
|
||||
for (String s : players.keySet()) {
|
||||
((NASUpdatePlayerPosForced) getActionByClass(NASUpdatePlayerPosForced.class))
|
||||
.startAction(null, null, s);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateTransformServer(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartGame(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndGame(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateMap(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateSettings(Connection c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,94 +99,19 @@ public class GameServer extends NetworkHandler {
|
|||
p.dispose();
|
||||
players.clear();
|
||||
if (isRunning()) {
|
||||
main.client.stop();
|
||||
getActionByClass(NASServerClosed.class).startAction(null, null);
|
||||
server.stop();
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(Connection c) {
|
||||
System.out.println("New client connected, updating him about the others!");
|
||||
for (String s : players.keySet()) {
|
||||
AddNewPlayer request = new AddNewPlayer();
|
||||
request.uuid = s;
|
||||
c.sendTCP(request);
|
||||
}
|
||||
|
||||
public boolean canUpdatePos(String u) {
|
||||
return positionUpdate.containsKey(u) && positionUpdate.get(u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddPowerUp(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemovePowerUp(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAssignPowerUp(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartUsingPowerUp(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndUsingPowerUp(Connection c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startGame() {
|
||||
if (!players.isEmpty()) {
|
||||
this.gameManager.generateMaze(new HashSet<MazePlayer>(players.values()));
|
||||
StartGame response = new StartGame();
|
||||
response.map = this.gameManager.mazeGen.runLenghtEncode();
|
||||
server.sendToAllTCP(response);
|
||||
|
||||
for (String s : players.keySet()) {
|
||||
Object pu = updatePlayer(s, players.get(s), true);
|
||||
server.sendToAllTCP(pu);
|
||||
}
|
||||
|
||||
periodicGameUpdate();
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
if (gameManager != null) {
|
||||
if (gameManager.anyoneWon)
|
||||
server.sendToAllUDP(new EndGame());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void periodicGameUpdate() {
|
||||
UpdateMap response = new UpdateMap();
|
||||
response.map = gameManager.mazeGen.runLenghtEncode();
|
||||
server.sendToAllUDP(response);
|
||||
|
||||
for (PowerUp p : gameManager.powerups) {
|
||||
AddPowerUp response1 = new AddPowerUp();
|
||||
response1.name = p.name;
|
||||
response1.x = p.getPosition().x;
|
||||
response1.z = p.getPosition().z;
|
||||
|
||||
server.sendToAllUDP(response1);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePowerUp(PowerUp pup) {
|
||||
if(pup != null) {
|
||||
RemovePowerUp response = new RemovePowerUp();
|
||||
response.x = pup.getPosition().z;
|
||||
response.z = pup.getPosition().z;
|
||||
server.sendToAllUDP(response);
|
||||
}
|
||||
|
||||
public void setUpdatePos(String uuid, boolean b) {
|
||||
if(positionUpdate.containsKey(uuid)) positionUpdate.replace(uuid, b);
|
||||
else positionUpdate.put(uuid, b);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,104 +5,81 @@ import com.esotericsoftware.kryonet.Connection;
|
|||
import com.esotericsoftware.kryonet.EndPoint;
|
||||
|
||||
public class NetworkCommon {
|
||||
|
||||
|
||||
// This registers objects that are going to be sent over the network.
|
||||
public static void register(EndPoint endPoint) {
|
||||
Kryo kryo = endPoint.getKryo();
|
||||
kryo.register(JustConnected.class);
|
||||
kryo.register(LoginAO.class);
|
||||
kryo.register(LoginAO2.class);
|
||||
kryo.register(ConnectionRefused.class);
|
||||
kryo.register(AddNewPlayer.class);
|
||||
kryo.register(ClientLoginAO.class);
|
||||
kryo.register(ServerLoginUUID.class);
|
||||
kryo.register(ClientLoginAO2.class);
|
||||
kryo.register(ServerLoginAO2.class);
|
||||
|
||||
kryo.register(RemovePlayer.class);
|
||||
kryo.register(UpdatePlayerTransform.class);
|
||||
kryo.register(UpdatePlayerTransformServer.class);
|
||||
kryo.register(StartGame.class);
|
||||
kryo.register(EndGame.class);
|
||||
kryo.register(UpdateMap.class);
|
||||
kryo.register(UpdateSettings.class);
|
||||
kryo.register(Present.class);
|
||||
kryo.register(AddPowerUp.class);
|
||||
kryo.register(RemovePowerUp.class);
|
||||
kryo.register(AssignPowerUp.class);
|
||||
kryo.register(StartUsingPowerUp.class);
|
||||
kryo.register(EndUsingPowerUp.class);
|
||||
}
|
||||
|
||||
//Login stuff
|
||||
public static class JustConnected {
|
||||
}
|
||||
public static class LoginAO {
|
||||
}
|
||||
public static class LoginAO2 {
|
||||
String uuid;
|
||||
}
|
||||
public static class ConnectionRefused {
|
||||
String uuid;
|
||||
}
|
||||
|
||||
//Player stuff
|
||||
public static class AddNewPlayer {
|
||||
String uuid;
|
||||
}
|
||||
public static class RemovePlayer {
|
||||
String uuid;
|
||||
}
|
||||
public static class UpdatePlayerTransform {
|
||||
String uuid;
|
||||
float tx, ty, tz, rx, ry, rz, rw;
|
||||
}
|
||||
public static class UpdatePlayerTransformServer {
|
||||
String uuid;
|
||||
float tx, ty, tz, rx, ry, rz, rw;
|
||||
}
|
||||
|
||||
//PowerUp stuff
|
||||
public static class AddPowerUp {
|
||||
String name;
|
||||
float x,z;
|
||||
}
|
||||
public static class RemovePowerUp {
|
||||
String uuid;
|
||||
float x,z;
|
||||
}
|
||||
public static class AssignPowerUp {
|
||||
String name, uuid;
|
||||
}
|
||||
public static class StartUsingPowerUp {
|
||||
String name, uuid;
|
||||
}
|
||||
public static class EndUsingPowerUp {
|
||||
String name, uuid;
|
||||
}
|
||||
|
||||
//Game
|
||||
public static class StartGame{
|
||||
//Use this to notify clients of a newly started game
|
||||
//A Run-lenght-encoded representation of the map can be appended, this can be avoided but it's not recommended
|
||||
String map;
|
||||
}
|
||||
public static class EndGame{
|
||||
//Use this to notify clients when a game ends
|
||||
}
|
||||
public static class UpdateMap{
|
||||
//Use this to notify clients of a modification of the map
|
||||
//Run-lenght-encoded representation of the map
|
||||
String map;
|
||||
}
|
||||
|
||||
public static class UpdateSettings {
|
||||
int index;
|
||||
String value;
|
||||
}
|
||||
|
||||
public static class Present{
|
||||
kryo.register(PlayerRemoved.class);
|
||||
|
||||
kryo.register(GameStatusUpdate.class);
|
||||
kryo.register(String[].class);
|
||||
kryo.register(UpdateMap.class);
|
||||
|
||||
kryo.register(UpdatePlayerPosition.class);
|
||||
kryo.register(UpdateForcedPlayerPosition.class);
|
||||
kryo.register(UpdateForcedPlayerPositionOk.class);
|
||||
|
||||
kryo.register(ServerClosed.class);
|
||||
}
|
||||
|
||||
public static class ClientLoginAO {
|
||||
}
|
||||
|
||||
public static class ServerLoginUUID {
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
public static class ClientLoginAO2 {
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
public static class ServerLoginAO2 {
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
public static class RemovePlayer{
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
public static class PlayerRemoved{
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
//Game Status is used to broadcast to clients infos about the game and players
|
||||
public static class GameStatusUpdate{
|
||||
public boolean gameStarted;
|
||||
public boolean anyoneWon;
|
||||
public String[] playersUUIDs;
|
||||
}
|
||||
|
||||
//Run-lenght encoding of the map
|
||||
public static class UpdateMap{
|
||||
public String map;
|
||||
}
|
||||
|
||||
|
||||
public static class UpdatePlayerPosition{
|
||||
public String uuid;
|
||||
public float px, py, pz;
|
||||
}
|
||||
|
||||
public static class UpdateForcedPlayerPosition{
|
||||
public String uuid;
|
||||
public float px, py, pz;
|
||||
}
|
||||
|
||||
public static class UpdateForcedPlayerPositionOk{
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
public static class ServerClosed{ }
|
||||
}
|
||||
|
||||
class ConnectionPlayer extends Connection {
|
||||
public String uuid;
|
||||
public String uuid;
|
||||
}
|
||||
|
|
|
@ -1,136 +1,52 @@
|
|||
package com.emamaker.amazeing.manager.network;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.badlogic.gdx.math.Quaternion;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.managers.GameManager;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.AddNewPlayer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.AddPowerUp;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.AssignPowerUp;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.ConnectionRefused;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.EndGame;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.EndUsingPowerUp;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.LoginAO;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.LoginAO2;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.RemovePlayer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.RemovePowerUp;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.StartGame;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.StartUsingPowerUp;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdateMap;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdatePlayerTransform;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdatePlayerTransformServer;
|
||||
import com.emamaker.amazeing.manager.GameManager;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdateForcedPlayerPosition;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdatePlayerPosition;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
import com.esotericsoftware.kryonet.Listener;
|
||||
|
||||
public abstract class NetworkHandler {
|
||||
|
||||
public Hashtable<String, MazePlayer> players = new Hashtable<String, MazePlayer>();
|
||||
public ConcurrentHashMap<String, MazePlayer> players = new ConcurrentHashMap<String, MazePlayer>();
|
||||
public GameManager gameManager;
|
||||
public AMazeIng main = AMazeIng.getMain();
|
||||
|
||||
// A List of all actions that can be done by the handler
|
||||
public CopyOnWriteArrayList<NetworkAction> actions = new CopyOnWriteArrayList<>();
|
||||
// A list of the actions that are currently in resolution and are waiting for a
|
||||
// response
|
||||
public CopyOnWriteArrayList<NetworkAction> pendingActions = new CopyOnWriteArrayList<>();
|
||||
// Some actions (such as the first step of login) cannot be done in multiple
|
||||
// instances at the same time
|
||||
// Actions of this type have to be stored here
|
||||
public ConcurrentLinkedQueue<NetworkAction> todoActions = new ConcurrentLinkedQueue<>();
|
||||
CopyOnWriteArrayList<NetworkAction> deletePending = new CopyOnWriteArrayList<>();
|
||||
|
||||
int port;
|
||||
boolean running = false;
|
||||
|
||||
long time = 0;
|
||||
int UPDATE_PERIOD = 2000;
|
||||
int UPDATE_PERIOD = 750;
|
||||
|
||||
/*
|
||||
* Since Kryonet defaults the use of a TCP port: Login UUID negotation, game
|
||||
* starting and ending, player adding and removal settings update are done using
|
||||
* TCP since we can't afford to lose packets on them, and they're done in a
|
||||
* phase of the game when there's few UPD traffic if not at all Player Transform
|
||||
* Updates and map updates will be done in UDP, since there can be a lot in a
|
||||
* short period of time and they're not essential to the game (meaning some
|
||||
* updates can be skipped)
|
||||
* Everything is done with the use of UDP and actions. Basically an Action will
|
||||
* send a specific UDP package to one end to another and repeat the same action
|
||||
* until a response is received, look in the NetworkAction class for more info A
|
||||
* NetworkHandler provides functionality to the NetworkActions: it updates and
|
||||
* manages the adding and removal of NetworkActions
|
||||
*/
|
||||
|
||||
public abstract void onLoginAO(Connection c);
|
||||
|
||||
public abstract void onLoginAO2(Connection c);
|
||||
|
||||
public abstract void onConnectionRefused(Connection c);
|
||||
|
||||
public abstract void onAddNewPlayer(Connection c);
|
||||
|
||||
public abstract void onRemovePlayer(Connection c);
|
||||
|
||||
public abstract void onUpdateTransform(Connection c);
|
||||
|
||||
public abstract void onUpdateTransformServer(Connection c);
|
||||
|
||||
public abstract void onStartGame(Connection c);
|
||||
|
||||
public abstract void onEndGame(Connection c);
|
||||
|
||||
public abstract void onUpdateMap(Connection c);
|
||||
|
||||
public abstract void onUpdateSettings(Connection c);
|
||||
|
||||
public abstract void onConnected(Connection c);
|
||||
|
||||
public abstract void onAddPowerUp(Connection c);
|
||||
|
||||
public abstract void onRemovePowerUp(Connection c);
|
||||
|
||||
public abstract void onAssignPowerUp(Connection c);
|
||||
|
||||
public abstract void onStartUsingPowerUp(Connection c);
|
||||
|
||||
public abstract void onEndUsingPowerUp(Connection c);
|
||||
|
||||
Object message;
|
||||
|
||||
public void onReceived(Connection c, Object object) {
|
||||
message = object;
|
||||
|
||||
if (object instanceof LoginAO)
|
||||
onLoginAO(c);
|
||||
else if (object instanceof LoginAO2)
|
||||
onLoginAO2(c);
|
||||
else if (object instanceof ConnectionRefused)
|
||||
onConnectionRefused(c);
|
||||
else if (object instanceof UpdatePlayerTransform)
|
||||
onUpdateTransform(c);
|
||||
else if (object instanceof UpdatePlayerTransformServer)
|
||||
onUpdateTransformServer(c);
|
||||
else if (object instanceof StartGame)
|
||||
onStartGame(c);
|
||||
else if (object instanceof EndGame)
|
||||
onEndGame(c);
|
||||
else if (object instanceof UpdateMap)
|
||||
onUpdateMap(c);
|
||||
else if (object instanceof AddNewPlayer)
|
||||
onAddNewPlayer(c);
|
||||
else if (object instanceof RemovePlayer)
|
||||
onRemovePlayer(c);
|
||||
else if (object instanceof AddPowerUp)
|
||||
onAddPowerUp(c);
|
||||
else if (object instanceof RemovePowerUp)
|
||||
onRemovePowerUp(c);
|
||||
else if (object instanceof AssignPowerUp)
|
||||
onAssignPowerUp(c);
|
||||
else if (object instanceof StartUsingPowerUp)
|
||||
onStartUsingPowerUp(c);
|
||||
else if (object instanceof EndUsingPowerUp)
|
||||
onEndUsingPowerUp(c);
|
||||
|
||||
}
|
||||
|
||||
Listener connectionListener = new Listener() {
|
||||
public void received(com.esotericsoftware.kryonet.Connection arg0, Object arg1) {
|
||||
onReceived(arg0, arg1);
|
||||
};
|
||||
|
||||
public void connected(com.esotericsoftware.kryonet.Connection arg0) {
|
||||
onConnected(arg0);
|
||||
};
|
||||
};
|
||||
|
||||
public void update() {
|
||||
if (gameManager != null && gameManager.gameStarted)
|
||||
updatePending();
|
||||
|
||||
if (gameManager != null)
|
||||
gameManager.update();
|
||||
|
||||
if (gameManager != null && System.currentTimeMillis() - time > UPDATE_PERIOD) {
|
||||
|
@ -142,48 +58,90 @@ public abstract class NetworkHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public void updatePending() {
|
||||
if (!todoActions.isEmpty()) {
|
||||
if (!alreadyPending(todoActions.peek()))
|
||||
todoActions.peek().startAction(null, null);
|
||||
addToPending(todoActions.remove());
|
||||
}
|
||||
|
||||
for (NetworkAction n : pendingActions)
|
||||
n.update();
|
||||
}
|
||||
|
||||
/*
|
||||
* Unluckily, we can't check if a specific action is already pending. But we can
|
||||
* check if there's another type of the same action running. NetworkActions can
|
||||
* override the startAction method to be started even if there's another one
|
||||
* already running (e.g. PositionUpdates)
|
||||
*/
|
||||
public boolean alreadyPending(NetworkAction act) {
|
||||
for (NetworkAction a : pendingActions) {
|
||||
if (a.getClass().isAssignableFrom(act.getClass())) {
|
||||
// System.out.println("Already pending " + act);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Actions can be removed from pending by instance
|
||||
public void removeFromPending(NetworkAction act) {
|
||||
pendingActions.remove(act);
|
||||
// System.out.println("Delete from pending " + act);
|
||||
}
|
||||
|
||||
public void addToPending(NetworkAction a) {
|
||||
pendingActions.add(a);
|
||||
}
|
||||
|
||||
public void periodicGameUpdate() {
|
||||
}
|
||||
|
||||
public void periodicNonGameUpdate() {
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
public void registerActions() {
|
||||
}
|
||||
|
||||
public abstract boolean startGame();
|
||||
|
||||
public abstract void stop();
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
public NetworkAction getActionByClass(Class<?> clas) {
|
||||
for (NetworkAction a : actions) {
|
||||
if (a.getClass() == clas) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void startDefaultActions() {
|
||||
}
|
||||
|
||||
public Object updatePlayer(String uuid, MazePlayer p, boolean force) {
|
||||
if (force) {
|
||||
NetworkCommon.UpdatePlayerTransformServer pu = new NetworkCommon.UpdatePlayerTransformServer();
|
||||
UpdateForcedPlayerPosition pu = new UpdateForcedPlayerPosition();
|
||||
Vector3 pos = p.getPos();
|
||||
Quaternion rot = p.getRotation();
|
||||
pu.tx = pos.x;
|
||||
pu.ty = pos.y;
|
||||
pu.tz = pos.z;
|
||||
pu.rx = rot.x;
|
||||
pu.ry = rot.y;
|
||||
pu.rz = rot.z;
|
||||
pu.rw = rot.w;
|
||||
pu.px = pos.x;
|
||||
pu.py = pos.y;
|
||||
pu.pz = pos.z;
|
||||
pu.uuid = uuid;
|
||||
System.out.println("Forcing position update to all clients for player " + uuid);
|
||||
// System.out.println("Forcing position update to all clients for player " + uuid + " in pos " + pos.toString());
|
||||
return pu;
|
||||
} else {
|
||||
UpdatePlayerTransform pu = new UpdatePlayerTransform();
|
||||
UpdatePlayerPosition pu = new UpdatePlayerPosition();
|
||||
Vector3 pos = p.getPos();
|
||||
Quaternion rot = p.getRotation();
|
||||
pu.tx = pos.x;
|
||||
pu.ty = pos.y;
|
||||
pu.tz = pos.z;
|
||||
pu.rx = rot.x;
|
||||
pu.ry = rot.y;
|
||||
pu.rz = rot.z;
|
||||
pu.rw = rot.w;
|
||||
pu.px = pos.x;
|
||||
pu.py = pos.y;
|
||||
pu.pz = pos.z;
|
||||
pu.uuid = uuid;
|
||||
System.out.println("Sending position update to all clients for player " + uuid);
|
||||
// System.out.println("Sending position update to all clients for player " + uuid + " in pos " + pos.toString());
|
||||
return pu;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
package com.emamaker.amazeing.manager.network.action;
|
||||
|
||||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.network.GameClient;
|
||||
import com.emamaker.amazeing.manager.network.GameServer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
import com.esotericsoftware.kryonet.Listener;
|
||||
|
||||
public abstract class NetworkAction {
|
||||
|
||||
/*
|
||||
* NetworkAction network structure. A NetworkAction has a listener to be started
|
||||
* and another one to be ended Once started (because the listener received the
|
||||
* trigger package or because it has be done manually with .startAction) an
|
||||
* action adds a new instance of itself to the pendingActions list of the parent
|
||||
* NetworkHandler. The NetworkHandler calls the update method of the action The
|
||||
* new instance needs the endlistener to be attached to its parent, so it can be
|
||||
* removed from the parent's pendingActions list by instance Generally a
|
||||
* NetworkAction always has a responsePacket If the startPacket is null, the
|
||||
* action has no start listener and must be started manually If the startPacket
|
||||
* is null, the action has no end listener and must be endeed manually, most of
|
||||
* the time using the oneTime boolean If an action has the oneTime flag set to
|
||||
* true, once called the resolveAction() method for the irst time, it's
|
||||
* automatically ended
|
||||
*
|
||||
* Every child of this class MUST override the newInstace() method, so that
|
||||
* adding to pendingActions can be done easily. Reflection could be used to
|
||||
* automatically do this, but some NetworkActions require a particular
|
||||
* constructor to pass arguments to the new instance
|
||||
*/
|
||||
|
||||
protected Object incomingMsg, endMsg;
|
||||
protected Object startPacket, responsePacket, endPacket;
|
||||
protected Connection incomingConnection, endConnection;
|
||||
protected NetworkHandler parent;
|
||||
protected boolean oneTime;
|
||||
|
||||
protected long TIMEOUT_TIME = 5000;
|
||||
protected long startTime;
|
||||
boolean tookTimeout = false;
|
||||
boolean usingTimeout = true;
|
||||
boolean oneAtTheTime = true;
|
||||
|
||||
public AMazeIng main = AMazeIng.getMain();
|
||||
|
||||
Listener startListener = new Listener() {
|
||||
@Override
|
||||
public void received(Connection arg0, Object arg1) {
|
||||
super.received(arg0, arg1);
|
||||
if (startPacket != null && arg1.getClass().equals(startPacket.getClass())) {
|
||||
// System.out.println("Received start packet " + arg1 + " for " + this);
|
||||
startAction(arg0, arg1);
|
||||
}
|
||||
}
|
||||
};
|
||||
Listener endListener = new Listener() {
|
||||
@Override
|
||||
public void received(Connection arg0, Object arg1) {
|
||||
super.received(arg0, arg1);
|
||||
if (endPacket != null && arg1.getClass().equals(endPacket.getClass())) {
|
||||
// System.out.println("Received end packet " + arg1 + " for " + this);
|
||||
responseReceived(arg0, arg1);
|
||||
}
|
||||
}
|
||||
};;
|
||||
|
||||
protected NetworkAction(NetworkHandler parent_, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
this.incomingConnection = c;
|
||||
this.incomingMsg = incomingMsg_;
|
||||
this.responsePacket = responsePacket_;
|
||||
this.endPacket = endPacket_;
|
||||
this.parent = parent_;
|
||||
this.oneTime = oneTime;
|
||||
|
||||
if (client() != null)
|
||||
client().client.addListener(endListener);
|
||||
if (server() != null)
|
||||
server().server.addListener(endListener);
|
||||
|
||||
tookTimeout = false;
|
||||
usingTimeout = true;
|
||||
// update();
|
||||
}
|
||||
|
||||
public NetworkAction(NetworkHandler parent_, Object startPacket_, Object responsePacket_, Object endPacket_,
|
||||
boolean oneTime_) {
|
||||
this.parent = parent_;
|
||||
this.startPacket = startPacket_;
|
||||
this.responsePacket = responsePacket_;
|
||||
this.endPacket = endPacket_;
|
||||
this.oneTime = oneTime_;
|
||||
|
||||
if (client() != null)
|
||||
client().client.addListener(startListener);
|
||||
if (server() != null)
|
||||
server().server.addListener(startListener);
|
||||
}
|
||||
|
||||
public void startAction() {
|
||||
this.startAction(incomingConnection, incomingMsg);
|
||||
}
|
||||
|
||||
public void startAction(Connection conn, Object msg) {
|
||||
this.incomingConnection = conn;
|
||||
this.incomingMsg = msg;
|
||||
// System.out.println("Starting action: " + this);
|
||||
|
||||
if (oneAtTheTime) {
|
||||
if (!parent.alreadyPending(this))
|
||||
parent.addToPending(newInstance());
|
||||
} else {
|
||||
parent.addToPending(newInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (!tookTimeout) {
|
||||
tookTimeout = true;
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
resolveAction();
|
||||
if (oneTime)
|
||||
responseReceived(null, null);
|
||||
if (System.currentTimeMillis() - startTime > TIMEOUT_TIME && usingTimeout)
|
||||
detachFromParent();
|
||||
}
|
||||
|
||||
public void resolveAction() {
|
||||
// System.out.println("Resolving action for " + this);
|
||||
}
|
||||
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
this.endConnection = conn;
|
||||
this.endMsg = msg;
|
||||
detachFromParent();
|
||||
// System.out.println("Response received for " + this);
|
||||
}
|
||||
|
||||
public void detachFromParent() {
|
||||
parent.removeFromPending(this);
|
||||
|
||||
if (client() != null)
|
||||
client().client.removeListener(endListener);
|
||||
if (server() != null)
|
||||
server().server.removeListener(startListener);
|
||||
}
|
||||
|
||||
public abstract NetworkAction newInstance();
|
||||
|
||||
public GameClient client() {
|
||||
try {
|
||||
return (GameClient) parent;
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Calling client, but this is server");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public GameServer server() {
|
||||
try {
|
||||
return (GameServer) parent;
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Calling server, but this is client");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void enableTimeout(boolean b) {
|
||||
this.usingTimeout = b;
|
||||
}
|
||||
|
||||
public void setOneAtTheTime(boolean b) {
|
||||
this.oneAtTheTime = b;
|
||||
}
|
||||
|
||||
public void onParentClosing() {
|
||||
responseReceived(null, null);
|
||||
}
|
||||
|
||||
public void addToQueue() {
|
||||
parent.todoActions.add(newInstance());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.GameStatusUpdate;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.player.MazePlayerRemote;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACGameStatusUpdate extends NetworkAction {
|
||||
|
||||
protected NACGameStatusUpdate(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NACGameStatusUpdate(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.GameStatusUpdate(), null, null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
ArrayList<String> uuids = new ArrayList<String>(Arrays.asList(((GameStatusUpdate) incomingMsg).playersUUIDs));
|
||||
|
||||
// Then check if older players have to be removed
|
||||
for (String s : client().players.keySet()) {
|
||||
if (!uuids.contains(s) && !client().localPlayers.contains(s)) {
|
||||
client().players.get(s).dispose();
|
||||
client().players.remove(s);
|
||||
}
|
||||
}
|
||||
|
||||
// First of all check if new players have to be added to the game
|
||||
for (String s : uuids) {
|
||||
if (!client().players.containsKey(s) && !client().localPlayers.contains(s)) {
|
||||
client().players.put(s, new MazePlayerRemote(s));
|
||||
}
|
||||
}
|
||||
|
||||
// Now check if the game has started. If so, start it
|
||||
if (client().gameManager.gameStarted != ((GameStatusUpdate) incomingMsg).gameStarted
|
||||
&& !((GameStatusUpdate) incomingMsg).anyoneWon)
|
||||
client().startGame();
|
||||
|
||||
// Update the vars
|
||||
client().gameManager.gameStarted = ((GameStatusUpdate) incomingMsg).gameStarted;
|
||||
client().gameManager.anyoneWon = ((GameStatusUpdate) incomingMsg).anyoneWon;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACGameStatusUpdate(client(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.game;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACServerClosed extends NetworkAction {
|
||||
|
||||
protected NACServerClosed(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NACServerClosed(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.ServerClosed(), null, null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
System.out.println("Server stopped!");
|
||||
parent.stop();
|
||||
main.uiManager.srvJoinScreen.showErrorDlg(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACServerClosed(client(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.game;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdateMap;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACUpdateMap extends NetworkAction {
|
||||
|
||||
String map;
|
||||
|
||||
protected NACUpdateMap(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NACUpdateMap(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.UpdateMap(), null, null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
if (client().gameManager.gameStarted) {
|
||||
map = ((UpdateMap) incomingMsg).map;
|
||||
client().gameManager.mazeGen.show(client().gameManager.mazeGen.runLenghtDecode(map));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACUpdateMap(client(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.login;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACLoginAO extends NetworkAction {
|
||||
|
||||
protected NACLoginAO(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_, Object endPacket_,
|
||||
boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NACLoginAO(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.ClientLoginAO(), new NetworkCommon.ServerLoginUUID(), false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
client().client.sendUDP(responsePacket);
|
||||
System.out.println("Asking the server for uuid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACLoginAO(client(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.login;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.ClientLoginAO2;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.ServerLoginUUID;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACLoginAO2 extends NetworkAction {
|
||||
|
||||
String uuid;
|
||||
|
||||
protected NACLoginAO2(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NACLoginAO2(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.ServerLoginUUID(), new NetworkCommon.ClientLoginAO2(),
|
||||
new NetworkCommon.ServerLoginAO2(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
uuid = ((ServerLoginUUID) incomingMsg).uuid;
|
||||
System.out.println(
|
||||
"Server has responded with uuid " + uuid + ", assigning it to the first local player in queue");
|
||||
|
||||
// Accept uuid
|
||||
if (!client().localPlrQueue.isEmpty() && !client().players.containsKey(uuid)) {
|
||||
client().players.put(uuid, client().localPlrQueue.get(0));
|
||||
client().players.get(uuid).uuid = uuid;
|
||||
|
||||
client().localPlrQueue.remove(0);
|
||||
client().localPlayers.add(uuid);
|
||||
System.out.println("Added player");
|
||||
}
|
||||
((ClientLoginAO2) responsePacket).uuid = uuid;
|
||||
client().client.sendUDP(responsePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACLoginAO2(client(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.login;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PlayerRemoved;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.RemovePlayer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACRemovePlayer extends NetworkAction {
|
||||
|
||||
String uuid;
|
||||
|
||||
protected NACRemovePlayer(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime, String uuid_) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
this.uuid = uuid_;
|
||||
}
|
||||
|
||||
public NACRemovePlayer(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.RemovePlayer(), new NetworkCommon.PlayerRemoved(), false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Here startAction needs to be overrided to allow for the uuid argument to be
|
||||
* passed from one instance to another and to remove the alreadyPending
|
||||
* limitation. Here we need to be able to call multiple instances of this at the
|
||||
* same time
|
||||
*/
|
||||
public void startAction(String s_) {
|
||||
this.startAction(incomingConnection, incomingMsg, s_);
|
||||
}
|
||||
|
||||
public void startAction(Connection conn, Object msg, String uuid_) {
|
||||
this.incomingConnection = conn;
|
||||
this.incomingMsg = msg;
|
||||
this.uuid = uuid_;
|
||||
System.out.println("Starting action: " + this);
|
||||
|
||||
parent.addToPending(newInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
System.out.println("Asking the server to remove player " + uuid);
|
||||
((RemovePlayer) responsePacket).uuid = uuid;
|
||||
client().client.sendUDP(responsePacket);
|
||||
}
|
||||
|
||||
/*
|
||||
* We also have to override the responseReceived package, because this action
|
||||
* has to finish only if the correct uuid has been received
|
||||
*/
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
this.endConnection = conn;
|
||||
this.endMsg = msg;
|
||||
if ( endMsg != null && (((PlayerRemoved) endMsg).uuid == null || ((PlayerRemoved) endMsg).uuid.equals(uuid))) {
|
||||
if (client().players.containsKey(uuid)) {
|
||||
client().players.get(uuid).dispose();
|
||||
client().players.remove(uuid);
|
||||
client().localPlayers.remove(uuid);
|
||||
}
|
||||
detachFromParent();
|
||||
}
|
||||
// System.out.println("Response received for " + this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACRemovePlayer(client(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime, uuid);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.player;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdatePlayerPosition;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACUpdateOtherPlayerPos extends NetworkAction {
|
||||
|
||||
protected NACUpdateOtherPlayerPos(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NACUpdateOtherPlayerPos(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.UpdatePlayerPosition(), null, null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
String uuid = ((UpdatePlayerPosition) incomingMsg).uuid;
|
||||
float px = ((UpdatePlayerPosition) incomingMsg).px;
|
||||
float py = ((UpdatePlayerPosition) incomingMsg).py;
|
||||
float pz = ((UpdatePlayerPosition) incomingMsg).pz;
|
||||
if (parent.players.containsKey(uuid) && !client().localPlayers.contains(uuid)
|
||||
&& parent.gameManager.gameStarted) {
|
||||
parent.players.get(uuid).setPos(px, py, pz);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACUpdateOtherPlayerPos(client(), incomingConnection, incomingMsg, responsePacket, endPacket,
|
||||
oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.player;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdateForcedPlayerPosition;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdateForcedPlayerPositionOk;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACUpdatePlayerPosForced extends NetworkAction {
|
||||
|
||||
String uuid;
|
||||
|
||||
protected NACUpdatePlayerPosForced(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NACUpdatePlayerPosForced(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.UpdateForcedPlayerPosition(), new NetworkCommon.UpdateForcedPlayerPositionOk(),
|
||||
null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
uuid = ((UpdateForcedPlayerPosition) incomingMsg).uuid;
|
||||
float px = ((UpdateForcedPlayerPosition) incomingMsg).px;
|
||||
float py = ((UpdateForcedPlayerPosition) incomingMsg).py;
|
||||
float pz = ((UpdateForcedPlayerPosition) incomingMsg).pz;
|
||||
if (parent.players.containsKey(uuid)) {
|
||||
parent.players.get(uuid).setPos(px, py, pz);
|
||||
((UpdateForcedPlayerPositionOk) responsePacket).uuid = uuid;
|
||||
if (client().localPlayers.contains(uuid)) {
|
||||
client().client.sendUDP(responsePacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACUpdatePlayerPosForced(client(), incomingConnection, incomingMsg, responsePacket, endPacket,
|
||||
oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.player;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.player.MazePlayerLocal;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACUpdatePlayersPos extends NetworkAction {
|
||||
|
||||
protected NACUpdatePlayersPos(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
enableTimeout(false);
|
||||
}
|
||||
|
||||
public NACUpdatePlayersPos(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.UpdatePlayerPosition(), null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
if (parent.gameManager.gameStarted)
|
||||
for (String s : client().localPlayers) {
|
||||
if (parent.players.containsKey(s) && ((MazePlayerLocal) parent.players.get(s)).pressed) {
|
||||
responsePacket = parent.updatePlayer(s, parent.players.get(s), false);
|
||||
client().client.sendUDP(responsePacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACUpdatePlayersPos(client(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.game;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.GameStatusUpdate;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASGameStatusUpdate extends NetworkAction {
|
||||
|
||||
protected NASGameStatusUpdate(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
enableTimeout(false);
|
||||
}
|
||||
|
||||
public NASGameStatusUpdate(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.GameStatusUpdate(), null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
try {
|
||||
((GameStatusUpdate) responsePacket).playersUUIDs = server().players.keySet()
|
||||
.toArray(new String[server().players.size()]);
|
||||
((GameStatusUpdate) responsePacket).gameStarted = server().gameManager.gameStarted;
|
||||
((GameStatusUpdate) responsePacket).anyoneWon = server().gameManager.anyoneWon;
|
||||
|
||||
server().server.sendToAllUDP(responsePacket);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASGameStatusUpdate(server(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.game;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASServerClosed extends NetworkAction {
|
||||
|
||||
protected NASServerClosed(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NASServerClosed(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.ServerClosed(), null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
System.out.println("Server stopped?");
|
||||
server().server.sendToAllTCP(responsePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASServerClosed(server(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.game;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdateMap;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASUpdateMap extends NetworkAction {
|
||||
|
||||
protected NASUpdateMap(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NASUpdateMap(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.UpdateMap(), null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
((UpdateMap) responsePacket).map = server().gameManager.mazeGen.runLenghtEncode();
|
||||
server().server.sendToAllUDP(responsePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASUpdateMap(server(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.login;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.ClientLoginAO2;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.ServerLoginAO2;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.player.MazePlayerRemote;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASLoginAO2 extends NetworkAction {
|
||||
|
||||
String uuid;
|
||||
|
||||
protected NASLoginAO2(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_, Object endPacket_,
|
||||
boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NASLoginAO2(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.ClientLoginAO2(), new NetworkCommon.ServerLoginAO2(), null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
uuid = ((ClientLoginAO2) incomingMsg).uuid;
|
||||
if (!server().players.containsKey(uuid)) {
|
||||
System.out.println("Client accepted uuid " + uuid);
|
||||
MazePlayerRemote player = new MazePlayerRemote(uuid);
|
||||
server().players.put(uuid, player);
|
||||
server().setUpdatePos(uuid, false);
|
||||
}
|
||||
((ServerLoginAO2)responsePacket).uuid = uuid;
|
||||
server().server.sendToAllUDP(responsePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASLoginAO2(server(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.login;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.ServerLoginUUID;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.maze.settings.MazeSettings;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASLoginUUID extends NetworkAction {
|
||||
|
||||
String uuid;
|
||||
|
||||
protected NASLoginUUID(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_, Object endPacket_,
|
||||
boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NASLoginUUID(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.ClientLoginAO(), new NetworkCommon.ServerLoginUUID(), new NetworkCommon.ClientLoginAO2(), false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
if (server().players.size() < MazeSettings.MAXPLAYERS && !parent.gameManager.gameStarted) {
|
||||
uuid = UUID.randomUUID().toString();
|
||||
System.out.println("Client requested adding new player, giving it uuid " + uuid);
|
||||
((ServerLoginUUID)responsePacket).uuid = uuid;
|
||||
incomingConnection.sendUDP(responsePacket);
|
||||
}else {
|
||||
responseReceived(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASLoginUUID(server(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.login;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PlayerRemoved;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.RemovePlayer;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASRemovePlayer extends NetworkAction {
|
||||
|
||||
String uuid;
|
||||
|
||||
protected NASRemovePlayer(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NASRemovePlayer(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.RemovePlayer(), new NetworkCommon.PlayerRemoved(), null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
uuid = ((RemovePlayer) incomingMsg).uuid;
|
||||
System.out.println("Removing player with uuid " + uuid);
|
||||
if (server().players.containsKey(uuid)) {
|
||||
server().players.get(uuid).dispose();
|
||||
server().players.remove(uuid);
|
||||
((PlayerRemoved) responsePacket).uuid = uuid;
|
||||
System.out.println("Removed player " + uuid);
|
||||
} else {
|
||||
System.out.println("That player is not here");
|
||||
((PlayerRemoved) responsePacket).uuid = null;
|
||||
}
|
||||
|
||||
incomingConnection.sendUDP(responsePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASRemovePlayer(server(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.player;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdatePlayerPosition;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASUpdatePlayerPos extends NetworkAction {
|
||||
|
||||
protected NASUpdatePlayerPos(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NASUpdatePlayerPos(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.UpdatePlayerPosition(), null, null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
String uuid = ((UpdatePlayerPosition) incomingMsg).uuid;
|
||||
float px = ((UpdatePlayerPosition) incomingMsg).px;
|
||||
float py = ((UpdatePlayerPosition) incomingMsg).py;
|
||||
float pz = ((UpdatePlayerPosition) incomingMsg).pz;
|
||||
if (parent.players.containsKey(uuid) && server().canUpdatePos(uuid) && parent.gameManager.gameStarted) {
|
||||
parent.players.get(uuid).setPos(px, py, pz);
|
||||
server().server.sendToAllUDP(incomingMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASUpdatePlayerPos(server(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.player;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.UpdateForcedPlayerPositionOk;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASUpdatePlayerPosForced extends NetworkAction {
|
||||
|
||||
String uuid;
|
||||
|
||||
protected NASUpdatePlayerPosForced(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime, String uuid_) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
this.uuid = uuid_;
|
||||
server().setUpdatePos(uuid, false);
|
||||
}
|
||||
|
||||
public NASUpdatePlayerPosForced(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.UpdateForcedPlayerPosition(), new NetworkCommon.UpdateForcedPlayerPositionOk(), false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Here startAction needs to be overrided to allow for the uuid argument to be
|
||||
* passed from one instance to another and to remove the alreadyPending
|
||||
* limitation. Here we need to be able to call multiple instances of this at the
|
||||
* same time
|
||||
*/
|
||||
public void startAction(String s_) {
|
||||
this.startAction(incomingConnection, incomingMsg);
|
||||
}
|
||||
|
||||
public void startAction(Connection conn, Object msg, String uuid_) {
|
||||
this.incomingConnection = conn;
|
||||
this.incomingMsg = msg;
|
||||
this.uuid = uuid_;
|
||||
// System.out.println("Starting action: " + this);
|
||||
|
||||
parent.addToPending(newInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
responsePacket = parent.updatePlayer(uuid, parent.players.get(uuid), true);
|
||||
server().server.sendToAllUDP(responsePacket);
|
||||
}
|
||||
|
||||
/*
|
||||
* We also have to override the responseReceived package, because this action
|
||||
* has to finish only if the correct uuid has been received
|
||||
*/
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
this.endConnection = conn;
|
||||
this.endMsg = msg;
|
||||
if (((UpdateForcedPlayerPositionOk) endMsg).uuid.equals(uuid)) {
|
||||
detachFromParent();
|
||||
server().setUpdatePos(uuid, true);
|
||||
System.out.println("Response received for " + this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASUpdatePlayerPosForced(server(), incomingConnection, incomingMsg, responsePacket, endPacket,
|
||||
oneTime, uuid);
|
||||
}
|
||||
|
||||
}
|
|
@ -36,7 +36,7 @@ public class MazeSettings {
|
|||
AMazeIng.getMain().uiManager);
|
||||
|
||||
setStartPowerups = new MazeSettingStartPowerUps("POWERUPS AT START : ",
|
||||
new String[] { "1", "2", "3", "4", "5", "8", "10", "15" }, 6, AMazeIng.getMain().uiManager);
|
||||
new String[] { "1", "2", "3", "4", "5", "8", "10", "15" }, 2, AMazeIng.getMain().uiManager);
|
||||
|
||||
setEpDist = new MazeSettingEPDIST("END POINT DISTANCE:", new String[] { "1", "2", "5", "10", "20" }, 2,
|
||||
AMazeIng.getMain().uiManager);
|
||||
|
|
|
@ -147,12 +147,16 @@ public abstract class MazePlayer implements Disposable {
|
|||
public void usePowerUp() {
|
||||
if (currentPowerUp != null && !currentPowerUp.beingUsed)
|
||||
if (currentPowerUp.usePowerUp(this))
|
||||
currentPowerUp = null;
|
||||
disablePowerUp();
|
||||
}
|
||||
|
||||
public void disablePowerUp() {
|
||||
currentPowerUp = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (!disposed) {
|
||||
if (!isDisposed()) {
|
||||
if (show && built)
|
||||
mazePlayerModel.dispose();
|
||||
}
|
||||
|
|
|
@ -49,11 +49,11 @@ public class MazePlayerLocal extends MazePlayer {
|
|||
}
|
||||
|
||||
public MazePlayerLocal(int up_, int down_, int sx_, int dx_, int pup_) {
|
||||
this(up_, down_, sx_, dx_, pup_, 0, 0, 0);
|
||||
this(up_, down_, sx_, dx_, pup_, 8, 8, 8);
|
||||
}
|
||||
|
||||
public MazePlayerLocal(int up_, int down_, int sx_, int dx_, int pup_, String name) {
|
||||
this(up_, down_, sx_, dx_, pup_, 0, 0, 0, name);
|
||||
this(up_, down_, sx_, dx_, pup_, 8, 8, 8, name);
|
||||
}
|
||||
|
||||
public MazePlayerLocal(int up_, int down_, int sx_, int dx_, int pup_, float startx, float starty, float startz) {
|
||||
|
@ -197,7 +197,7 @@ public class MazePlayerLocal extends MazePlayer {
|
|||
((btDiscreteDynamicsWorld) (main.world.dynamicsWorld)).addAction(characterController);
|
||||
}
|
||||
|
||||
boolean pressed = false;
|
||||
public boolean pressed = false;
|
||||
|
||||
public void inputs() {
|
||||
pressed = false;
|
||||
|
@ -242,8 +242,10 @@ public class MazePlayerLocal extends MazePlayer {
|
|||
characterController.setWalkDirection(walkDirection);
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyJustPressed(kpup))
|
||||
if (Gdx.input.isKeyJustPressed(kpup)) {
|
||||
pressed = true;
|
||||
usePowerUp();
|
||||
}
|
||||
}
|
||||
|
||||
public void inputTouchscreen() {
|
||||
|
@ -280,13 +282,15 @@ public class MazePlayerLocal extends MazePlayer {
|
|||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
if(initedPhysics) inputs();
|
||||
if (initedPhysics)
|
||||
inputs();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateFromTmpPos() {
|
||||
super.updateFromTmpPos();
|
||||
if(initedPhysics) pos.set(ghostObject.getWorldTransform().getTranslation(new Vector3()));
|
||||
if (initedPhysics)
|
||||
pos.set(ghostObject.getWorldTransform().getTranslation(new Vector3()));
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
@ -310,8 +314,8 @@ public class MazePlayerLocal extends MazePlayer {
|
|||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
if (!isDisposed()) {
|
||||
mazePlayerModel.dispose();
|
||||
main.world.dynamicsWorld.removeAction(characterController);
|
||||
main.world.dynamicsWorld.removeCollisionObject(ghostObject);
|
||||
characterController.dispose();
|
||||
|
|
|
@ -14,16 +14,27 @@ public class PlayerUtils {
|
|||
public static int[] WASDKEYS = {Keys.W, Keys.S, Keys.A, Keys.D, Keys.SPACE};
|
||||
public static int[] ARROWKEYS = {Keys.UP, Keys.DOWN, Keys.LEFT, Keys.RIGHT, Keys.SHIFT_RIGHT};
|
||||
|
||||
public static boolean wasdPressed() {
|
||||
public static boolean wasdJustPressed() {
|
||||
for(int i : WASDKEYS)
|
||||
if(Gdx.input.isKeyJustPressed(i)) return true;
|
||||
return false;
|
||||
}
|
||||
public static boolean arrowsPressed() {
|
||||
public static boolean arrowsJustPressed() {
|
||||
for(int i : ARROWKEYS)
|
||||
if(Gdx.input.isKeyJustPressed(i)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean wasdPressed() {
|
||||
for(int i : WASDKEYS)
|
||||
if(Gdx.input.isKeyPressed(i)) return true;
|
||||
return false;
|
||||
}
|
||||
public static boolean arrowsPressed() {
|
||||
for(int i : ARROWKEYS)
|
||||
if(Gdx.input.isKeyPressed(i)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*Utility function to add and remove players from arrays when organizing as game*/
|
||||
|
|
|
@ -208,9 +208,9 @@ public class PlayerChooseScreen extends MyScreen {
|
|||
public void update() {
|
||||
// Consantly search for new players to be added
|
||||
// First search for keyboard players (WASD and ARROWS)
|
||||
if (PlayerUtils.wasdPressed())
|
||||
if (PlayerUtils.wasdJustPressed())
|
||||
PlayerUtils.togglePlayerWithKeys(players, PlayerUtils.WASDKEYS);
|
||||
if (PlayerUtils.arrowsPressed())
|
||||
if (PlayerUtils.arrowsJustPressed())
|
||||
PlayerUtils.togglePlayerWithKeys(players, PlayerUtils.ARROWKEYS);
|
||||
|
||||
// for (Controller c : Controllers.getControllers()) {
|
||||
|
|
|
@ -122,7 +122,7 @@ public class PreGameScreen extends MyScreen {
|
|||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
buildTable();
|
||||
// AMazeIng.getMain().client.setUpdateMobilePlayers();
|
||||
AMazeIng.getMain().client.setUpdateMobilePlayers();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -138,20 +138,19 @@ public class PreGameScreen extends MyScreen {
|
|||
super.buildTable();
|
||||
|
||||
firstRowTable.clear();
|
||||
|
||||
|
||||
float d = containerDiagonal();
|
||||
float labScale = d * .00090f;
|
||||
float buttonDim = d * 0.05f;
|
||||
|
||||
|
||||
if(AMazeIng.PLATFORM == AMazeIng.Platform.DESKTOP) {
|
||||
if (AMazeIng.PLATFORM == AMazeIng.Platform.DESKTOP) {
|
||||
labels = new Label[MazeSettings.MAXPLAYERS];
|
||||
|
||||
// Labels to know if players joined
|
||||
for (int i = 0; i < labels.length; i++) {
|
||||
labels[i] = new Label("-- empty slot --", uiManager.skin);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
labels = new Label[MazeSettings.MAXPLAYERS - MazeSettings.MAXPLAYERS_MOBILE];
|
||||
|
||||
// Labels to know if players joined
|
||||
|
@ -186,7 +185,7 @@ public class PreGameScreen extends MyScreen {
|
|||
table.row().colspan(4);
|
||||
table.add(firstRowContainer);
|
||||
|
||||
if(AMazeIng.PLATFORM != AMazeIng.Platform.DESKTOP){
|
||||
if (AMazeIng.PLATFORM != AMazeIng.Platform.DESKTOP) {
|
||||
table.row().expandY().fillY().colspan(6);
|
||||
table.add(MazeSettings.setPlayers_Mobile.getTable());
|
||||
table.add(mobileSetBtn).width(buttonDim).height(buttonDim).expandX();
|
||||
|
@ -216,7 +215,8 @@ public class PreGameScreen extends MyScreen {
|
|||
nPlayers = type == GameType.SERVER ? uiManager.main.server.players.size()
|
||||
: uiManager.main.client.players.size();
|
||||
|
||||
if(AMazeIng.isMobile()) nPlayers -= MazeSettings.MAXPLAYERS_MOBILE;
|
||||
if (AMazeIng.isMobile())
|
||||
nPlayers -= MazeSettings.MAXPLAYERS_MOBILE;
|
||||
|
||||
if (labels.length > 0) {
|
||||
// Update Labels
|
||||
|
@ -226,6 +226,7 @@ public class PreGameScreen extends MyScreen {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void setGameType(GameType t) {
|
||||
type = t;
|
||||
show();
|
||||
|
|
|
@ -14,14 +14,14 @@ import com.emamaker.amazeing.ui.UIManager;
|
|||
|
||||
public class ServerJoinScreen extends MyScreen {
|
||||
|
||||
Label instLab, srvIpL, helpDlgText, failDlgText;
|
||||
TextButton backBtn, connectBtn, helpBtn, helpDlgOkBtn, failDlgOkBtn;
|
||||
Label instLab, srvIpL, helpDlgText, failDlgText, errorDlgText;
|
||||
TextButton backBtn, connectBtn, helpBtn, helpDlgOkBtn, failDlgOkBtn, errorDlgOkBtn;
|
||||
TextArea srvIp;
|
||||
|
||||
Container<Table> firstRowContainer;
|
||||
Table firstRowTable;
|
||||
|
||||
Dialog helpDlg, failDlg;
|
||||
Dialog helpDlg, failDlg, errorDlg;
|
||||
|
||||
public ServerJoinScreen(UIManager uiManager_) {
|
||||
super(uiManager_);
|
||||
|
@ -60,7 +60,7 @@ public class ServerJoinScreen extends MyScreen {
|
|||
}
|
||||
});
|
||||
|
||||
failDlg = new Dialog("Server start-up failed", uiManager.skin);
|
||||
failDlg = new Dialog("Server connection failed", uiManager.skin);
|
||||
/* HELP DIALOG */
|
||||
failDlgText = new Label("Connection to the server failed. Check your internet connection and address/port combination.\n"
|
||||
+ "Or Pheraps there's no server running there?", uiManager.skin);
|
||||
|
@ -75,12 +75,26 @@ public class ServerJoinScreen extends MyScreen {
|
|||
}
|
||||
});
|
||||
|
||||
/* ERROR DIALOG */
|
||||
errorDlg = new Dialog("Error in communicating with server", uiManager.skin);
|
||||
errorDlgText = new Label("", uiManager.skin);
|
||||
errorDlg.text(helpDlgText);
|
||||
errorDlgOkBtn = new TextButton("OK", uiManager.skin);
|
||||
errorDlg.button(helpDlgOkBtn);
|
||||
errorDlg.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
errorDlg.hide();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// Add actions to the buttons
|
||||
backBtn.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
hide();
|
||||
uiManager.main.client.stop();
|
||||
// uiManager.main.client.stop();
|
||||
uiManager.main.setScreen(uiManager.titleScreen);
|
||||
return true;
|
||||
}
|
||||
|
@ -166,5 +180,23 @@ public class ServerJoinScreen extends MyScreen {
|
|||
// table.add(connectBtn).fillX().width(buttonDim*3f).height(buttonDim);
|
||||
table.add(connectBtn).fillX().expandX().height(buttonDim);
|
||||
}
|
||||
|
||||
|
||||
public void showErrorDlg(int errorType) {
|
||||
switch (errorType) {
|
||||
case 0:
|
||||
errorDlgText.setText("Server closed");
|
||||
break;
|
||||
case 1:
|
||||
errorDlgText.setText("Timed out");
|
||||
break;
|
||||
default:
|
||||
errorDlgText.setText("An unknown error with the server occurred\n"
|
||||
+ "Maybe check your internet connection?");
|
||||
break;
|
||||
}
|
||||
uiManager.main.setScreen(this);
|
||||
errorDlg.show(stage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class ServerLaunchScreen extends MyScreen {
|
|||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
hide();
|
||||
uiManager.main.server.stop();
|
||||
// uiManager.main.server.stop();
|
||||
uiManager.main.setScreen(uiManager.titleScreen);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
info face="Droid Sans" size=17 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1
|
||||
common lineHeight=20 base=18 scaleW=256 scaleH=128 pages=1 packed=0
|
||||
page id=0 file="default.png"
|
||||
chars count=96
|
||||
char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=16 xadvance=4 page=0 chnl=0
|
||||
char id=124 x=0 y=0 width=6 height=20 xoffset=1 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=106 x=6 y=0 width=9 height=20 xoffset=-4 yoffset=3 xadvance=4 page=0 chnl=0
|
||||
char id=81 x=15 y=0 width=15 height=19 xoffset=-2 yoffset=3 xadvance=12 page=0 chnl=0
|
||||
char id=74 x=30 y=0 width=11 height=19 xoffset=-5 yoffset=3 xadvance=4 page=0 chnl=0
|
||||
char id=125 x=41 y=0 width=10 height=18 xoffset=-3 yoffset=3 xadvance=6 page=0 chnl=0
|
||||
char id=123 x=51 y=0 width=10 height=18 xoffset=-3 yoffset=3 xadvance=6 page=0 chnl=0
|
||||
char id=93 x=61 y=0 width=8 height=18 xoffset=-3 yoffset=3 xadvance=5 page=0 chnl=0
|
||||
char id=91 x=69 y=0 width=8 height=18 xoffset=-2 yoffset=3 xadvance=5 page=0 chnl=0
|
||||
char id=41 x=77 y=0 width=9 height=18 xoffset=-3 yoffset=3 xadvance=5 page=0 chnl=0
|
||||
char id=40 x=86 y=0 width=9 height=18 xoffset=-3 yoffset=3 xadvance=5 page=0 chnl=0
|
||||
char id=64 x=95 y=0 width=18 height=17 xoffset=-3 yoffset=3 xadvance=14 page=0 chnl=0
|
||||
char id=121 x=113 y=0 width=13 height=17 xoffset=-3 yoffset=6 xadvance=8 page=0 chnl=0
|
||||
char id=113 x=126 y=0 width=13 height=17 xoffset=-3 yoffset=6 xadvance=9 page=0 chnl=0
|
||||
char id=112 x=139 y=0 width=13 height=17 xoffset=-2 yoffset=6 xadvance=9 page=0 chnl=0
|
||||
char id=103 x=152 y=0 width=13 height=17 xoffset=-3 yoffset=6 xadvance=8 page=0 chnl=0
|
||||
char id=38 x=165 y=0 width=16 height=16 xoffset=-3 yoffset=3 xadvance=11 page=0 chnl=0
|
||||
char id=37 x=181 y=0 width=18 height=16 xoffset=-3 yoffset=3 xadvance=14 page=0 chnl=0
|
||||
char id=36 x=199 y=0 width=12 height=16 xoffset=-2 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=63 x=211 y=0 width=11 height=16 xoffset=-3 yoffset=3 xadvance=7 page=0 chnl=0
|
||||
char id=33 x=222 y=0 width=7 height=16 xoffset=-2 yoffset=3 xadvance=4 page=0 chnl=0
|
||||
char id=48 x=229 y=0 width=13 height=16 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=57 x=242 y=0 width=13 height=16 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=56 x=0 y=20 width=13 height=16 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=54 x=13 y=20 width=13 height=16 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=53 x=26 y=20 width=12 height=16 xoffset=-2 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=51 x=38 y=20 width=13 height=16 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=100 x=51 y=20 width=13 height=16 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=98 x=64 y=20 width=13 height=16 xoffset=-2 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=85 x=77 y=20 width=14 height=16 xoffset=-2 yoffset=3 xadvance=11 page=0 chnl=0
|
||||
char id=83 x=91 y=20 width=13 height=16 xoffset=-3 yoffset=3 xadvance=8 page=0 chnl=0
|
||||
char id=79 x=104 y=20 width=15 height=16 xoffset=-2 yoffset=3 xadvance=12 page=0 chnl=0
|
||||
char id=71 x=119 y=20 width=14 height=16 xoffset=-2 yoffset=3 xadvance=11 page=0 chnl=0
|
||||
char id=67 x=133 y=20 width=13 height=16 xoffset=-2 yoffset=3 xadvance=10 page=0 chnl=0
|
||||
char id=127 x=146 y=20 width=12 height=15 xoffset=-2 yoffset=3 xadvance=10 page=0 chnl=0
|
||||
char id=35 x=158 y=20 width=15 height=15 xoffset=-3 yoffset=3 xadvance=10 page=0 chnl=0
|
||||
char id=92 x=173 y=20 width=11 height=15 xoffset=-3 yoffset=3 xadvance=6 page=0 chnl=0
|
||||
char id=47 x=184 y=20 width=11 height=15 xoffset=-3 yoffset=3 xadvance=6 page=0 chnl=0
|
||||
char id=59 x=195 y=20 width=8 height=15 xoffset=-3 yoffset=6 xadvance=4 page=0 chnl=0
|
||||
char id=55 x=203 y=20 width=13 height=15 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=52 x=216 y=20 width=14 height=15 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=50 x=230 y=20 width=13 height=15 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=49 x=243 y=20 width=9 height=15 xoffset=-2 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=116 x=0 y=36 width=10 height=15 xoffset=-3 yoffset=4 xadvance=5 page=0 chnl=0
|
||||
char id=108 x=10 y=36 width=6 height=15 xoffset=-2 yoffset=3 xadvance=4 page=0 chnl=0
|
||||
char id=107 x=16 y=36 width=12 height=15 xoffset=-2 yoffset=3 xadvance=8 page=0 chnl=0
|
||||
char id=105 x=28 y=36 width=7 height=15 xoffset=-2 yoffset=3 xadvance=4 page=0 chnl=0
|
||||
char id=104 x=35 y=36 width=12 height=15 xoffset=-2 yoffset=3 xadvance=10 page=0 chnl=0
|
||||
char id=102 x=47 y=36 width=11 height=15 xoffset=-3 yoffset=3 xadvance=5 page=0 chnl=0
|
||||
char id=90 x=58 y=36 width=13 height=15 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=89 x=71 y=36 width=13 height=15 xoffset=-3 yoffset=3 xadvance=8 page=0 chnl=0
|
||||
char id=88 x=84 y=36 width=14 height=15 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=87 x=98 y=36 width=19 height=15 xoffset=-3 yoffset=3 xadvance=15 page=0 chnl=0
|
||||
char id=86 x=117 y=36 width=14 height=15 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=84 x=131 y=36 width=13 height=15 xoffset=-3 yoffset=3 xadvance=8 page=0 chnl=0
|
||||
char id=82 x=144 y=36 width=13 height=15 xoffset=-2 yoffset=3 xadvance=10 page=0 chnl=0
|
||||
char id=80 x=157 y=36 width=12 height=15 xoffset=-2 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=78 x=169 y=36 width=14 height=15 xoffset=-2 yoffset=3 xadvance=12 page=0 chnl=0
|
||||
char id=77 x=183 y=36 width=17 height=15 xoffset=-2 yoffset=3 xadvance=14 page=0 chnl=0
|
||||
char id=76 x=200 y=36 width=11 height=15 xoffset=-2 yoffset=3 xadvance=8 page=0 chnl=0
|
||||
char id=75 x=211 y=36 width=13 height=15 xoffset=-2 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=73 x=224 y=36 width=10 height=15 xoffset=-3 yoffset=3 xadvance=5 page=0 chnl=0
|
||||
char id=72 x=234 y=36 width=14 height=15 xoffset=-2 yoffset=3 xadvance=11 page=0 chnl=0
|
||||
char id=70 x=0 y=51 width=11 height=15 xoffset=-2 yoffset=3 xadvance=8 page=0 chnl=0
|
||||
char id=69 x=11 y=51 width=11 height=15 xoffset=-2 yoffset=3 xadvance=8 page=0 chnl=0
|
||||
char id=68 x=22 y=51 width=14 height=15 xoffset=-2 yoffset=3 xadvance=11 page=0 chnl=0
|
||||
char id=66 x=36 y=51 width=13 height=15 xoffset=-2 yoffset=3 xadvance=10 page=0 chnl=0
|
||||
char id=65 x=49 y=51 width=15 height=15 xoffset=-3 yoffset=3 xadvance=10 page=0 chnl=0
|
||||
char id=58 x=64 y=51 width=7 height=13 xoffset=-2 yoffset=6 xadvance=4 page=0 chnl=0
|
||||
char id=117 x=71 y=51 width=12 height=13 xoffset=-2 yoffset=6 xadvance=10 page=0 chnl=0
|
||||
char id=115 x=83 y=51 width=11 height=13 xoffset=-3 yoffset=6 xadvance=7 page=0 chnl=0
|
||||
char id=111 x=94 y=51 width=13 height=13 xoffset=-3 yoffset=6 xadvance=9 page=0 chnl=0
|
||||
char id=101 x=107 y=51 width=13 height=13 xoffset=-3 yoffset=6 xadvance=9 page=0 chnl=0
|
||||
char id=99 x=120 y=51 width=12 height=13 xoffset=-3 yoffset=6 xadvance=7 page=0 chnl=0
|
||||
char id=97 x=132 y=51 width=12 height=13 xoffset=-3 yoffset=6 xadvance=9 page=0 chnl=0
|
||||
char id=60 x=144 y=51 width=13 height=12 xoffset=-3 yoffset=5 xadvance=9 page=0 chnl=0
|
||||
char id=122 x=157 y=51 width=11 height=12 xoffset=-3 yoffset=6 xadvance=7 page=0 chnl=0
|
||||
char id=120 x=168 y=51 width=13 height=12 xoffset=-3 yoffset=6 xadvance=8 page=0 chnl=0
|
||||
char id=119 x=181 y=51 width=17 height=12 xoffset=-3 yoffset=6 xadvance=12 page=0 chnl=0
|
||||
char id=118 x=198 y=51 width=13 height=12 xoffset=-3 yoffset=6 xadvance=8 page=0 chnl=0
|
||||
char id=114 x=211 y=51 width=10 height=12 xoffset=-2 yoffset=6 xadvance=6 page=0 chnl=0
|
||||
char id=110 x=221 y=51 width=12 height=12 xoffset=-2 yoffset=6 xadvance=10 page=0 chnl=0
|
||||
char id=109 x=233 y=51 width=17 height=12 xoffset=-2 yoffset=6 xadvance=15 page=0 chnl=0
|
||||
char id=94 x=0 y=66 width=13 height=11 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=62 x=13 y=66 width=13 height=11 xoffset=-3 yoffset=5 xadvance=9 page=0 chnl=0
|
||||
char id=42 x=26 y=66 width=13 height=10 xoffset=-3 yoffset=3 xadvance=9 page=0 chnl=0
|
||||
char id=43 x=39 y=66 width=13 height=10 xoffset=-3 yoffset=6 xadvance=9 page=0 chnl=0
|
||||
char id=61 x=52 y=66 width=13 height=8 xoffset=-3 yoffset=7 xadvance=9 page=0 chnl=0
|
||||
char id=39 x=65 y=66 width=6 height=8 xoffset=-2 yoffset=3 xadvance=3 page=0 chnl=0
|
||||
char id=34 x=71 y=66 width=9 height=8 xoffset=-2 yoffset=3 xadvance=6 page=0 chnl=0
|
||||
char id=44 x=80 y=66 width=8 height=7 xoffset=-3 yoffset=14 xadvance=4 page=0 chnl=0
|
||||
char id=126 x=88 y=66 width=13 height=6 xoffset=-3 yoffset=8 xadvance=9 page=0 chnl=0
|
||||
char id=46 x=101 y=66 width=7 height=6 xoffset=-2 yoffset=13 xadvance=4 page=0 chnl=0
|
||||
char id=96 x=108 y=66 width=8 height=6 xoffset=0 yoffset=2 xadvance=9 page=0 chnl=0
|
||||
char id=45 x=116 y=66 width=9 height=5 xoffset=-3 yoffset=10 xadvance=5 page=0 chnl=0
|
||||
char id=95 x=125 y=66 width=13 height=4 xoffset=-4 yoffset=17 xadvance=6 page=0 chnl=0
|
||||
kernings count=-1
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
varying vec2 v_texCoord0;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = vec4(v_texCoord0, 0.0, 1.0);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
attribute vec3 a_position;
|
||||
attribute vec3 a_normal;
|
||||
attribute vec2 a_texCoord0;
|
||||
|
||||
uniform mat4 u_worldTrans;
|
||||
uniform mat4 u_projViewTrans;
|
||||
|
||||
varying vec2 v_texCoord0;
|
||||
|
||||
void main() {
|
||||
v_texCoord0 = a_texCoord0;
|
||||
gl_Position = u_projViewTrans * u_worldTrans * vec4(a_position, 1.0);
|
||||
}
|
After Width: | Height: | Size: 28 KiB |
|
@ -0,0 +1,200 @@
|
|||
|
||||
uiskin.png
|
||||
size: 256,128
|
||||
format: RGBA8888
|
||||
filter: Linear,Linear
|
||||
repeat: none
|
||||
check-off
|
||||
rotate: false
|
||||
xy: 11, 5
|
||||
size: 14, 14
|
||||
orig: 14, 14
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
textfield
|
||||
rotate: false
|
||||
xy: 11, 5
|
||||
size: 14, 14
|
||||
split: 3, 3, 3, 3
|
||||
orig: 14, 14
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
check-on
|
||||
rotate: false
|
||||
xy: 125, 35
|
||||
size: 14, 14
|
||||
orig: 14, 14
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
cursor
|
||||
rotate: false
|
||||
xy: 23, 1
|
||||
size: 3, 3
|
||||
split: 1, 1, 1, 1
|
||||
orig: 3, 3
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default
|
||||
rotate: false
|
||||
xy: 1, 50
|
||||
size: 254, 77
|
||||
orig: 254, 77
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-pane
|
||||
rotate: false
|
||||
xy: 11, 1
|
||||
size: 5, 3
|
||||
split: 1, 1, 1, 1
|
||||
orig: 5, 3
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-rect-pad
|
||||
rotate: false
|
||||
xy: 11, 1
|
||||
size: 5, 3
|
||||
split: 1, 1, 1, 1
|
||||
orig: 5, 3
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-pane-noborder
|
||||
rotate: false
|
||||
xy: 170, 44
|
||||
size: 1, 1
|
||||
split: 0, 0, 0, 0
|
||||
orig: 1, 1
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-rect
|
||||
rotate: false
|
||||
xy: 38, 25
|
||||
size: 3, 3
|
||||
split: 1, 1, 1, 1
|
||||
orig: 3, 3
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-rect-down
|
||||
rotate: false
|
||||
xy: 170, 46
|
||||
size: 3, 3
|
||||
split: 1, 1, 1, 1
|
||||
orig: 3, 3
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-round
|
||||
rotate: false
|
||||
xy: 112, 29
|
||||
size: 12, 20
|
||||
split: 5, 5, 5, 4
|
||||
pad: 4, 4, 1, 1
|
||||
orig: 12, 20
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-round-down
|
||||
rotate: false
|
||||
xy: 99, 29
|
||||
size: 12, 20
|
||||
split: 5, 5, 5, 4
|
||||
pad: 4, 4, 1, 1
|
||||
orig: 12, 20
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-round-large
|
||||
rotate: false
|
||||
xy: 57, 29
|
||||
size: 20, 20
|
||||
split: 5, 5, 5, 4
|
||||
orig: 20, 20
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-scroll
|
||||
rotate: false
|
||||
xy: 78, 29
|
||||
size: 20, 20
|
||||
split: 2, 2, 2, 2
|
||||
orig: 20, 20
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-select
|
||||
rotate: false
|
||||
xy: 29, 29
|
||||
size: 27, 20
|
||||
split: 4, 14, 4, 4
|
||||
orig: 27, 20
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-select-selection
|
||||
rotate: false
|
||||
xy: 26, 16
|
||||
size: 3, 3
|
||||
split: 1, 1, 1, 1
|
||||
orig: 3, 3
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-slider
|
||||
rotate: false
|
||||
xy: 29, 20
|
||||
size: 8, 8
|
||||
split: 2, 2, 2, 2
|
||||
orig: 8, 8
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-slider-knob
|
||||
rotate: false
|
||||
xy: 1, 1
|
||||
size: 9, 18
|
||||
orig: 9, 18
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-splitpane
|
||||
rotate: false
|
||||
xy: 17, 1
|
||||
size: 5, 3
|
||||
split: 0, 5, 0, 0
|
||||
orig: 5, 3
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-splitpane-vertical
|
||||
rotate: false
|
||||
xy: 125, 29
|
||||
size: 3, 5
|
||||
split: 0, 0, 0, 5
|
||||
orig: 3, 5
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
default-window
|
||||
rotate: false
|
||||
xy: 1, 20
|
||||
size: 27, 29
|
||||
split: 4, 3, 20, 3
|
||||
orig: 27, 29
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
selection
|
||||
rotate: false
|
||||
xy: 174, 48
|
||||
size: 1, 1
|
||||
orig: 1, 1
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
tree-minus
|
||||
rotate: false
|
||||
xy: 140, 35
|
||||
size: 14, 14
|
||||
orig: 14, 14
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
tree-plus
|
||||
rotate: false
|
||||
xy: 155, 35
|
||||
size: 14, 14
|
||||
orig: 14, 14
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
white
|
||||
rotate: false
|
||||
xy: 129, 31
|
||||
size: 3, 3
|
||||
orig: 3, 3
|
||||
offset: 0, 0
|
||||
index: -1
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
BitmapFont: { default-font: { file: default.fnt } },
|
||||
Color: {
|
||||
green: { a: 1, b: 0, g: 1, r: 0 },
|
||||
white: { a: 1, b: 1, g: 1, r: 1 },
|
||||
red: { a: 1, b: 0, g: 0, r: 1 },
|
||||
black: { a: 1, b: 0, g: 0, r: 0 },
|
||||
},
|
||||
TintedDrawable: {
|
||||
dialogDim: { name: white, color: { r: 0, g: 0, b: 0, a: 0.45 } },
|
||||
},
|
||||
ButtonStyle: {
|
||||
default: { down: default-round-down, up: default-round },
|
||||
toggle: { parent: default, checked: default-round-down }
|
||||
},
|
||||
TextButtonStyle: {
|
||||
default: { parent: default, font: default-font, fontColor: white },
|
||||
toggle: { parent: default, checked: default-round-down, downFontColor: red }
|
||||
},
|
||||
ScrollPaneStyle: {
|
||||
default: { vScroll: default-scroll, hScrollKnob: default-round-large, background: default-rect, hScroll: default-scroll, vScrollKnob: default-round-large }
|
||||
},
|
||||
SelectBoxStyle: {
|
||||
default: {
|
||||
font: default-font, fontColor: white, background: default-select,
|
||||
scrollStyle: default,
|
||||
listStyle: { font: default-font, selection: default-select-selection }
|
||||
}
|
||||
},
|
||||
SplitPaneStyle: {
|
||||
default-vertical: { handle: default-splitpane-vertical },
|
||||
default-horizontal: { handle: default-splitpane }
|
||||
},
|
||||
WindowStyle: {
|
||||
default: { titleFont: default-font, background: default-window, titleFontColor: white },
|
||||
dialog: { parent: default, stageBackground: dialogDim }
|
||||
},
|
||||
ProgressBarStyle: {
|
||||
default-horizontal: { background: default-slider, knob: default-slider-knob },
|
||||
default-vertical: { background: default-slider, knob: default-round-large }
|
||||
},
|
||||
SliderStyle: {
|
||||
default-horizontal: { parent: default-horizontal },
|
||||
default-vertical: { parent: default-vertical }
|
||||
},
|
||||
LabelStyle: {
|
||||
default: { font: default-font, fontColor: white }
|
||||
},
|
||||
TextFieldStyle: {
|
||||
default: { selection: selection, background: textfield, font: default-font, fontColor: white, cursor: cursor }
|
||||
},
|
||||
CheckBoxStyle: {
|
||||
default: { checkboxOn: check-on, checkboxOff: check-off, font: default-font, fontColor: white }
|
||||
},
|
||||
ListStyle: {
|
||||
default: { fontColorUnselected: white, selection: selection, fontColorSelected: white, font: default-font }
|
||||
},
|
||||
TouchpadStyle: {
|
||||
default: { background: default-pane, knob: default-round-large }
|
||||
},
|
||||
TreeStyle: {
|
||||
default: { minus: tree-minus, plus: tree-plus, selection: default-select-selection }
|
||||
},
|
||||
TextTooltipStyle: {
|
||||
default: {
|
||||
label: { font: default-font, fontColor: white },
|
||||
background: default-pane, wrapWidth: 150
|
||||
}
|
||||
},
|
||||
}
|
After Width: | Height: | Size: 28 KiB |