Core/ParameterList: Use double and long long instead of float and int

This commit is contained in:
Jérôme Leclercq 2017-05-29 19:55:02 +02:00
parent 30a4e20ee5
commit bc4a533b96
6 changed files with 53 additions and 56 deletions

View File

@ -105,7 +105,7 @@ namespace Nz
{ {
ParameterType_Boolean, ParameterType_Boolean,
ParameterType_Color, ParameterType_Color,
ParameterType_Float, ParameterType_Double,
ParameterType_Integer, ParameterType_Integer,
ParameterType_None, ParameterType_None,
ParameterType_Pointer, ParameterType_Pointer,

View File

@ -32,8 +32,8 @@ namespace Nz
bool GetBooleanParameter(const String& name, bool* value) const; bool GetBooleanParameter(const String& name, bool* value) const;
bool GetColorParameter(const String& name, Color* value) const; bool GetColorParameter(const String& name, Color* value) const;
bool GetFloatParameter(const String& name, float* value) const; bool GetDoubleParameter(const String& name, double* value) const;
bool GetIntegerParameter(const String& name, int* value) const; bool GetIntegerParameter(const String& name, long long* value) const;
bool GetParameterType(const String& name, ParameterType* type) const; bool GetParameterType(const String& name, ParameterType* type) const;
bool GetPointerParameter(const String& name, void** value) const; bool GetPointerParameter(const String& name, void** value) const;
bool GetStringParameter(const String& name, String* value) const; bool GetStringParameter(const String& name, String* value) const;
@ -48,8 +48,8 @@ namespace Nz
void SetParameter(const String& name, const String& value); void SetParameter(const String& name, const String& value);
void SetParameter(const String& name, const char* value); void SetParameter(const String& name, const char* value);
void SetParameter(const String& name, bool value); void SetParameter(const String& name, bool value);
void SetParameter(const String& name, float value); void SetParameter(const String& name, double value);
void SetParameter(const String& name, int value); void SetParameter(const String& name, long long value);
void SetParameter(const String& name, void* value); void SetParameter(const String& name, void* value);
void SetParameter(const String& name, void* value, Destructor destructor); void SetParameter(const String& name, void* value, Destructor destructor);
@ -84,8 +84,8 @@ namespace Nz
~Value() {} ~Value() {}
bool boolVal; bool boolVal;
float floatVal; double doubleVal;
int intVal; long long intVal;
void* ptrVal; void* ptrVal;
Color colorVal; Color colorVal;
String stringVal; String stringVal;

View File

@ -95,7 +95,7 @@ namespace Nz
} }
case ParameterType_Color: case ParameterType_Color:
case ParameterType_Float: case ParameterType_Double:
case ParameterType_None: case ParameterType_None:
case ParameterType_Pointer: case ParameterType_Pointer:
case ParameterType_Userdata: case ParameterType_Userdata:
@ -137,9 +137,9 @@ namespace Nz
return true; return true;
case ParameterType_Boolean: case ParameterType_Boolean:
case ParameterType_Double:
case ParameterType_Integer: case ParameterType_Integer:
case ParameterType_String: case ParameterType_String:
case ParameterType_Float:
case ParameterType_None: case ParameterType_None:
case ParameterType_Pointer: case ParameterType_Pointer:
case ParameterType_Userdata: case ParameterType_Userdata:
@ -151,19 +151,19 @@ namespace Nz
} }
/*! /*!
* \brief Gets a parameter as a float * \brief Gets a parameter as a double
* \return true if the parameter could be represented as a float * \return true if the parameter could be represented as a double
* *
* \param name Name of the parameter * \param name Name of the parameter
* \param value Pointer to a float to hold the retrieved value * \param value Pointer to a double to hold the retrieved value
* *
* \remark value must be a valid pointer * \remark value must be a valid pointer
* \remark In case of failure, the variable pointed by value keep its value * \remark In case of failure, the variable pointed by value keep its value
* \remark If the parameter is not a float, a conversion will be performed, compatibles types are: * \remark If the parameter is not a double, a conversion will be performed, compatibles types are:
Integer: The integer value is converted to its float representation Integer: The integer value is converted to its double representation
String: Conversion obeys the rule as described by String::ToDouble String: Conversion obeys the rule as described by String::ToDouble
*/ */
bool ParameterList::GetFloatParameter(const String& name, float* value) const bool ParameterList::GetDoubleParameter(const String& name, double* value) const
{ {
NazaraAssert(value, "Invalid pointer"); NazaraAssert(value, "Invalid pointer");
@ -178,12 +178,12 @@ namespace Nz
switch (it->second.type) switch (it->second.type)
{ {
case ParameterType_Float: case ParameterType_Double:
*value = it->second.value.floatVal; *value = it->second.value.doubleVal;
return true; return true;
case ParameterType_Integer: case ParameterType_Integer:
*value = static_cast<float>(it->second.value.intVal); *value = static_cast<double>(it->second.value.intVal);
return true; return true;
case ParameterType_String: case ParameterType_String:
@ -191,7 +191,7 @@ namespace Nz
double converted; double converted;
if (it->second.value.stringVal.ToDouble(&converted)) if (it->second.value.stringVal.ToDouble(&converted))
{ {
*value = static_cast<float>(converted); *value = converted;
return true; return true;
} }
@ -206,7 +206,7 @@ namespace Nz
break; break;
} }
NazaraError("Parameter value is not representable as a float"); NazaraError("Parameter value is not representable as a double");
return false; return false;
} }
@ -219,12 +219,12 @@ namespace Nz
* *
* \remark value must be a valid pointer * \remark value must be a valid pointer
* \remark In case of failure, the variable pointed by value keep its value * \remark In case of failure, the variable pointed by value keep its value
* \remark If the parameter is not a float, a conversion will be performed, compatibles types are: * \remark If the parameter is not an integer, a conversion will be performed, compatibles types are:
Boolean: The boolean is represented as 1 if true and 0 if false Boolean: The boolean is represented as 1 if true and 0 if false
Float: The floating-point value is truncated and converted to a integer Double: The floating-point value is truncated and converted to a integer
String: Conversion obeys the rule as described by String::ToInteger but fails if the value could not be represented as a int String: Conversion obeys the rule as described by String::ToInteger
*/ */
bool ParameterList::GetIntegerParameter(const String& name, int* value) const bool ParameterList::GetIntegerParameter(const String& name, long long* value) const
{ {
NazaraAssert(value, "Invalid pointer"); NazaraAssert(value, "Invalid pointer");
@ -243,8 +243,8 @@ namespace Nz
*value = (it->second.value.boolVal) ? 1 : 0; *value = (it->second.value.boolVal) ? 1 : 0;
return true; return true;
case ParameterType_Float: case ParameterType_Double:
*value = static_cast<int>(it->second.value.floatVal); *value = static_cast<long long>(it->second.value.doubleVal);
return true; return true;
case ParameterType_Integer: case ParameterType_Integer:
@ -256,11 +256,8 @@ namespace Nz
long long converted; long long converted;
if (it->second.value.stringVal.ToInteger(&converted)) if (it->second.value.stringVal.ToInteger(&converted))
{ {
if (converted <= std::numeric_limits<int>::max() && converted >= std::numeric_limits<int>::min()) *value = converted;
{ return true;
*value = static_cast<int>(converted);
return true;
}
} }
break; break;
} }
@ -335,7 +332,7 @@ namespace Nz
case ParameterType_Boolean: case ParameterType_Boolean:
case ParameterType_Color: case ParameterType_Color:
case ParameterType_Float: case ParameterType_Double:
case ParameterType_Integer: case ParameterType_Integer:
case ParameterType_None: case ParameterType_None:
case ParameterType_String: case ParameterType_String:
@ -358,7 +355,7 @@ namespace Nz
* \remark If the parameter is not a string, a conversion will be performed, all types are compatibles: * \remark If the parameter is not a string, a conversion will be performed, all types are compatibles:
Boolean: Conversion obeys the rules of String::Boolean Boolean: Conversion obeys the rules of String::Boolean
Color: Conversion obeys the rules of Color::ToString Color: Conversion obeys the rules of Color::ToString
Float: Conversion obeys the rules of String::Number Double: Conversion obeys the rules of String::Number
Integer: Conversion obeys the rules of String::Number Integer: Conversion obeys the rules of String::Number
None: An empty string is returned None: An empty string is returned
Pointer: Conversion obeys the rules of String::Pointer Pointer: Conversion obeys the rules of String::Pointer
@ -387,8 +384,8 @@ namespace Nz
*value = it->second.value.colorVal.ToString(); *value = it->second.value.colorVal.ToString();
return true; return true;
case ParameterType_Float: case ParameterType_Double:
*value = String::Number(it->second.value.floatVal); *value = String::Number(it->second.value.doubleVal);
return true; return true;
case ParameterType_Integer: case ParameterType_Integer:
@ -560,18 +557,18 @@ namespace Nz
} }
/*! /*!
* \brief Sets a float parameter named `name` * \brief Sets a double parameter named `name`
* *
* If a parameter already exists with that name, it is destroyed and replaced by this call * If a parameter already exists with that name, it is destroyed and replaced by this call
* *
* \param name Name of the parameter * \param name Name of the parameter
* \param value The float value * \param value The double value
*/ */
void ParameterList::SetParameter(const String& name, float value) void ParameterList::SetParameter(const String& name, double value)
{ {
Parameter& parameter = CreateValue(name); Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_Float; parameter.type = ParameterType_Double;
parameter.value.floatVal = value; parameter.value.doubleVal = value;
} }
/*! /*!
@ -582,7 +579,7 @@ namespace Nz
* \param name Name of the parameter * \param name Name of the parameter
* \param value The integer value * \param value The integer value
*/ */
void ParameterList::SetParameter(const String& name, int value) void ParameterList::SetParameter(const String& name, long long value)
{ {
Parameter& parameter = CreateValue(name); Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_Integer; parameter.type = ParameterType_Integer;
@ -627,8 +624,8 @@ namespace Nz
case ParameterType_Color: case ParameterType_Color:
ss << "Color(" << it->second.value.colorVal.ToString() << ")"; ss << "Color(" << it->second.value.colorVal.ToString() << ")";
break; break;
case ParameterType_Float: case ParameterType_Double:
ss << "Float(" << it->second.value.floatVal << ")"; ss << "Double(" << it->second.value.doubleVal << ")";
break; break;
case ParameterType_Integer: case ParameterType_Integer:
ss << "Integer(" << it->second.value.intVal << ")"; ss << "Integer(" << it->second.value.intVal << ")";
@ -692,7 +689,7 @@ namespace Nz
{ {
case ParameterType_Boolean: case ParameterType_Boolean:
case ParameterType_Color: case ParameterType_Color:
case ParameterType_Float: case ParameterType_Double:
case ParameterType_Integer: case ParameterType_Integer:
case ParameterType_Pointer: case ParameterType_Pointer:
std::memcpy(&parameter, &it->second, sizeof(Parameter)); std::memcpy(&parameter, &it->second, sizeof(Parameter));
@ -764,7 +761,7 @@ namespace Nz
case ParameterType_Boolean: case ParameterType_Boolean:
case ParameterType_Color: case ParameterType_Color:
case ParameterType_Float: case ParameterType_Double:
case ParameterType_Integer: case ParameterType_Integer:
case ParameterType_None: case ParameterType_None:
case ParameterType_Pointer: case ParameterType_Pointer:

View File

@ -124,8 +124,8 @@ namespace Nz
// Some default settings // Some default settings
data.SetParameter(MaterialData::Blending, true); data.SetParameter(MaterialData::Blending, true);
data.SetParameter(MaterialData::DepthWrite, true); data.SetParameter(MaterialData::DepthWrite, true);
data.SetParameter(MaterialData::DstBlend, static_cast<int>(BlendFunc_InvSrcAlpha)); data.SetParameter(MaterialData::DstBlend, static_cast<long long>(BlendFunc_InvSrcAlpha));
data.SetParameter(MaterialData::SrcBlend, static_cast<int>(BlendFunc_SrcAlpha)); data.SetParameter(MaterialData::SrcBlend, static_cast<long long>(BlendFunc_SrcAlpha));
} }
it = materialCache.emplace(matName, std::move(data)).first; it = materialCache.emplace(matName, std::move(data)).first;
@ -139,7 +139,7 @@ namespace Nz
bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters) bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters)
{ {
int reservedVertexCount; long long reservedVertexCount;
if (!parameters.custom.GetIntegerParameter("NativeOBJLoader_VertexCount", &reservedVertexCount)) if (!parameters.custom.GetIntegerParameter("NativeOBJLoader_VertexCount", &reservedVertexCount))
reservedVertexCount = 100; reservedVertexCount = 100;

View File

@ -128,7 +128,7 @@ namespace Nz
else else
{ {
Color colorVal; Color colorVal;
float fValue; double dValue;
if (matData.GetColorParameter(MaterialData::AmbientColor, &colorVal)) if (matData.GetColorParameter(MaterialData::AmbientColor, &colorVal))
material->ambient = colorVal; material->ambient = colorVal;
@ -139,8 +139,8 @@ namespace Nz
if (matData.GetColorParameter(MaterialData::SpecularColor, &colorVal)) if (matData.GetColorParameter(MaterialData::SpecularColor, &colorVal))
material->specular = colorVal; material->specular = colorVal;
if (matData.GetFloatParameter(MaterialData::Shininess, &fValue)) if (matData.GetDoubleParameter(MaterialData::Shininess, &dValue))
material->shininess = fValue; material->shininess = float(dValue);
if (matData.GetStringParameter(MaterialData::AlphaTexturePath, &strVal)) if (matData.GetStringParameter(MaterialData::AlphaTexturePath, &strVal))
material->alphaMap = strVal; material->alphaMap = strVal;

View File

@ -24,13 +24,13 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
WHEN("We add Float '3.f'") WHEN("We add Float '3.f'")
{ {
float fl = 3.f; double fl = 3.f;
parameterList.SetParameter("float", fl); parameterList.SetParameter("double", fl);
THEN("We can get it back") THEN("We can get it back")
{ {
float newFl; double newFl;
REQUIRE(parameterList.GetFloatParameter("float", &newFl)); REQUIRE(parameterList.GetDoubleParameter("double", &newFl));
REQUIRE(newFl == fl); REQUIRE(newFl == fl);
} }
} }