Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54c71536b1 | ||
|
|
84b3c3261c | ||
|
|
d1f3d67062 | ||
|
|
3094fc6112 | ||
|
|
9e6ff5e08f | ||
|
|
24526efb8d | ||
|
|
e5d7885a12 | ||
|
|
d151d4bfaf | ||
|
|
147aa266d5 | ||
|
|
2884865b53 | ||
|
|
a1a7f714d9 | ||
|
|
03323638e1 | ||
|
|
bd17d0ff9e |
No files matched your search
@@ -323,7 +323,7 @@ set(_have_freetype TRUE)
|
|||||||
foreach(cfg IN LISTS BUILD_CONFIGS)
|
foreach(cfg IN LISTS BUILD_CONFIGS)
|
||||||
if(NOT EXISTS "${FREETYPE_BASE_DIR}-${cfg}/lib/freetype.lib" AND
|
if(NOT EXISTS "${FREETYPE_BASE_DIR}-${cfg}/lib/freetype.lib" AND
|
||||||
NOT EXISTS "${FREETYPE_BASE_DIR}-${cfg}/lib/freetyped.lib")
|
NOT EXISTS "${FREETYPE_BASE_DIR}-${cfg}/lib/freetyped.lib")
|
||||||
set(_have_freetype FALSE)
|
#set(_have_freetype FALSE)
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
@@ -391,7 +391,7 @@ foreach(cand
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if(_ft_debug_lib STREQUAL "" OR _ft_release_lib STREQUAL "")
|
if(_ft_debug_lib STREQUAL "" OR _ft_release_lib STREQUAL "")
|
||||||
message(FATAL_ERROR "FreeType libs not found in ${FREETYPE_BASE_DIR}-Debug/Release")
|
# message(FATAL_ERROR "FreeType libs not found in ${FREETYPE_BASE_DIR}-Debug/Release")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library(freetype_external_lib UNKNOWN IMPORTED GLOBAL)
|
add_library(freetype_external_lib UNKNOWN IMPORTED GLOBAL)
|
||||||
@@ -441,7 +441,7 @@ if(NOT _have_sdl2ttf)
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if(_FT_LIB STREQUAL "")
|
if(_FT_LIB STREQUAL "")
|
||||||
message(FATAL_ERROR "FreeType library not found for ${cfg}")
|
# message(FATAL_ERROR "FreeType library not found for ${cfg}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
log("Configuring SDL_ttf (${cfg}) ...")
|
log("Configuring SDL_ttf (${cfg}) ...")
|
||||||
@@ -462,7 +462,7 @@ if(NOT _have_sdl2ttf)
|
|||||||
RESULT_VARIABLE _ttf_cfg_res
|
RESULT_VARIABLE _ttf_cfg_res
|
||||||
)
|
)
|
||||||
if(NOT _ttf_cfg_res EQUAL 0)
|
if(NOT _ttf_cfg_res EQUAL 0)
|
||||||
message(FATAL_ERROR "SDL_ttf configure failed for ${cfg}")
|
#message(FATAL_ERROR "SDL_ttf configure failed for ${cfg}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
log("Building SDL_ttf (${cfg}) ...")
|
log("Building SDL_ttf (${cfg}) ...")
|
||||||
@@ -472,7 +472,7 @@ if(NOT _have_sdl2ttf)
|
|||||||
RESULT_VARIABLE _ttf_build_res
|
RESULT_VARIABLE _ttf_build_res
|
||||||
)
|
)
|
||||||
if(NOT _ttf_build_res EQUAL 0)
|
if(NOT _ttf_build_res EQUAL 0)
|
||||||
message(FATAL_ERROR "SDL_ttf build failed for ${cfg}")
|
#message(FATAL_ERROR "SDL_ttf build failed for ${cfg}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
log("Installing SDL_ttf (${cfg}) ...")
|
log("Installing SDL_ttf (${cfg}) ...")
|
||||||
@@ -482,7 +482,7 @@ if(NOT _have_sdl2ttf)
|
|||||||
RESULT_VARIABLE _ttf_inst_res
|
RESULT_VARIABLE _ttf_inst_res
|
||||||
)
|
)
|
||||||
if(NOT _ttf_inst_res EQUAL 0)
|
if(NOT _ttf_inst_res EQUAL 0)
|
||||||
message(FATAL_ERROR "SDL_ttf install failed for ${cfg}")
|
#message(FATAL_ERROR "SDL_ttf install failed for ${cfg}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endforeach()
|
endforeach()
|
||||||
@@ -510,7 +510,7 @@ foreach(cand
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if(_ttf_debug_lib STREQUAL "" OR _ttf_release_lib STREQUAL "")
|
if(_ttf_debug_lib STREQUAL "" OR _ttf_release_lib STREQUAL "")
|
||||||
message(FATAL_ERROR "SDL_ttf libs not found in install-Debug / install-Release")
|
# message(FATAL_ERROR "SDL_ttf libs not found in install-Debug / install-Release")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library(SDL2_ttf_external_lib UNKNOWN IMPORTED GLOBAL)
|
add_library(SDL2_ttf_external_lib UNKNOWN IMPORTED GLOBAL)
|
||||||
@@ -546,4 +546,4 @@ if(NOT TARGET boost_external_lib)
|
|||||||
add_library(boost_external_lib INTERFACE)
|
add_library(boost_external_lib INTERFACE)
|
||||||
# Boost заголовки находятся непосредственно в корне распакованной папки
|
# Boost заголовки находятся непосредственно в корне распакованной папки
|
||||||
target_include_directories(boost_external_lib INTERFACE "${BOOST_SRC_DIR}")
|
target_include_directories(boost_external_lib INTERFACE "${BOOST_SRC_DIR}")
|
||||||
endif()
|
endif()
|
||||||
@@ -46,4 +46,4 @@ if(WIN32)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Дополнительный макрос, чтобы Asio знал, что мы работаем без устаревших функций
|
# Дополнительный макрос, чтобы Asio знал, что мы работаем без устаревших функций
|
||||||
target_compile_definitions(Server PRIVATE BOOST_ASIO_NO_DEPRECATED)
|
target_compile_definitions(Server PRIVATE BOOST_ASIO_NO_DEPRECATED)
|
||||||
+27
-50
@@ -689,15 +689,13 @@ void Server::update_world() {
|
|||||||
|
|
||||||
|
|
||||||
std::vector<int> boxesToRespawn;
|
std::vector<int> boxesToRespawn;
|
||||||
|
|
||||||
// --- Tick: box-projectile collisions ---
|
// --- Tick: box-projectile collisions ---
|
||||||
{
|
{
|
||||||
std::vector<BoxDestroyedInfo> localBoxDestructions;
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> bm(g_boxes_mutex);
|
std::lock_guard<std::mutex> bm(g_boxes_mutex);
|
||||||
std::lock_guard<std::mutex> pm(g_projectiles_mutex);
|
|
||||||
|
|
||||||
std::vector<int> projectilesToRemove;
|
|
||||||
std::vector<char> projectileUsed(g_projectiles.size(), 0);
|
std::vector<std::pair<size_t, size_t>> boxProjectileCollisions;
|
||||||
|
|
||||||
for (size_t bi = 0; bi < g_serverBoxes.size(); ++bi) {
|
for (size_t bi = 0; bi < g_serverBoxes.size(); ++bi) {
|
||||||
if (g_serverBoxes[bi].destroyed) continue;
|
if (g_serverBoxes[bi].destroyed) continue;
|
||||||
@@ -705,58 +703,37 @@ void Server::update_world() {
|
|||||||
Eigen::Vector3f boxWorld = g_serverBoxes[bi].position + Eigen::Vector3f(0.0f, 0.0f, 45000.0f);
|
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) {
|
for (size_t pi = 0; pi < g_projectiles.size(); ++pi) {
|
||||||
if (projectileUsed[pi]) continue;
|
|
||||||
|
|
||||||
const auto& pr = g_projectiles[pi];
|
const auto& pr = g_projectiles[pi];
|
||||||
Eigen::Vector3f diff = pr.pos - boxWorld;
|
Eigen::Vector3f diff = pr.pos - boxWorld;
|
||||||
|
float thresh = boxCollisionRadius + projectileHitRadius;
|
||||||
float thresh = g_serverBoxes[bi].collisionRadius + projectileHitRadius;
|
|
||||||
|
|
||||||
if (diff.squaredNorm() <= thresh * thresh) {
|
if (diff.squaredNorm() <= thresh * thresh) {
|
||||||
g_serverBoxes[bi].destroyed = true;
|
boxProjectileCollisions.push_back({ bi, pi });
|
||||||
|
|
||||||
BoxDestroyedInfo destruction;
|
|
||||||
destruction.boxIndex = static_cast<int>(bi);
|
|
||||||
destruction.serverTime = now_ms;
|
|
||||||
destruction.position = boxWorld;
|
|
||||||
destruction.destroyedBy = pr.shooterId;
|
|
||||||
|
|
||||||
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; // одна пуля уничтожает только одну коробку
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!projectilesToRemove.empty()) {
|
for (const auto& [boxIdx, projIdx] : boxProjectileCollisions) {
|
||||||
std::sort(projectilesToRemove.rbegin(), projectilesToRemove.rend());
|
if (g_serverBoxes[boxIdx].destroyed) continue;
|
||||||
projectilesToRemove.erase(
|
g_serverBoxes[boxIdx].destroyed = true;
|
||||||
std::unique(projectilesToRemove.begin(), projectilesToRemove.end()),
|
|
||||||
projectilesToRemove.end()
|
|
||||||
);
|
|
||||||
|
|
||||||
for (int idx : projectilesToRemove) {
|
Eigen::Vector3f boxWorld = g_serverBoxes[boxIdx].position + Eigen::Vector3f(0.0f, 0.0f, 45000.0f);
|
||||||
if (idx >= 0 && idx < (int)g_projectiles.size()) {
|
|
||||||
g_projectiles.erase(g_projectiles.begin() + idx);
|
BoxDestroyedInfo destruction;
|
||||||
}
|
destruction.boxIndex = static_cast<int>(boxIdx);
|
||||||
|
destruction.serverTime = now_ms;
|
||||||
|
destruction.position = boxWorld;
|
||||||
|
destruction.destroyedBy = g_projectiles[projIdx].shooterId;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> dm(g_boxDestructions_mutex);
|
||||||
|
g_boxDestructions.push_back(destruction);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!localBoxDestructions.empty()) {
|
boxesToRespawn.push_back(static_cast<int>(boxIdx));
|
||||||
std::lock_guard<std::mutex> dm(g_boxDestructions_mutex);
|
|
||||||
g_boxDestructions.insert(
|
std::cout << "Server: Box " << boxIdx << " destroyed by projectile from player "
|
||||||
g_boxDestructions.end(),
|
<< g_projectiles[projIdx].shooterId << std::endl;
|
||||||
localBoxDestructions.begin(),
|
|
||||||
localBoxDestructions.end()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -782,7 +759,7 @@ void Server::update_world() {
|
|||||||
if (!session->fetchStateAtTime(now, shipState)) continue;
|
if (!session->fetchStateAtTime(now, shipState)) continue;
|
||||||
|
|
||||||
Eigen::Vector3f diff = shipState.position - boxWorld;
|
Eigen::Vector3f diff = shipState.position - boxWorld;
|
||||||
float thresh = shipCollisionRadius + g_serverBoxes[bi].collisionRadius;
|
float thresh = shipCollisionRadius + boxCollisionRadius;
|
||||||
|
|
||||||
if (diff.squaredNorm() <= thresh * thresh) {
|
if (diff.squaredNorm() <= thresh * thresh) {
|
||||||
g_serverBoxes[bi].destroyed = true;
|
g_serverBoxes[bi].destroyed = true;
|
||||||
@@ -961,14 +938,14 @@ void Server::accept()
|
|||||||
int main() {
|
int main() {
|
||||||
try {
|
try {
|
||||||
net::io_context ioc;
|
net::io_context ioc;
|
||||||
tcp::acceptor acceptor{ ioc, {tcp::v4(), 8081} };
|
tcp::acceptor acceptor{ ioc, {tcp::v4(), 8010} };
|
||||||
|
|
||||||
Server server(acceptor, ioc);
|
Server server(acceptor, ioc);
|
||||||
|
|
||||||
server.init();
|
server.init();
|
||||||
server.accept();
|
server.accept();
|
||||||
|
|
||||||
std::cout << "Server started on port 8081...\n";
|
std::cout << "Server started on port 8010...\n";
|
||||||
|
|
||||||
server.update_world();
|
server.update_world();
|
||||||
ioc.run();
|
ioc.run();
|
||||||
@@ -977,4 +954,4 @@ int main() {
|
|||||||
std::cerr << "Error: " << e.what() << std::endl;
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -38,7 +38,7 @@ struct DeathInfo {
|
|||||||
struct ServerBox {
|
struct ServerBox {
|
||||||
Eigen::Vector3f position;
|
Eigen::Vector3f position;
|
||||||
Eigen::Matrix3f rotation;
|
Eigen::Matrix3f rotation;
|
||||||
float collisionRadius = 1.0f;
|
float collisionRadius = 2.0f;
|
||||||
bool destroyed = false;
|
bool destroyed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -1598,7 +1598,11 @@ namespace ZL
|
|||||||
|
|
||||||
this->fireProjectiles();
|
this->fireProjectiles();
|
||||||
|
|
||||||
Eigen::Vector3f shipPos = Environment::shipState.position;
|
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 - 6.0f, 5.0f };
|
||||||
|
|
||||||
Eigen::Quaternionf q(Environment::shipState.rotation);
|
Eigen::Quaternionf q(Environment::shipState.rotation);
|
||||||
float speedToSend = projectileSpeed + Environment::shipState.velocity;
|
float speedToSend = projectileSpeed + Environment::shipState.velocity;
|
||||||
@@ -1606,9 +1610,9 @@ namespace ZL
|
|||||||
|
|
||||||
std::string fireMsg = "FIRE:" +
|
std::string fireMsg = "FIRE:" +
|
||||||
std::to_string(now_ms) + ":" +
|
std::to_string(now_ms) + ":" +
|
||||||
std::to_string(shipPos.x()) + ":" +
|
std::to_string(centerPos.x()) + ":" +
|
||||||
std::to_string(shipPos.y()) + ":" +
|
std::to_string(centerPos.y()) + ":" +
|
||||||
std::to_string(shipPos.z()) + ":" +
|
std::to_string(centerPos.z()) + ":" +
|
||||||
std::to_string(q.w()) + ":" +
|
std::to_string(q.w()) + ":" +
|
||||||
std::to_string(q.x()) + ":" +
|
std::to_string(q.x()) + ":" +
|
||||||
std::to_string(q.y()) + ":" +
|
std::to_string(q.y()) + ":" +
|
||||||
|
|||||||
Reference in new issue
Block a user