(NDK) Added Listener component and system
Former-commit-id: 0553c4ad9a7e33608e9ab91bd4ca8812272a6293
This commit is contained in:
parent
f290b8d886
commit
f137a75267
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_COMPONENTS_LISTENERCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_LISTENERCOMPONENT_HPP
|
||||
|
||||
#include <NDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API ListenerComponent : public Component<ListenerComponent>
|
||||
{
|
||||
public:
|
||||
ListenerComponent();
|
||||
~ListenerComponent() = default;
|
||||
|
||||
bool IsActive() const;
|
||||
bool SetActive(bool active = true);
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
bool m_isActive;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Components/ListenerComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_LISTENERCOMPONENT_HPP
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline ListenerComponent::ListenerComponent() :
|
||||
m_isActive(true)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool ListenerComponent::IsActive() const
|
||||
{
|
||||
return m_isActive;
|
||||
}
|
||||
|
||||
inline bool ListenerComponent::SetActive(bool active)
|
||||
{
|
||||
m_isActive = active;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SYSTEMS_LISTENERSYSTEM_HPP
|
||||
#define NDK_SYSTEMS_LISTENERSYSTEM_HPP
|
||||
|
||||
#include <NDK/System.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API ListenerSystem : public System<ListenerSystem>
|
||||
{
|
||||
public:
|
||||
ListenerSystem();
|
||||
~ListenerSystem() = default;
|
||||
|
||||
void Update(float elapsedTime);
|
||||
|
||||
static SystemIndex systemIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Systems/ListenerSystem.inl>
|
||||
|
||||
#endif // NDK_SYSTEMS_LISTENERSYSTEM_HPP
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
|
@ -26,9 +26,11 @@ namespace Ndk
|
|||
public:
|
||||
using EntityList = std::vector<EntityHandle>;
|
||||
|
||||
World() = default;
|
||||
World(bool addDefaultSystems = true);
|
||||
~World();
|
||||
|
||||
void AddDefaultSystems();
|
||||
|
||||
BaseSystem& AddSystem(std::unique_ptr<BaseSystem>&& system);
|
||||
template<typename SystemType, typename... Args> SystemType& AddSystem(Args&&... args);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,12 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
inline World::World(bool addDefaultSystems)
|
||||
{
|
||||
if (addDefaultSystems)
|
||||
AddDefaultSystems();
|
||||
}
|
||||
|
||||
inline BaseSystem& World::AddSystem(std::unique_ptr<BaseSystem>&& system)
|
||||
{
|
||||
NazaraAssert(system, "System must be valid");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ComponentIndex ListenerComponent::componentIndex;
|
||||
}
|
||||
|
|
@ -6,5 +6,5 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
ComponentIndex NodeComponent::componentIndex = 0;
|
||||
ComponentIndex NodeComponent::componentIndex;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@
|
|||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/BaseSystem.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -45,8 +47,12 @@ namespace Ndk
|
|||
BaseSystem::Initialize();
|
||||
|
||||
// Composants
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<NodeComponent>("NdkNode");
|
||||
|
||||
// Systèmes
|
||||
InitializeSystem<ListenerSystem>();
|
||||
|
||||
NazaraNotice("Initialized: SDK");
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <Nazara/Audio/Audio.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ListenerSystem::ListenerSystem()
|
||||
{
|
||||
Requires<ListenerComponent, NodeComponent>();
|
||||
}
|
||||
|
||||
void ListenerSystem::Update(float elapsedTime)
|
||||
{
|
||||
unsigned int activeListenerCount = 0;
|
||||
|
||||
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||
{
|
||||
// Le listener est-il actif ?
|
||||
const ListenerComponent& listener = entity->GetComponent<ListenerComponent>();
|
||||
if (!listener.IsActive())
|
||||
continue;
|
||||
|
||||
const NodeComponent& node = entity->GetComponent<NodeComponent>();
|
||||
NzAudio::SetListenerPosition(node.GetPosition(nzCoordSys_Global));
|
||||
NzAudio::SetListenerRotation(node.GetRotation(nzCoordSys_Global));
|
||||
|
||||
activeListenerCount++;
|
||||
}
|
||||
|
||||
if (activeListenerCount > 1)
|
||||
NazaraWarning(NzString::Number(activeListenerCount) + " listeners were active in the same update loop");
|
||||
}
|
||||
|
||||
SystemIndex ListenerSystem::systemIndex;
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -13,6 +14,11 @@ namespace Ndk
|
|||
Clear();
|
||||
}
|
||||
|
||||
void World::AddDefaultSystems()
|
||||
{
|
||||
AddSystem<ListenerSystem>();
|
||||
}
|
||||
|
||||
const EntityHandle& World::CreateEntity()
|
||||
{
|
||||
EntityId id;
|
||||
|
|
|
|||
Loading…
Reference in New Issue