Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianMeizoso committed Mar 22, 2018
2 parents 3c3e9a0 + 61b970a commit c297db5
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 10,834 deletions.
5 changes: 5 additions & 0 deletions LCSEngine/ComponentFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "AudioListenerComponent.h"
#include "AudioSourceComponent.h"
#include "BillboardGridComponent.h"
#include "ParticleSystemComponent.h"

ComponentFactory::~ComponentFactory() {}

Expand Down Expand Up @@ -49,8 +50,12 @@ Component* ComponentFactory::getComponent(TypeComponent typeComponent, GameObjec
case TypeComponent::AUDIOSOURCE:
return new AudioSourceComponent(parentObject);
break;
case TypeComponent::PARTICLESYSTEM:
return new ParticleSystemComponent(parentObject);
break;
case TypeComponent::BILLBOARDGRID:
return new BillboardGridComponent(parentObject);
break;
default:
return nullptr;
break;
Expand Down
31 changes: 31 additions & 0 deletions LCSEngine/ElementGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ ElementGameUI::ElementGameUI(GameObject* parent, int x, int y, int h, int w, boo
enable = true;
}

ElementGameUI::ElementGameUI(GameObject * parent)
{
gameObject = parent;
if (gameObject != nullptr)
{
UUIDparent = parent->UUID;
}
}

ElementGameUI::~ElementGameUI() {}

void ElementGameUI::startGUI()
Expand All @@ -45,4 +54,26 @@ bool ElementGameUI::isHover()
}
}
return false;
}

void ElementGameUI::load(nlohmann::json& conf)
{
visible = conf.at("visible").get<bool>();
enable = conf.at("enable").get<bool>();
rect.x = conf.at("x").get<int>();
rect.y = conf.at("y").get<int>();
rect.w = conf.at("h").get<int>();
rect.h = conf.at("w").get<int>();
}

void ElementGameUI::save(nlohmann::json& conf)
{
conf["visible"] = visible;
conf["enable"] = enable;
conf["TypeElemeneGametUI"] = type;
conf["x"] = rect.x;
conf["y"] = rect.y;
conf["w"] = rect.w;
conf["h"] = rect.h;

}
4 changes: 4 additions & 0 deletions LCSEngine/ElementGameUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
#define __ELEMENTGAMEUI_H__

#include "Module.h"
#include <json.hpp>
#include <string>

