Merge branch 'spark'
This commit is contained in:
commit
cca1d0ece2
@ -3,6 +3,7 @@
|
||||
|
||||
Activate the environment:
|
||||
```
|
||||
C:\Work\Projects\emsdk\emsdk.bat install latest
|
||||
C:\Work\Projects\emsdk\emsdk.bat activate latest
|
||||
C:\Work\Projects\emsdk\emsdk_env.bat
|
||||
```
|
||||
|
||||
10
src/Game.cpp
10
src/Game.cpp
@ -180,6 +180,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;
|
||||
};
|
||||
@ -445,12 +451,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();
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +60,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);
|
||||
@ -56,6 +75,9 @@ namespace ZL {
|
||||
auto* self = static_cast<WebSocketClientEmscripten*>(userData);
|
||||
self->connected = true;
|
||||
std::cout << "[WebWS] Connection opened" << std::endl;
|
||||
|
||||
self->flushOutgoingQueue();
|
||||
|
||||
return EM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,10 @@ namespace ZL {
|
||||
// Очередь для хранения сырых строк от браузера
|
||||
std::queue<std::string> messageQueue;
|
||||
|
||||
std::queue<std::string> outgoingQueue;
|
||||
std::mutex outgoingMutex;
|
||||
void flushOutgoingQueue();
|
||||
|
||||
public:
|
||||
WebSocketClientEmscripten() = default;
|
||||
virtual ~WebSocketClientEmscripten() = default;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user