1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Adjust the Vector3 and Vector4 type functions to use the new method of receiving formatted strings.

This commit is contained in:
Sandu Liviu Catalin 2016-11-16 16:20:11 +02:00
parent 32ce07bdad
commit cb9581786e
4 changed files with 26 additions and 28 deletions

View File

@ -415,9 +415,9 @@ void Vector3::SetQuaternionEx(Value qx, Value qy, Value qz, Value qw)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Vector3::SetStr(CSStr values, SQChar delim) void Vector3::SetStr(SQChar delim, const StackStrF & values)
{ {
SetVector3(Vector3::Get(values, delim)); SetVector3(Vector3::GetEx(delim, values));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -629,13 +629,13 @@ void Vector3::CenterRotateYZBy(Value degrees, const Vector3 & center)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const Vector3 & Vector3::Get(CSStr str) const Vector3 & Vector3::Get(const StackStrF & str)
{ {
return Vector3::Get(str, Vector3::Delim); return Vector3::GetEx(Vector3::Delim, str);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const Vector3 & Vector3::Get(CSStr str, SQChar delim) const Vector3 & Vector3::GetEx(SQChar delim, const StackStrF & str)
{ {
// The format specifications that will be used to scan the string // The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f "); static SQChar fs[] = _SC(" %f , %f , %f ");
@ -643,7 +643,7 @@ const Vector3 & Vector3::Get(CSStr str, SQChar delim)
// Clear previous values, if any // Clear previous values, if any
vec.Clear(); vec.Clear();
// Is the specified string empty? // Is the specified string empty?
if (!str || *str == '\0') if (str.mLen <= 0)
{ {
return vec; // Return the value as is! return vec; // Return the value as is!
} }
@ -651,7 +651,7 @@ const Vector3 & Vector3::Get(CSStr str, SQChar delim)
fs[4] = delim; fs[4] = delim;
fs[9] = delim; fs[9] = delim;
// Attempt to extract the component values from the specified string // Attempt to extract the component values from the specified string
std::sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z); std::sscanf(str.mPtr, &fs[0], &vec.x, &vec.y, &vec.z);
// Return the resulted value // Return the resulted value
return vec; return vec;
} }
@ -742,7 +742,7 @@ void Register_Vector3(HSQUIRRELVM vm)
.Func(_SC("SetVector4Ex"), &Vector3::SetVector4Ex) .Func(_SC("SetVector4Ex"), &Vector3::SetVector4Ex)
.Func(_SC("SetQuaternion"), &Vector3::SetQuaternion) .Func(_SC("SetQuaternion"), &Vector3::SetQuaternion)
.Func(_SC("SetQuaternionEx"), &Vector3::SetQuaternionEx) .Func(_SC("SetQuaternionEx"), &Vector3::SetQuaternionEx)
.Func(_SC("SetStr"), &Vector3::SetStr) .FmtFunc(_SC("SetStr"), &Vector3::SetStr)
.Func(_SC("Clear"), &Vector3::Clear) .Func(_SC("Clear"), &Vector3::Clear)
.Func(_SC("Normalize"), &Vector3::Normalize) .Func(_SC("Normalize"), &Vector3::Normalize)
.Func(_SC("Dot"), &Vector3::DotProduct) .Func(_SC("Dot"), &Vector3::DotProduct)
@ -765,12 +765,11 @@ void Register_Vector3(HSQUIRRELVM vm)
.Overload< void (Vector3::*)(void) >(_SC("Generate"), &Vector3::Generate) .Overload< void (Vector3::*)(void) >(_SC("Generate"), &Vector3::Generate)
.Overload< void (Vector3::*)(Val, Val) >(_SC("Generate"), &Vector3::Generate) .Overload< void (Vector3::*)(Val, Val) >(_SC("Generate"), &Vector3::Generate)
.Overload< void (Vector3::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Vector3::Generate) .Overload< void (Vector3::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Vector3::Generate)
// Static Overloads
.StaticOverload< const Vector3 & (*)(CSStr) >(_SC("FromStr"), &Vector3::Get)
.StaticOverload< const Vector3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector3::Get)
// Static Functions // Static Functions
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Vector3 >) .StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Vector3 >)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector3 >) .StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector3 >)
.StaticFmtFunc(_SC("FromStr"), &Vector3::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Vector3::GetEx)
// Operator Exposure // Operator Exposure
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opAddAssign"), &Vector3::operator +=) .Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opAddAssign"), &Vector3::operator +=)
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opSubAssign"), &Vector3::operator -=) .Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opSubAssign"), &Vector3::operator -=)

View File

@ -336,7 +336,7 @@ struct Vector3
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Set the values extracted from the specified string using the specified delimiter. * Set the values extracted from the specified string using the specified delimiter.
*/ */
void SetStr(CSStr values, SQChar delim); void SetStr(SQChar delim, const StackStrF & values);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Generate random values for all components of this instance. * Generate random values for all components of this instance.
@ -493,12 +493,12 @@ struct Vector3
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string. * Extract the values for components of the Vector3 type from a string.
*/ */
static const Vector3 & Get(CSStr str); static const Vector3 & Get(const StackStrF & str);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string. * Extract the values for components of the Vector3 type from a string.
*/ */
static const Vector3 & Get(CSStr str, SQChar delim); static const Vector3 & GetEx(SQChar delim, const StackStrF & str);
}; };

View File

@ -416,9 +416,9 @@ void Vector4::SetQuaternionEx(Value nx, Value ny, Value nz, Value nw)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Vector4::SetStr(CSStr values, SQChar delim) void Vector4::SetStr(SQChar delim, const StackStrF & values)
{ {
SetVector4(Vector4::Get(values, delim)); SetVector4(Vector4::GetEx(delim, values));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -465,13 +465,13 @@ Vector4 Vector4::Abs() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const Vector4 & Vector4::Get(CSStr str) const Vector4 & Vector4::Get(const StackStrF & str)
{ {
return Vector4::Get(str, Vector4::Delim); return Vector4::GetEx(Vector4::Delim, str);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const Vector4 & Vector4::Get(CSStr str, SQChar delim) const Vector4 & Vector4::GetEx(SQChar delim, const StackStrF & str)
{ {
// The format specifications that will be used to scan the string // The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f "); static SQChar fs[] = _SC(" %f , %f , %f , %f ");
@ -479,7 +479,7 @@ const Vector4 & Vector4::Get(CSStr str, SQChar delim)
// Clear previous values, if any // Clear previous values, if any
vec.Clear(); vec.Clear();
// Is the specified string empty? // Is the specified string empty?
if (!str || *str == '\0') if (str.mLen <= 0)
{ {
return vec; // Return the value as is! return vec; // Return the value as is!
} }
@ -488,7 +488,7 @@ const Vector4 & Vector4::Get(CSStr str, SQChar delim)
fs[9] = delim; fs[9] = delim;
fs[14] = delim; fs[14] = delim;
// Attempt to extract the component values from the specified string // Attempt to extract the component values from the specified string
std::sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w); std::sscanf(str.mPtr, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w);
// Return the resulted value // Return the resulted value
return vec; return vec;
} }
@ -575,18 +575,17 @@ void Register_Vector4(HSQUIRRELVM vm)
.Func(_SC("SetVector3Ex"), &Vector4::SetVector3Ex) .Func(_SC("SetVector3Ex"), &Vector4::SetVector3Ex)
.Func(_SC("SetQuaternion"), &Vector4::SetQuaternion) .Func(_SC("SetQuaternion"), &Vector4::SetQuaternion)
.Func(_SC("SetQuaternionEx"), &Vector4::SetQuaternionEx) .Func(_SC("SetQuaternionEx"), &Vector4::SetQuaternionEx)
.Func(_SC("SetStr"), &Vector4::SetStr) .FmtFunc(_SC("SetStr"), &Vector4::SetStr)
.Func(_SC("Clear"), &Vector4::Clear) .Func(_SC("Clear"), &Vector4::Clear)
// Member Overloads // Member Overloads
.Overload< void (Vector4::*)(void) >(_SC("Generate"), &Vector4::Generate) .Overload< void (Vector4::*)(void) >(_SC("Generate"), &Vector4::Generate)
.Overload< void (Vector4::*)(Val, Val) >(_SC("Generate"), &Vector4::Generate) .Overload< void (Vector4::*)(Val, Val) >(_SC("Generate"), &Vector4::Generate)
.Overload< void (Vector4::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Vector4::Generate) .Overload< void (Vector4::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Vector4::Generate)
// Static Overloads
.StaticOverload< const Vector4 & (*)(CSStr) >(_SC("FromStr"), &Vector4::Get)
.StaticOverload< const Vector4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector4::Get)
// Static Functions // Static Functions
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Vector4 >) .StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Vector4 >)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector4 >) .StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector4 >)
.StaticFmtFunc(_SC("FromStr"), &Vector4::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Vector4::GetEx)
// Operator Exposure // Operator Exposure
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opAddAssign"), &Vector4::operator +=) .Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opAddAssign"), &Vector4::operator +=)
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opSubAssign"), &Vector4::operator -=) .Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opSubAssign"), &Vector4::operator -=)

View File

@ -334,7 +334,7 @@ struct Vector4
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Set the values extracted from the specified string using the specified delimiter. * Set the values extracted from the specified string using the specified delimiter.
*/ */
void SetStr(CSStr values, SQChar delim); void SetStr(SQChar delim, const StackStrF & values);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Generate random values for all components of this instance. * Generate random values for all components of this instance.
@ -367,12 +367,12 @@ struct Vector4
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string. * Extract the values for components of the Vector4 type from a string.
*/ */
static const Vector4 & Get(CSStr str); static const Vector4 & Get(const StackStrF & str);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string. * Extract the values for components of the Vector4 type from a string.
*/ */
static const Vector4 & Get(CSStr str, SQChar delim); static const Vector4 & GetEx(SQChar delim, const StackStrF & str);
}; };