Skip to content

Commit 9b541e5

Browse files
committed
Basically working... the timing is a bit off during replay
1 parent 85c50b3 commit 9b541e5

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

source/code/BlockGame.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,15 @@ void BlockGame::NewGame(const BlockGameStartInfo& s) {
372372
void BlockGame::NewGameInternal( unsigned int ticks) {
373373
this->ticks = ticks;
374374
stageButtonStatus = SBdontShow;
375+
hangTicks = ticks / FRAMELENGTH; // Must be relative to ticks for replay determinism
376+
bGarbageFallLeft = false; // Reset for deterministic garbage placement
375377
nrFellDown = 0;
376378
nrPushedPixel = 0;
377379
nrStops = 0;
378380
cursorx = 2;
379381
cursory = 3;
382+
mouse_cursorx = -1;
383+
mouse_cursory = -1;
380384
stop = 0;
381385
pixels = 0;
382386
score = 0;

source/code/main.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ int runGame(Gametype gametype, int level) {
15331533
unsigned int currentStartTime = SDL_GetTicks();
15341534
unsigned int originalStartTime = replayInfo.startInfo.ticks;
15351535
replayTimeOffset = currentStartTime - originalStartTime;
1536-
1536+
15371537
// Adjust startInfo ticks to current time
15381538
replayInfo.startInfo.ticks = currentStartTime;
15391539
theGame.NewGame(replayInfo.startInfo);
@@ -1960,32 +1960,31 @@ int runGame(Gametype gametype, int level) {
19601960

19611961
//set bNearDeath to false theGame*.Update() will change to true as needed
19621962
bNearDeath = theGame.IsNearDeath() || theGame2.IsNearDeath();
1963-
1963+
19641964
// Process replay actions if in replay mode
19651965
if (isReplayMode) {
19661966
unsigned int currentTick = SDL_GetTicks();
1967+
// Process all actions from the replay queue up to the current time
1968+
// We MUST use recorded UPDATE tick values to maintain deterministic state
19671969
while (replayActionIndex < replayQueue.size()) {
19681970
const BlockGameAction& replayAction = replayQueue[replayActionIndex];
1969-
// Process all actions up to the current tick
1970-
if (replayAction.action == BlockGameAction::Action::UPDATE) {
1971-
if (replayAction.tick > currentTick) {
1972-
break; // Wait for the right time
1973-
}
1974-
theGame.DoAction(replayAction);
1975-
replayActionIndex++;
1976-
break; // Only process one UPDATE per frame
1977-
} else {
1978-
// Non-UPDATE actions can be processed immediately
1979-
theGame.DoAction(replayAction);
1980-
replayActionIndex++;
1971+
1972+
// Check if it's time to process this action
1973+
if (replayAction.tick > currentTick) {
1974+
break; // Wait for the right time
19811975
}
1976+
1977+
// Process the action with its original recorded tick value
1978+
theGame.DoAction(replayAction);
1979+
replayActionIndex++;
19821980
}
1983-
} else {
1981+
}
1982+
else {
19841983
//Updates the objects (only when not in replay mode)
19851984
a.action = BlockGameAction::Action::UPDATE;
19861985
theGame.DoAction(a);
19871986
}
1988-
1987+
19891988
// Always update player 2
19901989
a.action = BlockGameAction::Action::UPDATE;
19911990
theGame2.DoAction(a);

source/code/replayhandler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ bool LoadLatestSinglePlayerReplay(BlockGameInfo& game1) {
101101
game1 = sr.playerInfo.at(0);
102102
return true;
103103
}
104-
} catch (const std::exception& e) {
104+
}
105+
catch (const std::exception& e) {
105106
return false;
106107
}
107108
return false;

0 commit comments

Comments
 (0)