-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSoundSystem.cpp
63 lines (56 loc) · 1.86 KB
/
SSoundSystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "SSoundSystem.h"
SSoundSystem::SSoundSystem()
{
//ctor
}
SSoundSystem::~SSoundSystem()
{
//dtor
}
void SSoundSystem::configure(entityx::ptr<EventManager> event_manager)
{
std::cout << "SSoundSystem configure" << std::endl;
event_manager->subscribe<ListenerPositionChangedEvent>(*this);
event_manager->subscribe<SoundEvent>(*this);
}
void SSoundSystem::update(entityx::ptr<EntityManager> es, entityx::ptr<EventManager> events, double dt)
{
}
void SSoundSystem::receive(const SoundEvent &sound)
{
entityx::Entity entity = sound.entity;
entityx::ptr<SoundComponent> soundcomp = entity.component<SoundComponent>();
entityx::ptr<PositionComponent> pos = entity.component<PositionComponent>();
if(pos)
{
soundcomp->sound.setPosition(pos->x, pos->y, pos->z);
}
if(soundcomp->sound.getStatus() != sf::Sound::Statusi::Playing && soundcomp->playme == true)
{
soundcomp->sound.play();
soundcomp->playme = false;
}
}
void SSoundSystem::receive(const ListenerPositionChangedEvent &listenerposchange)
{
sf::Listener::setPosition(listenerposchange.pos.X, listenerposchange.pos.Y, listenerposchange.pos.Z);
}
void SSoundSystem::setListenerPosition(core::vector3df pos)
{
sf::Listener::setPosition(pos.X, pos.Y, pos.Z);
}
void SSoundSystem::receive(const ComponentAddedEvent<SoundComponent> &soundcomponent)
{
entityx::ptr<SoundComponent> snd = soundcomponent.component;
entityx::Entity entity = soundcomponent.entity;
}
void SSoundSystem::receive(const ComponentAddedEvent<ListenerComponent> &listenercomponent)
{
entityx::ptr<ListenerComponent> listener = listenercomponent.component;
entityx::Entity entity = listenercomponent.entity;
entityx::ptr<PositionComponent> pos = entity.component<PositionComponent>();
if(pos)
{
sf::Listener::setPosition(pos->x, pos->y, pos->z);
}
}