Merge remote-tracking branch 'origin/master' into LevelSystemAndSuch.
This commit is contained in:
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"
|
||||
|
||||
Reference in New Issue
Block a user