Merge remote-tracking branch 'origin/master' into water
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -29,6 +29,15 @@ dd::Model::Model(std::string fileName)
|
||||
LOG_ERROR("Assimp error: %s", importer.GetErrorString());
|
||||
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;
|
||||
|
||||
|
||||
+16
-4
@@ -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 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
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ void dd::Systems::BallSystem::Initialize()
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &BallSystem::OnStageCleared);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EArrivedAtNewStage, &BallSystem::OnArrivedToNewStage);
|
||||
|
||||
|
||||
//OctoBall
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
@@ -34,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);
|
||||
@@ -287,6 +290,40 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier();
|
||||
float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f;
|
||||
|
||||
//When a combo is more than 2 create a particle showing it.
|
||||
if (ballComponent->Combo >= 2){
|
||||
|
||||
Events::CreateParticleSequence particleEvent;
|
||||
|
||||
particleEvent.EmitterLifeTime = 3;
|
||||
particleEvent.EmittingAngle = glm::half_pi<float>();
|
||||
particleEvent.Spread = 0.f;
|
||||
particleEvent.NumberOfTicks = 1;
|
||||
particleEvent.ParticleLifeTime = 2.f;
|
||||
particleEvent.ParticlesPerTick = 1;
|
||||
particleEvent.Position = glm::vec3(ballTransform->Position.x, -3.f, -3.f);
|
||||
if (ballTransform->Position.x >= 2.7f) {
|
||||
particleEvent.Position = glm::vec3(2.7f, -3.f, -3.f);
|
||||
} else if (ballTransform->Position.x <= -2.7f) {
|
||||
particleEvent.Position = glm::vec3(-2.7f, -3.f, -3.f);
|
||||
}
|
||||
particleEvent.ScaleValues.push_back(glm::vec3(1.f));
|
||||
particleEvent.Color = glm::vec4(1.f);
|
||||
particleEvent.Speed = 0;
|
||||
|
||||
if (ballComponent->Combo <= 9) {
|
||||
particleEvent.SpriteFile = "Textures/Combo/Combo00" + std::to_string(ballComponent->Combo) + ".png";
|
||||
} else if (ballComponent->Combo <= 42) {
|
||||
particleEvent.SpriteFile = "Textures/Combo/Combo0" + std::to_string(ballComponent->Combo) + ".png";
|
||||
} else {
|
||||
particleEvent.SpriteFile = "Textures/Combo/Combo043.png";
|
||||
}
|
||||
EventBroker->Publish(particleEvent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ballComponent->Combo = 0;
|
||||
if (!ballComponent->Waiting) {
|
||||
if (m_InkBlaster) {
|
||||
@@ -386,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;
|
||||
|
||||
Reference in New Issue
Block a user