Merge remote-tracking branch 'refs/remotes/origin/master' into reflection-mapping

This commit is contained in:
Lynix 2017-04-17 23:42:21 +02:00
commit 1305e8434a
13 changed files with 155 additions and 39 deletions

View File

@ -29,6 +29,7 @@ namespace Ndk
virtual std::unique_ptr<BaseComponent> Clone() const = 0;
inline const EntityHandle& GetEntity() const;
ComponentIndex GetIndex() const;
inline static ComponentIndex GetMaxComponentIndex();

View File

@ -19,11 +19,19 @@ namespace Ndk
{
}
/*!
* \brief Gets the entity owning this component
* \return A handle to the entity owning this component, may be invalid if no entity owns it.
*/
inline const EntityHandle& BaseComponent::GetEntity() const
{
return m_entity;
}
/*!
* \brief Gets the index of the component
* \return Index of the component
*/
inline ComponentIndex BaseComponent::GetIndex() const
{
return m_componentIndex;

View File

@ -85,8 +85,8 @@ ACTION.Function = function ()
local exeFileExt
local exeFilterFunc
if (os.is("windows")) then
binFileMasks = {"**.dll"}
libFileMasks = {"**.lib", "**.a", "**.pdb"}
binFileMasks = {"**.dll", "**.pdb"}
libFileMasks = {"**.lib", "**.a"}
exeFileExt = ".exe"
exeFilterFunc = function (filePath) return true end
else

View File

@ -1,4 +1,4 @@
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel-01---Hello-World
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World
#include <Nazara/Graphics.hpp>
#include <Nazara/Renderer.hpp>

11
examples/Tut02/build.lua Normal file
View File

@ -0,0 +1,11 @@
EXAMPLE.Name = "Tut02_Events"
EXAMPLE.EnableConsole = true
EXAMPLE.Files = {
"main.cpp"
}
EXAMPLE.Libraries = {
"NazaraSDK"
}

50
examples/Tut02/main.cpp Normal file
View File

@ -0,0 +1,50 @@
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B02%5D-Gestion-des-événements
#include <Nazara/Graphics.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <NDK/Application.hpp>
#include <NDK/Components.hpp>
#include <NDK/Systems.hpp>
#include <NDK/World.hpp>
#include <iostream>
int main(int argc, char* argv[])
{
Ndk::Application application(argc, argv);
Nz::RenderWindow& mainWindow = application.AddWindow<Nz::RenderWindow>();
mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test");
mainWindow.EnableCloseOnQuit(false);
Ndk::World& world = application.AddWorld();
world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214)));
Ndk::EntityHandle viewEntity = world.CreateEntity();
viewEntity->AddComponent<Ndk::NodeComponent>();
Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
viewer.SetTarget(&mainWindow);
viewer.SetProjectionType(Nz::ProjectionType_Orthogonal);
Nz::EventHandler& eventHandler = mainWindow.GetEventHandler();
eventHandler.OnKeyPressed.Connect([](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e)
{
std::cout << Nz::Keyboard::GetKeyName(e.code) << std::endl;
// Profitons-en aussi pour nous donner un moyen de quitter le programme
if (e.code == Nz::Keyboard::Escape)
Ndk::Application::Instance()->Quit(); // Cette ligne casse la boucle Run() de l'application
});
while (application.Run())
{
mainWindow.Display();
}
return EXIT_SUCCESS;
}

View File

