The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.7KB

  1. /*
  2. * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. * Permission is granted to anyone to use this software for any purpose,
  8. * including commercial applications, and to alter it and redistribute it
  9. * freely, subject to the following restrictions:
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software
  12. * in a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. * 2. Altered source versions must be plainly marked as such, and must not be
  15. * misrepresented as being the original software.
  16. * 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef TILES_H
  19. #define TILES_H
  20. /// This stress tests the dynamic tree broad-phase. This also shows that tile
  21. /// based collision is _not_ smooth due to Box2D not knowing about adjacency.
  22. class Tiles : public Test
  23. {
  24. public:
  25. enum
  26. {
  27. e_count = 20
  28. };
  29. Tiles()
  30. {
  31. m_fixtureCount = 0;
  32. b2Timer timer;
  33. {
  34. float32 a = 0.5f;
  35. b2BodyDef bd;
  36. bd.position.y = -a;
  37. b2Body* ground = m_world->CreateBody(&bd);
  38. #if 1
  39. int32 N = 200;
  40. int32 M = 10;
  41. b2Vec2 position;
  42. position.y = 0.0f;
  43. for (int32 j = 0; j < M; ++j)
  44. {
  45. position.x = -N * a;
  46. for (int32 i = 0; i < N; ++i)
  47. {
  48. b2PolygonShape shape;
  49. shape.SetAsBox(a, a, position, 0.0f);
  50. ground->CreateFixture(&shape, 0.0f);
  51. ++m_fixtureCount;
  52. position.x += 2.0f * a;
  53. }
  54. position.y -= 2.0f * a;
  55. }
  56. #else
  57. int32 N = 200;
  58. int32 M = 10;
  59. b2Vec2 position;
  60. position.x = -N * a;
  61. for (int32 i = 0; i < N; ++i)
  62. {
  63. position.y = 0.0f;
  64. for (int32 j = 0; j < M; ++j)
  65. {
  66. b2PolygonShape shape;
  67. shape.SetAsBox(a, a, position, 0.0f);
  68. ground->CreateFixture(&shape, 0.0f);
  69. position.y -= 2.0f * a;
  70. }
  71. position.x += 2.0f * a;
  72. }
  73. #endif
  74. }
  75. {
  76. float32 a = 0.5f;
  77. b2PolygonShape shape;
  78. shape.SetAsBox(a, a);
  79. b2Vec2 x(-7.0f, 0.75f);
  80. b2Vec2 y;
  81. b2Vec2 deltaX(0.5625f, 1.25f);
  82. b2Vec2 deltaY(1.125f, 0.0f);
  83. for (int32 i = 0; i < e_count; ++i)
  84. {
  85. y = x;
  86. for (int32 j = i; j < e_count; ++j)
  87. {
  88. b2BodyDef bd;
  89. bd.type = b2_dynamicBody;
  90. bd.position = y;
  91. //if (i == 0 && j == 0)
  92. //{
  93. // bd.allowSleep = false;
  94. //}
  95. //else
  96. //{
  97. // bd.allowSleep = true;
  98. //}
  99. b2Body* body = m_world->CreateBody(&bd);
  100. body->CreateFixture(&shape, 5.0f);
  101. ++m_fixtureCount;
  102. y += deltaY;
  103. }
  104. x += deltaX;
  105. }
  106. }
  107. m_createTime = timer.GetMilliseconds();
  108. }
  109. void Step(Settings* settings)
  110. {
  111. const b2ContactManager& cm = m_world->GetContactManager();
  112. int32 height = cm.m_broadPhase.GetTreeHeight();
  113. int32 leafCount = cm.m_broadPhase.GetProxyCount();
  114. int32 minimumNodeCount = 2 * leafCount - 1;
  115. float32 minimumHeight = ceilf(logf(float32(minimumNodeCount)) / logf(2.0f));
  116. m_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d, min = %d", height, int32(minimumHeight));
  117. m_textLine += 15;
  118. Test::Step(settings);
  119. m_debugDraw.DrawString(5, m_textLine, "create time = %6.2f ms, fixture count = %d",
  120. m_createTime, m_fixtureCount);
  121. m_textLine += 15;
  122. //b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree;
  123. //if (m_stepCount == 400)
  124. //{
  125. // tree->RebuildBottomUp();
  126. //}
  127. }
  128. static Test* Create()
  129. {
  130. return new Tiles;
  131. }
  132. int32 m_fixtureCount;
  133. float32 m_createTime;
  134. };
  135. #endif