Fixes for crashes in sprite and sprite cache tests

This commit is contained in:
rh101 2021-08-19 15:43:18 +10:00
parent 4ec017f4bc
commit ad3e3380e2
52 changed files with 404 additions and 413 deletions

View File

@ -677,29 +677,6 @@ void DrawNode::drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, cons
drawPolygon(poli, numberOfPoints, color, 0.0, Color4F());
}
void DrawNode::drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const Color4F& fillColor, float borderWidth, const Color4F& borderColor)
{
const float coef = 2.0f * (float)M_PI / segments;
Vec2* vertices = new (std::nothrow) Vec2[segments];
if (!vertices)
return;
for (unsigned int i = 0; i < segments; i++)
{
float rads = i * coef;
float j = radius * cosf(rads + angle) * scaleX + center.x;
float k = radius * sinf(rads + angle) * scaleY + center.y;
vertices[i].x = j;
vertices[i].y = k;
}
drawPolygon(vertices, segments, fillColor, borderWidth, borderColor);
CC_SAFE_DELETE_ARRAY(vertices);
}
void DrawNode::drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const Color4F &color)
{
const float coef = 2.0f * (float)M_PI/segments;
@ -723,9 +700,6 @@ void DrawNode::drawSolidCircle(const Vec2& center, float radius, float angle, un
CC_SAFE_DELETE_ARRAY(vertices);
}
void DrawNode::drawSolidCircle( const Vec2& center, float radius, float angle, unsigned int segments, const Color4F& color)
{
drawSolidCircle(center, radius, angle, segments, 1.0f, 1.0f, color);

View File

@ -216,20 +216,6 @@ public:
*/
void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, const Color4F &color);
/** Draws a solid circle given the center, radius and number of segments.
* @param center The circle center point.
* @param radius The circle rotate of radius.
* @param angle The circle angle.
* @param segments The number of segments.
* @param scaleX The scale value in x.
* @param scaleY The scale value in y.
* @param fillColor The color will fill in polygon.
* @param borderWidth The border of line width.
* @param borderColor The border of line color.
* @js NA
*/
void drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const Color4F& fillColor, float borderWidth, const Color4F& borderColor);
/** Draws a solid circle given the center, radius and number of segments.
* @param center The circle center point.
* @param radius The circle rotate of radius.

View File

@ -16,64 +16,90 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdbool.h>
#include <limits.h>
#include "CCPhysicsDebugNodeBox2D.h"
NS_CC_EXT_BEGIN
PhysicsDebugNodeBox2D::PhysicsDebugNodeBox2D()
USING_NS_CC;
#if defined(CC_PLATFORM_PC)
extern cocos2d::Label* labelDebugDraw;
#endif
#define BUFFER_OFFSET(x) ((const void*) (x))
DebugDraw::DebugDraw()
{
drawBP = DrawNode::create();
debugNodeOffset = { 40.0f, 0.0f };
mRatio = 1.0f;
debugNodeOffset = { 40, 0 };
}
PhysicsDebugNodeBox2D::~PhysicsDebugNodeBox2D()
DebugDraw::~DebugDraw()
{
}
cocos2d::DrawNode* PhysicsDebugNodeBox2D::GetDrawNode()
void DebugDraw::initShader(void)
{
// initShader is unsupported
}
cocos2d::DrawNode* DebugDraw::GetDrawNode()
{
return drawBP;
}
void PhysicsDebugNodeBox2D::SetDrawNode(cocos2d::DrawNode* drawNode)
void DebugDraw::SetDrawNode(cocos2d::DrawNode* drawNode)
{
CCASSERT(!drawBP, "drawBP is not NULL");
drawBP = drawNode;
}
cocos2d::Vec2& PhysicsDebugNodeBox2D::GetDebugNodeOffset()
cocos2d::Vec2& DebugDraw::GetDebugNodeOffset()
{
return debugNodeOffset;
}
void PhysicsDebugNodeBox2D::DrawPolygon(const b2Vec2* verts, int vertexCount, const b2Color& color)
void DebugDraw::DrawPolygon(const b2Vec2* verts, int vertexCount, const b2Color& color)
{
Vec2* vec = new (std::nothrow) Vec2[vertexCount];
for (size_t i = 0; i < vertexCount; i++) {
vec[i] = Vec2(verts[i].x * mRatio, verts[i].y * mRatio) + debugNodeOffset;
}
// drawBP->drawPolygon(vec, vertexCount, Color4F(color.r, color.g, color.b, color.a), 1, Color4F(color.r, color.g, color.b, color.a));
drawBP->drawPolygon(vec, vertexCount, Color4F::BLACK, 0.4f, Color4F(color.r, color.g, color.b, color.a));
}
void PhysicsDebugNodeBox2D::DrawSolidPolygon(const b2Vec2* verts, int vertexCount, const b2Color& color)
void DebugDraw::DrawSolidPolygon(const b2Vec2* verts, int vertexCount, const b2Color& color)
{
Vec2* vec = new (std::nothrow) Vec2[vertexCount];
for (size_t i = 0; i < vertexCount; i++) {
vec[i] = Vec2(verts[i].x * mRatio, verts[i].y * mRatio) + debugNodeOffset;
}
drawBP->drawPolygon(vec, vertexCount, Color4F(color.r / 2, color.g / 2, color.b / 2, color.a), 0.4f, Color4F(color.r, color.g, color.b, color.a));
//drawBP->drawSolidPoly(vec, vertexCount, Color4F(color.r, color.g, color.b, color.a));
}
void PhysicsDebugNodeBox2D::DrawCircle(const b2Vec2& center, float radius, const b2Color& color)
void DebugDraw::DrawCircle(const b2Vec2& center, float radius, const b2Color& color)
{
drawBP->drawCircle(Vec2(center.x * mRatio, center.y * mRatio) + debugNodeOffset, radius * mRatio, CC_DEGREES_TO_RADIANS(0), 30, true, 1.0f, 1.0f, Color4F(color.r, color.g, color.b, color.a));
drawBP->drawCircle(Vec2(center.x * mRatio, center.y * mRatio) + debugNodeOffset, radius * mRatio, CC_DEGREES_TO_RADIANS(0), 30, true, 1.0f,
1.0f, Color4F(color.r, color.g, color.b, color.a));
}
void PhysicsDebugNodeBox2D::DrawSolidCircle(const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color)
void DebugDraw::DrawSolidCircle(const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color)
{
// DrawSolidCircle Maybe have to fix later
Vec2 c = { Vec2(center.x * mRatio, center.y * mRatio) + debugNodeOffset };
drawBP->drawSolidCircle(c, radius * mRatio, CC_DEGREES_TO_RADIANS(0), 20, 1.0f, 1.0f, Color4F(color.r / 2, color.g / 2, color.b / 2, color.a), 0.4f, Color4F(color.r, color.g, color.b, color.a));
drawBP->drawCircle(c, radius * mRatio, CC_DEGREES_TO_RADIANS(0), 20, false, 1.0f, 1.0f, Color4F(color.r, color.g, color.b, color.a));
// Draw a line fixed in the circle to animate rotation.
b2Vec2 pp = { (center + radius * axis) };
@ -81,25 +107,66 @@ void PhysicsDebugNodeBox2D::DrawSolidCircle(const b2Vec2& center, float radius,
drawBP->drawLine(c, cp, Color4F(color.r, color.g, color.b, color.a));
}
void PhysicsDebugNodeBox2D::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
void DebugDraw::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
{
drawBP->drawLine(Vec2(p1.x * mRatio, p1.y * mRatio) + debugNodeOffset, Vec2(p2.x * mRatio, p2.y * mRatio) + debugNodeOffset, Color4F(color.r, color.g, color.b, color.a));
}
void PhysicsDebugNodeBox2D::DrawTransform(const b2Transform& xf)
void DebugDraw::DrawTransform(const b2Transform& xf)
{
b2Vec2 p1 = xf.p, p2;
const float k_axisScale = 0.4f;
p2 = p1 + k_axisScale * xf.q.GetXAxis();
DrawSegment(p1, p2, b2Color(1.0f, 0.0f, 0.0f));
DrawSegment(p1, p2, b2Color(1, 0, 0));
p2 = p1 + k_axisScale * xf.q.GetYAxis();
DrawSegment(p1, p2, b2Color(0.0f, 1.0f, 0.0f));
DrawSegment(p1, p2, b2Color(0, 1, 0));
}
void PhysicsDebugNodeBox2D::DrawPoint(const b2Vec2& p, float size, const b2Color& color)
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));
}
NS_CC_EXT_END
void DebugDraw::DrawString(int x, int y, const char* fmt, ...)
{
#if defined(CC_PLATFORM_PC)
debugString.append(std::string(fmt));
debugString.append("\n");
labelDebugDraw->setString(debugString);
// labelDebugDraw->setPosition(x, y);
#endif
}
void DebugDraw::DrawString(const b2Vec2& pw, const char* fmt, ...)
{
#if defined(CC_PLATFORM_PC)
debugString.append(std::string(fmt));
debugString.append("\n");
labelDebugDraw->setString(debugString);
// labelDebugDraw->setPosition(pw.x, pw.y);
#endif
}
void DebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color)
{
b2Vec2 p1 = aabb->lowerBound;
b2Vec2 p2 = b2Vec2(aabb->upperBound.x, aabb->lowerBound.y);
b2Vec2 p3 = aabb->upperBound;
b2Vec2 p4 = b2Vec2(aabb->lowerBound.x, aabb->upperBound.y);
Vec2 verts[] = {
Vec2(p1.x * mRatio, p1.y * mRatio) + debugNodeOffset ,
Vec2(p2.x * mRatio, p2.y * mRatio) + debugNodeOffset ,
Vec2(p3.x * mRatio, p3.y * mRatio) + debugNodeOffset ,
Vec2(p4.x * mRatio, p4.y * mRatio) + debugNodeOffset ,
};
drawBP->drawPolygon(verts, sizeof(verts) / sizeof(verts[0]), Color4F(color.r / 2, color.g / 2, color.b / 2, 0), 0.4f, Color4F(color.r, color.g, color.b, color.a));
}
void DebugDraw::Flush()
{
// Flush is unsupported
}

View File

@ -20,21 +20,28 @@
#ifndef __PHYSICSNODES_DEBUGNODE_BOX2D_H__
#define __PHYSICSNODES_DEBUGNODE_BOX2D_H__
#define GLFW_INCLUDE_NONE
#include "extensions/ExtensionMacros.h"
#include "extensions/ExtensionExport.h"
#include "2d/CCDrawNode.h"
#include "extensions/ExtensionExport.h"
#include "box2d/box2d.h"
#include "cocos2d.h"
NS_CC_EXT_BEGIN
// This class implements debug drawing callbacks that are invoked inside b2World::Step.
class CC_EX_DLL PhysicsDebugNodeBox2D : public b2Draw
// This class implements debug drawing callbacks that are invoked
// inside b2World::Step.
//PhysicsDebugNode : public DrawNode
class CC_EX_DLL DebugDraw : public b2Draw
{
public:
void initShader( void );
PhysicsDebugNodeBox2D();
~PhysicsDebugNodeBox2D();
DebugDraw();
~DebugDraw();
void Create();
void Destroy();
@ -53,19 +60,28 @@ public:
void DrawPoint(const b2Vec2& p, float size, const b2Color& color) override;
// adxe stuffs
void DrawString(int x, int y, const char* fmt, ...);
void DrawString(const b2Vec2& p, const char* fmt, ...);
void DrawAABB(b2AABB* aabb, const b2Color& color);
void Flush();
cocos2d::DrawNode* GetDrawNode();
void SetDrawNode(cocos2d::DrawNode* drawNode);
cocos2d::Vec2& GetDebugNodeOffset();
cocos2d::DrawNode* drawBP = NULL; // adxe "interface"!
cocos2d::Vec2 debugNodeOffset;
float mRatio;
cocos2d::DrawNode* drawBP = NULL;
std::string debugString = "";
cocos2d::Vec2 debugNodeOffset;
private:
};
NS_CC_EXT_END
#endif //__PHYSICSNODES_DEBUGNODE_BOX2D_H__

View File

@ -98092,9 +98092,9 @@ int lua_cocos2dx_SpriteFrameCache_getSpriteSheetLoader(lua_State* tolua_S)
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
unsigned int arg0;
std::string arg0;
ok &= luaval_to_uint32(tolua_S, 2,&arg0, "cc.SpriteFrameCache:getSpriteSheetLoader");
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.SpriteFrameCache:getSpriteSheetLoader");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_SpriteFrameCache_getSpriteSheetLoader'", nullptr);
@ -98244,8 +98244,8 @@ int lua_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile(lua_State* tolua_S)
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
std::string arg1;
ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.SpriteFrameCache:addSpriteFramesWithFile");
cocos2d::Texture2D* arg1;
ok &= luaval_to_object<cocos2d::Texture2D>(tolua_S, 3, "cc.Texture2D",&arg1, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
cobj->addSpriteFramesWithFile(arg0, arg1);
@ -98260,12 +98260,12 @@ int lua_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile(lua_State* tolua_S)
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
std::string arg1;
ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.SpriteFrameCache:addSpriteFramesWithFile");
cocos2d::Texture2D* arg1;
ok &= luaval_to_object<cocos2d::Texture2D>(tolua_S, 3, "cc.Texture2D",&arg1, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
unsigned int arg2;
ok &= luaval_to_uint32(tolua_S, 4,&arg2, "cc.SpriteFrameCache:addSpriteFramesWithFile");
std::string arg2;
ok &= luaval_to_std_string(tolua_S, 4,&arg2, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
cobj->addSpriteFramesWithFile(arg0, arg1, arg2);
@ -98292,8 +98292,8 @@ int lua_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile(lua_State* tolua_S)
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
unsigned int arg1;
ok &= luaval_to_uint32(tolua_S, 3,&arg1, "cc.SpriteFrameCache:addSpriteFramesWithFile");
std::string arg1;
ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
cobj->addSpriteFramesWithFile(arg0, arg1);
@ -98302,43 +98302,7 @@ int lua_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile(lua_State* tolua_S)
}
}while(0);
ok = true;
do{
if (argc == 2) {
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
cocos2d::Texture2D* arg1;
ok &= luaval_to_object<cocos2d::Texture2D>(tolua_S, 3, "cc.Texture2D",&arg1, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
cobj->addSpriteFramesWithFile(arg0, arg1);
lua_settop(tolua_S, 1);
return 1;
}
}while(0);
ok = true;
do{
if (argc == 3) {
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
cocos2d::Texture2D* arg1;
ok &= luaval_to_object<cocos2d::Texture2D>(tolua_S, 3, "cc.Texture2D",&arg1, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
unsigned int arg2;
ok &= luaval_to_uint32(tolua_S, 4,&arg2, "cc.SpriteFrameCache:addSpriteFramesWithFile");
if (!ok) { break; }
cobj->addSpriteFramesWithFile(arg0, arg1, arg2);
lua_settop(tolua_S, 1);
return 1;
}
}while(0);
ok = true;
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.SpriteFrameCache:addSpriteFramesWithFile",argc, 2);
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.SpriteFrameCache:addSpriteFramesWithFile",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
@ -98626,9 +98590,9 @@ int lua_cocos2dx_SpriteFrameCache_deregisterSpriteSheetLoader(lua_State* tolua_S
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
unsigned int arg0;
std::string arg0;
ok &= luaval_to_uint32(tolua_S, 2,&arg0, "cc.SpriteFrameCache:deregisterSpriteSheetLoader");
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.SpriteFrameCache:deregisterSpriteSheetLoader");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_SpriteFrameCache_deregisterSpriteSheetLoader'", nullptr);

View File

@ -59,7 +59,7 @@ private:
cocos2d::Texture2D* _spriteTexture;
cocos2d::DrawNode* drawBox2D;
cocos2d::extension::PhysicsDebugNodeBox2D g_debugDraw;
DebugDraw g_debugDraw;
bool showDebugDraw = true;
} ;

View File

@ -23,13 +23,11 @@
****************************************************************************/
#include "platform/CCPlatformConfig.h"
#include "extensions/cocos-ext.h"
#include "ImGuiEXT/CCImGuiEXT.h"
#include "cocos2d.h"
#include "Box2DTestBed.h"
#include "extensions/cocos-ext.h"
#include "tests/test.h"
#include "tests/settings.h"
#include "ImGuiEXT/CCImGuiEXT.h"
USING_NS_CC;
USING_NS_CC_EXT;
@ -38,7 +36,16 @@ enum {
kTagParentNode = 1,
};
#define kAccelerometerFrequency 30
#define FRAMES_BETWEEN_PRESSES_FOR_DOUBLE_CLICK 10
#define PTM_RATIO 32
Settings settings;
cocos2d::Label* labelDebugDraw;
enum
@ -116,11 +123,15 @@ bool Box2DTestBed::initWithEntryID(int entryId)
m_test->debugDrawNode = debugDrawNode;
m_test->g_debugDraw = g_debugDraw;
TestCase::addChild(debugDrawNode, 100);
// 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);
@ -131,20 +142,14 @@ bool Box2DTestBed::initWithEntryID(int entryId)
_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);
TestCase::_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);
TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_keyboardListener,1);
auto _mouseListener = EventListenerMouse::create();
_mouseListener->onMouseMove = CC_CALLBACK_1(Box2DTestBed::onMouseMove, this);
_mouseListener->onMouseUp = CC_CALLBACK_1(Box2DTestBed::onMouseUp, this);
_mouseListener->onMouseDown = CC_CALLBACK_1(Box2DTestBed::onMouseDown, this);
_mouseListener->onMouseScroll = CC_CALLBACK_1(Box2DTestBed::onMouseScroll, this);
TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_mouseListener, 12);
// Demo messageString
labelDebugDraw = Label::createWithTTF("TEST", "fonts/arial.ttf", 8.0f);
@ -160,6 +165,7 @@ bool Box2DTestBed::initWithEntryID(int entryId)
bool Box2DTestBed::onTouchBegan(Touch* touch, Event* event)
{
CCLOG("onTouchBegan");
auto location = touch->getLocation() - g_debugDraw.debugNodeOffset;
b2Vec2 pos = { location.x / g_debugDraw.mRatio, location.y / g_debugDraw.mRatio };
return m_test->MouseDown(pos);
@ -167,77 +173,36 @@ bool Box2DTestBed::onTouchBegan(Touch* touch, Event* event)
void Box2DTestBed::onTouchMoved(Touch* touch, Event* event)
{
CCLOG("onTouchMoved");
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::onTouchEnded(Touch* touch, Event* event)
{
CCLOG("onTouchEnded");
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)
{
CCLOG("onKeyPressed, keycode: %d", static_cast<int>(code));
m_test->Keyboard((static_cast<int>(code) - 59)); // its a bad hack!
m_test->Keyboard((static_cast<int>(code) - 59));
}
void Box2DTestBed::onKeyReleased(EventKeyboard::KeyCode code, Event* event)
{
CCLOG("onKeyPressed, keycode: %d", static_cast<int>(code));
m_test->KeyboardUp((static_cast<int>(code) - 59)); // its a bad hack!
m_test->KeyboardUp((static_cast<int>(code) - 59));
}
void Box2DTestBed::onMouseDown(Event* event)
{
EventMouse* e = (EventMouse*)event;
switch (e->getMouseButton())
{
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = false;
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = false;
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = false;
case EventMouse::MouseButton::BUTTON_LEFT:
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = true;
break;
case EventMouse::MouseButton::BUTTON_RIGHT:
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = true;
break;
case EventMouse::MouseButton::BUTTON_MIDDLE:
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = true;
break;
}
}
void Box2DTestBed::onMouseUp(Event* event)
{
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = false;
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = false;
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = false;
}
void Box2DTestBed::onMouseMove(Event* event)
{
EventMouse* e = (EventMouse*)event;
pos = { e->getCursorX() / g_debugDraw.mRatio , e->getCursorY() / g_debugDraw.mRatio };
if (button[(int)EventMouse::MouseButton::BUTTON_RIGHT])
{
(pos.x > oldPos.x) ? g_debugDraw.debugNodeOffset.x += 4 : g_debugDraw.debugNodeOffset.x -= 4;
(pos.y < oldPos.y) ? g_debugDraw.debugNodeOffset.y -= 2 : g_debugDraw.debugNodeOffset.y += 2;
}
oldPos = pos;
}
void Box2DTestBed::onMouseScroll(Event* event)
{
EventMouse* e = (EventMouse*)event;
g_debugDraw.mRatio += e->getScrollY();
}
void Box2DTestBed::onEnter()
{
Scene::onEnter();
@ -248,12 +213,13 @@ void Box2DTestBed::onExit()
{
Scene::onExit();
ImGuiEXT::getInstance()->removeRenderLoop("#im01");
}
void Box2DTestBed::update(float dt)
{
// Debug draw
m_test->debugString = "";
m_test->g_debugDraw.debugString = "";
labelDebugDraw->setString("");
debugDrawNode->clear();
m_test->Step(settings);
@ -268,7 +234,7 @@ void Box2DTestBed::initPhysics()
flags += 0 * b2Draw::e_aabbBit;
flags += 0 * b2Draw::e_centerOfMassBit;
g_debugDraw.SetFlags(flags);
g_debugDraw.mRatio = 8;
g_debugDraw.mRatio = PTM_RATIO / 4;
m_test->m_world->SetDebugDraw(&g_debugDraw);
m_test->g_debugDraw = g_debugDraw;
g_debugDraw.debugNodeOffset = { 250, 70 };

View File

@ -28,6 +28,8 @@
#include "cocos2d.h"
#include "box2d/box2d.h"
#include "../BaseTest.h"
#include "renderer/CCCustomCommand.h"
DEFINE_TEST_SUITE(Box2DTestBedTests);
@ -74,11 +76,6 @@ public:
void onKeyPressed(cocos2d::EventKeyboard::KeyCode code, cocos2d::Event* event) override;
void onKeyReleased(cocos2d::EventKeyboard::KeyCode code, cocos2d::Event* event) override;
void onMouseDown(cocos2d::Event* event);
void onMouseUp(cocos2d::Event* event);
void onMouseMove(cocos2d::Event* event);
void onMouseScroll(cocos2d::Event* event);
cocos2d::EventListenerTouchOneByOne* _touchListener;
cocos2d::EventListenerKeyboard* _keyboardListener;
@ -91,13 +88,9 @@ private:
b2World* world;
cocos2d::Texture2D* _spriteTexture;
b2Vec2 pos;
b2Vec2 oldPos;
bool button[2];
// Debug stuff
cocos2d::DrawNode* debugDrawNode;
cocos2d::extension::PhysicsDebugNodeBox2D g_debugDraw;
DebugDraw g_debugDraw;
};

View File

@ -18,18 +18,10 @@
#include "tests/test.h"
#include "tests/settings.h"
#include "extensions/cocos-ext.h"
#include "cocos2d.h"
#include <stdio.h>
USING_NS_CC;
USING_NS_CC_EXT;
#if defined(CC_PLATFORM_PC)
extern cocos2d::Label* labelDebugDraw;
#endif
void DestructionListener::SayGoodbye(b2Joint * joint)
{
@ -112,7 +104,7 @@ void Test::PreSolve(b2Contact * contact, const b2Manifold * oldManifold)
void Test::DrawTitle(const char* string)
{
DrawString(5, 5, string);
g_debugDraw.DrawString(5, 5, string);
m_textLine = int32(26.0f);
}
@ -299,8 +291,8 @@ void Test::Step(Settings& settings)
timeStep = 0.0f;
}
DrawString(5, m_textLine, "****PAUSED****");
g_debugDraw.DrawString(5, m_textLine, "****PAUSED****");
m_textLine += m_textIncrement;
}
uint32 flags = 0;
@ -331,15 +323,15 @@ void Test::Step(Settings& settings)
int32 bodyCount = m_world->GetBodyCount();
int32 contactCount = m_world->GetContactCount();
int32 jointCount = m_world->GetJointCount();
DrawString(5, m_textLine, "bodies/contacts/joints = %d/%d/%d", bodyCount, contactCount, jointCount);
g_debugDraw.DrawString(5, m_textLine, "bodies/contacts/joints = %d/%d/%d", bodyCount, contactCount, jointCount);
m_textLine += m_textIncrement;
int32 proxyCount = m_world->GetProxyCount();
int32 height = m_world->GetTreeHeight();
int32 balance = m_world->GetTreeBalance();
float quality = m_world->GetTreeQuality();
DrawString(5, m_textLine, "proxies/height/balance/quality = %d/%d/%d/%g", proxyCount, height, balance, quality);
g_debugDraw.DrawString(5, m_textLine, "proxies/height/balance/quality = %d/%d/%d/%g", proxyCount, height, balance, quality);
m_textLine += m_textIncrement;
}
// Track maximum profile times
@ -383,14 +375,22 @@ void Test::Step(Settings& settings)
aveProfile.broadphase = scale * m_totalProfile.broadphase;
}
DrawString(5, m_textLine, "step [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.step, aveProfile.step, m_maxProfile.step);
DrawString(5, m_textLine, "collide [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.collide, aveProfile.collide, m_maxProfile.collide);
DrawString(5, m_textLine, "solve [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solve, aveProfile.solve, m_maxProfile.solve);
DrawString(5, m_textLine, "solve init [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveInit, aveProfile.solveInit, m_maxProfile.solveInit);
DrawString(5, m_textLine, "solve velocity [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveVelocity, aveProfile.solveVelocity, m_maxProfile.solveVelocity);
DrawString(5, m_textLine, "solve position [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solvePosition, aveProfile.solvePosition, m_maxProfile.solvePosition);
DrawString(5, m_textLine, "solveTOI [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveTOI, aveProfile.solveTOI, m_maxProfile.solveTOI);
DrawString(5, m_textLine, "broad-phase [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.broadphase, aveProfile.broadphase, m_maxProfile.broadphase);
g_debugDraw.DrawString(5, m_textLine, "step [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.step, aveProfile.step, m_maxProfile.step);
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 += 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 += 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 += 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 += 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 += 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 += 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 += m_textIncrement;
}
if (m_bombSpawning)
@ -451,51 +451,3 @@ void Test::ShiftOrigin(const b2Vec2 & newOrigin)
{
m_world->ShiftOrigin(newOrigin);
}
void Test::initShader(void)
{
// initShader is unsupported
}
void Test::DrawString(int x, int y, const char* fmt, ...)
{
#if defined(CC_PLATFORM_PC)
debugString.append(std::string(fmt));
debugString.append("\n");
labelDebugDraw->setString(debugString);
// labelDebugDraw->setPosition(x, y);
#endif
}
void Test::DrawString(const b2Vec2& pw, const char* fmt, ...)
{
#if defined(CC_PLATFORM_PC)
debugString.append(std::string(fmt));
debugString.append("\n");
labelDebugDraw->setString(debugString);
// labelDebugDraw->setPosition(pw.x, pw.y);
#endif
}
void Test::DrawAABB(b2AABB* aabb, const b2Color& color)
{
b2Vec2 p1 = aabb->lowerBound;
b2Vec2 p2 = b2Vec2(aabb->upperBound.x, aabb->lowerBound.y);
b2Vec2 p3 = aabb->upperBound;
b2Vec2 p4 = b2Vec2(aabb->lowerBound.x, aabb->upperBound.y);
Vec2 verts[] = {
Vec2(p1.x * g_debugDraw.mRatio, p1.y * g_debugDraw.mRatio) + g_debugDraw.debugNodeOffset ,
Vec2(p2.x * g_debugDraw.mRatio, p2.y * g_debugDraw.mRatio) + g_debugDraw.debugNodeOffset ,
Vec2(p3.x * g_debugDraw.mRatio, p3.y * g_debugDraw.mRatio) + g_debugDraw.debugNodeOffset ,
Vec2(p4.x * g_debugDraw.mRatio, p4.y * g_debugDraw.mRatio) + g_debugDraw.debugNodeOffset ,
};
debugDrawNode->drawPolygon(verts, sizeof(verts) / sizeof(verts[0]), Color4F(color.r / 2, color.g / 2, color.b / 2, 0), 0.4f, Color4F(color.r, color.g, color.b, color.a));
}
void Test::Flush()
{
// Flush is unsupported
}

View File

@ -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;
};

View File

@ -169,8 +169,8 @@ public:
void Step(Settings& settings) override
{
DrawString(5, m_textLine, "Forward (W), Turn (A) and (D)");
g_debugDraw.DrawString(5, m_textLine, "Forward (W), Turn (A) and (D)");
m_textLine += m_textIncrement;
//if (glfwGetKey(g_mainWindow, GLFW_KEY_W) == GLFW_PRESS)
//{

View File

@ -146,8 +146,8 @@ public:
Test::Step(settings);
DrawString(5, m_textLine, "Keys: (d) dynamic, (s) static, (k) kinematic");
g_debugDraw.DrawString(5, m_textLine, "Keys: (d) dynamic, (s) static, (k) kinematic");
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -128,9 +128,9 @@ public:
void Step(Settings& settings) override
{
Test::Step(settings);
DrawString(5, m_textLine, "Press: (,) to launch a bullet.");
DrawString(5, m_textLine, "Blocksolve = %d", g_blockSolve);
g_debugDraw.DrawString(5, m_textLine, "Press: (,) to launch a bullet.");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Blocksolve = %d", g_blockSolve);
if (m_stepCount == 300)
{
if (m_bullet != NULL)

View File

@ -104,20 +104,20 @@ public:
if (b2_gjkCalls > 0)
{
DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",
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;
}
if (b2_toiCalls > 0)
{
DrawString(5, m_textLine, "toi calls = %d, ave toi iters = %3.1f, max toi iters = %d",
g_debugDraw.DrawString(5, m_textLine, "toi calls = %d, ave toi iters = %3.1f, max toi iters = %d",
b2_toiCalls, b2_toiIters / float(b2_toiCalls), b2_toiMaxRootIters);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d",
g_debugDraw.DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d",
b2_toiRootIters / float(b2_toiCalls), b2_toiMaxRootIters);
m_textLine += m_textIncrement;
}
if (m_stepCount % 60 == 0)

View File

@ -264,8 +264,8 @@ public:
void Step(Settings& settings) override
{
DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, hz down = q, hz up = e");
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_debugDraw.debugNodeOffset.x += m_car->GetPosition().x;

View File

@ -237,12 +237,12 @@ public:
m_character->SetLinearVelocity(v);
Test::Step(settings);
DrawString(5, m_textLine, "This tests various character collision shapes.");
DrawString(5, m_textLine, "Limitation: square and hexagon can snag on aligned boxes.");
DrawString(5, m_textLine, "Feature: edge chains have smooth collision inside and out.");
g_debugDraw.DrawString(5, m_textLine, "This tests various character collision shapes.");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Limitation: square and hexagon can snag on aligned boxes.");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Feature: edge chains have smooth collision inside and out.");
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -157,8 +157,8 @@ public:
}
}
DrawString(5, m_textLine, "Press 'c' to create a circle.");
g_debugDraw.DrawString(5, m_textLine, "Press 'c' to create a circle.");
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -118,9 +118,9 @@ public:
if (b2_gjkCalls > 0)
{
DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",
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;
@ -129,17 +129,17 @@ public:
if (b2_toiCalls > 0)
{
DrawString(5, m_textLine, "toi calls = %d, ave [max] toi iters = %3.1f [%d]",
g_debugDraw.DrawString(5, m_textLine, "toi calls = %d, ave [max] toi iters = %3.1f [%d]",
b2_toiCalls, b2_toiIters / float(b2_toiCalls), b2_toiMaxRootIters);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "ave [max] toi root iters = %3.1f [%d]",
g_debugDraw.DrawString(5, m_textLine, "ave [max] toi root iters = %3.1f [%d]",
b2_toiRootIters / float(b2_toiCalls), b2_toiMaxRootIters);
m_textLine += m_textIncrement;
DrawString(5, m_textLine, "ave [max] toi time = %.1f [%.1f] (microseconds)",
g_debugDraw.DrawString(5, m_textLine, "ave [max] toi time = %.1f [%.1f] (microseconds)",
1000.0f * b2_toiTime / float(b2_toiCalls), 1000.0f * b2_toiMaxTime);
m_textLine += m_textIncrement;
}
if (m_stepCount % 60 == 0)

View File

@ -77,15 +77,15 @@ public:
b2PolygonShape shape;
shape.Set(m_points, m_count);
DrawString(5, m_textLine, "Press g to generate a new random convex hull");
g_debugDraw.DrawString(5, m_textLine, "Press g to generate a new random convex hull");
m_textLine += m_textIncrement;
g_debugDraw.DrawPolygon(shape.m_vertices, shape.m_count, b2Color(0.9f, 0.9f, 0.9f));
for (int32 i = 0; i < m_count; ++i)
{
g_debugDraw.DrawPoint(m_points[i], 3.0f, b2Color(0.3f, 0.9f, 0.3f));
DrawString(m_points[i] + b2Vec2(0.05f, 0.05f), "%d", i);
g_debugDraw.DrawString(m_points[i] + b2Vec2(0.05f, 0.05f), "%d", i);
}
if (shape.Validate() == false)

View File

@ -63,11 +63,11 @@ public:
b2DistanceOutput output;
b2Distance(&output, &cache, &input);
DrawString(5, m_textLine, "distance = %g", output.distance);
DrawString(5, m_textLine, "iterations = %d", output.iterations);
g_debugDraw.DrawString(5, m_textLine, "distance = %g", output.distance);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "iterations = %d", output.iterations);
m_textLine += m_textIncrement;
{
b2Color color(0.9f, 0.9f, 0.9f);

View File

@ -71,8 +71,8 @@ public:
float ke = 0.5f * massData.mass * b2Dot(v, v) + 0.5f * massData.I * omega * omega;
DrawString(5, m_textLine, "kinetic energy = %.6f", ke);
g_debugDraw.DrawString(5, m_textLine, "kinetic energy = %.6f", ke);
m_textLine += m_textIncrement;
Test::Step(settings);
}

View File

@ -109,11 +109,11 @@ public:
c.Set(0.6f, 0.6f, 0.9f);
}
DrawAABB(&actor->aabb, c);
g_debugDraw.DrawAABB(&actor->aabb, c);
}
b2Color c(0.7f, 0.7f, 0.7f);
DrawAABB(&m_queryAABB, c);
g_debugDraw.DrawAABB(&m_queryAABB, c);
g_debugDraw.DrawSegment(m_rayCastInput.p1, m_rayCastInput.p2, c);
@ -131,8 +131,8 @@ public:
{
int32 height = m_tree.GetHeight();
DrawString(5, m_textLine, "dynamic tree height = %d", height);
g_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d", height);
m_textLine += m_textIncrement;
}
++m_stepCount;

View File

@ -205,8 +205,8 @@ public:
bool advanceRay = settings.m_pause == 0 || settings.m_singleStep;
Test::Step(settings);
DrawString(5, m_textLine, "Press 1-5 to drop stuff");
g_debugDraw.DrawString(5, m_textLine, "Press 1-5 to drop stuff");
m_textLine += m_textIncrement;
float L = 25.0f;
b2Vec2 point1(0.0f, 10.0f);

View File

@ -156,13 +156,13 @@ public:
ratio = m_joint4->GetRatio();
value = m_joint1->GetJointAngle() + ratio * m_joint2->GetJointAngle();
DrawString(5, m_textLine, "theta1 + %4.2f * theta2 = %4.2f", (float) ratio, (float) value);
g_debugDraw.DrawString(5, m_textLine, "theta1 + %4.2f * theta2 = %4.2f", (float) ratio, (float) value);
m_textLine += m_textIncrement;
ratio = m_joint5->GetRatio();
value = m_joint2->GetJointAngle() + ratio * m_joint3->GetJointTranslation();
DrawString(5, m_textLine, "theta2 + %4.2f * delta = %4.2f", (float) ratio, (float) value);
g_debugDraw.DrawString(5, m_textLine, "theta2 + %4.2f * delta = %4.2f", (float) ratio, (float) value);
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -101,7 +101,7 @@ public:
g_debugDraw.DrawPoint(linearOffset, 4.0f, b2Color(0.9f, 0.9f, 0.9f));
Test::Step(settings);
DrawString(5, m_textLine, "Keys: (s) pause");
g_debugDraw.DrawString(5, m_textLine, "Keys: (s) pause");
m_textLine += 15;
}

View File

@ -131,8 +131,8 @@ public:
Test::Step(settings);
DrawString(5, m_textLine, "Press 'a' to control the flippers");
g_debugDraw.DrawString(5, m_textLine, "Press 'a' to control the flippers");
m_textLine += m_textIncrement;
}

View File

@ -115,8 +115,8 @@ public:
Test::Step(settings);
b2Vec2 v = m_character->GetBody()->GetLinearVelocity();
DrawString(5, m_textLine, "Character Linear Velocity: %f", v.y);
g_debugDraw.DrawString(5, m_textLine, "Character Linear Velocity: %f", v.y);
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -55,8 +55,8 @@ public:
b2WorldManifold worldManifold;
worldManifold.Initialize(&manifold, m_transformA, m_polygonA.m_radius, m_transformB, m_polygonB.m_radius);
DrawString(5, m_textLine, "point count = %d", manifold.pointCount);
g_debugDraw.DrawString(5, m_textLine, "point count = %d", manifold.pointCount);
m_textLine += m_textIncrement;
{
b2Color color(0.9f, 0.9f, 0.9f);

View File

@ -243,12 +243,12 @@ public:
b2Color color(0.4f, 0.7f, 0.8f);
g_debugDraw.DrawCircle(callback.m_circle.m_p, callback.m_circle.m_radius, color);
DrawString(5, m_textLine, "Press 1-5 to drop stuff, maximum of %d overlaps detected", PolygonShapesCallback::e_maxCount);
DrawString(5, m_textLine, "Press 'a' to enable/disable some bodies");
DrawString(5, m_textLine, "Press 'd' to destroy a body");
g_debugDraw.DrawString(5, m_textLine, "Press 1-5 to drop stuff, maximum of %d overlaps detected", PolygonShapesCallback::e_maxCount);
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Press 'a' to enable/disable some bodies");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "Press 'd' to destroy a body");
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -100,8 +100,8 @@ public:
{
Test::Step(settings);
float force = m_joint->GetMotorForce(settings.m_hertz);
DrawString(5, m_textLine, "Motor Force = %4.0f", force);
g_debugDraw.DrawString(5, m_textLine, "Motor Force = %4.0f", force);
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -81,8 +81,8 @@ public:
float ratio = m_joint1->GetRatio();
float L = m_joint1->GetCurrentLengthA() + ratio * m_joint1->GetCurrentLengthB();
DrawString(5, m_textLine, "L1 + %4.2f * L2 = %4.2f", (float) ratio, (float) L);
g_debugDraw.DrawString(5, m_textLine, "L1 + %4.2f * L2 = %4.2f", (float) ratio, (float) L);
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -345,24 +345,24 @@ public:
{
Test::Step(settings);
DrawString(5, m_textLine, "Shape 1 is intentionally ignored by the ray");
g_debugDraw.DrawString(5, m_textLine, "Shape 1 is intentionally ignored by the ray");
m_textLine += m_textIncrement;
switch (m_mode)
{
case e_closest:
DrawString(5, m_textLine, "Ray-cast mode: closest - find closest fixture along the ray");
g_debugDraw.DrawString(5, m_textLine, "Ray-cast mode: closest - find closest fixture along the ray");
break;
case e_any:
DrawString(5, m_textLine, "Ray-cast mode: any - check for obstruction");
g_debugDraw.DrawString(5, m_textLine, "Ray-cast mode: any - check for obstruction");
break;
case e_multiple:
DrawString(5, m_textLine, "Ray-cast mode: multiple - gather multiple fixtures");
g_debugDraw.DrawString(5, m_textLine, "Ray-cast mode: multiple - gather multiple fixtures");
break;
}
m_textLine += m_textIncrement;
float angle = b2_pi * m_degrees / 180.0f;
float L = 11.0f;

View File

@ -138,12 +138,12 @@ public:
Test::Step(settings);
float torque1 = m_joint1->GetMotorTorque(settings.m_hertz);
DrawString(5, m_textLine, "Motor Torque 1= %4.0f", torque1);
g_debugDraw.DrawString(5, m_textLine, "Motor Torque 1= %4.0f", torque1);
m_textLine += m_textIncrement;
float torque2 = m_joint2->GetMotorTorque(settings.m_hertz);
DrawString(5, m_textLine, "Motor Torque 2= %4.0f", torque2);
g_debugDraw.DrawString(5, m_textLine, "Motor Torque 2= %4.0f", torque2);
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -263,8 +263,8 @@ public:
m_rope1.Draw(&g_debugDraw);
m_rope2.Draw(&g_debugDraw);
DrawString(5, m_textLine, "Press comma and period to move left and right");
g_debugDraw.DrawString(5, m_textLine, "Press comma and period to move left and right");
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -20,8 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef SETTINGS_H
#define SETTINGS_H
#pragma once
struct Settings
{
@ -82,5 +81,3 @@ struct Settings
bool m_pause;
bool m_singleStep;
};
#endif

View File

@ -120,9 +120,9 @@ public:
b2Distance(&distanceOutput, &simplexCache, &distanceInput);
DrawString(5, m_textLine, "hit = %s, iters = %d, lambda = %g, distance = %g",
g_debugDraw.DrawString(5, m_textLine, "hit = %s, iters = %d, lambda = %g, distance = %g",
hit ? "true" : "false", output.iterations, output.lambda, distanceOutput.distance);
m_textLine += m_textIncrement;
b2Vec2 vertices[b2_maxPolygonVertices];

View File

@ -88,10 +88,10 @@ public:
void Step(Settings& settings) override
{
Test::Step(settings);
DrawString(5, m_textLine, "Press: (c) create a shape, (d) destroy a shape.");
DrawString(5, m_textLine, "sensor = %d", m_sensor);
g_debugDraw.DrawString(5, m_textLine, "Press: (c) create a shape, (d) destroy a shape.");
m_textLine += m_textIncrement;
g_debugDraw.DrawString(5, m_textLine, "sensor = %d", m_sensor);
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -126,8 +126,8 @@ public:
void Step(Settings& settings) override
{
DrawString(5, m_textLine, "Keys: c = Camera fixed/tracking");
g_debugDraw.DrawString(5, m_textLine, "Keys: c = Camera fixed/tracking");
m_textLine += m_textIncrement;
if(!m_fixed_camera)
{

View File

@ -141,11 +141,11 @@ public:
void Step(Settings& settings) override
{
Test::Step(settings);
DrawString(5, m_textLine, "Keys: (f) toggle friction, (m) toggle motor");
g_debugDraw.DrawString(5, m_textLine, "Keys: (f) toggle friction, (m) toggle motor");
m_textLine += m_textIncrement;
float torque = m_joint1->GetMotorTorque(settings.m_hertz);
DrawString(5, m_textLine, "Motor Torque = %5.0f", (float) torque);
g_debugDraw.DrawString(5, m_textLine, "Motor Torque = %5.0f", (float) torque);
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -27,6 +27,8 @@
class Test;
struct Settings;
#define RAND_LIMIT 32767
#define DRAW_STRING_NEW_LINE 25
@ -111,15 +113,9 @@ public:
void ShiftOrigin(const b2Vec2& newOrigin);
void initShader(void);
void DrawString(int x, int y, const char* fmt, ...);
void DrawString(const b2Vec2& p, const char* fmt, ...);
void DrawAABB(b2AABB* aabb, const b2Color& color);
void Flush();
cocos2d::extension::PhysicsDebugNodeBox2D g_debugDraw;
DebugDraw g_debugDraw;
cocos2d::DrawNode* debugDrawNode;
std::string debugString = "";
b2World* m_world;

View File

@ -222,8 +222,8 @@ public:
void Step(Settings& settings) override
{
DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, toggle motor = m");
g_debugDraw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, toggle motor = m");
m_textLine += m_textIncrement;
Test::Step(settings);
}

View File

@ -130,14 +130,14 @@ public:
int32 leafCount = cm.m_broadPhase.GetProxyCount();
int32 minimumNodeCount = 2 * leafCount - 1;
float minimumHeight = ceilf(logf(float(minimumNodeCount)) / logf(2.0f));
DrawString(5, m_textLine, "dynamic tree height = %d, min = %d", height, int32(minimumHeight));
g_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d, min = %d", height, int32(minimumHeight));
m_textLine += m_textIncrement;
Test::Step(settings);
DrawString(5, m_textLine, "create time = %6.2f ms, fixture count = %d",
g_debugDraw.DrawString(5, m_textLine, "create time = %6.2f ms, fixture count = %d",
m_createTime, m_fixtureCount);
m_textLine += m_textIncrement;
//b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree;

View File

@ -69,12 +69,12 @@ public:
b2TimeOfImpact(&output, &input);
DrawString(5, m_textLine, "toi = %g", output.t);
g_debugDraw.DrawString(5, m_textLine, "toi = %g", output.t);
m_textLine += m_textIncrement;
extern B2_API int32 b2_toiMaxIters, b2_toiMaxRootIters;
DrawString(5, m_textLine, "max toi iters = %d, max root iters = %d", b2_toiMaxIters, b2_toiMaxRootIters);
g_debugDraw.DrawString(5, m_textLine, "max toi iters = %d, max root iters = %d", b2_toiMaxIters, b2_toiMaxRootIters);
m_textLine += m_textIncrement;
b2Vec2 vertices[b2_maxPolygonVertices];

View File

@ -190,8 +190,8 @@ public:
void Step(Settings& settings) override
{
Test::Step(settings);
DrawString(5, m_textLine, "Press: (b) to delete a body, (j) to delete a joint");
g_debugDraw.DrawString(5, m_textLine, "Press: (b) to delete a body, (j) to delete a joint");
m_textLine += m_textIncrement;
}
void JointDestroyed(b2Joint* joint) override

View File

@ -80,12 +80,12 @@ public:
Test::Step(settings);
float torque = m_joint->GetMotorTorque(settings.m_hertz);
DrawString(5, m_textLine, "Motor Torque = %4.0f", torque);
g_debugDraw.DrawString(5, m_textLine, "Motor Torque = %4.0f", torque);
m_textLine += m_textIncrement;
b2Vec2 F = m_joint->GetReactionForce(settings.m_hertz);
DrawString(5, m_textLine, "Reaction Force = (%4.1f, %4.1f)", F.x, F.y);
g_debugDraw.DrawString(5, m_textLine, "Reaction Force = (%4.1f, %4.1f)", F.x, F.y);
m_textLine += m_textIncrement;
}
void UpdateUI() override

View File

@ -143,13 +143,13 @@ public:
if (m_distanceJoint)
{
DrawString(5, m_textLine, "Distance Joint ON");
g_debugDraw.DrawString(5, m_textLine, "Distance Joint ON");
}
else
{
DrawString(5, m_textLine, "Distance Joint OFF");
g_debugDraw.DrawString(5, m_textLine, "Distance Joint OFF");
}
m_textLine += m_textIncrement;
}
static Test* Create()

View File

@ -57,7 +57,6 @@ SpriteFrameCachePixelFormatTest::SpriteFrameCachePixelFormatTest()
loadSpriteFrames("Images/sprite_frames_test/test_A8.plist", backend::PixelFormat::A8);
loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8);
loadSpriteFrames("Images/sprite_frames_test/test_AI88.plist", backend::PixelFormat::LA8);
loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8);
loadSpriteFrames("Images/sprite_frames_test/test_RGB565.plist", backend::PixelFormat::RGB565);
loadSpriteFrames("Images/sprite_frames_test/test_RGB888.plist", backend::PixelFormat::RGB8);
loadSpriteFrames("Images/sprite_frames_test/test_RGBA4444.plist", backend::PixelFormat::RGBA4);
@ -80,7 +79,7 @@ SpriteFrameCachePixelFormatTest::SpriteFrameCachePixelFormatTest()
void SpriteFrameCachePixelFormatTest::loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat)
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file);
SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png");
SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("sprite_frames_test/grossini.png");
Texture2D *texture = spriteFrame->getTexture();
const ssize_t bitsPerKB = 8 * 1024;
const double memorySize = 1.0 * texture->getBitsPerPixelForFormat() * texture->getContentSizeInPixels().width * texture->getContentSizeInPixels().height / bitsPerKB;
@ -110,11 +109,11 @@ SpriteFrameCacheLoadMultipleTimes::SpriteFrameCacheLoadMultipleTimes()
void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat)
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file);
SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png");
SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("sprite_frames_test/grossini.png");
Texture2D *texture = spriteFrame->getTexture();
CC_ASSERT(texture->getPixelFormat() == expectedFormat);
SpriteFrameCache::getInstance()->removeSpriteFrameByName("grossini.png");
SpriteFrameCache::getInstance()->removeSpriteFrameByName("sprite_frames_test/grossini.png");
Director::getInstance()->getTextureCache()->removeTexture(texture);
}
@ -491,7 +490,7 @@ SpriteFrameCacheJsonAtlasTest::~SpriteFrameCacheJsonAtlasTest()
void SpriteFrameCacheJsonAtlasTest::loadSpriteFrames(const std::string& file, cocos2d::backend::PixelFormat expectedFormat)
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file, GenericJsonArraySpriteSheetLoader::FORMAT);
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png");
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("sprite_frames_test/grossini.png");
Texture2D* texture = spriteFrame->getTexture();
const ssize_t bitsPerKB = 8 * 1024;
const double memorySize = 1.0 * texture->getBitsPerPixelForFormat() * texture->getContentSizeInPixels().width * texture->getContentSizeInPixels().height / bitsPerKB;

View File

@ -123,7 +123,7 @@ void SpritePolygonTestCase::updateDrawNode()
//draw 3 lines
Vec3 from = verts[indices[i*3]].vertices;
Vec3 to = verts[indices[i*3+1]].vertices;
drawnode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::BLUE);
drawnode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
from = verts[indices[i*3+1]].vertices;
to = verts[indices[i*3+2]].vertices;
@ -131,7 +131,7 @@ void SpritePolygonTestCase::updateDrawNode()
from = verts[indices[i*3+2]].vertices;
to = verts[indices[i*3]].vertices;
drawnode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::RED);
drawnode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
}
}
}
@ -791,7 +791,7 @@ void SpritePolygonTestFrameAnim::initSprites()
_drawNodes.pushBack(spDrawNode);
}
updateDrawNode();
Vector<SpriteFrame*> animFrames(5);
@ -803,8 +803,6 @@ void SpritePolygonTestFrameAnim::initSprites()
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
updateDrawNode();
}
//

View File

@ -5627,7 +5627,7 @@ SpriteSlice9Test10::SpriteSlice9Test10()
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist");
auto s1 = Sprite::createWithSpriteFrameName("blocks9r.png");
auto s1 = Sprite::createWithSpriteFrameName("blocks9ss/blocks9r.png");
addChild(s1);
s1->setPosition(s.width/2-s.width/3, s.height/2);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
@ -5635,7 +5635,7 @@ SpriteSlice9Test10::SpriteSlice9Test10()
s1->setContentSize(s1->getContentSize()*1.5);
s1->setFlippedX(true);
auto s2 = Sprite::createWithSpriteFrameName("blocks9r.png");
auto s2 = Sprite::createWithSpriteFrameName("blocks9ss/blocks9r.png");
addChild(s2);
s2->setPosition(s.width*2/4, s.height/2);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
@ -5643,7 +5643,7 @@ SpriteSlice9Test10::SpriteSlice9Test10()
s2->setContentSize(s2->getContentSize()*1.5);
//Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::createWithSpriteFrameName("blocks9r.png");
auto s3 = Sprite::createWithSpriteFrameName("blocks9ss/blocks9r.png");
addChild(s3);
s3->setPosition(s.width/2+s.width/3, s.height/2);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
@ -5666,7 +5666,7 @@ Issue17119::Issue17119()
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist");
auto s1 = Sprite::createWithSpriteFrameName("firstPic.png");
auto s1 = Sprite::createWithSpriteFrameName("issue_17119/firstPic.png");
addChild(s1);
s1->setPosition(s.width/2-s.width/3, s.height/2);
s1->setScale(0.25f);
@ -5675,7 +5675,7 @@ Issue17119::Issue17119()
p1->setPosition(s1->getPosition());
addChild(p1, 10);
auto s2 = Sprite::createWithSpriteFrameName("blocks9r.png");
auto s2 = Sprite::createWithSpriteFrameName("blocks9ss/blocks9r.png");
addChild(s2);
s2->setPosition(s.width/2, s.height/2);
s2->setCenterRectNormalized(Rect(1/3.f, 1/3.f, 1/3.f, 1/3.f));

