wip: Request pipelining
This commit is contained in:
parent
7142d2f642
commit
fcf43fcd83
@ -1,6 +1,10 @@
|
||||
package uulm.teamname.marvelous.server.Lobby;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.Character;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
||||
@ -8,7 +12,9 @@ import uulm.teamname.marvelous.gamelibrary.gamelogic.EventObserver;
|
||||
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
||||
import uulm.teamname.marvelous.gamelibrary.gamelogic.ParticipantType;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||
import uulm.teamname.marvelous.server.LobbyManager.LobbyConnection;
|
||||
import uulm.teamname.marvelous.server.LobbyManager.Participant;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -16,6 +22,7 @@ public class Lobby extends EventObserver {
|
||||
public final String gameID;
|
||||
public final LobbyConnection connection;
|
||||
public final GameInstance game;
|
||||
private final PauseHandler pause = new PauseHandler();
|
||||
|
||||
public Lobby(String gameID, IntVector2 mapSize, LobbyConnection connection) {
|
||||
this.gameID = gameID;
|
||||
@ -30,16 +37,31 @@ public class Lobby extends EventObserver {
|
||||
connection.broadcastEvents(events);
|
||||
}
|
||||
|
||||
public void receiveRequests(ParticipantType source, Request[] requests) {
|
||||
public void receiveRequests(Participant source, Request[] requests) {
|
||||
ArrayList<Request> stateRelevant = new ArrayList<>();
|
||||
|
||||
for(Request request: requests) {
|
||||
switch(request.type) {
|
||||
case MeleeAttackRequest, RangedAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> {
|
||||
if(!pause.isPaused()) {
|
||||
//if game is paused, no actions should happen
|
||||
stateRelevant.add(request); // these need to be checked all together by the game instance itself
|
||||
}
|
||||
else {
|
||||
connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent());
|
||||
}
|
||||
}
|
||||
case PauseStopRequest, PauseStartRequest, EndRoundRequest, DisconnectRequest, Req -> {
|
||||
//if game is paused only PauseStop, Disconnect and Req are available
|
||||
if(!pause.isPaused()){
|
||||
processRequest(source, request);
|
||||
}
|
||||
else if(request.type != RequestType.PauseStartRequest && request.type != RequestType.EndRoundRequest ) {
|
||||
processRequest(source, request);
|
||||
}
|
||||
else {
|
||||
connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent());
|
||||
}
|
||||
return; // only one of these will ever be sent at once, and if that is the case, we wont have any other state relevant events
|
||||
}
|
||||
}
|
||||
@ -51,58 +73,38 @@ public class Lobby extends EventObserver {
|
||||
}
|
||||
}
|
||||
|
||||
private void processRequest(ParticipantType source, Request request) {
|
||||
private void processRequest(Participant source, Request request) {
|
||||
//TODO: handle the rest of the requests
|
||||
switch(request.type) {
|
||||
case PauseStopRequest -> {
|
||||
|
||||
pause.pauseEnd();
|
||||
connection.sendEvents(source, new EventBuilder(EventType.PauseStopEvent).buildGameStateEvent(), game.getGameStateEvent());
|
||||
}
|
||||
case PauseStartRequest -> {
|
||||
|
||||
pause.pauseGame();
|
||||
connection.sendEvents(source, new EventBuilder(EventType.PauseStartEvent).buildGameStateEvent(), game.getGameStateEvent());
|
||||
}
|
||||
case EndRoundRequest -> {
|
||||
|
||||
}
|
||||
case DisconnectRequest -> {
|
||||
|
||||
connection.removePlayer(source);
|
||||
connection.sendEvents(source, new EventBuilder(EventType.DisconnectEvent).buildGameStateEvent(), game.getGameStateEvent());
|
||||
}
|
||||
case Req -> {
|
||||
|
||||
connection.sendEvents(source, game.getGameStateEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
public void endRound(){
|
||||
ArrayList Entitys = new ArrayList<>();
|
||||
for (EntityID id : game.state.getTurnOrder()) {
|
||||
if(((Character) game.state.getEntities().findEntity(id)).hp.getValue() == 0){
|
||||
|
||||
}
|
||||
public void unpause(){
|
||||
|
||||
}
|
||||
public void handleDisconnects(){
|
||||
|
||||
}
|
||||
public void DisconnectClient(){
|
||||
|
||||
}
|
||||
public void checkCheating(){
|
||||
|
||||
}
|
||||
public void SendGamestate(){
|
||||
|
||||
}
|
||||
public void handleConnects(){
|
||||
|
||||
}
|
||||
public void handleSpectators(){
|
||||
|
||||
}
|
||||
public void handlePlayers(){
|
||||
|
||||
}
|
||||
public void handleLogon(){
|
||||
|
||||
}
|
||||
public void handleLogoff(){
|
||||
int index = game.state.getTurnOrder().indexOf(game.state.getActiveCharacter());
|
||||
|
||||
}
|
||||
public void closeLobby(){
|
||||
|
@ -0,0 +1,21 @@
|
||||
package uulm.teamname.marvelous.server.Lobby;
|
||||
|
||||
public class PauseHandler {
|
||||
private boolean paused;
|
||||
|
||||
public PauseHandler(){
|
||||
paused = false;
|
||||
}
|
||||
public void pauseGame(){
|
||||
if(!paused)
|
||||
paused = true;
|
||||
}
|
||||
public void pauseEnd(){
|
||||
if(paused)
|
||||
paused = false;
|
||||
}
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package uulm.teamname.marvelous.server.Lobby;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Pipeline {
|
||||
|
||||
private final Segment[] segments;
|
||||
|
||||
public Pipeline(Segment[] segments) {
|
||||
this.segments = segments;
|
||||
}
|
||||
|
||||
public void processEvents(Request[] requests) {
|
||||
Request[] out;
|
||||
for (Segment segment: segments) {
|
||||
out = segment.processEvents(requests);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package uulm.teamname.marvelous.server.Lobby;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||
|
||||
public interface Segment {
|
||||
public Request[] processEvents(Request[] events);
|
||||
}
|
Loading…
Reference in New Issue
Block a user