diff --git a/extensions/physics-nodes/CCPhysicsDebugNodeBox2D.cpp b/extensions/physics-nodes/CCPhysicsDebugNodeBox2D.cpp index bb2e638c14..64fac8a70d 100644 --- a/extensions/physics-nodes/CCPhysicsDebugNodeBox2D.cpp +++ b/extensions/physics-nodes/CCPhysicsDebugNodeBox2D.cpp @@ -27,8 +27,6 @@ USING_NS_CC; -// 'Interfaces' to adxe -cocos2d::DrawNode* drawBox2D; #if defined(CC_PLATFORM_PC) extern cocos2d::Label* labelDebugDraw; @@ -37,22 +35,9 @@ extern cocos2d::Label* labelDebugDraw; #define BUFFER_OFFSET(x) ((const void*) (x)) - -// -//// halx99: since adxe init scene default camera at 'initWithXXX' function, only change design size at scene -//// construct is ok see also: https://github.com/adxeproject/adxe/commit/581a7921554c09746616759d5a5ca6ce9d3eaa22 -//auto director = Director::getInstance(); -//auto glview = director->getOpenGLView(); -//Size designSize(960 * 0.85, 640 * 0.85); -//glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER); -cocos2d::Vec2 debugNodeOffset = { 260, 70 }; -//float mRatio = 10.0f; - DebugDraw::DebugDraw() { - mRatio = 10; drawBP = DrawNode::create(); - drawBox2D = drawBP; } DebugDraw::~DebugDraw() @@ -61,10 +46,21 @@ DebugDraw::~DebugDraw() void DebugDraw::initShader( void ) { - //mShaderProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR); - //mColorLocation = glGetUniformLocation( mShaderProgram->getProgram(), "u_color"); + // initShader is unsupported } +cocos2d::DrawNode* DebugDraw::GetDrawNode() +{ + return drawBP; +} + +void DebugDraw::SetDrawNode(cocos2d::DrawNode* drawNode) +{ + CCASSERT(!drawBP, "drawBP is not NULL"); + drawBP = drawNode; +} + + void DebugDraw::DrawPolygon(const b2Vec2* verts, int vertexCount, const b2Color& color) { Vec2* vec = new (std::nothrow) Vec2[vertexCount]; @@ -117,9 +113,7 @@ void DebugDraw::DrawPoint(const b2Vec2& p, float size, const b2Color& color) { drawBP->drawPoint(Vec2(p.x * mRatio, p.y * mRatio) + debugNodeOffset, size, Color4F(color.r, color.g, color.b, color.a)); } -static char PrintStringBuffer[1024 * 8]; -static char* PrintStringCursor; -char const* MessageString = NULL; + void DebugDraw::DrawString(int x, int y, const char* string, ...) { #if defined(CC_PLATFORM_PC) @@ -129,7 +123,6 @@ void DebugDraw::DrawString(int x, int y, const char* string, ...) #endif } - void DebugDraw::DrawString(const b2Vec2& pw, const char* string, ...) { #if defined(CC_PLATFORM_PC) @@ -159,4 +152,5 @@ void DebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color) void DebugDraw::Flush() { + // Flush is unsupported } \ No newline at end of file diff --git a/extensions/physics-nodes/CCPhysicsDebugNodeBox2D.h b/extensions/physics-nodes/CCPhysicsDebugNodeBox2D.h index 51ecf8dc42..7c0af421bd 100644 --- a/extensions/physics-nodes/CCPhysicsDebugNodeBox2D.h +++ b/extensions/physics-nodes/CCPhysicsDebugNodeBox2D.h @@ -31,90 +31,8 @@ #include "cocos2d.h" -struct b2AABB; +//struct b2AABB; -extern cocos2d::DrawNode* drawBox2D; - -/// Test settings. Some can be controlled in the GUI. -struct Settings -{ - Settings() - { - viewCenter.Set(0.0f, 0.0f); - hz = 60.0f; - velocityIterations = 8; - positionIterations = 3; - drawShapes = 1; - drawJoints = 1; - drawAABBs = 0; - drawContactPoints = 0; - drawContactNormals = 0; - drawContactImpulse = 0; - drawFrictionImpulse = 0; - drawCOMs = 0; - drawStats = 0; - drawProfile = 0; - enableWarmStarting = 1; - enableContinuous = 1; - enableSubStepping = 0; - enableSleep = 1; - pause = 0; - singleStep = 0; - } - - b2Vec2 viewCenter; - float hz; - int32 velocityIterations; - int32 positionIterations; - int32 drawShapes; - int32 drawJoints; - int32 drawAABBs; - int32 drawContactPoints; - int32 drawContactNormals; - int32 drawContactImpulse; - int32 drawFrictionImpulse; - int32 drawCOMs; - int32 drawStats; - int32 drawProfile; - int32 enableWarmStarting; - int32 enableContinuous; - int32 enableSubStepping; - int32 enableSleep; - int32 pause; - int32 singleStep; -}; - -struct ContactPoint -{ - b2Fixture* fixtureA; - b2Fixture* fixtureB; - b2Vec2 normal; - b2Vec2 position; - b2PointState state; - float normalImpulse; - float tangentImpulse; - float separation; -}; - -//struct Camera -//{ -// Camera() -// { -// m_center.Set(0.0f, 20.0f); -// m_zoom = 1.0f; -// m_width = 1280; -// m_height = 800; -// } -// -// b2Vec2 ConvertScreenToWorld(const b2Vec2& screenPoint); -// b2Vec2 ConvertWorldToScreen(const b2Vec2& worldPoint); -// void BuildProjectionMatrix(float* m, float zBias); -// -// b2Vec2 m_center; -// float m_zoom; -// int32 m_width; -// int32 m_height; -//}; // This class implements debug drawing callbacks that are invoked // inside b2World::Step. @@ -122,14 +40,9 @@ struct ContactPoint //PhysicsDebugNode : public DrawNode class CC_EX_DLL DebugDraw : public b2Draw { - - // cocos2d::g* mShaderProgram; - // GLint mColorLocation; - - cocos2d::DrawNode* drawBP = NULL; - - void initShader( void ); public: + void initShader( void ); + DebugDraw(); ~DebugDraw(); @@ -158,7 +71,13 @@ public: void Flush(); + cocos2d::DrawNode* GetDrawNode(); + void SetDrawNode(cocos2d::DrawNode* drawNode); + float mRatio; + cocos2d::DrawNode* drawBP = NULL; + + cocos2d::Vec2 debugNodeOffset = { 250, 70 }; }; #endif //__PHYSICSNODES_DEBUGNODE_BOX2D_H__ diff --git a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp index 8ef40d6d7a..acd9599b6a 100644 --- a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp +++ b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp @@ -41,11 +41,6 @@ enum { }; -//DebugDraw stuff -extern cocos2d::DrawNode* drawBox2D; -extern cocos2d::Vec2 debugNodeOffset; - - Box2DTests::Box2DTests() { ADD_TEST_CASE(Box2DTest); @@ -103,6 +98,7 @@ bool Box2DTest::init() this->addChild(menu); menu->setPosition(VisibleRect::right().x - 100, VisibleRect::top().y - 60); + drawBox2D = g_debugDraw.GetDrawNode(); addChild(drawBox2D, 100); drawBox2D->setOpacity(150); @@ -253,7 +249,7 @@ void Box2DTest::initPhysics() g_debugDraw.SetFlags(flags); g_debugDraw.mRatio = PTM_RATIO; - debugNodeOffset = { 0, 0 }; + g_debugDraw.debugNodeOffset = { 0, 0 }; world->SetDebugDraw(&g_debugDraw); } @@ -279,6 +275,8 @@ void Box2DTest::addNewSpriteAtPosition(Vec2 p) bodyDef.type = b2_dynamicBody; bodyDef.position.Set(p.x / PTM_RATIO, p.y / PTM_RATIO); + CCLOG("Add PTM_RATIO sprite %0.2f x %0.2f", p.x / PTM_RATIO, p.y / PTM_RATIO); + b2Body* body = world->CreateBody(&bodyDef); // Define another box shape for our dynamic body. diff --git a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.h b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.h index e0ba8d2cf0..61cf7a33fb 100644 --- a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.h +++ b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.h @@ -58,7 +58,7 @@ private: b2World* world; cocos2d::Texture2D* _spriteTexture; - + cocos2d::DrawNode* drawBox2D; DebugDraw g_debugDraw; bool showDebugDraw = true; } ; diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Box2DTestBed.cpp b/tests/cpp-tests/Classes/Box2DTestBed/Box2DTestBed.cpp index afa7d44059..bf56fbca22 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Box2DTestBed.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/Box2DTestBed.cpp @@ -25,28 +25,27 @@ #include "platform/CCPlatformConfig.h" #include "Box2DTestBed.h" #include "extensions/cocos-ext.h" -#include "test.h" +#include "tests/test.h" +#include "tests/settings.h" #include "ImGuiEXT/CCImGuiEXT.h" - //#include "renderer/CCRenderer.h" - - USING_NS_CC; USING_NS_CC_EXT; -static bool show_test_window = true; -static bool show_another_window = true; -static ImVec4 clear_color = ImColor(114, 144, 154); +enum { + kTagParentNode = 1, +}; + + #define kAccelerometerFrequency 30 #define FRAMES_BETWEEN_PRESSES_FOR_DOUBLE_CLICK 10 -extern int g_testCount; + +#define PTM_RATIO 32 Settings settings; -extern cocos2d::Vec2 debugNodeOffset; -extern cocos2d::Vec2 physicsDebugNodeOffset; cocos2d::Label* labelDebugDraw; enum @@ -54,8 +53,22 @@ enum kTagBox2DNode, }; -extern cocos2d::DrawNode* drawBox2D; +TestEntry g_testEntries[MAX_TESTS] = { {nullptr} }; +int g_testCount = 0; + +int RegisterTest(const char* category, const char* name, TestCreateFcn* fcn) +{ + int index = g_testCount; + if (index < MAX_TESTS) + { + g_testEntries[index] = { category, name, fcn }; + ++g_testCount; + return index; + } + + return -1; +} Box2DTestBedTests::Box2DTestBedTests() { @@ -75,19 +88,18 @@ Box2DTestBedTests::Box2DTestBedTests() Box2DTestBed::Box2DTestBed() { - debugNodeOffset = { 260, 70 }; } Box2DTestBed::~Box2DTestBed() { - _eventDispatcher->removeEventListener(_touchListener); + Layer::_eventDispatcher->removeEventListener(_touchListener); } Box2DTestBed* Box2DTestBed::createWithEntryID(int entryId) { auto layer = new (std::nothrow) Box2DTestBed(); layer->initWithEntryID(entryId); - layer->autorelease(); +// layer->autorelease(); return layer; } @@ -104,279 +116,124 @@ bool Box2DTestBed::initWithEntryID(int entryId) m_entryID = entryId; - Box2DView* view = Box2DView::viewWithEntryID(entryId); - addChild(view, 0, kTagBox2DNode); - view->setScale(15); - view->setAnchorPoint(Vec2(0, 0)); - view->setPosition(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height / 3); - auto label = Label::createWithTTF(view->title().c_str(), "fonts/arial.ttf", 28); - addChild(label, 1); + m_entry = g_testEntries + entryId; + m_test = m_entry->createFcn(); + + debugDrawNode = g_debugDraw.GetDrawNode(); + m_test->debugDrawNode = g_debugDraw.GetDrawNode(); + m_test->g_debugDrawTestBed = g_debugDraw; + + TestCase::addChild(debugDrawNode, 100); + // drawBox2D->setOpacity(150); + + // init physics + this->initPhysics(); + + + auto label = Label::createWithTTF(m_entry->name, "fonts/arial.ttf", 28); + TestCase::addChild(label, 1); label->setPosition(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height - 50); // Adds touch event listener _touchListener = EventListenerTouchOneByOne::create(); _touchListener->setSwallowTouches(true); - _touchListener->onTouchBegan = CC_CALLBACK_2(Box2DTestBed::onTouchBegan, this); _touchListener->onTouchMoved = CC_CALLBACK_2(Box2DTestBed::onTouchMoved, this); + _touchListener->onTouchEnded = CC_CALLBACK_2(Box2DTestBed::onTouchEnded, this); + TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_touchListener, -10); - _eventDispatcher->addEventListenerWithFixedPriority(_touchListener, 1); + // Adds Keyboard event listener + _keyboardListener = EventListenerKeyboard::create(); + _keyboardListener->onKeyPressed = CC_CALLBACK_2(Box2DTestBed::onKeyPressed, this); + _keyboardListener->onKeyReleased = CC_CALLBACK_2(Box2DTestBed::onKeyReleased, this); + TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_keyboardListener, -11); - - addChild(drawBox2D, 100); - // Demo messageString labelDebugDraw = Label::createWithTTF("TEST", "fonts/Marker Felt.ttf", 8.0f); labelDebugDraw->setAnchorPoint(Vec2(0, 0)); labelDebugDraw->setPosition(VisibleRect::left().x, VisibleRect::top().y - 20); labelDebugDraw->setColor(Color3B::WHITE); - addChild(labelDebugDraw, 100); + TestCase::addChild(labelDebugDraw, 100); + + TestCase::scheduleUpdate(); return true; } bool Box2DTestBed::onTouchBegan(Touch* touch, Event* event) { - return true; + auto location = touch->getLocation() - g_debugDraw.debugNodeOffset; + b2Vec2 pos = { location.x / g_debugDraw.mRatio, location.y / g_debugDraw.mRatio }; + return m_test->MouseDown(pos); } void Box2DTestBed::onTouchMoved(Touch* touch, Event* event) { - auto diff = touch->getDelta(); - auto node = getChildByTag(kTagBox2DNode); - auto currentPos = node->getPosition(); - node->setPosition(currentPos + diff); + auto location = touch->getLocation() - g_debugDraw.debugNodeOffset; + b2Vec2 pos = { location.x / g_debugDraw.mRatio, location.y / g_debugDraw.mRatio }; + + m_test->MouseMove(pos); } -void Box2DTestBed::onEnter() +void Box2DTestBed::onTouchEnded(Touch* touch, Event* event) +{ + auto location = touch->getLocation() - g_debugDraw.debugNodeOffset; + b2Vec2 pos = { location.x / g_debugDraw.mRatio, location.y / g_debugDraw.mRatio }; + + m_test->MouseUp(pos); +} + +void Box2DTestBed::onKeyPressed(EventKeyboard::KeyCode code, Event* event) +{ + log("Box2dView:onKeyPressed, keycode: %d", static_cast(code)); + m_test->Keyboard((static_cast(code) - 59)); + +} + +void Box2DTestBed::onKeyReleased(EventKeyboard::KeyCode code, Event* event) +{ + log("onKeyReleased, keycode: %d", static_cast(code)); + m_test->Keyboard((static_cast(code) - 59)); + +} + +void Box2DTestBed::onEnter() { Scene::onEnter(); ImGuiEXT::getInstance()->addFont(FileUtils::getInstance()->fullPathForFilename("fonts/arial.ttf")); ImGuiEXT::getInstance()->addRenderLoop("#im01", CC_CALLBACK_0(Box2DTestBed::onDrawImGui, this), this); } -void Box2DTestBed::onExit() +void Box2DTestBed::onExit() { Scene::onExit(); ImGuiEXT::getInstance()->removeRenderLoop("#im01"); } +void Box2DTestBed::update(float dt) +{ + // Debug draw + debugDrawNode->clear(); + m_test->Step(settings); + m_test->m_world->DebugDraw(); +} + +void Box2DTestBed::initPhysics() +{ + uint32 flags = 0; + flags += 1 * b2Draw::e_shapeBit; + flags += 1 * b2Draw::e_jointBit; + flags += 0 * b2Draw::e_aabbBit; + flags += 0 * b2Draw::e_centerOfMassBit; + g_debugDraw.SetFlags(flags); + g_debugDraw.mRatio = PTM_RATIO / 4; + m_test->m_world->SetDebugDraw(&g_debugDraw); + m_test->g_debugDraw = g_debugDraw; + g_debugDraw.debugNodeOffset = { 250, 70 }; + settings.m_hertz = 60; +} + void Box2DTestBed::onDrawImGui() { - //// 1. Show a simple window - //// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" - //{ - // static float f = 0.0f; - // ImGui::Text("Hello, world!"); - // ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - // ImGui::ColorEdit3("clear color", (float*)&clear_color); - // if (ImGui::Button("Test Window")) show_test_window ^= 1; - // if (ImGui::Button("Another Window")) show_another_window ^= 1; - // ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); - //} - - //// 2. Show another simple window, this time using an explicit Begin/End pair - //if (show_another_window) - //{ - // ImGui::SetNextWindowSize(ImVec2(170, 80), ImGuiCond_FirstUseEver); - // ImGui::Begin("Another Window", &show_another_window); - - // ImGui::Text("Hello"); - // ImGui::End(); - //} - - //// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() - //if (show_test_window) - //{ - // ImGui::ShowDemoWindow(); - //} -} - - -//------------------------------------------------------------------ -// -// Box2DView -// -//------------------------------------------------------------------ -Box2DView::Box2DView(void) -{ -} - -Box2DView* Box2DView::viewWithEntryID(int entryId) -{ - Box2DView* pView = new (std::nothrow) Box2DView(); - - pView->initWithEntryID(entryId); - pView->autorelease(); - - return pView; -} - -bool Box2DView::initWithEntryID(int entryId) -{ - m_entry = g_testEntries + entryId; - m_test = m_entry->createFcn(); - - - // Adds Touch Event Listener - auto listener = EventListenerTouchOneByOne::create(); - listener->setSwallowTouches(true); - - listener->onTouchBegan = CC_CALLBACK_2(Box2DView::onTouchBegan, this); - listener->onTouchMoved = CC_CALLBACK_2(Box2DView::onTouchMoved, this); - listener->onTouchEnded = CC_CALLBACK_2(Box2DView::onTouchEnded, this); - - - - _eventDispatcher->addEventListenerWithFixedPriority(listener, -10); - _touchListener = listener; - - auto keyboardListener = EventListenerKeyboard::create(); - keyboardListener->onKeyPressed = CC_CALLBACK_2(Box2DView::onKeyPressed, this); - keyboardListener->onKeyReleased = CC_CALLBACK_2(Box2DView::onKeyReleased, this); - _eventDispatcher->addEventListenerWithFixedPriority(keyboardListener, -11); - _keyboardListener = keyboardListener; - - return true; -} - -std::string Box2DView::title() const -{ - std::string title = std::string(m_entry->category) + std::string(":") + std::string(m_entry->name); - return title; -} - - -void Box2DView::draw(Renderer* renderer, const Mat4& transform, uint32_t flags) -{ - Layer::draw(renderer, transform, flags); - - _customCmd.init(_globalZOrder, transform, flags); - _customCmd.func = CC_CALLBACK_0(Box2DView::onDraw, this, transform, flags); - renderer->addCommand(&_customCmd); -} - -void Box2DView::onDraw(const Mat4& transform, uint32_t flags) -{ - //Director* director = Director::getInstance(); - //CCASSERT(nullptr != director, "Director is null when setting matrix stack"); - //director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - //director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); - - //drawBox2D->clear(); - //m_test->Step(&settings); - //m_test->m_world->DebugDraw(); - - //director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - - Director* director = Director::getInstance(); - CCASSERT(nullptr != director, "Director is null when setting matrix stack"); - - auto oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV); -// world->DebugDraw(); - - drawBox2D->clear(); - m_test->Step(&settings); - //m_test->m_world->DebugDraw(); - - director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV); -} - -Box2DView::~Box2DView() -{ - // Removes Touch Event Listener - _eventDispatcher->removeEventListener(_touchListener); - _eventDispatcher->removeEventListener(_keyboardListener); - delete m_test; -} - -bool Box2DView::onTouchBegan(Touch* touch, Event* event) -{ - auto touchLocation = touch->getLocation(); - - auto nodePosition = convertToNodeSpace(touchLocation); - log("Box2DView::onTouchBegan, pos: %f,%f -> %f,%f", touchLocation.x, touchLocation.y, nodePosition.x, nodePosition.y); - - m_test->MouseDown(b2Vec2(nodePosition.x, nodePosition.y)); - - return false; -} - -void Box2DView::onTouchMoved(Touch* touch, Event* event) -{ - auto touchLocation = touch->getLocation(); - auto nodePosition = convertToNodeSpace(touchLocation); - - log("Box2DView::onTouchMoved, pos: %f,%f -> %f,%f", touchLocation.x, touchLocation.y, nodePosition.x, nodePosition.y); - - m_test->MouseMove(b2Vec2(nodePosition.x, nodePosition.y)); -} - -void Box2DView::onTouchEnded(Touch* touch, Event* event) -{ - auto touchLocation = touch->getLocation(); - auto nodePosition = convertToNodeSpace(touchLocation); - - log("Box2DView::onTouchEnded, pos: %f,%f -> %f,%f", touchLocation.x, touchLocation.y, nodePosition.x, nodePosition.y); - - m_test->MouseUp(b2Vec2(nodePosition.x, nodePosition.y)); -} - -void Box2DView::onKeyPressed(EventKeyboard::KeyCode code, Event* event) -{ - log("Box2dView:onKeyPressed, keycode: %d", static_cast(code)); -// m_test->Keyboard(static_cast(code)); - m_test->Keyboard((static_cast(code) - 59)); -} - -void Box2DView::onKeyReleased(EventKeyboard::KeyCode code, Event* event) -{ - log("onKeyReleased, keycode: %d", static_cast(code)); -// m_test->KeyboardUp(static_cast(code)); - m_test->Keyboard((static_cast(code) - 59)); -} - -//void Box2DView::onEnter() -//{ -// onEnter(); -// ImGuiEXT::getInstance()->addFont(FileUtils::getInstance()->fullPathForFilename("fonts/arial.ttf")); -// ImGuiEXT::getInstance()->addRenderLoop("#im01", CC_CALLBACK_0(Box2DView::onDrawImGui, this), this->getScene()); -// -//} -//void Box2DView::onExit() -//{ -// ImGuiEXT::getInstance()->removeRenderLoop("#im01"); -// onExit(); -//} - -void Box2DView::onDrawImGui() -{ - // 1. Show a simple window - // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" - { - static float f = 0.0f; - ImGui::Text("Hello, world!"); - ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - ImGui::ColorEdit3("clear color", (float*)&clear_color); - if (ImGui::Button("Test Window")) show_test_window ^= 1; - if (ImGui::Button("Another Window")) show_another_window ^= 1; - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); - } - - // 2. Show another simple window, this time using an explicit Begin/End pair - if (show_another_window) - { - ImGui::SetNextWindowSize(ImVec2(170, 80), ImGuiCond_FirstUseEver); - ImGui::Begin("Another Window", &show_another_window); - - ImGui::Text("Hello"); - ImGui::End(); - } - - // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() - if (show_test_window) - { - ImGui::ShowDemoWindow(); - } -} + m_test->UpdateUI(); +} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Box2DTestBed.h b/tests/cpp-tests/Classes/Box2DTestBed/Box2DTestBed.h index c028d76afe..652294419e 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Box2DTestBed.h +++ b/tests/cpp-tests/Classes/Box2DTestBed/Box2DTestBed.h @@ -31,12 +31,25 @@ #include "renderer/CCCustomCommand.h" - -extern cocos2d::Vec2 physicsDebugNodeOffset; - DEFINE_TEST_SUITE(Box2DTestBedTests); -class Box2DTestBed : public TestCase + +class Test; +typedef Test* TestCreateFcn(); + +struct TestEntry +{ + const char* category; + const char* name; + TestCreateFcn* createFcn; +}; + +#define MAX_TESTS 256 +extern TestEntry g_testEntries[MAX_TESTS]; + +int RegisterTest(const char* category, const char* name, TestCreateFcn* fcn); + +class Box2DTestBed : public TestCase, cocos2d::Layer { public: static Box2DTestBed* createWithEntryID(int entryId); @@ -46,65 +59,38 @@ public: void onEnter() override; void onExit() override; + void onDrawImGui(); - //void createResetButton(); - //void reset(cocos2d::Ref* sender); + + void initPhysics(); + void update(float dt) override; + + void createResetButton(); bool initWithEntryID(int entryId); bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event); void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event); + void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event); - cocos2d::DrawNode* draw = NULL; -private: - int m_entryID; - cocos2d::EventListenerTouchOneByOne* _touchListener; -}; + void onKeyPressed(cocos2d::EventKeyboard::KeyCode code, cocos2d::Event* event) override; + void onKeyReleased(cocos2d::EventKeyboard::KeyCode code, cocos2d::Event* event) override; -struct TestEntry; -class Test; -class Box2DView : public cocos2d::Layer -{ -public: cocos2d::EventListenerTouchOneByOne* _touchListener; cocos2d::EventListenerKeyboard* _keyboardListener; + TestEntry* m_entry; Test* m_test; int m_entryID; - - void onDrawImGui(); - - - Box2DView(void); - virtual ~Box2DView(void); - - bool initWithEntryID(int entryId); - std::string title() const; - virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags) override; - - // virtual void registerWithTouchDispatcher(); - bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event)override; - void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event)override; - void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event)override; - - void onKeyPressed(cocos2d::EventKeyboard::KeyCode code, cocos2d::Event* event)override; - void onKeyReleased(cocos2d::EventKeyboard::KeyCode code, cocos2d::Event* event)override; - //virtual void accelerometer(UIAccelerometer* accelerometer, cocos2d::Acceleration* acceleration); - - static Box2DView* viewWithEntryID(int entryId); - - - -protected: - void onDraw(const cocos2d::Mat4& transform, uint32_t flags); - - cocos2d::CallbackCommand _customCmd; - - cocos2d::Mat4 _modelViewMV; - //cocos2d::extension::PhysicsDebugNode* _debugLayer; // weak ref +private: b2World* world; + cocos2d::Texture2D* _spriteTexture; + + // Debug stuff + cocos2d::DrawNode* debugDrawNode; + DebugDraw g_debugDraw; }; #endif diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Test.cpp b/tests/cpp-tests/Classes/Box2DTestBed/Test.cpp index 1f7831cd00..a6be6b0e45 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Test.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/Test.cpp @@ -16,18 +16,18 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include "test.h" +#include "tests/test.h" +#include "tests/settings.h" #include "extensions/cocos-ext.h" #include -int m_textIncrement = 10; -void DestructionListener::SayGoodbye(b2Joint* joint) +void DestructionListener::SayGoodbye(b2Joint * joint) { if (test->m_mouseJoint == joint) { - test->m_mouseJoint = nullptr; + test->m_mouseJoint = NULL; } else { @@ -40,16 +40,17 @@ Test::Test() b2Vec2 gravity; gravity.Set(0.0f, -10.0f); m_world = new b2World(gravity); - m_bomb = nullptr; + m_bomb = NULL; m_textLine = 30; - m_mouseJoint = nullptr; + m_textIncrement = 13; + m_mouseJoint = NULL; m_pointCount = 0; m_destructionListener.test = this; m_world->SetDestructionListener(&m_destructionListener); m_world->SetContactListener(this); m_world->SetDebugDraw(&g_debugDraw); - + m_bombSpawning = false; m_stepCount = 0; @@ -65,10 +66,10 @@ Test::~Test() { // By deleting the world, we delete the bomb, mouse joint, etc. delete m_world; - m_world = nullptr; + m_world = NULL; } -void Test::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) +void Test::PreSolve(b2Contact * contact, const b2Manifold * oldManifold) { const b2Manifold* manifold = contact->GetManifold(); @@ -101,10 +102,10 @@ void Test::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) } } -void Test::DrawTitle(const char *string) +void Test::DrawTitle(const char* string) { - g_debugDraw.DrawString(5, DRAW_STRING_NEW_LINE, string); - m_textLine = 2 * DRAW_STRING_NEW_LINE; + g_debugDraw.DrawString(5, 5, string); + m_textLine = int32(26.0f); } class QueryCallback : public b2QueryCallback @@ -113,10 +114,10 @@ public: QueryCallback(const b2Vec2& point) { m_point = point; - m_fixture = nullptr; + m_fixture = NULL; } - bool ReportFixture(b2Fixture* fixture) + bool ReportFixture(b2Fixture* fixture) override { b2Body* body = fixture->GetBody(); if (body->GetType() == b2_dynamicBody) @@ -139,13 +140,13 @@ public: b2Fixture* m_fixture; }; -void Test::MouseDown(const b2Vec2& p) +bool Test::MouseDown(const b2Vec2 & p) { m_mouseWorld = p; - - if (m_mouseJoint != nullptr) + + if (m_mouseJoint != NULL) { - return; + return false; } // Make a small box. @@ -161,24 +162,31 @@ void Test::MouseDown(const b2Vec2& p) if (callback.m_fixture) { + float frequencyHz = 5.0f; + float dampingRatio = 0.7f; + b2Body* body = callback.m_fixture->GetBody(); - b2MouseJointDef md; - md.bodyA = m_groundBody; - md.bodyB = body; - md.target = p; - md.maxForce = 1000.0f * body->GetMass(); - m_mouseJoint = (b2MouseJoint*)m_world->CreateJoint(&md); + b2MouseJointDef jd; + jd.bodyA = m_groundBody; + jd.bodyB = body; + jd.target = p; + jd.maxForce = 1000.0f * body->GetMass(); + b2LinearStiffness(jd.stiffness, jd.damping, frequencyHz, dampingRatio, jd.bodyA, jd.bodyB); + + m_mouseJoint = (b2MouseJoint*)m_world->CreateJoint(&jd); body->SetAwake(true); + return true; } + return false; } -void Test::SpawnBomb(const b2Vec2& worldPt) +void Test::SpawnBomb(const b2Vec2 & worldPt) { m_bombSpawnPoint = worldPt; m_bombSpawning = true; } - -void Test::CompleteBombSpawn(const b2Vec2& p) + +void Test::CompleteBombSpawn(const b2Vec2 & p) { if (m_bombSpawning == false) { @@ -188,15 +196,15 @@ void Test::CompleteBombSpawn(const b2Vec2& p) const float multiplier = 30.0f; b2Vec2 vel = m_bombSpawnPoint - p; vel *= multiplier; - LaunchBomb(m_bombSpawnPoint,vel); + LaunchBomb(m_bombSpawnPoint, vel); m_bombSpawning = false; } -void Test::ShiftMouseDown(const b2Vec2& p) +void Test::ShiftMouseDown(const b2Vec2 & p) { m_mouseWorld = p; - - if (m_mouseJoint != nullptr) + + if (m_mouseJoint != NULL) { return; } @@ -204,25 +212,24 @@ void Test::ShiftMouseDown(const b2Vec2& p) SpawnBomb(p); } -void Test::MouseUp(const b2Vec2& p) +void Test::MouseUp(const b2Vec2 & p) { - CCLOG("MouseUp p: x:%i y:%i", p.x, p.y); if (m_mouseJoint) { m_world->DestroyJoint(m_mouseJoint); - m_mouseJoint = nullptr; + m_mouseJoint = NULL; } - + if (m_bombSpawning) { CompleteBombSpawn(p); } } -void Test::MouseMove(const b2Vec2& p) +void Test::MouseMove(const b2Vec2 & p) { m_mouseWorld = p; - + if (m_mouseJoint) { m_mouseJoint->SetTarget(p); @@ -236,12 +243,12 @@ void Test::LaunchBomb() LaunchBomb(p, v); } -void Test::LaunchBomb(const b2Vec2& position, const b2Vec2& velocity) +void Test::LaunchBomb(const b2Vec2 & position, const b2Vec2 & velocity) { if (m_bomb) { m_world->DestroyBody(m_bomb); - m_bomb = nullptr; + m_bomb = NULL; } b2BodyDef bd; @@ -250,7 +257,7 @@ void Test::LaunchBomb(const b2Vec2& position, const b2Vec2& velocity) bd.bullet = true; m_bomb = m_world->CreateBody(&bd); m_bomb->SetLinearVelocity(velocity); - + b2CircleShape circle; circle.m_radius = 0.3f; @@ -258,10 +265,10 @@ void Test::LaunchBomb(const b2Vec2& position, const b2Vec2& velocity) fd.shape = &circle; fd.density = 20.0f; fd.restitution = 0.0f; - - b2Vec2 minV = position - b2Vec2(0.3f,0.3f); - b2Vec2 maxV = position + b2Vec2(0.3f,0.3f); - + + b2Vec2 minV = position - b2Vec2(0.3f, 0.3f); + b2Vec2 maxV = position + b2Vec2(0.3f, 0.3f); + b2AABB aabb; aabb.lowerBound = minV; aabb.upperBound = maxV; @@ -269,15 +276,15 @@ void Test::LaunchBomb(const b2Vec2& position, const b2Vec2& velocity) m_bomb->CreateFixture(&fd); } -void Test::Step(Settings* settings) +void Test::Step(Settings& settings) { - float timeStep = settings->hz > 0.0f ? 1.0f / settings->hz : float(0.0f); + float timeStep = settings.m_hertz > 0.0f ? 1.0f / settings.m_hertz : float(0.0f); - if (settings->pause) + if (settings.m_pause) { - if (settings->singleStep) + if (settings.m_singleStep) { - settings->singleStep = 0; + settings.m_singleStep = 0; } else { @@ -285,24 +292,24 @@ void Test::Step(Settings* settings) } g_debugDraw.DrawString(5, m_textLine, "****PAUSED****"); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; } uint32 flags = 0; - flags += settings->drawShapes * b2Draw::e_shapeBit; - flags += settings->drawJoints * b2Draw::e_jointBit; - flags += settings->drawAABBs * b2Draw::e_aabbBit; - flags += settings->drawCOMs * b2Draw::e_centerOfMassBit; + flags += settings.m_drawShapes * b2Draw::e_shapeBit; + flags += settings.m_drawJoints * b2Draw::e_jointBit; + flags += settings.m_drawAABBs * b2Draw::e_aabbBit; + flags += settings.m_drawCOMs * b2Draw::e_centerOfMassBit; g_debugDraw.SetFlags(flags); - m_world->SetAllowSleeping(settings->enableSleep > 0); - m_world->SetWarmStarting(settings->enableWarmStarting > 0); - m_world->SetContinuousPhysics(settings->enableContinuous > 0); - m_world->SetSubStepping(settings->enableSubStepping > 0); + m_world->SetAllowSleeping(settings.m_enableSleep); + m_world->SetWarmStarting(settings.m_enableWarmStarting); + m_world->SetContinuousPhysics(settings.m_enableContinuous); + m_world->SetSubStepping(settings.m_enableSubStepping); m_pointCount = 0; - m_world->Step(timeStep, settings->velocityIterations, settings->positionIterations); + m_world->Step(timeStep, settings.m_velocityIterations, settings.m_positionIterations); m_world->DebugDraw(); @@ -311,20 +318,20 @@ void Test::Step(Settings* settings) ++m_stepCount; } - if (settings->drawStats) + if (settings.m_drawStats) { int32 bodyCount = m_world->GetBodyCount(); int32 contactCount = m_world->GetContactCount(); int32 jointCount = m_world->GetJointCount(); g_debugDraw.DrawString(5, m_textLine, "bodies/contacts/joints = %d/%d/%d", bodyCount, contactCount, jointCount); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; int32 proxyCount = m_world->GetProxyCount(); int32 height = m_world->GetTreeHeight(); int32 balance = m_world->GetTreeBalance(); float quality = m_world->GetTreeQuality(); g_debugDraw.DrawString(5, m_textLine, "proxies/height/balance/quality = %d/%d/%d/%g", proxyCount, height, balance, quality); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; } // Track maximum profile times @@ -349,7 +356,7 @@ void Test::Step(Settings* settings) m_totalProfile.broadphase += p.broadphase; } - if (settings->drawProfile) + if (settings.m_drawProfile) { const b2Profile& p = m_world->GetProfile(); @@ -369,37 +376,23 @@ void Test::Step(Settings* settings) } g_debugDraw.DrawString(5, m_textLine, "step [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.step, aveProfile.step, m_maxProfile.step); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; g_debugDraw.DrawString(5, m_textLine, "collide [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.collide, aveProfile.collide, m_maxProfile.collide); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; g_debugDraw.DrawString(5, m_textLine, "solve [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solve, aveProfile.solve, m_maxProfile.solve); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; g_debugDraw.DrawString(5, m_textLine, "solve init [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveInit, aveProfile.solveInit, m_maxProfile.solveInit); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; g_debugDraw.DrawString(5, m_textLine, "solve velocity [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveVelocity, aveProfile.solveVelocity, m_maxProfile.solveVelocity); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; g_debugDraw.DrawString(5, m_textLine, "solve position [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solvePosition, aveProfile.solvePosition, m_maxProfile.solvePosition); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; g_debugDraw.DrawString(5, m_textLine, "solveTOI [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveTOI, aveProfile.solveTOI, m_maxProfile.solveTOI); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; g_debugDraw.DrawString(5, m_textLine, "broad-phase [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.broadphase, aveProfile.broadphase, m_maxProfile.broadphase); - m_textLine += DRAW_STRING_NEW_LINE; + m_textLine += m_textIncrement; } - if (m_mouseJoint) - { - b2Vec2 p1 = m_mouseJoint->GetAnchorB(); - b2Vec2 p2 = m_mouseJoint->GetTarget(); - - b2Color c; - c.Set(0.0f, 1.0f, 0.0f); - g_debugDraw.DrawPoint(p1, 4.0f, c); - g_debugDraw.DrawPoint(p2, 4.0f, c); - - c.Set(0.8f, 0.8f, 0.8f); - g_debugDraw.DrawSegment(p1, p2, c); - } - if (m_bombSpawning) { b2Color c; @@ -410,7 +403,7 @@ void Test::Step(Settings* settings) g_debugDraw.DrawSegment(m_mouseWorld, m_bombSpawnPoint, c); } - if (settings->drawContactPoints) + if (settings.m_drawContactPoints) { const float k_impulseScale = 0.1f; const float k_axisScale = 0.3f; @@ -430,20 +423,20 @@ void Test::Step(Settings* settings) g_debugDraw.DrawPoint(point->position, 5.0f, b2Color(0.3f, 0.3f, 0.95f)); } - if (settings->drawContactNormals == 1) + if (settings.m_drawContactNormals == 1) { b2Vec2 p1 = point->position; b2Vec2 p2 = p1 + k_axisScale * point->normal; g_debugDraw.DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.9f)); } - else if (settings->drawContactImpulse == 1) + else if (settings.m_drawContactImpulse == 1) { b2Vec2 p1 = point->position; b2Vec2 p2 = p1 + k_impulseScale * point->normalImpulse * point->normal; g_debugDraw.DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } - if (settings->drawFrictionImpulse == 1) + if (settings.m_drawFrictionImpulse == 1) { b2Vec2 tangent = b2Cross(point->normal, 1.0f); b2Vec2 p1 = point->position; @@ -454,25 +447,7 @@ void Test::Step(Settings* settings) } } -void Test::ShiftOrigin(const b2Vec2& newOrigin) +void Test::ShiftOrigin(const b2Vec2 & newOrigin) { m_world->ShiftOrigin(newOrigin); -} - - - -TestEntry g_testEntries[MAX_TESTS] = { {nullptr} }; -int g_testCount = 0; - -int RegisterTest(const char* category, const char* name, TestCreateFcn* fcn) -{ - int index = g_testCount; - if (index < MAX_TESTS) - { - g_testEntries[index] = { category, name, fcn }; - ++g_testCount; - return index; - } - - return -1; -} +} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/Box2DTestBed/settings.h b/tests/cpp-tests/Classes/Box2DTestBed/settings.h new file mode 100644 index 0000000000..65045da447 --- /dev/null +++ b/tests/cpp-tests/Classes/Box2DTestBed/settings.h @@ -0,0 +1,83 @@ +// MIT License + +// Copyright (c) 2019 Erin Catto + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +struct Settings +{ + Settings() + { + Reset(); + } + + void Reset() + { + m_testIndex = 0; + m_windowWidth = 1600; + m_windowHeight = 900; + m_hertz = 60.0f; + m_velocityIterations = 8; + m_positionIterations = 1; + m_drawShapes = true; + m_drawJoints = true; + m_drawAABBs = false; + m_drawContactPoints = false; + m_drawContactNormals = false; + m_drawContactImpulse = false; + m_drawFrictionImpulse = false; + m_drawCOMs = false; + m_drawStats = false; + m_drawProfile = false; + m_enableWarmStarting = true; + m_enableContinuous = true; + m_enableSubStepping = false; + m_enableSleep = true; + m_pause = false; + m_singleStep = false; + } + + void Save(); + void Load(); + + int m_testIndex; + int m_windowWidth; + int m_windowHeight; + float m_hertz; + int m_velocityIterations; + int m_positionIterations; + bool m_drawShapes; + bool m_drawJoints; + bool m_drawAABBs; + bool m_drawContactPoints; + bool m_drawContactNormals; + bool m_drawContactImpulse; + bool m_drawFrictionImpulse; + bool m_drawCOMs; + bool m_drawStats; + bool m_drawProfile; + bool m_enableWarmStarting; + bool m_enableContinuous; + bool m_enableSubStepping; + bool m_enableSleep; + bool m_pause; + bool m_singleStep; +}; \ No newline at end of file diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Test.h b/tests/cpp-tests/Classes/Box2DTestBed/test.h_ similarity index 90% rename from tests/cpp-tests/Classes/Box2DTestBed/Test.h rename to tests/cpp-tests/Classes/Box2DTestBed/test.h_ index 594188c082..e6a0aa8927 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Test.h +++ b/tests/cpp-tests/Classes/Box2DTestBed/test.h_ @@ -50,7 +50,7 @@ inline float RandomFloat(float lo, float hi) return r; } -/// Test settings. Some can be controlled in the GUI. +// //Test settings. Some can be controlled in the GUI. //struct Settings //{ // Settings() @@ -113,18 +113,18 @@ public: }; const int32 k_maxContactPoints = 2048; -// -//struct ContactPoint -//{ -// b2Fixture* fixtureA; -// b2Fixture* fixtureB; -// b2Vec2 normal; -// b2Vec2 position; -// b2PointState state; -// float normalImpulse; -// float tangentImpulse; -// float separation; -//}; + +struct ContactPoint +{ + b2Fixture* fixtureA; + b2Fixture* fixtureB; + b2Vec2 normal; + b2Vec2 position; + b2PointState state; + float normalImpulse; + float tangentImpulse; + float separation; +}; class Test : public b2ContactListener { public: @@ -133,7 +133,7 @@ public: virtual ~Test(); void DrawTitle(const char* string); - virtual void Step(Settings* settings); + virtual void Step(Settings& settings); virtual void UpdateUI() {} virtual void Keyboard(int key) { B2_NOT_USED(key); } virtual void KeyboardUp(int key) { B2_NOT_USED(key); } @@ -189,19 +189,18 @@ protected: }; typedef Test* TestCreateFcn(); - int RegisterTest(const char* category, const char* name, TestCreateFcn* fcn); - // -struct TestEntry -{ - const char* category; - const char* name; - TestCreateFcn* createFcn; -}; - -#define MAX_TESTS 256 -extern TestEntry g_testEntries[MAX_TESTS]; -extern int g_testCount; +//// +//struct TestEntry +//{ +// const char* category; +// const char* name; +// TestCreateFcn* createFcn; +//}; +// +//#define MAX_TESTS 256 +//extern TestEntry g_testEntries[MAX_TESTS]; +//extern int g_testCount; #endif diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/add_pair.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/add_pair.cpp index b9a1330ccc..ceccbf8ca2 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/add_pair.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/add_pair.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class AddPair : public Test { @@ -68,6 +68,4 @@ public: } }; - static int testIndex = RegisterTest("Benchmark", "Add Pair", AddPair::Create); - diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/apply_force.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/apply_force.cpp index 74667c3e58..335b58a745 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/apply_force.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/apply_force.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" // This test shows how to apply forces and torques to a body. // It also shows how to use the friction joint that can be useful @@ -167,7 +167,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { g_debugDraw.DrawString(5, m_textLine, "Forward (W), Turn (A) and (D)"); m_textLine += m_textIncrement; @@ -192,30 +192,6 @@ public: Test::Step(settings); } - void Keyboard(int key) override - { - switch (key) - { - case GLFW_KEY_W: - { - b2Vec2 f = m_body->GetWorldVector(b2Vec2(0.0f, -50.0f)); - b2Vec2 p = m_body->GetWorldPoint(b2Vec2(0.0f, 3.0f)); - m_body->ApplyForce(f, p, true); - } - break; - - case GLFW_KEY_A: - m_body->ApplyTorque(10.0f, true); - break; - - case GLFW_KEY_D: - m_body->ApplyTorque(-10.0f, true); - break; - } - -// Test::Step(&settings); - } - static Test* Create() { return new ApplyForce; diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/body_types.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/body_types.cpp index d3cd631562..279ae39bf7 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/body_types.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/body_types.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class BodyTypes : public Test { @@ -128,7 +128,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { // Drive the kinematic body. if (m_platform->GetType() == b2_kinematicBody) diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/box_stack.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/box_stack.cpp index 15365e7efb..90dc04460d 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/box_stack.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/box_stack.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" extern B2_API bool g_blockSolve; @@ -125,7 +125,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); g_debugDraw.DrawString(5, m_textLine, "Press: (,) to launch a bullet."); @@ -171,4 +171,4 @@ public: int32 m_indices[e_rowCount * e_columnCount]; }; -static int testIndex = RegisterTest("Stacking", "Boxes", BoxStack::Create); \ No newline at end of file +static int testIndex = RegisterTest("Stacking", "Boxes", BoxStack::Create); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/breakable.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/breakable.cpp index 0bdc948bcc..136244a49d 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/breakable.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/breakable.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" // This is used to test sensor shapes. class Breakable : public Test @@ -119,7 +119,7 @@ public: body2->SetLinearVelocity(velocity2); } - void Step(Settings* settings) override + void Step(Settings& settings) override { if (m_break) { diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/bridge.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/bridge.cpp index 6fe65ebe91..d397a607da 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/bridge.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/bridge.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class Bridge : public Test { diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/bullet_test.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/bullet_test.cpp index c5975759a1..9ddd733a4a 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/bullet_test.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/bullet_test.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class BulletTest : public Test { @@ -94,7 +94,7 @@ public: b2_toiMaxRootIters = 0; } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/cantilever.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/cantilever.cpp index 652e0f0629..e54717b76b 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/cantilever.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/cantilever.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" // It is difficult to make a cantilever made of links completely rigid with weld joints. // You will have to use a high number of iterations to make them stiff. diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/car.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/car.cpp index e778e44d7e..954ca8ae1d 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/car.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/car.cpp @@ -1,6 +1,7 @@ // MIT License // Copyright (c) 2019 Erin Catto +// Copyright(c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +21,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" + // This is a fun demo that shows off the wheel joint class Car : public Test @@ -258,12 +260,12 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { g_debugDraw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, hz down = q, hz up = e"); m_textLine += m_textIncrement; - // g_camera.m_center.x = m_car->GetPosition().x; + g_debugDrawTestBed.debugNodeOffset.x = 250 + m_car->GetPosition().x * -g_debugDrawTestBed.mRatio; Test::Step(settings); } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/chain.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/chain.cpp index b4b1c2476d..e1580355e3 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/chain.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/chain.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #define TEST_BAD_BODY 0 diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/chain_problem.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/chain_problem.cpp index 719370e381..4b2ab3828d 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/chain_problem.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/chain_problem.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class ChainProblem : public Test { diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/character_collision.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/character_collision.cpp index 0f6ec07279..3eab4a744d 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/character_collision.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/character_collision.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" /// This is a test of typical character collision scenarios. This does not /// show how you should implement a character in your application. @@ -230,7 +230,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { b2Vec2 v = m_character->GetLinearVelocity(); v.x = -5.0f; diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/circle_stack.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/circle_stack.cpp index ad632cfe61..62d19ea3fe 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/circle_stack.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/circle_stack.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class CircleStack : public Test { @@ -61,21 +61,21 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); - for (int32 i = 0; i < e_count; ++i) - { - printf("%g ", m_bodies[i]->GetWorldCenter().y); - } + //for (int32 i = 0; i < e_count; ++i) + //{ + // printf("%g ", m_bodies[i]->GetWorldCenter().y); + //} - for (int32 i = 0; i < e_count; ++i) - { - printf("%g ", m_bodies[i]->GetLinearVelocity().y); - } + //for (int32 i = 0; i < e_count; ++i) + //{ + // printf("%g ", m_bodies[i]->GetLinearVelocity().y); + //} - printf("\n"); + //printf("\n"); } static Test* Create() diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/collision_filtering.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/collision_filtering.cpp index a9c3349f6a..4903da5f5c 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/collision_filtering.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/collision_filtering.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" // This is a test of collision filtering. // There is a triangle, a box, and a circle. diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/collision_processing.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/collision_processing.cpp index 1c12ca22c6..1c684bdaec 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/collision_processing.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/collision_processing.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #include @@ -122,7 +122,7 @@ public: body6->CreateFixture(&circleShapeDef); } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/compound_shapes.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/compound_shapes.cpp index 0ea4fc0b64..34aea77d0f 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/compound_shapes.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/compound_shapes.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #include "ImGuiEXT/CCImGuiEXT.h" class CompoundShapes : public Test diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/confined.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/confined.cpp index 85d4f79f09..3ac9bd6b87 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/confined.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/confined.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class Confined : public Test { @@ -115,7 +115,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { bool sleeping = true; for (b2Body* b = m_world->GetBodyList(); b; b = b->GetNext()) diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/continuous_test.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/continuous_test.cpp index eb5fddefaa..78cc223d88 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/continuous_test.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/continuous_test.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class ContinuousTest : public Test { @@ -110,7 +110,7 @@ public: m_body->SetAngularVelocity(m_angularVelocity); } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); @@ -118,9 +118,9 @@ public: if (b2_gjkCalls > 0) { - //g_debugDraw.DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d", - // b2_gjkCalls, b2_gjkIters / float(b2_gjkCalls), b2_gjkMaxIters); - //m_textLine += m_textIncrement; + g_debugDraw.DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d", + b2_gjkCalls, b2_gjkIters / float(b2_gjkCalls), b2_gjkMaxIters); + m_textLine += m_textIncrement; } extern B2_API int32 b2_toiCalls, b2_toiIters; diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/convex_hull.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/convex_hull.cpp index 82e64ec4c3..ab56e91154 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/convex_hull.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/convex_hull.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class ConvexHull : public Test { @@ -70,7 +70,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/conveyor_belt.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/conveyor_belt.cpp index 1ef99aa574..41d4f2c61c 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/conveyor_belt.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/conveyor_belt.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class ConveyorBelt : public Test { @@ -85,7 +85,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/distance_joint.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/distance_joint.cpp index c15bdc561b..07360a1c14 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/distance_joint.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/distance_joint.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #include "ImGuiEXT/CCImGuiEXT.h" // This tests distance joints, body destruction, and joint destruction. diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/distance_test.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/distance_test.cpp index 233107aa3c..90496adfd7 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/distance_test.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/distance_test.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #include "box2d/b2_distance.h" class DistanceTest : public Test @@ -48,7 +48,7 @@ public: return new DistanceTest; } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/dominos.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/dominos.cpp index bbbbb85da4..739876bf55 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/dominos.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/dominos.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class Dominos : public Test { diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/dump_loader.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/dump_loader.cpp index 05d474b58b..882f59b67c 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/dump_loader.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/dump_loader.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" // This test holds worlds dumped using b2World::Dump. class DumpLoader : public Test @@ -61,7 +61,7 @@ public: m_ball->ApplyForceToCenter(b2Vec2(-1000, -400), true); } - void Step(Settings* settings) override + void Step(Settings& settings) override { b2Vec2 v = m_ball->GetLinearVelocity(); float omega = m_ball->GetAngularVelocity(); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/dynamic_tree.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/dynamic_tree.cpp index 13e990bf70..7772d5ce57 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/dynamic_tree.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/dynamic_tree.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class DynamicTree : public Test { @@ -65,7 +65,7 @@ public: return new DynamicTree; } - void Step(Settings* settings) override + void Step(Settings& settings) override { B2_NOT_USED(settings); @@ -198,8 +198,8 @@ private: void GetRandomAABB(b2AABB* aabb) { b2Vec2 w; w.Set(2.0f * m_proxyExtent, 2.0f * m_proxyExtent); - aabb->lowerBound.x = -m_proxyExtent; - aabb->lowerBound.y = -m_proxyExtent + m_worldExtent; + //aabb->lowerBound.x = -m_proxyExtent; + //aabb->lowerBound.y = -m_proxyExtent + m_worldExtent; aabb->lowerBound.x = RandomFloat(-m_worldExtent, m_worldExtent); aabb->lowerBound.y = RandomFloat(0.0f, 2.0f * m_worldExtent); aabb->upperBound = aabb->lowerBound + w; diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/edge_shapes.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/edge_shapes.cpp index a8d68a062c..6648c3c5c3 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/edge_shapes.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/edge_shapes.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -//#include "settings.h" -#include "../test.h" +#include "settings.h" +#include "test.h" class EdgeShapesCallback : public b2RayCastCallback { @@ -200,13 +200,13 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { - bool advanceRay = 0.1;// settings.m_pause == 0 || settings.m_singleStep; + bool advanceRay = settings.m_pause == 0 || settings.m_singleStep; Test::Step(settings); g_debugDraw.DrawString(5, m_textLine, "Press 1-5 to drop stuff"); - // m_textLine += m_textIncrement; + m_textLine += m_textIncrement; float L = 25.0f; b2Vec2 point1(0.0f, 10.0f); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/edge_test.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/edge_test.cpp index 50d9743b76..749d7ef7bc 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/edge_test.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/edge_test.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #include "ImGuiEXT/CCImGuiEXT.h" class EdgeTest : public Test @@ -251,7 +251,7 @@ public: ImGui::End(); } - void Step(Settings* settings) override + void Step(Settings& settings) override { //if (glfwGetKey(g_mainWindow, GLFW_KEY_A) == GLFW_PRESS) //{ diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/friction.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/friction.cpp index aa5398f3a2..9f1c06e932 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/friction.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/friction.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class Friction : public Test { diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/gear_joint.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/gear_joint.cpp index 5d928c13c7..6f312837eb 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/gear_joint.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/gear_joint.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class GearJoint : public Test { @@ -148,7 +148,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/heavy1.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/heavy1.cpp index ac98ac1f16..d302808aad 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/heavy1.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/heavy1.cpp @@ -1,4 +1,4 @@ - // MIT License +// MIT License // Copyright (c) 2019 Erin Catto @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class Heavy1 : public Test { @@ -58,4 +58,4 @@ public: } }; -static int testIndex = RegisterTest("Solver", "Heavy 1", Heavy1::Create); \ No newline at end of file +static int testIndex = RegisterTest("Solver", "Heavy 1", Heavy1::Create); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/heavy2.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/heavy2.cpp index 01c0951858..271c089b3d 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/heavy2.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/heavy2.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class Heavy2 : public Test { diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/mobile_balanced.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/mobile_balanced.cpp index a802d1781e..ee5af37831 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/mobile_balanced.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/mobile_balanced.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class MobileBalanced : public Test { diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/mobile_unbalanced.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/mobile_unbalanced.cpp index aac855d484..5f62fb6ebf 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/mobile_unbalanced.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/mobile_unbalanced.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class MobileUnbalanced : public Test { diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/motor_joint.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/motor_joint.cpp index b90b7aa4b6..dcda76fa85 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/motor_joint.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/motor_joint.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -//#include "settings.h" -#include "../test.h" +#include "settings.h" +#include "test.h" /// This test shows how to use a motor joint. A motor joint /// can be used to animate a dynamic body. With finite motor forces @@ -82,12 +82,12 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { - //if (m_go && settings.m_hertz > 0.0f) - //{ - // m_time += 1.0f / settings.m_hertz; - //} + if (m_go && settings.m_hertz > 0.0f) + { + m_time += 1.0f / settings.m_hertz; + } b2Vec2 linearOffset; linearOffset.x = 6.0f * sinf(2.0f * m_time); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/pinball.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/pinball.cpp index 0fb69e4ea8..9a9826d79e 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/pinball.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/pinball.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" /// This tests bullet collision and provides an example of a gameplay scenario. /// This also uses a loop shape. @@ -116,7 +116,7 @@ public: m_button = false; } - void Step(Settings* settings) override + void Step(Settings& settings) override { if (m_button) { diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/platformer.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/platformer.cpp index e236fc9479..388892ff53 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/platformer.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/platformer.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class Platformer : public Test { @@ -110,7 +110,7 @@ public: #endif } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/polygon_collision.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/polygon_collision.cpp index 2c0962635a..e55f1336ff 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/polygon_collision.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/polygon_collision.cpp @@ -20,24 +20,24 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class PolygonCollision : public Test { public: PolygonCollision() { - //{ - // m_polygonA.SetAsBox(0.2f, 0.4f); - // m_transformA.Set(b2Vec2(0.0f, 0.0f), 0.0f); - //} + { + m_polygonA.SetAsBox(0.2f, 0.4f); + m_transformA.Set(b2Vec2(0.0f, 0.0f), 0.0f); + } - //{ - // m_polygonB.SetAsBox(0.5f, 0.5f); - // m_positionB.Set(19.345284f, 1.5632932f); - // m_angleB = 1.9160721f; - // m_transformB.Set(m_positionB, m_angleB); - //} + { + m_polygonB.SetAsBox(0.5f, 0.5f); + m_positionB.Set(19.345284f, 1.5632932f); + m_angleB = 1.9160721f; + m_transformB.Set(m_positionB, m_angleB); + } } static Test* Create() @@ -45,38 +45,38 @@ public: return new PolygonCollision; } - void Step(Settings* settings) override + void Step(Settings& settings) override { - // B2_NOT_USED(settings); + B2_NOT_USED(settings); - //b2Manifold manifold; - //b2CollidePolygons(&manifold, &m_polygonA, m_transformA, &m_polygonB, m_transformB); + b2Manifold manifold; + b2CollidePolygons(&manifold, &m_polygonA, m_transformA, &m_polygonB, m_transformB); - //b2WorldManifold worldManifold; - //worldManifold.Initialize(&manifold, m_transformA, m_polygonA.m_radius, m_transformB, m_polygonB.m_radius); + b2WorldManifold worldManifold; + worldManifold.Initialize(&manifold, m_transformA, m_polygonA.m_radius, m_transformB, m_polygonB.m_radius); - // g_debugDraw.DrawString(5, m_textLine, "point count = %d", manifold.pointCount); - // m_textLine += m_textIncrement; + g_debugDraw.DrawString(5, m_textLine, "point count = %d", manifold.pointCount); + m_textLine += m_textIncrement; - //{ - // b2Color color(0.9f, 0.9f, 0.9f); - // b2Vec2 v[b2_maxPolygonVertices]; - // for (int32 i = 0; i < m_polygonA.m_count; ++i) - // { - // v[i] = b2Mul(m_transformA, m_polygonA.m_vertices[i]); - // } - // g_debugDraw.DrawPolygon(v, m_polygonA.m_count, color); - - // for (int32 i = 0; i < m_polygonB.m_count; ++i) - // { - // v[i] = b2Mul(m_transformB, m_polygonB.m_vertices[i]); - // } - // g_debugDraw.DrawPolygon(v, m_polygonB.m_count, color); - //} - - // for (int32 i = 0; i < manifold.pointCount; ++i) { - // g_debugDraw.DrawPoint(worldManifold.points[i], 4.0f, b2Color(0.9f, 0.3f, 0.3f)); + b2Color color(0.9f, 0.9f, 0.9f); + b2Vec2 v[b2_maxPolygonVertices]; + for (int32 i = 0; i < m_polygonA.m_count; ++i) + { + v[i] = b2Mul(m_transformA, m_polygonA.m_vertices[i]); + } + g_debugDraw.DrawPolygon(v, m_polygonA.m_count, color); + + for (int32 i = 0; i < m_polygonB.m_count; ++i) + { + v[i] = b2Mul(m_transformB, m_polygonB.m_vertices[i]); + } + g_debugDraw.DrawPolygon(v, m_polygonB.m_count, color); + } + + for (int32 i = 0; i < manifold.pointCount; ++i) + { + g_debugDraw.DrawPoint(worldManifold.points[i], 4.0f, b2Color(0.9f, 0.3f, 0.3f)); } Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/polygon_shapes.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/polygon_shapes.cpp index 7c8fea9db0..e12875b8c0 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/polygon_shapes.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/polygon_shapes.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" /// This tests stacking. It also shows how to use b2World::Query /// and b2TestOverlap. @@ -225,7 +225,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/prismatic_joint.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/prismatic_joint.cpp index c2cab41038..c2822f0f5e 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/prismatic_joint.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/prismatic_joint.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -//#include "settings.h" -#include "../test.h" +#include "settings.h" +#include "test.h" #include "ImGuiEXT/CCImGuiEXT.h" // Test the prismatic joint with limits and motor options. @@ -96,10 +96,10 @@ public: ImGui::End(); } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); - float force = m_joint->GetMotorForce(settings->hz); + float force = m_joint->GetMotorForce(settings.m_hertz); g_debugDraw.DrawString(5, m_textLine, "Motor Force = %4.0f", force); m_textLine += m_textIncrement; } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/pulley_joint.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/pulley_joint.cpp index 099b55ac74..c2ff6839c6 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/pulley_joint.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/pulley_joint.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class PulleyJoint : public Test { @@ -75,7 +75,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/pyramid.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/pyramid.cpp index a0a6c1b4e0..ee90d5d01b 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/pyramid.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/pyramid.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class Pyramid : public Test { @@ -71,7 +71,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/ray_cast.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/ray_cast.cpp index 7b8c67d37b..de12f196bc 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/ray_cast.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/ray_cast.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -//#include "settings.h" -#include "../test.h" +#include "settings.h" +#include "test.h" #include "ImGuiEXT/CCImGuiEXT.h" enum @@ -293,7 +293,7 @@ public: void UpdateUI() override { - ImGui::SetNextWindowPos(ImVec2(10.0f, 100.0f)); + ImGui::SetNextWindowPos(ImVec2(g_debugDrawTestBed.debugNodeOffset.x, g_debugDrawTestBed.debugNodeOffset.y)); ImGui::SetNextWindowSize(ImVec2(210.0f, 285.0f)); ImGui::Begin("Ray-cast Controls", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize); @@ -341,7 +341,7 @@ public: ImGui::End(); } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/restitution.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/restitution.cpp index b32e47e1da..7772c62363 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/restitution.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/restitution.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" // Note: even with a restitution of 1.0, there is some energy change // due to position correction. diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/revolute_joint.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/revolute_joint.cpp index fd780a5ed3..24e0d6a8f2 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/revolute_joint.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/revolute_joint.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -//#include "settings.h" -#include "../test.h" +#include "settings.h" +#include "test.h" #include "ImGuiEXT/CCImGuiEXT.h" class RevoluteJoint : public Test @@ -133,15 +133,15 @@ public: ImGui::End(); } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); - float torque1 = m_joint1->GetMotorTorque(settings->hz); + float torque1 = m_joint1->GetMotorTorque(settings.m_hertz); g_debugDraw.DrawString(5, m_textLine, "Motor Torque 1= %4.0f", torque1); m_textLine += m_textIncrement; - float torque2 = m_joint2->GetMotorTorque(1.0); //settings.hz); + float torque2 = m_joint2->GetMotorTorque(settings.m_hertz); g_debugDraw.DrawString(5, m_textLine, "Motor Torque 2= %4.0f", torque2); m_textLine += m_textIncrement; } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/rope.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/rope.cpp index 35b75310bd..bdf752928c 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/rope.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/rope.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -//#include "settings.h" -#include "../test.h" +#include "settings.h" +#include "test.h" #include "box2d/b2_rope.h" #include "ImGuiEXT/CCImGuiEXT.h" @@ -232,11 +232,11 @@ public: ImGui::End(); } - void Step(Settings* settings) override + void Step(Settings& settings) override { - float dt = 0.5; // settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f; + float dt = settings.m_hertz > 0.0f ? 1.0f / settings.m_hertz : 0.0f; - if (settings->pause == 1 && settings->singleStep == 0) + if (settings.m_pause == 1 && settings.m_singleStep == 0) { dt = 0.0f; } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/sensor.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/sensor.cpp index 51a8412e74..05f55473b3 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/sensor.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/sensor.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #include "ImGuiEXT/CCImGuiEXT.h" // This shows how to use sensor shapes. Sensors don't have collision, but report overlap events. @@ -148,7 +148,7 @@ public: ImGui::End(); } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/settings.h b/tests/cpp-tests/Classes/Box2DTestBed/tests/settings.h new file mode 100644 index 0000000000..e4725e3d77 --- /dev/null +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/settings.h @@ -0,0 +1,83 @@ +// MIT License + +// Copyright (c) 2019 Erin Catto + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +struct Settings +{ + Settings() + { + Reset(); + } + + void Reset() + { + m_testIndex = 0; + m_windowWidth = 1600; + m_windowHeight = 900; + m_hertz = 60.0f; + m_velocityIterations = 8; + m_positionIterations = 3; + m_drawShapes = true; + m_drawJoints = true; + m_drawAABBs = false; + m_drawContactPoints = false; + m_drawContactNormals = false; + m_drawContactImpulse = false; + m_drawFrictionImpulse = false; + m_drawCOMs = false; + m_drawStats = false; + m_drawProfile = false; + m_enableWarmStarting = true; + m_enableContinuous = true; + m_enableSubStepping = false; + m_enableSleep = true; + m_pause = false; + m_singleStep = false; + } + + void Save(); + void Load(); + + int m_testIndex; + int m_windowWidth; + int m_windowHeight; + float m_hertz; + int m_velocityIterations; + int m_positionIterations; + bool m_drawShapes; + bool m_drawJoints; + bool m_drawAABBs; + bool m_drawContactPoints; + bool m_drawContactNormals; + bool m_drawContactImpulse; + bool m_drawFrictionImpulse; + bool m_drawCOMs; + bool m_drawStats; + bool m_drawProfile; + bool m_enableWarmStarting; + bool m_enableContinuous; + bool m_enableSubStepping; + bool m_enableSleep; + bool m_pause; + bool m_singleStep; +}; \ No newline at end of file diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/shape_cast.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/shape_cast.cpp index 9f2e195b98..85ce422741 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/shape_cast.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/shape_cast.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #include "box2d/b2_distance.h" class ShapeCast : public Test @@ -90,7 +90,7 @@ public: return new ShapeCast; } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/shape_editing.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/shape_editing.cpp index b7e6b1d2e7..307f295b83 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/shape_editing.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/shape_editing.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class ShapeEditing : public Test { @@ -51,41 +51,41 @@ public: m_sensor = false; } - //void Keyboard(int key) override - //{ - // switch (key) - // { - // case GLFW_KEY_C: - // if (m_fixture2 == NULL) - // { - // b2CircleShape shape; - // shape.m_radius = 3.0f; - // shape.m_p.Set(0.5f, -4.0f); - // m_fixture2 = m_body->CreateFixture(&shape, 10.0f); - // m_body->SetAwake(true); - // } - // break; + void Keyboard(int key) override + { + switch (key) + { + case GLFW_KEY_C: + if (m_fixture2 == NULL) + { + b2CircleShape shape; + shape.m_radius = 3.0f; + shape.m_p.Set(0.5f, -4.0f); + m_fixture2 = m_body->CreateFixture(&shape, 10.0f); + m_body->SetAwake(true); + } + break; - // case GLFW_KEY_D: - // if (m_fixture2 != NULL) - // { - // m_body->DestroyFixture(m_fixture2); - // m_fixture2 = NULL; - // m_body->SetAwake(true); - // } - // break; + case GLFW_KEY_D: + if (m_fixture2 != NULL) + { + m_body->DestroyFixture(m_fixture2); + m_fixture2 = NULL; + m_body->SetAwake(true); + } + break; - // case GLFW_KEY_S: - // if (m_fixture2 != NULL) - // { - // m_sensor = !m_sensor; - // m_fixture2->SetSensor(m_sensor); - // } - // break; - // } - //} + case GLFW_KEY_S: + if (m_fixture2 != NULL) + { + m_sensor = !m_sensor; + m_fixture2->SetSensor(m_sensor); + } + break; + } + } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); g_debugDraw.DrawString(5, m_textLine, "Press: (c) create a shape, (d) destroy a shape."); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/skier.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/skier.cpp index d2d01a54b0..94845fc1d8 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/skier.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/skier.cpp @@ -2,7 +2,7 @@ Test case for collision/jerking issue. */ -#include "../test.h" +#include "test.h" #include #include @@ -107,7 +107,7 @@ public: //g_camera.m_center = b2Vec2(m_platform_width / 2.0f, 0.0f); //g_camera.m_zoom = 0.4f; - //m_fixed_camera = true; + m_fixed_camera = true; } void Keyboard(int key) override @@ -118,21 +118,21 @@ public: m_fixed_camera = !m_fixed_camera; if(m_fixed_camera) { -// g_camera.m_center = b2Vec2(m_platform_width / 2.0f, 0.0f); + // g_camera.m_center = b2Vec2(m_platform_width / 2.0f, 0.0f); } break; } } - void Step(Settings* settings) override + void Step(Settings& settings) override { g_debugDraw.DrawString(5, m_textLine, "Keys: c = Camera fixed/tracking"); m_textLine += m_textIncrement; -// if(!m_fixed_camera) -// { -// g_camera.m_center = m_skier->GetPosition(); -// } + if(!m_fixed_camera) + { + //g_camera.m_center = m_skier->GetPosition(); + } Test::Step(settings); } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/slider_crank_1.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/slider_crank_1.cpp index d89a3c6daa..395b93939e 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/slider_crank_1.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/slider_crank_1.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" // A basic slider crank created for GDC tutorial: Understanding Constraints class SliderCrank1 : public Test diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/slider_crank_2.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/slider_crank_2.cpp index 6a83f8e36d..546d6a1d4c 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/slider_crank_2.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/slider_crank_2.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -//#include "settings.h" -#include "../test.h" +#include "settings.h" +#include "test.h" // A motor driven slider crank with joint friction. @@ -138,12 +138,12 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); g_debugDraw.DrawString(5, m_textLine, "Keys: (f) toggle friction, (m) toggle motor"); m_textLine += m_textIncrement; - float torque = m_joint1->GetMotorTorque(settings->hz); + float torque = m_joint1->GetMotorTorque(settings.m_hertz); g_debugDraw.DrawString(5, m_textLine, "Motor Torque = %5.0f", (float) torque); m_textLine += m_textIncrement; } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/test.h b/tests/cpp-tests/Classes/Box2DTestBed/tests/test.h new file mode 100644 index 0000000000..687db55394 --- /dev/null +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/test.h @@ -0,0 +1,148 @@ +/* +* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef TEST_H +#define TEST_H + +#include "box2d/box2d.h" +#include "extensions/cocos-ext.h" + +#include + +class Test; +struct Settings; + + + +#define RAND_LIMIT 32767 +#define DRAW_STRING_NEW_LINE 25 + +/// Random number in range [-1,1] +inline float RandomFloat() +{ + float r = (float)(std::rand() & (RAND_LIMIT)); + r /= RAND_LIMIT; + r = 2.0f * r - 1.0f; + return r; +} + +/// Random floating point number in range [lo, hi] +inline float RandomFloat(float lo, float hi) +{ + float r = (float)(std::rand() & (RAND_LIMIT)); + r /= RAND_LIMIT; + r = (hi - lo) * r + lo; + return r; +} + + +// This is called when a joint in the world is implicitly destroyed +// because an attached body is destroyed. This gives us a chance to +// nullify the mouse joint. +class DestructionListener : public b2DestructionListener +{ +public: + void SayGoodbye(b2Fixture* fixture) { B2_NOT_USED(fixture); } + void SayGoodbye(b2Joint* joint); + + Test* test; +}; + +const int32 k_maxContactPoints = 2048; + +struct ContactPoint +{ + b2Fixture* fixtureA; + b2Fixture* fixtureB; + b2Vec2 normal; + b2Vec2 position; + b2PointState state; + float normalImpulse; + float tangentImpulse; + float separation; +}; +class Test : public b2ContactListener +{ +public: + + Test(); + virtual ~Test(); + + void DrawTitle(const char* string); + virtual void Step(Settings& settings); + virtual void UpdateUI() {} + virtual void Keyboard(int key) { B2_NOT_USED(key); } + virtual void KeyboardUp(int key) { B2_NOT_USED(key); } + void ShiftMouseDown(const b2Vec2& p); + virtual bool MouseDown(const b2Vec2& p); + virtual void MouseUp(const b2Vec2& p); + virtual void MouseMove(const b2Vec2& p); + void LaunchBomb(); + void LaunchBomb(const b2Vec2& position, const b2Vec2& velocity); + + void SpawnBomb(const b2Vec2& worldPt); + void CompleteBombSpawn(const b2Vec2& p); + + // Let derived tests know that a joint was destroyed. + virtual void JointDestroyed(b2Joint* joint) { B2_NOT_USED(joint); } + + // Callbacks for derived classes. + virtual void BeginContact(b2Contact* contact) override { B2_NOT_USED(contact); } + virtual void EndContact(b2Contact* contact) override { B2_NOT_USED(contact); } + virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold) override; + virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) override + { + B2_NOT_USED(contact); + B2_NOT_USED(impulse); + } + + void ShiftOrigin(const b2Vec2& newOrigin); + + DebugDraw g_debugDraw; + DebugDraw g_debugDrawTestBed; + cocos2d::DrawNode* debugDrawNode; + + b2World* m_world; + +protected: + friend class DestructionListener; + friend class BoundaryListener; + friend class ContactListener; + + b2Body* m_groundBody; + b2AABB m_worldAABB; + ContactPoint m_points[k_maxContactPoints]; + int32 m_pointCount; + DestructionListener m_destructionListener; + int32 m_textLine; + + b2Body* m_bomb; + b2MouseJoint* m_mouseJoint; + b2Vec2 m_bombSpawnPoint; + bool m_bombSpawning; + b2Vec2 m_mouseWorld; + int32 m_stepCount; + int32 m_textIncrement; + b2Profile m_maxProfile; + b2Profile m_totalProfile; +}; + +typedef Test* TestCreateFcn(); +int RegisterTest(const char* category, const char* name, TestCreateFcn* fcn); + +#endif diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/theo_jansen.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/theo_jansen.cpp index fdab29a7f1..a3155acf9c 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/theo_jansen.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/theo_jansen.cpp @@ -23,7 +23,7 @@ // Inspired by a contribution from roman_m // Dimensions scooped from APE (http://www.cove.org/ape/index.htm) -#include "../test.h" +#include "test.h" class TheoJansen : public Test { @@ -220,7 +220,7 @@ public: CreateLeg(1.0f, wheelAnchor); } - void Step(Settings* settings) override + void Step(Settings& settings) override { g_debugDraw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, toggle motor = m"); m_textLine += m_textIncrement; @@ -230,8 +230,6 @@ public: void Keyboard(int key) override { - - CCLOG("Keyboard(int key %i A:%i)", key, GLFW_KEY_A); switch (key) { case GLFW_KEY_A: diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/tiles.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/tiles.cpp index 8d1750abe1..e6a4e56143 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/tiles.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/tiles.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" /// This stress tests the dynamic tree broad-phase. This also shows that tile /// based collision is _not_ smooth due to Box2D not knowing about adjacency. @@ -123,7 +123,7 @@ public: m_createTime = timer.GetMilliseconds(); } - void Step(Settings* settings) override + void Step(Settings& settings) override { const b2ContactManager& cm = m_world->GetContactManager(); int32 height = cm.m_broadPhase.GetTreeHeight(); @@ -139,12 +139,12 @@ public: m_createTime, m_fixtureCount); m_textLine += m_textIncrement; - // b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree; + //b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree; - if (m_stepCount == 400) - { - // tree->RebuildBottomUp(); - } + //if (m_stepCount == 400) + //{ + // tree->RebuildBottomUp(); + //} } static Test* Create() diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/time_of_impact.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/time_of_impact.cpp index 2c8fe1546d..25362bf23c 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/time_of_impact.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/time_of_impact.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #include "box2d/b2_time_of_impact.h" class TimeOfImpact : public Test @@ -37,7 +37,7 @@ public: return new TimeOfImpact; } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); @@ -55,8 +55,8 @@ public: sweepB.a = 513.62781f; // - 162.0f * b2_pi; sweepB.localCenter.SetZero(); - sweepB.a0 -= 300.0f * b2_pi; - sweepB.a -= 300.0f * b2_pi; + //sweepB.a0 -= 300.0f * b2_pi; + //sweepB.a -= 300.0f * b2_pi; b2TOIInput input; input.proxyA.Set(&m_shapeA, 0); @@ -89,7 +89,7 @@ public: b2Transform transformB; sweepB.GetTransform(&transformB, 0.0f); - b2Vec2 localPoint(2.0f, -0.1f); + //b2Vec2 localPoint(2.0f, -0.1f); for (int32 i = 0; i < m_shapeB.m_count; ++i) { @@ -101,7 +101,7 @@ public: for (int32 i = 0; i < m_shapeB.m_count; ++i) { vertices[i] = b2Mul(transformB, m_shapeB.m_vertices[i]); - } + } g_debugDraw.DrawPolygon(vertices, m_shapeB.m_count, b2Color(0.5f, 0.7f, 0.9f)); sweepB.GetTransform(&transformB, 1.0f); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/tumbler.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/tumbler.cpp index ce360e02d0..f7972bc777 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/tumbler.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/tumbler.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" class Tumbler : public Test { @@ -71,7 +71,7 @@ public: m_count = 0; } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); @@ -99,4 +99,4 @@ public: int32 m_count; }; - static int testIndex = RegisterTest("Benchmark", "Tumbler", Tumbler::Create); +static int testIndex = RegisterTest("Benchmark", "Tumbler", Tumbler::Create); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/web.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/web.cpp index 2b6ce72a94..aefa46ac97 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/web.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/web.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" // Test distance joints, body destruction, and joint destruction. class Web : public Test @@ -157,7 +157,7 @@ public: } } - void Keyboard(int key) + void Keyboard(int key) override { switch (key) { @@ -187,7 +187,7 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); g_debugDraw.DrawString(5, m_textLine, "Press: (b) to delete a body, (j) to delete a joint"); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/wheel_joint.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/wheel_joint.cpp index 228ab0653c..92bcae0bf8 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/wheel_joint.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/wheel_joint.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -//#include "settings.h" -#include "../test.h" +#include "settings.h" +#include "test.h" #include "ImGuiEXT/CCImGuiEXT.h" // Test the wheel joint with motor, spring, and limit options. @@ -75,15 +75,15 @@ public: } } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); - float torque = m_joint->GetMotorTorque(settings->hz); + float torque = m_joint->GetMotorTorque(settings.m_hertz); g_debugDraw.DrawString(5, m_textLine, "Motor Torque = %4.0f", torque); m_textLine += m_textIncrement; - b2Vec2 F = m_joint->GetReactionForce(settings->hz); + b2Vec2 F = m_joint->GetReactionForce(settings.m_hertz); g_debugDraw.DrawString(5, m_textLine, "Reaction Force = (%4.1f, %4.1f)", F.x, F.y); m_textLine += m_textIncrement; } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/tests/wrecking_ball.cpp b/tests/cpp-tests/Classes/Box2DTestBed/tests/wrecking_ball.cpp index fd2f006fd5..a3595a3899 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/tests/wrecking_ball.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/tests/wrecking_ball.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "../test.h" +#include "test.h" #include "ImGuiEXT/CCImGuiEXT.h" /// This test shows how a distance joint can be used to stabilize a chain of @@ -135,10 +135,9 @@ public: } ImGui::End(); - } - void Step(Settings* settings) override + void Step(Settings& settings) override { Test::Step(settings); @@ -151,8 +150,6 @@ public: g_debugDraw.DrawString(5, m_textLine, "Distance Joint OFF"); } m_textLine += m_textIncrement; - - UpdateUI(); } static Test* Create()