Refactored mathematics module

Added AABBs
Added code examples
Added experimental support for texture arrays (1D/2D)
Added initialisers (new way of initialising modules)
Added global headers (Plus a global header generator script)
Added pattern support for directory
Added support for spinlocks critical section on Windows
Added NzRenderWindow::SetFramerateLimit
Core project now includes Mathematics files
Fixed color implementation using double
Fixed declaration needing renderer include
Fixed MLT not clearing nextFree(File/Line) after Free
Fixed move operators not being noexcept
Fixed thread-safety (Now working correctly - If I'm lucky)
Moved Resource to core
New interface for modules
New interface for the renderer
Put some global functions to anonymous namespace
Removed empty modules
Renamed ThreadCondition to ConditionVariable
Replaced redirect to cerr log option by duplicate to cout
Setting mouse position relative to a window will make this window ignore
the event
Shaders sending methods no longer takes the uniform variable name (it's
using ID instead)
Using new OpenGL 4.3 header
This commit is contained in:
Lynix 2012-08-08 04:44:17 +02:00
parent 06eda4eba9
commit b442ab0bd2
142 changed files with 6861 additions and 2326 deletions

View File

@ -8,20 +8,22 @@
#define NAZARA_MODULENAME_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
class NAZARA_API NzModuleName
{
public:
NzModuleName();
~NzModuleName();
NzModuleName() = delete;
~NzModuleName() = delete;
bool Initialize();
void Uninitialize();
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static bool s_initialized;
static unsigned int s_moduleReferenceCouter;
};
#endif // NAZARA_MODULENAME_HPP

View File

@ -3,55 +3,47 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/ModuleName/ModuleName.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/ModuleName/Config.hpp>
#include <Nazara/ModuleName/Debug.hpp>
NzModuleName::NzModuleName()
{
}
NzModuleName::~NzModuleName()
{
if (s_initialized)
Uninitialize();
}
bool NzModuleName::Initialize()
{
#if NAZARA_MODULENAME_SAFE
if (s_initialized)
if (s_moduleReferenceCouter++ != 0)
return true; // Déjà initialisé
// Initialisation des dépendances
if (!NzCore::Initialize())
{
NazaraError("ModuleName already initialized");
return true;
NazaraError("Failed to initialize core module");
return false;
}
#endif
// Initialisation du module
s_initialized = true;
NazaraNotice("Initialized: ModuleName module");
return true;
}
bool NzModuleName::IsInitialized()
{
return s_moduleReferenceCouter != 0;
}
void NzModuleName::Uninitialize()
{
#if NAZARA_MODULENAME_SAFE
if (!s_initialized)
{
NazaraError("ModuleName not initialized");
return;
}
#endif
if (--s_moduleReferenceCouter != 0)
return; // Encore utilisé
// Libération du module
s_initialized = false;
NazaraNotice("Uninitialized: ModuleName module");
// Libération des dépendances
NzCore::Uninitialize();
}
bool NzModuleName::IsInitialized()
{
return s_initialized;
}
bool NzModuleName::s_initialized = false;
unsigned int NzModuleName::s_moduleReferenceCouter = 0;

View File

@ -0,0 +1 @@
premake4 --with-examples codeblocks

View File

@ -0,0 +1 @@
premake4 --with-examples vs2010

View File

@ -0,0 +1,2 @@
premake4 generateheaders
pause

View File

@ -0,0 +1,10 @@
function examples()
dofile("../examples/build/common.lua")
end
newaction
{
trigger = "examples",
description = "Generate examples",
execute = examples
}

View File

@ -0,0 +1,54 @@
function generateHeaders()
local modules = os.matchdirs("../include/Nazara/*")
for k, modulePath in pairs(modules) do
local moduleName = modulePath:match(".*/(.*)")
print(moduleName)
local config, err = io.open(modulePath .. "/Config.hpp", "r")
local head = ""
if (not config) then
error("Failed to read config file: " .. err)
end
for line in config:lines() do
head = head .. line .. "\n"
if (line == "#pragma once") then -- On s'arrête au #pragma once, qu'on inclut quand même
break
end
end
config:close()
local header, err = io.open(modulePath .. ".hpp", "w+")
if (not header) then
error("Failed to create header file: " .. err)
end
header:write("// This file was automatically generated by Nazara\n\n")
header:write(head .. "\n")
local files = os.matchfiles(modulePath .. "/*.hpp")
local count = 0
for k, filePath in pairs(files) do
local include, fileName = filePath:match(".*(Nazara/.*/(.*))")
if (fileName ~= "Debug.hpp" and
fileName ~= "DebugOff.hpp" and
fileName ~= "ThreadSafety.hpp" and
fileName ~= "ThreadSafetyOff.hpp") then
header:write("#include <" .. include .. ">\n")
count = count + 1
end
end
print(string.format("-# of includes: %d", count))
header:close()
end
end
newaction
{
trigger = "generateheaders",
description = "Generate a global header for each module",
execute = generateHeaders
}

View File

@ -9,11 +9,14 @@ configurations
defines "NAZARA_BUILD"
language "C++"
location(_ACTION)
includedirs
{
"../include",
"../src/"
}
libdirs "../lib"
targetdir "../lib"
@ -22,7 +25,7 @@ configuration "Debug*"
flags "Symbols"
configuration "Release*"
flags { "Optimize", "OptimizeSpeed" }
flags { "EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer", "NoRTTI" }
configuration "*Static"
defines "NAZARA_STATIC"

View File

@ -0,0 +1,33 @@
-- Configuration générale
configurations
{
"DebugStatic",
"ReleaseStatic",
"DebugDLL",
"ReleaseDLL"
}
language "C++"
location("../examples/build/" .. _ACTION)
includedirs
{
"../include"
}
debugdir "../examples/bin"
libdirs "../lib"
targetdir "../examples/bin"
configuration "Debug*"
defines "NAZARA_DEBUG"
flags "Symbols"
configuration "Release*"
flags { "EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer", "NoRTTI" }
configuration "*Static"
defines "NAZARA_STATIC"
configuration "gmake"
buildoptions "-std=c++11"

View File

@ -1,31 +0,0 @@
project "NazaraAudio"
files
{
"../include/Nazara/Audio/**.hpp",
"../include/Nazara/Audio/**.inl",
"../src/Nazara/Audio/**.hpp",
"../src/Nazara/Audio/**.cpp"
}
if (os.is("windows")) then
excludes { "../src/Nazara/Audio/Posix/*.hpp", "../src/Nazara/Audio/Posix/*.cpp" }
else
excludes { "../src/Nazara/Audio/Win32/*.hpp", "../src/Nazara/Audio/Win32/*.cpp" }
end
configuration "DebugStatic"
links "NazaraCored-s"
targetname "NazaraAudiod"
configuration "ReleaseStatic"
links "NazaraCore-s"
targetname "NazaraAudio"
configuration "DebugDLL"
links "NazaraCored"
targetname "NazaraAudiod"
configuration "ReleaseDLL"
links "NazaraCore"
targetname "NazaraAudio"

View File

@ -5,6 +5,8 @@ files
"../include/Nazara/Prerequesites.hpp",
"../include/Nazara/Core/**.hpp",
"../include/Nazara/Core/**.inl",
"../include/Nazara/Math/**.hpp",
"../include/Nazara/Math/**.inl",
"../src/Nazara/Core/**.hpp",
"../src/Nazara/Core/**.cpp"
}

View File

@ -1,35 +0,0 @@
project "NazaraNetwork"
if (os.is("windows")) then
links "ws2_32"
end
files
{
"../include/Nazara/Network/**.hpp",
"../include/Nazara/Network/**.inl",
"../src/Nazara/Network/**.hpp",
"../src/Nazara/Network/**.cpp"
}
if (os.is("windows")) then
excludes { "../src/Nazara/Network/Posix/*.hpp", "../src/Nazara/Network/Posix/*.cpp" }
else
excludes { "../src/Nazara/Network/Win32/*.hpp", "../src/Nazara/Network/Win32/*.cpp" }
end
configuration "DebugStatic"
links "NazaraCored-s"
targetname "NazaraNetworkd"
configuration "ReleaseStatic"
links "NazaraCore-s"
targetname "NazaraNetwork"
configuration "DebugDLL"
links "NazaraCored"
targetname "NazaraNetworkd"
configuration "ReleaseDLL"
links "NazaraCore"
targetname "NazaraNetwork"

View File

@ -0,0 +1,23 @@
kind "ConsoleApp"
files "main.cpp"
configuration "DebugStatic"
links "NazaraCored-s"
links "NazaraRendererd-s"
links "NazaraUtilityd-s"
configuration "ReleaseStatic"
links "NazaraCore-s"
links "NazaraRenderer-s"
links "NazaraUtility-s"
configuration "DebugDLL"
links "NazaraCored"
links "NazaraRendererd"
links "NazaraUtilityd"
configuration "ReleaseDLL"
links "NazaraCore"
links "NazaraRenderer"
links "NazaraUtility"

View File

@ -0,0 +1,623 @@
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Renderer/ContextParameters.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderWindow.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/StaticMesh.hpp>
#include <iostream>
#include <map>
// Une structure pour contenir nos informations (Cette structure est très simpliste)
struct Model
{
NzMatrix4f matrix; // Les transformations subies par le modèle
NzMesh mesh; // Le mesh
NzTexture texture; // Sa texture
};
struct AnimatedModel : public Model
{
// Quelques variables pour l'animation
const NzSequence* currentSequence = nullptr; // La séquence en cours
float interpolation = 0.f; // La valeur de l'interpolation ([0..1], si dépasse 1, on passe à la frame suivante)
unsigned int currentFrame = 0; // La première frame
unsigned int nextFrame; // La seconde frame, l'animation est interpollée entre ces deux-là
};
void AnimateModel(AnimatedModel& moedel, float elapsed);
bool CreateCheckerTexture(NzTexture* texture);
bool CreateFloorMesh(NzMesh* mesh);
void DrawModel(const Model& model);
void SetSequence(AnimatedModel& model, const NzString& name);
int main()
{
// Tout d'abord on affiche les instructions
std::cout << "Camera controls: ZQSD" << std::endl;
std::cout << "Dr. Freak controls: Up, down, left and right" << std::endl;
std::cout << "Escape to quit" << std::endl;
// Cette ligne active le mode de compatibilité d'OpenGL lors de l'initialisation de Nazara (Nécessaire pour le shader)
NzContextParameters::defaultCompatibilityProfile = true;
// Maintenant nous initialisons le Renderer (Qui initialisera le noyau ainsi que le module utlitaire)
// Cette étape est obligatoire pour beaucoup de classes
NzInitializer<NzRenderer> renderer;
if (!renderer)
{
// Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log
std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl;
std::getchar(); // On laise le temps de voir l'erreur
return EXIT_FAILURE;
}
// Maintenant nous pouvons utiliser le moteur comme bon nous semble, tout d'abord nous allons charger les ressources
// Charger une ressource se fait actuellement manuellement, mais un ResourceManager est à venir
// Vous initialisez une ressource, et la chargez via sa méthode LoadFrom[File|Memory|Stream]
// Note: il est possible de donner des instructions au loader (qui va charger le fichier en ressource) via les ResourceParameters
NzMeshParams parameters;
// Le loader doit-il automatiquement charger les animations ?
// Attention, ce paramètre possède une signification différente selon le type d'animation du mesh.
// -Pour les animations keyframe (image-clé), c'est la seule et unique façon de charger les animations, étant donné
// qu'elles sont fourniees avec le mesh.
// -Pour les animations squelettiques, le loader ne fera que charger automatiquement l'animation associée au mesh s'il le peut
// Dans les deux cas, les paramètres d'animations (parameters.animation) seront utilisés
parameters.loadAnimations = true; // Vaut true par défaut
// Pour qu'un mesh puisse être rendu, il doit être stocké du côté de la carte graphique (Hardware), mais il est parfois utile de
// le stocker côté RAM, par exemple pour le moteur physique. En sachant qu'il est facile de changer le stockage d'un buffer.
parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut
AnimatedModel drfreak;
if (!drfreak.mesh.LoadFromFile("resources/drfreak.md2", parameters)) // On charge notre bon vieux docteur avec les paramètres de chargement.
{
// Le chargement n'a pas fonctionné, le modèle est peut-être corrompu/non-supporté, ou alors n'existe pas.
std::cout << "Failed to load mesh" << std::endl;
std::getchar(); // On laise le temps de voir l'erreur
return EXIT_FAILURE;
}
if (!drfreak.mesh.HasAnimation()) // Le mesh possède-t-il des animations ?
{
// Cette démo n'a aucun intérêt sans animations
std::cout << "Mesh has no animation" << std::endl;
std::getchar();
return EXIT_FAILURE;
}
SetSequence(drfreak, "stand");
// Il est possible que le mesh possède un ou plusieurs skin, nous utiliserons cette information pour charger une texture
if (drfreak.mesh.HasSkin())
{
// Contrairement aux autres ressources, la texture n'est pas critique
if (drfreak.texture.LoadFromFile("resources/" + drfreak.mesh.GetSkin()))
drfreak.texture.SetFilterMode(nzTextureFilter_Bilinear); // Appliquons-lui un filtrage bilinéaire
else
std::cout << "Failed to load texture" << std::endl;
}
if (!drfreak.texture.IsValid()) // Les méthodes Resource::IsValid indiquent si la ressource a été correctement créée
{
std::cout << "Creating checker texture for mesh" << std::endl;
if (!CreateCheckerTexture(&drfreak.texture))
{
std::cout << "Failed to create mesh texture" << std::endl;
std::getchar();
return EXIT_FAILURE;
}
}
// Nous créons maintenant notre sol
Model floor;
if (!CreateFloorMesh(&floor.mesh))
{
std::cout << "Failed to create floor" << std::endl;
std::getchar();
return EXIT_FAILURE;
}
if (!CreateCheckerTexture(&floor.texture))
{
std::cout << "Failed to create floor texture" << std::endl;
std::getchar();
return EXIT_FAILURE;
}
// Le sol ne subit aucune transformation
floor.matrix.MakeIdentity();
// Pour effectuer un rendu, il faut que la carte graphique sache quoi faire.
// Les shaders sont de petits programmes qui donnent des instructions à la carte graphique lors du pipeline.
// Ils sont aujourd'hui indispensables pour un rendu 3D, mais sont très utiles pour divers effets !
// Il existe plusieurs langages de shaders, GLSL pour OpenGL, HLSL pour Direct3D et Cg qui peut être utilisé pour les deux.
// Le Renderer de Nazara utilise OpenGL, par conséquent nous utiliserons le GLSL
// La méthode NzShader::IsLanguageSupported permet de savoir si un langage est supporté.
NzShader shader;
if (!shader.Create(nzShaderLanguage_GLSL))
{
std::cout << "Failed to load shader" << std::endl;
std::getchar();
return EXIT_FAILURE;
}
// Une fois le shader créé, nous devons lui spécifier les codes sources de nos shaders
// Pour notre exemple nous prendrons un shader très simple
// Un shader doit obligatoirement posséder au moins deux codes, un pour le fragment shader et un pour le vertex shader
if (!shader.LoadFromFile(nzShaderType_Fragment, "shaders/basic.frag"))
{
std::cout << "Failed to load fragment shader from file" << std::endl;
// À la différence des autres ressources, le shader possède un log qui peut indiquer les erreurs en cas d'échec
std::cout << "Log: " << shader.GetLog() << std::endl;
std::getchar();
return EXIT_FAILURE;
}
// Maintenant le vertex shader
if (!shader.LoadFromFile(nzShaderType_Vertex, "shaders/basic.vert"))
{
std::cout << "Failed to load vertex shader from file" << std::endl;
std::cout << "Log: " << shader.GetLog() << std::endl;
std::getchar();
return EXIT_FAILURE;
}
// Une fois le code source de nos shaders chargé, nous pouvons le compiler, afin de le rendre utilisable
if (!shader.Compile())
{
std::cout << "Failed to compile shader" << std::endl;
std::cout << "Log: " << shader.GetLog() << std::endl;
std::getchar();
return EXIT_FAILURE;
}
// Nos ressources sont chargées, et c'est bien beau, mais il nous faudrait une fenêtre pour afficher tout ça
// Window représente une fenêtre singulière, pour y effectuer un rendu il nous faut une RenderWindow
// Tout d'abord, sa taille, disons celle du bureau divisé par deux
NzVideoMode mode = NzVideoMode::GetDesktopMode();
mode.width /= 2;
mode.height /= 2;
NzString title = "Nazara Demo - AnimatedMesh";
NzRenderWindow window;
// Le premier argument définit la taille de rendu de la fenêtre (Si elle possède des bordures elle sera légèrement plus grande)
// Le deuxième argument est le titre de la fenêtre lors de sa création, vous pouvez le modifier à tout moment via window.SetTitle
// Le troisième argument représente la décoration de la fenêtre, sa bordure, ses boutons.
// Attention que cela permet à la fenêtre d'envoyer des évènements, et de changer sa taille
// Par défaut le troisième argument vaut nzWindowStyle_Default (Bordure + Bouton de fermeture + Redimensionnement)
if (!window.Create(mode, title, nzWindowStyle_Default))
{
std::cout << "Failed to create window" << std::endl;
std::getchar();
return EXIT_FAILURE;
}
// On cache le curseur
window.SetCursor(nzWindowCursor_None);
// Nous limitons les FPS à 100
window.SetFramerateLimit(100);
// La matrice de projection définit la transformation du vertice 3D à un point 2D
NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast<float>(window.GetWidth())/window.GetHeight(), 1.f, 1000.f));
// Notre fenêtre est créée, cependant il faut s'occuper d'elle, pour le rendu et les évènements
NzClock secondClock, updateClock; // Des horloges pour gérer le temps
unsigned int fps = 0; // Compteur de FPS
// Quelques variables pour notre improvisation de physique
float groundPos = drfreak.mesh.GetAABB().GetMinimum().y; // Pas très exact
NzVector3f modelPos(0.f, groundPos, -50.f);
NzVector3f modelVel(0.f, 0.f, 0.f);
NzQuaternionf modelRot(NzEulerAnglesf(0.f, 0.f, 0.f)); // Les angles d'eulers sont bien plus facile à se représenter
float speed = 60.f;
// Nous initialisons la matrice
drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos);
// Notre caméra
NzVector3f camPos(0.f, 25.f, -20.f);
NzEulerAnglesf camRot(0.f, 0.f, 0.f);
NzMatrix4f camMatrix = NzMatrix4f::Translate(camPos);
float camSpeed = 2.f;
float sensitivity = 0.5;
// Dernière étape, nos touches
// Chaque touche fera bouger
struct Movement
{
NzVector3f direction; // La direction
NzQuaternionf rotation; // La rotation du modèle
};
std::map<NzKeyboard::Key, Movement> movements;
movements[NzKeyboard::Up] = Movement{NzVector3f(0.f, 0.f, -1.f), NzQuaternionf(NzEulerAnglesf(0.f, 180.f, 0.f))};
movements[NzKeyboard::Down] = Movement{NzVector3f(0.f, 0.f, 1.f), NzQuaternionf(NzEulerAnglesf(0.f, 0.f, 0.f))};
movements[NzKeyboard::Left] = Movement{NzVector3f(-1.f, 0.f, 0.f), NzQuaternionf(NzEulerAnglesf(0.f, 90.f, 0.f))};
movements[NzKeyboard::Right] = Movement{NzVector3f(1.f, 0.f, 0.f), NzQuaternionf(NzEulerAnglesf(0.f, -90.f, 0.f))};
NzKeyboard::Key currentKey = NzKeyboard::Undefined;
// Quelques booléens
bool camMode = true;
bool windowOpen = true;
while (windowOpen)
{
// Ici nous gérons les évènements
NzEvent event;
while (window.PollEvent(&event)) // Avons-nous un évènement dans la file ?
{
// Nous avons un évènement
switch (event.type) // De quel type est cet évènement ?
{
case nzEventType_Quit: // L'utilisateur/L'OS nous a demandé de terminer notre exécution
windowOpen = false; // Nous fermons alors la boucle
break;
case nzEventType_MouseMoved:
{
// Si nous ne sommes pas en mode caméra, on ne traite pas l'évènement
if (!camMode)
break;
// On modifie l'angle de la caméra grâce au déplacement relatif de la souris
camRot.yaw = NzNormalizeAngle(camRot.yaw - event.mouseMove.deltaX*sensitivity);
// Pour éviter les loopings, on restreint les angles
camRot.pitch = NzClamp(camRot.pitch + event.mouseMove.deltaY*sensitivity, -90.f, 90.f);
// La matrice vue représente les transformations effectuées par la caméra
// On recalcule la matrice de la caméra et on l'envoie au renderer
NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::Translate(camPos) * NzMatrix4f::Rotate(camRot));
// Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre
NzMouse::SetPosition(window.GetWidth()/2, window.GetHeight()/2, window);
break;
}
case nzEventType_MouseButtonPressed:
if (event.mouseButton.button == NzMouse::Left)
{
// L'utilisateur vient d'appuyer sur le bouton left de la souris
// Nous allons inverser le mode caméra et montrer/cacher le curseur en conséquence
if (camMode)
{
camMode = false;
window.SetCursor(nzWindowCursor_Default);
}
else
{
camMode = true;
window.SetCursor(nzWindowCursor_None);
}
}
break;
case nzEventType_Resized: // L'utilisateur a changé notre taille, le coquin !
NzRenderer::SetViewport(NzRectui(0, 0, event.size.width, event.size.height)); // Adaptons l'affichage
// Il nous faut aussi mettre à jour notre matrice de projection
NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast<float>(event.size.width)/event.size.height, 1.f, 1000.f));
break;
case nzEventType_KeyPressed:
if (!event.key.repeated) // Si la touche n'est pas répétée
{
auto it = movements.find(event.key.code);
if (it != movements.end())
{
// Si la touche est une touche de mouvement
SetSequence(drfreak, "run"); // On anime le personnage pour qu'il ait une animation de déplacement
modelRot = it->second.rotation; // On change la rotation du modèle
drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); // On recalcule sa matrice
modelVel = it->second.direction * speed; // On change la vitesse de déplacement
currentKey = event.key.code;
}
}
if (event.key.code == NzKeyboard::Escape)
windowOpen = false;
break;
case nzEventType_KeyReleased:
if (event.key.code == currentKey)
{
SetSequence(drfreak, "stand");
modelVel = NzVector3f(0.f); // On arrête le déplacement
break;
}
break;
default: // Les autres évènements, on s'en fiche
break;
}
}
// On active le shader et paramètrons le rendu
NzRenderer::SetShader(&shader);
NzRenderer::Enable(nzRendererParameter_DepthTest, true);
NzRenderer::SetClearColor(128, 128, 128);
NzRenderer::Clear(nzRendererClear_Color | nzRendererClear_Depth);
if (updateClock.GetMilliseconds() >= 1000/60) // 60 fois par seconde
{
float elapsedTime = updateClock.GetSeconds(); // Le temps depuis la dernière mise à jour
// Déplacement de la caméra
static const NzVector3f forward(NzVector3f::UnitZ());
static const NzVector3f left(NzVector3f::UnitX());
static const NzVector3f up(NzVector3f::UnitY());
// Notre rotation sous forme de quaternion nous permet de tourner un vecteur
NzQuaternionf quaternion(camRot);
// Par exemple ici, quaternion * forward nous permet de récupérer le vecteur de la direction "avant"
if (NzKeyboard::IsKeyPressed(NzKeyboard::Z))
camPos += quaternion * forward * camSpeed;
if (NzKeyboard::IsKeyPressed(NzKeyboard::S))
camPos -= quaternion * forward * camSpeed;
if (NzKeyboard::IsKeyPressed(NzKeyboard::Q))
camPos += quaternion * left * camSpeed;
if (NzKeyboard::IsKeyPressed(NzKeyboard::D))
camPos -= quaternion * left * camSpeed;
// En revanche, ici la hauteur est toujours la même, peu importe notre orientation
if (NzKeyboard::IsKeyPressed(NzKeyboard::Space))
camPos += up * camSpeed;
if (NzKeyboard::IsKeyPressed(NzKeyboard::LControl))
camPos -= up * camSpeed;
// Oui le quaternion et la matrice sont calculés même si la caméra ne bouge pas
// C'est une limitation de mon implémentation, qui ne sera pas présente une fois les NzSceneNode intégrés
NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::Translate(camPos) * NzMatrix4f::Rotate(camRot));
// Animation
AnimateModel(drfreak, elapsedTime);
updateClock.Restart();
// "Physique"
if (modelVel != NzVector3f::Zero())
{
modelPos += modelVel * elapsedTime;
/*if (jumping)
{
velocity.y -= 500.f * elapsedTime; // Un simulacre de gravité
if (modelPos.y <= groundPos)
{
// On stoppe net
modelPos.y = groundPos;
velocity.y = 0.f;
jumping = false;
SetSequence(drfreak, "stand");
}
}*/
// Mise à jour de la matrice
drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos);
}
}
// Affichage des meshs
DrawModel(floor);
// Notre Dr. Freak possède des normales, nous pouvons alors culler les faces qu'on ne voit pas
NzRenderer::Enable(nzRendererParameter_FaceCulling, true);
DrawModel(drfreak);
NzRenderer::Enable(nzRendererParameter_FaceCulling, false);
window.Display(); // Nous mettons à jour l'écran
fps++;
// Toutes les secondes
if (secondClock.GetMilliseconds() >= 1000)
{
window.SetTitle(title + " (FPS: " + NzString::Number(fps) + ')');
fps = 0;
secondClock.Restart();
}
}
return EXIT_SUCCESS;
}
void AnimateModel(AnimatedModel& model, float elapsed)
{
model.interpolation += model.currentSequence->framePerSecond * elapsed;
while (model.interpolation > 1.f)
{
model.interpolation -= 1.f;
model.currentFrame = model.nextFrame;
if (++model.nextFrame > model.currentSequence->lastFrame)
model.nextFrame = model.currentSequence->firstFrame;
}
model.mesh.Animate(model.currentFrame, model.nextFrame, (NzKeyboard::IsKeyPressed(NzKeyboard::A)) ? 0.f : model.interpolation);
}
bool CreateCheckerTexture(NzTexture* texture)
{
NzImage image;
// Nous crééons une image 2D, au format RGBA8 de dimensions 128*128 (8 blocs de 16 pixels de côté)
if (!image.Create(nzImageType_2D, nzPixelFormat_RGBA8, 8*16, 8*16))
{
// Ne devrait pas arriver (La création d'une image ne peut échouer que si l'un des argument est incorrect)
std::cout << "Failed to create image, this means a bug has been found in Nazara" << std::endl;
return false;
}
// Pour modifier les pixels, nous pouvons accéder directement à ces derniers avec GetPixels(), ou bien à un pixel
// via [Get|Set]PixelColor, mais pour cette occasion nous utiliserons une méthode bien pratique, Fill.
unsigned int blockCountX = image.GetWidth()/16;
unsigned int blockCountY = image.GetHeight()/16;
for (unsigned int x = 0; x < blockCountX; ++x)
{
for (unsigned int y = 0; y < blockCountY; ++y)
{
// Une belle texture de damier
NzColor color = (x%2 == y%2) ? NzColor::White : NzColor::Black;
// Fill remplit une zone de la texture avec une couleur
image.Fill(color, NzRectui(x*16, y*16, 16, 16));
}
}
if (!texture->LoadFromImage(image)) // Nous créons notre texture depuis notre image
{
// Nous n'avons vraiment pas beaucoup de chance..
std::cout << "Failed to load image" << std::endl;
return false;
}
texture->SetAnisotropyLevel(NzRenderer::GetMaxAnisotropyLevel()); // Un filtrage anisotropique pour la texture
texture->SetWrapMode(nzTextureWrap_Repeat); // Si les coordonnées de texture dépassent 1.f, la texture sera répétée
return true;
}
bool CreateFloorMesh(NzMesh* mesh)
{
// Cette fonction créé un mesh statique simpliste pour servir de sol
// Nous créons un mesh statique
if (!mesh->Create(nzAnimationType_Static))
{
// L'échec est techniquement impossible mais le moteur étant en constante évolution ...
std::cout << "Failed to create mesh" << std::endl;
return false;
}
// Les vertex declaration ont pour seul but de décrire l'agencement d'un vertex buffer
// Elles sont composées de VertexElement, chacun décrivant un élément du buffer
NzVertexDeclaration* declaration = new NzVertexDeclaration;
// Il y a cinq paramètres différents (stream, usage, type, offset, usageIndex)
// -Stream: À quoi serviront les données ? À définir des sommets (nzElementStream_VertexData) ou à l'instancing (nzElementStream_InstancedData)
// -Usage: Comment cette donnée doit-elle être envoyée au shader
// -Type: Comment sont stockées ces données ? (Un triplet de float ? Deux double ? ..)
// -Offset: La position de la donnée dans le buffer (les données sont entrelacées)
// -UsageIndex: Pour les coordonnées de texture, définit l'indice de texture utilisé.
NzVertexElement elements[2];
elements[0].usage = nzElementUsage_Position; // Notre premier élément sera la position des vertices
elements[0].offset = 0; // Celles-ci sont placées au début
elements[0].type = nzElementType_Float3; // Sont composées de trois flottants
elements[1].usage = nzElementUsage_TexCoord;
elements[1].offset = 3*sizeof(float);
elements[1].type = nzElementType_Float2;
if (!declaration->Create(elements, 2))
{
// Nos éléments sont invalides !
std::cout << "Failed to create vertex declaration" << std::endl;
return false;
}
// Nous créons ensuite un buffer de 4 vertices (le second argument précise l'espace pris par chaque vertex), le stockage
// Et nous indiquons que nous n'y toucherons plus
NzVertexBuffer* buffer = new NzVertexBuffer(4, declaration->GetStride(nzElementStream_VertexData), nzBufferStorage_Hardware, nzBufferUsage_Static);
// Doit respecter la declaration
float vertices[] =
{
// Vertex 1
-1000.f, 0.f, -1000.f, // Position
0.f, 0.f, // UV
// Vertex 2
-1000.f, 0.f, 1000.f, // Position
0.f, 10.f, // UV
// Vertex 3
1000.f, 0.f, -1000.f, // Position
10.f, 0.f, // UV
// Vertex 4
1000.f, 0.f, 1000.f, // Position
10.f, 10.f // UV
};
// Afin de modifier un buffer, il nous faut soit le verrouiller (accès bas-niveau), soit le remplir (accès de plus haut niveau)
if (!buffer->Fill(vertices, 0, 4)) // Nous remplissons à partir de l'index 0, et nous envoyons 4 vertices
{
std::cout << "Failed to fill buffer" << std::endl;
return false;
}
NzStaticMesh* subMesh = new NzStaticMesh(mesh);
if (!subMesh->Create(declaration, buffer))
{
std::cout << "Failed to create subMesh" << std::endl;
return false;
}
subMesh->SetPrimitiveType(nzPrimitiveType_TriangleStrip);
// On ajoute le submesh au mesh
mesh->AddSubMesh(subMesh);
// Nos ressources sont notifiées utilisées par le mesh et le submesh, nous pouvons les rendre éphèmères.
// Les ressources seront donc automatiquement libérées lorsque plus aucune classe n'en aura besoin
buffer->SetPersistent(false);
declaration->SetPersistent(false);
subMesh->SetPersistent(false); // Pour le submesh, c'est déjà à false à la base
return true;
}
void DrawModel(const Model& model)
{
// La matrice world est celle qui représente les transformations du modèle
NzRenderer::SetMatrix(nzMatrixType_World, model.matrix);
NzShader* shader = NzRenderer::GetShader();// On récupère le shader du rendu
shader->SendTexture(shader->GetUniformLocation("texture"), &model.texture);
// Un mesh est divisé en plusieurs submeshes
unsigned int subMeshCount = model.mesh.GetSubMeshCount();
for (unsigned int i = 0; i < subMeshCount; ++i)
{
// On récupère le submesh
const NzSubMesh* subMesh = model.mesh.GetSubMesh(i);
// On paramètre le Renderer avec ses données
NzRenderer::SetIndexBuffer(subMesh->GetIndexBuffer());
NzRenderer::SetVertexBuffer(subMesh->GetVertexBuffer());
NzRenderer::SetVertexDeclaration(subMesh->GetVertexDeclaration());
// On fait le rendu
NzRenderer::DrawPrimitives(subMesh->GetPrimitiveType(), 0, subMesh->GetVertexCount());
}
}
void SetSequence(AnimatedModel& model, const NzString& sequenceName)
{
// On récupère l'animation du mesh
const NzAnimation* animation = model.mesh.GetAnimation();
// Nous nous basons sur l'assertion que la séquence existe (Chose que nous pouvons tester avec HasSequence())
model.currentSequence = animation->GetSequence(sequenceName);
// Pour avoir une interpolation entre la séquence précédente et celle-ci, nous n'affectons que nextFrame
model.nextFrame = model.currentSequence->firstFrame;
}

View File

@ -0,0 +1,23 @@
kind "ConsoleApp"
files "main.cpp"
configuration "DebugStatic"
links "NazaraCored-s"
links "NazaraRendererd-s"
links "NazaraUtilityd-s"
configuration "ReleaseStatic"
links "NazaraCore-s"
links "NazaraRenderer-s"
links "NazaraUtility-s"
configuration "DebugDLL"
links "NazaraCored"
links "NazaraRendererd"
links "NazaraUtilityd"
configuration "ReleaseDLL"
links "NazaraCore"
links "NazaraRenderer"
links "NazaraUtility"

View File

@ -0,0 +1,49 @@
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <iostream>
int main()
{
// Pour charger des ressources, il est impératif d'initialiser le module utilitaire
NzInitializer<NzUtility> utility;
if (!utility)
{
// Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log
std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl;
std::getchar(); // On laise le temps de voir l'erreur
return EXIT_FAILURE;
}
// Le Renderer n'étant pas chargé, nous devons indiquer que nous désirons un stockage software de notre mesh
NzMeshParams parameters;
parameters.storage = nzBufferStorage_Software;
NzMesh drfreak;
if (!drfreak.LoadFromFile("resources/drfreak.md2", parameters))
{
std::cout << "Failed to load Dr. Freak's mesh" << std::endl;
std::getchar();
return EXIT_FAILURE;
}
if (drfreak.HasAnimation()) // Si le mesh possède des animations
{
std::cout << "Mesh has animation" << std::endl;
// Un objet NzAnimation représente un ensemble d'informations sur des animations
const NzAnimation* animation = drfreak.GetAnimation();
// Une séquence définit une "action", chaque séquence possède un nom, une frame de départ, une d'arrivée ainsi qu'un framerate
unsigned int sequenceCount = animation->GetSequenceCount();
std::cout << sequenceCount << " sequences:" << std::endl;
for (unsigned int i = 0; i < sequenceCount; ++i)
std::cout << "-" << (i+1) << ": " << animation->GetSequence(i)->name << std::endl;
}
else
std::cout << "Mesh has no animation" << std::endl;
std::getchar(); // Une attente pour avoir le temps de lire :-)
// Le module utilitaire et le mesh sont déchargés automatiquement
return EXIT_SUCCESS;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +0,0 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Audio/Config.hpp>
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

60
include/Nazara/Core.hpp Normal file
View File

@ -0,0 +1,60 @@
// This file was automatically generated by Nazara
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Directory.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/Format.hpp>
#include <Nazara/Core/Functor.hpp>
#include <Nazara/Core/Hash.hpp>
#include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/MemoryStream.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/Semaphore.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Core/Tuple.hpp>
#include <Nazara/Core/Unicode.hpp>

View File

@ -8,10 +8,10 @@
#define NAZARA_BYTEARRAY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Conig.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Hashable.hpp>
#if NAZARA_THREADSAFETY_BYTEARRAY
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_BYTEARRAY
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@ -28,7 +28,7 @@ class NAZARA_API NzByteArray : public NzHashable
NzByteArray();
NzByteArray(const nzUInt8* buffer, unsigned int bufferLength);
NzByteArray(const NzByteArray& buffer);
NzByteArray(NzByteArray&& buffer);
NzByteArray(NzByteArray&& buffer) noexcept;
NzByteArray(SharedArray* sharedArray);
~NzByteArray();
@ -80,7 +80,7 @@ class NAZARA_API NzByteArray : public NzHashable
nzUInt8 operator[](unsigned int pos) const;
NzByteArray& operator=(const NzByteArray& byteArray);
NzByteArray& operator=(NzByteArray&& byteArray);
NzByteArray& operator=(NzByteArray&& byteArray) noexcept;
NzByteArray operator+(const NzByteArray& byteArray) const;
NzByteArray& operator+=(const NzByteArray& byteArray);
@ -89,10 +89,7 @@ class NAZARA_API NzByteArray : public NzHashable
struct NAZARA_API SharedArray
{
SharedArray() :
refCount(1)
{
}
SharedArray() = default;
SharedArray(unsigned short referenceCount, unsigned int bufferSize, unsigned int arraySize, nzUInt8* ptr) :
capacity(bufferSize),
@ -104,7 +101,7 @@ class NAZARA_API NzByteArray : public NzHashable
unsigned int capacity;
unsigned int size;
unsigned short refCount;
unsigned short refCount = 1;
nzUInt8* buffer;
NazaraMutex(mutex)

View File

@ -9,7 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#if NAZARA_THREADSAFETY_CLOCK
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_CLOCK
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>

View File

@ -8,7 +8,7 @@
#include <cmath>
#include <cstdlib>
#include <stdexcept>
#include <Nazara/Utility/Debug.hpp>
#include <Nazara/Core/Debug.hpp>
inline NzColor::NzColor()
{
@ -198,26 +198,26 @@ inline NzColor NzColor::FromXYZ(float x, float y, float z)
y /= 100; // Y from 0 to 100.000
z /= 100; // Z from 0 to 108.883
double r = x * 3.2406 + y * -1.5372 + z * -0.4986;
double g = x * -0.9689 + y * 1.8758 + z * 0.0415;
double b = x * 0.0557 + y * -0.2040 + z * 1.0570;
float r = x * 3.2406f + y * -1.5372f + z * -0.4986f;
float g = x * -0.9689f + y * 1.8758f + z * 0.0415f;
float b = x * 0.0557f + y * -0.2040f + z * 1.0570f;
if (r > 0.0031308f)
r = 1.055 * (std::pow(r, 1.0/2.4)) - 0.055;
r = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
r *= 12.92;
r *= 12.92f;
if (g > 0.0031308f)
g = 1.055 * (std::pow(g, 1.0/2.4)) - 0.055;
g = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
g *= 12.92;
g *= 12.92f;
if (b > 0.0031308f)
b = 1.055 * (std::pow(b, 1.0/2.4)) - 0.055;
b = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
b *= 12.92;
b *= 12.92f;
return NzColor(r * 255.0, g * 255.0, b * 255.0);
return NzColor(r * 255.f, g * 255.f, b * 255.f);
}
inline void NzColor::ToCMY(const NzColor& color, float* cyan, float* magenta, float* yellow)
@ -409,4 +409,4 @@ inline std::ostream& operator<<(std::ostream& out, const NzColor& color)
return out << color.ToString();
}
#include <Nazara/Utility/DebugOff.hpp>
#include <Nazara/Core/DebugOff.hpp>

View File

@ -4,19 +4,19 @@
#pragma once
#ifndef NAZARA_THREADCONDITION_HPP
#define NAZARA_THREADCONDITION_HPP
#ifndef NAZARA_CONDITIONVARIABLE_HPP
#define NAZARA_CONDITIONVARIABLE_HPP
#include <Nazara/Prerequesites.hpp>
class NzConditionVariableImpl;
class NzMutex;
class NzThreadConditionImpl;
class NAZARA_API NzThreadCondition
class NAZARA_API NzConditionVariable
{
public:
NzThreadCondition();
~NzThreadCondition();
NzConditionVariable();
~NzConditionVariable();
void Signal();
void SignalAll();
@ -25,7 +25,7 @@ class NAZARA_API NzThreadCondition
bool Wait(NzMutex* mutex, nzUInt32 timeout);
private:
NzThreadConditionImpl* m_impl;
NzConditionVariableImpl* m_impl;
};
#endif // NAZARA_THREADCONDITION_HPP
#endif // NAZARA_CONDITIONVARIABLE_HPP

View File

@ -44,34 +44,36 @@
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_CORE_MEMORYLEAKTRACKER 0
// Standardise les séparateurs des dossiers selon le système d'exploitation courant
// Standardise les séparateurs des dossiers selon le système d'exploitation courant (Léger coût à l'exécution)
#define NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS 1
// Précision des réels lors de la transformation en texte (Max. chiffres après la virgule)
#define NAZARA_CORE_REAL_PRECISION 6
// Redirige la sortie du log sur le flux d'erreur standard (cerr) en cas d'erreur d'écriture (ou d'ouverture du fichier)
#define NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE 1
// Duplique la sortie du log sur le flux de sortie standard (cout)
#define NAZARA_CORE_DUPLICATE_TO_COUT 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_CORE_SAFE 1
// Protège le module des accès concurrentiels
// Protège les classes des accès concurrentiels
#define NAZARA_CORE_THREADSAFE 1
#if NAZARA_CORE_THREADSAFE
#define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW)
#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock
#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory
#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib
#define NAZARA_THREADSAFETY_FILE 1 // NzFile
#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest
#define NAZARA_THREADSAFETY_LOG 1 // NzLog
#define NAZARA_THREADSAFETY_STRING 1 // NzString (COW)
#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream
#endif
// Les classes à protéger des accès concurrentiels
#define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW)
#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock
#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory
#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib
#define NAZARA_THREADSAFETY_FILE 1 // NzFile
#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest
#define NAZARA_THREADSAFETY_LOG 1 // NzLog
#define NAZARA_THREADSAFETY_STRING 1 // NzString (COW)
#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream
// Optimise certaines parties du code avec les avancées venues de Windows Vista (Nécessite Vista ou supérieur et compilateur compatible)
// Le nombre de spinlocks à utiliser avec les critical sections de Windows (0 pour désactiver)
#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096
// Optimise certaines parties du code avec certaines avancées venues de Windows Vista (Casse la compatibilité XP mais n'affecte pas les autres OS)
#define NAZARA_CORE_WINDOWS_VISTA 0
/*

View File

@ -0,0 +1,29 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CORE_HPP
#define NAZARA_CORE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
class NAZARA_API NzCore
{
public:
NzCore() = delete;
~NzCore() = delete;
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static unsigned int s_moduleReferenceCouter;
};
#endif // NAZARA_CORE_HPP

View File

@ -19,7 +19,7 @@
#define NAZARA_DIRECTORY_SEPARATOR '/'
#endif
#if NAZARA_THREADSAFETY_DIRECTORY
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DIRECTORY
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@ -36,10 +36,12 @@ class NAZARA_API NzDirectory
void Close();
NzString GetPattern() const;
NzString GetResultName() const;
NzString GetResultPath() const;
nzUInt64 GetResultSize() const;
bool IsOpen() const;
bool IsResultDirectory() const;
bool NextResult(bool skipDots = true);
@ -47,6 +49,7 @@ class NAZARA_API NzDirectory
bool Open();
void SetDirectory(const NzString& dirPath);
void SetPattern(const NzString& pattern);
static bool Copy(const NzString& sourcePath, const NzString& destPath);
static bool Create(const NzString& dirPath, bool recursive = false);
@ -59,7 +62,8 @@ class NAZARA_API NzDirectory
NazaraMutexAttrib(m_mutex, mutable)
NzString m_dirPath;
NzDirectoryImpl* m_impl;
NzString m_pattern;
NzDirectoryImpl* m_impl = nullptr;
};
#endif // NAZARA_DIRECTORY_HPP

View File

@ -11,7 +11,7 @@
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#if NAZARA_THREADSAFETY_DYNLIB
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DYNLIB
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>

View File

@ -16,7 +16,7 @@
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#if NAZARA_THREADSAFETY_FILE
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@ -50,7 +50,7 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable
NzFile();
NzFile(const NzString& filePath);
NzFile(const NzString& filePath, unsigned long openMode);
NzFile(NzFile&& file);
NzFile(NzFile&& file) noexcept;
~NzFile();
bool Copy(const NzString& newFilePath);
@ -92,7 +92,7 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable
std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count);
NzFile& operator=(const NzString& filePath);
NzFile& operator=(NzFile&& file);
NzFile& operator=(NzFile&& file) noexcept;
static NzString AbsolutePath(const NzString& filePath);
static bool Copy(const NzString& sourcePath, const NzString& targetPath);

View File

@ -17,7 +17,7 @@ class NAZARA_API NzHashDigest
NzHashDigest();
NzHashDigest(const NzString& hashName, const nzUInt8* digest, unsigned int length);
NzHashDigest(const NzHashDigest& rhs);
NzHashDigest(NzHashDigest&& rhs);
NzHashDigest(NzHashDigest&& rhs) noexcept;
~NzHashDigest();
bool IsValid() const;
@ -31,7 +31,7 @@ class NAZARA_API NzHashDigest
nzUInt8 operator[](unsigned short pos) const;
NzHashDigest& operator=(const NzHashDigest& rhs);
NzHashDigest& operator=(NzHashDigest&& rhs);
NzHashDigest& operator=(NzHashDigest&& rhs) noexcept;
bool operator==(const NzHashDigest& rhs) const;
bool operator!=(const NzHashDigest& rhs) const;

View File

@ -0,0 +1,26 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_INITIALIZER_HPP
#define NAZARA_INITIALIZER_HPP
#include <Nazara/Prerequesites.hpp>
template<typename T>
class NzInitializer
{
public:
template<typename... Args> NzInitializer(Args... args);
~NzInitializer();
bool IsInitialized() const;
operator bool() const;
};
#include <Nazara/Core/Initializer.inl>
#endif // NAZARA_INITIALIZER_HPP

View File

@ -0,0 +1,35 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// http://www.easyrgb.com/index.php?X=MATH
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Core/Debug.hpp>
template<typename T>
template<typename... Args>
NzInitializer<T>::NzInitializer(Args... args)
{
T::Initialize(args...);
}
template<typename T>
NzInitializer<T>::~NzInitializer()
{
T::Uninitialize();
}
template<typename T>
bool NzInitializer<T>::IsInitialized() const
{
return T::IsInitialized();
}
template<typename T>
NzInitializer<T>::operator bool() const
{
return T::IsInitialized();
}
#include <Nazara/Core/DebugOff.hpp>

View File

@ -12,7 +12,7 @@
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#if NAZARA_THREADSAFETY_LOG
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_LOG
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>

View File

@ -11,11 +11,11 @@
#include <Nazara/Core/NonCopyable.hpp>
class NzMutexImpl;
class NzThreadCondition;
class NzConditionVariable;
class NAZARA_API NzMutex : NzNonCopyable
{
friend class NzThreadCondition;
friend class NzConditionVariable;
public:
NzMutex();

View File

@ -13,7 +13,7 @@
#include <string>
#include <vector>
#if NAZARA_THREADSAFETY_STRING
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRING
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@ -41,7 +41,7 @@ class NAZARA_API NzString : public NzHashable
NzString(const char* string);
NzString(const std::string& string);
NzString(const NzString& string);
NzString(NzString&& string);
NzString(NzString&& string) noexcept;
NzString(SharedString* sharedString);
~NzString();
@ -112,8 +112,8 @@ class NAZARA_API NzString : public NzHashable
unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None);
unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
//unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None);
//unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
void Reserve(unsigned int bufferSize);
@ -184,7 +184,7 @@ class NAZARA_API NzString : public NzHashable
NzString& operator=(const char* string);
NzString& operator=(const std::string& string);
NzString& operator=(const NzString& string);
NzString& operator=(NzString&& string);
NzString& operator=(NzString&& string) noexcept;
NzString operator+(char character) const;
NzString operator+(const char* string) const;
@ -282,10 +282,7 @@ class NAZARA_API NzString : public NzHashable
struct NAZARA_API SharedString
{
SharedString() :
refCount(1)
{
}
SharedString() = default;
SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) :
capacity(bufferSize),
@ -299,7 +296,7 @@ class NAZARA_API NzString : public NzHashable
unsigned int size;
char* string;
unsigned short refCount;
unsigned short refCount = 1;
NazaraMutex(mutex)
};

View File

@ -12,7 +12,7 @@
#include <string>
#include <vector>
#if NAZARA_THREADSAFETY_STRINGSTREAM
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRINGSTREAM
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>

View File

@ -26,7 +26,7 @@ class NAZARA_API NzThread : NzNonCopyable
friend class NzThreadImpl;
public:
Id() : m_handle(nullptr) {}
Id() = default;
Id(Id&& rhs) = default;
~Id();
@ -38,7 +38,7 @@ class NAZARA_API NzThread : NzNonCopyable
Id(void* handle) : m_handle(handle) {}
Id(const NzThreadImpl* thread);
void* m_handle;
void* m_handle = nullptr;
};
template<typename F> NzThread(F function);

View File

@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)

View File

@ -2,7 +2,5 @@
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif
#undef delete
#undef new

View File

@ -1,7 +1,10 @@
// This file was automatically generated by Nazara
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Rémi "overdrivr" Bèges (remi.beges@laposte.net)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@ -24,12 +27,14 @@
#pragma once
#ifndef NAZARA_CONFIG_NETWORK_HPP
#define NAZARA_CONFIG_NETWORK_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_NETWORK_MEMORYLEAKTRACKER 0
#endif // NAZARA_CONFIG_NETWORK_HPP
#include <Nazara/Math/Basic.hpp>
#include <Nazara/Math/Config.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/EulerAngles.hpp>
#include <Nazara/Math/Math.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>

View File

@ -10,6 +10,8 @@
#include <cstring>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
T NzApproach(T value, T objective, T increment)
{
@ -45,7 +47,7 @@ T NzDegrees(T degrees)
template<typename T>
T NzDegreeToRadian(T degrees)
{
return degrees * (M_PI/180.0);
return degrees * F(M_PI/180.0);
}
unsigned int NzGetNumberLength(signed char number)
@ -53,7 +55,15 @@ unsigned int NzGetNumberLength(signed char number)
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
// Le standard définit le char comme étant codé sur un octet
static_assert(sizeof(number) == 1, "Signed char must be one byte-sized");
if (number >= 100)
return 3;
else if (number >= 10)
return 2;
else
return 1;
}
unsigned int NzGetNumberLength(unsigned char number)
@ -61,7 +71,15 @@ unsigned int NzGetNumberLength(unsigned char number)
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(number))+1;
// Le standard définit le char comme étant codé sur un octet
static_assert(sizeof(number) == 1, "Signed char must be one byte-sized");
if (number >= 100)
return 3;
else if (number >= 10)
return 2;
else
return 1;
}
unsigned int NzGetNumberLength(short number)
@ -152,20 +170,20 @@ T NzNormalizeAngle(T angle)
#if NAZARA_MATH_ANGLE_RADIAN
const T limit = M_PI;
#else
const T limit = 180.0;
const T limit = F(180.0);
#endif
///TODO: Trouver une solution sans duplication
if (angle > 0.0)
if (angle > F(0.0))
{
angle += limit;
angle -= static_cast<int>(angle/(2.0*limit))*(2.0*limit);
angle -= static_cast<int>(angle/(F(2.0)*limit))*(F(2.0)*limit);
angle -= limit;
}
else
{
angle -= limit;
angle -= static_cast<int>(angle/(2.0*limit))*(2.0*limit);
angle -= static_cast<int>(angle/(F(2.0)*limit))*(F(2.0)*limit);
angle += limit;
}
@ -175,11 +193,7 @@ T NzNormalizeAngle(T angle)
template<typename T>
bool NzNumberEquals(T a, T b)
{
if (a > b)
return (a-b) <= std::numeric_limits<T>::epsilon();
else
return (b-a) <= std::numeric_limits<T>::epsilon();
return std::fabs(a-b) <= std::numeric_limits<T>::epsilon();
}
NzString NzNumberToString(long long number, nzUInt8 radix)
@ -235,7 +249,7 @@ T NzRadians(T radians)
template<typename T>
T NzRadianToDegree(T radians)
{
return radians * (180.0/M_PI);
return radians * F(180.0/M_PI);
}
long long NzStringToNumber(NzString str, nzUInt8 radix, bool* ok)
@ -288,4 +302,6 @@ long long NzStringToNumber(NzString str, nzUInt8 radix, bool* ok)
return (negative) ? -static_cast<long long>(total) : total;
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -36,15 +36,17 @@
// Définit la disposition des matrices en colonnes (Façon OpenGL)
#define NAZARA_MATH_MATRIX_COLUMN_MAJOR 1
// Optimise les opérations entre matrices affines (Demande plusieurs comparaisons pour déterminer si une matrice est affine)
#define NAZARA_MATH_MATRIX4_CHECK_AFFINE 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_MATH_SAFE 1
// Protège le module des accès concurrentiels
// Protège les classes des accès concurrentiels
#define NAZARA_MATH_THREADSAFE 1
#if NAZARA_MATH_THREADSAFE
#define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW)
#define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW)
#endif
// Les classes à protéger des accès concurrentiels
#define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW)
#define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW)
#endif // NAZARA_CONFIG_MATH_HPP

View File

@ -17,8 +17,9 @@ class NzCube
public:
NzCube();
NzCube(T X, T Y, T Z, T Width, T Height, T Depth);
NzCube(T cube[6]);
NzCube(const T cube[6]);
NzCube(const NzRect<T>& rect);
NzCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzCube(const NzCube<U>& rect);
NzCube(const NzCube& rect) = default;
~NzCube() = default;
@ -32,11 +33,16 @@ class NzCube
NzVector3<T> GetCenter() const;
bool Intersect(const NzCube& rect) const;
bool Intersect(const NzCube& rect, NzCube& intersection) const;
bool Intersect(const NzCube& rect, NzCube* intersection = nullptr) const;
bool IsValid() const;
void Set(T X, T Y, T Z, T Width, T Height, T Depth);
void Set(const T rect[6]);
void Set(const NzRect<T>& rect);
void Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> void Set(const NzCube<U>& rect);
NzString ToString() const;
operator NzString() const;

View File

@ -6,54 +6,42 @@
#include <algorithm>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzCube<T>::NzCube()
{
}
template<typename T>
NzCube<T>::NzCube(T X, T Y, T Z, T Width, T Height, T Depth) :
x(X),
y(Y),
z(Z),
width(Width),
height(Height),
depth(Depth)
NzCube<T>::NzCube(T X, T Y, T Z, T Width, T Height, T Depth)
{
Set(X, Y, Z, Width, Height, Depth);
}
template<typename T>
NzCube<T>::NzCube(T vec[6]) :
x(vec[0]),
y(vec[1]),
z(vec[2]),
width(vec[3]),
height(vec[4]),
depth(vec[5])
NzCube<T>::NzCube(const T vec[6])
{
Set(vec);
}
template<typename T>
NzCube<T>::NzCube(const NzRect<T>& rect) :
x(rect.x),
y(rect.y),
z(0),
width(rect.width),
height(rect.height),
depth(1)
NzCube<T>::NzCube(const NzRect<T>& rect)
{
Set(rect);
}
template<typename T>
NzCube<T>::NzCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
Set(vec1, vec2);
}
template<typename T>
template<typename U>
NzCube<T>::NzCube(const NzCube<U>& rect) :
x(static_cast<T>(rect.x)),
y(static_cast<T>(rect.y)),
z(static_cast<T>(rect.z)),
width(static_cast<T>(rect.width)),
height(static_cast<T>(rect.height)),
depth(static_cast<T>(rect.depth))
NzCube<T>::NzCube(const NzCube<U>& rect)
{
Set(rect);
}
template<typename T>
@ -102,18 +90,11 @@ void NzCube<T>::ExtendTo(const NzCube& rect)
template<typename T>
NzVector3<T> NzCube<T>::GetCenter() const
{
return NzVector3<T>((x+width)/2, (y+height)/2, (z+depth)/2);
return NzVector3<T>((x+width)/F(2.0), (y+height)/F(2.0), (z+depth)/F(2.0));
}
template<typename T>
bool NzCube<T>::Intersect(const NzCube& rect) const
{
NzCube intersection; // Optimisé par le compilateur
return Intersect(rect, intersection);
}
template<typename T>
bool NzCube<T>::Intersect(const NzCube& rect, NzCube& intersection) const
bool NzCube<T>::Intersect(const NzCube& rect, NzCube* intersection) const
{
T left = std::max(x, rect.x);
T right = std::min(x+width, rect.x+rect.width);
@ -124,12 +105,15 @@ bool NzCube<T>::Intersect(const NzCube& rect, NzCube& intersection) const
if (left < right && top < bottom && up < down)
{
intersection.x = left;
intersection.y = top;
intersection.z = up;
intersection.width = right-left;
intersection.height = bottom-top;
intersection.depth = down-up;
if (intersection)
{
intersection->x = left;
intersection->y = top;
intersection->z = up;
intersection->width = right-left;
intersection->height = bottom-top;
intersection->depth = down-up;
}
return true;
}
@ -140,7 +124,63 @@ bool NzCube<T>::Intersect(const NzCube& rect, NzCube& intersection) const
template<typename T>
bool NzCube<T>::IsValid() const
{
return width > 0 && height > 0 && depth > 0;
return width > F(0.0) && height > F(0.0) && depth > F(0.0);
}
template<typename T>
void NzCube<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{
x = X;
y = Y;
z = Z;
width = Width;
height = Height;
depth = Depth;
}
template<typename T>
void NzCube<T>::Set(const T rect[6])
{
x = rect[0];
y = rect[1];
z = rect[2];
width = rect[3];
height = rect[4];
depth = rect[5];
}
template<typename T>
void NzCube<T>::Set(const NzRect<T>& rect)
{
x = rect.x;
y = rect.y;
z = 0;
width = rect.width;
height = rect.height;
depth = 1;
}
template<typename T>
void NzCube<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
x = std::min(vec1.x, vec2.x);
y = std::min(vec1.y, vec2.y);
z = std::min(vec1.z, vec2.z);
width = (vec2.x > vec1.x) ? vec2.x-vec1.x : vec1.x-vec2.x;
height = (vec2.y > vec1.y) ? vec2.y-vec1.y : vec1.y-vec2.y;
depth = (vec2.z > vec1.z) ? vec2.z-vec1.z : vec1.z-vec2.z;
}
template<typename T>
template<typename U>
void NzCube<T>::Set(const NzCube<U>& cube)
{
x = F(cube.x);
y = F(cube.y);
z = F(cube.z);
width = F(cube.width);
height = F(cube.height);
depth = F(cube.depth);
}
template<typename T>
@ -160,13 +200,15 @@ NzCube<T>::operator NzString() const
template<typename T>
T& NzCube<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 6)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 6)";
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@ -174,13 +216,15 @@ T& NzCube<T>::operator[](unsigned int i)
template<typename T>
T NzCube<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 6)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 6)";
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@ -191,4 +235,6 @@ std::ostream& operator<<(std::ostream& out, const NzCube<T>& rect)
return out << rect.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -9,9 +9,8 @@
#define NAZARA_EULERANGLES_HPP
#include <Nazara/Core/String.hpp>
template<typename T> class NzQuaternion;
template<typename T> class NzVector3;
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T> class NzEulerAngles
{
@ -25,9 +24,7 @@ template<typename T> class NzEulerAngles
NzEulerAngles(const NzEulerAngles& angles) = default;
~NzEulerAngles() = default;
NzVector3<T> GetForward() const;
NzVector3<T> GetRight() const;
NzVector3<T> GetUp() const;
void MakeZero();
void Normalize();
@ -37,25 +34,28 @@ template<typename T> class NzEulerAngles
//void Set(const NzMatrix3<T>& mat);
void Set(const NzQuaternion<T>& quat);
template<typename U> void Set(const NzEulerAngles<U>& angles);
void SetZero();
//NzMatrix3<T> ToRotationMatrix() const;
NzQuaternion<T> ToQuaternion() const;
NzString ToString() const;
operator NzString() const;
NzEulerAngles operator+(const NzEulerAngles& angles) const;
NzEulerAngles operator-(const NzEulerAngles& angles) const;
NzEulerAngles operator*(const NzEulerAngles& angles) const;
NzEulerAngles operator/(const NzEulerAngles& angles) const;
/*NzEulerAngles operator*(const NzEulerAngles& angles) const;
NzEulerAngles operator/(const NzEulerAngles& angles) const;*/
NzEulerAngles operator+=(const NzEulerAngles& angles);
NzEulerAngles operator-=(const NzEulerAngles& angles);
NzEulerAngles operator*=(const NzEulerAngles& angles);
NzEulerAngles operator/=(const NzEulerAngles& angles);
/*NzEulerAngles operator*=(const NzEulerAngles& angles);
NzEulerAngles operator/=(const NzEulerAngles& angles);*/
bool operator==(const NzEulerAngles& angles) const;
bool operator!=(const NzEulerAngles& angles) const;
static NzEulerAngles Zero();
T pitch, yaw, roll;
};

View File

@ -7,9 +7,10 @@
#include <Nazara/Math/Config.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <cmath>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzEulerAngles<T>::NzEulerAngles()
{
@ -41,33 +42,9 @@ NzEulerAngles<T>::NzEulerAngles(const NzEulerAngles<U>& angles)
}
template<typename T>
NzVector3<T> NzEulerAngles<T>::GetForward() const
void NzEulerAngles<T>::MakeZero()
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzVector3<T>(std::cos(yaw), std::sin(roll), std::sin(yaw));
#else
return NzVector3<T>(std::cos(NzDegreeToRadian(yaw)), std::sin(NzDegreeToRadian(roll)), std::sin(NzDegreeToRadian(yaw)));
#endif
}
template<typename T>
NzVector3<T> NzEulerAngles<T>::GetRight() const
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzVector3<T>(std::sin(yaw), std::sin(pitch), std::cos(pitch));
#else
return NzVector3<T>(std::sin(NzDegreeToRadian(yaw)), std::sin(NzDegreeToRadian(pitch)), std::cos(NzDegreeToRadian(pitch)));
#endif
}
template<typename T>
NzVector3<T> NzEulerAngles<T>::GetUp() const
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzVector3<T>(std::sin(roll), std::cos(pitch), -std::sin(pitch));
#else
return NzVector3<T>(std::sin(NzDegreeToRadian(roll)), std::cos(NzDegreeToRadian(pitch)), -std::sin(NzDegreeToRadian(pitch)));
#endif
Set(F(0.0), F(0.0), F(0.0));
}
template<typename T>
@ -117,20 +94,14 @@ void NzEulerAngles<T>::Set(const NzEulerAngles<U>& angles)
roll = static_cast<T>(angles.roll);
}
template<typename T>
void NzEulerAngles<T>::SetZero()
{
Set(0.0, 0.0, 0.0);
}
template<typename T>
NzQuaternion<T> NzEulerAngles<T>::ToQuaternion() const
{
NzQuaternion<T> Qx(pitch, NzVector3<T>(1.0, 0.0, 0.0));
NzQuaternion<T> Qy(yaw, NzVector3<T>(0.0, 1.0, 0.0));
NzQuaternion<T> Qz(roll, NzVector3<T>(0.0, 0.0, 1.0));
NzQuaternion<T> rotX(pitch, NzVector3<T>(F(1.0), F(0.0), F(0.0)));
NzQuaternion<T> rotY(yaw, NzVector3<T>(F(0.0), F(1.0), F(0.0)));
NzQuaternion<T> rotZ(roll, NzVector3<T>(F(0.0), F(0.0), F(1.0)));
return Qx * Qy * Qz;
return rotY * rotX * rotZ;
}
template<typename T>
@ -141,6 +112,12 @@ NzString NzEulerAngles<T>::ToString() const
return ss << "EulerAngles(" << pitch << ", " << yaw << ", " << roll << ')';
}
template<typename T>
NzEulerAngles<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzEulerAngles<T> NzEulerAngles<T>::operator+(const NzEulerAngles& angles) const
{
@ -191,10 +168,21 @@ bool NzEulerAngles<T>::operator!=(const NzEulerAngles& angles) const
return !operator==(angles);
}
template<typename T>
NzEulerAngles<T> NzEulerAngles<T>::Zero()
{
NzEulerAngles angles;
angles.MakeZero();
return angles;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzEulerAngles<T>& angles)
{
return out << angles.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -20,16 +20,4 @@
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_AUDIO_HPP
#define NAZARA_CONFIG_AUDIO_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_AUDIO_MEMORYLEAKTRACKER 0
#endif // NAZARA_CONFIG_AUDIOs_HPP
*/

View File

@ -8,8 +8,9 @@
#define NAZARA_MATRIX4_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Config.hpp>
#if NAZARA_THREADSAFETY_MATRIX4
#if NAZARA_MATH_THREADSAFE && NAZARA_THREADSAFETY_MATRIX4
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@ -26,18 +27,21 @@ template<typename T> class NzMatrix4
public:
NzMatrix4();
NzMatrix4(T r11, T r12, T r13, T r14,
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
NzMatrix4(const T matrix[16]);
//NzMatrix4(const NzMatrix3<T>& matrix);
template<typename U> explicit NzMatrix4(const NzMatrix4<U>& matrix);
NzMatrix4(const NzMatrix4& matrix);
NzMatrix4(NzMatrix4&& matrix);
NzMatrix4(NzMatrix4&& matrix) noexcept;
~NzMatrix4();
NzMatrix4 Concatenate(const NzMatrix4& matrix) const;
T GetDeterminant() const;
NzMatrix4 GetInverse() const;
NzQuaternion<T> GetRotation() const;
//NzMatrix3 GetRotationMatrix() const;
NzVector3<T> GetScale() const;
NzVector3<T> GetTranslation() const;
@ -46,23 +50,30 @@ template<typename T> class NzMatrix4
bool HasNegativeScale() const;
bool HasScale() const;
bool IsAffine() const;
bool IsDefined() const;
void MakeIdentity();
void MakeLookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
void MakeOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0);
void MakePerspective(T angle, T ratio, T zNear, T zFar);
void MakeRotation(const NzQuaternion<T>& rotation);
void MakeScale(const NzVector3<T>& scale);
void MakeTranslation(const NzVector3<T>& translation);
void MakeZero();
void Set(T r11, T r12, T r13, T r14,
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
void Set(const T matrix[16]);
//NzMatrix4(const NzMatrix3<T>& matrix);
void Set(const NzMatrix4& matrix);
void Set(NzMatrix4&& matrix);
template<typename U> void Set(const NzMatrix4<U>& matrix);
void SetIdentity();
void SetLookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
void SetOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0);
void SetPerspective(T angle, T ratio, T zNear, T zFar);
void SetRotation(const NzQuaternion<T>& rotation);
void SetScale(const NzVector3<T>& scale);
void SetTranslation(const NzVector3<T>& translation);
void SetZero();
NzString ToString() const;
@ -72,6 +83,8 @@ template<typename T> class NzMatrix4
NzMatrix4& Transpose();
operator NzString() const;
operator T*();
operator const T*() const;
@ -79,7 +92,7 @@ template<typename T> class NzMatrix4
const T& operator()(unsigned int x, unsigned int y) const;
NzMatrix4& operator=(const NzMatrix4& matrix);
NzMatrix4& operator=(NzMatrix4&& matrix);
NzMatrix4& operator=(NzMatrix4&& matrix) noexcept;
NzMatrix4 operator*(const NzMatrix4& matrix) const;
NzVector2<T> operator*(const NzVector2<T>& vector) const;
@ -90,12 +103,16 @@ template<typename T> class NzMatrix4
NzMatrix4& operator*=(const NzMatrix4& matrix);
NzMatrix4& operator*=(T scalar);
static NzMatrix4 Concatenate(const NzMatrix4& m1, const NzMatrix4& m2);
static NzMatrix4 ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2);
static NzMatrix4 Identity();
static NzMatrix4 LookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
static NzMatrix4 Ortho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0);
static NzMatrix4 Perspective(T angle, T ratio, T zNear, T zFar);
static NzMatrix4 Rotate(const NzQuaternion<T>& rotation);
static NzMatrix4 Scale(const NzVector3<T>& scale);
static NzMatrix4 Translate(const NzVector3<T>& translation);
static NzMatrix4 Zero();
struct SharedMatrix
{
@ -112,11 +129,13 @@ template<typename T> class NzMatrix4
void EnsureOwnership();
void ReleaseMatrix();
SharedMatrix* m_sharedMatrix;
SharedMatrix* m_sharedMatrix = nullptr;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzMatrix4<T>& matrix);
template<typename T> NzMatrix4<T> operator*(T scale, const NzMatrix4<T>& matrix);
typedef NzMatrix4<double> NzMatrix4d;
typedef NzMatrix4<float> NzMatrix4f;

File diff suppressed because it is too large Load Diff

View File

@ -31,9 +31,12 @@ template<typename T> class NzQuaternion
NzQuaternion GetConjugate() const;
NzQuaternion GetNormalized() const;
void MakeIdentity();
void MakeZero();
T Magnitude() const;
T Normalize();
T SquaredMagnitude() const;
void Set(T W, T X, T Y, T Z);
void Set(T quat[4]);
@ -42,13 +45,17 @@ template<typename T> class NzQuaternion
//void Set(const NzMatrix3<T>& mat);
void Set(const NzQuaternion& quat);
template<typename U> void Set(const NzQuaternion<U>& quat);
void SetIdentity();
void SetZero();
T SquaredMagnitude() const;
NzEulerAngles<T> ToEulerAngles() const;
//NzMatrix3<T> ToRotationMatrix() const;
NzString ToString() const;
operator NzString() const;
NzQuaternion& operator=(const NzQuaternion& quat);
NzQuaternion operator+(const NzQuaternion& quat) const;
NzQuaternion operator*(const NzQuaternion& quat) const;
NzVector3<T> operator*(const NzVector3<T>& vec) const;
@ -67,7 +74,9 @@ template<typename T> class NzQuaternion
bool operator>(const NzQuaternion& quat) const;
bool operator>=(const NzQuaternion& quat) const;
static NzQuaternion Identity();
static NzQuaternion Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp);
static NzQuaternion Zero();
T w, x, y, z;
};

View File

@ -8,8 +8,11 @@
#include <Nazara/Math/Config.hpp>
#include <Nazara/Math/EulerAngles.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <limits>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzQuaternion<T>::NzQuaternion()
{
@ -53,9 +56,9 @@ NzQuaternion<T>::NzQuaternion(const NzQuaternion<U>& quat)
}
template<typename T>
T NzQuaternion<T>::DotProduct(const NzQuaternion& vec) const
T NzQuaternion<T>::DotProduct(const NzQuaternion& quat) const
{
return w*vec.w + x*vec.x + y*vec.y + z.vec.z;
return w*quat.w + x*quat.x + y*quat.y + z*quat.z;
}
template<typename T>
@ -73,6 +76,18 @@ NzQuaternion<T> NzQuaternion<T>::GetNormalized() const
return quat;
}
template<typename T>
void NzQuaternion<T>::MakeIdentity()
{
Set(1.0, 0.0, 0.0, 0.0);
}
template<typename T>
void NzQuaternion<T>::MakeZero()
{
Set(0.0, 0.0, 0.0, 0.0);
}
template<typename T>
T NzQuaternion<T>::Magnitude() const
{
@ -82,27 +97,21 @@ T NzQuaternion<T>::Magnitude() const
template<typename T>
T NzQuaternion<T>::Normalize()
{
T squaredLength = SquaredMagnitude();
T squaredMagnitude = SquaredMagnitude();
if (std::fabs(squaredLength) > 0.00001 && std::fabs(squaredLength - 1.0) > 0.00001)
if (squaredMagnitude-F(1.0) > std::numeric_limits<T>::epsilon())
{
T length = std::sqrt(squaredLength);
T magnitude = std::sqrt(squaredMagnitude);
w /= length;
x /= length;
y /= length;
z /= length;
w /= magnitude;
x /= magnitude;
y /= magnitude;
z /= magnitude;
return length;
return magnitude;
}
else
return 1.0; // Le quaternion est déjà normalisé
}
template<typename T>
T NzQuaternion<T>::SquaredMagnitude() const
{
return w * w + x * x + y * y + z * z;
return F(1.0); // Le quaternion est déjà normalisé
}
template<typename T>
@ -166,81 +175,29 @@ void NzQuaternion<T>::Set(const NzQuaternion& quat)
}
template<typename T>
void NzQuaternion<T>::SetIdentity()
T NzQuaternion<T>::SquaredMagnitude() const
{
Set(1.0, 0.0, 0.0, 0.0);
}
template<typename T>
void NzQuaternion<T>::SetZero()
{
Set(0.0, 0.0, 0.0, 0.0);
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp)
{
if (interp <= 0.0)
return quatA;
if (interp >= 1.0)
return quatB;
NzQuaternion q;
T cosOmega = quatA.DotProduct(quatB);
if (cosOmega < 0.0)
{
// On inverse tout
q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z);
cosOmega = -cosOmega;
}
else
q.Set(quatB);
T k0, k1;
if (cosOmega > 0.9999)
{
// Interpolation linéaire pour éviter une division par zéro
k0 = 1.0 - interp;
k1 = interp;
}
else
{
T sinOmega = std::sqrt(1.0f - (cosOmega * cosOmega));
T omega = std::atan2(sinOmega, cosOmega);
// Pour éviter deux divisions
sinOmega = 1/sinOmega;
k0 = std::sin((1.0 - interp) * omega) * sinOmega;
k1 = std::sin(interp * omega) * sinOmega;
}
NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z);
return result += q;
return w*w + x*x + y*y + z*z;
}
template<typename T>
NzEulerAngles<T> NzQuaternion<T>::ToEulerAngles() const
{
Normalize();
T test = x*y + z*w;
if (test > 0.499)
if (test > F(0.499))
// singularity at north pole
return NzEulerAngles<T>(NzDegrees(90.0), NzRadians(2.0 * std::atan2(x, w)), 0.0);
return NzEulerAngles<T>(NzDegrees(F(90.0)), NzRadians(F(2.0) * std::atan2(x, w)), F(0.0));
if (test < -0.499)
return NzEulerAngles<T>(NzDegrees(-90.0), NzRadians(-2.0 * std::atan2(x, w)), 0.0);
if (test < F(-0.499))
return NzEulerAngles<T>(NzDegrees(F(-90.0)), NzRadians(F(-2.0) * std::atan2(x, w)), F(0.0));
T xx = x*x;
T yy = y*y;
T zz = z*z;
return NzEulerAngles<T>(NzRadians(std::atan2(2.0*x*w - 2.0*y*z, 1.0 - 2.0*xx - 2.0*zz)),
NzRadians(std::atan2(2.0*y*w - 2.0*x*z, 1.f - 2.0*yy - 2.0*zz)),
NzRadians(std::asin(2.0*test)));
return NzEulerAngles<T>(NzRadians(std::atan2(F(2.0)*x*w - F(2.0)*y*z, F(1.0) - F(2.0)*xx - F(2.0)*zz)),
NzRadians(std::atan2(F(2.0)*y*w - F(2.0)*x*z, F(1.0) - F(2.0)*yy - F(2.0)*zz)),
NzRadians(std::asin(F(2.0)*test)));
}
template<typename T>
@ -251,6 +208,20 @@ NzString NzQuaternion<T>::ToString() const
return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')';
}
template<typename T>
NzQuaternion<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzQuaternion<T>& NzQuaternion<T>::operator=(const NzQuaternion& quat)
{
Set(quat);
return *this;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator+(const NzQuaternion& quat) const
{
@ -263,10 +234,10 @@ NzQuaternion<T> NzQuaternion<T>::operator+(const NzQuaternion& quat) const
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator*(const NzQuaternion& quat) const
{
return NzQuaternion(w * quat.w - x * quat.x - y * quat.y - z * quat.z,
w * quat.x + x * quat.w + y * quat.z - z * quat.y,
w * quat.y + y * quat.w + z * quat.x - x * quat.z,
w * quat.z + z * quat.w + x * quat.y - y * quat.x);
return NzQuaternion(w*quat.w - x*quat.x - y*quat.y - z*quat.z,
w*quat.x + x*quat.w + y*quat.z - z*quat.y,
w*quat.y + y*quat.w + z*quat.x - x*quat.z,
w*quat.z + z*quat.w + x*quat.y - y*quat.x);
}
template<typename T>
@ -276,7 +247,7 @@ NzVector3<T> NzQuaternion<T>::operator*(const NzVector3<T>& vec) const
normal.Normalize();
NzQuaternion qvec(0.0, normal.x, normal.y, normal.z);
NzQuaternion result = operator*(qvec * GetConjugate());
NzQuaternion result(operator*(qvec * GetConjugate()));
return NzVector3<T>(result.x, result.y, result.z);
@ -360,10 +331,74 @@ bool NzQuaternion<T>::operator>=(const NzQuaternion& quat) const
return !operator<(quat);
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::Identity()
{
NzQuaternion quaternion;
quaternion.MakeIdentity();
return quaternion;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp)
{
if (interp <= F(0.0))
return quatA;
if (interp >= F(1.0))
return quatB;
NzQuaternion q;
T cosOmega = quatA.DotProduct(quatB);
if (cosOmega < F(0.0))
{
// On inverse tout
q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z);
cosOmega = -cosOmega;
}
else
q.Set(quatB);
T k0, k1;
if (cosOmega > F(0.9999))
{
// Interpolation linéaire pour éviter une division par zéro
k0 = F(1.0) - interp;
k1 = interp;
}
else
{
T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega);
T omega = std::atan2(sinOmega, cosOmega);
// Pour éviter deux divisions
sinOmega = F(1.0)/sinOmega;
k0 = std::sin((F(1.0) - interp) * omega) * sinOmega;
k1 = std::sin(interp*omega) * sinOmega;
}
NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z);
return result += q*k1;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::Zero()
{
NzQuaternion quaternion;
quaternion.MakeZero();
return quaternion;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzQuaternion<T>& quat)
{
return out << quat.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -16,7 +16,8 @@ class NzRect
public:
NzRect();
NzRect(T X, T Y, T Width, T Height);
NzRect(T rect[4]);
NzRect(const T rect[4]);
NzRect(const NzVector2<T>& vec1, const NzVector2<T>& vec2);
template<typename U> explicit NzRect(const NzRect<U>& rect);
NzRect(const NzRect& rect) = default;
~NzRect() = default;
@ -30,11 +31,15 @@ class NzRect
NzVector2<T> GetCenter() const;
bool Intersect(const NzRect& rect) const;
bool Intersect(const NzRect& rect, NzRect& intersection) const;
bool Intersect(const NzRect& rect, NzRect* intersection = nullptr) const;
bool IsValid() const;
void Set(T X, T Y, T Width, T Height);
void Set(const T rect[4]);
void Set(const NzVector2<T>& vec1, const NzVector2<T>& vec2);
template<typename U> void Set(const NzRect<U>& rect);
NzString ToString() const;
operator NzString() const;

View File

@ -6,37 +6,36 @@
#include <algorithm>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzRect<T>::NzRect()
{
}
template<typename T>
NzRect<T>::NzRect(T X, T Y, T Width, T Height) :
x(X),
y(Y),
width(Width),
height(Height)
NzRect<T>::NzRect(T X, T Y, T Width, T Height)
{
Set(X, Y, Width, Height);
}
template<typename T>
NzRect<T>::NzRect(T vec[4]) :
x(vec[0]),
y(vec[1]),
width(vec[2]),
height(vec[3])
NzRect<T>::NzRect(const T vec[4])
{
Set(vec);
}
template<typename T>
NzRect<T>::NzRect(const NzVector2<T>& vec1, const NzVector2<T>& vec2)
{
Set(vec1, vec2);
}
template<typename T>
template<typename U>
NzRect<T>::NzRect(const NzRect<U>& rect) :
x(static_cast<T>(rect.x)),
y(static_cast<T>(rect.y)),
width(static_cast<T>(rect.width)),
height(static_cast<T>(rect.height))
NzRect<T>::NzRect(const NzRect<U>& rect)
{
Set(rect);
}
template<typename T>
@ -80,18 +79,11 @@ void NzRect<T>::ExtendTo(const NzRect& rect)
template<typename T>
NzVector2<T> NzRect<T>::GetCenter() const
{
return NzVector2<T>((x+width)/2, (y+height)/2);
return NzVector2<T>((x+width)/F(2.0), (y+height)/F(2.0));
}
template<typename T>
bool NzRect<T>::Intersect(const NzRect& rect) const
{
NzRect intersection; // Optimisé par le compilateur
return Intersect(rect, intersection);
}
template<typename T>
bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
bool NzRect<T>::Intersect(const NzRect& rect, NzRect* intersection) const
{
T left = std::max(x, rect.x);
T right = std::min(x+width, rect.x+rect.width);
@ -100,10 +92,13 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
if (left < right && top < bottom)
{
intersection.x = left;
intersection.y = top;
intersection.width = right-left;
intersection.height = bottom-top;
if (intersection)
{
intersection->x = left;
intersection->y = top;
intersection->width = right-left;
intersection->height = bottom-top;
}
return true;
}
@ -114,7 +109,44 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
template<typename T>
bool NzRect<T>::IsValid() const
{
return width > 0 && height > 0;
return width > F(0.0) && height > F(0.0);
}
template<typename T>
void NzRect<T>::Set(T X, T Y, T Width, T Height)
{
x = X;
y = Y;
width = Width;
height = Height;
}
template<typename T>
void NzRect<T>::Set(const T rect[4])
{
x = rect[0];
y = rect[1];
width = rect[2];
height = rect[3];
}
template<typename T>
void NzRect<T>::Set(const NzVector2<T>& vec1, const NzVector2<T>& vec2)
{
x = std::min(vec1.x, vec2.x);
y = std::min(vec1.y, vec2.y);
width = (vec2.x > vec1.x) ? vec2.x-vec1.x : vec1.x-vec2.x;
height = (vec2.y > vec1.y) ? vec2.y-vec1.y : vec1.y-vec2.y;
}
template<typename T>
template<typename U>
void NzRect<T>::Set(const NzRect<U>& rect)
{
x = F(rect.x);
y = F(rect.y);
width = F(rect.width);
height = F(rect.height);
}
template<typename T>
@ -134,6 +166,7 @@ NzRect<T>::operator NzString() const
template<typename T>
T& NzRect<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 4)
{
NzStringStream ss;
@ -141,6 +174,7 @@ T& NzRect<T>::operator[](unsigned int i)
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@ -148,6 +182,7 @@ T& NzRect<T>::operator[](unsigned int i)
template<typename T>
T NzRect<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 4)
{
NzStringStream ss;
@ -155,6 +190,7 @@ T NzRect<T>::operator[](unsigned int i) const
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@ -165,4 +201,6 @@ std::ostream& operator<<(std::ostream& out, const NzRect<T>& rect)
return out << rect.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -21,20 +21,37 @@ template<typename T> class NzVector2
~NzVector2() = default;
T AbsDotProduct(const NzVector2& vec) const;
T Distance(const NzVector2& vec) const;
float Distancef(const NzVector2& vec) const;
T DotProduct(const NzVector2& vec) const;
NzVector2 GetNormal() const;
void MakeCeil(const NzVector2& vec);
void MakeFloor(const NzVector2& vec);
void MakeUnitX();
void MakeUnitY();
void MakeZero();
T Length() const;
float Lengthf() const;
void Normalize();
void Set(T X, T Y);
void Set(T scale);
void Set(T vec[2]);
template<typename U> void Set(const NzVector2<U>& vec);
T SquaredDistance(const NzVector2& vec) const;
T SquaredLength() const;
NzString ToString() const;
operator NzString() const;
operator T*();
operator const T*() const;
@ -65,8 +82,11 @@ template<typename T> class NzVector2
bool operator>(const NzVector2& vec) const;
bool operator>=(const NzVector2& vec) const;
T x;
T y;
static NzVector2 UnitX();
static NzVector2 UnitY();
static NzVector2 Zero();
T x, y;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzVector2<T>& vec);

View File

@ -6,41 +6,40 @@
#include <Nazara/Math/Basic.hpp>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzVector2<T>::NzVector2()
{
}
template<typename T>
NzVector2<T>::NzVector2(T X, T Y) :
x(X),
y(Y)
NzVector2<T>::NzVector2(T X, T Y)
{
Set(X, Y);
}
template<typename T>
NzVector2<T>::NzVector2(T scale) :
x(scale),
y(scale)
NzVector2<T>::NzVector2(T scale)
{
Set(scale);
}
template<typename T>
NzVector2<T>::NzVector2(T vec[2]) :
x(vec[0]),
y(vec[1])
NzVector2<T>::NzVector2(T vec[2])
{
Set(vec);
}
template<typename T>
template<typename U>
NzVector2<T>::NzVector2(const NzVector2<U>& vec) :
x(static_cast<T>(vec.x)),
y(static_cast<T>(vec.y))
NzVector2<T>::NzVector2(const NzVector2<U>& vec)
{
Set(vec);
}
template<typename T>
@ -76,7 +75,7 @@ float NzVector2<T>::Distancef(const NzVector2& vec) const
template<typename T>
T NzVector2<T>::DotProduct(const NzVector2& vec) const
{
return x * vec.x + y * vec.y;
return x*vec.x + y*vec.y;
}
template<typename T>
@ -88,6 +87,18 @@ NzVector2<T> NzVector2<T>::GetNormal() const
return vec;
}
template<typename T>
T NzVector2<T>::Length() const
{
return std::sqrt(SquaredLength());
}
template<typename T>
float NzVector2<T>::Lengthf() const
{
return std::sqrt(static_cast<float>(SquaredLength()));
}
template<typename T>
void NzVector2<T>::MakeCeil(const NzVector2& vec)
{
@ -109,29 +120,65 @@ void NzVector2<T>::MakeFloor(const NzVector2& vec)
}
template<typename T>
T NzVector2<T>::Length() const
void NzVector2<T>::MakeUnitX()
{
return std::sqrt(SquaredLength());
Set(F(1.0), F(0.0));
}
template<typename T>
float NzVector2<T>::Lengthf() const
void NzVector2<T>::MakeUnitY()
{
return std::sqrt(static_cast<float>(SquaredLength()));
Set(F(0.0), F(1.0));
}
template<typename T>
void NzVector2<T>::MakeZero()
{
Set(F(0.0), F(0.0));
}
template<typename T>
void NzVector2<T>::Normalize()
{
auto length = Length();
T squaredLength = SquaredLength();
if (!NzNumberEquals(length, static_cast<T>(0.0)))
if (squaredLength-F(1.0) > std::numeric_limits<T>::epsilon())
{
T length = std::sqrt(squaredLength);
x /= length;
y /= length;
}
}
template<typename T>
void NzVector2<T>::Set(T X, T Y)
{
x = X;
y = Y;
}
template<typename T>
void NzVector2<T>::Set(T scale)
{
x = scale;
y = scale;
}
template<typename T>
void NzVector2<T>::Set(T vec[2])
{
std::memcpy(&x, vec, 2*sizeof(T));
}
template<typename T>
template<typename U>
void NzVector2<T>::Set(const NzVector2<U>& vec)
{
x = F(vec.x);
y = F(vec.y);
}
template<typename T>
T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
{
@ -141,7 +188,7 @@ T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
template<typename T>
T NzVector2<T>::SquaredLength() const
{
return x * x + y * y;
return x*x + y*y;
}
template<typename T>
@ -152,6 +199,12 @@ NzString NzVector2<T>::ToString() const
return ss << "Vector2(" << x << ", " << y << ')';
}
template<typename T>
NzVector2<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzVector2<T>::operator T*()
{
@ -167,6 +220,7 @@ NzVector2<T>::operator const T*() const
template<typename T>
T& NzVector2<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 2)
{
NzStringStream ss;
@ -174,6 +228,7 @@ T& NzVector2<T>::operator[](unsigned int i)
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@ -181,6 +236,7 @@ T& NzVector2<T>::operator[](unsigned int i)
template<typename T>
T NzVector2<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 2)
{
NzStringStream ss;
@ -188,6 +244,7 @@ T NzVector2<T>::operator[](unsigned int i) const
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@ -231,13 +288,15 @@ NzVector2<T> NzVector2<T>::operator*(T scale) const
template<typename T>
NzVector2<T> NzVector2<T>::operator/(const NzVector2& vec) const
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector2(x / vec.x, y / vec.y);
}
@ -245,13 +304,15 @@ NzVector2<T> NzVector2<T>::operator/(const NzVector2& vec) const
template<typename T>
NzVector2<T> NzVector2<T>::operator/(T scale) const
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector2(x / scale, y / scale);
}
@ -295,13 +356,15 @@ NzVector2<T>& NzVector2<T>::operator*=(T scale)
template<typename T>
NzVector2<T>& NzVector2<T>::operator/=(const NzVector2& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
x /= vec.x;
y /= vec.y;
@ -312,13 +375,15 @@ NzVector2<T>& NzVector2<T>::operator/=(const NzVector2& vec)
template<typename T>
NzVector2<T>& NzVector2<T>::operator/=(T scale)
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
x /= scale;
y /= scale;
@ -363,6 +428,33 @@ bool NzVector2<T>::operator>=(const NzVector2& vec) const
return !operator<(vec);
}
template<typename T>
NzVector2<T> NzVector2<T>::UnitX()
{
NzVector2 vector;
vector.MakeUnitX();
return vector;
}
template<typename T>
NzVector2<T> NzVector2<T>::UnitY()
{
NzVector2 vector;
vector.MakeUnitY();
return vector;
}
template<typename T>
NzVector2<T> NzVector2<T>::Zero()
{
NzVector2 vector;
vector.MakeZero();
return vector;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzVector2<T>& vec)
{
@ -378,15 +470,19 @@ NzVector2<T> operator*(T scale, const NzVector2<T>& vec)
template<typename T>
NzVector2<T> operator/(T scale, const NzVector2<T>& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector2<T>(scale/vec.x, scale/vec.y);
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -23,21 +23,41 @@ template<typename T> class NzVector3
~NzVector3() = default;
T AbsDotProduct(const NzVector3& vec) const;
NzVector3 CrossProduct(const NzVector3& vec) const;
T Distance(const NzVector3& vec) const;
float Distancef(const NzVector3& vec) const;
T DotProduct(const NzVector3& vec) const;
NzVector3 GetNormal() const;
void MakeCeil(const NzVector3& vec);
void MakeFloor(const NzVector3& vec);
T Length() const;
float Lengthf() const;
void MakeCeil(const NzVector3& vec);
void MakeFloor(const NzVector3& vec);
void MakeUnitX();
void MakeUnitY();
void MakeUnitZ();
void MakeZero();
void Normalize();
void Set(T X, T Y, T Z);
void Set(T scale);
void Set(T vec[3]);
void Set(const NzVector2<T>& vec, T Z = 0.0);
template<typename U> void Set(const NzVector3<U>& vec);
T SquaredDistance(const NzVector3& vec) const;
T SquaredLength() const;
NzString ToString() const;
operator NzString() const;
operator T*();
operator const T*() const;
@ -68,9 +88,12 @@ template<typename T> class NzVector3
bool operator>(const NzVector3& vec) const;
bool operator>=(const NzVector3& vec) const;
T x;
T y;
T z;
static NzVector3 UnitX();
static NzVector3 UnitY();
static NzVector3 UnitZ();
static NzVector3 Zero();
T x, y, z;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzVector3<T>& vec);

View File

@ -6,53 +6,46 @@
#include <Nazara/Math/Basic.hpp>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzVector3<T>::NzVector3()
{
}
template<typename T>
NzVector3<T>::NzVector3(T X, T Y, T Z) :
x(X),
y(Y),
z(Z)
NzVector3<T>::NzVector3(T X, T Y, T Z)
{
Set(X, Y, Z);
}
template<typename T>
NzVector3<T>::NzVector3(T scale) :
x(scale),
y(scale),
z(scale)
NzVector3<T>::NzVector3(T scale)
{
Set(scale);
}
template<typename T>
NzVector3<T>::NzVector3(T vec[3]) :
x(vec[0]),
y(vec[1]),
z(vec[2])
NzVector3<T>::NzVector3(T vec[3])
{
Set(vec);
}
template<typename T>
NzVector3<T>::NzVector3(const NzVector2<T>& vec, T Z) :
x(vec.x),
y(vec.y),
z(Z)
NzVector3<T>::NzVector3(const NzVector2<T>& vec, T Z)
{
Set(vec, Z);
}
template<typename T>
template<typename U>
NzVector3<T>::NzVector3(const NzVector3<U>& vec) :
x(static_cast<T>(vec.x)),
y(static_cast<T>(vec.y)),
z(static_cast<T>(vec.z))
NzVector3<T>::NzVector3(const NzVector3<U>& vec)
{
Set(vec);
}
template<typename T>
@ -94,7 +87,7 @@ float NzVector3<T>::Distancef(const NzVector3& vec) const
template<typename T>
T NzVector3<T>::DotProduct(const NzVector3& vec) const
{
return x * vec.x + y * vec.y + z * vec.z;
return x*vec.x + y*vec.y + z*vec.z;
}
template<typename T>
@ -132,6 +125,30 @@ void NzVector3<T>::MakeFloor(const NzVector3& vec)
z = vec.z;
}
template<typename T>
void NzVector3<T>::MakeUnitX()
{
Set(F(1.0), F(0.0), F(0.0));
}
template<typename T>
void NzVector3<T>::MakeUnitY()
{
Set(F(0.0), F(1.0), F(0.0));
}
template<typename T>
void NzVector3<T>::MakeUnitZ()
{
Set(F(0.0), F(0.0), F(1.0));
}
template<typename T>
void NzVector3<T>::MakeZero()
{
Set(F(0.0), F(0.0), F(0.0));
}
template<typename T>
T NzVector3<T>::Length() const
{
@ -147,16 +164,57 @@ float NzVector3<T>::Lengthf() const
template<typename T>
void NzVector3<T>::Normalize()
{
T length = Length();
T squaredLength = SquaredLength();
if (!NzNumberEquals(length, static_cast<T>(0.0)))
if (squaredLength-F(1.0) > std::numeric_limits<T>::epsilon())
{
T length = std::sqrt(squaredLength);
x /= length;
y /= length;
z /= length;
}
}
template<typename T>
void NzVector3<T>::Set(T X, T Y, T Z)
{
x = X;
y = Y;
z = Z;
}
template<typename T>
void NzVector3<T>::Set(T scale)
{
x = scale;
y = scale;
z = scale;
}
template<typename T>
void NzVector3<T>::Set(T vec[3])
{
std::memcpy(&x, vec, 3*sizeof(T));
}
template<typename T>
void NzVector3<T>::Set(const NzVector2<T>& vec, T Z)
{
x = vec.x;
y = vec.y;
z = Z;
}
template<typename T>
template<typename U>
void NzVector3<T>::Set(const NzVector3<U>& vec)
{
x = F(vec.x);
y = F(vec.y);
z = F(vec.z);
}
template<typename T>
T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
{
@ -166,7 +224,7 @@ T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
template<typename T>
T NzVector3<T>::SquaredLength() const
{
return x * x + y * y + z * z;
return x*x + y*y + z*z;
}
template<typename T>
@ -177,6 +235,12 @@ NzString NzVector3<T>::ToString() const
return ss << "Vector3(" << x << ", " << y << ", " << z <<')';
}
template<typename T>
NzVector3<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzVector3<T>::operator T*()
{
@ -192,13 +256,15 @@ NzVector3<T>::operator const T*() const
template<typename T>
T& NzVector3<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 3)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)";
throw std::domain_error(ss.ToString());
throw std::out_of_range(ss.ToString());
}
#endif
return *(&x+i);
}
@ -206,13 +272,15 @@ T& NzVector3<T>::operator[](unsigned int i)
template<typename T>
T NzVector3<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 3)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)";
throw std::domain_error(ss.ToString());
throw std::out_of_range(ss.ToString());
}
#endif
return *(&x+i);
}
@ -256,13 +324,15 @@ NzVector3<T> NzVector3<T>::operator*(T scale) const
template<typename T>
NzVector3<T> NzVector3<T>::operator/(const NzVector3& vec) const
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector3(x / vec.x, y / vec.y, z / vec.z);
}
@ -270,13 +340,15 @@ NzVector3<T> NzVector3<T>::operator/(const NzVector3& vec) const
template<typename T>
NzVector3<T> NzVector3<T>::operator/(T scale) const
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector3(x / scale, y / scale, z / scale);
}
@ -324,7 +396,7 @@ NzVector3<T>& NzVector3<T>::operator*=(T scale)
template<typename T>
NzVector3<T>& NzVector3<T>::operator/=(const NzVector3& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
@ -342,7 +414,7 @@ NzVector3<T>& NzVector3<T>::operator/=(const NzVector3& vec)
template<typename T>
NzVector3<T>& NzVector3<T>::operator/=(T scale)
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
@ -395,6 +467,42 @@ bool NzVector3<T>::operator>=(const NzVector3& vec) const
return !operator<(vec);
}
template<typename T>
NzVector3<T> NzVector3<T>::UnitX()
{
NzVector3 vector;
vector.MakeUnitX();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::UnitY()
{
NzVector3 vector;
vector.MakeUnitY();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::UnitZ()
{
NzVector3 vector;
vector.MakeUnitZ();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::Zero()
{
NzVector3 vector;
vector.MakeZero();
return vector;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzVector3<T>& vec)
{
@ -410,15 +518,19 @@ NzVector3<T> operator*(T scale, const NzVector3<T>& vec)
template<typename T>
NzVector3<T> operator/(T scale, const NzVector3<T>& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector3<T>(scale / vec.x, scale / vec.y, scale / vec.z);
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -17,19 +17,34 @@ template<typename T> class NzVector4
NzVector4(T X, T Y, T Z, T W = 1.0);
explicit NzVector4(T scale);
NzVector4(T vec[4]);
template<typename U> explicit NzVector4(const NzVector4<U>& vec);
NzVector4(const NzVector3<T>& vec, T W = 1.0);
template<typename U> explicit NzVector4(const NzVector4<U>& vec);
NzVector4(const NzVector4& vec) = default;
~NzVector4() = default;
T AbsDotProduct(const NzVector4& vec) const;
T DotProduct(const NzVector4& vec) const;
void MakeCeil(const NzVector4& vec);
void MakeFloor(const NzVector4& vec);
void MakeUnitX();
void MakeUnitY();
void MakeUnitZ();
void MakeZero();
void Normalize();
void Set(T X, T Y, T Z, T W = 1.0);
void Set(T scale);
void Set(T vec[4]);
void Set(const NzVector3<T>& vec, T W = 1.0);
template<typename U> void Set(const NzVector4<U>& vec);
NzString ToString() const;
operator NzString() const;
operator T*();
operator const T*() const;
@ -60,10 +75,12 @@ template<typename T> class NzVector4
bool operator>(const NzVector4& vec) const;
bool operator>=(const NzVector4& vec) const;
T x;
T y;
T z;
T w;
static NzVector4 UnitX();
static NzVector4 UnitY();
static NzVector4 UnitZ();
static NzVector4 Zero();
T x, y, z, w;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzVector4<T>& vec);

View File

@ -9,55 +9,44 @@
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D
#define F(a) static_cast<T>(a)
template<typename T>
NzVector4<T>::NzVector4()
{
}
template<typename T>
NzVector4<T>::NzVector4(T X, T Y, T Z, T W) :
x(X),
y(Y),
z(Z),
w(W)
NzVector4<T>::NzVector4(T X, T Y, T Z, T W)
{
Set(X, Y, Z, W);
}
template<typename T>
NzVector4<T>::NzVector4(T scale) :
x(scale),
y(scale),
z(scale),
w(scale)
NzVector4<T>::NzVector4(T scale)
{
Set(scale);
}
template<typename T>
NzVector4<T>::NzVector4(T vec[4]) :
x(vec[0]),
y(vec[1]),
z(vec[2]),
w(vec[3])
NzVector4<T>::NzVector4(T vec[4])
{
Set(vec);
}
template<typename T>
NzVector4<T>::NzVector4(const NzVector3<T>& vec, T W)
{
Set(vec, W);
}
template<typename T>
template<typename U>
NzVector4<T>::NzVector4(const NzVector4<U>& vec) :
x(static_cast<T>(vec.x)),
y(static_cast<T>(vec.y)),
z(static_cast<T>(vec.z)),
w(static_cast<T>(vec.w))
{
}
template<typename T>
NzVector4<T>::NzVector4(const NzVector3<T>& vec, T W) :
x(vec.x),
y(vec.y),
z(vec.z),
w(W)
NzVector4<T>::NzVector4(const NzVector4<U>& vec)
{
Set(vec);
}
template<typename T>
@ -81,7 +70,7 @@ inline unsigned int NzVector4<unsigned int>::AbsDotProduct(const NzVector4<unsig
template<typename T>
T NzVector4<T>::DotProduct(const NzVector4& vec) const
{
return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
return x*vec.x + y*vec.y + z*vec.z + w*vec.w;
}
template<typename T>
@ -116,10 +105,34 @@ void NzVector4<T>::MakeFloor(const NzVector4& vec)
w = vec.w;
}
template<typename T>
void NzVector4<T>::MakeUnitX()
{
Set(F(1.0), F(0.0), F(0.0), F(1.0));
}
template<typename T>
void NzVector4<T>::MakeUnitY()
{
Set(F(0.0), F(1.0), F(0.0), F(1.0));
}
template<typename T>
void NzVector4<T>::MakeUnitZ()
{
Set(F(0.0), F(0.0), F(1.0), F(1.0));
}
template<typename T>
void NzVector4<T>::MakeZero()
{
Set(F(0.0), F(0.0), F(0.0), F(0.0));
}
template<typename T>
void NzVector4<T>::Normalize()
{
if (!NzNumberEquals(w, static_cast<T>(0.0)))
if (!NzNumberEquals(w, F(0.0)))
{
x /= w;
y /= w;
@ -127,6 +140,49 @@ void NzVector4<T>::Normalize()
}
}
template<typename T>
void NzVector4<T>::Set(T X, T Y, T Z, T W)
{
w = W;
x = X;
y = Y;
z = Z;
}
template<typename T>
void NzVector4<T>::Set(T scale)
{
w = scale;
x = scale;
y = scale;
z = scale;
}
template<typename T>
void NzVector4<T>::Set(T vec[4])
{
std::memcpy(&x, vec, 4*sizeof(T));
}
template<typename T>
void NzVector4<T>::Set(const NzVector3<T>& vec, T W)
{
w = W;
x = vec.x;
y = vec.y;
z = vec.z;
}
template<typename T>
template<typename U>
void NzVector4<T>::Set(const NzVector4<U>& vec)
{
w = F(vec.w);
x = F(vec.x);
y = F(vec.y);
z = F(vec.z);
}
template<typename T>
NzString NzVector4<T>::ToString() const
{
@ -135,6 +191,12 @@ NzString NzVector4<T>::ToString() const
return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')';
}
template<typename T>
NzVector4<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzVector4<T>::operator T*()
{
@ -150,6 +212,7 @@ NzVector4<T>::operator const T*() const
template<typename T>
T& NzVector4<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 4)
{
NzStringStream ss;
@ -157,6 +220,7 @@ T& NzVector4<T>::operator[](unsigned int i)
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@ -164,6 +228,7 @@ T& NzVector4<T>::operator[](unsigned int i)
template<typename T>
T NzVector4<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 4)
{
NzStringStream ss;
@ -171,6 +236,7 @@ T NzVector4<T>::operator[](unsigned int i) const
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@ -214,13 +280,15 @@ NzVector4<T> NzVector4<T>::operator*(T scale) const
template<typename T>
NzVector4<T> NzVector4<T>::operator/(const NzVector4& vec) const
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)) || NzNumberEquals(vec.w, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w);
}
@ -228,13 +296,15 @@ NzVector4<T> NzVector4<T>::operator/(const NzVector4& vec) const
template<typename T>
NzVector4<T> NzVector4<T>::operator/(T scale) const
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector4(x / scale, y / scale, z / scale, w / scale);
}
@ -286,13 +356,15 @@ NzVector4<T>& NzVector4<T>::operator*=(T scale)
template<typename T>
NzVector4<T>& NzVector4<T>::operator/=(const NzVector4& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)) || NzNumberEquals(vec.w, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
x /= vec.x;
y /= vec.y;
@ -305,13 +377,15 @@ NzVector4<T>& NzVector4<T>::operator/=(const NzVector4& vec)
template<typename T>
NzVector4<T>& NzVector4<T>::operator/=(T scale)
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
x /= scale;
y /= scale;
@ -360,6 +434,42 @@ bool NzVector4<T>::operator>=(const NzVector4& vec) const
return !operator<(vec);
}
template<typename T>
NzVector4<T> NzVector4<T>::UnitX()
{
NzVector4 vector;
vector.MakeUnitX();
return vector;
}
template<typename T>
NzVector4<T> NzVector4<T>::UnitY()
{
NzVector4 vector;
vector.MakeUnitY();
return vector;
}
template<typename T>
NzVector4<T> NzVector4<T>::UnitZ()
{
NzVector4 vector;
vector.MakeUnitZ();
return vector;
}
template<typename T>
NzVector4<T> NzVector4<T>::Zero()
{
NzVector4 vector;
vector.MakeZero();
return vector;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzVector4<T>& vec)
{
@ -375,15 +485,19 @@ NzVector4<T> operator*(T scale, const NzVector4<T>& vec)
template<typename T>
NzVector4<T> operator/(T scale, const NzVector4<T>& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)) || NzNumberEquals(vec.w, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector4<T>(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w);
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -1,11 +0,0 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/Config.hpp>
#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

39
include/Nazara/Noise.hpp Normal file
View File

@ -0,0 +1,39 @@
// This file was automatically generated by Nazara
/*
Nazara Engine - NzNoise Module
Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <Nazara/Noise/ComplexNoiseBase.hpp>
#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/Noise.hpp>
#include <Nazara/Noise/NoiseBase.hpp>
#include <Nazara/Noise/NoiseMachine.hpp>
#include <Nazara/Noise/Perlin2D.hpp>
#include <Nazara/Noise/Perlin3D.hpp>
#include <Nazara/Noise/Perlin4D.hpp>
#include <Nazara/Noise/Simplex2D.hpp>
#include <Nazara/Noise/Simplex3D.hpp>
#include <Nazara/Noise/Simplex4D.hpp>

View File

@ -1,8 +1,4 @@
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Nazara Engine - NzNoise Module
Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net)

View File

@ -8,20 +8,22 @@
#define NAZARA_NOISE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
class NAZARA_API NzNoise
{
public:
NzNoise();
~NzNoise();
NzNoise() = delete;
~NzNoise() = delete;
bool Initialize();
void Uninitialize();
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static bool s_initialized;
static unsigned int s_moduleReferenceCouter;
};
#endif // NOISE_HPP
#endif // NAZARA_NOISE_HPP

View File

@ -6,7 +6,7 @@
#define NAZARA_PREREQUESITES_HPP
#if __cplusplus < 201103L
#error Nazara requires a C++11 compliant compiler
#error Nazara requires a C++11 compliant compiler
#endif
// Version du moteur
@ -42,7 +42,7 @@
#define NazaraUnused(a) (void) a
#if defined(_WIN32) || defined(__WIN32__) || defined(NAZARA_PLATFORM_WINDOWSVISTA)
#if defined(_WIN32) || defined(__WIN32__)
#if !defined(NAZARA_STATIC)
#ifdef NAZARA_BUILD
#define NAZARA_API __declspec(dllexport)
@ -71,6 +71,7 @@
#define NAZARA_WINNT 0x0501
#endif
// Pour ne pas casser le define déjà en place s'il est applicable
#if defined(_WIN32_WINNT)
#if _WIN32_WINNT < NAZARA_WINNT
#undef _WIN32_WINNT
@ -110,6 +111,16 @@
#include <cstdint>
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
typedef int8_t nzInt8;
typedef uint8_t nzUInt8;

View File

@ -0,0 +1,40 @@
// This file was automatically generated by Nazara
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Context.hpp>
#include <Nazara/Renderer/ContextParameters.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/OcclusionQuery.hpp>
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/RenderTargetParameters.hpp>
#include <Nazara/Renderer/RenderWindow.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/Texture.hpp>

View File

@ -32,9 +32,6 @@
// Active une fenêtre de rendu (NzRenderWindow) lors de sa création
#define NAZARA_RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION 1
// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes/plus de consommation mémoire)
#define NAZARA_RENDERER_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 0
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_RENDERER_MEMORYLEAKTRACKER 0

View File

@ -35,6 +35,15 @@ enum nzFaceFilling
nzFaceFilling_Fill
};
enum nzMatrixType
{
nzMatrixType_Projection,
nzMatrixType_View,
nzMatrixType_World,
nzMatrixType_Max = nzMatrixType_World
};
enum nzPixelBufferType
{
nzPixelBufferType_Pack,

View File

@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifdef NAZARA_RENDERER_COMMON
#error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it
#error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it
#endif
#pragma once
@ -12,18 +12,16 @@
#define NAZARA_OPENGL_HPP
// gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier
#include <GL3/gl3.h>
#include <GL3/glcorearb.h>
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
// Il semblerait qu'il ne soit pas conseillé d'inclure gl3.h t glext.h en même temps, mais je ne vois pas oomment gérer les extensions autrement...
// Inclusion des extensions
#include <GL3/glext.h>
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <GL3/wglext.h>
#elif defined(NAZARA_PLATFORM_LINUX)
#include <GL3/glxext.h>
#else
#error OS not handled
#endif
typedef void (*NzOpenGLFunc)();
@ -40,11 +38,12 @@ class NAZARA_API NzOpenGL
PixelBufferObject,
SeparateShaderObjects,
Texture3D,
TextureArray,
TextureCompression_s3tc,
TextureStorage,
VertexArrayObject,
Count
Max = VertexArrayObject
};
static NzOpenGLFunc GetEntry(const NzString& entryPoint);

View File

@ -10,6 +10,7 @@
#define NAZARA_RENDERWINDOW_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/ContextParameters.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
@ -23,7 +24,7 @@ struct NzContextParameters;
class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
{
public:
NzRenderWindow();
NzRenderWindow() = default;
NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters());
NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters());
virtual ~NzRenderWindow();
@ -52,15 +53,19 @@ class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
bool IsValid() const;
void SetFramerateLimit(unsigned int limit);
protected:
bool Activate();
virtual bool Activate() override;
private:
void OnClose();
bool OnCreate();
virtual void OnWindowDestroying() override;
virtual bool OnWindowCreated() override;
NzContext* m_context;
NzClock m_clock;
NzContextParameters m_parameters;
NzContext* m_context = nullptr;
unsigned int m_framerateLimit = 0;
};
#endif // NAZARA_RENDERWINDOW_HPP

View File

@ -8,99 +8,76 @@
#define NAZARA_RENDERER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <map>
#include <tuple>
#define NazaraRenderer NzRenderer::Instance()
class NzColor;
class NzContext;
class NzIndexBuffer;
class NzRenderTarget;
class NzShader;
class NzUtility;
class NzVertexBuffer;
class NzVertexDeclaration;
class NAZARA_API NzRenderer
{
public:
NzRenderer();
~NzRenderer();
NzRenderer() = delete;
~NzRenderer() = delete;
void Clear(unsigned long flags = nzRendererClear_Color | nzRendererClear_Depth);
static void Clear(unsigned long flags = nzRendererClear_Color | nzRendererClear_Depth);
void DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount);
void DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount);
static void DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount);
static void DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount);
void Enable(nzRendererParameter parameter, bool enable);
static void Enable(nzRendererParameter parameter, bool enable);
unsigned int GetMaxAnisotropyLevel() const;
unsigned int GetMaxRenderTargets() const;
unsigned int GetMaxTextureUnits() const;
NzShader* GetShader() const;
NzRenderTarget* GetTarget() const;
NzRectui GetViewport() const;
//static NzMatrix4f GetMatrix(nzMatrixCombination combination);
static NzMatrix4f GetMatrix(nzMatrixType type);
static unsigned int GetMaxAnisotropyLevel();
static unsigned int GetMaxRenderTargets();
static unsigned int GetMaxTextureUnits();
static NzShader* GetShader();
static NzRenderTarget* GetTarget();
static NzRectui GetViewport();
bool HasCapability(nzRendererCap capability) const;
bool Initialize();
static bool HasCapability(nzRendererCap capability);
void SetBlendFunc(nzBlendFunc src, nzBlendFunc dest);
void SetClearColor(const NzColor& color);
void SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a = 255);
void SetClearDepth(double depth);
void SetClearStencil(unsigned int value);
void SetFaceCulling(nzFaceCulling cullingMode);
void SetFaceFilling(nzFaceFilling fillingMode);
bool SetIndexBuffer(const NzIndexBuffer* indexBuffer);
bool SetShader(NzShader* shader);
void SetStencilCompareFunction(nzRendererComparison compareFunc);
void SetStencilFailOperation(nzStencilOperation failOperation);
void SetStencilMask(nzUInt32 mask);
void SetStencilPassOperation(nzStencilOperation passOperation);
void SetStencilReferenceValue(unsigned int refValue);
void SetStencilZFailOperation(nzStencilOperation zfailOperation);
bool SetTarget(NzRenderTarget* target);
bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer);
bool SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration);
void SetViewport(const NzRectui& viewport);
static bool Initialize();
void Uninitialize();
static NzRenderer* Instance();
static bool IsInitialized();
static void SetBlendFunc(nzBlendFunc src, nzBlendFunc dest);
static void SetClearColor(const NzColor& color);
static void SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a = 255);
static void SetClearDepth(double depth);
static void SetClearStencil(unsigned int value);
static void SetFaceCulling(nzFaceCulling cullingMode);
static void SetFaceFilling(nzFaceFilling fillingMode);
static bool SetIndexBuffer(const NzIndexBuffer* indexBuffer);
static void SetMatrix(nzMatrixType type, const NzMatrix4f& matrix);
static bool SetShader(NzShader* shader);
static void SetStencilCompareFunction(nzRendererComparison compareFunc);
static void SetStencilFailOperation(nzStencilOperation failOperation);
static void SetStencilMask(nzUInt32 mask);
static void SetStencilPassOperation(nzStencilOperation passOperation);
static void SetStencilReferenceValue(unsigned int refValue);
static void SetStencilZFailOperation(nzStencilOperation zfailOperation);
static bool SetTarget(NzRenderTarget* target);
static bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer);
static bool SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration);
static void SetViewport(const NzRectui& viewport);
static void Uninitialize();
private:
bool EnsureStateUpdate();
static bool EnsureStateUpdate();
typedef std::tuple<const NzContext*, const NzIndexBuffer*, const NzVertexBuffer*, const NzVertexDeclaration*> VAO_Key;
std::map<VAO_Key, unsigned int> m_vaos;
nzRendererComparison m_stencilCompare;
nzStencilOperation m_stencilFail;
nzStencilOperation m_stencilPass;
nzStencilOperation m_stencilZFail;
nzUInt32 m_stencilMask;
const NzIndexBuffer* m_indexBuffer;
NzRenderTarget* m_target;
NzShader* m_shader;
NzUtility* m_utilityModule;
const NzVertexBuffer* m_vertexBuffer;
const NzVertexDeclaration* m_vertexDeclaration;
bool m_vaoUpdated;
bool m_capabilities[nzRendererCap_Max+1];
bool m_stencilFuncUpdated;
bool m_stencilOpUpdated;
unsigned int m_maxAnisotropyLevel;
unsigned int m_maxRenderTarget;
unsigned int m_maxTextureUnit;
unsigned int m_stencilReference;
static NzRenderer* s_instance;
static bool s_initialized;
static unsigned int s_moduleReferenceCouter;
};
#endif // NAZARA_RENDERER_HPP

View File

@ -9,13 +9,13 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
class NzRenderer;
class NzShaderImpl;
@ -38,6 +38,9 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable
NzString GetLog() const;
nzShaderLanguage GetLanguage() const;
NzString GetSourceCode(nzShaderType type) const;
int GetUniformLocation(const NzString& name) const;
bool HasUniform(const NzString& name) const;
bool IsCompiled() const;
bool IsLoaded(nzShaderType type) const;
@ -47,19 +50,19 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable
bool Lock();
bool SendBoolean(const NzString& name, bool value);
bool SendDouble(const NzString& name, double value);
bool SendFloat(const NzString& name, float value);
bool SendInteger(const NzString& name, int value);
bool SendMatrix(const NzString& name, const NzMatrix4d& matrix);
bool SendMatrix(const NzString& name, const NzMatrix4f& matrix);
bool SendVector(const NzString& name, const NzVector2d& vector);
bool SendVector(const NzString& name, const NzVector2f& vector);
bool SendVector(const NzString& name, const NzVector3d& vector);
bool SendVector(const NzString& name, const NzVector3f& vector);
bool SendVector(const NzString& name, const NzVector4d& vector);
bool SendVector(const NzString& name, const NzVector4f& vector);
bool SendTexture(const NzString& name, NzTexture* texture);
bool SendBoolean(int location, bool value);
bool SendDouble(int location, double value);
bool SendFloat(int location, float value);
bool SendInteger(int location, int value);
bool SendMatrix(int location, const NzMatrix4d& matrix);
bool SendMatrix(int location, const NzMatrix4f& matrix);
bool SendTexture(int location, const NzTexture* texture);
bool SendVector(int location, const NzVector2d& vector);
bool SendVector(int location, const NzVector2f& vector);
bool SendVector(int location, const NzVector3d& vector);
bool SendVector(int location, const NzVector3f& vector);
bool SendVector(int location, const NzVector4d& vector);
bool SendVector(int location, const NzVector4f& vector);
void Unlock();

View File

@ -0,0 +1,53 @@
// This file was automatically generated by Nazara
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/BufferImpl.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Cursor.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Event.hpp>
#include <Nazara/Utility/Icon.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/Keyboard.hpp>
#include <Nazara/Utility/KeyframeMesh.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/Mouse.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/StaticMesh.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/VideoMode.hpp>
#include <Nazara/Utility/Window.hpp>
#include <Nazara/Utility/WindowHandle.hpp>

View File

@ -8,9 +8,9 @@
#define NAZARA_ANIMATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <list>
#include <map>

View File

@ -0,0 +1,50 @@
// Copyright (C) 2011 Jérôme Leclercq
// This file is part of the "Ungine".
// For conditions of distribution and use, see copyright notice in Core.h
#ifndef NAZARA_AXISALIGNEDBOX_HPP
#define NAZARA_AXISALIGNEDBOX_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Enums.hpp>
class NAZARA_API NzAxisAlignedBox
{
public:
NzAxisAlignedBox();
NzAxisAlignedBox(const NzVector3f& vec1, const NzVector3f& vec2);
NzAxisAlignedBox(nzExtend extend);
bool Contains(const NzAxisAlignedBox& box);
void ExtendTo(const NzAxisAlignedBox& box);
void ExtendTo(const NzVector3f& vector);
nzExtend GetExtend() const;
NzVector3f GetMaximum() const;
NzVector3f GetMinimum() const;
bool IsFinite() const;
bool IsInfinite() const;
bool IsNull() const;
void SetInfinite();
void SetExtends(const NzVector3f& vec1, const NzVector3f& vec2);
void SetNull();
NzString ToString() const;
static const NzAxisAlignedBox Infinite;
static const NzAxisAlignedBox Null;
private:
nzExtend m_extend;
NzCubef m_cube;
};
NAZARA_API std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox& aabb);
#endif // NAZARA_AXISALIGNEDBOX_HPP

View File

@ -9,8 +9,8 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
class NzBufferImpl;
class NzRenderer;

View File

@ -29,6 +29,9 @@
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes/plus de consommation mémoire)
#define NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 0
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_UTILITY_MEMORYLEAKTRACKER 0
@ -38,12 +41,11 @@
// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte
#define NAZARA_UTILITY_THREADED_WINDOW 0 ///FIXME: Buggé depuis GCC 4.7
// Protège le module des accès concurrentiels
// Protège les classes des accès concurrentiels
#define NAZARA_UTILITY_THREADSAFE 1
#if NAZARA_UTILITY_THREADSAFE
#define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW)
#define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW)
#endif
// Les classes à protéger des accès concurrentiels
#define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW)
#define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW)
#endif // NAZARA_CONFIG_UTILITY_HPP

View File

@ -24,6 +24,7 @@ enum nzBufferAccess
enum nzBufferStorage
{
//nzBufferStorage_Both,
nzBufferStorage_Hardware,
nzBufferStorage_Software,
@ -44,8 +45,8 @@ enum nzBufferUsage
enum nzCubemapFace
{
// L'ordre est X, -X, Y, -Y, Z, -Z
// Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap
// L'ordre est X, -X, Y, -Y, Z, -Z
nzCubemapFace_PositiveX = 0,
nzCubemapFace_PositiveY = 2,
nzCubemapFace_PositiveZ = 4,
@ -86,10 +87,38 @@ enum nzElementUsage
nzElementUsage_Max = nzElementUsage_TexCoord
};
enum nzEventType
{
nzEventType_GainedFocus,
nzEventType_LostFocus,
nzEventType_KeyPressed,
nzEventType_KeyReleased,
nzEventType_MouseButtonDoubleClicked,
nzEventType_MouseButtonPressed,
nzEventType_MouseButtonReleased,
nzEventType_MouseEntered,
nzEventType_MouseLeft,
nzEventType_MouseMoved,
nzEventType_MouseWheelMoved,
nzEventType_Moved,
nzEventType_Quit,
nzEventType_Resized,
nzEventType_TextEntered
};
enum nzExtend
{
nzExtend_Finite,
nzExtend_Infinite,
nzExtend_Null
};
enum nzImageType
{
nzImageType_1D,
nzImageType_1D_Array,
nzImageType_2D,
nzImageType_2D_Array,
nzImageType_3D,
nzImageType_Cubemap,

View File

@ -14,15 +14,22 @@
struct NzEvent
{
// Utilisé par:
// -nzEventType_KeyPressed
// -nzEventType_KeyReleased
struct KeyEvent
{
NzKeyboard::Key code;
bool alt;
bool control;
bool repeated;
bool shift;
bool system;
};
// Utilisé par:
// -nzEventType_MouseButtonDoubleClicked
// -nzEventType_MouseButtonPressed
struct MouseButtonEvent
{
NzMouse::Button button;
@ -30,63 +37,79 @@ struct NzEvent
unsigned int y;
};
// Utilisé par:
// -nzEventType_MouseMoved
struct MouseMoveEvent
{
int x;
int y;
int deltaX;
int deltaY;
unsigned int x;
unsigned int y;
};
// Utilisé par:
// -nzEventType_MouseWheelMoved
struct MouseWheelEvent
{
float delta;
};
// Utilisé par:
// -nzEventType_Moved
struct PositionEvent
{
int x;
int y;
};
// Utilisé par:
// -nzEventType_Resized
struct SizeEvent
{
unsigned int height;
unsigned int width;
};
// Utilisé par:
// -nzEventType_TextEntered
struct TextEvent
{
bool repeated;
char32_t character;
};
enum Type
{
GainedFocus,
LostFocus,
KeyPressed,
KeyReleased,
MouseButtonDoubleClicked,
MouseButtonPressed,
MouseButtonReleased,
MouseEntered,
MouseLeft,
MouseMoved,
MouseWheelMoved,
Moved,
Quit,
Resized,
TextEntered
};
Type type;
nzEventType type;
union
{
// Utilisé par:
// -nzEventType_KeyPressed
// -nzEventType_KeyReleased
KeyEvent key;
// Utilisé par:
// -nzEventType_MouseButtonDoubleClicked
// -nzEventType_MouseButtonPressed
MouseButtonEvent mouseButton;
// Utilisé par:
// -nzEventType_MouseMoved
MouseMoveEvent mouseMove;
// Utilisé par:
// -nzEventType_MouseWheelMoved
MouseWheelEvent mouseWheel;
// Utilisé par:
// -nzEventType_Moved
PositionEvent position;
// Utilisé par:
// -nzEventType_Resized
SizeEvent size;
// Utilisé par:
// -nzEventType_TextEntered
TextEvent text;
};
};

View File

@ -10,17 +10,17 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <list>
#include <map>
#if NAZARA_THREADSAFETY_IMAGE
#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_IMAGE
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@ -49,7 +49,7 @@ class NAZARA_API NzImage : public NzResource
NzImage();
NzImage(const NzImage& image);
NzImage(NzImage&& image);
NzImage(NzImage&& image) noexcept;
NzImage(SharedImage* sharedImage);
~NzImage();
@ -68,14 +68,14 @@ class NAZARA_API NzImage : public NzResource
bool FlipVertically();
nzUInt8 GetBPP() const;
const nzUInt8* GetConstPixels(nzUInt8 level = 0, unsigned int x = 0, unsigned int y = 0, unsigned int z = 0) const;
const nzUInt8* GetConstPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0) const;
unsigned int GetDepth(nzUInt8 level = 0) const;
nzPixelFormat GetFormat() const;
unsigned int GetHeight(nzUInt8 level = 0) const;
nzUInt8 GetLevelCount() const;
nzUInt8 GetMaxLevel() const;
NzColor GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const;
nzUInt8* GetPixels(nzUInt8 level = 0, unsigned int x = 0, unsigned int y = 0, unsigned int z = 0);
nzUInt8* GetPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0);
unsigned int GetSize() const;
unsigned int GetSize(nzUInt8 level) const;
nzImageType GetType() const;
@ -97,7 +97,7 @@ class NAZARA_API NzImage : public NzResource
bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0);
NzImage& operator=(const NzImage& image);
NzImage& operator=(NzImage&& image);
NzImage& operator=(NzImage&& image) noexcept;
static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);

View File

@ -8,8 +8,8 @@
#define NAZARA_INDEXBUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Resource.hpp>
class NAZARA_API NzIndexBuffer : public NzResource
{

View File

@ -9,21 +9,22 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <list>
#include <map>
class NzSubMesh;
class NzVertexDeclaration;
struct NzMeshParams
{
NzAnimationParams animation;
//const NzVertexDeclaration* declaration = nullptr;
bool forceSoftware = false;
nzBufferStorage storage = nzBufferStorage_Hardware;
bool loadAnimations = true;
bool IsValid() const;
@ -52,6 +53,7 @@ class NAZARA_API NzMesh : public NzResource
bool Create(nzAnimationType type);
void Destroy();
const NzAxisAlignedBox& GetAABB() const;
const NzAnimation* GetAnimation() const;
nzAnimationType GetAnimationType() const;
unsigned int GetFrameCount() const;
@ -69,6 +71,8 @@ class NAZARA_API NzMesh : public NzResource
bool HasSubMesh(const NzString& identifier) const;
bool HasSubMesh(nzUInt8 index = 0) const;
void InvalidateAABB() const;
bool IsAnimable() const;
bool IsValid() const;

View File

@ -25,7 +25,7 @@ class NAZARA_API NzMouse
XButton1,
XButton2,
Count
Max = XButton2
};
static NzVector2i GetPosition();

View File

@ -361,7 +361,7 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format)
return "RGBA8";
case nzPixelFormat_Undefined:
break;
return "Undefined";
}
NazaraError("Invalid pixel format");

View File

@ -14,12 +14,15 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh
{
public:
NzStaticMesh(const NzMesh* parent);
NzStaticMesh(const NzMesh* parent, const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr);
NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr);
virtual ~NzStaticMesh();
bool Create(const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr);
bool Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr);
void Destroy();
bool GenerateAABB();
const NzAxisAlignedBox& GetAABB() const;
nzAnimationType GetAnimationType() const;
unsigned int GetFrameCount() const;
const NzIndexBuffer* GetIndexBuffer() const;
@ -30,14 +33,16 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh
bool IsAnimated() const;
bool IsValid() const;
void SetAABB(const NzAxisAlignedBox& aabb);
void SetPrimitiveType(nzPrimitiveType primitiveType);
private:
void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation);
nzPrimitiveType m_primitiveType = nzPrimitiveType_TriangleList;
const NzIndexBuffer* m_indexBuffer = nullptr;
const NzVertexBuffer* m_vertexBuffer = nullptr;
NzAxisAlignedBox m_aabb;
NzIndexBuffer* m_indexBuffer = nullptr;
NzVertexBuffer* m_vertexBuffer = nullptr;
const NzVertexDeclaration* m_vertexDeclaration = nullptr;
};

View File

@ -8,9 +8,10 @@
#define NAZARA_SUBMESH_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
@ -26,6 +27,7 @@ class NAZARA_API NzSubMesh : public NzResource
void Animate(unsigned int frameA, unsigned int frameB, float interpolation);
virtual const NzAxisAlignedBox& GetAABB() const = 0;
virtual const NzIndexBuffer* GetIndexBuffer() const = 0;
const NzMesh* GetParent() const;
virtual nzPrimitiveType GetPrimitiveType() const = 0;

View File

@ -8,20 +8,22 @@
#define NAZARA_UTILITY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
class NAZARA_API NzUtility
{
public:
NzUtility();
~NzUtility();
NzUtility() = delete;
~NzUtility() = delete;
bool Initialize();
void Uninitialize();
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static bool s_initialized;
static unsigned int s_moduleReferenceCouter;
};
#endif // NAZARA_UTILITY_HPP

View File

@ -8,8 +8,8 @@
#define NAZARA_VERTEXBUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Resource.hpp>
class NAZARA_API NzVertexBuffer : public NzResource
{

View File

@ -6,8 +6,8 @@
#define NAZARA_VERTEXDECLARATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
struct NzVertexElement
{
@ -26,7 +26,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource
NzVertexDeclaration() = default;
NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount);
NzVertexDeclaration(const NzVertexDeclaration& declaration);
NzVertexDeclaration(NzVertexDeclaration&& declaration);
NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept;
~NzVertexDeclaration();
bool Create(const NzVertexElement* elements, unsigned int elementCount);
@ -44,7 +44,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource
bool IsValid() const;
NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration);
NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration);
NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration) noexcept;
private:
NzVertexDeclarationImpl* m_sharedImpl = nullptr;

View File

@ -28,11 +28,13 @@
class NzCursor;
class NzImage;
class NzIcon;
class NzMouse;
class NzUtility;
class NzWindowImpl;
class NAZARA_API NzWindow : NzNonCopyable
{
friend class NzMouse;
friend class NzUtility;
friend class NzWindowImpl;
@ -42,11 +44,11 @@ class NAZARA_API NzWindow : NzNonCopyable
NzWindow(NzWindowHandle handle);
virtual ~NzWindow();
void Close();
bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default);
bool Create(NzWindowHandle handle);
void Destroy();
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
@ -78,20 +80,20 @@ class NAZARA_API NzWindow : NzNonCopyable
void SetPosition(int x, int y);
void SetSize(const NzVector2i& size);
void SetSize(unsigned int width, unsigned int height);
void SetStayOnTop(bool stayOnTop);
void SetTitle(const NzString& title);
void SetVisible(bool visible);
void StayOnTop(bool stayOnTop);
bool WaitEvent(NzEvent* event);
protected:
virtual void OnClose();
virtual bool OnCreate();
virtual void OnWindowDestroying();
virtual bool OnWindowCreated();
NzWindowImpl* m_impl;
private:
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
void PushEvent(const NzEvent& event);
static bool Initialize();
@ -99,9 +101,9 @@ class NAZARA_API NzWindow : NzNonCopyable
std::queue<NzEvent> m_events;
#if NAZARA_UTILITY_THREADED_WINDOW
NzConditionVariable m_eventCondition;
NzMutex m_eventMutex;
NzMutex m_eventConditionMutex;
NzThreadCondition m_eventCondition;
bool m_eventListener;
bool m_waitForEvent;
#endif

View File

@ -1,29 +0,0 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Audio/Config.hpp>
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#include <new>
void* operator new(std::size_t size)
{
return NzMemoryManager::Allocate(size, false);
}
void* operator new[](std::size_t size)
{
return NzMemoryManager::Allocate(size, true);
}
void operator delete(void* pointer) noexcept
{
NzMemoryManager::Free(pointer, false);
}
void operator delete[](void* pointer) noexcept
{
NzMemoryManager::Free(pointer, true);
}
#endif

View File

@ -15,6 +15,24 @@
#include <Nazara/Core/Debug.hpp>
namespace
{
nzUInt64 NzGetMicrosecondsLowPrecision()
{
return NzClockImplGetMilliseconds()*1000ULL;
}
nzUInt64 NzGetMicrosecondsFirstRun()
{
if (NzClockImplInitializeHighPrecision())
NzGetMicroseconds = NzClockImplGetMicroseconds;
else
NzGetMicroseconds = NzGetMicrosecondsLowPrecision;
return NzGetMicroseconds();
}
}
NzClock::NzClock() :
m_elapsedTime(0),
m_refTime(NzGetMicroseconds()),
@ -81,20 +99,5 @@ void NzClock::Unpause()
NazaraWarning("Clock is not paused, ignoring...");
}
nzUInt64 NzGetMicrosecondsLowPrecision()
{
return NzClockImplGetMilliseconds()*1000ULL;
}
nzUInt64 NzGetMicrosecondsFirstRun()
{
if (NzClockImplInitializeHighPrecision())
NzGetMicroseconds = NzClockImplGetMicroseconds;
else
NzGetMicroseconds = NzGetMicrosecondsLowPrecision;
return NzGetMicroseconds();
}
NzClockFunction NzGetMicroseconds = NzGetMicrosecondsFirstRun;
NzClockFunction NzGetMilliseconds = NzClockImplGetMilliseconds;

View File

@ -2,45 +2,45 @@
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/ThreadCondition.hpp>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Mutex.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/Win32/ThreadConditionImpl.hpp>
#include <Nazara/Core/Win32/ConditionVariableImpl.hpp>
#elif defined(NAZARA_PLATFORM_POSIX)
#include <Nazara/Core/Posix/ThreadConditionImpl.hpp>
#include <Nazara/Core/Posix/ConditionVariableImpl.hpp>
#else
#error Thread condition has no implementation
#endif
#include <Nazara/Core/Debug.hpp>
NzThreadCondition::NzThreadCondition()
NzConditionVariable::NzConditionVariable()
{
m_impl = new NzThreadConditionImpl;
m_impl = new NzConditionVariableImpl;
}
NzThreadCondition::~NzThreadCondition()
NzConditionVariable::~NzConditionVariable()
{
delete m_impl;
}
void NzThreadCondition::Signal()
void NzConditionVariable::Signal()
{
m_impl->Signal();
}
void NzThreadCondition::SignalAll()
void NzConditionVariable::SignalAll()
{
m_impl->SignalAll();
}
void NzThreadCondition::Wait(NzMutex* mutex)
void NzConditionVariable::Wait(NzMutex* mutex)
{
m_impl->Wait(mutex->m_impl);
}
bool NzThreadCondition::Wait(NzMutex* mutex, nzUInt32 timeout)
bool NzConditionVariable::Wait(NzMutex* mutex, nzUInt32 timeout)
{
return m_impl->Wait(mutex->m_impl, timeout);
}

39
src/Nazara/Core/Core.cpp Normal file
View File

@ -0,0 +1,39 @@
// Copyright (C) 2012 AUTHORS
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/Debug.hpp>
bool NzCore::Initialize()
{
if (s_moduleReferenceCouter++ != 0)
return true; // Déjà initialisé
// Initialisation du module
// Le noyau de Nazara n'a pour l'instant aucun besoin d'initialisation, mais dans le futur il est très probable que ce soit le cas.
// Donc en prévision, tous les modules initialisent le noyau
NazaraNotice("Initialized: Core");
return true;
}
bool NzCore::IsInitialized()
{
return s_moduleReferenceCouter != 0;
}
void NzCore::Uninitialize()
{
if (--s_moduleReferenceCouter != 0)
return; // Encore utilisé
// Libération du module
NazaraNotice("Uninitialized: Core");
}
unsigned int NzCore::s_moduleReferenceCouter = 0;

View File

@ -119,19 +119,16 @@ void NzMemoryManager::Free(void* pointer, bool multi)
if (nextFreeFile)
{
if (multi)
std::fprintf(log, "%s Warning: delete[] on new at %s:%d\n", time, nextFreeFile, nextFreeLine);
std::fprintf(log, "%s Warning: delete[] after new at %s:%d\n", time, nextFreeFile, nextFreeLine);
else
std::fprintf(log, "%s Warning: delete on new[] at %s:%d\n", time, nextFreeFile, nextFreeLine);
nextFreeFile = nullptr;
nextFreeLine = 0;
std::fprintf(log, "%s Warning: delete after new[] at %s:%d\n", time, nextFreeFile, nextFreeLine);
}
else
{
if (multi)
std::fprintf(log, "%s Warning: delete[] on new at unknown position\n", time);
std::fprintf(log, "%s Warning: delete[] after new at unknown position\n", time);
else
std::fprintf(log, "%s Warning: delete on new[] at unknown position\n", time);
std::fprintf(log, "%s Warning: delete after new[] at unknown position\n", time);
}
std::fclose(log);
@ -145,6 +142,9 @@ void NzMemoryManager::Free(void* pointer, bool multi)
std::free(ptr);
nextFreeFile = nullptr;
nextFreeLine = 0;
#if defined(NAZARA_PLATFORM_WINDOWS)
LeaveCriticalSection(&mutex);
#elif defined(NAZARA_PLATFORM_POSIX)

View File

@ -25,14 +25,14 @@ namespace
}
NzDirectory::NzDirectory() :
m_impl(nullptr)
m_pattern('*')
{
}
NzDirectory::NzDirectory(const NzString& dirPath) :
m_impl(nullptr)
m_dirPath(dirPath),
m_pattern('*')
{
SetDirectory(dirPath);
}
NzDirectory::~NzDirectory()
@ -42,18 +42,27 @@ NzDirectory::~NzDirectory()
void NzDirectory::Close()
{
NazaraLock(m_mutex);
if (m_impl)
{
m_impl->Close();
delete m_impl;
m_impl = nullptr;
NazaraMutexUnlock(m_mutex);
}
}
NzString NzDirectory::GetPattern() const
{
NazaraLock(m_mutex);
return m_pattern;
}
NzString NzDirectory::GetResultName() const
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@ -67,6 +76,8 @@ NzString NzDirectory::GetResultName() const
NzString NzDirectory::GetResultPath() const
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@ -80,6 +91,8 @@ NzString NzDirectory::GetResultPath() const
nzUInt64 NzDirectory::GetResultSize() const
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@ -91,8 +104,17 @@ nzUInt64 NzDirectory::GetResultSize() const
return m_impl->GetResultSize();
}
bool NzDirectory::IsOpen() const
{
NazaraLock(m_mutex);
return m_impl != nullptr;
}
bool NzDirectory::IsResultDirectory() const
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@ -106,6 +128,8 @@ bool NzDirectory::IsResultDirectory() const
bool NzDirectory::NextResult(bool skipDots)
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@ -114,41 +138,40 @@ bool NzDirectory::NextResult(bool skipDots)
}
#endif
if (skipDots)
NzString name;
do
{
NzString name;
do
{
if (!m_impl->NextResult())
return false;
if (!m_impl->NextResult())
return false;
name = m_impl->GetResultName();
}
while (name == '.' || name == "..");
name = m_impl->GetResultName();
return true;
if (skipDots && (name == '.' || name == ".."))
continue;
if (name.Match(m_pattern))
break;
}
else
return m_impl->NextResult();
while (true);
return true;
}
bool NzDirectory::Open()
{
NazaraLock(m_mutex);
Close();
if (!Exists(m_dirPath))
return false;
NazaraMutexLock(m_mutex);
m_impl = new NzDirectoryImpl(this);
if (!m_impl->Open(m_dirPath))
{
delete m_impl;
m_impl = nullptr;
NazaraMutexUnlock(m_mutex);
return false;
}
@ -157,11 +180,20 @@ bool NzDirectory::Open()
void NzDirectory::SetDirectory(const NzString& dirPath)
{
NazaraLock(m_mutex);
Close();
m_dirPath = NzFile::AbsolutePath(dirPath);
}
void NzDirectory::SetPattern(const NzString& pattern)
{
NazaraLock(m_mutex);
m_pattern = pattern;
}
bool NzDirectory::Copy(const NzString& sourcePath, const NzString& destPath)
{
if (sourcePath.IsEmpty() || destPath.IsEmpty())
@ -187,12 +219,12 @@ bool NzDirectory::Copy(const NzString& sourcePath, const NzString& destPath)
{
if (dir.IsResultDirectory())
{
if (!Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName()))
if (!Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName()))
return false;
}
else if (!NzFile::Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName()))
{
NazaraError("Unable to copy \"" + dir.GetResultPath() + "\" to \"" + dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName() + '"');
NazaraError("Failed to copy \"" + dir.GetResultPath() + "\" to \"" + dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName() + '"');
return false;
}
}

View File

@ -42,7 +42,7 @@ NzString NzGetLastSystemError(unsigned int code)
wchar_t* buffer = nullptr;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
0,
nullptr,
code,
0,
reinterpret_cast<LPWSTR>(&buffer),

View File

@ -45,7 +45,7 @@ m_openMode(0)
Open(openMode);
}
NzFile::NzFile(NzFile&& file) :
NzFile::NzFile(NzFile&& file) noexcept :
m_endianness(file.m_endianness),
m_filePath(std::move(file.m_filePath)),
m_impl(file.m_impl),
@ -525,7 +525,7 @@ NzFile& NzFile::operator=(const NzString& filePath)
return *this;
}
NzFile& NzFile::operator=(NzFile&& file)
NzFile& NzFile::operator=(NzFile&& file) noexcept
{
NazaraLock(m_mutex)
@ -570,7 +570,7 @@ NzString NzFile::AbsolutePath(const NzString& filePath)
NazaraError("Path unrecognized");
return path;
}
#elif NAZARA_PLATEFORM_LINUX
#elif defined(NAZARA_PLATEFORM_LINUX)
base = '/';
start = 0;
#else
@ -718,7 +718,7 @@ bool NzFile::IsAbsolute(const NzString& path)
return true;
else
return false;
#elif NAZARA_PLATEFORM_LINUX
#elif defined(NAZARA_PLATEFORM_LINUX)
return wpath.StartsWith('/');
#else
#error OS case not implemented
@ -752,7 +752,7 @@ NzString NzFile::NormalizeSeparators(const NzString& filePath)
#elif defined(NAZARA_PLATFORM_LINUX)
path.Replace('\\', '/');
#else
#error OS not handled
#error OS case not implemented
#endif
return path;
@ -793,4 +793,4 @@ bool NzFile::FillHash(NzHashImpl* hash) const
}
return true;
} // Fermeture auttomatique du fichier
} // Fermeture automatique du fichier

View File

@ -136,7 +136,7 @@ namespace
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
if (!((data - reinterpret_cast<const nzUInt8*>(0)) & 3))
if (!(data - static_cast<const nzUInt8*>(nullptr)) & 3)
{
/* data are properly aligned */
X = reinterpret_cast<const nzUInt32*>(data);

View File

@ -315,119 +315,122 @@ void SHA1_Init(SHA_CTX* context)
(b) = ROTL32(30, b); \
j++;
void SHA1_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
namespace
{
nzUInt32 a, b, c, d, e;
nzUInt32 T1, *W1;
int j;
void SHA1_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
{
nzUInt32 a, b, c, d, e;
nzUInt32 T1, *W1;
int j;
W1 = reinterpret_cast<nzUInt32*>(context->s1.buffer);
W1 = reinterpret_cast<nzUInt32*>(context->s1.buffer);
/* Initialize registers with the prev. intermediate value */
a = context->s1.state[0];
b = context->s1.state[1];
c = context->s1.state[2];
d = context->s1.state[3];
e = context->s1.state[4];
/* Initialize registers with the prev. intermediate value */
a = context->s1.state[0];
b = context->s1.state[1];
c = context->s1.state[2];
d = context->s1.state[3];
e = context->s1.state[4];
j = 0;
j = 0;
/* Rounds 0 to 15 unrolled: */
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
/* Rounds 0 to 15 unrolled: */
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
/* Rounds 16 to 19 unrolled: */
ROUND1_16_TO_19(e,a,b,c,d);
ROUND1_16_TO_19(d,e,a,b,c);
ROUND1_16_TO_19(c,d,e,a,b);
ROUND1_16_TO_19(b,c,d,e,a);
/* Rounds 16 to 19 unrolled: */
ROUND1_16_TO_19(e,a,b,c,d);
ROUND1_16_TO_19(d,e,a,b,c);
ROUND1_16_TO_19(c,d,e,a,b);
ROUND1_16_TO_19(b,c,d,e,a);
/* Rounds 20 to 39 unrolled: */
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
/* Rounds 20 to 39 unrolled: */
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
/* Rounds 40 to 59 unrolled: */
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
/* Rounds 40 to 59 unrolled: */
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
/* Rounds 60 to 79 unrolled: */
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
/* Rounds 60 to 79 unrolled: */
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
/* Compute the current intermediate hash value */
context->s1.state[0] += a;
context->s1.state[1] += b;
context->s1.state[2] += c;
context->s1.state[3] += d;
context->s1.state[4] += e;
/* Compute the current intermediate hash value */
context->s1.state[0] += a;
context->s1.state[1] += b;
context->s1.state[2] += c;
context->s1.state[3] += d;
context->s1.state[4] += e;
}
}
void SHA1_Update(SHA_CTX* context, const nzUInt8* data, std::size_t len)
@ -766,9 +769,12 @@ void SHA224_Init(SHA_CTX* context)
SHA256_Internal_Init(context, sha224_initial_hash_value);
}
void SHA224_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
namespace
{
SHA256_Internal_Transform(context, data);
void SHA224_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
{
SHA256_Internal_Transform(context, data);
}
}
void SHA224_Update(SHA_CTX* context, const nzUInt8 *data, std::size_t len)

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