View File

@ -1230,7 +1230,7 @@ bool Issue17116::init()
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/issue_17116.plist");
auto button = ui::Button::create();
button->loadTextureNormal("buttons/play-big", ui::Widget::TextureResType::PLIST);
button->loadTextureNormal("issue_17116/buttons/play-big", ui::Widget::TextureResType::PLIST);
button->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
button->setOpacity(100);
addChild(button);

View File

@ -244,7 +244,7 @@ bool UIImageViewFlipTest::init()
_uiLayer->addChild(alert);
// Create the imageview
ImageView* imageView = ImageView::create("blocks9r.png", Widget::TextureResType::PLIST);
ImageView* imageView = ImageView::create("blocks9ss/blocks9r.png", Widget::TextureResType::PLIST);
imageView->setScale9Enabled(true);
imageView->setContentSize(Size(250, 115));
imageView->setFlippedX(true);
@ -296,7 +296,7 @@ bool UIImageViewIssue12249Test::init()
_uiLayer->addChild(alert);
// Create the imageview
ImageView* imageView = ImageView::create("blocks9r.png", Widget::TextureResType::PLIST);
ImageView* imageView = ImageView::create("blocks9ss/blocks9r.png", Widget::TextureResType::PLIST);
imageView->setScale9Enabled(true);
imageView->setContentSize(Size(250, imageView->getContentSize().height * 2));
imageView->setFlippedX(true);

