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
+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 "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);
}
+2
View File
@@ -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;
+4
View File
@@ -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);
};
}
+6
View File
@@ -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;
+5 -4
View File
@@ -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 &currentFrame, 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);
};
}
+5 -9
View File
@@ -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, ...)