Style guide fixes

This commit is contained in:
viktorljung
2015-09-28 17:19:45 +02:00
parent ad299ad2e5
commit 1a0201ee98
7 changed files with 84 additions and 1285 deletions
+33 -78
View File
@@ -3,19 +3,20 @@
#include <unordered_map>
#include <Box2D/Box2D.h>
#include "Core/System.h"
#include "Core/World.h"
#include "CRectangleShape.h"
#include "Physics/CPhysics.h"
#include <Box2D/Box2D.h>
#include "Core/EventBroker.h"
#include "Core/CTransform.h"
#include "Transform/TransformSystem.h"
#include "CRectangleShape.h"
#include "Physics/CPhysics.h"
#include "Physics/EContact.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CCircleShape.h"
#include "Core/EventBroker.h"
#include "Game/CPad.h"
#include "Physics/CWaterVolume.h"
#include "Game/CPad.h"
#include "Game/CBall.h"
#include "Rendering/CSprite.h"
@@ -26,66 +27,55 @@ namespace dd
namespace Systems
{
class PhysicsSystem : public System
{
friend class ContractListener;
public:
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker) {}
: System(world, eventBroker) { }
~PhysicsSystem();
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &event);
void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override;
// Called once per system every tick
void Update(double dt) override;
// Called once for every entity in the world every tick
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
// Called when components are committed to an entity
void OnEntityCommit(EntityID entity) override;
// Called when an entity is removed
void OnEntityRemoved(EntityID entity) override;
private:
b2Vec2 m_Gravity;
b2World* m_PhysicsWorld;
float m_TimeStep;
float m_Accumulator;
int m_VelocityIterations, m_PositionIterations;
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
void CreateBody(EntityID entity);
b2ParticleSystem *m_ParticleSystem;
b2ParticleGroup* t_watergroup;
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToParticleHandle;
std::unordered_map<const b2ParticleHandle*, EntityID> m_ParticleHandleToEntities;
void InitializeWater();
void SyncWater(); //TODO: Probably remove this
void CreateParticleGroup(EntityID entity);
struct Impulse
{
b2Body* Body;
b2Vec2 Impulse;
b2Vec2 Point;
};
b2Vec2 m_Gravity = b2Vec2(0.f, -9.82f);
b2World* m_PhysicsWorld = nullptr;
float m_TimeStep = 1.f/60.f;
float m_Accumulator = 0.f;
int m_VelocityIterations = 6;
int m_PositionIterations = 2;
b2ParticleSystem *m_ParticleSystem;
b2ParticleGroup* t_watergroup;
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToParticleHandle;
std::unordered_map<const b2ParticleHandle*, EntityID> m_ParticleHandleToEntities;
std::list<Impulse> m_Impulses;
void CreateBody(EntityID entity);
void InitializeWater();
void SyncWater(); //TODO: Probably remove this
void CreateParticleGroup(EntityID entity);
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &event);
class ContactListener : public b2ContactListener
{
@@ -93,45 +83,10 @@ private:
ContactListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
void BeginContact(b2Contact* contact)
{
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
Events::Contact e;
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
m_PhysicsSystem->EventBroker->Publish(e);
}
void EndContact(b2Contact* contact)
{
}
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
// Turn of collisions
contact->SetEnabled(false);
}
}
}
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
{
}
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
private:
PhysicsSystem* m_PhysicsSystem;
-149
View File
@@ -1,149 +0,0 @@
#ifndef DAYDREAM_PHYSICSSYSTEM_H
#define DAYDREAM_PHYSICSSYSTEM_H
#include <unordered_map>
#include "Core/System.h"
#include "Core/World.h"
#include "CRectangleShape.h"
#include "Physics/CPhysics.h"
#include <Box2D/Box2D.h>
#include "Core/CTransform.h"
#include "Transform/TransformSystem.h"
#include "Physics/EContact.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CCircleShape.h"
#include "Core/EventBroker.h"
#include "Game/CPad.h"
<<<<<<< HEAD
#include "Game/CBall.h"
=======
#include "Physics/CWaterVolume.h"
#include "Rendering/CSprite.h"
>>>>>>> origin/master
namespace dd
{
namespace Systems
{
class PhysicsSystem : public System
{
friend class ContractListener;
public:
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker) {}
~PhysicsSystem();
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &event);
void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override;
// Called once per system every tick
void Update(double dt) override;
// Called once for every entity in the world every tick
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
// Called when components are committed to an entity
void OnEntityCommit(EntityID entity) override;
// Called when an entity is removed
void OnEntityRemoved(EntityID entity) override;
private:
b2Vec2 m_Gravity;
b2World* m_PhysicsWorld;
float m_TimeStep;
float m_Accumulator;
int m_VelocityIterations, m_PositionIterations;
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
void CreateBody(EntityID entity);
b2ParticleSystem *m_ParticleSystem;
b2ParticleGroup* t_watergroup;
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToParticleHandle;
std::unordered_map<const b2ParticleHandle*, EntityID> m_ParticleHandleToEntities;
void InitializeWater();
void SyncWater(); //TODO: Probably remove this
void CreateParticleGroup(EntityID entity);
struct Impulse
{
b2Body* Body;
b2Vec2 Impulse;
b2Vec2 Point;
};
std::list<Impulse> m_Impulses;
class ContactListener : public b2ContactListener
{
public:
ContactListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
void BeginContact(b2Contact* contact)
{
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
Events::Contact e;
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
m_PhysicsSystem->EventBroker->Publish(e);
}
void EndContact(b2Contact* contact)
{
}
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
// Turn of collisions
contact->SetEnabled(false);
}
}
}
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
{
}
private:
PhysicsSystem* m_PhysicsSystem;
};
ContactListener* m_ContactListener;
};
}
}
#endif //DAYDREAM_PHYSICSSYSTEM_H
-372
View File
@@ -1,372 +0,0 @@
//
// Created by Adniklastrator on 2015-09-09.
//
#include "PrecompiledHeader.h"
#include "Game/LevelSystem.h"
void dd::Systems::LevelSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::OnLifeLost);
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::OnScoreEvent);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, LevelSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, LevelSystem::OnCreatePowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, LevelSystem::OnPowerUpTaken);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, LevelSystem::OnStageCleared);
for (int i = 0; i < Lives(); i++) {
CreateLife(i);
}
return;
}
void dd::Systems::LevelSystem::CreateLife(int number)
{
auto life = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->Number = number;
auto model = m_World->AddComponent<Components::Model>(life);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
m_World->CommitEntity(life);
}
void dd::Systems::LevelSystem::Update(double dt)
{
if (!m_Initialized) {
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
m_Initialized = true;
}
if (Lives() < 0)
{
SetLives(3);
Events::GameOver e;
EventBroker->Publish(e);
}
}
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (ball != nullptr) {
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (glm::abs(transformBall->Velocity.y) < 2) {
if (transformBall->Velocity.y > 0) {
transformBall->Velocity.y = 2;
} else {
transformBall->Velocity.y = -2;
}
}
if (transformBall->Position.y < -EdgeY() - 4) {
if (MultiBalls() != 0) {
SetMultiBalls(MultiBalls() - 1);
// m_World->RemoveComponent<Components::Ball>(entity);
// m_World->RemoveComponent<Components::Transform>(entity);
// m_World->RemoveComponent<Components::CircleShape>(entity);
// m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity);
} else if (Lives() == PastLives()) {
Events::ResetBall be;
EventBroker->Publish(be);
Events::LifeLost e;
e.Entity = entity;
EventBroker->Publish(e);
return;
}
} else if (transformBall->Position.x > EdgeX()) {
if (transformBall->Velocity.x > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.x < -EdgeX()) {
if (transformBall->Velocity.x < 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(-1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.y > EdgeY()) {
if (transformBall->Velocity.y > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(0, 1));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
}
}
if (Lives() != PastLives()) {
auto life = m_World->GetComponent<Components::Life>(entity);
if (life != nullptr) {
if (life->Number + 1 == PastLives()) {
// m_World->RemoveComponent<Components::Life>(entity);
// m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
SetPastLives(Lives());
}
}
}
if (NumberOfBricks() <= 0) {
/*SetRestarting(true);
if (MultiBalls() <= 0 && PowerUps() <= 0) {
Events::ResetBall e;
EventBroker->Publish(e);
Events::ScoreEvent es;
es.Score = 500;
EventBroker->Publish(es);
Events::StageCleared ec;
EventBroker->Publish(ec);
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
} else {
if (ball != nullptr && MultiBalls() > 0) {
SetMultiBalls(MultiBalls() - 1);
m_World->RemoveComponent<Components::Ball>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveComponent<Components::CircleShape>(entity);
m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity);
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
} else {
auto powerUp = m_World->GetComponent<Components::PowerUp>(entity);
if (powerUp != nullptr) {
SetPowerUps(PowerUps() - 1);
m_World->RemoveComponent<Components::PowerUp>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
}
}
}*/
}
}
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, float spaceToEdge)
{
SetNumberOfBricks(rows * lines);
std::cout << "You're only doing this once, right?" << std::endl;
int num = 0;
for (int i = 0; i < rows; i++) {
num++;
for (int j = 0; j < Lines(); j++) {
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num);
}
if (num == 7)
num = 0;
}
SetNumberOfBricks(rows * lines);
SetRestarting(false);
return;
}
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, float spaceToEdge, int num)
{
auto brick = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
auto model = m_World->AddComponent<Components::Model>(brick);
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick);
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(brick);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
cPhys->Static = false;
cPhys->GravityScale = 0.f;
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
std::string fileName = "Textures/Bricks/";
fileName.append(std::to_string(num));
fileName.append(".png");
//sprite->SpriteFile = fileName;
model->ModelFile = "Models/Test/Brick/Brick.obj";
if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 6 && row == 6)) {
std::shared_ptr<Components::PowerUpBrick> cPow = m_World->AddComponent<Components::PowerUpBrick>(brick);
}
float x = line * spacesBetweenBricks.x;
float y = row * spacesBetweenBricks.y;
transform->Scale = glm::vec3(0.8, 0.2, 0.2);
transform->Position = glm::vec3(x - 3, 5 - spaceToEdge - y , -10.f);
cBrick->Score = 10 * num;
//sound
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(brick);
collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav";
m_World->CommitEntity(brick);
return;
}
void dd::Systems::LevelSystem::ProcessCollision()
{
// Like, go into brick component and check what it does upon collision. Maybe not done here?
return;
}
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
{
auto brick = m_World->GetComponent<Components::Brick>(entity);
if (brick != nullptr) {
SetNumberOfBricks(NumberOfBricks() - 1);
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
/*if (numberOfBricks < 1) {
EndLevel();
}*/
}
return;
}
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
{
EntityID entityBrick;
EntityID entityBall;
auto ball = m_World->GetComponent<Components::Ball>(event.Entity2);
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
if (brick != nullptr) {
entityBrick = event.Entity1;
} else {
brick = m_World->GetComponent<Components::Brick>(event.Entity2);
if (brick != nullptr) {
entityBrick = event.Entity2;
} else {
return false;
}
}
if (ball != nullptr) {
entityBall = event.Entity2;
} else {
ball = m_World->GetComponent<Components::Ball>(event.Entity1);
if (ball != nullptr) {
entityBall = event.Entity1;
} else {
return false;
}
}
brick = m_World->GetComponent<Components::Brick>(entityBrick);
if (brick == nullptr) {
return false;
}
auto power = m_World->GetComponent<Components::PowerUpBrick>(entityBrick);
if (power != nullptr) {
Events::CreatePowerUp e;
auto transform = m_World->GetComponent<Components::Transform>(entityBrick);
e.Position = transform->Position;
EventBroker->Publish(e);
}
if (ball != nullptr && Restarting() == false) {
auto ballTransform = m_World->GetComponent<Components::Transform>(entityBall);
// m_World->RemoveComponent<Components::Brick>(entityBrick);
// m_World->RemoveComponent<Components::Transform>(entityBrick);
// m_World->RemoveComponent<Components::RectangleShape>(entityBrick);
// m_World->RemoveComponent<Components::Physics>(entityBrick);
// m_World->RemoveEntity(entityBrick);
auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick);
physicsComponent->GravityScale = 1.f;
physicsComponent->Mask = CollisionLayer::Type::Water | CollisionLayer::Type::Wall;
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
Events::SetImpulse e;
e.Entity = entityBrick;
glm::vec2 point = glm::vec2(transformComponentBrick->Position.x + ((transformComponentBrick->Position.x - transformComponentBall->Position.x)/4), transformComponentBrick->Position.y + ((transformComponentBrick->Position.y - transformComponentBall->Position.y )/4));
e.Impulse = glm::normalize(point)/2.f;
e.Point = point;
EventBroker->Publish(e);
//TODO: Bricks dont collide with walls D=
SetNumberOfBricks(NumberOfBricks() - 1);
if (NumberOfBricks() <= 0) {
SetMultiBalls(MultiBalls() + 1);
}
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
<<<<<<< HEAD
// std::cout << NumberOfBricks() << std::endl;
=======
//std::cout << NumberOfBricks() << std::endl;
>>>>>>> origin/master
//std::cout << "Score: " << Score() << std::endl;
}
return true;
}
bool dd::Systems::LevelSystem::OnLifeLost(const dd::Events::LifeLost &event)
{
SetLives(Lives() - 1);
return true;
}
bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
{
SetScore(Score() += event.Score);
return true;
}
bool dd::Systems::LevelSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
SetMultiBalls(MultiBalls()+2);
}
bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &event)
{
SetPowerUps(PowerUps() + 1);
auto powerUp = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(powerUp);
auto model = m_World->AddComponent<Components::Model>(powerUp);
std::shared_ptr<Components::CircleShape> cRec = m_World->AddComponent<Components::CircleShape>(powerUp);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(powerUp);
cPhys->Static = false;
cPhys->Category = CollisionLayer::Type::PowerUp;
cPhys->Mask = CollisionLayer::Type::Pad;
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
transform->Position = event.Position;
transform->Scale = glm::vec3(0.2, 0.2, 0.2);
transform->Velocity = glm::vec3(0, -4, 0);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
m_World->CommitEntity(powerUp);
return true;
}
bool dd::Systems::LevelSystem::OnPowerUpTaken(const dd::Events::PowerUpTaken &event)
{
SetPowerUps(PowerUps() - 1);
return true;
}
bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
return true;
}
void dd::Systems::LevelSystem::EndLevel()
{
Events::StageCleared e;
EventBroker->Publish(e);
return;
}
-313
View File
@@ -1,313 +0,0 @@
//
// Created by Adniklastrator on 2015-09-10.
//
#include "PrecompiledHeader.h"
#include "Game/PadSystem.h"
#include "Core/World.h"
#include <iostream>
#include <Game/CPad.h>
#include <Rendering/CPointLight.h>
void dd::Systems::PadSystem::Initialize()
{
Events::BindKey r;
r.KeyCode = GLFW_KEY_RIGHT;
r.Command = "right";
EventBroker->Publish(r);
Events::BindKey l;
l.KeyCode = GLFW_KEY_LEFT;
l.Command = "left";
EventBroker->Publish(l);
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &PadSystem::OnKeyDown);
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PadSystem::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &PadSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &PadSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared);
}
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (ball != nullptr) {
if (ReplaceBall() == true) {
SetReplaceBall(false);
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(0.0f, 0.26f, -10.f);
transform->Velocity = glm::vec3(0.0f, -ball->Speed, 0.f);
}
}
}
void dd::Systems::PadSystem::Update(double dt)
{
if (Entity() == 0) {
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") {
SetEntity(it->first);
SetTransform(m_World->GetComponent<Components::Transform>(Entity()));
SetPad(m_World->GetComponent<Components::Pad>(Entity()));
break;
}
}
}
auto transform = Transform();
auto pad = Pad();
auto acceleration = Acceleration();
if (transform->Velocity.x < -pad->MaxSpeed) {
transform->Velocity.x = -pad->MaxSpeed;
}
else if (transform->Velocity.x > pad->MaxSpeed) {
transform->Velocity.x = pad->MaxSpeed;
}
transform->Position += transform->Velocity * (float)dt;
transform->Velocity += acceleration * (float)dt;
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
if (Left()) {
acceleration.x = -pad->AccelerationSpeed;
<<<<<<< HEAD
}
else if (Right()) {
=======
} else if (Right()) {
>>>>>>> 72413dc0a93bd3a2f6ab9fa7e19bbc3b846232db
acceleration.x = pad->AccelerationSpeed;
} else {
acceleration.x = 0.f;
}
SetTransform(transform);
SetPad(pad);
SetAcceleration(acceleration);
if (MultiBall() == true) {
SetMultiBall(false);
Events::MultiBall e;
e.padTransform = transform;
EventBroker->Publish(e);
}
return;
}
EntityID dd::Systems::PadSystem::CreateBall()
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.5f, 0.26f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
cball->Speed = 10;
m_World->CommitEntity(ent);
return ent;
}
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
{
int val = event.KeyCode;
if (val == GLFW_KEY_UP) {
//std::cout << "Up!" << std::endl;
} else if (val == GLFW_KEY_DOWN) {
//std::cout << "Down!" << std::endl;
} else if (val == GLFW_KEY_LEFT) {
//std::cout << "Left!" << std::endl;
//acceleration.x = -0.01f;
SetLeft(true);
} else if (val == GLFW_KEY_RIGHT) {
//std::cout << "Right!" << std::endl;
//acceleration.x = 0.01f;
SetRight(true);
} else if (val == GLFW_KEY_R) {
SetReplaceBall(true);
} else if (val == GLFW_KEY_M) {
SetMultiBall(true);
} else if (val == GLFW_KEY_D) {
return false;
}
return true;
}
bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
{
int val = event.KeyCode;
if (val == GLFW_KEY_UP) {
} else if (val == GLFW_KEY_DOWN) {
} else if (val == GLFW_KEY_LEFT) {
SetLeft(false);
} else if (val == GLFW_KEY_RIGHT) {
SetRight(false);
}
return true;
}
bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
{
/*
EntityID entityBall = event.Entity2;
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
if (ball == NULL) {
return false;
}
EntityID entityPad = event.Entity1;
auto pad = m_World->GetComponent<Components::Pad>(entityPad);
if (pad == NULL) {
return false;
}
auto transformBall = m_World->GetComponent<Components::Transform>(entityBall);
auto transformPad = m_World->GetComponent<Components::Transform>(entityPad);
float movementMultiplier = 0.5f;
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
//float movementY = glm::cos((abs(movementX) / (3.2f * movementMultiplier)) * 3.14159265359f / 2) * 2.f;
if (whatX > 0) {
movementX = movementMultiplier * whatX;
//std::cout << "Right!" << std::endl;
} else {
movementX = movementMultiplier * whatX;
//std::cout << "Left!" << std::endl;
}
// std::cout << movementX << " " << movementY << std::endl;
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
<<<<<<< HEAD
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2) + 1;
=======
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2)+ 0.2;
>>>>>>> 72413dc0a93bd3a2f6ab9fa7e19bbc3b846232db
//std::cout << movementX << " " << movementY << std::endl;
float len = glm::length<float>(transformBall->Velocity);
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
transformBall->Velocity += glm::vec3(transformPad->Velocity.x, 0, 0);
transformBall->Velocity = glm::normalize(transformBall->Velocity) * len;
//transform->Velocity = glm::vec3(movementX, movementY, 0.f);
*/
}
bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
{
EntityID entityPower;
EntityID entityPad;
auto powerUp = m_World->GetComponent<Components::PowerUp>(event.Entity1);
auto pad = m_World->GetComponent<Components::Pad>(event.Entity2);
if (powerUp != nullptr) {
entityPower = event.Entity1;
} else {
powerUp = m_World->GetComponent<Components::PowerUp>(event.Entity2);
if (powerUp != nullptr) {
entityPower = event.Entity2;
}
}
if (pad != nullptr) {
entityPad = event.Entity2;
} else {
pad = m_World->GetComponent<Components::Pad>(event.Entity1);
if (pad != nullptr) {
entityPad = event.Entity1;
}
}
if (entityPower == NULL || entityPad == NULL) {
return false;
}
pad = m_World->GetComponent<Components::Pad>(entityPad);
if (pad == nullptr) {
return false;
}
m_World->RemoveComponent<Components::PowerUp>(entityPower);
m_World->RemoveComponent<Components::CircleShape>(entityPower);
m_World->RemoveComponent<Components::Physics>(entityPower);
m_World->RemoveEntity(entityPower);
Events::PowerUpTaken ep;
ep.Name = "Something";
EventBroker->Publish(ep);
Events::MultiBall e;
auto transform = m_World->GetComponent<Components::Transform>(entityPad);
e.padTransform = transform;
EventBroker->Publish(e);
return true;
}
bool dd::Systems::PadSystem::OnResetBall(const dd::Events::ResetBall &event)
{
SetReplaceBall(true);
return true;
}
bool dd::Systems::PadSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
auto ent1 = CreateBall();
auto ent2 = CreateBall();
auto transform1 = m_World->GetComponent<Components::Transform>(ent1);
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
auto ball1 = m_World->GetComponent<Components::Ball>(ent1);
auto ball2 = m_World->GetComponent<Components::Ball>(ent2);
auto padTransform = event.padTransform;
float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2;
if (x1 < -3.1) {
x1 = 3;
}
if (x2 > 3.1) {
x2 = -3;
}
transform1->Position = glm::vec3(x1, -5.5, -10);
transform2->Position = glm::vec3(x2, -5.5, -10);
transform1->Velocity = glm::normalize(glm::vec3(5, 5 ,0.f)) * ball1->Speed;
transform2->Velocity = glm::normalize(glm::vec3(-5, 5 ,0.f)) * ball2->Speed;
return true;
}
bool dd::Systems::PadSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
auto entity = CreateBall();
return true;
}
bool dd::Systems::PadSystem::PadSteeringInputController::OnCommand(const Events::InputCommand &event)
{
std::string command = event.Command;
std::cout << "Command!" << std::endl;
if (command == "right") {
std::cout << "Right!" << std::endl;
} else if (command == "left") {
std::cout << "Left!" << std::endl;
}
return true;
}
+47
View File
@@ -0,0 +1,47 @@
#include "PrecompiledHeader.h"
#include "Physics/PhysicsSystem.h"
void dd::Systems::PhysicsSystem::ContactListener::BeginContact(b2Contact* contact)
{
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
Events::Contact e;
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
m_PhysicsSystem->EventBroker->Publish(e);
}
void dd::Systems::PhysicsSystem::ContactListener::EndContact(b2Contact* contact)
{
}
void dd::Systems::PhysicsSystem::ContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
// Turn of collisions
contact->SetEnabled(false);
}
}
}
void dd::Systems::PhysicsSystem::ContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
{
}
+4 -10
View File
@@ -6,24 +6,15 @@
void dd::Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register<Components::CircleShape>();
//TODO: REGISTER PHYSICS COMPONENTS HERE
}
void dd::Systems::PhysicsSystem::Initialize()
{
m_ContactListener = new ContactListener(this);
m_Gravity = b2Vec2(0.f, -9.82f);
m_PhysicsWorld = new b2World(m_Gravity);
m_TimeStep = 1.f/60.f;
m_VelocityIterations = 6;
m_PositionIterations = 2;
m_Accumulator = 0.f;
m_PhysicsWorld->SetContactListener(m_ContactListener);
InitializeWater();
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse);
}
@@ -325,8 +316,11 @@ void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
LOG_INFO("ParticleCount: %i", m_ParticleSystem->GetParticleCount());
}
dd::Systems::PhysicsSystem::~PhysicsSystem()
{
//TODO: INPUT CODE HERE
if (m_ContactListener != nullptr) {
delete m_ContactListener;
m_ContactListener = nullptr;
-363
View File
@@ -1,363 +0,0 @@
#include "PrecompiledHeader.h"
#include "Physics/PhysicsSystem.h"
void dd::Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register<Components::CircleShape>();
}
void dd::Systems::PhysicsSystem::Initialize()
{
m_ContactListener = new ContactListener(this);
m_Gravity = b2Vec2(0.f, -9.82f);
m_PhysicsWorld = new b2World(m_Gravity);
m_TimeStep = 1.f/60.f;
m_VelocityIterations = 6;
m_PositionIterations = 2;
m_Accumulator = 0.f;
m_PhysicsWorld->SetContactListener(m_ContactListener);
InitializeWater();
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse);
}
void dd::Systems::PhysicsSystem::InitializeWater()
{
b2ParticleSystemDef m_ParticleSystemDef;
m_ParticleSystemDef.radius = 0.13f;
m_ParticleSystem = m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
}
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
{
b2Body* body = m_EntitiesToBodies[event.Entity];
b2Vec2 impulse;
impulse.x = event.Impulse.x;
impulse.y = event.Impulse.y;
b2Vec2 point;
point.x = event.Point.x;
point.y = event.Point.y;
Impulse i;
i.Body = body;
i.Impulse = impulse;
i.Point = point;
m_Impulses.push_back(i);
return true;
}
void dd::Systems::PhysicsSystem::Update(double dt)
{
m_Accumulator += dt;
while(m_Accumulator >= m_TimeStep)
{
for (auto i : m_EntitiesToBodies) {
EntityID entity = i.first;
b2Body* body = i.second;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent) {
continue;
LOG_ERROR("RigidBody with no TransformComponent");
}
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if (! physicsComponent) {
continue;
LOG_ERROR("RigidBody with no PhysicsComponent");
}
if (body == nullptr) {
LOG_ERROR("This body should not exist");
continue;
}
if (m_World->GetEntityParent(entity) == 0) { //TODO: Make this work with childs too
b2Vec2 position;
position.x = transformComponent->Position.x;
position.y = transformComponent->Position.y;
float angle = -glm::eulerAngles(transformComponent->Orientation).z;
body->SetTransform(position, angle);
body->SetLinearVelocity(b2Vec2(transformComponent->Velocity.x, transformComponent->Velocity.y));
body->SetGravityScale(physicsComponent->GravityScale);
<<<<<<< HEAD
b2Filter filter;
filter.categoryBits = physicsComponent->Category;
filter.maskBits = physicsComponent->Mask;
body->GetFixtureList()->SetFilterData(filter);
}
}
for (auto i : m_Impulses) {
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
=======
>>>>>>> origin/master
}
m_Impulses.clear();
<<<<<<< HEAD
=======
for (auto i : m_Impulses) {
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
}
m_Impulses.clear();
m_Accumulator += dt;
while(m_Accumulator >= m_TimeStep)
{
>>>>>>> origin/master
m_PhysicsWorld->Step(m_TimeStep, m_VelocityIterations, m_PositionIterations);
m_Accumulator -= dt;
<<<<<<< HEAD
=======
for (auto i : m_EntitiesToBodies) {
EntityID entity = i.first;
b2Body* body = i.second;
>>>>>>> origin/master
for (auto i : m_EntitiesToBodies) {
EntityID entity = i.first;
b2Body* body = i.second;
if (body == nullptr) {
LOG_ERROR("This body should not exist");
continue;
}
<<<<<<< HEAD
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent)
continue;
if (m_World->GetEntityParent(entity) == 0) {
b2Vec2 position = body->GetPosition();
transformComponent->Position.x = position.x;
transformComponent->Position.y = position.y;
=======
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent)
continue;
auto parent = m_World->GetEntityParent(entity);
if (parent == 0) {
b2Vec2 position = body->GetPosition();
transformComponent->Position.x = position.x;
transformComponent->Position.y = position.y;
>>>>>>> origin/master
float angle = body->GetAngle();
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
<<<<<<< HEAD
b2Vec2 velocity = body->GetLinearVelocity();
transformComponent->Velocity.x = velocity.x;
transformComponent->Velocity.y = velocity.y;
}
=======
>>>>>>> origin/master
}
}
b2Vec2* positionBuffer = m_ParticleSystem->GetPositionBuffer();
for (auto i : m_EntitiesToParticleHandle) {
EntityID entity = i.first;
b2ParticleHandle* particleH = i.second;
b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()];
glm::vec2 position = glm::vec2(positionB2.x, positionB2.y);
EntityID entityParent = m_World->GetEntityParent(entity);
auto transform = m_World->GetComponent<Components::Transform>(entity);
auto transformParent = m_World->GetComponent<Components::Transform>(entityParent);
transform->Position = glm::vec3(position.x, position.y, -10) - transformParent->Position;
}
}
void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
}
void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
{
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
auto waterComponent = m_World->GetComponent<Components::WaterVolume>(entity);
if (physicsComponent && waterComponent) {
LOG_ERROR("Entity has both water and physics component, this is illegal. The police has been alerted.");
return;
}
if (physicsComponent) {
CreateBody(entity);
} else if (waterComponent) {
CreateParticleGroup(entity);
}
}
void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
{
auto physics = m_World->GetComponent<Components::Physics>(entity);
if (physics == nullptr) {
return;
}
b2Body* body = m_EntitiesToBodies[entity];
if (body != nullptr) {
m_EntitiesToBodies.erase(entity);
m_BodiesToEntities.erase(body);
m_PhysicsWorld->DestroyBody(body);
}
}
void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
{
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if(!physicsComponent){
LOG_ERROR("No PhysicsComponent in CreateBody");
return;
}
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if(!transformComponent) {
LOG_ERROR("No TransformComponent in CreateBody");
return;
}
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
b2BodyDef bodyDef;
bodyDef.position.Set(absoluteTransform.Position.x, absoluteTransform.Position.y);
bodyDef.angle = -glm::eulerAngles(absoluteTransform.Orientation).z;
if (physicsComponent->Static) {
bodyDef.type = b2_staticBody;
} else {
bodyDef.type = b2_dynamicBody;
}
b2Body* body = m_PhysicsWorld->CreateBody(&bodyDef);
b2Shape* pShape;
auto boxComponent = m_World->GetComponent<Components::RectangleShape>(entity);
if (boxComponent) {
b2PolygonShape* bShape = new b2PolygonShape();
bShape->SetAsBox(absoluteTransform.Scale.x/2, absoluteTransform.Scale.y/2);
pShape = bShape;
} else {
auto circleComponent = m_World->GetComponent<Components::CircleShape>(entity);
if (circleComponent) {
pShape = new b2CircleShape();
pShape->m_radius = absoluteTransform.Scale.x;
if (absoluteTransform.Scale.x != absoluteTransform.Scale.y && absoluteTransform.Scale.y != absoluteTransform.Scale.z) {
LOG_WARNING("Circles has to be of uniform scale.");
}
pShape->m_radius = absoluteTransform.Scale.x/2;
}
}
b2FixtureDef fixtureDef;
fixtureDef.shape = pShape;
fixtureDef.filter.categoryBits = physicsComponent->Category;
fixtureDef.filter.maskBits = physicsComponent->Mask;
if(physicsComponent->Static) {
body->CreateFixture(&fixtureDef); //Density kanske ska vara 0 på statiska kroppar
}
else {
fixtureDef.shape = pShape;
fixtureDef.density = 1.f;
fixtureDef.restitution = 1.0f;
fixtureDef.friction = 0.0f;
body->CreateFixture(&fixtureDef);
}
delete pShape;
body->SetGravityScale(physicsComponent->GravityScale);
m_EntitiesToBodies.insert(std::make_pair(entity, body));
m_BodiesToEntities.insert(std::make_pair(body, entity));
}
void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
{
//TODO: Lägg alla pd i en lista
auto transform = m_World->GetComponent<Components::Transform>(e);
if (!transform) {
LOG_ERROR("No Transform component in CreateParticleGroup");
return;
}
b2ParticleGroupDef pd;
b2PolygonShape shape;
shape.SetAsBox(transform->Scale.x/2.f, transform->Scale.y/2.f);
pd.shape = &shape;
pd.flags = b2_tensileParticle;
pd.position.Set(transform->Position.x, transform->Position.y);
//TODO: PUT IN LIST
t_watergroup = m_ParticleSystem->CreateParticleGroup(pd);
b2Vec2* t_ParticlePositions = m_ParticleSystem->GetPositionBuffer();
for(int i = 0; i < m_ParticleSystem->GetParticleCount(); i++){
{
auto t_waterparticle = m_World->CreateEntity(e);
auto transformChild = m_World->AddComponent<Components::Transform>(t_waterparticle);
//auto sprite = m_World->AddComponent<Components::Sprite>(t_waterparticle);
transformChild->Position = glm::vec3(t_ParticlePositions[i].x - transform->Position.x, t_ParticlePositions[i].y - transform->Position.y, -9.5f);
transformChild->Scale = glm::vec3(m_ParticleSystem->GetRadius())/transform->Scale;
//sprite->SpriteFile = "Textures/Ball.png";
m_World->CommitEntity(t_waterparticle);
m_EntitiesToParticleHandle.insert(std::make_pair(t_waterparticle, m_ParticleSystem->GetParticleHandleFromIndex(i)));
m_ParticleHandleToEntities.insert(std::make_pair( m_ParticleSystem->GetParticleHandleFromIndex(i), t_waterparticle));
}
}
LOG_INFO("ParticleCount: %i", m_ParticleSystem->GetParticleCount());
}
dd::Systems::PhysicsSystem::~PhysicsSystem()
{
if (m_ContactListener != nullptr) {
delete m_ContactListener;
m_ContactListener = nullptr;
}
}