View File

@ -305,7 +305,7 @@ bool UIS9FrameNameSpriteSheet::init()
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s_s9s_blocks9_plist);
auto blocks = ui::Scale9Sprite::createWithSpriteFrameName("blocks9.png");
auto blocks = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9.png");
blocks->setInsetLeft(0);
blocks->setInsetRight(0);
blocks->setInsetTop(0);
@ -480,7 +480,7 @@ bool UIS9FrameNameSpriteSheetScaledNoInsets::init()
float y = 0 + (winSize.height / 2);
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s_s9s_blocks9_plist);
auto blocks_scaled = ui::Scale9Sprite::createWithSpriteFrameName("blocks9.png");
auto blocks_scaled = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9.png");
blocks_scaled->setPosition(Vec2(x, y));
@ -551,7 +551,7 @@ bool UIS9FrameNameSpriteSheetInsets::init()
float y = 0 + (winSize.height / 2);
auto blocks_with_insets = ui::Scale9Sprite::createWithSpriteFrameName("blocks9.png", Rect(32, 32, 32, 32));
auto blocks_with_insets = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9.png", Rect(32, 32, 32, 32));
blocks_with_insets->setPosition(Vec2(x, y));
@ -570,7 +570,7 @@ bool UIS9FrameNameSpriteSheetInsetsScaled::init()
float x = winSize.width / 2;
float y = 0 + (winSize.height / 2);
auto blocks_scaled_with_insets = ui::Scale9Sprite::createWithSpriteFrameName("blocks9.png", Rect(32, 32, 32, 32));
auto blocks_scaled_with_insets = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9.png", Rect(32, 32, 32, 32));
blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5));
@ -642,7 +642,7 @@ bool UIS9FrameNameSpriteSheetRotatedInsetsScaled::init()
float x = winSize.width / 2;
float y = 0 + (winSize.height / 2);
auto blocks_scaled_with_insets = ui::Scale9Sprite::createWithSpriteFrameName("blocks9.png", Rect(32, 32, 32, 32));
auto blocks_scaled_with_insets = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9.png", Rect(32, 32, 32, 32));
blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5));
@ -988,7 +988,7 @@ bool UIS9BatchTest::init()
this->addChild(label);
auto preferedSize = Size(150.0f,99.0f);
std::vector<std::string> spriteFrameNameArray = {"blocks9.png", "blocks9r.png"};
std::vector<std::string> spriteFrameNameArray = {"blocks9ss/blocks9.png", "blocks9ss/blocks9r.png"};
auto addSpriteButton = ui::Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
addSpriteButton->setPosition(Vec2(winSize.width/2 - 50,winSize.height - 100));
addSpriteButton->setTitleText("Add Normal Sprite");