main.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function physicsToggleSimulation()
  23. {
  24. %isEnabled = physicsSimulationEnabled();
  25. if ( %isEnabled )
  26. {
  27. physicsStateText.setText( "Simulation is paused." );
  28. physicsStopSimulation( "client" );
  29. physicsStopSimulation( "server" );
  30. }
  31. else
  32. {
  33. physicsStateText.setText( "Simulation is unpaused." );
  34. physicsStartSimulation( "client" );
  35. physicsStartSimulation( "server" );
  36. }
  37. }
  38. function initializePhysicsTools()
  39. {
  40. echo( " % - Initializing Physics Tools" );
  41. if ( !physicsPluginPresent() )
  42. {
  43. echo( "No physics plugin exists." );
  44. return;
  45. }
  46. globalactionmap.bindCmd( keyboard, "alt t", "physicsToggleSimulation();", "" );
  47. globalactionmap.bindCmd( keyboard, "alt r", "physicsRestoreState();", "" );
  48. new ScriptObject( PhysicsEditorPlugin )
  49. {
  50. superClass = "EditorPlugin";
  51. editorGui = EWorldEditor;
  52. };
  53. }
  54. function destroyPhysicsTools()
  55. {
  56. }
  57. function PhysicsEditorPlugin::onWorldEditorStartup( %this )
  58. {
  59. }
  60. function PhysicsToolsMenu::onMenuSelect(%this)
  61. {
  62. %isEnabled = physicsSimulationEnabled();
  63. %itemText = !%isEnabled ? "Start Simulation" : "Pause Simulation";
  64. %itemCommand = !%isEnabled ? "physicsStartSimulation( \"client\" );physicsStartSimulation( \"server\" );" : "physicsStopSimulation( \"client\" );physicsStopSimulation( \"server\" );";
  65. %this.setItemName( 0, %itemText );
  66. %this.setItemCommand( 0, %itemCommand );
  67. }
  68. function PhysicsEditorPlugin::onEditorWake( %this )
  69. {
  70. // Disable physics when entering
  71. // the editor. Will be re-enabled
  72. // when the editor is closed.
  73. physicsStopSimulation( "client" );
  74. physicsStopSimulation( "server" );
  75. physicsRestoreState();
  76. }
  77. function PhysicsEditorPlugin::onEditorSleep( %this )
  78. {
  79. physicsStoreState();
  80. %currentTimeScale = physicsGetTimeScale();
  81. if ( %currentTimeScale == 0.0 )
  82. physicsSetTimeScale( 1.0 );
  83. physicsStartSimulation( "client" );
  84. physicsStartSimulation( "server" );
  85. }