[deploy] Merge pull request #43 from KiwanoEngine/dev

Update ContactListener
This commit is contained in:
Haibo 2019-11-01 23:31:09 +08:00 committed by GitHub
commit 813b82ccc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 8 deletions

View File

@ -63,7 +63,7 @@ namespace kiwano
PhysicFixture AddChainShape(Vector<Point> const& vertexs, bool loop, float density = 0.f);
// 삿혤셸야
PhysicFixture GetFixtureList() const { KGE_ASSERT(body_); PhysicFixture(body_->GetFixtureList()); }
PhysicFixture GetFixtureList() const { KGE_ASSERT(body_); return PhysicFixture(body_->GetFixtureList()); }
// 盧뇜셸야
void RemoveFixture(PhysicFixture const& fixture);

View File

@ -63,7 +63,7 @@ namespace kiwano
void PhysicContactDispatcher::StartContactListeners(String const& listener_name)
{
for (auto listener = listeners_.first_item(); listener; listener = listener->next_item())
for (auto listener : listeners_)
{
if (listener->IsName(listener_name))
{
@ -74,7 +74,7 @@ namespace kiwano
void PhysicContactDispatcher::StopContactListeners(String const& listener_name)
{
for (auto listener = listeners_.first_item(); listener; listener = listener->next_item())
for (auto listener : listeners_)
{
if (listener->IsName(listener_name))
{
@ -97,6 +97,27 @@ namespace kiwano
}
}
void PhysicContactDispatcher::StartAllContactListeners()
{
for (auto listener : listeners_)
{
listener->Start();
}
}
void PhysicContactDispatcher::StopAllContactListeners()
{
for (auto listener : listeners_)
{
listener->Stop();
}
}
void PhysicContactDispatcher::RemoveAllContactListeners()
{
listeners_.clear();
}
void PhysicContactDispatcher::OnContactBegin(b2Contact* b2contact)
{
if (listeners_.empty())

View File

@ -120,6 +120,15 @@ namespace kiwano
String const& listener_name
);
// 启动所有监听器
void StartAllContactListeners();
// 停止所有监听器
void StopAllContactListeners();
// 移除所有监听器
void RemoveAllContactListeners();
protected:
void OnContactBegin(b2Contact* contact);

View File

@ -102,6 +102,8 @@ namespace kiwano
contact_listener_ = nullptr;
}
RemoveAllContactListeners();
// Make sure b2World was destroyed after b2Body
RemoveAllChildren();
RemoveAllBodies();
@ -110,12 +112,9 @@ namespace kiwano
void PhysicWorld::RemoveBody(PhysicBody* body)
{
if (body)
if (body && body->GetB2Body())
{
if (body->GetB2Body())
{
world_.DestroyBody(body->GetB2Body());
}
world_.DestroyBody(body->GetB2Body());
}
}