More changes

This commit is contained in:
Vladislav Khorev 2026-03-01 22:34:12 +03:00
parent bb0f584bf6
commit 70a617b688
9 changed files with 66 additions and 21 deletions

BIN
resources/spark2.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -41,7 +41,7 @@ namespace ZL {
} }
void Projectile::rebuildMesh(Renderer&) { void Projectile::rebuildMesh(Renderer&) {
float half = size * 0.5f; float half = 10 * size * 0.5f;
mesh.data.PositionData.clear(); mesh.data.PositionData.clear();
mesh.data.TexCoordData.clear(); mesh.data.TexCoordData.clear();

View File

@ -3,6 +3,7 @@
#include "render/Renderer.h" #include "render/Renderer.h"
#include "render/TextureManager.h" #include "render/TextureManager.h"
#include <memory> #include <memory>
#include "SparkEmitter.h"
namespace ZL { namespace ZL {
@ -19,6 +20,8 @@ namespace ZL {
Vector3f getPosition() const { return pos; } Vector3f getPosition() const { return pos; }
void deactivate() { active = false; } void deactivate() { active = false; }
SparkEmitter projectileEmitter;
private: private:
Vector3f pos; Vector3f pos;
Vector3f vel; Vector3f vel;

View File

@ -335,6 +335,7 @@ namespace ZL
cargo.AssignFrom(cargoBase); cargo.AssignFrom(cargoBase);
cargo.RefreshVBO(); cargo.RefreshVBO();
//projectileTexture = std::make_shared<Texture>(CreateTextureDataFromPng("resources/spark2.png", CONST_ZIP_FILE));
//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));
@ -490,13 +491,25 @@ namespace ZL
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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) { for (const auto& p : projectiles) {
if (p && p->isActive()) { if (p && p->isActive()) {
p->draw(renderer); 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) { if (shipAlive) {
renderer.PushMatrix(); renderer.PushMatrix();
@ -1124,7 +1137,7 @@ namespace ZL
// Lead Indicator // Lead Indicator
// скорость пули (как в fireProjectiles) // скорость пули (как в 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 }; 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<Vector3f> projCameraPoints;
for (const auto& p : projectiles) { for (const auto& p : projectiles) {
if (p && p->isActive()) { if (p && p->isActive()) {
Vector3f worldPos = p->getPosition(); Vector3f worldPos = p->getPosition();
Vector3f rel = worldPos - Environment::shipState.position; Vector3f rel = worldPos - Environment::shipState.position;
Vector3f camPos = Environment::inverseShipMatrix * rel; Vector3f camPos = Environment::inverseShipMatrix * rel;
projCameraPoints.push_back(camPos); p->projectileEmitter.setEmissionPoints({ camPos });
p->projectileEmitter.emit();
p->projectileEmitter.update(static_cast<float>(delta));
} }
} }
/*
if (!projCameraPoints.empty()) { if (!projCameraPoints.empty()) {
projectileEmitter.setEmissionPoints(projCameraPoints); projectileEmitter.setEmissionPoints(projCameraPoints);
projectileEmitter.emit(); projectileEmitter.emit();
} }
else { else {
projectileEmitter.setEmissionPoints(std::vector<Vector3f>()); projectileEmitter.setEmissionPoints(std::vector<Vector3f>());
} }*/
std::vector<Vector3f> shipCameraPoints; std::vector<Vector3f> shipCameraPoints;
for (const auto& lp : shipLocalEmissionPoints) { for (const auto& lp : shipLocalEmissionPoints) {
@ -1567,7 +1583,7 @@ namespace ZL
} }
sparkEmitter.update(static_cast<float>(delta)); sparkEmitter.update(static_cast<float>(delta));
projectileEmitter.update(static_cast<float>(delta)); //projectileEmitter.update(static_cast<float>(delta));
explosionEmitter.update(static_cast<float>(delta)); explosionEmitter.update(static_cast<float>(delta));
if (showExplosion) { if (showExplosion) {
@ -1696,8 +1712,8 @@ namespace ZL
Vector3f{ 1.5f, 0.9f - 6.f, 5.0f } Vector3f{ 1.5f, 0.9f - 6.f, 5.0f }
}; };
const float projectileSpeed = 60.0f; const float projectileSpeed = PROJECTILE_VELOCITY;
const float lifeMs = 50000.0f; const float lifeMs = PROJECTILE_LIFE;
const float size = 0.5f; const float size = 0.5f;
Vector3f localForward = { 0,0,-1 }; Vector3f localForward = { 0,0,-1 };
@ -1710,6 +1726,7 @@ namespace ZL
for (auto& p : projectiles) { for (auto& p : projectiles) {
if (!p->isActive()) { if (!p->isActive()) {
p->init(worldPos, worldVel, lifeMs, size, projectileTexture, renderer); p->init(worldPos, worldVel, lifeMs, size, projectileTexture, renderer);
p->projectileEmitter = SparkEmitter(projectileEmitter);
break; break;
} }
} }
@ -1721,8 +1738,8 @@ namespace ZL
if (networkClient) { if (networkClient) {
auto pending = networkClient->getPendingProjectiles(); auto pending = networkClient->getPendingProjectiles();
if (!pending.empty()) { if (!pending.empty()) {
const float projectileSpeed = 60.0f; const float projectileSpeed = PROJECTILE_VELOCITY;
const float lifeMs = 5000.0f; const float lifeMs = PROJECTILE_LIFE;
const float size = 0.5f; const float size = 0.5f;
for (const auto& pi : pending) { for (const auto& pi : pending) {
const std::vector<Vector3f> localOffsets = { const std::vector<Vector3f> localOffsets = {
@ -1747,6 +1764,7 @@ namespace ZL
for (auto& p : projectiles) { for (auto& p : projectiles) {
if (!p->isActive()) { if (!p->isActive()) {
p->init(shotPos, baseVel, lifeMs, size, projectileTexture, renderer); p->init(shotPos, baseVel, lifeMs, size, projectileTexture, renderer);
p->projectileEmitter = SparkEmitter(projectileEmitter);
break; break;
} }
} }

View File

@ -96,7 +96,7 @@ namespace ZL {
std::shared_ptr<Texture> projectileTexture; std::shared_ptr<Texture> projectileTexture;
float projectileCooldownMs = 500.0f; float projectileCooldownMs = 500.0f;
int64_t lastProjectileFireTime = 0; int64_t lastProjectileFireTime = 0;
int maxProjectiles = 32; int maxProjectiles = 500;
std::vector<Vector3f> shipLocalEmissionPoints; std::vector<Vector3f> shipLocalEmissionPoints;

View File

@ -25,6 +25,23 @@ namespace ZL {
sparkQuad.data = VertexDataStruct(); 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<Vector3f>& positions, float rate) SparkEmitter::SparkEmitter(const std::vector<Vector3f>& positions, float rate)
: emissionPoints(positions), emissionRate(rate), isActive(true), : emissionPoints(positions), emissionRate(rate), isActive(true),
drawDataDirty(true), maxParticles(positions.size() * 100), drawDataDirty(true), maxParticles(positions.size() * 100),

View File

@ -41,7 +41,7 @@ namespace ZL {
float biasX; float biasX;
// Ranges (used when config supplies intervals) // 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 speedRange; // XY speed
FloatRange zSpeedRange; // Z speed FloatRange zSpeedRange; // Z speed
FloatRange scaleRange; FloatRange scaleRange;
@ -55,6 +55,7 @@ namespace ZL {
public: public:
SparkEmitter(); SparkEmitter();
SparkEmitter(const SparkEmitter& copyFrom);
SparkEmitter(const std::vector<Vector3f>& positions, float rate = 100.0f); SparkEmitter(const std::vector<Vector3f>& positions, float rate = 100.0f);
SparkEmitter(const std::vector<Vector3f>& positions, SparkEmitter(const std::vector<Vector3f>& positions,
std::shared_ptr<Texture> tex, std::shared_ptr<Texture> tex,

View File

@ -27,6 +27,14 @@ constexpr long long SERVER_DELAY = 0; //ms
constexpr long long CLIENT_DELAY = 500; //ms constexpr long long CLIENT_DELAY = 500; //ms
constexpr long long CUTOFF_TIME = 5000; //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); uint32_t fnv1a_hash(const std::string& data);
struct ClientState { struct ClientState {

View File

@ -21,8 +21,8 @@ namespace ZL {
std::random_device rd; std::random_device rd;
std::mt19937 gen(rd()); std::mt19937 gen(rd());
const float MIN_COORD = -100.0f; const float MIN_COORD = -1000.0f;
const float MAX_COORD = 100.0f; const float MAX_COORD = 1000.0f;
const float MIN_DISTANCE = 3.0f; const float MIN_DISTANCE = 3.0f;
const float MIN_DISTANCE_SQUARED = MIN_DISTANCE * MIN_DISTANCE; const float MIN_DISTANCE_SQUARED = MIN_DISTANCE * MIN_DISTANCE;
const int MAX_ATTEMPTS = 1000; const int MAX_ATTEMPTS = 1000;
@ -68,7 +68,7 @@ namespace ZL {
Eigen::Vector3f LocalClient::generateRandomPosition() { Eigen::Vector3f LocalClient::generateRandomPosition() {
std::random_device rd; std::random_device rd;
std::mt19937 gen(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( return Eigen::Vector3f(
(float)distrib(gen), (float)distrib(gen),
@ -238,11 +238,6 @@ namespace ZL {
auto now_ms = std::chrono::duration_cast<std::chrono::milliseconds>( auto now_ms = 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();
const float projectileHitRadius = 1.5f;
const float boxCollisionRadius = 2.0f;
const float shipCollisionRadius = 15.0f;
const float npcCollisionRadius = 5.0f;
std::vector<std::pair<size_t, size_t>> boxProjectileCollisions; std::vector<std::pair<size_t, size_t>> boxProjectileCollisions;
for (size_t bi = 0; bi < serverBoxes.size(); ++bi) { for (size_t bi = 0; bi < serverBoxes.size(); ++bi) {