Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 58407203fc | |||
| 06c7245421 | |||
| 0cffdadd33 | |||
| 754356da1d | |||
| cf6f9866e7 | |||
| f45908647c | |||
| a1e49d75fb | |||
| 0743d882b9 | |||
| 4c7714dd21 | |||
| e120b09b84 | |||
| a4065f734b | |||
| 45711500f7 | |||
| 52dec86925 | |||
| 074c53a82b | |||
| 4d3428f125 | |||
| 39f4215c2b | |||
| cbaca42a3c | |||
| c63ec035a7 | |||
| c31ff4cfcb | |||
| 2fb16357fa | |||
| 2491dd8b74 | |||
| 45e68c51a3 | |||
| c3b54ef030 | |||
| 7733a44d53 | |||
| 94fc7c1ce6 | |||
| a1c709a2db | |||
| 38d3a8c990 | |||
| 7b7277509e | |||
| fc41727a5d | |||
| 22c7663cc5 | |||
| 1a0201ee98 | |||
| 90424b8d68 | |||
| 118c0b3a24 | |||
| 8bf10d4517 |
@@ -0,0 +1,21 @@
|
||||
# Blender MTL File: 'Sid.blend'
|
||||
# Material Count: 2
|
||||
|
||||
newmtl Derp
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd SquidTexture.png
|
||||
|
||||
newmtl None
|
||||
Ns 0
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
map_Kd SquidTexture.png
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Regular → Executable
+61
-58
@@ -45,6 +45,7 @@
|
||||
#include "Game/CPad.h"
|
||||
#include "Game/CBrick.h"
|
||||
#include "Game/BallSystem.h"
|
||||
#include "Game/HitLagSystem.h"
|
||||
#include "Game/Bricks/CPowerUpBrick.h"
|
||||
|
||||
#include "Physics/PhysicsSystem.h"
|
||||
@@ -52,6 +53,8 @@
|
||||
#include "Physics/CRectangleShape.h"
|
||||
#include "Physics/ESetImpulse.h"
|
||||
#include "Physics/CWaterVolume.h"
|
||||
#include "Physics/CParticle.h"
|
||||
#include "Physics/CParticleEmitter.h"
|
||||
|
||||
#include "Game/EGameStart.h"
|
||||
#include "Sound/EPlaySound.h"
|
||||
@@ -111,10 +114,6 @@ public:
|
||||
m_World->ComponentFactory.Register<Components::PowerUp>();
|
||||
m_World->ComponentFactory.Register<Components::PowerUpBrick>();
|
||||
|
||||
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
|
||||
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::PhysicsSystem>();
|
||||
|
||||
m_World->SystemFactory.Register<Systems::LevelSystem>(
|
||||
[this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::LevelSystem>();
|
||||
@@ -124,38 +123,22 @@ public:
|
||||
m_World->SystemFactory.Register<Systems::BallSystem>(
|
||||
[this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::BallSystem>();
|
||||
m_World->SystemFactory.Register<Systems::HitLagSystem>(
|
||||
[this]() { return new Systems::HitLagSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::HitLagSystem>();
|
||||
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->ComponentFactory.Register<Components::PointLight>();
|
||||
m_World->ComponentFactory.Register<Components::WaterVolume>();
|
||||
m_World->ComponentFactory.Register<Components::Particle>();
|
||||
m_World->ComponentFactory.Register<Components::ParticleEmitter>();
|
||||
m_World->Initialize();
|
||||
|
||||
|
||||
//OctoBall
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
transform->Position = glm::vec3(-0.f, 0.26f, -9.f);
|
||||
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||
transform->Velocity = glm::vec3(0.0f, -10.f, 0.f);
|
||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
||||
ball->Speed = 5.f;
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;
|
||||
physics->Category = CollisionLayer::Type::Ball;
|
||||
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
|
||||
physics->Calculate = true;
|
||||
|
||||
auto plight = m_World->AddComponent<Components::PointLight>(ent);
|
||||
plight->Radius = 2.f;
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
}
|
||||
|
||||
//PointLightTest
|
||||
{
|
||||
auto t_Light = m_World->CreateEntity();
|
||||
@@ -165,7 +148,7 @@ public:
|
||||
pl->Radius = 20.f;
|
||||
pl->Diffuse = glm::vec3(0.8f, 0.7f, 0.05f);
|
||||
auto model = m_World->AddComponent<Components::Model>(t_Light);
|
||||
model->ModelFile = "Core/UnitSphere.obj";
|
||||
model->ModelFile = "Models/Core/UnitSphere.obj";
|
||||
m_World->CommitEntity(t_Light);
|
||||
}
|
||||
{
|
||||
@@ -176,7 +159,7 @@ public:
|
||||
pl->Radius = 15.f;
|
||||
pl->Diffuse = glm::vec3(0.1f, 0.5f, 0.8f);
|
||||
auto model = m_World->AddComponent<Components::Model>(t_Light);
|
||||
model->ModelFile = "Core/UnitSphere.obj";
|
||||
model->ModelFile = "Models/Core/UnitSphere.obj";
|
||||
m_World->CommitEntity(t_Light);
|
||||
}
|
||||
|
||||
@@ -188,7 +171,7 @@ public:
|
||||
transform->Scale = glm::vec3(6.f, 6.f, 10.f);
|
||||
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
|
||||
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
||||
model->Color = glm::vec4(1.f, 1.f, 1.f, 0.3f);
|
||||
model->Color = glm::vec4(1.f, 0.f, 0.f, 0.3f);
|
||||
m_World->CommitEntity(t_halfPipe);
|
||||
}
|
||||
|
||||
@@ -203,16 +186,57 @@ public:
|
||||
m_World->CommitEntity(background);
|
||||
}
|
||||
|
||||
//ParticleTest
|
||||
// {
|
||||
// auto Pe = m_World->CreateEntity();
|
||||
// auto transform = m_World->AddComponent<Components::Transform>(Pe);
|
||||
// auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(Pe);
|
||||
//
|
||||
// transform->Position = glm::vec3(0.f, -5.f, -10.f);
|
||||
// particleEmitter->GravityScale = 0.0f;
|
||||
// particleEmitter->SpawnRate = 1.0f;
|
||||
//
|
||||
// {
|
||||
// auto Pt = m_World->CreateEntity(Pe);
|
||||
// auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
|
||||
// auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
|
||||
// //auto PtModel = m_World->AddComponent<Components::Model>(Pt);
|
||||
// auto PtParticle = m_World->AddComponent<Components::Particle>(Pt);
|
||||
// auto PtTemplate = m_World->AddComponent<Components::Template>(Pt);
|
||||
//
|
||||
// PtTransform->Velocity = glm::vec3(1.0f, 0.f, 0.f);
|
||||
// PtTransform->Position = transform->Position;
|
||||
// PtSprite->SpriteFile = "Textures/Ball.png";
|
||||
//
|
||||
// //PtModel->ModelFile = "Models/Brick/Brick.obj";
|
||||
// PtParticle->LifeTime = 1000.f;
|
||||
// PtParticle->Flags = ParticleFlags::Type::powderParticle;
|
||||
// }
|
||||
// m_World->CommitEntity(Pe);
|
||||
// }
|
||||
|
||||
{
|
||||
auto Pt = m_World->CreateEntity();
|
||||
auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
|
||||
auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
|
||||
|
||||
PtTransform->Position = glm::vec3(2.f, 0.f, -10.f);
|
||||
PtSprite->SpriteFile = "Textures/Ball.png";
|
||||
}
|
||||
|
||||
//Water test
|
||||
{
|
||||
float amount = 1.5f;
|
||||
|
||||
auto t_waterBody = m_World->CreateEntity();
|
||||
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
|
||||
transform->Position = glm::vec3(0.f, -5.5f, -10.f);
|
||||
transform->Scale = glm::vec3(7.f, 1.5f, 1.f);
|
||||
transform->Position = glm::vec3(0.f, -6.25f + (amount / 2), -10.f);
|
||||
transform->Scale = glm::vec3(7.f, amount, 1.f);
|
||||
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
|
||||
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
|
||||
m_World->CommitEntity(t_waterBody);
|
||||
}
|
||||
|
||||
//TODO: Why does the ball not collide with these bricks?
|
||||
//BottomBox
|
||||
{
|
||||
@@ -257,7 +281,7 @@ public:
|
||||
// m_World->CommitEntity(topWall);
|
||||
// }
|
||||
|
||||
{
|
||||
/*{
|
||||
auto topWall = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(
|
||||
topWall);
|
||||
@@ -276,14 +300,14 @@ public:
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
|
||||
|
||||
m_World->CommitEntity(topWall);
|
||||
}
|
||||
}*/
|
||||
|
||||
{
|
||||
auto leftWall = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(
|
||||
leftWall);
|
||||
transform->Position = glm::vec3(-4.f, 1.f, -10.f);
|
||||
transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
|
||||
transform->Scale = glm::vec3(0.5f, 35.f, 1.f);
|
||||
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
|
||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
@@ -304,7 +328,7 @@ public:
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(
|
||||
rightWall);
|
||||
transform->Position = glm::vec3(4.f, 1.f, -10.f);
|
||||
transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
|
||||
transform->Scale = glm::vec3(0.5f, 35.f, 1.f);
|
||||
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
|
||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
@@ -320,25 +344,6 @@ public:
|
||||
m_World->CommitEntity(rightWall);
|
||||
}
|
||||
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
m_World->SetProperty(ent, "Name", "Pad");
|
||||
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
|
||||
ctransform->Position = glm::vec3(0.f, -3.5f, -10.f);
|
||||
ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f);
|
||||
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;
|
||||
physics->Category = CollisionLayer::Type::Pad;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::PowerUp;
|
||||
physics->Calculate = true;
|
||||
auto cModel = m_World->AddComponent<Components::Model>(ent);
|
||||
cModel->ModelFile = "Models/Submarine2.obj";
|
||||
|
||||
auto pad = m_World->AddComponent<Components::Pad>(ent);
|
||||
m_World->CommitEntity(ent);
|
||||
}
|
||||
|
||||
|
||||
//EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart);
|
||||
m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1));
|
||||
@@ -449,7 +454,6 @@ public:
|
||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||
if (spriteComponent)
|
||||
{
|
||||
|
||||
std::string normal = spriteComponent->NormalTexture;
|
||||
std::string spec = spriteComponent->SpecularTexture;
|
||||
|
||||
@@ -472,7 +476,6 @@ public:
|
||||
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//TODO: Get this out of engine.h
|
||||
|
||||
+26
-38
@@ -16,8 +16,8 @@
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef Renderer_h__
|
||||
#define Renderer_h__
|
||||
#ifndef DD_RENDERER_H__
|
||||
#define DD_RENDERER_H__
|
||||
|
||||
#include "Util/Rectangle.h"
|
||||
#include "Camera.h"
|
||||
@@ -30,8 +30,6 @@ namespace dd
|
||||
class Renderer
|
||||
{
|
||||
public:
|
||||
//Render();
|
||||
|
||||
GLFWwindow* Window() const { return m_Window; }
|
||||
Rectangle Resolution() const { return m_Resolution; }
|
||||
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
|
||||
@@ -39,8 +37,6 @@ public:
|
||||
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
|
||||
bool VSYNC() const { return m_VSYNC; }
|
||||
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
|
||||
//void SetViewport(const Rectangle& viewport) { m_Viewport = viewport; }
|
||||
//void SetScissor(const Rectangle& scissor) { m_Scissor = scissor; }
|
||||
const dd::Camera* Camera() const { return m_Camera; }
|
||||
void SetCamera(const dd::Camera* camera)
|
||||
{
|
||||
@@ -50,7 +46,6 @@ public:
|
||||
m_Camera = camera;
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize();
|
||||
void Draw(RenderQueueCollection& rq);
|
||||
|
||||
@@ -58,8 +53,6 @@ private:
|
||||
Rectangle m_Resolution = Rectangle(1280, 720);
|
||||
bool m_Fullscreen = false;
|
||||
bool m_VSYNC = false;
|
||||
//Rectangle m_Viewport;
|
||||
//Rectangle m_Scissor;
|
||||
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
|
||||
const dd::Camera* m_Camera = nullptr;
|
||||
|
||||
@@ -67,42 +60,37 @@ private:
|
||||
std::string m_GLVendor;
|
||||
GLFWwindow* m_Window = nullptr;
|
||||
|
||||
ShaderProgram* m_spDeferred1;
|
||||
ShaderProgram* m_spDeferred2;
|
||||
ShaderProgram* m_spDeferred3;
|
||||
ShaderProgram* m_spForward;
|
||||
ShaderProgram* m_spScreen;
|
||||
ShaderProgram* t_m_spWater;
|
||||
ShaderProgram* t_m_spWater2;
|
||||
ShaderProgram* m_SpDeferred1;
|
||||
ShaderProgram* m_SpDeferred2;
|
||||
ShaderProgram* m_SpDeferred3;
|
||||
ShaderProgram* m_SpForward;
|
||||
ShaderProgram* m_SpScreen;
|
||||
ShaderProgram* m_SpWater;
|
||||
ShaderProgram* m_SpWater2;
|
||||
|
||||
GLuint m_ScreenQuad = 0;
|
||||
Model* m_UnitSphere = nullptr;
|
||||
Model* m_UnitQuad = nullptr;
|
||||
Texture* m_StandardNormal;
|
||||
Texture* m_StandardSpecular;
|
||||
Texture* t_m_WhiteSphereTexture;
|
||||
|
||||
GLuint m_rbDepthBuffer = 0;
|
||||
GLuint m_fbDeferred1 = 0;
|
||||
GLuint m_GDiffuse = 0;
|
||||
GLuint m_GPosition = 0;
|
||||
GLuint m_GNormal = 0;
|
||||
GLuint m_GSpecular = 0;
|
||||
GLuint m_fbDeferred2 = 0;
|
||||
GLuint m_tLighting = 0;
|
||||
GLuint m_fbDeferred3 = 0;
|
||||
GLuint m_tFinal = 0;
|
||||
//Water GTexture
|
||||
GLuint t_m_Gwater = 0;
|
||||
//Water blur texture
|
||||
GLuint t_m_BWater;
|
||||
GLuint t_m_BWater2;
|
||||
//WAterpass Framebuffer
|
||||
GLuint t_m_fbWater;
|
||||
//Waterpass Framebuffer
|
||||
GLuint t_m_fbWaterBlur;
|
||||
GLuint t_m_fbWaterBlur2;
|
||||
Texture* m_WhiteSphereTexture;
|
||||
|
||||
GLuint m_RbDepthBuffer = 0; //DepthBuffer Texture
|
||||
GLuint m_FbDeferred1 = 0; //Framebuffer for first pass
|
||||
GLuint m_GDiffuse = 0; //Texture for diffuseColors
|
||||
GLuint m_GPosition = 0; //Texture for positions
|
||||
GLuint m_GNormal = 0; //Texture for normals
|
||||
GLuint m_GSpecular = 0; //Texture for specular
|
||||
GLuint m_FbDeferred2 = 0; //Framebuffer that handles the lighting pass
|
||||
GLuint m_TLighting = 0; //Texture for the lighting pass
|
||||
GLuint m_FbDeferred3 = 0; //Frambuffer for handling the last pass.
|
||||
GLuint m_TFinal = 0; //Final Texture to be printed to screen
|
||||
GLuint m_Gwater = 0; //Water Color Texture
|
||||
GLuint m_BWater; //Water blur texture
|
||||
GLuint m_BWater2; //Water blur texture
|
||||
GLuint m_FbWater; //Waterpass Framebuffer
|
||||
GLuint m_FbWaterBlur; //Waterpass Framebuffer
|
||||
GLuint m_FbWaterBlur2; //Waterpass Framebuffer
|
||||
|
||||
GLuint m_CurrentScreenBuffer = 0;
|
||||
void LoadShaders();
|
||||
|
||||
+6
-6
@@ -44,9 +44,9 @@ public:
|
||||
: m_Name(name)
|
||||
{
|
||||
SetParent(parent);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
|
||||
//EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
|
||||
//EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
|
||||
//EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
|
||||
}
|
||||
|
||||
~Frame()
|
||||
@@ -253,9 +253,9 @@ protected:
|
||||
virtual bool OnCommand(const Events::InputCommand& event) { return false; }
|
||||
|
||||
private:
|
||||
EventRelay<Frame, Events::KeyDown> m_EKeyDown;
|
||||
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
|
||||
EventRelay<Frame, Events::InputCommand> m_EInputCommand;
|
||||
//EventRelay<Frame, Events::KeyDown> m_EKeyDown;
|
||||
//EventRelay<Frame, Events::KeyUp> m_EKeyUp;
|
||||
//EventRelay<Frame, Events::InputCommand> m_EInputCommand;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -5,15 +5,31 @@
|
||||
#include "Core/World.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/CTransform.h"
|
||||
#include "Core/CTemplate.h"
|
||||
#include "Physics/CPhysics.h"
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Physics/EContact.h"
|
||||
#include "Rendering/CModel.h"
|
||||
#include "Rendering/CPointLight.h"
|
||||
#include "Game/CBall.h"
|
||||
#include "Game/CPowerUp.h"
|
||||
#include "Game/CLife.h"
|
||||
#include "Game/ELifeLost.h"
|
||||
#include "Game/EComboEvent.h"
|
||||
#include "Game/EResetBall.h"
|
||||
#include "Game/EMultiBall.h"
|
||||
#include "Game/EMultiBallLost.h"
|
||||
#include "Game/EGameOver.h"
|
||||
#include "Game/EPause.h"
|
||||
|
||||
namespace dd {
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Systems {
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class BallSystem : public System {
|
||||
class BallSystem : public System
|
||||
{
|
||||
public:
|
||||
BallSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
@@ -39,11 +55,61 @@ public:
|
||||
// Called when an entity is removed
|
||||
void OnEntityRemoved(EntityID entity) override;
|
||||
|
||||
private:
|
||||
EntityID CreateBall();
|
||||
void CreateLife(int);
|
||||
EntityID Ball() { return m_Ball; };
|
||||
void SetBall(const EntityID& ball) { m_Ball = ball; }
|
||||
|
||||
float& XMovementMultiplier() { return m_XMovementMultiplier; }
|
||||
void SetXMovementMultiplier(const float& xMovementMultiplier) { m_XMovementMultiplier = xMovementMultiplier; }
|
||||
float& EdgeX() { return m_EdgeX; }
|
||||
void SetEdgeX(const float& edgeX) { m_EdgeX = edgeX; }
|
||||
float& EdgeY() { return m_EdgeY; }
|
||||
void SetEdgeY(const float& edgeY) { m_EdgeY = edgeY; }
|
||||
int& MultiBalls() { return m_MultiBalls; }
|
||||
void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
|
||||
int& Lives() { return m_Lives; }
|
||||
void SetLives(const int& lives) { m_Lives = lives; }
|
||||
int& PastLives() { return m_PastLives; }
|
||||
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
|
||||
bool ReplaceBall() const { return m_ReplaceBall; }
|
||||
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
|
||||
bool MultiBall() const { return m_MultiBall; }
|
||||
void SetMultiBall(const bool& multiBall) { m_MultiBall = multiBall; }
|
||||
bool IsPaused() const { return m_Pause; }
|
||||
void SetPause(const bool& pause) { m_Pause = pause; }
|
||||
|
||||
private:
|
||||
float m_XMovementMultiplier = 2.f;
|
||||
float m_EdgeX = 3.2f;
|
||||
float m_EdgeY = 5.2f;
|
||||
int m_MultiBalls = 0;
|
||||
int m_Lives = 3;
|
||||
int m_PastLives = 3;
|
||||
bool m_ReplaceBall = false;
|
||||
bool m_MultiBall = false;
|
||||
bool m_Pause = false;
|
||||
|
||||
glm::vec3 m_SavedSpeed;
|
||||
bool m_InitializePause = false;
|
||||
|
||||
EntityID m_Ball;
|
||||
|
||||
dd::EventRelay<BallSystem, dd::Events::LifeLost> m_ELifeLost;
|
||||
dd::EventRelay<BallSystem, dd::Events::MultiBallLost> m_EMultiBallLost;
|
||||
dd::EventRelay<BallSystem, dd::Events::ResetBall> m_EResetBall;
|
||||
dd::EventRelay<BallSystem, dd::Events::MultiBall> m_EMultiBall;
|
||||
dd::EventRelay<BallSystem, dd::Events::Pause> m_EPause;
|
||||
|
||||
bool OnLifeLost(const dd::Events::LifeLost &event);
|
||||
bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
|
||||
bool OnResetBall(const dd::Events::ResetBall &event);
|
||||
bool OnMultiBall(const dd::Events::MultiBall &event);
|
||||
bool OnPause(const dd::Events::Pause &event);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,9 @@ struct Ball : Component
|
||||
{
|
||||
int Number = 0;
|
||||
float Speed = 5.f;
|
||||
int Combo = 0;
|
||||
bool Paused = false;
|
||||
glm::vec3 SavedSpeed = glm::vec3(0, 0, 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -15,10 +15,8 @@ namespace Components
|
||||
|
||||
struct Brick : Component
|
||||
{
|
||||
int Points = 10;
|
||||
int Hits = 1;
|
||||
int Score = 50;
|
||||
bool Removed = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+1
-4
@@ -17,12 +17,9 @@ namespace Components
|
||||
|
||||
struct Pad : Component
|
||||
{
|
||||
int Lives;
|
||||
int Points;
|
||||
|
||||
float SlowdownModifier = 5.f;
|
||||
float AccelerationSpeed = 40.f;
|
||||
float MaxSpeed = 20.f;
|
||||
float MaxSpeed = 5.f;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-29.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_ECOMBOEVENT_H
|
||||
#define DAYDREAM_ECOMBOEVENT_H
|
||||
|
||||
#include "Core/Entity.h"
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct ComboEvent : Event
|
||||
{
|
||||
EntityID Ball;
|
||||
int Combo;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_ECOMBOEVENT_H
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Administrator on 2015-09-30.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_EHITLAG_H
|
||||
#define DAYDREAM_EHITLAG_H
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct HitLag : Event
|
||||
{
|
||||
float Time;
|
||||
std::string Type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_EHITLAG_H
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-28.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_EMULTIBALLLOST_H
|
||||
#define DAYDREAM_EMULTIBALLLOST_H
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/Entity.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct MultiBallLost : Event
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_EMULTIBALLLOST_H
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-30.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_EPAUSE_H
|
||||
#define DAYDREAM_EPAUSE_H
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct Pause : Event
|
||||
{
|
||||
std::string Type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_EPAUSE_H
|
||||
@@ -31,6 +31,9 @@ public:
|
||||
m_A2 = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
|
||||
m_A2->X = 60;
|
||||
m_A2->SetNumber(1);
|
||||
//m_A3 = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
|
||||
//m_A3->X = 80;
|
||||
//m_A3->SetNumber(123);
|
||||
|
||||
m_ScoreIndicator = new GUI::TextureFrame(this, "HUDScoreIndicator");
|
||||
m_ScoreIndicator->SetTexture("Textures/GUI/HUD/ScoreIndicatorBG.png");
|
||||
@@ -49,6 +52,7 @@ private:
|
||||
TextureFrame* m_ScoreIndicator = nullptr;
|
||||
NumberFrame* m_A1 = nullptr;
|
||||
NumberFrame* m_A2 = nullptr;
|
||||
//NumberFrame* m_A3 = nullptr;
|
||||
NumberFrame* m_ScoreNumberFrame = nullptr;
|
||||
FPSCounter* m_FPSCounter = nullptr;
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-30.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_HITLAGSYSTEM_H
|
||||
#define DAYDREAM_HITLAGSYSTEM_H
|
||||
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/CTransform.h"
|
||||
#include "Core/CTemplate.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/World.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
#include "Rendering/CModel.h"
|
||||
#include "Game/CBrick.h"
|
||||
#include "Game/CBall.h"
|
||||
#include "Game/CLife.h"
|
||||
#include "Game/CPowerUp.h"
|
||||
#include "Game/EStageCleared.h"
|
||||
#include "Game/ELifeLost.h"
|
||||
#include "Game/EResetBall.h"
|
||||
#include "Game/EScoreEvent.h"
|
||||
#include "Game/EComboEvent.h"
|
||||
#include "Game/EMultiBall.h"
|
||||
#include "Game/EMultiBallLost.h"
|
||||
#include "Game/EPause.h"
|
||||
#include "Game/EHitLag.h"
|
||||
#include "Game/EGameOver.h"
|
||||
#include "Game/ECreatePowerUp.h"
|
||||
#include "Game/EPowerUpTaken.h"
|
||||
#include "Game/Bricks/CPowerUpBrick.h"
|
||||
#include "Physics/CPhysics.h"
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Physics/CRectangleShape.h"
|
||||
#include "Physics/ESetImpulse.h"
|
||||
#include "Physics/EContact.h"
|
||||
#include "Sound/CCollisionSound.h"
|
||||
#include "Game/PadSystem.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class HitLagSystem : public System
|
||||
{
|
||||
public:
|
||||
HitLagSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker)
|
||||
{ }
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void FlipPause();
|
||||
|
||||
bool IsPaused() const { return m_Pause; }
|
||||
void SetPause(const bool& pause) { m_Pause = pause; }
|
||||
bool HitLag() const { return m_HitLag; }
|
||||
void SetHitLag(const bool& hitLag) { m_HitLag = hitLag; }
|
||||
float& HitLagDuration() { return m_HitLagDuration; }
|
||||
void SetHitLagDuration(const float& hitLagDuration) { m_HitLagDuration = hitLagDuration; }
|
||||
float& HitLagTimer() { return m_HitLagTimer; }
|
||||
void SetHitLagTimer(const float& hitLagTimer) { m_HitLagTimer = hitLagTimer; }
|
||||
std::string& CurrentType() { return m_CurrentType; }
|
||||
void SetCurrentType(const std::string& currentType) { m_CurrentType = currentType; }
|
||||
private:
|
||||
bool m_Pause;
|
||||
bool m_HitLag;
|
||||
float m_HitLagDuration;
|
||||
float m_HitLagTimer;
|
||||
std::string m_CurrentType;
|
||||
|
||||
dd::EventRelay<HitLagSystem, dd::Events::Pause> m_EPause;
|
||||
dd::EventRelay<HitLagSystem, dd::Events::HitLag> m_EHitLag;
|
||||
|
||||
bool OnPause(const dd::Events::Pause &event);
|
||||
bool OnHitLag(const dd::Events::HitLag &event);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_HITLAGSYSTEM_H
|
||||
+15
-19
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/CTransform.h"
|
||||
#include "Core/CTemplate.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/World.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
@@ -19,14 +20,17 @@
|
||||
#include "Game/ELifeLost.h"
|
||||
#include "Game/EResetBall.h"
|
||||
#include "Game/EScoreEvent.h"
|
||||
#include "Physics/CRectangleShape.h"
|
||||
#include "Game/EComboEvent.h"
|
||||
#include "Game/EMultiBall.h"
|
||||
#include "Game/EMultiBallLost.h"
|
||||
#include "Game/EPause.h"
|
||||
#include "Game/EGameOver.h"
|
||||
#include "Game/ECreatePowerUp.h"
|
||||
#include "Game/EPowerUpTaken.h"
|
||||
#include "Game/Bricks/CPowerUpBrick.h"
|
||||
#include "Physics/CPhysics.h"
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Physics/CRectangleShape.h"
|
||||
#include "Physics/ESetImpulse.h"
|
||||
#include "Physics/EContact.h"
|
||||
#include "Sound/CCollisionSound.h"
|
||||
@@ -61,11 +65,7 @@ public:
|
||||
void Initialize() override;
|
||||
|
||||
void CreateBasicLevel(int, int, glm::vec2, float);
|
||||
void CreateLife(int);
|
||||
void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting.
|
||||
void LoadLevel(char[20]);
|
||||
void CreateBrick(int, int, glm::vec2, float, int);
|
||||
void ProcessCollision();
|
||||
|
||||
void OnEntityRemoved(EntityID entity);
|
||||
|
||||
@@ -78,10 +78,8 @@ public:
|
||||
void SetRestarting(const bool& restarting) { m_Restarting = restarting; }
|
||||
bool Initialized() const { return m_Initialized; }
|
||||
void SetInitialized(const bool& initialized) { m_Initialized = initialized; }
|
||||
int& Lives() { return m_Lives; }
|
||||
void SetLives(const int& lives) { m_Lives = lives; }
|
||||
int& PastLives() { return m_PastLives; }
|
||||
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
|
||||
bool IsPaused() const { return m_Pause; }
|
||||
void SetPause(const bool& pause) { m_Pause = pause; }
|
||||
int& MultiBalls() { return m_MultiBalls; }
|
||||
void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
|
||||
int& PowerUps() { return m_PowerUps; }
|
||||
@@ -99,16 +97,13 @@ public:
|
||||
|
||||
glm::vec2& SpaceBetweenBricks() { return m_SpaceBetweenBricks; }
|
||||
void SetSpaceBetweenBricks(const glm::vec2& spaceBetweenBricks) { m_SpaceBetweenBricks = spaceBetweenBricks; }
|
||||
float& EdgeX() { return m_EdgeX; }
|
||||
void SetEdgeX(const float& edgeX) { m_EdgeX = edgeX; }
|
||||
float& EdgeY() { return m_EdgeY; }
|
||||
void SetEdgeY(const float& edgeY) { m_EdgeY = edgeY; }
|
||||
float& NotResettingTheStage() { return m_NotResettingTheStage; }
|
||||
void SetNotResettingTheStage(const float& notResettingTheStage) { m_NotResettingTheStage = notResettingTheStage; }
|
||||
|
||||
private:
|
||||
bool m_Restarting = false;
|
||||
bool m_Initialized = false;
|
||||
int m_Lives = 3;
|
||||
int m_PastLives = 3;
|
||||
bool m_Pause = false;
|
||||
int m_MultiBalls = 0;
|
||||
int m_PowerUps = 0;
|
||||
int m_Score = 0;
|
||||
@@ -117,24 +112,25 @@ private:
|
||||
int m_Lines = 7;
|
||||
float m_SpaceToEdge = 0.25f;
|
||||
glm::vec2 m_SpaceBetweenBricks = glm::vec2(1, 0.4);
|
||||
float m_EdgeX = 3.2f;
|
||||
float m_EdgeY = 5.2f;
|
||||
float m_NotResettingTheStage = 5.f;
|
||||
|
||||
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
||||
dd::EventRelay<LevelSystem, dd::Events::LifeLost> m_ELifeLost;
|
||||
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
|
||||
dd::EventRelay<LevelSystem, dd::Events::MultiBall> m_EMultiBall;
|
||||
dd::EventRelay<LevelSystem, dd::Events::MultiBallLost> m_EMultiBallLost;
|
||||
dd::EventRelay<LevelSystem, dd::Events::CreatePowerUp> m_ECreatePowerUp;
|
||||
dd::EventRelay<LevelSystem, dd::Events::PowerUpTaken> m_EPowerUpTaken;
|
||||
dd::EventRelay<LevelSystem, dd::Events::StageCleared> m_EStageCleared;
|
||||
dd::EventRelay<LevelSystem, dd::Events::Pause> m_EPause;
|
||||
|
||||
bool OnContact(const dd::Events::Contact &event);
|
||||
bool OnLifeLost(const dd::Events::LifeLost &event);
|
||||
bool OnScoreEvent(const dd::Events::ScoreEvent &event);
|
||||
bool OnMultiBall(const dd::Events::MultiBall &event);
|
||||
bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
|
||||
bool OnCreatePowerUp(const dd::Events::CreatePowerUp &event);
|
||||
bool OnPowerUpTaken(const dd::Events::PowerUpTaken &event);
|
||||
bool OnStageCleared(const dd::Events::StageCleared &event);
|
||||
bool OnPause(const dd::Events::Pause &event);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+13
-12
@@ -9,6 +9,7 @@
|
||||
#include "Core/System.h"
|
||||
#include "Core/Component.h"
|
||||
#include "Core/CTransform.h"
|
||||
#include "Core/CTemplate.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EKeyUp.h"
|
||||
@@ -27,6 +28,8 @@
|
||||
#include "Game/EMultiBall.h"
|
||||
#include "Game/EPowerUpTaken.h"
|
||||
#include "Game/EStageCleared.h"
|
||||
#include "Game/EPause.h"
|
||||
#include "Game/EHitLag.h"
|
||||
|
||||
|
||||
namespace dd
|
||||
@@ -45,8 +48,6 @@ public:
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
EntityID CreateBall();
|
||||
|
||||
EntityID& Entity() { return m_Entity; }
|
||||
void SetEntity(const EntityID& ent) { m_Entity = ent; }
|
||||
glm::vec3 Acceleration() const { return m_Acceleration; }
|
||||
@@ -56,42 +57,42 @@ public:
|
||||
void SetLeft(const bool& left) { m_Left = left; }
|
||||
bool Right() const { return m_Right; }
|
||||
void SetRight(const bool& right) { m_Right = right; }
|
||||
bool ReplaceBall() const { return m_ReplaceBall; }
|
||||
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
|
||||
bool MultiBall() const { return m_MultiBall; }
|
||||
void SetMultiBall(const bool& multiBall) { m_MultiBall = multiBall; }
|
||||
float Edge() const { return m_Edge; }
|
||||
void SetEdge(const float& edge) { m_Edge = edge; }
|
||||
|
||||
Components::Transform* Transform() const { return m_Transform; }
|
||||
void SetTransform(Components::Transform* transform) { m_Transform = transform; }
|
||||
Components::Pad* Pad() const { return m_Pad; }
|
||||
void SetPad(Components::Pad* pad) { m_Pad = pad; }
|
||||
|
||||
bool IsPaused() const { return m_Pause; }
|
||||
void SetPause(const bool& pause) { m_Pause = pause; }
|
||||
|
||||
private:
|
||||
EntityID m_Entity = 0;
|
||||
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
|
||||
bool m_Left = false;
|
||||
bool m_Right = false;
|
||||
bool m_ReplaceBall = false;
|
||||
float m_Edge = 2.8f;
|
||||
bool m_MultiBall = false;
|
||||
Components::Transform* m_Transform = nullptr;
|
||||
Components::Pad* m_Pad = nullptr;
|
||||
|
||||
bool m_Pause = false;
|
||||
|
||||
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
|
||||
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
|
||||
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
|
||||
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContactPowerUp;
|
||||
dd::EventRelay<PadSystem, dd::Events::ResetBall> m_EResetBall;
|
||||
dd::EventRelay<PadSystem, dd::Events::MultiBall> m_EMultiBall;
|
||||
dd::EventRelay<PadSystem, dd::Events::StageCleared> m_EStageCleared;
|
||||
dd::EventRelay<PadSystem, dd::Events::Pause> m_EPause;
|
||||
|
||||
bool OnKeyDown(const dd::Events::KeyDown &event);
|
||||
bool OnKeyUp(const dd::Events::KeyUp &event);
|
||||
|
||||
bool OnContact(const dd::Events::Contact &event);
|
||||
bool OnContactPowerUp(const dd::Events::Contact &event);
|
||||
bool OnResetBall(const dd::Events::ResetBall &event);
|
||||
bool OnMultiBall(const dd::Events::MultiBall &event);
|
||||
bool OnStageCleared(const dd::Events::StageCleared &event);
|
||||
bool OnPause(const dd::Events::Pause &event);
|
||||
|
||||
class PadSteeringInputController;
|
||||
std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers;
|
||||
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
#ifndef COMPONENTS_PARTICLE_H__
|
||||
#define COMPONENTS_PARTICLE_H__
|
||||
#include "Core/Component.h"
|
||||
|
||||
namespace dd {
|
||||
|
||||
namespace ParticleFlags {
|
||||
|
||||
enum Type {
|
||||
waterParticle = 0,
|
||||
zombieParticle = 1 << 1,
|
||||
wallParticle = 1 << 2,
|
||||
springParticle = 1 << 3,
|
||||
elasticParticle = 1 << 4,
|
||||
viscousParticle = 1 << 5,
|
||||
powderParticle = 1 << 6,
|
||||
tensileParticle = 1 << 7,
|
||||
colorMixingParticle = 1 << 8,
|
||||
destructionListenerParticle = 1 << 9,
|
||||
barrierParticle = 1 << 10,
|
||||
staticPressureParticle = 1 << 11,
|
||||
reactiveParticle = 1 << 12,
|
||||
repulsiveParticle = 1 << 13,
|
||||
fixtureContactListenerParticle = 1 << 14,
|
||||
particleContactListenerParticle = 1 << 15,
|
||||
fixtureContactFilterParticle = 1 << 16,
|
||||
particleContactFilterParticle = 1 << 17
|
||||
};
|
||||
}
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Particle : public Component
|
||||
{
|
||||
float Radius = 0.5f;
|
||||
float LifeTime = 5.0f;
|
||||
|
||||
ParticleFlags::Type Flags =
|
||||
ParticleFlags::Type::waterParticle |
|
||||
ParticleFlags::Type::zombieParticle |
|
||||
ParticleFlags::Type::wallParticle |
|
||||
ParticleFlags::Type::springParticle |
|
||||
ParticleFlags::Type::elasticParticle |
|
||||
ParticleFlags::Type::viscousParticle |
|
||||
ParticleFlags::Type::powderParticle |
|
||||
ParticleFlags::Type::tensileParticle |
|
||||
ParticleFlags::Type::colorMixingParticle |
|
||||
ParticleFlags::Type::destructionListenerParticle |
|
||||
ParticleFlags::Type::barrierParticle |
|
||||
ParticleFlags::Type::staticPressureParticle |
|
||||
ParticleFlags::Type::reactiveParticle |
|
||||
ParticleFlags::Type::repulsiveParticle |
|
||||
ParticleFlags::Type::fixtureContactListenerParticle |
|
||||
ParticleFlags::Type::particleContactListenerParticle |
|
||||
ParticleFlags::Type::fixtureContactFilterParticle |
|
||||
ParticleFlags::Type::particleContactFilterParticle;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#ifndef COMPONENTS_PARTICLEEMITTER_H__
|
||||
#define COMPONENTS_PARTICLEEMITTER_H__
|
||||
#include "Core/Component.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct ParticleEmitter : public Component
|
||||
{
|
||||
int Amount = 10.f;
|
||||
float InitialSpeed = 1.f;
|
||||
double SpawnRate = 1.f;
|
||||
double TimeSinceLastSpawn = 0;
|
||||
|
||||
//ParticleSystem variables
|
||||
float GravityScale = 1.0f;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,7 +9,7 @@ namespace Components
|
||||
|
||||
struct WaterVolume : public Component
|
||||
{
|
||||
|
||||
float Radius;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -3,22 +3,33 @@
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/World.h"
|
||||
#include "CRectangleShape.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/CTemplate.h"
|
||||
|
||||
#include "Physics/CRectangleShape.h"
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Physics/CPhysics.h"
|
||||
#include <Box2D/Box2D.h>
|
||||
#include "Physics/CWaterVolume.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/CParticle.h"
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Physics/CParticleEmitter.h"
|
||||
#include "Game/EPause.h"
|
||||
#include "Game/CPad.h"
|
||||
#include "Game/CPad.h"
|
||||
#include "Physics/CWaterVolume.h"
|
||||
#include "Game/CBall.h"
|
||||
#include "Transform/TransformSystem.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
|
||||
#include "Core/CTemplate.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -26,63 +37,75 @@ 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;
|
||||
double m_TimeStep;
|
||||
double 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;
|
||||
};
|
||||
bool m_Pause = false;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
std::vector<b2ParticleSystem*> m_ParticleSystem;
|
||||
std::vector<b2ParticleGroup*> t_ParticleGroup;
|
||||
|
||||
std::vector<std::unordered_map<EntityID, const b2ParticleHandle*>> m_EntitiesToParticleHandle;
|
||||
std::vector<std::unordered_map<const b2ParticleHandle*, EntityID>> m_ParticleHandleToEntities;
|
||||
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
|
||||
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
|
||||
|
||||
|
||||
|
||||
void CreateBody(EntityID entity);
|
||||
void SyncEntitiesWithBodies();
|
||||
void SyncBodiesWithEntities();
|
||||
void InitializeWater();
|
||||
void CreateParticleGroup(EntityID entity);
|
||||
|
||||
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale);
|
||||
void CreateParticleEmitter(EntityID entity);
|
||||
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed.
|
||||
|
||||
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
|
||||
bool SetImpulse(const Events::SetImpulse &event);
|
||||
|
||||
dd::EventRelay<PhysicsSystem, dd::Events::Pause> m_EPause;
|
||||
bool OnPause(const dd::Events::Pause &event);
|
||||
|
||||
//TODO: Fill struct with info needed.
|
||||
struct ParticleEmitter
|
||||
{
|
||||
std::vector<b2ParticleSystem*> ParticleSystem;
|
||||
std::vector<EntityID> ParticleEmitter;
|
||||
std::vector<EntityID> ParticleTemplate;
|
||||
};
|
||||
ParticleEmitter m_ParticleEmitters;
|
||||
|
||||
std::list<Impulse> m_Impulses;
|
||||
|
||||
|
||||
@@ -93,45 +116,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;
|
||||
@@ -141,6 +129,7 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_PHYSICSSYSTEM_H
|
||||
#endif
|
||||
|
||||
@@ -94,8 +94,7 @@ set(SOURCE_FILES
|
||||
${SOURCE_FILES_Physics}
|
||||
${SOURCE_FILES_Game}
|
||||
${SOURCE_FILES_Sound}
|
||||
${SOURCE_FILES_GUI}
|
||||
)
|
||||
${SOURCE_FILES_GUI})
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||
|
||||
+98
-129
@@ -70,7 +70,7 @@ void dd::Renderer::Initialize()
|
||||
LoadShaders();
|
||||
CreateBuffers();
|
||||
|
||||
m_CurrentScreenBuffer = m_tFinal;
|
||||
m_CurrentScreenBuffer = m_TFinal;
|
||||
}
|
||||
void dd::Renderer::LoadShaders()
|
||||
{
|
||||
@@ -79,39 +79,39 @@ void dd::Renderer::LoadShaders()
|
||||
*/
|
||||
|
||||
// Pass #1: Fill G-buffers
|
||||
m_spDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/1/");
|
||||
m_spDeferred1->BindFragDataLocation(0, "GDiffuse");
|
||||
m_spDeferred1->BindFragDataLocation(1, "GPosition");
|
||||
m_spDeferred1->BindFragDataLocation(2, "GNormal");
|
||||
m_spDeferred1->BindFragDataLocation(3, "GSpecular");
|
||||
m_spDeferred1->Link();
|
||||
m_SpDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/1/");
|
||||
m_SpDeferred1->BindFragDataLocation(0, "GDiffuse");
|
||||
m_SpDeferred1->BindFragDataLocation(1, "GPosition");
|
||||
m_SpDeferred1->BindFragDataLocation(2, "GNormal");
|
||||
m_SpDeferred1->BindFragDataLocation(3, "GSpecular");
|
||||
m_SpDeferred1->Link();
|
||||
|
||||
// Pass #2: Lighting
|
||||
m_spDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/2/");
|
||||
m_SpDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/2/");
|
||||
//glBindFragDataLocation(m_SPDeferred2, 0, "FragmentLighting");
|
||||
m_spDeferred2->Link();
|
||||
m_SpDeferred2->Link();
|
||||
|
||||
//Water Pass
|
||||
t_m_spWater = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water/");
|
||||
t_m_spWater->Link();
|
||||
t_m_spWater2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water2/");
|
||||
t_m_spWater2->Link();
|
||||
m_SpWater = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water/");
|
||||
m_SpWater->Link();
|
||||
m_SpWater2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water2/");
|
||||
m_SpWater2->Link();
|
||||
|
||||
// Pass #3: Combining into final image
|
||||
m_spDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
|
||||
m_spDeferred3->Link();
|
||||
m_SpDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
|
||||
m_SpDeferred3->Link();
|
||||
|
||||
/*
|
||||
Forward rendering
|
||||
*/
|
||||
m_spForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
|
||||
m_spForward->Link();
|
||||
m_SpForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
|
||||
m_SpForward->Link();
|
||||
|
||||
/*
|
||||
Screen draw
|
||||
*/
|
||||
m_spScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
|
||||
m_spScreen->Link();
|
||||
m_SpScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
|
||||
m_SpScreen->Link();
|
||||
}
|
||||
|
||||
void dd::Renderer::CreateBuffers()
|
||||
@@ -122,10 +122,10 @@ void dd::Renderer::CreateBuffers()
|
||||
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
||||
m_StandardNormal = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
|
||||
m_StandardSpecular = ResourceManager::Load<Texture>("Textures/Core/NeutralSpecularMap.png");
|
||||
t_m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
|
||||
m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
|
||||
|
||||
glGenRenderbuffers(1, &m_rbDepthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_rbDepthBuffer);
|
||||
glGenRenderbuffers(1, &m_RbDepthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_RbDepthBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Resolution.Width, m_Resolution.Height);
|
||||
|
||||
// Generate G-buffer textures
|
||||
@@ -157,8 +157,8 @@ void dd::Renderer::CreateBuffers()
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glGenTextures(1, &t_m_Gwater);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_Gwater);
|
||||
glGenTextures(1, &m_Gwater);
|
||||
glBindTexture(GL_TEXTURE_2D, m_Gwater);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_FLOAT, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@@ -166,9 +166,9 @@ void dd::Renderer::CreateBuffers()
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
// Create first pass framebuffer
|
||||
glGenFramebuffers(1, &m_fbDeferred1);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred1);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_rbDepthBuffer);
|
||||
glGenFramebuffers(1, &m_FbDeferred1);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred1);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RbDepthBuffer);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_GDiffuse, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_GPosition, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_GNormal, 0);
|
||||
@@ -176,13 +176,13 @@ void dd::Renderer::CreateBuffers()
|
||||
GLenum firstPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
|
||||
glDrawBuffers(4, firstPassDrawBuffers);
|
||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOG_ERROR("m_fbDeferred1 incomplete: 0x%x\n", fbStatus);
|
||||
LOG_ERROR("m_FbDeferred1 incomplete: 0x%x\n", fbStatus);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Generate lighting texture
|
||||
glGenTextures(1, &m_tLighting);
|
||||
glBindTexture(GL_TEXTURE_2D, m_tLighting);
|
||||
glGenTextures(1, &m_TLighting);
|
||||
glBindTexture(GL_TEXTURE_2D, m_TLighting);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@@ -190,19 +190,19 @@ void dd::Renderer::CreateBuffers()
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
// Create second pass framebuffer
|
||||
glGenFramebuffers(1, &m_fbDeferred2);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred2);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tLighting, 0);
|
||||
glGenFramebuffers(1, &m_FbDeferred2);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred2);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TLighting, 0);
|
||||
GLenum secondPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||
glDrawBuffers(1, secondPassDrawBuffers);
|
||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//Fill Water Texture
|
||||
glGenTextures(1, &t_m_Gwater);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_Gwater);
|
||||
glGenTextures(1, &m_Gwater);
|
||||
glBindTexture(GL_TEXTURE_2D, m_Gwater);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@@ -210,19 +210,19 @@ void dd::Renderer::CreateBuffers()
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
//Fill water pass
|
||||
glGenFramebuffers(1, &t_m_fbWater);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWater);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_Gwater, 0);
|
||||
glGenFramebuffers(1, &m_FbWater);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWater);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_Gwater, 0);
|
||||
GLenum waterPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||
glDrawBuffers(1, waterPassDrawBuffers);
|
||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//water Blur texture
|
||||
glGenTextures(1, &t_m_BWater);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_BWater);
|
||||
glGenTextures(1, &m_BWater);
|
||||
glBindTexture(GL_TEXTURE_2D, m_BWater);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@@ -230,20 +230,20 @@ void dd::Renderer::CreateBuffers()
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
//Fill waterBlur pass
|
||||
glGenFramebuffers(1, &t_m_fbWaterBlur);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWaterBlur);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_BWater, 0);
|
||||
glGenFramebuffers(1, &m_FbWaterBlur);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWaterBlur);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_BWater, 0);
|
||||
GLenum waterBlurDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||
glDrawBuffers(1, waterBlurDrawBuffers);
|
||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//water Blur texture2
|
||||
glGenTextures(1, &t_m_BWater2);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_BWater2);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_rbDepthBuffer);
|
||||
glGenTextures(1, &m_BWater2);
|
||||
glBindTexture(GL_TEXTURE_2D, m_BWater2);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RbDepthBuffer);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@@ -251,19 +251,19 @@ void dd::Renderer::CreateBuffers()
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
//Fill waterBlur pass2
|
||||
glGenFramebuffers(1, &t_m_fbWaterBlur2);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWaterBlur2);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_BWater2, 0);
|
||||
glGenFramebuffers(1, &m_FbWaterBlur2);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWaterBlur2);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_BWater2, 0);
|
||||
GLenum waterBlur2DrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||
glDrawBuffers(1, waterBlur2DrawBuffers);
|
||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Generate final deferred texture
|
||||
glGenTextures(1, &m_tFinal);
|
||||
glBindTexture(GL_TEXTURE_2D, m_tFinal);
|
||||
glGenTextures(1, &m_TFinal);
|
||||
glBindTexture(GL_TEXTURE_2D, m_TFinal);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@@ -271,14 +271,14 @@ void dd::Renderer::CreateBuffers()
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
// Create third pass framebuffer
|
||||
glGenFramebuffers(1, &m_fbDeferred3);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_rbDepthBuffer);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tFinal, 0);
|
||||
glGenFramebuffers(1, &m_FbDeferred3);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RbDepthBuffer);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TFinal, 0);
|
||||
GLenum thirdPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||
glDrawBuffers(1, thirdPassDrawBuffers);
|
||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOG_ERROR("m_fbDeferred3 incomplete: 0x%x\n", fbStatus);
|
||||
LOG_ERROR("m_FbDeferred3 incomplete: 0x%x\n", fbStatus);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -298,7 +298,7 @@ void dd::Renderer::Draw(RenderQueueCollection& rq)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glClearColor(1, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_spScreen->Bind();
|
||||
m_SpScreen->Bind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_CurrentScreenBuffer);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
@@ -312,17 +312,17 @@ void dd::Renderer::Draw(RenderQueueCollection& rq)
|
||||
void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
||||
{
|
||||
// Pass #1: Fill G-buffers
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glDepthMask(GL_TRUE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_BLEND);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred1);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred1);
|
||||
glClearColor(1, 1, 1, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
m_spDeferred1->Bind();
|
||||
DrawScene(objects, *m_spDeferred1);
|
||||
m_SpDeferred1->Bind();
|
||||
DrawScene(objects, *m_SpDeferred1);
|
||||
|
||||
// Pass #2: Lighting
|
||||
glEnable(GL_CULL_FACE);
|
||||
@@ -332,24 +332,24 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glDepthMask(GL_FALSE);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred2);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred2);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_spDeferred2->Bind();
|
||||
m_SpDeferred2->Bind();
|
||||
DrawLightSpheres(lights);
|
||||
|
||||
// Pass #3: Combine into final deferred image
|
||||
glCullFace(GL_BACK);
|
||||
glDisable(GL_BLEND);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_spDeferred3->Bind();
|
||||
glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f)));
|
||||
m_SpDeferred3->Bind();
|
||||
glUniform3fv(glGetUniformLocation(*m_SpDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f)));
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_GDiffuse);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, m_tLighting);
|
||||
glBindTexture(GL_TEXTURE_2D, m_TLighting);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
@@ -365,12 +365,12 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
|
||||
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||
// glClearColor(1, 0.9, 0.8f, 1);
|
||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
m_spForward->Bind();
|
||||
DrawScene(objects, *m_spForward);
|
||||
m_SpForward->Bind();
|
||||
DrawScene(objects, *m_SpForward);
|
||||
|
||||
//WaterPass
|
||||
glDisable(GL_CULL_FACE);
|
||||
@@ -379,10 +379,10 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWater);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWater);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
t_m_spWater->Bind();
|
||||
m_SpWater->Bind();
|
||||
DrawWater(objects);
|
||||
}
|
||||
|
||||
@@ -444,6 +444,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
||||
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
@@ -462,7 +463,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
|
||||
void dd::Renderer::DrawLightSpheres(RenderQueue &lights)
|
||||
{
|
||||
GLuint shaderProgramHandle = *m_spDeferred2;
|
||||
GLuint shaderProgramHandle = *m_SpDeferred2;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_GPosition);
|
||||
@@ -499,7 +500,7 @@ void dd::Renderer::DrawLightSpheres(RenderQueue &lights)
|
||||
|
||||
void dd::Renderer::DrawWater(RenderQueue &rq)
|
||||
{
|
||||
GLuint shaderProgramHandle = *t_m_spWater;
|
||||
GLuint shaderProgramHandle = *m_SpWater;
|
||||
|
||||
glm::mat4 projectionMatrix = m_Camera->ProjectionMatrix();
|
||||
glm::mat4 viewMatrix = m_Camera->ViewMatrix();
|
||||
@@ -517,7 +518,7 @@ void dd::Renderer::DrawWater(RenderQueue &rq)
|
||||
glm::value_ptr(viewMatrix));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, *t_m_WhiteSphereTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, *m_WhiteSphereTexture);
|
||||
|
||||
glBindVertexArray(m_UnitQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
|
||||
@@ -528,16 +529,17 @@ void dd::Renderer::DrawWater(RenderQueue &rq)
|
||||
|
||||
|
||||
//blur1
|
||||
shaderProgramHandle = *t_m_spWater2;
|
||||
shaderProgramHandle = *m_SpWater2;
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWaterBlur);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWaterBlur);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
t_m_spWater2->Bind();
|
||||
m_SpWater2->Bind();
|
||||
//TODO: Add this in water particle component. Blurradius
|
||||
float radius = 3.f;
|
||||
|
||||
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(1.0f, 0.0f)));
|
||||
@@ -545,64 +547,31 @@ void dd::Renderer::DrawWater(RenderQueue &rq)
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_Gwater);
|
||||
glBindTexture(GL_TEXTURE_2D, m_Gwater);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
|
||||
//blur2
|
||||
shaderProgramHandle = *t_m_spWater2;
|
||||
shaderProgramHandle = *m_SpWater2;
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
||||
t_m_spWater2->Bind();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||
m_SpWater2->Bind();
|
||||
|
||||
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(0.0f, 1.0f)));
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "res"), m_Resolution.Height);
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_BWater);
|
||||
glBindTexture(GL_TEXTURE_2D, m_BWater);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLuint dd::Renderer::CreateWaterParticleVAO(RenderQueue &particles)
|
||||
{
|
||||
float waterVerts[particles.Size()];
|
||||
int i = 0;
|
||||
|
||||
for ( auto &job : particles ) {
|
||||
auto waterJob = std::dynamic_pointer_cast<WaterParticleJob>(job);
|
||||
if (!waterJob)
|
||||
continue;
|
||||
waterVerts[i ] = waterJob->Position.x;
|
||||
waterVerts[i+1] = waterJob->Position.y;
|
||||
waterVerts[i+2] = waterJob->Position.z;
|
||||
i+3;
|
||||
}
|
||||
|
||||
GLuint vbo[1], vao;
|
||||
glGenBuffers(1, vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, 3 * particles.Size() * sizeof(float), waterVerts, GL_STATIC_DRAW);
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
return vao;
|
||||
}
|
||||
|
||||
GLuint dd::Renderer::CreateQuad()
|
||||
{
|
||||
float quadVertices[] =
|
||||
@@ -649,7 +618,7 @@ GLuint dd::Renderer::CreateQuad()
|
||||
void dd::Renderer::DebugKeys()
|
||||
{
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_F1)) {
|
||||
m_CurrentScreenBuffer = m_tFinal;
|
||||
m_CurrentScreenBuffer = m_TFinal;
|
||||
}
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_F2)) {
|
||||
m_CurrentScreenBuffer = m_GDiffuse;
|
||||
@@ -664,19 +633,19 @@ void dd::Renderer::DebugKeys()
|
||||
m_CurrentScreenBuffer = m_GSpecular;
|
||||
}
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_F6)) {
|
||||
m_CurrentScreenBuffer = m_tLighting;
|
||||
m_CurrentScreenBuffer = m_TLighting;
|
||||
}
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_F7)) {
|
||||
m_CurrentScreenBuffer = t_m_Gwater;
|
||||
m_CurrentScreenBuffer = m_Gwater;
|
||||
}
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_F8)) {
|
||||
m_CurrentScreenBuffer = t_m_BWater;
|
||||
m_CurrentScreenBuffer = m_BWater;
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
@@ -684,7 +653,7 @@ void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
|
||||
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
|
||||
|
||||
m_spScreen->Bind();
|
||||
m_SpScreen->Bind();
|
||||
|
||||
glm::mat4 MVP;
|
||||
|
||||
@@ -696,9 +665,9 @@ void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
|
||||
glm::mat4 PV = glm::mat4(1); //frameJob->ProjectionMatrix * viewMatrix;
|
||||
glm::mat4 modelMatrix = glm::mat4(1); //frameJob->ModelMatrix;
|
||||
MVP = PV * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(*m_spScreen, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
glUniformMatrix4fv(glGetUniformLocation(*m_spScreen, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(*m_spScreen, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(*m_SpScreen, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
glUniformMatrix4fv(glGetUniformLocation(*m_SpScreen, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(*m_SpScreen, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture);
|
||||
|
||||
@@ -61,9 +61,9 @@ void main()
|
||||
sum += texture(WaterTexture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
|
||||
sum += texture(WaterTexture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
|
||||
|
||||
frag_Diffuse = vec4(sum.rgb, 1.0) * vec4(0.0, 0.6, 1.5, 1.0);
|
||||
float avgColor = frag_Diffuse.r + frag_Diffuse.g + frag_Diffuse.b;
|
||||
float avgColor = sum.r + sum.g + sum.b;
|
||||
avgColor = avgColor/3;
|
||||
frag_Diffuse = vec4(sum.r, sum.g, sum.b, 1.0);
|
||||
if ( avgColor*dir.y > Threshhold ){
|
||||
frag_Diffuse = vec4(0.0, 0.3, 1.0, 1.0);
|
||||
}
|
||||
|
||||
@@ -14,16 +14,153 @@ void dd::Systems::BallSystem::Initialize()
|
||||
{
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_Contact, &BallSystem::Contact);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &BallSystem::OnLifeLost);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &BallSystem::OnMultiBallLost);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &BallSystem::OnResetBall);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause);
|
||||
|
||||
//OctoBall
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
transform->Position = glm::vec3(-0.f, 50.26f, -10.f);
|
||||
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
||||
ball->Speed = 5.f;
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
std::shared_ptr<Components::Template> ballTemplate = m_World->AddComponent<Components::Template>(ent);
|
||||
physics->Static = false;
|
||||
physics->Category = CollisionLayer::Type::Ball;
|
||||
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
|
||||
physics->Calculate = true;
|
||||
|
||||
//auto plight = m_World->AddComponent<Components::PointLight>(ent);
|
||||
//plight->Radius = 2.f;
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
|
||||
SetBall(ent);
|
||||
|
||||
auto ent2 = CreateBall();
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
|
||||
transform2->Position = glm::vec3(-0.f, 0.26f, -10.f);
|
||||
transform2->Velocity = glm::vec3(0.0f, -10.f, 0.f);
|
||||
|
||||
m_World->CommitEntity(ent2);
|
||||
}
|
||||
|
||||
for (int i = 0; i < Lives(); i++) {
|
||||
CreateLife(i);
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::Update(double dt)
|
||||
{
|
||||
|
||||
if (Lives() < 0)
|
||||
{
|
||||
SetLives(3);
|
||||
Events::GameOver e;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto ballComponent = m_World->GetComponent<Components::Ball>(entity);
|
||||
if (IsPaused()) {
|
||||
if (ballComponent != nullptr) {
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
if (!ballComponent->Paused) {
|
||||
ballComponent->Paused = true;
|
||||
ballComponent->SavedSpeed = transform->Velocity;
|
||||
transform->Velocity = glm::vec3(0, 0, 0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (ballComponent != nullptr) {
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
if (ballComponent->Paused) {
|
||||
transform->Velocity = ballComponent->SavedSpeed;
|
||||
ballComponent->Paused = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
|
||||
if (templateCheck != nullptr){ return; }
|
||||
|
||||
if (ballComponent != nullptr) {
|
||||
if (ReplaceBall()) {
|
||||
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, -ballComponent->Speed, 0.f);
|
||||
}
|
||||
|
||||
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) {
|
||||
// m_World->RemoveComponent<Components::Ball>(entity);
|
||||
// m_World->RemoveComponent<Components::Transform>(entity);
|
||||
// m_World->RemoveComponent<Components::CircleShape>(entity);
|
||||
// m_World->RemoveComponent<Components::Physics>(entity);
|
||||
transformBall->Velocity = glm::vec3(0, 0, 0);
|
||||
ballComponent->SavedSpeed = glm::vec3(0, 0, 0);
|
||||
m_World->RemoveEntity(entity);
|
||||
Events::MultiBallLost e;
|
||||
EventBroker->Publish(e);
|
||||
} 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->RemoveEntity(entity);
|
||||
SetPastLives(Lives());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ballComponent != nullptr) {
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y));
|
||||
@@ -33,6 +170,20 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
}
|
||||
}
|
||||
|
||||
bool dd::Systems::BallSystem::OnPause(const dd::Events::Pause &event)
|
||||
{
|
||||
if (event.Type != "BallSystem" && event.Type != "All") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsPaused()) {
|
||||
SetPause(false);
|
||||
} else {
|
||||
SetPause(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::OnEntityCommit(EntityID entity)
|
||||
{
|
||||
|
||||
@@ -86,11 +237,17 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
|
||||
if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Pad"){
|
||||
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
|
||||
float x = ballTransform->Position.x - padTransform->Position.x;
|
||||
float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier();
|
||||
|
||||
float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f;
|
||||
|
||||
ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed;
|
||||
ballComponent->Combo = 0;
|
||||
Events::ComboEvent ec;
|
||||
ec.Combo = ballComponent->Combo;
|
||||
ec.Ball = ballEntity;
|
||||
EventBroker->Publish(ec);
|
||||
//std::cout << "Combo: " << ballComponent->Combo << std::endl;
|
||||
}
|
||||
else {
|
||||
glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal);
|
||||
@@ -99,3 +256,79 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
EntityID dd::Systems::BallSystem::CreateBall()
|
||||
{
|
||||
auto ent = m_World->CloneEntity(Ball());
|
||||
|
||||
m_World->RemoveComponent<Components::Template>(ent);
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
|
||||
return ent;
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::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);
|
||||
}
|
||||
|
||||
bool dd::Systems::BallSystem::OnLifeLost(const dd::Events::LifeLost &event)
|
||||
{
|
||||
SetLives(Lives() - 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::BallSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event)
|
||||
{
|
||||
SetMultiBalls(MultiBalls()-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::BallSystem::OnResetBall(const dd::Events::ResetBall &event)
|
||||
{
|
||||
SetReplaceBall(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::BallSystem::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;
|
||||
//std::cout << "1: " <<transform1->Velocity.x << " " << transform1->Velocity.y << std::endl;
|
||||
//std::cout << "2: " <<transform2->Velocity.x << " " << transform2->Velocity.y << std::endl;
|
||||
|
||||
SetMultiBalls(MultiBalls() + 2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-30.
|
||||
//
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Game/HitLagSystem.h"
|
||||
|
||||
void dd::Systems::HitLagSystem::Initialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &HitLagSystem::OnPause);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EHitLag, &HitLagSystem::OnHitLag);
|
||||
}
|
||||
|
||||
void dd::Systems::HitLagSystem::Update(double dt)
|
||||
{
|
||||
if (IsPaused()) {
|
||||
if (HitLag()) {
|
||||
SetHitLagTimer(HitLagTimer() += dt);
|
||||
if (HitLagDuration() < HitLagTimer()) {
|
||||
SetHitLagTimer(0);
|
||||
SetHitLag(false);
|
||||
FlipPause();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::HitLagSystem::FlipPause()
|
||||
{
|
||||
Events::Pause e;
|
||||
e.Type = CurrentType();
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
bool dd::Systems::HitLagSystem::OnPause(const dd::Events::Pause &event)
|
||||
{
|
||||
if (IsPaused()) {
|
||||
SetPause(false);
|
||||
} else {
|
||||
SetPause(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::HitLagSystem::OnHitLag(const dd::Events::HitLag &event)
|
||||
{
|
||||
if (HitLag()) {
|
||||
FlipPause();
|
||||
}
|
||||
SetHitLag(true);
|
||||
SetCurrentType(event.Type);
|
||||
FlipPause();
|
||||
SetHitLagDuration(event.Time);
|
||||
return true;
|
||||
}
|
||||
+65
-148
@@ -10,136 +10,50 @@
|
||||
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_EMultiBallLost, &LevelSystem::OnMultiBallLost);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, &LevelSystem::OnPowerUpTaken);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &LevelSystem::OnStageCleared);
|
||||
|
||||
for (int i = 0; i < Lives(); i++) {
|
||||
CreateLife(i);
|
||||
}
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &LevelSystem::OnPause);
|
||||
|
||||
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)
|
||||
{
|
||||
if (IsPaused()) {
|
||||
return;
|
||||
}
|
||||
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
|
||||
if (templateCheck != nullptr){ return; }
|
||||
|
||||
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());
|
||||
if (NumberOfBricks() <= 0 && Restarting() == false) {
|
||||
/*if (MultiBalls() <= 0 && PowerUps() <= 0) {
|
||||
//Events::StageCleared ec;
|
||||
//EventBroker->Publish(ec);
|
||||
} 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);
|
||||
SetMultiBalls(MultiBalls()-1);
|
||||
transformBall->Velocity = glm::vec3(0, 0, 0);
|
||||
ball->SavedSpeed = glm::vec3(0, 0, 0);
|
||||
m_World->RemoveEntity(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);
|
||||
}
|
||||
}
|
||||
@@ -147,18 +61,31 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
}
|
||||
}
|
||||
|
||||
bool dd::Systems::LevelSystem::OnPause(const dd::Events::Pause &event)
|
||||
{
|
||||
if (event.Type != "LevelSystem" && event.Type != "All") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsPaused()) {
|
||||
SetPause(false);
|
||||
} else {
|
||||
SetPause(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
int num = Lines();
|
||||
for (int i = 0; i < rows; i++) {
|
||||
num++;
|
||||
num--;
|
||||
for (int j = 0; j < Lines(); j++) {
|
||||
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num);
|
||||
}
|
||||
if (num == 7)
|
||||
num = 0;
|
||||
if (num == 1)
|
||||
num = Lines();
|
||||
}
|
||||
|
||||
SetNumberOfBricks(rows * lines);
|
||||
@@ -179,12 +106,8 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
||||
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)) {
|
||||
if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 5 && row == 2)) {
|
||||
std::shared_ptr<Components::PowerUpBrick> cPow = m_World->AddComponent<Components::PowerUpBrick>(brick);
|
||||
}
|
||||
float x = line * spacesBetweenBricks.x;
|
||||
@@ -201,25 +124,9 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
||||
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)
|
||||
@@ -228,6 +135,8 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
EntityID entityBall;
|
||||
auto ball = m_World->GetComponent<Components::Ball>(event.Entity2);
|
||||
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
|
||||
|
||||
//This code ensures that it is a brick and a ball that has come into contact.
|
||||
if (brick != nullptr) {
|
||||
entityBrick = event.Entity1;
|
||||
} else {
|
||||
@@ -255,7 +164,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
}
|
||||
|
||||
auto power = m_World->GetComponent<Components::PowerUpBrick>(entityBrick);
|
||||
if (power != nullptr) {
|
||||
if (power != nullptr && NumberOfBricks() > 1) {
|
||||
Events::CreatePowerUp e;
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entityBrick);
|
||||
e.Position = transform->Position;
|
||||
@@ -263,13 +172,13 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
}
|
||||
|
||||
if (ball != nullptr && Restarting() == false) {
|
||||
auto ballTransform = m_World->GetComponent<Components::Transform>(entityBall);
|
||||
ball->Combo += 1;
|
||||
Events::ComboEvent ec;
|
||||
ec.Combo = ball->Combo;
|
||||
ec.Ball = entityBall;
|
||||
EventBroker->Publish(ec);
|
||||
|
||||
// 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 ballTransform = m_World->GetComponent<Components::Transform>(entityBall);
|
||||
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick);
|
||||
physicsComponent->GravityScale = 1.f;
|
||||
@@ -289,28 +198,21 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
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;
|
||||
es.Score = brick->Score * ball->Combo;
|
||||
EventBroker->Publish(es);
|
||||
|
||||
// std::cout << NumberOfBricks() << std::endl;
|
||||
//std::cout << "Combo: " << ball->Combo << std::endl;
|
||||
//std::cout << NumberOfBricks() << std::endl;
|
||||
//std::cout << "Brick Score: " << brick->Score << std::endl;
|
||||
//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);
|
||||
@@ -321,6 +223,15 @@ bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
|
||||
bool dd::Systems::LevelSystem::OnMultiBall(const dd::Events::MultiBall &event)
|
||||
{
|
||||
SetMultiBalls(MultiBalls()+2);
|
||||
//std::cout << MultiBalls() << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::LevelSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event)
|
||||
{
|
||||
SetMultiBalls(MultiBalls()-1);
|
||||
//std::cout << MultiBalls() << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &event)
|
||||
@@ -357,6 +268,12 @@ bool dd::Systems::LevelSystem::OnPowerUpTaken(const dd::Events::PowerUpTaken &ev
|
||||
|
||||
bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &event)
|
||||
{
|
||||
SetRestarting(true);
|
||||
Events::ResetBall e;
|
||||
EventBroker->Publish(e);
|
||||
Events::ScoreEvent es;
|
||||
es.Score = 500;
|
||||
EventBroker->Publish(es);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+60
-118
@@ -26,27 +26,42 @@ void dd::Systems::PadSystem::Initialize()
|
||||
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);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause);
|
||||
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
m_World->SetProperty(ent, "Name", "Pad");
|
||||
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
|
||||
ctransform->Position = glm::vec3(0.f, -3.5f, -10.f);
|
||||
ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f);
|
||||
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;
|
||||
physics->Category = CollisionLayer::Type::Pad;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::PowerUp;
|
||||
physics->Calculate = true;
|
||||
auto cModel = m_World->AddComponent<Components::Model>(ent);
|
||||
cModel->ModelFile = "Models/Submarine2.obj";
|
||||
|
||||
auto pad = m_World->AddComponent<Components::Pad>(ent);
|
||||
m_World->CommitEntity(ent);
|
||||
|
||||
SetEdge(3.2 - (ctransform->Scale.x / 2));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
|
||||
if (templateCheck != nullptr){ return; }
|
||||
}
|
||||
|
||||
void dd::Systems::PadSystem::Update(double dt)
|
||||
{
|
||||
if (IsPaused()) {
|
||||
return;
|
||||
}
|
||||
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") {
|
||||
@@ -69,9 +84,15 @@ void dd::Systems::PadSystem::Update(double dt)
|
||||
transform->Velocity.x = pad->MaxSpeed;
|
||||
}
|
||||
transform->Position += transform->Velocity * (float)dt;
|
||||
if (transform->Position.x > Edge()) {
|
||||
transform->Position.x = Edge();
|
||||
} else if (transform->Position.x < -Edge()) {
|
||||
transform->Position.x = -Edge();
|
||||
}
|
||||
transform->Velocity += acceleration * (float)dt;
|
||||
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
|
||||
|
||||
if (glm::abs(transform->Velocity.x) > 1 || (!Left() && !Right())) {
|
||||
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float) dt;
|
||||
}
|
||||
|
||||
if (Left()) {
|
||||
acceleration.x = -pad->AccelerationSpeed;
|
||||
@@ -85,38 +106,21 @@ void dd::Systems::PadSystem::Update(double dt)
|
||||
SetPad(pad);
|
||||
SetAcceleration(acceleration);
|
||||
|
||||
if (MultiBall() == true) {
|
||||
SetMultiBall(false);
|
||||
|
||||
Events::MultiBall e;
|
||||
e.padTransform = transform;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
EntityID dd::Systems::PadSystem::CreateBall()
|
||||
bool dd::Systems::PadSystem::OnPause(const dd::Events::Pause &event)
|
||||
{
|
||||
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;
|
||||
physics->Category = CollisionLayer::Type::Ball;
|
||||
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
|
||||
physics->Calculate = true;
|
||||
cball->Speed = 5.f;
|
||||
if (event.Type != "PadSystem" && event.Type != "All") {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
|
||||
return ent;
|
||||
if (IsPaused()) {
|
||||
SetPause(false);
|
||||
} else {
|
||||
SetPause(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
||||
@@ -135,9 +139,21 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
||||
//acceleration.x = 0.01f;
|
||||
SetRight(true);
|
||||
} else if (val == GLFW_KEY_R) {
|
||||
SetReplaceBall(true);
|
||||
Events::ResetBall e;
|
||||
EventBroker->Publish(e);
|
||||
} else if (val == GLFW_KEY_M) {
|
||||
SetMultiBall(true);
|
||||
Events::MultiBall e;
|
||||
e.padTransform = Transform();
|
||||
EventBroker->Publish(e);
|
||||
} else if (val == GLFW_KEY_P) {
|
||||
Events::Pause e;
|
||||
e.Type = "All";
|
||||
EventBroker->Publish(e);
|
||||
} else if (val == GLFW_KEY_H) {
|
||||
Events::HitLag e;
|
||||
e.Time = 0.2;
|
||||
e.Type = "All";
|
||||
EventBroker->Publish(e);
|
||||
} else if (val == GLFW_KEY_D) {
|
||||
return false;
|
||||
}
|
||||
@@ -161,47 +177,7 @@ bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
|
||||
|
||||
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;
|
||||
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2)+ 0.2;
|
||||
//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)
|
||||
@@ -236,9 +212,6 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
|
||||
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";
|
||||
@@ -251,40 +224,9 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
|
||||
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();
|
||||
//auto entity = CreateBall();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
+296
-144
@@ -1,44 +1,38 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Physics/PhysicsSystem.h"
|
||||
|
||||
|
||||
|
||||
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.0/60.0;
|
||||
m_VelocityIterations = 6;
|
||||
m_PositionIterations = 2;
|
||||
m_Accumulator = 0.0;
|
||||
|
||||
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
||||
|
||||
InitializeWater();
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause);
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::InitializeWater()
|
||||
{
|
||||
b2ParticleSystemDef m_ParticleSystemDef;
|
||||
m_ParticleSystemDef.radius = 0.13f;
|
||||
|
||||
m_ParticleSystem = m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
||||
float radius = 0.13f;
|
||||
float gravityScale = 1.0f;
|
||||
CreateParticleSystem(radius, gravityScale);
|
||||
}
|
||||
|
||||
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
||||
{
|
||||
b2Body* body = m_EntitiesToBodies[event.Entity];
|
||||
|
||||
if (body == nullptr) {
|
||||
LOG_ERROR("Entity: %i, Tried to set an impulse on a body that does not exsist", event.Entity);
|
||||
return false;
|
||||
}
|
||||
|
||||
b2Vec2 impulse;
|
||||
impulse.x = event.Impulse.x;
|
||||
impulse.y = event.Impulse.y;
|
||||
@@ -47,123 +41,153 @@ bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
||||
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::SyncEntitiesWithBodies()
|
||||
{
|
||||
|
||||
for (auto i : m_EntitiesToBodies) {
|
||||
EntityID entity = i.first;
|
||||
b2Body* body = i.second;
|
||||
|
||||
if (body == nullptr) {
|
||||
LOG_ERROR("This body should not exist, please fix this");
|
||||
continue;
|
||||
}
|
||||
|
||||
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 (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);
|
||||
|
||||
b2Filter filter;
|
||||
filter.categoryBits = physicsComponent->Category;
|
||||
filter.maskBits = physicsComponent->Mask;
|
||||
body->GetFixtureList()->SetFilterData(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::SyncBodiesWithEntities()
|
||||
{
|
||||
for (auto i : m_BodiesToEntities) {
|
||||
b2Body* body = i.first;
|
||||
EntityID entity = i.second;
|
||||
|
||||
if (body == nullptr) {
|
||||
LOG_ERROR("This body should not exist, please fix this");
|
||||
continue;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
auto parent = m_World->GetEntityParent(entity);
|
||||
if (parent == 0) {
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
|
||||
if (physicsComponent->Calculate) { //TODO: REPLACE THIS WITH PARTICLE COLLISION FILTERS
|
||||
transformComponent->Position.x = transformComponent->Position.x + (transformComponent->Velocity.x * m_TimeStep);
|
||||
transformComponent->Position.y = transformComponent->Position.y + (transformComponent->Velocity.y * m_TimeStep);
|
||||
} else {
|
||||
b2Vec2 position = body->GetPosition();
|
||||
transformComponent->Position.x = position.x;
|
||||
transformComponent->Position.y = position.y;
|
||||
|
||||
float angle = body->GetAngle();
|
||||
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, angle));
|
||||
|
||||
b2Vec2 velocity = body->GetLinearVelocity();
|
||||
transformComponent->Velocity.x = velocity.x;
|
||||
transformComponent->Velocity.y = velocity.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
{
|
||||
if (m_Pause) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
b2Filter filter;
|
||||
filter.categoryBits = physicsComponent->Category;
|
||||
filter.maskBits = physicsComponent->Mask;
|
||||
body->GetFixtureList()->SetFilterData(filter);
|
||||
}
|
||||
}
|
||||
UpdateParticleEmitters(dt);
|
||||
SyncEntitiesWithBodies();
|
||||
|
||||
//Apply Impulses Must be done after SyncEntitiesWithBodies
|
||||
for (auto i : m_Impulses) {
|
||||
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
|
||||
}
|
||||
m_Impulses.clear();
|
||||
|
||||
|
||||
//Update the PhysicsWorld
|
||||
m_PhysicsWorld->Step(m_TimeStep, m_VelocityIterations, m_PositionIterations);
|
||||
|
||||
SyncBodiesWithEntities();
|
||||
|
||||
|
||||
for (auto i : m_EntitiesToBodies) {
|
||||
EntityID entity = i.first;
|
||||
b2Body* body = i.second;
|
||||
for ( int e = 0; e < m_EntitiesToParticleHandle.size(); e++) {
|
||||
b2Vec2 *positionBuffer = m_ParticleSystem[e]->GetPositionBuffer();
|
||||
for (auto i : m_EntitiesToParticleHandle[e]) {
|
||||
EntityID entity = i.first;
|
||||
b2ParticleHandle *particleH = i.second;
|
||||
|
||||
if (body == nullptr) {
|
||||
LOG_ERROR("This body should not exist");
|
||||
continue;
|
||||
}
|
||||
b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()];
|
||||
glm::vec2 position = glm::vec2(positionB2.x, positionB2.y);
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (! transformComponent)
|
||||
continue;
|
||||
auto parent = m_World->GetEntityParent(entity);
|
||||
if (parent == 0) {
|
||||
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
if (physicsComponent->Calculate) { //TODO: REPLACE THIS WITH PARTICLE COLLISION FILTERS
|
||||
transformComponent->Position.x = transformComponent->Position.x + (transformComponent->Velocity.x * m_TimeStep);
|
||||
transformComponent->Position.y = transformComponent->Position.y + (transformComponent->Velocity.y * m_TimeStep);
|
||||
EntityID entityParent = m_World->GetEntityParent(entity);
|
||||
glm::vec3 parentTransform = glm::vec3(0.f);
|
||||
if (entityParent) {
|
||||
auto tp = m_World->GetComponent<Components::Transform>(entityParent);
|
||||
parentTransform = tp->Position;
|
||||
}
|
||||
else {
|
||||
b2Vec2 position = body->GetPosition();
|
||||
transformComponent->Position.x = position.x;
|
||||
transformComponent->Position.y = position.y;
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
float angle = body->GetAngle();
|
||||
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, angle));
|
||||
transform->Position = glm::vec3(position.x, position.y, -10) - parentTransform;
|
||||
|
||||
b2Vec2 velocity = body->GetLinearVelocity();
|
||||
transformComponent->Velocity.x = velocity.x;
|
||||
transformComponent->Velocity.y = velocity.y;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
m_Accumulator -= dt;
|
||||
}
|
||||
}
|
||||
@@ -173,19 +197,41 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
||||
|
||||
}
|
||||
|
||||
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
||||
{
|
||||
if (event.Type != "PhysicsSystem" && event.Type != "All") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_Pause) {
|
||||
m_Pause = false;
|
||||
} else {
|
||||
m_Pause = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
|
||||
{
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
auto waterComponent = m_World->GetComponent<Components::WaterVolume>(entity);
|
||||
auto particleEmitterComponent = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
||||
|
||||
if (physicsComponent && waterComponent) {
|
||||
LOG_ERROR("Entity has both water and physics component, this is illegal. The police has been alerted.");
|
||||
return;
|
||||
}
|
||||
if (physicsComponent && particleEmitterComponent) {
|
||||
LOG_ERROR("Entity has both particle and physics component, this is illegal. The police has been alerted.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (physicsComponent) {
|
||||
CreateBody(entity);
|
||||
} else if (waterComponent) {
|
||||
CreateParticleGroup(entity);
|
||||
} else if (particleEmitterComponent) {
|
||||
CreateParticleEmitter(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,14 +244,16 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
||||
}
|
||||
|
||||
b2Body* body = m_EntitiesToBodies[entity];
|
||||
|
||||
if (body != nullptr) {
|
||||
m_EntitiesToBodies.erase(entity);
|
||||
m_BodiesToEntities.erase(body);
|
||||
|
||||
m_PhysicsWorld->DestroyBody(body);
|
||||
if (body == nullptr) {
|
||||
LOG_ERROR("Trying to remove non-exsisting body, Entity: %i", entity);
|
||||
return;
|
||||
}
|
||||
|
||||
m_EntitiesToBodies.erase(entity);
|
||||
m_BodiesToEntities.erase(body);
|
||||
|
||||
body->GetWorld()->DestroyBody(body);
|
||||
//delete body;
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +265,6 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if(!transformComponent) {
|
||||
LOG_ERROR("No TransformComponent in CreateBody");
|
||||
@@ -250,14 +297,11 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
||||
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;
|
||||
|
||||
if (absoluteTransform.Scale.x != absoluteTransform.Scale.y && absoluteTransform.Scale.y != absoluteTransform.Scale.z) {
|
||||
LOG_WARNING("Circles has to be of uniform scale. xScale has been used for radius");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,20 +311,21 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
||||
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 = 10.f;
|
||||
fixtureDef.restitution = 1.0f;
|
||||
fixtureDef.friction = 0.0f;
|
||||
body->CreateFixture(&fixtureDef);
|
||||
|
||||
}
|
||||
fixtureDef.shape = pShape;
|
||||
fixtureDef.density = 10.f;
|
||||
fixtureDef.restitution = 1.0f;
|
||||
fixtureDef.friction = 0.0f;
|
||||
body->CreateFixture(&fixtureDef);
|
||||
|
||||
|
||||
delete pShape;
|
||||
|
||||
if(physicsComponent->Static) {
|
||||
body->SetType(b2BodyType::b2_staticBody);
|
||||
} else if (! physicsComponent->Static) {
|
||||
body->SetType(b2BodyType::b2_dynamicBody);
|
||||
}
|
||||
|
||||
body->SetGravityScale(physicsComponent->GravityScale);
|
||||
m_EntitiesToBodies.insert(std::make_pair(entity, body));
|
||||
@@ -289,46 +334,153 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID 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;
|
||||
auto water = m_World->GetComponent<Components::WaterVolume>(e);
|
||||
if (water) {
|
||||
|
||||
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);
|
||||
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);
|
||||
t_ParticleGroup.push_back(m_ParticleSystem[0]->CreateParticleGroup(pd));
|
||||
b2Vec2* t_ParticlePositions = m_ParticleSystem[0]->GetPositionBuffer();
|
||||
for(int i = 0; i < m_ParticleSystem[0]->GetParticleCount(); i++){
|
||||
{
|
||||
auto t_waterparticle = m_World->CreateEntity(e);
|
||||
auto transformChild = m_World->AddComponent<Components::Transform>(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);
|
||||
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[0]->GetRadius())/transform->Scale;
|
||||
m_World->CommitEntity(t_waterparticle);
|
||||
|
||||
m_EntitiesToParticleHandle[0].insert(std::make_pair(t_waterparticle, m_ParticleSystem[0]->GetParticleHandleFromIndex(i)));
|
||||
m_ParticleHandleToEntities[0].insert(std::make_pair( m_ParticleSystem[0]->GetParticleHandleFromIndex(i), 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());
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
{
|
||||
for (int i = 0; i < m_ParticleEmitters.ParticleSystem.size(); i++) {
|
||||
auto e = m_ParticleEmitters.ParticleEmitter[i];
|
||||
auto pt = m_ParticleEmitters.ParticleTemplate[i];
|
||||
auto ps = m_ParticleEmitters.ParticleSystem[i];
|
||||
|
||||
|
||||
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(e);
|
||||
auto particleTemplate = m_World->GetComponent<Components::Particle>(pt);
|
||||
emitter->TimeSinceLastSpawn += dt;
|
||||
if(emitter->TimeSinceLastSpawn < emitter->SpawnRate) {
|
||||
continue;
|
||||
}
|
||||
emitter->TimeSinceLastSpawn -= emitter->SpawnRate;
|
||||
auto templateTransform = m_World->GetComponent<Components::Transform>(pt);
|
||||
|
||||
b2ParticleDef particleDef;
|
||||
particleDef.flags = particleTemplate->Flags;
|
||||
//particleDef.color TODO: Implement this if we want color mixing and shit.
|
||||
particleDef.lifetime = particleTemplate->LifeTime;
|
||||
particleDef.velocity = b2Vec2(templateTransform->Velocity.x, templateTransform->Velocity.y);
|
||||
particleDef.position = b2Vec2(templateTransform->Position.x, templateTransform->Position.y);
|
||||
|
||||
auto particle = m_World->CloneEntity(pt, 0);
|
||||
m_World->RemoveComponent<Components::Template>(particle);
|
||||
|
||||
auto b2Particle = ps->CreateParticle(particleDef);
|
||||
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
|
||||
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
||||
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
||||
|
||||
//TODO: Ta bort detta
|
||||
int particles = 0;
|
||||
for (auto i : m_EntitiesToParticleHandle)
|
||||
{
|
||||
particles += i.size();
|
||||
}
|
||||
LOG_INFO("--I have %i particles.", particles);
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::CreateParticleEmitter(EntityID entity)
|
||||
{
|
||||
auto childEntities = m_World->GetEntityChildren(entity);
|
||||
if (childEntities.empty()) {
|
||||
LOG_ERROR("Particle Emitter does not have any child. Please adopt one or this will not work.");
|
||||
return;
|
||||
}
|
||||
int pf = 0;
|
||||
dd::Components::Particle* particle;
|
||||
EntityID childEntity;
|
||||
for ( auto c : childEntities ) {
|
||||
auto p = m_World->GetComponent<Components::Particle>(c);
|
||||
auto particleTemplate = m_World->GetComponent<Components::Template>(c);
|
||||
if (!p) {
|
||||
continue;
|
||||
LOG_WARNING("--ParticleEmitter's Child is not a particle.");
|
||||
}
|
||||
if(!particleTemplate) {
|
||||
LOG_ERROR("ParticleEmitter's particleChild is not a template.");
|
||||
continue;
|
||||
}
|
||||
if (pf != 0) {
|
||||
LOG_WARNING("ParticleEmitter has more than one child that is a particleTemplate, only the first one is used.");
|
||||
break;
|
||||
}
|
||||
childEntity = c;
|
||||
particle = p;
|
||||
pf++;
|
||||
}
|
||||
//TODO: Skicka med fler flaggor till particlesystemet;
|
||||
m_ParticleEmitters.ParticleSystem.push_back(CreateParticleSystem(particle->Radius, 0.f));
|
||||
m_ParticleEmitters.ParticleEmitter.push_back(entity);
|
||||
m_ParticleEmitters.ParticleTemplate.push_back(childEntity);
|
||||
}
|
||||
|
||||
|
||||
b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius, float gravityScale)
|
||||
{
|
||||
std::unordered_map<EntityID, const b2ParticleHandle*> m1;
|
||||
std::unordered_map<const b2ParticleHandle*, EntityID> m2;
|
||||
m_EntitiesToParticleHandle.push_back(m1);
|
||||
m_ParticleHandleToEntities.push_back(m2);
|
||||
|
||||
b2ParticleSystemDef m_ParticleSystemDef;
|
||||
m_ParticleSystemDef.radius = radius;
|
||||
m_ParticleSystemDef.gravityScale = gravityScale;
|
||||
|
||||
m_ParticleSystem.push_back(m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef));
|
||||
|
||||
return m_ParticleSystem.back();
|
||||
}
|
||||
|
||||
dd::Systems::PhysicsSystem::~PhysicsSystem()
|
||||
{
|
||||
for (auto i = m_BodiesToEntities.begin(); i != m_BodiesToEntities.end(); i++) {
|
||||
b2Body* body = i->first;
|
||||
body->GetWorld()->DestroyBody(body);
|
||||
//delete body;
|
||||
}
|
||||
m_BodiesToEntities.clear();
|
||||
m_EntitiesToBodies.clear();
|
||||
m_Impulses.clear();
|
||||
|
||||
//TODO:REMOVE PARTICLE SYSTEMS
|
||||
|
||||
if (m_ContactListener != nullptr) {
|
||||
delete m_ContactListener;
|
||||
m_ContactListener = nullptr;
|
||||
}
|
||||
|
||||
if (m_PhysicsWorld != nullptr) {
|
||||
delete m_PhysicsWorld;
|
||||
m_PhysicsWorld = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Sound/SoundSystem.h"
|
||||
|
||||
dd::Systems::SoundSystem::~SoundSystem()
|
||||
{
|
||||
alcCloseDevice(m_Device);
|
||||
};
|
||||
|
||||
void dd::Systems::SoundSystem::Initialize()
|
||||
{
|
||||
//initialize OpenAL
|
||||
m_Device = alcOpenDevice(NULL);
|
||||
ALCcontext* context;
|
||||
|
||||
if (m_Device) {
|
||||
context = alcCreateContext(m_Device, NULL);
|
||||
alcMakeContextCurrent(context);
|
||||
}
|
||||
else {
|
||||
LOG_ERROR("OpenAL failed to initialize.");
|
||||
}
|
||||
alGetError();
|
||||
|
||||
//Subscribe to events
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume);
|
||||
|
||||
<<<<<<< HEAD
|
||||
//Todo: Move this
|
||||
{
|
||||
dd::Events::PlaySound e;
|
||||
e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav";
|
||||
e.IsAmbient = true;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
{
|
||||
dd::Events::PlaySound e;
|
||||
e.FilePath = "Sounds/BGM/water-flowing.wav";
|
||||
e.Gain = 0.3f;
|
||||
e.IsAmbient = true;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
=======
|
||||
|
||||
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
||||
void dd::Systems::SoundSystem::Update(double dt)
|
||||
{
|
||||
//Clean up none-active sources
|
||||
//Only used for SFX's. BGM's are handled on stop sound.
|
||||
std::vector<ALuint> deleteList;
|
||||
for (auto& item : m_SFXSourcesToBuffers) {
|
||||
ALint sourceState;
|
||||
alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState);
|
||||
if (sourceState == AL_STOPPED) {
|
||||
deleteList.push_back(item.first);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < deleteList.size(); i++) {
|
||||
alDeleteSources(1, &deleteList[i]);
|
||||
//alDeleteBuffers(1, &m_SourcesToBuffers[deleteList[i]]);
|
||||
m_SFXSourcesToBuffers.erase(deleteList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
ALuint dd::Systems::SoundSystem::CreateSource()
|
||||
{
|
||||
ALuint source;
|
||||
alGenSources((ALuint)1, &source);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
|
||||
{
|
||||
//Loading and binding sound buffer to source
|
||||
Sound *sound = ResourceManager::Load<Sound>(event.FilePath);
|
||||
if (sound == nullptr) {
|
||||
return false;
|
||||
}
|
||||
ALuint source = CreateSource();
|
||||
ALuint buffer = sound->Buffer();
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
|
||||
//Sound settings
|
||||
float relativeVolume = 1.f;
|
||||
if (event.IsAmbient) {
|
||||
alSourcei(source, AL_LOOPING, AL_TRUE);
|
||||
relativeVolume = m_BGMMasterVolume;
|
||||
m_BGMSourcesToBuffers[source] = sound;
|
||||
|
||||
}
|
||||
else if (!event.IsAmbient)
|
||||
{
|
||||
m_SFXSourcesToBuffers[source] = sound;
|
||||
alSourcei(source, AL_LOOPING, AL_FALSE);
|
||||
relativeVolume = m_SFXMasterVolume;
|
||||
}
|
||||
|
||||
alSourcef(source, AL_GAIN, (event.Gain * relativeVolume));
|
||||
alSourcef(source, AL_PITCH, event.Pitch);
|
||||
|
||||
|
||||
//Play
|
||||
alSourcePlay(source);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event)
|
||||
{
|
||||
ALuint itemToDeleted;
|
||||
for (auto& item : m_BGMSourcesToBuffers)
|
||||
{
|
||||
if (item.second->Path() == event.FilePath) {
|
||||
itemToDeleted = item.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
alSourceStop(itemToDeleted);
|
||||
alDeleteSources(1, &itemToDeleted);
|
||||
m_BGMSourcesToBuffers.erase(itemToDeleted);
|
||||
|
||||
//Should not happen because SFX's should be very short.
|
||||
for (auto item : m_SFXSourcesToBuffers)
|
||||
{
|
||||
if (item.second->Path() == event.FilePath) {
|
||||
alSourceStop(item.first);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event)
|
||||
{
|
||||
//TODO: Make the Gain depend on the value given when stored.
|
||||
//TODO: .. now it ONLY uses the master Gain
|
||||
if (event.IsAmbient) {
|
||||
m_BGMMasterVolume = event.Gain;
|
||||
for (auto& item : m_BGMSourcesToBuffers)
|
||||
{
|
||||
alSourcef(item.first, AL_GAIN, event.Gain);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (!event.IsAmbient) {
|
||||
m_SFXMasterVolume = event.Gain;
|
||||
for (auto& item : m_SFXSourcesToBuffers)
|
||||
{
|
||||
alSourcef(item.first, AL_GAIN, event.Gain);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
||||
{
|
||||
//Check which entity has the collisionSound component.
|
||||
auto collisionSound = m_World->GetComponent<Components::CollisionSound>(event.Entity1);
|
||||
if (collisionSound == nullptr) {
|
||||
collisionSound = m_World->GetComponent<Components::CollisionSound>(event.Entity2);
|
||||
if (collisionSound == nullptr) {
|
||||
//None of the entities had a collisionSound component.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Send play-sound event
|
||||
dd::Events::PlaySound e;
|
||||
e.FilePath = collisionSound->FilePath;
|
||||
e.IsAmbient = false;
|
||||
EventBroker->Publish(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "Core/World.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Physics/PhysicsSystem.h"
|
||||
#include "Transform/TransformSystem.h"
|
||||
|
||||
#include "Physics/CPhysics.h"
|
||||
#include "Physics/CRectangleShape.h"
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace dd;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RemovePhysicsSystemTest)
|
||||
{
|
||||
// Setup world
|
||||
std::shared_ptr<EventBroker> eventBroker = std::make_shared<EventBroker>();
|
||||
World world(eventBroker);
|
||||
|
||||
world.SystemFactory.Register<Systems::TransformSystem>(
|
||||
[this]() { return new Systems::TransformSystem(&world, eventBroker); });
|
||||
world.AddSystem<Systems::TransformSystem>();
|
||||
|
||||
world.SystemFactory.Register<Systems::PhysicsSystem>(
|
||||
[this]() { return new Systems::PhysicsSystem(&world, eventBroker); });
|
||||
world.AddSystem<Systems::PhysicsSystem>();
|
||||
|
||||
world.ComponentFactory.Register<Components::RectangleShape>();
|
||||
world.ComponentFactory.Register<Components::Physics>();
|
||||
|
||||
//Create entity
|
||||
EntityID ent = world.CreateEntity();
|
||||
|
||||
auto transform = world.AddComponent<Components::Transform>(ent);
|
||||
transform->Position = glm::vec3(20.f, 0.f, -10.f);
|
||||
transform->Velocity = glm::vec3(1.f, 3.f, 0.f);
|
||||
transform->Scale = glm::vec3(2.f, 5.f, 1.f);
|
||||
|
||||
auto physics = world.AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;
|
||||
physics->Calculate = true;
|
||||
physics->Category = CollisionLayer::Type::Ball;
|
||||
physics->Mask = CollisionLayer::Type::Brick | CollisionLayer::Type::Pad | CollisionLayer::Wall;
|
||||
physics->GravityScale = 0.f;
|
||||
|
||||
auto rectangle = world.AddComponent<Components::RectangleShape>(ent);
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user