PhysicsStressTest.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "Sample.h"
  5. namespace Urho3D
  6. {
  7. class Node;
  8. class Scene;
  9. }
  10. /// Physics stress test example.
  11. /// This sample demonstrates:
  12. /// - Physics and rendering performance with a high (1000) moving object count
  13. /// - Using triangle meshes for collision
  14. /// - Optimizing physics simulation by leaving out collision event signaling
  15. class PhysicsStressTest : public Sample
  16. {
  17. URHO3D_OBJECT(PhysicsStressTest, Sample);
  18. public:
  19. /// Construct.
  20. explicit PhysicsStressTest(Context* context);
  21. /// Setup after engine initialization and before running the main loop.
  22. void Start() override;
  23. protected:
  24. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  25. String GetScreenJoystickPatchString() const override { return
  26. "<patch>"
  27. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
  28. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Spawn</replace>"
  29. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
  30. " <element type=\"Text\">"
  31. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />"
  32. " <attribute name=\"Text\" value=\"LEFT\" />"
  33. " </element>"
  34. " </add>"
  35. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
  36. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Debug</replace>"
  37. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
  38. " <element type=\"Text\">"
  39. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  40. " <attribute name=\"Text\" value=\"SPACE\" />"
  41. " </element>"
  42. " </add>"
  43. "</patch>";
  44. }
  45. private:
  46. /// Construct the scene content.
  47. void CreateScene();
  48. /// Construct an instruction text to the UI.
  49. void CreateInstructions();
  50. /// Set up a viewport for displaying the scene.
  51. void SetupViewport();
  52. /// Subscribe to application-wide logic update and post-render update events.
  53. void SubscribeToEvents();
  54. /// Read input and moves the camera.
  55. void MoveCamera(float timeStep);
  56. /// Spawn a physics object from the camera position.
  57. void SpawnObject();
  58. /// Handle the logic update event.
  59. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  60. /// Handle the post-render update event.
  61. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
  62. /// Flag for drawing debug geometry.
  63. bool drawDebug_;
  64. };