Add unity build support

This commit is contained in:
Jérôme Leclercq
2022-03-15 08:26:57 +01:00
parent 0a4fd8f56d
commit 6bd9f1a9e4
109 changed files with 964 additions and 680 deletions

View File

@@ -9,10 +9,12 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <optional>
namespace Nz
{
inline UInt32 GetChannelCount(AudioFormat format);
inline std::optional<AudioFormat> GuessAudioFormat(UInt32 channelCount);
template<typename T> void MixToMono(T* input, T* output, UInt32 channelCount, UInt64 frameCount);
}

View File

@@ -11,11 +11,13 @@ namespace Nz
/*!
* \ingroup audio
* \brief Get the number of channels occupied by an audio format
* \returns The number of channels occupied by an audio format (mono returns 1, stero returns 2, etc.)
* \returns The number of channels occupied by an audio format (mono returns 1, stereo returns 2, etc.)
*
* \param format A valid audio format
*
* \remark The format must be valid (using AudioFormat::Unknown will trigger an error)
* \remark format cannot be AudioFormat::Unknown
*
* \see GuessAudioFormat
*/
UInt32 GetChannelCount(AudioFormat format)
{
@@ -48,6 +50,42 @@ namespace Nz
return 0;
}
/*!
* \ingroup audio
* \brief Gets the common audio format associated with a specific channel count
* \returns AudioFormat associated with channel count or empty optional if none match
*
* \param channelCount Channel count
*
* \see GetChannelCount
*/
inline std::optional<AudioFormat> GuessAudioFormat(UInt32 channelCount)
{
switch (channelCount)
{
case 1:
return AudioFormat::I16_Mono;
case 2:
return AudioFormat::I16_Stereo;
case 4:
return AudioFormat::I16_Quad;
case 6:
return AudioFormat::I16_5_1;
case 7:
return AudioFormat::I16_6_1;
case 8:
return AudioFormat::I16_7_1;
default:
return std::nullopt;
}
}
/*!
* \ingroup audio
* \brief Mixes channels in mono

View File

@@ -39,13 +39,24 @@ namespace Nz
inline bool HashAppend(AbstractHash* hash, const std::string_view& v);
template<typename T> void HashCombine(std::size_t& seed, const T& v);
template<typename T> bool IsPowerOfTwo(T value);
template<typename K, typename V> V& Retrieve(std::unordered_map<K, V>& map, const K& key);
template<typename K, typename V> const V& Retrieve(const std::unordered_map<K, V>& map, const K& key);
template<typename T> T ReverseBits(T integer);
template<typename To, typename From> To SafeCast(From&& value);
template<typename T, typename U>std::unique_ptr<T> StaticUniquePointerCast(std::unique_ptr<U>&& ptr);
template<typename T> constexpr auto UnderlyingCast(T value) -> std::underlying_type_t<T>;
template<typename T>
struct AlwaysFalse : std::false_type {};
// Helper for std::visit
template<typename... Ts> struct Overloaded : Ts...
{
using Ts::operator()...;
};
template<typename... Ts> Overloaded(Ts...) -> Overloaded<Ts...>;
template<typename... Args>
struct OverloadResolver
{

View File

@@ -363,6 +363,38 @@ namespace Nz
return (value & (value - 1)) == 0;
}
/*!
* \ingroup core
* \brief Helper function to retrieve a key in a map which has to exist
* \return Value associated with key
*
* \param map Map
* \param key Key, has to exist in map
*/
template<typename K, typename V>
V& Retrieve(std::unordered_map<K, V>& map, const K& key)
{
auto it = map.find(key);
assert(it != map.end());
return it->second;
}
/*!
* \ingroup core
* \brief Helper function to retrieve a key in a map which has to exist
* \return Value associated with key
*
* \param map Map
* \param key Key, has to exist in map
*/
template<typename K, typename V>
const V& Retrieve(const std::unordered_map<K, V>& map, const K& key)
{
auto it = map.find(key);
assert(it != map.end());
return it->second;
}
/*!
* \ingroup core
* \brief Reverse the bit order of the integer
@@ -472,6 +504,12 @@ namespace Nz
#endif
}
template<typename T, typename U>
std::unique_ptr<T> StaticUniquePointerCast(std::unique_ptr<U>&& ptr)
{
return std::unique_ptr<T>(SafeCast<T*>(ptr.release()));
}
template<typename T>
constexpr auto UnderlyingCast(T value) -> std::underlying_type_t<T>
{

View File

@@ -149,6 +149,16 @@
#define NAZARA_PLATFORM_x64
#endif
#ifdef NAZARA_UNITY_BUILD
#define NAZARA_ANONYMOUS_NAMESPACE NAZARA_UNITY_ID
#define NAZARA_USE_ANONYMOUS_NAMESPACE using namespace NAZARA_UNITY_ID;
#define NAZARA_ANONYMOUS_NAMESPACE_PREFIX(a) NAZARA_UNITY_ID::a
#else
#define NAZARA_ANONYMOUS_NAMESPACE
#define NAZARA_USE_ANONYMOUS_NAMESPACE
#define NAZARA_ANONYMOUS_NAMESPACE_PREFIX(a) a
#endif
// A bunch of useful macros
#define NazaraPrefix(a, prefix) prefix ## a
#define NazaraPrefixMacro(a, prefix) NazaraPrefix(a, prefix)

View File

@@ -60,6 +60,7 @@ namespace Nz::ShaderAst
private:
enum class IdentifierCategory;
struct AstError;
struct CurrentFunctionData;
struct Environment;
struct FunctionData;