Merge remote-tracking branch 'origin/master' into LevelSystemAndSuch
Conflicts: include/Core/Engine.h
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#ifndef DAYDREAM_CRECTANGLESHAPE_H
|
||||
#define DAYDREAM_CRECTANGLESHAPE_H
|
||||
|
||||
#include "Core/Component.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct RectangleShape : public Component
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_CRECTANGLESHAPE_H
|
||||
+66
-24
@@ -37,45 +37,87 @@
|
||||
#include "Game/LevelSystem.h"
|
||||
#include "Game/PadSystem.h"
|
||||
|
||||
#include "Physics/PhysicsSystem.h"
|
||||
#include "Physics/CPhysics.h"
|
||||
|
||||
#include "CBoxShape.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
Engine(int argc, char* argv[])
|
||||
{
|
||||
m_EventBroker = std::make_shared<EventBroker>();
|
||||
Engine(int argc, char* argv[]) {
|
||||
m_EventBroker = std::make_shared<EventBroker>();
|
||||
|
||||
m_Renderer = std::make_shared<Renderer>();
|
||||
m_Renderer->SetFullscreen(false);
|
||||
m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
|
||||
m_Renderer->Initialize();
|
||||
m_Renderer = std::make_shared<Renderer>();
|
||||
m_Renderer->SetFullscreen(false);
|
||||
m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
|
||||
m_Renderer->Initialize();
|
||||
|
||||
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
|
||||
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
|
||||
|
||||
m_World = std::make_shared<World>(m_EventBroker);
|
||||
m_World = std::make_shared<World>(m_EventBroker);
|
||||
|
||||
//TODO: Move this out of engine.h
|
||||
m_World->ComponentFactory.Register<Components::Transform>();
|
||||
m_World->SystemFactory.Register<Systems::TransformSystem>(
|
||||
[this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::TransformSystem>();
|
||||
// m_World->ComponentFactory.Register<Components::Model>();
|
||||
// m_World->ComponentFactory.Register<Components::Template>();
|
||||
|
||||
//TODO: Move this out of engine.h
|
||||
m_World->ComponentFactory.Register<Components::Transform>();
|
||||
m_World->SystemFactory.Register<Systems::TransformSystem>([this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::TransformSystem>();
|
||||
m_World->SystemFactory.Register<Systems::LevelSystem>([this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::LevelSystem>();
|
||||
m_World->SystemFactory.Register<Systems::PadSystem>([this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::PadSystem>();
|
||||
m_World->ComponentFactory.Register<Components::Model>();
|
||||
m_World->ComponentFactory.Register<Components::Sprite>();
|
||||
m_World->ComponentFactory.Register<Components::Template>();
|
||||
m_World->Initialize();
|
||||
m_World->ComponentFactory.Register<Components::Sprite>();
|
||||
|
||||
// {
|
||||
// auto ent = m_World->CreateEntity();
|
||||
// std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
// transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
||||
// auto sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||
// sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
// }
|
||||
m_World->ComponentFactory.Register<Components::RectangleShape>();
|
||||
m_World->ComponentFactory.Register<Components::Physics>();
|
||||
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
|
||||
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::PhysicsSystem>();
|
||||
|
||||
m_World->ComponentFactory.Register<Components::Model>();
|
||||
m_World->ComponentFactory.Register<Components::Template>();
|
||||
m_World->Initialize();
|
||||
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
||||
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
|
||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
transform->Position = glm::vec3(0.f, -3.f, -9.f);
|
||||
transform->Scale = glm::vec3(2.f, 0.5f, 1.f);
|
||||
//transform->Orientation = glm::rotate(transform->Orientation, glm::radians(45.f), glm::vec3(0, 0, -1));
|
||||
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
|
||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = true;
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
}
|
||||
|
||||
m_LastTime = glfwGetTime();
|
||||
}
|
||||
|
||||
Regular → Executable
+1
-1
@@ -73,7 +73,7 @@ private:
|
||||
ShaderProgram* m_spForward;
|
||||
ShaderProgram* m_spScreen;
|
||||
|
||||
GLuint m_UnitQuad = 0;
|
||||
GLuint m_ScreenQuad = 0;
|
||||
Model* m_UnitSphere = nullptr;
|
||||
|
||||
GLuint m_rbDepthBuffer = 0;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef DAYDREAM_CPHYSICS_H
|
||||
#define DAYDREAM_CPHYSICS_H
|
||||
#include "Core/Component.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Physics: public Component
|
||||
{
|
||||
//idk if anything should be here :)
|
||||
bool Static = true;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_CPHYSICS_H
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Viktor on 10/09/2015.
|
||||
//
|
||||
|
||||
#ifndef Events_ECONTACT_h__
|
||||
#define Events_ECONTACT_h__
|
||||
|
||||
|
||||
#include <glm/detail/type_vec.hpp>
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/Entity.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace Events
|
||||
{
|
||||
struct Contact : Event
|
||||
{
|
||||
EntityID Entity1;
|
||||
EntityID Entity2;
|
||||
glm::vec2 ContactPoint;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //Events_ECONTACT_h__
|
||||
@@ -0,0 +1,94 @@
|
||||
#ifndef DAYDREAM_PHYSICSSYSTEM_H
|
||||
#define DAYDREAM_PHYSICSSYSTEM_H
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/World.h"
|
||||
#include "Core/CBoxShape.h"
|
||||
#include "Physics/CPhysics.h"
|
||||
#include <Box2D/Box2D.h>
|
||||
#include "Core/CTransform.h"
|
||||
#include "Transform/TransformSystem.h"
|
||||
#include "Physics/EContact.h"
|
||||
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
//KOLLA http://box2d.org/manual.pdf p52 Pre-Solve Event
|
||||
|
||||
class PhysicsSystem : public System
|
||||
{
|
||||
friend class ContractListener;
|
||||
|
||||
public:
|
||||
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) {}
|
||||
|
||||
~PhysicsSystem();
|
||||
|
||||
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;
|
||||
int m_VelocityIterations, m_PositionIterations;
|
||||
|
||||
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
|
||||
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
|
||||
|
||||
void CreateBody(EntityID entity);
|
||||
|
||||
|
||||
class ContactListener : public b2ContactListener
|
||||
{
|
||||
public:
|
||||
ContactListener(PhysicsSystem* physicsSystem)
|
||||
: m_PhysicsSystem(physicsSystem) { }
|
||||
|
||||
void BeginContact(b2Contact* contact)
|
||||
{
|
||||
b2Vec2 contactPoint = contact->GetManifold()->localPoint;
|
||||
|
||||
Events::Contact e;
|
||||
e.ContactPoint = glm::vec2(contactPoint.x, contactPoint.y);
|
||||
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
||||
|
||||
m_PhysicsSystem->EventBroker->Publish(e);
|
||||
}
|
||||
void EndContact(b2Contact* contact)
|
||||
{ /* handle end event */ }
|
||||
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
|
||||
{ /* handle pre-solve event */ }
|
||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||
{ /* handle post-solve event */ }
|
||||
|
||||
private:
|
||||
PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
|
||||
ContactListener* m_ContactListener;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_PHYSICSSYSTEM_H
|
||||
Reference in New Issue
Block a user