1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-15 22:57:12 +02:00

Updated the exception system in the main plugin to also include the location in the source files in debug builds.

Moved the functions that extract base types from strings as static functions under the associated type.
Revised some of the base shared code.
Fixed some of the functions in the String library that did not take into account the null terminator.
This commit is contained in:
Sandu Liviu Catalin
2016-03-21 22:37:58 +02:00
parent e3315430ea
commit 8088ba94c2
50 changed files with 648 additions and 493 deletions

View File

@ -358,6 +358,37 @@ AABB AABB::Abs() const
return AABB(min.Abs(), max.Abs());
}
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(CSStr str)
{
return GetAABB(str, AABB::Delim);
}
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f , %f , %f ");
static AABB box;
// Clear previous values, if any
box.Clear();
// Is the specified string empty?
if (!str || *str == '\0')
{
return box; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
fs[19] = delim;
fs[24] = delim;
// Attempt to extract the component values from the specified string
std::sscanf(str, fs, &box.min.x, &box.min.y, &box.min.z, &box.max.x, &box.max.y, &box.max.z);
// Return the resulted value
return box;
}
// ================================================================================================
void Register_AABB(HSQUIRRELVM vm)
{
@ -438,6 +469,9 @@ void Register_AABB(HSQUIRRELVM vm)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opGreaterThan"), &AABB::operator >)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opLessEqual"), &AABB::operator <=)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opGreaterEqual"), &AABB::operator >=)
// Static Overloads
.StaticOverload< const AABB & (*)(CSStr) >(_SC("FromStr"), &GetAABB)
.StaticOverload< const AABB & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetAABB)
);
}

View File

@ -7,6 +7,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the AABB type from a string.
*/
const AABB & GetAABB(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the AABB type from a string.
*/
const AABB & GetAABB(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent an axis aligned bounding box in three-dimensional space.
*/

View File

@ -382,7 +382,7 @@ void Circle::Generate()
void Circle::Generate(Value min, Value max, bool r)
{
if (EpsLt(max, min))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
else if (r)
rad = GetRandomFloat32(min, max);
else
@ -392,7 +392,7 @@ void Circle::Generate(Value min, Value max, bool r)
void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
pos.Generate(xmin, xmax, ymin, ymax);
}
@ -400,7 +400,7 @@ void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin, Value rmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(rmax, rmin))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
pos.Generate(xmin, xmax, ymin, ymax);
rad = GetRandomFloat32(rmin, rmax);
@ -412,6 +412,34 @@ Circle Circle::Abs() const
return Circle(pos.Abs(), fabs(rad));
}
// ------------------------------------------------------------------------------------------------
const Circle & GetCircle(CSStr str)
{
return GetCircle(str, Circle::Delim);
}
// ------------------------------------------------------------------------------------------------
const Circle & GetCircle(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f ");
static Circle circle;
// Clear previous values, if any
circle.Clear();
// Is the specified string empty?
if (!str || *str == '\0')
{
return circle; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
fs[9] = delim;
// Attempt to extract the component values from the specified string
std::sscanf(str, fs, &circle.pos.x, &circle.pos.y, &circle.rad);
// Return the resulted value
return circle;
}
// ================================================================================================
void Register_Circle(HSQUIRRELVM vm)
{
@ -502,6 +530,9 @@ void Register_Circle(HSQUIRRELVM vm)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opGreaterThan"), &Circle::operator >)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opLessEqual"), &Circle::operator <=)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opGreaterEqual"), &Circle::operator >=)
// Static Overloads
.StaticOverload< const Circle & (*)(CSStr) >(_SC("FromStr"), &GetCircle)
.StaticOverload< const Circle & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetCircle)
);
}

View File

