From 70a617b688624b134a038c5f2f0ed21183d697cb Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Sun, 1 Mar 2026 22:34:12 +0300 Subject: [PATCH] More changes --- resources/spark2.png | 3 +++ src/Projectile.cpp | 2 +- src/Projectile.h | 3 +++ src/Space.cpp | 38 +++++++++++++++++++++++++++---------- src/Space.h | 2 +- src/SparkEmitter.cpp | 17 +++++++++++++++++ src/SparkEmitter.h | 3 ++- src/network/ClientState.h | 8 ++++++++ src/network/LocalClient.cpp | 11 +++-------- 9 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 resources/spark2.png diff --git a/resources/spark2.png b/resources/spark2.png new file mode 100644 index 0000000..b0e806f --- /dev/null +++ b/resources/spark2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11cde0c85c95f91eb9ace65cead22a37ba80d215897f32a2d6be1410210c1acf +size 2656 diff --git a/src/Projectile.cpp b/src/Projectile.cpp index 419419d..9f98d4f 100644 --- a/src/Projectile.cpp +++ b/src/Projectile.cpp @@ -41,7 +41,7 @@ namespace ZL { } void Projectile::rebuildMesh(Renderer&) { - float half = size * 0.5f; + float half = 10 * size * 0.5f; mesh.data.PositionData.clear(); mesh.data.TexCoordData.clear(); diff --git a/src/Projectile.h b/src/Projectile.h index 872177f..e72552e 100644 --- a/src/Projectile.h +++ b/src/Projectile.h @@ -3,6 +3,7 @@ #include "render/Renderer.h" #include "render/TextureManager.h" #include +#include "SparkEmitter.h" namespace ZL { @@ -19,6 +20,8 @@ namespace ZL { Vector3f getPosition() const { return pos; } void deactivate() { active = false; } + + SparkEmitter projectileEmitter; private: Vector3f pos; Vector3f vel; diff --git a/src/Space.cpp b/src/Space.cpp index 691af98..3639912 100644 --- a/src/Space.cpp +++ b/src/Space.cpp @@ -335,6 +335,7 @@ namespace ZL cargo.AssignFrom(cargoBase); cargo.RefreshVBO(); + //projectileTexture = std::make_shared(CreateTextureDataFromPng("resources/spark2.png", CONST_ZIP_FILE)); //Boxes boxTexture = std::make_unique(CreateTextureDataFromPng("resources/box/box.png", CONST_ZIP_FILE)); @@ -490,13 +491,25 @@ namespace ZL glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + renderer.shaderManager.PushShader("default"); + renderer.RenderUniform1i(textureUniformName, 0); + renderer.EnableVertexAttribArray(vPositionName); + renderer.EnableVertexAttribArray(vTexCoordName); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); for (const auto& p : projectiles) { if (p && p->isActive()) { p->draw(renderer); + p->projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height); } } + glDisable(GL_BLEND); - projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height); + renderer.DisableVertexAttribArray(vPositionName); + renderer.DisableVertexAttribArray(vTexCoordName); + renderer.shaderManager.PopShader(); + + //projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height); if (shipAlive) { renderer.PushMatrix(); @@ -1124,7 +1137,7 @@ namespace ZL // Lead Indicator // скорость пули (как в fireProjectiles) - const float projectileSpeed = 60.0f; + const float projectileSpeed = PROJECTILE_VELOCITY; // позиция вылета Vector3f shooterPos = Environment::shipState.position + Environment::shipState.rotation * Vector3f{ 0.0f, 0.9f - 6.0f, 5.0f }; @@ -1540,22 +1553,25 @@ namespace ZL } } - std::vector projCameraPoints; + for (const auto& p : projectiles) { if (p && p->isActive()) { Vector3f worldPos = p->getPosition(); Vector3f rel = worldPos - Environment::shipState.position; Vector3f camPos = Environment::inverseShipMatrix * rel; - projCameraPoints.push_back(camPos); + p->projectileEmitter.setEmissionPoints({ camPos }); + p->projectileEmitter.emit(); + p->projectileEmitter.update(static_cast(delta)); } } + /* if (!projCameraPoints.empty()) { projectileEmitter.setEmissionPoints(projCameraPoints); projectileEmitter.emit(); } else { projectileEmitter.setEmissionPoints(std::vector()); - } + }*/ std::vector shipCameraPoints; for (const auto& lp : shipLocalEmissionPoints) { @@ -1567,7 +1583,7 @@ namespace ZL } sparkEmitter.update(static_cast(delta)); - projectileEmitter.update(static_cast(delta)); + //projectileEmitter.update(static_cast(delta)); explosionEmitter.update(static_cast(delta)); if (showExplosion) { @@ -1696,8 +1712,8 @@ namespace ZL Vector3f{ 1.5f, 0.9f - 6.f, 5.0f } }; - const float projectileSpeed = 60.0f; - const float lifeMs = 50000.0f; + const float projectileSpeed = PROJECTILE_VELOCITY; + const float lifeMs = PROJECTILE_LIFE; const float size = 0.5f; Vector3f localForward = { 0,0,-1 }; @@ -1710,6 +1726,7 @@ namespace ZL for (auto& p : projectiles) { if (!p->isActive()) { p->init(worldPos, worldVel, lifeMs, size, projectileTexture, renderer); + p->projectileEmitter = SparkEmitter(projectileEmitter); break; } } @@ -1721,8 +1738,8 @@ namespace ZL if (networkClient) { auto pending = networkClient->getPendingProjectiles(); if (!pending.empty()) { - const float projectileSpeed = 60.0f; - const float lifeMs = 5000.0f; + const float projectileSpeed = PROJECTILE_VELOCITY; + const float lifeMs = PROJECTILE_LIFE; const float size = 0.5f; for (const auto& pi : pending) { const std::vector localOffsets = { @@ -1747,6 +1764,7 @@ namespace ZL for (auto& p : projectiles) { if (!p->isActive()) { p->init(shotPos, baseVel, lifeMs, size, projectileTexture, renderer); + p->projectileEmitter = SparkEmitter(projectileEmitter); break; } } diff --git a/src/Space.h b/src/Space.h index 894fa39..b38b98e 100644 --- a/src/Space.h +++ b/src/Space.h @@ -96,7 +96,7 @@ namespace ZL { std::shared_ptr projectileTexture; float projectileCooldownMs = 500.0f; int64_t lastProjectileFireTime = 0; - int maxProjectiles = 32; + int maxProjectiles = 500; std::vector shipLocalEmissionPoints; diff --git a/src/SparkEmitter.cpp b/src/SparkEmitter.cpp index 05f686c..5f70710 100644 --- a/src/SparkEmitter.cpp +++ b/src/SparkEmitter.cpp @@ -25,6 +25,23 @@ namespace ZL { sparkQuad.data = VertexDataStruct(); } + SparkEmitter::SparkEmitter(const SparkEmitter& copyFrom) + : particles(copyFrom.particles), emissionPoints(copyFrom.emissionPoints), + lastEmissionTime(copyFrom.lastEmissionTime), emissionRate(copyFrom.emissionRate), + isActive(copyFrom.isActive), drawPositions(copyFrom.drawPositions), + drawTexCoords(copyFrom.drawTexCoords), drawDataDirty(copyFrom.drawDataDirty), + sparkQuad(copyFrom.sparkQuad), texture(copyFrom.texture), + maxParticles(copyFrom.maxParticles), particleSize(copyFrom.particleSize), + biasX(copyFrom.biasX), speedRange(copyFrom.speedRange), + zSpeedRange(copyFrom.zSpeedRange), + scaleRange(copyFrom.scaleRange), + lifeTimeRange(copyFrom.lifeTimeRange), + shaderProgramName(copyFrom.shaderProgramName), + configured(copyFrom.configured), useWorldSpace(copyFrom.useWorldSpace) + { + } + + SparkEmitter::SparkEmitter(const std::vector& positions, float rate) : emissionPoints(positions), emissionRate(rate), isActive(true), drawDataDirty(true), maxParticles(positions.size() * 100), diff --git a/src/SparkEmitter.h b/src/SparkEmitter.h index 3eed0aa..812b828 100644 --- a/src/SparkEmitter.h +++ b/src/SparkEmitter.h @@ -41,7 +41,7 @@ namespace ZL { float biasX; // Ranges (used when config supplies intervals) - struct FloatRange { float min; float max; }; + struct FloatRange { float min=0; float max=0; }; FloatRange speedRange; // XY speed FloatRange zSpeedRange; // Z speed FloatRange scaleRange; @@ -55,6 +55,7 @@ namespace ZL { public: SparkEmitter(); + SparkEmitter(const SparkEmitter& copyFrom); SparkEmitter(const std::vector& positions, float rate = 100.0f); SparkEmitter(const std::vector& positions, std::shared_ptr tex, diff --git a/src/network/ClientState.h b/src/network/ClientState.h index 2624679..5bbd8b3 100644 --- a/src/network/ClientState.h +++ b/src/network/ClientState.h @@ -27,6 +27,14 @@ constexpr long long SERVER_DELAY = 0; //ms constexpr long long CLIENT_DELAY = 500; //ms constexpr long long CUTOFF_TIME = 5000; //ms +constexpr float PROJECTILE_VELOCITY = 600.f; +constexpr float PROJECTILE_LIFE = 15000.f; //ms + +const float projectileHitRadius = 1.5f * 5; +const float boxCollisionRadius = 2.0f * 5; +const float shipCollisionRadius = 15.0f * 5; +const float npcCollisionRadius = 5.0f * 5; + uint32_t fnv1a_hash(const std::string& data); struct ClientState { diff --git a/src/network/LocalClient.cpp b/src/network/LocalClient.cpp index 0321249..1d43a78 100644 --- a/src/network/LocalClient.cpp +++ b/src/network/LocalClient.cpp @@ -21,8 +21,8 @@ namespace ZL { std::random_device rd; std::mt19937 gen(rd()); - const float MIN_COORD = -100.0f; - const float MAX_COORD = 100.0f; + const float MIN_COORD = -1000.0f; + const float MAX_COORD = 1000.0f; const float MIN_DISTANCE = 3.0f; const float MIN_DISTANCE_SQUARED = MIN_DISTANCE * MIN_DISTANCE; const int MAX_ATTEMPTS = 1000; @@ -68,7 +68,7 @@ namespace ZL { Eigen::Vector3f LocalClient::generateRandomPosition() { std::random_device rd; std::mt19937 gen(rd()); - std::uniform_real_distribution<> distrib(-500.0, 500.0); + std::uniform_real_distribution<> distrib(-5000.0, 5000.0); return Eigen::Vector3f( (float)distrib(gen), @@ -238,11 +238,6 @@ namespace ZL { auto now_ms = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count(); - const float projectileHitRadius = 1.5f; - const float boxCollisionRadius = 2.0f; - const float shipCollisionRadius = 15.0f; - const float npcCollisionRadius = 5.0f; - std::vector> boxProjectileCollisions; for (size_t bi = 0; bi < serverBoxes.size(); ++bi) {