update: added some Segments for Pipelining
This commit is contained in:
parent
2d72f0f5c0
commit
6eb16a2514
@ -8,6 +8,9 @@ import uulm.teamname.marvelous.gamelibrary.gamelogic.EventObserver;
|
|||||||
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
||||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||||
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||||
|
import uulm.teamname.marvelous.server.lobby.pipelining.PauseSegment;
|
||||||
|
import uulm.teamname.marvelous.server.lobby.pipelining.Pipeline;
|
||||||
|
import uulm.teamname.marvelous.server.lobby.pipelining.RequestGameStateSegment;
|
||||||
import uulm.teamname.marvelous.server.lobbymanager.LobbyConnection;
|
import uulm.teamname.marvelous.server.lobbymanager.LobbyConnection;
|
||||||
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
||||||
|
|
||||||
@ -17,6 +20,9 @@ public class Lobby extends EventObserver {
|
|||||||
public final String gameID;
|
public final String gameID;
|
||||||
public final LobbyConnection connection;
|
public final LobbyConnection connection;
|
||||||
public final GameInstance game;
|
public final GameInstance game;
|
||||||
|
public final Pipeline pipeline;
|
||||||
|
public final PauseSegment pauseSegment;
|
||||||
|
public final RequestGameStateSegment reqSegment;
|
||||||
private final PauseHandler pause = new PauseHandler();
|
private final PauseHandler pause = new PauseHandler();
|
||||||
|
|
||||||
public Lobby(String gameID, IntVector2 mapSize, LobbyConnection connection) {
|
public Lobby(String gameID, IntVector2 mapSize, LobbyConnection connection) {
|
||||||
@ -25,6 +31,10 @@ public class Lobby extends EventObserver {
|
|||||||
|
|
||||||
game = new GameInstance(mapSize);
|
game = new GameInstance(mapSize);
|
||||||
game.addObserver(this);
|
game.addObserver(this);
|
||||||
|
|
||||||
|
this.pipeline = new Pipeline();
|
||||||
|
this.pauseSegment = new PauseSegment();
|
||||||
|
this.reqSegment = new RequestGameStateSegment(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.EntityEvent;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||||
|
import uulm.teamname.marvelous.server.lobby.Lobby;
|
||||||
|
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
public class DisconnectSegment implements Segment {
|
||||||
|
private final Lobby parent;
|
||||||
|
private final Participant player;
|
||||||
|
public DisconnectSegment(Lobby parent, Participant player){
|
||||||
|
this.parent = parent;
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processRequests(List<Request> packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
|
if (packet.contains(new RequestBuilder(RequestType.DisconnectRequest).buildGameRequest())) {
|
||||||
|
carrier.add(new EventBuilder(EventType.DisconnectEvent).buildGameEvent());
|
||||||
|
parent.connection.removePlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
packet.clear();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||||
|
import uulm.teamname.marvelous.server.lobby.Lobby;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
public class GameStateSegment implements Segment{
|
||||||
|
private Lobby parent;
|
||||||
|
|
||||||
|
public GameStateSegment(Lobby parent){
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processRequests(List<Request> packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
|
if (packet.contains(new RequestBuilder(RequestType.MeleeAttackRequest).buildGameRequest())) {
|
||||||
|
carrier.add(new EventBuilder(EventType.MeleeAttackEvent).buildGameEvent());
|
||||||
|
}
|
||||||
|
if (packet.contains(new RequestBuilder(RequestType.RangedAttackRequest).buildGameRequest())) {
|
||||||
|
carrier.add(new EventBuilder(EventType.RangedAttackEvent).buildGameEvent());
|
||||||
|
}
|
||||||
|
if (packet.contains(new RequestBuilder(RequestType.MoveRequest).buildGameRequest())) {
|
||||||
|
carrier.add(new EventBuilder(EventType.MoveEvent).buildGameEvent());
|
||||||
|
}
|
||||||
|
if (packet.contains(new RequestBuilder(RequestType.ExchangeInfinityStoneRequest).buildGameRequest())) {
|
||||||
|
carrier.add(new EventBuilder(EventType.ExchangeInfinityStoneEvent).buildGameEvent());
|
||||||
|
}
|
||||||
|
if (packet.contains(new RequestBuilder(RequestType.UseInfinityStoneRequest).buildGameRequest())) {
|
||||||
|
carrier.add(new EventBuilder(EventType.UseInfinityStoneEvent).buildGameEvent());
|
||||||
|
}
|
||||||
|
if (packet.contains(new RequestBuilder(RequestType.EndRoundRequest).buildGameRequest())) {
|
||||||
|
//TODO what to do after EndRoundRequest
|
||||||
|
//carrier.add(new EventBuilder(EventType.EndRoundEvent).buildGameEvent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||||
|
import uulm.teamname.marvelous.server.lobby.Lobby;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
public class RequestGameStateSegment implements Segment {
|
||||||
|
|
||||||
|
private Lobby parent;
|
||||||
|
|
||||||
|
public RequestGameStateSegment(Lobby parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processRequests(List<Request> packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
|
if (packet.contains(new RequestBuilder(RequestType.Req).buildGameRequest())) {
|
||||||
|
carrier.add(parent.game.getGameStateEvent());
|
||||||
|
}
|
||||||
|
packet.clear();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user