class ElementGameUI
{
public:
ElementGameUI(GameObject* parent, int x, int y, int h, int w, bool isVisible = true);
ElementGameUI(GameObject* parent);
~ElementGameUI();
virtual void drawGUI() = 0;
void startGUI();
void endGUI();
bool isHover();
virtual void load(nlohmann::json& conf);
virtual void save(nlohmann::json& conf);

public:
TypeElemeneGametUI type;
Expand Down
55 changes: 55 additions & 0 deletions LCSEngine/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ void GameObject::save(nlohmann::json& conf) {
SaveLoadManager::convertFloat3ToMyJSON(aabb.minPoint, customJsont);
conf["aabbMin"] = customJsont;

//Save Components
list<nlohmann::json> componentsJson;
for (vector<Component*>::iterator it = components.begin(); it != components.end(); ++it)
{
Expand All @@ -246,6 +247,16 @@ void GameObject::save(nlohmann::json& conf) {
componentsJson.push_back(compJson);
}
conf["components"] = componentsJson;

//Save elementes
list<nlohmann::json> elementsJson;
for (vector<ElementGameUI*>::iterator it = elements.begin(); it != elements.end(); ++it)
{
nlohmann::json compJson;
(*it)->save(compJson);
elementsJson.push_back(compJson);
}
conf["elements"] = elementsJson;
}

void GameObject::load(nlohmann::json& conf) {
Expand Down Expand Up @@ -317,6 +328,46 @@ void GameObject::load(nlohmann::json& conf) {
break;
}
}

list<nlohmann::json> elementsJson = conf["elements"];
for (list<nlohmann::json>::iterator it = elementsJson.begin(); it != elementsJson.end(); ++it)
{
switch ((*it).at("TypeElemeneGametUI").get<int>())
{
case BUTTON:
{
UIButton* butonElem = new UIButton(this);
butonElem->type = BUTTON;
butonElem->load(*it);
addElement(butonElem);
}
break;
case LABEL:
{
UILabel* labelElem = new UILabel(this);
labelElem->type = LABEL;
labelElem->load(*it);
addElement(labelElem);
}
break;
case IMAGE:
{
UIImage * imageElem = new UIImage(this);
imageElem->type = IMAGE;
imageElem->load(*it);
addElement(imageElem);
}
break;
case EDITTEXT:
{
UIEditText* editTextElem = new UIEditText(this);
editTextElem->type = BUTTON;
editTextElem->load(*it);
addElement(editTextElem);
}
break;
}
}
}

void GameObject::drawComponentsElementsGui()
Expand Down Expand Up @@ -384,6 +435,10 @@ void GameObject::drawComponentsElementsGui()
{
addComponent(factory->getComponent(AUDIOSOURCE, this));
}
else if (ImGui::MenuItem("ParticleSystem"))
{
addComponent(factory->getComponent(PARTICLESYSTEM, this));
}
else if (ImGui::MenuItem("Billboard Grid"))
{
addComponent(factory->getComponent(BILLBOARDGRID, this));
Expand Down
1 change: 1 addition & 0 deletions LCSEngine/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum TypeComponent
ANIMATION,
AUDIOLISTENER,
AUDIOSOURCE,
PARTICLESYSTEM,
BILLBOARDGRID
};

Expand Down
2 changes: 2 additions & 0 deletions LCSEngine/LCSEngine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<ClInclude Include="ModuleTextures.h" />
<ClInclude Include="ModuleType.h" />
<ClInclude Include="ModuleWindow.h" />
<ClInclude Include="ParticleSystemComponent.h" />
<ClInclude Include="PhysRaycast.h" />
<ClInclude Include="Point.h" />
<ClInclude Include="Primitive.h" />
Expand Down Expand Up @@ -329,6 +330,7 @@
<ClCompile Include="ModuleTextures.cpp" />
<ClCompile Include="ModuleType.cpp" />
<ClCompile Include="ModuleWindow.cpp" />
<ClCompile Include="ParticleSystemComponent.cpp" />
<ClCompile Include="PhysRaycast.cpp" />
<ClCompile Include="Primitive.cpp" />
<ClCompile Include="QuadTree.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions LCSEngine/LCSEngine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@
<ClInclude Include="BillboardGridComponent.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="ParticleSystemComponent.h">
<Filter>Components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Log.cpp">
Expand Down Expand Up @@ -632,6 +635,9 @@
<ClCompile Include="BillboardGridComponent.cpp">
<Filter>Components</Filter>
</ClCompile>
<ClCompile Include="ParticleSystemComponent.cpp">
<Filter>Components</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="MathGeoLib\src\Geometry\KDTree.inl">
Expand Down
54 changes: 54 additions & 0 deletions LCSEngine/ParticleSystemComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "ParticleSystemComponent.h"
#include "TransformComponent.h"
#include "GameObject.h"

ParticleSystemComponent::ParticleSystemComponent(GameObject* gameObject) : Component(gameObject, true, true)
{
typeComponent = PARTICLESYSTEM;
}


ParticleSystemComponent::~ParticleSystemComponent() {}

void ParticleSystemComponent::drawGUI() {}

void ParticleSystemComponent::updateParticles(float deltaTime)
{
//Update Active particles
//if number of active particles less than total particles && timeSpawn
//Instantiate new particle from inactive particles
updateActiveParticles(deltaTime);
spawnParticle(deltaTime);
}

void ParticleSystemComponent::updateActiveParticles(float deltaTime)
{
for (std::list<Particle*>::iterator it = activeParticles.begin(); it != activeParticles.end();)
{
(*it)->lifeTime -= deltaTime;
if ((*it)->lifeTime < 0.f)
{
(*it)->lifeTime = lifeTimeParticles;
float3 posGameObject = ((TransformComponent*)gameObject->getComponent(TRANSFORM))->position;
//(*it)->position =
inactiveParticles.push_back(*it);
it = activeParticles.erase(it);
}
else
{
(*it)->position += (*it)->velocity * deltaTime;
++it;
}
}
}

void ParticleSystemComponent::spawnParticle(float deltaTime)
{
spawnCountdown -= deltaTime;
if (spawnCountdown < 0.f && inactiveParticles.size() > 0 && activeParticles.size() < totalParticles)
{
activeParticles.push_back(inactiveParticles.front());
inactiveParticles.pop_front();
spawnCountdown = spawnTime;
}
}
30 changes: 23 additions & 7 deletions LCSEngine/ParticleSystemComponent.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
#ifndef __PARTICLESYSTEMCOMPONENT_H__
#define __PARTICLESYSTEMCOMPONENT_H__

#include "Component.h"
#include "MathGeoLib/src/Math/float3.h"
#include <list>

typedef unsigned int GLuint;

struct Particle
{
float3 position = float3::zero;
float3 velocity = float3::zero;
float width = 0.f;
float height = 0.f;
float lifeTime = 0.f;
float3 color = float3(1.f,1.f,1.f);
GLuint sprite;

};

class ParticleSystemComponent
class ParticleSystemComponent : public Component
{
public:
ParticleSystemComponent();
ParticleSystemComponent(GameObject* gameObject);
~ParticleSystemComponent();
void drawGUI();
void updateParticles(float deltaTime);

public:
std::vector<Particle*> particles;
std::list<Particle*> activeParticles;
std::list<Particle*> inactiveParticles;
unsigned int totalParticles = 0;
float widthEmisor = 0.f;
float heightEmisor = 0.f;
float lifeTimeParticles = 0.f;
float spawnTime = 0.f;
float spawnCountdown = 0.f;
GLuint sprite;

private:
void updateActiveParticles(float deltaTime);
void spawnParticle(float deltaTime);

};

#endif //__PARTICLESYSTEMCOMPONENT_H__
Loading

0 comments on commit c297db5

Please sign in to comment.