@ -8,6 +8,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
*/
const Circle & GetCircle(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
*/
const Circle & GetCircle(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a two-dimensional circle.
*/

View File

@ -4,6 +4,9 @@
#include "Base/Shared.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@ -530,7 +533,7 @@ void Color3::Generate()
void Color3::Generate(Value min, Value max)
{
if (max < min)
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
r = GetRandomUint8(min, max);
g = GetRandomUint8(min, max);
@ -540,7 +543,7 @@ void Color3::Generate(Value min, Value max)
void Color3::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax)
{
if (rmax < rmin || gmax < gmin || bmax < bmin)
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
r = GetRandomUint8(rmin, rmax);
g = GetRandomUint8(gmin, gmax);
@ -561,6 +564,43 @@ void Color3::Inverse()
b = static_cast< Value >(~b);
}
// ------------------------------------------------------------------------------------------------
const Color3 & GetColor3(CSStr str)
{
return GetColor3(str, Color3::Delim);
}
// ------------------------------------------------------------------------------------------------
const Color3 & GetColor3(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u , %u , %u ");
static Color3 col;
// The minimum and maximum values supported by the Color3 type
static const Uint32 min = std::numeric_limits< Color3::Value >::min();
static const Uint32 max = std::numeric_limits< Color3::Value >::max();
// Clear previous values, if any
col.Clear();
// Is the specified string empty?
if (!str || *str == '\0')
{
return col; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
fs[9] = delim;
// The sscanf function requires at least 32 bit integers
Uint32 r = 0, g = 0, b = 0;
// Attempt to extract the component values from the specified string
std::sscanf(str, fs, &r, &g, &b);
// Cast the extracted integers to the value used by the Color3 type
col.r = static_cast< Color3::Value >(Clamp(r, min, max));
col.g = static_cast< Color3::Value >(Clamp(g, min, max));
col.b = static_cast< Color3::Value >(Clamp(b, min, max));
// Return the resulted value
return col;
}
// ================================================================================================
void Register_Color3(HSQUIRRELVM vm)
{
@ -667,6 +707,9 @@ void Register_Color3(HSQUIRRELVM vm)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterThan"), &Color3::operator >)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessEqual"), &Color3::operator <=)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterEqual"), &Color3::operator >=)
// Static Overloads
.StaticOverload< const Color3 & (*)(CSStr) >(_SC("FromStr"), &GetColor3)
.StaticOverload< const Color3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetColor3)
);
}

View File

@ -7,6 +7,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color3 type from a string.
*/
const Color3 & GetColor3(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color3 type from a string.
*/
const Color3 & GetColor3(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent an opaque RGB color.
*/

View File

@ -4,6 +4,9 @@
#include "Base/Shared.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@ -576,7 +579,7 @@ void Color4::Generate()
void Color4::Generate(Value min, Value max)
{
if (max < min)
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
r = GetRandomUint8(min, max);
g = GetRandomUint8(min, max);
@ -587,7 +590,7 @@ void Color4::Generate(Value min, Value max)
void Color4::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax, Value amin, Value amax)
{
if (rmax < rmin || gmax < gmin || bmax < bmin || amax < amin)
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
r = GetRandomUint8(rmin, rmax);
g = GetRandomUint8(gmin, gmax);
@ -610,6 +613,45 @@ void Color4::Inverse()
a = static_cast< Value >(~a);
}
// ------------------------------------------------------------------------------------------------
const Color4 & GetColor4(CSStr str)
{
return GetColor4(str, Color4::Delim);
}
// ------------------------------------------------------------------------------------------------
const Color4 & GetColor4(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u , %u , %u , %u ");
static Color4 col;
// The minimum and maximum values supported by the Color4 type
static const Uint32 min = std::numeric_limits< Color4::Value >::min();
static const Uint32 max = std::numeric_limits< Color4::Value >::max();
// Clear previous values, if any
col.Clear();
// Is the specified string empty?
if (!str || *str == '\0')
{
return col; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
// The sscanf function requires at least 32 bit integers
Uint32 r = 0, g = 0, b = 0, a = 0;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &r, &g, &b, &a);
// Cast the extracted integers to the value used by the Color4 type
col.r = static_cast< Color4::Value >(Clamp(r, min, max));
col.g = static_cast< Color4::Value >(Clamp(g, min, max));
col.b = static_cast< Color4::Value >(Clamp(b, min, max));
col.a = static_cast< Color4::Value >(Clamp(a, min, max));
// Return the resulted value
return col;
}
// ================================================================================================
void Register_Color4(HSQUIRRELVM vm)
{
@ -719,6 +761,9 @@ void Register_Color4(HSQUIRRELVM vm)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opGreaterThan"), &Color4::operator >)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opLessEqual"), &Color4::operator <=)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opGreaterEqual"), &Color4::operator >=)
// Static Overloads
.StaticOverload< const Color4 & (*)(CSStr) >(_SC("FromStr"), &GetColor4)
.StaticOverload< const Color4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetColor4)
);
}

