Former-commit-id: 5a7ef21c235a4a3c1e4f149478acb2a473e2f09f [formerly 85614fc319abb360d72a3d015d5ebad3400ae659]
Former-commit-id: 1682ec4cb350aabd7cb7ac8dabf598702098905c
This commit is contained in:
Lynix 2016-06-14 12:15:16 +02:00
commit 7989253066
227 changed files with 8563 additions and 1059 deletions

2
.gitignore vendored
View File

@ -5,6 +5,8 @@ examples/bin/*.dll
examples/bin/*.so examples/bin/*.so
tests/*.exe tests/*.exe
tests/*.pdb tests/*.pdb
tests/*.dll
tests/*.so
lib/* lib/*
# Feature page # Feature page

View File

@ -33,6 +33,10 @@ namespace Ndk
bool Run(); bool Run();
#ifndef NDK_SERVER
inline void MakeExitOnLastWindowClosed(bool exitOnClosedWindows);
#endif
inline void Quit(); inline void Quit();
Application& operator=(const Application&) = delete; Application& operator=(const Application&) = delete;

View File

@ -61,6 +61,13 @@ namespace Ndk
return m_updateTime; return m_updateTime;
} }
#ifndef NDK_SERVER
inline void Application::MakeExitOnLastWindowClosed(bool exitOnClosedWindows)
{
m_exitOnClosedWindows = exitOnClosedWindows;
}
#endif
inline void Application::Quit() inline void Application::Quit()
{ {
m_shouldQuit = true; m_shouldQuit = true;

View File

@ -26,7 +26,7 @@ namespace Ndk
inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc) inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc)
{ {
// Nous allons rajouter notre composant à la fin // Nous allons rajouter notre composant à la fin
ComponentIndex index = s_entries.size(); ComponentIndex index = static_cast<ComponentIndex>(s_entries.size());
s_entries.resize(index + 1); s_entries.resize(index + 1);
// On récupère et on affecte // On récupère et on affecte

View File

@ -40,7 +40,7 @@ namespace Ndk
private: private:
inline void InvalidateBoundingVolume(); inline void InvalidateBoundingVolume();
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index); void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index);
inline void InvalidateRenderables(); inline void InvalidateRenderables();
inline void InvalidateTransformMatrix(); inline void InvalidateTransformMatrix();

View File

@ -100,8 +100,8 @@ namespace Nz
params->animated = instance.CheckField<bool>("Animated", params->animated); params->animated = instance.CheckField<bool>("Animated", params->animated);
params->center = instance.CheckField<bool>("Center", params->center); params->center = instance.CheckField<bool>("Center", params->center);
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs); params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
//params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers); params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
params->scale = instance.CheckField<Vector3f>("Scale", params->scale);
return 1; return 1;
} }

View File

@ -9,7 +9,7 @@
namespace Ndk namespace Ndk
{ {
void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index) void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index)
{ {
NazaraAssert(index < m_renderables.size(), "Invalid renderable index"); NazaraAssert(index < m_renderables.size(), "Invalid renderable index");
NazaraUnused(renderable); NazaraUnused(renderable);

View File

@ -1,5 +1,14 @@
NazaraBuild = {} -- L'équivalent d'un namespace en Lua est une table NazaraBuild = {} -- L'équivalent d'un namespace en Lua est une table
function NazaraBuild:AddExecutablePath(path)
self.ExecutableDir[path] = true
self.InstallDir[path] = true
end
function NazaraBuild:AddInstallPath(path)
self.InstallDir[path] = true
end
function NazaraBuild:Execute() function NazaraBuild:Execute()
if (_ACTION == nil) then -- Si aucune action n'est spécifiée if (_ACTION == nil) then -- Si aucune action n'est spécifiée
return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien
@ -7,9 +16,9 @@ function NazaraBuild:Execute()
local platformData local platformData
if (os.is64bit()) then if (os.is64bit()) then
platformData = {"x64", "x86"} platformData = {"x64", "x32"}
else else
platformData = {"x86", "x64"} platformData = {"x32", "x64"}
end end
if (self.Actions[_ACTION] == nil) then if (self.Actions[_ACTION] == nil) then
@ -30,13 +39,13 @@ function NazaraBuild:Execute()
location(_ACTION) location(_ACTION)
kind("StaticLib") kind("StaticLib")
configuration("x86") configuration("x32")
libdirs("../extlibs/lib/common/x86") libdirs("../extlibs/lib/common/x86")
configuration("x64") configuration("x64")
libdirs("../extlibs/lib/common/x64") libdirs("../extlibs/lib/common/x64")
configuration({"codeblocks or codelite or gmake", "x86"}) configuration({"codeblocks or codelite or gmake", "x32"})
libdirs("../extlibs/lib/" .. makeLibDir .. "/x86") libdirs("../extlibs/lib/" .. makeLibDir .. "/x86")
targetdir("../extlibs/lib/" .. makeLibDir .. "/x86") targetdir("../extlibs/lib/" .. makeLibDir .. "/x86")
@ -45,9 +54,9 @@ function NazaraBuild:Execute()
targetdir("../extlibs/lib/" .. makeLibDir .. "/x64") targetdir("../extlibs/lib/" .. makeLibDir .. "/x64")
configuration("vs*") configuration("vs*")
buildoptions("/MP") buildoptions({"/MP", "/bigobj"}) -- Multiprocessus build and big .obj
configuration({"vs*", "x86"}) configuration({"vs*", "x32"})
libdirs("../extlibs/lib/msvc/x86") libdirs("../extlibs/lib/msvc/x86")
targetdir("../extlibs/lib/msvc/x86") targetdir("../extlibs/lib/msvc/x86")
@ -55,7 +64,7 @@ function NazaraBuild:Execute()
libdirs("../extlibs/lib/msvc/x64") libdirs("../extlibs/lib/msvc/x64")
targetdir("../extlibs/lib/msvc/x64") targetdir("../extlibs/lib/msvc/x64")
configuration({"xcode3 or xcode4", "x86"}) configuration({"xcode3 or xcode4", "x32"})
libdirs("../extlibs/lib/xcode/x86") libdirs("../extlibs/lib/xcode/x86")
targetdir("../extlibs/lib/xcode/x86") targetdir("../extlibs/lib/xcode/x86")
@ -82,8 +91,11 @@ function NazaraBuild:Execute()
configuration("ReleaseStatic") configuration("ReleaseStatic")
targetsuffix("-s") targetsuffix("-s")
configuration({"not windows", "codeblocks or codelite or gmake or xcode3 or xcode4"})
buildoptions("-fPIC")
configuration("codeblocks or codelite or gmake or xcode3 or xcode4") configuration("codeblocks or codelite or gmake or xcode3 or xcode4")
buildoptions({"-fPIC", "-std=c++14"}) buildoptions({"-std=c++14", "-U__STRICT_ANSI__"})
for k, libTable in ipairs(self.OrderedExtLibs) do for k, libTable in ipairs(self.OrderedExtLibs) do
project(libTable.Name) project(libTable.Name)
@ -145,11 +157,8 @@ function NazaraBuild:Execute()
configuration({"linux or bsd or macosx", "gmake"}) configuration({"linux or bsd or macosx", "gmake"})
buildoptions("-fvisibility=hidden") buildoptions("-fvisibility=hidden")
configuration({"linux or bsd or macosx", "gmake"})
buildoptions("-fvisibility=hidden")
configuration("vs*") configuration("vs*")
buildoptions("/MP") -- Multiprocessus build buildoptions({"/MP", "/bigobj"}) -- Multiprocessus build and big .obj
flags("NoMinimalRebuild") flags("NoMinimalRebuild")
defines("_CRT_SECURE_NO_WARNINGS") defines("_CRT_SECURE_NO_WARNINGS")
defines("_SCL_SECURE_NO_WARNINGS") defines("_SCL_SECURE_NO_WARNINGS")
@ -178,14 +187,14 @@ function NazaraBuild:Execute()
libdirs("../lib") libdirs("../lib")
libdirs("../extlibs/lib/common") libdirs("../extlibs/lib/common")
configuration("x86") configuration("x32")
libdirs("../extlibs/lib/common/x86") libdirs("../extlibs/lib/common/x86")
configuration("x64") configuration("x64")
defines("NAZARA_PLATFORM_x64") defines("NAZARA_PLATFORM_x64")
libdirs("../extlibs/lib/common/x64") libdirs("../extlibs/lib/common/x64")
configuration({"codeblocks or codelite or gmake", "x86"}) configuration({"codeblocks or codelite or gmake", "x32"})
libdirs("../extlibs/lib/" .. makeLibDir .. "/x86") libdirs("../extlibs/lib/" .. makeLibDir .. "/x86")
libdirs("../lib/" .. makeLibDir .. "/x86") libdirs("../lib/" .. makeLibDir .. "/x86")
targetdir("../lib/" .. makeLibDir .. "/x86") targetdir("../lib/" .. makeLibDir .. "/x86")
@ -196,9 +205,9 @@ function NazaraBuild:Execute()
targetdir("../lib/" .. makeLibDir .. "/x64") targetdir("../lib/" .. makeLibDir .. "/x64")
-- Copy the module binaries to the example folder -- Copy the module binaries to the example folder
self:MakeCopyAfterBuild(moduleTable) self:MakeInstallCommands(moduleTable)
configuration({"vs*", "x86"}) configuration({"vs*", "x32"})
libdirs("../extlibs/lib/msvc/x86") libdirs("../extlibs/lib/msvc/x86")
libdirs("../lib/msvc/x86") libdirs("../lib/msvc/x86")
targetdir("../lib/msvc/x86") targetdir("../lib/msvc/x86")
@ -208,7 +217,7 @@ function NazaraBuild:Execute()
libdirs("../lib/msvc/x64") libdirs("../lib/msvc/x64")
targetdir("../lib/msvc/x64") targetdir("../lib/msvc/x64")
configuration({"xcode3 or xcode4", "x86"}) configuration({"xcode3 or xcode4", "x32"})
libdirs("../extlibs/lib/xcode/x86") libdirs("../extlibs/lib/xcode/x86")
libdirs("../lib/xcode/x86") libdirs("../lib/xcode/x86")
targetdir("../lib/xcode/x86") targetdir("../lib/xcode/x86")
@ -261,16 +270,20 @@ function NazaraBuild:Execute()
project(prefix .. toolTable.Name) project(prefix .. toolTable.Name)
location(_ACTION .. "/tools") location(_ACTION .. "/tools")
targetdir(toolTable.Directory) targetdir(toolTable.TargetDirectory)
if (toolTable.Kind == "plugin" or toolTable.Kind == "library") then if (toolTable.Kind == "plugin" or toolTable.Kind == "library") then
kind("SharedLib") kind("SharedLib")
elseif (toolTable.Kind == "consoleapp") then
debugdir(toolTable.Directory) -- Copy the tool binaries to the example folder
self:MakeInstallCommands(toolTable)
elseif (toolTable.Kind == "application") then
debugdir(toolTable.TargetDirectory)
if (toolTable.EnableConsole) then
kind("ConsoleApp") kind("ConsoleApp")
elseif (toolTable.Kind == "windowapp") then else
debugdir(toolTable.Directory)
kind("WindowedApp") kind("WindowedApp")
end
else else
assert(false, "Invalid tool Kind") assert(false, "Invalid tool Kind")
end end
@ -283,14 +296,14 @@ function NazaraBuild:Execute()
libdirs("../lib") libdirs("../lib")
libdirs("../extlibs/lib/common") libdirs("../extlibs/lib/common")
configuration("x86") configuration("x32")
libdirs("../extlibs/lib/common/x86") libdirs("../extlibs/lib/common/x86")
configuration("x64") configuration("x64")
defines("NAZARA_PLATFORM_x64") defines("NAZARA_PLATFORM_x64")
libdirs("../extlibs/lib/common/x64") libdirs("../extlibs/lib/common/x64")
configuration({"codeblocks or codelite or gmake", "x86"}) configuration({"codeblocks or codelite or gmake", "x32"})
libdirs("../extlibs/lib/" .. makeLibDir .. "/x86") libdirs("../extlibs/lib/" .. makeLibDir .. "/x86")
libdirs("../lib/" .. makeLibDir .. "/x86") libdirs("../lib/" .. makeLibDir .. "/x86")
if (toolTable.Kind == "library") then if (toolTable.Kind == "library") then
@ -308,12 +321,7 @@ function NazaraBuild:Execute()
targetdir("../plugins/" .. toolTable.Name .. "/lib/" .. makeLibDir .. "/x64") targetdir("../plugins/" .. toolTable.Name .. "/lib/" .. makeLibDir .. "/x64")
end end
-- Copy the tool binaries to the example folder configuration({"vs*", "x32"})
if (toolTable.CopyTargetToExampleDir) then
self:MakeCopyAfterBuild(toolTable)
end
configuration({"vs*", "x86"})
libdirs("../extlibs/lib/msvc/x86") libdirs("../extlibs/lib/msvc/x86")
libdirs("../lib/msvc/x86") libdirs("../lib/msvc/x86")
if (toolTable.Kind == "library") then if (toolTable.Kind == "library") then
@ -331,7 +339,7 @@ function NazaraBuild:Execute()
targetdir("../plugins/" .. toolTable.Name .. "/lib/msvc/x64") targetdir("../plugins/" .. toolTable.Name .. "/lib/msvc/x64")
end end
configuration({"xcode3 or xcode4", "x86"}) configuration({"xcode3 or xcode4", "x32"})
libdirs("../extlibs/lib/xcode/x86") libdirs("../extlibs/lib/xcode/x86")
libdirs("../lib/xcode/x86") libdirs("../lib/xcode/x86")
if (toolTable.Kind == "library") then if (toolTable.Kind == "library") then
@ -385,23 +393,34 @@ function NazaraBuild:Execute()
end end
for k, exampleTable in ipairs(self.OrderedExamples) do for k, exampleTable in ipairs(self.OrderedExamples) do
local destPath = "../examples/bin"
project("Demo" .. exampleTable.Name) project("Demo" .. exampleTable.Name)
location(_ACTION .. "/examples") location(_ACTION .. "/examples")
if (exampleTable.Console) then if (exampleTable.Kind == "plugin" or exampleTable.Kind == "library") then
kind("SharedLib")
self:MakeInstallCommands(toolTable)
elseif (exampleTable.Kind == "application") then
debugdir(exampleTable.TargetDirectory)
if (exampleTable.EnableConsole) then
kind("ConsoleApp") kind("ConsoleApp")
else else
kind("Window") kind("WindowedApp")
end
else
assert(false, "Invalid tool Kind")
end end
debugdir("../examples/bin") debugdir(destPath)
includedirs({ includedirs({
"../include", "../include",
"../extlibs/include" "../extlibs/include"
}) })
libdirs("../lib") libdirs("../lib")
targetdir("../examples/bin") targetdir(destPath)
files(exampleTable.Files) files(exampleTable.Files)
excludes(exampleTable.FilesExcluded) excludes(exampleTable.FilesExcluded)
@ -411,26 +430,26 @@ function NazaraBuild:Execute()
includedirs(exampleTable.Includes) includedirs(exampleTable.Includes)
links(exampleTable.Libraries) links(exampleTable.Libraries)
configuration("x86") configuration("x32")
libdirs("../extlibs/lib/common/x86") libdirs("../extlibs/lib/common/x86")
configuration("x64") configuration("x64")
defines("NAZARA_PLATFORM_x64") defines("NAZARA_PLATFORM_x64")
libdirs("../extlibs/lib/common/x64") libdirs("../extlibs/lib/common/x64")
configuration({"codeblocks or codelite or gmake", "x86"}) configuration({"codeblocks or codelite or gmake", "x32"})
libdirs("../lib/" .. makeLibDir .. "/x86") libdirs("../lib/" .. makeLibDir .. "/x86")
configuration({"codeblocks or codelite or gmake", "x64"}) configuration({"codeblocks or codelite or gmake", "x64"})
libdirs("../lib/" .. makeLibDir .. "/x64") libdirs("../lib/" .. makeLibDir .. "/x64")
configuration({"vs*", "x86"}) configuration({"vs*", "x32"})
libdirs("../lib/msvc/x86") libdirs("../lib/msvc/x86")
configuration({"vs*", "x64"}) configuration({"vs*", "x64"})
libdirs("../lib/msvc/x64") libdirs("../lib/msvc/x64")
configuration({"xcode3 or xcode4", "x86"}) configuration({"xcode3 or xcode4", "x32"})
libdirs("../lib/xcode/x86") libdirs("../lib/xcode/x86")
configuration({"xcode3 or xcode4", "x64"}) configuration({"xcode3 or xcode4", "x64"})
@ -448,6 +467,11 @@ end
function NazaraBuild:Initialize() function NazaraBuild:Initialize()
-- Commençons par les options -- Commençons par les options
newoption({
trigger = "install-path",
description = "Setup additionnals install directories (library binaries will be copied there)"
})
newoption({ newoption({
trigger = "server", trigger = "server",
description = "Excludes client-only modules/tools/examples" description = "Excludes client-only modules/tools/examples"
@ -470,10 +494,19 @@ function NazaraBuild:Initialize()
self.Actions = {} self.Actions = {}
self.Examples = {} self.Examples = {}
self.ExecutableDir = {}
self.ExtLibs = {} self.ExtLibs = {}
self.InstallDir = {}
self.Modules = {} self.Modules = {}
self.Tools = {} self.Tools = {}
if (_OPTIONS["install-path"]) then
local paths = string.explode(_OPTIONS["install-path"], ";")
for k,v in pairs(paths) do
self:AddInstallPath(v)
end
end
-- Actions -- Actions
modules = os.matchfiles("scripts/actions/*.lua") modules = os.matchfiles("scripts/actions/*.lua")
for k,v in pairs(modules) do for k,v in pairs(modules) do
@ -499,7 +532,7 @@ function NazaraBuild:Initialize()
local f, err = loadfile(v) local f, err = loadfile(v)
if (f) then if (f) then
LIBRARY = {} LIBRARY = {}
self:SetupInfoTable(LIBRARY) self:SetupExtlibTable(LIBRARY)
f() f()
@ -519,18 +552,10 @@ function NazaraBuild:Initialize()
local moduleName = v:match(".*/(.*).lua") local moduleName = v:match(".*/(.*).lua")
local moduleNameLower = moduleName:lower() local moduleNameLower = moduleName:lower()
if (moduleNameLower ~= "core") then -- exclure le noyau n'aurait aucun sens
newoption({
trigger = "exclude-" .. moduleNameLower,
description = "Exclude the " .. moduleName .. " module from the build system"
})
end
if (not _OPTIONS["exclude-" .. moduleNameLower]) then
local f, err = loadfile(v) local f, err = loadfile(v)
if (f) then if (f) then
MODULE = {} MODULE = {}
self:SetupInfoTable(MODULE) self:SetupModuleTable(MODULE)
f() f()
@ -542,7 +567,6 @@ function NazaraBuild:Initialize()
print("Unable to load module file: " .. err) print("Unable to load module file: " .. err)
end end
end end
end
MODULE = nil MODULE = nil
-- Continue with the tools (ex: SDK) -- Continue with the tools (ex: SDK)
@ -551,16 +575,10 @@ function NazaraBuild:Initialize()
local toolName = v:match(".*/(.*).lua") local toolName = v:match(".*/(.*).lua")
local toolNameLower = toolName:lower() local toolNameLower = toolName:lower()
newoption({
trigger = "exclude-" .. toolNameLower,
description = "Exclude the " .. toolName .. " tool from the build system"
})
if (not _OPTIONS["exclude-" .. toolNameLower]) then
local f, err = loadfile(v) local f, err = loadfile(v)
if (f) then if (f) then
TOOL = {} TOOL = {}
self:SetupInfoTable(TOOL) self:SetupToolTable(TOOL)
f() f()
@ -572,7 +590,6 @@ function NazaraBuild:Initialize()
print("Unable to load tool file: " .. err) print("Unable to load tool file: " .. err)
end end
end end
end
TOOL = nil TOOL = nil
-- Examples -- Examples
@ -585,7 +602,7 @@ function NazaraBuild:Initialize()
if (f) then if (f) then
EXAMPLE = {} EXAMPLE = {}
EXAMPLE.Directory = dirName EXAMPLE.Directory = dirName
self:SetupInfoTable(EXAMPLE) self:SetupExampleTable(EXAMPLE)
f() f()
@ -618,7 +635,7 @@ function NazaraBuild:Initialize()
if (self:Process(projectTable)) then if (self:Process(projectTable)) then
table.insert(orderedTables[k], projectTable) table.insert(orderedTables[k], projectTable)
else else
print("Rejected client-only " .. projectTable.Name .. " " .. projectTable.Type) print("Rejected " .. projectTable.Name .. " " .. string.lower(projectTable.Type) .. ": " .. projectTable.ExcludeReason)
end end
end end
@ -752,7 +769,7 @@ function NazaraBuild:RegisterTool(toolTable)
return false, "This tool name is already in use" return false, "This tool name is already in use"
end end
if (toolTable.Directory == nil or type(toolTable.Directory) ~= "string" or string.len(toolTable.Directory) == 0) then if (toolTable.TargetDirectory == nil or type(toolTable.TargetDirectory) ~= "string" or string.len(toolTable.TargetDirectory) == 0) then
return false, "Invalid tool directory" return false, "Invalid tool directory"
end end
@ -761,7 +778,7 @@ function NazaraBuild:RegisterTool(toolTable)
end end
local lowerCaseKind = toolTable.Kind:lower() local lowerCaseKind = toolTable.Kind:lower()
if (lowerCaseKind == "library" or lowerCaseKind == "plugin" or lowerCaseKind == "consoleapp" or lowerCaseKind == "windowapp") then if (lowerCaseKind == "library" or lowerCaseKind == "plugin" or lowerCaseKind == "application") then
toolTable.Kind = lowerCaseKind toolTable.Kind = lowerCaseKind
else else
return false, "Invalid tool type" return false, "Invalid tool type"
@ -780,20 +797,17 @@ local PosixOSes = {
} }
function NazaraBuild:Process(infoTable) function NazaraBuild:Process(infoTable)
if (infoTable.ClientOnly and _OPTIONS["server"]) then
return false
end
local libraries = {} local libraries = {}
for k, library in pairs(infoTable.Libraries) do for k, library in pairs(infoTable.Libraries) do
local moduleName = library:match("Nazara(%w+)") local projectName = library:match("Nazara(%w+)")
local moduleTable = moduleName and self.Modules[moduleName:lower()] local moduleTable = projectName and self.Modules[projectName:lower()]
local toolTable = moduleName and self.Tools[moduleName:lower()] local toolTable = projectName and self.Tools[projectName:lower()]
if (moduleTable) then if (moduleTable) then
if (moduleTable.ClientOnly and _OPTIONS["server"]) then if (moduleTable.Excluded) then
infoTable.ClientOnly = true infoTable.Excluded = true
return false -- We depend on a client-only library infoTable.ExcludeReason = "depends on excluded " .. projectName .. " module"
return false
end end
if (_OPTIONS["united"]) then if (_OPTIONS["united"]) then
@ -811,9 +825,10 @@ function NazaraBuild:Process(infoTable)
else else
local extLibTable = self.ExtLibs[library:lower()] local extLibTable = self.ExtLibs[library:lower()]
if (extLibTable) then if (extLibTable) then
if (extLibTable.ClientOnly and _OPTIONS["server"]) then if (extLibTable.Excluded) then
infoTable.ClientOnly = true infoTable.Excluded = true
return false -- We depend on a client-only library infoTable.ExcludeReason = "depends on excluded " .. extLibTable.Name .. " external library"
return false
end end
library = extLibTable.Name library = extLibTable.Name
@ -824,9 +839,10 @@ function NazaraBuild:Process(infoTable)
table.insert(infoTable.ConfigurationLibraries.ReleaseDynamic, library .. "-s") table.insert(infoTable.ConfigurationLibraries.ReleaseDynamic, library .. "-s")
else else
if (toolTable and toolTable.Kind == "library") then if (toolTable and toolTable.Kind == "library") then
if (toolTable.ClientOnly and _OPTIONS["server"]) then if (toolTable.Excluded) then
infoTable.ClientOnly = true infoTable.Excluded = true
return false -- We depend on a client-only library infoTable.ExcludeReason = "depends on excluded " .. toolTable.Name .. " tool"
return false
end end
library = "Nazara" .. toolTable.Name library = "Nazara" .. toolTable.Name
@ -890,37 +906,71 @@ function NazaraBuild:Process(infoTable)
end end
end end
if (infoTable.Kind == "application") then
self:AddExecutablePath(infoTable.TargetDirectory)
end
return true return true
end end
function NazaraBuild:Resolve(infoTable) function NazaraBuild:Resolve(infoTable)
if (infoTable.ClientOnly and _OPTIONS["server"]) then
infoTable.Excluded = true
infoTable.ExcludeReason = "excluded by command-line options (client-only)"
end
if (infoTable.Excludable) then
local optionName = "excludes-" .. string.lower(infoTable.Type .. "-" .. infoTable.Name)
newoption({
trigger = optionName,
description = "Excludes the " .. infoTable.Name .. " " .. string.lower(infoTable.Type) .. " and projects relying on it"
})
if (_OPTIONS[optionName]) then
infoTable.Excluded = true
infoTable.ExcludeReason = "excluded by command-line options"
end
end
if (type(infoTable.Libraries) == "function") then if (type(infoTable.Libraries) == "function") then
infoTable.Libraries = infoTable.Libraries() infoTable.Libraries = infoTable.Libraries()
end end
end end
function NazaraBuild:MakeCopyAfterBuild(infoTable) function NazaraBuild:MakeInstallCommands(infoTable)
if (PremakeVersion < 50) then
return
end
if (os.is("windows")) then if (os.is("windows")) then
configuration({}) configuration({})
postbuildcommands({[[xcopy "%{path.translate(cfg.linktarget.relpath):sub(1, -5) .. ".dll"}" "..\..\..\examples\bin\" /E /Y]]})
for k,v in pairs(self.InstallDir) do
local destPath = path.translate(path.isabsolute(k) and k or "../../" .. k)
postbuildcommands({[[xcopy "%{path.translate(cfg.linktarget.relpath):sub(1, -5) .. ".dll"}" "]] .. destPath .. [[\" /E /Y]]})
end
for k,v in pairs(table.join(infoTable.Libraries, infoTable.DynLib)) do for k,v in pairs(table.join(infoTable.Libraries, infoTable.DynLib)) do
local paths = {} local paths = {}
table.insert(paths, {"x86", "../extlibs/lib/common/x86/" .. v .. ".dll"}) table.insert(paths, {"x32", "../extlibs/lib/common/x86/" .. v .. ".dll"})
table.insert(paths, {"x86", "../extlibs/lib/common/x86/lib" .. v .. ".dll"}) table.insert(paths, {"x32", "../extlibs/lib/common/x86/lib" .. v .. ".dll"})
table.insert(paths, {"x64", "../extlibs/lib/common/x64/" .. v .. ".dll"}) table.insert(paths, {"x64", "../extlibs/lib/common/x64/" .. v .. ".dll"})
table.insert(paths, {"x64", "../extlibs/lib/common/x64/lib" .. v .. ".dll"}) table.insert(paths, {"x64", "../extlibs/lib/common/x64/lib" .. v .. ".dll"})
for k,v in pairs(paths) do for k,v in pairs(paths) do
local config = v[1] local config = v[1]
local path = v[2] local srcPath = v[2]
if (os.isfile(path)) then if (os.isfile(srcPath)) then
if (infoTable.Kind == "plugin") then if (infoTable.Kind == "plugin") then
path = "../../" .. path srcPath = "../../" .. srcPath
end end
configuration(config) configuration(config)
postbuildcommands({[[xcopy "%{path.translate(cfg.linktarget.relpath:sub(1, -#cfg.linktarget.name - 1) .. "../../]] .. path .. [[")}" "..\..\..\examples\bin\" /E /Y]]})
for k,v in pairs(self.ExecutableDir) do
local destPath = path.translate(path.isabsolute(k) and k or "../../" .. k)
postbuildcommands({[[xcopy "%{path.translate(cfg.linktarget.relpath:sub(1, -#cfg.linktarget.name - 1) .. "../../]] .. srcPath .. [[")}" "]] .. destPath .. [[\" /E /Y]]})
end
end end
end end
end end
@ -928,6 +978,7 @@ function NazaraBuild:MakeCopyAfterBuild(infoTable)
end end
function NazaraBuild:SetupInfoTable(infoTable) function NazaraBuild:SetupInfoTable(infoTable)
infoTable.Excludable = true
infoTable.ConfigurationLibraries = {} infoTable.ConfigurationLibraries = {}
infoTable.ConfigurationLibraries.DebugStatic = {} infoTable.ConfigurationLibraries.DebugStatic = {}
infoTable.ConfigurationLibraries.ReleaseStatic = {} infoTable.ConfigurationLibraries.ReleaseStatic = {}
@ -940,3 +991,24 @@ function NazaraBuild:SetupInfoTable(infoTable)
infoTable["Os" .. v] = {} infoTable["Os" .. v] = {}
end end
end end
function NazaraBuild:SetupExampleTable(infoTable)
self:SetupInfoTable(infoTable)
infoTable.Kind = "application"
infoTable.TargetDirectory = "../examples/bin"
end
function NazaraBuild:SetupExtlibTable(infoTable)
self:SetupInfoTable(infoTable)
infoTable.Kind = "library"
end
function NazaraBuild:SetupModuleTable(infoTable)
self:SetupInfoTable(infoTable)
infoTable.Kind = "library"
end
NazaraBuild.SetupToolTable = NazaraBuild.SetupInfoTable

View File

@ -1,6 +1,7 @@
MODULE.Name = "Core" MODULE.Name = "Core"
MODULE.Excludable = false -- Excluding the core makes no sense as everything relies on it
MODULE.Files = { -- Les autres fichiers seront ajoutés automatiquement MODULE.Files = { -- Other files will be automatically added
"../include/Nazara/Prerequesites.hpp", "../include/Nazara/Prerequesites.hpp",
"../include/Nazara/Math/**.hpp", "../include/Nazara/Math/**.hpp",
"../include/Nazara/Math/**.inl", "../include/Nazara/Math/**.inl",

View File

@ -1,9 +1,8 @@
TOOL.Name = "Assimp" TOOL.Name = "Assimp"
TOOL.Directory = "../SDK/lib" TOOL.Directory = "../plugins/Assimp"
TOOL.Kind = "Plugin" TOOL.Kind = "Plugin"
TOOL.TargetDirectory = "../SDK/lib"
TOOL.CopyTargetToExampleDir = true
TOOL.Includes = { TOOL.Includes = {
"../include", "../include",

View File

@ -1,9 +1,8 @@
TOOL.Name = "SDK" TOOL.Name = "SDK"
TOOL.CopyTargetToExampleDir = true TOOL.Directory = "../SDK"
TOOL.Directory = "../SDK/lib"
TOOL.Kind = "Library" TOOL.Kind = "Library"
TOOL.TargetDirectory = "../SDK/lib"
TOOL.Defines = { TOOL.Defines = {
"NDK_BUILD" "NDK_BUILD"

View File

@ -1,9 +1,8 @@
TOOL.Name = "SDKServer" TOOL.Name = "SDKServer"
TOOL.CopyTargetToExampleDir = true TOOL.Directory = "../SDK"
TOOL.Directory = "../SDK/lib"
TOOL.Kind = "Library" TOOL.Kind = "Library"
TOOL.TargetDirectory = "../SDK/lib"
TOOL.Defines = { TOOL.Defines = {
"NDK_BUILD", "NDK_BUILD",
@ -23,7 +22,7 @@ TOOL.Files = {
"../SDK/src/NDK/**.cpp" "../SDK/src/NDK/**.cpp"
} }
-- Exlude client-only files -- Excludes client-only files
TOOL.FilesExcluded = { TOOL.FilesExcluded = {
"../SDK/**/CameraComponent.*", "../SDK/**/CameraComponent.*",
"../SDK/**/Console.*", "../SDK/**/Console.*",

View File

@ -1,7 +1,9 @@
TOOL.Name = "UnitTests" TOOL.Name = "UnitTests"
TOOL.Directory = "../tests" TOOL.Directory = "../tests"
TOOL.Kind = "ConsoleApp" TOOL.EnableConsole = true
TOOL.Kind = "Application"
TOOL.TargetDirectory = TOOL.Directory
TOOL.Defines = { TOOL.Defines = {
} }

View File

@ -1,6 +1,6 @@
EXAMPLE.Name = "DopplerEffect" EXAMPLE.Name = "DopplerEffect"
EXAMPLE.Console = true EXAMPLE.EnableConsole = true
EXAMPLE.Files = { EXAMPLE.Files = {
"main.cpp" "main.cpp"

View File

@ -1,6 +1,6 @@
EXAMPLE.Name = "FirstScene" EXAMPLE.Name = "FirstScene"
EXAMPLE.Console = true EXAMPLE.EnableConsole = true
EXAMPLE.Files = { EXAMPLE.Files = {
"main.cpp" "main.cpp"

View File

@ -1,6 +1,6 @@
EXAMPLE.Name = "MeshInfos" EXAMPLE.Name = "MeshInfos"
EXAMPLE.Console = true EXAMPLE.EnableConsole = true
EXAMPLE.Files = { EXAMPLE.Files = {
"main.cpp" "main.cpp"

View File

@ -1,6 +1,6 @@
EXAMPLE.Name = "Tut00_EmptyProject" EXAMPLE.Name = "Tut00_EmptyProject"
EXAMPLE.Console = true EXAMPLE.EnableConsole = true
EXAMPLE.Files = { EXAMPLE.Files = {
"main.cpp" "main.cpp"

View File

@ -1,6 +1,6 @@
EXAMPLE.Name = "Tut01_HelloWorld" EXAMPLE.Name = "Tut01_HelloWorld"
EXAMPLE.Console = true EXAMPLE.EnableConsole = true
EXAMPLE.Files = { EXAMPLE.Files = {
"main.cpp" "main.cpp"

View File

@ -7,11 +7,21 @@
namespace Nz namespace Nz
{ {
/*!
* \ingroup audio
* \brief Mixes channels in mono
*
* \param input Input buffer with multiples channels
* \param output Output butter for mono
* \param channelCount Number of channels
* \param frameCount Number of frames
*
* \remark The input buffer may be the same as the output one
*/
template<typename T> template<typename T>
void MixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount) void MixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount)
{ {
///DOC: Le buffer d'entrée peut être le même que le buffer de sortie // To avoid overflow, we use, as an accumulator, a type which is large enough: (u)int 64 bits for integers, double for floatings
// Pour éviter l'overflow, on utilise comme accumulateur un type assez grand, (u)int 64 bits pour les entiers, double pour les flottants
typedef typename std::conditional<std::is_unsigned<T>::value, UInt64, Int64>::type BiggestInt; typedef typename std::conditional<std::is_unsigned<T>::value, UInt64, Int64>::type BiggestInt;
typedef typename std::conditional<std::is_integral<T>::value, BiggestInt, double>::type Biggest; typedef typename std::conditional<std::is_integral<T>::value, BiggestInt, double>::type Biggest;
@ -19,7 +29,7 @@ namespace Nz
{ {
Biggest acc = Biggest(0); Biggest acc = Biggest(0);
for (unsigned int j = 0; j < channelCount; ++j) for (unsigned int j = 0; j < channelCount; ++j)
acc += input[i*channelCount + j]; acc += input[i * channelCount + j];
output[i] = static_cast<T>(acc / channelCount); output[i] = static_cast<T>(acc / channelCount);
} }

View File

@ -27,18 +27,23 @@
#ifndef NAZARA_CONFIG_AUDIO_HPP #ifndef NAZARA_CONFIG_AUDIO_HPP
#define NAZARA_CONFIG_AUDIO_HPP #define NAZARA_CONFIG_AUDIO_HPP
/// Modifier la configuration d'un module nécessite une recompilation quasi-intégrale de celui-ci et de ceux en héritant /*!
* \defgroup audio (NazaraAudio) Audio module
* Audio/System module including classes to handle music, sound, etc...
*/
// Utilise un manager de mémoire pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes) /// Each modification of a parameter needs a recompilation of the module
// Use the MemoryManager to manage dynamic allocations (can detect memory leak but allocations/frees are slower)
#define NAZARA_AUDIO_MANAGE_MEMORY 0 #define NAZARA_AUDIO_MANAGE_MEMORY 0
// Active les tests de sécurité supplémentaires (Teste notamment les arguments des fonctions, conseillé pour le développement) // Activate the security tests based on the code (Advised for development)
#define NAZARA_AUDIO_SAFE 1 #define NAZARA_AUDIO_SAFE 1
// Le nombre de buffers utilisés lors du streaming d'objets audio (Au moins deux) // The number of buffers used for audio streaming (At least two)
#define NAZARA_AUDIO_STREAMED_BUFFER_COUNT 2 #define NAZARA_AUDIO_STREAMED_BUFFER_COUNT 2
/// Vérification des valeurs et types de certaines constantes /// Checking the values and types of certain constants
#include <Nazara/Audio/ConfigCheck.hpp> #include <Nazara/Audio/ConfigCheck.hpp>
#if !defined(NAZARA_STATIC) #if !defined(NAZARA_STATIC)

View File

@ -7,12 +7,12 @@
#ifndef NAZARA_CONFIG_CHECK_AUDIO_HPP #ifndef NAZARA_CONFIG_CHECK_AUDIO_HPP
#define NAZARA_CONFIG_CHECK_AUDIO_HPP #define NAZARA_CONFIG_CHECK_AUDIO_HPP
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp /// This file is used to check the constant values defined in Config.hpp
#include <type_traits> #include <type_traits>
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err) #define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
// On force la valeur de MANAGE_MEMORY en mode debug // We force the value of MANAGE_MEMORY in debug
#if defined(NAZARA_DEBUG) && !NAZARA_AUDIO_MANAGE_MEMORY #if defined(NAZARA_DEBUG) && !NAZARA_AUDIO_MANAGE_MEMORY
#undef NAZARA_AUDIO_MANAGE_MEMORY #undef NAZARA_AUDIO_MANAGE_MEMORY
#define NAZARA_AUDIO_MANAGE_MEMORY 0 #define NAZARA_AUDIO_MANAGE_MEMORY 0

View File

@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine - Audio module" // This file is part of the "Nazara Engine - Audio module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp // We assume that Debug.hpp has already been included, same thing for Config.hpp
#if NAZARA_AUDIO_MANAGE_MEMORY #if NAZARA_AUDIO_MANAGE_MEMORY
#undef delete #undef delete
#undef new #undef new

View File

@ -13,7 +13,7 @@ namespace Nz
{ {
AudioFormat_Unknown = -1, AudioFormat_Unknown = -1,
// La valeur entière est le nombre de canaux possédés par ce format // The integer value is the number of channels used by the format
AudioFormat_Mono = 1, AudioFormat_Mono = 1,
AudioFormat_Stereo = 2, AudioFormat_Stereo = 2,
AudioFormat_Quad = 4, AudioFormat_Quad = 4,

View File

@ -15,18 +15,18 @@
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <vector> #include <vector>
// Inclusion des headers OpenAL // Inclusion of OpenAL headers
// Étant donné que les headers OpenAL ne nous permettent pas de n'avoir que les signatures sans les pointeurs de fonctions // OpenAL headers does not allow us to only get the signatures without the pointers to the functions
// Et que je ne souhaite pas les modifier, je suis contraint de les placer dans un espace de nom différent pour ensuite // And I do no want to modify them, I'm obliged to put them in a different namespace
// remettre dans l'espace global les choses intéressantes (les typedef notamment) // to put only interesting things back in the global namespace (specially typedef)
namespace OpenALDetail namespace OpenALDetail
{ {
#include <AL/al.h> #include <AL/al.h>
#include <AL/alc.h> #include <AL/alc.h>
} }
// Si quelqu'un a une meilleure idée ... // If someone has a better idea ...
using OpenALDetail::ALboolean; using OpenALDetail::ALboolean;
using OpenALDetail::ALbyte; using OpenALDetail::ALbyte;
using OpenALDetail::ALchar; using OpenALDetail::ALchar;

View File

@ -7,6 +7,13 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Creates a new sound buffer from the arguments
* \return A reference to the newly created sound buffer
*
* \param args Arguments for the sound buffer
*/
template<typename... Args> template<typename... Args>
SoundBufferRef SoundBuffer::New(Args&&... args) SoundBufferRef SoundBuffer::New(Args&&... args)
{ {

View File

@ -12,7 +12,7 @@
#include <Nazara/Audio/Enums.hpp> #include <Nazara/Audio/Enums.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
///TODO: Faire hériter SoundEmitter de Node ///TODO: Inherit SoundEmitter from Node
namespace Nz namespace Nz
{ {

View File

@ -26,9 +26,9 @@ namespace Nz
class Bit; class Bit;
Bitset(); Bitset();
explicit Bitset(unsigned int bitCount, bool val); explicit Bitset(std::size_t bitCount, bool val);
explicit Bitset(const char* bits); explicit Bitset(const char* bits);
Bitset(const char* bits, unsigned int bitCount); Bitset(const char* bits, std::size_t bitCount);
Bitset(const Bitset& bitset) = default; Bitset(const Bitset& bitset) = default;
explicit Bitset(const String& bits); explicit Bitset(const String& bits);
template<typename T> Bitset(T value); template<typename T> Bitset(T value);
@ -36,16 +36,16 @@ namespace Nz
~Bitset() noexcept = default; ~Bitset() noexcept = default;
void Clear() noexcept; void Clear() noexcept;
unsigned int Count() const; std::size_t Count() const;
void Flip(); void Flip();
unsigned int FindFirst() const; std::size_t FindFirst() const;
unsigned int FindNext(unsigned int bit) const; std::size_t FindNext(std::size_t bit) const;
Block GetBlock(unsigned int i) const; Block GetBlock(std::size_t i) const;
unsigned int GetBlockCount() const; std::size_t GetBlockCount() const;
unsigned int GetCapacity() const; std::size_t GetCapacity() const;
unsigned int GetSize() const; std::size_t GetSize() const;
void PerformsAND(const Bitset& a, const Bitset& b); void PerformsAND(const Bitset& a, const Bitset& b);
void PerformsNOT(const Bitset& a); void PerformsNOT(const Bitset& a);
@ -54,19 +54,19 @@ namespace Nz
bool Intersects(const Bitset& bitset) const; bool Intersects(const Bitset& bitset) const;
void Reserve(unsigned int bitCount); void Reserve(std::size_t bitCount);
void Resize(unsigned int bitCount, bool defaultVal = false); void Resize(std::size_t bitCount, bool defaultVal = false);
void Reset(); void Reset();
void Reset(unsigned int bit); void Reset(std::size_t bit);
void Set(bool val = true); void Set(bool val = true);
void Set(unsigned int bit, bool val = true); void Set(std::size_t bit, bool val = true);
void SetBlock(unsigned int i, Block block); void SetBlock(std::size_t i, Block block);
void Swap(Bitset& bitset); void Swap(Bitset& bitset);
bool Test(unsigned int bit) const; bool Test(std::size_t bit) const;
bool TestAll() const; bool TestAll() const;
bool TestAny() const; bool TestAny() const;
bool TestNone() const; bool TestNone() const;
@ -74,9 +74,9 @@ namespace Nz
template<typename T> T To() const; template<typename T> T To() const;
String ToString() const; String ToString() const;
void UnboundedReset(unsigned int bit); void UnboundedReset(std::size_t bit);
void UnboundedSet(unsigned int bit, bool val = true); void UnboundedSet(std::size_t bit, bool val = true);
bool UnboundedTest(unsigned int bit) const; bool UnboundedTest(std::size_t bit) const;
Bit operator[](int index); Bit operator[](int index);
bool operator[](int index) const; bool operator[](int index) const;
@ -93,20 +93,20 @@ namespace Nz
Bitset& operator^=(const Bitset& bitset); Bitset& operator^=(const Bitset& bitset);
static constexpr Block fullBitMask = std::numeric_limits<Block>::max(); static constexpr Block fullBitMask = std::numeric_limits<Block>::max();
static constexpr unsigned int bitsPerBlock = std::numeric_limits<Block>::digits; static constexpr std::size_t bitsPerBlock = std::numeric_limits<Block>::digits;
static constexpr unsigned int npos = std::numeric_limits<unsigned int>::max(); static constexpr std::size_t npos = std::numeric_limits<std::size_t>::max();
private: private:
unsigned int FindFirstFrom(unsigned int blockIndex) const; std::size_t FindFirstFrom(std::size_t blockIndex) const;
Block GetLastBlockMask() const; Block GetLastBlockMask() const;
void ResetExtraBits(); void ResetExtraBits();
static unsigned int ComputeBlockCount(unsigned int bitCount); static std::size_t ComputeBlockCount(std::size_t bitCount);
static unsigned int GetBitIndex(unsigned int bit); static std::size_t GetBitIndex(std::size_t bit);
static unsigned int GetBlockIndex(unsigned int bit); static std::size_t GetBlockIndex(std::size_t bit);
std::vector<Block, Allocator> m_blocks; std::vector<Block, Allocator> m_blocks;
unsigned int m_bitCount; std::size_t m_bitCount;
}; };
template<typename Block, class Allocator> template<typename Block, class Allocator>

View File

@ -42,7 +42,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
Bitset<Block, Allocator>::Bitset(unsigned int bitCount, bool val) : Bitset<Block, Allocator>::Bitset(std::size_t bitCount, bool val) :
Bitset() Bitset()
{ {
Resize(bitCount, val); Resize(bitCount, val);
@ -72,11 +72,11 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
Bitset<Block, Allocator>::Bitset(const char* bits, unsigned int bitCount) : Bitset<Block, Allocator>::Bitset(const char* bits, std::size_t bitCount) :
m_blocks(ComputeBlockCount(bitCount), 0U), m_blocks(ComputeBlockCount(bitCount), 0U),
m_bitCount(bitCount) m_bitCount(bitCount)
{ {
for (unsigned int i = 0; i < bitCount; ++i) for (std::size_t i = 0; i < bitCount; ++i)
{ {
switch (*bits++) switch (*bits++)
{ {
@ -126,7 +126,7 @@ namespace Nz
else else
{ {
// Note: I was kinda tired when I wrote this, there's probably a much easier method than checking bits to write bits // Note: I was kinda tired when I wrote this, there's probably a much easier method than checking bits to write bits
for (unsigned int bitPos = 0; bitPos < std::numeric_limits<T>::digits; bitPos++) for (std::size_t bitPos = 0; bitPos < std::numeric_limits<T>::digits; bitPos++)
{ {
if (value & (T(1U) << bitPos)) if (value & (T(1U) << bitPos))
UnboundedSet(bitPos, true); UnboundedSet(bitPos, true);
@ -153,13 +153,13 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::Count() const std::size_t Bitset<Block, Allocator>::Count() const
{ {
if (m_blocks.empty()) if (m_blocks.empty())
return 0; return 0;
unsigned int count = 0; std::size_t count = 0;
for (unsigned int i = 0; i < m_blocks.size(); ++i) for (std::size_t i = 0; i < m_blocks.size(); ++i)
count += CountBits(m_blocks[i]); count += CountBits(m_blocks[i]);
return count; return count;
@ -184,7 +184,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::FindFirst() const std::size_t Bitset<Block, Allocator>::FindFirst() const
{ {
return FindFirstFrom(0); return FindFirstFrom(0);
} }
@ -199,7 +199,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::FindNext(unsigned int bit) const std::size_t Bitset<Block, Allocator>::FindNext(std::size_t bit) const
{ {
NazaraAssert(bit < m_bitCount, "Bit index out of range"); NazaraAssert(bit < m_bitCount, "Bit index out of range");
@ -207,8 +207,8 @@ namespace Nz
return npos; return npos;
// The block of the bit and its index // The block of the bit and its index
unsigned int blockIndex = GetBlockIndex(bit); std::size_t blockIndex = GetBlockIndex(bit);
unsigned int bitIndex = GetBitIndex(bit); std::size_t bitIndex = GetBitIndex(bit);
// We get the block // We get the block
Block block = m_blocks[blockIndex]; Block block = m_blocks[blockIndex];
@ -233,7 +233,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
Block Bitset<Block, Allocator>::GetBlock(unsigned int i) const Block Bitset<Block, Allocator>::GetBlock(std::size_t i) const
{ {
NazaraAssert(i < m_blocks.size(), "Block index out of range"); NazaraAssert(i < m_blocks.size(), "Block index out of range");
@ -246,7 +246,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::GetBlockCount() const std::size_t Bitset<Block, Allocator>::GetBlockCount() const
{ {
return m_blocks.size(); return m_blocks.size();
} }
@ -257,7 +257,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::GetCapacity() const std::size_t Bitset<Block, Allocator>::GetCapacity() const
{ {
return m_blocks.capacity()*bitsPerBlock; return m_blocks.capacity()*bitsPerBlock;
} }
@ -268,7 +268,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::GetSize() const std::size_t Bitset<Block, Allocator>::GetSize() const
{ {
return m_bitCount; return m_bitCount;
} }
@ -285,7 +285,7 @@ namespace Nz
template<typename Block, class Allocator> template<typename Block, class Allocator>
void Bitset<Block, Allocator>::PerformsAND(const Bitset& a, const Bitset& b) void Bitset<Block, Allocator>::PerformsAND(const Bitset& a, const Bitset& b)
{ {
std::pair<unsigned int, unsigned int> minmax = std::minmax(a.GetBlockCount(), b.GetBlockCount()); std::pair<std::size_t, std::size_t> minmax = std::minmax(a.GetBlockCount(), b.GetBlockCount());
// We reinitialise our blocks with zero // We reinitialise our blocks with zero
m_blocks.clear(); m_blocks.clear();
@ -293,7 +293,7 @@ namespace Nz
m_bitCount = std::max(a.GetSize(), b.GetSize()); m_bitCount = std::max(a.GetSize(), b.GetSize());
// In case of the "AND", we can stop with the smallest size (because x & 0 = 0) // In case of the "AND", we can stop with the smallest size (because x & 0 = 0)
for (unsigned int i = 0; i < minmax.first; ++i) for (std::size_t i = 0; i < minmax.first; ++i)
m_blocks[i] = a.GetBlock(i) & b.GetBlock(i); m_blocks[i] = a.GetBlock(i) & b.GetBlock(i);
ResetExtraBits(); ResetExtraBits();
@ -311,7 +311,7 @@ namespace Nz
m_blocks.resize(a.GetBlockCount()); m_blocks.resize(a.GetBlockCount());
m_bitCount = a.GetSize(); m_bitCount = a.GetSize();
for (unsigned int i = 0; i < m_blocks.size(); ++i) for (std::size_t i = 0; i < m_blocks.size(); ++i)
m_blocks[i] = ~a.GetBlock(i); m_blocks[i] = ~a.GetBlock(i);
ResetExtraBits(); ResetExtraBits();
@ -332,15 +332,15 @@ namespace Nz
const Bitset& greater = (a.GetSize() > b.GetSize()) ? a : b; const Bitset& greater = (a.GetSize() > b.GetSize()) ? a : b;
const Bitset& lesser = (a.GetSize() > b.GetSize()) ? b : a; const Bitset& lesser = (a.GetSize() > b.GetSize()) ? b : a;
unsigned int maxBlockCount = greater.GetBlockCount(); std::size_t maxBlockCount = greater.GetBlockCount();
unsigned int minBlockCount = lesser.GetBlockCount(); std::size_t minBlockCount = lesser.GetBlockCount();
m_blocks.resize(maxBlockCount); m_blocks.resize(maxBlockCount);
m_bitCount = greater.GetSize(); m_bitCount = greater.GetSize();
for (unsigned int i = 0; i < minBlockCount; ++i) for (std::size_t i = 0; i < minBlockCount; ++i)
m_blocks[i] = a.GetBlock(i) | b.GetBlock(i); m_blocks[i] = a.GetBlock(i) | b.GetBlock(i);
for (unsigned int i = minBlockCount; i < maxBlockCount; ++i) for (std::size_t i = minBlockCount; i < maxBlockCount; ++i)
m_blocks[i] = greater.GetBlock(i); // (x | 0 = x) m_blocks[i] = greater.GetBlock(i); // (x | 0 = x)
ResetExtraBits(); ResetExtraBits();
@ -361,15 +361,15 @@ namespace Nz
const Bitset& greater = (a.GetSize() > b.GetSize()) ? a : b; const Bitset& greater = (a.GetSize() > b.GetSize()) ? a : b;
const Bitset& lesser = (a.GetSize() > b.GetSize()) ? b : a; const Bitset& lesser = (a.GetSize() > b.GetSize()) ? b : a;
unsigned int maxBlockCount = greater.GetBlockCount(); std::size_t maxBlockCount = greater.GetBlockCount();
unsigned int minBlockCount = lesser.GetBlockCount(); std::size_t minBlockCount = lesser.GetBlockCount();
m_blocks.resize(maxBlockCount); m_blocks.resize(maxBlockCount);
m_bitCount = greater.GetSize(); m_bitCount = greater.GetSize();
for (unsigned int i = 0; i < minBlockCount; ++i) for (std::size_t i = 0; i < minBlockCount; ++i)
m_blocks[i] = a.GetBlock(i) ^ b.GetBlock(i); m_blocks[i] = a.GetBlock(i) ^ b.GetBlock(i);
for (unsigned int i = minBlockCount; i < maxBlockCount; ++i) for (std::size_t i = minBlockCount; i < maxBlockCount; ++i)
m_blocks[i] = greater.GetBlock(i); // (x ^ 0 = x) m_blocks[i] = greater.GetBlock(i); // (x ^ 0 = x)
ResetExtraBits(); ResetExtraBits();
@ -385,8 +385,8 @@ namespace Nz
bool Bitset<Block, Allocator>::Intersects(const Bitset& bitset) const bool Bitset<Block, Allocator>::Intersects(const Bitset& bitset) const
{ {
// We only test the blocks in common // We only test the blocks in common
unsigned int sharedBlocks = std::min(GetBlockCount(), bitset.GetBlockCount()); std::size_t sharedBlocks = std::min(GetBlockCount(), bitset.GetBlockCount());
for (unsigned int i = 0; i < sharedBlocks; ++i) for (std::size_t i = 0; i < sharedBlocks; ++i)
{ {
Block a = GetBlock(i); Block a = GetBlock(i);
Block b = bitset.GetBlock(i); Block b = bitset.GetBlock(i);
@ -404,7 +404,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
void Bitset<Block, Allocator>::Reserve(unsigned int bitCount) void Bitset<Block, Allocator>::Reserve(std::size_t bitCount)
{ {
m_blocks.reserve(ComputeBlockCount(bitCount)); m_blocks.reserve(ComputeBlockCount(bitCount));
} }
@ -417,13 +417,13 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
void Bitset<Block, Allocator>::Resize(unsigned int bitCount, bool defaultVal) void Bitset<Block, Allocator>::Resize(std::size_t bitCount, bool defaultVal)
{ {
// We begin with changing the size of container, with the correct value of initialisation // We begin with changing the size of container, with the correct value of initialisation
unsigned int lastBlockIndex = m_blocks.size() - 1; std::size_t lastBlockIndex = m_blocks.size() - 1;
m_blocks.resize(ComputeBlockCount(bitCount), (defaultVal) ? fullBitMask : 0U); m_blocks.resize(ComputeBlockCount(bitCount), (defaultVal) ? fullBitMask : 0U);
unsigned int remainingBits = GetBitIndex(m_bitCount); std::size_t remainingBits = GetBitIndex(m_bitCount);
if (bitCount > m_bitCount && remainingBits > 0 && defaultVal) if (bitCount > m_bitCount && remainingBits > 0 && defaultVal)
// Initialisation of unused bits in the last block before the size change // Initialisation of unused bits in the last block before the size change
m_blocks[lastBlockIndex] |= fullBitMask << remainingBits; m_blocks[lastBlockIndex] |= fullBitMask << remainingBits;
@ -451,7 +451,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
void Bitset<Block, Allocator>::Reset(unsigned int bit) void Bitset<Block, Allocator>::Reset(std::size_t bit)
{ {
Set(bit, false); Set(bit, false);
} }
@ -482,7 +482,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
void Bitset<Block, Allocator>::Set(unsigned int bit, bool val) void Bitset<Block, Allocator>::Set(std::size_t bit, bool val)
{ {
NazaraAssert(bit < m_bitCount, "Bit index out of range"); NazaraAssert(bit < m_bitCount, "Bit index out of range");
@ -503,7 +503,7 @@ namespace Nz
* \remark Produce a NazaraAssert if i is greather than number of blocks in bitset * \remark Produce a NazaraAssert if i is greather than number of blocks in bitset
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
void Bitset<Block, Allocator>::SetBlock(unsigned int i, Block block) void Bitset<Block, Allocator>::SetBlock(std::size_t i, Block block)
{ {
NazaraAssert(i < m_blocks.size(), "Block index out of range"); NazaraAssert(i < m_blocks.size(), "Block index out of range");
@ -537,7 +537,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool Bitset<Block, Allocator>::Test(unsigned int bit) const bool Bitset<Block, Allocator>::Test(std::size_t bit) const
{ {
NazaraAssert(bit < m_bitCount, "Bit index out of range"); NazaraAssert(bit < m_bitCount, "Bit index out of range");
@ -555,7 +555,7 @@ namespace Nz
// Special case for the last block // Special case for the last block
Block lastBlockMask = GetLastBlockMask(); Block lastBlockMask = GetLastBlockMask();
for (unsigned int i = 0; i < m_blocks.size(); ++i) for (std::size_t i = 0; i < m_blocks.size(); ++i)
{ {
Block mask = (i == m_blocks.size() - 1) ? lastBlockMask : fullBitMask; Block mask = (i == m_blocks.size() - 1) ? lastBlockMask : fullBitMask;
if (m_blocks[i] == mask) // The extra bits are set to zero, thus we can't test without proceeding with a mask if (m_blocks[i] == mask) // The extra bits are set to zero, thus we can't test without proceeding with a mask
@ -576,7 +576,7 @@ namespace Nz
if (m_blocks.empty()) if (m_blocks.empty())
return false; return false;
for (unsigned int i = 0; i < m_blocks.size(); ++i) for (std::size_t i = 0; i < m_blocks.size(); ++i)
{ {
if (m_blocks[i]) if (m_blocks[i])
return true; return true;
@ -612,7 +612,7 @@ namespace Nz
NazaraAssert(m_bitCount <= std::numeric_limits<T>::digits, "Bit count cannot be greater than T bit count"); NazaraAssert(m_bitCount <= std::numeric_limits<T>::digits, "Bit count cannot be greater than T bit count");
T value = 0; T value = 0;
for (unsigned int i = 0; i < m_blocks.size(); ++i) for (std::size_t i = 0; i < m_blocks.size(); ++i)
value |= static_cast<T>(m_blocks[i]) << i*bitsPerBlock; value |= static_cast<T>(m_blocks[i]) << i*bitsPerBlock;
return value; return value;
@ -628,7 +628,7 @@ namespace Nz
{ {
String str(m_bitCount, '0'); String str(m_bitCount, '0');
for (unsigned int i = 0; i < m_bitCount; ++i) for (std::size_t i = 0; i < m_bitCount; ++i)
{ {
if (Test(i)) if (Test(i))
str[m_bitCount - i - 1] = '1'; // Inversion de l'indice str[m_bitCount - i - 1] = '1'; // Inversion de l'indice
@ -648,7 +648,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
void Bitset<Block, Allocator>::UnboundedReset(unsigned int bit) void Bitset<Block, Allocator>::UnboundedReset(std::size_t bit)
{ {
UnboundedSet(bit, false); UnboundedSet(bit, false);
} }
@ -665,7 +665,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
void Bitset<Block, Allocator>::UnboundedSet(unsigned int bit, bool val) void Bitset<Block, Allocator>::UnboundedSet(std::size_t bit, bool val)
{ {
if (bit < m_bitCount) if (bit < m_bitCount)
Set(bit, val); Set(bit, val);
@ -687,7 +687,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
bool Bitset<Block, Allocator>::UnboundedTest(unsigned int bit) const bool Bitset<Block, Allocator>::UnboundedTest(std::size_t bit) const
{ {
if (bit < m_bitCount) if (bit < m_bitCount)
return Test(bit); return Test(bit);
@ -816,13 +816,13 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::FindFirstFrom(unsigned int blockIndex) const std::size_t Bitset<Block, Allocator>::FindFirstFrom(std::size_t blockIndex) const
{ {
if (blockIndex >= m_blocks.size()) if (blockIndex >= m_blocks.size())
return npos; return npos;
// We are looking for the first non-null block // We are looking for the first non-null block
unsigned int i = blockIndex; std::size_t i = blockIndex;
for (; i < m_blocks.size(); ++i) for (; i < m_blocks.size(); ++i)
{ {
if (m_blocks[i]) if (m_blocks[i])
@ -868,7 +868,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::ComputeBlockCount(unsigned int bitCount) std::size_t Bitset<Block, Allocator>::ComputeBlockCount(std::size_t bitCount)
{ {
return GetBlockIndex(bitCount) + ((GetBitIndex(bitCount) != 0U) ? 1U : 0U); return GetBlockIndex(bitCount) + ((GetBitIndex(bitCount) != 0U) ? 1U : 0U);
} }
@ -879,7 +879,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::GetBitIndex(unsigned int bit) std::size_t Bitset<Block, Allocator>::GetBitIndex(std::size_t bit)
{ {
return bit & (bitsPerBlock - 1U); // bit % bitsPerBlock return bit & (bitsPerBlock - 1U); // bit % bitsPerBlock
} }
@ -890,7 +890,7 @@ namespace Nz
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
unsigned int Bitset<Block, Allocator>::GetBlockIndex(unsigned int bit) std::size_t Bitset<Block, Allocator>::GetBlockIndex(std::size_t bit)
{ {
return bit / bitsPerBlock; return bit / bitsPerBlock;
} }
@ -1106,18 +1106,18 @@ namespace Nz
const Bitset<Block, Allocator>& greater = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? lhs : rhs; const Bitset<Block, Allocator>& greater = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? lhs : rhs;
const Bitset<Block, Allocator>& lesser = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? rhs : lhs; const Bitset<Block, Allocator>& lesser = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? rhs : lhs;
unsigned int maxBlockCount = greater.GetBlockCount(); std::size_t maxBlockCount = greater.GetBlockCount();
unsigned int minBlockCount = lesser.GetBlockCount(); std::size_t minBlockCount = lesser.GetBlockCount();
// We test the blocks in common to check the equality of bits // We test the blocks in common to check the equality of bits
for (unsigned int i = 0; i < minBlockCount; ++i) for (std::size_t i = 0; i < minBlockCount; ++i)
{ {
if (lhs.GetBlock(i) != rhs.GetBlock(i)) if (lhs.GetBlock(i) != rhs.GetBlock(i))
return false; return false;
} }
// Now we check for the blocks that only the biggest bitset owns, and to be equal, they must be set to '0' // Now we check for the blocks that only the biggest bitset owns, and to be equal, they must be set to '0'
for (unsigned int i = minBlockCount; i < maxBlockCount; ++i) for (std::size_t i = minBlockCount; i < maxBlockCount; ++i)
if (greater.GetBlock(i)) if (greater.GetBlock(i))
return false; return false;
@ -1152,20 +1152,20 @@ namespace Nz
const Bitset<Block, Allocator>& greater = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? lhs : rhs; const Bitset<Block, Allocator>& greater = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? lhs : rhs;
const Bitset<Block, Allocator>& lesser = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? rhs : lhs; const Bitset<Block, Allocator>& lesser = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? rhs : lhs;
unsigned int maxBlockCount = greater.GetBlockCount(); std::size_t maxBlockCount = greater.GetBlockCount();
unsigned int minBlockCount = lesser.GetBlockCount(); std::size_t minBlockCount = lesser.GetBlockCount();
// If the greatest bitset has a single bit active in a block outside the lesser bitset range, then it is greater // If the greatest bitset has a single bit active in a block outside the lesser bitset range, then it is greater
for (unsigned int i = maxBlockCount; i > minBlockCount; ++i) for (std::size_t i = maxBlockCount; i > minBlockCount; ++i)
{ {
if (greater.GetBlock(i)) if (greater.GetBlock(i))
return lhs.GetBlockCount() < rhs.GetBlockCount(); return lhs.GetBlockCount() < rhs.GetBlockCount();
} }
// Compare the common blocks // Compare the common blocks
for (unsigned int i = 0; i < minBlockCount; ++i) for (std::size_t i = 0; i < minBlockCount; ++i)
{ {
unsigned int index = (minBlockCount - i - 1); // Compare from the most significant block to the less significant block std::size_t index = (minBlockCount - i - 1); // Compare from the most significant block to the less significant block
if (lhs.GetBlock(index) < rhs.GetBlock(index)) if (lhs.GetBlock(index) < rhs.GetBlock(index))
return true; return true;
} }

View File

@ -12,7 +12,7 @@
#include <type_traits> #include <type_traits>
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err) #define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
// We fore the value of MANAGE_MEMORY in debug // We force the value of MANAGE_MEMORY in debug
#if defined(NAZARA_DEBUG) && !NAZARA_CORE_MANAGE_MEMORY #if defined(NAZARA_DEBUG) && !NAZARA_CORE_MANAGE_MEMORY
#undef NAZARA_CORE_MANAGE_MEMORY #undef NAZARA_CORE_MANAGE_MEMORY
#define NAZARA_CORE_MANAGE_MEMORY 0 #define NAZARA_CORE_MANAGE_MEMORY 0

View File

@ -33,8 +33,8 @@ namespace Nz
inline void SwapBytes(void* buffer, std::size_t size) inline void SwapBytes(void* buffer, std::size_t size)
{ {
UInt8* bytes = static_cast<UInt8*>(buffer); UInt8* bytes = static_cast<UInt8*>(buffer);
unsigned int i = 0; std::size_t i = 0;
unsigned int j = size - 1; std::size_t j = size - 1;
while (i < j) while (i < j)
std::swap(bytes[i++], bytes[j--]); std::swap(bytes[i++], bytes[j--]);

View File

@ -10,6 +10,17 @@
namespace Nz namespace Nz
{ {
/*!
* \ingroup core
* \class Nz::HandledObject<T>
* \brief Core class that represents a handled object
*/
/*!
* \brief Constructs a HandledObject object by assignation
*
* \param object HandledObject to assign into this
*/
template<typename T> template<typename T>
HandledObject<T>::HandledObject(const HandledObject& object) HandledObject<T>::HandledObject(const HandledObject& object)
{ {
@ -17,6 +28,11 @@ namespace Nz
// Don't copy anything, we're a copy of the object, we have no handle right now // Don't copy anything, we're a copy of the object, we have no handle right now
} }
/*!
* \brief Constructs a HandledObject object by move semantic
*
* \param object HandledObject to move into this
*/
template<typename T> template<typename T>
HandledObject<T>::HandledObject(HandledObject&& object) : HandledObject<T>::HandledObject(HandledObject&& object) :
m_handles(std::move(object.m_handles)) m_handles(std::move(object.m_handles))
@ -25,18 +41,33 @@ namespace Nz
handle->OnObjectMoved(static_cast<T*>(this)); handle->OnObjectMoved(static_cast<T*>(this));
} }
/*!
* \brief Destructs the object and calls UnregisterAllHandles
*
* \see UnregisterAllHandles
*/
template<typename T> template<typename T>
HandledObject<T>::~HandledObject() HandledObject<T>::~HandledObject()
{ {
UnregisterAllHandles(); UnregisterAllHandles();
} }
/*!
* \brief Creates a ObjectHandle for this
* \return ObjectHandle to this
*/
template<typename T> template<typename T>
ObjectHandle<T> HandledObject<T>::CreateHandle() ObjectHandle<T> HandledObject<T>::CreateHandle()
{ {
return ObjectHandle<T>(static_cast<T*>(this)); return ObjectHandle<T>(static_cast<T*>(this));
} }
/*!
* \brief Sets the reference of the HandledObject with the handle from another
* \return A reference to this
*
* \param object The other HandledObject
*/
template<typename T> template<typename T>
HandledObject<T>& HandledObject<T>::operator=(const HandledObject& object) HandledObject<T>& HandledObject<T>::operator=(const HandledObject& object)
{ {
@ -44,6 +75,12 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Moves the HandledObject into this
* \return A reference to this
*
* \param object HandledObject to move in this
*/
template<typename T> template<typename T>
HandledObject<T>& HandledObject<T>::operator=(HandledObject&& object) HandledObject<T>& HandledObject<T>::operator=(HandledObject&& object)
{ {
@ -54,13 +91,22 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Registers a handle
*
* \param handle Handle to register
*
* \remark One handle can only be registered once, errors can occur if it's more than once
*/
template<typename T> template<typename T>
void HandledObject<T>::RegisterHandle(ObjectHandle<T>* handle) void HandledObject<T>::RegisterHandle(ObjectHandle<T>* handle)
{ {
///DOC: Un handle ne doit être enregistré qu'une fois, des erreurs se produisent s'il l'est plus d'une fois
m_handles.push_back(handle); m_handles.push_back(handle);
} }
/*!
* \brief Unregisters all handles
*/
template<typename T> template<typename T>
void HandledObject<T>::UnregisterAllHandles() void HandledObject<T>::UnregisterAllHandles()
{ {
@ -71,10 +117,17 @@ namespace Nz
m_handles.clear(); m_handles.clear();
} }
/*!
* \brief Unregisters a handle
*
* \param handle Handle to unregister
*
* \remark One handle can only be unregistered once, crash can occur if it's more than once
* \remark Produces a NazaraAssert if handle not registered
*/
template<typename T> template<typename T>
void HandledObject<T>::UnregisterHandle(ObjectHandle<T>* handle) noexcept void HandledObject<T>::UnregisterHandle(ObjectHandle<T>* handle) noexcept
{ {
///DOC: Un handle ne doit être libéré qu'une fois, et doit faire partie de la liste, sous peine de crash
auto it = std::find(m_handles.begin(), m_handles.end(), handle); auto it = std::find(m_handles.begin(), m_handles.end(), handle);
NazaraAssert(it != m_handles.end(), "Handle not registered"); NazaraAssert(it != m_handles.end(), "Handle not registered");
@ -83,6 +136,14 @@ namespace Nz
m_handles.pop_back(); m_handles.pop_back();
} }
/*!
* \brief Updates one handle with another
*
* \param oldHandle Old handle to replace
* \param newHandle New handle to take place
*
* \remark Produces a NazaraAssert if handle not registered
*/
template<typename T> template<typename T>
void HandledObject<T>::UpdateHandle(ObjectHandle<T>* oldHandle, ObjectHandle<T>* newHandle) noexcept void HandledObject<T>::UpdateHandle(ObjectHandle<T>* oldHandle, ObjectHandle<T>* newHandle) noexcept
{ {

View File

@ -9,12 +9,26 @@
namespace Nz namespace Nz
{ {
/*!
* \ingroup core
* \class Nz::ObjectHandle
* \brief Core class that represents a object handle
*/
/*!
* \brief Constructs a ObjectHandle object by default
*/
template<typename T> template<typename T>
ObjectHandle<T>::ObjectHandle() : ObjectHandle<T>::ObjectHandle() :
m_object(nullptr) m_object(nullptr)
{ {
} }
/*!
* \brief Constructs a ObjectHandle object with a pointer to an object
*
* \param object Pointer to handle like an object (can be nullptr)
*/
template<typename T> template<typename T>
ObjectHandle<T>::ObjectHandle(T* object) : ObjectHandle<T>::ObjectHandle(T* object) :
ObjectHandle() ObjectHandle()
@ -22,59 +36,97 @@ namespace Nz
Reset(object); Reset(object);
} }
/*!
* \brief Constructs a ObjectHandle object by assignation
*
* \param handle ObjectHandle to assign into this
*/
template<typename T> template<typename T>
ObjectHandle<T>::ObjectHandle(const ObjectHandle<T>& handle) : ObjectHandle<T>::ObjectHandle(const ObjectHandle& handle) :
ObjectHandle() ObjectHandle()
{ {
Reset(handle); Reset(handle);
} }
/*!
* \brief Constructs a ObjectHandle object by move semantic
*
* \param handle ObjectHandle to move into this
*/
template<typename T> template<typename T>
ObjectHandle<T>::ObjectHandle(ObjectHandle<T>&& handle) noexcept : ObjectHandle<T>::ObjectHandle(ObjectHandle&& handle) noexcept :
ObjectHandle() ObjectHandle()
{ {
Reset(std::move(handle)); Reset(std::move(handle));
} }
/*!
* \brief Destructs the object and calls reset with nullptr
*
* \see Reset
*/
template<typename T> template<typename T>
ObjectHandle<T>::~ObjectHandle() ObjectHandle<T>::~ObjectHandle()
{ {
Reset(nullptr); Reset(nullptr);
} }
/*!
* \brief Gets the underlying object
* \return Underlying object
*/
template<typename T> template<typename T>
T* ObjectHandle<T>::GetObject() const T* ObjectHandle<T>::GetObject() const
{ {
return m_object; return m_object;
} }
/*!
* \brief Checks whether the object is valid
* \return true if object is not nullptr
*/
template<typename T> template<typename T>
bool ObjectHandle<T>::IsValid() const bool ObjectHandle<T>::IsValid() const
{ {
return m_object != nullptr; return m_object != nullptr;
} }
/*!
* \brief Resets the content of the ObjectHandle with another object
*
* \param object Object to handle
*/
template<typename T> template<typename T>
void ObjectHandle<T>::Reset(T* object) void ObjectHandle<T>::Reset(T* object)
{ {
// Si nous avions déjà une entité, nous devons l'informer que nous ne pointons plus sur elle // If we already have an entity, we must alert it that we are not pointing to it anymore
if (m_object) if (m_object)
m_object->UnregisterHandle(this); m_object->UnregisterHandle(this);
m_object = object; m_object = object;
if (m_object) if (m_object)
// On informe la nouvelle entité que nous pointons sur elle // We alert the new entity that we are pointing to it
m_object->RegisterHandle(this); m_object->RegisterHandle(this);
} }
/*!
* \brief Resets the content of this with another object
*
* \param handle New object to handle
*/
template<typename T> template<typename T>
void ObjectHandle<T>::Reset(const ObjectHandle<T>& handle) void ObjectHandle<T>::Reset(const ObjectHandle& handle)
{ {
Reset(handle.GetObject()); Reset(handle.GetObject());
} }
/*!
* \brief Resets the content of this with another object by move semantic
*
* \param handle New object to handle to move into this
*/
template<typename T> template<typename T>
void ObjectHandle<T>::Reset(ObjectHandle<T>&& handle) noexcept void ObjectHandle<T>::Reset(ObjectHandle&& handle) noexcept
{ {
if (m_object) if (m_object)
m_object->UnregisterHandle(this); m_object->UnregisterHandle(this);
@ -87,12 +139,18 @@ namespace Nz
} }
} }
/*!
* \brief Swaps the content of the two ObjectHandle
* \return A reference to this
*
* \param handle ObjectHandle to swap
*/
template<typename T> template<typename T>
ObjectHandle<T>& ObjectHandle<T>::Swap(ObjectHandle<T>& handle) ObjectHandle<T>& ObjectHandle<T>::Swap(ObjectHandle& handle)
{ {
// Comme nous inversons les handles, nous devons prévenir les entités // As we swap the two handles, we must alert the entities
// La version par défaut de swap (à base de move) aurait fonctionné, // The default version with swap (move) would be working,
// mais en enregistrant les handles une fois de plus que nécessaire (à cause de la copie temporaire). // but will register handles one more time (due to temporary copy).
if (m_object) if (m_object)
{ {
m_object->UnregisterHandle(this); m_object->UnregisterHandle(this);
@ -105,11 +163,15 @@ namespace Nz
handle.m_object->RegisterHandle(this); handle.m_object->RegisterHandle(this);
} }
// On effectue l'échange // We do the swap
std::swap(m_object, handle.m_object); std::swap(m_object, handle.m_object);
return *this; return *this;
} }
/*!
* \brief Gives a string representation
* \return A string representation of the object "ObjectHandle(object representation) or Null"
*/
template<typename T> template<typename T>
Nz::String ObjectHandle<T>::ToString() const Nz::String ObjectHandle<T>::ToString() const
{ {
@ -125,24 +187,44 @@ namespace Nz
return ss; return ss;
} }
/*!
* \brief Converts the ObjectHandle to bool
* \return true if reference is not nullptr
*
* \see IsValid
*/
template<typename T> template<typename T>
ObjectHandle<T>::operator bool() const ObjectHandle<T>::operator bool() const
{ {
return IsValid(); return IsValid();
} }
/*!
* \brief Dereferences the ObjectHandle
* \return Underlying pointer
*/
template<typename T> template<typename T>
ObjectHandle<T>::operator T*() const ObjectHandle<T>::operator T*() const
{ {
return m_object; return m_object;
} }
/*!
* \brief Dereferences the ObjectHandle
* \return Underlying pointer
*/
template<typename T> template<typename T>
T* ObjectHandle<T>::operator->() const T* ObjectHandle<T>::operator->() const
{ {
return m_object; return m_object;
} }
/*!
* \brief Assigns the entity into this
* \return A reference to this
*
* \param entity Pointer to handle like an object (can be nullptr)
*/
template<typename T> template<typename T>
ObjectHandle<T>& ObjectHandle<T>::operator=(T* entity) ObjectHandle<T>& ObjectHandle<T>::operator=(T* entity)
{ {
@ -151,22 +233,37 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Sets the handle of the ObjectHandle with the handle from another
* \return A reference to this
*
* \param handle The other ObjectHandle
*/
template<typename T> template<typename T>
ObjectHandle<T>& ObjectHandle<T>::operator=(const ObjectHandle<T>& handle) ObjectHandle<T>& ObjectHandle<T>::operator=(const ObjectHandle& handle)
{ {
Reset(handle); Reset(handle);
return *this; return *this;
} }
/*!
* \brief Moves the ObjectHandle into this
* \return A reference to this
*
* \param handle ObjectHandle to move in this
*/
template<typename T> template<typename T>
ObjectHandle<T>& ObjectHandle<T>::operator=(ObjectHandle<T>&& handle) noexcept ObjectHandle<T>& ObjectHandle<T>::operator=(ObjectHandle&& handle) noexcept
{ {
Reset(std::move(handle)); Reset(std::move(handle));
return *this; return *this;
} }
/*!
* \brief Action to do on object destruction
*/
template<typename T> template<typename T>
void ObjectHandle<T>::OnObjectDestroyed() void ObjectHandle<T>::OnObjectDestroyed()
{ {
@ -174,6 +271,9 @@ namespace Nz
m_object = nullptr; m_object = nullptr;
} }
/*!
* \brief Action to do on object move
*/
template<typename T> template<typename T>
void ObjectHandle<T>::OnObjectMoved(T* newObject) void ObjectHandle<T>::OnObjectMoved(T* newObject)
{ {
@ -181,114 +281,247 @@ namespace Nz
m_object = newObject; m_object = newObject;
} }
/*!
* \brief Output operator
* \return The stream
*
* \param out The stream
* \param handle The ObjectHandle to output
*/
template<typename T> template<typename T>
std::ostream& operator<<(std::ostream& out, const ObjectHandle<T>& handle) std::ostream& operator<<(std::ostream& out, const ObjectHandle<T>& handle)
{ {
return handle.ToString(); return handle.ToString();
} }
/*!
* \brief Checks whether the first object handle is equal to the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator==(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator==(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return lhs.GetObject() == rhs.GetObject(); return lhs.GetObject() == rhs.GetObject();
} }
/*!
* \brief Checks whether the object is equal to the second object handle
* \return true if it is the case
*
* \param first Object to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator==(const T& lhs, const ObjectHandle<T>& rhs) bool operator==(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return &lhs == rhs.GetObject(); return &lhs == rhs.GetObject();
} }
/*!
* \brief Checks whether the object handle is equal to the second object
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second Object to compare in right hand side
*/
template<typename T> template<typename T>
bool operator==(const ObjectHandle<T>& lhs, const T& rhs) bool operator==(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return lhs.GetObject() == &rhs; return lhs.GetObject() == &rhs;
} }
/*!
* \brief Checks whether the first object handle is equal to the second object handle
* \return false if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator!=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator!=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
/*!
* \brief Checks whether the object is equal to the second object handle
* \return false if it is the case
*
* \param first Object to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator!=(const T& lhs, const ObjectHandle<T>& rhs) bool operator!=(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
/*!
* \brief Checks whether the object handle is equal to the second object
* \return false if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second Object to compare in right hand side
*/
template<typename T> template<typename T>
bool operator!=(const ObjectHandle<T>& lhs, const T& rhs) bool operator!=(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
/*!
* \brief Checks whether the first object handle is less than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator<(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return lhs.m_object < rhs.m_object; return lhs.m_object < rhs.m_object;
} }
/*!
* \brief Checks whether the first object handle is less than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<(const T& lhs, const ObjectHandle<T>& rhs) bool operator<(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return &lhs < rhs.m_object; return &lhs < rhs.m_object;
} }
/*!
* \brief Checks whether the first object handle is less than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<(const ObjectHandle<T>& lhs, const T& rhs) bool operator<(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return lhs.m_object < &rhs; return lhs.m_object < &rhs;
} }
/*!
* \brief Checks whether the first object handle is less or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator<=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
/*!
* \brief Checks whether the first object handle is less or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<=(const T& lhs, const ObjectHandle<T>& rhs) bool operator<=(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
/*!
* \brief Checks whether the first object handle is less or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<=(const ObjectHandle<T>& lhs, const T& rhs) bool operator<=(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
/*!
* \brief Checks whether the first object handle is greather than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator>(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return rhs < lhs; return rhs < lhs;
} }
/*!
* \brief Checks whether the first object handle is greather than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>(const T& lhs, const ObjectHandle<T>& rhs) bool operator>(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return rhs < lhs; return rhs < lhs;
} }
/*!
* \brief Checks whether the first object handle is greather than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>(const ObjectHandle<T>& lhs, const T& rhs) bool operator>(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return rhs < lhs; return rhs < lhs;
} }
/*!
* \brief Checks whether the first object handle is greather or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator>=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
/*!
* \brief Checks whether the first object handle is greather or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>=(const T& lhs, const ObjectHandle<T>& rhs) bool operator>=(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
/*!
* \brief Checks whether the first object handle is greather or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>=(const ObjectHandle<T>& lhs, const T& rhs) bool operator>=(const ObjectHandle<T>& lhs, const T& rhs)
{ {
@ -301,6 +534,12 @@ namespace Nz
namespace std namespace std
{ {
/*!
* \brief Swaps two ObjectHandle, specialisation of std
*
* \param lhs First object handle
* \param rhs Second object handle
*/
template<typename T> template<typename T>
void swap(Nz::ObjectHandle<T>& lhs, Nz::ObjectHandle<T>& rhs) void swap(Nz::ObjectHandle<T>& lhs, Nz::ObjectHandle<T>& rhs)
{ {

View File

@ -50,6 +50,8 @@ namespace Nz
void SetParameter(const String& name, void* value); void SetParameter(const String& name, void* value);
void SetParameter(const String& name, void* value, Destructor destructor); void SetParameter(const String& name, void* value, Destructor destructor);
String ToString() const;
ParameterList& operator=(const ParameterList& list); ParameterList& operator=(const ParameterList& list);
ParameterList& operator=(ParameterList&&) = default; ParameterList& operator=(ParameterList&&) = default;
@ -73,7 +75,7 @@ namespace Nz
ParameterType type; ParameterType type;
union Value union Value
{ {
// On définit un constructeur/destructeur vide, permettant de mettre des classes dans l'union // We define an empty constructor/destructor, to be able to put classes in the union
Value() {} Value() {}
Value(const Value&) {} // Placeholder Value(const Value&) {} // Placeholder
~Value() {} ~Value() {}
@ -98,4 +100,6 @@ namespace Nz
}; };
} }
std::ostream& operator<<(std::ostream& out, const Nz::ParameterList& parameterList);
#endif // NAZARA_PARAMETERLIST_HPP #endif // NAZARA_PARAMETERLIST_HPP

View File

@ -39,7 +39,7 @@ namespace Nz
static bool IsExtensionSupported(const String& extension); static bool IsExtensionSupported(const String& extension);
static bool LoadFromFile(Type* resource, const String& filePath, const Parameters& parameters = Parameters()); static bool LoadFromFile(Type* resource, const String& filePath, const Parameters& parameters = Parameters());
static bool LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters = Parameters()); static bool LoadFromMemory(Type* resource, const void* data, std::size_t size, const Parameters& parameters = Parameters());
static bool LoadFromStream(Type* resource, Stream& stream, const Parameters& parameters = Parameters()); static bool LoadFromStream(Type* resource, Stream& stream, const Parameters& parameters = Parameters());
static void RegisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader = nullptr, MemoryLoader memoryLoader = nullptr); static void RegisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader = nullptr, MemoryLoader memoryLoader = nullptr);

View File

@ -66,7 +66,7 @@ namespace Nz
return false; return false;
} }
File file(path); // Ouvert seulement en cas de besoin File file(path); // Open only if needed
bool found = false; bool found = false;
for (Loader& loader : Type::s_loaders) for (Loader& loader : Type::s_loaders)
@ -160,7 +160,7 @@ namespace Nz
* \remark Produces a NazaraError if all loaders failed or no loader was found * \remark Produces a NazaraError if all loaders failed or no loader was found
*/ */
template<typename Type, typename Parameters> template<typename Type, typename Parameters>
bool ResourceLoader<Type, Parameters>::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters) bool ResourceLoader<Type, Parameters>::LoadFromMemory(Type* resource, const void* data, std::size_t size, const Parameters& parameters)
{ {
NazaraAssert(resource, "Invalid resource"); NazaraAssert(resource, "Invalid resource");
NazaraAssert(data, "Invalid data pointer"); NazaraAssert(data, "Invalid data pointer");

View File

@ -7,6 +7,10 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a Billboard object by default
*/
inline Billboard::Billboard() inline Billboard::Billboard()
{ {
SetColor(Color::White); SetColor(Color::White);
@ -15,6 +19,12 @@ namespace Nz
SetSize(64.f, 64.f); SetSize(64.f, 64.f);
} }
/*!
* \brief Constructs a Billboard object with a reference to a material
*
* \param material Reference to a material
*/
inline Billboard::Billboard(MaterialRef material) inline Billboard::Billboard(MaterialRef material)
{ {
SetColor(Color::White); SetColor(Color::White);
@ -23,6 +33,12 @@ namespace Nz
SetSize(64.f, 64.f); SetSize(64.f, 64.f);
} }
/*!
* \brief Constructs a Billboard object with a pointer to a texture
*
* \param texture Pointer to a texture
*/
inline Billboard::Billboard(Texture* texture) inline Billboard::Billboard(Texture* texture)
{ {
SetColor(Color::White); SetColor(Color::White);
@ -31,6 +47,12 @@ namespace Nz
SetTexture(texture, true); SetTexture(texture, true);
} }
/*!
* \brief Constructs a Billboard object by assignation
*
* \param billboard Billboard to copy into this
*/
inline Billboard::Billboard(const Billboard& billboard) : inline Billboard::Billboard(const Billboard& billboard) :
InstancedRenderable(billboard), InstancedRenderable(billboard),
m_color(billboard.m_color), m_color(billboard.m_color),
@ -41,31 +63,61 @@ namespace Nz
{ {
} }
/*!
* \brief Gets the color of the billboard
* \return Current color
*/
inline const Color& Billboard::GetColor() const inline const Color& Billboard::GetColor() const
{ {
return m_color; return m_color;
} }
/*!
* \brief Gets the material of the billboard
* \return Current material
*/
inline const MaterialRef& Billboard::GetMaterial() const inline const MaterialRef& Billboard::GetMaterial() const
{ {
return m_material; return m_material;
} }
/*!
* \brief Gets the rotation of the billboard
* \return Current rotation
*/
inline float Billboard::GetRotation() const inline float Billboard::GetRotation() const
{ {
return m_rotation; return m_rotation;
} }
/*!
* \brief Gets the size of the billboard
* \return Current size
*/
inline const Vector2f& Billboard::GetSize() const inline const Vector2f& Billboard::GetSize() const
{ {
return m_size; return m_size;
} }
/*!
* \brief Sets the color of the billboard
*
* \param color Color for the billboard
*/
inline void Billboard::SetColor(const Color& color) inline void Billboard::SetColor(const Color& color)
{ {
m_color = color; m_color = color;
} }
/*!
* \brief Sets the default material of the billboard (just default material)
*/
inline void Billboard::SetDefaultMaterial() inline void Billboard::SetDefaultMaterial()
{ {
MaterialRef material = Material::New(); MaterialRef material = Material::New();
@ -75,6 +127,13 @@ namespace Nz
SetMaterial(std::move(material)); SetMaterial(std::move(material));
} }
/*!
* \brief Sets the material of the billboard
*
* \param material Material for the billboard
* \param resizeBillboard Should billboard be resized to the material size (diffuse map)
*/
inline void Billboard::SetMaterial(MaterialRef material, bool resizeBillboard) inline void Billboard::SetMaterial(MaterialRef material, bool resizeBillboard)
{ {
m_material = std::move(material); m_material = std::move(material);
@ -86,25 +145,51 @@ namespace Nz
} }
} }
/*!
* \brief Sets the rotation of the billboard
*
* \param rotation Rotation for the billboard
*/
inline void Billboard::SetRotation(float rotation) inline void Billboard::SetRotation(float rotation)
{ {
m_rotation = rotation; m_rotation = rotation;
m_sinCos.Set(std::sin(m_rotation), std::cos(m_rotation)); m_sinCos.Set(std::sin(m_rotation), std::cos(m_rotation));
} }
/*!
* \brief Sets the size of the billboard
*
* \param size Size for the billboard
*/
inline void Billboard::SetSize(const Vector2f& size) inline void Billboard::SetSize(const Vector2f& size)
{ {
m_size = size; m_size = size;
// On invalide la bounding box // We invalidate the bounding volume
InvalidateBoundingVolume(); InvalidateBoundingVolume();
} }
/*!
* \brief Sets the size of the billboard
*
* \param sizeX Size in X for the billboard
* \param sizeY Size in Y for the billboard
*/
inline void Billboard::SetSize(float sizeX, float sizeY) inline void Billboard::SetSize(float sizeX, float sizeY)
{ {
SetSize(Vector2f(sizeX, sizeY)); SetSize(Vector2f(sizeX, sizeY));
} }
/*!
* \brief Sets the texture of the billboard
*
* \param texture Texture for the billboard
* \param resizeBillboard Should billboard be resized to the texture size
*/
inline void Billboard::SetTexture(TextureRef texture, bool resizeBillboard) inline void Billboard::SetTexture(TextureRef texture, bool resizeBillboard)
{ {
if (!m_material) if (!m_material)
@ -118,6 +203,13 @@ namespace Nz
m_material->SetDiffuseMap(std::move(texture)); m_material->SetDiffuseMap(std::move(texture));
} }
/*!
* \brief Sets the current billboard with the content of the other one
* \return A reference to this
*
* \param billboard The other Billboard
*/
inline Billboard& Billboard::operator=(const Billboard& billboard) inline Billboard& Billboard::operator=(const Billboard& billboard)
{ {
InstancedRenderable::operator=(billboard); InstancedRenderable::operator=(billboard);
@ -131,6 +223,13 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Creates a new billboard from the arguments
* \return A reference to the newly created billboard
*
* \param args Arguments for the billboard
*/
template<typename... Args> template<typename... Args>
BillboardRef Billboard::New(Args&&... args) BillboardRef Billboard::New(Args&&... args)
{ {

View File

@ -7,6 +7,13 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Creates a new color background from the arguments
* \return A reference to the newly created color background
*
* \param args Arguments for the color background
*/
template<typename... Args> template<typename... Args>
ColorBackgroundRef ColorBackground::New(Args&&... args) ColorBackgroundRef ColorBackground::New(Args&&... args)
{ {

View File

@ -27,23 +27,28 @@
#ifndef NAZARA_CONFIG_GRAPHICS_HPP #ifndef NAZARA_CONFIG_GRAPHICS_HPP
#define NAZARA_CONFIG_GRAPHICS_HPP #define NAZARA_CONFIG_GRAPHICS_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci /*!
* \defgroup graphics (NazaraGraphics) Graphics module
* Graphics/System module including classes to handle graphical elements...
*/
// À partir de combien d'instances d'un même mesh/matériau l'instancing doit-il être utilisé ? /// Each modification of a paramater of the module needs a recompilation of the unit
// How much instances are need of a same mesh/material to enable instancing ?
#define NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT 10 #define NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT 10
// Utilise un manager de mémoire pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes) // Use the MemoryManager to manage dynamic allocations (can detect memory leak but allocations/frees are slower)
#define NAZARA_GRAPHICS_MANAGE_MEMORY 0 #define NAZARA_GRAPHICS_MANAGE_MEMORY 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement) // Activate the security tests based on the code (Advised for development)
#define NAZARA_GRAPHICS_SAFE 1 #define NAZARA_GRAPHICS_SAFE 1
/// Chaque modification d'un paramètre ci-dessous implique une modification (souvent mineure) du code /// Each modification of a parameter following implies a modification (often minor) of the code
// Le nombre maximum de lumières qu'un shader standard supportera // The maximum number of lights in a standard shader
#define NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS 3 #define NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS 3
/// Vérification des valeurs et types de certaines constantes /// Checking the values and types of certain constants
#include <Nazara/Graphics/ConfigCheck.hpp> #include <Nazara/Graphics/ConfigCheck.hpp>
#if defined(NAZARA_STATIC) #if defined(NAZARA_STATIC)

View File

@ -7,12 +7,12 @@
#ifndef NAZARA_CONFIG_CHECK_GRAPHICS_HPP #ifndef NAZARA_CONFIG_CHECK_GRAPHICS_HPP
#define NAZARA_CONFIG_CHECK_GRAPHICS_HPP #define NAZARA_CONFIG_CHECK_GRAPHICS_HPP
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp /// This file is used to check the constant values defined in Config.hpp
#include <type_traits> #include <type_traits>
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err) #define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
// On force la valeur de MANAGE_MEMORY en mode debug // We fore the value of MANAGE_MEMORY in debug
#if defined(NAZARA_DEBUG) && !NAZARA_GRAPHICS_MANAGE_MEMORY #if defined(NAZARA_DEBUG) && !NAZARA_GRAPHICS_MANAGE_MEMORY
#undef NAZARA_GRAPHICS_MANAGE_MEMORY #undef NAZARA_GRAPHICS_MANAGE_MEMORY
#define NAZARA_GRAPHICS_MANAGE_MEMORY 0 #define NAZARA_GRAPHICS_MANAGE_MEMORY 0

View File

@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine - Graphics module" // This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp // We suppose that Debug.hpp is already included, same goes for Config.hpp
#if NAZARA_GRAPHICS_MANAGE_MEMORY #if NAZARA_GRAPHICS_MANAGE_MEMORY
#undef delete #undef delete
#undef new #undef new

View File

@ -29,7 +29,7 @@ namespace Nz
float GetBrightThreshold() const; float GetBrightThreshold() const;
Texture* GetTexture(unsigned int i) const; Texture* GetTexture(unsigned int i) const;
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const; bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
bool Resize(const Vector2ui& dimensions); bool Resize(const Vector2ui& dimensions);
void SetBlurPassCount(unsigned int passCount); void SetBlurPassCount(unsigned int passCount);

View File

@ -23,7 +23,7 @@ namespace Nz
DeferredDOFPass(); DeferredDOFPass();
virtual ~DeferredDOFPass(); virtual ~DeferredDOFPass();
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const; bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
bool Resize(const Vector2ui& dimensions); bool Resize(const Vector2ui& dimensions);
protected: protected:

View File

@ -21,7 +21,7 @@ namespace Nz
DeferredFXAAPass(); DeferredFXAAPass();
virtual ~DeferredFXAAPass(); virtual ~DeferredFXAAPass();
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const; bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
protected: protected:
RenderStates m_states; RenderStates m_states;

View File

@ -21,7 +21,7 @@ namespace Nz
DeferredFinalPass(); DeferredFinalPass();
virtual ~DeferredFinalPass(); virtual ~DeferredFinalPass();
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const; bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
protected: protected:
RenderStates m_states; RenderStates m_states;

View File

@ -21,7 +21,7 @@ namespace Nz
DeferredFogPass(); DeferredFogPass();
virtual ~DeferredFogPass(); virtual ~DeferredFogPass();
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const; bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
protected: protected:
RenderStates m_states; RenderStates m_states;

View File

@ -21,7 +21,7 @@ namespace Nz
virtual ~DeferredForwardPass(); virtual ~DeferredForwardPass();
void Initialize(DeferredRenderTechnique* technique); void Initialize(DeferredRenderTechnique* technique);
bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned sceneTexture) const; bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned int sceneTexture) const;
protected: protected:
const ForwardRenderTechnique* m_forwardTechnique; const ForwardRenderTechnique* m_forwardTechnique;

View File

@ -21,7 +21,7 @@ namespace Nz
DeferredGeometryPass(); DeferredGeometryPass();
virtual ~DeferredGeometryPass(); virtual ~DeferredGeometryPass();
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const; bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
bool Resize(const Vector2ui& dimensions); bool Resize(const Vector2ui& dimensions);
protected: protected:

View File

@ -28,7 +28,7 @@ namespace Nz
bool IsLightMeshesDrawingEnabled() const; bool IsLightMeshesDrawingEnabled() const;
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const; bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
protected: protected:
LightUniforms m_directionalLightUniforms; LightUniforms m_directionalLightUniforms;

View File

@ -38,7 +38,7 @@ namespace Nz
bool IsEnabled() const; bool IsEnabled() const;
virtual bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned sceneTexture) const = 0; virtual bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned int sceneTexture) const = 0;
virtual bool Resize(const Vector2ui& GBufferSize); virtual bool Resize(const Vector2ui& GBufferSize);
DeferredRenderPass& operator=(const DeferredRenderPass&) = delete; DeferredRenderPass& operator=(const DeferredRenderPass&) = delete;

View File

@ -67,7 +67,7 @@ namespace Nz
}; };
std::map<RenderPassType, std::map<int, std::unique_ptr<DeferredRenderPass>>, RenderPassComparator> m_passes; std::map<RenderPassType, std::map<int, std::unique_ptr<DeferredRenderPass>>, RenderPassComparator> m_passes;
ForwardRenderTechnique m_forwardTechnique; // Doit être initialisé avant la RenderQueue ForwardRenderTechnique m_forwardTechnique; // Must be initialized before the RenderQueue
DeferredRenderQueue m_renderQueue; DeferredRenderQueue m_renderQueue;
mutable RenderBufferRef m_depthStencilBuffer; mutable RenderBufferRef m_depthStencilBuffer;
mutable RenderTexture m_GBufferRTT; mutable RenderTexture m_GBufferRTT;

View File

@ -6,6 +6,14 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Checks whether the material is suitable to fit in the render queue
* \return true If it is the case
*
* \param material Material to verify
*/
bool DepthRenderQueue::IsMaterialSuitable(const Material* material) const bool DepthRenderQueue::IsMaterialSuitable(const Material* material) const
{ {
NazaraAssert(material, "Invalid material"); NazaraAssert(material, "Invalid material");

View File

@ -128,7 +128,7 @@ namespace Nz
SceneNodeType_Max = SceneNodeType_User SceneNodeType_Max = SceneNodeType_User
}; };
// Ces paramètres sont indépendants du matériau: ils peuvent être demandés à tout moment // These parameters are independant of the material: they can not be asked for the moment
enum ShaderFlags enum ShaderFlags
{ {
ShaderFlags_None = 0, ShaderFlags_None = 0,
@ -139,7 +139,7 @@ namespace Nz
ShaderFlags_TextureOverlay = 0x08, ShaderFlags_TextureOverlay = 0x08,
ShaderFlags_VertexColor = 0x10, ShaderFlags_VertexColor = 0x10,
ShaderFlags_Max = ShaderFlags_VertexColor*2-1 ShaderFlags_Max = ShaderFlags_VertexColor * 2 - 1
}; };
} }

View File

@ -159,6 +159,7 @@ namespace Nz
std::map<int, Layer> layers; std::map<int, Layer> layers;
private: private:
BillboardData* GetBillboardData(int renderOrder, const Material* material, unsigned int count);
Layer& GetLayer(int i); ///TODO: Inline Layer& GetLayer(int i); ///TODO: Inline
void OnIndexBufferInvalidation(const IndexBuffer* indexBuffer); void OnIndexBufferInvalidation(const IndexBuffer* indexBuffer);

View File

@ -31,7 +31,7 @@ namespace Nz
AbstractRenderQueue* GetRenderQueue() override; AbstractRenderQueue* GetRenderQueue() override;
RenderTechniqueType GetType() const override; RenderTechniqueType GetType() const override;
void SetMaxLightPassPerObject(unsigned int passCount); void SetMaxLightPassPerObject(unsigned int maxLightPassPerObject);
static bool Initialize(); static bool Initialize();
static void Uninitialize(); static void Uninitialize();
@ -70,11 +70,11 @@ namespace Nz
LightUniforms lightUniforms; LightUniforms lightUniforms;
bool hasLightUniforms; bool hasLightUniforms;
/// Moins coûteux en mémoire que de stocker un LightUniforms par index de lumière, /// Less costly in memory than storing a LightUniforms by index of light,
/// à voir si ça fonctionne chez tout le monde /// this may not work everywhere
int lightOffset; // "Distance" entre Lights[0].type et Lights[1].type int lightOffset; // "Distance" between Lights[0].type and Lights[1].type
// Autre uniformes // Other uniforms
int eyePosition; int eyePosition;
int sceneAmbient; int sceneAmbient;
int textureOverlay; int textureOverlay;

View File

@ -6,6 +6,16 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Sens the uniforms for light
*
* \param shader Shader to send uniforms to
* \param uniforms Uniforms to send
* \param index Index of the light
* \param uniformOffset Offset for the uniform
* \param availableTextureUnit Unit texture available
*/
inline void ForwardRenderTechnique::SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int uniformOffset, UInt8 availableTextureUnit) const inline void ForwardRenderTechnique::SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int uniformOffset, UInt8 availableTextureUnit) const
{ {
// If anyone got a better idea.. // If anyone got a better idea..
@ -104,6 +114,14 @@ namespace Nz
} }
} }
/*!
* \brief Computes the score for directional light
* \return 0.f
*
* \param object Sphere symbolising the object
* \param light Light to compute
*/
inline float ForwardRenderTechnique::ComputeDirectionalLightScore(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light) inline float ForwardRenderTechnique::ComputeDirectionalLightScore(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light)
{ {
NazaraUnused(object); NazaraUnused(object);
@ -113,18 +131,42 @@ namespace Nz
return 0.f; return 0.f;
} }
/*!
* \brief Computes the score for point light
* \return Distance to the light
*
* \param object Sphere symbolising the object
* \param light Light to compute
*/
inline float ForwardRenderTechnique::ComputePointLightScore(const Spheref& object, const AbstractRenderQueue::PointLight& light) inline float ForwardRenderTechnique::ComputePointLightScore(const Spheref& object, const AbstractRenderQueue::PointLight& light)
{ {
///TODO: Compute a score depending on the light luminosity ///TODO: Compute a score depending on the light luminosity
return object.SquaredDistance(light.position); return object.SquaredDistance(light.position);
} }
/*!
* \brief Computes the score for spot light
* \return Distance to the light
*
* \param object Sphere symbolising the object
* \param light Light to compute
*/
inline float ForwardRenderTechnique::ComputeSpotLightScore(const Spheref& object, const AbstractRenderQueue::SpotLight& light) inline float ForwardRenderTechnique::ComputeSpotLightScore(const Spheref& object, const AbstractRenderQueue::SpotLight& light)
{ {
///TODO: Compute a score depending on the light luminosity and spot direction ///TODO: Compute a score depending on the light luminosity and spot direction
return object.SquaredDistance(light.position); return object.SquaredDistance(light.position);
} }
/*!
* \brief Checks whether the directional light is suitable for the computations
* \return true if light is enoughly close
*
* \param object Sphere symbolising the object
* \param light Light to compute
*/
inline bool ForwardRenderTechnique::IsDirectionalLightSuitable(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light) inline bool ForwardRenderTechnique::IsDirectionalLightSuitable(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light)
{ {
NazaraUnused(object); NazaraUnused(object);
@ -134,12 +176,28 @@ namespace Nz
return true; return true;
} }
/*!
* \brief Checks whether the point light is suitable for the computations
* \return true if light is enoughly close
*
* \param object Sphere symbolising the object
* \param light Light to compute
*/
inline bool ForwardRenderTechnique::IsPointLightSuitable(const Spheref& object, const AbstractRenderQueue::PointLight& light) inline bool ForwardRenderTechnique::IsPointLightSuitable(const Spheref& object, const AbstractRenderQueue::PointLight& light)
{ {
// If the object is too far away from this point light, there is not way it could light it // If the object is too far away from this point light, there is not way it could light it
return object.SquaredDistance(light.position) <= light.radius * light.radius; return object.SquaredDistance(light.position) <= light.radius * light.radius;
} }
/*!
* \brief Checks whether the spot light is suitable for the computations
* \return true if light is enoughly close
*
* \param object Sphere symbolising the object
* \param light Light to compute
*/
inline bool ForwardRenderTechnique::IsSpotLightSuitable(const Spheref& object, const AbstractRenderQueue::SpotLight& light) inline bool ForwardRenderTechnique::IsSpotLightSuitable(const Spheref& object, const AbstractRenderQueue::SpotLight& light)
{ {
///TODO: Exclude spot lights based on their direction and outer angle? ///TODO: Exclude spot lights based on their direction and outer angle?

View File

@ -4,6 +4,12 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a InstancedRenderable object by assignation
*
* \param renderable InstancedRenderable to copy into this
*/
inline InstancedRenderable::InstancedRenderable(const InstancedRenderable& renderable) : inline InstancedRenderable::InstancedRenderable(const InstancedRenderable& renderable) :
RefCounted(), RefCounted(),
m_boundingVolume(renderable.m_boundingVolume), m_boundingVolume(renderable.m_boundingVolume),
@ -11,22 +17,43 @@ namespace Nz
{ {
} }
/*!
* \brief Ensures that the bounding volume is up to date
*/
inline void InstancedRenderable::EnsureBoundingVolumeUpdated() const inline void InstancedRenderable::EnsureBoundingVolumeUpdated() const
{ {
if (!m_boundingVolumeUpdated) if (!m_boundingVolumeUpdated)
UpdateBoundingVolume(); UpdateBoundingVolume();
} }
/*!
* \brief Invalidates the bounding volume
*/
inline void InstancedRenderable::InvalidateBoundingVolume() inline void InstancedRenderable::InvalidateBoundingVolume()
{ {
m_boundingVolumeUpdated = false; m_boundingVolumeUpdated = false;
} }
/*!
* \brief Invalidates the instance data based on flags
*
* \param flags Flags to invalidate
*/
inline void InstancedRenderable::InvalidateInstanceData(UInt32 flags) inline void InstancedRenderable::InvalidateInstanceData(UInt32 flags)
{ {
OnInstancedRenderableInvalidateData(this, flags); OnInstancedRenderableInvalidateData(this, flags);
} }
/*!
* \brief Sets the current instanced renderable with the content of the other one
* \return A reference to this
*
* \param renderable The other InstancedRenderable
*/
inline InstancedRenderable& InstancedRenderable::operator=(const InstancedRenderable& renderable) inline InstancedRenderable& InstancedRenderable::operator=(const InstancedRenderable& renderable)
{ {
m_boundingVolume = renderable.m_boundingVolume; m_boundingVolume = renderable.m_boundingVolume;
@ -35,6 +62,10 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Updates the bounding volume
*/
inline void InstancedRenderable::UpdateBoundingVolume() const inline void InstancedRenderable::UpdateBoundingVolume() const
{ {
MakeBoundingVolume(); MakeBoundingVolume();

View File

@ -7,6 +7,10 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a Light object by default
*/
inline Light::Light(const Light& light) : inline Light::Light(const Light& light) :
Renderable(light), Renderable(light),
m_color(light.m_color), m_color(light.m_color),
@ -28,6 +32,12 @@ namespace Nz
{ {
} }
/*!
* \brief Enables shadow casting
*
* \param castShadows Should shadows be cast
*/
inline void Light::EnableShadowCasting(bool castShadows) inline void Light::EnableShadowCasting(bool castShadows)
{ {
if (m_shadowCastingEnabled != castShadows) if (m_shadowCastingEnabled != castShadows)
@ -37,72 +47,141 @@ namespace Nz
} }
} }
/*!
* \brief Ensures that the shadow map is up to date
*/
inline void Light::EnsureShadowMapUpdate() const inline void Light::EnsureShadowMapUpdate() const
{ {
if (!m_shadowMapUpdated) if (!m_shadowMapUpdated)
UpdateShadowMap(); UpdateShadowMap();
} }
/*!
* \brief Gets the ambient factor
* \return Current ambient factor
*/
inline float Light::GetAmbientFactor() const inline float Light::GetAmbientFactor() const
{ {
return m_ambientFactor; return m_ambientFactor;
} }
/*!
* \brief Gets the light attenuation (in 1 / R^2)
* \return Attenuation
*/
inline float Light::GetAttenuation() const inline float Light::GetAttenuation() const
{ {
return m_attenuation; return m_attenuation;
} }
/*!
* \brief Gets the color of the light
* \return Light color
*/
inline Color Light::GetColor() const inline Color Light::GetColor() const
{ {
return m_color; return m_color;
} }
/*!
* \brief Gets the diffuse factor
* \return Current diffuse factor
*/
inline float Light::GetDiffuseFactor() const inline float Light::GetDiffuseFactor() const
{ {
return m_diffuseFactor; return m_diffuseFactor;
} }
/*!
* \brief Gets the inner angle in spot light
* \return Inner angle
*/
inline float Light::GetInnerAngle() const inline float Light::GetInnerAngle() const
{ {
return m_innerAngle; return m_innerAngle;
} }
/*!
* \brief Gets the cosine inner angle in spot light
* \return Cosine inner angle
*/
inline float Light::GetInnerAngleCosine() const inline float Light::GetInnerAngleCosine() const
{ {
return m_innerAngleCosine; return m_innerAngleCosine;
} }
/*!
* \brief Gets the inverse of the radius
* \return Inverse of the radius
*/
inline float Light::GetInvRadius() const inline float Light::GetInvRadius() const
{ {
return m_invRadius; return m_invRadius;
} }
/*!
* \brief Gets the type of the light
* \return Light type
*/
inline LightType Light::GetLightType() const inline LightType Light::GetLightType() const
{ {
return m_type; return m_type;
} }
/*!
* \brief Gets the outer angle in spot light
* \return Outer angle
*/
inline float Light::GetOuterAngle() const inline float Light::GetOuterAngle() const
{ {
return m_outerAngle; return m_outerAngle;
} }
/*!
* \brief Gets the cosine outer angle in spot light
* \return Cosine outer angle
*/
inline float Light::GetOuterAngleCosine() const inline float Light::GetOuterAngleCosine() const
{ {
return m_outerAngleCosine; return m_outerAngleCosine;
} }
/*!
* \brief Gets the tangent outer angle in spot light
* \return Tangent outer angle
*/
inline float Light::GetOuterAngleTangent() const inline float Light::GetOuterAngleTangent() const
{ {
return m_outerAngleTangent; return m_outerAngleTangent;
} }
/*!
* \brief Gets the radius of the light
* \return Light radius
*/
inline float Light::GetRadius() const inline float Light::GetRadius() const
{ {
return m_radius; return m_radius;
} }
/*!
* \brief Gets the shadow map
* \return Reference to the shadow map texture
*/
inline TextureRef Light::GetShadowMap() const inline TextureRef Light::GetShadowMap() const
{ {
EnsureShadowMapUpdate(); EnsureShadowMapUpdate();
@ -110,47 +189,97 @@ namespace Nz
return m_shadowMap; return m_shadowMap;
} }
/*!
* \brief Gets the format of the shadow map
* \return Shadow map format
*/
inline PixelFormatType Light::GetShadowMapFormat() const inline PixelFormatType Light::GetShadowMapFormat() const
{ {
return m_shadowMapFormat; return m_shadowMapFormat;
} }
/*!
* \brief Gets the size of the shadow map
* \return Shadow map size
*/
inline const Vector2ui& Light::GetShadowMapSize() const inline const Vector2ui& Light::GetShadowMapSize() const
{ {
return m_shadowMapSize; return m_shadowMapSize;
} }
/*!
* \brief Checks whether the shadow casting is enabled
* \return true If it is the case
*/
inline bool Light::IsShadowCastingEnabled() const inline bool Light::IsShadowCastingEnabled() const
{ {
return m_shadowCastingEnabled; return m_shadowCastingEnabled;
} }
/*!
* \brief Sets the ambient factor
*
* \param factor Ambient factor
*/
inline void Light::SetAmbientFactor(float factor) inline void Light::SetAmbientFactor(float factor)
{ {
m_ambientFactor = factor; m_ambientFactor = factor;
} }
/*!
* \brief Sets the light attenuation (in 1 / R^2)
*
* \param attenuation Light attenuation
*/
inline void Light::SetAttenuation(float attenuation) inline void Light::SetAttenuation(float attenuation)
{ {
m_attenuation = attenuation; m_attenuation = attenuation;
} }
/*!
* \brief Sets the color of the light
*
* \param color Light color
*/
inline void Light::SetColor(const Color& color) inline void Light::SetColor(const Color& color)
{ {
m_color = color; m_color = color;
} }
/*!
* \brief Sets the diffuse factor
*
* \param factor Diffuse factor
*/
inline void Light::SetDiffuseFactor(float factor) inline void Light::SetDiffuseFactor(float factor)
{ {
m_diffuseFactor = factor; m_diffuseFactor = factor;
} }
/*!
* \brief Sets the inner angle in spot light
* \return innerAngle Inner angle
*/
inline void Light::SetInnerAngle(float innerAngle) inline void Light::SetInnerAngle(float innerAngle)
{ {
m_innerAngle = innerAngle; m_innerAngle = innerAngle;
m_innerAngleCosine = std::cos(DegreeToRadian(m_innerAngle)); m_innerAngleCosine = std::cos(DegreeToRadian(m_innerAngle));
} }
/*!
* \brief Sets the type of light
*
* \param type Light type
*/
inline void Light::SetLightType(LightType type) inline void Light::SetLightType(LightType type)
{ {
m_type = type; m_type = type;
@ -158,6 +287,13 @@ namespace Nz
InvalidateShadowMap(); InvalidateShadowMap();
} }
/*!
* \brief Sets the outer angle in spot light
* \return outerAngle Outer angle
*
* \remark Invalidates the bounding volume
*/
inline void Light::SetOuterAngle(float outerAngle) inline void Light::SetOuterAngle(float outerAngle)
{ {
m_outerAngle = outerAngle; m_outerAngle = outerAngle;
@ -167,6 +303,13 @@ namespace Nz
InvalidateBoundingVolume(); InvalidateBoundingVolume();
} }
/*!
* \brief Sets the radius of the light
* \return radius Light radius
*
* \remark Invalidates the bounding volume
*/
inline void Light::SetRadius(float radius) inline void Light::SetRadius(float radius)
{ {
m_radius = radius; m_radius = radius;
@ -176,6 +319,15 @@ namespace Nz
InvalidateBoundingVolume(); InvalidateBoundingVolume();
} }
/*!
* \brief Sets the shadow map format
*
* \param shadowFormat Shadow map format
*
* \remark Invalidates the shadow map
* \remark Produces a NazaraAssert if format is not a depth type
*/
inline void Light::SetShadowMapFormat(PixelFormatType shadowFormat) inline void Light::SetShadowMapFormat(PixelFormatType shadowFormat)
{ {
NazaraAssert(PixelFormat::GetContent(shadowFormat) == PixelFormatContent_DepthStencil, "Shadow format type is not a depth format"); NazaraAssert(PixelFormat::GetContent(shadowFormat) == PixelFormatContent_DepthStencil, "Shadow format type is not a depth format");
@ -185,6 +337,15 @@ namespace Nz
InvalidateShadowMap(); InvalidateShadowMap();
} }
/*!
* \brief Sets the size of the shadow map
*
* \param size Shadow map size
*
* \remark Invalidates the shadow map
* \remark Produces a NazaraAssert if size is zero
*/
inline void Light::SetShadowMapSize(const Vector2ui& size) inline void Light::SetShadowMapSize(const Vector2ui& size)
{ {
NazaraAssert(size.x > 0 && size.y > 0, "Shadow map size must have a positive size"); NazaraAssert(size.x > 0 && size.y > 0, "Shadow map size must have a positive size");
@ -194,6 +355,15 @@ namespace Nz
InvalidateShadowMap(); InvalidateShadowMap();
} }
/*!
* \brief Sets the current light with the content of the other one
* \return A reference to this
*
* \param light The other Light
*
* \remark Invalidates the shadow map
*/
inline Light& Light::operator=(const Light& light) inline Light& Light::operator=(const Light& light)
{ {
Renderable::operator=(light); Renderable::operator=(light);
@ -218,6 +388,10 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Invalidates the shadow map
*/
inline void Light::InvalidateShadowMap() inline void Light::InvalidateShadowMap()
{ {
m_shadowMapUpdated = false; m_shadowMapUpdated = false;

View File

@ -151,7 +151,7 @@ namespace Nz
inline Material& operator=(const Material& material); inline Material& operator=(const Material& material);
static MaterialRef GetDefault(); inline static MaterialRef GetDefault();
template<typename... Args> static MaterialRef New(Args&&... args); template<typename... Args> static MaterialRef New(Args&&... args);
// Signals: // Signals:
@ -163,7 +163,7 @@ namespace Nz
{ {
const Shader* shader; const Shader* shader;
UberShaderInstance* uberInstance = nullptr; UberShaderInstance* uberInstance = nullptr;
int uniforms[MaterialUniform_Max+1]; int uniforms[MaterialUniform_Max + 1];
}; };
void Copy(const Material& material); void Copy(const Material& material);
@ -187,7 +187,7 @@ namespace Nz
TextureRef m_normalMap; TextureRef m_normalMap;
TextureRef m_specularMap; TextureRef m_specularMap;
UberShaderConstRef m_uberShader; UberShaderConstRef m_uberShader;
mutable ShaderInstance m_shaders[ShaderFlags_Max+1]; mutable ShaderInstance m_shaders[ShaderFlags_Max + 1];
bool m_alphaTestEnabled; bool m_alphaTestEnabled;
bool m_depthSortingEnabled; bool m_depthSortingEnabled;
bool m_lightingEnabled; bool m_lightingEnabled;

File diff suppressed because it is too large Load Diff

View File

@ -68,8 +68,6 @@ namespace Nz
bool SetMaterial(unsigned int skinIndex, const String& subMeshName, Material* material); bool SetMaterial(unsigned int skinIndex, const String& subMeshName, Material* material);
void SetMaterial(unsigned int skinIndex, unsigned int matIndex, Material* material); void SetMaterial(unsigned int skinIndex, unsigned int matIndex, Material* material);
virtual void SetMesh(Mesh* mesh); virtual void SetMesh(Mesh* mesh);
bool SetSequence(const String& sequenceName);
void SetSequence(unsigned int sequenceIndex);
void SetSkin(unsigned int skin); void SetSkin(unsigned int skin);
void SetSkinCount(unsigned int skinCount); void SetSkinCount(unsigned int skinCount);

View File

@ -7,6 +7,13 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Creates a new Model from the arguments
* \return A reference to the newly created model
*
* \param args Arguments for the model
*/
template<typename... Args> template<typename... Args>
ModelRef Model::New(Args&&... args) ModelRef Model::New(Args&&... args)
{ {

View File

@ -62,16 +62,16 @@ namespace Nz
/* /*
** -Lynix: ** -Lynix:
** Il serait aussi possible de préciser le stride de façon indépendante, ce que je ne permets pas ** It would be also possible to precise the stride by an independant way, what I don't allow
** pour décomplexifier l'interface en enlevant quelque chose que je juge inutile. ** to decomplexify the interface of something I consider useless.
** Si vous pensez que ça peut être utile, n'hésitez pas à me le faire savoir ! ** If you think that could be useful, don't hesitate to make me aware !
*/ */
}; };
Component m_components[ParticleComponent_Max+1]; Component m_components[ParticleComponent_Max + 1];
unsigned int m_stride; unsigned int m_stride;
static ParticleDeclaration s_declarations[ParticleLayout_Max+1]; static ParticleDeclaration s_declarations[ParticleLayout_Max + 1];
static ParticleDeclarationLibrary::LibraryMap s_library; static ParticleDeclarationLibrary::LibraryMap s_library;
}; };
} }

View File

@ -7,10 +7,20 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Gets a pointer to iterate through same components
* \return SparsePtr pointing to same components
*
* \param component Component to get in the declaration
*
* \remark The same components are not continguous but separated by sizeof(ParticleSize)
* \remark Produces a NazaraError if component is disabled
*/
template <typename T> template <typename T>
SparsePtr<T> ParticleMapper::GetComponentPtr(ParticleComponent component) SparsePtr<T> ParticleMapper::GetComponentPtr(ParticleComponent component)
{ {
// Ensuite le composant qui nous intéresse // Then the component that are interesting
bool enabled; bool enabled;
ComponentType type; ComponentType type;
unsigned int offset; unsigned int offset;
@ -18,7 +28,7 @@ namespace Nz
if (enabled) if (enabled)
{ {
///TODO: Vérifier le rapport entre le type de l'attribut et le type template ? ///TODO: Check the ratio between the type of the attribute and the template type ?
return SparsePtr<T>(m_ptr + offset, m_declaration->GetStride()); return SparsePtr<T>(m_ptr + offset, m_declaration->GetStride());
} }
else else
@ -28,10 +38,20 @@ namespace Nz
} }
} }
/*!
* \brief Gets a pointer to iterate through same components
* \return SparsePtr pointing to same components
*
* \param component Component to get in the declaration
*
* \remark The same components are not continguous but separated by sizeof(ParticleSize)
* \remark Produces a NazaraError if component is disabled
*/
template <typename T> template <typename T>
SparsePtr<const T> ParticleMapper::GetComponentPtr(ParticleComponent component) const SparsePtr<const T> ParticleMapper::GetComponentPtr(ParticleComponent component) const
{ {
// Ensuite le composant qui nous intéresse // Then the component that are interesting
bool enabled; bool enabled;
ComponentType type; ComponentType type;
unsigned int offset; unsigned int offset;
@ -39,7 +59,7 @@ namespace Nz
if (enabled) if (enabled)
{ {
///TODO: Vérifier le rapport entre le type de l'attribut et le type template ? ///TODO: Check the ratio between the type of the attribute and the template type ?
return SparsePtr<const T>(m_ptr + offset, m_declaration->GetStride()); return SparsePtr<const T>(m_ptr + offset, m_declaration->GetStride());
} }
else else

View File

@ -4,17 +4,31 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Ensures that the bounding volume is up to date
*/
inline void Renderable::EnsureBoundingVolumeUpdated() const inline void Renderable::EnsureBoundingVolumeUpdated() const
{ {
if (!m_boundingVolumeUpdated) if (!m_boundingVolumeUpdated)
UpdateBoundingVolume(); UpdateBoundingVolume();
} }
/*!
* \brief Invalidates the bounding volume
*/
inline void Renderable::InvalidateBoundingVolume() inline void Renderable::InvalidateBoundingVolume()
{ {
m_boundingVolumeUpdated = false; m_boundingVolumeUpdated = false;
} }
/*!
* \brief Updates the bounding volume by a matrix
*
* \param transformMatrix Matrix transformation for our bounding volume
*/
inline void Renderable::UpdateBoundingVolume() const inline void Renderable::UpdateBoundingVolume() const
{ {
MakeBoundingVolume(); MakeBoundingVolume();

View File

@ -7,31 +7,62 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Gets the movement offset
* \return Offset of the movement
*/
inline const Vector3f& Nz::SkyboxBackground::GetMovementOffset() const inline const Vector3f& Nz::SkyboxBackground::GetMovementOffset() const
{ {
return m_movementOffset; return m_movementOffset;
} }
/*!
* \brief Gets the movement scale
* \return Scale of the movement
*/
inline float SkyboxBackground::GetMovementScale() const inline float SkyboxBackground::GetMovementScale() const
{ {
return m_movementScale; return m_movementScale;
} }
/*!
* \brief Gets the texture of the background
* \return Texture of the background
*/
inline const TextureRef& SkyboxBackground::GetTexture() const inline const TextureRef& SkyboxBackground::GetTexture() const
{ {
return m_texture; return m_texture;
} }
/*!
* \brief Gets the texture sampler of the background
* \return A reference to the texture sampler of the background
*/
inline TextureSampler& SkyboxBackground::GetTextureSampler() inline TextureSampler& SkyboxBackground::GetTextureSampler()
{ {
return m_sampler; return m_sampler;
} }
/*!
* \brief Gets the texture sampler of the background
* \return A constant reference to the texture sampler of the background
*/
inline const TextureSampler& SkyboxBackground::GetTextureSampler() const inline const TextureSampler& SkyboxBackground::GetTextureSampler() const
{ {
return m_sampler; return m_sampler;
} }
/*!
* \brief Sets the movement offset
*
* \param offset Offset of the movement
*/
inline void SkyboxBackground::SetMovementOffset(const Vector3f& offset) inline void SkyboxBackground::SetMovementOffset(const Vector3f& offset)
{ {
NazaraAssert(std::isfinite(offset.x) && std::isfinite(offset.y) && std::isfinite(offset.z), "Offset must be a finite vector"); NazaraAssert(std::isfinite(offset.x) && std::isfinite(offset.y) && std::isfinite(offset.z), "Offset must be a finite vector");
@ -39,6 +70,12 @@ namespace Nz
m_movementOffset = offset; m_movementOffset = offset;
} }
/*!
* \brief Sets the movement scale
*
* \param scale Scale of the movement
*/
inline void SkyboxBackground::SetMovementScale(float scale) inline void SkyboxBackground::SetMovementScale(float scale)
{ {
NazaraAssert(std::isfinite(scale), "Scale must be a finite value"); NazaraAssert(std::isfinite(scale), "Scale must be a finite value");
@ -46,6 +83,12 @@ namespace Nz
m_movementScale = scale; m_movementScale = scale;
} }
/*!
* \brief Sets the texture of the background
*
* \param cubemapTexture Texture of the background
*/
inline void SkyboxBackground::SetTexture(TextureRef cubemapTexture) inline void SkyboxBackground::SetTexture(TextureRef cubemapTexture)
{ {
NazaraAssert(!cubemapTexture || cubemapTexture->IsValid(), "Invalid texture"); NazaraAssert(!cubemapTexture || cubemapTexture->IsValid(), "Invalid texture");
@ -54,11 +97,24 @@ namespace Nz
m_texture = std::move(cubemapTexture); m_texture = std::move(cubemapTexture);
} }
/*!
* \brief Sets the texture sampler of the background
*
* \param sampler Texture sampler of the background
*/
void SkyboxBackground::SetTextureSampler(const TextureSampler& sampler) void SkyboxBackground::SetTextureSampler(const TextureSampler& sampler)
{ {
m_sampler = sampler; m_sampler = sampler;
} }
/*!
* \brief Creates a new skybox background from the arguments
* \return A reference to the newly created skybox background
*
* \param args Arguments for the skybox background
*/
template<typename... Args> template<typename... Args>
SkyboxBackgroundRef SkyboxBackground::New(Args&&... args) SkyboxBackgroundRef SkyboxBackground::New(Args&&... args)
{ {

View File

@ -8,6 +8,10 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a Sprite object by default
*/
inline Sprite::Sprite() : inline Sprite::Sprite() :
m_color(Color::White), m_color(Color::White),
m_textureCoords(0.f, 0.f, 1.f, 1.f), m_textureCoords(0.f, 0.f, 1.f, 1.f),
@ -16,6 +20,12 @@ namespace Nz
SetDefaultMaterial(); SetDefaultMaterial();
} }
/*!
* \brief Constructs a Sprite object with a reference to a material
*
* \param material Reference to a material
*/
inline Sprite::Sprite(MaterialRef material) : inline Sprite::Sprite(MaterialRef material) :
m_color(Color::White), m_color(Color::White),
m_textureCoords(0.f, 0.f, 1.f, 1.f), m_textureCoords(0.f, 0.f, 1.f, 1.f),
@ -24,6 +34,12 @@ namespace Nz
SetMaterial(std::move(material), true); SetMaterial(std::move(material), true);
} }
/*!
* \brief Constructs a Sprite object with a pointer to a texture
*
* \param texture Pointer to a texture
*/
inline Sprite::Sprite(Texture* texture) : inline Sprite::Sprite(Texture* texture) :
m_color(Color::White), m_color(Color::White),
m_textureCoords(0.f, 0.f, 1.f, 1.f), m_textureCoords(0.f, 0.f, 1.f, 1.f),
@ -32,6 +48,12 @@ namespace Nz
SetTexture(texture, true); SetTexture(texture, true);
} }
/*!
* \brief Constructs a Sprite object by assignation
*
* \param sprite Sprite to copy into this
*/
inline Sprite::Sprite(const Sprite& sprite) : inline Sprite::Sprite(const Sprite& sprite) :
InstancedRenderable(sprite), InstancedRenderable(sprite),
m_color(sprite.m_color), m_color(sprite.m_color),
@ -41,26 +63,52 @@ namespace Nz
{ {
} }
/*!
* \brief Gets the color of the sprite
* \return Current color
*/
inline const Color& Sprite::GetColor() const inline const Color& Sprite::GetColor() const
{ {
return m_color; return m_color;
} }
/*!
* \brief Gets the material of the sprite
* \return Current material
*/
inline const MaterialRef& Sprite::GetMaterial() const inline const MaterialRef& Sprite::GetMaterial() const
{ {
return m_material; return m_material;
} }
/*!
* \brief Gets the size of the sprite
* \return Current size
*/
inline const Vector2f& Sprite::GetSize() const inline const Vector2f& Sprite::GetSize() const
{ {
return m_size; return m_size;
} }
/*!
* \brief Gets the texture coordinates of the sprite
* \return Current texture coordinates
*/
inline const Rectf& Sprite::GetTextureCoords() const inline const Rectf& Sprite::GetTextureCoords() const
{ {
return m_textureCoords; return m_textureCoords;
} }
/*!
* \brief Sets the color of the billboard
*
* \param color Color for the billboard
*/
inline void Sprite::SetColor(const Color& color) inline void Sprite::SetColor(const Color& color)
{ {
m_color = color; m_color = color;
@ -68,6 +116,10 @@ namespace Nz
InvalidateVertices(); InvalidateVertices();
} }
/*!
* \brief Sets the default material of the sprite (just default material)
*/
inline void Sprite::SetDefaultMaterial() inline void Sprite::SetDefaultMaterial()
{ {
MaterialRef material = Material::New(); MaterialRef material = Material::New();
@ -77,6 +129,13 @@ namespace Nz
SetMaterial(std::move(material)); SetMaterial(std::move(material));
} }
/*!
* \brief Sets the material of the sprite
*
* \param material Material for the sprite
* \param resizeSprite Should sprite be resized to the material size (diffuse map)
*/
inline void Sprite::SetMaterial(MaterialRef material, bool resizeSprite) inline void Sprite::SetMaterial(MaterialRef material, bool resizeSprite)
{ {
m_material = std::move(material); m_material = std::move(material);
@ -88,6 +147,12 @@ namespace Nz
} }
} }
/*!
* \brief Sets the size of the sprite
*
* \param size Size for the sprite
*/
inline void Sprite::SetSize(const Vector2f& size) inline void Sprite::SetSize(const Vector2f& size)
{ {
m_size = size; m_size = size;
@ -97,11 +162,25 @@ namespace Nz
InvalidateVertices(); InvalidateVertices();
} }
/*!
* \brief Sets the size of the sprite
*
* \param sizeX Size in X for the sprite
* \param sizeY Size in Y for the sprite
*/
inline void Sprite::SetSize(float sizeX, float sizeY) inline void Sprite::SetSize(float sizeX, float sizeY)
{ {
SetSize(Vector2f(sizeX, sizeY)); SetSize(Vector2f(sizeX, sizeY));
} }
/*!
* \brief Sets the texture of the sprite
*
* \param texture Texture for the sprite
* \param resizeSprite Should sprite be resized to the texture size
*/
inline void Sprite::SetTexture(TextureRef texture, bool resizeSprite) inline void Sprite::SetTexture(TextureRef texture, bool resizeSprite)
{ {
if (!m_material) if (!m_material)
@ -115,12 +194,27 @@ namespace Nz
m_material->SetDiffuseMap(std::move(texture)); m_material->SetDiffuseMap(std::move(texture));
} }
/*!
* \brief Sets the texture coordinates of the sprite
*
* \param coords Texture coordinates
*/
inline void Sprite::SetTextureCoords(const Rectf& coords) inline void Sprite::SetTextureCoords(const Rectf& coords)
{ {
m_textureCoords = coords; m_textureCoords = coords;
InvalidateVertices(); InvalidateVertices();
} }
/*!
* \brief Sets the texture rectangle of the sprite
*
* \param rect Rectangles symbolizing the size of the texture
*
* \remark Produces a NazaraAssert if material is invalid
* \remark Produces a NazaraAssert if material has no diffuse map
*/
inline void Sprite::SetTextureRect(const Rectui& rect) inline void Sprite::SetTextureRect(const Rectui& rect)
{ {
NazaraAssert(m_material, "Sprite has no material"); NazaraAssert(m_material, "Sprite has no material");
@ -128,12 +222,19 @@ namespace Nz
Texture* diffuseMap = m_material->GetDiffuseMap(); Texture* diffuseMap = m_material->GetDiffuseMap();
float invWidth = 1.f/diffuseMap->GetWidth(); float invWidth = 1.f / diffuseMap->GetWidth();
float invHeight = 1.f/diffuseMap->GetHeight(); float invHeight = 1.f / diffuseMap->GetHeight();
SetTextureCoords(Rectf(invWidth*rect.x, invHeight*rect.y, invWidth*rect.width, invHeight*rect.height)); SetTextureCoords(Rectf(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height));
} }
/*!
* \brief Sets the current sprite with the content of the other one
* \return A reference to this
*
* \param sprite The other Sprite
*/
inline Sprite& Sprite::operator=(const Sprite& sprite) inline Sprite& Sprite::operator=(const Sprite& sprite)
{ {
InstancedRenderable::operator=(sprite); InstancedRenderable::operator=(sprite);
@ -143,18 +244,29 @@ namespace Nz
m_textureCoords = sprite.m_textureCoords; m_textureCoords = sprite.m_textureCoords;
m_size = sprite.m_size; m_size = sprite.m_size;
// On ne copie pas les sommets finaux car il est très probable que nos paramètres soient modifiés et qu'ils doivent être régénérés de toute façon // We do not copy final vertices because it's highly probable that our parameters are modified and they must be regenerated
InvalidateBoundingVolume(); InvalidateBoundingVolume();
InvalidateVertices(); InvalidateVertices();
return *this; return *this;
} }
/*!
* \brief Invalidates the vertices
*/
inline void Sprite::InvalidateVertices() inline void Sprite::InvalidateVertices()
{ {
InvalidateInstanceData(0); InvalidateInstanceData(0);
} }
/*!
* \brief Creates a new sprite from the arguments
* \return A reference to the newly created sprite
*
* \param args Arguments for the sprite
*/
template<typename... Args> template<typename... Args>
SpriteRef Sprite::New(Args&&... args) SpriteRef Sprite::New(Args&&... args)
{ {

View File

@ -7,6 +7,10 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a TextSprite object by default
*/
inline TextSprite::TextSprite() : inline TextSprite::TextSprite() :
m_color(Color::White), m_color(Color::White),
m_scale(1.f) m_scale(1.f)
@ -14,12 +18,24 @@ namespace Nz
SetDefaultMaterial(); SetDefaultMaterial();
} }
/*!
* \brief Constructs a TextSprite object with a drawer
*
* \param drawer Drawer used to compose text on the sprite
*/
inline TextSprite::TextSprite(const AbstractTextDrawer& drawer) : inline TextSprite::TextSprite(const AbstractTextDrawer& drawer) :
TextSprite() TextSprite()
{ {
Update(drawer); Update(drawer);
} }
/*!
* \brief Constructs a TextSprite object by assignation
*
* \param sprite TextSprite to copy into this
*/
inline TextSprite::TextSprite(const TextSprite& sprite) : inline TextSprite::TextSprite(const TextSprite& sprite) :
InstancedRenderable(sprite), InstancedRenderable(sprite),
m_renderInfos(sprite.m_renderInfos), m_renderInfos(sprite.m_renderInfos),
@ -40,6 +56,10 @@ namespace Nz
} }
} }
/*!
* \brief Clears the data
*/
inline void TextSprite::Clear() inline void TextSprite::Clear()
{ {
m_atlases.clear(); m_atlases.clear();
@ -48,21 +68,42 @@ namespace Nz
m_renderInfos.clear(); m_renderInfos.clear();
} }
/*!
* \brief Gets the color of the text sprite
* \return Current color
*/
inline const Color& TextSprite::GetColor() const inline const Color& TextSprite::GetColor() const
{ {
return m_color; return m_color;
} }
/*!
* \brief Gets the material of the text sprite
* \return Current material
*/
inline const MaterialRef& TextSprite::GetMaterial() const inline const MaterialRef& TextSprite::GetMaterial() const
{ {
return m_material; return m_material;
} }
/*!
* \brief Gets the current scale of the text sprite
* \return Current scale
*/
inline float TextSprite::GetScale() const inline float TextSprite::GetScale() const
{ {
return m_scale; return m_scale;
} }
/*!
* \brief Sets the color of the text sprite
*
* \param color Color for the text sprite
*/
inline void TextSprite::SetColor(const Color& color) inline void TextSprite::SetColor(const Color& color)
{ {
m_color = color; m_color = color;
@ -70,6 +111,11 @@ namespace Nz
InvalidateVertices(); InvalidateVertices();
} }
/*!
* \brief Sets the default material of the text sprite (just default material)
*/
inline void TextSprite::SetDefaultMaterial() inline void TextSprite::SetDefaultMaterial()
{ {
MaterialRef material = Material::New(); MaterialRef material = Material::New();
@ -83,11 +129,23 @@ namespace Nz
SetMaterial(material); SetMaterial(material);
} }
/*!
* \brief Sets the material of the text sprite
*
* \param material Material for the text sprite
*/
inline void TextSprite::SetMaterial(MaterialRef material) inline void TextSprite::SetMaterial(MaterialRef material)
{ {
m_material = std::move(material); m_material = std::move(material);
} }
/*!
* \brief Sets the current scale of the text sprite
*
* \param scale Scale of the text sprite
*/
inline void TextSprite::SetScale(float scale) inline void TextSprite::SetScale(float scale)
{ {
m_scale = scale; m_scale = scale;
@ -95,10 +153,12 @@ namespace Nz
InvalidateVertices(); InvalidateVertices();
} }
inline void TextSprite::InvalidateVertices() /*!
{ * \brief Sets the current text sprite with the content of the other one
InvalidateInstanceData(0); * \return A reference to this
} *
* \param text sprite The other TextSprite
*/
inline TextSprite& TextSprite::operator=(const TextSprite& text) inline TextSprite& TextSprite::operator=(const TextSprite& text)
{ {
@ -130,6 +190,22 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Invalidates the vertices
*/
inline void TextSprite::InvalidateVertices()
{
InvalidateInstanceData(0);
}
/*!
* \brief Creates a new text sprite from the arguments
* \return A reference to the newly created text sprite
*
* \param args Arguments for the text sprite
*/
template<typename... Args> template<typename... Args>
TextSpriteRef TextSprite::New(Args&&... args) TextSpriteRef TextSprite::New(Args&&... args)
{ {

View File

@ -7,11 +7,22 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Gets the texture of the background
* \return Texture of the background
*/
inline const TextureRef& TextureBackground::GetTexture() const inline const TextureRef& TextureBackground::GetTexture() const
{ {
return m_texture; return m_texture;
} }
/*!
* \brief Sets the texture of the background
*
* \param texture Texture of the background
*/
inline void TextureBackground::SetTexture(TextureRef texture) inline void TextureBackground::SetTexture(TextureRef texture)
{ {
NazaraAssert(!texture || texture->IsValid(), "Invalid texture"); NazaraAssert(!texture || texture->IsValid(), "Invalid texture");
@ -19,6 +30,13 @@ namespace Nz
m_texture = std::move(texture); m_texture = std::move(texture);
} }
/*!
* \brief Creates a new texture background from the arguments
* \return A reference to the newly created texture background
*
* \param args Arguments for the texture background
*/
template<typename... Args> template<typename... Args>
TextureBackgroundRef TextureBackground::New(Args&&... args) TextureBackgroundRef TextureBackground::New(Args&&... args)
{ {

View File

@ -84,7 +84,7 @@ namespace Nz
bool Execute(const String& code); bool Execute(const String& code);
bool ExecuteFromFile(const String& filePath); bool ExecuteFromFile(const String& filePath);
bool ExecuteFromMemory(const void* data, unsigned int size); bool ExecuteFromMemory(const void* data, std::size_t size);
bool ExecuteFromStream(Stream& stream); bool ExecuteFromStream(Stream& stream);
int GetAbsIndex(int index) const; int GetAbsIndex(int index) const;
@ -142,10 +142,10 @@ namespace Nz
void PushNumber(double value) const; void PushNumber(double value) const;
void PushReference(int ref) const; void PushReference(int ref) const;
void PushString(const char* str) const; void PushString(const char* str) const;
void PushString(const char* str, unsigned int size) const; void PushString(const char* str, std::size_t size) const;
void PushString(const String& str) const; void PushString(const String& str) const;
void PushTable(unsigned int sequenceElementCount = 0, unsigned int arrayElementCount = 0) const; void PushTable(unsigned int sequenceElementCount = 0, unsigned int arrayElementCount = 0) const;
void* PushUserdata(unsigned int size) const; void* PushUserdata(std::size_t size) const;
void PushValue(int index) const; void PushValue(int index) const;
void Remove(int index) const; void Remove(int index) const;
@ -158,7 +158,7 @@ namespace Nz
void SetMetatable(const char* tname) const; void SetMetatable(const char* tname) const;
void SetMetatable(const String& tname) const; void SetMetatable(const String& tname) const;
void SetMetatable(int index) const; void SetMetatable(int index) const;
void SetMemoryLimit(UInt32 memoryLimit); void SetMemoryLimit(std::size_t memoryLimit);
void SetTable(int index = -3) const; void SetTable(int index = -3) const;
void SetTimeLimit(UInt32 timeLimit); void SetTimeLimit(UInt32 timeLimit);
@ -185,8 +185,8 @@ namespace Nz
static int ProxyFunc(lua_State* state); static int ProxyFunc(lua_State* state);
static void TimeLimiter(lua_State* state, lua_Debug* debug); static void TimeLimiter(lua_State* state, lua_Debug* debug);
UInt32 m_memoryLimit; std::size_t m_memoryLimit;
UInt32 m_memoryUsage; std::size_t m_memoryUsage;
UInt32 m_timeLimit; UInt32 m_timeLimit;
Clock m_clock; Clock m_clock;
String m_lastError; String m_lastError;

View File

@ -90,7 +90,7 @@ namespace Nz
// Appel de la fonction avec le nombre 32bits, si le résultat est non-nul nous avons la réponse // Appel de la fonction avec le nombre 32bits, si le résultat est non-nul nous avons la réponse
unsigned int log2 = IntegralLog2Pot<UInt32>(val); unsigned int log2 = IntegralLog2Pot<UInt32>(val);
if (log2) if (log2 || val == 1)
return log2 + i*8; return log2 + i*8;
} }

View File

@ -491,8 +491,8 @@ namespace Nz
* *
* \remark If volume is infinite, IntersectionSide_Intersecting is returned * \remark If volume is infinite, IntersectionSide_Intersecting is returned
* \remark If volume is null, IntersectionSide_Outside is returned * \remark If volume is null, IntersectionSide_Outside is returned
* \remark If enumeration of the volume is not defined in Extend, a NazaraError is thrown and false is returned * \remark If enumeration of the volume is not defined in Extend, a NazaraError is thrown and IntersectionSide_Outside is returned
* \remark If enumeration of the intersection is not defined in IntersectionSide, a NazaraError is thrown and false is returned. This should not never happen for a user of the library * \remark If enumeration of the intersection is not defined in IntersectionSide, a NazaraError is thrown and IntersectionSide_Outside is returned. This should not never happen for a user of the library
*/ */
template<typename T> template<typename T>

View File

@ -485,7 +485,7 @@ namespace Nz
template<typename T> template<typename T>
T Sphere<T>::SquaredDistance(const Vector3<T>& point) const T Sphere<T>::SquaredDistance(const Vector3<T>& point) const
{ {
return Vector3f::Distance(point, GetPosition()) - radius * radius; return Vector3f::SquaredDistance(point, GetPosition() + (point - GetPosition()).Normalize() * radius);
} }
/*! /*!

View File

@ -6,31 +6,62 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Gets the last error
* \return Socket error
*/
inline SocketError AbstractSocket::GetLastError() const inline SocketError AbstractSocket::GetLastError() const
{ {
return m_lastError; return m_lastError;
} }
/*!
* \brief Gets the internal socket handle
* \return Socket handle
*/
inline SocketHandle AbstractSocket::GetNativeHandle() const inline SocketHandle AbstractSocket::GetNativeHandle() const
{ {
return m_handle; return m_handle;
} }
/*!
* \brief Gets the internal state
* \return Socket state
*/
inline SocketState AbstractSocket::GetState() const inline SocketState AbstractSocket::GetState() const
{ {
return m_state; return m_state;
} }
/*!
* \brief Gets the internal type
* \return Socket type
*/
inline SocketType AbstractSocket::GetType() const inline SocketType AbstractSocket::GetType() const
{ {
return m_type; return m_type;
} }
/*!
* \brief Checks whether the blocking is enabled
* \return true If successful
*/
inline bool AbstractSocket::IsBlockingEnabled() const inline bool AbstractSocket::IsBlockingEnabled() const
{ {
return m_isBlockingEnabled; return m_isBlockingEnabled;
} }
/*!
* \brief Updates the state of the socket
*
* \param newState Next state for the socket
*/
inline void AbstractSocket::UpdateState(SocketState newState) inline void AbstractSocket::UpdateState(SocketState newState)
{ {
if (m_state != newState) if (m_state != newState)

View File

@ -27,17 +27,22 @@
#ifndef NAZARA_CONFIG_NETWORK_HPP #ifndef NAZARA_CONFIG_NETWORK_HPP
#define NAZARA_CONFIG_NETWORK_HPP #define NAZARA_CONFIG_NETWORK_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci /*!
* \defgroup network (NazaraNetwork) Network module
* Network/System module including classes to handle networking elements...
*/
// Utilise le MemoryManager pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes) /// Each modification of a paramater of the module needs a recompilation of the unit
// Use the MemoryManager to manage dynamic allocations (can detect memory leak but allocations/frees are slower)
#define NAZARA_NETWORK_MANAGE_MEMORY 0 #define NAZARA_NETWORK_MANAGE_MEMORY 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement) // Activate the security tests based on the code (Advised for development)
#define NAZARA_NETWORK_SAFE 1 #define NAZARA_NETWORK_SAFE 1
/// Chaque modification d'un paramètre ci-dessous implique une modification (souvent mineure) du code /// Each modification of a parameter following implies a modification (often minor) of the code
/// Vérification des valeurs et types de certaines constantes /// Checking the values and types of certain constants
#include <Nazara/Network/ConfigCheck.hpp> #include <Nazara/Network/ConfigCheck.hpp>
#if defined(NAZARA_STATIC) #if defined(NAZARA_STATIC)

View File

@ -7,11 +7,11 @@
#ifndef NAZARA_CONFIG_CHECK_NETWORK_HPP #ifndef NAZARA_CONFIG_CHECK_NETWORK_HPP
#define NAZARA_CONFIG_CHECK_NETWORK_HPP #define NAZARA_CONFIG_CHECK_NETWORK_HPP
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp /// This file is used to check the constant values defined in Config.hpp
#include <type_traits> #include <type_traits>
// On force la valeur de MANAGE_MEMORY en mode debug // We fore the value of MANAGE_MEMORY in debug
#if defined(NAZARA_DEBUG) && !NAZARA_NETWORK_MANAGE_MEMORY #if defined(NAZARA_DEBUG) && !NAZARA_NETWORK_MANAGE_MEMORY
#undef NAZARA_NETWORK_MANAGE_MEMORY #undef NAZARA_NETWORK_MANAGE_MEMORY
#define NAZARA_NETWORK_MANAGE_MEMORY 0 #define NAZARA_NETWORK_MANAGE_MEMORY 0

View File

@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine - Network module" // This file is part of the "Nazara Engine - Network module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp // We suppose that Debug.hpp is already included, same goes for Config.hpp
#if NAZARA_NETWORK_MANAGE_MEMORY #if NAZARA_NETWORK_MANAGE_MEMORY
#undef delete #undef delete
#undef new #undef new

View File

@ -9,11 +9,22 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a IpAddress object by default
*/
inline IpAddress::IpAddress() : inline IpAddress::IpAddress() :
m_isValid(false) m_isValid(false)
{ {
} }
/*!
* \brief Constructs a IpAddress object with an IP and a port
*
* \param ip IPv4 address
* \param port Port of the IP
*/
inline IpAddress::IpAddress(const IPv4& ip, UInt16 port) : inline IpAddress::IpAddress(const IPv4& ip, UInt16 port) :
m_ipv4(ip), m_ipv4(ip),
m_protocol(NetProtocol_IPv4), m_protocol(NetProtocol_IPv4),
@ -22,6 +33,13 @@ namespace Nz
{ {
} }
/*!
* \brief Constructs a IpAddress object with an IP and a port
*
* \param ip IPv6 address
* \param port Port of the IP
*/
inline IpAddress::IpAddress(const IPv6& ip, UInt16 port) : inline IpAddress::IpAddress(const IPv6& ip, UInt16 port) :
m_ipv6(ip), m_ipv6(ip),
m_protocol(NetProtocol_IPv6), m_protocol(NetProtocol_IPv6),
@ -30,46 +48,100 @@ namespace Nz
{ {
} }
/*!
* \brief Constructs a IpAddress object with an IP and a port
*
* \param ip IPv4 address (a.b.c.d)
* \param port Port of the IP
*/
inline IpAddress::IpAddress(const UInt8& a, const UInt8& b, const UInt8& c, const UInt8& d, UInt16 port) : inline IpAddress::IpAddress(const UInt8& a, const UInt8& b, const UInt8& c, const UInt8& d, UInt16 port) :
IpAddress(IPv4{a, b, c, d}, port) IpAddress(IPv4{a, b, c, d}, port)
{ {
} }
/*!
* \brief Constructs a IpAddress object with an IP and a port
*
* \param ip IPv6 address (a.b.c.d.e.f.g.h)
* \param port Port of the IP
*/
inline IpAddress::IpAddress(const UInt16& a, const UInt16& b, const UInt16& c, const UInt16& d, const UInt16& e, const UInt16& f, const UInt16& g, const UInt16& h, UInt16 port) : inline IpAddress::IpAddress(const UInt16& a, const UInt16& b, const UInt16& c, const UInt16& d, const UInt16& e, const UInt16& f, const UInt16& g, const UInt16& h, UInt16 port) :
IpAddress(IPv6{a, b, c, d, e, f, g, h}, port) IpAddress(IPv6{a, b, c, d, e, f, g, h}, port)
{ {
} }
/*!
* Constructs a IpAddress object with a C-string
*
* \param address Hostname or textual IP address
*/
inline IpAddress::IpAddress(const char* address) inline IpAddress::IpAddress(const char* address)
{ {
BuildFromAddress(address); BuildFromAddress(address);
} }
/*!
* Constructs a IpAddress object with a string
*
* \param address Hostname or textual IP address
*/
inline IpAddress::IpAddress(const String& address) inline IpAddress::IpAddress(const String& address)
{ {
BuildFromAddress(address.GetConstBuffer()); BuildFromAddress(address.GetConstBuffer());
} }
/*!
* \brief Gets the port
* \return Port attached to the IP address
*/
inline UInt16 IpAddress::GetPort() const inline UInt16 IpAddress::GetPort() const
{ {
return m_port; return m_port;
} }
/*!
* \brief Gets the net protocol
* \return Protocol attached to the IP address
*/
inline NetProtocol IpAddress::GetProtocol() const inline NetProtocol IpAddress::GetProtocol() const
{ {
return m_protocol; return m_protocol;
} }
/*!
* \brief Checks whether the IP address is valid
* \return true If successful
*/
inline bool IpAddress::IsValid() const inline bool IpAddress::IsValid() const
{ {
return m_isValid; return m_isValid;
} }
/*!
* \brief Sets the port
*
* \param port Port attached to the IP address
*/
inline void IpAddress::SetPort(UInt16 port) inline void IpAddress::SetPort(UInt16 port)
{ {
m_port = port; m_port = port;
} }
/*!
* \brief Converts IpAddress to IPv4
* \return Corresponding IPv4
*
* \remark Produces a NazaraAssert if net protocol is not IPv4
*/
inline IpAddress::IPv4 IpAddress::ToIPv4() const inline IpAddress::IPv4 IpAddress::ToIPv4() const
{ {
NazaraAssert(m_isValid && m_protocol == NetProtocol_IPv4, "Address is not a valid IPv4"); NazaraAssert(m_isValid && m_protocol == NetProtocol_IPv4, "Address is not a valid IPv4");
@ -77,6 +149,13 @@ namespace Nz
return m_ipv4; return m_ipv4;
} }
/*!
* \brief Converts IpAddress to IPv6
* \return Corresponding IPv6
*
* \remark Produces a NazaraAssert if net protocol is not IPv6
*/
inline IpAddress::IPv6 IpAddress::ToIPv6() const inline IpAddress::IPv6 IpAddress::ToIPv6() const
{ {
NazaraAssert(m_isValid && m_protocol == NetProtocol_IPv6, "IP is not a valid IPv6"); NazaraAssert(m_isValid && m_protocol == NetProtocol_IPv6, "IP is not a valid IPv6");
@ -84,6 +163,13 @@ namespace Nz
return m_ipv6; return m_ipv6;
} }
/*!
* \brief Converts IpAddress to UInt32
* \return Corresponding UInt32
*
* \remark Produces a NazaraAssert if net protocol is not IPv4
*/
inline UInt32 IpAddress::ToUInt32() const inline UInt32 IpAddress::ToUInt32() const
{ {
NazaraAssert(m_isValid && m_protocol == NetProtocol_IPv4, "Address is not a valid IPv4"); NazaraAssert(m_isValid && m_protocol == NetProtocol_IPv4, "Address is not a valid IPv4");
@ -94,17 +180,40 @@ namespace Nz
UInt32(m_ipv4[3]) << 0; UInt32(m_ipv4[3]) << 0;
} }
/*!
* \brief Converts IpAddress to boolean
* \return true If IpAddress is valid
*
* \see IsValid
*/
inline IpAddress::operator bool() const inline IpAddress::operator bool() const
{ {
return IsValid(); return IsValid();
} }
/*!
* \brief Output operator
* \return The stream
*
* \param out The stream
* \param address The address to output
*/
inline std::ostream& operator<<(std::ostream& out, const IpAddress& address) inline std::ostream& operator<<(std::ostream& out, const IpAddress& address)
{ {
out << "IpAddress(" << address.ToString() << ')'; out << "IpAddress(" << address.ToString() << ')';
return out; return out;
} }
/*!
* \brief Compares the IpAddress to other one
* \return true if the ip addresses are the same
*
* \param first First ip address to compare
* \param second Second ip address to compare with
*/
inline bool operator==(const IpAddress& first, const IpAddress& second) inline bool operator==(const IpAddress& first, const IpAddress& second)
{ {
// We need to check the validity of each address before comparing them // We need to check the validity of each address before comparing them
@ -146,11 +255,27 @@ namespace Nz
return true; return true;
} }
/*!
* \brief Compares the IpAddress to other one
* \return false if the ip addresses are the same
*
* \param first First ip address to compare
* \param second Second ip address to compare with
*/
inline bool operator!=(const IpAddress& first, const IpAddress& second) inline bool operator!=(const IpAddress& first, const IpAddress& second)
{ {
return !operator==(first, second); return !operator==(first, second);
} }
/*!
* \brief Compares the IpAddress to other one
* \return true if this ip address is inferior to the other one
*
* \param first First ip address to compare
* \param second Second ip address to compare with
*/
inline bool operator<(const IpAddress& first, const IpAddress& second) inline bool operator<(const IpAddress& first, const IpAddress& second)
{ {
// If the second address is invalid, there's no way we're lower than it // If the second address is invalid, there's no way we're lower than it
@ -196,16 +321,40 @@ namespace Nz
return false; //< Same address return false; //< Same address
} }
/*!
* \brief Compares the IpAddress to other one
* \return true if this ip address is inferior or equal to the other one
*
* \param first First ip address to compare
* \param second Second ip address to compare with
*/
inline bool operator<=(const IpAddress& first, const IpAddress& second) inline bool operator<=(const IpAddress& first, const IpAddress& second)
{ {
return !operator<(second, first); return !operator<(second, first);
} }
/*!
* \brief Compares the IpAddress to other one
* \return true if this ip address is greather to the other one
*
* \param first First ip address to compare
* \param second Second ip address to compare with
*/
inline bool operator>(const IpAddress& first, const IpAddress& second) inline bool operator>(const IpAddress& first, const IpAddress& second)
{ {
return second < first; return second < first;
} }
/*!
* \brief Compares the IpAddress to other one
* \return true if this ip address is greather or equal to the other one
*
* \param first First ip address to compare
* \param second Second ip address to compare with
*/
inline bool operator>=(const IpAddress& first, const IpAddress& second) inline bool operator>=(const IpAddress& first, const IpAddress& second)
{ {
return !operator<(first, second); return !operator<(first, second);
@ -217,6 +366,13 @@ namespace std
template<> template<>
struct hash<Nz::IpAddress> struct hash<Nz::IpAddress>
{ {
/*!
* \brief Converts IpAddress to hash
* \return Hash of the IpAddress
*
* \param ip IpAddress to hash
*/
size_t operator()(const Nz::IpAddress& ip) const size_t operator()(const Nz::IpAddress& ip) const
{ {
if (!ip) if (!ip)
@ -224,7 +380,7 @@ namespace std
// This is SDBM adapted for IP addresses, tested to generate the least collisions possible // This is SDBM adapted for IP addresses, tested to generate the least collisions possible
// (It doesn't mean it cannot be improved though) // (It doesn't mean it cannot be improved though)
std::size_t h = 0; std::size_t hash = 0;
switch (ip.GetProtocol()) switch (ip.GetProtocol())
{ {
case Nz::NetProtocol_Any: case Nz::NetProtocol_Any:
@ -233,20 +389,20 @@ namespace std
case Nz::NetProtocol_IPv4: case Nz::NetProtocol_IPv4:
{ {
h = ip.ToUInt32() + (h << 6) + (h << 16) - h; hash = ip.ToUInt32() + (hash << 6) + (hash << 16) - hash;
break; break;
} }
case Nz::NetProtocol_IPv6: case Nz::NetProtocol_IPv6:
{ {
Nz::IpAddress::IPv6 v6 = ip.ToIPv6(); Nz::IpAddress::IPv6 v6 = ip.ToIPv6();
for (std::size_t i = 0; i < v6.size(); i++) for (std::size_t i = 0; i < v6.size(); i++)
h = v6[i] + (h << 6) + (h << 16) - h; hash = v6[i] + (hash << 6) + (hash << 16) - hash;
break; break;
} }
} }
return ip.GetPort() + (h << 6) + (h << 16) - h; return ip.GetPort() + (hash << 6) + (hash << 16) - hash;
} }
}; };
} }

View File

@ -9,21 +9,46 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a NetPacket object by default
*/
inline NetPacket::NetPacket() : inline NetPacket::NetPacket() :
m_netCode(NetCode_Invalid) m_netCode(NetCode_Invalid)
{ {
} }
/*!
* \brief Constructs a NetPacket object with a packet number and a minimal capacity
*
* \param netCode Packet number
* \param minCapacity Minimal capacity of the packet
*/
inline NetPacket::NetPacket(UInt16 netCode, std::size_t minCapacity) inline NetPacket::NetPacket(UInt16 netCode, std::size_t minCapacity)
{ {
Reset(netCode, minCapacity); Reset(netCode, minCapacity);
} }
/*!
* \brief Constructs a NetPacket object with a packet number and raw memory
*
* \param netCode Packet number
* \param ptr Raw memory
* \param size Size of the memory
*/
inline NetPacket::NetPacket(UInt16 netCode, const void* ptr, std::size_t size) inline NetPacket::NetPacket(UInt16 netCode, const void* ptr, std::size_t size)
{ {
Reset(netCode, ptr, size); Reset(netCode, ptr, size);
} }
/*!
* \brief Constructs a NetPacket object with another one by move semantic
*
* \param packet NetPacket to move into this
*/
inline NetPacket::NetPacket(NetPacket&& packet) : inline NetPacket::NetPacket(NetPacket&& packet) :
ByteStream(std::move(packet)), ByteStream(std::move(packet)),
m_buffer(std::move(packet.m_buffer)), m_buffer(std::move(packet.m_buffer)),
@ -35,12 +60,23 @@ namespace Nz
SetStream(&m_memoryStream); SetStream(&m_memoryStream);
} }
/*!
* \brief Destructs the object
*/
inline NetPacket::~NetPacket() inline NetPacket::~NetPacket()
{ {
FlushBits(); //< Needs to be done here as the stream will be freed before ByteStream calls it FlushBits(); //< Needs to be done here as the stream will be freed before ByteStream calls it
FreeStream(); FreeStream();
} }
/*!
* \brief Gets the raw buffer
* \return Constant raw buffer
*
* \remark Produces a NazaraAssert if internal buffer is invalid
*/
inline const UInt8* NetPacket::GetConstData() const inline const UInt8* NetPacket::GetConstData() const
{ {
NazaraAssert(m_buffer, "Invalid buffer"); NazaraAssert(m_buffer, "Invalid buffer");
@ -48,6 +84,13 @@ namespace Nz
return m_buffer->GetConstBuffer(); return m_buffer->GetConstBuffer();
} }
/*!
* \brief Gets the raw buffer
* \return Raw buffer
*
* \remark Produces a NazaraAssert if internal buffer is invalid
*/
inline UInt8* NetPacket::GetData() const inline UInt8* NetPacket::GetData() const
{ {
NazaraAssert(m_buffer, "Invalid buffer"); NazaraAssert(m_buffer, "Invalid buffer");
@ -55,6 +98,11 @@ namespace Nz
return m_buffer->GetBuffer(); return m_buffer->GetBuffer();
} }
/*!
* \brief Gets the size of the data
* \return Size of the data
*/
inline size_t NetPacket::GetDataSize() const inline size_t NetPacket::GetDataSize() const
{ {
if (m_buffer) if (m_buffer)
@ -63,22 +111,46 @@ namespace Nz
return 0; return 0;
} }
/*!
* \brief Gets the packet number
* \return Packet number
*/
inline UInt16 NetPacket::GetNetCode() const inline UInt16 NetPacket::GetNetCode() const
{ {
return m_netCode; return m_netCode;
} }
/*!
* \brief Resets the packet
*/
inline void NetPacket::Reset() inline void NetPacket::Reset()
{ {
FreeStream(); FreeStream();
} }
/*!
* \brief Resets the packet with a packet number and a minimal capacity
*
* \param netCode Packet number
* \param minCapacity Minimal capacity of the packet
*/
inline void NetPacket::Reset(UInt16 netCode, std::size_t minCapacity) inline void NetPacket::Reset(UInt16 netCode, std::size_t minCapacity)
{ {
InitStream(HeaderSize + minCapacity, HeaderSize, OpenMode_ReadWrite); InitStream(HeaderSize + minCapacity, HeaderSize, OpenMode_ReadWrite);
m_netCode = netCode; m_netCode = netCode;
} }
/*!
* \brief Resets the packet with a packet number and raw memory
*
* \param netCode Packet number
* \param ptr Raw memory
* \param size Size of the memory
*/
inline void NetPacket::Reset(UInt16 netCode, const void* ptr, std::size_t size) inline void NetPacket::Reset(UInt16 netCode, const void* ptr, std::size_t size)
{ {
InitStream(HeaderSize + size, HeaderSize, OpenMode_ReadOnly); InitStream(HeaderSize + size, HeaderSize, OpenMode_ReadOnly);
@ -88,6 +160,14 @@ namespace Nz
m_netCode = netCode; m_netCode = netCode;
} }
/*!
* \brief Resizes the packet
*
* \param newSize Size for the resizing operation
*
* \remark Produces a NazaraAssert if internal buffer is invalid
*/
inline void NetPacket::Resize(std::size_t newSize) inline void NetPacket::Resize(std::size_t newSize)
{ {
NazaraAssert(m_buffer, "Invalid buffer"); NazaraAssert(m_buffer, "Invalid buffer");
@ -95,11 +175,24 @@ namespace Nz
m_buffer->Resize(newSize); m_buffer->Resize(newSize);
} }
/*!
* \brief Sets the packet number
*
* \param netCode Packet number
*/
inline void NetPacket::SetNetCode(UInt16 netCode) inline void NetPacket::SetNetCode(UInt16 netCode)
{ {
m_netCode = netCode; m_netCode = netCode;
} }
/*!
* \brief Moves the NetPacket into this
* \return A reference to this
*
* \param packet NetPacket to move in this
*/
inline NetPacket& Nz::NetPacket::operator=(NetPacket&& packet) inline NetPacket& Nz::NetPacket::operator=(NetPacket&& packet)
{ {
FreeStream(); FreeStream();

View File

@ -8,31 +8,66 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Closes the connection
*/
inline void RUdpConnection::Close() inline void RUdpConnection::Close()
{ {
m_socket.Close(); m_socket.Close();
} }
/*!
* \brief Disconnects the connection
*
* \see Close
*/
inline void RUdpConnection::Disconnect() inline void RUdpConnection::Disconnect()
{ {
Close(); Close();
} }
/*!
* \brief Gets the bound address
* \return IpAddress we are linked to
*/
inline IpAddress RUdpConnection::GetBoundAddress() const inline IpAddress RUdpConnection::GetBoundAddress() const
{ {
return m_socket.GetBoundAddress(); return m_socket.GetBoundAddress();
} }
/*!
* \brief Gets the port of the bound address
* \return Port we are linked to
*/
inline UInt16 RUdpConnection::GetBoundPort() const inline UInt16 RUdpConnection::GetBoundPort() const
{ {
return m_socket.GetBoundPort(); return m_socket.GetBoundPort();
} }
/*!
* \brief Gets the last error
* \return Socket error
*/
inline SocketError RUdpConnection::GetLastError() const inline SocketError RUdpConnection::GetLastError() const
{ {
return m_lastError; return m_lastError;
} }
/*!
* \brief Listens to a socket
* \return true If successfully bound
*
* \param protocol Net protocol to listen to
* \param port Port to listen to
*
* \remark Produces a NazaraAssert if protocol is unknown or any
*/
inline bool RUdpConnection::Listen(NetProtocol protocol, UInt16 port) inline bool RUdpConnection::Listen(NetProtocol protocol, UInt16 port)
{ {
NazaraAssert(protocol != NetProtocol_Any, "Any protocol not supported for Listen"); //< TODO NazaraAssert(protocol != NetProtocol_Any, "Any protocol not supported for Listen"); //< TODO
@ -59,16 +94,36 @@ namespace Nz
return Listen(any); return Listen(any);
} }
/*!
* \brief Sets the protocol id
*
* \param protocolId Protocol ID like NNet
*/
inline void RUdpConnection::SetProtocolId(UInt32 protocolId) inline void RUdpConnection::SetProtocolId(UInt32 protocolId)
{ {
m_protocol = protocolId; m_protocol = protocolId;
} }
/*!
* \brief Sets the time before ack
*
* \param Time before acking to send many together (in ms)
*/
inline void RUdpConnection::SetTimeBeforeAck(UInt32 ms) inline void RUdpConnection::SetTimeBeforeAck(UInt32 ms)
{ {
m_forceAckSendTime = ms * 1000; //< Store in microseconds for easier handling m_forceAckSendTime = ms * 1000; //< Store in microseconds for easier handling
} }
/*!
* \brief Computes the difference of sequence
* \return Delta between the two sequences
*
* \param sequence First sequence
* \param sequence2 Second sequence
*/
inline unsigned int RUdpConnection::ComputeSequenceDifference(SequenceIndex sequence, SequenceIndex sequence2) inline unsigned int RUdpConnection::ComputeSequenceDifference(SequenceIndex sequence, SequenceIndex sequence2)
{ {
unsigned int difference; unsigned int difference;
@ -77,9 +132,16 @@ namespace Nz
else else
difference = sequence - sequence2; difference = sequence - sequence2;
return 0; return difference;
} }
/*!
* \brief Checks whether the peer has pending packets
* \return true If it is the case
*
* \param peer Data relative to the peer
*/
inline bool RUdpConnection::HasPendingPackets(PeerData& peer) inline bool RUdpConnection::HasPendingPackets(PeerData& peer)
{ {
for (unsigned int priority = PacketPriority_Highest; priority <= PacketPriority_Lowest; ++priority) for (unsigned int priority = PacketPriority_Highest; priority <= PacketPriority_Lowest; ++priority)
@ -87,13 +149,19 @@ namespace Nz
std::vector<PendingPacket>& pendingPackets = peer.pendingPackets[priority]; std::vector<PendingPacket>& pendingPackets = peer.pendingPackets[priority];
if (!pendingPackets.empty()) if (!pendingPackets.empty())
return true; return true;
pendingPackets.clear();
} }
return false; return false;
} }
/*!
* \brief Checks whether the ack is more recent
* \return true If it is the case
*
* \param ack First sequence
* \param ack2 Second sequence
*/
inline bool RUdpConnection::IsAckMoreRecent(SequenceIndex ack, SequenceIndex ack2) inline bool RUdpConnection::IsAckMoreRecent(SequenceIndex ack, SequenceIndex ack2)
{ {
constexpr SequenceIndex maxDifference = std::numeric_limits<SequenceIndex>::max() / 2; constexpr SequenceIndex maxDifference = std::numeric_limits<SequenceIndex>::max() / 2;
@ -106,6 +174,13 @@ namespace Nz
return false; ///< Same ack return false; ///< Same ack
} }
/*!
* \brief Checks whether the connection is reliable
* \return true If it is the case
*
* \remark Produces a NazaraError if enumeration is invalid
*/
inline bool RUdpConnection::IsReliable(PacketReliability reliability) inline bool RUdpConnection::IsReliable(PacketReliability reliability)
{ {
switch (reliability) switch (reliability)
@ -122,6 +197,14 @@ namespace Nz
return false; return false;
} }
/*!
* \brief Simulates the loss of packets on network
*
* \param packetLoss Ratio of packet loss according to bernoulli distribution
*
* \remark Produces a NazaraAssert if packetLoss is not in between 0.0 and 1.0
*/
inline void RUdpConnection::SimulateNetwork(double packetLoss) inline void RUdpConnection::SimulateNetwork(double packetLoss)
{ {
NazaraAssert(packetLoss >= 0.0 && packetLoss <= 1.0, "Packet loss must be in range [0..1]"); NazaraAssert(packetLoss >= 0.0 && packetLoss <= 1.0, "Packet loss must be in range [0..1]");

View File

@ -79,8 +79,8 @@ namespace Nz
PendingPacket m_pendingPacket; PendingPacket m_pendingPacket;
UInt64 m_keepAliveInterval; UInt64 m_keepAliveInterval;
UInt64 m_keepAliveTime; UInt64 m_keepAliveTime;
bool m_isKeepAliveEnabled;
bool m_isLowDelayEnabled; bool m_isLowDelayEnabled;
bool m_isKeepAliveEnabled;
}; };
} }

View File

@ -7,6 +7,10 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a TcpClient object by default
*/
inline TcpClient::TcpClient() : inline TcpClient::TcpClient() :
AbstractSocket(SocketType_TCP), AbstractSocket(SocketType_TCP),
Stream(StreamOption_Sequential), Stream(StreamOption_Sequential),
@ -17,31 +21,62 @@ namespace Nz
{ {
} }
/*!
* \brief Disconnects the connection
*
* \see Close
*/
inline void TcpClient::Disconnect() inline void TcpClient::Disconnect()
{ {
Close(); Close();
} }
/*!
* \brief Gets the interval between two keep alive pings
* \return Interval in milliseconds between two pings
*/
inline UInt64 TcpClient::GetKeepAliveInterval() const inline UInt64 TcpClient::GetKeepAliveInterval() const
{ {
return m_keepAliveInterval; return m_keepAliveInterval;
} }
/*!
* \brief Gets the time before expiration of connection
* \return Time in milliseconds before expiration
*/
inline UInt64 TcpClient::GetKeepAliveTime() const inline UInt64 TcpClient::GetKeepAliveTime() const
{ {
return m_keepAliveTime; return m_keepAliveTime;
} }
/*!
* \brief Gets the remote address
* \return Address of peer
*/
inline IpAddress TcpClient::GetRemoteAddress() const inline IpAddress TcpClient::GetRemoteAddress() const
{ {
return m_peerAddress; return m_peerAddress;
} }
/*!
* \brief Checks whether low delay is enabled
* \return true If it is the case
*/
inline bool TcpClient::IsLowDelayEnabled() const inline bool TcpClient::IsLowDelayEnabled() const
{ {
return m_isLowDelayEnabled; return m_isLowDelayEnabled;
} }
/*!
* \brief Checks whether the keep alive flag is enabled
* \return true If it is the case
*/
inline bool TcpClient::IsKeepAliveEnabled() const inline bool TcpClient::IsKeepAliveEnabled() const
{ {
return m_isKeepAliveEnabled; return m_isKeepAliveEnabled;

View File

@ -7,27 +7,58 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a TcpServer object by default
*/
inline TcpServer::TcpServer() : inline TcpServer::TcpServer() :
AbstractSocket(SocketType_TCP) AbstractSocket(SocketType_TCP)
{ {
} }
/*!
* \brief Constructs a TcpServer object with another one by move semantic
*
* \param tcpServer TcpServer to move into this
*/
inline TcpServer::TcpServer(TcpServer&& tcpServer) : inline TcpServer::TcpServer(TcpServer&& tcpServer) :
AbstractSocket(std::move(tcpServer)), AbstractSocket(std::move(tcpServer)),
m_boundAddress(std::move(tcpServer.m_boundAddress)) m_boundAddress(std::move(tcpServer.m_boundAddress))
{ {
} }
/*!
* \brief Gets the bound address
* \return IpAddress we are linked to
*/
inline IpAddress TcpServer::GetBoundAddress() const inline IpAddress TcpServer::GetBoundAddress() const
{ {
return m_boundAddress; return m_boundAddress;
} }
/*!
* \brief Gets the port of the bound address
* \return Port we are linked to
*/
inline UInt16 TcpServer::GetBoundPort() const inline UInt16 TcpServer::GetBoundPort() const
{ {
return m_boundAddress.GetPort(); return m_boundAddress.GetPort();
} }
/*!
* \brief Listens to a socket
* \return State of the socket
*
* \param protocol Net protocol to listen to
* \param port Port to listen to
* \param queueSize Size of the queue
*
* \remark Produces a NazaraAssert if protocol is unknown or any
*/
inline SocketState TcpServer::Listen(NetProtocol protocol, UInt16 port, unsigned int queueSize) inline SocketState TcpServer::Listen(NetProtocol protocol, UInt16 port, unsigned int queueSize)
{ {
NazaraAssert(protocol != NetProtocol_Any, "Any protocol not supported for Listen"); //< TODO NazaraAssert(protocol != NetProtocol_Any, "Any protocol not supported for Listen"); //< TODO

View File

@ -49,7 +49,6 @@ namespace Nz
void OnOpened() override; void OnOpened() override;
IpAddress m_boundAddress; IpAddress m_boundAddress;
SocketState m_state;
bool m_isBroadCastingEnabled; bool m_isBroadCastingEnabled;
}; };
} }

View File

@ -6,24 +6,46 @@
namespace Nz namespace Nz
{ {
/*!
* \brief Constructs a UdpSocket object by default
*/
inline UdpSocket::UdpSocket() : inline UdpSocket::UdpSocket() :
AbstractSocket(SocketType_UDP) AbstractSocket(SocketType_UDP)
{ {
} }
/*!
* \brief Constructs a UdpSocket object with a net protocol
*
* \param protocol Net protocol to use
*/
inline UdpSocket::UdpSocket(NetProtocol protocol) : inline UdpSocket::UdpSocket(NetProtocol protocol) :
UdpSocket() UdpSocket()
{ {
Create(protocol); Create(protocol);
} }
/*!
* \brief Constructs a UdpSocket object with another one by move semantic
*
* \param udpSocket UdpSocket to move into this
*/
inline UdpSocket::UdpSocket(UdpSocket&& udpSocket) : inline UdpSocket::UdpSocket(UdpSocket&& udpSocket) :
AbstractSocket(std::move(udpSocket)), AbstractSocket(std::move(udpSocket)),
m_boundAddress(std::move(udpSocket.m_boundAddress)), m_boundAddress(std::move(udpSocket.m_boundAddress))
m_state(udpSocket.m_state)
{ {
} }
/*!
* \brief Binds a specific port
* \return State of the socket
*
* \param port Port to bind
*/
inline SocketState UdpSocket::Bind(UInt16 port) inline SocketState UdpSocket::Bind(UInt16 port)
{ {
IpAddress any; IpAddress any;
@ -47,6 +69,13 @@ namespace Nz
return Bind(any); return Bind(any);
} }
/*!
* \brief Creates a UDP socket
* \return true If successful
*
* \param protocol Net protocol to use
*/
bool UdpSocket::Create(NetProtocol protocol) bool UdpSocket::Create(NetProtocol protocol)
{ {
NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol"); NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol");
@ -54,21 +83,41 @@ namespace Nz
return Open(protocol); return Open(protocol);
} }
/*!
* \brief Gets the bound address
* \return IpAddress we are linked to
*/
inline IpAddress UdpSocket::GetBoundAddress() const inline IpAddress UdpSocket::GetBoundAddress() const
{ {
return m_boundAddress; return m_boundAddress;
} }
/*!
* \brief Gets the port of the bound address
* \return Port we are linked to
*/
inline UInt16 UdpSocket::GetBoundPort() const inline UInt16 UdpSocket::GetBoundPort() const
{ {
return m_boundAddress.GetPort(); return m_boundAddress.GetPort();
} }
/*!
* \brief Gets the state of the socket
* \return State of the socket
*/
inline SocketState UdpSocket::GetState() const inline SocketState UdpSocket::GetState() const
{ {
return m_state; return m_state;
} }
/*!
* \brief Checks whether the broadcasting is enabled
* \return true If it is the case
*/
inline bool UdpSocket::IsBroadcastingEnabled() const inline bool UdpSocket::IsBroadcastingEnabled() const
{ {
return m_isBroadCastingEnabled; return m_isBroadCastingEnabled;

View File

@ -59,8 +59,8 @@ namespace Nz
unsigned int GetHeight(UInt8 level = 0) const; unsigned int GetHeight(UInt8 level = 0) const;
UInt8 GetLevelCount() const; UInt8 GetLevelCount() const;
UInt8 GetMaxLevel() const; UInt8 GetMaxLevel() const;
unsigned int GetMemoryUsage() const; std::size_t GetMemoryUsage() const;
unsigned int GetMemoryUsage(UInt8 level) const; std::size_t GetMemoryUsage(UInt8 level) const;
Vector3ui GetSize(UInt8 level = 0) const; Vector3ui GetSize(UInt8 level = 0) const;
ImageType GetType() const; ImageType GetType() const;
unsigned int GetWidth(UInt8 level = 0) const; unsigned int GetWidth(UInt8 level = 0) const;

View File

@ -29,7 +29,7 @@ namespace Nz
virtual void Clear() = 0; virtual void Clear() = 0;
virtual void Free(SparsePtr<const Rectui> rects, SparsePtr<unsigned int> layers, unsigned int count) = 0; virtual void Free(SparsePtr<const Rectui> rects, SparsePtr<unsigned int> layers, unsigned int count) = 0;
virtual AbstractImage* GetLayer(unsigned int layerIndex) const = 0; virtual AbstractImage* GetLayer(unsigned int layerIndex) const = 0;
virtual unsigned int GetLayerCount() const = 0; virtual std::size_t GetLayerCount() const = 0;
virtual UInt32 GetStorage() const = 0; virtual UInt32 GetStorage() const = 0;
virtual bool Insert(const Image& image, Rectui* rect, bool* flipped, unsigned int* layerIndex) = 0; virtual bool Insert(const Image& image, Rectui* rect, bool* flipped, unsigned int* layerIndex) = 0;

View File

@ -28,8 +28,8 @@ namespace Nz
virtual unsigned int GetHeight(UInt8 level = 0) const = 0; virtual unsigned int GetHeight(UInt8 level = 0) const = 0;
virtual UInt8 GetLevelCount() const = 0; virtual UInt8 GetLevelCount() const = 0;
virtual UInt8 GetMaxLevel() const = 0; virtual UInt8 GetMaxLevel() const = 0;
virtual unsigned int GetMemoryUsage() const = 0; virtual std::size_t GetMemoryUsage() const = 0;
virtual unsigned int GetMemoryUsage(UInt8 level) const = 0; virtual std::size_t GetMemoryUsage(UInt8 level) const = 0;
virtual Vector3ui GetSize(UInt8 level = 0) const = 0; virtual Vector3ui GetSize(UInt8 level = 0) const = 0;
virtual ImageType GetType() const = 0; virtual ImageType GetType() const = 0;
virtual unsigned int GetWidth(UInt8 level = 0) const = 0; virtual unsigned int GetWidth(UInt8 level = 0) const = 0;

View File

@ -27,10 +27,10 @@ namespace Nz
virtual ~AbstractTextDrawer(); virtual ~AbstractTextDrawer();
virtual const Recti& GetBounds() const = 0; virtual const Recti& GetBounds() const = 0;
virtual Font* GetFont(unsigned int index) const = 0; virtual Font* GetFont(std::size_t index) const = 0;
virtual unsigned int GetFontCount() const = 0; virtual std::size_t GetFontCount() const = 0;
virtual const Glyph& GetGlyph(unsigned int index) const = 0; virtual const Glyph& GetGlyph(std::size_t index) const = 0;
virtual unsigned int GetGlyphCount() const = 0; virtual std::size_t GetGlyphCount() const = 0;
struct Glyph struct Glyph
{ {

View File

@ -61,8 +61,8 @@ namespace Nz
bool ExtractGlyph(unsigned int characterSize, char32_t character, UInt32 style, FontGlyph* glyph) const; bool ExtractGlyph(unsigned int characterSize, char32_t character, UInt32 style, FontGlyph* glyph) const;
const std::shared_ptr<AbstractAtlas>& GetAtlas() const; const std::shared_ptr<AbstractAtlas>& GetAtlas() const;
unsigned int GetCachedGlyphCount(unsigned int characterSize, UInt32 style) const; std::size_t GetCachedGlyphCount(unsigned int characterSize, UInt32 style) const;
unsigned int GetCachedGlyphCount() const; std::size_t GetCachedGlyphCount() const;
String GetFamilyName() const; String GetFamilyName() const;
int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const; int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const;
const Glyph& GetGlyph(unsigned int characterSize, UInt32 style, char32_t character) const; const Glyph& GetGlyph(unsigned int characterSize, UInt32 style, char32_t character) const;

View File

@ -47,12 +47,12 @@ namespace Nz
Ternary Check(); Ternary Check();
unsigned int GetAnimatedComponentCount() const; std::size_t GetAnimatedComponentCount() const;
const Frame* GetFrames() const; const Frame* GetFrames() const;
unsigned int GetFrameCount() const; std::size_t GetFrameCount() const;
unsigned int GetFrameRate() const; std::size_t GetFrameRate() const;
const Joint* GetJoints() const; const Joint* GetJoints() const;
unsigned int GetJointCount() const; std::size_t GetJointCount() const;
bool Parse(); bool Parse();

View File

@ -58,9 +58,9 @@ namespace Nz
Ternary Check(); Ternary Check();
const Joint* GetJoints() const; const Joint* GetJoints() const;
unsigned int GetJointCount() const; std::size_t GetJointCount() const;
const Mesh* GetMeshes() const; const Mesh* GetMeshes() const;
unsigned int GetMeshCount() const; std::size_t GetMeshCount() const;
bool Parse(); bool Parse();

View File

@ -23,16 +23,17 @@ namespace Nz
GuillotineImageAtlas(); GuillotineImageAtlas();
virtual ~GuillotineImageAtlas(); virtual ~GuillotineImageAtlas();
void Clear(); void Clear() override;
void Free(SparsePtr<const Rectui> rects, SparsePtr<unsigned int> layers, unsigned int count);
void Free(SparsePtr<const Rectui> rects, SparsePtr<unsigned int> layers, unsigned int count) override;
GuillotineBinPack::FreeRectChoiceHeuristic GetRectChoiceHeuristic() const; GuillotineBinPack::FreeRectChoiceHeuristic GetRectChoiceHeuristic() const;
GuillotineBinPack::GuillotineSplitHeuristic GetRectSplitHeuristic() const; GuillotineBinPack::GuillotineSplitHeuristic GetRectSplitHeuristic() const;
AbstractImage* GetLayer(unsigned int layerIndex) const; AbstractImage* GetLayer(unsigned int layerIndex) const override;
unsigned int GetLayerCount() const; std::size_t GetLayerCount() const override;
UInt32 GetStorage() const; UInt32 GetStorage() const override;
bool Insert(const Image& image, Rectui* rect, bool* flipped, unsigned int* layerIndex); bool Insert(const Image& image, Rectui* rect, bool* flipped, unsigned int* layerIndex) override;
void SetRectChoiceHeuristic(GuillotineBinPack::FreeRectChoiceHeuristic heuristic); void SetRectChoiceHeuristic(GuillotineBinPack::FreeRectChoiceHeuristic heuristic);
void SetRectSplitHeuristic(GuillotineBinPack::GuillotineSplitHeuristic heuristic); void SetRectSplitHeuristic(GuillotineBinPack::GuillotineSplitHeuristic heuristic);

View File

@ -84,8 +84,8 @@ namespace Nz
unsigned int GetHeight(UInt8 level = 0) const; unsigned int GetHeight(UInt8 level = 0) const;
UInt8 GetLevelCount() const; UInt8 GetLevelCount() const;
UInt8 GetMaxLevel() const; UInt8 GetMaxLevel() const;
unsigned int GetMemoryUsage() const; std::size_t GetMemoryUsage() const;
unsigned int GetMemoryUsage(UInt8 level) const; std::size_t GetMemoryUsage(UInt8 level) const;
Color GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const; Color GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const;
UInt8* GetPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, UInt8 level = 0); UInt8* GetPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, UInt8 level = 0);
Vector3ui GetSize(UInt8 level = 0) const; Vector3ui GetSize(UInt8 level = 0) const;

View File

@ -41,6 +41,7 @@ namespace Nz
static constexpr const char* HeightTexturePath = "MatHeightTexturePath"; static constexpr const char* HeightTexturePath = "MatHeightTexturePath";
static constexpr const char* Lighting = "MatLighting"; static constexpr const char* Lighting = "MatLighting";
static constexpr const char* LineWidth = "MatLineWidth"; static constexpr const char* LineWidth = "MatLineWidth";
static constexpr const char* Name = "MatName";
static constexpr const char* NormalTexturePath = "MatNormalTexturePath"; static constexpr const char* NormalTexturePath = "MatNormalTexturePath";
static constexpr const char* PointSize = "MatPointSize"; static constexpr const char* PointSize = "MatPointSize";
static constexpr const char* ScissorTest = "MatScissorTest"; static constexpr const char* ScissorTest = "MatScissorTest";

View File

@ -29,8 +29,8 @@ namespace Nz
{ {
MeshParams(); // Vérifie que le storage par défaut est supporté (software autrement) MeshParams(); // Vérifie que le storage par défaut est supporté (software autrement)
// La mise à l'échelle éventuelle que subira le mesh // La transformation appliquée à tous les sommets du mesh
Vector3f scale = Vector3f::Unit(); Matrix4f matrix = Matrix4f::Identity();
// Si ceci sera le stockage utilisé par les buffers // Si ceci sera le stockage utilisé par les buffers
UInt32 storage = DataStorage_Hardware; UInt32 storage = DataStorage_Hardware;

View File

@ -100,7 +100,7 @@ namespace Nz
counter |= blueMask; counter |= blueMask;
counter |= alphaMask; counter |= alphaMask;
bitsPerPixel = counter.Count(); bitsPerPixel = static_cast<UInt8>(counter.Count());
} }
inline bool PixelFormatInfo::Validate() const inline bool PixelFormatInfo::Validate() const
@ -116,7 +116,7 @@ namespace Nz
for (unsigned int i = 0; i < 4; ++i) for (unsigned int i = 0; i < 4; ++i)
{ {
unsigned int usedBits = masks[i]->Count(); UInt8 usedBits = static_cast<UInt8>(masks[i]->Count());
if (usedBits == 0) if (usedBits == 0)
continue; continue;

View File

@ -32,10 +32,10 @@ namespace Nz
unsigned int GetCharacterSize() const; unsigned int GetCharacterSize() const;
const Color& GetColor() const; const Color& GetColor() const;
Font* GetFont() const; Font* GetFont() const;
Font* GetFont(unsigned int index) const override; Font* GetFont(std::size_t index) const override;
unsigned int GetFontCount() const override; std::size_t GetFontCount() const override;
const Glyph& GetGlyph(unsigned int index) const override; const Glyph& GetGlyph(std::size_t index) const override;
unsigned int GetGlyphCount() const override; std::size_t GetGlyphCount() const override;
UInt32 GetStyle() const; UInt32 GetStyle() const;
const String& GetText() const; const String& GetText() const;

View File

@ -27,6 +27,8 @@ namespace Nz
class NAZARA_VULKAN_API Device : public HandledObject<Device> class NAZARA_VULKAN_API Device : public HandledObject<Device>
{ {
public: public:
struct QueueFamilyInfo;
inline Device(Instance& instance); inline Device(Instance& instance);
Device(const Device&) = delete; Device(const Device&) = delete;
Device(Device&&) = delete; Device(Device&&) = delete;
@ -35,6 +37,7 @@ namespace Nz
bool Create(VkPhysicalDevice device, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); bool Create(VkPhysicalDevice device, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline void Destroy(); inline void Destroy();
inline const std::vector<QueueFamilyInfo>& GetEnabledQueues() const;
inline Queue GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex); inline Queue GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex);
inline Instance& GetInstance(); inline Instance& GetInstance();
inline const Instance& GetInstance() const; inline const Instance& GetInstance() const;
@ -185,6 +188,15 @@ namespace Nz
#undef NAZARA_VULKAN_DEVICE_FUNCTION #undef NAZARA_VULKAN_DEVICE_FUNCTION
struct QueueFamilyInfo
{
std::vector<float> queues;
VkExtent3D minImageTransferGranularity;
VkQueueFlags flags;
UInt32 familyIndex;
UInt32 timestampValidBits;
};
private: private:
inline PFN_vkVoidFunction GetProcAddr(const char* name); inline PFN_vkVoidFunction GetProcAddr(const char* name);
@ -195,6 +207,7 @@ namespace Nz
VkResult m_lastErrorCode; VkResult m_lastErrorCode;
std::unordered_set<String> m_loadedExtensions; std::unordered_set<String> m_loadedExtensions;
std::unordered_set<String> m_loadedLayers; std::unordered_set<String> m_loadedLayers;
std::vector<QueueFamilyInfo> m_enabledQueuesInfos;
}; };
} }
} }

View File

@ -36,12 +36,17 @@ namespace Nz
} }
} }
inline const std::vector<Device::QueueFamilyInfo>& Device::GetEnabledQueues() const
{
return m_enabledQueuesInfos;
}
inline Queue Device::GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex) inline Queue Device::GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex)
{ {
VkQueue queue; VkQueue queue;
vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, &queue); vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, &queue);
return Queue(DeviceHandle(this), queue); return Queue(CreateHandle(), queue);
} }
inline Instance& Device::GetInstance() inline Instance& Device::GetInstance()

View File

@ -33,7 +33,7 @@ namespace Nz
DeviceObject& operator=(const DeviceObject&) = delete; DeviceObject& operator=(const DeviceObject&) = delete;
DeviceObject& operator=(DeviceObject&&) = delete; DeviceObject& operator=(DeviceObject&&) = delete;
inline operator VkType(); inline operator VkType() const;
protected: protected:
DeviceHandle m_device; DeviceHandle m_device;

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