From 9998adcecd5b36c3d57ce65bc0a47cfc5b3121e4 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 5 Aug 2023 17:02:30 +0800 Subject: [PATCH] ... --- 3rd/box2d/include/box2d_bindings.hpp | 44 ++++++---------------------- 3rd/box2d/src/box2d_Body.cpp | 3 -- 3rd/box2d/src/box2d_DebugDraw.cpp | 33 +++++++++++++++++++++ 3rd/box2d/src/box2d_World.cpp | 15 ++++++++-- 4 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 3rd/box2d/src/box2d_DebugDraw.cpp diff --git a/3rd/box2d/include/box2d_bindings.hpp b/3rd/box2d/include/box2d_bindings.hpp index d1c29e06..502a5d74 100644 --- a/3rd/box2d/include/box2d_bindings.hpp +++ b/3rd/box2d/include/box2d_bindings.hpp @@ -1,8 +1,6 @@ #pragma once -#include "box2d/b2_world.h" #include "box2d/box2d.h" -#include "pocketpy/common.h" #include "pocketpy/pocketpy.h" namespace pkpy{ @@ -33,30 +31,17 @@ struct PyDebugDraw: b2Draw{ PK_ALWAYS_PASS_BY_POINTER(PyDebugDraw) VM* vm; - PyObject* draw_like; + PyObject* draw_like; // world will mark this PyDebugDraw(VM* vm): vm(vm){} - void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override{ - } - - void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override{ - } - - void DrawCircle(const b2Vec2& center, float radius, const b2Color& color) override{ - } - - void DrawSolidCircle(const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color) override{ - } - - void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) override{ - } - - void DrawTransform(const b2Transform& xf) override{ - } - - void DrawPoint(const b2Vec2& p, float size, const b2Color& color) override{ - } + void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override; + void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override; + void DrawCircle(const b2Vec2& center, float radius, const b2Color& color) override; + void DrawSolidCircle(const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color) override; + void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) override; + void DrawTransform(const b2Transform& xf) override; + void DrawPoint(const b2Vec2& p, float size, const b2Color& color) override; }; struct PyContactListener: b2ContactListener{ @@ -64,18 +49,7 @@ struct PyContactListener: b2ContactListener{ VM* vm; PyContactListener(VM* vm): vm(vm){} - void _contact_f(b2Contact* contact, StrName name){ - b2Body* bodyA = contact->GetFixtureA()->GetBody(); - b2Body* bodyB = contact->GetFixtureB()->GetBody(); - PyObject* a = get_body_object(bodyA); - PyObject* b = get_body_object(bodyB); - PyObject* self; - PyObject* f; - f = vm->get_unbound_method(a, name, &self, false); - if(f != nullptr) vm->call_method(self, f, b); - f = vm->get_unbound_method(b, name, &self, false); - if(f != nullptr) vm->call_method(self, f, a); - } + void _contact_f(b2Contact* contact, StrName name); void BeginContact(b2Contact* contact) override { DEF_SNAME(on_contact_begin); diff --git a/3rd/box2d/src/box2d_Body.cpp b/3rd/box2d/src/box2d_Body.cpp index 29d69c52..e2c92d4f 100644 --- a/3rd/box2d/src/box2d_Body.cpp +++ b/3rd/box2d/src/box2d_Body.cpp @@ -1,7 +1,4 @@ -#include "box2d/b2_world.h" -#include "box2d/b2_world_callbacks.h" #include "box2d_bindings.hpp" -#include "pocketpy/bindings.h" namespace pkpy{ diff --git a/3rd/box2d/src/box2d_DebugDraw.cpp b/3rd/box2d/src/box2d_DebugDraw.cpp new file mode 100644 index 00000000..9f620cc8 --- /dev/null +++ b/3rd/box2d/src/box2d_DebugDraw.cpp @@ -0,0 +1,33 @@ +#include "box2d_bindings.hpp" + +namespace pkpy{ + +void PyDebugDraw::DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color){ + +} + +void PyDebugDraw::DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color){ + +} + +void PyDebugDraw::DrawCircle(const b2Vec2& center, float radius, const b2Color& color){ + +} + +void PyDebugDraw::DrawSolidCircle(const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color){ + +} + +void PyDebugDraw::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color){ + +} + +void PyDebugDraw::DrawTransform(const b2Transform& xf){ + +} + +void PyDebugDraw::DrawPoint(const b2Vec2& p, float size, const b2Color& color){ + +} + +} \ No newline at end of file diff --git a/3rd/box2d/src/box2d_World.cpp b/3rd/box2d/src/box2d_World.cpp index c9c757aa..8d4ee205 100644 --- a/3rd/box2d/src/box2d_World.cpp +++ b/3rd/box2d/src/box2d_World.cpp @@ -1,5 +1,3 @@ -#include "box2d/b2_world.h" -#include "box2d/b2_world_callbacks.h" #include "box2d_bindings.hpp" namespace pkpy{ @@ -31,6 +29,19 @@ struct MyBoxCastCallback: b2QueryCallback{ } }; +void PyContactListener::_contact_f(b2Contact* contact, StrName name){ + PyObject* a = get_body_object(contact->GetFixtureA()->GetBody()); + PyObject* b = get_body_object(contact->GetFixtureB()->GetBody()); + PyBody& bodyA = PK_OBJ_GET(PyBody, a); + PyBody& bodyB = PK_OBJ_GET(PyBody, b); + PyObject* self; + PyObject* f; + f = vm->get_unbound_method(bodyA.node_like, name, &self, false); + if(f != nullptr) vm->call_method(self, f, b); + f = vm->get_unbound_method(bodyB.node_like, name, &self, false); + if(f != nullptr) vm->call_method(self, f, a); +} + /****************** PyWorld ******************/ PyWorld::PyWorld(VM* vm): world(b2Vec2(0, 0)), _contact_listener(vm), _debug_draw(vm){ _debug_draw.draw_like = vm->None;