Production-ready, fixing server bugs

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

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>Space Game</title>
<title>Sky Trek Tales</title>
<style>
body, html {
margin: 0; padding: 0; width: 100%; height: 100%;
@ -75,38 +75,6 @@
<button id="fs-button">Fullscreen</button>
<div id="status">Downloading...</div>
<canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex="-1"></canvas>
<!--
<script>
var statusElement = document.getElementById("status");
var canvas = document.getElementById("canvas");
var Module = {
canvas: canvas,
setStatus: function(text) {
statusElement.innerHTML = text;
statusElement.style.display = text ? 'block' : 'none';
}
};
document.getElementById('fs-button').addEventListener('click', function() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().catch(e => {
console.error(`Error attempting to enable full-screen mode: ${e.message}`);
});
} else {
document.exitFullscreen();
}
});
window.addEventListener("orientationchange", function() {
setTimeout(() => {
window.dispatchEvent(new Event('resize'));
}, 200);
});
</script>
<script async src="space-game001.js"></script>-->
<div id="nickOverlay" style="display:none;">
<div id="nickBox">
<h2>Enter your nickname</h2>

View File

@ -33,13 +33,13 @@
"type": "TextView",
"name": "aboutText1",
"width": 434,
"height": 40,
"height": 30,
"x": -300,
"y": 0,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Producer: Vladislav Khorev",
"fontSize": 32,
"fontSize": 24,
"color": [
255,
255,
@ -52,13 +52,13 @@
"type": "TextView",
"name": "aboutText2",
"width": 434,
"height": 40,
"height": 30,
"x": -300,
"y": 60,
"y": 40,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Lead Developer: Vladislav Khorev",
"fontSize": 32,
"fontSize": 24,
"color": [
255,
255,
@ -71,13 +71,51 @@
"type": "TextView",
"name": "aboutText2",
"width": 434,
"height": 40,
"height": 2,
"x": -300,
"y": 80,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Game Designer: Leila Bobrova",
"fontSize": 24,
"color": [
255,
255,
255,
1
],
"centered": false
},
{
"type": "TextView",
"name": "aboutText2",
"width": 434,
"height": 30,
"x": -300,
"y": 120,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Game Designer: Leila Bobrova",
"fontSize": 32,
"text": "Developers: ",
"fontSize": 24,
"color": [
255,
255,
255,
1
],
"centered": false
},
{
"type": "TextView",
"name": "aboutText2",
"width": 434,
"height": 40,
"x": -300,
"y": 150,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Vladislav Kan",
"fontSize": 24,
"color": [
255,
255,
@ -95,46 +133,8 @@
"y": 180,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Developers: ",
"fontSize": 32,
"color": [
255,
255,
255,
1
],
"centered": false
},
{
"type": "TextView",
"name": "aboutText2",
"width": 434,
"height": 40,
"x": -300,
"y": 220,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Vladislav Kan",
"fontSize": 32,
"color": [
255,
255,
255,
1
],
"centered": false
},
{
"type": "TextView",
"name": "aboutText2",
"width": 434,
"height": 40,
"x": -300,
"y": 260,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Beksultan Almazbekov",
"fontSize": 32,
"fontSize": 24,
"color": [
255,
255,
@ -149,11 +149,11 @@
"width": 434,
"height": 40,
"x": -300,
"y": 300,
"y": 210,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Sergei Zotov",
"fontSize": 32,
"fontSize": 24,
"color": [
255,
255,
@ -168,11 +168,11 @@
"width": 434,
"height": 40,
"x": -300,
"y": 360,
"y": 250,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "3D Artist: David \"nokken\" Im",
"fontSize": 32,
"fontSize": 24,
"color": [
255,
255,
@ -187,11 +187,49 @@
"width": 434,
"height": 40,
"x": -300,
"y": 420,
"y": 290,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "UI/UX Design: Kenje Kazmatova",
"fontSize": 32,
"fontSize": 24,
"color": [
255,
255,
255,
1
],
"centered": false
},
{
"type": "TextView",
"name": "aboutText2",
"width": 434,
"height": 40,
"x": -300,
"y": 330,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Sky Trek Tales v. 0.1",
"fontSize": 24,
"color": [
255,
255,
255,
1
],
"centered": false
},
{
"type": "TextView",
"name": "aboutText2",
"width": 434,
"height": 40,
"x": -300,
"y": 370,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "https://fishrungames.com",
"fontSize": 24,
"color": [
255,
255,

BIN
resources/rockdark3.png (Stored with Git LFS)

Binary file not shown.

BIN
resources/sand2.png (Stored with Git LFS)

Binary file not shown.

BIN
resources/sky/space1.png (Stored with Git LFS)

Binary file not shown.

View File

@ -25,7 +25,6 @@ Session::Session(Server& server, tcp::socket&& socket, int id)
}
bool Session::is_timed_out(std::chrono::system_clock::time_point now) const {
if (!joined_) return false;
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - lastReceivedTime_).count();
return elapsed > PLAYER_TIMEOUT_MS;
}
@ -268,6 +267,7 @@ void Session::process_message(const std::string& msg) {
std::lock_guard<std::mutex> lock(server_.g_sessions_mutex);
for (auto& session : server_.g_sessions) {
if (session->get_id() == this->id_) continue;
if (!session->joined_) continue;
std::string otherInfo = "PLAYERINFO:" + std::to_string(session->get_id()) + ":" + session->nickname + ":" + std::to_string(session->shipType);
this->send_message(otherInfo);

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.

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());

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) });
}
}

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;
}