diff --git a/src/Game.cpp b/src/Game.cpp index ee766d6..9cb5e6a 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -364,38 +364,7 @@ namespace ZL }); uiManager.setButtonCallback("shootButton", [this](const std::string& name) { - uint64_t now = SDL_GetTicks64(); - if (now - lastProjectileFireTime >= static_cast(projectileCooldownMs)) { - lastProjectileFireTime = now; - const float projectileSpeed = 60.0f; - - this->fireProjectiles(); - - Eigen::Vector3f localForward = { 0, 0, -1 }; - Eigen::Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized(); - - Eigen::Vector3f centerPos = Environment::shipState.position + - Environment::shipState.rotation * Vector3f{ 0, 0.9f, 5.0f }; - - Eigen::Quaternionf q(Environment::shipState.rotation); - float speedToSend = projectileSpeed + Environment::shipState.velocity; - int shotCount = 2; - - std::string fireMsg = "FIRE:" + - std::to_string(now) + ":" + - std::to_string(centerPos.x()) + ":" + - std::to_string(centerPos.y()) + ":" + - std::to_string(centerPos.z()) + ":" + - std::to_string(q.w()) + ":" + - std::to_string(q.x()) + ":" + - std::to_string(q.y()) + ":" + - std::to_string(q.z()) + ":" + - std::to_string(speedToSend) + ":" + - std::to_string(shotCount); - - //Temporary disable to avoid de-sync - //networkClient->Send(fireMsg); - } + firePressed = true; }); uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) { @@ -922,6 +891,40 @@ namespace ZL sparkEmitter.update(static_cast(delta)); planetObject.update(static_cast(delta)); + if (firePressed) + { + firePressed = false; + if (now_ms - lastProjectileFireTime >= static_cast(projectileCooldownMs)) { + lastProjectileFireTime = now_ms; + const float projectileSpeed = 250.0f; + + this->fireProjectiles(); + + Eigen::Vector3f localForward = { 0, 0, -1 }; + Eigen::Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized(); + + Eigen::Vector3f centerPos = Environment::shipState.position + + Environment::shipState.rotation * Vector3f{ 0, 0.9f, 5.0f }; + + Eigen::Quaternionf q(Environment::shipState.rotation); + float speedToSend = projectileSpeed + Environment::shipState.velocity; + int shotCount = 2; + + std::string fireMsg = "FIRE:" + + std::to_string(now_ms) + ":" + + std::to_string(centerPos.x()) + ":" + + std::to_string(centerPos.y()) + ":" + + std::to_string(centerPos.z()) + ":" + + std::to_string(q.w()) + ":" + + std::to_string(q.x()) + ":" + + std::to_string(q.y()) + ":" + + std::to_string(q.z()) + ":" + + std::to_string(speedToSend) + ":" + + std::to_string(shotCount); + + networkClient->Send(fireMsg); + } + } //Handle input: diff --git a/src/Game.h b/src/Game.h index e3eafdf..979908b 100644 --- a/src/Game.h +++ b/src/Game.h @@ -105,7 +105,7 @@ namespace ZL { std::vector> projectiles; std::shared_ptr projectileTexture; float projectileCooldownMs = 500.0f; - uint64_t lastProjectileFireTime = 0; + int64_t lastProjectileFireTime = 0; int maxProjectiles = 32; std::vector shipLocalEmissionPoints; @@ -119,6 +119,7 @@ namespace ZL { bool showExplosion = false; uint64_t lastExplosionTime = 0; const uint64_t explosionDurationMs = 500; + bool firePressed = false; bool serverBoxesApplied = false;