added random spaceship type

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

View File

@ -310,6 +310,21 @@ namespace ZL
spaceship.AssignFrom(spaceshipBase); spaceship.AssignFrom(spaceshipBase);
spaceship.RefreshVBO(); 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 //Boxes
boxTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/box/box.png", CONST_ZIP_FILE)); 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), static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR); Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
// Биндим текстуру корабля один раз для всех удаленных игроков (оптимизация батчинга) // Биндим ŃекŃ<C59F>ŃŃ<E2809A>Ń€Ń<E282AC> корабля один раз для Đ?Ń<>ех правильных игроков
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID()); // ?????????: ?????? ???????? ?????????? ?????? ????? ? ??????????? ?? ClientState.shipType
// Если сервер прислал коробки, применяем их однократно вместо локальной генерации // Если сервер прислал коробки, применяем их однократно вместо локальной генерации
if (!serverBoxesApplied && networkClient) { if (!serverBoxesApplied && networkClient) {
@ -633,7 +648,14 @@ namespace ZL
// 3. Поворот врага // 3. Поворот врага
renderer.RotateMatrix(playerState.rotation); renderer.RotateMatrix(playerState.rotation);
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.DrawVertexRenderStruct(spaceship);
}
renderer.PopMatrix(); renderer.PopMatrix();
} }

View File

@ -78,6 +78,9 @@ namespace ZL {
VertexDataStruct spaceshipBase; VertexDataStruct spaceshipBase;
VertexRenderStruct spaceship; VertexRenderStruct spaceship;
std::shared_ptr<Texture> cargoTexture;
VertexDataStruct cargoBase;
VertexRenderStruct cargo;
VertexRenderStruct cubemap; VertexRenderStruct cubemap;
@ -133,7 +136,7 @@ namespace ZL {
// helpers // helpers
void drawTargetHud(); // рисует рамку или стрелку void drawTargetHud(); // рисует рамку или стрелку
int pickTargetId() const; // выбирает цель (пока: ближайший живой удаленный игрок) int pickTargetId() const; // ???????? ???? (????: ????????? ????? ????????? ?????)
void clearTextRendererCache(); void clearTextRendererCache();
}; };

View File

@ -18,7 +18,7 @@ constexpr float ROTATION_SENSITIVITY = 0.002f;
constexpr float PLANET_RADIUS = 20000.f; constexpr float PLANET_RADIUS = 20000.f;
constexpr float PLANET_ALIGN_ZONE = 1.05f; 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 PLANET_MAX_ANGULAR_VELOCITY = 10.f;
constexpr float PITCH_LIMIT = static_cast<float>(M_PI) / 9.f;//18.0f; constexpr float PITCH_LIMIT = static_cast<float>(M_PI) / 9.f;//18.0f;
@ -38,7 +38,8 @@ struct ClientState {
float discreteMag = 0; float discreteMag = 0;
int discreteAngle = -1; int discreteAngle = -1;
// Для расчета лага int shipType = 0;
// ??? ??????? ????
std::chrono::system_clock::time_point lastUpdateServerTime; std::chrono::system_clock::time_point lastUpdateServerTime;
void simulate_physics(size_t delta); void simulate_physics(size_t delta);

View File

@ -79,6 +79,10 @@ namespace ZL {
void LocalClient::initializeNPCs() { void LocalClient::initializeNPCs() {
npcs.clear(); 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) { for (int i = 0; i < 3; ++i) {
LocalNPC npc; LocalNPC npc;
npc.id = 100 + i; npc.id = 100 + i;
@ -91,6 +95,11 @@ namespace ZL {
npc.currentState.discreteAngle = -1; npc.currentState.discreteAngle = -1;
npc.currentState.currentAngularVelocity = Eigen::Vector3f::Zero(); npc.currentState.currentAngularVelocity = Eigen::Vector3f::Zero();
// random
int shipType = typeDistrib(gen);
npc.shipType = shipType;
npc.currentState.shipType = shipType;
npc.targetPosition = generateRandomPosition(); npc.targetPosition = generateRandomPosition();
npc.lastStateUpdateMs = std::chrono::duration_cast<std::chrono::milliseconds>( npc.lastStateUpdateMs = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()).count(); std::chrono::system_clock::now().time_since_epoch()).count();

View File

@ -31,6 +31,7 @@ namespace ZL {
Eigen::Vector3f targetPosition; Eigen::Vector3f targetPosition;
uint64_t lastStateUpdateMs = 0; uint64_t lastStateUpdateMs = 0;
bool destroyed = false; bool destroyed = false;
int shipType = 0;
}; };
class LocalClient : public INetworkClient { class LocalClient : public INetworkClient {