View File

@ -7,6 +7,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color4 type from a string.
*/
const Color4 & GetColor4(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color4 type from a string.
*/
const Color4 & GetColor4(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a transparent RGBA color.
*/

View File

@ -393,7 +393,7 @@ void Quaternion::Generate()
void Quaternion::Generate(Value min, Value max)
{
if (EpsLt(max, min))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
@ -404,7 +404,7 @@ void Quaternion::Generate(Value min, Value max)
void Quaternion::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomFloat32(xmin, xmax);
y = GetRandomFloat32(ymin, ymax);
@ -418,6 +418,35 @@ Quaternion Quaternion::Abs() const
return Quaternion(fabs(x), fabs(y), fabs(z), fabs(w));
}
// ------------------------------------------------------------------------------------------------
const Quaternion & GetQuaternion(CSStr str)
{
return GetQuaternion(str, Quaternion::Delim);
}
// ------------------------------------------------------------------------------------------------
const Quaternion & GetQuaternion(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
static Quaternion quat;
// Clear previous values, if any
quat.Clear();
// Is the specified string empty?
if (!str || *str == '\0')
{
return quat; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &quat.x, &quat.y, &quat.z, &quat.w);
// Return the resulted value
return quat;
}
// ================================================================================================
void Register_Quaternion(HSQUIRRELVM vm)
{
@ -502,6 +531,9 @@ void Register_Quaternion(HSQUIRRELVM vm)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opGreaterThan"), &Quaternion::operator >)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opLessEqual"), &Quaternion::operator <=)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opGreaterEqual"), &Quaternion::operator >=)
// Static Overloads
.StaticOverload< const Quaternion & (*)(CSStr) >(_SC("FromStr"), &GetQuaternion)
.StaticOverload< const Quaternion & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetQuaternion)
);
}

View File

