Merge branch 'master' into NDK-ShadowMapping
Former-commit-id: e2be28b65207dfbb81efe58f31ca31548afecee7
This commit is contained in:
commit
37aa00b2e7
|
|
@ -1,5 +1,8 @@
|
|||
# Nazara build
|
||||
examples/bin/*.exe
|
||||
examples/bin/*.pdb
|
||||
tests/*.exe
|
||||
tests/*.pdb
|
||||
lib/*
|
||||
|
||||
# Feature page
|
||||
|
|
@ -21,6 +24,7 @@ build/**/*.workspace
|
|||
build/**/*.project
|
||||
|
||||
# Visual Studio
|
||||
build/**/*.pdb
|
||||
build/**/*.filters
|
||||
build/**/*.vcxproj
|
||||
build/**/*.tlog
|
||||
|
|
@ -28,17 +32,17 @@ build/**/*.sln
|
|||
build/**/*.vcxprojResolveAssemblyReference.cache
|
||||
build/**/*.nativecodeanalysis.all.xml
|
||||
build/**/*.nativecodeanalysis.xml
|
||||
lib/*.exp
|
||||
build/**/*.VC.opendb
|
||||
|
||||
# Compiled Object files
|
||||
build/**/*.slo
|
||||
build/**/*.lo
|
||||
build/**/*.o
|
||||
build/**/*.obj
|
||||
build/**/*.obj.enc
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
build/**/*.so
|
||||
lib/*.lib
|
||||
|
||||
# Compiled Static libraries
|
||||
build/**/*.lai
|
||||
|
|
@ -73,7 +77,6 @@ $RECYCLE.BIN/
|
|||
*.ilk
|
||||
*.meta
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
|
|
|
|||
4
Doxyfile
4
Doxyfile
|
|
@ -319,7 +319,7 @@ AUTOLINK_SUPPORT = YES
|
|||
# diagrams that involve STL classes more complete and accurate.
|
||||
# The default value is: NO.
|
||||
|
||||
BUILTIN_STL_SUPPORT = NO
|
||||
BUILTIN_STL_SUPPORT = YES
|
||||
|
||||
# If you use Microsoft's C++/CLI language, you should set this option to YES to
|
||||
# enable parsing support.
|
||||
|
|
@ -412,7 +412,7 @@ TYPEDEF_HIDES_STRUCT = NO
|
|||
# the optimal cache size from a speed point of view.
|
||||
# Minimum value: 0, maximum value: 9, default value: 0.
|
||||
|
||||
LOOKUP_CACHE_SIZE = 0
|
||||
LOOKUP_CACHE_SIZE = 5
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Build related configuration options
|
||||
|
|
|
|||
|
|
@ -20,6 +20,6 @@ namespace Ndk
|
|||
template<typename SystemType, typename S> bool IsSystem(S& system);
|
||||
}
|
||||
|
||||
#include <Ndk/Algorithm.inl>
|
||||
#include <NDK/Algorithm.inl>
|
||||
|
||||
#endif // NDK_ALGORITHM_HPP
|
||||
|
|
|
|||
|
|
@ -8,14 +8,51 @@
|
|||
#define NDK_APPLICATION_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API Application
|
||||
{
|
||||
public:
|
||||
Application();
|
||||
~Application();
|
||||
inline Application();
|
||||
Application(const Application&) = delete;
|
||||
Application(Application&&) = delete;
|
||||
inline ~Application();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
template<typename T, typename... Args> T& AddWindow(Args&&... args);
|
||||
#endif
|
||||
template<typename... Args> World& AddWorld(Args&&... args);
|
||||
|
||||
inline float GetUpdateTime() const;
|
||||
|
||||
bool Run();
|
||||
|
||||
inline void Quit();
|
||||
|
||||
Application& operator=(const Application&) = delete;
|
||||
Application& operator=(Application&&) = delete;
|
||||
|
||||
inline static Application* Instance();
|
||||
|
||||
private:
|
||||
#ifndef NDK_SERVER
|
||||
std::vector<std::unique_ptr<Nz::Window>> m_windows;
|
||||
#endif
|
||||
std::list<World> m_worlds;
|
||||
Nz::Clock m_updateClock;
|
||||
#ifndef NDK_SERVER
|
||||
bool m_exitOnClosedWindows;
|
||||
#endif
|
||||
bool m_shouldQuit;
|
||||
float m_updateTime;
|
||||
|
||||
static Application* s_application;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,21 @@
|
|||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <type_traits>
|
||||
#include <NDK/Sdk.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline Application::Application()
|
||||
inline Application::Application() :
|
||||
#ifndef NDK_SERVER
|
||||
m_exitOnClosedWindows(true),
|
||||
#endif
|
||||
m_shouldQuit(false),
|
||||
m_updateTime(0.f)
|
||||
{
|
||||
NazaraAssert(s_application == nullptr, "You can create only one application instance per program");
|
||||
s_application = this;
|
||||
|
||||
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
|
||||
|
||||
// Initialisation du SDK
|
||||
|
|
@ -17,9 +26,48 @@ namespace Ndk
|
|||
|
||||
inline Application::~Application()
|
||||
{
|
||||
m_worlds.clear();
|
||||
#ifndef NDK_SERVER
|
||||
m_windows.clear();
|
||||
#endif
|
||||
|
||||
// Libération du SDK
|
||||
Sdk::Uninitialize();
|
||||
|
||||
// Libération automatique des modules
|
||||
s_application = nullptr;
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
template<typename T, typename... Args>
|
||||
T& Application::AddWindow(Args&&... args)
|
||||
{
|
||||
static_assert(std::is_base_of<Nz::Window, T>::value, "Type must inherit Window");
|
||||
|
||||
m_windows.emplace_back(new T(std::forward<Args>(args)...));
|
||||
return static_cast<T&>(*m_windows.back().get());
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename... Args>
|
||||
World& Application::AddWorld(Args&&... args)
|
||||
{
|
||||
m_worlds.emplace_back(std::forward<Args>(args)...);
|
||||
return m_worlds.back();
|
||||
}
|
||||
|
||||
inline float Application::GetUpdateTime() const
|
||||
{
|
||||
return m_updateTime;
|
||||
}
|
||||
|
||||
inline void Application::Quit()
|
||||
{
|
||||
m_shouldQuit = true;
|
||||
}
|
||||
|
||||
inline Application* Application::Instance()
|
||||
{
|
||||
return s_application;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#ifndef NDK_BASECOMPONENT_HPP
|
||||
#define NDK_BASECOMPONENT_HPP
|
||||
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
|
@ -31,6 +31,8 @@ namespace Ndk
|
|||
|
||||
ComponentIndex GetIndex() const;
|
||||
|
||||
inline static ComponentIndex GetMaxComponentIndex();
|
||||
|
||||
BaseComponent& operator=(const BaseComponent&) = default;
|
||||
BaseComponent& operator=(BaseComponent&&) = default;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
namespace Ndk
|
||||
|
|
@ -17,6 +18,11 @@ namespace Ndk
|
|||
return m_componentIndex;
|
||||
}
|
||||
|
||||
inline ComponentIndex BaseComponent::GetMaxComponentIndex()
|
||||
{
|
||||
return static_cast<ComponentIndex>(s_entries.size());
|
||||
}
|
||||
|
||||
inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc)
|
||||
{
|
||||
// Nous allons rajouter notre composant à la fin
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#define NDK_BASESYSTEM_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
|
|
@ -71,7 +71,7 @@ namespace Ndk
|
|||
|
||||
inline void RemoveEntity(Entity* entity);
|
||||
|
||||
inline void SetWorld(World& world);
|
||||
inline void SetWorld(World* world) noexcept;
|
||||
|
||||
inline void ValidateEntity(Entity* entity, bool justAdded);
|
||||
|
||||
|
|
|
|||
|
|
@ -60,14 +60,16 @@ namespace Ndk
|
|||
{
|
||||
if (m_updateRate > 0.f)
|
||||
{
|
||||
m_updateCounter -= elapsedTime;
|
||||
if (m_updateCounter >= 0.f)
|
||||
return;
|
||||
m_updateCounter += elapsedTime;
|
||||
|
||||
m_updateCounter += m_updateRate;
|
||||
while (m_updateCounter >= m_updateRate)
|
||||
{
|
||||
OnUpdate(m_updateRate);
|
||||
m_updateCounter -= m_updateRate;
|
||||
}
|
||||
}
|
||||
|
||||
OnUpdate(elapsedTime);
|
||||
else
|
||||
OnUpdate(elapsedTime);
|
||||
}
|
||||
|
||||
template<typename ComponentType>
|
||||
|
|
@ -172,9 +174,9 @@ namespace Ndk
|
|||
OnEntityValidation(entity, justAdded);
|
||||
}
|
||||
|
||||
inline void BaseSystem::SetWorld(World& world)
|
||||
inline void BaseSystem::SetWorld(World* world) noexcept
|
||||
{
|
||||
m_world = &world;
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
inline bool BaseSystem::Initialize()
|
||||
|
|
@ -186,6 +188,6 @@ namespace Ndk
|
|||
|
||||
inline void BaseSystem::Uninitialize()
|
||||
{
|
||||
// Rien à faire
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Ndk/Algorithm.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Ndk
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
// This file was automatically generated on 03 Mar 2016 at 14:09:12
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_COMPONENTS_GLOBAL_HPP
|
||||
#define NDK_COMPONENTS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Components/CollisionComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#endif
|
||||
|
||||
#endif // NDK_COMPONENTS_GLOBAL_HPP
|
||||
|
|
@ -33,24 +33,27 @@ namespace Ndk
|
|||
inline void EnsureViewMatrixUpdate() const;
|
||||
inline void EnsureViewportUpdate() const;
|
||||
|
||||
inline float GetAspectRatio() const;
|
||||
inline Nz::Vector3f GetEyePosition() const;
|
||||
inline Nz::Vector3f GetForward() const;
|
||||
inline float GetAspectRatio() const override;
|
||||
inline Nz::Vector3f GetEyePosition() const override;
|
||||
inline Nz::Vector3f GetForward() const override;
|
||||
inline float GetFOV() const;
|
||||
inline const Nz::Frustumf& GetFrustum() const;
|
||||
inline const Nz::Frustumf& GetFrustum() const override;
|
||||
inline unsigned int GetLayer() const;
|
||||
inline const Nz::Matrix4f& GetProjectionMatrix() const;
|
||||
inline const Nz::Matrix4f& GetProjectionMatrix() const override;
|
||||
inline Nz::ProjectionType GetProjectionType() const;
|
||||
inline const Nz::RenderTarget* GetTarget() const;
|
||||
inline const Nz::Vector2f& GetSize() const;
|
||||
inline const Nz::RenderTarget* GetTarget() const override;
|
||||
inline const Nz::Rectf& GetTargetRegion() const;
|
||||
inline const Nz::Matrix4f& GetViewMatrix() const;
|
||||
inline const Nz::Recti& GetViewport() const;
|
||||
inline float GetZFar() const;
|
||||
inline float GetZNear() const;
|
||||
inline const Nz::Matrix4f& GetViewMatrix() const override;
|
||||
inline const Nz::Recti& GetViewport() const override;
|
||||
inline float GetZFar() const override;
|
||||
inline float GetZNear() const override;
|
||||
|
||||
inline void SetFOV(float fov);
|
||||
inline void SetLayer(unsigned int layer);
|
||||
inline void SetProjectionType(Nz::ProjectionType projection);
|
||||
inline void SetSize(const Nz::Vector2f& size);
|
||||
inline void SetSize(float width, float height);
|
||||
inline void SetTarget(const Nz::RenderTarget* renderTarget);
|
||||
inline void SetTargetRegion(const Nz::Rectf& region);
|
||||
inline void SetViewport(const Nz::Recti& viewport);
|
||||
|
|
@ -89,6 +92,7 @@ namespace Ndk
|
|||
Nz::Rectf m_targetRegion;
|
||||
mutable Nz::Recti m_viewport;
|
||||
const Nz::RenderTarget* m_target;
|
||||
Nz::Vector2f m_size;
|
||||
mutable bool m_frustumUpdated;
|
||||
mutable bool m_projectionMatrixUpdated;
|
||||
mutable bool m_viewMatrixUpdated;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@
|
|||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include "CameraComponent.hpp"
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline CameraComponent::CameraComponent() :
|
||||
m_projectionType(Nz::ProjectionType_Perspective),
|
||||
m_targetRegion(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(0.f),
|
||||
m_target(nullptr),
|
||||
m_frustumUpdated(false),
|
||||
m_projectionMatrixUpdated(false),
|
||||
|
|
@ -28,6 +30,7 @@ namespace Ndk
|
|||
AbstractViewer(camera),
|
||||
m_projectionType(camera.m_projectionType),
|
||||
m_targetRegion(camera.m_targetRegion),
|
||||
m_size(camera.m_size),
|
||||
m_target(nullptr),
|
||||
m_frustumUpdated(false),
|
||||
m_projectionMatrixUpdated(false),
|
||||
|
|
@ -102,6 +105,11 @@ namespace Ndk
|
|||
return m_projectionType;
|
||||
}
|
||||
|
||||
inline const Nz::Vector2f & CameraComponent::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline const Nz::RenderTarget* CameraComponent::GetTarget() const
|
||||
{
|
||||
return m_target;
|
||||
|
|
@ -151,6 +159,18 @@ namespace Ndk
|
|||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetSize(const Nz::Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetSize(float width, float height)
|
||||
{
|
||||
SetSize({width, height});
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetTarget(const Nz::RenderTarget* renderTarget)
|
||||
{
|
||||
m_target = renderTarget;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,11 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API GraphicsComponent : public Component<GraphicsComponent>
|
||||
class GraphicsComponent;
|
||||
|
||||
using GraphicsComponentHandle = Nz::ObjectHandle<GraphicsComponent>;
|
||||
|
||||
class NDK_API GraphicsComponent : public Component<GraphicsComponent>, public Nz::HandledObject<GraphicsComponent>
|
||||
{
|
||||
friend class RenderSystem;
|
||||
|
||||
|
|
@ -26,11 +30,15 @@ namespace Ndk
|
|||
|
||||
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||
|
||||
inline void EnsureBoundingVolumeUpdate() const;
|
||||
inline void EnsureTransformMatrixUpdate() const;
|
||||
|
||||
inline const Nz::BoundingVolumef& GetBoundingVolume() const;
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
inline void InvalidateBoundingVolume();
|
||||
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index);
|
||||
inline void InvalidateRenderables();
|
||||
inline void InvalidateTransformMatrix();
|
||||
|
|
@ -41,6 +49,7 @@ namespace Ndk
|
|||
void OnDetached() override;
|
||||
void OnNodeInvalidated(const Nz::Node* node);
|
||||
|
||||
void UpdateBoundingVolume() const;
|
||||
void UpdateTransformMatrix() const;
|
||||
|
||||
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
|
||||
|
|
@ -61,7 +70,9 @@ namespace Ndk
|
|||
};
|
||||
|
||||
std::vector<Renderable> m_renderables;
|
||||
mutable Nz::BoundingVolumef m_boundingVolume;
|
||||
mutable Nz::Matrix4f m_transformMatrix;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
mutable bool m_transformMatrixUpdated;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ namespace Ndk
|
|||
{
|
||||
inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) :
|
||||
Component(graphicsComponent),
|
||||
m_boundingVolume(graphicsComponent.m_boundingVolume),
|
||||
m_transformMatrix(graphicsComponent.m_transformMatrix),
|
||||
m_boundingVolumeUpdated(graphicsComponent.m_boundingVolumeUpdated),
|
||||
m_transformMatrixUpdated(graphicsComponent.m_transformMatrixUpdated)
|
||||
{
|
||||
m_renderables.reserve(graphicsComponent.m_renderables.size());
|
||||
|
|
@ -39,6 +41,14 @@ namespace Ndk
|
|||
r.data.renderOrder = renderOrder;
|
||||
r.renderable = std::move(renderable);
|
||||
r.renderableInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::EnsureBoundingVolumeUpdate() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::EnsureTransformMatrixUpdate() const
|
||||
|
|
@ -47,6 +57,18 @@ namespace Ndk
|
|||
UpdateTransformMatrix();
|
||||
}
|
||||
|
||||
inline const Nz::BoundingVolumef& GraphicsComponent::GetBoundingVolume() const
|
||||
{
|
||||
EnsureBoundingVolumeUpdate();
|
||||
|
||||
return m_boundingVolume;
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::InvalidateBoundingVolume()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::InvalidateRenderables()
|
||||
{
|
||||
for (Renderable& r : m_renderables)
|
||||
|
|
@ -55,6 +77,7 @@ namespace Ndk
|
|||
|
||||
inline void GraphicsComponent::InvalidateTransformMatrix()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
m_transformMatrixUpdated = false;
|
||||
|
||||
InvalidateRenderables();
|
||||
|
|
|
|||
|
|
@ -13,8 +13,11 @@
|
|||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
class NodeComponent;
|
||||
|
||||
class NDK_API NodeComponent : public Component<NodeComponent>, public Nz::Node
|
||||
using NodeComponentHandle = Nz::ObjectHandle<NodeComponent>;
|
||||
|
||||
class NDK_API NodeComponent : public Component<NodeComponent>, public Nz::Node, public Nz::HandledObject<NodeComponent>
|
||||
{
|
||||
public:
|
||||
NodeComponent() = default;
|
||||
|
|
|
|||
|
|
@ -13,8 +13,11 @@
|
|||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
class VelocityComponent;
|
||||
|
||||
class NDK_API VelocityComponent : public Component<VelocityComponent>
|
||||
using VelocityComponentHandle = Nz::ObjectHandle<VelocityComponent>;
|
||||
|
||||
class NDK_API VelocityComponent : public Component<VelocityComponent>, public Nz::HandledObject<VelocityComponent>
|
||||
{
|
||||
public:
|
||||
VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
// 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_CONSOLE_HPP
|
||||
#define NDK_CONSOLE_HPP
|
||||
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Utility/Event.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <NDK/EntityOwner.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class LuaInstance;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class Console;
|
||||
class Entity;
|
||||
|
||||
using ConsoleHandle = Nz::ObjectHandle<Console>;
|
||||
|
||||
class NDK_API Console : public Nz::Node, public Nz::HandledObject<Console>
|
||||
{
|
||||
public:
|
||||
Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance);
|
||||
Console(const Console& console) = delete;
|
||||
Console(Console&& console) = default;
|
||||
~Console() = default;
|
||||
|
||||
void AddLine(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
|
||||
|
||||
void Clear();
|
||||
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const EntityHandle& GetHistory() const;
|
||||
inline const EntityHandle& GetHistoryBackground() const;
|
||||
inline const EntityHandle& GetInput() const;
|
||||
inline const EntityHandle& GetInputBackground() const;
|
||||
inline const Nz::Vector2f& GetSize() const;
|
||||
inline const Nz::FontRef& GetTextFont() const;
|
||||
|
||||
inline bool IsVisible() const;
|
||||
|
||||
void SendCharacter(char32_t character);
|
||||
void SendEvent(Nz::WindowEvent event);
|
||||
|
||||
void SetCharacterSize(unsigned int size);
|
||||
void SetSize(const Nz::Vector2f& size);
|
||||
void SetTextFont(Nz::FontRef font);
|
||||
|
||||
void Show(bool show = true);
|
||||
|
||||
Console& operator=(const Console& console) = delete;
|
||||
Console& operator=(Console&& console) = default;
|
||||
|
||||
private:
|
||||
void AddLineInternal(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
|
||||
void ExecuteInput();
|
||||
void Layout();
|
||||
void RefreshHistory();
|
||||
|
||||
struct Line
|
||||
{
|
||||
Nz::Color color;
|
||||
Nz::String text;
|
||||
};
|
||||
|
||||
std::size_t m_historyPosition;
|
||||
std::vector<Nz::String> m_commandHistory;
|
||||
std::vector<Line> m_historyLines;
|
||||
EntityOwner m_historyBackground;
|
||||
EntityOwner m_history;
|
||||
EntityOwner m_input;
|
||||
EntityOwner m_inputBackground;
|
||||
Nz::FontRef m_defaultFont;
|
||||
Nz::LuaInstance& m_instance;
|
||||
Nz::SpriteRef m_historyBackgroundSprite;
|
||||
Nz::SpriteRef m_inputBackgroundSprite;
|
||||
Nz::SimpleTextDrawer m_historyDrawer;
|
||||
Nz::SimpleTextDrawer m_inputDrawer;
|
||||
Nz::TextSpriteRef m_historyTextSprite;
|
||||
Nz::TextSpriteRef m_inputTextSprite;
|
||||
Nz::Vector2f m_size;
|
||||
bool m_opened;
|
||||
unsigned int m_characterSize;
|
||||
unsigned int m_maxHistoryLines;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Console.inl>
|
||||
|
||||
#endif // NDK_CONSOLE_HPP
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
// 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 <Nazara/Core/Error.hpp>
|
||||
#include "Console.hpp"
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline unsigned int Console::GetCharacterSize() const
|
||||
{
|
||||
return m_characterSize;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetHistory() const
|
||||
{
|
||||
return m_history;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetHistoryBackground() const
|
||||
{
|
||||
return m_historyBackground;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetInput() const
|
||||
{
|
||||
return m_input;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetInputBackground() const
|
||||
{
|
||||
return m_inputBackground;
|
||||
}
|
||||
|
||||
inline const Nz::Vector2f& Console::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline const Nz::FontRef& Console::GetTextFont() const
|
||||
{
|
||||
return m_defaultFont;
|
||||
}
|
||||
|
||||
inline bool Console::IsVisible() const
|
||||
{
|
||||
return m_opened;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
#define NDK_ENTITY_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
|
@ -15,13 +16,14 @@
|
|||
namespace Ndk
|
||||
{
|
||||
class BaseComponent;
|
||||
class EntityHandle;
|
||||
class Entity;
|
||||
class World;
|
||||
|
||||
class NDK_API Entity
|
||||
using EntityHandle = Nz::ObjectHandle<Entity>;
|
||||
|
||||
class NDK_API Entity : public Nz::HandledObject<Entity>
|
||||
{
|
||||
friend class BaseSystem;
|
||||
friend EntityHandle;
|
||||
friend World;
|
||||
|
||||
public:
|
||||
|
|
@ -32,7 +34,7 @@ namespace Ndk
|
|||
BaseComponent& AddComponent(std::unique_ptr<BaseComponent>&& component);
|
||||
template<typename ComponentType, typename... Args> ComponentType& AddComponent(Args&&... args);
|
||||
|
||||
EntityHandle CreateHandle();
|
||||
inline void Enable(bool enable);
|
||||
|
||||
inline BaseComponent& GetComponent(ComponentIndex index);
|
||||
template<typename ComponentType> ComponentType& GetComponent();
|
||||
|
|
@ -47,32 +49,36 @@ namespace Ndk
|
|||
void Kill();
|
||||
|
||||
void Invalidate();
|
||||
inline bool IsEnabled() const;
|
||||
inline bool IsValid() const;
|
||||
|
||||
void RemoveAllComponents();
|
||||
void RemoveComponent(ComponentIndex index);
|
||||
template<typename ComponentType> void RemoveComponent();
|
||||
|
||||
inline Nz::String ToString() const;
|
||||
|
||||
Entity& operator=(const Entity&) = delete;
|
||||
Entity& operator=(Entity&&) = delete;
|
||||
|
||||
private:
|
||||
Entity(World& world, EntityId id);
|
||||
Entity(World* world, EntityId id);
|
||||
|
||||
void Create();
|
||||
void Destroy();
|
||||
|
||||
inline void RegisterHandle(EntityHandle* handle);
|
||||
inline void RegisterSystem(SystemIndex index);
|
||||
inline void UnregisterHandle(EntityHandle* handle);
|
||||
|
||||
inline void SetWorld(World* world) noexcept;
|
||||
|
||||
inline void UnregisterSystem(SystemIndex index);
|
||||
|
||||
std::vector<std::unique_ptr<BaseComponent>> m_components;
|
||||
std::vector<EntityHandle*> m_handles;
|
||||
Nz::Bitset<> m_componentBits;
|
||||
Nz::Bitset<> m_systemBits;
|
||||
EntityId m_id;
|
||||
World* m_world;
|
||||
bool m_enabled;
|
||||
bool m_valid;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
|
@ -19,6 +20,15 @@ namespace Ndk
|
|||
return static_cast<ComponentType&>(AddComponent(std::move(ptr)));
|
||||
}
|
||||
|
||||
inline void Entity::Enable(bool enable)
|
||||
{
|
||||
if (m_enabled != enable)
|
||||
{
|
||||
m_enabled = enable;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
inline BaseComponent& Entity::GetComponent(ComponentIndex index)
|
||||
{
|
||||
///DOC: Le component doit être présent
|
||||
|
|
@ -74,6 +84,11 @@ namespace Ndk
|
|||
return HasComponent(index);
|
||||
}
|
||||
|
||||
inline bool Entity::IsEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
inline bool Entity::IsValid() const
|
||||
{
|
||||
return m_valid;
|
||||
|
|
@ -88,10 +103,10 @@ namespace Ndk
|
|||
RemoveComponent(index);
|
||||
}
|
||||
|
||||
inline void Entity::RegisterHandle(EntityHandle* handle)
|
||||
inline Nz::String Entity::ToString() const
|
||||
{
|
||||
///DOC: Un handle ne doit être enregistré qu'une fois, des erreurs se produisent s'il l'est plus d'une fois
|
||||
m_handles.push_back(handle);
|
||||
Nz::StringStream ss;
|
||||
return ss << "Entity(" << GetId() << ')';
|
||||
}
|
||||
|
||||
inline void Entity::RegisterSystem(SystemIndex index)
|
||||
|
|
@ -99,14 +114,11 @@ namespace Ndk
|
|||
m_systemBits.UnboundedSet(index);
|
||||
}
|
||||
|
||||
inline void Entity::UnregisterHandle(EntityHandle* handle)
|
||||
inline void Entity::SetWorld(World* world) noexcept
|
||||
{
|
||||
///DOC: Un handle ne doit être libéré qu'une fois, et doit faire partie de la liste, sous peine de crash
|
||||
auto it = std::find(m_handles.begin(), m_handles.end(), handle);
|
||||
NazaraAssert(world, "An entity must be attached to a world at any time");
|
||||
|
||||
// On échange cet élément avec le dernier, et on diminue la taille du vector de 1
|
||||
std::swap(*it, m_handles.back());
|
||||
m_handles.pop_back();
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
inline void Entity::UnregisterSystem(SystemIndex index)
|
||||
|
|
@ -114,3 +126,19 @@ namespace Ndk
|
|||
m_systemBits.UnboundedReset(index);
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Ndk::EntityHandle>
|
||||
{
|
||||
size_t operator()(const Ndk::EntityHandle& handle) const
|
||||
{
|
||||
// Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée
|
||||
// pour cette raison, nous devons hasher l'ID de l'entité (qui reste constante)
|
||||
Ndk::EntityId id = (handle.IsValid()) ? handle->GetId() : std::numeric_limits<Ndk::EntityId>::max();
|
||||
|
||||
return hash<Ndk::EntityId>()(id);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
// 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_ENTITYHANDLE_HPP
|
||||
#define NDK_ENTITYHANDLE_HPP
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class EntityHandle
|
||||
{
|
||||
friend Entity;
|
||||
|
||||
public:
|
||||
EntityHandle();
|
||||
explicit EntityHandle(Entity* entity);
|
||||
EntityHandle(const EntityHandle& handle);
|
||||
EntityHandle(EntityHandle&& handle);
|
||||
~EntityHandle();
|
||||
|
||||
Entity* GetEntity() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void Reset(Entity* entity = nullptr);
|
||||
void Reset(const EntityHandle& handle);
|
||||
void Reset(EntityHandle&& handle);
|
||||
|
||||
EntityHandle& Swap(EntityHandle& handle);
|
||||
|
||||
Nz::String ToString() const;
|
||||
|
||||
operator bool() const;
|
||||
operator Entity*() const;
|
||||
Entity* operator->() const;
|
||||
|
||||
EntityHandle& operator=(Entity* entity);
|
||||
EntityHandle& operator=(const EntityHandle& handle);
|
||||
EntityHandle& operator=(EntityHandle&& handle);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const EntityHandle& handle);
|
||||
|
||||
friend bool operator==(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator==(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator==(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator!=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator!=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator!=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator<(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator<=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator>(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator>=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
static const EntityHandle InvalidHandle;
|
||||
|
||||
private:
|
||||
void OnEntityDestroyed();
|
||||
void OnEntityMoved(Entity* newEntity);
|
||||
|
||||
Entity* m_entity;
|
||||
};
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
void swap(Ndk::EntityHandle& lhs, Ndk::EntityHandle& rhs);
|
||||
}
|
||||
|
||||
#include <NDK/EntityHandle.inl>
|
||||
|
||||
#endif // NDK_ENTITYHANDLE_HPP
|
||||
|
|
@ -1,280 +0,0 @@
|
|||
// 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 <Nazara/Core/StringStream.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline EntityHandle::EntityHandle() :
|
||||
m_entity(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline EntityHandle::EntityHandle(Entity* entity) :
|
||||
EntityHandle()
|
||||
{
|
||||
Reset(entity);
|
||||
}
|
||||
|
||||
inline EntityHandle::EntityHandle(const EntityHandle& handle) :
|
||||
EntityHandle()
|
||||
{
|
||||
Reset(handle);
|
||||
}
|
||||
|
||||
inline EntityHandle::EntityHandle(EntityHandle&& handle) :
|
||||
EntityHandle()
|
||||
{
|
||||
Reset(handle);
|
||||
}
|
||||
|
||||
inline EntityHandle::~EntityHandle()
|
||||
{
|
||||
Reset(nullptr);
|
||||
}
|
||||
|
||||
inline Entity* EntityHandle::GetEntity() const
|
||||
{
|
||||
return m_entity;
|
||||
}
|
||||
|
||||
inline bool EntityHandle::IsValid() const
|
||||
{
|
||||
return m_entity != nullptr;
|
||||
}
|
||||
|
||||
inline void EntityHandle::Reset(Entity* entity)
|
||||
{
|
||||
// Si nous avions déjà une entité, nous devons l'informer que nous ne pointons plus sur elle
|
||||
if (m_entity)
|
||||
m_entity->UnregisterHandle(this);
|
||||
|
||||
m_entity = entity;
|
||||
if (m_entity)
|
||||
// On informe la nouvelle entité que nous pointons sur elle
|
||||
m_entity->RegisterHandle(this);
|
||||
}
|
||||
|
||||
inline void EntityHandle::Reset(const EntityHandle& handle)
|
||||
{
|
||||
Reset(handle.GetEntity());
|
||||
}
|
||||
|
||||
inline void EntityHandle::Reset(EntityHandle&& handle)
|
||||
{
|
||||
Reset(handle.GetEntity());
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::Swap(EntityHandle& handle)
|
||||
{
|
||||
// Comme nous inversons les handles, nous devons prévenir les entités
|
||||
// La version par défaut de swap (à base de move) aurait fonctionné,
|
||||
// mais en enregistrant les handles une fois de plus que nécessaire (à cause de la copie temporaire).
|
||||
if (m_entity)
|
||||
{
|
||||
m_entity->UnregisterHandle(this);
|
||||
m_entity->RegisterHandle(&handle);
|
||||
}
|
||||
|
||||
if (handle.m_entity)
|
||||
{
|
||||
handle.m_entity->UnregisterHandle(&handle);
|
||||
handle.m_entity->RegisterHandle(this);
|
||||
}
|
||||
|
||||
// On effectue l'échange
|
||||
std::swap(m_entity, handle.m_entity);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Nz::String EntityHandle::ToString() const
|
||||
{
|
||||
Nz::StringStream ss;
|
||||
ss << "EntityHandle(";
|
||||
if (IsValid())
|
||||
ss << "Entity(" << m_entity->GetId() << ')';
|
||||
else
|
||||
ss << "Null entity";
|
||||
|
||||
ss << ')';
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline EntityHandle::operator bool() const
|
||||
{
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
inline EntityHandle::operator Entity*() const
|
||||
{
|
||||
return m_entity;
|
||||
}
|
||||
|
||||
inline Entity* EntityHandle::operator->() const
|
||||
{
|
||||
return m_entity;
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::operator=(Entity* entity)
|
||||
{
|
||||
Reset(entity);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::operator=(const EntityHandle& handle)
|
||||
{
|
||||
Reset(handle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::operator=(EntityHandle&& handle)
|
||||
{
|
||||
Reset(handle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void EntityHandle::OnEntityDestroyed()
|
||||
{
|
||||
// Un raccourci, un appel à Reset nous enlèverait de la liste des handles que nous ne pouvons pas modifier
|
||||
// maintenant car elle est actuellement parcourue
|
||||
m_entity = nullptr;
|
||||
}
|
||||
|
||||
inline void EntityHandle::OnEntityMoved(Entity* newEntity)
|
||||
{
|
||||
// L'entité a été déplacée (peut arriver lors d'un changement de taille du conteneur du monde)
|
||||
// nous mettons à jour notre pointeur
|
||||
m_entity = newEntity;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const EntityHandle& handle)
|
||||
{
|
||||
out << "EntityHandle(";
|
||||
if (handle.IsValid())
|
||||
out << "Entity(" << handle->GetId() << ')';
|
||||
else
|
||||
out << "Null entity";
|
||||
|
||||
out << ')';
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
inline bool operator==(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return lhs.m_entity == rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator==(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return &lhs == rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator==(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return lhs.m_entity == &rhs;
|
||||
}
|
||||
|
||||
inline bool operator!=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return lhs.m_entity < rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator<(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return &lhs < rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator<(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return lhs.m_entity < &rhs;
|
||||
}
|
||||
|
||||
inline bool operator<=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator>(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Ndk::EntityHandle>
|
||||
{
|
||||
size_t operator()(const Ndk::EntityHandle& handle) const
|
||||
{
|
||||
// Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée
|
||||
// pour cette raison, nous devons hasher l'ID de l'entité (qui reste constante)
|
||||
Ndk::EntityId id = (handle.IsValid()) ? handle->GetId() : std::numeric_limits<Ndk::EntityId>::max();
|
||||
|
||||
return hash<Ndk::EntityId>()(id);
|
||||
}
|
||||
};
|
||||
|
||||
inline void swap(Ndk::EntityHandle& lhs, Ndk::EntityHandle& rhs)
|
||||
{
|
||||
lhs.Swap(rhs);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ namespace Ndk
|
|||
|
||||
std::swap(*it, m_entities.back());
|
||||
m_entities.pop_back(); // On le sort du vector
|
||||
m_entityBits.UnboundedSet(entity->GetId(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
// 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_ENTITYOWNER_HPP
|
||||
#define NDK_ENTITYOWNER_HPP
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class EntityOwner : public EntityHandle
|
||||
{
|
||||
public:
|
||||
EntityOwner() = default;
|
||||
explicit EntityOwner(Entity* entity);
|
||||
EntityOwner(const EntityOwner& handle) = delete;
|
||||
EntityOwner(EntityOwner&& handle);
|
||||
~EntityOwner();
|
||||
|
||||
void Reset(Entity* entity = nullptr);
|
||||
void Reset(EntityOwner&& handle);
|
||||
|
||||
EntityOwner& operator=(Entity* entity);
|
||||
EntityOwner& operator=(const EntityOwner& handle) = delete;
|
||||
EntityOwner& operator=(EntityOwner&& handle);
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/EntityOwner.inl>
|
||||
|
||||
#endif // NDK_ENTITYOwner_HPP
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
// 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 <Nazara/Core/StringStream.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline EntityOwner::EntityOwner(Entity* entity) :
|
||||
EntityOwner()
|
||||
{
|
||||
Reset(entity);
|
||||
}
|
||||
|
||||
inline EntityOwner::EntityOwner(EntityOwner&& handle) :
|
||||
EntityHandle(std::move(handle))
|
||||
{
|
||||
}
|
||||
|
||||
inline EntityOwner::~EntityOwner()
|
||||
{
|
||||
Reset(nullptr);
|
||||
}
|
||||
|
||||
inline void EntityOwner::Reset(Entity* entity)
|
||||
{
|
||||
if (m_object)
|
||||
m_object->Kill();
|
||||
|
||||
EntityHandle::Reset(entity);
|
||||
}
|
||||
|
||||
inline void EntityOwner::Reset(EntityOwner&& handle)
|
||||
{
|
||||
Reset(handle.GetObject());
|
||||
handle.m_object = nullptr;
|
||||
}
|
||||
|
||||
inline EntityOwner& EntityOwner::operator=(Entity* entity)
|
||||
{
|
||||
Reset(entity);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline EntityOwner& EntityOwner::operator=(EntityOwner&& handle)
|
||||
{
|
||||
Reset(std::move(handle));
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Ndk::EntityOwner> : public hash<Ndk::EntityHandle>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_LUAINTERFACE_HPP
|
||||
#define NDK_LUAINTERFACE_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class LuaInstance;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class LuaBinding;
|
||||
|
||||
class NDK_API LuaAPI
|
||||
{
|
||||
public:
|
||||
LuaAPI() = delete;
|
||||
~LuaAPI() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static LuaBinding* s_binding;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/LuaAPI.inl>
|
||||
|
||||
#endif // NDK_LUAINTERFACE_HPP
|
||||
|
|
@ -0,0 +1,385 @@
|
|||
// 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 <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <NDK/Application.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio/Music.hpp>
|
||||
#include <Nazara/Audio/SoundBuffer.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <NDK/Console.hpp>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Color* color, TypeTag<Color>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
color->r = instance.CheckField<UInt8>("r", index);
|
||||
color->g = instance.CheckField<UInt8>("g", index);
|
||||
color->b = instance.CheckField<UInt8>("b", index);
|
||||
color->a = instance.CheckField<UInt8>("a", 255, index);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesd* angles, TypeTag<EulerAnglesd>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Table:
|
||||
angles->Set(instance.CheckField<double>("pitch", index), instance.CheckField<double>("yaw", index), instance.CheckField<double>("roll", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
{
|
||||
if (instance.IsOfType(index, "EulerAngles"))
|
||||
angles->Set(*(*static_cast<EulerAnglesd**>(instance.ToUserdata(index))));
|
||||
else
|
||||
angles->Set(*(*static_cast<Quaterniond**>(instance.CheckUserdata(index, "Quaternion"))));
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesf* angles, TypeTag<EulerAnglesf>)
|
||||
{
|
||||
EulerAnglesd anglesDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &anglesDouble, TypeTag<EulerAnglesd>());
|
||||
|
||||
angles->Set(anglesDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Table:
|
||||
quat->Set(instance.CheckField<double>("w", index), instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
{
|
||||
if (instance.IsOfType(index, "EulerAngles"))
|
||||
quat->Set(*(*static_cast<EulerAnglesd**>(instance.ToUserdata(index))));
|
||||
else
|
||||
quat->Set(*(*static_cast<Quaterniond**>(instance.CheckUserdata(index, "Quaternion"))));
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag<Quaternionf>)
|
||||
{
|
||||
Quaterniond quatDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag<Quaterniond>());
|
||||
|
||||
quat->Set(quatDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag<IpAddress>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_String:
|
||||
address->BuildFromAddress(instance.CheckString(index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
*address = *(*static_cast<IpAddress**>(instance.CheckUserdata(index, "IpAddress")));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2d* vec, TypeTag<Vector2d>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
if (index < 0 && index > -2)
|
||||
instance.Error("Vector2 expected, two numbers are required to convert it");
|
||||
|
||||
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1));
|
||||
return 2;
|
||||
|
||||
case Nz::LuaType_Table:
|
||||
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
vec->Set(*(*static_cast<Vector2d**>(instance.CheckUserdata(index, "Vector2"))));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2f* vec, TypeTag<Vector2f>)
|
||||
{
|
||||
Vector2d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2ui* vec, TypeTag<Vector2ui>)
|
||||
{
|
||||
Vector2d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3d* vec, TypeTag<Vector3d>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
if (index < 0 && index > -3)
|
||||
instance.Error("Vector3 expected, three numbers are required to convert it");
|
||||
|
||||
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1), instance.CheckNumber(index + 2, 0.0));
|
||||
return 3;
|
||||
|
||||
case Nz::LuaType_Table:
|
||||
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", 0.0, index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
vec->Set(*(*static_cast<Vector3d**>(instance.CheckUserdata(index, "Vector3"))));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3f* vec, TypeTag<Vector3f>)
|
||||
{
|
||||
Vector3d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3ui* vec, TypeTag<Vector3ui>)
|
||||
{
|
||||
Vector3d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, InstancedRenderableRef* renderable, TypeTag<InstancedRenderableRef>)
|
||||
{
|
||||
if (instance.IsOfType(index, "InstancedRenderable"))
|
||||
*renderable = *(*static_cast<InstancedRenderableRef**>(instance.CheckUserdata(index, "InstancedRenderable")));
|
||||
else
|
||||
*renderable = *(*static_cast<InstancedRenderableRef**>(instance.CheckUserdata(index, "Model")));
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MaterialParams* params, TypeTag<MaterialParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->loadAlphaMap = instance.CheckField<bool>("LoadAlphaMap", params->loadAlphaMap);
|
||||
params->loadDiffuseMap = instance.CheckField<bool>("LoadDiffuseMap", params->loadDiffuseMap);
|
||||
params->loadEmissiveMap = instance.CheckField<bool>("LoadEmissiveMap", params->loadEmissiveMap);
|
||||
params->loadHeightMap = instance.CheckField<bool>("LoadHeightMap", params->loadHeightMap);
|
||||
params->loadNormalMap = instance.CheckField<bool>("LoadNormalMap", params->loadNormalMap);
|
||||
params->loadSpecularMap = instance.CheckField<bool>("LoadSpecularMap", params->loadSpecularMap);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MeshParams* params, TypeTag<MeshParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->animated = instance.CheckField<bool>("Animated", params->animated);
|
||||
params->center = instance.CheckField<bool>("Center", params->center);
|
||||
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
|
||||
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
|
||||
params->scale = instance.CheckField<Vector3f>("Scale", params->scale);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, ModelParameters* params, TypeTag<ModelParameters>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->loadMaterials = instance.CheckField<bool>("LoadMaterials", params->loadMaterials);
|
||||
|
||||
LuaImplQueryArg(instance, -1, ¶ms->material, TypeTag<MaterialParams>());
|
||||
LuaImplQueryArg(instance, -1, ¶ms->mesh, TypeTag<MeshParams>());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MusicParams* params, TypeTag<MusicParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->forceMono = instance.CheckField<bool>("ForceMono", params->forceMono);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SoundBufferParams* params, TypeTag<SoundBufferParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->forceMono = instance.CheckField<bool>("ForceMono", params->forceMono);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesd val, TypeTag<EulerAnglesd>)
|
||||
{
|
||||
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesf val, TypeTag<EulerAnglesf>)
|
||||
{
|
||||
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Quaterniond val, TypeTag<Quaterniond>)
|
||||
{
|
||||
instance.PushInstance<Quaterniond>("Quaternion", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Quaternionf val, TypeTag<Quaternionf>)
|
||||
{
|
||||
instance.PushInstance<Quaterniond>("Quaternion", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress val, TypeTag<IpAddress>)
|
||||
{
|
||||
instance.PushInstance<IpAddress>("IpAddress", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2d val, TypeTag<Vector2d>)
|
||||
{
|
||||
instance.PushInstance<Vector2d>("Vector2", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2f val, TypeTag<Vector2f>)
|
||||
{
|
||||
instance.PushInstance<Vector2d>("Vector2", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2ui val, TypeTag<Vector2ui>)
|
||||
{
|
||||
instance.PushInstance<Vector2d>("Vector2", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3d val, TypeTag<Vector3d>)
|
||||
{
|
||||
instance.PushInstance<Vector3d>("Vector3", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3f val, TypeTag<Vector3f>)
|
||||
{
|
||||
instance.PushInstance<Vector3d>("Vector3", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3ui val, TypeTag<Vector3ui>)
|
||||
{
|
||||
instance.PushInstance<Vector3d>("Vector3", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Entity* ptr, TypeTag<Ndk::Entity*>)
|
||||
{
|
||||
instance.PushInstance<Ndk::EntityHandle>("Entity", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Application* ptr, TypeTag<Ndk::Application*>)
|
||||
{
|
||||
instance.PushInstance<Ndk::Application*>("Application", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::EntityHandle handle, TypeTag<Ndk::EntityHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::EntityHandle>("Entity", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::NodeComponentHandle handle, TypeTag<Ndk::NodeComponentHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::NodeComponentHandle>("NodeComponent", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::VelocityComponentHandle handle, TypeTag<Ndk::VelocityComponentHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::VelocityComponentHandle>("VelocityComponent", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::World* ptr, TypeTag<Ndk::World*>)
|
||||
{
|
||||
instance.PushInstance<Ndk::WorldHandle>("World", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::WorldHandle handle, TypeTag<Ndk::WorldHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::WorldHandle>("World", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::ConsoleHandle handle, TypeTag<Ndk::ConsoleHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::ConsoleHandle>("Console", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::GraphicsComponentHandle handle, TypeTag<Ndk::GraphicsComponentHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::GraphicsComponentHandle>("GraphicsComponent", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
|
||||
{
|
||||
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -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_STATE_HPP
|
||||
#define NDK_STATE_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class StateMachine;
|
||||
|
||||
class State
|
||||
{
|
||||
public:
|
||||
State();
|
||||
~State();
|
||||
|
||||
virtual void Enter(StateMachine& fsm) = 0;
|
||||
virtual void Leave(StateMachine& fsm) = 0;
|
||||
virtual bool Update(StateMachine& fsm, float elapsedTime) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_STATE_HPP
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// 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_STATEMACHINE_HPP
|
||||
#define NDK_STATEMACHINE_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/State.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class StateMachine
|
||||
{
|
||||
public:
|
||||
inline StateMachine(std::shared_ptr<State> originalState);
|
||||
StateMachine(const StateMachine&) = delete;
|
||||
inline StateMachine(StateMachine&& fsm) = default;
|
||||
inline ~StateMachine();
|
||||
|
||||
inline void ChangeState(std::shared_ptr<State> state);
|
||||
|
||||
inline bool Update(float elapsedTime);
|
||||
|
||||
inline StateMachine& operator=(StateMachine&& fsm) = default;
|
||||
StateMachine& operator=(const StateMachine&) = delete;
|
||||
|
||||
private:
|
||||
std::shared_ptr<State> m_currentState;
|
||||
std::shared_ptr<State> m_nextState;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/StateMachine.inl>
|
||||
|
||||
#endif // NDK_STATEMACHINE_HPP
|
||||
|
|
@ -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 <Nazara/Core/Error.hpp>
|
||||
#include <NDK/StateMachine.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline StateMachine::StateMachine(std::shared_ptr<State> originalState) :
|
||||
m_currentState(std::move(originalState))
|
||||
{
|
||||
NazaraAssert(m_currentState, "StateMachine must have a state to begin with");
|
||||
m_currentState->Enter(*this);
|
||||
}
|
||||
|
||||
inline StateMachine::~StateMachine()
|
||||
{
|
||||
m_currentState->Leave(*this);
|
||||
}
|
||||
|
||||
|
||||
inline void StateMachine::ChangeState(std::shared_ptr<State> state)
|
||||
{
|
||||
m_nextState = std::move(state);
|
||||
}
|
||||
|
||||
inline bool StateMachine::Update(float elapsedTime)
|
||||
{
|
||||
if (m_nextState)
|
||||
{
|
||||
m_currentState->Leave(*this);
|
||||
m_currentState = std::move(m_nextState);
|
||||
m_currentState->Enter(*this);
|
||||
}
|
||||
|
||||
return m_currentState->Update(*this, elapsedTime);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Ndk/Algorithm.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Ndk
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
// This file was automatically generated on 03 Mar 2016 at 14:09:12
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SYSTEMS_GLOBAL_HPP
|
||||
#define NDK_SYSTEMS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
#endif // NDK_SYSTEMS_GLOBAL_HPP
|
||||
|
|
@ -27,11 +27,15 @@ namespace Ndk
|
|||
inline RenderSystem(const RenderSystem& renderSystem);
|
||||
~RenderSystem() = default;
|
||||
|
||||
template<typename T> void ChangeRenderTechnique();
|
||||
inline void ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique);
|
||||
|
||||
inline const Nz::BackgroundRef& GetDefaultBackground() const;
|
||||
inline const Nz::Matrix4f& GetCoordinateSystemMatrix() const;
|
||||
inline Nz::Vector3f GetGlobalForward() const;
|
||||
inline Nz::Vector3f GetGlobalRight() const;
|
||||
inline Nz::Vector3f GetGlobalUp() const;
|
||||
inline Nz::AbstractRenderTechnique& GetRenderTechnique() const;
|
||||
|
||||
inline void SetDefaultBackground(Nz::BackgroundRef background);
|
||||
inline void SetGlobalForward(const Nz::Vector3f& direction);
|
||||
|
|
@ -49,6 +53,7 @@ namespace Ndk
|
|||
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
|
||||
void UpdatePointSpotShadowMaps();
|
||||
|
||||
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
|
||||
EntityList m_cameras;
|
||||
EntityList m_drawables;
|
||||
EntityList m_directionalLights;
|
||||
|
|
@ -56,7 +61,6 @@ namespace Ndk
|
|||
EntityList m_pointSpotLights;
|
||||
Nz::BackgroundRef m_background;
|
||||
Nz::DepthRenderTechnique m_shadowTechnique;
|
||||
Nz::ForwardRenderTechnique m_renderTechnique;
|
||||
Nz::Matrix4f m_coordinateSystemMatrix;
|
||||
Nz::RenderTexture m_shadowRT;
|
||||
bool m_coordinateSystemInvalidated;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,17 @@ namespace Ndk
|
|||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void RenderSystem::ChangeRenderTechnique()
|
||||
{
|
||||
ChangeRenderTechnique(std::make_unique<T>());
|
||||
}
|
||||
|
||||
inline void RenderSystem::ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique)
|
||||
{
|
||||
m_renderTechnique = std::move(renderTechnique);
|
||||
}
|
||||
|
||||
inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const
|
||||
{
|
||||
return m_background;
|
||||
|
|
@ -34,6 +45,11 @@ namespace Ndk
|
|||
return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32);
|
||||
}
|
||||
|
||||
inline Nz::AbstractRenderTechnique& RenderSystem::GetRenderTechnique() const
|
||||
{
|
||||
return *m_renderTechnique.get();
|
||||
}
|
||||
|
||||
inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background)
|
||||
{
|
||||
m_background = std::move(background);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
#define NDK_WORLD_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/System.hpp>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
|
@ -18,7 +18,11 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API World
|
||||
class World;
|
||||
|
||||
using WorldHandle = Nz::ObjectHandle<World>;
|
||||
|
||||
class NDK_API World : public Nz::HandledObject<World>
|
||||
{
|
||||
friend Entity;
|
||||
|
||||
|
|
@ -27,8 +31,8 @@ namespace Ndk
|
|||
|
||||
inline World(bool addDefaultSystems = true);
|
||||
World(const World&) = delete;
|
||||
World(World&&) = delete; ///TODO
|
||||
~World();
|
||||
inline World(World&& world) noexcept;
|
||||
~World() noexcept;
|
||||
|
||||
void AddDefaultSystems();
|
||||
|
||||
|
|
@ -38,7 +42,7 @@ namespace Ndk
|
|||
const EntityHandle& CreateEntity();
|
||||
inline EntityList CreateEntities(unsigned int count);
|
||||
|
||||
void Clear();
|
||||
void Clear() noexcept;
|
||||
|
||||
const EntityHandle& GetEntity(EntityId id);
|
||||
inline const EntityList& GetEntities();
|
||||
|
|
@ -62,7 +66,7 @@ namespace Ndk
|
|||
inline void Update(float elapsedTime);
|
||||
|
||||
World& operator=(const World&) = delete;
|
||||
World& operator=(World&&) = delete; ///TODO
|
||||
inline World& operator=(World&& world) noexcept;
|
||||
|
||||
private:
|
||||
inline void Invalidate();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,12 @@ namespace Ndk
|
|||
AddDefaultSystems();
|
||||
}
|
||||
|
||||
inline World::World(World&& world) noexcept :
|
||||
HandledObject(std::move(world))
|
||||
{
|
||||
operator=(std::move(world));
|
||||
}
|
||||
|
||||
inline BaseSystem& World::AddSystem(std::unique_ptr<BaseSystem>&& system)
|
||||
{
|
||||
NazaraAssert(system, "System must be valid");
|
||||
|
|
@ -25,7 +31,7 @@ namespace Ndk
|
|||
|
||||
// Affectation et retour du système
|
||||
m_systems[index] = std::move(system);
|
||||
m_systems[index]->SetWorld(*this);
|
||||
m_systems[index]->SetWorld(this);
|
||||
|
||||
Invalidate(); // On force une mise à jour de toutes les entités
|
||||
|
||||
|
|
@ -152,4 +158,22 @@ namespace Ndk
|
|||
{
|
||||
m_dirtyEntities.UnboundedSet(id, true);
|
||||
}
|
||||
|
||||
inline World& World::operator=(World&& world) noexcept
|
||||
{
|
||||
m_aliveEntities = std::move(world.m_aliveEntities);
|
||||
m_dirtyEntities = std::move(world.m_dirtyEntities);
|
||||
m_freeIdList = std::move(world.m_freeIdList);
|
||||
m_killedEntities = std::move(world.m_killedEntities);
|
||||
|
||||
m_entities = std::move(world.m_entities);
|
||||
for (EntityBlock& block : m_entities)
|
||||
block.entity.SetWorld(this);
|
||||
|
||||
m_systems = std::move(world.m_systems);
|
||||
for (const auto& systemPtr : m_systems)
|
||||
systemPtr->SetWorld(this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,3 +3,47 @@
|
|||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Application.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool Application::Run()
|
||||
{
|
||||
#ifndef NDK_SERVER
|
||||
bool hasAtLeastOneActiveWindow = false;
|
||||
|
||||
auto it = m_windows.begin();
|
||||
while (it != m_windows.end())
|
||||
{
|
||||
Nz::Window& window = **it;
|
||||
|
||||
if (!window.IsOpen(true))
|
||||
{
|
||||
it = m_windows.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
hasAtLeastOneActiveWindow = true;
|
||||
|
||||
++it;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
if (m_exitOnClosedWindows && !hasAtLeastOneActiveWindow)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if (m_shouldQuit)
|
||||
return false;
|
||||
|
||||
m_updateTime = m_updateClock.GetSeconds();
|
||||
m_updateClock.Restart();
|
||||
|
||||
for (World& world : m_worlds)
|
||||
world.Update(m_updateTime);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Application* Application::s_application = nullptr;
|
||||
}
|
||||
|
|
@ -119,9 +119,14 @@ namespace Ndk
|
|||
switch (m_projectionType)
|
||||
{
|
||||
case Nz::ProjectionType_Orthogonal:
|
||||
EnsureViewportUpdate();
|
||||
if (m_size.x <= 0.f || m_size.y <= 0.f)
|
||||
{
|
||||
EnsureViewportUpdate();
|
||||
|
||||
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
|
||||
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
|
||||
}
|
||||
else
|
||||
m_projectionMatrix.MakeOrtho(0.f, m_size.x, 0.f, m_size.y, m_zNear, m_zFar);
|
||||
break;
|
||||
|
||||
case Nz::ProjectionType_Perspective:
|
||||
|
|
|
|||
|
|
@ -63,6 +63,18 @@ namespace Ndk
|
|||
InvalidateTransformMatrix();
|
||||
}
|
||||
|
||||
void GraphicsComponent::UpdateBoundingVolume() const
|
||||
{
|
||||
EnsureTransformMatrixUpdate();
|
||||
|
||||
m_boundingVolume.MakeNull();
|
||||
for (const Renderable& r : m_renderables)
|
||||
m_boundingVolume.ExtendTo(r.renderable->GetBoundingVolume());
|
||||
|
||||
m_boundingVolume.Update(m_transformMatrix);
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
|
||||
void GraphicsComponent::UpdateTransformMatrix() const
|
||||
{
|
||||
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "GraphicsComponent requires NodeComponent");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,272 @@
|
|||
// 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/Console.hpp>
|
||||
#include <Nazara/Core/Unicode.hpp>
|
||||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
///TODO: For now is unable to display different color in the history, it needs a RichTextDrawer to do so
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const char s_inputPrefix[] = "> ";
|
||||
constexpr std::size_t s_inputPrefixSize = Nz::CountOf(s_inputPrefix) - 1;
|
||||
}
|
||||
|
||||
Console::Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance) :
|
||||
m_historyPosition(0),
|
||||
m_defaultFont(Nz::Font::GetDefault()),
|
||||
m_instance(instance),
|
||||
m_size(size),
|
||||
m_opened(false),
|
||||
m_characterSize(24)
|
||||
{
|
||||
Nz::MaterialRef backgroundMaterial = Nz::Material::New();
|
||||
backgroundMaterial->Enable(Nz::RendererParameter_Blend, true);
|
||||
backgroundMaterial->Enable(Nz::RendererParameter_DepthBuffer, false);
|
||||
backgroundMaterial->SetDstBlend(Nz::BlendFunc_InvSrcAlpha);
|
||||
backgroundMaterial->SetSrcBlend(Nz::BlendFunc_SrcAlpha);
|
||||
|
||||
// History bakckground
|
||||
m_historyBackgroundSprite = Nz::Sprite::New();
|
||||
m_historyBackgroundSprite->SetColor(Nz::Color(80, 80, 160, 128));
|
||||
m_historyBackgroundSprite->SetMaterial(backgroundMaterial);
|
||||
|
||||
m_historyBackground = world.CreateEntity();
|
||||
m_historyBackground->Enable(m_opened);
|
||||
m_historyBackground->AddComponent<Ndk::GraphicsComponent>().Attach(m_historyBackgroundSprite, -1);
|
||||
m_historyBackground->AddComponent<Ndk::NodeComponent>().SetParent(this);
|
||||
|
||||
// History
|
||||
m_historyDrawer.SetCharacterSize(m_characterSize);
|
||||
m_historyDrawer.SetColor(Nz::Color(200, 200, 200));
|
||||
m_historyDrawer.SetFont(m_defaultFont);
|
||||
|
||||
m_historyTextSprite = Nz::TextSprite::New();
|
||||
|
||||
m_history = world.CreateEntity();
|
||||
m_history->Enable(m_opened);
|
||||
m_history->AddComponent<Ndk::GraphicsComponent>().Attach(m_historyTextSprite);
|
||||
|
||||
Ndk::NodeComponent& historyNode = m_history->AddComponent<Ndk::NodeComponent>();
|
||||
historyNode.SetParent(this);
|
||||
|
||||
// Input background
|
||||
m_inputBackgroundSprite = Nz::Sprite::New();
|
||||
m_inputBackgroundSprite->SetColor(Nz::Color(255, 255, 255, 200));
|
||||
m_inputBackgroundSprite->SetMaterial(backgroundMaterial);
|
||||
|
||||
m_inputBackground = world.CreateEntity();
|
||||
m_inputBackground->Enable(m_opened);
|
||||
m_inputBackground->AddComponent<Ndk::GraphicsComponent>().Attach(m_inputBackgroundSprite, -1);
|
||||
m_inputBackground->AddComponent<Ndk::NodeComponent>().SetParent(this);
|
||||
|
||||
// Input
|
||||
m_inputDrawer.SetColor(Nz::Color::Black);
|
||||
m_inputDrawer.SetCharacterSize(m_characterSize);
|
||||
m_inputDrawer.SetFont(m_defaultFont);
|
||||
m_inputDrawer.SetText(s_inputPrefix);
|
||||
|
||||
m_inputTextSprite = Nz::TextSprite::New();
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
|
||||
m_input = world.CreateEntity();
|
||||
m_input->Enable(m_opened);
|
||||
m_input->AddComponent<Ndk::GraphicsComponent>().Attach(m_inputTextSprite);
|
||||
|
||||
Ndk::NodeComponent& inputNode = m_input->AddComponent<Ndk::NodeComponent>();
|
||||
inputNode.SetParent(this);
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::AddLine(const Nz::String& text, const Nz::Color& color)
|
||||
{
|
||||
AddLineInternal(text, color);
|
||||
RefreshHistory();
|
||||
}
|
||||
|
||||
void Console::Clear()
|
||||
{
|
||||
m_historyLines.clear();
|
||||
RefreshHistory();
|
||||
}
|
||||
|
||||
void Console::SendCharacter(char32_t character)
|
||||
{
|
||||
switch (character)
|
||||
{
|
||||
case '\b':
|
||||
{
|
||||
Nz::String input = m_inputDrawer.GetText();
|
||||
if (input.GetLength() <= s_inputPrefixSize) // Prevent removal of the input prefix
|
||||
return; // Ignore if no user character is there
|
||||
|
||||
input.Resize(-1, Nz::String::HandleUtf8);
|
||||
m_inputDrawer.SetText(input);
|
||||
break;
|
||||
}
|
||||
|
||||
case '\r':
|
||||
case '\n':
|
||||
ExecuteInput();
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if (Nz::Unicode::GetCategory(character) == Nz::Unicode::Category_Other_Control)
|
||||
return;
|
||||
|
||||
m_inputDrawer.AppendText(Nz::String::Unicode(character));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
}
|
||||
|
||||
void Console::SendEvent(Nz::WindowEvent event)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case Nz::WindowEventType_TextEntered:
|
||||
SendCharacter(event.text.character);
|
||||
break;
|
||||
|
||||
case Nz::WindowEventType_KeyPressed:
|
||||
{
|
||||
switch (event.key.code)
|
||||
{
|
||||
case Nz::Keyboard::Down:
|
||||
case Nz::Keyboard::Up:
|
||||
if (event.key.code == Nz::Keyboard::Up)
|
||||
m_historyPosition = std::min<std::size_t>(m_commandHistory.size(), m_historyPosition + 1);
|
||||
else
|
||||
{
|
||||
if (m_historyPosition > 1)
|
||||
m_historyPosition--;
|
||||
else if (m_historyPosition == 0)
|
||||
m_historyPosition = 1;
|
||||
}
|
||||
|
||||
Nz::String text = m_commandHistory[m_commandHistory.size() - m_historyPosition];
|
||||
m_inputDrawer.SetText(s_inputPrefix + text);
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Console::SetCharacterSize(unsigned int size)
|
||||
{
|
||||
m_characterSize = size;
|
||||
|
||||
m_historyDrawer.SetCharacterSize(m_characterSize);
|
||||
m_historyTextSprite->Update(m_historyDrawer);
|
||||
m_inputDrawer.SetCharacterSize(m_characterSize);
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::SetSize(const Nz::Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
m_historyBackgroundSprite->SetSize(m_size);
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::SetTextFont(Nz::FontRef font)
|
||||
{
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::Show(bool show)
|
||||
{
|
||||
if (m_opened != show)
|
||||
{
|
||||
m_historyBackground->Enable(show);
|
||||
m_history->Enable(show);
|
||||
m_input->Enable(show);
|
||||
m_inputBackground->Enable(show);
|
||||
|
||||
m_opened = show;
|
||||
}
|
||||
}
|
||||
|
||||
void Console::AddLineInternal(const Nz::String& text, const Nz::Color& color)
|
||||
{
|
||||
m_historyLines.emplace_back(Line{color, text});
|
||||
}
|
||||
|
||||
void Console::ExecuteInput()
|
||||
{
|
||||
Nz::String input = m_inputDrawer.GetText();
|
||||
Nz::String inputCmd = input.SubString(s_inputPrefixSize);;
|
||||
m_inputDrawer.SetText(s_inputPrefix);
|
||||
|
||||
if (m_commandHistory.empty() || m_commandHistory.back() != inputCmd)
|
||||
m_commandHistory.push_back(inputCmd);
|
||||
|
||||
m_historyPosition = 0;
|
||||
|
||||
AddLineInternal(input); //< With the input prefix
|
||||
|
||||
if (!m_instance.Execute(inputCmd))
|
||||
AddLineInternal(m_instance.GetLastError(), Nz::Color::Red);
|
||||
|
||||
RefreshHistory();
|
||||
}
|
||||
|
||||
void Console::Layout()
|
||||
{
|
||||
unsigned int lineHeight = m_defaultFont->GetSizeInfo(m_characterSize).lineHeight;
|
||||
|
||||
Ndk::NodeComponent& inputNode = m_input->GetComponent<Ndk::NodeComponent>();
|
||||
inputNode.SetPosition(0.f, m_size.y - lineHeight - 5.f);
|
||||
|
||||
float historyHeight = m_size.y - lineHeight - 5.f - 2.f;
|
||||
m_historyBackgroundSprite->SetSize(m_size.x, historyHeight);
|
||||
|
||||
m_maxHistoryLines = static_cast<unsigned int>(std::ceil(historyHeight / lineHeight));
|
||||
|
||||
Ndk::NodeComponent& historyNode = m_history->GetComponent<Ndk::NodeComponent>();
|
||||
historyNode.SetPosition(0.f, historyHeight - m_maxHistoryLines * lineHeight);
|
||||
|
||||
Ndk::NodeComponent& inputBackgroundNode = m_inputBackground->GetComponent<Ndk::NodeComponent>();
|
||||
inputBackgroundNode.SetPosition(0.f, historyHeight + 2.f);
|
||||
|
||||
m_inputBackgroundSprite->SetSize(m_size.x, m_size.y - historyHeight);
|
||||
}
|
||||
|
||||
void Console::RefreshHistory()
|
||||
{
|
||||
m_historyDrawer.Clear();
|
||||
auto it = m_historyLines.end();
|
||||
if (m_historyLines.size() > m_maxHistoryLines)
|
||||
it -= m_maxHistoryLines;
|
||||
else
|
||||
it = m_historyLines.begin();
|
||||
|
||||
for (unsigned int i = 0; i < m_maxHistoryLines; ++i)
|
||||
{
|
||||
if (m_maxHistoryLines - i <= m_historyLines.size() && it != m_historyLines.end())
|
||||
{
|
||||
m_historyDrawer.AppendText(it->text);
|
||||
++it;
|
||||
}
|
||||
|
||||
m_historyDrawer.AppendText(Nz::String('\n'));
|
||||
}
|
||||
|
||||
m_historyTextSprite->Update(m_historyDrawer);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,27 +4,25 @@
|
|||
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
Entity::Entity(Entity&& entity) :
|
||||
HandledObject(std::move(entity)),
|
||||
m_components(std::move(entity.m_components)),
|
||||
m_handles(std::move(entity.m_handles)),
|
||||
m_componentBits(std::move(entity.m_componentBits)),
|
||||
m_systemBits(std::move(entity.m_systemBits)),
|
||||
m_id(entity.m_id),
|
||||
m_world(entity.m_world),
|
||||
m_enabled(entity.m_enabled),
|
||||
m_valid(entity.m_valid)
|
||||
{
|
||||
for (EntityHandle* handle : m_handles)
|
||||
handle->OnEntityMoved(this);
|
||||
}
|
||||
|
||||
Entity::Entity(World& world, EntityId id) :
|
||||
Entity::Entity(World* world, EntityId id) :
|
||||
m_id(id),
|
||||
m_world(&world)
|
||||
m_world(world)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -62,11 +60,6 @@ namespace Ndk
|
|||
return component;
|
||||
}
|
||||
|
||||
EntityHandle Entity::CreateHandle()
|
||||
{
|
||||
return EntityHandle(this);
|
||||
}
|
||||
|
||||
void Entity::Kill()
|
||||
{
|
||||
m_world->KillEntity(this);
|
||||
|
|
@ -114,6 +107,7 @@ namespace Ndk
|
|||
|
||||
void Entity::Create()
|
||||
{
|
||||
m_enabled = true;
|
||||
m_valid = true;
|
||||
}
|
||||
|
||||
|
|
@ -130,11 +124,7 @@ namespace Ndk
|
|||
}
|
||||
m_systemBits.Clear();
|
||||
|
||||
// On informe chaque handle de notre destruction pour éviter qu'il ne continue de pointer sur nous
|
||||
for (EntityHandle* handle : m_handles)
|
||||
handle->OnEntityDestroyed();
|
||||
|
||||
m_handles.clear();
|
||||
UnregisterAllHandles();
|
||||
|
||||
m_valid = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
// 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/EntityHandle.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
const EntityHandle EntityHandle::InvalidHandle;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool LuaAPI::Initialize()
|
||||
{
|
||||
s_binding = new LuaBinding;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LuaAPI::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
if (!s_binding && !Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize binding");
|
||||
return;
|
||||
}
|
||||
|
||||
s_binding->RegisterClasses(instance);
|
||||
}
|
||||
|
||||
void LuaAPI::Uninitialize()
|
||||
{
|
||||
delete s_binding;
|
||||
}
|
||||
|
||||
LuaBinding* LuaAPI::s_binding = nullptr;
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
LuaBinding::LuaBinding() :
|
||||
// Core
|
||||
clockClass("Clock"),
|
||||
directoryClass("Directory"),
|
||||
fileClass("File"),
|
||||
streamClass("Stream"),
|
||||
|
||||
// Math
|
||||
eulerAnglesClass("EulerAngles"),
|
||||
quaternionClass("Quaternion"),
|
||||
vector2dClass("Vector2"),
|
||||
vector3dClass("Vector3"),
|
||||
|
||||
// Network
|
||||
abstractSocketClass("AbstractSocket"),
|
||||
ipAddressClass("IpAddress"),
|
||||
|
||||
// Utility
|
||||
abstractImage("AbstractImage"),
|
||||
nodeClass("Node"),
|
||||
|
||||
// SDK
|
||||
application("Application"),
|
||||
nodeComponent("NodeComponent"),
|
||||
entityClass("Entity"),
|
||||
velocityComponent("VelocityComponent"),
|
||||
worldClass("World")
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
,
|
||||
|
||||
// Audio
|
||||
musicClass("Music"),
|
||||
soundBuffer("SoundBuffer"),
|
||||
soundEmitter("SoundEmitter"),
|
||||
soundClass("Sound"),
|
||||
|
||||
// Graphics
|
||||
instancedRenderable("InstancedRenderable"),
|
||||
modelClass("Model"),
|
||||
|
||||
// SDK
|
||||
consoleClass("Console"),
|
||||
graphicsComponent("GraphicsComponent")
|
||||
#endif
|
||||
{
|
||||
BindCore();
|
||||
BindMath();
|
||||
BindNetwork();
|
||||
BindSDK();
|
||||
BindUtility();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
BindAudio();
|
||||
BindGraphics();
|
||||
BindRenderer();
|
||||
#endif
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
RegisterCore(instance);
|
||||
RegisterMath(instance);
|
||||
RegisterNetwork(instance);
|
||||
RegisterSDK(instance);
|
||||
RegisterUtility(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
RegisterAudio(instance);
|
||||
RegisterGraphics(instance);
|
||||
RegisterRenderer(instance);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
// 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_LUABINDING_HPP
|
||||
#define NDK_LUABINDING_HPP
|
||||
|
||||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Lua.hpp>
|
||||
#include <Nazara/Math.hpp>
|
||||
#include <Nazara/Network.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <NDK/Application.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/Systems.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <NDK/Console.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class LuaBinding
|
||||
{
|
||||
public:
|
||||
LuaBinding();
|
||||
~LuaBinding() = default;
|
||||
|
||||
void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
private:
|
||||
void BindCore();
|
||||
void BindMath();
|
||||
void BindNetwork();
|
||||
void BindSDK();
|
||||
void BindUtility();
|
||||
|
||||
template<typename T> void EnableComponentBinding();
|
||||
|
||||
void RegisterCore(Nz::LuaInstance& instance);
|
||||
void RegisterMath(Nz::LuaInstance& instance);
|
||||
void RegisterNetwork(Nz::LuaInstance& instance);
|
||||
void RegisterSDK(Nz::LuaInstance& instance);
|
||||
void RegisterUtility(Nz::LuaInstance& instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
void BindAudio();
|
||||
void BindGraphics();
|
||||
void BindRenderer();
|
||||
|
||||
void RegisterAudio(Nz::LuaInstance& instance);
|
||||
void RegisterGraphics(Nz::LuaInstance& instance);
|
||||
void RegisterRenderer(Nz::LuaInstance& instance);
|
||||
#endif
|
||||
|
||||
// Core
|
||||
Nz::LuaClass<Nz::Clock> clockClass;
|
||||
Nz::LuaClass<Nz::Directory> directoryClass;
|
||||
Nz::LuaClass<Nz::File> fileClass;
|
||||
Nz::LuaClass<Nz::Stream> streamClass;
|
||||
|
||||
// Math
|
||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAnglesClass;
|
||||
Nz::LuaClass<Nz::Quaterniond> quaternionClass;
|
||||
Nz::LuaClass<Nz::Vector2d> vector2dClass;
|
||||
Nz::LuaClass<Nz::Vector3d> vector3dClass;
|
||||
|
||||
// Network
|
||||
Nz::LuaClass<Nz::AbstractSocket> abstractSocketClass;
|
||||
Nz::LuaClass<Nz::IpAddress> ipAddressClass;
|
||||
|
||||
// Utility
|
||||
Nz::LuaClass<Nz::AbstractImage*> abstractImage;
|
||||
Nz::LuaClass<Nz::Node> nodeClass;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<Application*> application;
|
||||
Nz::LuaClass<EntityHandle> entityClass;
|
||||
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
||||
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
||||
Nz::LuaClass<WorldHandle> worldClass;
|
||||
|
||||
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
||||
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
||||
|
||||
struct ComponentBinding
|
||||
{
|
||||
AddComponentFunc adder;
|
||||
GetComponentFunc getter;
|
||||
bool valid = false;
|
||||
};
|
||||
|
||||
std::vector<ComponentBinding> m_componentBinding;
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Audio
|
||||
Nz::LuaClass<Nz::Music> musicClass;
|
||||
Nz::LuaClass<Nz::Sound> soundClass;
|
||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
||||
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
||||
|
||||
// Graphics
|
||||
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
||||
Nz::LuaClass<Nz::ModelRef> modelClass;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<ConsoleHandle> consoleClass;
|
||||
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_HPP
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindAudio()
|
||||
{
|
||||
/*********************************** Nz::Music **********************************/
|
||||
musicClass.Inherit(soundEmitter);
|
||||
|
||||
musicClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Music*
|
||||
{
|
||||
return new Nz::Music;
|
||||
});
|
||||
|
||||
//musicClass.SetMethod("Create", &Nz::Music::Create);
|
||||
//musicClass.SetMethod("Destroy", &Nz::Music::Destroy);
|
||||
|
||||
musicClass.BindMethod("EnableLooping", &Nz::Music::EnableLooping);
|
||||
|
||||
musicClass.BindMethod("GetDuration", &Nz::Music::GetDuration);
|
||||
musicClass.BindMethod("GetFormat", &Nz::Music::GetFormat);
|
||||
musicClass.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset);
|
||||
musicClass.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount);
|
||||
musicClass.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate);
|
||||
musicClass.BindMethod("GetStatus", &Nz::Music::GetStatus);
|
||||
|
||||
musicClass.BindMethod("IsLooping", &Nz::Music::IsLooping);
|
||||
|
||||
musicClass.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams());
|
||||
|
||||
musicClass.BindMethod("Pause", &Nz::Music::Pause);
|
||||
musicClass.BindMethod("Play", &Nz::Music::Play);
|
||||
|
||||
musicClass.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset);
|
||||
|
||||
musicClass.BindMethod("Stop", &Nz::Music::Stop);
|
||||
|
||||
// Manual
|
||||
musicClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music) -> int
|
||||
{
|
||||
Nz::StringStream stream("Music(");
|
||||
stream << music.GetFilePath() << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Sound **********************************/
|
||||
soundClass.Inherit(soundEmitter);
|
||||
|
||||
soundClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Sound*
|
||||
{
|
||||
return new Nz::Sound;
|
||||
});
|
||||
|
||||
soundClass.BindMethod("GetBuffer", &Nz::Sound::GetBuffer);
|
||||
|
||||
soundClass.BindMethod("IsPlayable", &Nz::Sound::IsPlayable);
|
||||
soundClass.BindMethod("IsPlaying", &Nz::Sound::IsPlaying);
|
||||
|
||||
soundClass.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
|
||||
|
||||
soundClass.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);
|
||||
|
||||
// Manual
|
||||
soundClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int
|
||||
{
|
||||
Nz::StringStream stream("Sound(");
|
||||
if (const Nz::SoundBuffer* buffer = sound.GetBuffer())
|
||||
stream << buffer;
|
||||
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::SoundBuffer **********************************/
|
||||
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::SoundBufferRef*
|
||||
{
|
||||
return new Nz::SoundBufferRef(new Nz::SoundBuffer);
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy);
|
||||
|
||||
soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration);
|
||||
soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat);
|
||||
soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount);
|
||||
soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate);
|
||||
|
||||
soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid);
|
||||
|
||||
soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams());
|
||||
|
||||
soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported);
|
||||
|
||||
// Manual
|
||||
soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
|
||||
{
|
||||
int index = 1;
|
||||
Nz::AudioFormat format = lua.Check<Nz::AudioFormat>(&index);
|
||||
unsigned int sampleCount = lua.Check<unsigned int>(&index);
|
||||
unsigned int sampleRate = lua.Check<unsigned int>(&index);
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const char* buffer = lua.CheckString(index, &bufferSize);
|
||||
lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer");
|
||||
|
||||
lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast<const Nz::Int16*>(buffer)));
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
|
||||
{
|
||||
lua.PushString(reinterpret_cast<const char*>(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16));
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int
|
||||
{
|
||||
Nz::StringStream stream("SoundBuffer(");
|
||||
if (soundBuffer->IsValid())
|
||||
{
|
||||
Nz::String filePath = soundBuffer->GetFilePath();
|
||||
if (!filePath.IsEmpty())
|
||||
stream << "File: " << filePath << ", ";
|
||||
|
||||
stream << "Duration: " << soundBuffer->GetDuration() / 1000.f << "s";
|
||||
}
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::SoundEmitter **********************************/
|
||||
soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping);
|
||||
soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization);
|
||||
|
||||
soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation);
|
||||
soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration);
|
||||
soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance);
|
||||
soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch);
|
||||
soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset);
|
||||
soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition);
|
||||
soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus);
|
||||
soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity);
|
||||
soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume);
|
||||
|
||||
soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping);
|
||||
soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);
|
||||
|
||||
soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause);
|
||||
soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play);
|
||||
|
||||
soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation);
|
||||
soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance);
|
||||
soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch);
|
||||
soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition);
|
||||
soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity);
|
||||
soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume);
|
||||
|
||||
soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterAudio(Nz::LuaInstance& instance)
|
||||
{
|
||||
musicClass.Register(instance);
|
||||
soundClass.Register(instance);
|
||||
soundBuffer.Register(instance);
|
||||
soundEmitter.Register(instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,280 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindCore()
|
||||
{
|
||||
/*********************************** Nz::Clock **********************************/
|
||||
clockClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Clock*
|
||||
{
|
||||
int argIndex = 1;
|
||||
return new Nz::Clock(lua.Check<Nz::Int64>(&argIndex, 0), lua.Check<bool>(&argIndex, false));
|
||||
});
|
||||
|
||||
clockClass.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds);
|
||||
clockClass.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds);
|
||||
clockClass.BindMethod("GetSeconds", &Nz::Clock::GetSeconds);
|
||||
clockClass.BindMethod("IsPaused", &Nz::Clock::IsPaused);
|
||||
clockClass.BindMethod("Pause", &Nz::Clock::Pause);
|
||||
clockClass.BindMethod("Restart", &Nz::Clock::Restart);
|
||||
clockClass.BindMethod("Unpause", &Nz::Clock::Unpause);
|
||||
|
||||
// Manual
|
||||
clockClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int {
|
||||
Nz::StringStream stream("Clock(Elapsed: ");
|
||||
stream << clock.GetSeconds();
|
||||
stream << "s, Paused: ";
|
||||
stream << clock.IsPaused();
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/********************************* Nz::Directory ********************************/
|
||||
directoryClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Directory*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::Directory;
|
||||
|
||||
case 1:
|
||||
return new Nz::Directory(lua.Check<Nz::String>(&argIndex));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
directoryClass.BindMethod("Close", &Nz::Directory::Close);
|
||||
directoryClass.BindMethod("Exists", &Nz::Directory::Exists);
|
||||
directoryClass.BindMethod("GetPath", &Nz::Directory::GetPath);
|
||||
directoryClass.BindMethod("GetPattern", &Nz::Directory::GetPattern);
|
||||
directoryClass.BindMethod("GetResultName", &Nz::Directory::GetResultName);
|
||||
directoryClass.BindMethod("GetResultPath", &Nz::Directory::GetResultPath);
|
||||
directoryClass.BindMethod("GetResultSize", &Nz::Directory::GetResultSize);
|
||||
directoryClass.BindMethod("IsOpen", &Nz::Directory::IsOpen);
|
||||
directoryClass.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory);
|
||||
directoryClass.BindMethod("NextResult", &Nz::Directory::NextResult, true);
|
||||
directoryClass.BindMethod("Open", &Nz::Directory::Open);
|
||||
directoryClass.BindMethod("SetPath", &Nz::Directory::SetPath);
|
||||
directoryClass.BindMethod("SetPattern", &Nz::Directory::SetPattern);
|
||||
|
||||
directoryClass.BindStaticMethod("Copy", Nz::Directory::Copy);
|
||||
directoryClass.BindStaticMethod("Create", Nz::Directory::Create);
|
||||
directoryClass.BindStaticMethod("Exists", Nz::Directory::Exists);
|
||||
directoryClass.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent);
|
||||
directoryClass.BindStaticMethod("Remove", Nz::Directory::Remove);
|
||||
directoryClass.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
|
||||
|
||||
// Manual
|
||||
directoryClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int {
|
||||
Nz::StringStream stream("Directory(");
|
||||
stream << directory.GetPath();
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Stream ***********************************/
|
||||
streamClass.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode);
|
||||
streamClass.BindMethod("Flush", &Nz::Stream::Flush);
|
||||
streamClass.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos);
|
||||
streamClass.BindMethod("GetDirectory", &Nz::Stream::GetDirectory);
|
||||
streamClass.BindMethod("GetPath", &Nz::Stream::GetPath);
|
||||
streamClass.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode);
|
||||
streamClass.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions);
|
||||
streamClass.BindMethod("GetSize", &Nz::Stream::GetSize);
|
||||
streamClass.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U);
|
||||
streamClass.BindMethod("IsReadable", &Nz::Stream::IsReadable);
|
||||
streamClass.BindMethod("IsSequential", &Nz::Stream::IsSequential);
|
||||
streamClass.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled);
|
||||
streamClass.BindMethod("IsWritable", &Nz::Stream::IsWritable);
|
||||
streamClass.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos);
|
||||
|
||||
streamClass.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t length = lua.Check<std::size_t>(&argIndex);
|
||||
|
||||
std::unique_ptr<char[]> buffer(new char[length]);
|
||||
std::size_t readLength = stream.Read(buffer.get(), length);
|
||||
|
||||
lua.PushString(Nz::String(buffer.get(), readLength));
|
||||
return 1;
|
||||
});
|
||||
|
||||
streamClass.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const char* buffer = lua.CheckString(argIndex, &bufferSize);
|
||||
|
||||
if (stream.IsTextModeEnabled())
|
||||
lua.Push(stream.Write(Nz::String(buffer, bufferSize)));
|
||||
else
|
||||
lua.Push(stream.Write(buffer, bufferSize));
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::File ***********************************/
|
||||
fileClass.Inherit(streamClass);
|
||||
|
||||
fileClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::File*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::File;
|
||||
|
||||
case 1:
|
||||
return new Nz::File(lua.Check<Nz::String>(&argIndex));
|
||||
|
||||
case 2:
|
||||
return new Nz::File(lua.Check<Nz::String>(&argIndex), lua.Check<Nz::UInt32>(&argIndex));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
fileClass.BindMethod("Close", &Nz::File::Close);
|
||||
fileClass.BindMethod("Copy", &Nz::File::Copy);
|
||||
fileClass.BindMethod("Delete", &Nz::File::Delete);
|
||||
fileClass.BindMethod("EndOfFile", &Nz::File::EndOfFile);
|
||||
fileClass.BindMethod("Exists", &Nz::File::Exists);
|
||||
fileClass.BindMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
||||
fileClass.BindMethod("GetFileName", &Nz::File::GetFileName);
|
||||
fileClass.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
||||
fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||
fileClass.BindMethod("IsOpen", &Nz::File::IsOpen);
|
||||
fileClass.BindMethod("Rename", &Nz::File::GetLastWriteTime);
|
||||
fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||
fileClass.BindMethod("SetFile", &Nz::File::GetLastWriteTime);
|
||||
|
||||
fileClass.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath);
|
||||
fileClass.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash);
|
||||
fileClass.BindStaticMethod("Copy", &Nz::File::Copy);
|
||||
fileClass.BindStaticMethod("Delete", &Nz::File::Delete);
|
||||
fileClass.BindStaticMethod("Exists", &Nz::File::Exists);
|
||||
//fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
||||
fileClass.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory);
|
||||
//fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
||||
//fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||
fileClass.BindStaticMethod("GetSize", &Nz::File::GetSize);
|
||||
fileClass.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute);
|
||||
fileClass.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath);
|
||||
fileClass.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators);
|
||||
fileClass.BindStaticMethod("Rename", &Nz::File::Rename);
|
||||
|
||||
// Manual
|
||||
fileClass.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return lua.Push(file.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
|
||||
case 2:
|
||||
return lua.Push(file.Open(lua.Check<Nz::String>(&argIndex), lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Open");
|
||||
return 0;
|
||||
});
|
||||
|
||||
fileClass.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
return lua.Push(file.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||
|
||||
case 2:
|
||||
return lua.Push(file.SetCursorPos(lua.Check<Nz::CursorPosition>(&argIndex), lua.Check<Nz::Int64>(&argIndex)));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetCursorPos");
|
||||
return 0;
|
||||
});
|
||||
|
||||
fileClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int {
|
||||
Nz::StringStream stream("File(");
|
||||
if (file.IsOpen())
|
||||
stream << "Path: " << file.GetPath();
|
||||
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterCore(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
clockClass.Register(instance);
|
||||
directoryClass.Register(instance);
|
||||
fileClass.Register(instance);
|
||||
streamClass.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
||||
// Nz::CursorPosition
|
||||
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.SetField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||
instance.SetField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||
instance.SetField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||
}
|
||||
instance.SetGlobal("CursorPosition");
|
||||
|
||||
// Nz::HashType
|
||||
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 9);
|
||||
{
|
||||
instance.SetField("CRC32", Nz::HashType_CRC32);
|
||||
instance.SetField("Fletcher16", Nz::HashType_Fletcher16);
|
||||
instance.SetField("MD5", Nz::HashType_MD5);
|
||||
instance.SetField("SHA1", Nz::HashType_SHA1);
|
||||
instance.SetField("SHA224", Nz::HashType_SHA224);
|
||||
instance.SetField("SHA256", Nz::HashType_SHA256);
|
||||
instance.SetField("SHA384", Nz::HashType_SHA384);
|
||||
instance.SetField("SHA512", Nz::HashType_SHA512);
|
||||
instance.SetField("Whirlpool", Nz::HashType_Whirlpool);
|
||||
}
|
||||
instance.SetGlobal("HashType");
|
||||
|
||||
// Nz::OpenMode
|
||||
static_assert(Nz::OpenMode_Max + 1 == 2 * (64), "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 8);
|
||||
{
|
||||
instance.SetField("Append", Nz::OpenMode_Append);
|
||||
instance.SetField("NotOpen", Nz::OpenMode_NotOpen);
|
||||
instance.SetField("Lock", Nz::OpenMode_Lock);
|
||||
instance.SetField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||
instance.SetField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||
instance.SetField("Text", Nz::OpenMode_Text);
|
||||
instance.SetField("Truncate", Nz::OpenMode_Truncate);
|
||||
instance.SetField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||
}
|
||||
instance.SetGlobal("OpenMode");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindGraphics()
|
||||
{
|
||||
/*********************************** Nz::InstancedRenderable ***********************************/
|
||||
|
||||
/*********************************** Nz::Model ***********************************/
|
||||
modelClass.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef*
|
||||
{
|
||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(model); //TODO: Make a ObjectRefCast
|
||||
});
|
||||
|
||||
modelClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::ModelRef*
|
||||
{
|
||||
return new Nz::ModelRef(new Nz::Model);
|
||||
});
|
||||
|
||||
//modelClass.SetMethod("GetMaterial", &Nz::Model::GetMaterial);
|
||||
modelClass.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
|
||||
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
|
||||
modelClass.BindMethod("GetSkin", &Nz::Model::GetSkin);
|
||||
modelClass.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
|
||||
|
||||
modelClass.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
|
||||
modelClass.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
|
||||
|
||||
modelClass.BindMethod("Reset", &Nz::Model::Reset);
|
||||
|
||||
//modelClass.SetMethod("SetMaterial", &Nz::Model::SetMaterial);
|
||||
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
|
||||
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
||||
modelClass.BindMethod("SetSkin", &Nz::Model::SetSkin);
|
||||
modelClass.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance)
|
||||
{
|
||||
instancedRenderable.Register(instance);
|
||||
modelClass.Register(instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,482 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindMath()
|
||||
{
|
||||
/*********************************** Nz::EulerAngles **********************************/
|
||||
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::EulerAnglesd*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::EulerAnglesd(0.0, 0.0, 0.0);
|
||||
|
||||
case 1:
|
||||
return new Nz::EulerAnglesd(*(*static_cast<Nz::EulerAnglesd**>(lua.CheckUserdata(1, "EulerAngles"))));
|
||||
|
||||
case 3:
|
||||
return new Nz::EulerAnglesd(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for EulerAngles constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
eulerAnglesClass.BindMethod("__tostring", &Nz::EulerAnglesd::ToString);
|
||||
|
||||
eulerAnglesClass.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* ypr = lua.CheckString(1, &length);
|
||||
|
||||
switch (length)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
switch (ypr[0])
|
||||
{
|
||||
case 'p':
|
||||
lua.Push(instance.pitch);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.yaw);
|
||||
return true;
|
||||
|
||||
case 'r':
|
||||
lua.Push(instance.roll);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||
break;
|
||||
|
||||
lua.Push(instance.yaw);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||
break;
|
||||
|
||||
lua.Push(instance.roll);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 5:
|
||||
{
|
||||
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||
break;
|
||||
|
||||
lua.Push(instance.pitch);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
eulerAnglesClass.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* ypr = lua.CheckString(1, &length);
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (length)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
switch (ypr[0])
|
||||
{
|
||||
case 'p':
|
||||
instance.pitch = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.yaw = value;
|
||||
return true;
|
||||
|
||||
case 'r':
|
||||
instance.roll = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||
break;
|
||||
|
||||
instance.yaw = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||
break;
|
||||
|
||||
instance.roll = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
case 5:
|
||||
{
|
||||
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||
break;
|
||||
|
||||
instance.pitch = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Quaternion **********************************/
|
||||
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Quaterniond*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::Quaterniond(1.0, 0.0, 0.0, 0.0);
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, "EulerAngles"))
|
||||
return new Nz::Quaterniond(*(*static_cast<Nz::EulerAnglesd**>(lua.ToUserdata(1))));
|
||||
else if (lua.IsOfType(1, "Quaternion"))
|
||||
return new Nz::Quaterniond(*(*static_cast<Nz::Quaterniond**>(lua.ToUserdata(1))));
|
||||
}
|
||||
|
||||
case 2:
|
||||
return new Nz::Quaterniond(lua.CheckNumber(1), *(*static_cast<Nz::Vector3d**>(lua.CheckUserdata(2, "Vector3"))));
|
||||
|
||||
case 4:
|
||||
return new Nz::Quaterniond(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Quaternion constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
quaternionClass.BindMethod("__tostring", &Nz::Quaterniond::ToString);
|
||||
|
||||
quaternionClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* wxyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
return false;
|
||||
|
||||
switch (wxyz[0])
|
||||
{
|
||||
case 'w':
|
||||
lua.Push(instance.w);
|
||||
return true;
|
||||
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
lua.Push(instance.z);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
quaternionClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* wxyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
return false;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (wxyz[0])
|
||||
{
|
||||
case 'w':
|
||||
instance.w = value;
|
||||
return true;
|
||||
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
instance.z = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Vector2 **********************************/
|
||||
vector2dClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Vector2d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
return new Nz::Vector2d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector2d(lua.CheckNumber(1));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector2d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Vector2 constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
vector2dClass.BindMethod("__tostring", &Nz::Vector2d::ToString);
|
||||
|
||||
vector2dClass.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 2)
|
||||
return false;
|
||||
|
||||
lua.Push(instance[index - 1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
vector2dClass.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 2)
|
||||
return false;
|
||||
|
||||
instance[index - 1] = lua.CheckNumber(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Vector3 **********************************/
|
||||
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 3:
|
||||
return new Nz::Vector3d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0));
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector3d(lua.CheckNumber(1), *(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||
else if (lua.IsOfType(1, "Vector3"))
|
||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector3d**>(lua.ToUserdata(1))));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector3d(lua.CheckNumber(1), *(*static_cast<Nz::Vector2d**>(lua.CheckUserdata(1, "Vector2"))));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))), lua.CheckNumber(2));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
vector3dClass.BindMethod("__tostring", &Nz::Vector3d::ToString);
|
||||
|
||||
vector3dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 3)
|
||||
return false;
|
||||
|
||||
lua.Push(instance[index - 1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
switch (xyz[0])
|
||||
{
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
lua.Push(instance.z);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
vector3dClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 3)
|
||||
return false;
|
||||
|
||||
instance[index - 1] = lua.CheckNumber(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (xyz[0])
|
||||
{
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
instance.z = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterMath(Nz::LuaInstance& instance)
|
||||
{
|
||||
eulerAnglesClass.Register(instance);
|
||||
quaternionClass.Register(instance);
|
||||
vector2dClass.Register(instance);
|
||||
vector3dClass.Register(instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindNetwork()
|
||||
{
|
||||
/*********************************** Nz::AbstractSocket **********************************/
|
||||
abstractSocketClass.BindMethod("Close", &Nz::AbstractSocket::Close);
|
||||
abstractSocketClass.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
|
||||
abstractSocketClass.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
|
||||
abstractSocketClass.BindMethod("GetState", &Nz::AbstractSocket::GetState);
|
||||
abstractSocketClass.BindMethod("GetType", &Nz::AbstractSocket::GetType);
|
||||
abstractSocketClass.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
|
||||
abstractSocketClass.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
|
||||
|
||||
/*********************************** Nz::IpAddress **********************************/
|
||||
ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::IpAddress*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 9U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::IpAddress;
|
||||
|
||||
case 1:
|
||||
return new Nz::IpAddress(lua.CheckString(argIndex));
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
return new Nz::IpAddress(lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
return new Nz::IpAddress(lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex),
|
||||
lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
ipAddressClass.BindMethod("GetPort", &Nz::IpAddress::GetPort);
|
||||
ipAddressClass.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol);
|
||||
ipAddressClass.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback);
|
||||
ipAddressClass.BindMethod("IsValid", &Nz::IpAddress::IsValid);
|
||||
ipAddressClass.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32);
|
||||
ipAddressClass.BindMethod("__tostring", &Nz::IpAddress::ToString);
|
||||
|
||||
ipAddressClass.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int
|
||||
{
|
||||
Nz::String service;
|
||||
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
||||
|
||||
int argIndex = 1;
|
||||
Nz::String hostName = Nz::IpAddress::ResolveAddress(instance.Check<Nz::IpAddress>(&argIndex), &service, &error);
|
||||
|
||||
if (error == Nz::ResolveError_NoError)
|
||||
{
|
||||
instance.Push(hostName);
|
||||
instance.Push(service);
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.PushBoolean(false);
|
||||
instance.Push(error);
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
ipAddressClass.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int
|
||||
{
|
||||
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
||||
|
||||
int argIndex = 1;
|
||||
Nz::NetProtocol protocol = instance.Check<Nz::NetProtocol>(&argIndex);
|
||||
Nz::String hostname = instance.Check<Nz::String>(&argIndex);
|
||||
Nz::String service = instance.Check<Nz::String>(&argIndex, "http");
|
||||
|
||||
std::vector<Nz::HostnameInfo> addresses = Nz::IpAddress::ResolveHostname(protocol, hostname, service, &error);
|
||||
if (error == Nz::ResolveError_NoError)
|
||||
{
|
||||
int index = 1;
|
||||
instance.PushTable(addresses.size());
|
||||
for (Nz::HostnameInfo& info : addresses)
|
||||
{
|
||||
instance.PushInteger(index++);
|
||||
instance.PushTable(0, 4);
|
||||
instance.SetField("Address", std::move(info.address));
|
||||
instance.SetField("CanonicalName", std::move(info.canonicalName));
|
||||
instance.SetField("Protocol", std::move(info.protocol));
|
||||
instance.SetField("SocketType", std::move(info.socketType));
|
||||
instance.SetTable();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.PushBoolean(false);
|
||||
instance.Push(error);
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
abstractSocketClass.Register(instance);
|
||||
ipAddressClass.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
||||
// Nz::NetProtocol
|
||||
static_assert(Nz::NetProtocol_Max + 1 == 4, "Nz::NetProtocol has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 4);
|
||||
{
|
||||
instance.SetField("Any", Nz::NetProtocol_Any);
|
||||
instance.SetField("IPv4", Nz::NetProtocol_IPv4);
|
||||
instance.SetField("IPv6", Nz::NetProtocol_IPv6);
|
||||
instance.SetField("Unknown", Nz::NetProtocol_Unknown);
|
||||
}
|
||||
instance.SetGlobal("NetProtocol");
|
||||
|
||||
// Nz::PacketPriority
|
||||
static_assert(Nz::PacketPriority_Max + 1 == 4, "Nz::PacketPriority has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 6);
|
||||
{
|
||||
instance.SetField("High", Nz::PacketPriority_High);
|
||||
instance.SetField("Highest", Nz::PacketPriority_Highest);
|
||||
instance.SetField("Immediate", Nz::PacketPriority_Immediate);
|
||||
instance.SetField("Medium", Nz::PacketPriority_Medium);
|
||||
instance.SetField("Low", Nz::PacketPriority_Low);
|
||||
instance.SetField("Lowest", Nz::PacketPriority_Lowest);
|
||||
}
|
||||
instance.SetGlobal("PacketPriority");
|
||||
|
||||
// Nz::PacketReliability
|
||||
static_assert(Nz::PacketReliability_Max + 1 == 3, "Nz::PacketReliability has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.SetField("Reliable", Nz::PacketReliability_Reliable);
|
||||
instance.SetField("ReliableOrdered", Nz::PacketReliability_ReliableOrdered);
|
||||
instance.SetField("Unreliable", Nz::PacketReliability_Unreliable);
|
||||
}
|
||||
instance.SetGlobal("PacketReliability");
|
||||
|
||||
// Nz::ResolveError
|
||||
static_assert(Nz::ResolveError_Max + 1 == 9, "Nz::ResolveError has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 9);
|
||||
{
|
||||
instance.SetField("Internal", Nz::ResolveError_Internal);
|
||||
instance.SetField("ResourceError", Nz::ResolveError_ResourceError);
|
||||
instance.SetField("NoError", Nz::ResolveError_NoError);
|
||||
instance.SetField("NonRecoverable", Nz::ResolveError_NonRecoverable);
|
||||
instance.SetField("NotFound", Nz::ResolveError_NotFound);
|
||||
instance.SetField("NotInitialized", Nz::ResolveError_NotInitialized);
|
||||
instance.SetField("ProtocolNotSupported", Nz::ResolveError_ProtocolNotSupported);
|
||||
instance.SetField("TemporaryFailure", Nz::ResolveError_TemporaryFailure);
|
||||
instance.SetField("Unknown", Nz::ResolveError_Unknown);
|
||||
}
|
||||
instance.SetGlobal("ResolveError");
|
||||
|
||||
// Nz::SocketError
|
||||
static_assert(Nz::SocketError_Max + 1 == 15, "Nz::ResolveError has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 15);
|
||||
{
|
||||
instance.SetField("AddressNotAvailable", Nz::SocketError_AddressNotAvailable);
|
||||
instance.SetField("ConnectionClosed", Nz::SocketError_ConnectionClosed);
|
||||
instance.SetField("ConnectionRefused", Nz::SocketError_ConnectionRefused);
|
||||
instance.SetField("DatagramSize", Nz::SocketError_DatagramSize);
|
||||
instance.SetField("Internal", Nz::SocketError_Internal);
|
||||
instance.SetField("Packet", Nz::SocketError_Packet);
|
||||
instance.SetField("NetworkError", Nz::SocketError_NetworkError);
|
||||
instance.SetField("NoError", Nz::SocketError_NoError);
|
||||
instance.SetField("NotInitialized", Nz::SocketError_NotInitialized);
|
||||
instance.SetField("NotSupported", Nz::SocketError_NotSupported);
|
||||
instance.SetField("ResolveError", Nz::SocketError_ResolveError);
|
||||
instance.SetField("ResourceError", Nz::SocketError_ResourceError);
|
||||
instance.SetField("TimedOut", Nz::SocketError_TimedOut);
|
||||
instance.SetField("Unknown", Nz::SocketError_Unknown);
|
||||
instance.SetField("UnreachableHost", Nz::SocketError_UnreachableHost);
|
||||
}
|
||||
instance.SetGlobal("SocketError");
|
||||
|
||||
// Nz::SocketState
|
||||
static_assert(Nz::SocketState_Max + 1 == 5, "Nz::SocketState has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 5);
|
||||
{
|
||||
instance.SetField("Bound", Nz::SocketState_Bound);
|
||||
instance.SetField("Connecting", Nz::SocketState_Connecting);
|
||||
instance.SetField("Connected", Nz::SocketState_Connected);
|
||||
instance.SetField("NotConnected", Nz::SocketState_NotConnected);
|
||||
instance.SetField("Resolving", Nz::SocketState_Resolving);
|
||||
}
|
||||
instance.SetGlobal("SocketState");
|
||||
|
||||
// Nz::SocketType
|
||||
static_assert(Nz::SocketType_Max + 1 == 4, "Nz::SocketState has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 4);
|
||||
{
|
||||
instance.SetField("Raw", Nz::SocketType_Raw);
|
||||
instance.SetField("TCP", Nz::SocketType_TCP);
|
||||
instance.SetField("UDP", Nz::SocketType_UDP);
|
||||
instance.SetField("Unknown", Nz::SocketType_Unknown);
|
||||
}
|
||||
instance.SetGlobal("SocketType");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,253 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace
|
||||
{
|
||||
int AddNilComponent(Nz::LuaInstance& lua, EntityHandle&)
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& component = handle->AddComponent<T>();
|
||||
lua.Push(component.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PushNilComponent(Nz::LuaInstance& lua, BaseComponent&)
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& rightComponent = static_cast<T&>(component);
|
||||
lua.Push(rightComponent.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void LuaBinding::BindSDK()
|
||||
{
|
||||
/*********************************** Ndk::Application **********************************/
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
//application.SetMethod("AddWindow", &Application::AddWindow);
|
||||
#endif
|
||||
application.BindMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application) -> int
|
||||
{
|
||||
instance.Push(application->AddWorld().CreateHandle());
|
||||
return 1;
|
||||
});
|
||||
|
||||
application.BindMethod("GetUpdateTime", &Application::GetUpdateTime);
|
||||
application.BindMethod("Quit", &Application::Quit);
|
||||
|
||||
/*********************************** Ndk::Console **********************************/
|
||||
#ifndef NDK_SERVER
|
||||
consoleClass.Inherit<Nz::Node>(nodeClass, [] (ConsoleHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
consoleClass.BindMethod("AddLine", &Console::AddLine, Nz::Color::White);
|
||||
consoleClass.BindMethod("Clear", &Console::Clear);
|
||||
consoleClass.BindMethod("GetCharacterSize", &Console::GetCharacterSize);
|
||||
consoleClass.BindMethod("GetHistory", &Console::GetHistory);
|
||||
consoleClass.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground);
|
||||
consoleClass.BindMethod("GetInput", &Console::GetInput);
|
||||
consoleClass.BindMethod("GetInputBackground", &Console::GetInputBackground);
|
||||
consoleClass.BindMethod("GetSize", &Console::GetSize);
|
||||
//consoleClass.SetMethod("GetTextFont", &Console::GetTextFont);
|
||||
|
||||
consoleClass.BindMethod("IsVisible", &Console::IsVisible);
|
||||
|
||||
consoleClass.BindMethod("SendCharacter", &Console::SendCharacter);
|
||||
//consoleClass.SetMethod("SendEvent", &Console::SendEvent);
|
||||
|
||||
consoleClass.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
|
||||
consoleClass.BindMethod("SetSize", &Console::SetSize);
|
||||
//consoleClass.SetMethod("SetTextFont", &Console::SetTextFont);
|
||||
|
||||
consoleClass.BindMethod("Show", &Console::Show, true);
|
||||
#endif
|
||||
|
||||
/*********************************** Ndk::Entity **********************************/
|
||||
entityClass.BindMethod("Enable", &Entity::Enable);
|
||||
entityClass.BindMethod("GetId", &Entity::GetId);
|
||||
entityClass.BindMethod("GetWorld", &Entity::GetWorld);
|
||||
entityClass.BindMethod("Kill", &Entity::Kill);
|
||||
entityClass.BindMethod("IsEnabled", &Entity::IsEnabled);
|
||||
entityClass.BindMethod("IsValid", &Entity::IsValid);
|
||||
entityClass.BindMethod("RemoveComponent", (void(Entity::*)(ComponentIndex)) &Entity::RemoveComponent);
|
||||
entityClass.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
|
||||
entityClass.BindMethod("__tostring", &EntityHandle::ToString);
|
||||
|
||||
entityClass.BindMethod("AddComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (!binding.valid)
|
||||
{
|
||||
lua.Error("This component is not available to the LuaAPI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return binding.adder(lua, handle);
|
||||
});
|
||||
|
||||
entityClass.BindMethod("GetComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
if (!handle->HasComponent(componentIndex))
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (!binding.valid)
|
||||
{
|
||||
lua.Error("This component is not available to the LuaAPI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return binding.getter(lua, handle->GetComponent(componentIndex));
|
||||
});
|
||||
|
||||
/*********************************** Ndk::NodeComponent **********************************/
|
||||
nodeComponent.Inherit<Nz::Node>(nodeClass, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
/*********************************** Ndk::VelocityComponent **********************************/
|
||||
velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(1, &length);
|
||||
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
lua.Push(instance->linearVelocity);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(1, &length);
|
||||
|
||||
int argIndex = 2;
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Ndk::World **********************************/
|
||||
worldClass.BindMethod("CreateEntity", &World::CreateEntity);
|
||||
worldClass.BindMethod("CreateEntities", &World::CreateEntities);
|
||||
worldClass.BindMethod("Clear", &World::Clear);
|
||||
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
/*********************************** Ndk::GraphicsComponent **********************************/
|
||||
graphicsComponent.BindMethod("Attach", &GraphicsComponent::Attach, 0);
|
||||
#endif
|
||||
|
||||
|
||||
// Components functions
|
||||
m_componentBinding.resize(BaseComponent::GetMaxComponentIndex() + 1);
|
||||
|
||||
EnableComponentBinding<NodeComponent>();
|
||||
EnableComponentBinding<VelocityComponent>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
EnableComponentBinding<GraphicsComponent>();
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void LuaBinding::EnableComponentBinding()
|
||||
{
|
||||
ComponentBinding binding;
|
||||
binding.adder = &AddComponentOfType<T>;
|
||||
binding.getter = &PushComponentOfType<T>;
|
||||
binding.valid = true;
|
||||
|
||||
NazaraAssert(T::componentIndex < m_componentBinding.size(), "Component index is over component binding size");
|
||||
|
||||
m_componentBinding[T::componentIndex] = std::move(binding);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterSDK(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
application.Register(instance);
|
||||
entityClass.Register(instance);
|
||||
nodeComponent.Register(instance);
|
||||
velocityComponent.Register(instance);
|
||||
worldClass.Register(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
consoleClass.Register(instance);
|
||||
graphicsComponent.Register(instance);
|
||||
#endif
|
||||
|
||||
// Enums
|
||||
|
||||
// ComponentType (fake enumeration to expose component indexes)
|
||||
instance.PushTable();
|
||||
{
|
||||
#ifndef NDK_SERVER
|
||||
instance.PushInteger(GraphicsComponent::componentIndex);
|
||||
instance.SetField("Graphics");
|
||||
#endif
|
||||
|
||||
instance.PushInteger(NodeComponent::componentIndex);
|
||||
instance.SetField("Node");
|
||||
|
||||
instance.PushInteger(VelocityComponent::componentIndex);
|
||||
instance.SetField("Velocity");
|
||||
}
|
||||
instance.SetGlobal("ComponentType");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindUtility()
|
||||
{
|
||||
/*********************************** Nz::AbstractImage **********************************/
|
||||
abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
||||
abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
|
||||
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||
|
||||
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return lua.Push(abstractImage->GetMemoryUsage());
|
||||
|
||||
case 1:
|
||||
{
|
||||
int index = 1;
|
||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&index));
|
||||
|
||||
return lua.Push(abstractImage->GetMemoryUsage(level));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 6U);
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
||||
|
||||
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
/* Disabled until Box and Rect have been ported
|
||||
else if (lua.IsOfType(2, "Box"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Rectui box = lua.Check<Nz::Rectui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}*/
|
||||
|
||||
lua.Error("No matching overload for method Update");
|
||||
return 0;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Node **********************************/
|
||||
nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||
//nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds);
|
||||
nodeClass.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||
nodeClass.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||
nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||
nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||
nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||
nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||
//nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||
nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||
nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||
nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||
//nodeClass.SetMethod("GetParent", &Nz::Node::GetParent);
|
||||
nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||
//nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||
//nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix);
|
||||
nodeClass.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||
|
||||
nodeClass.BindMethod("HasChilds", &Nz::Node::HasChilds);
|
||||
|
||||
nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||
nodeClass.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||
nodeClass.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||
nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||
nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||
nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||
nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||
nodeClass.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||
nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||
nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||
nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||
nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||
nodeClass.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||
|
||||
nodeClass.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
|
||||
nodeClass.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation);
|
||||
|
||||
nodeClass.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
|
||||
nodeClass.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
|
||||
|
||||
nodeClass.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
int argIndex = 1;
|
||||
|
||||
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.Move(offset, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
int argIndex = 1;
|
||||
|
||||
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.Rotate(rotation, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
node.Scale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Scale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
float scale = lua.Check<float>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.SetScale(scale, coordSys);
|
||||
}
|
||||
else
|
||||
node.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
{
|
||||
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
|
||||
node.SetScale(scale, coordSys);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetScale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
node.SetInitialScale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
node.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
node.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetInitialScale");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterUtility(Nz::LuaInstance& instance)
|
||||
{
|
||||
abstractImage.Register(instance);
|
||||
nodeClass.Register(instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -13,64 +13,80 @@
|
|||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/BaseSystem.hpp>
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/CollisionComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool Sdk::Initialize()
|
||||
{
|
||||
if (s_referenceCounter++ > 0)
|
||||
return true; // Déjà initialisé
|
||||
return true; // Already initialized
|
||||
|
||||
try
|
||||
{
|
||||
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
|
||||
|
||||
// Initialisation du moteur
|
||||
// Initialize the engine first
|
||||
|
||||
// Modules clients
|
||||
Nz::Audio::Initialize();
|
||||
Nz::Graphics::Initialize();
|
||||
|
||||
// Modules serveurs
|
||||
// Shared modules
|
||||
Nz::Lua::Initialize();
|
||||
Nz::Noise::Initialize();
|
||||
Nz::Physics::Initialize();
|
||||
Nz::Utility::Initialize();
|
||||
|
||||
// Initialisation du SDK
|
||||
#ifndef NDK_SERVER
|
||||
// Client modules
|
||||
Nz::Audio::Initialize();
|
||||
Nz::Graphics::Initialize();
|
||||
#endif
|
||||
|
||||
// Initialisation des composants et systèmes
|
||||
// SDK Initialization
|
||||
|
||||
// Components
|
||||
BaseComponent::Initialize();
|
||||
BaseSystem::Initialize();
|
||||
|
||||
// Composants
|
||||
InitializeComponent<CameraComponent>("NdkCam");
|
||||
// Shared components
|
||||
InitializeComponent<CollisionComponent>("NdkColli");
|
||||
InitializeComponent<LightComponent>("NdkLight");
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<GraphicsComponent>("NdkGfx");
|
||||
InitializeComponent<NodeComponent>("NdkNode");
|
||||
InitializeComponent<PhysicsComponent>("NdkPhys");
|
||||
InitializeComponent<VelocityComponent>("NdkVeloc");
|
||||
|
||||
// Systèmes
|
||||
InitializeSystem<ListenerSystem>();
|
||||
#ifndef NDK_SERVER
|
||||
// Client components
|
||||
InitializeComponent<CameraComponent>("NdkCam");
|
||||
InitializeComponent<LightComponent>("NdkLight");
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<GraphicsComponent>("NdkGfx");
|
||||
#endif
|
||||
|
||||
// Systems
|
||||
|
||||
BaseSystem::Initialize();
|
||||
|
||||
// Shared systems
|
||||
InitializeSystem<PhysicsSystem>();
|
||||
InitializeSystem<RenderSystem>();
|
||||
InitializeSystem<VelocitySystem>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Client systems
|
||||
InitializeSystem<ListenerSystem>();
|
||||
InitializeSystem<RenderSystem>();
|
||||
#endif
|
||||
|
||||
NazaraNotice("Initialized: SDK");
|
||||
return true;
|
||||
}
|
||||
|
|
@ -86,23 +102,25 @@ namespace Ndk
|
|||
{
|
||||
if (s_referenceCounter != 1)
|
||||
{
|
||||
// Le module est soit encore utilisé, soit pas initialisé
|
||||
// Either the module is not initialized, either it was initialized multiple times
|
||||
if (s_referenceCounter > 1)
|
||||
s_referenceCounter--;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Libération du SDK
|
||||
// Uninitialize the SDK
|
||||
s_referenceCounter = 0;
|
||||
|
||||
// Libération du moteur
|
||||
// Uninitialize the engine
|
||||
|
||||
// Modules clients
|
||||
#ifndef NDK_SERVER
|
||||
// Client modules
|
||||
Nz::Audio::Uninitialize();
|
||||
Nz::Graphics::Uninitialize();
|
||||
#endif
|
||||
|
||||
// Modules serveurs
|
||||
// Shared modules
|
||||
Nz::Lua::Uninitialize();
|
||||
Nz::Noise::Uninitialize();
|
||||
Nz::Physics::Uninitialize();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace Ndk
|
|||
m_coordinateSystemMatrix(Nz::Matrix4f::Identity()),
|
||||
m_coordinateSystemInvalidated(true)
|
||||
{
|
||||
ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
|
||||
SetDefaultBackground(Nz::ColorBackground::New());
|
||||
SetUpdateRate(0.f);
|
||||
}
|
||||
|
|
@ -95,7 +96,7 @@ namespace Ndk
|
|||
|
||||
//UpdateDirectionalShadowMaps(camComponent);
|
||||
|
||||
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue();
|
||||
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue();
|
||||
renderQueue->Clear();
|
||||
|
||||
//TODO: Culling
|
||||
|
|
@ -123,7 +124,8 @@ namespace Ndk
|
|||
sceneData.background = m_background;
|
||||
sceneData.viewer = &camComponent;
|
||||
|
||||
m_renderTechnique.Draw(sceneData);
|
||||
m_renderTechnique->Clear(sceneData);
|
||||
m_renderTechnique->Draw(sceneData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,17 @@
|
|||
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
World::~World()
|
||||
World::~World() noexcept
|
||||
{
|
||||
// La destruction doit se faire dans un ordre précis
|
||||
Clear();
|
||||
|
|
@ -19,10 +22,13 @@ namespace Ndk
|
|||
|
||||
void World::AddDefaultSystems()
|
||||
{
|
||||
AddSystem<ListenerSystem>();
|
||||
AddSystem<PhysicsSystem>();
|
||||
AddSystem<RenderSystem>();
|
||||
AddSystem<VelocitySystem>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
AddSystem<ListenerSystem>();
|
||||
AddSystem<RenderSystem>();
|
||||
#endif
|
||||
}
|
||||
|
||||
const EntityHandle& World::CreateEntity()
|
||||
|
|
@ -40,7 +46,7 @@ namespace Ndk
|
|||
id = m_entities.size();
|
||||
|
||||
// Impossible d'utiliser emplace_back à cause de la portée
|
||||
m_entities.push_back(Entity(*this, id));
|
||||
m_entities.push_back(Entity(this, id));
|
||||
}
|
||||
|
||||
// On initialise l'entité et on l'ajoute à la liste des entités vivantes
|
||||
|
|
@ -53,9 +59,9 @@ namespace Ndk
|
|||
return m_aliveEntities.back();
|
||||
}
|
||||
|
||||
void World::Clear()
|
||||
void World::Clear() noexcept
|
||||
{
|
||||
///DOC: Tous les handles sont correctement invalidés
|
||||
///DOC: Tous les handles sont correctement invalidés, les entités sont immédiatement invalidées
|
||||
|
||||
// Destruction des entités d'abord, et des handles ensuite
|
||||
// ceci pour éviter que les handles n'informent les entités inutilement lors de leur destruction
|
||||
|
|
@ -127,33 +133,33 @@ namespace Ndk
|
|||
|
||||
Entity* entity = &m_entities[i].entity;
|
||||
|
||||
// Aucun intérêt de traiter une entité n'existant plus
|
||||
if (entity->IsValid())
|
||||
// Check entity validity (as it could have been reported as dirty and killed during the same iteration)
|
||||
if (!entity->IsValid())
|
||||
continue;
|
||||
|
||||
for (auto& system : m_systems)
|
||||
{
|
||||
for (auto& system : m_systems)
|
||||
// Ignore non-existent systems
|
||||
if (!system)
|
||||
continue;
|
||||
|
||||
// Is our entity already part of this system?
|
||||
bool partOfSystem = system->HasEntity(entity);
|
||||
|
||||
// Should it be part of it?
|
||||
if (entity->IsEnabled() && system->Filters(entity))
|
||||
{
|
||||
// Ignore non-existent systems
|
||||
if (!system)
|
||||
continue;
|
||||
// Yes it should, add it to the system if not already done and validate it (again)
|
||||
if (!partOfSystem)
|
||||
system->AddEntity(entity);
|
||||
|
||||
// L'entité est-elle enregistrée comme faisant partie du système ?
|
||||
bool partOfSystem = system->HasEntity(entity);
|
||||
|
||||
// Doit-elle en faire partie ?
|
||||
if (system->Filters(entity))
|
||||
{
|
||||
// L'entité doit faire partie du système, revalidons-là (événement système) ou ajoutons-la au système
|
||||
if (!partOfSystem)
|
||||
system->AddEntity(entity);
|
||||
|
||||
system->ValidateEntity(entity, !partOfSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Elle ne doit pas en faire partie, si elle en faisait partie nous devons la retirer
|
||||
if (partOfSystem)
|
||||
system->RemoveEntity(entity);
|
||||
}
|
||||
system->ValidateEntity(entity, !partOfSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, it shouldn't, remove it if it's part of the system
|
||||
if (partOfSystem)
|
||||
system->RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
premake4 --with-extlibs --with-examples codelite
|
||||
premake5 --with-extlibs --with-examples codelite
|
||||
|
|
@ -1 +1 @@
|
|||
premake4 --united --with-extlibs --with-examples codelite
|
||||
premake5 --united --with-extlibs --with-examples codelite
|
||||
|
|
@ -1 +0,0 @@
|
|||
premake4 --with-extlibs --with-examples vs2013
|
||||
|
|
@ -1 +0,0 @@
|
|||
premake4 --united --with-extlibs --with-examples vs2013
|
||||
|
|
@ -0,0 +1 @@
|
|||
premake5 --with-extlibs --with-examples vs2015
|
||||
|
|
@ -0,0 +1 @@
|
|||
premake5 --united --with-extlibs --with-examples vs2015
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
premake4 encoderesources
|
||||
premake5 encoderesources
|
||||
pause
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
premake4 generateheaders
|
||||
premake5 generateheaders
|
||||
pause
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
premake4 parseunicode
|
||||
premake5 parseunicode
|
||||
pause
|
||||
|
|
@ -1,11 +1,20 @@
|
|||
ACTION.Name = "GenerateHeaders"
|
||||
ACTION.Description = "Generate a global header for each module"
|
||||
|
||||
ACTION.ModuleExcludes = {}
|
||||
ACTION.ModuleExcludes["ConfigCheck.hpp"] = true
|
||||
ACTION.ModuleExcludes["Debug.hpp"] = true
|
||||
ACTION.ModuleExcludes["DebugOff.hpp"] = true
|
||||
ACTION.ModuleExcludes["ThreadSafety.hpp"] = true
|
||||
ACTION.ModuleExcludes["ThreadSafetyOff.hpp"] = true
|
||||
|
||||
local action = ACTION
|
||||
ACTION.Function = function ()
|
||||
local paths = {}
|
||||
|
||||
local modules = os.matchdirs("../include/Nazara/*")
|
||||
for k, modulePath in pairs(modules) do
|
||||
local moduleName = modulePath:match(".*/(.*)")
|
||||
print(moduleName)
|
||||
|
||||
local config, err = io.open(modulePath .. "/Config.hpp", "r")
|
||||
local head = ""
|
||||
|
|
@ -14,44 +23,72 @@ ACTION.Function = function ()
|
|||
end
|
||||
|
||||
for line in config:lines() do
|
||||
head = head .. line .. "\n"
|
||||
if (line == "#pragma once") then -- On s'arrête au #pragma once, qu'on inclut quand même
|
||||
if (line == "#pragma once") then -- Stop before including the #pragma once as it's already written automatically
|
||||
break
|
||||
end
|
||||
head = head .. line .. "\n"
|
||||
end
|
||||
|
||||
config:close()
|
||||
|
||||
local header, err = io.open(modulePath .. ".hpp", "w+")
|
||||
table.insert(paths, {
|
||||
Excludes = action.ModuleExcludes,
|
||||
Header = head,
|
||||
HeaderGuard = "NAZARA_GLOBAL_" .. moduleName:upper() .. "_HPP",
|
||||
Name = "Nazara" .. moduleName,
|
||||
SearchDir = modulePath,
|
||||
Target = modulePath .. ".hpp",
|
||||
TopDir = "Nazara"
|
||||
})
|
||||
end
|
||||
|
||||
table.insert(paths, {
|
||||
Excludes = {},
|
||||
HeaderGuard = "NDK_COMPONENTS_GLOBAL_HPP",
|
||||
Name = "NDK Components",
|
||||
SearchDir = "../SDK/include/NDK/Components",
|
||||
TopDir = "NDK",
|
||||
Target = "../SDK/include/NDK/Components.hpp"
|
||||
})
|
||||
|
||||
table.insert(paths, {
|
||||
Excludes = {},
|
||||
HeaderGuard = "NDK_SYSTEMS_GLOBAL_HPP",
|
||||
Name = "NDK Systems",
|
||||
SearchDir = "../SDK/include/NDK/Systems",
|
||||
TopDir = "NDK",
|
||||
Target = "../SDK/include/NDK/Systems.hpp"
|
||||
})
|
||||
|
||||
for k,v in ipairs(paths) do
|
||||
print(v.Name)
|
||||
local header, err = io.open(v.Target, "w+")
|
||||
if (not header) then
|
||||
error("Failed to create header file: " .. err)
|
||||
error("Failed to create header file (" .. v.Target .. "): " .. err)
|
||||
end
|
||||
|
||||
header:write("// This file was automatically generated on " .. os.date("%d %b %Y at %X") .. "\n\n")
|
||||
header:write(head .. "\n")
|
||||
if (v.Header) then
|
||||
header:write(v.Header)
|
||||
end
|
||||
|
||||
-- Protection du multi-including
|
||||
local preprocessorName = "NAZARA_GLOBAL_" .. string.upper(moduleName) .. "_HPP"
|
||||
header:write("#ifndef " .. preprocessorName .. "\n")
|
||||
header:write("#define " .. preprocessorName .. "\n\n")
|
||||
header:write("#pragma once\n\n")
|
||||
header:write("#ifndef " .. v.HeaderGuard .. "\n")
|
||||
header:write("#define " .. v.HeaderGuard .. "\n\n")
|
||||
|
||||
local files = os.matchfiles(modulePath .. "/*.hpp")
|
||||
local files = os.matchfiles(v.SearchDir .. "/*.hpp")
|
||||
local count = 0
|
||||
for k, filePath in pairs(files) do
|
||||
local include, fileName = filePath:match(".*(Nazara/.*/(.*))")
|
||||
if (fileName ~= "ConfigCheck.hpp" and
|
||||
fileName ~= "Debug.hpp" and
|
||||
fileName ~= "DebugOff.hpp" and
|
||||
fileName ~= "ThreadSafety.hpp" and
|
||||
fileName ~= "ThreadSafetyOff.hpp") then
|
||||
local include, fileName = filePath:match(".*(" .. v.TopDir .. "/.*/(.*))")
|
||||
if (not v.Excludes[fileName]) then
|
||||
header:write("#include <" .. include .. ">\n")
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
header:write("\n#endif // " .. preprocessorName .. "\n")
|
||||
|
||||
header:write("\n#endif // " .. v.HeaderGuard .. "\n")
|
||||
header:close()
|
||||
|
||||
|
||||
print(string.format("-#include count: %d", count))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ function NazaraBuild:Execute()
|
|||
local makeLibDir = os.is("windows") and "mingw" or "gmake"
|
||||
|
||||
if (#self.OrderedExtLibs > 0) then
|
||||
solution("NazaraExtlibs")
|
||||
workspace("NazaraExtlibs")
|
||||
platforms({"x32", "x64"})
|
||||
|
||||
-- Configuration générale
|
||||
|
|
@ -60,7 +60,10 @@ function NazaraBuild:Execute()
|
|||
flags("Symbols")
|
||||
|
||||
configuration("Release*")
|
||||
flags({"EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer", "NoRTTI"})
|
||||
flags("NoFramePointer")
|
||||
optimize("Speed")
|
||||
rtti("Off")
|
||||
vectorextensions("SSE2")
|
||||
|
||||
configuration({"Release*", "codeblocks or codelite or gmake or xcode3 or xcode4"})
|
||||
buildoptions("-mfpmath=sse") -- Utilisation du SSE pour les calculs flottants
|
||||
|
|
@ -98,7 +101,7 @@ function NazaraBuild:Execute()
|
|||
end
|
||||
end
|
||||
|
||||
solution("NazaraEngine")
|
||||
workspace("NazaraEngine")
|
||||
platforms({"x32", "x64"})
|
||||
|
||||
-- Configuration générale
|
||||
|
|
@ -117,7 +120,10 @@ function NazaraBuild:Execute()
|
|||
flags("Symbols")
|
||||
|
||||
configuration("Release*")
|
||||
flags({"EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer", "NoRTTI"})
|
||||
flags("NoFramePointer")
|
||||
optimize("Speed")
|
||||
rtti("Off")
|
||||
vectorextensions("SSE2")
|
||||
|
||||
configuration({"Release*", "codeblocks or codelite or gmake or xcode3 or xcode4"})
|
||||
buildoptions("-mfpmath=sse") -- Utilisation du SSE pour les calculs flottants
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ TOOL.Defines = {
|
|||
}
|
||||
|
||||
TOOL.Includes = {
|
||||
"../SDK/include"
|
||||
"../SDK/include",
|
||||
"../SDK/src"
|
||||
}
|
||||
|
||||
TOOL.Files = {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
TOOL.Name = "SDKServer"
|
||||
|
||||
TOOL.Directory = "../SDK/lib"
|
||||
TOOL.Kind = "Library"
|
||||
|
||||
TOOL.Defines = {
|
||||
"NDK_BUILD",
|
||||
"NDK_SERVER"
|
||||
}
|
||||
|
||||
TOOL.Includes = {
|
||||
"../SDK/include",
|
||||
"../SDK/src"
|
||||
}
|
||||
|
||||
TOOL.Files = {
|
||||
"../SDK/include/NDK/**.hpp",
|
||||
"../SDK/include/NDK/**.inl",
|
||||
"../SDK/src/NDK/**.hpp",
|
||||
"../SDK/src/NDK/**.inl",
|
||||
"../SDK/src/NDK/**.cpp"
|
||||
}
|
||||
|
||||
-- Exlude client-only files
|
||||
TOOL.FilesExclusion = {
|
||||
"../SDK/**/CameraComponent.*",
|
||||
"../SDK/**/Console.*",
|
||||
"../SDK/**/GraphicsComponent.*",
|
||||
"../SDK/**/LightComponent.*",
|
||||
"../SDK/**/ListenerComponent.*",
|
||||
"../SDK/**/ListenerSystem.*",
|
||||
"../SDK/**/RenderSystem.*",
|
||||
"../SDK/**/LuaBinding_Audio.*",
|
||||
"../SDK/**/LuaBinding_Graphics.*",
|
||||
"../SDK/**/LuaBinding_Renderer.*"
|
||||
}
|
||||
|
||||
TOOL.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraLua",
|
||||
"NazaraNoise",
|
||||
"NazaraPhysics",
|
||||
"NazaraUtility"
|
||||
}
|
||||
|
|
@ -13,12 +13,13 @@
|
|||
#include <Nazara/Core/Thread.hpp> // Thread::Sleep
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Utility/Keyboard.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
// NzKeyboard ne nécessite pas l'initialisation du module Utilitaire
|
||||
Nz::Initializer<Nz::Audio> audio;
|
||||
// NzKeyboard nécessite l'initialisation du module Utilitaire
|
||||
Nz::Initializer<Nz::Audio, Nz::Utility> audio;
|
||||
if (!audio)
|
||||
{
|
||||
std::cout << "Failed to initialize audio module" << std::endl;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
EXAMPLE.Name = "Tut01_HelloWorld"
|
||||
|
||||
EXAMPLE.Console = true
|
||||
|
||||
EXAMPLE.Files = {
|
||||
"main.cpp"
|
||||
}
|
||||
|
||||
EXAMPLE.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraGraphics",
|
||||
"NazaraUtility",
|
||||
"NazaraSDK"
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel-01---Hello-World
|
||||
|
||||
#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()
|
||||
{
|
||||
Ndk::Application application;
|
||||
|
||||
Nz::RenderWindow& mainWindow = application.AddWindow<Nz::RenderWindow>();
|
||||
mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test");
|
||||
|
||||
Ndk::World& world = application.AddWorld();
|
||||
world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
|
||||
world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(192, 100, 100)));
|
||||
|
||||
|
||||
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::TextSpriteRef textSprite = Nz::TextSprite::New();
|
||||
textSprite->Update(Nz::SimpleTextDrawer::Draw("Hello world !", 72));
|
||||
|
||||
Ndk::EntityHandle text = world.CreateEntity();
|
||||
Ndk::NodeComponent& nodeComponent = text->AddComponent<Ndk::NodeComponent>();
|
||||
|
||||
Ndk::GraphicsComponent& graphicsComponent = text->AddComponent<Ndk::GraphicsComponent>();
|
||||
graphicsComponent.Attach(textSprite);
|
||||
|
||||
Nz::Boxf textBox = graphicsComponent.GetBoundingVolume().aabb;
|
||||
nodeComponent.SetPosition(mainWindow.GetWidth() / 2 - textBox.width / 2, mainWindow.GetHeight() / 2 - textBox.height / 2);
|
||||
|
||||
while (application.Run())
|
||||
{
|
||||
Nz::WindowEvent event;
|
||||
while (mainWindow.PollEvent(&event))
|
||||
{
|
||||
if (event.type == Nz::WindowEventType_Quit)
|
||||
application.Quit();
|
||||
}
|
||||
|
||||
mainWindow.Display();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -12,10 +12,11 @@
|
|||
#include <Nazara/Audio/SoundEmitter.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct MusicParams
|
||||
struct MusicParams : ResourceParameters
|
||||
{
|
||||
bool forceMono = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ namespace Nz
|
|||
|
||||
static bool IsInitialized();
|
||||
|
||||
static unsigned int QueryInputDevices(std::vector<String>& devices);
|
||||
static unsigned int QueryOutputDevices(std::vector<String>& devices);
|
||||
static std::size_t QueryInputDevices(std::vector<String>& devices);
|
||||
static std::size_t QueryOutputDevices(std::vector<String>& devices);
|
||||
|
||||
static bool SetDevice(const String& deviceName);
|
||||
|
||||
|
|
@ -87,7 +87,6 @@ namespace Nz
|
|||
static bool OpenDevice();
|
||||
static OpenALFunc LoadEntry(const char* name, bool throwException = false);
|
||||
};
|
||||
}
|
||||
|
||||
// al
|
||||
NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFER3F alBuffer3f;
|
||||
|
|
@ -186,6 +185,8 @@ NAZARA_AUDIO_API extern OpenALDetail::LPALCOPENDEVICE alcOpenDevice;
|
|||
NAZARA_AUDIO_API extern OpenALDetail::LPALCPROCESSCONTEXT alcProcessContext;
|
||||
NAZARA_AUDIO_API extern OpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext;
|
||||
|
||||
}
|
||||
|
||||
#endif // NAZARA_AUDIO_OPENAL
|
||||
|
||||
#endif // NAZARA_OPENAL_HPP
|
||||
|
|
|
|||
|
|
@ -16,12 +16,13 @@
|
|||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct SoundBufferParams
|
||||
struct SoundBufferParams : ResourceParameters
|
||||
{
|
||||
bool forceMono = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// This file was automatically generated on 20 Nov 2015 at 14:22:32
|
||||
// This file was automatically generated on 03 Feb 2016 at 00:06:56
|
||||
|
||||
/*
|
||||
Nazara Engine - Core module
|
||||
|
|
@ -30,9 +30,11 @@
|
|||
#define NAZARA_GLOBAL_CORE_HPP
|
||||
|
||||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <Nazara/Core/AbstractLogger.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/ByteStream.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
|
|
@ -46,6 +48,7 @@
|
|||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/FileLogger.hpp>
|
||||
#include <Nazara/Core/Functor.hpp>
|
||||
#include <Nazara/Core/GuillotineBinPack.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
|
|
@ -55,6 +58,7 @@
|
|||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <Nazara/Core/MemoryManager.hpp>
|
||||
#include <Nazara/Core/MemoryPool.hpp>
|
||||
#include <Nazara/Core/MemoryStream.hpp>
|
||||
#include <Nazara/Core/MemoryView.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
|
|
@ -70,16 +74,15 @@
|
|||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/Semaphore.hpp>
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <Nazara/Core/Serializer.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/SparsePtr.hpp>
|
||||
#include <Nazara/Core/StdLogger.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/TaskScheduler.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <Nazara/Core/Unicode.hpp>
|
||||
#include <Nazara/Core/Unserializer.hpp>
|
||||
#include <Nazara/Core/Updatable.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_CORE_HPP
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::AbstractLogger
|
||||
* \brief Logger interface
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -23,8 +23,16 @@ namespace Nz
|
|||
template<typename O, typename F, typename Tuple> auto Apply(O& object, F&& fn, Tuple&& t);
|
||||
template<typename T> ByteArray ComputeHash(HashType hash, const T& v);
|
||||
template<typename T> ByteArray ComputeHash(AbstractHash* hash, const T& v);
|
||||
template<typename T, std::size_t N> constexpr std::size_t CountOf(T(&name)[N]) noexcept;
|
||||
template<typename T> std::size_t CountOf(const T& c);
|
||||
template<typename T> void HashCombine(std::size_t& seed, const T& v);
|
||||
|
||||
template<typename T>
|
||||
struct PointedType
|
||||
{
|
||||
using type = void; //< FIXME: I can't make SFINAE work
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct TypeTag {};
|
||||
|
||||
|
|
@ -33,10 +41,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value);
|
||||
|
||||
inline bool Unserialize(UnserializationContext& context, bool* value);
|
||||
inline bool Unserialize(SerializationContext& context, bool* value);
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(UnserializationContext& context, T* value);
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Algorithm.inl>
|
||||
|
|
|
|||
|
|
@ -30,6 +30,16 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Applies the tuple to the function (e.g. calls the function using the tuple content as arguments)
|
||||
* \return The result of the function
|
||||
*
|
||||
* \param fn Function
|
||||
* \param t Tuple of arguments for the function
|
||||
*
|
||||
* \see Apply
|
||||
*/
|
||||
template<typename F, typename Tuple>
|
||||
auto Apply(F&& fn, Tuple&& t)
|
||||
{
|
||||
|
|
@ -38,6 +48,17 @@ namespace Nz
|
|||
return Detail::ApplyImplFunc(std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Applies the tuple to the member function on an object (e.g. calls the member function using the tuple content as arguments)
|
||||
* \return The result of the member function called
|
||||
*
|
||||
* \param object Object of a class
|
||||
* \param fn Member function
|
||||
* \param t Tuple of arguments for the member function
|
||||
*
|
||||
* \see Apply
|
||||
*/
|
||||
template<typename O, typename F, typename Tuple>
|
||||
auto Apply(O& object, F&& fn, Tuple&& t)
|
||||
{
|
||||
|
|
@ -46,15 +67,42 @@ namespace Nz
|
|||
return Detail::ApplyImplMethod(object, std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Computes the hash of a hashable object
|
||||
* \return A bytearray which represents the hash
|
||||
*
|
||||
* \param hash Enumeration of type HashType
|
||||
* \param v Object to hash
|
||||
*
|
||||
* \remark a HashAppend specialization for type T is required
|
||||
*
|
||||
* \see ComputeHash
|
||||
*/
|
||||
template<typename T>
|
||||
ByteArray ComputeHash(HashType hash, const T& v)
|
||||
{
|
||||
return ComputeHash(AbstractHash::Get(hash).get(), v);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Computes the hash of a hashable object
|
||||
* \return A bytearray which represents the hash
|
||||
*
|
||||
* \param hash Pointer to abstract hash
|
||||
* \param v Object to hash
|
||||
*
|
||||
* \remark Produce a NazaraAssert if pointer to Abstracthash is invalid
|
||||
* \remark a HashAppend specialization for type T is required
|
||||
*
|
||||
* \see ComputeHash
|
||||
*/
|
||||
template<typename T>
|
||||
ByteArray ComputeHash(AbstractHash* hash, const T& v)
|
||||
{
|
||||
NazaraAssert(hash != nullptr, "Invalid abstracthash pointer");
|
||||
|
||||
hash->Begin();
|
||||
|
||||
HashAppend(hash, v);
|
||||
|
|
@ -62,7 +110,44 @@ namespace Nz
|
|||
return hash->End();
|
||||
}
|
||||
|
||||
// Algorithme venant de CityHash par Google
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Returns the number of elements in a C-array
|
||||
* \return The number of elements
|
||||
*
|
||||
* \param name C-array
|
||||
*
|
||||
* \see CountOf
|
||||
*/
|
||||
template<typename T, std::size_t N>
|
||||
constexpr std::size_t CountOf(T(&name)[N]) noexcept
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Returns the number of elements in a container
|
||||
* \return The number of elements
|
||||
*
|
||||
* \param c Container with the member function "size()"
|
||||
*
|
||||
* \see CountOf
|
||||
*/
|
||||
template<typename T>
|
||||
std::size_t CountOf(const T& c)
|
||||
{
|
||||
return c.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Combines two hash in one
|
||||
*
|
||||
* \param seed First value that will be modified (expected to be 64bits)
|
||||
* \param v Second value to hash
|
||||
*/
|
||||
// Algorithm from CityHash by Google
|
||||
// http://stackoverflow.com/questions/8513911/how-to-create-a-good-hash-combine-with-64-bit-output-inspired-by-boosthash-co
|
||||
template<typename T>
|
||||
void HashCombine(std::size_t& seed, const T& v)
|
||||
|
|
@ -79,6 +164,21 @@ namespace Nz
|
|||
seed = static_cast<std::size_t>(b * kMul);
|
||||
}
|
||||
|
||||
template<typename T> struct PointedType<T*> {typedef T type;};
|
||||
template<typename T> struct PointedType<T* const> {typedef T type;};
|
||||
template<typename T> struct PointedType<T* volatile> {typedef T type;};
|
||||
template<typename T> struct PointedType<T* const volatile> {typedef T type;};
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Serializes a boolean
|
||||
* \return true if serialization succedeed
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value Boolean to serialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
inline bool Serialize(SerializationContext& context, bool value)
|
||||
{
|
||||
if (context.currentBitPos == 8)
|
||||
|
|
@ -96,6 +196,16 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Serializes an arithmetic type
|
||||
* \return true if serialization succedeed
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value Arithmetic type to serialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value)
|
||||
{
|
||||
|
|
@ -114,10 +224,18 @@ namespace Nz
|
|||
return context.stream->Write(&value, sizeof(T)) == sizeof(T);
|
||||
}
|
||||
|
||||
inline bool Unserialize(UnserializationContext& context, bool* value)
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Unserializes a boolean
|
||||
* \return true if unserialization succedeed
|
||||
*
|
||||
* \param context Context for the unserialization
|
||||
* \param value Pointer to boolean to unserialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
inline bool Unserialize(SerializationContext& context, bool* value)
|
||||
{
|
||||
NazaraAssert(value, "Invalid data pointer");
|
||||
|
||||
if (context.currentBitPos == 8)
|
||||
{
|
||||
if (!Unserialize(context, &context.currentByte))
|
||||
|
|
@ -134,8 +252,20 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Unserializes an arithmetic type
|
||||
* \return true if unserialization succedeed
|
||||
*
|
||||
* \param context Context for the unserialization
|
||||
* \param value Pointer to arithmetic type to serialize
|
||||
*
|
||||
* \remark Produce a NazaraAssert if pointer to value is invalid
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(UnserializationContext& context, T* value)
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value)
|
||||
{
|
||||
NazaraAssert(value, "Invalid data pointer");
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
|
|
@ -31,9 +32,9 @@ namespace Nz
|
|||
Bitset(const Bitset& bitset) = default;
|
||||
explicit Bitset(const String& bits);
|
||||
Bitset(Bitset&& bitset) noexcept = default;
|
||||
~Bitset() = default;
|
||||
~Bitset() noexcept = default;
|
||||
|
||||
void Clear();
|
||||
void Clear() noexcept;
|
||||
unsigned int Count() const;
|
||||
void Flip();
|
||||
|
||||
|
|
@ -89,9 +90,9 @@ namespace Nz
|
|||
Bitset& operator|=(const Bitset& bitset);
|
||||
Bitset& operator^=(const Bitset& bitset);
|
||||
|
||||
static Block fullBitMask;
|
||||
static unsigned int bitsPerBlock;
|
||||
static unsigned int npos;
|
||||
static constexpr Block fullBitMask = std::numeric_limits<Block>::max();
|
||||
static constexpr unsigned int bitsPerBlock = std::numeric_limits<Block>::digits;
|
||||
static constexpr unsigned int npos = std::numeric_limits<unsigned int>::max();
|
||||
|
||||
private:
|
||||
unsigned int FindFirstFrom(unsigned int blockIndex) const;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -3,62 +3,146 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <cstdio>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a ByteArray object with a reserved size
|
||||
*
|
||||
* \param n Space reserved
|
||||
*/
|
||||
|
||||
inline ByteArray::ByteArray(size_type n) :
|
||||
m_array()
|
||||
{
|
||||
m_array.reserve(n);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ByteArray object with a raw memory and a size
|
||||
*
|
||||
* \param ptr Pointer to raw memory
|
||||
* \param n Size that can be accessed
|
||||
*
|
||||
* \remark If preallocated space of ptr is less than the size, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::ByteArray(const void* buffer, size_type n) :
|
||||
m_array(static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ByteArray object with n times the same value
|
||||
*
|
||||
* \param n Number of repetitions
|
||||
* \param value Value to repeat
|
||||
*/
|
||||
|
||||
inline ByteArray::ByteArray(size_type n, const value_type value) :
|
||||
m_array(n, value)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ByteArray object from two iterators
|
||||
*
|
||||
* \param first First iterator
|
||||
* \param last Second iterator
|
||||
*/
|
||||
|
||||
template <class InputIterator>
|
||||
ByteArray::ByteArray(InputIterator first, InputIterator last) :
|
||||
m_array(first, last)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Appends the content of raw memory
|
||||
*
|
||||
* \param ptr Constant pointer to raw memory
|
||||
* \param n Size that can be read
|
||||
*
|
||||
* \remark If preallocated space of ptr is less than the size, the behaviour is undefined
|
||||
*
|
||||
* \see Insert
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Append(const void* buffer, size_type n)
|
||||
{
|
||||
return Insert(end(), static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Appends another array of bytes
|
||||
*
|
||||
* \param other ByteArray to add
|
||||
*
|
||||
* \see Insert
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Append(const ByteArray& other)
|
||||
{
|
||||
return Insert(end(), other.begin(), other.end());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigns this with n times the same value
|
||||
*
|
||||
* \param n Number of repetitions
|
||||
* \param value Value to repeat
|
||||
*/
|
||||
|
||||
inline void ByteArray::Assign(size_type n, value_type value)
|
||||
{
|
||||
m_array.assign(n, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigns this with the content between two iterators
|
||||
*
|
||||
* \param first First iterator
|
||||
* \param last Second iterator
|
||||
*/
|
||||
|
||||
template <class InputIterator>
|
||||
void ByteArray::Assign(InputIterator first, InputIterator last)
|
||||
{
|
||||
m_array.assign(first, last);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets last element
|
||||
* \return A reference to last element
|
||||
*
|
||||
* \remark If ByteArray is empty, behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::reference ByteArray::Back()
|
||||
{
|
||||
return m_array.back();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets last element
|
||||
* \return A constant reference to last element
|
||||
*
|
||||
* \remark If ByteArray is empty, behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reference ByteArray::Back() const
|
||||
{
|
||||
return m_array.back();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Clears the content of the string
|
||||
*
|
||||
* \param keepBuffer Should the buffer be kept
|
||||
*/
|
||||
|
||||
inline void ByteArray::Clear(bool keepBuffer)
|
||||
{
|
||||
m_array.clear();
|
||||
|
|
@ -66,142 +150,326 @@ namespace Nz
|
|||
m_array.shrink_to_fit();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Erases an element from the byte array
|
||||
*
|
||||
* \param pos Iterator to the element
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Erase(const_iterator pos)
|
||||
{
|
||||
return m_array.erase(pos);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Erases the elements between the two pointers from the byte array
|
||||
*
|
||||
* \param first First iterator
|
||||
* \param last Second iterator
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Erase(const_iterator first, const_iterator last)
|
||||
{
|
||||
return m_array.erase(first, last);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets first element
|
||||
* \return A reference to first element
|
||||
*
|
||||
* \remark If ByteArray is empty, behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::reference ByteArray::Front()
|
||||
{
|
||||
return m_array.front();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets first element
|
||||
* \return A constant reference to first element
|
||||
*
|
||||
* \remark If ByteArray is empty, behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reference ByteArray::Front() const
|
||||
{
|
||||
return m_array.front();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the internal allocator of the byte array
|
||||
* \return Allocator
|
||||
*/
|
||||
|
||||
inline ByteArray::allocator_type ByteArray::GetAllocator() const
|
||||
{
|
||||
return m_array.get_allocator();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the raw buffer
|
||||
* \return Raw buffer
|
||||
*/
|
||||
|
||||
inline ByteArray::pointer ByteArray::GetBuffer()
|
||||
{
|
||||
return m_array.data();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the capacity of the byte array
|
||||
* \return Capacity of the byte array
|
||||
*/
|
||||
|
||||
inline ByteArray::size_type ByteArray::GetCapacity() const noexcept
|
||||
{
|
||||
return m_array.capacity();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the raw buffer
|
||||
* \return Raw buffer
|
||||
*/
|
||||
|
||||
inline ByteArray::const_pointer ByteArray::GetConstBuffer() const
|
||||
{
|
||||
return m_array.data();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the maximal size supported by the byte array
|
||||
* \return Biggest size handled
|
||||
*/
|
||||
|
||||
inline ByteArray::size_type ByteArray::GetMaxSize() const noexcept
|
||||
{
|
||||
return m_array.max_size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the byte array
|
||||
* \return Size of the byte array
|
||||
*/
|
||||
|
||||
inline ByteArray::size_type ByteArray::GetSize() const noexcept
|
||||
{
|
||||
return m_array.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a sub byte array of the byte array
|
||||
* \return Sub byte array
|
||||
*
|
||||
* \param startPos First iterator
|
||||
* \param endPos Second iterator
|
||||
*/
|
||||
|
||||
inline ByteArray ByteArray::GetSubArray(const_iterator startPos, const_iterator endPos) const
|
||||
{
|
||||
return ByteArray(startPos, endPos);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Inserts the content of raw memory at the iterator position
|
||||
*
|
||||
* \param pos Iterator to the position
|
||||
* \param buffer Constant pointer to raw memory
|
||||
* \param n Size that can be read
|
||||
*
|
||||
* \remark If preallocated space of ptr is less than the size, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Insert(const_iterator pos, const void* buffer, size_type n)
|
||||
{
|
||||
return m_array.insert(pos, static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Inserts the content of another byte array at the iterator position
|
||||
*
|
||||
* \param pos Iterator to the position
|
||||
* \param other Other byte array
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Insert(const_iterator pos, const ByteArray& other)
|
||||
{
|
||||
return m_array.insert(pos, other.begin(), other.end());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Inserts n times the same value at the iterator position
|
||||
*
|
||||
* \param pos Iterator to the position
|
||||
* \param n Number of repetitions
|
||||
* \param value Value to repeat
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Insert(const_iterator pos, size_type n, value_type byte)
|
||||
{
|
||||
return m_array.insert(pos, n, byte);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Inserts the content from two iterators at the iterator position
|
||||
*
|
||||
* \param pos Iterator to the position
|
||||
* \param first First iterator
|
||||
* \param last Second iterator
|
||||
*/
|
||||
|
||||
template <class InputIterator>
|
||||
ByteArray::iterator ByteArray::Insert(const_iterator pos, InputIterator first, InputIterator last)
|
||||
{
|
||||
return m_array.insert(pos, first, last);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the byte array is empty
|
||||
* \return true if byte array is empty
|
||||
*/
|
||||
|
||||
inline bool ByteArray::IsEmpty() const noexcept
|
||||
{
|
||||
return m_array.empty();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Erases the last element
|
||||
*
|
||||
* \remark If byte array is empty, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline void ByteArray::PopBack()
|
||||
{
|
||||
Erase(end() - 1);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Erases the first element
|
||||
*
|
||||
* \remark If byte array is empty, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline void ByteArray::PopFront()
|
||||
{
|
||||
Erase(begin());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Prepends the content of raw memory
|
||||
*
|
||||
* \param ptr Constant pointer to raw memory
|
||||
* \param n Size that can be read
|
||||
*
|
||||
* \remark If preallocated space of ptr is less than the size, the behaviour is undefined
|
||||
*
|
||||
* \see Insert
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Prepend(const void* buffer, size_type n)
|
||||
{
|
||||
return Insert(begin(), buffer, n);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Prepends another array of bytes
|
||||
*
|
||||
* \param other ByteArray to add
|
||||
*
|
||||
* \see Insert
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Prepend(const ByteArray& other)
|
||||
{
|
||||
return Insert(begin(), other);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Pushes the byte at the end
|
||||
*
|
||||
* \param byte Byte to add
|
||||
*/
|
||||
|
||||
inline void ByteArray::PushBack(const value_type byte)
|
||||
{
|
||||
m_array.push_back(byte);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Pushes the byte at the beginning
|
||||
*
|
||||
* \param byte Byte to add
|
||||
*/
|
||||
|
||||
inline void ByteArray::PushFront(const value_type byte)
|
||||
{
|
||||
m_array.insert(begin(), 1, byte);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reserves enough memory for the buffer size
|
||||
*
|
||||
* \param bufferSize Size of the buffer to allocate
|
||||
*
|
||||
* \remark If bufferSize is smaller than the old one, nothing is done
|
||||
*/
|
||||
|
||||
inline void ByteArray::Reserve(size_type bufferSize)
|
||||
{
|
||||
m_array.reserve(bufferSize);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resizes the string
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param newSize Target size
|
||||
*/
|
||||
|
||||
inline void ByteArray::Resize(size_type newSize)
|
||||
{
|
||||
m_array.resize(newSize);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resizes the string
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param newSize Target size
|
||||
* \param byte Byte to add if newSize is greather than actual size
|
||||
*/
|
||||
|
||||
inline void ByteArray::Resize(size_type newSize, const value_type byte)
|
||||
{
|
||||
m_array.resize(newSize, byte);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Releases the excedent memory
|
||||
*/
|
||||
|
||||
inline void ByteArray::ShrinkToFit()
|
||||
{
|
||||
m_array.shrink_to_fit();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Swaps the content with the other byte array
|
||||
*
|
||||
* \param other Other byte array to swap with
|
||||
*/
|
||||
|
||||
inline void ByteArray::Swap(ByteArray& other)
|
||||
{
|
||||
m_array.swap(other.m_array);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gives a string representation in base 16
|
||||
* \return String in base 16
|
||||
*/
|
||||
|
||||
inline String ByteArray::ToHex() const
|
||||
{
|
||||
std::size_t length = m_array.size() * 2;
|
||||
|
|
@ -213,76 +481,153 @@ namespace Nz
|
|||
return hexOutput;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gives a string representation
|
||||
* \return String where each byte is converted to char
|
||||
*/
|
||||
|
||||
inline String ByteArray::ToString() const
|
||||
{
|
||||
return String(reinterpret_cast<const char*>(GetConstBuffer()), GetSize());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns an iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::begin() noexcept
|
||||
{
|
||||
return m_array.begin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns an iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_iterator ByteArray::begin() const noexcept
|
||||
{
|
||||
return m_array.begin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a constant iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_iterator ByteArray::cbegin() const noexcept
|
||||
{
|
||||
return m_array.cbegin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a constant iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_iterator ByteArray::cend() const noexcept
|
||||
{
|
||||
return m_array.cend();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a constant reversed iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reverse_iterator ByteArray::crbegin() const noexcept
|
||||
{
|
||||
return m_array.crbegin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a constant reversed iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reverse_iterator ByteArray::crend() const noexcept
|
||||
{
|
||||
return m_array.crend();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the byte array is empty
|
||||
* \return true if byte array is empty
|
||||
*/
|
||||
|
||||
inline bool ByteArray::empty() const noexcept
|
||||
{
|
||||
return m_array.empty();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns an iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::end() noexcept
|
||||
{
|
||||
return m_array.end();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns an iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_iterator ByteArray::end() const noexcept
|
||||
{
|
||||
return m_array.end();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a reversed iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::reverse_iterator ByteArray::rbegin() noexcept
|
||||
{
|
||||
return m_array.rbegin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a reversed iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reverse_iterator ByteArray::rbegin() const noexcept
|
||||
{
|
||||
return m_array.rbegin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a reversed iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::reverse_iterator ByteArray::rend() noexcept
|
||||
{
|
||||
return m_array.rend();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the byte array
|
||||
* \return Size of the byte array
|
||||
*/
|
||||
|
||||
inline ByteArray::size_type ByteArray::size() const noexcept
|
||||
{
|
||||
return GetSize();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ith byte
|
||||
* \return A reference to the byte at the ith position
|
||||
*
|
||||
* \remark Produces a NazaraAssert if pos is greather than the size
|
||||
*/
|
||||
|
||||
inline ByteArray::reference ByteArray::operator[](size_type pos)
|
||||
{
|
||||
NazaraAssert(pos < GetSize(), "Index out of range");
|
||||
|
|
@ -290,6 +635,13 @@ namespace Nz
|
|||
return m_array[pos];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ith byte
|
||||
* \return A constant reference to the byte at the ith position
|
||||
*
|
||||
* \remark Produces a NazaraAssert if pos is greather than the size
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reference ByteArray::operator[](size_type pos) const
|
||||
{
|
||||
NazaraAssert(pos < GetSize(), "Index out of range");
|
||||
|
|
@ -297,6 +649,13 @@ namespace Nz
|
|||
return m_array[pos];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Concatenates the byte array to another
|
||||
* \return ByteArray which is the result of the concatenation
|
||||
*
|
||||
* \param other ByteArray to add
|
||||
*/
|
||||
|
||||
inline ByteArray ByteArray::operator+(const ByteArray& other) const
|
||||
{
|
||||
ByteArray tmp(*this);
|
||||
|
|
@ -305,6 +664,13 @@ namespace Nz
|
|||
return tmp;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Concatenates the byte array to this byte array
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param other ByteArray to add
|
||||
*/
|
||||
|
||||
inline ByteArray& ByteArray::operator+=(const ByteArray& other)
|
||||
{
|
||||
Append(other);
|
||||
|
|
@ -312,31 +678,79 @@ namespace Nz
|
|||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is equal to the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator==(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array == rhs.m_array;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is equal to the second byte array
|
||||
* \return false if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator!=(const ByteArray& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is less than the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator<(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array < rhs.m_array;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is less or equal than the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator<=(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array <= rhs.m_array;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is greather than the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator>(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array > rhs.m_array;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is greather or equal than the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator>=(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array >= rhs.m_array;
|
||||
|
|
@ -351,8 +765,17 @@ namespace Nz
|
|||
|
||||
namespace std
|
||||
{
|
||||
/*!
|
||||
* \brief Swaps two byte arrays, specialisation of std
|
||||
*
|
||||
* \param lhs First byte array
|
||||
* \param rhs Second byte array
|
||||
*/
|
||||
|
||||
inline void swap(Nz::ByteArray& lhs, Nz::ByteArray& rhs)
|
||||
{
|
||||
lhs.Swap(rhs);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BYTESTREAM_HPP
|
||||
#define NAZARA_BYTESTREAM_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API ByteStream
|
||||
{
|
||||
public:
|
||||
inline ByteStream(Stream* stream = nullptr);
|
||||
ByteStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
||||
ByteStream(void* ptr, Nz::UInt64 size);
|
||||
ByteStream(const void* ptr, Nz::UInt64 size);
|
||||
ByteStream(const ByteStream&) = delete;
|
||||
inline ByteStream(ByteStream&& stream);
|
||||
~ByteStream();
|
||||
|
||||
inline Endianness GetDataEndianness() const;
|
||||
inline Nz::UInt64 GetSize() const;
|
||||
inline Stream* GetStream() const;
|
||||
|
||||
inline bool FlushBits();
|
||||
|
||||
inline std::size_t Read(void* ptr, std::size_t size);
|
||||
|
||||
inline void SetDataEndianness(Endianness endiannes);
|
||||
inline void SetStream(Stream* stream);
|
||||
void SetStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
||||
void SetStream(void* ptr, Nz::UInt64 size);
|
||||
void SetStream(const void* ptr, Nz::UInt64 size);
|
||||
|
||||
inline void Write(const void* data, std::size_t size);
|
||||
|
||||
template<typename T>
|
||||
ByteStream& operator>>(T& value);
|
||||
|
||||
template<typename T>
|
||||
ByteStream& operator<<(const T& value);
|
||||
|
||||
ByteStream& operator=(const ByteStream&) = delete;
|
||||
inline ByteStream& operator=(ByteStream&&);
|
||||
|
||||
private:
|
||||
virtual void OnEmptyStream();
|
||||
|
||||
std::unique_ptr<Stream> m_ownedStream;
|
||||
SerializationContext m_context;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ByteStream.inl>
|
||||
|
||||
#endif // NAZARA_BYTESTREAM_HPP
|
||||
|
|
@ -0,0 +1,226 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a ByteStream object with a stream
|
||||
*/
|
||||
|
||||
inline ByteStream::ByteStream(Stream* stream)
|
||||
{
|
||||
m_context.stream = stream;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ByteStream object by move semantic
|
||||
*
|
||||
* \param stream ByteStream to move into this
|
||||
*/
|
||||
|
||||
inline ByteStream::ByteStream(ByteStream&& stream) :
|
||||
m_ownedStream(std::move(stream.m_ownedStream)),
|
||||
m_context(stream.m_context)
|
||||
{
|
||||
stream.m_context.stream = nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object and calls FlushBits
|
||||
*
|
||||
* \remark Produces a NazaraWarning if flush did not work
|
||||
*
|
||||
* \see FlushBits
|
||||
*/
|
||||
|
||||
inline ByteStream::~ByteStream()
|
||||
{
|
||||
if (!FlushBits())
|
||||
NazaraWarning("Failed to flush bits at serializer destruction");
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the stream endianness
|
||||
* \return Type of the endianness
|
||||
*/
|
||||
|
||||
inline Endianness ByteStream::GetDataEndianness() const
|
||||
{
|
||||
return m_context.endianness;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the byte stream
|
||||
* \return Size of the stream
|
||||
*/
|
||||
|
||||
inline Nz::UInt64 ByteStream::GetSize() const
|
||||
{
|
||||
if (m_context.stream)
|
||||
return m_context.stream->GetSize();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the internal stream
|
||||
* \return Internal stream
|
||||
*/
|
||||
|
||||
inline Stream* ByteStream::GetStream() const
|
||||
{
|
||||
return m_context.stream;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Flushes the stream
|
||||
* \return true if flushing is successful
|
||||
*/
|
||||
|
||||
inline bool ByteStream::FlushBits()
|
||||
{
|
||||
if (!m_context.stream)
|
||||
return true;
|
||||
|
||||
if (m_context.currentBitPos != 8)
|
||||
{
|
||||
m_context.currentBitPos = 8; //< To prevent Serialize to flush bits itself
|
||||
|
||||
if (!Serialize<UInt8>(m_context, m_context.currentByte))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reads data
|
||||
* \return Number of data read
|
||||
*
|
||||
* \param buffer Preallocated buffer to contain information read
|
||||
* \param size Size of the read and thus of the buffer
|
||||
*/
|
||||
|
||||
inline std::size_t ByteStream::Read(void* ptr, std::size_t size)
|
||||
{
|
||||
if (!m_context.stream)
|
||||
OnEmptyStream();
|
||||
|
||||
FlushBits();
|
||||
return m_context.stream->Read(ptr, size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the stream endianness
|
||||
*
|
||||
* \param Type of the endianness
|
||||
*/
|
||||
|
||||
inline void ByteStream::SetDataEndianness(Endianness endiannes)
|
||||
{
|
||||
m_context.endianness = endiannes;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets this with a stream
|
||||
*
|
||||
* \param stream Stream existing
|
||||
*
|
||||
* \remark Produces a NazaraAssert if stream is invalid
|
||||
*/
|
||||
|
||||
inline void ByteStream::SetStream(Stream* stream)
|
||||
{
|
||||
NazaraAssert(stream, "Invalid stream");
|
||||
|
||||
// We don't want to lose some bits..
|
||||
FlushBits();
|
||||
|
||||
m_context.stream = stream;
|
||||
m_ownedStream.reset();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Writes data
|
||||
* \return Number of data written
|
||||
*
|
||||
* \param buffer Preallocated buffer containing information to write
|
||||
* \param size Size of the writting and thus of the buffer
|
||||
*
|
||||
* \remark Produces a NazaraAssert if buffer is nullptr
|
||||
*/
|
||||
|
||||
inline void ByteStream::Write(const void* data, std::size_t size)
|
||||
{
|
||||
if (!m_context.stream)
|
||||
OnEmptyStream();
|
||||
|
||||
FlushBits();
|
||||
m_context.stream->Write(data, size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Outputs a data from the stream
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param value Value to unserialize
|
||||
*
|
||||
* \remark Produces a NazaraError if unserialization failed
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ByteStream& ByteStream::operator>>(T& value)
|
||||
{
|
||||
if (!m_context.stream)
|
||||
OnEmptyStream();
|
||||
|
||||
if (!Unserialize(m_context, &value))
|
||||
NazaraError("Failed to serialize value");
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds the data to the stream
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param value Value to serialize
|
||||
*
|
||||
* \remark Produces a NazaraError if serialization failed
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ByteStream& ByteStream::operator<<(const T& value)
|
||||
{
|
||||
if (!m_context.stream)
|
||||
OnEmptyStream();
|
||||
|
||||
if (!Serialize(m_context, value))
|
||||
NazaraError("Failed to serialize value");
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the other byte stream into this
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param stream ByteStream to move in this
|
||||
*/
|
||||
|
||||
inline ByteStream& ByteStream::operator=(ByteStream&& stream)
|
||||
{
|
||||
m_context = stream.m_context;
|
||||
m_ownedStream = std::move(stream.m_ownedStream);
|
||||
|
||||
stream.m_context.stream = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -7,17 +7,39 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::CallOnExit
|
||||
* \brief Core class that represents a function to call at the end of the scope
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a CallOnExit object with a function
|
||||
*
|
||||
* \param func Function to call on exit
|
||||
*/
|
||||
|
||||
inline CallOnExit::CallOnExit(Func func) :
|
||||
m_func(func)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object and calls the function
|
||||
*/
|
||||
|
||||
inline CallOnExit::~CallOnExit()
|
||||
{
|
||||
if (m_func)
|
||||
m_func();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calls the function and sets the new callback
|
||||
*
|
||||
* \param func Function to call on exit
|
||||
*/
|
||||
|
||||
inline void CallOnExit::CallAndReset(Func func)
|
||||
{
|
||||
if (m_func)
|
||||
|
|
@ -26,6 +48,12 @@ namespace Nz
|
|||
Reset(func);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the function
|
||||
*
|
||||
* \param func Function to call on exit
|
||||
*/
|
||||
|
||||
inline void CallOnExit::Reset(Func func)
|
||||
{
|
||||
m_func = func;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
struct SerializationContext;
|
||||
|
||||
class Color
|
||||
{
|
||||
public:
|
||||
|
|
@ -62,6 +64,9 @@ namespace Nz
|
|||
private:
|
||||
static float Hue2RGB(float v1, float v2, float vH);
|
||||
};
|
||||
|
||||
inline bool Serialize(SerializationContext& context, const Color& color);
|
||||
inline bool Unserialize(SerializationContext& context, Color* color);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Color& color);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
|
@ -11,10 +12,29 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::Color
|
||||
* \brief Core class that represents a color
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Color object by default
|
||||
*/
|
||||
|
||||
inline Color::Color()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Color object with values
|
||||
*
|
||||
* \param red Red value
|
||||
* \param green Green value
|
||||
* \param blue Blue value
|
||||
* \param alpha Alpha value
|
||||
*/
|
||||
|
||||
inline Color::Color(UInt8 red, UInt8 green, UInt8 blue, UInt8 alpha) :
|
||||
r(red),
|
||||
g(green),
|
||||
|
|
@ -23,6 +43,12 @@ namespace Nz
|
|||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Color object with a light level
|
||||
*
|
||||
* \param lightness Value for r, g and b
|
||||
*/
|
||||
|
||||
inline Color::Color(UInt8 lightness) :
|
||||
r(lightness),
|
||||
g(lightness),
|
||||
|
|
@ -31,6 +57,13 @@ namespace Nz
|
|||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Color object with values
|
||||
*
|
||||
* \param vec[3] vec[0] = red value, vec[1] = green value, vec[2] = blue value
|
||||
* \param alpha Alpha value
|
||||
*/
|
||||
|
||||
inline Color::Color(UInt8 vec[3], UInt8 alpha) :
|
||||
r(vec[0]),
|
||||
g(vec[1]),
|
||||
|
|
@ -39,6 +72,11 @@ namespace Nz
|
|||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts this to string
|
||||
* \return String representation of the object "Color(r, g, b[, a])"
|
||||
*/
|
||||
|
||||
inline String Color::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
|
|
@ -52,6 +90,13 @@ namespace Nz
|
|||
return ss;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds two colors together
|
||||
* \return Color which is the sum
|
||||
*
|
||||
* \param color Other color
|
||||
*/
|
||||
|
||||
inline Color Color::operator+(const Color& color) const
|
||||
{
|
||||
///TODO: Improve this shit
|
||||
|
|
@ -64,6 +109,13 @@ namespace Nz
|
|||
return c;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Multiplies two colors together
|
||||
* \return Color which is the product
|
||||
*
|
||||
* \param color Other color
|
||||
*/
|
||||
|
||||
inline Color Color::operator*(const Color& color) const
|
||||
{
|
||||
///TODO: Improve this shit
|
||||
|
|
@ -76,48 +128,104 @@ namespace Nz
|
|||
return c;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds the color to this
|
||||
* \return Color which is the sum
|
||||
*
|
||||
* \param color Other color
|
||||
*/
|
||||
|
||||
inline Color Color::operator+=(const Color& color)
|
||||
{
|
||||
return operator=(operator+(color));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Multiplies the color to this
|
||||
* \return Color which is the product
|
||||
*
|
||||
* \param color Other color
|
||||
*/
|
||||
|
||||
inline Color Color::operator*=(const Color& color)
|
||||
{
|
||||
return operator=(operator*(color));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the two colors are equal
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param color Color to compare
|
||||
*/
|
||||
|
||||
inline bool Color::operator==(const Color& color) const
|
||||
{
|
||||
return r == color.r && g == color.g && b == color.b && a == color.a;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the two colors are equal
|
||||
* \return false if it is the case
|
||||
*
|
||||
* \param color Color to compare
|
||||
*/
|
||||
|
||||
inline bool Color::operator!=(const Color& color) const
|
||||
{
|
||||
return !operator==(color);
|
||||
}
|
||||
|
||||
// Algorithmes venant de http://www.easyrgb.com/index.php?X=MATH
|
||||
// Algorithm coming from http://www.easyrgb.com/index.php?X=MATH
|
||||
|
||||
/*!
|
||||
* \brief Converts CMY representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param cyan Cyan component
|
||||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
*/
|
||||
|
||||
inline Color Color::FromCMY(float cyan, float magenta, float yellow)
|
||||
{
|
||||
return Color(static_cast<UInt8>((1.f-cyan)*255.f), static_cast<UInt8>((1.f-magenta)*255.f), static_cast<UInt8>((1.f-yellow)*255.f));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts CMYK representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param cyan Cyan component
|
||||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
* \param black Black component
|
||||
*/
|
||||
|
||||
inline Color Color::FromCMYK(float cyan, float magenta, float yellow, float black)
|
||||
{
|
||||
return FromCMY(cyan * (1.f - black) + black,
|
||||
magenta * (1.f - black) + black,
|
||||
yellow * (1.f - black) + black);
|
||||
magenta * (1.f - black) + black,
|
||||
yellow * (1.f - black) + black);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts HSL representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param hue Hue component
|
||||
* \param saturation Saturation component
|
||||
* \param lightness Lightness component
|
||||
*/
|
||||
|
||||
inline Color Color::FromHSL(UInt8 hue, UInt8 saturation, UInt8 lightness)
|
||||
{
|
||||
if (saturation == 0)
|
||||
{
|
||||
// RGB results from 0 to 255
|
||||
return Color(lightness * 255,
|
||||
lightness * 255,
|
||||
lightness * 255);
|
||||
lightness * 255,
|
||||
lightness * 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -135,11 +243,20 @@ namespace Nz
|
|||
float v1 = 2.f * l - v2;
|
||||
|
||||
return Color(static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h + (1.f/3.f))),
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h)),
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h - (1.f/3.f))));
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h)),
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h - (1.f/3.f))));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts HSV representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param hue Hue component
|
||||
* \param saturation Saturation component
|
||||
* \param value Value component
|
||||
*/
|
||||
|
||||
inline Color Color::FromHSV(float hue, float saturation, float value)
|
||||
{
|
||||
if (NumberEquals(saturation, 0.f))
|
||||
|
|
@ -201,11 +318,28 @@ namespace Nz
|
|||
return Color(static_cast<UInt8>(r*255.f), static_cast<UInt8>(g*255.f), static_cast<UInt8>(b*255.f));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts XYZ representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param vec Vector3 representing the space color
|
||||
*/
|
||||
|
||||
inline Color Color::FromXYZ(const Vector3f& vec)
|
||||
{
|
||||
return FromXYZ(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts XYZ representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param x X component
|
||||
* \param y Y component
|
||||
* \param z Z component
|
||||
*/
|
||||
|
||||
inline Color Color::FromXYZ(float x, float y, float z)
|
||||
{
|
||||
x /= 100.f; // X from 0 to 95.047
|
||||
|
|
@ -234,6 +368,15 @@ namespace Nz
|
|||
return Color(static_cast<UInt8>(r * 255.f), static_cast<UInt8>(g * 255.f), static_cast<UInt8>(b * 255.f));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to CMYK
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param cyan Cyan component
|
||||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
*/
|
||||
|
||||
inline void Color::ToCMY(const Color& color, float* cyan, float* magenta, float* yellow)
|
||||
{
|
||||
*cyan = 1.f - color.r/255.f;
|
||||
|
|
@ -241,6 +384,15 @@ namespace Nz
|
|||
*yellow = 1.f - color.b/255.f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to CMYK
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param cyan Cyan component
|
||||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
*/
|
||||
|
||||
inline void Color::ToCMYK(const Color& color, float* cyan, float* magenta, float* yellow, float* black)
|
||||
{
|
||||
float c, m, y;
|
||||
|
|
@ -265,6 +417,15 @@ namespace Nz
|
|||
*black = k;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to HSL
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param hue Hue component
|
||||
* \param saturation Saturation component
|
||||
* \param lightness Lightness component
|
||||
*/
|
||||
|
||||
inline void Color::ToHSL(const Color& color, UInt8* hue, UInt8* saturation, UInt8* lightness)
|
||||
{
|
||||
float r = color.r / 255.f;
|
||||
|
|
@ -315,6 +476,15 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to HSV
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param hue Hue component
|
||||
* \param saturation Saturation component
|
||||
* \param value Value component
|
||||
*/
|
||||
|
||||
inline void Color::ToHSV(const Color& color, float* hue, float* saturation, float* value)
|
||||
{
|
||||
float r = color.r / 255.f;
|
||||
|
|
@ -361,11 +531,27 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to XYZ
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param vec Vector3 representing the space color
|
||||
*/
|
||||
|
||||
inline void Color::ToXYZ(const Color& color, Vector3f* vec)
|
||||
{
|
||||
return ToXYZ(color, &vec->x, &vec->y, &vec->z);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to XYZ
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param x X component
|
||||
* \param y Y component
|
||||
* \param z Z component
|
||||
*/
|
||||
|
||||
inline void Color::ToXYZ(const Color& color, float* x, float* y, float* z)
|
||||
{
|
||||
float r = color.r/255.f; //R from 0 to 255
|
||||
|
|
@ -397,6 +583,15 @@ namespace Nz
|
|||
*z = r*0.0193f + g*0.1192f + b*0.9505f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts HUE representation to RGV
|
||||
* \return RGB corresponding
|
||||
*
|
||||
* \param v1 V1 component
|
||||
* \param v2 V2 component
|
||||
* \param vH VH component
|
||||
*/
|
||||
|
||||
inline float Color::Hue2RGB(float v1, float v2, float vH)
|
||||
{
|
||||
if (vH < 0.f)
|
||||
|
|
@ -415,8 +610,64 @@ namespace Nz
|
|||
return v1 + (v2 - v1)*(2.f/3.f - vH)*6;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Serializes a Color
|
||||
* \return true if successfully serialized
|
||||
*
|
||||
* \param context Serialization context
|
||||
* \param color Input color
|
||||
*/
|
||||
inline bool Serialize(SerializationContext& context, const Color& color)
|
||||
{
|
||||
if (!Serialize(context, color.r))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, color.g))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, color.b))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, color.a))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unserializes a Color
|
||||
* \return true if successfully unserialized
|
||||
*
|
||||
* \param context Serialization context
|
||||
* \param color Output color
|
||||
*/
|
||||
inline bool Unserialize(SerializationContext& context, Color* color)
|
||||
{
|
||||
if (!Unserialize(context, &color->r))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &color->g))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &color->b))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &color->a))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Output operator
|
||||
* \return The stream
|
||||
*
|
||||
* \param out The stream
|
||||
* \param color The color to output
|
||||
*/
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const Nz::Color& color)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Nz
|
|||
public:
|
||||
ConditionVariable();
|
||||
ConditionVariable(const ConditionVariable&) = delete;
|
||||
ConditionVariable(ConditionVariable&&) = delete; ///TODO
|
||||
inline ConditionVariable(ConditionVariable&& condition) noexcept;
|
||||
~ConditionVariable();
|
||||
|
||||
void Signal();
|
||||
|
|
@ -29,11 +29,13 @@ namespace Nz
|
|||
bool Wait(Mutex* mutex, UInt32 timeout);
|
||||
|
||||
ConditionVariable& operator=(const ConditionVariable&) = delete;
|
||||
ConditionVariable& operator=(ConditionVariable&&) = delete; ///TODO
|
||||
inline ConditionVariable& operator=(ConditionVariable&& condition) noexcept;
|
||||
|
||||
private:
|
||||
ConditionVariableImpl* m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ConditionVariable.inl>
|
||||
|
||||
#endif // NAZARA_CONDITIONVARIABLE_HPP
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ConditionVariable.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::ConditionVariable
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ConditionVariable object by moving another one
|
||||
*/
|
||||
inline ConditionVariable::ConditionVariable(ConditionVariable&& condition) noexcept :
|
||||
m_impl(condition.m_impl)
|
||||
{
|
||||
condition.m_impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -27,36 +27,41 @@
|
|||
#ifndef NAZARA_CONFIG_CORE_HPP
|
||||
#define NAZARA_CONFIG_CORE_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
/*!
|
||||
* \defgroup core (NazaraCore) Core module
|
||||
* Core/System module including classes to handle threading, time, hardware info, memory management, etc...
|
||||
*/
|
||||
|
||||
// Précision des réels lors de la transformation en chaîne de caractère (Max. chiffres après la virgule)
|
||||
/// Each modification of a parameter needs a recompilation of the module
|
||||
|
||||
// Precision of reals when transformed into string (Max. numbers after the coma)
|
||||
#define NAZARA_CORE_DECIMAL_DIGITS 6
|
||||
|
||||
// Duplique la sortie du log sur le flux de sortie standard (cout)
|
||||
// Duplicate the log output on the standard output flux (cout)
|
||||
#define NAZARA_CORE_DUPLICATE_LOG_TO_COUT 0
|
||||
|
||||
// Teste les assertions
|
||||
// Checks the assertions
|
||||
#define NAZARA_CORE_ENABLE_ASSERTS 0
|
||||
|
||||
// Appelle exit dès qu'une assertion est invalide
|
||||
// Call exit when an assertion is invalid
|
||||
#define NAZARA_CORE_EXIT_ON_ASSERT_FAILURE 1
|
||||
|
||||
// Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash)
|
||||
// Size of buffer when reading entirely a file (ex: Hash)
|
||||
#define NAZARA_CORE_FILE_BUFFERSIZE 4096
|
||||
|
||||
// Incorpore la table Unicode Character Data (Nécessaires pour faire fonctionner le flag String::HandleUTF8)
|
||||
// Incorporate the Unicode Character Data table (Necessary to make it work with the flag String::HandleUTF8)
|
||||
#define NAZARA_CORE_INCLUDE_UNICODEDATA 0
|
||||
|
||||
// Utilise le MemoryManager pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
|
||||
// Use the MemoryManager to manage dynamic allocations (can detect memory leak but allocations/frees are slower)
|
||||
#define NAZARA_CORE_MANAGE_MEMORY 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
// Activate the security tests based on the code (Advised for development)
|
||||
#define NAZARA_CORE_SAFE 1
|
||||
|
||||
// Protège les classes des accès concurrentiels
|
||||
// Protect the classes against data race
|
||||
#define NAZARA_CORE_THREADSAFE 1
|
||||
|
||||
// Les classes à protéger des accès concurrentiels
|
||||
// Classes to protect against data race
|
||||
#define NAZARA_THREADSAFETY_CLOCK 0 // Clock
|
||||
#define NAZARA_THREADSAFETY_DIRECTORY 1 // Directory
|
||||
#define NAZARA_THREADSAFETY_DYNLIB 1 // DynLib
|
||||
|
|
@ -64,18 +69,19 @@
|
|||
#define NAZARA_THREADSAFETY_LOG 1 // Log
|
||||
#define NAZARA_THREADSAFETY_REFCOUNTED 1 // RefCounted
|
||||
|
||||
// Le nombre de spinlocks à utiliser avec les sections critiques de Windows (0 pour désactiver)
|
||||
// Number of spinlocks to use with the Windows critical sections (0 to disable)
|
||||
#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096
|
||||
|
||||
// Optimise l'implémentation Windows avec certaines avancées de Windows vista (Casse la compatibilité XP)
|
||||
// Optimize the Windows implementation with technologies of Windows vista (and greather) (Break the compatibility with XP)
|
||||
#define NAZARA_CORE_WINDOWS_VISTA 0
|
||||
|
||||
|
||||
/*
|
||||
// Règle le temps entre le réveil du thread des timers et l'activation d'un timer (En millisecondes)
|
||||
// Sets the time between waking thread timers and activating a timer (in milliseconds)
|
||||
#define NAZARA_CORE_TIMER_WAKEUPTIME 10
|
||||
*/
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
/// Checking the values and types of certain constants
|
||||
#include <Nazara/Core/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@
|
|||
#ifndef NAZARA_CONFIG_CHECK_CORE_HPP
|
||||
#define NAZARA_CONFIG_CHECK_CORE_HPP
|
||||
|
||||
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
|
||||
/// This file is used to check the constant values defined in Config.hpp
|
||||
|
||||
#include <type_traits>
|
||||
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
|
||||
|
||||
// On force la valeur de MANAGE_MEMORY en mode debug
|
||||
// We fore the value of MANAGE_MEMORY in debug
|
||||
#if defined(NAZARA_DEBUG) && !NAZARA_CORE_MANAGE_MEMORY
|
||||
#undef NAZARA_CORE_MANAGE_MEMORY
|
||||
#define NAZARA_CORE_MANAGE_MEMORY 0
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
|
||||
// We assume that Debug.hpp has already been included, same thing for Config.hpp
|
||||
#if NAZARA_CORE_MANAGE_MEMORY
|
||||
#undef delete
|
||||
#undef new
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
using DynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction
|
||||
using DynLibFunc = int (*)(); // "Generic" type of poiter to function
|
||||
|
||||
class DynLibImpl;
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ namespace Nz
|
|||
|
||||
mutable String m_lastError;
|
||||
DynLibImpl* m_impl;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DYNLIB_HPP
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@
|
|||
#include <Nazara/Core/Enums.hpp>
|
||||
|
||||
#if !defined(NAZARA_BIG_ENDIAN) && !defined(NAZARA_LITTLE_ENDIAN)
|
||||
// Détection automatique selon les macros du compilateur
|
||||
// Automatic detection following macroes of compiler
|
||||
#if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \
|
||||
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__)
|
||||
#define NAZARA_BIG_ENDIAN
|
||||
#elif defined(__i386__) || defined(__i386) || defined(__X86__) || defined (__x86_64) || defined(_M_I86) || \
|
||||
defined(_M_IX86) || defined(_M_X64)
|
||||
defined(_M_IX86) || defined(_M_X64)
|
||||
#define NAZARA_LITTLE_ENDIAN
|
||||
#else
|
||||
#error Failed to identify endianness, you must define either NAZARA_BIG_ENDIAN or NAZARA_LITTLE_ENDIAN
|
||||
|
|
|
|||
|
|
@ -7,6 +7,12 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Gets the platform endianness
|
||||
* \return Type of the endianness
|
||||
*/
|
||||
|
||||
inline constexpr Endianness GetPlatformEndianness()
|
||||
{
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
|
|
@ -16,11 +22,21 @@ namespace Nz
|
|||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Swaps the byte for endianness operations
|
||||
*
|
||||
* \param buffer Raw memory
|
||||
* \param size Size to change endianness
|
||||
*
|
||||
* \remark If size is greather than the preallocated buffer, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline void SwapBytes(void* buffer, unsigned int size)
|
||||
{
|
||||
UInt8* bytes = reinterpret_cast<UInt8*>(buffer);
|
||||
UInt8* bytes = static_cast<UInt8*>(buffer);
|
||||
unsigned int i = 0;
|
||||
unsigned int j = size-1;
|
||||
unsigned int j = size - 1;
|
||||
|
||||
while (i < j)
|
||||
std::swap(bytes[i++], bytes[j--]);
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ namespace Nz
|
|||
|
||||
enum CursorPosition
|
||||
{
|
||||
CursorPosition_AtBegin, // Début du fichier
|
||||
CursorPosition_AtCurrent, // Position du pointeur
|
||||
CursorPosition_AtEnd, // Fin du fichier
|
||||
CursorPosition_AtBegin, // beginning of the file
|
||||
CursorPosition_AtCurrent, // Position of the cursor
|
||||
CursorPosition_AtEnd, // End of the file
|
||||
|
||||
CursorPosition_Max = CursorPosition_AtEnd
|
||||
};
|
||||
|
|
@ -45,7 +45,7 @@ namespace Nz
|
|||
ErrorFlag_ThrowException = 0x4,
|
||||
ErrorFlag_ThrowExceptionDisabled = 0x8,
|
||||
|
||||
ErrorFlag_Max = ErrorFlag_ThrowExceptionDisabled*2-1
|
||||
ErrorFlag_Max = ErrorFlag_ThrowExceptionDisabled * 2 - 1
|
||||
};
|
||||
|
||||
enum ErrorType
|
||||
|
|
@ -75,18 +75,18 @@ namespace Nz
|
|||
|
||||
enum OpenModeFlags
|
||||
{
|
||||
OpenMode_NotOpen = 0x00, // Utilise le mode d'ouverture actuel
|
||||
OpenMode_NotOpen = 0x00, // Use the current mod of opening
|
||||
|
||||
OpenMode_Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
|
||||
OpenMode_Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
|
||||
OpenMode_ReadOnly = 0x04, // Ouvre uniquement en lecture
|
||||
OpenMode_Text = 0x10, // Ouvre en mode texte
|
||||
OpenMode_Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe
|
||||
OpenMode_WriteOnly = 0x40, // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas
|
||||
OpenMode_Append = 0x01, // Disable writing on existing parts and put the cursor at the end
|
||||
OpenMode_Lock = 0x02, // Disable modifying the file before it is open
|
||||
OpenMode_ReadOnly = 0x04, // Open in read only
|
||||
OpenMode_Text = 0x10, // Open in text mod
|
||||
OpenMode_Truncate = 0x20, // Create the file if it doesn't exist and empty it if it exists
|
||||
OpenMode_WriteOnly = 0x40, // Open in write only, create the file if it doesn't exist
|
||||
|
||||
OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly, // Ouvre en lecture/écriture
|
||||
OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly, // Open in read and write
|
||||
|
||||
OpenMode_Max = OpenMode_WriteOnly
|
||||
OpenMode_Max = OpenMode_WriteOnly * 2 - 1
|
||||
};
|
||||
|
||||
enum ParameterType
|
||||
|
|
@ -177,7 +177,7 @@ namespace Nz
|
|||
StreamOption_Sequential = 0x1,
|
||||
StreamOption_Text = 0x2,
|
||||
|
||||
StreamOption_Max = StreamOption_Text*2-1
|
||||
StreamOption_Max = StreamOption_Text * 2 - 1
|
||||
};
|
||||
|
||||
enum Ternary
|
||||
|
|
|
|||
|
|
@ -9,19 +9,18 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Directory.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
#if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG)
|
||||
#define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
|
||||
#define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, __FILE__, NAZARA_FUNCTION)
|
||||
#else
|
||||
#define NazaraAssert(a, err) for (;;) break
|
||||
#endif
|
||||
|
||||
#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType_Normal, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
|
||||
#define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType_Internal, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
|
||||
#define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType_Warning, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
|
||||
#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType_Normal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
|
||||
#define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType_Internal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
|
||||
#define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType_Warning, err, __LINE__, __FILE__, NAZARA_FUNCTION)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,11 +8,27 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Computes the hash for the file
|
||||
* \return ByteArray represing the result of the hash of the file
|
||||
*
|
||||
* \param hash Hash to execute
|
||||
* \param filePath Path for the file
|
||||
*/
|
||||
|
||||
inline ByteArray File::ComputeHash(HashType hash, const String& filePath)
|
||||
{
|
||||
return ComputeHash(AbstractHash::Get(hash).get(), filePath);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Computes the hash for the file
|
||||
* \return ByteArray represing the result of the hash of the file
|
||||
*
|
||||
* \param hash Hash to execute
|
||||
* \param filePath Path for the file
|
||||
*/
|
||||
|
||||
inline ByteArray File::ComputeHash(AbstractHash* hash, const String& filePath)
|
||||
{
|
||||
return Nz::ComputeHash(hash, File(filePath));
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue