Added two new particle sprites.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 600 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
@@ -188,6 +188,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Background
|
//Background
|
||||||
|
|
||||||
{
|
{
|
||||||
auto background = m_World->CreateEntity();
|
auto background = m_World->CreateEntity();
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(background);
|
auto transform = m_World->AddComponent<Components::Transform>(background);
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ struct ParticleEmitter : public Component
|
|||||||
float InitialSpeed = 1.f;
|
float InitialSpeed = 1.f;
|
||||||
double SpawnRate = 1;
|
double SpawnRate = 1;
|
||||||
int ParticlesPerTick = 1;
|
int ParticlesPerTick = 1;
|
||||||
double TimeSinceLastSpawn = 0;
|
//TODO: Refactor. Have cooldown instead of this
|
||||||
|
double TimeSinceLastSpawn = 100;
|
||||||
int MaxCount = 0;
|
int MaxCount = 0;
|
||||||
float EmittingAngle = 0.f;
|
float EmittingAngle = 0.f;
|
||||||
float Spread = 0.f;
|
float Spread = 0.f;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ struct Contact : Event
|
|||||||
{
|
{
|
||||||
EntityID Entity1;
|
EntityID Entity1;
|
||||||
EntityID Entity2;
|
EntityID Entity2;
|
||||||
|
glm::vec2 IntersectionPoint;
|
||||||
glm::vec2 Normal;
|
glm::vec2 Normal;
|
||||||
glm::vec2 SignificantNormal;
|
glm::vec2 SignificantNormal;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ struct CreateParticleSequence : public Event
|
|||||||
float Spread = 1.f;
|
float Spread = 1.f;
|
||||||
float EmittingAngle = 0.f;
|
float EmittingAngle = 0.f;
|
||||||
float MaxCount = 0;
|
float MaxCount = 0;
|
||||||
|
glm::vec4 Color = glm::vec4(0);
|
||||||
|
|
||||||
//Particle
|
//Particle
|
||||||
std::string SpriteFile = "Texures/Core/ErrorTexture.png";
|
std::string SpriteFile = "";
|
||||||
double ParticleLifeTime = 3.f;
|
double ParticleLifeTime = 3.f;
|
||||||
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Powder | ParticleFlags::ParticleContactFilter | ParticleFlags::FixtureContactFilter);
|
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Powder | ParticleFlags::ParticleContactFilter | ParticleFlags::FixtureContactFilter);
|
||||||
float Radius = 1.f;
|
float Radius = 1.f;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
|
|
||||||
#include "Rendering/CSprite.h"
|
#include "Rendering/CSprite.h"
|
||||||
|
#include "Rendering/CModel.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
@@ -113,6 +114,8 @@ namespace dd
|
|||||||
bool OnPause(const dd::Events::Pause &event);
|
bool OnPause(const dd::Events::Pause &event);
|
||||||
dd::EventRelay<PhysicsSystem, dd::Events::StageCleared> m_EStageCleared;
|
dd::EventRelay<PhysicsSystem, dd::Events::StageCleared> m_EStageCleared;
|
||||||
bool OnStageCleared(const dd::Events::StageCleared &event);
|
bool OnStageCleared(const dd::Events::StageCleared &event);
|
||||||
|
dd::EventRelay<PhysicsSystem, dd::Events::Contact> m_EContact;
|
||||||
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
bool m_Travelling = false;
|
bool m_Travelling = false;
|
||||||
float m_Timer = 0;
|
float m_Timer = 0;
|
||||||
|
|
||||||
@@ -173,7 +176,7 @@ namespace dd
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -196,7 +199,7 @@ namespace dd
|
|||||||
};
|
};
|
||||||
|
|
||||||
DestructionListener* m_DestructionListener;
|
DestructionListener* m_DestructionListener;
|
||||||
ParticleContactDisabler m_ParticleContactDisabler;
|
ParticleContactDisabler* m_ParticleContactDisabler;
|
||||||
ContactListener* m_ContactListener;
|
ContactListener* m_ContactListener;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,11 @@ void dd::Systems::PhysicsSystem::ContactListener::BeginContact(b2Contact* contac
|
|||||||
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->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.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));
|
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));
|
||||||
|
//contact->GetManifold()->points
|
||||||
m_PhysicsSystem->EventBroker->Publish(e);
|
b2Vec2 pos = worldManifold.points[0];
|
||||||
|
glm::vec2 glmPos = glm::vec2(pos.x, pos.y);
|
||||||
|
e.IntersectionPoint = glmPos;
|
||||||
|
m_PhysicsSystem->EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::PhysicsSystem::ContactListener::EndContact(b2Contact* contact)
|
void dd::Systems::PhysicsSystem::ContactListener::EndContact(b2Contact* contact)
|
||||||
|
|||||||
@@ -15,14 +15,16 @@ void dd::Systems::PhysicsSystem::Initialize()
|
|||||||
m_DestructionListener = new DestructionListener(this);
|
m_DestructionListener = new DestructionListener(this);
|
||||||
m_ContactListener = new ContactListener(this);
|
m_ContactListener = new ContactListener(this);
|
||||||
m_PhysicsWorld = new b2World(m_Gravity);
|
m_PhysicsWorld = new b2World(m_Gravity);
|
||||||
|
m_ParticleContactDisabler = new ParticleContactDisabler();
|
||||||
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
||||||
m_PhysicsWorld->SetContactFilter(&m_ParticleContactDisabler);
|
m_PhysicsWorld->SetContactFilter(m_ParticleContactDisabler);
|
||||||
m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
||||||
|
|
||||||
InitializeWater();
|
InitializeWater();
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause);
|
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PhysicsSystem::OnPause);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ECreateParticleSequence, &PhysicsSystem::CreateParticleSequence);
|
EVENT_SUBSCRIBE_MEMBER(m_ECreateParticleSequence, &PhysicsSystem::CreateParticleSequence);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PhysicsSystem::OnContact);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,8 +252,14 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
||||||
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
|
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
|
||||||
|
|
||||||
|
if (particle && pTemplate)
|
||||||
|
LOG_ERROR("Particel + template finns");
|
||||||
|
|
||||||
if (particle && !pTemplate) {
|
if (particle && !pTemplate) {
|
||||||
|
//LOG_ERROR("Particel - template finns");
|
||||||
|
|
||||||
particle->LifeTime -= dt;
|
particle->LifeTime -= dt;
|
||||||
if (particle->LifeTime <= 0) {
|
if (particle->LifeTime <= 0) {
|
||||||
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
|
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
|
||||||
@@ -266,6 +274,7 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
|||||||
if (iter2 != m_ParticleHandleToEntities[i].end()) {
|
if (iter2 != m_ParticleHandleToEntities[i].end()) {
|
||||||
m_ParticleHandleToEntities[i].erase(iter2);
|
m_ParticleHandleToEntities[i].erase(iter2);
|
||||||
}
|
}
|
||||||
|
LOG_INFO("Deleteing particle!!.");
|
||||||
m_World->RemoveEntity(entity);
|
m_World->RemoveEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -448,14 +457,14 @@ void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
|
|||||||
void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||||
{
|
{
|
||||||
std::vector<EntityID> emittersToDelete;
|
std::vector<EntityID> emittersToDelete;
|
||||||
int pSizeTest = 0;
|
int pSizeTest = 0; //For debugging, delete this
|
||||||
|
int psListSize = 0;
|
||||||
for (int i = 0; i < m_ParticleEmitters.ParticleSystem.size(); i++) {
|
for (int i = 0; i < m_ParticleEmitters.ParticleSystem.size(); i++) {
|
||||||
auto e = m_ParticleEmitters.ParticleEmitter[i];
|
auto e = m_ParticleEmitters.ParticleEmitter[i];
|
||||||
auto pt = m_ParticleEmitters.ParticleTemplate[i];
|
auto pt = m_ParticleEmitters.ParticleTemplate[i];
|
||||||
auto ps = m_ParticleEmitters.ParticleSystem[i];
|
auto ps = m_ParticleEmitters.ParticleSystem[i];
|
||||||
pSizeTest += ps->GetParticleCount();
|
pSizeTest += ps->GetParticleCount();
|
||||||
|
psListSize++;
|
||||||
|
|
||||||
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(e);
|
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(e);
|
||||||
auto particleTemplate = m_World->GetComponent<Components::Particle>(pt);
|
auto particleTemplate = m_World->GetComponent<Components::Particle>(pt);
|
||||||
if(!emitter) {
|
if(!emitter) {
|
||||||
@@ -493,7 +502,7 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
std::uniform_real_distribution<float> dis(eAngle - halfSpread, eAngle + halfSpread);
|
std::uniform_real_distribution<float> dis(eAngle - halfSpread, eAngle + halfSpread);
|
||||||
float pAngle = dis(gen);
|
float pAngle = dis(gen);
|
||||||
glm::vec2 unitVec = glm::normalize(glm::vec2(glm::cos(pAngle), glm::sin(pAngle)));
|
glm::vec2 unitVec = glm::normalize(glm::vec2(glm::cos(pAngle), glm::sin(pAngle)));
|
||||||
glm::vec2 vel = unitVec * emitter->Speed;
|
glm::vec2 vel = unitVec * emitter->Speed * (float)dt;
|
||||||
particleDef.velocity = b2Vec2(vel.x, vel.y);
|
particleDef.velocity = b2Vec2(vel.x, vel.y);
|
||||||
particleDef.position = b2Vec2(templateTransform->Position.x, templateTransform->Position.y);
|
particleDef.position = b2Vec2(templateTransform->Position.x, templateTransform->Position.y);
|
||||||
|
|
||||||
@@ -513,8 +522,25 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
|
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
|
||||||
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
||||||
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// system("cls");
|
||||||
|
// std::cout << "Particles living: " << pSizeTest << std::endl;
|
||||||
|
// std::cout << "particle systems: " << psListSize << std::endl;
|
||||||
|
// int entHandles = 0;
|
||||||
|
// for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++)
|
||||||
|
// entHandles += m_EntitiesToParticleHandle[i].size();
|
||||||
|
// std::cout << "Entities and handles: " << entHandles << std::endl;
|
||||||
|
// LOG_INFO("Particles living: %i", pSizeTest);
|
||||||
|
// LOG_INFO("Particle systems: %i", psListSize);
|
||||||
|
// int entHandles = 0;
|
||||||
|
// for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++)
|
||||||
|
// entHandles += m_EntitiesToParticleHandle[i].size();
|
||||||
|
// LOG_INFO("Entities and handles: %i", entHandles);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < emittersToDelete.size(); i++)
|
for (int i = 0; i < emittersToDelete.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -537,6 +563,8 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int stp = 0;
|
int stp = 0;
|
||||||
for (auto ts : m_EntitiesToParticleHandle)
|
for (auto ts : m_EntitiesToParticleHandle)
|
||||||
{
|
{
|
||||||
@@ -571,6 +599,7 @@ bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreatePart
|
|||||||
|
|
||||||
particleTransform->Position = emitterTransform->Position;
|
particleTransform->Position = emitterTransform->Position;
|
||||||
sprite->SpriteFile = event.SpriteFile;
|
sprite->SpriteFile = event.SpriteFile;
|
||||||
|
sprite->Color = event.Color;
|
||||||
particleComponent->LifeTime = event.ParticleLifeTime;
|
particleComponent->LifeTime = event.ParticleLifeTime;
|
||||||
particleComponent->Flags = event.Flags;
|
particleComponent->Flags = event.Flags;
|
||||||
particleComponent->Radius = event.Radius;
|
particleComponent->Radius = event.Radius;
|
||||||
@@ -632,6 +661,40 @@ b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius,
|
|||||||
return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||||
|
{
|
||||||
|
//Check if it is a brick colliding
|
||||||
|
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
|
||||||
|
Components::Model* model;
|
||||||
|
|
||||||
|
if (!brick) {
|
||||||
|
brick = m_World->GetComponent<Components::Brick>(event.Entity2);
|
||||||
|
if (!brick) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
model = m_World->GetComponent<Components::Model>(event.Entity2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
model = m_World->GetComponent<Components::Model>(event.Entity1);
|
||||||
|
}
|
||||||
|
Events::CreateParticleSequence e;
|
||||||
|
e.EmitterLifeTime = 2;
|
||||||
|
//- glm::atan(event.Normal.x, event.Normal.y
|
||||||
|
e.EmittingAngle = glm::half_pi<float>();
|
||||||
|
e.Spread = 0;
|
||||||
|
e.NumberOfTicks = 1;
|
||||||
|
e.ParticleLifeTime = 1.f;
|
||||||
|
e.ParticlesPerTick = 1;
|
||||||
|
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -10);
|
||||||
|
e.Radius = 0.1f;
|
||||||
|
e.SpriteFile = "Textures/Bricks/3.png";
|
||||||
|
e.Color = model->Color;
|
||||||
|
e.Speed = 100.f;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
dd::Systems::PhysicsSystem::~PhysicsSystem()
|
dd::Systems::PhysicsSystem::~PhysicsSystem()
|
||||||
|
|||||||
Reference in New Issue
Block a user