From f10749d220fb08939e08f24b19134f62e366d8f7 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Mon, 28 Sep 2015 17:59:57 +0200 Subject: [PATCH 1/9] Refactoring SoundSystem and its events, components --- include/Sound/CCollisionSound.h | 8 +-- include/Sound/EMasterVolume.h | 10 +--- include/Sound/EPlaySound.h | 14 ++--- include/Sound/EStopSound.h | 6 +- include/Sound/Sound.h | 9 +-- include/Sound/SoundSystem.h | 41 +++++++------- src/game/Core/OBJ.cpp | 6 +- src/game/Game/LevelSystem.cpp | 2 +- src/game/Sound/SoundSystem.cpp | 97 +++++++++++++-------------------- 9 files changed, 77 insertions(+), 116 deletions(-) diff --git a/include/Sound/CCollisionSound.h b/include/Sound/CCollisionSound.h index 4a631a3..3bf312a 100644 --- a/include/Sound/CCollisionSound.h +++ b/include/Sound/CCollisionSound.h @@ -1,7 +1,3 @@ -// -// Created by Adam on 2015-09-17. -// - #ifndef COMPONENTS_CCOLLISIONSOUND_H__ #define COMPONENTS_CCOLLISIONSOUND_H__ @@ -9,17 +5,15 @@ namespace dd { - namespace Components { struct CollisionSound : public Component { - std::string filePath; + std::string FilePath; }; } - } #endif diff --git a/include/Sound/EMasterVolume.h b/include/Sound/EMasterVolume.h index 3f95e6d..6c7999b 100644 --- a/include/Sound/EMasterVolume.h +++ b/include/Sound/EMasterVolume.h @@ -1,7 +1,3 @@ -// -// Created by Adam on 2015-09-24. -// - #ifndef EVENTS_EMASTERVOLUME_H__ #define EVENTS_EMASTERVOLUME_H__ @@ -9,19 +5,17 @@ namespace dd { - namespace Events { struct MasterVolume : public Event { - float gain = 1; + float Gain = 1; //To determine what channel group to apply the change to. - bool isAmbient = false; + bool IsAmbient = false; }; } - } #endif diff --git a/include/Sound/EPlaySound.h b/include/Sound/EPlaySound.h index a66300d..ed7ab76 100644 --- a/include/Sound/EPlaySound.h +++ b/include/Sound/EPlaySound.h @@ -1,24 +1,22 @@ -#ifndef Events_PlaySFX_h__ -#define Events_PlaySFX_h__ +#ifndef EVENTS_PLAYSFX_H__ +#define EVENTS_PLAYSFX_H__ #include "Core/EventBroker.h" namespace dd { - namespace Events { struct PlaySound : Event { - std::string path; - float volume = 1.f; - float pitch = 1.f; - bool isAmbient = false; + std::string FilePath; + float Gain = 1.f; + float Pitch = 1.f; + bool IsAmbient = false; }; } - } #endif \ No newline at end of file diff --git a/include/Sound/EStopSound.h b/include/Sound/EStopSound.h index 81ff474..8f7bbd8 100644 --- a/include/Sound/EStopSound.h +++ b/include/Sound/EStopSound.h @@ -8,16 +8,12 @@ namespace dd namespace Events { - struct StopSound : public Event { - std::string path; + std::string FilePath; }; - } - - } #endif diff --git a/include/Sound/Sound.h b/include/Sound/Sound.h index 7084e64..0992948 100644 --- a/include/Sound/Sound.h +++ b/include/Sound/Sound.h @@ -12,12 +12,17 @@ namespace dd class Sound : public Resource { friend class ResourceManager; + public: ALuint Buffer() { return m_Buffer; }; std::string Path() { return m_Path; }; + private: Sound(std::string path); + ALuint m_Buffer; + std::string m_Path; + //File-info char m_Type[4]; unsigned long m_Size, m_ChunkSize; @@ -27,12 +32,8 @@ private: unsigned long m_DataSize; std::map m_BufferCache; ALuint LoadFile(std::string path); - - ALuint m_Buffer; - std::string m_Path; }; - } #endif diff --git a/include/Sound/SoundSystem.h b/include/Sound/SoundSystem.h index 32dd05e..89713f5 100644 --- a/include/Sound/SoundSystem.h +++ b/include/Sound/SoundSystem.h @@ -1,61 +1,60 @@ -#ifndef DAYDREAM_SOUND_H -#define DAYDREAM_SOUND_H - +#ifndef SYSTEMS_SOUNDSYSTEM_H__ +#define SYSTEMS_SOUNDSYSTEM_H__ #include "AL/al.h" #include "AL/alc.h" + #include "Core/System.h" #include "Core/World.h" #include "Core/EventBroker.h" +#include "Core/ResourceManager.h" #include "Sound.h" #include "Sound/EPlaySound.h" #include "Sound/EStopSound.h" #include "Sound/EMasterVolume.h" +#include "Sound/CCollisionSound.h" #include "Physics/EContact.h" #include "Game/CBall.h" #include "Game/CBrick.h" #include "Game/CPad.h" -#include "Sound/CCollisionSound.h" -#include "Core/ResourceManager.h" - namespace dd { namespace Systems { + class SoundSystem : public System { public: SoundSystem(World *world, std::shared_ptr eventBroker) : System(world, eventBroker) { } + ~SoundSystem(); + void Initialize() override; void Update(double dt) override; - - - private: + float m_BGMMasterVolume = 1.f; + float m_SFXMasterVolume = 1.f; + std::map m_BGMSourcesToBuffers; + std::map m_SFXSourcesToBuffers; + ALCdevice* m_Device = nullptr; + //Events dd::EventRelay m_EPlaySFX; - dd::EventRelay m_EContact; - dd::EventRelay m_EStopSound; - dd::EventRelay m_EMasterVolume; bool OnPlaySound(const dd::Events::PlaySound &event); + //On contact: play the sound given in the CCOllisionSound. + dd::EventRelay m_EContact; bool OnContact(const dd::Events::Contact &event); + dd::EventRelay m_EStopSound; bool OnStopSound(const dd::Events::StopSound &event); + dd::EventRelay m_EMasterVolume; bool OnMasterVolume(const dd::Events::MasterVolume &event); ALuint CreateSource(); - - std::map m_BGMSourcesToBuffers; - std::map m_SFXSourcesToBuffers; - - ALCdevice* m_Device; - - float m_BGMMasterVolume, m_SFXMasterVolume; - }; + } } -#endif //DAYDREAM_SOUND_H +#endif diff --git a/src/game/Core/OBJ.cpp b/src/game/Core/OBJ.cpp index fe6a818..0dd75a5 100644 --- a/src/game/Core/OBJ.cpp +++ b/src/game/Core/OBJ.cpp @@ -263,7 +263,7 @@ void dd::OBJ::ParseMaterial() ParseColorMap(currentLine, ss, prefix, arg, colorMap); } - // HACK: Should we really have to specify the full path here? + // HACK: Should we really have to specify the full FilePath here? colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string(); currentMaterial->DiffuseTexture = colorMap; continue; @@ -280,7 +280,7 @@ void dd::OBJ::ParseMaterial() ParseColorMap(currentLine, ss, prefix, arg, colorMap); } - // HACK: Should we really have to specify the full path here? + // HACK: Should we really have to specify the full FilePath here? colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string(); currentMaterial->SpecularMap = colorMap; continue; @@ -297,7 +297,7 @@ void dd::OBJ::ParseMaterial() ParseBumpMap(currentLine, ss, prefix, arg, bumpMap); } - // HACK: Should we really have to specify the full path here? + // HACK: Should we really have to specify the full FilePath here? bumpMap.FileName = (m_MaterialPath.branch_path() / bumpMap.FileName).string(); currentMaterial->NormalMap = bumpMap; continue; diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index 0389cca..86451b3 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -191,7 +191,7 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe //sound auto collisionSound = m_World->AddComponent(brick); - collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav"; + collisionSound->FilePath = "Sounds/Brick/shortbrickbreak.wav"; m_World->CommitEntity(brick); return; diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index 8594d92..8fb89fd 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -4,7 +4,7 @@ dd::Systems::SoundSystem::~SoundSystem() { alcCloseDevice(m_Device); -} +}; void dd::Systems::SoundSystem::Initialize() { @@ -19,41 +19,26 @@ void dd::Systems::SoundSystem::Initialize() else { LOG_ERROR("OpenAL failed to initialize."); } - alGetError(); - //Probably unnecessary. vec3(0) probably default. - const ALfloat pos[3] = {0, 0, 0}; - //alListenerfv(AL_POSITION, pos); - - m_SFXMasterVolume = 1.f; - m_BGMMasterVolume = 1.f; - //Subscribe to events EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact); EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound); EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound); EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume); - //Todo: Move this { dd::Events::PlaySound e; - e.path = "Sounds/BGM/under-the-sea-instrumental.wav"; - e.isAmbient = true; + e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav"; + e.IsAmbient = true; EventBroker->Publish(e); } { dd::Events::PlaySound e; - e.path = "Sounds/BGM/water-flowing.wav"; - e.volume = 0.3f; - e.isAmbient = true; - EventBroker->Publish(e); - } - { - dd::Events::MasterVolume e; - e.isAmbient = true; - e.gain = 1.f; + e.FilePath = "Sounds/BGM/water-flowing.wav"; + e.Gain = 0.3f; + e.IsAmbient = true; EventBroker->Publish(e); } } @@ -63,7 +48,7 @@ void dd::Systems::SoundSystem::Update(double dt) //Clean up none-active sources //Only used for SFX's. BGM's are handled on stop sound. std::vector deleteList; - for (auto item : m_SFXSourcesToBuffers) { + for (auto& item : m_SFXSourcesToBuffers) { ALint sourceState; alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState); if (sourceState == AL_STOPPED) { @@ -89,7 +74,7 @@ ALuint dd::Systems::SoundSystem::CreateSource() bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) { //Loading and binding sound buffer to source - Sound *sound = ResourceManager::Load(event.path); + Sound *sound = ResourceManager::Load(event.FilePath); if (sound == nullptr) { return false; } @@ -99,21 +84,21 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) //Sound settings float relativeVolume = 1.f; - if (event.isAmbient) { + if (event.IsAmbient) { alSourcei(source, AL_LOOPING, AL_TRUE); relativeVolume = m_BGMMasterVolume; m_BGMSourcesToBuffers[source] = sound; } - else if (!event.isAmbient) + else if (!event.IsAmbient) { m_SFXSourcesToBuffers[source] = sound; alSourcei(source, AL_LOOPING, AL_FALSE); relativeVolume = m_SFXMasterVolume; } - alSourcef(source, AL_GAIN, (event.volume * relativeVolume)); - alSourcef(source, AL_PITCH, event.pitch); + alSourcef(source, AL_GAIN, (event.Gain * relativeVolume)); + alSourcef(source, AL_PITCH, event.Pitch); //Play @@ -123,53 +108,52 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event) { - - //TODO: Delete sources for bgms - ALuint itemToDelete; - for (auto item : m_BGMSourcesToBuffers) + ALuint itemToDeleted; + for (auto& item : m_BGMSourcesToBuffers) { - if (item.second->Path() == event.path) { - itemToDelete = item.first; + if (item.second->Path() == event.FilePath) { + itemToDeleted = item.first; break; } } - alSourceStop(itemToDelete); - alDeleteSources(1, &itemToDelete); - m_BGMSourcesToBuffers.erase(itemToDelete); + alSourceStop(itemToDeleted); + alDeleteSources(1, &itemToDeleted); + m_BGMSourcesToBuffers.erase(itemToDeleted); - //Should not because SFX's should be very short. + //Should not happen because SFX's should be very short. for (auto item : m_SFXSourcesToBuffers) { - if (item.second->Path() == event.path) { + if (item.second->Path() == event.FilePath) { alSourceStop(item.first); return true; } } - return false; } bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event) { - //TODO: Make the volume depend on the value given when stored. - //TODO: .. now it ONLY uses the master volume - if (event.isAmbient) { - m_BGMMasterVolume = event.gain; - for (auto item : m_BGMSourcesToBuffers) + //TODO: Make the Gain depend on the value given when stored. + //TODO: .. now it ONLY uses the master Gain + if (event.IsAmbient) { + m_BGMMasterVolume = event.Gain; + for (auto& item : m_BGMSourcesToBuffers) { - alSourcef(item.first, AL_GAIN, event.gain); + alSourcef(item.first, AL_GAIN, event.Gain); } + return true; } - else if (!event.isAmbient) { - m_SFXMasterVolume = event.gain; - for (auto item : m_SFXSourcesToBuffers) + else if (!event.IsAmbient) { + m_SFXMasterVolume = event.Gain; + for (auto& item : m_SFXSourcesToBuffers) { - alSourcef(item.first, AL_GAIN, event.gain); + alSourcef(item.first, AL_GAIN, event.Gain); } + return true; } + return false; } -//On contact: play the sound given in the CCOllisionSound. bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event) { //Check which entity has the collisionSound component. @@ -182,18 +166,13 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event) } } - { - dd::Events::StopSound e; - e.path = "Sounds/BGM/water-flowing.wav"; - EventBroker->Publish(e); - } - //Send play-sound event dd::Events::PlaySound e; - e.path = collisionSound->filePath; - e.isAmbient = false; + e.FilePath = collisionSound->FilePath; + e.IsAmbient = false; EventBroker->Publish(e); - //return true; + return true; } + From edd87ddf58c471cd8f44bb9ab53f655597ea1030 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 28 Sep 2015 20:40:28 +0200 Subject: [PATCH 2/9] Fixed critical warnings for Linux build --- include/Game/LevelSystem.h | 1 - src/game/Game/BallSystem.cpp | 2 +- src/game/Game/LevelSystem.cpp | 14 +++++++------- src/game/Physics/PhysicsSystem.cpp | 6 +++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h index 545d2fb..9e73a6b 100755 --- a/include/Game/LevelSystem.h +++ b/include/Game/LevelSystem.h @@ -33,7 +33,6 @@ #include "Game/PadSystem.h" #include #include -#include namespace dd { diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 37df50a..6f1b510 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -13,7 +13,7 @@ void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf) void dd::Systems::BallSystem::Initialize() { - EVENT_SUBSCRIBE_MEMBER(m_Contact, BallSystem::Contact); + EVENT_SUBSCRIBE_MEMBER(m_Contact, &BallSystem::Contact); } void dd::Systems::BallSystem::Update(double dt) diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index 4130a78..6c50c72 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -9,13 +9,13 @@ void dd::Systems::LevelSystem::Initialize() { - EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact); - EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::OnLifeLost); - EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::OnScoreEvent); - EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, LevelSystem::OnMultiBall); - EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, LevelSystem::OnCreatePowerUp); - EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, LevelSystem::OnPowerUpTaken); - EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, LevelSystem::OnStageCleared); + EVENT_SUBSCRIBE_MEMBER(m_EContact, &LevelSystem::OnContact); + EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &LevelSystem::OnLifeLost); + EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, &LevelSystem::OnScoreEvent); + EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &LevelSystem::OnMultiBall); + EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, &LevelSystem::OnCreatePowerUp); + EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, &LevelSystem::OnPowerUpTaken); + EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &LevelSystem::OnStageCleared); for (int i = 0; i < Lives(); i++) { CreateLife(i); diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index 7d23110..ecc2495 100644 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -24,7 +24,7 @@ void dd::Systems::PhysicsSystem::Initialize() InitializeWater(); - EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, PhysicsSystem::SetImpulse); + EVENT_SUBSCRIBE_MEMBER(m_SetImpulse, &PhysicsSystem::SetImpulse); } void dd::Systems::PhysicsSystem::InitializeWater() @@ -268,7 +268,7 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity) if(physicsComponent->Static) { - body->CreateFixture(&fixtureDef); //Density kanske ska vara 0 på statiska kroppar + body->CreateFixture(&fixtureDef); //Density kanske ska vara 0 p� statiska kroppar } else { fixtureDef.shape = pShape; @@ -289,7 +289,7 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity) void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e) { - //TODO: Lägg alla pd i en lista + //TODO: L�gg alla pd i en lista auto transform = m_World->GetComponent(e); if (!transform) { LOG_ERROR("No Transform component in CreateParticleGroup"); From d472e2ae88c876fa9dd0a86b36d5767c7d50a028 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 28 Sep 2015 21:56:11 +0200 Subject: [PATCH 3/9] Added ignore rule for .orig files, since nobody seem to be able to look at what they commit... --- .gitignore | 3 +- include/Core/Engine.h.orig | 562 ------------------------------------- 2 files changed, 2 insertions(+), 563 deletions(-) delete mode 100644 include/Core/Engine.h.orig diff --git a/.gitignore b/.gitignore index 4dd52f7..db4d37d 100755 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /bin/ /lib/ # CLion -.idea/ \ No newline at end of file +.idea/ +.orig \ No newline at end of file diff --git a/include/Core/Engine.h.orig b/include/Core/Engine.h.orig deleted file mode 100644 index f19102e..0000000 --- a/include/Core/Engine.h.orig +++ /dev/null @@ -1,562 +0,0 @@ -/* - This file is part of Daydream Engine. - Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung - - Daydream Engine is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Daydream Engine is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with Daydream Engine. If not, see . -*/ - -#include -#include -#include - -#include "ResourceManager.h" -#include "OBJ.h" -#include "Model.h" -#include "Texture.h" -#include "EventBroker.h" -#include "RenderQueue.h" -#include "Renderer.h" -#include "InputManager.h" -//TODO: Remove includes that are only here for the temporary draw solution. -#include "World.h" -#include "CTransform.h" -#include "Core/EventBroker.h" -#include "Rendering/CModel.h" -#include "Rendering/CSprite.h" -#include "CTemplate.h" -#include "Rendering/CPointLight.h" -#include "Transform/TransformSystem.h" -#include "Sound/SoundSystem.h" -#include "Sound/CCollisionSound.h" -#include "Game/LevelSystem.h" -#include "Game/PadSystem.h" -#include "Game/CBall.h" -#include "Game/CPad.h" -#include "Game/CBrick.h" -#include "Game/BallSystem.h" -#include "Game/Bricks/CPowerUpBrick.h" - -#include "Physics/PhysicsSystem.h" -#include "Physics/CPhysics.h" -#include "Physics/CRectangleShape.h" -#include "Physics/ESetImpulse.h" -#include "Physics/CWaterVolume.h" - -#include "Game/EGameStart.h" -#include "Sound/EPlaySound.h" - -#include "GUI/Frame.h" -#include "GUI/Button.h" -#include "Game/MainMenu.h" -#include "Game/HUD.h" - -namespace dd -{ - -class Engine -{ - -public: - Engine(int argc, char* argv[]) { - m_EventBroker = std::make_shared(); - - m_Renderer = std::make_shared(); - m_Renderer->SetFullscreen(false); - //m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080)); - m_Renderer->SetResolution(Rectangle(0, 0, 675, 1080)); - m_Renderer->Initialize(); - - m_FrameStack = new GUI::Frame(m_EventBroker.get()); - m_FrameStack->Width = 675; - m_FrameStack->Height = 1080; - auto hud = new GUI::HUD(m_FrameStack, "HUD"); - auto menu = new GUI::MainMenu(m_FrameStack, "MainMenu"); - - m_InputManager = std::make_shared(m_Renderer->Window(), m_EventBroker); - - m_World = std::make_shared(m_EventBroker); - - //TODO: Move this out of engine.h - m_World->ComponentFactory.Register(); - m_World->SystemFactory.Register( - [this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); }); - m_World->AddSystem(); - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - - m_World->ComponentFactory.Register(); - m_World->SystemFactory.Register( - [this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); }); - m_World->AddSystem(); - - m_World->ComponentFactory.Register(); - - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - - m_World->SystemFactory.Register( - [this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); }); - m_World->AddSystem(); - - m_World->SystemFactory.Register( - [this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); }); - m_World->AddSystem(); - m_World->SystemFactory.Register( - [this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); }); - m_World->AddSystem(); - m_World->SystemFactory.Register( - [this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); }); - m_World->AddSystem(); - - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - m_World->ComponentFactory.Register(); - m_World->Initialize(); - - - //OctoBall - { - auto ent = m_World->CreateEntity(); - std::shared_ptr transform = m_World->AddComponent(ent); - transform->Position = glm::vec3(-0.f, 0.26f, -9.f); - transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f); - transform->Velocity = glm::vec3(0.0f, -10.f, 0.f); - auto model = m_World->AddComponent(ent); - model->ModelFile = "Models/Test/Ball/Ballopus.obj"; - std::shared_ptr circleShape = m_World->AddComponent(ent); - std::shared_ptr ball = m_World->AddComponent(ent); - ball->Speed = 5.f; -<<<<<<< HEAD - std::shared_ptr physics = m_World->AddComponent(ent); - physics->Static = false; - physics->Category = CollisionLayer::Type::Ball; - physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall; - physics->Calculate = true; -======= - std::shared_ptr physics = m_World->AddComponent(ent); - physics->Static = false; ->>>>>>> origin/master - - auto plight = m_World->AddComponent(ent); - plight->Radius = 2.f; - - m_World->CommitEntity(ent); - } - - //PointLightTest - { - auto t_Light = m_World->CreateEntity(); - auto transform = m_World->AddComponent(t_Light); - transform->Position = glm::vec3(2.f, 1.5f, -9.f); - auto pl = m_World->AddComponent(t_Light); - pl->Radius = 8.f; - m_World->CommitEntity(t_Light); - } - - //Halfpipe background test model. - { - auto t_halfPipe = m_World->CreateEntity(); - auto transform = m_World->AddComponent(t_halfPipe); - transform->Position = glm::vec3(0.f, 0.f, -15.f); - transform->Scale = glm::vec3(15.f); - auto model = m_World->AddComponent(t_halfPipe); - model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj"; - model->Color = glm::vec4(1.f, 1.f, 1.f, 0.3f); - m_World->CommitEntity(t_halfPipe); - } - - //Background - { - auto background = m_World->CreateEntity(); - auto transform = m_World->AddComponent(background); - transform->Position = glm::vec3(0.f, 0.f, -30.f); - transform->Scale = glm::vec3(2681.f / 50.f, 1080.f / 50.f, 1.f); - auto sprite = m_World->AddComponent(background); - sprite->SpriteFile = "Textures/Background.png"; - m_World->CommitEntity(background); - } - - //Water test - { - auto t_waterBody = m_World->CreateEntity(); - auto transform = m_World->AddComponent(t_waterBody); - transform->Position = glm::vec3(0.f, -4.5f, -10.f); - transform->Scale = glm::vec3(7.f, 1.5f, 1.f); - auto water = m_World->AddComponent(t_waterBody); - auto body = m_World->AddComponent(t_waterBody); - m_World->CommitEntity(t_waterBody); - } - //TODO: Why does the ball not collide with these bricks? - //BottomBox - { - auto topWall = m_World->CreateEntity(); - auto transform = m_World->AddComponent(topWall); - transform->Position = glm::vec3(0.f, -6.f, -9.9f); - transform->Scale = glm::vec3(10.f, 0.5f, 1.f); - std::shared_ptr sprite = m_World->AddComponent(topWall); - sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; - std::shared_ptr boxShape = m_World->AddComponent( - topWall); - std::shared_ptr physics = m_World->AddComponent(topWall); - physics->Static = true; - m_World->CommitEntity(topWall); - } - //SideBox -// { -// auto topWall = m_World->CreateEntity(); -// std::shared_ptr transform = m_World->AddComponent(topWall); -// transform->Position = glm::vec3(3.f, -3.0f, -9.9f); -// transform->Scale = glm::vec3(0.5f, 3.f, 1.f); -// std::shared_ptr sprite = m_World->AddComponent(topWall); -// sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; -// std::shared_ptr boxShape = m_World->AddComponent( -// topWall); -// std::shared_ptr physics = m_World->AddComponent(topWall); -// physics->Static = true; -// m_World->CommitEntity(topWall); -// } -// //OtherSideBox -// { -// auto topWall = m_World->CreateEntity(); -// std::shared_ptr transform = m_World->AddComponent(topWall); -// transform->Position = glm::vec3(-4.f, -3.0f, -9.9f); -// transform->Scale = glm::vec3(0.5f, 3.0f, 1.f); -// std::shared_ptr sprite = m_World->AddComponent(topWall); -// sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; -// std::shared_ptr boxShape = m_World->AddComponent( -// topWall); -// std::shared_ptr physics = m_World->AddComponent(topWall); -// physics->Static = true; -// m_World->CommitEntity(topWall); -// } - - { - auto topWall = m_World->CreateEntity(); - std::shared_ptr transform = m_World->AddComponent( - topWall); - transform->Position = glm::vec3(0.f, 6.f, -10.f); - transform->Scale = glm::vec3(20.f, 0.5f, 1.f); - - std::shared_ptr sprite = m_World->AddComponent(topWall); - sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; - - std::shared_ptr boxShape = m_World->AddComponent( - topWall); - - std::shared_ptr physics = m_World->AddComponent(topWall); - physics->Static = true; - physics->Category = CollisionLayer::Type::Wall; - physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick; - - m_World->CommitEntity(topWall); - } - - { - auto leftWall = m_World->CreateEntity(); - std::shared_ptr transform = m_World->AddComponent( - leftWall); - transform->Position = glm::vec3(-4.f, 1.f, -10.f); - transform->Scale = glm::vec3(0.5f, 20.f, 1.f); - - std::shared_ptr sprite = m_World->AddComponent(leftWall); - sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; - - std::shared_ptr boxShape = m_World->AddComponent( - leftWall); - - std::shared_ptr physics = m_World->AddComponent(leftWall); - physics->Static = true; - physics->Category = CollisionLayer::Type::Wall; - physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick; - - m_World->CommitEntity(leftWall); - } - - { - auto rightWall = m_World->CreateEntity(); - std::shared_ptr transform = m_World->AddComponent( - rightWall); - transform->Position = glm::vec3(4.f, 1.f, -10.f); - transform->Scale = glm::vec3(0.5f, 20.f, 1.f); - - std::shared_ptr sprite = m_World->AddComponent(rightWall); - sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; - - std::shared_ptr boxShape = m_World->AddComponent( - rightWall); - - std::shared_ptr physics = m_World->AddComponent(rightWall); - physics->Static = true; - physics->Category = CollisionLayer::Type::Wall; - physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick; - - m_World->CommitEntity(rightWall); - } - - { - auto ent = m_World->CreateEntity(); - m_World->SetProperty(ent, "Name", "Pad"); - auto ctransform = m_World->AddComponent(ent); - ctransform->Position = glm::vec3(0.f, -5.f, -10.f); - ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f); - auto rectangle = m_World->AddComponent(ent); - auto physics = m_World->AddComponent(ent); - physics->Static = false; - physics->Category = CollisionLayer::Type::Pad; - physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::PowerUp; - physics->Calculate = true; - auto cModel = m_World->AddComponent(ent); - cModel->ModelFile = "Models/Submarine2.obj"; - - auto pad = m_World->AddComponent(ent); - m_World->CommitEntity(ent); - } - - - //EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart); - m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1)); - m_EventBroker->Subscribe(m_EGameStart); - - m_LastTime = glfwGetTime(); - } - - bool Running() const { return !glfwWindowShouldClose(m_Renderer->Window()); } - - void Tick() - { - double currentTime = glfwGetTime(); - double dt = currentTime - m_LastTime; - m_LastTime = currentTime; - - // Update input - m_InputManager->Update(dt); - // Swap event queues to get fresh input data in the read queue - //m_EventBroker->Swap(); - - ResourceManager::Update(); - if (m_GameIsRunning) { - m_World->Update(dt); - } - m_EventBroker->Process(); - m_FrameStack->UpdateLayered(dt); - - m_RendererQueue.Clear(); - m_FrameStack->DrawLayered(m_RendererQueue); - //TODO Fill up the renderQueue with models (Temp fix) - if (m_GameIsRunning) { - TEMPAddToRenderQueue(); - } - - // Render scene - //TODO send renderqueue to draw. - m_Renderer->Draw(m_RendererQueue); - - m_EventBroker->Process(); - // Swap event queues - m_EventBroker->Swap(); - - glfwPollEvents(); - } - - std::shared_ptr m_TransformSystem; - std::shared_ptr m_LevelSystem; - - //TODO: Get this out of engine.h - void TEMPAddToRenderQueue() - { - if (!m_TransformSystem) - m_TransformSystem = m_World->GetSystem(); - - for (auto &pair : *m_World->GetEntities()) - { - EntityID entity = pair.first; - - auto templateComponent = m_World->GetComponent(entity); - if (templateComponent) - continue; - - auto transform = m_World->GetComponent(entity); - if (!transform) - continue; - - auto modelComponent = m_World->GetComponent(entity); - if (modelComponent) - { - Model* modelAsset = nullptr; - modelAsset = ResourceManager::Load(modelComponent->ModelFile); - - if (modelAsset) - { - Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); - 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); - } - } - - auto pointLightComponent = m_World->GetComponent(entity); - if (pointLightComponent) - { - Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); - EnqueuePointLight(absoluteTransform.Position, - pointLightComponent->Diffuse, - pointLightComponent->Specular, - pointLightComponent->Radius); - } - - auto parent = m_World->GetEntityParent(entity); - if(parent != 0) { - auto waterParticleComponent = m_World->GetComponent(parent); - if (waterParticleComponent) { - //TODO: Remove hardcoded color. - //TODO: Do i even need modelMatrix? - Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); - glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position) - * glm::scale(absoluteTransform.Scale); - EnqueueWaterParticles(absoluteTransform.Position, glm::vec4(1.f, 1.f, 1.f, 1.f), modelMatrix, absoluteTransform.Position.z); - } - } - - - auto spriteComponent = m_World->GetComponent(entity); - if (spriteComponent) - { - - std::string normal = spriteComponent->NormalTexture; - std::string spec = spriteComponent->SpecularTexture; - - if (normal.empty()) { - normal = "Textures/Core/NeutralNormalMap.png"; - } - if (spec.empty()) { - spec = "Textures/Core/NeutralSpecularMap.png"; - } - auto texturediff = ResourceManager::Load(spriteComponent->SpriteFile); - auto texturenorm = ResourceManager::Load(normal); - auto texturespec = ResourceManager::Load(spec); - - - Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); - glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1)); - glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position) - * glm::toMat4(orientation2D) - * glm::scale(absoluteTransform.Scale); - EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z); - } - } - - } - - //TODO: Get this out of engine.h - void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color, std::string fileName) - { - for (auto texGroup : model->TextureGroups) - { - ModelJob job; - job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; - job.DiffuseTexture = (texGroup.Texture) ? *texGroup.Texture : 0; - job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0; - job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0; - job.VAO = model->VAO; - job.ElementBuffer = model->ElementBuffer; - job.StartIndex = texGroup.StartIndex; - job.EndIndex = texGroup.EndIndex; - job.ModelMatrix = modelMatrix; - job.Color = color; - - m_RendererQueue.Deferred.Add(job); - } - } - - // TODO: Get this out of engine.h - void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color, float depth) - { - SpriteJob job; - job.TextureID = texture->ResourceID; - job.DiffuseTexture = *texture; - job.NormalTexture = *normalTexture; - job.SpecularTexture = *specularTexture; - job.ModelMatrix = modelMatrix; - job.Color = color; - job.Depth = depth; - - - m_RendererQueue.Forward.Add(job); - } - - void EnqueuePointLight(glm::vec3 position, glm::vec3 diffuseColor, glm::vec3 specularColor, float radius) - { - PointLightJob job; - job.Position = position; - job.DiffuseColor = diffuseColor; - job.SpecularColor = specularColor; - job.Radius = radius; - - m_RendererQueue.Lights.Add(job); - - } - - void EnqueueWaterParticles(glm::vec3 position, glm::vec4 color, glm::mat4 modelMatrix, float depth) - { - WaterParticleJob job; - job.Position = position; - job.Color = color; - job.ModelMatrix = modelMatrix; - job.Depth = depth; - - m_RendererQueue.Forward.Add(job); - } - -private: - std::shared_ptr m_EventBroker; - GUI::Frame* m_FrameStack = nullptr; - std::shared_ptr m_Renderer; - RenderQueueCollection m_RendererQueue; - std::shared_ptr m_InputManager; - std::shared_ptr m_World; - - //TODO: Redo - bool m_GameIsRunning = false; - dd::EventRelay m_EGameStart; - bool OnGameStart(const dd::Events::GameStart &event) - { - m_GameIsRunning = true; - //Todo: Move this - { - dd::Events::PlaySound e; - e.path = "Sounds/BGM/under-the-sea-instrumental.wav"; - e.isAmbient = true; - m_EventBroker->Publish(e); - } - { - dd::Events::PlaySound e; - e.path = "Sounds/BGM/water-flowing.wav"; - e.volume = 0.3f; - e.isAmbient = true; - m_EventBroker->Publish(e); - } - }; - double m_LastTime; -}; - -} From 5e0b0f920a1ce2befee384017f589c04c6206364 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 28 Sep 2015 22:46:35 +0200 Subject: [PATCH 4/9] Fixed your asset loading fuckups --- .../Models/{submarine2.mtl => Submarine2.mtl} | 0 .../Models/{submarine2.obj => Submarine2.obj} | 2 +- src/game/Sound/Sound.cpp | 20 +++++++++---------- 3 files changed, 11 insertions(+), 11 deletions(-) rename assets/Models/{submarine2.mtl => Submarine2.mtl} (100%) rename assets/Models/{submarine2.obj => Submarine2.obj} (99%) diff --git a/assets/Models/submarine2.mtl b/assets/Models/Submarine2.mtl similarity index 100% rename from assets/Models/submarine2.mtl rename to assets/Models/Submarine2.mtl diff --git a/assets/Models/submarine2.obj b/assets/Models/Submarine2.obj similarity index 99% rename from assets/Models/submarine2.obj rename to assets/Models/Submarine2.obj index 5796eba..144e0ad 100644 --- a/assets/Models/submarine2.obj +++ b/assets/Models/Submarine2.obj @@ -1,6 +1,6 @@ # Blender v2.75 (sub 0) OBJ File: 'submarine.blend' # www.blender.org -mtllib submarine2.mtl +mtllib Submarine2.mtl o Cube v -0.378953 -0.002680 -0.065172 v 0.212611 0.044805 -0.044067 diff --git a/src/game/Sound/Sound.cpp b/src/game/Sound/Sound.cpp index 972f71b..f98f8eb 100644 --- a/src/game/Sound/Sound.cpp +++ b/src/game/Sound/Sound.cpp @@ -26,7 +26,7 @@ ALuint dd::Sound::LoadFile(std::string path) return 0; } - fread(&m_Size, sizeof(unsigned long), 1, fp); + fread(&m_Size, 4*sizeof(char), 1, fp); fread(m_Type, sizeof(char), 4, fp); if (m_Type[0] != 'W' || m_Type[1] != 'A' || m_Type[2] != 'V' || m_Type[3]!= 'E') { LOG_ERROR("ERROR: Not WAVE-file"); @@ -40,13 +40,13 @@ ALuint dd::Sound::LoadFile(std::string path) } //READ THE DATA FROM WAVE-FILE - fread(&m_ChunkSize, sizeof(unsigned long), 1, fp); - fread(&m_FormatType, sizeof(short), 1, fp); - fread(&m_Channels, sizeof(short), 1, fp); - fread(&m_SampleRate, sizeof(unsigned long), 1, fp); - fread(&m_AvgBytesPerSec, sizeof(unsigned long), 1, fp); - fread(&m_BytesPerSample, sizeof(short), 1, fp); - fread(&m_BitsPerSample, sizeof(short), 1, fp); + fread(&m_ChunkSize, 4*sizeof(char), 1, fp); + fread(&m_FormatType, 2*sizeof(char), 1, fp); + fread(&m_Channels, 2*sizeof(char), 1, fp); + fread(&m_SampleRate, 4*sizeof(char), 1, fp); + fread(&m_AvgBytesPerSec, 4*sizeof(char), 1, fp); + fread(&m_BytesPerSample, 2*sizeof(char), 1, fp); + fread(&m_BitsPerSample, 2*sizeof(char), 1, fp); fread(m_Type, sizeof(char), 4, fp); if (m_Type[0] !='d' || m_Type[1] != 'a' || m_Type[2] != 't' || m_Type[3] != 'a') { @@ -54,10 +54,10 @@ ALuint dd::Sound::LoadFile(std::string path) return 0; } - fread(&m_DataSize, sizeof(unsigned long), 1, fp); + fread(&m_DataSize, 4*sizeof(char), 1, fp); unsigned char* buf = new unsigned char[m_DataSize]; - fread(buf, sizeof(unsigned char), m_DataSize, fp); + fread(buf, sizeof(char), m_DataSize, fp); fclose(fp); // Create buffer From 5e7e5ec8bb6988403775c6074cfc320a0c2e8afd Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 28 Sep 2015 22:55:39 +0200 Subject: [PATCH 5/9] Fixed precision loss in physics accumulator --- include/Physics/PhysicsSystem.h | 4 +- include/Physics/PhysicsSystem.h.orig | 149 --------------------------- src/game/Physics/PhysicsSystem.cpp | 4 +- 3 files changed, 4 insertions(+), 153 deletions(-) delete mode 100755 include/Physics/PhysicsSystem.h.orig diff --git a/include/Physics/PhysicsSystem.h b/include/Physics/PhysicsSystem.h index eaaf49e..05ea1e7 100644 --- a/include/Physics/PhysicsSystem.h +++ b/include/Physics/PhysicsSystem.h @@ -57,8 +57,8 @@ public: private: b2Vec2 m_Gravity; b2World* m_PhysicsWorld; - float m_TimeStep; - float m_Accumulator; + double m_TimeStep; + double m_Accumulator; int m_VelocityIterations, m_PositionIterations; diff --git a/include/Physics/PhysicsSystem.h.orig b/include/Physics/PhysicsSystem.h.orig deleted file mode 100755 index f1465aa..0000000 --- a/include/Physics/PhysicsSystem.h.orig +++ /dev/null @@ -1,149 +0,0 @@ -#ifndef DAYDREAM_PHYSICSSYSTEM_H -#define DAYDREAM_PHYSICSSYSTEM_H - -#include - -#include "Core/System.h" -#include "Core/World.h" -#include "CRectangleShape.h" -#include "Physics/CPhysics.h" -#include -#include "Core/CTransform.h" -#include "Transform/TransformSystem.h" -#include "Physics/EContact.h" -#include "Physics/ESetImpulse.h" -#include "Physics/CCircleShape.h" -#include "Core/EventBroker.h" -#include "Game/CPad.h" -<<<<<<< HEAD -#include "Game/CBall.h" -======= -#include "Physics/CWaterVolume.h" -#include "Rendering/CSprite.h" ->>>>>>> origin/master - - -namespace dd -{ - -namespace Systems -{ - - -class PhysicsSystem : public System -{ - friend class ContractListener; - -public: - PhysicsSystem(World* world, std::shared_ptr eventBroker) - : System(world, eventBroker) {} - - ~PhysicsSystem(); - - EventRelay m_SetImpulse; - bool SetImpulse(const Events::SetImpulse &event); - - void RegisterComponents(ComponentFactory* cf) override; - void Initialize() override; - - // Called once per system every tick - void Update(double dt) override; - // Called once for every entity in the world every tick - void UpdateEntity(double dt, EntityID entity, EntityID parent) override; - - // Called when components are committed to an entity - void OnEntityCommit(EntityID entity) override; - - // Called when an entity is removed - void OnEntityRemoved(EntityID entity) override; - -private: - b2Vec2 m_Gravity; - b2World* m_PhysicsWorld; - float m_TimeStep; - float m_Accumulator; - - int m_VelocityIterations, m_PositionIterations; - - std::unordered_map m_EntitiesToBodies; - std::unordered_map m_BodiesToEntities; - - void CreateBody(EntityID entity); - - b2ParticleSystem *m_ParticleSystem; - b2ParticleGroup* t_watergroup; - - std::unordered_map m_EntitiesToParticleHandle; - std::unordered_map m_ParticleHandleToEntities; - - void InitializeWater(); - void SyncWater(); //TODO: Probably remove this - void CreateParticleGroup(EntityID entity); - - struct Impulse - { - b2Body* Body; - b2Vec2 Impulse; - b2Vec2 Point; - }; - std::list m_Impulses; - - - - class ContactListener : public b2ContactListener - { - public: - ContactListener(PhysicsSystem* physicsSystem) - : m_PhysicsSystem(physicsSystem) { } - - void BeginContact(b2Contact* contact) - { - b2WorldManifold worldManifold; - - contact->GetWorldManifold(&worldManifold); - - Events::Contact e; - e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()]; - e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()]; - e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y)); - e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y)); - - m_PhysicsSystem->EventBroker->Publish(e); - } - void EndContact(b2Contact* contact) - { - - } - void PreSolve(b2Contact* contact, const b2Manifold* oldManifold) - { - EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()]; - EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()]; - - auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent(entityA); - auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent(entityB); - - if (physicsComponentA != nullptr && physicsComponentB != nullptr) { - if (physicsComponentA->Calculate || physicsComponentB->Calculate) { - // Turn of collisions - contact->SetEnabled(false); - } - } - - - } - void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) - { - - } - - private: - PhysicsSystem* m_PhysicsSystem; - }; - - ContactListener* m_ContactListener; -}; - -} -} - -#endif //DAYDREAM_PHYSICSSYSTEM_H diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index ecc2495..c425b5f 100644 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -15,10 +15,10 @@ void dd::Systems::PhysicsSystem::Initialize() m_Gravity = b2Vec2(0.f, -9.82f); m_PhysicsWorld = new b2World(m_Gravity); - m_TimeStep = 1.f/60.f; + m_TimeStep = 1.0/60.0; m_VelocityIterations = 6; m_PositionIterations = 2; - m_Accumulator = 0.f; + m_Accumulator = 0.0; m_PhysicsWorld->SetContactListener(m_ContactListener); From 3ab6c0c5ba66f73a2fb1697a97056580ee73b531 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 29 Sep 2015 11:09:43 +0200 Subject: [PATCH 6/9] Sound channel volume not overriding individual volume for sounds. --- include/Sound/Sound.h | 3 +++ src/game/Sound/SoundSystem.cpp | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/Sound/Sound.h b/include/Sound/Sound.h index 0992948..bc3aae8 100644 --- a/include/Sound/Sound.h +++ b/include/Sound/Sound.h @@ -16,10 +16,13 @@ class Sound : public Resource public: ALuint Buffer() { return m_Buffer; }; std::string Path() { return m_Path; }; + float Gain() { return m_Gain; }; + void SetGain(const float Gain) { m_Gain = Gain; }; private: Sound(std::string path); + float m_Gain = 1; ALuint m_Buffer; std::string m_Path; diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index 8fb89fd..5fca564 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -81,6 +81,7 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) ALuint source = CreateSource(); ALuint buffer = sound->Buffer(); alSourcei(source, AL_BUFFER, buffer); + sound->SetGain(event.Gain); //Sound settings float relativeVolume = 1.f; @@ -97,10 +98,9 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) relativeVolume = m_SFXMasterVolume; } - alSourcef(source, AL_GAIN, (event.Gain * relativeVolume)); + alSourcef(source, AL_GAIN, (sound->Gain() * relativeVolume)); alSourcef(source, AL_PITCH, event.Pitch); - //Play alSourcePlay(source); return true; @@ -133,13 +133,11 @@ bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event) bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event) { - //TODO: Make the Gain depend on the value given when stored. - //TODO: .. now it ONLY uses the master Gain if (event.IsAmbient) { m_BGMMasterVolume = event.Gain; for (auto& item : m_BGMSourcesToBuffers) { - alSourcef(item.first, AL_GAIN, event.Gain); + alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_BGMMasterVolume)); } return true; } @@ -147,7 +145,7 @@ bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &ev m_SFXMasterVolume = event.Gain; for (auto& item : m_SFXSourcesToBuffers) { - alSourcef(item.first, AL_GAIN, event.Gain); + alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_SFXMasterVolume)); } return true; } From ba67f6ea37e89a789963f9f916aabd958c8b99ba Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 1 Oct 2015 10:53:29 +0200 Subject: [PATCH 7/9] Tests fixed into working order --- src/tests/CMakeLists.txt | 11 +++++------ src/tests/EventFixture.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index ae7d47f..13604e2 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,18 +1,17 @@ project(tests) +find_package(PNG REQUIRED) find_package(Boost REQUIRED COMPONENTS chrono thread unit_test_framework) include_directories( ${CMAKE_SOURCE_DIR}/include + ${PNG_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ) -set(SOURCE_FILES - main.cpp - FileWatcherTest.cpp - EventTest.cpp - ComponentCopyTest.cpp - EntityCloneTest.cpp + +file(GLOB SOURCE_FILES + "*.cpp" ) if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/src/tests/EventFixture.h b/src/tests/EventFixture.h index ef9acbf..1548a08 100644 --- a/src/tests/EventFixture.h +++ b/src/tests/EventFixture.h @@ -40,7 +40,7 @@ struct EventFixture // Publish the event this->EventBroker->Publish(Before); // Clear to swap buffers - this->EventBroker->Clear(); + this->EventBroker->Swap(); // Process the event this->EventBroker->template Process(); } From 842a112be837ed3f7e947674fe61fc2751ae116c Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 1 Oct 2015 10:53:46 +0200 Subject: [PATCH 8/9] Added Frame tests --- src/tests/FrameTest.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/tests/FrameTest.cpp diff --git a/src/tests/FrameTest.cpp b/src/tests/FrameTest.cpp new file mode 100644 index 0000000..57f9712 --- /dev/null +++ b/src/tests/FrameTest.cpp @@ -0,0 +1,41 @@ +#include +#include "PrecompiledHeader.h" +#include "Core/EventBroker.h" +#include "GUI/Frame.h" + +using namespace dd; + +BOOST_AUTO_TEST_CASE(FrameTest) +{ + EventBroker eb; + + GUI::Frame baseFrame(&eb); + baseFrame.X = 100; + baseFrame.Y = 100; + + // Create a frame with a relative position to baseFrame + GUI::Frame f1(&baseFrame, "f1"); + f1.X = 50; + f1.Y = 50; + f1.Width = 50; + f1.Height = 50; + + BOOST_CHECK(f1.Left() == 150); BOOST_CHECK(baseFrame.X + f1.X == 150); + BOOST_CHECK(f1.Top() == 150); BOOST_CHECK(baseFrame.Y + f1.Y == 150); + BOOST_CHECK(f1.Right() == 200); BOOST_CHECK(baseFrame.X + f1.X + f1.Width == 200); + BOOST_CHECK(f1.Bottom() == 200); BOOST_CHECK(baseFrame.Y + f1.Y + f1.Height == 200); + + // Create a frame to the right of f1 + GUI::Frame f2(&baseFrame, "f2"); + f2.SetLeft(f1.Right()); + f2.SetTop(f1.Bottom()); + f2.Width = 50; + f2.Height = 50; + + BOOST_CHECK(f2.X == 100); BOOST_CHECK(f2.X == f1.X + f1.Width); + BOOST_CHECK(f2.Left() == 200); BOOST_CHECK(f2.Left() == f1.Right()); + BOOST_CHECK(f2.Y == 100); BOOST_CHECK(f2.Y == f1.Y + f1.Height); + BOOST_CHECK(f2.Top() == 150); BOOST_CHECK(f2.Top() == f1.Bottom()); + BOOST_CHECK(f2.Right() == 250); BOOST_CHECK(f2.Right() == f1.Right() + f2.Width); + BOOST_CHECK(f2.Bottom() == 200); BOOST_CHECK(f2.Bottom() == f1.Bottom() + f2.Height); +} \ No newline at end of file From e1ff3825eeaaaecb7bf39f7179c11bef03ed0502 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 1 Oct 2015 12:51:29 +0200 Subject: [PATCH 9/9] Fixed type error in sound loading --- include/Sound/Sound.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Sound/Sound.h b/include/Sound/Sound.h index bc3aae8..1e892b7 100644 --- a/include/Sound/Sound.h +++ b/include/Sound/Sound.h @@ -32,7 +32,7 @@ private: short m_FormatType, m_Channels; unsigned long m_SampleRate, m_AvgBytesPerSec; short m_BytesPerSample, m_BitsPerSample; - unsigned long m_DataSize; + unsigned int m_DataSize; std::map m_BufferCache; ALuint LoadFile(std::string path); };