@ -7,6 +7,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
*/
const Quaternion & GetQuaternion(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
*/
const Quaternion & GetQuaternion(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Quaternion class for representing rotations.
*/

View File

@ -17,10 +17,11 @@
#include "Base/Vector4.hpp"
// ------------------------------------------------------------------------------------------------
#include <time.h>
#include <float.h>
#include <limits.h>
#include <stdarg.h>
#include <ctime>
#include <cfloat>
#include <limits>
#include <cstdarg>
#include <cstring>
#include <algorithm>
// ------------------------------------------------------------------------------------------------
@ -113,7 +114,7 @@ Object BufferToStrObj(const Buffer & b, Uint32 size)
// Perform a range check on the specified buffer
if (size > b.Capacity())
{
SqThrowF("The specified buffer size is out of range: %u >= %u", size, b.Capacity());
STHROWF("The specified buffer size is out of range: %u >= %u", size, b.Capacity());
}
// Obtain the initial stack size
const StackGuard sg(DefaultVM::Get());
@ -138,7 +139,9 @@ void SqThrowF(CCStr fmt, ...)
va_start (args, fmt);
// Write the requested contents
if (snprintf(g_Buffer, sizeof(g_Buffer), fmt, args) < 0)
{
strcpy(g_Buffer, "Unknown error has occurred");
}
// Release the argument list
va_end(args);
// Throw the exception with the resulted message
@ -155,7 +158,9 @@ CSStr ToStrF(CCStr fmt, ...)
int ret = vsnprintf(g_Buffer, sizeof(g_Buffer), fmt, args);
// See if the format function failed
if (ret < 0)
SqThrowF("Failed to run the specified string format");
{
STHROWF("Failed to run the specified string format");
}
// Finalized the arguments list
va_end(args);
// Return the resulted string
@ -172,8 +177,10 @@ CSStr ToStringF(CCStr fmt, ...)
va_start (args, fmt);
// Attempt to run the specified format
if (b.WriteF(0, fmt, args) == 0)
{
// Make sure the string is null terminated
b.At(0) = 0;
}
// Finalized the arguments list
va_end(args);
// Return the resulted string
@ -336,15 +343,19 @@ Color3 GetColor(CSStr name)
{
// See if we actually have something to search for
if(!name || *name == 0)
SqThrowF("Cannot extract values from an empty string");
{
STHROWF("Cannot extract values from an empty string");
}
// Clone the string into an editable version
CCStr str = StrJustAlphaNum(name);
str = StrToLowercase(str);
// See if we still have a valid name after the cleanup
if(!str || *str == 0)
SqThrowF("Cannot extract values from an invalid string: %s", name);
if(!str || *str == '\0')
{
STHROWF("Cannot extract values from an invalid string: %s", name);
}
// Calculate the name length
const Uint32 len = strlen(str);
const Uint32 len = std::strlen(str);
// Get the most significant characters used to identify a weapon
SQChar a = str[0], b = 0, c = 0, d = str[len-1];
// Look for deeper specifiers
@ -933,283 +944,6 @@ Color3 GetColor(CSStr name)
}
}
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %f , %f , %f , %f , %f , %f ");
static AABB box;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
box.Clear();
if (delim != AABB::Delim)
{
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
fs[19] = delim;
fs[24] = delim;
}
else
{
fs[4] = AABB::Delim;
fs[9] = AABB::Delim;
fs[14] = AABB::Delim;
fs[19] = AABB::Delim;
fs[24] = AABB::Delim;
}
sscanf(str, &fs[0], &box.min.x, &box.min.y, &box.min.z, &box.max.x, &box.max.y, &box.max.z);
return box;
}
// ------------------------------------------------------------------------------------------------
const Circle & GetCircle(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %f , %f , %f ");
static Circle circle;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
circle.Clear();
if (delim != Circle::Delim)
{
fs[4] = delim;
fs[9] = delim;
}
else
{
fs[4] = Circle::Delim;
fs[9] = Circle::Delim;
}
sscanf(str, &fs[0], &circle.pos.x, &circle.pos.y, &circle.rad);
return circle;
}
// ------------------------------------------------------------------------------------------------
const Color3 & GetColor3(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %u , %u , %u ");
static Color3 col;
Uint32 r = 0, g = 0, b = 0;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
else if (delim != Color3::Delim)
{
fs[4] = delim;
fs[9] = delim;
}
else
{
fs[4] = Color3::Delim;
fs[9] = Color3::Delim;
}
sscanf(str, &fs[0], &r, &g, &b);
col.r = static_cast< Color4::Value >(r);
col.g = static_cast< Color4::Value >(g);
col.b = static_cast< Color4::Value >(b);
return col;
}
// ------------------------------------------------------------------------------------------------
const Color4 & GetColor4(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %u , %u , %u , %u ");
static Color4 col;
Uint32 r = 0, g = 0, b = 0, a = 0;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
else if (delim != Color4::Delim)
{
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
}
else
{
fs[4] = Color4::Delim;
fs[9] = Color4::Delim;
fs[14] = Color4::Delim;
}
sscanf(str, &fs[0], &r, &g, &b, &a);
col.r = static_cast< Color4::Value >(r);
col.g = static_cast< Color4::Value >(g);
col.b = static_cast< Color4::Value >(b);
col.a = static_cast< Color4::Value >(a);
return col;
}
// ------------------------------------------------------------------------------------------------
const Quaternion & GetQuaternion(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
static Quaternion quat;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
quat.Clear();
if (delim != Quaternion::Delim)
{
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
}
else
{
fs[4] = Quaternion::Delim;
fs[9] = Quaternion::Delim;
fs[14] = Quaternion::Delim;
}
sscanf(str, &fs[0], &quat.x, &quat.y, &quat.z, &quat.w);
return quat;
}
// ------------------------------------------------------------------------------------------------
const Sphere & GetSphere(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
static Sphere sphere;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
sphere.Clear();
if (delim != Sphere::Delim)
{
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
}
else
{
fs[4] = Sphere::Delim;
fs[9] = Sphere::Delim;
fs[14] = Sphere::Delim;
}
sscanf(str, &fs[0], &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad);
return sphere;
}
// ------------------------------------------------------------------------------------------------
const Vector2 & GetVector2(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %f , %f ");
static Vector2 vec;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
vec.Clear();
if (delim != Vector2::Delim)
fs[4] = delim;
else
fs[4] = Vector2::Delim;
sscanf(str, &fs[0], &vec.x, &vec.y);
return vec;
}
const Vector2i & GetVector2i(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %d , %d ");
static Vector2i vec;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
vec.Clear();
if (delim != Vector2i::Delim)
fs[4] = delim;
else
fs[4] = Vector2i::Delim;
sscanf(str, &fs[0], &vec.x, &vec.y);
return vec;
}
// ------------------------------------------------------------------------------------------------
const Vector3 & GetVector3(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %f , %f , %f ");
static Vector3 vec;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
vec.Clear();
if (delim != Vector3::Delim)
{
fs[4] = delim;
fs[9] = delim;
}
else
{
fs[4] = Vector3::Delim;
fs[9] = Vector3::Delim;
}
sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z);
return vec;
}
const Vector4 & GetVector4(CSStr str, SQChar delim)
{
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
static Vector4 vec;
if (!str || *str == 0)
SqThrowF("Cannot extract values from an empty string");
vec.Clear();
if (delim != Vector4::Delim)
{
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
}
else
{
fs[4] = Vector4::Delim;
fs[9] = Vector4::Delim;
fs[14] = Vector4::Delim;
}
sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w);
return vec;
}
// ================================================================================================
void Register_Base(HSQUIRRELVM vm)
{
@ -1232,17 +966,7 @@ void Register_Base(HSQUIRRELVM vm)
.Func(_SC("IsGraph"), &isgraph)
.Func(_SC("IsBlank"), &isblank)
.Func(_SC("SToB"), &SToB)
.Func(_SC("GetColor"), &GetColor)
.Func(_SC("GetCircle"), &GetCircle)
.Func(_SC("GetAABB"), &GetAABB)
.Func(_SC("GetColor3"), &GetColor3)
.Func(_SC("GetColor4"), &GetColor4)
.Func(_SC("GetQuaternion"), &GetQuaternion)
.Func(_SC("GetSphere"), &GetSphere)
.Func(_SC("GetVector2"), &GetVector2)
.Func(_SC("GetVector2i"), &GetVector2i)
.Func(_SC("GetVector3"), &GetVector3)
.Func(_SC("GetVector4"), &GetVector4);
.Func(_SC("GetColor"), &GetColor);
}
} // Namespace:: SqMod

View File

@ -263,9 +263,13 @@ Object BufferToStrObj(const Buffer & b, Uint32 size);
*/
template < typename T > Object MakeObject(const T & v)
{
// Transform the specified value into a script object
PushVar< T >(DefaultVM::Get(), v);
// Get the object from the stack to obtain a strong reference to it
Var< Object > var(DefaultVM::Get(), -1);
// Now it's safe to pop the object from the stack
sq_pop(DefaultVM::Get(), 1);
// Return the resulted script object
return var.value;
}
@ -274,9 +278,13 @@ template < typename T > Object MakeObject(const T & v)
*/
template < typename T > Object MakeObject(HSQUIRRELVM vm, const T & v)
{
// Transform the specified value into a script object
PushVar< T >(vm, v);
// Get the object from the stack to obtain a strong reference to it
Var< Object > var(vm, -1);
// Now it's safe to pop the object from the stack
sq_pop(vm, 1);
// Return the resulted script object
return var.value;
}
@ -310,61 +318,10 @@ const Color3 & GetRandomColor();
*/
Color3 GetColor(CSStr name);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the AABB type from a string.
*/
const AABB & GetAABB(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
*/
const Circle & GetCircle(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color3 type from a string.
*/
const Color3 & GetColor3(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color4 type from a string.
*/
const Color4 & GetColor4(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
*/
const Quaternion & GetQuaternion(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string.
*/
const Sphere & GetSphere(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2 type from a string.
*/
const Vector2 & GetVector2(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2i type from a string.
*/
const Vector2i & GetVector2i(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string.
*/
const Vector3 & GetVector3(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string.
*/
const Vector4 & GetVector4(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary logging functions.
*/
// ------------------------------------------------------------------------------------------------
void LogDbg(CCStr fmt, ...);
void LogUsr(CCStr fmt, ...);
void LogScs(CCStr fmt, ...);
@ -373,7 +330,10 @@ void LogWrn(CCStr fmt, ...);
void LogErr(CCStr fmt, ...);
void LogFtl(CCStr fmt, ...);
// ------------------------------------------------------------------------------------------------
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary logging functions.
*/
void LogSDbg(CCStr fmt, ...);
void LogSUsr(CCStr fmt, ...);
void LogSScs(CCStr fmt, ...);
@ -382,7 +342,10 @@ void LogSWrn(CCStr fmt, ...);
void LogSErr(CCStr fmt, ...);
void LogSFtl(CCStr fmt, ...);
// ------------------------------------------------------------------------------------------------
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary conditional logging functions.
*/
bool cLogDbg(bool cond, CCStr fmt, ...);
bool cLogUsr(bool cond, CCStr fmt, ...);
bool cLogScs(bool cond, CCStr fmt, ...);
@ -391,7 +354,10 @@ bool cLogWrn(bool cond, CCStr fmt, ...);
bool cLogErr(bool cond, CCStr fmt, ...);
bool cLogFtl(bool cond, CCStr fmt, ...);
// ------------------------------------------------------------------------------------------------
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary conditional logging functions.
*/
bool cLogSDbg(bool cond, CCStr fmt, ...);
bool cLogSUsr(bool cond, CCStr fmt, ...);
bool cLogSScs(bool cond, CCStr fmt, ...);

View File

@ -382,7 +382,7 @@ void Sphere::Generate()
void Sphere::Generate(Value min, Value max, bool r)
{
if (EpsLt(max, min))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
else if (r)
rad = GetRandomFloat32(min, max);
else
@ -392,7 +392,7 @@ void Sphere::Generate(Value min, Value max, bool r)
void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax);
}
@ -400,7 +400,7 @@ void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin
void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value rmin, Value rmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(rmax, rmin))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax);
rad = GetRandomFloat32(rmin, rmax);
@ -412,6 +412,35 @@ Sphere Sphere::Abs() const
return Sphere(pos.Abs(), fabs(rad));
}
// ------------------------------------------------------------------------------------------------
const Sphere & GetSphere(CSStr str)
{
return GetSphere(str, Sphere::Delim);
}
// ------------------------------------------------------------------------------------------------
const Sphere & GetSphere(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
static Sphere sphere;
// Clear previous values, if any
sphere.Clear();
// Is the specified string empty?
if (!str || *str == '\0')
{
return sphere; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad);
// Return the resulted value
return sphere;
}
// ================================================================================================
void Register_Sphere(HSQUIRRELVM vm)
{
@ -502,6 +531,9 @@ void Register_Sphere(HSQUIRRELVM vm)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opGreaterThan"), &Sphere::operator >)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opLessEqual"), &Sphere::operator <=)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opGreaterEqual"), &Sphere::operator >=)
// Static Overloads
.StaticOverload< const Sphere & (*)(CSStr) >(_SC("FromStr"), &GetSphere)
.StaticOverload< const Sphere & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetSphere)
);
}

View File

@ -8,6 +8,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string.
*/
const Sphere & GetSphere(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string.
*/
const Sphere & GetSphere(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a three-dimensional sphere.
*/

View File

@ -322,7 +322,7 @@ void Vector2::Generate()
void Vector2::Generate(Value min, Value max)
{
if (EpsLt(max, min))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
@ -331,7 +331,7 @@ void Vector2::Generate(Value min, Value max)
void Vector2::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomFloat32(ymin, ymax);
y = GetRandomFloat32(xmin, xmax);
@ -343,6 +343,33 @@ Vector2 Vector2::Abs() const
return Vector2(fabs(x), fabs(y));
}
// ------------------------------------------------------------------------------------------------
const Vector2 & GetVector2(CSStr str)
{
return GetVector2(str, Vector2::Delim);
}
// ------------------------------------------------------------------------------------------------
const Vector2 & GetVector2(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f ");
static Vector2 vec;
// Clear previous values, if any
vec.Clear();
// Is the specified string empty?
if (!str || *str == '0')
{
return vec; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &vec.x, &vec.y);
// Return the resulted value
return vec;
}
// ================================================================================================
void Register_Vector2(HSQUIRRELVM vm)
{
@ -422,6 +449,9 @@ void Register_Vector2(HSQUIRRELVM vm)
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opGreaterThan"), &Vector2::operator >)
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opLessEqual"), &Vector2::operator <=)
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opGreaterEqual"), &Vector2::operator >=)
// Static Overloads
.StaticOverload< const Vector2 & (*)(CSStr) >(_SC("FromStr"), &GetVector2)
.StaticOverload< const Vector2 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector2)
);
}

View File

@ -7,6 +7,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2 type from a string.
*/
const Vector2 & GetVector2(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2 type from a string.
*/
const Vector2 & GetVector2(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a two-dimensional vector.
*/

View File

@ -448,7 +448,7 @@ void Vector2i::Generate()
void Vector2i::Generate(Value min, Value max)
{
if (max < min)
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomInt32(min, max);
y = GetRandomInt32(min, max);
@ -457,7 +457,7 @@ void Vector2i::Generate(Value min, Value max)
void Vector2i::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (xmax < xmin || ymax < ymin)
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomInt32(ymin, ymax);
y = GetRandomInt32(xmin, xmax);
@ -469,6 +469,33 @@ Vector2i Vector2i::Abs() const
return Vector2i(abs(x), abs(y));
}
// ------------------------------------------------------------------------------------------------
const Vector2i & GetVector2i(CSStr str)
{
return GetVector2i(str, Vector2i::Delim);
}
// ------------------------------------------------------------------------------------------------
const Vector2i & GetVector2i(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %d , %d ");
static Vector2i vec;
// Clear previous values, if any
vec.Clear();
// Is the specified string empty?
if (!str || *str == '\0')
{
return vec; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, &fs[0], &vec.x, &vec.y);
// Return the resulted value
return vec;
}
// ================================================================================================
void Register_Vector2i(HSQUIRRELVM vm)
{
@ -569,6 +596,9 @@ void Register_Vector2i(HSQUIRRELVM vm)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opGreaterThan"), &Vector2i::operator >)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opLessEqual"), &Vector2i::operator <=)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opGreaterEqual"), &Vector2i::operator >=)
// Static Overloads
.StaticOverload< const Vector2i & (*)(CSStr) >(_SC("FromStr"), &GetVector2i)
.StaticOverload< const Vector2i & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector2i)
);
}

