Change clock to system clock, fix bugs
This commit is contained in:
1 parent
f967807296
commit
e0a60dcd6f
4 files changed
+28
-27
No files matched your search
+8
-6
@@ -40,7 +40,7 @@ class Session : public std::enable_shared_from_this<Session> {
|
||||
ClientState state_;
|
||||
|
||||
void process_message(const std::string& msg) {
|
||||
auto now_server = std::chrono::steady_clock::now();
|
||||
auto now_server = std::chrono::system_clock::now();
|
||||
|
||||
// Ïðåäïîëîæèì ôîðìàò ñîîáùåíèé:
|
||||
// ROT:ANGLE:MAG:TIMESTAMP
|
||||
@@ -65,7 +65,7 @@ class Session : public std::enable_shared_from_this<Session> {
|
||||
|
||||
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)) };
|
||||
std::chrono::system_clock::time_point uptime_timepoint{ std::chrono::duration_cast<std::chrono::system_clock::time_point::duration>(std::chrono::milliseconds(clientTimestamp)) };
|
||||
state_.lastUpdateServerTime = uptime_timepoint;
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ class Session : public std::enable_shared_from_this<Session> {
|
||||
if (parts[0] == "ROT") {
|
||||
state_.discreteAngle = std::stoi(parts[2]);
|
||||
state_.discreteMag = std::stof(parts[3]);
|
||||
std::cout << "ROT id = " << this->id_ << " discreteMag=" << state_.discreteMag << std::endl;
|
||||
state_.apply_lag_compensation(now_server);
|
||||
state_.lastUpdateServerTime = now_server;
|
||||
retranslateMessage(msg);
|
||||
@@ -85,6 +86,7 @@ class Session : public std::enable_shared_from_this<Session> {
|
||||
}
|
||||
else if (parts[0] == "PING") {
|
||||
state_.handle_full_sync(parts);
|
||||
std::cout << "PING id = " << this->id_ <<" discreteMag=" << state_.discreteMag << std::endl;
|
||||
state_.apply_lag_compensation(now_server);
|
||||
state_.lastUpdateServerTime = now_server;
|
||||
}
|
||||
@@ -110,7 +112,7 @@ public:
|
||||
|
||||
void init()
|
||||
{
|
||||
state_.lastUpdateServerTime = std::chrono::steady_clock::now();
|
||||
state_.lastUpdateServerTime = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
std::string get_state_string() {
|
||||
@@ -133,7 +135,7 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
void tick_physics_global(std::chrono::steady_clock::time_point now) {
|
||||
void tick_physics_global(std::chrono::system_clock::time_point now) {
|
||||
long long deltaMs = 0;
|
||||
|
||||
// Åñëè ýòî ñàìûé ïåðâûé òèê, ïðîñòî çàïîìèíàåì âðåìÿ
|
||||
@@ -181,7 +183,7 @@ private:
|
||||
};
|
||||
|
||||
void update_world(net::steady_timer& timer, net::io_context& ioc) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto now = std::chrono::system_clock::now();
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_sessions_mutex);
|
||||
@@ -196,7 +198,7 @@ void update_world(net::steady_timer& timer, net::io_context& ioc) {
|
||||
last_broadcast = now;
|
||||
|
||||
auto now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()
|
||||
std::chrono::system_clock::now().time_since_epoch()
|
||||
).count();
|
||||
|
||||
// Ñîáèðàåì äàííûå âñåõ èãðîêîâ â îäèí ïàêåò
|
||||
|
||||
Reference in new issue
Block a user