1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2026-04-20 19:17:24 +02:00

Major plugin refactor and cleanup.

Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
This commit is contained in:
Sandu Liviu Catalin
2021-01-30 08:51:39 +02:00
parent e0e34b4030
commit 4a6bfc086c
6219 changed files with 1209835 additions and 454916 deletions
+25 -79
View File
@@ -1,15 +1,15 @@
// ------------------------------------------------------------------------------------------------
#include "Base/AABB.hpp"
#include "Base/Sphere.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("AABB"))
SQMOD_DECL_TYPENAME(Typename, _SC("AABB"))
// ------------------------------------------------------------------------------------------------
const AABB AABB::NIL = AABB(0, 0);
@@ -19,13 +19,6 @@ const AABB AABB::MAX = AABB(HUGE_VALF, -HUGE_VALF);
// ------------------------------------------------------------------------------------------------
SQChar AABB::Delim = ',';
// ------------------------------------------------------------------------------------------------
AABB::AABB() noexcept
: min(HUGE_VALF), max(-HUGE_VALF)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(Value mins, Value maxs) noexcept
: min(mins), max(maxs)
@@ -285,7 +278,7 @@ bool AABB::operator >= (const AABB & b) const
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::Cmp(const AABB & o) const
int32_t AABB::Cmp(const AABB & o) const
{
if (*this == o)
{
@@ -302,9 +295,9 @@ Int32 AABB::Cmp(const AABB & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr AABB::ToString() const
String AABB::ToString() const
{
return ToStrF("%f,%f,%f,%f,%f,%f", min.x, min.y, min.z, max.x, max.y, max.z);
return fmt::format("{},{},{},{},{},{}", min.x, min.y, min.z, max.x, max.y, max.z);
}
// ------------------------------------------------------------------------------------------------
@@ -531,7 +524,7 @@ AABB::Value AABB::Area() const
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsVector3Inside(const Vector3 & point) const
int32_t AABB::IsVector3Inside(const Vector3 & point) const
{
return (point.x < min.x || point.x > max.x ||
point.y < min.y || point.y > max.y ||
@@ -539,7 +532,7 @@ Int32 AABB::IsVector3Inside(const Vector3 & point) const
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsVector3InsideEx(Value x, Value y, Value z) const
int32_t AABB::IsVector3InsideEx(Value x, Value y, Value z) const
{
return (x < min.x || x > max.x ||
y < min.y || y > max.y ||
@@ -547,7 +540,7 @@ Int32 AABB::IsVector3InsideEx(Value x, Value y, Value z) const
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsAABBInside(const AABB & box) const
int32_t AABB::IsAABBInside(const AABB & box) const
{
if (box.max.x < min.x || box.min.x > max.x ||
box.max.y < min.y || box.min.y > max.y ||
@@ -568,7 +561,7 @@ Int32 AABB::IsAABBInside(const AABB & box) const
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsAABBInsideEx(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) const
int32_t AABB::IsAABBInsideEx(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) const
{
if (xmax < min.x || xmin > max.x ||
ymax < min.y || ymin > max.y ||
@@ -589,7 +582,7 @@ Int32 AABB::IsAABBInsideEx(Value xmin, Value ymin, Value zmin, Value xmax, Value
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsAABBInsideFast(const AABB & box) const
int32_t AABB::IsAABBInsideFast(const AABB & box) const
{
if (box.max.x < min.x || box.min.x > max.x ||
box.max.y < min.y || box.min.y > max.y ||
@@ -604,7 +597,7 @@ Int32 AABB::IsAABBInsideFast(const AABB & box) const
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsAABBInsideFastEx(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) const
int32_t AABB::IsAABBInsideFastEx(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) const
{
if (xmax < min.x || xmin > max.x ||
ymax < min.y || ymin > max.y ||
@@ -619,7 +612,7 @@ Int32 AABB::IsAABBInsideFastEx(Value xmin, Value ymin, Value zmin, Value xmax, V
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsSphereInside(const Sphere & sphere) const
int32_t AABB::IsSphereInside(const Sphere & sphere) const
{
Value dist_squared = 0, temp;
const Vector3 & center = sphere.pos;
@@ -673,14 +666,14 @@ Int32 AABB::IsSphereInside(const Sphere & sphere) const
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsSphereInsideEx(Value x, Value y, Value z, Value r) const
int32_t AABB::IsSphereInsideEx(Value x, Value y, Value z, Value r) const
{
return IsSphereInside(Sphere(x, y, z, r));
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsSphereInsideFast(const Sphere & sphere) const
int32_t AABB::IsSphereInsideFast(const Sphere & sphere) const
{
Value dist_squared = 0, temp;
const Vector3& center = sphere.pos;
@@ -729,36 +722,22 @@ Int32 AABB::IsSphereInsideFast(const Sphere & sphere) const
}
// ------------------------------------------------------------------------------------------------
Int32 AABB::IsSphereInsideFastEx(Value x, Value y, Value z, Value r) const
int32_t AABB::IsSphereInsideFastEx(Value x, Value y, Value z, Value r) const
{
return IsSphereInsideFast(Sphere(x, y, z, r));
}
// ------------------------------------------------------------------------------------------------
LightObj AABB::Format(const String & spec, StackStrF & fmt) const
String AABB::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 6, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), min.x, min.y, min.z, max.x, max.y, max.z);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("min_x", min.x)
, fmt::arg("min_y", min.y)
, fmt::arg("min_z", min.z)
, fmt::arg("max_x", max.x)
, fmt::arg("max_y", max.y)
, fmt::arg("max_z", max.z)
);
}
// ------------------------------------------------------------------------------------------------
@@ -865,39 +844,6 @@ void Register_AABB(HSQUIRRELVM vm)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< AABB >)
.StaticFmtFunc(_SC("FromStr"), &AABB::Get)
.StaticFmtFunc(_SC("FromStrEx"), &AABB::GetEx)
// Operator Exposure
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opAddAssign"), &AABB::operator +=)
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opSubAssign"), &AABB::operator -=)
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opMulAssign"), &AABB::operator *=)
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opDivAssign"), &AABB::operator /=)
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opModAssign"), &AABB::operator %=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opAddAssignS"), &AABB::operator +=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opSubAssignS"), &AABB::operator -=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opMulAssignS"), &AABB::operator *=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opDivAssignS"), &AABB::operator /=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opModAssignS"), &AABB::operator %=)
.Func< AABB & (AABB::*)(void) >(_SC("opPreInc"), &AABB::operator ++)
.Func< AABB & (AABB::*)(void) >(_SC("opPreDec"), &AABB::operator --)
.Func< AABB (AABB::*)(int) >(_SC("opPostInc"), &AABB::operator ++)
.Func< AABB (AABB::*)(int) >(_SC("opPostDec"), &AABB::operator --)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opAdd"), &AABB::operator +)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opSub"), &AABB::operator -)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opMul"), &AABB::operator *)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opDiv"), &AABB::operator /)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opMod"), &AABB::operator %)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opAddS"), &AABB::operator +)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opSubS"), &AABB::operator -)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opMulS"), &AABB::operator *)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opDivS"), &AABB::operator /)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opModS"), &AABB::operator %)
.Func< AABB (AABB::*)(void) const >(_SC("opUnPlus"), &AABB::operator +)
.Func< AABB (AABB::*)(void) const >(_SC("opUnMinus"), &AABB::operator -)
.Func< bool (AABB::*)(const AABB &) const >(_SC("opEqual"), &AABB::operator ==)
.Func< bool (AABB::*)(const AABB &) const >(_SC("opNotEqual"), &AABB::operator !=)
.Func< bool (AABB::*)(const AABB &) const >(_SC("opLessThan"), &AABB::operator <)
.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 >=)
);
}
+30 -27
View File
@@ -3,6 +3,9 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Vector3.hpp"
// ------------------------------------------------------------------------------------------------
#include <cmath>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -31,12 +34,12 @@ struct AABB
/* --------------------------------------------------------------------------------------------
* The minimum and maximum components of this type.
*/
Vector3 min, max;
Vector3 min{HUGE_VALF}, max{-HUGE_VALF};
/* --------------------------------------------------------------------------------------------
* Construct with zero size.
*/
AABB() noexcept;
AABB() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct a an equally sized and perfectly shaped box from scalar values.
@@ -254,12 +257,12 @@ struct AABB
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const AABB & b) const;
SQMOD_NODISCARD int32_t Cmp(const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(AABB(s, s, s, s, s, s));
}
@@ -267,7 +270,7 @@ struct AABB
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
const auto v = static_cast< Value >(s);
return Cmp(AABB(v, v, v, v, v, v));
@@ -276,7 +279,7 @@ struct AABB
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
const auto v = static_cast< Value >(s);
return Cmp(AABB(v, v, v, v, v, v));
@@ -285,7 +288,7 @@ struct AABB
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
const auto v = static_cast< Value >(0);
return Cmp(AABB(v, v, v, v, v, v));
@@ -294,7 +297,7 @@ struct AABB
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set the values extracted from the specified string using the specified delimiter.
@@ -379,97 +382,97 @@ struct AABB
/* --------------------------------------------------------------------------------------------
* Check if the box is empty. This means that there is no space between the min and max edge.
*/
bool Empty() const;
SQMOD_NODISCARD bool Empty() const;
/* --------------------------------------------------------------------------------------------
* Return true if this bounding box is defined via a previous call to Define() or Merge().
*/
bool Defined() const;
SQMOD_NODISCARD bool Defined() const;
/* --------------------------------------------------------------------------------------------
* Return center.
*/
Vector3 Center() const;
SQMOD_NODISCARD Vector3 Center() const;
/* --------------------------------------------------------------------------------------------
* Get size/extent of the box (maximal distance of two points in the box).
*/
Vector3 Size() const;
SQMOD_NODISCARD Vector3 Size() const;
/* --------------------------------------------------------------------------------------------
* Return half-size.
*/
Vector3 HalfSize() const;
SQMOD_NODISCARD Vector3 HalfSize() const;
/* --------------------------------------------------------------------------------------------
* Get radius of the bounding sphere.
*/
Value Radius() const;
SQMOD_NODISCARD Value Radius() const;
/* --------------------------------------------------------------------------------------------
* Get the volume enclosed by the box in cubed units.
*/
Value Volume() const;
SQMOD_NODISCARD Value Volume() const;
/* --------------------------------------------------------------------------------------------
* Get the surface area of the box in squared units.
*/
Value Area() const;
SQMOD_NODISCARD Value Area() const;
/* --------------------------------------------------------------------------------------------
* Test if a point is inside.
*/
Int32 IsVector3Inside(const Vector3 & point) const;
SQMOD_NODISCARD int32_t IsVector3Inside(const Vector3 & point) const;
/* --------------------------------------------------------------------------------------------
* Test if a point is inside.
*/
Int32 IsVector3InsideEx(Value x, Value y, Value z) const;
SQMOD_NODISCARD int32_t IsVector3InsideEx(Value x, Value y, Value z) const;
/* --------------------------------------------------------------------------------------------
* Test if another bounding box is inside, outside or intersects.
*/
Int32 IsAABBInside(const AABB & box) const;
SQMOD_NODISCARD int32_t IsAABBInside(const AABB & box) const;
/* --------------------------------------------------------------------------------------------
* Test if another bounding box is inside, outside or intersects.
*/
Int32 IsAABBInsideEx(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) const;
SQMOD_NODISCARD int32_t IsAABBInsideEx(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) const;
/* --------------------------------------------------------------------------------------------
* Test if another bounding box is (partially) inside or outside.
*/
Int32 IsAABBInsideFast(const AABB & box) const;
SQMOD_NODISCARD int32_t IsAABBInsideFast(const AABB & box) const;
/* --------------------------------------------------------------------------------------------
* Test if another bounding box is (partially) inside or outside.
*/
Int32 IsAABBInsideFastEx(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) const;
SQMOD_NODISCARD int32_t IsAABBInsideFastEx(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) const;
/* --------------------------------------------------------------------------------------------
* Test if a sphere is inside, outside or intersects.
*/
Int32 IsSphereInside(const Sphere & sphere) const;
SQMOD_NODISCARD int32_t IsSphereInside(const Sphere & sphere) const;
/* --------------------------------------------------------------------------------------------
* Test if a sphere is inside, outside or intersects.
*/
Int32 IsSphereInsideEx(Value x, Value y, Value z, Value r) const;
SQMOD_NODISCARD int32_t IsSphereInsideEx(Value x, Value y, Value z, Value r) const;
/* --------------------------------------------------------------------------------------------
* Test if a sphere is (partially) inside or outside.
*/
Int32 IsSphereInsideFast(const Sphere & sphere) const;
SQMOD_NODISCARD int32_t IsSphereInsideFast(const Sphere & sphere) const;
/* --------------------------------------------------------------------------------------------
* Test if a sphere is (partially) inside or outside.
*/
Int32 IsSphereInsideFastEx(Value x, Value y, Value z, Value r) const;
SQMOD_NODISCARD int32_t IsSphereInsideFastEx(Value x, Value y, Value z, Value r) const;
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the AABB type from a string.
+20 -90
View File
@@ -1,18 +1,15 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Circle.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("Circle"))
SQMOD_DECL_TYPENAME(Typename, _SC("Circle"))
// ------------------------------------------------------------------------------------------------
const Circle Circle::NIL = Circle();
@@ -22,13 +19,6 @@ const Circle Circle::MAX = Circle(std::numeric_limits< Circle::Value >::max());
// ------------------------------------------------------------------------------------------------
SQChar Circle::Delim = ',';
// ------------------------------------------------------------------------------------------------
Circle::Circle() noexcept
: pos(0.0, 0.0), rad(0.0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Circle::Circle(Value rv) noexcept
: pos(0.0, 0.0), rad(rv)
@@ -100,7 +90,7 @@ Circle & Circle::operator /= (const Circle & c)
Circle & Circle::operator %= (const Circle & c)
{
pos %= c.pos;
rad = std::fmod(rad, c.rad);
rad = fmodf(rad, c.rad);
return *this;
}
@@ -136,7 +126,7 @@ Circle & Circle::operator /= (Value r)
// ------------------------------------------------------------------------------------------------
Circle & Circle::operator %= (Value r)
{
rad = std::fmod(rad, r);
rad = fmodf(rad, r);
return *this;
}
@@ -236,7 +226,7 @@ Circle Circle::operator / (const Circle & c) const
// ------------------------------------------------------------------------------------------------
Circle Circle::operator % (const Circle & c) const
{
return {pos % c.pos, std::fmod(rad, c.rad)};
return {pos % c.pos, fmodf(rad, c.rad)};
}
// ------------------------------------------------------------------------------------------------
@@ -266,7 +256,7 @@ Circle Circle::operator / (Value r) const
// ------------------------------------------------------------------------------------------------
Circle Circle::operator % (Value r) const
{
return {std::fmod(rad, r)};
return {fmodf(rad, r)};
}
// ------------------------------------------------------------------------------------------------
@@ -302,7 +292,7 @@ Circle Circle::operator % (const Vector2 & p) const
// ------------------------------------------------------------------------------------------------
Circle Circle::operator + () const
{
return {pos.Abs(), std::fabs(rad)};
return {pos.Abs(), fabsf(rad)};
}
// ------------------------------------------------------------------------------------------------
@@ -348,7 +338,7 @@ bool Circle::operator >= (const Circle & c) const
}
// ------------------------------------------------------------------------------------------------
Int32 Circle::Cmp(const Circle & o) const
int32_t Circle::Cmp(const Circle & o) const
{
if (*this == o)
{
@@ -365,9 +355,9 @@ Int32 Circle::Cmp(const Circle & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Circle::ToString() const
String Circle::ToString() const
{
return ToStrF("%f,%f,%f", pos.x, pos.y, rad);
return fmt::format("{},{},{}", pos.x, pos.y, rad);
}
// ------------------------------------------------------------------------------------------------
@@ -465,7 +455,7 @@ void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin
// ------------------------------------------------------------------------------------------------
Circle Circle::Abs() const
{
return {pos.Abs(), std::fabs(rad)};
return {pos.Abs(), fabsf(rad)};
}
// ------------------------------------------------------------------------------------------------
@@ -483,9 +473,9 @@ Array Circle::ToPointsArray(SQInteger num_segments) const
SQFloat theta = 2.0f * SQMOD_PI * static_cast< SQFloat >(i) / static_cast< SQFloat >(num_segments);
#endif // SQUSEDOUBLE
// Calculate the x component
SQFloat x = (rad * std::cos(theta)) + pos.x;
SQFloat x = (rad * cosf(theta)) + pos.x;
// Calculate the y component
SQFloat y = (rad * std::sin(theta)) + pos.y;
SQFloat y = (rad * sinf(theta)) + pos.y;
// Push the Vector2 instance on the stack
Var< Vector2 >::push(vm, Vector2{x, y});
// Insert the element on the stack into the array
@@ -496,30 +486,13 @@ Array Circle::ToPointsArray(SQInteger num_segments) const
}
// ------------------------------------------------------------------------------------------------
LightObj Circle::Format(const String & spec, StackStrF & fmt) const
String Circle::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 3, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), pos.x, pos.y, rad);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("x", pos.x)
, fmt::arg("y", pos.y)
, fmt::arg("r", rad)
);
}
// ------------------------------------------------------------------------------------------------
@@ -603,49 +576,6 @@ void Register_Circle(HSQUIRRELVM vm)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Circle >)
.StaticFmtFunc(_SC("FromStr"), &Circle::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Circle::GetEx)
// Operator Exposure
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opAddAssign"), &Circle::operator +=)
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opSubAssign"), &Circle::operator -=)
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opMulAssign"), &Circle::operator *=)
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opDivAssign"), &Circle::operator /=)
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opModAssign"), &Circle::operator %=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opAddAssignR"), &Circle::operator +=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opSubAssignR"), &Circle::operator -=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opMulAssignR"), &Circle::operator *=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opDivAssignR"), &Circle::operator /=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opModAssignR"), &Circle::operator %=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opAddAssignP"), &Circle::operator +=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opSubAssignP"), &Circle::operator -=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opMulAssignP"), &Circle::operator *=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opDivAssignP"), &Circle::operator /=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opModAssignP"), &Circle::operator %=)
.Func< Circle & (Circle::*)(void) >(_SC("opPreInc"), &Circle::operator ++)
.Func< Circle & (Circle::*)(void) >(_SC("opPreDec"), &Circle::operator --)
.Func< Circle (Circle::*)(int) >(_SC("opPostInc"), &Circle::operator ++)
.Func< Circle (Circle::*)(int) >(_SC("opPostDec"), &Circle::operator --)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opAdd"), &Circle::operator +)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opSub"), &Circle::operator -)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opMul"), &Circle::operator *)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opDiv"), &Circle::operator /)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opMod"), &Circle::operator %)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opAddR"), &Circle::operator +)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opSubR"), &Circle::operator -)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opMulR"), &Circle::operator *)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opDivR"), &Circle::operator /)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opModR"), &Circle::operator %)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opAddP"), &Circle::operator +)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opSubP"), &Circle::operator -)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opMulP"), &Circle::operator *)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opDivP"), &Circle::operator /)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opModP"), &Circle::operator %)
.Func< Circle (Circle::*)(void) const >(_SC("opUnPlus"), &Circle::operator +)
.Func< Circle (Circle::*)(void) const >(_SC("opUnMinus"), &Circle::operator -)
.Func< bool (Circle::*)(const Circle &) const >(_SC("opEqual"), &Circle::operator ==)
.Func< bool (Circle::*)(const Circle &) const >(_SC("opNotEqual"), &Circle::operator !=)
.Func< bool (Circle::*)(const Circle &) const >(_SC("opLessThan"), &Circle::operator <)
.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 >=)
);
}
+12 -13
View File
@@ -1,7 +1,6 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Vector2.hpp"
// ------------------------------------------------------------------------------------------------
@@ -32,13 +31,13 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* The position and radius components of this type.
*/
Vector2 pos;
Value rad;
Vector2 pos{};
Value rad{0};
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Circle() noexcept;
Circle() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct a circle at position 0,0 using the specified radius.
@@ -303,12 +302,12 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Circle & c) const;
SQMOD_NODISCARD int32_t Cmp(const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(Circle(static_cast< Value >(s)));
}
@@ -316,7 +315,7 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
return Cmp(Circle(static_cast< Value >(s)));
}
@@ -324,7 +323,7 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
return Cmp(Circle(static_cast< Value >(s)));
}
@@ -332,7 +331,7 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
return Cmp(Circle(static_cast< Value >(0)));
}
@@ -340,7 +339,7 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set the specified radius.
@@ -409,17 +408,17 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Circle Abs() const;
SQMOD_NODISCARD Circle Abs() const;
/* --------------------------------------------------------------------------------------------
* Transform this into an array of Vector2 points that form a circle.
*/
Array ToPointsArray(SQInteger num_segments) const;
SQMOD_NODISCARD Array ToPointsArray(SQInteger num_segments) const;
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
+24 -105
View File
@@ -1,19 +1,16 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Color3.hpp"
#include "Base/Color4.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("Color3"))
SQMOD_DECL_TYPENAME(Typename, _SC("Color3"))
// ------------------------------------------------------------------------------------------------
const Color3 Color3::NIL = Color3();
@@ -24,13 +21,6 @@ const Color3 Color3::MAX = Color3(std::numeric_limits< Color3::Value >::max());
SQChar Color3::Delim = ',';
bool Color3::UpperCaseHex = false;
// ------------------------------------------------------------------------------------------------
Color3::Color3() noexcept
: r(0), g(0), b(0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color3::Color3(Value sv) noexcept
: r(sv), g(sv), b(sv)
@@ -469,7 +459,7 @@ Color3::operator Color4 () const
}
// ------------------------------------------------------------------------------------------------
Int32 Color3::Cmp(const Color3 & o) const
int32_t Color3::Cmp(const Color3 & o) const
{
if (*this == o)
{
@@ -486,9 +476,9 @@ Int32 Color3::Cmp(const Color3 & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Color3::ToString() const
String Color3::ToString() const
{
return ToStrF("%u,%u,%u", r, g, b);
return fmt::format("{},{},{}", r, g, b);
}
// ------------------------------------------------------------------------------------------------
@@ -544,13 +534,13 @@ void Color3::SetName(StackStrF & name)
}
// ------------------------------------------------------------------------------------------------
Uint32 Color3::GetRGB() const
uint32_t Color3::GetRGB() const
{
return Uint32(r << 16u | g << 8u | b); // NOLINT(hicpp-signed-bitwise)
return uint32_t(r << 16u | g << 8u | b); // NOLINT(hicpp-signed-bitwise)
}
// ------------------------------------------------------------------------------------------------
void Color3::SetRGB(Uint32 p)
void Color3::SetRGB(uint32_t p)
{
r = static_cast< Value >((p >> 16u) & 0xFFu);
g = static_cast< Value >((p >> 8u) & 0xFFu);
@@ -558,13 +548,13 @@ void Color3::SetRGB(Uint32 p)
}
// ------------------------------------------------------------------------------------------------
Uint32 Color3::GetRGBA() const
uint32_t Color3::GetRGBA() const
{
return Uint32(r << 24u | g << 16u | b << 8u | 0u); // NOLINT(hicpp-signed-bitwise)
return (r << 24u | g << 16u | b << 8u | 0u); // NOLINT(hicpp-signed-bitwise)
}
// ------------------------------------------------------------------------------------------------
void Color3::SetRGBA(Uint32 p)
void Color3::SetRGBA(uint32_t p)
{
r = static_cast< Value >((p >> 24u) & 0xFFu);
g = static_cast< Value >((p >> 16u) & 0xFFu);
@@ -572,13 +562,13 @@ void Color3::SetRGBA(Uint32 p)
}
// ------------------------------------------------------------------------------------------------
Uint32 Color3::GetARGB() const
uint32_t Color3::GetARGB() const
{
return Uint32(0u << 24u | r << 16u | g << 8u | b); // NOLINT(hicpp-signed-bitwise)
return (0u << 24u | r << 16u | g << 8u | b); // NOLINT(hicpp-signed-bitwise)
}
// ------------------------------------------------------------------------------------------------
void Color3::SetARGB(Uint32 p)
void Color3::SetARGB(uint32_t p)
{
r = static_cast< Value >((p >> 16u) & 0xFFu);
g = static_cast< Value >((p >> 8u) & 0xFFu);
@@ -660,30 +650,13 @@ LightObj Color3::ToHex4() const
}
// ------------------------------------------------------------------------------------------------
LightObj Color3::Format(const String & spec, StackStrF & fmt) const
String Color3::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 3, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), r, g, b);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("r", r)
, fmt::arg("g", g)
, fmt::arg("b", b)
);
}
// ------------------------------------------------------------------------------------------------
@@ -697,8 +670,8 @@ const Color3 & Color3::GetEx(SQChar delim, StackStrF & str)
{
static Color3 col;
// The minimum and maximum values supported by the Color3 type
static constexpr Uint32 min = std::numeric_limits< Color3::Value >::min();
static constexpr Uint32 max = std::numeric_limits< Color3::Value >::max();
static constexpr uint32_t min = std::numeric_limits< Color3::Value >::min();
static constexpr uint32_t max = std::numeric_limits< Color3::Value >::max();
// Clear previous values, if any
col.Clear();
// Is the specified string empty?
@@ -712,7 +685,7 @@ const Color3 & Color3::GetEx(SQChar delim, StackStrF & str)
fs[4] = delim;
fs[9] = delim;
// The sscanf function requires at least 32 bit integers
Uint32 r = 0, g = 0, b = 0;
uint32_t r = 0, g = 0, b = 0;
// Attempt to extract the component values from the specified string
std::sscanf(str.mPtr, fs, &r, &g, &b);
// Cast the extracted integers to the value used by the Color3 type
@@ -798,60 +771,6 @@ void Register_Color3(HSQUIRRELVM vm)
.StaticFunc(_SC("SetUpperCaseHex"), &SqSetColor3UpperCaseHex)
.StaticFmtFunc(_SC("FromStr"), &Color3::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Color3::GetEx)
// Operator Exposure
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opAddAssign"), &Color3::operator +=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opSubAssign"), &Color3::operator -=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opMulAssign"), &Color3::operator *=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opDivAssign"), &Color3::operator /=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opModAssign"), &Color3::operator %=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opAndAssign"), &Color3::operator &=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opOrAssign"), &Color3::operator |=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opXorAssign"), &Color3::operator ^=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opShlAssign"), &Color3::operator <<=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opShrAssign"), &Color3::operator >>=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opAddAssignS"), &Color3::operator +=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opSubAssignS"), &Color3::operator -=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opMulAssignS"), &Color3::operator *=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opDivAssignS"), &Color3::operator /=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opModAssignS"), &Color3::operator %=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opAndAssignS"), &Color3::operator &=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opOrAssignS"), &Color3::operator |=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opXorAssignS"), &Color3::operator ^=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opShlAssignS"), &Color3::operator <<=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opShrAssignS"), &Color3::operator >>=)
.Func< Color3 & (Color3::*)(void) >(_SC("opPreInc"), &Color3::operator ++)
.Func< Color3 & (Color3::*)(void) >(_SC("opPreDec"), &Color3::operator --)
.Func< Color3 (Color3::*)(int) >(_SC("opPostInc"), &Color3::operator ++)
.Func< Color3 (Color3::*)(int) >(_SC("opPostDec"), &Color3::operator --)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opAdd"), &Color3::operator +)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opSub"), &Color3::operator -)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opMul"), &Color3::operator *)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opDiv"), &Color3::operator /)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opMod"), &Color3::operator %)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opAnd"), &Color3::operator &)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opOr"), &Color3::operator |)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opShl"), &Color3::operator ^)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opShl"), &Color3::operator <<)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opShr"), &Color3::operator >>)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opAddS"), &Color3::operator +)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opSubS"), &Color3::operator -)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opMulS"), &Color3::operator *)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opDivS"), &Color3::operator /)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opModS"), &Color3::operator %)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opAndS"), &Color3::operator &)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opOrS"), &Color3::operator |)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opShlS"), &Color3::operator ^)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opShlS"), &Color3::operator <<)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opShrS"), &Color3::operator >>)
.Func< Color3 (Color3::*)(void) const >(_SC("opUnPlus"), &Color3::operator +)
.Func< Color3 (Color3::*)(void) const >(_SC("opUnMinus"), &Color3::operator -)
.Func< Color3 (Color3::*)(void) const >(_SC("opCom"), &Color3::operator ~)
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opEqual"), &Color3::operator ==)
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opNotEqual"), &Color3::operator !=)
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opLessThan"), &Color3::operator <)
.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 >=)
);
}
+18 -18
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -36,12 +36,12 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* The red, green and blue components of this type.
*/
Value r, g, b;
Value r{0}, g{0}, b{0};
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Color3() noexcept;
Color3() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct a color with all components with the same specified color.
@@ -366,12 +366,12 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Color3 & c) const;
SQMOD_NODISCARD int32_t Cmp(const Color3 & c) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
return Cmp(Color3(static_cast< Value >(s)));
}
@@ -379,7 +379,7 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(Color3(static_cast< Value >(s)));
}
@@ -387,7 +387,7 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
return Cmp(Color3(static_cast< Value >(s)));
}
@@ -395,7 +395,7 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
return Cmp(Color3(static_cast< Value >(0)));
}
@@ -403,7 +403,7 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set all components to the specified scalar value.
@@ -443,32 +443,32 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* Get the component values packed inside an integer value.
*/
Uint32 GetRGB() const;
SQMOD_NODISCARD uint32_t GetRGB() const;
/* --------------------------------------------------------------------------------------------
* Set the component values wxtracted from an integer value.
*/
void SetRGB(Uint32 p);
void SetRGB(uint32_t p);
/* --------------------------------------------------------------------------------------------
* Get the component values packed inside an integer value.
*/
Uint32 GetRGBA() const;
SQMOD_NODISCARD uint32_t GetRGBA() const;
/* --------------------------------------------------------------------------------------------
* Set the component values wxtracted from an integer value.
*/
void SetRGBA(Uint32 p);
void SetRGBA(uint32_t p);
/* --------------------------------------------------------------------------------------------
* Get the component values packed inside an integer value.
*/
Uint32 GetARGB() const;
SQMOD_NODISCARD uint32_t GetARGB() const;
/* --------------------------------------------------------------------------------------------
* Set the component values wxtracted from an integer value.
*/
void SetARGB(Uint32 p);
void SetARGB(uint32_t p);
/* --------------------------------------------------------------------------------------------
* Generate random values for all components of this instance.
@@ -506,17 +506,17 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* Generate a 3 component hex color from the values in this instance.
*/
LightObj ToHex() const;
SQMOD_NODISCARD LightObj ToHex() const;
/* --------------------------------------------------------------------------------------------
* Generate a 4 component hex color from the values in this instance.
*/
LightObj ToHex4() const;
SQMOD_NODISCARD LightObj ToHex4() const;
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Color3 type from a string.
+25 -105
View File
@@ -1,19 +1,16 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Color4.hpp"
#include "Base/Color3.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("Color4"))
SQMOD_DECL_TYPENAME(Typename, _SC("Color4"))
// ------------------------------------------------------------------------------------------------
const Color4 Color4::NIL = Color4();
@@ -24,13 +21,6 @@ const Color4 Color4::MAX = Color4(std::numeric_limits< Color4::Value >::max());
SQChar Color4::Delim = ',';
bool Color4::UpperCaseHex = false;
// ------------------------------------------------------------------------------------------------
Color4::Color4() noexcept
: r(0), g(0), b(0), a(0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color4::Color4(Value sv) noexcept
: r(sv), g(sv), b(sv), a(0)
@@ -494,7 +484,7 @@ Color4::operator Color3 () const
}
// ------------------------------------------------------------------------------------------------
Int32 Color4::Cmp(const Color4 & o) const
int32_t Color4::Cmp(const Color4 & o) const
{
if (*this == o)
{
@@ -511,9 +501,9 @@ Int32 Color4::Cmp(const Color4 & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Color4::ToString() const
String Color4::ToString() const
{
return ToStrF("%u,%u,%u,%u", r, g, b, a);
return fmt::format("{},{},{},{}", r, g, b, a);
}
// ------------------------------------------------------------------------------------------------
@@ -573,13 +563,13 @@ void Color4::SetName(StackStrF & name)
}
// ------------------------------------------------------------------------------------------------
Uint32 Color4::GetRGB() const
uint32_t Color4::GetRGB() const
{
return Uint32(r << 16u | g << 8u | b); // NOLINT(hicpp-signed-bitwise)
return uint32_t(r << 16u | g << 8u | b); // NOLINT(hicpp-signed-bitwise)
}
// ------------------------------------------------------------------------------------------------
void Color4::SetRGB(Uint32 p)
void Color4::SetRGB(uint32_t p)
{
r = static_cast< Value >((p >> 16u) & 0xFFu);
g = static_cast< Value >((p >> 8u) & 0xFFu);
@@ -587,13 +577,13 @@ void Color4::SetRGB(Uint32 p)
}
// ------------------------------------------------------------------------------------------------
Uint32 Color4::GetRGBA() const
uint32_t Color4::GetRGBA() const
{
return Uint32(r << 24u | g << 16u | b << 8u | a); // NOLINT(hicpp-signed-bitwise)
return uint32_t(r << 24u | g << 16u | b << 8u | a); // NOLINT(hicpp-signed-bitwise)
}
// ------------------------------------------------------------------------------------------------
void Color4::SetRGBA(Uint32 p)
void Color4::SetRGBA(uint32_t p)
{
r = static_cast< Value >((p >> 24u) & 0xFFu);
g = static_cast< Value >((p >> 16u) & 0xFFu);
@@ -602,13 +592,13 @@ void Color4::SetRGBA(Uint32 p)
}
// ------------------------------------------------------------------------------------------------
Uint32 Color4::GetARGB() const
uint32_t Color4::GetARGB() const
{
return Uint32(a << 24u | r << 16u | g << 8u | b); // NOLINT(hicpp-signed-bitwise)
return uint32_t(a << 24u | r << 16u | g << 8u | b); // NOLINT(hicpp-signed-bitwise)
}
// ------------------------------------------------------------------------------------------------
void Color4::SetARGB(Uint32 p)
void Color4::SetARGB(uint32_t p)
{
a = static_cast< Value >((p >> 24u) & 0xFFu);
r = static_cast< Value >((p >> 16u) & 0xFFu);
@@ -695,30 +685,14 @@ LightObj Color4::ToHex3() const
}
// ------------------------------------------------------------------------------------------------
LightObj Color4::Format(const String & spec, StackStrF & fmt) const
String Color4::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 4, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), r, g, b, a);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("r", r)
, fmt::arg("g", g)
, fmt::arg("b", b)
, fmt::arg("a", a)
);
}
// ------------------------------------------------------------------------------------------------
@@ -732,8 +706,8 @@ const Color4 & Color4::GetEx(SQChar delim, StackStrF & str)
{
static Color4 col;
// The minimum and maximum values supported by the Color4 type
static constexpr Uint32 min = std::numeric_limits< Color4::Value >::min();
static constexpr Uint32 max = std::numeric_limits< Color4::Value >::max();
static constexpr uint32_t min = std::numeric_limits< Color4::Value >::min();
static constexpr uint32_t max = std::numeric_limits< Color4::Value >::max();
// Clear previous values, if any
col.Clear();
// Is the specified string empty?
@@ -748,7 +722,7 @@ const Color4 & Color4::GetEx(SQChar delim, StackStrF & str)
fs[9] = delim;
fs[14] = delim;
// The sscanf function requires at least 32 bit integers
Uint32 r = 0, g = 0, b = 0, a = 0;
uint32_t r = 0, g = 0, b = 0, a = 0;
// Attempt to extract the component values from the specified string
std::sscanf(str.mPtr, fs, &r, &g, &b, &a);
// Cast the extracted integers to the value used by the Color4 type
@@ -837,60 +811,6 @@ void Register_Color4(HSQUIRRELVM vm)
.StaticFunc(_SC("SetUpperCaseHex"), &SqSetColor4UpperCaseHex)
.StaticFmtFunc(_SC("FromStr"), &Color4::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Color4::GetEx)
// Operator Exposure
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opAddAssign"), &Color4::operator +=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opSubAssign"), &Color4::operator -=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opMulAssign"), &Color4::operator *=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opDivAssign"), &Color4::operator /=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opModAssign"), &Color4::operator %=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opAndAssign"), &Color4::operator &=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opOrAssign"), &Color4::operator |=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opXorAssign"), &Color4::operator ^=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opShlAssign"), &Color4::operator <<=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opShrAssign"), &Color4::operator >>=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opAddAssignS"), &Color4::operator +=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opSubAssignS"), &Color4::operator -=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opMulAssignS"), &Color4::operator *=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opDivAssignS"), &Color4::operator /=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opModAssignS"), &Color4::operator %=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opAndAssignS"), &Color4::operator &=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opOrAssignS"), &Color4::operator |=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opXorAssignS"), &Color4::operator ^=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opShlAssignS"), &Color4::operator <<=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opShrAssignS"), &Color4::operator >>=)
.Func< Color4 & (Color4::*)(void) >(_SC("opPreInc"), &Color4::operator ++)
.Func< Color4 & (Color4::*)(void) >(_SC("opPreDec"), &Color4::operator --)
.Func< Color4 (Color4::*)(int) >(_SC("opPostInc"), &Color4::operator ++)
.Func< Color4 (Color4::*)(int) >(_SC("opPostDec"), &Color4::operator --)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opAdd"), &Color4::operator +)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opSub"), &Color4::operator -)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opMul"), &Color4::operator *)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opDiv"), &Color4::operator /)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opMod"), &Color4::operator %)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opAnd"), &Color4::operator &)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opOr"), &Color4::operator |)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opShl"), &Color4::operator ^)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opShl"), &Color4::operator <<)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opShr"), &Color4::operator >>)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opAddS"), &Color4::operator +)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opSubS"), &Color4::operator -)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opMulS"), &Color4::operator *)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opDivS"), &Color4::operator /)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opModS"), &Color4::operator %)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opAndS"), &Color4::operator &)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opOrS"), &Color4::operator |)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opShlS"), &Color4::operator ^)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opShlS"), &Color4::operator <<)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opShrS"), &Color4::operator >>)
.Func< Color4 (Color4::*)(void) const >(_SC("opUnPlus"), &Color4::operator +)
.Func< Color4 (Color4::*)(void) const >(_SC("opUnMinus"), &Color4::operator -)
.Func< Color4 (Color4::*)(void) const >(_SC("opCom"), &Color4::operator ~)
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opEqual"), &Color4::operator ==)
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opNotEqual"), &Color4::operator !=)
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opLessThan"), &Color4::operator <)
.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 >=)
);
}
+18 -18
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -36,12 +36,12 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* The red, green and blue components of this type.
*/
Value r, g, b, a;
Value r{0}, g{0}, b{0}, a{0};
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Color4() noexcept;
Color4() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct a color with all components with the same specified color.
@@ -366,12 +366,12 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Color4 & c) const;
SQMOD_NODISCARD int32_t Cmp(const Color4 & c) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
return Cmp(Color4(static_cast< Value >(s)));
}
@@ -379,7 +379,7 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(Color4(static_cast< Value >(s)));
}
@@ -387,7 +387,7 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
return Cmp(Color4(static_cast< Value >(s)));
}
@@ -395,7 +395,7 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
return Cmp(Color4(static_cast< Value >(0)));
}
@@ -403,7 +403,7 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set all components to the specified scalar value.
@@ -443,32 +443,32 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* Get the component values packed inside an integer value.
*/
Uint32 GetRGB() const;
SQMOD_NODISCARD uint32_t GetRGB() const;
/* --------------------------------------------------------------------------------------------
* Set the component values wxtracted from an integer value.
*/
void SetRGB(Uint32 p);
void SetRGB(uint32_t p);
/* --------------------------------------------------------------------------------------------
* Get the component values packed inside an integer value.
*/
Uint32 GetRGBA() const;
SQMOD_NODISCARD uint32_t GetRGBA() const;
/* --------------------------------------------------------------------------------------------
* Set the component values wxtracted from an integer value.
*/
void SetRGBA(Uint32 p);
void SetRGBA(uint32_t p);
/* --------------------------------------------------------------------------------------------
* Get the component values packed inside an integer value.
*/
Uint32 GetARGB() const;
SQMOD_NODISCARD uint32_t GetARGB() const;
/* --------------------------------------------------------------------------------------------
* Set the component values wxtracted from an integer value.
*/
void SetARGB(Uint32 p);
void SetARGB(uint32_t p);
/* --------------------------------------------------------------------------------------------
* Generate random values for all components of this instance.
@@ -506,17 +506,17 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* Generate a 4 component hex color from the values in this instance.
*/
LightObj ToHex() const;
SQMOD_NODISCARD LightObj ToHex() const;
/* --------------------------------------------------------------------------------------------
* Generate a 3 component hex color from the values in this instance.
*/
LightObj ToHex3() const;
SQMOD_NODISCARD LightObj ToHex3() const;
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Color4 type from a string.
+9 -5
View File
@@ -1,5 +1,8 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -312,12 +315,12 @@ template < typename... Ts > struct SqDynArgImpl;
*/
template < > struct SqDynArgImpl< >
{
template < typename T > static Int32 Try(const T & /*val*/, HSQUIRRELVM vm)
template < typename T > static SQInteger Try(const T & /*val*/, HSQUIRRELVM vm)
{
const String tn1(SqTypeName(vm, 1));
const String tn2(SqTypeName(vm, 2));
return sq_throwerror(vm, ToStrF("Such operation is not possible between (%s) and (%s)",
tn1.c_str(), tn2.c_str()));
return sq_throwerrorf(vm, "Such operation is not possible between (%s) and (%s)",
tn1.c_str(), tn2.c_str());
}
};
@@ -326,7 +329,7 @@ template < > struct SqDynArgImpl< >
*/
template < typename U, typename... Ts > struct SqDynArgImpl< U, Ts... >
{
template < typename F > static Int32 Try(F & fn, HSQUIRRELVM vm)
template < typename F > static SQInteger Try(F & fn, HSQUIRRELVM vm)
{
typedef typename std::decay< U >::type ArgType;
// Can the stack value be used with the current type?
@@ -389,7 +392,7 @@ template < typename F, typename U, typename... Ts > SQInteger SqDynArgFwd(HSQUIR
{
return SqDynArgImpl< U, Ts... >::Try(fn, vm);
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
return sq_throwerror(vm, e.what());
}
@@ -397,6 +400,7 @@ template < typename F, typename U, typename... Ts > SQInteger SqDynArgFwd(HSQUIR
{
return sq_throwerror(vm, "Unknown error occurred during comparison");
}
SQ_UNREACHABLE
// We shouldn't really reach this point but something must be returned
return sq_throwerror(vm, "Operation encountered unknown behavior");
}
+55 -114
View File
@@ -2,14 +2,11 @@
#include "Base/Quaternion.hpp"
#include "Base/Vector3.hpp"
#include "Base/Vector4.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -17,7 +14,7 @@ namespace SqMod {
#define STOVAL(v) static_cast< Quaternion::Value >(v)
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("Quaternion"))
SQMOD_DECL_TYPENAME(Typename, _SC("Quaternion"))
// ------------------------------------------------------------------------------------------------
const Quaternion Quaternion::NIL(0);
@@ -28,13 +25,6 @@ const Quaternion Quaternion::IDENTITY(1.0, 0.0, 0.0, 0.0);
// ------------------------------------------------------------------------------------------------
SQChar Quaternion::Delim = ',';
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion() noexcept
: x(0.0), y(0.0), z(0.0), w(0.0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(Value sv) noexcept
: x(sv), y(sv), z(sv), w(sv)
@@ -129,10 +119,10 @@ Quaternion & Quaternion::operator /= (const Quaternion & q)
// ------------------------------------------------------------------------------------------------
Quaternion & Quaternion::operator %= (const Quaternion & q)
{
x = std::fmod(x, q.x);
y = std::fmod(y, q.y);
z = std::fmod(z, q.z);
w = std::fmod(w, q.w);
x = fmodf(x, q.x);
y = fmodf(y, q.y);
z = fmodf(z, q.z);
w = fmodf(w, q.w);
return *this;
}
@@ -179,10 +169,10 @@ Quaternion & Quaternion::operator /= (Value s)
// ------------------------------------------------------------------------------------------------
Quaternion & Quaternion::operator %= (Value s)
{
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
w = std::fmod(w, s);
x = fmodf(x, s);
y = fmodf(y, s);
z = fmodf(z, s);
w = fmodf(w, s);
return *this;
}
@@ -279,19 +269,19 @@ Quaternion Quaternion::operator / (Value s) const
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator % (const Quaternion & q) const
{
return {std::fmod(x, q.x), std::fmod(y, q.y), std::fmod(z, q.z), std::fmod(w, q.w)};
return {fmodf(x, q.x), fmodf(y, q.y), fmodf(z, q.z), fmodf(w, q.w)};
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator % (Value s) const
{
return {std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s)};
return {fmodf(x, s), fmodf(y, s), fmodf(z, s), fmodf(w, s)};
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator + () const
{
return {std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w)};
return {fabsf(x), fabsf(y), fabsf(z), fabsf(w)};
}
// ------------------------------------------------------------------------------------------------
@@ -337,7 +327,7 @@ bool Quaternion::operator >= (const Quaternion & q) const
}
// ------------------------------------------------------------------------------------------------
Int32 Quaternion::Cmp(const Quaternion & o) const
int32_t Quaternion::Cmp(const Quaternion & o) const
{
if (*this == o)
{
@@ -354,9 +344,9 @@ Int32 Quaternion::Cmp(const Quaternion & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Quaternion::ToString() const
String Quaternion::ToString() const
{
return ToStrF("%f,%f,%f,%f", x, y, z, w);
return fmt::format("{},{},{},{}", x, y, z, w);
}
// ------------------------------------------------------------------------------------------------
@@ -395,24 +385,24 @@ void Quaternion::SetVector3(const Vector3 & v)
// ------------------------------------------------------------------------------------------------
void Quaternion::SetVector3Ex(Value nx, Value ny, Value nz)
{
Float64 angle;
double angle;
angle = (nx * 0.5);
const Float64 sr = std::sin(angle);
const Float64 cr = std::cos(angle);
const double sr = sin(angle);
const double cr = cos(angle);
angle = (ny * 0.5);
const Float64 sp = std::sin(angle);
const Float64 cp = std::cos(angle);
const double sp = sin(angle);
const double cp = cos(angle);
angle = (nz * 0.5);
const Float64 sy = std::sin(angle);
const Float64 cy = std::cos(angle);
const double sy = sin(angle);
const double cy = cos(angle);
const Float64 cpcy = (cp * cy);
const Float64 spcy = (sp * cy);
const Float64 cpsy = (cp * sy);
const Float64 spsy = (sp * sy);
const double cpcy = (cp * cy);
const double spcy = (sp * cy);
const double cpsy = (cp * sy);
const double spsy = (sp * sy);
x = STOVAL(sr * cpcy - cr * spsy);
y = STOVAL(cr * spcy + sr * cpsy);
@@ -477,13 +467,13 @@ void Quaternion::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::Abs() const
{
return {std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w)};
return {fabsf(x), fabsf(y), fabsf(z), fabsf(w)};
}
// ------------------------------------------------------------------------------------------------
bool Quaternion::IsNaN() const
{
return std::isnan(w) || std::isnan(x) || std::isnan(y) || std::isnan(z);
return isnanf(w) || isnanf(x) || isnanf(y) || isnanf(z);
}
// ------------------------------------------------------------------------------------------------
@@ -511,7 +501,7 @@ void Quaternion::Normalize()
if (!EpsEq(len_squared, STOVAL(1.0)) && EpsGt(len_squared, STOVAL(0.0)))
{
const Value inv_len = STOVAL(1.0) / std::sqrt(len_squared);
const Value inv_len = STOVAL(1.0) / sqrtf(len_squared);
x *= inv_len;
y *= inv_len;
@@ -542,11 +532,11 @@ void Quaternion::FromAngleAxis(Value angle, const Vector3 & axis)
{
const Vector3 norm_axis = axis.Normalized();
angle *= SQMOD_DEGTORAD_2;
const Value sin_angle = std::sin(angle);
const Value sin_angle = sinf(angle);
x = norm_axis.x * sin_angle;
y = norm_axis.y * sin_angle;
z = norm_axis.z * sin_angle;
w = std::cos(angle);
w = cosf(angle);
}
// ------------------------------------------------------------------------------------------------
@@ -559,7 +549,7 @@ void Quaternion::FromRotationTo(const Vector3 & start, const Vector3 & end)
if (EpsGt(d, STOVAL(-1.0)))
{
const Vector3 c = norm_start.CrossProduct(norm_end);
const Value s = std::sqrt((STOVAL(1.0) + d) * STOVAL(2.0));
const Value s = sqrtf((STOVAL(1.0) + d) * STOVAL(2.0));
const Value inv_s = STOVAL(1.0) / s;
x = c.x * inv_s;
@@ -603,11 +593,11 @@ Quaternion Quaternion::Inverse() const
// ------------------------------------------------------------------------------------------------
Vector3 Quaternion::ToEuler() const
{
const Float64 sqw = (w * w);
const Float64 sqx = (x * x);
const Float64 sqy = (y * y);
const Float64 sqz = (z * z);
const Float64 test = 2.0 * ((y * w) - (x * z));
const double sqw = (w * w);
const double sqx = (x * x);
const double sqy = (y * y);
const double sqz = (z * z);
const double test = 2.0 * ((y * w) - (x * z));
if (EpsEq(test, 1.0))
{
@@ -617,7 +607,7 @@ Vector3 Quaternion::ToEuler() const
// attitude = rotation about y-axis
STOVAL(SQMOD_PI64 / 2.0),
// heading = rotation about z-axis
STOVAL(-2.0 * std::atan2(x, w))
STOVAL(-2.0 * atan2f(x, w))
};
}
else if (EpsEq(test, -1.0))
@@ -628,17 +618,17 @@ Vector3 Quaternion::ToEuler() const
// attitude = rotation about y-axis
STOVAL(SQMOD_PI64 / -2.0),
// heading = rotation about z-axis
STOVAL(2.0 * std::atan2(x, w))
STOVAL(2.0 * atan2f(x, w))
};
}
return {
// bank = rotation about x-axis
STOVAL(std::atan2(2.0 * ((y * z) + (x * w)), (-sqx - sqy + sqz + sqw))),
STOVAL(atan2(2.0 * ((y * z) + (x * w)), (-sqx - sqy + sqz + sqw))),
// attitude = rotation about y-axis
STOVAL(std::asin(Clamp(test, -1.0, 1.0))),
STOVAL(asin(Clamp(test, -1.0, 1.0))),
// heading = rotation about z-axis
STOVAL(std::atan2(2.0 * ((x * y) + (z * w)), (sqx - sqy - sqz + sqw)))
STOVAL(atan2(2.0 * ((x * y) + (z * w)), (sqx - sqy - sqz + sqw)))
};
}
@@ -672,15 +662,15 @@ Quaternion Quaternion::Slerp(Quaternion quat, Value t) const
quat = -quat;
}
const Value angle = std::acos(cos_angle);
Value sin_angle = std::sin(angle);
const Value angle = acosf(cos_angle);
Value sin_angle = sinf(angle);
Value t1, t2;
if (sin_angle > STOVAL(0.001))
{
Value inv_sin_angle = STOVAL(1.0) / sin_angle;
t1 = std::sin((STOVAL(1.0) - t) * angle) * inv_sin_angle;
t2 = std::sin(t * angle) * inv_sin_angle;
t1 = sinf((STOVAL(1.0) - t) * angle) * inv_sin_angle;
t2 = sinf(t * angle) * inv_sin_angle;
}
else
{
@@ -721,30 +711,14 @@ const Quaternion & Quaternion::Get(StackStrF & str)
}
// ------------------------------------------------------------------------------------------------
LightObj Quaternion::Format(const String & spec, StackStrF & fmt) const
String Quaternion::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 4, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), x, y, z, w);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("x", x)
, fmt::arg("y", y)
, fmt::arg("z", z)
, fmt::arg("w", w)
);
}
// ------------------------------------------------------------------------------------------------
@@ -839,39 +813,6 @@ void Register_Quaternion(HSQUIRRELVM vm)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Quaternion >)
.StaticFmtFunc(_SC("FromStr"), &Quaternion::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Quaternion::GetEx)
// Operator Exposure
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opAddAssign"), &Quaternion::operator +=)
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opSubAssign"), &Quaternion::operator -=)
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opMulAssign"), &Quaternion::operator *=)
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opDivAssign"), &Quaternion::operator /=)
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opModAssign"), &Quaternion::operator %=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opAddAssignS"), &Quaternion::operator +=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opSubAssignS"), &Quaternion::operator -=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opMulAssignS"), &Quaternion::operator *=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opDivAssignS"), &Quaternion::operator /=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opModAssignS"), &Quaternion::operator %=)
.Func< Quaternion & (Quaternion::*)(void) >(_SC("opPreInc"), &Quaternion::operator ++)
.Func< Quaternion & (Quaternion::*)(void) >(_SC("opPreDec"), &Quaternion::operator --)
.Func< Quaternion (Quaternion::*)(int) >(_SC("opPostInc"), &Quaternion::operator ++)
.Func< Quaternion (Quaternion::*)(int) >(_SC("opPostDec"), &Quaternion::operator --)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opAdd"), &Quaternion::operator +)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opSub"), &Quaternion::operator -)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opMul"), &Quaternion::operator *)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opDiv"), &Quaternion::operator /)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opMod"), &Quaternion::operator %)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opAddS"), &Quaternion::operator +)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opSubS"), &Quaternion::operator -)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opMulS"), &Quaternion::operator *)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opDivS"), &Quaternion::operator /)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opModS"), &Quaternion::operator %)
.Func< Quaternion (Quaternion::*)(void) const >(_SC("opUnPlus"), &Quaternion::operator +)
.Func< Quaternion (Quaternion::*)(void) const >(_SC("opUnMinus"), &Quaternion::operator -)
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opEqual"), &Quaternion::operator ==)
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opNotEqual"), &Quaternion::operator !=)
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opLessThan"), &Quaternion::operator <)
.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 >=)
);
}
+24 -24
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -32,12 +32,12 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* The x, y, z and w components of this type.
*/
Value x, y, z, w;
Value x{0}, y{0}, z{0}, w{0};
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Quaternion() noexcept;
Quaternion() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct from scalar value.
@@ -257,12 +257,12 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Quaternion & q) const;
SQMOD_NODISCARD int32_t Cmp(const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(Quaternion(static_cast< Value >(s)));
}
@@ -270,7 +270,7 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
return Cmp(Quaternion(static_cast< Value >(s)));
}
@@ -278,7 +278,7 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
return Cmp(Quaternion(static_cast< Value >(s)));
}
@@ -286,7 +286,7 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
return Cmp(Quaternion(static_cast< Value >(0)));
}
@@ -294,7 +294,7 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set all components to the specified scalar value.
@@ -357,27 +357,27 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Quaternion Abs() const;
SQMOD_NODISCARD Quaternion Abs() const;
/* --------------------------------------------------------------------------------------------
* Return whether is NaN.
*/
bool IsNaN() const;
SQMOD_NODISCARD bool IsNaN() const;
/* --------------------------------------------------------------------------------------------
* Return squared length.
*/
Value LengthSquared() const;
SQMOD_NODISCARD Value LengthSquared() const;
/* --------------------------------------------------------------------------------------------
* Calculate dot product.
*/
Value DotProduct(const Quaternion & quat) const;
SQMOD_NODISCARD Value DotProduct(const Quaternion & quat) const;
/* --------------------------------------------------------------------------------------------
* Return conjugate.
*/
Quaternion Conjugate() const;
SQMOD_NODISCARD Quaternion Conjugate() const;
/* --------------------------------------------------------------------------------------------
* Normalize to unit length.
@@ -387,7 +387,7 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* Return normalized to unit length.
*/
Quaternion Normalized() const;
SQMOD_NODISCARD Quaternion Normalized() const;
/* --------------------------------------------------------------------------------------------
* Define from an angle (in degrees) and axis.
@@ -402,47 +402,47 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* Return inverse.
*/
Quaternion Inverse() const;
SQMOD_NODISCARD Quaternion Inverse() const;
/* --------------------------------------------------------------------------------------------
* Return Euler angles in degrees.
*/
Vector3 ToEuler() const;
SQMOD_NODISCARD Vector3 ToEuler() const;
/* --------------------------------------------------------------------------------------------
* Return yaw angle in degrees.
*/
Value YawAngle() const;
SQMOD_NODISCARD Value YawAngle() const;
/* --------------------------------------------------------------------------------------------
* Return pitch angle in degrees.
*/
Value PitchAngle() const;
SQMOD_NODISCARD Value PitchAngle() const;
/* --------------------------------------------------------------------------------------------
* Return roll angle in degrees.
*/
Value RollAngle() const;
SQMOD_NODISCARD Value RollAngle() const;
/* --------------------------------------------------------------------------------------------
* Spherical interpolation with another quaternion.
*/
Quaternion Slerp(Quaternion quat, Value t) const;
SQMOD_NODISCARD Quaternion Slerp(Quaternion quat, Value t) const;
/* --------------------------------------------------------------------------------------------
* Normalized linear interpolation with another quaternion.
*/
Quaternion Nlerp(const Quaternion & quat, Value t) const;
SQMOD_NODISCARD Quaternion Nlerp(const Quaternion & quat, Value t) const;
/* --------------------------------------------------------------------------------------------
* Normalized linear interpolation with another quaternion.
*/
Quaternion NlerpEx(const Quaternion & quat, Value t, bool shortest_path) const;
SQMOD_NODISCARD Quaternion NlerpEx(const Quaternion & quat, Value t, bool shortest_path) const;
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
+21 -283
View File
@@ -1,19 +1,9 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Base/Buffer.hpp"
#include "Base/Color3.hpp"
#include "Library/Numeric/Random.hpp"
#include "Core/Utility.hpp"
#include "Library/String.hpp"
// ------------------------------------------------------------------------------------------------
#include <cerrno>
#include <cstring>
#include <cstdarg>
// ------------------------------------------------------------------------------------------------
#ifdef SQMOD_OS_WINDOWS
#include <windows.h>
#endif // SQMOD_OS_WINDOWS
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -163,114 +153,6 @@ static const Color3 SQ_Color_List[] =
Color3(154, 205, 50)
};
// ------------------------------------------------------------------------------------------------
bool NameFilterCheck(CSStr filter, CSStr name)
{
// If only one of them is null then they don't match
if ((!filter && name) || (filter && !name))
{
return false;
}
// If they're both null or the filter is empty then there's nothing to check for
else if ((!filter && !name) || (*filter == '\0'))
{
return true;
}
SQChar ch = 0;
// Start comparing the strings
while (true)
{
// Grab the current character from filter
ch = *(filter++);
// See if the filter or name was completed
if (ch == '\0' || *name == '\0')
{
break; // They matched so far
}
// Are we supposed to perform a wild-card search?
else if (ch == '*')
{
// Grab the next character from filter
ch = *(filter++);
// Start comparing characters until the first match
while (*name != '\0')
{
if (*(name++) == ch)
{
break;
}
}
}
// See if the character matches doesn't have to match
else if (ch != '?' && *name != ch)
{
return false; // The character had to match and failed
}
else
{
++name;
}
}
// At this point the name satisfied the filter
return true;
}
// ------------------------------------------------------------------------------------------------
bool NameFilterCheckInsensitive(CSStr filter, CSStr name)
{
// If only one of them is null then they don't match
if ((!filter && name) || (filter && !name))
{
return false;
}
// If they're both null or the filter is empty then there's nothing to check for
else if ((!filter && !name) || (*filter == '\0'))
{
return true;
}
SQChar ch = 0;
// Start comparing the strings
while (true)
{
// Grab the current character from filter
ch = static_cast< SQChar >(std::tolower(*(filter++)));
// See if the filter or name was completed
if (ch == '\0' || *name == '\0')
{
break; // They matched so far
}
// Are we supposed to perform a wild-card search?
else if (ch == '*')
{
// Grab the next character from filter
ch = static_cast< SQChar >(std::tolower(*(filter++)));
// Start comparing characters until the first match
while (*name != '\0')
{
if (static_cast< SQChar >(std::tolower(*(name++))) == ch)
{
break;
}
}
}
// See if the character matches doesn't have to match
else if (ch != '?' && static_cast< SQChar >(std::tolower(*name)) != ch)
{
return false; // The character had to match and failed
}
else
{
++name;
}
}
// At this point the name satisfied the filter
return true;
}
// ------------------------------------------------------------------------------------------------
const Color3 & GetRandomColor()
{
@@ -284,7 +166,7 @@ Color3 GetColor(StackStrF & name)
}
// ------------------------------------------------------------------------------------------------
Color3 GetColorStr(CSStr name)
Color3 GetColorStr(const SQChar * name)
{
// See if we actually have something to search for
if(!name || *name == '\0')
@@ -292,7 +174,7 @@ Color3 GetColorStr(CSStr name)
return Color3::NIL; // Use default color
}
// Clone the string into an editable version
CSStr str = StrJustAlphaNum(name);
const SQChar * str = StrJustAlphaNum(name);
str = StrToLowercase(str);
// See if we still have a valid name after the cleanup
if(!str || *str == '\0')
@@ -300,7 +182,7 @@ Color3 GetColorStr(CSStr name)
return Color3::NIL; // Use default color
}
// Calculate the name length
const Uint32 len = std::strlen(str);
const size_t 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
@@ -889,186 +771,42 @@ Color3 GetColorStr(CSStr name)
}
}
// ------------------------------------------------------------------------------------------------
bool BuildFormatString(String & out, StackStrF & fmt, Uint32 arg, const String & spec)
{
// Is the specified string empty?
if (fmt.mLen <= 0)
{
return false; // Nothing to parse
}
// Backup current string size so we can revert back if anything
const size_t size = out.size();
// Number of processed arguments
Uint32 count = 0;
// Attempt to predict the required space
out.reserve(size + static_cast< size_t >(fmt.mLen) + arg * 2);
// Previously processed characters and the current one
SQChar p2, p1=0, c=0;
// Look for the value specifier in the specified string
for (SQInteger i = 0; i <= fmt.mLen; ++i) {
// Advance to the peaked character
p2 = p1, p1 = c, c = fmt.mPtr[i];
// The escape character is literal?
if (p1 == '\\' && p2 == '\\')
{
out.push_back('\\');
// Safeguard against a sequence of escape characters
p1 = 0;
}
// The marker is literal?
if (p1 == '\\' && c == '$')
{
out.push_back('$');
}
// Is this a marker?
else if (c == '$') {
// Did we run out of allowed arguments?
if (count++ < arg) {
out.append(spec); // Append the format specifier to the string
} else {
// Discard everything so far
out.resize(size);
// Signal failure
SqThrowF("Requested (%u) values but only (%u) available", count, arg);
}
} else if (c != '\\') {
// Append the current character to the string
out.push_back(c);
}
}
// Parsed successfully
return true;
}
// ------------------------------------------------------------------------------------------------
size_t PrintToStrF(String & out, CSStr str, ...)
{
// Initialize the variable argument list
va_list args;
va_start(args, str);
// Forward to the actual implementation
const size_t r = PrintToStrFv(out, str, args);
// Finalize the variable argument list
va_end(args);
// Return result
return r;
}
// ------------------------------------------------------------------------------------------------
size_t PrintToStrFv(String & out, CSStr str, va_list vl)
{
va_list args;
// Backup original size to revert back if necessary
const size_t size = out.size();
// The estimated buffer required
ssize_t len = 256;
begin:
// Do not modify the original va_list
va_copy(args, vl);
// Reserve the necessary space
out.resize(size + static_cast< size_t >(len), '\0');
// Attempt to generate the specified string
int res = std::vsnprintf(&out[0] + size, len, str, args);
// Do we need more space?
if (res >= len)
{
// Adjust to required size
len = res + 1;
// Try again
goto begin;
}
// Did the format failed?
else if (res < 0)
{
// Discard changes
out.resize(size);
}
else
{
// Discard extra characters
out.resize(size + static_cast< size_t >(res));
}
// Return the amount of written characters
return static_cast< size_t >(res);
}
// ------------------------------------------------------------------------------------------------
void SqThrowLastF(CSStr msg, ...)
{
// Acquire a moderately sized buffer
Buffer b(128);
// Prepare the arguments list
va_list args;
va_start (args, msg);
// Attempt to run the specified format
if (b.WriteF(0, msg, args) == 0)
{
b.At(0) = '\0'; // Make sure the string is null terminated
}
// Finalize the argument list
va_end(args);
#ifdef SQMOD_OS_WINDOWS
// Get the error message, if any.
const DWORD error_num = ::GetLastError();
// Was there an error recorded?
if(error_num == 0)
{
// Invoker is responsible for making sure this doesn't happen!
SqThrowF("%s [Unknown error]", b.Data());
}
// The resulted message buffer
LPSTR msg_buff = nullptr;
// Attempt to obtain the error message
const std::size_t size = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, // NOLINT(hicpp-signed-bitwise)
nullptr, error_num, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // NOLINT(hicpp-signed-bitwise)
reinterpret_cast< LPSTR >(&msg_buff), 0, nullptr);
// Copy the message buffer before freeing it
std::string message(msg_buff, size);
//Free the message buffer
LocalFree(msg_buff);
// Now it's safe to throw the error
SqThrowF("%s [%s]", b.Data(), message.c_str());
#else
SqThrowF("%s [%s]", b.Data(), std::strerror(errno));
#endif // SQMOD_OS_WINDOWS
}
// ------------------------------------------------------------------------------------------------
static SQInteger SqPackRGB(SQInteger r, SQInteger g, SQInteger b)
{
return static_cast< Int32 >(SQMOD_PACK_RGB(
ConvTo< Uint8 >::From(r), // NOLINT(hicpp-signed-bitwise)
ConvTo< Uint8 >::From(g),
ConvTo< Uint8 >::From(b)
return static_cast< int32_t >(SQMOD_PACK_RGB(
ConvTo< uint8_t >::From(r), // NOLINT(hicpp-signed-bitwise)
ConvTo< uint8_t >::From(g),
ConvTo< uint8_t >::From(b)
));
}
// ------------------------------------------------------------------------------------------------
static SQInteger SqPackRGBA(SQInteger r, SQInteger g, SQInteger b, SQInteger a)
{
return static_cast< Int32 >(SQMOD_PACK_RGBA(
ConvTo< Uint8 >::From(r), // NOLINT(hicpp-signed-bitwise)
ConvTo< Uint8 >::From(g),
ConvTo< Uint8 >::From(b),
ConvTo< Uint8 >::From(a)
return static_cast< int32_t >(SQMOD_PACK_RGBA(
ConvTo< uint8_t >::From(r), // NOLINT(hicpp-signed-bitwise)
ConvTo< uint8_t >::From(g),
ConvTo< uint8_t >::From(b),
ConvTo< uint8_t >::From(a)
));
}
// ------------------------------------------------------------------------------------------------
static SQInteger SqPackARGB(SQInteger r, SQInteger g, SQInteger b, SQInteger a)
{
return static_cast< Int32 >(SQMOD_PACK_ARGB(
ConvTo< Uint8 >::From(a), // NOLINT(hicpp-signed-bitwise)
ConvTo< Uint8 >::From(r),
ConvTo< Uint8 >::From(g),
ConvTo< Uint8 >::From(b)
return static_cast< int32_t >(SQMOD_PACK_ARGB(
ConvTo< uint8_t >::From(a), // NOLINT(hicpp-signed-bitwise)
ConvTo< uint8_t >::From(r),
ConvTo< uint8_t >::From(g),
ConvTo< uint8_t >::From(b)
));
}
// ------------------------------------------------------------------------------------------------
static SQInteger SqNameFilterCheck(HSQUIRRELVM vm)
{
const Int32 top = sq_gettop(vm);
const int32_t top = sq_gettop(vm);
// Was the filter string specified?
if (top <= 1)
{
@@ -1102,7 +840,7 @@ static SQInteger SqNameFilterCheck(HSQUIRRELVM vm)
// ------------------------------------------------------------------------------------------------
static SQInteger SqNameFilterCheckInsensitive(HSQUIRRELVM vm)
{
const Int32 top = sq_gettop(vm);
const int32_t top = sq_gettop(vm);
// Was the filter string specified?
if (top <= 1)
{
+16 -149
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Utility.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -9,23 +9,23 @@ namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Helper constants used by the bas types.
*/
static constexpr Float32 SQMOD_PI = 3.14159265358979323846264338327950288f;
static constexpr Float64 SQMOD_PI64 = 3.1415926535897932384626433832795028841971693993751d;
static constexpr float SQMOD_PI = 3.14159265358979323846264338327950288f;
static constexpr double SQMOD_PI64 = 3.1415926535897932384626433832795028841971693993751;
static constexpr Float32 SQMOD_RECIPROCAL_PI = (1.0f / SQMOD_PI);
static constexpr Float64 SQMOD_RECIPROCAL_PI64 = 1.0 / SQMOD_PI64;
static constexpr float SQMOD_RECIPROCAL_PI = (1.0f / SQMOD_PI);
static constexpr double SQMOD_RECIPROCAL_PI64 = (1.0 / SQMOD_PI64);
static constexpr Float32 SQMOD_HALF_PI = (SQMOD_PI * 0.5f);
static constexpr Float32 SQMOD_HALF_PI64 = (SQMOD_PI64 * 0.5);
static constexpr float SQMOD_HALF_PI = (SQMOD_PI * 0.5f);
static constexpr double SQMOD_HALF_PI64 = (SQMOD_PI64 * 0.5);
static constexpr Float32 SQMOD_DEGTORAD = SQMOD_PI / 180.0f;
static constexpr Float64 SQMOD_DEGTORAD64 = SQMOD_PI64 / 180.0;
static constexpr float SQMOD_DEGTORAD = SQMOD_PI / 180.0f;
static constexpr double SQMOD_DEGTORAD64 = SQMOD_PI64 / 180.0;
static constexpr Float32 SQMOD_DEGTORAD_2 = SQMOD_PI / 360.0f; // M_DEGTORAD / 2.f
static constexpr Float64 SQMOD_DEGTORAD64_2 = SQMOD_PI64 / 360.0; // M_DEGTORAD / 2.f
static constexpr float SQMOD_DEGTORAD_2 = SQMOD_PI / 360.0f; // M_DEGTORAD / 2.f
static constexpr double SQMOD_DEGTORAD64_2 = SQMOD_PI64 / 360.0; // M_DEGTORAD / 2.f
static constexpr Float32 SQMOD_RADTODEG = 1.0f / SQMOD_DEGTORAD;
static constexpr Float64 SQMOD_RADTODEG64 = 1.0 / SQMOD_DEGTORAD64;
static constexpr float SQMOD_RADTODEG = 1.0f / SQMOD_DEGTORAD;
static constexpr double SQMOD_RADTODEG64 = 1.0 / SQMOD_DEGTORAD64;
/* ------------------------------------------------------------------------------------------------
* Intersection test result.
@@ -37,152 +37,19 @@ enum Intersection
SQMODI_INSIDE,
};
/* ------------------------------------------------------------------------------------------------
* Helper used to reference and keep track of signal instances.
*/
typedef std::pair< Signal *, LightObj > SignalPair;
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary logging functions.
*/
extern void LogDbg(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogUsr(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogScs(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogInf(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogWrn(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogErr(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogFtl(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary logging functions.
*/
extern void LogSDbg(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSUsr(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSScs(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSInf(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSWrn(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSErr(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSFtl(CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary logging functions.
*/
extern void LogDbgV(CCStr fmt, va_list vlist);
extern void LogUsrV(CCStr fmt, va_list vlist);
extern void LogScsV(CCStr fmt, va_list vlist);
extern void LogInfV(CCStr fmt, va_list vlist);
extern void LogWrnV(CCStr fmt, va_list vlist);
extern void LogErrV(CCStr fmt, va_list vlist);
extern void LogFtlV(CCStr fmt, va_list vlist);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary logging functions.
*/
extern void LogSDbgV(CCStr fmt, va_list vlist);
extern void LogSUsrV(CCStr fmt, va_list vlist);
extern void LogSScsV(CCStr fmt, va_list vlist);
extern void LogSInfV(CCStr fmt, va_list vlist);
extern void LogSWrnV(CCStr fmt, va_list vlist);
extern void LogSErrV(CCStr fmt, va_list vlist);
extern void LogSFtlV(CCStr fmt, va_list vlist);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary conditional logging functions.
*/
extern bool cLogDbg(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogUsr(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogScs(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogInf(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogWrn(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogErr(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogFtl(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary conditional logging functions.
*/
extern bool cLogSDbg(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSUsr(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSScs(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSInf(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSWrn(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSErr(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSFtl(bool exp, CCStr fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
/* ------------------------------------------------------------------------------------------------
* Initialize a signal instance into the specified pair.
*/
extern void InitSignalPair(SignalPair & sp, LightObj & et, const char * name);
/* ------------------------------------------------------------------------------------------------
* Reset/release the specified signal pair.
*/
extern void ResetSignalPair(SignalPair & sp, bool clear = true);
/* ------------------------------------------------------------------------------------------------
* A simple implementation of name filtering.
*/
bool NameFilterCheck(CSStr filter, CSStr name);
/* ------------------------------------------------------------------------------------------------
* A simple implementation of name filtering without case sensitivity.
*/
bool NameFilterCheckInsensitive(CSStr filter, CSStr name);
/* ------------------------------------------------------------------------------------------------
* Obtain a randomly chosen color from a list of known colors.
*/
const Color3 & GetRandomColor();
SQMOD_NODISCARD const Color3 & GetRandomColor();
/* ------------------------------------------------------------------------------------------------
* Attempt to identify the color in the specified name and return it.
*/
Color3 GetColorStr(CSStr name);
SQMOD_NODISCARD Color3 GetColorStr(const SQChar * name);
/* ------------------------------------------------------------------------------------------------
* Attempt to identify the color in the specified name and return it.
*/
Color3 GetColor(StackStrF & name);
/* ------------------------------------------------------------------------------------------------
* Throw the last system error as an exception.
*/
void SqThrowLastF(CSStr msg, ...);
/* ------------------------------------------------------------------------------------------------
* Retrieve the string delimiter of a base type.
*/
template < typename T > inline SQInteger SqGetDelimiter()
{
return T::Delim;
}
/* ------------------------------------------------------------------------------------------------
* Modify the string delimiter of a base type.
*/
template < typename T > inline void SqSetDelimiter(SQInteger c)
{
T::Delim = ConvTo< SQChar >::From(c);
}
/* ------------------------------------------------------------------------------------------------
* Used internally to build format strings for math types.
*/
bool BuildFormatString(String & out, StackStrF & fmt, Uint32 arg, const String & spec);
/* ------------------------------------------------------------------------------------------------
* Append a formatted string to a string container.
*/
size_t PrintToStrF(String & out, CSStr str, ...);
/* ------------------------------------------------------------------------------------------------
* Append a formatted string to a string container.
*/
size_t PrintToStrFv(String & out, CSStr str, va_list vl);
SQMOD_NODISCARD Color3 GetColor(StackStrF & name);
} // Namespace:: SqMod
+19 -88
View File
@@ -1,18 +1,15 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Sphere.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("Sphere"))
SQMOD_DECL_TYPENAME(Typename, _SC("Sphere"))
// ------------------------------------------------------------------------------------------------
const Sphere Sphere::NIL = Sphere();
@@ -22,13 +19,6 @@ const Sphere Sphere::MAX = Sphere(std::numeric_limits< Sphere::Value >::max());
// ------------------------------------------------------------------------------------------------
SQChar Sphere::Delim = ',';
// ------------------------------------------------------------------------------------------------
Sphere::Sphere() noexcept
: pos(0.0), rad(0.0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Sphere::Sphere(Value rv) noexcept
: pos(0.0), rad(rv)
@@ -100,7 +90,7 @@ Sphere & Sphere::operator /= (const Sphere & s)
Sphere & Sphere::operator %= (const Sphere & s)
{
pos %= s.pos;
rad = std::fmod(rad, s.rad);
rad = fmodf(rad, s.rad);
return *this;
}
@@ -136,7 +126,7 @@ Sphere & Sphere::operator /= (Value r)
// ------------------------------------------------------------------------------------------------
Sphere & Sphere::operator %= (Value r)
{
rad = std::fmod(rad, r);
rad = fmodf(rad, r);
return *this;
}
@@ -236,7 +226,7 @@ Sphere Sphere::operator / (const Sphere & s) const
// ------------------------------------------------------------------------------------------------
Sphere Sphere::operator % (const Sphere & s) const
{
return {pos % s.pos, std::fmod(rad, s.rad)};
return {pos % s.pos, fmodf(rad, s.rad)};
}
// ------------------------------------------------------------------------------------------------
@@ -266,7 +256,7 @@ Sphere Sphere::operator / (Value r) const
// ------------------------------------------------------------------------------------------------
Sphere Sphere::operator % (Value r) const
{
return {std::fmod(rad, r)};
return {fmodf(rad, r)};
}
// ------------------------------------------------------------------------------------------------
@@ -302,7 +292,7 @@ Sphere Sphere::operator % (const Vector3 & p) const
// ------------------------------------------------------------------------------------------------
Sphere Sphere::operator + () const
{
return {pos.Abs(), std::fabs(rad)};
return {pos.Abs(), fabsf(rad)};
}
// ------------------------------------------------------------------------------------------------
@@ -348,7 +338,7 @@ bool Sphere::operator >= (const Sphere & s) const
}
// ------------------------------------------------------------------------------------------------
Int32 Sphere::Cmp(const Sphere & o) const
int32_t Sphere::Cmp(const Sphere & o) const
{
if (*this == o)
{
@@ -365,9 +355,9 @@ Int32 Sphere::Cmp(const Sphere & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Sphere::ToString() const
String Sphere::ToString() const
{
return ToStrF("%f,%f,%f,%f", pos.x, pos.y, pos.z, rad);
return fmt::format("{},{},{},{}", pos.x, pos.y, pos.z, rad);
}
// ------------------------------------------------------------------------------------------------
@@ -465,34 +455,18 @@ void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin
// ------------------------------------------------------------------------------------------------
Sphere Sphere::Abs() const
{
return {pos.Abs(), std::fabs(rad)};
return {pos.Abs(), fabsf(rad)};
}
// ------------------------------------------------------------------------------------------------
LightObj Sphere::Format(const String & spec, StackStrF & fmt) const
String Sphere::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 4, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), pos.x, pos.y, pos.z, rad);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("x", pos.x)
, fmt::arg("y", pos.y)
, fmt::arg("z", pos.z)
, fmt::arg("r", rad)
);
}
// ------------------------------------------------------------------------------------------------
@@ -574,49 +548,6 @@ void Register_Sphere(HSQUIRRELVM vm)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Sphere >)
.StaticFmtFunc(_SC("FromStr"), &Sphere::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Sphere::GetEx)
// Operator Exposure
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opAddAssign"), &Sphere::operator +=)
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opSubAssign"), &Sphere::operator -=)
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opMulAssign"), &Sphere::operator *=)
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opDivAssign"), &Sphere::operator /=)
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opModAssign"), &Sphere::operator %=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opAddAssignR"), &Sphere::operator +=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opSubAssignR"), &Sphere::operator -=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opMulAssignR"), &Sphere::operator *=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opDivAssignR"), &Sphere::operator /=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opModAssignR"), &Sphere::operator %=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opAddAssignP"), &Sphere::operator +=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opSubAssignP"), &Sphere::operator -=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opMulAssignP"), &Sphere::operator *=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opDivAssignP"), &Sphere::operator /=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opModAssignP"), &Sphere::operator %=)
.Func< Sphere & (Sphere::*)(void) >(_SC("opPreInc"), &Sphere::operator ++)
.Func< Sphere & (Sphere::*)(void) >(_SC("opPreDec"), &Sphere::operator --)
.Func< Sphere (Sphere::*)(int) >(_SC("opPostInc"), &Sphere::operator ++)
.Func< Sphere (Sphere::*)(int) >(_SC("opPostDec"), &Sphere::operator --)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opAdd"), &Sphere::operator +)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opSub"), &Sphere::operator -)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opMul"), &Sphere::operator *)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opDiv"), &Sphere::operator /)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opMod"), &Sphere::operator %)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opAddR"), &Sphere::operator +)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opSubR"), &Sphere::operator -)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opMulR"), &Sphere::operator *)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opDivR"), &Sphere::operator /)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opModR"), &Sphere::operator %)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opAddP"), &Sphere::operator +)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opSubP"), &Sphere::operator -)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opMulP"), &Sphere::operator *)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opDivP"), &Sphere::operator /)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opModP"), &Sphere::operator %)
.Func< Sphere (Sphere::*)(void) const >(_SC("opUnPlus"), &Sphere::operator +)
.Func< Sphere (Sphere::*)(void) const >(_SC("opUnMinus"), &Sphere::operator -)
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opEqual"), &Sphere::operator ==)
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opNotEqual"), &Sphere::operator !=)
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opLessThan"), &Sphere::operator <)
.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 >=)
);
}
+11 -12
View File
@@ -1,7 +1,6 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Vector3.hpp"
// ------------------------------------------------------------------------------------------------
@@ -32,13 +31,13 @@ struct Sphere
/* --------------------------------------------------------------------------------------------
* The position and radius components of this type.
*/
Vector3 pos;
Value rad;
Vector3 pos{};
Value rad{0};
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Sphere() noexcept;
Sphere() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct a sphere at position 0,0,0 using the specified radius.
@@ -303,12 +302,12 @@ struct Sphere
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Sphere & s) const;
SQMOD_NODISCARD int32_t Cmp(const Sphere & s) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(Sphere(static_cast< Value >(s)));
}
@@ -316,7 +315,7 @@ struct Sphere
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
return Cmp(Sphere(static_cast< Value >(s)));
}
@@ -324,7 +323,7 @@ struct Sphere
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
return Cmp(Sphere(static_cast< Value >(s)));
}
@@ -332,7 +331,7 @@ struct Sphere
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
return Cmp(Sphere(static_cast< Value >(0)));
}
@@ -340,7 +339,7 @@ struct Sphere
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set the specified radius.
@@ -408,12 +407,12 @@ struct Sphere
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Sphere Abs() const;
SQMOD_NODISCARD Sphere Abs() const;
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string.
-194
View File
@@ -1,194 +0,0 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <type_traits>
/* ------------------------------------------------------------------------------------------------
* Hybrid associative container combining the performance of a vector and usefulness of a map container.
*/
template < class Key, class T, class Pred = std::equal_to< Key > > struct VecMap
{
// --------------------------------------------------------------------------------------------
using key_type = Key;
using mapped_type = T;
using value_type = std::pair< Key, T >;
using storage_type = std::vector< value_type >;
using key_equal = Pred;
using pointer = typename storage_type::pointer;
using const_pointer = typename storage_type::const_pointer;
using reference = typename storage_type::reference;
using const_reference = typename storage_type::const_reference;
using size_type = typename storage_type::size_type;
using difference_type = typename storage_type::difference_type;
using iterator = typename storage_type::iterator;
using const_iterator = typename storage_type::const_iterator;
using insert_return_type = std::pair< iterator, pointer >;
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
VecMap() noexcept(noexcept(storage_type())) = default;
/* --------------------------------------------------------------------------------------------
* Copy constructor. Does exactly what you expect it to do.
*/
VecMap(const VecMap & o)
: m_Storage(o.m_Storage)
{
}
/* --------------------------------------------------------------------------------------------
* Move constructor. Does exactly what you expect it to do.
*/
VecMap(VecMap && o) noexcept
: m_Storage(std::forward< storage_type >(o.m_Storage))
{
}
/* --------------------------------------------------------------------------------------------
* Sub-script operator.
*/
mapped_type & operator [] (const key_type & key)
{
for (auto & e : m_Storage)
{
if (e.first == key) return e.second;
}
m_Storage.emplace_back(key, mapped_type{});
return m_Storage.back().second;
}
/* --------------------------------------------------------------------------------------------
* Retrieve an iterator to the beginning. See: std::vector::begin()
*/
iterator begin() noexcept { return m_Storage.begin(); }
/* --------------------------------------------------------------------------------------------
* Retrieve an iterator to the beginning (const). See: std::vector::[c]begin()
*/
const_iterator begin() const noexcept { return m_Storage.begin(); }
/* --------------------------------------------------------------------------------------------
* Retrieve an iterator to the beginning (const). See: std::vector::cbegin()
*/
const_iterator cbegin() const noexcept { return m_Storage.cbegin(); }
/* --------------------------------------------------------------------------------------------
* Retrieve an iterator to the beginning. See: std::vector::end()
*/
iterator end() noexcept { return m_Storage.end(); }
/* --------------------------------------------------------------------------------------------
* Retrieve an iterator to the beginning (const). See: std::vector::[c]end()
*/
const_iterator end() const noexcept { return m_Storage.end(); }
/* --------------------------------------------------------------------------------------------
* Retrieve an iterator to the beginning (const). See: std::vector::cend()
*/
const_iterator cend() const noexcept { return m_Storage.cend(); }
/* --------------------------------------------------------------------------------------------
* Retrieve a reverse iterator to the beginning. See: std::vector::rbegin()
*/
iterator rbegin() noexcept { return m_Storage.rbegin(); }
/* --------------------------------------------------------------------------------------------
* Retrieve a reverse iterator to the beginning (const). See: std::vector::[c]rbegin()
*/
const_iterator rbegin() const noexcept { return m_Storage.rbegin(); }
/* --------------------------------------------------------------------------------------------
* Retrieve a reverse iterator to the beginning (const). See: std::vector::crbegin()
*/
const_iterator crbegin() const noexcept { return m_Storage.crbegin(); }
/* --------------------------------------------------------------------------------------------
* Retrieve a reverse iterator to the beginning. See: std::vector::rend()
*/
iterator rend() noexcept { return m_Storage.rend(); }
/* --------------------------------------------------------------------------------------------
* Retrieve a reverse iterator to the beginning (const). See: std::vector::[c]rend()
*/
const_iterator rend() const noexcept { return m_Storage.rend(); }
/* --------------------------------------------------------------------------------------------
* Retrieve a reverse iterator to the beginning (const). See: std::vector::crend()
*/
const_iterator crend() const noexcept { return m_Storage.crend(); }
/* --------------------------------------------------------------------------------------------
* Check if elements are stored in the container.
*/
bool empty() const noexcept { return m_Storage.empty(); }
/* --------------------------------------------------------------------------------------------
* Retrieve the number of elements stored in the container.
*/
size_type size() const noexcept { return m_Storage.size(); }
/* --------------------------------------------------------------------------------------------
* Retrieve the number of elements that can be stored in the container.
*/
size_type max_size() const noexcept { return m_Storage.max_size(); }
/* --------------------------------------------------------------------------------------------
* Reserve space for a specific amount of elements.
*/
void reserve(size_type n) { m_Storage.reserve(n); }
/* --------------------------------------------------------------------------------------------
* Retrieve the number of elements that can be held in currently allocated storage.
*/
size_type capacity() const noexcept { return m_Storage.capacity(); }
/* --------------------------------------------------------------------------------------------
* Reduce memory usage by freeing unused memory.
*/
void conform() { m_Storage.shrink_to_fit(); }
/* --------------------------------------------------------------------------------------------
* Discard all stored elements.
*/
void clear() noexcept { m_Storage.clear(); }
/* --------------------------------------------------------------------------------------------
* Locate a an element with a specific key and obtain an iterator to it's location.
*/
iterator find(const key_type & key) noexcept
{
return std::find_if(m_Storage.begin(), m_Storage.end(),
[&](reference e) -> bool { return e.first == key; });
}
/* --------------------------------------------------------------------------------------------
* Locate a an element with a specific key and obtain an iterator to it's location.
*/
const_iterator find(const key_type & key) const noexcept
{
return std::find_if(m_Storage.cbegin(), m_Storage.cend(),
[&](const_reference e) -> bool { return e.first == key; });
}
/* --------------------------------------------------------------------------------------------
* Check if an element with a specific key exists in the container.
*/
bool exists(const key_type & key) const noexcept { return find(key) != m_Storage.cend(); }
/* --------------------------------------------------------------------------------------------
* Append a new element to the end of the container.
*/
template< class... Args > mapped_type & emplace_back( Args&&... args )
{
m_Storage.emplace_back(std::forward< Args >(args)...);
return m_Storage.back().second;
}
/* --------------------------------------------------------------------------------------------
* Remove the last element of the container.
*/
void pop_back() { m_Storage.pop_back(); }
/* --------------------------------------------------------------------------------------------
* Removes specified element from the container. Returns true if found and removed, false otherwise.
*/
bool erase(const key_type & key)
{
auto itr = find(key);
if (itr != m_Storage.end())
{
m_Storage.erase(itr);
return true;
}
return false;
}
/* --------------------------------------------------------------------------------------------
* Removes specified element from the container. Returns iterator to the next element.
*/
iterator erase(iterator pos) { return m_Storage.erase(pos); }
/* --------------------------------------------------------------------------------------------
* Removes specified element from the container. Returns iterator to the next element.
*/
iterator erase(const_iterator pos) { return m_Storage.erase(pos); }
private:
/* --------------------------------------------------------------------------------------------
* Internal container used to store elements.
*/
storage_type m_Storage;
};
+19 -80
View File
@@ -1,19 +1,16 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Vector2.hpp"
#include "Base/Vector2i.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("Vector2"))
SQMOD_DECL_TYPENAME(Typename, _SC("Vector2"))
// ------------------------------------------------------------------------------------------------
const Vector2 Vector2::NIL = Vector2(0);
@@ -23,13 +20,6 @@ const Vector2 Vector2::MAX = Vector2(std::numeric_limits< Vector2::Value >::max(
// ------------------------------------------------------------------------------------------------
SQChar Vector2::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector2::Vector2() noexcept
: x(0.0), y(0.0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2::Vector2(Value sv) noexcept
: x(sv), y(sv)
@@ -95,8 +85,8 @@ Vector2 & Vector2::operator /= (const Vector2 & v)
// ------------------------------------------------------------------------------------------------
Vector2 & Vector2::operator %= (const Vector2 & v)
{
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
x = fmodf(x, v.x);
y = fmodf(y, v.y);
return *this;
}
@@ -135,8 +125,8 @@ Vector2 & Vector2::operator /= (Value s)
// ------------------------------------------------------------------------------------------------
Vector2 & Vector2::operator %= (Value s)
{
x = std::fmod(x, s);
y = std::fmod(y, s);
x = fmodf(x, s);
y = fmodf(y, s);
return *this;
}
@@ -201,7 +191,7 @@ Vector2 Vector2::operator / (const Vector2 & v) const
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::operator % (const Vector2 & v) const
{
return {std::fmod(x, v.x), std::fmod(y, v.y)};
return {fmodf(x, v.x), fmodf(y, v.y)};
}
// ------------------------------------------------------------------------------------------------
@@ -231,13 +221,13 @@ Vector2 Vector2::operator / (Value s) const
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::operator % (Value s) const
{
return {std::fmod(x, s), std::fmod(y, s)};
return {fmodf(x, s), fmodf(y, s)};
}
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::operator + () const
{
return {std::fabs(x), std::fabs(y)};
return {fabsf(x), fabsf(y)};
}
// ------------------------------------------------------------------------------------------------
@@ -283,7 +273,7 @@ bool Vector2::operator >= (const Vector2 & v) const
}
// ------------------------------------------------------------------------------------------------
Int32 Vector2::Cmp(const Vector2 & o) const
int32_t Vector2::Cmp(const Vector2 & o) const
{
if (*this == o)
{
@@ -300,9 +290,9 @@ Int32 Vector2::Cmp(const Vector2 & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Vector2::ToString() const
String Vector2::ToString() const
{
return ToStrF("%f,%f", x, y);
return fmt::format("{},{}", x, y);
}
// ------------------------------------------------------------------------------------------------
@@ -373,34 +363,16 @@ void Vector2::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::Abs() const
{
return {std::fabs(x), std::fabs(y)};
return {fabsf(x), fabsf(y)};
}
// ------------------------------------------------------------------------------------------------
LightObj Vector2::Format(const String & spec, StackStrF & fmt) const
String Vector2::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 2, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), x, y);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("x", x)
, fmt::arg("y", y)
);
}
// ------------------------------------------------------------------------------------------------
@@ -476,39 +448,6 @@ void Register_Vector2(HSQUIRRELVM vm)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector2 >)
.StaticFmtFunc(_SC("FromStr"), &Vector2::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Vector2::GetEx)
// Operator Exposure
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opAddAssign"), &Vector2::operator +=)
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opSubAssign"), &Vector2::operator -=)
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opMulAssign"), &Vector2::operator *=)
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opDivAssign"), &Vector2::operator /=)
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opModAssign"), &Vector2::operator %=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opAddAssignS"), &Vector2::operator +=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opSubAssignS"), &Vector2::operator -=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opMulAssignS"), &Vector2::operator *=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opDivAssignS"), &Vector2::operator /=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opModAssignS"), &Vector2::operator %=)
.Func< Vector2 & (Vector2::*)(void) >(_SC("opPreInc"), &Vector2::operator ++)
.Func< Vector2 & (Vector2::*)(void) >(_SC("opPreDec"), &Vector2::operator --)
.Func< Vector2 (Vector2::*)(int) >(_SC("opPostInc"), &Vector2::operator ++)
.Func< Vector2 (Vector2::*)(int) >(_SC("opPostDec"), &Vector2::operator --)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opAdd"), &Vector2::operator +)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opSub"), &Vector2::operator -)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opMul"), &Vector2::operator *)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opDiv"), &Vector2::operator /)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opMod"), &Vector2::operator %)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opAddS"), &Vector2::operator +)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opSubS"), &Vector2::operator -)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opMulS"), &Vector2::operator *)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opDivS"), &Vector2::operator /)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opModS"), &Vector2::operator %)
.Func< Vector2 (Vector2::*)(void) const >(_SC("opUnPlus"), &Vector2::operator +)
.Func< Vector2 (Vector2::*)(void) const >(_SC("opUnMinus"), &Vector2::operator -)
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opEqual"), &Vector2::operator ==)
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opNotEqual"), &Vector2::operator !=)
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opLessThan"), &Vector2::operator <)
.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 >=)
);
}
+11 -11
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -31,12 +31,12 @@ struct Vector2
/* --------------------------------------------------------------------------------------------
* The x and y components of this type.
*/
Value x, y;
Value x{0}, y{0};
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Vector2() noexcept;
Vector2() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct a vector with the same scalar value for all components.
@@ -246,12 +246,12 @@ struct Vector2
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Vector2 & v) const;
SQMOD_NODISCARD int32_t Cmp(const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(Vector2(static_cast< Value >(s)));
}
@@ -259,7 +259,7 @@ struct Vector2
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
return Cmp(Vector2(static_cast< Value >(s)));
}
@@ -267,7 +267,7 @@ struct Vector2
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
return Cmp(Vector2(static_cast< Value >(s)));
}
@@ -275,7 +275,7 @@ struct Vector2
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
return Cmp(Vector2(static_cast< Value >(0)));
}
@@ -283,7 +283,7 @@ struct Vector2
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set all components to the specified scalar value.
@@ -336,12 +336,12 @@ struct Vector2
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Vector2 Abs() const;
SQMOD_NODISCARD Vector2 Abs() const;
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2 type from a string.
+11 -93
View File
@@ -1,19 +1,16 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Vector2i.hpp"
#include "Base/Vector2.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("Vector2i"))
SQMOD_DECL_TYPENAME(Typename, _SC("Vector2i"))
// ------------------------------------------------------------------------------------------------
const Vector2i Vector2i::NIL = Vector2i(0);
@@ -23,13 +20,6 @@ const Vector2i Vector2i::MAX = Vector2i(std::numeric_limits< Vector2i::Value >::
// ------------------------------------------------------------------------------------------------
SQChar Vector2i::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i() noexcept
: x(0), y(0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i(Value sv) noexcept
: x(sv), y(sv)
@@ -429,7 +419,7 @@ bool Vector2i::operator >= (const Vector2i & v) const
}
// ------------------------------------------------------------------------------------------------
Int32 Vector2i::Cmp(const Vector2i & o) const
int32_t Vector2i::Cmp(const Vector2i & o) const
{
if (*this == o)
{
@@ -446,9 +436,9 @@ Int32 Vector2i::Cmp(const Vector2i & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Vector2i::ToString() const
String Vector2i::ToString() const
{
return ToStrF("%d,%d", x, y);
return fmt::format("{},{}", x, y);
}
// ------------------------------------------------------------------------------------------------
@@ -523,30 +513,12 @@ Vector2i Vector2i::Abs() const
}
// ------------------------------------------------------------------------------------------------
LightObj Vector2i::Format(const String & spec, StackStrF & fmt) const
String Vector2i::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 2, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), x, y);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("x", x)
, fmt::arg("y", y)
);
}
// ------------------------------------------------------------------------------------------------
@@ -622,60 +594,6 @@ void Register_Vector2i(HSQUIRRELVM vm)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector2i >)
.StaticFmtFunc(_SC("FromStr"), &Vector2i::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Vector2i::GetEx)
// Operator Exposure
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opAddAssign"), &Vector2i::operator +=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opSubAssign"), &Vector2i::operator -=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opMulAssign"), &Vector2i::operator *=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opDivAssign"), &Vector2i::operator /=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opModAssign"), &Vector2i::operator %=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opAndAssign"), &Vector2i::operator &=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opOrAssign"), &Vector2i::operator |=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opXorAssign"), &Vector2i::operator ^=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opShlAssign"), &Vector2i::operator <<=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opShrAssign"), &Vector2i::operator >>=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opAddAssignS"), &Vector2i::operator +=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opSubAssignS"), &Vector2i::operator -=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opMulAssignS"), &Vector2i::operator *=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opDivAssignS"), &Vector2i::operator /=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opModAssignS"), &Vector2i::operator %=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opAndAssignS"), &Vector2i::operator &=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opOrAssignS"), &Vector2i::operator |=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opXorAssignS"), &Vector2i::operator ^=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opShlAssignS"), &Vector2i::operator <<=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opShrAssignS"), &Vector2i::operator >>=)
.Func< Vector2i & (Vector2i::*)(void) >(_SC("opPreInc"), &Vector2i::operator ++)
.Func< Vector2i & (Vector2i::*)(void) >(_SC("opPreDec"), &Vector2i::operator --)
.Func< Vector2i (Vector2i::*)(int) >(_SC("opPostInc"), &Vector2i::operator ++)
.Func< Vector2i (Vector2i::*)(int) >(_SC("opPostDec"), &Vector2i::operator --)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opAdd"), &Vector2i::operator +)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opSub"), &Vector2i::operator -)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opMul"), &Vector2i::operator *)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opDiv"), &Vector2i::operator /)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opMod"), &Vector2i::operator %)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opAnd"), &Vector2i::operator &)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opOr"), &Vector2i::operator |)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opShl"), &Vector2i::operator ^)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opShl"), &Vector2i::operator <<)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opShr"), &Vector2i::operator >>)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opAddS"), &Vector2i::operator +)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opSubS"), &Vector2i::operator -)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opMulS"), &Vector2i::operator *)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opDivS"), &Vector2i::operator /)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opModS"), &Vector2i::operator %)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opAndS"), &Vector2i::operator &)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opOrS"), &Vector2i::operator |)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opShlS"), &Vector2i::operator ^)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opShlS"), &Vector2i::operator <<)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opShrS"), &Vector2i::operator >>)
.Func< Vector2i (Vector2i::*)(void) const >(_SC("opUnPlus"), &Vector2i::operator +)
.Func< Vector2i (Vector2i::*)(void) const >(_SC("opUnMinus"), &Vector2i::operator -)
.Func< Vector2i (Vector2i::*)(void) const >(_SC("opCom"), &Vector2i::operator ~)
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opEqual"), &Vector2i::operator ==)
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opNotEqual"), &Vector2i::operator !=)
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opLessThan"), &Vector2i::operator <)
.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 >=)
);
}
+11 -11
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -31,12 +31,12 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* The x and y components of this type.
*/
Value x, y;
Value x{0}, y{0};
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Vector2i() noexcept;
Vector2i() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct a vector with the same scalar value for all components.
@@ -351,12 +351,12 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Vector2i & v) const;
SQMOD_NODISCARD int32_t Cmp(const Vector2i & v) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
return Cmp(Vector2i(static_cast< Value >(s)));
}
@@ -364,7 +364,7 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(Vector2i(static_cast< Value >(s)));
}
@@ -372,7 +372,7 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
return Cmp(Vector2i(static_cast< Value >(s)));
}
@@ -380,7 +380,7 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
return Cmp(Vector2i(static_cast< Value >(0)));
}
@@ -388,7 +388,7 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set all components to the specified scalar value.
@@ -441,12 +441,12 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Vector2i Abs() const;
SQMOD_NODISCARD Vector2i Abs() const;
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2i type from a string.
+45 -105
View File
@@ -2,14 +2,11 @@
#include "Base/Vector3.hpp"
#include "Base/Vector4.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -17,7 +14,7 @@ namespace SqMod {
#define STOVAL(v) static_cast< Vector3::Value >(v)
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("Vector3"))
SQMOD_DECL_TYPENAME(Typename, _SC("Vector3"))
// ------------------------------------------------------------------------------------------------
const Vector3 Vector3::NIL(STOVAL(0.0));
@@ -34,13 +31,6 @@ const Vector3 Vector3::ONE(STOVAL(1.0), STOVAL(1.0), STOVAL(1.0));
// ------------------------------------------------------------------------------------------------
SQChar Vector3::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector3::Vector3() noexcept
: x(0.0), y(0.0), z(0.0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector3::Vector3(Value sv) noexcept
: x(sv), y(sv), z(sv)
@@ -121,9 +111,9 @@ Vector3 & Vector3::operator /= (const Vector3 & v)
// ------------------------------------------------------------------------------------------------
Vector3 & Vector3::operator %= (const Vector3 & v)
{
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
z = std::fmod(z, v.z);
x = fmodf(x, v.x);
y = fmodf(y, v.y);
z = fmodf(z, v.z);
return *this;
}
@@ -166,9 +156,9 @@ Vector3 & Vector3::operator /= (Value s)
// ------------------------------------------------------------------------------------------------
Vector3 & Vector3::operator %= (Value s)
{
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
x = fmodf(x, s);
y = fmodf(y, s);
z = fmodf(z, s);
return *this;
}
@@ -237,7 +227,7 @@ Vector3 Vector3::operator / (const Vector3 & v) const
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::operator % (const Vector3 & v) const
{
return {std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z)};
return {fmodf(x, v.x), fmodf(y, v.y), fmodf(z, v.z)};
}
// ------------------------------------------------------------------------------------------------
@@ -267,13 +257,13 @@ Vector3 Vector3::operator / (Value s) const
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::operator % (Value s) const
{
return {std::fmod(x, s), std::fmod(y, s), std::fmod(z, s)};
return {fmodf(x, s), fmodf(y, s), fmodf(z, s)};
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::operator + () const
{
return {std::fabs(x), std::fabs(y), std::fabs(z)};
return {fabsf(x), fabsf(y), fabsf(z)};
}
// ------------------------------------------------------------------------------------------------
@@ -319,7 +309,7 @@ bool Vector3::operator >= (const Vector3 & v) const
}
// ------------------------------------------------------------------------------------------------
Int32 Vector3::Cmp(const Vector3 & o) const
int32_t Vector3::Cmp(const Vector3 & o) const
{
if (*this == o)
{
@@ -336,9 +326,9 @@ Int32 Vector3::Cmp(const Vector3 & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Vector3::ToString() const
String Vector3::ToString() const
{
return ToStrF("%f,%f,%f", x, y, z);
return fmt::format("{},{},{}", x, y, z);
}
// ------------------------------------------------------------------------------------------------
@@ -393,17 +383,17 @@ void Vector3::SetQuaternionEx(Value qx, Value qy, Value qz, Value qw)
// Quick conversion to Euler angles to give tilt to user
const Value sqx = (qx * qx), sqy = (qy * qy), sqz = (qz * qz), sqw = (qw * qw);
y = std::asin(STOVAL(2.0) * ((qw * qy) - (qx * qz)));
y = asinf(STOVAL(2.0) * ((qw * qy) - (qx * qz)));
if (EpsGt((SQMOD_PI * STOVAL(0.5)) - std::abs(y), STOVAL(1e-10)))
{
z = std::atan2(STOVAL(2.0) * ((qx * qy) + (qw * qz)), sqx - sqy - sqz + sqw);
x = std::atan2(STOVAL(2.0) * ((qw * qx) + (qy * qz)), sqw - sqx - sqy + sqz);
z = atan2f(STOVAL(2.0) * ((qx * qy) + (qw * qz)), sqx - sqy - sqz + sqw);
x = atan2f(STOVAL(2.0) * ((qw * qx) + (qy * qz)), sqw - sqx - sqy + sqz);
}
else
{
// Compute heading from local 'down' vector
z = std::atan2((STOVAL(2.0) * qy * qz) - (STOVAL(2.0) * qx * qw),
z = atan2f((STOVAL(2.0) * qy * qz) - (STOVAL(2.0) * qx * qw),
(STOVAL(2.0) * qx * qz) + (STOVAL(2.0) * qy * qw));
x = STOVAL(0.0);
@@ -458,19 +448,19 @@ void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmi
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::Abs() const
{
return {std::fabs(x), std::fabs(y), std::fabs(z)};
return {fabsf(x), fabsf(y), fabsf(z)};
}
// ------------------------------------------------------------------------------------------------
bool Vector3::IsNaN() const
{
return std::isnan(x) || std::isnan(y) || std::isnan(z);
return isnanf(x) || isnanf(y) || isnanf(z);
}
// ------------------------------------------------------------------------------------------------
Vector3::Value Vector3::GetLength() const
{
return std::sqrt((x * x) + (y * y) + (z * z));
return sqrtf((x * x) + (y * y) + (z * z));
}
// ------------------------------------------------------------------------------------------------
@@ -492,7 +482,7 @@ void Vector3::SetLengthSquared(Value length)
{
Normalize();
// Assign the specified length
*this *= std::sqrt(length);
*this *= sqrtf(length);
}
// ------------------------------------------------------------------------------------------------
@@ -502,7 +492,7 @@ Vector3 Vector3::Normalized() const
if (!EpsEq(len_squared, STOVAL(1.0)) && EpsLt(len_squared, STOVAL(0.0)))
{
return (*this * (STOVAL(1.0) / std::sqrt(len_squared)));
return (*this * (STOVAL(1.0) / sqrtf(len_squared)));
}
else
{
@@ -517,7 +507,7 @@ void Vector3::Normalize()
if (!EpsEq(len_squared, STOVAL(1.0)) && EpsGt(len_squared, STOVAL(0.0)))
{
const Value inv_len = STOVAL(1.0) / std::sqrt(len_squared);
const Value inv_len = STOVAL(1.0) / sqrtf(len_squared);
x *= inv_len;
y *= inv_len;
z *= inv_len;
@@ -545,19 +535,19 @@ Vector3 Vector3::CrossProduct(const Vector3 & vec) const
// ------------------------------------------------------------------------------------------------
Vector3::Value Vector3::Angle(const Vector3 & vec) const
{
return std::acos(DotProduct(vec) / (GetLength() * vec.GetLength()));
return acosf(DotProduct(vec) / (GetLength() * vec.GetLength()));
}
// ------------------------------------------------------------------------------------------------
Vector3::Value Vector3::GetDistanceTo(const Vector3 & vec) const
{
return std::sqrt(std::pow(x - vec.x, 2) + std::pow(y - vec.y, 2) + std::pow(z - vec.z, 2));
return sqrtf(powf(x - vec.x, 2) + powf(y - vec.y, 2) + powf(z - vec.z, 2));
}
// ------------------------------------------------------------------------------------------------
Vector3::Value Vector3::GetSquaredDistanceTo(const Vector3 & vec) const
{
return (std::pow(x - vec.x, 2) + std::pow(y - vec.y, 2) + std::pow(z - vec.z, 2));
return (powf(x - vec.x, 2) + powf(y - vec.y, 2) + powf(z - vec.z, 2));
}
// ------------------------------------------------------------------------------------------------
@@ -570,15 +560,15 @@ bool Vector3::IsBetweenPoints(const Vector3 & begin, const Vector3 & end) const
// ------------------------------------------------------------------------------------------------
void Vector3::Interpolate(const Vector3 & a, const Vector3 & b, Value d)
{
x = STOVAL(static_cast< Float64 >(b.x) + ((a.x - b.x) * d));
y = STOVAL(static_cast< Float64 >(b.y) + ((a.y - b.y) * d));
z = STOVAL(static_cast< Float64 >(b.z) + ((a.z - b.z) * d));
x = STOVAL(static_cast< double >(b.x) + ((a.x - b.x) * d));
y = STOVAL(static_cast< double >(b.y) + ((a.y - b.y) * d));
z = STOVAL(static_cast< double >(b.z) + ((a.z - b.z) * d));
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::Interpolated(const Vector3 & vec, Value d) const
{
const Float64 inv = 1.0 - d;
const double inv = 1.0 - d;
return {
STOVAL((vec.x * inv) + (x * d)),
STOVAL((vec.y * inv) + (y * d)),
@@ -590,15 +580,15 @@ Vector3 Vector3::Interpolated(const Vector3 & vec, Value d) const
Vector3 Vector3::Rotated(const Vector3 & axis, Value angle) const
{
const Vector3 o(axis * axis.DotProduct(*this));
return (o + ((*this - o) * std::cos(angle)) + (axis.CrossProduct(*this) * std::sin(angle)));
return (o + ((*this - o) * cosf(angle)) + (axis.CrossProduct(*this) * sinf(angle)));
}
// ------------------------------------------------------------------------------------------------
void Vector3::CenterRotateXZBy(Value degrees, const Vector3 & center)
{
degrees *= SQMOD_DEGTORAD;
const Value cs = std::cos(degrees);
const Value sn = std::sin(degrees);
const Value cs = cosf(degrees);
const Value sn = sinf(degrees);
x -= center.x;
z -= center.z;
x = static_cast< Value >((x * cs) - (z * sn)) + center.x;
@@ -609,8 +599,8 @@ void Vector3::CenterRotateXZBy(Value degrees, const Vector3 & center)
void Vector3::CenterRotateXYBy(Value degrees, const Vector3 & center)
{
degrees *= SQMOD_DEGTORAD;
const Value cs = std::cos(degrees);
const Value sn = std::sin(degrees);
const Value cs = cosf(degrees);
const Value sn = sinf(degrees);
x -= center.x;
y -= center.y;
x = static_cast< Value >((x * cs) - (y * sn)) + center.x;
@@ -621,8 +611,8 @@ void Vector3::CenterRotateXYBy(Value degrees, const Vector3 & center)
void Vector3::CenterRotateYZBy(Value degrees, const Vector3 & center)
{
degrees *= SQMOD_DEGTORAD;
const Value cs = std::cos(degrees);
const Value sn = std::sin(degrees);
const Value cs = cosf(degrees);
const Value sn = sinf(degrees);
z -= center.z;
y -= center.y;
y = static_cast< Value >((y * cs) - (z * sn)) + center.z;
@@ -630,30 +620,13 @@ void Vector3::CenterRotateYZBy(Value degrees, const Vector3 & center)
}
// ------------------------------------------------------------------------------------------------
LightObj Vector3::Format(const String & spec, StackStrF & fmt) const
String Vector3::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 3, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), x, y, z);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("x", x)
, fmt::arg("y", y)
, fmt::arg("z", z)
);
}
// ------------------------------------------------------------------------------------------------
@@ -767,39 +740,6 @@ void Register_Vector3(HSQUIRRELVM vm)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector3 >)
.StaticFmtFunc(_SC("FromStr"), &Vector3::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Vector3::GetEx)
// Operator Exposure
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opAddAssign"), &Vector3::operator +=)
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opSubAssign"), &Vector3::operator -=)
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opMulAssign"), &Vector3::operator *=)
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opDivAssign"), &Vector3::operator /=)
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opModAssign"), &Vector3::operator %=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opAddAssignS"), &Vector3::operator +=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opSubAssignS"), &Vector3::operator -=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opMulAssignS"), &Vector3::operator *=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opDivAssignS"), &Vector3::operator /=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opModAssignS"), &Vector3::operator %=)
.Func< Vector3 & (Vector3::*)(void) >(_SC("opPreInc"), &Vector3::operator ++)
.Func< Vector3 & (Vector3::*)(void) >(_SC("opPreDec"), &Vector3::operator --)
.Func< Vector3 (Vector3::*)(int) >(_SC("opPostInc"), &Vector3::operator ++)
.Func< Vector3 (Vector3::*)(int) >(_SC("opPostDec"), &Vector3::operator --)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opAdd"), &Vector3::operator +)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opSub"), &Vector3::operator -)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opMul"), &Vector3::operator *)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opDiv"), &Vector3::operator /)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opMod"), &Vector3::operator %)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opAddS"), &Vector3::operator +)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opSubS"), &Vector3::operator -)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opMulS"), &Vector3::operator *)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opDivS"), &Vector3::operator /)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opModS"), &Vector3::operator %)
.Func< Vector3 (Vector3::*)(void) const >(_SC("opUnPlus"), &Vector3::operator +)
.Func< Vector3 (Vector3::*)(void) const >(_SC("opUnMinus"), &Vector3::operator -)
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opEqual"), &Vector3::operator ==)
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opNotEqual"), &Vector3::operator !=)
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opLessThan"), &Vector3::operator <)
.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 >=)
);
}
+24 -24
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -38,12 +38,12 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* The x, y and z components of this type.
*/
Value x, y, z;
Value x{0}, y{0}, z{0};
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Vector3() noexcept;
Vector3() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct a vector with the same scalar value for all components.
@@ -258,12 +258,12 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Vector3 & v) const;
SQMOD_NODISCARD int32_t Cmp(const Vector3 & v) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(Vector3(static_cast< Value >(s)));
}
@@ -271,7 +271,7 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
return Cmp(Vector3(static_cast< Value >(s)));
}
@@ -279,7 +279,7 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
return Cmp(Vector3(static_cast< Value >(s)));
}
@@ -287,7 +287,7 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
return Cmp(static_cast< Value >(0));
}
@@ -295,7 +295,7 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set all components to the specified scalar value.
@@ -363,17 +363,17 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Vector3 Abs() const;
SQMOD_NODISCARD Vector3 Abs() const;
/* --------------------------------------------------------------------------------------------
* Return whether is NaN.
*/
bool IsNaN() const;
SQMOD_NODISCARD bool IsNaN() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the length.
*/
Value GetLength() const;
SQMOD_NODISCARD Value GetLength() const;
/* --------------------------------------------------------------------------------------------
* Assign the length.
@@ -383,7 +383,7 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Return the squared length.
*/
Value GetLengthSquared() const;
SQMOD_NODISCARD Value GetLengthSquared() const;
/* --------------------------------------------------------------------------------------------
* Assign the squared length.
@@ -393,7 +393,7 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Return normalized to unit length.
*/
Vector3 Normalized() const;
SQMOD_NODISCARD Vector3 Normalized() const;
/* --------------------------------------------------------------------------------------------
* Normalize to unit length.
@@ -403,37 +403,37 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Calculate dot product.
*/
Value DotProduct(const Vector3 & vec) const;
SQMOD_NODISCARD Value DotProduct(const Vector3 & vec) const;
/* --------------------------------------------------------------------------------------------
* Calculate absolute dot product.
*/
Value AbsDotProduct(const Vector3 & vec) const;
SQMOD_NODISCARD Value AbsDotProduct(const Vector3 & vec) const;
/* --------------------------------------------------------------------------------------------
* Calculate cross product.
*/
Vector3 CrossProduct(const Vector3 & vec) const;
SQMOD_NODISCARD Vector3 CrossProduct(const Vector3 & vec) const;
/* --------------------------------------------------------------------------------------------
* Returns the angle between this vector and another vector in degrees.
*/
Value Angle(const Vector3 & vec) const;
SQMOD_NODISCARD Value Angle(const Vector3 & vec) const;
/* --------------------------------------------------------------------------------------------
* Return the distance between this vector and another vector.
*/
Value GetDistanceTo(const Vector3 & vec) const;
SQMOD_NODISCARD Value GetDistanceTo(const Vector3 & vec) const;
/* --------------------------------------------------------------------------------------------
* Return the squared distance between this vector and another vector.
*/
Value GetSquaredDistanceTo(const Vector3 & vec) const;
SQMOD_NODISCARD Value GetSquaredDistanceTo(const Vector3 & vec) const;
/* --------------------------------------------------------------------------------------------
* Linear interpolation with another vector.
*/
bool IsBetweenPoints(const Vector3 & begin, const Vector3 & end) const;
SQMOD_NODISCARD bool IsBetweenPoints(const Vector3 & begin, const Vector3 & end) const;
/* --------------------------------------------------------------------------------------------
* Sets this vector to the linearly interpolated vector between a and b.
@@ -443,12 +443,12 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Sets this vector to the linearly interpolated vector between a and b.
*/
Vector3 Interpolated(const Vector3 & vec, Value d) const;
SQMOD_NODISCARD Vector3 Interpolated(const Vector3 & vec, Value d) const;
/* --------------------------------------------------------------------------------------------
* Rotates the vector by a specified number of degrees around the Y axis and the specified center.
*/
Vector3 Rotated(const Vector3 & axis, Value angle) const;
SQMOD_NODISCARD Vector3 Rotated(const Vector3 & axis, Value angle) const;
/* --------------------------------------------------------------------------------------------
* Rotates the vector by a specified number of degrees around the Y axis and the specified center.
@@ -492,7 +492,7 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string.
+25 -84
View File
@@ -2,19 +2,16 @@
#include "Base/Vector4.hpp"
#include "Base/Vector3.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <limits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("Vector4"))
SQMOD_DECL_TYPENAME(Typename, _SC("Vector4"))
// ------------------------------------------------------------------------------------------------
const Vector4 Vector4::NIL = Vector4(0);
@@ -24,13 +21,6 @@ const Vector4 Vector4::MAX = Vector4(std::numeric_limits< Vector4::Value >::max(
// ------------------------------------------------------------------------------------------------
SQChar Vector4::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector4::Vector4() noexcept
: x(0.0), y(0.0), z(0.0), w(0.0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(Value sv) noexcept
: x(sv), y(sv), z(sv), w(sv)
@@ -125,10 +115,10 @@ Vector4 & Vector4::operator /= (const Vector4 & v)
// ------------------------------------------------------------------------------------------------
Vector4 & Vector4::operator %= (const Vector4 & v)
{
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
z = std::fmod(z, v.z);
w = std::fmod(w, v.w);
x = fmodf(x, v.x);
y = fmodf(y, v.y);
z = fmodf(z, v.z);
w = fmodf(w, v.w);
return *this;
}
@@ -174,10 +164,10 @@ Vector4 & Vector4::operator /= (Value s)
// ------------------------------------------------------------------------------------------------
Vector4 & Vector4::operator %= (Value s)
{
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
w = std::fmod(w, s);
x = fmodf(x, s);
y = fmodf(y, s);
z = fmodf(z, s);
w = fmodf(w, s);
return *this;
}
@@ -250,7 +240,7 @@ Vector4 Vector4::operator / (const Vector4 & v) const
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::operator % (const Vector4 & v) const
{
return {std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z), std::fmod(w, v.w)};
return {fmodf(x, v.x), fmodf(y, v.y), fmodf(z, v.z), fmodf(w, v.w)};
}
// ------------------------------------------------------------------------------------------------
@@ -280,13 +270,13 @@ Vector4 Vector4::operator / (Value s) const
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::operator % (Value s) const
{
return {std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s)};
return {fmodf(x, s), fmodf(y, s), fmodf(z, s), fmodf(w, s)};
}
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::operator + () const
{
return {std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w)};
return {fabsf(x), fabsf(y), fabsf(z), fabsf(w)};
}
// ------------------------------------------------------------------------------------------------
@@ -332,7 +322,7 @@ bool Vector4::operator >= (const Vector4 & v) const
}
// ------------------------------------------------------------------------------------------------
Int32 Vector4::Cmp(const Vector4 & o) const
int32_t Vector4::Cmp(const Vector4 & o) const
{
if (*this == o)
{
@@ -349,9 +339,9 @@ Int32 Vector4::Cmp(const Vector4 & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Vector4::ToString() const
String Vector4::ToString() const
{
return ToStrF("%f,%f,%f,%f", x, y, z, w);
return fmt::format("{},{},{},{}", x, y, z, w);
}
// ------------------------------------------------------------------------------------------------
@@ -462,7 +452,7 @@ void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmi
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::Abs() const
{
return {std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w)};
return {fabsf(x), fabsf(y), fabsf(z), fabsf(w)};
}
// ------------------------------------------------------------------------------------------------
@@ -472,30 +462,14 @@ const Vector4 & Vector4::Get(StackStrF & str)
}
// ------------------------------------------------------------------------------------------------
LightObj Vector4::Format(const String & spec, StackStrF & fmt) const
String Vector4::Format(StackStrF & str) const
{
String out;
// Attempt to build the format string
if (!BuildFormatString(out, fmt, 4, spec))
{
return LightObj{}; // Default to null
}
// Empty string is unacceptable
else if (out.empty())
{
STHROWF("Unable to build a valid format string.");
}
// Grab a temporary buffer
Buffer buff(out.size());
// Generate the string
Buffer::SzType n = buff.WriteF(0, out.c_str(), x, y, z, w);
// Did the format failed?
if (!n && !out.empty())
{
STHROWF("Format failed. Please check format specifier and parameter count.");
}
// Return the resulted string
return LightObj{buff.Begin< SQChar >(), static_cast< SQInteger >(n)};
return fmt::format(str.ToStr()
, fmt::arg("x", x)
, fmt::arg("y", y)
, fmt::arg("z", z)
, fmt::arg("w", w)
);
}
// ------------------------------------------------------------------------------------------------
@@ -575,39 +549,6 @@ void Register_Vector4(HSQUIRRELVM vm)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector4 >)
.StaticFmtFunc(_SC("FromStr"), &Vector4::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Vector4::GetEx)
// Operator Exposure
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opAddAssign"), &Vector4::operator +=)
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opSubAssign"), &Vector4::operator -=)
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opMulAssign"), &Vector4::operator *=)
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opDivAssign"), &Vector4::operator /=)
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opModAssign"), &Vector4::operator %=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opAddAssignS"), &Vector4::operator +=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opSubAssignS"), &Vector4::operator -=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opMulAssignS"), &Vector4::operator *=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opDivAssignS"), &Vector4::operator /=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opModAssignS"), &Vector4::operator %=)
.Func< Vector4 & (Vector4::*)(void) >(_SC("opPreInc"), &Vector4::operator ++)
.Func< Vector4 & (Vector4::*)(void) >(_SC("opPreDec"), &Vector4::operator --)
.Func< Vector4 (Vector4::*)(int) >(_SC("opPostInc"), &Vector4::operator ++)
.Func< Vector4 (Vector4::*)(int) >(_SC("opPostDec"), &Vector4::operator --)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opAdd"), &Vector4::operator +)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opSub"), &Vector4::operator -)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opMul"), &Vector4::operator *)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opDiv"), &Vector4::operator /)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opMod"), &Vector4::operator %)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opAddS"), &Vector4::operator +)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opSubS"), &Vector4::operator -)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opMulS"), &Vector4::operator *)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opDivS"), &Vector4::operator /)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opModS"), &Vector4::operator %)
.Func< Vector4 (Vector4::*)(void) const >(_SC("opUnPlus"), &Vector4::operator +)
.Func< Vector4 (Vector4::*)(void) const >(_SC("opUnMinus"), &Vector4::operator -)
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opEqual"), &Vector4::operator ==)
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opNotEqual"), &Vector4::operator !=)
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opLessThan"), &Vector4::operator <)
.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 >=)
);
}
+11 -11
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -31,12 +31,12 @@ struct Vector4
/* --------------------------------------------------------------------------------------------
* The x, y, z and w components of this type.
*/
Value x, y, z, w;
Value x{0}, y{0}, z{0}, w{0};
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Vector4() noexcept;
Vector4() noexcept = default;
/* --------------------------------------------------------------------------------------------
* Construct a vector with the same scalar value for all components.
@@ -256,12 +256,12 @@ struct Vector4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Vector4 & v) const;
SQMOD_NODISCARD int32_t Cmp(const Vector4 & v) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQFloat s) const
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
{
return Cmp(Vector4(static_cast< Value >(s)));
}
@@ -269,7 +269,7 @@ struct Vector4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(SQInteger s) const
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
{
return Cmp(Vector4(static_cast< Value >(s)));
}
@@ -277,7 +277,7 @@ struct Vector4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(bool s) const
SQMOD_NODISCARD int32_t Cmp(bool s) const
{
return Cmp(Vector4(static_cast< Value >(s)));
}
@@ -285,7 +285,7 @@ struct Vector4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
{
return Cmp(Vector4(static_cast< Value >(0)));
}
@@ -293,7 +293,7 @@ struct Vector4
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* Set all components to the specified scalar value.
@@ -361,12 +361,12 @@ struct Vector4
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Vector4 Abs() const;
SQMOD_NODISCARD Vector4 Abs() const;
/* --------------------------------------------------------------------------------------------
* Generate a formatted string with the values from this instance.
*/
LightObj Format(const String & spec, StackStrF & fmt) const;
SQMOD_NODISCARD String Format(StackStrF & str) const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string.
+54 -70
View File
@@ -1,35 +1,57 @@
# Include third-party libraries
add_subdirectory(Vendor)
# Create the Squirrel module
add_library(SqModule MODULE
SqBase.hpp
Main.cpp
Register.cpp
Core.cpp Core.hpp
Logger.cpp Logger.hpp
Base/DynArg.hpp
add_library(SqModule MODULE SqBase.hpp Main.cpp
# VCMP
VCMP/vcmp.h
VCMP/vcmp20.h
VCMP/vcmp21.h
# Sqrat
Sqrat/sqratAllocator.h
Sqrat/sqratArray.h
Sqrat/sqratClass.h
Sqrat/sqratClassType.h
Sqrat/sqratConst.h
Sqrat/sqratFunction.h
Sqrat/sqratGlobalMethods.h
Sqrat/sqratLightObj.h
Sqrat/sqratMemberMethods.h
Sqrat/sqratObject.h
Sqrat/sqratOverloadMethods.h
Sqrat/sqratScript.h
Sqrat/sqratTable.h
Sqrat/sqratTypes.h
Sqrat/sqratUtil.h
# Base
Base/AABB.cpp Base/AABB.hpp
Base/Buffer.cpp Base/Buffer.hpp
Base/Circle.cpp Base/Circle.hpp
Base/Color3.cpp Base/Color3.hpp
Base/Color4.cpp Base/Color4.hpp
Base/Quaternion.cpp Base/Quaternion.hpp
Base/ScriptSrc.cpp Base/ScriptSrc.hpp
Base/Shared.cpp Base/Shared.hpp
Base/Sphere.cpp Base/Sphere.hpp
Base/Utility.cpp Base/Utility.hpp
Base/VecMap.hpp
Base/Vector2.cpp Base/Vector2.hpp
Base/Vector2i.cpp Base/Vector2i.hpp
Base/Vector3.cpp Base/Vector3.hpp
Base/Vector4.cpp Base/Vector4.hpp
# Core
Core/Areas.cpp Core/Areas.hpp
Core/Buffer.cpp Core/Buffer.hpp
Core/Command.cpp Core/Command.hpp
Core/Common.cpp Core/Common.hpp
Core/Entity.cpp Core/Entity.hpp
Core/Routine.cpp Core/Routine.hpp
Core/Script.cpp Core/Script.hpp
Core/Signal.cpp Core/Signal.hpp
Core/Tasks.cpp Core/Tasks.hpp
Core/Utility.cpp Core/Utility.hpp
# Entity
Entity/Blip.cpp Entity/Blip.hpp
Entity/Checkpoint.cpp Entity/Checkpoint.hpp
Entity/Keybind.cpp Entity/Keybind.hpp
Entity/KeyBind.cpp Entity/KeyBind.hpp
Entity/Object.cpp Entity/Object.hpp
Entity/Pickup.cpp Entity/Pickup.hpp
Entity/Player.cpp Entity/Player.hpp
Entity/Vehicle.cpp Entity/Vehicle.hpp
# Library
Library/Chrono.cpp Library/Chrono.hpp
Library/Chrono/Date.cpp Library/Chrono/Date.hpp
Library/Chrono/Datetime.cpp Library/Chrono/Datetime.hpp
@@ -37,89 +59,49 @@ add_library(SqModule MODULE
Library/Chrono/Timer.cpp Library/Chrono/Timer.hpp
Library/Chrono/Timestamp.cpp Library/Chrono/Timestamp.hpp
Library/Crypt.cpp Library/Crypt.hpp
Library/Crypt/AES.cpp Library/Crypt/AES.hpp
Library/Crypt/Hash.cpp Library/Crypt/Hash.hpp
Library/CURL.cpp Library/CURL.hpp
Library/IO.cpp Library/IO.hpp
Library/IO/Buffer.cpp Library/IO/Buffer.hpp
Library/IO/File.cpp Library/IO/File.hpp
Library/IO/INI.cpp Library/IO/INI.hpp
Library/MMDB.cpp Library/MMDB.hpp
Library/IO/JSON.cpp Library/IO/JSON.hpp
Library/IO/XML.cpp Library/IO/XML.hpp
Library/Numeric.cpp Library/Numeric.hpp
Library/Numeric/LongInt.cpp Library/Numeric/LongInt.hpp
Library/Numeric/Long.cpp Library/Numeric/Long.hpp
Library/Numeric/Math.cpp Library/Numeric/Math.hpp
Library/Numeric/Random.cpp Library/Numeric/Random.hpp
Library/Socket.cpp Library/Socket.hpp
Library/SQLite.cpp Library/SQLite.hpp
Library/String.cpp Library/String.hpp
Library/System.cpp Library/System.hpp
Library/System/Dir.cpp Library/System/Dir.hpp
Library/System/Environment.cpp Library/System/Environment.hpp
Library/System/Env.cpp Library/System/Env.hpp
Library/System/Path.cpp Library/System/Path.hpp
Library/Utils.cpp Library/Utils.hpp
Library/Utils/Buffer.cpp Library/Utils/Buffer.hpp
Library/Web.cpp Library/Web.hpp
Library/Worker.cpp Library/Worker.hpp
Library/Worker/Job.cpp Library/Worker/Job.hpp
Library/Worker/Parameter.cpp Library/Worker/Parameter.hpp
Library/XML.cpp Library/XML.hpp
# Misc
Misc/Broadcast.cpp
Misc/Constants.cpp
Misc/Exports.cpp
Misc/Register.cpp
Misc/Algo.cpp Misc/Algo.hpp
Misc/Areas.cpp Misc/Areas.hpp
Misc/Command.cpp Misc/Command.hpp
Misc/Functions.cpp Misc/Functions.hpp
Misc/Model.cpp Misc/Model.hpp
Misc/Player.cpp Misc/Player.hpp
Misc/Privilege.cpp Misc/Privilege.hpp
Misc/Routine.cpp Misc/Routine.hpp
Misc/Signal.cpp Misc/Signal.hpp
Misc/Tasks.cpp Misc/Tasks.hpp
Misc/Vehicle.cpp Misc/Vehicle.hpp
Misc/Weapon.cpp Misc/Weapon.hpp
#
Core.cpp Core.hpp
Logger.cpp Logger.hpp
Register.cpp
)
# Include MINGW runtime into the binary
if(GCC OR MINGW)
if(BUILTIN_RUNTIMES)
target_link_libraries (SqModule -static gcc stdc++ winpthread -dynamic)
endif()
endif()
# Link to libraries
target_link_libraries(SqModule SqModSDK FmtLib SimpleINI HashLib B64Lib AES256Lib WhirlpoolLib TinyDir PUGIXML SQLite MaxmindDB CivetWeb SimpleSocket ConcurrentQueue)
# Link to windows libraries if on windows
if(WIN32 OR MINGW)
target_compile_definitions(SqModule PRIVATE _WIN32_WINNT=0x0601)
target_link_libraries(SqModule wsock32 ws2_32 shlwapi)
endif()
# Link to CURL libraries
if(ENABLE_CURL)
# Link to necessary libraries
target_link_libraries(SqModule libcurl cpr::cpr)
# Include the implementation
target_sources(SqModule PRIVATE Library/CURL.cpp Library/CURL.hpp)
# Specify that CURL is enabled
target_compile_definitions(SqModule PRIVATE SQ_ENABLE_CURL=1)
endif()
# Enable LTO
if(LTO_ENABLED)
target_link_libraries(SqModule -flto)
endif()
# Link to mysql client library
if(ENABLE_MYSQL)
# Include the implementation
target_sources(SqModule PRIVATE Library/MySQL.cpp Library/MySQL.hpp)
# Specify that mysql is enabled
target_compile_definitions(SqModule PRIVATE SQ_ENABLE_MYSQL=1)
# Use builting client on windows (for now)
if(WIN32 OR MINGW)
target_link_libraries(SqModule mariadbclient)
else()
find_package(MySQL)
target_link_libraries(SqModule MySQL::MySQL)
endif()
endif()
# Link to base libraries
target_link_libraries(SqModule Squirrel FmtLib SimpleINI TinyDir ConcurrentQueue cpr::cpr)
# Link to POCO libraries
target_link_libraries(SqModule Poco::Foundation Poco::Encodings Poco::Crypto Poco::Util Poco::Data Poco::Net Poco::JSON Poco::XML Poco::Zip Poco::JWT Poco::Redis)
# Determine if build mode
if(CMAKE_BUILD_TYPE MATCHES Release)
if(CMAKE_BUILD_TYPE MATCHES "(Release)+")
target_compile_definitions(SqModule PRIVATE NDEBUG=1)
else()
target_compile_definitions(SqModule PRIVATE _DEBUG=1 SQMOD_EXCEPTLOC=1)
@@ -146,5 +128,7 @@ else(WIN32)
endif(WIN32)
# Include current directory in the search path
target_include_directories(SqModule PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(SqModule PRIVATE ${CMAKE_CURRENT_LIST_DIR}/VCMP)
target_include_directories(SqModule PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Sqrat)
# Copy module into the plugins folder
add_custom_command(TARGET SqModule POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:SqModule> "${PROJECT_SOURCE_DIR}/bin/plugins")
+1576 -51
View File
File diff suppressed because it is too large Load Diff
+237 -824
View File
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
// ------------------------------------------------------------------------------------------------
#include "Misc/Areas.hpp"
#include "Core/Areas.hpp"
// ------------------------------------------------------------------------------------------------
#include <algorithm>
@@ -8,7 +8,7 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(AreaTypename, _SC("SqArea"))
SQMOD_DECL_TYPENAME(AreaTypename, _SC("SqArea"))
// ------------------------------------------------------------------------------------------------
AreaManager AreaManager::s_Inst;
@@ -113,7 +113,7 @@ bool Area::IsInside(float x, float y) const
// How many times the ray crosses a line segment
int crossings = 0;
// Iterate through each line
for (Uint32 i = 0, n = static_cast< Uint32 >(mPoints.size()); i < n; ++i)
for (uint32_t i = 0, n = static_cast< uint32_t >(mPoints.size()); i < n; ++i)
{
Points::const_reference a = mPoints[i];
Points::const_reference b = mPoints[(i + 1) % n];
@@ -139,7 +139,7 @@ bool Area::IsInside(float x, float y) const
if (fabsf(dx) < 0.000001f)
{
k = 0xffffffffu; // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
k = static_cast< float >(0xffffffffu); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
}
else
{
+15 -15
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
#include "Base/Circle.hpp"
#include "Base/Vector2.hpp"
#include "Base/Vector4.hpp"
@@ -183,7 +183,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert this instance to a string.
*/
const String & ToString() const
SQMOD_NODISCARD const String & ToString() const
{
return mName;
}
@@ -191,7 +191,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* Checks if the area is locked from changes and throws an exception if it is.
*/
void CheckLock()
void CheckLock() const
{
// Are we connected to any cells?
if (!mCells.empty())
@@ -203,7 +203,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* Retrieve the name of this area.
*/
const String & GetName() const
SQMOD_NODISCARD const String & GetName() const
{
return mName;
}
@@ -236,7 +236,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of this area.
*/
SQInteger GetID() const
SQMOD_NODISCARD SQInteger GetID() const
{
return mID;
}
@@ -261,7 +261,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* Check if the area is locked from changes
*/
bool IsLocked() const
SQMOD_NODISCARD bool IsLocked() const
{
return mCells.empty();
}
@@ -269,7 +269,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* Retrieve the center of this area.
*/
Vector2 GetCenter() const
SQMOD_NODISCARD Vector2 GetCenter() const
{
return {(mL * 0.5f) + (mR * 0.5f), (mB * 0.5f) + (mT * 0.5f)};
}
@@ -277,7 +277,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* Retrieve the bounding box of this area.
*/
Vector4 GetBoundingBox() const
SQMOD_NODISCARD Vector4 GetBoundingBox() const
{
return {mL, mB, mR, mT};
}
@@ -311,7 +311,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* See whether the area has no points.
*/
bool Empty() const
SQMOD_NODISCARD bool Empty() const
{
return mPoints.empty();
}
@@ -319,7 +319,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* Retrieve the number of points in this area.
*/
SQInteger Size() const
SQMOD_NODISCARD SQInteger Size() const
{
return ConvTo< SQInteger >::From(mPoints.size());
}
@@ -327,7 +327,7 @@ struct Area
/* --------------------------------------------------------------------------------------------
* Retrieve the number of points this area has allocated for.
*/
SQInteger Capacity() const
SQMOD_NODISCARD SQInteger Capacity() const
{
return ConvTo< SQInteger >::From(mPoints.capacity());
}
@@ -424,7 +424,7 @@ struct Area
// Is the given point in this bounding box at least?
if (mL <= v.x && mR >= v.x && mB <= v.y && mT >= v.y)
{
return mPoints.empty() ? true : IsInside(v.x, v.y);
return mPoints.empty() || IsInside(v.x, v.y);
}
// Not in this area
return false;
@@ -438,7 +438,7 @@ struct Area
// Is the given point in this bounding box at least?
if (mL <= x && mR >= x && mB <= y && mT >= y)
{
return mPoints.empty() ? true : IsInside(x, y);
return mPoints.empty() || IsInside(x, y);
}
// Not in this area
return false;
@@ -459,7 +459,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* Test if a point is inside the area.
*/
bool IsInside(float x, float y) const;
SQMOD_NODISCARD bool IsInside(float x, float y) const;
/* --------------------------------------------------------------------------------------------
* Expand the bounding box area to include the given point.
@@ -636,7 +636,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the core instance.
*/
static AreaManager & Get()
SQMOD_NODISCARD static AreaManager & Get()
{
return s_Inst;
}
@@ -1,11 +1,8 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Buffer.hpp"
#include "sqrat/sqratUtil.h"
#include "Core/Buffer.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstdlib>
#include <cstring>
#include <stdexcept>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -13,7 +10,7 @@ namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Compute the next power of two for the specified number.
*/
inline unsigned int NextPow2(unsigned int num)
SQMOD_NODISCARD inline unsigned int NextPow2(unsigned int num)
{
--num;
num |= num >> 1u;
@@ -24,33 +21,9 @@ inline unsigned int NextPow2(unsigned int num)
return ++num;
}
/* ------------------------------------------------------------------------------------------------
* Throw an memory exception.
*/
void ThrowMemExcept(const char * msg, ...)
{
// Exception messages should be concise
SQChar buffer[256];
// Variable arguments structure
va_list args;
// Get the specified arguments
va_start(args, msg);
// Run the specified format
int ret = std::vsnprintf(buffer, sizeof(buffer), msg, args);
// Check for formatting errors
if (ret < 0)
{
throw Sqrat::Exception(_SC("Unknown memory error")); // NOLINT(hicpp-exception-baseclass,cert-err60-cpp)
}
// Throw the actual exception
throw Sqrat::Exception(buffer); // NOLINT(hicpp-exception-baseclass,cert-err60-cpp)
}
// ------------------------------------------------------------------------------------------------
Buffer::Buffer(const Buffer & o)
: m_Ptr(nullptr)
, m_Cap(o.m_Cap)
, m_Cur(o.m_Cur)
: m_Ptr(nullptr), m_Cap(o.m_Cap), m_Cur(o.m_Cur)
{
if (m_Cap)
{
@@ -220,7 +193,7 @@ Buffer::SzType Buffer::WriteS(SzType pos, ConstPtr str)
if (str && *str != '\0')
{
// Forward this to the regular write function
return Write(pos, str, std::strlen(str));
return Write(pos, str, static_cast< SzType >(std::strlen(str)));
}
// Nothing to write
return 0;
@@ -244,7 +217,7 @@ void Buffer::AppendS(const char * str)
// Is there any string to write?
if (str)
{
m_Cur += Write(m_Cur, str, std::strlen(str));
m_Cur += Write(m_Cur, str, static_cast< SzType >(std::strlen(str)));
}
}
@@ -8,11 +8,19 @@
// ------------------------------------------------------------------------------------------------
#include <utility>
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include <fmt/core.h>
#include <sqratUtil.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
void ThrowMemExcept(const char * msg, ...);
template < class... Args > void ThrowMemExcept(Args &&... args)
{
throw Sqrat::Exception(fmt::format(std::forward< Args >(args)...));
}
/* ------------------------------------------------------------------------------------------------
* Reusable and re-scalable buffer memory for quick memory allocations.
@@ -38,6 +46,13 @@ public:
// --------------------------------------------------------------------------------------------
static_assert(sizeof(Value) == 1, "Value type must be 1 byte");
/* --------------------------------------------------------------------------------------------
* Disambiguation tags that can be passed to constructors to indicate that memory can be owned.
*/
struct OwnIt {
explicit OwnIt() = default;
};
private:
/* --------------------------------------------------------------------------------------------
@@ -53,23 +68,13 @@ private:
cur = 0;
}
/* --------------------------------------------------------------------------------------------
* Round a size value.
*/
template < typename T > static inline SzType RoundSz(T n)
{
return static_cast< SzType >(floor(n));
}
public:
/* --------------------------------------------------------------------------------------------
* Default constructor. (null)
*/
Buffer()
: m_Ptr(nullptr)
, m_Cap(0)
, m_Cur(0)
: m_Ptr(nullptr), m_Cap(0), m_Cur(0)
{
/* ... */
}
@@ -78,9 +83,7 @@ public:
* Explicit size constructor.
*/
explicit Buffer(SzType size)
: m_Ptr(nullptr)
, m_Cap(0)
, m_Cur(0)
: Buffer()
{
Request(size < 8 ? 8 : size);
}
@@ -89,9 +92,7 @@ public:
* Explicit size and cursor position constructor.
*/
Buffer(SzType size, SzType pos)
: m_Ptr(nullptr)
, m_Cap(0)
, m_Cur(0)
: Buffer()
{
Request(size < 8 ? 8 : size);
Move(pos);
@@ -101,27 +102,40 @@ public:
* Explicit size and buffer constructor.
*/
Buffer(ConstPtr data, SzType size)
: m_Ptr(nullptr)
, m_Cap(0)
, m_Cur(0)
: Buffer()
{
Request(size < 8 ? 8 : size);
m_Cur += Write(m_Cur, data, size);
}
/* --------------------------------------------------------------------------------------------
* Explicit size and buffer constructor with buffer stealing.
*/
Buffer(Pointer data, SzType size, OwnIt)
: m_Ptr(data), m_Cap(size), m_Cur(0)
{
}
/* --------------------------------------------------------------------------------------------
* Explicit size, data and cursor position constructor.
*/
Buffer(ConstPtr data, SzType size, SzType pos)
: m_Ptr(nullptr)
, m_Cap(0)
, m_Cur(0)
: Buffer()
{
Request(size < 8 ? 8 : size);
Write(m_Cur, data, size);
Move(pos);
}
/* --------------------------------------------------------------------------------------------
* Explicit size, data and cursor position constructor with buffer stealing.
*/
Buffer(Pointer data, SzType size, SzType pos, OwnIt)
: m_Ptr(data), m_Cap(size), m_Cur(0)
{
Move(pos);
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
@@ -131,9 +145,7 @@ public:
* Move constructor.
*/
Buffer(Buffer && o) noexcept
: m_Ptr(o.m_Ptr)
, m_Cap(o.m_Cap)
, m_Cur(o.m_Cur)
: m_Ptr(o.m_Ptr), m_Cap(o.m_Cap), m_Cur(o.m_Cur)
{
o.m_Ptr = nullptr;
}
@@ -234,7 +246,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer.
*/
Pointer Data()
SQMOD_NODISCARD Pointer Data()
{
return m_Ptr;
}
@@ -242,7 +254,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer.
*/
ConstPtr Data() const
SQMOD_NODISCARD ConstPtr Data() const
{
return m_Ptr;
}
@@ -250,7 +262,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer casted as a different type.
*/
template < typename T = Value > T * Get()
template < typename T = Value > SQMOD_NODISCARD T * Get()
{
return reinterpret_cast< T * >(m_Ptr);
}
@@ -258,7 +270,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer casted as a different type.
*/
template < typename T = Value > const T * Get() const
template < typename T = Value > SQMOD_NODISCARD const T * Get() const
{
return reinterpret_cast< const T * >(m_Ptr);
}
@@ -266,7 +278,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve a certain element type at the specified position.
*/
template < typename T = Value > T & At(SzType n)
template < typename T = Value > SQMOD_NODISCARD T & At(SzType n)
{
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
@@ -287,7 +299,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve a certain element type at the specified position.
*/
template < typename T = Value > const T & At(SzType n) const
template < typename T = Value > SQMOD_NODISCARD const T & At(SzType n) const
{
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
@@ -308,7 +320,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer casted as a different type.
*/
template < typename T = Value > T * Begin()
template < typename T = Value > SQMOD_NODISCARD T * Begin()
{
return reinterpret_cast< T * >(m_Ptr);
}
@@ -316,7 +328,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer casted as a different type.
*/
template < typename T = Value > const T * Begin() const
template < typename T = Value > SQMOD_NODISCARD const T * Begin() const
{
return reinterpret_cast< const T * >(m_Ptr);
}
@@ -324,7 +336,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer casted as a different type.
*/
template < typename T = Value > T * End()
template < typename T = Value > SQMOD_NODISCARD T * End()
{
return reinterpret_cast< T * >(m_Ptr) + (m_Cap / sizeof(T));
}
@@ -332,7 +344,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer casted as a different type.
*/
template < typename T = Value > const T * End() const
template < typename T = Value > SQMOD_NODISCARD const T * End() const
{
return reinterpret_cast< const T * >(m_Ptr) + (m_Cap / sizeof(T));
}
@@ -340,7 +352,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the front of the buffer.
*/
template < typename T = Value > T & Front()
template < typename T = Value > SQMOD_NODISCARD T & Front()
{
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
@@ -355,7 +367,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the front of the buffer.
*/
template < typename T = Value > const T & Front() const
template < typename T = Value > SQMOD_NODISCARD const T & Front() const
{
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
@@ -370,7 +382,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element after the first element in the buffer.
*/
template < typename T = Value > T & Next()
template < typename T = Value > SQMOD_NODISCARD T & Next()
{
// Make sure that the buffer can host at least two elements of this type
if (m_Cap < (sizeof(T) * 2))
@@ -385,7 +397,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element after the first element in the buffer.
*/
template < typename T = Value > const T & Next() const
template < typename T = Value > SQMOD_NODISCARD const T & Next() const
{
// Make sure that the buffer can host at least two elements of this type
if (m_Cap < (sizeof(T) * 2))
@@ -400,7 +412,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the back of the buffer.
*/
template < typename T = Value > T & Back()
template < typename T = Value > SQMOD_NODISCARD T & Back()
{
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
@@ -415,7 +427,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the back of the buffer.
*/
template < typename T = Value > const T & Back() const
template < typename T = Value > SQMOD_NODISCARD const T & Back() const
{
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
@@ -430,7 +442,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element before the last element in the buffer.
*/
template < typename T = Value > T & Prev()
template < typename T = Value > SQMOD_NODISCARD T & Prev()
{
// Make sure that the buffer can host at least two elements of this type
if (m_Cap < (sizeof(T) * 2))
@@ -445,7 +457,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element before the last element in the buffer.
*/
template < typename T = Value > const T & Prev() const
template < typename T = Value > SQMOD_NODISCARD const T & Prev() const
{
// Make sure that the buffer can host at least two elements of this type
if (m_Cap < (sizeof(T) * 2))
@@ -521,7 +533,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the cursor position.
*/
template < typename T = Value > T & Cursor()
template < typename T = Value > SQMOD_NODISCARD T & Cursor()
{
// Make sure that at least one element of this type exists after the cursor
if ((m_Cur + sizeof(T)) > m_Cap)
@@ -536,7 +548,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the cursor position.
*/
template < typename T = Value > const T & Cursor() const
template < typename T = Value > SQMOD_NODISCARD const T & Cursor() const
{
// Make sure that at least one element of this type exists after the cursor
if ((m_Cur + sizeof(T)) > m_Cap)
@@ -551,7 +563,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element before the cursor position.
*/
template < typename T = Value > T & Before()
template < typename T = Value > SQMOD_NODISCARD T & Before()
{
// The cursor must have at least one element of this type behind
if (m_Cur < sizeof(T))
@@ -566,7 +578,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element before the cursor position.
*/
template < typename T = Value > const T & Before() const
template < typename T = Value > SQMOD_NODISCARD const T & Before() const
{
// The cursor must have at least one element of this type behind
if (m_Cur < sizeof(T))
@@ -581,7 +593,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element after the cursor position.
*/
template < typename T = Value > T & After()
template < typename T = Value > SQMOD_NODISCARD T & After()
{
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
@@ -602,7 +614,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element after the cursor position.
*/
template < typename T = Value > const T & After() const
template < typename T = Value > SQMOD_NODISCARD const T & After() const
{
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
@@ -623,7 +635,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve maximum elements it can hold for a certain type.
*/
template < typename T = Value > static SzType Max()
template < typename T = Value > SQMOD_NODISCARD static SzType Max()
{
return static_cast< SzType >(0xFFFFFFFF / sizeof(T));
}
@@ -631,7 +643,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current buffer capacity in element count.
*/
template < typename T = Value > SzType Size() const
template < typename T = Value > SQMOD_NODISCARD SzType Size() const
{
return static_cast< SzType >(m_Cap / sizeof(T));
}
@@ -639,7 +651,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current buffer capacity in byte count.
*/
SzType Capacity() const
SQMOD_NODISCARD SzType Capacity() const
{
return m_Cap;
}
@@ -647,7 +659,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current buffer capacity in byte count.
*/
template < typename T = Value > SzType CapacityAs() const
template < typename T = Value > SQMOD_NODISCARD SzType CapacityAs() const
{
return static_cast< SzType >(m_Cap / sizeof(T));
}
@@ -655,7 +667,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current position of the cursor in the buffer.
*/
SzType Position() const
SQMOD_NODISCARD SzType Position() const
{
return m_Cur;
}
@@ -663,7 +675,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current position of the cursor in the buffer.
*/
template < typename T = Value > SzType PositionAs() const
template < typename T = Value > SQMOD_NODISCARD SzType PositionAs() const
{
return static_cast< SzType >(m_Cur / sizeof(T));
}
@@ -671,7 +683,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of unused buffer after the edit cursor.
*/
SzType Remaining() const
SQMOD_NODISCARD SzType Remaining() const
{
return m_Cap - m_Cur;
}
@@ -1,8 +1,8 @@
// ------------------------------------------------------------------------------------------------
#include <utility>
#include "Core/Command.hpp"
#include "Misc/Command.hpp"
// ------------------------------------------------------------------------------------------------
#include <sqratConst.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -15,8 +15,8 @@ Controllers Controller::s_Controllers;
Listener * Listener::s_Head = nullptr;
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(ManagerTypename, _SC("SqCmdManager"))
SQMODE_DECL_TYPENAME(ListenerTypename, _SC("SqCmdListener"))
SQMOD_DECL_TYPENAME(ManagerTypename, _SC("SqCmdManager"))
SQMOD_DECL_TYPENAME(ListenerTypename, _SC("SqCmdListener"))
// ------------------------------------------------------------------------------------------------
Guard::Guard(CtrRef ctr, Object & invoker)
@@ -151,7 +151,7 @@ Object & Controller::Attach(Object && obj, Listener * ptr)
}
// ------------------------------------------------------------------------------------------------
Object Manager::Create(StackStrF & name, StackStrF & spec, Array & tags, Uint8 min, Uint8 max, SQInteger auth, bool prot, bool assoc)
Object Manager::Create(StackStrF & name, StackStrF & spec, Array & tags, uint8_t min, uint8_t max, SQInteger auth, bool prot, bool assoc)
{
// Is there a controller to store the listener?
if (!m_Controller)
@@ -160,7 +160,7 @@ Object Manager::Create(StackStrF & name, StackStrF & spec, Array & tags, Uint8 m
}
// Script object and listener instance to be created and managed
Object obj;
Listener * ptr = nullptr;
Listener * ptr;
// Create the command listener
{
// Create a new instance of this class and make sure it can't get leaked due to exceptions
@@ -182,7 +182,7 @@ Object Manager::Create(StackStrF & name, StackStrF & spec, Array & tags, Uint8 m
}
// ------------------------------------------------------------------------------------------------
Int32 Controller::Run(const Guard & guard, CCStr command)
int32_t Controller::Run(const Guard & guard, const char * command)
{
// Validate the string command
if (!command || *command == '\0')
@@ -208,7 +208,7 @@ Int32 Controller::Run(const Guard & guard, CCStr command)
return -1;
}
// Where the name ends and argument begins
CCStr split = command;
const char * split = command;
// Find where the command name ends
while (*split != '\0' && !std::isspace(*split))
{
@@ -240,7 +240,7 @@ Int32 Controller::Run(const Guard & guard, CCStr command)
{
ValidateName(ctx.mCommand.c_str());
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
// Tell the script callback to deal with the error
SqError(CMDERR_INVALID_COMMAND, e.what(), guard.mCurrent->mInvoker);
@@ -279,7 +279,7 @@ Int32 Controller::Run(const Guard & guard, CCStr command)
{
return Exec(ctx);
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
// Tell the script callback to deal with the error
SqError(CMDERR_EXECUTION_FAILED, _SC("Exceptions occurred during execution"), e.what());
@@ -289,7 +289,7 @@ Int32 Controller::Run(const Guard & guard, CCStr command)
}
// ------------------------------------------------------------------------------------------------
Int32 Controller::Exec(Context & ctx)
int32_t Controller::Exec(Context & ctx)
{
// Clear previous arguments
ctx.mArgv.clear();
@@ -334,7 +334,7 @@ Int32 Controller::Exec(Context & ctx)
return -1;
}
// The check during the parsing may omit the last argument
else if (static_cast< Uint32 >(ctx.mInstance->GetMaxArgC()) < ctx.mArgc)
else if (static_cast< uint32_t >(ctx.mInstance->GetMaxArgC()) < ctx.mArgc)
{
// Tell the script callback to deal with the error
SqError(CMDERR_EXTRANEOUS_ARGS, _SC("Extraneous command arguments"), ctx.mInstance->GetMaxArgC());
@@ -342,7 +342,7 @@ Int32 Controller::Exec(Context & ctx)
return -1;
}
// Check argument types against the command specifiers
for (Uint32 arg = 0; arg < ctx.mArgc; ++arg)
for (uint32_t arg = 0; arg < ctx.mArgc; ++arg)
{
if (!ctx.mInstance->ArgCheck(arg, ctx.mArgv[arg].first))
{
@@ -364,7 +364,7 @@ Int32 Controller::Exec(Context & ctx)
// Create the associative container
Table args(SqVM());
// Copy the arguments into the table
for (Uint32 arg = 0; arg < ctx.mArgc; ++arg)
for (uint32_t arg = 0; arg < ctx.mArgc; ++arg)
{
// Do we have use the argument index as the key?
if (ctx.mInstance->m_ArgTags[arg].empty())
@@ -395,7 +395,7 @@ Int32 Controller::Exec(Context & ctx)
// Reserve an array for the extracted arguments
Array args(SqVM(), ctx.mArgc);
// Copy the arguments into the array
for (Uint32 arg = 0; arg < ctx.mArgc; ++arg)
for (uint32_t arg = 0; arg < ctx.mArgc; ++arg)
{
args.Bind(SQInteger(arg), ctx.mArgv[arg].second);
}
@@ -425,7 +425,7 @@ Int32 Controller::Exec(Context & ctx)
{
ctx.mInstance->m_OnFail.Execute(ctx.mInvoker, result);
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
// Tell the script callback to deal with the error
SqError(CMDERR_UNRESOLVED_FAILURE, _SC("Unable to resolve command failure"), e.what());
@@ -447,7 +447,7 @@ Int32 Controller::Exec(Context & ctx)
{
ctx.mInstance->m_OnFail.Execute(ctx.mInvoker, result);
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
// Tell the script callback to deal with the error
SqError(CMDERR_UNRESOLVED_FAILURE, _SC("Unable to resolve command failure"), e.what());
@@ -462,14 +462,14 @@ Int32 Controller::Exec(Context & ctx)
{
ctx.mInstance->m_OnPost.Execute(ctx.mInvoker, result);
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
// Tell the script callback to deal with the error
SqError(CMDERR_POST_PROCESSING_FAILED, _SC("Unable to complete command post processing"), e.what());
}
}
// Return the result
return ConvTo< Int32 >::From(result);
return ConvTo< int32_t >::From(result);
}
// ------------------------------------------------------------------------------------------------
@@ -481,7 +481,7 @@ bool Controller::Parse(Context & ctx)
return true; // Done parsing!
}
// Obtain the flags of the currently processed argument
Uint8 arg_flags = ctx.mInstance->m_ArgSpec[ctx.mArgc];
uint8_t arg_flags = ctx.mInstance->m_ArgSpec[ctx.mArgc];
// Adjust the internal buffer if necessary (mostly never)
ctx.mBuffer.Adjust(static_cast< Buffer::SzType >(ctx.mArgument.size()));
// The iterator to the currently processed character
@@ -489,7 +489,7 @@ bool Controller::Parse(Context & ctx)
// Previous and currently processed character
String::value_type prev = 0, elem = 0;
// Maximum arguments allowed to be processed
const Uint8 max_arg = ctx.mInstance->m_MaxArgc;
const uint8_t max_arg = ctx.mInstance->m_MaxArgc;
// Process loop result
bool good = true;
// Process the specified command text
@@ -531,8 +531,8 @@ bool Controller::Parse(Context & ctx)
else if ((elem == '\'' || elem == '"') && prev != '\\')
{
// Obtain the beginning and ending of the internal buffer
SStr str = ctx.mBuffer.Begin< SQChar >();
SStr end = (ctx.mBuffer.End< SQChar >() - 1); // + null terminator
auto * str = ctx.mBuffer.Begin< SQChar >();
auto * end = (ctx.mBuffer.End< SQChar >() - 1); // + null terminator
// Save the closing quote type
const SQChar close = elem;
// Skip the opening quote
@@ -596,7 +596,7 @@ bool Controller::Parse(Context & ctx)
// Do we have to make the string lowercase?
if (arg_flags & CMDARG_LOWER)
{
for (CStr chr = str; chr < end; ++chr)
for (char * chr = str; chr < end; ++chr)
{
*chr = static_cast< SQChar >(std::tolower(*chr));
}
@@ -604,7 +604,7 @@ bool Controller::Parse(Context & ctx)
// Do we have to make the string uppercase?
else if (arg_flags & CMDARG_UPPER)
{
for (CStr chr = str; chr < end; ++chr)
for (char * chr = str; chr < end; ++chr)
{
*chr = static_cast< SQChar >(std::toupper(*chr));
}
@@ -634,9 +634,9 @@ bool Controller::Parse(Context & ctx)
// Find the first space character that marks the end of the argument
String::const_iterator pos = std::find_if(itr, ctx.mArgument.cend(), IsCType(std::isspace));
// Obtain both ends of the argument string
CCStr str = &(*itr), end = &(*pos);
const char * str = &(*itr), * end = &(*pos);
// Compute the argument string size
const auto sz = static_cast< const Uint32 >(std::distance(itr, pos));
const auto sz = static_cast< const uint32_t >(std::distance(itr, pos));
// Update the main iterator position
itr = pos;
// Update the currently processed character
@@ -647,9 +647,9 @@ bool Controller::Parse(Context & ctx)
if (!identified && (arg_flags & CMDARG_INTEGER))
{
// Let's us know if the whole argument was part of the resulted value
CStr next = nullptr;
char * next = nullptr;
// Attempt to extract the integer value from the string
const Int64 value = std::strtoll(str, &next, 10);
const int64_t value = std::strtoll(str, &next, 10);
// See if this whole string was indeed an integer
if (next == end)
{
@@ -667,12 +667,12 @@ bool Controller::Parse(Context & ctx)
if (!identified && (arg_flags & CMDARG_FLOAT))
{
// Let's us know if the whole argument was part of the resulted value
CStr next = nullptr;
char * next = nullptr;
// Attempt to extract the float value from the string
#ifdef SQUSEDOUBLE
const Float64 value = std::strtod(str, &next);
const double value = std::strtod(str, &next);
#else
const Float32 value = std::strtof(str, &next);
const float value = std::strtof(str, &next);
#endif // SQUSEDOUBLE
// See if this whole string was indeed an float
if (next == end)
@@ -694,8 +694,8 @@ bool Controller::Parse(Context & ctx)
// Allocate memory for enough data to form a boolean value
CharT lc[6];
// Don't modify the original string or buffer pointer
CStr bptr = lc;
CSStr sptr = str;
char * bptr = lc;
const SQChar * sptr = str;
// Fill the temporary buffer with data from the internal buffer
for (; sptr < end; ++sptr, ++bptr)
{
@@ -737,7 +737,7 @@ bool Controller::Parse(Context & ctx)
if (arg_flags & CMDARG_LOWER)
{
// Convert all characters from the argument string into the buffer
for (CStr chr = ctx.mBuffer.Data(); str < end; ++str, ++chr)
for (char * chr = ctx.mBuffer.Data(); str < end; ++str, ++chr)
{
*chr = static_cast< CharT >(std::tolower(*str));
}
@@ -748,7 +748,7 @@ bool Controller::Parse(Context & ctx)
else if (arg_flags & CMDARG_UPPER)
{
// Convert all characters from the argument string into the buffer
for (CStr chr = ctx.mBuffer.Data(); str < end; ++str, ++chr)
for (char * chr = ctx.mBuffer.Data(); str < end; ++str, ++chr)
{
*chr = static_cast< CharT >(std::toupper(*str));
}
@@ -767,7 +767,7 @@ bool Controller::Parse(Context & ctx)
arg_flags = ctx.mInstance->m_ArgSpec[++ctx.mArgc];
}
// Is there anything left to parse?
if (itr >= ctx.mArgument.end())
if (itr >= ctx.mArgument.end()) // NOLINT(modernize-use-nullptr)
{
break;
}
@@ -784,7 +784,7 @@ void Listener::GenerateInfo(bool full)
// Clear any previously generated informational message
m_Info.clear();
// Process each supported command argument
for (Uint32 arg = 0; arg < m_MaxArgc; ++arg)
for (uint32_t arg = 0; arg < m_MaxArgc; ++arg)
{
// If this is not a full command request then see if we must stop
if (!full)
@@ -792,7 +792,7 @@ void Listener::GenerateInfo(bool full)
// Default to stop if criteria are not meet
bool stop = true;
// Check all arguments after this and see if there's any left
for (Uint32 idx = arg; idx < m_MaxArgc; ++idx)
for (uint32_t idx = arg; idx < m_MaxArgc; ++idx)
{
// If the argument has a name or a type specifier then it's valid
if (!m_ArgTags[idx].empty() || m_ArgSpec[idx] != CMDARG_ANY)
@@ -825,7 +825,7 @@ void Listener::GenerateInfo(bool full)
m_Info.push_back(':');
}
// Obtain the argument specifier
const Uint8 spec = m_ArgSpec[arg];
const uint8_t spec = m_ArgSpec[arg];
// Is this a greedy argument?
if (spec & CMDARG_GREEDY)
{
@@ -894,7 +894,7 @@ void Listener::GenerateInfo(bool full)
}
// ------------------------------------------------------------------------------------------------
void Listener::ProcSpec(CSStr str)
void Listener::ProcSpec(const SQChar * str)
{
// Reset current argument specifiers
std::memset(m_ArgSpec, CMDARG_ANY, sizeof(m_ArgSpec));
@@ -904,7 +904,7 @@ void Listener::ProcSpec(CSStr str)
return;
}
// Currently processed argument
Uint32 idx = 0;
uint32_t idx = 0;
// Try to apply the specified type specifiers
try
{
@@ -1010,7 +1010,7 @@ void Listener::ProcSpec(CSStr str)
}
}
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
// Reset all argument specifiers if failed
std::memset(m_ArgSpec, CMDARG_ANY, sizeof(m_ArgSpec));
@@ -1070,11 +1070,11 @@ void Register(HSQUIRRELVM vm)
.Ctor< StackStrF & >()
.Ctor< StackStrF &, StackStrF & >()
.Ctor< StackStrF &, StackStrF &, Array & >()
.Ctor< StackStrF &, StackStrF &, Uint8, Uint8 >()
.Ctor< StackStrF &, StackStrF &, Array &, Uint8, Uint8 >()
.Ctor< StackStrF &, StackStrF &, Array &, Uint8, Uint8, SQInteger >()
.Ctor< StackStrF &, StackStrF &, Array &, Uint8, Uint8, SQInteger, bool >()
.Ctor< StackStrF &, StackStrF &, Array &, Uint8, Uint8, SQInteger, bool, bool >()
.Ctor< StackStrF &, StackStrF &, uint8_t, uint8_t >()
.Ctor< StackStrF &, StackStrF &, Array &, uint8_t, uint8_t >()
.Ctor< StackStrF &, StackStrF &, Array &, uint8_t, uint8_t, SQInteger >()
.Ctor< StackStrF &, StackStrF &, Array &, uint8_t, uint8_t, SQInteger, bool >()
.Ctor< StackStrF &, StackStrF &, Array &, uint8_t, uint8_t, SQInteger, bool, bool >()
// Meta-methods
.SquirrelFunc(_SC("_typename"), &ListenerTypename::Fn)
.Func(_SC("_tostring"), &Listener::ToString)
@@ -1,8 +1,8 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Logger.hpp"
// ------------------------------------------------------------------------------------------------
@@ -15,7 +15,7 @@
#include <algorithm>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace SqMod { // NOLINT(modernize-concat-nested-namespaces)
namespace Cmd {
/* ------------------------------------------------------------------------------------------------
@@ -41,7 +41,7 @@ typedef SharedPtr< Controller > CtrRef; // Shared reference to a command con
typedef WeakPtr< Controller > CtrPtr; // Shared reference to a command controller.
// ------------------------------------------------------------------------------------------------
typedef std::pair< Uint8, Object > Argument; // Can hold the argument value and type.
typedef std::pair< uint8_t, Object > Argument; // Can hold the argument value and type.
typedef std::vector< Argument > Arguments; // A list of extracted arguments.
// ------------------------------------------------------------------------------------------------
@@ -105,7 +105,7 @@ enum CmdError
};
// ------------------------------------------------------------------------------------------------
inline CSStr ValidateName(CSStr name)
inline const SQChar * ValidateName(const SQChar * name)
{
// Is the name empty?
if (!name || *name == '\0')
@@ -113,7 +113,7 @@ inline CSStr ValidateName(CSStr name)
STHROWF("Invalid or empty command name");
}
// Create iterator to name start
CSStr str = name;
const SQChar * str = name;
// Inspect name characters
while ('\0' != *str)
{
@@ -130,7 +130,7 @@ inline CSStr ValidateName(CSStr name)
}
// ------------------------------------------------------------------------------------------------
inline CSStr ArgSpecToStr(Uint8 spec)
inline const SQChar * ArgSpecToStr(uint8_t spec)
{
switch (spec)
{
@@ -165,7 +165,7 @@ public:
// --------------------------------------------------------------------------------------------
Arguments mArgv; // Extracted command arguments.
Uint32 mArgc; // Extracted arguments count.
uint32_t mArgc; // Extracted arguments count.
/* --------------------------------------------------------------------------------------------
* Default constructor.
@@ -259,7 +259,7 @@ struct Command
String mName; // The unique name that identifies this command.
Listener* mPtr; // The listener that reacts to this command.
Object mObj; // A strong reference to the script object.
CtrPtr mCtr; // The associated contoller.
CtrPtr mCtr; // The associated controller.
/* --------------------------------------------------------------------------------------------
* Construct a command and the also create a script object from the specified listener.
@@ -378,7 +378,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* Forward error message to the error callback.
*/
template < typename T > void SqError(Int32 type, CSStr msg, T data)
template < typename T > void SqError(int32_t type, const SQChar * msg, T data)
{
// Is there a callback that deals with errors?
if (m_OnFail.IsNull())
@@ -390,7 +390,7 @@ protected:
{
m_OnFail.Execute(type, msg, data);
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
// The debugger probably took care of reporting the details
LogErr("Command error callback failed [%s]", e.what());
@@ -400,12 +400,12 @@ protected:
/* --------------------------------------------------------------------------------------------
* Execute one of the managed commands.
*/
Int32 Run(const Guard & guard, CSStr command);
int32_t Run(const Guard & guard, const SQChar * command);
/* --------------------------------------------------------------------------------------------
* Attempt to execute the specified command.
*/
Int32 Exec(Context & ctx);
int32_t Exec(Context & ctx);
/* --------------------------------------------------------------------------------------------
* Attempt to parse the specified argument.
@@ -530,7 +530,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the currently active execution context.
*/
const CtxRef & GetCtx() const
SQMOD_NODISCARD const CtxRef & GetCtx() const
{
return m_Context;
}
@@ -538,12 +538,12 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether a certain name exist in the command list.
*/
bool Attached(const String & name) const
SQMOD_NODISCARD bool Attached(const String & name) const
{
// Obtain the unique identifier of the specified name
const std::size_t hash = std::hash< String >()(name);
// Attempt to find the specified command
for (const auto & cmd : m_Commands)
for (const auto & cmd : m_Commands) // NOLINT(readability-use-anyofallof)
{
// Are the hashes identical?
if (cmd.mHash == hash)
@@ -561,7 +561,7 @@ public:
bool Attached(const Listener * ptr) const
{
// Attempt to find the specified command
for (const auto & cmd : m_Commands)
for (const auto & cmd : m_Commands) // NOLINT(readability-use-anyofallof)
{
// Are the instances identical?
if (cmd.mPtr == ptr)
@@ -580,7 +580,7 @@ public:
{
std::sort(m_Commands.begin(), m_Commands.end(),
[](Commands::const_reference a, Commands::const_reference b) -> bool {
return (a.mName < b.mName);
return (a.mName < b.mName); // NOLINT(modernize-use-nullptr)
});
}
@@ -647,7 +647,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether an execution context is currently active.
*/
bool IsContext() const
SQMOD_NODISCARD bool IsContext() const
{
return !!m_Context;
}
@@ -655,7 +655,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the invoker from the current execution context.
*/
const Object & GetInvoker() const
SQMOD_NODISCARD const Object & GetInvoker() const
{
// See if there's an execution context available
if (!m_Context)
@@ -669,7 +669,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the listener object from the current execution context.
*/
const Object & GetListener() const
SQMOD_NODISCARD const Object & GetListener() const
{
// See if there's an execution context available
if (!m_Context)
@@ -683,7 +683,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the command name from the current execution context.
*/
const String & GetCommand() const
SQMOD_NODISCARD const String & GetCommand() const
{
// See if there's an execution context available
if (!m_Context)
@@ -697,7 +697,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the command argument from the current execution context.
*/
const String & GetArgument() const
SQMOD_NODISCARD const String & GetArgument() const
{
// See if there's an execution context available
if (!m_Context)
@@ -711,7 +711,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve all command listeners in an array.
*/
Array GetCommandsArray() const
SQMOD_NODISCARD Array GetCommandsArray() const
{
// Allocate an array with an adequate size
Array arr(SqVM(), m_Commands.size());
@@ -729,7 +729,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve all command listeners in a table.
*/
Table GetCommandsTable() const
SQMOD_NODISCARD Table GetCommandsTable() const
{
// Allocate an empty table
Table tbl(SqVM());
@@ -773,7 +773,7 @@ private:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated controller if valid otherwise throw an exception.
*/
const CtrRef & GetValid() const
SQMOD_NODISCARD const CtrRef & GetValid() const
{
// Validate the managed controller
if (!m_Controller)
@@ -818,7 +818,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Manager & o) const
SQMOD_NODISCARD int32_t Cmp(const Manager & o) const
{
if (m_Controller == o.m_Controller)
{
@@ -837,15 +837,15 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert this instance to a string.
*/
CSStr ToString() const
SQMOD_NODISCARD String ToString() const
{
return ToStrF("%d", m_Controller.Count());
return fmt::format("{}", m_Controller.Count());
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated controller reference.
*/
const CtrRef & GetCtr() const
SQMOD_NODISCARD const CtrRef & GetCtr() const
{
return m_Controller;
}
@@ -853,7 +853,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of references to the managed controller.
*/
Uint32 GetRefCount() const
SQMOD_NODISCARD uint32_t GetRefCount() const
{
return m_Controller.Count();
}
@@ -861,11 +861,11 @@ public:
/* --------------------------------------------------------------------------------------------
* Run a command under a specific invoker.
*/
Int32 Run(Object & invoker, StackStrF & command)
int32_t Run(Object & invoker, StackStrF & command)
{
if ((SQ_FAILED(command.Proc())))
{
return static_cast< Int32 >(command.mRes);
return static_cast< int32_t >(command.mRes);
}
else
{
@@ -918,7 +918,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of managed command listeners.
*/
SQInteger GetCount() const
SQMOD_NODISCARD SQInteger GetCount() const
{
return ConvTo< SQInteger >::From(GetValid()->m_Commands.size());
}
@@ -926,7 +926,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether an execution context is currently active.
*/
bool IsContext() const
SQMOD_NODISCARD bool IsContext() const
{
return GetValid()->IsContext();
}
@@ -966,7 +966,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the invoker from the current execution context.
*/
const Object & GetInvoker() const
SQMOD_NODISCARD const Object & GetInvoker() const
{
return GetValid()->GetInvoker();
}
@@ -974,7 +974,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the listener object from the current execution context.
*/
const Object & GetListener() const
SQMOD_NODISCARD const Object & GetListener() const
{
return GetValid()->GetListener();
}
@@ -982,7 +982,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the command name from the current execution context.
*/
const String & GetCommand() const
SQMOD_NODISCARD const String & GetCommand() const
{
return GetValid()->GetCommand();
}
@@ -990,7 +990,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the command argument from the current execution context.
*/
const String & GetArgument() const
SQMOD_NODISCARD const String & GetArgument() const
{
return GetValid()->GetArgument();
}
@@ -998,7 +998,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve all command listeners in an array.
*/
Array GetCommandsArray() const
SQMOD_NODISCARD Array GetCommandsArray() const
{
return GetValid()->GetCommandsArray();
}
@@ -1006,7 +1006,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve all command listeners in a table.
*/
Table GetCommandsTable() const
SQMOD_NODISCARD Table GetCommandsTable() const
{
return GetValid()->GetCommandsTable();
}
@@ -1024,7 +1024,7 @@ public:
*/
Object Create1(StackStrF & name)
{
return Create(name, DummyStackStrF(), NullArray(), 0, SQMOD_MAX_CMD_ARGS-1, -1, false, false);
return Create(name, StackStrF::Dummy(), NullArray(), 0, SQMOD_MAX_CMD_ARGS-1, -1, false, false);
}
/* --------------------------------------------------------------------------------------------
@@ -1046,7 +1046,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Create command instances and obtain the associated object.
*/
Object Create4(StackStrF & name, StackStrF & spec, Uint8 min, Uint8 max)
Object Create4(StackStrF & name, StackStrF & spec, uint8_t min, uint8_t max)
{
return Create(name, spec, NullArray(), min, max, -1, false, false);
}
@@ -1054,7 +1054,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Create command instances and obtain the associated object.
*/
Object Create5(StackStrF & name, StackStrF & spec, Array & tags, Uint8 min, Uint8 max)
Object Create5(StackStrF & name, StackStrF & spec, Array & tags, uint8_t min, uint8_t max)
{
return Create(name, spec, tags, min, max, -1, false, false);
}
@@ -1062,7 +1062,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Create command instances and obtain the associated object.
*/
Object Create6(StackStrF & name, StackStrF & spec, Array & tags, Uint8 min, Uint8 max, SQInteger auth)
Object Create6(StackStrF & name, StackStrF & spec, Array & tags, uint8_t min, uint8_t max, SQInteger auth)
{
return Create(name, spec, tags, min, max, auth, auth >= 0, false);
}
@@ -1070,7 +1070,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Create command instances and obtain the associated object.
*/
Object Create7(StackStrF & name, StackStrF & spec, Array & tags, Uint8 min, Uint8 max, SQInteger auth, bool prot)
Object Create7(StackStrF & name, StackStrF & spec, Array & tags, uint8_t min, uint8_t max, SQInteger auth, bool prot)
{
return Create(name, spec, tags, min, max, auth, prot, false);
}
@@ -1078,7 +1078,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Create command instances and obtain the associated object.
*/
Object Create(StackStrF & name, StackStrF & spec, Array & tags, Uint8 min, Uint8 max, SQInteger auth, bool prot, bool assoc);
Object Create(StackStrF & name, StackStrF & spec, Array & tags, uint8_t min, uint8_t max, SQInteger auth, bool prot, bool assoc);
};
/* ------------------------------------------------------------------------------------------------
@@ -1124,7 +1124,7 @@ public:
* Convenience constructor.
*/
explicit Listener(StackStrF & name)
: Listener(name, DummyStackStrF(), NullArray(), 0, SQMOD_MAX_CMD_ARGS-1, -1, false, false)
: Listener(name, StackStrF::Dummy(), NullArray(), 0, SQMOD_MAX_CMD_ARGS-1, -1, false, false)
{
/* ... */
}
@@ -1150,7 +1150,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Convenience constructor.
*/
Listener(StackStrF & name, StackStrF & spec, Uint8 min, Uint8 max)
Listener(StackStrF & name, StackStrF & spec, uint8_t min, uint8_t max)
: Listener(name, spec, NullArray(), min, max, -1, false, false)
{
/* ... */
@@ -1159,7 +1159,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Convenience constructor.
*/
Listener(StackStrF & name, StackStrF & spec, Array & tags, Uint8 min, Uint8 max)
Listener(StackStrF & name, StackStrF & spec, Array & tags, uint8_t min, uint8_t max)
: Listener(name, spec, tags, min, max, -1, false, false)
{
/* ... */
@@ -1168,7 +1168,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Convenience constructor.
*/
Listener(StackStrF & name, StackStrF & spec, Array & tags, Uint8 min, Uint8 max, SQInteger auth)
Listener(StackStrF & name, StackStrF & spec, Array & tags, uint8_t min, uint8_t max, SQInteger auth)
: Listener(name, spec, tags, min, max, auth, auth >= 0, false)
{
/* ... */
@@ -1177,7 +1177,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Convenience constructor.
*/
Listener(StackStrF & name, StackStrF & spec, Array & tags, Uint8 min, Uint8 max, SQInteger auth, bool prot)
Listener(StackStrF & name, StackStrF & spec, Array & tags, uint8_t min, uint8_t max, SQInteger auth, bool prot)
: Listener(name, spec, tags, min, max, auth, prot, false)
{
/* ... */
@@ -1186,7 +1186,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
Listener(StackStrF & name, StackStrF & spec, Array & tags, Uint8 min, Uint8 max, SQInteger auth, bool prot, bool assoc)
Listener(StackStrF & name, StackStrF & spec, Array & tags, uint8_t min, uint8_t max, SQInteger auth, bool prot, bool assoc)
: m_Controller()
, m_Name()
, m_ArgSpec()
@@ -1200,7 +1200,7 @@ public:
, m_OnAuth()
, m_OnPost()
, m_OnFail()
, m_Authority(ConvTo< Int32 >::From(auth))
, m_Authority(ConvTo< int32_t >::From(auth))
, m_Protected(prot)
, m_Suspended(false)
, m_Associate(assoc)
@@ -1303,7 +1303,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Listener & o) const
SQMOD_NODISCARD int32_t Cmp(const Listener & o) const
{
if (m_Name == o.m_Name)
{
@@ -1322,7 +1322,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert this instance to a string.
*/
const String & ToString() const
SQMOD_NODISCARD const String & ToString() const
{
return m_Name;
}
@@ -1330,7 +1330,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of weak references to the managed controller.
*/
Uint32 GetRefCount() const
SQMOD_NODISCARD uint32_t GetRefCount() const
{
return m_Controller.Count();
}
@@ -1373,7 +1373,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the listener instance is attached to the associated command name.
*/
bool Attached() const
SQMOD_NODISCARD bool Attached() const
{
return (!m_Controller.Expired() && m_Controller.Lock()->Attached(this));
}
@@ -1381,7 +1381,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the manager associated with this command listener instance.
*/
Object GetManager() const
SQMOD_NODISCARD Object GetManager() const
{
// Are we even associated with a controller?
if (m_Controller.Expired())
@@ -1399,7 +1399,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the name that triggers this command listener instance.
*/
const String & GetName() const
SQMOD_NODISCARD const String & GetName() const
{
return m_Name;
}
@@ -1452,7 +1452,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the argument specification string.
*/
const String & GetSpec() const
SQMOD_NODISCARD const String & GetSpec() const
{
return m_Spec;
}
@@ -1483,12 +1483,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the argument tags array.
*/
Array GetArgTags() const
SQMOD_NODISCARD Array GetArgTags() const
{
// Allocate an array to encapsulate all tags
Array arr(SqVM(), SQMOD_MAX_CMD_ARGS);
// Put the tags to the allocated array
for (Uint32 arg = 0; arg < SQMOD_MAX_CMD_ARGS; ++arg)
for (uint32_t arg = 0; arg < SQMOD_MAX_CMD_ARGS; ++arg)
{
arr.SetValue(arg, m_ArgTags[arg]);
}
@@ -1512,7 +1512,7 @@ public:
return;
}
// Attempt to retrieve the number of specified tags
const Uint32 max = ConvTo< Uint32 >::From(tags.Length());
const uint32_t max = ConvTo< uint32_t >::From(tags.Length());
// If no tags were specified then clear current tags
if (!max)
{
@@ -1536,7 +1536,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the help message associated with this command listener instance.
*/
const String & GetHelp() const
SQMOD_NODISCARD const String & GetHelp() const
{
return m_Help;
}
@@ -1563,7 +1563,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the informational message associated with this command listener instance.
*/
const String & GetInfo() const
SQMOD_NODISCARD const String & GetInfo() const
{
return m_Info;
}
@@ -1590,7 +1590,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the authority level required to execute this command listener instance.
*/
SQInteger GetAuthority() const
SQMOD_NODISCARD SQInteger GetAuthority() const
{
return m_Authority;
}
@@ -1600,13 +1600,13 @@ public:
*/
void SetAuthority(SQInteger level)
{
m_Authority = ConvTo< Int32 >::From(level);
m_Authority = ConvTo< int32_t >::From(level);
}
/* --------------------------------------------------------------------------------------------
* See whether this command listener instance requires explicit authority inspection.
*/
bool GetProtected() const
SQMOD_NODISCARD bool GetProtected() const
{
return m_Protected;
}
@@ -1622,7 +1622,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether this command listener instance is currently ignoring calls.
*/
bool GetSuspended() const
SQMOD_NODISCARD bool GetSuspended() const
{
return m_Suspended;
}
@@ -1638,7 +1638,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether this command listener instance receives arguments in an associative container.
*/
bool GetAssociate() const
SQMOD_NODISCARD bool GetAssociate() const
{
return m_Associate;
}
@@ -1654,7 +1654,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum arguments supported by this command listener.
*/
Uint8 GetMinArgC() const
SQMOD_NODISCARD uint8_t GetMinArgC() const
{
return m_MinArgc;
}
@@ -1665,24 +1665,24 @@ public:
void SetMinArgC(SQInteger val)
{
// Limit the specified number withing allowed range
val = ConvTo< Uint8 >::From(val);
val = ConvTo< uint8_t >::From(val);
// Perform a range check on the specified argument index
if (val >= SQMOD_MAX_CMD_ARGS)
{
STHROWF("Argument (%d) is out of total range (%d)", val, SQMOD_MAX_CMD_ARGS);
}
else if (static_cast< Uint8 >(val) > m_MaxArgc)
else if (static_cast< uint8_t >(val) > m_MaxArgc)
{
STHROWF("Minimum argument (%d) exceeds maximum (%u)", val, m_MaxArgc);
}
// Apply the specified value
m_MinArgc = static_cast< Uint8 >(val);
m_MinArgc = static_cast< uint8_t >(val);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum arguments supported by this command listener.
*/
SQInteger GetMaxArgC() const
SQMOD_NODISCARD SQInteger GetMaxArgC() const
{
return m_MaxArgc;
}
@@ -1693,18 +1693,18 @@ public:
void SetMaxArgC(SQInteger val)
{
// Limit the specified number withing allowed range
val = ConvTo< Uint8 >::From(val);
val = ConvTo< uint8_t >::From(val);
// Perform a range check on the specified argument index
if (val >= SQMOD_MAX_CMD_ARGS)
{
STHROWF("Argument (%d) is out of total range (%d)", val, SQMOD_MAX_CMD_ARGS);
}
else if (static_cast< Uint8 >(val) < m_MinArgc)
else if (static_cast< uint8_t >(val) < m_MinArgc)
{
STHROWF("Maximum argument (%d) exceeds minimum (%u)", val, m_MinArgc);
}
// Apply the specified value
m_MaxArgc = static_cast< Uint8 >(val);
m_MaxArgc = static_cast< uint8_t >(val);
}
/* --------------------------------------------------------------------------------------------
@@ -1774,7 +1774,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the tag of a certain argument.
*/
const String & GetArgTag(Uint32 arg) const
SQMOD_NODISCARD const String & GetArgTag(uint32_t arg) const
{
// Perform a range check on the specified argument index
if (arg >= SQMOD_MAX_CMD_ARGS)
@@ -1788,7 +1788,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the tag of a certain argument.
*/
void SetArgTag(Uint32 arg, StackStrF & name)
void SetArgTag(uint32_t arg, StackStrF & name)
{
// Perform a range check on the specified argument index
if (arg >= SQMOD_MAX_CMD_ARGS)
@@ -1814,7 +1814,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the flags of the specified argument.
*/
Uint8 GetArgFlags(Uint32 idx) const
SQMOD_NODISCARD uint8_t GetArgFlags(uint32_t idx) const
{
// Perform a range check on the specified argument index
if (idx >= SQMOD_MAX_CMD_ARGS)
@@ -1828,7 +1828,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether whether the specified argument can be used on this command listener instance.
*/
bool ArgCheck(Uint32 arg, Uint8 flag) const
SQMOD_NODISCARD bool ArgCheck(uint32_t arg, uint8_t flag) const
{
// Perform a range check on the specified argument index
if (arg >= SQMOD_MAX_CMD_ARGS)
@@ -1836,7 +1836,7 @@ public:
STHROWF("Argument (%u) is out of total range (%u)", arg, SQMOD_MAX_CMD_ARGS);
}
// Retrieve the argument flags
const Uint8 f = m_ArgSpec[arg];
const uint8_t f = m_ArgSpec[arg];
// Perform the requested check
return (f == CMDARG_ANY) || ((f & flag) != 0x0) || ((f & CMDARG_GREEDY) && (flag & CMDARG_STRING));
}
@@ -1854,7 +1854,7 @@ public:
// Ask the specified authority inspector if this execution should be allowed
const SharedPtr< bool > ret = m_OnAuth.Evaluate< bool, const Object &, Listener * >(invoker, this);
// See what the custom authority inspector said or default to disallow
return !ret ? false : *ret;
return !!ret && *ret;
}
// Was there a global authority inspector specified?
else if (!m_Controller.Expired() && !m_Controller.Lock()->GetOnAuth().IsNull())
@@ -1862,7 +1862,7 @@ public:
// Ask the specified authority inspector if this execution should be allowed
const SharedPtr< bool > ret = m_Controller.Lock()->GetOnAuth().Evaluate< bool, const Object &, Listener * >(invoker, this);
// See what the custom authority inspector said or default to disallow
return !ret ? false : *ret;
return !!ret && *ret;
}
// A negative authority level is considered to be the same as unprotected
else if (m_Authority < 0)
@@ -1881,7 +1881,7 @@ public:
protected:
// --------------------------------------------------------------------------------------------
typedef Uint8 ArgSpec[SQMOD_MAX_CMD_ARGS];
typedef uint8_t ArgSpec[SQMOD_MAX_CMD_ARGS];
typedef String ArgTags[SQMOD_MAX_CMD_ARGS];
/* --------------------------------------------------------------------------------------------
@@ -1909,7 +1909,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* Process the specified string and extract the argument properties in it.
*/
void ProcSpec(CSStr spec);
void ProcSpec(const SQChar * spec);
private:
@@ -1925,8 +1925,8 @@ private:
ArgTags m_ArgTags; // List of argument tags/names.
// --------------------------------------------------------------------------------------------
Uint8 m_MinArgc; // Minimum number of arguments supported by this listener.
Uint8 m_MaxArgc; // Maximum number of arguments supported by this listener.
uint8_t m_MinArgc; // Minimum number of arguments supported by this listener.
uint8_t m_MaxArgc; // Maximum number of arguments supported by this listener.
// --------------------------------------------------------------------------------------------
String m_Spec; // String used to generate the argument type specification list.
@@ -1940,7 +1940,7 @@ private:
Function m_OnFail; // Function to call after the command execution failed.
// --------------------------------------------------------------------------------------------
Int32 m_Authority; // Built-in authority level required to execute this command.
int32_t m_Authority; // Built-in authority level required to execute this command.
// --------------------------------------------------------------------------------------------
bool m_Protected; // Whether explicit authentication of the invoker is required.
@@ -1,13 +1,11 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Utility.hpp"
#include "Base/Buffer.hpp"
#include "Core/Common.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
#include "Library/Numeric/Long.hpp"
// ------------------------------------------------------------------------------------------------
#include <ctime>
#include <cfloat>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include <cstdarg>
// ------------------------------------------------------------------------------------------------
@@ -15,40 +13,18 @@
#include <windows.h>
#endif // SQMOD_OS_WINDOWS
// ------------------------------------------------------------------------------------------------
#include <sqstdstring.h>
#include "Library/Numeric/LongInt.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
PluginFuncs* _Func = nullptr; //NOLINT(bugprone-reserved-identifier)
PluginCallbacks* _Clbk = nullptr; //NOLINT(bugprone-reserved-identifier)
PluginInfo* _Info = nullptr; //NOLINT(bugprone-reserved-identifier)
/* ------------------------------------------------------------------------------------------------
* Common buffers to reduce memory allocations. To be immediately copied upon return!
*/
static SQChar g_Buffer[4096];
static SQChar g_NumBuf[1024];
// ------------------------------------------------------------------------------------------------
SStr GetTempBuff()
{
return g_Buffer;
}
// ------------------------------------------------------------------------------------------------
Uint32 GetTempBuffSize()
{
return sizeof(g_Buffer);
}
PluginFuncs * _Func = nullptr; //NOLINT(bugprone-reserved-identifier)
PluginCallbacks * _Clbk = nullptr; //NOLINT(bugprone-reserved-identifier)
PluginInfo * _Info = nullptr; //NOLINT(bugprone-reserved-identifier)
/* --------------------------------------------------------------------------------------------
* Raw console message output.
*/
static inline void OutputMessageImpl(CCStr msg, va_list args)
static inline void OutputMessageImpl(const char * msg, va_list args)
{
#ifdef SQMOD_OS_WINDOWS
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
@@ -73,7 +49,7 @@ static inline void OutputMessageImpl(CCStr msg, va_list args)
/* --------------------------------------------------------------------------------------------
* Raw console error output.
*/
static inline void OutputErrorImpl(CCStr msg, va_list args)
static inline void OutputErrorImpl(const char * msg, va_list args)
{
#ifdef SQMOD_OS_WINDOWS
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
@@ -96,7 +72,7 @@ static inline void OutputErrorImpl(CCStr msg, va_list args)
}
// --------------------------------------------------------------------------------------------
void OutputDebug(CCStr msg, ...)
void OutputDebug(const char * msg, ...)
{
#ifdef _DEBUG
// Initialize the arguments list
@@ -112,7 +88,7 @@ void OutputDebug(CCStr msg, ...)
}
// --------------------------------------------------------------------------------------------
void OutputMessage(CCStr msg, ...)
void OutputMessage(const char * msg, ...)
{
// Initialize the arguments list
va_list args;
@@ -124,7 +100,7 @@ void OutputMessage(CCStr msg, ...)
}
// --------------------------------------------------------------------------------------------
void OutputError(CCStr msg, ...)
void OutputError(const char * msg, ...)
{
// Initialize the arguments list
va_list args;
@@ -136,118 +112,45 @@ void OutputError(CCStr msg, ...)
}
// ------------------------------------------------------------------------------------------------
void SqThrowF(CSStr str, ...)
{
// Initialize the argument list
va_list args;
va_start (args, str);
// Write the requested contents
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
{
// Write a generic message at least
std::strcpy(g_Buffer, "Unknown error has occurred");
}
// Finalize the argument list
va_end(args);
// Throw the exception with the resulted message
throw Sqrat::Exception(g_Buffer); // NOLINT(hicpp-exception-baseclass,cert-err60-cpp)
}
// ------------------------------------------------------------------------------------------------
CSStr FmtStr(CSStr str, ...)
{
// Initialize the argument list
va_list args;
va_start (args, str);
// Write the requested contents
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
{
STHROWF("Failed to run the specified string format");
}
// Finalize the argument list
va_end(args);
// Return the data from the buffer
return g_Buffer;
}
// ------------------------------------------------------------------------------------------------
CSStr ToStrF(CSStr str, ...)
{
// Prepare the arguments list
va_list args;
va_start(args, str);
// Write the requested contents
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
{
g_Buffer[0] = '\0'; // Make sure the string is null terminated
}
// Finalize the argument list
va_end(args);
// Return the resulted string
return g_Buffer;
}
// ------------------------------------------------------------------------------------------------
CSStr ToStringF(CSStr str, ...)
void SqThrowLastF(const SQChar * msg, ...)
{
// Acquire a moderately sized buffer
Buffer b(128);
// Prepare the arguments list
va_list args;
va_start (args, str);
va_start (args, msg);
// Attempt to run the specified format
if (b.WriteF(0, str, args) == 0)
if (b.WriteF(0, msg, args) == 0)
{
b.At(0) = '\0'; // Make sure the string is null terminated
}
// Finalize the argument list
va_end(args);
// Return the resulted string
return b.Get< SQChar >();
}
// ------------------------------------------------------------------------------------------------
SQRESULT SqThrowErrorF(HSQUIRRELVM vm, CCStr str, ...)
{
// Prepare the arguments list
va_list args;
va_start(args, str);
// Write the requested contents
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
#ifdef SQMOD_OS_WINDOWS
// Get the error message, if any.
const DWORD error_num = ::GetLastError();
// Was there an error recorded?
if(error_num == 0)
{
return sq_throwerror(vm, _SC("Formatting error occurred while throwing a script error"));
// Invoker is responsible for making sure this doesn't happen!
SqThrowF("%s [Unknown error]", b.Data());
}
// Finalize the argument list
va_end(args);
// Throw the resulted string
return sq_throwerror(vm, g_Buffer);
}
// ------------------------------------------------------------------------------------------------
bool SToB(CSStr str)
{
// Temporary buffer to store the lowercase string
SQChar buffer[8];
// The currently processed character
unsigned i = 0;
// Convert only the necessary characters to lowercase
while (i < 7 && *str != '\0')
{
buffer[i++] = static_cast< SQChar >(std::tolower(*(str++)));
}
// Add the null terminator
buffer[i] = '\0';
// Compare the lowercase string and return the result
return std::strcmp(buffer, "true") == 0 || std::strcmp(buffer, "yes") == 0 ||
std::strcmp(buffer, "on") == 0 || std::strcmp(buffer, "1") == 0;
}
// ------------------------------------------------------------------------------------------------
StackStrF & DummyStackStrF()
{
static StackStrF s;
s.Release();
return s;
// The resulted message buffer
LPSTR msg_buff = nullptr;
// Attempt to obtain the error message
const std::size_t size = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, // NOLINT(hicpp-signed-bitwise)
nullptr, error_num, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // NOLINT(hicpp-signed-bitwise)
reinterpret_cast< LPSTR >(&msg_buff), 0, nullptr);
// Copy the message buffer before freeing it
std::string message(msg_buff, size);
//Free the message buffer
LocalFree(msg_buff);
// Now it's safe to throw the error
SqThrowF("%s [%s]", b.Data(), message.c_str());
#else
SqThrowF("%s [%s]", b.Data(), std::strerror(errno));
#endif // SQMOD_OS_WINDOWS
}
// ------------------------------------------------------------------------------------------------
@@ -299,312 +202,7 @@ String & NullString()
}
// ------------------------------------------------------------------------------------------------
String & StringRef(const SQChar * str)
{
static String s;
s.assign(str);
return s;
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Int8 >::ToStr(Int8 v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%d", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
Int8 ConvNum< Int8 >::FromStr(CSStr s)
{
return ConvTo< Int8 >::From(std::strtol(s, nullptr, 10));
}
Int8 ConvNum< Int8 >::FromStr(CSStr s, Int32 base)
{
return ConvTo< Int8 >::From(std::strtol(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Uint8 >::ToStr(Uint8 v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%u", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
Uint8 ConvNum< Uint8 >::FromStr(CSStr s)
{
return ConvTo< Uint8 >::From(std::strtoul(s, nullptr, 10));
}
Uint8 ConvNum< Uint8 >::FromStr(CSStr s, Int32 base)
{
return ConvTo< Uint8 >::From(std::strtoul(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Int16 >::ToStr(Int16 v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%d", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
Int16 ConvNum< Int16 >::FromStr(CSStr s)
{
return ConvTo< Int16 >::From(std::strtol(s, nullptr, 10));
}
Int16 ConvNum< Int16 >::FromStr(CSStr s, Int32 base)
{
return ConvTo< Int16 >::From(std::strtol(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Uint16 >::ToStr(Uint16 v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%u", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
Uint16 ConvNum< Uint16 >::FromStr(CSStr s)
{
return ConvTo< Uint16 >::From(std::strtoul(s, nullptr, 10));
}
Uint16 ConvNum< Uint16 >::FromStr(CSStr s, Int32 base)
{
return ConvTo< Uint16 >::From(std::strtoul(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Int32 >::ToStr(Int32 v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%d", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
Int32 ConvNum< Int32 >::FromStr(CSStr s)
{
return ConvTo< Int32 >::From(std::strtol(s, nullptr, 10));
}
Int32 ConvNum< Int32 >::FromStr(CSStr s, Int32 base)
{
return ConvTo< Int32 >::From(std::strtol(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Uint32 >::ToStr(Uint32 v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%u", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
Uint32 ConvNum< Uint32 >::FromStr(CSStr s)
{
return ConvTo< Uint32 >::From(std::strtoul(s, nullptr, 10));
}
Uint32 ConvNum< Uint32 >::FromStr(CSStr s, Int32 base)
{
return ConvTo< Uint32 >::From(std::strtoul(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Int64 >::ToStr(Int64 v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%lld", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
Int64 ConvNum< Int64 >::FromStr(CSStr s)
{
return std::strtoll(s, nullptr, 10);
}
Int64 ConvNum< Int64 >::FromStr(CSStr s, Int32 base)
{
return std::strtoll(s, nullptr, base);
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Uint64 >::ToStr(Uint64 v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%llu", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
Uint64 ConvNum< Uint64 >::FromStr(CSStr s)
{
return std::strtoull(s, nullptr, 10);
}
Uint64 ConvNum< Uint64 >::FromStr(CSStr s, Int32 base)
{
return std::strtoull(s, nullptr, base);
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< LongI >::ToStr(LongI v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%ld", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
LongI ConvNum< LongI >::FromStr(CSStr s)
{
return std::strtol(s, nullptr, 10);
}
LongI ConvNum< LongI >::FromStr(CSStr s, Int32 base)
{
return std::strtol(s, nullptr, base);
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Ulong >::ToStr(Ulong v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%lu", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
Ulong ConvNum< Ulong >::FromStr(CSStr s)
{
return std::strtoul(s, nullptr, 10);
}
Ulong ConvNum< Ulong >::FromStr(CSStr s, Int32 base)
{
return std::strtoul(s, nullptr, base);
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Float32 >::ToStr(Float32 v)
{
// Attempt to convert the value to a string
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%f", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the data from the buffer
return g_NumBuf;
}
Float32 ConvNum< Float32 >::FromStr(CSStr s)
{
return std::strtof(s, nullptr);
}
Float32 ConvNum< Float32 >::FromStr(CSStr s, Int32 /*base*/)
{
return std::strtof(s, nullptr);
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< Float64 >::ToStr(Float64 v)
{
// Attempt to convert the value to a string
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%f", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the data from the buffer
return g_NumBuf;
}
Float64 ConvNum< Float64 >::FromStr(CSStr s)
{
return std::strtod(s, nullptr);
}
Float64 ConvNum< Float64 >::FromStr(CSStr s, Int32 /*base*/)
{
return std::strtod(s, nullptr);
}
// ------------------------------------------------------------------------------------------------
CSStr ConvNum< bool >::ToStr(bool v)
{
if (v)
{
g_NumBuf[0] = 't';
g_NumBuf[1] = 'r';
g_NumBuf[2] = 'u';
g_NumBuf[3] = 'e';
g_NumBuf[4] = '\0';
}
else
{
g_NumBuf[0] = 'f';
g_NumBuf[1] = 'a';
g_NumBuf[2] = 'l';
g_NumBuf[3] = 's';
g_NumBuf[4] = 'e';
g_NumBuf[5] = '\0';
}
return g_NumBuf;
}
bool ConvNum< bool >::FromStr(CSStr s)
{
return std::strcmp(s, "true") == 0;
}
bool ConvNum< bool >::FromStr(CSStr s, Int32 /*base*/)
{
return std::strcmp(s, "true") == 0;
}
// ------------------------------------------------------------------------------------------------
CSStr SqTypeName(SQObjectType type)
const SQChar * SqTypeName(SQObjectType type)
{
switch (type)
{
@@ -652,18 +250,18 @@ String SqTypeName(HSQUIRRELVM vm, SQInteger idx)
}
// ------------------------------------------------------------------------------------------------
Object BufferToStrObj(const Buffer & b)
LightObj BufferToStrObj(const Buffer & b)
{
// Obtain the initial stack size
const StackGuard sg(SqVM());
// Push the string onto the stack
sq_pushstring(SqVM(), b.Data(), b.Position());
// Obtain the object from the stack and return it
return Var< Object >(SqVM(), -1).value;
return Var< LightObj >(SqVM(), -1).value;
}
// --------------------------------------------------------------------------------------------
Object BufferToStrObj(const Buffer & b, Uint32 size)
LightObj BufferToStrObj(const Buffer & b, uint32_t size)
{
// Perform a range check on the specified buffer
if (size > b.Capacity())
@@ -675,7 +273,7 @@ Object BufferToStrObj(const Buffer & b, Uint32 size)
// Push the string onto the stack
sq_pushstring(SqVM(), b.Data(), size);
// Obtain the object from the stack and return it
return Var< Object >(SqVM(), -1).value;
return Var< LightObj >(SqVM(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@@ -704,7 +302,7 @@ SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx)
}
case OT_STRING:
{
CSStr val = nullptr;
const SQChar * val = nullptr;
// Attempt to retrieve and convert the string
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
{
@@ -773,7 +371,7 @@ SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
}
case OT_STRING:
{
CSStr val = nullptr;
const SQChar * val = nullptr;
// Attempt to retrieve and convert the string
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
{
@@ -820,4 +418,23 @@ SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
return 0.0;
}
// ------------------------------------------------------------------------------------------------
bool SToB(const SQChar * str)
{
// Temporary buffer to store the lowercase string
SQChar buffer[8];
// The currently processed character
unsigned i = 0;
// Convert only the necessary characters to lowercase
while (i < 7 && *str != '\0')
{
buffer[i++] = static_cast< SQChar >(std::tolower(*(str++)));
}
// Add the null terminator
buffer[i] = '\0';
// Compare the lowercase string and return the result
return std::strcmp(buffer, "true") == 0 || std::strcmp(buffer, "yes") == 0 ||
std::strcmp(buffer, "on") == 0 || std::strcmp(buffer, "1") == 0;
}
} // Namespace:: SqMod
+269
View File
@@ -0,0 +1,269 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstddef>
#include <climits>
#include <cstdlib>
#include <cstdint>
#include <cassert>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <cinttypes>
// ------------------------------------------------------------------------------------------------
#include <new>
#include <limits>
#include <memory>
#include <string>
#include <utility>
#include <typeinfo>
#include <typeindex>
#include <exception>
#include <stdexcept>
#include <functional>
#include <type_traits>
// ------------------------------------------------------------------------------------------------
#include <vcmp.h>
#include <squirrelex.h>
#include <sqratAllocator.h>
#include <sqratArray.h>
#include <sqratClass.h>
#include <sqratClassType.h>
#include <sqratFunction.h>
#include <sqratLightObj.h>
#include <sqratObject.h>
#include <sqratTable.h>
#include <sqratUtil.h>
#include <fmt/core.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Proxies to communicate with the server.
*/
extern PluginFuncs * _Func; //NOLINT(bugprone-reserved-identifier)
extern PluginCallbacks * _Clbk; //NOLINT(bugprone-reserved-identifier)
extern PluginInfo * _Info; //NOLINT(bugprone-reserved-identifier)
/* ------------------------------------------------------------------------------------------------
* Helper to register pure typename functions for better performance.
*/
#define SQMOD_DECL_TYPENAME(t, s) /*
*/ namespace { /*
*/ struct t { /*
*/ static const SQChar Str[]; /*
*/ static SQInteger Fn(HSQUIRRELVM vm); /*
*/ }; /*
*/ const SQChar t::Str[] = s; /*
*/ SQInteger t::Fn(HSQUIRRELVM vm) { /*
*/ sq_pushstring(vm, Str, sizeof(Str) / sizeof(SQChar)); /*
*/ return 1; /*
*/ } /*
*/ } /*
*/
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary logging functions.
*/
extern void LogDbg(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogUsr(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogScs(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogInf(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogWrn(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogErr(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogFtl(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary logging functions.
*/
extern void LogSDbg(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSUsr(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSScs(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSInf(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSWrn(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSErr(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
extern void LogSFtl(const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 1, 2);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary logging functions.
*/
extern void LogDbgV(const char * fmt, va_list vlist);
extern void LogUsrV(const char * fmt, va_list vlist);
extern void LogScsV(const char * fmt, va_list vlist);
extern void LogInfV(const char * fmt, va_list vlist);
extern void LogWrnV(const char * fmt, va_list vlist);
extern void LogErrV(const char * fmt, va_list vlist);
extern void LogFtlV(const char * fmt, va_list vlist);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary logging functions.
*/
extern void LogSDbgV(const char * fmt, va_list vlist);
extern void LogSUsrV(const char * fmt, va_list vlist);
extern void LogSScsV(const char * fmt, va_list vlist);
extern void LogSInfV(const char * fmt, va_list vlist);
extern void LogSWrnV(const char * fmt, va_list vlist);
extern void LogSErrV(const char * fmt, va_list vlist);
extern void LogSFtlV(const char * fmt, va_list vlist);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary conditional logging functions.
*/
extern bool cLogDbg(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogUsr(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogScs(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogInf(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogWrn(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogErr(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogFtl(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary conditional logging functions.
*/
extern bool cLogSDbg(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSUsr(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSScs(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSInf(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSWrn(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSErr(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
extern bool cLogSFtl(bool exp, const char * fmt, ...) SQMOD_FORMAT_ATTR(printf, 2, 3);
/* ------------------------------------------------------------------------------------------------
* Helper used to reference and keep track of signal instances.
*/
typedef std::pair< Signal *, LightObj > SignalPair;
/* ------------------------------------------------------------------------------------------------
* Initialize a signal instance into the specified pair.
*/
extern void InitSignalPair(SignalPair & sp, LightObj & et, const char * name);
/* ------------------------------------------------------------------------------------------------
* Reset/release the specified signal pair.
*/
extern void ResetSignalPair(SignalPair & sp, bool clear = true);
/* ------------------------------------------------------------------------------------------------
* Output a message only if the _DEBUG was defined.
*/
void OutputDebug(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Output a formatted user message to the console.
*/
void OutputMessage(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Output a formatted error message to the console.
*/
void OutputError(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Generate a formatted string and throw it as a sqrat exception.
*/
template < class... Args > void SqThrowF(Args &&... args)
{
throw Sqrat::Exception(fmt::format(std::forward< Args >(args)...));
}
/* ------------------------------------------------------------------------------------------------
* Generate a formatted string and throw it as a squirrel exception.
*/
template < class... Args > SQRESULT SqThrowErrorF(HSQUIRRELVM vm, Args &&... args)
{
String msg;
try
{
msg = fmt::format(std::forward< Args >(args)...);
}
catch(const std::exception & e)
{
return sq_throwerror(vm, e.what());
}
return sq_throwerror(vm, msg.c_str());
}
/* ------------------------------------------------------------------------------------------------
* Throw the last system error as an exception.
*/
void SqThrowLastF(const SQChar * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null script object.
*/
SQMOD_NODISCARD Object & NullObject();
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null script object.
*/
SQMOD_NODISCARD LightObj & NullLightObj();
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null/empty script table.
*/
SQMOD_NODISCARD Table & NullTable();
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null/empty script array.
*/
SQMOD_NODISCARD Array & NullArray();
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null script function.
*/
SQMOD_NODISCARD Function & NullFunction();
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null string.
*/
SQMOD_NODISCARD String & NullString();
/* ------------------------------------------------------------------------------------------------
* Retrieve the string representation of a certain type.
*/
SQMOD_NODISCARD const SQChar * SqTypeName(SQObjectType type);
/* ------------------------------------------------------------------------------------------------
* Retrieve the string representation of a certain type from a value on the stack.
*/
SQMOD_NODISCARD String SqTypeName(HSQUIRRELVM vm, SQInteger idx);
/* ------------------------------------------------------------------------------------------------
* Create a script string instance from a buffer.
*/
SQMOD_NODISCARD LightObj BufferToStrObj(const Buffer & b);
/* ------------------------------------------------------------------------------------------------
* Create a script string instance from a portion of a buffer.
*/
SQMOD_NODISCARD LightObj BufferToStrObj(const Buffer & b, uint32_t size);
/* ------------------------------------------------------------------------------------------------
* Attempt to pop the value at the specified index on the stack as a native integer.
*/
SQMOD_NODISCARD SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx);
/* ------------------------------------------------------------------------------------------------
* Attempt to pop the value at the specified index on the stack as a native float.
*/
SQMOD_NODISCARD SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx);
/* ------------------------------------------------------------------------------------------------
* Simple function to check whether the specified string can be considered as a boolean value
*/
SQMOD_NODISCARD bool SToB(const SQChar * str);
} // Namespace:: SqMod
+116 -39
View File
@@ -1,7 +1,21 @@
// ------------------------------------------------------------------------------------------------
#include "Core/Entity.hpp"
#include "Core.hpp"
#include "Logger.hpp"
// ------------------------------------------------------------------------------------------------
#include "Entity/Blip.hpp"
#include "Entity/Checkpoint.hpp"
#include "Entity/KeyBind.hpp"
#include "Entity/Object.hpp"
#include "Entity/Pickup.hpp"
#include "Entity/Player.hpp"
#include "Entity/Vehicle.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// --------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
#define SQMOD_CATCH_EVENT_EXCEPTION(action) /*
*/ catch (const Sqrat::Exception & e) /*
*/ { /*
@@ -11,10 +25,73 @@ namespace SqMod {
*/
// ------------------------------------------------------------------------------------------------
extern void CleanupTasks(Int32 id, Int32 type);
extern void CleanupTasks(int32_t id, int32_t type);
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::Destroy(bool destroy, Int32 header, LightObj & payload)
BlipInst::~BlipInst()
{
if (VALID_ENTITY(mID))
{
Destroy(!Core::Get().ShuttingDown(), SQMOD_DESTROY_CLEANUP, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
CheckpointInst::~CheckpointInst()
{
if (VALID_ENTITY(mID))
{
Destroy(!Core::Get().ShuttingDown(), SQMOD_DESTROY_CLEANUP, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
KeyBindInst::~KeyBindInst()
{
if (VALID_ENTITY(mID))
{
Destroy(!Core::Get().ShuttingDown(), SQMOD_DESTROY_CLEANUP, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
ObjectInst::~ObjectInst()
{
if (VALID_ENTITY(mID))
{
Destroy(!Core::Get().ShuttingDown(), SQMOD_DESTROY_CLEANUP, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
PickupInst::~PickupInst()
{
if (VALID_ENTITY(mID))
{
Destroy(!Core::Get().ShuttingDown(), SQMOD_DESTROY_CLEANUP, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
PlayerInst::~PlayerInst()
{
if (VALID_ENTITY(mID))
{
Destroy(false, SQMOD_DESTROY_CLEANUP, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
VehicleInst::~VehicleInst()
{
if (VALID_ENTITY(mID))
{
Destroy(!Core::Get().ShuttingDown(), SQMOD_DESTROY_CLEANUP, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
void BlipInst::Destroy(bool destroy, int32_t header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@@ -44,7 +121,7 @@ void Core::BlipInst::Destroy(bool destroy, Int32 header, LightObj & payload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU32 bg(mFlags, static_cast< Uint32 >(ENF_LOCKED));
const BitGuardU32 bg(mFlags, static_cast< uint32_t >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DestroyCoordBlip(mID);
}
@@ -55,7 +132,7 @@ void Core::BlipInst::Destroy(bool destroy, Int32 header, LightObj & payload)
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::Destroy(bool destroy, Int32 header, LightObj & payload)
void CheckpointInst::Destroy(bool destroy, int32_t header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@@ -85,7 +162,7 @@ void Core::CheckpointInst::Destroy(bool destroy, Int32 header, LightObj & payloa
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU32 bg(mFlags, static_cast< Uint32 >(ENF_LOCKED));
const BitGuardU32 bg(mFlags, static_cast< uint32_t >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeleteCheckPoint(mID);
}
@@ -96,7 +173,7 @@ void Core::CheckpointInst::Destroy(bool destroy, Int32 header, LightObj & payloa
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::Destroy(bool destroy, Int32 header, LightObj & payload)
void KeyBindInst::Destroy(bool destroy, int32_t header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@@ -104,7 +181,7 @@ void Core::KeybindInst::Destroy(bool destroy, Int32 header, LightObj & payload)
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitKeybindDestroyed(mID, header, payload);
Core::Get().EmitKeyBindDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying keybind")
}
@@ -126,7 +203,7 @@ void Core::KeybindInst::Destroy(bool destroy, Int32 header, LightObj & payload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU32 bg(mFlags, static_cast< Uint32 >(ENF_LOCKED));
const BitGuardU32 bg(mFlags, static_cast< uint32_t >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->RemoveKeyBind(mID);
}
@@ -137,7 +214,7 @@ void Core::KeybindInst::Destroy(bool destroy, Int32 header, LightObj & payload)
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::Destroy(bool destroy, Int32 header, LightObj & payload)
void ObjectInst::Destroy(bool destroy, int32_t header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@@ -167,7 +244,7 @@ void Core::ObjectInst::Destroy(bool destroy, Int32 header, LightObj & payload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU32 bg(mFlags, static_cast< Uint32 >(ENF_LOCKED));
const BitGuardU32 bg(mFlags, static_cast< uint32_t >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeleteObject(mID);
}
@@ -178,7 +255,7 @@ void Core::ObjectInst::Destroy(bool destroy, Int32 header, LightObj & payload)
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::Destroy(bool destroy, Int32 header, LightObj & payload)
void PickupInst::Destroy(bool destroy, int32_t header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@@ -208,7 +285,7 @@ void Core::PickupInst::Destroy(bool destroy, Int32 header, LightObj & payload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU32 bg(mFlags, static_cast< Uint32 >(ENF_LOCKED));
const BitGuardU32 bg(mFlags, static_cast< uint32_t >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeletePickup(mID);
}
@@ -219,7 +296,7 @@ void Core::PickupInst::Destroy(bool destroy, Int32 header, LightObj & payload)
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::Destroy(bool /*destroy*/, Int32 header, LightObj & payload)
void PlayerInst::Destroy(bool /*destroy*/, int32_t header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@@ -254,7 +331,7 @@ void Core::PlayerInst::Destroy(bool /*destroy*/, Int32 header, LightObj & payloa
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::Destroy(bool destroy, Int32 header, LightObj & payload)
void VehicleInst::Destroy(bool destroy, int32_t header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@@ -284,7 +361,7 @@ void Core::VehicleInst::Destroy(bool destroy, Int32 header, LightObj & payload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU32 bg(mFlags, static_cast< Uint32 >(ENF_LOCKED));
const BitGuardU32 bg(mFlags, static_cast< uint32_t >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeleteVehicle(mID);
}
@@ -295,7 +372,7 @@ void Core::VehicleInst::Destroy(bool destroy, Int32 header, LightObj & payload)
}
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::ResetInstance()
void BlipInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
@@ -307,14 +384,14 @@ void Core::BlipInst::ResetInstance()
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::ResetInstance()
void CheckpointInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::ResetInstance()
void KeyBindInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
@@ -325,21 +402,21 @@ void Core::KeybindInst::ResetInstance()
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::ResetInstance()
void ObjectInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::ResetInstance()
void PickupInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::ResetInstance()
void PlayerInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
@@ -360,7 +437,7 @@ void Core::PlayerInst::ResetInstance()
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::ResetInstance()
void VehicleInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
@@ -376,7 +453,7 @@ void Core::VehicleInst::ResetInstance()
}
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::InitEvents()
void BlipInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
@@ -395,7 +472,7 @@ void Core::BlipInst::InitEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::DropEvents()
void BlipInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
@@ -403,7 +480,7 @@ void Core::BlipInst::DropEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::InitEvents()
void CheckpointInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
@@ -429,7 +506,7 @@ void Core::CheckpointInst::InitEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::DropEvents()
void CheckpointInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
@@ -444,7 +521,7 @@ void Core::CheckpointInst::DropEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::InitEvents()
void KeyBindInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
@@ -465,7 +542,7 @@ void Core::KeybindInst::InitEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::DropEvents()
void KeyBindInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
@@ -475,7 +552,7 @@ void Core::KeybindInst::DropEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::InitEvents()
void ObjectInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
@@ -502,7 +579,7 @@ void Core::ObjectInst::InitEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::DropEvents()
void ObjectInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
@@ -518,7 +595,7 @@ void Core::ObjectInst::DropEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::InitEvents()
void PickupInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
@@ -548,7 +625,7 @@ void Core::PickupInst::InitEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::DropEvents()
void PickupInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
@@ -567,7 +644,7 @@ void Core::PickupInst::DropEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::InitEvents()
void PlayerInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
@@ -632,7 +709,7 @@ void Core::PlayerInst::InitEvents()
InitSignalPair(mOnKeyRelease, mEvents, "KeyRelease");
InitSignalPair(mOnSpectate, mEvents, "Spectate");
InitSignalPair(mOnUnspectate, mEvents, "Unspectate");
InitSignalPair(mOnCrashreport, mEvents, "Crashreport");
InitSignalPair(mOnCrashReport, mEvents, "CrashReport");
InitSignalPair(mOnModuleList, mEvents, "ModuleList");
InitSignalPair(mOnObjectShot, mEvents, "ObjectShot");
InitSignalPair(mOnObjectTouched, mEvents, "ObjectTouched");
@@ -665,7 +742,7 @@ void Core::PlayerInst::InitEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::DropEvents()
void PlayerInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
@@ -718,7 +795,7 @@ void Core::PlayerInst::DropEvents()
ResetSignalPair(mOnKeyRelease);
ResetSignalPair(mOnSpectate);
ResetSignalPair(mOnUnspectate);
ResetSignalPair(mOnCrashreport);
ResetSignalPair(mOnCrashReport);
ResetSignalPair(mOnModuleList);
ResetSignalPair(mOnObjectShot);
ResetSignalPair(mOnObjectTouched);
@@ -752,7 +829,7 @@ void Core::PlayerInst::DropEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::InitEvents()
void VehicleInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
@@ -794,7 +871,7 @@ void Core::VehicleInst::InitEvents()
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::DropEvents()
void VehicleInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
+555
View File
@@ -0,0 +1,555 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Core/Utility.hpp"
#include "Base/Color4.hpp"
#include "Base/Vector3.hpp"
#include "Base/Quaternion.hpp"
// ------------------------------------------------------------------------------------------------
#include <vector>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// --------------------------------------------------------------------------------------------
typedef std::vector< std::pair< Area *, LightObj > > AreaList; // List of collided areas.
/* --------------------------------------------------------------------------------------------
* Helper structure used to identify a blip entity instance on the server.
*/
struct BlipInst
{
/* ----------------------------------------------------------------------------------------
* Default constructor.
*/
BlipInst() = default;
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~BlipInst();
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy(bool destroy, int32_t header, LightObj & payload);
/* ----------------------------------------------------------------------------------------
* Reset the instance to the default values.
*/
void ResetInstance();
/* ----------------------------------------------------------------------------------------
* Create the associated signals.
*/
void InitEvents();
/* ----------------------------------------------------------------------------------------
* Clear the associated signals.
*/
void DropEvents();
// ----------------------------------------------------------------------------------------
int32_t mID{-1}; // The unique number that identifies this entity on the server.
uint32_t mFlags{ENF_DEFAULT}; // Various options and states that can be toggled on the instance.
CBlip * mInst{nullptr}; // Pointer to the actual instance used to interact this entity.
LightObj mObj{}; // Script object of the instance used to interact this entity.
// ----------------------------------------------------------------------------------------
int32_t mWorld{-1}; // The identifier of the world in which this blip was created.
int32_t mScale{-1}; // The scale of the blip.
// ----------------------------------------------------------------------------------------
int32_t mSprID{-1};
// ----------------------------------------------------------------------------------------
LightObj mEvents{}; // Table containing the emitted entity events.
// ----------------------------------------------------------------------------------------
Vector3 mPosition{};
Color4 mColor{};
// ----------------------------------------------------------------------------------------
SignalPair mOnDestroyed{};
SignalPair mOnCustom{};
};
/* --------------------------------------------------------------------------------------------
* Helper structure used to identify a checkpoint entity instance on the server.
*/
struct CheckpointInst
{
/* ----------------------------------------------------------------------------------------
* Default constructor.
*/
CheckpointInst() = default;
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~CheckpointInst();
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy(bool destroy, int32_t header, LightObj & payload);
/* ----------------------------------------------------------------------------------------
* Reset the instance to the default values.
*/
void ResetInstance();
/* ----------------------------------------------------------------------------------------
* Create the associated signals.
*/
void InitEvents();
/* ----------------------------------------------------------------------------------------
* Clear the associated signals.
*/
void DropEvents();
// ----------------------------------------------------------------------------------------
int32_t mID{-1}; // The unique number that identifies this entity on the server.
uint32_t mFlags{ENF_DEFAULT}; // Various options and states that can be toggled on the instance.
CCheckpoint * mInst{nullptr}; // Pointer to the actual instance used to interact this entity.
LightObj mObj{}; // Script object of the instance used to interact this entity.
// ----------------------------------------------------------------------------------------
LightObj mEvents{}; // Table containing the emitted entity events.
// ----------------------------------------------------------------------------------------
SignalPair mOnDestroyed{};
SignalPair mOnCustom{};
#if SQMOD_SDK_LEAST(2, 1)
SignalPair mOnStream{};
#endif
// ----------------------------------------------------------------------------------------
SignalPair mOnEntered{};
SignalPair mOnExited{};
SignalPair mOnWorld{};
SignalPair mOnRadius{};
};
/* --------------------------------------------------------------------------------------------
* Helper structure used to identify a key-bind entity instance on the server.
*/
struct KeyBindInst
{
/* ----------------------------------------------------------------------------------------
* Default constructor.
*/
KeyBindInst() = default;
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~KeyBindInst();
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy(bool destroy, int32_t header, LightObj & payload);
/* ----------------------------------------------------------------------------------------
* Reset the instance to the default values.
*/
void ResetInstance();
/* ----------------------------------------------------------------------------------------
* Create the associated signals.
*/
void InitEvents();
/* ----------------------------------------------------------------------------------------
* Clear the associated signals.
*/
void DropEvents();
// ----------------------------------------------------------------------------------------
int32_t mID{-1}; // The unique number that identifies this entity on the server.
uint32_t mFlags{ENF_DEFAULT}; // Various options and states that can be toggled on the instance.
CKeyBind * mInst{nullptr}; // Pointer to the actual instance used to interact this entity.
LightObj mObj{}; // Script object of the instance used to interact this entity.
// ----------------------------------------------------------------------------------------
int32_t mFirst{-1}; // Key-code of the first button from the triggering combination.
int32_t mSecond{-1}; // Key-code of the second button from the triggering combination.
int32_t mThird{-1}; // Key-code of the third button from the triggering combination.
int32_t mRelease{-1}; // Whether the key-bind reacts to button press or release.
// ----------------------------------------------------------------------------------------
LightObj mEvents{}; // Table containing the emitted entity events.
// ----------------------------------------------------------------------------------------
SignalPair mOnDestroyed{};
SignalPair mOnCustom{};
// ----------------------------------------------------------------------------------------
SignalPair mOnKeyPress{};
SignalPair mOnKeyRelease{};
};
/* --------------------------------------------------------------------------------------------
* Helper structure used to identify an object entity instance on the server.
*/
struct ObjectInst
{
/* ----------------------------------------------------------------------------------------
* Default constructor.
*/
ObjectInst() = default;
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~ObjectInst();
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy(bool destroy, int32_t header, LightObj & payload);
/* ----------------------------------------------------------------------------------------
* Reset the instance to the default values.
*/
void ResetInstance();
/* ----------------------------------------------------------------------------------------
* Create the associated signals.
*/
void InitEvents();
/* ----------------------------------------------------------------------------------------
* Clear the associated signals.
*/
void DropEvents();
// ----------------------------------------------------------------------------------------
int32_t mID{-1}; // The unique number that identifies this entity on the server.
uint32_t mFlags{ENF_DEFAULT}; // Various options and states that can be toggled on the instance.
CObject * mInst{nullptr}; // Pointer to the actual instance used to interact this entity.
LightObj mObj{}; // Script object of the instance used to interact this entity.
// ----------------------------------------------------------------------------------------
LightObj mEvents{}; // Table containing the emitted entity events.
// ----------------------------------------------------------------------------------------
SignalPair mOnDestroyed{};
SignalPair mOnCustom{};
#if SQMOD_SDK_LEAST(2, 1)
SignalPair mOnStream{};
#endif
// ----------------------------------------------------------------------------------------
SignalPair mOnShot{};
SignalPair mOnTouched{};
SignalPair mOnWorld{};
SignalPair mOnAlpha{};
SignalPair mOnReport{};
};
/* --------------------------------------------------------------------------------------------
* Helper structure used to identify a pickup entity instance on the server.
*/
struct PickupInst
{
/* ----------------------------------------------------------------------------------------
* Default constructor.
*/
PickupInst() = default;
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~PickupInst();
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy(bool destroy, int32_t header, LightObj & payload);
/* ----------------------------------------------------------------------------------------
* Reset the instance to the default values.
*/
void ResetInstance();
/* ----------------------------------------------------------------------------------------
* Create the associated signals.
*/
void InitEvents();
/* ----------------------------------------------------------------------------------------
* Clear the associated signals.
*/
void DropEvents();
// ----------------------------------------------------------------------------------------
int32_t mID{-1}; // The unique number that identifies this entity on the server.
uint32_t mFlags{ENF_DEFAULT}; // Various options and states that can be toggled on the instance.
CPickup * mInst{nullptr}; // Pointer to the actual instance used to interact this entity.
LightObj mObj{}; // Script object of the instance used to interact this entity.
// ----------------------------------------------------------------------------------------
LightObj mEvents{}; // Table containing the emitted entity events.
// ----------------------------------------------------------------------------------------
SignalPair mOnDestroyed{};
SignalPair mOnCustom{};
#if SQMOD_SDK_LEAST(2, 1)
SignalPair mOnStream{};
#endif
// ----------------------------------------------------------------------------------------
SignalPair mOnRespawn{};
SignalPair mOnClaimed{};
SignalPair mOnCollected{};
SignalPair mOnWorld{};
SignalPair mOnAlpha{};
SignalPair mOnAutomatic{};
SignalPair mOnAutoTimer{};
SignalPair mOnOption{};
};
/* --------------------------------------------------------------------------------------------
* Helper structure used to identify a player entity instance on the server.
*/
struct PlayerInst
{
/* ----------------------------------------------------------------------------------------
* Default constructor.
*/
PlayerInst() = default;
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~PlayerInst();
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy(bool destroy, int32_t header, LightObj & payload);
/* ----------------------------------------------------------------------------------------
* Reset the instance to the default values.
*/
void ResetInstance();
/* ----------------------------------------------------------------------------------------
* Create the associated signals.
*/
void InitEvents();
/* ----------------------------------------------------------------------------------------
* Clear the associated signals.
*/
void DropEvents();
// ----------------------------------------------------------------------------------------
int32_t mID{-1}; // The unique number that identifies this entity on the server.
uint32_t mFlags{ENF_DEFAULT}; // Various options and states that can be toggled on the instance.
CPlayer * mInst{nullptr}; // Pointer to the actual instance used to interact this entity.
LightObj mObj{}; // Script object of the instance used to interact this entity.
// ----------------------------------------------------------------------------------------
AreaList mAreas{}; // Areas the player is currently in.
double mDistance{0}; // Distance traveled while tracking was enabled.
// ----------------------------------------------------------------------------------------
SQInteger mTrackPosition{0}; // The number of times to track position changes.
SQInteger mTrackHeading{0}; // The number of times to track heading changes.
// ----------------------------------------------------------------------------------------
int32_t mTrackPositionHeader{0}; // Header to send when triggering position callback.
LightObj mTrackPositionPayload{}; // Payload to send when triggering position callback.
// ----------------------------------------------------------------------------------------
int32_t mKickBanHeader{0}; // Header to send when triggering kick/ban callback.
LightObj mKickBanPayload{}; // Payload to send when triggering kick/ban callback.
// ----------------------------------------------------------------------------------------
int32_t mLastWeapon{-1}; // Last known weapon of the player entity.
float mLastHealth{0}; // Last known health of the player entity.
float mLastArmour{0}; // Last known armor of the player entity.
float mLastHeading{0}; // Last known heading of the player entity.
Vector3 mLastPosition{}; // Last known position of the player entity.
// ----------------------------------------------------------------------------------------
int32_t mAuthority{0}; // The authority level of the managed player.
// ----------------------------------------------------------------------------------------
LightObj mEvents{}; // Table containing the emitted entity events.
// ----------------------------------------------------------------------------------------
SignalPair mOnDestroyed{};
SignalPair mOnCustom{};
#if SQMOD_SDK_LEAST(2, 1)
SignalPair mOnStream{};
#endif
// ----------------------------------------------------------------------------------------
SignalPair mOnRequestClass{};
SignalPair mOnRequestSpawn{};
SignalPair mOnSpawn{};
SignalPair mOnWasted{};
SignalPair mOnKilled{};
SignalPair mOnEmbarking{};
SignalPair mOnEmbarked{};
SignalPair mOnDisembark{};
SignalPair mOnRename{};
SignalPair mOnState{};
SignalPair mOnStateNone{};
SignalPair mOnStateNormal{};
SignalPair mOnStateAim{};
SignalPair mOnStateDriver{};
SignalPair mOnStatePassenger{};
SignalPair mOnStateEnterDriver{};
SignalPair mOnStateEnterPassenger{};
SignalPair mOnStateExit{};
SignalPair mOnStateUnspawned{};
SignalPair mOnAction{};
SignalPair mOnActionNone{};
SignalPair mOnActionNormal{};
SignalPair mOnActionAiming{};
SignalPair mOnActionShooting{};
SignalPair mOnActionJumping{};
SignalPair mOnActionLieDown{};
SignalPair mOnActionGettingUp{};
SignalPair mOnActionJumpVehicle{};
SignalPair mOnActionDriving{};
SignalPair mOnActionDying{};
SignalPair mOnActionWasted{};
SignalPair mOnActionEmbarking{};
SignalPair mOnActionDisembarking{};
SignalPair mOnBurning{};
SignalPair mOnCrouching{};
SignalPair mOnGameKeys{};
SignalPair mOnStartTyping{};
SignalPair mOnStopTyping{};
SignalPair mOnAway{};
SignalPair mOnMessage{};
SignalPair mOnCommand{};
SignalPair mOnPrivateMessage{};
SignalPair mOnKeyPress{};
SignalPair mOnKeyRelease{};
SignalPair mOnSpectate{};
SignalPair mOnUnspectate{};
SignalPair mOnCrashReport{};
SignalPair mOnModuleList{};
SignalPair mOnObjectShot{};
SignalPair mOnObjectTouched{};
SignalPair mOnPickupClaimed{};
SignalPair mOnPickupCollected{};
SignalPair mOnCheckpointEntered{};
SignalPair mOnCheckpointExited{};
SignalPair mOnClientScriptData{};
#if SQMOD_SDK_LEAST(2, 1)
SignalPair mOnEntityStream{};
#endif
SignalPair mOnUpdate{};
SignalPair mOnHealth{};
SignalPair mOnArmour{};
SignalPair mOnWeapon{};
SignalPair mOnHeading{};
SignalPair mOnPosition{};
SignalPair mOnOption{};
SignalPair mOnAdmin{};
SignalPair mOnWorld{};
SignalPair mOnTeam{};
SignalPair mOnSkin{};
SignalPair mOnMoney{};
SignalPair mOnScore{};
SignalPair mOnWantedLevel{};
SignalPair mOnImmunity{};
SignalPair mOnAlpha{};
SignalPair mOnEnterArea{};
SignalPair mOnLeaveArea{};
};
/* --------------------------------------------------------------------------------------------
* Helper structure used to identify a vehicle entity instance on the server.
*/
struct VehicleInst
{
/* ----------------------------------------------------------------------------------------
* Default constructor.
*/
VehicleInst() = default;
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~VehicleInst();
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy(bool destroy, int32_t header, LightObj & payload);
/* ----------------------------------------------------------------------------------------
* Reset the instance to the default values.
*/
void ResetInstance();
/* ----------------------------------------------------------------------------------------
* Create the associated signals.
*/
void InitEvents();
/* ----------------------------------------------------------------------------------------
* Clear the associated signals.
*/
void DropEvents();
// ----------------------------------------------------------------------------------------
int32_t mID{-1}; // The unique number that identifies this entity on the server.
uint32_t mFlags{ENF_DEFAULT}; // Various options and states that can be toggled on the instance.
CVehicle * mInst{nullptr}; // Pointer to the actual instance used to interact this entity.
LightObj mObj{}; // Script object of the instance used to interact this entity.
// ----------------------------------------------------------------------------------------
AreaList mAreas{}; // Areas the vehicle is currently in.
double mDistance{0}; // Distance traveled while tracking was enabled.
// ----------------------------------------------------------------------------------------
SQInteger mTrackPosition{0}; // The number of times to track position changes.
SQInteger mTrackRotation{0}; // The number of times to track rotation changes.
// ----------------------------------------------------------------------------------------
int32_t mLastPrimaryColor{-1}; // Last known secondary-color of the player entity.
int32_t mLastSecondaryColor{-1}; // Last known primary-color of the player entity.
float mLastHealth{0}; // Last known health of the player entity.
Vector3 mLastPosition{}; // Last known position of the player entity.
Quaternion mLastRotation{}; // Last known rotation of the player entity.
// ----------------------------------------------------------------------------------------
LightObj mEvents{}; // Table containing the emitted entity events.
// ----------------------------------------------------------------------------------------
SignalPair mOnDestroyed{};
SignalPair mOnCustom{};
#if SQMOD_SDK_LEAST(2, 1)
SignalPair mOnStream{};
#endif
// ----------------------------------------------------------------------------------------
SignalPair mOnEmbarking{};
SignalPair mOnEmbarked{};
SignalPair mOnDisembark{};
SignalPair mOnExplode{};
SignalPair mOnRespawn{};
SignalPair mOnUpdate{};
SignalPair mOnColor{};
SignalPair mOnHealth{};
SignalPair mOnPosition{};
SignalPair mOnRotation{};
SignalPair mOnOption{};
SignalPair mOnWorld{};
SignalPair mOnImmunity{};
SignalPair mOnPartStatus{};
SignalPair mOnTyreStatus{};
SignalPair mOnDamageData{};
SignalPair mOnRadio{};
SignalPair mOnHandlingRule{};
SignalPair mOnEnterArea{};
SignalPair mOnLeaveArea{};
};
} // Namespace:: SqMod
-826
View File
@@ -1,826 +0,0 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// --------------------------------------------------------------------------------------------
void Core::ImportBlips()
{
// Information about the blip entity
Int32 world = -1, scale = -1, sprid = -1;
Uint32 color = 0;
Float32 x = 0.0, y = 0.0, z = 0.0;
for (Int32 i = 0; i < SQMOD_BLIP_POOL; ++i)
{
// See if this entity exists on the server and whether was not allocated already
if (_Func->CheckEntityExists(vcmpEntityPoolBlip, i) && INVALID_ENTITY(m_Blips[i].mID))
{
_Func->GetCoordBlipInfo(i, &world, &x, &y, &z, &scale, &color, &sprid);
// Make the properties available before triggering the event
m_Blips[i].mWorld = world;
m_Blips[i].mScale = scale;
m_Blips[i].mSprID = sprid;
m_Blips[i].mPosition.SetVector3Ex(x, y, z);
m_Blips[i].mColor.SetRGBA(color);
// Attempt to allocate the instance
AllocBlip(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
// ------------------------------------------------------------------------------------------------
void Core::ImportCheckpoints()
{
for (Int32 i = 0; i < SQMOD_CHECKPOINT_POOL; ++i)
{
// See if this entity exists on the server and whether was not allocated already
if (_Func->CheckEntityExists(vcmpEntityPoolCheckPoint, i) && INVALID_ENTITY(m_Checkpoints[i].mID))
{
AllocCheckpoint(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
// ------------------------------------------------------------------------------------------------
void Core::ImportKeybinds()
{
/* @NOTE This function is disabled because VC:MP server seems bugged
* and does not return vcmpErrorNoSuchEntity when the keybind does not exist.
* Therefore causing incorrect behavior in the plugin.
*/
return;
// Information about the key-bind entity
Uint8 release = 0;
Int32 first = -1, second = -1, third = -1;
for (Int32 i = 0; i < SQMOD_KEYBIND_POOL; ++i)
{
// See if this entity exists on the server and whether was not allocated already
if ((_Func->GetKeyBindData(i, &release, &first, &second, &third) != vcmpErrorNoSuchEntity)
&& (INVALID_ENTITY(m_Keybinds[i].mID)))
{
// Make the properties available before triggering the event
m_Keybinds[i].mFirst = first;
m_Keybinds[i].mSecond = second;
m_Keybinds[i].mThird = third;
m_Keybinds[i].mRelease = release;
// Attempt to allocate the instance
AllocKeybind(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
// ------------------------------------------------------------------------------------------------
void Core::ImportObjects()
{
for (Int32 i = 0; i < SQMOD_OBJECT_POOL; ++i)
{
// See if this entity exists on the server and whether was not allocated already
if (_Func->CheckEntityExists(vcmpEntityPoolObject, i) && INVALID_ENTITY(m_Objects[i].mID))
{
AllocObject(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
// ------------------------------------------------------------------------------------------------
void Core::ImportPickups()
{
for (Int32 i = 0; i < SQMOD_PICKUP_POOL; ++i)
{
// See if this entity exists on the server and whether was not allocated already
if (_Func->CheckEntityExists(vcmpEntityPoolPickup, i) && (INVALID_ENTITY(m_Pickups[i].mID)))
{
AllocPickup(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
// ------------------------------------------------------------------------------------------------
void Core::ImportPlayers()
{
for (Int32 i = 0; i < SQMOD_PLAYER_POOL; ++i)
{
// See if this entity exists on the server and whether was not allocated already
if (_Func->IsPlayerConnected(i) && (INVALID_ENTITY(m_Players[i].mID)))
{
ConnectPlayer(i, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
// ------------------------------------------------------------------------------------------------
void Core::ImportVehicles()
{
for (Int32 i = 0; i < SQMOD_VEHICLE_POOL; ++i)
{
// See if this entity exists on the server and whether was not allocated already
if (_Func->CheckEntityExists(vcmpEntityPoolVehicle, i) && INVALID_ENTITY(m_Vehicles[i].mID))
{
AllocVehicle(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
// --------------------------------------------------------------------------------------------
Core::BlipInst & Core::AllocBlip(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
{
STHROWF("Cannot allocate blip with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
BlipInst & inst = m_Blips[id];
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(inst.mID))
{
return inst; // Return the existing instance
}
// Instantiate the entity manager
DeleteGuard< CBlip > dg(new CBlip(id));
// Create the script object
inst.mObj = LightObj(dg.Get(), m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a blip instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitBlipCreated(id, header, payload);
// Return the allocated instance
return inst;
}
// --------------------------------------------------------------------------------------------
Core::CheckpointInst & Core::AllocCheckpoint(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
{
STHROWF("Cannot allocate checkpoint with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
CheckpointInst & inst = m_Checkpoints[id];
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(inst.mID))
{
return inst; // Return the existing instance
}
// Instantiate the entity manager
DeleteGuard< CCheckpoint > dg(new CCheckpoint(id));
// Create the script object
inst.mObj = LightObj(dg.Get(), m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a checkpoint instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitCheckpointCreated(id, header, payload);
// Return the allocated instance
return inst;
}
// --------------------------------------------------------------------------------------------
Core::KeybindInst & Core::AllocKeybind(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
{
STHROWF("Cannot allocate keybind with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
KeybindInst & inst = m_Keybinds[id];
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(inst.mID))
{
return inst; // Return the existing instance
}
// Instantiate the entity manager
DeleteGuard< CKeybind > dg(new CKeybind(id));
// Create the script object
inst.mObj = LightObj(dg.Get(), m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a keybind instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitKeybindCreated(id, header, payload);
// Return the allocated instance
return inst;
}
// --------------------------------------------------------------------------------------------
Core::ObjectInst & Core::AllocObject(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
{
STHROWF("Cannot allocate object with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
ObjectInst & inst = m_Objects[id];
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(inst.mID))
{
return inst; // Return the existing instance
}
// Instantiate the entity manager
DeleteGuard< CObject > dg(new CObject(id));
// Create the script object
inst.mObj = LightObj(dg.Get(), m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a object instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitObjectCreated(id, header, payload);
// Return the allocated instance
return inst;
}
// --------------------------------------------------------------------------------------------
Core::PickupInst & Core::AllocPickup(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
{
STHROWF("Cannot allocate pickup with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
PickupInst & inst = m_Pickups[id];
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(inst.mID))
{
return inst; // Return the existing instance
}
// Instantiate the entity manager
DeleteGuard< CPickup > dg(new CPickup(id));
// Create the script object
inst.mObj = LightObj(dg.Get(), m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a pickup instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitPickupCreated(id, header, payload);
// Return the allocated instance
return inst;
}
// --------------------------------------------------------------------------------------------
Core::VehicleInst & Core::AllocVehicle(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{
STHROWF("Cannot allocate vehicle with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
VehicleInst & inst = m_Vehicles[id];
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(inst.mID))
{
return inst; // Return the existing instance
}
// Instantiate the entity manager
DeleteGuard< CVehicle > dg(new CVehicle(id));
// Create the script object
inst.mObj = LightObj(dg.Get(), m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a vehicle instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Specify whether the entity is owned by this plug-in
if (owned)
{
inst.mFlags |= ENF_OWNED;
}
else if (inst.mFlags & ENF_OWNED)
{
inst.mFlags ^= ENF_OWNED;
}
// Should we enable area tracking?
if (m_AreasEnabled)
{
inst.mFlags |= ENF_AREA_TRACK;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitVehicleCreated(id, header, payload);
// Return the allocated instance
return inst;
}
// --------------------------------------------------------------------------------------------
void Core::DeallocBlip(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
{
STHROWF("Cannot deallocate blip with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
BlipInst & inst = m_Blips[id];
// Make sure that the instance is even allocated and we are allowed to destroy it
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
{
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
}
}
// --------------------------------------------------------------------------------------------
void Core::DeallocCheckpoint(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
{
STHROWF("Cannot deallocate checkpoint with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
CheckpointInst & inst = m_Checkpoints[id];
// Make sure that the instance is even allocated and we are allowed to destroy it
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
{
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
}
}
// --------------------------------------------------------------------------------------------
void Core::DeallocKeybind(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
{
STHROWF("Cannot deallocate keybind with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
KeybindInst & inst = m_Keybinds[id];
// Make sure that the instance is even allocated and we are allowed to destroy it
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
{
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
}
}
// --------------------------------------------------------------------------------------------
void Core::DeallocObject(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
{
STHROWF("Cannot deallocate object with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
ObjectInst & inst = m_Objects[id];
// Make sure that the instance is even allocated and we are allowed to destroy it
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
{
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
}
}
// --------------------------------------------------------------------------------------------
void Core::DeallocPickup(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
{
STHROWF("Cannot deallocate pickup with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
PickupInst & inst = m_Pickups[id];
// Make sure that the instance is even allocated and we are allowed to destroy it
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
{
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
}
}
// --------------------------------------------------------------------------------------------
void Core::DeallocVehicle(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{
STHROWF("Cannot deallocate vehicle with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
VehicleInst & inst = m_Vehicles[id];
// Make sure that the instance is even allocated and we are allowed to destroy it
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
{
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
}
}
// --------------------------------------------------------------------------------------------
LightObj & Core::NewBlip(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 scale, Uint32 color, Int32 sprid,
Int32 header, LightObj & payload)
{
// Request the server to create this entity
const Int32 id = _Func->CreateCoordBlip(index, world, x, y, z, scale, color, sprid);
// See if the entity creation failed on the server
if (_Func->GetLastError() == vcmpErrorPoolExhausted)
{
STHROWF("Blip pool was exhausted: %d", id);
}
// Validate the identifier returned by the server
else if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
{
STHROWF("Server returned invalid blip: %d", id);
}
// Attempt to allocate this entity and grab the reference to the instance
BlipInst & inst = AllocBlip(id, true, header, payload);
// Just in case it was created during the notification for changes in entity pool
if (VALID_ENTITY(inst.mID))
{
inst.mFlags |= ENF_OWNED;
}
// Now we can return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
LightObj & Core::NewCheckpoint(Int32 player, Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, LightObj & payload)
{
// Request the server to create this entity
const Int32 id = _Func->CreateCheckPoint(player, world, sphere, x, y, z, r, g, b, a, radius);
// See if the entity creation failed on the server
if (_Func->GetLastError() == vcmpErrorNoSuchEntity)
{
STHROWF("Invalid player reference: %d", player);
}
else if (_Func->GetLastError() == vcmpErrorPoolExhausted)
{
STHROWF("Checkpoint pool was exhausted: %d", id);
}
// Validate the identifier returned by the server
else if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
{
STHROWF("Server returned invalid checkpoint: %d", id);
}
// Attempt to allocate this entity and grab the reference to the instance
CheckpointInst & inst = AllocCheckpoint(id, true, header, payload);
// Just in case it was created during the notification for changes in entity pool
if (VALID_ENTITY(inst.mID))
{
inst.mFlags |= ENF_OWNED;
}
// Now we can return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
LightObj & Core::NewKeybind(Int32 slot, bool release, Int32 primary, Int32 secondary, Int32 alternative,
Int32 header, LightObj & payload)
{
// Should we obtain a new keybind slot automatically?
if (slot < 0)
{
slot = _Func->GetKeyBindUnusedSlot();
}
// Validate the keybind slot returned by the server
if (INVALID_ENTITYEX(slot, SQMOD_KEYBIND_POOL))
{
STHROWF("Server returned invalid keybind slot: %d", slot);
}
// Request the server to create this entity
const vcmpError result = _Func->RegisterKeyBind(slot, release, primary, secondary, alternative);
// See if the entity creation failed on the server
if (result == vcmpErrorArgumentOutOfBounds)
{
STHROWF("Out of bounds keybind argument: %d", slot);
}
// Attempt to allocate this entity and grab the reference to the instance
KeybindInst & inst = AllocKeybind(slot, true, header, payload);
// Just in case it was created during the notification for changes in entity pool
if (VALID_ENTITY(inst.mID))
{
inst.mFlags |= ENF_OWNED;
}
// Now we can return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
LightObj & Core::NewObject(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Int32 alpha,
Int32 header, LightObj & payload)
{
// Request the server to create this entity
const Int32 id = _Func->CreateObject(model, world, x, y, z, alpha);
// See if the entity creation failed on the server
if (_Func->GetLastError() == vcmpErrorPoolExhausted)
{
STHROWF("Object pool was exhausted: %d", id);
}
// Validate the identifier returned by the server
else if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
{
STHROWF("Server returned invalid object: %d", id);
}
// Attempt to allocate this entity and grab the reference to the instance
ObjectInst & inst = AllocObject(id, true, header, payload);
// Just in case it was created during the notification for changes in entity pool
if (VALID_ENTITY(inst.mID))
{
inst.mFlags |= ENF_OWNED;
}
// Now we can return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
LightObj & Core::NewPickup(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
Int32 header, LightObj & payload)
{
// Request the server to create this entity
const Int32 id = _Func->CreatePickup(model, world, quantity, x, y, z, alpha, automatic);
// See if the entity creation failed on the server
if (_Func->GetLastError() == vcmpErrorPoolExhausted)
{
STHROWF("Pickup pool was exhausted: %d", id);
}
// Validate the identifier returned by the server
else if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
{
STHROWF("Server returned invalid pickup: %d", id);
}
// Attempt to allocate this entity and grab the reference to the instance
PickupInst & inst = AllocPickup(id, true, header, payload);
// Just in case it was created during the notification for changes in entity pool
if (VALID_ENTITY(inst.mID))
{
inst.mFlags |= ENF_OWNED;
}
// Now we can return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
LightObj & Core::NewVehicle(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Float32 angle, Int32 primary, Int32 secondary,
Int32 header, LightObj & payload)
{
// Request the server to create this entity
const Int32 id = _Func->CreateVehicle(model, world, x, y, z, angle, primary, secondary);
// See if the entity creation failed on the server
if (_Func->GetLastError() == vcmpErrorArgumentOutOfBounds)
{
STHROWF("Out of bounds vehicle argument: %d", id);
}
else if (_Func->GetLastError() == vcmpErrorPoolExhausted)
{
STHROWF("Vehicle pool was exhausted: %d", id);
}
// Validate the identifier returned by the server
else if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{
STHROWF("Server returned invalid vehicle: %d", id);
}
// Attempt to allocate this entity and grab the reference to the instance
VehicleInst & inst = AllocVehicle(id, true, header, payload);
// Just in case it was created during the notification for changes in entity pool
if (VALID_ENTITY(inst.mID))
{
inst.mFlags |= ENF_OWNED;
}
// Now we can return the script object
return inst.mObj;
}
// --------------------------------------------------------------------------------------------
bool Core::DelBlip(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocBlip(id, true, header, payload);
// The entity could be destroyed
return true;
}
// ------------------------------------------------------------------------------------------------
bool Core::DelCheckpoint(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocCheckpoint(id, true, header, payload);
// The entity could be destroyed
return true;
}
// ------------------------------------------------------------------------------------------------
bool Core::DelKeybind(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocKeybind(id, true, header, payload);
// The entity could be destroyed
return true;
}
// ------------------------------------------------------------------------------------------------
bool Core::DelObject(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocObject(id, true, header, payload);
// The entity could be destroyed
return true;
}
// ------------------------------------------------------------------------------------------------
bool Core::DelPickup(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocPickup(id, true, header, payload);
// The entity could be destroyed
return true;
}
// ------------------------------------------------------------------------------------------------
bool Core::DelVehicle(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocVehicle(id, true, header, payload);
// The entity could be destroyed
return true;
}
// ------------------------------------------------------------------------------------------------
void Core::ConnectPlayer(Int32 id, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
{
STHROWF("Cannot allocate player with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
PlayerInst & inst = m_Players[id];
// Make sure that the instance isn't already allocated
if (VALID_ENTITY(inst.mID))
{
return; // Nothing to allocate!
}
// Instantiate the entity manager
DeleteGuard< CPlayer > dg(new CPlayer(id));
// Create the script object
inst.mObj = LightObj(dg.Get(), m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
inst.ResetInstance();
STHROWF("Unable to create a player instance for: %d", id);
}
// Assign the specified entity identifier
inst.mID = id;
// Should we enable area tracking?
if (m_AreasEnabled)
{
inst.mFlags |= ENF_AREA_TRACK;
}
// Initialize the position
_Func->GetPlayerPosition(id, &inst.mLastPosition.x, &inst.mLastPosition.y, &inst.mLastPosition.z);
// Initialize the remaining attributes
inst.mLastWeapon = _Func->GetPlayerWeapon(id);
inst.mLastHealth = _Func->GetPlayerHealth(id);
inst.mLastArmour = _Func->GetPlayerArmour(id);
inst.mLastHeading = _Func->GetPlayerHeading(id);
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitPlayerCreated(id, header, payload);
}
// ------------------------------------------------------------------------------------------------
void Core::DisconnectPlayer(Int32 id, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
{
STHROWF("Cannot deallocate player with invalid identifier: %d", id);
}
// Retrieve the specified entity instance
PlayerInst & inst = m_Players[id];
// Make sure that the instance is even allocated and we are allowed to destroy it
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
{
inst.Destroy(false, header, payload); // Now attempt to destroy the entity from the server
}
}
} // Namespace:: SqMod
+182 -182
View File
File diff suppressed because it is too large Load Diff
-375
View File
@@ -1,375 +0,0 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
extern bool GetReloadStatus();
extern void SetReloadStatus(bool toggle);
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(CoreStateTypename, _SC("SqCoreState"))
// ------------------------------------------------------------------------------------------------
static SQInteger SqLoadScript(HSQUIRRELVM vm)
{
const Int32 top = sq_gettop(vm);
// Was the delay option specified?
if (top <= 1)
{
return sq_throwerror(vm, "Missing delay parameter");
}
// Was the script path specified?
else if (top <= 2)
{
return sq_throwerror(vm, "Missing script path");
}
// Whether the script execution is delayed
SQBool delay = SQFalse;
// Attempt to generate the string value
StackStrF val(vm, 3);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.Proc(true)))
{
return val.mRes; // Propagate the error!
}
else if (SQ_FAILED(sq_getbool(vm, 2, &delay)))
{
return sq_throwerror(vm, "Failed to retrieve the delay parameter");
}
// Forward the call to the actual implementation
sq_pushbool(vm, Core::Get().LoadScript(val.mPtr, static_cast< bool >(delay)));
// We have an argument on the stack
return 1;
}
// ------------------------------------------------------------------------------------------------
static SQInteger SqGetEvents(HSQUIRRELVM vm)
{
// Push the events table object on the stack
sq_pushobject(vm, Core::Get().GetEvents().mObj);
// Specify that we're returning a value
return 1;
}
// ------------------------------------------------------------------------------------------------
static void SqEmitCustomEvent(Int32 group, Int32 header, LightObj & payload)
{
Core::Get().EmitCustomEvent(group, header, payload);
}
// ------------------------------------------------------------------------------------------------
static SQInteger SqForceEnableNullEntities(HSQUIRRELVM vm)
{
Core::Get().EnableNullEntities();
return 0;
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetPreLoadEvent()
{
return Core::Get().GetPreLoadEvent();
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetPostLoadEvent()
{
return Core::Get().GetPostLoadEvent();
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetUnloadEvent()
{
return Core::Get().GetUnloadEvent();
}
// ------------------------------------------------------------------------------------------------
static bool SqGetReloadStatus()
{
return GetReloadStatus();
}
// ------------------------------------------------------------------------------------------------
static void SqSetReloadStatus(bool toggle)
{
SetReloadStatus(toggle);
}
// ------------------------------------------------------------------------------------------------
static void SqReloadBecause(Int32 header, LightObj & payload)
{
// Assign the reload info
Core::Get().SetReloadInfo(header, payload);
// Enable reloading
SetReloadStatus(true);
}
// ------------------------------------------------------------------------------------------------
static void SqSetReloadInfo(Int32 header, LightObj & payload)
{
Core::Get().SetReloadInfo(header, payload);
}
// ------------------------------------------------------------------------------------------------
static Int32 SqGetReloadHeader()
{
return Core::Get().GetReloadHeader();
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetReloadPayload()
{
return Core::Get().GetReloadPayload();
}
// ------------------------------------------------------------------------------------------------
static Int32 SqGetState()
{
return Core::Get().GetState();
}
// ------------------------------------------------------------------------------------------------
static void SqSetState(Int32 value)
{
return Core::Get().SetState(value);
}
// ------------------------------------------------------------------------------------------------
static bool SqGetAreasEnabled()
{
return Core::Get().AreasEnabled();
}
// ------------------------------------------------------------------------------------------------
static void SqSetAreasEnabled(bool toggle)
{
Core::Get().AreasEnabled(toggle);
}
// ------------------------------------------------------------------------------------------------
static const String & SqGetOption(StackStrF & name)
{
return Core::Get().GetOption(String(name.mPtr, name.mLen));
}
// ------------------------------------------------------------------------------------------------
static const String & SqGetOptionOr(StackStrF & name, StackStrF & value)
{
return Core::Get().GetOption(String(name.mPtr, name.mLen), StringRef(value.mPtr));
}
// ------------------------------------------------------------------------------------------------
static void SqSetOption(StackStrF & name, StackStrF & value)
{
Core::Get().SetOption(String(name.mPtr, name.mLen), String(value.mPtr, value.mLen));
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetBlip(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
{
STHROWF("Out of range blip identifier: %d", id);
}
// Return the requested information
return Core::Get().GetBlip(id).mObj;
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetCheckpoint(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
{
STHROWF("Out of range checkpoint identifier: %d", id);
}
// Return the requested information
return Core::Get().GetCheckpoint(id).mObj;
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetKeybind(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
{
STHROWF("Out of range keybind identifier: %d", id);
}
// Return the requested information
return Core::Get().GetKeybind(id).mObj;
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetObj(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
{
STHROWF("Out of range object identifier: %d", id);
}
// Return the requested information
return Core::Get().GetObj(id).mObj;
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetPickup(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
{
STHROWF("Out of range blip identifier: %d", id);
}
// Return the requested information
return Core::Get().GetPickup(id).mObj;
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetPlayer(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
{
STHROWF("Out of range player identifier: %d", id);
}
// Return the requested information
return Core::Get().GetPlayer(id).mObj;
}
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetVehicle(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{
STHROWF("Out of range vehicle identifier: %d", id);
}
// Return the requested information
return Core::Get().GetVehicle(id).mObj;
}
// ------------------------------------------------------------------------------------------------
static bool SqDelBlip(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
{
STHROWF("Out of range blip identifier: %d", id);
}
// Perform the requested operation
return Core::Get().DelBlip(id, header, payload);
}
// ------------------------------------------------------------------------------------------------
static bool SqDelCheckpoint(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
{
STHROWF("Out of range checkpoint identifier: %d", id);
}
// Perform the requested operation
return Core::Get().DelCheckpoint(id, header, payload);
}
// ------------------------------------------------------------------------------------------------
static bool SqDelKeybind(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
{
STHROWF("Out of range keybind identifier: %d", id);
}
// Perform the requested operation
return Core::Get().DelKeybind(id, header, payload);
}
// ------------------------------------------------------------------------------------------------
static bool SqDelObject(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
{
STHROWF("Out of range object identifier: %d", id);
}
// Perform the requested operation
return Core::Get().DelObject(id, header, payload);
}
// ------------------------------------------------------------------------------------------------
static bool SqDelPickup(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
{
STHROWF("Out of range blip identifier: %d", id);
}
// Perform the requested operation
return Core::Get().DelPickup(id, header, payload);
}
// ------------------------------------------------------------------------------------------------
static bool SqDelVehicle(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{
STHROWF("Out of range vehicle identifier: %d", id);
}
// Perform the requested operation
return Core::Get().DelVehicle(id, header, payload);
}
// ================================================================================================
void Register_Core(HSQUIRRELVM vm)
{
Table corens(vm);
corens.Bind(_SC("State"),
Class< CoreState, NoCopy< CoreState > >(vm, CoreStateTypename::Str)
// Constructors
.Ctor()
.Ctor< int >()
// Meta-methods
.SquirrelFunc(_SC("_typename"), &CoreStateTypename::Fn)
// Member Properties
.Prop(_SC("Value"), &CoreState::GetValue)
);
corens
.Func(_SC("Reload"), &SqSetReloadStatus)
.Func(_SC("Reloading"), &SqGetReloadStatus)
.Func(_SC("ReloadBecause"), &SqReloadBecause)
.Func(_SC("SetReloadInfo"), &SqSetReloadInfo)
.Func(_SC("GetReloadHeader"), &SqGetReloadHeader)
.Func(_SC("GetReloadPayload"), &SqGetReloadPayload)
.Func(_SC("CustomEvent"), &SqEmitCustomEvent)
.Func(_SC("GetState"), &SqGetState)
.Func(_SC("SetState"), &SqSetState)
.Func(_SC("AreasEnabled"), &SqGetAreasEnabled)
.Func(_SC("SetAreasEnabled"), &SqSetAreasEnabled)
.Func(_SC("GetOption"), &SqGetOption)
.Func(_SC("GetOptionOr"), &SqGetOptionOr)
.Func(_SC("SetOption"), &SqSetOption)
.Func(_SC("GetBlip"), &SqGetBlip)
.Func(_SC("GetCheckpoint"), &SqGetCheckpoint)
.Func(_SC("GetKeybind"), &SqGetKeybind)
.Func(_SC("GetObj"), &SqGetObj)
.Func(_SC("GetPickup"), &SqGetPickup)
.Func(_SC("GetPlayer"), &SqGetPlayer)
.Func(_SC("GetVehicle"), &SqGetVehicle)
.Func(_SC("DestroyBlip"), &SqDelBlip)
.Func(_SC("DestroyCheckpoint"), &SqDelCheckpoint)
.Func(_SC("DestroyKeybind"), &SqDelKeybind)
.Func(_SC("DestroyObject"), &SqDelObject)
.Func(_SC("DestroyPickup"), &SqDelPickup)
.Func(_SC("DestroyVehicle"), &SqDelVehicle)
.Func(_SC("OnPreLoad"), &SqGetPreLoadEvent)
.Func(_SC("OnPostLoad"), &SqGetPostLoadEvent)
.Func(_SC("OnUnload"), &SqGetUnloadEvent)
.SquirrelFunc(_SC("ForceEnableNullEntities"), &SqForceEnableNullEntities)
.SquirrelFunc(_SC("LoadScript"), &SqLoadScript, -3, ".b.")
.SquirrelFunc(_SC("On"), &SqGetEvents);
RootTable(vm).Bind(_SC("SqCore"), corens);
}
} // Namespace:: SqMod
@@ -1,5 +1,5 @@
// ------------------------------------------------------------------------------------------------
#include "Misc/Routine.hpp"
#include "Core/Routine.hpp"
#include "Library/Chrono.hpp"
// ------------------------------------------------------------------------------------------------
@@ -11,7 +11,7 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqRoutineInstance"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqRoutineInstance"))
// ------------------------------------------------------------------------------------------------
Routine::Time Routine::s_Last = 0;
@@ -35,7 +35,7 @@ void Routine::Process()
// Get the current time-stamp
s_Last = Chrono::GetCurrentSysTime();
// Calculate the elapsed time
const auto delta = Int32((s_Last - s_Prev) / 1000L);
const auto delta = int32_t((s_Last - s_Prev) / 1000L);
// Process all active routines
for (Interval * itr = s_Intervals; itr != (s_Intervals + SQMOD_MAX_ROUTINES); ++itr)
{
@@ -196,7 +196,7 @@ SQInteger Routine::Create(HSQUIRRELVM vm)
ClassType< Routine >::PushInstance(vm, dg.Get());
dg.Release();
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
return sq_throwerror(vm, "Unable to create the routine instance");
}
@@ -241,9 +241,9 @@ SQInteger Routine::Create(HSQUIRRELVM vm)
// Attempt to retrieve the routine from the stack and associate it with the slot
try
{
Var< Routine * >(vm, -1).value->m_Slot = ConvTo< Uint32 >::From(slot);
Var< Routine * >(vm, -1).value->m_Slot = ConvTo< uint32_t >::From(slot);
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
// Clear extracted arguments
inst.Clear();
@@ -347,7 +347,7 @@ void Register_Routine(HSQUIRRELVM vm)
.Func(_SC("SetInterval"), &Routine::ApplyInterval)
.Func(_SC("SetIterations"), &Routine::ApplyIterations)
.Func(_SC("SetSuspended"), &Routine::ApplySuspended)
.Func(_SC("SetQuiet"), &Routine::AppplyQuiet)
.Func(_SC("SetQuiet"), &Routine::ApplyQuiet)
.Func(_SC("SetEndure"), &Routine::ApplyEndure)
.Func(_SC("Terminate"), &Routine::Terminate)
.Func(_SC("GetArgument"), &Routine::GetArgument)
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -16,9 +16,9 @@ public:
/* --------------------------------------------------------------------------------------------
* Simplify future changes to a single point of change.
*/
typedef Int64 Time;
typedef int64_t Time;
typedef SQInteger Interval;
typedef Uint32 Iterator;
typedef uint32_t Iterator;
typedef LightObj Argument;
private:
@@ -40,7 +40,7 @@ private:
bool mQuiet; // Whether this instance is allowed to handle errors.
bool mEndure; // Whether this instance is allowed to terminate itself on errors.
bool mExecuting; // Whether this instance is currently being executed.
Uint8 mArgc; // The number of arguments that the routine must forward.
uint8_t mArgc; // The number of arguments that the routine must forward.
Argument mArgv[14]; // The arguments that the routine must forward.
/* ----------------------------------------------------------------------------------------
@@ -150,7 +150,7 @@ private:
sq_pushobject(vm, mInst); // Push self
}
// Push function parameters, if any
for (Uint32 n = 0; n < mArgc; ++n)
for (uint32_t n = 0; n < mArgc; ++n)
{
sq_pushobject(vm, mArgv[n].mObj);
}
@@ -219,7 +219,7 @@ private:
/* --------------------------------------------------------------------------------------------
* The index of the slot in the pool of active routines.
*/
Uint32 m_Slot;
uint32_t m_Slot;
protected:
@@ -235,7 +235,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
explicit Routine(Uint32 slot)
explicit Routine(uint32_t slot)
: m_Slot(slot)
{
/* ... */
@@ -383,7 +383,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* See whether this routine is valid otherwise throw an exception.
*/
Instance & GetValid() const
SQMOD_NODISCARD Instance & GetValid() const
{
if (m_Slot >= SQMOD_MAX_ROUTINES)
{
@@ -398,7 +398,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const
SQMOD_NODISCARD const String & ToString() const
{
return (m_Slot >= SQMOD_MAX_ROUTINES) ? NullString() : s_Instances[m_Slot].mTag;
}
@@ -416,7 +416,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
const String & GetTag() const
SQMOD_NODISCARD const String & GetTag() const
{
return GetValid().mTag;
}
@@ -441,7 +441,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the environment object.
*/
const LightObj & GetEnv() const
SQMOD_NODISCARD const LightObj & GetEnv() const
{
return GetValid().mEnv;
}
@@ -451,13 +451,13 @@ public:
*/
void SetEnv(const LightObj & env)
{
GetValid().mEnv = env.IsNull() ? LightObj(RootTable().GetObj()) : env;
GetValid().mEnv = env.IsNull() ? LightObj(RootTable{}.GetObj()) : env;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the function object.
*/
const LightObj & GetFunc() const
SQMOD_NODISCARD const LightObj & GetFunc() const
{
return GetValid().mFunc;
}
@@ -479,7 +479,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the arbitrary user data object.
*/
const LightObj & GetData() const
SQMOD_NODISCARD const LightObj & GetData() const
{
return GetValid().mData;
}
@@ -504,7 +504,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the execution interval.
*/
SQInteger GetInterval() const
SQMOD_NODISCARD SQInteger GetInterval() const
{
return ConvTo< SQInteger >::From(GetValid().mInterval);
}
@@ -529,7 +529,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of iterations.
*/
SQInteger GetIterations() const
SQMOD_NODISCARD SQInteger GetIterations() const
{
return ConvTo< SQInteger >::From(GetValid().mIterations);
}
@@ -554,7 +554,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the routine is suspended.
*/
bool GetSuspended() const
SQMOD_NODISCARD bool GetSuspended() const
{
return GetValid().mSuspended;
}
@@ -579,7 +579,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the routine is quite.
*/
bool GetQuiet() const
SQMOD_NODISCARD bool GetQuiet() const
{
return GetValid().mQuiet;
}
@@ -595,7 +595,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Set whether the routine should be quiet.
*/
Routine & AppplyQuiet(bool toggle)
Routine & ApplyQuiet(bool toggle)
{
SetQuiet(toggle);
return *this;
@@ -604,7 +604,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the routine endures.
*/
bool GetEndure() const
SQMOD_NODISCARD bool GetEndure() const
{
return GetValid().mEndure;
}
@@ -629,7 +629,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of arguments to be forwarded.
*/
SQInteger GetArguments() const
SQMOD_NODISCARD SQInteger GetArguments() const
{
return ConvTo< SQInteger >::From(GetValid().mArgc);
}
@@ -637,10 +637,10 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve a certain argument.
*/
const Argument & GetArgument(SQInteger arg) const
SQMOD_NODISCARD const Argument & GetArgument(SQInteger arg) const
{
// Cast the index to the proper value
Uint8 idx = ConvTo< Uint8 >::From(arg);
uint8_t idx = ConvTo< uint8_t >::From(arg);
// Validate the specified index
if (idx >= 14)
{
@@ -659,7 +659,7 @@ public:
}
/* --------------------------------------------------------------------------------------------
* See if error reporting is enabled for all newlly created routines.
* See if error reporting is enabled for all newly created routines.
*/
static bool GetSilenced()
{
@@ -667,7 +667,7 @@ public:
}
/* --------------------------------------------------------------------------------------------
* Set if error reporting should be enabled for all newlly created routines.
* Set if error reporting should be enabled for all newly created routines.
*/
static void SetSilenced(bool toggle)
{
@@ -1,5 +1,5 @@
// ------------------------------------------------------------------------------------------------
#include "Base/ScriptSrc.hpp"
#include "Core/Script.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstdio>
@@ -22,7 +22,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
explicit FileHandle(CSStr path)
explicit FileHandle(const SQChar * path)
: mFile(std::fopen(path, "rb"))
{
if (!mFile)
@@ -62,14 +62,6 @@ public:
*/
FileHandle & operator = (FileHandle && o) = delete;
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed file handle.
*/
operator std::FILE * () // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
{
return mFile;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed file handle.
*/
@@ -90,7 +82,7 @@ void ScriptSrc::Process()
// Go to the end of the file
std::fseek(fp, 0, SEEK_END);
// Calculate buffer size from beginning to current position
const LongI length = std::ftell(fp);
const long length = std::ftell(fp);
// Go back to the beginning
std::fseek(fp, 0, SEEK_SET);
// Read the first 2 bytes of the file and determine the file type
@@ -151,7 +143,7 @@ void ScriptSrc::Process()
}
// ------------------------------------------------------------------------------------------------
ScriptSrc::ScriptSrc(const String & path, bool delay, bool info)
ScriptSrc::ScriptSrc(const String & path, bool delay, bool info) // NOLINT(modernize-pass-by-value)
: mExec()
, mPath(path)
, mData()
@@ -1,12 +1,15 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Utility.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <vector>
#include <utility>
// ------------------------------------------------------------------------------------------------
#include <sqratScript.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -21,7 +24,7 @@ class ScriptSrc
public:
// --------------------------------------------------------------------------------------------
typedef std::vector< std::pair< Uint32, Uint32 > > Line;
typedef std::vector< std::pair< uint32_t, uint32_t > > Line;
// --------------------------------------------------------------------------------------------
Script mExec; // Reference to the script object.
@@ -39,7 +42,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
ScriptSrc(const String & path, bool delay = false, bool info = false);
explicit ScriptSrc(const String & path, bool delay = false, bool info = false);
/* --------------------------------------------------------------------------------------------
* Copy constructor.
@@ -62,9 +65,9 @@ public:
ScriptSrc & operator = (ScriptSrc && o) = default;
/* --------------------------------------------------------------------------------------------
* Fetches a line from the code. Can also triim whitespace at the beginning.
* Fetches a line from the code. Can also trim whitespace at the beginning.
*/
String FetchLine(size_t line, bool trim = true) const;
SQMOD_NODISCARD String FetchLine(size_t line, bool trim = true) const;
};
@@ -1,11 +1,11 @@
// ------------------------------------------------------------------------------------------------
#include "Misc/Signal.hpp"
#include "Core/Signal.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqSignalBase"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqSignalBase"))
// ------------------------------------------------------------------------------------------------
Signal::SignalPool Signal::s_Signals;
@@ -56,7 +56,7 @@ struct SignalWrapper
{
mSignal = Var< Signal * >(vm, 1).value;
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
return sq_throwerror(vm, e.what());
}
@@ -1348,7 +1348,7 @@ SQInteger Signal::SqEmit(HSQUIRRELVM vm)
res = signal->Emit(vm, top);
}
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
res = sq_throwerror(vm, e.what());
}
@@ -1388,7 +1388,7 @@ SQInteger Signal::SqQuery(HSQUIRRELVM vm)
res = signal->Query(vm, top);
}
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
res = sq_throwerror(vm, e.what());
}
@@ -1418,7 +1418,7 @@ SQInteger Signal::SqConsume(HSQUIRRELVM vm)
res = signal->Consume(vm, top);
}
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
res = sq_throwerror(vm, e.what());
}
@@ -1448,7 +1448,7 @@ SQInteger Signal::SqApprove(HSQUIRRELVM vm)
res = signal->Approve(vm, top);
}
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
res = sq_throwerror(vm, e.what());
}
@@ -1478,7 +1478,7 @@ SQInteger Signal::SqRequest(HSQUIRRELVM vm)
res = signal->Request(vm, top);
}
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
res = sq_throwerror(vm, e.what());
}
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
#include <vector>
@@ -90,7 +90,8 @@ protected:
/* --------------------------------------------------------------------------------------------
* Structure responsible for storing information about a slot.
*/
struct Slot {
struct Slot
{
SQHash mThisHash; // The hash of the specified environment.
SQHash mFuncHash; // The hash of the specified callback.
HSQOBJECT mThisRef; // The specified script environment.
@@ -265,7 +266,7 @@ protected:
/* ----------------------------------------------------------------------------------------
* Release managed script resources.
*/
bool Available() const
SQMOD_NODISCARD bool Available() const
{
return (mFuncHash == 0);
}
@@ -326,7 +327,8 @@ protected:
// --------------------------------------------------------------------------------------------
/// Execution scope used to adjust iterators when removing slots or adjusting the buffer.
struct Scope {
struct Scope
{
// ----------------------------------------------------------------------------------------
Pointer mItr; ///< Currently executed slot.
Pointer mEnd; ///< Where the execution ends.
@@ -374,7 +376,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const
SQMOD_NODISCARD const String & ToString() const
{
return m_Name;
}
@@ -382,7 +384,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
LightObj & GetData()
SQMOD_NODISCARD LightObj & GetData()
{
return m_Data;
}
@@ -398,7 +400,7 @@ public:
/* --------------------------------------------------------------------------------------------
* The number of slots connected to the signal.
*/
SQInteger GetUsed() const
SQMOD_NODISCARD SQInteger GetUsed() const
{
return static_cast< SQInteger >(m_Used);
}
@@ -411,7 +413,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See if there are any slots connected.
*/
bool IsEmpty() const
SQMOD_NODISCARD bool IsEmpty() const
{
return (m_Used == 0);
}
@@ -699,12 +701,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Create a free signal without a specific name.
*/
static LightObj CreateFree();
SQMOD_NODISCARD static LightObj CreateFree();
/* --------------------------------------------------------------------------------------------
* Create a new signal with the specified name.
*/
static LightObj Create(StackStrF & name);
SQMOD_NODISCARD static LightObj Create(StackStrF & name);
/* --------------------------------------------------------------------------------------------
* Remove the signal with the specified name.
@@ -714,7 +716,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the signal with the specified name.
*/
static const LightObj & Fetch(StackStrF & name);
SQMOD_NODISCARD static const LightObj & Fetch(StackStrF & name);
/* --------------------------------------------------------------------------------------------
* Emit a signal from the module.
+25 -25
View File
@@ -1,5 +1,5 @@
// ------------------------------------------------------------------------------------------------
#include "Tasks.hpp"
#include "Core/Tasks.hpp"
#include "Core.hpp"
#include "Library/Chrono.hpp"
@@ -12,7 +12,7 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqTask"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqTask"))
// ------------------------------------------------------------------------------------------------
Tasks::Time Tasks::s_Last = 0;
@@ -21,7 +21,7 @@ Tasks::Interval Tasks::s_Intervals[SQMOD_MAX_TASKS];
Tasks::Task Tasks::s_Tasks[SQMOD_MAX_TASKS];
// ------------------------------------------------------------------------------------------------
void Tasks::Task::Init(HSQOBJECT & func, HSQOBJECT & inst, Interval intrv, Iterator itr, Int32 id, Int32 type)
void Tasks::Task::Init(HSQOBJECT & func, HSQOBJECT & inst, Interval intrv, Iterator itr, int32_t id, int32_t type)
{
// Initialize the callback hash
mHash = 0;
@@ -32,8 +32,8 @@ void Tasks::Task::Init(HSQOBJECT & func, HSQOBJECT & inst, Interval intrv, Itera
mIterations = itr;
mInterval = intrv;
// Initialize the entity information
mEntity = ConvTo< Int16 >::From(id);
mType = ConvTo< Uint8 >::From(type);
mEntity = ConvTo< int16_t >::From(id);
mType = ConvTo< uint8_t >::From(type);
// Grab the virtual machine once
HSQUIRRELVM vm = SqVM();
// Remember the current stack size
@@ -77,7 +77,7 @@ Tasks::Interval Tasks::Task::Execute()
// Push the environment on the stack
sq_pushobject(vm, mSelf);
// Push function parameters, if any
for (Uint32 n = 0; n < mArgc; ++n)
for (uint32_t n = 0; n < mArgc; ++n)
{
sq_pushobject(vm, mArgv[n].mObj);
}
@@ -114,7 +114,7 @@ void Tasks::Process()
// Get the current time-stamp
s_Last = Chrono::GetCurrentSysTime();
// Calculate the elapsed time
const auto delta = Int32((s_Last - s_Prev) / 1000L);
const auto delta = int32_t((s_Last - s_Prev) / 1000L);
// Process all active tasks
for (Interval * itr = s_Intervals; itr != (s_Intervals + SQMOD_MAX_TASKS); ++itr)
{
@@ -183,13 +183,13 @@ void Tasks::Deinitialize()
}
// ------------------------------------------------------------------------------------------------
LightObj & Tasks::FindEntity(Int32 id, Int32 type)
LightObj & Tasks::FindEntity(int32_t id, int32_t type)
{
switch (type)
{
case ENT_BLIP: return Core::Get().GetBlip(id).mObj;
case ENT_CHECKPOINT: return Core::Get().GetCheckpoint(id).mObj;
case ENT_KEYBIND: return Core::Get().GetKeybind(id).mObj;
case ENT_KEYBIND: return Core::Get().GetKeyBind(id).mObj;
case ENT_OBJECT: return Core::Get().GetObj(id).mObj;
case ENT_PICKUP: return Core::Get().GetPickup(id).mObj;
case ENT_PLAYER: return Core::Get().GetPlayer(id).mObj;
@@ -213,7 +213,7 @@ SQInteger Tasks::FindUnused()
}
// ------------------------------------------------------------------------------------------------
SQInteger Tasks::Create(Int32 id, Int32 type, HSQUIRRELVM vm)
SQInteger Tasks::Create(int32_t id, int32_t type, HSQUIRRELVM vm)
{
// Locate the identifier of a free slot
const SQInteger slot = FindUnused();
@@ -324,7 +324,7 @@ SQInteger Tasks::Create(Int32 id, Int32 type, HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
SQInteger Tasks::Find(Int32 id, Int32 type, SQInteger & pos, HSQUIRRELVM vm)
SQInteger Tasks::Find(int32_t id, int32_t type, SQInteger & pos, HSQUIRRELVM vm)
{
// Grab the top of the stack
const SQInteger top = sq_gettop(vm);
@@ -402,7 +402,7 @@ SQInteger Tasks::Find(Int32 id, Int32 type, SQInteger & pos, HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
SQInteger Tasks::Remove(Int32 id, Int32 type, HSQUIRRELVM vm)
SQInteger Tasks::Remove(int32_t id, int32_t type, HSQUIRRELVM vm)
{
// Default to not found
SQInteger pos = -1;
@@ -430,7 +430,7 @@ SQInteger Tasks::Remove(Int32 id, Int32 type, HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
SQInteger Tasks::Exists(Int32 id, Int32 type, HSQUIRRELVM vm)
SQInteger Tasks::Exists(int32_t id, int32_t type, HSQUIRRELVM vm)
{
// Default to not found
SQInteger pos = -1;
@@ -448,7 +448,7 @@ SQInteger Tasks::Exists(Int32 id, Int32 type, HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
const Tasks::Task & Tasks::FindByTag(Int32 id, Int32 type, StackStrF & tag)
const Tasks::Task & Tasks::FindByTag(int32_t id, int32_t type, StackStrF & tag)
{
// Attempt to find the requested task
for (const auto & t : s_Tasks)
@@ -461,11 +461,11 @@ const Tasks::Task & Tasks::FindByTag(Int32 id, Int32 type, StackStrF & tag)
// Unable to find such task
STHROWF("Unable to find a task with tag (%s)", tag.mPtr);
// Should not reach this point but if it did, we have to return something
return s_Tasks[SQMOD_MAX_TASKS]; // Intentional Buffer overflow!
SQ_UNREACHABLE
}
// ------------------------------------------------------------------------------------------------
void Tasks::Cleanup(Int32 id, Int32 type)
void Tasks::Cleanup(int32_t id, int32_t type)
{
for (auto & t : s_Tasks)
{
@@ -494,14 +494,6 @@ void InitializeTasks()
Tasks::Initialize();
}
/* ------------------------------------------------------------------------------------------------
* Forward the call to register tasks.
*/
void RegisterTask(HSQUIRRELVM vm)
{
Tasks::Register(vm);
}
/* ------------------------------------------------------------------------------------------------
* Forward the call to terminate tasks.
*/
@@ -513,9 +505,17 @@ void TerminateTasks()
/* ------------------------------------------------------------------------------------------------
* Forward the call to cleanup certain tasks.
*/
void CleanupTasks(Int32 id, Int32 type)
void CleanupTasks(int32_t id, int32_t type)
{
Tasks::Cleanup(id, type);
}
/* ------------------------------------------------------------------------------------------------
* Forward the call to register tasks.
*/
void Register_Tasks(HSQUIRRELVM vm)
{
Tasks::Register(vm);
}
} // Namespace:: SqMod
+40 -40
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -16,9 +16,9 @@ public:
/* --------------------------------------------------------------------------------------------
* Simplify future changes to a single point of change.
*/
typedef Int64 Time;
typedef int64_t Time;
typedef SQInteger Interval;
typedef Uint32 Iterator;
typedef uint32_t Iterator;
typedef LightObj Argument;
private:
@@ -37,9 +37,9 @@ private:
LightObj mData; // A reference to the arbitrary data associated with this instance.
Iterator mIterations; // Number of iterations before self destruct.
Interval mInterval; // Interval between task invocations.
Int16 mEntity; // The identifier of the entity to which is belongs.
Uint8 mType; // The type of the entity to which is belongs.
Uint8 mArgc; // The number of arguments that the task must forward.
int16_t mEntity; // The identifier of the entity to which is belongs.
uint8_t mType; // The type of the entity to which is belongs.
uint8_t mArgc; // The number of arguments that the task must forward.
Argument mArgv[8]; // The arguments that the task must forward.
/* ----------------------------------------------------------------------------------------
@@ -93,7 +93,7 @@ private:
/* ----------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const
SQMOD_NODISCARD const String & ToString() const
{
return mTag;
}
@@ -101,7 +101,7 @@ private:
/* ----------------------------------------------------------------------------------------
* Initializes the task parameters. (assumes previous values are already released)
*/
void Init(HSQOBJECT & inst, HSQOBJECT & func, Interval intrv, Iterator itr, Int32 id, Int32 type);
void Init(HSQOBJECT & inst, HSQOBJECT & func, Interval intrv, Iterator itr, int32_t id, int32_t type);
/* ----------------------------------------------------------------------------------------
* Release managed script resources.
@@ -139,7 +139,7 @@ private:
/* ----------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
const String & GetTag() const
SQMOD_NODISCARD const String & GetTag() const
{
return mTag;
}
@@ -155,7 +155,7 @@ private:
/* ----------------------------------------------------------------------------------------
* Retrieve the instance to entity instance.
*/
const LightObj & GetInst() const
SQMOD_NODISCARD const LightObj & GetInst() const
{
return mInst;
}
@@ -163,7 +163,7 @@ private:
/* ----------------------------------------------------------------------------------------
* Retrieve the function object.
*/
const LightObj & GetFunc() const
SQMOD_NODISCARD const LightObj & GetFunc() const
{
return mFunc;
}
@@ -193,7 +193,7 @@ private:
/* ----------------------------------------------------------------------------------------
* Retrieve the arbitrary user data object.
*/
const LightObj & GetData() const
SQMOD_NODISCARD const LightObj & GetData() const
{
return mData;
}
@@ -209,7 +209,7 @@ private:
/* ----------------------------------------------------------------------------------------
* Retrieve the execution interval.
*/
SQInteger GetInterval() const
SQMOD_NODISCARD SQInteger GetInterval() const
{
return ConvTo< SQInteger >::From(mInterval);
}
@@ -225,7 +225,7 @@ private:
/* ----------------------------------------------------------------------------------------
* Retrieve the number of iterations.
*/
SQInteger GetIterations() const
SQMOD_NODISCARD SQInteger GetIterations() const
{
return ConvTo< SQInteger >::From(mIterations);
}
@@ -241,7 +241,7 @@ private:
/* ----------------------------------------------------------------------------------------
* Retrieve the number of arguments to be forwarded.
*/
SQInteger GetArguments() const
SQMOD_NODISCARD SQInteger GetArguments() const
{
return ConvTo< SQInteger >::From(mArgc);
}
@@ -249,11 +249,11 @@ private:
/* ----------------------------------------------------------------------------------------
* Retrieve a certain argument.
*/
const Argument & GetArgument(SQInteger arg) const
SQMOD_NODISCARD const Argument & GetArgument(SQInteger arg) const
{
constexpr Uint32 argvn = (sizeof(mArgv) / sizeof(mArgv[0]));
constexpr uint32_t argvn = (sizeof(mArgv) / sizeof(mArgv[0]));
// Cast the index to the proper value
Uint8 idx = ConvTo< Uint8 >::From(arg);
uint8_t idx = ConvTo< uint8_t >::From(arg);
// Validate the specified index
if (idx >= argvn)
{
@@ -327,7 +327,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* Retrieve the instance of the specified entity.
*/
static LightObj & FindEntity(Int32 id, Int32 type);
static LightObj & FindEntity(int32_t id, int32_t type);
/* --------------------------------------------------------------------------------------------
* Find an unoccupied task slot.
@@ -337,34 +337,34 @@ protected:
/* --------------------------------------------------------------------------------------------
* Locate the first task with the specified parameters.
*/
static SQInteger Find(Int32 id, Int32 type, SQInteger & pos, HSQUIRRELVM vm);
static SQInteger Find(int32_t id, int32_t type, SQInteger & pos, HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Attempt to create a task with the specified parameters.
*/
static SQInteger Create(Int32 id, Int32 type, HSQUIRRELVM vm);
static SQInteger Create(int32_t id, int32_t type, HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Attempt to remove the task with the specified parameters.
*/
static SQInteger Remove(Int32 id, Int32 type, HSQUIRRELVM vm);
static SQInteger Remove(int32_t id, int32_t type, HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* See if a task with the specified parameters exists.
*/
static SQInteger Exists(Int32 id, Int32 type, HSQUIRRELVM vm);
static SQInteger Exists(int32_t id, int32_t type, HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Cleanup all tasks associated with the specified entity.
*/
static const Task & FindByTag(Int32 id, Int32 type, StackStrF & tag);
static const Task & FindByTag(int32_t id, int32_t type, StackStrF & tag);
public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of used tasks slots.
*/
static SQInteger GetUsed()
SQMOD_NODISCARD static SQInteger GetUsed()
{
SQInteger n = 0;
// Iterate task list
@@ -382,15 +382,15 @@ public:
/* --------------------------------------------------------------------------------------------
* Cleanup all tasks associated with the specified entity.
*/
static void Cleanup(Int32 id, Int32 type);
static void Cleanup(int32_t id, int32_t type);
/* --------------------------------------------------------------------------------------------
* Forwards calls to create tasks.
*/
template < typename Entity, Int32 Type > static SQInteger MakeTask(HSQUIRRELVM vm)
template < typename Entity, int32_t Type > static SQInteger MakeTask(HSQUIRRELVM vm)
{
// The entity instance
const Entity * inst = nullptr;
const Entity * inst;
// Attempt to extract the instance
try
{
@@ -401,10 +401,10 @@ public:
{
STHROWF("Invalid entity instance");
}
// Validate the actual entity instance
// Validate the std::exception entity instance
inst->Validate();
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
return sq_throwerror(vm, e.what());
}
@@ -415,10 +415,10 @@ public:
/* --------------------------------------------------------------------------------------------
* Forwards calls to remove tasks.
*/
template < typename Entity, Int32 Type > static SQInteger DropTask(HSQUIRRELVM vm)
template < typename Entity, int32_t Type > static SQInteger DropTask(HSQUIRRELVM vm)
{
// The entity instance
const Entity * inst = nullptr;
const Entity * inst;
// Attempt to extract the instance
try
{
@@ -432,7 +432,7 @@ public:
// Validate the actual entity instance
inst->Validate();
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
return sq_throwerror(vm, e.what());
}
@@ -443,10 +443,10 @@ public:
/* --------------------------------------------------------------------------------------------
* Forwards calls to check tasks.
*/
template < typename Entity, Int32 Type > static SQInteger DoesTask(HSQUIRRELVM vm)
template < typename Entity, int32_t Type > static SQInteger DoesTask(HSQUIRRELVM vm)
{
// The entity instance
const Entity * inst = nullptr;
const Entity * inst;
// Attempt to extract the instance
try
{
@@ -460,7 +460,7 @@ public:
// Validate the actual entity instance
inst->Validate();
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
return sq_throwerror(vm, e.what());
}
@@ -471,7 +471,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Forwards calls to find tasks.
*/
template < typename Entity, Int32 Type > static SQInteger FindTask(HSQUIRRELVM vm)
template < typename Entity, int32_t Type > static SQInteger FindTask(HSQUIRRELVM vm)
{
// Was the tag string specified?
if (sq_gettop(vm) <= 1)
@@ -479,7 +479,7 @@ public:
return sq_throwerror(vm, "Missing tag string");
}
// The entity instance
const Entity * inst = nullptr;
const Entity * inst;
// Attempt to extract the instance
try
{
@@ -493,7 +493,7 @@ public:
// Validate the actual entity instance
inst->Validate();
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
return sq_throwerror(vm, e.what());
}
@@ -512,7 +512,7 @@ public:
// Now push the instance on the stack
sq_pushobject(vm, task.mSelf.mObj);
}
catch (const Sqrat::Exception & e)
catch (const std::exception & e)
{
return sq_throwerror(vm, e.what());
}
+423
View File
@@ -0,0 +1,423 @@
// ------------------------------------------------------------------------------------------------
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
#ifdef SQMOD_OS_WINDOWS
#include <windows.h>
#endif // SQMOD_OS_WINDOWS
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Really poor design decision if a multi-threaded situation ever occurs. Don't do this. Ever!
*/
static SQChar g_NumBuf[1024];
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< int8_t >::ToStr(int8_t v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%d", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
int8_t ConvNum< int8_t >::FromStr(const SQChar * s)
{
return ConvTo< int8_t >::From(std::strtol(s, nullptr, 10));
}
int8_t ConvNum< int8_t >::FromStr(const SQChar * s, int32_t base)
{
return ConvTo< int8_t >::From(std::strtol(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< uint8_t >::ToStr(uint8_t v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%u", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
uint8_t ConvNum< uint8_t >::FromStr(const SQChar * s)
{
return ConvTo< uint8_t >::From(std::strtoul(s, nullptr, 10));
}
uint8_t ConvNum< uint8_t >::FromStr(const SQChar * s, int32_t base)
{
return ConvTo< uint8_t >::From(std::strtoul(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< int16_t >::ToStr(int16_t v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%d", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
int16_t ConvNum< int16_t >::FromStr(const SQChar * s)
{
return ConvTo< int16_t >::From(std::strtol(s, nullptr, 10));
}
int16_t ConvNum< int16_t >::FromStr(const SQChar * s, int32_t base)
{
return ConvTo< int16_t >::From(std::strtol(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< uint16_t >::ToStr(uint16_t v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%u", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
uint16_t ConvNum< uint16_t >::FromStr(const SQChar * s)
{
return ConvTo< uint16_t >::From(std::strtoul(s, nullptr, 10));
}
uint16_t ConvNum< uint16_t >::FromStr(const SQChar * s, int32_t base)
{
return ConvTo< uint16_t >::From(std::strtoul(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< int32_t >::ToStr(int32_t v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%d", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
int32_t ConvNum< int32_t >::FromStr(const SQChar * s)
{
return ConvTo< int32_t >::From(std::strtol(s, nullptr, 10));
}
int32_t ConvNum< int32_t >::FromStr(const SQChar * s, int32_t base)
{
return ConvTo< int32_t >::From(std::strtol(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< uint32_t >::ToStr(uint32_t v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%u", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
uint32_t ConvNum< uint32_t >::FromStr(const SQChar * s)
{
return ConvTo< uint32_t >::From(std::strtoul(s, nullptr, 10));
}
uint32_t ConvNum< uint32_t >::FromStr(const SQChar * s, int32_t base)
{
return ConvTo< uint32_t >::From(std::strtoul(s, nullptr, base));
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< int64_t >::ToStr(int64_t v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%lld", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
int64_t ConvNum< int64_t >::FromStr(const SQChar * s)
{
return std::strtoll(s, nullptr, 10);
}
int64_t ConvNum< int64_t >::FromStr(const SQChar * s, int32_t base)
{
return std::strtoll(s, nullptr, base);
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< uint64_t >::ToStr(uint64_t v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%llu", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
uint64_t ConvNum< uint64_t >::FromStr(const SQChar * s)
{
return std::strtoull(s, nullptr, 10);
}
uint64_t ConvNum< uint64_t >::FromStr(const SQChar * s, int32_t base)
{
return std::strtoull(s, nullptr, base);
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< long >::ToStr(long v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%ld", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
long ConvNum< long >::FromStr(const SQChar * s)
{
return std::strtol(s, nullptr, 10);
}
long ConvNum< long >::FromStr(const SQChar * s, int32_t base)
{
return std::strtol(s, nullptr, base);
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< unsigned long >::ToStr(unsigned long v)
{
// Write the numeric value to the buffer
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%lu", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the beginning of the buffer
return g_NumBuf;
}
unsigned long ConvNum< unsigned long >::FromStr(const SQChar * s)
{
return std::strtoul(s, nullptr, 10);
}
unsigned long ConvNum< unsigned long >::FromStr(const SQChar * s, int32_t base)
{
return std::strtoul(s, nullptr, base);
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< float >::ToStr(float v)
{
// Attempt to convert the value to a string
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%f", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the data from the buffer
return g_NumBuf;
}
float ConvNum< float >::FromStr(const SQChar * s)
{
return std::strtof(s, nullptr);
}
float ConvNum< float >::FromStr(const SQChar * s, int32_t /*base*/)
{
return std::strtof(s, nullptr);
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< double >::ToStr(double v)
{
// Attempt to convert the value to a string
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%f", v) < 0)
{
g_NumBuf[0] = '\0';
}
// Return the data from the buffer
return g_NumBuf;
}
double ConvNum< double >::FromStr(const SQChar * s)
{
return std::strtod(s, nullptr);
}
double ConvNum< double >::FromStr(const SQChar * s, int32_t /*base*/)
{
return std::strtod(s, nullptr);
}
// ------------------------------------------------------------------------------------------------
const SQChar * ConvNum< bool >::ToStr(bool v)
{
if (v)
{
g_NumBuf[0] = 't';
g_NumBuf[1] = 'r';
g_NumBuf[2] = 'u';
g_NumBuf[3] = 'e';
g_NumBuf[4] = '\0';
}
else
{
g_NumBuf[0] = 'f';
g_NumBuf[1] = 'a';
g_NumBuf[2] = 'l';
g_NumBuf[3] = 's';
g_NumBuf[4] = 'e';
g_NumBuf[5] = '\0';
}
return g_NumBuf;
}
bool ConvNum< bool >::FromStr(const SQChar * s)
{
return std::strcmp(s, "true") == 0;
}
bool ConvNum< bool >::FromStr(const SQChar * s, int32_t /*base*/)
{
return std::strcmp(s, "true") == 0;
}
// ------------------------------------------------------------------------------------------------
bool NameFilterCheck(const SQChar * filter, const SQChar * name)
{
// If only one of them is null then they don't match
if ((!filter && name) || (filter && !name))
{
return false;
}
// If they're both null or the filter is empty then there's nothing to check for
else if ((!filter && !name) || (*filter == '\0'))
{
return true;
}
SQChar ch;
// Start comparing the strings
while (true)
{
// Grab the current character from filter
ch = *(filter++);
// See if the filter or name was completed
if (ch == '\0' || *name == '\0')
{
break; // They matched so far
}
// Are we supposed to perform a wild-card search?
else if (ch == '*')
{
// Grab the next character from filter
ch = *(filter++);
// Start comparing characters until the first match
while (*name != '\0')
{
if (*(name++) == ch)
{
break;
}
}
}
// See if the character matches doesn't have to match
else if (ch != '?' && *name != ch)
{
return false; // The character had to match and failed
}
else
{
++name;
}
}
// At this point the name satisfied the filter
return true;
}
// ------------------------------------------------------------------------------------------------
bool NameFilterCheckInsensitive(const SQChar * filter, const SQChar * name)
{
// If only one of them is null then they don't match
if ((!filter && name) || (filter && !name))
{
return false;
}
// If they're both null or the filter is empty then there's nothing to check for
else if ((!filter && !name) || (*filter == '\0'))
{
return true;
}
SQChar ch;
// Start comparing the strings
while (true)
{
// Grab the current character from filter
ch = static_cast< SQChar >(std::tolower(*(filter++)));
// See if the filter or name was completed
if (ch == '\0' || *name == '\0')
{
break; // They matched so far
}
// Are we supposed to perform a wild-card search?
else if (ch == '*')
{
// Grab the next character from filter
ch = static_cast< SQChar >(std::tolower(*(filter++)));
// Start comparing characters until the first match
while (*name != '\0')
{
if (static_cast< SQChar >(std::tolower(*(name++))) == ch)
{
break;
}
}
}
// See if the character matches doesn't have to match
else if (ch != '?' && static_cast< SQChar >(std::tolower(*name)) != ch)
{
return false; // The character had to match and failed
}
else
{
++name;
}
}
// At this point the name satisfied the filter
return true;
}
} // Namespace:: SqMod
File diff suppressed because it is too large Load Diff
-345
View File
@@ -1,345 +0,0 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
void Core::ClearContainer(EntityType type)
{
switch (type)
{
case ENT_BLIP:
{
m_Blips.clear();
} break;
case ENT_CHECKPOINT:
{
m_Checkpoints.clear();
} break;
case ENT_KEYBIND:
{
m_Keybinds.clear();
} break;
case ENT_OBJECT:
{
m_Objects.clear();
} break;
case ENT_PICKUP:
{
m_Pickups.clear();
} break;
case ENT_PLAYER:
{
m_Players.clear();
} break;
case ENT_VEHICLE:
{
m_Vehicles.clear();
} break;
default: STHROWF("Cannot clear unknown entity type container");
}
}
// ------------------------------------------------------------------------------------------------
void Core::InitEvents()
{
// Ignore the call if already initialized
if (!m_Events.IsNull())
{
return;
}
// Create a new table on the stack
sq_newtableex(SqVM(), 128);
// Grab the table object from the stack
m_Events = LightObj(-1, SqVM());
// Pop the table object from the stack
sq_pop(SqVM(), 1);
// Proceed to initializing the events
InitSignalPair(mOnCustomEvent, m_Events, "CustomEvent");
InitSignalPair(mOnBlipCreated, m_Events, "BlipCreated");
InitSignalPair(mOnCheckpointCreated, m_Events, "CheckpointCreated");
InitSignalPair(mOnKeybindCreated, m_Events, "KeybindCreated");
InitSignalPair(mOnObjectCreated, m_Events, "ObjectCreated");
InitSignalPair(mOnPickupCreated, m_Events, "PickupCreated");
InitSignalPair(mOnPlayerCreated, m_Events, "PlayerCreated");
InitSignalPair(mOnVehicleCreated, m_Events, "VehicleCreated");
InitSignalPair(mOnBlipDestroyed, m_Events, "BlipDestroyed");
InitSignalPair(mOnCheckpointDestroyed, m_Events, "CheckpointDestroyed");
InitSignalPair(mOnKeybindDestroyed, m_Events, "KeybindDestroyed");
InitSignalPair(mOnObjectDestroyed, m_Events, "ObjectDestroyed");
InitSignalPair(mOnPickupDestroyed, m_Events, "PickupDestroyed");
InitSignalPair(mOnPlayerDestroyed, m_Events, "PlayerDestroyed");
InitSignalPair(mOnVehicleDestroyed, m_Events, "VehicleDestroyed");
InitSignalPair(mOnBlipCustom, m_Events, "BlipCustom");
InitSignalPair(mOnCheckpointCustom, m_Events, "CheckpointCustom");
InitSignalPair(mOnKeybindCustom, m_Events, "KeybindCustom");
InitSignalPair(mOnObjectCustom, m_Events, "ObjectCustom");
InitSignalPair(mOnPickupCustom, m_Events, "PickupCustom");
InitSignalPair(mOnPlayerCustom, m_Events, "PlayerCustom");
InitSignalPair(mOnVehicleCustom, m_Events, "VehicleCustom");
#if SQMOD_SDK_LEAST(2, 1)
InitSignalPair(mOnCheckpointStream, m_Events, "CheckpointStream");
InitSignalPair(mOnObjectStream, m_Events, "ObjectStream");
InitSignalPair(mOnPickupStream, m_Events, "PickupStream");
InitSignalPair(mOnPlayerStream, m_Events, "PlayerStream");
InitSignalPair(mOnVehicleStream, m_Events, "VehicleStream");
#endif
InitSignalPair(mOnServerStartup, m_Events, "ServerStartup");
InitSignalPair(mOnServerShutdown, m_Events, "ServerShutdown");
InitSignalPair(mOnServerFrame, m_Events, "ServerFrame");
InitSignalPair(mOnIncomingConnection, m_Events, "IncomingConnection");
InitSignalPair(mOnPlayerRequestClass, m_Events, "PlayerRequestClass");
InitSignalPair(mOnPlayerRequestSpawn, m_Events, "PlayerRequestSpawn");
InitSignalPair(mOnPlayerSpawn, m_Events, "PlayerSpawn");
InitSignalPair(mOnPlayerWasted, m_Events, "PlayerWasted");
InitSignalPair(mOnPlayerKilled, m_Events, "PlayerKilled");
InitSignalPair(mOnPlayerEmbarking, m_Events, "PlayerEmbarking");
InitSignalPair(mOnPlayerEmbarked, m_Events, "PlayerEmbarked");
InitSignalPair(mOnPlayerDisembark, m_Events, "PlayerDisembark");
InitSignalPair(mOnPlayerRename, m_Events, "PlayerRename");
InitSignalPair(mOnPlayerState, m_Events, "PlayerState");
InitSignalPair(mOnStateNone, m_Events, "StateNone");
InitSignalPair(mOnStateNormal, m_Events, "StateNormal");
InitSignalPair(mOnStateAim, m_Events, "StateAim");
InitSignalPair(mOnStateDriver, m_Events, "StateDriver");
InitSignalPair(mOnStatePassenger, m_Events, "StatePassenger");
InitSignalPair(mOnStateEnterDriver, m_Events, "StateEnterDriver");
InitSignalPair(mOnStateEnterPassenger, m_Events, "StateEnterPassenger");
InitSignalPair(mOnStateExit, m_Events, "StateExit");
InitSignalPair(mOnStateUnspawned, m_Events, "StateUnspawned");
InitSignalPair(mOnPlayerAction, m_Events, "PlayerAction");
InitSignalPair(mOnActionNone, m_Events, "ActionNone");
InitSignalPair(mOnActionNormal, m_Events, "ActionNormal");
InitSignalPair(mOnActionAiming, m_Events, "ActionAiming");
InitSignalPair(mOnActionShooting, m_Events, "ActionShooting");
InitSignalPair(mOnActionJumping, m_Events, "ActionJumping");
InitSignalPair(mOnActionLieDown, m_Events, "ActionLieDown");
InitSignalPair(mOnActionGettingUp, m_Events, "ActionGettingUp");
InitSignalPair(mOnActionJumpVehicle, m_Events, "ActionJumpVehicle");
InitSignalPair(mOnActionDriving, m_Events, "ActionDriving");
InitSignalPair(mOnActionDying, m_Events, "ActionDying");
InitSignalPair(mOnActionWasted, m_Events, "ActionWasted");
InitSignalPair(mOnActionEmbarking, m_Events, "ActionEmbarking");
InitSignalPair(mOnActionDisembarking, m_Events, "ActionDisembarking");
InitSignalPair(mOnPlayerBurning, m_Events, "PlayerBurning");
InitSignalPair(mOnPlayerCrouching, m_Events, "PlayerCrouching");
InitSignalPair(mOnPlayerGameKeys, m_Events, "PlayerGameKeys");
InitSignalPair(mOnPlayerStartTyping, m_Events, "PlayerStartTyping");
InitSignalPair(mOnPlayerStopTyping, m_Events, "PlayerStopTyping");
InitSignalPair(mOnPlayerAway, m_Events, "PlayerAway");
InitSignalPair(mOnPlayerMessage, m_Events, "PlayerMessage");
InitSignalPair(mOnPlayerCommand, m_Events, "PlayerCommand");
InitSignalPair(mOnPlayerPrivateMessage, m_Events, "PlayerPrivateMessage");
InitSignalPair(mOnPlayerKeyPress, m_Events, "PlayerKeyPress");
InitSignalPair(mOnPlayerKeyRelease, m_Events, "PlayerKeyRelease");
InitSignalPair(mOnPlayerSpectate, m_Events, "PlayerSpectate");
InitSignalPair(mOnPlayerUnspectate, m_Events, "PlayerUnspectate");
InitSignalPair(mOnPlayerCrashreport, m_Events, "PlayerCrashreport");
InitSignalPair(mOnPlayerModuleList, m_Events, "PlayerModuleList");
InitSignalPair(mOnVehicleExplode, m_Events, "VehicleExplode");
InitSignalPair(mOnVehicleRespawn, m_Events, "VehicleRespawn");
InitSignalPair(mOnObjectShot, m_Events, "ObjectShot");
InitSignalPair(mOnObjectTouched, m_Events, "ObjectTouched");
InitSignalPair(mOnObjectWorld, m_Events, "ObjectWorld");
InitSignalPair(mOnObjectAlpha, m_Events, "ObjectAlpha");
InitSignalPair(mOnObjectReport, m_Events, "ObjectReport");
InitSignalPair(mOnPickupClaimed, m_Events, "PickupClaimed");
InitSignalPair(mOnPickupCollected, m_Events, "PickupCollected");
InitSignalPair(mOnPickupRespawn, m_Events, "PickupRespawn");
InitSignalPair(mOnPickupWorld, m_Events, "PickupWorld");
InitSignalPair(mOnPickupAlpha, m_Events, "PickupAlpha");
InitSignalPair(mOnPickupAutomatic, m_Events, "PickupAutomatic");
InitSignalPair(mOnPickupAutoTimer, m_Events, "PickupAutoTimer");
InitSignalPair(mOnPickupOption, m_Events, "PickupOption");
InitSignalPair(mOnCheckpointEntered, m_Events, "CheckpointEntered");
InitSignalPair(mOnCheckpointExited, m_Events, "CheckpointExited");
InitSignalPair(mOnCheckpointWorld, m_Events, "CheckpointWorld");
InitSignalPair(mOnCheckpointRadius, m_Events, "CheckpointRadius");
InitSignalPair(mOnEntityPool, m_Events, "EntityPool");
InitSignalPair(mOnClientScriptData, m_Events, "ClientScriptData");
InitSignalPair(mOnPlayerUpdate, m_Events, "PlayerUpdate");
InitSignalPair(mOnVehicleUpdate, m_Events, "VehicleUpdate");
InitSignalPair(mOnPlayerHealth, m_Events, "PlayerHealth");
InitSignalPair(mOnPlayerArmour, m_Events, "PlayerArmour");
InitSignalPair(mOnPlayerWeapon, m_Events, "PlayerWeapon");
InitSignalPair(mOnPlayerHeading, m_Events, "PlayerHeading");
InitSignalPair(mOnPlayerPosition, m_Events, "PlayerPosition");
InitSignalPair(mOnPlayerOption, m_Events, "PlayerOption");
InitSignalPair(mOnPlayerAdmin, m_Events, "PlayerAdmin");
InitSignalPair(mOnPlayerWorld, m_Events, "PlayerWorld");
InitSignalPair(mOnPlayerTeam, m_Events, "PlayerTeam");
InitSignalPair(mOnPlayerSkin, m_Events, "PlayerSkin");
InitSignalPair(mOnPlayerMoney, m_Events, "PlayerMoney");
InitSignalPair(mOnPlayerScore, m_Events, "PlayerScore");
InitSignalPair(mOnPlayerWantedLevel, m_Events, "PlayerWantedLevel");
InitSignalPair(mOnPlayerImmunity, m_Events, "PlayerImmunity");
InitSignalPair(mOnPlayerAlpha, m_Events, "PlayerAlpha");
InitSignalPair(mOnPlayerEnterArea, m_Events, "PlayerEnterArea");
InitSignalPair(mOnPlayerLeaveArea, m_Events, "PlayerLeaveArea");
InitSignalPair(mOnVehicleColor, m_Events, "VehicleColor");
InitSignalPair(mOnVehicleHealth, m_Events, "VehicleHealth");
InitSignalPair(mOnVehiclePosition, m_Events, "VehiclePosition");
InitSignalPair(mOnVehicleRotation, m_Events, "VehicleRotation");
InitSignalPair(mOnVehicleOption, m_Events, "VehicleOption");
InitSignalPair(mOnVehicleWorld, m_Events, "VehicleWorld");
InitSignalPair(mOnVehicleImmunity, m_Events, "VehicleImmunity");
InitSignalPair(mOnVehiclePartStatus, m_Events, "VehiclePartStatus");
InitSignalPair(mOnVehicleTyreStatus, m_Events, "VehicleTyreStatus");
InitSignalPair(mOnVehicleDamageData, m_Events, "VehicleDamageData");
InitSignalPair(mOnVehicleRadio, m_Events, "VehicleRadio");
InitSignalPair(mOnVehicleHandlingRule, m_Events, "VehicleHandlingRule");
InitSignalPair(mOnVehicleEnterArea, m_Events, "VehicleEnterArea");
InitSignalPair(mOnVehicleLeaveArea, m_Events, "VehicleLeaveArea");
#if SQMOD_SDK_LEAST(2, 1)
InitSignalPair(mOnEntityStream, m_Events, "EntityStream");
#endif
InitSignalPair(mOnServerOption, m_Events, "ServerOption");
InitSignalPair(mOnScriptReload, m_Events, "ScriptReload");
InitSignalPair(mOnScriptLoaded, m_Events, "ScriptLoaded");
}
// ------------------------------------------------------------------------------------------------
void Core::DropEvents()
{
ResetSignalPair(mOnCustomEvent);
ResetSignalPair(mOnBlipCreated);
ResetSignalPair(mOnCheckpointCreated);
ResetSignalPair(mOnKeybindCreated);
ResetSignalPair(mOnObjectCreated);
ResetSignalPair(mOnPickupCreated);
ResetSignalPair(mOnPlayerCreated);
ResetSignalPair(mOnVehicleCreated);
ResetSignalPair(mOnBlipDestroyed);
ResetSignalPair(mOnCheckpointDestroyed);
ResetSignalPair(mOnKeybindDestroyed);
ResetSignalPair(mOnObjectDestroyed);
ResetSignalPair(mOnPickupDestroyed);
ResetSignalPair(mOnPlayerDestroyed);
ResetSignalPair(mOnVehicleDestroyed);
ResetSignalPair(mOnBlipCustom);
ResetSignalPair(mOnCheckpointCustom);
ResetSignalPair(mOnKeybindCustom);
ResetSignalPair(mOnObjectCustom);
ResetSignalPair(mOnPickupCustom);
ResetSignalPair(mOnPlayerCustom);
ResetSignalPair(mOnVehicleCustom);
#if SQMOD_SDK_LEAST(2, 1)
ResetSignalPair(mOnCheckpointStream);
ResetSignalPair(mOnObjectStream);
ResetSignalPair(mOnPickupStream);
ResetSignalPair(mOnPlayerStream);
ResetSignalPair(mOnVehicleStream);
#endif
ResetSignalPair(mOnServerStartup);
ResetSignalPair(mOnServerShutdown);
ResetSignalPair(mOnServerFrame);
ResetSignalPair(mOnIncomingConnection);
ResetSignalPair(mOnPlayerRequestClass);
ResetSignalPair(mOnPlayerRequestSpawn);
ResetSignalPair(mOnPlayerSpawn);
ResetSignalPair(mOnPlayerWasted);
ResetSignalPair(mOnPlayerKilled);
ResetSignalPair(mOnPlayerEmbarking);
ResetSignalPair(mOnPlayerEmbarked);
ResetSignalPair(mOnPlayerDisembark);
ResetSignalPair(mOnPlayerRename);
ResetSignalPair(mOnPlayerState);
ResetSignalPair(mOnStateNone);
ResetSignalPair(mOnStateNormal);
ResetSignalPair(mOnStateAim);
ResetSignalPair(mOnStateDriver);
ResetSignalPair(mOnStatePassenger);
ResetSignalPair(mOnStateEnterDriver);
ResetSignalPair(mOnStateEnterPassenger);
ResetSignalPair(mOnStateExit);
ResetSignalPair(mOnStateUnspawned);
ResetSignalPair(mOnPlayerAction);
ResetSignalPair(mOnActionNone);
ResetSignalPair(mOnActionNormal);
ResetSignalPair(mOnActionAiming);
ResetSignalPair(mOnActionShooting);
ResetSignalPair(mOnActionJumping);
ResetSignalPair(mOnActionLieDown);
ResetSignalPair(mOnActionGettingUp);
ResetSignalPair(mOnActionJumpVehicle);
ResetSignalPair(mOnActionDriving);
ResetSignalPair(mOnActionDying);
ResetSignalPair(mOnActionWasted);
ResetSignalPair(mOnActionEmbarking);
ResetSignalPair(mOnActionDisembarking);
ResetSignalPair(mOnPlayerBurning);
ResetSignalPair(mOnPlayerCrouching);
ResetSignalPair(mOnPlayerGameKeys);
ResetSignalPair(mOnPlayerStartTyping);
ResetSignalPair(mOnPlayerStopTyping);
ResetSignalPair(mOnPlayerAway);
ResetSignalPair(mOnPlayerMessage);
ResetSignalPair(mOnPlayerCommand);
ResetSignalPair(mOnPlayerPrivateMessage);
ResetSignalPair(mOnPlayerKeyPress);
ResetSignalPair(mOnPlayerKeyRelease);
ResetSignalPair(mOnPlayerSpectate);
ResetSignalPair(mOnPlayerUnspectate);
ResetSignalPair(mOnPlayerCrashreport);
ResetSignalPair(mOnPlayerModuleList);
ResetSignalPair(mOnVehicleExplode);
ResetSignalPair(mOnVehicleRespawn);
ResetSignalPair(mOnObjectShot);
ResetSignalPair(mOnObjectTouched);
ResetSignalPair(mOnObjectWorld);
ResetSignalPair(mOnObjectAlpha);
ResetSignalPair(mOnObjectReport);
ResetSignalPair(mOnPickupClaimed);
ResetSignalPair(mOnPickupCollected);
ResetSignalPair(mOnPickupRespawn);
ResetSignalPair(mOnPickupWorld);
ResetSignalPair(mOnPickupAlpha);
ResetSignalPair(mOnPickupAutomatic);
ResetSignalPair(mOnPickupAutoTimer);
ResetSignalPair(mOnPickupOption);
ResetSignalPair(mOnCheckpointEntered);
ResetSignalPair(mOnCheckpointExited);
ResetSignalPair(mOnCheckpointWorld);
ResetSignalPair(mOnCheckpointRadius);
ResetSignalPair(mOnEntityPool);
ResetSignalPair(mOnClientScriptData);
ResetSignalPair(mOnPlayerUpdate);
ResetSignalPair(mOnVehicleUpdate);
ResetSignalPair(mOnPlayerHealth);
ResetSignalPair(mOnPlayerArmour);
ResetSignalPair(mOnPlayerWeapon);
ResetSignalPair(mOnPlayerHeading);
ResetSignalPair(mOnPlayerPosition);
ResetSignalPair(mOnPlayerOption);
ResetSignalPair(mOnPlayerAdmin);
ResetSignalPair(mOnPlayerWorld);
ResetSignalPair(mOnPlayerTeam);
ResetSignalPair(mOnPlayerSkin);
ResetSignalPair(mOnPlayerMoney);
ResetSignalPair(mOnPlayerScore);
ResetSignalPair(mOnPlayerWantedLevel);
ResetSignalPair(mOnPlayerImmunity);
ResetSignalPair(mOnPlayerAlpha);
ResetSignalPair(mOnPlayerEnterArea);
ResetSignalPair(mOnPlayerLeaveArea);
ResetSignalPair(mOnVehicleColor);
ResetSignalPair(mOnVehicleHealth);
ResetSignalPair(mOnVehiclePosition);
ResetSignalPair(mOnVehicleRotation);
ResetSignalPair(mOnVehicleOption);
ResetSignalPair(mOnVehicleWorld);
ResetSignalPair(mOnVehicleImmunity);
ResetSignalPair(mOnVehiclePartStatus);
ResetSignalPair(mOnVehicleTyreStatus);
ResetSignalPair(mOnVehicleDamageData);
ResetSignalPair(mOnVehicleRadio);
ResetSignalPair(mOnVehicleHandlingRule);
ResetSignalPair(mOnVehicleEnterArea);
ResetSignalPair(mOnVehicleLeaveArea);
#if SQMOD_SDK_LEAST(2, 1)
ResetSignalPair(mOnEntityStream);
#endif
ResetSignalPair(mOnServerOption);
ResetSignalPair(mOnScriptReload);
ResetSignalPair(mOnScriptLoaded);
m_Events.Release();
}
} // Namespace:: SqMod
+55 -63
View File
@@ -1,16 +1,16 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Blip.hpp"
#include "Core.hpp"
#include "Misc/Tasks.hpp"
#include "Core/Tasks.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqBlip"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqBlip"))
// ------------------------------------------------------------------------------------------------
const Int32 CBlip::Max = SQMOD_BLIP_POOL;
const int32_t CBlip::Max = SQMOD_BLIP_POOL;
// ------------------------------------------------------------------------------------------------
SQInteger CBlip::SqGetNull(HSQUIRRELVM vm)
@@ -26,9 +26,9 @@ LightObj & CBlip::GetNull()
}
// ------------------------------------------------------------------------------------------------
CBlip::CBlip(Int32 id)
CBlip::CBlip(int32_t id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_BLIP_POOL))
, m_Tag(ToStrF("%d", id))
, m_Tag(fmt::format("{}", id))
{
/* ... */
}
@@ -84,7 +84,7 @@ void CBlip::SetData(LightObj & data)
}
// ------------------------------------------------------------------------------------------------
bool CBlip::Destroy(Int32 header, LightObj & payload)
bool CBlip::Destroy(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@@ -102,16 +102,16 @@ LightObj & CBlip::GetEvents() const
}
// ------------------------------------------------------------------------------------------------
void CBlip::CustomEvent(Int32 header, LightObj & payload) const
void CBlip::CustomEvent(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
// Perfrom the requested action
// Perform the requested action
Core::Get().EmitBlipCustom(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetWorld() const
int32_t CBlip::GetWorld() const
{
// Validate the managed identifier
Validate();
@@ -120,7 +120,7 @@ Int32 CBlip::GetWorld() const
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetScale() const
int32_t CBlip::GetScale() const
{
// Validate the managed identifier
Validate();
@@ -147,7 +147,7 @@ const Color4 & CBlip::GetColor() const
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetSprID() const
int32_t CBlip::GetSprID() const
{
// Validate the managed identifier
Validate();
@@ -156,7 +156,7 @@ Int32 CBlip::GetSprID() const
}
// ------------------------------------------------------------------------------------------------
Float32 CBlip::GetPositionX() const
float CBlip::GetPositionX() const
{
// Validate the managed identifier
Validate();
@@ -165,7 +165,7 @@ Float32 CBlip::GetPositionX() const
}
// ------------------------------------------------------------------------------------------------
Float32 CBlip::GetPositionY() const
float CBlip::GetPositionY() const
{
// Validate the managed identifier
Validate();
@@ -174,7 +174,7 @@ Float32 CBlip::GetPositionY() const
}
// ------------------------------------------------------------------------------------------------
Float32 CBlip::GetPositionZ() const
float CBlip::GetPositionZ() const
{
// Validate the managed identifier
Validate();
@@ -183,7 +183,7 @@ Float32 CBlip::GetPositionZ() const
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetColorR() const
int32_t CBlip::GetColorR() const
{
// Validate the managed identifier
Validate();
@@ -192,7 +192,7 @@ Int32 CBlip::GetColorR() const
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetColorG() const
int32_t CBlip::GetColorG() const
{
// Validate the managed identifier
Validate();
@@ -201,7 +201,7 @@ Int32 CBlip::GetColorG() const
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetColorB() const
int32_t CBlip::GetColorB() const
{
// Validate the managed identifier
Validate();
@@ -210,7 +210,7 @@ Int32 CBlip::GetColorB() const
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetColorA() const
int32_t CBlip::GetColorA() const
{
// Validate the managed identifier
Validate();
@@ -219,64 +219,64 @@ Int32 CBlip::GetColorA() const
}
// ------------------------------------------------------------------------------------------------
static LightObj & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid)
static LightObj & Blip_CreateEx1a(int32_t world, float x, float y, float z, int32_t scale,
uint8_t r, uint8_t g, uint8_t b, uint8_t a, int32_t spr_id)
{
return Core::Get().NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid, // NOLINT(hicpp-signed-bitwise)
return Core::Get().NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), spr_id, // NOLINT(hicpp-signed-bitwise)
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid,
Int32 header, LightObj & payload)
static LightObj & Blip_CreateEx1b(int32_t world, float x, float y, float z, int32_t scale,
uint8_t r, uint8_t g, uint8_t b, uint8_t a, int32_t spr_id,
int32_t header, LightObj & payload)
{
return Core::Get().NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid, // NOLINT(hicpp-signed-bitwise)
return Core::Get().NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), spr_id, // NOLINT(hicpp-signed-bitwise)
header, payload);
}
// ------------------------------------------------------------------------------------------------
static LightObj & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 scale, Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid)
static LightObj & Blip_CreateEx2a(int32_t index, int32_t world, float x, float y, float z,
int32_t scale, uint8_t r, uint8_t g, uint8_t b, uint8_t a, int32_t spr_id)
{
return Core::Get().NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid, // NOLINT(hicpp-signed-bitwise)
return Core::Get().NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), spr_id, // NOLINT(hicpp-signed-bitwise)
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid,
Int32 header, LightObj & payload)
static LightObj & Blip_CreateEx2b(int32_t index, int32_t world, float x, float y, float z, int32_t scale,
uint8_t r, uint8_t g, uint8_t b, uint8_t a, int32_t spr_id,
int32_t header, LightObj & payload)
{
return Core::Get().NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid, // NOLINT(hicpp-signed-bitwise)
return Core::Get().NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), spr_id, // NOLINT(hicpp-signed-bitwise)
header, payload);
}
// ------------------------------------------------------------------------------------------------
static LightObj & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
Int32 sprid)
static LightObj & Blip_Create1a(int32_t world, const Vector3 & pos, int32_t scale, const Color4 & color,
int32_t spr_id)
{
return Core::Get().NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
return Core::Get().NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), spr_id,
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
Int32 sprid, Int32 header, LightObj & payload)
static LightObj & Blip_Create1b(int32_t world, const Vector3 & pos, int32_t scale, const Color4 & color,
int32_t spr_id, int32_t header, LightObj & payload)
{
return Core::Get().NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
return Core::Get().NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), spr_id,
header, payload);
}
// ------------------------------------------------------------------------------------------------
static LightObj & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
const Color4 & color, Int32 sprid)
static LightObj & Blip_Create2a(int32_t index, int32_t world, const Vector3 & pos, int32_t scale,
const Color4 & color, int32_t spr_id)
{
return Core::Get().NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
return Core::Get().NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), spr_id,
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
const Color4 & color, Int32 sprid, Int32 header, LightObj & payload)
static LightObj & Blip_Create2b(int32_t index, int32_t world, const Vector3 & pos, int32_t scale,
const Color4 & color, int32_t spr_id, int32_t header, LightObj & payload)
{
return Core::Get().NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
return Core::Get().NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), spr_id,
header, payload);
}
@@ -300,9 +300,9 @@ void Register_CBlip(HSQUIRRELVM vm)
.FmtFunc(_SC("SetTag"), &CBlip::ApplyTag)
.Func(_SC("CustomEvent"), &CBlip::CustomEvent)
// Core Overloads
.Overload< bool (CBlip::*)(void) >(_SC("Destroy"), &CBlip::Destroy)
.Overload< bool (CBlip::*)(Int32) >(_SC("Destroy"), &CBlip::Destroy)
.Overload< bool (CBlip::*)(Int32, LightObj &) >(_SC("Destroy"), &CBlip::Destroy)
.Overload(_SC("Destroy"), &CBlip::Destroy0)
.Overload(_SC("Destroy"), &CBlip::Destroy1)
.Overload(_SC("Destroy"), &CBlip::Destroy)
// Properties
.Prop(_SC("World"), &CBlip::GetWorld)
.Prop(_SC("Scale"), &CBlip::GetScale)
@@ -319,22 +319,14 @@ void Register_CBlip(HSQUIRRELVM vm)
.Prop(_SC("Blue"), &CBlip::GetColorB)
.Prop(_SC("Alpha"), &CBlip::GetColorA)
// Static Overloads
.StaticOverload< LightObj & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< LightObj & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, LightObj &) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, LightObj &) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< LightObj & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("Create"), &Blip_Create)
.StaticOverload< LightObj & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, LightObj &) >
(_SC("Create"), &Blip_Create)
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("Create"), &Blip_Create)
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, LightObj &) >
(_SC("Create"), &Blip_Create)
.StaticOverload(_SC("CreateEx"), &Blip_CreateEx1a)
.StaticOverload(_SC("CreateEx"), &Blip_CreateEx1b)
.StaticOverload(_SC("CreateEx"), &Blip_CreateEx2a)
.StaticOverload(_SC("CreateEx"), &Blip_CreateEx2b)
.StaticOverload(_SC("Create"), &Blip_Create1a)
.StaticOverload(_SC("Create"), &Blip_Create1b)
.StaticOverload(_SC("Create"), &Blip_Create2a)
.StaticOverload(_SC("Create"), &Blip_Create2b)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CBlip::SqGetNull)
.SquirrelFunc(_SC("MakeTask"), &Tasks::MakeTask< CBlip, ENT_BLIP >)
+28 -27
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -13,13 +13,14 @@ class CBlip
{
// --------------------------------------------------------------------------------------------
friend class Core;
friend class BlipInst;
private:
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
int32_t m_ID;
/* --------------------------------------------------------------------------------------------
* User tag associated with this instance.
@@ -34,14 +35,14 @@ private:
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
explicit CBlip(Int32 id);
explicit CBlip(int32_t id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
static const int32_t Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
@@ -77,7 +78,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const;
SQMOD_NODISCARD const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
@@ -87,12 +88,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static LightObj & GetNull();
SQMOD_NODISCARD static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const
SQMOD_NODISCARD int32_t GetID() const
{
return m_ID;
}
@@ -100,7 +101,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const
SQMOD_NODISCARD bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
@@ -108,7 +109,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
const String & GetTag() const;
SQMOD_NODISCARD const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@@ -123,7 +124,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
LightObj & GetData();
SQMOD_NODISCARD LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
@@ -133,7 +134,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed blip entity.
*/
bool Destroy()
bool Destroy0() const // NOLINT(modernize-use-nodiscard)
{
return Destroy(0, NullLightObj());
}
@@ -141,7 +142,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed blip entity.
*/
bool Destroy(Int32 header)
bool Destroy1(int32_t header) const // NOLINT(modernize-use-nodiscard)
{
return Destroy(header, NullLightObj());
}
@@ -149,77 +150,77 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed blip entity.
*/
bool Destroy(Int32 header, LightObj & payload);
bool Destroy(int32_t header, LightObj & payload) const; // NOLINT(modernize-use-nodiscard)
/* --------------------------------------------------------------------------------------------
* Retrieve the events table of this entity.
*/
LightObj & GetEvents() const;
SQMOD_NODISCARD LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, LightObj & payload) const;
void CustomEvent(int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced blip entity exists.
*/
Int32 GetWorld() const;
SQMOD_NODISCARD int32_t GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the scale of the managed blip entity.
*/
Int32 GetScale() const;
SQMOD_NODISCARD int32_t GetScale() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed blip entity.
*/
const Vector3 & GetPosition() const;
SQMOD_NODISCARD const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the managed blip entity.
*/
const Color4 & GetColor() const;
SQMOD_NODISCARD const Color4 & GetColor() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the sprite used by the managed blip entity.
*/
Int32 GetSprID() const;
SQMOD_NODISCARD int32_t GetSprID() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed blip entity.
*/
Float32 GetPositionX() const;
SQMOD_NODISCARD float GetPositionX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed blip entity.
*/
Float32 GetPositionY() const;
SQMOD_NODISCARD float GetPositionY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed blip entity.
*/
Float32 GetPositionZ() const;
SQMOD_NODISCARD float GetPositionZ() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the red color of the managed blip entity.
*/
Int32 GetColorR() const;
SQMOD_NODISCARD int32_t GetColorR() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the green color of the managed blip entity.
*/
Int32 GetColorG() const;
SQMOD_NODISCARD int32_t GetColorG() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the blue color of the managed blip entity.
*/
Int32 GetColorB() const;
SQMOD_NODISCARD int32_t GetColorB() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha transparency of the managed blip entity.
*/
Int32 GetColorA() const;
SQMOD_NODISCARD int32_t GetColorA() const;
};
} // Namespace:: SqMod
+64 -70
View File
@@ -4,16 +4,16 @@
#include "Base/Color4.hpp"
#include "Base/Vector3.hpp"
#include "Core.hpp"
#include "Misc/Tasks.hpp"
#include "Core/Tasks.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqCheckpoint"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqCheckpoint"))
// ------------------------------------------------------------------------------------------------
const Int32 CCheckpoint::Max = SQMOD_CHECKPOINT_POOL;
const int32_t CCheckpoint::Max = SQMOD_CHECKPOINT_POOL;
// ------------------------------------------------------------------------------------------------
SQInteger CCheckpoint::SqGetNull(HSQUIRRELVM vm)
@@ -29,9 +29,9 @@ LightObj & CCheckpoint::GetNull()
}
// ------------------------------------------------------------------------------------------------
CCheckpoint::CCheckpoint(Int32 id)
CCheckpoint::CCheckpoint(int32_t id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_CHECKPOINT_POOL))
, m_Tag(ToStrF("%d", id)), m_Data(), m_CircularLocks(0)
, m_Tag(fmt::format("{}", id)), m_Data(), m_CircularLocks(0)
{
/* ... */
}
@@ -87,7 +87,7 @@ void CCheckpoint::SetData(LightObj & data)
}
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::Destroy(Int32 header, LightObj & payload)
bool CCheckpoint::Destroy(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@@ -105,7 +105,7 @@ LightObj & CCheckpoint::GetEvents() const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::CustomEvent(Int32 header, LightObj & payload) const
void CCheckpoint::CustomEvent(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@@ -137,7 +137,7 @@ bool CCheckpoint::IsSphere() const
}
// ------------------------------------------------------------------------------------------------
Int32 CCheckpoint::GetWorld() const
int32_t CCheckpoint::GetWorld() const
{
// Validate the managed identifier
Validate();
@@ -146,12 +146,12 @@ Int32 CCheckpoint::GetWorld() const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetWorld(Int32 world)
void CCheckpoint::SetWorld(int32_t world)
{
// Validate the managed identifier
Validate();
// Grab the current value for this property
const Int32 current = _Func->GetCheckPointWorld(m_ID);
const int32_t current = _Func->GetCheckPointWorld(m_ID);
// Don't even bother if it's the same value
if (current == world)
{
@@ -175,7 +175,7 @@ Color4 CCheckpoint::GetColor() const
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the color information
Int32 r, g, b, a;
int32_t r, g, b, a;
// Query the server for the color values
_Func->GetCheckPointColour(m_ID, &r, &g, &b, &a);
// Return the requested information
@@ -193,7 +193,7 @@ void CCheckpoint::SetColor(const Color4 & col) const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColorEx(Uint8 r, Uint8 g, Uint8 b) const
void CCheckpoint::SetColorEx3(uint8_t r, uint8_t g, uint8_t b) const
{
// Validate the managed identifier
Validate();
@@ -202,7 +202,7 @@ void CCheckpoint::SetColorEx(Uint8 r, Uint8 g, Uint8 b) const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColorEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
void CCheckpoint::SetColorEx4(uint8_t r, uint8_t g, uint8_t b, uint8_t a) const
{
// Validate the managed identifier
Validate();
@@ -233,7 +233,7 @@ void CCheckpoint::SetPosition(const Vector3 & pos) const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPositionEx(Float32 x, Float32 y, Float32 z) const
void CCheckpoint::SetPositionEx(float x, float y, float z) const
{
// Validate the managed identifier
Validate();
@@ -242,7 +242,7 @@ void CCheckpoint::SetPositionEx(Float32 x, Float32 y, Float32 z) const
}
// ------------------------------------------------------------------------------------------------
Float32 CCheckpoint::GetRadius() const
float CCheckpoint::GetRadius() const
{
// Validate the managed identifier
Validate();
@@ -251,12 +251,12 @@ Float32 CCheckpoint::GetRadius() const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetRadius(Float32 radius)
void CCheckpoint::SetRadius(float radius)
{
// Validate the managed identifier
Validate();
// Grab the current value for this property
const Float32 current = _Func->GetCheckPointRadius(m_ID);
const float current = _Func->GetCheckPointRadius(m_ID);
// Avoid property unwind from a recursive call
_Func->SetCheckPointRadius(m_ID, radius);
// Avoid infinite recursive event loops
@@ -279,7 +279,7 @@ LightObj & CCheckpoint::GetOwner() const
}
// ------------------------------------------------------------------------------------------------
Int32 CCheckpoint::GetOwnerID() const
int32_t CCheckpoint::GetOwnerID() const
{
// Validate the managed identifier
Validate();
@@ -288,12 +288,12 @@ Int32 CCheckpoint::GetOwnerID() const
}
// ------------------------------------------------------------------------------------------------
Float32 CCheckpoint::GetPositionX() const
float CCheckpoint::GetPositionX() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
Float32 x = 0.0f, dummy;
float x = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetCheckPointPosition(m_ID, &x, &dummy, &dummy);
// Return the requested information
@@ -301,12 +301,12 @@ Float32 CCheckpoint::GetPositionX() const
}
// ------------------------------------------------------------------------------------------------
Float32 CCheckpoint::GetPositionY() const
float CCheckpoint::GetPositionY() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
Float32 y = 0.0f, dummy;
float y = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetCheckPointPosition(m_ID, &dummy, &y, &dummy);
// Return the requested information
@@ -314,12 +314,12 @@ Float32 CCheckpoint::GetPositionY() const
}
// ------------------------------------------------------------------------------------------------
Float32 CCheckpoint::GetPositionZ() const
float CCheckpoint::GetPositionZ() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
Float32 z = 0.0f, dummy;
float z = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetCheckPointPosition(m_ID, &dummy, &dummy, &z);
// Return the requested information
@@ -327,12 +327,12 @@ Float32 CCheckpoint::GetPositionZ() const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPositionX(Float32 x) const
void CCheckpoint::SetPositionX(float x) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 y, z, dummy;
float y, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetCheckPointPosition(m_ID, &dummy, &y, &z);
// Perform the requested operation
@@ -340,12 +340,12 @@ void CCheckpoint::SetPositionX(Float32 x) const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPositionY(Float32 y) const
void CCheckpoint::SetPositionY(float y) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, z, dummy;
float x, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetCheckPointPosition(m_ID, &x, &dummy, &z);
// Perform the requested operation
@@ -353,12 +353,12 @@ void CCheckpoint::SetPositionY(Float32 y) const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPositionZ(Float32 z) const
void CCheckpoint::SetPositionZ(float z) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, y, dummy;
float x, y, dummy;
// Retrieve the current values for unchanged components
_Func->GetCheckPointPosition(m_ID, &x, &y, &dummy);
// Perform the requested operation
@@ -366,12 +366,12 @@ void CCheckpoint::SetPositionZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
Int32 CCheckpoint::GetColorR() const
int32_t CCheckpoint::GetColorR() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
Int32 r = 0, dummy;
int32_t r = 0, dummy;
// Query the server for the requested component value
_Func->GetCheckPointColour(m_ID, &r, &dummy, &dummy, &dummy);
// Return the requested information
@@ -379,12 +379,12 @@ Int32 CCheckpoint::GetColorR() const
}
// ------------------------------------------------------------------------------------------------
Int32 CCheckpoint::GetColorG() const
int32_t CCheckpoint::GetColorG() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
Int32 g = 0, dummy;
int32_t g = 0, dummy;
// Query the server for the requested component value
_Func->GetCheckPointColour(m_ID, &dummy, &g, &dummy, &dummy);
// Return the requested information
@@ -392,12 +392,12 @@ Int32 CCheckpoint::GetColorG() const
}
// ------------------------------------------------------------------------------------------------
Int32 CCheckpoint::GetColorB() const
int32_t CCheckpoint::GetColorB() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
Int32 b = 0, dummy;
int32_t b = 0, dummy;
// Query the server for the requested component value
_Func->GetCheckPointColour(m_ID, &dummy, &dummy, &b, &dummy);
// Return the requested information
@@ -405,12 +405,12 @@ Int32 CCheckpoint::GetColorB() const
}
// ------------------------------------------------------------------------------------------------
Int32 CCheckpoint::GetColorA() const
int32_t CCheckpoint::GetColorA() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
Int32 a = 0, dummy;
int32_t a = 0, dummy;
// Query the server for the requested component value
_Func->GetCheckPointColour(m_ID, &dummy, &dummy, &dummy, &a);
// Return the requested information
@@ -418,12 +418,12 @@ Int32 CCheckpoint::GetColorA() const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColorR(Int32 r) const
void CCheckpoint::SetColorR(int32_t r) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary integers to retrieve the missing components
Int32 g, b, a, dummy;
int32_t g, b, a, dummy;
// Retrieve the current values for unchanged components
_Func->GetCheckPointColour(m_ID, &dummy, &g, &b, &a);
// Perform the requested operation
@@ -431,12 +431,12 @@ void CCheckpoint::SetColorR(Int32 r) const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColorG(Int32 g) const
void CCheckpoint::SetColorG(int32_t g) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary integers to retrieve the missing components
Int32 r, b, a, dummy;
int32_t r, b, a, dummy;
// Retrieve the current values for unchanged components
_Func->GetCheckPointColour(m_ID, &r, &dummy, &b, &a);
// Perform the requested operation
@@ -444,12 +444,12 @@ void CCheckpoint::SetColorG(Int32 g) const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColorB(Int32 b) const
void CCheckpoint::SetColorB(int32_t b) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary integers to retrieve the missing components
Int32 r, g, a, dummy;
int32_t r, g, a, dummy;
// Retrieve the current values for unchanged components
_Func->GetCheckPointColour(m_ID, &r, &g, &dummy, &a);
// Perform the requested operation
@@ -457,12 +457,12 @@ void CCheckpoint::SetColorB(Int32 b) const
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColorA(Int32 a) const
void CCheckpoint::SetColorA(int32_t a) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary integers to retrieve the missing components
Int32 r, g, b, dummy;
int32_t r, g, b, dummy;
// Retrieve the current values for unchanged components
_Func->GetCheckPointColour(m_ID, &r, &g, &b, &dummy);
// Perform the requested operation
@@ -470,32 +470,32 @@ void CCheckpoint::SetColorA(Int32 a) const
}
// ------------------------------------------------------------------------------------------------
static LightObj & Checkpoint_CreateEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius)
static LightObj & Checkpoint_CreateEx1a(int32_t world, bool sphere, float x, float y, float z,
uint8_t r, uint8_t g, uint8_t b, uint8_t a, float radius)
{
return Core::Get().NewCheckpoint(-1, world, sphere, x, y, z, r, g, b, a, radius,
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Checkpoint_CreateEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, LightObj & payload)
static LightObj & Checkpoint_CreateEx1b(int32_t world, bool sphere, float x, float y, float z,
uint8_t r, uint8_t g, uint8_t b, uint8_t a, float radius,
int32_t header, LightObj & payload)
{
return Core::Get().NewCheckpoint(-1, world, sphere, x, y, z, r, g, b, a,
radius, header, payload);
}
// ------------------------------------------------------------------------------------------------
static LightObj & Checkpoint_Create(Int32 world, bool sphere, const Vector3 & pos,
const Color4 & color, Float32 radius)
static LightObj & Checkpoint_Create1a(int32_t world, bool sphere, const Vector3 & pos,
const Color4 & color, float radius)
{
return Core::Get().NewCheckpoint(-1, world, sphere, pos.x, pos.y, pos.z,
color.r, color.g, color.b, color.a, radius,
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Checkpoint_Create(Int32 world, bool sphere, const Vector3 & pos,
const Color4 & color, Float32 radius, Int32 header, LightObj & payload)
static LightObj & Checkpoint_Create1b(int32_t world, bool sphere, const Vector3 & pos,
const Color4 & color, float radius, int32_t header, LightObj & payload)
{
return Core::Get().NewCheckpoint(-1, world, sphere, pos.x, pos.y, pos.z,
color.r, color.g, color.b, color.a, radius, header, payload);
@@ -521,9 +521,9 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
.FmtFunc(_SC("SetTag"), &CCheckpoint::ApplyTag)
.Func(_SC("CustomEvent"), &CCheckpoint::CustomEvent)
// Core Overloads
.Overload< bool (CCheckpoint::*)(void) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload< bool (CCheckpoint::*)(Int32) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload< bool (CCheckpoint::*)(Int32, LightObj &) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload(_SC("Destroy"), &CCheckpoint::Destroy0)
.Overload(_SC("Destroy"), &CCheckpoint::Destroy1)
.Overload(_SC("Destroy"), &CCheckpoint::Destroy)
// Properties
.Prop(_SC("Sphere"), &CCheckpoint::IsSphere)
.Prop(_SC("World"), &CCheckpoint::GetWorld, &CCheckpoint::SetWorld)
@@ -546,19 +546,13 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
.Func(_SC("SetPos"), &CCheckpoint::SetPositionEx)
.Func(_SC("SetPosition"), &CCheckpoint::SetPositionEx)
// Member Overloads
.Overload< void (CCheckpoint::*)(Uint8, Uint8, Uint8) const >
(_SC("SetColor"), &CCheckpoint::SetColorEx)
.Overload< void (CCheckpoint::*)(Uint8, Uint8, Uint8, Uint8) const >
(_SC("SetColor"), &CCheckpoint::SetColorEx)
.Overload(_SC("SetColor"), &CCheckpoint::SetColorEx3)
.Overload(_SC("SetColor"), &CCheckpoint::SetColorEx4)
// Static Overloads
.StaticOverload< LightObj & (*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateEx"), &Checkpoint_CreateEx)
.StaticOverload< LightObj & (*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, LightObj &) >
(_SC("CreateEx"), &Checkpoint_CreateEx)
.StaticOverload< LightObj & (*)(Int32, bool, const Vector3 &, const Color4 &, Float32) >
(_SC("Create"), &Checkpoint_Create)
.StaticOverload< LightObj & (*)(Int32, bool, const Vector3 &, const Color4 &, Float32, Int32, LightObj &) >
(_SC("Create"), &Checkpoint_Create)
.StaticOverload(_SC("CreateEx"), &Checkpoint_CreateEx1a)
.StaticOverload(_SC("CreateEx"), &Checkpoint_CreateEx1b)
.StaticOverload(_SC("Create"), &Checkpoint_Create1a)
.StaticOverload(_SC("Create"), &Checkpoint_Create1b)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CCheckpoint::SqGetNull)
.SquirrelFunc(_SC("MakeTask"), &Tasks::MakeTask< CCheckpoint, ENT_CHECKPOINT >)
+44 -43
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -22,13 +22,14 @@ class CCheckpoint
{
// --------------------------------------------------------------------------------------------
friend class Core;
friend class CheckpointInst;
private:
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
int32_t m_ID;
/* --------------------------------------------------------------------------------------------
* User tag associated with this instance.
@@ -43,19 +44,19 @@ private:
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
*/
Uint32 m_CircularLocks;
uint32_t m_CircularLocks;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
explicit CCheckpoint(Int32 id);
explicit CCheckpoint(int32_t id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
static const int32_t Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
@@ -91,7 +92,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const;
SQMOD_NODISCARD const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
@@ -101,12 +102,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static LightObj & GetNull();
SQMOD_NODISCARD static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const
SQMOD_NODISCARD int32_t GetID() const
{
return m_ID;
}
@@ -114,7 +115,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const
SQMOD_NODISCARD bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
@@ -122,7 +123,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
const String & GetTag() const;
SQMOD_NODISCARD const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@@ -137,7 +138,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
LightObj & GetData();
SQMOD_NODISCARD LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
@@ -147,7 +148,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed checkpoint entity.
*/
bool Destroy()
bool Destroy0() const // NOLINT(modernize-use-nodiscard)
{
return Destroy(0, NullLightObj());
}
@@ -155,7 +156,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed checkpoint entity.
*/
bool Destroy(Int32 header)
bool Destroy1(int32_t header) const // NOLINT(modernize-use-nodiscard)
{
return Destroy(header, NullLightObj());
}
@@ -163,42 +164,42 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed checkpoint entity.
*/
bool Destroy(Int32 header, LightObj & payload);
bool Destroy(int32_t header, LightObj & payload) const; // NOLINT(modernize-use-nodiscard)
/* --------------------------------------------------------------------------------------------
* Retrieve the events table of this entity.
*/
LightObj & GetEvents() const;
SQMOD_NODISCARD LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, LightObj & payload) const;
void CustomEvent(int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See if the managed checkpoint entity is streamed for the specified player.
*/
bool IsStreamedFor(CPlayer & player) const;
SQMOD_NODISCARD bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* See if the managed checkpoint entity of sphere type.
*/
bool IsSphere() const;
SQMOD_NODISCARD bool IsSphere() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed checkpoint entity exists.
*/
Int32 GetWorld() const;
SQMOD_NODISCARD int32_t GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed checkpoint entity exists.
*/
void SetWorld(Int32 world);
void SetWorld(int32_t world);
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the managed checkpoint entity.
*/
Color4 GetColor() const;
SQMOD_NODISCARD Color4 GetColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed checkpoint entity.
@@ -208,17 +209,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed checkpoint entity.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
void SetColorEx3(uint8_t r, uint8_t g, uint8_t b) const;
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed checkpoint entity.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
void SetColorEx4(uint8_t r, uint8_t g, uint8_t b, uint8_t a) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed checkpoint entity.
*/
Vector3 GetPosition() const;
SQMOD_NODISCARD Vector3 GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed checkpoint entity.
@@ -228,97 +229,97 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed checkpoint entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
void SetPositionEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radius of the managed checkpoint entity.
*/
Float32 GetRadius() const;
SQMOD_NODISCARD float GetRadius() const;
/* --------------------------------------------------------------------------------------------
* Modify the radius of the managed checkpoint entity.
*/
void SetRadius(Float32 radius);
void SetRadius(float radius);
/* --------------------------------------------------------------------------------------------
* Retrieve the owner of the managed checkpoint entity.
*/
LightObj & GetOwner() const;
SQMOD_NODISCARD LightObj & GetOwner() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner identifier of the managed checkpoint entity.
*/
Int32 GetOwnerID() const;
SQMOD_NODISCARD int32_t GetOwnerID() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed checkpoint entity.
*/
Float32 GetPositionX() const;
SQMOD_NODISCARD float GetPositionX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed checkpoint entity.
*/
Float32 GetPositionY() const;
SQMOD_NODISCARD float GetPositionY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed checkpoint entity.
*/
Float32 GetPositionZ() const;
SQMOD_NODISCARD float GetPositionZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed checkpoint entity.
*/
void SetPositionX(Float32 x) const;
void SetPositionX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed checkpoint entity.
*/
void SetPositionY(Float32 y) const;
void SetPositionY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed checkpoint entity.
*/
void SetPositionZ(Float32 z) const;
void SetPositionZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the red color of the managed checkpoint entity.
*/
Int32 GetColorR() const;
SQMOD_NODISCARD int32_t GetColorR() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the green color of the managed checkpoint entity.
*/
Int32 GetColorG() const;
SQMOD_NODISCARD int32_t GetColorG() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the blue color of the managed checkpoint entity.
*/
Int32 GetColorB() const;
SQMOD_NODISCARD int32_t GetColorB() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha transparency of the managed checkpoint entity.
*/
Int32 GetColorA() const;
SQMOD_NODISCARD int32_t GetColorA() const;
/* --------------------------------------------------------------------------------------------
* Modify the red color of the managed checkpoint entity.
*/
void SetColorR(Int32 r) const;
void SetColorR(int32_t r) const;
/* --------------------------------------------------------------------------------------------
* Modify the green color of the managed checkpoint entity.
*/
void SetColorG(Int32 g) const;
void SetColorG(int32_t g) const;
/* --------------------------------------------------------------------------------------------
* Modify the blue color of the managed checkpoint entity.
*/
void SetColorB(Int32 b) const;
void SetColorB(int32_t b) const;
/* --------------------------------------------------------------------------------------------
* Modify the alpha transparency of the managed checkpoint entity.
*/
void SetColorA(Int32 a) const;
void SetColorA(int32_t a) const;
};
} // Namespace:: SqMod
@@ -1,52 +1,52 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Keybind.hpp"
#include "Entity/KeyBind.hpp"
#include "Core.hpp"
#include "Misc/Tasks.hpp"
#include "Core/Tasks.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqKeybind"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqKeyBind"))
// ------------------------------------------------------------------------------------------------
const Int32 CKeybind::Max = SQMOD_KEYBIND_POOL;
const int32_t CKeyBind::Max = SQMOD_KEYBIND_POOL;
// ------------------------------------------------------------------------------------------------
SQInteger CKeybind::SqGetNull(HSQUIRRELVM vm)
SQInteger CKeyBind::SqGetNull(HSQUIRRELVM vm)
{
sq_pushobject(vm, Core::Get().GetNullKeybind().GetObj());
sq_pushobject(vm, Core::Get().GetNullKeyBind().GetObj());
return 1;
}
// ------------------------------------------------------------------------------------------------
LightObj & CKeybind::GetNull()
LightObj & CKeyBind::GetNull()
{
return Core::Get().GetNullKeybind();
return Core::Get().GetNullKeyBind();
}
// ------------------------------------------------------------------------------------------------
CKeybind::CKeybind(Int32 id)
CKeyBind::CKeyBind(int32_t id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_KEYBIND_POOL))
, m_Tag(ToStrF("%d", id))
, m_Tag(fmt::format("{}", id))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
const String & CKeybind::ToString() const
const String & CKeyBind::ToString() const
{
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
const String & CKeybind::GetTag() const
const String & CKeyBind::GetTag() const
{
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CKeybind::SetTag(StackStrF & tag)
void CKeyBind::SetTag(StackStrF & tag)
{
if (tag.mLen > 0)
{
@@ -59,14 +59,14 @@ void CKeybind::SetTag(StackStrF & tag)
}
// ------------------------------------------------------------------------------------------------
CKeybind & CKeybind::ApplyTag(StackStrF & tag)
CKeyBind & CKeyBind::ApplyTag(StackStrF & tag)
{
SetTag(tag);
return *this;
}
// ------------------------------------------------------------------------------------------------
LightObj & CKeybind::GetData()
LightObj & CKeyBind::GetData()
{
// Validate the managed identifier
Validate();
@@ -75,7 +75,7 @@ LightObj & CKeybind::GetData()
}
// ------------------------------------------------------------------------------------------------
void CKeybind::SetData(LightObj & data)
void CKeyBind::SetData(LightObj & data)
{
// Validate the managed identifier
Validate();
@@ -84,146 +84,142 @@ void CKeybind::SetData(LightObj & data)
}
// ------------------------------------------------------------------------------------------------
bool CKeybind::Destroy(Int32 header, LightObj & payload)
bool CKeyBind::Destroy(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return Core::Get().DelKeybind(m_ID, header, payload);
return Core::Get().DelKeyBind(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
LightObj & CKeybind::GetEvents() const
LightObj & CKeyBind::GetEvents() const
{
// Validate the managed identifier
Validate();
// Return the associated event table
return Core::Get().GetKeybind(m_ID).mEvents;
return Core::Get().GetKeyBind(m_ID).mEvents;
}
// ------------------------------------------------------------------------------------------------
void CKeybind::CustomEvent(Int32 header, LightObj & payload) const
void CKeyBind::CustomEvent(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
// Perfrom the requested action
Core::Get().EmitKeybindCustom(m_ID, header, payload);
// Perform the requested action
Core::Get().EmitKeyBindCustom(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
Int32 CKeybind::GetFirst() const
int32_t CKeyBind::GetFirst() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return Core::Get().GetKeybind(m_ID).mFirst;
return Core::Get().GetKeyBind(m_ID).mFirst;
}
// ------------------------------------------------------------------------------------------------
Int32 CKeybind::GetSecond() const
int32_t CKeyBind::GetSecond() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return Core::Get().GetKeybind(m_ID).mSecond;
return Core::Get().GetKeyBind(m_ID).mSecond;
}
// ------------------------------------------------------------------------------------------------
Int32 CKeybind::GetThird() const
int32_t CKeyBind::GetThird() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return Core::Get().GetKeybind(m_ID).mThird;
return Core::Get().GetKeyBind(m_ID).mThird;
}
// ------------------------------------------------------------------------------------------------
bool CKeybind::IsRelease() const
bool CKeyBind::IsRelease() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return static_cast< bool >(Core::Get().GetKeybind(m_ID).mRelease);
return static_cast< bool >(Core::Get().GetKeyBind(m_ID).mRelease);
}
// ------------------------------------------------------------------------------------------------
static LightObj & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
Int32 alternative)
static LightObj & KeyBind_CreateEx1a(int32_t slot, bool release, int32_t primary, int32_t secondary,
int32_t alternative)
{
return Core::Get().NewKeybind(slot, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullLightObj());
return Core::Get().NewKeyBind(slot, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
Int32 alternative, Int32 header, LightObj & payload)
static LightObj & KeyBind_CreateEx1b(int32_t slot, bool release, int32_t primary, int32_t secondary,
int32_t alternative, int32_t header, LightObj & payload)
{
return Core::Get().NewKeybind(slot, release, primary, secondary, alternative, header, payload);
return Core::Get().NewKeyBind(slot, release, primary, secondary, alternative, header, payload);
}
// ------------------------------------------------------------------------------------------------
static LightObj & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative)
static LightObj & KeyBind_Create1a(bool release, int32_t primary, int32_t secondary, int32_t alternative)
{
return Core::Get().NewKeybind(-1, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullLightObj());
return Core::Get().NewKeyBind(-1, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative,
Int32 header, LightObj & payload)
static LightObj & KeyBind_Create1b(bool release, int32_t primary, int32_t secondary, int32_t alternative,
int32_t header, LightObj & payload)
{
return Core::Get().NewKeybind(-1, release, primary, secondary, alternative, header, payload);
return Core::Get().NewKeyBind(-1, release, primary, secondary, alternative, header, payload);
}
// ------------------------------------------------------------------------------------------------
static SQInteger Keybind_UnusedSlot()
static SQInteger KeyBind_UnusedSlot()
{
return _Func->GetKeyBindUnusedSlot();
}
// ================================================================================================
void Register_CKeybind(HSQUIRRELVM vm)
void Register_CKeyBind(HSQUIRRELVM vm)
{
RootTable(vm).Bind(Typename::Str,
Class< CKeybind, NoConstructor< CKeybind > >(vm, Typename::Str)
Class< CKeyBind, NoConstructor< CKeyBind > >(vm, Typename::Str)
// Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &CKeybind::ToString)
.Func(_SC("_tostring"), &CKeyBind::ToString)
// Static Values
.SetStaticValue(_SC("MaxID"), CKeybind::Max)
.SetStaticValue(_SC("MaxID"), CKeyBind::Max)
// Core Properties
.Prop(_SC("On"), &CKeybind::GetEvents)
.Prop(_SC("ID"), &CKeybind::GetID)
.Prop(_SC("Tag"), &CKeybind::GetTag, &CKeybind::SetTag)
.Prop(_SC("Data"), &CKeybind::GetData, &CKeybind::SetData)
.Prop(_SC("Active"), &CKeybind::IsActive)
.Prop(_SC("On"), &CKeyBind::GetEvents)
.Prop(_SC("ID"), &CKeyBind::GetID)
.Prop(_SC("Tag"), &CKeyBind::GetTag, &CKeyBind::SetTag)
.Prop(_SC("Data"), &CKeyBind::GetData, &CKeyBind::SetData)
.Prop(_SC("Active"), &CKeyBind::IsActive)
// Core Methods
.FmtFunc(_SC("SetTag"), &CKeybind::ApplyTag)
.Func(_SC("CustomEvent"), &CKeybind::CustomEvent)
.FmtFunc(_SC("SetTag"), &CKeyBind::ApplyTag)
.Func(_SC("CustomEvent"), &CKeyBind::CustomEvent)
// Core Overloads
.Overload< bool (CKeybind::*)(void) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload< bool (CKeybind::*)(Int32) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload< bool (CKeybind::*)(Int32, LightObj &) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload(_SC("Destroy"), &CKeyBind::Destroy0)
.Overload(_SC("Destroy"), &CKeyBind::Destroy1)
.Overload(_SC("Destroy"), &CKeyBind::Destroy)
// Properties
.Prop(_SC("First"), &CKeybind::GetFirst)
.Prop(_SC("Second"), &CKeybind::GetSecond)
.Prop(_SC("Third"), &CKeybind::GetThird)
.Prop(_SC("Release"), &CKeybind::IsRelease)
.Prop(_SC("First"), &CKeyBind::GetFirst)
.Prop(_SC("Second"), &CKeyBind::GetSecond)
.Prop(_SC("Third"), &CKeyBind::GetThird)
.Prop(_SC("Release"), &CKeyBind::IsRelease)
// Static Functions
.StaticFunc(_SC("UnusedSlot"), &Keybind_UnusedSlot)
.StaticFunc(_SC("UnusedSlot"), &KeyBind_UnusedSlot)
// Static Overloads
.StaticOverload< LightObj & (*)(Int32, bool, Int32, Int32, Int32) >
(_SC("CreateEx"), &Keybind_CreateEx)
.StaticOverload< LightObj & (*)(Int32, bool, Int32, Int32, Int32, Int32, LightObj &) >
(_SC("CreateEx"), &Keybind_CreateEx)
.StaticOverload< LightObj & (*)(bool, Int32, Int32, Int32) >
(_SC("Create"), &Keybind_Create)
.StaticOverload< LightObj & (*)(bool, Int32, Int32, Int32, Int32, LightObj &) >
(_SC("Create"), &Keybind_Create)
.StaticOverload(_SC("CreateEx"), &KeyBind_CreateEx1a)
.StaticOverload(_SC("CreateEx"), &KeyBind_CreateEx1b)
.StaticOverload(_SC("Create"), &KeyBind_Create1a)
.StaticOverload(_SC("Create"), &KeyBind_Create1b)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CKeybind::SqGetNull)
.SquirrelFunc(_SC("MakeTask"), &Tasks::MakeTask< CKeybind, ENT_KEYBIND >)
.SquirrelFunc(_SC("DropTask"), &Tasks::DropTask< CKeybind, ENT_KEYBIND >)
.SquirrelFunc(_SC("DoesTask"), &Tasks::DoesTask< CKeybind, ENT_KEYBIND >)
.SquirrelFunc(_SC("FindTask"), &Tasks::FindTask< CKeybind, ENT_KEYBIND >)
.SquirrelFunc(_SC("NullInst"), &CKeyBind::SqGetNull)
.SquirrelFunc(_SC("MakeTask"), &Tasks::MakeTask< CKeyBind, ENT_KEYBIND >)
.SquirrelFunc(_SC("DropTask"), &Tasks::DropTask< CKeyBind, ENT_KEYBIND >)
.SquirrelFunc(_SC("DoesTask"), &Tasks::DoesTask< CKeyBind, ENT_KEYBIND >)
.SquirrelFunc(_SC("FindTask"), &Tasks::FindTask< CKeyBind, ENT_KEYBIND >)
);
}
@@ -1,25 +1,26 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages a single keybind entity.
* Manages a single key-bind entity.
*/
class CKeybind
class CKeyBind
{
// --------------------------------------------------------------------------------------------
friend class Core;
friend class KeyBindInst;
private:
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
int32_t m_ID;
/* --------------------------------------------------------------------------------------------
* User tag associated with this instance.
@@ -34,34 +35,34 @@ private:
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
explicit CKeybind(Int32 id);
explicit CKeyBind(int32_t id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
static const int32_t Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CKeybind(const CKeybind &) = delete;
CKeyBind(const CKeyBind &) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor. (disabled)
*/
CKeybind(CKeybind &&) = delete;
CKeyBind(CKeyBind &&) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CKeybind & operator = (const CKeybind &) = delete;
CKeyBind & operator = (const CKeyBind &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CKeybind & operator = (CKeybind &&) = delete;
CKeyBind & operator = (CKeyBind &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity instance otherwise throw an exception.
@@ -77,7 +78,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const;
SQMOD_NODISCARD const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
@@ -87,12 +88,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static LightObj & GetNull();
SQMOD_NODISCARD static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const
SQMOD_NODISCARD int32_t GetID() const
{
return m_ID;
}
@@ -100,7 +101,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const
SQMOD_NODISCARD bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
@@ -108,7 +109,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
const String & GetTag() const;
SQMOD_NODISCARD const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@@ -118,12 +119,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
*/
CKeybind & ApplyTag(StackStrF & tag);
CKeyBind & ApplyTag(StackStrF & tag);
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
LightObj & GetData();
SQMOD_NODISCARD LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
@@ -133,7 +134,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed destroy entity.
*/
bool Destroy()
bool Destroy0() const // NOLINT(modernize-use-nodiscard)
{
return Destroy(0, NullLightObj());
}
@@ -141,7 +142,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed destroy entity.
*/
bool Destroy(Int32 header)
bool Destroy1(int32_t header) const // NOLINT(modernize-use-nodiscard)
{
return Destroy(header, NullLightObj());
}
@@ -149,37 +150,37 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed destroy entity.
*/
bool Destroy(Int32 header, LightObj & payload);
bool Destroy(int32_t header, LightObj & payload) const; // NOLINT(modernize-use-nodiscard)
/* --------------------------------------------------------------------------------------------
* Retrieve the events table of this entity.
*/
LightObj & GetEvents() const;
SQMOD_NODISCARD LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, LightObj & payload) const;
void CustomEvent(int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the first key code of the managed keybind entity.
* Retrieve the first key code of the managed key-bind entity.
*/
Int32 GetFirst() const;
SQMOD_NODISCARD int32_t GetFirst() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the second key code of the managed keybind entity.
* Retrieve the second key code of the managed key-bind entity.
*/
Int32 GetSecond() const;
SQMOD_NODISCARD int32_t GetSecond() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the third key code of the managed keybind entity.
* Retrieve the third key code of the managed key-bind entity.
*/
Int32 GetThird() const;
SQMOD_NODISCARD int32_t GetThird() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed keybind entity reacts to key release events.
* See whether the managed key-bind entity reacts to key release events.
*/
bool IsRelease() const;
SQMOD_NODISCARD bool IsRelease() const;
};
} // Namespace:: SqMod
+117 -133
View File
@@ -4,16 +4,16 @@
#include "Base/Quaternion.hpp"
#include "Base/Vector3.hpp"
#include "Core.hpp"
#include "Misc/Tasks.hpp"
#include "Core/Tasks.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqObject"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqObject"))
// ------------------------------------------------------------------------------------------------
const Int32 CObject::Max = SQMOD_OBJECT_POOL;
const int32_t CObject::Max = SQMOD_OBJECT_POOL;
// ------------------------------------------------------------------------------------------------
SQInteger CObject::SqGetNull(HSQUIRRELVM vm)
@@ -29,9 +29,9 @@ LightObj & CObject::GetNull()
}
// ------------------------------------------------------------------------------------------------
CObject::CObject(Int32 id)
CObject::CObject(int32_t id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_OBJECT_POOL))
, m_Tag(ToStrF("%d", id)), m_Data(), m_CircularLocks(0)
, m_Tag(fmt::format("{}", id)), m_Data(), m_CircularLocks(0)
, mMoveToDuration(0)
, mMoveByDuration(0)
, mRotateToDuration(0)
@@ -93,7 +93,7 @@ void CObject::SetData(LightObj & data)
}
// ------------------------------------------------------------------------------------------------
bool CObject::Destroy(Int32 header, LightObj & payload)
bool CObject::Destroy(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@@ -111,11 +111,11 @@ LightObj & CObject::GetEvents() const
}
// ------------------------------------------------------------------------------------------------
void CObject::CustomEvent(Int32 header, LightObj & payload) const
void CObject::CustomEvent(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
// Perfrom the requested action
// Perform the requested action
Core::Get().EmitObjectCustom(m_ID, header, payload);
}
@@ -134,7 +134,7 @@ bool CObject::IsStreamedFor(CPlayer & player) const
}
// ------------------------------------------------------------------------------------------------
Int32 CObject::GetModel() const
int32_t CObject::GetModel() const
{
// Validate the managed identifier
Validate();
@@ -143,7 +143,7 @@ Int32 CObject::GetModel() const
}
// ------------------------------------------------------------------------------------------------
Int32 CObject::GetWorld() const
int32_t CObject::GetWorld() const
{
// Validate the managed identifier
Validate();
@@ -152,12 +152,12 @@ Int32 CObject::GetWorld() const
}
// ------------------------------------------------------------------------------------------------
void CObject::SetWorld(Int32 world)
void CObject::SetWorld(int32_t world)
{
// Validate the managed identifier
Validate();
// Grab the current value for this property
const Int32 current = _Func->GetObjectWorld(m_ID);
const int32_t current = _Func->GetObjectWorld(m_ID);
// Don't even bother if it's the same value
if (current == world)
{
@@ -176,7 +176,7 @@ void CObject::SetWorld(Int32 world)
}
// ------------------------------------------------------------------------------------------------
Int32 CObject::GetAlpha() const
int32_t CObject::GetAlpha() const
{
// Validate the managed identifier
Validate();
@@ -185,18 +185,18 @@ Int32 CObject::GetAlpha() const
}
// ------------------------------------------------------------------------------------------------
void CObject::SetAlpha(Int32 alpha)
void CObject::SetAlpha(int32_t alpha)
{
SetAlphaEx(alpha, 0);
}
// ------------------------------------------------------------------------------------------------
void CObject::SetAlphaEx(Int32 alpha, Uint32 time)
void CObject::SetAlphaEx(int32_t alpha, uint32_t time)
{
// Validate the managed identifier
Validate();
// Grab the current value for this property
const Int32 current = _Func->GetObjectAlpha(m_ID);
const int32_t current = _Func->GetObjectAlpha(m_ID);
// Don't even bother if it's the same value
if (current == alpha)
{
@@ -215,7 +215,7 @@ void CObject::SetAlphaEx(Int32 alpha, Uint32 time)
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveTo(const Vector3 & pos, Uint32 time) const
void CObject::MoveTo(const Vector3 & pos, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -224,7 +224,7 @@ void CObject::MoveTo(const Vector3 & pos, Uint32 time) const
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveToEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
void CObject::MoveToEx(float x, float y, float z, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -233,7 +233,7 @@ void CObject::MoveToEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveBy(const Vector3 & pos, Uint32 time) const
void CObject::MoveBy(const Vector3 & pos, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -242,7 +242,7 @@ void CObject::MoveBy(const Vector3 & pos, Uint32 time) const
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveByEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
void CObject::MoveByEx(float x, float y, float z, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -251,7 +251,7 @@ void CObject::MoveByEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
}
// ------------------------------------------------------------------------------------------------
Vector3 CObject::GetPosition()
Vector3 CObject::GetPosition() const
{
// Validate the managed identifier
Validate();
@@ -273,7 +273,7 @@ void CObject::SetPosition(const Vector3 & pos) const
}
// ------------------------------------------------------------------------------------------------
void CObject::SetPositionEx(Float32 x, Float32 y, Float32 z) const
void CObject::SetPositionEx(float x, float y, float z) const
{
// Validate the managed identifier
Validate();
@@ -282,7 +282,7 @@ void CObject::SetPositionEx(Float32 x, Float32 y, Float32 z) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateTo(const Quaternion & rot, Uint32 time) const
void CObject::RotateTo(const Quaternion & rot, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -291,7 +291,7 @@ void CObject::RotateTo(const Quaternion & rot, Uint32 time) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time) const
void CObject::RotateToEx(float x, float y, float z, float w, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -300,7 +300,7 @@ void CObject::RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToEuler(const Vector3 & rot, Uint32 time) const
void CObject::RotateToEuler(const Vector3 & rot, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -309,7 +309,7 @@ void CObject::RotateToEuler(const Vector3 & rot, Uint32 time) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
void CObject::RotateToEulerEx(float x, float y, float z, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -318,7 +318,7 @@ void CObject::RotateToEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) cons
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateBy(const Quaternion & rot, Uint32 time) const
void CObject::RotateBy(const Quaternion & rot, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -327,7 +327,7 @@ void CObject::RotateBy(const Quaternion & rot, Uint32 time) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time) const
void CObject::RotateByEx(float x, float y, float z, float w, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -336,7 +336,7 @@ void CObject::RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByEuler(const Vector3 & rot, Uint32 time) const
void CObject::RotateByEuler(const Vector3 & rot, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -345,7 +345,7 @@ void CObject::RotateByEuler(const Vector3 & rot, Uint32 time) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
void CObject::RotateByEulerEx(float x, float y, float z, uint32_t time) const
{
// Validate the managed identifier
Validate();
@@ -354,20 +354,20 @@ void CObject::RotateByEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) cons
}
// ------------------------------------------------------------------------------------------------
Quaternion CObject::GetRotation()
Quaternion CObject::GetRotation() const
{
// Validate the managed identifier
Validate();
// Create a default quaternion instance
Quaternion quat;
Quaternion q;
// Query the server for the values
_Func->GetObjectRotation(m_ID, &quat.x, &quat.y, &quat.z, &quat.w);
_Func->GetObjectRotation(m_ID, &q.x, &q.y, &q.z, &q.w);
// Return the requested information
return quat;
return q;
}
// ------------------------------------------------------------------------------------------------
Vector3 CObject::GetRotationEuler()
Vector3 CObject::GetRotationEuler() const
{
// Validate the managed identifier
Validate();
@@ -446,12 +446,12 @@ void CObject::SetTouchedReport(bool toggle)
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetPositionX() const
float CObject::GetPositionX() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 x = 0.0f, dummy;
float x = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectPosition(m_ID, &x, &dummy, &dummy);
// Return the requested information
@@ -459,12 +459,12 @@ Float32 CObject::GetPositionX() const
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetPositionY() const
float CObject::GetPositionY() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 y = 0.0f, dummy;
float y = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectPosition(m_ID, &dummy, &y, &dummy);
// Return the requested information
@@ -472,12 +472,12 @@ Float32 CObject::GetPositionY() const
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetPositionZ() const
float CObject::GetPositionZ() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 z = 0.0f, dummy;
float z = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectPosition(m_ID, &dummy, &dummy, &z);
// Return the requested information
@@ -485,12 +485,12 @@ Float32 CObject::GetPositionZ() const
}
// ------------------------------------------------------------------------------------------------
void CObject::SetPositionX(Float32 x) const
void CObject::SetPositionX(float x) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 y, z, dummy;
float y, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectPosition(m_ID, &dummy, &y, &z);
// Perform the requested operation
@@ -498,12 +498,12 @@ void CObject::SetPositionX(Float32 x) const
}
// ------------------------------------------------------------------------------------------------
void CObject::SetPositionY(Float32 y) const
void CObject::SetPositionY(float y) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, z, dummy;
float x, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectPosition(m_ID, &x, &dummy, &z);
// Perform the requested operation
@@ -511,12 +511,12 @@ void CObject::SetPositionY(Float32 y) const
}
// ------------------------------------------------------------------------------------------------
void CObject::SetPositionZ(Float32 z) const
void CObject::SetPositionZ(float z) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, y, dummy;
float x, y, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectPosition(m_ID, &x, &y, &dummy);
// Perform the requested operation
@@ -524,12 +524,12 @@ void CObject::SetPositionZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetRotationX() const
float CObject::GetRotationX() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 x = 0.0f, dummy;
float x = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectRotation(m_ID, &x, &dummy, &dummy, &dummy);
// Return the requested information
@@ -537,12 +537,12 @@ Float32 CObject::GetRotationX() const
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetRotationY() const
float CObject::GetRotationY() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 y = 0.0f, dummy;
float y = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectRotation(m_ID, &dummy, &y, &dummy, &dummy);
// Return the requested information
@@ -550,12 +550,12 @@ Float32 CObject::GetRotationY() const
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetRotationZ() const
float CObject::GetRotationZ() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 z = 0.0f, dummy;
float z = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectRotation(m_ID, &dummy, &dummy, &z, &dummy);
// Return the requested information
@@ -563,12 +563,12 @@ Float32 CObject::GetRotationZ() const
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetRotationW() const
float CObject::GetRotationW() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 w = 0.0f, dummy;
float w = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectRotation(m_ID, &dummy, &dummy, &dummy, &w);
// Return the requested information
@@ -576,12 +576,12 @@ Float32 CObject::GetRotationW() const
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetEulerRotationX() const
float CObject::GetEulerRotationX() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 x = 0.0f, dummy;
float x = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectRotationEuler(m_ID, &x, &dummy, &dummy);
// Return the requested information
@@ -589,12 +589,12 @@ Float32 CObject::GetEulerRotationX() const
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetEulerRotationY() const
float CObject::GetEulerRotationY() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 y = 0.0f, dummy;
float y = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectRotationEuler(m_ID, &dummy, &y, &dummy);
// Return the requested information
@@ -602,12 +602,12 @@ Float32 CObject::GetEulerRotationY() const
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetEulerRotationZ() const
float CObject::GetEulerRotationZ() const
{
// Validate the managed identifier
Validate();
// Clear previous information, if any
Float32 z = 0.0f, dummy;
float z = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetObjectRotationEuler(m_ID, &dummy, &dummy, &z);
// Return the requested information
@@ -615,12 +615,12 @@ Float32 CObject::GetEulerRotationZ() const
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveToX(Float32 x) const
void CObject::MoveToX(float x) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 y, z, dummy;
float y, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectPosition(m_ID, &dummy, &y, &z);
// Perform the requested operation
@@ -628,12 +628,12 @@ void CObject::MoveToX(Float32 x) const
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveToY(Float32 y) const
void CObject::MoveToY(float y) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, z, dummy;
float x, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectPosition(m_ID, &x, &dummy, &z);
// Perform the requested operation
@@ -641,12 +641,12 @@ void CObject::MoveToY(Float32 y) const
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveToZ(Float32 z) const
void CObject::MoveToZ(float z) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, y, dummy;
float x, y, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectPosition(m_ID, &x, &y, &dummy);
// Perform the requested operation
@@ -654,7 +654,7 @@ void CObject::MoveToZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveByX(Float32 x) const
void CObject::MoveByX(float x) const
{
// Validate the managed identifier
Validate();
@@ -663,7 +663,7 @@ void CObject::MoveByX(Float32 x) const
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveByY(Float32 y) const
void CObject::MoveByY(float y) const
{
// Validate the managed identifier
Validate();
@@ -672,7 +672,7 @@ void CObject::MoveByY(Float32 y) const
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveByZ(Float32 z) const
void CObject::MoveByZ(float z) const
{
// Validate the managed identifier
Validate();
@@ -681,12 +681,12 @@ void CObject::MoveByZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToX(Float32 x) const
void CObject::RotateToX(float x) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 y, z, w, dummy;
float y, z, w, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectRotation(m_ID, &dummy, &y, &z, &w);
// Perform the requested operation
@@ -694,12 +694,12 @@ void CObject::RotateToX(Float32 x) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToY(Float32 y) const
void CObject::RotateToY(float y) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, z, w, dummy;
float x, z, w, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectRotation(m_ID, &x, &dummy, &z, &w);
// Perform the requested operation
@@ -707,12 +707,12 @@ void CObject::RotateToY(Float32 y) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToZ(Float32 z) const
void CObject::RotateToZ(float z) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, y, w, dummy;
float x, y, w, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectRotation(m_ID, &x, &y, &dummy, &w);
// Perform the requested operation
@@ -720,12 +720,12 @@ void CObject::RotateToZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToW(Float32 w) const
void CObject::RotateToW(float w) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, y, z, dummy;
float x, y, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectRotation(m_ID, &x, &y, &z, &dummy);
// Perform the requested operation
@@ -733,7 +733,7 @@ void CObject::RotateToW(Float32 w) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByX(Float32 x) const
void CObject::RotateByX(float x) const
{
// Validate the managed identifier
Validate();
@@ -742,7 +742,7 @@ void CObject::RotateByX(Float32 x) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByY(Float32 y) const
void CObject::RotateByY(float y) const
{
// Validate the managed identifier
Validate();
@@ -751,7 +751,7 @@ void CObject::RotateByY(Float32 y) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByZ(Float32 z) const
void CObject::RotateByZ(float z) const
{
// Validate the managed identifier
Validate();
@@ -760,7 +760,7 @@ void CObject::RotateByZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByW(Float32 w) const
void CObject::RotateByW(float w) const
{
// Validate the managed identifier
Validate();
@@ -769,12 +769,12 @@ void CObject::RotateByW(Float32 w) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToEulerX(Float32 x) const
void CObject::RotateToEulerX(float x) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 y, z, dummy;
float y, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectRotationEuler(m_ID, &dummy, &y, &z);
// Perform the requested operation
@@ -782,12 +782,12 @@ void CObject::RotateToEulerX(Float32 x) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToEulerY(Float32 y) const
void CObject::RotateToEulerY(float y) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, z, dummy;
float x, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectRotationEuler(m_ID, &x, &dummy, &z);
// Perform the requested operation
@@ -795,12 +795,12 @@ void CObject::RotateToEulerY(Float32 y) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToEulerZ(Float32 z) const
void CObject::RotateToEulerZ(float z) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, y, dummy;
float x, y, dummy;
// Retrieve the current values for unchanged components
_Func->GetObjectRotationEuler(m_ID, &x, &y, &dummy);
// Perform the requested operation
@@ -808,7 +808,7 @@ void CObject::RotateToEulerZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByEulerX(Float32 x) const
void CObject::RotateByEulerX(float x) const
{
// Validate the managed identifier
Validate();
@@ -817,7 +817,7 @@ void CObject::RotateByEulerX(Float32 x) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByEulerY(Float32 y) const
void CObject::RotateByEulerY(float y) const
{
// Validate the managed identifier
Validate();
@@ -826,7 +826,7 @@ void CObject::RotateByEulerY(Float32 y) const
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByEulerZ(Float32 z) const
void CObject::RotateByEulerZ(float z) const
{
// Validate the managed identifier
Validate();
@@ -835,27 +835,27 @@ void CObject::RotateByEulerZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
static LightObj & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 alpha)
static LightObj & Object_CreateEx1a(int32_t model, int32_t world, float x, float y, float z,
int32_t alpha)
{
return Core::Get().NewObject(model, world, x, y, z, alpha, SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 alpha, Int32 header, LightObj & payload)
static LightObj & Object_CreateEx1b(int32_t model, int32_t world, float x, float y, float z,
int32_t alpha, int32_t header, LightObj & payload)
{
return Core::Get().NewObject(model, world, x, y, z, alpha, header, payload);
}
// ------------------------------------------------------------------------------------------------
static LightObj & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha)
static LightObj & Object_Create1a(int32_t model, int32_t world, const Vector3 & pos, int32_t alpha)
{
return Core::Get().NewObject(model, world, pos.x, pos.y, pos.z, alpha,
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha,
Int32 header, LightObj & payload)
static LightObj & Object_Create1b(int32_t model, int32_t world, const Vector3 & pos, int32_t alpha,
int32_t header, LightObj & payload)
{
return Core::Get().NewObject(model, world, pos.x, pos.y, pos.z, alpha, header, payload);
}
@@ -887,9 +887,9 @@ void Register_CObject(HSQUIRRELVM vm)
.FmtFunc(_SC("SetTag"), &CObject::ApplyTag)
.Func(_SC("CustomEvent"), &CObject::CustomEvent)
// Core Overloads
.Overload< bool (CObject::*)(void) >(_SC("Destroy"), &CObject::Destroy)
.Overload< bool (CObject::*)(Int32) >(_SC("Destroy"), &CObject::Destroy)
.Overload< bool (CObject::*)(Int32, LightObj &) >(_SC("Destroy"), &CObject::Destroy)
.Overload(_SC("Destroy"), &CObject::Destroy0)
.Overload(_SC("Destroy"), &CObject::Destroy1)
.Overload(_SC("Destroy"), &CObject::Destroy)
// Properties
.Prop(_SC("Model"), &CObject::GetModel)
.Prop(_SC("World"), &CObject::GetWorld, &CObject::SetWorld)
@@ -938,39 +938,23 @@ void Register_CObject(HSQUIRRELVM vm)
.Func(_SC("SetAlpha"), &CObject::SetAlphaEx)
.Func(_SC("SetPosition"), &CObject::SetPositionEx)
// Member Overloads
.Overload< void (CObject::*)(const Vector3 &, Uint32) const >
(_SC("MoveTo"), &CObject::MoveTo)
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
(_SC("MoveTo"), &CObject::MoveToEx)
.Overload< void (CObject::*)(const Vector3 &, Uint32) const >
(_SC("MoveBy"), &CObject::MoveBy)
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
(_SC("MoveBy"), &CObject::MoveByEx)
.Overload< void (CObject::*)(const Quaternion &, Uint32) const >
(_SC("RotateTo"), &CObject::RotateTo)
.Overload< void (CObject::*)(Float32, Float32, Float32, Float32, Uint32) const >
(_SC("RotateTo"), &CObject::RotateToEx)
.Overload< void (CObject::*)(const Vector3 &, Uint32) const >
(_SC("RotateToEuler"), &CObject::RotateToEuler)
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
(_SC("RotateToEuler"), &CObject::RotateToEulerEx)
.Overload< void (CObject::*)(const Quaternion &, Uint32) const >
(_SC("RotateBy"), &CObject::RotateBy)
.Overload< void (CObject::*)(Float32, Float32, Float32, Float32, Uint32) const >
(_SC("RotateBy"), &CObject::RotateByEx)
.Overload< void (CObject::*)(const Vector3 &, Uint32) const >
(_SC("RotateByEuler"), &CObject::RotateByEuler)
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
(_SC("RotateByEuler"), &CObject::RotateByEulerEx)
.Overload(_SC("MoveTo"), &CObject::MoveTo)
.Overload(_SC("MoveTo"), &CObject::MoveToEx)
.Overload(_SC("MoveBy"), &CObject::MoveBy)
.Overload(_SC("MoveBy"), &CObject::MoveByEx)
.Overload(_SC("RotateTo"), &CObject::RotateTo)
.Overload(_SC("RotateTo"), &CObject::RotateToEx)
.Overload(_SC("RotateToEuler"), &CObject::RotateToEuler)
.Overload(_SC("RotateToEuler"), &CObject::RotateToEulerEx)
.Overload(_SC("RotateBy"), &CObject::RotateBy)
.Overload(_SC("RotateBy"), &CObject::RotateByEx)
.Overload(_SC("RotateByEuler"), &CObject::RotateByEuler)
.Overload(_SC("RotateByEuler"), &CObject::RotateByEulerEx)
// Static Overloads
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Int32) >
(_SC("CreateEx"), &Object_CreateEx)
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Int32, LightObj &) >
(_SC("CreateEx"), &Object_CreateEx)
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Int32) >
(_SC("Create"), &Object_Create)
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Int32, Int32, LightObj &) >
(_SC("Create"), &Object_Create)
.StaticOverload(_SC("CreateEx"), &Object_CreateEx1a)
.StaticOverload(_SC("CreateEx"), &Object_CreateEx1b)
.StaticOverload(_SC("Create"), &Object_Create1a)
.StaticOverload(_SC("Create"), &Object_Create1b)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CObject::SqGetNull)
.SquirrelFunc(_SC("MakeTask"), &Tasks::MakeTask< CObject, ENT_OBJECT >)
+81 -80
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -23,13 +23,14 @@ class CObject
{
// --------------------------------------------------------------------------------------------
friend class Core;
friend class ObjectInst;
private:
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
int32_t m_ID;
/* --------------------------------------------------------------------------------------------
* User tag associated with this instance.
@@ -44,37 +45,37 @@ private:
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
*/
Uint32 m_CircularLocks;
uint32_t m_CircularLocks;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
explicit CObject(Int32 id);
explicit CObject(int32_t id);
public:
/* --------------------------------------------------------------------------------------------
* The default duration to use when moving the object.
*/
Uint32 mMoveToDuration;
Uint32 mMoveByDuration;
uint32_t mMoveToDuration;
uint32_t mMoveByDuration;
/* --------------------------------------------------------------------------------------------
* The default duration to use when rotating the object to Quaternion.
*/
Uint32 mRotateToDuration;
Uint32 mRotateByDuration;
uint32_t mRotateToDuration;
uint32_t mRotateByDuration;
/* --------------------------------------------------------------------------------------------
* The default duration to use when rotating the object to Euler.
*/
Uint32 mRotateToEulerDuration;
Uint32 mRotateByEulerDuration;
uint32_t mRotateToEulerDuration;
uint32_t mRotateByEulerDuration;
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
static const int32_t Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
@@ -110,7 +111,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const;
SQMOD_NODISCARD const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
@@ -120,12 +121,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static LightObj & GetNull();
SQMOD_NODISCARD static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const
SQMOD_NODISCARD int32_t GetID() const
{
return m_ID;
}
@@ -133,7 +134,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const
SQMOD_NODISCARD bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
@@ -141,7 +142,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
const String & GetTag() const;
SQMOD_NODISCARD const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@@ -156,7 +157,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
LightObj & GetData();
SQMOD_NODISCARD LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
@@ -166,7 +167,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed object entity.
*/
bool Destroy()
bool Destroy0() const // NOLINT(modernize-use-nodiscard)
{
return Destroy(0, NullLightObj());
}
@@ -174,7 +175,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed object entity.
*/
bool Destroy(Int32 header)
bool Destroy1(int32_t header) const // NOLINT(modernize-use-nodiscard)
{
return Destroy(header, NullLightObj());
}
@@ -182,77 +183,77 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed object entity.
*/
bool Destroy(Int32 header, LightObj & payload);
bool Destroy(int32_t header, LightObj & payload) const; // NOLINT(modernize-use-nodiscard)
/* --------------------------------------------------------------------------------------------
* Retrieve the events table of this entity.
*/
LightObj & GetEvents() const;
SQMOD_NODISCARD LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, LightObj & payload) const;
void CustomEvent(int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See if the managed object entity is streamed for the specified player.
*/
bool IsStreamedFor(CPlayer & player) const;
SQMOD_NODISCARD bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the model of the managed object entity.
*/
Int32 GetModel() const;
SQMOD_NODISCARD int32_t GetModel() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed object entity exists.
*/
Int32 GetWorld() const;
SQMOD_NODISCARD int32_t GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed object entity exists.
*/
void SetWorld(Int32 world);
void SetWorld(int32_t world);
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the managed object entity.
*/
Int32 GetAlpha() const;
SQMOD_NODISCARD int32_t GetAlpha() const;
/* --------------------------------------------------------------------------------------------
* Modify the alpha of the managed object entity.
*/
void SetAlpha(Int32 alpha);
void SetAlpha(int32_t alpha);
/* --------------------------------------------------------------------------------------------
* Modify the alpha of the managed object entity over the specified time.
*/
void SetAlphaEx(Int32 alpha, Uint32 time);
void SetAlphaEx(int32_t alpha, uint32_t time);
/* --------------------------------------------------------------------------------------------
* Move the managed object entity to the specified position over the specified time.
*/
void MoveTo(const Vector3 & pos, Uint32 time) const;
void MoveTo(const Vector3 & pos, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Move the managed object entity to the specified position over the specified time.
*/
void MoveToEx(Float32 x, Float32 y, Float32 z, Uint32 time) const;
void MoveToEx(float x, float y, float z, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Move the managed object entity by the specified position over the specified time.
*/
void MoveBy(const Vector3 & pos, Uint32 time) const;
void MoveBy(const Vector3 & pos, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Move the managed object entity by the specified position over the specified time.
*/
void MoveByEx(Float32 x, Float32 y, Float32 z, Uint32 time) const;
void MoveByEx(float x, float y, float z, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed object entity.
*/
Vector3 GetPosition();
SQMOD_NODISCARD Vector3 GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed object entity.
@@ -262,62 +263,62 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed object entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
void SetPositionEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity to the specified rotation over the specified time.
*/
void RotateTo(const Quaternion & rot, Uint32 time) const;
void RotateTo(const Quaternion & rot, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity to the specified rotation over the specified time.
*/
void RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time) const;
void RotateToEx(float x, float y, float z, float w, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity to the specified Euler rotation over the specified time.
*/
void RotateToEuler(const Vector3 & rot, Uint32 time) const;
void RotateToEuler(const Vector3 & rot, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity to the specified Euler rotation over the specified time.
*/
void RotateToEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) const;
void RotateToEulerEx(float x, float y, float z, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity by the specified rotation over the specified time.
*/
void RotateBy(const Quaternion & rot, Uint32 time) const;
void RotateBy(const Quaternion & rot, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity by the specified rotation over the specified time.
*/
void RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time) const;
void RotateByEx(float x, float y, float z, float w, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity by the specified Euler rotation over the specified time.
*/
void RotateByEuler(const Vector3 & rot, Uint32 time) const;
void RotateByEuler(const Vector3 & rot, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity by the specified Euler rotation over the specified time.
*/
void RotateByEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) const;
void RotateByEulerEx(float x, float y, float z, uint32_t time) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation of the managed object entity.
*/
Quaternion GetRotation();
SQMOD_NODISCARD Quaternion GetRotation() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the Euler rotation of the managed object entity.
*/
Vector3 GetRotationEuler();
SQMOD_NODISCARD Vector3 GetRotationEuler() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed object entity reports gunshots.
*/
bool GetShotReport() const;
SQMOD_NODISCARD bool GetShotReport() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed object entity reports gunshots.
@@ -327,7 +328,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the managed object entity reports player bumps.
*/
bool GetTouchedReport() const;
SQMOD_NODISCARD bool GetTouchedReport() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed object entity reports player bumps.
@@ -337,167 +338,167 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed object entity.
*/
Float32 GetPositionX() const;
SQMOD_NODISCARD float GetPositionX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed object entity.
*/
Float32 GetPositionY() const;
SQMOD_NODISCARD float GetPositionY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed object entity.
*/
Float32 GetPositionZ() const;
SQMOD_NODISCARD float GetPositionZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed object entity.
*/
void SetPositionX(Float32 x) const;
void SetPositionX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed object entity.
*/
void SetPositionY(Float32 y) const;
void SetPositionY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed object entity.
*/
void SetPositionZ(Float32 z) const;
void SetPositionZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the x axis of the managed object entity.
*/
Float32 GetRotationX() const;
SQMOD_NODISCARD float GetRotationX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the y axis of the managed object entity.
*/
Float32 GetRotationY() const;
SQMOD_NODISCARD float GetRotationY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the z axis of the managed object entity.
*/
Float32 GetRotationZ() const;
SQMOD_NODISCARD float GetRotationZ() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation amount of the managed object entity.
*/
Float32 GetRotationW() const;
SQMOD_NODISCARD float GetRotationW() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the Euler rotation on the x axis of the managed object entity.
*/
Float32 GetEulerRotationX() const;
SQMOD_NODISCARD float GetEulerRotationX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the Euler rotation on the y axis of the managed object entity.
*/
Float32 GetEulerRotationY() const;
SQMOD_NODISCARD float GetEulerRotationY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the Euler rotation on the z axis of the managed object entity.
*/
Float32 GetEulerRotationZ() const;
SQMOD_NODISCARD float GetEulerRotationZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed object entity.
*/
void MoveToX(Float32 x) const;
void MoveToX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed object entity.
*/
void MoveToY(Float32 y) const;
void MoveToY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed object entity.
*/
void MoveToZ(Float32 z) const;
void MoveToZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed object entity.
*/
void MoveByX(Float32 x) const;
void MoveByX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed object entity.
*/
void MoveByY(Float32 y) const;
void MoveByY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed object entity.
*/
void MoveByZ(Float32 z) const;
void MoveByZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the x axis of the managed object entity.
*/
void RotateToX(Float32 x) const;
void RotateToX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the y axis of the managed object entity.
*/
void RotateToY(Float32 y) const;
void RotateToY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the z axis of the managed object entity.
*/
void RotateToZ(Float32 z) const;
void RotateToZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the w axis of the managed object entity.
*/
void RotateToW(Float32 w) const;
void RotateToW(float w) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the x axis of the managed object entity.
*/
void RotateByX(Float32 x) const;
void RotateByX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the y axis of the managed object entity.
*/
void RotateByY(Float32 y) const;
void RotateByY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the z axis of the managed object entity.
*/
void RotateByZ(Float32 z) const;
void RotateByZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the w axis of the managed object entity.
*/
void RotateByW(Float32 w) const;
void RotateByW(float w) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the x axis of the managed object entity.
*/
void RotateToEulerX(Float32 x) const;
void RotateToEulerX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the y axis of the managed object entity.
*/
void RotateToEulerY(Float32 y) const;
void RotateToEulerY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the z axis of the managed object entity.
*/
void RotateToEulerZ(Float32 z) const;
void RotateToEulerZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the x axis of the managed object entity.
*/
void RotateByEulerX(Float32 x) const;
void RotateByEulerX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the y axis of the managed object entity.
*/
void RotateByEulerY(Float32 y) const;
void RotateByEulerY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the z axis of the managed object entity.
*/
void RotateByEulerZ(Float32 z) const;
void RotateByEulerZ(float z) const;
};
} // Namespace:: SqMod
+53 -57
View File
@@ -3,16 +3,16 @@
#include "Entity/Player.hpp"
#include "Base/Vector3.hpp"
#include "Core.hpp"
#include "Misc/Tasks.hpp"
#include "Core/Tasks.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqPickup"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqPickup"))
// ------------------------------------------------------------------------------------------------
const Int32 CPickup::Max = SQMOD_PICKUP_POOL;
const int32_t CPickup::Max = SQMOD_PICKUP_POOL;
// ------------------------------------------------------------------------------------------------
SQInteger CPickup::SqGetNull(HSQUIRRELVM vm)
@@ -28,9 +28,9 @@ LightObj & CPickup::GetNull()
}
// ------------------------------------------------------------------------------------------------
CPickup::CPickup(Int32 id)
CPickup::CPickup(int32_t id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_PICKUP_POOL))
, m_Tag(ToStrF("%d", id)), m_Data(), m_CircularLocks(0)
, m_Tag(fmt::format("{}", id)), m_Data(), m_CircularLocks(0)
{
/* ... */
}
@@ -86,7 +86,7 @@ void CPickup::SetData(LightObj & data)
}
// ------------------------------------------------------------------------------------------------
bool CPickup::Destroy(Int32 header, LightObj & payload)
bool CPickup::Destroy(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@@ -104,11 +104,11 @@ LightObj & CPickup::GetEvents() const
}
// ------------------------------------------------------------------------------------------------
void CPickup::CustomEvent(Int32 header, LightObj & payload) const
void CPickup::CustomEvent(int32_t header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
// Perfrom the requested action
// Perform the requested action
Core::Get().EmitPickupCustom(m_ID, header, payload);
}
@@ -127,7 +127,7 @@ bool CPickup::IsStreamedFor(CPlayer & player) const
}
// ------------------------------------------------------------------------------------------------
bool CPickup::GetOption(Int32 option_id) const
bool CPickup::GetOption(int32_t option_id) const
{
// Attempt to obtain the current value of the specified option
const bool value = _Func->GetPickupOption(m_ID, static_cast< vcmpPickupOption >(option_id));
@@ -141,7 +141,7 @@ bool CPickup::GetOption(Int32 option_id) const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetOption(Int32 option_id, bool toggle)
void CPickup::SetOption(int32_t option_id, bool toggle)
{
// Attempt to obtain the current value of the specified option
const bool value = _Func->GetPickupOption(m_ID, static_cast< vcmpPickupOption >(option_id));
@@ -161,7 +161,7 @@ void CPickup::SetOption(Int32 option_id, bool toggle)
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload)
void CPickup::SetOptionEx(int32_t option_id, bool toggle, int32_t header, LightObj & payload)
{
// Attempt to obtain the current value of the specified option
const bool value = _Func->GetPickupOption(m_ID, static_cast< vcmpPickupOption >(option_id));
@@ -181,7 +181,7 @@ void CPickup::SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj &
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetWorld() const
int32_t CPickup::GetWorld() const
{
// Validate the managed identifier
Validate();
@@ -190,12 +190,12 @@ Int32 CPickup::GetWorld() const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetWorld(Int32 world)
void CPickup::SetWorld(int32_t world)
{
// Validate the managed identifier
Validate();
// Grab the current value for this property
const Int32 current = _Func->GetPickupWorld(m_ID);
const int32_t current = _Func->GetPickupWorld(m_ID);
// Don't even bother if it's the same value
if (current == world)
{
@@ -214,7 +214,7 @@ void CPickup::SetWorld(Int32 world)
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetAlpha() const
int32_t CPickup::GetAlpha() const
{
// Validate the managed identifier
Validate();
@@ -223,12 +223,12 @@ Int32 CPickup::GetAlpha() const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAlpha(Int32 alpha)
void CPickup::SetAlpha(int32_t alpha)
{
// Validate the managed identifier
Validate();
// Grab the current value for this property
const Int32 current = _Func->GetPickupAlpha(m_ID);
const int32_t current = _Func->GetPickupAlpha(m_ID);
// Don't even bother if it's the same value
if (current == alpha)
{
@@ -280,7 +280,7 @@ void CPickup::SetAutomatic(bool toggle)
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetAutoTimer() const
int32_t CPickup::GetAutoTimer() const
{
// Validate the managed identifier
Validate();
@@ -289,12 +289,12 @@ Int32 CPickup::GetAutoTimer() const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAutoTimer(Int32 timer)
void CPickup::SetAutoTimer(int32_t timer)
{
// Validate the managed identifier
Validate();
// Grab the current value for this property
const Int32 current = _Func->GetPickupAutoTimer(m_ID);
const int32_t current = _Func->GetPickupAutoTimer(m_ID);
// Don't even bother if it's the same value
if (current == timer)
{
@@ -322,7 +322,7 @@ void CPickup::Refresh() const
}
// ------------------------------------------------------------------------------------------------
Vector3 CPickup::GetPosition()
Vector3 CPickup::GetPosition() const
{
// Validate the managed identifier
Validate();
@@ -344,7 +344,7 @@ void CPickup::SetPosition(const Vector3 & pos) const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPositionEx(Float32 x, Float32 y, Float32 z) const
void CPickup::SetPositionEx(float x, float y, float z) const
{
// Validate the managed identifier
Validate();
@@ -353,7 +353,7 @@ void CPickup::SetPositionEx(Float32 x, Float32 y, Float32 z) const
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetModel() const
int32_t CPickup::GetModel() const
{
// Validate the managed identifier
Validate();
@@ -362,7 +362,7 @@ Int32 CPickup::GetModel() const
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetQuantity() const
int32_t CPickup::GetQuantity() const
{
// Validate the managed identifier
Validate();
@@ -371,12 +371,12 @@ Int32 CPickup::GetQuantity() const
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPositionX() const
float CPickup::GetPositionX() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
Float32 x = 0.0f, dummy;
float x = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetPickupPosition(m_ID, &x, &dummy, &dummy);
// Return the requested information
@@ -384,12 +384,12 @@ Float32 CPickup::GetPositionX() const
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPositionY() const
float CPickup::GetPositionY() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
Float32 y = 0.0f, dummy;
float y = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetPickupPosition(m_ID, &dummy, &y, &dummy);
// Return the requested information
@@ -397,12 +397,12 @@ Float32 CPickup::GetPositionY() const
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPositionZ() const
float CPickup::GetPositionZ() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
Float32 z = 0.0f, dummy;
float z = 0.0f, dummy;
// Query the server for the requested component value
_Func->GetPickupPosition(m_ID, &dummy, &dummy, &z);
// Return the requested information
@@ -410,12 +410,12 @@ Float32 CPickup::GetPositionZ() const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPositionX(Float32 x) const
void CPickup::SetPositionX(float x) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 y, z, dummy;
float y, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetPickupPosition(m_ID, &dummy, &y, &z);
// Perform the requested operation
@@ -423,12 +423,12 @@ void CPickup::SetPositionX(Float32 x) const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPositionY(Float32 y) const
void CPickup::SetPositionY(float y) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, z, dummy;
float x, z, dummy;
// Retrieve the current values for unchanged components
_Func->GetPickupPosition(m_ID, &x, &dummy, &z);
// Perform the requested operation
@@ -436,12 +436,12 @@ void CPickup::SetPositionY(Float32 y) const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPositionZ(Float32 z) const
void CPickup::SetPositionZ(float z) const
{
// Validate the managed identifier
Validate();
// Reserve some temporary floats to retrieve the missing components
Float32 x, y, dummy;
float x, y, dummy;
// Retrieve the current values for unchanged components
_Func->GetPickupPosition(m_ID, &x, &y, &dummy);
// Perform the requested operation
@@ -449,30 +449,30 @@ void CPickup::SetPositionZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
static LightObj & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic)
static LightObj & Pickup_CreateEx1a(int32_t model, int32_t world, int32_t quantity,
float x, float y, float z, int32_t alpha, bool automatic)
{
return Core::Get().NewPickup(model, world, quantity, x, y, z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
Int32 header, LightObj & payload)
static LightObj & Pickup_CreateEx1b(int32_t model, int32_t world, int32_t quantity,
float x, float y, float z, int32_t alpha, bool automatic,
int32_t header, LightObj & payload)
{
return Core::Get().NewPickup(model, world, quantity, x, y, z, alpha, automatic, header, payload);
}
// ------------------------------------------------------------------------------------------------
static LightObj & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
Int32 alpha, bool automatic)
static LightObj & Pickup_Create1a(int32_t model, int32_t world, int32_t quantity, const Vector3 & pos,
int32_t alpha, bool automatic)
{
return Core::Get().NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static LightObj & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
Int32 alpha, bool automatic, Int32 header, LightObj & payload)
static LightObj & Pickup_Create1b(int32_t model, int32_t world, int32_t quantity, const Vector3 & pos,
int32_t alpha, bool automatic, int32_t header, LightObj & payload)
{
return Core::Get().NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
header, payload);
@@ -498,9 +498,9 @@ void Register_CPickup(HSQUIRRELVM vm)
.FmtFunc(_SC("SetTag"), &CPickup::ApplyTag)
.Func(_SC("CustomEvent"), &CPickup::CustomEvent)
// Core Overloads
.Overload< bool (CPickup::*)(void) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32, LightObj &) >(_SC("Destroy"), &CPickup::Destroy)
.Overload(_SC("Destroy"), &CPickup::Destroy)
.Overload(_SC("Destroy"), &CPickup::Destroy)
.Overload(_SC("Destroy"), &CPickup::Destroy)
// Properties
.Prop(_SC("Model"), &CPickup::GetModel)
.Prop(_SC("World"), &CPickup::GetWorld, &CPickup::SetWorld)
@@ -508,7 +508,7 @@ void Register_CPickup(HSQUIRRELVM vm)
.Prop(_SC("Auto"), &CPickup::GetAutomatic, &CPickup::SetAutomatic)
.Prop(_SC("Automatic"), &CPickup::GetAutomatic, &CPickup::SetAutomatic)
.Prop(_SC("Timer"), &CPickup::GetAutoTimer, &CPickup::SetAutoTimer)
.Prop(_SC("Autotimer"), &CPickup::GetAutoTimer, &CPickup::SetAutoTimer)
.Prop(_SC("AutoTimer"), &CPickup::GetAutoTimer, &CPickup::SetAutoTimer)
.Prop(_SC("Pos"), &CPickup::GetPosition, &CPickup::SetPosition)
.Prop(_SC("Position"), &CPickup::GetPosition, &CPickup::SetPosition)
.Prop(_SC("Quantity"), &CPickup::GetQuantity)
@@ -524,14 +524,10 @@ void Register_CPickup(HSQUIRRELVM vm)
.Func(_SC("SetPos"), &CPickup::SetPositionEx)
.Func(_SC("SetPosition"), &CPickup::SetPositionEx)
// Static Overloads
.StaticOverload< LightObj & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
(_SC("CreateEx"), &Pickup_CreateEx)
.StaticOverload< LightObj & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool, Int32, LightObj &) >
(_SC("CreateEx"), &Pickup_CreateEx)
.StaticOverload< LightObj & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool) >
(_SC("Create"), &Pickup_Create)
.StaticOverload< LightObj & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool, Int32, LightObj &) >
(_SC("Create"), &Pickup_Create)
.StaticOverload(_SC("CreateEx"), &Pickup_CreateEx1a)
.StaticOverload(_SC("CreateEx"), &Pickup_CreateEx1b)
.StaticOverload(_SC("Create"), &Pickup_Create1a)
.StaticOverload(_SC("Create"), &Pickup_Create1b)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CPickup::SqGetNull)
.SquirrelFunc(_SC("MakeTask"), &Tasks::MakeTask< CPickup, ENT_PICKUP >)
+43 -42
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -25,13 +25,14 @@ class CPickup
{
// --------------------------------------------------------------------------------------------
friend class Core;
friend class PickupInst;
private:
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
int32_t m_ID;
/* --------------------------------------------------------------------------------------------
* User tag associated with this instance.
@@ -46,19 +47,19 @@ private:
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
*/
Uint32 m_CircularLocks;
uint32_t m_CircularLocks;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
explicit CPickup(Int32 id);
explicit CPickup(int32_t id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
static const int32_t Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
@@ -94,7 +95,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const;
SQMOD_NODISCARD const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
@@ -104,12 +105,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static LightObj & GetNull();
SQMOD_NODISCARD static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const
SQMOD_NODISCARD int32_t GetID() const
{
return m_ID;
}
@@ -117,7 +118,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const
SQMOD_NODISCARD bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
@@ -125,7 +126,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
const String & GetTag() const;
SQMOD_NODISCARD const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@@ -140,7 +141,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
LightObj & GetData();
SQMOD_NODISCARD LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
@@ -150,7 +151,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed pickup entity.
*/
bool Destroy()
bool Destroy0() const // NOLINT(modernize-use-nodiscard)
{
return Destroy(0, NullLightObj());
}
@@ -158,7 +159,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed pickup entity.
*/
bool Destroy(Int32 header)
bool Destroy1(int32_t header) const // NOLINT(modernize-use-nodiscard)
{
return Destroy(header, NullLightObj());
}
@@ -166,62 +167,62 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed pickup entity.
*/
bool Destroy(Int32 header, LightObj & payload);
bool Destroy(int32_t header, LightObj & payload) const; // NOLINT(modernize-use-nodiscard)
/* --------------------------------------------------------------------------------------------
* Retrieve the events table of this entity.
*/
LightObj & GetEvents() const;
SQMOD_NODISCARD LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, LightObj & payload) const;
void CustomEvent(int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See if the managed pickup entity is streamed for the specified player.
*/
bool IsStreamedFor(CPlayer & player) const;
SQMOD_NODISCARD bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current option value of the managed pickup entity.
*/
bool GetOption(Int32 option_id) const;
SQMOD_NODISCARD bool GetOption(int32_t option_id) const;
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed pickup entity.
*/
void SetOption(Int32 option_id, bool toggle);
void SetOption(int32_t option_id, bool toggle);
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed pickup entity.
*/
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload);
void SetOptionEx(int32_t option_id, bool toggle, int32_t header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed pickup entity exists.
*/
Int32 GetWorld() const;
SQMOD_NODISCARD int32_t GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Mpdify the world in which the managed pickup entity exists.
* Modify the world in which the managed pickup entity exists.
*/
void SetWorld(Int32 world);
void SetWorld(int32_t world);
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the managed pickup entity.
*/
Int32 GetAlpha() const;
SQMOD_NODISCARD int32_t GetAlpha() const;
/* --------------------------------------------------------------------------------------------
* Mpdify the alpha of the managed pickup entity.
* Modify the alpha of the managed pickup entity.
*/
void SetAlpha(Int32 alpha);
void SetAlpha(int32_t alpha);
/* --------------------------------------------------------------------------------------------
* See whether the managed pickup entity is automatic.
*/
bool GetAutomatic() const;
SQMOD_NODISCARD bool GetAutomatic() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed pickup entity is automatic.
@@ -231,12 +232,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the automatic timer of the managed pickup entity.
*/
Int32 GetAutoTimer() const;
SQMOD_NODISCARD int32_t GetAutoTimer() const;
/* --------------------------------------------------------------------------------------------
* Mpdify the automatic timer of the managed pickup entity.
* Modify the automatic timer of the managed pickup entity.
*/
void SetAutoTimer(Int32 timer);
void SetAutoTimer(int32_t timer);
/* --------------------------------------------------------------------------------------------
* Refresh the managed pickup entity.
@@ -246,57 +247,57 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed pickup entity.
*/
Vector3 GetPosition();
SQMOD_NODISCARD Vector3 GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Mpdify the position of the managed pickup entity.
* Modify the position of the managed pickup entity.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Mpdify the position of the managed pickup entity.
* Modify the position of the managed pickup entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
void SetPositionEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the model of the managed pickup entity.
*/
Int32 GetModel() const;
SQMOD_NODISCARD int32_t GetModel() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the quantity of the managed pickup entity.
*/
Int32 GetQuantity() const;
SQMOD_NODISCARD int32_t GetQuantity() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed pickup entity.
*/
Float32 GetPositionX() const;
SQMOD_NODISCARD float GetPositionX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed pickup entity.
*/
Float32 GetPositionY() const;
SQMOD_NODISCARD float GetPositionY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed pickup entity.
*/
Float32 GetPositionZ() const;
SQMOD_NODISCARD float GetPositionZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed pickup entity.
*/
void SetPositionX(Float32 x) const;
void SetPositionX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed pickup entity.
*/
void SetPositionY(Float32 y) const;
void SetPositionY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed pickup entity.
*/
void SetPositionZ(Float32 z) const;
void SetPositionZ(float z) const;
};
} // Namespace:: SqMod
+222 -236
View File
File diff suppressed because it is too large Load Diff
+153 -152
View File
@@ -1,8 +1,8 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Base/Buffer.hpp"
#include "Core/Common.hpp"
#include "Core/Buffer.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -31,6 +31,7 @@ class CPlayer
{
// --------------------------------------------------------------------------------------------
friend class Core;
friend class PlayerInst;
private:
@@ -40,7 +41,7 @@ private:
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
int32_t m_ID;
/* --------------------------------------------------------------------------------------------
* User tag associated with this instance.
@@ -60,12 +61,12 @@ private:
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
*/
Uint32 m_CircularLocks;
uint32_t m_CircularLocks;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
explicit CPlayer(Int32 id);
explicit CPlayer(int32_t id);
public:
@@ -75,27 +76,27 @@ public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
static const int32_t Max;
/* --------------------------------------------------------------------------------------------
* The initial size of the allocated memory buffer when starting a new stream.
*/
Uint32 mBufferInitSize;
uint32_t mBufferInitSize;
/* --------------------------------------------------------------------------------------------
* Default color to use in client messages.
*/
Uint32 mMessageColor;
uint32_t mMessageColor;
/* --------------------------------------------------------------------------------------------
* Default style to use in client announcements.
*/
Int32 mAnnounceStyle;
int32_t mAnnounceStyle;
/* --------------------------------------------------------------------------------------------
* Default ammo to give to the managed player when not specifying any.
*/
Int32 mDefaultAmmo;
int32_t mDefaultAmmo;
/* --------------------------------------------------------------------------------------------
* Set of strings to add before a client message automatically.
@@ -161,7 +162,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const;
SQMOD_NODISCARD const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
@@ -171,12 +172,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static LightObj & GetNull();
SQMOD_NODISCARD static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const
SQMOD_NODISCARD int32_t GetID() const
{
return m_ID;
}
@@ -184,7 +185,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const
SQMOD_NODISCARD bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
@@ -192,7 +193,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
const String & GetTag() const;
SQMOD_NODISCARD const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@@ -207,7 +208,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
LightObj & GetData();
SQMOD_NODISCARD LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
@@ -217,17 +218,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the events table of this entity.
*/
LightObj & GetEvents() const;
SQMOD_NODISCARD LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, LightObj & payload) const;
void CustomEvent(int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is connected.
*/
bool IsConnected() const;
SQMOD_NODISCARD bool IsConnected() const;
/* --------------------------------------------------------------------------------------------
* See if the managed player entity is streamed for the specified player.
@@ -237,7 +238,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has administrator privileges.
*/
bool GetAdmin() const;
SQMOD_NODISCARD bool GetAdmin() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity has administrator privileges.
@@ -247,17 +248,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the ip address of the managed player entity.
*/
CSStr GetIP() const;
SQMOD_NODISCARD const SQChar * GetIP() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the unique user identifier of the managed player entity.
*/
CSStr GetUID() const;
SQMOD_NODISCARD const SQChar * GetUID() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the unique user identifier version 2 of the managed player entity.
*/
CSStr GetUID2() const;
SQMOD_NODISCARD const SQChar * GetUID2() const;
#if SQMOD_SDK_LEAST(2, 1)
/* --------------------------------------------------------------------------------------------
* Set player's health to 0 and reset the death reason.
@@ -272,7 +273,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Kick the managed player entity from the server.
*/
void KickBecause(Int32 header, LightObj & payload) const;
void KickBecause(int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Ban the managed player entity from the server.
@@ -282,17 +283,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Ban the managed player entity from the server.
*/
void BanBecause(Int32 header, LightObj & payload) const;
void BanBecause(int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the key of the managed player entity.
*/
Uint32 GetKey() const;
SQMOD_NODISCARD uint32_t GetKey() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the nick name of the managed player entity.
*/
CSStr GetName() const;
SQMOD_NODISCARD const SQChar * GetName() const;
/* --------------------------------------------------------------------------------------------
* Modify the nick name of the managed player entity.
@@ -302,92 +303,92 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current state of the managed player entity.
*/
Int32 GetState() const;
SQMOD_NODISCARD int32_t GetState() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current option value of the managed player entity.
*/
Int32 GetOption(Int32 option_id) const;
SQMOD_NODISCARD int32_t GetOption(int32_t option_id) const;
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed player entity.
*/
void SetOption(Int32 option_id, bool toggle);
void SetOption(int32_t option_id, bool toggle);
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed player entity.
*/
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload);
void SetOptionEx(int32_t option_id, bool toggle, int32_t header, LightObj & payload);
#if SQMOD_SDK_LEAST(2, 1)
/* --------------------------------------------------------------------------------------------
* Retrieve network statistics related to the managed player entity.
*/
SQFloat GetNetworkStatisticsF(Int32 option_id) const;
SQMOD_NODISCARD SQFloat GetNetworkStatisticsF(int32_t option_id) const;
/* --------------------------------------------------------------------------------------------
* Retrieve network statistics related to the managed player entity.
*/
SQInteger GetNetworkStatisticsI(Int32 option_id) const;
SQMOD_NODISCARD SQInteger GetNetworkStatisticsI(int32_t option_id) const;
#endif
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed player entity exists.
*/
Int32 GetWorld() const;
SQMOD_NODISCARD int32_t GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed player entity exists.
*/
void SetWorld(Int32 world);
void SetWorld(int32_t world);
/* --------------------------------------------------------------------------------------------
* Retrieve the secondary world of the managed player entity.
*/
Int32 GetSecondaryWorld() const;
SQMOD_NODISCARD int32_t GetSecondaryWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the secondary world of the managed player entity.
*/
void SetSecondaryWorld(Int32 world);
void SetSecondaryWorld(int32_t world);
/* --------------------------------------------------------------------------------------------
* Retrieve the unique world of the managed player entity.
*/
Int32 GetUniqueWorld() const;
SQMOD_NODISCARD int32_t GetUniqueWorld() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is compatible with the specified world.
*/
bool IsWorldCompatible(Int32 world) const;
SQMOD_NODISCARD bool IsWorldCompatible(int32_t world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the class of the managed player entity.
*/
Int32 GetClass() const;
SQMOD_NODISCARD int32_t GetClass() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the team of the managed player entity.
*/
Int32 GetTeam() const;
SQMOD_NODISCARD int32_t GetTeam() const;
/* --------------------------------------------------------------------------------------------
* Modify the team of the managed player entity.
*/
void SetTeam(Int32 team);
void SetTeam(int32_t team);
/* --------------------------------------------------------------------------------------------
* Retrieve the skin identifier of the managed player entity.
*/
Int32 GetSkin() const;
SQMOD_NODISCARD int32_t GetSkin() const;
/* --------------------------------------------------------------------------------------------
* Modify the skin identifier of the managed player entity.
*/
void SetSkin(Int32 skin);
void SetSkin(int32_t skin);
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the managed player entity.
*/
Color3 GetColor() const;
SQMOD_NODISCARD Color3 GetColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed player entity.
@@ -397,12 +398,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed player entity.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
void SetColorEx(uint8_t r, uint8_t g, uint8_t b) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is spawned.
*/
bool IsSpawned() const;
SQMOD_NODISCARD bool IsSpawned() const;
/* --------------------------------------------------------------------------------------------
* Force the managed player entity to spawn in the game.
@@ -417,87 +418,87 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is typing.
*/
bool IsTyping() const;
SQMOD_NODISCARD bool IsTyping() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the money amount of the managed player entity.
*/
Int32 GetMoney() const;
SQMOD_NODISCARD int32_t GetMoney() const;
/* --------------------------------------------------------------------------------------------
* Modify the money amount of the managed player entity.
*/
void SetMoney(Int32 amount);
void SetMoney(int32_t amount);
/* --------------------------------------------------------------------------------------------
* Give a certain amount of money to the managed player entity.
*/
void GiveMoney(Int32 amount);
void GiveMoney(int32_t amount);
/* --------------------------------------------------------------------------------------------
* Retrieve the score of the managed player entity.
*/
Int32 GetScore() const;
SQMOD_NODISCARD int32_t GetScore() const;
/* --------------------------------------------------------------------------------------------
* Modify the score of the managed player entity.
*/
void SetScore(Int32 score);
void SetScore(int32_t score);
/* --------------------------------------------------------------------------------------------
* Retrieve the wanted level of the managed player entity.
*/
Int32 GetWantedLevel() const;
SQMOD_NODISCARD int32_t GetWantedLevel() const;
/* --------------------------------------------------------------------------------------------
* Modify the wanted level of the managed player entity.
*/
void SetWantedLevel(Int32 level);
void SetWantedLevel(int32_t level);
/* --------------------------------------------------------------------------------------------
* Retrieve the connection latency of the managed player entity.
*/
Int32 GetPing() const;
SQMOD_NODISCARD int32_t GetPing() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the frames per second of the managed player entity.
*/
SQFloat GetFPS() const;
SQMOD_NODISCARD SQFloat GetFPS() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current health of the managed player entity.
*/
Float32 GetHealth() const;
SQMOD_NODISCARD float GetHealth() const;
/* --------------------------------------------------------------------------------------------
* Modify the health of the managed player entity.
*/
void SetHealth(Float32 amount) const;
void SetHealth(float amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current health of the managed player entity.
*/
Float32 GetArmor() const;
SQMOD_NODISCARD float GetArmor() const;
/* --------------------------------------------------------------------------------------------
* Modify the health of the managed player entity.
*/
void SetArmor(Float32 amount) const;
void SetArmor(float amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the immunity flags of the managed player entity.
*/
Int32 GetImmunity() const;
SQMOD_NODISCARD int32_t GetImmunity() const;
/* --------------------------------------------------------------------------------------------
* Modify the immunity flags of the managed player entity.
*/
void SetImmunity(Int32 flags);
void SetImmunity(int32_t flags);
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed player entity.
*/
Vector3 GetPosition() const;
SQMOD_NODISCARD Vector3 GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed player entity.
@@ -507,12 +508,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed player entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
void SetPositionEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the speed of the managed player entity.
*/
Vector3 GetSpeed() const;
SQMOD_NODISCARD Vector3 GetSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed player entity.
@@ -522,7 +523,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed player entity.
*/
void SetSpeedEx(Float32 x, Float32 y, Float32 z) const;
void SetSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed player entity.
@@ -532,62 +533,62 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed player entity.
*/
void AddSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the heading angle of the managed player entity.
*/
Float32 GetHeading() const;
SQMOD_NODISCARD float GetHeading() const;
/* --------------------------------------------------------------------------------------------
* Modify the heading angle of the managed player entity.
*/
void SetHeading(Float32 angle) const;
void SetHeading(float angle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the managed player entity.
*/
Int32 GetAlpha() const;
SQMOD_NODISCARD int32_t GetAlpha() const;
/* --------------------------------------------------------------------------------------------
* Modify the alpha of the managed player entity.
*/
void SetAlpha(Int32 alpha);
void SetAlpha(int32_t alpha);
/* --------------------------------------------------------------------------------------------
* Modify the alpha of the managed player entity.
*/
void SetAlphaEx(Int32 alpha, Int32 fade);
void SetAlphaEx(int32_t alpha, int32_t fade);
/* --------------------------------------------------------------------------------------------
* Retrieve the aim position of the managed player entity.
*/
Vector3 GetAimPosition() const;
SQMOD_NODISCARD Vector3 GetAimPosition() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the aim direction of the managed player entity.
*/
Vector3 GetAimDirection() const;
SQMOD_NODISCARD Vector3 GetAimDirection() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is burning.
*/
bool IsBurning() const;
SQMOD_NODISCARD bool IsBurning() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is crouched.
*/
bool IsCrouched() const;
SQMOD_NODISCARD bool IsCrouched() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current action of the managed player entity.
*/
Int32 GetAction() const;
SQMOD_NODISCARD int32_t GetAction() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the game keys of the managed player entity.
*/
Int32 GetGameKeys() const;
SQMOD_NODISCARD int32_t GetGameKeys() const;
/* --------------------------------------------------------------------------------------------
* Embark the managed player entity into the specified vehicle entity.
@@ -597,7 +598,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Embark the managed player entity into the specified vehicle entity.
*/
bool Embark(CVehicle & vehicle, Int32 slot, bool allocate, bool warp) const;
bool EmbarkEx(CVehicle & vehicle, int32_t slot, bool allocate, bool warp) const;
/* --------------------------------------------------------------------------------------------
* Disembark the managed player entity from the currently embarked vehicle entity.
@@ -607,72 +608,72 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle status of the managed player entity.
*/
Int32 GetVehicleStatus() const;
SQMOD_NODISCARD int32_t GetVehicleStatus() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the occupied vehicle slot by the managed player entity.
*/
Int32 GetVehicleSlot() const;
SQMOD_NODISCARD int32_t GetVehicleSlot() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle in which the managed player entity is embarked.
*/
LightObj & GetVehicle() const;
SQMOD_NODISCARD LightObj & GetVehicle() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle identifier in which the managed player entity is embarked.
*/
Int32 GetVehicleID() const;
SQMOD_NODISCARD int32_t GetVehicleID() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the weapon identifier of the managed player entity.
*/
Int32 GetWeapon() const;
SQMOD_NODISCARD int32_t GetWeapon() const;
/* --------------------------------------------------------------------------------------------
* Modify the weapon of the managed player entity.
*/
void SetWeapon(Int32 wep) const;
void SetWeapon(int32_t wep) const;
/* --------------------------------------------------------------------------------------------
* Modify the weapon of the managed player entity.
*/
void SetWeaponEx(Int32 wep, Int32 ammo) const;
void SetWeaponEx(int32_t wep, int32_t ammo) const;
/* --------------------------------------------------------------------------------------------
* Give a weapon of the managed player entity.
*/
void GiveWeapon(Int32 wep, Int32 ammo) const;
void GiveWeapon(int32_t wep, int32_t ammo) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the active weapon ammo of the managed player entity.
*/
Int32 GetAmmo() const;
SQMOD_NODISCARD int32_t GetAmmo() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the weapon slot of the managed player entity.
*/
Int32 GetWeaponSlot() const;
SQMOD_NODISCARD int32_t GetWeaponSlot() const;
/* --------------------------------------------------------------------------------------------
* Modify the weapon slot of the managed player entity.
*/
void SetWeaponSlot(Int32 slot) const;
void SetWeaponSlot(int32_t slot) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the weapon identifier at the specified slot for the managed player entity.
*/
Int32 GetWeaponAtSlot(Int32 slot) const;
SQMOD_NODISCARD int32_t GetWeaponAtSlot(int32_t slot) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the ammo from the weapon at the specified slot for the managed player entity.
*/
Int32 GetAmmoAtSlot(Int32 slot) const;
SQMOD_NODISCARD int32_t GetAmmoAtSlot(int32_t slot) const;
/* --------------------------------------------------------------------------------------------
* Remove a certain weapon from the managed player entity.
*/
void RemoveWeapon(Int32 wep) const;
void RemoveWeapon(int32_t wep) const;
/* --------------------------------------------------------------------------------------------
* Strip the managed player entity of all weapons.
@@ -687,7 +688,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the camera position of the managed player entity.
*/
void SetCameraPosition(Float32 xp, Float32 yp, Float32 zp, Float32 xa, Float32 ya, Float32 za) const;
void SetCameraPositionEx(float xp, float yp, float zp, float xa, float ya, float za) const;
/* --------------------------------------------------------------------------------------------
* Restore the camera position of the managed player entity.
@@ -697,37 +698,37 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has camera locked.
*/
bool IsCameraLocked() const;
SQMOD_NODISCARD bool IsCameraLocked() const;
/* --------------------------------------------------------------------------------------------
* Modify the animation of the managed player entity.
*/
void SetAnimation(Int32 anim) const;
void SetAnimation(int32_t anim) const;
/* --------------------------------------------------------------------------------------------
* Modify the animation of the managed player entity.
*/
void SetAnimation(Int32 anim, Int32 group) const;
void SetAnimationEx(int32_t anim, int32_t group) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle that the managed player entity is standing on.
*/
LightObj & StandingOnVehicle() const;
SQMOD_NODISCARD LightObj & StandingOnVehicle() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the object that the managed player entity is standing on.
*/
LightObj & StandingOnObject() const;
SQMOD_NODISCARD LightObj & StandingOnObject() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is away.
*/
bool IsAway() const;
SQMOD_NODISCARD bool IsAway() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the player that the managed player entity is spectating.
*/
LightObj & GetSpectator() const;
SQMOD_NODISCARD LightObj & GetSpectator() const;
/* --------------------------------------------------------------------------------------------
* Set the managed player entity to spectate the specified player entity.
@@ -737,7 +738,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the player that the managed player entity is spectating.
*/
SQInteger GetSpectatorID() const;
SQMOD_NODISCARD SQInteger GetSpectatorID() const;
/* --------------------------------------------------------------------------------------------
* Set the managed player entity to spectate the specified player entity.
@@ -757,7 +758,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the target player sees an objective arrow over a player.
*/
bool GetPlayer3DArrow(CPlayer & target) const;
SQMOD_NODISCARD bool GetPlayer3DArrow(CPlayer & target) const;
/* --------------------------------------------------------------------------------------------
* Set whether the target player will see an objective arrow over a player.
@@ -767,23 +768,23 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the target player sees an objective arrow over a player.
*/
bool GetPlayer3DArrowID(SQInteger id) const;
SQMOD_NODISCARD bool GetPlayer3DArrowID(SQInteger id) const;
/* --------------------------------------------------------------------------------------------
* Smoothly pivots the camera angle.
*/
bool InterpolateCameraLookAt(const Vector3 & pos, Uint32 ms) const;
SQMOD_NODISCARD bool InterpolateCameraLookAt(const Vector3 & pos, uint32_t ms) const;
/* --------------------------------------------------------------------------------------------
* Smoothly pivots the camera angle.
*/
bool InterpolateCameraLookAtEx(Float32 x, Float32 y, Float32 z, Uint32 ms) const;
SQMOD_NODISCARD bool InterpolateCameraLookAtEx(float x, float y, float z, uint32_t ms) const;
#endif
/* --------------------------------------------------------------------------------------------
* Redirect the managed player entity to the specified server.
*/
void Redirect(StackStrF & ip, Uint32 port, StackStrF & nick,
StackStrF & server_pass, StackStrF & user_pass);
void Redirect(StackStrF & ip, uint32_t port, StackStrF & nick,
StackStrF & server_pass, StackStrF & user_pass) const;
/* --------------------------------------------------------------------------------------------
* Request a list of the modules loaded into the client session.
@@ -793,7 +794,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the authority level of the managed player entity.
*/
void PlaySound(Int32 sound_id) const;
void PlaySound(int32_t sound_id) const;
#if SQMOD_SDK_LEAST(2, 1)
/* --------------------------------------------------------------------------------------------
* Set how delayed a player's turn handling is when in a vehicle.
@@ -803,7 +804,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve how delayed a player's turn handling is when in a vehicle.
*/
SQInteger GetDrunkHandling() const;
SQMOD_NODISCARD SQInteger GetDrunkHandling() const;
/* --------------------------------------------------------------------------------------------
* Set how intense the drunk blur overlay is for a player.
@@ -813,37 +814,37 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve how intense the drunk blur overlay is for a player.
*/
SQInteger GetDrunkVisuals() const;
SQMOD_NODISCARD SQInteger GetDrunkVisuals() const;
#endif
/* --------------------------------------------------------------------------------------------
* Create a checkpoint or sphere for this player.
*/
LightObj & CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius) const;
LightObj & CreateCheckpointEx1a(int32_t world, bool sphere, float x, float y, float z, // NOLINT(modernize-use-nodiscard)
uint8_t r, uint8_t g, uint8_t b, uint8_t a, float radius) const;
/* --------------------------------------------------------------------------------------------
* Create a checkpoint or sphere for this player.
*/
LightObj & CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, LightObj & payload) const;
LightObj & CreateCheckpointEx1b(int32_t world, bool sphere, float x, float y, float z, // NOLINT(modernize-use-nodiscard)
uint8_t r, uint8_t g, uint8_t b, uint8_t a, float radius,
int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Create a checkpoint or sphere for this player.
*/
LightObj & CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos,
const Color4 & color, Float32 radius) const;
LightObj & CreateCheckpoint1a(int32_t world, bool sphere, const Vector3 & pos, // NOLINT(modernize-use-nodiscard)
const Color4 & color, float radius) const;
/* --------------------------------------------------------------------------------------------
* Create a checkpoint or sphere for this player.
*/
LightObj & CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos, const Color4 & color,
Float32 radius, Int32 header, LightObj & payload) const;
LightObj & CreateCheckpoint1b(int32_t world, bool sphere, const Vector3 & pos, const Color4 & color, // NOLINT(modernize-use-nodiscard)
float radius, int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity collides with user defined areas.
*/
bool GetCollideAreas() const;
SQMOD_NODISCARD bool GetCollideAreas() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity can collide with user defined areas.
@@ -858,27 +859,27 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the authority level of the managed player entity.
*/
Int32 GetAuthority() const;
SQMOD_NODISCARD int32_t GetAuthority() const;
/* --------------------------------------------------------------------------------------------
* Modify the authority level of the managed player entity.
*/
void SetAuthority(Int32 level) const;
void SetAuthority(int32_t level) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the message prefix at the specified index for the managed player entity.
*/
const String & GetMessagePrefix(Uint32 index) const;
SQMOD_NODISCARD const String & GetMessagePrefix(uint32_t index) const;
/* --------------------------------------------------------------------------------------------
* Modify the message prefix at the specified index for the managed player entity.
*/
void SetMessagePrefix(Uint32 index, StackStrF & prefix);
void SetMessagePrefix(uint32_t index, StackStrF & prefix);
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of tracked position changes for the managed player entity.
*/
SQInteger GetTrackPosition() const;
SQMOD_NODISCARD SQInteger GetTrackPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the amount of tracked position changes for the managed player entity.
@@ -888,12 +889,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the amount of tracked position changes for the managed player entity.
*/
void SetTrackPositionEx(SQInteger num, Int32 header, const LightObj & payload) const;
void SetTrackPositionEx(SQInteger num, int32_t header, const LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of tracked heading changes for the managed player entity.
*/
SQInteger GetTrackHeading() const;
SQMOD_NODISCARD SQInteger GetTrackHeading() const;
/* --------------------------------------------------------------------------------------------
* Modify the amount of tracked heading changes for the managed player entity.
@@ -903,32 +904,32 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the last known weapon for the managed player entity.
*/
Int32 GetLastWeapon() const;
SQMOD_NODISCARD int32_t GetLastWeapon() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the last known health for the managed player entity.
*/
Float32 GetLastHealth() const;
SQMOD_NODISCARD float GetLastHealth() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the last known armour for the managed player entity.
*/
Float32 GetLastArmour() const;
SQMOD_NODISCARD float GetLastArmour() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the last known heading for the managed player entity.
*/
Float32 GetLastHeading() const;
SQMOD_NODISCARD float GetLastHeading() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the last known position for the managed player entity.
*/
const Vector3 & GetLastPosition() const;
SQMOD_NODISCARD const Vector3 & GetLastPosition() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the distance traveled by the managed player entity while tracking was enabled.
*/
SQFloat GetDistance() const;
SQMOD_NODISCARD SQFloat GetDistance() const;
/* --------------------------------------------------------------------------------------------
* Modify the distance traveled by the managed player entity.
@@ -938,7 +939,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check whether distance tracking is enabled for the managed player entity.
*/
bool GetTrackDistance() const;
SQMOD_NODISCARD bool GetTrackDistance() const;
/* --------------------------------------------------------------------------------------------
* Set whether distance tracking is enabled for the managed player entity.
@@ -953,17 +954,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Start a new stream with a custom size.
*/
void StartStream(Uint32 size);
void StartStreamEx(uint32_t size);
/* --------------------------------------------------------------------------------------------
* Retrieve the current cursor position of the stream buffer.
*/
Int32 GetBufferCursor() const;
SQMOD_NODISCARD int32_t GetBufferCursor() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current cursor position of the stream buffer.
*/
void SetBufferCursor(Int32 pos);
void SetBufferCursor(int32_t pos);
/* --------------------------------------------------------------------------------------------
* Write a 8bit byte to the stream buffer.
@@ -1003,7 +1004,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the total capacity of the buffer stream in bytes.
*/
Uint32 GetBufferCapacity() const;
SQMOD_NODISCARD uint32_t GetBufferCapacity() const;
/* --------------------------------------------------------------------------------------------
* Send the specified buffer contents to the managed player entity.
@@ -1013,62 +1014,62 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed player entity.
*/
Float32 GetPositionX() const;
SQMOD_NODISCARD float GetPositionX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed player entity.
*/
Float32 GetPositionY() const;
SQMOD_NODISCARD float GetPositionY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed player entity.
*/
Float32 GetPositionZ() const;
SQMOD_NODISCARD float GetPositionZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed player entity.
*/
void SetPositionX(Float32 x) const;
void SetPositionX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed player entity.
*/
void SetPositionY(Float32 y) const;
void SetPositionY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed player entity.
*/
void SetPositionZ(Float32 z) const;
void SetPositionZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the red color of the managed player entity.
*/
Int32 GetColorR() const;
SQMOD_NODISCARD int32_t GetColorR() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the green color of the managed player entity.
*/
Int32 GetColorG() const;
SQMOD_NODISCARD int32_t GetColorG() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the blue color of the managed player entity.
*/
Int32 GetColorB() const;
SQMOD_NODISCARD int32_t GetColorB() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the red color of the managed player entity.
*/
void SetColorR(Int32 r) const;
void SetColorR(int32_t r) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the green color of the managed player entity.
*/
void SetColorG(Int32 g) const;
void SetColorG(int32_t g) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the blue color of the managed player entity.
*/
void SetColorB(Int32 b) const;
void SetColorB(int32_t b) const;
/* --------------------------------------------------------------------------------------------
* Send a formatted colored message to the managed player entity.
+210 -230
View File
File diff suppressed because it is too large Load Diff
+141 -140
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -28,13 +28,14 @@ class CVehicle
{
// --------------------------------------------------------------------------------------------
friend class Core;
friend class VehicleInst;
private:
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
int32_t m_ID;
/* --------------------------------------------------------------------------------------------
* User tag associated with this instance.
@@ -49,19 +50,19 @@ private:
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
*/
Uint32 m_CircularLocks;
uint32_t m_CircularLocks;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
explicit CVehicle(Int32 id);
explicit CVehicle(int32_t id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
static const int32_t Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
@@ -97,7 +98,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const;
SQMOD_NODISCARD const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
@@ -107,12 +108,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static LightObj & GetNull();
SQMOD_NODISCARD static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const
SQMOD_NODISCARD int32_t GetID() const
{
return m_ID;
}
@@ -120,7 +121,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const
SQMOD_NODISCARD bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
@@ -128,7 +129,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
const String & GetTag() const;
SQMOD_NODISCARD const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@@ -143,7 +144,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
LightObj & GetData();
SQMOD_NODISCARD LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
@@ -153,7 +154,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed vehicle entity.
*/
bool Destroy()
bool Destroy0() const // NOLINT(modernize-use-nodiscard)
{
return Destroy(0, NullLightObj());
}
@@ -161,7 +162,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed vehicle entity.
*/
bool Destroy(Int32 header)
bool Destroy1(int32_t header) const // NOLINT(modernize-use-nodiscard)
{
return Destroy(header, NullLightObj());
}
@@ -169,17 +170,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Destroy the managed vehicle entity.
*/
bool Destroy(Int32 header, LightObj & payload);
bool Destroy(int32_t header, LightObj & payload) const; // NOLINT(modernize-use-nodiscard)
/* --------------------------------------------------------------------------------------------
* Retrieve the events table of this entity.
*/
LightObj & GetEvents() const;
SQMOD_NODISCARD LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, LightObj & payload) const;
void CustomEvent(int32_t header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See if the managed vehicle entity is streamed for the specified player.
@@ -189,57 +190,57 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current option value of the managed vehicle entity.
*/
bool GetOption(Int32 option_id) const;
SQMOD_NODISCARD bool GetOption(int32_t option_id) const;
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed vehicle entity.
*/
void SetOption(Int32 option_id, bool toggle);
void SetOption(int32_t option_id, bool toggle);
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed vehicle entity.
*/
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload);
void SetOptionEx(int32_t option_id, bool toggle, int32_t header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Retrieve the synchronization source of the managed vehicle entity.
*/
Int32 GetSyncSource() const;
SQMOD_NODISCARD int32_t GetSyncSource() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the synchronization type of the managed vehicle entity.
*/
Int32 GetSyncType() const;
SQMOD_NODISCARD int32_t GetSyncType() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed vehicle entity exists.
*/
Int32 GetWorld() const;
SQMOD_NODISCARD int32_t GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed vehicle entity exists.
*/
void SetWorld(Int32 world);
void SetWorld(int32_t world);
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle model of the managed vehicle entity.
*/
Int32 GetModel() const;
SQMOD_NODISCARD int32_t GetModel() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the slot occupant from the managed vehicle entity.
*/
LightObj & GetOccupant(Int32 slot) const;
SQMOD_NODISCARD LightObj & GetOccupant(int32_t slot) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the slot occupant identifier from the managed vehicle entity.
*/
Int32 GetOccupantID(Int32 slot) const;
SQMOD_NODISCARD int32_t GetOccupantID(int32_t slot) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity has an occupant in a certain slot.
*/
bool HasOccupant(Int32 slot) const;
SQMOD_NODISCARD bool HasOccupant(int32_t slot) const;
/* --------------------------------------------------------------------------------------------
* Respawn the managed vehicle entity.
@@ -249,12 +250,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the immunity flags of the managed vehicle entity.
*/
Int32 GetImmunity() const;
SQMOD_NODISCARD int32_t GetImmunity() const;
/* --------------------------------------------------------------------------------------------
* Modify the immunity flags of the managed vehicle entity.
*/
void SetImmunity(Int32 flags);
void SetImmunity(int32_t flags);
/* --------------------------------------------------------------------------------------------
* Explode the managed vehicle entity.
@@ -264,12 +265,12 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity is wrecked.
*/
bool IsWrecked() const;
SQMOD_NODISCARD bool IsWrecked() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed vehicle entity.
*/
Vector3 GetPosition() const;
SQMOD_NODISCARD Vector3 GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed vehicle entity.
@@ -279,22 +280,22 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed vehicle entity.
*/
void SetPositionEx(const Vector3 & pos, bool empty) const;
void SetPositionB(const Vector3 & pos, bool empty) const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed vehicle entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
void SetPositionEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed vehicle entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z, bool empty) const;
void SetPositionExB(float x, float y, float z, bool empty) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation of the managed vehicle entity.
*/
Quaternion GetRotation() const;
SQMOD_NODISCARD Quaternion GetRotation() const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation of the managed vehicle entity.
@@ -304,12 +305,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the rotation of the managed vehicle entity.
*/
void SetRotationEx(Float32 x, Float32 y, Float32 z, Float32 w) const;
void SetRotationEx(float x, float y, float z, float w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation of the managed vehicle entity.
*/
Vector3 GetRotationEuler() const;
SQMOD_NODISCARD Vector3 GetRotationEuler() const;
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation of the managed vehicle entity.
@@ -319,12 +320,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation of the managed vehicle entity.
*/
void SetRotationEulerEx(Float32 x, Float32 y, Float32 z) const;
void SetRotationEulerEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the speed of the managed vehicle entity.
*/
Vector3 GetSpeed() const;
SQMOD_NODISCARD Vector3 GetSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed vehicle entity.
@@ -334,7 +335,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed vehicle entity.
*/
void SetSpeedEx(Float32 x, Float32 y, Float32 z) const;
void SetSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed vehicle entity.
@@ -344,12 +345,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed vehicle entity.
*/
void AddSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative speed of the managed vehicle entity.
*/
Vector3 GetRelativeSpeed() const;
SQMOD_NODISCARD Vector3 GetRelativeSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the relative speed of the managed vehicle entity.
@@ -359,7 +360,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the relative speed of the managed vehicle entity.
*/
void SetRelativeSpeedEx(Float32 x, Float32 y, Float32 z) const;
void SetRelativeSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative speed of the managed vehicle entity.
@@ -369,12 +370,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the relative speed of the managed vehicle entity.
*/
void AddRelativeSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddRelativeSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the turn speed of the managed vehicle entity.
*/
Vector3 GetTurnSpeed() const;
SQMOD_NODISCARD Vector3 GetTurnSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the turn speed of the managed vehicle entity.
@@ -384,7 +385,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the turn speed of the managed vehicle entity.
*/
void SetTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
void SetTurnSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the turn speed of the managed vehicle entity.
@@ -394,12 +395,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the turn speed of the managed vehicle entity.
*/
void AddTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddTurnSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative turn speed of the managed vehicle entity.
*/
Vector3 GetRelativeTurnSpeed() const;
SQMOD_NODISCARD Vector3 GetRelativeTurnSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the relative turn speed of the managed vehicle entity.
@@ -409,7 +410,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the relative turn speed of the managed vehicle entity.
*/
void SetRelativeTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
void SetRelativeTurnSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative turn speed of the managed vehicle entity.
@@ -419,12 +420,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the relative turn speed of the managed vehicle entity.
*/
void AddRelativeTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddRelativeTurnSpeedEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the spawn position of the managed vehicle entity.
*/
Vector3 GetSpawnPosition() const;
SQMOD_NODISCARD Vector3 GetSpawnPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the spawn position of the managed vehicle entity.
@@ -434,12 +435,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the spawn position of the managed vehicle entity.
*/
void SetSpawnPositionEx(Float32 x, Float32 y, Float32 z) const;
void SetSpawnPositionEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the spawn rotation of the managed vehicle entity.
*/
Quaternion GetSpawnRotation() const;
SQMOD_NODISCARD Quaternion GetSpawnRotation() const;
/* --------------------------------------------------------------------------------------------
* Modify the spawn rotation of the managed vehicle entity.
@@ -449,12 +450,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the spawn rotation of the managed vehicle entity.
*/
void SetSpawnRotationEx(Float32 x, Float32 y, Float32 z, Float32 w) const;
void SetSpawnRotationEx(float x, float y, float z, float w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler spawn rotation of the managed vehicle entity.
*/
Vector3 GetSpawnRotationEuler() const;
SQMOD_NODISCARD Vector3 GetSpawnRotationEuler() const;
/* --------------------------------------------------------------------------------------------
* Modify the euler spawn rotation of the managed vehicle entity.
@@ -464,27 +465,27 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the euler spawn rotation of the managed vehicle entity.
*/
void SetSpawnRotationEulerEx(Float32 x, Float32 y, Float32 z) const;
void SetSpawnRotationEulerEx(float x, float y, float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the respawn timer of the managed vehicle entity.
*/
Uint32 GetIdleRespawnTimer() const;
SQMOD_NODISCARD uint32_t GetIdleRespawnTimer() const;
/* --------------------------------------------------------------------------------------------
* Modify the respawn timer of the managed vehicle entity.
*/
void SetIdleRespawnTimer(Uint32 millis) const;
void SetIdleRespawnTimer(uint32_t millis) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the health of the managed vehicle entity.
*/
Float32 GetHealth() const;
SQMOD_NODISCARD float GetHealth() const;
/* --------------------------------------------------------------------------------------------
* Modify the health of the managed vehicle entity.
*/
void SetHealth(Float32 amount) const;
void SetHealth(float amount) const;
/* --------------------------------------------------------------------------------------------
* Fix the damage and restore health for the managed vehicle entity.
@@ -494,102 +495,102 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the primary color of the managed vehicle entity.
*/
Int32 GetPrimaryColor() const;
SQMOD_NODISCARD int32_t GetPrimaryColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the primary color of the managed vehicle entity.
*/
void SetPrimaryColor(Int32 col) const;
void SetPrimaryColor(int32_t col) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the secondary color of the managed vehicle entity.
*/
Int32 GetSecondaryColor() const;
SQMOD_NODISCARD int32_t GetSecondaryColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the secondary color of the managed vehicle entity.
*/
void SetSecondaryColor(Int32 col) const;
void SetSecondaryColor(int32_t col) const;
/* --------------------------------------------------------------------------------------------
* Modify the primary and secondary colors of the managed vehicle entity.
*/
void SetColors(Int32 primary, Int32 secondary) const;
void SetColors(int32_t primary, int32_t secondary) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the part status of the managed vehicle entity.
*/
Int32 GetPartStatus(Int32 part) const;
SQMOD_NODISCARD int32_t GetPartStatus(int32_t part) const;
/* --------------------------------------------------------------------------------------------
* Modify the part status of the managed vehicle entity.
*/
void SetPartStatus(Int32 part, Int32 status);
void SetPartStatus(int32_t part, int32_t status);
/* --------------------------------------------------------------------------------------------
* Retrieve the tyre status of the managed vehicle entity.
*/
Int32 GetTyreStatus(Int32 tyre) const;
SQMOD_NODISCARD int32_t GetTyreStatus(int32_t tyre) const;
/* --------------------------------------------------------------------------------------------
* Modify the tyre status of the managed vehicle entity.
*/
void SetTyreStatus(Int32 tyre, Int32 status);
void SetTyreStatus(int32_t tyre, int32_t status);
/* --------------------------------------------------------------------------------------------
* Retrieve the damage data of the managed vehicle entity.
*/
Uint32 GetDamageData() const;
SQMOD_NODISCARD uint32_t GetDamageData() const;
/* --------------------------------------------------------------------------------------------
* Modify the damage data of the managed vehicle entity.
*/
void SetDamageData(Uint32 data);
void SetDamageData(uint32_t data);
/* --------------------------------------------------------------------------------------------
* Retrieve the radio of the managed vehicle entity.
*/
Int32 GetRadio() const;
SQMOD_NODISCARD int32_t GetRadio() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radio of the managed vehicle entity.
*/
void SetRadio(Int32 radio);
void SetRadio(int32_t radio);
/* --------------------------------------------------------------------------------------------
* Retrieve the turret rotation of the managed vehicle entity.
*/
Vector2 GetTurretRotation() const;
SQMOD_NODISCARD Vector2 GetTurretRotation() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the horizontal turret rotation of the managed vehicle entity.
*/
Float32 GetHorizontalTurretRotation() const;
SQMOD_NODISCARD float GetHorizontalTurretRotation() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vertical turret rotation of the managed vehicle entity.
*/
Float32 GetVerticalTurretRotation() const;
SQMOD_NODISCARD float GetVerticalTurretRotation() const;
/* --------------------------------------------------------------------------------------------
* See whether the specified handling ruleexists in the managed vehicle entity.
* See whether the specified handling rule exists in the managed vehicle entity.
*/
bool ExistsHandlingRule(Int32 rule) const;
SQMOD_NODISCARD bool ExistsHandlingRule(int32_t rule) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the handling data of the managed vehicle entity.
*/
SQFloat GetHandlingRule(Int32 rule) const;
SQMOD_NODISCARD SQFloat GetHandlingRule(int32_t rule) const;
/* --------------------------------------------------------------------------------------------
* Modify the handling data of the managed vehicle entity.
*/
void SetHandlingRule(Int32 rule, Float32 data);
void SetHandlingRule(int32_t rule, float data);
/* --------------------------------------------------------------------------------------------
* Reset the specified handling rule for the managed vehicle entity.
*/
void ResetHandlingRule(Int32 rule);
void ResetHandlingRule(int32_t rule);
/* --------------------------------------------------------------------------------------------
* Reset all the handling rules for the managed vehicle entity.
@@ -599,12 +600,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the lights data for the managed vehicle entity.
*/
Int32 GetLightsData() const;
SQMOD_NODISCARD int32_t GetLightsData() const;
/* --------------------------------------------------------------------------------------------
* Modify the lights data for the managed vehicle entity.
*/
void SetLightsData(Int32 data) const;
void SetLightsData(int32_t data) const;
/* --------------------------------------------------------------------------------------------
* Embark the specified player entity into the managed vehicle entity.
@@ -614,7 +615,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Embark the specified player entity into the managed vehicle entity.
*/
bool Embark(CPlayer & player, Int32 slot, bool allocate, bool warp) const;
bool EmbarkEx(CPlayer & player, int32_t slot, bool allocate, bool warp) const;
#if SQMOD_SDK_LEAST(2, 1)
/* --------------------------------------------------------------------------------------------
* Set whether the target player will see an objective arrow over a vehicle.
@@ -624,7 +625,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the target player sees an objective arrow over a vehicle.
*/
bool GetPlayer3DArrow(CPlayer & target) const;
SQMOD_NODISCARD bool GetPlayer3DArrow(CPlayer & target) const;
/* --------------------------------------------------------------------------------------------
* Set whether the target player will see an objective arrow over a vehicle.
@@ -634,12 +635,12 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the target player sees an objective arrow over a vehicle.
*/
bool GetPlayer3DArrowID(SQInteger id) const;
SQMOD_NODISCARD bool GetPlayer3DArrowID(SQInteger id) const;
#endif
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity collides with user defined areas.
*/
bool GetCollideAreas() const;
SQMOD_NODISCARD bool GetCollideAreas() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed vehicle entity can collide with user defined areas.
@@ -654,7 +655,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of tracked position changes for the managed vehicle entity.
*/
SQInteger GetTrackPosition() const;
SQMOD_NODISCARD SQInteger GetTrackPosition() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of tracked position changes for the managed vehicle entity.
@@ -664,7 +665,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of tracked rotation changes for the managed vehicle entity.
*/
SQInteger GetTrackRotation() const;
SQMOD_NODISCARD SQInteger GetTrackRotation() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of tracked rotation changes for the managed vehicle entity.
@@ -674,32 +675,32 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the last known primary color for the managed vehicle entity.
*/
Int32 GetLastPrimaryColor() const;
SQMOD_NODISCARD int32_t GetLastPrimaryColor() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the last known secondary color for the managed vehicle entity.
*/
Int32 GetLastSecondaryColor() const;
SQMOD_NODISCARD int32_t GetLastSecondaryColor() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the last known health for the managed vehicle entity.
*/
Float32 GetLastHealth() const;
SQMOD_NODISCARD float GetLastHealth() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the last known position for the managed vehicle entity.
*/
const Vector3 & GetLastPosition() const;
SQMOD_NODISCARD const Vector3 & GetLastPosition() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the last known rotation for the managed vehicle entity.
*/
const Quaternion & GetLastRotation() const;
SQMOD_NODISCARD const Quaternion & GetLastRotation() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the distance traveled by the managed vehicle entity while tracking was enabled.
*/
SQFloat GetDistance() const;
SQMOD_NODISCARD SQFloat GetDistance() const;
/* --------------------------------------------------------------------------------------------
* Modify the distance traveled by the managed vehicle entity.
@@ -709,7 +710,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check whether distance tracking is enabled for the managed vehicle entity.
*/
bool GetTrackDistance() const;
SQMOD_NODISCARD bool GetTrackDistance() const;
/* --------------------------------------------------------------------------------------------
* Set whether distance tracking is enabled for the managed vehicle entity.
@@ -719,222 +720,222 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed vehicle entity.
*/
Float32 GetPositionX() const;
SQMOD_NODISCARD float GetPositionX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed vehicle entity.
*/
Float32 GetPositionY() const;
SQMOD_NODISCARD float GetPositionY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed vehicle entity.
*/
Float32 GetPositionZ() const;
SQMOD_NODISCARD float GetPositionZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed vehicle entity.
*/
void SetPositionX(Float32 x) const;
void SetPositionX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed vehicle entity.
*/
void SetPositionY(Float32 y) const;
void SetPositionY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed vehicle entity.
*/
void SetPositionZ(Float32 z) const;
void SetPositionZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the x axis of the managed vehicle entity.
*/
Float32 GetRotationX() const;
SQMOD_NODISCARD float GetRotationX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the y axis of the managed vehicle entity.
*/
Float32 GetRotationY() const;
SQMOD_NODISCARD float GetRotationY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the z axis of the managed vehicle entity.
*/
Float32 GetRotationZ() const;
SQMOD_NODISCARD float GetRotationZ() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation amount of the managed vehicle entity.
*/
Float32 GetRotationW() const;
SQMOD_NODISCARD float GetRotationW() const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the x axis of the managed vehicle entity.
*/
void SetRotationX(Float32 x) const;
void SetRotationX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the y axis of the managed vehicle entity.
*/
void SetRotationY(Float32 y) const;
void SetRotationY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the z axis of the managed vehicle entity.
*/
void SetRotationZ(Float32 z) const;
void SetRotationZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation amount of the managed vehicle entity.
*/
void SetRotationW(Float32 w) const;
void SetRotationW(float w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation on the x axis of the managed vehicle entity.
*/
Float32 GetEulerRotationX() const;
SQMOD_NODISCARD float GetEulerRotationX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation on the y axis of the managed vehicle entity.
*/
Float32 GetEulerRotationY() const;
SQMOD_NODISCARD float GetEulerRotationY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation on the z axis of the managed vehicle entity.
*/
Float32 GetEulerRotationZ() const;
SQMOD_NODISCARD float GetEulerRotationZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation on the x axis of the managed vehicle entity.
*/
void SetEulerRotationX(Float32 x) const;
void SetEulerRotationX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation on the y axis of the managed vehicle entity.
*/
void SetEulerRotationY(Float32 y) const;
void SetEulerRotationY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation on the z axis of the managed vehicle entity.
*/
void SetEulerRotationZ(Float32 z) const;
void SetEulerRotationZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the velocity on the x axis of the managed vehicle entity.
*/
Float32 GetSpeedX() const;
SQMOD_NODISCARD float GetSpeedX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the velocity on the y axis of the managed vehicle entity.
*/
Float32 GetSpeedY() const;
SQMOD_NODISCARD float GetSpeedY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the velocity on the z axis of the managed vehicle entity.
*/
Float32 GetSpeedZ() const;
SQMOD_NODISCARD float GetSpeedZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the velocity on the x axis of the managed vehicle entity.
*/
void SetSpeedX(Float32 x) const;
void SetSpeedX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the velocity on the y axis of the managed vehicle entity.
*/
void SetSpeedY(Float32 y) const;
void SetSpeedY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the velocity on the z axis of the managed vehicle entity.
*/
void SetSpeedZ(Float32 z) const;
void SetSpeedZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative velocity on the x axis of the managed vehicle entity.
*/
Float32 GetRelativeSpeedX() const;
SQMOD_NODISCARD float GetRelativeSpeedX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative velocity on the y axis of the managed vehicle entity.
*/
Float32 GetRelativeSpeedY() const;
SQMOD_NODISCARD float GetRelativeSpeedY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative velocity on the z axis of the managed vehicle entity.
*/
Float32 GetRelativeSpeedZ() const;
SQMOD_NODISCARD float GetRelativeSpeedZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the relative velocity on the x axis of the managed vehicle entity.
*/
void SetRelativeSpeedX(Float32 x) const;
void SetRelativeSpeedX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative velocity on the y axis of the managed vehicle entity.
*/
void SetRelativeSpeedY(Float32 y) const;
void SetRelativeSpeedY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative velocity on the z axis of the managed vehicle entity.
*/
void SetRelativeSpeedZ(Float32 z) const;
void SetRelativeSpeedZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the turn velocity on the x axis of the managed vehicle entity.
*/
Float32 GetTurnSpeedX() const;
SQMOD_NODISCARD float GetTurnSpeedX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the turn velocity on the y axis of the managed vehicle entity.
*/
Float32 GetTurnSpeedY() const;
SQMOD_NODISCARD float GetTurnSpeedY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the turn velocity on the z axis of the managed vehicle entity.
*/
Float32 GetTurnSpeedZ() const;
SQMOD_NODISCARD float GetTurnSpeedZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the turn velocity on the x axis of the managed vehicle entity.
*/
void SetTurnSpeedX(Float32 x) const;
void SetTurnSpeedX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the turn velocity on the y axis of the managed vehicle entity.
*/
void SetTurnSpeedY(Float32 y) const;
void SetTurnSpeedY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the turn velocity on the z axis of the managed vehicle entity.
*/
void SetTurnSpeedZ(Float32 z) const;
void SetTurnSpeedZ(float z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative turn velocity on the x axis of the managed vehicle entity.
*/
Float32 GetRelativeTurnSpeedX() const;
SQMOD_NODISCARD float GetRelativeTurnSpeedX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative turn velocity on the y axis of the managed vehicle entity.
*/
Float32 GetRelativeTurnSpeedY() const;
SQMOD_NODISCARD float GetRelativeTurnSpeedY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative turn velocity on the z axis of the managed vehicle entity.
*/
Float32 GetRelativeTurnSpeedZ() const;
SQMOD_NODISCARD float GetRelativeTurnSpeedZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the relative turn velocity on the x axis of the managed vehicle entity.
*/
void SetRelativeTurnSpeedX(Float32 x) const;
void SetRelativeTurnSpeedX(float x) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative turn velocity on the y axis of the managed vehicle entity.
*/
void SetRelativeTurnSpeedY(Float32 y) const;
void SetRelativeTurnSpeedY(float y) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative turn velocity on the z axis of the managed vehicle entity.
*/
void SetRelativeTurnSpeedZ(Float32 z) const;
void SetRelativeTurnSpeedZ(float z) const;
};
} // Namespace:: SqMod
+12 -9
View File
@@ -1,19 +1,22 @@
// ------------------------------------------------------------------------------------------------
#include "Library/CURL.hpp"
// ------------------------------------------------------------------------------------------------
#include <sqratConst.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(SqCpSslOptions, _SC("SqCprSslOptions"))
SQMODE_DECL_TYPENAME(SqCpError, _SC("SqCpError"))
SQMODE_DECL_TYPENAME(SqCpCookies, _SC("SqCprCookies"))
SQMODE_DECL_TYPENAME(SqCpHeader, _SC("SqCprHeader"))
SQMODE_DECL_TYPENAME(SqCpResponse, _SC("SqCprResponse"))
SQMODE_DECL_TYPENAME(SqCpParameters, _SC("SqCprParameters"))
SQMODE_DECL_TYPENAME(SqCpPayload, _SC("SqCprPayload"))
SQMODE_DECL_TYPENAME(SqCpProxies, _SC("SqCprProxies"))
SQMODE_DECL_TYPENAME(SqCpSession, _SC("SqCprSession"))
SQMOD_DECL_TYPENAME(SqCpSslOptions, _SC("SqCprSslOptions"))
SQMOD_DECL_TYPENAME(SqCpError, _SC("SqCpError"))
SQMOD_DECL_TYPENAME(SqCpCookies, _SC("SqCprCookies"))
SQMOD_DECL_TYPENAME(SqCpHeader, _SC("SqCprHeader"))
SQMOD_DECL_TYPENAME(SqCpResponse, _SC("SqCprResponse"))
SQMOD_DECL_TYPENAME(SqCpParameters, _SC("SqCprParameters"))
SQMOD_DECL_TYPENAME(SqCpPayload, _SC("SqCprPayload"))
SQMOD_DECL_TYPENAME(SqCpProxies, _SC("SqCprProxies"))
SQMOD_DECL_TYPENAME(SqCpSession, _SC("SqCprSession"))
// ------------------------------------------------------------------------------------------------
static const EnumElement g_ErrorCodes[] = {
+79 -79
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <cpr/cpr.h>
@@ -48,7 +48,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::cert_file value.
*/
const std::string & GetCertFile() const { return Base::cert_file; }
SQMOD_NODISCARD const std::string & GetCertFile() const { return Base::cert_file; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::cert_file and cpr::SslOptions::cert_type values.
@@ -80,7 +80,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::cert_type value.
*/
const std::string & GetCertType() const { return Base::cert_type; }
SQMOD_NODISCARD const std::string & GetCertType() const { return Base::cert_type; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::cert_type values.
@@ -90,7 +90,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::key_file value.
*/
const std::string & GetKeyFile() const { return Base::key_file; }
SQMOD_NODISCARD const std::string & GetKeyFile() const { return Base::key_file; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::cert_file, cpr::SslOptions::key_pass and cpr::SslOptions::cert_type values.
@@ -126,7 +126,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::key_type value.
*/
const std::string & GetKeyType() const { return Base::key_type; }
SQMOD_NODISCARD const std::string & GetKeyType() const { return Base::key_type; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::key_type values.
@@ -136,7 +136,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::key_pass value.
*/
const std::string & GetKeyPass() const { return Base::key_pass; }
SQMOD_NODISCARD const std::string & GetKeyPass() const { return Base::key_pass; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::key_pass values.
@@ -147,36 +147,36 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::enable_alpn value.
*/
bool GetALPN() const { return Base::enable_alpn; }
SQMOD_NODISCARD bool GetALPN() const { return Base::enable_alpn; }
/* --------------------------------------------------------------------------------------------
* Modify cpr::SslOptions::enable_alpn value.
*/
void SetALPN(bool value) { Base::enable_alpn = value; }
#else
void GetALPN() const { STHROWF("Unsupported"); }
void SetALPN(bool) { STHROWF("Unsupported"); }
void GetALPN() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
void SetALPN(bool) { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif // SUPPORT_ALPN
#if SUPPORT_NPN
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::enable_npn value.
*/
bool GetNPM() const { return Base::enable_npn; }
SQMOD_NODISCARD bool GetNPM() const { return Base::enable_npn; }
/* --------------------------------------------------------------------------------------------
* Modify cpr::SslOptions::enable_npn value.
*/
void SetNPM(bool value) { Base::enable_npn = value; }
#else
void GetNPM() const { STHROWF("Unsupported"); }
void SetNPM(bool) { STHROWF("Unsupported"); }
void GetNPM() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
void SetNPM(bool) { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif // SUPPORT_NPN
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::verify_host value.
*/
bool GetVerifyHost() const { return Base::verify_host; }
SQMOD_NODISCARD bool GetVerifyHost() const { return Base::verify_host; }
/* --------------------------------------------------------------------------------------------
* Modify cpr::SslOptions::verify_host value.
@@ -186,7 +186,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::verify_peer value.
*/
bool GetVerifyPeer() const { return Base::verify_peer; }
SQMOD_NODISCARD bool GetVerifyPeer() const { return Base::verify_peer; }
/* --------------------------------------------------------------------------------------------
* Modify cpr::SslOptions::verify_peer value.
@@ -196,7 +196,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::verify_status value.
*/
bool GetVerifyStatus() const { return Base::verify_status; }
SQMOD_NODISCARD bool GetVerifyStatus() const { return Base::verify_status; }
/* --------------------------------------------------------------------------------------------
* Modify cpr::SslOptions::verify_status value.
@@ -206,21 +206,21 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::ssl_version value.
*/
int GetSslVersion() const { return Base::ssl_version; }
SQMOD_NODISCARD int GetSslVersion() const { return Base::ssl_version; }
#if SUPPORT_MAX_TLS_VERSION
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::max_version value.
*/
int GetMaxVersion() const { return Base::max_version; }
SQMOD_NODISCARD int GetMaxVersion() const { return Base::max_version; }
#else
void GetMaxVersion() const { STHROWF("Unsupported"); }
void GetMaxVersion() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif // SUPPORT_MAX_TLS_VERSION
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::ca_info value.
*/
const std::string & GetCaInfo() const { return Base::ca_info; }
SQMOD_NODISCARD const std::string & GetCaInfo() const { return Base::ca_info; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::ca_info values.
@@ -230,7 +230,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::ca_path value.
*/
const std::string & GetCaPath() const { return Base::ca_path; }
SQMOD_NODISCARD const std::string & GetCaPath() const { return Base::ca_path; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::ca_path values.
@@ -240,7 +240,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::crl_file value.
*/
const std::string & GetCrlFile() const { return Base::crl_file; }
SQMOD_NODISCARD const std::string & GetCrlFile() const { return Base::crl_file; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::crl_file values.
@@ -250,7 +250,7 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::ciphers value.
*/
const std::string & GetCiphers() const { return Base::ciphers; }
SQMOD_NODISCARD const std::string & GetCiphers() const { return Base::ciphers; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::ciphers values.
@@ -261,30 +261,30 @@ struct CpSslOptions : public cpr::SslOptions
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::tls13_ciphers value.
*/
const std::string & GetTLS13Ciphers() const { return Base::tls13_ciphers; }
SQMOD_NODISCARD const std::string & GetTLS13Ciphers() const { return Base::tls13_ciphers; }
/* --------------------------------------------------------------------------------------------
* Assign cpr::SslOptions::tls13_ciphers values.
*/
void SetTLS13Ciphers(StackStrF & cph) { tls13_ciphers.assign(cph.mPtr, cph.GetSize()); }
#else
void GetTLS13Ciphers() const { STHROWF("Unsupported"); }
void SetTLS13Ciphers(StackStrF &) const { STHROWF("Unsupported"); }
void GetTLS13Ciphers() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
void SetTLS13Ciphers(StackStrF &) const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif // SUPPORT_TLSv13_CIPHERS
#if SUPPORT_SESSIONID_CACHE
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::SslOptions::session_id_cache value.
*/
bool GetSessionIdCache() const { return Base::session_id_cache; }
SQMOD_NODISCARD bool GetSessionIdCache() const { return Base::session_id_cache; }
/* --------------------------------------------------------------------------------------------
* Modify cpr::SslOptions::session_id_cache value.
*/
void SetSessionIdCache(bool value) { Base::session_id_cache = value; }
#else
void GetSessionIdCache() const { STHROWF("Unsupported"); }
void SetSessionIdCache(bool) const { STHROWF("Unsupported"); }
void GetSessionIdCache() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
void SetSessionIdCache(bool) const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif // SUPPORT_SESSIONID_CACHE
/* --------------------------------------------------------------------------------------------
@@ -298,7 +298,7 @@ struct CpSslOptions : public cpr::SslOptions
*/
void SetSSLv2() { ssl_version = CURL_SSLVERSION_SSLv2; }
#else
void SetSSLv2() const { STHROWF("Unsupported"); }
void SetSSLv2() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
* Modify cpr::SslOptions::ssl_version value.
@@ -306,7 +306,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_SSLv3
void SetSSLv3() { ssl_version = CURL_SSLVERSION_SSLv3; }
#else
void SetSSLv3() const { STHROWF("Unsupported"); }
void SetSSLv3() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
@@ -315,7 +315,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_TLSv1_0
void SetTLSv1_0() { ssl_version = CURL_SSLVERSION_TLSv1_0; }
#else
void SetTLSv1_0() const { STHROWF("Unsupported"); }
void SetTLSv1_0() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
@@ -324,7 +324,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_TLSv1_1
void SetTLSv1_1() { ssl_version = CURL_SSLVERSION_TLSv1_1; }
#else
void SetTLSv1_1() const { STHROWF("Unsupported"); }
void SetTLSv1_1() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
@@ -333,7 +333,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_TLSv1_2
void SetTLSv1_2() { ssl_version = CURL_SSLVERSION_TLSv1_2; }
#else
void SetTLSv1_2() const { STHROWF("Unsupported"); }
void SetTLSv1_2() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
@@ -342,7 +342,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_TLSv1_3
void SetTLSv1_3() { ssl_version = CURL_SSLVERSION_TLSv1_3; }
#else
void SetTLSv1_3() const { STHROWF("Unsupported"); }
void SetTLSv1_3() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
@@ -351,7 +351,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_MAX_TLS_VERSION
void SetMaxTLSVersion() { max_version = CURL_SSLVERSION_DEFAULT; }
#else
void SetMaxTLSVersion() const { STHROWF("Unsupported"); }
void SetMaxTLSVersion() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
@@ -360,7 +360,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_MAX_TLSv1_0
void SetMaxTLSv1_0() { max_version = CURL_SSLVERSION_MAX_TLSv1_0; }
#else
void SetMaxTLSv1_0() const { STHROWF("Unsupported"); }
void SetMaxTLSv1_0() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
@@ -369,7 +369,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_MAX_TLSv1_1
void SetMaxTLSv1_1() { max_version = CURL_SSLVERSION_MAX_TLSv1_1; }
#else
void SetMaxTLSv1_1() const { STHROWF("Unsupported"); }
void SetMaxTLSv1_1() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
@@ -378,7 +378,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_MAX_TLSv1_2
void SetMaxTLSv1_2() { max_version = CURL_SSLVERSION_MAX_TLSv1_2; }
#else
void SetMaxTLSv1_2() const { STHROWF("Unsupported"); }
void SetMaxTLSv1_2() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
/* --------------------------------------------------------------------------------------------
@@ -387,7 +387,7 @@ struct CpSslOptions : public cpr::SslOptions
#if SUPPORT_MAX_TLSv1_3
void SetMaxTLSv1_3() { max_version = CURL_SSLVERSION_MAX_TLSv1_3; }
#else
void SetMaxTLSv1_3() const { STHROWF("Unsupported"); }
void SetMaxTLSv1_3() const { STHROWF("Unsupported"); } // NOLINT(readability-convert-member-functions-to-static)
#endif
};
@@ -448,7 +448,7 @@ struct CpError : public cpr::Error
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Error::code.
*/
SQInteger GetCode() const
SQMOD_NODISCARD SQInteger GetCode() const
{
return static_cast< SQInteger >(cpr::Error::code);
}
@@ -464,7 +464,7 @@ struct CpError : public cpr::Error
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Error::text.
*/
const std::string & GetMessage() const
SQMOD_NODISCARD const std::string & GetMessage() const
{
return cpr::Error::message;
}
@@ -532,7 +532,7 @@ struct CpCookies : public cpr::Cookies
/* --------------------------------------------------------------------------------------------
* Retrieve the number of values.
*/
SQInteger Size() const
SQMOD_NODISCARD SQInteger Size() const
{
return static_cast< SQInteger >(cpr::Cookies::map_.size());
}
@@ -540,7 +540,7 @@ struct CpCookies : public cpr::Cookies
/* --------------------------------------------------------------------------------------------
* Check if no value is stored.
*/
bool Empty() const
SQMOD_NODISCARD bool Empty() const
{
return cpr::Cookies::map_.empty();
}
@@ -556,7 +556,7 @@ struct CpCookies : public cpr::Cookies
/* --------------------------------------------------------------------------------------------
* Retrieve the number of matching values.
*/
SQInteger Count(StackStrF & key) const
SQMOD_NODISCARD SQInteger Count(StackStrF & key) const
{
return static_cast< SQInteger >(cpr::Cookies::map_.count(key.ToStr()));
}
@@ -581,7 +581,7 @@ struct CpCookies : public cpr::Cookies
/* --------------------------------------------------------------------------------------------
* Check if value exists.
*/
bool Has(StackStrF & key) const
SQMOD_NODISCARD bool Has(StackStrF & key) const
{
return cpr::Cookies::map_.find(key.ToStr()) != cpr::Cookies::map_.end();
}
@@ -589,7 +589,7 @@ struct CpCookies : public cpr::Cookies
/* --------------------------------------------------------------------------------------------
* Retrieve value.
*/
std::string & Get(StackStrF & key)
SQMOD_NODISCARD std::string & Get(StackStrF & key)
{
auto itr = cpr::Cookies::map_.find(key.ToStr());
// Does it exist?
@@ -654,7 +654,7 @@ struct CpHeader
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
explicit CpHeader(const cpr::Header & e) : mMap(e) { }
explicit CpHeader(const cpr::Header & e) : mMap(e) { } // NOLINT(modernize-pass-by-value)
/* --------------------------------------------------------------------------------------------
* Move constructor.
@@ -699,7 +699,7 @@ struct CpHeader
/* --------------------------------------------------------------------------------------------
* Retrieve the number of values.
*/
SQInteger Size() const
SQMOD_NODISCARD SQInteger Size() const
{
return static_cast< SQInteger >(mMap.size());
}
@@ -707,7 +707,7 @@ struct CpHeader
/* --------------------------------------------------------------------------------------------
* Check if no value is stored.
*/
bool Empty() const
SQMOD_NODISCARD bool Empty() const
{
return mMap.empty();
}
@@ -723,7 +723,7 @@ struct CpHeader
/* --------------------------------------------------------------------------------------------
* Retrieve the number of matching values.
*/
SQInteger Count(StackStrF & key) const
SQMOD_NODISCARD SQInteger Count(StackStrF & key) const
{
return static_cast< SQInteger >(mMap.count(key.ToStr()));
}
@@ -748,7 +748,7 @@ struct CpHeader
/* --------------------------------------------------------------------------------------------
* Check if value exists.
*/
bool Has(StackStrF & key) const
SQMOD_NODISCARD bool Has(StackStrF & key) const
{
return mMap.find(key.ToStr()) != mMap.end();
}
@@ -756,7 +756,7 @@ struct CpHeader
/* --------------------------------------------------------------------------------------------
* Retrieve value.
*/
std::string & Get(StackStrF & key)
SQMOD_NODISCARD std::string & Get(StackStrF & key)
{
auto itr = mMap.find(key.ToStr());
// Does it exist?
@@ -852,7 +852,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve certificate information.
*/
Array GetCertInfoArray()
SQMOD_NODISCARD Array GetCertInfoArray()
{
if (!cpr::Response::curl_)
{
@@ -874,7 +874,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::status_code.
*/
SQInteger GetStatusCode() const
SQMOD_NODISCARD SQInteger GetStatusCode() const
{
return cpr::Response::status_code;
}
@@ -890,7 +890,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::text.
*/
const std::string & GetText() const
SQMOD_NODISCARD const std::string & GetText() const
{
return cpr::Response::text;
}
@@ -906,7 +906,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Steal values from cpr::Response::header.
*/
CpHeader StealHeader()
SQMOD_NODISCARD CpHeader StealHeader()
{
return CpHeader(std::move(cpr::Response::header));
}
@@ -914,7 +914,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::header.
*/
CpHeader GetHeader() const
SQMOD_NODISCARD CpHeader GetHeader() const
{
return CpHeader(cpr::Response::header);
}
@@ -938,7 +938,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::url.
*/
const std::string & GetURL() const
SQMOD_NODISCARD const std::string & GetURL() const
{
return cpr::Response::url.str();
}
@@ -954,7 +954,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Steal values from cpr::Response::cookies.
*/
CpCookies StealCookies()
SQMOD_NODISCARD CpCookies StealCookies()
{
return CpCookies(std::move(cpr::Response::cookies));
}
@@ -962,7 +962,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::cookies.
*/
CpCookies GetCookies() const
SQMOD_NODISCARD CpCookies GetCookies() const
{
return CpCookies(cpr::Response::cookies);
}
@@ -986,7 +986,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::url.
*/
CpError GetError() const
SQMOD_NODISCARD CpError GetError() const
{
return CpError(cpr::Response::error);
}
@@ -1002,7 +1002,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::raw_header.
*/
const std::string & GetRawHeader() const
SQMOD_NODISCARD const std::string & GetRawHeader() const
{
return cpr::Response::raw_header;
}
@@ -1018,7 +1018,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::status_line.
*/
const std::string & GetStatusLine() const
SQMOD_NODISCARD const std::string & GetStatusLine() const
{
return cpr::Response::status_line;
}
@@ -1034,7 +1034,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::reason.
*/
const std::string & GetReason() const
SQMOD_NODISCARD const std::string & GetReason() const
{
return cpr::Response::reason;
}
@@ -1050,7 +1050,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::uploaded_bytes.
*/
SQInteger GetUploadedBytes() const
SQMOD_NODISCARD SQInteger GetUploadedBytes() const
{
return static_cast< SQInteger >(cpr::Response::uploaded_bytes); // possible precision loss!
}
@@ -1066,7 +1066,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::downloaded_bytes.
*/
SQInteger GetDownloadedBytes() const
SQMOD_NODISCARD SQInteger GetDownloadedBytes() const
{
return static_cast< SQInteger >(cpr::Response::downloaded_bytes); // possible precision loss!
}
@@ -1082,7 +1082,7 @@ struct CpResponse : public cpr::Response
/* --------------------------------------------------------------------------------------------
* Retrieve cpr::Response::redirect_count.
*/
SQInteger GetRedirectCount() const
SQMOD_NODISCARD SQInteger GetRedirectCount() const
{
return cpr::Response::redirect_count;
}
@@ -1145,7 +1145,7 @@ struct CpParameters : public cpr::Parameters
/* --------------------------------------------------------------------------------------------
* Retrieve the number of values.
*/
SQInteger Size() const
SQMOD_NODISCARD SQInteger Size() const
{
return static_cast< SQInteger >(cpr::Parameters::containerList_.size());
}
@@ -1153,7 +1153,7 @@ struct CpParameters : public cpr::Parameters
/* --------------------------------------------------------------------------------------------
* Check if no value is stored.
*/
bool Empty() const
SQMOD_NODISCARD bool Empty() const
{
return cpr::Parameters::containerList_.empty();
}
@@ -1316,7 +1316,7 @@ struct CpPayload : public cpr::Payload
/* --------------------------------------------------------------------------------------------
* Retrieve the number of values.
*/
SQInteger Size() const
SQMOD_NODISCARD SQInteger Size() const
{
return static_cast< SQInteger >(cpr::Payload::containerList_.size());
}
@@ -1324,7 +1324,7 @@ struct CpPayload : public cpr::Payload
/* --------------------------------------------------------------------------------------------
* Check if no value is stored.
*/
bool Empty() const
SQMOD_NODISCARD bool Empty() const
{
return cpr::Payload::containerList_.empty();
}
@@ -1340,7 +1340,7 @@ struct CpPayload : public cpr::Payload
/* --------------------------------------------------------------------------------------------
* Retrieve the number of matching values.
*/
SQInteger Count(StackStrF & key) const
SQMOD_NODISCARD SQInteger Count(StackStrF & key) const
{
return static_cast< SQInteger >(std::count_if(
cpr::Payload::containerList_.begin(), cpr::Payload::containerList_.end(),
@@ -1364,7 +1364,7 @@ struct CpPayload : public cpr::Payload
/* --------------------------------------------------------------------------------------------
* Check if value exists.
*/
bool Has(StackStrF & key) const
SQMOD_NODISCARD bool Has(StackStrF & key) const
{
return std::find_if(
cpr::Payload::containerList_.begin(), cpr::Payload::containerList_.end(),
@@ -1375,7 +1375,7 @@ struct CpPayload : public cpr::Payload
/* --------------------------------------------------------------------------------------------
* Retrieve value.
*/
std::string & Get(StackStrF & key)
SQMOD_NODISCARD std::string & Get(StackStrF & key)
{
auto itr = std::find_if(
cpr::Payload::containerList_.begin(), cpr::Payload::containerList_.end(),
@@ -1495,7 +1495,7 @@ struct CpProxies : public cpr::Proxies
/* --------------------------------------------------------------------------------------------
* Retrieve the number of values.
*/
SQInteger Size() const
SQMOD_NODISCARD SQInteger Size() const
{
return static_cast< SQInteger >(cpr::Proxies::hosts_.size());
}
@@ -1503,7 +1503,7 @@ struct CpProxies : public cpr::Proxies
/* --------------------------------------------------------------------------------------------
* Check if no value is stored.
*/
bool Empty() const
SQMOD_NODISCARD bool Empty() const
{
return cpr::Proxies::hosts_.empty();
}
@@ -1519,7 +1519,7 @@ struct CpProxies : public cpr::Proxies
/* --------------------------------------------------------------------------------------------
* Retrieve the number of matching values.
*/
SQInteger Count(StackStrF & key) const
SQMOD_NODISCARD SQInteger Count(StackStrF & key) const
{
return static_cast< SQInteger >(cpr::Proxies::hosts_.count(key.ToStr()));
}
@@ -1544,7 +1544,7 @@ struct CpProxies : public cpr::Proxies
/* --------------------------------------------------------------------------------------------
* Check if value exists.
*/
bool Has(StackStrF & key) const
SQMOD_NODISCARD bool Has(StackStrF & key) const
{
return cpr::Proxies::hosts_.find(key.ToStr()) != cpr::Proxies::hosts_.end();
}
@@ -1552,7 +1552,7 @@ struct CpProxies : public cpr::Proxies
/* --------------------------------------------------------------------------------------------
* Retrieve value.
*/
std::string & Get(StackStrF & key)
SQMOD_NODISCARD std::string & Get(StackStrF & key)
{
auto itr = cpr::Proxies::hosts_.find(key.ToStr());
// Does it exist?
+31 -38
View File
@@ -1,12 +1,10 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Chrono.hpp"
#include "Library/Chrono/Date.hpp"
#include "Library/Chrono/Datetime.hpp"
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Timer.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Library/Numeric/LongInt.hpp"
#include "Base/Shared.hpp"
#include "Library/Numeric/Long.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
#ifdef SQMOD_OS_WINDOWS
@@ -33,7 +31,7 @@ extern void Register_ChronoTimer(HSQUIRRELVM vm, Table & cns);
extern void Register_ChronoTimestamp(HSQUIRRELVM vm, Table & cns);
// ------------------------------------------------------------------------------------------------
const Uint8 Chrono::MonthLengths[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const uint8_t Chrono::MonthLengths[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
// ------------------------------------------------------------------------------------------------
#ifdef SQMOD_OS_WINDOWS
@@ -49,7 +47,7 @@ inline LARGE_INTEGER GetFrequency()
}
// ------------------------------------------------------------------------------------------------
Int64 Chrono::GetCurrentSysTime()
int64_t Chrono::GetCurrentSysTime()
{
// Force the following code to run on first core
// (see http://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx)
@@ -68,54 +66,54 @@ Int64 Chrono::GetCurrentSysTime()
SetThreadAffinityMask(current_thread, previous_mask);
// Return the current time as microseconds
return Int64(1000000LL * time.QuadPart / frequency.QuadPart);
return int64_t(1000000LL * time.QuadPart / frequency.QuadPart);
}
// ------------------------------------------------------------------------------------------------
Int64 Chrono::GetEpochTimeMicro()
int64_t Chrono::GetEpochTimeMicro()
{
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
// Extract the nanoseconds from the resulted timestamp
Uint64 time = ft.dwHighDateTime;
uint64_t time = ft.dwHighDateTime;
time <<= 32;
time |= ft.dwLowDateTime;
time /= 10;
time -= 11644473600000000ULL;
// Return the resulted timestamp
return Int64(time);
return int64_t(time);
}
// ------------------------------------------------------------------------------------------------
#ifndef _SQ64
Int64 GetTickCount64()
int64_t GetTickCount64()
{
return static_cast< Int64 >(GetTickCount()); // Fall-back to 32 bit?
return static_cast< int64_t >(GetTickCount()); // Fall-back to 32 bit?
}
#endif // _SQ64
#else
// ------------------------------------------------------------------------------------------------
Int64 Chrono::GetCurrentSysTime()
int64_t Chrono::GetCurrentSysTime()
{
// POSIX implementation
timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
return Int64(Uint64(time.tv_sec) * 1000000 + time.tv_nsec / 1000);
return int64_t(uint64_t(time.tv_sec) * 1000000 + time.tv_nsec / 1000);
}
// ------------------------------------------------------------------------------------------------
Int64 Chrono::GetEpochTimeMicro()
int64_t Chrono::GetEpochTimeMicro()
{
// POSIX implementation
timespec time;
clock_gettime(CLOCK_REALTIME, &time);
return Int64(Uint64(time.tv_sec) * 1000000 + time.tv_nsec / 1000);
return int64_t(uint64_t(time.tv_sec) * 1000000 + time.tv_nsec / 1000);
}
// ------------------------------------------------------------------------------------------------
Uint32 GetTickCount()
uint32_t GetTickCount()
{
// POSIX implementation
struct timespec time;
@@ -127,7 +125,7 @@ Uint32 GetTickCount()
}
// ------------------------------------------------------------------------------------------------
Int64 GetTickCount64()
int64_t GetTickCount64()
{
struct timespec time;
if (clock_gettime(CLOCK_MONOTONIC, &time))
@@ -140,21 +138,16 @@ Int64 GetTickCount64()
#endif // SQMOD_OS_WINDOWS
// ------------------------------------------------------------------------------------------------
Int64 Chrono::GetEpochTimeMilli()
int64_t Chrono::GetEpochTimeMilli()
{
return (GetEpochTimeMicro() / 1000L);
}
// ------------------------------------------------------------------------------------------------
bool Chrono::ValidDate(Uint16 year, Uint8 month, Uint8 day)
bool Chrono::ValidDate(uint16_t year, uint8_t month, uint8_t day)
{
// Is this a valid date?
if (year == 0 || month == 0 || day == 0)
{
return false;
}
// Is the month within range?
else if (month > 12)
// Is this a valid date? & Is the month within range?
if (year == 0 || month == 0 || day == 0 || month > 12)
{
return false;
}
@@ -163,7 +156,7 @@ bool Chrono::ValidDate(Uint16 year, Uint8 month, Uint8 day)
}
// ------------------------------------------------------------------------------------------------
Uint8 Chrono::DaysInMonth(Uint16 year, Uint8 month)
uint8_t Chrono::DaysInMonth(uint16_t year, uint8_t month)
{
// Is the specified month within range?
if (month > 12)
@@ -171,7 +164,7 @@ Uint8 Chrono::DaysInMonth(Uint16 year, Uint8 month)
STHROWF("Month value is out of range: %u > 12", month);
}
// Obtain the days in this month
Uint8 days = *(MonthLengths + month);
uint8_t days = *(MonthLengths + month);
// Should we account for January?
if (month == 2 && IsLeapYear(year))
{
@@ -182,12 +175,12 @@ Uint8 Chrono::DaysInMonth(Uint16 year, Uint8 month)
}
// ------------------------------------------------------------------------------------------------
Uint16 Chrono::DayOfYear(Uint16 year, Uint8 month, Uint8 day)
uint16_t Chrono::DayOfYear(uint16_t year, uint8_t month, uint8_t day)
{
// Start with 0 days
Uint16 doy = 0;
uint16_t doy = 0;
// Cumulate the days in months
for (Uint8 m = 1; m < month; ++month)
for (uint8_t m = 1; m < month; ++month)
{
doy += DaysInMonth(year, m);
}
@@ -198,15 +191,15 @@ Uint16 Chrono::DayOfYear(Uint16 year, Uint8 month, Uint8 day)
}
// ------------------------------------------------------------------------------------------------
Date Chrono::ReverseDayOfyear(Uint16 year, Uint16 doy)
Date Chrono::ReverseDayOfYear(uint16_t year, uint16_t doy)
{
// The resulted month
Uint8 month = 1;
uint8_t month = 1;
// Calculate the months till the specified day of year
for (; month < 12; ++month)
{
// Get the number of days in the current month
Uint32 days = DaysInMonth(year, month);
uint32_t days = DaysInMonth(year, month);
// Can this month fit in the remaining days?
if (days >= doy)
{
@@ -220,7 +213,7 @@ Date Chrono::ReverseDayOfyear(Uint16 year, Uint16 doy)
}
// ------------------------------------------------------------------------------------------------
Int64 Chrono::DateRangeToSeconds(Uint16 _year, Uint8 _month, Uint8 _day, Uint16 year_, Uint8 month_, Uint8 day_)
int64_t Chrono::DateRangeToSeconds(uint16_t _year, uint8_t _month, uint8_t _day, uint16_t year_, uint8_t month_, uint8_t day_)
{
// Are we within the same year?
if (_year == year_)
@@ -235,7 +228,7 @@ Int64 Chrono::DateRangeToSeconds(Uint16 _year, Uint8 _month, Uint8 _day, Uint16
std::swap(_day, day_);
}
// Calculate the remaining days from the first year
Int64 num = DaysInYear(_year) - DayOfYear(_year, _month, _day);
int64_t num = DaysInYear(_year) - DayOfYear(_year, _month, _day);
// Calculate the days withing the years range
while (++_year < year_)
{
@@ -301,7 +294,7 @@ void Register_Chrono(HSQUIRRELVM vm)
.Func(_SC("DaysInYear"), &Chrono::DaysInYear)
.Func(_SC("DaysInMonth"), &Chrono::DaysInMonth)
.Func(_SC("DayOfYear"), &Chrono::DayOfYear)
.Func(_SC("ReverseDayOfyear"), &Chrono::ReverseDayOfyear);
.Func(_SC("ReverseDayOfYear"), &Chrono::ReverseDayOfYear);
RootTable(vm).Bind(_SC("SqChrono"), cns);
}
+12 -12
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -21,7 +21,7 @@ class Chrono
public:
// ------------------------------------------------------------------------------------------------
static const Uint8 MonthLengths[12];
static const uint8_t MonthLengths[12];
/* --------------------------------------------------------------------------------------------
* Default constructor. (disabled)
@@ -56,27 +56,27 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current time as microseconds.
*/
static Int64 GetCurrentSysTime();
static int64_t GetCurrentSysTime();
/* --------------------------------------------------------------------------------------------
* Retrieve the epoch time as microseconds.
*/
static Int64 GetEpochTimeMicro();
static int64_t GetEpochTimeMicro();
/* --------------------------------------------------------------------------------------------
* Retrieve the epoch time as milliseconds.
*/
static Int64 GetEpochTimeMilli();
static int64_t GetEpochTimeMilli();
/* --------------------------------------------------------------------------------------------
* See whether the specified date is valid.
*/
static bool ValidDate(Uint16 year, Uint8 month, Uint8 day);
static bool ValidDate(uint16_t year, uint8_t month, uint8_t day);
/* --------------------------------------------------------------------------------------------
* See whether the specified year is a leap year.
*/
static bool IsLeapYear(Uint16 year)
static bool IsLeapYear(uint16_t year)
{
return !(year % 400) || (!(year % 4) && (year % 100));
}
@@ -84,7 +84,7 @@ public:
/* --------------------------------------------------------------------------------------------
* retrieve the number of days in the specified year.
*/
static Uint16 DaysInYear(Uint16 year)
static uint16_t DaysInYear(uint16_t year)
{
return IsLeapYear(year) ? 366 : 365;
}
@@ -92,22 +92,22 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of days in the specified month.
*/
static Uint8 DaysInMonth(Uint16 year, Uint8 month);
static uint8_t DaysInMonth(uint16_t year, uint8_t month);
/* --------------------------------------------------------------------------------------------
* Retrieve the number/position of the specified day in the specified year and month.
*/
static Uint16 DayOfYear(Uint16 year, Uint8 month, Uint8 day);
static uint16_t DayOfYear(uint16_t year, uint8_t month, uint8_t day);
/* --------------------------------------------------------------------------------------------
* Convert just the year and day of year to full date.
*/
static Date ReverseDayOfyear(Uint16 year, Uint16 doy);
static Date ReverseDayOfYear(uint16_t year, uint16_t doy);
/* --------------------------------------------------------------------------------------------
* Calculate the number of days in the specified date range.
*/
static Int64 DateRangeToSeconds(Uint16 _year, Uint8 _month, Uint8 _day, Uint16 year_, Uint8 month_, Uint8 day_);
static int64_t DateRangeToSeconds(uint16_t _year, uint8_t _month, uint8_t _day, uint16_t year_, uint8_t month_, uint8_t day_);
};
} // Namespace:: SqMod
+57 -59
View File
@@ -1,28 +1,26 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Chrono/Date.hpp"
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Datetime.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqDate"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqDate"))
// ------------------------------------------------------------------------------------------------
SQChar Date::Delimiter = '-';
// ------------------------------------------------------------------------------------------------
Int32 Date::Compare(const Date & o) const
int32_t Date::Compare(const Date & o) const
{
if (m_Year < o.m_Year)
{
{ // NOLINT(bugprone-branch-clone)
return -1;
}
else if (m_Year > o.m_Year)
{
{ // NOLINT(bugprone-branch-clone)
return 1;
}
else if (m_Month < o.m_Month)
@@ -71,13 +69,13 @@ Date Date::operator / (const Date & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Date::ToString() const
String Date::ToString() const
{
return ToStrF("%04u%c%02u%c%02u", m_Year, m_Delimiter, m_Month, m_Delimiter, m_Day);
return fmt::format("{:04}{}{:02}{}{:02}", m_Year, m_Delimiter, m_Month, m_Delimiter, m_Day);
}
// ------------------------------------------------------------------------------------------------
void Date::Set(Uint16 year, Uint8 month, Uint8 day)
void Date::Set(uint16_t year, uint8_t month, uint8_t day)
{
if (!Chrono::ValidDate(year, month, day))
{
@@ -90,7 +88,7 @@ void Date::Set(Uint16 year, Uint8 month, Uint8 day)
}
// ------------------------------------------------------------------------------------------------
void Date::SetStr(CSStr str)
void Date::SetStr(const SQChar * str)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u - %u - %u ");
@@ -108,21 +106,21 @@ void Date::SetStr(CSStr str)
fs[4] = m_Delimiter;
fs[9] = m_Delimiter;
// The sscanf function requires at least 32 bit integers
Uint32 year = 0, month = 0, day = 0;
uint32_t year = 0, month = 0, day = 0;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &year, &month, &day);
// Clamp the extracted values to the boundaries of associated type and assign them
Set(ClampL< Uint32, Uint8 >(year),
ClampL< Uint32, Uint8 >(month),
ClampL< Uint32, Uint8 >(day)
Set(ClampL< uint32_t, uint8_t >(year),
ClampL< uint32_t, uint8_t >(month),
ClampL< uint32_t, uint8_t >(day)
);
}
// ------------------------------------------------------------------------------------------------
void Date::SetDayOfYear(Uint16 doy)
void Date::SetDayOfYear(uint16_t doy)
{
// Reverse the given day of year to a full date
Date d = Chrono::ReverseDayOfyear(m_Year, doy);
Date d = Chrono::ReverseDayOfYear(m_Year, doy);
// Set the obtained month
SetMonth(d.m_Month);
// Set the obtained day
@@ -130,7 +128,7 @@ void Date::SetDayOfYear(Uint16 doy)
}
// ------------------------------------------------------------------------------------------------
void Date::SetYear(Uint16 year)
void Date::SetYear(uint16_t year)
{
// Make sure the year is valid
if (!year)
@@ -148,7 +146,7 @@ void Date::SetYear(Uint16 year)
}
// ------------------------------------------------------------------------------------------------
void Date::SetMonth(Uint8 month)
void Date::SetMonth(uint8_t month)
{
// Make sure the month is valid
if (month == 0 || month > 12)
@@ -165,10 +163,10 @@ void Date::SetMonth(Uint8 month)
}
// ------------------------------------------------------------------------------------------------
void Date::SetDay(Uint8 day)
void Date::SetDay(uint8_t day)
{
// Grab the amount of days in the current month
const Uint8 dim = Chrono::DaysInMonth(m_Year, m_Month);
const uint8_t dim = Chrono::DaysInMonth(m_Year, m_Month);
// Make sure the day is valid
if (day == 0)
{
@@ -183,26 +181,26 @@ void Date::SetDay(Uint8 day)
}
// ------------------------------------------------------------------------------------------------
Date & Date::AddYears(Int32 years)
Date & Date::AddYears(int32_t years)
{
// Do we have a valid amount of years?
if (years)
{
// Add the specified amount of years
SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Date & Date::AddMonths(Int32 months)
Date & Date::AddMonths(int32_t months)
{
// Do we have a valid amount of months?
if (months)
{
// Extract the number of years
Int32 years = static_cast< Int32 >(months / 12);
auto years = static_cast< int32_t >(months / 12);
// Extract the number of months
months = (months % 12) + m_Month;
// Do we have extra months?
@@ -223,47 +221,47 @@ Date & Date::AddMonths(Int32 months)
// Are there any years to add?
if (years)
{
SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Add the months
SetMonth(months);
SetMonth(static_cast< uint8_t >(months));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Date & Date::AddDays(Int32 days)
Date & Date::AddDays(int32_t days)
{
// Do we have a valid amount of days?
if (days)
{
// Whether the number of days is positive or negative
const Int32 dir = days > 0 ? 1 : -1;
const int32_t dir = days > 0 ? 1 : -1;
// Grab current year
Int32 year = m_Year;
int32_t year = m_Year;
// Calculate the days in the current year
Int32 diy = Chrono::DaysInYear(year);
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
// Calculate the day of year
Int32 doy = GetDayOfYear() + days;
int32_t doy = GetDayOfYear() + days;
// Calculate the resulting years
while (doy > diy || doy < 0)
{
doy -= diy * dir;
year += dir;
diy = Chrono::DaysInYear(year);
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Set the obtained year
SetYear(year);
SetYear(static_cast< uint16_t >(year));
// Set the obtained day of year
SetDayOfYear(doy);
SetDayOfYear(static_cast< uint16_t >(doy));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Date Date::AndYears(Int32 years)
Date Date::AndYears(int32_t years)
{
// Do we have a valid amount of years?
if (!years)
@@ -273,13 +271,13 @@ Date Date::AndYears(Int32 years)
// Replicate the current date
Date d(*this);
// Add the specified amount of years
d.SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
d.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
// Return the resulted date
return d;
}
// ------------------------------------------------------------------------------------------------
Date Date::AndMonths(Int32 months)
Date Date::AndMonths(int32_t months)
{
// Do we have a valid amount of months?
if (!months)
@@ -287,7 +285,7 @@ Date Date::AndMonths(Int32 months)
return Date(*this); // Return the date as is
}
// Extract the number of years
Int32 years = static_cast< Int32 >(months / 12);
auto years = static_cast< int32_t >(months / 12);
// Extract the number of months
months = (months % 12) + m_Month;
// Do we have extra months?
@@ -310,16 +308,16 @@ Date Date::AndMonths(Int32 months)
// Are there any years to add?
if (years)
{
d.SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
d.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Add the months
d.SetMonth(months);
d.SetMonth(static_cast< uint8_t >(months));
// Return the resulted date
return d;
}
// ------------------------------------------------------------------------------------------------
Date Date::AndDays(Int32 days)
Date Date::AndDays(int32_t days)
{
// Do we have a valid amount of days?
if (!days)
@@ -327,26 +325,26 @@ Date Date::AndDays(Int32 days)
return Date(*this); // Return the date as is
}
// Whether the number of days is positive or negative
const Int32 dir = days > 0 ? 1 : -1;
const int32_t dir = days > 0 ? 1 : -1;
// Grab current year
Int32 year = m_Year;
int32_t year = m_Year;
// Calculate the days in the current year
Int32 diy = Chrono::DaysInYear(year);
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
// Calculate the day of year
Int32 doy = GetDayOfYear() + days;
int32_t doy = GetDayOfYear() + days;
// Calculate the resulting years
while (doy > diy || doy < 0)
{
doy -= diy * dir;
year += dir;
diy = Chrono::DaysInYear(year);
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Replicate the current date
Date d(*this);
// Set the obtained year
d.SetYear(year);
d.SetYear(static_cast< uint16_t >(year));
// Set the obtained day of year
d.SetDayOfYear(doy);
d.SetDayOfYear(static_cast< uint16_t >(doy));
// Return the resulted date
return d;
}
@@ -355,14 +353,14 @@ Date Date::AndDays(Int32 days)
Timestamp Date::GetTimestamp() const
{
// Calculate the current day of the year
Int32 days = Chrono::DayOfYear(m_Year, m_Month, m_Day);
int32_t days = Chrono::DayOfYear(m_Year, m_Month, m_Day);
// Calculate all days till the current year
for (Int32 year = 0; year < m_Year; --year)
for (int32_t year = 0; year < m_Year; --year)
{
days += Chrono::DaysInYear(year);
days += Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Return the resulted timestamp
return Timestamp(static_cast< Int64 >(days * 86400000000LL));
return Timestamp(static_cast< int64_t >(days * 86400000000LL));
}
// ================================================================================================
@@ -372,9 +370,9 @@ void Register_ChronoDate(HSQUIRRELVM vm, Table & /*cns*/)
Class< Date >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< Uint16 >()
.Ctor< Uint16, Uint8 >()
.Ctor< Uint16, Uint8, Uint8 >()
.Ctor< uint16_t >()
.Ctor< uint16_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t >()
// Static Properties
.SetStaticValue(_SC("GlobalDelimiter"), &Date::Delimiter)
// Core Meta-methods
@@ -405,9 +403,9 @@ void Register_ChronoDate(HSQUIRRELVM vm, Table & /*cns*/)
.Func(_SC("AndMonths"), &Date::AndMonths)
.Func(_SC("AndDays"), &Date::AndDays)
// Overloaded Methods
.Overload< void (Date::*)(Uint16) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(Uint16, Uint8) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(Uint16, Uint8, Uint8) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(uint16_t) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(uint16_t, uint8_t) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(uint16_t, uint8_t, uint8_t) >(_SC("Set"), &Date::Set)
);
}
+37 -37
View File
@@ -19,9 +19,9 @@ public:
private:
// ------------------------------------------------------------------------------------------------
Uint16 m_Year; // Year
Uint8 m_Month; // Month
Uint8 m_Day; // Day
uint16_t m_Year{}; // Year
uint8_t m_Month{}; // Month
uint8_t m_Day{}; // Day
// ------------------------------------------------------------------------------------------------
SQChar m_Delimiter; // Component delimiter when generating strings.
@@ -31,7 +31,7 @@ protected:
/* ------------------------------------------------------------------------------------------------
* Compare the values of two instances.
*/
Int32 Compare(const Date & o) const;
SQMOD_NODISCARD int32_t Compare(const Date & o) const;
public:
@@ -48,27 +48,27 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic year constructor.
* Specific year constructor.
*/
Date(Uint16 year)
explicit Date(uint16_t year)
: m_Delimiter(Delimiter)
{
Set(year, 1, 1);
}
/* ------------------------------------------------------------------------------------------------
* Speciffic year and month constructor.
* Specific year and month constructor.
*/
Date(Uint16 year, Uint8 month)
Date(uint16_t year, uint8_t month)
: m_Delimiter(Delimiter)
{
Set(year, month, 1);
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date constructor.
* Specific date constructor.
*/
Date(Uint16 year, Uint8 month, Uint8 day)
Date(uint16_t year, uint8_t month, uint8_t day)
: m_Delimiter(Delimiter)
{
Set(year, month, day);
@@ -77,7 +77,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* String constructor.
*/
Date(CSStr str)
explicit Date(const SQChar * str)
: m_Delimiter(Delimiter)
{
SetStr(str);
@@ -179,7 +179,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Date & o) const
SQMOD_NODISCARD int32_t Cmp(const Date & o) const
{
return Compare(o);
}
@@ -187,12 +187,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year)
void Set(uint16_t year)
{
Set(year, m_Month, m_Day);
}
@@ -200,7 +200,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month)
void Set(uint16_t year, uint8_t month)
{
Set(year, month, m_Day);
}
@@ -208,12 +208,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day);
void Set(uint16_t year, uint8_t month, uint8_t day);
/* ------------------------------------------------------------------------------------------------
* Retrieve the local delimiter character.
*/
SQChar GetDelimiter() const
SQMOD_NODISCARD SQChar GetDelimiter() const
{
return m_Delimiter;
}
@@ -229,7 +229,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the values as a string.
*/
CSStr GetStr() const
SQMOD_NODISCARD String GetStr() const
{
return ToString();
}
@@ -237,12 +237,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Extract the values from a string.
*/
void SetStr(CSStr str);
void SetStr(const SQChar * str);
/* ------------------------------------------------------------------------------------------------
* Retrieve the day component.
*/
Uint16 GetDayOfYear() const
SQMOD_NODISCARD uint16_t GetDayOfYear() const
{
return Chrono::DayOfYear(m_Year, m_Month, m_Day);
}
@@ -250,12 +250,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the day component.
*/
void SetDayOfYear(Uint16 doy);
void SetDayOfYear(uint16_t doy);
/* ------------------------------------------------------------------------------------------------
* Retrieve the year component.
*/
Uint16 GetYear() const
SQMOD_NODISCARD uint16_t GetYear() const
{
return m_Year;
}
@@ -263,12 +263,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the year component.
*/
void SetYear(Uint16 year);
void SetYear(uint16_t year);
/* ------------------------------------------------------------------------------------------------
* Retrieve the month component.
*/
Uint8 GetMonth() const
SQMOD_NODISCARD uint8_t GetMonth() const
{
return m_Month;
}
@@ -276,12 +276,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the month component.
*/
void SetMonth(Uint8 month);
void SetMonth(uint8_t month);
/* ------------------------------------------------------------------------------------------------
* Retrieve the day component.
*/
Uint8 GetDay() const
SQMOD_NODISCARD uint8_t GetDay() const
{
return m_Day;
}
@@ -289,42 +289,42 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the day component.
*/
void SetDay(Uint8 day);
void SetDay(uint8_t day);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of years to the current date.
*/
Date & AddYears(Int32 years);
Date & AddYears(int32_t years);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of months to the current date.
*/
Date & AddMonths(Int32 months);
Date & AddMonths(int32_t months);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of days to the current date.
*/
Date & AddDays(Int32 days);
Date & AddDays(int32_t days);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of years to obtain a new date.
*/
Date AndYears(Int32 years);
SQMOD_NODISCARD Date AndYears(int32_t years);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of months to obtain a new date.
*/
Date AndMonths(Int32 months);
SQMOD_NODISCARD Date AndMonths(int32_t months);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of days to obtain a new date.
*/
Date AndDays(Int32 days);
SQMOD_NODISCARD Date AndDays(int32_t days);
/* ------------------------------------------------------------------------------------------------
* See whether the associated year is a leap year.
*/
bool IsThisLeapYear() const
SQMOD_NODISCARD bool IsThisLeapYear() const
{
return Chrono::IsLeapYear(m_Year);
}
@@ -332,7 +332,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the number of days in the associated year.
*/
Uint16 GetYearDays() const
SQMOD_NODISCARD uint16_t GetYearDays() const
{
return Chrono::DaysInYear(m_Year);
}
@@ -340,7 +340,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the number of days in the associated month.
*/
Uint8 GetMonthDays() const
SQMOD_NODISCARD uint8_t GetMonthDays() const
{
return Chrono::DaysInMonth(m_Year, m_Month);
}
@@ -348,7 +348,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Convert this date instance to a time-stamp.
*/
Timestamp GetTimestamp() const;
SQMOD_NODISCARD Timestamp GetTimestamp() const;
};
} // Namespace:: SqMod
+97 -97
View File
@@ -3,13 +3,13 @@
#include "Library/Chrono/Date.hpp"
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqDatetime"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqDatetime"))
// ------------------------------------------------------------------------------------------------
SQChar Datetime::Delimiter = ' ';
@@ -17,14 +17,14 @@ SQChar Datetime::DateDelim = '-';
SQChar Datetime::TimeDelim = ':';
// ------------------------------------------------------------------------------------------------
Int32 Datetime::Compare(const Datetime & o) const
int32_t Datetime::Compare(const Datetime & o) const
{
if (m_Year < o.m_Year)
{
{ // NOLINT(bugprone-branch-clone)
return -1;
}
else if (m_Year > o.m_Year)
{
{ // NOLINT(bugprone-branch-clone)
return 1;
}
else if (m_Month < o.m_Month)
@@ -107,9 +107,9 @@ Datetime Datetime::operator / (const Datetime & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Datetime::ToString() const
String Datetime::ToString() const
{
return ToStrF("%04u%c%02u%c%02u%c%02u%c%02u%c%02u%c%u"
return fmt::format("{:04}{}{:02}{}{:02}{}{:02}{}{:02}{}{:02}{}{}"
, m_Year, m_DateDelim, m_Month, m_DateDelim, m_Day
, m_Delimiter
, m_Hour, m_TimeDelim, m_Minute, m_TimeDelim, m_Second , m_TimeDelim, m_Millisecond
@@ -117,7 +117,7 @@ CSStr Datetime::ToString() const
}
// ------------------------------------------------------------------------------------------------
void Datetime::Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
void Datetime::Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond)
{
// Validate the specified date
if (!Chrono::ValidDate(year, month, day))
@@ -159,7 +159,7 @@ void Datetime::Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetStr(CSStr str)
void Datetime::SetStr(const SQChar * str)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u - %u - %u %u : %u : %u : %u ");
@@ -185,25 +185,25 @@ void Datetime::SetStr(CSStr str)
fs[24] = m_TimeDelim;
fs[29] = m_TimeDelim;
// The sscanf function requires at least 32 bit integers
Uint32 year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, milli = 0;
uint32_t year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, milli = 0;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &year, &month, &day, &hour, &minute, &second, &milli);
// Clamp the extracted values to the boundaries of associated type and assign them
Set(ClampL< Uint32, Uint8 >(year),
ClampL< Uint32, Uint8 >(month),
ClampL< Uint32, Uint8 >(day),
ClampL< Uint32, Uint8 >(hour),
ClampL< Uint32, Uint8 >(minute),
ClampL< Uint32, Uint8 >(second),
ClampL< Uint32, Uint16 >(milli)
Set(ClampL< uint32_t, uint8_t >(year),
ClampL< uint32_t, uint8_t >(month),
ClampL< uint32_t, uint8_t >(day),
ClampL< uint32_t, uint8_t >(hour),
ClampL< uint32_t, uint8_t >(minute),
ClampL< uint32_t, uint8_t >(second),
ClampL< uint32_t, uint16_t >(milli)
);
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetDayOfYear(Uint16 doy)
void Datetime::SetDayOfYear(uint16_t doy)
{
// Reverse the given day of year to a full date
Date d = Chrono::ReverseDayOfyear(m_Year, doy);
Date d = Chrono::ReverseDayOfYear(m_Year, doy);
// Set the obtained month
SetMonth(d.GetMonth());
// Set the obtained day
@@ -211,7 +211,7 @@ void Datetime::SetDayOfYear(Uint16 doy)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetYear(Uint16 year)
void Datetime::SetYear(uint16_t year)
{
// Make sure the year is valid
if (!year)
@@ -229,7 +229,7 @@ void Datetime::SetYear(Uint16 year)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetMonth(Uint8 month)
void Datetime::SetMonth(uint8_t month)
{
// Make sure the month is valid
if (month == 0 || month > 12)
@@ -246,10 +246,10 @@ void Datetime::SetMonth(Uint8 month)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetDay(Uint8 day)
void Datetime::SetDay(uint8_t day)
{
// Grab the amount of days in the current month
const Uint8 dim = Chrono::DaysInMonth(m_Year, m_Month);
const uint8_t dim = Chrono::DaysInMonth(m_Year, m_Month);
// Make sure the day is valid
if (day == 0)
{
@@ -264,7 +264,7 @@ void Datetime::SetDay(Uint8 day)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetHour(Uint8 hour)
void Datetime::SetHour(uint8_t hour)
{
// Is the specified hour within range?
if (hour >= 24)
@@ -276,7 +276,7 @@ void Datetime::SetHour(Uint8 hour)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetMinute(Uint8 minute)
void Datetime::SetMinute(uint8_t minute)
{
// Is the specified minute within range?
if (minute >= 60)
@@ -288,7 +288,7 @@ void Datetime::SetMinute(Uint8 minute)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetSecond(Uint8 second)
void Datetime::SetSecond(uint8_t second)
{
// Is the specified second within range?
if (second >= 60)
@@ -300,7 +300,7 @@ void Datetime::SetSecond(Uint8 second)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetMillisecond(Uint16 millisecond)
void Datetime::SetMillisecond(uint16_t millisecond)
{
// Is the specified millisecond within range?
if (millisecond >= 1000)
@@ -312,26 +312,26 @@ void Datetime::SetMillisecond(Uint16 millisecond)
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddYears(Int32 years)
Datetime & Datetime::AddYears(int32_t years)
{
// Do we have a valid amount of years?
if (years)
{
// Add the specified amount of years
SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddMonths(Int32 months)
Datetime & Datetime::AddMonths(int32_t months)
{
// Do we have a valid amount of months?
if (months)
{
// Extract the number of years
Int32 years = static_cast< Int32 >(months / 12);
auto years = static_cast< int32_t >(months / 12);
// Extract the number of months
months = (months % 12) + m_Month;
// Do we have extra months?
@@ -352,53 +352,53 @@ Datetime & Datetime::AddMonths(Int32 months)
// Are there any years to add?
if (years)
{
SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Add the months
SetMonth(months);
SetMonth(static_cast< uint8_t >(months));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddDays(Int32 days)
Datetime & Datetime::AddDays(int32_t days)
{
// Do we have a valid amount of days?
if (days)
{
// Whether the number of days is positive or negative
const Int32 dir = days > 0 ? 1 : -1;
const int32_t dir = days > 0 ? 1 : -1;
// Grab current year
Int32 year = m_Year;
int32_t year = m_Year;
// Calculate the days in the current year
Int32 diy = Chrono::DaysInYear(year);
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
// Calculate the day of year
Int32 doy = GetDayOfYear() + days;
int32_t doy = GetDayOfYear() + days;
// Calculate the resulting years
while (doy > diy || doy < 0)
{
doy -= diy * dir;
year += dir;
diy = Chrono::DaysInYear(year);
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Set the obtained year
SetYear(year);
SetYear(static_cast< uint16_t >(year));
// Set the obtained day of year
SetDayOfYear(doy);
SetDayOfYear(static_cast< uint16_t >(doy));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddHours(Int32 hours)
Datetime & Datetime::AddHours(int32_t hours)
{
// Did we even add any hours?
if (hours)
{
// Extract the number of days
Int32 days = static_cast< Int32 >(hours / 24);
auto days = static_cast< int32_t >(hours / 24);
// Extract the number of hours
m_Hour += (hours % 24);
// Are the hours overlapping with the next day?
@@ -420,13 +420,13 @@ Datetime & Datetime::AddHours(Int32 hours)
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddMinutes(Int32 minutes)
Datetime & Datetime::AddMinutes(int32_t minutes)
{
// Did we even add any minutes?
if (minutes)
{
// Extract the number of hours
Int32 hours = static_cast< Int32 >(minutes / 60);
auto hours = static_cast< int32_t >(minutes / 60);
// Extract the number of minutes
m_Minute += (minutes % 60);
// Are the minutes overlapping with the next hour?
@@ -448,13 +448,13 @@ Datetime & Datetime::AddMinutes(Int32 minutes)
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddSeconds(Int32 seconds)
Datetime & Datetime::AddSeconds(int32_t seconds)
{
// Did we even add any seconds?
if (seconds)
{
// Extract the number of minutes
Int32 minutes = static_cast< Int32 >(seconds / 60);
auto minutes = static_cast< int32_t >(seconds / 60);
// Extract the number of seconds
m_Second += (seconds % 60);
// Are the seconds overlapping with the next minute?
@@ -476,13 +476,13 @@ Datetime & Datetime::AddSeconds(Int32 seconds)
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddMilliseconds(Int32 milliseconds)
Datetime & Datetime::AddMilliseconds(int32_t milliseconds)
{
// Did we even add any milliseconds?
if (milliseconds)
{
// Extract the number of seconds
Int32 seconds = static_cast< Int32 >(milliseconds / 1000);
auto seconds = static_cast< int32_t >(milliseconds / 1000);
// Extract the number of milliseconds
m_Millisecond += (milliseconds / 1000);
// Are the milliseconds overlapping with the next second?
@@ -504,7 +504,7 @@ Datetime & Datetime::AddMilliseconds(Int32 milliseconds)
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndYears(Int32 years)
Datetime Datetime::AndYears(int32_t years)
{
// Do we have a valid amount of years?
if (!years)
@@ -514,13 +514,13 @@ Datetime Datetime::AndYears(Int32 years)
// Replicate the current date
Datetime dt(*this);
// Add the specified amount of years
dt.SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
dt.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
// Return the resulted date
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndMonths(Int32 months)
Datetime Datetime::AndMonths(int32_t months)
{
// Do we have a valid amount of months?
if (!months)
@@ -528,7 +528,7 @@ Datetime Datetime::AndMonths(Int32 months)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of years
Int32 years = static_cast< Int32 >(months / 12);
auto years = static_cast< int32_t >(months / 12);
// Extract the number of months
months = (months % 12) + m_Month;
// Do we have extra months?
@@ -551,16 +551,16 @@ Datetime Datetime::AndMonths(Int32 months)
// Are there any years to add?
if (years)
{
dt.SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
dt.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Add the months
dt.SetMonth(months);
dt.SetMonth(static_cast< uint8_t >(months));
// Return the resulted date
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndDays(Int32 days)
Datetime Datetime::AndDays(int32_t days)
{
// Do we have a valid amount of days?
if (!days)
@@ -568,32 +568,32 @@ Datetime Datetime::AndDays(Int32 days)
return Datetime(*this); // Return the date-time as is
}
// Whether the number of days is positive or negative
const Int32 dir = days > 0 ? 1 : -1;
const int32_t dir = days > 0 ? 1 : -1;
// Grab current year
Int32 year = m_Year;
int32_t year = m_Year;
// Calculate the days in the current year
Int32 diy = Chrono::DaysInYear(year);
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
// Calculate the day of year
Int32 doy = GetDayOfYear() + days;
int32_t doy = GetDayOfYear() + days;
// Calculate the resulting years
while (doy > diy || doy < 0)
{
doy -= diy * dir;
year += dir;
diy = Chrono::DaysInYear(year);
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Replicate the current date
Datetime dt(*this);
// Set the obtained year
dt.SetYear(year);
dt.SetYear(static_cast< uint16_t >(year));
// Set the obtained day of year
dt.SetDayOfYear(doy);
dt.SetDayOfYear(static_cast< uint16_t >(doy));
// Return the resulted date
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndHours(Int32 hours)
Datetime Datetime::AndHours(int32_t hours)
{
// Did we even add any hours?
if (!hours)
@@ -601,7 +601,7 @@ Datetime Datetime::AndHours(Int32 hours)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of days
Int32 days = static_cast< Int32 >(hours / 24);
auto days = static_cast< int32_t >(hours / 24);
// Extract the number of hours
hours = m_Hour + (hours % 24);
// Are the hours overlapping with the next day?
@@ -617,13 +617,13 @@ Datetime Datetime::AndHours(Int32 hours)
dt.AddDays(days);
}
// Assign the resulted hours
dt.m_Hour = (hours % 24);
dt.m_Hour = static_cast< uint8_t >(hours % 24);
// Return the result
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndMinutes(Int32 minutes)
Datetime Datetime::AndMinutes(int32_t minutes)
{
// Did we even added any minutes?
if (!minutes)
@@ -631,7 +631,7 @@ Datetime Datetime::AndMinutes(Int32 minutes)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of hours
Int32 hours = static_cast< Int32 >(minutes / 60);
auto hours = static_cast< int32_t >(minutes / 60);
// Extract the number of minutes
minutes = m_Minute + (minutes % 60);
// Are the minutes overlapping with the next hour?
@@ -647,13 +647,13 @@ Datetime Datetime::AndMinutes(Int32 minutes)
dt.AddHours(hours);
}
// Assign the resulted minutes
dt.m_Minute = (minutes % 60);
dt.m_Minute = static_cast< uint8_t >(minutes % 60);
// Return the result
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndSeconds(Int32 seconds)
Datetime Datetime::AndSeconds(int32_t seconds)
{
// Did we even added any seconds?
if (!seconds)
@@ -661,7 +661,7 @@ Datetime Datetime::AndSeconds(Int32 seconds)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of minutes
Int32 minutes = static_cast< Int32 >(seconds / 60);
auto minutes = static_cast< int32_t >(seconds / 60);
// Extract the number of seconds
seconds = m_Second + (seconds % 60);
// Are the seconds overlapping with the next minute?
@@ -677,13 +677,13 @@ Datetime Datetime::AndSeconds(Int32 seconds)
dt.AddMinutes(minutes);
}
// Assign the resulted seconds
dt.m_Second = (seconds % 60);
dt.m_Second = static_cast< uint8_t >(seconds % 60);
// Return the result
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndMilliseconds(Int32 milliseconds)
Datetime Datetime::AndMilliseconds(int32_t milliseconds)
{
// Did we even added any milliseconds?
if (!milliseconds)
@@ -691,7 +691,7 @@ Datetime Datetime::AndMilliseconds(Int32 milliseconds)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of seconds
Int32 seconds = static_cast< Int32 >(milliseconds / 1000);
auto seconds = static_cast< int32_t >(milliseconds / 1000);
// Extract the number of milliseconds
milliseconds = m_Millisecond + (milliseconds % 1000);
// Are the milliseconds overlapping with the next second?
@@ -707,7 +707,7 @@ Datetime Datetime::AndMilliseconds(Int32 milliseconds)
dt.AddSeconds(seconds);
}
// Assign the resulted milliseconds
dt.m_Millisecond = (milliseconds % 1000);
dt.m_Millisecond = static_cast< uint16_t >(milliseconds % 1000);
// Return the result
return dt;
}
@@ -728,19 +728,19 @@ Time Datetime::GetTime() const
Timestamp Datetime::GetTimestamp() const
{
// Calculate the current day of the year
Int32 days = Chrono::DayOfYear(m_Year, m_Month, m_Day);
int32_t days = Chrono::DayOfYear(m_Year, m_Month, m_Day);
// Calculate all days till the current year
for (Int32 year = 0; year < m_Year; --year)
for (int32_t year = 0; year < m_Year; --year)
{
days += Chrono::DaysInYear(year);
days += Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Calculate the microseconds in the resulted days
Int64 ms = static_cast< Int64 >(days * 86400000000LL);
auto ms = static_cast< int64_t >(days * 86400000000LL);
// Calculate the microseconds in the current time
ms += static_cast< Int64 >(m_Hour * 3600000000LL);
ms += static_cast< Int64 >(m_Minute * 60000000L);
ms += static_cast< Int64 >(m_Second * 1000000L);
ms += static_cast< Int64 >(m_Millisecond * 1000L);
ms += static_cast< int64_t >(m_Hour * 3600000000LL);
ms += static_cast< int64_t >(m_Minute * 60000000L);
ms += static_cast< int64_t >(m_Second * 1000000L);
ms += static_cast< int64_t >(m_Millisecond * 1000L);
// Return the resulted timestamp
return Timestamp(ms);
}
@@ -752,13 +752,13 @@ void Register_ChronoDatetime(HSQUIRRELVM vm, Table & /*cns*/)
Class< Datetime >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< Uint16 >()
.Ctor< Uint16, Uint8 >()
.Ctor< Uint16, Uint8, Uint8 >()
.Ctor< Uint16, Uint8, Uint8, Uint8 >()
.Ctor< Uint16, Uint8, Uint8, Uint8, Uint8 >()
.Ctor< Uint16, Uint8, Uint8, Uint8, Uint8, Uint8 >()
.Ctor< Uint16, Uint8, Uint8, Uint8, Uint8, Uint8, Uint16 >()
.Ctor< uint16_t >()
.Ctor< uint16_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t, uint8_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t >()
// Static Properties
.SetStaticValue(_SC("GlobalDelimiter"), &Datetime::Delimiter)
.SetStaticValue(_SC("GlobalDateDelim"), &Datetime::DateDelim)
@@ -809,13 +809,13 @@ void Register_ChronoDatetime(HSQUIRRELVM vm, Table & /*cns*/)
.Func(_SC("AndMillis"), &Datetime::AndMilliseconds)
.Func(_SC("AndMilliseconds"), &Datetime::AndMilliseconds)
// Overloaded Methods
.Overload< void (Datetime::*)(Uint16) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8, Uint8, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8, Uint8, Uint8, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8, Uint8, Uint8, Uint8, Uint16) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t, uint8_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t) >(_SC("Set"), &Datetime::Set)
);
}
+72 -72
View File
@@ -21,15 +21,15 @@ public:
private:
// ------------------------------------------------------------------------------------------------
Uint16 m_Year; // Year
Uint8 m_Month; // Month
Uint8 m_Day; // Day
uint16_t m_Year{}; // Year
uint8_t m_Month{}; // Month
uint8_t m_Day{}; // Day
// ------------------------------------------------------------------------------------------------
Uint8 m_Hour; // Hour
Uint8 m_Minute; // Minute
Uint8 m_Second; // Second
Uint16 m_Millisecond; // Millisecond
uint8_t m_Hour{}; // Hour
uint8_t m_Minute{}; // Minute
uint8_t m_Second{}; // Second
uint16_t m_Millisecond{}; // Millisecond
// ------------------------------------------------------------------------------------------------
SQChar m_Delimiter; // Date and time delimiter when generating strings.
@@ -41,7 +41,7 @@ protected:
/* ------------------------------------------------------------------------------------------------
* Compare the values of two instances.
*/
Int32 Compare(const Datetime & o) const;
SQMOD_NODISCARD int32_t Compare(const Datetime & o) const;
public:
@@ -64,9 +64,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic year constructor.
* Specific year constructor.
*/
Datetime(Uint16 year)
explicit Datetime(uint16_t year)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@@ -75,9 +75,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic year and month constructor.
* Specific year and month constructor.
*/
Datetime(Uint16 year, Uint8 month)
Datetime(uint16_t year, uint8_t month)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@@ -86,9 +86,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date constructor.
* Specific date constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day)
Datetime(uint16_t year, uint8_t month, uint8_t day)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@@ -97,9 +97,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date and hour constructor.
* Specific date and hour constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day, Uint8 hour)
Datetime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@@ -108,9 +108,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date, hour and minute constructor.
* Specific date, hour and minute constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute)
Datetime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@@ -119,9 +119,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date and time constructor.
* Specific date and time constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second)
Datetime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@@ -130,9 +130,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date and precise time constructor.
* Specific date and precise time constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
Datetime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@@ -236,7 +236,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Datetime & o) const
SQMOD_NODISCARD int32_t Cmp(const Datetime & o) const
{
return Compare(o);
}
@@ -244,12 +244,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year)
void Set(uint16_t year)
{
Set(year, m_Month, m_Day, m_Hour, m_Minute, m_Second, m_Millisecond);
}
@@ -257,7 +257,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month)
void Set(uint16_t year, uint8_t month)
{
Set(year, month, m_Day, m_Hour, m_Minute, m_Second, m_Millisecond);
}
@@ -265,7 +265,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day)
void Set(uint16_t year, uint8_t month, uint8_t day)
{
Set(year, month, day, m_Hour, m_Minute, m_Second, m_Millisecond);
}
@@ -273,7 +273,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour)
void Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour)
{
Set(year, month, day, hour, m_Minute, m_Second, m_Millisecond);
}
@@ -281,7 +281,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute)
void Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute)
{
Set(year, month, day, hour, minute, m_Second, m_Millisecond);
}
@@ -289,7 +289,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second)
void Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
{
Set(year, month, day, hour, minute, second, m_Millisecond);
}
@@ -297,12 +297,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond);
void Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
/* ------------------------------------------------------------------------------------------------
* Retrieve the local delimiter character.
*/
SQChar GetDelimiter() const
SQMOD_NODISCARD SQChar GetDelimiter() const
{
return m_Delimiter;
}
@@ -318,7 +318,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the local date delimiter character.
*/
SQChar GetDateDelim() const
SQMOD_NODISCARD SQChar GetDateDelim() const
{
return m_DateDelim;
}
@@ -334,7 +334,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the local time delimiter character.
*/
SQChar GetTimeDelim() const
SQMOD_NODISCARD SQChar GetTimeDelim() const
{
return m_TimeDelim;
}
@@ -350,7 +350,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the values as a string.
*/
CSStr GetStr() const
SQMOD_NODISCARD String GetStr() const
{
return ToString();
}
@@ -358,12 +358,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Extract the values from a string.
*/
void SetStr(CSStr str);
void SetStr(const SQChar * str);
/* ------------------------------------------------------------------------------------------------
* Retrieve the day component.
*/
Uint16 GetDayOfYear() const
SQMOD_NODISCARD uint16_t GetDayOfYear() const
{
return Chrono::DayOfYear(m_Year, m_Month, m_Day);
}
@@ -371,12 +371,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the day component.
*/
void SetDayOfYear(Uint16 doy);
void SetDayOfYear(uint16_t doy);
/* ------------------------------------------------------------------------------------------------
* Retrieve the year component.
*/
Uint16 GetYear() const
SQMOD_NODISCARD uint16_t GetYear() const
{
return m_Year;
}
@@ -384,12 +384,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the year component.
*/
void SetYear(Uint16 year);
void SetYear(uint16_t year);
/* ------------------------------------------------------------------------------------------------
* Retrieve the month component.
*/
Uint8 GetMonth() const
SQMOD_NODISCARD uint8_t GetMonth() const
{
return m_Month;
}
@@ -397,12 +397,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the month component.
*/
void SetMonth(Uint8 month);
void SetMonth(uint8_t month);
/* ------------------------------------------------------------------------------------------------
* Retrieve the day component.
*/
Uint8 GetDay() const
SQMOD_NODISCARD uint8_t GetDay() const
{
return m_Day;
}
@@ -410,12 +410,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the day component.
*/
void SetDay(Uint8 day);
void SetDay(uint8_t day);
/* ------------------------------------------------------------------------------------------------
* Retrieve the hour component.
*/
Uint8 GetHour() const
SQMOD_NODISCARD uint8_t GetHour() const
{
return m_Hour;
}
@@ -423,12 +423,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the hour component.
*/
void SetHour(Uint8 hour);
void SetHour(uint8_t hour);
/* ------------------------------------------------------------------------------------------------
* Retrieve the minute component.
*/
Uint8 GetMinute() const
SQMOD_NODISCARD uint8_t GetMinute() const
{
return m_Minute;
}
@@ -436,12 +436,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the minute component.
*/
void SetMinute(Uint8 minute);
void SetMinute(uint8_t minute);
/* ------------------------------------------------------------------------------------------------
* Retrieve the second component.
*/
Uint8 GetSecond() const
SQMOD_NODISCARD uint8_t GetSecond() const
{
return m_Second;
}
@@ -449,12 +449,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the second component.
*/
void SetSecond(Uint8 second);
void SetSecond(uint8_t second);
/* ------------------------------------------------------------------------------------------------
* Retrieve the millisecond component.
*/
Uint16 GetMillisecond() const
SQMOD_NODISCARD uint16_t GetMillisecond() const
{
return m_Millisecond;
}
@@ -462,82 +462,82 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the millisecond component.
*/
void SetMillisecond(Uint16 millisecond);
void SetMillisecond(uint16_t millisecond);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of years to the current date.
*/
Datetime & AddYears(Int32 years);
Datetime & AddYears(int32_t years);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of months to the current date.
*/
Datetime & AddMonths(Int32 months);
Datetime & AddMonths(int32_t months);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of days to the current date.
*/
Datetime & AddDays(Int32 days);
Datetime & AddDays(int32_t days);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of hours to the current time.
*/
Datetime & AddHours(Int32 hours);
Datetime & AddHours(int32_t hours);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of minutes to the current time.
*/
Datetime & AddMinutes(Int32 minutes);
Datetime & AddMinutes(int32_t minutes);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of seconds to the current time.
*/
Datetime & AddSeconds(Int32 seconds);
Datetime & AddSeconds(int32_t seconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of milliseconds to the current time.
*/
Datetime & AddMilliseconds(Int32 milliseconds);
Datetime & AddMilliseconds(int32_t milliseconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of years to obtain a new date.
*/
Datetime AndYears(Int32 years);
SQMOD_NODISCARD Datetime AndYears(int32_t years);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of months to obtain a new date.
*/
Datetime AndMonths(Int32 months);
SQMOD_NODISCARD Datetime AndMonths(int32_t months);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of days to obtain a new date.
*/
Datetime AndDays(Int32 days);
SQMOD_NODISCARD Datetime AndDays(int32_t days);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of hours to obtain a new time.
*/
Datetime AndHours(Int32 hours);
SQMOD_NODISCARD Datetime AndHours(int32_t hours);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of minutes to obtain a new time.
*/
Datetime AndMinutes(Int32 minutes);
SQMOD_NODISCARD Datetime AndMinutes(int32_t minutes);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of seconds to obtain a new time.
*/
Datetime AndSeconds(Int32 seconds);
SQMOD_NODISCARD Datetime AndSeconds(int32_t seconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of milliseconds to obtain a new time.
*/
Datetime AndMilliseconds(Int32 milliseconds);
SQMOD_NODISCARD Datetime AndMilliseconds(int32_t milliseconds);
/* ------------------------------------------------------------------------------------------------
* See whether the associated year is a leap year.
*/
bool IsThisLeapYear() const
SQMOD_NODISCARD bool IsThisLeapYear() const
{
return Chrono::IsLeapYear(m_Year);
}
@@ -545,7 +545,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the number of days in the associated year.
*/
Uint16 GetYearDays() const
SQMOD_NODISCARD uint16_t GetYearDays() const
{
return Chrono::DaysInYear(m_Year);
}
@@ -553,7 +553,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the number of days in the associated month.
*/
Uint8 GetMonthDays() const
SQMOD_NODISCARD uint8_t GetMonthDays() const
{
return Chrono::DaysInMonth(m_Year, m_Month);
}
@@ -561,17 +561,17 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the date from this date-time instance.
*/
Date GetDate() const;
SQMOD_NODISCARD Date GetDate() const;
/* ------------------------------------------------------------------------------------------------
* Retrieve the time from this date-time instance.
*/
Time GetTime() const;
SQMOD_NODISCARD Time GetTime() const;
/* ------------------------------------------------------------------------------------------------
* Convert this date-time instance to a time-stamp.
*/
Timestamp GetTimestamp() const;
SQMOD_NODISCARD Timestamp GetTimestamp() const;
};
} // Namespace:: SqMod
+48 -50
View File
@@ -1,28 +1,26 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Date.hpp"
#include "Library/Chrono/Datetime.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqTime"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqTime"))
// ------------------------------------------------------------------------------------------------
SQChar Time::Delimiter = ':';
// ------------------------------------------------------------------------------------------------
Int32 Time::Compare(const Time & o) const
int32_t Time::Compare(const Time & o) const
{
if (m_Hour < o.m_Hour)
{
{ // NOLINT(bugprone-branch-clone)
return -1;
}
else if (m_Hour > o.m_Hour)
{
{ // NOLINT(bugprone-branch-clone)
return 1;
}
else if (m_Minute < o.m_Minute)
@@ -80,9 +78,9 @@ Time Time::operator / (const Time & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Time::ToString() const
String Time::ToString() const
{
return ToStrF("%02u%c%02u%c%02u%c%u",
return fmt::format("{:02}{}{:02}{}{:02}{}{}",
m_Hour, m_Delimiter,
m_Minute, m_Delimiter,
m_Second, m_Delimiter,
@@ -90,7 +88,7 @@ CSStr Time::ToString() const
}
// ------------------------------------------------------------------------------------------------
void Time::Set(Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
void Time::Set(uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond)
{
// Is the specified hour within range?
if (hour >= 24)
@@ -120,7 +118,7 @@ void Time::Set(Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
}
// ------------------------------------------------------------------------------------------------
void Time::SetStr(CSStr str)
void Time::SetStr(const SQChar * str)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u : %u : %u : %u ");
@@ -140,19 +138,19 @@ void Time::SetStr(CSStr str)
fs[9] = m_Delimiter;
fs[14] = m_Delimiter;
// The sscanf function requires at least 32 bit integers
Uint32 hour = 0, minute = 0, second = 0, milli = 0;
uint32_t hour = 0, minute = 0, second = 0, milli = 0;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &hour, &minute, &second, &milli);
// Clamp the extracted values to the boundaries of associated type and assign them
Set(ClampL< Uint32, Uint8 >(hour),
ClampL< Uint32, Uint8 >(minute),
ClampL< Uint32, Uint8 >(second),
ClampL< Uint32, Uint16 >(milli)
Set(ClampL< uint32_t, uint8_t >(hour),
ClampL< uint32_t, uint8_t >(minute),
ClampL< uint32_t, uint8_t >(second),
ClampL< uint32_t, uint16_t >(milli)
);
}
// ------------------------------------------------------------------------------------------------
void Time::SetHour(Uint8 hour)
void Time::SetHour(uint8_t hour)
{
// Is the specified hour within range?
if (hour >= 24)
@@ -164,7 +162,7 @@ void Time::SetHour(Uint8 hour)
}
// ------------------------------------------------------------------------------------------------
void Time::SetMinute(Uint8 minute)
void Time::SetMinute(uint8_t minute)
{
// Is the specified minute within range?
if (minute >= 60)
@@ -176,7 +174,7 @@ void Time::SetMinute(Uint8 minute)
}
// ------------------------------------------------------------------------------------------------
void Time::SetSecond(Uint8 second)
void Time::SetSecond(uint8_t second)
{
// Is the specified second within range?
if (second >= 60)
@@ -188,7 +186,7 @@ void Time::SetSecond(Uint8 second)
}
// ------------------------------------------------------------------------------------------------
void Time::SetMillisecond(Uint16 millisecond)
void Time::SetMillisecond(uint16_t millisecond)
{
// Is the specified millisecond within range?
if (millisecond >= 1000)
@@ -200,7 +198,7 @@ void Time::SetMillisecond(Uint16 millisecond)
}
// ------------------------------------------------------------------------------------------------
Time & Time::AddHours(Int32 hours)
Time & Time::AddHours(int32_t hours)
{
// Did we even add any hours?
if (hours)
@@ -215,13 +213,13 @@ Time & Time::AddHours(Int32 hours)
}
// ------------------------------------------------------------------------------------------------
Time & Time::AddMinutes(Int32 minutes)
Time & Time::AddMinutes(int32_t minutes)
{
// Did we even add any minutes?
if (minutes)
{
// Extract the number of hours
Int32 hours = static_cast< Int32 >(minutes / 60);
auto hours = static_cast< int32_t >(minutes / 60);
// Extract the number of minutes
m_Minute += (minutes % 60);
// Are the minutes overlapping with the next hour?
@@ -243,13 +241,13 @@ Time & Time::AddMinutes(Int32 minutes)
}
// ------------------------------------------------------------------------------------------------
Time & Time::AddSeconds(Int32 seconds)
Time & Time::AddSeconds(int32_t seconds)
{
// Did we even add any seconds?
if (seconds)
{
// Extract the number of minutes
Int32 minutes = static_cast< Int32 >(seconds / 60);
auto minutes = static_cast< int32_t >(seconds / 60);
// Extract the number of seconds
m_Second += (seconds % 60);
// Are the seconds overlapping with the next minute?
@@ -271,13 +269,13 @@ Time & Time::AddSeconds(Int32 seconds)
}
// ------------------------------------------------------------------------------------------------
Time & Time::AddMilliseconds(Int32 milliseconds)
Time & Time::AddMilliseconds(int32_t milliseconds)
{
// Did we even add any milliseconds?
if (milliseconds)
{
// Extract the number of seconds
Int32 seconds = static_cast< Int32 >(milliseconds / 1000);
auto seconds = static_cast< int32_t >(milliseconds / 1000);
// Extract the number of milliseconds
m_Millisecond += (milliseconds / 1000);
// Are the milliseconds overlapping with the next second?
@@ -299,19 +297,19 @@ Time & Time::AddMilliseconds(Int32 milliseconds)
}
// ------------------------------------------------------------------------------------------------
Time Time::AndHours(Int32 hours)
Time Time::AndHours(int32_t hours)
{
// Did we even add any hours?
if (hours)
{
return Time((m_Hour + (hours % 24)) % 24, m_Minute, m_Second, m_Millisecond);
return Time(static_cast< uint8_t >((m_Hour + (hours % 24)) % 24), m_Minute, m_Second, m_Millisecond);
}
// Return the time as is
return Time(*this);
}
// ------------------------------------------------------------------------------------------------
Time Time::AndMinutes(Int32 minutes)
Time Time::AndMinutes(int32_t minutes)
{
// Did we even added any minutes?
if (!minutes)
@@ -319,7 +317,7 @@ Time Time::AndMinutes(Int32 minutes)
return Time(*this); // Return the time as is
}
// Extract the number of hours
Int32 hours = static_cast< Int32 >(minutes / 60);
auto hours = static_cast< int32_t >(minutes / 60);
// Extract the number of minutes
minutes = m_Minute + (minutes % 60);
// Are the minutes overlapping with the next hour?
@@ -335,13 +333,13 @@ Time Time::AndMinutes(Int32 minutes)
t.AddHours(hours);
}
// Assign the resulted minutes
t.m_Minute = (minutes % 60);
t.m_Minute = static_cast< uint8_t >(minutes % 60);
// Return the result
return t;
}
// ------------------------------------------------------------------------------------------------
Time Time::AndSeconds(Int32 seconds)
Time Time::AndSeconds(int32_t seconds)
{
// Did we even added any seconds?
if (!seconds)
@@ -349,7 +347,7 @@ Time Time::AndSeconds(Int32 seconds)
return Time(*this); // Return the time as is
}
// Extract the number of minutes
Int32 minutes = static_cast< Int32 >(seconds / 60);
auto minutes = static_cast< int32_t >(seconds / 60);
// Extract the number of seconds
seconds = m_Second + (seconds % 60);
// Are the seconds overlapping with the next minute?
@@ -365,13 +363,13 @@ Time Time::AndSeconds(Int32 seconds)
t.AddMinutes(minutes);
}
// Assign the resulted seconds
t.m_Second = (seconds % 60);
t.m_Second = static_cast< uint8_t >(seconds % 60);
// Return the result
return t;
}
// ------------------------------------------------------------------------------------------------
Time Time::AndMilliseconds(Int32 milliseconds)
Time Time::AndMilliseconds(int32_t milliseconds)
{
// Did we even added any milliseconds?
if (!milliseconds)
@@ -379,7 +377,7 @@ Time Time::AndMilliseconds(Int32 milliseconds)
return Time(*this); // Return the time as is
}
// Extract the number of seconds
Int32 seconds = static_cast< Int32 >(milliseconds / 1000);
auto seconds = static_cast< int32_t >(milliseconds / 1000);
// Extract the number of milliseconds
milliseconds = m_Millisecond + (milliseconds % 1000);
// Are the milliseconds overlapping with the next second?
@@ -395,7 +393,7 @@ Time Time::AndMilliseconds(Int32 milliseconds)
t.AddSeconds(seconds);
}
// Assign the resulted milliseconds
t.m_Millisecond = (milliseconds % 1000);
t.m_Millisecond = static_cast< uint16_t >(milliseconds % 1000);
// Return the result
return t;
}
@@ -404,10 +402,10 @@ Time Time::AndMilliseconds(Int32 milliseconds)
Timestamp Time::GetTimestamp() const
{
// Calculate the microseconds in the current time
Int64 ms = static_cast< Int64 >(m_Hour * 3600000000LL);
ms += static_cast< Int64 >(m_Minute * 60000000L);
ms += static_cast< Int64 >(m_Second * 1000000L);
ms += static_cast< Int64 >(m_Millisecond * 1000L);
auto ms = static_cast< int64_t >(m_Hour * 3600000000LL);
ms += static_cast< int64_t >(m_Minute * 60000000L);
ms += static_cast< int64_t >(m_Second * 1000000L);
ms += static_cast< int64_t >(m_Millisecond * 1000L);
// Return the resulted timestamp
return Timestamp(ms);
}
@@ -419,10 +417,10 @@ void Register_ChronoTime(HSQUIRRELVM vm, Table & /*cns*/)
Class< Time >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< Uint8 >()
.Ctor< Uint8, Uint8 >()
.Ctor< Uint8, Uint8, Uint8 >()
.Ctor< Uint8, Uint8, Uint8, Uint16 >()
.Ctor< uint8_t >()
.Ctor< uint8_t, uint8_t >()
.Ctor< uint8_t, uint8_t, uint8_t >()
.Ctor< uint8_t, uint8_t, uint8_t, uint16_t >()
// Static Properties
.SetStaticValue(_SC("GlobalDelimiter"), &Time::Delimiter)
// Core Meta-methods
@@ -454,10 +452,10 @@ void Register_ChronoTime(HSQUIRRELVM vm, Table & /*cns*/)
.Func(_SC("AndMillis"), &Time::AndMilliseconds)
.Func(_SC("AndMilliseconds"), &Time::AndMilliseconds)
// Overloaded Methods
.Overload< void (Time::*)(Uint8) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(Uint8, Uint8) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(Uint8, Uint8, Uint8) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(Uint8, Uint8, Uint8, Uint16) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(uint8_t) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(uint8_t, uint8_t) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(uint8_t, uint8_t, uint8_t) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(uint8_t, uint8_t, uint8_t, uint16_t) >(_SC("Set"), &Time::Set)
);
}
+36 -36
View File
@@ -21,15 +21,15 @@ protected:
/* ------------------------------------------------------------------------------------------------
* Compare the values of two instances.
*/
Int32 Compare(const Time & o) const;
SQMOD_NODISCARD int32_t Compare(const Time & o) const;
private:
// ------------------------------------------------------------------------------------------------
Uint8 m_Hour; // Hour
Uint8 m_Minute; // Minute
Uint8 m_Second; // Second
Uint16 m_Millisecond; // Millisecond
uint8_t m_Hour{}; // Hour
uint8_t m_Minute{}; // Minute
uint8_t m_Second{}; // Second
uint16_t m_Millisecond{}; // Millisecond
// ------------------------------------------------------------------------------------------------
SQChar m_Delimiter; // Component delimiter when generating strings.
@@ -52,7 +52,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Base constructor.
*/
Time(Uint8 hour)
explicit Time(uint8_t hour)
: m_Delimiter(Delimiter)
{
Set(hour, 0, 0, 0);
@@ -61,7 +61,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Base constructor.
*/
Time(Uint8 hour, Uint8 minute)
Time(uint8_t hour, uint8_t minute)
: m_Delimiter(Delimiter)
{
Set(hour, minute, 0, 0);
@@ -70,7 +70,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Base constructor.
*/
Time(Uint8 hour, Uint8 minute, Uint8 second)
Time(uint8_t hour, uint8_t minute, uint8_t second)
: m_Delimiter(Delimiter)
{
Set(hour, minute, second, 0);
@@ -79,7 +79,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Base constructor.
*/
Time(Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
Time(uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond)
: m_Delimiter(Delimiter)
{
Set(hour, minute, second, millisecond);
@@ -88,7 +88,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* String constructor.
*/
Time(CSStr str)
explicit Time(const SQChar * str)
: m_Delimiter(Delimiter)
{
SetStr(str);
@@ -190,7 +190,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Time & o) const
SQMOD_NODISCARD int32_t Cmp(const Time & o) const
{
return Compare(o);
}
@@ -198,12 +198,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint8 hour)
void Set(uint8_t hour)
{
Set(hour, m_Minute, m_Second, m_Millisecond);
}
@@ -211,7 +211,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint8 hour, Uint8 minute)
void Set(uint8_t hour, uint8_t minute)
{
Set(hour, minute, m_Second, m_Millisecond);
}
@@ -219,7 +219,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint8 hour, Uint8 minute, Uint8 second)
void Set(uint8_t hour, uint8_t minute, uint8_t second)
{
Set(hour, minute, second, m_Millisecond);
}
@@ -227,12 +227,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond);
void Set(uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
/* ------------------------------------------------------------------------------------------------
* Retrieve the local delimiter character.
*/
SQChar GetDelimiter() const
SQMOD_NODISCARD SQChar GetDelimiter() const
{
return m_Delimiter;
}
@@ -248,7 +248,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the values as a string.
*/
CSStr GetStr() const
SQMOD_NODISCARD String GetStr() const
{
return ToString();
}
@@ -256,12 +256,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Extract the values from a string.
*/
void SetStr(CSStr str);
void SetStr(const SQChar * str);
/* ------------------------------------------------------------------------------------------------
* Retrieve the hour component.
*/
Uint8 GetHour() const
SQMOD_NODISCARD uint8_t GetHour() const
{
return m_Hour;
}
@@ -269,12 +269,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the hour component.
*/
void SetHour(Uint8 hour);
void SetHour(uint8_t hour);
/* ------------------------------------------------------------------------------------------------
* Retrieve the minute component.
*/
Uint8 GetMinute() const
SQMOD_NODISCARD uint8_t GetMinute() const
{
return m_Minute;
}
@@ -282,12 +282,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the minute component.
*/
void SetMinute(Uint8 minute);
void SetMinute(uint8_t minute);
/* ------------------------------------------------------------------------------------------------
* Retrieve the second component.
*/
Uint8 GetSecond() const
SQMOD_NODISCARD uint8_t GetSecond() const
{
return m_Second;
}
@@ -295,12 +295,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the second component.
*/
void SetSecond(Uint8 second);
void SetSecond(uint8_t second);
/* ------------------------------------------------------------------------------------------------
* Retrieve the millisecond component.
*/
Uint16 GetMillisecond() const
SQMOD_NODISCARD uint16_t GetMillisecond() const
{
return m_Millisecond;
}
@@ -308,52 +308,52 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the millisecond component.
*/
void SetMillisecond(Uint16 millisecond);
void SetMillisecond(uint16_t millisecond);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of hours to the current time.
*/
Time & AddHours(Int32 hours);
Time & AddHours(int32_t hours);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of minutes to the current time.
*/
Time & AddMinutes(Int32 minutes);
Time & AddMinutes(int32_t minutes);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of seconds to the current time.
*/
Time & AddSeconds(Int32 seconds);
Time & AddSeconds(int32_t seconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of milliseconds to the current time.
*/
Time & AddMilliseconds(Int32 milliseconds);
Time & AddMilliseconds(int32_t milliseconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of hours to obtain a new time.
*/
Time AndHours(Int32 hours);
SQMOD_NODISCARD Time AndHours(int32_t hours);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of minutes to obtain a new time.
*/
Time AndMinutes(Int32 minutes);
SQMOD_NODISCARD Time AndMinutes(int32_t minutes);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of seconds to obtain a new time.
*/
Time AndSeconds(Int32 seconds);
SQMOD_NODISCARD Time AndSeconds(int32_t seconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of milliseconds to obtain a new time.
*/
Time AndMilliseconds(Int32 milliseconds);
SQMOD_NODISCARD Time AndMilliseconds(int32_t milliseconds);
/* ------------------------------------------------------------------------------------------------
* Convert this time instance to a time-stamp.
*/
Timestamp GetTimestamp() const;
SQMOD_NODISCARD Timestamp GetTimestamp() const;
};
} // Namespace:: SqMod
+8 -9
View File
@@ -1,13 +1,12 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Chrono/Timer.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqTimer"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqTimer"))
// ------------------------------------------------------------------------------------------------
Timer::Timer()
@@ -17,7 +16,7 @@ Timer::Timer()
}
// ------------------------------------------------------------------------------------------------
Int32 Timer::Cmp(const Timer & o) const
int32_t Timer::Cmp(const Timer & o) const
{
if (m_Timestamp == o.m_Timestamp)
return 0;
@@ -28,9 +27,9 @@ Int32 Timer::Cmp(const Timer & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Timer::ToString() const
String Timer::ToString() const
{
return ToStrF("%lld", m_Timestamp);
return fmt::format("{}", m_Timestamp);
}
// ------------------------------------------------------------------------------------------------
@@ -42,15 +41,15 @@ void Timer::Reset()
// ------------------------------------------------------------------------------------------------
Timestamp Timer::Restart()
{
const Int64 now = Chrono::GetCurrentSysTime(), elapsed = now - m_Timestamp;
const int64_t now = Chrono::GetCurrentSysTime(), elapsed = now - m_Timestamp;
m_Timestamp = now;
return Timestamp(elapsed);
}
// ------------------------------------------------------------------------------------------------
Int64 Timer::RestartRaw()
int64_t Timer::RestartRaw()
{
const Int64 now = Chrono::GetCurrentSysTime(), elapsed = now - m_Timestamp;
const int64_t now = Chrono::GetCurrentSysTime(), elapsed = now - m_Timestamp;
m_Timestamp = now;
return elapsed;
}
@@ -62,7 +61,7 @@ Timestamp Timer::GetElapsedTime() const
}
// ------------------------------------------------------------------------------------------------
Int64 Timer::GetElapsedTimeRaw() const
int64_t Timer::GetElapsedTimeRaw() const
{
return (Chrono::GetCurrentSysTime() - m_Timestamp);
}
+9 -16
View File
@@ -14,7 +14,7 @@ class Timer
/* --------------------------------------------------------------------------------------------
*
*/
Timer(Int64 t)
explicit Timer(int64_t t)
: m_Timestamp(t)
{
/* ... */
@@ -30,19 +30,12 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Timer(const Timer & o)
: m_Timestamp(o.m_Timestamp)
{
/* ... */
}
Timer(const Timer & o) = default;
/* --------------------------------------------------------------------------------------------
*
*/
~Timer()
{
/* ... */
}
~Timer() = default;
/* --------------------------------------------------------------------------------------------
*
@@ -56,12 +49,12 @@ public:
/* --------------------------------------------------------------------------------------------
* ...
*/
Int32 Cmp(const Timer & b) const;
SQMOD_NODISCARD int32_t Cmp(const Timer & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
*
@@ -76,22 +69,22 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Int64 RestartRaw();
int64_t RestartRaw();
/* --------------------------------------------------------------------------------------------
*
*/
Timestamp GetElapsedTime() const;
SQMOD_NODISCARD Timestamp GetElapsedTime() const;
/* --------------------------------------------------------------------------------------------
*
*/
Int64 GetElapsedTimeRaw() const;
SQMOD_NODISCARD int64_t GetElapsedTimeRaw() const;
private:
// --------------------------------------------------------------------------------------------
Int64 m_Timestamp;
int64_t m_Timestamp;
};
} // Namespace:: SqMod
+25 -28
View File
@@ -2,15 +2,13 @@
#include "Library/Chrono/Timestamp.hpp"
#include "Library/Chrono/Timer.hpp"
#include "Library/Chrono/Date.hpp"
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Datetime.hpp"
#include "Library/Numeric/LongInt.hpp"
#include "Library/Numeric/Long.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqTimestamp"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqTimestamp"))
// ------------------------------------------------------------------------------------------------
Timestamp::Timestamp(const SLongInt & t)
@@ -20,7 +18,7 @@ Timestamp::Timestamp(const SLongInt & t)
}
// ------------------------------------------------------------------------------------------------
Int32 Timestamp::Cmp(const Timestamp & o) const
int32_t Timestamp::Cmp(const Timestamp & o) const
{
if (m_Timestamp == o.m_Timestamp)
{
@@ -37,9 +35,9 @@ Int32 Timestamp::Cmp(const Timestamp & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Timestamp::ToString() const
String Timestamp::ToString() const
{
return ToStrF("%lld", m_Timestamp);
return fmt::format("{}", m_Timestamp);
}
// ------------------------------------------------------------------------------------------------
@@ -55,9 +53,9 @@ SLongInt Timestamp::GetMicroseconds() const
}
// ------------------------------------------------------------------------------------------------
void Timestamp::SetMicroseconds(const SLongInt & ammount)
void Timestamp::SetMicroseconds(const SLongInt & amount)
{
m_Timestamp = ammount.GetNum();
m_Timestamp = amount.GetNum();
}
// ------------------------------------------------------------------------------------------------
@@ -67,9 +65,9 @@ SLongInt Timestamp::GetMilliseconds() const
}
// ------------------------------------------------------------------------------------------------
void Timestamp::SetMilliseconds(const SLongInt & ammount)
void Timestamp::SetMilliseconds(const SLongInt & amount)
{
m_Timestamp = (ammount.GetNum() * 1000L);
m_Timestamp = (amount.GetNum() * 1000L);
}
// ------------------------------------------------------------------------------------------------
@@ -79,51 +77,51 @@ static Timestamp SqGetEpochTimeNow()
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetMicrosecondsRaw(Int64 ammount)
static Timestamp SqGetMicrosecondsRaw(int64_t amount)
{
return Timestamp(ammount);
return Timestamp(amount);
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetMicroseconds(const SLongInt & ammount)
static Timestamp SqGetMicroseconds(const SLongInt & amount)
{
return Timestamp(ammount);
return Timestamp(amount);
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetMilliseconds(SQInteger ammount)
static Timestamp SqGetMilliseconds(SQInteger amount)
{
return Timestamp(Int64(Int64(ammount) * 1000L));
return Timestamp(int64_t(int64_t(amount) * 1000L));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetSeconds(SQFloat ammount)
static Timestamp SqGetSeconds(SQFloat amount)
{
return Timestamp(Int64(Float64(ammount) * 1000000L));
return Timestamp(int64_t(double(amount) * 1000000L));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetMinutes(SQFloat ammount)
static Timestamp SqGetMinutes(SQFloat amount)
{
return Timestamp(Int64((Float64(ammount) * 60000000L)));
return Timestamp(int64_t((double(amount) * 60000000L)));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetHours(SQFloat ammount)
static Timestamp SqGetHours(SQFloat amount)
{
return Timestamp(Int64(Float64(ammount) * 3600000000LL));
return Timestamp(int64_t(double(amount) * 3600000000LL));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetDays(SQFloat ammount)
static Timestamp SqGetDays(SQFloat amount)
{
return Timestamp(Int64(Float64(ammount) * 86400000000LL));
return Timestamp(int64_t(double(amount) * 86400000000LL));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetYears(SQFloat ammount)
static Timestamp SqGetYears(SQFloat amount)
{
return Timestamp(Int64(Float64(ammount) * 31557600000000LL));
return Timestamp(int64_t(double(amount) * 31557600000000LL));
}
// ================================================================================================
@@ -174,7 +172,6 @@ void Register_ChronoTimestamp(HSQUIRRELVM vm, Table & /*cns*/)
.StaticFunc(_SC("GetDays"), &SqGetDays)
.StaticFunc(_SC("GetYears"), &SqGetYears)
);
;
}
} // Namespace:: SqMod
+52 -59
View File
@@ -31,7 +31,7 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Timestamp(Int64 t)
explicit Timestamp(int64_t t)
: m_Timestamp(t)
{
/* ... */
@@ -45,19 +45,12 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Timestamp(const Timestamp & o)
: m_Timestamp(o.m_Timestamp)
{
/* ... */
}
Timestamp(const Timestamp & o) = default;
/* --------------------------------------------------------------------------------------------
*
*/
~Timestamp()
{
/* ... */
}
~Timestamp() = default;
/* --------------------------------------------------------------------------------------------
*
@@ -103,12 +96,12 @@ public:
/* --------------------------------------------------------------------------------------------
* ...
*/
Int32 Cmp(const Timestamp & b) const;
SQMOD_NODISCARD int32_t Cmp(const Timestamp & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -118,7 +111,7 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Int64 GetNum() const
SQMOD_NODISCARD int64_t GetNum() const
{
return m_Timestamp;
}
@@ -126,17 +119,17 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
SLongInt GetMicroseconds() const;
SQMOD_NODISCARD SLongInt GetMicroseconds() const;
/* --------------------------------------------------------------------------------------------
*
*/
void SetMicroseconds(const SLongInt & ammount);
void SetMicroseconds(const SLongInt & amount);
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetMicrosecondsRaw() const
SQMOD_NODISCARD SQInteger GetMicrosecondsRaw() const
{
return SQInteger(m_Timestamp);
}
@@ -144,25 +137,25 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetMicrosecondsRaw(SQInteger ammount)
void SetMicrosecondsRaw(SQInteger amount)
{
m_Timestamp = ammount;
m_Timestamp = amount;
}
/* --------------------------------------------------------------------------------------------
*
*/
SLongInt GetMilliseconds() const;
SQMOD_NODISCARD SLongInt GetMilliseconds() const;
/* --------------------------------------------------------------------------------------------
*
*/
void SetMilliseconds(const SLongInt & ammount);
void SetMilliseconds(const SLongInt & amount);
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetMillisecondsRaw() const
SQMOD_NODISCARD SQInteger GetMillisecondsRaw() const
{
return SQInteger(m_Timestamp / 1000L);
}
@@ -170,31 +163,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetMillisecondsRaw(SQInteger ammount)
void SetMillisecondsRaw(SQInteger amount)
{
m_Timestamp = Int64(Int64(ammount) * 1000L);
m_Timestamp = int64_t(int64_t(amount) * 1000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetSecondsF() const
SQMOD_NODISCARD SQFloat GetSecondsF() const
{
return SQFloat(m_Timestamp / 1000000L);
return static_cast< SQFloat >(static_cast< int64_t >(m_Timestamp / 1000000LL));
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetSecondsF(SQFloat ammount)
void SetSecondsF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 1000000L);
m_Timestamp = int64_t(double(amount) * 1000000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetSecondsI() const
SQMOD_NODISCARD SQInteger GetSecondsI() const
{
return SQInteger(m_Timestamp / 1000000L);
}
@@ -202,31 +195,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetSecondsI(SQInteger ammount)
void SetSecondsI(SQInteger amount)
{
m_Timestamp = Int64(Int64(ammount) * 1000000L);
m_Timestamp = int64_t(int64_t(amount) * 1000000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetMinutesF() const
SQMOD_NODISCARD SQFloat GetMinutesF() const
{
return SQFloat(m_Timestamp / 60000000.0f);
return SQFloat(m_Timestamp / 60000000.0);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetMinutesF(SQFloat ammount)
void SetMinutesF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 60000000L);
m_Timestamp = int64_t(double(amount) * 60000000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetMinutesI() const
SQMOD_NODISCARD SQInteger GetMinutesI() const
{
return SQInteger(m_Timestamp / 60000000L);
}
@@ -234,31 +227,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetMinutesI(SQInteger ammount)
void SetMinutesI(SQInteger amount)
{
m_Timestamp = Int64(Int64(ammount) * 60000000L);
m_Timestamp = int64_t(int64_t(amount) * 60000000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetHoursF() const
SQMOD_NODISCARD SQFloat GetHoursF() const
{
return SQFloat(m_Timestamp / 3600000000.0d);
return SQFloat(m_Timestamp / 3600000000.0);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetHoursF(SQFloat ammount)
void SetHoursF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 3600000000LL);
m_Timestamp = int64_t(double(amount) * 3600000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetHoursI() const
SQMOD_NODISCARD SQInteger GetHoursI() const
{
return SQInteger(m_Timestamp / 3600000000LL);
}
@@ -266,31 +259,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetHoursI(SQInteger ammount)
void SetHoursI(SQInteger amount)
{
m_Timestamp = Int64(Float64(ammount) * 3600000000LL);
m_Timestamp = int64_t(double(amount) * 3600000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetDaysF() const
SQMOD_NODISCARD SQFloat GetDaysF() const
{
return SQFloat(m_Timestamp / 86400000000.0d);
return SQFloat(m_Timestamp / 86400000000.0);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetDaysF(SQFloat ammount)
void SetDaysF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 86400000000LL);
m_Timestamp = int64_t(double(amount) * 86400000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetDaysI() const
SQMOD_NODISCARD SQInteger GetDaysI() const
{
return SQInteger(m_Timestamp / 86400000000LL);
}
@@ -298,31 +291,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetDaysI(SQInteger ammount)
void SetDaysI(SQInteger amount)
{
m_Timestamp = Int64(Float64(ammount) * 86400000000LL);
m_Timestamp = int64_t(double(amount) * 86400000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetYearsF() const
SQMOD_NODISCARD SQFloat GetYearsF() const
{
return SQFloat(m_Timestamp / 31557600000000.0d);
return SQFloat(m_Timestamp / 31557600000000.0);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetYearsF(SQFloat ammount)
void SetYearsF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 31557600000000LL);
m_Timestamp = int64_t(double(amount) * 31557600000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetYearsI() const
SQMOD_NODISCARD SQInteger GetYearsI() const
{
return SQInteger(m_Timestamp / 31557600000000LL);
}
@@ -330,15 +323,15 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetYearsI(SQInteger ammount)
void SetYearsI(SQInteger amount)
{
m_Timestamp = Int64(Float64(ammount) * 31557600000000LL);
m_Timestamp = int64_t(double(amount) * 31557600000000LL);
}
private:
// --------------------------------------------------------------------------------------------
Int64 m_Timestamp;
int64_t m_Timestamp;
};
} // Namespace:: SqMod
+1 -11
View File
@@ -1,23 +1,13 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Crypt.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstdlib>
#include <cstring>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
extern void Register_Hash(HSQUIRRELVM vm);
extern void Register_AES(HSQUIRRELVM vm);
// ================================================================================================
void Register_Crypt(HSQUIRRELVM vm)
{
Register_Hash(vm);
Register_AES(vm);
}
} // Namespace:: SqMod
+1 -3
View File
@@ -1,11 +1,9 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
} // Namespace:: SqMod
-155
View File
@@ -1,155 +0,0 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Crypt/AES.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstdlib>
#include <cstring>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqAES256"))
// ------------------------------------------------------------------------------------------------
AES256::AES256()
: m_Context(), m_Buffer()
{
aes256_done(&m_Context);
}
// ------------------------------------------------------------------------------------------------
AES256::AES256(CSStr key)
: m_Context(), m_Buffer()
{
Init(key);
}
// ------------------------------------------------------------------------------------------------
Int32 AES256::Cmp(const AES256 & o) const
{
return std::memcmp(m_Buffer, o.m_Buffer, sizeof(m_Buffer));
}
// ------------------------------------------------------------------------------------------------
CSStr AES256::ToString() const
{
return ToStrF("%s", m_Buffer);
}
// ------------------------------------------------------------------------------------------------
CSStr AES256::GetKey() const
{
return reinterpret_cast< CSStr >(m_Buffer);
}
// ------------------------------------------------------------------------------------------------
bool AES256::Init(CSStr key)
{
// Clear current key, if any
aes256_done(&m_Context);
// Is the specified key empty?
if (!key || *key == '\0')
{
return false; // Leave the context with an empty key
}
// Obtain the specified key size
const Uint32 size = (std::strlen(key) * sizeof(SQChar));
// See if the key size is accepted
if (size > sizeof(m_Buffer))
{
STHROWF("The specified key is out of bounds: %u > %u", size, sizeof(m_Buffer));
}
// Initialize the key buffer to 0
std::memset(m_Buffer, 0, sizeof(m_Buffer));
// Copy the key into the key buffer
std::memcpy(m_Buffer, key, size);
// Initialize the context with the specified key
aes256_init(&m_Context, m_Buffer);
// This context was successfully initialized
return true;
}
// ------------------------------------------------------------------------------------------------
void AES256::Done()
{
aes256_done(&m_Context);
}
// ------------------------------------------------------------------------------------------------
String AES256::Encrypt(CSStr data)
{
// Is there any data to encrypt?
if (!data || *data == 0)
{
return String();
}
// Copy the data into an editable string
String str(data);
// Make sure that we have a size with a multiple of 16
if ((str.size() % 16) != 0)
{
str.resize(str.size() - (str.size() % 16) + 16);
}
// Encrypt in chunks of 16 characters
for (Uint32 n = 0; n < str.size(); n += 16)
{
aes256_encrypt_ecb(&m_Context, reinterpret_cast< Uint8 * >(&str[n]));
}
// Return ownership of the encrypted string
return str;
}
// ------------------------------------------------------------------------------------------------
String AES256::Decrypt(CSStr data)
{
// Is there any data to decrypt?
if (!data || *data == 0)
{
return String();
}
// Copy the data into an editable string
String str(data);
// Make sure that we have a size with a multiple of 16
if ((str.size() % 16) != 0)
{
str.resize(str.size() - (str.size() % 16) + 16);
}
// Decrypt inc chunks of 16 characters
for (Uint32 n = 0; n < str.size(); n += 16)
{
aes256_decrypt_ecb(&m_Context, reinterpret_cast< Uint8 * >(&str[n]));
}
// Remove null characters in case the string was not a multiple of 16 when encrypted
while (!str.empty() && str.back() == 0)
{
str.pop_back();
}
// Return ownership of the encrypted string
return str;
}
// ================================================================================================
void Register_AES(HSQUIRRELVM vm)
{
RootTable(vm).Bind(Typename::Str,
Class< AES256 >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< CSStr >()
// Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &AES256::ToString)
.Func(_SC("cmp"), &AES256::Cmp)
/* Properties */
.Prop(_SC("Key"), &AES256::GetKey)
/* Functions */
.Func(_SC("Init"), &AES256::Init)
.Func(_SC("Done"), &AES256::Done)
.Func(_SC("Encrypt"), &AES256::Encrypt)
.Func(_SC("Decrypt"), &AES256::Decrypt)
);
}
} // Namespace:: SqMod
-102
View File
@@ -1,102 +0,0 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
#include <aes256.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Simple wrapper around a the AES encryption context.
*/
class AES256
{
public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
AES256();
/* --------------------------------------------------------------------------------------------
* Construct with an explicit key.
*/
AES256(CSStr key);
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
AES256(const AES256 & o) = default;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
AES256(AES256 && o) = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~AES256() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
AES256 & operator = (const AES256 & o) = default;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
AES256 & operator = (AES256 && o) = default;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const AES256 & o) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the associated key.
*/
CSStr GetKey() const;
/* --------------------------------------------------------------------------------------------
* Initialize the context key.
*/
bool Init(CSStr key);
/* --------------------------------------------------------------------------------------------
* Reset the associated context.
*/
void Done();
/* --------------------------------------------------------------------------------------------
* Encrypt the specified string.
*/
String Encrypt(CSStr data);
/* --------------------------------------------------------------------------------------------
* Decrypt the specified string.
*/
String Decrypt(CSStr data);
private:
/* --------------------------------------------------------------------------------------------
* The managed encryption context.
*/
aes256_context m_Context;
/* --------------------------------------------------------------------------------------------
* The key used to encrypt data.
*/
Uint8 m_Buffer[32]{0};
};
} // Namespace:: SqMod
-192
View File
@@ -1,192 +0,0 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Crypt/Hash.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
#include <crc32.h>
#include <keccak.h>
#include <md5.h>
#include <sha1.h>
#include <sha256.h>
#include <sha3.h>
#include <b64.h>
#include <whirlpool.h>
// ------------------------------------------------------------------------------------------------
#include <cstdlib>
#include <cstring>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Utility to avoid creating encoder instances for each call.
*/
template < class T > struct BaseHash
{
static T Algo;
};
// ------------------------------------------------------------------------------------------------
template < class T > T BaseHash< T >::Algo;
/* ------------------------------------------------------------------------------------------------
* Hash the specified value or the result of a formatted string.
*/
template < class T > static SQInteger HashF(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.Proc(true)))
{
return val.mRes; // Propagate the error!
}
// Forward the call to the actual implementation and store the string
String str(BaseHash< T >::Algo(val.mPtr));
// Push the string on the stack
sq_pushstring(vm, str.data(), str.size());
// At this point we have a valid string on the stack
return 1;
}
/* ------------------------------------------------------------------------------------------------
* Hash the specified value or the result of a formatted string with whirlpool algorithm.
*/
static SQInteger WhirlpoolF(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.Proc(true)))
{
return val.mRes; // Propagate the error!
}
// Prepare a whirlpool hashing context
whirlpool_ctx ctx;
// Initialize the hashing context
rhash_whirlpool_init(&ctx);
// Update the context with the given string
rhash_whirlpool_update(&ctx, reinterpret_cast< const unsigned char * >(val.mPtr),
val.mLen < 0 ? 0 : static_cast< size_t >(val.mLen));
// Reserve space for the result in binary form
unsigned char raw_hash[whirlpool_block_size];
// Finalize hashing and obtain the result
rhash_whirlpool_final(&ctx, raw_hash);
// Reserve space for the hexadecimal string
char hex_hash[whirlpool_block_size * 2];
// Convert from binary form to hex string
for (int i = 0, p = 0; i < whirlpool_block_size; ++i)
{
static const char dec2hex[16+1] = "0123456789abcdef";
hex_hash[p++] = dec2hex[(raw_hash[i] >> 4) & 15];
hex_hash[p++] = dec2hex[ raw_hash[i] & 15];
}
// Push the string on the stack
sq_pushstring(vm, hex_hash, whirlpool_block_size * 2);
// At this point we have a valid string on the stack
return 1;
}
/* ------------------------------------------------------------------------------------------------
* Encode the specified value or the result of a formatted string with base64 algorithm.
*/
static SQInteger EncodeBase64F(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.Proc(true)))
{
return val.mRes; // Propagate the error!
}
// Size of the encoded string
size_t enclen = 0;
// Attempt to encode the resulted string
char * result = b64_encode_ex(reinterpret_cast< const unsigned char * >(val.mPtr),
val.mLen < 0 ? 0 : static_cast< size_t >(val.mLen), &enclen);
// Did we fail to allocate memory for it?
if (!result)
{
return sq_throwerror(vm, _SC("Unable to allocate memory for output"));
}
// Push the string on the stack
sq_pushstring(vm, result, ConvTo< SQInteger >::From(enclen));
// At this point we have a valid string on the stack
return 1;
}
/* ------------------------------------------------------------------------------------------------
* Decode the specified value or the result of a formatted string with base64 algorithm.
*/
static SQInteger DecodeBase64F(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.Proc(true)))
{
return val.mRes; // Propagate the error!
}
// Size of the decoded string
size_t declen = 0;
// Attempt to decode the resulted string
unsigned char * result = b64_decode_ex(val.mPtr, val.mLen < 0 ? 0 : static_cast< size_t >(val.mLen), &declen);
// Did we fail to allocate memory for it?
if (!result)
{
return sq_throwerror(vm, _SC("Unable to allocate memory for output"));
}
// Push the string on the stack
sq_pushstring(vm, reinterpret_cast< CSStr >(result), ConvTo< SQInteger >::From(declen));
// At this point we have a valid string on the stack
return 1;
}
// ================================================================================================
template < class T > static void RegisterWrapper(Table & hashns, CCStr cname)
{
typedef HashWrapper< T > Hash;
hashns.Bind(cname,
Class< Hash >(hashns.GetVM(), cname)
// Constructors
.Ctor()
// Meta-methods
.Func(_SC("_tostring"), &Hash::ToString)
// Properties
.Prop(_SC("Hash"), &Hash::GetHash)
// Functions
.Func(_SC("Reset"), &Hash::Reset)
.Func(_SC("Compute"), &Hash::Compute)
.Func(_SC("GetHash"), &Hash::GetHash)
.Func(_SC("Add"), &Hash::AddStr)
.Func(_SC("AddStr"), &Hash::AddStr)
);
}
// ================================================================================================
void Register_Hash(HSQUIRRELVM vm)
{
Table hashns(vm);
RegisterWrapper< CRC32 >(hashns, _SC("CRC32"));
RegisterWrapper< Keccak >(hashns, _SC("Keccak"));
RegisterWrapper< MD5 >(hashns, _SC("MD5"));
RegisterWrapper< SHA1 >(hashns, _SC("SHA1"));
RegisterWrapper< SHA256 >(hashns, _SC("SHA256"));
RegisterWrapper< SHA3 >(hashns, _SC("SHA3"));
hashns.SquirrelFunc(_SC("GetCRC32"), &HashF< CRC32 >);
hashns.SquirrelFunc(_SC("GetKeccak"), &HashF< Keccak >);
hashns.SquirrelFunc(_SC("GetMD5"), &HashF< MD5 >);
hashns.SquirrelFunc(_SC("GetSHA1"), &HashF< SHA1 >);
hashns.SquirrelFunc(_SC("GetSHA256"), &HashF< SHA256 >);
hashns.SquirrelFunc(_SC("GetSHA3"), &HashF< SHA3 >);
hashns.SquirrelFunc(_SC("GetWhirlpool"), &WhirlpoolF);
hashns.SquirrelFunc(_SC("EncodeBase64"), &EncodeBase64F);
hashns.SquirrelFunc(_SC("DecodeBase64"), &DecodeBase64F);
RootTable(vm).Bind(_SC("SqHash"), hashns);
}
} // Namespace:: SqMod
-99
View File
@@ -1,99 +0,0 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Simple class to maintain the state of an encoder.
*/
template < class T > class HashWrapper
{
public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
HashWrapper()
: m_Encoder()
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy operator.
*/
HashWrapper(const HashWrapper & o)
: m_Encoder(o.m_Encoder)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~HashWrapper()
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
HashWrapper & operator = (const HashWrapper & o)
{
m_Encoder = o.m_Encoder;
return *this;
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
String ToString()
{
return m_Encoder.getHash();
}
/* --------------------------------------------------------------------------------------------
* Reset the encoder state.
*/
void Reset()
{
m_Encoder.reset();
}
/* --------------------------------------------------------------------------------------------
* Compute the hash of the specified string.
*/
String Compute(const String & str)
{
return m_Encoder(str);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the hash value of the data hashed so far.
*/
String GetHash()
{
return m_Encoder.getHash();
}
/* --------------------------------------------------------------------------------------------
* Add a string value to be hashed.
*/
void AddStr(const String & str)
{
m_Encoder.add(str.data(), str.length() * sizeof(String::value_type));
}
private:
/* --------------------------------------------------------------------------------------------
* The managed encoder state.
*/
T m_Encoder;
};
} // Namespace:: SqMod
+2
View File
@@ -5,11 +5,13 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
extern void Register_Buffer(HSQUIRRELVM vm);
extern void Register_INI(HSQUIRRELVM vm);
// ================================================================================================
void Register_IO(HSQUIRRELVM vm)
{
Register_Buffer(vm);
Register_INI(vm);
}
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -1,25 +1,20 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Utils/Buffer.hpp"
#include "Library/Numeric/LongInt.hpp"
#include "Library/IO/Buffer.hpp"
#include "Library/Numeric/Long.hpp"
#include "Base/AABB.hpp"
#include "Base/Circle.hpp"
#include "Base/Color3.hpp"
#include "Base/Color4.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Sphere.hpp"
#include "Base/Vector2.hpp"
#include "Base/Vector2i.hpp"
#include "Base/Vector3.hpp"
#include "Base/Vector4.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstring>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqBuffer"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqBuffer"))
// ------------------------------------------------------------------------------------------------
void SqBuffer::WriteInt64(const SLongInt & val)
@@ -27,7 +22,7 @@ void SqBuffer::WriteInt64(const SLongInt & val)
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Int64 >(val.GetNum());
m_Buffer->Push< int64_t >(val.GetNum());
}
// ------------------------------------------------------------------------------------------------
@@ -36,7 +31,7 @@ void SqBuffer::WriteUint64(const ULongInt & val)
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Uint64 >(val.GetNum());
m_Buffer->Push< uint64_t >(val.GetNum());
}
// ------------------------------------------------------------------------------------------------
@@ -72,11 +67,11 @@ SQInteger SqBuffer::WriteClientString(StackStrF & val)
STHROWF("String too large");
}
// Calculate the string length
Uint16 length = ConvTo< Uint16 >::From(val.mLen);
uint16_t length = ConvTo< uint16_t >::From(val.mLen);
// Change the size endianness to big endian
Uint16 size = ((length >> 8) & 0xFF) | ((length & 0xFF) << 8);
auto size = static_cast< uint16_t >(((length >> 8) & 0xFF) | ((length & 0xFF) << 8));
// Write the size and then the string contents
m_Buffer->Push< Uint16 >(size);
m_Buffer->Push< uint16_t >(size);
m_Buffer->AppendS(val.mPtr, length);
// Return the length of the written string
return val.mLen;
@@ -178,9 +173,9 @@ SLongInt SqBuffer::ReadInt64()
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Int64 value = m_Buffer->Cursor< Int64 >();
const int64_t value = m_Buffer->Cursor< int64_t >();
// Advance the buffer cursor
m_Buffer->Advance< Int64 >(1);
m_Buffer->Advance< int64_t >(1);
// Return the requested information
return SLongInt(value);
}
@@ -191,9 +186,9 @@ ULongInt SqBuffer::ReadUint64()
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Uint64 value = m_Buffer->Cursor< Uint64 >();
const uint64_t value = m_Buffer->Cursor< uint64_t >();
// Advance the buffer cursor
m_Buffer->Advance< Uint64 >(1);
m_Buffer->Advance< uint64_t >(1);
// Return the requested information
return ULongInt(value);
}
@@ -209,7 +204,7 @@ LightObj SqBuffer::ReadRawString(SQInteger length)
if (length < 0)
{
// Grab the buffer range to search for
CCStr ptr = &m_Buffer->Cursor(), itr = ptr, end = m_Buffer->End();
const char * ptr = &m_Buffer->Cursor(), * itr = ptr, * end = m_Buffer->End();
// Attempt to look for a string terminator
while (itr != end && *itr != '\0')
{
@@ -244,17 +239,17 @@ LightObj SqBuffer::ReadClientString()
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
Uint16 length = m_Buffer->Cursor< Uint16 >();
uint16_t length = m_Buffer->Cursor< uint16_t >();
// Convert the length to little endian
length = ((length >> 8) & 0xFF) | ((length & 0xFF) << 8);
length = static_cast< uint16_t >(((length >> 8) & 0xFF) | ((length & 0xFF) << 8));
// Validate the obtained length
if ((m_Buffer->Position() + sizeof(Uint16) + length) > m_Buffer->Capacity())
if ((m_Buffer->Position() + sizeof(uint16_t) + length) > m_Buffer->Capacity())
{
STHROWF("String of size (%u) starting at (%u) is out of buffer capacity (%u)",
length, m_Buffer->Position() + sizeof(Uint16), m_Buffer->Capacity());
length, m_Buffer->Position() + sizeof(uint16_t), m_Buffer->Capacity());
}
// Advance the buffer to the actual string
m_Buffer->Advance< Uint16 >(1);
m_Buffer->Advance< uint16_t >(1);
// Remember the current stack size
const StackGuard sg;
// Attempt to create the string as an object
@@ -1,8 +1,8 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Base/Buffer.hpp"
#include "Core/Buffer.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -39,11 +39,6 @@ public:
public:
/* --------------------------------------------------------------------------------------------
* Create a memory buffer with the requested size.
*/
static Object Create(SzType n);
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
@@ -56,7 +51,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Allocate constructor.
*/
SqBuffer(SQInteger n)
explicit SqBuffer(SQInteger n)
: m_Buffer(new Buffer(ConvTo< SzType >::From(n)))
{
/* ... */
@@ -92,7 +87,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Reference constructor.
*/
SqBuffer(const SRef & ref)
explicit SqBuffer(const SRef & ref) // NOLINT(modernize-pass-by-value)
: m_Buffer(ref)
{
/* ... */
@@ -101,7 +96,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Buffer constructor.
*/
SqBuffer(const Buffer & b)
explicit SqBuffer(const Buffer & b)
: m_Buffer(new Buffer(b))
{
/* ... */
@@ -110,7 +105,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Buffer constructor.
*/
SqBuffer(Buffer && b)
explicit SqBuffer(Buffer && b)
: m_Buffer(new Buffer(std::move(b)))
{
/* ... */
@@ -144,7 +139,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve a reference to the managed memory buffer.
*/
const SRef & GetRef() const
SQMOD_NODISCARD const SRef & GetRef() const
{
return m_Buffer;
}
@@ -181,7 +176,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve a certain element type at the specified position.
*/
Value Get(SQInteger n) const
SQMOD_NODISCARD Value Get(SQInteger n) const
{
// Validate the managed buffer reference
Validate();
@@ -203,7 +198,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the front of the buffer.
*/
Value GetFront() const
SQMOD_NODISCARD Value GetFront() const
{
// Validate the managed buffer reference
Validate();
@@ -225,7 +220,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element after the first element in the buffer.
*/
Value GetNext() const
SQMOD_NODISCARD Value GetNext() const
{
// Validate the managed buffer reference
Validate();
@@ -247,7 +242,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the back of the buffer.
*/
Value GetBack() const
SQMOD_NODISCARD Value GetBack() const
{
// Validate the managed buffer reference
Validate();
@@ -269,7 +264,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element before the last element in the buffer.
*/
Value GetPrev() const
SQMOD_NODISCARD Value GetPrev() const
{
// Validate the managed buffer reference
Validate();
@@ -335,7 +330,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element at the cursor position.
*/
Value GetCursor() const
SQMOD_NODISCARD Value GetCursor() const
{
// Validate the managed buffer reference
Validate();
@@ -357,7 +352,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element before the cursor position.
*/
Value GetBefore() const
SQMOD_NODISCARD Value GetBefore() const
{
// Validate the managed buffer reference
Validate();
@@ -379,7 +374,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the element after the cursor position.
*/
Value GetAfter() const
SQMOD_NODISCARD Value GetAfter() const
{
// Validate the managed buffer reference
Validate();
@@ -401,7 +396,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve maximum elements it can hold for a certain type.
*/
SzType GetMax() const
SQMOD_NODISCARD SzType GetMax() const // NOLINT(readability-convert-member-functions-to-static)
{
return Buffer::Max();
}
@@ -409,7 +404,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current buffer capacity in element count.
*/
SzType GetSize() const
SQMOD_NODISCARD SzType GetSize() const
{
// Validate the managed buffer reference
Validate();
@@ -420,7 +415,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current buffer capacity in byte count.
*/
SzType GetCapacity() const
SQMOD_NODISCARD SzType GetCapacity() const
{
// Validate the managed buffer reference
Validate();
@@ -431,7 +426,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the current position of the cursor in the buffer.
*/
SzType GetPosition() const
SQMOD_NODISCARD SzType GetPosition() const
{
// Validate the managed buffer reference
Validate();
@@ -442,7 +437,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of unused buffer after the edit cursor.
*/
SzType GetRemaining() const
SQMOD_NODISCARD SzType GetRemaining() const
{
// Validate the managed buffer reference
Validate();
@@ -490,7 +485,7 @@ public:
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Int8 >(ConvTo< Int8 >::From(val));
m_Buffer->Push< int8_t >(ConvTo< int8_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
@@ -501,7 +496,7 @@ public:
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Uint8 >(ConvTo< Uint8 >::From(val));
m_Buffer->Push< uint8_t >(ConvTo< uint8_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
@@ -512,7 +507,7 @@ public:
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Int16 >(ConvTo< Int16 >::From(val));
m_Buffer->Push< int16_t >(ConvTo< int16_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
@@ -523,7 +518,7 @@ public:
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Uint16 >(ConvTo< Uint16 >::From(val));
m_Buffer->Push< uint16_t >(ConvTo< uint16_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
@@ -534,7 +529,7 @@ public:
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Int32 >(ConvTo< Int32 >::From(val));
m_Buffer->Push< int32_t >(ConvTo< int32_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
@@ -545,7 +540,7 @@ public:
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Uint32 >(ConvTo< Uint32 >::From(val));
m_Buffer->Push< uint32_t >(ConvTo< uint32_t >::From(val));
}
/* --------------------------------------------------------------------------------------------
@@ -566,7 +561,7 @@ public:
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Float32 >(ConvTo< Float32 >::From(val));
m_Buffer->Push< float >(ConvTo< float >::From(val));
}
/* --------------------------------------------------------------------------------------------
@@ -577,7 +572,7 @@ public:
// Validate the managed buffer reference
Validate();
// Perform the requested operation
m_Buffer->Push< Float64 >(ConvTo< Float64 >::From(val));
m_Buffer->Push< double >(ConvTo< double >::From(val));
}
/* --------------------------------------------------------------------------------------------
@@ -648,9 +643,9 @@ public:
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Int8 value = m_Buffer->Cursor< Int8 >();
const int8_t value = m_Buffer->Cursor< int8_t >();
// Advance the buffer cursor
m_Buffer->Advance< Int8 >(1);
m_Buffer->Advance< int8_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
@@ -663,9 +658,9 @@ public:
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Uint8 value = m_Buffer->Cursor< Uint8 >();
const uint8_t value = m_Buffer->Cursor< uint8_t >();
// Advance the buffer cursor
m_Buffer->Advance< Uint8 >(1);
m_Buffer->Advance< uint8_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
@@ -678,9 +673,9 @@ public:
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Int16 value = m_Buffer->Cursor< Int16 >();
const int16_t value = m_Buffer->Cursor< int16_t >();
// Advance the buffer cursor
m_Buffer->Advance< Int16 >(1);
m_Buffer->Advance< int16_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
@@ -693,9 +688,9 @@ public:
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Uint16 value = m_Buffer->Cursor< Uint16 >();
const uint16_t value = m_Buffer->Cursor< uint16_t >();
// Advance the buffer cursor
m_Buffer->Advance< Uint16 >(1);
m_Buffer->Advance< uint16_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
@@ -708,9 +703,9 @@ public:
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Int32 value = m_Buffer->Cursor< Int32 >();
const int32_t value = m_Buffer->Cursor< int32_t >();
// Advance the buffer cursor
m_Buffer->Advance< Int32 >(1);
m_Buffer->Advance< int32_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
@@ -723,9 +718,9 @@ public:
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Uint32 value = m_Buffer->Cursor< Uint32 >();
const uint32_t value = m_Buffer->Cursor< uint32_t >();
// Advance the buffer cursor
m_Buffer->Advance< Uint32 >(1);
m_Buffer->Advance< uint32_t >(1);
// Return the requested information
return ConvTo< SQInteger >::From(value);
}
@@ -748,9 +743,9 @@ public:
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Float32 value = m_Buffer->Cursor< Float32 >();
const float value = m_Buffer->Cursor< float >();
// Advance the buffer cursor
m_Buffer->Advance< Float32 >(1);
m_Buffer->Advance< float >(1);
// Return the requested information
return ConvTo< SQFloat >::From(value);
}
@@ -763,9 +758,9 @@ public:
// Validate the managed buffer reference
ValidateDeeper();
// Read one element from the buffer
const Float64 value = m_Buffer->Cursor< Float64 >();
const double value = m_Buffer->Cursor< double >();
// Advance the buffer cursor
m_Buffer->Advance< Float64 >(1);
m_Buffer->Advance< double >(1);
// Return the requested information
return ConvTo< SQFloat >::From(value);
}
+59 -59
View File
@@ -2,15 +2,15 @@
#include "Library/IO/INI.hpp"
// ------------------------------------------------------------------------------------------------
#include <cerrno>
#include <sqratConst.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(ResultTypename, _SC("SqIniResult"))
SQMODE_DECL_TYPENAME(EntriesTypename, _SC("SqIniEntries"))
SQMODE_DECL_TYPENAME(DocumentTypename, _SC("SqIniDocument"))
SQMOD_DECL_TYPENAME(ResultTypename, _SC("SqIniResult"))
SQMOD_DECL_TYPENAME(EntriesTypename, _SC("SqIniEntries"))
SQMOD_DECL_TYPENAME(DocumentTypename, _SC("SqIniDocument"))
// ------------------------------------------------------------------------------------------------
void IniResult::Check() const
@@ -30,7 +30,7 @@ void IniResult::Check() const
case SI_OK:
case SI_UPDATED:
case SI_INSERTED:
break; /* These are not error messahes. */
break; /* These are not error messages. */
default:
STHROWF("Unable to %s for some unforeseen reason", m_Action.c_str());
}
@@ -47,7 +47,7 @@ void IniDocumentRef::Validate() const
}
// ------------------------------------------------------------------------------------------------
Int32 IniEntries::Cmp(const IniEntries & o) const
int32_t IniEntries::Cmp(const IniEntries & o) const
{
if (m_Elem == o.m_Elem)
{
@@ -84,7 +84,7 @@ void IniEntries::Prev()
}
// ------------------------------------------------------------------------------------------------
void IniEntries::Advance(Int32 n)
void IniEntries::Advance(int32_t n)
{
// Are there any other elements ahead?
if (m_List.empty() || m_Elem == m_List.end())
@@ -99,7 +99,7 @@ void IniEntries::Advance(Int32 n)
}
// ------------------------------------------------------------------------------------------------
void IniEntries::Retreat(Int32 n)
void IniEntries::Retreat(int32_t n)
{
// Are there any other elements behind?
if (m_List.empty() || m_Elem == m_List.begin())
@@ -114,7 +114,7 @@ void IniEntries::Retreat(Int32 n)
}
// ------------------------------------------------------------------------------------------------
CSStr IniEntries::GetItem() const
const SQChar * IniEntries::GetItem() const
{
// is the current element valid?
if (m_List.empty() || m_Elem == m_List.end())
@@ -126,7 +126,7 @@ CSStr IniEntries::GetItem() const
}
// ------------------------------------------------------------------------------------------------
CSStr IniEntries::GetComment() const
const SQChar * IniEntries::GetComment() const
{
// is the current element valid?
if (m_List.empty() || m_Elem == m_List.end())
@@ -138,7 +138,7 @@ CSStr IniEntries::GetComment() const
}
// ------------------------------------------------------------------------------------------------
Int32 IniEntries::GetOrder() const
int32_t IniEntries::GetOrder() const
{
// is the current element valid?
if (m_List.empty() || m_Elem == m_List.end())
@@ -150,7 +150,7 @@ Int32 IniEntries::GetOrder() const
}
// ------------------------------------------------------------------------------------------------
Int32 IniDocument::Cmp(const IniDocument & o) const
int32_t IniDocument::Cmp(const IniDocument & o) const
{
if (m_Doc == o.m_Doc)
{
@@ -167,7 +167,7 @@ Int32 IniDocument::Cmp(const IniDocument & o) const
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::LoadFile(CSStr filepath)
IniResult IniDocument::LoadFile(const SQChar * filepath)
{
// Validate the handle
m_Doc.Validate();
@@ -176,7 +176,7 @@ IniResult IniDocument::LoadFile(CSStr filepath)
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::LoadData(CSStr source, Int32 size)
IniResult IniDocument::LoadData(const SQChar * source, int32_t size)
{
// Validate the handle
m_Doc.Validate();
@@ -185,7 +185,7 @@ IniResult IniDocument::LoadData(CSStr source, Int32 size)
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SaveFile(CSStr filepath, bool signature)
IniResult IniDocument::SaveFile(const SQChar * filepath, bool signature)
{
// Validate the handle
m_Doc.Validate();
@@ -227,7 +227,7 @@ IniEntries IniDocument::GetAllSections() const
}
// ------------------------------------------------------------------------------------------------
IniEntries IniDocument::GetAllKeys(CSStr section) const
IniEntries IniDocument::GetAllKeys(const SQChar * section) const
{
// Validate the handle
m_Doc.Validate();
@@ -240,7 +240,7 @@ IniEntries IniDocument::GetAllKeys(CSStr section) const
}
// ------------------------------------------------------------------------------------------------
IniEntries IniDocument::GetAllValues(CSStr section, CSStr key) const
IniEntries IniDocument::GetAllValues(const SQChar * section, const SQChar * key) const
{
// Validate the handle
m_Doc.Validate();
@@ -253,7 +253,7 @@ IniEntries IniDocument::GetAllValues(CSStr section, CSStr key) const
}
// ------------------------------------------------------------------------------------------------
Int32 IniDocument::GetSectionSize(CSStr section) const
int32_t IniDocument::GetSectionSize(const SQChar * section) const
{
// Validate the handle
m_Doc.Validate();
@@ -262,11 +262,11 @@ Int32 IniDocument::GetSectionSize(CSStr section) const
}
// ------------------------------------------------------------------------------------------------
bool IniDocument::HasMultipleKeys(CSStr section, CSStr key) const
bool IniDocument::HasMultipleKeys(const SQChar * section, const SQChar * key) const
{
// Validate the handle
m_Doc.Validate();
// Where to retrive whether the key has multiple instances
// Where to retrieve whether the key has multiple instances
bool multiple = false;
// Attempt to query the information
if (m_Doc->GetValue(section, key, nullptr, &multiple) == nullptr)
@@ -278,7 +278,7 @@ bool IniDocument::HasMultipleKeys(CSStr section, CSStr key) const
}
// ------------------------------------------------------------------------------------------------
CCStr IniDocument::GetValue(CSStr section, CSStr key, CSStr def) const
const char * IniDocument::GetValue(const SQChar * section, const SQChar * key, const SQChar * def) const
{
// Validate the handle
m_Doc.Validate();
@@ -287,16 +287,16 @@ CCStr IniDocument::GetValue(CSStr section, CSStr key, CSStr def) const
}
// ------------------------------------------------------------------------------------------------
SQInteger IniDocument::GetInteger(CSStr section, CSStr key, SQInteger def) const
SQInteger IniDocument::GetInteger(const SQChar * section, const SQChar * key, SQInteger def) const
{
// Validate the handle
m_Doc.Validate();
// Attempt to query the information and return it
return static_cast< SQInteger >(m_Doc->GetLongValue(section, key, def, nullptr));
return static_cast< SQInteger >(m_Doc->GetLongValue(section, key, static_cast< long >(def), nullptr));
}
// ------------------------------------------------------------------------------------------------
SQFloat IniDocument::GetFloat(CSStr section, CSStr key, SQFloat def) const
SQFloat IniDocument::GetFloat(const SQChar * section, const SQChar * key, SQFloat def) const
{
// Validate the handle
m_Doc.Validate();
@@ -305,7 +305,7 @@ SQFloat IniDocument::GetFloat(CSStr section, CSStr key, SQFloat def) const
}
// ------------------------------------------------------------------------------------------------
bool IniDocument::GetBoolean(CSStr section, CSStr key, bool def) const
bool IniDocument::GetBoolean(const SQChar * section, const SQChar * key, bool def) const
{
// Validate the handle
m_Doc.Validate();
@@ -314,7 +314,7 @@ bool IniDocument::GetBoolean(CSStr section, CSStr key, bool def) const
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SetValue(CSStr section, CSStr key, CSStr value, bool force, CSStr comment)
IniResult IniDocument::SetValue(const SQChar * section, const SQChar * key, const SQChar * value, bool force, const SQChar * comment)
{
// Validate the handle
m_Doc.Validate();
@@ -323,16 +323,16 @@ IniResult IniDocument::SetValue(CSStr section, CSStr key, CSStr value, bool forc
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force, CSStr comment)
IniResult IniDocument::SetInteger(const SQChar * section, const SQChar * key, SQInteger value, bool hex, bool force, const SQChar * comment)
{
// Validate the handle
m_Doc.Validate();
// Attempt to apply the specified information and return the result
return IniResult("set INI integer", m_Doc->SetLongValue(section, key, value, comment, hex, force));
return IniResult("set INI integer", m_Doc->SetLongValue(section, key, static_cast< long >(value), comment, hex, force));
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SetFloat(CSStr section, CSStr key, SQFloat value, bool force, CSStr comment)
IniResult IniDocument::SetFloat(const SQChar * section, const SQChar * key, SQFloat value, bool force, const SQChar * comment)
{
// Validate the handle
m_Doc.Validate();
@@ -341,7 +341,7 @@ IniResult IniDocument::SetFloat(CSStr section, CSStr key, SQFloat value, bool fo
}
// ------------------------------------------------------------------------------------------------
IniResult IniDocument::SetBoolean(CSStr section, CSStr key, bool value, bool force, CSStr comment)
IniResult IniDocument::SetBoolean(const SQChar * section, const SQChar * key, bool value, bool force, const SQChar * comment)
{
// Validate the handle
m_Doc.Validate();
@@ -350,7 +350,7 @@ IniResult IniDocument::SetBoolean(CSStr section, CSStr key, bool value, bool for
}
// ------------------------------------------------------------------------------------------------
bool IniDocument::DeleteValue(CSStr section, CSStr key, CSStr value, bool empty)
bool IniDocument::DeleteValue(const SQChar * section, const SQChar * key, const SQChar * value, bool empty)
{
// Validate the handle
m_Doc.Validate();
@@ -367,7 +367,7 @@ void Register_INI(HSQUIRRELVM vm)
Class< IniResult >(vm, ResultTypename::Str)
// Constructors
.Ctor()
.Ctor< CSStr, SQInteger >()
.Ctor< const SQChar *, SQInteger >()
.Ctor< const IniResult & >()
// Core Meta-methods
.SquirrelFunc(_SC("_typename"), &ResultTypename::Fn)
@@ -431,10 +431,10 @@ void Register_INI(HSQUIRRELVM vm)
// Member Methods
.Func(_SC("Reset"), &IniDocument::Reset)
.Func(_SC("LoadFile"), &IniDocument::LoadFile)
.Overload< IniResult (IniDocument::*)(CSStr) >(_SC("LoadString"), &IniDocument::LoadData)
.Overload< IniResult (IniDocument::*)(CSStr, Int32) >(_SC("LoadString"), &IniDocument::LoadData)
.Overload< IniResult (IniDocument::*)(CSStr) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Overload< IniResult (IniDocument::*)(CSStr, bool) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Overload< IniResult (IniDocument::*)(const SQChar *) >(_SC("LoadString"), &IniDocument::LoadData)
.Overload< IniResult (IniDocument::*)(const SQChar *, int32_t) >(_SC("LoadString"), &IniDocument::LoadData)
.Overload< IniResult (IniDocument::*)(const SQChar *) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Overload< IniResult (IniDocument::*)(const SQChar *, bool) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Func(_SC("SaveData"), &IniDocument::SaveData)
.Func(_SC("GetSections"), &IniDocument::GetAllSections)
.Func(_SC("GetKeys"), &IniDocument::GetAllKeys)
@@ -445,34 +445,34 @@ void Register_INI(HSQUIRRELVM vm)
.Func(_SC("GetInteger"), &IniDocument::GetInteger)
.Func(_SC("GetFloat"), &IniDocument::GetFloat)
.Func(_SC("GetBoolean"), &IniDocument::GetBoolean)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, CSStr) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, CSStr, bool) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, CSStr, bool, CSStr) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQInteger) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQInteger, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQInteger, bool, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQInteger, bool, bool, CSStr) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQFloat) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQFloat, bool) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, SQFloat, bool, CSStr) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, bool, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< IniResult (IniDocument::*)(CSStr, CSStr, bool, bool, CSStr) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< bool (IniDocument::*)(CSStr) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(CSStr, CSStr) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(CSStr, CSStr, CSStr) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(CSStr, CSStr, CSStr, bool) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *, bool) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *, bool, const SQChar *) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQInteger) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQInteger, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQInteger, bool, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQInteger, bool, bool, const SQChar *) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQFloat) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQFloat, bool) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, SQFloat, bool, const SQChar *) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, bool, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< IniResult (IniDocument::*)(const SQChar *, const SQChar *, bool, bool, const SQChar *) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< bool (IniDocument::*)(const SQChar *) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(const SQChar *, const SQChar *) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *, bool) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
);
RootTable(vm).Bind(_SC("SqIni"), inins);
ConstTable(vm).Enum(_SC("SqIniError"), Enumeration(vm)
.Const(_SC("Ok"), Int32(SI_OK))
.Const(_SC("Updated"), Int32(SI_UPDATED))
.Const(_SC("Inserted"), Int32(SI_INSERTED))
.Const(_SC("Fail"), Int32(SI_FAIL))
.Const(_SC("NoMem"), Int32(SI_NOMEM))
.Const(_SC("File"), Int32(SI_FILE))
.Const(_SC("Ok"), int32_t(SI_OK))
.Const(_SC("Updated"), int32_t(SI_UPDATED))
.Const(_SC("Inserted"), int32_t(SI_INSERTED))
.Const(_SC("Fail"), int32_t(SI_FAIL))
.Const(_SC("NoMem"), int32_t(SI_NOMEM))
.Const(_SC("File"), int32_t(SI_FILE))
);
}
+101 -120
View File
@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <SimpleIni.h>
@@ -34,7 +34,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Construct with no specific result.
*/
explicit IniResult(CSStr action)
explicit IniResult(const SQChar * action)
: m_Action(!action ? _SC("") : action), m_Result(SI_OK)
{
/* ... */
@@ -52,7 +52,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Construct with specific action and result.
*/
IniResult(CSStr action, SQInteger result)
IniResult(const SQChar * action, SQInteger result)
: m_Action(!action ? _SC("") : action), m_Result(result)
{
/* ... */
@@ -61,30 +61,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
IniResult(const IniResult & o)
: m_Action(o.m_Action), m_Result(o.m_Result)
{
/* ... */
}
IniResult(const IniResult & o) = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~IniResult()
{
/* ... */
}
~IniResult() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
IniResult & operator = (const IniResult & o)
{
m_Action = o.m_Action;
m_Result = o.m_Result;
return *this;
}
IniResult & operator = (const IniResult & o) = default;
/* --------------------------------------------------------------------------------------------
* Perform an equality comparison between two results.
@@ -105,7 +92,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean for use in boolean operations.
*/
operator bool () const
operator bool () const // NOLINT(google-explicit-constructor)
{
return (m_Result >= 0);
}
@@ -113,7 +100,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const IniResult & o) const
SQMOD_NODISCARD int32_t Cmp(const IniResult & o) const
{
if (m_Result == o.m_Result)
{
@@ -132,7 +119,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
SQMOD_NODISCARD const SQChar * ToString() const
{
return m_Action.c_str();
}
@@ -140,7 +127,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether this instance references a valid INI result.
*/
bool IsValid() const
SQMOD_NODISCARD bool IsValid() const
{
return (m_Result >= 0);
}
@@ -148,7 +135,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated action.
*/
CSStr GetAction() const
SQMOD_NODISCARD const SQChar * GetAction() const
{
return m_Action.c_str();
}
@@ -156,7 +143,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the resulted code.
*/
SQInteger GetResult() const
SQMOD_NODISCARD SQInteger GetResult() const
{
return m_Result;
}
@@ -222,8 +209,8 @@ private:
{
delete m_Ptr;
delete m_Ref;
m_Ptr = NULL;
m_Ref = NULL;
m_Ptr = nullptr;
m_Ref = nullptr;
}
}
@@ -242,7 +229,7 @@ public:
* Default constructor (null).
*/
IniDocumentRef()
: m_Ptr(NULL), m_Ref(NULL)
: m_Ptr(nullptr), m_Ref(nullptr)
{
/* ... */
}
@@ -260,12 +247,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
IniDocumentRef(IniDocumentRef && o)
IniDocumentRef(IniDocumentRef && o) noexcept
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
{
o.m_Ptr = NULL;
o.m_Ref = NULL;
o.m_Ptr = nullptr;
o.m_Ref = nullptr;
}
/* --------------------------------------------------------------------------------------------
@@ -279,7 +266,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
IniDocumentRef & operator = (const IniDocumentRef & o)
IniDocumentRef & operator = (const IniDocumentRef & o) noexcept // NOLINT(bugprone-unhandled-self-assignment)
{
if (m_Ptr != o.m_Ptr)
{
@@ -294,14 +281,14 @@ public:
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
IniDocumentRef & operator = (IniDocumentRef && o)
IniDocumentRef & operator = (IniDocumentRef && o) noexcept
{
if (m_Ptr != o.m_Ptr)
{
m_Ptr = o.m_Ptr;
m_Ref = o.m_Ref;
o.m_Ptr = NULL;
o.m_Ref = NULL;
o.m_Ptr = nullptr;
o.m_Ref = nullptr;
}
return *this;
}
@@ -325,7 +312,15 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean for use in boolean operations.
*/
operator bool () const
operator bool () const // NOLINT(google-explicit-constructor)
{
return static_cast< bool >(m_Ptr);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance pointer.
*/
operator Pointer () // NOLINT(google-explicit-constructor)
{
return m_Ptr;
}
@@ -333,15 +328,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance pointer.
*/
operator Pointer ()
{
return m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance pointer.
*/
operator ConstPtr () const
operator ConstPtr () const // NOLINT(google-explicit-constructor)
{
return m_Ptr;
}
@@ -349,7 +336,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance reference.
*/
operator Reference ()
operator Reference () // NOLINT(google-explicit-constructor)
{
assert(m_Ptr);
return *m_Ptr;
@@ -358,7 +345,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance reference.
*/
operator ConstRef () const
operator ConstRef () const // NOLINT(google-explicit-constructor)
{
assert(m_Ptr);
return *m_Ptr;
@@ -385,7 +372,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of active references to the managed instance.
*/
Counter Count() const
SQMOD_NODISCARD Counter Count() const
{
return (m_Ptr && m_Ref) ? (*m_Ref) : 0;
}
@@ -410,7 +397,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
IniEntries(const IniDocumentRef & ini, Container & list)
IniEntries(const IniDocumentRef & ini, Container & list) // NOLINT(modernize-pass-by-value)
: m_Doc(ini), m_List(), m_Elem()
{
m_List.swap(list);
@@ -447,10 +434,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~IniEntries()
{
/* ... */
}
~IniEntries() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
@@ -466,12 +450,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const IniEntries & o) const;
SQMOD_NODISCARD int32_t Cmp(const IniEntries & o) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
SQMOD_NODISCARD const SQChar * ToString() const
{
return GetItem();
}
@@ -479,7 +463,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Return whether the current element is valid and can be accessed.
*/
bool IsValid() const
SQMOD_NODISCARD bool IsValid() const
{
return !(m_List.empty() || m_Elem == m_List.end());
}
@@ -487,7 +471,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Return whether the entry list is empty.
*/
bool IsEmpty() const
SQMOD_NODISCARD bool IsEmpty() const
{
return m_List.empty();
}
@@ -495,7 +479,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Return the number of active references to this document instance.
*/
Uint32 GetRefCount() const
SQMOD_NODISCARD uint32_t GetRefCount() const
{
return m_Doc.Count();
}
@@ -503,9 +487,9 @@ public:
/* --------------------------------------------------------------------------------------------
* Return the total entries in the list.
*/
Int32 GetSize() const
SQMOD_NODISCARD int32_t GetSize() const
{
return static_cast< Int32 >(m_List.size());
return static_cast< int32_t >(m_List.size());
}
/* --------------------------------------------------------------------------------------------
@@ -536,12 +520,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Advance a certain number of elements.
*/
void Advance(Int32 n);
void Advance(int32_t n);
/* --------------------------------------------------------------------------------------------
* Retreat a certain number of elements.
*/
void Retreat(Int32 n);
void Retreat(int32_t n);
/* --------------------------------------------------------------------------------------------
* Sort the entries using the default options.
@@ -579,17 +563,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the string value of the current element item.
*/
CSStr GetItem() const;
SQMOD_NODISCARD const SQChar * GetItem() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the string value of the current element comment.
*/
CSStr GetComment() const;
SQMOD_NODISCARD const SQChar * GetComment() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the order of the current element.
*/
Int32 GetOrder() const;
SQMOD_NODISCARD int32_t GetOrder() const;
};
/* ------------------------------------------------------------------------------------------------
@@ -602,16 +586,6 @@ protected:
// --------------------------------------------------------------------------------------------
typedef IniDocumentRef::Type::TNamesDepend Container;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
IniDocument(const IniDocument & o);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
IniDocument & operator = (const IniDocument & o);
private:
// ---------------------------------------------------------------------------------------------
@@ -631,7 +605,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Explicit constructor.
*/
IniDocument(bool utf8)
explicit IniDocument(bool utf8)
: m_Doc(utf8, false, true)
{
/* ... */
@@ -655,23 +629,30 @@ public:
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
IniDocument(const IniDocument & o) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~IniDocument()
{
/* ... */
}
~IniDocument() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
IniDocument & operator = (const IniDocument & o) = delete;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const IniDocument & o) const;
SQMOD_NODISCARD int32_t Cmp(const IniDocument & o) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
SQMOD_NODISCARD const SQChar * ToString() const // NOLINT(readability-convert-member-functions-to-static)
{
return _SC("");
}
@@ -679,7 +660,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether this instance references a valid INI document.
*/
bool IsValid() const
SQMOD_NODISCARD bool IsValid() const
{
return m_Doc;
}
@@ -687,7 +668,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Return the number of active references to this document instance.
*/
Uint32 GetRefCount() const
SQMOD_NODISCARD uint32_t GetRefCount() const
{
return m_Doc.Count();
}
@@ -695,7 +676,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether any data has been loaded into this document.
*/
bool IsEmpty() const
SQMOD_NODISCARD bool IsEmpty() const
{
return m_Doc->IsEmpty();
}
@@ -711,7 +692,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the INI data is treated as unicode.
*/
bool GetUnicode() const
SQMOD_NODISCARD bool GetUnicode() const
{
return m_Doc->IsUnicode();
}
@@ -727,7 +708,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether multiple identical keys be permitted in the file.
*/
bool GetMultiKey() const
SQMOD_NODISCARD bool GetMultiKey() const
{
return m_Doc->IsMultiKey();
}
@@ -743,7 +724,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether data values are permitted to span multiple lines in the file.
*/
bool GetMultiLine() const
SQMOD_NODISCARD bool GetMultiLine() const
{
return m_Doc->IsMultiLine();
}
@@ -759,7 +740,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether spaces are added around the equals sign when writing key/value pairs out.
*/
bool GetSpaces() const
SQMOD_NODISCARD bool GetSpaces() const
{
return m_Doc->UsingSpaces();
}
@@ -775,12 +756,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Load an INI file from disk into memory.
*/
IniResult LoadFile(CSStr filepath);
IniResult LoadFile(const SQChar * filepath);
/* --------------------------------------------------------------------------------------------
* Load INI file data direct from a string. (LoadString collides with the windows api)
*/
IniResult LoadData(CSStr source)
IniResult LoadData(const SQChar * source)
{
return LoadData(source, -1);
}
@@ -788,12 +769,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Load INI file data direct from a string. (LoadString collides with the windows api)
*/
IniResult LoadData(CSStr source, Int32 size);
IniResult LoadData(const SQChar * source, int32_t size);
/* --------------------------------------------------------------------------------------------
* Save an INI file from memory to disk.
*/
IniResult SaveFile(CSStr filepath)
IniResult SaveFile(const SQChar * filepath)
{
return SaveFile(filepath, true);
}
@@ -801,7 +782,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Save an INI file from memory to disk.
*/
IniResult SaveFile(CSStr filepath, bool signature);
IniResult SaveFile(const SQChar * filepath, bool signature);
/* --------------------------------------------------------------------------------------------
* Save the INI data to a string.
@@ -811,52 +792,52 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve all section names.
*/
IniEntries GetAllSections() const;
SQMOD_NODISCARD IniEntries GetAllSections() const;
/* --------------------------------------------------------------------------------------------
* Retrieve all unique key names in a section.
*/
IniEntries GetAllKeys(CSStr section) const;
SQMOD_NODISCARD IniEntries GetAllKeys(const SQChar * section) const;
/* --------------------------------------------------------------------------------------------
* Retrieve all values for a specific key.
*/
IniEntries GetAllValues(CSStr section, CSStr key) const;
SQMOD_NODISCARD IniEntries GetAllValues(const SQChar * section, const SQChar * key) const;
/* --------------------------------------------------------------------------------------------
* Query the number of keys in a specific section.
*/
Int32 GetSectionSize(CSStr section) const;
SQMOD_NODISCARD int32_t GetSectionSize(const SQChar * section) const;
/* --------------------------------------------------------------------------------------------
* See whether a certain key has multiple instances.
*/
bool HasMultipleKeys(CSStr section, CSStr key) const;
SQMOD_NODISCARD bool HasMultipleKeys(const SQChar * section, const SQChar * key) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the value for a specific key.
*/
CCStr GetValue(CSStr section, CSStr key, CSStr def) const;
SQMOD_NODISCARD const char * GetValue(const SQChar * section, const SQChar * key, const SQChar * def) const;
/* --------------------------------------------------------------------------------------------
* Retrieve a numeric value for a specific key.
*/
SQInteger GetInteger(CSStr section, CSStr key, SQInteger def) const;
SQMOD_NODISCARD SQInteger GetInteger(const SQChar * section, const SQChar * key, SQInteger def) const;
/* --------------------------------------------------------------------------------------------
* Retrieve a numeric value for a specific key.
*/
SQFloat GetFloat(CSStr section, CSStr key, SQFloat def) const;
SQMOD_NODISCARD SQFloat GetFloat(const SQChar * section, const SQChar * key, SQFloat def) const;
/* --------------------------------------------------------------------------------------------
* Retrieve a boolean value for a specific key.
*/
bool GetBoolean(CSStr section, CSStr key, bool def) const;
SQMOD_NODISCARD bool GetBoolean(const SQChar * section, const SQChar * key, bool def) const;
/* --------------------------------------------------------------------------------------------
* Add or update a section or value.
*/
IniResult SetValue(CSStr section, CSStr key, CSStr value)
IniResult SetValue(const SQChar * section, const SQChar * key, const SQChar * value)
{
return SetValue(section, key, value, false, nullptr);
}
@@ -864,7 +845,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a section or value.
*/
IniResult SetValue(CSStr section, CSStr key, CSStr value, bool force)
IniResult SetValue(const SQChar * section, const SQChar * key, const SQChar * value, bool force)
{
return SetValue(section, key, value, force, nullptr);
}
@@ -872,12 +853,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a section or value.
*/
IniResult SetValue(CSStr section, CSStr key, CSStr value, bool force, CSStr comment);
IniResult SetValue(const SQChar * section, const SQChar * key, const SQChar * value, bool force, const SQChar * comment);
/* --------------------------------------------------------------------------------------------
* Add or update a numeric value.
*/
IniResult SetInteger(CSStr section, CSStr key, SQInteger value)
IniResult SetInteger(const SQChar * section, const SQChar * key, SQInteger value)
{
return SetInteger(section, key, value, false, false, nullptr);
}
@@ -885,7 +866,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a numeric value.
*/
IniResult SetInteger(CSStr section, CSStr key, SQInteger value, bool hex)
IniResult SetInteger(const SQChar * section, const SQChar * key, SQInteger value, bool hex)
{
return SetInteger(section, key, value, hex, false, nullptr);
}
@@ -893,7 +874,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a numeric value.
*/
IniResult SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force)
IniResult SetInteger(const SQChar * section, const SQChar * key, SQInteger value, bool hex, bool force)
{
return SetInteger(section, key, value, hex, force, nullptr);
}
@@ -901,12 +882,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a numeric value.
*/
IniResult SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force, CSStr comment);
IniResult SetInteger(const SQChar * section, const SQChar * key, SQInteger value, bool hex, bool force, const SQChar * comment);
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetFloat(CSStr section, CSStr key, SQFloat value)
IniResult SetFloat(const SQChar * section, const SQChar * key, SQFloat value)
{
return SetFloat(section, key, value, false, nullptr);
}
@@ -914,7 +895,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetFloat(CSStr section, CSStr key, SQFloat value, bool force)
IniResult SetFloat(const SQChar * section, const SQChar * key, SQFloat value, bool force)
{
return SetFloat(section, key, value, force, nullptr);
}
@@ -922,12 +903,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetFloat(CSStr section, CSStr key, SQFloat value, bool force, CSStr comment);
IniResult SetFloat(const SQChar * section, const SQChar * key, SQFloat value, bool force, const SQChar * comment);
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetBoolean(CSStr section, CSStr key, bool value)
IniResult SetBoolean(const SQChar * section, const SQChar * key, bool value)
{
return SetBoolean(section, key, value, false, nullptr);
}
@@ -935,7 +916,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a double value.
*/
IniResult SetBoolean(CSStr section, CSStr key, bool value, bool force)
IniResult SetBoolean(const SQChar * section, const SQChar * key, bool value, bool force)
{
return SetBoolean(section, key, value, force, nullptr);
}
@@ -943,12 +924,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Add or update a boolean value.
*/
IniResult SetBoolean(CSStr section, CSStr key, bool value, bool force, CSStr comment);
IniResult SetBoolean(const SQChar * section, const SQChar * key, bool value, bool force, const SQChar * comment);
/* --------------------------------------------------------------------------------------------
* Delete an entire section, or a key from a section.
*/
bool DeleteValue(CSStr section)
bool DeleteValue(const SQChar * section)
{
return DeleteValue(section, nullptr, nullptr, false);
}
@@ -956,7 +937,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Delete an entire section, or a key from a section.
*/
bool DeleteValue(CSStr section, CSStr key)
bool DeleteValue(const SQChar * section, const SQChar * key)
{
return DeleteValue(section, key, nullptr, false);
}
@@ -964,7 +945,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Delete an entire section, or a key from a section.
*/
bool DeleteValue(CSStr section, CSStr key, CSStr value)
bool DeleteValue(const SQChar * section, const SQChar * key, const SQChar * value)
{
return DeleteValue(section, key, value, false);
}
@@ -972,7 +953,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Delete an entire section, or a key from a section.
*/
bool DeleteValue(CSStr section, CSStr key, CSStr value, bool empty);
bool DeleteValue(const SQChar * section, const SQChar * key, const SQChar * value, bool empty);
};
} // Namespace:: SqMod
View File
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1 -3
View File
@@ -1,11 +1,9 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
} // Namespace:: SqMod

Some files were not shown because too many files have changed in this diff Show More