Merge remote-tracking branch 'origin/master' into LevelSystemAndSuch.

This commit is contained in:
PlatinumSkink
2015-10-19 13:37:10 +02:00
47 changed files with 17173 additions and 905 deletions
+12
View File
@@ -0,0 +1,12 @@
[Debug]
SkipStory=false
LogLevel=1
[Audio]
SFXVolume=0.5
BGMVolume=0.5
[Video]
Fullscreen=false
Width=675
Height=1080
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+12
View File
@@ -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
+14717
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 579 KiB

Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 839 KiB

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

+50
View File
@@ -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
View File
@@ -32,6 +32,7 @@
#include "World.h" #include "World.h"
#include "CTransform.h" #include "CTransform.h"
#include "CTemplate.h" #include "CTemplate.h"
#include "Core/ConfigFile.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Rendering/CModel.h" #include "Rendering/CModel.h"
#include "Rendering/CSprite.h" #include "Rendering/CSprite.h"
@@ -72,6 +73,8 @@
#include "Physics/CParticle.h" #include "Physics/CParticle.h"
#include "Physics/CParticleEmitter.h" #include "Physics/CParticleEmitter.h"
#include "Rendering/AnimationSystem.h"
#include "Game/EGameStart.h" #include "Game/EGameStart.h"
#include "Sound/EPlaySound.h" #include "Sound/EPlaySound.h"
@@ -88,18 +91,34 @@ class Engine
public: public:
Engine(int argc, char* argv[]) { 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_EventBroker = std::make_shared<EventBroker>();
m_Renderer = std::make_shared<Renderer>(); m_Renderer = std::make_shared<Renderer>();
m_Renderer->SetFullscreen(false); m_Renderer->SetFullscreen(config->GetValue<bool>("Video.Fullscreen", false));
//m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080)); m_Renderer->SetResolution(Rectangle(
m_Renderer->SetResolution(Rectangle(0, 0, 675, 1080)); 0,
0,
config->GetValue<int>("Video.Width", 675),
config->GetValue<int>("Video.Height", 1080)
));
m_Renderer->Initialize(); m_Renderer->Initialize();
m_FrameStack = new GUI::Frame(m_EventBroker.get()); m_FrameStack = new GUI::Frame(m_EventBroker.get());
m_FrameStack->Width = 675; m_FrameStack->Width = 675;
m_FrameStack->Height = 1080; 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); m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
@@ -165,6 +184,9 @@ public:
m_World->SystemFactory.Register<Systems::PhysicsSystem>( m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); }); [this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>(); 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>( m_World->SystemFactory.Register<Systems::TravellingSystem>(
[this]() { return new Systems::TravellingSystem(m_World.get(), m_EventBroker); }); [this]() { return new Systems::TravellingSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::TravellingSystem>(); m_World->AddSystem<Systems::TravellingSystem>();
@@ -260,7 +282,8 @@ public:
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position) glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
* glm::toMat4(absoluteTransform.Orientation) * glm::toMat4(absoluteTransform.Orientation)
* glm::scale(absoluteTransform.Scale); * 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 //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) for (auto texGroup : model->TextureGroups)
{ {
@@ -329,8 +352,17 @@ public:
job.ElementBuffer = model->ElementBuffer; job.ElementBuffer = model->ElementBuffer;
job.StartIndex = texGroup.StartIndex; job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex; job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix; job.ModelMatrix = modelMatrix * model->m_Matrix;
job.Color = color; 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); m_RendererQueue.Deferred.Add(job);
} }
+2
View File
@@ -86,6 +86,8 @@ public:
std::vector<unsigned int> m_Indices; std::vector<unsigned int> m_Indices;
Skeleton* m_Skeleton = nullptr; Skeleton* m_Skeleton = nullptr;
glm::mat4 m_Matrix;
private: private:
std::vector<glm::ivec2> BoneIndices; std::vector<glm::ivec2> BoneIndices;
std::vector<glm::vec2> BoneWeights; std::vector<glm::vec2> BoneWeights;
+4
View File
@@ -33,6 +33,10 @@ class PNG : public Image
public: public:
PNG(std::string path); PNG(std::string path);
~PNG(); ~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);
}; };
} }
+6
View File
@@ -66,6 +66,12 @@ struct ModelJob : RenderJob
unsigned int StartIndex; unsigned int StartIndex;
unsigned int EndIndex; unsigned int EndIndex;
// Animation
dd::Skeleton* Skeleton = nullptr;
bool NoRootMotion = true;
std::string AnimationName;
double AnimationTime = 0;
void CalculateHash() override void CalculateHash() override
{ {
Hash = TextureID; Hash = TextureID;
+5 -4
View File
@@ -100,16 +100,17 @@ public:
int GetBoneID(std::string name); int GetBoneID(std::string name);
std::vector<glm::mat4> GetFrameBones(std::string animationName, double time, bool noRootMotion = false); const Animation* GetAnimation(std::string name);
void AccumulateBoneTransforms(bool noRootMotion, Animation::Keyframe &currentFrame, Animation::Keyframe &nextFrame, float progress, std::map<int, glm::mat4> &boneMatrices, Bone* bone, glm::mat4 parentMatrix); 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();
void PrintSkeleton(Bone* parent, int depthCount); void PrintSkeleton(const Bone* parent, int depthCount);
std::map<std::string, Animation> Animations; std::map<std::string, Animation> Animations;
private: private:
std::map<std::string, Bone*> m_BonesByName; std::map<std::string, Bone*> m_BonesByName;
int GetKeyframe(Animation& animation, double time); int GetKeyframe(const Animation& animation, double time);
}; };
} }
+5 -9
View File
@@ -40,23 +40,19 @@
enum _LOG_LEVEL enum _LOG_LEVEL
{ {
LOG_LEVEL_ERROR, LOG_LEVEL_ERROR,
LOG_LEVEL_WARNING,
LOG_LEVEL_INFO, LOG_LEVEL_INFO,
LOG_LEVEL_WARNING,
LOG_LEVEL_DEBUG LOG_LEVEL_DEBUG
}; };
#ifdef DEBUG extern _LOG_LEVEL LOG_LEVEL;
static _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG;
#else
static _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG;
#endif
const static char* _LOG_LEVEL_PREFIX[] = const static char* _LOG_LEVEL_PREFIX[] =
{ {
"E: ", "EE: ",
"W: ",
"", "",
"D: " "WW: ",
"DD: "
}; };
static void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int line, const char* format, ...) static void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int line, const char* format, ...)
+1
View File
@@ -13,6 +13,7 @@
#include "Rendering/CModel.h" #include "Rendering/CModel.h"
#include "Rendering/CSprite.h" #include "Rendering/CSprite.h"
#include "Rendering/CPointLight.h" #include "Rendering/CPointLight.h"
#include "Rendering/CAnimation.h"
#include "Game/CBall.h" #include "Game/CBall.h"
#include "Game/CPowerUp.h" #include "Game/CPowerUp.h"
#include "Game/CLife.h" #include "Game/CLife.h"
+10 -2
View File
@@ -6,6 +6,7 @@
#include "GUI/Slider.h" #include "GUI/Slider.h"
#include "GUI/ESliderUpdate.h" #include "GUI/ESliderUpdate.h"
#include "Sound/EMasterVolume.h" #include "Sound/EMasterVolume.h"
#include "Core/ConfigFile.h"
namespace dd namespace dd
{ {
@@ -33,7 +34,6 @@ public:
m_SFXSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png"); m_SFXSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
m_SFXSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png"); m_SFXSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
m_SFXSlider->AlignVertically(); m_SFXSlider->AlignVertically();
m_SFXSlider->SetPercentage(1.f);
m_TitleBGM = new GUI::TextureFrame(this, "MainMenuOptionsBGMTitle"); m_TitleBGM = new GUI::TextureFrame(this, "MainMenuOptionsBGMTitle");
m_TitleBGM->SetTop(m_SFXSlider->Bottom() + 20); m_TitleBGM->SetTop(m_SFXSlider->Bottom() + 20);
@@ -44,9 +44,12 @@ public:
m_BGMSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png"); m_BGMSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
m_BGMSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png"); m_BGMSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
m_BGMSlider->AlignVertically(); m_BGMSlider->AlignVertically();
m_BGMSlider->SetPercentage(1.f);
EVENT_SUBSCRIBE_MEMBER(m_ESliderUpdate, &MainMenuOptions::OnSliderUpdate); 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: private:
@@ -73,6 +76,11 @@ private:
EventBroker->Publish(e); 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; return true;
} }
}; };
+4 -2
View File
@@ -33,8 +33,10 @@ namespace Components
struct Particle : public Component struct Particle : public Component
{ {
float Radius = 0.5f; EntityID ParticleSystem;
float LifeTime = 5.0f; glm::vec3 Scale = glm::vec3(1.f);
double TimeLived = 0;
double LifeTime = 5;
ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>( ParticleFlags::Type Flags = static_cast<ParticleFlags::Type>(
ParticleFlags::Water ParticleFlags::Water
+5
View File
@@ -21,6 +21,11 @@ struct ParticleEmitter : public Component
float Spread = 0.f; float Spread = 0.f;
float Speed = 2.f; float Speed = 2.f;
double LifeTime = 100; double LifeTime = 100;
float RadiusDistribution = 0;
//values to interpolate between.
std::vector<glm::vec3> ScaleValues;
std::vector<float> AlphaValues;
//System variables //System variables
float GravityScale = 1.0f; float GravityScale = 1.0f;
+5 -1
View File
@@ -22,14 +22,18 @@ 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;
float RadiusDistribution = 0;
glm::vec4 Color = glm::vec4(0); glm::vec4 Color = glm::vec4(0);
EntityID parent = 0; EntityID parent = 0;
// values to interpolate between.
std::vector<glm::vec3> ScaleValues;
std::vector<float> AlphaValues;
//Particle //Particle
std::string SpriteFile = ""; 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;
}; };
} }
+35 -32
View File
@@ -49,7 +49,7 @@ namespace dd
class PhysicsSystem : public System class PhysicsSystem : public System
{ {
friend class ContractListener; friend class ContractListener;
friend class DestructionListener; //friend class DestructionListener;
public: public:
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker) PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
@@ -106,6 +106,9 @@ namespace dd
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale, int maxCount); b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale, int maxCount);
void CreateParticleEmitter(EntityID entity); void CreateParticleEmitter(EntityID entity);
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed. 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; EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &event); bool SetImpulse(const Events::SetImpulse &event);
@@ -128,36 +131,36 @@ namespace dd
std::list<Impulse> m_Impulses; std::list<Impulse> m_Impulses;
class DestructionListener : public b2DestructionListener // class DestructionListener : public b2DestructionListener
{ // {
public: // public:
DestructionListener(PhysicsSystem* physicsSystem) // DestructionListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { } // : m_PhysicsSystem(physicsSystem) { }
//
void SayGoodbye(b2Joint*) {LOG_INFO("joint körs");}; // void SayGoodbye(b2Joint*) {LOG_INFO("joint körs");};
void SayGoodbye(b2Fixture*) {/*LOG_INFO("Fixture körs");*/}; // void SayGoodbye(b2Fixture*) {/*LOG_INFO("Fixture körs");*/};
//
void SayGoodbye(b2ParticleSystem* particleSystem, int32 index) override // void SayGoodbye(b2ParticleSystem* particleSystem, int32 index) override
{ // {
LOG_INFO("Particle ded"); // // LOG_INFO("Particle ded");
// //
// //
const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index); // // const b2ParticleHandle* handle = particleSystem->GetParticleHandleFromIndex(index);
for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) { // // for (int i = 0; i < m_PhysicsSystem->m_ParticleEmitters.ParticleSystem.size(); i++) {
if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) { // // if(m_PhysicsSystem->m_ParticleEmitters.ParticleSystem[i] == particleSystem) {
std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle); // // std::unordered_map<const b2ParticleHandle*, EntityID>::iterator it = m_PhysicsSystem->m_ParticleHandleToEntities[i].find(handle);
if(it != m_PhysicsSystem->m_ParticleHandleToEntities[i].end()) { // // if(it != m_PhysicsSystem->m_ParticleHandleToEntities[i].end()) {
EntityID id = it->second; // // EntityID id = it->second;
m_PhysicsSystem->m_World->RemoveEntity(id); // // m_PhysicsSystem->m_World->RemoveEntity(id);
m_PhysicsSystem->m_ParticleHandleToEntities[i].erase(it); // // m_PhysicsSystem->m_ParticleHandleToEntities[i].erase(it);
LOG_INFO("Removing from list"); // // LOG_INFO("Removing from list");
} // // }
} // // }
} // // }
} // }
private: // private:
PhysicsSystem* m_PhysicsSystem; // PhysicsSystem* m_PhysicsSystem;
}; // };
class ParticleContactDisabler : public b2ContactFilter class ParticleContactDisabler : public b2ContactFilter
{ {
@@ -195,7 +198,7 @@ namespace dd
PhysicsSystem* m_PhysicsSystem; PhysicsSystem* m_PhysicsSystem;
}; };
DestructionListener* m_DestructionListener; //DestructionListener* m_DestructionListener;
ParticleContactDisabler* m_ParticleContactDisabler; ParticleContactDisabler* m_ParticleContactDisabler;
ContactListener* m_ContactListener; ContactListener* m_ContactListener;
}; };
+33
View File
@@ -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
+21
View File
@@ -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
+1
View File
@@ -8,6 +8,7 @@
#include "Core/World.h" #include "Core/World.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Core/ResourceManager.h" #include "Core/ResourceManager.h"
#include "Core/ConfigFile.h"
#include "Sound.h" #include "Sound.h"
#include "Sound/EPlaySound.h" #include "Sound/EPlaySound.h"
#include "Sound/EStopSound.h" #include "Sound/EStopSound.h"
+1
View File
@@ -50,6 +50,7 @@ source_group(Input FILES ${SOURCE_FILES_Input})
file(GLOB SOURCE_FILES_Rendering file(GLOB SOURCE_FILES_Rendering
"${INCLUDE_PATH}/Rendering/*.h" "${INCLUDE_PATH}/Rendering/*.h"
"Rendering/*.cpp"
) )
source_group(Rendering FILES ${SOURCE_FILES_Rendering}) source_group(Rendering FILES ${SOURCE_FILES_Rendering})
+39
View File
@@ -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);
}
+9
View File
@@ -29,6 +29,15 @@ dd::Model::Model(std::string fileName)
LOG_ERROR("Assimp error: %s", importer.GetErrorString()); LOG_ERROR("Assimp error: %s", importer.GetErrorString());
return; 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; auto meshes = scene->mMeshes;
+16 -4
View File
@@ -37,7 +37,7 @@ dd::PNG::PNG(std::string path)
} }
// Initialize libpng // 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) { if (!png_ptr) {
LOG_ERROR("libpng: Failed to initialze png_struct"); LOG_ERROR("libpng: Failed to initialze png_struct");
png_destroy_read_struct(&png_ptr, nullptr, nullptr); png_destroy_read_struct(&png_ptr, nullptr, nullptr);
@@ -97,6 +97,7 @@ dd::PNG::PNG(std::string path)
// Read in the data // Read in the data
png_read_image(png_ptr, row_pointers); png_read_image(png_ptr, row_pointers);
delete[] row_pointers;
this->Width = width; this->Width = width;
this->Height = height; this->Height = height;
@@ -107,7 +108,18 @@ dd::PNG::PNG(std::string path)
dd::PNG::~PNG() dd::PNG::~PNG()
{ {
if (Data) { if (this->Data != nullptr) {
delete[] Data; 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);
}
+14
View File
@@ -431,6 +431,20 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
glBindTexture(GL_TEXTURE_2D, *m_StandardSpecular); 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); glBindVertexArray(modelJob->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex); glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
+1 -1
View File
@@ -65,7 +65,7 @@ void main()
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])]; + 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.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz; Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
+2 -2
View File
@@ -65,8 +65,8 @@ void main()
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])]; + BoneWeights2[3] * Bones[int(BoneIndices2[3])];
} }
//gl_Position = MVP * boneTransform * vec4(Position, 1.0); gl_Position = MVP * boneTransform * vec4(Position, 1.0);
gl_Position = MVP * vec4(Position, 1.0); //gl_Position = MVP * vec4(Position, 1.0);
//TODO: Make sure that boneTransform works here. //TODO: Make sure that boneTransform works here.
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz; Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
+20 -9
View File
@@ -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 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*/)
{ {
auto& animation = Animations.at(animationName);
// HACK: Animation wrap-around // HACK: Animation wrap-around
while (time < 0) while (time < 0)
time += animation.Duration; time += animation.Duration;
@@ -60,8 +68,8 @@ std::vector<glm::mat4> dd::Skeleton::GetFrameBones(std::string animationName, do
int currentKeyframeIndex = GetKeyframe(animation, time); int currentKeyframeIndex = GetKeyframe(animation, time);
Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex]; const Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex];
Animation::Keyframe& nextFrame = animation.Keyframes[currentKeyframeIndex + 1]; const Animation::Keyframe& nextFrame = animation.Keyframes[currentKeyframeIndex + 1];
float alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); float alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
//auto animationFrame = Animations[""].Keyframes[frame]; //auto animationFrame = Animations[""].Keyframes[frame];
@@ -75,7 +83,7 @@ std::vector<glm::mat4> dd::Skeleton::GetFrameBones(std::string animationName, do
return finalMatrices; return finalMatrices;
} }
void dd::Skeleton::AccumulateBoneTransforms(bool noRootMotion, Animation::Keyframe &currentFrame, 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 &currentFrame, const Animation::Keyframe &nextFrame, float progress, std::map<int, glm::mat4> &boneMatrices, const Bone* bone, glm::mat4 parentMatrix)
{ {
glm::mat4 boneMatrix; glm::mat4 boneMatrix;
@@ -117,10 +125,13 @@ int dd::Skeleton::GetBoneID(std::string name)
void dd::Skeleton::PrintSkeleton() void dd::Skeleton::PrintSkeleton()
{ {
if (LOG_LEVEL < LOG_LEVEL_DEBUG) {
return;
}
PrintSkeleton(RootBone, 0); PrintSkeleton(RootBone, 0);
} }
void dd::Skeleton::PrintSkeleton(Bone* bone, int depthCount) void dd::Skeleton::PrintSkeleton(const Bone* bone, int depthCount)
{ {
std::stringstream ss; std::stringstream ss;
ss << std::string(depthCount, ' '); 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) if (time < 0)
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) { for (int keyframe = 0; keyframe < animation.Keyframes.size(); ++keyframe) {
if (animation.Keyframes[keyframe].Time > time) 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; return 0;
+8 -8
View File
@@ -21,21 +21,21 @@
dd::Texture::Texture(std::string path) 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) { if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) {
image = std::make_unique<PNG>("Textures/Core/ErrorTexture.png"); image = 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) {
LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed."); LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
return; return;
} }
} }
this->Width = image->Width; this->Width = image.Width;
this->Height = image->Height; this->Height = image.Height;
GLint format; GLint format;
switch (image->Format) { switch (image.Format) {
case Image::ImageFormat::RGB: case Image::ImageFormat::RGB:
format = GL_RGB; format = GL_RGB;
break; break;
@@ -48,7 +48,7 @@ dd::Texture::Texture(std::string path)
glGenTextures(1, &m_Texture); glGenTextures(1, &m_Texture);
glBindTexture(GL_TEXTURE_2D, m_Texture); glBindTexture(GL_TEXTURE_2D, m_Texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 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_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+7
View File
@@ -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
+8 -6
View File
@@ -154,12 +154,14 @@ void dd::World::Initialize()
{ {
RegisterSystems(); RegisterSystems();
AddSystems(); AddSystems();
for (auto pair : m_Systems) for (auto pair : m_Systems) {
{ pair.second->RegisterComponents(&ComponentFactory);
auto system = pair.second; }
system->RegisterComponents(&ComponentFactory); for (auto pair : m_Systems) {
system->RegisterResourceTypes(ResourceManager); pair.second->RegisterResourceTypes(ResourceManager);
system->Initialize(); }
for (auto pair : m_Systems) {
pair.second->Initialize();
} }
} }
+6 -4
View File
@@ -35,7 +35,9 @@ void dd::Systems::BallSystem::Initialize()
transform->Scale = glm::vec3(0.3f, 0.3f, 0.3f); transform->Scale = glm::vec3(0.3f, 0.3f, 0.3f);
transform->Velocity = glm::vec3(0.f, 0.f, 0.f); transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
auto model = m_World->AddComponent<Components::Model>(ent); 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); std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
circleShape->Radius = 0.4f; circleShape->Radius = 0.4f;
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent); 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) { } else if (ballTransform->Position.x <= -2.7f) {
particleEvent.Position = glm::vec3(-2.7f, -3.f, -3.f); 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.Color = glm::vec4(1.f);
particleEvent.Speed = 0; particleEvent.Speed = 0;
@@ -322,7 +324,7 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
EventBroker->Publish(particleEvent); EventBroker->Publish(particleEvent);
} }
ballComponent->Combo = 56; ballComponent->Combo = 0;
if (!ballComponent->Waiting) { if (!ballComponent->Waiting) {
if (m_InkBlaster) { if (m_InkBlaster) {
if (!m_InkAttached) { if (!m_InkAttached) {
@@ -421,7 +423,7 @@ void dd::Systems::BallSystem::CreateLife(int number)
lifeNr->Number = number; lifeNr->Number = number;
auto model = m_World->AddComponent<Components::Model>(life); 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); m_World->CommitEntity(life);
+40
View File
@@ -612,6 +612,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
brick->Removed = true; brick->Removed = true;
m_World->RemoveEntity(entityShot); m_World->RemoveEntity(entityShot);
BrickHit(entityShot, entityBrick, 1); BrickHit(entityShot, entityBrick, 1);
//ep.Radius = 0.05;
return true; return true;
} }
@@ -719,6 +720,45 @@ void dd::Systems::LevelSystem::BrickHit(EntityID entityHitter, EntityID entityBr
m_World->RemoveComponent<Components::Template>(b); m_World->RemoveComponent<Components::Template>(b);
m_World->SetEntityParent(b, 0); m_World->SetEntityParent(b, 0);
m_World->CommitEntity(b); 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);
} }
File diff suppressed because it is too large Load Diff
+35
View File
@@ -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;
}
+3
View File
@@ -27,6 +27,9 @@ void dd::Systems::SoundSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound); EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume); 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 //Todo: Move this
{ {
dd::Events::PlaySound e; dd::Events::PlaySound e;
+3 -1
View File
@@ -1,4 +1,4 @@
@ECHO on @ECHO off
SET DeployLocation=bin\ SET DeployLocation=bin\
@@ -7,6 +7,8 @@ ECHO Deploying resources to %DeployLocation%
MKLINK "%DeployLocation%\Models\" "assets\Models" /J MKLINK "%DeployLocation%\Models\" "assets\Models" /J
MKLINK "%DeployLocation%\Textures\" "assets\Textures\" /J MKLINK "%DeployLocation%\Textures\" "assets\Textures\" /J
MKLINK "%DeployLocation%\Sounds\" "assets\Sounds\" /J MKLINK "%DeployLocation%\Sounds\" "assets\Sounds\" /J
:: Configuration files
MKLINK "%DeployLocation%\DefaultConfig.ini" "assets\DefaultConfig.ini" /H
:: Shaders :: Shaders
MKLINK "%DeployLocation%\Shaders\" "src\game\Core\Shaders\" /J MKLINK "%DeployLocation%\Shaders\" "src\game\Core\Shaders\" /J
:: Platform specific binaries :: Platform specific binaries
+2
View File
@@ -8,6 +8,8 @@ echo "Deploying resources to ${DeployLocation}"
ln -srf assets/Models ${DeployLocation} ln -srf assets/Models ${DeployLocation}
ln -srf assets/Textures ${DeployLocation} ln -srf assets/Textures ${DeployLocation}
ln -srf assets/Sounds ${DeployLocation} ln -srf assets/Sounds ${DeployLocation}
# Configuration files
ln -s assets/DefaultConfig.ini $[DeployLocation}
# Shaders # Shaders
ln -srf src/game/Core/Shaders ${DeployLocation} ln -srf src/game/Core/Shaders ${DeployLocation}
# Platform specific binaries # Platform specific binaries