Merge branch 'NDK-Refactor' into NDK

Conflicts:
	examples/HardwareInfo/main.cpp
	include/Nazara/Renderer/Enums.hpp
	include/Nazara/Renderer/GpuQuery.hpp
	include/Nazara/Renderer/OpenGL.hpp
	include/Nazara/Renderer/RenderBuffer.hpp
	include/Nazara/Renderer/RenderTexture.hpp
	include/Nazara/Renderer/Texture.hpp
	src/Nazara/Graphics/AbstractRenderTechnique.cpp
	src/Nazara/Graphics/DeferredRenderTechnique.cpp
	src/Nazara/Graphics/Material.cpp
	src/Nazara/Graphics/SkyboxBackground.cpp
	src/Nazara/Renderer/GpuQuery.cpp
	src/Nazara/Renderer/OpenGL.cpp
	src/Nazara/Renderer/RenderBuffer.cpp
	src/Nazara/Renderer/RenderTexture.cpp
	src/Nazara/Renderer/Renderer.cpp
	src/Nazara/Renderer/Shader.cpp
	src/Nazara/Renderer/ShaderStage.cpp
	src/Nazara/Renderer/Texture.cpp

Former-commit-id: 2f1c7e9f9766f59ab83d9405856a1898ac4ab48f
This commit is contained in:
Lynix 2015-09-25 23:16:58 +02:00
commit eaf1bb3601
613 changed files with 68051 additions and 66125 deletions

View File

@ -9,7 +9,7 @@ namespace Ndk
{ {
inline Application::Application() inline Application::Application()
{ {
NzErrorFlags errFlags(nzErrorFlag_ThrowException, true); Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
// Initialisation du SDK // Initialisation du SDK
Sdk::Initialize(); Sdk::Initialize();

View File

@ -24,7 +24,7 @@ namespace Ndk
BaseComponent(ComponentIndex componentIndex); BaseComponent(ComponentIndex componentIndex);
BaseComponent(const BaseComponent&) = default; BaseComponent(const BaseComponent&) = default;
BaseComponent(BaseComponent&&) noexcept = default; BaseComponent(BaseComponent&&) = default;
virtual ~BaseComponent(); virtual ~BaseComponent();
virtual BaseComponent* Clone() const = 0; virtual BaseComponent* Clone() const = 0;
@ -32,7 +32,7 @@ namespace Ndk
ComponentIndex GetIndex() const; ComponentIndex GetIndex() const;
BaseComponent& operator=(const BaseComponent&) = default; BaseComponent& operator=(const BaseComponent&) = default;
BaseComponent& operator=(BaseComponent&&) noexcept = default; BaseComponent& operator=(BaseComponent&&) = default;
protected: protected:
ComponentIndex m_componentIndex; ComponentIndex m_componentIndex;

View File

@ -79,11 +79,11 @@ namespace Ndk
static inline void Uninitialize(); static inline void Uninitialize();
std::vector<EntityHandle> m_entities; std::vector<EntityHandle> m_entities;
NzBitset<nzUInt64> m_entityBits; Nz::Bitset<Nz::UInt64> m_entityBits;
NzBitset<> m_excludedComponents; Nz::Bitset<> m_excludedComponents;
mutable NzBitset<> m_filterResult; mutable Nz::Bitset<> m_filterResult;
NzBitset<> m_requiredAnyComponents; Nz::Bitset<> m_requiredAnyComponents;
NzBitset<> m_requiredComponents; Nz::Bitset<> m_requiredComponents;
SystemIndex m_systemIndex; SystemIndex m_systemIndex;
World* m_world; World* m_world;
float m_updateCounter; float m_updateCounter;

View File

@ -19,7 +19,7 @@ namespace Ndk
{ {
class Entity; class Entity;
class NDK_API CameraComponent : public Component<CameraComponent>, public NzAbstractViewer class NDK_API CameraComponent : public Component<CameraComponent>, public Nz::AbstractViewer
{ {
public: public:
inline CameraComponent(); inline CameraComponent();
@ -34,26 +34,26 @@ namespace Ndk
inline void EnsureViewportUpdate() const; inline void EnsureViewportUpdate() const;
inline float GetAspectRatio() const; inline float GetAspectRatio() const;
inline NzVector3f GetEyePosition() const; inline Nz::Vector3f GetEyePosition() const;
inline NzVector3f GetForward() const; inline Nz::Vector3f GetForward() const;
inline float GetFOV() const; inline float GetFOV() const;
inline const NzFrustumf& GetFrustum() const; inline const Nz::Frustumf& GetFrustum() const;
inline unsigned int GetLayer() const; inline unsigned int GetLayer() const;
inline const NzMatrix4f& GetProjectionMatrix() const; inline const Nz::Matrix4f& GetProjectionMatrix() const;
inline nzProjectionType GetProjectionType() const; inline Nz::ProjectionType GetProjectionType() const;
inline const NzRenderTarget* GetTarget() const; inline const Nz::RenderTarget* GetTarget() const;
inline const NzRectf& GetTargetRegion() const; inline const Nz::Rectf& GetTargetRegion() const;
inline const NzMatrix4f& GetViewMatrix() const; inline const Nz::Matrix4f& GetViewMatrix() const;
inline const NzRecti& GetViewport() const; inline const Nz::Recti& GetViewport() const;
inline float GetZFar() const; inline float GetZFar() const;
inline float GetZNear() const; inline float GetZNear() const;
inline void SetFOV(float fov); inline void SetFOV(float fov);
inline void SetLayer(unsigned int layer); inline void SetLayer(unsigned int layer);
inline void SetProjectionType(nzProjectionType projection); inline void SetProjectionType(Nz::ProjectionType projection);
inline void SetTarget(const NzRenderTarget* renderTarget); inline void SetTarget(const Nz::RenderTarget* renderTarget);
inline void SetTargetRegion(const NzRectf& region); inline void SetTargetRegion(const Nz::Rectf& region);
inline void SetViewport(const NzRecti& viewport); inline void SetViewport(const Nz::Recti& viewport);
inline void SetZFar(float zFar); inline void SetZFar(float zFar);
inline void SetZNear(float zNear); inline void SetZNear(float zNear);
@ -69,26 +69,26 @@ namespace Ndk
void OnComponentAttached(BaseComponent& component) override; void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override; void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override; void OnDetached() override;
void OnNodeInvalidated(const NzNode* node); void OnNodeInvalidated(const Nz::Node* node);
void OnRenderTargetRelease(const NzRenderTarget* renderTarget); void OnRenderTargetRelease(const Nz::RenderTarget* renderTarget);
void OnRenderTargetSizeChange(const NzRenderTarget* renderTarget); void OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget);
void UpdateFrustum() const; void UpdateFrustum() const;
void UpdateProjectionMatrix() const; void UpdateProjectionMatrix() const;
void UpdateViewMatrix() const; void UpdateViewMatrix() const;
void UpdateViewport() const; void UpdateViewport() const;
NazaraSlot(NzNode, OnNodeInvalidation, m_nodeInvalidationSlot); NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
NazaraSlot(NzRenderTarget, OnRenderTargetRelease, m_targetReleaseSlot); NazaraSlot(Nz::RenderTarget, OnRenderTargetRelease, m_targetReleaseSlot);
NazaraSlot(NzRenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot); NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot);
nzProjectionType m_projectionType; Nz::ProjectionType m_projectionType;
mutable NzFrustumf m_frustum; mutable Nz::Frustumf m_frustum;
mutable NzMatrix4f m_projectionMatrix; mutable Nz::Matrix4f m_projectionMatrix;
mutable NzMatrix4f m_viewMatrix; mutable Nz::Matrix4f m_viewMatrix;
NzRectf m_targetRegion; Nz::Rectf m_targetRegion;
mutable NzRecti m_viewport; mutable Nz::Recti m_viewport;
const NzRenderTarget* m_target; const Nz::RenderTarget* m_target;
mutable bool m_frustumUpdated; mutable bool m_frustumUpdated;
mutable bool m_projectionMatrixUpdated; mutable bool m_projectionMatrixUpdated;
mutable bool m_viewMatrixUpdated; mutable bool m_viewMatrixUpdated;

View File

@ -8,7 +8,7 @@
namespace Ndk namespace Ndk
{ {
inline CameraComponent::CameraComponent() : inline CameraComponent::CameraComponent() :
m_projectionType(nzProjectionType_Perspective), m_projectionType(Nz::ProjectionType_Perspective),
m_targetRegion(0.f, 0.f, 1.f, 1.f), m_targetRegion(0.f, 0.f, 1.f, 1.f),
m_target(nullptr), m_target(nullptr),
m_frustumUpdated(false), m_frustumUpdated(false),
@ -25,7 +25,7 @@ namespace Ndk
inline CameraComponent::CameraComponent(const CameraComponent& camera) : inline CameraComponent::CameraComponent(const CameraComponent& camera) :
Component(camera), Component(camera),
NzAbstractViewer(camera), AbstractViewer(camera),
m_projectionType(camera.m_projectionType), m_projectionType(camera.m_projectionType),
m_targetRegion(camera.m_targetRegion), m_targetRegion(camera.m_targetRegion),
m_target(nullptr), m_target(nullptr),
@ -78,7 +78,7 @@ namespace Ndk
return m_fov; return m_fov;
} }
inline const NzFrustumf& CameraComponent::GetFrustum() const inline const Nz::Frustumf& CameraComponent::GetFrustum() const
{ {
EnsureFrustumUpdate(); EnsureFrustumUpdate();
@ -90,36 +90,36 @@ namespace Ndk
return m_layer; return m_layer;
} }
inline const NzMatrix4f& CameraComponent::GetProjectionMatrix() const inline const Nz::Matrix4f& CameraComponent::GetProjectionMatrix() const
{ {
EnsureProjectionMatrixUpdate(); EnsureProjectionMatrixUpdate();
return m_projectionMatrix; return m_projectionMatrix;
} }
inline nzProjectionType CameraComponent::GetProjectionType() const inline Nz::ProjectionType CameraComponent::GetProjectionType() const
{ {
return m_projectionType; return m_projectionType;
} }
inline const NzRenderTarget* CameraComponent::GetTarget() const inline const Nz::RenderTarget* CameraComponent::GetTarget() const
{ {
return m_target; return m_target;
} }
inline const NzRectf& CameraComponent::GetTargetRegion() const inline const Nz::Rectf& CameraComponent::GetTargetRegion() const
{ {
return m_targetRegion; return m_targetRegion;
} }
inline const NzMatrix4f& CameraComponent::GetViewMatrix() const inline const Nz::Matrix4f& CameraComponent::GetViewMatrix() const
{ {
EnsureViewMatrixUpdate(); EnsureViewMatrixUpdate();
return m_viewMatrix; return m_viewMatrix;
} }
inline const NzRecti& CameraComponent::GetViewport() const inline const Nz::Recti& CameraComponent::GetViewport() const
{ {
EnsureViewportUpdate(); EnsureViewportUpdate();
@ -138,20 +138,20 @@ namespace Ndk
inline void CameraComponent::SetFOV(float fov) inline void CameraComponent::SetFOV(float fov)
{ {
NazaraAssert(!NzNumberEquals(fov, 0.f), "FOV must be different from zero"); NazaraAssert(!Nz::NumberEquals(fov, 0.f), "FOV must be different from zero");
m_fov = fov; m_fov = fov;
InvalidateProjectionMatrix(); InvalidateProjectionMatrix();
} }
inline void CameraComponent::SetProjectionType(nzProjectionType projectionType) inline void CameraComponent::SetProjectionType(Nz::ProjectionType projectionType)
{ {
m_projectionType = projectionType; m_projectionType = projectionType;
InvalidateProjectionMatrix(); InvalidateProjectionMatrix();
} }
inline void CameraComponent::SetTarget(const NzRenderTarget* renderTarget) inline void CameraComponent::SetTarget(const Nz::RenderTarget* renderTarget)
{ {
m_target = renderTarget; m_target = renderTarget;
if (m_target) if (m_target)
@ -160,14 +160,14 @@ namespace Ndk
m_targetReleaseSlot.Disconnect(); m_targetReleaseSlot.Disconnect();
} }
inline void CameraComponent::SetTargetRegion(const NzRectf& region) inline void CameraComponent::SetTargetRegion(const Nz::Rectf& region)
{ {
m_targetRegion = region; m_targetRegion = region;
InvalidateViewport(); InvalidateViewport();
} }
inline void CameraComponent::SetViewport(const NzRecti& viewport) inline void CameraComponent::SetViewport(const Nz::Recti& viewport)
{ {
NazaraAssert(m_target, "Component has no render target"); NazaraAssert(m_target, "Component has no render target");
@ -175,7 +175,7 @@ namespace Ndk
float invWidth = 1.f/m_target->GetWidth(); float invWidth = 1.f/m_target->GetWidth();
float invHeight = 1.f/m_target->GetHeight(); float invHeight = 1.f/m_target->GetHeight();
SetTargetRegion(NzRectf(invWidth * viewport.x, invHeight * viewport.y, invWidth * viewport.width, invHeight * viewport.height)); SetTargetRegion(Nz::Rectf(invWidth * viewport.x, invHeight * viewport.y, invWidth * viewport.width, invHeight * viewport.height));
} }
inline void CameraComponent::SetZFar(float zFar) inline void CameraComponent::SetZFar(float zFar)
@ -187,7 +187,7 @@ namespace Ndk
inline void CameraComponent::SetZNear(float zNear) inline void CameraComponent::SetZNear(float zNear)
{ {
NazaraAssert(!NzNumberEquals(zNear, 0.f), "zNear cannot be zero"); NazaraAssert(!Nz::NumberEquals(zNear, 0.f), "zNear cannot be zero");
m_zNear = zNear; m_zNear = zNear;
InvalidateProjectionMatrix(); InvalidateProjectionMatrix();

View File

@ -11,7 +11,10 @@
#include <NDK/Component.hpp> #include <NDK/Component.hpp>
#include <memory> #include <memory>
class NzPhysObject; namespace Nz
{
class PhysObject;
}
namespace Ndk namespace Ndk
{ {
@ -23,30 +26,30 @@ namespace Ndk
friend class StaticCollisionSystem; friend class StaticCollisionSystem;
public: public:
CollisionComponent(NzPhysGeomRef geom = NzPhysGeomRef()); CollisionComponent(Nz::PhysGeomRef geom = Nz::PhysGeomRef());
CollisionComponent(const CollisionComponent& collision); CollisionComponent(const CollisionComponent& collision);
~CollisionComponent() = default; ~CollisionComponent() = default;
const NzPhysGeomRef& GetGeom() const; const Nz::PhysGeomRef& GetGeom() const;
void SetGeom(NzPhysGeomRef geom); void SetGeom(Nz::PhysGeomRef geom);
CollisionComponent& operator=(NzPhysGeomRef geom); CollisionComponent& operator=(Nz::PhysGeomRef geom);
CollisionComponent& operator=(CollisionComponent&& collision) = default; CollisionComponent& operator=(CollisionComponent&& collision) = default;
static ComponentIndex componentIndex; static ComponentIndex componentIndex;
private: private:
void InitializeStaticBody(); void InitializeStaticBody();
NzPhysObject* GetStaticBody(); Nz::PhysObject* GetStaticBody();
void OnAttached() override; void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override; void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override; void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override; void OnDetached() override;
std::unique_ptr<NzPhysObject> m_staticBody; std::unique_ptr<Nz::PhysObject> m_staticBody;
NzPhysGeomRef m_geom; Nz::PhysGeomRef m_geom;
bool m_bodyUpdated; bool m_bodyUpdated;
}; };
} }

View File

@ -9,7 +9,7 @@
namespace Ndk namespace Ndk
{ {
inline CollisionComponent::CollisionComponent(NzPhysGeomRef geom) : inline CollisionComponent::CollisionComponent(Nz::PhysGeomRef geom) :
m_geom(std::move(geom)), m_geom(std::move(geom)),
m_bodyUpdated(false) m_bodyUpdated(false)
{ {
@ -21,19 +21,19 @@ namespace Ndk
{ {
} }
inline const NzPhysGeomRef& CollisionComponent::GetGeom() const inline const Nz::PhysGeomRef& CollisionComponent::GetGeom() const
{ {
return m_geom; return m_geom;
} }
inline CollisionComponent& CollisionComponent::operator=(NzPhysGeomRef geom) inline CollisionComponent& CollisionComponent::operator=(Nz::PhysGeomRef geom)
{ {
SetGeom(geom); SetGeom(geom);
return *this; return *this;
} }
inline NzPhysObject* CollisionComponent::GetStaticBody() inline Nz::PhysObject* CollisionComponent::GetStaticBody()
{ {
return m_staticBody.get(); return m_staticBody.get();
} }

View File

@ -22,16 +22,16 @@ namespace Ndk
inline GraphicsComponent(const GraphicsComponent& graphicsComponent); inline GraphicsComponent(const GraphicsComponent& graphicsComponent);
~GraphicsComponent() = default; ~GraphicsComponent() = default;
inline void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const; inline void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const;
inline void Attach(NzInstancedRenderableRef renderable); inline void Attach(Nz::InstancedRenderableRef renderable);
inline void EnsureTransformMatrixUpdate() const; inline void EnsureTransformMatrixUpdate() const;
static ComponentIndex componentIndex; static ComponentIndex componentIndex;
private: private:
void InvalidateRenderableData(const NzInstancedRenderable* renderable, nzUInt32 flags, unsigned int index); void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index);
inline void InvalidateRenderables(); inline void InvalidateRenderables();
inline void InvalidateTransformMatrix(); inline void InvalidateTransformMatrix();
@ -39,29 +39,29 @@ namespace Ndk
void OnComponentAttached(BaseComponent& component) override; void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override; void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override; void OnDetached() override;
void OnNodeInvalidated(const NzNode* node); void OnNodeInvalidated(const Nz::Node* node);
void UpdateTransformMatrix() const; void UpdateTransformMatrix() const;
NazaraSlot(NzNode, OnNodeInvalidation, m_nodeInvalidationSlot); NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
struct Renderable struct Renderable
{ {
Renderable(NzMatrix4f& transformMatrix) : Renderable(Nz::Matrix4f& transformMatrix) :
data(transformMatrix), data(transformMatrix),
dataUpdated(false) dataUpdated(false)
{ {
} }
NazaraSlot(NzInstancedRenderable, OnInstancedRenderableInvalidateData, renderableInvalidationSlot); NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateData, renderableInvalidationSlot);
mutable NzInstancedRenderable::InstanceData data; mutable Nz::InstancedRenderable::InstanceData data;
NzInstancedRenderableRef renderable; Nz::InstancedRenderableRef renderable;
mutable bool dataUpdated; mutable bool dataUpdated;
}; };
std::vector<Renderable> m_renderables; std::vector<Renderable> m_renderables;
mutable NzMatrix4f m_transformMatrix; mutable Nz::Matrix4f m_transformMatrix;
mutable bool m_transformMatrixUpdated; mutable bool m_transformMatrixUpdated;
}; };
} }

View File

@ -16,7 +16,7 @@ namespace Ndk
Attach(r.renderable); Attach(r.renderable);
} }
inline void GraphicsComponent::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const inline void GraphicsComponent::AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const
{ {
EnsureTransformMatrixUpdate(); EnsureTransformMatrixUpdate();
@ -32,7 +32,7 @@ namespace Ndk
} }
} }
inline void GraphicsComponent::Attach(NzInstancedRenderableRef renderable) inline void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable)
{ {
m_renderables.emplace_back(m_transformMatrix); m_renderables.emplace_back(m_transformMatrix);
Renderable& r = m_renderables.back(); Renderable& r = m_renderables.back();

View File

@ -12,10 +12,10 @@
namespace Ndk namespace Ndk
{ {
class NDK_API LightComponent : public Component<LightComponent>, public NzLight class NDK_API LightComponent : public Component<LightComponent>, public Nz::Light
{ {
public: public:
inline LightComponent(nzLightType lightType = nzLightType_Point); inline LightComponent(Nz::LightType lightType = Nz::LightType_Point);
LightComponent(const LightComponent& light) = default; LightComponent(const LightComponent& light) = default;
~LightComponent() = default; ~LightComponent() = default;

View File

@ -4,8 +4,8 @@
namespace Ndk namespace Ndk
{ {
inline LightComponent::LightComponent(nzLightType lightType) : inline LightComponent::LightComponent(Nz::LightType lightType) :
NzLight(lightType) Nz::Light(lightType)
{ {
} }
} }

View File

@ -14,14 +14,14 @@ namespace Ndk
{ {
class Entity; class Entity;
class NDK_API NodeComponent : public Component<NodeComponent>, public NzNode class NDK_API NodeComponent : public Component<NodeComponent>, public Nz::Node
{ {
public: public:
NodeComponent() = default; NodeComponent() = default;
~NodeComponent() = default; ~NodeComponent() = default;
void SetParent(Entity* entity, bool keepDerived = false); void SetParent(Entity* entity, bool keepDerived = false);
using NzNode::SetParent; using Nz::Node::SetParent;
static ComponentIndex componentIndex; static ComponentIndex componentIndex;
}; };

View File

@ -13,9 +13,9 @@ namespace Ndk
{ {
NazaraAssert(entity->HasComponent<NodeComponent>(), "Entity must have a NodeComponent"); NazaraAssert(entity->HasComponent<NodeComponent>(), "Entity must have a NodeComponent");
NzNode::SetParent(entity->GetComponent<NodeComponent>(), keepDerived); Nz::Node::SetParent(entity->GetComponent<NodeComponent>(), keepDerived);
} }
else else
NzNode::SetParent(nullptr, keepDerived); Nz::Node::SetParent(nullptr, keepDerived);
} }
} }

View File

@ -25,45 +25,45 @@ namespace Ndk
PhysicsComponent(const PhysicsComponent& physics); PhysicsComponent(const PhysicsComponent& physics);
~PhysicsComponent() = default; ~PhysicsComponent() = default;
void AddForce(const NzVector3f& force, nzCoordSys coordSys = nzCoordSys_Global); void AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddForce(const NzVector3f& force, const NzVector3f& point, nzCoordSys coordSys = nzCoordSys_Global); void AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddTorque(const NzVector3f& torque, nzCoordSys coordSys = nzCoordSys_Global); void AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void EnableAutoSleep(bool autoSleep); void EnableAutoSleep(bool autoSleep);
NzBoxf GetAABB() const; Nz::Boxf GetAABB() const;
NzVector3f GetAngularVelocity() const; Nz::Vector3f GetAngularVelocity() const;
float GetGravityFactor() const; float GetGravityFactor() const;
float GetMass() const; float GetMass() const;
NzVector3f GetMassCenter(nzCoordSys coordSys = nzCoordSys_Local) const; Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
const NzMatrix4f& GetMatrix() const; const Nz::Matrix4f& GetMatrix() const;
NzVector3f GetPosition() const; Nz::Vector3f GetPosition() const;
NzQuaternionf GetRotation() const; Nz::Quaternionf GetRotation() const;
NzVector3f GetVelocity() const; Nz::Vector3f GetVelocity() const;
bool IsAutoSleepEnabled() const; bool IsAutoSleepEnabled() const;
bool IsMoveable() const; bool IsMoveable() const;
bool IsSleeping() const; bool IsSleeping() const;
void SetAngularVelocity(const NzVector3f& angularVelocity); void SetAngularVelocity(const Nz::Vector3f& angularVelocity);
void SetGravityFactor(float gravityFactor); void SetGravityFactor(float gravityFactor);
void SetMass(float mass); void SetMass(float mass);
void SetMassCenter(const NzVector3f& center); void SetMassCenter(const Nz::Vector3f& center);
void SetPosition(const NzVector3f& position); void SetPosition(const Nz::Vector3f& position);
void SetRotation(const NzQuaternionf& rotation); void SetRotation(const Nz::Quaternionf& rotation);
void SetVelocity(const NzVector3f& velocity); void SetVelocity(const Nz::Vector3f& velocity);
static ComponentIndex componentIndex; static ComponentIndex componentIndex;
private: private:
NzPhysObject& GetPhysObject(); Nz::PhysObject& GetPhysObject();
void OnAttached() override; void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override; void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override; void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override; void OnDetached() override;
std::unique_ptr<NzPhysObject> m_object; std::unique_ptr<Nz::PhysObject> m_object;
}; };
} }

View File

@ -12,21 +12,21 @@ namespace Ndk
NazaraUnused(physics); NazaraUnused(physics);
} }
inline void PhysicsComponent::AddForce(const NzVector3f& force, nzCoordSys coordSys) inline void PhysicsComponent::AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys)
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
m_object->AddForce(force, coordSys); m_object->AddForce(force, coordSys);
} }
inline void PhysicsComponent::AddForce(const NzVector3f& force, const NzVector3f& point, nzCoordSys coordSys) inline void PhysicsComponent::AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys)
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
m_object->AddForce(force, point, coordSys); m_object->AddForce(force, point, coordSys);
} }
inline void PhysicsComponent::AddTorque(const NzVector3f& torque, nzCoordSys coordSys) inline void PhysicsComponent::AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys)
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
@ -40,14 +40,14 @@ namespace Ndk
m_object->EnableAutoSleep(autoSleep); m_object->EnableAutoSleep(autoSleep);
} }
inline NzBoxf PhysicsComponent::GetAABB() const inline Nz::Boxf PhysicsComponent::GetAABB() const
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
return m_object->GetAABB(); return m_object->GetAABB();
} }
inline NzVector3f PhysicsComponent::GetAngularVelocity() const inline Nz::Vector3f PhysicsComponent::GetAngularVelocity() const
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
@ -68,35 +68,35 @@ namespace Ndk
return m_object->GetMass(); return m_object->GetMass();
} }
inline NzVector3f PhysicsComponent::GetMassCenter(nzCoordSys coordSys) const inline Nz::Vector3f PhysicsComponent::GetMassCenter(Nz::CoordSys coordSys) const
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
return m_object->GetMassCenter(coordSys); return m_object->GetMassCenter(coordSys);
} }
inline const NzMatrix4f& PhysicsComponent::GetMatrix() const inline const Nz::Matrix4f& PhysicsComponent::GetMatrix() const
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
return m_object->GetMatrix(); return m_object->GetMatrix();
} }
inline NzVector3f PhysicsComponent::GetPosition() const inline Nz::Vector3f PhysicsComponent::GetPosition() const
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
return m_object->GetPosition(); return m_object->GetPosition();
} }
inline NzQuaternionf PhysicsComponent::GetRotation() const inline Nz::Quaternionf PhysicsComponent::GetRotation() const
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
return m_object->GetRotation(); return m_object->GetRotation();
} }
inline NzVector3f PhysicsComponent::GetVelocity() const inline Nz::Vector3f PhysicsComponent::GetVelocity() const
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
@ -117,7 +117,7 @@ namespace Ndk
return m_object->IsSleeping(); return m_object->IsSleeping();
} }
inline void PhysicsComponent::SetAngularVelocity(const NzVector3f& angularVelocity) inline void PhysicsComponent::SetAngularVelocity(const Nz::Vector3f& angularVelocity)
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
@ -139,35 +139,35 @@ namespace Ndk
m_object->SetMass(mass); m_object->SetMass(mass);
} }
inline void PhysicsComponent::SetMassCenter(const NzVector3f& center) inline void PhysicsComponent::SetMassCenter(const Nz::Vector3f& center)
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
m_object->SetMassCenter(center); m_object->SetMassCenter(center);
} }
inline void PhysicsComponent::SetPosition(const NzVector3f& position) inline void PhysicsComponent::SetPosition(const Nz::Vector3f& position)
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
m_object->SetPosition(position); m_object->SetPosition(position);
} }
inline void PhysicsComponent::SetRotation(const NzQuaternionf& rotation) inline void PhysicsComponent::SetRotation(const Nz::Quaternionf& rotation)
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
m_object->SetRotation(rotation); m_object->SetRotation(rotation);
} }
inline void PhysicsComponent::SetVelocity(const NzVector3f& velocity) inline void PhysicsComponent::SetVelocity(const Nz::Vector3f& velocity)
{ {
NazaraAssert(m_object, "Invalid physics object"); NazaraAssert(m_object, "Invalid physics object");
m_object->SetVelocity(velocity); m_object->SetVelocity(velocity);
} }
inline NzPhysObject& PhysicsComponent::GetPhysObject() inline Nz::PhysObject& PhysicsComponent::GetPhysObject()
{ {
return *m_object.get(); return *m_object.get();
} }

View File

@ -17,12 +17,12 @@ namespace Ndk
class NDK_API VelocityComponent : public Component<VelocityComponent> class NDK_API VelocityComponent : public Component<VelocityComponent>
{ {
public: public:
VelocityComponent(const NzVector3f& velocity = NzVector3f::Zero()); VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero());
~VelocityComponent() = default; ~VelocityComponent() = default;
NzVector3f linearVelocity; Nz::Vector3f linearVelocity;
VelocityComponent& operator=(const NzVector3f& vel); VelocityComponent& operator=(const Nz::Vector3f& vel);
static ComponentIndex componentIndex; static ComponentIndex componentIndex;
}; };

View File

@ -7,12 +7,12 @@
namespace Ndk namespace Ndk
{ {
inline VelocityComponent::VelocityComponent(const NzVector3f& velocity) : inline VelocityComponent::VelocityComponent(const Nz::Vector3f& velocity) :
linearVelocity(velocity) linearVelocity(velocity)
{ {
} }
inline VelocityComponent& VelocityComponent::operator=(const NzVector3f& vel) inline VelocityComponent& VelocityComponent::operator=(const Nz::Vector3f& vel)
{ {
linearVelocity = vel; linearVelocity = vel;
return *this; return *this;

View File

@ -36,9 +36,9 @@ namespace Ndk
inline BaseComponent& GetComponent(ComponentIndex index); inline BaseComponent& GetComponent(ComponentIndex index);
template<typename ComponentType> ComponentType& GetComponent(); template<typename ComponentType> ComponentType& GetComponent();
inline const NzBitset<>& GetComponentBits() const; inline const Nz::Bitset<>& GetComponentBits() const;
inline EntityId GetId() const; inline EntityId GetId() const;
inline const NzBitset<>& GetSystemBits() const; inline const Nz::Bitset<>& GetSystemBits() const;
inline World* GetWorld() const; inline World* GetWorld() const;
inline bool HasComponent(ComponentIndex index) const; inline bool HasComponent(ComponentIndex index) const;
@ -69,9 +69,9 @@ namespace Ndk
std::vector<std::unique_ptr<BaseComponent>> m_components; std::vector<std::unique_ptr<BaseComponent>> m_components;
std::vector<EntityHandle*> m_handles; std::vector<EntityHandle*> m_handles;
Nz::Bitset<> m_componentBits;
Nz::Bitset<> m_systemBits;
EntityId m_id; EntityId m_id;
NzBitset<> m_componentBits;
NzBitset<> m_systemBits;
World* m_world; World* m_world;
bool m_valid; bool m_valid;
}; };

View File

@ -40,7 +40,7 @@ namespace Ndk
return static_cast<ComponentType&>(GetComponent(index)); return static_cast<ComponentType&>(GetComponent(index));
} }
inline const NzBitset<>& Entity::GetComponentBits() const inline const Nz::Bitset<>& Entity::GetComponentBits() const
{ {
return m_componentBits; return m_componentBits;
} }
@ -50,7 +50,7 @@ namespace Ndk
return m_id; return m_id;
} }
inline const NzBitset<>& Entity::GetSystemBits() const inline const Nz::Bitset<>& Entity::GetSystemBits() const
{ {
return m_systemBits; return m_systemBits;
} }

View File

@ -33,7 +33,7 @@ namespace Ndk
EntityHandle& Swap(EntityHandle& handle); EntityHandle& Swap(EntityHandle& handle);
NzString ToString() const; Nz::String ToString() const;
operator bool() const; operator bool() const;
operator Entity*() const; operator Entity*() const;

View File

@ -90,9 +90,9 @@ namespace Ndk
return *this; return *this;
} }
inline NzString EntityHandle::ToString() const inline Nz::String EntityHandle::ToString() const
{ {
NzStringStream ss; Nz::StringStream ss;
ss << "EntityHandle("; ss << "EntityHandle(";
if (IsValid()) if (IsValid())
ss << "Entity(" << m_entity->GetId() << ')'; ss << "Entity(" << m_entity->GetId() << ')';
@ -260,9 +260,9 @@ namespace Ndk
namespace std namespace std
{ {
template<> template<>
struct hash<Ndk::EntityHandle> struct hash<Ndk::EntityHandle>
{ {
size_t operator()(const Ndk::EntityHandle& handle) const size_t operator()(const Ndk::EntityHandle& handle) const
{ {
// Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée // Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée
@ -271,9 +271,9 @@ namespace std
return hash<Ndk::EntityId>()(id); return hash<Ndk::EntityId>()(id);
} }
}; };
inline void swap(Ndk::EntityHandle& lhs, Ndk::EntityHandle& rhs) inline void swap(Ndk::EntityHandle& lhs, Ndk::EntityHandle& rhs)
{ {
lhs.Swap(rhs); lhs.Swap(rhs);
} }

View File

@ -54,7 +54,7 @@ namespace Ndk
private: private:
std::vector<EntityHandle> m_entities; std::vector<EntityHandle> m_entities;
NzBitset<nzUInt64> m_entityBits; Nz::Bitset<Nz::UInt64> m_entityBits;
}; };
} }

View File

@ -44,7 +44,7 @@ namespace Ndk
} }
} }
// Interface STD // Nz::Interface STD
inline EntityList::Container::iterator EntityList::begin() inline EntityList::Container::iterator EntityList::begin()
{ {
return m_entities.begin(); return m_entities.begin();

View File

@ -57,10 +57,10 @@
namespace Ndk namespace Ndk
{ {
using ComponentId = nzUInt64; using ComponentId = Nz::UInt64;
using ComponentIndex = nzUInt32; using ComponentIndex = Nz::UInt32;
using EntityId = nzUInt32; using EntityId = Nz::UInt32;
using SystemIndex = nzUInt32; using SystemIndex = Nz::UInt32;
} }
#endif // NDK_PREREQUESITES_HPP #endif // NDK_PREREQUESITES_HPP

View File

@ -20,8 +20,8 @@ namespace Ndk
PhysicsSystem(const PhysicsSystem& system); PhysicsSystem(const PhysicsSystem& system);
~PhysicsSystem() = default; ~PhysicsSystem() = default;
NzPhysWorld& GetWorld(); Nz::PhysWorld& GetWorld();
const NzPhysWorld& GetWorld() const; const Nz::PhysWorld& GetWorld() const;
static SystemIndex systemIndex; static SystemIndex systemIndex;
@ -31,7 +31,7 @@ namespace Ndk
EntityList m_dynamicObjects; EntityList m_dynamicObjects;
EntityList m_staticObjects; EntityList m_staticObjects;
NzPhysWorld m_world; Nz::PhysWorld m_world;
}; };
} }

View File

@ -4,12 +4,12 @@
namespace Ndk namespace Ndk
{ {
inline NzPhysWorld& PhysicsSystem::GetWorld() inline Nz::PhysWorld& PhysicsSystem::GetWorld()
{ {
return m_world; return m_world;
} }
inline const NzPhysWorld& PhysicsSystem::GetWorld() const inline const Nz::PhysWorld& PhysicsSystem::GetWorld() const
{ {
return m_world; return m_world;
} }

View File

@ -25,16 +25,16 @@ namespace Ndk
inline RenderSystem(const RenderSystem& renderSystem); inline RenderSystem(const RenderSystem& renderSystem);
~RenderSystem() = default; ~RenderSystem() = default;
inline const NzBackgroundRef& GetDefaultBackground() const; inline const Nz::BackgroundRef& GetDefaultBackground() const;
inline const NzMatrix4f& GetCoordinateSystemMatrix() const; inline const Nz::Matrix4f& GetCoordinateSystemMatrix() const;
inline NzVector3f GetGlobalForward() const; inline Nz::Vector3f GetGlobalForward() const;
inline NzVector3f GetGlobalRight() const; inline Nz::Vector3f GetGlobalRight() const;
inline NzVector3f GetGlobalUp() const; inline Nz::Vector3f GetGlobalUp() const;
inline void SetDefaultBackground(NzBackgroundRef background); inline void SetDefaultBackground(Nz::BackgroundRef background);
inline void SetGlobalForward(const NzVector3f& direction); inline void SetGlobalForward(const Nz::Vector3f& direction);
inline void SetGlobalRight(const NzVector3f& direction); inline void SetGlobalRight(const Nz::Vector3f& direction);
inline void SetGlobalUp(const NzVector3f& direction); inline void SetGlobalUp(const Nz::Vector3f& direction);
static SystemIndex systemIndex; static SystemIndex systemIndex;
@ -48,9 +48,9 @@ namespace Ndk
EntityList m_cameras; EntityList m_cameras;
EntityList m_drawables; EntityList m_drawables;
EntityList m_lights; EntityList m_lights;
NzBackgroundRef m_background; Nz::BackgroundRef m_background;
NzForwardRenderTechnique m_renderTechnique; Nz::ForwardRenderTechnique m_renderTechnique;
NzMatrix4f m_coordinateSystemMatrix; Nz::Matrix4f m_coordinateSystemMatrix;
bool m_coordinateSystemInvalidated; bool m_coordinateSystemInvalidated;
}; };
} }

View File

@ -9,37 +9,37 @@ namespace Ndk
{ {
} }
inline const NzBackgroundRef& RenderSystem::GetDefaultBackground() const inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const
{ {
return m_background; return m_background;
} }
inline const NzMatrix4f& RenderSystem::GetCoordinateSystemMatrix() const inline const Nz::Matrix4f& RenderSystem::GetCoordinateSystemMatrix() const
{ {
return m_coordinateSystemMatrix; return m_coordinateSystemMatrix;
} }
inline NzVector3f RenderSystem::GetGlobalForward() const inline Nz::Vector3f RenderSystem::GetGlobalForward() const
{ {
return NzVector3f(-m_coordinateSystemMatrix.m13, -m_coordinateSystemMatrix.m23, -m_coordinateSystemMatrix.m33); return Nz::Vector3f(-m_coordinateSystemMatrix.m13, -m_coordinateSystemMatrix.m23, -m_coordinateSystemMatrix.m33);
} }
inline NzVector3f RenderSystem::GetGlobalRight() const inline Nz::Vector3f RenderSystem::GetGlobalRight() const
{ {
return NzVector3f(m_coordinateSystemMatrix.m11, m_coordinateSystemMatrix.m21, m_coordinateSystemMatrix.m31); return Nz::Vector3f(m_coordinateSystemMatrix.m11, m_coordinateSystemMatrix.m21, m_coordinateSystemMatrix.m31);
} }
inline NzVector3f RenderSystem::GetGlobalUp() const inline Nz::Vector3f RenderSystem::GetGlobalUp() const
{ {
return NzVector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32); return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32);
} }
inline void RenderSystem::SetDefaultBackground(NzBackgroundRef background) inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background)
{ {
m_background = std::move(background); m_background = std::move(background);
} }
inline void RenderSystem::SetGlobalForward(const NzVector3f& direction) inline void RenderSystem::SetGlobalForward(const Nz::Vector3f& direction)
{ {
m_coordinateSystemMatrix.m13 = -direction.x; m_coordinateSystemMatrix.m13 = -direction.x;
m_coordinateSystemMatrix.m23 = -direction.y; m_coordinateSystemMatrix.m23 = -direction.y;
@ -48,7 +48,7 @@ namespace Ndk
InvalidateCoordinateSystem(); InvalidateCoordinateSystem();
} }
inline void RenderSystem::SetGlobalRight(const NzVector3f& direction) inline void RenderSystem::SetGlobalRight(const Nz::Vector3f& direction)
{ {
m_coordinateSystemMatrix.m11 = direction.x; m_coordinateSystemMatrix.m11 = direction.x;
m_coordinateSystemMatrix.m21 = direction.y; m_coordinateSystemMatrix.m21 = direction.y;
@ -57,7 +57,7 @@ namespace Ndk
InvalidateCoordinateSystem(); InvalidateCoordinateSystem();
} }
inline void RenderSystem::SetGlobalUp(const NzVector3f& direction) inline void RenderSystem::SetGlobalUp(const Nz::Vector3f& direction)
{ {
m_coordinateSystemMatrix.m12 = direction.x; m_coordinateSystemMatrix.m12 = direction.x;
m_coordinateSystemMatrix.m22 = direction.y; m_coordinateSystemMatrix.m22 = direction.y;

View File

@ -8,7 +8,6 @@
#define NDK_WORLD_HPP #define NDK_WORLD_HPP
#include <Nazara/Core/Bitset.hpp> #include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <NDK/Entity.hpp> #include <NDK/Entity.hpp>
#include <NDK/EntityHandle.hpp> #include <NDK/EntityHandle.hpp>
#include <NDK/System.hpp> #include <NDK/System.hpp>
@ -19,7 +18,7 @@
namespace Ndk namespace Ndk
{ {
class NDK_API World : NzNonCopyable class NDK_API World
{ {
friend Entity; friend Entity;
@ -27,6 +26,8 @@ namespace Ndk
using EntityList = std::vector<EntityHandle>; using EntityList = std::vector<EntityHandle>;
inline World(bool addDefaultSystems = true); inline World(bool addDefaultSystems = true);
World(const World&) = delete;
World(World&&) = delete; ///TODO
~World(); ~World();
void AddDefaultSystems(); void AddDefaultSystems();
@ -60,6 +61,9 @@ namespace Ndk
void Update(); void Update();
inline void Update(float elapsedTime); inline void Update(float elapsedTime);
World& operator=(const World&) = delete;
World& operator=(World&&) = delete; ///TODO
private: private:
inline void Invalidate(); inline void Invalidate();
inline void Invalidate(EntityId id); inline void Invalidate(EntityId id);
@ -81,8 +85,8 @@ namespace Ndk
std::vector<EntityBlock> m_entities; std::vector<EntityBlock> m_entities;
std::vector<EntityId> m_freeIdList; std::vector<EntityId> m_freeIdList;
EntityList m_aliveEntities; EntityList m_aliveEntities;
NzBitset<nzUInt64> m_dirtyEntities; Nz::Bitset<Nz::UInt64> m_dirtyEntities;
NzBitset<nzUInt64> m_killedEntities; Nz::Bitset<Nz::UInt64> m_killedEntities;
}; };
} }

View File

@ -17,15 +17,15 @@ namespace Ndk
if (!entity) if (!entity)
return false; return false;
const NzBitset<>& components = entity->GetComponentBits(); const Nz::Bitset<>& components = entity->GetComponentBits();
m_filterResult.PerformsAND(m_requiredComponents, components); m_filterResult.PerformsAND(m_requiredComponents, components);
if (m_filterResult != m_requiredComponents) if (m_filterResult != m_requiredComponents)
return false; // Au moins un component requis n'est pas présent return false; // Au moins un component requis n'est pas présent
m_filterResult.PerformsAND(m_excludedComponents, components); m_filterResult.PerformsAND(m_excludedComponents, components);
if (m_filterResult.TestAny()) if (m_filterResult.TestAny())
return false; // Au moins un component exclu est présent return false; // Au moins un component exclu est présent
// Si nous avons une liste de composants nécessaires // Si nous avons une liste de composants nécessaires
if (m_requiredAnyComponents.TestAny()) if (m_requiredAnyComponents.TestAny())
@ -34,7 +34,7 @@ namespace Ndk
return false; return false;
} }
return true; return true;
} }
void BaseSystem::OnEntityAdded(Entity* entity) void BaseSystem::OnEntityAdded(Entity* entity)

View File

@ -17,20 +17,20 @@ namespace Ndk
EnsureViewMatrixUpdate(); EnsureViewMatrixUpdate();
EnsureViewportUpdate(); EnsureViewportUpdate();
NzRenderer::SetMatrix(nzMatrixType_Projection, m_projectionMatrix); Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, m_projectionMatrix);
NzRenderer::SetMatrix(nzMatrixType_View, m_viewMatrix); Nz::Renderer::SetMatrix(Nz::MatrixType_View, m_viewMatrix);
NzRenderer::SetTarget(m_target); Nz::Renderer::SetTarget(m_target);
NzRenderer::SetViewport(m_viewport); Nz::Renderer::SetViewport(m_viewport);
} }
NzVector3f CameraComponent::GetEyePosition() const Nz::Vector3f CameraComponent::GetEyePosition() const
{ {
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "CameraComponent requires NodeComponent"); NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "CameraComponent requires NodeComponent");
return m_entity->GetComponent<NodeComponent>().GetPosition(); return m_entity->GetComponent<NodeComponent>().GetPosition();
} }
NzVector3f CameraComponent::GetForward() const Nz::Vector3f CameraComponent::GetForward() const
{ {
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "CameraComponent requires NodeComponent"); NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "CameraComponent requires NodeComponent");
@ -80,7 +80,7 @@ namespace Ndk
InvalidateViewMatrix(); InvalidateViewMatrix();
} }
void CameraComponent::OnNodeInvalidated(const NzNode* node) void CameraComponent::OnNodeInvalidated(const Nz::Node* node)
{ {
NazaraUnused(node); NazaraUnused(node);
@ -88,20 +88,20 @@ namespace Ndk
InvalidateViewMatrix(); InvalidateViewMatrix();
} }
void CameraComponent::OnRenderTargetRelease(const NzRenderTarget* renderTarget) void CameraComponent::OnRenderTargetRelease(const Nz::RenderTarget* renderTarget)
{ {
if (renderTarget == m_target) if (renderTarget == m_target)
m_target = nullptr; m_target = nullptr;
else else
NazaraInternalError("Not listening to " + NzString::Pointer(renderTarget)); NazaraInternalError("Not listening to " + Nz::String::Pointer(renderTarget));
} }
void CameraComponent::OnRenderTargetSizeChange(const NzRenderTarget* renderTarget) void CameraComponent::OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget)
{ {
if (renderTarget == m_target) if (renderTarget == m_target)
InvalidateViewport(); InvalidateViewport();
else else
NazaraInternalError("Not listening to " + NzString::Pointer(renderTarget)); NazaraInternalError("Not listening to " + Nz::String::Pointer(renderTarget));
} }
void CameraComponent::UpdateFrustum() const void CameraComponent::UpdateFrustum() const
@ -118,13 +118,13 @@ namespace Ndk
{ {
switch (m_projectionType) switch (m_projectionType)
{ {
case nzProjectionType_Orthogonal: case Nz::ProjectionType_Orthogonal:
EnsureViewportUpdate(); 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);
break; break;
case nzProjectionType_Perspective: case Nz::ProjectionType_Perspective:
EnsureViewportUpdate(); // Can affect aspect ratio EnsureViewportUpdate(); // Can affect aspect ratio
m_projectionMatrix.MakePerspective(m_fov, m_aspectRatio, m_zNear, m_zFar); m_projectionMatrix.MakePerspective(m_fov, m_aspectRatio, m_zNear, m_zFar);
@ -141,7 +141,7 @@ namespace Ndk
NodeComponent& nodeComponent = m_entity->GetComponent<NodeComponent>(); NodeComponent& nodeComponent = m_entity->GetComponent<NodeComponent>();
// Build the view matrix using the NodeComponent position/rotation // Build the view matrix using the NodeComponent position/rotation
m_viewMatrix.MakeViewMatrix(nodeComponent.GetPosition(nzCoordSys_Global), nodeComponent.GetRotation(nzCoordSys_Global)); m_viewMatrix.MakeViewMatrix(nodeComponent.GetPosition(Nz::CoordSys_Global), nodeComponent.GetRotation(Nz::CoordSys_Global));
m_viewMatrixUpdated = true; m_viewMatrixUpdated = true;
} }
@ -153,7 +153,7 @@ namespace Ndk
unsigned int targetHeight = std::max(m_target->GetHeight(), 1U); // Let's make sure we won't divide by zero unsigned int targetHeight = std::max(m_target->GetHeight(), 1U); // Let's make sure we won't divide by zero
// Our target region is expressed as % of the viewport dimensions, let's compute it in pixels // Our target region is expressed as % of the viewport dimensions, let's compute it in pixels
NzRectf fViewport(m_targetRegion); Nz::Rectf fViewport(m_targetRegion);
fViewport.x *= targetWidth; fViewport.x *= targetWidth;
fViewport.y *= targetHeight; fViewport.y *= targetHeight;
fViewport.width *= targetWidth; fViewport.width *= targetWidth;
@ -161,11 +161,11 @@ namespace Ndk
// Compute the new aspect ratio, if it's different we need to invalidate the projection matrix // Compute the new aspect ratio, if it's different we need to invalidate the projection matrix
float aspectRatio = fViewport.width/fViewport.height; float aspectRatio = fViewport.width/fViewport.height;
if (!NzNumberEquals(m_aspectRatio, aspectRatio, 0.001f)) if (!Nz::NumberEquals(m_aspectRatio, aspectRatio, 0.001f))
{ {
m_aspectRatio = aspectRatio; m_aspectRatio = aspectRatio;
if (m_projectionType == nzProjectionType_Perspective) if (m_projectionType == Nz::ProjectionType_Perspective)
InvalidateProjectionMatrix(); InvalidateProjectionMatrix();
} }

View File

@ -11,7 +11,7 @@
namespace Ndk namespace Ndk
{ {
void CollisionComponent::SetGeom(NzPhysGeomRef geom) void CollisionComponent::SetGeom(Nz::PhysGeomRef geom)
{ {
m_geom = std::move(geom); m_geom = std::move(geom);
@ -35,9 +35,9 @@ namespace Ndk
NazaraAssert(entityWorld, "Entity must have world"); NazaraAssert(entityWorld, "Entity must have world");
NazaraAssert(entityWorld->HasSystem<PhysicsSystem>(), "World must have a physics system"); NazaraAssert(entityWorld->HasSystem<PhysicsSystem>(), "World must have a physics system");
NzPhysWorld& physWorld = entityWorld->GetSystem<PhysicsSystem>().GetWorld(); Nz::PhysWorld& physWorld = entityWorld->GetSystem<PhysicsSystem>().GetWorld();
m_staticBody.reset(new NzPhysObject(&physWorld, m_geom)); m_staticBody.reset(new Nz::PhysObject(&physWorld, m_geom));
m_staticBody->EnableAutoSleep(false); m_staticBody->EnableAutoSleep(false);
} }

View File

@ -9,7 +9,7 @@
namespace Ndk namespace Ndk
{ {
void GraphicsComponent::InvalidateRenderableData(const NzInstancedRenderable* renderable, nzUInt32 flags, unsigned int index) void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index)
{ {
NazaraAssert(index < m_renderables.size(), "Invalid renderable index"); NazaraAssert(index < m_renderables.size(), "Invalid renderable index");
NazaraUnused(renderable); NazaraUnused(renderable);
@ -55,7 +55,7 @@ namespace Ndk
InvalidateTransformMatrix(); InvalidateTransformMatrix();
} }
void GraphicsComponent::OnNodeInvalidated(const NzNode* node) void GraphicsComponent::OnNodeInvalidated(const Nz::Node* node)
{ {
NazaraUnused(node); NazaraUnused(node);
@ -69,7 +69,7 @@ namespace Ndk
Ndk::RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem<Ndk::RenderSystem>(); Ndk::RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem<Ndk::RenderSystem>();
m_transformMatrix = NzMatrix4f::ConcatenateAffine(renderSystem.GetCoordinateSystemMatrix(), m_entity->GetComponent<NodeComponent>().GetTransformMatrix()); m_transformMatrix = Nz::Matrix4f::ConcatenateAffine(renderSystem.GetCoordinateSystemMatrix(), m_entity->GetComponent<NodeComponent>().GetTransformMatrix());
m_transformMatrixUpdated = true; m_transformMatrixUpdated = true;
} }

View File

@ -17,19 +17,19 @@ namespace Ndk
World* entityWorld = m_entity->GetWorld(); World* entityWorld = m_entity->GetWorld();
NazaraAssert(entityWorld->HasSystem<PhysicsSystem>(), "World must have a physics system"); NazaraAssert(entityWorld->HasSystem<PhysicsSystem>(), "World must have a physics system");
NzPhysWorld& world = entityWorld->GetSystem<PhysicsSystem>().GetWorld(); Nz::PhysWorld& world = entityWorld->GetSystem<PhysicsSystem>().GetWorld();
NzPhysGeomRef geom; Nz::PhysGeomRef geom;
if (m_entity->HasComponent<CollisionComponent>()) if (m_entity->HasComponent<CollisionComponent>())
geom = m_entity->GetComponent<CollisionComponent>().GetGeom(); geom = m_entity->GetComponent<CollisionComponent>().GetGeom();
NzMatrix4f matrix; Nz::Matrix4f matrix;
if (m_entity->HasComponent<NodeComponent>()) if (m_entity->HasComponent<NodeComponent>())
matrix = m_entity->GetComponent<NodeComponent>().GetTransformMatrix(); matrix = m_entity->GetComponent<NodeComponent>().GetTransformMatrix();
else else
matrix.MakeIdentity(); matrix.MakeIdentity();
m_object.reset(new NzPhysObject(&world, geom, matrix)); m_object.reset(new Nz::PhysObject(&world, geom, matrix));
m_object->SetMass(1.f); m_object->SetMass(1.f);
} }
@ -47,7 +47,7 @@ namespace Ndk
if (IsComponent<CollisionComponent>(component)) if (IsComponent<CollisionComponent>(component))
{ {
NazaraAssert(m_object, "Invalid object"); NazaraAssert(m_object, "Invalid object");
m_object->SetGeom(NzNullGeom::New()); m_object->SetGeom(Nz::NullGeom::New());
} }
} }

View File

@ -35,19 +35,19 @@ namespace Ndk
try try
{ {
NzErrorFlags errFlags(nzErrorFlag_ThrowException, true); Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
// Initialisation du moteur // Initialisation du moteur
// Modules clients // Modules clients
NzAudio::Initialize(); Nz::Audio::Initialize();
NzGraphics::Initialize(); Nz::Graphics::Initialize();
// Modules serveurs // Modules serveurs
NzLua::Initialize(); Nz::Lua::Initialize();
NzNoise::Initialize(); Nz::Noise::Initialize();
NzPhysics::Initialize(); Nz::Physics::Initialize();
NzUtility::Initialize(); Nz::Utility::Initialize();
// Initialisation du SDK // Initialisation du SDK
@ -76,7 +76,7 @@ namespace Ndk
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
NazaraError("Failed to initialize NDK: " + NzString(e.what())); NazaraError("Failed to initialize NDK: " + Nz::String(e.what()));
return false; return false;
} }
@ -99,14 +99,14 @@ namespace Ndk
// Libération du moteur // Libération du moteur
// Modules clients // Modules clients
NzAudio::Uninitialize(); Nz::Audio::Uninitialize();
NzGraphics::Uninitialize(); Nz::Graphics::Uninitialize();
// Modules serveurs // Modules serveurs
NzLua::Uninitialize(); Nz::Lua::Uninitialize();
NzNoise::Uninitialize(); Nz::Noise::Uninitialize();
NzPhysics::Uninitialize(); Nz::Physics::Uninitialize();
NzUtility::Uninitialize(); Nz::Utility::Uninitialize();
NazaraNotice("Uninitialized: SDK"); NazaraNotice("Uninitialized: SDK");
} }

View File

@ -30,22 +30,22 @@ namespace Ndk
// On récupère la position et la rotation pour les affecter au listener // On récupère la position et la rotation pour les affecter au listener
const NodeComponent& node = entity->GetComponent<NodeComponent>(); const NodeComponent& node = entity->GetComponent<NodeComponent>();
NzAudio::SetListenerPosition(node.GetPosition(nzCoordSys_Global)); Nz::Audio::SetListenerPosition(node.GetPosition(Nz::CoordSys_Global));
NzAudio::SetListenerRotation(node.GetRotation(nzCoordSys_Global)); Nz::Audio::SetListenerRotation(node.GetRotation(Nz::CoordSys_Global));
// On vérifie la présence d'une donnée de vitesse, et on l'affecte // On vérifie la présence d'une donnée de vitesse, et on l'affecte
// (La vitesse du listener Audio ne le fait pas se déplacer, mais affecte par exemple l'effet Doppler) // (La vitesse du listener Audio ne le fait pas se déplacer, mais affecte par exemple l'effet Doppler)
if (entity->HasComponent<VelocityComponent>()) if (entity->HasComponent<VelocityComponent>())
{ {
const VelocityComponent& velocity = entity->GetComponent<VelocityComponent>(); const VelocityComponent& velocity = entity->GetComponent<VelocityComponent>();
NzAudio::SetListenerVelocity(velocity.linearVelocity); Nz::Audio::SetListenerVelocity(velocity.linearVelocity);
} }
activeListenerCount++; activeListenerCount++;
} }
if (activeListenerCount > 1) if (activeListenerCount > 1)
NazaraWarning(NzString::Number(activeListenerCount) + " listeners were active in the same update loop"); NazaraWarning(Nz::String::Number(activeListenerCount) + " listeners were active in the same update loop");
} }
SystemIndex ListenerSystem::systemIndex; SystemIndex ListenerSystem::systemIndex;

View File

@ -45,9 +45,9 @@ namespace Ndk
NodeComponent& node = entity->GetComponent<NodeComponent>(); NodeComponent& node = entity->GetComponent<NodeComponent>();
PhysicsComponent& phys = entity->GetComponent<PhysicsComponent>(); PhysicsComponent& phys = entity->GetComponent<PhysicsComponent>();
NzPhysObject& physObj = phys.GetPhysObject(); Nz::PhysObject& physObj = phys.GetPhysObject();
node.SetRotation(physObj.GetRotation(), nzCoordSys_Global); node.SetRotation(physObj.GetRotation(), Nz::CoordSys_Global);
node.SetPosition(physObj.GetPosition(), nzCoordSys_Global); node.SetPosition(physObj.GetPosition(), Nz::CoordSys_Global);
} }
float invElapsedTime = 1.f / elapsedTime; float invElapsedTime = 1.f / elapsedTime;
@ -56,12 +56,12 @@ namespace Ndk
CollisionComponent& collision = entity->GetComponent<CollisionComponent>(); CollisionComponent& collision = entity->GetComponent<CollisionComponent>();
NodeComponent& node = entity->GetComponent<NodeComponent>(); NodeComponent& node = entity->GetComponent<NodeComponent>();
NzPhysObject* physObj = collision.GetStaticBody(); Nz::PhysObject* physObj = collision.GetStaticBody();
NzQuaternionf oldRotation = physObj->GetRotation(); Nz::Quaternionf oldRotation = physObj->GetRotation();
NzVector3f oldPosition = physObj->GetPosition(); Nz::Vector3f oldPosition = physObj->GetPosition();
NzQuaternionf newRotation = node.GetRotation(nzCoordSys_Global); Nz::Quaternionf newRotation = node.GetRotation(Nz::CoordSys_Global);
NzVector3f newPosition = node.GetPosition(nzCoordSys_Global); Nz::Vector3f newPosition = node.GetPosition(Nz::CoordSys_Global);
// Pour déplacer des objets statiques et assurer les collisions, il faut leur définir une vitesse // Pour déplacer des objets statiques et assurer les collisions, il faut leur définir une vitesse
// (note importante: le moteur physique n'applique pas la vitesse sur les objets statiques) // (note importante: le moteur physique n'applique pas la vitesse sur les objets statiques)
@ -71,21 +71,21 @@ namespace Ndk
physObj->SetVelocity((newPosition - oldPosition) * invElapsedTime); physObj->SetVelocity((newPosition - oldPosition) * invElapsedTime);
} }
else else
physObj->SetVelocity(NzVector3f::Zero()); physObj->SetVelocity(Nz::Vector3f::Zero());
if (newRotation != oldRotation) if (newRotation != oldRotation)
{ {
NzQuaternionf transition = newRotation * oldRotation.GetConjugate(); Nz::Quaternionf transition = newRotation * oldRotation.GetConjugate();
NzEulerAnglesf angles = transition.ToEulerAngles(); Nz::EulerAnglesf angles = transition.ToEulerAngles();
NzVector3f angularVelocity(NzToRadians(angles.pitch * invElapsedTime), Nz::Vector3f angularVelocity(Nz::ToRadians(angles.pitch * invElapsedTime),
NzToRadians(angles.yaw * invElapsedTime), Nz::ToRadians(angles.yaw * invElapsedTime),
NzToRadians(angles.roll * invElapsedTime)); Nz::ToRadians(angles.roll * invElapsedTime));
physObj->SetRotation(oldRotation); physObj->SetRotation(oldRotation);
physObj->SetAngularVelocity(angularVelocity); physObj->SetAngularVelocity(angularVelocity);
} }
else else
physObj->SetAngularVelocity(NzVector3f::Zero()); physObj->SetAngularVelocity(Nz::Vector3f::Zero());
} }
} }

View File

@ -12,10 +12,10 @@
namespace Ndk namespace Ndk
{ {
RenderSystem::RenderSystem() : RenderSystem::RenderSystem() :
m_coordinateSystemMatrix(NzMatrix4f::Identity()), m_coordinateSystemMatrix(Nz::Matrix4f::Identity()),
m_coordinateSystemInvalidated(true) m_coordinateSystemInvalidated(true)
{ {
SetDefaultBackground(NzColorBackground::New()); SetDefaultBackground(Nz::ColorBackground::New());
SetUpdateRate(0.f); SetUpdateRate(0.f);
} }
@ -73,7 +73,7 @@ namespace Ndk
CameraComponent& camComponent = camera->GetComponent<CameraComponent>(); CameraComponent& camComponent = camera->GetComponent<CameraComponent>();
camComponent.ApplyView(); camComponent.ApplyView();
NzAbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue(); Nz::AbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue();
renderQueue->Clear(); renderQueue->Clear();
//TODO: Culling //TODO: Culling
@ -91,11 +91,11 @@ namespace Ndk
NodeComponent& drawableNode = light->GetComponent<NodeComponent>(); NodeComponent& drawableNode = light->GetComponent<NodeComponent>();
///TODO: Cache somehow? ///TODO: Cache somehow?
lightComponent.AddToRenderQueue(renderQueue, NzMatrix4f::ConcatenateAffine(m_coordinateSystemMatrix, drawableNode.GetTransformMatrix())); lightComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::ConcatenateAffine(m_coordinateSystemMatrix, drawableNode.GetTransformMatrix()));
} }
NzSceneData sceneData; Nz::SceneData sceneData;
sceneData.ambientColor = NzColor(25, 25, 25); sceneData.ambientColor = Nz::Color(25, 25, 25);
sceneData.background = m_background; sceneData.background = m_background;
sceneData.viewer = &camComponent; sceneData.viewer = &camComponent;

View File

