diff --git a/Dockerfile b/Dockerfile index 0b9ee6567..b1ab55789 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM debian:buster -RUN apt-get update && apt-get install -y build-essential clang libopenal-dev libsndfile1-dev libfreetype6-dev libassimp-dev libsdl2-dev +RUN apt-get update && apt-get install -y build-essential clang libopenal-dev libsndfile1-dev libfreetype6-dev libassimp-dev libsdl2-dev libxcb-keysyms1-dev libxcb-ewmh-dev libx11-dev libfreetype6-dev mesa-common-dev libgl1-mesa-dev RUN mkdir /NazaraEngine WORKDIR /NazaraEngine \ No newline at end of file diff --git a/build/scripts/modules/platform.lua b/build/scripts/modules/platform.lua index 9a04ca3e8..e3be1e0be 100644 --- a/build/scripts/modules/platform.lua +++ b/build/scripts/modules/platform.lua @@ -16,3 +16,12 @@ MODULE.Files = { "../src/Nazara/Platform/SDL2/**.hpp", "../src/Nazara/Platform/SDL2/**.cpp" } + +MODULE.OsDefines.Windows = { + "SDL_VIDEO_DRIVER_WINDOWS=1" +} + +MODULE.OsDefines.Posix = { + "SDL_VIDEO_DRIVER_X11=1", + "SDL_VIDEO_DRIVER_WAYLAND=1", +} diff --git a/build/scripts/modules/renderer.lua b/build/scripts/modules/renderer.lua index 2e3a6619a..f371bc5d1 100644 --- a/build/scripts/modules/renderer.lua +++ b/build/scripts/modules/renderer.lua @@ -18,4 +18,3 @@ MODULE.OsFiles.Posix = { "../src/Nazara/Renderer/GLX/**.hpp", "../src/Nazara/Renderer/GLX/**.cpp" } - diff --git a/examples/Particles/SpacebattleDemo.cpp b/examples/Particles/SpacebattleDemo.cpp index 375749f5e..4b8dc12fd 100644 --- a/examples/Particles/SpacebattleDemo.cpp +++ b/examples/Particles/SpacebattleDemo.cpp @@ -674,10 +674,14 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm) Nz::Boxf introAABB = introGfx.GetAABB(); introNode.SetPosition(cannonNode.GetForward() * 500.f + introNode.GetLeft() * introAABB.width / 2.f + introNode.GetUp() * introAABB.height / 2.f); + + Nz::Mouse::SetRelativeMouseMode(true); } void SpacebattleExample::Leave(Ndk::StateMachine& fsm) { + Nz::Mouse::SetRelativeMouseMode(false); + m_ambientMusic.Stop(); m_onMouseMoved.Disconnect(); if (m_shared.target) @@ -836,7 +840,4 @@ void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* /*eventHandler*/, m_turretCannonBaseRotation = Nz::Clamp(m_turretCannonBaseRotation + speed * event.deltaY, -65.f, 40.f); m_turretBaseRotation -= event.deltaX * speed; - - Nz::Vector2ui size = m_shared.target->GetSize(); - Nz::Mouse::SetPosition(size.x / 2, size.y / 2, *m_shared.target); } diff --git a/include/Nazara/Math/Quaternion.hpp b/include/Nazara/Math/Quaternion.hpp index 991b23b94..e26149573 100644 --- a/include/Nazara/Math/Quaternion.hpp +++ b/include/Nazara/Math/Quaternion.hpp @@ -60,6 +60,7 @@ namespace Nz T SquaredMagnitude() const; + RadianAngle To2DAngle() const; EulerAngles ToEulerAngles() const; //Matrix3 ToRotationMatrix() const; String ToString() const; diff --git a/include/Nazara/Math/Quaternion.inl b/include/Nazara/Math/Quaternion.inl index 7da2c4635..130604814 100644 --- a/include/Nazara/Math/Quaternion.inl +++ b/include/Nazara/Math/Quaternion.inl @@ -463,13 +463,27 @@ namespace Nz return w * w + x * x + y * y + z * z; } + /*! + * \brief Returns the "roll angle" of this quaternion + * \return Roll rotation + * + * \remark This function only has sense when quaternion only represents a "roll rotation" + */ + template + RadianAngle Quaternion::To2DAngle() const + { + T siny_cosp = T(2.0) * (w * z + x * y); + T cosy_cosp = T(1.0) - T(2.0) * (y * y + z * z); + + return std::atan2(siny_cosp, cosy_cosp); + } + /*! * \brief Converts this quaternion to Euler angles representation * \return EulerAngles which is the representation of this rotation * * \remark Rotation are "left-handed" */ - template EulerAngles Quaternion::ToEulerAngles() const { diff --git a/include/Nazara/Platform/WindowHandle.hpp b/include/Nazara/Platform/WindowHandle.hpp index 7982d902f..3d8121ef7 100644 --- a/include/Nazara/Platform/WindowHandle.hpp +++ b/include/Nazara/Platform/WindowHandle.hpp @@ -14,7 +14,7 @@ namespace Nz { enum class WindowManager { - None, + Invalid, X11, Wayland, @@ -23,14 +23,14 @@ namespace Nz struct WindowHandle { - WindowManager type = WindowManager::None; + WindowManager type = WindowManager::Invalid; union { struct { void* display; //< Display* - void* window; //< Window + unsigned long window; //< Window } x11; struct diff --git a/include/Nazara/Prerequisites.hpp b/include/Nazara/Prerequisites.hpp index 24bc14dc1..4187f4c3d 100644 --- a/include/Nazara/Prerequisites.hpp +++ b/include/Nazara/Prerequisites.hpp @@ -119,6 +119,8 @@ #define NAZARA_PLATFORM_LINUX #define NAZARA_PLATFORM_POSIX + #define NAZARA_PLATFORM_GLX + #define NAZARA_EXPORT __attribute__((visibility ("default"))) #define NAZARA_IMPORT __attribute__((visibility ("default"))) /*#elif defined(__APPLE__) && defined(__MACH__) diff --git a/include/NazaraSDK/Components/PhysicsComponent2D.hpp b/include/NazaraSDK/Components/PhysicsComponent2D.hpp index 66c034537..89aeb8dfd 100644 --- a/include/NazaraSDK/Components/PhysicsComponent2D.hpp +++ b/include/NazaraSDK/Components/PhysicsComponent2D.hpp @@ -99,6 +99,8 @@ namespace Ndk void OnComponentDetached(BaseComponent& component) override; void OnDetached() override; void OnEntityDestruction() override; + void OnEntityDisabled() override; + void OnEntityEnabled() override; struct PendingPhysObjectStates { diff --git a/src/Nazara/Physics2D/RigidBody2D.cpp b/src/Nazara/Physics2D/RigidBody2D.cpp index 656fdb03f..130194257 100644 --- a/src/Nazara/Physics2D/RigidBody2D.cpp +++ b/src/Nazara/Physics2D/RigidBody2D.cpp @@ -168,9 +168,9 @@ namespace Nz void RigidBody2D::EnableSimulation(bool simulation) { - if (m_isRegistered != simulation) + if (m_isSimulationEnabled != simulation) { - m_isRegistered = simulation; + m_isSimulationEnabled = simulation; if (simulation) RegisterToSpace(); @@ -325,7 +325,7 @@ namespace Nz bool RigidBody2D::IsSimulationEnabled() const { - return m_isRegistered; + return m_isSimulationEnabled; } bool RigidBody2D::IsSleeping() const diff --git a/src/Nazara/Platform/SDL2/WindowImpl.cpp b/src/Nazara/Platform/SDL2/WindowImpl.cpp index 6ca5857d3..c4fe1076b 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.cpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.cpp @@ -126,7 +126,7 @@ namespace Nz bool WindowImpl::Create(void* handle) { m_handle = SDL_CreateWindowFrom(handle); - if (!m_handle || !SDL_GetWindowID(m_handle)) + if (!m_handle) { NazaraError("Invalid handle"); return false; @@ -286,7 +286,8 @@ namespace Nz void WindowImpl::ProcessEvents(bool block) { - SDL_PumpEvents(); + if (m_ownsWindow) + SDL_PumpEvents(); /*if (m_ownsWindow) diff --git a/src/Nazara/Renderer/GLX/ContextImpl.cpp b/src/Nazara/Renderer/GLX/ContextImpl.cpp index d7a4fa425..572c6eace 100644 --- a/src/Nazara/Renderer/GLX/ContextImpl.cpp +++ b/src/Nazara/Renderer/GLX/ContextImpl.cpp @@ -141,7 +141,7 @@ namespace Nz } // If context is shared by multiple windows - if (parameters.window) + if (parameters.window.type != WindowManager::Invalid) { NazaraAssert(parameters.window.type == WindowManager::X11, "Cannot create a context for a non-x11 window"); diff --git a/src/Nazara/Renderer/GLX/Display.cpp b/src/Nazara/Renderer/GLX/Display.cpp new file mode 100644 index 000000000..647e22f19 --- /dev/null +++ b/src/Nazara/Renderer/GLX/Display.cpp @@ -0,0 +1,246 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +namespace Nz +{ + namespace + { + // The shared display and its reference counter + xcb_connection_t* sharedConnection = nullptr; + int screen_nbr = 0; + unsigned int referenceCountConnection = 0; + + xcb_key_symbols_t* sharedkeySymbol = nullptr; + unsigned int referenceCountKeySymbol = 0; + + xcb_ewmh_connection_t* sharedEwmhConnection = nullptr; + unsigned int referenceCountEwmhConnection = 0; + + using AtomMap = std::unordered_map; + AtomMap atoms; + } + + bool X11::CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie) + { + ScopedXCB error(xcb_request_check( + connection, + cookie + )); + + if (error) + return false; + else + return true; + } + + void X11::CloseConnection(xcb_connection_t* connection) + { + NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); + --referenceCountConnection; + } + + void X11::CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection) + { + NazaraAssert(ewmh_connection == sharedEwmhConnection, "The model is meant for one connection to X11 server"); + --referenceCountEwmhConnection; + } + + xcb_atom_t X11::GetAtom(const std::string& name, bool onlyIfExists) + { + auto iter = atoms.find(name); + + if (iter != atoms.end()) + return iter->second; + + ScopedXCB error(nullptr); + + xcb_connection_t* connection = OpenConnection(); + + ScopedXCB reply(xcb_intern_atom_reply( + connection, + xcb_intern_atom( + connection, + onlyIfExists, + name.size(), + name.data() + ), + &error + )); + + CloseConnection(connection); + + if (error || !reply) + { + NazaraError("Failed to get " + name + " atom."); + return XCB_ATOM_NONE; + } + + atoms[name] = reply->atom; + + return reply->atom; + } + + bool X11::Initialize() + { + if (IsInitialized()) + { + s_moduleReferenceCounter++; + return true; // Déjà initialisé + } + + s_moduleReferenceCounter++; + + NazaraAssert(referenceCountConnection == 0, "Initialize should be called before anything"); + NazaraAssert(referenceCountKeySymbol == 0, "Initialize should be called before anything"); + NazaraAssert(referenceCountEwmhConnection == 0, "Initialize should be called before anything"); + + { + sharedConnection = xcb_connect(nullptr, &screen_nbr); + + // Opening display failed: The best we can do at the moment is to output a meaningful error message + if (!sharedConnection || xcb_connection_has_error(sharedConnection)) + { + NazaraError("Failed to open xcb connection"); + return false; + } + + OpenConnection(); + } + + { + sharedkeySymbol = xcb_key_symbols_alloc(sharedConnection); + + XCBKeySymbolsAlloc(sharedConnection); + } + + { + sharedEwmhConnection = new xcb_ewmh_connection_t; + xcb_intern_atom_cookie_t* ewmh_cookie = xcb_ewmh_init_atoms(sharedConnection, sharedEwmhConnection); + + if(!xcb_ewmh_init_atoms_replies(sharedEwmhConnection, ewmh_cookie, nullptr)) + { + NazaraError("Could not initialize EWMH Connection"); + sharedEwmhConnection = nullptr; + } + + OpenEWMHConnection(sharedConnection); + } + + return true; + } + + bool X11::IsInitialized() + { + return s_moduleReferenceCounter != 0; + } + + xcb_key_symbols_t* X11::XCBKeySymbolsAlloc(xcb_connection_t* connection) + { + NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); + + ++referenceCountKeySymbol; + return sharedkeySymbol; + } + + void X11::XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols) + { + NazaraAssert(keySymbols == sharedkeySymbol, "The model is meant for one connection to X11 server"); + + --referenceCountKeySymbol; + } + + xcb_connection_t* X11::OpenConnection() + { + ++referenceCountConnection; + return sharedConnection; + } + + xcb_ewmh_connection_t* X11::OpenEWMHConnection(xcb_connection_t* connection) + { + NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); + + ++referenceCountEwmhConnection; + return sharedEwmhConnection; + } + + void X11::Uninitialize() + { + if (s_moduleReferenceCounter != 1) + { + // Le module est soit encore utilisé, soit pas initialisé + if (s_moduleReferenceCounter > 1) + s_moduleReferenceCounter--; + + return; + } + + s_moduleReferenceCounter = 0; + + { + NazaraAssert(referenceCountEwmhConnection == 1, "Uninitialize should be called after anything or a close is missing"); + CloseEWMHConnection(sharedEwmhConnection); + + xcb_ewmh_connection_wipe(sharedEwmhConnection); + delete sharedEwmhConnection; + } + + { + NazaraAssert(referenceCountKeySymbol == 1, "Uninitialize should be called after anything or a free is missing"); + XCBKeySymbolsFree(sharedkeySymbol); + + xcb_key_symbols_free(sharedkeySymbol); + } + + { + NazaraAssert(referenceCountConnection == 1, "Uninitialize should be called after anything or a close is missing"); + CloseConnection(sharedConnection); + + xcb_disconnect(sharedConnection); + } + } + + xcb_window_t X11::XCBDefaultRootWindow(xcb_connection_t* connection) + { + NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); + xcb_screen_t* screen = XCBDefaultScreen(connection); + if (screen) + return screen->root; + return XCB_NONE; + } + + xcb_screen_t* X11::XCBDefaultScreen(xcb_connection_t* connection) + { + NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); + return XCBScreenOfDisplay(connection, screen_nbr); + } + + int X11::XCBScreen(xcb_connection_t* connection) + { + NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); + return screen_nbr; + } + + xcb_screen_t* X11::XCBScreenOfDisplay(xcb_connection_t* connection, int screenIndex) + { + NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); + xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection)); + + for (; iter.rem; --screenIndex, xcb_screen_next (&iter)) + { + if (screenIndex == 0) + return iter.data; + } + + return nullptr; + } + + unsigned int X11::s_moduleReferenceCounter = 0; +} diff --git a/src/Nazara/Renderer/GLX/Display.hpp b/src/Nazara/Renderer/GLX/Display.hpp new file mode 100644 index 000000000..95161914f --- /dev/null +++ b/src/Nazara/Renderer/GLX/Display.hpp @@ -0,0 +1,53 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_X11DISPLAY_HPP +#define NAZARA_X11DISPLAY_HPP + +#include +#include +#include +#include +#include + +typedef struct _XCBKeySymbols xcb_key_symbols_t; + +namespace Nz +{ + class NAZARA_PLATFORM_API X11 + { + public: + X11() = delete; + ~X11() = delete; + + static bool CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie); + static void CloseConnection(xcb_connection_t* connection); + static void CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection); + + static xcb_atom_t GetAtom(const std::string& name, bool onlyIfExists = false); + + static bool Initialize(); + static bool IsInitialized(); + + static xcb_key_symbols_t* XCBKeySymbolsAlloc(xcb_connection_t* connection); + static void XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols); + + static xcb_connection_t* OpenConnection(); + static xcb_ewmh_connection_t* OpenEWMHConnection(xcb_connection_t* connection); + + static void Uninitialize(); + + static xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection); + static xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection); + static int XCBScreen(xcb_connection_t* connection); + static xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr); + + private: + static unsigned int s_moduleReferenceCounter; + }; +} + +#endif // NAZARA_X11DISPLAY_HPP diff --git a/src/Nazara/Renderer/GLX/ScopedXCB.cpp b/src/Nazara/Renderer/GLX/ScopedXCB.cpp new file mode 100644 index 000000000..35e19cd79 --- /dev/null +++ b/src/Nazara/Renderer/GLX/ScopedXCB.cpp @@ -0,0 +1,111 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +namespace Nz +{ + /*********************************************** + ScopedXCBConnection + ***********************************************/ + + ScopedXCBConnection::ScopedXCBConnection() : + m_connection(nullptr) + { + m_connection = X11::OpenConnection(); + } + + ScopedXCBConnection::~ScopedXCBConnection() + { + X11::CloseConnection(m_connection); + } + + ScopedXCBConnection::operator xcb_connection_t*() const + { + return m_connection; + } + + /*********************************************** + ScopedXCBEWMHConnection + ***********************************************/ + + ScopedXCBEWMHConnection::ScopedXCBEWMHConnection(xcb_connection_t* connection) : + m_ewmhConnection(nullptr) + { + m_ewmhConnection = X11::OpenEWMHConnection(connection); + } + + ScopedXCBEWMHConnection::~ScopedXCBEWMHConnection() + { + X11::CloseEWMHConnection(m_ewmhConnection); + } + + xcb_ewmh_connection_t* ScopedXCBEWMHConnection::operator ->() const + { + return m_ewmhConnection; + } + + ScopedXCBEWMHConnection::operator xcb_ewmh_connection_t*() const + { + return m_ewmhConnection; + } + + /*********************************************** + XCBGContext + ***********************************************/ + + XCBGContext::XCBGContext(xcb_connection_t* connection) : + m_connection(connection), + m_gcontext(XCB_NONE) + { + NazaraAssert(connection, "Connection must have been established"); + } + + XCBGContext::~XCBGContext() + { + Destroy(); + } + + bool XCBGContext::Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list) + { + NazaraAssert(m_gcontext == XCB_NONE, "Context must have been destroyed before or just created"); + + m_gcontext = xcb_generate_id(m_connection); + + return X11::CheckCookie( + m_connection, + xcb_create_gc( + m_connection, + m_gcontext, + drawable, + value_mask, + value_list + )); + } + + void XCBGContext::Destroy() + { + if (m_gcontext == XCB_NONE) + return; + + if (!X11::CheckCookie( + m_connection, + xcb_free_gc( + m_connection, + m_gcontext + )) + ) + NazaraError("Failed to free gcontext"); + + m_gcontext = XCB_NONE; + } + + XCBGContext::operator xcb_gcontext_t() const + { + return m_gcontext; + } +} diff --git a/src/Nazara/Renderer/GLX/ScopedXCB.hpp b/src/Nazara/Renderer/GLX/ScopedXCB.hpp new file mode 100644 index 000000000..b7c2c1fd2 --- /dev/null +++ b/src/Nazara/Renderer/GLX/ScopedXCB.hpp @@ -0,0 +1,81 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_SCOPEDXCB_HPP +#define NAZARA_SCOPEDXCB_HPP + +#include +#include +#include +#include + +namespace Nz +{ + class ScopedXCBConnection + { + public: + ScopedXCBConnection(); + ~ScopedXCBConnection(); + + operator xcb_connection_t*() const; + + private: + xcb_connection_t* m_connection; + }; + + class ScopedXCBEWMHConnection + { + public: + ScopedXCBEWMHConnection(xcb_connection_t* connection); + ~ScopedXCBEWMHConnection(); + + xcb_ewmh_connection_t* operator ->() const; + + operator xcb_ewmh_connection_t*() const; + + private: + xcb_ewmh_connection_t* m_ewmhConnection; + }; + + template + class ScopedXCB + { + public: + ScopedXCB(T* pointer); + ~ScopedXCB(); + + T* operator ->() const; + T** operator &(); + + operator bool() const; + + T* get() const; + + private: + T* m_pointer; + }; + + class XCBGContext + { + public: + XCBGContext(xcb_connection_t* connection); + ~XCBGContext(); + + bool Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list); + + void Destroy(); + + operator xcb_gcontext_t() const; + + private: + xcb_connection_t* m_connection; + xcb_gcontext_t m_gcontext; + }; +} + +#include + +#endif // NAZARA_SCOPEDXCB_HPP diff --git a/src/Nazara/Renderer/GLX/ScopedXCB.inl b/src/Nazara/Renderer/GLX/ScopedXCB.inl new file mode 100644 index 000000000..b25ae1178 --- /dev/null +++ b/src/Nazara/Renderer/GLX/ScopedXCB.inl @@ -0,0 +1,46 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include + +namespace Nz +{ + template + ScopedXCB::ScopedXCB(T* pointer) : + m_pointer(pointer) + { + } + + template + ScopedXCB::~ScopedXCB() + { + std::free(m_pointer); + } + + template + T* ScopedXCB::operator ->() const + { + return m_pointer; + } + + template + T** ScopedXCB::operator &() + { + return &m_pointer; + } + + template + ScopedXCB::operator bool() const + { + return m_pointer != nullptr; + } + + template + T* ScopedXCB::get() const + { + return m_pointer; + } +} + +#include diff --git a/src/NazaraSDK/Components/PhysicsComponent2D.cpp b/src/NazaraSDK/Components/PhysicsComponent2D.cpp index 5c2de1abb..d932c3de7 100644 --- a/src/NazaraSDK/Components/PhysicsComponent2D.cpp +++ b/src/NazaraSDK/Components/PhysicsComponent2D.cpp @@ -51,9 +51,15 @@ namespace Ndk m_object = std::make_unique(&world, 1.f, geom); m_object->SetPositionOffset(positionOffset); - m_object->SetPosition(Nz::Vector2f(matrix.GetTranslation())); m_object->SetUserdata(reinterpret_cast(static_cast(m_entity->GetId()))); + if (m_entity->HasComponent()) + { + auto& entityNode = m_entity->GetComponent(); + m_object->SetPosition(Nz::Vector2f(entityNode.GetPosition())); + m_object->SetRotation(entityNode.GetRotation().To2DAngle()); + } + if (m_pendingStates.valid) ApplyPhysicsState(*m_object); } @@ -111,5 +117,19 @@ namespace Ndk m_object.reset(); } + void PhysicsComponent2D::OnEntityDisabled() + { + NazaraAssert(m_object, "Invalid physics object"); + + m_object->EnableSimulation(false); + } + + void PhysicsComponent2D::OnEntityEnabled() + { + NazaraAssert(m_object, "Invalid physics object"); + + m_object->EnableSimulation(true); + } + ComponentIndex PhysicsComponent2D::componentIndex; } diff --git a/src/NazaraSDK/Systems/PhysicsSystem2D.cpp b/src/NazaraSDK/Systems/PhysicsSystem2D.cpp index 86c9e69d3..263296903 100644 --- a/src/NazaraSDK/Systems/PhysicsSystem2D.cpp +++ b/src/NazaraSDK/Systems/PhysicsSystem2D.cpp @@ -249,19 +249,16 @@ namespace Ndk else body->SetVelocity(Nz::Vector2f::Zero()); - /*if (newRotation != oldRotation) - { - Nz::Quaternionf transition = newRotation * oldRotation.GetConjugate(); - Nz::EulerAnglesf angles = transition.ToEulerAngles(); - Nz::Vector3f angularVelocity(Nz::ToRadians(angles.pitch * invElapsedTime), - Nz::ToRadians(angles.yaw * invElapsedTime), - Nz::ToRadians(angles.roll * invElapsedTime)); + Nz::RadianAnglef oldRotation = body->GetRotation(); + Nz::RadianAnglef newRotation = node.GetRotation(Nz::CoordSys_Global).To2DAngle(); - physObj->SetRotation(oldRotation); - physObj->SetAngularVelocity(angularVelocity); + if (newRotation != oldRotation) + { + body->SetRotation(oldRotation); + body->SetAngularVelocity((newRotation - oldRotation) * invElapsedTime); } else - physObj->SetAngularVelocity(Nz::Vector3f::Zero());*/ + body->SetAngularVelocity(Nz::RadianAnglef::Zero()); } } diff --git a/thirdparty/build/lua.lua b/thirdparty/build/lua.lua index eac1edcac..76281076a 100644 --- a/thirdparty/build/lua.lua +++ b/thirdparty/build/lua.lua @@ -8,3 +8,11 @@ LIBRARY.Files = { "../thirdparty/src/Lua/*.h", "../thirdparty/src/Lua/*.cpp" } + +LIBRARY.OsDefines.Windows = { + "LUA_USE_WINDOWS" +} + +LIBRARY.OsDefines.Posix = { + "LUA_USE_LINUX" +} diff --git a/thirdparty/include/SDL2/SDL_config.h b/thirdparty/include/SDL2/SDL_config.h index f269bfc04..efebe9f02 100644 --- a/thirdparty/include/SDL2/SDL_config.h +++ b/thirdparty/include/SDL2/SDL_config.h @@ -214,7 +214,6 @@ typedef unsigned int uintptr_t; /* Enable various video drivers */ #define SDL_VIDEO_DRIVER_DUMMY 1 -#define SDL_VIDEO_DRIVER_WINDOWS 1 #ifndef SDL_VIDEO_RENDER_D3D #define SDL_VIDEO_RENDER_D3D 1