@ -128,6 +128,9 @@ namespace Nz
template<typename T>
void ObjectHandle<T>::Reset(ObjectHandle&& handle) noexcept
{
if (this == &handle)
return;
if (m_object)
m_object->UnregisterHandle(this);

View File

@ -31,7 +31,7 @@ namespace Nz
public:
LuaInstance();
LuaInstance(const LuaInstance&) = delete;
inline LuaInstance(LuaInstance&& instance) noexcept;
LuaInstance(LuaInstance&& instance) noexcept;
~LuaInstance();
void ArgCheck(bool condition, unsigned int argNum, const char* error) const;
@ -173,7 +173,7 @@ namespace Nz
void* ToUserdata(int index, const String& tname) const;
LuaInstance& operator=(const LuaInstance&) = delete;
inline LuaInstance& operator=(LuaInstance&& instance) noexcept;
LuaInstance& operator=(LuaInstance&& instance) noexcept;
static int GetIndexOfUpValue(int upValue);
static LuaInstance* GetInstance(lua_State* state);

View File

@ -7,6 +7,7 @@
#include <Nazara/Core/Flags.hpp>
#include <Nazara/Core/MemoryHelper.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <limits>
#include <string>
#include <vector>
@ -14,18 +15,6 @@
namespace Nz
{
inline LuaInstance::LuaInstance(LuaInstance&& instance) noexcept :
m_memoryLimit(instance.m_memoryLimit),
m_memoryUsage(instance.m_memoryUsage),
m_timeLimit(instance.m_timeLimit),
m_clock(std::move(instance.m_clock)),
m_lastError(std::move(instance.m_lastError)),
m_state(instance.m_state),
m_level(instance.m_level)
{
instance.m_state = nullptr;
}
inline lua_State* LuaInstance::GetInternalState() const
{
return m_state;
@ -51,21 +40,6 @@ namespace Nz
return m_timeLimit;
}
inline LuaInstance& LuaInstance::operator=(LuaInstance&& instance) noexcept
{
m_clock = std::move(instance.m_clock);
m_lastError = std::move(instance.m_lastError);
m_level = instance.m_level;
m_memoryLimit = instance.m_memoryLimit;
m_memoryUsage = instance.m_memoryUsage;
m_state = instance.m_state;
m_timeLimit = instance.m_timeLimit;
instance.m_state = nullptr;
return *this;
}
// Functions args
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, bool* arg, TypeTag<bool>)
{

View File

@ -97,6 +97,29 @@ namespace Nz
return 0;
}
template<typename T> /*constexpr*/ std::enable_if_t<!std::is_signed<T>::value || !std::is_integral<T>::value, bool> NumberEquals(T a, T b, T maxDifference)
{
if (b > a)
std::swap(a, b);
T diff = a - b;
return diff <= maxDifference;
}
template<typename T> /*constexpr*/ std::enable_if_t<std::is_signed<T>::value && std::is_integral<T>::value, bool> NumberEquals(T a, T b, T maxDifference)
{
if (b > a)
std::swap(a, b);
if ((b < 0) && (a > std::numeric_limits<T>::max() + b))
return false;
if ((b > 0) && (a < std::numeric_limits<T>::min() + b))
return false;
return std::abs(a - b) <= maxDifference;
}
}
/*!
@ -565,11 +588,7 @@ namespace Nz
//TODO: Mark as constexpr when supported by all major compilers
/*constexpr*/ inline bool NumberEquals(T a, T b, T maxDifference)
{
if (b > a)
std::swap(a, b);
T diff = a - b;
return diff <= maxDifference;
return Detail::NumberEquals(a, b, maxDifference);
}
/*!

View File

@ -49,6 +49,8 @@ namespace Nz
bool RaycastQuery(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<RaycastHit>* hitInfos);
bool RaycastQueryFirst(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RaycastHit* hitInfo = nullptr);
void RegionQuery(const Nz::Rectf& boundingBox, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<Nz::RigidBody2D*>* bodies);
void RegisterCallbacks(unsigned int collisionId, const Callback& callbacks);
void RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, const Callback& callbacks);

View File

@ -143,6 +143,20 @@ namespace Nz
luaL_openlibs(m_state);
}
LuaInstance::LuaInstance(LuaInstance&& instance) noexcept :
m_memoryLimit(instance.m_memoryLimit),
m_memoryUsage(instance.m_memoryUsage),
m_timeLimit(instance.m_timeLimit),
m_clock(std::move(instance.m_clock)),
m_lastError(std::move(instance.m_lastError)),
m_state(instance.m_state),
m_level(instance.m_level)
{
instance.m_state = nullptr;
lua_setallocf(m_state, MemoryAllocator, this);
}
LuaInstance::~LuaInstance()
{
if (m_state)
@ -801,6 +815,24 @@ namespace Nz
return luaL_testudata(m_state, index, tname.GetConstBuffer());
}
LuaInstance& LuaInstance::operator=(LuaInstance&& instance) noexcept
{
m_clock = std::move(instance.m_clock);
m_lastError = std::move(instance.m_lastError);
m_level = instance.m_level;
m_memoryLimit = instance.m_memoryLimit;
m_memoryUsage = instance.m_memoryUsage;
m_state = instance.m_state;
m_timeLimit = instance.m_timeLimit;
instance.m_state = nullptr;
// Update allocator pointer
lua_setallocf(m_state, MemoryAllocator, this);
return *this;
}
int LuaInstance::GetIndexOfUpValue(int upValue)
{
return lua_upvalueindex(upValue);

View File

@ -83,9 +83,11 @@ namespace Nz
bool PhysWorld2D::RaycastQuery(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<RaycastHit>* hitInfos)
{
using ResultType = decltype(hitInfos);
auto callback = [](cpShape* shape, cpVect point, cpVect normal, cpFloat alpha, void* data)
{
std::vector<RaycastHit>* results = reinterpret_cast<std::vector<RaycastHit>*>(data);
ResultType results = static_cast<ResultType>(data);
RaycastHit hitInfo;
hitInfo.fraction = alpha;
@ -133,6 +135,20 @@ namespace Nz
}
}
void PhysWorld2D::RegionQuery(const Nz::Rectf& boundingBox, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<Nz::RigidBody2D*>* bodies)
{
using ResultType = decltype(bodies);
auto callback = [] (cpShape* shape, void* data)
{
ResultType results = static_cast<ResultType>(data);
results->push_back(static_cast<Nz::RigidBody2D*>(cpShapeGetUserData(shape)));
};
cpShapeFilter filter = cpShapeFilterNew(collisionGroup, categoryMask, collisionMask);
cpSpaceBBQuery(m_handle, cpBBNew(boundingBox.x, boundingBox.y + boundingBox.height, boundingBox.x + boundingBox.width, boundingBox.y), filter, callback, bodies);
}
void PhysWorld2D::RegisterCallbacks(unsigned int collisionId, const Callback& callbacks)
{
InitCallbacks(cpSpaceAddWildcardHandler(m_handle, collisionId), callbacks);