Camera v3: dedicated=server cam only; drop KeyMap stack

This commit is contained in:
RallyBlock committed 2026-11-10 01:26:02 -05:00
1 parent c731f4ab15
commit 19abb97585
1 file changed
+33 -125
+33 -125
View File
@@ -1,4 +1,6 @@
// Client_RPG - top-down camera, click-to-move, and RPG windows for GameMode_RPG.
// Camera v3: on dedicated servers the host owns the Camera transform; the client only
// sends RPG_CamSync (yaw/dist) and uses stock moveMap + RPGClient_Input (no extra ActionMaps).
exec("./ui.cs");
// The server probes with RPG_Probe; reply with serverCmdRPG_Hello(2) to play.
@@ -9,9 +11,6 @@ $RPGClient::Dist = 14;
$RPGClient::TopDownPitch = 1.22;
$RPGClient::OrbitInit = 0;
$RPGClient::HudPlaced = 0;
$RPGClient::KeyMapPushed = 0;
$RPGClient::MoveHijacked = 0;
$RPGClient::GlobalKeys = 0;
$RPGClient::PlayBooted = 0;
$RPGClient::CamTickOn = 0;
$RPGClient::PanX = 0;
@@ -181,10 +180,14 @@ function RPGClient_EnsureCursor()
cursorOn();
}
function RPGClient_NetCam()
{
return isObject(ServerConnection) && !isObject(localClientConnection);
}
function RPGClient_CameraTick()
{
$RPGClient::CamTickSched = 0;
RPGClient_SyncInputStack();
if (!isObject(ServerConnection) || !$RPGClient::CamTickOn)
{
return;
@@ -236,16 +239,6 @@ function RPGClient_CameraTick()
$RPGClient::CamTickSched = schedule(32, 0, RPGClient_CameraTick);
}
function RPGClient_BumpKeyMap()
{
if (!$RPGClient::Active || !isObject(RPGClient_KeyMap))
{
return;
}
RPGClient_KeyMap.pop();
RPGClient_KeyMap.push();
}
function RPGClient_StartCameraTick()
{
cancel($RPGClient::CamTickSched);
@@ -265,10 +258,6 @@ function RPGClient_TextTyping()
function RPGClient_SetChatOpen(%open)
{
$RPGClient::ChatOpen = %open ? 1 : 0;
if ($RPGClient::Active)
{
schedule(0, 0, RPGClient_SyncInputStack);
}
}
function RPGClient_RpgKeys()
@@ -418,35 +407,6 @@ function RPGClient_RestoreMoveMap()
RPGClient_StockMoveMapBinds();
}
function RPGClient_SyncInputStack()
{
if (!$RPGClient::Active)
{
return;
}
RPGClient_StockMoveMapBinds();
if (RPGClient_TextTyping())
{
if ($RPGClient::KeyMapPushed && isObject(RPGClient_KeyMap))
{
RPGClient_KeyMap.pop();
$RPGClient::KeyMapPushed = 0;
}
RPGClient_ClearGlobalKeys();
return;
}
RPGClient_EnsureKeyMap();
}
function RPGClient_EnsureGlobalKeys()
{
}
function RPGClient_ClearGlobalKeys()
{
$RPGClient::GlobalKeys = 0;
}
function RPGClient_SendClickFromCursor(%button)
{
if (!$RPGClient::Active || !isObject(Canvas))
@@ -456,68 +416,6 @@ function RPGClient_SendClickFromCursor(%button)
RPGClient_SendClick(%button, Canvas.getCursorPos());
}
function RPGClient_EnsureKeyMap()
{
if (!isObject(RPGClient_KeyMap))
{
new ActionMap(RPGClient_KeyMap);
RPGClient_KeyMap.bind(keyboard, w, RPGClient_KeyMvForward);
RPGClient_KeyMap.bind(keyboard, s, RPGClient_KeyMvBackward);
RPGClient_KeyMap.bind(keyboard, a, RPGClient_KeyMvLeft);
RPGClient_KeyMap.bind(keyboard, d, RPGClient_KeyMvRight);
RPGClient_KeyMap.bind(keyboard0, w, RPGClient_KeyMvForward);
RPGClient_KeyMap.bind(keyboard0, s, RPGClient_KeyMvBackward);
RPGClient_KeyMap.bind(keyboard0, a, RPGClient_KeyMvLeft);
RPGClient_KeyMap.bind(keyboard0, d, RPGClient_KeyMvRight);
RPGClient_KeyMap.bind(keyboard, left, RPGClient_YawLeft);
RPGClient_KeyMap.bind(keyboard, right, RPGClient_YawRight);
RPGClient_KeyMap.bind(keyboard0, left, RPGClient_YawLeft);
RPGClient_KeyMap.bind(keyboard0, right, RPGClient_YawRight);
RPGClient_KeyMap.bind(keyboard, equals, RPGClient_ZoomIn);
RPGClient_KeyMap.bind(keyboard, minus, RPGClient_ZoomOut);
RPGClient_KeyMap.bind(keyboard, "[", RPGClient_ZoomIn);
RPGClient_KeyMap.bind(keyboard, "]", RPGClient_ZoomOut);
RPGClient_KeyMap.bind(keyboard0, equals, RPGClient_ZoomIn);
RPGClient_KeyMap.bind(keyboard0, minus, RPGClient_ZoomOut);
RPGClient_KeyMap.bind(keyboard, m, RPGClient_ToggleCursor);
RPGClient_KeyMap.bind(keyboard0, m, RPGClient_ToggleCursor);
}
if (RPGClient_TextTyping())
{
if ($RPGClient::KeyMapPushed)
{
RPGClient_KeyMap.pop();
$RPGClient::KeyMapPushed = 0;
}
return;
}
if ($RPGClient::KeyMapPushed)
{
RPGClient_KeyMap.pop();
}
RPGClient_KeyMap.push();
$RPGClient::KeyMapPushed = 1;
}
function RPGClient_HijackMoveMap()
{
if ($RPGClient::MoveHijacked || !isObject(moveMap))
{
return;
}
moveMap.bind(keyboard, w, RPGClient_KeyMvForward);
moveMap.bind(keyboard, s, RPGClient_KeyMvBackward);
moveMap.bind(keyboard, a, RPGClient_KeyMvLeft);
moveMap.bind(keyboard, d, RPGClient_KeyMvRight);
moveMap.bind(keyboard, left, RPGClient_YawLeft);
moveMap.bind(keyboard, right, RPGClient_YawRight);
moveMap.bind(keyboard, equals, RPGClient_ZoomIn);
moveMap.bind(keyboard, minus, RPGClient_ZoomOut);
moveMap.bind(keyboard, "[", RPGClient_ZoomIn);
moveMap.bind(keyboard, "]", RPGClient_ZoomOut);
$RPGClient::MoveHijacked = 1;
}
function RPGClient_EnsureOverlay()
{
if (!isObject(PlayGui))
@@ -541,7 +439,10 @@ function RPGClient_EnsureOverlay()
PlayGui.add(RPGClient_Mouse);
PlayGui.pushToBack(RPGClient_Mouse);
}
RPGClient_SyncInputStack();
if ($RPGClient::Active)
{
RPGClient_StockMoveMapBinds();
}
$enableDirectInput = 1;
activateDirectInput();
$mvFreeLook = 0;
@@ -580,11 +481,6 @@ function RPGClient_DisableOverlay()
$RPGClient::MvB = 0;
$RPGClient::MvL = 0;
$RPGClient::MvR = 0;
if ($RPGClient::KeyMapPushed && isObject(RPGClient_KeyMap))
{
RPGClient_KeyMap.pop();
$RPGClient::KeyMapPushed = 0;
}
if (isObject(RPGClient_Mouse))
{
RPGClient_Mouse.delete();
@@ -592,10 +488,9 @@ function RPGClient_DisableOverlay()
$RPGClient::Active = 0;
$RPGClient::OrbitInit = 0;
$RPGClient::HudPlaced = 0;
$RPGClient::MoveHijacked = 0;
$RPGClient::PlayBooted = 0;
$RPGClient::CamTickOn = 0;
RPGClient_ClearGlobalKeys();
$RPGClient::ChatOpen = 0;
RPGClient_RestoreMoveMap();
}
@@ -625,13 +520,23 @@ function RPGClient_Hud_Place()
function RPGClient_ApplyCamera(%forceSync)
{
%now = getSimTime();
%doSync = %forceSync || %now - $RPGClient::LastCamSync >= 40;
if (!%doSync || !isObject(ServerConnection))
{
return;
}
$RPGClient::LastCamSync = %now;
commandToServer('RPG_CamSync', $RPGClient::Yaw, $RPGClient::Dist, 0, 0);
if (RPGClient_NetCam())
{
return;
}
%conn = RPGClient_GetConn();
if (!isObject(%conn))
{
return;
}
%now = getSimTime();
%doSync = %forceSync || %now - $RPGClient::LastCamSync >= 40;
%body = RPGClient_BodyForCamera(%conn);
if (!isObject(%body))
{
@@ -661,11 +566,6 @@ function RPGClient_ApplyCamera(%forceSync)
%cam.setTransform(%xfm);
%cam.setOrbitMode(%body, %xfm, 0, 32, $RPGClient::Dist);
%cam.setOrbitDist($RPGClient::Dist);
if (%doSync)
{
$RPGClient::LastCamSync = %now;
commandToServer('RPG_CamSync', $RPGClient::Yaw, $RPGClient::Dist, 0, 0);
}
}
function RPGClient_ScheduleCamera()
@@ -857,6 +757,15 @@ function RPGClient_EnsurePlayGui()
return 1;
}
function clientCmdRPG_Camera(%yaw, %dist)
{
$RPGClient::Yaw = %yaw;
if (%dist > 0)
{
$RPGClient::Dist = %dist;
}
}
function clientCmdRPG_TopDown(%on, %yaw, %dist)
{
if (%on)
@@ -1271,7 +1180,6 @@ package RPGClient_Cleanup
$RPGClient::Server = 0;
$RPGClient::PlayBooted = 0;
$RPGClient::CamTickOn = 0;
RPGClient_ClearGlobalKeys();
RPGClient_RestoreMoveMap();
Parent::disconnectedCleanup(%doReconnect);
}