53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
#pragma once
|
|
#include <chrono>
|
|
#include <Eigen/Dense>
|
|
#define _USE_MATH_DEFINES
|
|
#include <math.h>
|
|
#include <iostream>
|
|
|
|
|
|
using std::min;
|
|
using std::max;
|
|
|
|
constexpr float ANGULAR_ACCEL = 0.005f * 1000.0f;
|
|
constexpr float SHIP_ACCEL = 1.0f * 1000.0f;
|
|
constexpr float ROTATION_SENSITIVITY = 0.002f;
|
|
|
|
constexpr long long SERVER_DELAY = 0; //ms
|
|
constexpr long long CLIENT_DELAY = 200; //ms
|
|
constexpr long long CUTOFF_TIME = 5000; //ms
|
|
|
|
struct ClientState {
|
|
int id = 0;
|
|
Eigen::Vector3f position = { 0, 0, 45000.0f };
|
|
Eigen::Matrix3f rotation = Eigen::Matrix3f::Identity();
|
|
Eigen::Vector3f currentAngularVelocity = Eigen::Vector3f::Zero();
|
|
float velocity = 0.0f;
|
|
int selectedVelocity = 0;
|
|
float discreteMag = 0;
|
|
int discreteAngle = -1;
|
|
|
|
// Для расчета лага
|
|
std::chrono::system_clock::time_point lastUpdateServerTime;
|
|
|
|
void simulate_physics(size_t delta);
|
|
|
|
void apply_lag_compensation(std::chrono::system_clock::time_point nowTime);
|
|
|
|
void handle_full_sync(const std::vector<std::string>& parts, int startFrom);
|
|
|
|
std::string formPingMessageContent();
|
|
};
|
|
|
|
struct ClientStateInterval
|
|
{
|
|
std::vector<ClientState> timedStates;
|
|
|
|
void add_state(const ClientState& state);
|
|
|
|
bool canFetchClientStateAtTime(std::chrono::system_clock::time_point targetTime) const;
|
|
|
|
ClientState fetchClientStateAtTime(std::chrono::system_clock::time_point targetTime) const;
|
|
};
|
|
|