doc: added logging
This commit is contained in:
parent
30a8a03eb2
commit
aecfcd2d42
@ -1,5 +1,6 @@
|
|||||||
package uulm.teamname.marvelous.server.lobby.pipelining;
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
|
import org.tinylog.Logger;
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||||
import uulm.teamname.marvelous.server.ParticipantType;
|
import uulm.teamname.marvelous.server.ParticipantType;
|
||||||
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||||
@ -19,7 +20,9 @@ public class DisconnectSegment implements Segment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
|
Logger.trace("DisconnectSegment received {} requests.", packet.size());
|
||||||
if (packet.containsRequestOfType(RequestType.DisconnectRequest)) {
|
if (packet.containsRequestOfType(RequestType.DisconnectRequest)) {
|
||||||
|
Logger.debug("Player {} sent DisconnectRequest", packet.getOrigin().type);
|
||||||
parent.connection.removePlayer(packet.getOrigin());
|
parent.connection.removePlayer(packet.getOrigin());
|
||||||
|
|
||||||
if (packet.getOrigin().type != ParticipantType.Spectator) {
|
if (packet.getOrigin().type != ParticipantType.Spectator) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package uulm.teamname.marvelous.server.lobby.pipelining;
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
|
import org.tinylog.Logger;
|
||||||
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.gamelogic.GameInstance;
|
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
||||||
@ -19,7 +20,9 @@ public class GameStateSegment implements Segment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
|
Logger.trace("GameStateSegment received {} requests.", packet.size());
|
||||||
var result = game.checkRequestsAndApply(packet.toArray(new Request[0]));
|
var result = game.checkRequestsAndApply(packet.toArray(new Request[0]));
|
||||||
|
Logger.trace("GameLogic gener");
|
||||||
if (result.isPresent()) {
|
if (result.isPresent()) {
|
||||||
carrier.addAll(result.get());
|
carrier.addAll(result.get());
|
||||||
packet.clear();
|
packet.clear();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package uulm.teamname.marvelous.server.lobby.pipelining;
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
|
import org.tinylog.Logger;
|
||||||
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;
|
||||||
@ -19,12 +20,16 @@ public class PauseSegment implements Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void pauseGame(){
|
public void pauseGame(){
|
||||||
if(!paused)
|
if(!paused) {
|
||||||
paused = true;
|
paused = true;
|
||||||
|
Logger.debug("Game paused.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void pauseEnd(){
|
public void pauseEnd(){
|
||||||
if(paused)
|
if(paused) {
|
||||||
paused = false;
|
paused = false;
|
||||||
|
Logger.debug("Game unpaused.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPaused() {
|
public boolean isPaused() {
|
||||||
@ -54,55 +59,48 @@ public class PauseSegment implements Segment {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
|
Logger.trace("PauseSegment received {} requests. PausedState is {}", packet.size(), paused);
|
||||||
// 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())) {
|
||||||
|
Logger.trace("PauseStartRequest found");
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
// pause the game
|
// pause the game
|
||||||
pauseGame();
|
pauseGame();
|
||||||
// create a new PauseStartEvent
|
// create a new PauseStartEvent
|
||||||
carrier.add(new EventBuilder(EventType.PauseStartEvent).buildGameEvent());
|
carrier.add(new EventBuilder(EventType.PauseStartEvent).buildGameEvent());
|
||||||
|
Logger.trace("Added PauseStartEvent to pipeline carrier");
|
||||||
} else { // if the game is already paused
|
} else { // if the game is already paused
|
||||||
|
Logger.info("PauseStartRequest sent even though the game wasn't paused. Error triggered.");
|
||||||
abort.set(true);
|
abort.set(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (packet.contains(new RequestBuilder(RequestType.PauseStopRequest).buildGameRequest())) {
|
} else if (packet.contains(new RequestBuilder(RequestType.PauseStopRequest).buildGameRequest())) {
|
||||||
|
Logger.trace("PauseStopRequest found");
|
||||||
if (paused) {
|
if (paused) {
|
||||||
// pause the game
|
|
||||||
pauseEnd();
|
pauseEnd();
|
||||||
|
Logger.debug("Game unpaused.");
|
||||||
// create a new PauseStartRequest
|
// create a new PauseStartRequest
|
||||||
carrier.add(new EventBuilder(EventType.PauseStopEvent).buildGameEvent());
|
carrier.add(new EventBuilder(EventType.PauseStopEvent).buildGameEvent());
|
||||||
|
Logger.trace("Added PauseStopEvent to pipeline carrier");
|
||||||
} else { // if the game is not paused
|
} else { // if the game is not paused
|
||||||
|
Logger.info("PauseStopRequest sent even though the game wasn't paused. Error triggered.");
|
||||||
abort.set(true);
|
abort.set(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* filter the events
|
|
||||||
if (paused) {
|
if (paused) {
|
||||||
for (Request request: packet) {
|
Logger.trace("As the game is paused, Requests are removed.");
|
||||||
switch (request.type) {
|
packet.removeRequestsOfTypes(
|
||||||
case MeleeAttackRequest,
|
RequestType.MeleeAttackRequest,
|
||||||
RangedAttackRequest,
|
RequestType.RangedAttackRequest,
|
||||||
MoveRequest,
|
RequestType.MoveRequest,
|
||||||
ExchangeInfinityStoneRequest,
|
RequestType.ExchangeInfinityStoneRequest,
|
||||||
UseInfinityStoneRequest,
|
RequestType.UseInfinityStoneRequest,
|
||||||
EndRoundRequest,
|
RequestType.EndRoundRequest,
|
||||||
PauseStopRequest,
|
RequestType.PauseStopRequest,
|
||||||
PauseStartRequest -> packet.remove(request);
|
RequestType.PauseStartRequest);
|
||||||
|
|
||||||
case DisconnectRequest, Req -> { /* do nothing }
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
packet.removeRequestsOfTypes(
|
|
||||||
RequestType.MeleeAttackRequest,
|
|
||||||
RequestType.RangedAttackRequest,
|
|
||||||
RequestType.MoveRequest,
|
|
||||||
RequestType.ExchangeInfinityStoneRequest,
|
|
||||||
RequestType.UseInfinityStoneRequest,
|
|
||||||
RequestType.EndRoundRequest,
|
|
||||||
RequestType.PauseStopRequest,
|
|
||||||
RequestType.PauseStartRequest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package uulm.teamname.marvelous.server.lobby.pipelining;
|
package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||||
|
|
||||||
|
import org.tinylog.Logger;
|
||||||
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 uulm.teamname.marvelous.server.lobbymanager.Participant;
|
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
||||||
@ -37,6 +38,7 @@ public class Pipeline {
|
|||||||
* {@link Optional#isEmpty()} or {@link Optional#isPresent()}, and act accordingly.
|
* {@link Optional#isEmpty()} or {@link Optional#isPresent()}, and act accordingly.
|
||||||
*/
|
*/
|
||||||
public Optional<Event[]> processRequests(Request[] requests, Participant origin) {
|
public Optional<Event[]> processRequests(Request[] requests, Participant origin) {
|
||||||
|
Logger.trace("Pipeline started RequestProcessing");
|
||||||
// The packet carries the requests, and gets smaller per segment
|
// The packet carries the requests, and gets smaller per segment
|
||||||
Packet packet = new Packet(requests, origin);
|
Packet packet = new Packet(requests, origin);
|
||||||
// The packet is filled by the requests resulting from events per segment
|
// The packet is filled by the requests resulting from events per segment
|
||||||
@ -44,6 +46,7 @@ public class Pipeline {
|
|||||||
// The abort boolean describes whether an abort happened in a segment
|
// The abort boolean describes whether an abort happened in a segment
|
||||||
AtomicBoolean abort = new AtomicBoolean(false);
|
AtomicBoolean abort = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
Logger.trace("Iterating through segments");
|
||||||
// Loop through all segments
|
// Loop through all segments
|
||||||
for (Segment segment: segments) {
|
for (Segment segment: segments) {
|
||||||
// Give the segment the packet, carrier and abort, and let it process requests
|
// Give the segment the packet, carrier and abort, and let it process requests
|
||||||
@ -53,8 +56,10 @@ public class Pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (abort.get()) { // if abort is true, return empty optional
|
if (abort.get()) { // if abort is true, return empty optional
|
||||||
|
Logger.debug("Abort triggered in Pipeline");
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
} else { // else return an optional of the array
|
} else { // else return an optional of the array
|
||||||
|
Logger.trace("Pipeline executed normally. Returning {} events.", carrier.size());
|
||||||
return Optional.of(carrier.toArray(new Event[0]));
|
return Optional.of(carrier.toArray(new Event[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user