mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-05-02 10:33:57 +00:00
e57164d345
10 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
e57164d345
|
Fix use-after-free crash and misaligned protocol access
Stop active ScenePlayer animation in OnActorEnter/OnActorExit before modifying ride animation state — the ScenePlayer may still hold a reference to the ride vehicle ROI that ClearRideAnimation frees. Deactivate() and OnWorldDisabled() already had this guard. Add alignment padding to MessageHeader (13→14 bytes) so uint16_t fields in packed protocol structs no longer sit at odd offsets (UBSan violation). Breaking wire format change — all clients and relay must update together. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> |
||
|
|
982957ee5e
|
Add WebSocket reconnection with exponential backoff
Automatically reconnect when the WebSocket connection is lost (e.g. phone sleep, alt-tab, network blip) instead of exiting the game. - Add reconnection state machine (CONNECTED → RECONNECTING → CONNECTED or DISCONNECTED) with exponential backoff (1s→30s cap, 10 max attempts) - Add OnConnectionStatusChanged callback (connected/reconnecting/failed/ rejected) to PlatformCallbacks, with Emscripten CustomEvent dispatch and native SDL_Log implementations - Add WorldStateSync::ResetForReconnect() to clear session state - Only exit the game on room-full rejection (WasRejected); connection loss is handled internally by the state machine - Rename WasDisconnected→WasRejected, CheckDisconnected→CheckRejected, IsMultiplayerDisconnected→IsMultiplayerRejected through the full call chain for accurate naming - Remove Module._exitCode from JS onclose; use C++ callback + sessionStorage for room-full signaling instead - Clean up EXIT_CONNECTION_LOST constant (obsolete) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> |
||
|
|
13f6239808
|
Claude/fix platform compilation errors hol yw (#19)
* Add native platform multiplayer support via libwebsockets Add a general-purpose WebSocket transport using libwebsockets (v4.5-stable) for all non-Emscripten platforms, enabling multiplayer on desktop, mobile, and any other platform that libwebsockets supports. New files: - LwsTransport: implements NetworkTransport using lws client API with non-blocking event loop integration via lws_service(ctx, 0) in Receive() - NativeCallbacks: implements PlatformCallbacks with SDL_Log output Build integration: - libwebsockets fetched conditionally only when ISLE_EXTENSIONS=ON and not building for Emscripten, with SSL disabled (ws:// only) - Follows existing 3rdparty dependency patterns (FetchContent/find_package) https://claude.ai/code/session_01BojPvEEhREJ4xdihJfin3m * Fix Connect() reconnection guard to check context instead of connected flag The previous check (m_connected) would fail to clean up a stale lws context when reconnecting after a connection error, since the error handler already sets m_connected=false. Check m_context instead, matching the emscripten version's behavior of cleaning up any existing connection state. https://claude.ai/code/session_01BojPvEEhREJ4xdihJfin3m * Fix cross-platform compilation errors for libwebsockets multiplayer - Add ISLE_USE_WEBSOCKETS cmake option to conditionally build lws transport (disabled on Switch, 3DS, Vita, Emscripten which lack standard networking) - Disable lws internal -Werror (DISABLE_WERROR) to fix GCC/Clang builds - Override MSVC /WX with /WX- on the websockets target to fix MSVC builds - Skip precompiled headers for native transport files to avoid miniwin/windows.h type conflicts on MinGW - Guard native transport includes/instantiation with ISLE_USE_WEBSOCKETS define so platforms without lws gracefully skip multiplayer networking https://claude.ai/code/session_01UdLx6KWCXocF6guCQDq8C8 * Fix native WebSocket transport compilation errors and disconnect detection - Fix undefined variable: relayUrl → s_relayUrl in multiplayer.cpp - Fix interface mismatch: LwsTransport now implements WasDisconnected() matching the base class pure virtual - Add WasRejected() to NetworkTransport interface for parity between emscripten and native backends (rejected = closed before ever connected) - Fix post-connection disconnect detection: m_disconnected is now set unconditionally on any close/error, not only for pre-connection failures - Guard shared init code with #if defined(__EMSCRIPTEN__) || defined(ISLE_USE_WEBSOCKETS) to avoid creating a NetworkManager on platforms without a transport - Collapse identical CONNECTION_ERROR/CLOSED handlers into fallthrough Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Move exit code constants to networktransport.h and eliminate magic numbers Move EXIT_ROOM_FULL/EXIT_CONNECTION_LOST from NetworkManager (where they were unused) to the Multiplayer namespace in networktransport.h so both backends can reference them. Pass them into the emscripten inline JS as parameters instead of hardcoding 10/11. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Implement missing PlatformCallbacks pure virtuals in NativeCallbacks NativeCallbacks only overrode OnPlayerCountChanged, leaving three pure virtuals unimplemented (OnThirdPersonChanged, OnNameBubblesChanged, OnAllowCustomizeChanged), making it abstract and un-instantiable on MSVC. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Remove WebSocket subprotocol request to match browser behavior The relay server doesn't negotiate subprotocols, so lws requesting Sec-WebSocket-Protocol: lws-multiplayer caused the handshake to stall and freeze the game. The browser WebSocket API doesn't send this header. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add debug logging to native WebSocket transport Temporary diagnostic logs to find where the game freezes on Windows: - Before/after lws_create_context, lws_client_connect_via_info, lws_service - In all lws callback events including unhandled reason codes - Suppress verbose lws internal logging Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Move lws_service to background thread to prevent game loop blocking lws_service(ctx, 0) blocks the main thread on Windows despite the 0ms timeout, freezing the game on a black screen. Move all libwebsockets event processing to a dedicated LwsServiceThread using MxThread, with MxCriticalSection-protected queues for thread-safe send/receive and std::atomic flags for connection state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix service thread lifecycle for reconnect support MxThread is single-use: m_running is set TRUE in the constructor and never reset after Terminate(). Allocate LwsServiceThread on the heap so each connection gets a fresh instance. Also handle Start() failure to avoid deadlock in Terminate() if SDL thread creation fails. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix right-click camera turning on Desktop by tracking button state internally On Windows, SDL3 uses different mouse device IDs for button events (normal input) vs motion events (raw input during relative mouse mode). This causes motion.state to not reflect the right button being held, since the button state was recorded under a different device ID. Track right button state internally via SDL_EVENT_MOUSE_BUTTON_DOWN/UP instead of relying on motion.state, which works reliably across all platforms. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Restore cursor position after right-click camera drag on Desktop On Desktop, SDL_SetWindowRelativeMouseMode accumulates absolute position internally, so the cursor appears at a different location when released. Save the cursor position before entering relative mode and warp it back on release, matching the Emscripten pointer lock behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix default * Add debug logging for peer ID assignment Logs the assigned peer ID when MSG_ASSIGN_ID is received to help diagnose whether ws:// connections are reaching the Durable Object. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add missing SDL_log.h include for SDL_Log Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add TLS/WSS support to native WebSocket transport via mbedTLS Cloudflare custom domains require wss:// for proper Worker routing. Fetch mbedTLS v3.6.3 via FetchContent and enable LWS_WITH_MBEDTLS so the Desktop client can connect over TLS. The transport now detects wss:// URLs and sets the appropriate SSL context and connection flags. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Disable iniparser test suite during FetchContent build iniparser's main branch added tests that require Ruby. Set BUILD_TESTING OFF in the block to skip test configuration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Revert "Disable iniparser test suite during FetchContent build" This reverts commit abdd9b37bced18dd54486c1cfb23a53a2d1b3142. * Fix mbedTLS tarball MD5 hash Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Bump mbedTLS from 3.6.3 to 3.6.5 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Use official mbedTLS release archive instead of GitHub auto-generated tarball The auto-generated tarball from /archive/refs/tags/ doesn't include the mbedtls_framework submodule, causing a build failure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix mbedTLS download URL to use correct release tag format Release tags use 'mbedtls-3.6.5' not 'v3.6.5'. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix mbedTLS include dirs by setting cache vars inside block() scope mbedtls_SOURCE_DIR and mbedtls_BINARY_DIR are only available inside the block() where FetchContent_MakeAvailable runs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Disable lws export targets to fix mbedTLS export set conflict lws install(EXPORT) fails because FetchContent'd mbedTLS targets aren't in an export set. LWS_WITH_EXPORT_LWSTARGETS OFF disables this since we don't need install rules. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Remove EXCLUDE_FROM_ALL from mbedTLS FetchContent mbedcrypto depends on internal sub-libraries (everest, p256m) that don't get built when EXCLUDE_FROM_ALL is set, causing link failures. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add explicit build dependencies from websockets to mbedTLS internals The Visual Studio generator doesn't infer the build order for mbedTLS's internal sub-libraries (everest, p256m) when they are transitive dependencies through mbedcrypto. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Force mbedTLS to build as static libraries Without explicit BUILD_SHARED_LIBS OFF, mbedTLS (and its internal sub-libraries like everest) build as DLLs instead of static libs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Remove unnecessary add_dependencies for mbedTLS internals The real issue was BUILD_SHARED_LIBS, not build ordering. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Scope BUILD_SHARED_LIBS to mbedTLS block instead of global cache CACHE BOOL FORCE writes to the global cache, leaking beyond the block() and preventing lego1.dll from being built as a shared lib. A regular variable is properly scoped by block(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Pre-set mbedTLS 3.x API check results for lws configure lws uses check_function_exists for mbedtls_md_setup but the check fails since mbedTLS targets aren't built at configure time. Without the result, lws falls back to the removed 2.x mbedtls_md_init_ctx. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add debug logging to multiplayer initialization Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Enable verbose lws logging to diagnose TLS handshake failure Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix TLS: use ALLOW_INSECURE instead of SKIP_SERVER_CERT_HOSTNAME_CHECK SKIP_SERVER_CERT_HOSTNAME_CHECK also skips setting SNI (Server Name Indication) via mbedtls_ssl_set_hostname. Without SNI, Cloudflare can't route the connection to the Worker. ALLOW_INSECURE disables cert verification while still setting the SNI hostname. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Suppress CMake deprecation error for mbedTLS cmake_minimum_required Newer CMake versions (3.27+) error on old cmake_minimum_required values. Setting CMAKE_POLICY_VERSION_MINIMUM to 3.10 suppresses this for the mbedTLS subdirectory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix left-click and cursor warp regression from right-click camera fix The mouse button handler ran relative-mouse-mode and cursor-warp logic for ALL button events, not just right-button events. Left clicks would enter the else branch, disabling relative mode and warping the cursor to a stale/zero position. Scope the entire block to right-button events only. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Move CMAKE_POLICY_VERSION_MINIMUM outside block() scope The variable may not propagate from block() scope into FetchContent's add_subdirectory call on some CMake versions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix mbedTLS cmake_minimum_required deprecation error in CI CI uses -Werror=dev which makes the CMake deprecation warning for cmake_minimum_required(VERSION < 3.10) a fatal error. Patch mbedTLS's CMakeLists.txt via PATCH_COMMAND to use VERSION 3.10 instead. CMAKE_POLICY_VERSION_MINIMUM only works on CMake 4.x, not 3.28. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Rename ISLE_USE_WEBSOCKETS to ISLE_HAS_LWS and clean up multiplayer code Rename the CMake option and compile definition to better reflect the presence of the libwebsockets library. Remove debug SDL_Log calls and unused includes, extract magic numbers into named constants, add null guard for lws_cancel_service, and use inline constexpr for namespace constants. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Rename ISLE_HAS_LWS to ISLE_USE_LWS Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix uninitialized variable UB in WorldStateSync::HandleEntityMutation Split GetInfoArray() output parameter from FindEntityIndex() call to avoid undefined behavior from unspecified function argument evaluation order. MSVC evaluates right-to-left, reading `count` before GetInfoArray() initializes it, triggering _RTC_UninitUse and preventing entity mutation sync in multiplayer. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
569c8b467b
|
Separate extensions (#18)
* WIP * WIP * Make camera the single source of truth for broadcast state Remove redundant local copies of walkAnimId, idleAnimId, and displayActorIndex from NetworkManager. BroadcastLocalState now reads these from the camera's Controller, eliminating dual-copy sync issues. Additional cleanup: - Early-return on null cam in SendEmote/HandleCustomize for clarity - Only consume camera-dependent pending requests when cam is available - Move local name bubble creation from BroadcastLocalState to Tickle - Remove dead NetworkManager::SetDisplayActorIndex method Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix clang format --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> |
||
|
|
a5b2ea0ce9
|
Extract CharacterAnimator component, EncodeUsername utility, replace C stdlib with SDL
Extract ~420 lines of duplicated character animation logic from RemotePlayer and ThirdPersonCamera into a shared CharacterAnimator component. Both classes now compose a CharacterAnimator member that handles walk/idle/emote animation playback, vehicle ride animations, click animation tracking, name bubbles, and animation cache management. Behavioral differences between consumers (emote transform save/restore) are handled via CharacterAnimatorConfig. Also extract duplicated username encoding (letter indices to ASCII) from NetworkManager::BroadcastLocalState and ThirdPersonCamera::CreateNameBubble into EncodeUsername() in protocol.cpp. Replace C standard library usage across the multiplayer extension with SDL equivalents: sprintf->SDL_snprintf, sscanf->SDL_sscanf, atoi->SDL_atoi, strcmp->SDL_strcmp, fabsf->SDL_fabsf, floorf->SDL_floorf, and remove unnecessary <cmath>, <cstdio>, <cstdlib> headers. |
||
|
|
9e8ecd6d44
|
Move routing info into message header, make relay type-agnostic | ||
|
|
e0a1ac781f
|
Add free camera controls (#10)
* Add free camera orbit controls to multiplayer third-person camera Replace the fixed camera offset with dynamic orbit parameters (yaw, pitch, distance) computed from spherical coordinates. Mouse wheel controls zoom, right-click drag controls orbit, and two-finger touch gestures support pinch-zoom and orbit on touchscreens. The controls are always active when third-person mode is enabled. A single SDL event forwarding hook is added to the main event loop; all other changes are contained within the multiplayer extension. https://claude.ai/code/session_013FyPCrJSaHxiJwdfGBVnYP * Fix linker error and refactor orbit camera controls Move HandleSDLEvent extension call from ISLE (no EXTENSIONS define) into LegoInputManager::UpdateLastInputMethod in LEGO1 to fix unresolved symbol errors. DRY up orbit camera code with ClampPitch/ClampDistance/ ResetOrbitState/ApplyOrbitCamera helpers. Simplify direction vector computation. Fix mouse orbit yaw direction. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fixes --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
eb6d2b8728
|
Sync sky light (#9)
* Sync sky color and light position in multiplayer Add ENTITY_SKY and ENTITY_LIGHT to the WorldEvent system so the host controls sky color (hue/saturation via observatory sun/moon/palette buttons) and light position (globe arrows) with the same host-authoritative pattern used for plants and buildings. Non-host players send requests to the host who applies and broadcasts. Sky/light state is appended to the world snapshot so joining players get the current values. https://claude.ai/code/session_01X2cPVQEo7c92wpWA7QPPMG * Clean up sky/light sync: remove debug logging, DRY apply logic, fix host routing - Extract ApplySkyLightState helper to deduplicate sky/light apply code between RestoreSkyLightState and HandleWorldSnapshot - Remove all SDL_Log debug calls and SDL_log.h includes - Remove dead OnWorldEnabled method from WorldStateSync (replaced by OnHostChanged in OnSaveLoaded) - Fix HandleSkyLightMutation host path: return FALSE to let local switch case proceed, instead of duplicating via ApplyWorldEvent - Simplify isle.cpp HandleControl: split observatory cases into individual switch arms with single early-return multiplayer hook - Add save load hooks to sync world state with multiplayer peers - Fix player count to exclude local player without valid actor - Support broadcast snapshots (targetPeerId=0) in relay server --------- |
||
|
|
c8c3b7276e
|
Fix 3rd/1st person camera switch direction bugs (#4)
- Fix broadcast direction: use IsActive() instead of IsROITurnedAround() so the negate in BroadcastLocalState only fires when movement inversion is active, not based on a default-true flag - Fix vehicle ROI direction for 3rd-person camera: undo Enter()'s TurnAround on small vehicles so the backward-z convention is preserved. Vehicles are placed with ROI z opposite to visual forward, and Enter()'s TurnAround breaks this for 3rd-person rendering. Applied in both OnActorEnter (entering while 3rd-person enabled) and ReinitForCharacter (enabling 3rd-person while already on a vehicle) - Fix vehicle direction on exit: apply extra TurnAround in OnActorExit when 3rd-person is active, since Exit()'s TurnAround assumes Enter()'s TurnAround is still in effect - Add WrappedUpdateWorldData() after manual direction flips in Disable() and ReinitForCharacter() to keep bounding volumes consistent and prevent stale world data from causing momentary camera/direction glitches - Remove unused IsROITurnedAround() method - Fix data race between WASM exports and game thread |
||
|
|
c760db50a9
|
Extract WorldStateSync from NetworkManager
Move world state synchronization logic (snapshots, events, entity mutation routing) into a dedicated WorldStateSync class, reducing NetworkManager from ~790 to ~420 lines. |