Base PhysicsSystem.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#ifndef DAYDREAM_PHYSICSSYSTEM_H
|
||||
#define DAYDREAM_PHYSICSSYSTEM_H
|
||||
|
||||
#include "Core/System.h"
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Systems {
|
||||
|
||||
|
||||
class PhysicsSystem : public System {
|
||||
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) {}
|
||||
|
||||
~PhysicsSystem();
|
||||
|
||||
void Initialize();
|
||||
|
||||
// Called once per system every tick
|
||||
void Update(double dt);
|
||||
// Called once for every entity in the world every tick
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent);
|
||||
|
||||
// Called when components are committed to an entity
|
||||
void OnEntityCommit(EntityID entity);
|
||||
|
||||
// Called when an entity is removed
|
||||
void OnEntityRemoved(EntityID entity);
|
||||
|
||||
|
||||
b2Vec2 m_Gravity;
|
||||
b2World* m_PhysicsWorld;
|
||||
float m_TimeStep;
|
||||
int m_VelocityIterations, m_PositionIterations;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_PHYSICSSYSTEM_H
|
||||
@@ -69,7 +69,7 @@ set(SOURCE_FILES
|
||||
${SOURCE_FILES_Rendering}
|
||||
${SOURCE_FILES_Transform}
|
||||
${SOURCE_FILES_Game}
|
||||
)
|
||||
Physics/PhysicsSystem.cpp ../../include/Core/Physics/PhysicsSystem.h)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/Physics/PhysicsSystem.h"
|
||||
|
||||
void dd::Systems::PhysicsSystem::Initialize(){
|
||||
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;
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::Update(double dt){
|
||||
m_PhysicsWorld->Step(m_TimeStep, m_VelocityIterations, m_PositionIterations);
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity){
|
||||
|
||||
}
|
||||
|
||||
dd::Systems::PhysicsSystem::~PhysicsSystem(){
|
||||
delete m_PhysicsWorld;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user