Change clock to system clock, fix bugs

This commit is contained in:
Vladislav Khorev committed 2026-01-17 13:59:02 +03:00
1 parent f967807296
commit e0a60dcd6f
4 files changed
+28 -27

No files matched your search

+6 -12
View File
@@ -24,7 +24,7 @@ struct ClientState {
int discreteAngle = -1;
// Для расчета лага
std::chrono::steady_clock::time_point lastUpdateServerTime;
std::chrono::system_clock::time_point lastUpdateServerTime;
void simulate_physics(size_t delta) {
// Константы из Game.cpp, приведенные к секундам (умножаем на 1000)
@@ -87,6 +87,10 @@ struct ClientState {
Eigen::Quaternionf rotateQuat(Eigen::AngleAxisf(deltaAlpha, axis));
rotation = rotation * rotateQuat.toRotationMatrix();
//std::cout << "Rotating ship. d="<< delta <<" DeltaAlpha: " << deltaAlpha << ", Axis: [" << axis.x() << ", " << axis.y() << ", " << axis.z() << "]\n";
}
else {
//std::cout << "NOT Rotating ship. speedScale=" << speedScale << " discreteMag=" << discreteMag << "\n";
}
/*
@@ -154,7 +158,6 @@ struct ClientState {
velocity = shipDesiredVelocity;
}
}
std::cout << "velocity=" << velocity << " delta=" << delta << std::endl;
if (fabs(velocity) > 0.01f)
{
@@ -164,16 +167,7 @@ struct ClientState {
}
}
void apply_lag_compensation(std::chrono::steady_clock::time_point nowTime) {
// 1. Получаем текущее время сервера в той же шкале (мс)
/*uto now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch()
).count();
long long deltaMs = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch() - lastUpdateServerTime
).count();*/
void apply_lag_compensation(std::chrono::system_clock::time_point nowTime) {
// 2. Вычисляем задержку
long long deltaMs = 0;
+6 -3
View File
@@ -69,7 +69,7 @@ namespace ZL {
void WebSocketClient::Poll() {
std::lock_guard<std::mutex> lock(queueMutex);
auto nowTime = std::chrono::steady_clock::now();
auto nowTime = std::chrono::system_clock::now();
auto now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
nowTime.time_since_epoch()
@@ -98,6 +98,7 @@ namespace ZL {
rp.discreteAngle = std::stoi(parts[4]);
rp.discreteMag = std::stof(parts[5]);
}
std::cout << "EVENT Received discreteMag=" << rp.discreteMag << std::endl;
// --- ÊÎÌÏÅÍÑÀÖÈß ËÀÃÀ ---
// Âû÷èñëÿåì çàäåðæêó â ñåêóíäàõ
@@ -160,9 +161,11 @@ namespace ZL {
rp.velocity = std::stof(vals[8]);
rp.currentAngularVelocity = { std::stof(vals[9]), std::stof(vals[10]), std::stof(vals[11]) };
rp.selectedVelocity = std::stoi(vals[12]);
rp.discreteMag = std::stoi(vals[13]);
rp.discreteMag = std::stof(vals[13]);
rp.discreteAngle = std::stoi(vals[14]);
std::chrono::steady_clock::time_point uptime_timepoint{ std::chrono::duration_cast<std::chrono::steady_clock::time_point::duration>(std::chrono::milliseconds(serverTime)) };
std::chrono::system_clock::time_point uptime_timepoint{ std::chrono::duration_cast<std::chrono::system_clock::time_point::duration>(std::chrono::milliseconds(serverTime)) };
std::cout << "PING Received discreteMag=" << rp.discreteMag << std::endl;
rp.lastUpdateServerTime = uptime_timepoint;