Skip to content

Commit cab3761

Browse files
committed
Fixed bug whether the controller was not able to process new snapshots.
1 parent 81813b0 commit cab3761

3 files changed

Lines changed: 35 additions & 43 deletions

File tree

core/peer_networked_controller.cpp

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ bool DollController::fetch_next_input(double p_delta) {
14661466
return false;
14671467
}
14681468

1469-
if (closest_frame_index > 0) {
1469+
if (closest_frame_index >= 0) {
14701470
// It was impossible to find the input, so just pick the closest one and
14711471
// assume it's the one we are executing.
14721472
FrameInput guessed_fi = frames_input[closest_frame_index];
@@ -1518,33 +1518,33 @@ void DollController::on_state_validated(FrameIndex p_frame_index, bool p_detecte
15181518
}
15191519

15201520
void DollController::notify_frame_checked(FrameIndex p_doll_frame_index) {
1521-
if (p_doll_frame_index == FrameIndex::NONE) {
1522-
// Nothing to do.
1523-
return;
1524-
}
1525-
15261521
if (last_doll_validated_input != FrameIndex::NONE && last_doll_validated_input >= p_doll_frame_index) {
15271522
// Already checked.
15281523
return;
15291524
}
15301525

1531-
// Removes all the inputs older than the known one (included).
1532-
while (!frames_input.empty() && frames_input.front().id <= p_doll_frame_index) {
1533-
if (frames_input.front().id == p_doll_frame_index) {
1534-
// Pause the streaming if the last frame is empty.
1535-
streaming_paused = (frames_input.front().buffer_size_bit - METADATA_SIZE) <= 0;
1526+
if (p_doll_frame_index != FrameIndex::NONE) {
1527+
// Removes all the inputs older than the known one (included).
1528+
while (!frames_input.empty() && frames_input.front().id <= p_doll_frame_index) {
1529+
if (frames_input.front().id == p_doll_frame_index) {
1530+
// Pause the streaming if the last frame is empty.
1531+
streaming_paused = (frames_input.front().buffer_size_bit - METADATA_SIZE) <= 0;
1532+
}
1533+
frames_input.pop_front();
15361534
}
1537-
frames_input.pop_front();
1538-
}
15391535

1540-
// Remove all the server snapshots which doll frame was already executed.
1541-
while (!server_snapshots.empty() && server_snapshots.front().doll_executed_input <= p_doll_frame_index) {
1542-
VecFunc::remove_at(server_snapshots, 0);
1543-
}
1536+
// Remove all the server snapshots which doll frame was already executed.
1537+
while (!server_snapshots.empty() && server_snapshots.front().doll_executed_input <= p_doll_frame_index) {
1538+
VecFunc::remove_at(server_snapshots, 0);
1539+
}
15441540

1545-
// Removed all the checked doll frame snapshots.
1546-
while (!client_snapshots.empty() && client_snapshots.front().doll_executed_input <= p_doll_frame_index) {
1547-
VecFunc::remove_at(client_snapshots, 0);
1541+
// Removed all the checked doll frame snapshots.
1542+
while (!client_snapshots.empty() && client_snapshots.front().doll_executed_input <= p_doll_frame_index) {
1543+
VecFunc::remove_at(client_snapshots, 0);
1544+
}
1545+
} else {
1546+
VecFunc::remove(server_snapshots, FrameIndex::NONE);
1547+
VecFunc::remove(client_snapshots, FrameIndex::NONE);
15481548
}
15491549

15501550
last_doll_validated_input = p_doll_frame_index;
@@ -1650,7 +1650,7 @@ void DollController::copy_controlled_objects_snapshot(
16501650
is_doll_snap_A_older);
16511651
}
16521652

1653-
FrameIndex DollController::fetch_best_recoverable_snapshot(DollSnapshot *&r_client_snapshot, DollSnapshot *&r_server_snapshot) {
1653+
FrameIndex DollController::fetch_last_processed_recoverable_snapshot(DollSnapshot *&r_client_snapshot, DollSnapshot *&r_server_snapshot) {
16541654
for (auto client_snap_it = client_snapshots.rbegin(); client_snap_it != client_snapshots.rend(); client_snap_it++) {
16551655
if (client_snap_it->doll_executed_input != FrameIndex::NONE) {
16561656
auto server_snap_it = VecFunc::find(server_snapshots, client_snap_it->doll_executed_input);
@@ -1696,7 +1696,7 @@ bool DollController::__pcr__fetch_recovery_info(
16961696

16971697
// This is valid until we reset it again.
16981698
is_last_doll_compared_input_valid = true;
1699-
last_doll_compared_input = fetch_best_recoverable_snapshot(client_snapshot, server_snapshot);
1699+
last_doll_compared_input = fetch_last_processed_recoverable_snapshot(client_snapshot, server_snapshot);
17001700

17011701
if (last_doll_compared_input == FrameIndex::NONE) {
17021702
// Nothing to check.
@@ -1729,18 +1729,15 @@ void DollController::on_snapshot_applied(
17291729

17301730
queued_frame_index_to_process = FrameIndex{ 0 };
17311731

1732-
if (!is_last_doll_compared_input_valid) {
1733-
DollSnapshot *client_snapshot;
1734-
DollSnapshot *server_snapshot;
1735-
last_doll_compared_input = fetch_best_recoverable_snapshot(client_snapshot, server_snapshot);
1736-
}
1732+
const int input_count = frames_input.size();
17371733

1738-
if make_unlikely (last_doll_compared_input == FrameIndex::NONE || p_frame_count_to_rewind <= 0) {
1734+
// 1. Ensure the input reconciliation algorithm can process, otherwise:
1735+
if make_unlikely (input_count <= 0 || p_frame_count_to_rewind <= 0) {
17391736
// - On the server, the doll was not processed so just apply the server snapshot.
17401737
// - In case of no rewinding, it applies the most up to date server snapshot right away.
1741-
auto server_snapshot_it = VecFunc::find(server_snapshots, last_doll_compared_input);
1742-
ENSURE_MSG(server_snapshot_it != server_snapshots.end(), "This should be impossible. The doll was unable to set the server snapshot since the snapshot was not found: " + last_doll_compared_input);
1743-
static_cast<ClientSynchronizer *>(peer_controller->scene_synchronizer->get_synchronizer_internal())->apply_snapshot(server_snapshot_it->data, 0, 0, nullptr, true, true, true, true, true);
1738+
ENSURE_MSG(!server_snapshots.empty(), "This should be impossible. The doll was unable to set the server snapshot since there are no server snapshots.");
1739+
static_cast<ClientSynchronizer *>(peer_controller->scene_synchronizer->get_synchronizer_internal())->apply_snapshot(server_snapshots.back().data, 0, 0, nullptr, true, true, true, true, true);
1740+
last_doll_compared_input = server_snapshots.back().doll_executed_input;
17441741
// Reset the current_input_buffer_id, to make sure the next Frame processed starts from here.
17451742
current_input_buffer_id = last_doll_compared_input;
17461743
return;
@@ -1751,14 +1748,10 @@ void DollController::on_snapshot_applied(
17511748
// best moment to manipulate the processing (to consume or build the input
17521749
// queue) and avoid to make it noticeable.
17531750

1754-
// 1. Fetch the optimal queued inputs (how many inputs should be queued based
1751+
// 2. Fetch the optimal queued inputs (how many inputs should be queued based
17551752
// on the current connection).
17561753
const int optimal_queued_inputs = fetch_optimal_queued_inputs();
17571754

1758-
// 2. Get the input count.
1759-
const int input_count = frames_input.size();
1760-
ENSURE_MSG(input_count > 0, "This function is not supposed to work with 0 inputs. Report this bug.")
1761-
17621755
// 3. Fetch the best input to start processing.
17631756
const int optimal_input_count = p_frame_count_to_rewind + optimal_queued_inputs;
17641757

core/peer_networked_controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ struct DollController final : public RemotelyControlledController {
418418
std::vector<DollSnapshot> &r_snapshots,
419419
bool p_store_even_when_doll_is_not_processing);
420420

421-
FrameIndex fetch_best_recoverable_snapshot(DollSnapshot *&r_client_snapshot, DollSnapshot *&r_server_snapshot);
421+
FrameIndex fetch_last_processed_recoverable_snapshot(DollSnapshot *&r_client_snapshot, DollSnapshot *&r_server_snapshot);
422422

423423
// Checks whether this doll requires a reconciliation.
424424
// The check done is relative to the doll timeline, and not the scene sync timeline.

tests/tests.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ void NS_Test::test_all() {
1111
NS::LocalSceneSynchronizer::install_local_scene_sync();
1212

1313
// TODO test DataBuffer.
14-
// TODO enable these again.
15-
//test_data_buffer();
16-
//test_processor();
17-
//test_local_network();
18-
//test_scene_synchronizer();
19-
//test_simulation();
14+
test_data_buffer();
15+
test_processor();
16+
test_local_network();
17+
test_scene_synchronizer();
18+
test_simulation();
2019
test_doll_simulation();
2120

2221
NS::LocalSceneSynchronizer::uninstall_local_scene_sync();

0 commit comments

Comments
 (0)