added random spaceship type
This commit is contained in:
parent
3893038d9a
commit
ad7294ceea
@ -310,6 +310,21 @@ namespace ZL
|
||||
spaceship.AssignFrom(spaceshipBase);
|
||||
spaceship.RefreshVBO();
|
||||
|
||||
// Load cargo
|
||||
cargoTexture = std::make_shared<Texture>(CreateTextureDataFromPng("resources/Cargo_Base_color_sRGB.png", CONST_ZIP_FILE));
|
||||
cargoBase = LoadFromTextFile02("resources/cargoship001.txt", CONST_ZIP_FILE);
|
||||
auto quat = Eigen::Quaternionf(Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitZ()));
|
||||
auto rotMatrix = quat.toRotationMatrix();
|
||||
cargoBase.RotateByMatrix(rotMatrix);
|
||||
|
||||
auto quat2 = Eigen::Quaternionf(Eigen::AngleAxisf(M_PI * 0.5, Eigen::Vector3f::UnitY()));
|
||||
auto rotMatrix2 = quat2.toRotationMatrix();
|
||||
cargoBase.RotateByMatrix(rotMatrix2);
|
||||
//cargoBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
cargoBase.Move(Vector3f{ 1.2, 0, -5 });
|
||||
cargo.AssignFrom(cargoBase);
|
||||
cargo.RefreshVBO();
|
||||
|
||||
|
||||
//Boxes
|
||||
boxTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/box/box.png", CONST_ZIP_FILE));
|
||||
@ -588,8 +603,8 @@ namespace ZL
|
||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||
|
||||
// Биндим текстуру корабля один раз для всех удаленных игроков (оптимизация батчинга)
|
||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||
// Биндим текŃ<C59F>Ń‚Ń<E2809A>Ń€Ń<E282AC> корабля один раз для Đ?Ń<>ех правильных игроков
|
||||
// ?????????: ?????? ???????? ?????????? ?????? ????? ? ??????????? ?? ClientState.shipType
|
||||
|
||||
// Если сервер прислал коробки, применяем их однократно вместо локальной генерации
|
||||
if (!serverBoxesApplied && networkClient) {
|
||||
@ -633,7 +648,14 @@ namespace ZL
|
||||
// 3. Поворот врага
|
||||
renderer.RotateMatrix(playerState.rotation);
|
||||
|
||||
renderer.DrawVertexRenderStruct(spaceship);
|
||||
if (playerState.shipType == 1 && cargoTexture) {
|
||||
glBindTexture(GL_TEXTURE_2D, cargoTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(cargo);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(spaceship);
|
||||
}
|
||||
renderer.PopMatrix();
|
||||
}
|
||||
|
||||
|
||||
@ -78,6 +78,9 @@ namespace ZL {
|
||||
VertexDataStruct spaceshipBase;
|
||||
VertexRenderStruct spaceship;
|
||||
|
||||
std::shared_ptr<Texture> cargoTexture;
|
||||
VertexDataStruct cargoBase;
|
||||
VertexRenderStruct cargo;
|
||||
|
||||
VertexRenderStruct cubemap;
|
||||
|
||||
@ -133,7 +136,7 @@ namespace ZL {
|
||||
|
||||
// helpers
|
||||
void drawTargetHud(); // рисует рамку или стрелку
|
||||
int pickTargetId() const; // выбирает цель (пока: ближайший живой удаленный игрок)
|
||||
int pickTargetId() const; // ???????? ???? (????: ????????? ????? ????????? ?????)
|
||||
|
||||
void clearTextRendererCache();
|
||||
};
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -31,6 +31,7 @@ namespace ZL {
|
||||
Eigen::Vector3f targetPosition;
|
||||
uint64_t lastStateUpdateMs = 0;
|
||||
bool destroyed = false;
|
||||
int shipType = 0;
|
||||
};
|
||||
|
||||
class LocalClient : public INetworkClient {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user