From f17be35cab378d412e3390691b338a0f4373c042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 4 Oct 2017 10:53:51 +0200 Subject: [PATCH 01/11] Network/SocketPoller: Uniformize behavior accross platforms On Windows, a closed connection will mark as ready for read/write --- src/Nazara/Network/Linux/SocketPollerImpl.cpp | 3 --- src/Nazara/Network/Posix/SocketPollerImpl.cpp | 11 ++++++++--- src/Nazara/Network/Win32/SocketPollerImpl.cpp | 11 ++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Nazara/Network/Linux/SocketPollerImpl.cpp b/src/Nazara/Network/Linux/SocketPollerImpl.cpp index 6e902a587..d3287a815 100644 --- a/src/Nazara/Network/Linux/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Linux/SocketPollerImpl.cpp @@ -111,9 +111,6 @@ namespace Nz if (m_events[i].events & (EPOLLOUT | EPOLLERR)) m_readyToWriteSockets.insert(m_events[i].data.fd); - - if (m_events[i].events & EPOLLERR) - NazaraWarning("Descriptor " + String::Number(m_events[i].data.fd) + " was returned by epoll with EPOLLERR status"); } else { diff --git a/src/Nazara/Network/Posix/SocketPollerImpl.cpp b/src/Nazara/Network/Posix/SocketPollerImpl.cpp index ed391c6f3..76e43ed4f 100644 --- a/src/Nazara/Network/Posix/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Posix/SocketPollerImpl.cpp @@ -90,12 +90,12 @@ namespace Nz int socketRemaining = activeSockets; for (PollSocket& entry : m_sockets) { - if (entry.revents != 0) + if (entry.revents & (POLLRDNORM | POLLWRNORM | POLLHUP | POLLERR)) { - if (entry.revents & POLLRDNORM) + if (entry.revents & (POLLRDNORM | POLLHUP | POLLERR)) m_readyToReadSockets.insert(entry.fd); - if (entry.revents & POLLWRNORM) + if (entry.revents & (POLLWRNORM | POLLERR)) m_readyToWriteSockets.insert(entry.fd); entry.revents = 0; @@ -103,6 +103,11 @@ namespace Nz if (--socketRemaining == 0) break; } + else + { + NazaraWarning("Socket " + String::Number(entry.fd) + " was returned by WSAPoll without POLLRDNORM nor POLLWRNORM events (events: 0x" + String::Number(entry.events, 16) + ')'); + activeSockets--; + } } } diff --git a/src/Nazara/Network/Win32/SocketPollerImpl.cpp b/src/Nazara/Network/Win32/SocketPollerImpl.cpp index 6789f35f4..40f176da2 100644 --- a/src/Nazara/Network/Win32/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Win32/SocketPollerImpl.cpp @@ -143,12 +143,12 @@ namespace Nz int socketRemaining = activeSockets; for (PollSocket& entry : m_sockets) { - if (entry.revents != 0) + if (entry.revents & (POLLRDNORM | POLLWRNORM | POLLHUP | POLLERR)) { - if (entry.revents & POLLRDNORM) + if (entry.revents & (POLLRDNORM | POLLHUP | POLLERR)) m_readyToReadSockets.insert(entry.fd); - if (entry.revents & POLLWRNORM) + if (entry.revents & (POLLWRNORM | POLLERR)) m_readyToWriteSockets.insert(entry.fd); entry.revents = 0; @@ -156,6 +156,11 @@ namespace Nz if (--socketRemaining == 0) break; } + else + { + NazaraWarning("Socket " + String::Number(entry.fd) + " was returned by WSAPoll without POLLRDNORM nor POLLWRNORM events (events: 0x" + String::Number(entry.events, 16) + ')'); + activeSockets--; + } } } From ecbc8343a521fa628099a6ffc513f3047adfb660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 4 Oct 2017 16:24:57 +0200 Subject: [PATCH 02/11] SocketPoller: Fix behavior on Windows and BSD --- src/Nazara/Network/Posix/SocketPollerImpl.cpp | 5 ++++- src/Nazara/Network/Win32/SocketPollerImpl.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Nazara/Network/Posix/SocketPollerImpl.cpp b/src/Nazara/Network/Posix/SocketPollerImpl.cpp index 76e43ed4f..810427933 100644 --- a/src/Nazara/Network/Posix/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Posix/SocketPollerImpl.cpp @@ -90,6 +90,9 @@ namespace Nz int socketRemaining = activeSockets; for (PollSocket& entry : m_sockets) { + if (!entry.revents) + continue; + if (entry.revents & (POLLRDNORM | POLLWRNORM | POLLHUP | POLLERR)) { if (entry.revents & (POLLRDNORM | POLLHUP | POLLERR)) @@ -105,7 +108,7 @@ namespace Nz } else { - NazaraWarning("Socket " + String::Number(entry.fd) + " was returned by WSAPoll without POLLRDNORM nor POLLWRNORM events (events: 0x" + String::Number(entry.events, 16) + ')'); + NazaraWarning("Socket " + String::Number(entry.fd) + " was returned by WSAPoll without POLLRDNORM nor POLLWRNORM events (events: 0x" + String::Number(entry.revents, 16) + ')'); activeSockets--; } } diff --git a/src/Nazara/Network/Win32/SocketPollerImpl.cpp b/src/Nazara/Network/Win32/SocketPollerImpl.cpp index 40f176da2..43dc9fec2 100644 --- a/src/Nazara/Network/Win32/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Win32/SocketPollerImpl.cpp @@ -143,6 +143,9 @@ namespace Nz int socketRemaining = activeSockets; for (PollSocket& entry : m_sockets) { + if (!entry.revents) + continue; + if (entry.revents & (POLLRDNORM | POLLWRNORM | POLLHUP | POLLERR)) { if (entry.revents & (POLLRDNORM | POLLHUP | POLLERR)) @@ -158,12 +161,11 @@ namespace Nz } else { - NazaraWarning("Socket " + String::Number(entry.fd) + " was returned by WSAPoll without POLLRDNORM nor POLLWRNORM events (events: 0x" + String::Number(entry.events, 16) + ')'); + NazaraWarning("Socket " + String::Number(entry.fd) + " was returned by WSAPoll without POLLRDNORM nor POLLWRNORM events (events: 0x" + String::Number(entry.revents, 16) + ')'); activeSockets--; } } } - #else fd_set* readSet = nullptr; fd_set* writeSet = nullptr; From f42be919e6e050c333c0f7427c701d365911c5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 6 Oct 2017 09:18:14 +0200 Subject: [PATCH 03/11] Fix LogoDemo after mapper change --- examples/Particles/LogoDemo.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/Particles/LogoDemo.cpp b/examples/Particles/LogoDemo.cpp index 831fcffd5..ae30c6436 100644 --- a/examples/Particles/LogoDemo.cpp +++ b/examples/Particles/LogoDemo.cpp @@ -21,7 +21,7 @@ struct ParticleData { Nz::Color color; Nz::Vector2f destination; - Nz::Vector2f position; + Nz::Vector3f position; Nz::Vector2f velocity; }; @@ -33,18 +33,18 @@ struct SpriteController : public Nz::ParticleController return; auto destPtr = mapper.GetComponentPtr(Nz::ParticleComponent_Userdata0); - auto posPtr = mapper.GetComponentPtr(Nz::ParticleComponent_Position); + auto posPtr = mapper.GetComponentPtr(Nz::ParticleComponent_Position); auto velPtr = mapper.GetComponentPtr(Nz::ParticleComponent_Velocity); std::uniform_real_distribution dis(-1.f, 1.f); for (unsigned int i = startId; i <= endId; ++i) { - Nz::Vector2f newVel = destPtr[i] - posPtr[i]; + Nz::Vector2f newVel = destPtr[i] - Nz::Vector2f(posPtr[i]); float length; newVel.Normalize(&length); - float distance = SquaredDistancePointSegment(oldMousePos, actualMousePos, posPtr[i]); + float distance = SquaredDistancePointSegment(oldMousePos, actualMousePos, Nz::Vector2f(posPtr[i])); if (distance < 250.f) { Nz::Vector2f mouseLine = actualMousePos - oldMousePos; @@ -162,7 +162,7 @@ ParticleDemo("Logo", sharedData) m_declaration = Nz::ParticleDeclaration::New(); m_declaration->EnableComponent(Nz::ParticleComponent_Color, Nz::ComponentType_Color, NazaraOffsetOf(ParticleData, color)); - m_declaration->EnableComponent(Nz::ParticleComponent_Position, Nz::ComponentType_Float2, NazaraOffsetOf(ParticleData, position)); + m_declaration->EnableComponent(Nz::ParticleComponent_Position, Nz::ComponentType_Float3, NazaraOffsetOf(ParticleData, position)); m_declaration->EnableComponent(Nz::ParticleComponent_Userdata0, Nz::ComponentType_Float2, NazaraOffsetOf(ParticleData, destination)); m_declaration->EnableComponent(Nz::ParticleComponent_Velocity, Nz::ComponentType_Float2, NazaraOffsetOf(ParticleData, velocity)); } @@ -265,7 +265,7 @@ void LogoExample::ResetParticles(float elapsed) { sprite->color = data.color; sprite->destination = offset + Nz::Vector2f(data.pos); - sprite->position.Set(disX(m_shared.randomGen) - float(width), disY(m_shared.randomGen)); + sprite->position.Set(disX(m_shared.randomGen) - float(width), disY(m_shared.randomGen), 0.f); sprite->velocity = Nz::Vector2f::Zero(); sprite++; } From 1f48ec40993901a9bd78c92c7ab1944baddc2772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 6 Oct 2017 14:04:36 +0200 Subject: [PATCH 04/11] Network/ENetHost: Fix compression callbacks --- src/Nazara/Network/ENetHost.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Nazara/Network/ENetHost.cpp b/src/Nazara/Network/ENetHost.cpp index f86b2289f..892b5ed56 100644 --- a/src/Nazara/Network/ENetHost.cpp +++ b/src/Nazara/Network/ENetHost.cpp @@ -201,7 +201,7 @@ namespace Nz { m_serviceTime = GetElapsedMilliseconds(); - SendOutgoingCommands(nullptr, 0); + SendOutgoingCommands(nullptr, false); } int ENetHost::Service(ENetEvent* event, UInt32 timeout) @@ -526,7 +526,7 @@ namespace Nz if (!m_compressor) return false; - std::size_t newSize = m_compressor->Decompress(peer, m_receivedData, m_receivedDataLength, m_packetData[1].data() + headerSize, m_packetData[1].size() - headerSize); + std::size_t newSize = m_compressor->Decompress(peer, m_receivedData + headerSize, m_receivedDataLength - headerSize, m_packetData[1].data() + headerSize, m_packetData[1].size() - headerSize); if (newSize == 0 || newSize > m_packetData[1].size() - headerSize) return false; @@ -1041,7 +1041,7 @@ namespace Nz std::size_t compressedSize = 0; if (m_compressor) { - compressedSize = m_compressor->Compress(currentPeer, &m_buffers[1], m_bufferCount, m_packetSize - sizeof(ENetProtocolHeader), m_packetData[1].data(), m_packetData[1].size()); + compressedSize = m_compressor->Compress(currentPeer, &m_buffers[1], m_bufferCount - 1, m_packetSize - sizeof(ENetProtocolHeader), m_packetData[1].data(), m_packetData[1].size()); if (compressedSize > 0) m_headerFlags |= ENetProtocolHeaderFlag_Compressed; } @@ -1181,6 +1181,8 @@ namespace Nz buffer.data = &command; buffer.dataLength = commandSize; + m_packetSize += buffer.dataLength; + command = outgoingCommand->command; if (outgoingCommand->packet) From be8cc08ba9b5c9544bcff60fa4bd8deea4aba1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 6 Oct 2017 14:12:18 +0200 Subject: [PATCH 05/11] Sdk: Fix segfault when deleting hovered widget --- SDK/include/NDK/BaseWidget.hpp | 2 +- SDK/include/NDK/Canvas.hpp | 6 +-- SDK/include/NDK/Canvas.inl | 10 ++-- SDK/src/NDK/BaseWidget.cpp | 6 +-- SDK/src/NDK/Canvas.cpp | 87 ++++++++++++++++++++-------------- 5 files changed, 63 insertions(+), 48 deletions(-) diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 2494f37f4..9ec7ef7a9 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -80,7 +80,7 @@ namespace Ndk }; protected: - EntityHandle CreateEntity(); + const EntityHandle& CreateEntity(); void DestroyEntity(Entity* entity); virtual void Layout(); void InvalidateNode() override; diff --git a/SDK/include/NDK/Canvas.hpp b/SDK/include/NDK/Canvas.hpp index f37ad3cda..bcafc1680 100644 --- a/SDK/include/NDK/Canvas.hpp +++ b/SDK/include/NDK/Canvas.hpp @@ -39,7 +39,7 @@ namespace Ndk std::size_t RegisterWidget(BaseWidget* widget); - inline void SetKeyboardOwner(BaseWidget* widget); + inline void SetKeyboardOwner(std::size_t canvasIndex); void UnregisterWidget(std::size_t index); @@ -67,10 +67,10 @@ namespace Ndk NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot); NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot); + std::size_t m_keyboardOwner; + std::size_t m_hoveredWidget; std::vector m_widgetBoxes; Nz::CursorControllerHandle m_cursorController; - const WidgetBox* m_hoveredWidget; - BaseWidget* m_keyboardOwner; WorldHandle m_world; }; } diff --git a/SDK/include/NDK/Canvas.inl b/SDK/include/NDK/Canvas.inl index f3a8dea88..1d64621f2 100644 --- a/SDK/include/NDK/Canvas.inl +++ b/SDK/include/NDK/Canvas.inl @@ -8,9 +8,9 @@ namespace Ndk { inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController) : + m_hoveredWidget(InvalidCanvasIndex), + m_keyboardOwner(InvalidCanvasIndex), m_cursorController(cursorController), - m_hoveredWidget(nullptr), - m_keyboardOwner(nullptr), m_world(std::move(world)) { m_canvas = this; @@ -61,12 +61,12 @@ namespace Ndk WidgetBox& entry = m_widgetBoxes[index]; entry.cursor = entry.widget->GetCursor(); - if (m_cursorController && m_hoveredWidget == &entry) + if (m_cursorController && m_hoveredWidget == index) m_cursorController->UpdateCursor(Nz::Cursor::Get(entry.cursor)); } - inline void Ndk::Canvas::SetKeyboardOwner(BaseWidget* widget) + inline void Canvas::SetKeyboardOwner(std::size_t canvasIndex) { - m_keyboardOwner = widget; + m_keyboardOwner = canvasIndex; } } diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index 7368558d3..aad8c56c6 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -87,7 +87,7 @@ namespace Ndk void BaseWidget::GrabKeyboard() { - m_canvas->SetKeyboardOwner(this); + m_canvas->SetKeyboardOwner(m_canvasIndex); } void BaseWidget::SetBackgroundColor(const Nz::Color& color) @@ -133,9 +133,9 @@ namespace Ndk } } - EntityHandle BaseWidget::CreateEntity() + const Ndk::EntityHandle& BaseWidget::CreateEntity() { - EntityHandle newEntity = m_world->CreateEntity(); + const EntityHandle& newEntity = m_world->CreateEntity(); newEntity->Enable(m_visible); m_entities.emplace_back(newEntity); diff --git a/SDK/src/NDK/Canvas.cpp b/SDK/src/NDK/Canvas.cpp index 81f5ea994..c3b2862c4 100644 --- a/SDK/src/NDK/Canvas.cpp +++ b/SDK/src/NDK/Canvas.cpp @@ -28,18 +28,25 @@ namespace Ndk { WidgetBox& entry = m_widgetBoxes[index]; - if (m_hoveredWidget == &entry) - m_hoveredWidget = nullptr; + if (m_hoveredWidget == index) + m_hoveredWidget = InvalidCanvasIndex; - if (m_keyboardOwner == entry.widget) - m_keyboardOwner = nullptr; + if (m_keyboardOwner == index) + m_keyboardOwner = InvalidCanvasIndex; if (m_widgetBoxes.size() > 1U) { WidgetBox& lastEntry = m_widgetBoxes.back(); + std::size_t lastEntryIndex = m_widgetBoxes.size() - 1; entry = std::move(lastEntry); entry.widget->UpdateCanvasIndex(index); + + if (m_hoveredWidget == lastEntryIndex) + m_hoveredWidget = index; + + if (m_keyboardOwner == lastEntryIndex) + m_keyboardOwner = index; } m_widgetBoxes.pop_back(); @@ -47,70 +54,78 @@ namespace Ndk void Canvas::OnEventMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event) { - if (m_hoveredWidget) + if (m_hoveredWidget != InvalidCanvasIndex) { - int x = static_cast(std::round(event.x - m_hoveredWidget->box.x)); - int y = static_cast(std::round(event.y - m_hoveredWidget->box.y)); + WidgetBox& hoveredWidget = m_widgetBoxes[m_hoveredWidget]; - m_hoveredWidget->widget->OnMouseButtonPress(x, y, event.button); + int x = static_cast(std::round(event.x - hoveredWidget.box.x)); + int y = static_cast(std::round(event.y - hoveredWidget.box.y)); + + hoveredWidget.widget->OnMouseButtonPress(x, y, event.button); } } void Canvas::OnEventMouseButtonRelease(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent & event) { - if (m_hoveredWidget) + if (m_hoveredWidget != InvalidCanvasIndex) { - int x = static_cast(std::round(event.x - m_hoveredWidget->box.x)); - int y = static_cast(std::round(event.y - m_hoveredWidget->box.y)); + WidgetBox& hoveredWidget = m_widgetBoxes[m_hoveredWidget]; - m_hoveredWidget->widget->OnMouseButtonRelease(x, y, event.button); + int x = static_cast(std::round(event.x - hoveredWidget.box.x)); + int y = static_cast(std::round(event.y - hoveredWidget.box.y)); + + hoveredWidget.widget->OnMouseButtonRelease(x, y, event.button); } } void Canvas::OnEventMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event) { - const WidgetBox* bestEntry = nullptr; + std::size_t bestEntry = InvalidCanvasIndex; float bestEntryArea = std::numeric_limits::infinity(); Nz::Vector3f mousePos(float(event.x), float(event.y), 0.f); - for (const WidgetBox& entry : m_widgetBoxes) + for (std::size_t i = 0; i < m_widgetBoxes.size(); ++i) { - const Nz::Boxf& box = entry.box; + const Nz::Boxf& box = m_widgetBoxes[i].box; if (box.Contains(mousePos)) { float area = box.width * box.height; if (area < bestEntryArea) { - bestEntry = &entry; + bestEntry = i; bestEntryArea = area; } } } - if (bestEntry) + if (bestEntry != InvalidCanvasIndex) { if (m_hoveredWidget != bestEntry) { - if (m_hoveredWidget) - m_hoveredWidget->widget->OnMouseExit(); + if (m_hoveredWidget != InvalidCanvasIndex) + { + WidgetBox& previouslyHovered = m_widgetBoxes[m_hoveredWidget]; + previouslyHovered.widget->OnMouseExit(); + } m_hoveredWidget = bestEntry; - m_hoveredWidget->widget->OnMouseEnter(); + m_widgetBoxes[m_hoveredWidget].widget->OnMouseEnter(); if (m_cursorController) - m_cursorController->UpdateCursor(Nz::Cursor::Get(m_hoveredWidget->cursor)); + m_cursorController->UpdateCursor(Nz::Cursor::Get(m_widgetBoxes[m_hoveredWidget].cursor)); } - int x = static_cast(std::round(event.x - m_hoveredWidget->box.x)); - int y = static_cast(std::round(event.y - m_hoveredWidget->box.y)); + WidgetBox& hoveredWidget = m_widgetBoxes[m_hoveredWidget]; - bestEntry->widget->OnMouseMoved(x, y, event.deltaX, event.deltaY); + int x = static_cast(std::round(event.x - hoveredWidget.box.x)); + int y = static_cast(std::round(event.y - hoveredWidget.box.y)); + hoveredWidget.widget->OnMouseMoved(x, y, event.deltaX, event.deltaY); } - else if (m_hoveredWidget) + else if (m_hoveredWidget != InvalidCanvasIndex) { - m_hoveredWidget->widget->OnMouseExit(); - m_hoveredWidget = nullptr; + m_widgetBoxes[m_hoveredWidget].widget->OnMouseExit(); + m_hoveredWidget = InvalidCanvasIndex; if (m_cursorController) m_cursorController->UpdateCursor(Nz::Cursor::Get(Nz::SystemCursor_Default)); @@ -119,28 +134,28 @@ namespace Ndk void Canvas::OnEventMouseLeft(const Nz::EventHandler* /*eventHandler*/) { - if (m_hoveredWidget) + if (m_hoveredWidget != InvalidCanvasIndex) { - m_hoveredWidget->widget->OnMouseExit(); - m_hoveredWidget = nullptr; + m_widgetBoxes[m_hoveredWidget].widget->OnMouseExit(); + m_hoveredWidget = InvalidCanvasIndex; } } void Canvas::OnEventKeyPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event) { - if (m_keyboardOwner) - m_keyboardOwner->OnKeyPressed(event); + if (m_keyboardOwner != InvalidCanvasIndex) + m_widgetBoxes[m_hoveredWidget].widget->OnKeyPressed(event); } void Canvas::OnEventKeyReleased(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event) { - if (m_keyboardOwner) - m_keyboardOwner->OnKeyReleased(event); + if (m_keyboardOwner != InvalidCanvasIndex) + m_widgetBoxes[m_hoveredWidget].widget->OnKeyReleased(event); } void Canvas::OnEventTextEntered(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::TextEvent& event) { - if (m_keyboardOwner) - m_keyboardOwner->OnTextEntered(event.character, event.repeated); + if (m_keyboardOwner != InvalidCanvasIndex) + m_widgetBoxes[m_hoveredWidget].widget->OnTextEntered(event.character, event.repeated); } } From 52033c8697ad7298f6ee765158ac1f9c857f901d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 6 Oct 2017 15:03:03 +0200 Subject: [PATCH 06/11] Package: Fix resource copy on Linux --- build/scripts/actions/package.lua | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/build/scripts/actions/package.lua b/build/scripts/actions/package.lua index 0797d5441..f1ddb5087 100644 --- a/build/scripts/actions/package.lua +++ b/build/scripts/actions/package.lua @@ -84,13 +84,13 @@ ACTION.Function = function () local libFileMasks local exeFileExt local exeFilterFunc - if (os.is("windows")) then + if (os.ishost("windows")) then binFileMasks = {"**.dll", "**.pdb"} libFileMasks = {"**.lib", "**.a"} exeFileExt = ".exe" exeFilterFunc = function (filePath) return true end else - if (os.is("macosx")) then + if (os.ishost("macosx")) then binFileMasks = {"**.dynlib"} else binFileMasks = {"**.so"} @@ -183,14 +183,7 @@ ACTION.Function = function () end end - local ok, err - if (os.is("windows")) then - ok, err = os.copyfile(v, targetPath) - else - -- Workaround: As premake is translating this to "cp %s %s", it fails if space are presents in source/destination paths. - ok, err = os.copyfile(string.format("\"%s\"", v), string.format("\"%s\"", targetPath)) - end - + local ok, err = os.copyfile(v, targetPath) if (not ok) then print("Failed to copy \"" .. v .. "\" to \"" .. targetPath .. "\": " .. err) end From 817064cbebb13945e8c873d16363976aff3c3b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 6 Oct 2017 15:18:37 +0200 Subject: [PATCH 07/11] Sdk/Algortihm: Fix 64bits shift --- SDK/include/NDK/Algorithm.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDK/include/NDK/Algorithm.inl b/SDK/include/NDK/Algorithm.inl index 54339ce38..39762243b 100644 --- a/SDK/include/NDK/Algorithm.inl +++ b/SDK/include/NDK/Algorithm.inl @@ -21,7 +21,7 @@ namespace Ndk static_assert(N-1 <= sizeof(ComponentId), "Name too long for this size of component id"); ComponentId componentId = 0; - for (unsigned int i = 0; i < N; ++i) + for (unsigned int i = 0; i < N - 1; ++i) componentId |= static_cast(name[i]) << i*8; return componentId; From 08645f669da74ba05e73cf7de95f4f18ba72c853 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 10 Oct 2017 18:29:15 +0200 Subject: [PATCH 08/11] Regenerate global headers --- SDK/include/NDK/Widgets.hpp | 1 + include/Nazara/Core.hpp | 1 + include/Nazara/Network.hpp | 1 + include/Nazara/Platform.hpp | 1 - include/Nazara/Renderer.hpp | 4 ++++ 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/SDK/include/NDK/Widgets.hpp b/SDK/include/NDK/Widgets.hpp index 2c3ba7dad..f2cce1559 100644 --- a/SDK/include/NDK/Widgets.hpp +++ b/SDK/include/NDK/Widgets.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/include/Nazara/Core.hpp b/include/Nazara/Core.hpp index 606d6969a..b4481b1a6 100644 --- a/include/Nazara/Core.hpp +++ b/include/Nazara/Core.hpp @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include diff --git a/include/Nazara/Network.hpp b/include/Nazara/Network.hpp index 151bc3f52..1b27049e6 100644 --- a/include/Nazara/Network.hpp +++ b/include/Nazara/Network.hpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/include/Nazara/Platform.hpp b/include/Nazara/Platform.hpp index fc2b3c0d3..51d4e0a32 100644 --- a/include/Nazara/Platform.hpp +++ b/include/Nazara/Platform.hpp @@ -45,4 +45,3 @@ #include #endif // NAZARA_GLOBAL_PLATFORM_HPP - diff --git a/include/Nazara/Renderer.hpp b/include/Nazara/Renderer.hpp index 159b990de..b586cea28 100644 --- a/include/Nazara/Renderer.hpp +++ b/include/Nazara/Renderer.hpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,10 @@ #include #include #include +#include +#include #include +#include #include #include #include From 75a5ccad2a1ce813af0062d977be1e5906f73d8f Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 10 Oct 2017 20:33:31 +0200 Subject: [PATCH 09/11] Physics2D: Add constraint support --- include/Nazara/Physics2D.hpp | 1 + include/Nazara/Physics2D/Constraint2D.hpp | 189 ++++++++++ include/Nazara/Physics2D/Constraint2D.inl | 13 + src/Nazara/Physics2D/Constraint2D.cpp | 424 ++++++++++++++++++++++ 4 files changed, 627 insertions(+) create mode 100644 include/Nazara/Physics2D/Constraint2D.hpp create mode 100644 include/Nazara/Physics2D/Constraint2D.inl create mode 100644 src/Nazara/Physics2D/Constraint2D.cpp diff --git a/include/Nazara/Physics2D.hpp b/include/Nazara/Physics2D.hpp index 2c908ca79..074578140 100644 --- a/include/Nazara/Physics2D.hpp +++ b/include/Nazara/Physics2D.hpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include diff --git a/include/Nazara/Physics2D/Constraint2D.hpp b/include/Nazara/Physics2D/Constraint2D.hpp new file mode 100644 index 000000000..761742348 --- /dev/null +++ b/include/Nazara/Physics2D/Constraint2D.hpp @@ -0,0 +1,189 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Physics 2D module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_CONSTRAINT2D_HPP +#define NAZARA_CONSTRAINT2D_HPP + +#include +#include +#include +#include +#include +#include + +struct cpConstraint; + +namespace Nz +{ + class NAZARA_PHYSICS2D_API Constraint2D + { + public: + Constraint2D(const Constraint2D&) = delete; + Constraint2D(Constraint2D&& rhs); + virtual ~Constraint2D(); + + void EnableBodyCollision(bool enable); + + RigidBody2D& GetBodyA(); + const RigidBody2D& GetBodyA() const; + RigidBody2D& GetBodyB(); + const RigidBody2D& GetBodyB() const; + float GetErrorBias() const; + float GetMaxBias() const; + float GetMaxForce() const; + PhysWorld2D& GetWorld(); + const PhysWorld2D& GetWorld() const; + + bool IsBodyCollisionEnabled() const; + + void SetErrorBias(float bias); + void SetMaxBias(float bias); + void SetMaxForce(float force); + + Constraint2D& operator=(const Constraint2D&) = delete; + Constraint2D& operator=(Constraint2D&& rhs); + + protected: + Constraint2D(PhysWorld2D& world, cpConstraint* constraint); + + MovablePtr m_constraint; + }; + + class NAZARA_PHYSICS2D_API DampedSpring2D : public Constraint2D + { + public: + DampedSpring2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float restLength, float stiffness, float damping); + ~DampedSpring2D() = default; + + float GetDamping() const; + Vector2f GetFirstAnchor() const; + float GetRestLength() const; + Vector2f GetSecondAnchor() const; + float GetStiffness() const; + + void SetDamping(float newDamping); + void SetFirstAnchor(const Vector2f& firstAnchor); + void SetRestLength(float newLength); + void SetSecondAnchor(const Vector2f& firstAnchor); + void SetStiffness(float newStiffness); + }; + + class NAZARA_PHYSICS2D_API DampedRotarySpring2D : public Constraint2D + { + public: + DampedRotarySpring2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping); + ~DampedRotarySpring2D() = default; + + float GetDamping() const; + float GetRestAngle() const; + float GetStiffness() const; + + void SetDamping(float newDamping); + void SetRestAngle(float newAngle); + void SetStiffness(float newStiffness); + }; + + class NAZARA_PHYSICS2D_API GearJoint2D : public Constraint2D + { + public: + GearJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratio); + ~GearJoint2D() = default; + + float GetPhase() const; + float GetRatio() const; + + void SetPhase(float phase); + void SetRatio(float ratio); + }; + + class NAZARA_PHYSICS2D_API MotorJoint2D : public Constraint2D + { + public: + MotorJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float rate); + ~MotorJoint2D() = default; + + float GetRate() const; + void SetRate(float rate); + }; + + class NAZARA_PHYSICS2D_API PinJoint2D : public Constraint2D + { + public: + PinJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor); + ~PinJoint2D() = default; + + float GetDistance() const; + Vector2f GetFirstAnchor() const; + Vector2f GetSecondAnchor() const; + + void SetDistance(float newDistance); + void SetFirstAnchor(const Vector2f& firstAnchor); + void SetSecondAnchor(const Vector2f& firstAnchor); + }; + + class NAZARA_PHYSICS2D_API PivotJoint2D : public Constraint2D + { + public: + PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor); + PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor); + ~PivotJoint2D() = default; + + Vector2f GetFirstAnchor() const; + Vector2f GetSecondAnchor() const; + + void SetFirstAnchor(const Vector2f& firstAnchor); + void SetSecondAnchor(const Vector2f& firstAnchor); + }; + + class NAZARA_PHYSICS2D_API RatchetJoint2D : public Constraint2D + { + public: + RatchetJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratchet); + ~RatchetJoint2D() = default; + + float GetAngle() const; + float GetPhase() const; + float GetRatchet() const; + + void SetAngle(float angle); + void SetPhase(float phase); + void SetRatchet(float ratchet); + }; + + class NAZARA_PHYSICS2D_API RotaryLimitJoint2D : public Constraint2D + { + public: + RotaryLimitJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle); + ~RotaryLimitJoint2D() = default; + + float GetMaxAngle() const; + float GetMinAngle() const; + + void SetMaxAngle(float maxAngle); + void SetMinAngle(float minAngle); + }; + + class NAZARA_PHYSICS2D_API SlideJoint2D : public Constraint2D + { + public: + SlideJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float min, float max); + ~SlideJoint2D() = default; + + Vector2f GetFirstAnchor() const; + float GetMaxDistance() const; + float GetMinDistance() const; + Vector2f GetSecondAnchor() const; + + void SetFirstAnchor(const Vector2f& firstAnchor); + void SetMaxDistance(float newMaxDistance); + void SetMinDistance(float newMinDistance); + void SetSecondAnchor(const Vector2f& firstAnchor); + }; +} + +#include + +#endif // NAZARA_CONSTRAINT2D_HPP diff --git a/include/Nazara/Physics2D/Constraint2D.inl b/include/Nazara/Physics2D/Constraint2D.inl new file mode 100644 index 000000000..2ed7744f3 --- /dev/null +++ b/include/Nazara/Physics2D/Constraint2D.inl @@ -0,0 +1,13 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Physics 2D module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +namespace Nz +{ +} + +#include diff --git a/src/Nazara/Physics2D/Constraint2D.cpp b/src/Nazara/Physics2D/Constraint2D.cpp new file mode 100644 index 000000000..39aa6a9f9 --- /dev/null +++ b/src/Nazara/Physics2D/Constraint2D.cpp @@ -0,0 +1,424 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Physics 2D module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +namespace Nz +{ + Constraint2D::Constraint2D(PhysWorld2D& world, cpConstraint* constraint) : + m_constraint(constraint) + { + cpConstraintSetUserData(m_constraint, this); + cpSpaceAddConstraint(world.GetHandle(), m_constraint); + } + + Constraint2D::Constraint2D(Constraint2D&& rhs) : + m_constraint(std::move(rhs.m_constraint)) + { + cpConstraintSetUserData(m_constraint, this); + } + + Constraint2D::~Constraint2D() + { + cpSpaceRemoveConstraint(cpConstraintGetSpace(m_constraint), m_constraint); + } + + void Constraint2D::EnableBodyCollision(bool enable) + { + cpConstraintSetCollideBodies(m_constraint, (enable) ? cpTrue : cpFalse); + } + + RigidBody2D& Constraint2D::GetBodyA() + { + return *static_cast(cpBodyGetUserData(cpConstraintGetBodyA(m_constraint))); + } + + const RigidBody2D& Constraint2D::GetBodyA() const + { + return *static_cast(cpBodyGetUserData(cpConstraintGetBodyA(m_constraint))); + } + + RigidBody2D& Constraint2D::GetBodyB() + { + return *static_cast(cpBodyGetUserData(cpConstraintGetBodyB(m_constraint))); + } + + const RigidBody2D& Constraint2D::GetBodyB() const + { + return *static_cast(cpBodyGetUserData(cpConstraintGetBodyB(m_constraint))); + } + + float Constraint2D::GetErrorBias() const + { + return float(cpConstraintGetErrorBias(m_constraint)); + } + + float Constraint2D::GetMaxBias() const + { + return float(cpConstraintGetMaxBias(m_constraint)); + } + + float Constraint2D::GetMaxForce() const + { + return float(cpConstraintGetMaxForce(m_constraint)); + } + + PhysWorld2D& Constraint2D::GetWorld() + { + return *static_cast(cpSpaceGetUserData(cpConstraintGetSpace(m_constraint))); + } + + const PhysWorld2D& Constraint2D::GetWorld() const + { + return *static_cast(cpSpaceGetUserData(cpConstraintGetSpace(m_constraint))); + } + + bool Constraint2D::IsBodyCollisionEnabled() const + { + return cpConstraintGetCollideBodies(m_constraint) == cpTrue; + } + + void Constraint2D::SetErrorBias(float bias) + { + cpConstraintSetErrorBias(m_constraint, bias); + } + + void Constraint2D::SetMaxBias(float bias) + { + cpConstraintSetMaxBias(m_constraint, bias); + } + + void Constraint2D::SetMaxForce(float force) + { + cpConstraintSetMaxForce(m_constraint, force); + } + + Constraint2D& Constraint2D::operator=(Constraint2D && rhs) + { + m_constraint = std::move(rhs.m_constraint); + cpConstraintSetUserData(m_constraint, this); + + return *this; + } + + + DampedSpring2D::DampedSpring2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float restLength, float stiffness, float damping) : + Constraint2D(world, cpDampedSpringNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), restLength, stiffness, damping)) + { + } + + float DampedSpring2D::GetDamping() const + { + return float(cpDampedSpringGetDamping(m_constraint)); + } + + Vector2f DampedSpring2D::GetFirstAnchor() const + { + cpVect anchor = cpDampedSpringGetAnchorA(m_constraint); + return Vector2f(static_cast(anchor.x), static_cast(anchor.y)); + } + + float DampedSpring2D::GetRestLength() const + { + return float(cpDampedSpringGetRestLength(m_constraint)); + } + + Vector2f DampedSpring2D::GetSecondAnchor() const + { + cpVect anchor = cpDampedSpringGetAnchorB(m_constraint); + return Vector2f(static_cast(anchor.x), static_cast(anchor.y)); + } + + float DampedSpring2D::GetStiffness() const + { + return float(cpDampedSpringGetStiffness(m_constraint)); + } + + void DampedSpring2D::SetDamping(float newDamping) + { + cpDampedSpringSetDamping(m_constraint, newDamping); + } + + void DampedSpring2D::SetFirstAnchor(const Vector2f& firstAnchor) + { + cpDampedSpringSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y)); + } + + void DampedSpring2D::SetRestLength(float newLength) + { + cpDampedSpringSetRestLength(m_constraint, newLength); + } + + void DampedSpring2D::SetSecondAnchor(const Vector2f& firstAnchor) + { + cpDampedSpringSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y)); + } + + void DampedSpring2D::SetStiffness(float newStiffness) + { + cpDampedSpringSetStiffness(m_constraint, newStiffness); + } + + + DampedRotarySpring2D::DampedRotarySpring2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping) : + Constraint2D(world, cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle, stiffness, damping)) + { + } + + float DampedRotarySpring2D::GetDamping() const + { + return float(cpDampedRotarySpringGetDamping(m_constraint)); + } + + float DampedRotarySpring2D::GetRestAngle() const + { + return float(cpDampedRotarySpringGetRestAngle(m_constraint)); + } + + float DampedRotarySpring2D::GetStiffness() const + { + return float(cpDampedRotarySpringGetStiffness(m_constraint)); + } + + void DampedRotarySpring2D::SetDamping(float newDamping) + { + cpDampedSpringSetDamping(m_constraint, newDamping); + } + + void DampedRotarySpring2D::SetRestAngle(float newAngle) + { + cpDampedRotarySpringSetRestAngle(m_constraint, newAngle); + } + + void DampedRotarySpring2D::SetStiffness(float newStiffness) + { + cpDampedRotarySpringSetStiffness(m_constraint, newStiffness); + } + + + GearJoint2D::GearJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratio) : + Constraint2D(world, cpGearJointNew(first.GetHandle(), second.GetHandle(), phase, ratio)) + { + } + + float GearJoint2D::GetPhase() const + { + return float(cpGearJointGetPhase(m_constraint)); + } + + float GearJoint2D::GetRatio() const + { + return float(cpGearJointGetRatio(m_constraint)); + } + + void GearJoint2D::SetPhase(float phase) + { + cpGearJointSetPhase(m_constraint, phase); + } + + void GearJoint2D::SetRatio(float ratio) + { + cpGearJointSetRatio(m_constraint, ratio); + } + + + MotorJoint2D::MotorJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float rate) : + Constraint2D(world, cpSimpleMotorNew(first.GetHandle(), second.GetHandle(), rate)) + { + } + + float MotorJoint2D::GetRate() const + { + return float(cpSimpleMotorGetRate(m_constraint)); + } + + void MotorJoint2D::SetRate(float rate) + { + cpSimpleMotorSetRate(m_constraint, rate); + } + + + PinJoint2D::PinJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor) : + Constraint2D(world, cpPinJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y))) + { + } + + float PinJoint2D::GetDistance() const + { + return float(cpPinJointGetDist(m_constraint)); + } + + Vector2f PinJoint2D::GetFirstAnchor() const + { + cpVect anchor = cpPinJointGetAnchorA(m_constraint); + return Vector2f(static_cast(anchor.x), static_cast(anchor.y)); + } + + Vector2f PinJoint2D::GetSecondAnchor() const + { + cpVect anchor = cpPinJointGetAnchorB(m_constraint); + return Vector2f(static_cast(anchor.x), static_cast(anchor.y)); + } + + void PinJoint2D::SetDistance(float newDistance) + { + cpPinJointSetDist(m_constraint, newDistance); + } + + void PinJoint2D::SetFirstAnchor(const Vector2f& firstAnchor) + { + cpPinJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y)); + } + + void PinJoint2D::SetSecondAnchor(const Vector2f& firstAnchor) + { + cpPinJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y)); + } + + + PivotJoint2D::PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor) : + Constraint2D(world, cpPivotJointNew(first.GetHandle(), second.GetHandle(), cpv(anchor.x, anchor.y))) + { + } + + PivotJoint2D::PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor) : + Constraint2D(world, cpPivotJointNew2(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y))) + { + } + + Vector2f PivotJoint2D::GetFirstAnchor() const + { + cpVect anchor = cpPivotJointGetAnchorA(m_constraint); + return Vector2f(static_cast(anchor.x), static_cast(anchor.y)); + } + + Vector2f PivotJoint2D::GetSecondAnchor() const + { + cpVect anchor = cpPivotJointGetAnchorB(m_constraint); + return Vector2f(static_cast(anchor.x), static_cast(anchor.y)); + } + + void PivotJoint2D::SetFirstAnchor(const Vector2f& firstAnchor) + { + cpPivotJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y)); + } + + void PivotJoint2D::SetSecondAnchor(const Vector2f& firstAnchor) + { + cpPivotJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y)); + } + + + RatchetJoint2D::RatchetJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratchet) : + Constraint2D(world, cpRatchetJointNew(first.GetHandle(), second.GetHandle(), phase, ratchet)) + { + } + + float RatchetJoint2D::GetAngle() const + { + return float(cpRatchetJointGetAngle(m_constraint)); + } + + float RatchetJoint2D::GetPhase() const + { + return float(cpRatchetJointGetPhase(m_constraint)); + } + + float RatchetJoint2D::GetRatchet() const + { + return float(cpRatchetJointGetRatchet(m_constraint)); + } + + void RatchetJoint2D::SetAngle(float angle) + { + cpRatchetJointSetAngle(m_constraint, angle); + } + + void RatchetJoint2D::SetPhase(float phase) + { + cpRatchetJointSetPhase(m_constraint, phase); + } + + void RatchetJoint2D::SetRatchet(float ratchet) + { + cpRatchetJointSetRatchet(m_constraint, ratchet); + } + + + RotaryLimitJoint2D::RotaryLimitJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle) : + Constraint2D(world, cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle, maxAngle)) + { + } + + float RotaryLimitJoint2D::GetMaxAngle() const + { + return float(cpRotaryLimitJointGetMax(m_constraint)); + } + + float RotaryLimitJoint2D::GetMinAngle() const + { + return float(cpRotaryLimitJointGetMax(m_constraint)); + } + + void RotaryLimitJoint2D::SetMaxAngle(float maxAngle) + { + cpRotaryLimitJointSetMax(m_constraint, maxAngle); + } + + void RotaryLimitJoint2D::SetMinAngle(float minAngle) + { + cpRotaryLimitJointSetMin(m_constraint, minAngle); + } + + + SlideJoint2D::SlideJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float min, float max) : + Constraint2D(world, cpSlideJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), min, max)) + { + } + + Vector2f SlideJoint2D::GetFirstAnchor() const + { + cpVect anchor = cpSlideJointGetAnchorA(m_constraint); + return Vector2f(static_cast(anchor.x), static_cast(anchor.y)); + } + + float SlideJoint2D::GetMaxDistance() const + { + return float(cpSlideJointGetMax(m_constraint)); + } + + float SlideJoint2D::GetMinDistance() const + { + return float(cpSlideJointGetMin(m_constraint)); + } + + Vector2f SlideJoint2D::GetSecondAnchor() const + { + cpVect anchor = cpSlideJointGetAnchorB(m_constraint); + return Vector2f(static_cast(anchor.x), static_cast(anchor.y)); + } + + void SlideJoint2D::SetFirstAnchor(const Vector2f& firstAnchor) + { + cpSlideJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y)); + } + + void SlideJoint2D::SetMaxDistance(float newMaxDistance) + { + cpSlideJointSetMax(m_constraint, newMaxDistance); + } + + void SlideJoint2D::SetMinDistance(float newMinDistance) + { + cpSlideJointSetMin(m_constraint, newMinDistance); + } + + void SlideJoint2D::SetSecondAnchor(const Vector2f& firstAnchor) + { + cpSlideJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y)); + } + +} From c5f7b36df189b98f0aca186047b76abc3eedd0a4 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 10 Oct 2017 20:56:54 +0200 Subject: [PATCH 10/11] Fix -Wignored-qualifiers warning --- include/Nazara/Utility/Algorithm.hpp | 2 +- include/Nazara/Utility/Algorithm.inl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Utility/Algorithm.hpp b/include/Nazara/Utility/Algorithm.hpp index aadec8aaa..9c275021d 100644 --- a/include/Nazara/Utility/Algorithm.hpp +++ b/include/Nazara/Utility/Algorithm.hpp @@ -67,7 +67,7 @@ namespace Nz NAZARA_UTILITY_API void TransformVertices(VertexPointers vertexPointers, unsigned int vertexCount, const Matrix4f& matrix); template constexpr ComponentType ComponentTypeId(); - template constexpr const ComponentType GetComponentTypeOf(); + template constexpr ComponentType GetComponentTypeOf(); } #include diff --git a/include/Nazara/Utility/Algorithm.inl b/include/Nazara/Utility/Algorithm.inl index 61bdb9e77..cc0a4fdc7 100644 --- a/include/Nazara/Utility/Algorithm.inl +++ b/include/Nazara/Utility/Algorithm.inl @@ -36,7 +36,7 @@ namespace Nz template<> constexpr ComponentType ComponentTypeId() { return ComponentType_Quaternion; } template - constexpr const ComponentType GetComponentTypeOf() + constexpr ComponentType GetComponentTypeOf() { return ComponentTypeId>(); } From bddc03c22846c11151d1261a003a10b7191c6bd6 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 10 Oct 2017 21:08:16 +0200 Subject: [PATCH 11/11] Fix demo compilation and warnings --- examples/Particles/LogoDemo.cpp | 2 +- include/Nazara/Utility/Algorithm.inl | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/Particles/LogoDemo.cpp b/examples/Particles/LogoDemo.cpp index ae30c6436..f35d3fa5e 100644 --- a/examples/Particles/LogoDemo.cpp +++ b/examples/Particles/LogoDemo.cpp @@ -231,7 +231,7 @@ bool LogoExample::Update(Ndk::StateMachine& fsm, float elapsedTime) ParticleData* sprite = static_cast(m_particles); for (std::size_t i = 0; i < m_pixels.size(); ++i) { - Nz::Vector2f particleToMouse = sprite[i].position - controller->actualMousePos; + Nz::Vector2f particleToMouse = Nz::Vector2f(sprite[i].position) - controller->actualMousePos; float sqDist = particleToMouse.GetSquaredLength(); if (sqDist < 10000.f) { diff --git a/include/Nazara/Utility/Algorithm.inl b/include/Nazara/Utility/Algorithm.inl index cc0a4fdc7..829276bfb 100644 --- a/include/Nazara/Utility/Algorithm.inl +++ b/include/Nazara/Utility/Algorithm.inl @@ -1,4 +1,6 @@ -#pragma once +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp #include #include @@ -42,4 +44,4 @@ namespace Nz } } -#include \ No newline at end of file +#include