Merge branch 'nazara-next' into vulkan

This commit is contained in:
Lynix
2020-02-25 19:15:07 +01:00
448 changed files with 2739 additions and 15884 deletions

View File

@@ -39,7 +39,7 @@ namespace Nz
bool IsLooping() const override;
bool OpenFromFile(const String& filePath, const SoundStreamParams& params = SoundStreamParams());
bool OpenFromFile(const std::filesystem::path& filePath, const SoundStreamParams& params = SoundStreamParams());
bool OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params = SoundStreamParams());
bool OpenFromStream(Stream& stream, const SoundStreamParams& params = SoundStreamParams());

View File

@@ -34,7 +34,7 @@ namespace Nz
bool IsPlayable() const;
bool IsPlaying() const;
bool LoadFromFile(const String& filePath, const SoundBufferParams& params = SoundBufferParams());
bool LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params = SoundBufferParams());
bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
bool LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());

View File

@@ -71,7 +71,7 @@ namespace Nz
static bool IsFormatSupported(AudioFormat format);
static SoundBufferRef LoadFromFile(const String& filePath, const SoundBufferParams& params = SoundBufferParams());
static SoundBufferRef LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params = SoundBufferParams());
static SoundBufferRef LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
static SoundBufferRef LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());

View File

@@ -14,6 +14,7 @@
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <mutex>
namespace Nz
{
@@ -40,7 +41,7 @@ namespace Nz
virtual UInt32 GetDuration() const = 0;
virtual AudioFormat GetFormat() const = 0;
virtual Mutex& GetMutex() = 0;
virtual std::mutex& GetMutex() = 0;
virtual UInt64 GetSampleCount() const = 0;
virtual UInt32 GetSampleRate() const = 0;
@@ -48,7 +49,7 @@ namespace Nz
virtual void Seek(UInt64 offset) = 0;
virtual UInt64 Tell() = 0;
static SoundStreamRef OpenFromFile(const String& filePath, const SoundStreamParams& params = SoundStreamParams());
static SoundStreamRef OpenFromFile(const std::filesystem::path& filePath, const SoundStreamParams& params = SoundStreamParams());
static SoundStreamRef OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params = SoundStreamParams());
static SoundStreamRef OpenFromStream(Stream& stream, const SoundStreamParams& params = SoundStreamParams());

View File

@@ -34,14 +34,13 @@
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/ByteArrayPool.hpp>
#include <Nazara/Core/ByteStream.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Directory.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/EmptyStream.hpp>
#include <Nazara/Core/Endianness.hpp>
@@ -56,7 +55,6 @@
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/HardwareInfo.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/MemoryHelper.hpp>
#include <Nazara/Core/MemoryManager.hpp>
@@ -64,13 +62,13 @@
#include <Nazara/Core/MemoryStream.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/OffsetOf.hpp>
#include <Nazara/Core/ParameterList.hpp>
#include <Nazara/Core/PluginManager.hpp>
#include <Nazara/Core/PoolByteStream.hpp>
#include <Nazara/Core/Primitive.hpp>
#include <Nazara/Core/PrimitiveList.hpp>
#include <Nazara/Core/RefCounted.hpp>
@@ -79,7 +77,6 @@
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <Nazara/Core/ResourceSaver.hpp>
#include <Nazara/Core/Semaphore.hpp>
#include <Nazara/Core/SerializationContext.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Core/SparsePtr.hpp>
@@ -88,9 +85,9 @@
#include <Nazara/Core/StdLogger.hpp>
#include <Nazara/Core/Stream.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Core/TaskScheduler.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Core/TypeTag.hpp>
#include <Nazara/Core/Unicode.hpp>
#include <Nazara/Core/Updatable.hpp>

View File

