PhysicsStressTest.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "Sample.h"
  24. namespace Urho3D
  25. {
  26. class Node;
  27. class Scene;
  28. }
  29. /// Physics stress test example.
  30. /// This sample demonstrates:
  31. /// - Physics and rendering performance with a high (1000) moving object count
  32. /// - Using triangle meshes for collision
  33. /// - Optimizing physics simulation by leaving out collision event signaling
  34. class PhysicsStressTest : public Sample
  35. {
  36. URHO3D_OBJECT(PhysicsStressTest, Sample);
  37. public:
  38. /// Construct.
  39. explicit PhysicsStressTest(Context* context);
  40. /// Setup after engine initialization and before running the main loop.
  41. void Start() override;
  42. protected:
  43. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  44. String GetScreenJoystickPatchString() const override { return
  45. "<patch>"
  46. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
  47. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Spawn</replace>"
  48. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
  49. " <element type=\"Text\">"
  50. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />"
  51. " <attribute name=\"Text\" value=\"LEFT\" />"
  52. " </element>"
  53. " </add>"
  54. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
  55. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Debug</replace>"
  56. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
  57. " <element type=\"Text\">"
  58. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  59. " <attribute name=\"Text\" value=\"SPACE\" />"
  60. " </element>"
  61. " </add>"
  62. "</patch>";
  63. }
  64. private:
  65. /// Construct the scene content.
  66. void CreateScene();
  67. /// Construct an instruction text to the UI.
  68. void CreateInstructions();
  69. /// Set up a viewport for displaying the scene.
  70. void SetupViewport();
  71. /// Subscribe to application-wide logic update and post-render update events.
  72. void SubscribeToEvents();
  73. /// Read input and moves the camera.
  74. void MoveCamera(float timeStep);
  75. /// Spawn a physics object from the camera position.
  76. void SpawnObject();
  77. /// Handle the logic update event.
  78. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  79. /// Handle the post-render update event.
  80. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
  81. /// Flag for drawing debug geometry.
  82. bool drawDebug_;
  83. };