@ -18,7 +18,7 @@
int main() int main()
{ {
// NzKeyboard ne nécessite pas l'initialisation du module Utilitaire // NzKeyboard ne nécessite pas l'initialisation du module Utilitaire
NzInitializer<NzAudio> audio; Nz::Initializer<Nz::Audio> audio;
if (!audio) if (!audio)
{ {
std::cout << "Failed to initialize audio module" << std::endl; std::cout << "Failed to initialize audio module" << std::endl;
@ -26,7 +26,7 @@ int main()
return 1; return 1;
} }
NzSound sound; Nz::Sound sound;
if (!sound.LoadFromFile("resources/siren.wav")) if (!sound.LoadFromFile("resources/siren.wav"))
{ {
std::cout << "Failed to load sound" << std::endl; std::cout << "Failed to load sound" << std::endl;
@ -44,32 +44,32 @@ int main()
sound.EnableLooping(true); sound.EnableLooping(true);
// La source du son se situe vers la gauche (Et un peu en avant) // La source du son se situe vers la gauche (Et un peu en avant)
sound.SetPosition(NzVector3f::Left()*50.f + NzVector3f::Forward()*5.f); sound.SetPosition(Nz::Vector3f::Left()*50.f + Nz::Vector3f::Forward()*5.f);
// Et possède une vitesse de 10 par seconde vers la droite // Et possède une vitesse de 10 par seconde vers la droite
sound.SetVelocity(NzVector3f::Left()*-10.f); sound.SetVelocity(Nz::Vector3f::Left()*-10.f);
// On joue le son // On joue le son
sound.Play(); sound.Play();
// La boucle du programme (Pour déplacer le son) // La boucle du programme (Pour déplacer le son)
NzClock clock; Nz::Clock clock;
while (sound.GetStatus() == nzSoundStatus_Playing) while (sound.GetStatus() == Nz::SoundStatus_Playing)
{ {
// Comme le son se joue dans un thread séparé, on peut mettre en pause le principal régulièrement // Comme le son se joue dans un thread séparé, on peut mettre en pause le principal régulièrement
int sleepTime = int(1000/60 - clock.GetMilliseconds()); // 60 FPS int sleepTime = int(1000/60 - clock.GetMilliseconds()); // 60 FPS
if (sleepTime > 0) if (sleepTime > 0)
NzThread::Sleep(sleepTime); Nz::Thread::Sleep(sleepTime);
// On bouge la source du son en fonction du temps depuis chaque mise à jour // On bouge la source du son en fonction du temps depuis chaque mise à jour
NzVector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds(); Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds();
sound.SetPosition(pos); sound.SetPosition(pos);
std::cout << "Sound position: " << pos << std::endl; std::cout << "Sound position: " << pos << std::endl;
// Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap // Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap
if (pos.x > NzVector3f::Left().x*-50.f || NzKeyboard::IsKeyPressed(NzKeyboard::Escape)) if (pos.x > Nz::Vector3f::Left().x*-50.f || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Escape))
sound.Stop(); // On arrête le son (Stoppant également la boucle) sound.Stop(); // On arrête le son (Stoppant également la boucle)
clock.Restart(); clock.Restart();

View File

@ -1,5 +1,5 @@
/* /*
** HardwareInfo - Récupération des caractéristiques de l'ordinateur ** Nz::HardwareInfo - Récupération des caractéristiques de l'ordinateur
** Prérequis: Aucun ** Prérequis: Aucun
** Utilisation du noyau et du module de rendu ** Utilisation du noyau et du module de rendu
** Présente: ** Présente:
@ -15,7 +15,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
void printCap(std::ostream& o, const NzString& cap, bool b); void printCap(std::ostream& o, const Nz::String& cap, bool b);
int main() int main()
{ {
@ -28,63 +28,63 @@ int main()
// Plutôt que d'initialiser le Renderer de Nazara, nous initialisons les deux classes utilisées ici // Plutôt que d'initialiser le Renderer de Nazara, nous initialisons les deux classes utilisées ici
// Elles sont compatibles avec NzInitialiser et seront donc libérées automatiquement // Elles sont compatibles avec NzInitialiser et seront donc libérées automatiquement
// Cela permet d'avoir une initialisation plus rapide et un coût en mémoire moindre // Cela permet d'avoir une initialisation plus rapide et un coût en mémoire moindre
NzInitializer<NzHardwareInfo> hardwareInfo; Nz::Initializer<Nz::HardwareInfo> hardwareInfo;
if (hardwareInfo) if (hardwareInfo)
{ {
// On commence par les informations sur le processeur, Nazara en récupère trois caractéristiques: // On commence par les informations sur le processeur, Nazara en récupère trois caractéristiques:
// 1) La "brand string", qui est une chaîne de 48 caractères identifiant le processeur // 1) La "brand string", qui est une chaîne de 48 caractères identifiant le processeur
// 2) Le concepteur du processeur, accessible via une énumération (GetProcessorVendor) ou une chaîne de caractère (GetProcessorVendorName) // 2) Le concepteur du processeur, accessible via une énumération (GetProcessorVendor) ou une chaîne de caractère (GetProcessorVendorName)
// 3) Le nombre de processeurs logique, alias bien souvent le nombre de coeurs (logiques), cette valeur est renvoyée par l'OS (Le SMT multiplie donc la valeur réelle) // 3) Le nombre de processeurs logique, alias bien souvent le nombre de coeurs (logiques), cette valeur est renvoyée par l'OS (Le SMT multiplie donc la valeur réelle)
oss << "Identification: " << NzHardwareInfo::GetProcessorBrandString() << std::endl; oss << "Identification: " << Nz::HardwareInfo::GetProcessorBrandString() << std::endl;
oss << "Concepteur: " << NzHardwareInfo::GetProcessorVendorName() << std::endl; oss << "Concepteur: " << Nz::HardwareInfo::GetProcessorVendorName() << std::endl;
oss << "Nombre de coeurs logiques: " << NzHardwareInfo::GetProcessorCount() << std::endl; oss << "Nombre de coeurs logiques: " << Nz::HardwareInfo::GetProcessorCount() << std::endl;
oss << std::endl; oss << std::endl;
// Ensuite, Nazara récupère les capacités du processeur, dont des jeux d'extensions supplémentaires // Ensuite, Nazara récupère les capacités du processeur, dont des jeux d'extensions supplémentaires
oss << "Rapport des capacites: " << std::endl;// Pas d'accent car écriture dans un fichier (et on ne va pas s'embêter avec ça) oss << "Rapport des capacites: " << std::endl;// Pas d'accent car écriture dans un fichier (et on ne va pas s'embêter avec ça)
printCap(oss, "-64bits", NzHardwareInfo::HasCapability(nzProcessorCap_x64)); printCap(oss, "-64bits", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_x64));
printCap(oss, "-AVX", NzHardwareInfo::HasCapability(nzProcessorCap_AVX)); printCap(oss, "-AVX", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_AVX));
printCap(oss, "-FMA3", NzHardwareInfo::HasCapability(nzProcessorCap_FMA3)); printCap(oss, "-FMA3", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_FMA3));
printCap(oss, "-FMA4", NzHardwareInfo::HasCapability(nzProcessorCap_FMA4)); printCap(oss, "-FMA4", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_FMA4));
printCap(oss, "-MMX", NzHardwareInfo::HasCapability(nzProcessorCap_MMX)); printCap(oss, "-MMX", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_MMX));
printCap(oss, "-SSE", NzHardwareInfo::HasCapability(nzProcessorCap_SSE)); printCap(oss, "-SSE", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_SSE));
printCap(oss, "-SSE2", NzHardwareInfo::HasCapability(nzProcessorCap_SSE2)); printCap(oss, "-SSE2", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_SSE2));
printCap(oss, "-SSE3", NzHardwareInfo::HasCapability(nzProcessorCap_SSE3)); printCap(oss, "-SSE3", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_SSE3));
printCap(oss, "-SSSE3", NzHardwareInfo::HasCapability(nzProcessorCap_SSSE3)); printCap(oss, "-SSSE3", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_SSSE3));
printCap(oss, "-SSE4.1", NzHardwareInfo::HasCapability(nzProcessorCap_SSE41)); printCap(oss, "-SSE4.1", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_SSE41));
printCap(oss, "-SSE4.2", NzHardwareInfo::HasCapability(nzProcessorCap_SSE42)); printCap(oss, "-SSE4.2", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_SSE42));
printCap(oss, "-SSE4.a", NzHardwareInfo::HasCapability(nzProcessorCap_SSE4a)); printCap(oss, "-SSE4.a", Nz::HardwareInfo::HasCapability(Nz::ProcessorCap_SSE4a));
} }
else else
oss << "Impossible de retrouver les informations du processeur" << std::endl; oss << "Impossible de retrouver les informations du processeur" << std::endl;
oss << std::endl << "--Carte graphique--" << std::endl; oss << std::endl << "--Carte graphique--" << std::endl;
// La classe NzOpenGL nous donne accès à des informations sur la carte graphique // La classe OpenGL nous donne accès à des informations sur la carte graphique
// Cependant celle-ci n'est accessible que si le projet est compilé avec NAZARA_RENDERER_OPENGL // Cependant celle-ci n'est accessible que si le projet est compilé avec NAZARA_RENDERER_OPENGL
// et que les répertoires d'inclusions donnent accès aux includes d'OpenGL (Cette démo utilisent ceux de Nazara) // et que les répertoires d'inclusions donnent accès aux includes d'OpenGL (Cette démo utilisent ceux de Nazara)
NzInitializer<NzOpenGL> openGL; Nz::Initializer<Nz::OpenGL> openGL;
if (openGL) if (openGL)
{ {
// Nous récupérons ensuite la version d'OpenGL sous forme d'entier (ex: OpenGL 3.3 donnera 330) // Nous récupérons ensuite la version d'OpenGL sous forme d'entier (ex: OpenGL 3.3 donnera 330)
unsigned int openglVersion = NzOpenGL::GetVersion(); unsigned int openglVersion = Nz::OpenGL::GetVersion();
// NzOpenGL nous donne accès à trois informations principales: // OpenGL nous donne accès à trois informations principales:
// 1) La chaîne d'identification du driver ("Renderer name") // 1) La chaîne d'identification du driver ("Renderer name")
// 2) La chaîne d'identification du concepteur ("Vendor name") // 2) La chaîne d'identification du concepteur ("Vendor name")
// 3) La version d'OpenGL // 3) La version d'OpenGL
oss << "Identification: " << NzOpenGL::GetRendererName() << std::endl; oss << "Identification: " << Nz::OpenGL::GetRendererName() << std::endl;
oss << "Concepteur: " << NzOpenGL::GetVendorName() << std::endl; oss << "Concepteur: " << Nz::OpenGL::GetVendorName() << std::endl;
oss << "Version d'OpenGL: " << openglVersion/100 << '.' << openglVersion%100 << std::endl; oss << "Version d'OpenGL: " << openglVersion/100 << '.' << openglVersion%100 << std::endl;
oss << std::endl; oss << std::endl;
// Ainsi qu'un report des capacités de la carte graphique (avec le driver actuel) // Ainsi qu'un report des capacités de la carte graphique (avec le driver actuel)
oss << "Rapport des capacites: " << std::endl; // Pas d'accent car écriture dans un fichier (et on ne va pas s'embêter avec ça) oss << "Rapport des capacites: " << std::endl; // Pas d'accent car écriture dans un fichier (et on ne va pas s'embêter avec ça)
printCap(oss, "-Calculs 64bits", NzOpenGL::IsSupported(nzOpenGLExtension_FP64)); printCap(oss, "-Calculs 64bits", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_FP64));
printCap(oss, "-Compression de textures (s3tc)", NzOpenGL::IsSupported(nzOpenGLExtension_TextureCompression_s3tc)); printCap(oss, "-Compression de textures (s3tc)", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_TextureCompression_s3tc));
printCap(oss, "-Filtrage anisotrope", NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)); printCap(oss, "-Filtrage anisotrope", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_AnisotropicFilter));
printCap(oss, "-Mode debug", NzOpenGL::IsSupported(nzOpenGLExtension_DebugOutput)); printCap(oss, "-Mode debug", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_DebugOutput));
printCap(oss, "-Separate shader objects", NzOpenGL::IsSupported(nzOpenGLExtension_SeparateShaderObjects)); printCap(oss, "-Separate shader objects", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_SeparateShaderObjects));
printCap(oss, "-Texture storage", NzOpenGL::IsSupported(nzOpenGLExtension_TextureStorage)); printCap(oss, "-Texture storage", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_TextureStorage));
} }
else else
oss << "Impossible de retrouver les informations de la carte graphique" << std::endl; oss << "Impossible de retrouver les informations de la carte graphique" << std::endl;
@ -94,14 +94,14 @@ int main()
std::cout << oss.str() << std::endl; std::cout << oss.str() << std::endl;
NzFile reportFile("RapportHardwareInfo.txt"); Nz::File reportFile("RapportNz::HardwareInfo.txt");
if (reportFile.Open(nzOpenMode_Text | nzOpenMode_Truncate | nzOpenMode_WriteOnly)) if (reportFile.Open(Nz::OpenMode_Text | Nz::OpenMode_Truncate | Nz::OpenMode_WriteOnly))
{ {
reportFile.Write(oss.str()); // Conversion implicite en NzString reportFile.Write(oss.str()); // Conversion implicite en Nz::String
reportFile.Close(); reportFile.Close();
char accentAigu = static_cast<char>(130); // C'est crade, mais ça marche chez 95% des Windowsiens char accentAigu = static_cast<char>(130); // C'est crade, mais ça marche chez 95% des Windowsiens
std::cout << "Un fichier (RapportHardwareInfo.txt) contenant le rapport a " << accentAigu << 't' << accentAigu << " cr" << accentAigu << accentAigu << std::endl; std::cout << "Un fichier (RapportNz::HardwareInfo.txt) contenant le rapport a " << accentAigu << 't' << accentAigu << " cr" << accentAigu << accentAigu << std::endl;
} }
else else
std::cout << "Impossible de sauvegarder le rapport" << std::endl; std::cout << "Impossible de sauvegarder le rapport" << std::endl;
@ -111,7 +111,7 @@ int main()
return 0; return 0;
} }
void printCap(std::ostream& o, const NzString& cap, bool b) void printCap(std::ostream& o, const Nz::String& cap, bool b)
{ {
if (b) if (b)
o << cap << ": Oui" << std::endl; o << cap << ": Oui" << std::endl;

View File

@ -11,7 +11,7 @@
int main() int main()
{ {
// Pour charger des ressources, il est impératif d'initialiser le module utilitaire // Pour charger des ressources, il est impératif d'initialiser le module utilitaire
NzInitializer<NzUtility> utility; Initializer<Utility> utility;
if (!utility) if (!utility)
{ {
// Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log
@ -22,7 +22,7 @@ int main()
for (;;) for (;;)
{ {
NzDirectory resourceDirectory("resources/"); Directory resourceDirectory("resources/");
if (!resourceDirectory.Open()) if (!resourceDirectory.Open())
{ {
std::cerr << "Failed to open resource directory" << std::endl; std::cerr << "Failed to open resource directory" << std::endl;
@ -30,12 +30,12 @@ int main()
return EXIT_FAILURE; return EXIT_FAILURE;
} }
std::vector<NzString> models; std::vector<String> models;
while (resourceDirectory.NextResult()) while (resourceDirectory.NextResult())
{ {
NzString path = resourceDirectory.GetResultName(); String path = resourceDirectory.GetResultName();
NzString ext = path.SubStringFrom('.', -1, true); // Tout ce qui vient après le dernier '.' de la chaîne String ext = path.SubStringFrom('.', -1, true); // Tout ce qui vient après le dernier '.' de la chaîne
if (NzMeshLoader::IsExtensionSupported(ext)) // L'extension est-elle supportée par le MeshLoader ? if (MeshLoader::IsExtensionSupported(ext)) // L'extension est-elle supportée par le MeshLoader ?
models.push_back(path); models.push_back(path);
} }
@ -67,7 +67,7 @@ int main()
if (iChoice == 0) if (iChoice == 0)
break; break;
NzMesh mesh; Mesh mesh;
if (!mesh.LoadFromFile("resources/" + models[iChoice-1])) if (!mesh.LoadFromFile("resources/" + models[iChoice-1]))
{ {
std::cout << "Failed to load mesh" << std::endl; std::cout << "Failed to load mesh" << std::endl;
@ -77,11 +77,11 @@ int main()
switch (mesh.GetAnimationType()) switch (mesh.GetAnimationType())
{ {
case nzAnimationType_Skeletal: case AnimationType_Skeletal:
std::cout << "This is a skeletal-animated mesh" << std::endl; std::cout << "This is a skeletal-animated mesh" << std::endl;
break; break;
case nzAnimationType_Static: case AnimationType_Static:
std::cout << "This is a static mesh" << std::endl; std::cout << "This is a static mesh" << std::endl;
break; break;
@ -92,9 +92,9 @@ int main()
if (mesh.IsAnimable()) if (mesh.IsAnimable())
{ {
if (mesh.GetAnimationType() == nzAnimationType_Skeletal) if (mesh.GetAnimationType() == AnimationType_Skeletal)
{ {
const NzSkeleton* skeleton = mesh.GetSkeleton(); const Skeleton* skeleton = mesh.GetSkeleton();
unsigned int jointCount = skeleton->GetJointCount(); unsigned int jointCount = skeleton->GetJointCount();
std::cout << "It has a skeleton made of " << skeleton->GetJointCount() << " joint(s)." << std::endl; std::cout << "It has a skeleton made of " << skeleton->GetJointCount() << " joint(s)." << std::endl;
std::cout << "Print joints ? (Y/N) "; std::cout << "Print joints ? (Y/N) ";
@ -107,10 +107,10 @@ int main()
{ {
for (unsigned int i = 0; i < jointCount; ++i) for (unsigned int i = 0; i < jointCount; ++i)
{ {
const NzJoint* joint = skeleton->GetJoint(i); const Joint* joint = skeleton->GetJoint(i);
std::cout << "\t" << (i+1) << ": " << joint->GetName(); std::cout << "\t" << (i+1) << ": " << joint->GetName();
const NzJoint* parent = static_cast<const NzJoint*>(joint->GetParent()); const Joint* parent = static_cast<const Joint*>(joint->GetParent());
if (parent) if (parent)
std::cout << " (Parent: " << parent->GetName() << ')'; std::cout << " (Parent: " << parent->GetName() << ')';
@ -119,10 +119,10 @@ int main()
} }
} }
NzString animationPath = mesh.GetAnimation(); String animationPath = mesh.GetAnimation();
if (!animationPath.IsEmpty()) if (!animationPath.IsEmpty())
{ {
NzAnimation animation; Animation animation;
if (animation.LoadFromFile(animationPath)) if (animation.LoadFromFile(animationPath))
{ {
unsigned int sequenceCount = animation.GetSequenceCount(); unsigned int sequenceCount = animation.GetSequenceCount();
@ -137,7 +137,7 @@ int main()
{ {
for (unsigned int i = 0; i < sequenceCount; ++i) for (unsigned int i = 0; i < sequenceCount; ++i)
{ {
const NzSequence* sequence = animation.GetSequence(i); const Sequence* sequence = animation.GetSequence(i);
std::cout << "\t" << (i+1) << ": " << sequence->name << std::endl; std::cout << "\t" << (i+1) << ": " << sequence->name << std::endl;
std::cout << "\t\tStart frame: " << sequence->firstFrame << std::endl; std::cout << "\t\tStart frame: " << sequence->firstFrame << std::endl;
std::cout << "\t\tFrame count: " << sequence->frameCount << std::endl; std::cout << "\t\tFrame count: " << sequence->frameCount << std::endl;
@ -153,7 +153,7 @@ int main()
std::cout << "It's animable but has no animation information" << std::endl; std::cout << "It's animable but has no animation information" << std::endl;
} }
NzBoxf cube = mesh.GetAABB(); Boxf cube = mesh.GetAABB();
std::cout << "Mesh is " << cube.width << " units wide, " << cube.height << " units height and " << cube.depth << " units depth" << std::endl; std::cout << "Mesh is " << cube.width << " units wide, " << cube.height << " units height and " << cube.depth << " units depth" << std::endl;
unsigned int materialCount = mesh.GetMaterialCount(); unsigned int materialCount = mesh.GetMaterialCount();

View File

@ -9,7 +9,10 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
template<typename T> void NzMixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount); namespace Nz
{
template<typename T> void MixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount);
}
#include <Nazara/Audio/Algorithm.inl> #include <Nazara/Audio/Algorithm.inl>

View File

@ -5,21 +5,24 @@
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Audio/Debug.hpp> #include <Nazara/Audio/Debug.hpp>
template<typename T> namespace Nz
void NzMixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount)
{ {
///DOC: Le buffer d'entrée peut être le même que le buffer de sortie template<typename T>
// Pour éviter l'overflow, on utilise comme accumulateur un type assez grand, (u)int 64 bits pour les entiers, double pour les flottants void MixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount)
typedef typename std::conditional<std::is_unsigned<T>::value, nzUInt64, nzInt64>::type BiggestInt;
typedef typename std::conditional<std::is_integral<T>::value, BiggestInt, double>::type Biggest;
for (unsigned int i = 0; i < frameCount; ++i)
{ {
Biggest acc = Biggest(0); ///DOC: Le buffer d'entrée peut être le même que le buffer de sortie
for (unsigned int j = 0; j < channelCount; ++j) // Pour éviter l'overflow, on utilise comme accumulateur un type assez grand, (u)int 64 bits pour les entiers, double pour les flottants
acc += input[i*channelCount + j]; typedef typename std::conditional<std::is_unsigned<T>::value, UInt64, Int64>::type BiggestInt;
typedef typename std::conditional<std::is_integral<T>::value, BiggestInt, double>::type Biggest;
output[i] = static_cast<T>(acc/channelCount); for (unsigned int i = 0; i < frameCount; ++i)
{
Biggest acc = Biggest(0);
for (unsigned int j = 0; j < channelCount; ++j)
acc += input[i*channelCount + j];
output[i] = static_cast<T>(acc / channelCount);
}
} }
} }

View File

@ -14,41 +14,44 @@
#include <Nazara/Math/Quaternion.hpp> #include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
class NAZARA_AUDIO_API NzAudio namespace Nz
{ {
public: class NAZARA_AUDIO_API Audio
NzAudio() = delete; {
~NzAudio() = delete; public:
Audio() = delete;
~Audio() = delete;
static nzAudioFormat GetAudioFormat(unsigned int channelCount); static AudioFormat GetAudioFormat(unsigned int channelCount);
static float GetDopplerFactor(); static float GetDopplerFactor();
static float GetGlobalVolume(); static float GetGlobalVolume();
static NzVector3f GetListenerDirection(); static Vector3f GetListenerDirection();
static NzVector3f GetListenerPosition(); static Vector3f GetListenerPosition();
static NzQuaternionf GetListenerRotation(); static Quaternionf GetListenerRotation();
static NzVector3f GetListenerVelocity(); static Vector3f GetListenerVelocity();
static float GetSpeedOfSound(); static float GetSpeedOfSound();
static bool Initialize(); static bool Initialize();
static bool IsFormatSupported(nzAudioFormat format); static bool IsFormatSupported(AudioFormat format);
static bool IsInitialized(); static bool IsInitialized();
static void SetDopplerFactor(float dopplerFactor); static void SetDopplerFactor(float dopplerFactor);
static void SetGlobalVolume(float volume); static void SetGlobalVolume(float volume);
static void SetListenerDirection(const NzVector3f& direction); static void SetListenerDirection(const Vector3f& direction);
static void SetListenerDirection(float dirX, float dirY, float dirZ); static void SetListenerDirection(float dirX, float dirY, float dirZ);
static void SetListenerPosition(const NzVector3f& position); static void SetListenerPosition(const Vector3f& position);
static void SetListenerPosition(float x, float y, float z); static void SetListenerPosition(float x, float y, float z);
static void SetListenerRotation(const NzQuaternionf& rotation); static void SetListenerRotation(const Quaternionf& rotation);
static void SetListenerVelocity(const NzVector3f& velocity); static void SetListenerVelocity(const Vector3f& velocity);
static void SetListenerVelocity(float velX, float velY, float velZ); static void SetListenerVelocity(float velX, float velY, float velZ);
static void SetSpeedOfSound(float speed); static void SetSpeedOfSound(float speed);
static void Uninitialize(); static void Uninitialize();
private: private:
static unsigned int s_moduleReferenceCounter; static unsigned int s_moduleReferenceCounter;
}; };
}
#endif // NAZARA_AUDIO_HPP #endif // NAZARA_AUDIO_HPP

View File

@ -7,26 +7,30 @@
#ifndef NAZARA_ENUMS_HPP #ifndef NAZARA_ENUMS_HPP
#define NAZARA_ENUMS_HPP #define NAZARA_ENUMS_HPP
enum nzAudioFormat namespace Nz
{ {
nzAudioFormat_Unknown = -1,
// La valeur entière est le nombre de canaux possédés par ce format enum AudioFormat
nzAudioFormat_Mono = 1, {
nzAudioFormat_Stereo = 2, AudioFormat_Unknown = -1,
nzAudioFormat_Quad = 4,
nzAudioFormat_5_1 = 6,
nzAudioFormat_6_1 = 7,
nzAudioFormat_7_1 = 8,
nzAudioFormat_Max = nzAudioFormat_7_1 // La valeur entière est le nombre de canaux possédés par ce format
}; AudioFormat_Mono = 1,
AudioFormat_Stereo = 2,
AudioFormat_Quad = 4,
AudioFormat_5_1 = 6,
AudioFormat_6_1 = 7,
AudioFormat_7_1 = 8,
enum nzSoundStatus AudioFormat_Max = AudioFormat_7_1
{ };
nzSoundStatus_Playing,
nzSoundStatus_Paused, enum SoundStatus
nzSoundStatus_Stopped {
}; SoundStatus_Playing,
SoundStatus_Paused,
SoundStatus_Stopped
};
}
#endif // NAZARA_ENUMS_HPP #endif // NAZARA_ENUMS_HPP

View File

@ -13,60 +13,68 @@
#include <Nazara/Core/Resource.hpp> #include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp> #include <Nazara/Core/ResourceLoader.hpp>
struct NzMusicParams namespace Nz
{ {
bool forceMono = false; struct MusicParams
{
bool forceMono = false;
bool IsValid() const; bool IsValid() const;
}; };
class NzMusic; class Music;
class NzSoundStream; class SoundStream;
using NzMusicLoader = NzResourceLoader<NzMusic, NzMusicParams>; using MusicLoader = ResourceLoader<Music, MusicParams>;
struct NzMusicImpl; struct MusicImpl;
class NAZARA_AUDIO_API NzMusic : public NzResource, public NzSoundEmitter, NzNonCopyable class NAZARA_AUDIO_API Music : public Resource, public SoundEmitter
{ {
friend NzMusicLoader; friend MusicLoader;
public: public:
NzMusic() = default; Music() = default;
~NzMusic(); Music(const Music&) = delete;
Music(Music&&) = delete; ///TODO
~Music();
bool Create(NzSoundStream* soundStream); bool Create(SoundStream* soundStream);
void Destroy(); void Destroy();
void EnableLooping(bool loop); void EnableLooping(bool loop);
nzUInt32 GetDuration() const; UInt32 GetDuration() const;
nzAudioFormat GetFormat() const; AudioFormat GetFormat() const;
nzUInt32 GetPlayingOffset() const; UInt32 GetPlayingOffset() const;
unsigned int GetSampleCount() const; UInt32 GetSampleCount() const;
unsigned int GetSampleRate() const; UInt32 GetSampleRate() const;
nzSoundStatus GetStatus() const; SoundStatus GetStatus() const;
bool IsLooping() const; bool IsLooping() const;
bool OpenFromFile(const NzString& filePath, const NzMusicParams& params = NzMusicParams()); bool OpenFromFile(const String& filePath, const MusicParams& params = MusicParams());
bool OpenFromMemory(const void* data, std::size_t size, const NzMusicParams& params = NzMusicParams()); bool OpenFromMemory(const void* data, std::size_t size, const MusicParams& params = MusicParams());
bool OpenFromStream(NzInputStream& stream, const NzMusicParams& params = NzMusicParams()); bool OpenFromStream(InputStream& stream, const MusicParams& params = MusicParams());
void Pause(); void Pause();
void Play(); void Play();
void SetPlayingOffset(nzUInt32 offset); void SetPlayingOffset(UInt32 offset);
void Stop(); void Stop();
private: Music& operator=(const Music&) = delete;
NzMusicImpl* m_impl = nullptr; Music& operator=(Music&&) = delete; ///TODO
bool FillAndQueueBuffer(unsigned int buffer); private:
void MusicThread(); MusicImpl* m_impl = nullptr;
static NzMusicLoader::LoaderList s_loaders; bool FillAndQueueBuffer(unsigned int buffer);
}; void MusicThread();
static MusicLoader::LoaderList s_loaders;
};
}
#endif // NAZARA_MUSIC_HPP #endif // NAZARA_MUSIC_HPP

View File

@ -20,168 +20,171 @@
// Étant donné que les headers OpenAL ne nous permettent pas de n'avoir que les signatures sans les pointeurs de fonctions // Étant donné que les headers OpenAL ne nous permettent pas de n'avoir que les signatures sans les pointeurs de fonctions
// Et que je ne souhaite pas les modifier, je suis contraint de les placer dans un espace de nom différent pour ensuite // Et que je ne souhaite pas les modifier, je suis contraint de les placer dans un espace de nom différent pour ensuite
// remettre dans l'espace global les choses intéressantes (les typedef notamment) // remettre dans l'espace global les choses intéressantes (les typedef notamment)
namespace NzOpenALDetail namespace OpenALDetail
{ {
#include <AL/al.h> #include <AL/al.h>
#include <AL/alc.h> #include <AL/alc.h>
} }
// Si quelqu'un a une meilleure idée ... // Si quelqu'un a une meilleure idée ...
using NzOpenALDetail::ALboolean; using OpenALDetail::ALboolean;
using NzOpenALDetail::ALbyte; using OpenALDetail::ALbyte;
using NzOpenALDetail::ALchar; using OpenALDetail::ALchar;
using NzOpenALDetail::ALdouble; using OpenALDetail::ALdouble;
using NzOpenALDetail::ALenum; using OpenALDetail::ALenum;
using NzOpenALDetail::ALfloat; using OpenALDetail::ALfloat;
using NzOpenALDetail::ALint; using OpenALDetail::ALint;
using NzOpenALDetail::ALshort; using OpenALDetail::ALshort;
using NzOpenALDetail::ALsizei; using OpenALDetail::ALsizei;
using NzOpenALDetail::ALubyte; using OpenALDetail::ALubyte;
using NzOpenALDetail::ALuint; using OpenALDetail::ALuint;
using NzOpenALDetail::ALushort; using OpenALDetail::ALushort;
using NzOpenALDetail::ALvoid; using OpenALDetail::ALvoid;
using NzOpenALDetail::ALCboolean; using OpenALDetail::ALCboolean;
using NzOpenALDetail::ALCbyte; using OpenALDetail::ALCbyte;
using NzOpenALDetail::ALCchar; using OpenALDetail::ALCchar;
using NzOpenALDetail::ALCcontext; using OpenALDetail::ALCcontext;
using NzOpenALDetail::ALCdevice; using OpenALDetail::ALCdevice;
using NzOpenALDetail::ALCdouble; using OpenALDetail::ALCdouble;
using NzOpenALDetail::ALCenum; using OpenALDetail::ALCenum;
using NzOpenALDetail::ALCfloat; using OpenALDetail::ALCfloat;
using NzOpenALDetail::ALCint; using OpenALDetail::ALCint;
using NzOpenALDetail::ALCshort; using OpenALDetail::ALCshort;
using NzOpenALDetail::ALCsizei; using OpenALDetail::ALCsizei;
using NzOpenALDetail::ALCubyte; using OpenALDetail::ALCubyte;
using NzOpenALDetail::ALCuint; using OpenALDetail::ALCuint;
using NzOpenALDetail::ALCushort; using OpenALDetail::ALCushort;
using NzOpenALDetail::ALCvoid; using OpenALDetail::ALCvoid;
using NzOpenALFunc = void (*)(); namespace Nz
class NAZARA_AUDIO_API NzOpenAL
{ {
public: using OpenALFunc = void(*)();
static NzOpenALFunc GetEntry(const NzString& entryPoint);
static NzString GetRendererName();
static NzString GetVendorName();
static unsigned int GetVersion();
static bool Initialize(bool openDevice = true); class NAZARA_AUDIO_API OpenAL
{
public:
static OpenALFunc GetEntry(const String& entryPoint);
static String GetRendererName();
static String GetVendorName();
static unsigned int GetVersion();
static bool IsInitialized(); static bool Initialize(bool openDevice = true);
static unsigned int QueryInputDevices(std::vector<NzString>& devices); static bool IsInitialized();
static unsigned int QueryOutputDevices(std::vector<NzString>& devices);
static bool SetDevice(const NzString& deviceName); static unsigned int QueryInputDevices(std::vector<String>& devices);
static unsigned int QueryOutputDevices(std::vector<String>& devices);
static void Uninitialize(); static bool SetDevice(const String& deviceName);
static ALenum AudioFormat[nzAudioFormat_Max+1]; static void Uninitialize();
private: static ALenum AudioFormat[AudioFormat_Max + 1];
static void CloseDevice();
static bool OpenDevice(); private:
static NzOpenALFunc LoadEntry(const char* name, bool throwException = false); static void CloseDevice();
}; static bool OpenDevice();
static OpenALFunc LoadEntry(const char* name, bool throwException = false);
};
}
// al // al
NAZARA_AUDIO_API extern NzOpenALDetail::LPALBUFFER3F alBuffer3f; NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFER3F alBuffer3f;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALBUFFER3I alBuffer3i; NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFER3I alBuffer3i;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALBUFFERDATA alBufferData; NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERDATA alBufferData;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALBUFFERF alBufferf; NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERF alBufferf;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALBUFFERFV alBufferfv; NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERFV alBufferfv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALBUFFERI alBufferi; NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERI alBufferi;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALBUFFERIV alBufferiv; NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERIV alBufferiv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALDELETEBUFFERS alDeleteBuffers; NAZARA_AUDIO_API extern OpenALDetail::LPALDELETEBUFFERS alDeleteBuffers;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALDELETESOURCES alDeleteSources; NAZARA_AUDIO_API extern OpenALDetail::LPALDELETESOURCES alDeleteSources;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALDISABLE alDisable; NAZARA_AUDIO_API extern OpenALDetail::LPALDISABLE alDisable;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALDISTANCEMODEL alDistanceModel; NAZARA_AUDIO_API extern OpenALDetail::LPALDISTANCEMODEL alDistanceModel;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALDOPPLERFACTOR alDopplerFactor; NAZARA_AUDIO_API extern OpenALDetail::LPALDOPPLERFACTOR alDopplerFactor;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALDOPPLERVELOCITY alDopplerVelocity; NAZARA_AUDIO_API extern OpenALDetail::LPALDOPPLERVELOCITY alDopplerVelocity;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALENABLE alEnable; NAZARA_AUDIO_API extern OpenALDetail::LPALENABLE alEnable;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGENBUFFERS alGenBuffers; NAZARA_AUDIO_API extern OpenALDetail::LPALGENBUFFERS alGenBuffers;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGENSOURCES alGenSources; NAZARA_AUDIO_API extern OpenALDetail::LPALGENSOURCES alGenSources;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETBOOLEAN alGetBoolean; NAZARA_AUDIO_API extern OpenALDetail::LPALGETBOOLEAN alGetBoolean;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETBOOLEANV alGetBooleanv; NAZARA_AUDIO_API extern OpenALDetail::LPALGETBOOLEANV alGetBooleanv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETBUFFER3F alGetBuffer3f; NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFER3F alGetBuffer3f;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETBUFFER3I alGetBuffer3i; NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFER3I alGetBuffer3i;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETBUFFERF alGetBufferf; NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFERF alGetBufferf;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETBUFFERFV alGetBufferfv; NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFERFV alGetBufferfv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETBUFFERI alGetBufferi; NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFERI alGetBufferi;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETBUFFERIV alGetBufferiv; NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFERIV alGetBufferiv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETDOUBLE alGetDouble; NAZARA_AUDIO_API extern OpenALDetail::LPALGETDOUBLE alGetDouble;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETDOUBLEV alGetDoublev; NAZARA_AUDIO_API extern OpenALDetail::LPALGETDOUBLEV alGetDoublev;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETENUMVALUE alGetEnumValue; NAZARA_AUDIO_API extern OpenALDetail::LPALGETENUMVALUE alGetEnumValue;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETERROR alGetError; NAZARA_AUDIO_API extern OpenALDetail::LPALGETERROR alGetError;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETFLOAT alGetFloat; NAZARA_AUDIO_API extern OpenALDetail::LPALGETFLOAT alGetFloat;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETFLOATV alGetFloatv; NAZARA_AUDIO_API extern OpenALDetail::LPALGETFLOATV alGetFloatv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETINTEGER alGetInteger; NAZARA_AUDIO_API extern OpenALDetail::LPALGETINTEGER alGetInteger;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETINTEGERV alGetIntegerv; NAZARA_AUDIO_API extern OpenALDetail::LPALGETINTEGERV alGetIntegerv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETLISTENER3F alGetListener3f; NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENER3F alGetListener3f;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETLISTENER3I alGetListener3i; NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENER3I alGetListener3i;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETLISTENERF alGetListenerf; NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENERF alGetListenerf;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETLISTENERFV alGetListenerfv; NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENERFV alGetListenerfv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETLISTENERI alGetListeneri; NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENERI alGetListeneri;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETLISTENERIV alGetListeneriv; NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENERIV alGetListeneriv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETPROCADDRESS alGetProcAddress; NAZARA_AUDIO_API extern OpenALDetail::LPALGETPROCADDRESS alGetProcAddress;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETSOURCE3F alGetSource3f; NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCE3F alGetSource3f;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETSOURCE3I alGetSource3i; NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCE3I alGetSource3i;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETSOURCEF alGetSourcef; NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCEF alGetSourcef;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETSOURCEFV alGetSourcefv; NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCEFV alGetSourcefv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETSOURCEI alGetSourcei; NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCEI alGetSourcei;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETSOURCEIV alGetSourceiv; NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCEIV alGetSourceiv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALGETSTRING alGetString; NAZARA_AUDIO_API extern OpenALDetail::LPALGETSTRING alGetString;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALISBUFFER alIsBuffer; NAZARA_AUDIO_API extern OpenALDetail::LPALISBUFFER alIsBuffer;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALISENABLED alIsEnabled; NAZARA_AUDIO_API extern OpenALDetail::LPALISENABLED alIsEnabled;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALISEXTENSIONPRESENT alIsExtensionPresent; NAZARA_AUDIO_API extern OpenALDetail::LPALISEXTENSIONPRESENT alIsExtensionPresent;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALISSOURCE alIsSource; NAZARA_AUDIO_API extern OpenALDetail::LPALISSOURCE alIsSource;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALLISTENER3F alListener3f; NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENER3F alListener3f;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALLISTENER3I alListener3i; NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENER3I alListener3i;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALLISTENERF alListenerf; NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENERF alListenerf;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALLISTENERFV alListenerfv; NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENERFV alListenerfv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALLISTENERI alListeneri; NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENERI alListeneri;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALLISTENERIV alListeneriv; NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENERIV alListeneriv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCE3F alSource3f; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCE3F alSource3f;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCE3I alSource3i; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCE3I alSource3i;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEF alSourcef; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEF alSourcef;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEFV alSourcefv; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEFV alSourcefv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEI alSourcei; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEI alSourcei;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEIV alSourceiv; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEIV alSourceiv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEPAUSE alSourcePause; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEPAUSE alSourcePause;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEPAUSEV alSourcePausev; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEPAUSEV alSourcePausev;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEPLAY alSourcePlay; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEPLAY alSourcePlay;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEPLAYV alSourcePlayv; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEPLAYV alSourcePlayv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEQUEUEBUFFERS alSourceQueueBuffers; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEQUEUEBUFFERS alSourceQueueBuffers;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEREWIND alSourceRewind; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEREWIND alSourceRewind;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEREWINDV alSourceRewindv; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEREWINDV alSourceRewindv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCESTOP alSourceStop; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCESTOP alSourceStop;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCESTOPV alSourceStopv; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCESTOPV alSourceStopv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSOURCEUNQUEUEBUFFERS alSourceUnqueueBuffers; NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEUNQUEUEBUFFERS alSourceUnqueueBuffers;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALSPEEDOFSOUND alSpeedOfSound; NAZARA_AUDIO_API extern OpenALDetail::LPALSPEEDOFSOUND alSpeedOfSound;
// alc // alc
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCCAPTURECLOSEDEVICE alcCaptureCloseDevice; NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTURECLOSEDEVICE alcCaptureCloseDevice;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCCAPTUREOPENDEVICE alcCaptureOpenDevice; NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTUREOPENDEVICE alcCaptureOpenDevice;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCCAPTURESAMPLES alcCaptureSamples; NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTURESAMPLES alcCaptureSamples;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCCAPTURESTART alcCaptureStart; NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTURESTART alcCaptureStart;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCCAPTURESTOP alcCaptureStop; NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTURESTOP alcCaptureStop;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCCLOSEDEVICE alcCloseDevice; NAZARA_AUDIO_API extern OpenALDetail::LPALCCLOSEDEVICE alcCloseDevice;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCCREATECONTEXT alcCreateContext; NAZARA_AUDIO_API extern OpenALDetail::LPALCCREATECONTEXT alcCreateContext;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCDESTROYCONTEXT alcDestroyContext; NAZARA_AUDIO_API extern OpenALDetail::LPALCDESTROYCONTEXT alcDestroyContext;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCGETCONTEXTSDEVICE alcGetContextsDevice; NAZARA_AUDIO_API extern OpenALDetail::LPALCGETCONTEXTSDEVICE alcGetContextsDevice;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCGETCURRENTCONTEXT alcGetCurrentContext; NAZARA_AUDIO_API extern OpenALDetail::LPALCGETCURRENTCONTEXT alcGetCurrentContext;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCGETENUMVALUE alcGetEnumValue; NAZARA_AUDIO_API extern OpenALDetail::LPALCGETENUMVALUE alcGetEnumValue;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCGETERROR alcGetError; NAZARA_AUDIO_API extern OpenALDetail::LPALCGETERROR alcGetError;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCGETINTEGERV alcGetIntegerv; NAZARA_AUDIO_API extern OpenALDetail::LPALCGETINTEGERV alcGetIntegerv;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCGETPROCADDRESS alcGetProcAddress; NAZARA_AUDIO_API extern OpenALDetail::LPALCGETPROCADDRESS alcGetProcAddress;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCGETSTRING alcGetString; NAZARA_AUDIO_API extern OpenALDetail::LPALCGETSTRING alcGetString;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCISEXTENSIONPRESENT alcIsExtensionPresent; NAZARA_AUDIO_API extern OpenALDetail::LPALCISEXTENSIONPRESENT alcIsExtensionPresent;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCMAKECONTEXTCURRENT alcMakeContextCurrent; NAZARA_AUDIO_API extern OpenALDetail::LPALCMAKECONTEXTCURRENT alcMakeContextCurrent;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCOPENDEVICE alcOpenDevice; NAZARA_AUDIO_API extern OpenALDetail::LPALCOPENDEVICE alcOpenDevice;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCPROCESSCONTEXT alcProcessContext; NAZARA_AUDIO_API extern OpenALDetail::LPALCPROCESSCONTEXT alcProcessContext;
NAZARA_AUDIO_API extern NzOpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext; NAZARA_AUDIO_API extern OpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext;
#endif // NAZARA_AUDIO_OPENAL #endif // NAZARA_AUDIO_OPENAL

View File

@ -12,39 +12,46 @@
#include <Nazara/Audio/SoundBuffer.hpp> #include <Nazara/Audio/SoundBuffer.hpp>
#include <Nazara/Audio/SoundEmitter.hpp> #include <Nazara/Audio/SoundEmitter.hpp>
class NAZARA_AUDIO_API NzSound : public NzSoundEmitter namespace Nz
{ {
public: class NAZARA_AUDIO_API Sound : public SoundEmitter
NzSound() = default; {
NzSound(const NzSoundBuffer* soundBuffer); public:
NzSound(const NzSound& sound); Sound() = default;
~NzSound(); Sound(const SoundBuffer* soundBuffer);
Sound(const Sound& sound);
Sound(Sound&&) = default;
~Sound();
void EnableLooping(bool loop); void EnableLooping(bool loop);
const NzSoundBuffer* GetBuffer() const; const SoundBuffer* GetBuffer() const;
nzUInt32 GetDuration() const; UInt32 GetDuration() const;
nzUInt32 GetPlayingOffset() const; UInt32 GetPlayingOffset() const;
nzSoundStatus GetStatus() const; SoundStatus GetStatus() const;
bool IsLooping() const; bool IsLooping() const;
bool IsPlayable() const; bool IsPlayable() const;
bool IsPlaying() const; bool IsPlaying() const;
bool LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params = NzSoundBufferParams()); bool LoadFromFile(const String& filePath, const SoundBufferParams& params = SoundBufferParams());
bool LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params = NzSoundBufferParams()); bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
bool LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params = NzSoundBufferParams()); bool LoadFromStream(InputStream& stream, const SoundBufferParams& params = SoundBufferParams());
void Pause(); void Pause();
void Play(); void Play();
void SetBuffer(const NzSoundBuffer* buffer); void SetBuffer(const SoundBuffer* buffer);
void SetPlayingOffset(nzUInt32 offset); void SetPlayingOffset(UInt32 offset);
void Stop(); void Stop();
private: Sound& operator=(const Sound&) = delete; ///TODO?
NzSoundBufferConstRef m_buffer; Sound& operator=(Sound&&) = default;
};
private:
SoundBufferConstRef m_buffer;
};
}
#endif // NAZARA_SOUND_HPP #endif // NAZARA_SOUND_HPP

View File

@ -11,7 +11,6 @@
#include <Nazara/Audio/Config.hpp> #include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp> #include <Nazara/Audio/Enums.hpp>
#include <Nazara/Core/InputStream.hpp> #include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/ObjectRef.hpp> #include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/ObjectLibrary.hpp> #include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/RefCounted.hpp> #include <Nazara/Core/RefCounted.hpp>
@ -20,72 +19,80 @@
#include <Nazara/Core/ResourceManager.hpp> #include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/Signal.hpp> #include <Nazara/Core/Signal.hpp>
struct NzSoundBufferParams namespace Nz
{ {
bool forceMono = false; struct SoundBufferParams
{
bool IsValid() const; bool forceMono = false;
};
class NzSound;
class NzSoundBuffer;
using NzSoundBufferConstRef = NzObjectRef<const NzSoundBuffer>;
using NzSoundBufferLibrary = NzObjectLibrary<NzSoundBuffer>;
using NzSoundBufferLoader = NzResourceLoader<NzSoundBuffer, NzSoundBufferParams>;
using NzSoundBufferManager = NzResourceManager<NzSoundBuffer, NzSoundBufferParams>;
using NzSoundBufferRef = NzObjectRef<NzSoundBuffer>;
struct NzSoundBufferImpl;
class NAZARA_AUDIO_API NzSoundBuffer : public NzRefCounted, public NzResource, NzNonCopyable
{
friend NzSound;
friend NzSoundBufferLibrary;
friend NzSoundBufferLoader;
friend NzSoundBufferManager;
friend class NzAudio;
public:
NzSoundBuffer() = default;
NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples);
~NzSoundBuffer();
bool Create(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples);
void Destroy();
nzUInt32 GetDuration() const;
nzAudioFormat GetFormat() const;
const nzInt16* GetSamples() const;
unsigned int GetSampleCount() const;
unsigned int GetSampleRate() const;
bool IsValid() const; bool IsValid() const;
};
bool LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params = NzSoundBufferParams()); class Sound;
bool LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params = NzSoundBufferParams()); class SoundBuffer;
bool LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params = NzSoundBufferParams());
static bool IsFormatSupported(nzAudioFormat format); using SoundBufferConstRef = ObjectRef<const SoundBuffer>;
template<typename... Args> static NzSoundBufferRef New(Args&&... args); using SoundBufferLibrary = ObjectLibrary<SoundBuffer>;
using SoundBufferLoader = ResourceLoader<SoundBuffer, SoundBufferParams>;
using SoundBufferManager = ResourceManager<SoundBuffer, SoundBufferParams>;
using SoundBufferRef = ObjectRef<SoundBuffer>;
// Signals: struct SoundBufferImpl;
NazaraSignal(OnSoundBufferDestroy, const NzSoundBuffer* /*soundBuffer*/);
NazaraSignal(OnSoundBufferRelease, const NzSoundBuffer* /*soundBuffer*/);
private: class NAZARA_AUDIO_API SoundBuffer : public RefCounted, public Resource
unsigned int GetOpenALBuffer() const; {
friend Sound;
friend SoundBufferLibrary;
friend SoundBufferLoader;
friend SoundBufferManager;
friend class Audio;
static bool Initialize(); public:
static void Uninitialize(); SoundBuffer() = default;
SoundBuffer(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples);
SoundBuffer(const SoundBuffer&) = delete;
SoundBuffer(SoundBuffer&&) = delete;
~SoundBuffer();
NzSoundBufferImpl* m_impl = nullptr; bool Create(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples);
void Destroy();
static NzSoundBufferLibrary::LibraryMap s_library; UInt32 GetDuration() const;
static NzSoundBufferLoader::LoaderList s_loaders; AudioFormat GetFormat() const;
static NzSoundBufferManager::ManagerMap s_managerMap; const Int16* GetSamples() const;
static NzSoundBufferManager::ManagerParams s_managerParameters; UInt32 GetSampleCount() const;
}; UInt32 GetSampleRate() const;
bool IsValid() const;
bool LoadFromFile(const String& filePath, const SoundBufferParams& params = SoundBufferParams());
bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
bool LoadFromStream(InputStream& stream, const SoundBufferParams& params = SoundBufferParams());
static bool IsFormatSupported(AudioFormat format);
template<typename... Args> static SoundBufferRef New(Args&&... args);
SoundBuffer& operator=(const SoundBuffer&) = delete;
SoundBuffer& operator=(SoundBuffer&&) = delete; ///TODO
// Signals:
NazaraSignal(OnSoundBufferDestroy, const SoundBuffer* /*soundBuffer*/);
NazaraSignal(OnSoundBufferRelease, const SoundBuffer* /*soundBuffer*/);
private:
unsigned int GetOpenALBuffer() const;
static bool Initialize();
static void Uninitialize();
SoundBufferImpl* m_impl = nullptr;
static SoundBufferLibrary::LibraryMap s_library;
static SoundBufferLoader::LoaderList s_loaders;
static SoundBufferManager::ManagerMap s_managerMap;
static SoundBufferManager::ManagerParams s_managerParameters;
};
}
#include <Nazara/Audio/SoundBuffer.inl> #include <Nazara/Audio/SoundBuffer.inl>

View File

@ -5,13 +5,16 @@
#include <memory> #include <memory>
#include <Nazara/Audio/Debug.hpp> #include <Nazara/Audio/Debug.hpp>
template<typename... Args> namespace Nz
NzSoundBufferRef NzSoundBuffer::New(Args&&... args)
{ {
std::unique_ptr<NzSoundBuffer> object(new NzSoundBuffer(std::forward<Args>(args)...)); template<typename... Args>
object->SetPersistent(false); SoundBufferRef SoundBuffer::New(Args&&... args)
{
std::unique_ptr<SoundBuffer> object(new SoundBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release(); return object.release();
}
} }
#include <Nazara/Audio/DebugOff.hpp> #include <Nazara/Audio/DebugOff.hpp>

View File

@ -11,53 +11,58 @@
#include <Nazara/Audio/Config.hpp> #include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp> #include <Nazara/Audio/Enums.hpp>
#include <Nazara/Core/InputStream.hpp> #include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
///TODO: Faire hériter SoundEmitter de Node ///TODO: Faire hériter SoundEmitter de Node
class NAZARA_AUDIO_API NzSoundEmitter namespace Nz
{ {
public: class NAZARA_AUDIO_API SoundEmitter
virtual ~NzSoundEmitter(); {
public:
virtual ~SoundEmitter();
virtual void EnableLooping(bool loop) = 0; virtual void EnableLooping(bool loop) = 0;
void EnableSpatialization(bool spatialization); void EnableSpatialization(bool spatialization);
float GetAttenuation() const; float GetAttenuation() const;
virtual nzUInt32 GetDuration() const = 0; virtual UInt32 GetDuration() const = 0;
float GetMinDistance() const; float GetMinDistance() const;
float GetPitch() const; float GetPitch() const;
virtual nzUInt32 GetPlayingOffset() const = 0; virtual UInt32 GetPlayingOffset() const = 0;
NzVector3f GetPosition() const; Vector3f GetPosition() const;
NzVector3f GetVelocity() const; Vector3f GetVelocity() const;
virtual nzSoundStatus GetStatus() const = 0; virtual SoundStatus GetStatus() const = 0;
float GetVolume() const; float GetVolume() const;
virtual bool IsLooping() const = 0; virtual bool IsLooping() const = 0;
bool IsSpatialized() const; bool IsSpatialized() const;
virtual void Pause() = 0; virtual void Pause() = 0;
virtual void Play() = 0; virtual void Play() = 0;
void SetAttenuation(float attenuation); void SetAttenuation(float attenuation);
void SetMinDistance(float minDistance); void SetMinDistance(float minDistance);
void SetPitch(float pitch); void SetPitch(float pitch);
void SetPosition(const NzVector3f& position); void SetPosition(const Vector3f& position);
void SetPosition(float x, float y, float z); void SetPosition(float x, float y, float z);
void SetVelocity(const NzVector3f& velocity); void SetVelocity(const Vector3f& velocity);
void SetVelocity(float velX, float velY, float velZ); void SetVelocity(float velX, float velY, float velZ);
void SetVolume(float volume); void SetVolume(float volume);
virtual void Stop() = 0; virtual void Stop() = 0;
protected: SoundEmitter& operator=(const SoundEmitter&) = delete; ///TODO
NzSoundEmitter(); SoundEmitter& operator=(SoundEmitter&&) = delete; ///TODO
NzSoundEmitter(const NzSoundEmitter& emitter);
nzSoundStatus GetInternalStatus() const; protected:
SoundEmitter();
SoundEmitter(const SoundEmitter& emitter);
SoundEmitter(SoundEmitter&&) = delete; ///TODO
unsigned int m_source; SoundStatus GetInternalStatus() const;
};
unsigned int m_source;
};
}
#endif // NAZARA_SOUNDEMITTER_HPP #endif // NAZARA_SOUNDEMITTER_HPP

View File

@ -11,19 +11,22 @@
#include <Nazara/Audio/Config.hpp> #include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp> #include <Nazara/Audio/Enums.hpp>
class NAZARA_AUDIO_API NzSoundStream namespace Nz
{ {
public: class NAZARA_AUDIO_API SoundStream
NzSoundStream() = default; {
virtual ~NzSoundStream(); public:
SoundStream() = default;
virtual ~SoundStream();
virtual nzUInt32 GetDuration() const = 0; virtual UInt32 GetDuration() const = 0;
virtual nzAudioFormat GetFormat() const = 0; virtual AudioFormat GetFormat() const = 0;
virtual nzUInt64 GetSampleCount() const = 0; virtual UInt32 GetSampleCount() const = 0;
virtual nzUInt32 GetSampleRate() const = 0; virtual UInt32 GetSampleRate() const = 0;
virtual unsigned int Read(void* buffer, unsigned int sampleCount) = 0; virtual unsigned int Read(void* buffer, unsigned int sampleCount) = 0;
virtual void Seek(nzUInt32 offset) = 0; virtual void Seek(UInt32 offset) = 0;
}; };
}
#endif // NAZARA_SOUNDSTREAM_HPP #endif // NAZARA_SOUNDSTREAM_HPP

View File

@ -61,7 +61,6 @@
#include <Nazara/Core/MemoryPool.hpp> #include <Nazara/Core/MemoryPool.hpp>
#include <Nazara/Core/MemoryStream.hpp> #include <Nazara/Core/MemoryStream.hpp>
#include <Nazara/Core/Mutex.hpp> #include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/ObjectLibrary.hpp> #include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp> #include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/OffsetOf.hpp> #include <Nazara/Core/OffsetOf.hpp>

View File

@ -8,19 +8,26 @@
#define NAZARA_ABSTRACTHASH_HPP #define NAZARA_ABSTRACTHASH_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
class NzHashDigest; namespace Nz
class NAZARA_CORE_API NzAbstractHash : NzNonCopyable
{ {
public: class HashDigest;
NzAbstractHash() = default;
virtual ~NzAbstractHash();
virtual void Append(const nzUInt8* data, unsigned int len) = 0; class NAZARA_CORE_API AbstractHash
virtual void Begin() = 0; {
virtual NzHashDigest End() = 0; public:
}; AbstractHash() = default;
AbstractHash(const AbstractHash&) = delete;
AbstractHash(AbstractHash&&) = default;
virtual ~AbstractHash();
virtual void Append(const UInt8* data, unsigned int len) = 0;
virtual void Begin() = 0;
virtual HashDigest End() = 0;
AbstractHash& operator=(const AbstractHash&) = delete;
AbstractHash& operator=(AbstractHash&&) = default;
};
}
#endif // NAZARA_ABSTRACTHASH_HPP #endif // NAZARA_ABSTRACTHASH_HPP

View File

@ -11,12 +11,15 @@
#include <functional> #include <functional>
#include <tuple> #include <tuple>
template<typename F, typename Tuple> auto NzApply(F&& fn, Tuple&& t); namespace Nz
template<typename O, typename F, typename Tuple> auto NzApply(O& object, F&& fn, Tuple&& t); {
template<typename T> void NzHashCombine(std::size_t& seed, const T& v); template<typename F, typename Tuple> auto Apply(F&& fn, Tuple&& t);
template<typename O, typename F, typename Tuple> auto Apply(O& object, F&& fn, Tuple&& t);
template<typename T> void HashCombine(std::size_t& seed, const T& v);
template<typename T> template<typename T>
struct NzTypeTag {}; struct TypeTag {};
}
#include <Nazara/Core/Algorithm.inl> #include <Nazara/Core/Algorithm.inl>

View File

@ -8,49 +8,55 @@
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
// http://www.cppsamples.com/common-tasks/apply-tuple-to-function.html namespace Nz
template<typename F, typename Tuple, size_t... S>
auto NzApplyImplFunc(F&& fn, Tuple&& t, std::index_sequence<S...>)
{ {
return std::forward<F>(fn)(std::get<S>(std::forward<Tuple>(t))...); namespace Detail
} {
// http://www.cppsamples.com/common-tasks/apply-tuple-to-function.html
template<typename F, typename Tuple, size_t... S>
auto ApplyImplFunc(F&& fn, Tuple&& t, std::index_sequence<S...>)
{
return std::forward<F>(fn)(std::get<S>(std::forward<Tuple>(t))...);
}
template<typename F, typename Tuple> template<typename O, typename F, typename Tuple, size_t... S>
auto NzApply(F&& fn, Tuple&& t) auto ApplyImplMethod(O& object, F&& fn, Tuple&& t, std::index_sequence<S...>)
{ {
constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value; return (object .* std::forward<F>(fn))(std::get<S>(std::forward<Tuple>(t))...);
}
}
return NzApplyImplFunc(std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>()); template<typename F, typename Tuple>
} auto Apply(F&& fn, Tuple&& t)
{
constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value;
template<typename O, typename F, typename Tuple, size_t... S> return Detail::ApplyImplFunc(std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
auto NzApplyImplMethod(O& object, F&& fn, Tuple&& t, std::index_sequence<S...>) }
{
return (object .* std::forward<F>(fn))(std::get<S>(std::forward<Tuple>(t))...);
}
template<typename O, typename F, typename Tuple> template<typename O, typename F, typename Tuple>
auto NzApply(O& object, F&& fn, Tuple&& t) auto Apply(O& object, F&& fn, Tuple&& t)
{ {
constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value; constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value;
return NzApplyImplMethod(object, std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>()); return Detail::ApplyImplMethod(object, std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
} }
// Algorithme venant de CityHash par Google // Algorithme venant de CityHash par Google
// http://stackoverflow.com/questions/8513911/how-to-create-a-good-hash-combine-with-64-bit-output-inspired-by-boosthash-co // http://stackoverflow.com/questions/8513911/how-to-create-a-good-hash-combine-with-64-bit-output-inspired-by-boosthash-co
template<typename T> template<typename T>
void NzHashCombine(std::size_t& seed, const T& v) void HashCombine(std::size_t& seed, const T& v)
{ {
const nzUInt64 kMul = 0x9ddfea08eb382d69ULL; const UInt64 kMul = 0x9ddfea08eb382d69ULL;
std::hash<T> hasher; std::hash<T> hasher;
nzUInt64 a = (hasher(v) ^ seed) * kMul; UInt64 a = (hasher(v) ^ seed) * kMul;
a ^= (a >> 47); a ^= (a >> 47);
nzUInt64 b = (seed ^ a) * kMul; UInt64 b = (seed ^ a) * kMul;
b ^= (b >> 47); b ^= (b >> 47);
seed = static_cast<std::size_t>(b * kMul); seed = static_cast<std::size_t>(b * kMul);
}
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

View File

@ -12,165 +12,168 @@
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
class NzAbstractHash; namespace Nz
template<typename Block = nzUInt32, class Allocator = std::allocator<Block>>
class NzBitset
{ {
static_assert(std::is_integral<Block>::value && std::is_unsigned<Block>::value, "Block must be a unsigned integral type"); class AbstractHash;
public: template<typename Block = UInt32, class Allocator = std::allocator<Block>>
class Bit; class Bitset
{
static_assert(std::is_integral<Block>::value && std::is_unsigned<Block>::value, "Block must be a unsigned integral type");
NzBitset(); public:
explicit NzBitset(unsigned int bitCount, bool val = false); class Bit;
explicit NzBitset(const char* bits);
NzBitset(const char* bits, unsigned int bitCount);
NzBitset(const NzBitset& bitset) = default;
explicit NzBitset(const NzString& bits);
NzBitset(NzBitset&& bitset) noexcept = default;
~NzBitset() = default;
void Clear(); Bitset();
unsigned int Count() const; explicit Bitset(unsigned int bitCount, bool val = false);
void Flip(); explicit Bitset(const char* bits);
Bitset(const char* bits, unsigned int bitCount);
Bitset(const Bitset& bitset) = default;
explicit Bitset(const String& bits);
Bitset(Bitset&& bitset) noexcept = default;
~Bitset() = default;
unsigned int FindFirst() const; void Clear();
unsigned int FindNext(unsigned int bit) const; unsigned int Count() const;
void Flip();
Block GetBlock(unsigned int i) const; unsigned int FindFirst() const;
unsigned int GetBlockCount() const; unsigned int FindNext(unsigned int bit) const;
unsigned int GetCapacity() const;
unsigned int GetSize() const;
void PerformsAND(const NzBitset& a, const NzBitset& b); Block GetBlock(unsigned int i) const;
void PerformsNOT(const NzBitset& a); unsigned int GetBlockCount() const;
void PerformsOR(const NzBitset& a, const NzBitset& b); unsigned int GetCapacity() const;
void PerformsXOR(const NzBitset& a, const NzBitset& b); unsigned int GetSize() const;
bool Intersects(const NzBitset& bitset) const; void PerformsAND(const Bitset& a, const Bitset& b);
void PerformsNOT(const Bitset& a);
void PerformsOR(const Bitset& a, const Bitset& b);
void PerformsXOR(const Bitset& a, const Bitset& b);
void Reserve(unsigned int bitCount); bool Intersects(const Bitset& bitset) const;
void Resize(unsigned int bitCount, bool defaultVal = false);
void Reset(); void Reserve(unsigned int bitCount);
void Reset(unsigned int bit); void Resize(unsigned int bitCount, bool defaultVal = false);
void Set(bool val = true); void Reset();
void Set(unsigned int bit, bool val = true); void Reset(unsigned int bit);
void SetBlock(unsigned int i, Block block);
void Swap(NzBitset& bitset); void Set(bool val = true);
void Set(unsigned int bit, bool val = true);
void SetBlock(unsigned int i, Block block);
bool Test(unsigned int bit) const; void Swap(Bitset& bitset);
bool TestAll() const;
bool TestAny() const;
bool TestNone() const;
template<typename T> T To() const; bool Test(unsigned int bit) const;
NzString ToString() const; bool TestAll() const;
bool TestAny() const;
bool TestNone() const;
void UnboundedReset(unsigned int bit); template<typename T> T To() const;
void UnboundedSet(unsigned int bit, bool val = true); String ToString() const;
bool UnboundedTest(unsigned int bit) const;
Bit operator[](int index); void UnboundedReset(unsigned int bit);
bool operator[](int index) const; void UnboundedSet(unsigned int bit, bool val = true);
bool UnboundedTest(unsigned int bit) const;
NzBitset operator~() const; Bit operator[](int index);
bool operator[](int index) const;
NzBitset& operator=(const NzBitset& bitset) = default; Bitset operator~() const;
NzBitset& operator=(const NzString& bits);
NzBitset& operator=(NzBitset&& bitset) noexcept = default;
NzBitset& operator&=(const NzBitset& bitset); Bitset& operator=(const Bitset& bitset) = default;
NzBitset& operator|=(const NzBitset& bitset); Bitset& operator=(const String& bits);
NzBitset& operator^=(const NzBitset& bitset); Bitset& operator=(Bitset&& bitset) noexcept = default;
static Block fullBitMask; Bitset& operator&=(const Bitset& bitset);
static unsigned int bitsPerBlock; Bitset& operator|=(const Bitset& bitset);
static unsigned int npos; Bitset& operator^=(const Bitset& bitset);
private: static Block fullBitMask;
unsigned int FindFirstFrom(unsigned int blockIndex) const; static unsigned int bitsPerBlock;
Block GetLastBlockMask() const; static unsigned int npos;
void ResetExtraBits();
static unsigned int ComputeBlockCount(unsigned int bitCount); private:
static unsigned int GetBitIndex(unsigned int bit); unsigned int FindFirstFrom(unsigned int blockIndex) const;
static unsigned int GetBlockIndex(unsigned int bit); Block GetLastBlockMask() const;
void ResetExtraBits();
std::vector<Block, Allocator> m_blocks; static unsigned int ComputeBlockCount(unsigned int bitCount);
unsigned int m_bitCount; static unsigned int GetBitIndex(unsigned int bit);
}; static unsigned int GetBlockIndex(unsigned int bit);
template<typename Block, class Allocator> std::vector<Block, Allocator> m_blocks;
bool operator==(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs); unsigned int m_bitCount;
};
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool operator!=(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs); class Bitset<Block, Allocator>::Bit
{
friend Bitset<Block, Allocator>;
template<typename Block, class Allocator> public:
bool operator<(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs); Bit(const Bit& bit) = default;
template<typename Block, class Allocator> Bit& Flip();
bool operator<=(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs); Bit& Reset();
Bit& Set(bool val = true);
bool Test() const;
template<typename Block, class Allocator> template<bool BadCall = true>
bool operator>(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs); void* operator&() const;
template<typename Block, class Allocator> operator bool() const;
bool operator>=(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs); Bit& operator=(bool val);
Bit& operator=(const Bit& bit);
template<typename Block, class Allocator> Bit& operator|=(bool val);
NzBitset<Block, Allocator> operator&(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs); Bit& operator&=(bool val);
Bit& operator^=(bool val);
Bit& operator-=(bool val);
template<typename Block, class Allocator> private:
NzBitset<Block, Allocator> operator|(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs); Bit(Block& block, Block mask) :
m_block(block),
m_mask(mask)
{
}
template<typename Block, class Allocator> Block& m_block;
NzBitset<Block, Allocator> operator^(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs); Block m_mask;
};
template<typename Block, class Allocator> template<typename Block, class Allocator>
class NzBitset<Block, Allocator>::Bit bool operator==(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
{
friend NzBitset<Block, Allocator>;
public: template<typename Block, class Allocator>
Bit(const Bit& bit) = default; bool operator!=(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
Bit& Flip(); template<typename Block, class Allocator>
Bit& Reset(); bool operator<(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
Bit& Set(bool val = true);
bool Test() const;
template<bool BadCall = true> template<typename Block, class Allocator>
void* operator&() const; bool operator<=(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
operator bool() const; template<typename Block, class Allocator>
Bit& operator=(bool val); bool operator>(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
Bit& operator=(const Bit& bit);
Bit& operator|=(bool val); template<typename Block, class Allocator>
Bit& operator&=(bool val); bool operator>=(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
Bit& operator^=(bool val);
Bit& operator-=(bool val);
private: template<typename Block, class Allocator>
Bit(Block& block, Block mask) : Bitset<Block, Allocator> operator&(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs);
m_block(block),
m_mask(mask)
{
}
Block& m_block; template<typename Block, class Allocator>
Block m_mask; Bitset<Block, Allocator> operator|(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs);
};
template<typename Block, class Allocator>
Bitset<Block, Allocator> operator^(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs);
}
namespace std namespace std
{ {
template<typename Block, class Allocator> template<typename Block, class Allocator>
void swap(NzBitset<Block, Allocator>& lhs, NzBitset<Block, Allocator>& rhs); void swap(Nz::Bitset<Block, Allocator>& lhs, Nz::Bitset<Block, Allocator>& rhs);
} }
#include <Nazara/Core/Bitset.inl> #include <Nazara/Core/Bitset.inl>

File diff suppressed because it is too large Load Diff

View File

@ -13,125 +13,128 @@
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <vector> #include <vector>
class NzAbstractHash; namespace Nz
class NAZARA_CORE_API NzByteArray : public NzHashable
{ {
using Container = std::vector<nzUInt8>; class AbstractHash;
public: class NAZARA_CORE_API ByteArray : public Hashable
// types: {
using allocator_type = Container::allocator_type; using Container = std::vector<UInt8>;
using const_iterator = Container::const_iterator;
using const_reference = Container::const_reference;
using const_pointer = Container::const_pointer;
using const_reverse_iterator = Container::const_reverse_iterator;
using difference_type = Container::difference_type;
using pointer = Container::pointer;
using iterator = Container::iterator;
using reference = Container::reference;
using reverse_iterator = Container::reverse_iterator;
using size_type = Container::size_type;
using value_type = Container::value_type;
// construct/destroy: public:
inline NzByteArray() = default; // types:
inline explicit NzByteArray(size_type n); using allocator_type = Container::allocator_type;
inline NzByteArray(const void* buffer, size_type n); using const_iterator = Container::const_iterator;
inline NzByteArray(size_type n, value_type value); using const_reference = Container::const_reference;
template <class InputIterator> NzByteArray(InputIterator first, InputIterator last); using const_pointer = Container::const_pointer;
NzByteArray(const NzByteArray& other) = default; using const_reverse_iterator = Container::const_reverse_iterator;
NzByteArray(NzByteArray&& other) = default; using difference_type = Container::difference_type;
~NzByteArray() = default; using pointer = Container::pointer;
using iterator = Container::iterator;
using reference = Container::reference;
using reverse_iterator = Container::reverse_iterator;
using size_type = Container::size_type;
using value_type = Container::value_type;
inline iterator Append(const void* buffer, size_type size); // construct/destroy:
inline iterator Append(const NzByteArray& other); inline ByteArray() = default;
template <class InputIterator> void Assign(InputIterator first, InputIterator last); inline explicit ByteArray(size_type n);
inline void Assign(size_type n, value_type value); inline ByteArray(const void* buffer, size_type n);
inline ByteArray(size_type n, value_type value);
template <class InputIterator> ByteArray(InputIterator first, InputIterator last);
ByteArray(const ByteArray& other) = default;
ByteArray(ByteArray&& other) = default;
~ByteArray() = default;
inline reference Back(); inline iterator Append(const void* buffer, size_type size);
inline const_reference Back() const; inline iterator Append(const ByteArray& other);
template <class InputIterator> void Assign(InputIterator first, InputIterator last);
inline void Assign(size_type n, value_type value);
inline void Clear(bool keepBuffer = false); inline reference Back();
inline const_reference Back() const;
inline iterator Erase(const_iterator pos); inline void Clear(bool keepBuffer = false);
inline iterator Erase(const_iterator first, const_iterator last);
inline reference Front(); inline iterator Erase(const_iterator pos);
inline const_reference Front() const; inline iterator Erase(const_iterator first, const_iterator last);
inline allocator_type GetAllocator() const; inline reference Front();
inline pointer GetBuffer(); inline const_reference Front() const;
inline size_type GetCapacity() const noexcept;
inline const_pointer GetConstBuffer() const;
inline size_type GetMaxSize() const noexcept;
inline size_type GetSize() const noexcept;
inline NzByteArray GetSubArray(const_iterator startPos, const_iterator endPos) const;
inline iterator Insert(const_iterator pos, const void* buffer, size_type n); inline allocator_type GetAllocator() const;
inline iterator Insert(const_iterator pos, const NzByteArray& other); inline pointer GetBuffer();
inline iterator Insert(const_iterator pos, size_type n, value_type byte); inline size_type GetCapacity() const noexcept;
template <class InputIterator> iterator Insert(const_iterator pos, InputIterator first, InputIterator last); inline const_pointer GetConstBuffer() const;
inline bool IsEmpty() const noexcept; inline size_type GetMaxSize() const noexcept;
inline size_type GetSize() const noexcept;
inline ByteArray GetSubArray(const_iterator startPos, const_iterator endPos) const;
inline void PopBack(); inline iterator Insert(const_iterator pos, const void* buffer, size_type n);
inline void PopFront(); inline iterator Insert(const_iterator pos, const ByteArray& other);
inline iterator Prepend(const void* buffer, size_type size); inline iterator Insert(const_iterator pos, size_type n, value_type byte);
inline iterator Prepend(const NzByteArray& other); template <class InputIterator> iterator Insert(const_iterator pos, InputIterator first, InputIterator last);
inline void PushBack(value_type byte); inline bool IsEmpty() const noexcept;
inline void PushFront(value_type byte);
inline void Reserve(size_type bufferSize); inline void PopBack();
inline void Resize(size_type newSize); inline void PopFront();
inline void Resize(size_type newSize, value_type byte); inline iterator Prepend(const void* buffer, size_type size);
inline iterator Prepend(const ByteArray& other);
inline void PushBack(value_type byte);
inline void PushFront(value_type byte);
inline void ShrinkToFit(); inline void Reserve(size_type bufferSize);
inline void Swap(NzByteArray& other); inline void Resize(size_type newSize);
inline void Resize(size_type newSize, value_type byte);
inline NzString ToString() const; inline void ShrinkToFit();
inline void Swap(ByteArray& other);
// STL interface inline String ToString() const;
inline iterator begin() noexcept;
inline const_iterator begin() const noexcept;
inline bool empty() const noexcept;
inline iterator end() noexcept;
inline const_iterator end() const noexcept;
inline reverse_iterator rbegin() noexcept;
inline const_reverse_iterator rbegin() const noexcept;
inline reverse_iterator rend() noexcept;
inline const_reverse_iterator rend() const noexcept;
inline const_iterator cbegin() const noexcept;
inline const_iterator cend() const noexcept;
inline const_reverse_iterator crbegin() const noexcept;
inline const_reverse_iterator crend() const noexcept;
inline size_type size() const noexcept;
// Operators // STL interface
inline reference operator[](size_type pos); inline iterator begin() noexcept;
inline const_reference operator[](size_type pos) const; inline const_iterator begin() const noexcept;
inline NzByteArray& operator=(const NzByteArray& array) = default; inline bool empty() const noexcept;
inline NzByteArray& operator=(NzByteArray&& array) = default; inline iterator end() noexcept;
inline NzByteArray operator+(const NzByteArray& array) const; inline const_iterator end() const noexcept;
inline NzByteArray& operator+=(const NzByteArray& array); inline reverse_iterator rbegin() noexcept;
inline const_reverse_iterator rbegin() const noexcept;
inline reverse_iterator rend() noexcept;
inline const_reverse_iterator rend() const noexcept;
inline const_iterator cbegin() const noexcept;
inline const_iterator cend() const noexcept;
inline const_reverse_iterator crbegin() const noexcept;
inline const_reverse_iterator crend() const noexcept;
inline size_type size() const noexcept;
inline bool operator==(const NzByteArray& rhs) const; // Operators
inline bool operator!=(const NzByteArray& rhs) const; inline reference operator[](size_type pos);
inline bool operator<(const NzByteArray& rhs) const; inline const_reference operator[](size_type pos) const;
inline bool operator<=(const NzByteArray& rhs) const; inline ByteArray& operator=(const ByteArray& array) = default;
inline bool operator>(const NzByteArray& rhs) const; inline ByteArray& operator=(ByteArray&& array) = default;
inline bool operator>=(const NzByteArray& rhs) const; inline ByteArray operator+(const ByteArray& array) const;
inline ByteArray& operator+=(const ByteArray& array);
private: inline bool operator==(const ByteArray& rhs) const;
bool FillHash(NzAbstractHash* hash) const; inline bool operator!=(const ByteArray& rhs) const;
inline bool operator<(const ByteArray& rhs) const;
inline bool operator<=(const ByteArray& rhs) const;
inline bool operator>(const ByteArray& rhs) const;
inline bool operator>=(const ByteArray& rhs) const;
Container m_array; private:
}; bool FillHash(AbstractHash* hash) const;
NAZARA_CORE_API std::ostream& operator<<(std::ostream& out, const NzByteArray& byteArray); Container m_array;
};
}
NAZARA_CORE_API std::ostream& operator<<(std::ostream& out, const Nz::ByteArray& byteArray);
namespace std namespace std
{ {
void swap(NzByteArray& lhs, NzByteArray& rhs); void swap(Nz::ByteArray& lhs, Nz::ByteArray& rhs);
} }
#include <Nazara/Core/ByteArray.inl> #include <Nazara/Core/ByteArray.inl>

View File

@ -2,327 +2,330 @@
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
inline NzByteArray::NzByteArray(size_type n) : namespace Nz
m_array()
{ {
m_array.reserve(n); inline ByteArray::ByteArray(size_type n) :
} m_array()
{
m_array.reserve(n);
}
inline NzByteArray::NzByteArray(const void* buffer, size_type n) : inline ByteArray::ByteArray(const void* buffer, size_type n) :
m_array(static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n) m_array(static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n)
{ {
} }
inline NzByteArray::NzByteArray(size_type n, const value_type value) : inline ByteArray::ByteArray(size_type n, const value_type value) :
m_array(n, value) m_array(n, value)
{ {
} }
template <class InputIterator> template <class InputIterator>
NzByteArray::NzByteArray(InputIterator first, InputIterator last) : ByteArray::ByteArray(InputIterator first, InputIterator last) :
m_array(first, last) m_array(first, last)
{ {
} }
inline NzByteArray::iterator NzByteArray::Append(const void* buffer, size_type n) 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); return Insert(end(), static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n);
} }
inline NzByteArray::iterator NzByteArray::Append(const NzByteArray& other) inline ByteArray::iterator ByteArray::Append(const ByteArray& other)
{ {
return Insert(end(), other.begin(), other.end()); return Insert(end(), other.begin(), other.end());
} }
inline void NzByteArray::Assign(size_type n, value_type value) inline void ByteArray::Assign(size_type n, value_type value)
{ {
m_array.assign(n, value); m_array.assign(n, value);
} }
template <class InputIterator> template <class InputIterator>
void NzByteArray::Assign(InputIterator first, InputIterator last) void ByteArray::Assign(InputIterator first, InputIterator last)
{ {
m_array.assign(first, last); m_array.assign(first, last);
} }
inline NzByteArray::reference NzByteArray::Back() inline ByteArray::reference ByteArray::Back()
{ {
return m_array.back(); return m_array.back();
} }
inline NzByteArray::const_reference NzByteArray::Back() const inline ByteArray::const_reference ByteArray::Back() const
{ {
return m_array.back(); return m_array.back();
} }
inline NzByteArray::iterator NzByteArray::Erase(const_iterator pos) inline ByteArray::iterator ByteArray::Erase(const_iterator pos)
{ {
return m_array.erase(pos); return m_array.erase(pos);
} }
inline NzByteArray::iterator NzByteArray::Erase(const_iterator first, const_iterator last) inline ByteArray::iterator ByteArray::Erase(const_iterator first, const_iterator last)
{ {
return m_array.erase(first, last); return m_array.erase(first, last);
} }
inline NzByteArray::reference NzByteArray::Front() inline ByteArray::reference ByteArray::Front()
{ {
return m_array.front(); return m_array.front();
} }
inline NzByteArray::const_reference NzByteArray::Front() const inline ByteArray::const_reference ByteArray::Front() const
{ {
return m_array.front(); return m_array.front();
} }
inline NzByteArray::allocator_type NzByteArray::GetAllocator() const inline ByteArray::allocator_type ByteArray::GetAllocator() const
{ {
return m_array.get_allocator(); return m_array.get_allocator();
} }
inline NzByteArray::pointer NzByteArray::GetBuffer() inline ByteArray::pointer ByteArray::GetBuffer()
{ {
return m_array.data(); return m_array.data();
} }
inline NzByteArray::size_type NzByteArray::GetCapacity() const noexcept inline ByteArray::size_type ByteArray::GetCapacity() const noexcept
{ {
return m_array.capacity(); return m_array.capacity();
} }
inline NzByteArray::const_pointer NzByteArray::GetConstBuffer() const inline ByteArray::const_pointer ByteArray::GetConstBuffer() const
{ {
return m_array.data(); return m_array.data();
} }
inline NzByteArray::size_type NzByteArray::GetMaxSize() const noexcept inline ByteArray::size_type ByteArray::GetMaxSize() const noexcept
{ {
return m_array.max_size(); return m_array.max_size();
} }
inline NzByteArray::size_type NzByteArray::GetSize() const noexcept inline ByteArray::size_type ByteArray::GetSize() const noexcept
{ {
return m_array.size(); return m_array.size();
} }
inline NzByteArray NzByteArray::GetSubArray(const_iterator startPos, const_iterator endPos) const inline ByteArray ByteArray::GetSubArray(const_iterator startPos, const_iterator endPos) const
{ {
return NzByteArray(startPos, endPos); return ByteArray(startPos, endPos);
} }
inline NzByteArray::iterator NzByteArray::Insert(const_iterator pos, const void* buffer, size_type n) 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); return m_array.insert(pos, static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n);
} }
inline NzByteArray::iterator NzByteArray::Insert(const_iterator pos, const NzByteArray& other) inline ByteArray::iterator ByteArray::Insert(const_iterator pos, const ByteArray& other)
{ {
return m_array.insert(pos, other.begin(), other.end()); return m_array.insert(pos, other.begin(), other.end());
} }
inline NzByteArray::iterator NzByteArray::Insert(const_iterator pos, size_type n, value_type byte) inline ByteArray::iterator ByteArray::Insert(const_iterator pos, size_type n, value_type byte)
{ {
return m_array.insert(pos, n, byte); return m_array.insert(pos, n, byte);
} }
template <class InputIterator> template <class InputIterator>
NzByteArray::iterator NzByteArray::Insert(const_iterator pos, InputIterator first, InputIterator last) ByteArray::iterator ByteArray::Insert(const_iterator pos, InputIterator first, InputIterator last)
{ {
return m_array.insert(pos, first, last); return m_array.insert(pos, first, last);
} }
inline bool NzByteArray::IsEmpty() const noexcept inline bool ByteArray::IsEmpty() const noexcept
{ {
return m_array.empty(); return m_array.empty();
} }
inline void NzByteArray::PopBack() inline void ByteArray::PopBack()
{ {
Erase(end() - 1); Erase(end() - 1);
} }
inline void NzByteArray::PopFront() inline void ByteArray::PopFront()
{ {
Erase(begin()); Erase(begin());
} }
inline NzByteArray::iterator NzByteArray::Prepend(const void* buffer, size_type n) inline ByteArray::iterator ByteArray::Prepend(const void* buffer, size_type n)
{ {
return Insert(begin(), buffer, n); return Insert(begin(), buffer, n);
} }
inline NzByteArray::iterator NzByteArray::Prepend(const NzByteArray& other) inline ByteArray::iterator ByteArray::Prepend(const ByteArray& other)
{ {
return Insert(begin(), other); return Insert(begin(), other);
} }
inline void NzByteArray::PushBack(const value_type byte) inline void ByteArray::PushBack(const value_type byte)
{ {
m_array.push_back(byte); m_array.push_back(byte);
} }
inline void NzByteArray::PushFront(const value_type byte) inline void ByteArray::PushFront(const value_type byte)
{ {
m_array.insert(begin(), 1, byte); m_array.insert(begin(), 1, byte);
} }
inline void NzByteArray::Reserve(size_type bufferSize) inline void ByteArray::Reserve(size_type bufferSize)
{ {
m_array.reserve(bufferSize); m_array.reserve(bufferSize);
} }
inline void NzByteArray::Resize(size_type newSize) inline void ByteArray::Resize(size_type newSize)
{ {
m_array.resize(newSize); m_array.resize(newSize);
} }
inline void NzByteArray::Resize(size_type newSize, const value_type byte) inline void ByteArray::Resize(size_type newSize, const value_type byte)
{ {
m_array.resize(newSize, byte); m_array.resize(newSize, byte);
} }
inline void NzByteArray::ShrinkToFit() inline void ByteArray::ShrinkToFit()
{ {
m_array.shrink_to_fit(); m_array.shrink_to_fit();
} }
inline void NzByteArray::Swap(NzByteArray& other) inline void ByteArray::Swap(ByteArray& other)
{ {
m_array.swap(other.m_array); m_array.swap(other.m_array);
} }
inline NzString NzByteArray::ToString() const inline String ByteArray::ToString() const
{ {
return NzString(reinterpret_cast<const char*>(GetConstBuffer()), GetSize()); return String(reinterpret_cast<const char*>(GetConstBuffer()), GetSize());
} }
inline NzByteArray::iterator NzByteArray::begin() noexcept inline ByteArray::iterator ByteArray::begin() noexcept
{ {
return m_array.begin(); return m_array.begin();
} }
inline NzByteArray::const_iterator NzByteArray::begin() const noexcept inline ByteArray::const_iterator ByteArray::begin() const noexcept
{ {
return m_array.begin(); return m_array.begin();
} }
inline NzByteArray::const_iterator NzByteArray::cbegin() const noexcept inline ByteArray::const_iterator ByteArray::cbegin() const noexcept
{ {
return m_array.cbegin(); return m_array.cbegin();
} }
inline NzByteArray::const_iterator NzByteArray::cend() const noexcept inline ByteArray::const_iterator ByteArray::cend() const noexcept
{ {
return m_array.cend(); return m_array.cend();
} }
inline NzByteArray::const_reverse_iterator NzByteArray::crbegin() const noexcept inline ByteArray::const_reverse_iterator ByteArray::crbegin() const noexcept
{ {
return m_array.crbegin(); return m_array.crbegin();
} }
inline NzByteArray::const_reverse_iterator NzByteArray::crend() const noexcept inline ByteArray::const_reverse_iterator ByteArray::crend() const noexcept
{ {
return m_array.crend(); return m_array.crend();
} }
inline bool NzByteArray::empty() const noexcept inline bool ByteArray::empty() const noexcept
{ {
return m_array.empty(); return m_array.empty();
} }
inline NzByteArray::iterator NzByteArray::end() noexcept inline ByteArray::iterator ByteArray::end() noexcept
{ {
return m_array.end(); return m_array.end();
} }
inline NzByteArray::const_iterator NzByteArray::end() const noexcept inline ByteArray::const_iterator ByteArray::end() const noexcept
{ {
return m_array.end(); return m_array.end();
} }
inline NzByteArray::reverse_iterator NzByteArray::rbegin() noexcept inline ByteArray::reverse_iterator ByteArray::rbegin() noexcept
{ {
return m_array.rbegin(); return m_array.rbegin();
} }
inline NzByteArray::const_reverse_iterator NzByteArray::rbegin() const noexcept inline ByteArray::const_reverse_iterator ByteArray::rbegin() const noexcept
{ {
return m_array.rbegin(); return m_array.rbegin();
} }
inline NzByteArray::reverse_iterator NzByteArray::rend() noexcept inline ByteArray::reverse_iterator ByteArray::rend() noexcept
{ {
return m_array.rend(); return m_array.rend();
} }
inline NzByteArray::size_type NzByteArray::size() const noexcept inline ByteArray::size_type ByteArray::size() const noexcept
{ {
return GetSize(); return GetSize();
} }
inline NzByteArray::reference NzByteArray::operator[](size_type pos) inline ByteArray::reference ByteArray::operator[](size_type pos)
{ {
NazaraAssert(pos < GetSize(), "Index out of range"); NazaraAssert(pos < GetSize(), "Index out of range");
return m_array[pos]; return m_array[pos];
} }
inline NzByteArray::const_reference NzByteArray::operator[](size_type pos) const inline ByteArray::const_reference ByteArray::operator[](size_type pos) const
{ {
NazaraAssert(pos < GetSize(), "Index out of range"); NazaraAssert(pos < GetSize(), "Index out of range");
return m_array[pos]; return m_array[pos];
} }
inline NzByteArray NzByteArray::operator+(const NzByteArray& other) const inline ByteArray ByteArray::operator+(const ByteArray& other) const
{ {
NzByteArray tmp(*this); ByteArray tmp(*this);
tmp += other; tmp += other;
return tmp; return tmp;
} }
inline NzByteArray& NzByteArray::operator+=(const NzByteArray& other) inline ByteArray& ByteArray::operator+=(const ByteArray& other)
{ {
Append(other); Append(other);
return *this; return *this;
} }
inline bool NzByteArray::operator==(const NzByteArray& rhs) const inline bool ByteArray::operator==(const ByteArray& rhs) const
{ {
return m_array == rhs.m_array; return m_array == rhs.m_array;
} }
inline bool NzByteArray::operator!=(const NzByteArray& rhs) const inline bool ByteArray::operator!=(const ByteArray& rhs) const
{ {
return !operator==(rhs); return !operator==(rhs);
} }
inline bool NzByteArray::operator<(const NzByteArray& rhs) const inline bool ByteArray::operator<(const ByteArray& rhs) const
{ {
return m_array < rhs.m_array; return m_array < rhs.m_array;
} }
inline bool NzByteArray::operator<=(const NzByteArray& rhs) const inline bool ByteArray::operator<=(const ByteArray& rhs) const
{ {
return m_array <= rhs.m_array; return m_array <= rhs.m_array;
} }
inline bool NzByteArray::operator>(const NzByteArray& rhs) const inline bool ByteArray::operator>(const ByteArray& rhs) const
{ {
return m_array > rhs.m_array; return m_array > rhs.m_array;
} }
inline bool NzByteArray::operator>=(const NzByteArray& rhs) const inline bool ByteArray::operator>=(const ByteArray& rhs) const
{ {
return m_array >= rhs.m_array; return m_array >= rhs.m_array;
}
} }
namespace std namespace std
{ {
inline void swap(NzByteArray& lhs, NzByteArray& rhs) inline void swap(Nz::ByteArray& lhs, Nz::ByteArray& rhs)
{ {
lhs.Swap(rhs); lhs.Swap(rhs);
} }

View File

@ -8,23 +8,30 @@
#define NAZARA_CALLONEXIT_HPP #define NAZARA_CALLONEXIT_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <functional> #include <functional>
class NzCallOnExit : NzNonCopyable namespace Nz
{ {
using Func = std::function<void()>; class CallOnExit
{
using Func = std::function<void()>;
public: public:
NzCallOnExit(Func func = nullptr); CallOnExit(Func func = nullptr);
~NzCallOnExit(); CallOnExit(const CallOnExit&) = delete;
CallOnExit(CallOnExit&&) = delete;
~CallOnExit();
void CallAndReset(Func func = nullptr); void CallAndReset(Func func = nullptr);
void Reset(Func func = nullptr); void Reset(Func func = nullptr);
private: CallOnExit& operator=(const CallOnExit&) = delete;
Func m_func; CallOnExit& operator=(CallOnExit&&) = default;
};
private:
Func m_func;
};
}
#include <Nazara/Core/CallOnExit.inl> #include <Nazara/Core/CallOnExit.inl>

View File

@ -5,28 +5,31 @@
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
inline NzCallOnExit::NzCallOnExit(Func func) : namespace Nz
m_func(func)
{ {
} inline CallOnExit::CallOnExit(Func func) :
m_func(func)
{
}
inline NzCallOnExit::~NzCallOnExit() inline CallOnExit::~CallOnExit()
{ {
if (m_func) if (m_func)
m_func(); m_func();
} }
inline void NzCallOnExit::CallAndReset(Func func) inline void CallOnExit::CallAndReset(Func func)
{ {
if (m_func) if (m_func)
m_func(); m_func();
Reset(func); Reset(func);
} }
inline void NzCallOnExit::Reset(Func func) inline void CallOnExit::Reset(Func func)
{ {
m_func = func; m_func = func;
}
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

View File

@ -15,35 +15,41 @@
#include <Nazara/Core/ThreadSafetyOff.hpp> #include <Nazara/Core/ThreadSafetyOff.hpp>
#endif #endif
class NAZARA_CORE_API NzClock namespace Nz
{ {
public: class NAZARA_CORE_API Clock
NzClock(nzUInt64 startingValue = 0, bool paused = false); {
NzClock(const NzClock& clock) = default; public:
Clock(UInt64 startingValue = 0, bool paused = false);
Clock(const Clock& clock) = default;
Clock(Clock&& clock) = default;
~Clock() = default;
float GetSeconds() const; float GetSeconds() const;
nzUInt64 GetMicroseconds() const; UInt64 GetMicroseconds() const;
nzUInt64 GetMilliseconds() const; UInt64 GetMilliseconds() const;
bool IsPaused() const; bool IsPaused() const;
void Pause(); void Pause();
void Restart(); void Restart();
void Unpause(); void Unpause();
NzClock& operator=(const NzClock& clock) = default; Clock& operator=(const Clock& clock) = default;
Clock& operator=(Clock&& clock) = default;
private: private:
NazaraMutexAttrib(m_mutex, mutable) NazaraMutexAttrib(m_mutex, mutable)
nzUInt64 m_elapsedTime; UInt64 m_elapsedTime;
nzUInt64 m_refTime; UInt64 m_refTime;
bool m_paused; bool m_paused;
}; };
typedef nzUInt64 (*NzClockFunction)(); typedef UInt64 (*ClockFunction)();
extern NAZARA_CORE_API NzClockFunction NzGetMicroseconds; extern NAZARA_CORE_API ClockFunction GetElapsedMicroseconds;
extern NAZARA_CORE_API NzClockFunction NzGetMilliseconds; extern NAZARA_CORE_API ClockFunction GetElapsedMilliseconds;
}
#endif // NAZARA_CLOCK_HPP #endif // NAZARA_CLOCK_HPP

View File

@ -11,57 +11,60 @@
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
class NzColor namespace Nz
{ {
public: class Color
inline NzColor(); {
inline NzColor(nzUInt8 red, nzUInt8 green, nzUInt8 blue, nzUInt8 alpha = 255); public:
inline explicit NzColor(nzUInt8 lightness); inline Color();
inline NzColor(nzUInt8 color[3], nzUInt8 alpha = 255); inline Color(UInt8 red, UInt8 green, UInt8 blue, UInt8 alpha = 255);
inline NzColor(const NzColor& color) = default; inline explicit Color(UInt8 lightness);
inline ~NzColor() = default; inline Color(UInt8 color[3], UInt8 alpha = 255);
inline Color(const Color& color) = default;
inline ~Color() = default;
inline NzString ToString() const; inline String ToString() const;
inline NzColor operator+(const NzColor& angles) const; inline Color operator+(const Color& angles) const;
inline NzColor operator*(const NzColor& angles) const; inline Color operator*(const Color& angles) const;
inline NzColor operator+=(const NzColor& angles); inline Color operator+=(const Color& angles);
inline NzColor operator*=(const NzColor& angles); inline Color operator*=(const Color& angles);
inline bool operator==(const NzColor& angles) const; inline bool operator==(const Color& angles) const;
inline bool operator!=(const NzColor& angles) const; inline bool operator!=(const Color& angles) const;
static inline NzColor FromCMY(float cyan, float magenta, float yellow); static inline Color FromCMY(float cyan, float magenta, float yellow);
static inline NzColor FromCMYK(float cyan, float magenta, float yellow, float black); static inline Color FromCMYK(float cyan, float magenta, float yellow, float black);
static inline NzColor FromHSL(nzUInt8 hue, nzUInt8 saturation, nzUInt8 lightness); static inline Color FromHSL(UInt8 hue, UInt8 saturation, UInt8 lightness);
static inline NzColor FromHSV(float hue, float saturation, float value); static inline Color FromHSV(float hue, float saturation, float value);
static inline NzColor FromXYZ(const NzVector3f& vec); static inline Color FromXYZ(const Vector3f& vec);
static inline NzColor FromXYZ(float x, float y, float z); static inline Color FromXYZ(float x, float y, float z);
static inline void ToCMY(const NzColor& color, float* cyan, float* magenta, float* yellow); static inline void ToCMY(const Color& color, float* cyan, float* magenta, float* yellow);
static inline void ToCMYK(const NzColor& color, float* cyan, float* magenta, float* yellow, float* black); static inline void ToCMYK(const Color& color, float* cyan, float* magenta, float* yellow, float* black);
static inline void ToHSL(const NzColor& color, nzUInt8* hue, nzUInt8* saturation, nzUInt8* lightness); static inline void ToHSL(const Color& color, UInt8* hue, UInt8* saturation, UInt8* lightness);
static inline void ToHSV(const NzColor& color, float* hue, float* saturation, float* value); static inline void ToHSV(const Color& color, float* hue, float* saturation, float* value);
static inline void ToXYZ(const NzColor& color, NzVector3f* vec); static inline void ToXYZ(const Color& color, Vector3f* vec);
static inline void ToXYZ(const NzColor& color, float* x, float* y, float* z); static inline void ToXYZ(const Color& color, float* x, float* y, float* z);
nzUInt8 r, g, b, a; UInt8 r, g, b, a;
static NAZARA_CORE_API const NzColor Black; static NAZARA_CORE_API const Color Black;
static NAZARA_CORE_API const NzColor Blue; static NAZARA_CORE_API const Color Blue;
static NAZARA_CORE_API const NzColor Cyan; static NAZARA_CORE_API const Color Cyan;
static NAZARA_CORE_API const NzColor Green; static NAZARA_CORE_API const Color Green;
static NAZARA_CORE_API const NzColor Magenta; static NAZARA_CORE_API const Color Magenta;
static NAZARA_CORE_API const NzColor Orange; static NAZARA_CORE_API const Color Orange;
static NAZARA_CORE_API const NzColor Red; static NAZARA_CORE_API const Color Red;
static NAZARA_CORE_API const NzColor Yellow; static NAZARA_CORE_API const Color Yellow;
static NAZARA_CORE_API const NzColor White; static NAZARA_CORE_API const Color White;
private: private:
static float Hue2RGB(float v1, float v2, float vH); static float Hue2RGB(float v1, float v2, float vH);
}; };
}
std::ostream& operator<<(std::ostream& out, const NzColor& color); std::ostream& operator<<(std::ostream& out, const Nz::Color& color);
#include <Nazara/Core/Color.inl> #include <Nazara/Core/Color.inl>

View File

@ -9,411 +9,414 @@
#include <stdexcept> #include <stdexcept>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
inline NzColor::NzColor() namespace Nz
{ {
} inline Color::Color()
inline NzColor::NzColor(nzUInt8 red, nzUInt8 green, nzUInt8 blue, nzUInt8 alpha) :
r(red),
g(green),
b(blue),
a(alpha)
{
}
inline NzColor::NzColor(nzUInt8 lightness) :
r(lightness),
g(lightness),
b(lightness),
a(255)
{
}
inline NzColor::NzColor(nzUInt8 vec[3], nzUInt8 alpha) :
r(vec[0]),
g(vec[1]),
b(vec[2]),
a(alpha)
{
}
inline NzString NzColor::ToString() const
{
NzStringStream ss;
ss << "Color(" << static_cast<int>(r) << ", " << static_cast<int>(g) << ", " << static_cast<int>(b);
if (a != 255)
ss << ", " << static_cast<int>(a);
ss << ')';
return ss;
}
inline NzColor NzColor::operator+(const NzColor& color) const
{
NzColor c;
c.r = std::min(static_cast<unsigned int>(r) + static_cast<unsigned int>(color.r), 255U);
c.g = std::min(static_cast<unsigned int>(g) + static_cast<unsigned int>(color.g), 255U);
c.b = std::min(static_cast<unsigned int>(b) + static_cast<unsigned int>(color.b), 255U);
c.a = std::min(static_cast<unsigned int>(a) + static_cast<unsigned int>(color.a), 255U);
return c;
}
inline NzColor NzColor::operator*(const NzColor& color) const
{
NzColor c;
c.r = (static_cast<unsigned int>(r) * static_cast<unsigned int>(color.r)) / 255U;
c.g = (static_cast<unsigned int>(g) * static_cast<unsigned int>(color.g)) / 255U;
c.b = (static_cast<unsigned int>(b) * static_cast<unsigned int>(color.b)) / 255U;
c.a = (static_cast<unsigned int>(a) * static_cast<unsigned int>(color.a)) / 255U;
return c;
}
inline NzColor NzColor::operator+=(const NzColor& color)
{
return operator=(operator+(color));
}
inline NzColor NzColor::operator*=(const NzColor& color)
{
return operator=(operator*(color));
}
inline bool NzColor::operator==(const NzColor& color) const
{
return r == color.r && g == color.g && b == color.b && a == color.a;
}
inline bool NzColor::operator!=(const NzColor& color) const
{
return !operator==(color);
}
// Algorithmes venant de http://www.easyrgb.com/index.php?X=MATH
inline NzColor NzColor::FromCMY(float cyan, float magenta, float yellow)
{
return NzColor(static_cast<nzUInt8>((1.f-cyan)*255.f), static_cast<nzUInt8>((1.f-magenta)*255.f), static_cast<nzUInt8>((1.f-yellow)*255.f));
}
inline NzColor NzColor::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);
}
inline NzColor NzColor::FromHSL(nzUInt8 hue, nzUInt8 saturation, nzUInt8 lightness)
{
if (saturation == 0)
{ {
// RGB results from 0 to 255
return NzColor(lightness * 255,
lightness * 255,
lightness * 255);
} }
else
inline Color::Color(UInt8 red, UInt8 green, UInt8 blue, UInt8 alpha) :
r(red),
g(green),
b(blue),
a(alpha)
{ {
// Norme Windows
float l = lightness/240.f;
float h = hue/240.f;
float s = saturation/240.f;
float v2;
if (l < 0.5f)
v2 = l * (1.f + s);
else
v2 = (l + s) - (s*l);
float v1 = 2.f * l - v2;
return NzColor(static_cast<nzUInt8>(255.f * Hue2RGB(v1, v2, h + (1.f/3.f))),
static_cast<nzUInt8>(255.f * Hue2RGB(v1, v2, h)),
static_cast<nzUInt8>(255.f * Hue2RGB(v1, v2, h - (1.f/3.f))));
} }
}
inline NzColor NzColor::FromHSV(float hue, float saturation, float value) inline Color::Color(UInt8 lightness) :
{ r(lightness),
if (NzNumberEquals(saturation, 0.f)) g(lightness),
return NzColor(static_cast<nzUInt8>(value * 255.f)); b(lightness),
else a(255)
{ {
float h = hue/360.f * 6.f; }
float s = saturation/360.f;
if (NzNumberEquals(h, 6.f)) inline Color::Color(UInt8 vec[3], UInt8 alpha) :
h = 0; // hue must be < 1 r(vec[0]),
g(vec[1]),
b(vec[2]),
a(alpha)
{
}
int i = static_cast<unsigned int>(h); inline String Color::ToString() const
float v1 = value * (1.f - s); {
float v2 = value * (1.f - s * (h - i)); StringStream ss;
float v3 = value * (1.f - s * (1.f - (h - i))); ss << "Color(" << static_cast<int>(r) << ", " << static_cast<int>(g) << ", " << static_cast<int>(b);
float r, g, b; if (a != 255)
switch (i) ss << ", " << static_cast<int>(a);
ss << ')';
return ss;
}
inline Color Color::operator+(const Color& color) const
{
Color c;
c.r = std::min(static_cast<unsigned int>(r) + static_cast<unsigned int>(color.r), 255U);
c.g = std::min(static_cast<unsigned int>(g) + static_cast<unsigned int>(color.g), 255U);
c.b = std::min(static_cast<unsigned int>(b) + static_cast<unsigned int>(color.b), 255U);
c.a = std::min(static_cast<unsigned int>(a) + static_cast<unsigned int>(color.a), 255U);
return c;
}
inline Color Color::operator*(const Color& color) const
{
Color c;
c.r = (static_cast<unsigned int>(r) * static_cast<unsigned int>(color.r)) / 255U;
c.g = (static_cast<unsigned int>(g) * static_cast<unsigned int>(color.g)) / 255U;
c.b = (static_cast<unsigned int>(b) * static_cast<unsigned int>(color.b)) / 255U;
c.a = (static_cast<unsigned int>(a) * static_cast<unsigned int>(color.a)) / 255U;
return c;
}
inline Color Color::operator+=(const Color& color)
{
return operator=(operator+(color));
}
inline Color Color::operator*=(const Color& color)
{
return operator=(operator*(color));
}
inline bool Color::operator==(const Color& color) const
{
return r == color.r && g == color.g && b == color.b && a == color.a;
}
inline bool Color::operator!=(const Color& color) const
{
return !operator==(color);
}
// Algorithmes venant de http://www.easyrgb.com/index.php?X=MATH
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));
}
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);
}
inline Color Color::FromHSL(UInt8 hue, UInt8 saturation, UInt8 lightness)
{
if (saturation == 0)
{ {
case 0: // RGB results from 0 to 255
r = value; return Color(lightness * 255,
g = v3; lightness * 255,
b = v1; lightness * 255);
break; }
else
{
// Norme Windows
float l = lightness/240.f;
float h = hue/240.f;
float s = saturation/240.f;
case 1: float v2;
r = v2; if (l < 0.5f)
g = value; v2 = l * (1.f + s);
b = v1; else
break; v2 = (l + s) - (s*l);
case 2: float v1 = 2.f * l - v2;
r = v1;
g = value;
b = v3;
break;
case 3: return Color(static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h + (1.f/3.f))),
r = v1; static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h)),
g = v2; static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h - (1.f/3.f))));
b = value; }
break; }
case 4: inline Color Color::FromHSV(float hue, float saturation, float value)
r = v3; {
g = v1; if (NumberEquals(saturation, 0.f))
b = value; return Color(static_cast<UInt8>(value * 255.f));
break; else
{
float h = hue/360.f * 6.f;
float s = saturation/360.f;
default: if (NumberEquals(h, 6.f))
r = value; h = 0; // hue must be < 1
g = v1;
b = v2; int i = static_cast<unsigned int>(h);
break; float v1 = value * (1.f - s);
float v2 = value * (1.f - s * (h - i));
float v3 = value * (1.f - s * (1.f - (h - i)));
float r, g, b;
switch (i)
{
case 0:
r = value;
g = v3;
b = v1;
break;
case 1:
r = v2;
g = value;
b = v1;
break;
case 2:
r = v1;
g = value;
b = v3;
break;
case 3:
r = v1;
g = v2;
b = value;
break;
case 4:
r = v3;
g = v1;
b = value;
break;
default:
r = value;
g = v1;
b = v2;
break;
}
// RGB results from 0 to 255
return Color(static_cast<UInt8>(r*255.f), static_cast<UInt8>(g*255.f), static_cast<UInt8>(b*255.f));
}
}
inline Color Color::FromXYZ(const Vector3f& vec)
{
return FromXYZ(vec.x, vec.y, vec.z);
}
inline Color Color::FromXYZ(float x, float y, float z)
{
x /= 100.f; // X from 0 to 95.047
y /= 100.f; // Y from 0 to 100.000
z /= 100.f; // Z from 0 to 108.883
float r = x * 3.2406f + y * -1.5372f + z * -0.4986f;
float g = x * -0.9689f + y * 1.8758f + z * 0.0415f;
float b = x * 0.0557f + y * -0.2040f + z * 1.0570f;
if (r > 0.0031308f)
r = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
r *= 12.92f;
if (g > 0.0031308f)
g = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
g *= 12.92f;
if (b > 0.0031308f)
b = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
b *= 12.92f;
return Color(static_cast<UInt8>(r * 255.f), static_cast<UInt8>(g * 255.f), static_cast<UInt8>(b * 255.f));
}
inline void Color::ToCMY(const Color& color, float* cyan, float* magenta, float* yellow)
{
*cyan = 1.f - color.r/255.f;
*magenta = 1.f - color.g/255.f;
*yellow = 1.f - color.b/255.f;
}
inline void Color::ToCMYK(const Color& color, float* cyan, float* magenta, float* yellow, float* black)
{
float c, m, y;
ToCMY(color, &c, &m, &y);
float k = std::min({1.f, c, m, y});
if (NumberEquals(k, 1.f))
{
//Black
*cyan = 0.f;
*magenta = 0.f;
*yellow = 0.f;
}
else
{
*cyan = (c-k)/(1.f-k);
*magenta = (m-k)/(1.f-k);
*yellow = (y-k)/(1.f-k);
} }
// RGB results from 0 to 255 *black = k;
return NzColor(static_cast<nzUInt8>(r*255.f), static_cast<nzUInt8>(g*255.f), static_cast<nzUInt8>(b*255.f));
}
}
inline NzColor NzColor::FromXYZ(const NzVector3f& vec)
{
return FromXYZ(vec.x, vec.y, vec.z);
}
inline NzColor NzColor::FromXYZ(float x, float y, float z)
{
x /= 100.f; // X from 0 to 95.047
y /= 100.f; // Y from 0 to 100.000
z /= 100.f; // Z from 0 to 108.883
float r = x * 3.2406f + y * -1.5372f + z * -0.4986f;
float g = x * -0.9689f + y * 1.8758f + z * 0.0415f;
float b = x * 0.0557f + y * -0.2040f + z * 1.0570f;
if (r > 0.0031308f)
r = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
r *= 12.92f;
if (g > 0.0031308f)
g = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
g *= 12.92f;
if (b > 0.0031308f)
b = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
b *= 12.92f;
return NzColor(static_cast<nzUInt8>(r * 255.f), static_cast<nzUInt8>(g * 255.f), static_cast<nzUInt8>(b * 255.f));
}
inline void NzColor::ToCMY(const NzColor& color, float* cyan, float* magenta, float* yellow)
{
*cyan = 1.f - color.r/255.f;
*magenta = 1.f - color.g/255.f;
*yellow = 1.f - color.b/255.f;
}
inline void NzColor::ToCMYK(const NzColor& color, float* cyan, float* magenta, float* yellow, float* black)
{
float c, m, y;
ToCMY(color, &c, &m, &y);
float k = std::min({1.f, c, m, y});
if (NzNumberEquals(k, 1.f))
{
//Black
*cyan = 0.f;
*magenta = 0.f;
*yellow = 0.f;
}
else
{
*cyan = (c-k)/(1.f-k);
*magenta = (m-k)/(1.f-k);
*yellow = (y-k)/(1.f-k);
} }
*black = k; inline void Color::ToHSL(const Color& color, UInt8* hue, UInt8* saturation, UInt8* lightness)
}
inline void NzColor::ToHSL(const NzColor& color, nzUInt8* hue, nzUInt8* saturation, nzUInt8* lightness)
{
float r = color.r / 255.f;
float g = color.g / 255.f;
float b = color.b / 255.f;
float min = std::min({r, g, b}); // Min. value of RGB
float max = std::max({r, g, b}); // Max. value of RGB
float deltaMax = max - min; //Delta RGB value
float l = (max + min)/2.f;
if (NzNumberEquals(deltaMax, 0.f))
{ {
//This is a gray, no chroma... float r = color.r / 255.f;
*hue = 0; //HSL results from 0 to 1 float g = color.g / 255.f;
*saturation = 0; float b = color.b / 255.f;
}
else float min = std::min({r, g, b}); // Min. value of RGB
{ float max = std::max({r, g, b}); // Max. value of RGB
//Chromatic data...
if (l < 0.5f) float deltaMax = max - min; //Delta RGB value
*saturation = static_cast<nzUInt8>(deltaMax/(max+min)*240.f);
float l = (max + min)/2.f;
if (NumberEquals(deltaMax, 0.f))
{
//This is a gray, no chroma...
*hue = 0; //HSL results from 0 to 1
*saturation = 0;
}
else else
*saturation = static_cast<nzUInt8>(deltaMax/(2.f-max-min)*240.f); {
//Chromatic data...
if (l < 0.5f)
*saturation = static_cast<UInt8>(deltaMax/(max+min)*240.f);
else
*saturation = static_cast<UInt8>(deltaMax/(2.f-max-min)*240.f);
*lightness = static_cast<nzUInt8>(l*240.f); *lightness = static_cast<UInt8>(l*240.f);
float deltaR = ((max - r)/6.f + deltaMax/2.f)/deltaMax; float deltaR = ((max - r)/6.f + deltaMax/2.f)/deltaMax;
float deltaG = ((max - g)/6.f + deltaMax/2.f)/deltaMax; float deltaG = ((max - g)/6.f + deltaMax/2.f)/deltaMax;
float deltaB = ((max - b)/6.f + deltaMax/2.f)/deltaMax; float deltaB = ((max - b)/6.f + deltaMax/2.f)/deltaMax;
float h; float h;
if (NzNumberEquals(r, max)) if (NumberEquals(r, max))
h = deltaB - deltaG; h = deltaB - deltaG;
else if (NzNumberEquals(g, max)) else if (NumberEquals(g, max))
h = (1.f/3.f) + deltaR - deltaB; h = (1.f/3.f) + deltaR - deltaB;
else else
h = (2.f/3.f) + deltaG - deltaR; h = (2.f/3.f) + deltaG - deltaR;
if (h < 0.f) if (h < 0.f)
h += 1.f; h += 1.f;
else if (h > 1.f) else if (h > 1.f)
h -= 1.f; h -= 1.f;
*hue = static_cast<nzUInt8>(h*240.f); *hue = static_cast<UInt8>(h*240.f);
}
} }
}
inline void NzColor::ToHSV(const NzColor& color, float* hue, float* saturation, float* value) inline void Color::ToHSV(const Color& color, float* hue, float* saturation, float* value)
{
float r = color.r / 255.f;
float g = color.g / 255.f;
float b = color.b / 255.f;
float min = std::min({r, g, b}); //Min. value of RGB
float max = std::max({r, g, b}); //Max. value of RGB
float deltaMax = max - min; //Delta RGB value
*value = max;
if (NzNumberEquals(deltaMax, 0.f))
{ {
//This is a gray, no chroma... float r = color.r / 255.f;
*hue = 0; //HSV results from 0 to 1 float g = color.g / 255.f;
*saturation = 0; float b = color.b / 255.f;
}
else
{
//Chromatic data...
*saturation = deltaMax/max*360.f;
float deltaR = ((max - r)/6.f + deltaMax/2.f)/deltaMax; float min = std::min({r, g, b}); //Min. value of RGB
float deltaG = ((max - g)/6.f + deltaMax/2.f)/deltaMax; float max = std::max({r, g, b}); //Max. value of RGB
float deltaB = ((max - b)/6.f + deltaMax/2.f)/deltaMax;
float h; float deltaMax = max - min; //Delta RGB value
if (NzNumberEquals(r, max)) *value = max;
h = deltaB - deltaG;
else if (NzNumberEquals(g, max)) if (NumberEquals(deltaMax, 0.f))
h = (1.f/3.f) + deltaR - deltaB; {
//This is a gray, no chroma...
*hue = 0; //HSV results from 0 to 1
*saturation = 0;
}
else else
h = (2.f/3.f) + deltaG - deltaR; {
//Chromatic data...
*saturation = deltaMax/max*360.f;
if (h < 0.f) float deltaR = ((max - r)/6.f + deltaMax/2.f)/deltaMax;
h += 1.f; float deltaG = ((max - g)/6.f + deltaMax/2.f)/deltaMax;
else if (h > 1.f) float deltaB = ((max - b)/6.f + deltaMax/2.f)/deltaMax;
h -= 1.f;
*hue = h*360.f; float h;
if (NumberEquals(r, max))
h = deltaB - deltaG;
else if (NumberEquals(g, max))
h = (1.f/3.f) + deltaR - deltaB;
else
h = (2.f/3.f) + deltaG - deltaR;
if (h < 0.f)
h += 1.f;
else if (h > 1.f)
h -= 1.f;
*hue = h*360.f;
}
} }
inline void Color::ToXYZ(const Color& color, Vector3f* vec)
{
return ToXYZ(color, &vec->x, &vec->y, &vec->z);
}
inline void Color::ToXYZ(const Color& color, float* x, float* y, float* z)
{
float r = color.r/255.f; //R from 0 to 255
float g = color.g/255.f; //G from 0 to 255
float b = color.b/255.f; //B from 0 to 255
if (r > 0.04045f)
r = std::pow((r + 0.055f)/1.055f, 2.4f);
else
r /= 12.92f;
if (g > 0.04045f)
g = std::pow((g + 0.055f)/1.055f, 2.4f);
else
g /= 12.92f;
if (b > 0.04045f)
b = std::pow((b + 0.055f)/1.055f, 2.4f);
else
b /= 12.92f;
r *= 100.f;
g *= 100.f;
b *= 100.f;
//Observer. = 2°, Illuminant = D65
*x = r*0.4124f + g*0.3576f + b*0.1805f;
*y = r*0.2126f + g*0.7152f + b*0.0722f;
*z = r*0.0193f + g*0.1192f + b*0.9505f;
}
inline float Color::Hue2RGB(float v1, float v2, float vH)
{
if (vH < 0.f)
vH += 1;
if (vH > 1.f)
vH -= 1;
if ((6.f * vH) < 1.f)
return v1 + (v2-v1)*6*vH;
if ((2.f * vH) < 1.f)
return v2;
if ((3.f * vH) < 2.f)
return v1 + (v2 - v1)*(2.f/3.f - vH)*6;
return v1;
}
} }
inline void NzColor::ToXYZ(const NzColor& color, NzVector3f* vec) inline std::ostream& operator<<(std::ostream& out, const Nz::Color& color)
{
return ToXYZ(color, &vec->x, &vec->y, &vec->z);
}
inline void NzColor::ToXYZ(const NzColor& color, float* x, float* y, float* z)
{
float r = color.r/255.f; //R from 0 to 255
float g = color.g/255.f; //G from 0 to 255
float b = color.b/255.f; //B from 0 to 255
if (r > 0.04045f)
r = std::pow((r + 0.055f)/1.055f, 2.4f);
else
r /= 12.92f;
if (g > 0.04045f)
g = std::pow((g + 0.055f)/1.055f, 2.4f);
else
g /= 12.92f;
if (b > 0.04045f)
b = std::pow((b + 0.055f)/1.055f, 2.4f);
else
b /= 12.92f;
r *= 100.f;
g *= 100.f;
b *= 100.f;
//Observer. = 2°, Illuminant = D65
*x = r*0.4124f + g*0.3576f + b*0.1805f;
*y = r*0.2126f + g*0.7152f + b*0.0722f;
*z = r*0.0193f + g*0.1192f + b*0.9505f;
}
inline float NzColor::Hue2RGB(float v1, float v2, float vH)
{
if (vH < 0.f)
vH += 1;
if (vH > 1.f)
vH -= 1;
if ((6.f * vH) < 1.f)
return v1 + (v2-v1)*6*vH;
if ((2.f * vH) < 1.f)
return v2;
if ((3.f * vH) < 2.f)
return v1 + (v2 - v1)*(2.f/3.f - vH)*6;
return v1;
}
inline std::ostream& operator<<(std::ostream& out, const NzColor& color)
{ {
return out << color.ToString(); return out << color.ToString();
} }