View File

@ -7,6 +7,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2i type from a string.
*/
const Vector2i & GetVector2i(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2i type from a string.
*/
const Vector2i & GetVector2i(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a two-dimensional vector using integral values.
*/

View File

@ -353,7 +353,7 @@ void Vector3::Generate()
void Vector3::Generate(Value min, Value max)
{
if (EpsLt(max, min))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
@ -363,7 +363,7 @@ void Vector3::Generate(Value min, Value max)
void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomFloat32(xmin, xmax);
y = GetRandomFloat32(ymin, ymax);
@ -376,6 +376,34 @@ Vector3 Vector3::Abs() const
return Vector3(fabs(x), fabs(y), fabs(z));
}
// ------------------------------------------------------------------------------------------------
const Vector3 & GetVector3(CSStr str)
{
return GetVector3(str, Vector3::Delim);
}
// ------------------------------------------------------------------------------------------------
const Vector3 & GetVector3(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f ");
static Vector3 vec;
// Clear previous values, if any
vec.Clear();
// Is the specified string empty?
if (!str || *str == '\0')
{
return vec; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
fs[9] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z);
// Return the resulted value
return vec;
}
// ================================================================================================
void Register_Vector3(HSQUIRRELVM vm)
{
@ -457,6 +485,9 @@ void Register_Vector3(HSQUIRRELVM vm)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterThan"), &Vector3::operator >)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opLessEqual"), &Vector3::operator <=)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterEqual"), &Vector3::operator >=)
// Static Overloads
.StaticOverload< const Vector3 & (*)(CSStr) >(_SC("FromStr"), &GetVector3)
.StaticOverload< const Vector3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector3)
);
}

