Fixing bugs, unify velocity
This commit is contained in:
1 parent
fbc420e894
commit
f967807296
7 files changed
+153
-54
No files matched your search
+12
-11
@@ -57,13 +57,13 @@ class Session : public std::enable_shared_from_this<Session> {
|
||||
uint64_t clientTimestamp = std::stoull(parts[1]);
|
||||
|
||||
// Ñíà÷àëà ïðîãîíÿåì ñòàíäàðòíóþ ñèìóëÿöèþ "äî òåêóùåãî ìîìåíòà ñåðâåðà"
|
||||
float dt_server = 0.0f;
|
||||
long long deltaMs = 0.0f;
|
||||
if (state_.lastUpdateServerTime.time_since_epoch().count() > 0) {
|
||||
dt_server = (clientTimestamp - now_ms) * 1000.f;
|
||||
deltaMs = (clientTimestamp - now_ms);
|
||||
}
|
||||
|
||||
|
||||
if (dt_server > 0) state_.simulate_physics(dt_server);
|
||||
if (deltaMs > 0) state_.simulate_physics(deltaMs);
|
||||
|
||||
std::chrono::steady_clock::time_point uptime_timepoint{ std::chrono::duration_cast<std::chrono::steady_clock::time_point::duration>(std::chrono::milliseconds(clientTimestamp)) };
|
||||
state_.lastUpdateServerTime = uptime_timepoint;
|
||||
@@ -74,16 +74,19 @@ class Session : public std::enable_shared_from_this<Session> {
|
||||
state_.discreteAngle = std::stoi(parts[2]);
|
||||
state_.discreteMag = std::stof(parts[3]);
|
||||
state_.apply_lag_compensation(now_server);
|
||||
state_.lastUpdateServerTime = now_server;
|
||||
retranslateMessage(msg);
|
||||
}
|
||||
else if (parts[0] == "VEL") {
|
||||
state_.selectedVelocity = std::stoi(parts[2]);
|
||||
state_.apply_lag_compensation(now_server);
|
||||
state_.lastUpdateServerTime = now_server;
|
||||
retranslateMessage(msg);
|
||||
}
|
||||
else if (parts[0] == "PING") {
|
||||
state_.handle_full_sync(parts);
|
||||
state_.apply_lag_compensation(now_server);
|
||||
state_.lastUpdateServerTime = now_server;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,23 +134,21 @@ public:
|
||||
}
|
||||
|
||||
void tick_physics_global(std::chrono::steady_clock::time_point now) {
|
||||
float dt = 0.0f;
|
||||
long long deltaMs = 0;
|
||||
|
||||
// Åñëè ýòî ñàìûé ïåðâûé òèê, ïðîñòî çàïîìèíàåì âðåìÿ
|
||||
if (state_.lastUpdateServerTime.time_since_epoch().count() > 0) {
|
||||
dt = std::chrono::duration<float>(now - state_.lastUpdateServerTime).count();
|
||||
deltaMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
now - state_.lastUpdateServerTime
|
||||
).count();
|
||||
}
|
||||
|
||||
if (dt > 0.0001f) {
|
||||
state_.simulate_physics(dt);
|
||||
if (deltaMs > 0) {
|
||||
state_.simulate_physics(deltaMs);
|
||||
state_.lastUpdateServerTime = now; // Îáíîâëÿåì âðåìÿ ïîñëå ñèìóëÿöèè
|
||||
}
|
||||
}
|
||||
|
||||
void tick_physics(float dt_s) {
|
||||
state_.simulate_physics(dt_s);
|
||||
}
|
||||
|
||||
void send_message(std::string msg) {
|
||||
auto ss = std::make_shared<std::string>(std::move(msg));
|
||||
ws_.async_write(net::buffer(*ss), [ss](beast::error_code, std::size_t) {});
|
||||
|
||||
Reference in new issue
Block a user