mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Fix Box2D JSB normalImpulses/tangentImpulses properties were not bound. (#18546)
This commit is contained in:
@@ -29,19 +29,19 @@ bool js_b2World_SetContactListener(se::State& s)
|
||||
size_t argc = args.size();
|
||||
b2World *arg1 = (b2World *) NULL ;
|
||||
JSB_b2ContactListener *arg2 = (JSB_b2ContactListener *) NULL ;
|
||||
|
||||
|
||||
if(argc != 1) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<b2World>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg2, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
(arg1)->SetContactListener(arg2);
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_b2World_SetContactListener)
|
||||
@@ -53,19 +53,19 @@ bool js_b2World_SetDebugDraw(se::State& s)
|
||||
size_t argc = args.size();
|
||||
b2World *arg1 = (b2World *) NULL ;
|
||||
JSBB2Draw *arg2 = (JSBB2Draw *) NULL ;
|
||||
|
||||
|
||||
if(argc != 1) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<b2World>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg2, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
(arg1)->SetDebugDraw(arg2);
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_b2World_SetDebugDraw)
|
||||
@@ -79,24 +79,24 @@ bool js_b2World_QueryAABB(se::State& s)
|
||||
JSBQueryCallback *arg2 = (JSBQueryCallback *) NULL ;
|
||||
b2AABB *arg3 = 0 ;
|
||||
b2AABB temp3 ;
|
||||
|
||||
|
||||
if(argc != 2) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<b2World>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg2, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
|
||||
ok &= sevalue_to_native(args[1], &temp3, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
arg3 = &temp3;
|
||||
|
||||
|
||||
((b2World const *)arg1)->QueryAABB(arg2,(b2AABB const &)*arg3);
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_b2World_QueryAABB)
|
||||
@@ -112,29 +112,29 @@ bool js_b2World_RayCast(se::State& s)
|
||||
b2Vec2 *arg4 = 0 ;
|
||||
b2Vec2 temp3 ;
|
||||
b2Vec2 temp4 ;
|
||||
|
||||
|
||||
if(argc != 3) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 3);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<b2World>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg2, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
|
||||
ok &= sevalue_to_native(args[1], &temp3, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
arg3 = &temp3;
|
||||
|
||||
|
||||
|
||||
|
||||
ok &= sevalue_to_native(args[2], &temp4, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
arg4 = &temp4;
|
||||
|
||||
|
||||
((b2World const *)arg1)->RayCast(arg2,(b2Vec2 const &)*arg3,(b2Vec2 const &)*arg4);
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_b2World_RayCast)
|
||||
@@ -145,20 +145,20 @@ bool js_Contact_GetWorldManifold(se::State& s)
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
b2Contact *arg1 = (b2Contact *) NULL ;
|
||||
|
||||
|
||||
if(argc != 1) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<b2Contact>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
|
||||
b2WorldManifold worldManifold;
|
||||
|
||||
|
||||
((b2Contact const *)arg1)->GetWorldManifold(&worldManifold);
|
||||
|
||||
|
||||
se::Object *worldManifoldObj = args[0].toObject();
|
||||
|
||||
|
||||
{
|
||||
se::Value normal;
|
||||
worldManifoldObj->getProperty("normal", &normal);
|
||||
@@ -167,7 +167,7 @@ bool js_Contact_GetWorldManifold(se::State& s)
|
||||
normal.toObject()->setProperty("y", se::Value(worldManifold.normal.y));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
se::Value points;
|
||||
worldManifoldObj->getProperty("points", &points);
|
||||
@@ -182,7 +182,7 @@ bool js_Contact_GetWorldManifold(se::State& s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
se::Value separations;
|
||||
worldManifoldObj->getProperty("separations", &separations);
|
||||
@@ -193,10 +193,10 @@ bool js_Contact_GetWorldManifold(se::State& s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_Contact_GetWorldManifold)
|
||||
SE_BIND_FUNC(js_Contact_GetWorldManifold)
|
||||
|
||||
bool js_b2PolygonShape_Set(se::State& s) {
|
||||
CC_UNUSED bool ok = true;
|
||||
@@ -205,10 +205,10 @@ bool js_b2PolygonShape_Set(se::State& s) {
|
||||
if (argc != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
b2PolygonShape *arg1 = SE_THIS_OBJECT<b2PolygonShape>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
|
||||
int32 count = 0;
|
||||
ok = sevalue_to_native(args[1], &count, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
@@ -246,7 +246,7 @@ bool js_Body_GetTransformJSB(void *s) // NOLINT(readability-identifier-naming)
|
||||
auto *cobj = reinterpret_cast<b2Body *>(s);
|
||||
const auto &pos = cobj->GetPosition();
|
||||
float angle = cobj->GetAngle();
|
||||
|
||||
|
||||
tempFloatArray[0] = pos.x;
|
||||
tempFloatArray[1] = pos.y;
|
||||
tempFloatArray[2] = angle;
|
||||
@@ -278,6 +278,38 @@ bool js_Body_SetAngleJSB(void *s) // NOLINT(readability-identifier-naming)
|
||||
}
|
||||
SE_BIND_FUNC_FAST(js_Body_SetAngleJSB)
|
||||
|
||||
bool js_ContactImpulse_normalImpulses_get(se::State &s) {
|
||||
b2ContactImpulse *cobj = SE_THIS_OBJECT<b2ContactImpulse>(s);
|
||||
if (nullptr == cobj) return true;
|
||||
|
||||
static ccstd::array<float, b2_maxManifoldPoints> normalImpulses;
|
||||
for (size_t i = 0; i < b2_maxManifoldPoints; ++i) {
|
||||
normalImpulses[i] = cobj->normalImpulses[i];
|
||||
}
|
||||
|
||||
bool ok = nativevalue_to_se(normalImpulses, s.rval());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_ContactImpulse_normalImpulses_get)
|
||||
|
||||
bool js_ContactImpulse_tangentImpulses_get(se::State &s) {
|
||||
b2ContactImpulse *cobj = SE_THIS_OBJECT<b2ContactImpulse>(s);
|
||||
if (nullptr == cobj) return true;
|
||||
|
||||
static ccstd::array<float, b2_maxManifoldPoints> tangentImpulses;
|
||||
for (size_t i = 0; i < b2_maxManifoldPoints; ++i) {
|
||||
tangentImpulses[i] = cobj->tangentImpulses[i];
|
||||
}
|
||||
|
||||
bool ok = nativevalue_to_se(tangentImpulses, s.rval());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_ContactImpulse_tangentImpulses_get)
|
||||
|
||||
} // namespace {
|
||||
|
||||
bool register_all_box2d_manual(se::Object *obj) { // NOLINT
|
||||
@@ -288,29 +320,32 @@ bool register_all_box2d_manual(se::Object *obj) { // NOLINT
|
||||
nsVal.setObject(jsobj);
|
||||
obj->setProperty("b2jsb", nsVal);
|
||||
}
|
||||
|
||||
|
||||
se::Object *nsObj = nsVal.toObject();
|
||||
|
||||
|
||||
__jsb_b2PolygonShape_proto->defineFunction("Set", _SE(js_b2PolygonShape_Set));
|
||||
__jsb_b2World_proto->defineFunction("SetDebugDraw", _SE(js_b2World_SetDebugDraw));
|
||||
__jsb_b2World_proto->defineFunction("SetContactListener", _SE(js_b2World_SetContactListener));
|
||||
__jsb_b2World_proto->defineFunction("QueryAABB", _SE(js_b2World_QueryAABB));
|
||||
__jsb_b2World_proto->defineFunction("RayCast", _SE(js_b2World_RayCast));
|
||||
|
||||
|
||||
__jsb_b2Contact_proto->defineFunction("GetWorldManifold", _SE(js_Contact_GetWorldManifold));
|
||||
|
||||
|
||||
nsVal.toObject()->defineFunction("_setTempFloatArray", _SE(js_b2_setTempFloatArray));
|
||||
|
||||
|
||||
__jsb_b2Body_proto->defineFunction("_GetTransformJSB", _SE(js_Body_GetTransformJSB));
|
||||
|
||||
__jsb_b2Body_proto->defineFunction("_SetTransformJSB", _SE(js_Body_SetTransformJSB));
|
||||
__jsb_b2Body_proto->defineFunction("_SetPositionJSB", _SE(js_Body_SetPositionJSB));
|
||||
__jsb_b2Body_proto->defineFunction("_SetAngleJSB", _SE(js_Body_SetAngleJSB));
|
||||
|
||||
|
||||
__jsb_b2ContactImpulse_proto->defineProperty("normalImpulses", _SE(js_ContactImpulse_normalImpulses_get), nullptr);
|
||||
__jsb_b2ContactImpulse_proto->defineProperty("tangentImpulses", _SE(js_ContactImpulse_tangentImpulses_get), nullptr);
|
||||
|
||||
nsObj->setProperty("maxFloat", se::Value(b2_maxFloat));
|
||||
nsObj->setProperty("epsilon", se::Value(b2_epsilon));
|
||||
nsObj->setProperty("pi", se::Value(b2_pi));
|
||||
|
||||
|
||||
nsObj->setProperty("maxManifoldPoints", se::Value(b2_maxManifoldPoints));
|
||||
nsObj->setProperty("maxPolygonVertices", se::Value(b2_maxPolygonVertices));
|
||||
nsObj->setProperty("aabbExtension", se::Value(b2_aabbExtension));
|
||||
@@ -332,6 +367,6 @@ bool register_all_box2d_manual(se::Object *obj) { // NOLINT
|
||||
nsObj->setProperty("timeToSleep", se::Value(b2_timeToSleep));
|
||||
nsObj->setProperty("linearSleepTolerance", se::Value(b2_linearSleepTolerance));
|
||||
nsObj->setProperty("angularSleepTolerance", se::Value(b2_angularSleepTolerance));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user