Merge remote-tracking branch 'origin/master' into LevelSystemAndSuch.
This commit is contained in:
Executable
+12
@@ -0,0 +1,12 @@
|
||||
[Debug]
|
||||
SkipStory=false
|
||||
LogLevel=1
|
||||
|
||||
[Audio]
|
||||
SFXVolume=0.5
|
||||
BGMVolume=0.5
|
||||
|
||||
[Video]
|
||||
Fullscreen=false
|
||||
Width=675
|
||||
Height=1080
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
+12
@@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'Arm.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd texture.png
|
||||
Executable
+14717
File diff suppressed because it is too large
Load Diff
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 579 KiB |
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 839 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#ifndef ConfigFile_h__
|
||||
#define ConfigFile_h__
|
||||
|
||||
#include <string>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/ini_parser.hpp>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
class ConfigFile : public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
private:
|
||||
ConfigFile(std::string path);
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
T GetValue(std::string key, T defaultValue);
|
||||
template <typename T>
|
||||
void SetValue(std::string key, T value);
|
||||
|
||||
void SaveToDisk();
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_Path;
|
||||
boost::property_tree::ptree m_PTreeDefaults;
|
||||
boost::property_tree::ptree m_PTreeOverrides;
|
||||
boost::property_tree::ptree m_PTreeMerged;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T ConfigFile::GetValue(std::string key, T defaultValue)
|
||||
{
|
||||
return m_PTreeMerged.get<T>(key, defaultValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ConfigFile::SetValue(std::string key, T value)
|
||||
{
|
||||
m_PTreeOverrides.put<T>(key, value);
|
||||
m_PTreeMerged.put<T>(key, value);
|
||||
}
|
||||
|
||||
};
|
||||
#endif // ConfigFile_h__
|
||||
+40
-8
@@ -32,6 +32,7 @@
|
||||
#include "World.h"
|
||||
#include "CTransform.h"
|
||||
#include "CTemplate.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Rendering/CModel.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
@@ -72,6 +73,8 @@
|
||||
#include "Physics/CParticle.h"
|
||||
#include "Physics/CParticleEmitter.h"
|
||||
|
||||
#include "Rendering/AnimationSystem.h"
|
||||
|
||||
#include "Game/EGameStart.h"
|
||||
#include "Sound/EPlaySound.h"
|
||||
|
||||
@@ -88,18 +91,34 @@ class Engine
|
||||
|
||||
public:
|
||||
Engine(int argc, char* argv[]) {
|
||||
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(config->GetValue<int>("Debug.LogLevel", 1));
|
||||
|
||||
m_EventBroker = std::make_shared<EventBroker>();
|
||||
|
||||
m_Renderer = std::make_shared<Renderer>();
|
||||
m_Renderer->SetFullscreen(false);
|
||||
//m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
|
||||
m_Renderer->SetResolution(Rectangle(0, 0, 675, 1080));
|
||||
m_Renderer->SetFullscreen(config->GetValue<bool>("Video.Fullscreen", false));
|
||||
m_Renderer->SetResolution(Rectangle(
|
||||
0,
|
||||
0,
|
||||
config->GetValue<int>("Video.Width", 675),
|
||||
config->GetValue<int>("Video.Height", 1080)
|
||||
));
|
||||
m_Renderer->Initialize();
|
||||
|
||||
m_FrameStack = new GUI::Frame(m_EventBroker.get());
|
||||
m_FrameStack->Width = 675;
|
||||
m_FrameStack->Height = 1080;
|
||||
auto menu = new GUI::MainMenu(m_FrameStack, "MainMenu");
|
||||
|
||||
if (config->GetValue<bool>("Debug.SkipStory", false)) {
|
||||
Events::GameStart e;
|
||||
m_EventBroker->Publish(e);
|
||||
auto hud = new GUI::HUD(m_FrameStack, "HUD");
|
||||
}
|
||||
else {
|
||||
auto menu = new GUI::MainMenu(m_FrameStack, "MainMenu");
|
||||
}
|
||||
|
||||
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
|
||||
|
||||
@@ -165,6 +184,9 @@ public:
|
||||
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::AnimationSystem>(
|
||||
[this]() { return new Systems::AnimationSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::AnimationSystem>();
|
||||
m_World->SystemFactory.Register<Systems::TravellingSystem>(
|
||||
[this]() { return new Systems::TravellingSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::TravellingSystem>();
|
||||
@@ -260,7 +282,8 @@ public:
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
|
||||
* glm::toMat4(absoluteTransform.Orientation)
|
||||
* glm::scale(absoluteTransform.Scale);
|
||||
EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color, modelComponent->ModelFile);
|
||||
Components::Animation* animationComponent = m_World->GetComponent<Components::Animation>(entity);
|
||||
EnqueueModel(modelAsset, modelMatrix, modelComponent, animationComponent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +339,7 @@ public:
|
||||
}
|
||||
|
||||
//TODO: Get this out of engine.h
|
||||
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color, std::string fileName)
|
||||
void EnqueueModel(Model* model, glm::mat4 modelMatrix, const Components::Model* modelComponent, const Components::Animation* animationComponent)
|
||||
{
|
||||
for (auto texGroup : model->TextureGroups)
|
||||
{
|
||||
@@ -329,8 +352,17 @@ public:
|
||||
job.ElementBuffer = model->ElementBuffer;
|
||||
job.StartIndex = texGroup.StartIndex;
|
||||
job.EndIndex = texGroup.EndIndex;
|
||||
job.ModelMatrix = modelMatrix;
|
||||
job.Color = color;
|
||||
job.ModelMatrix = modelMatrix * model->m_Matrix;
|
||||
job.Color = modelComponent->Color;
|
||||
|
||||
if (model->m_Skeleton != nullptr) {
|
||||
job.Skeleton = model->m_Skeleton;
|
||||
if (animationComponent != nullptr) {
|
||||
job.AnimationName = animationComponent->Name;
|
||||
job.AnimationTime = animationComponent->Time;
|
||||
job.NoRootMotion = animationComponent->NoRootMotion;
|
||||
}
|
||||
}
|
||||
|
||||
m_RendererQueue.Deferred.Add(job);
|
||||
}
|
||||
|
||||
@@ -86,6 +86,8 @@ public:
|
||||
std::vector<unsigned int> m_Indices;
|
||||
Skeleton* m_Skeleton = nullptr;
|
||||
|
||||
glm::mat4 m_Matrix;
|
||||
|
||||
private:
|
||||
std::vector<glm::ivec2> BoneIndices;
|
||||
std::vector<glm::vec2> BoneWeights;
|
||||
|
||||
@@ -33,6 +33,10 @@ class PNG : public Image
|
||||
public:
|
||||
PNG(std::string path);
|
||||
~PNG();
|
||||
|
||||
private:
|
||||
static void pngErrorFunction(png_structp png_ptr, png_const_charp error_msg);
|
||||
static void pngWarningFunction(png_structp png_ptr, png_const_charp warning_msg);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -66,6 +66,12 @@ struct ModelJob : RenderJob
|
||||
unsigned int StartIndex;
|
||||
unsigned int EndIndex;
|
||||
|
||||
// Animation
|
||||
dd::Skeleton* Skeleton = nullptr;
|
||||
bool NoRootMotion = true;
|
||||
std::string AnimationName;
|
||||
double AnimationTime = 0;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = TextureID;
|
||||
|
||||
@@ -100,16 +100,17 @@ public:
|
||||
|
||||
int GetBoneID(std::string name);
|
||||
|
||||
std::vector<glm::mat4> GetFrameBones(std::string animationName, double time, bool noRootMotion = false);
|
||||
void AccumulateBoneTransforms(bool noRootMotion, Animation::Keyframe ¤tFrame, Animation::Keyframe &nextFrame, float progress, std::map<int, glm::mat4> &boneMatrices, Bone* bone, glm::mat4 parentMatrix);
|
||||
const Animation* GetAnimation(std::string name);
|
||||
std::vector<glm::mat4> GetFrameBones(const Animation& animation, double time, bool noRootMotion = false);
|
||||
void AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyframe& currentFrame, const Animation::Keyframe& nextFrame, float progress, std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix);
|
||||
void PrintSkeleton();
|
||||
void PrintSkeleton(Bone* parent, int depthCount);
|
||||
void PrintSkeleton(const Bone* parent, int depthCount);
|
||||
std::map<std::string, Animation> Animations;
|
||||
|
||||
private:
|
||||
std::map<std::string, Bone*> m_BonesByName;
|
||||
|
||||
int GetKeyframe(Animation& animation, double time);
|
||||
int GetKeyframe(const Animation& animation, double time);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -40,23 +40,19 @@
|
||||
enum _LOG_LEVEL
|
||||
{
|
||||
LOG_LEVEL_ERROR,
|
||||
LOG_LEVEL_WARNING,
|
||||
LOG_LEVEL_INFO,
|
||||
LOG_LEVEL_WARNING,
|
||||
LOG_LEVEL_DEBUG
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
static _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG;
|
||||
#else
|
||||
static _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG;
|
||||
#endif
|
||||
extern _LOG_LEVEL LOG_LEVEL;
|
||||
|
||||
const static char* _LOG_LEVEL_PREFIX[] =
|
||||
{
|
||||
"E: ",
|
||||
"W: ",
|
||||
"EE: ",
|
||||
"",
|
||||
"D: "
|
||||
"WW: ",
|
||||
"DD: "
|
||||
};
|
||||
|
||||
static void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int line, const char* format, ...)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "Rendering/CModel.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
#include "Rendering/CPointLight.h"
|
||||
#include "Rendering/CAnimation.h"
|
||||
#include "Game/CBall.h"
|
||||
#include "Game/CPowerUp.h"
|
||||
#include "Game/CLife.h"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "GUI/Slider.h"
|
||||
#include "GUI/ESliderUpdate.h"
|
||||
#include "Sound/EMasterVolume.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -33,7 +34,6 @@ public:
|
||||
m_SFXSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
|
||||
m_SFXSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
|
||||
m_SFXSlider->AlignVertically();
|
||||
m_SFXSlider->SetPercentage(1.f);
|
||||
|
||||
m_TitleBGM = new GUI::TextureFrame(this, "MainMenuOptionsBGMTitle");
|
||||
m_TitleBGM->SetTop(m_SFXSlider->Bottom() + 20);
|
||||
@@ -44,9 +44,12 @@ public:
|
||||
m_BGMSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
|
||||
m_BGMSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
|
||||
m_BGMSlider->AlignVertically();
|
||||
m_BGMSlider->SetPercentage(1.f);
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESliderUpdate, &MainMenuOptions::OnSliderUpdate);
|
||||
|
||||
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_SFXSlider->SetPercentage(config->GetValue<float>("Audio.SFXVolume", 1.f));
|
||||
m_BGMSlider->SetPercentage(config->GetValue<float>("Audio.BGMVolume", 1.f));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -73,6 +76,11 @@ private:
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
config->SetValue("Audio.SFXVolume", m_SFXSlider->Percentage());
|
||||
config->SetValue("Audio.BGMVolume", m_BGMSlider->Percentage());
|
||||
config->SaveToDisk();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,8 +33,10 @@ namespace Components
|
||||
|
||||
struct Particle : public Component
|
||||
{
|
||||
float Radius = 0.5f;
|
||||
float LifeTime = 5.0f;
|
||||
EntityID ParticleSystem;
|
||||
glm::vec3 Scale = glm::vec3(1.f);
|
||||
double TimeLived = 0;
|
||||
double LifeTime = 5;
|
||||
|
||||
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(
|
||||
ParticleFlags::Water
|
||||
|
||||
@@ -21,6 +21,11 @@ struct ParticleEmitter : public Component
|
||||
float Spread = 0.f;
|
||||
float Speed = 2.f;
|
||||
double LifeTime = 100;
|
||||
float RadiusDistribution = 0;
|
||||
|
||||
//values to interpolate between.
|
||||
std::vector<glm::vec3> ScaleValues;
|
||||
std::vector<float> AlphaValues;
|
||||
|
||||
//System variables
|
||||
float GravityScale = 1.0f;
|
||||
|
||||
@@ -22,14 +22,18 @@ struct CreateParticleSequence : public Event
|
||||
float Spread = 1.f;
|
||||
float EmittingAngle = 0.f;
|
||||
float MaxCount = 0;
|
||||
float RadiusDistribution = 0;
|
||||
glm::vec4 Color = glm::vec4(0);
|
||||
EntityID parent = 0;
|
||||
// values to interpolate between.
|
||||
std::vector<glm::vec3> ScaleValues;
|
||||
std::vector<float> AlphaValues;
|
||||
|
||||
//Particle
|
||||
std::string SpriteFile = "";
|
||||
double ParticleLifeTime = 3.f;
|
||||
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(ParticleFlags::Powder | ParticleFlags::ParticleContactFilter | ParticleFlags::FixtureContactFilter);
|
||||
float Radius = 1.f;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace dd
|
||||
class PhysicsSystem : public System
|
||||
{
|
||||
friend class ContractListener;
|
||||
friend class DestructionListener;
|
||||
//friend class DestructionListener;
|
||||
|
||||
public:
|
||||
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
@@ -106,6 +106,9 @@ namespace dd
|
||||
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale, int maxCount);
|
||||
void CreateParticleEmitter(EntityID entity);
|
||||
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed.
|
||||
float ScalarInterpolation(float timeProgress, std::vector<float> spectrum);
|
||||
glm::vec3 VectorInterpolation(float timeProgress, std::vector<glm::vec3> spectrum);
|
||||
|
||||
|
||||
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
|
||||
bool SetImpulse(const Events::SetImpulse &event);
|
||||
@@ -128,36 +131,36 @@ namespace dd
|
||||
std::list<Impulse> m_Impulses;
|
||||
|
||||
|
||||
class DestructionListener : public b2DestructionListener
|
||||
{
|
||||
public:
|
||||
DestructionListener(PhysicsSystem* physicsSystem)
|
||||
: m_PhysicsSystem(physicsSystem) { }
|
||||
|
||||
void SayGoodbye(b2Joint*) {LOG_INFO("joint körs");};
|
||||
void SayGoodbye(b2Fixture*) {/*LOG_INFO("Fixture körs");*/};
|
||||
|
||||
void SayGoodbye(b2ParticleSystem* particleSystem, int32 index) override
|
||||
{
|
||||
LOG_INFO("Particle ded");
|
||||
|
||||
|
||||
const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index);
|
||||
for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) {
|
||||
if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) {
|
||||
std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle);
|
||||
if(it != m_PhysicsSystem->m_ParticleHandleToEntities[i].end()) {
|
||||
EntityID id = it->second;
|
||||
m_PhysicsSystem->m_World->RemoveEntity(id);
|
||||
m_PhysicsSystem->m_ParticleHandleToEntities[i].erase(it);
|
||||
LOG_INFO("Removing from list");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
// class DestructionListener : public b2DestructionListener
|
||||
// {
|
||||
// public:
|
||||
// DestructionListener(PhysicsSystem* physicsSystem)
|
||||
// : m_PhysicsSystem(physicsSystem) { }
|
||||
//
|
||||
// void SayGoodbye(b2Joint*) {LOG_INFO("joint körs");};
|
||||
// void SayGoodbye(b2Fixture*) {/*LOG_INFO("Fixture körs");*/};
|
||||
//
|
||||
// void SayGoodbye(b2ParticleSystem* particleSystem, int32 index) override
|
||||
// {
|
||||
// // LOG_INFO("Particle ded");
|
||||
// //
|
||||
// //
|
||||
// // const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index);
|
||||
// // for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) {
|
||||
// // if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) {
|
||||
// // std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle);
|
||||
// // if(it != m_PhysicsSystem->m_ParticleHandleToEntities[i].end()) {
|
||||
// // EntityID id = it->second;
|
||||
// // m_PhysicsSystem->m_World->RemoveEntity(id);
|
||||
// // m_PhysicsSystem->m_ParticleHandleToEntities[i].erase(it);
|
||||
// // LOG_INFO("Removing from list");
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// }
|
||||
// private:
|
||||
// PhysicsSystem* m_PhysicsSystem;
|
||||
// };
|
||||
|
||||
class ParticleContactDisabler : public b2ContactFilter
|
||||
{
|
||||
@@ -195,7 +198,7 @@ namespace dd
|
||||
PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
|
||||
DestructionListener* m_DestructionListener;
|
||||
//DestructionListener* m_DestructionListener;
|
||||
ParticleContactDisabler* m_ParticleContactDisabler;
|
||||
ContactListener* m_ContactListener;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef AnimationSystem_h__
|
||||
#define AnimationSystem_h__
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/World.h"
|
||||
#include "Rendering/CAnimation.h"
|
||||
#include "Game/EPause.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class AnimationSystem : public System
|
||||
{
|
||||
public:
|
||||
AnimationSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
void Update(double dt) override;
|
||||
|
||||
private:
|
||||
bool m_Paused = false;
|
||||
|
||||
EventRelay<AnimationSystem, Events::Pause> m_EPause;
|
||||
bool OnPause(const Events::Pause& e);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef COMPONENTS_CANIMATION_H__
|
||||
#define COMPONENTS_CANIMATION_H__
|
||||
|
||||
#include "Core/Component.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Animation : Component
|
||||
{
|
||||
std::string Name;
|
||||
double Time = 0.0;
|
||||
double Speed = 0.0;
|
||||
bool NoRootMotion = true;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Core/World.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
#include "Sound.h"
|
||||
#include "Sound/EPlaySound.h"
|
||||
#include "Sound/EStopSound.h"
|
||||
|
||||
@@ -50,6 +50,7 @@ source_group(Input FILES ${SOURCE_FILES_Input})
|
||||
|
||||
file(GLOB SOURCE_FILES_Rendering
|
||||
"${INCLUDE_PATH}/Rendering/*.h"
|
||||
"Rendering/*.cpp"
|
||||
)
|
||||
source_group(Rendering FILES ${SOURCE_FILES_Rendering})
|
||||
|
||||
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
|
||||
dd::ConfigFile::ConfigFile(std::string path)
|
||||
{
|
||||
m_Path = path;
|
||||
|
||||
boost::filesystem::path defaultFile;
|
||||
defaultFile = m_Path.parent_path() / ("Default" + m_Path.filename().string());
|
||||
|
||||
// Read defaults
|
||||
if (boost::filesystem::exists(defaultFile)) {
|
||||
try {
|
||||
boost::property_tree::ini_parser::read_ini(defaultFile.string(), m_PTreeDefaults);
|
||||
} catch (boost::property_tree::ptree_error& e) {
|
||||
LOG_ERROR("Failed to parse \"%s\":\n%s", defaultFile.string().c_str(), e.what());
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("Failed to find \"%s\"! Relying on hardcoded default values!", defaultFile.string().c_str());
|
||||
}
|
||||
|
||||
m_PTreeMerged = m_PTreeDefaults;
|
||||
|
||||
// Read overrides
|
||||
if (boost::filesystem::exists(m_Path)) {
|
||||
try {
|
||||
boost::property_tree::ini_parser::read_ini(m_Path.string(), m_PTreeOverrides);
|
||||
for (auto& node : m_PTreeOverrides) {
|
||||
m_PTreeMerged.put_child(node.first, node.second);
|
||||
}
|
||||
} catch (boost::property_tree::ptree_error& e) {
|
||||
LOG_ERROR("Failed to parse \"%s\":\n%s", m_Path.filename().string().c_str(), e.what());
|
||||
}
|
||||
}}
|
||||
|
||||
void dd::ConfigFile::SaveToDisk()
|
||||
{
|
||||
boost::property_tree::ini_parser::write_ini(m_Path.string(), m_PTreeOverrides);
|
||||
}
|
||||
@@ -30,6 +30,15 @@ dd::Model::Model(std::string fileName)
|
||||
return;
|
||||
}
|
||||
|
||||
auto m = scene->mRootNode->mTransformation;
|
||||
m_Matrix = glm::mat4(
|
||||
m.a1, m.a2, m.a3, m.a4,
|
||||
m.b1, m.b2, m.b3, m.b4,
|
||||
m.c1, m.c2, m.c3, m.c4,
|
||||
m.d1, m.d2, m.d3, m.d4
|
||||
);
|
||||
m_Matrix = glm::transpose(m_Matrix);
|
||||
|
||||
auto meshes = scene->mMeshes;
|
||||
|
||||
// Pre-count vertices
|
||||
|
||||
+15
-3
@@ -37,7 +37,7 @@ dd::PNG::PNG(std::string path)
|
||||
}
|
||||
|
||||
// Initialize libpng
|
||||
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
||||
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, (png_error_ptr)&PNG::pngErrorFunction, (png_error_ptr)&PNG::pngErrorFunction);
|
||||
if (!png_ptr) {
|
||||
LOG_ERROR("libpng: Failed to initialze png_struct");
|
||||
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
|
||||
@@ -97,6 +97,7 @@ dd::PNG::PNG(std::string path)
|
||||
|
||||
// Read in the data
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
delete[] row_pointers;
|
||||
|
||||
this->Width = width;
|
||||
this->Height = height;
|
||||
@@ -107,7 +108,18 @@ dd::PNG::PNG(std::string path)
|
||||
|
||||
dd::PNG::~PNG()
|
||||
{
|
||||
if (Data) {
|
||||
delete[] Data;
|
||||
if (this->Data != nullptr) {
|
||||
delete[] this->Data;
|
||||
this->Data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void dd::PNG::pngErrorFunction(png_structp png_ptr, png_const_charp error_msg)
|
||||
{
|
||||
LOG_WARNING("%s", error_msg);
|
||||
}
|
||||
|
||||
void dd::PNG::pngWarningFunction(png_structp png_ptr, png_const_charp warning_msg)
|
||||
{
|
||||
LOG_WARNING("%s", warning_msg);
|
||||
}
|
||||
|
||||
@@ -431,6 +431,20 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
glBindTexture(GL_TEXTURE_2D, *m_StandardSpecular);
|
||||
}
|
||||
|
||||
if (modelJob->Skeleton != nullptr) {
|
||||
auto animation = modelJob->Skeleton->GetAnimation(modelJob->AnimationName);
|
||||
if (animation != nullptr) {
|
||||
std::vector<glm::mat4> frameBones = modelJob->Skeleton->GetFrameBones(
|
||||
*animation,
|
||||
modelJob->AnimationTime,
|
||||
modelJob->NoRootMotion
|
||||
);
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
} else {
|
||||
LOG_WARNING("Tried to play unknown animation \"%s\"", modelJob->AnimationName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
glBindVertexArray(modelJob->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
|
||||
@@ -65,7 +65,7 @@ void main()
|
||||
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
||||
}
|
||||
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
|
||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||
|
||||
@@ -65,8 +65,8 @@ void main()
|
||||
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
||||
}
|
||||
|
||||
//gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
//gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
//TODO: Make sure that boneTransform works here.
|
||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
|
||||
@@ -48,10 +48,18 @@ dd::Skeleton::~Skeleton()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<glm::mat4> dd::Skeleton::GetFrameBones(std::string animationName, double time, bool noRootMotion /*= false*/)
|
||||
const dd::Skeleton::Animation* dd::Skeleton::GetAnimation(std::string name)
|
||||
{
|
||||
auto& animation = Animations.at(animationName);
|
||||
auto it = Animations.find(name);
|
||||
if (it != Animations.end()) {
|
||||
return const_cast<const Animation*>(&it->second);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<glm::mat4> dd::Skeleton::GetFrameBones(const Animation& animation, double time, bool noRootMotion /*= false*/)
|
||||
{
|
||||
// HACK: Animation wrap-around
|
||||
while (time < 0)
|
||||
time += animation.Duration;
|
||||
@@ -60,8 +68,8 @@ std::vector<glm::mat4> dd::Skeleton::GetFrameBones(std::string animationName, do
|
||||
|
||||
int currentKeyframeIndex = GetKeyframe(animation, time);
|
||||
|
||||
Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex];
|
||||
Animation::Keyframe& nextFrame = animation.Keyframes[currentKeyframeIndex + 1];
|
||||
const Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex];
|
||||
const Animation::Keyframe& nextFrame = animation.Keyframes[currentKeyframeIndex + 1];
|
||||
float alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
|
||||
|
||||
//auto animationFrame = Animations[""].Keyframes[frame];
|
||||
@@ -75,7 +83,7 @@ std::vector<glm::mat4> dd::Skeleton::GetFrameBones(std::string animationName, do
|
||||
return finalMatrices;
|
||||
}
|
||||
|
||||
void dd::Skeleton::AccumulateBoneTransforms(bool noRootMotion, Animation::Keyframe ¤tFrame, Animation::Keyframe &nextFrame, float progress, std::map<int, glm::mat4> &boneMatrices, Bone* bone, glm::mat4 parentMatrix)
|
||||
void dd::Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyframe ¤tFrame, const Animation::Keyframe &nextFrame, float progress, std::map<int, glm::mat4> &boneMatrices, const Bone* bone, glm::mat4 parentMatrix)
|
||||
{
|
||||
glm::mat4 boneMatrix;
|
||||
|
||||
@@ -117,10 +125,13 @@ int dd::Skeleton::GetBoneID(std::string name)
|
||||
|
||||
void dd::Skeleton::PrintSkeleton()
|
||||
{
|
||||
if (LOG_LEVEL < LOG_LEVEL_DEBUG) {
|
||||
return;
|
||||
}
|
||||
PrintSkeleton(RootBone, 0);
|
||||
}
|
||||
|
||||
void dd::Skeleton::PrintSkeleton(Bone* bone, int depthCount)
|
||||
void dd::Skeleton::PrintSkeleton(const Bone* bone, int depthCount)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::string(depthCount, ' ');
|
||||
@@ -134,7 +145,7 @@ void dd::Skeleton::PrintSkeleton(Bone* bone, int depthCount)
|
||||
}
|
||||
}
|
||||
|
||||
int dd::Skeleton::GetKeyframe(Animation& animation, double time)
|
||||
int dd::Skeleton::GetKeyframe(const Animation& animation, double time)
|
||||
{
|
||||
if (time < 0)
|
||||
time = 0;
|
||||
@@ -143,7 +154,7 @@ int dd::Skeleton::GetKeyframe(Animation& animation, double time)
|
||||
|
||||
for (int keyframe = 0; keyframe < animation.Keyframes.size(); ++keyframe) {
|
||||
if (animation.Keyframes[keyframe].Time > time)
|
||||
return keyframe - 1;
|
||||
return glm::max(0, keyframe - 1); // HACK: If the time is less than the first keyframe, don
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -21,21 +21,21 @@
|
||||
|
||||
dd::Texture::Texture(std::string path)
|
||||
{
|
||||
std::unique_ptr<Image> image = std::make_unique<PNG>(path);
|
||||
PNG image(path);
|
||||
|
||||
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
|
||||
image = std::make_unique<PNG>("Textures/Core/ErrorTexture.png");
|
||||
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
|
||||
if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) {
|
||||
image = PNG("Textures/Core/ErrorTexture.png");
|
||||
if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) {
|
||||
LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this->Width = image->Width;
|
||||
this->Height = image->Height;
|
||||
this->Width = image.Width;
|
||||
this->Height = image.Height;
|
||||
|
||||
GLint format;
|
||||
switch (image->Format) {
|
||||
switch (image.Format) {
|
||||
case Image::ImageFormat::RGB:
|
||||
format = GL_RGB;
|
||||
break;
|
||||
@@ -48,7 +48,7 @@ dd::Texture::Texture(std::string path)
|
||||
glGenTextures(1, &m_Texture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_Texture);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, image->Width, image->Height, 0, format, GL_UNSIGNED_BYTE, image->Data);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, image.Width, image.Height, 0, format, GL_UNSIGNED_BYTE, image.Data);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "Core/Util/Logging.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
_LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG;
|
||||
#else
|
||||
_LOG_LEVEL LOG_LEVEL = LOG_LEVEL_INFO;
|
||||
#endif
|
||||
@@ -154,12 +154,14 @@ void dd::World::Initialize()
|
||||
{
|
||||
RegisterSystems();
|
||||
AddSystems();
|
||||
for (auto pair : m_Systems)
|
||||
{
|
||||
auto system = pair.second;
|
||||
system->RegisterComponents(&ComponentFactory);
|
||||
system->RegisterResourceTypes(ResourceManager);
|
||||
system->Initialize();
|
||||
for (auto pair : m_Systems) {
|
||||
pair.second->RegisterComponents(&ComponentFactory);
|
||||
}
|
||||
for (auto pair : m_Systems) {
|
||||
pair.second->RegisterResourceTypes(ResourceManager);
|
||||
}
|
||||
for (auto pair : m_Systems) {
|
||||
pair.second->Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ void dd::Systems::BallSystem::Initialize()
|
||||
transform->Scale = glm::vec3(0.3f, 0.3f, 0.3f);
|
||||
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||
model->ModelFile = "Models/Test/Ball/Sid.obj";
|
||||
model->ModelFile = "Models/Sid/Sid.dae";
|
||||
auto animation = m_World->AddComponent<Components::Animation>(ent);
|
||||
animation->Speed = 1.0;
|
||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||
circleShape->Radius = 0.4f;
|
||||
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
||||
@@ -308,7 +310,7 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
} else if (ballTransform->Position.x <= -2.7f) {
|
||||
particleEvent.Position = glm::vec3(-2.7f, -3.f, -3.f);
|
||||
}
|
||||
particleEvent.Radius = 1.f;
|
||||
particleEvent.ScaleValues.push_back(glm::vec3(1.f));
|
||||
particleEvent.Color = glm::vec4(1.f);
|
||||
particleEvent.Speed = 0;
|
||||
|
||||
@@ -322,7 +324,7 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
EventBroker->Publish(particleEvent);
|
||||
}
|
||||
|
||||
ballComponent->Combo = 56;
|
||||
ballComponent->Combo = 0;
|
||||
if (!ballComponent->Waiting) {
|
||||
if (m_InkBlaster) {
|
||||
if (!m_InkAttached) {
|
||||
@@ -421,7 +423,7 @@ void dd::Systems::BallSystem::CreateLife(int number)
|
||||
lifeNr->Number = number;
|
||||
|
||||
auto model = m_World->AddComponent<Components::Model>(life);
|
||||
model->ModelFile = "Models/Test/Ball/Sid.obj";
|
||||
model->ModelFile = "Models/Sid/Sid.dae";
|
||||
|
||||
|
||||
m_World->CommitEntity(life);
|
||||
|
||||
@@ -612,6 +612,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
brick->Removed = true;
|
||||
m_World->RemoveEntity(entityShot);
|
||||
BrickHit(entityShot, entityBrick, 1);
|
||||
//ep.Radius = 0.05;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -719,6 +720,45 @@ void dd::Systems::LevelSystem::BrickHit(EntityID entityHitter, EntityID entityBr
|
||||
m_World->RemoveComponent<Components::Template>(b);
|
||||
m_World->SetEntityParent(b, 0);
|
||||
m_World->CommitEntity(b);
|
||||
|
||||
//Particle trail
|
||||
Events::CreateParticleSequence trail;
|
||||
trail.parent = b;
|
||||
trail.AlphaValues.push_back(1.f);
|
||||
trail.AlphaValues.push_back(0.f);
|
||||
trail.ScaleValues.push_back(glm::vec3(0.08f));
|
||||
trail.ScaleValues.push_back(glm::vec3(0.f));
|
||||
trail.RadiusDistribution = 1;
|
||||
trail.EmitterLifeTime = 2.f;
|
||||
trail.ParticleLifeTime = 1.f;
|
||||
trail.ParticlesPerTick = 1;
|
||||
trail.SpawnRate = 0.1f;
|
||||
trail.Speed = 10.f;
|
||||
trail.EmittingAngle = glm::half_pi<float>();
|
||||
trail.SpriteFile = "Textures/Particles/FadeBall.png";
|
||||
trail.Color = brickModel->Color;
|
||||
//p.Spread = ...
|
||||
EventBroker->Publish(trail);
|
||||
|
||||
//ParticlePoof
|
||||
Events::CreateParticleSequence poof;
|
||||
poof.EmitterLifeTime = 4;
|
||||
poof.EmittingAngle = glm::half_pi<float>();
|
||||
poof.Spread = 0.5f;
|
||||
poof.NumberOfTicks = 1;
|
||||
poof.ParticleLifeTime = 1.5f;
|
||||
poof.ParticlesPerTick = 1;
|
||||
poof.Position = cTransform->Position;
|
||||
poof.ScaleValues.clear();
|
||||
poof.ScaleValues.push_back(glm::vec3(0.5f));
|
||||
poof.ScaleValues.push_back(glm::vec3(2.f, 2.f, 0.2f));
|
||||
poof.SpriteFile = "Textures/Particles/Cloud_Particle.png";
|
||||
poof.Color = brickModel->Color;
|
||||
poof.AlphaValues.clear();
|
||||
poof.AlphaValues.push_back(1.f);
|
||||
poof.AlphaValues.push_back(0.f);
|
||||
poof.Speed = 10;
|
||||
EventBroker->Publish(poof);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ void dd::Systems::PhysicsSystem::Initialize()
|
||||
{
|
||||
std::random_device rd;
|
||||
gen = std::mt19937(rd());
|
||||
m_DestructionListener = new DestructionListener(this);
|
||||
// m_DestructionListener = new DestructionListener(this);
|
||||
m_ContactListener = new ContactListener(this);
|
||||
m_PhysicsWorld = new b2World(m_Gravity);
|
||||
m_ParticleContactDisabler = new ParticleContactDisabler();
|
||||
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
||||
m_PhysicsWorld->SetContactFilter(m_ParticleContactDisabler);
|
||||
m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
||||
// m_PhysicsWorld->SetDestructionListener(m_DestructionListener);
|
||||
|
||||
InitializeWater();
|
||||
EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse);
|
||||
@@ -231,8 +231,10 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
parentTransform = tp->Position;
|
||||
}
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
||||
|
||||
transform->Position = glm::vec3(position.x, position.y, transform->Position.z);
|
||||
transform->Scale = particle->Scale;//glm::vec3(particle->Radius * 2.f, particle->Radius * 2.f, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,8 +248,9 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
||||
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
|
||||
|
||||
if (particle && !pTemplate) {
|
||||
particle->LifeTime -= dt;
|
||||
if (particle->LifeTime <= 0) {
|
||||
particle->TimeLived += dt;
|
||||
//Delete particles
|
||||
if (particle->TimeLived >= particle->LifeTime - 0.1) {
|
||||
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
|
||||
const b2ParticleHandle* handle = m_EntitiesToParticleHandle[i][entity];
|
||||
std::unordered_map<EntityID, const b2ParticleHandle*>::iterator iter1;
|
||||
@@ -263,10 +266,21 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
||||
m_World->RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
//Update alpha
|
||||
auto sprite = m_World->GetComponent<Components::Sprite>(entity);
|
||||
sprite->Color.w = particle->LifeTime;
|
||||
float timeProgress = particle->TimeLived / (particle->LifeTime - 0.1);
|
||||
if (timeProgress > 1) {
|
||||
timeProgress = 1;
|
||||
}
|
||||
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(particle->ParticleSystem);
|
||||
if (emitter) {
|
||||
sprite->Color.w = ScalarInterpolation(timeProgress, emitter->AlphaValues);
|
||||
particle->Scale = VectorInterpolation(timeProgress, emitter->ScaleValues);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Particlesystem relative to parent
|
||||
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
||||
if (emitter) {
|
||||
EntityID emitterParent = emitter->Parent;
|
||||
@@ -280,6 +294,43 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
||||
}
|
||||
}
|
||||
|
||||
float dd::Systems::PhysicsSystem::ScalarInterpolation(float timeProgress, std::vector<float> spectrum)
|
||||
{
|
||||
int spectrumSize = spectrum.size();
|
||||
if (spectrumSize == 0) {
|
||||
return 1.f;
|
||||
}
|
||||
if (spectrumSize == 1) {
|
||||
return spectrum[0];
|
||||
}
|
||||
|
||||
float dValue = spectrum[1] - spectrum[0];
|
||||
float scalar = spectrum[0] + dValue * timeProgress;
|
||||
|
||||
return scalar;
|
||||
}
|
||||
|
||||
glm::vec3 dd::Systems::PhysicsSystem::VectorInterpolation(float timeProgress, std::vector<glm::vec3> spectrum)
|
||||
{
|
||||
int spectrumSize = spectrum.size();
|
||||
if (spectrumSize == 0) {
|
||||
LOG_ERROR("You need to supply your particlesystem with scales in ScaleValues.");
|
||||
return glm::vec3(1);
|
||||
}
|
||||
else if (spectrumSize == 1) {
|
||||
return spectrum[0];
|
||||
}
|
||||
|
||||
float dX = spectrum[1].x - spectrum[0].x;
|
||||
float x = spectrum[0].x + dX * timeProgress;
|
||||
float dY = spectrum[1].y - spectrum[0].y;
|
||||
float y = spectrum[0].y + dY * timeProgress;
|
||||
float dZ = spectrum[1].z - spectrum[0].z;
|
||||
float z = spectrum[0].z + dZ * timeProgress;
|
||||
|
||||
return glm::vec3(x, y, z);
|
||||
}
|
||||
|
||||
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
||||
{
|
||||
if (event.Type != "PhysicsSystem" && event.Type != "All") {
|
||||
@@ -332,7 +383,6 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
||||
m_BodiesToEntities.erase(it->second);
|
||||
m_EntitiesToBodies.erase(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -473,44 +523,70 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
if(emitter->TimeSinceLastSpawn < emitter->SpawnRate || emitter->NumberOfTicks < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
emitter->NumberOfTicks--;
|
||||
emitter->TimeSinceLastSpawn -= emitter->SpawnRate;
|
||||
auto templateTransform = m_World->GetComponent<Components::Transform>(pt);
|
||||
b2ParticleDef particleDef;
|
||||
|
||||
//Create new particle
|
||||
for ( int j = 0; j < emitter->ParticlesPerTick; j++) {
|
||||
b2ParticleDef particleDef;
|
||||
//position
|
||||
particleDef.position = b2Vec2(emitterTransform->Position.x, emitterTransform->Position.y);
|
||||
if (particleDef.position.x == 0.f && particleDef.position.y == 0.f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto particle = m_World->CloneEntity(pt, 0);
|
||||
m_World->RemoveComponent<Components::Template>(particle);
|
||||
auto particleTransform = m_World->GetComponent<Components::Transform>(particle);
|
||||
auto particleComponent = m_World->GetComponent<Components::Particle>(particle);
|
||||
|
||||
particleDef.flags = particleTemplate->Flags;
|
||||
//particleDef.color TODO: Implement this if we want color mixing and shit.
|
||||
particleDef.lifetime = particleTemplate->LifeTime;
|
||||
float eAngle = emitter->EmittingAngle;
|
||||
float halfSpread = emitter->Spread / 2;
|
||||
|
||||
//random angle
|
||||
float eAngle = emitter->EmittingAngle;
|
||||
float halfSpread = emitter->Spread / 2;
|
||||
std::uniform_real_distribution<float> dis(eAngle - halfSpread, eAngle + halfSpread);
|
||||
float pAngle = dis(gen);
|
||||
|
||||
//Using angle to determine velocity
|
||||
std::uniform_real_distribution<float> dis2(0.3, 1.5);
|
||||
float speedMultiplier = dis2(gen);
|
||||
glm::vec2 unitVec = glm::normalize(glm::vec2(glm::cos(pAngle), glm::sin(pAngle)));
|
||||
glm::vec2 vel = unitVec * emitter->Speed * (float)dt * speedMultiplier * 0.5f;
|
||||
glm::vec2 vel = unitVec * emitter->Speed * (float)dt * speedMultiplier;
|
||||
particleDef.velocity = b2Vec2(vel.x, vel.y);
|
||||
particleDef.position = b2Vec2(emitterTransform->Position.x, emitterTransform->Position.y);
|
||||
|
||||
//radius
|
||||
float radius = emitter->ScaleValues[0].x;
|
||||
float newRadius = 0;
|
||||
if (emitter->RadiusDistribution > 0) {
|
||||
float halfRadius = radius / 2;
|
||||
std::uniform_real_distribution<float> dis3(radius - halfRadius, radius + halfRadius);
|
||||
newRadius = dis3(gen);
|
||||
}
|
||||
else {
|
||||
newRadius = radius;
|
||||
}
|
||||
particleComponent->Scale = glm::vec3(newRadius);
|
||||
|
||||
|
||||
auto particle = m_World->CloneEntity(pt, 0);
|
||||
m_World->RemoveComponent<Components::Template>(particle);
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(particle);
|
||||
|
||||
//Random z-value
|
||||
std::uniform_real_distribution<float> dist(0, 1);
|
||||
float zDistribution = dist(gen);
|
||||
transform2->Position = glm::vec3(emitterTransform->Position.x, emitterTransform->Position.y, -9.5f + zDistribution);
|
||||
transform2->Scale = glm::vec3(particleTemplate->Radius * 2.f / speedMultiplier, particleTemplate->Radius * 2.f / speedMultiplier, 1);
|
||||
particleTransform->Position = glm::vec3(emitterTransform->Position.x, emitterTransform->Position.y, -9.5f + zDistribution);
|
||||
particleTransform->Scale = particleTemplate->Scale;
|
||||
//glm::vec3(particleTemplate->Radius * 2.f / speedMultiplier, particleTemplate->Radius * 2.f / speedMultiplier, 1);
|
||||
particleTransform->Velocity = glm::vec3(vel.x, vel.y, 0);
|
||||
|
||||
|
||||
auto b2Particle = ps->CreateParticle(particleDef);
|
||||
auto b2ParticleIndex = ps->CreateParticle(particleDef);
|
||||
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2ParticleIndex);
|
||||
|
||||
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
|
||||
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
||||
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -523,7 +599,7 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
// std::cout << "Entities and handles: " << entHandles << std::endl;
|
||||
// LOG_INFO("Particles living: %i", pSizeTest);
|
||||
// LOG_INFO("Particle systems: %i", psListSize);
|
||||
// int entHandles = 0;
|
||||
// //int entHandles = 0;
|
||||
// for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++)
|
||||
// entHandles += m_EntitiesToParticleHandle[i].size();
|
||||
// LOG_INFO("Entities and handles: %i", entHandles);
|
||||
@@ -538,7 +614,7 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
}
|
||||
}
|
||||
|
||||
if (m_ParticleEmitters.ParticleSystem[key]->GetParticleCount() == 0 && key <= m_ParticleEmitters.ParticleSystem.size()) {
|
||||
if (m_ParticleEmitters.ParticleSystem[key]->GetParticleCount() == 0 && key <= m_ParticleEmitters.ParticleSystem.size() - 1) {
|
||||
// DEBUG vvvvvv
|
||||
// int t_Entities = m_World->GetEntities()->size();
|
||||
// int t_Systems = m_ParticleEmitters.ParticleSystem.size();
|
||||
@@ -576,7 +652,7 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
m_ParticleEmitters.ParticleTemplate.erase(m_ParticleEmitters.ParticleTemplate.begin() + key);
|
||||
m_EntitiesToParticleHandle.erase(m_EntitiesToParticleHandle.begin() + key);
|
||||
m_ParticleHandleToEntities.erase(m_ParticleHandleToEntities.begin() + key);
|
||||
|
||||
emittersToDelete.clear();
|
||||
// DEBUG vvvvv
|
||||
// t_Entities = m_World->GetEntities()->size();
|
||||
// t_Systems = m_ParticleEmitters.ParticleSystem.size();
|
||||
@@ -609,14 +685,6 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int stp = 0;
|
||||
for (auto ts : m_EntitiesToParticleHandle)
|
||||
{
|
||||
stp += ts.size();
|
||||
}
|
||||
}
|
||||
|
||||
bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreateParticleSequence &event)
|
||||
@@ -640,21 +708,23 @@ bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreatePart
|
||||
particleEmitter->Spread = event.Spread;
|
||||
particleEmitter->EmittingAngle = event.EmittingAngle;
|
||||
particleEmitter->LifeTime = event.EmitterLifeTime;
|
||||
|
||||
{
|
||||
//Creating Particle Template
|
||||
auto particle = m_World->CreateEntity(emitter);
|
||||
auto particleTransform = m_World->AddComponent<Components::Transform>(particle);
|
||||
auto sprite = m_World->AddComponent<Components::Sprite>(particle);
|
||||
auto particleComponent = m_World->AddComponent<Components::Particle>(particle);
|
||||
m_World->AddComponent<Components::Template>(particle);
|
||||
|
||||
particleTransform->Position = emitterTransform->Position;
|
||||
sprite->SpriteFile = event.SpriteFile;
|
||||
particleEmitter->AlphaValues = event.AlphaValues;
|
||||
particleEmitter->ScaleValues = event.ScaleValues;
|
||||
particleEmitter->RadiusDistribution = event.RadiusDistribution;
|
||||
{
|
||||
//Creating Particle Template
|
||||
auto particle = m_World->CreateEntity(emitter);
|
||||
auto particleTransform = m_World->AddComponent<Components::Transform>(particle);
|
||||
auto sprite = m_World->AddComponent<Components::Sprite>(particle);
|
||||
auto particleComponent = m_World->AddComponent<Components::Particle>(particle);
|
||||
m_World->AddComponent<Components::Template>(particle);
|
||||
particleTransform->Position = emitterTransform->Position;
|
||||
sprite->SpriteFile = event.SpriteFile;
|
||||
sprite->Color = event.Color;
|
||||
particleComponent->LifeTime = event.ParticleLifeTime;
|
||||
particleComponent->Flags = event.Flags;
|
||||
particleComponent->Radius = event.Radius;
|
||||
particleComponent->LifeTime = event.ParticleLifeTime;
|
||||
particleComponent->Flags = event.Flags;
|
||||
particleComponent->Scale = event.ScaleValues[0];
|
||||
particleComponent->ParticleSystem = emitter;
|
||||
}
|
||||
m_World->CommitEntity(emitter);
|
||||
return true;
|
||||
@@ -691,7 +761,7 @@ void dd::Systems::PhysicsSystem::CreateParticleEmitter(EntityID entity)
|
||||
}
|
||||
//TODO: Skicka med fler flaggor till particlesystemet;
|
||||
|
||||
m_ParticleEmitters.ParticleSystem.push_back(CreateParticleSystem(particle->Radius, 0.f, 0));
|
||||
m_ParticleEmitters.ParticleSystem.push_back(CreateParticleSystem(particle->Scale.x, 0.f, 0));
|
||||
m_ParticleEmitters.ParticleEmitter.push_back(entity);
|
||||
m_ParticleEmitters.ParticleTemplate.push_back(childEntity);
|
||||
}
|
||||
@@ -708,18 +778,18 @@ b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius,
|
||||
m_ParticleSystemDef.maxCount = maxCount;
|
||||
m_ParticleSystemDef.radius = radius;
|
||||
m_ParticleSystemDef.gravityScale = gravityScale;
|
||||
m_ParticleSystemDef.destroyByAge = true;
|
||||
m_ParticleSystemDef.destroyByAge = false;
|
||||
|
||||
return m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
||||
}
|
||||
|
||||
bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||
{
|
||||
//Check if it is a brick colliding
|
||||
//Check if it is a brick colliding with ball
|
||||
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
|
||||
EntityID entity = event.Entity1;
|
||||
Components::Model* model;
|
||||
|
||||
auto ball = m_World->GetComponent<Components::Ball>(event.Entity2);
|
||||
if (!brick) {
|
||||
brick = m_World->GetComponent<Components::Brick>(event.Entity2);
|
||||
EntityID entity = event.Entity2;
|
||||
@@ -730,14 +800,19 @@ bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||
model = m_World->GetComponent<Components::Model>(event.Entity2);
|
||||
}
|
||||
}
|
||||
else if (!ball) {
|
||||
ball = m_World->GetComponent<Components::Ball>(event.Entity1);
|
||||
if (!ball) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
model = m_World->GetComponent<Components::Model>(event.Entity1);
|
||||
}
|
||||
|
||||
//Spawn a particle when a brick collides with somthing
|
||||
Events::CreateParticleSequence e;
|
||||
|
||||
|
||||
e.EmitterLifeTime = 3;
|
||||
e.EmittingAngle = glm::half_pi<float>();
|
||||
e.Spread = 0.f;
|
||||
@@ -746,7 +821,9 @@ bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||
e.ParticlesPerTick = 1;
|
||||
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -7);
|
||||
e.Color = glm::vec4(1.f);
|
||||
e.Radius = 1.f;
|
||||
e.AlphaValues.push_back(1.f);
|
||||
e.AlphaValues.push_back(0.f);
|
||||
e.ScaleValues.push_back(glm::vec3(1.f));
|
||||
e.Speed = 0;
|
||||
|
||||
auto PowerFriend = m_World->GetComponent<Components::MultiBallBrick>(entity);
|
||||
@@ -771,13 +848,18 @@ bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
||||
e.EmittingAngle = glm::half_pi<float>();
|
||||
e.Spread = 0.5f;
|
||||
e.NumberOfTicks = 1;
|
||||
e.ParticleLifeTime = 1.f;
|
||||
e.ParticlesPerTick = 15;
|
||||
e.ParticleLifeTime = 0.5f;
|
||||
e.ParticlesPerTick = 1;
|
||||
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -10);
|
||||
e.Radius = 0.2f;
|
||||
e.ScaleValues.clear();
|
||||
e.ScaleValues.push_back(glm::vec3(0.5f));
|
||||
e.ScaleValues.push_back(glm::vec3(4.f, 4.f, 0.2f));
|
||||
e.SpriteFile = "Textures/Particles/Cloud_Particle.png";
|
||||
e.Color = model->Color + glm::vec4(0.5f);
|
||||
e.Speed = 100;
|
||||
e.Color = model->Color;
|
||||
e.AlphaValues.clear();
|
||||
e.AlphaValues.push_back(1.f);
|
||||
e.AlphaValues.push_back(0.f);
|
||||
//e.Speed = 0;
|
||||
}
|
||||
|
||||
EventBroker->Publish(e);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/AnimationSystem.h"
|
||||
|
||||
void dd::Systems::AnimationSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register<Components::Animation>();
|
||||
}
|
||||
|
||||
void dd::Systems::AnimationSystem::Initialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &AnimationSystem::OnPause);
|
||||
}
|
||||
|
||||
void dd::Systems::AnimationSystem::Update(double dt)
|
||||
{
|
||||
if (m_Paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto animations = m_World->GetComponentsOfType<Components::Animation>();
|
||||
if (animations == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& component : *animations) {
|
||||
auto animation = static_cast<Components::Animation*>(component.get());
|
||||
animation->Time += animation->Speed * dt;
|
||||
}
|
||||
}
|
||||
|
||||
bool dd::Systems::AnimationSystem::OnPause(const Events::Pause& e)
|
||||
{
|
||||
m_Paused = !m_Paused;
|
||||
return true;
|
||||
}
|
||||
@@ -27,6 +27,9 @@ void dd::Systems::SoundSystem::Initialize()
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume);
|
||||
|
||||
m_SFXMasterVolume = ResourceManager::Load<ConfigFile>("Config.ini")->GetValue<float>("Audio.SFXVolume", 1.f);
|
||||
m_BGMMasterVolume = ResourceManager::Load<ConfigFile>("Config.ini")->GetValue<float>("Audio.BGMVolume", 1.f);
|
||||
|
||||
//Todo: Move this
|
||||
{
|
||||
dd::Events::PlaySound e;
|
||||
|
||||
+3
-1
@@ -1,4 +1,4 @@
|
||||
@ECHO on
|
||||
@ECHO off
|
||||
|
||||
SET DeployLocation=bin\
|
||||
|
||||
@@ -7,6 +7,8 @@ ECHO Deploying resources to %DeployLocation%
|
||||
MKLINK "%DeployLocation%\Models\" "assets\Models" /J
|
||||
MKLINK "%DeployLocation%\Textures\" "assets\Textures\" /J
|
||||
MKLINK "%DeployLocation%\Sounds\" "assets\Sounds\" /J
|
||||
:: Configuration files
|
||||
MKLINK "%DeployLocation%\DefaultConfig.ini" "assets\DefaultConfig.ini" /H
|
||||
:: Shaders
|
||||
MKLINK "%DeployLocation%\Shaders\" "src\game\Core\Shaders\" /J
|
||||
:: Platform specific binaries
|
||||
|
||||
@@ -8,6 +8,8 @@ echo "Deploying resources to ${DeployLocation}"
|
||||
ln -srf assets/Models ${DeployLocation}
|
||||
ln -srf assets/Textures ${DeployLocation}
|
||||
ln -srf assets/Sounds ${DeployLocation}
|
||||
# Configuration files
|
||||
ln -s assets/DefaultConfig.ini $[DeployLocation}
|
||||
# Shaders
|
||||
ln -srf src/game/Core/Shaders ${DeployLocation}
|
||||
# Platform specific binaries
|
||||
|
||||
Reference in New Issue
Block a user