isle-portable/LEGO1/lego/legoomni/include/isle.h
foxtacles 7b114bbe59
Add multiplayer extension (#789)
* Add multiplayer extension

* Fix animation system to work when host is outside ISLE world

- Move TickHostSessions outside m_inIsleWorld gate so the host can
  coordinate animations from any world
- Load animation catalog early in HandleCreate so the host can
  coordinate before entering the ISLE world
- Use network-reported positions for remote player location detection
  instead of requiring spawned ROIs
- Always erase sessions at launch — the host's job ends when the
  animation starts; clients play and complete independently
- Replace BroadcastAnimComplete with locally-driven completion
  callbacks: host generates eventId at launch, clients cache
  completion JSON at start time, fire it when ScenePlayer finishes
- Make StopAnimation only do local cleanup (stop playback, cancel
  own interest, reset coordinator) without destroying the session
  host, so other players' sessions survive world transitions
- Broadcast state=0 in ResetAnimationState for full teardown paths
  (shutdown, reconnect, host migration) so clients aren't left with
  stale session state

* Fix use-after-free crash in ScenePlayer when remote player disconnects mid-animation

When a remote player's ROI is destroyed (disconnect, timeout, or respawn),
notify all active ScenePlayer instances to null out dangling references
before the ROI is freed. The animation engine already handles null ROI map
entries gracefully, so playback continues for remaining participants.

* Fix crash when performer's child ROIs are left dangling in ScenePlayer

NotifyROIDestroyed now walks the parent chain to also invalidate child
ROIs of the destroyed performer (head, limbs, etc.) that were placed
into the roiMap by BuildROIMap. The ancestor walk happens once; all
other fields are cleaned with simple pointer equality.

* Allow spectator to play click animation during scene playback

* Make PTATCAM track spectator ROI instead of camera in ScenePlayer

* Only regenerate emscripten version files when git state changes

Replace add_custom_target(ALL) with add_custom_command(OUTPUT) so the
version script only runs when .git/HEAD or the current branch ref file
changes, instead of on every build.

* Fix ROI name collision causing dangling pointers in NPC locomotion roiMaps

When ScenePlayer created cloned NPC ROIs for cooperative animations, it
renamed them to match the original character name and added them to the
ViewManager. This created a name collision: two ROIs with the same name.
The original game's AppendROIToScene searches by name and stops at the
first match, so if a locomotion BuildROIMap ran while the clone existed,
it could capture pointers to the clone's child ROIs. When the clone was
later destroyed (CleanupProps), those roiMap entries became dangling
pointers, crashing in AnimateWithTransform at roi.h:151 (SetVisibility).

Fix: use the alias mechanism (already supported by AnimUtils::BuildROIMap)
instead of renaming clones. Also unify all ROI name generation behind a
shared counter to prevent character manager key collisions.
2026-04-05 17:13:15 +02:00

207 lines
6.3 KiB
C++

#ifndef ISLE_H
#define ISLE_H
#include "actionsfwd.h"
#include "extensions/fwd.h"
#include "legogamestate.h"
#include "legonamedplane.h"
#include "legostate.h"
#include "legoworld.h"
#include "radio.h"
class Ambulance;
class Bike;
class DuneBuggy;
class Helicopter;
class Jetski;
class JukeBoxEntity;
class LegoNamedTexture;
class Motocycle;
class LegoPathStructNotificationParam;
class Pizza;
class Pizzeria;
class RaceCar;
class SkateBoard;
class TowTrack;
// VTABLE: LEGO1 0x100d7028
// VTABLE: BETA10 0x101b9d40
// SIZE 0x26c
class Act1State : public LegoState {
public:
enum ElevatorFloor {
c_floor1 = 1,
c_floor2,
c_floor3
};
enum {
e_none = 0,
e_initial = 1,
e_elevator = 2,
e_pizza = 3,
e_helicopter = 4,
e_transitionToJetski = 5,
e_transitionToRacecar = 6,
e_transitionToTowtrack = 7,
e_towtrack = 8,
e_transitionToAmbulance = 9,
e_ambulance = 10,
e_jukebox = 11,
};
Act1State();
// FUNCTION: LEGO1 0x100338a0
// FUNCTION: BETA10 0x10036040
const char* ClassName() const override // vtable+0x0c
{
// STRING: LEGO1 0x100f0154
return "Act1State";
}
// FUNCTION: LEGO1 0x100338b0
MxBool IsA(const char* p_name) const override // vtable+0x10
{
return !strcmp(p_name, Act1State::ClassName()) || LegoState::IsA(p_name);
}
MxBool Reset() override; // vtable+0x18
MxResult Serialize(LegoStorage* p_storage) override; // vtable+0x1c
void PlayCptClickDialogue();
void StopCptClickDialogue();
void RemoveActors();
void PlaceActors();
MxU32 GetState() { return m_state; }
ElevatorFloor GetElevatorFloor() { return (ElevatorFloor) m_elevFloor; }
MxBool IsSpawnInInfocenter() { return m_spawnInInfocenter; }
void SetState(MxU32 p_state) { m_state = p_state; }
void SetElevatorFloor(ElevatorFloor p_elevFloor) { m_elevFloor = p_elevFloor; }
void SetSpawnInInfocenter(MxBool p_spawnInInfocenter) { m_spawnInInfocenter = p_spawnInInfocenter; }
// SYNTHETIC: LEGO1 0x10033960
// Act1State::`scalar deleting destructor'
// TODO: Most likely getters/setters are not used according to BETA.
Playlist m_cptClickDialogue; // 0x008
IsleScript::Script m_currentCptClickDialogue; // 0x014
MxU32 m_state; // 0x018
MxS16 m_elevFloor; // 0x01c
MxBool m_playingFloor2Animation; // 0x01e
MxBool m_switchedToArea; // 0x01f
MxBool m_planeActive; // 0x020
MxBool m_spawnInInfocenter; // 0x021
MxBool m_playedExitExplanation; // 0x022
undefined m_unk0x023; // 0x023
LegoNamedPlane m_motocyclePlane; // 0x024
LegoNamedPlane m_bikePlane; // 0x070
LegoNamedPlane m_skateboardPlane; // 0x0bc
LegoNamedPlane m_helicopterPlane; // 0x108
LegoNamedTexture* m_helicopterWindshield; // 0x154
LegoNamedTexture* m_helicopterJetLeft; // 0x158
LegoNamedTexture* m_helicopterJetRight; // 0x15c
Helicopter* m_helicopter; // 0x160
LegoNamedPlane m_jetskiPlane; // 0x164
LegoNamedTexture* m_jetskiFront; // 0x1b0
LegoNamedTexture* m_jetskiWindshield; // 0x1b4
Jetski* m_jetski; // 0x1b8
LegoNamedPlane m_dunebuggyPlane; // 0x1bc
LegoNamedTexture* m_dunebuggyFront; // 0x208
DuneBuggy* m_dunebuggy; // 0x20c
LegoNamedPlane m_racecarPlane; // 0x210
LegoNamedTexture* m_racecarFront; // 0x25c
LegoNamedTexture* m_racecarBack; // 0x260
LegoNamedTexture* m_racecarTail; // 0x264
RaceCar* m_racecar; // 0x268
};
// VTABLE: LEGO1 0x100d6fb8
// VTABLE: BETA10 0x101b9cc8
// SIZE 0x140
class Isle : public LegoWorld {
public:
enum {
c_playCamAnims = 0x20,
c_playMusic = 0x40
};
Isle();
~Isle() override;
MxLong Notify(MxParam& p_param) override; // vtable+0x04
// FUNCTION: LEGO1 0x10030900
MxBool WaitForTransition() override { return TRUE; } // vtable+0x5c
// FUNCTION: LEGO1 0x10030910
// FUNCTION: BETA10 0x10035d70
const char* ClassName() const override // vtable+0x0c
{
// STRING: LEGO1 0x100f0458
return "Isle";
}
// FUNCTION: LEGO1 0x10030920
MxBool IsA(const char* p_name) const override // vtable+0x10
{
return !strcmp(p_name, Isle::ClassName()) || LegoWorld::IsA(p_name);
}
MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18
void ReadyWorld() override; // vtable+0x50
void Add(MxCore* p_object) override; // vtable+0x58
void VTable0x60() override; // vtable+0x60
MxBool Escape() override; // vtable+0x64
void Enable(MxBool p_enable) override; // vtable+0x68
virtual void RemoveVehicle(LegoPathActor* p_actor); // vtable+0x6c
void SetDestLocation(LegoGameState::Area p_destLocation) { m_destLocation = p_destLocation; }
MxBool HasHelicopter() { return m_helicopter != NULL; }
void SwitchToInfocenter();
friend class Act1State;
friend class Multiplayer::WorldStateSync;
// SYNTHETIC: LEGO1 0x10030a30
// Isle::`scalar deleting destructor'
protected:
MxLong HandleEndAction(MxEndActionNotificationParam& p_param);
MxLong HandleControl(LegoControlManagerNotificationParam& p_param);
MxLong HandlePathStruct(LegoPathStructNotificationParam& p_param);
MxLong HandleTransitionEnd();
void HandleElevatorEndAction();
void UpdateGlobe();
void CheckAreaExiting();
void CreateState();
void TransitionToOverlay(
IsleScript::Script p_script,
JukeboxScript::Script p_music,
const char* p_cameraLocation,
MxBool p_setCamera
);
Act1State* m_act1state; // 0xf8
Pizza* m_pizza; // 0xfc
Pizzeria* m_pizzeria; // 0x100
TowTrack* m_towtrack; // 0x104
Ambulance* m_ambulance; // 0x108
JukeBoxEntity* m_jukebox; // 0x10c
Helicopter* m_helicopter; // 0x110
Bike* m_bike; // 0x114
DuneBuggy* m_dunebuggy; // 0x118
Motocycle* m_motocycle; // 0x11c
SkateBoard* m_skateboard; // 0x120
RaceCar* m_racecar; // 0x124
Jetski* m_jetski; // 0x128
Radio m_radio; // 0x12c
LegoGameState::Area m_destLocation; // 0x13c
};
#endif // ISLE_H