Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#2130 closed enhancement (fixed)

[PATCH] Clean up endGameManager code

Reported by: sanderd17 Owned by: sanderd17
Priority: Nice to Have Milestone: Alpha 15
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

The EndGameManager has some dirty code that gets executed once a second via timers.

Instead, I update it every turn, but with cached values to save work. And only check the entire state if something changed to the cache (which doesn't happen often).

I tried to not change any functionality, but it should be tested if it still works in all cases (diplomacy, saved games, resign ...)

Attachments (8)

endgame.diff (5.6 KB ) - added by sanderd17 11 years ago.
endgame.2.diff (6.2 KB ) - added by sanderd17 10 years ago.
endgame.3.diff (6.2 KB ) - added by sanderd17 10 years ago.
endgame.4.diff (6.3 KB ) - added by sanderd17 10 years ago.
endgame.5.diff (6.3 KB ) - added by sanderd17 10 years ago.
endgame.6.diff (6.1 KB ) - added by sanderd17 10 years ago.
endgame.7.diff (6.1 KB ) - added by sanderd17 10 years ago.
endgame.8.diff (6.0 KB ) - added by sanderd17 10 years ago.

Download all attachments as: .zip

Change History (17)

by sanderd17, 11 years ago

Attachment: endgame.diff added

comment:1 by sanderd17, 10 years ago

Keywords: review removed

Hmm, the current patch seems to break saved games because of the cmpPlayer instances it saves. Instead, it should just save the player IDs.

comment:2 by sanderd17, 10 years ago

Alternative version of the patch, it's a lot cleaner IMO.

by sanderd17, 10 years ago

Attachment: endgame.2.diff added

comment:3 by sanderd17, 10 years ago

Keywords: review added

comment:4 by leper, 10 years ago

I'm quite sure that line 70 (after the patch) shouldn't be return;. Probably the else clause shouldn't be there at all.

Line 76 could be inverted to an if (...) return;.

comment:5 by sanderd17, 10 years ago

You're right about line 76.

About line 70, I do think there needs to be a return. The point of that code is to see if you need to mark players as "won". So you store all allies. The moment you have more than solely allies, you don't need to mark a player as "won", so you can simply return.

There is a problem in that loop though, the allies array will contain duplicates of the player ids, they should only appear once. So it should break earlier and not continue the entire for loop.

by sanderd17, 10 years ago

Attachment: endgame.3.diff added

comment:6 by leper, 10 years ago

What about making the for loops (line 58-74) into two non-nested for loops? That would make the logic easier to understand and be a lot less convoluted.

comment:7 by sanderd17, 10 years ago

leper, better?

by sanderd17, 10 years ago

Attachment: endgame.4.diff added

by sanderd17, 10 years ago

Attachment: endgame.5.diff added

by sanderd17, 10 years ago

Attachment: endgame.6.diff added

by sanderd17, 10 years ago

Attachment: endgame.7.diff added

by sanderd17, 10 years ago

Attachment: endgame.8.diff added

comment:8 by sanderd17, 10 years ago

Owner: set to sanderd17
Resolution: fixed
Status: newclosed

In 14087:

Clean up EndGameManager. Fixes #2130

comment:9 by sanderd17, 10 years ago

Keywords: review removed
Note: See TracTickets for help on using tickets.