@@ -31,6 +31,33 @@ namespace Nz
template<typename T> void HashCombine(std::size_t& seed, const T& v);
template<typename T> T ReverseBits(T integer);
template<typename T>
struct AlwaysFalse : std::false_type {};
template<typename... Args>
struct OverloadResolver
{
template<typename R, typename T>
constexpr auto operator()(R(T::* ptr)(Args...)) const noexcept
{
return ptr;
}
template<typename R, typename T>
constexpr auto operator()(R(T::* ptr)(Args...) const) const noexcept
{
return ptr;
}
template<typename R>
constexpr auto operator()(R(*ptr)(Args...)) const noexcept
{
return ptr;
}
};
template<typename... Args> constexpr OverloadResolver<Args...> Overload = {};
template<typename T>
struct PointedType
{

View File

@@ -119,7 +119,7 @@ namespace Nz
Bitset<Block, Allocator>::Bitset(T value) :
Bitset()
{
if (sizeof(T) <= sizeof(Block))
if constexpr (sizeof(T) <= sizeof(Block))
{
m_bitCount = BitCount<T>();
m_blocks.push_back(static_cast<Block>(value));

View File

@@ -9,12 +9,6 @@
#include <Nazara/Prerequisites.hpp>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_CLOCK
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
namespace Nz
{
class NAZARA_CORE_API Clock
@@ -39,8 +33,6 @@ namespace Nz
Clock& operator=(Clock&& clock) = default;
private:
NazaraMutexAttrib(m_mutex, mutable)
UInt64 m_elapsedTime;
UInt64 m_refTime;
bool m_paused;

View File

@@ -1,42 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CONDITIONVARIABLE_HPP
#define NAZARA_CONDITIONVARIABLE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
namespace Nz
{
class ConditionVariableImpl;
class Mutex;
class NAZARA_CORE_API ConditionVariable
{
public:
ConditionVariable();
ConditionVariable(const ConditionVariable&) = delete;
ConditionVariable(ConditionVariable&& condition) noexcept = default;
~ConditionVariable();
void Signal();
void SignalAll();
void Wait(Mutex* mutex);
bool Wait(Mutex* mutex, UInt32 timeout);
ConditionVariable& operator=(const ConditionVariable&) = delete;
ConditionVariable& operator=(ConditionVariable&& condition) noexcept = default;
private:
MovablePtr<ConditionVariableImpl> m_impl;
};
}
#include <Nazara/Core/ConditionVariable.inl>
#endif // NAZARA_CONDITIONVARIABLE_HPP

View File

@@ -1,14 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
/*!
* \class Nz::ConditionVariable
*/
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -58,17 +58,6 @@
// Activate the security tests based on the code (Advised for development)
#define NAZARA_CORE_SAFE 1
// Protect the classes against data race
#define NAZARA_CORE_THREADSAFE 1
// Classes to protect against data race
#define NAZARA_THREADSAFETY_CLOCK 0 // Clock
#define NAZARA_THREADSAFETY_DIRECTORY 1 // Directory
#define NAZARA_THREADSAFETY_DYNLIB 1 // DynLib
#define NAZARA_THREADSAFETY_FILE 1 // File
#define NAZARA_THREADSAFETY_LOG 1 // Log
#define NAZARA_THREADSAFETY_REFCOUNTED 1 // RefCounted
// Number of spinlocks to use with the Windows critical sections (0 to disable)
#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096

View File

@@ -1,82 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DIRECTORY_HPP
#define NAZARA_DIRECTORY_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/String.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS)
#define NAZARA_DIRECTORY_SEPARATOR '\\'
#elif defined(NAZARA_PLATFORM_LINUX)
#define NAZARA_DIRECTORY_SEPARATOR '/'
#else
#error OS not handled
#define NAZARA_DIRECTORY_SEPARATOR '/'
#endif
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DIRECTORY
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
namespace Nz
{
class DirectoryImpl;
class NAZARA_CORE_API Directory
{
public:
Directory();
Directory(const String& dirPath);
Directory(const Directory&) = delete;
Directory(Directory&&) noexcept = default;
~Directory();
void Close();
bool Exists() const;
String GetPath() const;
String GetPattern() const;
String GetResultName() const;
String GetResultPath() const;
UInt64 GetResultSize() const;
bool IsOpen() const;
bool IsResultDirectory() const;
bool NextResult(bool skipDots = true);
bool Open();
void SetPath(const String& dirPath);
void SetPattern(const String& pattern);
static bool Copy(const String& sourcePath, const String& destPath);
static bool Create(const String& dirPath, bool recursive = false);
static bool Exists(const String& dirPath);
static String GetCurrent();
static const char* GetCurrentFileRelativeToEngine(const char* currentFile);
static bool Remove(const String& dirPath, bool emptyDirectory = false);
static bool SetCurrent(const String& dirPath);
Directory& operator=(const Directory&) = delete;
Directory& operator=(Directory&&) noexcept = delete;
private:
NazaraMutexAttrib(m_mutex, mutable)
String m_dirPath;
String m_pattern;
MovablePtr<DirectoryImpl> m_impl;
};
}
#endif // NAZARA_DIRECTORY_HPP

View File

@@ -9,7 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/String.hpp>
#include <filesystem>
#if defined(NAZARA_PLATFORM_WINDOWS)
#define NAZARA_DYNLIB_EXTENSION ".dll"
@@ -21,12 +21,6 @@
#error OS not handled
#endif
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DYNLIB
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
namespace Nz
{
using DynLibFunc = int (*)(); // "Generic" type of pointer to function
@@ -38,25 +32,23 @@ namespace Nz
public:
DynLib();
DynLib(const DynLib&) = delete;
DynLib(DynLib&&) noexcept = default;
DynLib(DynLib&&) noexcept;
~DynLib();
String GetLastError() const;
DynLibFunc GetSymbol(const String& symbol) const;
std::string GetLastError() const;
DynLibFunc GetSymbol(const char* symbol) const;
bool IsLoaded() const;
bool Load(const String& libraryPath);
bool Load(const std::filesystem::path& libraryPath);
void Unload();
DynLib& operator=(const DynLib&) = delete;
DynLib& operator=(DynLib&& lib) noexcept = default;
DynLib& operator=(DynLib&& lib) noexcept;
private:
NazaraMutexAttrib(m_mutex, mutable)
mutable String m_lastError;
MovablePtr<DynLibImpl> m_impl;
mutable std::string m_lastError;
std::unique_ptr<DynLibImpl> m_impl;
};
}

View File

@@ -33,7 +33,7 @@ namespace Nz
static UInt32 GetFlags();
static String GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr);
static unsigned int GetLastSystemErrorCode();
static String GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
static std::string GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
static void SetFlags(UInt32 flags);
@@ -41,6 +41,8 @@ namespace Nz
static void Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function);
private:
static const char* GetCurrentFileRelativeToEngine(const char* file);
static UInt32 s_flags;
static String s_lastError;
static const char* s_lastErrorFunction;

View File

@@ -13,14 +13,9 @@
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/Stream.hpp>
#include <Nazara/Core/String.hpp>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
#include <ctime>
#include <filesystem>
#include <fstream>
namespace Nz
{
@@ -30,13 +25,13 @@ namespace Nz
{
public:
File();
File(const String& filePath);
File(const String& filePath, OpenModeFlags openMode);
File(const std::filesystem::path& filePath);
File(const std::filesystem::path& filePath, OpenModeFlags openMode);
File(const File&) = delete;
File(File&& file) noexcept = default;
File(File&& file) noexcept;
~File();
bool Copy(const String& newFilePath);
void Copy(const std::filesystem::path& newFilePath);
void Close();
bool Delete();
@@ -46,56 +41,35 @@ namespace Nz
bool Exists() const;
time_t GetCreationTime() const;
UInt64 GetCursorPos() const override;
String GetDirectory() const override;
String GetFileName() const;
time_t GetLastAccessTime() const;
time_t GetLastWriteTime() const;
String GetPath() const override;
std::filesystem::path GetDirectory() const override;
std::filesystem::path GetFileName() const;
std::filesystem::path GetPath() const override;
UInt64 GetSize() const override;
bool IsOpen() const;
bool Open(OpenModeFlags openMode = OpenMode_NotOpen);
bool Open(const String& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
bool Rename(const String& newFilePath);
bool Open(const std::filesystem::path& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
bool SetCursorPos(CursorPosition pos, Int64 offset = 0);
bool SetCursorPos(UInt64 offset) override;
bool SetFile(const String& filePath);
bool SetFile(const std::filesystem::path& filePath);
bool SetSize(UInt64 size);
File& operator=(const String& filePath);
File& operator=(const File&) = delete;
File& operator=(File&& file) noexcept = default;
File& operator=(File&& file) noexcept;
static String AbsolutePath(const String& filePath);
static inline ByteArray ComputeHash(HashType hash, const String& filePath);
static inline ByteArray ComputeHash(AbstractHash* hash, const String& filePath);
static bool Copy(const String& sourcePath, const String& targetPath);
static bool Delete(const String& filePath);
static bool Exists(const String& filePath);
static time_t GetCreationTime(const String& filePath);
static String GetDirectory(const String& filePath);
static time_t GetLastAccessTime(const String& filePath);
static time_t GetLastWriteTime(const String& filePath);
static UInt64 GetSize(const String& filePath);
static bool IsAbsolute(const String& filePath);
static String NormalizePath(const String& filePath);
static String NormalizeSeparators(const String& filePath);
static bool Rename(const String& sourcePath, const String& targetPath);
static inline ByteArray ComputeHash(HashType hash, const std::filesystem::path& filePath);
static inline ByteArray ComputeHash(AbstractHash* hash, const std::filesystem::path& filePath);
private:
NazaraMutexAttrib(m_mutex, mutable)
void FlushStream() override;
std::size_t ReadBlock(void* buffer, std::size_t size) override;
std::size_t WriteBlock(const void* buffer, std::size_t size) override;
String m_filePath;
MovablePtr<FileImpl> m_impl;
std::filesystem::path m_filePath;
std::unique_ptr<FileImpl> m_impl;
};
NAZARA_CORE_API bool HashAppend(AbstractHash* hash, const File& originalFile);

View File

@@ -15,7 +15,7 @@ namespace Nz
* \param filePath Path for the file
*/
inline ByteArray File::ComputeHash(HashType hash, const String& filePath)
inline ByteArray File::ComputeHash(HashType hash, const std::filesystem::path& filePath)
{
return ComputeHash(AbstractHash::Get(hash).get(), filePath);
}
@@ -28,7 +28,7 @@ namespace Nz
* \param filePath Path for the file
*/
inline ByteArray File::ComputeHash(AbstractHash* hash, const String& filePath)
inline ByteArray File::ComputeHash(AbstractHash* hash, const std::filesystem::path& filePath)
{
return Nz::ComputeHash(hash, File(filePath));
}

View File

@@ -9,8 +9,9 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/AbstractLogger.hpp>
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/StdLogger.hpp>
#include <filesystem>
#include <fstream>
namespace Nz
{
@@ -19,7 +20,7 @@ namespace Nz
public:
FileLogger(const String& logPath = "NazaraLog.log");
FileLogger(const FileLogger&) = default;
FileLogger(FileLogger&&) noexcept = default;
FileLogger(FileLogger&&) = default;
~FileLogger();
void EnableTimeLogging(bool enable);
@@ -32,10 +33,11 @@ namespace Nz
void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override;
FileLogger& operator=(const FileLogger&) = default;
FileLogger& operator=(FileLogger&&) noexcept = default;
FileLogger& operator=(FileLogger&&) = default;
private:
File m_outputFile;
std::fstream m_outputFile;
std::filesystem::path m_outputPath;
StdLogger m_stdLogger;
bool m_forceStdOutput;
bool m_stdReplicationEnabled;

View File

@@ -1,34 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_LOCKGUARD_HPP
#define NAZARA_LOCKGUARD_HPP
#include <Nazara/Prerequisites.hpp>
namespace Nz
{
class Mutex;
class LockGuard
{
public:
inline LockGuard(Mutex& mutex, bool lock = true);
inline ~LockGuard();
inline void Lock();
inline bool TryLock();
inline void Unlock();
private:
Mutex& m_mutex;
bool m_locked;
};
}
#include <Nazara/Core/LockGuard.inl>
#endif // NAZARA_LOCKGUARD_HPP

View File

@@ -1,83 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
/*!
* \ingroup core
* \class Nz::LockGuard
* \brief Core class that represents a mutex wrapper that provides a convenient RAII-style mechanism
*/
/*!
* \brief Constructs a LockGuard object with a mutex
*
* \param mutex Mutex to lock
* \param lock Should the mutex be locked by the constructor
*/
inline LockGuard::LockGuard(Mutex& mutex, bool lock) :
m_mutex(mutex),
m_locked(false)
{
if (lock)
{
m_mutex.Lock();
m_locked = true;
}
}
/*!
* \brief Destructs a LockGuard object and unlocks the mutex if it was previously locked
*/
inline LockGuard::~LockGuard()
{
if (m_locked)
m_mutex.Unlock();
}
/*!
* \brief Locks the underlying mutex
*
* \see Mutex::Lock
*/
inline void LockGuard::Lock()
{
NazaraAssert(!m_locked, "Mutex is already locked");
m_mutex.Lock();
}
/*!
* \brief Tries to lock the underlying mutex
*
* \see Mutex::TryLock
*
* \return true if the lock was acquired successfully
*/
inline bool LockGuard::TryLock()
{
NazaraAssert(!m_locked, "Mutex is already locked");
return m_mutex.TryLock();
}
/*!
* \brief Unlocks the underlying mutex
*
* \see Mutex::Unlock
*/
inline void LockGuard::Unlock()
{
NazaraAssert(m_locked, "Mutex is not locked");
m_mutex.Unlock();
}
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -11,12 +11,6 @@
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Core/String.hpp>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_LOG
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
#ifdef NAZARA_DEBUG
#define NazaraDebug(txt) NazaraNotice(txt)
#else

View File

@@ -1,41 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_MUTEX_HPP
#define NAZARA_MUTEX_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
namespace Nz
{
class MutexImpl;
class NAZARA_CORE_API Mutex
{
friend class ConditionVariable;
public:
Mutex();
Mutex(const Mutex&) = delete;
Mutex(Mutex&&) noexcept = default;
~Mutex();
void Lock();
bool TryLock();
void Unlock();
Mutex& operator=(const Mutex&) = delete;
Mutex& operator=(Mutex&&) noexcept = default;
private:
MovablePtr<MutexImpl> m_impl;
};
}
#include <Nazara/Core/Mutex.inl>
#endif // NAZARA_MUTEX_HPP

View File

@@ -1,17 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
/*!
* \ingroup core
* \class Nz::Mutex
*/
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -9,7 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/String.hpp>
#include <filesystem>
#include <set>
#include <unordered_map>
@@ -24,23 +24,32 @@ namespace Nz
PluginManager() = delete;
~PluginManager() = delete;
static void AddDirectory(const String& directoryPath);
static void AddDirectory(const std::filesystem::path& directoryPath);
static bool Initialize();
static bool Mount(Plugin plugin);
static bool Mount(const String& pluginPath, bool appendExtension = true);
static bool Mount(const std::filesystem::path& pluginPath, bool appendExtension = true);
static void RemoveDirectory(const String& directoryPath);
static void RemoveDirectory(const std::filesystem::path& directoryPath);
static void Unmount(Plugin plugin);
static void Unmount(const String& pluginPath);
static void Unmount(const std::filesystem::path& pluginPath);
static void Uninitialize();
private:
static std::set<String> s_directories;
static std::unordered_map<String, DynLib*> s_plugins;
// https://stackoverflow.com/questions/51065244/is-there-no-standard-hash-for-stdfilesystempath
struct PathHash
{
std::size_t operator()(const std::filesystem::path& p) const
{
return hash_value(p);
}
};
static std::set<std::filesystem::path> s_directories;
static std::unordered_map<std::filesystem::path, std::unique_ptr<DynLib>, PathHash> s_plugins;
static bool s_initialized;
};
}

View File

@@ -10,12 +10,6 @@
#include <Nazara/Prerequisites.hpp>
#include <atomic>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_REFCOUNTED
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
namespace Nz
{
class NAZARA_CORE_API RefCounted

View File

@@ -8,7 +8,7 @@
#define NAZARA_RESOURCE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/String.hpp>
#include <filesystem>
namespace Nz
{
@@ -20,15 +20,15 @@ namespace Nz
Resource(Resource&&) noexcept = default;
virtual ~Resource();
const String& GetFilePath() const;
const std::filesystem::path& GetFilePath() const;
void SetFilePath(const String& filePath);
void SetFilePath(const std::filesystem::path& filePath);
Resource& operator=(const Resource&) = default;
Resource& operator=(Resource&&) noexcept = default;
private:
String m_filePath;
std::filesystem::path m_filePath;
};
}

View File

@@ -12,7 +12,7 @@
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <Nazara/Core/String.hpp>
#include <filesystem>
#include <list>
#include <tuple>
#include <type_traits>
@@ -29,8 +29,8 @@ namespace Nz
friend Type;
public:
using ExtensionGetter = bool (*)(const String& extension);
using FileLoader = ObjectRef<Type> (*)(const String& filePath, const Parameters& parameters);
using ExtensionGetter = bool (*)(const std::string& extension);
using FileLoader = ObjectRef<Type> (*)(const std::filesystem::path& filePath, const Parameters& parameters);
using MemoryLoader = ObjectRef<Type> (*)(const void* data, std::size_t size, const Parameters& parameters);
using StreamChecker = Ternary (*)(Stream& stream, const Parameters& parameters);
using StreamLoader = ObjectRef<Type> (*)(Stream& stream, const Parameters& parameters);
@@ -38,9 +38,9 @@ namespace Nz
ResourceLoader() = delete;
~ResourceLoader() = delete;
static bool IsExtensionSupported(const String& extension);
static bool IsExtensionSupported(const std::string& extension);
static ObjectRef<Type> LoadFromFile(const String& filePath, const Parameters& parameters = Parameters());
static ObjectRef<Type> LoadFromFile(const std::filesystem::path& filePath, const Parameters& parameters = Parameters());
static ObjectRef<Type> LoadFromMemory(const void* data, std::size_t size, const Parameters& parameters = Parameters());
static ObjectRef<Type> LoadFromStream(Stream& stream, const Parameters& parameters = Parameters());

View File

@@ -7,6 +7,7 @@
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/Core/Stream.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
@@ -24,7 +25,7 @@ namespace Nz
* \param extension Extension of the file
*/
template<typename Type, typename Parameters>
bool ResourceLoader<Type, Parameters>::IsExtensionSupported(const String& extension)
bool ResourceLoader<Type, Parameters>::IsExtensionSupported(const std::string& extension)
{
for (Loader& loader : Type::s_loaders)
{
@@ -53,19 +54,21 @@ namespace Nz
* \remark Produces a NazaraError if all loaders failed or no loader was found
*/
template<typename Type, typename Parameters>
ObjectRef<Type> ResourceLoader<Type, Parameters>::LoadFromFile(const String& filePath, const Parameters& parameters)
ObjectRef<Type> ResourceLoader<Type, Parameters>::LoadFromFile(const std::filesystem::path& filePath, const Parameters& parameters)
{
NazaraAssert(parameters.IsValid(), "Invalid parameters");
String path = File::NormalizePath(filePath);
String ext = path.SubStringFrom('.', -1, true).ToLower();
if (ext.IsEmpty())
std::string ext = ToLower(filePath.extension().generic_u8string());
if (ext.empty())
{
NazaraError("Failed to get file extension from \"" + filePath + '"');
NazaraError("Failed to get file extension from \"" + filePath.generic_u8string() + '"');
return nullptr;
}
File file(path); // Open only if needed
if (ext[0] == '.')
ext.erase(ext.begin());
File file(filePath.generic_u8string()); // Open only if needed
bool found = false;
for (Loader& loader : Type::s_loaders)
@@ -82,7 +85,7 @@ namespace Nz
{
if (!file.Open(OpenMode_ReadOnly))
{
NazaraError("Failed to load file: unable to open \"" + filePath + '"');
NazaraError("Failed to load file: unable to open \"" + filePath.generic_u8string() + '"');
return nullptr;
}
}

View File

@@ -25,19 +25,28 @@ namespace Nz
static void Clear();
static ObjectRef<Type> Get(const String& filePath);
static ObjectRef<Type> Get(const std::filesystem::path& filePath);
static const Parameters& GetDefaultParameters();
static void Purge();
static void Register(const String& filePath, ObjectRef<Type> resource);
static void Register(const std::filesystem::path& filePath, ObjectRef<Type> resource);
static void SetDefaultParameters(const Parameters& params);
static void Unregister(const String& filePath);
static void Unregister(const std::filesystem::path& filePath);
private:
static bool Initialize();
static void Uninitialize();
using ManagerMap = std::unordered_map<String, ObjectRef<Type>>;
// https://stackoverflow.com/questions/51065244/is-there-no-standard-hash-for-stdfilesystempath
struct PathHash
{
std::size_t operator()(const std::filesystem::path& p) const
{
return hash_value(p);
}
};
using ManagerMap = std::unordered_map<std::filesystem::path, ObjectRef<Type>, PathHash>;
using ManagerParams = Parameters;
};
}

View File

@@ -31,20 +31,20 @@ namespace Nz
* \param filePath Path to the asset that will be loaded
*/
template<typename Type, typename Parameters>
ObjectRef<Type> ResourceManager<Type, Parameters>::Get(const String& filePath)
ObjectRef<Type> ResourceManager<Type, Parameters>::Get(const std::filesystem::path& filePath)
{
String absolutePath = File::AbsolutePath(filePath);
std::filesystem::path absolutePath = std::filesystem::canonical(filePath);
auto it = Type::s_managerMap.find(absolutePath);
if (it == Type::s_managerMap.end())
{
ObjectRef<Type> resource = Type::LoadFromFile(absolutePath, GetDefaultParameters());
if (!resource)
{
NazaraError("Failed to load resource from file: " + absolutePath);
NazaraError("Failed to load resource from file: " + absolutePath.generic_u8string());
return ObjectRef<Type>();
}
NazaraDebug("Loaded resource from file " + absolutePath);
NazaraDebug("Loaded resource from file " + absolutePath.generic_u8string());
it = Type::s_managerMap.insert(std::make_pair(absolutePath, resource)).first;
}
@@ -74,7 +74,7 @@ namespace Nz
const ObjectRef<Type>& ref = it->second;
if (ref->GetReferenceCount() == 1) // Are we the only ones to own the resource ?
{
NazaraDebug("Purging resource from file " + ref->GetFilePath());
NazaraDebug("Purging resource from file " + ref->GetFilePath().generic_u8string());
Type::s_managerMap.erase(it++); // Then we erase it
}
else
@@ -89,9 +89,9 @@ namespace Nz
* \param resource Object to associate with
*/
template<typename Type, typename Parameters>
void ResourceManager<Type, Parameters>::Register(const String& filePath, ObjectRef<Type> resource)
void ResourceManager<Type, Parameters>::Register(const std::filesystem::path& filePath, ObjectRef<Type> resource)
{
String absolutePath = File::AbsolutePath(filePath);
std::filesystem::path absolutePath = std::filesystem::canonical(filePath);
Type::s_managerMap[absolutePath] = resource;
}
@@ -113,9 +113,9 @@ namespace Nz
* \param filePath Path for the resource
*/
template<typename Type, typename Parameters>
void ResourceManager<Type, Parameters>::Unregister(const String& filePath)
void ResourceManager<Type, Parameters>::Unregister(const std::filesystem::path& filePath)
{
String absolutePath = File::AbsolutePath(filePath);
std::filesystem::path absolutePath = std::filesystem::canonical(filePath);
Type::s_managerMap.erase(absolutePath);
}

View File

@@ -11,6 +11,7 @@
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <Nazara/Core/String.hpp>
#include <filesystem>
#include <list>
#include <tuple>
#include <type_traits>
@@ -27,18 +28,18 @@ namespace Nz
friend Type;
public:
using ExtensionGetter = bool (*)(const String& extension);
using FormatQuerier = bool (*)(const String& format);
using FileSaver = bool (*)(const Type& resource, const String& filePath, const Parameters& parameters);
using StreamSaver = bool (*)(const Type& resource, const String& format, Stream& stream, const Parameters& parameters);
using ExtensionGetter = bool (*)(const std::string& extension);
using FormatQuerier = bool (*)(const std::string& format);
using FileSaver = bool (*)(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters);
using StreamSaver = bool (*)(const Type& resource, const std::string& format, Stream& stream, const Parameters& parameters);
ResourceSaver() = delete;
~ResourceSaver() = delete;
static bool IsFormatSupported(const String& extension);
static bool IsFormatSupported(const std::string& extension);
static bool SaveToFile(const Type& resource, const String& filePath, const Parameters& parameters = Parameters());
static bool SaveToStream(const Type& resource, Stream& stream, const String& format, const Parameters& parameters = Parameters());
static bool SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters = Parameters());
static bool SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters = Parameters());
static void RegisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver = nullptr);
static void UnregisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver = nullptr);

View File

@@ -7,6 +7,7 @@
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/Core/Stream.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
@@ -24,7 +25,7 @@ namespace Nz
* \param extension Extension of the file
*/
template<typename Type, typename Parameters>
bool ResourceSaver<Type, Parameters>::IsFormatSupported(const String& extension)
bool ResourceSaver<Type, Parameters>::IsFormatSupported(const std::string& extension)
{
for (Saver& saver : Type::s_savers)
{
@@ -51,19 +52,18 @@ namespace Nz
* \see SaveToStream
*/
template<typename Type, typename Parameters>
bool ResourceSaver<Type, Parameters>::SaveToFile(const Type& resource, const String& filePath, const Parameters& parameters)
bool ResourceSaver<Type, Parameters>::SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters)
{
NazaraAssert(parameters.IsValid(), "Invalid parameters");
String path = File::NormalizePath(filePath);
String ext = path.SubStringFrom('.', -1, true).ToLower();
if (ext.IsEmpty())
std::string ext = ToLower(filePath.extension().generic_u8string());
if (ext.empty())
{
NazaraError("Failed to get file extension from \"" + filePath + '"');
NazaraError("Failed to get file extension from \"" + filePath.generic_u8string() + '"');
return false;
}
File file(path); // Opened only is required
File file(filePath.generic_u8string()); // Opened only is required
bool found = false;
for (Saver& saver : Type::s_savers)
@@ -86,7 +86,7 @@ namespace Nz
{
if (!file.Open(OpenMode_WriteOnly | OpenMode_Truncate))
{
NazaraError("Failed to save to file: unable to open \"" + filePath + "\" in write mode");
NazaraError("Failed to save to file: unable to open \"" + filePath.generic_u8string() + "\" in write mode");
return false;
}
@@ -117,7 +117,7 @@ namespace Nz
* \see SaveToFile
*/
template<typename Type, typename Parameters>
bool ResourceSaver<Type, Parameters>::SaveToStream(const Type& resource, Stream& stream, const String& format, const Parameters& parameters)
bool ResourceSaver<Type, Parameters>::SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters)
{
NazaraAssert(stream.IsWritable(), "Stream is not writable");
NazaraAssert(parameters.IsValid(), "Invalid parameters");

View File

@@ -1,40 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SEMAPHORE_HPP
#define NAZARA_SEMAPHORE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
namespace Nz
{
class SemaphoreImpl;
class NAZARA_CORE_API Semaphore
{
public:
Semaphore(unsigned int count);
Semaphore(const Semaphore&) = delete;
Semaphore(Semaphore&&) noexcept = default;
~Semaphore();
unsigned int GetCount() const;
void Post();
void Wait();
bool Wait(UInt32 timeout);
Semaphore& operator=(const Semaphore&) = delete;
Semaphore& operator=(Semaphore&&) noexcept = default;
private:
MovablePtr<SemaphoreImpl> m_impl;
};
}
#endif // NAZARA_SEMAPHORE_HPP

View File

@@ -43,10 +43,10 @@ namespace Nz
void SetStride(int stride);
explicit operator bool() const;
operator T*() const;
explicit operator T*() const;
T& operator*() const;
T* operator->() const;
T& operator[](int index) const;
T& operator[](std::size_t index) const;
SparsePtr& operator=(const SparsePtr& ptr) = default;

View File

@@ -247,7 +247,7 @@ namespace Nz
*/
template<typename T>
T& SparsePtr<T>::operator[](int index) const
T& SparsePtr<T>::operator[](std::size_t index) const
{
return *reinterpret_cast<T*>(m_ptr + index * m_stride);
}

View File

@@ -10,11 +10,12 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/String.hpp>
#include <filesystem>
namespace Nz
{
class ByteArray;
class String; //< Do not include String.hpp in this file
class NAZARA_CORE_API Stream
{
@@ -30,15 +31,15 @@ namespace Nz
inline void Flush();
virtual UInt64 GetCursorPos() const = 0;
virtual String GetDirectory() const;
virtual String GetPath() const;
virtual std::filesystem::path GetDirectory() const;
virtual std::filesystem::path GetPath() const;
inline OpenModeFlags GetOpenMode() const;
inline StreamOptionFlags GetStreamOptions() const;
virtual UInt64 GetSize() const = 0;
inline std::size_t Read(void* buffer, std::size_t size);
virtual String ReadLine(unsigned int lineSize = 0);
virtual std::string ReadLine(unsigned int lineSize = 0);
inline bool IsReadable() const;
inline bool IsSequential() const;

View File

@@ -0,0 +1,61 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CORE_STRING_EXT_HPP
#define NAZARA_CORE_STRING_EXT_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Unicode.hpp>
#include <string>
namespace Nz
{
struct CaseIndependent {};
struct UnicodeAware {};
// std::string is assumed to contains UTF-8
NAZARA_CORE_API std::string FromUtf16String(const char16_t* u16str);
NAZARA_CORE_API std::string FromUtf16String(const std::u16string_view& u16str);
NAZARA_CORE_API std::string FromUtf32String(const char32_t* u32str);
NAZARA_CORE_API std::string FromUtf32String(const std::u32string_view& u32str);
NAZARA_CORE_API std::string FromWideString(const wchar_t* wstr);
NAZARA_CORE_API std::string FromWideString(const std::wstring_view& str);
inline bool IsNumber(const char* str);
inline bool IsNumber(const std::string_view& str);
template<typename... Args> bool StartsWith(const std::string_view& str, const char* s, Args&&... args);
inline bool StartsWith(const std::string_view& str, const std::string_view& s);
NAZARA_CORE_API bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent);
NAZARA_CORE_API bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent, UnicodeAware);
inline std::string ToLower(const char* str);
NAZARA_CORE_API std::string ToLower(const std::string_view& str);
inline std::string ToLower(const char* str, UnicodeAware);
NAZARA_CORE_API std::string ToLower(const std::string_view& str, UnicodeAware);
inline std::string ToUpper(const char* str);
NAZARA_CORE_API std::string ToUpper(const std::string_view& str);
inline std::string ToUpper(const char* str, UnicodeAware);
NAZARA_CORE_API std::string ToUpper(const std::string_view& str, UnicodeAware);
inline std::u16string ToUtf16String(const char* str);
NAZARA_CORE_API std::u16string ToUtf16String(const std::string_view& str);
inline std::u32string ToUtf32String(const char* str);
NAZARA_CORE_API std::u32string ToUtf32String(const std::string_view& str);
inline std::wstring ToWideString(const char* str);
NAZARA_CORE_API std::wstring ToWideString(const std::string_view& str);
}
#include <Nazara/Core/StringExt.inl>
#endif // NAZARA_ALGORITHM_CORE_HPP

View File

@@ -0,0 +1,85 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/StringExt.hpp>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
bool IsNumber(const char* str)
{
std::size_t size = std::strlen(str);
return IsNumber(std::string_view(str, size));
}
bool IsNumber(const std::string_view& str)
{
return !str.empty() && std::find_if(str.begin(), str.end(), [](unsigned char c) { return !std::isdigit(c); }) == str.end();
}
template<typename... Args> bool StartsWith(const std::string_view& str, const char* s, Args&&... args)
{
std::size_t size = std::strlen(s);
return StartsWith(str, std::string_view(s, size), std::forward<Args>(args)...);
}
bool StartsWith(const std::string_view& str, const std::string_view& s)
{
//FIXME: Replace with proper C++20 value once it's available
#if __cplusplus > 201703L
// C++20
return str.starts_with(s);
#else
return str.compare(0, s.size(), s.data()) == 0;
#endif
}
inline std::string ToLower(const char* str)
{
std::size_t size = std::strlen(str);
return ToLower(std::string_view(str, size));
}
inline std::string ToLower(const char* str, UnicodeAware)
{
std::size_t size = std::strlen(str);
return ToLower(std::string_view(str, size), UnicodeAware{});
}
inline std::string ToUpper(const char* str)
{
std::size_t size = std::strlen(str);
return ToUpper(std::string_view(str, size));
}
inline std::string ToUpper(const char* str, UnicodeAware)
{
std::size_t size = std::strlen(str);
return ToUpper(std::string_view(str, size), UnicodeAware{});
}
inline std::u16string ToUtf16String(const char* str)
{
std::size_t size = std::strlen(str);
return ToUtf16String(std::string_view(str, size));
}
inline std::u32string ToUtf32String(const char* str)
{
std::size_t size = std::strlen(str);
return ToUtf32String(std::string_view(str, size));
}
inline std::wstring ToWideString(const char* str)
{
std::size_t size = std::strlen(str);
return ToWideString(std::string_view(str, size));
}
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -1,75 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_THREAD_HPP
#define NAZARA_THREAD_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Functor.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <iosfwd>
namespace Nz
{
class String;
class ThreadImpl;
class NAZARA_CORE_API Thread
{
public:
class Id;
Thread();
template<typename F> Thread(F function);
template<typename F, typename... Args> Thread(F function, Args&&... args);
template<typename C> Thread(void (C::*function)(), C* object);
Thread(const Thread&) = delete;
Thread(Thread&& other) noexcept = default;
~Thread();
void Detach();
Id GetId() const;
bool IsJoinable() const;
void Join();
void SetName(const String& name);
Thread& operator=(const Thread&) = delete;
Thread& operator=(Thread&& thread) noexcept = default;
static unsigned int HardwareConcurrency();
static void SetCurrentThreadName(const String& name);
static void Sleep(UInt32 milliseconds);
private:
void CreateImpl(Functor* functor);
MovablePtr<ThreadImpl> m_impl;
};
class NAZARA_CORE_API Thread::Id
{
friend Thread;
public:
NAZARA_CORE_API friend bool operator==(const Id& lhs, const Id& rhs);
NAZARA_CORE_API friend bool operator!=(const Id& lhs, const Id& rhs);
NAZARA_CORE_API friend bool operator<(const Id& lhs, const Id& rhs);
NAZARA_CORE_API friend bool operator<=(const Id& lhs, const Id& rhs);
NAZARA_CORE_API friend bool operator>(const Id& lhs, const Id& rhs);
NAZARA_CORE_API friend bool operator>=(const Id& lhs, const Id& rhs);
NAZARA_CORE_API friend std::ostream& operator<<(std::ostream& o, const Id& id);
private:
explicit Id(ThreadImpl* thread);
ThreadImpl* m_id = nullptr;
};
}
#include <Nazara/Core/Thread.inl>
#endif // NAZARA_THREAD_HPP

View File

@@ -1,55 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <utility>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
/*!
* \ingroup core
* \class Nz::Thread
* \brief Core class that represents a thread
*/
/*!
* \brief Constructs a Thread object with a function
*
* \param function Task the thread will execute in parallel
*/
template<typename F>
Thread::Thread(F function)
{
CreateImpl(new FunctorWithoutArgs<F>(function));
}
/*!
* \brief Constructs a Thread object with a function and its parameters
*
* \param function Task the thread will execute in parallel
* \param args Arguments of the function
*/
template<typename F, typename... Args>
Thread::Thread(F function, Args&&... args)
{
CreateImpl(new FunctorWithArgs<F, Args...>(function, std::forward<Args>(args)...));
}
/*!
* \brief Constructs a Thread object with a member function and its object
*
* \param function Task the thread will execute in parallel
* \param object Object on which the method will be called
*/
template<typename C>
Thread::Thread(void (C::*function)(), C* object)
{
CreateImpl(new MemberWithoutArgs<C>(function, object));
}
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -1,23 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// No header guard
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Core/Mutex.hpp>
// These macroes can change for any file which uses it in the same unit of compilation
#undef NazaraLock
#undef NazaraMutex
#undef NazaraMutexAttrib
#undef NazaraMutexLock
#undef NazaraMutexUnlock
#undef NazaraNamedLock
#define NazaraLock(mutex) Nz::LockGuard lock_mutex(mutex);
#define NazaraMutex(name) Nz::Mutex name;
#define NazaraMutexAttrib(name, attribute) attribute Mutex name;
#define NazaraMutexLock(mutex) mutex.Lock();
#define NazaraMutexUnlock(mutex) mutex.Unlock();
#define NazaraNamedLock(mutex, name) Nz::LockGuard lock_##name(mutex);

View File

@@ -1,21 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// No header guard
// These macroes can change for any file which uses it in the same unit of compilation
#undef NazaraLock
#undef NazaraMutex
#undef NazaraMutexAttrib
#undef NazaraMutexLock
#undef NazaraMutexUnlock
#undef NazaraNamedLock
#define NazaraLock(mutex)
#define NazaraMutex(name)
#define NazaraMutexAttrib(name, attribute)
#define NazaraMutexLock(mutex)
#define NazaraMutexUnlock(mutex)
#define NazaraNamedLock(mutex, name)

View File

@@ -17,7 +17,6 @@
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/MaterialPipeline.hpp>
@@ -35,7 +34,7 @@ namespace Nz
bool loadHeightMap = true;
bool loadNormalMap = true;
bool loadSpecularMap = true;
String shaderName = "Basic";
std::string shaderName = "Basic";
bool IsValid() const;
};
@@ -59,7 +58,7 @@ namespace Nz
inline Material();
inline Material(const MaterialPipeline* pipeline);
inline Material(const MaterialPipelineInfo& pipelineInfo);
inline Material(const String& pipelineName);
inline Material(const std::string& pipelineName);
inline Material(const Material& material);
inline ~Material();
@@ -69,7 +68,7 @@ namespace Nz
inline void Configure(const MaterialPipeline* pipeline);
inline void Configure(const MaterialPipelineInfo& pipelineInfo);
inline bool Configure(const String& pipelineName);
inline bool Configure(const std::string& pipelineName);
inline void EnableAlphaTest(bool alphaTest);
inline void EnableBlending(bool blending);
@@ -141,33 +140,33 @@ namespace Nz
void SaveToParameters(ParameterList* matData);
inline bool SetAlphaMap(const String& textureName);
inline bool SetAlphaMap(const std::string& textureName);
inline void SetAlphaMap(TextureRef alphaMap);
inline void SetAlphaThreshold(float alphaThreshold);
inline void SetAmbientColor(const Color& ambient);
inline void SetDepthFunc(RendererComparison depthFunc);
inline void SetDepthMaterial(MaterialRef depthMaterial);
inline void SetDiffuseColor(const Color& diffuse);
inline bool SetDiffuseMap(const String& textureName);
inline bool SetDiffuseMap(const std::string& textureName);
inline void SetDiffuseMap(TextureRef diffuseMap);
inline void SetDiffuseSampler(const TextureSampler& sampler);
inline void SetDstBlend(BlendFunc func);
inline bool SetEmissiveMap(const String& textureName);
inline bool SetEmissiveMap(const std::string& textureName);
inline void SetEmissiveMap(TextureRef textureName);
inline void SetFaceCulling(FaceSide faceSide);
inline void SetFaceFilling(FaceFilling filling);
inline bool SetHeightMap(const String& textureName);
inline bool SetHeightMap(const std::string& textureName);
inline void SetHeightMap(TextureRef textureName);
inline void SetLineWidth(float lineWidth);
inline bool SetNormalMap(const String& textureName);
inline bool SetNormalMap(const std::string& textureName);
inline void SetNormalMap(TextureRef textureName);
inline void SetPointSize(float pointSize);
inline void SetReflectionMode(ReflectionMode reflectionMode);
inline void SetShader(UberShaderConstRef uberShader);
inline bool SetShader(const String& uberShaderName);
inline bool SetShader(const std::string& uberShaderName);
inline void SetShininess(float shininess);
inline void SetSpecularColor(const Color& specular);
inline bool SetSpecularMap(const String& textureName);
inline bool SetSpecularMap(const std::string& textureName);
inline void SetSpecularMap(TextureRef specularMap);
inline void SetSpecularSampler(const TextureSampler& sampler);
inline void SetSrcBlend(BlendFunc func);
@@ -177,7 +176,7 @@ namespace Nz
inline static MaterialRef GetDefault();
inline static int GetTextureUnit(TextureMap textureMap);
static inline MaterialRef LoadFromFile(const String& filePath, const MaterialParams& params = MaterialParams());
static inline MaterialRef LoadFromFile(const std::filesystem::path& filePath, const MaterialParams& params = MaterialParams());
static inline MaterialRef LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams());
static inline MaterialRef LoadFromStream(Stream& stream, const MaterialParams& params = MaterialParams());

View File

@@ -57,7 +57,7 @@ namespace Nz
*
* \see Configure
*/
inline Material::Material(const String& pipelineName)
inline Material::Material(const std::string& pipelineName)
{
ErrorFlags errFlags(ErrorFlag_ThrowException, true);
@@ -139,7 +139,7 @@ namespace Nz
*
* \see Configure
*/
inline bool Material::Configure(const String& pipelineName)
inline bool Material::Configure(const std::string& pipelineName)
{
MaterialPipelineRef pipeline = MaterialPipelineLibrary::Query(pipelineName);
if (!pipeline)
@@ -909,7 +909,7 @@ namespace Nz
*
* \param textureName Named texture
*/
inline bool Material::SetAlphaMap(const String& textureName)
inline bool Material::SetAlphaMap(const std::string& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
@@ -1005,7 +1005,7 @@ namespace Nz
*
* \remark Invalidates the pipeline
*/
inline bool Material::SetDiffuseMap(const String& textureName)
inline bool Material::SetDiffuseMap(const std::string& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
@@ -1071,7 +1071,7 @@ namespace Nz
*
* \see GetEmissiveMap
*/
inline bool Material::SetEmissiveMap(const String& textureName)
inline bool Material::SetEmissiveMap(const std::string& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
@@ -1140,7 +1140,7 @@ namespace Nz
*
* \see GetHeightMap
*/
inline bool Material::SetHeightMap(const String& textureName)
inline bool Material::SetHeightMap(const std::string& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
@@ -1202,7 +1202,7 @@ namespace Nz
*
* \see GetNormalMap
*/
inline bool Material::SetNormalMap(const String& textureName)
inline bool Material::SetNormalMap(const std::string& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
@@ -1305,7 +1305,7 @@ namespace Nz
*
* \param uberShaderName Named shader
*/
inline bool Material::SetShader(const String& uberShaderName)
inline bool Material::SetShader(const std::string& uberShaderName)
{
UberShaderConstRef uberShader = UberShaderLibrary::Get(uberShaderName);
if (!uberShader)
@@ -1343,7 +1343,7 @@ namespace Nz
*
* \remark Invalidates the pipeline
*/
inline bool Material::SetSpecularMap(const String& textureName)
inline bool Material::SetSpecularMap(const std::string& textureName)
{
TextureRef texture = TextureLibrary::Query(textureName);
if (!texture)
@@ -1444,7 +1444,7 @@ namespace Nz
* \param filePath Path to the file
* \param params Parameters for the material
*/
inline MaterialRef Material::LoadFromFile(const String& filePath, const MaterialParams& params)
inline MaterialRef Material::LoadFromFile(const std::filesystem::path& filePath, const MaterialParams& params)
{
return MaterialLoader::LoadFromFile(filePath, params);
}

View File

@@ -59,22 +59,22 @@ namespace Nz
std::unique_ptr<InstancedRenderable> Clone() const override;
using InstancedRenderable::GetMaterial;
const MaterialRef& GetMaterial(const String& subMeshName) const;
const MaterialRef& GetMaterial(std::size_t skinIndex, const String& subMeshName) const;
const MaterialRef& GetMaterial(const std::string& subMeshName) const;
const MaterialRef& GetMaterial(std::size_t skinIndex, const std::string& subMeshName) const;
Mesh* GetMesh() const;
virtual bool IsAnimated() const;
using InstancedRenderable::SetMaterial;
bool SetMaterial(const String& subMeshName, MaterialRef material);
bool SetMaterial(std::size_t skinIndex, const String& subMeshName, MaterialRef material);
bool SetMaterial(const std::string& subMeshName, MaterialRef material);
bool SetMaterial(std::size_t skinIndex, const std::string& subMeshName, MaterialRef material);
virtual void SetMesh(Mesh* mesh);
Model& operator=(const Model& node) = default;
Model& operator=(Model&& node) = delete;
static ModelRef LoadFromFile(const String& filePath, const ModelParameters& params = ModelParameters());
static ModelRef LoadFromFile(const std::filesystem::path& filePath, const ModelParameters& params = ModelParameters());
static ModelRef LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters());
static ModelRef LoadFromStream(Stream& stream, const ModelParameters& params = ModelParameters());

View File

@@ -47,15 +47,15 @@ namespace Nz
inline void SetCornerColor(RectCorner corner, const Color& color);
inline void SetDefaultMaterial();
inline void SetMaterial(MaterialRef material, bool resizeSprite = true);
bool SetMaterial(String materialName, bool resizeSprite = true);
bool SetMaterial(std::string materialName, bool resizeSprite = true);
inline void SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeSprite = true);
bool SetMaterial(std::size_t skinIndex, String materialName, bool resizeSprite = true);
bool SetMaterial(std::size_t skinIndex, std::string materialName, bool resizeSprite = true);
inline void SetOrigin(const Vector3f& origin);
inline void SetSize(const Vector2f& size);
inline void SetSize(float sizeX, float sizeY);
bool SetTexture(String textureName, bool resizeSprite = true);
bool SetTexture(std::string textureName, bool resizeSprite = true);
inline void SetTexture(TextureRef texture, bool resizeSprite = true);
bool SetTexture(std::size_t skinIndex, String textureName, bool resizeSprite = true);
bool SetTexture(std::size_t skinIndex, std::string textureName, bool resizeSprite = true);
inline void SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeSprite = true);
inline void SetTextureCoords(const Rectf& coords);
inline void SetTextureRect(const Rectui& rect);

View File

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

View File

@@ -1,51 +0,0 @@
/*
Nazara Engine - Lua scripting module
Copyright (C) 2015 Jérôme Leclercq (lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_LUA_HPP
#define NAZARA_CONFIG_LUA_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// 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)
#define NAZARA_LUA_MANAGE_MEMORY 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_LUA_SAFE 1
/// Vérification des valeurs et types de certaines constantes
#include <Nazara/Lua/ConfigCheck.hpp>
#if defined(NAZARA_STATIC)
#define NAZARA_LUA_API
#else
#ifdef NAZARA_LUA_BUILD
#define NAZARA_LUA_API NAZARA_EXPORT
#else
#define NAZARA_LUA_API NAZARA_IMPORT
#endif
#endif
#endif // NAZARA_CONFIG_LUA_HPP

View File

@@ -1,18 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CONFIG_CHECK_LUA_HPP
#define NAZARA_CONFIG_CHECK_LUA_HPP
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
// On force la valeur de MANAGE_MEMORY en mode debug
#if defined(NAZARA_DEBUG) && !NAZARA_LUA_MANAGE_MEMORY
#undef NAZARA_LUA_MANAGE_MEMORY
#define NAZARA_LUA_MANAGE_MEMORY 0
#endif
#endif // NAZARA_CONFIG_CHECK_LUA_HPP

View File

@@ -1,8 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Lua/Config.hpp>
#if NAZARA_LUA_MANAGE_MEMORY
#include <Nazara/Core/Debug/NewRedefinition.hpp>
#endif

View File

@@ -1,9 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
#if NAZARA_LUA_MANAGE_MEMORY
#undef delete
#undef new
#endif

View File

@@ -1,93 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ENUMS_LUA_HPP
#define NAZARA_ENUMS_LUA_HPP
#include <Nazara/Core/Flags.hpp>
namespace Nz
{
enum LuaBindMode
{
LuaBindMode_Table,
LuaBindMode_Userdata,
LuaBindMode_Max = LuaBindMode_Userdata
};
enum LuaComparison
{
LuaComparison_Equality,
LuaComparison_Less,
LuaComparison_LessOrEqual,
LuaComparison_Max = LuaComparison_LessOrEqual
};
enum LuaLib
{
LuaLib_Coroutine,
LuaLib_Debug,
LuaLib_Math,
LuaLib_Io,
LuaLib_Package,
LuaLib_Os,
LuaLib_String,
LuaLib_Table,
LuaLib_Utf8,
LuaLib_Max = LuaLib_Utf8
};
enum LuaOperation
{
LuaOperation_Addition,
LuaOperation_BitwiseAnd,
LuaOperation_BitwiseLeftShift,
LuaOperation_BitwiseNot,
LuaOperation_BitwiseOr,
LuaOperation_BitwideRightShift,
LuaOperation_BitwiseXOr,
LuaOperation_Division,
LuaOperation_Exponentiation,
LuaOperation_FloorDivision,
LuaOperation_Modulo,
LuaOperation_Multiplication,
LuaOperation_Negation,
LuaOperation_Substraction,
LuaOperation_Max = LuaOperation_Substraction
};
enum LuaType
{
LuaType_Boolean,
LuaType_Function,
LuaType_LightUserdata,
LuaType_Nil,
LuaType_Number,
LuaType_None,
LuaType_String,
LuaType_Table,
LuaType_Thread,
LuaType_Userdata,
LuaType_Max = LuaType_Userdata
};
template<>
struct EnumAsFlags<LuaLib>
{
static constexpr LuaLib max = LuaLib_Max;
};
using LuaLibFlags = Flags<LuaLib>;
constexpr LuaLibFlags LuaLib_All = LuaLibFlags(LuaLibFlags::ValueMask);
}
#endif // NAZARA_ENUMS_LUA_HPP

View File

@@ -1,32 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_LUA_HPP
#define NAZARA_LUA_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Lua/Config.hpp>
namespace Nz
{
class NAZARA_LUA_API Lua
{
public:
Lua() = delete;
~Lua() = delete;
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static unsigned int s_moduleReferenceCounter;
};
}
#endif // NAZARA_LUA_HPP

View File

@@ -1,121 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_LUACLASS_HPP
#define NAZARA_LUACLASS_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Lua/LuaInstance.hpp>
#include <functional>
#include <map>
#include <memory>
#include <unordered_map>
#include <vector>
namespace Nz
{
template<class T>
class LuaClass
{
template<class U>
friend class LuaClass;
public:
using ClassFunc = std::function<int(LuaState& state, T& instance, std::size_t argumentCount)>;
using ClassIndexFunc = std::function<bool(LuaState& state, T& instance)>;
using ConstructorFunc = std::function<bool(LuaState& state, T* instance, std::size_t argumentCount)>;
template<typename P> using ConvertToParent = std::function<P*(T*)>;
using FinalizerFunc = std::function<bool(LuaState& state, T& instance)>;
using StaticIndexFunc = std::function<bool(LuaState& state)>;
using StaticFunc = std::function<int(LuaState& state)>;
LuaClass() = default;
LuaClass(const String& name);
void BindDefaultConstructor();
void BindMethod(const String& name, ClassFunc method);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs);
void BindStaticMethod(const String& name, StaticFunc func);
template<typename R, typename... Args, typename... DefArgs> void BindStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs);
template<class P> void Inherit(LuaClass<P>& parent);
template<class P> void Inherit(LuaClass<P>& parent, ConvertToParent<P> convertFunc);
void Reset();
void Reset(const String& name);
void Register(LuaState& state);
void PushGlobalTable(LuaState& state);
void SetConstructor(ConstructorFunc constructor);
void SetFinalizer(FinalizerFunc finalizer);
void SetGetter(ClassIndexFunc getter);
void SetSetter(ClassIndexFunc setter);
void SetStaticGetter(StaticIndexFunc getter);
void SetStaticSetter(StaticIndexFunc getter);
private:
template<typename U, bool HasDestructor>
friend struct LuaClassImplFinalizerSetupProxy;
int PushClassInfo(LuaState& state);
void SetupConstructor(LuaState& state, int classInfoRef);
void SetupDefaultToString(LuaState& state, int classInfoRef);
void SetupFinalizer(LuaState& state, int classInfoRef);
void SetupGetter(LuaState& state, LuaCFunction proxy, int classInfoRef);
void SetupGlobalTable(LuaState& state, int classInfoRef);
void SetupMetatable(LuaState& state, int classInfoRef);
void SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex, int classInfoRef);
void SetupSetter(LuaState& state, LuaCFunction proxy, int classInfoRef);
using ParentFunc = std::function<void(LuaState& state, T* instance)>;
using InstanceGetter = std::function<T*(LuaState& state)>;
struct ClassInfo
{
std::vector<ClassFunc> methods;
std::vector<ParentFunc> parentGetters;
std::vector<StaticFunc> staticMethods;
std::unordered_map<String, InstanceGetter> instanceGetters;
ClassIndexFunc getter;
ClassIndexFunc setter;
ConstructorFunc constructor;
FinalizerFunc finalizer;
StaticIndexFunc staticGetter;
StaticIndexFunc staticSetter;
String name;
int globalTableRef = -1;
};
static int ConstructorProxy(lua_State* internalState);
static int FinalizerProxy(lua_State* internalState);
static int InfoDestructor(lua_State* internalState);
static void Get(const std::shared_ptr<ClassInfo>& info, LuaState& state, T* instance);
static int GetterProxy(lua_State* internalState);
static int MethodProxy(lua_State* internalState);
static int SetterProxy(lua_State* internalState);
static int StaticGetterProxy(lua_State* internalState);
static int StaticMethodProxy(lua_State* internalState);
static int StaticSetterProxy(lua_State* internalState);
static int ToStringProxy(lua_State* internalState);
std::map<String, ClassFunc> m_methods;
std::map<String, StaticFunc> m_staticMethods;
std::shared_ptr<ClassInfo> m_info;
};
}
#include <Nazara/Lua/LuaClass.inl>
#endif // NAZARA_LUACLASS_HPP

View File

@@ -1,603 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Lua/LuaClass.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/MemoryHelper.hpp>
#include <type_traits>
#include <Nazara/Lua/Debug.hpp>
namespace Nz
{
template<class T>
LuaClass<T>::LuaClass(const String& name)
{
Reset(name);
}
template<class T>
inline void LuaClass<T>::BindDefaultConstructor()
{
SetConstructor([] (Nz::LuaState& state, T* instance, std::size_t argumentCount)
{
NazaraUnused(state);
NazaraUnused(argumentCount);
PlacementNew(instance);
return true;
});
}
template<class T>
template<class P>
inline void LuaClass<T>::Inherit(LuaClass<P>& parent)
{
Inherit<P>(parent, [] (T* instance) -> P*
{
return static_cast<P*>(instance);
});
}
template<class T>
template<class P>
inline void LuaClass<T>::Inherit(LuaClass<P>& parent, ConvertToParent<P> convertFunc)
{
static_assert(!std::is_same<P, T>::value || std::is_base_of<P, T>::value, "P must be a base of T");
std::shared_ptr<typename LuaClass<P>::ClassInfo>& parentInfo = parent.m_info;
parentInfo->instanceGetters[m_info->name] = [info = m_info, convertFunc] (LuaState& state) -> P*
{
return convertFunc(static_cast<T*>(state.CheckUserdata(1, info->name)));
};
m_info->parentGetters.emplace_back([parentInfo, convertFunc] (LuaState& state, T* instance)
{
LuaClass<P>::Get(parentInfo, state, convertFunc(instance));
});
}
template<class T>
void LuaClass<T>::Reset()
{
m_info.reset();
}
template<class T>
void LuaClass<T>::Reset(const String& name)
{
m_info = std::make_shared<ClassInfo>();
m_info->name = name;
m_info->instanceGetters[m_info->name] = [info = m_info] (LuaState& state)
{
return static_cast<T*>(state.CheckUserdata(1, info->name));
};
}
template<class T>
void LuaClass<T>::Register(LuaState& state)
{
int classInfoRef = PushClassInfo(state);
// Let's create the metatable which will be associated with every state.
SetupMetatable(state, classInfoRef);
if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_staticMethods.empty())
SetupGlobalTable(state, classInfoRef);
state.DestroyReference(classInfoRef);
}
template<class T>
void LuaClass<T>::PushGlobalTable(LuaState& state)
{
state.PushReference(m_info->globalTableRef);
}
template<class T>
void LuaClass<T>::SetConstructor(ConstructorFunc constructor)
{
m_info->constructor = constructor;
}
template<class T>
void LuaClass<T>::SetFinalizer(FinalizerFunc finalizer)
{
m_info->finalizer = finalizer;
}
template<class T>
void LuaClass<T>::SetGetter(ClassIndexFunc getter)
{
m_info->getter = getter;
}
template<class T>
void LuaClass<T>::BindMethod(const String& name, ClassFunc method)
{
m_methods[name] = method;
}
template<class T>
template<typename R, typename P, typename... Args, typename... DefArgs>
std::enable_if_t<std::is_base_of<P, T>::value> LuaClass<T>::BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs)
{
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
BindMethod(name, [func, handler] (LuaState& state, T& object, std::size_t /*argumentCount*/) -> int
{
handler.ProcessArguments(state);
return handler.Invoke(state, object, func);
});
}
template<class T>
template<typename R, typename P, typename... Args, typename... DefArgs>
std::enable_if_t<std::is_base_of<P, T>::value> LuaClass<T>::BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs)
{
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
BindMethod(name, [func, handler] (LuaState& state, T& object, std::size_t /*argumentCount*/) -> int
{
handler.ProcessArguments(state);
return handler.Invoke(state, object, func);
});
}
template<class T>
template<typename R, typename P, typename... Args, typename... DefArgs>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> LuaClass<T>::BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs)
{
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
BindMethod(name, [func, handler] (LuaState& state, T& object, std::size_t /*argumentCount*/) -> int
{
handler.ProcessArguments(state);
return handler.Invoke(state, object, func);
});
}
template<class T>
template<typename R, typename P, typename... Args, typename... DefArgs>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> LuaClass<T>::BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs)
{
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
BindMethod(name, [func, handler] (LuaState& state, T& object, std::size_t /*argumentCount*/) -> int
{
handler.ProcessArguments(state);
return handler.Invoke(state, object, func);
});
}
template<class T>
void LuaClass<T>::SetSetter(ClassIndexFunc setter)
{
m_info->setter = setter;
}
template<class T>
void LuaClass<T>::SetStaticGetter(StaticIndexFunc getter)
{
m_info->staticGetter = getter;
}
template<class T>
void LuaClass<T>::BindStaticMethod(const String& name, StaticFunc method)
{
m_staticMethods[name] = method;
}
template<class T>
template<typename R, typename... Args, typename... DefArgs>
void LuaClass<T>::BindStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs)
{
typename LuaImplFunctionProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
BindStaticMethod(name, [func, handler] (LuaState& state) -> int
{
handler.ProcessArguments(state);
return handler.Invoke(state, func);
});
}
template<class T>
void LuaClass<T>::SetStaticSetter(StaticIndexFunc setter)
{
m_info->staticSetter = setter;
}
template<class T>
int LuaClass<T>::PushClassInfo(LuaState& state)
{
// Our ClassInfo has to outlive the LuaClass, because we don't want to force the user to keep the LuaClass alive
// To do that, each Registration creates a tiny shared_ptr wrapper whose life is directly managed by Lua.
// This shared_ptr object gets pushed as a up-value for every proxy function set in the metatable.
// This way, there is no way our ClassInfo gets freed before any instance and the global class gets destroyed.
std::shared_ptr<ClassInfo>* info = static_cast<std::shared_ptr<ClassInfo>*>(state.PushUserdata(sizeof(std::shared_ptr<ClassInfo>)));
PlacementNew(info, m_info);
// Setup a tiny metatable to let Lua know how to destroy our ClassInfo
state.PushTable(0, 1);
state.PushLightUserdata(info);
state.PushCFunction(InfoDestructor, 1);
state.SetField("__gc");
state.SetMetatable(-2);
return state.CreateReference();
}
template<class T>
void LuaClass<T>::SetupConstructor(LuaState& state, int classInfoRef)
{
state.PushReference(classInfoRef);
state.PushCFunction(ConstructorProxy, 1);
state.SetField("__call"); // ClassMeta.__call = ConstructorProxy
}
template<class T>
void LuaClass<T>::SetupDefaultToString(LuaState& state, int classInfoRef)
{
state.PushReference(classInfoRef);
state.PushCFunction(ToStringProxy, 1);
state.SetField("__tostring");
}
template<typename T, bool HasDestructor>
struct LuaClassImplFinalizerSetupProxy;
template<typename T>
struct LuaClassImplFinalizerSetupProxy<T, true>
{
static void Setup(LuaState& state, int classInfoRef)
{
state.PushReference(classInfoRef);
state.PushCFunction(LuaClass<T>::FinalizerProxy, 1);
state.SetField("__gc");
}
};
template<typename T>
struct LuaClassImplFinalizerSetupProxy<T, false>
{
static void Setup(LuaState&, int)
{
}
};
template<class T>
void LuaClass<T>::SetupFinalizer(LuaState& state, int classInfoRef)
{
LuaClassImplFinalizerSetupProxy<T, std::is_destructible<T>::value>::Setup(state, classInfoRef);
}
template<class T>
void LuaClass<T>::SetupGetter(LuaState& state, LuaCFunction proxy, int classInfoRef)
{
state.PushReference(classInfoRef);
state.PushValue(-2); // Metatable
state.PushCFunction(proxy, 2);
state.SetField("__index"); // Getter
}
template<class T>
void LuaClass<T>::SetupGlobalTable(LuaState& state, int classInfoRef)
{
// Create the global table
state.PushTable(); // Class = {}
// Create a metatable which will be used for our global table
state.PushTable(); // ClassMeta = {}
if (m_info->constructor)
SetupConstructor(state, classInfoRef);
if (m_info->staticGetter)
SetupGetter(state, StaticGetterProxy, classInfoRef);
else
{
// Optimize by assigning the metatable instead of a search function
state.PushValue(-1); // Metatable
state.SetField("__index");
}
if (m_info->staticSetter)
SetupSetter(state, StaticSetterProxy, classInfoRef);
m_info->staticMethods.reserve(m_staticMethods.size());
for (auto& pair : m_staticMethods)
{
std::size_t methodIndex = m_info->staticMethods.size();
m_info->staticMethods.push_back(pair.second);
SetupMethod(state, StaticMethodProxy, pair.first, methodIndex, classInfoRef);
}
state.SetMetatable(-2); // setmetatable(Class, ClassMeta), pops ClassMeta
state.PushValue(-1); // As CreateReference() pops the table, push a copy
m_info->globalTableRef = state.CreateReference();
state.SetGlobal(m_info->name); // _G["Class"] = Class
}
template<class T>
void LuaClass<T>::SetupMetatable(LuaState& state, int classInfoRef)
{
if (!state.NewMetatable(m_info->name))
NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance");
{
SetupFinalizer(state, classInfoRef);
if (m_info->getter || !m_info->parentGetters.empty())
SetupGetter(state, GetterProxy, classInfoRef);
else
{
// Optimize by assigning the metatable instead of a search function
// This is only possible if we have no custom getter nor parent
state.PushValue(-1); // Metatable
state.SetField("__index");
}
if (m_info->setter)
SetupSetter(state, SetterProxy, classInfoRef);
// In case a __tostring method is missing, add a default implementation returning the class name
if (m_methods.find("__tostring") == m_methods.end())
SetupDefaultToString(state, classInfoRef);
m_info->methods.reserve(m_methods.size());
for (auto& pair : m_methods)
{
std::size_t methodIndex = m_info->methods.size();
m_info->methods.push_back(pair.second);
SetupMethod(state, MethodProxy, pair.first, methodIndex, classInfoRef);
}
}
state.Pop(); //< Pops the metatable, it won't be collected before it's referenced by the Lua registry.
}
template<class T>
void LuaClass<T>::SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex, int classInfoRef)
{
state.PushReference(classInfoRef);
state.PushInteger(methodIndex);
state.PushCFunction(proxy, 2);
state.SetField(name); // Method name
}
template<class T>
void LuaClass<T>::SetupSetter(LuaState& state, LuaCFunction proxy, int classInfoRef)
{
state.PushReference(classInfoRef);
state.PushCFunction(proxy, 1);
state.SetField("__newindex"); // Setter
}
template<class T>
int LuaClass<T>::ConstructorProxy(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
const ConstructorFunc& constructor = info->constructor;
state.Remove(1); // On enlève l'argument "table" du stack
std::size_t argCount = state.GetStackTop();
T* instance = static_cast<T*>(state.PushUserdata(sizeof(T)));
if (!constructor(state, instance, argCount))
{
state.Error("Constructor failed");
return 0; // Normalement jamais exécuté (l'erreur provoquant une exception)
}
state.SetMetatable(info->name);
return 1;
}
template<class T>
int LuaClass<T>::FinalizerProxy(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
const FinalizerFunc& finalizer = info->finalizer;
T* instance = static_cast<T*>(state.CheckUserdata(1, info->name));
state.Remove(1); //< Remove the instance from the Lua stack
if (!finalizer || finalizer(state, *instance))
instance->~T();
return 0;
}
template<class T>
int LuaClass<T>::InfoDestructor(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
state.DestroyReference(info->globalTableRef);
using namespace std; // Obligatoire pour le destructeur
info.~shared_ptr(); // Si vous voyez une autre façon de faire, je suis preneur
return 0;
}
template<class T>
void LuaClass<T>::Get(const std::shared_ptr<ClassInfo>& info, LuaState& state, T* instance)
{
const ClassIndexFunc& getter = info->getter;
if (!getter || !getter(state, *instance))
{
// Query from the metatable
state.GetMetatable(info->name); //< Metatable
state.PushValue(2); //< Field
state.GetTable(); // Metatable[Field]
state.Remove(-2); // Remove Metatable
if (!state.IsValid(-1))
{
for (const ParentFunc& parentGetter : info->parentGetters)
{
state.Pop(); //< Pop the last nil value
parentGetter(state, instance);
if (state.IsValid(-1))
return;
}
}
}
}
template<class T>
int LuaClass<T>::GetterProxy(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
T* instance = static_cast<T*>(state.CheckUserdata(1, info->name));
Get(info, state, instance);
return 1;
}
template<class T>
int LuaClass<T>::MethodProxy(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
T* instance = nullptr;
if (state.GetMetatable(1))
{
LuaType type = state.GetField("__name");
if (type == LuaType_String)
{
String name = state.ToString(-1);
auto it = info->instanceGetters.find(name);
if (it != info->instanceGetters.end())
instance = it->second(state);
}
state.Pop(2);
}
if (!instance)
{
state.Error("Method cannot be called without an object");
return 0;
}
std::size_t argCount = state.GetStackTop() - 1U;
unsigned int index = static_cast<unsigned int>(state.ToInteger(state.GetIndexOfUpValue(2)));
const ClassFunc& method = info->methods[index];
return method(state, *instance, argCount);
}
template<class T>
int LuaClass<T>::SetterProxy(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
const ClassIndexFunc& setter = info->setter;
T& instance = *static_cast<T*>(state.CheckUserdata(1, info->name));
if (!setter(state, instance))
{
std::size_t length;
const char* str = state.ToString(2, &length);
state.Error("Class \"" + info->name + "\" has no field \"" + String(str, length) + "\")");
}
return 1;
}
template<class T>
int LuaClass<T>::StaticGetterProxy(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
const StaticIndexFunc& getter = info->staticGetter;
if (!getter(state))
{
// On accède alors à la table
state.PushValue(state.GetIndexOfUpValue(2));
state.PushValue(-2);
state.GetTable();
}
return 1;
}
template<class T>
int LuaClass<T>::StaticMethodProxy(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
unsigned int index = static_cast<unsigned int>(state.ToInteger(state.GetIndexOfUpValue(2)));
const StaticFunc& method = info->staticMethods[index];
return method(state);
}
template<class T>
int LuaClass<T>::StaticSetterProxy(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
const StaticIndexFunc& setter = info->staticSetter;
if (!setter(state))
{
std::size_t length;
const char* str = state.ToString(2, &length);
state.Error("Class \"" + info->name + "\" has no static field \"" + String(str, length) + ')');
}
return 1;
}
template<class T>
int LuaClass<T>::ToStringProxy(lua_State* internalState)
{
LuaState state = LuaInstance::GetState(internalState);
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(state.ToUserdata(state.GetIndexOfUpValue(1)));
state.PushString(info->name);
return 1;
}
}
#include <Nazara/Lua/DebugOff.hpp>