View File

@ -8,25 +8,32 @@
#define NAZARA_CONDITIONVARIABLE_HPP #define NAZARA_CONDITIONVARIABLE_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
class NzConditionVariableImpl; namespace Nz
class NzMutex;
class NAZARA_CORE_API NzConditionVariable : NzNonCopyable
{ {
public: class ConditionVariableImpl;
NzConditionVariable(); class Mutex;
~NzConditionVariable();
void Signal(); class NAZARA_CORE_API ConditionVariable
void SignalAll(); {
public:
ConditionVariable();
ConditionVariable(const ConditionVariable&) = delete;
ConditionVariable(ConditionVariable&&) = delete; ///TODO
~ConditionVariable();
void Wait(NzMutex* mutex); void Signal();
bool Wait(NzMutex* mutex, nzUInt32 timeout); void SignalAll();
private: void Wait(Mutex* mutex);
NzConditionVariableImpl* m_impl; bool Wait(Mutex* mutex, UInt32 timeout);
};
ConditionVariable& operator=(const ConditionVariable&) = delete;
ConditionVariable& operator=(ConditionVariable&&) = delete; ///TODO
private:
ConditionVariableImpl* m_impl;
};
}
#endif // NAZARA_CONDITIONVARIABLE_HPP #endif // NAZARA_CONDITIONVARIABLE_HPP

View File

@ -44,7 +44,7 @@
// Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash) // Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash)
#define NAZARA_CORE_FILE_BUFFERSIZE 4096 #define NAZARA_CORE_FILE_BUFFERSIZE 4096
// Incorpore la table Unicode Character Data (Nécessaires pour faire fonctionner le flag NzString::HandleUTF8) // Incorpore la table Unicode Character Data (Nécessaires pour faire fonctionner le flag String::HandleUTF8)
#define NAZARA_CORE_INCLUDE_UNICODEDATA 0 #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) // Utilise le MemoryManager pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
@ -57,12 +57,12 @@
#define NAZARA_CORE_THREADSAFE 1 #define NAZARA_CORE_THREADSAFE 1
// Les classes à protéger des accès concurrentiels // Les classes à protéger des accès concurrentiels
#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock #define NAZARA_THREADSAFETY_CLOCK 0 // Clock
#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory #define NAZARA_THREADSAFETY_DIRECTORY 1 // Directory
#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib #define NAZARA_THREADSAFETY_DYNLIB 1 // DynLib
#define NAZARA_THREADSAFETY_FILE 1 // NzFile #define NAZARA_THREADSAFETY_FILE 1 // File
#define NAZARA_THREADSAFETY_LOG 1 // NzLog #define NAZARA_THREADSAFETY_LOG 1 // Log
#define NAZARA_THREADSAFETY_REFCOUNTED 1 // NzRefCounted #define NAZARA_THREADSAFETY_REFCOUNTED 1 // RefCounted
// Le nombre de spinlocks à utiliser avec les sections critiques de Windows (0 pour désactiver) // Le nombre de spinlocks à utiliser avec les sections critiques de Windows (0 pour désactiver)
#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096 #define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096

View File

@ -10,20 +10,23 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp> #include <Nazara/Core/Initializer.hpp>
class NAZARA_CORE_API NzCore namespace Nz
{ {
public: class NAZARA_CORE_API Core
NzCore() = delete; {
~NzCore() = delete; public:
Core() = delete;
~Core() = delete;
static bool Initialize(); static bool Initialize();
static bool IsInitialized(); static bool IsInitialized();
static void Uninitialize(); static void Uninitialize();
private: private:
static unsigned int s_moduleReferenceCounter; static unsigned int s_moduleReferenceCounter;
}; };
}
#endif // NAZARA_CORE_HPP #endif // NAZARA_CORE_HPP

View File

@ -21,7 +21,7 @@ NAZARA_CORE_API void operator delete[](void* ptr, const char* file, unsigned int
#endif // NAZARA_DEBUG_NEWREDEFINITION_HPP #endif // NAZARA_DEBUG_NEWREDEFINITION_HPP
#ifndef NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION #ifndef NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete #define delete MemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__) #define new new(__FILE__, __LINE__)
#endif #endif

View File

@ -8,7 +8,6 @@
#define NAZARA_DIRECTORY_HPP #define NAZARA_DIRECTORY_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_WINDOWS)
@ -26,49 +25,57 @@
#include <Nazara/Core/ThreadSafetyOff.hpp> #include <Nazara/Core/ThreadSafetyOff.hpp>
#endif #endif
class NzDirectoryImpl; namespace Nz
class NAZARA_CORE_API NzDirectory : NzNonCopyable
{ {
public: class DirectoryImpl;
NzDirectory();
NzDirectory(const NzString& dirPath);
~NzDirectory();
void Close(); class NAZARA_CORE_API Directory
{
public:
Directory();
Directory(const String& dirPath);
Directory(const Directory&) = delete;
Directory(Directory&&) = delete; ///TODO
~Directory();
bool Exists() const; void Close();
NzString GetPath() const; bool Exists() const;
NzString GetPattern() const;
NzString GetResultName() const;
NzString GetResultPath() const;
nzUInt64 GetResultSize() const;
bool IsOpen() const; String GetPath() const;
bool IsResultDirectory() const; String GetPattern() const;
String GetResultName() const;
String GetResultPath() const;
UInt64 GetResultSize() const;
bool NextResult(bool skipDots = true); bool IsOpen() const;
bool IsResultDirectory() const;
bool Open(); bool NextResult(bool skipDots = true);
void SetPath(const NzString& dirPath); bool Open();
void SetPattern(const NzString& pattern);
static bool Copy(const NzString& sourcePath, const NzString& destPath); void SetPath(const String& dirPath);
static bool Create(const NzString& dirPath, bool recursive = false); void SetPattern(const String& pattern);
static bool Exists(const NzString& dirPath);
static NzString GetCurrent();
static const char* GetCurrentFileRelativeToEngine(const char* currentFile);
static bool Remove(const NzString& dirPath, bool emptyDirectory = false);
static bool SetCurrent(const NzString& dirPath);
private: static bool Copy(const String& sourcePath, const String& destPath);
NazaraMutexAttrib(m_mutex, mutable) static bool Create(const String& dirPath, bool recursive = false);
static bool Exists(const String& dirPath);
static String GetCurrent();
static const char* GetCurrentFileRelativeToEngine(const char* currentFile);
static bool Remove(const String& dirPath, bool emptyDirectory = false);
static bool SetCurrent(const String& dirPath);
NzString m_dirPath; Directory& operator=(const Directory&) = delete;
NzString m_pattern; Directory& operator=(Directory&&) = delete; ///TODO
NzDirectoryImpl* m_impl;
}; private:
NazaraMutexAttrib(m_mutex, mutable)
String m_dirPath;
String m_pattern;
DirectoryImpl* m_impl;
};
}
#endif // NAZARA_DIRECTORY_HPP #endif // NAZARA_DIRECTORY_HPP

View File

@ -8,7 +8,6 @@
#define NAZARA_DYNLIB_HPP #define NAZARA_DYNLIB_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_WINDOWS)
@ -27,32 +26,37 @@
#include <Nazara/Core/ThreadSafetyOff.hpp> #include <Nazara/Core/ThreadSafetyOff.hpp>
#endif #endif
using NzDynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction namespace Nz
class NzDynLibImpl;
class NAZARA_CORE_API NzDynLib : NzNonCopyable
{ {
public: using DynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction
NzDynLib();
NzDynLib(NzDynLib&& lib);
~NzDynLib();
NzString GetLastError() const; class DynLibImpl;
NzDynLibFunc GetSymbol(const NzString& symbol) const;
bool IsLoaded() const; class NAZARA_CORE_API DynLib
{
public:
DynLib();
DynLib(const DynLib&) = delete;
DynLib(DynLib&& lib);
~DynLib();
bool Load(const NzString& libraryPath); String GetLastError() const;
void Unload(); DynLibFunc GetSymbol(const String& symbol) const;
NzDynLib& operator=(NzDynLib&& lib); bool IsLoaded() const;
private: bool Load(const String& libraryPath);
NazaraMutexAttrib(m_mutex, mutable) void Unload();
mutable NzString m_lastError; DynLib& operator=(const DynLib&) = delete;
NzDynLibImpl* m_impl; DynLib& operator=(DynLib&& lib);
private:
NazaraMutexAttrib(m_mutex, mutable)
mutable String m_lastError;
DynLibImpl* m_impl;
}; };
}
#endif // NAZARA_DYNLIB_HPP #endif // NAZARA_DYNLIB_HPP

View File

@ -25,8 +25,11 @@
#error You cannot define both NAZARA_BIG_ENDIAN and NAZARA_LITTLE_ENDIAN #error You cannot define both NAZARA_BIG_ENDIAN and NAZARA_LITTLE_ENDIAN
#endif #endif
inline void NzByteSwap(void* buffer, unsigned int size); namespace Nz
inline nzEndianness NzGetPlatformEndianness(); {
inline Endianness GetPlatformEndianness();
inline void SwapBytes(void* buffer, unsigned int size);
}
#include <Nazara/Core/Endianness.inl> #include <Nazara/Core/Endianness.inl>

View File

@ -5,23 +5,26 @@
#include <algorithm> #include <algorithm>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
inline void NzByteSwap(void* buffer, unsigned int size) namespace Nz
{ {
nzUInt8* bytes = reinterpret_cast<nzUInt8*>(buffer); inline Endianness GetPlatformEndianness()
unsigned int i = 0; {
unsigned int j = size-1; #if defined(NAZARA_BIG_ENDIAN)
return Endianness_BigEndian;
#elif defined(NAZARA_LITTLE_ENDIAN)
return Endianness_LittleEndian;
#endif
}
while (i < j) inline void SwapBytes(void* buffer, unsigned int size)
std::swap(bytes[i++], bytes[j--]); {
} UInt8* bytes = reinterpret_cast<UInt8*>(buffer);
unsigned int i = 0;
unsigned int j = size-1;
inline nzEndianness NzGetPlatformEndianness() while (i < j)
{ std::swap(bytes[i++], bytes[j--]);
#if defined(NAZARA_BIG_ENDIAN) }
return nzEndianness_BigEndian;
#elif defined(NAZARA_LITTLE_ENDIAN)
return nzEndianness_LittleEndian;
#endif
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

View File

@ -7,182 +7,185 @@
#ifndef NAZARA_ENUMS_CORE_HPP #ifndef NAZARA_ENUMS_CORE_HPP
#define NAZARA_ENUMS_CORE_HPP #define NAZARA_ENUMS_CORE_HPP
enum nzCoordSys namespace Nz
{ {
nzCoordSys_Global, enum CoordSys
nzCoordSys_Local, {
CoordSys_Global,
CoordSys_Local,
nzCoordSys_Max = nzCoordSys_Local CoordSys_Max = CoordSys_Local
}; };
enum nzCursorPosition enum CursorPosition
{ {
nzCursorPosition_AtBegin, // Début du fichier CursorPosition_AtBegin, // Début du fichier
nzCursorPosition_AtCurrent, // Position du pointeur CursorPosition_AtCurrent, // Position du pointeur
nzCursorPosition_AtEnd, // Fin du fichier CursorPosition_AtEnd, // Fin du fichier
nzCursorPosition_Max = nzCursorPosition_AtEnd CursorPosition_Max = CursorPosition_AtEnd
}; };
enum nzEndianness enum Endianness
{ {
nzEndianness_Unknown = -1, Endianness_Unknown = -1,
nzEndianness_BigEndian, Endianness_BigEndian,
nzEndianness_LittleEndian, Endianness_LittleEndian,
nzEndianness_Max = nzEndianness_LittleEndian Endianness_Max = Endianness_LittleEndian
}; };
enum nzErrorFlag enum ErrorFlag
{ {
nzErrorFlag_None = 0, ErrorFlag_None = 0,
nzErrorFlag_Silent = 0x1, ErrorFlag_Silent = 0x1,
nzErrorFlag_SilentDisabled = 0x2, ErrorFlag_SilentDisabled = 0x2,
nzErrorFlag_ThrowException = 0x4, ErrorFlag_ThrowException = 0x4,
nzErrorFlag_ThrowExceptionDisabled = 0x8, ErrorFlag_ThrowExceptionDisabled = 0x8,
nzErrorFlag_Max = nzErrorFlag_ThrowExceptionDisabled*2-1 ErrorFlag_Max = ErrorFlag_ThrowExceptionDisabled*2-1
}; };
enum nzErrorType enum ErrorType
{ {
nzErrorType_AssertFailed, ErrorType_AssertFailed,
nzErrorType_Internal, ErrorType_Internal,
nzErrorType_Normal, ErrorType_Normal,
nzErrorType_Warning, ErrorType_Warning,
nzErrorType_Max = nzErrorType_Warning ErrorType_Max = ErrorType_Warning
}; };
enum nzHash enum HashType
{ {
nzHash_CRC32, HashType_CRC32,
nzHash_Fletcher16, HashType_Fletcher16,
nzHash_MD5, HashType_MD5,
nzHash_SHA1, HashType_SHA1,
nzHash_SHA224, HashType_SHA224,
nzHash_SHA256, HashType_SHA256,
nzHash_SHA384, HashType_SHA384,
nzHash_SHA512, HashType_SHA512,
nzHash_Whirlpool, HashType_Whirlpool,
nzHash_Max = nzHash_Whirlpool HashType_Max = HashType_Whirlpool
}; };
enum nzOpenModeFlags enum OpenModeFlags
{ {
nzOpenMode_Current = 0x00, // Utilise le mode d'ouverture actuel OpenMode_Current = 0x00, // Utilise le mode d'ouverture actuel
nzOpenMode_Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin OpenMode_Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
nzOpenMode_Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert OpenMode_Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
nzOpenMode_ReadOnly = 0x04, // Ouvre uniquement en lecture OpenMode_ReadOnly = 0x04, // Ouvre uniquement en lecture
nzOpenMode_ReadWrite = 0x08, // Ouvre en lecture/écriture OpenMode_ReadWrite = 0x08, // Ouvre en lecture/écriture
nzOpenMode_Text = 0x10, // Ouvre en mode texte OpenMode_Text = 0x10, // Ouvre en mode texte
nzOpenMode_Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe OpenMode_Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe
nzOpenMode_WriteOnly = 0x40, // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas OpenMode_WriteOnly = 0x40, // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas
nzOpenMode_Max = nzOpenMode_WriteOnly OpenMode_Max = OpenMode_WriteOnly
}; };
enum nzParameterType enum ParameterType
{ {
nzParameterType_Boolean, ParameterType_Boolean,
nzParameterType_Float, ParameterType_Float,
nzParameterType_Integer, ParameterType_Integer,
nzParameterType_None, ParameterType_None,
nzParameterType_Pointer, ParameterType_Pointer,
nzParameterType_String, ParameterType_String,
nzParameterType_Userdata, ParameterType_Userdata,
nzParameterType_Max = nzParameterType_Userdata ParameterType_Max = ParameterType_Userdata
}; };
enum nzPlugin enum Plugin
{ {
nzPlugin_Assimp, Plugin_Assimp,
nzPlugin_FreeType Plugin_FreeType
}; };
enum nzPrimitiveType enum PrimitiveType
{ {
nzPrimitiveType_Box, PrimitiveType_Box,
nzPrimitiveType_Cone, PrimitiveType_Cone,
nzPrimitiveType_Plane, PrimitiveType_Plane,
nzPrimitiveType_Sphere, PrimitiveType_Sphere,
nzPrimitiveType_Max = nzPrimitiveType_Sphere PrimitiveType_Max = PrimitiveType_Sphere
}; };
enum nzProcessorCap enum ProcessorCap
{ {
nzProcessorCap_x64, ProcessorCap_x64,
nzProcessorCap_AVX, ProcessorCap_AVX,
nzProcessorCap_FMA3, ProcessorCap_FMA3,
nzProcessorCap_FMA4, ProcessorCap_FMA4,
nzProcessorCap_MMX, ProcessorCap_MMX,
nzProcessorCap_XOP, ProcessorCap_XOP,
nzProcessorCap_SSE, ProcessorCap_SSE,
nzProcessorCap_SSE2, ProcessorCap_SSE2,
nzProcessorCap_SSE3, ProcessorCap_SSE3,
nzProcessorCap_SSSE3, ProcessorCap_SSSE3,
nzProcessorCap_SSE41, ProcessorCap_SSE41,
nzProcessorCap_SSE42, ProcessorCap_SSE42,
nzProcessorCap_SSE4a, ProcessorCap_SSE4a,
nzProcessorCap_Max = nzProcessorCap_SSE4a ProcessorCap_Max = ProcessorCap_SSE4a
}; };
enum nzProcessorVendor enum ProcessorVendor
{ {
nzProcessorVendor_Unknown = -1, ProcessorVendor_Unknown = -1,
nzProcessorVendor_AMD, ProcessorVendor_AMD,
nzProcessorVendor_Centaur, ProcessorVendor_Centaur,
nzProcessorVendor_Cyrix, ProcessorVendor_Cyrix,
nzProcessorVendor_Intel, ProcessorVendor_Intel,
nzProcessorVendor_KVM, ProcessorVendor_KVM,
nzProcessorVendor_HyperV, ProcessorVendor_HyperV,
nzProcessorVendor_NSC, ProcessorVendor_NSC,
nzProcessorVendor_NexGen, ProcessorVendor_NexGen,
nzProcessorVendor_Rise, ProcessorVendor_Rise,
nzProcessorVendor_SIS, ProcessorVendor_SIS,
nzProcessorVendor_Transmeta, ProcessorVendor_Transmeta,
nzProcessorVendor_UMC, ProcessorVendor_UMC,
nzProcessorVendor_VIA, ProcessorVendor_VIA,
nzProcessorVendor_VMware, ProcessorVendor_VMware,
nzProcessorVendor_Vortex, ProcessorVendor_Vortex,
nzProcessorVendor_XenHVM, ProcessorVendor_XenHVM,
nzProcessorVendor_Max = nzProcessorVendor_XenHVM ProcessorVendor_Max = ProcessorVendor_XenHVM
}; };
enum nzSphereType enum SphereType
{ {
nzSphereType_Cubic, SphereType_Cubic,
nzSphereType_Ico, SphereType_Ico,
nzSphereType_UV, SphereType_UV,
nzSphereType_Max = nzSphereType_UV SphereType_Max = SphereType_UV
}; };
enum nzStreamOptionFlags enum StreamOptionFlags
{ {
nzStreamOption_None = 0, StreamOption_None = 0,
nzStreamOption_Text = 0x1, StreamOption_Text = 0x1,
nzStreamOption_Max = nzStreamOption_Text*2-1 StreamOption_Max = StreamOption_Text*2-1
}; };
enum nzTernary enum Ternary
{ {
nzTernary_False, Ternary_False,
nzTernary_True, Ternary_True,
nzTernary_Unknown, Ternary_Unknown,
nzTernary_Max = nzTernary_Unknown Ternary_Max = Ternary_Unknown
}; };
}
#endif // NAZARA_ENUMS_CORE_HPP #endif // NAZARA_ENUMS_CORE_HPP

View File

@ -14,37 +14,40 @@
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG) #if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG)
#define NazaraAssert(a, err) if (!(a)) NzError::Error(nzErrorType_AssertFailed, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION) #define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#else #else
#define NazaraAssert(a, err) #define NazaraAssert(a, err)
#endif #endif
#define NazaraError(err) NzError::Error(nzErrorType_Normal, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION) #define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType_Normal, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#define NazaraInternalError(err) NzError::Error(nzErrorType_Internal, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION) #define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType_Internal, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#define NazaraWarning(err) NzError::Error(nzErrorType_Warning, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION) #define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType_Warning, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
class NAZARA_CORE_API NzError namespace Nz
{ {
public: class NAZARA_CORE_API Error
NzError() = delete; {
~NzError() = delete; public:
Error() = delete;
~Error() = delete;
static void Error(nzErrorType type, const NzString& error); static UInt32 GetFlags();
static void Error(nzErrorType type, const NzString& error, unsigned int line, const char* file, const char* function); static String GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr);
static unsigned int GetLastSystemErrorCode();
static String GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
static nzUInt32 GetFlags(); static void SetFlags(UInt32 flags);
static NzString GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr);
static unsigned int GetLastSystemErrorCode();
static NzString GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
static void SetFlags(nzUInt32 flags); static void Trigger(ErrorType type, const String& error);
static void Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function);
private: private:
static nzUInt32 s_flags; static UInt32 s_flags;
static NzString s_lastError; static String s_lastError;
static const char* s_lastErrorFunction; static const char* s_lastErrorFunction;
static const char* s_lastErrorFile; static const char* s_lastErrorFile;
static unsigned int s_lastErrorLine; static unsigned int s_lastErrorLine;
}; };
}
#endif // NAZARA_ERROR_HPP #endif // NAZARA_ERROR_HPP

View File

@ -9,20 +9,27 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Enums.hpp> #include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/NonCopyable.hpp>
class NAZARA_CORE_API NzErrorFlags : NzNonCopyable namespace Nz
{ {
public: class NAZARA_CORE_API ErrorFlags
NzErrorFlags(nzUInt32 flags, bool replace = false); {
~NzErrorFlags(); public:
ErrorFlags(UInt32 flags, bool replace = false);
ErrorFlags(const ErrorFlags&) = delete;
ErrorFlags(ErrorFlags&&) = delete;
~ErrorFlags();
nzUInt32 GetPreviousFlags() const; UInt32 GetPreviousFlags() const;
void SetFlags(nzUInt32 flags, bool replace = false); void SetFlags(UInt32 flags, bool replace = false);
private: ErrorFlags& operator=(const ErrorFlags&) = delete;
nzUInt32 m_previousFlags; ErrorFlags& operator=(ErrorFlags&&) = delete;
};
private:
UInt32 m_previousFlags;
};
}
#endif // NAZARA_ERRORFLAGS_HPP #endif // NAZARA_ERRORFLAGS_HPP

View File

@ -14,7 +14,6 @@
#include <Nazara/Core/Hashable.hpp> #include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/InputStream.hpp> #include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE #if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE
@ -25,85 +24,90 @@
#include <ctime> #include <ctime>
class NzFileImpl; namespace Nz
class NAZARA_CORE_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable
{ {
public: class FileImpl;
NzFile();
NzFile(const NzString& filePath);
NzFile(const NzString& filePath, unsigned int openMode);
NzFile(NzFile&& file) noexcept;
~NzFile();
bool Copy(const NzString& newFilePath); class NAZARA_CORE_API File : public Hashable, public InputStream
void Close(); {
public:
File();
File(const String& filePath);
File(const String& filePath, unsigned int openMode);
File(const File&) = delete;
File(File&& file) noexcept;
~File();
bool Delete(); bool Copy(const String& newFilePath);
void Close();
bool EndOfFile() const; bool Delete();
bool EndOfStream() const;
bool Exists() const; bool EndOfFile() const;
bool EndOfStream() const;
void Flush(); bool Exists() const;
time_t GetCreationTime() const; void Flush();
nzUInt64 GetCursorPos() const;
NzString GetDirectory() const;
NzString GetFileName() const;
time_t GetLastAccessTime() const;
time_t GetLastWriteTime() const;
NzString GetPath() const;
nzUInt64 GetSize() const;
bool IsOpen() const; time_t GetCreationTime() const;
UInt64 GetCursorPos() const;
String GetDirectory() const;
String GetFileName() const;
time_t GetLastAccessTime() const;
time_t GetLastWriteTime() const;
String GetPath() const;
UInt64 GetSize() const;
bool Open(unsigned int openMode = nzOpenMode_Current); bool IsOpen() const;
bool Open(const NzString& filePath, unsigned int openMode = nzOpenMode_Current);
std::size_t Read(void* buffer, std::size_t size); bool Open(unsigned int openMode = OpenMode_Current);
std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count); bool Open(const String& filePath, unsigned int openMode = OpenMode_Current);
bool Rename(const NzString& newFilePath);
bool SetCursorPos(nzCursorPosition pos, nzInt64 offset = 0); std::size_t Read(void* buffer, std::size_t size);
bool SetCursorPos(nzUInt64 offset); std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count);
void SetEndianness(nzEndianness endianness); bool Rename(const String& newFilePath);
bool SetFile(const NzString& filePath);
bool SetOpenMode(unsigned int openMode);
bool Write(const NzByteArray& byteArray); bool SetCursorPos(CursorPosition pos, Int64 offset = 0);
bool Write(const NzString& string); bool SetCursorPos(UInt64 offset);
std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count); void SetEndianness(Endianness endianness);
bool SetFile(const String& filePath);
bool SetOpenMode(unsigned int openMode);
NzFile& operator=(const NzString& filePath); bool Write(const Nz::ByteArray& byteArray);
NzFile& operator=(NzFile&& file) noexcept; bool Write(const String& string);
std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count);
static NzString AbsolutePath(const NzString& filePath); File& operator=(const String& filePath);
static bool Copy(const NzString& sourcePath, const NzString& targetPath); File& operator=(const File&) = delete;
static bool Delete(const NzString& filePath); File& operator=(File&& file) noexcept;
static bool Exists(const NzString& filePath);
static time_t GetCreationTime(const NzString& filePath);
static NzString GetDirectory(const NzString& filePath);
static time_t GetLastAccessTime(const NzString& filePath);
static time_t GetLastWriteTime(const NzString& filePath);
static NzHashDigest GetHash(const NzString& filePath, nzHash hash);
static NzHashDigest GetHash(const NzString& filePath, NzAbstractHash* hash);
static nzUInt64 GetSize(const NzString& filePath);
static bool IsAbsolute(const NzString& filePath);
static NzString NormalizePath(const NzString& filePath);
static NzString NormalizeSeparators(const NzString& filePath);
static bool Rename(const NzString& sourcePath, const NzString& targetPath);
private: static String AbsolutePath(const String& filePath);
bool FillHash(NzAbstractHash* hash) const; static bool Copy(const String& sourcePath, const String& targetPath);
static bool Delete(const String& filePath);
static bool Exists(const String& filePath);
static time_t GetCreationTime(const String& filePath);
static String GetDirectory(const String& filePath);
static time_t GetLastAccessTime(const String& filePath);
static time_t GetLastWriteTime(const String& filePath);
static HashDigest GetHash(const String& filePath, HashType hash);
static HashDigest GetHash(const String& filePath, AbstractHash* hash);
static UInt64 GetSize(const String& filePath);
static bool IsAbsolute(const String& filePath);
static String NormalizePath(const String& filePath);
static String NormalizeSeparators(const String& filePath);
static bool Rename(const String& sourcePath, const String& targetPath);
NazaraMutexAttrib(m_mutex, mutable) private:
bool FillHash(AbstractHash* hash) const;
nzEndianness m_endianness; NazaraMutexAttrib(m_mutex, mutable)
NzString m_filePath;
NzFileImpl* m_impl; Endianness m_endianness;
unsigned int m_openMode; String m_filePath;
}; FileImpl* m_impl;
unsigned int m_openMode;
};
}
#endif // NAZARA_FILE_HPP #endif // NAZARA_FILE_HPP

View File

@ -11,47 +11,50 @@
// Inspiré du code de la SFML par Laurent Gomila // Inspiré du code de la SFML par Laurent Gomila
struct NzFunctor namespace Nz
{ {
virtual ~NzFunctor() {} struct Functor
{
virtual ~Functor() {}
virtual void Run() = 0; virtual void Run() = 0;
}; };
template<typename F> template<typename F>
struct NzFunctorWithoutArgs : NzFunctor struct FunctorWithoutArgs : Functor
{ {
NzFunctorWithoutArgs(F func); FunctorWithoutArgs(F func);
void Run(); void Run();
private: private:
F m_func; F m_func;
}; };
template<typename F, typename... Args> template<typename F, typename... Args>
struct NzFunctorWithArgs : NzFunctor struct FunctorWithArgs : Functor
{ {
NzFunctorWithArgs(F func, Args&&... args); FunctorWithArgs(F func, Args&&... args);
void Run(); void Run();
private: private:
F m_func; F m_func;
std::tuple<Args...> m_args; std::tuple<Args...> m_args;
}; };
template<typename C> template<typename C>
struct NzMemberWithoutArgs : NzFunctor struct MemberWithoutArgs : Functor
{ {
NzMemberWithoutArgs(void (C::*func)(), C* object); MemberWithoutArgs(void (C::*func)(), C* object);
void Run(); void Run();
private: private:
void (C::*m_func)(); void (C::*m_func)();
C* m_object; C* m_object;
}; };
}
#include <Nazara/Core/Functor.inl> #include <Nazara/Core/Functor.inl>

View File

@ -4,41 +4,44 @@
#include <utility> #include <utility>
template<typename F> namespace Nz
NzFunctorWithoutArgs<F>::NzFunctorWithoutArgs(F func) :
m_func(func)
{ {
} template<typename F>
FunctorWithoutArgs<F>::FunctorWithoutArgs(F func) :
m_func(func)
{
}
template<typename F> template<typename F>
void NzFunctorWithoutArgs<F>::Run() void FunctorWithoutArgs<F>::Run()
{ {
m_func(); m_func();
} }
template<typename F, typename... Args> template<typename F, typename... Args>
NzFunctorWithArgs<F, Args...>::NzFunctorWithArgs(F func, Args&&... args) : FunctorWithArgs<F, Args...>::FunctorWithArgs(F func, Args&&... args) :
m_func(func), m_func(func),
m_args(std::forward<Args>(args)...) m_args(std::forward<Args>(args)...)
{ {
} }
template<typename F, typename... Args> template<typename F, typename... Args>
void NzFunctorWithArgs<F, Args...>::Run() void FunctorWithArgs<F, Args...>::Run()
{ {
NzApply(m_func, m_args); Apply(m_func, m_args);
} }
template<typename C> template<typename C>
NzMemberWithoutArgs<C>::NzMemberWithoutArgs(void (C::*func)(), C* object) : MemberWithoutArgs<C>::MemberWithoutArgs(void (C::*func)(), C* object) :
m_func(func), m_func(func),
m_object(object) m_object(object)
{ {
} }
template<typename C> template<typename C>
void NzMemberWithoutArgs<C>::Run() void MemberWithoutArgs<C>::Run()
{ {
(m_object->*m_func)(); (m_object->*m_func)();
}
} }

View File

@ -15,74 +15,77 @@
#include <Nazara/Math/Rect.hpp> #include <Nazara/Math/Rect.hpp>
#include <vector> #include <vector>
class NAZARA_CORE_API NzGuillotineBinPack namespace Nz
{ {
public: class NAZARA_CORE_API GuillotineBinPack
enum FreeRectChoiceHeuristic : int; {
enum GuillotineSplitHeuristic : int; public:
enum FreeRectChoiceHeuristic : int;
enum GuillotineSplitHeuristic : int;
NzGuillotineBinPack(); GuillotineBinPack();
NzGuillotineBinPack(unsigned int width, unsigned int height); GuillotineBinPack(unsigned int width, unsigned int height);
NzGuillotineBinPack(const NzVector2ui& size); GuillotineBinPack(const Vector2ui& size);
NzGuillotineBinPack(const NzGuillotineBinPack&) = default; GuillotineBinPack(const GuillotineBinPack&) = default;
NzGuillotineBinPack(NzGuillotineBinPack&&) = default; GuillotineBinPack(GuillotineBinPack&&) = default;
~NzGuillotineBinPack() = default; ~GuillotineBinPack() = default;
void Clear(); void Clear();
void Expand(unsigned int newWidth, unsigned newHeight); void Expand(unsigned int newWidth, unsigned newHeight);
void Expand(const NzVector2ui& newSize); void Expand(const Vector2ui& newSize);
void FreeRectangle(const NzRectui& rect); void FreeRectangle(const Rectui& rect);
unsigned int GetHeight() const; unsigned int GetHeight() const;
float GetOccupancy() const; float GetOccupancy() const;
NzVector2ui GetSize() const; Vector2ui GetSize() const;
unsigned int GetWidth() const; unsigned int GetWidth() const;
bool Insert(NzRectui* rects, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod); bool Insert(Rectui* rects, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod);
bool Insert(NzRectui* rects, bool* flipped, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod); bool Insert(Rectui* rects, bool* flipped, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod);
bool Insert(NzRectui* rects, bool* flipped, bool* inserted, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod); bool Insert(Rectui* rects, bool* flipped, bool* inserted, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod);
bool MergeFreeRectangles(); bool MergeFreeRectangles();
void Reset(); void Reset();
void Reset(unsigned int width, unsigned int height); void Reset(unsigned int width, unsigned int height);
void Reset(const NzVector2ui& size); void Reset(const Vector2ui& size);
NzGuillotineBinPack& operator=(const NzGuillotineBinPack&) = default; GuillotineBinPack& operator=(const GuillotineBinPack&) = default;
NzGuillotineBinPack& operator=(NzGuillotineBinPack&&) = default; GuillotineBinPack& operator=(GuillotineBinPack&&) = default;
enum FreeRectChoiceHeuristic : int enum FreeRectChoiceHeuristic : int
{ {
RectBestAreaFit, RectBestAreaFit,
RectBestLongSideFit, RectBestLongSideFit,
RectBestShortSideFit, RectBestShortSideFit,
RectWorstAreaFit, RectWorstAreaFit,
RectWorstLongSideFit, RectWorstLongSideFit,
RectWorstShortSideFit RectWorstShortSideFit
}; };
enum GuillotineSplitHeuristic : int enum GuillotineSplitHeuristic : int
{ {
SplitLongerAxis, SplitLongerAxis,
SplitLongerLeftoverAxis, SplitLongerLeftoverAxis,
SplitMaximizeArea, SplitMaximizeArea,
SplitMinimizeArea, SplitMinimizeArea,
SplitShorterAxis, SplitShorterAxis,
SplitShorterLeftoverAxis SplitShorterLeftoverAxis
}; };
private: private:
void SplitFreeRectAlongAxis(const NzRectui& freeRect, const NzRectui& placedRect, bool splitHorizontal); void SplitFreeRectAlongAxis(const Rectui& freeRect, const Rectui& placedRect, bool splitHorizontal);
void SplitFreeRectByHeuristic(const NzRectui& freeRect, const NzRectui& placedRect, GuillotineSplitHeuristic method); void SplitFreeRectByHeuristic(const Rectui& freeRect, const Rectui& placedRect, GuillotineSplitHeuristic method);
static int ScoreByHeuristic(int width, int height, const NzRectui& freeRect, FreeRectChoiceHeuristic rectChoice); static int ScoreByHeuristic(int width, int height, const Rectui& freeRect, FreeRectChoiceHeuristic rectChoice);
std::vector<NzRectui> m_freeRectangles; std::vector<Rectui> m_freeRectangles;
unsigned int m_height; unsigned int m_height;
unsigned int m_usedArea; unsigned int m_usedArea;
unsigned int m_width; unsigned int m_width;
}; };
}
#endif // NAZARA_GUILLOTINEBINPACK_HPP #endif // NAZARA_GUILLOTINEBINPACK_HPP

View File

@ -11,25 +11,31 @@
#include <Nazara/Core/Enums.hpp> #include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
class NAZARA_CORE_API NzHardwareInfo namespace Nz
{ {
public: class NAZARA_CORE_API HardwareInfo
static void Cpuid(nzUInt32 functionId, nzUInt32 subFunctionId, nzUInt32 result[4]); {
public:
HardwareInfo() = delete;
~HardwareInfo() = delete;
static NzString GetProcessorBrandString(); static void Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 result[4]);
static unsigned int GetProcessorCount();
static nzProcessorVendor GetProcessorVendor();
static NzString GetProcessorVendorName();
static nzUInt64 GetTotalMemory();
static bool HasCapability(nzProcessorCap capability); static String GetProcessorBrandString();
static unsigned int GetProcessorCount();
static ProcessorVendor GetProcessorVendor();
static String GetProcessorVendorName();
static UInt64 GetTotalMemory();
static bool Initialize(); static bool HasCapability(ProcessorCap capability);
static bool IsCpuidSupported(); static bool Initialize();
static bool IsInitialized();
static void Uninitialize(); static bool IsCpuidSupported();
}; static bool IsInitialized();
static void Uninitialize();
};
}
#endif // NAZARA_HARDWAREINFO_HPP #endif // NAZARA_HARDWAREINFO_HPP

View File

@ -11,19 +11,26 @@
#include <Nazara/Core/AbstractHash.hpp> #include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/Hashable.hpp> #include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/NonCopyable.hpp>
class NAZARA_CORE_API NzHash : NzNonCopyable namespace Nz
{ {
public: class NAZARA_CORE_API Hash
NzHash(nzHash hash); {
NzHash(NzAbstractHash* hashImpl); public:
~NzHash(); Hash(HashType hash);
Hash(AbstractHash* hashImpl);
Hash(const Hash&) = delete;
Hash(Hash&&) = delete; ///TODO
~Hash();
NzHashDigest Hash(const NzHashable& hashable); HashDigest Process(const Hashable& hashable);
private: Hash& operator=(const Hash&) = delete;
NzAbstractHash* m_impl; Hash& operator=(Hash&&) = delete; ///TODO
};
private:
AbstractHash* m_impl;
};
}
#endif // NAZARA_HASH_HPP #endif // NAZARA_HASH_HPP

View File

@ -11,23 +11,26 @@
#include <Nazara/Core/AbstractHash.hpp> #include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
struct NzHashCRC32_state; namespace Nz
class NAZARA_CORE_API NzHashCRC32 : public NzAbstractHash
{ {
public: struct HashCRC32_state;
NzHashCRC32(nzUInt32 polynomial = 0x04c11db7);
virtual ~NzHashCRC32();
void Append(const nzUInt8* data, unsigned int len); class NAZARA_CORE_API HashCRC32 : public AbstractHash
void Begin(); {
NzHashDigest End(); public:
HashCRC32(UInt32 polynomial = 0x04c11db7);
virtual ~HashCRC32();
static unsigned int GetDigestLength(); void Append(const UInt8* data, unsigned int len);
static NzString GetHashName(); void Begin();
HashDigest End();
private: static unsigned int GetDigestLength();
NzHashCRC32_state* m_state; static String GetHashName();
};
private:
HashCRC32_state* m_state;
};
}
#endif // NAZARA_HASH_CRC32_HPP #endif // NAZARA_HASH_CRC32_HPP

View File

@ -12,23 +12,26 @@
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
struct NzHashFletcher16_state; namespace Nz
class NAZARA_CORE_API NzHashFletcher16 : public NzAbstractHash
{ {
public: struct HashFletcher16_state;
NzHashFletcher16();
virtual ~NzHashFletcher16();
void Append(const nzUInt8* data, unsigned int len); class NAZARA_CORE_API HashFletcher16 : public AbstractHash
void Begin(); {
NzHashDigest End(); public:
HashFletcher16();
virtual ~HashFletcher16();
static unsigned int GetDigestLength(); void Append(const UInt8* data, unsigned int len);
static NzString GetHashName(); void Begin();
HashDigest End();
private: static unsigned int GetDigestLength();
NzHashFletcher16_state* m_state; static String GetHashName();
};
private:
HashFletcher16_state* m_state;
};
}
#endif // NAZARA_HASH_FLETCHER16_HPP #endif // NAZARA_HASH_FLETCHER16_HPP

View File

@ -11,23 +11,26 @@
#include <Nazara/Core/AbstractHash.hpp> #include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
struct NzHashMD5_state; namespace Nz
class NAZARA_CORE_API NzHashMD5 : public NzAbstractHash
{ {
public: struct HashMD5_state;
NzHashMD5();
virtual ~NzHashMD5();
void Append(const nzUInt8* data, unsigned int len); class NAZARA_CORE_API HashMD5 : public AbstractHash
void Begin(); {
NzHashDigest End(); public:
HashMD5();
virtual ~HashMD5();
static unsigned int GetDigestLength(); void Append(const UInt8* data, unsigned int len);
static NzString GetHashName(); void Begin();
HashDigest End();
private: static unsigned int GetDigestLength();
NzHashMD5_state* m_state; static String GetHashName();
};
private:
HashMD5_state* m_state;
};
}
#endif // NAZARA_HASH_MD5_HPP #endif // NAZARA_HASH_MD5_HPP

View File

@ -11,23 +11,26 @@
#include <Nazara/Core/AbstractHash.hpp> #include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
union SHA_CTX; namespace Nz
class NAZARA_CORE_API NzHashSHA1 : public NzAbstractHash
{ {
public: union SHA_CTX;
NzHashSHA1();
virtual ~NzHashSHA1();
void Append(const nzUInt8* data, unsigned int len); class NAZARA_CORE_API HashSHA1 : public AbstractHash
void Begin(); {
NzHashDigest End(); public:
HashSHA1();
virtual ~HashSHA1();
static unsigned int GetDigestLength(); void Append(const UInt8* data, unsigned int len);
static NzString GetHashName(); void Begin();
HashDigest End();
private: static unsigned int GetDigestLength();
SHA_CTX* m_state; static String GetHashName();
};
private:
SHA_CTX* m_state;
};
}
#endif // NAZARA_HASH_SHA1_HPP #endif // NAZARA_HASH_SHA1_HPP

View File

@ -11,23 +11,26 @@
#include <Nazara/Core/AbstractHash.hpp> #include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
union SHA_CTX; namespace Nz
class NAZARA_CORE_API NzHashSHA224 : public NzAbstractHash
{ {
public: union SHA_CTX;
NzHashSHA224();
virtual ~NzHashSHA224();
void Append(const nzUInt8* data, unsigned int len); class NAZARA_CORE_API HashSHA224 : public AbstractHash
void Begin(); {
NzHashDigest End(); public:
HashSHA224();
virtual ~HashSHA224();
static unsigned int GetDigestLength(); void Append(const UInt8* data, unsigned int len);
static NzString GetHashName(); void Begin();
HashDigest End();
private: static unsigned int GetDigestLength();
SHA_CTX* m_state; static String GetHashName();
};
private:
SHA_CTX* m_state;
};
}
#endif // NAZARA_HASH_SHA224_HPP #endif // NAZARA_HASH_SHA224_HPP

View File

@ -11,23 +11,26 @@
#include <Nazara/Core/AbstractHash.hpp> #include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
union SHA_CTX; namespace Nz
class NAZARA_CORE_API NzHashSHA256 : public NzAbstractHash
{ {
public: union SHA_CTX;
NzHashSHA256();
virtual ~NzHashSHA256();
void Append(const nzUInt8* data, unsigned int len); class NAZARA_CORE_API HashSHA256 : public AbstractHash
void Begin(); {
NzHashDigest End(); public:
HashSHA256();
virtual ~HashSHA256();
static unsigned int GetDigestLength(); void Append(const UInt8* data, unsigned int len);
static NzString GetHashName(); void Begin();
HashDigest End();
private: static unsigned int GetDigestLength();
SHA_CTX* m_state; static String GetHashName();
};
private:
SHA_CTX* m_state;
};
}
#endif // NAZARA_HASH_SHA256_HPP #endif // NAZARA_HASH_SHA256_HPP

View File

@ -11,23 +11,26 @@
#include <Nazara/Core/AbstractHash.hpp> #include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
union SHA_CTX; namespace Nz
class NAZARA_CORE_API NzHashSHA384 : public NzAbstractHash
{ {
public: union SHA_CTX;
NzHashSHA384();
virtual ~NzHashSHA384();
void Append(const nzUInt8* data, unsigned int len); class NAZARA_CORE_API HashSHA384 : public AbstractHash
void Begin(); {
NzHashDigest End(); public:
HashSHA384();
virtual ~HashSHA384();
static unsigned int GetDigestLength(); void Append(const UInt8* data, unsigned int len);
static NzString GetHashName(); void Begin();
HashDigest End();
private: static unsigned int GetDigestLength();
SHA_CTX* m_state; static String GetHashName();
};
private:
SHA_CTX* m_state;
};
}
#endif // NAZARA_HASH_SHA384_HPP #endif // NAZARA_HASH_SHA384_HPP

View File

@ -11,23 +11,26 @@
#include <Nazara/Core/AbstractHash.hpp> #include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
union SHA_CTX; namespace Nz
class NAZARA_CORE_API NzHashSHA512 : public NzAbstractHash
{ {
public: union SHA_CTX;
NzHashSHA512();
virtual ~NzHashSHA512();
void Append(const nzUInt8* data, unsigned int len); class NAZARA_CORE_API HashSHA512 : public AbstractHash
void Begin(); {
NzHashDigest End(); public:
HashSHA512();
virtual ~HashSHA512();
static unsigned int GetDigestLength(); void Append(const UInt8* data, unsigned int len);
static NzString GetHashName(); void Begin();
HashDigest End();
private: static unsigned int GetDigestLength();
SHA_CTX* m_state; static String GetHashName();
};
private:
SHA_CTX* m_state;
};
}
#endif // NAZARA_HASH_SHA512_HPP #endif // NAZARA_HASH_SHA512_HPP

View File

@ -9,23 +9,26 @@
#include <Nazara/Core/AbstractHash.hpp> #include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
struct NzHashWhirlpool_state; namespace Nz
class NAZARA_CORE_API NzHashWhirlpool : public NzAbstractHash
{ {
public: struct HashWhirlpool_state;
NzHashWhirlpool();
virtual ~NzHashWhirlpool();
void Append(const nzUInt8* data, unsigned int len); class NAZARA_CORE_API HashWhirlpool : public AbstractHash
void Begin(); {
NzHashDigest End(); public:
HashWhirlpool();
virtual ~HashWhirlpool();
static unsigned int GetDigestLength(); void Append(const UInt8* data, unsigned int len);
static NzString GetHashName(); void Begin();
HashDigest End();
private: static unsigned int GetDigestLength();
NzHashWhirlpool_state* m_state; static String GetHashName();
};
private:
HashWhirlpool_state* m_state;
};
}
#endif // NAZARA_HASH_WHIRLPOOL_HPP #endif // NAZARA_HASH_WHIRLPOOL_HPP

View File

@ -13,41 +13,44 @@
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <iosfwd> #include <iosfwd>
class NAZARA_CORE_API NzHashDigest namespace Nz
{ {
public: class NAZARA_CORE_API HashDigest
NzHashDigest(); {
NzHashDigest(const NzString& hashName, const nzUInt8* digest, unsigned int length); public:
NzHashDigest(const NzHashDigest& rhs); HashDigest();
NzHashDigest(NzHashDigest&& rhs) noexcept; HashDigest(const String& hashName, const UInt8* digest, unsigned int length);
~NzHashDigest(); HashDigest(const HashDigest& rhs);
HashDigest(HashDigest&& rhs) noexcept;
~HashDigest();
bool IsValid() const; bool IsValid() const;
const nzUInt8* GetDigest() const; const UInt8* GetDigest() const;
unsigned int GetDigestLength() const; unsigned int GetDigestLength() const;
NzString GetHashName() const; String GetHashName() const;
NzString ToHex() const; String ToHex() const;
nzUInt8 operator[](unsigned int pos) const; UInt8 operator[](unsigned int pos) const;
NzHashDigest& operator=(const NzHashDigest& rhs); HashDigest& operator=(const HashDigest& rhs);
NzHashDigest& operator=(NzHashDigest&& rhs) noexcept; HashDigest& operator=(HashDigest&& rhs) noexcept;
bool operator==(const NzHashDigest& rhs) const; bool operator==(const HashDigest& rhs) const;
bool operator!=(const NzHashDigest& rhs) const; bool operator!=(const HashDigest& rhs) const;
bool operator<(const NzHashDigest& rhs) const; bool operator<(const HashDigest& rhs) const;
bool operator<=(const NzHashDigest& rhs) const; bool operator<=(const HashDigest& rhs) const;
bool operator>(const NzHashDigest& rhs) const; bool operator>(const HashDigest& rhs) const;
bool operator>=(const NzHashDigest& rhs) const; bool operator>=(const HashDigest& rhs) const;
NAZARA_CORE_API friend std::ostream& operator<<(std::ostream& out, const NzHashDigest& string); NAZARA_CORE_API friend std::ostream& operator<<(std::ostream& out, const HashDigest& string);
private: private:
NzString m_hashName; String m_hashName;
nzUInt8* m_digest; UInt8* m_digest;
unsigned int m_digestLength; unsigned int m_digestLength;
}; };
}
#endif // NAZARA_HASHDIGEST_HPP #endif // NAZARA_HASHDIGEST_HPP

View File

@ -10,22 +10,30 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Enums.hpp> #include <Nazara/Core/Enums.hpp>
class NzAbstractHash; namespace Nz
class NzHashDigest;
class NAZARA_CORE_API NzHashable
{ {
friend class NzHash; class AbstractHash;
class HashDigest;
public: class NAZARA_CORE_API Hashable
NzHashable() = default; {
virtual ~NzHashable(); friend class Hash;
NzHashDigest GetHash(nzHash hash) const; public:
NzHashDigest GetHash(NzAbstractHash* impl) const; Hashable() = default;
Hashable(const Hashable&) = default;
Hashable(Hashable&&) = default;
virtual ~Hashable();
private: HashDigest GetHash(HashType hash) const;
virtual bool FillHash(NzAbstractHash* impl) const = 0; HashDigest GetHash(AbstractHash* impl) const;
};
Hashable& operator=(const Hashable&) = default;
Hashable& operator=(Hashable&&) = default;
private:
virtual bool FillHash(AbstractHash* impl) const = 0;
};
}
#endif // HASHABLE_HPP_INCLUDED #endif // HASHABLE_HPP_INCLUDED

View File

@ -9,22 +9,30 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
template<typename... Args> namespace Nz
class NzInitializer
{ {
public: template<typename... Args>
NzInitializer(bool initialize = true); class Initializer
~NzInitializer(); {
public:
Initializer(bool initialize = true);
Initializer(const Initializer&) = delete;
Initializer(Initializer&&) = delete; ///TODO
~Initializer();
bool Initialize(); bool Initialize();
bool IsInitialized() const; bool IsInitialized() const;
void Uninitialize(); void Uninitialize();
operator bool() const; operator bool() const;
private: Initializer& operator=(const Initializer&) = delete;
bool m_initialized; Initializer& operator=(Initializer&&) = delete; ///TODO
};
private:
bool m_initialized;
};
}
#include <Nazara/Core/Initializer.inl> #include <Nazara/Core/Initializer.inl>

View File

@ -4,84 +4,91 @@
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
template<typename...> struct NzImplInitializer; namespace Nz
template<typename T, typename... Rest>
struct NzImplInitializer<T, Rest...>
{ {
static bool Init() namespace Detail
{ {
if (T::Initialize()) template<typename...> struct Initializer;
template<typename T, typename... Rest>
struct Initializer<T, Rest...>
{ {
if (NzImplInitializer<Rest...>::Init()) static bool Init()
return true; {
else if (T::Initialize())
{
if (Initializer<Rest...>::Init())
return true;
else
T::Uninitialize();
}
return false;
}
static void Uninit()
{
Initializer<Rest...>::Uninit();
T::Uninitialize(); T::Uninitialize();
} }
};
return false; template<>
struct Initializer<>
{
static bool Init()
{
return true;
}
static void Uninit()
{
}
};
} }
static void Uninit()
template<typename... Args>
Initializer<Args...>::Initializer(bool initialize) :
m_initialized(false)
{ {
NzImplInitializer<Rest...>::Uninit(); if (initialize)
T::Uninitialize(); Initialize();
} }
};
template<> template<typename... Args>
struct NzImplInitializer<> Initializer<Args...>::~Initializer()
{
static bool Init()
{ {
return true; Uninitialize();
} }
static void Uninit() template<typename... Args>
bool Initializer<Args...>::Initialize()
{ {
if (!m_initialized)
m_initialized = Detail::Initializer<Args...>::Init();
return m_initialized;
} }
};
template<typename... Args> template<typename... Args>
NzInitializer<Args...>::NzInitializer(bool initialize) : bool Initializer<Args...>::IsInitialized() const
m_initialized(false) {
{ return m_initialized;
if (initialize) }
Initialize();
}
template<typename... Args> template<typename... Args>
NzInitializer<Args...>::~NzInitializer() void Initializer<Args...>::Uninitialize()
{ {
Uninitialize(); if (m_initialized)
} Detail::Initializer<Args...>::Uninit();
}
template<typename... Args> template<typename... Args>
bool NzInitializer<Args...>::Initialize() Initializer<Args...>::operator bool() const
{ {
if (!m_initialized) return IsInitialized();
m_initialized = NzImplInitializer<Args...>::Init(); }
return m_initialized;
}
template<typename... Args>
bool NzInitializer<Args...>::IsInitialized() const
{
return m_initialized;
}
template<typename... Args>
void NzInitializer<Args...>::Uninitialize()
{
if (m_initialized)
NzImplInitializer<Args...>::Uninit();
}
template<typename... Args>
NzInitializer<Args...>::operator bool() const
{
return IsInitialized();
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

View File

@ -10,17 +10,20 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Stream.hpp> #include <Nazara/Core/Stream.hpp>
class NAZARA_CORE_API NzInputStream : public NzStream namespace Nz
{ {
public: class NAZARA_CORE_API InputStream : public Stream
virtual ~NzInputStream(); {
public:
virtual ~InputStream();
virtual bool EndOfStream() const = 0; virtual bool EndOfStream() const = 0;
virtual nzUInt64 GetSize() const = 0; virtual UInt64 GetSize() const = 0;
virtual std::size_t Read(void* buffer, std::size_t size) = 0; virtual std::size_t Read(void* buffer, std::size_t size) = 0;
virtual NzString ReadLine(unsigned int lineSize = 0); virtual String ReadLine(unsigned int lineSize = 0);
}; };
}
#endif // NAZARA_INPUTSTREAM_HPP #endif // NAZARA_INPUTSTREAM_HPP

View File

@ -9,16 +9,19 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
class NzMutex; namespace Nz
class NAZARA_CORE_API NzLockGuard
{ {
public: class Mutex;
NzLockGuard(NzMutex& mutex);
~NzLockGuard();
private: class NAZARA_CORE_API LockGuard
NzMutex& m_mutex; {
}; public:
LockGuard(Mutex& mutex);
~LockGuard();
private:
Mutex& m_mutex;
};
}
#endif // NAZARA_LOCKGUARD_HPP #endif // NAZARA_LOCKGUARD_HPP

View File

@ -9,7 +9,6 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_LOG #if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_LOG
@ -24,41 +23,49 @@
#define NazaraDebug(txt) #define NazaraDebug(txt)
#endif #endif
#define NazaraLog NzLog::Instance() #define NazaraLog Nz::Log::Instance()
#define NazaraNotice(txt) NazaraLog->Write(txt) #define NazaraNotice(txt) NazaraLog->Write(txt)
class NzFile; namespace Nz
class NAZARA_CORE_API NzLog : NzNonCopyable
{ {
public: class File;
void Enable(bool enable);
void EnableAppend(bool enable);
void EnableDateTime(bool enable);
NzString GetFile() const; class NAZARA_CORE_API Log
{
public:
void Enable(bool enable);
void EnableAppend(bool enable);
void EnableDateTime(bool enable);
bool IsEnabled() const; String GetFile() const;
void SetFile(const NzString& filePath); bool IsEnabled() const;
void Write(const NzString& string); void SetFile(const String& filePath);
void WriteError(nzErrorType type, const NzString& error);
void WriteError(nzErrorType type, const NzString& error, unsigned int line, const NzString& file, const NzString& func);
static NzLog* Instance(); void Write(const String& string);
void WriteError(ErrorType type, const String& error);
void WriteError(ErrorType type, const String& error, unsigned int line, const String& file, const String& func);
private: static Log* Instance();
NzLog();
~NzLog();
NazaraMutexAttrib(m_mutex, mutable) private:
Log();
Log(const Log&) = delete;
Log(Log&&) = delete;
~Log();
NzString m_filePath; Log& operator=(const Log&) = delete;
NzFile* m_file; Log& operator=(Log&&) = delete;
bool m_append;
bool m_enabled; NazaraMutexAttrib(m_mutex, mutable)
bool m_writeTime;
}; String m_filePath;
File* m_file;
bool m_append;
bool m_enabled;
bool m_writeTime;
};
}
#endif // NAZARA_LOGGER_HPP #endif // NAZARA_LOGGER_HPP

View File

@ -9,11 +9,14 @@
#include <cstddef> #include <cstddef>
void NzOperatorDelete(void* ptr); namespace Nz
void* NzOperatorNew(std::size_t size); {
void OperatorDelete(void* ptr);
void* OperatorNew(std::size_t size);
template<typename T, typename... Args> template<typename T, typename... Args>
T* NzPlacementNew(void* ptr, Args&&... args); T* PlacementNew(void* ptr, Args&&... args);
}
#include <Nazara/Core/MemoryHelper.inl> #include <Nazara/Core/MemoryHelper.inl>

View File

@ -14,28 +14,31 @@
#include <utility> #include <utility>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
inline void NzOperatorDelete(void* ptr) namespace Nz
{ {
#if NAZARA_CORE_MANAGE_MEMORY inline void OperatorDelete(void* ptr)
NzMemoryManager::Free(ptr); {
#else #if NAZARA_CORE_MANAGE_MEMORY
operator delete(ptr); MemoryManager::Free(ptr);
#endif #else
} operator delete(ptr);
#endif
}
inline void* NzOperatorNew(std::size_t size) inline void* OperatorNew(std::size_t size)
{ {
#if NAZARA_CORE_MANAGE_MEMORY #if NAZARA_CORE_MANAGE_MEMORY
return NzMemoryManager::Allocate(size); return MemoryManager::Allocate(size);
#else #else
return operator new(size); return operator new(size);
#endif #endif
} }
template<typename T, typename... Args> template<typename T, typename... Args>
T* NzPlacementNew(void* ptr, Args&&... args) T* PlacementNew(void* ptr, Args&&... args)
{ {
return new (ptr) T(std::forward<Args>(args)...); return new (ptr) T(std::forward<Args>(args)...);
}
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

Some files were not shown because too many files have changed in this diff Show More