View File

@ -7,6 +7,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string.
*/
const Vector3 & GetVector3(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string.
*/
const Vector3 & GetVector3(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a three-dimensional vector.
*/

View File

@ -390,7 +390,7 @@ void Vector4::Generate()
void Vector4::Generate(Value min, Value max)
{
if (max < min)
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
@ -401,7 +401,7 @@ void Vector4::Generate(Value min, Value max)
void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
SqThrowF("max value is lower than min value");
STHROWF("max value is lower than min value");
x = GetRandomFloat32(xmin, xmax);
y = GetRandomFloat32(ymin, ymax);
@ -415,6 +415,35 @@ Vector4 Vector4::Abs() const
return Vector4(fabs(x), fabs(y), fabs(z), fabs(w));
}
// ------------------------------------------------------------------------------------------------
const Vector4 & GetVector4(CSStr str)
{
return GetVector4(str, Vector4::Delim);
}
// ------------------------------------------------------------------------------------------------
const Vector4 & GetVector4(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
static Vector4 vec;
// Clear previous values, if any
vec.Clear();
// Is the specified string empty?
if (!str || *str == '\0')
{
return vec; // Return the value as is!
}
// Assign the specified delimiter
fs[4] = delim;
fs[9] = delim;
fs[14] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w);
// Return the resulted value
return vec;
}
// ================================================================================================
void Register_Vector4(HSQUIRRELVM vm)
{
@ -499,6 +528,9 @@ void Register_Vector4(HSQUIRRELVM vm)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opGreaterThan"), &Vector4::operator >)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opLessEqual"), &Vector4::operator <=)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opGreaterEqual"), &Vector4::operator >=)
// Static Overloads
.StaticOverload< const Vector4 & (*)(CSStr) >(_SC("FromStr"), &GetVector4)
.StaticOverload< const Vector4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector4)
);
}

View File

@ -7,6 +7,16 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string.
*/
const Vector4 & GetVector4(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string.
*/
const Vector4 & GetVector4(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a four-dimensional vector.
*/