View File

@@ -1,42 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_LUACOROUTINE_HPP
#define NAZARA_LUACOROUTINE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Lua/LuaState.hpp>
namespace Nz
{
class NAZARA_LUA_API LuaCoroutine : public LuaState
{
friend class LuaState;
public:
LuaCoroutine(const LuaCoroutine&) = delete;
inline LuaCoroutine(LuaCoroutine&& instance);
~LuaCoroutine();
bool CanResume() const;
Ternary Resume(unsigned int argCount = 0);
LuaCoroutine& operator=(const LuaCoroutine&) = delete;
inline LuaCoroutine& operator=(LuaCoroutine&& instance);
private:
LuaCoroutine(lua_State* internalState, int refIndex);
bool Run(int argCount, int resultCount, int errHandler) override;
int m_ref;
};
}
#include <Nazara/Lua/LuaCoroutine.inl>
#endif // NAZARA_LUACOROUTINE_HPP

View File

@@ -1,22 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
namespace Nz
{
inline LuaCoroutine::LuaCoroutine(LuaCoroutine&& instance) :
LuaState(std::move(instance)),
m_ref(instance.m_ref)
{
instance.m_ref = -1;
}
inline LuaCoroutine& LuaCoroutine::operator=(LuaCoroutine&& instance)
{
LuaState::operator=(std::move(instance));
std::swap(m_ref, instance.m_ref);
return *this;
}
}

