Switch from Nz prefix to namespace Nz

What a huge commit


Former-commit-id: 38ac5eebf70adc1180f571f6006192d28fb99897
This commit is contained in:
Lynix 2015-09-25 19:20:05 +02:00
parent c214251ecf
commit df8da275c4
609 changed files with 68265 additions and 66534 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() << ')';

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

@ -85,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,7 +17,7 @@ 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)

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

@ -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 String& cap, bool b);
int main() int main()
{ {
@ -28,68 +28,68 @@ 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; Initializer<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: " << HardwareInfo::GetProcessorBrandString() << std::endl;
oss << "Concepteur: " << NzHardwareInfo::GetProcessorVendorName() << std::endl; oss << "Concepteur: " << HardwareInfo::GetProcessorVendorName() << std::endl;
oss << "Nombre de coeurs logiques: " << NzHardwareInfo::GetProcessorCount() << std::endl; oss << "Nombre de coeurs logiques: " << 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", HardwareInfo::HasCapability(ProcessorCap_x64));
printCap(oss, "-AVX", NzHardwareInfo::HasCapability(nzProcessorCap_AVX)); printCap(oss, "-AVX", HardwareInfo::HasCapability(ProcessorCap_AVX));
printCap(oss, "-FMA3", NzHardwareInfo::HasCapability(nzProcessorCap_FMA3)); printCap(oss, "-FMA3", HardwareInfo::HasCapability(ProcessorCap_FMA3));
printCap(oss, "-FMA4", NzHardwareInfo::HasCapability(nzProcessorCap_FMA4)); printCap(oss, "-FMA4", HardwareInfo::HasCapability(ProcessorCap_FMA4));
printCap(oss, "-MMX", NzHardwareInfo::HasCapability(nzProcessorCap_MMX)); printCap(oss, "-MMX", HardwareInfo::HasCapability(ProcessorCap_MMX));
printCap(oss, "-SSE", NzHardwareInfo::HasCapability(nzProcessorCap_SSE)); printCap(oss, "-SSE", HardwareInfo::HasCapability(ProcessorCap_SSE));
printCap(oss, "-SSE2", NzHardwareInfo::HasCapability(nzProcessorCap_SSE2)); printCap(oss, "-SSE2", HardwareInfo::HasCapability(ProcessorCap_SSE2));
printCap(oss, "-SSE3", NzHardwareInfo::HasCapability(nzProcessorCap_SSE3)); printCap(oss, "-SSE3", HardwareInfo::HasCapability(ProcessorCap_SSE3));
printCap(oss, "-SSSE3", NzHardwareInfo::HasCapability(nzProcessorCap_SSSE3)); printCap(oss, "-SSSE3", HardwareInfo::HasCapability(ProcessorCap_SSSE3));
printCap(oss, "-SSE4.1", NzHardwareInfo::HasCapability(nzProcessorCap_SSE41)); printCap(oss, "-SSE4.1", HardwareInfo::HasCapability(ProcessorCap_SSE41));
printCap(oss, "-SSE4.2", NzHardwareInfo::HasCapability(nzProcessorCap_SSE42)); printCap(oss, "-SSE4.2", HardwareInfo::HasCapability(ProcessorCap_SSE42));
printCap(oss, "-SSE4.a", NzHardwareInfo::HasCapability(nzProcessorCap_SSE4a)); printCap(oss, "-SSE4.a", HardwareInfo::HasCapability(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; Initializer<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 = 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: " << OpenGL::GetRendererName() << std::endl;
oss << "Concepteur: " << NzOpenGL::GetVendorName() << std::endl; oss << "Concepteur: " << 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", OpenGL::IsSupported(OpenGLExtension_FP64));
printCap(oss, "-Compression de textures (s3tc)", NzOpenGL::IsSupported(nzOpenGLExtension_TextureCompression_s3tc)); printCap(oss, "-Compression de textures (s3tc)", OpenGL::IsSupported(OpenGLExtension_TextureCompression_s3tc));
printCap(oss, "-Filtrage anisotrope", NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)); printCap(oss, "-Filtrage anisotrope", OpenGL::IsSupported(OpenGLExtension_AnisotropicFilter));
printCap(oss, "-Framebuffer Object", NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject)); printCap(oss, "-Framebuffer Object", OpenGL::IsSupported(OpenGLExtension_FrameBufferObject));
printCap(oss, "-Mode debug", NzOpenGL::IsSupported(nzOpenGLExtension_DebugOutput)); printCap(oss, "-Mode debug", OpenGL::IsSupported(OpenGLExtension_DebugOutput));
printCap(oss, "-Pixelbuffer Object", NzOpenGL::IsSupported(nzOpenGLExtension_PixelBufferObject)); printCap(oss, "-Pixelbuffer Object", OpenGL::IsSupported(OpenGLExtension_PixelBufferObject));
printCap(oss, "-Samplers Object", NzOpenGL::IsSupported(nzOpenGLExtension_SamplerObjects)); printCap(oss, "-Samplers Object", OpenGL::IsSupported(OpenGLExtension_SamplerObjects));
printCap(oss, "-Separate shader objects", NzOpenGL::IsSupported(nzOpenGLExtension_SeparateShaderObjects)); printCap(oss, "-Separate shader objects", OpenGL::IsSupported(OpenGLExtension_SeparateShaderObjects));
printCap(oss, "-Texture array", NzOpenGL::IsSupported(nzOpenGLExtension_TextureArray)); printCap(oss, "-Texture array", OpenGL::IsSupported(OpenGLExtension_TextureArray));
printCap(oss, "-Texture storage", NzOpenGL::IsSupported(nzOpenGLExtension_TextureStorage)); printCap(oss, "-Texture storage", OpenGL::IsSupported(OpenGLExtension_TextureStorage));
printCap(oss, "-Vertex array objects", NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObjects)); printCap(oss, "-Vertex array objects", OpenGL::IsSupported(OpenGLExtension_VertexArrayObjects));
} }
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;
@ -99,10 +99,10 @@ int main()
std::cout << oss.str() << std::endl; std::cout << oss.str() << std::endl;
NzFile reportFile("RapportHardwareInfo.txt"); File reportFile("RapportHardwareInfo.txt");
if (reportFile.Open(nzOpenMode_Text | nzOpenMode_Truncate | nzOpenMode_WriteOnly)) if (reportFile.Open(OpenMode_Text | OpenMode_Truncate | OpenMode_WriteOnly))
{ {
reportFile.Write(oss.str()); // Conversion implicite en NzString reportFile.Write(oss.str()); // Conversion implicite en 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
@ -116,7 +116,7 @@ int main()
return 0; return 0;
} }
void printCap(std::ostream& o, const NzString& cap, bool b) void printCap(std::ostream& o, const 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,12 +5,14 @@
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Audio/Debug.hpp> #include <Nazara/Audio/Debug.hpp>
namespace Nz
{
template<typename T> template<typename T>
void NzMixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount) void MixToMono(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 ///DOC: Le buffer d'entrée peut être le même que le buffer de sortie
// Pour éviter l'overflow, on utilise comme accumulateur un type assez grand, (u)int 64 bits pour les entiers, double pour les flottants // Pour éviter l'overflow, on utilise comme accumulateur un type assez grand, (u)int 64 bits pour les entiers, double pour les flottants
typedef typename std::conditional<std::is_unsigned<T>::value, nzUInt64, nzInt64>::type BiggestInt; 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; typedef typename std::conditional<std::is_integral<T>::value, BiggestInt, double>::type Biggest;
for (unsigned int i = 0; i < frameCount; ++i) for (unsigned int i = 0; i < frameCount; ++i)
@ -22,5 +24,6 @@ void NzMixToMono(T* input, T* output, unsigned int channelCount, unsigned int fr
output[i] = static_cast<T>(acc / channelCount); output[i] = static_cast<T>(acc / channelCount);
} }
} }
}
#include <Nazara/Audio/DebugOff.hpp> #include <Nazara/Audio/DebugOff.hpp>

View File

@ -14,34 +14,36 @@
#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
{
class NAZARA_AUDIO_API Audio
{ {
public: public:
NzAudio() = delete; Audio() = delete;
~NzAudio() = 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);
@ -50,5 +52,6 @@ class NAZARA_AUDIO_API NzAudio
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,
enum AudioFormat
{
AudioFormat_Unknown = -1,
// La valeur entière est le nombre de canaux possédés par ce format // La valeur entière est le nombre de canaux possédés par ce format
nzAudioFormat_Mono = 1, AudioFormat_Mono = 1,
nzAudioFormat_Stereo = 2, AudioFormat_Stereo = 2,
nzAudioFormat_Quad = 4, AudioFormat_Quad = 4,
nzAudioFormat_5_1 = 6, AudioFormat_5_1 = 6,
nzAudioFormat_6_1 = 7, AudioFormat_6_1 = 7,
nzAudioFormat_7_1 = 8, AudioFormat_7_1 = 8,
nzAudioFormat_Max = nzAudioFormat_7_1 AudioFormat_Max = AudioFormat_7_1
}; };
enum nzSoundStatus enum SoundStatus
{ {
nzSoundStatus_Playing, SoundStatus_Playing,
nzSoundStatus_Paused, SoundStatus_Paused,
nzSoundStatus_Stopped SoundStatus_Stopped
}; };
}
#endif // NAZARA_ENUMS_HPP #endif // NAZARA_ENUMS_HPP

View File

@ -13,65 +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
{
struct MusicParams
{ {
bool forceMono = false; 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 class NAZARA_AUDIO_API Music : public Resource, public SoundEmitter
{ {
friend NzMusicLoader; friend MusicLoader;
public: public:
NzMusic() = default; Music() = default;
NzMusic(const NzMusic&) = delete; Music(const Music&) = delete;
NzMusic(NzMusic&&) = delete; ///TODO Music(Music&&) = delete; ///TODO
~NzMusic(); ~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;
nzUInt32 GetSampleCount() const; UInt32 GetSampleCount() const;
nzUInt32 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();
NzMusic& operator=(const NzMusic&) = delete; Music& operator=(const Music&) = delete;
NzMusic& operator=(NzMusic&&) = delete; ///TODO Music& operator=(Music&&) = delete; ///TODO
private: private:
NzMusicImpl* m_impl = nullptr; MusicImpl* m_impl = nullptr;
bool FillAndQueueBuffer(unsigned int buffer); bool FillAndQueueBuffer(unsigned int buffer);
void MusicThread(); void MusicThread();
static NzMusicLoader::LoaderList s_loaders; 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
{
using OpenALFunc = void(*)();
class NAZARA_AUDIO_API NzOpenAL class NAZARA_AUDIO_API OpenAL
{ {
public: public:
static NzOpenALFunc GetEntry(const NzString& entryPoint); static OpenALFunc GetEntry(const String& entryPoint);
static NzString GetRendererName(); static String GetRendererName();
static NzString GetVendorName(); static String GetVendorName();
static unsigned int GetVersion(); static unsigned int GetVersion();
static bool Initialize(bool openDevice = true); static bool Initialize(bool openDevice = true);
static bool IsInitialized(); static bool IsInitialized();
static unsigned int QueryInputDevices(std::vector<NzString>& devices); static unsigned int QueryInputDevices(std::vector<String>& devices);
static unsigned int QueryOutputDevices(std::vector<NzString>& devices); static unsigned int QueryOutputDevices(std::vector<String>& devices);
static bool SetDevice(const NzString& deviceName); static bool SetDevice(const String& deviceName);
static void Uninitialize(); static void Uninitialize();
static ALenum AudioFormat[nzAudioFormat_Max+1]; static ALenum AudioFormat[AudioFormat_Max + 1];
private: private:
static void CloseDevice(); static void CloseDevice();
static bool OpenDevice(); static bool OpenDevice();
static NzOpenALFunc LoadEntry(const char* name, bool throwException = false); 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,43 +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
{
class NAZARA_AUDIO_API Sound : public SoundEmitter
{ {
public: public:
NzSound() = default; Sound() = default;
NzSound(const NzSoundBuffer* soundBuffer); Sound(const SoundBuffer* soundBuffer);
NzSound(const NzSound& sound); Sound(const Sound& sound);
NzSound(NzSound&&) = default; Sound(Sound&&) = default;
~NzSound(); ~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();
NzSound& operator=(const NzSound&) = delete; ///TODO? Sound& operator=(const Sound&) = delete; ///TODO?
NzSound& operator=(NzSound&&) = default; Sound& operator=(Sound&&) = default;
private: private:
NzSoundBufferConstRef m_buffer; SoundBufferConstRef m_buffer;
}; };
}
#endif // NAZARA_SOUND_HPP #endif // NAZARA_SOUND_HPP

View File

@ -19,63 +19,65 @@
#include <Nazara/Core/ResourceManager.hpp> #include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/Signal.hpp> #include <Nazara/Core/Signal.hpp>
struct NzSoundBufferParams namespace Nz
{
struct SoundBufferParams
{ {
bool forceMono = false; bool forceMono = false;
bool IsValid() const; bool IsValid() const;
}; };
class NzSound; class Sound;
class NzSoundBuffer; class SoundBuffer;
using NzSoundBufferConstRef = NzObjectRef<const NzSoundBuffer>; using SoundBufferConstRef = ObjectRef<const SoundBuffer>;
using NzSoundBufferLibrary = NzObjectLibrary<NzSoundBuffer>; using SoundBufferLibrary = ObjectLibrary<SoundBuffer>;
using NzSoundBufferLoader = NzResourceLoader<NzSoundBuffer, NzSoundBufferParams>; using SoundBufferLoader = ResourceLoader<SoundBuffer, SoundBufferParams>;
using NzSoundBufferManager = NzResourceManager<NzSoundBuffer, NzSoundBufferParams>; using SoundBufferManager = ResourceManager<SoundBuffer, SoundBufferParams>;
using NzSoundBufferRef = NzObjectRef<NzSoundBuffer>; using SoundBufferRef = ObjectRef<SoundBuffer>;
struct NzSoundBufferImpl; struct SoundBufferImpl;
class NAZARA_AUDIO_API NzSoundBuffer : public NzRefCounted, public NzResource class NAZARA_AUDIO_API SoundBuffer : public RefCounted, public Resource
{ {
friend NzSound; friend Sound;
friend NzSoundBufferLibrary; friend SoundBufferLibrary;
friend NzSoundBufferLoader; friend SoundBufferLoader;
friend NzSoundBufferManager; friend SoundBufferManager;
friend class NzAudio; friend class Audio;
public: public:
NzSoundBuffer() = default; SoundBuffer() = default;
NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples); SoundBuffer(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples);
NzSoundBuffer(const NzSoundBuffer&) = delete; SoundBuffer(const SoundBuffer&) = delete;
NzSoundBuffer(NzSoundBuffer&&) = delete; SoundBuffer(SoundBuffer&&) = delete;
~NzSoundBuffer(); ~SoundBuffer();
bool Create(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples); bool Create(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples);
void Destroy(); void Destroy();
nzUInt32 GetDuration() const; UInt32 GetDuration() const;
nzAudioFormat GetFormat() const; AudioFormat GetFormat() const;
const nzInt16* GetSamples() const; const Int16* GetSamples() const;
nzUInt32 GetSampleCount() const; UInt32 GetSampleCount() const;
nzUInt32 GetSampleRate() const; UInt32 GetSampleRate() const;
bool IsValid() const; bool IsValid() 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());
static bool IsFormatSupported(nzAudioFormat format); static bool IsFormatSupported(AudioFormat format);
template<typename... Args> static NzSoundBufferRef New(Args&&... args); template<typename... Args> static SoundBufferRef New(Args&&... args);
NzSoundBuffer& operator=(const NzSoundBuffer&) = delete; SoundBuffer& operator=(const SoundBuffer&) = delete;
NzSoundBuffer& operator=(NzSoundBuffer&&) = delete; ///TODO SoundBuffer& operator=(SoundBuffer&&) = delete; ///TODO
// Signals: // Signals:
NazaraSignal(OnSoundBufferDestroy, const NzSoundBuffer* /*soundBuffer*/); NazaraSignal(OnSoundBufferDestroy, const SoundBuffer* /*soundBuffer*/);
NazaraSignal(OnSoundBufferRelease, const NzSoundBuffer* /*soundBuffer*/); NazaraSignal(OnSoundBufferRelease, const SoundBuffer* /*soundBuffer*/);
private: private:
unsigned int GetOpenALBuffer() const; unsigned int GetOpenALBuffer() const;
@ -83,13 +85,14 @@ class NAZARA_AUDIO_API NzSoundBuffer : public NzRefCounted, public NzResource
static bool Initialize(); static bool Initialize();
static void Uninitialize(); static void Uninitialize();
NzSoundBufferImpl* m_impl = nullptr; SoundBufferImpl* m_impl = nullptr;
static NzSoundBufferLibrary::LibraryMap s_library; static SoundBufferLibrary::LibraryMap s_library;
static NzSoundBufferLoader::LoaderList s_loaders; static SoundBufferLoader::LoaderList s_loaders;
static NzSoundBufferManager::ManagerMap s_managerMap; static SoundBufferManager::ManagerMap s_managerMap;
static NzSoundBufferManager::ManagerParams s_managerParameters; 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>
SoundBufferRef SoundBuffer::New(Args&&... args)
{
std::unique_ptr<SoundBuffer> object(new SoundBuffer(std::forward<Args>(args)...));
object->SetPersistent(false); object->SetPersistent(false);
return object.release(); return object.release();
} }
}
#include <Nazara/Audio/DebugOff.hpp> #include <Nazara/Audio/DebugOff.hpp>

View File

@ -15,22 +15,24 @@
///TODO: Faire hériter SoundEmitter de Node ///TODO: Faire hériter SoundEmitter de Node
class NAZARA_AUDIO_API NzSoundEmitter namespace Nz
{
class NAZARA_AUDIO_API SoundEmitter
{ {
public: public:
virtual ~NzSoundEmitter(); 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;
@ -42,25 +44,25 @@ class NAZARA_AUDIO_API NzSoundEmitter
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;
NzSoundEmitter& operator=(const NzSoundEmitter&) = delete; ///TODO SoundEmitter& operator=(const SoundEmitter&) = delete; ///TODO
NzSoundEmitter& operator=(NzSoundEmitter&&) = delete; ///TODO SoundEmitter& operator=(SoundEmitter&&) = delete; ///TODO
protected: protected:
NzSoundEmitter(); SoundEmitter();
NzSoundEmitter(const NzSoundEmitter& emitter); SoundEmitter(const SoundEmitter& emitter);
NzSoundEmitter(NzSoundEmitter&&) = delete; ///TODO SoundEmitter(SoundEmitter&&) = delete; ///TODO
nzSoundStatus GetInternalStatus() const; SoundStatus GetInternalStatus() const;
unsigned int m_source; 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
{
class NAZARA_AUDIO_API SoundStream
{ {
public: public:
NzSoundStream() = default; SoundStream() = default;
virtual ~NzSoundStream(); virtual ~SoundStream();
virtual nzUInt32 GetDuration() const = 0; virtual UInt32 GetDuration() const = 0;
virtual nzAudioFormat GetFormat() const = 0; virtual AudioFormat GetFormat() const = 0;
virtual nzUInt32 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

@ -9,22 +9,25 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
class NzHashDigest; namespace Nz
{
class HashDigest;
class NAZARA_CORE_API NzAbstractHash class NAZARA_CORE_API AbstractHash
{ {
public: public:
NzAbstractHash() = default; AbstractHash() = default;
NzAbstractHash(const NzAbstractHash&) = delete; AbstractHash(const AbstractHash&) = delete;
NzAbstractHash(NzAbstractHash&&) = default; AbstractHash(AbstractHash&&) = default;
virtual ~NzAbstractHash(); virtual ~AbstractHash();
virtual void Append(const nzUInt8* data, unsigned int len) = 0; virtual void Append(const UInt8* data, unsigned int len) = 0;
virtual void Begin() = 0; virtual void Begin() = 0;
virtual NzHashDigest End() = 0; virtual HashDigest End() = 0;
NzAbstractHash& operator=(const NzAbstractHash&) = delete; AbstractHash& operator=(const AbstractHash&) = delete;
NzAbstractHash& operator=(NzAbstractHash&&) = default; 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>
namespace Nz
{
namespace Detail
{
// http://www.cppsamples.com/common-tasks/apply-tuple-to-function.html // http://www.cppsamples.com/common-tasks/apply-tuple-to-function.html
template<typename F, typename Tuple, size_t... S> template<typename F, typename Tuple, size_t... S>
auto NzApplyImplFunc(F&& fn, Tuple&& t, std::index_sequence<S...>) auto ApplyImplFunc(F&& fn, Tuple&& t, std::index_sequence<S...>)
{ {
return std::forward<F>(fn)(std::get<S>(std::forward<Tuple>(t))...); return std::forward<F>(fn)(std::get<S>(std::forward<Tuple>(t))...);
} }
template<typename F, typename Tuple>
auto NzApply(F&& fn, Tuple&& t)
{
constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value;
return NzApplyImplFunc(std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
}
template<typename O, typename F, typename Tuple, size_t... S> template<typename O, typename F, typename Tuple, size_t... S>
auto NzApplyImplMethod(O& object, F&& fn, Tuple&& t, std::index_sequence<S...>) auto ApplyImplMethod(O& object, F&& fn, Tuple&& t, std::index_sequence<S...>)
{ {
return (object .* std::forward<F>(fn))(std::get<S>(std::forward<Tuple>(t))...); return (object .* std::forward<F>(fn))(std::get<S>(std::forward<Tuple>(t))...);
} }
}
template<typename O, typename F, typename Tuple> template<typename F, typename Tuple>
auto NzApply(O& object, F&& fn, Tuple&& t) auto Apply(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::ApplyImplFunc(std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
}
template<typename O, typename F, typename Tuple>
auto Apply(O& object, F&& fn, Tuple&& t)
{
constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value;
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,24 +12,26 @@
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
class NzAbstractHash; namespace Nz
{
class AbstractHash;
template<typename Block = nzUInt32, class Allocator = std::allocator<Block>> template<typename Block = UInt32, class Allocator = std::allocator<Block>>
class NzBitset class Bitset
{ {
static_assert(std::is_integral<Block>::value && std::is_unsigned<Block>::value, "Block must be a unsigned integral type"); static_assert(std::is_integral<Block>::value && std::is_unsigned<Block>::value, "Block must be a unsigned integral type");
public: public:
class Bit; class Bit;
NzBitset(); Bitset();
explicit NzBitset(unsigned int bitCount, bool val = false); explicit Bitset(unsigned int bitCount, bool val = false);
explicit NzBitset(const char* bits); explicit Bitset(const char* bits);
NzBitset(const char* bits, unsigned int bitCount); Bitset(const char* bits, unsigned int bitCount);
NzBitset(const NzBitset& bitset) = default; Bitset(const Bitset& bitset) = default;
explicit NzBitset(const NzString& bits); explicit Bitset(const String& bits);
NzBitset(NzBitset&& bitset) noexcept = default; Bitset(Bitset&& bitset) noexcept = default;
~NzBitset() = default; ~Bitset() = default;
void Clear(); void Clear();
unsigned int Count() const; unsigned int Count() const;
@ -43,12 +45,12 @@ class NzBitset
unsigned int GetCapacity() const; unsigned int GetCapacity() const;
unsigned int GetSize() const; unsigned int GetSize() const;
void PerformsAND(const NzBitset& a, const NzBitset& b); void PerformsAND(const Bitset& a, const Bitset& b);
void PerformsNOT(const NzBitset& a); void PerformsNOT(const Bitset& a);
void PerformsOR(const NzBitset& a, const NzBitset& b); void PerformsOR(const Bitset& a, const Bitset& b);
void PerformsXOR(const NzBitset& a, const NzBitset& b); void PerformsXOR(const Bitset& a, const Bitset& b);
bool Intersects(const NzBitset& bitset) const; bool Intersects(const Bitset& bitset) const;
void Reserve(unsigned int bitCount); void Reserve(unsigned int bitCount);
void Resize(unsigned int bitCount, bool defaultVal = false); void Resize(unsigned int bitCount, bool defaultVal = false);
@ -60,7 +62,7 @@ class NzBitset
void Set(unsigned int bit, bool val = true); void Set(unsigned int bit, bool val = true);
void SetBlock(unsigned int i, Block block); void SetBlock(unsigned int i, Block block);
void Swap(NzBitset& bitset); void Swap(Bitset& bitset);
bool Test(unsigned int bit) const; bool Test(unsigned int bit) const;
bool TestAll() const; bool TestAll() const;
@ -68,7 +70,7 @@ class NzBitset
bool TestNone() const; bool TestNone() const;
template<typename T> T To() const; template<typename T> T To() const;
NzString ToString() const; String ToString() const;
void UnboundedReset(unsigned int bit); void UnboundedReset(unsigned int bit);
void UnboundedSet(unsigned int bit, bool val = true); void UnboundedSet(unsigned int bit, bool val = true);
@ -77,15 +79,15 @@ class NzBitset
Bit operator[](int index); Bit operator[](int index);
bool operator[](int index) const; bool operator[](int index) const;
NzBitset operator~() const; Bitset operator~() const;
NzBitset& operator=(const NzBitset& bitset) = default; Bitset& operator=(const Bitset& bitset) = default;
NzBitset& operator=(const NzString& bits); Bitset& operator=(const String& bits);
NzBitset& operator=(NzBitset&& bitset) noexcept = default; Bitset& operator=(Bitset&& bitset) noexcept = default;
NzBitset& operator&=(const NzBitset& bitset); Bitset& operator&=(const Bitset& bitset);
NzBitset& operator|=(const NzBitset& bitset); Bitset& operator|=(const Bitset& bitset);
NzBitset& operator^=(const NzBitset& bitset); Bitset& operator^=(const Bitset& bitset);
static Block fullBitMask; static Block fullBitMask;
static unsigned int bitsPerBlock; static unsigned int bitsPerBlock;
@ -105,36 +107,9 @@ class NzBitset
}; };
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
template<typename Block, class Allocator>
bool operator!=(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
bool operator<(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
bool operator<=(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
bool operator>(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
bool operator>=(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
NzBitset<Block, Allocator> operator&(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
NzBitset<Block, Allocator> operator|(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
NzBitset<Block, Allocator> operator^(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
class NzBitset<Block, Allocator>::Bit
{ {
friend NzBitset<Block, Allocator>; friend Bitset<Block, Allocator>;
public: public:
Bit(const Bit& bit) = default; Bit(const Bit& bit) = default;
@ -167,10 +142,38 @@ class NzBitset<Block, Allocator>::Bit
Block m_mask; Block m_mask;
}; };
template<typename Block, class Allocator>
bool operator==(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
bool operator!=(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
bool operator<(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
bool operator<=(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
bool operator>(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
bool operator>=(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);
template<typename Block, class Allocator>
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);
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>

View File

@ -14,27 +14,29 @@
#pragma warning(disable: 4804) #pragma warning(disable: 4804)
#endif #endif
namespace Nz
{
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator>::NzBitset() : Bitset<Block, Allocator>::Bitset() :
m_bitCount(0) m_bitCount(0)
{ {
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator>::NzBitset(unsigned int bitCount, bool val) : Bitset<Block, Allocator>::Bitset(unsigned int bitCount, bool val) :
NzBitset() Bitset()
{ {
Resize(bitCount, val); Resize(bitCount, val);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator>::NzBitset(const char* bits) : Bitset<Block, Allocator>::Bitset(const char* bits) :
NzBitset(bits, std::strlen(bits)) Bitset(bits, std::strlen(bits))
{ {
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator>::NzBitset(const char* bits, unsigned int bitCount) : Bitset<Block, Allocator>::Bitset(const char* bits, unsigned int bitCount) :
m_blocks(ComputeBlockCount(bitCount), 0U), m_blocks(ComputeBlockCount(bitCount), 0U),
m_bitCount(bitCount) m_bitCount(bitCount)
{ {
@ -59,33 +61,33 @@ m_bitCount(bitCount)
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator>::NzBitset(const NzString& bits) : Bitset<Block, Allocator>::Bitset(const String& bits) :
NzBitset(bits.GetConstBuffer(), bits.GetSize()) Bitset(bits.GetConstBuffer(), bits.GetSize())
{ {
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::Clear() void Bitset<Block, Allocator>::Clear()
{ {
m_bitCount = 0; m_bitCount = 0;
m_blocks.clear(); m_blocks.clear();
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::Count() const unsigned int Bitset<Block, Allocator>::Count() const
{ {
if (m_blocks.empty()) if (m_blocks.empty())
return 0; return 0;
unsigned int count = 0; unsigned int count = 0;
for (unsigned int i = 0; i < m_blocks.size(); ++i) for (unsigned int i = 0; i < m_blocks.size(); ++i)
count += NzCountBits(m_blocks[i]); count += CountBits(m_blocks[i]);
return count; return count;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::Flip() void Bitset<Block, Allocator>::Flip()
{ {
for (Block& block : m_blocks) for (Block& block : m_blocks)
block ^= fullBitMask; block ^= fullBitMask;
@ -94,13 +96,13 @@ void NzBitset<Block, Allocator>::Flip()
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::FindFirst() const unsigned int Bitset<Block, Allocator>::FindFirst() const
{ {
return FindFirstFrom(0); return FindFirstFrom(0);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::FindNext(unsigned int bit) const unsigned int Bitset<Block, Allocator>::FindNext(unsigned int bit) const
{ {
NazaraAssert(bit < m_bitCount, "Bit index out of range"); NazaraAssert(bit < m_bitCount, "Bit index out of range");
@ -119,13 +121,13 @@ unsigned int NzBitset<Block, Allocator>::FindNext(unsigned int bit) const
// Si le bloc n'est pas nul, c'est bon, sinon on doit chercher à partir du prochain bloc // Si le bloc n'est pas nul, c'est bon, sinon on doit chercher à partir du prochain bloc
if (block) if (block)
return NzIntegralLog2Pot(block & -block) + bit; return IntegralLog2Pot(block & -block) + bit;
else else
return FindFirstFrom(blockIndex + 1); return FindFirstFrom(blockIndex + 1);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
Block NzBitset<Block, Allocator>::GetBlock(unsigned int i) const Block Bitset<Block, Allocator>::GetBlock(unsigned int i) const
{ {
NazaraAssert(i < m_blocks.size(), "Block index out of range"); NazaraAssert(i < m_blocks.size(), "Block index out of range");
@ -133,25 +135,25 @@ Block NzBitset<Block, Allocator>::GetBlock(unsigned int i) const
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::GetBlockCount() const unsigned int Bitset<Block, Allocator>::GetBlockCount() const
{ {
return m_blocks.size(); return m_blocks.size();
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::GetCapacity() const unsigned int Bitset<Block, Allocator>::GetCapacity() const
{ {
return m_blocks.capacity()*bitsPerBlock; return m_blocks.capacity()*bitsPerBlock;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::GetSize() const unsigned int Bitset<Block, Allocator>::GetSize() const
{ {
return m_bitCount; return m_bitCount;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::PerformsAND(const NzBitset& a, const NzBitset& b) void Bitset<Block, Allocator>::PerformsAND(const Bitset& a, const Bitset& b)
{ {
std::pair<unsigned int, unsigned int> minmax = std::minmax(a.GetBlockCount(), b.GetBlockCount()); std::pair<unsigned int, unsigned int> minmax = std::minmax(a.GetBlockCount(), b.GetBlockCount());
@ -168,7 +170,7 @@ void NzBitset<Block, Allocator>::PerformsAND(const NzBitset& a, const NzBitset&
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::PerformsNOT(const NzBitset& a) void Bitset<Block, Allocator>::PerformsNOT(const Bitset& a)
{ {
m_blocks.resize(a.GetBlockCount()); m_blocks.resize(a.GetBlockCount());
m_bitCount = a.GetSize(); m_bitCount = a.GetSize();
@ -180,10 +182,10 @@ void NzBitset<Block, Allocator>::PerformsNOT(const NzBitset& a)
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::PerformsOR(const NzBitset& a, const NzBitset& b) void Bitset<Block, Allocator>::PerformsOR(const Bitset& a, const Bitset& b)
{ {
const NzBitset& greater = (a.GetBlockCount() > b.GetBlockCount()) ? a : b; const Bitset& greater = (a.GetBlockCount() > b.GetBlockCount()) ? a : b;
const NzBitset& lesser = (a.GetBlockCount() > b.GetBlockCount()) ? b : a; const Bitset& lesser = (a.GetBlockCount() > b.GetBlockCount()) ? b : a;
unsigned int maxBlockCount = greater.GetBlockCount(); unsigned int maxBlockCount = greater.GetBlockCount();
unsigned int minBlockCount = lesser.GetBlockCount(); unsigned int minBlockCount = lesser.GetBlockCount();
@ -200,10 +202,10 @@ void NzBitset<Block, Allocator>::PerformsOR(const NzBitset& a, const NzBitset& b
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::PerformsXOR(const NzBitset& a, const NzBitset& b) void Bitset<Block, Allocator>::PerformsXOR(const Bitset& a, const Bitset& b)
{ {
const NzBitset& greater = (a.GetBlockCount() > b.GetBlockCount()) ? a : b; const Bitset& greater = (a.GetBlockCount() > b.GetBlockCount()) ? a : b;
const NzBitset& lesser = (a.GetBlockCount() > b.GetBlockCount()) ? b : a; const Bitset& lesser = (a.GetBlockCount() > b.GetBlockCount()) ? b : a;
unsigned int maxBlockCount = greater.GetBlockCount(); unsigned int maxBlockCount = greater.GetBlockCount();
unsigned int minBlockCount = lesser.GetBlockCount(); unsigned int minBlockCount = lesser.GetBlockCount();
@ -220,7 +222,7 @@ void NzBitset<Block, Allocator>::PerformsXOR(const NzBitset& a, const NzBitset&
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::Intersects(const NzBitset& bitset) const bool Bitset<Block, Allocator>::Intersects(const Bitset& bitset) const
{ {
// On ne testera que les blocs en commun // On ne testera que les blocs en commun
unsigned int sharedBlocks = std::min(GetBlockCount(), bitset.GetBlockCount()); unsigned int sharedBlocks = std::min(GetBlockCount(), bitset.GetBlockCount());
@ -236,13 +238,13 @@ bool NzBitset<Block, Allocator>::Intersects(const NzBitset& bitset) const
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::Reserve(unsigned int bitCount) void Bitset<Block, Allocator>::Reserve(unsigned int bitCount)
{ {
m_blocks.reserve(ComputeBlockCount(bitCount)); m_blocks.reserve(ComputeBlockCount(bitCount));
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::Resize(unsigned int bitCount, bool defaultVal) void Bitset<Block, Allocator>::Resize(unsigned int bitCount, bool defaultVal)
{ {
// On commence par changer la taille du conteneur, avec la valeur correcte d'initialisation // On commence par changer la taille du conteneur, avec la valeur correcte d'initialisation
unsigned int lastBlockIndex = m_blocks.size() - 1; unsigned int lastBlockIndex = m_blocks.size() - 1;
@ -258,19 +260,19 @@ void NzBitset<Block, Allocator>::Resize(unsigned int bitCount, bool defaultVal)
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::Reset() void Bitset<Block, Allocator>::Reset()
{ {
Set(false); Set(false);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::Reset(unsigned int bit) void Bitset<Block, Allocator>::Reset(unsigned int bit)
{ {
Set(bit, false); Set(bit, false);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::Set(bool val) void Bitset<Block, Allocator>::Set(bool val)
{ {
std::fill(m_blocks.begin(), m_blocks.end(), (val) ? fullBitMask : Block(0U)); std::fill(m_blocks.begin(), m_blocks.end(), (val) ? fullBitMask : Block(0U));
if (val) if (val)
@ -278,7 +280,7 @@ void NzBitset<Block, Allocator>::Set(bool val)
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::Set(unsigned int bit, bool val) void Bitset<Block, Allocator>::Set(unsigned int bit, bool val)
{ {
NazaraAssert(bit < m_bitCount, "Bit index out of range"); NazaraAssert(bit < m_bitCount, "Bit index out of range");
@ -291,7 +293,7 @@ void NzBitset<Block, Allocator>::Set(unsigned int bit, bool val)
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::SetBlock(unsigned int i, Block block) void Bitset<Block, Allocator>::SetBlock(unsigned int i, Block block)
{ {
NazaraAssert(i < m_blocks.size(), "Block index out of range"); NazaraAssert(i < m_blocks.size(), "Block index out of range");
@ -301,14 +303,14 @@ void NzBitset<Block, Allocator>::SetBlock(unsigned int i, Block block)
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::Swap(NzBitset& bitset) void Bitset<Block, Allocator>::Swap(Bitset& bitset)
{ {
std::swap(m_bitCount, bitset.m_bitCount); std::swap(m_bitCount, bitset.m_bitCount);
std::swap(m_blocks, bitset.m_blocks); std::swap(m_blocks, bitset.m_blocks);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::Test(unsigned int bit) const bool Bitset<Block, Allocator>::Test(unsigned int bit) const
{ {
NazaraAssert(bit < m_bitCount, "Bit index out of range"); NazaraAssert(bit < m_bitCount, "Bit index out of range");
@ -316,7 +318,7 @@ bool NzBitset<Block, Allocator>::Test(unsigned int bit) const
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::TestAll() const bool Bitset<Block, Allocator>::TestAll() const
{ {
// Cas particulier du dernier bloc // Cas particulier du dernier bloc
Block lastBlockMask = GetLastBlockMask(); Block lastBlockMask = GetLastBlockMask();
@ -332,7 +334,7 @@ bool NzBitset<Block, Allocator>::TestAll() const
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::TestAny() const bool Bitset<Block, Allocator>::TestAny() const
{ {
if (m_blocks.empty()) if (m_blocks.empty())
return false; return false;
@ -347,14 +349,14 @@ bool NzBitset<Block, Allocator>::TestAny() const
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::TestNone() const bool Bitset<Block, Allocator>::TestNone() const
{ {
return !TestAny(); return !TestAny();
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
template<typename T> template<typename T>
T NzBitset<Block, Allocator>::To() const T Bitset<Block, Allocator>::To() const
{ {
static_assert(std::is_integral<T>() && std::is_unsigned<T>(), "T must be a unsigned integral type"); static_assert(std::is_integral<T>() && std::is_unsigned<T>(), "T must be a unsigned integral type");
@ -368,9 +370,9 @@ T NzBitset<Block, Allocator>::To() const
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzString NzBitset<Block, Allocator>::ToString() const String Bitset<Block, Allocator>::ToString() const
{ {
NzString str(m_bitCount, '0'); String str(m_bitCount, '0');
for (unsigned int i = 0; i < m_bitCount; ++i) for (unsigned int i = 0; i < m_bitCount; ++i)
{ {
@ -382,13 +384,13 @@ NzString NzBitset<Block, Allocator>::ToString() const
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::UnboundedReset(unsigned int bit) void Bitset<Block, Allocator>::UnboundedReset(unsigned int bit)
{ {
UnboundedSet(bit, false); UnboundedSet(bit, false);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::UnboundedSet(unsigned int bit, bool val) void Bitset<Block, Allocator>::UnboundedSet(unsigned int bit, bool val)
{ {
if (bit < m_bitCount) if (bit < m_bitCount)
Set(bit, val); Set(bit, val);
@ -401,7 +403,7 @@ void NzBitset<Block, Allocator>::UnboundedSet(unsigned int bit, bool val)
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::UnboundedTest(unsigned int bit) const bool Bitset<Block, Allocator>::UnboundedTest(unsigned int bit) const
{ {
if (bit < m_bitCount) if (bit < m_bitCount)
return Test(bit); return Test(bit);
@ -410,37 +412,37 @@ bool NzBitset<Block, Allocator>::UnboundedTest(unsigned int bit) const
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit NzBitset<Block, Allocator>::operator[](int index) typename Bitset<Block, Allocator>::Bit Bitset<Block, Allocator>::operator[](int index)
{ {
return Bit(m_blocks[GetBlockIndex(index)], Block(1U) << GetBitIndex(index)); return Bit(m_blocks[GetBlockIndex(index)], Block(1U) << GetBitIndex(index));
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::operator[](int index) const bool Bitset<Block, Allocator>::operator[](int index) const
{ {
return Test(index); return Test(index);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator> NzBitset<Block, Allocator>::operator~() const Bitset<Block, Allocator> Bitset<Block, Allocator>::operator~() const
{ {
NzBitset bitset; Bitset bitset;
bitset.PerformsNOT(*this); bitset.PerformsNOT(*this);
return bitset; return bitset;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator>& NzBitset<Block, Allocator>::operator=(const NzString& bits) Bitset<Block, Allocator>& Bitset<Block, Allocator>::operator=(const String& bits)
{ {
NzBitset bitset(bits); Bitset bitset(bits);
std::swap(*this, bitset); std::swap(*this, bitset);
return *this; return *this;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator>& NzBitset<Block, Allocator>::operator&=(const NzBitset& bitset) Bitset<Block, Allocator>& Bitset<Block, Allocator>::operator&=(const Bitset& bitset)
{ {
PerformsAND(*this, bitset); PerformsAND(*this, bitset);
@ -448,7 +450,7 @@ NzBitset<Block, Allocator>& NzBitset<Block, Allocator>::operator&=(const NzBitse
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator>& NzBitset<Block, Allocator>::operator|=(const NzBitset& bitset) Bitset<Block, Allocator>& Bitset<Block, Allocator>::operator|=(const Bitset& bitset)
{ {
PerformsOR(*this, bitset); PerformsOR(*this, bitset);
@ -456,7 +458,7 @@ NzBitset<Block, Allocator>& NzBitset<Block, Allocator>::operator|=(const NzBitse
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator>& NzBitset<Block, Allocator>::operator^=(const NzBitset& bitset) Bitset<Block, Allocator>& Bitset<Block, Allocator>::operator^=(const Bitset& bitset)
{ {
PerformsXOR(*this, bitset); PerformsXOR(*this, bitset);
@ -464,7 +466,7 @@ NzBitset<Block, Allocator>& NzBitset<Block, Allocator>::operator^=(const NzBitse
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::FindFirstFrom(unsigned int blockIndex) const unsigned int Bitset<Block, Allocator>::FindFirstFrom(unsigned int blockIndex) const
{ {
if (blockIndex >= m_blocks.size()) if (blockIndex >= m_blocks.size())
return npos; return npos;
@ -484,17 +486,17 @@ unsigned int NzBitset<Block, Allocator>::FindFirstFrom(unsigned int blockIndex)
Block block = m_blocks[i]; Block block = m_blocks[i];
// Calcul de la position du LSB dans le bloc (et ajustement de la position) // Calcul de la position du LSB dans le bloc (et ajustement de la position)
return NzIntegralLog2Pot(block & -block) + i*bitsPerBlock; return IntegralLog2Pot(block & -block) + i*bitsPerBlock;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
Block NzBitset<Block, Allocator>::GetLastBlockMask() const Block Bitset<Block, Allocator>::GetLastBlockMask() const
{ {
return (Block(1U) << GetBitIndex(m_bitCount)) - 1U; return (Block(1U) << GetBitIndex(m_bitCount)) - 1U;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
void NzBitset<Block, Allocator>::ResetExtraBits() void Bitset<Block, Allocator>::ResetExtraBits()
{ {
Block mask = GetLastBlockMask(); Block mask = GetLastBlockMask();
if (mask) if (mask)
@ -502,40 +504,157 @@ void NzBitset<Block, Allocator>::ResetExtraBits()
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::ComputeBlockCount(unsigned int bitCount) unsigned int Bitset<Block, Allocator>::ComputeBlockCount(unsigned int bitCount)
{ {
return GetBlockIndex(bitCount) + ((GetBitIndex(bitCount) != 0U) ? 1U : 0U); return GetBlockIndex(bitCount) + ((GetBitIndex(bitCount) != 0U) ? 1U : 0U);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::GetBitIndex(unsigned int bit) unsigned int Bitset<Block, Allocator>::GetBitIndex(unsigned int bit)
{ {
return bit & (bitsPerBlock - 1U); // bit % bitsPerBlock return bit & (bitsPerBlock - 1U); // bit % bitsPerBlock
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::GetBlockIndex(unsigned int bit) unsigned int Bitset<Block, Allocator>::GetBlockIndex(unsigned int bit)
{ {
return bit / bitsPerBlock; return bit / bitsPerBlock;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
Block NzBitset<Block, Allocator>::fullBitMask = std::numeric_limits<Block>::max(); Block Bitset<Block, Allocator>::fullBitMask = std::numeric_limits<Block>::max();
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::bitsPerBlock = std::numeric_limits<Block>::digits; unsigned int Bitset<Block, Allocator>::bitsPerBlock = std::numeric_limits<Block>::digits;
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int NzBitset<Block, Allocator>::npos = std::numeric_limits<unsigned int>::max(); unsigned int Bitset<Block, Allocator>::npos = std::numeric_limits<unsigned int>::max();
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool operator==(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs) typename Bitset<Block, Allocator>::Bit& Bitset<Block, Allocator>::Bit::Flip()
{
m_block ^= m_mask;
return *this;
}
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::Bit& Bitset<Block, Allocator>::Bit::Reset()
{
return Set(false);
}
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::Bit& Bitset<Block, Allocator>::Bit::Set(bool val)
{
// https://graphics.stanford.edu/~seander/bithacks.html#ConditionalSetOrClearBitsWithoutBranching
m_block = (m_block & ~m_mask) | (-val & m_mask);
return *this;
}
template<typename Block, class Allocator>
bool Bitset<Block, Allocator>::Bit::Test() const
{
return m_block & m_mask;
}
template<typename Block, class Allocator>
template<bool BadCall>
void* Bitset<Block, Allocator>::Bit::operator&() const
{
// Le template est nécessaire pour ne planter la compilation qu'à l'utilisation
static_assert(!BadCall, "It is impossible to take the address of a bit in a bitset");
return nullptr;
}
template<typename Block, class Allocator>
Bitset<Block, Allocator>::Bit::operator bool() const
{
return Test();
}
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::Bit& Bitset<Block, Allocator>::Bit::operator=(bool val)
{
return Set(val);
}
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::Bit& Bitset<Block, Allocator>::Bit::operator=(const Bit& bit)
{
return Set(bit);
}
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::Bit& Bitset<Block, Allocator>::Bit::operator|=(bool val)
{
// Version sans branching:
Set((val) ? true : Test());
// Avec branching:
/*
if (val)
Set();
*/
return *this;
}
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::Bit& Bitset<Block, Allocator>::Bit::operator&=(bool val)
{
// Version sans branching:
Set((val) ? Test() : false);
// Avec branching:
/*
if (!val)
Reset();
*/
return *this;
}
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::Bit& Bitset<Block, Allocator>::Bit::operator^=(bool val)
{
// Version sans branching:
Set((val) ? !Test() : Test());
// Avec branching:
/*
if (val)
Flip();
*/
return *this;
}
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::Bit& Bitset<Block, Allocator>::Bit::operator-=(bool val)
{
// Version sans branching:
Set((val) ? false : Test());
// Avec branching:
/*
if (val)
Reset();
*/
return *this;
}
template<typename Block, class Allocator>
bool operator==(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs)
{ {
// La comparaison part du principe que (uint8) 00001100 == (uint16) 00000000 00001100 // La comparaison part du principe que (uint8) 00001100 == (uint16) 00000000 00001100
// et conserve donc cette propriété // et conserve donc cette propriété
const NzBitset<Block, Allocator>& greater = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? lhs : rhs; const Bitset<Block, Allocator>& greater = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? lhs : rhs;
const NzBitset<Block, Allocator>& lesser = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? rhs : lhs; const Bitset<Block, Allocator>& lesser = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? rhs : lhs;
unsigned int maxBlockCount = greater.GetBlockCount(); unsigned int maxBlockCount = greater.GetBlockCount();
unsigned int minBlockCount = lesser.GetBlockCount(); unsigned int minBlockCount = lesser.GetBlockCount();
@ -557,16 +676,16 @@ bool operator==(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, All
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool operator!=(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs) bool operator!=(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool operator<(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs) bool operator<(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs)
{ {
const NzBitset<Block, Allocator>& greater = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? lhs : rhs; const Bitset<Block, Allocator>& greater = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? lhs : rhs;
const NzBitset<Block, Allocator>& lesser = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? rhs : lhs; const Bitset<Block, Allocator>& lesser = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? rhs : lhs;
unsigned int maxBlockCount = greater.GetBlockCount(); unsigned int maxBlockCount = greater.GetBlockCount();
unsigned int minBlockCount = lesser.GetBlockCount(); unsigned int minBlockCount = lesser.GetBlockCount();
@ -590,172 +709,56 @@ bool operator<(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allo
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool operator<=(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs) bool operator<=(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs)
{ {
return lhs < rhs || lhs == rhs; return lhs < rhs || lhs == rhs;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool operator>(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs) bool operator>(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs)
{ {
return rhs < lhs; return rhs < lhs;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool operator>=(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs) bool operator>=(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs)
{ {
return rhs <= lhs; return rhs <= lhs;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator> operator&(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs) Bitset<Block, Allocator> operator&(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs)
{ {
NzBitset<Block, Allocator> bitset; Bitset<Block, Allocator> bitset;
bitset.PerformsAND(lhs, rhs); bitset.PerformsAND(lhs, rhs);
return bitset; return bitset;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator> operator|(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs) Bitset<Block, Allocator> operator|(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs)
{ {
NzBitset<Block, Allocator> bitset; Bitset<Block, Allocator> bitset;
bitset.PerformsOR(lhs, rhs); bitset.PerformsOR(lhs, rhs);
return bitset; return bitset;
} }
template<typename Block, class Allocator> template<typename Block, class Allocator>
NzBitset<Block, Allocator> operator^(const NzBitset<Block, Allocator>& lhs, const NzBitset<Block, Allocator>& rhs) Bitset<Block, Allocator> operator^(const Bitset<Block, Allocator>& lhs, const Bitset<Block, Allocator>& rhs)
{ {
NzBitset<Block, Allocator> bitset; Bitset<Block, Allocator> bitset;
bitset.PerformsXOR(lhs, rhs); bitset.PerformsXOR(lhs, rhs);
return bitset; return bitset;
} }
template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit& NzBitset<Block, Allocator>::Bit::Flip()
{
m_block ^= m_mask;
return *this;
} }
template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit& NzBitset<Block, Allocator>::Bit::Reset()
{
return Set(false);
}
template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit& NzBitset<Block, Allocator>::Bit::Set(bool val)
{
// https://graphics.stanford.edu/~seander/bithacks.html#ConditionalSetOrClearBitsWithoutBranching
m_block = (m_block & ~m_mask) | (-val & m_mask);
return *this;
}
template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::Bit::Test() const
{
return m_block & m_mask;
}
template<typename Block, class Allocator>
template<bool BadCall>
void* NzBitset<Block, Allocator>::Bit::operator&() const
{
// Le template est nécessaire pour ne planter la compilation qu'à l'utilisation
static_assert(!BadCall, "It is impossible to take the address of a bit in a bitset");
return nullptr;
}
template<typename Block, class Allocator>
NzBitset<Block, Allocator>::Bit::operator bool() const
{
return Test();
}
template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit& NzBitset<Block, Allocator>::Bit::operator=(bool val)
{
return Set(val);
}
template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit& NzBitset<Block, Allocator>::Bit::operator=(const Bit& bit)
{
return Set(bit);
}
template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit& NzBitset<Block, Allocator>::Bit::operator|=(bool val)
{
// Version sans branching:
Set((val) ? true : Test());
// Avec branching:
/*
if (val)
Set();
*/
return *this;
}
template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit& NzBitset<Block, Allocator>::Bit::operator&=(bool val)
{
// Version sans branching:
Set((val) ? Test() : false);
// Avec branching:
/*
if (!val)
Reset();
*/
return *this;
}
template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit& NzBitset<Block, Allocator>::Bit::operator^=(bool val)
{
// Version sans branching:
Set((val) ? !Test() : Test());
// Avec branching:
/*
if (val)
Flip();
*/
return *this;
}
template<typename Block, class Allocator>
typename NzBitset<Block, Allocator>::Bit& NzBitset<Block, Allocator>::Bit::operator-=(bool val)
{
// Version sans branching:
Set((val) ? false : Test());
// Avec branching:
/*
if (val)
Reset();
*/
return *this;
}
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)
{ {
lhs.Swap(rhs); lhs.Swap(rhs);
} }

View File

@ -13,11 +13,13 @@
#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;
class NAZARA_CORE_API ByteArray : public Hashable
{
using Container = std::vector<UInt8>;
public: public:
// types: // types:
@ -35,17 +37,17 @@ class NAZARA_CORE_API NzByteArray : public NzHashable
using value_type = Container::value_type; using value_type = Container::value_type;
// construct/destroy: // construct/destroy:
inline NzByteArray() = default; inline ByteArray() = default;
inline explicit NzByteArray(size_type n); inline explicit ByteArray(size_type n);
inline NzByteArray(const void* buffer, size_type n); inline ByteArray(const void* buffer, size_type n);
inline NzByteArray(size_type n, value_type value); inline ByteArray(size_type n, value_type value);
template <class InputIterator> NzByteArray(InputIterator first, InputIterator last); template <class InputIterator> ByteArray(InputIterator first, InputIterator last);
NzByteArray(const NzByteArray& other) = default; ByteArray(const ByteArray& other) = default;
NzByteArray(NzByteArray&& other) = default; ByteArray(ByteArray&& other) = default;
~NzByteArray() = default; ~ByteArray() = default;
inline iterator Append(const void* buffer, size_type size); inline iterator Append(const void* buffer, size_type size);
inline iterator Append(const NzByteArray& other); inline iterator Append(const ByteArray& other);
template <class InputIterator> void Assign(InputIterator first, InputIterator last); template <class InputIterator> void Assign(InputIterator first, InputIterator last);
inline void Assign(size_type n, value_type value); inline void Assign(size_type n, value_type value);
@ -66,10 +68,10 @@ class NAZARA_CORE_API NzByteArray : public NzHashable
inline const_pointer GetConstBuffer() const; inline const_pointer GetConstBuffer() const;
inline size_type GetMaxSize() const noexcept; inline size_type GetMaxSize() const noexcept;
inline size_type GetSize() const noexcept; inline size_type GetSize() const noexcept;
inline NzByteArray GetSubArray(const_iterator startPos, const_iterator endPos) const; inline ByteArray GetSubArray(const_iterator startPos, const_iterator endPos) const;
inline iterator Insert(const_iterator pos, const void* buffer, size_type n); inline iterator Insert(const_iterator pos, const void* buffer, size_type n);
inline iterator Insert(const_iterator pos, const NzByteArray& other); inline iterator Insert(const_iterator pos, const ByteArray& other);
inline iterator Insert(const_iterator pos, size_type n, value_type byte); inline iterator Insert(const_iterator pos, size_type n, value_type byte);
template <class InputIterator> iterator Insert(const_iterator pos, InputIterator first, InputIterator last); template <class InputIterator> iterator Insert(const_iterator pos, InputIterator first, InputIterator last);
inline bool IsEmpty() const noexcept; inline bool IsEmpty() const noexcept;
@ -77,7 +79,7 @@ class NAZARA_CORE_API NzByteArray : public NzHashable
inline void PopBack(); inline void PopBack();
inline void PopFront(); inline void PopFront();
inline iterator Prepend(const void* buffer, size_type size); inline iterator Prepend(const void* buffer, size_type size);
inline iterator Prepend(const NzByteArray& other); inline iterator Prepend(const ByteArray& other);
inline void PushBack(value_type byte); inline void PushBack(value_type byte);
inline void PushFront(value_type byte); inline void PushFront(value_type byte);
@ -86,9 +88,9 @@ class NAZARA_CORE_API NzByteArray : public NzHashable
inline void Resize(size_type newSize, value_type byte); inline void Resize(size_type newSize, value_type byte);
inline void ShrinkToFit(); inline void ShrinkToFit();
inline void Swap(NzByteArray& other); inline void Swap(ByteArray& other);
inline NzString ToString() const; inline String ToString() const;
// STL interface // STL interface
inline iterator begin() noexcept; inline iterator begin() noexcept;
@ -109,29 +111,30 @@ class NAZARA_CORE_API NzByteArray : public NzHashable
// Operators // Operators
inline reference operator[](size_type pos); inline reference operator[](size_type pos);
inline const_reference operator[](size_type pos) const; inline const_reference operator[](size_type pos) const;
inline NzByteArray& operator=(const NzByteArray& array) = default; inline ByteArray& operator=(const ByteArray& array) = default;
inline NzByteArray& operator=(NzByteArray&& array) = default; inline ByteArray& operator=(ByteArray&& array) = default;
inline NzByteArray operator+(const NzByteArray& array) const; inline ByteArray operator+(const ByteArray& array) const;
inline NzByteArray& operator+=(const NzByteArray& array); inline ByteArray& operator+=(const ByteArray& array);
inline bool operator==(const NzByteArray& rhs) const; inline bool operator==(const ByteArray& rhs) const;
inline bool operator!=(const NzByteArray& rhs) const; inline bool operator!=(const ByteArray& rhs) const;
inline bool operator<(const NzByteArray& rhs) const; inline bool operator<(const ByteArray& rhs) const;
inline bool operator<=(const NzByteArray& rhs) const; inline bool operator<=(const ByteArray& rhs) const;
inline bool operator>(const NzByteArray& rhs) const; inline bool operator>(const ByteArray& rhs) const;
inline bool operator>=(const NzByteArray& rhs) const; inline bool operator>=(const ByteArray& rhs) const;
private: private:
bool FillHash(NzAbstractHash* hash) const; bool FillHash(AbstractHash* hash) const;
Container m_array; Container m_array;
}; };
}
NAZARA_CORE_API std::ostream& operator<<(std::ostream& out, const NzByteArray& byteArray); 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
{
inline ByteArray::ByteArray(size_type n) :
m_array() m_array()
{ {
m_array.reserve(n); 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

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

View File

@ -5,18 +5,20 @@
#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
{
inline CallOnExit::CallOnExit(Func func) :
m_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();
@ -24,9 +26,10 @@ inline void NzCallOnExit::CallAndReset(Func 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,17 +15,19 @@
#include <Nazara/Core/ThreadSafetyOff.hpp> #include <Nazara/Core/ThreadSafetyOff.hpp>
#endif #endif
class NAZARA_CORE_API NzClock namespace Nz
{
class NAZARA_CORE_API Clock
{ {
public: public:
NzClock(nzUInt64 startingValue = 0, bool paused = false); Clock(UInt64 startingValue = 0, bool paused = false);
NzClock(const NzClock& clock) = default; Clock(const Clock& clock) = default;
NzClock(NzClock&& clock) = default; Clock(Clock&& clock) = default;
~NzClock() = 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;
@ -33,20 +35,21 @@ class NAZARA_CORE_API NzClock
void Restart(); void Restart();
void Unpause(); void Unpause();
NzClock& operator=(const NzClock& clock) = default; Clock& operator=(const Clock& clock) = default;
NzClock& operator=(NzClock&& 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
{
class Color
{ {
public: public:
inline NzColor(); inline Color();
inline NzColor(nzUInt8 red, nzUInt8 green, nzUInt8 blue, nzUInt8 alpha = 255); inline Color(UInt8 red, UInt8 green, UInt8 blue, UInt8 alpha = 255);
inline explicit NzColor(nzUInt8 lightness); inline explicit Color(UInt8 lightness);
inline NzColor(nzUInt8 color[3], nzUInt8 alpha = 255); inline Color(UInt8 color[3], UInt8 alpha = 255);
inline NzColor(const NzColor& color) = default; inline Color(const Color& color) = default;
inline ~NzColor() = 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,11 +9,13 @@
#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) : inline Color::Color(UInt8 red, UInt8 green, UInt8 blue, UInt8 alpha) :
r(red), r(red),
g(green), g(green),
b(blue), b(blue),
@ -21,7 +23,7 @@ a(alpha)
{ {
} }
inline NzColor::NzColor(nzUInt8 lightness) : inline Color::Color(UInt8 lightness) :
r(lightness), r(lightness),
g(lightness), g(lightness),
b(lightness), b(lightness),
@ -29,7 +31,7 @@ a(255)
{ {
} }
inline NzColor::NzColor(nzUInt8 vec[3], nzUInt8 alpha) : inline Color::Color(UInt8 vec[3], UInt8 alpha) :
r(vec[0]), r(vec[0]),
g(vec[1]), g(vec[1]),
b(vec[2]), b(vec[2]),
@ -37,9 +39,9 @@ a(alpha)
{ {
} }
inline NzString NzColor::ToString() const inline String Color::ToString() const
{ {
NzStringStream ss; StringStream ss;
ss << "Color(" << static_cast<int>(r) << ", " << static_cast<int>(g) << ", " << static_cast<int>(b); ss << "Color(" << static_cast<int>(r) << ", " << static_cast<int>(g) << ", " << static_cast<int>(b);
if (a != 255) if (a != 255)
@ -50,9 +52,9 @@ inline NzString NzColor::ToString() const
return ss; return ss;
} }
inline NzColor NzColor::operator+(const NzColor& color) const inline Color Color::operator+(const Color& color) const
{ {
NzColor c; Color c;
c.r = std::min(static_cast<unsigned int>(r) + static_cast<unsigned int>(color.r), 255U); 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.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.b = std::min(static_cast<unsigned int>(b) + static_cast<unsigned int>(color.b), 255U);
@ -61,9 +63,9 @@ inline NzColor NzColor::operator+(const NzColor& color) const
return c; return c;
} }
inline NzColor NzColor::operator*(const NzColor& color) const inline Color Color::operator*(const Color& color) const
{ {
NzColor c; Color c;
c.r = (static_cast<unsigned int>(r) * static_cast<unsigned int>(color.r)) / 255U; 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.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.b = (static_cast<unsigned int>(b) * static_cast<unsigned int>(color.b)) / 255U;
@ -72,46 +74,46 @@ inline NzColor NzColor::operator*(const NzColor& color) const
return c; return c;
} }
inline NzColor NzColor::operator+=(const NzColor& color) inline Color Color::operator+=(const Color& color)
{ {
return operator=(operator+(color)); return operator=(operator+(color));
} }
inline NzColor NzColor::operator*=(const NzColor& color) inline Color Color::operator*=(const Color& color)
{ {
return operator=(operator*(color)); return operator=(operator*(color));
} }
inline bool NzColor::operator==(const NzColor& color) const inline bool Color::operator==(const Color& color) const
{ {
return r == color.r && g == color.g && b == color.b && a == color.a; return r == color.r && g == color.g && b == color.b && a == color.a;
} }
inline bool NzColor::operator!=(const NzColor& color) const inline bool Color::operator!=(const Color& color) const
{ {
return !operator==(color); return !operator==(color);
} }
// Algorithmes venant de http://www.easyrgb.com/index.php?X=MATH // Algorithmes venant de http://www.easyrgb.com/index.php?X=MATH
inline NzColor NzColor::FromCMY(float cyan, float magenta, float yellow) inline Color Color::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)); 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 NzColor NzColor::FromCMYK(float cyan, float magenta, float yellow, float black) inline Color Color::FromCMYK(float cyan, float magenta, float yellow, float black)
{ {
return FromCMY(cyan * (1.f - black) + black, return FromCMY(cyan * (1.f - black) + black,
magenta * (1.f - black) + black, magenta * (1.f - black) + black,
yellow * (1.f - black) + black); yellow * (1.f - black) + black);
} }
inline NzColor NzColor::FromHSL(nzUInt8 hue, nzUInt8 saturation, nzUInt8 lightness) inline Color Color::FromHSL(UInt8 hue, UInt8 saturation, UInt8 lightness)
{ {
if (saturation == 0) if (saturation == 0)
{ {
// RGB results from 0 to 255 // RGB results from 0 to 255
return NzColor(lightness * 255, return Color(lightness * 255,
lightness * 255, lightness * 255,
lightness * 255); lightness * 255);
} }
@ -130,22 +132,22 @@ inline NzColor NzColor::FromHSL(nzUInt8 hue, nzUInt8 saturation, nzUInt8 lightne
float v1 = 2.f * l - v2; float v1 = 2.f * l - v2;
return NzColor(static_cast<nzUInt8>(255.f * Hue2RGB(v1, v2, h + (1.f/3.f))), return Color(static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h + (1.f/3.f))),
static_cast<nzUInt8>(255.f * Hue2RGB(v1, v2, h)), static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h)),
static_cast<nzUInt8>(255.f * Hue2RGB(v1, v2, h - (1.f/3.f)))); static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h - (1.f/3.f))));
} }
} }
inline NzColor NzColor::FromHSV(float hue, float saturation, float value) inline Color Color::FromHSV(float hue, float saturation, float value)
{ {
if (NzNumberEquals(saturation, 0.f)) if (NumberEquals(saturation, 0.f))
return NzColor(static_cast<nzUInt8>(value * 255.f)); return Color(static_cast<UInt8>(value * 255.f));
else else
{ {
float h = hue/360.f * 6.f; float h = hue/360.f * 6.f;
float s = saturation/360.f; float s = saturation/360.f;
if (NzNumberEquals(h, 6.f)) if (NumberEquals(h, 6.f))
h = 0; // hue must be < 1 h = 0; // hue must be < 1
int i = static_cast<unsigned int>(h); int i = static_cast<unsigned int>(h);
@ -194,15 +196,15 @@ inline NzColor NzColor::FromHSV(float hue, float saturation, float value)
} }
// RGB results from 0 to 255 // RGB results from 0 to 255
return NzColor(static_cast<nzUInt8>(r*255.f), static_cast<nzUInt8>(g*255.f), static_cast<nzUInt8>(b*255.f)); return Color(static_cast<UInt8>(r*255.f), static_cast<UInt8>(g*255.f), static_cast<UInt8>(b*255.f));
} }
} }
inline NzColor NzColor::FromXYZ(const NzVector3f& vec) inline Color Color::FromXYZ(const Vector3f& vec)
{ {
return FromXYZ(vec.x, vec.y, vec.z); return FromXYZ(vec.x, vec.y, vec.z);
} }
inline NzColor NzColor::FromXYZ(float x, float y, float z) inline Color Color::FromXYZ(float x, float y, float z)
{ {
x /= 100.f; // X from 0 to 95.047 x /= 100.f; // X from 0 to 95.047
y /= 100.f; // Y from 0 to 100.000 y /= 100.f; // Y from 0 to 100.000
@ -227,24 +229,24 @@ inline NzColor NzColor::FromXYZ(float x, float y, float z)
else else
b *= 12.92f; b *= 12.92f;
return NzColor(static_cast<nzUInt8>(r * 255.f), static_cast<nzUInt8>(g * 255.f), static_cast<nzUInt8>(b * 255.f)); return Color(static_cast<UInt8>(r * 255.f), static_cast<UInt8>(g * 255.f), static_cast<UInt8>(b * 255.f));
} }
inline void NzColor::ToCMY(const NzColor& color, float* cyan, float* magenta, float* yellow) inline void Color::ToCMY(const Color& color, float* cyan, float* magenta, float* yellow)
{ {
*cyan = 1.f - color.r/255.f; *cyan = 1.f - color.r/255.f;
*magenta = 1.f - color.g/255.f; *magenta = 1.f - color.g/255.f;
*yellow = 1.f - color.b/255.f; *yellow = 1.f - color.b/255.f;
} }
inline void NzColor::ToCMYK(const NzColor& color, float* cyan, float* magenta, float* yellow, float* black) inline void Color::ToCMYK(const Color& color, float* cyan, float* magenta, float* yellow, float* black)
{ {
float c, m, y; float c, m, y;
ToCMY(color, &c, &m, &y); ToCMY(color, &c, &m, &y);
float k = std::min({1.f, c, m, y}); float k = std::min({1.f, c, m, y});
if (NzNumberEquals(k, 1.f)) if (NumberEquals(k, 1.f))
{ {
//Black //Black
*cyan = 0.f; *cyan = 0.f;
@ -261,7 +263,7 @@ inline void NzColor::ToCMYK(const NzColor& color, float* cyan, float* magenta, f
*black = k; *black = k;
} }
inline void NzColor::ToHSL(const NzColor& color, nzUInt8* hue, nzUInt8* saturation, nzUInt8* lightness) inline void Color::ToHSL(const Color& color, UInt8* hue, UInt8* saturation, UInt8* lightness)
{ {
float r = color.r / 255.f; float r = color.r / 255.f;
float g = color.g / 255.f; float g = color.g / 255.f;
@ -274,7 +276,7 @@ inline void NzColor::ToHSL(const NzColor& color, nzUInt8* hue, nzUInt8* saturati
float l = (max + min)/2.f; float l = (max + min)/2.f;
if (NzNumberEquals(deltaMax, 0.f)) if (NumberEquals(deltaMax, 0.f))
{ {
//This is a gray, no chroma... //This is a gray, no chroma...
*hue = 0; //HSL results from 0 to 1 *hue = 0; //HSL results from 0 to 1
@ -284,20 +286,20 @@ inline void NzColor::ToHSL(const NzColor& color, nzUInt8* hue, nzUInt8* saturati
{ {
//Chromatic data... //Chromatic data...
if (l < 0.5f) if (l < 0.5f)
*saturation = static_cast<nzUInt8>(deltaMax/(max+min)*240.f); *saturation = static_cast<UInt8>(deltaMax/(max+min)*240.f);
else else
*saturation = static_cast<nzUInt8>(deltaMax/(2.f-max-min)*240.f); *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;
@ -307,11 +309,11 @@ inline void NzColor::ToHSL(const NzColor& color, nzUInt8* hue, nzUInt8* saturati
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 r = color.r / 255.f;
float g = color.g / 255.f; float g = color.g / 255.f;
@ -324,7 +326,7 @@ inline void NzColor::ToHSV(const NzColor& color, float* hue, float* saturation,
*value = max; *value = max;
if (NzNumberEquals(deltaMax, 0.f)) if (NumberEquals(deltaMax, 0.f))
{ {
//This is a gray, no chroma... //This is a gray, no chroma...
*hue = 0; //HSV results from 0 to 1 *hue = 0; //HSV results from 0 to 1
@ -341,9 +343,9 @@ inline void NzColor::ToHSV(const NzColor& color, float* hue, float* saturation,
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;
@ -357,12 +359,12 @@ inline void NzColor::ToHSV(const NzColor& color, float* hue, float* saturation,
} }
} }
inline void NzColor::ToXYZ(const NzColor& color, NzVector3f* vec) inline void Color::ToXYZ(const Color& color, Vector3f* vec)
{ {
return ToXYZ(color, &vec->x, &vec->y, &vec->z); return ToXYZ(color, &vec->x, &vec->y, &vec->z);
} }
inline void NzColor::ToXYZ(const NzColor& color, float* x, float* y, float* 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 r = color.r/255.f; //R from 0 to 255
float g = color.g/255.f; //G from 0 to 255 float g = color.g/255.f; //G from 0 to 255
@ -393,7 +395,7 @@ inline void NzColor::ToXYZ(const NzColor& color, float* x, float* y, float* z)
*z = r*0.0193f + g*0.1192f + b*0.9505f; *z = r*0.0193f + g*0.1192f + b*0.9505f;
} }
inline float NzColor::Hue2RGB(float v1, float v2, float vH) inline float Color::Hue2RGB(float v1, float v2, float vH)
{ {
if (vH < 0.f) if (vH < 0.f)
vH += 1; vH += 1;
@ -412,8 +414,9 @@ inline float NzColor::Hue2RGB(float v1, float v2, float vH)
return v1; return v1;
} }
}
inline std::ostream& operator<<(std::ostream& out, const NzColor& color) inline std::ostream& operator<<(std::ostream& out, const Nz::Color& color)
{ {
return out << color.ToString(); return out << color.ToString();
} }

View File

@ -9,28 +9,31 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
class NzConditionVariableImpl; namespace Nz
class NzMutex; {
class ConditionVariableImpl;
class Mutex;
class NAZARA_CORE_API NzConditionVariable class NAZARA_CORE_API ConditionVariable
{ {
public: public:
NzConditionVariable(); ConditionVariable();
NzConditionVariable(const NzConditionVariable&) = delete; ConditionVariable(const ConditionVariable&) = delete;
NzConditionVariable(NzConditionVariable&&) = delete; ///TODO ConditionVariable(ConditionVariable&&) = delete; ///TODO
~NzConditionVariable(); ~ConditionVariable();
void Signal(); void Signal();
void SignalAll(); void SignalAll();
void Wait(NzMutex* mutex); void Wait(Mutex* mutex);
bool Wait(NzMutex* mutex, nzUInt32 timeout); bool Wait(Mutex* mutex, UInt32 timeout);
NzConditionVariable& operator=(const NzConditionVariable&) = delete; ConditionVariable& operator=(const ConditionVariable&) = delete;
NzConditionVariable& operator=(NzConditionVariable&&) = delete; ///TODO ConditionVariable& operator=(ConditionVariable&&) = delete; ///TODO
private: private:
NzConditionVariableImpl* m_impl; 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,11 +10,13 @@
#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
{
class NAZARA_CORE_API Core
{ {
public: public:
NzCore() = delete; Core() = delete;
~NzCore() = delete; ~Core() = delete;
static bool Initialize(); static bool Initialize();
@ -25,5 +27,6 @@ class NAZARA_CORE_API NzCore
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

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

View File

@ -26,34 +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
{
using DynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction
class NzDynLibImpl; class DynLibImpl;
class NAZARA_CORE_API NzDynLib class NAZARA_CORE_API DynLib
{ {
public: public:
NzDynLib(); DynLib();
NzDynLib(const NzDynLib&) = delete; DynLib(const DynLib&) = delete;
NzDynLib(NzDynLib&& lib); DynLib(DynLib&& lib);
~NzDynLib(); ~DynLib();
NzString GetLastError() const; String GetLastError() const;
NzDynLibFunc GetSymbol(const NzString& symbol) const; DynLibFunc GetSymbol(const String& symbol) const;
bool IsLoaded() const; bool IsLoaded() const;
bool Load(const NzString& libraryPath); bool Load(const String& libraryPath);
void Unload(); void Unload();
NzDynLib& operator=(const NzDynLib&) = delete; DynLib& operator=(const DynLib&) = delete;
NzDynLib& operator=(NzDynLib&& lib); DynLib& operator=(DynLib&& lib);
private: private:
NazaraMutexAttrib(m_mutex, mutable) NazaraMutexAttrib(m_mutex, mutable)
mutable NzString m_lastError; mutable String m_lastError;
NzDynLibImpl* m_impl; 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()
{
#if defined(NAZARA_BIG_ENDIAN)
return Endianness_BigEndian;
#elif defined(NAZARA_LITTLE_ENDIAN)
return Endianness_LittleEndian;
#endif
}
inline void SwapBytes(void* buffer, unsigned int size)
{
UInt8* bytes = reinterpret_cast<UInt8*>(buffer);
unsigned int i = 0; unsigned int i = 0;
unsigned int j = size-1; unsigned int j = size-1;
while (i < j) while (i < j)
std::swap(bytes[i++], bytes[j--]); std::swap(bytes[i++], bytes[j--]);
} }
inline nzEndianness NzGetPlatformEndianness()
{
#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
{
class NAZARA_CORE_API Error
{ {
public: public:
NzError() = delete; Error() = delete;
~NzError() = 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 nzUInt32 GetFlags();
static NzString GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr);
static unsigned int GetLastSystemErrorCode(); static unsigned int GetLastSystemErrorCode();
static NzString GetLastSystemError(unsigned int code = GetLastSystemErrorCode()); static String GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
static void SetFlags(nzUInt32 flags); static void SetFlags(UInt32 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

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

View File

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

View File

@ -11,17 +11,19 @@
// 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();
@ -30,9 +32,9 @@ struct NzFunctorWithoutArgs : NzFunctor
}; };
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();
@ -42,9 +44,9 @@ struct NzFunctorWithArgs : NzFunctor
}; };
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();
@ -52,6 +54,7 @@ struct NzMemberWithoutArgs : NzFunctor
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>
namespace Nz
{
template<typename F> template<typename F>
NzFunctorWithoutArgs<F>::NzFunctorWithoutArgs(F func) : FunctorWithoutArgs<F>::FunctorWithoutArgs(F func) :
m_func(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,43 +15,45 @@
#include <Nazara/Math/Rect.hpp> #include <Nazara/Math/Rect.hpp>
#include <vector> #include <vector>
class NAZARA_CORE_API NzGuillotineBinPack namespace Nz
{
class NAZARA_CORE_API GuillotineBinPack
{ {
public: public:
enum FreeRectChoiceHeuristic : int; enum FreeRectChoiceHeuristic : int;
enum GuillotineSplitHeuristic : 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
{ {
@ -74,15 +76,16 @@ class NAZARA_CORE_API NzGuillotineBinPack
}; };
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,21 +11,23 @@
#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
{
class NAZARA_CORE_API HardwareInfo
{ {
public: public:
NzHardwareInfo() = delete; HardwareInfo() = delete;
~NzHardwareInfo() = delete; ~HardwareInfo() = delete;
static void Cpuid(nzUInt32 functionId, nzUInt32 subFunctionId, nzUInt32 result[4]); static void Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 result[4]);
static NzString GetProcessorBrandString(); static String GetProcessorBrandString();
static unsigned int GetProcessorCount(); static unsigned int GetProcessorCount();
static nzProcessorVendor GetProcessorVendor(); static ProcessorVendor GetProcessorVendor();
static NzString GetProcessorVendorName(); static String GetProcessorVendorName();
static nzUInt64 GetTotalMemory(); static UInt64 GetTotalMemory();
static bool HasCapability(nzProcessorCap capability); static bool HasCapability(ProcessorCap capability);
static bool Initialize(); static bool Initialize();
@ -34,5 +36,6 @@ class NAZARA_CORE_API NzHardwareInfo
static void Uninitialize(); static void Uninitialize();
}; };
}
#endif // NAZARA_HARDWAREINFO_HPP #endif // NAZARA_HARDWAREINFO_HPP

View File

@ -12,22 +12,25 @@
#include <Nazara/Core/Hashable.hpp> #include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/HashDigest.hpp> #include <Nazara/Core/HashDigest.hpp>
class NAZARA_CORE_API NzHash namespace Nz
{
class NAZARA_CORE_API Hash
{ {
public: public:
NzHash(nzHash hash); Hash(HashType hash);
NzHash(NzAbstractHash* hashImpl); Hash(AbstractHash* hashImpl);
NzHash(const NzHash&) = delete; Hash(const Hash&) = delete;
NzHash(NzHash&&) = delete; ///TODO Hash(Hash&&) = delete; ///TODO
~NzHash(); ~Hash();
NzHashDigest Hash(const NzHashable& hashable); HashDigest Process(const Hashable& hashable);
NzHash& operator=(const NzHash&) = delete; Hash& operator=(const Hash&) = delete;
NzHash& operator=(NzHash&&) = delete; ///TODO Hash& operator=(Hash&&) = delete; ///TODO
private: private:
NzAbstractHash* m_impl; 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
{
struct HashCRC32_state;
class NAZARA_CORE_API NzHashCRC32 : public NzAbstractHash class NAZARA_CORE_API HashCRC32 : public AbstractHash
{ {
public: public:
NzHashCRC32(nzUInt32 polynomial = 0x04c11db7); HashCRC32(UInt32 polynomial = 0x04c11db7);
virtual ~NzHashCRC32(); virtual ~HashCRC32();
void Append(const nzUInt8* data, unsigned int len); void Append(const UInt8* data, unsigned int len);
void Begin(); void Begin();
NzHashDigest End(); HashDigest End();
static unsigned int GetDigestLength(); static unsigned int GetDigestLength();
static NzString GetHashName(); static String GetHashName();
private: private:
NzHashCRC32_state* m_state; 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
{
struct HashFletcher16_state;
class NAZARA_CORE_API NzHashFletcher16 : public NzAbstractHash class NAZARA_CORE_API HashFletcher16 : public AbstractHash
{ {
public: public:
NzHashFletcher16(); HashFletcher16();
virtual ~NzHashFletcher16(); virtual ~HashFletcher16();
void Append(const nzUInt8* data, unsigned int len); void Append(const UInt8* data, unsigned int len);
void Begin(); void Begin();
NzHashDigest End(); HashDigest End();
static unsigned int GetDigestLength(); static unsigned int GetDigestLength();
static NzString GetHashName(); static String GetHashName();
private: private:
NzHashFletcher16_state* m_state; 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
{
struct HashMD5_state;
class NAZARA_CORE_API NzHashMD5 : public NzAbstractHash class NAZARA_CORE_API HashMD5 : public AbstractHash
{ {
public: public:
NzHashMD5(); HashMD5();
virtual ~NzHashMD5(); virtual ~HashMD5();
void Append(const nzUInt8* data, unsigned int len); void Append(const UInt8* data, unsigned int len);
void Begin(); void Begin();
NzHashDigest End(); HashDigest End();
static unsigned int GetDigestLength(); static unsigned int GetDigestLength();
static NzString GetHashName(); static String GetHashName();
private: private:
NzHashMD5_state* m_state; 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>
namespace Nz
{
union SHA_CTX; union SHA_CTX;
class NAZARA_CORE_API NzHashSHA1 : public NzAbstractHash class NAZARA_CORE_API HashSHA1 : public AbstractHash
{ {
public: public:
NzHashSHA1(); HashSHA1();
virtual ~NzHashSHA1(); virtual ~HashSHA1();
void Append(const nzUInt8* data, unsigned int len); void Append(const UInt8* data, unsigned int len);
void Begin(); void Begin();
NzHashDigest End(); HashDigest End();
static unsigned int GetDigestLength(); static unsigned int GetDigestLength();
static NzString GetHashName(); static String GetHashName();
private: private:
SHA_CTX* m_state; 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>
namespace Nz
{
union SHA_CTX; union SHA_CTX;
class NAZARA_CORE_API NzHashSHA224 : public NzAbstractHash class NAZARA_CORE_API HashSHA224 : public AbstractHash
{ {
public: public:
NzHashSHA224(); HashSHA224();
virtual ~NzHashSHA224(); virtual ~HashSHA224();
void Append(const nzUInt8* data, unsigned int len); void Append(const UInt8* data, unsigned int len);
void Begin(); void Begin();
NzHashDigest End(); HashDigest End();
static unsigned int GetDigestLength(); static unsigned int GetDigestLength();
static NzString GetHashName(); static String GetHashName();
private: private:
SHA_CTX* m_state; 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>
namespace Nz
{
union SHA_CTX; union SHA_CTX;
class NAZARA_CORE_API NzHashSHA256 : public NzAbstractHash class NAZARA_CORE_API HashSHA256 : public AbstractHash
{ {
public: public:
NzHashSHA256(); HashSHA256();
virtual ~NzHashSHA256(); virtual ~HashSHA256();
void Append(const nzUInt8* data, unsigned int len); void Append(const UInt8* data, unsigned int len);
void Begin(); void Begin();
NzHashDigest End(); HashDigest End();
static unsigned int GetDigestLength(); static unsigned int GetDigestLength();
static NzString GetHashName(); static String GetHashName();
private: private:
SHA_CTX* m_state; 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>
namespace Nz
{
union SHA_CTX; union SHA_CTX;
class NAZARA_CORE_API NzHashSHA384 : public NzAbstractHash class NAZARA_CORE_API HashSHA384 : public AbstractHash
{ {
public: public:
NzHashSHA384(); HashSHA384();
virtual ~NzHashSHA384(); virtual ~HashSHA384();
void Append(const nzUInt8* data, unsigned int len); void Append(const UInt8* data, unsigned int len);
void Begin(); void Begin();
NzHashDigest End(); HashDigest End();
static unsigned int GetDigestLength(); static unsigned int GetDigestLength();
static NzString GetHashName(); static String GetHashName();
private: private:
SHA_CTX* m_state; 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>
namespace Nz
{
union SHA_CTX; union SHA_CTX;
class NAZARA_CORE_API NzHashSHA512 : public NzAbstractHash class NAZARA_CORE_API HashSHA512 : public AbstractHash
{ {
public: public:
NzHashSHA512(); HashSHA512();
virtual ~NzHashSHA512(); virtual ~HashSHA512();
void Append(const nzUInt8* data, unsigned int len); void Append(const UInt8* data, unsigned int len);
void Begin(); void Begin();
NzHashDigest End(); HashDigest End();
static unsigned int GetDigestLength(); static unsigned int GetDigestLength();
static NzString GetHashName(); static String GetHashName();
private: private:
SHA_CTX* m_state; 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
{
struct HashWhirlpool_state;
class NAZARA_CORE_API NzHashWhirlpool : public NzAbstractHash class NAZARA_CORE_API HashWhirlpool : public AbstractHash
{ {
public: public:
NzHashWhirlpool(); HashWhirlpool();
virtual ~NzHashWhirlpool(); virtual ~HashWhirlpool();
void Append(const nzUInt8* data, unsigned int len); void Append(const UInt8* data, unsigned int len);
void Begin(); void Begin();
NzHashDigest End(); HashDigest End();
static unsigned int GetDigestLength(); static unsigned int GetDigestLength();
static NzString GetHashName(); static String GetHashName();
private: private:
NzHashWhirlpool_state* m_state; 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
{
class NAZARA_CORE_API HashDigest
{ {
public: public:
NzHashDigest(); HashDigest();
NzHashDigest(const NzString& hashName, const nzUInt8* digest, unsigned int length); HashDigest(const String& hashName, const UInt8* digest, unsigned int length);
NzHashDigest(const NzHashDigest& rhs); HashDigest(const HashDigest& rhs);
NzHashDigest(NzHashDigest&& rhs) noexcept; HashDigest(HashDigest&& rhs) noexcept;
~NzHashDigest(); ~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,27 +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;
class NAZARA_CORE_API Hashable
{
friend class Hash;
public: public:
NzHashable() = default; Hashable() = default;
NzHashable(const NzHashable&) = default; Hashable(const Hashable&) = default;
NzHashable(NzHashable&&) = default; Hashable(Hashable&&) = default;
virtual ~NzHashable(); virtual ~Hashable();
NzHashDigest GetHash(nzHash hash) const; HashDigest GetHash(HashType hash) const;
NzHashDigest GetHash(NzAbstractHash* impl) const; HashDigest GetHash(AbstractHash* impl) const;
NzHashable& operator=(const NzHashable&) = default; Hashable& operator=(const Hashable&) = default;
NzHashable& operator=(NzHashable&&) = default; Hashable& operator=(Hashable&&) = default;
private: private:
virtual bool FillHash(NzAbstractHash* impl) const = 0; virtual bool FillHash(AbstractHash* impl) const = 0;
}; };
}
#endif // HASHABLE_HPP_INCLUDED #endif // HASHABLE_HPP_INCLUDED

View File

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

View File

@ -4,16 +4,20 @@
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
template<typename...> struct NzImplInitializer; namespace Nz
{
namespace Detail
{
template<typename...> struct Initializer;
template<typename T, typename... Rest> template<typename T, typename... Rest>
struct NzImplInitializer<T, Rest...> struct Initializer<T, Rest...>
{ {
static bool Init() static bool Init()
{ {
if (T::Initialize()) if (T::Initialize())
{ {
if (NzImplInitializer<Rest...>::Init()) if (Initializer<Rest...>::Init())
return true; return true;
else else
T::Uninitialize(); T::Uninitialize();
@ -24,13 +28,13 @@ struct NzImplInitializer<T, Rest...>
static void Uninit() static void Uninit()
{ {
NzImplInitializer<Rest...>::Uninit(); Initializer<Rest...>::Uninit();
T::Uninitialize(); T::Uninitialize();
} }
}; };
template<> template<>
struct NzImplInitializer<> struct Initializer<>
{ {
static bool Init() static bool Init()
{ {
@ -41,9 +45,11 @@ struct NzImplInitializer<>
{ {
} }
}; };
}
template<typename... Args> template<typename... Args>
NzInitializer<Args...>::NzInitializer(bool initialize) : Initializer<Args...>::Initializer(bool initialize) :
m_initialized(false) m_initialized(false)
{ {
if (initialize) if (initialize)
@ -51,37 +57,38 @@ m_initialized(false)
} }
template<typename... Args> template<typename... Args>
NzInitializer<Args...>::~NzInitializer() Initializer<Args...>::~Initializer()
{ {
Uninitialize(); Uninitialize();
} }
template<typename... Args> template<typename... Args>
bool NzInitializer<Args...>::Initialize() bool Initializer<Args...>::Initialize()
{ {
if (!m_initialized) if (!m_initialized)
m_initialized = NzImplInitializer<Args...>::Init(); m_initialized = Detail::Initializer<Args...>::Init();
return m_initialized; return m_initialized;
} }
template<typename... Args> template<typename... Args>
bool NzInitializer<Args...>::IsInitialized() const bool Initializer<Args...>::IsInitialized() const
{ {
return m_initialized; return m_initialized;
} }
template<typename... Args> template<typename... Args>
void NzInitializer<Args...>::Uninitialize() void Initializer<Args...>::Uninitialize()
{ {
if (m_initialized) if (m_initialized)
NzImplInitializer<Args...>::Uninit(); Detail::Initializer<Args...>::Uninit();
} }
template<typename... Args> template<typename... Args>
NzInitializer<Args...>::operator bool() const Initializer<Args...>::operator bool() const
{ {
return IsInitialized(); 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
{
class NAZARA_CORE_API InputStream : public Stream
{ {
public: public:
virtual ~NzInputStream(); 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 Mutex;
class NAZARA_CORE_API NzLockGuard class NAZARA_CORE_API LockGuard
{ {
public: public:
NzLockGuard(NzMutex& mutex); LockGuard(Mutex& mutex);
~NzLockGuard(); ~LockGuard();
private: private:
NzMutex& m_mutex; Mutex& m_mutex;
}; };
}
#endif // NAZARA_LOCKGUARD_HPP #endif // NAZARA_LOCKGUARD_HPP

View File

@ -23,46 +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 File;
class NAZARA_CORE_API NzLog class NAZARA_CORE_API Log
{ {
public: public:
void Enable(bool enable); void Enable(bool enable);
void EnableAppend(bool enable); void EnableAppend(bool enable);
void EnableDateTime(bool enable); void EnableDateTime(bool enable);
NzString GetFile() const; String GetFile() const;
bool IsEnabled() const; bool IsEnabled() const;
void SetFile(const NzString& filePath); void SetFile(const String& filePath);
void Write(const NzString& string); void Write(const String& string);
void WriteError(nzErrorType type, const NzString& error); void WriteError(ErrorType type, const String& error);
void WriteError(nzErrorType type, const NzString& error, unsigned int line, const NzString& file, const NzString& func); void WriteError(ErrorType type, const String& error, unsigned int line, const String& file, const String& func);
static NzLog* Instance(); static Log* Instance();
private: private:
NzLog(); Log();
NzLog(const NzLog&) = delete; Log(const Log&) = delete;
NzLog(NzLog&&) = delete; Log(Log&&) = delete;
~NzLog(); ~Log();
NzLog& operator=(const NzLog&) = delete; Log& operator=(const Log&) = delete;
NzLog& operator=(NzLog&&) = delete; Log& operator=(Log&&) = delete;
NazaraMutexAttrib(m_mutex, mutable) NazaraMutexAttrib(m_mutex, mutable)
NzString m_filePath; String m_filePath;
NzFile* m_file; File* m_file;
bool m_append; bool m_append;
bool m_enabled; bool m_enabled;
bool m_writeTime; 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,29 +14,32 @@
#include <utility> #include <utility>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
inline void NzOperatorDelete(void* ptr) namespace Nz
{
inline void OperatorDelete(void* ptr)
{ {
#if NAZARA_CORE_MANAGE_MEMORY #if NAZARA_CORE_MANAGE_MEMORY
NzMemoryManager::Free(ptr); MemoryManager::Free(ptr);
#else #else
operator delete(ptr); operator delete(ptr);
#endif #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>

View File

@ -11,7 +11,9 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
class NAZARA_CORE_API NzMemoryManager namespace Nz
{
class NAZARA_CORE_API MemoryManager
{ {
public: public:
static void* Allocate(std::size_t size, bool multi = false, const char* file = nullptr, unsigned int line = 0); static void* Allocate(std::size_t size, bool multi = false, const char* file = nullptr, unsigned int line = 0);
@ -31,12 +33,13 @@ class NAZARA_CORE_API NzMemoryManager
static void NextFree(const char* file, unsigned int line); static void NextFree(const char* file, unsigned int line);
private: private:
NzMemoryManager(); MemoryManager();
~NzMemoryManager(); ~MemoryManager();
static void Initialize(); static void Initialize();
static void TimeInfo(char buffer[23]); static void TimeInfo(char buffer[23]);
static void Uninitialize(); static void Uninitialize();
}; };
}
#endif // NAZARA_MEMORYMANAGER_HPP #endif // NAZARA_MEMORYMANAGER_HPP

View File

@ -11,13 +11,15 @@
#include <atomic> #include <atomic>
#include <memory> #include <memory>
class NzMemoryPool namespace Nz
{
class MemoryPool
{ {
public: public:
NzMemoryPool(unsigned int blockSize, unsigned int size = 1024, bool canGrow = true); MemoryPool(unsigned int blockSize, unsigned int size = 1024, bool canGrow = true);
NzMemoryPool(const NzMemoryPool&) = delete; MemoryPool(const MemoryPool&) = delete;
NzMemoryPool(NzMemoryPool&& pool) noexcept; MemoryPool(MemoryPool&& pool) noexcept;
~NzMemoryPool() = default; ~MemoryPool() = default;
void* Allocate(unsigned int size); void* Allocate(unsigned int size);
template<typename T> void Delete(T* ptr); template<typename T> void Delete(T* ptr);
@ -29,21 +31,22 @@ class NzMemoryPool
template<typename T, typename... Args> T* New(Args&&... args); template<typename T, typename... Args> T* New(Args&&... args);
NzMemoryPool& operator=(const NzMemoryPool&) = delete; MemoryPool& operator=(const MemoryPool&) = delete;
NzMemoryPool& operator=(NzMemoryPool&& pool) noexcept; MemoryPool& operator=(MemoryPool&& pool) noexcept;
private: private:
NzMemoryPool(NzMemoryPool* pool); MemoryPool(MemoryPool* pool);
std::unique_ptr<void*[]> m_freeList; std::unique_ptr<void*[]> m_freeList;
std::unique_ptr<nzUInt8[]> m_pool; std::unique_ptr<UInt8[]> m_pool;
std::unique_ptr<NzMemoryPool> m_next; std::unique_ptr<MemoryPool> m_next;
std::atomic_uint m_freeCount; std::atomic_uint m_freeCount;
NzMemoryPool* m_previous; MemoryPool* m_previous;
bool m_canGrow; bool m_canGrow;
unsigned int m_blockSize; unsigned int m_blockSize;
unsigned int m_size; unsigned int m_size;
}; };
}
#include <Nazara/Core/MemoryPool.inl> #include <Nazara/Core/MemoryPool.inl>

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