Merge remote-tracking branch 'origin/master' into Physics
Conflicts: include/Physics/PhysicsSystem.h src/game/Physics/PhysicsSystem.cpp
This commit is contained in:
@@ -3,3 +3,4 @@
|
|||||||
/lib/
|
/lib/
|
||||||
# CLion
|
# CLion
|
||||||
.idea/
|
.idea/
|
||||||
|
.orig
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Blender v2.75 (sub 0) OBJ File: 'submarine.blend'
|
# Blender v2.75 (sub 0) OBJ File: 'submarine.blend'
|
||||||
# www.blender.org
|
# www.blender.org
|
||||||
mtllib submarine2.mtl
|
mtllib Submarine2.mtl
|
||||||
o Cube
|
o Cube
|
||||||
v -0.378953 -0.002680 -0.065172
|
v -0.378953 -0.002680 -0.065172
|
||||||
v 0.212611 0.044805 -0.044067
|
v 0.212611 0.044805 -0.044067
|
||||||
@@ -552,15 +552,15 @@ private:
|
|||||||
//Todo: Move this
|
//Todo: Move this
|
||||||
{
|
{
|
||||||
dd::Events::PlaySound e;
|
dd::Events::PlaySound e;
|
||||||
e.path = "Sounds/BGM/under-the-sea-instrumental.wav";
|
e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav";
|
||||||
e.isAmbient = true;
|
e.IsAmbient = true;
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
dd::Events::PlaySound e;
|
dd::Events::PlaySound e;
|
||||||
e.path = "Sounds/BGM/water-flowing.wav";
|
e.FilePath = "Sounds/BGM/water-flowing.wav";
|
||||||
e.volume = 0.3f;
|
e.Gain = 0.3f;
|
||||||
e.isAmbient = true;
|
e.IsAmbient = true;
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
#include "Game/PadSystem.h"
|
#include "Game/PadSystem.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <intrin.h>
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -61,15 +61,15 @@ private:
|
|||||||
{
|
{
|
||||||
if (event.Slider == m_SFXSlider) {
|
if (event.Slider == m_SFXSlider) {
|
||||||
Events::MasterVolume e;
|
Events::MasterVolume e;
|
||||||
e.isAmbient = false;
|
e.IsAmbient = false;
|
||||||
e.gain = event.Percentage;
|
e.Gain = event.Percentage;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.Slider == m_BGMSlider) {
|
if (event.Slider == m_BGMSlider) {
|
||||||
Events::MasterVolume e;
|
Events::MasterVolume e;
|
||||||
e.isAmbient = true;
|
e.IsAmbient = true;
|
||||||
e.gain = event.Percentage;
|
e.Gain = event.Percentage;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
//
|
|
||||||
// Created by Adam on 2015-09-17.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef COMPONENTS_CCOLLISIONSOUND_H__
|
#ifndef COMPONENTS_CCOLLISIONSOUND_H__
|
||||||
#define COMPONENTS_CCOLLISIONSOUND_H__
|
#define COMPONENTS_CCOLLISIONSOUND_H__
|
||||||
|
|
||||||
@@ -9,17 +5,15 @@
|
|||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
|
||||||
struct CollisionSound : public Component
|
struct CollisionSound : public Component
|
||||||
{
|
{
|
||||||
std::string filePath;
|
std::string FilePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
//
|
|
||||||
// Created by Adam on 2015-09-24.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef EVENTS_EMASTERVOLUME_H__
|
#ifndef EVENTS_EMASTERVOLUME_H__
|
||||||
#define EVENTS_EMASTERVOLUME_H__
|
#define EVENTS_EMASTERVOLUME_H__
|
||||||
|
|
||||||
@@ -9,19 +5,17 @@
|
|||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace Events
|
namespace Events
|
||||||
{
|
{
|
||||||
|
|
||||||
struct MasterVolume : public Event
|
struct MasterVolume : public Event
|
||||||
{
|
{
|
||||||
float gain = 1;
|
float Gain = 1;
|
||||||
//To determine what channel group to apply the change to.
|
//To determine what channel group to apply the change to.
|
||||||
bool isAmbient = false;
|
bool IsAmbient = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
#ifndef Events_PlaySFX_h__
|
#ifndef EVENTS_PLAYSFX_H__
|
||||||
#define Events_PlaySFX_h__
|
#define EVENTS_PLAYSFX_H__
|
||||||
|
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace Events
|
namespace Events
|
||||||
{
|
{
|
||||||
|
|
||||||
struct PlaySound : Event
|
struct PlaySound : Event
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string FilePath;
|
||||||
float volume = 1.f;
|
float Gain = 1.f;
|
||||||
float pitch = 1.f;
|
float Pitch = 1.f;
|
||||||
bool isAmbient = false;
|
bool IsAmbient = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -8,16 +8,12 @@ namespace dd
|
|||||||
|
|
||||||
namespace Events
|
namespace Events
|
||||||
{
|
{
|
||||||
|
|
||||||
struct StopSound : public Event
|
struct StopSound : public Event
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string FilePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,27 +12,31 @@ namespace dd
|
|||||||
class Sound : public Resource
|
class Sound : public Resource
|
||||||
{
|
{
|
||||||
friend class ResourceManager;
|
friend class ResourceManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ALuint Buffer() { return m_Buffer; };
|
ALuint Buffer() { return m_Buffer; };
|
||||||
std::string Path() { return m_Path; };
|
std::string Path() { return m_Path; };
|
||||||
|
float Gain() { return m_Gain; };
|
||||||
|
void SetGain(const float Gain) { m_Gain = Gain; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Sound(std::string path);
|
Sound(std::string path);
|
||||||
|
|
||||||
|
float m_Gain = 1;
|
||||||
|
ALuint m_Buffer;
|
||||||
|
std::string m_Path;
|
||||||
|
|
||||||
//File-info
|
//File-info
|
||||||
char m_Type[4];
|
char m_Type[4];
|
||||||
unsigned long m_Size, m_ChunkSize;
|
unsigned long m_Size, m_ChunkSize;
|
||||||
short m_FormatType, m_Channels;
|
short m_FormatType, m_Channels;
|
||||||
unsigned long m_SampleRate, m_AvgBytesPerSec;
|
unsigned long m_SampleRate, m_AvgBytesPerSec;
|
||||||
short m_BytesPerSample, m_BitsPerSample;
|
short m_BytesPerSample, m_BitsPerSample;
|
||||||
unsigned long m_DataSize;
|
unsigned int m_DataSize;
|
||||||
std::map<std::string, ALuint> m_BufferCache;
|
std::map<std::string, ALuint> m_BufferCache;
|
||||||
ALuint LoadFile(std::string path);
|
ALuint LoadFile(std::string path);
|
||||||
|
|
||||||
ALuint m_Buffer;
|
|
||||||
std::string m_Path;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+20
-21
@@ -1,61 +1,60 @@
|
|||||||
#ifndef DAYDREAM_SOUND_H
|
#ifndef SYSTEMS_SOUNDSYSTEM_H__
|
||||||
#define DAYDREAM_SOUND_H
|
#define SYSTEMS_SOUNDSYSTEM_H__
|
||||||
|
|
||||||
|
|
||||||
#include "AL/al.h"
|
#include "AL/al.h"
|
||||||
#include "AL/alc.h"
|
#include "AL/alc.h"
|
||||||
|
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/ResourceManager.h"
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
#include "Sound/EPlaySound.h"
|
#include "Sound/EPlaySound.h"
|
||||||
#include "Sound/EStopSound.h"
|
#include "Sound/EStopSound.h"
|
||||||
#include "Sound/EMasterVolume.h"
|
#include "Sound/EMasterVolume.h"
|
||||||
|
#include "Sound/CCollisionSound.h"
|
||||||
#include "Physics/EContact.h"
|
#include "Physics/EContact.h"
|
||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
#include "Game/CBrick.h"
|
#include "Game/CBrick.h"
|
||||||
#include "Game/CPad.h"
|
#include "Game/CPad.h"
|
||||||
#include "Sound/CCollisionSound.h"
|
|
||||||
#include "Core/ResourceManager.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
namespace Systems
|
namespace Systems
|
||||||
{
|
{
|
||||||
|
|
||||||
class SoundSystem : public System {
|
class SoundSystem : public System {
|
||||||
public:
|
public:
|
||||||
SoundSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
|
SoundSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
: System(world, eventBroker) { }
|
: System(world, eventBroker) { }
|
||||||
|
|
||||||
~SoundSystem();
|
~SoundSystem();
|
||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
void Update(double dt) override;
|
void Update(double dt) override;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float m_BGMMasterVolume = 1.f;
|
||||||
|
float m_SFXMasterVolume = 1.f;
|
||||||
|
std::map<ALuint, Sound*> m_BGMSourcesToBuffers;
|
||||||
|
std::map<ALuint, Sound*> m_SFXSourcesToBuffers;
|
||||||
|
ALCdevice* m_Device = nullptr;
|
||||||
|
|
||||||
//Events
|
//Events
|
||||||
dd::EventRelay<SoundSystem, dd::Events::PlaySound> m_EPlaySFX;
|
dd::EventRelay<SoundSystem, dd::Events::PlaySound> m_EPlaySFX;
|
||||||
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
|
|
||||||
dd::EventRelay<SoundSystem, dd::Events::StopSound> m_EStopSound;
|
|
||||||
dd::EventRelay<SoundSystem, dd::Events::MasterVolume> m_EMasterVolume;
|
|
||||||
bool OnPlaySound(const dd::Events::PlaySound &event);
|
bool OnPlaySound(const dd::Events::PlaySound &event);
|
||||||
|
//On contact: play the sound given in the CCOllisionSound.
|
||||||
|
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
|
||||||
bool OnContact(const dd::Events::Contact &event);
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
|
dd::EventRelay<SoundSystem, dd::Events::StopSound> m_EStopSound;
|
||||||
bool OnStopSound(const dd::Events::StopSound &event);
|
bool OnStopSound(const dd::Events::StopSound &event);
|
||||||
|
dd::EventRelay<SoundSystem, dd::Events::MasterVolume> m_EMasterVolume;
|
||||||
bool OnMasterVolume(const dd::Events::MasterVolume &event);
|
bool OnMasterVolume(const dd::Events::MasterVolume &event);
|
||||||
|
|
||||||
ALuint CreateSource();
|
ALuint CreateSource();
|
||||||
|
|
||||||
std::map<ALuint, Sound*> m_BGMSourcesToBuffers;
|
|
||||||
std::map<ALuint, Sound*> m_SFXSourcesToBuffers;
|
|
||||||
|
|
||||||
ALCdevice* m_Device;
|
|
||||||
|
|
||||||
float m_BGMMasterVolume, m_SFXMasterVolume;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //DAYDREAM_SOUND_H
|
#endif
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ void dd::OBJ::ParseMaterial()
|
|||||||
ParseColorMap(currentLine, ss, prefix, arg, colorMap);
|
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();
|
colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string();
|
||||||
currentMaterial->DiffuseTexture = colorMap;
|
currentMaterial->DiffuseTexture = colorMap;
|
||||||
continue;
|
continue;
|
||||||
@@ -280,7 +280,7 @@ void dd::OBJ::ParseMaterial()
|
|||||||
ParseColorMap(currentLine, ss, prefix, arg, colorMap);
|
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();
|
colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string();
|
||||||
currentMaterial->SpecularMap = colorMap;
|
currentMaterial->SpecularMap = colorMap;
|
||||||
continue;
|
continue;
|
||||||
@@ -297,7 +297,7 @@ void dd::OBJ::ParseMaterial()
|
|||||||
ParseBumpMap(currentLine, ss, prefix, arg, bumpMap);
|
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();
|
bumpMap.FileName = (m_MaterialPath.branch_path() / bumpMap.FileName).string();
|
||||||
currentMaterial->NormalMap = bumpMap;
|
currentMaterial->NormalMap = bumpMap;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf)
|
|||||||
void dd::Systems::BallSystem::Initialize()
|
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)
|
void dd::Systems::BallSystem::Update(double dt)
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
void dd::Systems::LevelSystem::Initialize()
|
void dd::Systems::LevelSystem::Initialize()
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, &LevelSystem::OnContact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::OnLifeLost);
|
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &LevelSystem::OnLifeLost);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::OnScoreEvent);
|
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, &LevelSystem::OnScoreEvent);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, LevelSystem::OnMultiBall);
|
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &LevelSystem::OnMultiBall);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, LevelSystem::OnCreatePowerUp);
|
EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, &LevelSystem::OnCreatePowerUp);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, LevelSystem::OnPowerUpTaken);
|
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, &LevelSystem::OnPowerUpTaken);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, LevelSystem::OnStageCleared);
|
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &LevelSystem::OnStageCleared);
|
||||||
|
|
||||||
for (int i = 0; i < Lives(); i++) {
|
for (int i = 0; i < Lives(); i++) {
|
||||||
CreateLife(i);
|
CreateLife(i);
|
||||||
@@ -195,7 +195,7 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
|||||||
|
|
||||||
//sound
|
//sound
|
||||||
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(brick);
|
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(brick);
|
||||||
collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav";
|
collisionSound->FilePath = "Sounds/Brick/shortbrickbreak.wav";
|
||||||
|
|
||||||
m_World->CommitEntity(brick);
|
m_World->CommitEntity(brick);
|
||||||
return;
|
return;
|
||||||
|
|||||||
+10
-10
@@ -26,7 +26,7 @@ ALuint dd::Sound::LoadFile(std::string path)
|
|||||||
return 0;
|
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);
|
fread(m_Type, sizeof(char), 4, fp);
|
||||||
if (m_Type[0] != 'W' || m_Type[1] != 'A' || m_Type[2] != 'V' || m_Type[3]!= 'E') {
|
if (m_Type[0] != 'W' || m_Type[1] != 'A' || m_Type[2] != 'V' || m_Type[3]!= 'E') {
|
||||||
LOG_ERROR("ERROR: Not WAVE-file");
|
LOG_ERROR("ERROR: Not WAVE-file");
|
||||||
@@ -40,13 +40,13 @@ ALuint dd::Sound::LoadFile(std::string path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//READ THE DATA FROM WAVE-FILE
|
//READ THE DATA FROM WAVE-FILE
|
||||||
fread(&m_ChunkSize, sizeof(unsigned long), 1, fp);
|
fread(&m_ChunkSize, 4*sizeof(char), 1, fp);
|
||||||
fread(&m_FormatType, sizeof(short), 1, fp);
|
fread(&m_FormatType, 2*sizeof(char), 1, fp);
|
||||||
fread(&m_Channels, sizeof(short), 1, fp);
|
fread(&m_Channels, 2*sizeof(char), 1, fp);
|
||||||
fread(&m_SampleRate, sizeof(unsigned long), 1, fp);
|
fread(&m_SampleRate, 4*sizeof(char), 1, fp);
|
||||||
fread(&m_AvgBytesPerSec, sizeof(unsigned long), 1, fp);
|
fread(&m_AvgBytesPerSec, 4*sizeof(char), 1, fp);
|
||||||
fread(&m_BytesPerSample, sizeof(short), 1, fp);
|
fread(&m_BytesPerSample, 2*sizeof(char), 1, fp);
|
||||||
fread(&m_BitsPerSample, sizeof(short), 1, fp);
|
fread(&m_BitsPerSample, 2*sizeof(char), 1, fp);
|
||||||
|
|
||||||
fread(m_Type, sizeof(char), 4, 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') {
|
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;
|
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];
|
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);
|
fclose(fp);
|
||||||
|
|
||||||
// Create buffer
|
// Create buffer
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
dd::Systems::SoundSystem::~SoundSystem()
|
dd::Systems::SoundSystem::~SoundSystem()
|
||||||
{
|
{
|
||||||
alcCloseDevice(m_Device);
|
alcCloseDevice(m_Device);
|
||||||
}
|
};
|
||||||
|
|
||||||
void dd::Systems::SoundSystem::Initialize()
|
void dd::Systems::SoundSystem::Initialize()
|
||||||
{
|
{
|
||||||
@@ -19,24 +19,28 @@ void dd::Systems::SoundSystem::Initialize()
|
|||||||
else {
|
else {
|
||||||
LOG_ERROR("OpenAL failed to initialize.");
|
LOG_ERROR("OpenAL failed to initialize.");
|
||||||
}
|
}
|
||||||
|
|
||||||
alGetError();
|
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
|
//Subscribe to events
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
|
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume);
|
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume);
|
||||||
|
|
||||||
|
//Todo: Move this
|
||||||
|
{
|
||||||
|
dd::Events::PlaySound e;
|
||||||
|
e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav";
|
||||||
|
e.IsAmbient = true;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
dd::Events::PlaySound e;
|
||||||
|
e.FilePath = "Sounds/BGM/water-flowing.wav";
|
||||||
|
e.Gain = 0.3f;
|
||||||
|
e.IsAmbient = true;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::SoundSystem::Update(double dt)
|
void dd::Systems::SoundSystem::Update(double dt)
|
||||||
@@ -44,7 +48,7 @@ void dd::Systems::SoundSystem::Update(double dt)
|
|||||||
//Clean up none-active sources
|
//Clean up none-active sources
|
||||||
//Only used for SFX's. BGM's are handled on stop sound.
|
//Only used for SFX's. BGM's are handled on stop sound.
|
||||||
std::vector<ALuint> deleteList;
|
std::vector<ALuint> deleteList;
|
||||||
for (auto item : m_SFXSourcesToBuffers) {
|
for (auto& item : m_SFXSourcesToBuffers) {
|
||||||
ALint sourceState;
|
ALint sourceState;
|
||||||
alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState);
|
alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState);
|
||||||
if (sourceState == AL_STOPPED) {
|
if (sourceState == AL_STOPPED) {
|
||||||
@@ -70,32 +74,32 @@ ALuint dd::Systems::SoundSystem::CreateSource()
|
|||||||
bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
|
bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
|
||||||
{
|
{
|
||||||
//Loading and binding sound buffer to source
|
//Loading and binding sound buffer to source
|
||||||
Sound *sound = ResourceManager::Load<Sound>(event.path);
|
Sound *sound = ResourceManager::Load<Sound>(event.FilePath);
|
||||||
if (sound == nullptr) {
|
if (sound == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ALuint source = CreateSource();
|
ALuint source = CreateSource();
|
||||||
ALuint buffer = sound->Buffer();
|
ALuint buffer = sound->Buffer();
|
||||||
alSourcei(source, AL_BUFFER, buffer);
|
alSourcei(source, AL_BUFFER, buffer);
|
||||||
|
sound->SetGain(event.Gain);
|
||||||
|
|
||||||
//Sound settings
|
//Sound settings
|
||||||
float relativeVolume = 1.f;
|
float relativeVolume = 1.f;
|
||||||
if (event.isAmbient) {
|
if (event.IsAmbient) {
|
||||||
alSourcei(source, AL_LOOPING, AL_TRUE);
|
alSourcei(source, AL_LOOPING, AL_TRUE);
|
||||||
relativeVolume = m_BGMMasterVolume;
|
relativeVolume = m_BGMMasterVolume;
|
||||||
m_BGMSourcesToBuffers[source] = sound;
|
m_BGMSourcesToBuffers[source] = sound;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (!event.isAmbient)
|
else if (!event.IsAmbient)
|
||||||
{
|
{
|
||||||
m_SFXSourcesToBuffers[source] = sound;
|
m_SFXSourcesToBuffers[source] = sound;
|
||||||
alSourcei(source, AL_LOOPING, AL_FALSE);
|
alSourcei(source, AL_LOOPING, AL_FALSE);
|
||||||
relativeVolume = m_SFXMasterVolume;
|
relativeVolume = m_SFXMasterVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
alSourcef(source, AL_GAIN, (event.volume * relativeVolume));
|
alSourcef(source, AL_GAIN, (sound->Gain() * relativeVolume));
|
||||||
alSourcef(source, AL_PITCH, event.pitch);
|
alSourcef(source, AL_PITCH, event.Pitch);
|
||||||
|
|
||||||
|
|
||||||
//Play
|
//Play
|
||||||
alSourcePlay(source);
|
alSourcePlay(source);
|
||||||
@@ -104,53 +108,50 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
|
|||||||
|
|
||||||
bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event)
|
bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event)
|
||||||
{
|
{
|
||||||
|
ALuint itemToDeleted;
|
||||||
//TODO: Delete sources for bgms
|
for (auto& item : m_BGMSourcesToBuffers)
|
||||||
ALuint itemToDelete;
|
|
||||||
for (auto item : m_BGMSourcesToBuffers)
|
|
||||||
{
|
{
|
||||||
if (item.second->Path() == event.path) {
|
if (item.second->Path() == event.FilePath) {
|
||||||
itemToDelete = item.first;
|
itemToDeleted = item.first;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
alSourceStop(itemToDelete);
|
alSourceStop(itemToDeleted);
|
||||||
alDeleteSources(1, &itemToDelete);
|
alDeleteSources(1, &itemToDeleted);
|
||||||
m_BGMSourcesToBuffers.erase(itemToDelete);
|
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)
|
for (auto item : m_SFXSourcesToBuffers)
|
||||||
{
|
{
|
||||||
if (item.second->Path() == event.path) {
|
if (item.second->Path() == event.FilePath) {
|
||||||
alSourceStop(item.first);
|
alSourceStop(item.first);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event)
|
bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event)
|
||||||
{
|
{
|
||||||
//TODO: Make the volume depend on the value given when stored.
|
if (event.IsAmbient) {
|
||||||
//TODO: .. now it ONLY uses the master volume
|
m_BGMMasterVolume = event.Gain;
|
||||||
if (event.isAmbient) {
|
for (auto& item : m_BGMSourcesToBuffers)
|
||||||
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;
|
||||||
}
|
}
|
||||||
else if (!event.isAmbient) {
|
else if (!event.IsAmbient) {
|
||||||
m_SFXMasterVolume = event.gain;
|
m_SFXMasterVolume = event.Gain;
|
||||||
for (auto item : m_SFXSourcesToBuffers)
|
for (auto& item : m_SFXSourcesToBuffers)
|
||||||
{
|
{
|
||||||
alSourcef(item.first, AL_GAIN, event.gain);
|
alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_SFXMasterVolume));
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//On contact: play the sound given in the CCOllisionSound.
|
|
||||||
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
||||||
{
|
{
|
||||||
//Check which entity has the collisionSound component.
|
//Check which entity has the collisionSound component.
|
||||||
@@ -165,10 +166,11 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
|
|
||||||
//Send play-sound event
|
//Send play-sound event
|
||||||
dd::Events::PlaySound e;
|
dd::Events::PlaySound e;
|
||||||
e.path = collisionSound->filePath;
|
e.FilePath = collisionSound->FilePath;
|
||||||
e.isAmbient = false;
|
e.IsAmbient = false;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
//return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
project(tests)
|
project(tests)
|
||||||
|
|
||||||
|
find_package(PNG REQUIRED)
|
||||||
find_package(Boost REQUIRED COMPONENTS chrono thread unit_test_framework)
|
find_package(Boost REQUIRED COMPONENTS chrono thread unit_test_framework)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${CMAKE_SOURCE_DIR}/include
|
${CMAKE_SOURCE_DIR}/include
|
||||||
|
${PNG_INCLUDE_DIRS}
|
||||||
${Boost_INCLUDE_DIRS}
|
${Boost_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCE_FILES
|
|
||||||
main.cpp
|
file(GLOB SOURCE_FILES
|
||||||
FileWatcherTest.cpp
|
"*.cpp"
|
||||||
EventTest.cpp
|
|
||||||
ComponentCopyTest.cpp
|
|
||||||
EntityCloneTest.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ struct EventFixture
|
|||||||
// Publish the event
|
// Publish the event
|
||||||
this->EventBroker->Publish(Before);
|
this->EventBroker->Publish(Before);
|
||||||
// Clear to swap buffers
|
// Clear to swap buffers
|
||||||
this->EventBroker->Clear();
|
this->EventBroker->Swap();
|
||||||
// Process the event
|
// Process the event
|
||||||
this->EventBroker->template Process<EventFixture>();
|
this->EventBroker->template Process<EventFixture>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user