Core/ParameterList: Rework Parameter getter using Result
This commit is contained in:
parent
e063c7b45e
commit
6bf4ccaae1
|
|
@ -115,9 +115,7 @@ int main()
|
|||
std::vector<std::shared_ptr<Nz::Material>> materials(bobMesh->GetMaterialCount());
|
||||
for (std::size_t i = 0; i < bobMesh->GetMaterialCount(); ++i)
|
||||
{
|
||||
std::string matPath;
|
||||
bobMesh->GetMaterialData(i).GetStringParameter(Nz::MaterialData::BaseColorTexturePath, &matPath);
|
||||
|
||||
std::string matPath = bobMesh->GetMaterialData(i).GetStringParameter(Nz::MaterialData::BaseColorTexturePath).GetValueOr("");
|
||||
if (!matPath.empty())
|
||||
materials[i] = Nz::Material::LoadFromFile(matPath);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Utils/MovablePtr.hpp>
|
||||
#include <Nazara/Utils/Result.hpp>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
|
@ -20,6 +21,7 @@ namespace Nz
|
|||
{
|
||||
public:
|
||||
using Destructor = void (*)(void* value);
|
||||
enum class Error;
|
||||
|
||||
ParameterList() = default;
|
||||
ParameterList(const ParameterList& list);
|
||||
|
|
@ -31,14 +33,15 @@ namespace Nz
|
|||
inline void ForEach(const std::function<bool(const ParameterList& list, const std::string& name)>& callback);
|
||||
inline void ForEach(const std::function<void(const ParameterList& list, const std::string& name)>& callback) const;
|
||||
|
||||
bool GetBooleanParameter(const std::string& name, bool* value) const;
|
||||
bool GetColorParameter(const std::string& name, Color* value) const;
|
||||
bool GetDoubleParameter(const std::string& name, double* value) const;
|
||||
bool GetIntegerParameter(const std::string& name, long long* value) const;
|
||||
bool GetParameterType(const std::string& name, ParameterType* type) const;
|
||||
bool GetPointerParameter(const std::string& name, void** value) const;
|
||||
bool GetStringParameter(const std::string& name, std::string* value) const;
|
||||
bool GetUserdataParameter(const std::string& name, void** value) const;
|
||||
Result<bool, Error> GetBooleanParameter(const std::string& name, bool strict = true) const;
|
||||
Result<Color, Error> GetColorParameter(const std::string& name, bool strict = true) const;
|
||||
Result<double, Error> GetDoubleParameter(const std::string& name, bool strict = true) const;
|
||||
Result<long long, Error> GetIntegerParameter(const std::string& name, bool strict = true) const;
|
||||
Result<ParameterType, Error> GetParameterType(const std::string& name) const;
|
||||
Result<void*, Error> GetPointerParameter(const std::string& name, bool strict = true) const;
|
||||
Result<std::string, Error> GetStringParameter(const std::string& name, bool strict = true) const;
|
||||
Result<std::string_view, Error> GetStringViewParameter(const std::string& name, bool strict = true) const;
|
||||
Result<void*, Error> GetUserdataParameter(const std::string& name, bool strict = true) const;
|
||||
|
||||
bool HasParameter(const std::string& name) const;
|
||||
|
||||
|
|
@ -59,6 +62,14 @@ namespace Nz
|
|||
ParameterList& operator=(const ParameterList& list);
|
||||
ParameterList& operator=(ParameterList&&) = default;
|
||||
|
||||
enum class Error
|
||||
{
|
||||
ConversionFailed,
|
||||
MissingValue,
|
||||
WouldRequireConversion,
|
||||
WrongType
|
||||
};
|
||||
|
||||
private:
|
||||
struct Parameter
|
||||
{
|
||||
|
|
|
|||
|
|
@ -775,14 +775,9 @@ Nz::Result<std::shared_ptr<Nz::Mesh>, Nz::ResourceLoadingError> LoadMesh(Nz::Str
|
|||
if (parameters.optimizeIndexBuffers)
|
||||
postProcess |= aiProcess_ImproveCacheLocality;
|
||||
|
||||
double smoothingAngle = 80.f;
|
||||
parameters.custom.GetDoubleParameter("AssimpLoader_SmoothingAngle", &smoothingAngle);
|
||||
|
||||
long long triangleLimit = 1'000'000;
|
||||
parameters.custom.GetIntegerParameter("AssimpLoader_TriangleLimit", &triangleLimit);
|
||||
|
||||
long long vertexLimit = 1'000'000;
|
||||
parameters.custom.GetIntegerParameter("AssimpLoader_VertexLimit", &vertexLimit);
|
||||
double smoothingAngle = parameters.custom.GetDoubleParameter("AssimpLoader_SmoothingAngle").GetValueOr(80.0);
|
||||
long long triangleLimit = parameters.custom.GetIntegerParameter("AssimpLoader_TriangleLimit").GetValueOr(1'000'000);
|
||||
long long vertexLimit = parameters.custom.GetIntegerParameter("AssimpLoader_VertexLimit").GetValueOr(1'000'000);
|
||||
|
||||
int excludedComponents = 0;
|
||||
|
||||
|
|
@ -879,8 +874,7 @@ namespace
|
|||
animationLoaderEntry.streamLoader = LoadAnimation;
|
||||
animationLoaderEntry.parameterFilter = [](const Nz::AnimationParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipAssimpLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipAssimpLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -894,8 +888,7 @@ namespace
|
|||
meshLoaderEntry.streamLoader = LoadMesh;
|
||||
meshLoaderEntry.parameterFilter = [](const Nz::MeshParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipAssimpLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipAssimpLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -910,7 +903,7 @@ namespace
|
|||
void Deactivate() override
|
||||
{
|
||||
Nz::Utility* utility = Nz::Utility::Instance();
|
||||
NazaraAssert(utility, "utility module is not instancied");
|
||||
NazaraAssert(utility, "utility module is not instanced");
|
||||
|
||||
Nz::AnimationLoader& animationLoader = utility->GetAnimationLoader();
|
||||
animationLoader.UnregisterLoader(m_animationLoaderEntry);
|
||||
|
|
|
|||
|
|
@ -443,8 +443,7 @@ namespace
|
|||
loaderEntry.streamLoader = LoadStream;
|
||||
loaderEntry.parameterFilter = [](const Nz::ImageStreamParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipFFMpegLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipFFMpegLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -459,7 +458,7 @@ namespace
|
|||
void Deactivate() override
|
||||
{
|
||||
Nz::Utility* utility = Nz::Utility::Instance();
|
||||
NazaraAssert(utility, "utility module is not instancied");
|
||||
NazaraAssert(utility, "utility module is not instanced");
|
||||
|
||||
Nz::ImageStreamLoader& imageStreamLoader = utility->GetImageStreamLoader();
|
||||
imageStreamLoader.UnregisterLoader(m_ffmpegLoaderEntry);
|
||||
|
|
|
|||
|
|
@ -271,8 +271,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadWavSoundBuffer;
|
||||
loaderEntry.parameterFilter = [](const SoundBufferParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinWavLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinWavLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -290,8 +289,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadWavSoundStreamStream;
|
||||
loaderEntry.parameterFilter = [](const SoundStreamParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinWavLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinWavLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -520,8 +520,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadFlacSoundBuffer;
|
||||
loaderEntry.parameterFilter = [](const SoundBufferParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinFlacLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinFlacLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -539,8 +538,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadFlacSoundStreamStream;
|
||||
loaderEntry.parameterFilter = [](const SoundStreamParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinFlacLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinFlacLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -360,8 +360,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadVorbisSoundBuffer;
|
||||
loaderEntry.parameterFilter = [](const SoundBufferParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinVorbisLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinVorbisLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -379,8 +378,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadVorbisSoundStreamStream;
|
||||
loaderEntry.parameterFilter = [](const SoundStreamParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinVorbisLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinVorbisLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -316,8 +316,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadMP3SoundBuffer;
|
||||
loaderEntry.parameterFilter = [](const SoundBufferParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinMP3Loader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinMP3Loader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -335,8 +334,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadMP3SoundStreamStream;
|
||||
loaderEntry.parameterFilter = [](const SoundStreamParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinMP3Loader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinMP3Loader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <Nazara/Core/ParameterList.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
#include <Nazara/Utils/MemoryHelper.hpp>
|
||||
#include <cstring>
|
||||
|
|
@ -47,54 +46,43 @@ namespace Nz
|
|||
|
||||
/*!
|
||||
* \brief Gets a parameter as a boolean
|
||||
* \return true if the parameter could be represented as a boolean
|
||||
* \return result containing the value or an error
|
||||
*
|
||||
* \param name Name of the parameter
|
||||
* \param value Pointer to a boolean to hold the retrieved value
|
||||
* \param strict If true, prevent conversions from compatible types
|
||||
*
|
||||
* \remark value must be a valid pointer
|
||||
* \remark In case of failure, the variable pointed by value keep its value
|
||||
* \remark If the parameter is not a boolean, a conversion will be performed, compatibles types are:
|
||||
* \remark If the parameter is not a boolean, a conversion may be performed if strict parameter is set to false, compatibles types are:
|
||||
Integer: 0 is interpreted as false, any other value is interpreted as true
|
||||
std::string: Conversion obeys the rule as described by std::string::ToBool
|
||||
*/
|
||||
bool ParameterList::GetBooleanParameter(const std::string& name, bool* value) const
|
||||
auto ParameterList::GetBooleanParameter(const std::string& name, bool strict) const -> Result<bool, Error>
|
||||
{
|
||||
NazaraAssert(value, "Invalid pointer");
|
||||
|
||||
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
|
||||
|
||||
auto it = m_parameters.find(name);
|
||||
if (it == m_parameters.end())
|
||||
{
|
||||
NazaraError("Parameter \"" + name + "\" is not present");
|
||||
return false;
|
||||
}
|
||||
return Err(Error::MissingValue);
|
||||
|
||||
switch (it->second.type)
|
||||
{
|
||||
case ParameterType::Boolean:
|
||||
*value = it->second.value.boolVal;
|
||||
return true;
|
||||
return it->second.value.boolVal;
|
||||
|
||||
case ParameterType::Integer:
|
||||
*value = (it->second.value.intVal != 0);
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return (it->second.value.intVal != 0);
|
||||
|
||||
case ParameterType::String:
|
||||
{
|
||||
if (it->second.value.stringVal == "1" || it->second.value.stringVal == "yes" || it->second.value.stringVal == "true")
|
||||
{
|
||||
*value = true;
|
||||
return true;
|
||||
}
|
||||
else if (it->second.value.stringVal == "0" || it->second.value.stringVal == "no" || it->second.value.stringVal == "false")
|
||||
{
|
||||
*value = false;
|
||||
return true;
|
||||
}
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
break;
|
||||
if (it->second.value.stringVal == "1" || it->second.value.stringVal == "yes" || it->second.value.stringVal == "true")
|
||||
return true;
|
||||
else if (it->second.value.stringVal == "0" || it->second.value.stringVal == "no" || it->second.value.stringVal == "false")
|
||||
return false;
|
||||
|
||||
return Err(Error::ConversionFailed);
|
||||
}
|
||||
|
||||
case ParameterType::Color:
|
||||
|
|
@ -105,39 +93,28 @@ namespace Nz
|
|||
break;
|
||||
}
|
||||
|
||||
NazaraError("Parameter value is not representable as a boolean");
|
||||
return false;
|
||||
return Err(Error::WrongType);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a parameter as a color
|
||||
* \return true if the parameter could be represented as a color
|
||||
* \return result containing the value or an error
|
||||
*
|
||||
* \param name Name of the parameter
|
||||
* \param value Pointer to a color to hold the retrieved value
|
||||
* \param strict If true, prevent conversions from compatible types
|
||||
*
|
||||
* \remark value must be a valid pointer
|
||||
* \remark In case of failure, the variable pointed by value keep its value
|
||||
* \remark If the parameter is not a color, the function fails
|
||||
*/
|
||||
bool ParameterList::GetColorParameter(const std::string& name, Color* value) const
|
||||
auto ParameterList::GetColorParameter(const std::string& name, bool /*strict*/) const -> Result<Color, Error>
|
||||
{
|
||||
NazaraAssert(value, "Invalid pointer");
|
||||
|
||||
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
|
||||
|
||||
auto it = m_parameters.find(name);
|
||||
if (it == m_parameters.end())
|
||||
{
|
||||
NazaraError("Parameter \"" + name + "\" is not present");
|
||||
return false;
|
||||
}
|
||||
return Err(Error::MissingValue);
|
||||
|
||||
switch (it->second.type)
|
||||
{
|
||||
case ParameterType::Color:
|
||||
*value = it->second.value.colorVal;
|
||||
return true;
|
||||
return it->second.value.colorVal;
|
||||
|
||||
case ParameterType::Boolean:
|
||||
case ParameterType::Double:
|
||||
|
|
@ -149,48 +126,42 @@ namespace Nz
|
|||
break;
|
||||
}
|
||||
|
||||
NazaraError("Parameter value is not representable as a color");
|
||||
return false;
|
||||
return Err(Error::WrongType);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a parameter as a double
|
||||
* \return true if the parameter could be represented as a double
|
||||
* \return result containing the value or an error
|
||||
*
|
||||
* \param name Name of the parameter
|
||||
* \param value Pointer to a double to hold the retrieved value
|
||||
* \param strict If true, prevent conversions from compatible types
|
||||
*
|
||||
* \remark value must be a valid pointer
|
||||
* \remark In case of failure, the variable pointed by value keep its value
|
||||
* \remark If the parameter is not a double, a conversion will be performed, compatibles types are:
|
||||
* \remark If the parameter is not a double, a conversion may be performed if strict parameter is set to false, compatibles types are:
|
||||
Integer: The integer value is converted to its double representation
|
||||
std::string: Conversion obeys the rule as described by std::string::ToDouble
|
||||
*/
|
||||
bool ParameterList::GetDoubleParameter(const std::string& name, double* value) const
|
||||
auto ParameterList::GetDoubleParameter(const std::string& name, bool strict) const -> Result<double, Error>
|
||||
{
|
||||
NazaraAssert(value, "Invalid pointer");
|
||||
|
||||
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
|
||||
|
||||
auto it = m_parameters.find(name);
|
||||
if (it == m_parameters.end())
|
||||
{
|
||||
NazaraError("Parameter \"" + name + "\" is not present");
|
||||
return false;
|
||||
}
|
||||
return Err(Error::MissingValue);
|
||||
|
||||
switch (it->second.type)
|
||||
{
|
||||
case ParameterType::Double:
|
||||
*value = it->second.value.doubleVal;
|
||||
return true;
|
||||
return it->second.value.doubleVal;
|
||||
|
||||
case ParameterType::Integer:
|
||||
*value = static_cast<double>(it->second.value.intVal);
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return static_cast<double>(it->second.value.intVal);
|
||||
|
||||
case ParameterType::String:
|
||||
{
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
const std::string& str = it->second.value.stringVal;
|
||||
|
||||
int& err = errno;
|
||||
|
|
@ -202,8 +173,7 @@ namespace Nz
|
|||
if (str.data() == endStr || err == ERANGE)
|
||||
break;
|
||||
|
||||
*value = ret;
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
case ParameterType::Boolean:
|
||||
|
|
@ -214,53 +184,49 @@ namespace Nz
|
|||
break;
|
||||
}
|
||||
|
||||
NazaraError("Parameter value is not representable as a double");
|
||||
return false;
|
||||
return Err(Error::WrongType);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a parameter as an integer
|
||||
* \return true if the parameter could be represented as an integer
|
||||
* \return result containing the value or an error
|
||||
*
|
||||
* \param name Name of the parameter
|
||||
* \param value Pointer to an integer to hold the retrieved value
|
||||
* \param strict If true, prevent conversions from compatible types
|
||||
*
|
||||
* \remark value must be a valid pointer
|
||||
* \remark In case of failure, the variable pointed by value keep its value
|
||||
* \remark If the parameter is not an integer, a conversion will be performed, compatibles types are:
|
||||
* \remark If the parameter is not an integer, a conversion may be performed if strict parameter is set to false, compatibles types are:
|
||||
Boolean: The boolean is represented as 1 if true and 0 if false
|
||||
Double: The floating-point value is truncated and converted to a integer
|
||||
std::string: Conversion obeys the rule as described by std::string::ToInteger
|
||||
*/
|
||||
bool ParameterList::GetIntegerParameter(const std::string& name, long long* value) const
|
||||
auto ParameterList::GetIntegerParameter(const std::string& name, bool strict) const -> Result<long long, Error>
|
||||
{
|
||||
NazaraAssert(value, "Invalid pointer");
|
||||
|
||||
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
|
||||
|
||||
auto it = m_parameters.find(name);
|
||||
if (it == m_parameters.end())
|
||||
{
|
||||
NazaraError("Parameter \"" + name + "\" is not present");
|
||||
return false;
|
||||
}
|
||||
return Err(Error::MissingValue);
|
||||
|
||||
switch (it->second.type)
|
||||
{
|
||||
case ParameterType::Boolean:
|
||||
*value = (it->second.value.boolVal) ? 1 : 0;
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return (it->second.value.boolVal) ? 1LL : 0LL;
|
||||
|
||||
case ParameterType::Double:
|
||||
*value = static_cast<long long>(it->second.value.doubleVal);
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return static_cast<long long>(it->second.value.doubleVal);
|
||||
|
||||
case ParameterType::Integer:
|
||||
*value = it->second.value.intVal;
|
||||
return true;
|
||||
return it->second.value.intVal;
|
||||
|
||||
case ParameterType::String:
|
||||
{
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
const std::string& str = it->second.value.stringVal;
|
||||
|
||||
int& err = errno;
|
||||
|
|
@ -272,8 +238,7 @@ namespace Nz
|
|||
if (str.data() == endStr || err == ERANGE)
|
||||
break;
|
||||
|
||||
*value = ret;
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
case ParameterType::Color:
|
||||
|
|
@ -283,66 +248,52 @@ namespace Nz
|
|||
break;
|
||||
}
|
||||
|
||||
NazaraError("Parameter value is not representable as a integer");
|
||||
return false;
|
||||
return Err(Error::WrongType);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a parameter type
|
||||
* \return true if the parameter is present, its type being written to type
|
||||
* \return result containing the parameter type or an error
|
||||
*
|
||||
* \param name Name of the variable
|
||||
* \param type Pointer to a variable to hold the result
|
||||
*
|
||||
* \remark type must be a valid pointer to a ParameterType variable
|
||||
*/
|
||||
bool ParameterList::GetParameterType(const std::string& name, ParameterType* type) const
|
||||
auto ParameterList::GetParameterType(const std::string& name) const -> Result<ParameterType, Error>
|
||||
{
|
||||
NazaraAssert(type, "Invalid pointer");
|
||||
|
||||
auto it = m_parameters.find(name);
|
||||
if (it == m_parameters.end())
|
||||
return false;
|
||||
return Err(Error::MissingValue);
|
||||
|
||||
*type = it->second.type;
|
||||
|
||||
return true;
|
||||
return it->second.type;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a parameter as a pointer
|
||||
* \return true if the parameter could be represented as a pointer
|
||||
* \return result containing the value or an error
|
||||
*
|
||||
* \param name Name of the parameter
|
||||
* \param value Pointer to a pointer to hold the retrieved value
|
||||
* \param strict If true, prevent conversions from compatible types
|
||||
*
|
||||
* \remark value must be a valid pointer
|
||||
* \remark In case of failure, the variable pointed by value keep its value
|
||||
* \remark If the parameter is not a pointer, a conversion will be performed, compatibles types are:
|
||||
* \remark If the parameter is not a pointer, a conversion may be performed if strict parameter is set to false, compatibles types are:
|
||||
Userdata: The pointer part of the userdata is returned
|
||||
*/
|
||||
bool ParameterList::GetPointerParameter(const std::string& name, void** value) const
|
||||
auto ParameterList::GetPointerParameter(const std::string& name, bool strict) const -> Result<void*, Error>
|
||||
{
|
||||
NazaraAssert(value, "Invalid pointer");
|
||||
|
||||
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
|
||||
|
||||
auto it = m_parameters.find(name);
|
||||
if (it == m_parameters.end())
|
||||
{
|
||||
NazaraError("Parameter \"" + name + "\" is not present");
|
||||
return false;
|
||||
}
|
||||
return Err(Error::MissingValue);
|
||||
|
||||
switch (it->second.type)
|
||||
{
|
||||
case ParameterType::Pointer:
|
||||
*value = it->second.value.ptrVal;
|
||||
return true;
|
||||
return it->second.value.ptrVal;
|
||||
|
||||
case ParameterType::Userdata:
|
||||
*value = it->second.value.userdataVal->ptr;
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return it->second.value.userdataVal->ptr.Get();
|
||||
|
||||
case ParameterType::Boolean:
|
||||
case ParameterType::Color:
|
||||
|
|
@ -353,118 +304,150 @@ namespace Nz
|
|||
break;
|
||||
}
|
||||
|
||||
NazaraError("Parameter value is not a pointer");
|
||||
return false;
|
||||
return Err(Error::WrongType);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a parameter as a string
|
||||
* \return true if the parameter could be represented as a string
|
||||
* \return result containing the value or an error
|
||||
*
|
||||
* \param name Name of the parameter
|
||||
* \param value Pointer to a pointer to hold the retrieved value
|
||||
* \param strict If true, prevent conversions from compatible types
|
||||
*
|
||||
* \remark value must be a valid pointer
|
||||
* \remark In case of failure, the variable pointed by value keep its value
|
||||
* \remark If the parameter is not a string, a conversion will be performed, all types are compatibles:
|
||||
Boolean: Conversion obeys the rules of std::string::Boolean
|
||||
* \remark If the parameter is not a string, a conversion may be performed if strict parameter is set to false, all types are compatibles:
|
||||
Boolean: Returns "true" or "false" as a string
|
||||
Color: Conversion obeys the rules of Color::ToString
|
||||
Double: Conversion obeys the rules of std::string::Number
|
||||
Integer: Conversion obeys the rules of std::string::Number
|
||||
Double: Conversion obeys the rules of std::to_string
|
||||
Integer: Conversion obeys the rules of std::to_string
|
||||
None: An empty string is returned
|
||||
Pointer: Conversion obeys the rules of PointerToString
|
||||
Userdata: Conversion obeys the rules of PointerToString
|
||||
*/
|
||||
bool ParameterList::GetStringParameter(const std::string& name, std::string* value) const
|
||||
auto ParameterList::GetStringParameter(const std::string& name, bool strict) const -> Result<std::string, Error>
|
||||
{
|
||||
NazaraAssert(value, "Invalid pointer");
|
||||
|
||||
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
|
||||
|
||||
auto it = m_parameters.find(name);
|
||||
if (it == m_parameters.end())
|
||||
{
|
||||
NazaraError("Parameter \"" + name + "\" is not present");
|
||||
return false;
|
||||
}
|
||||
return Err(Error::MissingValue);
|
||||
|
||||
switch (it->second.type)
|
||||
{
|
||||
case ParameterType::Boolean:
|
||||
*value = (it->second.value.boolVal) ? "true" : "false";
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return std::string{ (it->second.value.boolVal) ? "true" : "false" };
|
||||
|
||||
case ParameterType::Color:
|
||||
*value = it->second.value.colorVal.ToString();
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return it->second.value.colorVal.ToString();
|
||||
|
||||
case ParameterType::Double:
|
||||
*value = std::to_string(it->second.value.doubleVal);
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return std::to_string(it->second.value.doubleVal);
|
||||
|
||||
case ParameterType::Integer:
|
||||
*value = std::to_string(it->second.value.intVal);
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return std::to_string(it->second.value.intVal);
|
||||
|
||||
case ParameterType::String:
|
||||
*value = it->second.value.stringVal;
|
||||
return true;
|
||||
return it->second.value.stringVal;
|
||||
|
||||
case ParameterType::Pointer:
|
||||
*value = PointerToString(it->second.value.ptrVal);
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return PointerToString(it->second.value.ptrVal);
|
||||
|
||||
case ParameterType::Userdata:
|
||||
*value = PointerToString(it->second.value.userdataVal->ptr);
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return PointerToString(it->second.value.userdataVal->ptr);
|
||||
|
||||
case ParameterType::None:
|
||||
*value = std::string();
|
||||
return true;
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
NazaraInternalError("Parameter value is not valid");
|
||||
return false;
|
||||
return Err(Error::WrongType);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a parameter as a string view
|
||||
* \return result containing the value or an error
|
||||
*
|
||||
* \param name Name of the parameter
|
||||
* \param strict If true, prevent conversions from compatible types
|
||||
*
|
||||
* \remark If the parameter is not a string, a conversion may be performed if strict parameter is set to false, the following types are compatibles:
|
||||
Boolean: A string view containing true or false
|
||||
None: An empty string view is returned
|
||||
*/
|
||||
auto ParameterList::GetStringViewParameter(const std::string& name, bool strict) const -> Result<std::string_view, Error>
|
||||
{
|
||||
auto it = m_parameters.find(name);
|
||||
if (it == m_parameters.end())
|
||||
return Err(Error::MissingValue);
|
||||
|
||||
switch (it->second.type)
|
||||
{
|
||||
case ParameterType::Boolean:
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return std::string_view{ (it->second.value.boolVal) ? "true" : "false" };
|
||||
|
||||
case ParameterType::String:
|
||||
return std::string_view{ it->second.value.stringVal };
|
||||
|
||||
case ParameterType::None:
|
||||
if (strict)
|
||||
return Err(Error::WouldRequireConversion);
|
||||
|
||||
return std::string_view{};
|
||||
|
||||
case ParameterType::Color:
|
||||
case ParameterType::Double:
|
||||
case ParameterType::Integer:
|
||||
case ParameterType::Pointer:
|
||||
case ParameterType::Userdata:
|
||||
break;
|
||||
}
|
||||
|
||||
return Err(Error::WrongType);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a parameter as an userdata
|
||||
* \return true if the parameter could be represented as a userdata
|
||||
* \return result containing the value or an error
|
||||
*
|
||||
* \param name Name of the parameter
|
||||
* \param value Pointer to a pointer to hold the retrieved value
|
||||
* \param strict If true, prevent conversions from compatible types
|
||||
*
|
||||
* \remark value must be a valid pointer
|
||||
* \remark In case of failure, the variable pointed by value keep its value
|
||||
* \remark If the parameter is not an userdata, the function fails
|
||||
*
|
||||
* \see GetPointerParameter
|
||||
*/
|
||||
bool ParameterList::GetUserdataParameter(const std::string& name, void** value) const
|
||||
auto ParameterList::GetUserdataParameter(const std::string& name, bool /*strict*/) const -> Result<void*, Error>
|
||||
{
|
||||
NazaraAssert(value, "Invalid pointer");
|
||||
|
||||
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
|
||||
|
||||
auto it = m_parameters.find(name);
|
||||
if (it == m_parameters.end())
|
||||
{
|
||||
NazaraError("Parameter \"" + name + "\" is not present");
|
||||
return false;
|
||||
}
|
||||
return Err(Error::MissingValue);
|
||||
|
||||
const auto& parameter = it->second;
|
||||
|
||||
if (parameter.type == ParameterType::Userdata)
|
||||
{
|
||||
*value = parameter.value.userdataVal->ptr;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraError("Parameter value is not a userdata");
|
||||
return false;
|
||||
}
|
||||
if (parameter.type != ParameterType::Userdata)
|
||||
return Err(Error::WrongType);
|
||||
|
||||
return parameter.value.userdataVal->ptr.Get();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -35,8 +35,7 @@ namespace Nz
|
|||
|
||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
|
||||
bool hasAlphaTest = false;
|
||||
parameters.custom.GetBooleanParameter("EnableAlphaTest", &hasAlphaTest);
|
||||
bool hasAlphaTest = parameters.custom.GetBooleanParameter("EnableAlphaTest").GetValueOr(false);
|
||||
|
||||
// ForwardPass
|
||||
{
|
||||
|
|
@ -79,8 +78,7 @@ namespace Nz
|
|||
|
||||
loaderEntry.parameterFilter = [](const MaterialParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipNativeTextureLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipNativeTextureLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace Nz
|
|||
if (header.flags & DDSD_DEPTH)
|
||||
depth = std::max(header.depth, 1U);
|
||||
|
||||
unsigned int levelCount = (parameters.levelCount > 0) ? std::min(parameters.levelCount, static_cast<UInt8>(header.levelCount)) : header.levelCount;
|
||||
unsigned int levelCount = (parameters.levelCount > 0) ? std::min(parameters.levelCount, SafeCast<UInt8>(header.levelCount)) : header.levelCount;
|
||||
|
||||
// First, identify the type
|
||||
ImageType type;
|
||||
|
|
@ -258,8 +258,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = DDSLoader::Load;
|
||||
loaderEntry.parameterFilter = [](const ImageParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinDDSLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinDDSLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -467,8 +467,7 @@ namespace Nz
|
|||
loader.streamLoader = LoadFreetypeStream;
|
||||
loader.parameterFilter = [](const FontParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinFreeTypeLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinFreeTypeLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -749,8 +749,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadGIFStream;
|
||||
loaderEntry.parameterFilter = [](const ImageStreamParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinGIFLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinGIFLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -259,8 +259,7 @@ namespace Nz
|
|||
loader.streamLoader = LoadMD2;
|
||||
loader.parameterFilter = [](const MeshParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinMD2Loader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinMD2Loader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -100,8 +100,7 @@ namespace Nz
|
|||
loader.streamLoader = LoadMD5Anim;
|
||||
loader.parameterFilter = [](const AnimationParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinMD5AnimLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinMD5AnimLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -43,10 +43,9 @@ namespace Nz
|
|||
}
|
||||
|
||||
UInt32 maxWeightCount = 4;
|
||||
long long customMaxWeightCount;
|
||||
if (parameters.custom.GetIntegerParameter("MaxWeightCount", &customMaxWeightCount))
|
||||
if (auto result = parameters.custom.GetIntegerParameter("MaxWeightCount"))
|
||||
{
|
||||
maxWeightCount = SafeCast<UInt32>(customMaxWeightCount);
|
||||
maxWeightCount = SafeCast<UInt32>(result.GetValue());
|
||||
if (maxWeightCount > 4)
|
||||
{
|
||||
NazaraWarning("MaxWeightCount cannot be over 4");
|
||||
|
|
@ -361,8 +360,7 @@ namespace Nz
|
|||
loader.streamLoader = LoadMD5Mesh;
|
||||
loader.parameterFilter = [](const MeshParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinMD5MeshLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinMD5MeshLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -144,9 +144,7 @@ namespace Nz
|
|||
|
||||
Result<std::shared_ptr<Mesh>, ResourceLoadingError> LoadOBJ(Stream& stream, const MeshParams& parameters)
|
||||
{
|
||||
long long reservedVertexCount;
|
||||
if (!parameters.custom.GetIntegerParameter("NativeOBJLoader_VertexCount", &reservedVertexCount))
|
||||
reservedVertexCount = 100;
|
||||
long long reservedVertexCount = parameters.custom.GetIntegerParameter("ReserveVertexCount").GetValueOr(1'000);
|
||||
|
||||
OBJParser parser;
|
||||
|
||||
|
|
@ -360,8 +358,7 @@ namespace Nz
|
|||
loader.streamLoader = LoadOBJ;
|
||||
loader.parameterFilter = [](const MeshParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinOBJLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinOBJLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -103,7 +103,9 @@ namespace Nz
|
|||
const ParameterList& matData = mesh.GetMaterialData(i);
|
||||
|
||||
std::string name;
|
||||
if (!matData.GetStringParameter(MaterialData::Name, &name))
|
||||
if (auto result = matData.GetStringParameter(MaterialData::Name))
|
||||
name = std::move(result).GetValue();
|
||||
else
|
||||
name = "material_" + std::to_string(i);
|
||||
|
||||
// Makes sure we only have one material of that name
|
||||
|
|
@ -115,27 +117,32 @@ namespace Nz
|
|||
|
||||
MTLParser::Material* material = mtlFormat.AddMaterial(name);
|
||||
|
||||
if (!matData.GetStringParameter(MaterialData::FilePath, &material->diffuseMap))
|
||||
auto pathResult = matData.GetStringParameter(MaterialData::FilePath);
|
||||
if (!pathResult)
|
||||
{
|
||||
Color colorVal;
|
||||
double dValue;
|
||||
if (auto result = matData.GetColorParameter(MaterialData::AmbientColor))
|
||||
material->ambient = result.GetValue();
|
||||
|
||||
if (matData.GetColorParameter(MaterialData::AmbientColor, &colorVal))
|
||||
material->ambient = colorVal;
|
||||
if (auto result = matData.GetColorParameter(MaterialData::BaseColor))
|
||||
material->diffuse = result.GetValue();
|
||||
|
||||
if (matData.GetColorParameter(MaterialData::BaseColor, &colorVal))
|
||||
material->diffuse = colorVal;
|
||||
if (auto result = matData.GetColorParameter(MaterialData::SpecularColor))
|
||||
material->specular = result.GetValue();
|
||||
|
||||
if (matData.GetColorParameter(MaterialData::SpecularColor, &colorVal))
|
||||
material->specular = colorVal;
|
||||
if (auto result = matData.GetDoubleParameter(MaterialData::Shininess))
|
||||
material->shininess = SafeCast<float>(result.GetValue());
|
||||
|
||||
if (matData.GetDoubleParameter(MaterialData::Shininess, &dValue))
|
||||
material->shininess = float(dValue);
|
||||
if (auto result = matData.GetStringParameter(MaterialData::AlphaTexturePath))
|
||||
material->alphaMap = std::move(result).GetValue();
|
||||
|
||||
matData.GetStringParameter(MaterialData::AlphaTexturePath, &material->alphaMap);
|
||||
matData.GetStringParameter(MaterialData::BaseColorTexturePath, &material->diffuseMap);
|
||||
matData.GetStringParameter(MaterialData::SpecularTexturePath, &material->specularMap);
|
||||
if (auto result = matData.GetStringParameter(MaterialData::BaseColorTexturePath))
|
||||
material->diffuseMap = std::move(result).GetValue();
|
||||
|
||||
if (auto result = matData.GetStringParameter(MaterialData::SpecularTexturePath))
|
||||
material->specularMap = std::move(result).GetValue();
|
||||
}
|
||||
else
|
||||
material->diffuseMap = std::move(pathResult).GetValue();
|
||||
}
|
||||
|
||||
// Meshes
|
||||
|
|
|
|||
|
|
@ -331,8 +331,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadPCX;
|
||||
loaderEntry.parameterFilter = [](const ImageParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinPCXLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinPCXLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ namespace Nz
|
|||
if (!ptr)
|
||||
{
|
||||
NazaraError("Failed to load image: " + std::string(stbi_failure_reason()));
|
||||
return Err(ResourceLoadingError::Unrecognized);
|
||||
return Err(ResourceLoadingError::DecodingError);
|
||||
}
|
||||
|
||||
CallOnExit freeStbiImage([ptr]()
|
||||
|
|
@ -103,8 +103,7 @@ namespace Nz
|
|||
loaderEntry.streamLoader = LoadSTB;
|
||||
loaderEntry.parameterFilter = [](const ImageParams& parameters)
|
||||
{
|
||||
bool skip;
|
||||
if (parameters.custom.GetBooleanParameter("SkipBuiltinSTBLoader", &skip) && skip)
|
||||
if (auto result = parameters.custom.GetBooleanParameter("SkipBuiltinSTBLoader"); result.GetValueOr(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -175,17 +175,12 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
long long imageQuality;
|
||||
if (parameters.custom.GetIntegerParameter("NativeJPEGSaver_Quality", &imageQuality))
|
||||
long long imageQuality = parameters.custom.GetIntegerParameter("JPEGQuality").GetValueOr(100);
|
||||
if (imageQuality <= 0 || imageQuality > 100)
|
||||
{
|
||||
if (imageQuality <= 0 || imageQuality > 100)
|
||||
{
|
||||
NazaraError("NativeJPEGSaver_Quality value (" + Nz::NumberToString(imageQuality) + ") does not fit in bounds ]0, 100], clamping...");
|
||||
imageQuality = Nz::Clamp(imageQuality, 1LL, 100LL);
|
||||
}
|
||||
NazaraError("NativeJPEGSaver_Quality value (" + Nz::NumberToString(imageQuality) + ") does not fit in bounds ]0, 100], clamping...");
|
||||
imageQuality = Nz::Clamp(imageQuality, 1LL, 100LL);
|
||||
}
|
||||
else
|
||||
imageQuality = 100;
|
||||
|
||||
if (!stbi_write_jpg_to_func(&WriteToStream, &stream, tempImage.GetWidth(), tempImage.GetHeight(), componentCount, tempImage.GetConstPixels(), int(imageQuality)))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -129,26 +129,14 @@ namespace Nz
|
|||
|
||||
CallOnExit onExit(Vulkan::Uninitialize);
|
||||
|
||||
std::string appName = "Another application made with Nazara Engine";
|
||||
std::string engineName = "Nazara Engine - Vulkan Renderer";
|
||||
std::string appName = parameters.GetStringParameter("VkAppInfo_OverrideApplicationName").GetValueOr("Another application made with Nazara Engine");
|
||||
std::string engineName = parameters.GetStringParameter("VkAppInfo_OverrideEngineName").GetValueOr("Nazara Engine - Vulkan Renderer");
|
||||
|
||||
UInt32 appVersion = VK_MAKE_API_VERSION(0, 1, 0, 0);
|
||||
UInt32 engineVersion = VK_MAKE_API_VERSION(0, 1, 0, 0);
|
||||
UInt32 appVersion = parameters.GetIntegerParameter("VkAppInfo_OverrideApplicationVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0));
|
||||
UInt32 engineVersion = parameters.GetIntegerParameter("VkAppInfo_OverrideEngineVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0));
|
||||
|
||||
parameters.GetStringParameter("VkAppInfo_OverrideApplicationName", &appName);
|
||||
parameters.GetStringParameter("VkAppInfo_OverrideEngineName", &engineName);
|
||||
|
||||
bool bParam;
|
||||
long long iParam;
|
||||
|
||||
if (parameters.GetIntegerParameter("VkAppInfo_OverrideAPIVersion", &iParam))
|
||||
targetApiVersion = static_cast<UInt32>(iParam);
|
||||
|
||||
if (parameters.GetIntegerParameter("VkAppInfo_OverrideApplicationVersion", &iParam))
|
||||
appVersion = static_cast<UInt32>(iParam);
|
||||
|
||||
if (parameters.GetIntegerParameter("VkAppInfo_OverrideEngineVersion", &iParam))
|
||||
engineVersion = static_cast<UInt32>(iParam);
|
||||
if (auto result = parameters.GetIntegerParameter("VkAppInfo_OverrideAPIVersion"))
|
||||
targetApiVersion = SafeCast<UInt32>(result.GetValue());
|
||||
|
||||
if (Vk::Loader::vkEnumerateInstanceVersion)
|
||||
{
|
||||
|
|
@ -171,10 +159,7 @@ namespace Nz
|
|||
targetApiVersion
|
||||
};
|
||||
|
||||
VkInstanceCreateFlags createFlags = 0;
|
||||
|
||||
if (parameters.GetIntegerParameter("VkInstanceInfo_OverrideCreateFlags", &iParam))
|
||||
createFlags = static_cast<VkInstanceCreateFlags>(iParam);
|
||||
VkInstanceCreateFlags createFlags = parameters.GetIntegerParameter("VkInstanceInfo_OverrideCreateFlags").GetValueOr(0);
|
||||
|
||||
std::vector<const char*> enabledLayers;
|
||||
|
||||
|
|
@ -182,7 +167,7 @@ namespace Nz
|
|||
std::unordered_map<std::string, std::size_t> availableLayerByName;
|
||||
EnumerateVulkanLayers(availableLayers, availableLayerByName);
|
||||
|
||||
if (!parameters.GetBooleanParameter("VkInstanceInfo_OverrideEnabledLayers", &bParam) || !bParam)
|
||||
if (auto result = parameters.GetBooleanParameter("VkInstanceInfo_OverrideEnabledLayers"); !result.GetValueOr(false))
|
||||
{
|
||||
//< Nazara default layers goes here
|
||||
|
||||
|
|
@ -198,16 +183,15 @@ namespace Nz
|
|||
|
||||
std::vector<const char*> enabledExtensions;
|
||||
std::vector<std::string> additionalLayers; // Just to keep the String alive
|
||||
if (parameters.GetIntegerParameter("VkInstanceInfo_EnabledLayerCount", &iParam))
|
||||
if (long long customLayerCount = parameters.GetIntegerParameter("VkInstanceInfo_EnabledLayerCount").GetValueOr(0) > 0)
|
||||
{
|
||||
additionalLayers.reserve(iParam);
|
||||
for (long long i = 0; i < iParam; ++i)
|
||||
additionalLayers.reserve(customLayerCount);
|
||||
for (long long i = 0; i < customLayerCount; ++i)
|
||||
{
|
||||
std::string parameterName = "VkInstanceInfo_EnabledLayer" + NumberToString(i);
|
||||
std::string layer;
|
||||
if (parameters.GetStringParameter(parameterName, &layer))
|
||||
if (auto result = parameters.GetStringParameter(parameterName))
|
||||
{
|
||||
additionalLayers.emplace_back(std::move(layer));
|
||||
additionalLayers.emplace_back(std::move(result).GetValue());
|
||||
enabledLayers.push_back(additionalLayers.back().c_str());
|
||||
}
|
||||
else
|
||||
|
|
@ -224,7 +208,7 @@ namespace Nz
|
|||
availableExtensions.insert(extProperty.extensionName);
|
||||
}
|
||||
|
||||
if (!parameters.GetBooleanParameter("VkInstanceInfo_OverrideEnabledExtensions", &bParam) || !bParam)
|
||||
if (auto result = parameters.GetBooleanParameter("VkInstanceInfo_OverrideEnabledExtensions"); !result.GetValueOr(false))
|
||||
{
|
||||
enabledExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
|
||||
|
|
@ -260,16 +244,15 @@ namespace Nz
|
|||
}
|
||||
|
||||
std::vector<std::string> additionalExtensions; // Just to keep the String alive
|
||||
if (parameters.GetIntegerParameter("VkInstanceInfo_EnabledExtensionCount", &iParam))
|
||||
if (long long customLayerCount = parameters.GetIntegerParameter("VkInstanceInfo_EnabledExtensionCount").GetValueOr(0) > 0)
|
||||
{
|
||||
additionalExtensions.reserve(iParam);
|
||||
for (int i = 0; i < iParam; ++i)
|
||||
additionalExtensions.reserve(customLayerCount);
|
||||
for (int i = 0; i < customLayerCount; ++i)
|
||||
{
|
||||
std::string parameterName = "VkInstanceInfo_EnabledExtension" + NumberToString(i);
|
||||
std::string extension;
|
||||
if (parameters.GetStringParameter(parameterName, &extension))
|
||||
if (auto result = parameters.GetStringParameter(parameterName))
|
||||
{
|
||||
additionalExtensions.emplace_back(std::move(extension));
|
||||
additionalLayers.emplace_back(std::move(result).GetValue());
|
||||
enabledExtensions.push_back(additionalExtensions.back().c_str());
|
||||
}
|
||||
else
|
||||
|
|
@ -526,25 +509,21 @@ namespace Nz
|
|||
std::vector<const char*> enabledLayers;
|
||||
std::vector<const char*> enabledExtensions;
|
||||
|
||||
bool bParam;
|
||||
long long iParam;
|
||||
|
||||
if (!s_initializationParameters.GetBooleanParameter("VkDeviceInfo_OverrideEnabledLayers", &bParam) || !bParam)
|
||||
if (auto result = s_initializationParameters.GetBooleanParameter("VkDeviceInfo_OverrideEnabledLayers"); !result.GetValueOr(false))
|
||||
{
|
||||
//< Nazara default layers goes here
|
||||
}
|
||||
|
||||
std::vector<std::string> additionalLayers; // Just to keep the string alive
|
||||
if (s_initializationParameters.GetIntegerParameter("VkDeviceInfo_EnabledLayerCount", &iParam))
|
||||
if (long long customLayerCount = s_initializationParameters.GetIntegerParameter("VkDeviceInfo_EnabledLayerCount").GetValueOr(0))
|
||||
{
|
||||
additionalLayers.reserve(iParam);
|
||||
for (long long i = 0; i < iParam; ++i)
|
||||
additionalLayers.reserve(customLayerCount);
|
||||
for (long long i = 0; i < customLayerCount; ++i)
|
||||
{
|
||||
std::string parameterName = "VkDeviceInfo_EnabledLayer" + NumberToString(i);
|
||||
std::string layer;
|
||||
if (s_initializationParameters.GetStringParameter(parameterName, &layer))
|
||||
if (auto value = s_initializationParameters.GetStringViewParameter(parameterName))
|
||||
{
|
||||
additionalLayers.emplace_back(std::move(layer));
|
||||
additionalLayers.emplace_back(std::move(value).GetValue());
|
||||
enabledLayers.push_back(additionalLayers.back().c_str());
|
||||
}
|
||||
else
|
||||
|
|
@ -552,7 +531,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
if (!s_initializationParameters.GetBooleanParameter("VkDeviceInfo_OverrideEnabledExtensions", &bParam) || !bParam)
|
||||
if (auto result = s_initializationParameters.GetBooleanParameter("VkDeviceInfo_OverrideEnabledExtensions"); !result.GetValueOr(false))
|
||||
{
|
||||
// Swapchain extension is required for rendering
|
||||
enabledExtensions.emplace_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
||||
|
|
@ -574,15 +553,14 @@ namespace Nz
|
|||
}
|
||||
|
||||
std::vector<std::string> additionalExtensions; // Just to keep the String alive
|
||||
if (s_initializationParameters.GetIntegerParameter("VkDeviceInfo_EnabledExtensionCount", &iParam))
|
||||
if (long long customExtCount = s_initializationParameters.GetIntegerParameter("VkDeviceInfo_EnabledExtensionCount").GetValueOr(0))
|
||||
{
|
||||
for (long long i = 0; i < iParam; ++i)
|
||||
for (long long i = 0; i < customExtCount; ++i)
|
||||
{
|
||||
std::string parameterName = "VkDeviceInfo_EnabledExtension" + NumberToString(i);
|
||||
std::string extension;
|
||||
if (s_initializationParameters.GetStringParameter(parameterName, &extension))
|
||||
if (auto value = s_initializationParameters.GetStringViewParameter(parameterName))
|
||||
{
|
||||
additionalExtensions.emplace_back(std::move(extension));
|
||||
additionalExtensions.emplace_back(std::move(value).GetValue());
|
||||
enabledExtensions.push_back(additionalExtensions.back().c_str());
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -29,27 +29,19 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
|||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
bool retrievedValue = false;
|
||||
CHECK(parameterList.GetBooleanParameter("bool", &retrievedValue));
|
||||
CHECK(retrievedValue == boolean);
|
||||
CHECK(parameterList.GetBooleanParameter("bool").GetValue() == true);
|
||||
}
|
||||
|
||||
THEN("Conversion from int to bool should also work")
|
||||
THEN("Conversion from int to bool should also work if strict mode is disabled")
|
||||
{
|
||||
bool retrievedValue = false;
|
||||
CHECK(parameterList.GetBooleanParameter("intTrue", &retrievedValue));
|
||||
CHECK(retrievedValue);
|
||||
CHECK(parameterList.GetBooleanParameter("intFalse", &retrievedValue));
|
||||
CHECK(!retrievedValue);
|
||||
CHECK(parameterList.GetBooleanParameter("intTrue", false).GetValue() == true);
|
||||
CHECK(parameterList.GetBooleanParameter("intFalse", false).GetValue() == false);
|
||||
}
|
||||
|
||||
THEN("Conversion from str to bool should also work")
|
||||
THEN("Conversion from str to bool should also work if strict mode is disabled")
|
||||
{
|
||||
bool retrievedValue = false;
|
||||
CHECK(parameterList.GetBooleanParameter("strTrue", &retrievedValue));
|
||||
CHECK(retrievedValue);
|
||||
CHECK(parameterList.GetBooleanParameter("strFalse", &retrievedValue));
|
||||
CHECK(!retrievedValue);
|
||||
CHECK(parameterList.GetBooleanParameter("strTrue", false).GetValue() == true);
|
||||
CHECK(parameterList.GetBooleanParameter("strFalse", false).GetValue() == false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -60,9 +52,7 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
|||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
Nz::Color retrievedColor;
|
||||
CHECK(parameterList.GetColorParameter("color", &retrievedColor));
|
||||
CHECK(retrievedColor == rgb);
|
||||
CHECK(parameterList.GetColorParameter("color").GetValue() == rgb);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -79,23 +69,17 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
|||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
double retrievedValue;
|
||||
CHECK(parameterList.GetDoubleParameter("double", &retrievedValue));
|
||||
CHECK(retrievedValue == fl);
|
||||
CHECK(parameterList.GetDoubleParameter("double").GetValue() == fl);
|
||||
}
|
||||
|
||||
THEN("Conversion from int to double should also work")
|
||||
THEN("Conversion from int to double should also work if strict mode is disabled")
|
||||
{
|
||||
double retrievedValue;
|
||||
CHECK(parameterList.GetDoubleParameter("intDouble", &retrievedValue));
|
||||
CHECK(retrievedValue == fl);
|
||||
CHECK(parameterList.GetDoubleParameter("intDouble", false).GetValue() == fl);
|
||||
}
|
||||
|
||||
THEN("Conversion from string to double should also work")
|
||||
THEN("Conversion from string to double should also work if strict mode is disabled")
|
||||
{
|
||||
double retrievedValue;
|
||||
CHECK(parameterList.GetDoubleParameter("strDouble", &retrievedValue));
|
||||
CHECK(retrievedValue == fl);
|
||||
CHECK(parameterList.GetDoubleParameter("strDouble", false).GetValue() == fl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,32 +101,23 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
|||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
long long retrievedValue;
|
||||
CHECK(parameterList.GetIntegerParameter("int", &retrievedValue));
|
||||
CHECK(retrievedValue == i);
|
||||
CHECK(parameterList.GetIntegerParameter("int").GetValue() == i);
|
||||
}
|
||||
|
||||
THEN("Conversion from bool to int should also work")
|
||||
THEN("Conversion from bool to int should also work if strict mode is disabled")
|
||||
{
|
||||
long long retrievedValue;
|
||||
CHECK(parameterList.GetIntegerParameter("trueInt", &retrievedValue));
|
||||
CHECK(retrievedValue == trueInt);
|
||||
CHECK(parameterList.GetIntegerParameter("falseInt", &retrievedValue));
|
||||
CHECK(retrievedValue == falseInt);
|
||||
CHECK(parameterList.GetIntegerParameter("trueInt", false).GetValue() == trueInt);
|
||||
CHECK(parameterList.GetIntegerParameter("falseInt", false).GetValue() == falseInt);
|
||||
}
|
||||
|
||||
THEN("Conversion from double to int should also work")
|
||||
THEN("Conversion from double to int should also work if strict mode is disabled")
|
||||
{
|
||||
long long retrievedValue;
|
||||
CHECK(parameterList.GetIntegerParameter("doubleInt", &retrievedValue));
|
||||
CHECK(retrievedValue == i);
|
||||
CHECK(parameterList.GetIntegerParameter("doubleInt", false).GetValue() == i);
|
||||
}
|
||||
|
||||
THEN("Conversion from string to int should also work")
|
||||
THEN("Conversion from string to int should also work if strict mode is disabled")
|
||||
{
|
||||
long long retrievedValue;
|
||||
CHECK(parameterList.GetIntegerParameter("strInt", &retrievedValue));
|
||||
CHECK(retrievedValue == i);
|
||||
CHECK(parameterList.GetIntegerParameter("strInt", false).GetValue() == i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,39 +142,31 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
|||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
std::string newString;
|
||||
CHECK(parameterList.GetStringParameter("string", &newString));
|
||||
CHECK(newString == string);
|
||||
CHECK(parameterList.GetStringParameter("string").GetValue() == string);
|
||||
CHECK(parameterList.GetStringViewParameter("string").GetValue() == string);
|
||||
}
|
||||
|
||||
THEN("Conversion from bool to str should also work")
|
||||
THEN("Conversion from bool to str should also work if strict mode is disabled")
|
||||
{
|
||||
std::string retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("trueString", &retrievedValue));
|
||||
CHECK(retrievedValue == "true");
|
||||
CHECK(parameterList.GetStringParameter("falseString", &retrievedValue));
|
||||
CHECK(retrievedValue == "false");
|
||||
CHECK(parameterList.GetStringParameter("trueString", false).GetValue() == "true");
|
||||
CHECK(parameterList.GetStringParameter("falseString", false).GetValue() == "false");
|
||||
CHECK(parameterList.GetStringViewParameter("trueString", false).GetValue() == "true");
|
||||
CHECK(parameterList.GetStringViewParameter("falseString", false).GetValue() == "false");
|
||||
}
|
||||
|
||||
THEN("Conversion from color to string should also work")
|
||||
THEN("Conversion from color to string should also work if strict mode is disabled")
|
||||
{
|
||||
std::string retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("colorString", &retrievedValue));
|
||||
CHECK(retrievedValue == colorString.ToString());
|
||||
CHECK(parameterList.GetStringParameter("colorString", false).GetValue() == colorString.ToString());
|
||||
}
|
||||
|
||||
THEN("Conversion from string to double should also work")
|
||||
THEN("Conversion from string to double should also work if strict mode is disabled")
|
||||
{
|
||||
std::string retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("doubleString", &retrievedValue));
|
||||
CHECK(retrievedValue == "3.000000");
|
||||
CHECK(parameterList.GetStringParameter("doubleString", false).GetValue() == "3.000000");
|
||||
}
|
||||
|
||||
THEN("Conversion from string to int should also work")
|
||||
THEN("Conversion from string to int should also work if strict mode is disabled")
|
||||
{
|
||||
std::string retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("intString", &retrievedValue));
|
||||
CHECK(retrievedValue == "3");
|
||||
CHECK(parameterList.GetStringParameter("intString", false).GetValue() == "3");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,9 +178,7 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
|||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
void* newPtrToStackValue = nullptr;
|
||||
CHECK(parameterList.GetPointerParameter("ptr", &newPtrToStackValue));
|
||||
CHECK(newPtrToStackValue == ptrToStackValue);
|
||||
CHECK(parameterList.GetPointerParameter("ptr").GetValue() == ptrToStackValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -229,11 +194,10 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
|||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
Data retrievedValue;
|
||||
void* ptrToData = &retrievedValue;
|
||||
void* ptrToData;
|
||||
|
||||
CHECK(parameterList.GetUserdataParameter("userData", &ptrToData));
|
||||
Data* dataPtr = reinterpret_cast<Data*>(ptrToData);
|
||||
CHECK_NOTHROW(ptrToData = parameterList.GetUserdataParameter("userData").GetValue());
|
||||
Data* dataPtr = static_cast<Data*>(ptrToData);
|
||||
CHECK(dataPtr->i == data.i);
|
||||
CHECK(dataPtr->f == data.f);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue