added random spaceship type

This commit is contained in:
Vlad committed 2026-02-24 19:51:33 +06:00
1 parent 3893038d9a
commit ad7294ceea
5 files changed
+59 -23

No files matched your search

+20 -19
View File
@@ -13,12 +13,12 @@ constexpr auto NET_SECRET = "880b3713b9ff3e7a94b2712d54679e1f";
#define ENABLE_NETWORK_CHECKSUM
constexpr float ANGULAR_ACCEL = 0.005f * 1000.0f;
constexpr float SHIP_ACCEL = 1.0f * 1000.0f;
constexpr float SHIP_ACCEL = 1.0f * 1000.0f;
constexpr float ROTATION_SENSITIVITY = 0.002f;
constexpr float PLANET_RADIUS = 20000.f;
constexpr float PLANET_ALIGN_ZONE = 1.05f;
constexpr float PLANET_ANGULAR_ACCEL = 0.01f; // Подбери под динамику
constexpr float PLANET_ANGULAR_ACCEL = 0.01f; // ??????? ??? ????????
constexpr float PLANET_MAX_ANGULAR_VELOCITY = 10.f;
constexpr float PITCH_LIMIT = static_cast<float>(M_PI) / 9.f;//18.0f;
@@ -29,35 +29,36 @@ constexpr long long CUTOFF_TIME = 5000; //ms
uint32_t fnv1a_hash(const std::string& data);
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;
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;
int shipType = 0;
// ??? ??????? ????
std::chrono::system_clock::time_point lastUpdateServerTime;
void simulate_physics(size_t delta);
void simulate_physics(size_t delta);
void apply_lag_compensation(std::chrono::system_clock::time_point nowTime);
void apply_lag_compensation(std::chrono::system_clock::time_point nowTime);
void handle_full_sync(const std::vector<std::string>& parts, int startFrom);
void handle_full_sync(const std::vector<std::string>& parts, int startFrom);
std::string formPingMessageContent();
std::string formPingMessageContent();
};
struct ClientStateInterval
{
std::vector<ClientState> timedStates;
void add_state(const ClientState& state);
void add_state(const ClientState& state);
bool canFetchClientStateAtTime(std::chrono::system_clock::time_point targetTime) const;
bool canFetchClientStateAtTime(std::chrono::system_clock::time_point targetTime) const;
ClientState fetchClientStateAtTime(std::chrono::system_clock::time_point targetTime) const;
ClientState fetchClientStateAtTime(std::chrono::system_clock::time_point targetTime) const;
};
+9
View File
@@ -79,6 +79,10 @@ namespace ZL {
void LocalClient::initializeNPCs() {
npcs.clear();
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> typeDistrib(0, 1); // 0 = default ship, 1 = cargo
for (int i = 0; i < 3; ++i) {
LocalNPC npc;
npc.id = 100 + i;
@@ -91,6 +95,11 @@ namespace ZL {
npc.currentState.discreteAngle = -1;
npc.currentState.currentAngularVelocity = Eigen::Vector3f::Zero();
// random
int shipType = typeDistrib(gen);
npc.shipType = shipType;
npc.currentState.shipType = shipType;
npc.targetPosition = generateRandomPosition();
npc.lastStateUpdateMs = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
+1
View File
@@ -31,6 +31,7 @@ namespace ZL {
Eigen::Vector3f targetPosition;
uint64_t lastStateUpdateMs = 0;
bool destroyed = false;
int shipType = 0;
};
class LocalClient : public INetworkClient {