123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- if ( isObject( moveMap ) )
- moveMap.delete();
- new ActionMap(moveMap);
- //------------------------------------------------------------------------------
- // Non-remapable binds
- //------------------------------------------------------------------------------
- function escapeFromGame()
- {
- if ( $Server::ServerType $= "SinglePlayer" )
- MessageBoxYesNo( "Exit", "Exit from this Mission?", "disconnect();", "");
- else
- MessageBoxYesNo( "Disconnect", "Disconnect from the server?", "disconnect();", "");
- }
- moveMap.bindCmd(keyboard, "escape", "", "handleEscape();");
- //------------------------------------------------------------------------------
- // Movement Keys
- //------------------------------------------------------------------------------
- $movementSpeed = 1; // m/s
- function setSpeed(%speed)
- {
- if(%speed)
- $movementSpeed = %speed;
- }
- function moveleft(%val)
- {
- $mvLeftAction = %val * $movementSpeed;
- }
- function moveright(%val)
- {
- $mvRightAction = %val * $movementSpeed;
- }
- function moveforward(%val)
- {
- $mvForwardAction = %val * $movementSpeed;
- }
- function movebackward(%val)
- {
- $mvBackwardAction = %val * $movementSpeed;
- }
- function moveup(%val)
- {
- %object = ServerConnection.getControlObject();
-
- if(%object.isInNamespaceHierarchy("Camera"))
- $mvUpAction = %val * $movementSpeed;
- }
- function movedown(%val)
- {
- %object = ServerConnection.getControlObject();
-
- if(%object.isInNamespaceHierarchy("Camera"))
- $mvDownAction = %val * $movementSpeed;
- }
- function turnLeft( %val )
- {
- $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
- }
- function turnRight( %val )
- {
- $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
- }
- function panUp( %val )
- {
- $mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
- }
- function panDown( %val )
- {
- $mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
- }
- function getMouseAdjustAmount(%val)
- {
- // based on a default camera FOV of 90'
- return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
- }
- function getGamepadAdjustAmount(%val)
- {
- // based on a default camera FOV of 90'
- return(%val * ($cameraFov / 90) * 0.01) * 10.0;
- }
- function yaw(%val)
- {
- %yawAdj = getMouseAdjustAmount(%val);
- if(ServerConnection.isControlObjectRotDampedCamera())
- {
- // Clamp and scale
- %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
- %yawAdj *= 0.5;
- }
- $mvYaw += %yawAdj;
- }
- function pitch(%val)
- {
- %pitchAdj = getMouseAdjustAmount(%val);
- if(ServerConnection.isControlObjectRotDampedCamera())
- {
- // Clamp and scale
- %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
- %pitchAdj *= 0.5;
- }
- $mvPitch += %pitchAdj;
- }
- function jump(%val)
- {
- $mvTriggerCount2++;
- }
- function gamePadMoveX( %val )
- {
- $mvXAxis_L = %val;
- }
- function gamePadMoveY( %val )
- {
- $mvYAxis_L = %val;
- }
- function gamepadYaw(%val)
- {
- %yawAdj = getGamepadAdjustAmount(%val);
- if(ServerConnection.isControlObjectRotDampedCamera())
- {
- // Clamp and scale
- %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
- %yawAdj *= 0.5;
- }
- if(%yawAdj > 0)
- {
- $mvYawLeftSpeed = %yawAdj;
- $mvYawRightSpeed = 0;
- }
- else
- {
- $mvYawLeftSpeed = 0;
- $mvYawRightSpeed = -%yawAdj;
- }
- }
- function gamepadPitch(%val)
- {
- %pitchAdj = getGamepadAdjustAmount(%val);
- if(ServerConnection.isControlObjectRotDampedCamera())
- {
- // Clamp and scale
- %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
- %pitchAdj *= 0.5;
- }
- if(%pitchAdj > 0)
- {
- $mvPitchDownSpeed = %pitchAdj;
- $mvPitchUpSpeed = 0;
- }
- else
- {
- $mvPitchDownSpeed = 0;
- $mvPitchUpSpeed = -%pitchAdj;
- }
- }
- moveMap.bind( keyboard, a, moveleft );
- moveMap.bind( keyboard, d, moveright );
- moveMap.bind( keyboard, left, moveleft );
- moveMap.bind( keyboard, right, moveright );
- moveMap.bind( keyboard, w, moveforward );
- moveMap.bind( keyboard, s, movebackward );
- moveMap.bind( keyboard, up, moveforward );
- moveMap.bind( keyboard, down, movebackward );
- moveMap.bind( keyboard, e, moveup );
- moveMap.bind( keyboard, c, movedown );
- moveMap.bind( keyboard, space, jump );
- moveMap.bind( mouse, xaxis, yaw );
- moveMap.bind( mouse, yaxis, pitch );
- moveMap.bind( gamepad, thumbrx, "D", "-0.23 0.23", gamepadYaw );
- moveMap.bind( gamepad, thumbry, "D", "-0.23 0.23", gamepadPitch );
- moveMap.bind( gamepad, thumblx, "D", "-0.23 0.23", gamePadMoveX );
- moveMap.bind( gamepad, thumbly, "D", "-0.23 0.23", gamePadMoveY );
- moveMap.bind( gamepad, btn_a, jump );
- moveMap.bindCmd( gamepad, btn_back, "disconnect();", "" );
- moveMap.bindCmd(gamepad, dpadl, "toggleLightColorViz();", "");
- moveMap.bindCmd(gamepad, dpadu, "toggleDepthViz();", "");
- moveMap.bindCmd(gamepad, dpadd, "toggleNormalsViz();", "");
- moveMap.bindCmd(gamepad, dpadr, "toggleLightSpecularViz();", "");
- //------------------------------------------------------------------------------
- // Mouse Trigger
- //------------------------------------------------------------------------------
- function mouseFire(%val)
- {
- $mvTriggerCount0++;
- }
- function altTrigger(%val)
- {
- $mvTriggerCount1++;
- }
- moveMap.bind( mouse, button0, mouseFire );
- moveMap.bind( mouse, button1, altTrigger );
- //------------------------------------------------------------------------------
- // Gamepad Trigger
- //------------------------------------------------------------------------------
- function gamepadFire(%val)
- {
- if(%val > 0.1 && !$gamepadFireTriggered)
- {
- $gamepadFireTriggered = true;
- $mvTriggerCount0++;
- }
- else if(%val <= 0.1 && $gamepadFireTriggered)
- {
- $gamepadFireTriggered = false;
- $mvTriggerCount0++;
- }
- }
- function gamepadAltTrigger(%val)
- {
- if(%val > 0.1 && !$gamepadAltTriggerTriggered)
- {
- $gamepadAltTriggerTriggered = true;
- $mvTriggerCount1++;
- }
- else if(%val <= 0.1 && $gamepadAltTriggerTriggered)
- {
- $gamepadAltTriggerTriggered = false;
- $mvTriggerCount1++;
- }
- }
- moveMap.bind(gamepad, triggerr, gamepadFire);
- moveMap.bind(gamepad, triggerl, gamepadAltTrigger);
- //------------------------------------------------------------------------------
- // Zoom and FOV functions
- //------------------------------------------------------------------------------
- if($Player::CurrentFOV $= "")
- $Player::CurrentFOV = $pref::Player::DefaultFOV / 2;
- // toggleZoomFOV() works by dividing the CurrentFOV by 2. Each time that this
- // toggle is hit it simply divides the CurrentFOV by 2 once again. If the
- // FOV is reduced below a certain threshold then it resets to equal half of the
- // DefaultFOV value. This gives us 4 zoom levels to cycle through.
- function toggleZoomFOV()
- {
- $Player::CurrentFOV = $Player::CurrentFOV / 2;
- if($Player::CurrentFOV < 5)
- resetCurrentFOV();
- if(ServerConnection.zoomed)
- setFOV($Player::CurrentFOV);
- else
- {
- setFov(ServerConnection.getControlCameraDefaultFov());
- }
- }
- function resetCurrentFOV()
- {
- $Player::CurrentFOV = ServerConnection.getControlCameraDefaultFov() / 2;
- }
- function turnOffZoom()
- {
- ServerConnection.zoomed = false;
- setFov(ServerConnection.getControlCameraDefaultFov());
- // Rather than just disable the DOF effect, we want to set it to the level's
- // preset values.
- //DOFPostEffect.disable();
- ppOptionsUpdateDOFSettings();
- }
- function setZoomFOV(%val)
- {
- if(%val)
- toggleZoomFOV();
- }
- function toggleZoom(%val)
- {
- if (%val)
- {
- ServerConnection.zoomed = true;
- setFov($Player::CurrentFOV);
- DOFPostEffect.setAutoFocus( true );
- DOFPostEffect.setFocusParams( 0.5, 0.5, 50, 500, -5, 5 );
- DOFPostEffect.enable();
- }
- else
- {
- turnOffZoom();
- }
- }
- moveMap.bind(keyboard, f, setZoomFOV);
- moveMap.bind(keyboard, r, toggleZoom);
- moveMap.bind( gamepad, btn_b, toggleZoom );
- //------------------------------------------------------------------------------
- // Camera & View functions
- //------------------------------------------------------------------------------
- function toggleFreeLook( %val )
- {
- if ( %val )
- $mvFreeLook = true;
- else
- $mvFreeLook = false;
- }
- function toggleFirstPerson(%val)
- {
- if (%val)
- {
- ServerConnection.setFirstPerson(!ServerConnection.isFirstPerson());
- }
- }
- function toggleCamera(%val)
- {
- if (%val)
- commandToServer('ToggleCamera');
- }
- moveMap.bind( keyboard, z, toggleFreeLook );
- moveMap.bind(keyboard, tab, toggleFirstPerson );
- moveMap.bind(keyboard, "alt c", toggleCamera);
- moveMap.bind( gamepad, btn_back, toggleCamera );
- //------------------------------------------------------------------------------
- // Demo recording functions
- //------------------------------------------------------------------------------
- function startRecordingDemo( %val )
- {
- if ( %val )
- startDemoRecord();
- }
- function stopRecordingDemo( %val )
- {
- if ( %val )
- stopDemoRecord();
- }
- moveMap.bind( keyboard, F3, startRecordingDemo );
- moveMap.bind( keyboard, F4, stopRecordingDemo );
- //------------------------------------------------------------------------------
- // Helper Functions
- //------------------------------------------------------------------------------
- function dropCameraAtPlayer(%val)
- {
- if (%val)
- commandToServer('dropCameraAtPlayer');
- }
- function dropPlayerAtCamera(%val)
- {
- if (%val)
- commandToServer('DropPlayerAtCamera');
- }
- moveMap.bind(keyboard, "F8", dropCameraAtPlayer);
- moveMap.bind(keyboard, "F7", dropPlayerAtCamera);
- function bringUpOptions(%val)
- {
- if (%val)
- Canvas.pushDialog(OptionsDlg);
- }
- GlobalActionMap.bind(keyboard, "ctrl o", bringUpOptions);
- //------------------------------------------------------------------------------
- // Debugging Functions
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- //
- // Start profiler by pressing ctrl f3
- // ctrl f3 - starts profile that will dump to console and file
- //
- function doProfile(%val)
- {
- if (%val)
- {
- // key down -- start profile
- echo("Starting profile session...");
- profilerReset();
- profilerEnable(true);
- }
- else
- {
- // key up -- finish off profile
- echo("Ending profile session...");
- profilerDumpToFile("profilerDumpToFile" @ getSimTime() @ ".txt");
- profilerEnable(false);
- }
- }
- GlobalActionMap.bind(keyboard, "ctrl F3", doProfile);
- //------------------------------------------------------------------------------
- // Misc.
- //------------------------------------------------------------------------------
- GlobalActionMap.bind(keyboard, "tilde", toggleConsole);
- GlobalActionMap.bindCmd(keyboard, "alt k", "cls();","");
- GlobalActionMap.bindCmd(keyboard, "alt enter", "", "Canvas.attemptFullscreenToggle();");
|