Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Not in a step, but trying to add event". #11844

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import games.strategy.engine.history.Event;
import games.strategy.engine.history.EventChild;
import games.strategy.engine.history.HistoryNode;
import games.strategy.engine.history.HistoryWriter;
import games.strategy.engine.history.Step;
import games.strategy.engine.message.ConnectionLostException;
import games.strategy.engine.message.IRemote;
Expand Down Expand Up @@ -117,13 +118,17 @@ public ServerGame(
this.clientNetworkBridge = clientNetworkBridge;
this.launchAction = launchAction;
this.inGameLobbyWatcher = inGameLobbyWatcher;
// Keep a ref to the history writer. This not only makes the calls below more concise, but also
// prevents a need to grab the lock on gameData (as its history object can get reset temporarily
// during game cloning operations for the battle calculator, e.g. by AIs).
final HistoryWriter historyWriter = gameData.getHistory().getHistoryWriter();
gameModifiedChannel =
new IGameModifiedChannel() {
@Override
public void gameDataChanged(final Change change) {
assertCorrectCaller();
gameData.performChange(change);
gameData.getHistory().getHistoryWriter().addChange(change);
historyWriter.addChange(change);
}

private void assertCorrectCaller() {
Expand All @@ -143,21 +148,18 @@ public void startHistoryEvent(final String event, final Object renderingData) {
@Override
public void startHistoryEvent(final String event) {
assertCorrectCaller();
gameData.getHistory().getHistoryWriter().startEvent(event);
historyWriter.startEvent(event);
}

@Override
public void addChildToEvent(final String text, final Object renderingData) {
assertCorrectCaller();
gameData
.getHistory()
.getHistoryWriter()
.addChildToEvent(new EventChild(text, renderingData));
historyWriter.addChildToEvent(new EventChild(text, renderingData));
}

void setRenderingData(final Object renderingData) {
assertCorrectCaller();
gameData.getHistory().getHistoryWriter().setRenderingData(renderingData);
historyWriter.setRenderingData(renderingData);
}

@Override
Expand All @@ -172,10 +174,7 @@ public void stepChanged(
if (loadedFromSavedGame) {
return;
}
gameData
.getHistory()
.getHistoryWriter()
.startNextStep(stepName, delegateName, player, displayName);
historyWriter.startNextStep(stepName, delegateName, player, displayName);
}

// nothing to do, we call this
Expand Down