fixed web ship types boxes / local boxes collision and projectiles

This commit is contained in:
Vlad 2026-03-03 19:17:07 +06:00
parent 167c04b107
commit 3879eb1d75
4 changed files with 45 additions and 11 deletions

View File

@ -174,6 +174,12 @@ namespace ZL
std::cerr << "Sent JOIN: " << joinMsg << std::endl;
}
space.boxCoordsArr.clear();
space.boxRenderArr.clear();
//space.boxLabels.clear();
space.boxAlive.clear();
space.serverBoxesApplied = false;
lastTickCount = 0;
spaceGameStarted = 1;
};
@ -440,12 +446,12 @@ namespace ZL
render();
if (networkClient) {
#ifndef NETWORK
//#ifndef NETWORK
auto localClient = dynamic_cast<ZL::LocalClient*>(networkClient.get());
if (localClient) {
localClient->setLocalPlayerState(Environment::shipState);
}
#endif
//#endif
networkClient->Poll();
}
mainThreadHandler.processMainThreadTasks();

View File

@ -418,11 +418,13 @@ namespace ZL {
pinfo.position = pr.pos;
pinfo.rotation = dir.toRotationMatrix();
pinfo.velocity = velocity;
pendingProjectiles.push_back(pinfo);
std::cout << "LocalClient: Created projectile at pos (" << shotPos.x() << ", "
if (pinfo.shooterId != GetClientId()) {
pendingProjectiles.push_back(pinfo);
}
std::cout << "LocalClient: Created server projectile at pos (" << shotPos.x() << ", "
<< shotPos.y() << ", " << shotPos.z() << ") vel (" << pr.vel.x() << ", "
<< pr.vel.y() << ", " << pr.vel.z() << ")" << std::endl;
<< pr.vel.y() << ", " << pr.vel.z() << ") shooter=" << pr.shooterId << std::endl;
}
}
}

View File

@ -22,13 +22,32 @@ namespace ZL {
emscripten_websocket_set_onmessage_callback(socket_, this, onMessage);
emscripten_websocket_set_onerror_callback(socket_, this, onError);
emscripten_websocket_set_onclose_callback(socket_, this, onClose);
connected = false;
}
void WebSocketClientEmscripten::flushOutgoingQueue() {
std::lock_guard<std::mutex> lock(outgoingMutex);
if (!socket_) return;
while (!outgoingQueue.empty()) {
const std::string &m = outgoingQueue.front();
emscripten_websocket_send_utf8_text(socket_, m.c_str());
outgoingQueue.pop();
}
}
void WebSocketClientEmscripten::Send(const std::string& message) {
if (connected && socket_ > 0) {
auto signedMsg = SignMessage(message);
std::cout << "[WebWS] Sending message: " << signedMsg << std::endl;
emscripten_websocket_send_utf8_text(socket_, signedMsg.c_str());
std::string signedMsg = SignMessage(message);
{
std::lock_guard<std::mutex> lock(outgoingMutex);
if (connected && socket_ > 0) {
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;
}
}
@ -44,7 +63,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);
@ -59,6 +78,9 @@ namespace ZL {
auto* self = static_cast<WebSocketClientEmscripten*>(userData);
self->connected = true;
std::cout << "[WebWS] Connection opened" << std::endl;
self->flushOutgoingQueue();
return EM_TRUE;
}

View File

@ -20,6 +20,10 @@ namespace ZL {
std::queue<std::string> messageQueue;
std::mutex queueMutex;
std::queue<std::string> outgoingQueue;
std::mutex outgoingMutex;
void flushOutgoingQueue();
public:
WebSocketClientEmscripten() = default;
virtual ~WebSocketClientEmscripten() = default;