Repository navigation
Exit to Main Menu and Load Game stay in the same window - #177
Open
MortenLyhr wants to merge 1 commit into
Open
MortenLyhr wants to merge 1 commit into
MortenLyhr wants to merge 1 commit into
Conversation
The game menu's Exit to Main Menu, its Load Game (and Ctrl+L), a quick load and a load from the game left the program and started it again: the window closed and a new one opened. The original goes back to its main menu, or on to the loaded game, in the same window. Now the game is torn down in the same process and the next one starts there: - GameSession::endGame resets the game core as at the start (players, teams, init core, map, game: the DLL's exported resets). The init core's active player must go too: else a loaded game's setActivePlayer does nothing and its slot stays reserved instead of assigned (a save written after differs). - Utility::endGame clears what the host kept of the game (queued messages, selection, popups, messages, city screen, battles and walks, plot marks, signs, globe, camera turn). - oc4screens.endGame closes the game's screens and the main interface. - MapWindow::clearMap empties the window for the menu and drops the game's helpers (popup, action and plot help), which pointed into the game that was. Another mod's save still starts that mod's program, as the original restarts into a save's mod; a multiplayer game still starts again (its connections). Checked: a save written right after a load from the menu, and after three turns played from there, equals one written after a fresh load (but for the turn timing bytes, which also differ between two fresh loads). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Clean room (#181): checked on 2026-11-25 against #181's clean-room rules and guides (
CONTRIBUTING.md"Clean room",AGENTS.md). This PR was written before #181; its sources are below, in #181's terms.What it is based on: the open-source game core (
CvDLLButtonPopup.cpp,CvGameInterface.cpp, the players', teams' and map'sreset). This exact flow was not checked in Wine, as the description says.strings), and nothing here comes from someone else's (CONTRIBUTING)In the game menu, Exit to Main Menu and Load Game (also Ctrl+L, a quick load, and a load the game core asks for when it leaves) quit OpenCiv4 and started it again: the window closed, a new process started (
--menu,--menu --menu-page loador--play --load <save>) and a new window opened. The original goes back to its main menu, or on to the loaded game, in the window it is in.Why it restarted. This was the host's design from the start (
main.cpp:g_relaunch,startAgain):wmainsets up one game and returns, so the next game was a new process. Nothing in the game core needs that.CvGame::init/read,CvMap::init/read,CvTeam::init/readandCvPlayer::init/readreset their objects first, andCvGame,CvMap,CvTeam,CvPlayerandCvInitCoreexportreset/initfor the engine to tear a game down. A new process is only needed where the game core itself would change: a save of another mod (its own DLL), which the original also answers by restarting into that mod.What changes
wmainplays games in a loop. When a game is left for the main menu (on its load page for Load Game) or for a save, the game is torn down and the menu or the save comes next, in the sameMapWindow.--keysgo on into the menu and the next game, so a whole session can be scripted.GameSession::endGameputs the game core back as it was before the first game: each player's and team'sreset,CvInitCore::init(NO_GAMEMODE),CvMap::resetwith an emptyCvMapInitData(no plots; the last game's map script is not asked),CvGame::reset. The init core matters: its active player is not saved, andCvGame::readclaims the human's slot throughCvGame::setActivePlayer, which does nothing when the active player is already that player. Without the reset, a save written after loading from the menu had the human's slotSLOTCLAIM_RESERVEDinstead ofSLOTCLAIM_ASSIGNED.Utility::endGameclears what the host kept of the game: the queued game messages, the diplomacy screen, and in the interface the selection, popups (queued and shown), messages, city screen, interface mode, WorldBuilder state and the camera's requests; the entities' walks, battles, actions, foundings, damage times and siege towers; the engine's plot marks, signs, effects, globe and camera turn. The display choices the player made (grid, resource and unit icons, yields, bare map) stay, as options do.oc4screens.endGame(Python) closes every screen the game had up, the main interface too, and forgets their widgets, so the menu doesn't draw the last game's interface (it did: the scoreboard's flag widget asked a player with no civilization and crashed).MapWindow::clearMap(andMapView::clear) empties the window for the menu: no map, no popup, no action buttons, help or messages, the camera unframed so the next game frames its own start. It also drops the game's helpers (action, popup and plot help), which pointed into locals of the game that was.loadElsewhere, as before and as the original). A multiplayer game (hosted or joined) still starts the program again for whatever comes next, since its connections belong to the process.Sources: the open-source game core (
CvDLLButtonPopup.cpp: the game menu's buttons,BUTTONPOPUP_CONFIRM_MENU→exitingToMainMenu(), Load Game →CONTROL_LOAD_GAME;CvGameInterface.cpp:CONTROL_LOAD_GAME→gDLL->LoadGame(),CONTROL_QUICK_LOAD;CvInitCore.cpp:readturnsSLOTCLAIM_ASSIGNEDintoSLOTCLAIM_RESERVED,setActivePlayerclaims the slot;CvGame.cpp:readandsetActivePlayer;CvMap.cpp:reset). The restart into a save's mod was seen in Wine earlier: loading a BUG save, the original offered to restart with BUG Mod (docs/wine-vs-openciv4-backlog.md, item 1). That the original stays in its window for Exit to Main Menu and Load Game is the user's report of the original; it was not filmed in Wine for this PR.Checks
--turns 100 --map Fractal --size STANDARD --seed 7):D7D43800, unchanged.8b7d8557,--play --load "TestMap Caesar"with BUG Mod, keys~#1#0: Esc, Exit to Main Menu, Yes): the process ends and a newoc4core … --menuprocess is running (out/before.log).--keys(BUG Mod,OC4_PLAY_LOG=1), all in one process and one window:~#1#0: the main menu, nothing of the game left on it (menu-after-exit.png; beforeclearMapdropped the window's popup, the game's "Are you sure?" stayed over it).~#1#0{MenuLoad}{MenuLoadGo}>>: back in the menu, the save loaded again, two turns played (t1.log,reload-played.png).^l{MenuLoadGo}…: Ctrl+L (the game menu's Load Game) opens the menu on its load page; the save loads (c1.log).~#1#0{MenuNew}{MenuLaunch}: a new game (Continents, 84x52) after the 150x104 save, framed on its settler, minimap as in a fresh new game (new-game-after-exit.png).~#1#0{MenuLoad}{MenuLoadGo}^s) equals one written after a fresh load (^s), part by part (savediff.py): init core and Python data the same, the game data different only in byte 20, which also differs between two fresh loads (the turn's timing). After three turns played (>>>^s), the two differ in the same 11 bytes as two fresh runs do.cycles.log): load, menu, load, menu, load, menu, new game, two turns.--keyscan't type), a load the game core asks for with a file (exitingToMainMenu(file)), loading another mod's save from inside a game (the menu's own path for that is unchanged), multiplayer.🤖 Generated with Claude Code