mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-06 23:59:18 +08:00
work on paused replays
This commit is contained in:
parent
13ad00029c
commit
e3ef47dfc0
@ -1579,7 +1579,7 @@ static auto PyRewindReplay(PyObject* self, PyObject* args) -> PyObject* {
|
|||||||
throw Exception(
|
throw Exception(
|
||||||
"Attempting to rewind a replay not in replay session context.");
|
"Attempting to rewind a replay not in replay session context.");
|
||||||
}
|
}
|
||||||
session->RestoreState();
|
session->RestoreState(session->base_time() - 2'000);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
BA_PYTHON_CATCH;
|
BA_PYTHON_CATCH;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -96,6 +96,12 @@ class ClientSession : public Session {
|
|||||||
target_base_time_millisecs_ = base_time_millisecs_;
|
target_base_time_millisecs_ = base_time_millisecs_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void SetBaseTime(millisecs_t time) {
|
||||||
|
base_time_millisecs_ = time;
|
||||||
|
ResetTargetBaseTime();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ClearSessionObjs();
|
void ClearSessionObjs();
|
||||||
void AddCommand(const std::vector<uint8_t>& command);
|
void AddCommand(const std::vector<uint8_t>& command);
|
||||||
|
|||||||
@ -18,7 +18,7 @@ auto ClientSessionReplay::GetActualTimeAdvanceMillisecs(
|
|||||||
double base_advance_millisecs) -> double {
|
double base_advance_millisecs) -> double {
|
||||||
auto* appmode = SceneV1AppMode::GetActiveOrFatal();
|
auto* appmode = SceneV1AppMode::GetActiveOrFatal();
|
||||||
if (appmode->is_replay_paused()) {
|
if (appmode->is_replay_paused()) {
|
||||||
return 0.0;
|
return 0.001;
|
||||||
}
|
}
|
||||||
return base_advance_millisecs * pow(2.0f, appmode->replay_speed_exponent());
|
return base_advance_millisecs * pow(2.0f, appmode->replay_speed_exponent());
|
||||||
}
|
}
|
||||||
@ -139,6 +139,7 @@ void ClientSessionReplay::FetchMessages() {
|
|||||||
SessionStream out(nullptr, false);
|
SessionStream out(nullptr, false);
|
||||||
DumpFullState(&out);
|
DumpFullState(&out);
|
||||||
|
|
||||||
|
current_state_.base_time_ = base_time();
|
||||||
current_state_.correction_messages_.clear();
|
current_state_.correction_messages_.clear();
|
||||||
GetCorrectionMessages(false, ¤t_state_.correction_messages_);
|
GetCorrectionMessages(false, ¤t_state_.correction_messages_);
|
||||||
|
|
||||||
@ -281,28 +282,28 @@ void ClientSessionReplay::OnReset(bool rewind) {
|
|||||||
|
|
||||||
void ClientSessionReplay::SaveState() { states_.push_back(current_state_); }
|
void ClientSessionReplay::SaveState() { states_.push_back(current_state_); }
|
||||||
|
|
||||||
void ClientSessionReplay::RestoreState() {
|
void ClientSessionReplay::RestoreState(millisecs_t to_base_time) {
|
||||||
ScreenMessage("restoring state " + std::to_string(states_.size()));
|
ScreenMessage("was: " + std::to_string(base_time()) + "ms");
|
||||||
const int N = 500;
|
ScreenMessage("want: " + std::to_string(to_base_time) + "ms");
|
||||||
|
|
||||||
if (states_.size() <= N) {
|
while (!states_.empty() && states_.back().base_time_ > to_base_time) {
|
||||||
states_.clear();
|
|
||||||
Reset(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i) {
|
|
||||||
states_.pop_back();
|
states_.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
current_state_ = states_.back();
|
if (states_.empty()) {
|
||||||
RestoreFromCurrentState();
|
Reset(true);
|
||||||
|
} else {
|
||||||
|
current_state_ = states_.back();
|
||||||
|
RestoreFromCurrentState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientSessionReplay::RestoreFromCurrentState() {
|
void ClientSessionReplay::RestoreFromCurrentState() {
|
||||||
// what to do with messages_fetch_num_? is it used somewhere at all?
|
// what to do with messages_fetch_num_? is it used somewhere at all?
|
||||||
Reset(true);
|
Reset(true);
|
||||||
fseek(file_, current_state_.file_position_, SEEK_SET);
|
fseek(file_, current_state_.file_position_, SEEK_SET);
|
||||||
|
|
||||||
|
SetBaseTime(current_state_.base_time_);
|
||||||
HandleSessionMessage(current_state_.message_);
|
HandleSessionMessage(current_state_.message_);
|
||||||
for (const auto& msg : current_state_.correction_messages_) {
|
for (const auto& msg : current_state_.correction_messages_) {
|
||||||
HandleSessionMessage(msg);
|
HandleSessionMessage(msg);
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class ClientSessionReplay : public ClientSession,
|
|||||||
void Error(const std::string& description) override;
|
void Error(const std::string& description) override;
|
||||||
void FetchMessages() override;
|
void FetchMessages() override;
|
||||||
void SaveState();
|
void SaveState();
|
||||||
void RestoreState();
|
void RestoreState(millisecs_t to_base_time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct IntermediateState {
|
struct IntermediateState {
|
||||||
@ -39,6 +39,8 @@ class ClientSessionReplay : public ClientSession,
|
|||||||
|
|
||||||
// A position in replay file where we should continue from.
|
// A position in replay file where we should continue from.
|
||||||
long file_position_;
|
long file_position_;
|
||||||
|
|
||||||
|
millisecs_t base_time_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void RestoreFromCurrentState();
|
void RestoreFromCurrentState();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user