Core/Signals: Remove Connect/Disconnect macros
And make interface easier to use Former-commit-id: 5b789c9acb694839cb173ae96392650d80d383b7
This commit is contained in:
parent
004b53c590
commit
4e5cdea454
|
|
@ -140,9 +140,9 @@ namespace Ndk
|
|||
{
|
||||
m_target = renderTarget;
|
||||
if (m_target)
|
||||
m_targetReleaseSlot = NazaraConnectThis(*m_target, OnRenderTargetRelease, OnRenderTargetRelease);
|
||||
m_targetReleaseSlot.Connect(m_target->OnRenderTargetRelease, this, OnRenderTargetRelease);
|
||||
else
|
||||
NazaraDisconnect(m_targetReleaseSlot);
|
||||
m_targetReleaseSlot.Disconnect();
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetTargetRegion(const NzRectf& region)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace Ndk
|
|||
void CameraComponent::OnAttached()
|
||||
{
|
||||
if (m_entity->HasComponent<NodeComponent>())
|
||||
m_nodeInvalidationSlot = NazaraConnectThis(m_entity->GetComponent<NodeComponent>(), OnNodeInvalidation, OnNodeInvalidated);
|
||||
m_nodeInvalidationSlot.Connect(m_entity->GetComponent<NodeComponent>().OnNodeInvalidation, this, OnNodeInvalidated);
|
||||
|
||||
InvalidateViewMatrix();
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ namespace Ndk
|
|||
if (IsComponent<NodeComponent>(component))
|
||||
{
|
||||
NodeComponent& nodeComponent = static_cast<NodeComponent&>(component);
|
||||
m_nodeInvalidationSlot = NazaraConnectThis(nodeComponent, OnNodeInvalidation, OnNodeInvalidated);
|
||||
m_nodeInvalidationSlot.Connect(nodeComponent.OnNodeInvalidation, this, OnNodeInvalidated);
|
||||
|
||||
InvalidateViewMatrix();
|
||||
}
|
||||
|
|
@ -67,8 +67,7 @@ namespace Ndk
|
|||
{
|
||||
if (IsComponent<NodeComponent>(component))
|
||||
{
|
||||
NodeComponent& nodeComponent = static_cast<NodeComponent&>(component);
|
||||
NazaraDisconnect(m_nodeInvalidationSlot);
|
||||
m_nodeInvalidationSlot.Disconnect();
|
||||
|
||||
InvalidateViewMatrix();
|
||||
}
|
||||
|
|
@ -76,7 +75,7 @@ namespace Ndk
|
|||
|
||||
void CameraComponent::OnDetached()
|
||||
{
|
||||
NazaraDisconnect(m_nodeInvalidationSlot);
|
||||
m_nodeInvalidationSlot.Disconnect();
|
||||
|
||||
InvalidateViewMatrix();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,6 @@
|
|||
#define NazaraSlotType(Class, SignalName) Class::SignalName ## Type::ConnectionGuard
|
||||
#define NazaraSlot(Class, SignalName, SlotName) NazaraSlotType(Class, SignalName) SlotName
|
||||
|
||||
#define NazaraConnect(Instance, SignalName, Callback) (Instance).SignalName.Connect(Callback)
|
||||
#define NazaraConnectThis(Instance, SignalName, Callback) (Instance).SignalName.Connect(this, Callback)
|
||||
#define NazaraDisconnect(SlotName) SlotName.GetConnection().Disconnect()
|
||||
|
||||
|
||||
template<typename... Args>
|
||||
class NzSignal
|
||||
|
|
@ -82,6 +78,8 @@ class NzSignal<Args...>::Connection
|
|||
Connection(Connection&& connection) = default;
|
||||
~Connection() = default;
|
||||
|
||||
template<typename... ConnectArgs>
|
||||
void Connect(BaseClass& signal, ConnectArgs&&... args);
|
||||
void Disconnect();
|
||||
|
||||
bool IsConnected() const;
|
||||
|
|
@ -109,8 +107,14 @@ class NzSignal<Args...>::ConnectionGuard
|
|||
ConnectionGuard(ConnectionGuard&& connection) = default;
|
||||
~ConnectionGuard();
|
||||
|
||||
template<typename... ConnectArgs>
|
||||
void Connect(BaseClass& signal, ConnectArgs&&... args);
|
||||
void Disconnect();
|
||||
|
||||
Connection& GetConnection();
|
||||
|
||||
bool IsConnected() const;
|
||||
|
||||
ConnectionGuard& operator=(const Connection& connection);
|
||||
ConnectionGuard& operator=(const ConnectionGuard& connection) = delete;
|
||||
ConnectionGuard& operator=(Connection&& connection);
|
||||
|
|
|
|||
|
|
@ -100,6 +100,13 @@ m_ptr(slot)
|
|||
{
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
template<typename... ConnectArgs>
|
||||
void NzSignal<Args...>::Connection::Connect(BaseClass& signal, ConnectArgs&&... args)
|
||||
{
|
||||
operator=(signal.Connect(std::forward<ConnectArgs>(args)...));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void NzSignal<Args...>::Connection::Disconnect()
|
||||
{
|
||||
|
|
@ -132,12 +139,32 @@ NzSignal<Args...>::ConnectionGuard::~ConnectionGuard()
|
|||
m_connection.Disconnect();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
template<typename... ConnectArgs>
|
||||
void NzSignal<Args...>::ConnectionGuard::Connect(BaseClass& signal, ConnectArgs&&... args)
|
||||
{
|
||||
m_connection.Disconnect();
|
||||
m_connection.Connect(signal, std::forward<ConnectArgs>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void NzSignal<Args...>::ConnectionGuard::Disconnect()
|
||||
{
|
||||
m_connection.Disconnect();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
typename NzSignal<Args...>::Connection& NzSignal<Args...>::ConnectionGuard::GetConnection()
|
||||
{
|
||||
return m_connection;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
bool NzSignal<Args...>::ConnectionGuard::IsConnected() const
|
||||
{
|
||||
return m_connection.IsConnected();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
typename NzSignal<Args...>::ConnectionGuard& NzSignal<Args...>::ConnectionGuard::operator=(const Connection& connection)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -163,13 +163,13 @@ void NzCamera::SetTarget(const NzRenderTarget* renderTarget)
|
|||
|
||||
if (m_target)
|
||||
{
|
||||
m_targetReleaseSlot = NazaraConnectThis(*m_target, OnRenderTargetRelease, OnRenderTargetRelease);
|
||||
m_targetResizeSlot = NazaraConnectThis(*m_target, OnRenderTargetSizeChange, OnRenderTargetSizeChange);
|
||||
m_targetReleaseSlot.Connect(m_target->OnRenderTargetRelease, this, OnRenderTargetRelease);
|
||||
m_targetResizeSlot.Connect(m_target->OnRenderTargetSizeChange, this, OnRenderTargetSizeChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraDisconnect(m_targetReleaseSlot);
|
||||
NazaraDisconnect(m_targetResizeSlot);
|
||||
m_targetReleaseSlot.Disconnect();
|
||||
m_targetResizeSlot.Disconnect();
|
||||
}
|
||||
|
||||
m_frustumUpdated = false;
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ m_verticesUpdated(sprite.m_verticesUpdated)
|
|||
const NzAbstractAtlas* atlas = it->first;
|
||||
AtlasSlots& slots = m_atlases[atlas];
|
||||
|
||||
slots.clearSlot = NazaraConnectThis(*atlas, OnAtlasCleared, OnAtlasInvalidated);
|
||||
slots.layerChangeSlot = NazaraConnectThis(*atlas, OnAtlasLayerChange, OnAtlasLayerChange);
|
||||
slots.releaseSlot = NazaraConnectThis(*atlas, OnAtlasRelease, OnAtlasInvalidated);
|
||||
slots.clearSlot.Connect(atlas->OnAtlasCleared, this, OnAtlasInvalidated);
|
||||
slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, OnAtlasLayerChange);
|
||||
slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, OnAtlasInvalidated);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -153,9 +153,9 @@ void NzTextSprite::Update(const NzAbstractTextDrawer& drawer)
|
|||
{
|
||||
AtlasSlots& slots = m_atlases[atlas];
|
||||
|
||||
slots.clearSlot = NazaraConnectThis(*atlas, OnAtlasCleared, OnAtlasInvalidated);
|
||||
slots.layerChangeSlot = NazaraConnectThis(*atlas, OnAtlasLayerChange, OnAtlasLayerChange);
|
||||
slots.releaseSlot = NazaraConnectThis(*atlas, OnAtlasRelease, OnAtlasInvalidated);
|
||||
slots.clearSlot.Connect(atlas->OnAtlasCleared, this, OnAtlasInvalidated);
|
||||
slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, OnAtlasLayerChange);
|
||||
slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, OnAtlasInvalidated);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -277,9 +277,9 @@ NzTextSprite& NzTextSprite::operator=(const NzTextSprite& text)
|
|||
const NzAbstractAtlas* atlas = it->first;
|
||||
AtlasSlots& slots = m_atlases[atlas];
|
||||
|
||||
slots.clearSlot = NazaraConnectThis(*atlas, OnAtlasCleared, OnAtlasInvalidated);
|
||||
slots.layerChangeSlot = NazaraConnectThis(*atlas, OnAtlasLayerChange, OnAtlasLayerChange);
|
||||
slots.releaseSlot = NazaraConnectThis(*atlas, OnAtlasRelease, OnAtlasInvalidated);
|
||||
slots.clearSlot.Connect(atlas->OnAtlasCleared, this, OnAtlasInvalidated);
|
||||
slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, OnAtlasLayerChange);
|
||||
slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, OnAtlasInvalidated);
|
||||
}
|
||||
|
||||
// On ne copie pas les sommets finaux car il est très probable que nos paramètres soient modifiés et qu'ils doivent être régénérés de toute façon
|
||||
|
|
|
|||
|
|
@ -218,13 +218,13 @@ void NzView::SetTarget(const NzRenderTarget* renderTarget)
|
|||
m_target = renderTarget;
|
||||
if (m_target)
|
||||
{
|
||||
m_targetReleaseSlot = NazaraConnectThis(*m_target, OnRenderTargetRelease, OnRenderTargetRelease);
|
||||
m_targetResizeSlot = NazaraConnectThis(*m_target, OnRenderTargetSizeChange, OnRenderTargetSizeChange);
|
||||
m_targetReleaseSlot.Connect(m_target->OnRenderTargetRelease, this, OnRenderTargetRelease);
|
||||
m_targetResizeSlot.Connect(m_target->OnRenderTargetSizeChange, this, OnRenderTargetSizeChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraDisconnect(m_targetReleaseSlot);
|
||||
NazaraDisconnect(m_targetResizeSlot);
|
||||
m_targetReleaseSlot.Disconnect();
|
||||
m_targetResizeSlot.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1621,7 +1621,7 @@ bool NzRenderer::EnsureStateUpdate()
|
|||
if (it == s_vaos.end())
|
||||
{
|
||||
Context_Entry entry;
|
||||
entry.onReleaseSlot = context->OnContextRelease.Connect(OnContextRelease);
|
||||
entry.onReleaseSlot.Connect(context->OnContextRelease, OnContextRelease);
|
||||
|
||||
it = s_vaos.insert(std::make_pair(context, std::move(entry))).first;
|
||||
}
|
||||
|
|
@ -1647,13 +1647,13 @@ bool NzRenderer::EnsureStateUpdate()
|
|||
|
||||
// Connect the slots
|
||||
if (s_indexBuffer)
|
||||
entry.onIndexBufferReleaseSlot = s_indexBuffer->OnIndexBufferRelease.Connect(OnIndexBufferRelease);
|
||||
entry.onIndexBufferReleaseSlot.Connect(s_indexBuffer->OnIndexBufferRelease, OnIndexBufferRelease);
|
||||
|
||||
if (instancingDeclaration)
|
||||
entry.onInstancingDeclarationReleaseSlot = instancingDeclaration->OnVertexDeclarationRelease.Connect(OnVertexDeclarationRelease);
|
||||
entry.onInstancingDeclarationReleaseSlot.Connect(instancingDeclaration->OnVertexDeclarationRelease, OnVertexDeclarationRelease);
|
||||
|
||||
entry.onVertexBufferReleaseSlot = s_vertexBuffer->OnVertexBufferRelease.Connect(OnVertexBufferRelease);
|
||||
entry.onVertexDeclarationReleaseSlot = vertexDeclaration->OnVertexDeclarationRelease.Connect(OnVertexDeclarationRelease);
|
||||
entry.onVertexBufferReleaseSlot.Connect(s_vertexBuffer->OnVertexBufferRelease, OnVertexBufferRelease);
|
||||
entry.onVertexDeclarationReleaseSlot.Connect(vertexDeclaration->OnVertexDeclarationRelease, OnVertexDeclarationRelease);
|
||||
|
||||
vaoIt = vaoMap.insert(std::make_pair(key, std::move(entry))).first;
|
||||
|
||||
|
|
|
|||
|
|
@ -298,15 +298,15 @@ void NzFont::SetAtlas(const std::shared_ptr<NzAbstractAtlas>& atlas)
|
|||
m_atlas = atlas;
|
||||
if (m_atlas)
|
||||
{
|
||||
m_atlasClearedSlot = NazaraConnectThis(*m_atlas, OnAtlasCleared, OnAtlasCleared);
|
||||
m_atlasLayerChangeSlot = NazaraConnectThis(*m_atlas, OnAtlasLayerChange, OnAtlasLayerChange);
|
||||
m_atlasReleaseSlot = NazaraConnectThis(*m_atlas, OnAtlasRelease, OnAtlasRelease);
|
||||
m_atlasClearedSlot.Connect(m_atlas->OnAtlasCleared, this, OnAtlasCleared);
|
||||
m_atlasLayerChangeSlot.Connect(m_atlas->OnAtlasLayerChange, this, OnAtlasLayerChange);
|
||||
m_atlasReleaseSlot.Connect(m_atlas->OnAtlasRelease, this, OnAtlasRelease);
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraDisconnect(m_atlasClearedSlot);
|
||||
NazaraDisconnect(m_atlasLayerChangeSlot);
|
||||
NazaraDisconnect(m_atlasReleaseSlot);
|
||||
m_atlasClearedSlot.Disconnect();
|
||||
m_atlasLayerChangeSlot.Disconnect();
|
||||
m_atlasReleaseSlot.Disconnect();
|
||||
}
|
||||
|
||||
OnFontAtlasChanged(this);
|
||||
|
|
|
|||
|
|
@ -112,17 +112,17 @@ void NzSimpleTextDrawer::SetFont(NzFont* font)
|
|||
m_font = font;
|
||||
if (m_font)
|
||||
{
|
||||
m_atlasChangedSlot = NazaraConnectThis(*m_font, OnFontAtlasChanged, OnFontInvalidated);
|
||||
m_atlasLayerChangedSlot = NazaraConnectThis(*m_font, OnFontAtlasLayerChanged, OnFontInvalidated);
|
||||
m_fontReleaseSlot = NazaraConnectThis(*m_font, OnFontRelease, OnFontRelease);
|
||||
m_glyphCacheClearedSlot = NazaraConnectThis(*m_font, OnFontGlyphCacheCleared, OnFontInvalidated);
|
||||
m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, OnFontInvalidated);
|
||||
m_atlasLayerChangedSlot.Connect(m_font->OnFontAtlasLayerChanged, this, OnFontInvalidated);
|
||||
m_fontReleaseSlot.Connect(m_font->OnFontRelease, this, OnFontRelease);
|
||||
m_glyphCacheClearedSlot.Connect(m_font->OnFontAtlasChanged, this, OnFontInvalidated);
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraDisconnect(m_atlasChangedSlot);
|
||||
NazaraDisconnect(m_atlasLayerChangedSlot);
|
||||
NazaraDisconnect(m_fontReleaseSlot);
|
||||
NazaraDisconnect(m_glyphCacheClearedSlot);
|
||||
m_atlasChangedSlot.Disconnect();
|
||||
m_atlasLayerChangedSlot.Disconnect();
|
||||
m_fontReleaseSlot.Disconnect();
|
||||
m_glyphCacheClearedSlot.Disconnect();
|
||||
}
|
||||
|
||||
m_glyphUpdated = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue