|
|
|
|
@ -689,13 +689,15 @@ void Server::update_world() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<int> boxesToRespawn;
|
|
|
|
|
|
|
|
|
|
// --- Tick: box-projectile collisions ---
|
|
|
|
|
{
|
|
|
|
|
std::vector<BoxDestroyedInfo> localBoxDestructions;
|
|
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> bm(g_boxes_mutex);
|
|
|
|
|
std::lock_guard<std::mutex> pm(g_projectiles_mutex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::pair<size_t, size_t>> boxProjectileCollisions;
|
|
|
|
|
std::vector<int> projectilesToRemove;
|
|
|
|
|
std::vector<char> projectileUsed(g_projectiles.size(), 0);
|
|
|
|
|
|
|
|
|
|
for (size_t bi = 0; bi < g_serverBoxes.size(); ++bi) {
|
|
|
|
|
if (g_serverBoxes[bi].destroyed) continue;
|
|
|
|
|
@ -703,37 +705,58 @@ void Server::update_world() {
|
|
|
|
|
Eigen::Vector3f boxWorld = g_serverBoxes[bi].position + Eigen::Vector3f(0.0f, 0.0f, 45000.0f);
|
|
|
|
|
|
|
|
|
|
for (size_t pi = 0; pi < g_projectiles.size(); ++pi) {
|
|
|
|
|
if (projectileUsed[pi]) continue;
|
|
|
|
|
|
|
|
|
|
const auto& pr = g_projectiles[pi];
|
|
|
|
|
Eigen::Vector3f diff = pr.pos - boxWorld;
|
|
|
|
|
float thresh = boxCollisionRadius + projectileHitRadius;
|
|
|
|
|
|
|
|
|
|
float thresh = g_serverBoxes[bi].collisionRadius + projectileHitRadius;
|
|
|
|
|
|
|
|
|
|
if (diff.squaredNorm() <= thresh * thresh) {
|
|
|
|
|
boxProjectileCollisions.push_back({ bi, pi });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto& [boxIdx, projIdx] : boxProjectileCollisions) {
|
|
|
|
|
if (g_serverBoxes[boxIdx].destroyed) continue;
|
|
|
|
|
g_serverBoxes[boxIdx].destroyed = true;
|
|
|
|
|
|
|
|
|
|
Eigen::Vector3f boxWorld = g_serverBoxes[boxIdx].position + Eigen::Vector3f(0.0f, 0.0f, 45000.0f);
|
|
|
|
|
g_serverBoxes[bi].destroyed = true;
|
|
|
|
|
|
|
|
|
|
BoxDestroyedInfo destruction;
|
|
|
|
|
destruction.boxIndex = static_cast<int>(boxIdx);
|
|
|
|
|
destruction.boxIndex = static_cast<int>(bi);
|
|
|
|
|
destruction.serverTime = now_ms;
|
|
|
|
|
destruction.position = boxWorld;
|
|
|
|
|
destruction.destroyedBy = g_projectiles[projIdx].shooterId;
|
|
|
|
|
destruction.destroyedBy = pr.shooterId;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard<std::mutex> dm(g_boxDestructions_mutex);
|
|
|
|
|
g_boxDestructions.push_back(destruction);
|
|
|
|
|
localBoxDestructions.push_back(destruction);
|
|
|
|
|
boxesToRespawn.push_back(static_cast<int>(bi));
|
|
|
|
|
|
|
|
|
|
projectileUsed[pi] = 1;
|
|
|
|
|
projectilesToRemove.push_back(static_cast<int>(pi));
|
|
|
|
|
|
|
|
|
|
std::cout << "Server: Box " << bi
|
|
|
|
|
<< " destroyed by projectile from player "
|
|
|
|
|
<< pr.shooterId << std::endl;
|
|
|
|
|
|
|
|
|
|
break; // одна пуля уничтожает только одну коробку
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boxesToRespawn.push_back(static_cast<int>(boxIdx));
|
|
|
|
|
if (!projectilesToRemove.empty()) {
|
|
|
|
|
std::sort(projectilesToRemove.rbegin(), projectilesToRemove.rend());
|
|
|
|
|
projectilesToRemove.erase(
|
|
|
|
|
std::unique(projectilesToRemove.begin(), projectilesToRemove.end()),
|
|
|
|
|
projectilesToRemove.end()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
std::cout << "Server: Box " << boxIdx << " destroyed by projectile from player "
|
|
|
|
|
<< g_projectiles[projIdx].shooterId << std::endl;
|
|
|
|
|
for (int idx : projectilesToRemove) {
|
|
|
|
|
if (idx >= 0 && idx < (int)g_projectiles.size()) {
|
|
|
|
|
g_projectiles.erase(g_projectiles.begin() + idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!localBoxDestructions.empty()) {
|
|
|
|
|
std::lock_guard<std::mutex> dm(g_boxDestructions_mutex);
|
|
|
|
|
g_boxDestructions.insert(
|
|
|
|
|
g_boxDestructions.end(),
|
|
|
|
|
localBoxDestructions.begin(),
|
|
|
|
|
localBoxDestructions.end()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -759,7 +782,7 @@ void Server::update_world() {
|
|
|
|
|
if (!session->fetchStateAtTime(now, shipState)) continue;
|
|
|
|
|
|
|
|
|
|
Eigen::Vector3f diff = shipState.position - boxWorld;
|
|
|
|
|
float thresh = shipCollisionRadius + boxCollisionRadius;
|
|
|
|
|
float thresh = shipCollisionRadius + g_serverBoxes[bi].collisionRadius;
|
|
|
|
|
|
|
|
|
|
if (diff.squaredNorm() <= thresh * thresh) {
|
|
|
|
|
g_serverBoxes[bi].destroyed = true;
|
|
|
|
|
|