isle-portable/extensions/include/extensions/multiplayer.h
foxtacles 29955df947
Export MultiplayerExt symbols accessed from isle executable (#1)
* Export MultiplayerExt symbols accessed from isle executable

When lego1 is built as a shared library (DLL), symbols used by the isle
executable through the Extension<T>::Call() template need to be exported.
Add LEGO1_EXPORT to MultiplayerExt::enabled and MultiplayerExt::CheckRejected()
which are referenced from isleapp.cpp via the template instantiation.

https://claude.ai/code/session_01HHMmowothg25fephi6iidq

* Use inline const instead of constexpr for extension function pointers

constexpr cannot be used with dllimport function addresses since they
are resolved at load time through the IAT, not at compile time. Change
to inline const which preserves the single-definition semantics (via
inline) while allowing runtime initialization of the function pointers.

https://claude.ai/code/session_01HHMmowothg25fephi6iidq

* Fix multiplayer extension link errors across DLL boundary

When lego1 is a shared library, Extension<T>::Call() instantiated from
isle.exe references MultiplayerExt::enabled and CheckRejected() which
are not exported. Instead of exporting internal symbols (which also
breaks constexpr with dllimport), add an exported IsMultiplayerRejected()
wrapper that keeps the Extension<T>::Call() instantiation inside lego1.

https://claude.ai/code/session_01HHMmowothg25fephi6iidq

* Guard IsMultiplayerRejected with EXTENSIONS ifdef

extensions.cpp is only compiled when ISLE_EXTENSIONS is ON, so the
wrapper function and its call site need #ifdef EXTENSIONS guards for
targets like x86 MSVC where extensions are disabled.

https://claude.ai/code/session_01HHMmowothg25fephi6iidq

* Move IsMultiplayerRejected definition to multiplayer.cpp

The function is declared in multiplayer.h and belongs with the rest of
the multiplayer extension code, not in the general extensions.cpp file.

https://claude.ai/code/session_01HHMmowothg25fephi6iidq

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-01 18:21:15 -08:00

60 lines
1.6 KiB
C++

#pragma once
#include "extensions/extensions.h"
#include "mxtypes.h"
#include <map>
#include <string>
class LegoEntity;
class LegoWorld;
namespace Multiplayer
{
class NetworkManager;
class NetworkTransport;
} // namespace Multiplayer
namespace Extensions
{
class MultiplayerExt {
public:
static void Initialize();
static MxBool HandleWorldEnable(LegoWorld* p_world, MxBool p_enable);
// Intercepts click notifications on plants/buildings for multiplayer routing.
// Returns TRUE if the click should be suppressed locally (non-host).
static MxBool HandleEntityNotify(LegoEntity* p_entity);
static std::map<std::string, std::string> options;
static bool enabled;
static std::string relayUrl;
static std::string room;
// Returns true if the multiplayer connection was rejected (e.g. room full).
static MxBool CheckRejected();
static void SetNetworkManager(Multiplayer::NetworkManager* p_networkManager);
static Multiplayer::NetworkManager* GetNetworkManager();
private:
static Multiplayer::NetworkManager* s_networkManager;
static Multiplayer::NetworkTransport* s_transport;
};
#ifdef EXTENSIONS
LEGO1_EXPORT bool IsMultiplayerRejected();
constexpr auto HandleWorldEnable = &MultiplayerExt::HandleWorldEnable;
constexpr auto HandleEntityNotify = &MultiplayerExt::HandleEntityNotify;
constexpr auto CheckRejected = &MultiplayerExt::CheckRejected;
#else
constexpr decltype(&MultiplayerExt::HandleWorldEnable) HandleWorldEnable = nullptr;
constexpr decltype(&MultiplayerExt::HandleEntityNotify) HandleEntityNotify = nullptr;
constexpr decltype(&MultiplayerExt::CheckRejected) CheckRejected = nullptr;
#endif
}; // namespace Extensions