View File

@@ -1,57 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_LUAINSTANCE_HPP
#define NAZARA_LUAINSTANCE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Lua/Enums.hpp>
#include <Nazara/Lua/LuaState.hpp>
#include <cstddef>
namespace Nz
{
class NAZARA_LUA_API LuaInstance : public LuaState
{
friend class LuaCoroutine;
friend class LuaState;
public:
LuaInstance();
LuaInstance(const LuaInstance&) = delete;
LuaInstance(LuaInstance&& instance);
~LuaInstance();
inline std::size_t GetMemoryLimit() const;
inline std::size_t GetMemoryUsage() const;
inline UInt32 GetTimeLimit() const;
void LoadLibraries(LuaLibFlags libFlags = LuaLib_All);
inline void SetMemoryLimit(std::size_t memoryLimit);
inline void SetTimeLimit(UInt32 limit);
LuaInstance& operator=(const LuaInstance&) = delete;
LuaInstance& operator=(LuaInstance&& instance);
private:
inline void SetMemoryUsage(std::size_t memoryUsage);
static void* MemoryAllocator(void *ud, void *ptr, std::size_t osize, std::size_t nsize);
static void TimeLimiter(lua_State* internalState, lua_Debug* debug);
std::size_t m_memoryLimit;
std::size_t m_memoryUsage;
UInt32 m_timeLimit;
Clock m_clock;
unsigned int m_level;
};
}
#include <Nazara/Lua/LuaInstance.inl>
#endif // NAZARA_LUAINSTANCE_HPP

View File

@@ -1,40 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Lua/Debug.hpp>
namespace Nz
{
inline std::size_t LuaInstance::GetMemoryLimit() const
{
return m_memoryLimit;
}
inline std::size_t LuaInstance::GetMemoryUsage() const
{
return m_memoryUsage;
}
inline UInt32 LuaInstance::GetTimeLimit() const
{
return m_timeLimit;
}
inline void LuaInstance::SetMemoryLimit(std::size_t memoryLimit)
{
m_memoryLimit = memoryLimit;
}
inline void LuaInstance::SetTimeLimit(UInt32 limit)
{
m_timeLimit = limit;
}
inline void LuaInstance::SetMemoryUsage(std::size_t memoryUsage)
{
m_memoryUsage = memoryUsage;
}
}
#include <Nazara/Lua/DebugOff.hpp>

View File

@@ -1,209 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_LUASTATE_HPP
#define NAZARA_LUASTATE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Lua/Config.hpp>
#include <Nazara/Lua/Enums.hpp>
#include <cstddef>
#include <functional>
#include <type_traits>
struct lua_Debug;
struct lua_State;
namespace Nz
{
class LuaCoroutine;
class LuaInstance;
class LuaState;
class Stream;
using LuaCFunction = int (*)(lua_State* internalState);
using LuaFunction = std::function<int(LuaState& state)>;
class NAZARA_LUA_API LuaState
{
public:
LuaState(const LuaState&) = default;
LuaState(LuaState&& instance) = default;
~LuaState() = default;
void ArgCheck(bool condition, unsigned int argNum, const char* error) const;
void ArgCheck(bool condition, unsigned int argNum, const String& error) const;
int ArgError(unsigned int argNum, const char* error) const;
int ArgError(unsigned int argNum, const String& error) const;
bool Call(unsigned int argCount);
bool Call(unsigned int argCount, unsigned int resultCount);
bool CallWithHandler(unsigned int argCount, int errorHandler);
bool CallWithHandler(unsigned int argCount, unsigned int resultCount, int errorHandler);
template<typename T> T Check(int* index) const;
template<typename T> T Check(int* index, T defValue) const;
void CheckAny(int index) const;
bool CheckBoolean(int index) const;
bool CheckBoolean(int index, bool defValue) const;
template<typename T> T CheckBoundInteger(int index) const;
template<typename T> T CheckBoundInteger(int index, T defValue) const;
template<typename T> T CheckField(const char* fieldName, int tableIndex = -1) const;
template<typename T> T CheckField(const String& fieldName, int tableIndex = -1) const;
template<typename T> T CheckField(const char* fieldName, T defValue, int tableIndex = -1) const;
template<typename T> T CheckField(const String& fieldName, T defValue, int tableIndex = -1) const;
long long CheckInteger(int index) const;
long long CheckInteger(int index, long long defValue) const;
template<typename T> T CheckGlobal(const char* fieldName) const;
template<typename T> T CheckGlobal(const String& fieldName) const;
template<typename T> T CheckGlobal(const char* fieldName, T defValue) const;
template<typename T> T CheckGlobal(const String& fieldName, T defValue) const;
double CheckNumber(int index) const;
double CheckNumber(int index, double defValue) const;
void CheckStack(int space, const char* error = nullptr) const;
void CheckStack(int space, const String& error) const;
const char* CheckString(int index, std::size_t* length = nullptr) const;
const char* CheckString(int index, const char* defValue, std::size_t* length = nullptr) const;
void CheckType(int index, LuaType type) const;
void* CheckUserdata(int index, const char* tname) const;
void* CheckUserdata(int index, const String& tname) const;
bool Compare(int index1, int index2, LuaComparison comparison) const;
void Compute(LuaOperation operation) const;
void Concatenate(int count) const;
int CreateReference();
void DestroyReference(int ref);
String DumpStack() const;
void Error(const char* message) const;
void Error(const String& message) const;
bool Execute(const String& code, int errorHandler = 0);
bool ExecuteFromFile(const String& filePath, int errorHandler = 0);
bool ExecuteFromMemory(const void* data, std::size_t size, int errorHandler = 0);
bool ExecuteFromStream(Stream& stream, int errorHandler = 0);
int GetAbsIndex(int index) const;
LuaType GetField(const char* fieldName, int tableIndex = -1) const;
LuaType GetField(const String& fieldName, int tableIndex = -1) const;
LuaType GetGlobal(const char* name) const;
LuaType GetGlobal(const String& name) const;
inline lua_State* GetInternalState() const;
inline String GetLastError() const;
LuaType GetMetatable(const char* tname) const;
LuaType GetMetatable(const String& tname) const;
bool GetMetatable(int index) const;
unsigned int GetStackTop() const;
LuaType GetTable(int index = -2) const;
LuaType GetTableRaw(int index = -2) const;
LuaType GetType(int index) const;
const char* GetTypeName(LuaType type) const;
void Insert(int index) const;
bool IsOfType(int index, LuaType type) const;
bool IsOfType(int index, const char* tname) const;
bool IsOfType(int index, const String& tname) const;
bool IsValid(int index) const;
bool Load(const String& code);
bool LoadFromFile(const String& filePath);
bool LoadFromMemory(const void* data, std::size_t size);
bool LoadFromStream(Stream& stream);
long long Length(int index) const;
std::size_t LengthRaw(int index) const;
void MoveTo(LuaState* instance, int n) const;
LuaCoroutine NewCoroutine();
bool NewMetatable(const char* str);
bool NewMetatable(const String& str);
bool Next(int index = -2) const;
void Pop(unsigned int n = 1U) const;
template<typename T> int Push(T arg) const;
template<typename T, typename T2, typename... Args> int Push(T firstArg, T2 secondArg, Args... args) const;
void PushBoolean(bool value) const;
void PushCFunction(LuaCFunction func, unsigned int upvalueCount = 0) const;
template<typename T> void PushField(const char* name, T&& arg, int tableIndex = -2) const;
template<typename T> void PushField(const String& name, T&& arg, int tableIndex = -2) const;
void PushFunction(LuaFunction func) const;
template<typename R, typename... Args, typename... DefArgs> void PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const;
template<typename T> void PushGlobal(const char* name, T&& arg);
template<typename T> void PushGlobal(const String& name, T&& arg);
template<typename T> void PushInstance(const char* tname, T&& instance) const;
template<typename T, typename... Args> void PushInstance(const char* tname, Args&&... args) const;
void PushInteger(long long value) const;
void PushLightUserdata(void* value) const;
void PushMetatable(const char* str) const;
void PushMetatable(const String& str) const;
void PushNil() const;
void PushNumber(double value) const;
void PushReference(int ref) const;
void PushString(const char* str) const;
void PushString(const char* str, std::size_t size) const;
void PushString(const String& str) const;
void PushTable(std::size_t sequenceElementCount = 0, std::size_t arrayElementCount = 0) const;
void* PushUserdata(std::size_t size) const;
void PushValue(int index) const;
bool RawEqual(int index1, int index2) const;
void Remove(int index) const;
void Replace(int index) const;
void SetField(const char* name, int tableIndex = -2) const;
void SetField(const String& name, int tableIndex = -2) const;
void SetGlobal(const char* name);
void SetGlobal(const String& name);
void SetMetatable(const char* tname) const;
void SetMetatable(const String& tname) const;
void SetMetatable(int index) const;
void SetTable(int index = -3) const;
void SetTableRaw(int index = -3) const;
bool ToBoolean(int index) const;
long long ToInteger(int index, bool* succeeded = nullptr) const;
double ToNumber(int index, bool* succeeded = nullptr) const;
const void* ToPointer(int index) const;
const char* ToString(int index, std::size_t* length = nullptr) const;
void* ToUserdata(int index) const;
void* ToUserdata(int index, const char* tname) const;
void* ToUserdata(int index, const String& tname) const;
void Traceback(const char* message = nullptr, int level = 0);
LuaState& operator=(const LuaState&) = default;
LuaState& operator=(LuaState&& instance) = default;
static int GetIndexOfUpValue(int upValue);
static LuaInstance& GetInstance(lua_State* internalState);
static inline LuaState GetState(lua_State* internalState);
protected:
LuaState(lua_State* internalState);
template<typename T> std::enable_if_t<std::is_signed<T>::value, T> CheckBounds(int index, long long value) const;
template<typename T> std::enable_if_t<std::is_unsigned<T>::value, T> CheckBounds(int index, long long value) const;
virtual bool Run(int argCount, int resultCount, int errHandler);
static int ProxyFunc(lua_State* internalState);
MovablePtr<lua_State> m_state;
String m_lastError;
};
}
#include <Nazara/Lua/LuaState.inl>
#endif // NAZARA_LUASTATE_HPP

View File

@@ -1,828 +0,0 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Lua scripting module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Flags.hpp>
#include <Nazara/Core/MemoryHelper.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <limits>
#include <string>
#include <vector>
#include <type_traits>
namespace Nz
{
inline LuaState::LuaState(lua_State* internalState) :
m_state(internalState)
{
}
inline lua_State* LuaState::GetInternalState() const
{
return m_state;
}
inline String LuaState::GetLastError() const
{
return m_lastError;
}
// Functions args
inline unsigned int LuaImplQueryArg(const LuaState& instance, int index, bool* arg, TypeTag<bool>)
{
*arg = instance.CheckBoolean(index);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaState& instance, int index, bool* arg, bool defValue, TypeTag<bool>)
{
*arg = instance.CheckBoolean(index, defValue);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaState& instance, int index, std::string* arg, TypeTag<std::string>)
{
std::size_t strLength = 0;
const char* str = instance.CheckString(index, &strLength);
arg->assign(str, strLength);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaState& instance, int index, String* arg, TypeTag<String>)
{
std::size_t strLength = 0;
const char* str = instance.CheckString(index, &strLength);
arg->Set(str, strLength);
return 1;
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value && !IsEnumFlag<T>::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), TypeTag<UnderlyingT>());
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value && !IsEnumFlag<T>::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, T defValue, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value && IsEnumFlag<T>::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
UnderlyingT pot2Val;
unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, TypeTag<UnderlyingT>());
*arg = static_cast<T>(IntegralLog2Pot(pot2Val));
return ret;
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value && IsEnumFlag<T>::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, T defValue, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
UnderlyingT pot2Val;
unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, 1U << static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
*arg = static_cast<T>(IntegralLog2Pot(pot2Val));
return ret;
}
template<typename E>
unsigned int LuaImplQueryArg(const LuaState& instance, int index, Flags<E>* arg, TypeTag<Flags<E>>)
{
*arg = Flags<E>(instance.CheckBoundInteger<UInt32>(index));
return 1;
}
template<typename T>
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckNumber(index));
return 1;
}
template<typename T>
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, T defValue, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckNumber(index, static_cast<double>(defValue)));
return 1;
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag<T>)
{
*arg = instance.CheckBoundInteger<T>(index);
return 1;
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, T defValue, TypeTag<T>)
{
*arg = instance.CheckBoundInteger<T>(index, defValue);
return 1;
}
template<typename T>
std::enable_if_t<!std::is_integral<T>::value && !std::is_enum<T>::value && !std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, const T& defValue, TypeTag<T> tag)
{
if (instance.IsValid(index))
return LuaImplQueryArg(instance, index, arg, tag);
else
{
*arg = defValue;
return 1;
}
}
template<typename T>
unsigned int LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag<const T&>)
{
return LuaImplQueryArg(instance, index, arg, TypeTag<T>());
}
template<typename T>
unsigned int LuaImplQueryArg(const LuaState& instance, int index, T* arg, const T& defValue, TypeTag<const T&>)
{
return LuaImplQueryArg(instance, index, arg, defValue, TypeTag<T>());
}
template<typename T>
unsigned int LuaImplQueryArg(const LuaState& instance, int index, std::vector<T>* container, TypeTag<std::vector<T>>)
{
instance.CheckType(index, Nz::LuaType_Table);
std::size_t pos = 1;
container->clear();
for (;;)
{
Nz::CallOnExit popStack { [&instance]() { instance.Pop(); } };
instance.PushInteger(pos++);
int tableIndex = (index < 0) ? index - 1 : index;
if (instance.GetTable(tableIndex) == Nz::LuaType_Nil)
break;
T arg;
if (LuaImplQueryArg(instance, -1, &arg, TypeTag<T>()) != 1)
{
instance.Error("Type needs more than one place to be initialized");
return 0;
}
container->push_back(arg);
}
return 1;
}
// Function returns
inline int LuaImplReplyVal(const LuaState& instance, bool val, TypeTag<bool>)
{
instance.PushBoolean(val);
return 1;
}
inline int LuaImplReplyVal(const LuaState& instance, double val, TypeTag<double>)
{
instance.PushNumber(val);
return 1;
}
inline int LuaImplReplyVal(const LuaState& instance, float val, TypeTag<float>)
{
instance.PushNumber(val);
return 1;
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value && !IsEnumFlag<T>::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag<T>)
{
using EnumT = typename std::underlying_type<T>::type;
return LuaImplReplyVal(instance, static_cast<EnumT>(val), TypeTag<EnumT>());
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value && IsEnumFlag<T>::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag<T>)
{
Flags<T> flags(val);
return LuaImplReplyVal(instance, flags, TypeTag<decltype(flags)>());
}
template<typename E>
int LuaImplReplyVal(const LuaState& instance, Flags<E> val, TypeTag<Flags<E>>)
{
instance.PushInteger(typename Flags<E>::BitField(val));
return 1;
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag<T>)
{
instance.PushInteger(val);
return 1;
}
template<typename T>
std::enable_if_t<std::is_arithmetic<T>::value || std::is_enum<T>::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag<T&>)
{
return LuaImplReplyVal(instance, val, TypeTag<T>());
}
template<typename T>
std::enable_if_t<std::is_arithmetic<T>::value || std::is_enum<T>::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag<const T&>)
{
return LuaImplReplyVal(instance, val, TypeTag<T>());
}
template<typename T>
std::enable_if_t<!std::is_arithmetic<T>::value && !std::is_enum<T>::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag<T&>)
{
return LuaImplReplyVal(instance, std::move(val), TypeTag<T>());
}
template<typename T>
std::enable_if_t<!std::is_arithmetic<T>::value && !std::is_enum<T>::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag<const T&>)
{
return LuaImplReplyVal(instance, std::move(val), TypeTag<T>());
}
template<typename T>
int LuaImplReplyVal(const LuaState& instance, T&& val, TypeTag<T&&>)
{
return LuaImplReplyVal(instance, std::forward<T>(val), TypeTag<T>());
}
inline int LuaImplReplyVal(const LuaState& instance, std::string&& val, TypeTag<std::string>)
{
instance.PushString(val.c_str(), val.size());
return 1;
}
template<typename T>
inline int LuaImplReplyVal(const LuaState& instance, std::vector<T>&& valContainer, TypeTag<std::vector<T>>)
{
std::size_t index = 1;
instance.PushTable(valContainer.size());
for (T& val : valContainer)
{
instance.PushInteger(index++);
if (LuaImplReplyVal(instance, std::move(val), TypeTag<T>()) != 1)
{
instance.Error("Couldn't create table: type need more than one place to store");
return 0;
}
instance.SetTable();
}
return 1;
}
inline int LuaImplReplyVal(const LuaState& instance, ByteArray&& val, TypeTag<ByteArray>)
{
instance.PushString(reinterpret_cast<const char*>(val.GetConstBuffer()), val.GetSize());
return 1;
}
inline int LuaImplReplyVal(const LuaState& instance, String&& val, TypeTag<String>)
{
instance.PushString(std::move(val));
return 1;
}
template<typename T1, typename T2>
int LuaImplReplyVal(const LuaState& instance, std::pair<T1, T2>&& val, TypeTag<std::pair<T1, T2>>)
{
int retVal = 0;
retVal += LuaImplReplyVal(instance, std::move(val.first), TypeTag<T1>());
retVal += LuaImplReplyVal(instance, std::move(val.second), TypeTag<T2>());
return retVal;
}
template<bool HasDefault>
struct LuaImplArgProcesser;
template<>
struct LuaImplArgProcesser<true>
{
template<std::size_t N, std::size_t FirstDefArg, typename ArgType, typename ArgContainer, typename DefArgContainer>
static unsigned int Process(const LuaState& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs)
{
return LuaImplQueryArg(instance, argIndex, &std::get<N>(args), std::get<FirstDefArg + std::tuple_size<DefArgContainer>() - N - 1>(defArgs), TypeTag<ArgType>());
}
};
template<>
struct LuaImplArgProcesser<false>
{
template<std::size_t N, std::size_t FirstDefArg, typename ArgType, typename ArgContainer, typename DefArgContainer>
static unsigned int Process(const LuaState& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs)
{
NazaraUnused(defArgs);
return LuaImplQueryArg(instance, argIndex, &std::get<N>(args), TypeTag<ArgType>());
}
};
template<typename... Args>
class LuaImplFunctionProxy
{
public:
template<typename... DefArgs>
class Impl
{
static constexpr std::size_t ArgCount = sizeof...(Args);
static constexpr std::size_t DefArgCount = sizeof...(DefArgs);
static_assert(ArgCount >= DefArgCount, "There cannot be more default arguments than argument");
static constexpr std::size_t FirstDefArg = ArgCount - DefArgCount;
public:
Impl(DefArgs... defArgs) :
m_defaultArgs(std::forward<DefArgs>(defArgs)...)
{
}
void ProcessArguments(const LuaState& instance) const
{
m_index = 1;
ProcessArgs<0, Args...>(instance);
}
int Invoke(const LuaState& instance, void(*func)(Args...)) const
{
NazaraUnused(instance);
Apply(func, m_args);
return 0;
}
template<typename Ret>
int Invoke(const LuaState& instance, Ret(*func)(Args...)) const
{
return LuaImplReplyVal(instance, std::move(Apply(func, m_args)), TypeTag<decltype(Apply(func, m_args))>());
}
private:
using ArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...>;
using DefArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<DefArgs>>...>;
template<std::size_t N>
void ProcessArgs(const LuaState& instance) const
{
NazaraUnused(instance);
// No argument to process
}
template<std::size_t N, typename ArgType>
void ProcessArgs(const LuaState& instance) const
{
LuaImplArgProcesser<(N >= FirstDefArg)>::template Process<N, FirstDefArg, ArgType>(instance, m_index, m_args, m_defaultArgs);
}
template<std::size_t N, typename ArgType1, typename ArgType2, typename... Rest>
void ProcessArgs(const LuaState& instance) const
{
ProcessArgs<N, ArgType1>(instance);
ProcessArgs<N + 1, ArgType2, Rest...>(instance);
}
mutable ArgContainer m_args;
DefArgContainer m_defaultArgs;
mutable unsigned int m_index;
};
};
template<typename... Args>
class LuaImplMethodProxy
{
public:
template<typename... DefArgs>
class Impl
{
static constexpr std::size_t ArgCount = sizeof...(Args);
static constexpr std::size_t DefArgCount = sizeof...(DefArgs);
static_assert(ArgCount >= DefArgCount, "There cannot be more default arguments than argument");
static constexpr std::size_t FirstDefArg = ArgCount - DefArgCount;
public:
Impl(DefArgs... defArgs) :
m_defaultArgs(std::forward<DefArgs>(defArgs)...)
{
}
void ProcessArguments(const LuaState& instance) const
{
m_index = 2; //< 1 being the instance
ProcessArgs<0, Args...>(instance);
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaState& instance, T& object, void(P::*func)(Args...)) const
{
NazaraUnused(instance);
Apply(object, func, m_args);
return 0;
}
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaState& instance, T& object, Ret(P::*func)(Args...)) const
{
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaState& instance, T& object, T&(P::*func)(Args...)) const
{
T& r = Apply(object, func, m_args);
if (&r == &object)
{
instance.PushValue(1); //< Userdata
return 1;
}
else
return LuaImplReplyVal(instance, r, TypeTag<T&>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaState& instance, const T& object, void(P::*func)(Args...) const) const
{
NazaraUnused(instance);
Apply(object, func, m_args);
return 0;
}
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaState& instance, const T& object, Ret(P::*func)(Args...) const) const
{
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaState& instance, const T& object, const T&(P::*func)(Args...) const) const
{
const T& r = Apply(object, func, m_args);
if (&r == &object)
{
instance.PushValue(1); //< Userdata
return 1;
}
else
return LuaImplReplyVal(instance, r, TypeTag<T&>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaState& instance, T& object, void(P::*func)(Args...)) const
{
if (!object)
{
instance.Error("Invalid object");
return 0;
}
Apply(*object, func, m_args);
return 0;
}
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaState& instance, T& object, Ret(P::*func)(Args...)) const
{
if (!object)
{
instance.Error("Invalid object");
return 0;
}
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaState& instance, T& object, typename PointedType<T>::type&(P::*func)(Args...) const) const
{
if (!object)
{
instance.Error("Invalid object");
return 0;
}
const typename PointedType<T>::type& r = Apply(*object, func, m_args);
if (&r == &*object)
{
instance.PushValue(1); //< Userdata
return 1;
}
else
return LuaImplReplyVal(instance, r, TypeTag<T&>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaState& instance, const T& object, void(P::*func)(Args...) const) const
{
if (!object)
{
instance.Error("Invalid object");
return 0;
}
Apply(*object, func, m_args);
return 0;
}
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaState& instance, const T& object, Ret(P::*func)(Args...) const) const
{
if (!object)
{
instance.Error("Invalid object");
return 0;
}
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaState& instance, const T& object, const typename PointedType<T>::type&(P::*func)(Args...) const) const
{
if (!object)
{
instance.Error("Invalid object");
return 0;
}
const typename PointedType<T>::type& r = Apply(*object, func, m_args);
if (&r == &*object)
{
instance.PushValue(1); //< Userdata
return 1;
}
else
return LuaImplReplyVal(instance, r, TypeTag<T&>());
}
private:
using ArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...>;
using DefArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<DefArgs>>...>;
template<std::size_t N>
void ProcessArgs(const LuaState& instance) const
{
NazaraUnused(instance);
// No argument to process
}
template<std::size_t N, typename ArgType>
void ProcessArgs(const LuaState& instance) const
{
m_index += LuaImplArgProcesser<(N >= FirstDefArg)>::template Process<N, FirstDefArg, ArgType>(instance, m_index, m_args, m_defaultArgs);
}
template<std::size_t N, typename ArgType1, typename ArgType2, typename... Rest>
void ProcessArgs(const LuaState& instance) const
{
ProcessArgs<N, ArgType1>(instance);
ProcessArgs<N + 1, ArgType2, Rest...>(instance);
}
mutable ArgContainer m_args;
DefArgContainer m_defaultArgs;
mutable unsigned int m_index;
};
};
template<typename T>
T LuaState::Check(int* index) const
{
NazaraAssert(index, "Invalid index pointer");
T object;
*index += LuaImplQueryArg(*this, *index, &object, TypeTag<T>());
return object;
}
template<typename T>
T LuaState::Check(int* index, T defValue) const
{
NazaraAssert(index, "Invalid index pointer");
T object;
*index += LuaImplQueryArg(*this, *index, &object, defValue, TypeTag<T>());
return object;
}
template<typename T>
inline T LuaState::CheckBoundInteger(int index) const
{
return CheckBounds<T>(index, CheckInteger(index));
}
template<typename T>
inline T LuaState::CheckBoundInteger(int index, T defValue) const
{
return CheckBounds<T>(index, CheckInteger(index, defValue));
}
template<typename T>
T LuaState::CheckField(const char* fieldName, int tableIndex) const
{
T object;
GetField(fieldName, tableIndex);
tableIndex += LuaImplQueryArg(*this, -1, &object, TypeTag<T>());
Pop();
return object;
}
template<typename T>
T LuaState::CheckField(const String& fieldName, int tableIndex) const
{
return CheckField<T>(fieldName.GetConstBuffer(), tableIndex);
}
template<typename T>
T LuaState::CheckField(const char* fieldName, T defValue, int tableIndex) const
{
T object;
GetField(fieldName, tableIndex);
tableIndex += LuaImplQueryArg(*this, -1, &object, defValue, TypeTag<T>());
Pop();
return object;
}
template<typename T>
T LuaState::CheckField(const String& fieldName, T defValue, int tableIndex) const
{
return CheckField<T>(fieldName.GetConstBuffer(), defValue, tableIndex);
}
template<typename T>
T LuaState::CheckGlobal(const char* fieldName) const
{
T object;
GetGlobal(fieldName);
LuaImplQueryArg(*this, -1, &object, TypeTag<T>());
Pop();
return object;
}
template<typename T>
T LuaState::CheckGlobal(const String& fieldName) const
{
return CheckGlobal<T>(fieldName.GetConstBuffer());
}
template<typename T>
T LuaState::CheckGlobal(const char* fieldName, T defValue) const
{
T object;
GetGlobal(fieldName);
LuaImplQueryArg(*this, -1, &object, defValue, TypeTag<T>());
Pop();
return object;
}
template<typename T>
T LuaState::CheckGlobal(const String& fieldName, T defValue) const
{
return CheckGlobal<T>(fieldName.GetConstBuffer(), defValue);
}
template<typename T>
int LuaState::Push(T arg) const
{
return LuaImplReplyVal(*this, std::move(arg), TypeTag<T>());
}
template<typename T, typename T2, typename... Args>
int LuaState::Push(T firstArg, T2 secondArg, Args... args) const
{
int valCount = 0;
valCount += Push(std::move(firstArg));
valCount += Push(secondArg, std::forward<Args>(args)...);
return valCount;
}
template<typename T>
void LuaState::PushField(const char* name, T&& arg, int tableIndex) const
{
Push(std::forward<T>(arg));
SetField(name, tableIndex);
}
template<typename T>
void LuaState::PushField(const String& name, T&& arg, int tableIndex) const
{
PushField(name.GetConstBuffer(), std::forward<T>(arg), tableIndex);
}
template<typename R, typename... Args, typename... DefArgs>
void LuaState::PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const
{
typename LuaImplFunctionProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
PushFunction([func, handler] (LuaState& lua) -> int
{
handler.ProcessArguments(lua);
return handler.Invoke(lua, func);
});
}
template<typename T>
void LuaState::PushGlobal(const char* name, T&& arg)
{
Push(std::forward<T>(arg));
SetGlobal(name);
}
template<typename T>
void LuaState::PushGlobal(const String& name, T&& arg)
{
PushGlobal(name.GetConstBuffer(), std::forward<T>(arg));
}
template<typename T>
void LuaState::PushInstance(const char* tname, T&& instance) const
{
T* userdata = static_cast<T*>(PushUserdata(sizeof(T)));
PlacementNew(userdata, std::move(instance));
SetMetatable(tname);
}
template<typename T, typename... Args>
void LuaState::PushInstance(const char* tname, Args&&... args) const
{
T* userdata = static_cast<T*>(PushUserdata(sizeof(T)));
PlacementNew(userdata, std::forward<Args>(args)...);
SetMetatable(tname);
}
template<typename T>
std::enable_if_t<std::is_signed<T>::value, T> LuaState::CheckBounds(int index, long long value) const
{
constexpr long long minBounds = std::numeric_limits<T>::min();
constexpr long long maxBounds = std::numeric_limits<T>::max();
if (value < minBounds || value > maxBounds)
{
Nz::StringStream stream;
stream << "Argument #" << index << " is outside value range [" << minBounds << ", " << maxBounds << "] (" << value << ')';
Error(stream);
}
return static_cast<T>(value);
}
template<typename T>
std::enable_if_t<std::is_unsigned<T>::value, T> LuaState::CheckBounds(int index, long long value) const
{
unsigned long long uValue = static_cast<unsigned long long>(value);
constexpr unsigned long long minBounds = 0;
constexpr unsigned long long maxBounds = std::numeric_limits<T>::max();
if (uValue < minBounds || uValue > maxBounds)
{
Nz::StringStream stream;
stream << "Argument #" << index << " is outside value range [" << minBounds << ", " << maxBounds << "] (" << value << ')';
Error(stream);
}
return static_cast<T>(uValue);
}
inline LuaState LuaState::GetState(lua_State* internalState)
{
return LuaState(internalState);
}
}

View File

@@ -10,8 +10,8 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ByteStream.hpp>
#include <Nazara/Core/MemoryStream.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Network/Config.hpp>
#include <mutex>
namespace Nz
{
@@ -64,7 +64,7 @@ namespace Nz
MemoryStream m_memoryStream;
UInt16 m_netCode;
static std::unique_ptr<Mutex> s_availableBuffersMutex;
static std::mutex s_availableBuffersMutex;
static std::vector<std::pair<std::size_t, std::unique_ptr<ByteArray>>> s_availableBuffers;
};
}

View File

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

View File

