Minor fixing
This commit is contained in:
1 parent
6cfd47e80d
commit
24c963c0a5
11 files changed
+125
-67
No files matched your search
@@ -89,7 +89,7 @@ public:
|
||||
bool showWeapon = true;
|
||||
|
||||
// --- Stable character references ---
|
||||
// Empty means no target. "player" is the campaign player; NPC IDs are
|
||||
// Empty means no target. "player1" is the campaign player; NPC IDs are
|
||||
// location-local and validated while loading location content.
|
||||
std::string attackTargetId;
|
||||
std::string faceTargetId;
|
||||
|
||||
+4
-2
@@ -558,8 +558,10 @@ namespace FRG
|
||||
logger() << "[network] Campaign '" << campaignId
|
||||
<< "' selected; creating WebSocket client" << std::endl;
|
||||
// Use "ws://127.0.0.1:8080/" for a local development server.
|
||||
static const char* const kMultiplayerServerUrl =
|
||||
"wss://api.shadowoverbishkek.com/server001/";
|
||||
|
||||
//static const char* const kMultiplayerServerUrl = "wss://api.shadowoverbishkek.com/server001/";
|
||||
static const char* const kMultiplayerServerUrl = "ws://127.0.0.1:8080/";
|
||||
|
||||
WebsocketEndpoint endpoint;
|
||||
if (!endpoint.parse(kMultiplayerServerUrl)) {
|
||||
logger() << "[network] Invalid multiplayer server URL: "
|
||||
|
||||
@@ -140,11 +140,16 @@ std::vector<PathFinder::DynamicObstacle> LocationGameState::collectPathObstacles
|
||||
std::sort(characters.begin(), characters.end(),
|
||||
[](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; });
|
||||
|
||||
const CharacterState* requester = findCharacter(requesterId, players);
|
||||
const std::string attackTargetId =
|
||||
requester ? requester->attackTargetId : std::string();
|
||||
std::vector<PathFinder::DynamicObstacle> obstacles;
|
||||
obstacles.reserve(characters.size());
|
||||
for (const auto& [id, character] : characters) {
|
||||
if (id == requesterId || !character->enabled || character->hp <= 0.f)
|
||||
continue;
|
||||
if (id == attackTargetId && id != forcedObstacleId)
|
||||
continue;
|
||||
if (character->movedLastTick && id != forcedObstacleId) continue;
|
||||
obstacles.push_back({character->position, character->collisionRadius});
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace FRG {
|
||||
ScriptEngine::~ScriptEngine() = default;
|
||||
|
||||
void ScriptEngine::init(Location* loc, AudioPlayerAsync* audioPlayer, const std::string& scriptPath) {
|
||||
logger() << "ScriptEngine::init with script path: " << scriptPath << std::endl;
|
||||
impl = std::make_unique<Impl>();
|
||||
sol::state& lua = impl->lua;
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ LocationDefinition LocationContentLoader::load(
|
||||
for (const auto& item : root.value("npcs", json::array())) {
|
||||
NpcData data;
|
||||
data.id = item.at("id").get<std::string>();
|
||||
if (data.id.empty() || data.id == "player" ||
|
||||
if (data.id.empty() || data.id == "player1" ||
|
||||
!ids.insert(data.id).second) {
|
||||
throw std::runtime_error(
|
||||
"Missing, duplicate, or reserved NPC id in " +
|
||||
|
||||
+30
-15
@@ -2,6 +2,7 @@
|
||||
#include "Environment.h"
|
||||
#include "utils/Utils.h"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
@@ -75,25 +76,43 @@ extern "C" void EMSCRIPTEN_KEEPALIVE onFileSystemLoaded() {
|
||||
}
|
||||
|
||||
|
||||
// Single definition of the "logical" viewport size: the *visible* area of the page
|
||||
// (visualViewport), not 100vh, which on mobile includes the area under the URL bar.
|
||||
static void getViewportCssSize(int& w, int& h) {
|
||||
w = EM_ASM_INT({
|
||||
var vv = window.visualViewport;
|
||||
return Math.round((vv && vv.width) || window.innerWidth);
|
||||
});
|
||||
h = EM_ASM_INT({
|
||||
var vv = window.visualViewport;
|
||||
return Math.round((vv && vv.height) || window.innerHeight);
|
||||
});
|
||||
}
|
||||
|
||||
static void applyResize(int logicalW, int logicalH) {
|
||||
// Получаем коэффициент плотности пикселей (например, 2.625 на Pixel или 3.0 на Samsung)
|
||||
double dpr = emscripten_get_device_pixel_ratio();
|
||||
//double dpr = 1; // low quality
|
||||
|
||||
// Вычисляем реальные физические пиксели
|
||||
int physicalW = static_cast<int>(logicalW * dpr);
|
||||
int physicalH = static_cast<int>(logicalH * dpr);
|
||||
int physicalW = static_cast<int>(std::lround(logicalW * dpr));
|
||||
int physicalH = static_cast<int>(std::lround(logicalH * dpr));
|
||||
|
||||
// Устанавливаем размер внутреннего буфера канваса
|
||||
emscripten_set_canvas_element_size("#canvas", physicalW, physicalH);
|
||||
|
||||
// Сообщаем SDL о новом размере.
|
||||
// ВАЖНО: SDL2 в Emscripten ожидает здесь именно физические пиксели
|
||||
// Сообщаем SDL о новом размере.
|
||||
// ВАЖНО: SDL2 в Emscripten ожидает здесь именно физические пиксели
|
||||
// для корректной работы последующих вызовов glViewport.
|
||||
if (FRG::Environment::window) {
|
||||
SDL_SetWindowSize(FRG::Environment::window, physicalW, physicalH);
|
||||
}
|
||||
|
||||
// SDL may have written an inline CSS size derived from the physical pixels, which
|
||||
// overrides the stylesheet. Re-assert the CSS box so its aspect always matches the
|
||||
// drawing buffer (otherwise the image is stretched / cropped on mobile).
|
||||
emscripten_set_element_css_size("#canvas", logicalW, logicalH);
|
||||
|
||||
// Пушим событие, чтобы движок пересчитал матрицы проекции
|
||||
SDL_Event e = {};
|
||||
e.type = SDL_WINDOWEVENT;
|
||||
@@ -118,8 +137,8 @@ void MainLoop() {
|
||||
|
||||
// Теперь DOM перестроен, можно забирать актуальные размеры.
|
||||
// Если canvas должен занимать все окно браузера:
|
||||
int canvasW = EM_ASM_INT({ return window.innerWidth; });
|
||||
int canvasH = EM_ASM_INT({ return window.innerHeight; });
|
||||
int canvasW, canvasH;
|
||||
getViewportCssSize(canvasW, canvasH);
|
||||
|
||||
applyResize(canvasW, canvasH);
|
||||
}
|
||||
@@ -141,14 +160,10 @@ EM_BOOL onWebGLContextRestored(int /*eventType*/, const void* /*reserved*/, void
|
||||
|
||||
|
||||
EM_BOOL onWindowResized(int /*eventType*/, const EmscriptenUiEvent* e, void* /*userData*/) {
|
||||
double w, h;
|
||||
emscripten_get_element_css_size("window", &w, &h);
|
||||
int w, h;
|
||||
getViewportCssSize(w, h);
|
||||
|
||||
// Если "window" не поддерживается вашей версией SDK, используем данные из e:
|
||||
// int logicalW = e->windowInnerWidth;
|
||||
// int logicalH = e->windowInnerHeight;
|
||||
|
||||
applyResize(static_cast<int>(w), static_cast<int>(h));
|
||||
applyResize(w, h);
|
||||
return EM_FALSE;
|
||||
}
|
||||
|
||||
@@ -181,8 +196,8 @@ int main(int argc, char* argv[]) {
|
||||
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, EM_FALSE, onWindowResized);
|
||||
emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, nullptr, EM_TRUE, onFullscreenChanged);
|
||||
|
||||
int canvasW = EM_ASM_INT({ return window.innerWidth; });
|
||||
int canvasH = EM_ASM_INT({ return window.innerHeight; });
|
||||
int canvasW, canvasH;
|
||||
getViewportCssSize(canvasW, canvasH);
|
||||
applyResize(canvasW, canvasH);
|
||||
|
||||
SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
|
||||
|
||||
Reference in new issue
Block a user