Merge remote-tracking branch 'origin/master' into Physics
Conflicts: include/Core/Engine.h include/Physics/PhysicsSystem.h src/game/Game/PadSystem.cpp src/game/Physics/PhysicsSystem.cpp
This commit is contained in:
+61
-38
@@ -52,6 +52,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 +113,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,11 +122,16 @@ 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::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();
|
||||
|
||||
|
||||
@@ -136,12 +139,14 @@ public:
|
||||
{
|
||||
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->Position = glm::vec3(-0.f, 0.26f, -10.f);
|
||||
transform->Scale = glm::vec3(0.35f, 0.35f, 0.2f);
|
||||
transform->Velocity = glm::vec3(0.0f, -10.f, 0.f);
|
||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||
model->ModelFile = "Models/Test/Ball/Sid.obj";
|
||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||
circleShape->Radius = 0.35f;
|
||||
|
||||
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);
|
||||
@@ -165,7 +170,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 +181,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 +193,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,6 +208,44 @@ 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
|
||||
{
|
||||
auto t_waterBody = m_World->CreateEntity();
|
||||
@@ -213,6 +256,7 @@ public:
|
||||
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
|
||||
{
|
||||
@@ -222,8 +266,8 @@ public:
|
||||
transform->Scale = glm::vec3(10.f, 0.5f, 1.f);
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
|
||||
topWall);
|
||||
std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(topWall);
|
||||
rectangleShape->Dimensions = glm::vec3(10.f, 0.5f);
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
|
||||
physics->CollisionType = CollisionType::Type::Static;
|
||||
m_World->CommitEntity(topWall);
|
||||
@@ -267,8 +311,8 @@ public:
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
|
||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
|
||||
topWall);
|
||||
std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(topWall);
|
||||
rectangleShape->Dimensions = glm::vec3(20.f, 0.5f);
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
|
||||
physics->CollisionType = CollisionType::Type::Static;
|
||||
@@ -288,8 +332,8 @@ public:
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
|
||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
|
||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
|
||||
leftWall);
|
||||
std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(leftWall);
|
||||
rectangleShape->Dimensions = glm::vec3(0.5f, 20.f);
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(leftWall);
|
||||
physics->CollisionType = CollisionType::Type::Static;
|
||||
@@ -309,35 +353,16 @@ public:
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
|
||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
|
||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
|
||||
rightWall);
|
||||
std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(rightWall);
|
||||
rectangleShape->Dimensions = glm::vec3(0.5f, 20.f);
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(rightWall);
|
||||
physics->CollisionType = CollisionType::Type::Static;
|
||||
physics->Category = CollisionLayer::Type::Wall;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
|
||||
|
||||
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->CollisionType = CollisionType::Type::Kinematic;
|
||||
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);
|
||||
@@ -360,7 +385,7 @@ public:
|
||||
// Swap event queues to get fresh input data in the read queue
|
||||
//m_EventBroker->Swap();
|
||||
|
||||
ResourceManager::Update();
|
||||
//ResourceManager::Update();
|
||||
if (m_GameIsRunning) {
|
||||
m_World->Update(dt);
|
||||
}
|
||||
@@ -449,7 +474,6 @@ public:
|
||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||
if (spriteComponent)
|
||||
{
|
||||
|
||||
std::string normal = spriteComponent->NormalTexture;
|
||||
std::string spec = spriteComponent->SpecularTexture;
|
||||
|
||||
@@ -472,7 +496,6 @@ public:
|
||||
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//TODO: Get this out of engine.h
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
|
||||
#define EVENT_SUBSCRIBE_MEMBER(relay, handler) \
|
||||
relay = decltype(relay)(std::bind(handler, this, std::placeholders::_1)); \
|
||||
@@ -123,16 +124,23 @@ public:
|
||||
void Unsubscribe(BaseEventRelay &relay);
|
||||
|
||||
private:
|
||||
bool m_IsProcessing = false;
|
||||
|
||||
typedef std::string ContextTypeName_t; // typeid(ContextType).name()
|
||||
typedef std::string EventTypeName_t; // typeid(EventType).name()
|
||||
|
||||
typedef std::unordered_multimap<EventTypeName_t, BaseEventRelay*> EventRelays_t;
|
||||
typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t;
|
||||
ContextRelays_t m_ContextRelays;
|
||||
std::vector<BaseEventRelay*> m_RelaysToSubscribe;
|
||||
std::vector<BaseEventRelay*> m_RelaysToUnsubscribe;
|
||||
|
||||
typedef std::list<std::pair<EventTypeName_t, std::shared_ptr<Event>>> EventQueue_t;
|
||||
std::shared_ptr<EventQueue_t> m_EventQueueRead;
|
||||
std::shared_ptr<EventQueue_t> m_EventQueueWrite;
|
||||
|
||||
void subscribeImmediate(BaseEventRelay& relay);
|
||||
void unsubscribeImmediate(BaseEventRelay& relay);
|
||||
};
|
||||
|
||||
template <typename EventType>
|
||||
|
||||
+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();
|
||||
|
||||
@@ -60,6 +60,10 @@ protected:
|
||||
|
||||
virtual bool OnMouseMove(const Events::MouseMove& event)
|
||||
{
|
||||
if (Hidden()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
|
||||
if (isOver && !m_MouseIsOver) { // Enter
|
||||
if (!m_IsDown) {
|
||||
@@ -88,6 +92,11 @@ protected:
|
||||
}
|
||||
virtual bool OnMousePress(const Events::MousePress& event)
|
||||
{
|
||||
if (Hidden()) {
|
||||
LOG_DEBUG("Pressed hidden button");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1))) {
|
||||
return false;
|
||||
}
|
||||
@@ -107,6 +116,11 @@ protected:
|
||||
}
|
||||
virtual bool OnMouseRelease(const Events::MouseRelease& event)
|
||||
{
|
||||
if (Hidden()) {
|
||||
LOG_DEBUG("Released hidden button");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
|
||||
if (!isOver && !m_IsDown) {
|
||||
return false;
|
||||
|
||||
+42
-57
@@ -1,6 +1,8 @@
|
||||
#ifndef GUI_NUMBERFRAME_H__
|
||||
#define GUI_NUMBERFRAME_H__
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "GUI/TextureFrame.h"
|
||||
|
||||
namespace dd
|
||||
@@ -14,32 +16,16 @@ public:
|
||||
NumberFrame(Frame* parent, std::string name)
|
||||
: Frame(parent, name)
|
||||
{
|
||||
m_NumberTextures[0] = "Textures/GUI/Numbers/N0.png";
|
||||
m_NumberTextures[1] = "Textures/GUI/Numbers/N1.png";
|
||||
m_NumberTextures[2] = "Textures/GUI/Numbers/N2.png";
|
||||
m_NumberTextures[3] = "Textures/GUI/Numbers/N3.png";
|
||||
m_NumberTextures[4] = "Textures/GUI/Numbers/N4.png";
|
||||
m_NumberTextures[5] = "Textures/GUI/Numbers/N5.png";
|
||||
m_NumberTextures[6] = "Textures/GUI/Numbers/N6.png";
|
||||
m_NumberTextures[7] = "Textures/GUI/Numbers/N7.png";
|
||||
m_NumberTextures[8] = "Textures/GUI/Numbers/N8.png";
|
||||
m_NumberTextures[9] = "Textures/GUI/Numbers/N9.png";
|
||||
|
||||
// Create number frame if missing
|
||||
for (int i = 0; i < 10; i++) {
|
||||
auto frame = new GUI::TextureFrame(this, "NumberFrameDigit");
|
||||
frame->SetTexture(m_NumberTextures[0]);
|
||||
frame->DisableScissor();
|
||||
// Position frame based on alignment
|
||||
if (i > 0) {
|
||||
frame->X = i * 20;
|
||||
}
|
||||
Width += frame->Width;
|
||||
if (Height < frame->Height) {
|
||||
Height = frame->Height;
|
||||
}
|
||||
m_NumberFrames.push_front(frame);
|
||||
}
|
||||
m_CharacterTextures['0'] = "Textures/GUI/Numbers/N0.png";
|
||||
m_CharacterTextures['1'] = "Textures/GUI/Numbers/N1.png";
|
||||
m_CharacterTextures['2'] = "Textures/GUI/Numbers/N2.png";
|
||||
m_CharacterTextures['3'] = "Textures/GUI/Numbers/N3.png";
|
||||
m_CharacterTextures['4'] = "Textures/GUI/Numbers/N4.png";
|
||||
m_CharacterTextures['5'] = "Textures/GUI/Numbers/N5.png";
|
||||
m_CharacterTextures['6'] = "Textures/GUI/Numbers/N6.png";
|
||||
m_CharacterTextures['7'] = "Textures/GUI/Numbers/N7.png";
|
||||
m_CharacterTextures['8'] = "Textures/GUI/Numbers/N8.png";
|
||||
m_CharacterTextures['9'] = "Textures/GUI/Numbers/N9.png";
|
||||
|
||||
SetNumber(0);
|
||||
}
|
||||
@@ -50,41 +36,40 @@ public:
|
||||
m_Number = number;
|
||||
|
||||
// Clear number textures
|
||||
//for (auto& frame : m_NumberFrames) {
|
||||
// frame->SetTexture("");
|
||||
//}
|
||||
for (auto& frame : m_NumberFrames) {
|
||||
frame->SetTexture("");
|
||||
}
|
||||
|
||||
//Width = 0;
|
||||
//Height = 0;
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
|
||||
int n = 0;
|
||||
do {
|
||||
// // Create number frame if missing
|
||||
// if (m_NumberFrames.size() <= n) {
|
||||
// auto frame = new GUI::TextureFrame(this, "NumberFrameDigit");
|
||||
// frame->DisableScissor();
|
||||
// m_NumberFrames.push_front(frame);
|
||||
// }
|
||||
std::string digits = std::to_string(number);
|
||||
|
||||
int i = 0;
|
||||
for (char& c : digits) {
|
||||
// Create number frame if missing
|
||||
if (i >= m_NumberFrames.size()) {
|
||||
auto frame = new GUI::TextureFrame(this, "NumberFrameDigit");
|
||||
if (i > 0) {
|
||||
frame->SetLeft(m_NumberFrames[i - 1]->Right());
|
||||
}
|
||||
frame->DisableScissor();
|
||||
m_NumberFrames.push_back(frame);
|
||||
}
|
||||
|
||||
// Update value
|
||||
int digit = number % 10;
|
||||
m_NumberFrames[n]->SetTexture(m_NumberTextures[digit]);
|
||||
//Width += m_NumberFrames[n]->Width;
|
||||
//if (Height < m_NumberFrames[n]->Height) {
|
||||
// Height = m_NumberFrames[n]->Height;
|
||||
//}
|
||||
// // Position frame based on alignment
|
||||
// if (n > 0) {
|
||||
// if (!m_LeftAligned) {
|
||||
// m_NumberFrames[n]->SetLeft(m_NumberFrames[n - 1]->Right());
|
||||
// } else {
|
||||
// m_NumberFrames[n]->SetRight(m_NumberFrames[n - 1]->Left());
|
||||
// }
|
||||
// }
|
||||
std::string texture = "Textures/Core/ErrorTexture.png";
|
||||
if (m_CharacterTextures.find(c) != m_CharacterTextures.end()) {
|
||||
texture = m_CharacterTextures.at(c);
|
||||
}
|
||||
m_NumberFrames[i]->SetTexture(m_CharacterTextures.at(c));
|
||||
Width += m_NumberFrames[i]->Width;
|
||||
if (Height < m_NumberFrames[i]->Height) {
|
||||
Height = m_NumberFrames[i]->Height;
|
||||
}
|
||||
|
||||
number /= 10;
|
||||
n++;
|
||||
} while (number > 0);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void SetLeftAlign() { m_LeftAligned = true; }
|
||||
@@ -99,7 +84,7 @@ private:
|
||||
int m_Number = 0;
|
||||
bool m_LeftAligned = true;
|
||||
|
||||
std::string m_NumberTextures[10];
|
||||
std::unordered_map<char, std::string> m_CharacterTextures;
|
||||
std::deque<TextureFrame*> m_NumberFrames;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,15 +5,30 @@
|
||||
#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"
|
||||
|
||||
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 +54,53 @@ 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; }
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,7 @@ struct Ball : Component
|
||||
{
|
||||
int Number = 0;
|
||||
float Speed = 5.f;
|
||||
int Combo = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ struct Pad : Component
|
||||
|
||||
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 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,43 @@
|
||||
#ifndef GUI_FPSCOUNTER_H__
|
||||
#define GUI_FPSCOUNTER_H__
|
||||
|
||||
#include "GUI/Frame.h"
|
||||
#include "GUI/NumberFrame.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class FPSCounter : public Frame
|
||||
{
|
||||
public:
|
||||
FPSCounter(Frame* parent, std::string name)
|
||||
: Frame(parent, name)
|
||||
{
|
||||
m_FrameTimes.resize(m_MaxSamples);
|
||||
m_Numbers = new GUI::NumberFrame(this, "FPSCounterNumberFrame");
|
||||
}
|
||||
|
||||
virtual void Update(double dt)
|
||||
{
|
||||
m_FrameTimes[m_CurrentFrame % m_MaxSamples] = dt;
|
||||
double sum = std::accumulate(m_FrameTimes.begin(), m_FrameTimes.end(), 0.0);
|
||||
sum /= std::min(m_CurrentFrame, m_MaxSamples);
|
||||
m_Numbers->SetNumber(std::round(1.0 / sum));
|
||||
|
||||
m_CurrentFrame++;
|
||||
}
|
||||
|
||||
private:
|
||||
NumberFrame* m_Numbers = nullptr;
|
||||
|
||||
int m_MaxSamples = 100;
|
||||
int m_CurrentFrame = 0;
|
||||
std::vector<double> m_FrameTimes;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "GUI/NumberFrame.h"
|
||||
#include "Core/EKeyUp.h"
|
||||
#include "Game/EScoreEvent.h"
|
||||
#include "Game/FPSCounter.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -24,6 +25,15 @@ public:
|
||||
m_LevelIndicator = new GUI::TextureFrame(this, "HUDLevelIndicator");
|
||||
m_LevelIndicator->SetTexture("Textures/GUI/HUD/LevelIndicatorBG.png");
|
||||
|
||||
m_AreaNumberFrame = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
|
||||
m_AreaNumberFrame->X = 132;
|
||||
m_AreaNumberFrame->Y = 19;
|
||||
m_AreaNumberFrame->SetNumber(6);
|
||||
m_StageNumberFrame = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
|
||||
m_StageNumberFrame->X = 165;
|
||||
m_StageNumberFrame->Y = 19;
|
||||
m_StageNumberFrame->SetNumber(5);
|
||||
|
||||
m_ScoreIndicator = new GUI::TextureFrame(this, "HUDScoreIndicator");
|
||||
m_ScoreIndicator->SetTexture("Textures/GUI/HUD/ScoreIndicatorBG.png");
|
||||
m_ScoreIndicator->SetRight(Right());
|
||||
@@ -31,13 +41,18 @@ public:
|
||||
m_ScoreNumberFrame->X = 15;
|
||||
m_ScoreNumberFrame->Y = 21;
|
||||
|
||||
m_FPSCounter = new GUI::FPSCounter(this, "FPSCounter");
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EScore, &HUD::OnScore);
|
||||
}
|
||||
|
||||
private:
|
||||
TextureFrame* m_LevelIndicator = nullptr;
|
||||
TextureFrame* m_ScoreIndicator = nullptr;
|
||||
NumberFrame* m_AreaNumberFrame = nullptr;
|
||||
NumberFrame* m_StageNumberFrame = nullptr;
|
||||
NumberFrame* m_ScoreNumberFrame = nullptr;
|
||||
FPSCounter* m_FPSCounter = nullptr;
|
||||
|
||||
EventRelay<Frame, Events::ScoreEvent> m_EScore;
|
||||
|
||||
|
||||
@@ -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,16 @@
|
||||
#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/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,7 +64,6 @@ 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);
|
||||
@@ -78,10 +80,6 @@ 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; }
|
||||
int& MultiBalls() { return m_MultiBalls; }
|
||||
void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
|
||||
int& PowerUps() { return m_PowerUps; }
|
||||
@@ -99,16 +97,12 @@ 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;
|
||||
int m_MultiBalls = 0;
|
||||
int m_PowerUps = 0;
|
||||
int m_Score = 0;
|
||||
@@ -117,21 +111,20 @@ 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;
|
||||
|
||||
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);
|
||||
|
||||
+10
-13
@@ -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"
|
||||
@@ -45,8 +46,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,10 +55,8 @@ 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; }
|
||||
@@ -69,16 +66,18 @@ public:
|
||||
private:
|
||||
EntityID m_Entity = 0;
|
||||
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
|
||||
bool m_Left = false, m_Right = false, m_ReplaceBall = false, m_MultiBall = false;
|
||||
Components::Transform* m_Transform;
|
||||
Components::Pad* m_Pad;
|
||||
bool m_Left = false;
|
||||
bool m_Right = false;
|
||||
bool m_ReplaceBall = false;
|
||||
bool m_MultiBall = false;
|
||||
float m_Edge = 2.8f;
|
||||
Components::Transform* m_Transform = nullptr;
|
||||
Components::Pad* m_Pad = nullptr;
|
||||
|
||||
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;
|
||||
|
||||
bool OnKeyDown(const dd::Events::KeyDown &event);
|
||||
@@ -86,8 +85,6 @@ private:
|
||||
|
||||
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);
|
||||
|
||||
class PadSteeringInputController;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,96 +8,123 @@
|
||||
#include "Core/System.h"
|
||||
#include "Core/World.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/CTemplate.h"
|
||||
|
||||
#include "Physics/CRectangleShape.h"
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Physics/CPhysics.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 "Physics/CWaterVolume.h"
|
||||
#include "Physics/CParticleEmitter.h"
|
||||
#include "Game/CPad.h"
|
||||
#include "Game/CPad.h"
|
||||
#include "Game/CBall.h"
|
||||
#include "Transform/TransformSystem.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
|
||||
#include "Core/CTemplate.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class PhysicsSystem : public System
|
||||
{
|
||||
friend class ContractListener;
|
||||
|
||||
public:
|
||||
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
|
||||
~PhysicsSystem();
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnEntityCommit(EntityID entity) override;
|
||||
void OnEntityRemoved(EntityID entity) override;
|
||||
|
||||
private:
|
||||
struct Impulse
|
||||
namespace Systems
|
||||
{
|
||||
b2Body* Body;
|
||||
b2Vec2 Impulse;
|
||||
b2Vec2 Point;
|
||||
};
|
||||
|
||||
b2Vec2 m_Gravity = b2Vec2(0.f, -9.82f);
|
||||
b2World* m_PhysicsWorld = nullptr;
|
||||
float m_TimeStep = 1.f/60.f;
|
||||
float m_Accumulator = 0.f;
|
||||
int m_VelocityIterations = 6;
|
||||
int m_PositionIterations = 2;
|
||||
class PhysicsSystem : public System
|
||||
{
|
||||
friend class ContractListener;
|
||||
|
||||
b2ParticleSystem *m_ParticleSystem;
|
||||
b2ParticleGroup* t_watergroup;
|
||||
public:
|
||||
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
|
||||
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
|
||||
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
|
||||
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToParticleHandle;
|
||||
std::unordered_map<const b2ParticleHandle*, EntityID> m_ParticleHandleToEntities;
|
||||
~PhysicsSystem();
|
||||
|
||||
std::list<Impulse> m_Impulses;
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnEntityCommit(EntityID entity) override;
|
||||
void OnEntityRemoved(EntityID entity) override;
|
||||
|
||||
void CreateBody(EntityID entity);
|
||||
void SyncEntitiesWithBodies();
|
||||
void SyncBodiesWithEntities();
|
||||
void InitializeWater();
|
||||
void SyncWater(); //TODO: Probably remove this
|
||||
void CreateParticleGroup(EntityID entity);
|
||||
private:
|
||||
struct Impulse
|
||||
{
|
||||
b2Body* Body;
|
||||
b2Vec2 Impulse;
|
||||
b2Vec2 Point;
|
||||
};
|
||||
bool m_Pause = false;
|
||||
|
||||
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
|
||||
bool SetImpulse(const Events::SetImpulse &event);
|
||||
|
||||
class ContactListener : public b2ContactListener
|
||||
{
|
||||
public:
|
||||
ContactListener(PhysicsSystem* physicsSystem)
|
||||
: m_PhysicsSystem(physicsSystem) { }
|
||||
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;
|
||||
|
||||
void BeginContact(b2Contact* contact);
|
||||
void EndContact(b2Contact* contact);
|
||||
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
|
||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
|
||||
std::vector<b2ParticleSystem*> m_ParticleSystem;
|
||||
std::vector<b2ParticleGroup*> t_ParticleGroup;
|
||||
|
||||
private:
|
||||
PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
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;
|
||||
|
||||
ContactListener* m_ContactListener;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
//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;
|
||||
|
||||
|
||||
|
||||
class ContactListener : public b2ContactListener
|
||||
{
|
||||
public:
|
||||
ContactListener(PhysicsSystem* physicsSystem)
|
||||
: m_PhysicsSystem(physicsSystem) { }
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
ContactListener* m_ContactListener;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user