Production-ready, fixing server bugs

This commit is contained in:
Vladislav Khorev committed 2026-03-12 11:36:47 +03:00
1 parent ca98fea2bd
commit beac06fd45
10 files changed
+110 -108

No files matched your search

-8
View File
@@ -37,7 +37,6 @@ namespace ZL
#ifdef EMSCRIPTEN
const char* CONST_ZIP_FILE = "resources.zip";
#else
//const char* CONST_ZIP_FILE = "C:\\Work\\Projects\\space-game001\\resources.zip";
const char* CONST_ZIP_FILE = "";
#endif
@@ -72,13 +71,6 @@ namespace ZL
}
Game::~Game() {
/*
if (glContext) {
SDL_GL_DeleteContext(glContext);
}
if (window) {
SDL_DestroyWindow(window);
}*/
#ifndef EMSCRIPTEN
// In Emscripten, SDL must stay alive across context loss/restore cycles
// so the window remains valid when the game object is re-created.
+1
View File
@@ -570,6 +570,7 @@ namespace ZL
renderer.PushMatrix();
renderer.TranslateMatrix({ 0, -6.f, 0 }); //Ship camera offset
//renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI * 150 / 180.f, Eigen::Vector3f::UnitY())).toRotationMatrix());
if (shipAlive) {
if (Environment::shipState.shipType == 1 && cargoTexture) {
glBindTexture(GL_TEXTURE_2D, cargoTexture->getTexID());
+3
View File
@@ -100,7 +100,10 @@ namespace ZL {
}
else {
posCam = particle.position;
//Vector3f rel = particle.position - Environment::shipState.position;
//posCam = Environment::shipState.position + Eigen::Quaternionf(Eigen::AngleAxisf(M_PI * 150 / 180.f, Eigen::Vector3f::UnitY())).toRotationMatrix() * Environment::inverseShipMatrix * rel;
}
//sortedParticles.push_back({ &particle, particle.position(2) });
sortedParticles.push_back({ &particle, posCam(2) });
}
}
+7 -7
View File
@@ -51,12 +51,12 @@ namespace ZL {
{
std::lock_guard<std::mutex> lock(outgoingMutex);
if (connected && socket_ > 0) {
std::cout << "[WebWS] Sending message (immediate): " << signedMsg << std::endl;
//std::cout << "[WebWS] Sending message (immediate): " << signedMsg << std::endl;
emscripten_websocket_send_utf8_text(socket_, signedMsg.c_str());
return;
}
outgoingQueue.push(signedMsg);
std::cout << "[WebWS] Queued outgoing message (waiting for open): " << signedMsg << std::endl;
//std::cout << "[WebWS] Queued outgoing message (waiting for open): " << signedMsg << std::endl;
}
}
@@ -69,7 +69,7 @@ namespace ZL {
while (!localQueue.empty()) {
const std::string& msg = localQueue.front();
std::cout << "[WebWS] Processing message: " << msg << std::endl;
//std::cout << "[WebWS] Processing message: " << msg << std::endl;
// Передаем в базовый класс для парсинга игровых событий (BOXES, UPD, и т.д.)
HandlePollMessage(msg);
@@ -83,7 +83,7 @@ namespace ZL {
EM_BOOL WebSocketClientEmscripten::onOpen(int eventType, const EmscriptenWebSocketOpenEvent* e, void* userData) {
auto* self = static_cast<WebSocketClientEmscripten*>(userData);
self->connected = true;
std::cout << "[WebWS] Connection opened" << std::endl;
//std::cout << "[WebWS] Connection opened" << std::endl;
self->flushOutgoingQueue();
@@ -91,7 +91,7 @@ namespace ZL {
}
EM_BOOL WebSocketClientEmscripten::onMessage(int eventType, const EmscriptenWebSocketMessageEvent* e, void* userData) {
std::cout << "[WebWS] onMessage " << std::endl;
//std::cout << "[WebWS] onMessage " << std::endl;
auto* self = static_cast<WebSocketClientEmscripten*>(userData);
if (e->isText && e->data) {
std::string msg(reinterpret_cast<const char*>(e->data), e->numBytes);
@@ -103,14 +103,14 @@ namespace ZL {
EM_BOOL WebSocketClientEmscripten::onError(int eventType, const EmscriptenWebSocketErrorEvent* e, void* userData) {
auto* self = static_cast<WebSocketClientEmscripten*>(userData);
self->connected = false;
std::cerr << "[WebWS] Error detected" << std::endl;
//std::cerr << "[WebWS] Error detected" << std::endl;
return EM_TRUE;
}
EM_BOOL WebSocketClientEmscripten::onClose(int eventType, const EmscriptenWebSocketCloseEvent* e, void* userData) {
auto* self = static_cast<WebSocketClientEmscripten*>(userData);
self->connected = false;
std::cout << "[WebWS] Connection closed" << std::endl;
//std::cout << "[WebWS] Connection closed" << std::endl;
return EM_TRUE;
}