Merge branch 'master' of github.com:teamfisk/AgileBreakOut into Tobias
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
[Debug]
|
||||
SkipStory=0
|
||||
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
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
@@ -2,12 +2,12 @@
|
||||
#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
|
||||
{
|
||||
|
||||
@@ -19,16 +19,32 @@ private:
|
||||
ConfigFile(std::string path);
|
||||
|
||||
public:
|
||||
template <typename T, T defaultValue>
|
||||
T GetValue(std::string key)
|
||||
{
|
||||
return m_ptree.get<T>(key, defaultValue);
|
||||
}
|
||||
template <typename T>
|
||||
T GetValue(std::string key, T defaultValue);
|
||||
template <typename T>
|
||||
void SetValue(std::string key, T value);
|
||||
|
||||
void SaveToDisk();
|
||||
|
||||
private:
|
||||
boost::property_tree::ptree m_ptree;
|
||||
|
||||
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__
|
||||
|
||||
+31
-8
@@ -68,6 +68,8 @@
|
||||
#include "Physics/CParticle.h"
|
||||
#include "Physics/CParticleEmitter.h"
|
||||
|
||||
#include "Rendering/AnimationSystem.h"
|
||||
|
||||
#include "Game/EGameStart.h"
|
||||
#include "Sound/EPlaySound.h"
|
||||
|
||||
@@ -84,19 +86,27 @@ 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;
|
||||
|
||||
if (ResourceManager::Load<ConfigFile>("Config.ini")->GetValue<int, 0>("Debug.SkipStory") == 1) {
|
||||
if (config->GetValue<bool>("Debug.SkipStory", false)) {
|
||||
Events::GameStart e;
|
||||
m_EventBroker->Publish(e);
|
||||
auto hud = new GUI::HUD(m_FrameStack, "HUD");
|
||||
@@ -165,6 +175,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>();
|
||||
@@ -457,7 +470,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,7 +527,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)
|
||||
{
|
||||
@@ -526,8 +540,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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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})
|
||||
|
||||
|
||||
@@ -3,5 +3,37 @@
|
||||
|
||||
dd::ConfigFile::ConfigFile(std::string path)
|
||||
{
|
||||
boost::property_tree::ini_parser::read_ini(path, m_ptree);
|
||||
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);
|
||||
@@ -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);
|
||||
|
||||
@@ -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