inputCommands.tscript 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. function escapeFromGame()
  2. {
  3. disconnect();
  4. }
  5. function showPlayerList(%val)
  6. {
  7. if (%val)
  8. PlayerListGui.toggle();
  9. }
  10. function hideHUDs(%val)
  11. {
  12. if (%val)
  13. HudlessPlayGui.toggle();
  14. }
  15. function doScreenShotHudless(%val)
  16. {
  17. if(%val)
  18. {
  19. canvas.setContent(HudlessPlayGui);
  20. //doScreenshot(%val);
  21. schedule(10, 0, "doScreenShot", %val);
  22. }
  23. else
  24. {
  25. %playGUIName = ProjectSettings.value("UI/playGUIName");
  26. Canvas.setContent(%playGUIName);
  27. }
  28. }
  29. $movementSpeed = 1; // m/s
  30. function setSpeed(%speed)
  31. {
  32. if(%speed)
  33. $movementSpeed = %speed;
  34. }
  35. function moveleft(%val)
  36. {
  37. $mvLeftAction = %val * $movementSpeed;
  38. }
  39. function moveright(%val)
  40. {
  41. $mvRightAction = %val * $movementSpeed;
  42. }
  43. function moveforward(%val)
  44. {
  45. $mvForwardAction = %val * $movementSpeed;
  46. }
  47. function movebackward(%val)
  48. {
  49. $mvBackwardAction = %val * $movementSpeed;
  50. }
  51. function moveup(%val)
  52. {
  53. %object = ServerConnection.getControlObject();
  54. if(%object.isInNamespaceHierarchy("Camera"))
  55. $mvUpAction = %val * $movementSpeed;
  56. }
  57. function movedown(%val)
  58. {
  59. %object = ServerConnection.getControlObject();
  60. if(%object.isInNamespaceHierarchy("Camera"))
  61. $mvDownAction = %val * $movementSpeed;
  62. }
  63. function turnLeft( %val )
  64. {
  65. $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  66. }
  67. function turnRight( %val )
  68. {
  69. $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  70. }
  71. function panUp( %val )
  72. {
  73. $mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  74. }
  75. function panDown( %val )
  76. {
  77. $mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  78. }
  79. function getMouseAdjustAmount(%val)
  80. {
  81. // based on a default camera FOV of 90'
  82. return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
  83. }
  84. function getGamepadAdjustAmount(%val)
  85. {
  86. // based on a default camera FOV of 90'
  87. return(%val * ($cameraFov / 90) * 0.01) * 10.0;
  88. }
  89. function yaw(%val)
  90. {
  91. %yawAdj = getMouseAdjustAmount(%val);
  92. if(ServerConnection.isControlObjectRotDampedCamera())
  93. {
  94. // Clamp and scale
  95. %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
  96. %yawAdj *= 0.5;
  97. }
  98. $mvYaw += %yawAdj;
  99. }
  100. function pitch(%val)
  101. {
  102. %pitchAdj = getMouseAdjustAmount(%val);
  103. if(ServerConnection.isControlObjectRotDampedCamera())
  104. {
  105. // Clamp and scale
  106. %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
  107. %pitchAdj *= 0.5;
  108. }
  109. $mvPitch += %pitchAdj;
  110. }
  111. function jump(%val)
  112. {
  113. $mvTriggerCount2++;
  114. }
  115. function gamePadMoveX( %val )
  116. {
  117. if(%val > 0)
  118. {
  119. $mvRightAction = %val * $movementSpeed;
  120. $mvLeftAction = 0;
  121. }
  122. else
  123. {
  124. $mvRightAction = 0;
  125. $mvLeftAction = -%val * $movementSpeed;
  126. }
  127. }
  128. function gamePadMoveY( %val )
  129. {
  130. if(%val > 0)
  131. {
  132. $mvForwardAction = %val * $movementSpeed;
  133. $mvBackwardAction = 0;
  134. }
  135. else
  136. {
  137. $mvForwardAction = 0;
  138. $mvBackwardAction = -%val * $movementSpeed;
  139. }
  140. }
  141. function gamepadYaw(%val)
  142. {
  143. %yawAdj = getGamepadAdjustAmount(%val);
  144. if(ServerConnection.isControlObjectRotDampedCamera())
  145. {
  146. // Clamp and scale
  147. %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
  148. %yawAdj *= 0.5;
  149. }
  150. if(%yawAdj > 0)
  151. {
  152. $mvYawLeftSpeed = %yawAdj;
  153. $mvYawRightSpeed = 0;
  154. }
  155. else
  156. {
  157. $mvYawLeftSpeed = 0;
  158. $mvYawRightSpeed = -%yawAdj;
  159. }
  160. }
  161. function gamepadPitch(%val)
  162. {
  163. %pitchAdj = getGamepadAdjustAmount(%val);
  164. if(ServerConnection.isControlObjectRotDampedCamera())
  165. {
  166. // Clamp and scale
  167. %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
  168. %pitchAdj *= 0.5;
  169. }
  170. if(%pitchAdj > 0)
  171. {
  172. $mvPitchDownSpeed = %pitchAdj;
  173. $mvPitchUpSpeed = 0;
  174. }
  175. else
  176. {
  177. $mvPitchDownSpeed = 0;
  178. $mvPitchUpSpeed = -%pitchAdj;
  179. }
  180. }
  181. function startRecordingDemo( %val )
  182. {
  183. if ( %val )
  184. startDemoRecord();
  185. }
  186. function stopRecordingDemo( %val )
  187. {
  188. if ( %val )
  189. stopDemoRecord();
  190. }
  191. //------------------------------------------------------------------------------
  192. // Debugging Functions
  193. //------------------------------------------------------------------------------
  194. function showMetrics(%val)
  195. {
  196. if(%val)
  197. {
  198. if(!Canvas.isMember(FrameOverlayGui))
  199. metrics("fps gfx shadow sfx terrain groundcover forest net");
  200. else
  201. metrics("");
  202. }
  203. }
  204. GlobalActionMap.bind(keyboard, "ctrl F2", showMetrics);
  205. //------------------------------------------------------------------------------
  206. //
  207. // Start profiler by pressing ctrl f3
  208. // ctrl f3 - starts profile that will dump to console and file
  209. //
  210. function doProfile(%val)
  211. {
  212. if (%val)
  213. {
  214. // key down -- start profile
  215. echo("Starting profile session...");
  216. profilerReset();
  217. profilerEnable(true);
  218. }
  219. else
  220. {
  221. // key up -- finish off profile
  222. echo("Ending profile session...");
  223. profilerDumpToFile("profilerDumpToFile" @ getSimTime() @ ".txt");
  224. profilerEnable(false);
  225. }
  226. }