feat: created packet class for pipelining
This commit is contained in:
parent
74f3b86144
commit
0c2bc6cf6a
@ -1,11 +1,8 @@
|
|||||||
package uulm.teamname.marvelous.server.lobby.pipelining;
|
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.Event;
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
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.RequestBuilder;
|
||||||
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||||
import uulm.teamname.marvelous.server.lobby.Lobby;
|
import uulm.teamname.marvelous.server.lobby.Lobby;
|
||||||
@ -24,7 +21,7 @@ public class DisconnectSegment implements Segment {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(List<Request> packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
if (packet.contains(new RequestBuilder(RequestType.DisconnectRequest).buildGameRequest())) {
|
if (packet.contains(new RequestBuilder(RequestType.DisconnectRequest).buildGameRequest())) {
|
||||||
carrier.add(new EventBuilder(EventType.DisconnectEvent).buildGameEvent());
|
carrier.add(new EventBuilder(EventType.DisconnectEvent).buildGameEvent());
|
||||||
parent.connection.removePlayer(player);
|
parent.connection.removePlayer(player);
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
package uulm.teamname.marvelous.server.lobby.pipelining;
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
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.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.lobby.Lobby;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class GameStateSegment implements Segment{
|
public class GameStateSegment implements Segment {
|
||||||
private Lobby parent;
|
private Lobby parent;
|
||||||
|
|
||||||
public GameStateSegment(Lobby parent){
|
public GameStateSegment(Lobby parent){
|
||||||
@ -19,25 +15,28 @@ public class GameStateSegment implements Segment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(List<Request> packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
if (packet.contains(new RequestBuilder(RequestType.MeleeAttackRequest).buildGameRequest())) {
|
|
||||||
carrier.add(new EventBuilder(EventType.MeleeAttackEvent).buildGameEvent());
|
parent.game.checkRequestsAndApply(packet.toArray(new Request[0]));
|
||||||
}
|
|
||||||
if (packet.contains(new RequestBuilder(RequestType.RangedAttackRequest).buildGameRequest())) {
|
// if (packet.contains(new RequestBuilder(RequestType.MeleeAttackRequest).buildGameRequest())) {
|
||||||
carrier.add(new EventBuilder(EventType.RangedAttackEvent).buildGameEvent());
|
// carrier.add(new EventBuilder(EventType.MeleeAttackEvent).buildGameEvent());
|
||||||
}
|
// }
|
||||||
if (packet.contains(new RequestBuilder(RequestType.MoveRequest).buildGameRequest())) {
|
// if (packet.contains(new RequestBuilder(RequestType.RangedAttackRequest).buildGameRequest())) {
|
||||||
carrier.add(new EventBuilder(EventType.MoveEvent).buildGameEvent());
|
// carrier.add(new EventBuilder(EventType.RangedAttackEvent).buildGameEvent());
|
||||||
}
|
// }
|
||||||
if (packet.contains(new RequestBuilder(RequestType.ExchangeInfinityStoneRequest).buildGameRequest())) {
|
// if (packet.contains(new RequestBuilder(RequestType.MoveRequest).buildGameRequest())) {
|
||||||
carrier.add(new EventBuilder(EventType.ExchangeInfinityStoneEvent).buildGameEvent());
|
// carrier.add(new EventBuilder(EventType.MoveEvent).buildGameEvent());
|
||||||
}
|
// }
|
||||||
if (packet.contains(new RequestBuilder(RequestType.UseInfinityStoneRequest).buildGameRequest())) {
|
// if (packet.contains(new RequestBuilder(RequestType.ExchangeInfinityStoneRequest).buildGameRequest())) {
|
||||||
carrier.add(new EventBuilder(EventType.UseInfinityStoneEvent).buildGameEvent());
|
// carrier.add(new EventBuilder(EventType.ExchangeInfinityStoneEvent).buildGameEvent());
|
||||||
}
|
// }
|
||||||
if (packet.contains(new RequestBuilder(RequestType.EndRoundRequest).buildGameRequest())) {
|
// if (packet.contains(new RequestBuilder(RequestType.UseInfinityStoneRequest).buildGameRequest())) {
|
||||||
//TODO what to do after EndRoundRequest
|
// carrier.add(new EventBuilder(EventType.UseInfinityStoneEvent).buildGameEvent());
|
||||||
//carrier.add(new EventBuilder(EventType.EndRoundEvent).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,26 @@
|
|||||||
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Packet extends ArrayList<Request> {
|
||||||
|
|
||||||
|
public Packet (Request[] requests) {
|
||||||
|
addAll(Arrays.asList(requests));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsRequestOfType(RequestType requiredType) {
|
||||||
|
for (Request request : this) {
|
||||||
|
if (request.type == requiredType) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -53,7 +53,7 @@ public class PauseSegment implements Segment {
|
|||||||
* @param packet
|
* @param packet
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(List<Request> packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
// check if there is a pause request (either start or stop)
|
// check if there is a pause request (either start or stop)
|
||||||
if (packet.contains(new RequestBuilder(RequestType.PauseStartRequest).buildGameRequest())) {
|
if (packet.contains(new RequestBuilder(RequestType.PauseStartRequest).buildGameRequest())) {
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
|
@ -3,10 +3,7 @@ package uulm.teamname.marvelous.server.lobby.pipelining;
|
|||||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,7 +37,7 @@ public class Pipeline {
|
|||||||
*/
|
*/
|
||||||
public Optional<Event[]> processRequests(Request[] requests) {
|
public Optional<Event[]> processRequests(Request[] requests) {
|
||||||
// The packet carries the requests, and gets smaller per segment
|
// The packet carries the requests, and gets smaller per segment
|
||||||
List<Request> packet = Arrays.asList(requests);
|
Packet packet = new Packet(requests);
|
||||||
// The packet is filled by the requests resulting from events per segment
|
// The packet is filled by the requests resulting from events per segment
|
||||||
List<Event> carrier = new ArrayList<>();
|
List<Event> carrier = new ArrayList<>();
|
||||||
// The abort boolean describes whether an abort happened in a segment
|
// The abort boolean describes whether an abort happened in a segment
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package uulm.teamname.marvelous.server.lobby.pipelining;
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
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.RequestBuilder;
|
||||||
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||||
import uulm.teamname.marvelous.server.lobby.Lobby;
|
import uulm.teamname.marvelous.server.lobby.Lobby;
|
||||||
@ -18,7 +17,7 @@ public class RequestGameStateSegment implements Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(List<Request> packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
if (packet.contains(new RequestBuilder(RequestType.Req).buildGameRequest())) {
|
if (packet.contains(new RequestBuilder(RequestType.Req).buildGameRequest())) {
|
||||||
carrier.add(parent.game.getGameStateEvent());
|
carrier.add(parent.game.getGameStateEvent());
|
||||||
}
|
}
|
||||||
|
@ -21,5 +21,5 @@ public interface Segment {
|
|||||||
* of the segment, but instead an error in the events passed to it, like for example moving into a Rock.
|
* of the segment, but instead an error in the events passed to it, like for example moving into a Rock.
|
||||||
* The conventional way of setting this boolean is to write {@code abort.set(true); return;}
|
* The conventional way of setting this boolean is to write {@code abort.set(true); return;}
|
||||||
*/
|
*/
|
||||||
public void processRequests(List<Request> packet, List<Event> carrier, AtomicBoolean abort);
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user