@@ -1,51 +0,0 @@
/*
Nazara Engine - Noise module
Copyright (C) 2016 Rémi "Overdrivr" Bèges (remi.beges@laposte.net)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_NOISE_HPP
#define NAZARA_CONFIG_NOISE_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// 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)
#define NAZARA_NOISE_MANAGE_MEMORY 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_NOISE_SAFE 1
/// Vérification des valeurs et types de certaines constantes
#include <Nazara/Noise/ConfigCheck.hpp>
#if defined(NAZARA_STATIC)
#define NAZARA_NOISE_API
#else
#ifdef NAZARA_NOISE_BUILD
#define NAZARA_NOISE_API NAZARA_EXPORT
#else
#define NAZARA_NOISE_API NAZARA_IMPORT
#endif
#endif
#endif // NAZARA_CONFIG_MODULENAME_HPP

View File

@@ -1,18 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CONFIG_CHECK_NOISE_HPP
#define NAZARA_CONFIG_CHECK_NOISE_HPP
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
// On force la valeur de MANAGE_MEMORY en mode debug
#if defined(NAZARA_DEBUG) && !NAZARA_NOISE_MANAGE_MEMORY
#undef NAZARA_NOISE_MANAGE_MEMORY
#define NAZARA_NOISE_MANAGE_MEMORY 0
#endif
#endif // NAZARA_CONFIG_CHECK_NOISE_HPP

View File

@@ -1,8 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Noise/Config.hpp>
#if NAZARA_NOISE_MANAGE_MEMORY
#include <Nazara/Core/Debug/NewRedefinition.hpp>
#endif

View File

@@ -1,9 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
#if NAZARA_NOISE_MANAGE_MEMORY
#undef delete
#undef new
#endif

View File

@@ -1,18 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_ENUMS_NOISE_HPP
#define NAZARA_ENUMS_NOISE_HPP
namespace Nz
{
enum WorleyFunction
{
WorleyFunction_F1 = 0,
WorleyFunction_F2 = 1,
WorleyFunction_F3 = 2,
WorleyFunction_F4 = 3
};
}
#endif // NAZARA_ENUMS_NOISE_HPP

View File

@@ -1,31 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_FBM_HPP
#define NAZARA_FBM_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Noise/MixerBase.hpp>
namespace Nz
{
class NAZARA_NOISE_API FBM : public MixerBase
{
public:
FBM(const NoiseBase& source);
FBM(const FBM&) = delete;
~FBM() = default;
float Get(float x, float y, float scale) const override;
float Get(float x, float y, float z, float scale) const override;
float Get(float x, float y, float z, float w, float scale) const override;
FBM& operator=(const FBM&) = delete;
private:
const NoiseBase& m_source;
};
}
#endif // NAZARA_FBM_HPP

View File

@@ -1,31 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_HYBRIDMULTIFRACTAL_HPP
#define NAZARA_HYBRIDMULTIFRACTAL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Noise/MixerBase.hpp>
namespace Nz
{
class NAZARA_NOISE_API HybridMultiFractal : public MixerBase
{
public:
HybridMultiFractal(const NoiseBase & source);
HybridMultiFractal(const HybridMultiFractal&) = delete;
~HybridMultiFractal() = default;
float Get(float x, float y, float scale) const override;
float Get(float x, float y, float z, float scale) const override;
float Get(float x, float y, float z, float w, float scale) const override;
HybridMultiFractal& operator=(const HybridMultiFractal&) = delete;
private:
const NoiseBase& m_source;
};
}
#endif // NAZARA_HYBRIDMULTIFRACTAL_HPP

View File

@@ -1,41 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_MIXERBASE_HPP
#define NAZARA_MIXERBASE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Noise/NoiseBase.hpp>
namespace Nz
{
class NAZARA_NOISE_API MixerBase
{
public:
MixerBase();
virtual ~MixerBase() = default;
virtual float Get(float x, float y, float scale) const = 0;
virtual float Get(float x, float y, float z, float scale) const = 0;
virtual float Get(float x, float y, float z, float w, float scale) const = 0;
float GetHurstParameter() const;
float GetLacunarity() const;
float GetOctaveNumber() const;
void SetParameters(float hurst, float lacunarity, float octaves);
protected:
float m_hurst;
float m_lacunarity;
float m_octaves;
std::vector<float> m_exponent_array;
float m_sum;
private:
void Recompute();
};
}
#endif // NAZARA_MIXERBASE_HPP

View File

@@ -1,32 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_NOISE_HPP
#define NAZARA_NOISE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Noise/Config.hpp>
namespace Nz
{
class NAZARA_NOISE_API Noise
{
public:
Noise() = delete;
~Noise() = delete;
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static unsigned int s_moduleReferenceCounter;
};
}
#endif // NAZARA_NOISE_HPP

View File

@@ -1,47 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_NOISEBASE_HPP
#define NAZARA_NOISEBASE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Noise/Config.hpp>
#include <array>
#include <random>
namespace Nz
{
class NAZARA_NOISE_API NoiseBase
{
public:
NoiseBase(unsigned int seed = 0);
virtual ~NoiseBase() = default;
virtual float Get(float x, float y, float scale) const = 0;
virtual float Get(float x, float y, float z, float scale) const = 0;
virtual float Get(float x, float y, float z, float w, float scale) const = 0;
float GetScale();
void SetScale(float scale);
void SetSeed(unsigned int seed);
void Shuffle();
protected:
std::array<std::size_t, 3 * 256> m_permutations;
float m_scale;
static std::array<Vector2f, 2 * 2 * 2> s_gradients2;
static std::array<Vector3f, 2 * 2 * 2 * 2> s_gradients3;
static std::array<Vector4f, 2 * 2 * 2 * 2 * 2> s_gradients4;
private:
std::mt19937 m_randomEngine;
};
}
#endif // NAZARA_NOISEBASE_HPP

View File

@@ -1,14 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_NOISETOOLS_HPP
#define NAZARA_NOISETOOLS_HPP
namespace Nz
{
int fastfloor(float n);
int JenkinsHash(int a, int b, int c);
}
#endif // NAZARA_NOISETOOLS_HPP

View File

@@ -1,27 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_PERLIN_HPP
#define NAZARA_PERLIN_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/NoiseBase.hpp>
namespace Nz
{
class NAZARA_NOISE_API Perlin : public NoiseBase
{
public:
Perlin() = default;
Perlin(unsigned int seed);
~Perlin() = default;
float Get(float x, float y, float scale) const override;
float Get(float x, float y, float z, float scale) const override;
float Get(float x, float y, float z, float w, float scale) const override;
};
}
#endif // NAZARA_PERLIN_HPP

View File

@@ -1,27 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_SIMPLEX_HPP
#define NAZARA_SIMPLEX_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/NoiseBase.hpp>
namespace Nz
{
class NAZARA_NOISE_API Simplex : public NoiseBase
{
public:
Simplex() = default;
Simplex(unsigned int seed);
~Simplex() = default;
float Get(float x, float y, float scale) const override;
float Get(float x, float y, float z, float scale) const override;
float Get(float x, float y, float z, float w, float scale) const override;
};
}
#endif // NAZARA_SIMPLEX_HPP

View File

@@ -1,37 +0,0 @@
// Copyright (C) 2017 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_WORLEY_HPP
#define NAZARA_WORLEY_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/Enums.hpp>
#include <Nazara/Noise/NoiseBase.hpp>
#include <map>
namespace Nz
{
class NAZARA_NOISE_API Worley : public NoiseBase
{
public:
Worley();
Worley(unsigned int seed);
~Worley() = default;
float Get(float x, float y, float scale) const override;
float Get(float x, float y, float z, float scale) const override;
float Get(float x, float y, float z, float w, float scale) const override;
void Set(WorleyFunction func);
private:
void SquareTest(int xi, int yi, float x, float y, std::map<float, Vector2f> & featurePoints) const;
WorleyFunction m_function;
};
}
#endif // NAZARA_WORLEY_HPP

View File

@@ -10,9 +10,7 @@
#define NAZARA_WINDOW_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Config.hpp>
@@ -23,6 +21,8 @@
#include <Nazara/Platform/Icon.hpp>
#include <Nazara/Platform/VideoMode.hpp>
#include <Nazara/Platform/WindowHandle.hpp>
#include <condition_variable>
#include <mutex>
#include <queue>
namespace Nz
@@ -126,13 +126,13 @@ namespace Nz
std::queue<WindowEvent> m_events;
std::vector<WindowEvent> m_pendingEvents;
ConditionVariable m_eventCondition;
std::condition_variable m_eventCondition;
CursorController m_cursorController;
CursorRef m_cursor;
EventHandler m_eventHandler;
IconRef m_icon;
Mutex m_eventMutex;
Mutex m_eventConditionMutex;
std::mutex m_eventMutex;
std::mutex m_eventConditionMutex;
bool m_asyncWindow;
bool m_closed;
bool m_closeOnQuit;

View File

@@ -4,7 +4,6 @@
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Platform/Debug.hpp>
namespace Nz
@@ -98,16 +97,15 @@ namespace Nz
else
{
{
LockGuard eventLock(m_eventMutex);
std::lock_guard<std::mutex> eventLock(m_eventMutex);
m_pendingEvents.push_back(event);
}
if (m_waitForEvent)
{
m_eventConditionMutex.Lock();
m_eventCondition.Signal();
m_eventConditionMutex.Unlock();
std::lock_guard<std::mutex> lock(m_eventConditionMutex);
m_eventCondition.notify_all();
}
}
}

View File

@@ -20,6 +20,7 @@
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <filesystem>
namespace Nz
{
@@ -43,7 +44,7 @@ namespace Nz
~Shader();
void AttachStage(ShaderStageType stage, const ShaderStage& shaderStage);
bool AttachStageFromFile(ShaderStageType stage, const String& filePath);
bool AttachStageFromFile(ShaderStageType stage, const std::filesystem::path& filePath);
bool AttachStageFromSource(ShaderStageType stage, const char* source, unsigned int length);
bool AttachStageFromSource(ShaderStageType stage, const String& source);

View File

@@ -68,13 +68,13 @@ namespace Nz
bool IsValid() const;
// LoadFace
bool LoadFaceFromFile(CubemapFace face, const String& filePath, const ImageParams& params = ImageParams());
bool LoadFaceFromFile(CubemapFace face, const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams());
// Save
bool SaveToFile(const String& filePath, const ImageParams& params = ImageParams());
bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams());
bool SaveToFile(const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
bool SaveToStream(Stream& stream, const std::string& format, const ImageParams& params = ImageParams());
bool SetMipmapRange(UInt8 minLevel, UInt8 maxLevel);
@@ -96,19 +96,19 @@ namespace Nz
static bool IsTypeSupported(ImageType type);
// Load
static TextureRef LoadFromFile(const String& filePath, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
static TextureRef LoadFromFile(const std::filesystem::path& filePath, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
static TextureRef LoadFromImage(const Image* image, bool generateMipmaps = true);
static TextureRef LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
static TextureRef LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
// LoadArray
static TextureRef LoadArrayFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
static TextureRef LoadArrayFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
static TextureRef LoadArrayFromImage(const Image* image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
static TextureRef LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
static TextureRef LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
// LoadCubemap
static TextureRef LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
static TextureRef LoadCubemapFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
static TextureRef LoadCubemapFromImage(const Image* image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams());
static TextureRef LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
static TextureRef LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());

View File

@@ -26,9 +26,9 @@ namespace Nz
struct NAZARA_UTILITY_API AnimationParams : ResourceParameters
{
// La frame de fin à charger
UInt32 endFrame = 0xFFFFFFFF;
std::size_t endFrame = 0xFFFFFFFF;
// La frame de début à charger
UInt32 startFrame = 0;
std::size_t startFrame = 0;
bool IsValid() const;
};
@@ -58,37 +58,37 @@ namespace Nz
~Animation();
bool AddSequence(const Sequence& sequence);
void AnimateSkeleton(Skeleton* targetSkeleton, UInt32 frameA, UInt32 frameB, float interpolation) const;
void AnimateSkeleton(Skeleton* targetSkeleton, std::size_t frameA, std::size_t frameB, float interpolation) const;
bool CreateSkeletal(UInt32 frameCount, UInt32 jointCount);
bool CreateSkeletal(std::size_t frameCount, std::size_t jointCount);
void Destroy();
void EnableLoopPointInterpolation(bool loopPointInterpolation);
UInt32 GetFrameCount() const;
UInt32 GetJointCount() const;
std::size_t GetFrameCount() const;
std::size_t GetJointCount() const;
Sequence* GetSequence(const String& sequenceName);
Sequence* GetSequence(UInt32 index);
Sequence* GetSequence(std::size_t index);
const Sequence* GetSequence(const String& sequenceName) const;
const Sequence* GetSequence(UInt32 index) const;
UInt32 GetSequenceCount() const;
UInt32 GetSequenceIndex(const String& sequenceName) const;
SequenceJoint* GetSequenceJoints(UInt32 frameIndex = 0);
const SequenceJoint* GetSequenceJoints(UInt32 frameIndex = 0) const;
const Sequence* GetSequence(std::size_t index) const;
std::size_t GetSequenceCount() const;
std::size_t GetSequenceIndex(const String& sequenceName) const;
SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0);
const SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0) const;
AnimationType GetType() const;
bool HasSequence(const String& sequenceName) const;
bool HasSequence(UInt32 index = 0) const;
bool HasSequence(std::size_t index = 0) const;
bool IsLoopPointInterpolationEnabled() const;
bool IsValid() const;
void RemoveSequence(const String& sequenceName);
void RemoveSequence(UInt32 index);
void RemoveSequence(std::size_t index);
template<typename... Args> static AnimationRef New(Args&&... args);
static AnimationRef LoadFromFile(const String& filePath, const AnimationParams& params = AnimationParams());
static AnimationRef LoadFromFile(const std::filesystem::path& filePath, const AnimationParams& params = AnimationParams());
static AnimationRef LoadFromMemory(const void* data, std::size_t size, const AnimationParams& params = AnimationParams());
static AnimationRef LoadFromStream(Stream& stream, const AnimationParams& params = AnimationParams());

View File

@@ -89,7 +89,7 @@ namespace Nz
static unsigned int GetDefaultGlyphBorder();
static unsigned int GetDefaultMinimumStepSize();
static FontRef OpenFromFile(const String& filePath, const FontParams& params = FontParams());
static FontRef OpenFromFile(const std::filesystem::path& filePath, const FontParams& params = FontParams());
static FontRef OpenFromMemory(const void* data, std::size_t size, const FontParams& params = FontParams());
static FontRef OpenFromStream(Stream& stream, const FontParams& params = FontParams());

View File

@@ -49,7 +49,7 @@ namespace Nz
std::vector<Triangle> triangles;
std::vector<Vertex> vertices;
std::vector<Weight> weights;
String shader;
std::string shader;
};
MD5MeshParser(Stream& stream);
@@ -66,17 +66,17 @@ namespace Nz
private:
bool Advance(bool required = true);
void Error(const String& message);
void Error(const std::string& message);
bool ParseJoints();
bool ParseMesh();
void Warning(const String& message);
void Warning(const std::string& message);
void UnrecognizedLine(bool error = false);
std::vector<Joint> m_joints;
std::vector<Mesh> m_meshes;
Stream& m_stream;
StreamOptionFlags m_streamFlags;
String m_currentLine;
std::string m_currentLine;
bool m_keepLastLine;
unsigned int m_lineCount;
unsigned int m_meshIndex;

View File

@@ -9,7 +9,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Config.hpp>
#include <unordered_map>
@@ -23,12 +22,12 @@ namespace Nz
MTLParser() = default;
~MTLParser() = default;
inline Material* AddMaterial(const String& matName);
inline Material* AddMaterial(const std::string& matName);
inline void Clear();
inline const Material* GetMaterial(const String& materialName) const;
inline const std::unordered_map<String, Material>& GetMaterials() const;
inline const Material* GetMaterial(const std::string& materialName) const;
inline const std::unordered_map<std::string, Material>& GetMaterials() const;
bool Parse(Stream& stream);
@@ -39,17 +38,17 @@ namespace Nz
Color ambient = Color::White;
Color diffuse = Color::White;
Color specular = Color::White;
String alphaMap;
String ambientMap;
String bumpMap;
String decalMap;
String diffuseMap;
String displacementMap;
String emissiveMap; //< <!> Custom addition: not present in MTL
String normalMap; //< <!> Custom addition: not present in MTL
String reflectionMap;
String shininessMap;
String specularMap;
std::string alphaMap;
std::string ambientMap;
std::string bumpMap;
std::string decalMap;
std::string diffuseMap;
std::string displacementMap;
std::string emissiveMap; //< <!> Custom addition: not present in MTL
std::string normalMap; //< <!> Custom addition: not present in MTL
std::string reflectionMap;
std::string shininessMap;
std::string specularMap;
float alpha = 1.f;
float refractionIndex = 1.f;
float shininess = 1.f;
@@ -61,14 +60,14 @@ namespace Nz
template<typename T> void Emit(const T& text) const;
inline void EmitLine() const;
template<typename T> void EmitLine(const T& line) const;
inline void Error(const String& message);
inline void Error(const std::string& message);
inline void Flush() const;
inline void Warning(const String& message);
inline void Warning(const std::string& message);
inline void UnrecognizedLine(bool error = false);
std::unordered_map<String, Material> m_materials;
std::unordered_map<std::string, Material> m_materials;
mutable Stream* m_currentStream;
String m_currentLine;
std::string m_currentLine;
mutable StringStream m_outputStream;
bool m_keepLastLine;
unsigned int m_lineCount;

View File

@@ -7,7 +7,7 @@
namespace Nz
{
inline MTLParser::Material* MTLParser::AddMaterial(const String& matName)
inline MTLParser::Material* MTLParser::AddMaterial(const std::string& matName)
{
return &m_materials[matName];
}
@@ -17,7 +17,7 @@ namespace Nz
m_materials.clear();
}
inline const MTLParser::Material* MTLParser::GetMaterial(const String& materialName) const
inline const MTLParser::Material* MTLParser::GetMaterial(const std::string& materialName) const
{
auto it = m_materials.find(materialName);
if (it != m_materials.end())
@@ -26,7 +26,7 @@ namespace Nz
return nullptr;
}
inline const std::unordered_map<String, MTLParser::Material>& MTLParser::GetMaterials() const
inline const std::unordered_map<std::string, MTLParser::Material>& MTLParser::GetMaterials() const
{
return m_materials;
}
@@ -51,9 +51,9 @@ namespace Nz
Emit('\n');
}
inline void MTLParser::Error(const String& message)
inline void MTLParser::Error(const std::string& message)
{
NazaraError(message + " at line #" + String::Number(m_lineCount));
NazaraError(message + " at line #" + std::to_string(m_lineCount));
}
inline void MTLParser::Flush() const
@@ -62,14 +62,14 @@ namespace Nz
m_outputStream.Clear();
}
inline void MTLParser::Warning(const String& message)
inline void MTLParser::Warning(const std::string& message)
{
NazaraWarning(message + " at line #" + String::Number(m_lineCount));
NazaraWarning(message + " at line #" + std::to_string(m_lineCount));
}
inline void MTLParser::UnrecognizedLine(bool error)
{
String message = "Unrecognized \"" + m_currentLine + '"';
std::string message = "Unrecognized \"" + m_currentLine + '"';
if (error)
Error(message);

View File

@@ -8,7 +8,6 @@
#define NAZARA_FORMATS_OBJPARSER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Utility/Config.hpp>
@@ -28,53 +27,53 @@ namespace Nz
bool Check(Stream& stream);
inline String* GetMaterials();
inline const String* GetMaterials() const;
inline UInt32 GetMaterialCount() const;
inline std::string* GetMaterials();
inline const std::string* GetMaterials() const;
inline std::size_t GetMaterialCount() const;
inline Mesh* GetMeshes();
inline const Mesh* GetMeshes() const;
inline UInt32 GetMeshCount() const;
inline const String& GetMtlLib() const;
inline std::size_t GetMeshCount() const;
inline const std::filesystem::path& GetMtlLib() const;
inline Vector3f* GetNormals();
inline const Vector3f* GetNormals() const;
inline UInt32 GetNormalCount() const;
inline std::size_t GetNormalCount() const;
inline Vector4f* GetPositions();
inline const Vector4f* GetPositions() const;
inline UInt32 GetPositionCount() const;
inline std::size_t GetPositionCount() const;
inline Vector3f* GetTexCoords();
inline const Vector3f* GetTexCoords() const;
inline UInt32 GetTexCoordCount() const;
inline std::size_t GetTexCoordCount() const;
bool Parse(Stream& stream, UInt32 reservedVertexCount = 100);
bool Parse(Stream& stream, std::size_t reservedVertexCount = 100);
bool Save(Stream& stream) const;
inline String* SetMaterialCount(UInt32 materialCount);
inline Mesh* SetMeshCount(UInt32 meshCount);
inline void SetMtlLib(const String& mtlLib);
inline Vector3f* SetNormalCount(UInt32 normalCount);
inline Vector4f* SetPositionCount(UInt32 positionCount);
inline Vector3f* SetTexCoordCount(UInt32 texCoordCount);
inline std::string* SetMaterialCount(std::size_t materialCount);
inline Mesh* SetMeshCount(std::size_t meshCount);
inline void SetMtlLib(const std::filesystem::path& mtlLib);
inline Vector3f* SetNormalCount(std::size_t normalCount);
inline Vector4f* SetPositionCount(std::size_t positionCount);
inline Vector3f* SetTexCoordCount(std::size_t texCoordCount);
struct Face
{
UInt32 firstVertex;
UInt32 vertexCount;
std::size_t firstVertex;
std::size_t vertexCount;
};
struct FaceVertex
{
UInt32 normal;
UInt32 position;
UInt32 texCoord;
std::size_t normal;
std::size_t position;
std::size_t texCoord;
};
struct Mesh
{
std::vector<Face> faces;
std::vector<FaceVertex> vertices;
String name;
UInt32 material;
std::string name;
std::size_t material;
};
private:
@@ -82,19 +81,19 @@ namespace Nz
template<typename T> void Emit(const T& text) const;
inline void EmitLine() const;
template<typename T> void EmitLine(const T& line) const;
inline void Error(const String& message);
inline void Error(const std::string& message);
inline void Flush() const;
inline void Warning(const String& message);
inline void Warning(const std::string& message);
inline bool UnrecognizedLine(bool error = false);
std::vector<Mesh> m_meshes;
std::vector<String> m_materials;
std::vector<std::string> m_materials;
std::vector<Vector3f> m_normals;
std::vector<Vector4f> m_positions;
std::vector<Vector3f> m_texCoords;
mutable Stream* m_currentStream;
String m_currentLine;
String m_mtlLib;
std::string m_currentLine;
std::filesystem::path m_mtlLib;
mutable StringStream m_outputStream;
bool m_keepLastLine;
unsigned int m_lineCount;

View File

@@ -16,19 +16,19 @@ namespace Nz
m_texCoords.clear();
}
inline String* OBJParser::GetMaterials()
inline std::string* OBJParser::GetMaterials()
{
return m_materials.data();
}
inline const String* OBJParser::GetMaterials() const
inline const std::string* OBJParser::GetMaterials() const
{
return m_materials.data();
}
inline UInt32 OBJParser::GetMaterialCount() const
inline std::size_t OBJParser::GetMaterialCount() const
{
return static_cast<UInt32>(m_materials.size());
return m_materials.size();
}
inline OBJParser::Mesh* OBJParser::GetMeshes()
@@ -41,12 +41,12 @@ namespace Nz
return m_meshes.data();
}
inline UInt32 OBJParser::GetMeshCount() const
inline std::size_t OBJParser::GetMeshCount() const
{
return static_cast<UInt32>(m_meshes.size());
return m_meshes.size();
}
inline const String& OBJParser::GetMtlLib() const
inline const std::filesystem::path& OBJParser::GetMtlLib() const
{
return m_mtlLib;
}
@@ -61,9 +61,9 @@ namespace Nz
return m_normals.data();
}
inline UInt32 OBJParser::GetNormalCount() const
inline std::size_t OBJParser::GetNormalCount() const
{
return static_cast<UInt32>(m_normals.size());
return m_normals.size();
}
inline Vector4f* OBJParser::GetPositions()
@@ -76,9 +76,9 @@ namespace Nz
return m_positions.data();
}
inline UInt32 OBJParser::GetPositionCount() const
inline std::size_t OBJParser::GetPositionCount() const
{
return static_cast<UInt32>(m_positions.size());
return m_positions.size();
}
inline Vector3f* OBJParser::GetTexCoords()
@@ -91,41 +91,41 @@ namespace Nz
return m_texCoords.data();
}
inline UInt32 OBJParser::GetTexCoordCount() const
inline std::size_t OBJParser::GetTexCoordCount() const
{
return static_cast<UInt32>(m_texCoords.size());
return m_texCoords.size();
}
inline String* OBJParser::SetMaterialCount(UInt32 materialCount)
inline std::string* OBJParser::SetMaterialCount(std::size_t materialCount)
{
m_materials.resize(materialCount);
return m_materials.data();
}
inline OBJParser::Mesh* OBJParser::SetMeshCount(UInt32 meshCount)
inline OBJParser::Mesh* OBJParser::SetMeshCount(std::size_t meshCount)
{
m_meshes.resize(meshCount);
return m_meshes.data();
}
inline void OBJParser::SetMtlLib(const String& mtlLib)
inline void OBJParser::SetMtlLib(const std::filesystem::path& mtlLib)
{
m_mtlLib = mtlLib;
}
inline Vector3f* OBJParser::SetNormalCount(UInt32 normalCount)
inline Vector3f* OBJParser::SetNormalCount(std::size_t normalCount)
{
m_normals.resize(normalCount);
return m_normals.data();
}
inline Vector4f* OBJParser::SetPositionCount(UInt32 positionCount)
inline Vector4f* OBJParser::SetPositionCount(std::size_t positionCount)
{
m_positions.resize(positionCount);
return m_positions.data();
}
inline Vector3f* OBJParser::SetTexCoordCount(UInt32 texCoordCount)
inline Vector3f* OBJParser::SetTexCoordCount(std::size_t texCoordCount)
{
m_texCoords.resize(texCoordCount);
return m_texCoords.data();
@@ -151,9 +151,9 @@ namespace Nz
Emit('\n');
}
inline void OBJParser::Error(const String& message)
inline void OBJParser::Error(const std::string& message)
{
NazaraError(message + " at line #" + String::Number(m_lineCount));
NazaraError(message + " at line #" + std::to_string(m_lineCount));
}
inline void OBJParser::Flush() const
@@ -162,14 +162,14 @@ namespace Nz
m_outputStream.Clear();
}
inline void OBJParser::Warning(const String& message)
inline void OBJParser::Warning(const std::string& message)
{
NazaraWarning(message + " at line #" + String::Number(m_lineCount));
NazaraWarning(message + " at line #" + std::to_string(m_lineCount));
}
inline bool OBJParser::UnrecognizedLine(bool error)
{
String message = "Unrecognized \"" + m_currentLine + '"';
std::string message = "Unrecognized \"" + m_currentLine + '"';
if (error)
Error(message);

View File

@@ -94,13 +94,13 @@ namespace Nz
bool IsValid() const;
// LoadFace
bool LoadFaceFromFile(CubemapFace face, const String& filePath, const ImageParams& params = ImageParams());
bool LoadFaceFromFile(CubemapFace face, const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams());
// Save
bool SaveToFile(const String& filePath, const ImageParams& params = ImageParams());
bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams());
bool SaveToFile(const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
bool SaveToStream(Stream& stream, const std::string& format, const ImageParams& params = ImageParams());
//TODO: SaveArray, SaveCubemap, SaveFace
@@ -118,18 +118,18 @@ namespace Nz
static UInt8 GetMaxLevel(ImageType type, unsigned int width, unsigned int height, unsigned int depth = 1);
// Load
static ImageRef LoadFromFile(const String& filePath, const ImageParams& params = ImageParams());
static ImageRef LoadFromFile(const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
static ImageRef LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams());
static ImageRef LoadFromStream(Stream& stream, const ImageParams& params = ImageParams());
// LoadArray
static ImageRef LoadArrayFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
static ImageRef LoadArrayFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
static ImageRef LoadArrayFromImage(const Image* image, const Vector2ui& atlasSize = Vector2ui(2, 2));
static ImageRef LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
static ImageRef LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
// LoadCubemap
static ImageRef LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
static ImageRef LoadCubemapFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
static ImageRef LoadCubemapFromImage(const Image* image, const CubemapParams& params = CubemapParams());
static ImageRef LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
static ImageRef LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());

View File

@@ -24,38 +24,38 @@ namespace Nz
public:
IndexBuffer() = default;
IndexBuffer(bool largeIndices, BufferRef buffer);
IndexBuffer(bool largeIndices, BufferRef buffer, UInt32 offset, UInt32 size);
IndexBuffer(bool largeIndices, UInt32 length, DataStorage storage, BufferUsageFlags usage);
IndexBuffer(bool largeIndices, BufferRef buffer, std::size_t offset, std::size_t size);
IndexBuffer(bool largeIndices, std::size_t length, DataStorage storage, BufferUsageFlags usage);
IndexBuffer(const IndexBuffer& indexBuffer);
IndexBuffer(IndexBuffer&&) = delete;
~IndexBuffer();
unsigned int ComputeCacheMissCount() const;
bool Fill(const void* data, UInt32 startIndex, UInt32 length);
bool FillRaw(const void* data, UInt32 offset, UInt32 size);
bool Fill(const void* data, std::size_t startIndex, std::size_t length);
bool FillRaw(const void* data, std::size_t offset, std::size_t size);
inline const BufferRef& GetBuffer() const;
inline UInt32 GetEndOffset() const;
inline UInt32 GetIndexCount() const;
inline UInt32 GetStride() const;
inline UInt32 GetStartOffset() const;
inline std::size_t GetEndOffset() const;
inline std::size_t GetIndexCount() const;
inline std::size_t GetStride() const;
inline std::size_t GetStartOffset() const;
inline bool HasLargeIndices() const;
inline bool IsValid() const;
inline void* Map(BufferAccess access, UInt32 startVertex = 0, UInt32 length = 0);
inline void* Map(BufferAccess access, UInt32 startVertex = 0, UInt32 length = 0) const;
void* MapRaw(BufferAccess access, UInt32 offset = 0, UInt32 size = 0);
void* MapRaw(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) const;
inline void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0);
inline void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0) const;
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0);
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0) const;
void Optimize();
void Reset();
void Reset(bool largeIndices, BufferRef buffer);
void Reset(bool largeIndices, BufferRef buffer, UInt32 offset, UInt32 size);
void Reset(bool largeIndices, UInt32 length, DataStorage storage, BufferUsageFlags usage);
void Reset(bool largeIndices, BufferRef buffer, std::size_t offset, std::size_t size);
void Reset(bool largeIndices, std::size_t length, DataStorage storage, BufferUsageFlags usage);
void Reset(const IndexBuffer& indexBuffer);
void Unmap() const;
@@ -70,9 +70,9 @@ namespace Nz
private:
BufferRef m_buffer;
UInt32 m_endOffset;
UInt32 m_indexCount;
UInt32 m_startOffset;
std::size_t m_endOffset;
std::size_t m_indexCount;
std::size_t m_startOffset;
bool m_largeIndices;
};
}

View File

@@ -12,22 +12,22 @@ namespace Nz
return m_buffer;
}
inline UInt32 IndexBuffer::GetEndOffset() const
inline std::size_t IndexBuffer::GetEndOffset() const
{
return m_endOffset;
}
inline UInt32 IndexBuffer::GetIndexCount() const
inline std::size_t IndexBuffer::GetIndexCount() const
{
return m_indexCount;
}
inline UInt32 IndexBuffer::GetStride() const
inline std::size_t IndexBuffer::GetStride() const
{
return static_cast<UInt32>((m_largeIndices) ? sizeof(UInt32) : sizeof(UInt16));
return static_cast<std::size_t>((m_largeIndices) ? sizeof(std::size_t) : sizeof(UInt16));
}
inline UInt32 IndexBuffer::GetStartOffset() const
inline std::size_t IndexBuffer::GetStartOffset() const
{
return m_startOffset;
}
@@ -42,15 +42,15 @@ namespace Nz
return m_buffer.IsValid();
}
inline void* IndexBuffer::Map(BufferAccess access, UInt32 startIndex, UInt32 length)
inline void* IndexBuffer::Map(BufferAccess access, std::size_t startIndex, std::size_t length)
{
UInt32 stride = GetStride();
std::size_t stride = GetStride();
return MapRaw(access, startIndex*stride, length*stride);
}
inline void* IndexBuffer::Map(BufferAccess access, UInt32 startIndex, UInt32 length) const
inline void* IndexBuffer::Map(BufferAccess access, std::size_t startIndex, std::size_t length) const
{
UInt32 stride = GetStride();
std::size_t stride = GetStride();
return MapRaw(access, startIndex*stride, length*stride);
}

View File

@@ -89,12 +89,12 @@ namespace Nz
inline ~Mesh();
void AddSubMesh(SubMesh* subMesh);
void AddSubMesh(const String& identifier, SubMesh* subMesh);
void AddSubMesh(const std::string& identifier, SubMesh* subMesh);
SubMesh* BuildSubMesh(const Primitive& primitive, const MeshParams& params = MeshParams());
void BuildSubMeshes(const PrimitiveList& list, const MeshParams& params = MeshParams());
bool CreateSkeletal(UInt32 jointCount);
bool CreateSkeletal(std::size_t jointCount);
bool CreateStatic();
void Destroy();
@@ -103,25 +103,25 @@ namespace Nz
void GenerateTangents();
const Boxf& GetAABB() const;
String GetAnimation() const;
std::filesystem::path GetAnimation() const;
AnimationType GetAnimationType() const;
UInt32 GetJointCount() const;
ParameterList& GetMaterialData(UInt32 index);
const ParameterList& GetMaterialData(UInt32 index) const;
UInt32 GetMaterialCount() const;
std::size_t GetJointCount() const;
ParameterList& GetMaterialData(std::size_t index);
const ParameterList& GetMaterialData(std::size_t index) const;
std::size_t GetMaterialCount() const;
Skeleton* GetSkeleton();
const Skeleton* GetSkeleton() const;
SubMesh* GetSubMesh(const String& identifier);
SubMesh* GetSubMesh(UInt32 index);
const SubMesh* GetSubMesh(const String& identifier) const;
const SubMesh* GetSubMesh(UInt32 index) const;
UInt32 GetSubMeshCount() const;
UInt32 GetSubMeshIndex(const String& identifier) const;
UInt32 GetTriangleCount() const;
UInt32 GetVertexCount() const;
SubMesh* GetSubMesh(const std::string& identifier);
SubMesh* GetSubMesh(std::size_t index);
const SubMesh* GetSubMesh(const std::string& identifier) const;
const SubMesh* GetSubMesh(std::size_t index) const;
std::size_t GetSubMeshCount() const;
std::size_t GetSubMeshIndex(const std::string& identifier) const;
std::size_t GetTriangleCount() const;
std::size_t GetVertexCount() const;
bool HasSubMesh(const String& identifier) const;
bool HasSubMesh(UInt32 index = 0) const;
bool HasSubMesh(const std::string& identifier) const;
bool HasSubMesh(std::size_t index = 0) const;
void InvalidateAABB() const;
@@ -130,22 +130,22 @@ namespace Nz
void Recenter();
void RemoveSubMesh(const String& identifier);
void RemoveSubMesh(UInt32 index);
void RemoveSubMesh(const std::string& identifier);
void RemoveSubMesh(std::size_t index);
bool SaveToFile(const String& filePath, const MeshParams& params = MeshParams());
bool SaveToStream(Stream& stream, const String& format, const MeshParams& params = MeshParams());
bool SaveToFile(const std::filesystem::path& filePath, const MeshParams& params = MeshParams());
bool SaveToStream(Stream& stream, const std::string& format, const MeshParams& params = MeshParams());
void SetAnimation(const String& animationPath);
void SetMaterialCount(UInt32 matCount);
void SetMaterialData(UInt32 matIndex, ParameterList data);
void SetAnimation(const std::filesystem::path& animationPath);
void SetMaterialCount(std::size_t matCount);
void SetMaterialData(std::size_t matIndex, ParameterList data);
void Transform(const Matrix4f& matrix);
Mesh& operator=(const Mesh&) = delete;
Mesh& operator=(Mesh&&) = delete;
static MeshRef LoadFromFile(const String& filePath, const MeshParams& params = MeshParams());
static MeshRef LoadFromFile(const std::filesystem::path& filePath, const MeshParams& params = MeshParams());
static MeshRef LoadFromMemory(const void* data, std::size_t size, const MeshParams& params = MeshParams());
static MeshRef LoadFromStream(Stream& stream, const MeshParams& params = MeshParams());
@@ -164,16 +164,16 @@ namespace Nz
NazaraSlot(SubMesh, OnSubMeshInvalidateAABB, onSubMeshInvalidated);
};
std::unordered_map<String, UInt32> m_subMeshMap;
std::unordered_map<std::string, std::size_t> m_subMeshMap;
std::vector<ParameterList> m_materialData;
std::vector<SubMeshData> m_subMeshes;
AnimationType m_animationType;
mutable Boxf m_aabb;
Skeleton m_skeleton; // Only used by skeletal meshes
String m_animationPath;
std::filesystem::path m_animationPath;
mutable bool m_aabbUpdated;
bool m_isValid;
UInt32 m_jointCount; // Only used by skeletal meshes
std::size_t m_jointCount; // Only used by skeletal meshes
static bool Initialize();
static void Uninitialize();

View File

@@ -36,13 +36,13 @@ namespace Nz
void Destroy();
const Boxf& GetAABB() const override;
AnimationType GetAnimationType() const final override;
AnimationType GetAnimationType() const final;
const IndexBuffer* GetIndexBuffer() const override;
VertexBuffer* GetVertexBuffer();
const VertexBuffer* GetVertexBuffer() const;
unsigned int GetVertexCount() const override;
std::size_t GetVertexCount() const override;
bool IsAnimated() const final override;
bool IsAnimated() const final;
bool IsValid() const;
void SetAABB(const Boxf& aabb);

View File

@@ -37,21 +37,21 @@ namespace Nz
Skeleton(const Skeleton& skeleton);
~Skeleton();
bool Create(UInt32 jointCount);
bool Create(std::size_t jointCount);
void Destroy();
const Boxf& GetAABB() const;
Joint* GetJoint(const String& jointName);
Joint* GetJoint(UInt32 index);
Joint* GetJoint(std::size_t index);
const Joint* GetJoint(const String& jointName) const;
const Joint* GetJoint(UInt32 index) const;
const Joint* GetJoint(std::size_t index) const;
Joint* GetJoints();
const Joint* GetJoints() const;
UInt32 GetJointCount() const;
std::size_t GetJointCount() const;
int GetJointIndex(const String& jointName) const;
void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation);
void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, UInt32* indices, UInt32 indiceCount);
void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, std::size_t* indices, std::size_t indiceCount);
bool IsValid() const;

View File

@@ -37,13 +37,13 @@ namespace Nz
bool GenerateAABB();
const Boxf& GetAABB() const override;
AnimationType GetAnimationType() const final override;
AnimationType GetAnimationType() const final;
const IndexBuffer* GetIndexBuffer() const override;
VertexBuffer* GetVertexBuffer();
const VertexBuffer* GetVertexBuffer() const;
unsigned int GetVertexCount() const override;
std::size_t GetVertexCount() const override;
bool IsAnimated() const final override;
bool IsAnimated() const final;
bool IsValid() const;
void SetAABB(const Boxf& aabb);

View File

@@ -44,14 +44,14 @@ namespace Nz
virtual const Boxf& GetAABB() const = 0;
virtual AnimationType GetAnimationType() const = 0;
virtual const IndexBuffer* GetIndexBuffer() const = 0;
UInt32 GetMaterialIndex() const;
std::size_t GetMaterialIndex() const;
PrimitiveMode GetPrimitiveMode() const;
UInt32 GetTriangleCount() const;
virtual UInt32 GetVertexCount() const = 0;
std::size_t GetTriangleCount() const;
virtual std::size_t GetVertexCount() const = 0;
virtual bool IsAnimated() const = 0;
void SetMaterialIndex(UInt32 matIndex);
void SetMaterialIndex(std::size_t matIndex);
void SetPrimitiveMode(PrimitiveMode mode);
SubMesh& operator=(const SubMesh&) = delete;
@@ -63,7 +63,7 @@ namespace Nz
protected:
PrimitiveMode m_primitiveMode;
UInt32 m_matIndex;
std::size_t m_matIndex;
};
}

View File

@@ -26,33 +26,33 @@ namespace Nz
public:
VertexBuffer() = default;
VertexBuffer(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer);
VertexBuffer(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, UInt32 offset, UInt32 size);
VertexBuffer(VertexDeclarationConstRef vertexDeclaration, UInt32 length, DataStorage storage, BufferUsageFlags usage);
VertexBuffer(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, std::size_t offset, std::size_t size);
VertexBuffer(VertexDeclarationConstRef vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
VertexBuffer(const VertexBuffer& vertexBuffer);
VertexBuffer(VertexBuffer&&) = delete;
~VertexBuffer();
bool Fill(const void* data, UInt32 startVertex, UInt32 length);
bool FillRaw(const void* data, UInt32 offset, UInt32 size);
bool Fill(const void* data, std::size_t startVertex, std::size_t length);
bool FillRaw(const void* data, std::size_t offset, std::size_t size);
inline const BufferRef& GetBuffer() const;
inline UInt32 GetEndOffset() const;
inline UInt32 GetStartOffset() const;
inline UInt32 GetStride() const;
inline UInt32 GetVertexCount() const;
inline std::size_t GetEndOffset() const;
inline std::size_t GetStartOffset() const;
inline std::size_t GetStride() const;
inline std::size_t GetVertexCount() const;
inline const VertexDeclarationConstRef& GetVertexDeclaration() const;
inline bool IsValid() const;
void* Map(BufferAccess access, UInt32 startVertex = 0, UInt32 length = 0);
void* Map(BufferAccess access, UInt32 startVertex = 0, UInt32 length = 0) const;
void* MapRaw(BufferAccess access, UInt32 offset = 0, UInt32 size = 0);
void* MapRaw(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) const;
void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0);
void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0) const;
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0);
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0) const;
void Reset();
void Reset(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer);
void Reset(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, UInt32 offset, UInt32 size);
void Reset(VertexDeclarationConstRef vertexDeclaration, UInt32 length, DataStorage storage, BufferUsageFlags usage);
void Reset(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, std::size_t offset, std::size_t size);
void Reset(VertexDeclarationConstRef vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
void Reset(const VertexBuffer& vertexBuffer);
void SetVertexDeclaration(VertexDeclarationConstRef vertexDeclaration);
@@ -69,9 +69,9 @@ namespace Nz
private:
BufferRef m_buffer;
UInt32 m_endOffset;
UInt32 m_startOffset;
UInt32 m_vertexCount;
std::size_t m_endOffset;
std::size_t m_startOffset;
std::size_t m_vertexCount;
VertexDeclarationConstRef m_vertexDeclaration;
};
}

View File

@@ -12,22 +12,22 @@ namespace Nz
return m_buffer;
}
inline UInt32 VertexBuffer::GetEndOffset() const
inline std::size_t VertexBuffer::GetEndOffset() const
{
return m_endOffset;
}
inline UInt32 VertexBuffer::GetStride() const
inline std::size_t VertexBuffer::GetStride() const
{
return static_cast<UInt32>(m_vertexDeclaration->GetStride());
return static_cast<std::size_t>(m_vertexDeclaration->GetStride());
}
inline UInt32 VertexBuffer::GetStartOffset() const
inline std::size_t VertexBuffer::GetStartOffset() const
{
return m_startOffset;
}
inline UInt32 VertexBuffer::GetVertexCount() const
inline std::size_t VertexBuffer::GetVertexCount() const
{
return m_vertexCount;
}

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -28,7 +28,7 @@ namespace Nz
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component);
inline const VertexBuffer* GetVertexBuffer() const;
inline UInt32 GetVertexCount() const;
inline std::size_t GetVertexCount() const;
template<typename T> bool HasComponentOfType(VertexComponent component) const;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -32,7 +32,7 @@ namespace Nz
return m_mapper.GetBuffer();
}
inline UInt32 VertexMapper::GetVertexCount() const
inline std::size_t VertexMapper::GetVertexCount() const
{
return GetVertexBuffer()->GetVertexCount();
}