diff --git a/source/Base/AABB.cpp b/source/Base/AABB.cpp new file mode 100644 index 00000000..a5016c4f --- /dev/null +++ b/source/Base/AABB.cpp @@ -0,0 +1,492 @@ +#include "Base/AABB.hpp" +#include "Base/Vector4.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const AABB AABB::NIL = AABB(0); +const AABB AABB::MIN = AABB(-1, -1, -1, 1, 1, 1); +const AABB AABB::MAX = AABB(Vector3::MIN, Vector3::MAX); + +// ------------------------------------------------------------------------------------------------ +SQChar AABB::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +AABB::AABB() noexcept + : min(-1), max(1) +{ + +} + +AABB::AABB(Value s) noexcept + : min(-s), max(std::fabs(s)) +{ + +} + +AABB::AABB(Value xv, Value yv, Value zv) noexcept + : min(-xv, -yv, -zv), max(std::fabs(xv), std::fabs(yv), std::fabs(zv)) +{ + +} + +AABB::AABB(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) noexcept + : min(xmin, ymin, zmin), max(xmax, ymax, zmax) +{ + +} + +// ------------------------------------------------------------------------------------------------ +AABB::AABB(const Vector3 & v) noexcept + : min(-v), max(v.Abs()) +{ + +} + +AABB::AABB(const Vector3 & vmin, const Vector3 & vmax) noexcept + : min(vmin), max(vmax) +{ + +} + +// ------------------------------------------------------------------------------------------------ +AABB::AABB(const Vector4 & v) noexcept + : min(-v), max(v.Abs()) +{ + +} + +AABB::AABB(const Vector4 & vmin, const Vector4 & vmax) noexcept + : min(vmin), max(vmax) +{ + +} + +// ------------------------------------------------------------------------------------------------ +AABB::AABB(const SQChar * values, SQChar delim) noexcept + : AABB(GetAABB(values, delim)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +AABB::AABB(const AABB & b) noexcept + : min(b.min), max(b.max) +{ + +} + +AABB::AABB(AABB && b) noexcept + : min(b.min), max(b.max) +{ + +} + +// ------------------------------------------------------------------------------------------------ +AABB::~AABB() +{ + +} + +// ------------------------------------------------------------------------------------------------ +AABB & AABB::operator = (const AABB & b) noexcept +{ + min = b.min; + max = b.max; + return *this; +} + +AABB & AABB::operator = (AABB && b) noexcept +{ + min = b.min; + max = b.max; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +AABB & AABB::operator = (Value s) noexcept +{ + min.Set(-s); + max.Set(std::fabs(s)); + return *this; +} + +AABB & AABB::operator = (const Vector3 & v) noexcept +{ + min.Set(-v); + max.Set(v.Abs()); + return *this; +} + +AABB & AABB::operator = (const Vector4 & v) noexcept +{ + min.Set(-v); + max.Set(v.Abs()); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +AABB & AABB::operator += (const AABB & b) noexcept +{ + min += b.min; + max += b.max; + return *this; +} + +AABB & AABB::operator -= (const AABB & b) noexcept +{ + min -= b.min; + max -= b.max; + return *this; +} + +AABB & AABB::operator *= (const AABB & b) noexcept +{ + min *= b.min; + max *= b.max; + return *this; +} + +AABB & AABB::operator /= (const AABB & b) noexcept +{ + min /= b.min; + max /= b.max; + return *this; +} + +AABB & AABB::operator %= (const AABB & b) noexcept +{ + min %= b.min; + max %= b.max; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +AABB & AABB::operator += (Value s) noexcept +{ + min += s; + max += s; + return *this; +} + +AABB & AABB::operator -= (Value s) noexcept +{ + min -= s; + max -= s; + return *this; +} + +AABB & AABB::operator *= (Value s) noexcept +{ + min *= s; + max *= s; + return *this; +} + +AABB & AABB::operator /= (Value s) noexcept +{ + min /= s; + max /= s; + return *this; +} + +AABB & AABB::operator %= (Value s) noexcept +{ + min %= s; + max %= s; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +AABB & AABB::operator ++ () noexcept +{ + ++min; + ++max; + return *this; +} + +AABB & AABB::operator -- () noexcept +{ + --min; + --max; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +AABB AABB::operator ++ (int) noexcept +{ + AABB state(*this); + ++min; + ++max; + return state; +} + +AABB AABB::operator -- (int) noexcept +{ + AABB state(*this); + --min; + --max; + return state; +} + +// ------------------------------------------------------------------------------------------------ +AABB AABB::operator + (const AABB & b) const noexcept +{ + return AABB(min + b.min, max + b.max); +} + +AABB AABB::operator - (const AABB & b) const noexcept +{ + return AABB(min - b.min, max - b.max); +} + +AABB AABB::operator * (const AABB & b) const noexcept +{ + return AABB(min * b.min, max * b.max); +} + +AABB AABB::operator / (const AABB & b) const noexcept +{ + return AABB(min / b.min, max / b.max); +} + +AABB AABB::operator % (const AABB & b) const noexcept +{ + return AABB(min % b.min, max % b.max); +} + +// ------------------------------------------------------------------------------------------------ +AABB AABB::operator + (Value s) const noexcept +{ + return AABB(min + s, max + s); +} + +AABB AABB::operator - (Value s) const noexcept +{ + return AABB(min - s, max - s); +} + +AABB AABB::operator * (Value s) const noexcept +{ + return AABB(min * s, max * s); +} + +AABB AABB::operator / (Value s) const noexcept +{ + return AABB(min / s, max / s); +} + +AABB AABB::operator % (Value s) const noexcept +{ + return AABB(min % s, max % s); +} + +// ------------------------------------------------------------------------------------------------ +AABB AABB::operator + () const noexcept +{ + return AABB(min.Abs(), max.Abs()); +} + +AABB AABB::operator - () const noexcept +{ + return AABB(-min, -max); +} + +// ------------------------------------------------------------------------------------------------ +bool AABB::operator == (const AABB & b) const noexcept +{ + return (min == b.min) && (max == b.max); +} + +bool AABB::operator != (const AABB & b) const noexcept +{ + return (min != b.min) && (max != b.max); +} + +bool AABB::operator < (const AABB & b) const noexcept +{ + return (min < b.min) && (max < b.max); +} + +bool AABB::operator > (const AABB & b) const noexcept +{ + return (min > b.min) && (max > b.max); +} + +bool AABB::operator <= (const AABB & b) const noexcept +{ + return (min <= b.min) && (max <= b.max); +} + +bool AABB::operator >= (const AABB & b) const noexcept +{ + return (min >= b.min) && (max >= b.max); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger AABB::Cmp(const AABB & b) const noexcept +{ + return *this == b ? 0 : (*this > b ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * AABB::ToString() const noexcept +{ + return ToStringF("%f,%f,%f,%f,%f,%f", min.x, min.y, min.z, max.x, max.y, max.z); +} + +// ------------------------------------------------------------------------------------------------ +void AABB::Set(Value ns) noexcept +{ + min = -ns; + max = std::fabs(ns); +} + +void AABB::Set(Value nx, Value ny, Value nz) noexcept +{ + min.Set(-nx, -ny, -nz); + max.Set(std::fabs(nx), std::fabs(ny), std::fabs(nz)); +} + +void AABB::Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) noexcept +{ + min.Set(xmin, ymin, zmin); + max.Set(xmax, ymax, zmax); +} + +// ------------------------------------------------------------------------------------------------ +void AABB::Set(const AABB & b) noexcept +{ + min = b.min; + max = b.max; +} + +// ------------------------------------------------------------------------------------------------ +void AABB::Set(const Vector3 & v) noexcept +{ + min = -v; + max = v.Abs(); +} + +void AABB::Set(const Vector3 & nmin, const Vector3 & nmax) noexcept +{ + min = nmin; + max = nmax; +} + +// ------------------------------------------------------------------------------------------------ +void AABB::Set(const Vector4 & v) noexcept +{ + min = -v; + max = v.Abs(); +} + +void AABB::Set(const Vector4 & nmin, const Vector4 & nmax) noexcept +{ + min = nmin; + max = nmax; +} + +// ------------------------------------------------------------------------------------------------ +void AABB::Set(const SQChar * values, SQChar delim) noexcept +{ + Set(GetAABB(values, delim)); +} + +// ------------------------------------------------------------------------------------------------ +AABB AABB::Abs() const noexcept +{ + return AABB(min.Abs(), max.Abs()); +} + +// ================================================================================================ +bool Register_AABB(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef AABB::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("AABB"), Sqrat::Class(vm, _SC("AABB")) + .Ctor() + .Ctor() + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &AABB::Delim) + + .Var(_SC("min"), &AABB::min) + .Var(_SC("max"), &AABB::max) + + .Prop(_SC("abs"), &AABB::Abs) + + .Func(_SC("_tostring"), &AABB::ToString) + .Func(_SC("_cmp"), &AABB::Cmp) + + .Func(_SC("_add"), &AABB::operator +) + .Func(_SC("_sub"), &AABB::operator -) + .Func(_SC("_mul"), &AABB::operator *) + .Func(_SC("_div"), &AABB::operator /) + .Func(_SC("_modulo"), &AABB::operator %) + .Func(_SC("_unm"), &AABB::operator -) + + .Overload(_SC("set"), &AABB::Set) + .Overload(_SC("set"), &AABB::Set) + .Overload(_SC("set"), &AABB::Set) + .Overload(_SC("set_box"), &AABB::Set) + .Overload(_SC("set_vec3"), &AABB::Set) + .Overload(_SC("set_vec3"), &AABB::Set) + .Overload(_SC("set_vec4"), &AABB::Set) + .Overload(_SC("set_vec4"), &AABB::Set) + .Overload(_SC("set_str"), &AABB::Set) + + .Func(_SC("clear"), &AABB::Clear) + + .Func(_SC("opAddAssign"), &AABB::operator +=) + .Func(_SC("opSubAssign"), &AABB::operator -=) + .Func(_SC("opMulAssign"), &AABB::operator *=) + .Func(_SC("opDivAssign"), &AABB::operator /=) + .Func(_SC("opModAssign"), &AABB::operator %=) + + .Func(_SC("opAddAssignS"), &AABB::operator +=) + .Func(_SC("opSubAssignS"), &AABB::operator -=) + .Func(_SC("opMulAssignS"), &AABB::operator *=) + .Func(_SC("opDivAssignS"), &AABB::operator /=) + .Func(_SC("opModAssignS"), &AABB::operator %=) + + .Func(_SC("opPreInc"), &AABB::operator ++) + .Func(_SC("opPreDec"), &AABB::operator --) + .Func(_SC("opPostInc"), &AABB::operator ++) + .Func(_SC("opPostDec"), &AABB::operator --) + + .Func(_SC("opAdd"), &AABB::operator +) + .Func(_SC("opAddS"), &AABB::operator +) + .Func(_SC("opSub"), &AABB::operator -) + .Func(_SC("opSubS"), &AABB::operator -) + .Func(_SC("opMul"), &AABB::operator *) + .Func(_SC("opMulS"), &AABB::operator *) + .Func(_SC("opDiv"), &AABB::operator /) + .Func(_SC("opDivS"), &AABB::operator /) + .Func(_SC("opMod"), &AABB::operator %) + .Func(_SC("opModS"), &AABB::operator %) + + .Func(_SC("opUnPlus"), &AABB::operator +) + .Func(_SC("opUnMinus"), &AABB::operator -) + + .Func(_SC("opEqual"), &AABB::operator ==) + .Func(_SC("opNotEqual"), &AABB::operator !=) + .Func(_SC("opLessThan"), &AABB::operator <) + .Func(_SC("opGreaterThan"), &AABB::operator >) + .Func(_SC("opLessEqual"), &AABB::operator <=) + .Func(_SC("opGreaterEqual"), &AABB::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/AABB.hpp b/source/Base/AABB.hpp new file mode 100644 index 00000000..a8a990cf --- /dev/null +++ b/source/Base/AABB.hpp @@ -0,0 +1,117 @@ +#ifndef _BASE_AABB_HPP_ +#define _BASE_AABB_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" +#include "Base/Vector3.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct AABB +{ + // -------------------------------------------------------------------------------------------- + typedef SQFloat Value; + // -------------------------------------------------------------------------------------------- + static const AABB NIL; + static const AABB MIN; + static const AABB MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Vector3 min, max; + // -------------------------------------------------------------------------------------------- + AABB() noexcept; + AABB(Value s) noexcept; + AABB(Value x, Value y, Value z) noexcept; + AABB(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) noexcept; + // -------------------------------------------------------------------------------------------- + AABB(const Vector3 & b) noexcept; + AABB(const Vector3 & vmin, const Vector3 & vmax) noexcept; + // -------------------------------------------------------------------------------------------- + AABB(const Vector4 & b) noexcept; + AABB(const Vector4 & vmin, const Vector4 & vmax) noexcept; + // -------------------------------------------------------------------------------------------- + AABB(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + AABB(const AABB & b) noexcept; + AABB(AABB && b) noexcept; + // -------------------------------------------------------------------------------------------- + ~AABB(); + // -------------------------------------------------------------------------------------------- + AABB & operator = (const AABB & b) noexcept; + AABB & operator = (AABB && b) noexcept; + // -------------------------------------------------------------------------------------------- + AABB & operator = (Value s) noexcept; + AABB & operator = (const Vector3 & v) noexcept; + AABB & operator = (const Vector4 & v) noexcept; + // -------------------------------------------------------------------------------------------- + AABB & operator += (const AABB & b) noexcept; + AABB & operator -= (const AABB & b) noexcept; + AABB & operator *= (const AABB & b) noexcept; + AABB & operator /= (const AABB & b) noexcept; + AABB & operator %= (const AABB & b) noexcept; + // -------------------------------------------------------------------------------------------- + AABB & operator += (Value s) noexcept; + AABB & operator -= (Value s) noexcept; + AABB & operator *= (Value s) noexcept; + AABB & operator /= (Value s) noexcept; + AABB & operator %= (Value s) noexcept; + // -------------------------------------------------------------------------------------------- + AABB & operator ++ () noexcept; + AABB & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + AABB operator ++ (int) noexcept; + AABB operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + AABB operator + (const AABB & b) const noexcept; + AABB operator - (const AABB & b) const noexcept; + AABB operator * (const AABB & b) const noexcept; + AABB operator / (const AABB & b) const noexcept; + AABB operator % (const AABB & b) const noexcept; + // -------------------------------------------------------------------------------------------- + AABB operator + (Value s) const noexcept; + AABB operator - (Value s) const noexcept; + AABB operator * (Value s) const noexcept; + AABB operator / (Value s) const noexcept; + AABB operator % (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + AABB operator + () const noexcept; + AABB operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const AABB & b) const noexcept; + bool operator != (const AABB & b) const noexcept; + bool operator < (const AABB & b) const noexcept; + bool operator > (const AABB & b) const noexcept; + bool operator <= (const AABB & b) const noexcept; + bool operator >= (const AABB & b) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const AABB & b) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value ns) noexcept; + void Set(Value nx, Value ny, Value nz) noexcept; + void Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const AABB & b) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Vector3 & v) noexcept; + void Set(const Vector3 & nmin, const Vector3 & nmax) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Vector4 & v) noexcept; + void Set(const Vector4 & nmin, const Vector4 & nmax) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { min.Clear(); max.Clear(); } + // -------------------------------------------------------------------------------------------- + AABB Abs() const noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_AABB_HPP_ diff --git a/source/Base/Circle.cpp b/source/Base/Circle.cpp new file mode 100644 index 00000000..63fc6270 --- /dev/null +++ b/source/Base/Circle.cpp @@ -0,0 +1,542 @@ +#include "Base/Circle.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Circle Circle::NIL = Circle(); +const Circle Circle::MIN = Circle(0.0); +const Circle Circle::MAX = Circle(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Circle::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Circle::Circle() noexcept + : pos(0.0, 0.0), rad(0.0) +{ + +} + +Circle::Circle(Value r) noexcept + : pos(0.0, 0.0), rad(r) +{ + +} + +Circle::Circle(const Vector2f & p) noexcept + : pos(p), rad(0.0) +{ + +} + +Circle::Circle(const Vector2f & p, Value r) noexcept + : pos(p), rad(r) +{ + +} + +Circle::Circle(Value x, Value y, Value r) noexcept + : pos(x, y), rad(r) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Circle::Circle(const Circle & c) noexcept + : pos(c.pos), rad(c.rad) +{ + +} + +Circle::Circle(Circle && c) noexcept + : pos(c.pos), rad(c.rad) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Circle::~Circle() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Circle & Circle::operator = (const Circle & c) noexcept +{ + pos = c.pos; + rad = c.rad; + return *this; +} + +Circle & Circle::operator = (Circle && c) noexcept +{ + pos = c.pos; + rad = c.rad; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Circle & Circle::operator = (Value r) noexcept +{ + rad = r; + return *this; +} + +Circle & Circle::operator = (const Vector2f & p) noexcept +{ + pos = p; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Circle & Circle::operator += (const Circle & c) noexcept +{ + pos += c.pos; + rad += c.rad; + return *this; +} + +Circle & Circle::operator -= (const Circle & c) noexcept +{ + pos -= c.pos; + rad -= c.rad; + return *this; +} + +Circle & Circle::operator *= (const Circle & c) noexcept +{ + pos *= c.pos; + rad *= c.rad; + return *this; +} + +Circle & Circle::operator /= (const Circle & c) noexcept +{ + pos /= c.pos; + rad /= c.rad; + return *this; +} + +Circle & Circle::operator %= (const Circle & c) noexcept +{ + pos %= c.pos; + rad = std::fmod(rad, c.rad); + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Circle & Circle::operator += (Value r) noexcept +{ + rad += r; + return *this; +} + +Circle & Circle::operator -= (Value r) noexcept +{ + rad -= r; + return *this; +} + +Circle & Circle::operator *= (Value r) noexcept +{ + rad *= r; + return *this; +} + +Circle & Circle::operator /= (Value r) noexcept +{ + rad /= r; + return *this; +} + +Circle & Circle::operator %= (Value r) noexcept +{ + rad = std::fmod(rad, r); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Circle & Circle::operator += (const Vector2f & p) noexcept +{ + pos += p; + return *this; +} + +Circle & Circle::operator -= (const Vector2f & p) noexcept +{ + pos -= p; + return *this; +} + +Circle & Circle::operator *= (const Vector2f & p) noexcept +{ + pos *= p; + return *this; +} + +Circle & Circle::operator /= (const Vector2f & p) noexcept +{ + pos /= p; + return *this; +} + +Circle & Circle::operator %= (const Vector2f & p) noexcept +{ + pos %= p; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Circle & Circle::operator ++ () noexcept +{ + ++pos; + ++rad; + return *this; +} + +Circle & Circle::operator -- () noexcept +{ + --pos; + --rad; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Circle Circle::operator ++ (int) noexcept +{ + Circle state(*this); + ++pos; + ++rad; + return state; +} + +Circle Circle::operator -- (int) noexcept +{ + Circle state(*this); + --pos; + --rad; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Circle Circle::operator + (const Circle & c) const noexcept +{ + return Circle(pos + c.pos, rad + c.rad); +} + +Circle Circle::operator - (const Circle & c) const noexcept +{ + return Circle(pos - c.pos, rad - c.rad); +} + +Circle Circle::operator * (const Circle & c) const noexcept +{ + return Circle(pos * c.pos, rad * c.rad); +} + +Circle Circle::operator / (const Circle & c) const noexcept +{ + return Circle(pos / c.pos, rad / c.rad); +} + +Circle Circle::operator % (const Circle & c) const noexcept +{ + return Circle(pos % c.pos, std::fmod(rad, c.rad)); +} + +// ------------------------------------------------------------------------------------------------ +Circle Circle::operator + (Value r) const noexcept +{ + return Circle(rad + r); +} + +Circle Circle::operator - (Value r) const noexcept +{ + return Circle(rad - r); +} + +Circle Circle::operator * (Value r) const noexcept +{ + return Circle(rad * r); +} + +Circle Circle::operator / (Value r) const noexcept +{ + return Circle(rad / r); +} + +Circle Circle::operator % (Value r) const noexcept +{ + return Circle(std::fmod(rad, r)); +} + +// ------------------------------------------------------------------------------------------------ +Circle Circle::operator + (const Vector2f & p) const noexcept +{ + return Circle(pos + p); +} + +Circle Circle::operator - (const Vector2f & p) const noexcept +{ + return Circle(pos - p); +} + +Circle Circle::operator * (const Vector2f & p) const noexcept +{ + return Circle(pos * p); +} + +Circle Circle::operator / (const Vector2f & p) const noexcept +{ + return Circle(pos / p); +} + +Circle Circle::operator % (const Vector2f & p) const noexcept +{ + return Circle(pos % p); +} + +// ------------------------------------------------------------------------------------------------ +Circle Circle::operator + () const noexcept +{ + return Circle(pos.Abs(), std::fabs(rad)); +} + +Circle Circle::operator - () const noexcept +{ + return Circle(-pos, -rad); +} + +// ------------------------------------------------------------------------------------------------ +bool Circle::operator == (const Circle & c) const noexcept +{ + return (rad == c.rad) && (pos == c.pos); +} + +bool Circle::operator != (const Circle & c) const noexcept +{ + return (rad != c.rad) && (pos != c.pos); +} + +bool Circle::operator < (const Circle & c) const noexcept +{ + return (rad < c.rad) && (pos < c.pos); +} + +bool Circle::operator > (const Circle & c) const noexcept +{ + return (rad > c.rad) && (pos > c.pos); +} + +bool Circle::operator <= (const Circle & c) const noexcept +{ + return (rad <= c.rad) && (pos <= c.pos); +} + +bool Circle::operator >= (const Circle & c) const noexcept +{ + return (rad >= c.rad) && (pos >= c.pos); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Circle::Cmp(const Circle & c) const noexcept +{ + return *this == c ? 0 : (*this > c ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Circle::ToString() const noexcept +{ + return ToStringF("%f,%f,%f", pos.x, pos.y, rad); +} + +// ------------------------------------------------------------------------------------------------ +void Circle::Set(Value nr) noexcept +{ + rad = nr; +} + +void Circle::Set(const Circle & nc) noexcept +{ + pos = nc.pos; + rad = nc.rad; +} + +void Circle::Set(const Vector2f & np) noexcept +{ + pos = np; +} + +void Circle::Set(const Vector2f & np, Value nr) noexcept +{ + pos = np; + rad = nr; +} + +// ------------------------------------------------------------------------------------------------ +void Circle::Set(Value nx, Value ny) noexcept +{ + pos.Set(nx, ny); +} + +void Circle::Set(Value nx, Value ny, Value nr) noexcept +{ + pos.Set(nx, ny); + rad = nr; +} + +// ------------------------------------------------------------------------------------------------ +void Circle::Set(const SQChar * values, SQChar delim) noexcept +{ + Set(GetCircle(values, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Circle::Generate() noexcept +{ + pos.Generate(); + rad = RandomVal::Get(); +} + +void Circle::Generate(Value min, Value max, bool r) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else if (r) + { + rad = RandomVal::Get(min, max); + } + else + { + pos.Generate(min, max); + } +} + +void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept +{ + pos.Generate(xmin, xmax, ymin, ymax); +} + +void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin, Value rmax) noexcept +{ + if (std::isless(rmax, rmin)) + { + LogErr("max value is lower than min value"); + } + else + { + pos.Generate(xmin, xmax, ymin, ymax); + rad = RandomVal::Get(rmin, rmax); + } +} + +// ------------------------------------------------------------------------------------------------ +Circle Circle::Abs() const noexcept +{ + return Circle(pos.Abs(), std::fabs(rad)); +} + +// ------------------------------------------------------------------------------------------------ +bool Register_Circle(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Circle::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Circle"), Sqrat::Class(vm, _SC("Circle")) + .Ctor() + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Circle::Delim) + + .Var(_SC("pos"), &Circle::pos) + .Var(_SC("rad"), &Circle::rad) + + .Prop(_SC("abs"), &Circle::Abs) + + .Func(_SC("_tostring"), &Circle::ToString) + .Func(_SC("_cmp"), &Circle::Cmp) + + .Func(_SC("_add"), &Circle::operator +) + .Func(_SC("_sub"), &Circle::operator -) + .Func(_SC("_mul"), &Circle::operator *) + .Func(_SC("_div"), &Circle::operator /) + .Func(_SC("_modulo"), &Circle::operator %) + .Func(_SC("_unm"), &Circle::operator -) + + .Overload(_SC("set"), &Circle::Set) + .Overload(_SC("set"), &Circle::Set) + .Overload(_SC("set"), &Circle::Set) + .Overload(_SC("set_rad"), &Circle::Set) + .Overload(_SC("set_vec2"), &Circle::Set) + .Overload(_SC("set_vec2"), &Circle::Set) + .Overload(_SC("set_str"), &Circle::Set) + + .Func(_SC("clear"), &Circle::Clear) + + .Func(_SC("opAddAssign"), &Circle::operator +=) + .Func(_SC("opSubAssign"), &Circle::operator -=) + .Func(_SC("opMulAssign"), &Circle::operator *=) + .Func(_SC("opDivAssign"), &Circle::operator /=) + .Func(_SC("opModAssign"), &Circle::operator %=) + + .Func(_SC("opAddAssignR"), &Circle::operator +=) + .Func(_SC("opSubAssignR"), &Circle::operator -=) + .Func(_SC("opMulAssignR"), &Circle::operator *=) + .Func(_SC("opDivAssignR"), &Circle::operator /=) + .Func(_SC("opModAssignR"), &Circle::operator %=) + + .Func(_SC("opAddAssignP"), &Circle::operator +=) + .Func(_SC("opSubAssignP"), &Circle::operator -=) + .Func(_SC("opMulAssignP"), &Circle::operator *=) + .Func(_SC("opDivAssignP"), &Circle::operator /=) + .Func(_SC("opModAssignP"), &Circle::operator %=) + + .Func(_SC("opPreInc"), &Circle::operator ++) + .Func(_SC("opPreDec"), &Circle::operator --) + .Func(_SC("opPostInc"), &Circle::operator ++) + .Func(_SC("opPostDec"), &Circle::operator --) + + .Func(_SC("opAdd"), &Circle::operator +) + .Func(_SC("opSub"), &Circle::operator -) + .Func(_SC("opMul"), &Circle::operator *) + .Func(_SC("opDiv"), &Circle::operator /) + .Func(_SC("opMod"), &Circle::operator %) + + .Func(_SC("opAddR"), &Circle::operator +) + .Func(_SC("opSubR"), &Circle::operator -) + .Func(_SC("opMulR"), &Circle::operator *) + .Func(_SC("opDivR"), &Circle::operator /) + .Func(_SC("opModR"), &Circle::operator %) + + .Func(_SC("opAddP"), &Circle::operator +) + .Func(_SC("opSubP"), &Circle::operator -) + .Func(_SC("opMulP"), &Circle::operator *) + .Func(_SC("opDivP"), &Circle::operator /) + .Func(_SC("opModP"), &Circle::operator %) + + .Func(_SC("opUnPlus"), &Circle::operator +) + .Func(_SC("opUnMinus"), &Circle::operator -) + + .Func(_SC("opEqual"), &Circle::operator ==) + .Func(_SC("opNotEqual"), &Circle::operator !=) + .Func(_SC("opLessThan"), &Circle::operator <) + .Func(_SC("opGreaterThan"), &Circle::operator >) + .Func(_SC("opLessEqual"), &Circle::operator <=) + .Func(_SC("opGreaterEqual"), &Circle::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Circle.hpp b/source/Base/Circle.hpp new file mode 100644 index 00000000..8ff34930 --- /dev/null +++ b/source/Base/Circle.hpp @@ -0,0 +1,123 @@ +#ifndef _BASE_CIRCLE_HPP_ +#define _BASE_CIRCLE_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" +#include "Base/Vector2f.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Circle +{ + // -------------------------------------------------------------------------------------------- + typedef SQFloat Value; + // -------------------------------------------------------------------------------------------- + static const Circle NIL; + static const Circle MIN; + static const Circle MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Vector2f pos; + Value rad; + // -------------------------------------------------------------------------------------------- + Circle() noexcept; + Circle(Value r) noexcept; + Circle(const Vector2f & p) noexcept; + Circle(const Vector2f & p, Value r) noexcept; + Circle(Value x, Value y, Value r) noexcept; + // -------------------------------------------------------------------------------------------- + Circle(const Circle & c) noexcept; + Circle(Circle && c) noexcept; + // -------------------------------------------------------------------------------------------- + ~Circle(); + // -------------------------------------------------------------------------------------------- + Circle & operator = (const Circle & c) noexcept; + Circle & operator = (Circle && c) noexcept; + // -------------------------------------------------------------------------------------------- + Circle & operator = (Value r) noexcept; + Circle & operator = (const Vector2f & p) noexcept; + // -------------------------------------------------------------------------------------------- + Circle & operator += (const Circle & c) noexcept; + Circle & operator -= (const Circle & c) noexcept; + Circle & operator *= (const Circle & c) noexcept; + Circle & operator /= (const Circle & c) noexcept; + Circle & operator %= (const Circle & c) noexcept; + // -------------------------------------------------------------------------------------------- + Circle & operator += (Value r) noexcept; + Circle & operator -= (Value r) noexcept; + Circle & operator *= (Value r) noexcept; + Circle & operator /= (Value r) noexcept; + Circle & operator %= (Value r) noexcept; + // -------------------------------------------------------------------------------------------- + Circle & operator += (const Vector2f & p) noexcept; + Circle & operator -= (const Vector2f & p) noexcept; + Circle & operator *= (const Vector2f & p) noexcept; + Circle & operator /= (const Vector2f & p) noexcept; + Circle & operator %= (const Vector2f & p) noexcept; + // -------------------------------------------------------------------------------------------- + Circle & operator ++ () noexcept; + Circle & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Circle operator ++ (int) noexcept; + Circle operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Circle operator + (const Circle & c) const noexcept; + Circle operator - (const Circle & c) const noexcept; + Circle operator * (const Circle & c) const noexcept; + Circle operator / (const Circle & c) const noexcept; + Circle operator % (const Circle & c) const noexcept; + // -------------------------------------------------------------------------------------------- + Circle operator + (Value r) const noexcept; + Circle operator - (Value r) const noexcept; + Circle operator * (Value r) const noexcept; + Circle operator / (Value r) const noexcept; + Circle operator % (Value r) const noexcept; + // -------------------------------------------------------------------------------------------- + Circle operator + (const Vector2f & p) const noexcept; + Circle operator - (const Vector2f & p) const noexcept; + Circle operator * (const Vector2f & p) const noexcept; + Circle operator / (const Vector2f & p) const noexcept; + Circle operator % (const Vector2f & p) const noexcept; + // -------------------------------------------------------------------------------------------- + Circle operator + () const noexcept; + Circle operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Circle & c) const noexcept; + bool operator != (const Circle & c) const noexcept; + bool operator < (const Circle & c) const noexcept; + bool operator > (const Circle & c) const noexcept; + bool operator <= (const Circle & c) const noexcept; + bool operator >= (const Circle & c) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Circle & c) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value nr) noexcept; + void Set(const Circle & nc) noexcept; + void Set(const Vector2f & np) noexcept; + void Set(const Vector2f & np, Value nr) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value nx, Value ny) noexcept; + void Set(Value nx, Value ny, Value nr) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max, bool r) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin, Value rmax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { pos.Clear(); rad = 0.0; } + // -------------------------------------------------------------------------------------------- + Circle Abs() const noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_CIRCLE_HPP_ diff --git a/source/Base/Color3.cpp b/source/Base/Color3.cpp new file mode 100644 index 00000000..c594ad39 --- /dev/null +++ b/source/Base/Color3.cpp @@ -0,0 +1,720 @@ +#include "Base/Color3.hpp" +#include "Base/Color4.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Color3 Color3::NIL = Color3(); +const Color3 Color3::MIN = Color3(std::numeric_limits::min()); +const Color3 Color3::MAX = Color3(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Color3::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Color3::Color3() noexcept + : r(0), g(0), b(0) +{ + +} + +Color3::Color3(Value s) noexcept + : r(s), g(s), b(s) +{ + +} + +Color3::Color3(Value rv, Value gv, Value bv) noexcept + : r(rv), g(gv), b(bv) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color3::Color3(const Color4 & c) noexcept + : r(c.r), g(c.g), b(c.b) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color3::Color3(const SQChar * name) noexcept + : Color3(GetColor(name)) +{ + +} + +Color3::Color3(const SQChar * str, SQChar delim) noexcept + : Color3(GetColor3(str, delim)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color3::Color3(const Color3 & c) noexcept + : r(c.r), g(c.g), b(c.b) +{ + +} + +Color3::Color3(Color3 && c) noexcept + : r(c.r), g(c.g), b(c.b) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color3::~Color3() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color3 & Color3::operator = (const Color3 & c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; + return *this; +} + +Color3 & Color3::operator = (Color3 && c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color3 & Color3::operator = (Value s) noexcept +{ + r = s; + g = s; + b = s; + return *this; +} + +Color3 & Color3::operator = (const SQChar * name) noexcept +{ + Set(GetColor(name)); + return *this; +} + +Color3 & Color3::operator = (const Color4 & c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color3 & Color3::operator += (const Color3 & c) noexcept +{ + r += c.r; + g += c.g; + b += c.b; + return *this; +} + +Color3 & Color3::operator -= (const Color3 & c) noexcept +{ + r -= c.r; + g -= c.g; + b -= c.b; + return *this; +} + +Color3 & Color3::operator *= (const Color3 & c) noexcept +{ + r *= c.r; + g *= c.g; + b *= c.b; + return *this; +} + +Color3 & Color3::operator /= (const Color3 & c) noexcept +{ + r /= c.r; + g /= c.g; + b /= c.b; + return *this; +} + +Color3 & Color3::operator %= (const Color3 & c) noexcept +{ + r %= c.r; + g %= c.g; + b %= c.b; + return *this; +} + +Color3 & Color3::operator &= (const Color3 & c) noexcept +{ + r &= c.r; + g &= c.g; + b &= c.b; + return *this; +} + +Color3 & Color3::operator |= (const Color3 & c) noexcept +{ + r |= c.r; + g |= c.g; + b |= c.b; + return *this; +} + +Color3 & Color3::operator ^= (const Color3 & c) noexcept +{ + r ^= c.r; + g ^= c.g; + b ^= c.b; + return *this; +} + +Color3 & Color3::operator <<= (const Color3 & c) noexcept +{ + r <<= c.r; + g <<= c.g; + b <<= c.b; + return *this; +} + +Color3 & Color3::operator >>= (const Color3 & c) noexcept +{ + r >>= c.r; + g >>= c.g; + b >>= c.b; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color3 & Color3::operator += (Value s) noexcept +{ + r += s; + g += s; + b += s; + return *this; +} + +Color3 & Color3::operator -= (Value s) noexcept +{ + r -= s; + g -= s; + b -= s; + return *this; +} + +Color3 & Color3::operator *= (Value s) noexcept +{ + r *= s; + g *= s; + b *= s; + return *this; +} + +Color3 & Color3::operator /= (Value s) noexcept +{ + r /= s; + g /= s; + b /= s; + return *this; +} + +Color3 & Color3::operator %= (Value s) noexcept +{ + r %= s; + g %= s; + b %= s; + return *this; +} + +Color3 & Color3::operator &= (Value s) noexcept +{ + r &= s; + g &= s; + b &= s; + return *this; +} + +Color3 & Color3::operator |= (Value s) noexcept +{ + r |= s; + g |= s; + b |= s; + return *this; +} + +Color3 & Color3::operator ^= (Value s) noexcept +{ + r ^= s; + g ^= s; + b ^= s; + return *this; +} + +Color3 & Color3::operator <<= (Value s) noexcept +{ + r <<= s; + g <<= s; + b <<= s; + return *this; +} + +Color3 & Color3::operator >>= (Value s) noexcept +{ + r >>= s; + g >>= s; + b >>= s; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color3 & Color3::operator ++ () noexcept +{ + ++r; + ++g; + ++b; + return *this; +} + +Color3 & Color3::operator -- () noexcept +{ + --r; + --g; + --b; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color3 Color3::operator ++ (int) noexcept +{ + Color3 state(*this); + ++r; + ++g; + ++b; + return state; +} + +Color3 Color3::operator -- (int) noexcept +{ + Color3 state(*this); + --r; + --g; + --b; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Color3 Color3::operator + (const Color3 & c) const noexcept +{ + return Color3(r + c.r, g + c.g, b + c.b); +} + +Color3 Color3::operator - (const Color3 & c) const noexcept +{ + return Color3(r - c.r, g - c.g, b - c.b); +} + +Color3 Color3::operator * (const Color3 & c) const noexcept +{ + return Color3(r * c.r, g * c.g, b * c.b); +} + +Color3 Color3::operator / (const Color3 & c) const noexcept +{ + return Color3(r / c.r, g / c.g, b / c.b); +} + +Color3 Color3::operator % (const Color3 & c) const noexcept +{ + return Color3(r % c.r, g % c.g, b % c.b); +} + +Color3 Color3::operator & (const Color3 & c) const noexcept +{ + return Color3(r & c.r, g & c.g, b & c.b); +} + +Color3 Color3::operator | (const Color3 & c) const noexcept +{ + return Color3(r | c.r, g | c.g, b | c.b); +} + +Color3 Color3::operator ^ (const Color3 & c) const noexcept +{ + return Color3(r ^ c.r, g ^ c.g, b ^ c.b); +} + +Color3 Color3::operator << (const Color3 & c) const noexcept +{ + return Color3(r << c.r, g << c.g, b << c.b); +} + +Color3 Color3::operator >> (const Color3 & c) const noexcept +{ + return Color3(r >> c.r, g >> c.g, b >> c.b); +} + +// ------------------------------------------------------------------------------------------------ +Color3 Color3::operator + (Value s) const noexcept +{ + return Color3(r + s, g + s, b + s); +} + +Color3 Color3::operator - (Value s) const noexcept +{ + return Color3(r - s, g - s, b - s); +} + +Color3 Color3::operator * (Value s) const noexcept +{ + return Color3(r * s, g * s, b * s); +} + +Color3 Color3::operator / (Value s) const noexcept +{ + return Color3(r / s, g / s, b / s); +} + +Color3 Color3::operator % (Value s) const noexcept +{ + return Color3(r % s, g % s, b % s); +} + +Color3 Color3::operator & (Value s) const noexcept +{ + return Color3(r & s, g & s, b & s); +} + +Color3 Color3::operator | (Value s) const noexcept +{ + return Color3(r | s, g | s, b | s); +} + +Color3 Color3::operator ^ (Value s) const noexcept +{ + return Color3(r ^ s, g ^ s, b ^ s); +} + +Color3 Color3::operator << (Value s) const noexcept +{ + return Color3(r << s, g << s, b << s); +} + +Color3 Color3::operator >> (Value s) const noexcept +{ + return Color3(r >> s, g >> s, b >> s); +} + +// ------------------------------------------------------------------------------------------------ +Color3 Color3::operator + () const noexcept +{ + return Color3(r, g, b); +} + +Color3 Color3::operator - () const noexcept +{ + return Color3(0, 0, 0); +} + +// ------------------------------------------------------------------------------------------------ +Color3 Color3::operator ~ () const noexcept +{ + return Color3(~r, ~g, ~b); +} + +// ------------------------------------------------------------------------------------------------ +bool Color3::operator == (const Color3 & c) const noexcept +{ + return (r == c.r) && (g == c.g) && (b == c.b); +} + +bool Color3::operator != (const Color3 & c) const noexcept +{ + return (r != c.r) && (g != c.g) && (b != c.b); +} + +bool Color3::operator < (const Color3 & c) const noexcept +{ + return (r < c.r) && (g < c.g) && (b < c.b); +} + +bool Color3::operator > (const Color3 & c) const noexcept +{ + return (r > c.r) && (g > c.g) && (b > c.b); +} + +bool Color3::operator <= (const Color3 & c) const noexcept +{ + return (r <= c.r) && (g <= c.g) && (b <= c.b); +} + +bool Color3::operator >= (const Color3 & c) const noexcept +{ + return (r >= c.r) && (g >= c.g) && (b >= c.b); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Color3::Cmp(const Color3 & c) const noexcept +{ + return *this == c ? 0 : (*this > c ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Color3::ToString() const noexcept +{ + return ToStringF("%u,%u,%u", r, g, b); +} + +// ------------------------------------------------------------------------------------------------ +void Color3::Set(Value ns) noexcept +{ + r = ns; + g = ns; + b = ns; +} + +void Color3::Set(Value nr, Value ng, Value nb) noexcept +{ + r = nr; + g = ng; + b = nb; +} + +// ------------------------------------------------------------------------------------------------ +void Color3::Set(const Color3 & c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; +} + +void Color3::Set(const Color4 & c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; +} + +// ------------------------------------------------------------------------------------------------ +void Color3::Set(const SQChar * str, SQChar delim) noexcept +{ + Set(GetColor3(str, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Color3::SetCol(const SQChar * name) noexcept +{ + Set(GetColor(name)); +} + +// ------------------------------------------------------------------------------------------------ +SQUint32 Color3::GetRGB() const noexcept +{ + return static_cast(r << 16 | g << 8 | b); +} + +void Color3::SetRGB(SQUint32 p) noexcept +{ + r = static_cast((p >> 16) & 0xFF); + g = static_cast((p >> 8) & 0xFF); + b = static_cast((p) & 0xFF); +} + +// ------------------------------------------------------------------------------------------------ +SQUint32 Color3::GetRGBA() const noexcept +{ + return static_cast(r << 24 | g << 16 | b << 8 | 0x00); +} + +void Color3::SetRGBA(SQUint32 p) noexcept +{ + r = static_cast((p >> 24) & 0xFF); + g = static_cast((p >> 16) & 0xFF); + b = static_cast((p >> 8) & 0xFF); +} + +// ------------------------------------------------------------------------------------------------ +SQUint32 Color3::GetARGB() const noexcept +{ + return static_cast(0x00 << 24 | r << 16 | g << 8 | b); +} + +void Color3::SetARGB(SQUint32 p) noexcept +{ + r = static_cast((p >> 16) & 0xFF); + g = static_cast((p >> 8) & 0xFF); + b = static_cast((p) & 0xFF); +} + +// ------------------------------------------------------------------------------------------------ +void Color3::Generate() noexcept +{ + r = RandomVal::Get(); + g = RandomVal::Get(); + b = RandomVal::Get(); +} + +void Color3::Generate(Value min, Value max) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else + { + r = RandomVal::Get(min, max); + g = RandomVal::Get(min, max); + b = RandomVal::Get(min, max); + } +} + +void Color3::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax) noexcept +{ + if (rmax < rmin || gmax < gmin || bmax < bmin) + { + LogErr("max value is lower than min value"); + } + else + { + r = RandomVal::Get(rmin, rmax); + g = RandomVal::Get(gmin, gmax); + b = RandomVal::Get(bmin, bmax); + } +} + +// ------------------------------------------------------------------------------------------------ +void Color3::Random() noexcept +{ + Set(GetRandomColor()); +} + +// ------------------------------------------------------------------------------------------------ +void Color3::Inverse() noexcept +{ + r = static_cast(~r); + g = static_cast(~g); + b = static_cast(~b); +} + +// ================================================================================================ +bool Register_Color3(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Color3::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Color3"), Sqrat::Class(vm, _SC("Color3")) + .Ctor() + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Color3::Delim) + + .Var(_SC("r"), &Color3::r) + .Var(_SC("g"), &Color3::g) + .Var(_SC("b"), &Color3::b) + + .Prop(_SC("rgb"), &Color3::GetRGB, &Color3::SetRGB) + .Prop(_SC("rgba"), &Color3::GetRGBA, &Color3::SetRGBA) + .Prop(_SC("argb"), &Color3::GetARGB, &Color3::SetARGB) + .Prop(_SC("str"), &Color3::SetCol) + + .Func(_SC("_tostring"), &Color3::ToString) + .Func(_SC("_cmp"), &Color3::Cmp) + + .Func(_SC("_add"), &Color3::operator +) + .Func(_SC("_sub"), &Color3::operator -) + .Func(_SC("_mul"), &Color3::operator *) + .Func(_SC("_div"), &Color3::operator /) + .Func(_SC("_modulo"), &Color3::operator %) + .Func(_SC("_unm"), &Color3::operator -) + + .Overload(_SC("set"), &Color3::Set) + .Overload(_SC("set"), &Color3::Set) + .Overload(_SC("set_col3"), &Color3::Set) + .Overload(_SC("set_col4"), &Color3::Set) + .Overload(_SC("set_str"), &Color3::Set) + + .Overload(_SC("generate"), &Color3::Generate) + .Overload(_SC("generate"), &Color3::Generate) + .Overload(_SC("generate"), &Color3::Generate) + + .Func(_SC("clear"), &Color3::Clear) + .Func(_SC("random"), &Color3::Random) + .Func(_SC("inverse"), &Color3::Inverse) + + .Func(_SC("opAddAssign"), &Color3::operator +=) + .Func(_SC("opSubAssign"), &Color3::operator -=) + .Func(_SC("opMulAssign"), &Color3::operator *=) + .Func(_SC("opDivAssign"), &Color3::operator /=) + .Func(_SC("opModAssign"), &Color3::operator %=) + .Func(_SC("opAndAssign"), &Color3::operator &=) + .Func(_SC("opOrAssign"), &Color3::operator |=) + .Func(_SC("opXorAssign"), &Color3::operator ^=) + .Func(_SC("opShlAssign"), &Color3::operator <<=) + .Func(_SC("opShrAssign"), &Color3::operator >>=) + + .Func(_SC("opAddAssignS"), &Color3::operator +=) + .Func(_SC("opSubAssignS"), &Color3::operator -=) + .Func(_SC("opMulAssignS"), &Color3::operator *=) + .Func(_SC("opDivAssignS"), &Color3::operator /=) + .Func(_SC("opModAssignS"), &Color3::operator %=) + .Func(_SC("opAndAssignS"), &Color3::operator &=) + .Func(_SC("opOrAssignS"), &Color3::operator |=) + .Func(_SC("opXorAssignS"), &Color3::operator ^=) + .Func(_SC("opShlAssignS"), &Color3::operator <<=) + .Func(_SC("opShrAssignS"), &Color3::operator >>=) + + .Func(_SC("opPreInc"), &Color3::operator ++) + .Func(_SC("opPreDec"), &Color3::operator --) + .Func(_SC("opPostInc"), &Color3::operator ++) + .Func(_SC("opPostDec"), &Color3::operator --) + + .Func(_SC("opAdd"), &Color3::operator +) + .Func(_SC("opSub"), &Color3::operator -) + .Func(_SC("opMul"), &Color3::operator *) + .Func(_SC("opDiv"), &Color3::operator /) + .Func(_SC("opMod"), &Color3::operator %) + .Func(_SC("opAnd"), &Color3::operator &) + .Func(_SC("opOr"), &Color3::operator |) + .Func(_SC("opShl"), &Color3::operator ^) + .Func(_SC("opShl"), &Color3::operator <<) + .Func(_SC("opShr"), &Color3::operator >>) + + .Func(_SC("opAddS"), &Color3::operator +) + .Func(_SC("opSubS"), &Color3::operator -) + .Func(_SC("opMulS"), &Color3::operator *) + .Func(_SC("opDivS"), &Color3::operator /) + .Func(_SC("opModS"), &Color3::operator %) + .Func(_SC("opAndS"), &Color3::operator &) + .Func(_SC("opOrS"), &Color3::operator |) + .Func(_SC("opShlS"), &Color3::operator ^) + .Func(_SC("opShlS"), &Color3::operator <<) + .Func(_SC("opShrS"), &Color3::operator >>) + + .Func(_SC("opUnPlus"), &Color3::operator +) + .Func(_SC("opUnMinus"), &Color3::operator -) + .Func(_SC("opCom"), &Color3::operator ~) + + .Func(_SC("opEqual"), &Color3::operator ==) + .Func(_SC("opNotEqual"), &Color3::operator !=) + .Func(_SC("opLessThan"), &Color3::operator <) + .Func(_SC("opGreaterThan"), &Color3::operator >) + .Func(_SC("opLessEqual"), &Color3::operator <=) + .Func(_SC("opGreaterEqual"), &Color3::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Color3.hpp b/source/Base/Color3.hpp new file mode 100644 index 00000000..12ad3b9d --- /dev/null +++ b/source/Base/Color3.hpp @@ -0,0 +1,145 @@ +#ifndef _BASE_COLOR3_HPP_ +#define _BASE_COLOR3_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Color3 +{ + // -------------------------------------------------------------------------------------------- + typedef Uint8 Value; + // -------------------------------------------------------------------------------------------- + static const Color3 NIL; + static const Color3 MIN; + static const Color3 MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Value r, g, b; + // -------------------------------------------------------------------------------------------- + Color3() noexcept; + Color3(Value s) noexcept; + Color3(Value r, Value g, Value b) noexcept; + // -------------------------------------------------------------------------------------------- + Color3(const Color4 & c) noexcept; + // -------------------------------------------------------------------------------------------- + Color3(const SQChar * name) noexcept; + Color3(const SQChar * str, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + Color3(const Color3 & c) noexcept; + Color3(Color3 && c) noexcept; + // -------------------------------------------------------------------------------------------- + ~Color3(); + // -------------------------------------------------------------------------------------------- + Color3 & operator = (const Color3 & c) noexcept; + Color3 & operator = (Color3 && c) noexcept; + // -------------------------------------------------------------------------------------------- + Color3 & operator = (Value s) noexcept; + Color3 & operator = (const SQChar * name) noexcept; + Color3 & operator = (const Color4 & c) noexcept; + // -------------------------------------------------------------------------------------------- + Color3 & operator += (const Color3 & c) noexcept; + Color3 & operator -= (const Color3 & c) noexcept; + Color3 & operator *= (const Color3 & c) noexcept; + Color3 & operator /= (const Color3 & c) noexcept; + Color3 & operator %= (const Color3 & c) noexcept; + Color3 & operator &= (const Color3 & c) noexcept; + Color3 & operator |= (const Color3 & c) noexcept; + Color3 & operator ^= (const Color3 & c) noexcept; + Color3 & operator <<= (const Color3 & c) noexcept; + Color3 & operator >>= (const Color3 & c) noexcept; + // -------------------------------------------------------------------------------------------- + Color3 & operator += (Value s) noexcept; + Color3 & operator -= (Value s) noexcept; + Color3 & operator *= (Value s) noexcept; + Color3 & operator /= (Value s) noexcept; + Color3 & operator %= (Value s) noexcept; + Color3 & operator &= (Value s) noexcept; + Color3 & operator |= (Value s) noexcept; + Color3 & operator ^= (Value s) noexcept; + Color3 & operator <<= (Value s) noexcept; + Color3 & operator >>= (Value s) noexcept; + // -------------------------------------------------------------------------------------------- + Color3 & operator ++ () noexcept; + Color3 & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Color3 operator ++ (int) noexcept; + Color3 operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Color3 operator + (const Color3 & c) const noexcept; + Color3 operator - (const Color3 & c) const noexcept; + Color3 operator * (const Color3 & c) const noexcept; + Color3 operator / (const Color3 & c) const noexcept; + Color3 operator % (const Color3 & c) const noexcept; + Color3 operator & (const Color3 & c) const noexcept; + Color3 operator | (const Color3 & c) const noexcept; + Color3 operator ^ (const Color3 & c) const noexcept; + Color3 operator << (const Color3 & c) const noexcept; + Color3 operator >> (const Color3 & c) const noexcept; + // -------------------------------------------------------------------------------------------- + Color3 operator + (Value s) const noexcept; + Color3 operator - (Value s) const noexcept; + Color3 operator * (Value s) const noexcept; + Color3 operator / (Value s) const noexcept; + Color3 operator % (Value s) const noexcept; + Color3 operator & (Value s) const noexcept; + Color3 operator | (Value s) const noexcept; + Color3 operator ^ (Value s) const noexcept; + Color3 operator << (Value s) const noexcept; + Color3 operator >> (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Color3 operator + () const noexcept; + Color3 operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + Color3 operator ~ () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Color3 & c) const noexcept; + bool operator != (const Color3 & c) const noexcept; + bool operator < (const Color3 & c) const noexcept; + bool operator > (const Color3 & c) const noexcept; + bool operator <= (const Color3 & c) const noexcept; + bool operator >= (const Color3 & c) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Color3 & c) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value ns) noexcept; + void Set(Value nr, Value ng, Value nb) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Color3 & c) noexcept; + void Set(const Color4 & c) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * str, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void SetCol(const SQChar * name) noexcept; + // -------------------------------------------------------------------------------------------- + SQUint32 GetRGB() const noexcept; + void SetRGB(SQUint32 p) noexcept; + // -------------------------------------------------------------------------------------------- + SQUint32 GetRGBA() const noexcept; + void SetRGBA(SQUint32 p) noexcept; + // -------------------------------------------------------------------------------------------- + SQUint32 GetARGB() const noexcept; + void SetARGB(SQUint32 p) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max) noexcept; + void Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { r = 0, g = 0, b = 0; } + // -------------------------------------------------------------------------------------------- + void Random() noexcept; + // -------------------------------------------------------------------------------------------- + void Inverse() noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_COLOR3_HPP_ diff --git a/source/Base/Color4.cpp b/source/Base/Color4.cpp new file mode 100644 index 00000000..c93f5772 --- /dev/null +++ b/source/Base/Color4.cpp @@ -0,0 +1,773 @@ +#include "Base/Color4.hpp" +#include "Base/Color3.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Color4 Color4::NIL = Color4(); +const Color4 Color4::MIN = Color4(std::numeric_limits::min()); +const Color4 Color4::MAX = Color4(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Color4::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Color4::Color4() noexcept + : r(0), g(0), b(0), a(0) +{ + +} + +Color4::Color4(Value s) noexcept + : r(s), g(s), b(s), a(s) +{ + +} + +Color4::Color4(Value rv, Value gv, Value bv) noexcept + : r(rv), g(gv), b(bv), a(0) +{ + +} + +Color4::Color4(Value rv, Value gv, Value bv, Value av) noexcept + : r(rv), g(gv), b(bv), a(av) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color4::Color4(const Color3 & c) noexcept + : r(c.r), g(c.g), b(c.b), a(0) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color4::Color4(const SQChar * name) noexcept + : Color4(GetColor(name)) +{ + +} + +Color4::Color4(const SQChar * str, SQChar delim) noexcept + : Color4(GetColor4(str, delim)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color4::Color4(const Color4 & c) noexcept + : r(c.r), g(c.g), b(c.b), a(c.a) +{ + +} + +Color4::Color4(Color4 && c) noexcept + : r(c.r), g(c.g), b(c.b), a(c.a) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color4::~Color4() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Color4 & Color4::operator = (const Color4 & c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; + return *this; +} + +Color4 & Color4::operator = (Color4 && c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color4 & Color4::operator = (Value s) noexcept +{ + r = s; + g = s; + b = s; + a = s; + return *this; +} + +Color4 & Color4::operator = (const SQChar * name) noexcept +{ + Set(GetColor(name)); + return *this; +} + +Color4 & Color4::operator = (const Color3 & c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color4 & Color4::operator += (const Color4 & c) noexcept +{ + r += c.r; + g += c.g; + b += c.b; + a += c.a; + return *this; +} + +Color4 & Color4::operator -= (const Color4 & c) noexcept +{ + r -= c.r; + g -= c.g; + b -= c.b; + a -= c.a; + return *this; +} + +Color4 & Color4::operator *= (const Color4 & c) noexcept +{ + r *= c.r; + g *= c.g; + b *= c.b; + a *= c.a; + return *this; +} + +Color4 & Color4::operator /= (const Color4 & c) noexcept +{ + r /= c.r; + g /= c.g; + b /= c.b; + a /= c.a; + return *this; +} + +Color4 & Color4::operator %= (const Color4 & c) noexcept +{ + r %= c.r; + g %= c.g; + b %= c.b; + a %= c.a; + return *this; +} + +Color4 & Color4::operator &= (const Color4 & c) noexcept +{ + r &= c.r; + g &= c.g; + b &= c.b; + a &= c.a; + return *this; +} + +Color4 & Color4::operator |= (const Color4 & c) noexcept +{ + r |= c.r; + g |= c.g; + b |= c.b; + a |= c.a; + return *this; +} + +Color4 & Color4::operator ^= (const Color4 & c) noexcept +{ + r ^= c.r; + g ^= c.g; + b ^= c.b; + a ^= c.a; + return *this; +} + +Color4 & Color4::operator <<= (const Color4 & c) noexcept +{ + r <<= c.r; + g <<= c.g; + b <<= c.b; + a <<= c.a; + return *this; +} + +Color4 & Color4::operator >>= (const Color4 & c) noexcept +{ + r >>= c.r; + g >>= c.g; + b >>= c.b; + a >>= c.a; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color4 & Color4::operator += (Value s) noexcept +{ + r += s; + g += s; + b += s; + a += s; + return *this; +} + +Color4 & Color4::operator -= (Value s) noexcept +{ + r -= s; + g -= s; + b -= s; + a -= s; + return *this; +} + +Color4 & Color4::operator *= (Value s) noexcept +{ + r *= s; + g *= s; + b *= s; + a *= s; + return *this; +} + +Color4 & Color4::operator /= (Value s) noexcept +{ + r /= s; + g /= s; + b /= s; + a /= s; + return *this; +} + +Color4 & Color4::operator %= (Value s) noexcept +{ + r %= s; + g %= s; + b %= s; + a %= s; + return *this; +} + +Color4 & Color4::operator &= (Value s) noexcept +{ + r &= s; + g &= s; + b &= s; + a &= s; + return *this; +} + +Color4 & Color4::operator |= (Value s) noexcept +{ + r |= s; + g |= s; + b |= s; + a |= s; + return *this; +} + +Color4 & Color4::operator ^= (Value s) noexcept +{ + r ^= s; + g ^= s; + b ^= s; + a ^= s; + return *this; +} + +Color4 & Color4::operator <<= (Value s) noexcept +{ + r <<= s; + g <<= s; + b <<= s; + a <<= s; + return *this; +} + +Color4 & Color4::operator >>= (Value s) noexcept +{ + r >>= s; + g >>= s; + b >>= s; + a >>= s; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color4 & Color4::operator ++ () noexcept +{ + ++r; + ++g; + ++b; + ++a; + return *this; +} + +Color4 & Color4::operator -- () noexcept +{ + --r; + --g; + --b; + --a; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Color4 Color4::operator ++ (int) noexcept +{ + Color4 state(*this); + ++r; + ++g; + ++b; + ++a; + return state; +} + +Color4 Color4::operator -- (int) noexcept +{ + Color4 state(*this); + --r; + --g; + --b; + --a; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Color4 Color4::operator + (const Color4 & c) const noexcept +{ + return Color4(r + c.r, g + c.g, b + c.b, a + c.a); +} + +Color4 Color4::operator - (const Color4 & c) const noexcept +{ + return Color4(r - c.r, g - c.g, b - c.b, a - c.a); +} + +Color4 Color4::operator * (const Color4 & c) const noexcept +{ + return Color4(r * c.r, g * c.g, b * c.b, a * c.a); +} + +Color4 Color4::operator / (const Color4 & c) const noexcept +{ + return Color4(r / c.r, g / c.g, b / c.b, a / c.a); +} + +Color4 Color4::operator % (const Color4 & c) const noexcept +{ + return Color4(r % c.r, g % c.g, b % c.b, a % c.a); +} + +Color4 Color4::operator & (const Color4 & c) const noexcept +{ + return Color4(r & c.r, g & c.g, b & c.b, a & c.a); +} + +Color4 Color4::operator | (const Color4 & c) const noexcept +{ + return Color4(r | c.r, g | c.g, b | c.b, a | c.a); +} + +Color4 Color4::operator ^ (const Color4 & c) const noexcept +{ + return Color4(r ^ c.r, g ^ c.g, b ^ c.b, a ^ c.a); +} + +Color4 Color4::operator << (const Color4 & c) const noexcept +{ + return Color4(r << c.r, g << c.g, b << c.b, a << c.a); +} + +Color4 Color4::operator >> (const Color4 & c) const noexcept +{ + return Color4(r >> c.r, g >> c.g, b >> c.b, a >> c.a); +} + +// ------------------------------------------------------------------------------------------------ +Color4 Color4::operator + (Value s) const noexcept +{ + return Color4(r + s, g + s, b + s, a + s); +} + +Color4 Color4::operator - (Value s) const noexcept +{ + return Color4(r - s, g - s, b - s, a - s); +} + +Color4 Color4::operator * (Value s) const noexcept +{ + return Color4(r * s, g * s, b * s, a * s); +} + +Color4 Color4::operator / (Value s) const noexcept +{ + return Color4(r / s, g / s, b / s, a / s); +} + +Color4 Color4::operator % (Value s) const noexcept +{ + return Color4(r % s, g % s, b % s, a % s); +} + +Color4 Color4::operator & (Value s) const noexcept +{ + return Color4(r & s, g & s, b & s, a & s); +} + +Color4 Color4::operator | (Value s) const noexcept +{ + return Color4(r | s, g | s, b | s, a | s); +} + +Color4 Color4::operator ^ (Value s) const noexcept +{ + return Color4(r ^ s, g ^ s, b ^ s, a ^ s); +} + +Color4 Color4::operator << (Value s) const noexcept +{ + return Color4(r << s, g << s, b << s, a << s); +} + +Color4 Color4::operator >> (Value s) const noexcept +{ + return Color4(r >> s, g >> s, b >> s, a >> s); +} + +// ------------------------------------------------------------------------------------------------ +Color4 Color4::operator + () const noexcept +{ + return Color4(r, g, b, a); +} + +Color4 Color4::operator - () const noexcept +{ + return Color4(0, 0, 0, 0); +} + +// ------------------------------------------------------------------------------------------------ +Color4 Color4::operator ~ () const noexcept +{ + return Color4(~r, ~g, ~b, ~a); +} + +// ------------------------------------------------------------------------------------------------ +bool Color4::operator == (const Color4 & c) const noexcept +{ + return (r == c.r) && (g == c.g) && (b == c.b) && (a == c.a); +} + +bool Color4::operator != (const Color4 & c) const noexcept +{ + return (r != c.r) && (g != c.g) && (b != c.b) && (a != c.a); +} + +bool Color4::operator < (const Color4 & c) const noexcept +{ + return (r < c.r) && (g < c.g) && (b < c.b) && (a < c.a); +} + +bool Color4::operator > (const Color4 & c) const noexcept +{ + return (r > c.r) && (g > c.g) && (b > c.b) && (a > c.a); +} + +bool Color4::operator <= (const Color4 & c) const noexcept +{ + return (r <= c.r) && (g <= c.g) && (b <= c.b) && (a <= c.a); +} + +bool Color4::operator >= (const Color4 & c) const noexcept +{ + return (r >= c.r) && (g >= c.g) && (b >= c.b) && (a >= c.a); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Color4::Cmp(const Color4 & c) const noexcept +{ + return *this == c ? 0 : (*this > c ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Color4::ToString() const noexcept +{ + return ToStringF("%u,%u,%u,%u", r, g, b, a); +} + +// ------------------------------------------------------------------------------------------------ +void Color4::Set(Value ns) noexcept +{ + r = ns; + g = ns; + b = ns; + a = ns; +} + +void Color4::Set(Value nr, Value ng, Value nb) noexcept +{ + r = nr; + g = ng; + b = nb; +} + +void Color4::Set(Value nr, Value ng, Value nb, Value na) noexcept +{ + r = nr; + g = ng; + b = nb; + a = na; +} + +// ------------------------------------------------------------------------------------------------ +void Color4::Set(const Color4 & c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +void Color4::Set(const Color3 & c) noexcept +{ + r = c.r; + g = c.g; + b = c.b; + a = 0; +} + +// ------------------------------------------------------------------------------------------------ +void Color4::Set(const SQChar * str, SQChar delim) noexcept +{ + Set(GetColor4(str, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Color4::SetCol(const SQChar * name) noexcept +{ + Set(GetColor(name)); +} + +// ------------------------------------------------------------------------------------------------ +SQUint32 Color4::GetRGB() const noexcept +{ + return static_cast(r << 16 | g << 8 | b); +} + +void Color4::SetRGB(SQUint32 p) noexcept +{ + r = static_cast((p >> 16) & 0xFF); + g = static_cast((p >> 8) & 0xFF); + b = static_cast((p) & 0xFF); +} + +// ------------------------------------------------------------------------------------------------ +SQUint32 Color4::GetRGBA() const noexcept +{ + return static_cast(r << 24 | g << 16 | b << 8 | a); +} + +void Color4::SetRGBA(SQUint32 p) noexcept +{ + r = static_cast((p >> 24) & 0xFF); + g = static_cast((p >> 16) & 0xFF); + b = static_cast((p >> 8) & 0xFF); + a = static_cast((p) & 0xFF); +} + +// ------------------------------------------------------------------------------------------------ +SQUint32 Color4::GetARGB() const noexcept +{ + return static_cast(a << 24 | r << 16 | g << 8 | b); +} + +void Color4::SetARGB(SQUint32 p) noexcept +{ + a = static_cast((p >> 24) & 0xFF); + r = static_cast((p >> 16) & 0xFF); + g = static_cast((p >> 8) & 0xFF); + b = static_cast((p) & 0xFF); +} + +// ------------------------------------------------------------------------------------------------ +void Color4::Generate() noexcept +{ + r = RandomVal::Get(); + g = RandomVal::Get(); + b = RandomVal::Get(); + a = RandomVal::Get(); +} + +void Color4::Generate(Value min, Value max) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else + { + r = RandomVal::Get(min, max); + g = RandomVal::Get(min, max); + b = RandomVal::Get(min, max); + a = RandomVal::Get(min, max); + } +} + +void Color4::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax, Value amin, Value amax) noexcept +{ + if (rmax < rmin || gmax < gmin || bmax < bmin || amax < amin) + { + LogErr("max value is lower than min value"); + } + else + { + r = RandomVal::Get(rmin, rmax); + g = RandomVal::Get(gmin, gmax); + b = RandomVal::Get(bmin, bmax); + a = RandomVal::Get(bmin, bmax); + } +} + +// ------------------------------------------------------------------------------------------------ +void Color4::Random() noexcept +{ + Set(GetRandomColor()); +} + +// ------------------------------------------------------------------------------------------------ +void Color4::Inverse() noexcept +{ + r = static_cast(~r); + g = static_cast(~g); + b = static_cast(~b); + a = static_cast(~a); +} + +// ================================================================================================ +bool Register_Color4(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Color4::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Color4"), Sqrat::Class(vm, _SC("Color4")) + .Ctor() + .Ctor() + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Color4::Delim) + + .Var(_SC("r"), &Color4::r) + .Var(_SC("g"), &Color4::g) + .Var(_SC("b"), &Color4::b) + .Var(_SC("a"), &Color4::a) + + .Prop(_SC("rgb"), &Color4::GetRGB, &Color4::SetRGB) + .Prop(_SC("rgba"), &Color4::GetRGBA, &Color4::SetRGBA) + .Prop(_SC("argb"), &Color4::GetARGB, &Color4::SetARGB) + .Prop(_SC("str"), &Color4::SetCol) + + .Func(_SC("_tostring"), &Color4::ToString) + .Func(_SC("_cmp"), &Color4::Cmp) + + .Func(_SC("_add"), &Color4::operator +) + .Func(_SC("_sub"), &Color4::operator -) + .Func(_SC("_mul"), &Color4::operator *) + .Func(_SC("_div"), &Color4::operator /) + .Func(_SC("_modulo"), &Color4::operator %) + .Func(_SC("_unm"), &Color4::operator -) + + .Overload(_SC("set"), &Color4::Set) + .Overload(_SC("set"), &Color4::Set) + .Overload(_SC("set"), &Color4::Set) + .Overload(_SC("set_col4"), &Color4::Set) + .Overload(_SC("set_col3"), &Color4::Set) + .Overload(_SC("set_str"), &Color4::Set) + + .Overload(_SC("generate"), &Color4::Generate) + .Overload(_SC("generate"), &Color4::Generate) + .Overload(_SC("generate"), &Color4::Generate) + + .Func(_SC("clear"), &Color4::Clear) + .Func(_SC("random"), &Color4::Random) + .Func(_SC("inverse"), &Color4::Inverse) + + .Func(_SC("opAddAssign"), &Color4::operator +=) + .Func(_SC("opSubAssign"), &Color4::operator -=) + .Func(_SC("opMulAssign"), &Color4::operator *=) + .Func(_SC("opDivAssign"), &Color4::operator /=) + .Func(_SC("opModAssign"), &Color4::operator %=) + .Func(_SC("opAndAssign"), &Color4::operator &=) + .Func(_SC("opOrAssign"), &Color4::operator |=) + .Func(_SC("opXorAssign"), &Color4::operator ^=) + .Func(_SC("opShlAssign"), &Color4::operator <<=) + .Func(_SC("opShrAssign"), &Color4::operator >>=) + + .Func(_SC("opAddAssignS"), &Color4::operator +=) + .Func(_SC("opSubAssignS"), &Color4::operator -=) + .Func(_SC("opMulAssignS"), &Color4::operator *=) + .Func(_SC("opDivAssignS"), &Color4::operator /=) + .Func(_SC("opModAssignS"), &Color4::operator %=) + .Func(_SC("opAndAssignS"), &Color4::operator &=) + .Func(_SC("opOrAssignS"), &Color4::operator |=) + .Func(_SC("opXorAssignS"), &Color4::operator ^=) + .Func(_SC("opShlAssignS"), &Color4::operator <<=) + .Func(_SC("opShrAssignS"), &Color4::operator >>=) + + .Func(_SC("opPreInc"), &Color4::operator ++) + .Func(_SC("opPreDec"), &Color4::operator --) + .Func(_SC("opPostInc"), &Color4::operator ++) + .Func(_SC("opPostDec"), &Color4::operator --) + + .Func(_SC("opAdd"), &Color4::operator +) + .Func(_SC("opSub"), &Color4::operator -) + .Func(_SC("opMul"), &Color4::operator *) + .Func(_SC("opDiv"), &Color4::operator /) + .Func(_SC("opMod"), &Color4::operator %) + .Func(_SC("opAnd"), &Color4::operator &) + .Func(_SC("opOr"), &Color4::operator |) + .Func(_SC("opShl"), &Color4::operator ^) + .Func(_SC("opShl"), &Color4::operator <<) + .Func(_SC("opShr"), &Color4::operator >>) + + .Func(_SC("opAddS"), &Color4::operator +) + .Func(_SC("opSubS"), &Color4::operator -) + .Func(_SC("opMulS"), &Color4::operator *) + .Func(_SC("opDivS"), &Color4::operator /) + .Func(_SC("opModS"), &Color4::operator %) + .Func(_SC("opAndS"), &Color4::operator &) + .Func(_SC("opOrS"), &Color4::operator |) + .Func(_SC("opShlS"), &Color4::operator ^) + .Func(_SC("opShlS"), &Color4::operator <<) + .Func(_SC("opShrS"), &Color4::operator >>) + + .Func(_SC("opUnPlus"), &Color4::operator +) + .Func(_SC("opUnMinus"), &Color4::operator -) + .Func(_SC("opCom"), &Color4::operator ~) + + .Func(_SC("opEqual"), &Color4::operator ==) + .Func(_SC("opNotEqual"), &Color4::operator !=) + .Func(_SC("opLessThan"), &Color4::operator <) + .Func(_SC("opGreaterThan"), &Color4::operator >) + .Func(_SC("opLessEqual"), &Color4::operator <=) + .Func(_SC("opGreaterEqual"), &Color4::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Color4.hpp b/source/Base/Color4.hpp new file mode 100644 index 00000000..ee881e85 --- /dev/null +++ b/source/Base/Color4.hpp @@ -0,0 +1,147 @@ +#ifndef _BASE_COLOR4_HPP_ +#define _BASE_COLOR4_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Color4 +{ + // -------------------------------------------------------------------------------------------- + typedef Uint8 Value; + // -------------------------------------------------------------------------------------------- + static const Color4 NIL; + static const Color4 MIN; + static const Color4 MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Value r, g, b, a; + // -------------------------------------------------------------------------------------------- + Color4() noexcept; + Color4(Value s) noexcept; + Color4(Value r, Value g, Value b) noexcept; + Color4(Value r, Value g, Value b, Value a) noexcept; + // -------------------------------------------------------------------------------------------- + Color4(const Color3 & c) noexcept; + // -------------------------------------------------------------------------------------------- + Color4(const SQChar * name) noexcept; + Color4(const SQChar * str, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + Color4(const Color4 & c) noexcept; + Color4(Color4 && c) noexcept; + // -------------------------------------------------------------------------------------------- + ~Color4(); + // -------------------------------------------------------------------------------------------- + Color4 & operator = (const Color4 & c) noexcept; + Color4 & operator = (Color4 && c) noexcept; + // -------------------------------------------------------------------------------------------- + Color4 & operator = (Value s) noexcept; + Color4 & operator = (const SQChar * name) noexcept; + Color4 & operator = (const Color3 & c) noexcept; + // -------------------------------------------------------------------------------------------- + Color4 & operator += (const Color4 & c) noexcept; + Color4 & operator -= (const Color4 & c) noexcept; + Color4 & operator *= (const Color4 & c) noexcept; + Color4 & operator /= (const Color4 & c) noexcept; + Color4 & operator %= (const Color4 & c) noexcept; + Color4 & operator &= (const Color4 & c) noexcept; + Color4 & operator |= (const Color4 & c) noexcept; + Color4 & operator ^= (const Color4 & c) noexcept; + Color4 & operator <<= (const Color4 & c) noexcept; + Color4 & operator >>= (const Color4 & c) noexcept; + // -------------------------------------------------------------------------------------------- + Color4 & operator += (Value s) noexcept; + Color4 & operator -= (Value s) noexcept; + Color4 & operator *= (Value s) noexcept; + Color4 & operator /= (Value s) noexcept; + Color4 & operator %= (Value s) noexcept; + Color4 & operator &= (Value s) noexcept; + Color4 & operator |= (Value s) noexcept; + Color4 & operator ^= (Value s) noexcept; + Color4 & operator <<= (Value s) noexcept; + Color4 & operator >>= (Value s) noexcept; + // -------------------------------------------------------------------------------------------- + Color4 & operator ++ () noexcept; + Color4 & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Color4 operator ++ (int) noexcept; + Color4 operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Color4 operator + (const Color4 & c) const noexcept; + Color4 operator - (const Color4 & c) const noexcept; + Color4 operator * (const Color4 & c) const noexcept; + Color4 operator / (const Color4 & c) const noexcept; + Color4 operator % (const Color4 & c) const noexcept; + Color4 operator & (const Color4 & c) const noexcept; + Color4 operator | (const Color4 & c) const noexcept; + Color4 operator ^ (const Color4 & c) const noexcept; + Color4 operator << (const Color4 & c) const noexcept; + Color4 operator >> (const Color4 & c) const noexcept; + // -------------------------------------------------------------------------------------------- + Color4 operator + (Value s) const noexcept; + Color4 operator - (Value s) const noexcept; + Color4 operator * (Value s) const noexcept; + Color4 operator / (Value s) const noexcept; + Color4 operator % (Value s) const noexcept; + Color4 operator & (Value s) const noexcept; + Color4 operator | (Value s) const noexcept; + Color4 operator ^ (Value s) const noexcept; + Color4 operator << (Value s) const noexcept; + Color4 operator >> (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Color4 operator + () const noexcept; + Color4 operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + Color4 operator ~ () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Color4 & c) const noexcept; + bool operator != (const Color4 & c) const noexcept; + bool operator < (const Color4 & c) const noexcept; + bool operator > (const Color4 & c) const noexcept; + bool operator <= (const Color4 & c) const noexcept; + bool operator >= (const Color4 & c) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Color4 & c) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value ns) noexcept; + void Set(Value nr, Value ng, Value nb) noexcept; + void Set(Value nr, Value ng, Value nb, Value na) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Color4 & c) noexcept; + void Set(const Color3 & c) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * name, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void SetCol(const SQChar * name) noexcept; + // -------------------------------------------------------------------------------------------- + SQUint32 GetRGB() const noexcept; + void SetRGB(SQUint32 p) noexcept; + // -------------------------------------------------------------------------------------------- + SQUint32 GetRGBA() const noexcept; + void SetRGBA(SQUint32 p) noexcept; + // -------------------------------------------------------------------------------------------- + SQUint32 GetARGB() const noexcept; + void SetARGB(SQUint32 p) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max) noexcept; + void Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax, Value amin, Value amax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { r = 0, g = 0, b = 0, a = 0; } + // -------------------------------------------------------------------------------------------- + void Random() noexcept; + // -------------------------------------------------------------------------------------------- + void Inverse() noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_COLOR4_HPP_ diff --git a/source/Base/Quaternion.cpp b/source/Base/Quaternion.cpp new file mode 100644 index 00000000..c55451ac --- /dev/null +++ b/source/Base/Quaternion.cpp @@ -0,0 +1,562 @@ +#include "Base/Quaternion.hpp" +#include "Base/Vector3.hpp" +#include "Base/Vector4.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Quaternion Quaternion::NIL = Quaternion(0); +const Quaternion Quaternion::MIN = Quaternion(std::numeric_limits::min()); +const Quaternion Quaternion::MAX = Quaternion(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Quaternion::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Quaternion::Quaternion() noexcept + : x(0.0), y(0.0), z(0.0), w(0.0) +{ + +} + +Quaternion::Quaternion(Value s) noexcept + : x(s), y(s), z(s), w(s) +{ + +} + +Quaternion::Quaternion(Value xv, Value yv, Value zv) noexcept + : x(xv), y(yv), z(zv), w(0.0) +{ + +} + +Quaternion::Quaternion(Value xv, Value yv, Value zv, Value wv) noexcept + : x(xv), y(yv), z(zv), w(wv) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Quaternion::Quaternion(const Vector3 & v) noexcept + : x(v.x), y(v.y), z(v.z), w(0.0) +{ + +} + +Quaternion::Quaternion(const Vector4 & v) noexcept + : x(v.x), y(v.y), z(v.z), w(v.w) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Quaternion::Quaternion(const SQChar * values, SQChar delim) noexcept + : Quaternion(GetQuaternion(values, delim)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Quaternion::Quaternion(const Quaternion & q) noexcept + : x(q.x), y(q.y), z(q.z), w(q.w) +{ + +} + +Quaternion::Quaternion(Quaternion && q) noexcept + : x(q.x), y(q.y), z(q.z), w(q.w) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Quaternion::~Quaternion() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Quaternion & Quaternion::operator = (const Quaternion & q) noexcept +{ + x = q.x; + y = q.y; + z = q.z; + w = q.w; + return *this; +} + +Quaternion & Quaternion::operator = (Quaternion && q) noexcept +{ + x = q.x; + y = q.y; + z = q.z; + w = q.w; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Quaternion & Quaternion::operator = (Value s) noexcept +{ + x = s; + y = s; + z = s; + w = s; + return *this; +} + +Quaternion & Quaternion::operator = (const Vector3 & q) noexcept +{ + x = q.x; + y = q.y; + z = q.z; + w = 0.0; + return *this; +} + +Quaternion & Quaternion::operator = (const Vector4 & q) noexcept +{ + x = q.x; + y = q.y; + z = q.z; + w = q.w; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Quaternion & Quaternion::operator += (const Quaternion & q) noexcept +{ + x += q.x; + y += q.y; + z += q.z; + w += q.w; + return *this; +} + +Quaternion & Quaternion::operator -= (const Quaternion & q) noexcept +{ + x -= q.x; + y -= q.y; + z -= q.z; + w -= q.w; + return *this; +} + +Quaternion & Quaternion::operator *= (const Quaternion & q) noexcept +{ + x *= q.x; + y *= q.y; + z *= q.z; + w *= q.w; + return *this; +} + +Quaternion & Quaternion::operator /= (const Quaternion & q) noexcept +{ + x /= q.x; + y /= q.y; + z /= q.z; + w /= q.w; + return *this; +} + +Quaternion & Quaternion::operator %= (const Quaternion & q) noexcept +{ + x = std::fmod(x, q.x); + y = std::fmod(y, q.y); + z = std::fmod(z, q.z); + w = std::fmod(w, q.w); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Quaternion & Quaternion::operator += (Value s) noexcept +{ + x += s; + y += s; + z += s; + w += s; + return *this; +} + +Quaternion & Quaternion::operator -= (Value s) noexcept +{ + x -= s; + y -= s; + z -= s; + w -= s; + return *this; +} + +Quaternion & Quaternion::operator *= (Value s) noexcept +{ + x *= s; + y *= s; + z *= s; + w *= s; + return *this; +} + +Quaternion & Quaternion::operator /= (Value s) noexcept +{ + x /= s; + y /= s; + z /= s; + w /= s; + return *this; +} + +Quaternion & Quaternion::operator %= (Value s) noexcept +{ + x = std::fmod(x, s); + y = std::fmod(y, s); + z = std::fmod(z, s); + w = std::fmod(w, s); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Quaternion & Quaternion::operator ++ () noexcept +{ + ++x; + ++y; + ++z; + ++w; + return *this; +} + +Quaternion & Quaternion::operator -- () noexcept +{ + --x; + --y; + --z; + --w; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Quaternion Quaternion::operator ++ (int) noexcept +{ + Quaternion state(*this); + ++x; + ++y; + ++z; + ++w; + return state; +} + +Quaternion Quaternion::operator -- (int) noexcept +{ + Quaternion state(*this); + --x; + --y; + --z; + --w; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Quaternion Quaternion::operator + (const Quaternion & q) const noexcept +{ + return Quaternion(x + q.x, y + q.y, z + q.z, w + q.w); +} + +Quaternion Quaternion::operator + (Value s) const noexcept +{ + return Quaternion(x + s, y + s, z + s, w + s); +} + +// ------------------------------------------------------------------------------------------------ +Quaternion Quaternion::operator - (const Quaternion & q) const noexcept +{ + return Quaternion(x - q.x, y - q.y, z - q.z, w - q.w); +} + +Quaternion Quaternion::operator - (Value s) const noexcept +{ + return Quaternion(x - s, y - s, z - s, w - s); +} + +// ------------------------------------------------------------------------------------------------ +Quaternion Quaternion::operator * (const Quaternion & q) const noexcept +{ + return Quaternion(x * q.x, y * q.y, z * q.z, w * q.w); +} + +Quaternion Quaternion::operator * (Value s) const noexcept +{ + return Quaternion(x * s, y * s, z * s, w * s); +} + +// ------------------------------------------------------------------------------------------------ +Quaternion Quaternion::operator / (const Quaternion & q) const noexcept +{ + return Quaternion(x / q.x, y / q.y, z / q.z, w / q.w); +} + +Quaternion Quaternion::operator / (Value s) const noexcept +{ + return Quaternion(x / s, y / s, z / s, w / s); +} + +// ------------------------------------------------------------------------------------------------ +Quaternion Quaternion::operator % (const Quaternion & q) const noexcept +{ + return Quaternion(std::fmod(x, q.x), std::fmod(y, q.y), std::fmod(z, q.z), std::fmod(w, q.w)); +} + +Quaternion Quaternion::operator % (Value s) const noexcept +{ + return Quaternion(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s)); +} + +// ------------------------------------------------------------------------------------------------ +Quaternion Quaternion::operator + () const noexcept +{ + return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w)); +} + +Quaternion Quaternion::operator - () const noexcept +{ + return Quaternion(-x, -y, -z, -w); +} + +// ------------------------------------------------------------------------------------------------ +bool Quaternion::operator == (const Quaternion & q) const noexcept +{ + return EpsEq(x, q.x) && EpsEq(y, q.y) && EpsEq(z, q.z) && EpsEq(w, q.w); +} + +bool Quaternion::operator != (const Quaternion & q) const noexcept +{ + return !EpsEq(x, q.x) && !EpsEq(y, q.y) && !EpsEq(z, q.z) && !EpsEq(w, q.w); +} + +bool Quaternion::operator < (const Quaternion & q) const noexcept +{ + return std::isless(x, q.x) && std::isless(y, q.y) && std::isless(z, q.z) && std::isless(w, q.w); +} + +bool Quaternion::operator > (const Quaternion & q) const noexcept +{ + return std::isgreater(x, q.x) && std::isgreater(y, q.y) && std::isgreater(z, q.z) && std::isgreater(w, q.w); +} + +bool Quaternion::operator <= (const Quaternion & q) const noexcept +{ + return std::islessequal(x, q.x) && std::islessequal(y, q.y) && std::islessequal(z, q.z) && std::islessequal(w, q.w); +} + +bool Quaternion::operator >= (const Quaternion & q) const noexcept +{ + return std::isgreaterequal(x, q.x) && std::isgreaterequal(y, q.y) && std::isgreaterequal(z, q.z) && std::isgreaterequal(w, q.w); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Quaternion::Cmp(const Quaternion & q) const noexcept +{ + return *this == q ? 0 : (*this > q ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Quaternion::ToString() const noexcept +{ + return ToStringF("%f,%f,%f,%f", x, y, z, w); +} + +// ------------------------------------------------------------------------------------------------ +void Quaternion::Set(Value ns) noexcept +{ + x = ns; + y = ns; + z = ns; + w = ns; +} + +void Quaternion::Set(Value nx, Value ny, Value nz) noexcept +{ + x = nx; + y = ny; + z = nz; +} + +void Quaternion::Set(Value nx, Value ny, Value nz, Value nw) noexcept +{ + x = nx; + y = ny; + z = nz; + w = nw; +} + +// ------------------------------------------------------------------------------------------------ +void Quaternion::Set(const Quaternion & q) noexcept +{ + x = q.x; + y = q.y; + z = q.z; + w = q.w; +} + +void Quaternion::Set(const Vector3 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + w = 0.0; +} + +void Quaternion::Set(const Vector4 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + w = v.w; +} + +// ------------------------------------------------------------------------------------------------ +void Quaternion::Set(const SQChar * values, SQChar delim) noexcept +{ + Set(GetQuaternion(values, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Quaternion::Generate() noexcept +{ + x = RandomVal::Get(); + y = RandomVal::Get(); + z = RandomVal::Get(); + w = RandomVal::Get(); +} + +void Quaternion::Generate(Value min, Value max) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(min, max); + y = RandomVal::Get(min, max); + z = RandomVal::Get(min, max); + y = RandomVal::Get(min, max); + } +} + +void Quaternion::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax) noexcept +{ + if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin) || std::isless(wmax, wmin)) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(xmin, xmax); + y = RandomVal::Get(ymin, ymax); + z = RandomVal::Get(zmin, zmax); + y = RandomVal::Get(ymin, ymax); + } +} + +// ------------------------------------------------------------------------------------------------ +Quaternion Quaternion::Abs() const noexcept +{ + return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w)); +} + +// ================================================================================================ +bool Register_Quaternion(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Quaternion::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Quaternion"), Sqrat::Class(vm, _SC("Quaternion")) + .Ctor() + .Ctor() + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Quaternion::Delim) + + .Var(_SC("x"), &Quaternion::x) + .Var(_SC("y"), &Quaternion::y) + .Var(_SC("z"), &Quaternion::z) + .Var(_SC("w"), &Quaternion::w) + + .Prop(_SC("abs"), &Quaternion::Abs) + + .Func(_SC("_tostring"), &Quaternion::ToString) + .Func(_SC("_cmp"), &Quaternion::Cmp) + + .Func(_SC("_add"), &Quaternion::operator +) + .Func(_SC("_sub"), &Quaternion::operator -) + .Func(_SC("_mul"), &Quaternion::operator *) + .Func(_SC("_div"), &Quaternion::operator /) + .Func(_SC("_modulo"), &Quaternion::operator %) + .Func(_SC("_unm"), &Quaternion::operator -) + + .Overload(_SC("set"), &Quaternion::Set) + .Overload(_SC("set"), &Quaternion::Set) + .Overload(_SC("set"), &Quaternion::Set) + .Overload(_SC("set_quat"), &Quaternion::Set) + .Overload(_SC("set_vec3"), &Quaternion::Set) + .Overload(_SC("set_vec4"), &Quaternion::Set) + .Overload(_SC("set_str"), &Quaternion::Set) + + .Overload(_SC("generate"), &Quaternion::Generate) + .Overload(_SC("generate"), &Quaternion::Generate) + .Overload(_SC("generate"), &Quaternion::Generate) + + .Func(_SC("clear"), &Quaternion::Clear) + + .Func(_SC("opAddAssign"), &Quaternion::operator +=) + .Func(_SC("opSubAssign"), &Quaternion::operator -=) + .Func(_SC("opMulAssign"), &Quaternion::operator *=) + .Func(_SC("opDivAssign"), &Quaternion::operator /=) + .Func(_SC("opModAssign"), &Quaternion::operator %=) + + .Func(_SC("opAddAssignS"), &Quaternion::operator +=) + .Func(_SC("opSubAssignS"), &Quaternion::operator -=) + .Func(_SC("opMulAssignS"), &Quaternion::operator *=) + .Func(_SC("opDivAssignS"), &Quaternion::operator /=) + .Func(_SC("opModAssignS"), &Quaternion::operator %=) + + .Func(_SC("opPreInc"), &Quaternion::operator ++) + .Func(_SC("opPreDec"), &Quaternion::operator --) + .Func(_SC("opPostInc"), &Quaternion::operator ++) + .Func(_SC("opPostDec"), &Quaternion::operator --) + + .Func(_SC("opAdd"), &Quaternion::operator +) + .Func(_SC("opSub"), &Quaternion::operator -) + .Func(_SC("opMul"), &Quaternion::operator *) + .Func(_SC("opDiv"), &Quaternion::operator /) + .Func(_SC("opMod"), &Quaternion::operator %) + + .Func(_SC("opAddS"), &Quaternion::operator +) + .Func(_SC("opSubS"), &Quaternion::operator -) + .Func(_SC("opMulS"), &Quaternion::operator *) + .Func(_SC("opDivS"), &Quaternion::operator /) + .Func(_SC("opModS"), &Quaternion::operator %) + + .Func(_SC("opUnPlus"), &Quaternion::operator +) + .Func(_SC("opUnMinus"), &Quaternion::operator -) + + .Func(_SC("opEqual"), &Quaternion::operator ==) + .Func(_SC("opNotEqual"), &Quaternion::operator !=) + .Func(_SC("opLessThan"), &Quaternion::operator <) + .Func(_SC("opGreaterThan"), &Quaternion::operator >) + .Func(_SC("opLessEqual"), &Quaternion::operator <=) + .Func(_SC("opGreaterEqual"), &Quaternion::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Quaternion.hpp b/source/Base/Quaternion.hpp new file mode 100644 index 00000000..61ce3eb3 --- /dev/null +++ b/source/Base/Quaternion.hpp @@ -0,0 +1,113 @@ +#ifndef _BASE_QUATERNION_HPP_ +#define _BASE_QUATERNION_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Quaternion +{ + // -------------------------------------------------------------------------------------------- + typedef SQFloat Value; + // -------------------------------------------------------------------------------------------- + static const Quaternion NIL; + static const Quaternion MIN; + static const Quaternion MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Value x, y, z, w; + // -------------------------------------------------------------------------------------------- + Quaternion() noexcept; + Quaternion(Value s) noexcept; + Quaternion(Value xv, Value yv, Value zv) noexcept; + Quaternion(Value xv, Value yv, Value zv, Value wv) noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion(const Vector3 & v) noexcept; + Quaternion(const Vector4 & v) noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion(const Quaternion & q) noexcept; + Quaternion(Quaternion && q) noexcept; + // -------------------------------------------------------------------------------------------- + ~Quaternion(); + // -------------------------------------------------------------------------------------------- + Quaternion & operator = (const Quaternion & q) noexcept; + Quaternion & operator = (Quaternion && q) noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion & operator = (Value s) noexcept; + Quaternion & operator = (const Vector3 & q) noexcept; + Quaternion & operator = (const Vector4 & q) noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion & operator += (const Quaternion & q) noexcept; + Quaternion & operator -= (const Quaternion & q) noexcept; + Quaternion & operator *= (const Quaternion & q) noexcept; + Quaternion & operator /= (const Quaternion & q) noexcept; + Quaternion & operator %= (const Quaternion & q) noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion & operator += (Value s) noexcept; + Quaternion & operator -= (Value s) noexcept; + Quaternion & operator *= (Value s) noexcept; + Quaternion & operator /= (Value s) noexcept; + Quaternion & operator %= (Value s) noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion & operator ++ () noexcept; + Quaternion & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion operator ++ (int) noexcept; + Quaternion operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion operator + (const Quaternion & q) const noexcept; + Quaternion operator - (const Quaternion & q) const noexcept; + Quaternion operator * (const Quaternion & q) const noexcept; + Quaternion operator / (const Quaternion & q) const noexcept; + Quaternion operator % (const Quaternion & q) const noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion operator + (Value s) const noexcept; + Quaternion operator - (Value s) const noexcept; + Quaternion operator * (Value s) const noexcept; + Quaternion operator / (Value s) const noexcept; + Quaternion operator % (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Quaternion operator + () const noexcept; + Quaternion operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Quaternion & q) const noexcept; + bool operator != (const Quaternion & q) const noexcept; + bool operator < (const Quaternion & q) const noexcept; + bool operator > (const Quaternion & q) const noexcept; + bool operator <= (const Quaternion & q) const noexcept; + bool operator >= (const Quaternion & q) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Quaternion & q) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value ns) noexcept; + void Set(Value nx, Value ny, Value nz) noexcept; + void Set(Value nx, Value ny, Value nz, Value nw) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Quaternion & q) noexcept; + void Set(const Vector3 & v) noexcept; + void Set(const Vector4 & v) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { x = 0.0, y = 0.0, z = 0.0, w = 0.0; } + // -------------------------------------------------------------------------------------------- + Quaternion Abs() const noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_QUATERNION_HPP_ diff --git a/source/Base/Shared.cpp b/source/Base/Shared.cpp new file mode 100644 index 00000000..dc678260 --- /dev/null +++ b/source/Base/Shared.cpp @@ -0,0 +1,1848 @@ +#include "Base/Shared.hpp" +#include "Register.hpp" +#include "Logger.hpp" +#include "Core.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/Vector2i.hpp" +#include "Base/Vector2u.hpp" +#include "Base/Vector2f.hpp" +#include "Base/Vector3.hpp" +#include "Base/Vector4.hpp" + +// ------------------------------------------------------------------------------------------------ +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +static std::unique_ptr RG32_MT19937 = std::unique_ptr( \ + new std::mt19937(static_cast(std::time(0)))); + +static std::unique_ptr RG64_MT19937 = std::unique_ptr( \ + new std::mt19937_64(static_cast(std::time(0)))); + +// ------------------------------------------------------------------------------------------------ +static std::uniform_int_distribution Int8_Dist(std::numeric_limits::min(), std::numeric_limits::max()); +static std::uniform_int_distribution UInt8_Dist(std::numeric_limits::min(), std::numeric_limits::max()); + +static std::uniform_int_distribution Int16_Dist(std::numeric_limits::min(), std::numeric_limits::max()); +static std::uniform_int_distribution UInt16_Dist(std::numeric_limits::min(), std::numeric_limits::max()); + +static std::uniform_int_distribution Int32_Dist(std::numeric_limits::min(), std::numeric_limits::max()); +static std::uniform_int_distribution UInt32_Dist(std::numeric_limits::min(), std::numeric_limits::max()); + +static std::uniform_int_distribution Int64_Dist(std::numeric_limits::min(), std::numeric_limits::max()); +static std::uniform_int_distribution UInt64_Dist(std::numeric_limits::min(), std::numeric_limits::max()); + +static std::uniform_real_distribution Float32_Dist(std::numeric_limits::min(), std::numeric_limits::max()); +static std::uniform_real_distribution Float64_Dist(std::numeric_limits::min(), std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +static std::uniform_int_distribution String_Dist(std::numeric_limits::min(), std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +static const std::vector SQ_Color_List +{ + Color3(240, 248, 255), + Color3(250, 235, 215), + Color3(0, 255, 255), + Color3(127, 255, 212), + Color3(240, 255, 255), + Color3(245, 245, 220), + Color3(255, 228, 196), + Color3(0, 0, 0), + Color3(255, 235, 205), + Color3(0, 0, 255), + Color3(138, 43, 226), + Color3(165, 42, 42), + Color3(222, 184, 135), + Color3(95, 158, 160), + Color3(127, 255, 0), + Color3(210, 105, 30), + Color3(255, 127, 80), + Color3(100, 149, 237), + Color3(255, 248, 220), + Color3(220, 20, 60), + Color3(0, 255, 255), + Color3(0, 0, 139), + Color3(0, 139, 139), + Color3(184, 134, 11), + Color3(169, 169, 169), + Color3(0, 100, 0), + Color3(189, 183, 107), + Color3(139, 0, 139), + Color3(85, 107, 47), + Color3(255, 140, 0), + Color3(153, 50, 204), + Color3(139, 0, 0), + Color3(233, 150, 122), + Color3(143, 188, 143), + Color3(72, 61, 139), + Color3(47, 79, 79), + Color3(0, 206, 209), + Color3(148, 0, 211), + Color3(255, 20, 147), + Color3(0, 191, 255), + Color3(105, 105, 105), + Color3(30, 144, 255), + Color3(178, 34, 34), + Color3(255, 250, 240), + Color3(34, 139, 34), + Color3(255, 0, 255), + Color3(220, 220, 220), + Color3(248, 248, 255), + Color3(255, 215, 0), + Color3(218, 165, 32), + Color3(128, 128, 128), + Color3(0, 128, 0), + Color3(173, 255, 47), + Color3(240, 255, 240), + Color3(255, 105, 180), + Color3(205, 92, 92), + Color3(75, 0, 130), + Color3(255, 255, 240), + Color3(240, 230, 140), + Color3(230, 230, 250), + Color3(255, 240, 245), + Color3(124, 252, 0), + Color3(255, 250, 205), + Color3(173, 216, 230), + Color3(240, 128, 128), + Color3(224, 255, 255), + Color3(250, 250, 210), + Color3(211, 211, 211), + Color3(144, 238, 144), + Color3(255, 182, 193), + Color3(255, 160, 122), + Color3(32, 178, 170), + Color3(135, 206, 250), + Color3(119, 136, 153), + Color3(176, 196, 222), + Color3(255, 255, 224), + Color3(0, 255, 0), + Color3(50, 205, 50), + Color3(250, 240, 230), + Color3(255, 0, 255), + Color3(128, 0, 0), + Color3(102, 205, 170), + Color3(0, 0, 205), + Color3(186, 85, 211), + Color3(147, 112, 219), + Color3(60, 179, 113), + Color3(123, 104, 238), + Color3(0, 250, 154), + Color3(72, 209, 204), + Color3(199, 21, 133), + Color3(25, 25, 112), + Color3(245, 255, 250), + Color3(255, 228, 225), + Color3(255, 228, 181), + Color3(255, 222, 173), + Color3(0, 0, 128), + Color3(253, 245, 230), + Color3(128, 128, 0), + Color3(107, 142, 35), + Color3(255, 165, 0), + Color3(255, 69, 0), + Color3(218, 112, 214), + Color3(238, 232, 170), + Color3(152, 251, 152), + Color3(175, 238, 238), + Color3(219, 112, 147), + Color3(255, 239, 213), + Color3(255, 218, 185), + Color3(205, 133, 63), + Color3(255, 192, 203), + Color3(221, 160, 221), + Color3(176, 224, 230), + Color3(128, 0, 128), + Color3(255, 0, 0), + Color3(188, 143, 143), + Color3(65, 105, 225), + Color3(139, 69, 19), + Color3(250, 128, 114), + Color3(244, 164, 96), + Color3(46, 139, 87), + Color3(255, 245, 238), + Color3(160, 82, 45), + Color3(192, 192, 192), + Color3(135, 206, 235), + Color3(106, 90, 205), + Color3(112, 128, 144), + Color3(255, 250, 250), + Color3(0, 255, 127), + Color3(70, 130, 180), + Color3(210, 180, 140), + Color3(0, 128, 128), + Color3(216, 191, 216), + Color3(255, 99, 71), + Color3(64, 224, 208), + Color3(238, 130, 238), + Color3(245, 222, 179), + Color3(255, 255, 255), + Color3(245, 245, 245), + Color3(255, 255, 0), + Color3(154, 205, 50) +}; + +// ------------------------------------------------------------------------------------------------ +void LogDbg(const char * fmt, ...) noexcept +{ + va_list args; + va_start(args, fmt); + _Log->Send(Logger::LEVEL_DBG, false, fmt, args); + va_end(args); +} + +void LogMsg(const char * fmt, ...) noexcept +{ + va_list args; + va_start(args, fmt); + _Log->Send(Logger::LEVEL_MSG, false, fmt, args); + va_end(args); +} + +void LogScs(const char * fmt, ...) noexcept +{ + va_list args; + va_start(args, fmt); + _Log->Send(Logger::LEVEL_SCS, false, fmt, args); + va_end(args); +} + +void LogInf(const char * fmt, ...) noexcept +{ + va_list args; + va_start(args, fmt); + _Log->Send(Logger::LEVEL_INF, false, fmt, args); + va_end(args); +} + +void LogWrn(const char * fmt, ...) noexcept +{ + va_list args; + va_start(args, fmt); + _Log->Send(Logger::LEVEL_WRN, false, fmt, args); + va_end(args); +} + +void LogErr(const char * fmt, ...) noexcept +{ + va_list args; + va_start(args, fmt); + _Log->Send(Logger::LEVEL_ERR, false, fmt, args); + va_end(args); +} + +void LogFtl(const char * fmt, ...) noexcept +{ + va_list args; + va_start(args, fmt); + _Log->Send(Logger::LEVEL_FTL, false, fmt, args); + va_end(args); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * ToStringF(const char * fmt, ...) noexcept +{ + // Acquire a buffer from the buffer pool + Core::Buffer vbuf = _Core->PullBuffer(); + // Get direct access to the buffer data + Core::Buffer::value_type * buf = vbuf.data(); + // Variable arguments structure + va_list args; + // Get the specified arguments + va_start (args, fmt); + // Run the specified format + int ret = std::vsnprintf(buf, vbuf.size() * sizeof(Core::Buffer::value_type), fmt, args); + // Check for buffer overflows + if (static_cast(ret) >= vbuf.size()) + { + // Throw error + LogErr("Buffer overflow object to string conversion: %d > %d", ret, vbuf.size()); + // Return an empty string + buf[0] = '\0'; + } + // Check for formatting errors + else if (ret < 0) + { + // Throw error + LogErr("Failed to convert object to string"); + // Return an empty string + buf[0] = '\0'; + } + // Move the buffer back to the buffer pool + _Core->PushBuffer(std::move(vbuf)); + // The buffer data wasn't destroyed and Squirrel should have time to copy it + return buf; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * InsertStr(const SQChar * f, const std::vector< const SQChar * > & a) noexcept +{ + // Acquire a buffer from the buffer pool + Core::Buffer vbuf = _Core->PullBuffer(); + // Get direct access to the buffer data + Core::Buffer::value_type * buf = vbuf.data(); + // Get the size of the buffer + const Core::Buffer::size_type sz = vbuf.size(); + // Size of the resulted string and the number of specified arguments + unsigned n = 0, s = a.size(); + // See if the format string is valid + if (f) + { + // Temporary variables used for processing characters + SQChar c = 0, p = 0; + // Process each character in the format string + while ((c = *(f++)) && (n < sz)) + { + // Peek at the next character + p = *f; + // Check for argument character + if (c != '%') + { + // Add this character to the buffer + buf[n++] = c; + } + // See if the argument character is escaped + else if (p == '%') + { + // Skip the escaping character + ++f; + // Add this character to the buffer + buf[n++] = '%'; + } + // See if there's a number to extract + else if (p >= 48 && p <= 57) + { + // Attempt to extract a numeric value + long int i = strtol(f, nullptr, 10); + // Skip until the first non digit character + while (*f >= 48 && *f <= 57) + { + ++f; + } + // Force the index to be in range + i = i <= 0 ? 0 : (i >= (long int)s ? s : i); + // Don't even bother if the argument isn't valid + if (a[i]) + { + // Get the specified argument + const SQChar * v = a[i]; + // Add the specified argument to the buffer + while ((c = *(v++)) && (n < sz)) + { + buf[n++] = c; + } + } + } + // Fallback to regular replication + else + { + // Add this character to the buffer + buf[n++] = c; + } + } + + } + // Insert the null character + buf[n] = '\0'; + // Move the buffer back to the buffer pool + _Core->PushBuffer(std::move(vbuf)); + // The buffer data wasn't destroyed and Squirrel should have time to copy it + return buf; +} + +// Utility for the function +const SQChar * InsStr(const SQChar * f) noexcept +{ + return InsertStr(f, std::vector< const SQChar * >()); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * LeftStr(const SQChar * t, SQChar f, SQUint32 w) noexcept +{ + // Acquire a buffer from the buffer pool + Core::Buffer vbuf = _Core->PullBuffer(); + // Get direct access to the buffer data + Core::Buffer::value_type * buf = vbuf.data(); + // Get the length of the string + SQUint32 n = strlen(t); + // Fill the buffer with the specified fill character + memset(buf, f, w * sizeof(Core::Buffer::value_type)); + // Is the width in bounds? + if (w >= vbuf.size()) + { + LogWrn("Invalid width specified: %d > %d", w, vbuf.size()); + // Invalidate the width + w = 0; + } + // Is the string empty? + else if (n < 0) + { + LogWrn("Invalid string length: %d < 0", n); + } + // Is the string in bounds? + else if (n > w) + { + LogWrn("String is out of bounds: %d > %d", n, w); + } + // Insert the string + else + { + strncpy(buf, t, n); + } + // Add the terminating character + buf[w] = '\0'; + // Move the buffer back to the buffer pool + _Core->PushBuffer(std::move(vbuf)); + // The buffer data wasn't destroyed and Squirrel should have time to copy it + return buf; +} + +const SQChar * LeftStr(const SQChar * t, SQChar f, SQUint32 w, SQUint32 o) noexcept +{ + // Acquire a buffer from the buffer pool + Core::Buffer vbuf = _Core->PullBuffer(); + // Get direct access to the buffer data + Core::Buffer::value_type * buf = vbuf.data(); + // Get the length of the string + SQUint32 n = strlen(t); + // Fill the buffer with the specified fill character + memset(buf, f, w * sizeof(Core::Buffer::value_type)); + // Is the width in bounds? + if (w >= vbuf.size()) + { + LogWrn("Invalid width specified: %d > %d", w, vbuf.size()); + // Invalidate the width + w = 0; + } + // Is the string empty? + else if (n < 0) + { + LogWrn("Invalid string length: %d < 0", n); + } + // Is the string in bounds? + else if ((o+n) > w) + { + LogWrn("String is out of bounds: (%d+%d) > %d", o, n, w); + } + // Insert the string + else + { + strncpy(buf + o, t, n); + } + // Add the terminating character + buf[w] = '\0'; + // Move the buffer back to the buffer pool + _Core->PushBuffer(std::move(vbuf)); + // The buffer data wasn't destroyed and Squirrel should have time to copy it + return buf; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * RightStr(const SQChar * t, SQChar f, SQUint32 w) noexcept +{ + // Acquire a buffer from the buffer pool + Core::Buffer vbuf = _Core->PullBuffer(); + // Get direct access to the buffer data + Core::Buffer::value_type * buf = vbuf.data(); + // Get the length of the string + SQUint32 n = strlen(t); + // Fill the buffer with the specified fill character + memset(buf, f, w * sizeof(Core::Buffer::value_type)); + // Is the width in bounds? + if (w >= vbuf.size()) + { + LogWrn("Invalid width specified: %d > %d", w, vbuf.size()); + // Invalidate the width + w = 0; + } + // Is the string empty? + else if (n < 0) + { + LogWrn("Invalid string length: %d < 0", n); + } + // Is the string in bounds? + else if (n > w) + { + LogWrn("String is out of bounds: %d > %d", n, w); + } + // Insert the string + else + { + strncpy(buf + (w-n), t, n); + } + // Add the terminating character + buf[w] = '\0'; + // Move the buffer back to the buffer pool + _Core->PushBuffer(std::move(vbuf)); + // The buffer data wasn't destroyed and Squirrel should have time to copy it + return buf; +} + +const SQChar * RightStr(const SQChar * t, SQChar f, SQUint32 w, SQUint32 o) noexcept +{ + // Acquire a buffer from the buffer pool + Core::Buffer vbuf = _Core->PullBuffer(); + // Get direct access to the buffer data + Core::Buffer::value_type * buf = vbuf.data(); + // Get the length of the string + SQUint32 n = strlen(t); + // Fill the buffer with the specified fill character + memset(buf, f, w * sizeof(Core::Buffer::value_type)); + // Is the width in bounds? + if (w >= vbuf.size()) + { + LogWrn("Invalid width specified: %d > %d", w, vbuf.size()); + // Invalidate the width + w = 0; + } + // Is the string empty? + else if (n < 0) + { + LogWrn("Invalid string length: %d < 0", n); + } + // Is the string in bounds? + else if ((n+o) > w) + { + LogWrn("String is out of bounds: (%d+%d) > %d", n, o, w); + } + // Insert the string + else + { + strncpy(buf + ((w-n)-o), t, n); + } + // Add the terminating character + buf[w] = '\0'; + // Move the buffer back to the buffer pool + _Core->PushBuffer(std::move(vbuf)); + // The buffer data wasn't destroyed and Squirrel should have time to copy it + return buf; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CenterStr(const SQChar * t, SQChar f, SQUint32 w) noexcept +{ + // Acquire a buffer from the buffer pool + Core::Buffer vbuf = _Core->PullBuffer(); + // Get direct access to the buffer data + Core::Buffer::value_type * buf = vbuf.data(); + // Get the length of the string + SQUint32 n = strlen(t); + // Fill the buffer with the specified fill character + memset(buf, f, w * sizeof(Core::Buffer::value_type)); + // Is the width in bounds? + if (w >= vbuf.size()) + { + LogWrn("Invalid width specified: %d > %d", w, vbuf.size()); + // Invalidate the width + w = 0; + } + // Is the string empty? + else if (n < 0) + { + LogWrn("Invalid string length: %d < 0", n); + } + // Is the string in bounds? + else if (n > w) + { + LogWrn("String is out of bounds: %d > %d", n, w); + } + // Insert the string + else + { + strncpy(buf + (w/2 - n/2), t, n); + } + // Add the terminating character + buf[w] = '\0'; + // Move the buffer back to the buffer pool + _Core->PushBuffer(std::move(vbuf)); + // The buffer data wasn't destroyed and Squirrel should have time to copy it + return buf; +} + +// ------------------------------------------------------------------------------------------------ +void InitMTRG32() noexcept +{ + RG32_MT19937.reset(new std::mt19937(static_cast(std::time(0)))); +} + +// ------------------------------------------------------------------------------------------------ +void InitMTRG64() noexcept +{ + RG64_MT19937.reset(new std::mt19937_64(static_cast(std::time(0)))); +} + +// ------------------------------------------------------------------------------------------------ +Int8 GetRandomInt8() noexcept +{ + return Int8_Dist(*RG32_MT19937); +} + +Int8 GetRandomInt8(Int8 min, Int8 max) noexcept +{ + std::uniform_int_distribution dist(min, max); + return dist(*RG32_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +Uint8 GetRandomUint8() noexcept +{ + return UInt8_Dist(*RG32_MT19937); +} + +Uint8 GetRandomUint8(Uint8 min, Uint8 max) noexcept +{ + std::uniform_int_distribution dist(min, max); + return dist(*RG32_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +Int16 GetRandomInt16() noexcept +{ + return Int16_Dist(*RG32_MT19937); +} + +Int16 GetRandomInt16(Int16 min, Int16 max) noexcept +{ + std::uniform_int_distribution dist(min, max); + return dist(*RG32_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +Uint16 GetRandomUint16() noexcept +{ + return UInt16_Dist(*RG32_MT19937); +} + +Uint16 GetRandomUint16(Uint16 min, Uint16 max) noexcept +{ + std::uniform_int_distribution dist(min, max); + return dist(*RG32_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +Int32 GetRandomInt32() noexcept +{ + return Int32_Dist(*RG32_MT19937); +} + +Int32 GetRandomInt32(Int32 min, Int32 max) noexcept +{ + std::uniform_int_distribution dist(min, max); + return dist(*RG32_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +Uint32 GetRandomUint32() noexcept +{ + return UInt32_Dist(*RG32_MT19937); +} + +Uint32 GetRandomUint32(Uint32 min, Uint32 max) noexcept +{ + std::uniform_int_distribution dist(min, max); + return dist(*RG32_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +Int64 GetRandomInt64() noexcept +{ + return Int64_Dist(*RG64_MT19937); +} + +Int64 GetRandomInt64(Int64 min, Int64 max) noexcept +{ + std::uniform_int_distribution dist(min, max); + return dist(*RG64_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +Uint64 GetRandomUint64() noexcept +{ + return UInt64_Dist(*RG64_MT19937); +} + +Uint64 GetRandomUint64(Uint64 min, Uint64 max) noexcept +{ + std::uniform_int_distribution dist(min, max); + return dist(*RG64_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +Float32 GetRandomFloat32() noexcept +{ + return Float32_Dist(*RG32_MT19937); +} + +Float32 GetRandomFloat32(Float32 min, Float32 max) noexcept +{ + std::uniform_real_distribution dist(min, max); + return dist(*RG32_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +Float64 GetRandomFloat64() noexcept +{ + return Float64_Dist(*RG64_MT19937); +} + +Float64 GetRandomFloat64(Float64 min, Float64 max) noexcept +{ + std::uniform_real_distribution dist(min, max); + return dist(*RG64_MT19937); +} + +// ------------------------------------------------------------------------------------------------ +String GetRandomString(String::size_type len) noexcept +{ + String str(len, 0); + std::generate(str.begin(), str.end(), [&] () -> String::value_type { return String_Dist(*RG32_MT19937); }); + return std::move(str); +} + +String GetRandomString(String::size_type len, String::value_type min, String::value_type max) noexcept +{ + String str(len, 0); + std::uniform_int_distribution dist(min, max); + std::generate(str.begin(), str.end(), [&] () -> String::value_type { return dist(*RG32_MT19937); }); + return std::move(str); +} + +// ------------------------------------------------------------------------------------------------ +bool GetRandomBool() noexcept +{ + return Int8_Dist(*RG32_MT19937) > 0 ? true : false; +} + +// ------------------------------------------------------------------------------------------------ +const Color3 & GetRandomColor() noexcept +{ + return SQ_Color_List.at(GetRandomUint32(0, SQ_Color_List.size()-1)); +} + +// -------------------------------------------------------------------------------------------- +bool SToB(const SQChar * str) noexcept +{ + return (strcmp(str, "true") == 0 || \ + strcmp(str, "yes") == 0 || \ + strcmp(str, "on") == 0 || \ + strcmp(str, "1") == 0) ? true : false; +} + +// ------------------------------------------------------------------------------------------------ +Color3 GetColor(const SQChar * name) noexcept +{ + // See if we actually have something to search for + if(std::strlen(name) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return Color3::NIL; + } + // Clone the string into an editable version + String str = String(name); + // Strip non alphanumeric characters from the name + str.erase(std::remove_if(str.begin(), str.end(), std::not1(std::ptr_fun(::isalnum))), str.end()); + // Convert the string to lowercase + std::transform(str.begin(), str.end(), str.begin(), ::tolower); + // See if we still have a valid name after the cleanup + if(str.empty()) + { + LogErr("Cannot extract values from an invalid string: %s", name); + return Color3::NIL; + } + // Grab the actual length of the string + std::size_t len = str.length(); + // 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 + if(str.length() >= 3) + { + c = str[2]; + b = str[1]; + } + else if(str.length() >= 2) + { + b = str[1]; + } + // Search for a pattern in the name + switch(a) + { + // [A]liceBlue + // [A]ntiqueWhite + // [A]qua + // [A]quamarine + // [A]zure + case 'a': + switch (b) + { + // [Al]iceBlue + case 'l': return Color3(240, 248, 255); + // [Aq]ua[m]arine + case 'm': return Color3(127, 255, 212); + // [An]tiqueWhite + case 'n': return Color3(250, 235, 215); + // [Aq]ua + // [Aq]uamarine + case 'q': + // [Aq]u[a] + if (d == 'a') return Color3(0, 255, 255); + // [Aq]ua[m]arin[e] + else if (d == 'e' || (len > 4 && str[4] == 'm')) return Color3(127, 255, 212); + // Default to blank + else return Color3::NIL; + // [Az]ure + case 'z': return Color3(240, 255, 255); + // Default to blank + default: return Color3::NIL; + } + // [B]eige + // [B]isque + // [B]lack + // [B]lanchedAlmond + // [B]lue + // [B]lueViolet + // [B]rown + // [B]urlyWood + case 'b': + switch (b) + { + // [B]lanched[A]lmond + case 'a': return Color3(255, 235, 205); + // [Be]ige + case 'e': return Color3(245, 245, 220); + // [Bi]sque + case 'i': return Color3(255, 228, 196); + // [Bl]ack + // [Bl]anchedAlmond + // [Bl]ue + // [Bl]ueViolet + case 'l': + // [Bl]a[ck] + if (d == 'k' || d == 'c') return Color3(0, 0, 0); + // [Bl]anched[A]lmon[d] + else if (d == 'd' || (len > 8 && str[8] == 'a')) return Color3(255, 235, 205); + // [Bl]u[e] + else if (d == 'e') return Color3(0, 0, 255); + // [Bl]ue[V]iole[t] + else if (d == 't' || (len > 4 && str[4] == 'v')) return Color3(138, 43, 226); + // Default to blank + else return Color3::NIL; + // [Br]own + case 'r': return Color3(165, 42, 42); + // [Bu]rlyWood + case 'u': return Color3(222, 184, 135); + // [B]lue[V]iolet + case 'v': return Color3(138, 43, 226); + // Default to blank + default: return Color3::NIL; + } + // [C]adetBlue + // [C]hartreuse + // [C]hocolate + // [C]oral + // [C]ornflowerBlue + // [C]ornsilk + // [C]rimson + // [C]yan + case 'c': + switch (b) + { + // [Ca]detBlue + case 'a': return Color3(95, 158, 160); + // [Ch]artreuse + // [Ch]ocolate + case 'h': + // [Ch]artreuse + if (c == 'a') return Color3(127, 255, 0); + // [Ch]ocolate + else if (c == 'o') return Color3(210, 105, 30); + // Default to blank + else return Color3::NIL; + // [Co]ral + // [Co]rnflowerBlue + // [Co]rnsilk + case 'o': + // [Co]ra[l] + if (d == 'l') return Color3(255, 127, 80); + // [Co]rnflower[B]lu[e] + else if (d == 'e' || (len > 10 && str[10] == 'b')) return Color3(100, 149, 237); + // [Co]rnsil[k] + else if (d == 'k') return Color3(255, 248, 220); + // Default to blank + else return Color3::NIL; + // [Cr]imson + case 'r': return Color3(220, 20, 60); + // [Cy]an + case 'y': return Color3(0, 255, 255); + // Default to blank + default: return Color3::NIL; + } + // [D]arkBlue + // [D]arkCyan + // [D]arkGoldenRod + // [D]arkGray + // [D]arkGreen + // [D]arkKhaki + // [D]arkMagenta + // [D]arkOliveGreen + // [D]arkOrange + // [D]arkOrchid + // [D]arkRed + // [D]arkSalmon + // [D]arkSeaGreen + // [D]arkSlateBlue + // [D]arkSlateGray + // [D]arkTurquoise + // [D]arkViolet + // [D]eepPink + // [D]eepSkyBlue + // [D]imGray + // [D]odgerBlue + case 'd': + // [Di]mGray + if (b == 'i' || b == 'g') return Color3(105, 105, 105); + // [Do]dgerBlue + else if (b == 'o' || b == 'b') return Color3(30, 144, 255); + // [De]ep[P]in[k] + else if (b == 'e' && (d == 'k' || (len > 4 && str[4] == 'p'))) return Color3(255, 20, 147); + // [De]ep[S]kyBlu[e] + else if (b == 'e' && (d == 'e' || (len > 4 && str[4] == 's'))) return Color3(0, 191, 255); + // [Da]rkBlue + // [Da]rkCyan + // [Da]rkGoldenRod + // [Da]rkGray + // [Da]rkGreen + // [Da]rkKhaki + // [Da]rkMagenta + // [Da]rkOliveGreen + // [Da]rkOrange + // [Da]rkOrchid + // [Da]rkRed + // [Da]rkSalmon + // [Da]rkSeaGreen + // [Da]rkSlateBlue + // [Da]rkSlateGray + // [Da]rkTurquoise + // [Da]rkViolet + else if (b == 'a') { + // [Da]rk[B]lue + if (c == 'b' || (len > 4 && str[4] == 'b')) return Color3(0, 0, 139); + // [Da]rk[C]yan + else if (c == 'c' || (len > 4 && str[4] == 'c')) return Color3(0, 139, 139); + // [Da]rk[Go]ldenRo[d] + else if ((len > 4 && str[4] == 'g') && (d == 'd' || d == 'o')) return Color3(184, 134, 11); + // [Da]rk[G]r[ay] + else if ((len > 4 && str[4] == 'g') && (d == 'y' || d == 'a')) return Color3(169, 169, 169); + // [Da]rk[G]r[een] + else if ((len > 4 && str[4] == 'g') && (d == 'n' || d == 'e')) return Color3(0, 100, 0); + // [Da]rk[K]hak[i] + else if (d == 'i' || c == 'k' || (len > 4 && str[4] == 'k')) return Color3(189, 183, 107); + // [Da]rk[M]agent[a] + else if (d == 'a' || c == 'm' || (len > 4 && str[4] == 'm')) return Color3(139, 0, 139); + // [Da]rk[O]liveGr[een] + else if ((len > 4 && str[4] == 'o') && (d == 'n' || d == 'e')) return Color3(85, 107, 47); + // [Da]rk[O]r[a]ng[e] + else if ((len > 4 && str[4] == 'o') && (d == 'e' || d == 'a')) return Color3(255, 140, 0); + // [Da]rk[O]r[c]hi[d] + else if ((len > 4 && str[4] == 'o') && (d == 'd' || d == 'c')) return Color3(153, 50, 204); + // [Da]rk[R]ed + else if (len > 4 && str[4] == 'r') return Color3(139, 0, 0); + // [Da]rk[Sa]lmon + else if (len > 5 && str[4] == 's' && str[5] == 'a') return Color3(233, 150, 122); + // [Da]rk[Se]aGreen + else if (len > 5 && str[4] == 's' && str[5] == 'e') return Color3(143, 188, 143); + // [Da]rk[S]lateBlu[e] + else if ((len > 4 && str[4] == 's') && (d == 'e' || d == 'b')) return Color3(72, 61, 139); + // [Da]rk[S]lateGra[y] + else if ((len > 4 && str[4] == 's') && (d == 'y' || d == 'g')) return Color3(47, 79, 79); + // [Da]rk[T]urquoise + else if (c == 't' || (len > 4 && str[4] == 't')) return Color3(0, 206, 209); + // [Da]rk[V]iolet + else if (c == 'v' || (len > 4 && str[4] == 'v')) return Color3(148, 0, 211); + // Default to blank + else return Color3::NIL; + // Default to blank + } else return Color3::NIL; + // [F]ireBrick + // [F]loralWhite + // [F]orestGreen + // [F]uchsia + case 'f': + switch (b) + { + // [Fi]re[B]rick + case 'i': + case 'b': return Color3(178, 34, 34); + // [Fl]oral[W]hite + case 'l': + case 'w': return Color3(255, 250, 240); + // [Fo]rest[G]reen + case 'o': + case 'g': return Color3(34, 139, 34); + // [Fu]chsia + case 'u': return Color3(255, 0, 255); + // Default to blank + default: return Color3::NIL; + } + // [G]ainsboro + // [G]hostWhite + // [G]old + // [G]oldenRod + // [G]ray + // [G]reen + // [G]reenYellow + case 'g': + // [Ga]insboro + if (b == 'a') return Color3(220, 220, 220); + // [Gh]ost[W]hite + else if (b == 'h' || b == 'w') return Color3(248, 248, 255); + // [Go]ld[e]n[R]od + else if (len > 4 && (str[4] == 'e' || str[4] == 'r')) return Color3(218, 165, 32); + // [Go]l[d] + else if (b == 'o' && d == 'd') return Color3(255, 215, 0); + // [Gray] + else if (b == 'r' && (d == 'y' || d == 'a')) return Color3(128, 128, 128); + // [Gr]een + else if (b == 'r' && d == 'n') return Color3(0, 128, 0); + // [Gr]eenYellow + else if (b == 'r' && (d == 'w' || (len > 5 && str[5] == 'y'))) return Color3(173, 255, 47); + // Default to blank + else return Color3::NIL; + // [H]oneyDew + // [H]otPink + case 'h': + // [H]o[n]ey[D]e[w] + if (d == 'w' || c == 'n' || (len > 5 && str[5] == 'd')) return Color3(240, 255, 240); + // [H]o[tP]in[k] + else if (d == 'k' || c == 't' || (len > 3 && str[3] == 'p')) return Color3(255, 105, 180); + // Default to blank + else return Color3::NIL; + // [I]ndianRed + // [I]ndigo + // [I]vory + case 'i': + // [In]dian[R]e[d] + if (b == 'n' && (d == 'd' || d == 'r')) return Color3(205, 92, 92); + // [In]di[go] + else if (b == 'n' && (d == 'o' || d == 'g')) return Color3(75, 0, 130); + // [I]vory + else if (b == 'v') return Color3(255, 255, 240); + // Default to blank + else return Color3::NIL; + // [K]haki + case 'k': return Color3(240, 230, 140); + // [L]avender + // [L]avenderBlush + // [L]awnGreen + // [L]emonChiffon + // [L]ightBlue + // [L]ightCoral + // [L]ightCyan + // [L]ightGoldenRodYellow + // [L]ightGray + // [L]ightGreen + // [L]ightPink + // [L]ightSalmon + // [L]ightSeaGreen + // [L]ightSkyBlue + // [L]ightSlateGray + // [L]ightSteelBlue + // [L]ightYellow + // [L]ime + // [L]imeGreen + // [L]inen + case 'l': + // [La]vende[r] + if (b == 'a' && d == 'r') return Color3(230, 230, 250); + // [La]vender[B]lus[h] + else if (b == 'a' && (d == 'h' || d == 'b')) return Color3(255, 240, 245); + // [Law]n[G]ree[n] + else if (b == 'g' || (b == 'a' && (c == 'w' || d == 'n'))) return Color3(124, 252, 0); + // [Le]mon[C]hiffon + else if (b == 'e' || b == 'c') return Color3(255, 250, 205); + // [Li]me[G]reen + else if (b == 'g' || (b == 'i' && (len > 4 && str[4] == 'g'))) return Color3(50, 205, 50); + // [Lime] + else if (b == 'i' && c == 'm' && d == 'e') return Color3(0, 255, 0); + // [Lin]e[n] + else if (b == 'i' && (c == 'n' || d == 'n')) return Color3(250, 240, 230); + // [Li]ghtBlue + // [Li]ghtCoral + // [Li]ghtCyan + // [Li]ghtGoldenRodYellow + // [Li]ghtGray + // [Li]ghtGreen + // [Li]ghtPink + // [Li]ghtSalmon + // [Li]ghtSeaGreen + // [Li]ghtSkyBlue + // [Li]ghtSlateGray + // [Li]ghtSteelBlue + // [Li]ghtYellow + else if (b == 'i') { + // [Li]ght[B]lue + if (len > 5 && str[5] == 'b') return Color3(173, 216, 230); + // [Li]ght[Co]ra[l] + else if ((len > 5 && str[5] == 'c') && (d == 'l' || d == 'o')) return Color3(240, 128, 128); + // [Li]ght[Cy]a[n] + else if ((len > 5 && str[5] == 'c') && (d == 'n' || d == 'y')) return Color3(224, 255, 255); + // [Li]ght[Go]ldenRodYello[w] + else if ((len > 5 && str[5] == 'g') && (d == 'w' || d == 'o')) return Color3(250, 250, 210); + // [Li]ght[G]r[ay] + else if ((len > 5 && str[5] == 'g') && (d == 'y' || d == 'a')) return Color3(211, 211, 211); + // [Li]ght[G]r[een] + else if ((len > 5 && str[5] == 'g') && (d == 'n' || d == 'e')) return Color3(144, 238, 144); + // [Li]ght[P]ink + else if (len > 5 && str[5] == 'p') return Color3(255, 182, 193); + // [Li]ght[Sa]lmon + else if (len > 6 && str[5] == 's' && str[5] == 'a') return Color3(255, 160, 122); + // [Li]ght[Se]aGreen + else if (len > 6 && str[5] == 's' && str[5] == 'e') return Color3(32, 178, 170); + // [Li]ght[Sk]yBlue + else if (len > 6 && str[5] == 's' && str[5] == 'k') return Color3(135, 206, 250); + // [Li]ght[Sl]ateGray + else if (len > 6 && str[5] == 's' && str[5] == 'l') return Color3(119, 136, 153); + // [Li]ght[St]eelBlue + else if (len > 6 && str[5] == 's' && str[5] == 't') return Color3(176, 196, 222); + // [Li]ght[Y]ellow + else if (len > 5 && str[5] == 'y') return Color3(255, 255, 224); + // Default to blank + else return Color3::NIL; + // Default to blank + } else return Color3::NIL; + // [M]agenta + // [M]aroon + // [M]ediumAquaMarine + // [M]ediumBlue + // [M]ediumOrchid + // [M]ediumPurple + // [M]ediumSeaGreen + // [M]ediumSlateBlue + // [M]ediumSpringGreen + // [M]ediumTurquoise + // [M]ediumVioletRed + // [M]idnightBlue + // [M]intCream + // [M]istyRose + // [M]occasin + case 'm': + // [Ma]genta + if (b == 'a' && (c == 'a' || d == 'a')) return Color3(255, 0, 255); + // [Ma]roon + else if (b == 'a' && (c == 'r' || d == 'n' || d == 'o')) return Color3(128, 0, 0); + // [Me]diumAquaMarine + // [Me]diumBlue + // [Me]diumOrchid + // [Me]diumPurple + // [Me]diumSeaGreen + // [Me]diumSlateBlue + // [Me]diumSpringGreen + // [Me]diumTurquoise + // [Me]diumVioletRed + else if (b == 'e') { + // [Me]dium[A]quaMarine + if (c == 'a' || (len > 6 && str[6] == 'a')) return Color3(102, 205, 170); + // [Me]dium[B]lue + else if (c == 'b' || (len > 6 && str[6] == 'b')) return Color3(0, 0, 205); + // [Me]dium[O]rchid + else if (c == 'o' || (len > 6 && str[6] == 'o')) return Color3(186, 85, 211); + // [Me]dium[P]urple + else if (c == 'p' || (len > 6 && str[6] == 'p')) return Color3(147, 112, 219); + // [Me]dium[T]urquoise + else if (c == 't' || (len > 6 && str[6] == 't')) return Color3(72, 209, 204); + // [Me]dium[V]ioletRed + else if (c == 'v' || (len > 6 && str[6] == 'v')) return Color3(199, 21, 133); + // [Me]dium[Se]aGreen + else if (len > 7 && str[6] == 's' && str[7] == 'e') return Color3(60, 179, 113); + // [Me]dium[Sl]ateBlue + else if (len > 7 && str[6] == 's' && str[7] == 'l') return Color3(123, 104, 238); + // [Me]dium[Sp]ringGreen + else if (len > 7 && str[6] == 's' && str[7] == 'p') return Color3(0, 250, 154); + // Default to blank + else return Color3::NIL; + } + // [Mi]dnightBlue + else if (b == 'i' && c == 'd') return Color3(25, 25, 112); + // [Mi]ntCream + else if (b == 'i' && c == 'n') return Color3(245, 255, 250); + // [Mi]styRose + else if (b == 'i' && c == 's') return Color3(255, 228, 225); + // [Mo]ccasin + else if (b == 'o') return Color3(255, 228, 181); + // Default to blank + else return Color3::NIL; + // [N]avajoWhite + // [N]avy + case 'n': + // [Na]vajo[W]hite + if (c == 'v' || c == 'w') return Color3(255, 222, 173); + // [Na]v[y] + else if (c == 'a' || d == 'y') return Color3(0, 0, 128); + // Default to blank + else return Color3::NIL; + // [O]ldLace + // [O]live + // [O]liveDrab + // [O]range + // [O]rangeRed + // [O]rchid + case 'o': + // [Old]Lace + if (b == 'l' && c == 'd') return Color3(253, 245, 230); + // [Ol]ive[D]ra[b] + else if (b == 'l' && (d == 'b' || d == 'd')) return Color3(107, 142, 35); + // [Ol]iv[e] + else if (b == 'l' && d == 'e') return Color3(128, 128, 0); + // [Or]ange[R]e[d] + else if (b == 'r' && (d == 'd' || d == 'r')) return Color3(255, 69, 0); + // [Or]ang[e] + else if (b == 'r' && d == 'e') return Color3(255, 165, 0); + // [Orc]hid + else if (d == 'c') return Color3(218, 112, 214); + // Default to blank + else return Color3::NIL; + // [P]aleGoldenRod + // [P]aleGreen + // [P]aleTurquoise + // [P]aleVioletRed + // [P]apayaWhip + // [P]eachPuff + // [P]eru + // [P]ink + // [P]lum + // [P]owderBlue + // [P]urple + case 'p': + // [Pu]rple + if (b == 'u') return Color3(128, 0, 128); + // [Po]wderBlue + else if (b == 'o') return Color3(176, 224, 230); + // [Pi]nk + else if (b == 'i') return Color3(255, 192, 203); + // [Pl]um + else if (b == 'l') return Color3(221, 160, 221); + // [Pea]chPuff + else if (b == 'e' && c == 'a') return Color3(255, 218, 185); + // [Per]u + else if (b == 'e' && c == 'r') return Color3(205, 133, 63); + // [Pa]payaWhip + else if (b == 'a' && c == 'p') return Color3(255, 239, 213); + // [Pa]le[Go]ldenRod + else if (b == 'a' && (len > 5 && str[4] == 'g' && str[5] == 'o')) return Color3(238, 232, 170); + // [Pa]le[Gr]een + else if (b == 'a' && (len > 5 && str[4] == 'g' && str[5] == 'r')) return Color3(152, 251, 152); + // [Pa]le[T]urquoise + else if (b == 'a' && (len > 4 && str[4] == 't')) return Color3(175, 238, 238); + // [Pa]le[V]ioletRed + else if (b == 'a' && (len > 4 && str[4] == 'v')) return Color3(219, 112, 147); + // Default to blank + else return Color3::NIL; + // [R]ed + // [R]osyBrown + // [R]oyalBlue + case 'r': + // [Re]d + if (b == 'e') return Color3(255, 0, 0); + // [Ros]yBrown + else if (b == 'o' && c == 's') return Color3(188, 143, 143); + // [Roy]alBlue + else if (b == 'o' && c == 'y') return Color3(65, 105, 225); + // Default to blank + else return Color3::NIL; + // [S]addleBrown + // [S]almon + // [S]andyBrown + // [S]eaGreen + // [S]eaShell + // [S]ienna + // [S]ilver + // [S]kyBlue + // [S]lateBlue + // [S]lateGray + // [S]now + // [S]pringGreen + // [S]teelBlue + case 's': + // [Sad]dleBrown + if (b == 'a' && c == 'd') return Color3(139, 69, 19); + // [Sal]mon + else if (b == 'a' && c == 'l') return Color3(250, 128, 114); + // [San]dyBrown + else if (b == 'a' && c == 'n') return Color3(244, 164, 96); + // [Se]a[G]reen + else if (b == 'e' && d == 'g') return Color3(46, 139, 87); + // [Se]a[S]hell + else if (b == 'e' && d == 's') return Color3(255, 245, 238); + // [Sie]nna + else if (b == 'i' && c == 'e') return Color3(160, 82, 45); + // [Sil]ver + else if (b == 'i' && c == 'l') return Color3(192, 192, 192); + // [Sk]yBlue + else if (b == 'k') return Color3(135, 206, 235); + // [Sl]ateBlue + else if (b == 'l' && (d == 'e' || (len > 5 && str[5] == 'b'))) return Color3(106, 90, 205); + // [Sl]ateGray + else if (b == 'l' && (d == 'y' || (len > 5 && str[5] == 'g'))) return Color3(112, 128, 144); + // [Sn]ow + else if (b == 'n') return Color3(255, 250, 250); + // [Sp]ringGreen + else if (b == 'p') return Color3(0, 255, 127); + // [St]eelBlue + else if (b == 't') return Color3(70, 130, 180); + // Default to blank + else return Color3::NIL; + // [T]an + // [T]eal + // [T]histle + // [T]omato + // [T]urquoise + case 't': + switch(b) + { + // [Ta]n + case 'a': return Color3(210, 180, 140); + // [Te]al + case 'e': return Color3(0, 128, 128); + // [Th]istle + case 'h': return Color3(216, 191, 216); + // [To]mato + case 'o': return Color3(255, 99, 71); + // [Tu]rquoise + case 'u': return Color3(64, 224, 208); + // Default to blank + default: return Color3::NIL; + } + // [V]iolet + case 'v': return Color3(238, 130, 238); + // [W]heat + // [W]hite + // [W]hiteSmoke + case 'w': + // [Wh]eat + if (b == 'h' && c == 'e') return Color3(245, 222, 179); + // [Wh]ite[S]moke + else if (b == 'h' && (len > 5 && str[5] == 's')) return Color3(245, 245, 245); + // [Whi]te + else if (b == 'h' && c == 'i') return Color3(255, 255, 255); + // Default to blank + else return Color3::NIL; + // [Y]ellow + // [Y]ellowGreen + case 'y': + // [Ye]llow[G]reen + if (b == 'e' && (len > 6 && str[6] == 'g')) return Color3(154, 205, 50); + // [Yel]low + else if (b == 'e' && c == 'l') return Color3(255, 255, 0); + // Default to blank + else return Color3::NIL; + // Default to blank + default: return Color3::NIL; + } +} + +// ------------------------------------------------------------------------------------------------ +AABB GetAABB(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %f , %f , %f , %f , %f , %f "); + static AABB box; + + box.Clear(); + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return box; + } + else if (delim != AABB::Delim) + { + fs[4] = delim; + fs[9] = delim; + fs[14] = delim; + fs[19] = delim; + fs[24] = delim; + } + else + { + fs[4] = AABB::Delim; + fs[9] = AABB::Delim; + fs[14] = AABB::Delim; + fs[19] = AABB::Delim; + fs[24] = AABB::Delim; + } + + std::sscanf(str, &fs[0], &box.min.x, &box.min.y, &box.min.z, &box.max.x, &box.max.y, &box.max.z); + + return box; +} + +// ------------------------------------------------------------------------------------------------ +Circle GetCircle(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %f , %f , %f "); + static Circle circle; + + circle.Clear(); + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return circle; + } + else if (delim != Circle::Delim) + { + fs[4] = delim; + fs[9] = delim; + } + else + { + fs[4] = Circle::Delim; + fs[9] = Circle::Delim; + } + + std::sscanf(str, &fs[0], &circle.pos.x, &circle.pos.y, &circle.rad); + + return circle; +} + +// ------------------------------------------------------------------------------------------------ +Color3 GetColor3(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %u , %u , %u "); + SQUint32 r = 0, g = 0, b = 0; + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return Color3(); + } + else if (delim != Color3::Delim) + { + fs[4] = delim; + fs[9] = delim; + } + else + { + fs[4] = Color3::Delim; + fs[9] = Color3::Delim; + } + + std::sscanf(str, &fs[0], &r, &g, &b); + + return Color3(static_cast(r), static_cast(g), static_cast(b)); +} + +Color4 GetColor4(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %u , %u , %u , %u "); + SQUint32 r = 0, g = 0, b = 0, a = 0; + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return Color4(); + } + else if (delim != Color4::Delim) + { + fs[4] = delim; + fs[9] = delim; + fs[14] = delim; + } + else + { + fs[4] = Color4::Delim; + fs[9] = Color4::Delim; + fs[14] = Color4::Delim; + } + + std::sscanf(str, &fs[0], &r, &g, &b, &a); + + return Color4(static_cast(r), static_cast(g), static_cast(b), static_cast(a)); +} + +// ------------------------------------------------------------------------------------------------ +Quaternion GetQuaternion(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %f , %f , %f , %f "); + static Quaternion quat; + + quat.Clear(); + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return quat; + } + else if (delim != Quaternion::Delim) + { + fs[4] = delim; + fs[9] = delim; + fs[14] = delim; + } + else + { + fs[4] = Quaternion::Delim; + fs[9] = Quaternion::Delim; + fs[14] = Quaternion::Delim; + } + + std::sscanf(str, &fs[0], &quat.x, &quat.y, &quat.z, &quat.w); + + return quat; +} + +Sphere GetSphere(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %f , %f , %f , %f "); + static Sphere sphere; + + sphere.Clear(); + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return sphere; + } + else if (delim != Sphere::Delim) + { + fs[4] = delim; + fs[9] = delim; + fs[14] = delim; + } + else + { + fs[4] = Sphere::Delim; + fs[9] = Sphere::Delim; + fs[14] = Sphere::Delim; + } + + std::sscanf(str, &fs[0], &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad); + + return sphere; +} + +// ------------------------------------------------------------------------------------------------ +Vector2f GetVector2f(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %f , %f "); + static Vector2f vec; + + vec.Clear(); + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return vec; + } + else if (delim != Vector2f::Delim) + { + fs[4] = delim; + } + else + { + fs[4] = Vector2f::Delim; + } + + std::sscanf(str, &fs[0], &vec.x, &vec.y); + + return vec; +} + +Vector2i GetVector2i(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %d , %d "); + static Vector2i vec; + + vec.Clear(); + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return vec; + } + else if (delim != Vector2i::Delim) + { + fs[4] = delim; + } + else + { + fs[4] = Vector2i::Delim; + } + + std::sscanf(str, &fs[0], &vec.x, &vec.y); + + return vec; +} + +Vector2u GetVector2u(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %u , %u "); + static Vector2u vec; + + vec.Clear(); + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return vec; + } + else if (delim != Vector2u::Delim) + { + fs[4] = delim; + } + else + { + fs[4] = Vector2u::Delim; + } + + std::sscanf(str, &fs[0], &vec.x, &vec.y); + + return vec; +} + +// ------------------------------------------------------------------------------------------------ +Vector3 GetVector3(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %f , %f , %f "); + static Vector3 vec; + + vec.Clear(); + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return vec; + } + else if (delim != Vector3::Delim) + { + fs[4] = delim; + fs[9] = delim; + } + else + { + fs[4] = Vector3::Delim; + fs[9] = Vector3::Delim; + } + + std::sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z); + + return vec; +} + +Vector4 GetVector4(const SQChar * str, SQChar delim) noexcept +{ + static SQChar fs[] = _SC(" %f , %f , %f , %f "); + static Vector4 vec; + + vec.Clear(); + + if (std::strlen(str) <= 0) + { + LogErr("Cannot extract values from an empty string"); + return vec; + } + else if (delim != Vector4::Delim) + { + fs[4] = delim; + fs[9] = delim; + fs[14] = delim; + } + else + { + fs[4] = Vector4::Delim; + fs[9] = Vector4::Delim; + fs[14] = Vector4::Delim; + } + + std::sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w); + + return vec; +} + +// ------------------------------------------------------------------------------------------------ +template < typename T > T StrToInt(const SQChar * str) noexcept +{ + try + { + return SToI< T >::Fn(str, nullptr, 10); + } + catch (const std::invalid_argument & ia) + { + LogErr("Unable to convert string to integer: %s", ia.what()); + } + catch (const std::out_of_range & oor) + { + LogErr("Unable to convert string to integer: %s", oor.what()); + } + return static_cast< T >(0); +} + +// ------------------------------------------------------------------------------------------------ +template < typename T > T StrToInt(const SQChar * str, SQInt32 base) noexcept +{ + try + { + return SToI< T >::Fn(str, nullptr, base); + } + catch (const std::invalid_argument & ia) + { + LogErr("Unable to convert string to integer: %s", ia.what()); + } + catch (const std::out_of_range & oor) + { + LogErr("Unable to convert string to integer: %s", oor.what()); + } + return static_cast< T >(0); +} + +// ------------------------------------------------------------------------------------------------ +template < typename T > T StrToReal(const SQChar * str) noexcept +{ + try + { + return SToF< T >::Fn(str, nullptr); + } + catch (const std::invalid_argument & ia) + { + LogErr("Unable to convert string to float: %s", ia.what()); + } + catch (const std::out_of_range & oor) + { + LogErr("Unable to convert string to float: %s", oor.what()); + } + return static_cast< T >(0.0); +} + +// ------------------------------------------------------------------------------------------------ +template < typename T > T RandomValue() noexcept +{ + return RandomVal< T >::Get(); +} + +template < typename T > T RandomValue(T min, T max) noexcept +{ + return RandomVal< T >::Get(min, max); +} + +// ------------------------------------------------------------------------------------------------ +bool Register_Base(HSQUIRRELVM vm) +{ + // Typedef squirrel string to simplify code + typedef const SQChar * SQS; + // Output debugging information + LogDbg("Beginning registration of API"); + // Attempt to register the specified API + Sqrat::RootTable(vm) + + .Func(_SC("EpsEqI"), &EpsEq) + .Func(_SC("EpsEqF"), &EpsEq) + + .Func(_SC("ClampI"), &Clamp) + .Func(_SC("ClampF"), &Clamp) + + .Func(_SC("IsSpace"), &isspace) + .Func(_SC("IsPrint"), &isprint) + .Func(_SC("IsCntrl"), &iscntrl) + .Func(_SC("IsUpper"), &isupper) + .Func(_SC("IsLower"), &islower) + .Func(_SC("IsAlpha"), &isalpha) + .Func(_SC("IsDigit"), &isdigit) + .Func(_SC("IsPunct"), &ispunct) + .Func(_SC("IsXdigit"), &isxdigit) + .Func(_SC("IsAlnum"), &isalnum) + .Func(_SC("IsGraph"), &isgraph) + .Func(_SC("IsBlank"), &isblank) + + .Overload< SQInteger (*)(void) >(_SC("GetRandomInt"), &RandomValue< SQInteger >) + .Overload< SQInteger (*)(SQInteger, SQInteger) >(_SC("GetRandomInt"), &RandomValue< SQInteger >) + + .Overload< SQFloat (*)(void) >(_SC("GetRandomFloat"), &RandomVal< SQFloat >::Get) + .Overload< SQFloat (*)(SQFloat, SQFloat) >(_SC("GetRandomFloat"), &RandomVal< SQFloat >::Get) + + .Overload< String (*)(String::size_type) >(_SC("GetRandomString"), &GetRandomString) + .Overload< String (*)(String::size_type, String::value_type, String::value_type) >(_SC("GetRandomString"), &GetRandomString) + + .Func(_SC("GetRandomBool"), &GetRandomBool) + .Func(_SC("GetRandomColor"), &GetRandomColor) + + .Overload< SQInteger (*)(const SQChar *) >(_SC("SToI"), &StrToInt) + .Overload< SQInteger (*)(const SQChar *, SQInt32) >(_SC("SToI"), &StrToInt) + + .Func(_SC("SToF"), &StrToReal) + .Func(_SC("SToB"), &SToB) + + .Func(_SC("GetColor"), &GetColor) + .Func(_SC("GetCircle"), &GetCircle) + .Func(_SC("GetAABB"), &GetAABB) + .Func(_SC("GetColor3"), &GetColor3) + .Func(_SC("GetColor4"), &GetColor4) + .Func(_SC("GetQuaternion"), &GetQuaternion) + .Func(_SC("GetSphere"), &GetSphere) + .Func(_SC("GetVector2f"), &GetVector2f) + .Func(_SC("GetVector2i"), &GetVector2i) + .Func(_SC("GetVector2u"), &GetVector2u) + .Func(_SC("GetVector3"), &GetVector3) + .Func(_SC("GetVector4"), &GetVector4) + + .Bind(_SC("Fmt"), Sqrat::Table(vm) + .Overload< SQS (*)(SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS, SQS) >(_SC("Ins"), \ + &InsStr) + .Overload< SQS (*)(SQS, SQChar, SQUint32) >(_SC("Left"), \ + &LeftStr) + .Overload< SQS (*)(SQS, SQChar, SQUint32, SQUint32) >(_SC("Left"), \ + &LeftStr) + .Overload< SQS (*)(SQS, SQChar, SQUint32) >(_SC("Right"), \ + &RightStr) + .Overload< SQS (*)(SQS, SQChar, SQUint32, SQUint32) >(_SC("Right"), \ + &RightStr) + .Func(_SC("Center"), &CenterStr) + ) + + /* END REGISTRATION STATEMENT */ ; + + // Output debugging information + LogDbg("Registration of API was successful"); + // Registration succeeded + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Shared.hpp b/source/Base/Shared.hpp new file mode 100644 index 00000000..0fdcff2f --- /dev/null +++ b/source/Base/Shared.hpp @@ -0,0 +1,400 @@ +#ifndef _BASE_SHARED_HPP_ +#define _BASE_SHARED_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +#include +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +#ifdef PI + #undef PI +#endif + +// ------------------------------------------------------------------------------------------------ +const Float32 PI = 3.14159265359f; +const Float32 RECIPROCAL_PI = 1.0f/PI; +const Float32 HALF_PI = PI/2.0f; + +// ------------------------------------------------------------------------------------------------ +#ifdef PI64 + #undef PI64 +#endif + +// ------------------------------------------------------------------------------------------------ +const Float64 PI64 = 3.1415926535897932384626433832795028841971693993751; +const Float64 RECIPROCAL_PI64 = 1.0/PI64; + +// ------------------------------------------------------------------------------------------------ +const Float32 DEGTORAD = PI / 180.0f; +const Float32 RADTODEG = 180.0f / PI; +const Float64 DEGTORAD64 = PI64 / 180.0; +const Float64 RADTODEG64 = 180.0 / PI64; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template< typename T > inline bool EpsEq(const T a, const T b) noexcept +{ + return abs(a - b) <= std::numeric_limits::epsilon(); +} + +template <> inline bool EpsEq(const Float32 a, const Float32 b) noexcept +{ + return fabs(a - b) <= 0.000001f; +} + +template <> inline bool EpsEq(const Float64 a, const Float64 b) noexcept +{ + return fabs(a - b) <= 0.000000001d; +} + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template< typename T > inline T Clamp(T val, T min, T max) noexcept +{ + return val < min ? min : (val > max ? max : val); +} + +template<> inline Float32 Clamp(const Float32 val, const Float32 min, const Float32 max) noexcept +{ + return std::isless(val, min) ? min : (std::isgreater(val, max) ? max : val); +} + +template<> inline Float64 Clamp(const Float64 val, const Float64 min, const Float64 max) noexcept +{ + return std::isless(val, min) ? min : (std::isgreater(val, max) ? max : val); +} + +/* ------------------------------------------------------------------------------------------------ + * Simple functions to quickly forward logging messages without including the logging system +*/ +void LogDbg(const char * fmt, ...) noexcept; +void LogMsg(const char * fmt, ...) noexcept; +void LogScs(const char * fmt, ...) noexcept; +void LogInf(const char * fmt, ...) noexcept; +void LogWrn(const char * fmt, ...) noexcept; +void LogErr(const char * fmt, ...) noexcept; +void LogFtl(const char * fmt, ...) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +const SQChar * ToStringF(const char * fmt, ...) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +void InitMTRG64() noexcept; +void InitMTRG64() noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Int8 GetRandomInt8() noexcept; +Int8 GetRandomInt8(Int8 min, Int8 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Uint8 GetRandomUint8() noexcept; +Uint8 GetRandomUint8(Uint8 min, Uint8 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Int16 GetRandomInt16() noexcept; +Int16 GetRandomInt16(Int16 min, Int16 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Uint16 GetRandomUint16() noexcept; +Uint16 GetRandomUint16(Uint16 min, Uint16 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Int32 GetRandomInt32() noexcept; +Int32 GetRandomInt32(Int32 min, Int32 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Uint32 GetRandomUint32() noexcept; +Uint32 GetRandomUint32(Uint32 min, Uint32 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Int64 GetRandomInt64() noexcept; +Int64 GetRandomInt64(Int64 min, Int64 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Uint64 GetRandomUint64() noexcept; +Uint64 GetRandomUint64(Uint64 min, Uint64 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Float32 GetRandomFloat32() noexcept; +Float32 GetRandomFloat32(Float32 min, Float32 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Float64 GetRandomFloat64() noexcept; +Float64 GetRandomFloat64(Float64 min, Float64 max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +String GetRandomString(String::size_type len) noexcept; +String GetRandomString(String::size_type len, String::value_type min, String::value_type max) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +bool GetRandomBool() noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template struct RandomVal +{ /* ... */ }; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> struct RandomVal +{ + static inline Int8 Get() noexcept { return GetRandomInt8(); } + static inline Int8 Get(Int8 min, Int8 max) noexcept { return GetRandomInt8(min, max); } +}; + +template <> struct RandomVal +{ + static inline Uint8 Get() noexcept { return GetRandomUint8(); } + static inline Uint8 Get(Uint8 min, Uint8 max) noexcept { return GetRandomUint8(min, max); } +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> struct RandomVal +{ + static inline Int16 Get() noexcept { return GetRandomInt16(); } + static inline Int16 Get(Int16 min, Int16 max) noexcept { return GetRandomInt16(min, max); } +}; + +template <> struct RandomVal +{ + static inline Uint16 Get() noexcept { return GetRandomUint16(); } + static inline Uint16 Get(Uint16 min, Uint16 max) noexcept { return GetRandomUint16(min, max); } +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> struct RandomVal +{ + static inline Int32 Get() noexcept { return GetRandomInt32(); } + static inline Int32 Get(Int32 min, Int32 max) noexcept { return GetRandomInt32(min, max); } +}; + +template <> struct RandomVal +{ + static inline Uint32 Get() noexcept { return GetRandomUint32(); } + static inline Uint32 Get(Uint32 min, Uint32 max) noexcept { return GetRandomUint32(min, max); } +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> struct RandomVal +{ + static inline Int64 Get() noexcept { return GetRandomInt64(); } + static inline Int64 Get(Int64 min, Int64 max) noexcept { return GetRandomInt64(min, max); } +}; + +template <> struct RandomVal +{ + static inline Uint64 Get() noexcept { return GetRandomUint64(); } + static inline Uint64 Get(Uint64 min, Uint64 max) noexcept { return GetRandomUint64(min, max); } +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> struct RandomVal +{ + static inline Float32 Get() noexcept { return GetRandomFloat32(); } + static inline Float32 Get(Float32 min, Float32 max) noexcept { return GetRandomFloat32(min, max); } +}; + +template <> struct RandomVal +{ + static inline Float64 Get() noexcept { return GetRandomFloat64(); } + static inline Float64 Get(Float64 min, Float64 max) noexcept { return GetRandomFloat64(min, max); } +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> struct RandomVal +{ + static inline String Get(String::size_type len) noexcept { return GetRandomString(len); } + static inline String Get(String::size_type len, String::value_type min, String::value_type max) noexcept + { return GetRandomString(len, min, max); } +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> struct RandomVal +{ + static inline bool Get() noexcept { return GetRandomBool(); } +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +const Color3 & GetRandomColor() noexcept; + +/* ------------------------------------------------------------------------------------------------ + * Simple function to check whether the specified string can be considered as a boolean value +*/ +bool SToB(const SQChar * str) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * Utility used to unify the string converstion functions under one name. +*/ +template < typename T > struct SToI { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); }; +template < typename T > struct SToF { static constexpr auto Fn = static_cast< float(*)(const String &, std::size_t*) >(std::stof); }; + +// ------------------------------------------------------------------------------------------------ +template <> struct SToI < char > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); }; +template <> struct SToI < signed char > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); }; +template <> struct SToI < unsigned char > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); }; +template <> struct SToI < short > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); }; +template <> struct SToI < unsigned short > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); }; +template <> struct SToI < int > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); }; +template <> struct SToI < unsigned int > { static constexpr auto Fn = static_cast< unsigned long(*)(const String &, std::size_t*, int) >(std::stoul); }; +template <> struct SToI < long > { static constexpr auto Fn = static_cast< long(*)(const String &, std::size_t*, int) >(std::stol); }; +template <> struct SToI < unsigned long > { static constexpr auto Fn = static_cast< unsigned long(*)(const String &, std::size_t*, int) >(std::stoul); }; +template <> struct SToI < long long > { static constexpr auto Fn = static_cast< long long(*)(const String &, std::size_t*, int b) >(std::stoll); }; +template <> struct SToI < unsigned long long > { static constexpr auto Fn = static_cast< unsigned long long(*)(const String &, std::size_t*, int) >(std::stoull); }; +template <> struct SToF < float > { static constexpr auto Fn = static_cast< float(*)(const String &, std::size_t*) >(std::stof); }; +template <> struct SToF < double > { static constexpr auto Fn = static_cast< double(*)(const String &, std::size_t*) >(std::stod); }; +template <> struct SToF < long double > { static constexpr auto Fn = static_cast< long double(*)(const String &, std::size_t*) >(std::stold); }; + +// ------------------------------------------------------------------------------------------------ +template < typename T > inline String NToS(T n) noexcept { return std::to_string(n); } +template < typename T > inline const SQChar * NToCS(T n) noexcept { return std::to_string(n).c_str(); } + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Color3 GetColor(const SQChar * name) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Circle GetCircle(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +AABB GetAABB(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Color3 GetColor3(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Color4 GetColor4(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Quaternion GetQuaternion(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Sphere GetSphere(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Vector2f GetVector2f(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Vector2i GetVector2i(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Vector2u GetVector2u(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Vector3 GetVector3(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +Vector4 GetVector4(const SQChar * str, SQChar delim) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * Fake deleter meant for classes that should not be deleted by smart pointers +*/ +template struct FakeDeleter +{ + void operator () (T * /* ptr */) const noexcept { /* Ignored... */ } +}; + +/* ------------------------------------------------------------------------------------------------ + * Utility used to generate a string with an arbitrary text surrounded by a specific character +*/ +const SQChar * LeftStr(const SQChar * t, SQChar f, SQUint32 w = 72) noexcept; +const SQChar * LeftStr(const SQChar * t, SQChar f, SQUint32 w = 72, SQUint32 o = 0) noexcept; +const SQChar * RightStr(const SQChar * t, SQChar f, SQUint32 w = 72) noexcept; +const SQChar * RightStr(const SQChar * t, SQChar f, SQUint32 w = 72, SQUint32 o = 0) noexcept; +const SQChar * CenterStr(const SQChar * t, SQChar f, SQUint32 w = 72) noexcept; + +/* ------------------------------------------------------------------------------------------------ + * Function used insert arbitrary text at certain positions within a string +*/ +const SQChar * InsertStr(const SQChar * f, const std::vector< const SQChar * > & a) noexcept; + +// Utility for the function +const SQChar * InsStr(const SQChar * f) noexcept; + +template < typename... Args > const SQChar * InsStr(const SQChar * f, Args... args) noexcept +{ + return InsertStr(f, {{args...}}); +} + +} // Namespace:: SqMod + +#endif // _BASE_SHARED_HPP_ diff --git a/source/Base/Sphere.cpp b/source/Base/Sphere.cpp new file mode 100644 index 00000000..c35c530c --- /dev/null +++ b/source/Base/Sphere.cpp @@ -0,0 +1,542 @@ +#include "Base/Sphere.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Sphere Sphere::NIL = Sphere(); +const Sphere Sphere::MIN = Sphere(0.0); +const Sphere Sphere::MAX = Sphere(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Sphere::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Sphere::Sphere() noexcept + : pos(0.0, 0.0, 0.0), rad(0.0) +{ + +} + +Sphere::Sphere(Value r) noexcept + : pos(0.0, 0.0, 0.0), rad(r) +{ + +} + +Sphere::Sphere(const Vector3 & p) noexcept + : pos(p), rad(0.0) +{ + +} + +Sphere::Sphere(const Vector3 & p, Value r) noexcept + : pos(p), rad(r) +{ + +} + +Sphere::Sphere(Value x, Value y, Value z, Value r) noexcept + : pos(x, y, z), rad(r) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Sphere::Sphere(const Sphere & s) noexcept + : pos(s.pos), rad(s.rad) +{ + +} + +Sphere::Sphere(Sphere && s) noexcept + : pos(s.pos), rad(s.rad) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Sphere::~Sphere() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Sphere & Sphere::operator = (const Sphere & s) noexcept +{ + pos = s.pos; + rad = s.rad; + return *this; +} + +Sphere & Sphere::operator = (Sphere && s) noexcept +{ + pos = s.pos; + rad = s.rad; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Sphere & Sphere::operator = (Value r) noexcept +{ + rad = r; + return *this; +} + +Sphere & Sphere::operator = (const Vector3 & p) noexcept +{ + pos = p; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Sphere & Sphere::operator += (const Sphere & s) noexcept +{ + pos += s.pos; + rad += s.rad; + return *this; +} + +Sphere & Sphere::operator -= (const Sphere & s) noexcept +{ + pos -= s.pos; + rad -= s.rad; + return *this; +} + +Sphere & Sphere::operator *= (const Sphere & s) noexcept +{ + pos *= s.pos; + rad *= s.rad; + return *this; +} + +Sphere & Sphere::operator /= (const Sphere & s) noexcept +{ + pos /= s.pos; + rad /= s.rad; + return *this; +} + +Sphere & Sphere::operator %= (const Sphere & s) noexcept +{ + pos %= s.pos; + rad = std::fmod(rad, s.rad); + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Sphere & Sphere::operator += (Value r) noexcept +{ + rad += r; + return *this; +} + +Sphere & Sphere::operator -= (Value r) noexcept +{ + rad -= r; + return *this; +} + +Sphere & Sphere::operator *= (Value r) noexcept +{ + rad *= r; + return *this; +} + +Sphere & Sphere::operator /= (Value r) noexcept +{ + rad /= r; + return *this; +} + +Sphere & Sphere::operator %= (Value r) noexcept +{ + rad = std::fmod(rad, r); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Sphere & Sphere::operator += (const Vector3 & p) noexcept +{ + pos += p; + return *this; +} + +Sphere & Sphere::operator -= (const Vector3 & p) noexcept +{ + pos -= p; + return *this; +} + +Sphere & Sphere::operator *= (const Vector3 & p) noexcept +{ + pos *= p; + return *this; +} + +Sphere & Sphere::operator /= (const Vector3 & p) noexcept +{ + pos /= p; + return *this; +} + +Sphere & Sphere::operator %= (const Vector3 & p) noexcept +{ + pos %= p; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Sphere & Sphere::operator ++ () noexcept +{ + ++pos; + ++rad; + return *this; +} + +Sphere & Sphere::operator -- () noexcept +{ + --pos; + --rad; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Sphere Sphere::operator ++ (int) noexcept +{ + Sphere state(*this); + ++pos; + ++rad; + return state; +} + +Sphere Sphere::operator -- (int) noexcept +{ + Sphere state(*this); + --pos; + --rad; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Sphere Sphere::operator + (const Sphere & s) const noexcept +{ + return Sphere(pos + s.pos, rad + s.rad); +} + +Sphere Sphere::operator - (const Sphere & s) const noexcept +{ + return Sphere(pos - s.pos, rad - s.rad); +} + +Sphere Sphere::operator * (const Sphere & s) const noexcept +{ + return Sphere(pos * s.pos, rad * s.rad); +} + +Sphere Sphere::operator / (const Sphere & s) const noexcept +{ + return Sphere(pos / s.pos, rad / s.rad); +} + +Sphere Sphere::operator % (const Sphere & s) const noexcept +{ + return Sphere(pos % s.pos, std::fmod(rad, s.rad)); +} + +// ------------------------------------------------------------------------------------------------ +Sphere Sphere::operator + (Value r) const noexcept +{ + return Sphere(rad + r); +} + +Sphere Sphere::operator - (Value r) const noexcept +{ + return Sphere(rad - r); +} + +Sphere Sphere::operator * (Value r) const noexcept +{ + return Sphere(rad * r); +} + +Sphere Sphere::operator / (Value r) const noexcept +{ + return Sphere(rad / r); +} + +Sphere Sphere::operator % (Value r) const noexcept +{ + return Sphere(std::fmod(rad, r)); +} + +// ------------------------------------------------------------------------------------------------ +Sphere Sphere::operator + (const Vector3 & p) const noexcept +{ + return Sphere(pos + p); +} + +Sphere Sphere::operator - (const Vector3 & p) const noexcept +{ + return Sphere(pos - p); +} + +Sphere Sphere::operator * (const Vector3 & p) const noexcept +{ + return Sphere(pos * p); +} + +Sphere Sphere::operator / (const Vector3 & p) const noexcept +{ + return Sphere(pos / p); +} + +Sphere Sphere::operator % (const Vector3 & p) const noexcept +{ + return Sphere(pos % p); +} + +// ------------------------------------------------------------------------------------------------ +Sphere Sphere::operator + () const noexcept +{ + return Sphere(pos.Abs(), std::fabs(rad)); +} + +Sphere Sphere::operator - () const noexcept +{ + return Sphere(-pos, -rad); +} + +// ------------------------------------------------------------------------------------------------ +bool Sphere::operator == (const Sphere & s) const noexcept +{ + return (rad == s.rad) && (pos == s.pos); +} + +bool Sphere::operator != (const Sphere & s) const noexcept +{ + return (rad != s.rad) && (pos != s.pos); +} + +bool Sphere::operator < (const Sphere & s) const noexcept +{ + return (rad < s.rad) && (pos < s.pos); +} + +bool Sphere::operator > (const Sphere & s) const noexcept +{ + return (rad > s.rad) && (pos > s.pos); +} + +bool Sphere::operator <= (const Sphere & s) const noexcept +{ + return (rad <= s.rad) && (pos <= s.pos); +} + +bool Sphere::operator >= (const Sphere & s) const noexcept +{ + return (rad >= s.rad) && (pos >= s.pos); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Sphere::Cmp(const Sphere & s) const noexcept +{ + return *this == s ? 0 : (*this > s ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Sphere::ToString() const noexcept +{ + return ToStringF("%f,%f,%f,%f", pos.x, pos.y, pos.z, rad); +} + +// ------------------------------------------------------------------------------------------------ +void Sphere::Set(Value nr) noexcept +{ + rad = nr; +} + +void Sphere::Set(const Sphere & ns) noexcept +{ + pos = ns.pos; + rad = ns.rad; +} + +void Sphere::Set(const Vector3 & np) noexcept +{ + pos = np; +} + +void Sphere::Set(const Vector3 & np, Value nr) noexcept +{ + pos = np; + rad = nr; +} + +// ------------------------------------------------------------------------------------------------ +void Sphere::Set(Value nx, Value ny, Value nz) noexcept +{ + pos.Set(nx, ny, nz); +} + +void Sphere::Set(Value nx, Value ny, Value nz, Value nr) noexcept +{ + pos.Set(nx, ny, nz); + rad = nr; +} + +// ------------------------------------------------------------------------------------------------ +void Sphere::Set(const SQChar * values, SQChar delim) noexcept +{ + Set(GetSphere(values, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Sphere::Generate() noexcept +{ + pos.Generate(); + rad = RandomVal::Get(); +} + +void Sphere::Generate(Value min, Value max, bool r) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else if (r) + { + rad = RandomVal::Get(min, max); + } + else + { + pos.Generate(min, max); + } +} + +void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax) noexcept +{ + pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax); +} + +void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value rmin, Value rmax) noexcept +{ + if (std::isless(rmax, rmin)) + { + LogErr("max value is lower than min value"); + } + else + { + pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax); + rad = RandomVal::Get(rmin, rmax); + } +} + +// ------------------------------------------------------------------------------------------------ +Sphere Sphere::Abs() const noexcept +{ + return Sphere(pos.Abs(), std::fabs(rad)); +} + +// ------------------------------------------------------------------------------------------------ +bool Register_Sphere(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Sphere::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Sphere"), Sqrat::Class(vm, _SC("Sphere")) + .Ctor() + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Sphere::Delim) + + .Var(_SC("pos"), &Sphere::pos) + .Var(_SC("rad"), &Sphere::rad) + + .Prop(_SC("abs"), &Sphere::Abs) + + .Func(_SC("_tostring"), &Sphere::ToString) + .Func(_SC("_cmp"), &Sphere::Cmp) + + .Func(_SC("_add"), &Sphere::operator +) + .Func(_SC("_sub"), &Sphere::operator -) + .Func(_SC("_mul"), &Sphere::operator *) + .Func(_SC("_div"), &Sphere::operator /) + .Func(_SC("_modulo"), &Sphere::operator %) + .Func(_SC("_unm"), &Sphere::operator -) + + .Overload(_SC("set"), &Sphere::Set) + .Overload(_SC("set"), &Sphere::Set) + .Overload(_SC("set"), &Sphere::Set) + .Overload(_SC("set_rad"), &Sphere::Set) + .Overload(_SC("set_vec3"), &Sphere::Set) + .Overload(_SC("set_vec3"), &Sphere::Set) + .Overload(_SC("set_str"), &Sphere::Set) + + .Func(_SC("clear"), &Sphere::Clear) + + .Func(_SC("opAddAssign"), &Sphere::operator +=) + .Func(_SC("opSubAssign"), &Sphere::operator -=) + .Func(_SC("opMulAssign"), &Sphere::operator *=) + .Func(_SC("opDivAssign"), &Sphere::operator /=) + .Func(_SC("opModAssign"), &Sphere::operator %=) + + .Func(_SC("opAddAssignR"), &Sphere::operator +=) + .Func(_SC("opSubAssignR"), &Sphere::operator -=) + .Func(_SC("opMulAssignR"), &Sphere::operator *=) + .Func(_SC("opDivAssignR"), &Sphere::operator /=) + .Func(_SC("opModAssignR"), &Sphere::operator %=) + + .Func(_SC("opAddAssignP"), &Sphere::operator +=) + .Func(_SC("opSubAssignP"), &Sphere::operator -=) + .Func(_SC("opMulAssignP"), &Sphere::operator *=) + .Func(_SC("opDivAssignP"), &Sphere::operator /=) + .Func(_SC("opModAssignP"), &Sphere::operator %=) + + .Func(_SC("opPreInc"), &Sphere::operator ++) + .Func(_SC("opPreDec"), &Sphere::operator --) + .Func(_SC("opPostInc"), &Sphere::operator ++) + .Func(_SC("opPostDec"), &Sphere::operator --) + + .Func(_SC("opAdd"), &Sphere::operator +) + .Func(_SC("opSub"), &Sphere::operator -) + .Func(_SC("opMul"), &Sphere::operator *) + .Func(_SC("opDiv"), &Sphere::operator /) + .Func(_SC("opMod"), &Sphere::operator %) + + .Func(_SC("opAddR"), &Sphere::operator +) + .Func(_SC("opSubR"), &Sphere::operator -) + .Func(_SC("opMulR"), &Sphere::operator *) + .Func(_SC("opDivR"), &Sphere::operator /) + .Func(_SC("opModR"), &Sphere::operator %) + + .Func(_SC("opAddP"), &Sphere::operator +) + .Func(_SC("opSubP"), &Sphere::operator -) + .Func(_SC("opMulP"), &Sphere::operator *) + .Func(_SC("opDivP"), &Sphere::operator /) + .Func(_SC("opModP"), &Sphere::operator %) + + .Func(_SC("opUnPlus"), &Sphere::operator +) + .Func(_SC("opUnMinus"), &Sphere::operator -) + + .Func(_SC("opEqual"), &Sphere::operator ==) + .Func(_SC("opNotEqual"), &Sphere::operator !=) + .Func(_SC("opLessThan"), &Sphere::operator <) + .Func(_SC("opGreaterThan"), &Sphere::operator >) + .Func(_SC("opLessEqual"), &Sphere::operator <=) + .Func(_SC("opGreaterEqual"), &Sphere::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Sphere.hpp b/source/Base/Sphere.hpp new file mode 100644 index 00000000..87b73053 --- /dev/null +++ b/source/Base/Sphere.hpp @@ -0,0 +1,123 @@ +#ifndef _BASE_SPHERE_HPP_ +#define _BASE_SPHERE_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" +#include "Base/Vector3.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Sphere +{ + // -------------------------------------------------------------------------------------------- + typedef SQFloat Value; + // -------------------------------------------------------------------------------------------- + static const Sphere NIL; + static const Sphere MIN; + static const Sphere MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Vector3 pos; + Value rad; + // -------------------------------------------------------------------------------------------- + Sphere() noexcept; + Sphere(Value r) noexcept; + Sphere(const Vector3 & p) noexcept; + Sphere(const Vector3 & p, Value r) noexcept; + Sphere(Value x, Value y, Value z, Value r) noexcept; + // -------------------------------------------------------------------------------------------- + Sphere(const Sphere & s) noexcept; + Sphere(Sphere && s) noexcept; + // -------------------------------------------------------------------------------------------- + ~Sphere(); + // -------------------------------------------------------------------------------------------- + Sphere & operator = (const Sphere & s) noexcept; + Sphere & operator = (Sphere && s) noexcept; + // -------------------------------------------------------------------------------------------- + Sphere & operator = (Value r) noexcept; + Sphere & operator = (const Vector3 & p) noexcept; + // -------------------------------------------------------------------------------------------- + Sphere & operator += (const Sphere & s) noexcept; + Sphere & operator -= (const Sphere & s) noexcept; + Sphere & operator *= (const Sphere & s) noexcept; + Sphere & operator /= (const Sphere & s) noexcept; + Sphere & operator %= (const Sphere & s) noexcept; + // -------------------------------------------------------------------------------------------- + Sphere & operator += (Value r) noexcept; + Sphere & operator -= (Value r) noexcept; + Sphere & operator *= (Value r) noexcept; + Sphere & operator /= (Value r) noexcept; + Sphere & operator %= (Value r) noexcept; + // -------------------------------------------------------------------------------------------- + Sphere & operator += (const Vector3 & p) noexcept; + Sphere & operator -= (const Vector3 & p) noexcept; + Sphere & operator *= (const Vector3 & p) noexcept; + Sphere & operator /= (const Vector3 & p) noexcept; + Sphere & operator %= (const Vector3 & p) noexcept; + // -------------------------------------------------------------------------------------------- + Sphere & operator ++ () noexcept; + Sphere & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Sphere operator ++ (int) noexcept; + Sphere operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Sphere operator + (const Sphere & s) const noexcept; + Sphere operator - (const Sphere & s) const noexcept; + Sphere operator * (const Sphere & s) const noexcept; + Sphere operator / (const Sphere & s) const noexcept; + Sphere operator % (const Sphere & s) const noexcept; + // -------------------------------------------------------------------------------------------- + Sphere operator + (Value r) const noexcept; + Sphere operator - (Value r) const noexcept; + Sphere operator * (Value r) const noexcept; + Sphere operator / (Value r) const noexcept; + Sphere operator % (Value r) const noexcept; + // -------------------------------------------------------------------------------------------- + Sphere operator + (const Vector3 & p) const noexcept; + Sphere operator - (const Vector3 & p) const noexcept; + Sphere operator * (const Vector3 & p) const noexcept; + Sphere operator / (const Vector3 & p) const noexcept; + Sphere operator % (const Vector3 & p) const noexcept; + // -------------------------------------------------------------------------------------------- + Sphere operator + () const noexcept; + Sphere operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Sphere & s) const noexcept; + bool operator != (const Sphere & s) const noexcept; + bool operator < (const Sphere & s) const noexcept; + bool operator > (const Sphere & s) const noexcept; + bool operator <= (const Sphere & s) const noexcept; + bool operator >= (const Sphere & s) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Sphere & s) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value nr) noexcept; + void Set(const Sphere & ns) noexcept; + void Set(const Vector3 & np) noexcept; + void Set(const Vector3 & np, Value nr) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value nx, Value ny, Value nz) noexcept; + void Set(Value nx, Value ny, Value nz, Value nr) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max, bool r) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value rmin, Value rmax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { pos.Clear(); rad = 0.0; } + // -------------------------------------------------------------------------------------------- + Sphere Abs() const noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_SPHERE_HPP_ diff --git a/source/Base/Vector2f.cpp b/source/Base/Vector2f.cpp new file mode 100644 index 00000000..74dbf043 --- /dev/null +++ b/source/Base/Vector2f.cpp @@ -0,0 +1,493 @@ +#include "Base/Vector2f.hpp" +#include "Base/Vector2i.hpp" +#include "Base/Vector2u.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Vector2f Vector2f::NIL = Vector2f(0); +const Vector2f Vector2f::MIN = Vector2f(std::numeric_limits::min()); +const Vector2f Vector2f::MAX = Vector2f(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Vector2f::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Vector2f::Vector2f() noexcept + : x(0.0), y(0.0) +{ + +} + +Vector2f::Vector2f(Value s) noexcept + : x(s), y(s) +{ + +} + +Vector2f::Vector2f(Value xv, Value yv) noexcept + : x(xv), y(yv) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2f::Vector2f(const Vector2i & v) noexcept + : x(static_cast(v.x)), y(static_cast(v.y)) +{ + +} + +Vector2f::Vector2f(const Vector2u & v) noexcept + : x(static_cast(v.x)), y(static_cast(v.y)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2f::Vector2f(const SQChar * values, SQChar delim) noexcept + : Vector2f(GetVector2f(values, delim)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2f::Vector2f(const Vector2f & v) noexcept + : x(v.x), y(v.y) +{ + +} + +Vector2f::Vector2f(Vector2f && v) noexcept + : x(v.x), y(v.y) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2f::~Vector2f() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2f & Vector2f::operator = (const Vector2f & v) noexcept +{ + x = v.x; + y = v.y; + return *this; +} + +Vector2f & Vector2f::operator = (Vector2f && v) noexcept +{ + x = v.x; + y = v.y; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2f & Vector2f::operator = (Value s) noexcept +{ + x = s; + y = s; + return *this; +} + +Vector2f & Vector2f::operator = (const SQChar * values) noexcept +{ + Set(GetVector2f(values, Delim)); + return *this; +} + +Vector2f & Vector2f::operator = (const Vector2i & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); + return *this; +} + +Vector2f & Vector2f::operator = (const Vector2u & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2f & Vector2f::operator += (const Vector2f & v) noexcept +{ + x += v.x; + y += v.y; + return *this; +} + +Vector2f & Vector2f::operator -= (const Vector2f & v) noexcept +{ + x -= v.x; + y -= v.y; + return *this; +} + +Vector2f & Vector2f::operator *= (const Vector2f & v) noexcept +{ + x *= v.x; + y *= v.y; + return *this; +} + +Vector2f & Vector2f::operator /= (const Vector2f & v) noexcept +{ + x /= v.x; + y /= v.y; + return *this; +} + +Vector2f & Vector2f::operator %= (const Vector2f & v) noexcept +{ + x = std::fmod(x, v.x); + y = std::fmod(y, v.y); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2f & Vector2f::operator += (Value s) noexcept +{ + x += s; + y += s; + return *this; +} + +Vector2f & Vector2f::operator -= (Value s) noexcept +{ + x -= s; + y -= s; + return *this; +} + +Vector2f & Vector2f::operator *= (Value s) noexcept +{ + x *= s; + y *= s; + return *this; +} + +Vector2f & Vector2f::operator /= (Value s) noexcept +{ + x /= s; + y /= s; + return *this; +} + +Vector2f & Vector2f::operator %= (Value s) noexcept +{ + x = std::fmod(x, s); + y = std::fmod(y, s); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2f & Vector2f::operator ++ () noexcept +{ + ++x; + ++y; + return *this; +} + +Vector2f & Vector2f::operator -- () noexcept +{ + --x; + --y; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2f Vector2f::operator ++ (int) noexcept +{ + Vector2f state(*this); + ++x; + ++y; + return state; +} + +Vector2f Vector2f::operator -- (int) noexcept +{ + Vector2f state(*this); + --x; + --y; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Vector2f Vector2f::operator + (const Vector2f & v) const noexcept +{ + return Vector2f(x + v.x, y + v.y); +} + +Vector2f Vector2f::operator - (const Vector2f & v) const noexcept +{ + return Vector2f(x - v.x, y - v.y); +} + +Vector2f Vector2f::operator * (const Vector2f & v) const noexcept +{ + return Vector2f(x * v.x, y * v.y); +} + +Vector2f Vector2f::operator / (const Vector2f & v) const noexcept +{ + return Vector2f(x / v.x, y / v.y); +} + +Vector2f Vector2f::operator % (const Vector2f & v) const noexcept +{ + return Vector2f(std::fmod(x, v.x), std::fmod(y, v.y)); +} + +// ------------------------------------------------------------------------------------------------ +Vector2f Vector2f::operator + (Value s) const noexcept +{ + return Vector2f(x + s, y + s); +} + +Vector2f Vector2f::operator - (Value s) const noexcept +{ + return Vector2f(x - s, y - s); +} + +Vector2f Vector2f::operator * (Value s) const noexcept +{ + return Vector2f(x * s, y * s); +} + +Vector2f Vector2f::operator / (Value s) const noexcept +{ + return Vector2f(x / s, y / s); +} + +Vector2f Vector2f::operator % (Value s) const noexcept +{ + return Vector2f(std::fmod(x, s), std::fmod(y, s)); +} + +// ------------------------------------------------------------------------------------------------ +Vector2f Vector2f::operator + () const noexcept +{ + return Vector2f(std::fabs(x), std::fabs(y)); +} + +Vector2f Vector2f::operator - () const noexcept +{ + return Vector2f(-x, -y); +} + +// ------------------------------------------------------------------------------------------------ +bool Vector2f::operator == (const Vector2f & v) const noexcept +{ + return EpsEq(x, v.x) && EpsEq(y, v.y); +} + +bool Vector2f::operator != (const Vector2f & v) const noexcept +{ + return !EpsEq(x, v.x) && !EpsEq(y, v.y); +} + +bool Vector2f::operator < (const Vector2f & v) const noexcept +{ + return std::isless(x, v.x) && std::isless(y, v.y); +} + +bool Vector2f::operator > (const Vector2f & v) const noexcept +{ + return std::isgreater(x, v.x) && std::isgreater(y, v.y); +} + +bool Vector2f::operator <= (const Vector2f & v) const noexcept +{ + return std::islessequal(x, v.x) && std::islessequal(y, v.y); +} + +bool Vector2f::operator >= (const Vector2f & v) const noexcept +{ + return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Vector2f::Cmp(const Vector2f & v) const noexcept +{ + return *this == v ? 0 : (*this > v ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Vector2f::ToString() const noexcept +{ + return ToStringF("%f,%f", x, y); +} + +// ------------------------------------------------------------------------------------------------ +void Vector2f::Set(Value ns) noexcept +{ + x = ns; + y = ns; +} + +void Vector2f::Set(Value nx, Value ny) noexcept +{ + x = nx; + y = ny; +} + +// ------------------------------------------------------------------------------------------------ +void Vector2f::Set(const Vector2f & v) noexcept +{ + x = v.x; + y = v.y; +} + +void Vector2f::Set(const Vector2i & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); +} + +void Vector2f::Set(const Vector2u & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); +} + +// ------------------------------------------------------------------------------------------------ +void Vector2f::Set(const SQChar * values, SQChar delim) noexcept +{ + Set(GetVector2f(values, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Vector2f::Generate() noexcept +{ + x = RandomVal::Get(); + y = RandomVal::Get(); +} + +void Vector2f::Generate(Value min, Value max) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(min, max); + y = RandomVal::Get(min, max); + } +} + +void Vector2f::Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept +{ + if (xmax < xmin || ymax < ymin) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(ymin, ymax); + y = RandomVal::Get(xmin, xmax); + } +} + +// ------------------------------------------------------------------------------------------------ +Vector2f Vector2f::Abs() const noexcept +{ + return Vector2f(std::fabs(x), std::fabs(y)); +} + +// ================================================================================================ +bool Register_Vector2f(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Vector2f::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Vector2f"), Sqrat::Class(vm, _SC("Vector2f")) + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Vector2f::Delim) + + .Var(_SC("x"), &Vector2f::x) + .Var(_SC("y"), &Vector2f::y) + + .Prop(_SC("abs"), &Vector2f::Abs) + + .Func(_SC("_tostring"), &Vector2f::ToString) + .Func(_SC("_cmp"), &Vector2f::Cmp) + + .Func(_SC("_add"), &Vector2f::operator +) + .Func(_SC("_sub"), &Vector2f::operator -) + .Func(_SC("_mul"), &Vector2f::operator *) + .Func(_SC("_div"), &Vector2f::operator /) + .Func(_SC("_modulo"), &Vector2f::operator %) + .Func(_SC("_unm"), &Vector2f::operator -) + + .Overload(_SC("set"), &Vector2f::Set) + .Overload(_SC("set"), &Vector2f::Set) + .Overload(_SC("set_vec2f"), &Vector2f::Set) + .Overload(_SC("set_vec2i"), &Vector2f::Set) + .Overload(_SC("set_vec2u"), &Vector2f::Set) + .Overload(_SC("set_str"), &Vector2f::Set) + + .Overload(_SC("generate"), &Vector2f::Generate) + .Overload(_SC("generate"), &Vector2f::Generate) + .Overload(_SC("generate"), &Vector2f::Generate) + + .Func(_SC("clear"), &Vector2f::Clear) + + .Func(_SC("opAddAssign"), &Vector2f::operator +=) + .Func(_SC("opSubAssign"), &Vector2f::operator -=) + .Func(_SC("opMulAssign"), &Vector2f::operator *=) + .Func(_SC("opDivAssign"), &Vector2f::operator /=) + .Func(_SC("opModAssign"), &Vector2f::operator %=) + + .Func(_SC("opAddAssignS"), &Vector2f::operator +=) + .Func(_SC("opSubAssignS"), &Vector2f::operator -=) + .Func(_SC("opMulAssignS"), &Vector2f::operator *=) + .Func(_SC("opDivAssignS"), &Vector2f::operator /=) + .Func(_SC("opModAssignS"), &Vector2f::operator %=) + + .Func(_SC("opPreInc"), &Vector2f::operator ++) + .Func(_SC("opPreDec"), &Vector2f::operator --) + .Func(_SC("opPostInc"), &Vector2f::operator ++) + .Func(_SC("opPostDec"), &Vector2f::operator --) + + .Func(_SC("opAdd"), &Vector2f::operator +) + .Func(_SC("opSub"), &Vector2f::operator -) + .Func(_SC("opMul"), &Vector2f::operator *) + .Func(_SC("opDiv"), &Vector2f::operator /) + .Func(_SC("opMod"), &Vector2f::operator %) + + .Func(_SC("opAddS"), &Vector2f::operator +) + .Func(_SC("opSubS"), &Vector2f::operator -) + .Func(_SC("opMulS"), &Vector2f::operator *) + .Func(_SC("opDivS"), &Vector2f::operator /) + .Func(_SC("opModS"), &Vector2f::operator %) + + .Func(_SC("opUnPlus"), &Vector2f::operator +) + .Func(_SC("opUnMinus"), &Vector2f::operator -) + + .Func(_SC("opEqual"), &Vector2f::operator ==) + .Func(_SC("opNotEqual"), &Vector2f::operator !=) + .Func(_SC("opLessThan"), &Vector2f::operator <) + .Func(_SC("opGreaterThan"), &Vector2f::operator >) + .Func(_SC("opLessEqual"), &Vector2f::operator <=) + .Func(_SC("opGreaterEqual"), &Vector2f::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Vector2f.hpp b/source/Base/Vector2f.hpp new file mode 100644 index 00000000..b200242a --- /dev/null +++ b/source/Base/Vector2f.hpp @@ -0,0 +1,112 @@ +#ifndef _BASE_VECTOR2F_HPP_ +#define _BASE_VECTOR2F_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Vector2f +{ + // -------------------------------------------------------------------------------------------- + typedef SQFloat Value; + // -------------------------------------------------------------------------------------------- + static const Vector2f NIL; + static const Vector2f MIN; + static const Vector2f MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Value x, y; + // -------------------------------------------------------------------------------------------- + Vector2f() noexcept; + Vector2f(Value s) noexcept; + Vector2f(Value xv, Value yv) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f(const Vector2i & v) noexcept; + Vector2f(const Vector2u & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f(const Vector2f & v) noexcept; + Vector2f(Vector2f && v) noexcept; + // -------------------------------------------------------------------------------------------- + ~Vector2f(); + // -------------------------------------------------------------------------------------------- + Vector2f & operator = (const Vector2f & v) noexcept; + Vector2f & operator = (Vector2f && v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f & operator = (Value s) noexcept; + Vector2f & operator = (const SQChar * values) noexcept; + Vector2f & operator = (const Vector2i & v) noexcept; + Vector2f & operator = (const Vector2u & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f & operator += (const Vector2f & v) noexcept; + Vector2f & operator -= (const Vector2f & v) noexcept; + Vector2f & operator *= (const Vector2f & v) noexcept; + Vector2f & operator /= (const Vector2f & v) noexcept; + Vector2f & operator %= (const Vector2f & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f & operator += (Value s) noexcept; + Vector2f & operator -= (Value s) noexcept; + Vector2f & operator *= (Value s) noexcept; + Vector2f & operator /= (Value s) noexcept; + Vector2f & operator %= (Value s) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f & operator ++ () noexcept; + Vector2f & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f operator ++ (int) noexcept; + Vector2f operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f operator + (const Vector2f & v) const noexcept; + Vector2f operator - (const Vector2f & v) const noexcept; + Vector2f operator * (const Vector2f & v) const noexcept; + Vector2f operator / (const Vector2f & v) const noexcept; + Vector2f operator % (const Vector2f & v) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f operator + (Value s) const noexcept; + Vector2f operator - (Value s) const noexcept; + Vector2f operator * (Value s) const noexcept; + Vector2f operator / (Value s) const noexcept; + Vector2f operator % (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2f operator + () const noexcept; + Vector2f operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Vector2f & v) const noexcept; + bool operator != (const Vector2f & v) const noexcept; + bool operator < (const Vector2f & v) const noexcept; + bool operator > (const Vector2f & v) const noexcept; + bool operator <= (const Vector2f & v) const noexcept; + bool operator >= (const Vector2f & v) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Vector2f & v) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value ns) noexcept; + void Set(Value nx, Value ny) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Vector2f & v) noexcept; + void Set(const Vector2i & v) noexcept; + void Set(const Vector2u & v) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { x = 0.0, y = 0.0; } + // -------------------------------------------------------------------------------------------- + Vector2f Abs() const noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_VECTOR2F_HPP_ diff --git a/source/Base/Vector2i.cpp b/source/Base/Vector2i.cpp new file mode 100644 index 00000000..f4697984 --- /dev/null +++ b/source/Base/Vector2i.cpp @@ -0,0 +1,640 @@ +#include "Base/Vector2i.hpp" +#include "Base/Vector2u.hpp" +#include "Base/Vector2f.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Vector2i Vector2i::NIL = Vector2i(0); +const Vector2i Vector2i::MIN = Vector2i(std::numeric_limits::min()); +const Vector2i Vector2i::MAX = Vector2i(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Vector2i::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Vector2i::Vector2i() noexcept + : x(0), y(0) +{ + +} + +Vector2i::Vector2i(Value s) noexcept + : x(s), y(s) +{ + +} + +Vector2i::Vector2i(Value xv, Value yv) noexcept + : x(xv), y(yv) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2i::Vector2i(const Vector2u & v) noexcept + : x(static_cast(v.x)), y(static_cast(v.y)) +{ + +} + +Vector2i::Vector2i(const Vector2f & v) noexcept + : x(static_cast(v.x)), y(static_cast(v.y)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2i::Vector2i(const SQChar * values, SQChar delim) noexcept + : Vector2i(GetVector2i(values, delim)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2i::Vector2i(const Vector2i & v) noexcept + : x(v.x), y(v.y) +{ + +} + +Vector2i::Vector2i(Vector2i && v) noexcept + : x(v.x), y(v.y) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2i::~Vector2i() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2i & Vector2i::operator = (const Vector2i & v) noexcept +{ + x = v.x; + y = v.y; + return *this; +} + +Vector2i & Vector2i::operator = (Vector2i && v) noexcept +{ + x = v.x; + y = v.y; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2i & Vector2i::operator = (Value s) noexcept +{ + x = s; + y = s; + return *this; +} + +Vector2i & Vector2i::operator = (const SQChar * values) noexcept +{ + Set(GetVector2i(values, Delim)); + return *this; +} + +Vector2i & Vector2i::operator = (const Vector2u & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); + return *this; +} + +Vector2i & Vector2i::operator = (const Vector2f & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2i & Vector2i::operator += (const Vector2i & v) noexcept +{ + x += v.x; + y += v.y; + return *this; +} + +Vector2i & Vector2i::operator -= (const Vector2i & v) noexcept +{ + x -= v.x; + y -= v.y; + return *this; +} + +Vector2i & Vector2i::operator *= (const Vector2i & v) noexcept +{ + x *= v.x; + y *= v.y; + return *this; +} + +Vector2i & Vector2i::operator /= (const Vector2i & v) noexcept +{ + x /= v.x; + y /= v.y; + return *this; +} + +Vector2i & Vector2i::operator %= (const Vector2i & v) noexcept +{ + x %= v.x; + y %= v.y; + return *this; +} + +Vector2i & Vector2i::operator &= (const Vector2i & v) noexcept +{ + x &= v.x; + y &= v.y; + return *this; +} + +Vector2i & Vector2i::operator |= (const Vector2i & v) noexcept +{ + x |= v.x; + y |= v.y; + return *this; +} + +Vector2i & Vector2i::operator ^= (const Vector2i & v) noexcept +{ + x ^= v.x; + y ^= v.y; + return *this; +} + +Vector2i & Vector2i::operator <<= (const Vector2i & v) noexcept +{ + x <<= v.x; + y <<= v.y; + return *this; +} + +Vector2i & Vector2i::operator >>= (const Vector2i & v) noexcept +{ + x >>= v.x; + y >>= v.y; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2i & Vector2i::operator += (Value s) noexcept +{ + x += s; + y += s; + return *this; +} + +Vector2i & Vector2i::operator -= (Value s) noexcept +{ + x -= s; + y -= s; + return *this; +} + +Vector2i & Vector2i::operator *= (Value s) noexcept +{ + x *= s; + y *= s; + return *this; +} + +Vector2i & Vector2i::operator /= (Value s) noexcept +{ + x /= s; + y /= s; + return *this; +} + +Vector2i & Vector2i::operator %= (Value s) noexcept +{ + x %= s; + y %= s; + return *this; +} + +Vector2i & Vector2i::operator &= (Value s) noexcept +{ + x &= s; + y &= s; + return *this; +} + +Vector2i & Vector2i::operator |= (Value s) noexcept +{ + x |= s; + y |= s; + return *this; +} + +Vector2i & Vector2i::operator ^= (Value s) noexcept +{ + x += s; + y += s; + return *this; +} + +Vector2i & Vector2i::operator <<= (Value s) noexcept +{ + x <<= s; + y <<= s; + return *this; +} + +Vector2i & Vector2i::operator >>= (Value s) noexcept +{ + x >>= s; + y >>= s; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2i & Vector2i::operator ++ () noexcept +{ + ++x; + ++y; + return *this; +} + +Vector2i & Vector2i::operator -- () noexcept +{ + --x; + --y; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2i Vector2i::operator ++ (int) noexcept +{ + Vector2i state(*this); + ++x; + ++y; + return state; +} + +Vector2i Vector2i::operator -- (int) noexcept +{ + Vector2i state(*this); + --x; + --y; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Vector2i Vector2i::operator + (const Vector2i & v) const noexcept +{ + return Vector2i(x + v.x, y + v.y); +} + +Vector2i Vector2i::operator - (const Vector2i & v) const noexcept +{ + return Vector2i(x - v.x, y - v.y); +} + +Vector2i Vector2i::operator * (const Vector2i & v) const noexcept +{ + return Vector2i(x * v.x, y * v.y); +} + +Vector2i Vector2i::operator / (const Vector2i & v) const noexcept +{ + return Vector2i(x / v.x, y / v.y); +} + +Vector2i Vector2i::operator % (const Vector2i & v) const noexcept +{ + return Vector2i(x % v.x, y % v.y); +} + +Vector2i Vector2i::operator & (const Vector2i & v) const noexcept +{ + return Vector2i(x & v.x, y & v.y); +} + +Vector2i Vector2i::operator | (const Vector2i & v) const noexcept +{ + return Vector2i(x | v.x, y | v.y); +} + +Vector2i Vector2i::operator ^ (const Vector2i & v) const noexcept +{ + return Vector2i(x ^ v.x, y ^ v.y); +} + +Vector2i Vector2i::operator << (const Vector2i & v) const noexcept +{ + return Vector2i(x << v.x, y << v.y); +} + +Vector2i Vector2i::operator >> (const Vector2i & v) const noexcept +{ + return Vector2i(x >> v.x, y >> v.y); +} + +// ------------------------------------------------------------------------------------------------ +Vector2i Vector2i::operator + (Value s) const noexcept +{ + return Vector2i(x + s, y + s); +} + +Vector2i Vector2i::operator - (Value s) const noexcept +{ + return Vector2i(x - s, y - s); +} + +Vector2i Vector2i::operator * (Value s) const noexcept +{ + return Vector2i(x * s, y * s); +} + +Vector2i Vector2i::operator / (Value s) const noexcept +{ + return Vector2i(x / s, y / s); +} + +Vector2i Vector2i::operator % (Value s) const noexcept +{ + return Vector2i(x % s, y % s); +} + +Vector2i Vector2i::operator & (Value s) const noexcept +{ + return Vector2i(x & s, y & s); +} + +Vector2i Vector2i::operator | (Value s) const noexcept +{ + return Vector2i(x | s, y | s); +} + +Vector2i Vector2i::operator ^ (Value s) const noexcept +{ + return Vector2i(x ^ s, y ^ s); +} + +Vector2i Vector2i::operator << (Value s) const noexcept +{ + return Vector2i(x < s, y < s); +} + +Vector2i Vector2i::operator >> (Value s) const noexcept +{ + return Vector2i(x >> s, y >> s); +} + +// ------------------------------------------------------------------------------------------------ +Vector2i Vector2i::operator + () const noexcept +{ + return Vector2i(std::abs(x), std::abs(y)); +} + +Vector2i Vector2i::operator - () const noexcept +{ + return Vector2i(-x, -y); +} + +// ------------------------------------------------------------------------------------------------ +Vector2i Vector2i::operator ~ () const noexcept +{ + return Vector2i(~x, ~y); +} + +// ------------------------------------------------------------------------------------------------ +bool Vector2i::operator == (const Vector2i & v) const noexcept +{ + return (x == v.x) && (y == v.y); +} + +bool Vector2i::operator != (const Vector2i & v) const noexcept +{ + return (x != v.x) && (y != v.y); +} + +bool Vector2i::operator < (const Vector2i & v) const noexcept +{ + return (x < v.x) && (y < v.y); +} + +bool Vector2i::operator > (const Vector2i & v) const noexcept +{ + return (x > v.x) && (y > v.y); +} + +bool Vector2i::operator <= (const Vector2i & v) const noexcept +{ + return (x <= v.x) && (y <= v.y); +} + +bool Vector2i::operator >= (const Vector2i & v) const noexcept +{ + return (x >= v.x) && (y >= v.y); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Vector2i::Cmp(const Vector2i & v) const noexcept +{ + return *this == v ? 0 : (*this > v ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Vector2i::ToString() const noexcept +{ + return ToStringF("%d,%d", x, y); +} + +// ------------------------------------------------------------------------------------------------ +void Vector2i::Set(Value ns) noexcept +{ + x = ns; + y = ns; +} + +void Vector2i::Set(Value nx, Value ny) noexcept +{ + x = nx; + y = ny; +} + +// ------------------------------------------------------------------------------------------------ +void Vector2i::Set(const Vector2i & v) noexcept +{ + x = v.x; + y = v.y; +} + +void Vector2i::Set(const Vector2u & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); +} + +void Vector2i::Set(const Vector2f & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); +} + +// ------------------------------------------------------------------------------------------------ +void Vector2i::Set(const SQChar * values, SQChar delim) noexcept +{ + Set(GetVector2i(values, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Vector2i::Generate() noexcept +{ + x = RandomVal::Get(); + y = RandomVal::Get(); +} + +void Vector2i::Generate(Value min, Value max) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(min, max); + y = RandomVal::Get(min, max); + } +} + +void Vector2i::Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept +{ + if (xmax < xmin || ymax < ymin) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(ymin, ymax); + y = RandomVal::Get(xmin, xmax); + } +} + +// ------------------------------------------------------------------------------------------------ +Vector2i Vector2i::Abs() const noexcept +{ + return Vector2i(std::abs(x), std::abs(y)); +} + +// ================================================================================================ +bool Register_Vector2i(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Vector2i::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Vector2i"), Sqrat::Class(vm, _SC("Vector2i")) + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Vector2i::Delim) + + .Var(_SC("x"), &Vector2i::x) + .Var(_SC("y"), &Vector2i::y) + + .Prop(_SC("abs"), &Vector2i::Abs) + + .Func(_SC("_tostring"), &Vector2i::ToString) + .Func(_SC("_cmp"), &Vector2i::Cmp) + + .Func(_SC("_add"), &Vector2i::operator +) + .Func(_SC("_sub"), &Vector2i::operator -) + .Func(_SC("_mul"), &Vector2i::operator *) + .Func(_SC("_div"), &Vector2i::operator /) + .Func(_SC("_modulo"), &Vector2i::operator %) + .Func(_SC("_unm"), &Vector2i::operator -) + + .Overload(_SC("set"), &Vector2i::Set) + .Overload(_SC("set"), &Vector2i::Set) + .Overload(_SC("set_vec2i"), &Vector2i::Set) + .Overload(_SC("set_vec2u"), &Vector2i::Set) + .Overload(_SC("set_vec2f"), &Vector2i::Set) + .Overload(_SC("set_str"), &Vector2i::Set) + + .Overload(_SC("generate"), &Vector2i::Generate) + .Overload(_SC("generate"), &Vector2i::Generate) + .Overload(_SC("generate"), &Vector2i::Generate) + + .Func(_SC("clear"), &Vector2i::Clear) + + .Func(_SC("opAddAssign"), &Vector2i::operator +=) + .Func(_SC("opSubAssign"), &Vector2i::operator -=) + .Func(_SC("opMulAssign"), &Vector2i::operator *=) + .Func(_SC("opDivAssign"), &Vector2i::operator /=) + .Func(_SC("opModAssign"), &Vector2i::operator %=) + .Func(_SC("opAndAssign"), &Vector2i::operator &=) + .Func(_SC("opOrAssign"), &Vector2i::operator |=) + .Func(_SC("opXorAssign"), &Vector2i::operator ^=) + .Func(_SC("opShlAssign"), &Vector2i::operator <<=) + .Func(_SC("opShrAssign"), &Vector2i::operator >>=) + + .Func(_SC("opAddAssignS"), &Vector2i::operator +=) + .Func(_SC("opSubAssignS"), &Vector2i::operator -=) + .Func(_SC("opMulAssignS"), &Vector2i::operator *=) + .Func(_SC("opDivAssignS"), &Vector2i::operator /=) + .Func(_SC("opModAssignS"), &Vector2i::operator %=) + .Func(_SC("opAndAssignS"), &Vector2i::operator &=) + .Func(_SC("opOrAssignS"), &Vector2i::operator |=) + .Func(_SC("opXorAssignS"), &Vector2i::operator ^=) + .Func(_SC("opShlAssignS"), &Vector2i::operator <<=) + .Func(_SC("opShrAssignS"), &Vector2i::operator >>=) + + .Func(_SC("opPreInc"), &Vector2i::operator ++) + .Func(_SC("opPreDec"), &Vector2i::operator --) + .Func(_SC("opPostInc"), &Vector2i::operator ++) + .Func(_SC("opPostDec"), &Vector2i::operator --) + + .Func(_SC("opAdd"), &Vector2i::operator +) + .Func(_SC("opSub"), &Vector2i::operator -) + .Func(_SC("opMul"), &Vector2i::operator *) + .Func(_SC("opDiv"), &Vector2i::operator /) + .Func(_SC("opMod"), &Vector2i::operator %) + .Func(_SC("opAnd"), &Vector2i::operator &) + .Func(_SC("opOr"), &Vector2i::operator |) + .Func(_SC("opShl"), &Vector2i::operator ^) + .Func(_SC("opShl"), &Vector2i::operator <<) + .Func(_SC("opShr"), &Vector2i::operator >>) + + .Func(_SC("opAddS"), &Vector2i::operator +) + .Func(_SC("opSubS"), &Vector2i::operator -) + .Func(_SC("opMulS"), &Vector2i::operator *) + .Func(_SC("opDivS"), &Vector2i::operator /) + .Func(_SC("opModS"), &Vector2i::operator %) + .Func(_SC("opAndS"), &Vector2i::operator &) + .Func(_SC("opOrS"), &Vector2i::operator |) + .Func(_SC("opShlS"), &Vector2i::operator ^) + .Func(_SC("opShlS"), &Vector2i::operator <<) + .Func(_SC("opShrS"), &Vector2i::operator >>) + + .Func(_SC("opUnPlus"), &Vector2i::operator +) + .Func(_SC("opUnMinus"), &Vector2i::operator -) + .Func(_SC("opCom"), &Vector2i::operator ~) + + .Func(_SC("opEqual"), &Vector2i::operator ==) + .Func(_SC("opNotEqual"), &Vector2i::operator !=) + .Func(_SC("opLessThan"), &Vector2i::operator <) + .Func(_SC("opGreaterThan"), &Vector2i::operator >) + .Func(_SC("opLessEqual"), &Vector2i::operator <=) + .Func(_SC("opGreaterEqual"), &Vector2i::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Vector2i.hpp b/source/Base/Vector2i.hpp new file mode 100644 index 00000000..258c3ccd --- /dev/null +++ b/source/Base/Vector2i.hpp @@ -0,0 +1,134 @@ +#ifndef _BASE_VECTOR2I_HPP_ +#define _BASE_VECTOR2I_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Vector2i +{ + // -------------------------------------------------------------------------------------------- + typedef SQInt32 Value; + // -------------------------------------------------------------------------------------------- + static const Vector2i NIL; + static const Vector2i MIN; + static const Vector2i MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Value x, y; + // -------------------------------------------------------------------------------------------- + Vector2i() noexcept; + Vector2i(Value s) noexcept; + Vector2i(Value xv, Value yv) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i(const Vector2u & v) noexcept; + Vector2i(const Vector2f & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i(const Vector2i & v) noexcept; + Vector2i(Vector2i && v) noexcept; + // -------------------------------------------------------------------------------------------- + ~Vector2i(); + // -------------------------------------------------------------------------------------------- + Vector2i & operator = (const Vector2i & v) noexcept; + Vector2i & operator = (Vector2i && v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i & operator = (Value s) noexcept; + Vector2i & operator = (const SQChar * values) noexcept; + Vector2i & operator = (const Vector2u & v) noexcept; + Vector2i & operator = (const Vector2f & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i & operator += (const Vector2i & v) noexcept; + Vector2i & operator -= (const Vector2i & v) noexcept; + Vector2i & operator *= (const Vector2i & v) noexcept; + Vector2i & operator /= (const Vector2i & v) noexcept; + Vector2i & operator %= (const Vector2i & v) noexcept; + Vector2i & operator &= (const Vector2i & v) noexcept; + Vector2i & operator |= (const Vector2i & v) noexcept; + Vector2i & operator ^= (const Vector2i & v) noexcept; + Vector2i & operator <<= (const Vector2i & v) noexcept; + Vector2i & operator >>= (const Vector2i & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i & operator += (Value s) noexcept; + Vector2i & operator -= (Value s) noexcept; + Vector2i & operator *= (Value s) noexcept; + Vector2i & operator /= (Value s) noexcept; + Vector2i & operator %= (Value s) noexcept; + Vector2i & operator &= (Value s) noexcept; + Vector2i & operator |= (Value s) noexcept; + Vector2i & operator ^= (Value s) noexcept; + Vector2i & operator <<= (Value s) noexcept; + Vector2i & operator >>= (Value s) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i & operator ++ () noexcept; + Vector2i & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i operator ++ (int) noexcept; + Vector2i operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i operator + (const Vector2i & v) const noexcept; + Vector2i operator - (const Vector2i & v) const noexcept; + Vector2i operator * (const Vector2i & v) const noexcept; + Vector2i operator / (const Vector2i & v) const noexcept; + Vector2i operator % (const Vector2i & v) const noexcept; + Vector2i operator & (const Vector2i & v) const noexcept; + Vector2i operator | (const Vector2i & v) const noexcept; + Vector2i operator ^ (const Vector2i & v) const noexcept; + Vector2i operator << (const Vector2i & v) const noexcept; + Vector2i operator >> (const Vector2i & v) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i operator + (Value s) const noexcept; + Vector2i operator - (Value s) const noexcept; + Vector2i operator * (Value s) const noexcept; + Vector2i operator / (Value s) const noexcept; + Vector2i operator % (Value s) const noexcept; + Vector2i operator & (Value s) const noexcept; + Vector2i operator | (Value s) const noexcept; + Vector2i operator ^ (Value s) const noexcept; + Vector2i operator << (Value s) const noexcept; + Vector2i operator >> (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i operator + () const noexcept; + Vector2i operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2i operator ~ () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Vector2i & v) const noexcept; + bool operator != (const Vector2i & v) const noexcept; + bool operator < (const Vector2i & v) const noexcept; + bool operator > (const Vector2i & v) const noexcept; + bool operator <= (const Vector2i & v) const noexcept; + bool operator >= (const Vector2i & v) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Vector2i & v) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value ns) noexcept; + void Set(Value nx, Value ny) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Vector2i & v) noexcept; + void Set(const Vector2u & v) noexcept; + void Set(const Vector2f & v) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { x = 0, y = 0; } + // -------------------------------------------------------------------------------------------- + Vector2i Abs() const noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_VECTOR2I_HPP_ diff --git a/source/Base/Vector2u.cpp b/source/Base/Vector2u.cpp new file mode 100644 index 00000000..158a479a --- /dev/null +++ b/source/Base/Vector2u.cpp @@ -0,0 +1,640 @@ +#include "Base/Vector2u.hpp" +#include "Base/Vector2f.hpp" +#include "Base/Vector2i.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Vector2u Vector2u::NIL = Vector2u(0); +const Vector2u Vector2u::MIN = Vector2u(std::numeric_limits::min()); +const Vector2u Vector2u::MAX = Vector2u(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Vector2u::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Vector2u::Vector2u() noexcept + : x(0), y(0) +{ + +} + +Vector2u::Vector2u(Value s) noexcept + : x(s), y(s) +{ + +} + +Vector2u::Vector2u(Value xv, Value yv) noexcept + : x(xv), y(yv) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2u::Vector2u(const Vector2i & v) noexcept + : x(static_cast(v.x)), y(static_cast(v.y)) +{ + +} + +Vector2u::Vector2u(const Vector2f & v) noexcept + : x(static_cast(v.x)), y(static_cast(v.y)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2u::Vector2u(const SQChar * values, SQChar delim) noexcept + : Vector2u(GetVector2u(values, delim)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2u::Vector2u(const Vector2u & v) noexcept + : x(v.x), y(v.y) +{ + +} + +Vector2u::Vector2u(Vector2u && v) noexcept + : x(v.x), y(v.y) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2u::~Vector2u() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector2u & Vector2u::operator = (const Vector2u & v) noexcept +{ + x = v.x; + y = v.y; + return *this; +} + +Vector2u & Vector2u::operator = (Vector2u && v) noexcept +{ + x = v.x; + y = v.y; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2u & Vector2u::operator = (Value s) noexcept +{ + x = s; + y = s; + return *this; +} + +Vector2u & Vector2u::operator = (const SQChar * values) noexcept +{ + Set(GetVector2i(values, Delim)); + return *this; +} + +Vector2u & Vector2u::operator = (const Vector2i & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); + return *this; +} + +Vector2u & Vector2u::operator = (const Vector2f & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2u & Vector2u::operator += (const Vector2u & v) noexcept +{ + x += v.x; + y += v.y; + return *this; +} + +Vector2u & Vector2u::operator -= (const Vector2u & v) noexcept +{ + x -= v.x; + y -= v.y; + return *this; +} + +Vector2u & Vector2u::operator *= (const Vector2u & v) noexcept +{ + x *= v.x; + y *= v.y; + return *this; +} + +Vector2u & Vector2u::operator /= (const Vector2u & v) noexcept +{ + x /= v.x; + y /= v.y; + return *this; +} + +Vector2u & Vector2u::operator %= (const Vector2u & v) noexcept +{ + x %= v.x; + y %= v.y; + return *this; +} + +Vector2u & Vector2u::operator &= (const Vector2u & v) noexcept +{ + x &= v.x; + y &= v.y; + return *this; +} + +Vector2u & Vector2u::operator |= (const Vector2u & v) noexcept +{ + x |= v.x; + y |= v.y; + return *this; +} + +Vector2u & Vector2u::operator ^= (const Vector2u & v) noexcept +{ + x ^= v.x; + y ^= v.y; + return *this; +} + +Vector2u & Vector2u::operator <<= (const Vector2u & v) noexcept +{ + x <<= v.x; + y <<= v.y; + return *this; +} + +Vector2u & Vector2u::operator >>= (const Vector2u & v) noexcept +{ + x >>= v.x; + y >>= v.y; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2u & Vector2u::operator += (Value s) noexcept +{ + x += s; + y += s; + return *this; +} + +Vector2u & Vector2u::operator -= (Value s) noexcept +{ + x -= s; + y -= s; + return *this; +} + +Vector2u & Vector2u::operator *= (Value s) noexcept +{ + x *= s; + y *= s; + return *this; +} + +Vector2u & Vector2u::operator /= (Value s) noexcept +{ + x /= s; + y /= s; + return *this; +} + +Vector2u & Vector2u::operator %= (Value s) noexcept +{ + x %= s; + y %= s; + return *this; +} + +Vector2u & Vector2u::operator &= (Value s) noexcept +{ + x &= s; + y &= s; + return *this; +} + +Vector2u & Vector2u::operator |= (Value s) noexcept +{ + x |= s; + y |= s; + return *this; +} + +Vector2u & Vector2u::operator ^= (Value s) noexcept +{ + x ^= s; + y ^= s; + return *this; +} + +Vector2u & Vector2u::operator <<= (Value s) noexcept +{ + x <<= s; + y <<= s; + return *this; +} + +Vector2u & Vector2u::operator >>= (Value s) noexcept +{ + x >>= s; + y >>= s; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2u & Vector2u::operator ++ () noexcept +{ + ++x; + ++y; + return *this; +} + +Vector2u & Vector2u::operator -- () noexcept +{ + --x; + --y; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector2u Vector2u::operator ++ (int) noexcept +{ + Vector2i state(*this); + ++x; + ++y; + return state; +} + +Vector2u Vector2u::operator -- (int) noexcept +{ + Vector2i state(*this); + --x; + --y; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Vector2u Vector2u::operator + (const Vector2u & v) const noexcept +{ + return Vector2i(x + v.x, y + v.y); +} + +Vector2u Vector2u::operator - (const Vector2u & v) const noexcept +{ + return Vector2i(x - v.x, y - v.y); +} + +Vector2u Vector2u::operator * (const Vector2u & v) const noexcept +{ + return Vector2i(x * v.x, y * v.y); +} + +Vector2u Vector2u::operator / (const Vector2u & v) const noexcept +{ + return Vector2i(x / v.x, y / v.y); +} + +Vector2u Vector2u::operator % (const Vector2u & v) const noexcept +{ + return Vector2i(x % v.x, y % v.y); +} + +Vector2u Vector2u::operator & (const Vector2u & v) const noexcept +{ + return Vector2i(x & v.x, y & v.y); +} + +Vector2u Vector2u::operator | (const Vector2u & v) const noexcept +{ + return Vector2i(x | v.x, y | v.y); +} + +Vector2u Vector2u::operator ^ (const Vector2u & v) const noexcept +{ + return Vector2i(x ^ v.x, y ^ v.y); +} + +Vector2u Vector2u::operator << (const Vector2u & v) const noexcept +{ + return Vector2i(x << v.x, y << v.y); +} + +Vector2u Vector2u::operator >> (const Vector2u & v) const noexcept +{ + return Vector2i(x >> v.x, y >> v.y); +} + +// ------------------------------------------------------------------------------------------------ +Vector2u Vector2u::operator + (Value s) const noexcept +{ + return Vector2i(x + s, y + s); +} + +Vector2u Vector2u::operator - (Value s) const noexcept +{ + return Vector2i(x - s, y - s); +} + +Vector2u Vector2u::operator * (Value s) const noexcept +{ + return Vector2i(x - s, y - s); +} + +Vector2u Vector2u::operator / (Value s) const noexcept +{ + return Vector2i(x / s, y / s); +} + +Vector2u Vector2u::operator % (Value s) const noexcept +{ + return Vector2i(x % s, y % s); +} + +Vector2u Vector2u::operator & (Value s) const noexcept +{ + return Vector2i(x & s, y & s); +} + +Vector2u Vector2u::operator | (Value s) const noexcept +{ + return Vector2i(x | s, y | s); +} + +Vector2u Vector2u::operator ^ (Value s) const noexcept +{ + return Vector2i(x ^ s, y ^ s); +} + +Vector2u Vector2u::operator << (Value s) const noexcept +{ + return Vector2i(x << s, y << s); +} + +Vector2u Vector2u::operator >> (Value s) const noexcept +{ + return Vector2i(x >> s, y >> s); +} + +// ------------------------------------------------------------------------------------------------ +Vector2u Vector2u::operator + () const noexcept +{ + return Vector2i(x, y); +} + +Vector2u Vector2u::operator - () const noexcept +{ + return Vector2i(0, 0); +} + +// ------------------------------------------------------------------------------------------------ +Vector2u Vector2u::operator ~ () const noexcept +{ + return Vector2i(~x, ~y); +} + +// ------------------------------------------------------------------------------------------------ +bool Vector2u::operator == (const Vector2u & v) const noexcept +{ + return (x == v.x) && (y == v.y); +} + +bool Vector2u::operator != (const Vector2u & v) const noexcept +{ + return (x != v.x) && (y != v.y); +} + +bool Vector2u::operator < (const Vector2u & v) const noexcept +{ + return (x < v.x) && (y < v.y); +} + +bool Vector2u::operator > (const Vector2u & v) const noexcept +{ + return (x > v.x) && (y > v.y); +} + +bool Vector2u::operator <= (const Vector2u & v) const noexcept +{ + return (x <= v.x) && (y <= v.y); +} + +bool Vector2u::operator >= (const Vector2u & v) const noexcept +{ + return (x >= v.x) && (y >= v.y); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Vector2u::Cmp(const Vector2u & v) const noexcept +{ + return *this == v ? 0 : (*this > v ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Vector2u::ToString() const noexcept +{ + return ToStringF("%u,%u", x, y); +} + +// ------------------------------------------------------------------------------------------------ +void Vector2u::Set(Value ns) noexcept +{ + x = ns; + y = ns; +} + +void Vector2u::Set(Value nx, Value ny) noexcept +{ + x = nx; + y = ny; +} + +// ------------------------------------------------------------------------------------------------ +void Vector2u::Set(const Vector2u & v) noexcept +{ + x = v.x; + y = v.y; +} + +void Vector2u::Set(const Vector2i & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); +} + +void Vector2u::Set(const Vector2f & v) noexcept +{ + x = static_cast(v.x); + y = static_cast(v.y); +} + +// ------------------------------------------------------------------------------------------------ +void Vector2u::Set(const SQChar * values, SQChar delim) noexcept +{ + Set(GetVector2i(values, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Vector2u::Generate() noexcept +{ + x = RandomVal::Get(); + y = RandomVal::Get(); +} + +void Vector2u::Generate(Value min, Value max) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(min, max); + y = RandomVal::Get(min, max); + } +} + +void Vector2u::Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept +{ + if (xmax < xmin || ymax < ymin) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(ymin, ymax); + y = RandomVal::Get(xmin, xmax); + } +} + +// ------------------------------------------------------------------------------------------------ +Vector2u Vector2u::Abs() const noexcept +{ + return Vector2i(x, y); +} + +// ================================================================================================ +bool Register_Vector2u(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Vector2u::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Vector2u"), Sqrat::Class(vm, _SC("Vector2u")) + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Vector2u::Delim) + + .Var(_SC("x"), &Vector2u::x) + .Var(_SC("y"), &Vector2u::y) + + .Prop(_SC("abs"), &Vector2u::Abs) + + .Func(_SC("_tostring"), &Vector2u::ToString) + .Func(_SC("_cmp"), &Vector2u::Cmp) + + .Func(_SC("_add"), &Vector2u::operator +) + .Func(_SC("_sub"), &Vector2u::operator -) + .Func(_SC("_mul"), &Vector2u::operator *) + .Func(_SC("_div"), &Vector2u::operator /) + .Func(_SC("_modulo"), &Vector2u::operator %) + .Func(_SC("_unm"), &Vector2u::operator -) + + .Overload(_SC("set"), &Vector2u::Set) + .Overload(_SC("set"), &Vector2u::Set) + .Overload(_SC("set_vec2u"), &Vector2u::Set) + .Overload(_SC("set_vec2i"), &Vector2u::Set) + .Overload(_SC("set_vec2f"), &Vector2u::Set) + .Overload(_SC("set_str"), &Vector2u::Set) + + .Overload(_SC("generate"), &Vector2u::Generate) + .Overload(_SC("generate"), &Vector2u::Generate) + .Overload(_SC("generate"), &Vector2u::Generate) + + .Func(_SC("clear"), &Vector2u::Clear) + + .Func(_SC("opAddAssign"), &Vector2u::operator +=) + .Func(_SC("opSubAssign"), &Vector2u::operator -=) + .Func(_SC("opMulAssign"), &Vector2u::operator *=) + .Func(_SC("opDivAssign"), &Vector2u::operator /=) + .Func(_SC("opModAssign"), &Vector2u::operator %=) + .Func(_SC("opAndAssign"), &Vector2u::operator &=) + .Func(_SC("opOrAssign"), &Vector2u::operator |=) + .Func(_SC("opXorAssign"), &Vector2u::operator ^=) + .Func(_SC("opShlAssign"), &Vector2u::operator <<=) + .Func(_SC("opShrAssign"), &Vector2u::operator >>=) + + .Func(_SC("opAddAssignS"), &Vector2u::operator +=) + .Func(_SC("opSubAssignS"), &Vector2u::operator -=) + .Func(_SC("opMulAssignS"), &Vector2u::operator *=) + .Func(_SC("opDivAssignS"), &Vector2u::operator /=) + .Func(_SC("opModAssignS"), &Vector2u::operator %=) + .Func(_SC("opAndAssignS"), &Vector2u::operator &=) + .Func(_SC("opOrAssignS"), &Vector2u::operator |=) + .Func(_SC("opXorAssignS"), &Vector2u::operator ^=) + .Func(_SC("opShlAssignS"), &Vector2u::operator <<=) + .Func(_SC("opShrAssignS"), &Vector2u::operator >>=) + + .Func(_SC("opPreInc"), &Vector2u::operator ++) + .Func(_SC("opPreDec"), &Vector2u::operator --) + .Func(_SC("opPostInc"), &Vector2u::operator ++) + .Func(_SC("opPostDec"), &Vector2u::operator --) + + .Func(_SC("opAdd"), &Vector2u::operator +) + .Func(_SC("opSub"), &Vector2u::operator -) + .Func(_SC("opMul"), &Vector2u::operator *) + .Func(_SC("opDiv"), &Vector2u::operator /) + .Func(_SC("opMod"), &Vector2u::operator %) + .Func(_SC("opAnd"), &Vector2u::operator &) + .Func(_SC("opOr"), &Vector2u::operator |) + .Func(_SC("opShl"), &Vector2u::operator ^) + .Func(_SC("opShl"), &Vector2u::operator <<) + .Func(_SC("opShr"), &Vector2u::operator >>) + + .Func(_SC("opAddS"), &Vector2u::operator +) + .Func(_SC("opSubS"), &Vector2u::operator -) + .Func(_SC("opMulS"), &Vector2u::operator *) + .Func(_SC("opDivS"), &Vector2u::operator /) + .Func(_SC("opModS"), &Vector2u::operator %) + .Func(_SC("opAndS"), &Vector2u::operator &) + .Func(_SC("opOrS"), &Vector2u::operator |) + .Func(_SC("opShlS"), &Vector2u::operator ^) + .Func(_SC("opShlS"), &Vector2u::operator <<) + .Func(_SC("opShrS"), &Vector2u::operator >>) + + .Func(_SC("opUnPlus"), &Vector2u::operator +) + .Func(_SC("opUnMinus"), &Vector2u::operator -) + .Func(_SC("opCom"), &Vector2u::operator ~) + + .Func(_SC("opEqual"), &Vector2u::operator ==) + .Func(_SC("opNotEqual"), &Vector2u::operator !=) + .Func(_SC("opLessThan"), &Vector2u::operator <) + .Func(_SC("opGreaterThan"), &Vector2u::operator >) + .Func(_SC("opLessEqual"), &Vector2u::operator <=) + .Func(_SC("opGreaterEqual"), &Vector2u::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Vector2u.hpp b/source/Base/Vector2u.hpp new file mode 100644 index 00000000..8263fb43 --- /dev/null +++ b/source/Base/Vector2u.hpp @@ -0,0 +1,142 @@ +#ifndef _BASE_VECTOR2U_HPP_ +#define _BASE_VECTOR2U_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Vector2u +{ + // -------------------------------------------------------------------------------------------- + typedef SQUnsignedInteger32 Value; + // -------------------------------------------------------------------------------------------- + static const Vector2u NIL; + static const Vector2u MIN; + static const Vector2u MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Value x, y; + // -------------------------------------------------------------------------------------------- + Vector2u() noexcept; + Vector2u(Value s) noexcept; + Vector2u(Value xv, Value yv) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u(const Vector2i & v) noexcept; + Vector2u(const Vector2f & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u(const Vector2u & v) noexcept; + Vector2u(Vector2u && v) noexcept; + // -------------------------------------------------------------------------------------------- + ~Vector2u(); + // -------------------------------------------------------------------------------------------- + Vector2u & operator = (const Vector2u & v) noexcept; + Vector2u & operator = (Vector2u && v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u & operator = (Value s) noexcept; + Vector2u & operator = (const SQChar * values) noexcept; + Vector2u & operator = (const Vector2i & v) noexcept; + Vector2u & operator = (const Vector2f & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u & operator += (const Vector2u & v) noexcept; + Vector2u & operator -= (const Vector2u & v) noexcept; + Vector2u & operator *= (const Vector2u & v) noexcept; + Vector2u & operator /= (const Vector2u & v) noexcept; + Vector2u & operator %= (const Vector2u & v) noexcept; + Vector2u & operator &= (const Vector2u & v) noexcept; + Vector2u & operator |= (const Vector2u & v) noexcept; + Vector2u & operator ^= (const Vector2u & v) noexcept; + Vector2u & operator <<= (const Vector2u & v) noexcept; + Vector2u & operator >>= (const Vector2u & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u & operator += (Value s) noexcept; + Vector2u & operator -= (Value s) noexcept; + Vector2u & operator *= (Value s) noexcept; + Vector2u & operator /= (Value s) noexcept; + Vector2u & operator %= (Value s) noexcept; + Vector2u & operator &= (Value s) noexcept; + Vector2u & operator |= (Value s) noexcept; + Vector2u & operator ^= (Value s) noexcept; + Vector2u & operator <<= (Value s) noexcept; + Vector2u & operator >>= (Value s) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u & operator ++ () noexcept; + Vector2u & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator ++ (int) noexcept; + Vector2u operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator + (const Vector2u & v) const noexcept; + Vector2u operator + (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator - (const Vector2u & v) const noexcept; + Vector2u operator - (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator * (const Vector2u & v) const noexcept; + Vector2u operator * (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator / (const Vector2u & v) const noexcept; + Vector2u operator / (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator % (const Vector2u & v) const noexcept; + Vector2u operator % (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator & (const Vector2u & v) const noexcept; + Vector2u operator & (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator | (const Vector2u & v) const noexcept; + Vector2u operator | (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator ^ (const Vector2u & v) const noexcept; + Vector2u operator ^ (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator << (const Vector2u & v) const noexcept; + Vector2u operator << (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator >> (const Vector2u & v) const noexcept; + Vector2u operator >> (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator + () const noexcept; + Vector2u operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + Vector2u operator ~ () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Vector2u & v) const noexcept; + bool operator != (const Vector2u & v) const noexcept; + bool operator < (const Vector2u & v) const noexcept; + bool operator > (const Vector2u & v) const noexcept; + bool operator <= (const Vector2u & v) const noexcept; + bool operator >= (const Vector2u & v) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Vector2u & v) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value ns) noexcept; + void Set(Value nx, Value ny) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Vector2u & v) noexcept; + void Set(const Vector2i & v) noexcept; + void Set(const Vector2f & v) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { x = 0, y = 0; } + // -------------------------------------------------------------------------------------------- + Vector2u Abs() const noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_VECTOR2U_HPP_ diff --git a/source/Base/Vector3.cpp b/source/Base/Vector3.cpp new file mode 100644 index 00000000..0cd2c458 --- /dev/null +++ b/source/Base/Vector3.cpp @@ -0,0 +1,516 @@ +#include "Base/Vector3.hpp" +#include "Base/Vector4.hpp" +#include "Base/Quaternion.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Vector3 Vector3::NIL = Vector3(0); +const Vector3 Vector3::MIN = Vector3(std::numeric_limits::min()); +const Vector3 Vector3::MAX = Vector3(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Vector3::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Vector3::Vector3() noexcept + : x(0.0), y(0.0), z(0.0) +{ + +} + +Vector3::Vector3(Value s) noexcept + : x(s), y(s), z(s) +{ + +} + +Vector3::Vector3(Value xv, Value yv, Value zv) noexcept + : x(xv), y(yv), z(zv) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector3::Vector3(const Vector4 & v) noexcept + : x(v.x), y(v.y), z(v.z) +{ + +} + +Vector3::Vector3(const Quaternion & q) noexcept + : x(q.x), y(q.y), z(q.z) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector3::Vector3(const SQChar * values, char delim) noexcept + : Vector3(GetVector3(values, delim)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector3::Vector3(const Vector3 & v) noexcept + : x(v.x), y(v.y), z(v.z) +{ + +} + +Vector3::Vector3(Vector3 && v) noexcept + : x(v.x), y(v.y), z(v.z) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector3::~Vector3() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector3 & Vector3::operator = (const Vector3 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + return *this; +} + +Vector3 & Vector3::operator = (Vector3 && v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector3 & Vector3::operator = (Value s) noexcept +{ + x = s; + y = s; + z = s; + return *this; +} + +Vector3 & Vector3::operator = (const Vector4 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + return *this; +} + +Vector3 & Vector3::operator = (const Quaternion & q) noexcept +{ + x = q.x; + y = q.y; + z = q.z; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector3 & Vector3::operator += (const Vector3 & v) noexcept +{ + x += v.x; + y += v.y; + z += v.z; + return *this; +} + +Vector3 & Vector3::operator -= (const Vector3 & v) noexcept +{ + x -= v.x; + y -= v.y; + z -= v.z; + return *this; +} + +Vector3 & Vector3::operator *= (const Vector3 & v) noexcept +{ + x *= v.x; + y *= v.y; + z *= v.z; + return *this; +} + +Vector3 & Vector3::operator /= (const Vector3 & v) noexcept +{ + x /= v.x; + y /= v.y; + z /= v.z; + return *this; +} + +Vector3 & Vector3::operator %= (const Vector3 & v) noexcept +{ + x = std::fmod(x, v.x); + y = std::fmod(y, v.y); + z = std::fmod(z, v.z); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector3 & Vector3::operator += (Value s) noexcept +{ + x += s; + y += s; + z += s; + return *this; +} + +Vector3 & Vector3::operator -= (Value s) noexcept +{ + x -= s; + y -= s; + z -= s; + return *this; +} + +Vector3 & Vector3::operator *= (Value s) noexcept +{ + x *= s; + y *= s; + z *= s; + return *this; +} + +Vector3 & Vector3::operator /= (Value s) noexcept +{ + x /= s; + y /= s; + z /= s; + return *this; +} + +Vector3 & Vector3::operator %= (Value s) noexcept +{ + x = std::fmod(x, s); + y = std::fmod(y, s); + z = std::fmod(z, s); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector3 & Vector3::operator ++ () noexcept +{ + ++x; + ++y; + ++z; + return *this; +} + +Vector3 & Vector3::operator -- () noexcept +{ + --x; + --y; + --z; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector3 Vector3::operator ++ (int) noexcept +{ + Vector3 state(*this); + ++x; + ++y; + ++z; + return state; +} + +Vector3 Vector3::operator -- (int) noexcept +{ + Vector3 state(*this); + --x; + --y; + --z; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Vector3 Vector3::operator + (const Vector3 & v) const noexcept +{ + return Vector3(x + v.x, y + v.y, z + v.z); +} + +Vector3 Vector3::operator - (const Vector3 & v) const noexcept +{ + return Vector3(x - v.x, y - v.y, z - v.z); +} + +Vector3 Vector3::operator * (const Vector3 & v) const noexcept +{ + return Vector3(x * v.x, y * v.y, z * v.z); +} + +Vector3 Vector3::operator / (const Vector3 & v) const noexcept +{ + return Vector3(x / v.x, y / v.y, z / v.z); +} + +Vector3 Vector3::operator % (const Vector3 & v) const noexcept +{ + return Vector3(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z)); +} + +// ------------------------------------------------------------------------------------------------ +Vector3 Vector3::operator + (Value s) const noexcept +{ + return Vector3(x + s, y + s, z + s); +} + +Vector3 Vector3::operator - (Value s) const noexcept +{ + return Vector3(x - s, y - s, z - s); +} + +Vector3 Vector3::operator * (Value s) const noexcept +{ + return Vector3(x * s, y * s, z * s); +} + +Vector3 Vector3::operator / (Value s) const noexcept +{ + return Vector3(x / s, y / s, z / s); +} + +Vector3 Vector3::operator % (Value s) const noexcept +{ + return Vector3(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s)); +} + +// ------------------------------------------------------------------------------------------------ +Vector3 Vector3::operator + () const noexcept +{ + return Vector3(std::fabs(x), std::fabs(y), std::fabs(z)); +} + +Vector3 Vector3::operator - () const noexcept +{ + return Vector3(-x, -y, -z); +} + +// ------------------------------------------------------------------------------------------------ +bool Vector3::operator == (const Vector3 & v) const noexcept +{ + return EpsEq(x, v.x) && EpsEq(y, v.y) && EpsEq(z, v.z); +} + +bool Vector3::operator != (const Vector3 & v) const noexcept +{ + return !EpsEq(x, v.x) && !EpsEq(y, v.y) && !EpsEq(z, v.z); +} + +bool Vector3::operator < (const Vector3 & v) const noexcept +{ + return std::isless(x, v.x) && std::isless(y, v.y) && std::isless(z, v.z); +} + +bool Vector3::operator > (const Vector3 & v) const noexcept +{ + return std::isgreater(x, v.x) && std::isgreater(y, v.y) && std::isgreater(z, v.z); +} + +bool Vector3::operator <= (const Vector3 & v) const noexcept +{ + return std::islessequal(x, v.x) && std::islessequal(y, v.y) && std::islessequal(z, v.z); +} + +bool Vector3::operator >= (const Vector3 & v) const noexcept +{ + return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y) && std::isgreaterequal(z, v.z); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Vector3::Cmp(const Vector3 & v) const noexcept +{ + return *this == v ? 0 : (*this > v ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Vector3::ToString() const noexcept +{ + return ToStringF("%f,%f,%f", x, y, z); +} + +// ------------------------------------------------------------------------------------------------ +void Vector3::Set(Value ns) noexcept +{ + x = ns; + y = ns; + z = ns; +} + +void Vector3::Set(Value nx, Value ny, Value nz) noexcept +{ + x = nx; + y = ny; + z = nz; +} + +// ------------------------------------------------------------------------------------------------ +void Vector3::Set(const Vector3 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; +} + +void Vector3::Set(const Vector4 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; +} + +void Vector3::Set(const Quaternion & q) noexcept +{ + x = q.x; + y = q.y; + z = q.z; +} + +// ------------------------------------------------------------------------------------------------ +void Vector3::Set(const SQChar * values, char delim) noexcept +{ + Set(GetVector3(values, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Vector3::Generate() noexcept +{ + x = RandomVal::Get(); + y = RandomVal::Get(); + z = RandomVal::Get(); +} + +void Vector3::Generate(Value min, Value max) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(min, max); + y = RandomVal::Get(min, max); + z = RandomVal::Get(min, max); + } +} + +void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax) noexcept +{ + if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin)) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(xmin, xmax); + y = RandomVal::Get(ymin, ymax); + z = RandomVal::Get(zmin, zmax); + } +} + +// ------------------------------------------------------------------------------------------------ +Vector3 Vector3::Abs() const noexcept +{ + return Vector3(std::fabs(x), std::fabs(y), std::fabs(z)); +} + +// ================================================================================================ +bool Register_Vector3(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Vector3::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Vector3"), Sqrat::Class(vm, _SC("Vector3")) + .Ctor() + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Vector3::Delim) + + .Var(_SC("x"), &Vector3::x) + .Var(_SC("y"), &Vector3::y) + .Var(_SC("z"), &Vector3::z) + + .Prop(_SC("abs"), &Vector3::Abs) + + .Func(_SC("_tostring"), &Vector3::ToString) + .Func(_SC("_cmp"), &Vector3::Cmp) + + .Func(_SC("_add"), &Vector3::operator +) + .Func(_SC("_sub"), &Vector3::operator -) + .Func(_SC("_mul"), &Vector3::operator *) + .Func(_SC("_div"), &Vector3::operator /) + .Func(_SC("_modulo"), &Vector3::operator %) + .Func(_SC("_unm"), &Vector3::operator -) + + .Overload(_SC("set"), &Vector3::Set) + .Overload(_SC("set"), &Vector3::Set) + .Overload(_SC("set_vec3"), &Vector3::Set) + .Overload(_SC("set_vec4"), &Vector3::Set) + .Overload(_SC("set_quat"), &Vector3::Set) + .Overload(_SC("set_str"), &Vector3::Set) + + .Overload(_SC("generate"), &Vector3::Generate) + .Overload(_SC("generate"), &Vector3::Generate) + .Overload(_SC("generate"), &Vector3::Generate) + + .Func(_SC("clear"), &Vector3::Clear) + + .Func(_SC("opAddAssign"), &Vector3::operator +=) + .Func(_SC("opSubAssign"), &Vector3::operator -=) + .Func(_SC("opMulAssign"), &Vector3::operator *=) + .Func(_SC("opDivAssign"), &Vector3::operator /=) + .Func(_SC("opModAssign"), &Vector3::operator %=) + + .Func(_SC("opAddAssignS"), &Vector3::operator +=) + .Func(_SC("opSubAssignS"), &Vector3::operator -=) + .Func(_SC("opMulAssignS"), &Vector3::operator *=) + .Func(_SC("opDivAssignS"), &Vector3::operator /=) + .Func(_SC("opModAssignS"), &Vector3::operator %=) + + .Func(_SC("opPreInc"), &Vector3::operator ++) + .Func(_SC("opPreDec"), &Vector3::operator --) + .Func(_SC("opPostInc"), &Vector3::operator ++) + .Func(_SC("opPostDec"), &Vector3::operator --) + + .Func(_SC("opAdd"), &Vector3::operator +) + .Func(_SC("opSub"), &Vector3::operator -) + .Func(_SC("opMul"), &Vector3::operator *) + .Func(_SC("opDiv"), &Vector3::operator /) + .Func(_SC("opMod"), &Vector3::operator %) + + .Func(_SC("opAddS"), &Vector3::operator +) + .Func(_SC("opSubS"), &Vector3::operator -) + .Func(_SC("opMulS"), &Vector3::operator *) + .Func(_SC("opDivS"), &Vector3::operator /) + .Func(_SC("opModS"), &Vector3::operator %) + + .Func(_SC("opUnPlus"), &Vector3::operator +) + .Func(_SC("opUnMinus"), &Vector3::operator -) + + .Func(_SC("opEqual"), &Vector3::operator ==) + .Func(_SC("opNotEqual"), &Vector3::operator !=) + .Func(_SC("opLessThan"), &Vector3::operator <) + .Func(_SC("opGreaterThan"), &Vector3::operator >) + .Func(_SC("opLessEqual"), &Vector3::operator <=) + .Func(_SC("opGreaterEqual"), &Vector3::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Vector3.hpp b/source/Base/Vector3.hpp new file mode 100644 index 00000000..88f907c0 --- /dev/null +++ b/source/Base/Vector3.hpp @@ -0,0 +1,111 @@ +#ifndef _BASE_VECTOR3_HPP_ +#define _BASE_VECTOR3_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Vector3 +{ + // -------------------------------------------------------------------------------------------- + typedef SQFloat Value; + // -------------------------------------------------------------------------------------------- + static const Vector3 NIL; + static const Vector3 MIN; + static const Vector3 MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Value x, y, z; + // -------------------------------------------------------------------------------------------- + Vector3() noexcept; + Vector3(Value s) noexcept; + Vector3(Value xv, Value yv, Value zv) noexcept; + // -------------------------------------------------------------------------------------------- + Vector3(const Vector4 & v) noexcept; + Vector3(const Quaternion & q) noexcept; + // -------------------------------------------------------------------------------------------- + Vector3(const SQChar * values, char delim) noexcept; + // -------------------------------------------------------------------------------------------- + Vector3(const Vector3 & v) noexcept; + Vector3(Vector3 && v) noexcept; + // -------------------------------------------------------------------------------------------- + ~Vector3(); + // -------------------------------------------------------------------------------------------- + Vector3 & operator = (const Vector3 & v) noexcept; + Vector3 & operator = (Vector3 && v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector3 & operator = (Value s) noexcept; + Vector3 & operator = (const Vector4 & v) noexcept; + Vector3 & operator = (const Quaternion & q) noexcept; + // -------------------------------------------------------------------------------------------- + Vector3 & operator += (const Vector3 & v) noexcept; + Vector3 & operator -= (const Vector3 & v) noexcept; + Vector3 & operator *= (const Vector3 & v) noexcept; + Vector3 & operator /= (const Vector3 & v) noexcept; + Vector3 & operator %= (const Vector3 & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector3 & operator += (Value s) noexcept; + Vector3 & operator -= (Value s) noexcept; + Vector3 & operator *= (Value s) noexcept; + Vector3 & operator /= (Value s) noexcept; + Vector3 & operator %= (Value s) noexcept; + // -------------------------------------------------------------------------------------------- + Vector3 & operator ++ () noexcept; + Vector3 & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Vector3 operator ++ (int) noexcept; + Vector3 operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Vector3 operator + (const Vector3 & v) const noexcept; + Vector3 operator - (const Vector3 & v) const noexcept; + Vector3 operator * (const Vector3 & v) const noexcept; + Vector3 operator / (const Vector3 & v) const noexcept; + Vector3 operator % (const Vector3 & v) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector3 operator + (Value s) const noexcept; + Vector3 operator - (Value s) const noexcept; + Vector3 operator * (Value s) const noexcept; + Vector3 operator / (Value s) const noexcept; + Vector3 operator % (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector3 operator + () const noexcept; + Vector3 operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Vector3 & v) const noexcept; + bool operator != (const Vector3 & v) const noexcept; + bool operator < (const Vector3 & v) const noexcept; + bool operator > (const Vector3 & v) const noexcept; + bool operator <= (const Vector3 & v) const noexcept; + bool operator >= (const Vector3 & v) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Vector3 & v) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value ns) noexcept; + void Set(Value nx, Value ny, Value nz) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Vector3 & v) noexcept; + void Set(const Vector4 & v) noexcept; + void Set(const Quaternion & q) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * values, char delim) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { x = 0.0, y = 0.0, z = 0.0; } + // -------------------------------------------------------------------------------------------- + Vector3 Abs() const noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_VECTOR3_HPP_ diff --git a/source/Base/Vector4.cpp b/source/Base/Vector4.cpp new file mode 100644 index 00000000..f23b01fc --- /dev/null +++ b/source/Base/Vector4.cpp @@ -0,0 +1,559 @@ +#include "Base/Vector4.hpp" +#include "Base/Vector3.hpp" +#include "Base/Quaternion.hpp" +#include "Base/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Vector4 Vector4::NIL = Vector4(0); +const Vector4 Vector4::MIN = Vector4(std::numeric_limits::min()); +const Vector4 Vector4::MAX = Vector4(std::numeric_limits::max()); + +// ------------------------------------------------------------------------------------------------ +SQChar Vector4::Delim = ','; + +// ------------------------------------------------------------------------------------------------ +Vector4::Vector4() noexcept + : x(0.0), y(0.0), z(0.0), w(0.0) +{ + +} + +Vector4::Vector4(Value s) noexcept + : x(s), y(s), z(s), w(s) +{ + +} + +Vector4::Vector4(Value xv, Value yv, Value zv) noexcept + : x(xv), y(yv), z(zv), w(0.0) +{ + +} + +Vector4::Vector4(Value xv, Value yv, Value zv, Value wv) noexcept + : x(xv), y(yv), z(zv), w(wv) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector4::Vector4(const Vector3 & v) noexcept + : x(v.x), y(v.y), z(v.z), w(0.0) +{ + +} + +Vector4::Vector4(const Quaternion & q) noexcept + : x(q.x), y(q.y), z(q.z), w(q.w) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector4::Vector4(const SQChar * values, SQChar delim) noexcept + : Vector4(GetVector4(values, delim)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector4::Vector4(const Vector4 & v) noexcept + : x(v.x), y(v.y), z(v.z), w(v.w) +{ + +} + +Vector4::Vector4(Vector4 && v) noexcept + : x(v.x), y(v.y), z(v.z), w(v.w) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector4::~Vector4() +{ + +} + +// ------------------------------------------------------------------------------------------------ +Vector4 & Vector4::operator = (const Vector4 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + w = v.w; + return *this; +} + +Vector4 & Vector4::operator = (Vector4 && v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + w = v.w; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector4 & Vector4::operator = (Value s) noexcept +{ + x = s; + y = s; + z = s; + w = s; + return *this; +} + +Vector4 & Vector4::operator = (const Vector3 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + w = 0.0; + return *this; +} + +Vector4 & Vector4::operator = (const Quaternion & q) noexcept +{ + x = q.x; + y = q.y; + z = q.z; + w = q.w; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector4 & Vector4::operator += (const Vector4 & v) noexcept +{ + x += v.x; + y += v.y; + z += v.z; + w += v.w; + return *this; +} + +Vector4 & Vector4::operator -= (const Vector4 & v) noexcept +{ + x -= v.x; + y -= v.y; + z -= v.z; + w -= v.w; + return *this; +} + +Vector4 & Vector4::operator *= (const Vector4 & v) noexcept +{ + x *= v.x; + y *= v.y; + z *= v.z; + w *= v.w; + return *this; +} + +Vector4 & Vector4::operator /= (const Vector4 & v) noexcept +{ + x /= v.x; + y /= v.y; + z /= v.z; + w /= v.w; + return *this; +} + +Vector4 & Vector4::operator %= (const Vector4 & v) noexcept +{ + x = std::fmod(x, v.x); + y = std::fmod(y, v.y); + z = std::fmod(z, v.z); + w = std::fmod(w, v.w); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector4 & Vector4::operator += (Value s) noexcept +{ + x += s; + y += s; + z += s; + w += s; + return *this; +} + +Vector4 & Vector4::operator -= (Value s) noexcept +{ + x -= s; + y -= s; + z -= s; + w -= s; + return *this; +} + +Vector4 & Vector4::operator *= (Value s) noexcept +{ + x *= s; + y *= s; + z *= s; + w *= s; + return *this; +} + +Vector4 & Vector4::operator /= (Value s) noexcept +{ + x /= s; + y /= s; + z /= s; + w /= s; + return *this; +} + +Vector4 & Vector4::operator %= (Value s) noexcept +{ + x = std::fmod(x, s); + y = std::fmod(y, s); + z = std::fmod(z, s); + w = std::fmod(w, s); + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector4 & Vector4::operator ++ () noexcept +{ + ++x; + ++y; + ++z; + ++w; + return *this; +} + +Vector4 & Vector4::operator -- () noexcept +{ + --x; + --y; + --z; + --w; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +Vector4 Vector4::operator ++ (int) noexcept +{ + Vector4 state(*this); + ++x; + ++y; + ++z; + ++w; + return state; +} + +Vector4 Vector4::operator -- (int) noexcept +{ + Vector4 state(*this); + --x; + --y; + --z; + --w; + return state; +} + +// ------------------------------------------------------------------------------------------------ +Vector4 Vector4::operator + (const Vector4 & v) const noexcept +{ + return Vector4(x + v.x, y + v.y, z + v.z, w + v.w); +} + +Vector4 Vector4::operator - (const Vector4 & v) const noexcept +{ + return Vector4(x - v.x, y - v.y, z - v.z, w - v.w); +} + +Vector4 Vector4::operator * (const Vector4 & v) const noexcept +{ + return Vector4(x * v.x, y * v.y, z * v.z, w * v.w); +} + +Vector4 Vector4::operator / (const Vector4 & v) const noexcept +{ + return Vector4(x / v.x, y / v.y, z / v.z, w / v.w); +} + +Vector4 Vector4::operator % (const Vector4 & v) const noexcept +{ + return Vector4(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z), std::fmod(w, v.w)); +} + +// ------------------------------------------------------------------------------------------------ +Vector4 Vector4::operator + (Value s) const noexcept +{ + return Vector4(x + s, y + s, z + s, w + s); +} + +Vector4 Vector4::operator - (Value s) const noexcept +{ + return Vector4(x - s, y - s, z - s, w - s); +} + +Vector4 Vector4::operator * (Value s) const noexcept +{ + return Vector4(x * s, y * s, z * s, w * s); +} + +Vector4 Vector4::operator / (Value s) const noexcept +{ + return Vector4(x / s, y / s, z / s, w / s); +} + +Vector4 Vector4::operator % (Value s) const noexcept +{ + return Vector4(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s)); +} + +// ------------------------------------------------------------------------------------------------ +Vector4 Vector4::operator + () const noexcept +{ + return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w)); +} + +Vector4 Vector4::operator - () const noexcept +{ + return Vector4(-x, -y, -z, -w); +} + +// ------------------------------------------------------------------------------------------------ +bool Vector4::operator == (const Vector4 & v) const noexcept +{ + return EpsEq(x, v.x) && EpsEq(y, v.y) && EpsEq(z, v.z) && EpsEq(w, v.w); +} + +bool Vector4::operator != (const Vector4 & v) const noexcept +{ + return !EpsEq(x, v.x) && !EpsEq(y, v.y) && !EpsEq(z, v.z) && !EpsEq(w, v.w); +} + +bool Vector4::operator < (const Vector4 & v) const noexcept +{ + return std::isless(x, v.x) && std::isless(y, v.y) && std::isless(z, v.z) && std::isless(w, v.w); +} + +bool Vector4::operator > (const Vector4 & v) const noexcept +{ + return std::isgreater(x, v.x) && std::isgreater(y, v.y) && std::isgreater(z, v.z) && std::isgreater(w, v.w); +} + +bool Vector4::operator <= (const Vector4 & v) const noexcept +{ + return std::islessequal(x, v.x) && std::islessequal(y, v.y) && std::islessequal(z, v.z) && std::islessequal(w, v.w); +} + +bool Vector4::operator >= (const Vector4 & v) const noexcept +{ + return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y) && std::isgreaterequal(z, v.z) && std::isgreaterequal(w, v.w); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Vector4::Cmp(const Vector4 & v) const noexcept +{ + return *this == v ? 0 : (*this > v ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * Vector4::ToString() const noexcept +{ + return ToStringF("%f,%f,%f,%f", x, y, z, w); +} + +// ------------------------------------------------------------------------------------------------ +void Vector4::Set(Value ns) noexcept +{ + x = ns; + y = ns; + z = ns; + w = ns; +} + +void Vector4::Set(Value nx, Value ny, Value nz) noexcept +{ + x = nx; + y = ny; + z = nz; +} + +void Vector4::Set(Value nx, Value ny, Value nz, Value nw) noexcept +{ + x = nx; + y = ny; + z = nz; + w = nw; +} + +// ------------------------------------------------------------------------------------------------ +void Vector4::Set(const Vector4 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + w = v.w; +} + +void Vector4::Set(const Vector3 & v) noexcept +{ + x = v.x; + y = v.y; + z = v.z; + w = 0.0; +} + +void Vector4::Set(const Quaternion & q) noexcept +{ + x = q.x; + y = q.y; + z = q.z; + w = q.w; +} + +// ------------------------------------------------------------------------------------------------ +void Vector4::Set(const SQChar * values, SQChar delim) noexcept +{ + Set(GetVector4(values, delim)); +} + +// ------------------------------------------------------------------------------------------------ +void Vector4::Generate() noexcept +{ + x = RandomVal::Get(); + y = RandomVal::Get(); + z = RandomVal::Get(); + w = RandomVal::Get(); +} + +void Vector4::Generate(Value min, Value max) noexcept +{ + if (max < min) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(min, max); + y = RandomVal::Get(min, max); + z = RandomVal::Get(min, max); + y = RandomVal::Get(min, max); + } +} + +void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax) noexcept +{ + if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin) || std::isless(wmax, wmin)) + { + LogErr("max value is lower than min value"); + } + else + { + x = RandomVal::Get(xmin, xmax); + y = RandomVal::Get(ymin, ymax); + z = RandomVal::Get(zmin, zmax); + y = RandomVal::Get(ymin, ymax); + } +} + +// ------------------------------------------------------------------------------------------------ +Vector4 Vector4::Abs() const noexcept +{ + return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w)); +} + +// ================================================================================================ +bool Register_Vector4(HSQUIRRELVM vm) +{ + LogDbg("Beginning registration of type"); + + typedef Vector4::Value Val; + + Sqrat::RootTable(vm).Bind(_SC("Vector4"), Sqrat::Class(vm, _SC("Vector4")) + .Ctor() + .Ctor() + .Ctor() + .Ctor() + .Ctor() + + .SetStaticValue(_SC("delim"), &Vector4::Delim) + + .Var(_SC("x"), &Vector4::x) + .Var(_SC("y"), &Vector4::y) + .Var(_SC("z"), &Vector4::z) + .Var(_SC("w"), &Vector4::w) + + .Prop(_SC("abs"), &Vector4::Abs) + + .Func(_SC("_tostring"), &Vector4::ToString) + .Func(_SC("_cmp"), &Vector4::Cmp) + + .Func(_SC("_add"), &Vector4::operator +) + .Func(_SC("_sub"), &Vector4::operator -) + .Func(_SC("_mul"), &Vector4::operator *) + .Func(_SC("_div"), &Vector4::operator /) + .Func(_SC("_modulo"), &Vector4::operator %) + .Func(_SC("_unm"), &Vector4::operator -) + + .Overload(_SC("set"), &Vector4::Set) + .Overload(_SC("set"), &Vector4::Set) + .Overload(_SC("set"), &Vector4::Set) + .Overload(_SC("set_vec4"), &Vector4::Set) + .Overload(_SC("set_vec3"), &Vector4::Set) + .Overload(_SC("set_quat"), &Vector4::Set) + .Overload(_SC("set_str"), &Vector4::Set) + + .Overload(_SC("generate"), &Vector4::Generate) + .Overload(_SC("generate"), &Vector4::Generate) + .Overload(_SC("generate"), &Vector4::Generate) + + .Func(_SC("clear"), &Vector4::Clear) + + .Func(_SC("opAddAssign"), &Vector4::operator +=) + .Func(_SC("opSubAssign"), &Vector4::operator -=) + .Func(_SC("opMulAssign"), &Vector4::operator *=) + .Func(_SC("opDivAssign"), &Vector4::operator /=) + .Func(_SC("opModAssign"), &Vector4::operator %=) + + .Func(_SC("opAddAssignS"), &Vector4::operator +=) + .Func(_SC("opSubAssignS"), &Vector4::operator -=) + .Func(_SC("opMulAssignS"), &Vector4::operator *=) + .Func(_SC("opDivAssignS"), &Vector4::operator /=) + .Func(_SC("opModAssignS"), &Vector4::operator %=) + + .Func(_SC("opPreInc"), &Vector4::operator ++) + .Func(_SC("opPreDec"), &Vector4::operator --) + .Func(_SC("opPostInc"), &Vector4::operator ++) + .Func(_SC("opPostDec"), &Vector4::operator --) + + .Func(_SC("opAdd"), &Vector4::operator +) + .Func(_SC("opSub"), &Vector4::operator -) + .Func(_SC("opMul"), &Vector4::operator *) + .Func(_SC("opDiv"), &Vector4::operator /) + .Func(_SC("opMod"), &Vector4::operator %) + + .Func(_SC("opAddS"), &Vector4::operator +) + .Func(_SC("opSubS"), &Vector4::operator -) + .Func(_SC("opMulS"), &Vector4::operator *) + .Func(_SC("opDivS"), &Vector4::operator /) + .Func(_SC("opModS"), &Vector4::operator %) + + .Func(_SC("opUnPlus"), &Vector4::operator +) + .Func(_SC("opUnMinus"), &Vector4::operator -) + + .Func(_SC("opEqual"), &Vector4::operator ==) + .Func(_SC("opNotEqual"), &Vector4::operator !=) + .Func(_SC("opLessThan"), &Vector4::operator <) + .Func(_SC("opGreaterThan"), &Vector4::operator >) + .Func(_SC("opLessEqual"), &Vector4::operator <=) + .Func(_SC("opGreaterEqual"), &Vector4::operator >=) + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Base/Vector4.hpp b/source/Base/Vector4.hpp new file mode 100644 index 00000000..965bc587 --- /dev/null +++ b/source/Base/Vector4.hpp @@ -0,0 +1,113 @@ +#ifndef _BASE_VECTOR4_HPP_ +#define _BASE_VECTOR4_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +struct Vector4 +{ + // -------------------------------------------------------------------------------------------- + typedef SQFloat Value; + // -------------------------------------------------------------------------------------------- + static const Vector4 NIL; + static const Vector4 MIN; + static const Vector4 MAX; + // -------------------------------------------------------------------------------------------- + static SQChar Delim; + // -------------------------------------------------------------------------------------------- + Value x, y, z, w; + // -------------------------------------------------------------------------------------------- + Vector4() noexcept; + Vector4(Value s) noexcept; + Vector4(Value xv, Value yv, Value zv) noexcept; + Vector4(Value xv, Value yv, Value zv, Value wv) noexcept; + // -------------------------------------------------------------------------------------------- + Vector4(const Vector3 & v) noexcept; + Vector4(const Quaternion & q) noexcept; + // -------------------------------------------------------------------------------------------- + Vector4(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + Vector4(const Vector4 & v) noexcept; + Vector4(Vector4 && v) noexcept; + // -------------------------------------------------------------------------------------------- + ~Vector4(); + // -------------------------------------------------------------------------------------------- + Vector4 & operator = (const Vector4 & v) noexcept; + Vector4 & operator = (Vector4 && v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector4 & operator = (Value s) noexcept; + Vector4 & operator = (const Vector3 & v) noexcept; + Vector4 & operator = (const Quaternion & q) noexcept; + // -------------------------------------------------------------------------------------------- + Vector4 & operator += (const Vector4 & v) noexcept; + Vector4 & operator -= (const Vector4 & v) noexcept; + Vector4 & operator *= (const Vector4 & v) noexcept; + Vector4 & operator /= (const Vector4 & v) noexcept; + Vector4 & operator %= (const Vector4 & v) noexcept; + // -------------------------------------------------------------------------------------------- + Vector4 & operator += (Value s) noexcept; + Vector4 & operator -= (Value s) noexcept; + Vector4 & operator *= (Value s) noexcept; + Vector4 & operator /= (Value s) noexcept; + Vector4 & operator %= (Value s) noexcept; + // -------------------------------------------------------------------------------------------- + Vector4 & operator ++ () noexcept; + Vector4 & operator -- () noexcept; + // -------------------------------------------------------------------------------------------- + Vector4 operator ++ (int) noexcept; + Vector4 operator -- (int) noexcept; + // -------------------------------------------------------------------------------------------- + Vector4 operator + (const Vector4 & v) const noexcept; + Vector4 operator - (const Vector4 & v) const noexcept; + Vector4 operator * (const Vector4 & v) const noexcept; + Vector4 operator / (const Vector4 & v) const noexcept; + Vector4 operator % (const Vector4 & v) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector4 operator + (Value s) const noexcept; + Vector4 operator - (Value s) const noexcept; + Vector4 operator * (Value s) const noexcept; + Vector4 operator / (Value s) const noexcept; + Vector4 operator % (Value s) const noexcept; + // -------------------------------------------------------------------------------------------- + Vector4 operator + () const noexcept; + Vector4 operator - () const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const Vector4 & v) const noexcept; + bool operator != (const Vector4 & v) const noexcept; + bool operator < (const Vector4 & v) const noexcept; + bool operator > (const Vector4 & v) const noexcept; + bool operator <= (const Vector4 & v) const noexcept; + bool operator >= (const Vector4 & v) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const Vector4 & v) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + void Set(Value ns) noexcept; + void Set(Value nx, Value ny, Value nz) noexcept; + void Set(Value nx, Value ny, Value nz, Value nw) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const Vector4 & v) noexcept; + void Set(const Vector3 & v) noexcept; + void Set(const Quaternion & q) noexcept; + // -------------------------------------------------------------------------------------------- + void Set(const SQChar * values, SQChar delim) noexcept; + // -------------------------------------------------------------------------------------------- + void Generate() noexcept; + void Generate(Value min, Value max) noexcept; + void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax) noexcept; + // -------------------------------------------------------------------------------------------- + void Clear() noexcept { x = 0.0, y = 0.0, z = 0.0, w = 0.0; } + // -------------------------------------------------------------------------------------------- + Vector4 Abs() const noexcept; +}; + +} // Namespace:: SqMod + +#endif // _BASE_VECTOR4_HPP_ diff --git a/source/Common.cpp b/source/Common.cpp new file mode 100644 index 00000000..9652f585 --- /dev/null +++ b/source/Common.cpp @@ -0,0 +1,463 @@ +#include "Common.hpp" +#include "Logger.hpp" +#include "Core.hpp" + +// ------------------------------------------------------------------------------------------------ +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// -------------------------------------------------------------------------------------------- +PluginFuncs* _Func = 0; +PluginCallbacks* _Clbk = 0; +PluginInfo* _Info = 0; + +// ------------------------------------------------------------------------------------------------ +void BindCallbacks() noexcept; + +// ------------------------------------------------------------------------------------------------ +SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallbacks * calls, PluginInfo * info) +{ + if (!_Log) + { + puts("[SQMOD] Unable to start because the logging class could not be instantiated"); + return SQMOD_FAILURE; + } + else if (!_Core) + { + puts("[SQMOD] Unable to start because the central core class could not be instantiated"); + return SQMOD_FAILURE; + } + else + { + _Func = funcs; + _Clbk = calls; + _Info = info; + + _Info->uPluginVer = SQMOD_VERSION; + std::strcpy(_Info->szName, SQMOD_NAME); + } + + _Log->Msg("%s", CenterStr("STARTUP", '*')); + + _Log->Inf("%s", CenterStr(SQMOD_NAME, ' ')); + _Log->Inf("%s", CenterStr(SQMOD_COPYRIGHT, ' ')); + _Log->Inf("%s", CenterStr(SQMOD_VERSION_STR, ' ')); + + if (!_Core->Init()) + { + _Log->Ftl("The plugin failed to initialize"); + _Log->Msg("%s", CenterStr("ABORTING", '*')); + + _Core->Deinit(); + + return SQMOD_FAILURE; + } + else if (_Clbk) + { + BindCallbacks(); + } + else + { + _Log->Ftl("Unable to start because the server callbacks are missing"); + + return SQMOD_FAILURE; + } + + return SQMOD_SUCCESS; +} + +// -------------------------------------------------------------------------------------------- +static int VC_InitServer(void) noexcept +{ + if (_Core->Load()) + { + _Core->OnServerStartup(); + } + else + { + _Log->Ftl("Unable to load the plugin resources properly"); + } + return _Core->GetState(); +} + +static void VC_ShutdownServer(void) noexcept +{ + _Core->OnServerShutdown(); + _Core->Terminate(); +} + +static void VC_Frame(float delta) noexcept +{ + _Core->OnServerFrame(delta); +} + +static void VC_PlayerConnect(int player) noexcept +{ + _Core->ConnectPlayer(player, SQMOD_CREATE_AUTOMATIC, SqObj()); +} + +static void VC_PlayerDisconnect(int player, int reason) noexcept +{ + _Core->DisconnectPlayer(player, reason, SqObj()); +} + +static void VC_PlayerBeginTyping(int player) noexcept +{ + _Core->OnPlayerStartTyping(player); +} + +static void VC_PlayerEndTyping(int player) noexcept +{ + _Core->OnPlayerStopTyping(player); +} + +static int VC_PlayerRequestClass(int player, int offset) noexcept +{ + _Core->SetState(SQMOD_SUCCESS); + _Core->OnPlayerRequestClass(player, offset); + return _Core->GetState(); +} + +static int VC_PlayerRequestSpawn(int player) noexcept +{ + _Core->SetState(SQMOD_SUCCESS); + _Core->OnPlayerRequestSpawn(player); + return _Core->GetState(); +} + +static void VC_PlayerSpawn(int player) noexcept +{ + _Core->OnPlayerSpawn(player); +} + +static void VC_PlayerDeath(int player, int killer, int reason, int body_part) noexcept +{ + if (_Func->IsPlayerConnected(killer)) + { + _Core->OnPlayerKilled(player, killer, reason, body_part); + } + else + { + _Core->OnPlayerWasted(player, reason); + } +} + +static void VC_PlayerUpdate(int player, int type) noexcept +{ + _Core->OnPlayerUpdate(player, type); +} + +static int VC_PlayerRequestEnter(int player, int vehicle, int slot) noexcept +{ + _Core->SetState(SQMOD_SUCCESS); + _Core->OnPlayerEmbarking(player, vehicle, slot); + return _Core->GetState(); +} + +static void VC_PlayerEnterVehicle(int player, int vehicle, int slot) noexcept +{ + _Core->OnPlayerEmbarked(player, vehicle, slot); +} + +static void VC_PlayerExitVehicle(int player, int vehicle) noexcept +{ + _Core->OnPlayerDisembark(player, vehicle); +} + +static int VC_PickupClaimPicked(int pickup, int player) noexcept +{ + _Core->SetState(SQMOD_SUCCESS); + _Core->OnPickupClaimed(pickup, player); + return _Core->GetState(); +} + +static void VC_PickupPickedUp(int pickup, int player) noexcept +{ + _Core->OnPickupCollected(pickup, player); +} + +static void VC_PickupRespawn(int pickup) noexcept +{ + _Core->OnPickupRespawn(pickup); +} + +static void VC_VehicleUpdate(int vehicle, int type) noexcept +{ + _Core->OnVehicleUpdate(vehicle, type); +} + +static void VC_VehicleExplode(int vehicle) noexcept +{ + _Core->OnVehicleExplode(vehicle); +} + +static void VC_VehicleRespawn(int vehicle) noexcept +{ + _Core->OnVehicleRespawn(vehicle); +} + +static void VC_ObjectShot(int object, int player, int weapon) noexcept +{ + _Core->OnObjectShot(object, player, weapon); +} + +static void VC_ObjectBump(int object, int player) noexcept +{ + _Core->OnObjectBump(object, player); +} + +static int VC_PublicMessage(int player, const char * text) noexcept +{ + _Core->SetState(SQMOD_SUCCESS); + _Core->OnPlayerChat(player, static_cast(text)); + return _Core->GetState(); +} + +static int VC_CommandMessage(int player, const char * text) noexcept +{ + _Core->SetState(SQMOD_SUCCESS); + _Core->OnPlayerCommand(player, static_cast(text)); + return _Core->GetState(); +} + +static int VC_PrivateMessage(int player, int target, const char * text) noexcept +{ + _Core->SetState(SQMOD_SUCCESS); + _Core->OnPlayerMessage(player, target, static_cast(text)); + return _Core->GetState(); +} + +static int VC_InternalCommand(unsigned int type, const char * text) noexcept +{ + _Core->SetState(SQMOD_SUCCESS); + _Core->OnInternalCommand(type, static_cast(text)); + return _Core->GetState(); +} + +static int VC_LoginAttempt(char * name, const char * passwd, const char * address) noexcept +{ + _Core->SetState(SQMOD_SUCCESS); + _Core->OnLoginAttempt(static_cast(name), static_cast(passwd), static_cast(address)); + return _Core->GetState(); +} + +static void VC_EntityPool(int type, int id, unsigned int deleted) noexcept +{ + _Core->OnEntityPool(type, id, static_cast(deleted)); +} + +static void VC_KeyBindDown(int player, int bind) noexcept +{ + _Core->OnPlayerKeyPress(player, bind); +} + +static void VC_KeyBindUp(int player, int bind) noexcept +{ + _Core->OnPlayerKeyRelease(player, bind); +} + +static void VC_PlayerAway(int player, unsigned int status) noexcept +{ + _Core->OnPlayerAway(player, static_cast(status)); +} + +static void VC_PlayerSpectate(int player, int target) noexcept +{ + _Core->OnPlayerSpectate(player, target); +} + +static void VC_PlayerCrashReport(int player, const char * report) noexcept +{ + _Core->OnPlayerCrashreport(player, static_cast(report)); +} + +static void VC_ServerPerformanceReport(int count, const char ** description, unsigned long long * millis) noexcept +{ + // Ignored for now... +} + +static void VC_PlayerName(int player, const char * previous, const char * current) noexcept +{ + _Core->OnPlayerName(player, static_cast(previous), static_cast(current)); +} + +static void VC_PlayerState(int player, int previous, int current) noexcept +{ + _Core->OnPlayerState(player, previous, current); + + switch (current) + { + case SQMOD_PLAYER_STATE_NONE: + _Core->OnStateNone(player, previous); + break; + case SQMOD_PLAYER_STATE_NORMAL: + _Core->OnStateNormal(player, previous); + break; + case SQMOD_PLAYER_STATE_SHOOTING: + _Core->OnStateShooting(player, previous); + break; + case SQMOD_PLAYER_STATE_DRIVER: + _Core->OnStateDriver(player, previous); + break; + case SQMOD_PLAYER_STATE_PASSENGER: + _Core->OnStatePassenger(player, previous); + break; + case SQMOD_PLAYER_STATE_ENTERING_AS_DRIVER: + _Core->OnStateEnterDriver(player, previous); + break; + case SQMOD_PLAYER_STATE_ENTERING_AS_PASSENGER: + _Core->OnStateEnterPassenger(player, previous); + break; + case SQMOD_PLAYER_STATE_EXITING_VEHICLE: + _Core->OnStateExitVehicle(player, previous); + break; + case SQMOD_PLAYER_STATE_UNSPAWNED: + _Core->OnStateUnspawned(player, previous); + break; + } +} + +static void VC_PlayerAction(int player, int previous, int current) noexcept +{ + _Core->OnPlayerAction(player, previous, current); + + switch (current) + { + case SQMOD_PLAYER_ACTION_NONE: + _Core->OnActionNone(player, previous); + break; + case SQMOD_PLAYER_ACTION_NORMAL: + _Core->OnActionNormal(player, previous); + break; + case SQMOD_PLAYER_ACTION_AIMING: + _Core->OnActionAiming(player, previous); + break; + case SQMOD_PLAYER_ACTION_SHOOTING: + _Core->OnActionShooting(player, previous); + break; + case SQMOD_PLAYER_ACTION_JUMPING: + _Core->OnActionJumping(player, previous); + break; + case SQMOD_PLAYER_ACTION_LYING_ON_GROUND: + _Core->OnActionLieDown(player, previous); + break; + case SQMOD_PLAYER_ACTION_GETTING_UP: + _Core->OnActionGettingUp(player, previous); + break; + case SQMOD_PLAYER_ACTION_JUMPING_FROM_VEHICLE: + _Core->OnActionJumpVehicle(player, previous); + break; + case SQMOD_PLAYER_ACTION_DRIVING: + _Core->OnActionDriving(player, previous); + break; + case SQMOD_PLAYER_ACTION_DYING: + _Core->OnActionDying(player, previous); + break; + case SQMOD_PLAYER_ACTION_WASTED: + _Core->OnActionWasted(player, previous); + break; + case SQMOD_PLAYER_ACTION_ENTERING_VEHICLE: + _Core->OnActionEmbarking(player, previous); + break; + case SQMOD_PLAYER_ACTION_EXITING_VEHICLE: + _Core->OnActionDisembarking(player, previous); + break; + } +} + +static void VC_PlayerOnFire(int player, unsigned int state) noexcept +{ + _Core->OnPlayerBurning(player, static_cast(state)); +} + +static void VC_PlayerCrouch(int player, unsigned int state) noexcept +{ + _Core->OnPlayerCrouching(player, static_cast(state)); +} + +static void VC_PlayerGameKeys(int player, int previous, int current) noexcept +{ + _Core->OnPlayerGameKeys(player, previous, current); +} + +static void VC_OnCheckpointEntered(int checkpoint, int player) noexcept +{ + _Core->OnCheckpointEntered(checkpoint, player); +} + +static void VC_OnCheckpointExited(int checkpoint, int player) noexcept +{ + _Core->OnCheckpointExited(checkpoint, player); +} + +static void VC_OnSphereEntered(int sphere, int player) noexcept +{ + _Core->OnSphereEntered(sphere, player); +} + +static void VC_OnSphereExited(int sphere, int player) noexcept +{ + _Core->OnSphereExited(sphere, player); +} + +// ------------------------------------------------------------------------------------------------ +void BindCallbacks() noexcept +{ + _Clbk->OnInitServer = VC_InitServer; + _Clbk->OnShutdownServer = VC_ShutdownServer; + _Clbk->OnFrame = VC_Frame; + _Clbk->OnPlayerConnect = VC_PlayerConnect; + _Clbk->OnPlayerDisconnect = VC_PlayerDisconnect; + _Clbk->OnPlayerBeginTyping = VC_PlayerBeginTyping; + _Clbk->OnPlayerEndTyping = VC_PlayerEndTyping; + _Clbk->OnPlayerRequestClass = VC_PlayerRequestClass; + _Clbk->OnPlayerRequestSpawn = VC_PlayerRequestSpawn; + _Clbk->OnPlayerSpawn = VC_PlayerSpawn; + _Clbk->OnPlayerDeath = VC_PlayerDeath; + _Clbk->OnPlayerUpdate = VC_PlayerUpdate; + _Clbk->OnPlayerRequestEnter = VC_PlayerRequestEnter; + _Clbk->OnPlayerEnterVehicle = VC_PlayerEnterVehicle; + _Clbk->OnPlayerExitVehicle = VC_PlayerExitVehicle; + _Clbk->OnPickupClaimPicked = VC_PickupClaimPicked; + _Clbk->OnPickupPickedUp = VC_PickupPickedUp; + _Clbk->OnPickupRespawn = VC_PickupRespawn; + _Clbk->OnVehicleUpdate = VC_VehicleUpdate; + _Clbk->OnVehicleExplode = VC_VehicleExplode; + _Clbk->OnVehicleRespawn = VC_VehicleRespawn; + _Clbk->OnObjectShot = VC_ObjectShot; + _Clbk->OnObjectBump = VC_ObjectBump; + _Clbk->OnPublicMessage = VC_PublicMessage; + _Clbk->OnCommandMessage = VC_CommandMessage; + _Clbk->OnPrivateMessage = VC_PrivateMessage; + _Clbk->OnInternalCommand = VC_InternalCommand; + _Clbk->OnLoginAttempt = VC_LoginAttempt; + _Clbk->OnEntityPoolChange = VC_EntityPool; + _Clbk->OnKeyBindDown = VC_KeyBindDown; + _Clbk->OnKeyBindUp = VC_KeyBindUp; + _Clbk->OnPlayerAwayChange = VC_PlayerAway; + _Clbk->OnPlayerSpectate = VC_PlayerSpectate; + _Clbk->OnPlayerCrashReport = VC_PlayerCrashReport; + _Clbk->OnServerPerformanceReport = VC_ServerPerformanceReport; + _Clbk->OnPlayerNameChange = VC_PlayerName; + _Clbk->OnPlayerStateChange = VC_PlayerState; + _Clbk->OnPlayerActionChange = VC_PlayerAction; + _Clbk->OnPlayerOnFireChange = VC_PlayerOnFire; + _Clbk->OnPlayerCrouchChange = VC_PlayerCrouch; + _Clbk->OnPlayerGameKeysChange = VC_PlayerGameKeys; + _Clbk->OnCheckpointEntered = VC_OnCheckpointEntered; + _Clbk->OnCheckpointExited = VC_OnCheckpointExited; + _Clbk->OnSphereEntered = VC_OnSphereEntered; + _Clbk->OnSphereExited = VC_OnSphereExited; +} + +// ------------------------------------------------------------------------------------------------ +SqObj & NullData() noexcept +{ + static SqObj d; + d.Release(); + return d; +} + +} // Namespace:: SqMod diff --git a/source/Common.hpp b/source/Common.hpp new file mode 100644 index 00000000..2901c8a0 --- /dev/null +++ b/source/Common.hpp @@ -0,0 +1,68 @@ +#ifndef _COMMON_HPP_ +#define _COMMON_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Base/Shared.hpp" + +// ------------------------------------------------------------------------------------------------ +#include +#include + +// ------------------------------------------------------------------------------------------------ +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +using namespace Sqrat; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +typedef ::Sqrat::string SqTag; +typedef ::Sqrat::Object SqObj; + +// ------------------------------------------------------------------------------------------------ +extern PluginFuncs* _Func; +extern PluginCallbacks* _Clbk; +extern PluginInfo* _Info; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +SqObj & NullData() noexcept; + +/* ------------------------------------------------------------------------------------------------ + * Utility used to transform values into script objects on the default VM +*/ +template < typename T > SqObj MakeSqObj(const T & v) noexcept +{ + // Push the specified value on the stack + Sqrat::PushVar< T >(Sqrat::DefaultVM::Get(), v); + // Get the object off the stack + Sqrat::Var< SqObj > var(Sqrat::DefaultVM::Get(), -1); + // Pop the object from the stack + sq_pop(Sqrat::DefaultVM::Get(), 1); + // Return the object + return var.value; +} + +/* ------------------------------------------------------------------------------------------------ + * Utility used to transform values into script objects +*/ +template < typename T > SqObj MakeSqObj(HSQUIRRELVM vm, const T & v) noexcept +{ + // Push the specified value on the stack + Sqrat::PushVar< T >(vm, v); + // Get the object off the stack + Sqrat::Var< SqObj > var(vm, -1); + // Pop the object from the stack + sq_pop(vm, 1); + // Return the object + return var.value; +} + +} // Namespace:: SqMod + +#endif // _COMMON_HPP_ diff --git a/source/Config.hpp b/source/Config.hpp new file mode 100644 index 00000000..1c733f6a --- /dev/null +++ b/source/Config.hpp @@ -0,0 +1,1175 @@ +#ifndef _CONFIG_HPP_ +#define _CONFIG_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include + +// ------------------------------------------------------------------------------------------------ +#include +#include + +/* ------------------------------------------------------------------------------------------------ + * ARCHITECTURE IDENTIFIERS +*/ + +#define SQMOD_ARCH_ID_UNKNOWN 0 +#define SQMOD_ARCH_ID_32_BIT 1 +#define SQMOD_ARCH_ID_64_BIT 2 + +/* ------------------------------------------------------------------------------------------------ + * PLATFORM IDENTIFIERS +*/ + +#define SQMOD_PLAT_ID_UNKNOWN 0 +#define SQMOD_PLAT_ID_WINDOWS 1 +#define SQMOD_PLAT_ID_LINUX 2 +#define SQMOD_PLAT_ID_MACOS 3 +#define SQMOD_PLAT_ID_UNIX 4 + +/* ------------------------------------------------------------------------------------------------ + * OS IDENTIFICATION +*/ + +#if defined(_WIN32) || defined(__WIN32__) || defined(_WIN) || defined(__WIN__) + // Windows x32 + #define SQMOD_OS_WINDOWS + #define SQMOD_OS_32 + #define SQMOD_OS_WINDOWS32 + #define SQMOD_ARCHITECTURE 1 + #define SQMOD_PLATFORM 1 +#elif defined(_WIN64) || defined(__WIN64__) + // Windows x64 + #define SQMOD_OS_WINDOWS + #define SQMOD_OS_64 + #define SQMOD_OS_WINDOWS64 + #define SQMOD_ARCHITECTURE 2 + #define SQMOD_PLATFORM 1 +#elif defined(linux) || defined(__linux) || defined(__linux__) + // Linux + #define SQMOD_OS_LINUX + #if __GNUC__ + #if __x86_64__ || __ppc64__ + #define SQMOD_OS_64 + #define SQMOD_OS_LINUX64 + #define SQMOD_ARCHITECTURE 2 + #define SQMOD_PLATFORM 2 + #else + #define SQMOD_OS_32 + #define SQMOD_OS_LINUX32 + #define SQMOD_ARCHITECTURE 1 + #define SQMOD_PLATFORM 2 + #endif + #endif +#elif defined(__APPLE__) || defined(__MACH__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh) + // MacOS + #define SQMOD_OS_MACOS + #if __GNUC__ + #if __x86_64__ || __ppc64__ + #define SQMOD_OS_64 + #define SQMOD_OS_MACOS64 + #define SQMOD_ARCHITECTURE 2 + #define SQMOD_PLATFORM 3 + #else + #define SQMOD_OS_32 + #define SQMOD_OS_MACOS32 + #define SQMOD_ARCHITECTURE 1 + #define SQMOD_PLATFORM 3 + #endif + #endif +#elif defined(__unix) || defined(__unix__) + // Unix + #define SQMOD_OS_UNIX + #if __GNUC__ + #if __x86_64__ || __ppc64__ + #define SQMOD_OS_64 + #define SQMOD_OS_UNIX64 + #define SQMOD_ARCHITECTURE 2 + #define SQMOD_PLATFORM 4 + #else + #define SQMOD_OS_32 + #define SQMOD_OS_UNIX32 + #define SQMOD_ARCHITECTURE 1 + #define SQMOD_PLATFORM 4 + #endif + #endif +#else + // Unsupported system + #error This operating system is not supported by the Hybrid Squirrel Module +#endif + +#ifndef SQMOD_ARCHITECTURE + #define SQMOD_ARCHITECTURE 0 +#endif + +#ifndef SQMOD_PLATFORM + #define SQMOD_PLATFORM 0 +#endif + +/* ------------------------------------------------------------------------------------------------ + * SOFTWARE INFORMATION +*/ + +#define SQMOD_NAME "Hybrid Squirrel Module" +#define SQMOD_AUTHOR "Sandu Liviu Catalin" +#define SQMOD_COPYRIGHT "Copyright (C) 2015 Sandu Liviu Catalin" +#define SQMOD_VERSION 001 +#define SQMOD_VERSION_STR "0.0.1" +#define SQMOD_VERSION_MAJOR 0 +#define SQMOD_VERSION_MINOR 0 +#define SQMOD_VERSION_PATCH 1 + +/* ------------------------------------------------------------------------------------------------ + * OS SPECIFFIC OPTIONS +*/ + +#if defined(SQMOD_OS_WINDOWS) + #define SQMOD_DIRSEP_CHAR '\\' + #define SQMOD_DIRSEP_STR "\\" +#else + #define SQMOD_DIRSEP_CHAR '/' + #define SQMOD_DIRSEP_STR "/" +#endif + +/* ------------------------------------------------------------------------------------------------ + * FUNDAMENTAL DATATYPES +*/ + +namespace SqMod { + +/**< 8 bits integer types */ +typedef signed char Int8; +typedef unsigned char Uint8; + +/**< 16 bits integer types */ +typedef signed short Int16; +typedef unsigned short Uint16; + +/**< 32 bits integer types */ +typedef signed int Int32; +typedef unsigned int Uint32; + +/**< 64 bits integer types */ +#if defined(_MSC_VER) + typedef signed __int64 Int64; + typedef unsigned __int64 Uint64; +#else + typedef signed long long Int64; + typedef unsigned long long Uint64; +#endif + +/**< 32 bits float types */ +typedef float Float32; + +/**< 64 bits float types */ +typedef double Float64; + +/* ------------------------------------------------------------------------------------------------ + * SHORT SQUIRREL TYPENAMES +*/ +typedef SQUnsignedInteger32 SQUint32; +typedef SQUnsignedInteger SQUint; +typedef SQInteger SQInt; + +/* ------------------------------------------------------------------------------------------------ + * STRING TYPE +*/ +typedef std::basic_string String; + +/* ------------------------------------------------------------------------------------------------ + * FORWARD DECLARATIONS +*/ + +// ------------------------------------------------------------------------------------------------ +class Core; +class Logger; + +// ------------------------------------------------------------------------------------------------ +struct AABB; +struct Circle; +struct Color3; +struct Color4; +struct Quaternion; +struct Sphere; +struct Vector2f; +struct Vector2i; +struct Vector2u; +struct Vector3; +struct Vector4; + +// ------------------------------------------------------------------------------------------------ +template < class T > class Ent; +template < class T > class EntMan; +template < class T > class Reference; + + +// ------------------------------------------------------------------------------------------------ +class CBlip; +class CCheckpoint; +class CKeybind; +class CObject; +class CPickup; +class CPlayer; +class CSphere; +class CSprite; +class CTextdraw; +class CVehicle; + +// ------------------------------------------------------------------------------------------------ +struct CAutomobile; +struct CModel; + +// ------------------------------------------------------------------------------------------------ + + +} // Namespace:: SqMod + +/* ------------------------------------------------------------------------------------------------ + * SYMBOL EXPORTING +*/ + +#if defined(_MSC_VER) + #define SQMOD_EXPORT __declspec(dllexport) + #define SQMOD_IMPORT __declspec(dllimport) +#elif defined(__GNUC__) + #define SQMOD_EXPORT __declspec(dllexport) + #define SQMOD_IMPORT __declspec(dllimport) +#endif + +#if defined(__cplusplus) + #define SQMOD_EXTERN_C extern "C" +#else + #define SQMOD_EXTERN_C /* */ +#endif + +#if defined(_MSC_VER) + #define SQMOD_API_EXPORT extern "C" __declspec(dllexport) +#elif defined(__GNUC__) + #define SQMOD_API_EXPORT extern "C" __declspec(dllexport) +#endif + +/* ------------------------------------------------------------------------------------------------ + * CALLING CONVENTIONS +*/ + +#if defined(_MSC_VER) + #define SQMOD_STDCALL __stdcall + #define SQMOD_CDECL __cdecl + #define SQMOD_FASTCALL __fastcall +#elif defined(__GNUC__) + #define SQMOD_STDCALL __attribute__((stdcall)) + #define SQMOD_CDECL /* */ + #define SQMOD_FASTCALL __attribute__((fastcall)) +#endif + +/* ------------------------------------------------------------------------------------------------ + * FUNCTION INLINING +*/ + +#if defined(_MSC_VER) + #define SQMOD_FORCEINLINE __forceinline +#elif defined(__GNUC__) + #define SQMOD_FORCEINLINE inline +#endif + +/* ------------------------------------------------------------------------------------------------ + * VARIOUS DEFINES +*/ + +#define VALID_ENTITY(e) (e >= 0) +#define INVALID_ENTITY(e) (e < 0) + +#define VALID_ENTITYEX(e, m) ((e >= 0) && (e < m)) +#define INVALID_ENTITYEX(e, m) ((e < 0) || (e >= m)) + +#define VALID_ENTITYGET(e) ((e >= 0) ? e : -1) +#define VALID_ENTITYGETEX(e, m) ((e >= 0) && (e < m) ? e : -1) + +// Character Buffer Elements Count (n = buffer bytes / char size) +#define SQMOD_CHBUFEC(n) (n / sizeof(SQChar)) +// Character Buffer Bytes Count (n = buffer chars * char size) +#define SQMOD_CHBUFBC(n) (n * sizeof(SQChar)) + +// Short notation for static casting to primitive types +#define _SCI8(v) static_cast(v) +#define _SCU8(v) static_cast(v) +#define _SCI16(v) static_cast(v) +#define _SCU16(v) static_cast(v) +#define _SCI32(v) static_cast(v) +#define _SCU32(v) static_cast(v) +#define _SCI64(v) static_cast(v) +#define _SCU64(v) static_cast(v) +#define _SCF32(v) static_cast(v) +#define _SCF64(v) static_cast(v) + +// Short notation for getting the minimum and maxmimum value of primitives +#define _NLMIN(t) std::numeric_limits::min() +#define _NLMAX(t) std::numeric_limits::max() + +/* ------------------------------------------------------------------------------------------------ + * COLOR PACKING +*/ + +#define PACK_RGB(r, g, b) (uint32)(r << 16 | g << 8 | b) +#define PACK_RGBA(r, g, b, a) (uint32)(r << 24 | g << 16 | b << 8 | a) +#define PACK_ARGB(a, r, g, b) (uint32)(a << 24 | r << 16 | g << 8 | b) + +#define PACK_RGB_TO_RGBA(r, g, b) (uint32)(r << 24 | g << 16 | b << 8 | 0) +#define PACK_RGB_TO_ARGB(r, g, b) (uint32)(0 << 24 | r << 16 | g << 8 | b) + +/* ------------------------------------------------------------------------------------------------ + * GENERAL RESPONSES +*/ + +#define SQMOD_SUCCESS 1 +#define SQMOD_FAILURE 0 +#define SQMOD_UNKNOWN -1 +#define SQMOD_TRUE 1 +#define SQMOD_FALSE 0 +#define SQMOD_NULL NULL +#define SQMOD_BLANK 0 + +/* ------------------------------------------------------------------------------------------------ + * GENERAL SERVER LIMITS +*/ + +#define SQMOD_NAMELENGTH 64 +#define SQMOD_NAMELENGTH_T 65 +#define SQMOD_UIDLENGTH 40 +#define SQMOD_UIDLENGTH_T 41 +#define SQMOD_IPADDRESS 16 +#define SQMOD_IPADDRESS_T 17 +#define SQMOD_SVNAMELENGTH 128 +#define SQMOD_PASSWDLENGTH 128 +#define SQMOD_GMNAMELENGTH 96 +#define SQMOD_MSGLENGTH 512 +#define SQMOD_CMDLENGTH 512 + +/* ------------------------------------------------------------------------------------------------ + * INITIAL ENTITY POOLS +*/ + +#define SQMOD_BLIP_POOL 128 +#define SQMOD_CHECKPOINT_POOL 2000 +#define SQMOD_KEYBIND_POOL 256 +#define SQMOD_OBJECT_POOL 3000 +#define SQMOD_PICKUP_POOL 2000 +#define SQMOD_PLAYER_POOL 100 +#define SQMOD_SPHERE_POOL 2000 +#define SQMOD_SPRITE_POOL 128 +#define SQMOD_TEXTDRAW_POOL 256 +#define SQMOD_VEHICLE_POOL 1000 + +/* ------------------------------------------------------------------------------------------------ + * ENTITY CREATE/DESTROY +*/ + +#define SQMOD_CREATE_DEFAULT 0 +#define SQMOD_CREATE_MANUAL -3 +#define SQMOD_CREATE_POOL -4 +#define SQMOD_CREATE_AUTOMATIC -5 +#define SQMOD_CREATE_OVERWRITE -6 +#define SQMOD_CREATE_RESURECT -7 + +#define SQMOD_DESTROY_DEFAULT 0 +#define SQMOD_DESTROY_MANUAL -3 +#define SQMOD_DESTROY_POOL -4 +#define SQMOD_DESTROY_AUTOMATIC -5 +#define SQMOD_DESTROY_OVERWRITE -6 +#define SQMOD_DESTROY_CLEANUP -7 + +/* ------------------------------------------------------------------------------------------------ + * MODEL ID LIMITS +*/ + +#define SQMOD_WEAPONID_MAX 71 +#define SQMOD_WEAPONID_CAP 256 +#define SQMOD_VEHICLEID_MAX 237 +#define SQMOD_VEHICLEID_CAP 512 +#define SQMOD_SKINID_MAX 160 +#define SQMOD_SKINID_CAP 256 +#define SQMOD_MODELID_MAX 640 +#define SQMOD_MODELID_CAP 2048 + +/* ------------------------------------------------------------------------------------------------ + * SCRIPT OPTIONS +*/ + +#define SQMOD_STACK_SIZE 4096 + +#ifndef NDEBUG + #define SQMOD_DEBUG_LEVEL 0 +#else + #define SQMOD_DEBUG_LEVEL 3 +#endif + +/* ------------------------------------------------------------------------------------------------ + * PLUGIN OPTIONS +*/ + +// Size of the buffer used for string formatting +#define SQMOD_SHARED_BUFFER_SZ 8192 + +/* ------------------------------------------------------------------------------------------------ + * ENTITY POOL UPDATE IDENTIFIERS +*/ +#define SQMOD_ENTITY_POOL_VEHICLE 1 +#define SQMOD_ENTITY_POOL_OBJECT 2 +#define SQMOD_ENTITY_POOL_PICKUP 3 +#define SQMOD_ENTITY_POOL_RADIO 4 +#define SQMOD_ENTITY_POOL_SPRITE 5 +#define SQMOD_ENTITY_POOL_TEXTDRAW 6 +#define SQMOD_ENTITY_POOL_BLIP 7 + +/* ------------------------------------------------------------------------------------------------ + * PLAYER STATE IDENTIFIERS +*/ +#define SQMOD_PLAYER_STATE_NONE 0 +#define SQMOD_PLAYER_STATE_NORMAL 1 +#define SQMOD_PLAYER_STATE_SHOOTING 2 +#define SQMOD_PLAYER_STATE_DRIVER 3 +#define SQMOD_PLAYER_STATE_PASSENGER 4 +#define SQMOD_PLAYER_STATE_ENTERING_AS_DRIVER 5 +#define SQMOD_PLAYER_STATE_ENTERING_AS_PASSENGER 6 +#define SQMOD_PLAYER_STATE_EXITING_VEHICLE 7 +#define SQMOD_PLAYER_STATE_UNSPAWNED 8 + +/* ------------------------------------------------------------------------------------------------ + * PLAYER ACTION IDENTIFIERS +*/ +#define SQMOD_PLAYER_ACTION_NONE 0 +#define SQMOD_PLAYER_ACTION_NORMAL 1 +#define SQMOD_PLAYER_ACTION_AIMING 12 +#define SQMOD_PLAYER_ACTION_SHOOTING 16 +#define SQMOD_PLAYER_ACTION_JUMPING 41 +#define SQMOD_PLAYER_ACTION_LYING_ON_GROUND 42 +#define SQMOD_PLAYER_ACTION_GETTING_UP 43 +#define SQMOD_PLAYER_ACTION_JUMPING_FROM_VEHICLE 44 +#define SQMOD_PLAYER_ACTION_DRIVING 50 +#define SQMOD_PLAYER_ACTION_DYING 54 +#define SQMOD_PLAYER_ACTION_WASTED 55 +#define SQMOD_PLAYER_ACTION_ENTERING_VEHICLE 58 +#define SQMOD_PLAYER_ACTION_EXITING_VEHICLE 60 + +/* ------------------------------------------------------------------------------------------------ + * VEHICLE UPDATE IDENTIFIERS +*/ +#define SQMOD_VEHICLEUPD_DRIVER 0 +#define SQMOD_VEHICLEUPD_OTHER 1 + +/* ------------------------------------------------------------------------------------------------ + * PLAYER UPDATE IDENTIFIERS +*/ +#define SQMOD_PLAYERUPD_ONFOOT 0 +#define SQMOD_PLAYERUPD_AIM 1 +#define SQMOD_PLAYERUPD_DRIVER 2 +#define SQMOD_PLAYERUPD_PASSENGER 3 + +/* ------------------------------------------------------------------------------------------------ + * PART REASON IDENTIFIERS +*/ +#define SQMOD_PARTREASON_TIMEOUT 0 +#define SQMOD_PARTREASON_DISCONNECTED 1 +#define SQMOD_PARTREASON_KICKEDBANNED 2 +#define SQMOD_PARTREASON_CRASHED 3 + +/* ------------------------------------------------------------------------------------------------ + * BODY PART IDENTIFIERS +*/ +#define SQMOD_BODYPART_BODY 0 +#define SQMOD_BODYPART_TORSO 1 +#define SQMOD_BODYPART_LEFTARM 2 +#define SQMOD_BODYPART_RIGHTARM 3 +#define SQMOD_BODYPART_LEFTLEG 4 +#define SQMOD_BODYPART_RIGHTLEG 5 +#define SQMOD_BODYPART_HEAD 6 + +/* ------------------------------------------------------------------------------------------------ + * WEATHER IDENTIFIERS +*/ +#define SQMOD_WEATHER_MOSTLYCLEAR 0 +#define SQMOD_WEATHER_OVERCAST 1 +#define SQMOD_WEATHER_THUNDERSTORM 2 +#define SQMOD_WEATHER_STORM 2 +#define SQMOD_WEATHER_STORMY 2 +#define SQMOD_WEATHER_FOGGY 3 +#define SQMOD_WEATHER_FOG 3 +#define SQMOD_WEATHER_CLEAR 4 +#define SQMOD_WEATHER_SUNNY 4 +#define SQMOD_WEATHER_RAIN 5 +#define SQMOD_WEATHER_RAINY 5 +#define SQMOD_WEATHER_DARKCLOUDY 6 +#define SQMOD_WEATHER_LIGHTCLOUDY 7 +#define SQMOD_WEATHER_OVERCASTCLOUDY 8 +#define SQMOD_WEATHER_BLACKCLOUDS 9 + + +/* ------------------------------------------------------------------------------------------------ + * WEAPON IDENTIFIERS +*/ +#define SQMOD_WEAPON_UNARMED 0 +#define SQMOD_WEAPON_BRASSKNUCKLES 1 +#define SQMOD_WEAPON_SCREWDRIVER 2 +#define SQMOD_WEAPON_GOLFCLUB 3 +#define SQMOD_WEAPON_NIGHTSTICK 4 +#define SQMOD_WEAPON_KNIFE 5 +#define SQMOD_WEAPON_BASEBALLBAT 6 +#define SQMOD_WEAPON_HAMMER 7 +#define SQMOD_WEAPON_MEATCLEAVER 8 +#define SQMOD_WEAPON_MACHETE 9 +#define SQMOD_WEAPON_KATANA 10 +#define SQMOD_WEAPON_CHAINSAW 11 +#define SQMOD_WEAPON_GRENADE 12 +#define SQMOD_WEAPON_REMOTE 13 +#define SQMOD_WEAPON_TEARGAS 14 +#define SQMOD_WEAPON_MOLOTOV 15 +#define SQMOD_WEAPON_ROCKET 16 +#define SQMOD_WEAPON_COLT45 17 +#define SQMOD_WEAPON_PYTHON 18 +#define SQMOD_WEAPON_SHOTGUN 19 +#define SQMOD_WEAPON_SPAS12 20 +#define SQMOD_WEAPON_STUBBY 21 +#define SQMOD_WEAPON_TEC9 22 +#define SQMOD_WEAPON_UZI 23 +#define SQMOD_WEAPON_INGRAM 24 +#define SQMOD_WEAPON_MP5 25 +#define SQMOD_WEAPON_M4 26 +#define SQMOD_WEAPON_RUGER 27 +#define SQMOD_WEAPON_SNIPER 28 +#define SQMOD_WEAPON_LASERSCOPE 29 +#define SQMOD_WEAPON_ROCKETLAUNCHER 30 +#define SQMOD_WEAPON_FLAMETHROWER 31 +#define SQMOD_WEAPON_M60 32 +#define SQMOD_WEAPON_MINIGUN 33 +#define SQMOD_WEAPON_BOMB 34 +#define SQMOD_WEAPON_HELICANNON 35 +#define SQMOD_WEAPON_CAMERA 36 +#define SQMOD_WEAPON_VEHICLE 39 +#define SQMOD_WEAPON_EXPLOSION1 41 +#define SQMOD_WEAPON_DRIVEBY 42 +#define SQMOD_WEAPON_DROWNED 43 +#define SQMOD_WEAPON_FALL 44 +#define SQMOD_WEAPON_EXPLOSION2 51 +#define SQMOD_WEAPON_SUICIDE 70 + +/* ------------------------------------------------------------------------------------------------ + * VEHICLE IDENTIFIERS +*/ +#define SQMOD_VEHICLE_LANDSTALKER 130 +#define SQMOD_VEHICLE_IDAHO 131 +#define SQMOD_VEHICLE_STINGER 132 +#define SQMOD_VEHICLE_LINERUNNER 133 +#define SQMOD_VEHICLE_PERENNIAL 134 +#define SQMOD_VEHICLE_SENTINEL 135 +#define SQMOD_VEHICLE_RIO 136 +#define SQMOD_VEHICLE_FIRETRUCK 137 +#define SQMOD_VEHICLE_TRASHMASTER 138 +#define SQMOD_VEHICLE_STRETCH 139 +#define SQMOD_VEHICLE_MANANA 140 +#define SQMOD_VEHICLE_INFERNUS 141 +#define SQMOD_VEHICLE_VOODOO 142 +#define SQMOD_VEHICLE_PONY 143 +#define SQMOD_VEHICLE_MULE 144 +#define SQMOD_VEHICLE_CHEETAH 145 +#define SQMOD_VEHICLE_AMBULANCE 146 +#define SQMOD_VEHICLE_FBIWASHINGTON 147 +#define SQMOD_VEHICLE_MOONBEAM 148 +#define SQMOD_VEHICLE_ESPERANTO 149 +#define SQMOD_VEHICLE_TAXI 150 +#define SQMOD_VEHICLE_WASHINGTON 151 +#define SQMOD_VEHICLE_BOBCAT 152 +#define SQMOD_VEHICLE_MRWHOOPEE 153 +#define SQMOD_VEHICLE_BFINJECTION 154 +#define SQMOD_VEHICLE_HUNTER 155 +#define SQMOD_VEHICLE_POLICE 156 +#define SQMOD_VEHICLE_ENFORCER 157 +#define SQMOD_VEHICLE_SECURICAR 158 +#define SQMOD_VEHICLE_BANSHEE 159 +#define SQMOD_VEHICLE_PREDATOR 160 +#define SQMOD_VEHICLE_BUS 161 +#define SQMOD_VEHICLE_RHINO 162 +#define SQMOD_VEHICLE_BARRACKSOL 163 +#define SQMOD_VEHICLE_BARRACKS 163 +#define SQMOD_VEHICLE_CUBANHERMES 164 +#define SQMOD_VEHICLE_HELICOPTER 165 +#define SQMOD_VEHICLE_ANGEL 166 +#define SQMOD_VEHICLE_COACH 167 +#define SQMOD_VEHICLE_CABBIE 168 +#define SQMOD_VEHICLE_STALLION 169 +#define SQMOD_VEHICLE_RUMPO 170 +#define SQMOD_VEHICLE_RCBANDIT 171 +#define SQMOD_VEHICLE_HEARSE 172 +#define SQMOD_VEHICLE_PACKER 173 +#define SQMOD_VEHICLE_SENTINELXS 174 +#define SQMOD_VEHICLE_ADMIRAL 175 +#define SQMOD_VEHICLE_SQUALO 176 +#define SQMOD_VEHICLE_SEASPARROW 177 +#define SQMOD_VEHICLE_PIZZABOY 178 +#define SQMOD_VEHICLE_GANGBURRITO 179 +#define SQMOD_VEHICLE_AIRTRAIN 180 +#define SQMOD_VEHICLE_DEADDODO 181 +#define SQMOD_VEHICLE_SPEEDER 182 +#define SQMOD_VEHICLE_REEFER 183 +#define SQMOD_VEHICLE_TROPIC 184 +#define SQMOD_VEHICLE_FLATBED 185 +#define SQMOD_VEHICLE_YANKEE 186 +#define SQMOD_VEHICLE_CADDY 187 +#define SQMOD_VEHICLE_ZEBRA 188 +#define SQMOD_VEHICLE_ZEBRACAB 188 +#define SQMOD_VEHICLE_TOPFUN 189 +#define SQMOD_VEHICLE_SKIMMER 190 +#define SQMOD_VEHICLE_PCJ600 191 +#define SQMOD_VEHICLE_PCJ 191 +#define SQMOD_VEHICLE_FAGGIO 192 +#define SQMOD_VEHICLE_FREEWAY 193 +#define SQMOD_VEHICLE_RCBARON 194 +#define SQMOD_VEHICLE_RCRAIDER 195 +#define SQMOD_VEHICLE_GLENDALE 196 +#define SQMOD_VEHICLE_OCEANIC 197 +#define SQMOD_VEHICLE_SANCHEZ 198 +#define SQMOD_VEHICLE_SPARROW 199 +#define SQMOD_VEHICLE_PATRIOT 200 +#define SQMOD_VEHICLE_LOVEFIST 201 +#define SQMOD_VEHICLE_COASTGUARD 202 +#define SQMOD_VEHICLE_DINGHY 203 +#define SQMOD_VEHICLE_HERMES 204 +#define SQMOD_VEHICLE_SABRE 205 +#define SQMOD_VEHICLE_SABRETURBO 206 +#define SQMOD_VEHICLE_PHOENIX 207 +#define SQMOD_VEHICLE_WALTON 208 +#define SQMOD_VEHICLE_REGINA 209 +#define SQMOD_VEHICLE_COMET 210 +#define SQMOD_VEHICLE_DELUXO 211 +#define SQMOD_VEHICLE_BURRITO 212 +#define SQMOD_VEHICLE_SPANDEX 213 +#define SQMOD_VEHICLE_SPANDEXPRESS 213 +#define SQMOD_VEHICLE_MARQUIS 214 +#define SQMOD_VEHICLE_BAGGAGE 215 +#define SQMOD_VEHICLE_BAGGAGEHANDLER 215 +#define SQMOD_VEHICLE_KAUFMAN 216 +#define SQMOD_VEHICLE_KAUFMANCAB 216 +#define SQMOD_VEHICLE_MAVERICK 217 +#define SQMOD_VEHICLE_VCNMAVERICK 218 +#define SQMOD_VEHICLE_RANCHER 219 +#define SQMOD_VEHICLE_FBIRANCHER 220 +#define SQMOD_VEHICLE_VIRGO 221 +#define SQMOD_VEHICLE_GREENWOOD 222 +#define SQMOD_VEHICLE_CUBANJETMAX 223 +#define SQMOD_VEHICLE_HOTRING1 224 +#define SQMOD_VEHICLE_HOTRINGRACER1 224 +#define SQMOD_VEHICLE_SANDKING 225 +#define SQMOD_VEHICLE_BLISTA 226 +#define SQMOD_VEHICLE_BLISTAC 226 +#define SQMOD_VEHICLE_BLISTACOMPACT 226 +#define SQMOD_VEHICLE_COMPACT 226 +#define SQMOD_VEHICLE_POLICEMAV 227 +#define SQMOD_VEHICLE_POLICEMAVERICK 227 +#define SQMOD_VEHICLE_BOXVILLE 228 +#define SQMOD_VEHICLE_BENSON 229 +#define SQMOD_VEHICLE_MESA 230 +#define SQMOD_VEHICLE_MESAGRANDE 230 +#define SQMOD_VEHICLE_RCGOBLIN 231 +#define SQMOD_VEHICLE_HOTRING2 232 +#define SQMOD_VEHICLE_HOTRINGRACER2 232 +#define SQMOD_VEHICLE_HOTRING3 233 +#define SQMOD_VEHICLE_HOTRINGRACER3 233 +#define SQMOD_VEHICLE_BLOODRING1 234 +#define SQMOD_VEHICLE_BLOODRINGBANGER1 234 +#define SQMOD_VEHICLE_BLOODRING2 235 +#define SQMOD_VEHICLE_BLOODRINGBANGER2 235 +#define SQMOD_VEHICLE_VICECHEE 236 +#define SQMOD_VEHICLE_POLICECHEETAH 236 +#define SQMOD_VEHICLE_FBICHEETAH 236 +#define SQMOD_VEHICLE_CHEETAH2 236 + +/* ------------------------------------------------------------------------------------------------ + * SKIN IDENTIFIERS +*/ +#define SQMOD_SKIN_TOMMY_VERCETTI 0 +#define SQMOD_SKIN_COP 1 +#define SQMOD_SKIN_SWAT 2 +#define SQMOD_SKIN_FBI 3 +#define SQMOD_SKIN_ARMY 4 +#define SQMOD_SKIN_PARAMEDIC 5 +#define SQMOD_SKIN_FIREMAN 6 +#define SQMOD_SKIN_GOLF_GUY_A 7 +#define SQMOD_SKIN_BUM_LADY_A 9 +#define SQMOD_SKIN_BUM_LADY_B 10 +#define SQMOD_SKIN_PUNK_A 11 +#define SQMOD_SKIN_LAWYER 12 +#define SQMOD_SKIN_SPANISH_LADY_A 13 +#define SQMOD_SKIN_SPANISH_LADY_B 14 +#define SQMOD_SKIN_COOL_GUY_A 15 +#define SQMOD_SKIN_ARABIC_GUY 16 +#define SQMOD_SKIN_BEACH_LADY_A 17 +#define SQMOD_SKIN_BEACH_LADY_B 18 +#define SQMOD_SKIN_BEACH_GUY_A 19 +#define SQMOD_SKIN_BEACH_GUY_B 20 +#define SQMOD_SKIN_OFFICE_LADY_A 21 +#define SQMOD_SKIN_WAITRESS_A 22 +#define SQMOD_SKIN_FOOD_LADY 23 +#define SQMOD_SKIN_PROSTITUTE_A 24 +#define SQMOD_SKIN_BUM_LADY_C 25 +#define SQMOD_SKIN_BUM_GUY_A 26 +#define SQMOD_SKIN_GARBAGEMAN_A 27 +#define SQMOD_SKIN_TAXI_DRIVER_A 28 +#define SQMOD_SKIN_HATIAN_A 29 +#define SQMOD_SKIN_CRIMINAL_A 30 +#define SQMOD_SKIN_HOOD_LADY 31 +#define SQMOD_SKIN_GRANNY_A 32 +#define SQMOD_SKIN_BUSINESS_MAN_A 33 +#define SQMOD_SKIN_CHURCH_GUY 34 +#define SQMOD_SKIN_CLUB_LADY 35 +#define SQMOD_SKIN_CHURCH_LADY 36 +#define SQMOD_SKIN_PIMP 37 +#define SQMOD_SKIN_BEACH_LADY_C 38 +#define SQMOD_SKIN_BEACH_GUY_C 39 +#define SQMOD_SKIN_BEACH_LADY_D 40 +#define SQMOD_SKIN_BEACH_GUY_D 41 +#define SQMOD_SKIN_BUSINESS_MAN_B 42 +#define SQMOD_SKIN_PROSTITUTE_B 43 +#define SQMOD_SKIN_BUM_LADY_D 44 +#define SQMOD_SKIN_BUM_GUY_B 45 +#define SQMOD_SKIN_HATIAN_B 46 +#define SQMOD_SKIN_CONSTRUCTION_WORKER_A 47 +#define SQMOD_SKIN_PUNK_B 48 +#define SQMOD_SKIN_PROSTITUTE_C 49 +#define SQMOD_SKIN_GRANNY_B 50 +#define SQMOD_SKIN_PUNK_C 51 +#define SQMOD_SKIN_BUSINESS_MAN_C 52 +#define SQMOD_SKIN_SPANISH_LADY_C 53 +#define SQMOD_SKIN_SPANISH_LADY_D 54 +#define SQMOD_SKIN_COOL_GUY_B 55 +#define SQMOD_SKIN_BUSINESS_MAN_D 56 +#define SQMOD_SKIN_BEACH_LADY_E 57 +#define SQMOD_SKIN_BEACH_GUY_E 58 +#define SQMOD_SKIN_BEACH_LADY_F 59 +#define SQMOD_SKIN_BEACH_GUY_F 60 +#define SQMOD_SKIN_CONSTRUCTION_WORKER_B 61 +#define SQMOD_SKIN_GOLF_GUY_B 62 +#define SQMOD_SKIN_GOLF_LADY 63 +#define SQMOD_SKIN_GOLF_GUY_C 64 +#define SQMOD_SKIN_BEACH_LADY_G 65 +#define SQMOD_SKIN_BEACH_GUY_G 66 +#define SQMOD_SKIN_OFFICE_LADY_B 67 +#define SQMOD_SKIN_BUSINESS_MAN_E 68 +#define SQMOD_SKIN_BUSINESS_MAN_F 69 +#define SQMOD_SKIN_PROSTITUTE_D 70 +#define SQMOD_SKIN_BUM_LADY_E 71 +#define SQMOD_SKIN_BUM_GUY_C 72 +#define SQMOD_SKIN_SPANISH_GUY 73 +#define SQMOD_SKIN_TAXI_DRIVER_B 74 +#define SQMOD_SKIN_GYM_LADY 75 +#define SQMOD_SKIN_GYM_GUY 76 +#define SQMOD_SKIN_SKATE_LADY 77 +#define SQMOD_SKIN_SKATE_GUY 78 +#define SQMOD_SKIN_SHOPPER_A 79 +#define SQMOD_SKIN_SHOPPER_B 80 +#define SQMOD_SKIN_TOURIST_A 81 +#define SQMOD_SKIN_TOURIST_B 82 +#define SQMOD_SKIN_CUBAN_A 83 +#define SQMOD_SKIN_CUBAN_B 84 +#define SQMOD_SKIN_HATIAN_C 85 +#define SQMOD_SKIN_HATIAN_D 86 +#define SQMOD_SKIN_SHARK_A 87 +#define SQMOD_SKIN_SHARK_B 88 +#define SQMOD_SKIN_DIAZ_GUY_A 89 +#define SQMOD_SKIN_DIAZ_GUY_B 90 +#define SQMOD_SKIN_DBP_SECURITY_A 91 +#define SQMOD_SKIN_DBP_SECURITY_B 92 +#define SQMOD_SKIN_BIKER_A 93 +#define SQMOD_SKIN_BIKER_B 94 +#define SQMOD_SKIN_VERCETTI_GUY_A 95 +#define SQMOD_SKIN_VERCETTI_GUY_B 96 +#define SQMOD_SKIN_UNDERCOVER_COP_A 97 +#define SQMOD_SKIN_UNDERCOVER_COP_B 98 +#define SQMOD_SKIN_UNDERCOVER_COP_C 99 +#define SQMOD_SKIN_UNDERCOVER_COP_D 100 +#define SQMOD_SKIN_UNDERCOVER_COP_E 101 +#define SQMOD_SKIN_UNDERCOVER_COP_F 102 +#define SQMOD_SKIN_RICH_GUY 103 +#define SQMOD_SKIN_COOL_GUY_C 104 +#define SQMOD_SKIN_PROSTITUTE_E 105 +#define SQMOD_SKIN_PROSTITUTE_F 106 +#define SQMOD_SKIN_LOVE_FIST_A 107 +#define SQMOD_SKIN_KEN_ROSENBURG 108 +#define SQMOD_SKIN_CANDY_SUXX 109 +#define SQMOD_SKIN_HILARY 110 +#define SQMOD_SKIN_LOVE_FIST_B 111 +#define SQMOD_SKIN_PHIL 112 +#define SQMOD_SKIN_ROCKSTAR_GUY 113 +#define SQMOD_SKIN_SONNY 114 +#define SQMOD_SKIN_LANCE_A 115 +#define SQMOD_SKIN_MERCADES_A 116 +#define SQMOD_SKIN_LOVE_FIST_C 117 +#define SQMOD_SKIN_ALEX_SRUB 118 +#define SQMOD_SKIN_LANCE_COP 119 +#define SQMOD_SKIN_LANCE_B 120 +#define SQMOD_SKIN_CORTEZ 121 +#define SQMOD_SKIN_LOVE_FIST_D 122 +#define SQMOD_SKIN_COLUMBIAN_GUY_A 123 +#define SQMOD_SKIN_HILARY_ROBBER 124 +#define SQMOD_SKIN_MERCADES_B 125 +#define SQMOD_SKIN_CAM 126 +#define SQMOD_SKIN_CAM_ROBBER 127 +#define SQMOD_SKIN_PHIL_ONE_ARM 128 +#define SQMOD_SKIN_PHIL_ROBBER 129 +#define SQMOD_SKIN_COOL_GUY_D 130 +#define SQMOD_SKIN_PIZZAMAN 131 +#define SQMOD_SKIN_TAXI_DRIVER_C 132 +#define SQMOD_SKIN_TAXI_DRIVER_D 133 +#define SQMOD_SKIN_SAILOR_A 134 +#define SQMOD_SKIN_SAILOR_B 135 +#define SQMOD_SKIN_SAILOR_C 136 +#define SQMOD_SKIN_CHEF 137 +#define SQMOD_SKIN_CRIMINAL_B 138 +#define SQMOD_SKIN_FRENCH_GUY 139 +#define SQMOD_SKIN_GARBAGEMAN_B 140 +#define SQMOD_SKIN_HATIAN_E 141 +#define SQMOD_SKIN_WAITRESS_B 142 +#define SQMOD_SKIN_SONNY_GUY_A 143 +#define SQMOD_SKIN_SONNY_GUY_B 144 +#define SQMOD_SKIN_SONNY_GUY_C 145 +#define SQMOD_SKIN_COLUMBIAN_GUY_B 146 +#define SQMOD_SKIN_THUG_A 147 +#define SQMOD_SKIN_BEACH_GUY_H 148 +#define SQMOD_SKIN_GARBAGEMAN_C 149 +#define SQMOD_SKIN_GARBAGEMAN_D 150 +#define SQMOD_SKIN_GARBAGEMAN_E 151 +#define SQMOD_SKIN_TRANNY 152 +#define SQMOD_SKIN_THUG_B 153 +#define SQMOD_SKIN_SPANDEX_GUY_A 154 +#define SQMOD_SKIN_SPANDEX_GUY_B 155 +#define SQMOD_SKIN_STRIPPER_A 156 +#define SQMOD_SKIN_STRIPPER_B 157 +#define SQMOD_SKIN_STRIPPER_C 158 +#define SQMOD_SKIN_STORE_CLERK 159 + +/* ------------------------------------------------------------------------------------------------ + * KEYBOARD CODES +*/ +#define SQMOD_KEYCODE_ABNT_C1 0xC1 +#define SQMOD_KEYCODE_ABNT_C2 0xC2 +#define SQMOD_KEYCODE_ADD 0x6B +#define SQMOD_KEYCODE_ATTN 0xF6 +#define SQMOD_KEYCODE_BACK 0x08 +#define SQMOD_KEYCODE_CANCEL 0x03 +#define SQMOD_KEYCODE_CLEAR 0x0C +#define SQMOD_KEYCODE_CRSEL 0xF7 +#define SQMOD_KEYCODE_DECIMAL 0x6E +#define SQMOD_KEYCODE_DIVIDE 0x6F +#define SQMOD_KEYCODE_EREOF 0xF9 +#define SQMOD_KEYCODE_ESCAPE 0x1B +#define SQMOD_KEYCODE_EXECUTE 0x2B +#define SQMOD_KEYCODE_EXSEL 0xF8 +#define SQMOD_KEYCODE_ICO_CLEAR 0xE6 +#define SQMOD_KEYCODE_ICO_HELP 0xE3 +#define SQMOD_KEYCODE_KEY_0 0x30 +#define SQMOD_KEYCODE_KEY_1 0x31 +#define SQMOD_KEYCODE_KEY_2 0x32 +#define SQMOD_KEYCODE_KEY_3 0x33 +#define SQMOD_KEYCODE_KEY_4 0x34 +#define SQMOD_KEYCODE_KEY_5 0x35 +#define SQMOD_KEYCODE_KEY_6 0x36 +#define SQMOD_KEYCODE_KEY_7 0x37 +#define SQMOD_KEYCODE_KEY_8 0x38 +#define SQMOD_KEYCODE_KEY_9 0x39 +#define SQMOD_KEYCODE_KEY_A 0x41 +#define SQMOD_KEYCODE_KEY_B 0x42 +#define SQMOD_KEYCODE_KEY_C 0x43 +#define SQMOD_KEYCODE_KEY_D 0x44 +#define SQMOD_KEYCODE_KEY_E 0x45 +#define SQMOD_KEYCODE_KEY_F 0x46 +#define SQMOD_KEYCODE_KEY_G 0x47 +#define SQMOD_KEYCODE_KEY_H 0x48 +#define SQMOD_KEYCODE_KEY_I 0x49 +#define SQMOD_KEYCODE_KEY_J 0x4A +#define SQMOD_KEYCODE_KEY_K 0x4B +#define SQMOD_KEYCODE_KEY_L 0x4C +#define SQMOD_KEYCODE_KEY_M 0x4D +#define SQMOD_KEYCODE_KEY_N 0x4E +#define SQMOD_KEYCODE_KEY_O 0x4F +#define SQMOD_KEYCODE_KEY_P 0x50 +#define SQMOD_KEYCODE_KEY_Q 0x51 +#define SQMOD_KEYCODE_KEY_R 0x52 +#define SQMOD_KEYCODE_KEY_S 0x53 +#define SQMOD_KEYCODE_KEY_T 0x54 +#define SQMOD_KEYCODE_KEY_U 0x55 +#define SQMOD_KEYCODE_KEY_V 0x56 +#define SQMOD_KEYCODE_KEY_W 0x57 +#define SQMOD_KEYCODE_KEY_X 0x58 +#define SQMOD_KEYCODE_KEY_Y 0x59 +#define SQMOD_KEYCODE_KEY_Z 0x5A +#define SQMOD_KEYCODE_MULTIPLY 0x6A +#define SQMOD_KEYCODE_NONAME 0xFC +#define SQMOD_KEYCODE_NUMPAD0 0x60 +#define SQMOD_KEYCODE_NUMPAD1 0x61 +#define SQMOD_KEYCODE_NUMPAD2 0x62 +#define SQMOD_KEYCODE_NUMPAD3 0x63 +#define SQMOD_KEYCODE_NUMPAD4 0x64 +#define SQMOD_KEYCODE_NUMPAD5 0x65 +#define SQMOD_KEYCODE_NUMPAD6 0x66 +#define SQMOD_KEYCODE_NUMPAD7 0x67 +#define SQMOD_KEYCODE_NUMPAD8 0x68 +#define SQMOD_KEYCODE_NUMPAD9 0x69 +#define SQMOD_KEYCODE_OEM_1 0xBA +#define SQMOD_KEYCODE_OEM_102 0xE2 +#define SQMOD_KEYCODE_OEM_2 0xBF +#define SQMOD_KEYCODE_OEM_3 0xC0 +#define SQMOD_KEYCODE_OEM_4 0xDB +#define SQMOD_KEYCODE_OEM_5 0xDC +#define SQMOD_KEYCODE_OEM_6 0xDD +#define SQMOD_KEYCODE_OEM_7 0xDE +#define SQMOD_KEYCODE_OEM_8 0xDF +#define SQMOD_KEYCODE_OEM_ATTN 0xF0 +#define SQMOD_KEYCODE_OEM_AUTO 0xF3 +#define SQMOD_KEYCODE_OEM_AX 0xE1 +#define SQMOD_KEYCODE_OEM_BACKTAB 0xF5 +#define SQMOD_KEYCODE_OEM_CLEAR 0xFE +#define SQMOD_KEYCODE_OEM_COMMA 0xBC +#define SQMOD_KEYCODE_OEM_COPY 0xF2 +#define SQMOD_KEYCODE_OEM_CUSEL 0xEF +#define SQMOD_KEYCODE_OEM_ENLW 0xF4 +#define SQMOD_KEYCODE_OEM_FINISH 0xF1 +#define SQMOD_KEYCODE_OEM_FJ_LOYA 0x95 +#define SQMOD_KEYCODE_OEM_FJ_MASSHOU 0x93 +#define SQMOD_KEYCODE_OEM_FJ_ROYA 0x96 +#define SQMOD_KEYCODE_OEM_FJ_TOUROKU 0x94 +#define SQMOD_KEYCODE_OEM_JUMP 0xEA +#define SQMOD_KEYCODE_OEM_MINUS 0xBD +#define SQMOD_KEYCODE_OEM_PA1 0xEB +#define SQMOD_KEYCODE_OEM_PA2 0xEC +#define SQMOD_KEYCODE_OEM_PA3 0xED +#define SQMOD_KEYCODE_OEM_PERIOD 0xBE +#define SQMOD_KEYCODE_OEM_PLUS 0xBB +#define SQMOD_KEYCODE_OEM_RESET 0xE9 +#define SQMOD_KEYCODE_OEM_WSCTRL 0xEE +#define SQMOD_KEYCODE_PA1 0xFD +#define SQMOD_KEYCODE_PACKET 0xE7 +#define SQMOD_KEYCODE_PLAY 0xFA +#define SQMOD_KEYCODE_PROCESSKEY 0xE5 +#define SQMOD_KEYCODE_RETURN 0x0D +#define SQMOD_KEYCODE_SELECT 0x29 +#define SQMOD_KEYCODE_SEPARATOR 0x6C +#define SQMOD_KEYCODE_SPACE 0x20 +#define SQMOD_KEYCODE_SUBTRACT 0x6D +#define SQMOD_KEYCODE_TAB 0x09 +#define SQMOD_KEYCODE_ZOOM 0xFB +#define SQMOD_KEYCODE_ACCEPT 0x1E +#define SQMOD_KEYCODE_APPS 0x5D +#define SQMOD_KEYCODE_BROWSER_BACK 0xA6 +#define SQMOD_KEYCODE_BROWSER_FAVORITES 0xAB +#define SQMOD_KEYCODE_BROWSER_FORWARD 0xA7 +#define SQMOD_KEYCODE_BROWSER_HOME 0xAC +#define SQMOD_KEYCODE_BROWSER_REFRESH 0xA8 +#define SQMOD_KEYCODE_BROWSER_SEARCH 0xAA +#define SQMOD_KEYCODE_BROWSER_STOP 0xA9 +#define SQMOD_KEYCODE_CAPITAL 0x14 +#define SQMOD_KEYCODE_CONVERT 0x1C +#define SQMOD_KEYCODE_DELETE 0x2E +#define SQMOD_KEYCODE_DOWN 0x28 +#define SQMOD_KEYCODE_END 0x23 +#define SQMOD_KEYCODE_F1 0x70 +#define SQMOD_KEYCODE_F10 0x79 +#define SQMOD_KEYCODE_F11 0x7A +#define SQMOD_KEYCODE_F12 0x7B +#define SQMOD_KEYCODE_F13 0x7C +#define SQMOD_KEYCODE_F14 0x7D +#define SQMOD_KEYCODE_F15 0x7E +#define SQMOD_KEYCODE_F16 0x7F +#define SQMOD_KEYCODE_F17 0x80 +#define SQMOD_KEYCODE_F18 0x81 +#define SQMOD_KEYCODE_F19 0x82 +#define SQMOD_KEYCODE_F2 0x71 +#define SQMOD_KEYCODE_F20 0x83 +#define SQMOD_KEYCODE_F21 0x84 +#define SQMOD_KEYCODE_F22 0x85 +#define SQMOD_KEYCODE_F23 0x86 +#define SQMOD_KEYCODE_F24 0x87 +#define SQMOD_KEYCODE_F3 0x72 +#define SQMOD_KEYCODE_F4 0x73 +#define SQMOD_KEYCODE_F5 0x74 +#define SQMOD_KEYCODE_F6 0x75 +#define SQMOD_KEYCODE_F7 0x76 +#define SQMOD_KEYCODE_F8 0x77 +#define SQMOD_KEYCODE_F9 0x78 +#define SQMOD_KEYCODE_FINAL 0x18 +#define SQMOD_KEYCODE_HELP 0x2F +#define SQMOD_KEYCODE_HOME 0x24 +#define SQMOD_KEYCODE_ICO_00 0xE4 +#define SQMOD_KEYCODE_INSERT 0x2D +#define SQMOD_KEYCODE_JUNJA 0x17 +#define SQMOD_KEYCODE_KANA 0x15 +#define SQMOD_KEYCODE_KANJI 0x19 +#define SQMOD_KEYCODE_LAUNCH_APP1 0xB6 +#define SQMOD_KEYCODE_LAUNCH_APP2 0xB7 +#define SQMOD_KEYCODE_LAUNCH_MAIL 0xB4 +#define SQMOD_KEYCODE_LAUNCH_MEDIA_SELECT 0xB5 +#define SQMOD_KEYCODE_LBUTTON 0x01 +#define SQMOD_KEYCODE_LCONTROL 0xA2 +#define SQMOD_KEYCODE_LEFT 0x25 +#define SQMOD_KEYCODE_LMENU 0xA4 +#define SQMOD_KEYCODE_LSHIFT 0xA0 +#define SQMOD_KEYCODE_LWIN 0x5B +#define SQMOD_KEYCODE_MBUTTON 0x04 +#define SQMOD_KEYCODE_MEDIA_NEXT_TRACK 0xB0 +#define SQMOD_KEYCODE_MEDIA_PLAY_PAUSE 0xB3 +#define SQMOD_KEYCODE_MEDIA_PREV_TRACK 0xB1 +#define SQMOD_KEYCODE_MEDIA_STOP 0xB2 +#define SQMOD_KEYCODE_MODECHANGE 0x1F +#define SQMOD_KEYCODE_NEXT 0x22 +#define SQMOD_KEYCODE_NONCONVERT 0x1D +#define SQMOD_KEYCODE_NUMLOCK 0x90 +#define SQMOD_KEYCODE_OEM_FJ_JISHO 0x92 +#define SQMOD_KEYCODE_PAUSE 0x13 +#define SQMOD_KEYCODE_PRINT 0x2A +#define SQMOD_KEYCODE_PRIOR 0x21 +#define SQMOD_KEYCODE_RBUTTON 0x02 +#define SQMOD_KEYCODE_RCONTROL 0xA3 +#define SQMOD_KEYCODE_RIGHT 0x27 +#define SQMOD_KEYCODE_RMENU 0xA5 +#define SQMOD_KEYCODE_RSHIFT 0xA1 +#define SQMOD_KEYCODE_RWIN 0x5C +#define SQMOD_KEYCODE_SCROLL 0x91 +#define SQMOD_KEYCODE_SLEEP 0x5F +#define SQMOD_KEYCODE_SNAPSHOT 0x2C +#define SQMOD_KEYCODE_UP 0x26 +#define SQMOD_KEYCODE_VOLUME_DOWN 0xAE +#define SQMOD_KEYCODE_VOLUME_MUTE 0xAD +#define SQMOD_KEYCODE_VOLUME_UP 0xAF +#define SQMOD_KEYCODE_XBUTTON1 0x05 +#define SQMOD_KEYCODE_XBUTTON2 0x06 +#define SQMOD_KEYCODE_NONE 0xFF + +/* ------------------------------------------------------------------------------------------------ + * ASCII CHARACTER CODES +*/ +#define SQMOD_ASCII_NUL 0 +#define SQMOD_ASCII_SOH 1 +#define SQMOD_ASCII_STX 2 +#define SQMOD_ASCII_ETX 3 +#define SQMOD_ASCII_EOT 4 +#define SQMOD_ASCII_ENQ 5 +#define SQMOD_ASCII_ACK 6 +#define SQMOD_ASCII_BEL 7 +#define SQMOD_ASCII_BS 8 +#define SQMOD_ASCII_TAB 9 +#define SQMOD_ASCII_LF 10 +#define SQMOD_ASCII_VT 11 +#define SQMOD_ASCII_FF 12 +#define SQMOD_ASCII_CR 13 +#define SQMOD_ASCII_SO 14 +#define SQMOD_ASCII_SI 15 +#define SQMOD_ASCII_DLE 16 +#define SQMOD_ASCII_DC1 17 +#define SQMOD_ASCII_DC2 18 +#define SQMOD_ASCII_DC3 19 +#define SQMOD_ASCII_DC4 20 +#define SQMOD_ASCII_NAK 21 +#define SQMOD_ASCII_SYN 22 +#define SQMOD_ASCII_ETB 23 +#define SQMOD_ASCII_CAN 24 +#define SQMOD_ASCII_EM 25 +#define SQMOD_ASCII_SUB 26 +#define SQMOD_ASCII_ESC 27 +#define SQMOD_ASCII_FS 28 +#define SQMOD_ASCII_GS 29 +#define SQMOD_ASCII_RS 30 +#define SQMOD_ASCII_US 31 +#define SQMOD_ASCII_SPACE 32 +#define SQMOD_ASCII_EXCLAMATION_POINT 33 +#define SQMOD_ASCII_DOUBLE_QUOTES 34 +#define SQMOD_ASCII_NUMBER_SIGN 35 +#define SQMOD_ASCII_DOLLAR_SIGN 36 +#define SQMOD_ASCII_PERCENT_SIGN 37 +#define SQMOD_ASCII_AMPERSAND 38 +#define SQMOD_ASCII_SINGLE_QUOTE 39 +#define SQMOD_ASCII_OPENING_PARENTHESIS 40 +#define SQMOD_ASCII_CLOSING_PARENTHESIS 41 +#define SQMOD_ASCII_ASTERISK 42 +#define SQMOD_ASCII_PLUS 43 +#define SQMOD_ASCII_COMMA 44 +#define SQMOD_ASCII_MINUS 45 +#define SQMOD_ASCII_PERIOD 46 +#define SQMOD_ASCII_SLASH 47 +#define SQMOD_ASCII_ZERO 48 +#define SQMOD_ASCII_ONE 49 +#define SQMOD_ASCII_TWO 50 +#define SQMOD_ASCII_THREE 51 +#define SQMOD_ASCII_FOUR 52 +#define SQMOD_ASCII_FIVE 53 +#define SQMOD_ASCII_SIX 54 +#define SQMOD_ASCII_SEVEN 55 +#define SQMOD_ASCII_EIGHT 56 +#define SQMOD_ASCII_NINE 57 +#define SQMOD_ASCII_COLON 58 +#define SQMOD_ASCII_EMICOLON 59 +#define SQMOD_ASCII_LESS_THAN_SIGN 60 +#define SQMOD_ASCII_EQUAL_SIGN 61 +#define SQMOD_ASCII_GREATER_THAN_SIGN 62 +#define SQMOD_ASCII_QUESTION_MARK 63 +#define SQMOD_ASCII_AT 64 +#define SQMOD_ASCII_UPPER_A 65 +#define SQMOD_ASCII_UPPER_B 66 +#define SQMOD_ASCII_UPPER_C 67 +#define SQMOD_ASCII_UPPER_D 68 +#define SQMOD_ASCII_UPPER_E 69 +#define SQMOD_ASCII_UPPER_F 70 +#define SQMOD_ASCII_UPPER_G 71 +#define SQMOD_ASCII_UPPER_H 72 +#define SQMOD_ASCII_UPPER_I 73 +#define SQMOD_ASCII_UPPER_J 74 +#define SQMOD_ASCII_UPPER_K 75 +#define SQMOD_ASCII_UPPER_L 76 +#define SQMOD_ASCII_UPPER_M 77 +#define SQMOD_ASCII_UPPER_N 78 +#define SQMOD_ASCII_UPPER_O 79 +#define SQMOD_ASCII_UPPER_P 80 +#define SQMOD_ASCII_UPPER_Q 81 +#define SQMOD_ASCII_UPPER_R 82 +#define SQMOD_ASCII_UPPER_S 83 +#define SQMOD_ASCII_UPPER_T 84 +#define SQMOD_ASCII_UPPER_U 85 +#define SQMOD_ASCII_UPPER_V 86 +#define SQMOD_ASCII_UPPER_W 87 +#define SQMOD_ASCII_UPPER_X 88 +#define SQMOD_ASCII_UPPER_Y 89 +#define SQMOD_ASCII_UPPER_Z 90 +#define SQMOD_ASCII_OPENING_BRACKET 91 +#define SQMOD_ASCII_BACKSLASH 92 +#define SQMOD_ASCII_CLOSING_BRACKET 93 +#define SQMOD_ASCII_CARET 94 +#define SQMOD_ASCII_UNDERSCORE 95 +#define SQMOD_ASCII_GRAVE_ACCENT 96 +#define SQMOD_ASCII_LOWER_A 97 +#define SQMOD_ASCII_LOWER_B 98 +#define SQMOD_ASCII_LOWER_C 99 +#define SQMOD_ASCII_LOWER_D 100 +#define SQMOD_ASCII_LOWER_E 101 +#define SQMOD_ASCII_LOWER_F 102 +#define SQMOD_ASCII_LOWER_G 103 +#define SQMOD_ASCII_LOWER_H 104 +#define SQMOD_ASCII_LOWER_I 105 +#define SQMOD_ASCII_LOWER_J 106 +#define SQMOD_ASCII_LOWER_K 107 +#define SQMOD_ASCII_LOWER_L 108 +#define SQMOD_ASCII_LOWER_M 109 +#define SQMOD_ASCII_LOWER_N 110 +#define SQMOD_ASCII_LOWER_O 111 +#define SQMOD_ASCII_LOWER_P 112 +#define SQMOD_ASCII_LOWER_Q 113 +#define SQMOD_ASCII_LOWER_R 114 +#define SQMOD_ASCII_LOWER_S 115 +#define SQMOD_ASCII_LOWER_T 116 +#define SQMOD_ASCII_LOWER_U 117 +#define SQMOD_ASCII_LOWER_V 118 +#define SQMOD_ASCII_LOWER_W 119 +#define SQMOD_ASCII_LOWER_X 120 +#define SQMOD_ASCII_LOWER_Y 121 +#define SQMOD_ASCII_LOWER_Z 122 +#define SQMOD_ASCII_OPENING_BRACE 123 +#define SQMOD_ASCII_VERTICAL_BAR 124 +#define SQMOD_ASCII_CLOSING_BRACE 125 +#define SQMOD_ASCII_TILDE 126 +#define SQMOD_ASCII_UNDEFINED 127 + +#endif // _CONFIG_HPP_ diff --git a/source/Core.cpp b/source/Core.cpp new file mode 100644 index 00000000..06c89948 --- /dev/null +++ b/source/Core.cpp @@ -0,0 +1,1581 @@ +#include "Core.hpp" +#include "Logger.hpp" +#include "Entity.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +#include "Base/Color3.hpp" +#include "Base/Vector2i.hpp" +#include "Misc/Automobile.hpp" +#include "Misc/Model.hpp" + +// ------------------------------------------------------------------------------------------------ +#include +#include + +// ------------------------------------------------------------------------------------------------ +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------------------------------ +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Core::Pointer _Core = Core::Inst(); + +// ------------------------------------------------------------------------------------------------ +static std::shared_ptr g_Config; + +// ------------------------------------------------------------------------------------------------ +Core::Core() noexcept + : m_State(SQMOD_SUCCESS) + , m_Options() + , m_VM(nullptr) + , m_RootTable(nullptr) + , m_Scripts() + , m_ErrorMsg() + , m_PlayerTrack() + , m_VehicleTrack() +{ + // Create a few shared buffers + MakeBuffer(8); +} + +// ------------------------------------------------------------------------------------------------ +Core::~Core() +{ + this->Terminate(); +} + +// ------------------------------------------------------------------------------------------------ +void Core::_Finalizer(Core * ptr) noexcept +{ + if (ptr) delete ptr; +} + +// ------------------------------------------------------------------------------------------------ +Core::Pointer Core::Inst() noexcept +{ + if (!_Core) + { + return Pointer(new Core(), &Core::_Finalizer); + } + return Pointer(nullptr, &Core::_Finalizer); +} + +// ------------------------------------------------------------------------------------------------ +bool Core::Init() noexcept +{ + _Log->Msg("%s", CenterStr("INITIALIZING", '*')); + + if (!this->Configure() || !this->CreateVM() || !this->LoadScripts()) + { + return false; + } + + _Log->Msg("%s", CenterStr("SUCCESS", '*')); + + return true; +} + +bool Core::Load() noexcept +{ + _Log->Msg("%s", CenterStr("LOADING", '*')); + + if (!this->Execute()) + { + return false; + } + + _Log->Msg("%s", CenterStr("SUCCESS", '*')); + + return true; +} + +// ------------------------------------------------------------------------------------------------ +void Core::Deinit() noexcept +{ + this->DestroyVM(); +} + +void Core::Unload() noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::Terminate() noexcept +{ + this->Deinit(); + this->Unload(); +} + +// ------------------------------------------------------------------------------------------------ +void Core::SetState(SQInteger val) noexcept +{ + m_State = val; +} + +SQInteger Core::GetState() const noexcept +{ + return m_State; +} + +// ------------------------------------------------------------------------------------------------ +string Core::GetOption(const string & name) const noexcept +{ + OptionPool::const_iterator elem = m_Options.find(name); + return (elem == m_Options.cend()) ? string() : elem->second; +} + +void Core::SetOption(const string & name, const string & value) noexcept +{ + m_Options[name] = value; +} + +// ------------------------------------------------------------------------------------------------ +Core::Buffer Core::PullBuffer(unsigned sz) noexcept +{ + Buffer buf; + if (m_BufferPool.empty()) + { + buf.resize(sz); + } + else + { + buf = std::move(m_BufferPool.back()); + m_BufferPool.pop(); + } + return std::move(buf); +} + +// ------------------------------------------------------------------------------------------------ +void Core::PushBuffer(Buffer && buf) noexcept +{ + m_BufferPool.push(std::move(buf)); +} + +// ------------------------------------------------------------------------------------------------ +void Core::MakeBuffer(unsigned num, unsigned sz) noexcept +{ + while (num--) + { + m_BufferPool.emplace(sz); + } +} + +// ------------------------------------------------------------------------------------------------ +void Core::ConnectPlayer(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CPlayer >::Activate(id, false)) + { + // Trigger the specific event + OnPlayerCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } +} + +void Core::DisconnectPlayer(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + // Check to be sure we have this player instance active + if (Reference< CPlayer >::Verify(id)) + { + // Trigger the specific event + OnPlayerDestroyed(id, header, payload); + } +} + +// ------------------------------------------------------------------------------------------------ +bool Core::Configure() noexcept +{ + _Log->Dbg("Attempting to instantiate the configuration file"); + + if (g_Config) + { + g_Config->Reset(); + } + else + { + g_Config.reset(new CSimpleIniA(true, true, true)); + } + + if (!g_Config) + { + _Log->Ftl("Unable to instantiate the configuration class"); + + return false; + } + + _Log->Dbg("Attempting to load the configuration file."); + + SI_Error ini_ret = g_Config->LoadFile(_SC("./sqmod.ini")); + + if (ini_ret < 0) + { + switch (ini_ret) + { + case SI_FAIL: _Log->Err("Failed to load the configuration file. Probably invalid"); break; + case SI_NOMEM: _Log->Err("Run out of memory while loading the configuration file"); break; + case SI_FILE: _Log->Err("Failed to load the configuration file. %s", strerror(errno)); break; + default: _Log->Err("Failed to load the configuration file for some unforeseen reason"); + } + return false; + } + + _Log->Dbg("Applying the specified logging filters"); + + if (!SToB(g_Config->GetValue("ConsoleLog", "Debug", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_DBG); + if (!SToB(g_Config->GetValue("ConsoleLog", "Message", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_MSG); + if (!SToB(g_Config->GetValue("ConsoleLog", "Success", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_SCS); + if (!SToB(g_Config->GetValue("ConsoleLog", "Info", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_INF); + if (!SToB(g_Config->GetValue("ConsoleLog", "Warning", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_WRN); + if (!SToB(g_Config->GetValue("ConsoleLog", "Error", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_ERR); + if (!SToB(g_Config->GetValue("ConsoleLog", "Fatal", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_FTL); + + if (!SToB(g_Config->GetValue("FileLog", "Debug", "true"))) _Log->DisableFileLevel(Logger::LEVEL_DBG); + if (!SToB(g_Config->GetValue("FileLog", "Message", "true"))) _Log->DisableFileLevel(Logger::LEVEL_MSG); + if (!SToB(g_Config->GetValue("FileLog", "Success", "true"))) _Log->DisableFileLevel(Logger::LEVEL_SCS); + if (!SToB(g_Config->GetValue("FileLog", "Info", "true"))) _Log->DisableFileLevel(Logger::LEVEL_INF); + if (!SToB(g_Config->GetValue("FileLog", "Warning", "true"))) _Log->DisableFileLevel(Logger::LEVEL_WRN); + if (!SToB(g_Config->GetValue("FileLog", "Error", "true"))) _Log->DisableFileLevel(Logger::LEVEL_ERR); + if (!SToB(g_Config->GetValue("FileLog", "Fatal", "true"))) _Log->DisableFileLevel(Logger::LEVEL_FTL); + + _Log->Dbg("Reading the options from the general section"); + + CSimpleIniA::TNamesDepend general_options; + + if (g_Config->GetAllKeys("Options", general_options) || general_options.size() > 0) + { + for (auto const & cfg_option : general_options) + { + CSimpleIniA::TNamesDepend option_list; + + if (!g_Config->GetAllValues("Options", cfg_option.pItem, option_list)) + { + continue; + } + + option_list.sort(CSimpleIniA::Entry::LoadOrder()); + + for (auto const & cfg_value : option_list) + { + m_Options[cfg_option.pItem] = cfg_value.pItem; + } + } + } + else + { + _Log->Inf("No options specified in the configuration file"); + } + + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::CreateVM() noexcept +{ + _Log->Dbg("Acquiring the virtual machine stack size"); + + // Start with an unknown stack size + SQInteger stack_size = SQMOD_UNKNOWN; + + // Attempt to get it from the configuration file + try + { + stack_size = SToI::Fn(GetOption(_SC("VMStackSize")), 0, 10); + } + catch (const std::invalid_argument & e) + { + _Log->Wrn("Unable to extract option value: %s", e.what()); + } + + // Validate the stack size + if (stack_size <= 0) + { + _Log->Wrn("Invalid stack size. Reverting to default size"); + SetOption(_SC("VMStackSize"), std::to_string(SQMOD_STACK_SIZE)); + stack_size = SQMOD_STACK_SIZE; + } + + _Log->Inf("Creating a virtual machine with a stack size of: %d", stack_size); + + m_VM = sq_open(stack_size); + + if (!m_VM) + { + _Log->Ftl("Unable to create the virtual machine"); + + return false; + } + else + { + DefaultVM::Set(m_VM); + ErrorHandling::Enable(true); + m_RootTable.reset(new RootTable(m_VM)); + m_Scripts.clear(); + } + + _Log->Dbg("Registering the standard libraries"); + + sq_pushroottable(m_VM); + sqstd_register_iolib(m_VM); + sqstd_register_bloblib(m_VM); + sqstd_register_mathlib(m_VM); + sqstd_register_systemlib(m_VM); + sqstd_register_stringlib(m_VM); + sq_pop(m_VM, 1); + + _Log->Dbg("Setting the base output function"); + + sq_setprintfunc(m_VM, PrintFunc, ErrorFunc); + + _Log->Dbg("Setting the base error handlers"); + + sq_setcompilererrorhandler(m_VM, CompilerErrorHandler); + sq_newclosure(m_VM, RuntimeErrorHandler, 0); + sq_seterrorhandler(m_VM); + + _Log->Dbg("Registering the plugin API"); + + if (!RegisterAPI(m_VM)) + { + _Log->Ftl("Unable to register the script API"); + return false; + } + + return true; +} + +void Core::DestroyVM() noexcept +{ + if (m_VM) sq_close(m_VM); +} + +// ------------------------------------------------------------------------------------------------ +bool Core::LoadScripts() noexcept +{ + _Log->Dbg("Attempting to compile the specified scripts"); + + if (!g_Config) + { + _Log->Wrn("Cannot compile any scripts without the configurations"); + + return false; + } + + CSimpleIniA::TNamesDepend script_list; + g_Config->GetAllValues("Scripts", "Source", script_list); + + if (script_list.size() <= 0) + { + _Log->Wrn("No scripts specified in the configuration file"); + + return false; + } + + script_list.sort(CSimpleIniA::Entry::LoadOrder()); + + for (auto const & cfg_script : script_list) + { + string path(cfg_script.pItem); + + if (m_Scripts.find(path) != m_Scripts.cend()) + { + _Log->Wrn("Script was already loaded: %s", path.c_str()); + + continue; + } + else if (!Compile(path)) + { + return false; + } + else + { + _Log->Scs("Successfully compiled script: %s", path.c_str()); + } + } + + if (m_Scripts.empty()) + { + _Log->Err("No scripts compiled. No reason to load the plugin"); + + return false; + } + + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::Compile(const string & name) noexcept +{ + if (name.empty()) + { + _Log->Err("Cannot compile script without a valid name"); + + return false; + } + + std::pair< SqScriptPool::iterator, bool > res = m_Scripts.emplace(name, Script(m_VM)); + + if (res.second) + { + res.first->second.CompileFile(name); + + if (Error::Occurred(m_VM)) + { + _Log->Err("Unable to compile script: %s", name.c_str()); + _Log->Inf("=> %s", Error::Message(m_VM).c_str()); + m_Scripts.erase(res.first); + + return false; + } + } + else + { + _Log->Err("Unable to queue script: %s", name.c_str()); + + return false; + } + + return true; +} + +bool Core::Execute() noexcept +{ + _Log->Dbg("Attempting to execute the specified scripts"); + + for (auto & elem : m_Scripts) + { + elem.second.Run(); + + if (Error::Occurred(m_VM)) + { + _Log->Err("Unable to execute script: %s", elem.first.c_str()); + _Log->Inf("=> %s", Error::Message(m_VM).c_str()); + + return false; + } + else + { + _Log->Scs("Successfully executed script: %s", elem.first.c_str()); + } + } + + return true; +} + +// ------------------------------------------------------------------------------------------------ +void Core::PrintCallstack() noexcept +{ + SQStackInfos si; + + + _Log->Msg("%s", CenterStr("CALLSTACK", '*')); + + for (SQInteger level = 1; SQ_SUCCEEDED(sq_stackinfos(m_VM, level, &si)); ++level) + { + _Log->Inf("FUNCTION %s()", si.funcname ? si.funcname : _SC("unknown")); + _Log->SInf("=> [%d] : {%s}", si.line, si.source ? si.source : _SC("unknown")); + } + + const SQChar * s_ = 0, * name = 0; + SQInteger i_, seq = 0; + SQFloat f_; + SQUserPointer p_; + + _Log->Msg("%s", CenterStr("LOCALS", '*')); + + for (SQInteger level = 0; level < 10; level++) { + seq = 0; + while((name = sq_getlocal(m_VM, level, seq))) { + ++seq; + switch(sq_gettype(m_VM, -1)) + { + case OT_NULL: + _Log->Inf("NULL [%s] : ...", name); + break; + case OT_INTEGER: + sq_getinteger(m_VM, -1, &i_); + _Log->Inf("INTEGER [%s] : {%d}", name, i_); + break; + case OT_FLOAT: + sq_getfloat(m_VM, -1, &f_); + _Log->Inf("FLOAT [%s] : {%f}", name, f_); + break; + case OT_USERPOINTER: + sq_getuserpointer(m_VM, -1, &p_); + _Log->Inf("USERPOINTER [%s] : {%p}\n", name, p_); + break; + case OT_STRING: + sq_getstring(m_VM, -1, &s_); + _Log->Inf("STRING [%s] : {%s}", name, s_); + break; + case OT_TABLE: + _Log->Inf("TABLE [%s] : ...", name); + break; + case OT_ARRAY: + _Log->Inf("ARRAY [%s] : ...", name); + break; + case OT_CLOSURE: + _Log->Inf("CLOSURE [%s] : ...", name); + break; + case OT_NATIVECLOSURE: + _Log->Inf("NATIVECLOSURE [%s] : ...", name); + break; + case OT_GENERATOR: + _Log->Inf("GENERATOR [%s] : ...", name); + break; + case OT_USERDATA: + _Log->Inf("USERDATA [%s] : ...", name); + break; + case OT_THREAD: + _Log->Inf("THREAD [%s] : ...", name); + break; + case OT_CLASS: + _Log->Inf("CLASS [%s] : ...", name); + break; + case OT_INSTANCE: + _Log->Inf("INSTANCE [%s] : ...", name); + break; + case OT_WEAKREF: + _Log->Inf("WEAKREF [%s] : ...", name); + break; + case OT_BOOL: + sq_getinteger(m_VM, -1, &i_); + _Log->Inf("BOOL [%s] : {%s}", name, i_ ? _SC("true") : _SC("false")); + break; + default: + _Log->Err("UNKNOWN [%s] : ...", name); + break; + } + sq_pop(m_VM, 1); + } + } +} + +// ------------------------------------------------------------------------------------------------ +void Core::PrintFunc(HSQUIRRELVM vm, const SQChar * str, ...) noexcept +{ + va_list args; + va_start(args, str); + + std::vector buffer(256); + SQInt32 fmt_ret = std::vsnprintf(&buffer[0], buffer.size(), str, args); + + if (fmt_ret < 0) + { + return; + } + else if (static_cast(fmt_ret) > buffer.size()) + { + buffer.resize(++fmt_ret); + vsnprintf(&buffer[0], buffer.size(), str, args); + } + + va_end(args); + + _Log->Msg("%s", buffer.data()); +} + +void Core::ErrorFunc(HSQUIRRELVM vm, const SQChar * str, ...) noexcept +{ + va_list args; + va_start(args, str); + + std::vector buffer(256); + std::size_t buff_sz = static_cast(vsnprintf(&buffer[0], buffer.size(), str, args)); + + if (buff_sz > buffer.size()) + { + buffer.resize(++buff_sz); + vsnprintf(&buffer[0], buffer.size(), str, args); + } + + va_end(args); + + _Log->Err("%s", buffer.data()); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger Core::RuntimeErrorHandler(HSQUIRRELVM vm) noexcept +{ + if (sq_gettop(vm) < 1) + { + return 0; + } + + const SQChar * err_msg = NULL; + + if (SQ_SUCCEEDED(sq_getstring(vm, 2, &err_msg))) + { + _Core->m_ErrorMsg.assign(err_msg); + } + else + { + _Core->m_ErrorMsg.assign(_SC("An unknown runtime error has occurred")); + } + + _Log->Msg("%s", CenterStr("ERROR", '*')); + + _Log->Inf("[MESSAGE] : %s", _Core->m_ErrorMsg.c_str()); + + if (_Log->GetVerbosity() > 0) + { + _Core->PrintCallstack(); + } + + _Log->Msg("%s", CenterStr("CONCLUDED", '*')); + + return SQ_OK; +} + +void Core::CompilerErrorHandler(HSQUIRRELVM vm, const SQChar * desc, const SQChar * src, SQInteger line, SQInteger column) noexcept +{ + try + { + _Core->m_ErrorMsg.assign(fmt::format("{0:s} : {1:d}:{2:d} : {3:s}", src, line, column, desc).c_str()); + } + catch (const std::exception & e) + { + _Log->Err("Compiler error: %s", e.what()); + _Core->m_ErrorMsg.assign(_SC("An unknown compiler error has occurred")); + } + + _Log->Err("%s", _Core->m_ErrorMsg.c_str()); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CBlip > Core::CreateBlip(SQInt32 index, SQInt32 world, const Vector3 & pos, SQInt32 scale, \ + const Color4 & color, SQInt32 sprite, SQInt32 header, const SqObj & payload) noexcept +{ + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = _Func->CreateCoordBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprite); + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CBlip >::Activate(id, true, world, scale, sprite, pos, color)) + { + // Trigger the specific event + OnBlipCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } + // Return the obtained reference as is + return Reference< CBlip >(id); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CCheckpoint > Core::CreateCheckpoint(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \ + const Color4 & color, SQFloat radius, SQInt32 header, const SqObj & payload) noexcept +{ + // See if the specified player reference is valid + if (!player) + { + LogWrn("Attempting to create a instance on an invalid player: %d", _SCI32(player)); + } + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = _Func->CreateCheckpoint(_SCI32(player), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius); + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CCheckpoint >::Activate(id, true)) + { + // Trigger the specific event + OnCheckpointCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } + // Return the obtained reference as is + return Reference< CCheckpoint >(id); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CKeybind > Core::CreateKeybind(SQInt32 slot, bool release, SQInt32 primary, SQInt32 secondary, \ + SQInt32 alternative, SQInt32 header, const SqObj & payload) noexcept +{ + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = _Func->RegisterKeyBind(slot, release, primary, secondary, alternative); + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CKeybind >::Activate(id, true, primary, secondary, alternative, release)) + { + // Trigger the specific event + OnKeybindCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } + // Return the obtained reference as is + return Reference< CKeybind >(id); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CObject > Core::CreateObject(const CModel & model, SQInt32 world, const Vector3 & pos, SQInt32 alpha, \ + SQInt32 header, const SqObj & payload) noexcept +{ + // See if the specified model is valid + if (!model) + { + LogWrn("Attempting to create an instance with an invalid model: %d", _SCI32(model)); + } + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = _Func->CreateObject(_SCI32(model), world, pos.x, pos.y, pos.z, alpha); + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CObject >::Activate(id, true)) + { + // Trigger the specific event + OnObjectCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } + // Return the obtained reference as is + return Reference< CObject >(id); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CPickup > Core::CreatePickup(const CModel & model, SQInt32 world, SQInt32 quantity, const Vector3 & pos, \ + SQInt32 alpha, bool automatic, SQInt32 header, const SqObj & payload) noexcept +{ + // See if the specified model is valid + if (!model) + { + LogWrn("Attempting to create a instance with an invalid model: %d", _SCI32(model)); + } + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = _Func->CreatePickup(_SCI32(model), world, quantity, pos.x, pos.y, pos.z, alpha, automatic); + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CPickup >::Activate(id, true)) + { + // Trigger the specific event + OnPickupCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } + // Return the obtained reference as is + return Reference< CPickup >(id); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CSphere > Core::CreateSphere(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \ + const Color3 & color, SQFloat radius, SQInt32 header, const SqObj & payload) noexcept +{ + // See if the specified player reference is valid + if (!player) + { + LogWrn("Attempting to create a instance on an invalid player: %d", _SCI32(player)); + } + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = _Func->CreateSphere(_SCI32(player), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius); + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CSphere >::Activate(id, true)) + { + // Trigger the specific event + OnSphereCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } + // Return the obtained reference as is + return Reference< CSphere >(id); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CSprite > Core::CreateSprite(SQInt32 index, const String & file, const Vector2i & pos, const Vector2i & rot, \ + SQFloat angle, SQInt32 alpha, bool rel, SQInt32 header, const SqObj & payload) noexcept +{ + // See if the specified file path is valid + if (file.empty()) + { + LogWrn("Attempting to create a instance with an empty path: %d", file.size()); + } + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = _Func->CreateSprite(index, file.c_str(), pos.x, pos.y, rot.x, rot.y, angle, alpha, rel); + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CSprite >::Activate(id, true, file)) + { + // Trigger the specific event + OnSpriteCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } + // Return the obtained reference as is + return Reference< CSprite >(id); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CTextdraw > Core::CreateTextdraw(SQInt32 index, const String & text, const Vector2i & pos, \ + const Color4 & color, bool rel, SQInt32 header, const SqObj & payload) noexcept +{ + // See if the specified text is valid + if (text.empty()) + { + LogWrn("Attempting to create a instance with an empty text: %d", text.size()); + } + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = _Func->CreateTextdraw(index, text.c_str(), pos.x, pos.y, color.GetRGBA(), rel); + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CTextdraw >::Activate(id, true, text)) + { + // Trigger the specific event + OnTextdrawCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } + // Return the obtained reference as is + return Reference< CTextdraw >(id); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CVehicle > Core::CreateVehicle(const CAutomobile & model, SQInt32 world, const Vector3 & pos, \ + SQFloat angle, SQInt32 primary, SQInt32 secondary, SQInt32 header, const SqObj & payload) noexcept +{ + // See if the specified model is valid + if (!model) + { + LogWrn("Attempting to create an instance with an invalid model: %d", _SCI32(model)); + } + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = _Func->CreateVehicle(_SCI32(model), world, pos.x, pos.y, pos.z, angle, primary, secondary); + // Attempt to activate the instance in the plugin at the received identifier + if (EntMan< CVehicle >::Activate(id, true)) + { + // Trigger the specific event + OnVehicleCreated(id, header, payload); + } + else + { + LogErr("Unable to create a new instance"); + } + // Return the obtained reference as is + return Reference< CVehicle >(id); +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroyBlip(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroyCheckpoint(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroyKeybind(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroyObject(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroyPickup(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroyPlayer(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroySphere(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroySprite(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroyTextdraw(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool Core::DestroyVehicle(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + return true; +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnBlipCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnCheckpointCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnKeybindCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnObjectCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnPickupCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnPlayerCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnSphereCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnSpriteCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnTextdrawCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnVehicleCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnBlipDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnCheckpointDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnKeybindDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnObjectDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnPickupDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnPlayerDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnSphereDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnSpriteDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnTextdrawDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnVehicleDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnBlipCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnCheckpointCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnKeybindCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnObjectCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnPickupCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnPlayerCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnSphereCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnSpriteCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnTextdrawCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +void Core::OnVehicleCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerAway(SQInt32 player, bool status) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerGameKeys(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept +{ + +} + +void Core::OnPlayerName(SQInt32 player, const SQChar * previous, const SQChar * current) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerRequestClass(SQInt32 player, SQInt32 offset) noexcept +{ + +} + +void Core::OnPlayerRequestSpawn(SQInt32 player) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerSpawn(SQInt32 player) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerStartTyping(SQInt32 player) noexcept +{ + +} + +void Core::OnPlayerStopTyping(SQInt32 player) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerChat(SQInt32 player, const SQChar * message) noexcept +{ + +} + +void Core::OnPlayerCommand(SQInt32 player, const SQChar * command) noexcept +{ + +} + +void Core::OnPlayerMessage(SQInt32 player, SQInt32 receiver, const SQChar * message) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerHealth(SQInt32 player, SQFloat previous, SQFloat current) noexcept +{ + +} + +void Core::OnPlayerArmour(SQInt32 player, SQFloat previous, SQFloat current) noexcept +{ + +} + +void Core::OnPlayerWeapon(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept +{ + +} + +void Core::OnPlayerMove(SQInt32 player, const Vector3 & previous, const Vector3 & current) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerWasted(SQInt32 player, SQInt32 reason) noexcept +{ + +} + +void Core::OnPlayerKilled(SQInt32 player, SQInt32 killer, SQInt32 reason, SQInt32 body_part) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerSpectate(SQInt32 player, SQInt32 target) noexcept +{ + +} + +void Core::OnPlayerCrashreport(SQInt32 player, const SQChar * report) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerBurning(SQInt32 player, bool state) noexcept +{ + +} + +void Core::OnPlayerCrouching(SQInt32 player, bool state) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerState(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept +{ + +} + +void Core::OnPlayerAction(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnStateNone(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnStateNormal(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnStateShooting(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnStateDriver(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnStatePassenger(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnStateEnterDriver(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnStateEnterPassenger(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnStateExitVehicle(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnStateUnspawned(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnActionNone(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionNormal(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionAiming(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionShooting(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionJumping(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionLieDown(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionGettingUp(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionJumpVehicle(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionDriving(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionDying(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionWasted(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionEmbarking(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +void Core::OnActionDisembarking(SQInt32 player, SQInt32 previous) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnVehicleRespawn(SQInt32 vehicle) noexcept +{ + +} + +void Core::OnVehicleExplode(SQInt32 vehicle) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnVehicleHealth(SQInt32 vehicle, SQFloat previous, SQFloat current) noexcept +{ + +} + +void Core::OnVehicleMove(SQInt32 vehicle, const Vector3 & previous, const Vector3 & current) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPickupRespawn(SQInt32 pickup) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerKeyPress(SQInt32 player, SQInt32 keybind) noexcept +{ + +} + +void Core::OnPlayerKeyRelease(SQInt32 player, SQInt32 keybind) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerEmbarking(SQInt32 player, SQInt32 vehicle, SQInt32 slot) noexcept +{ + +} + +void Core::OnPlayerEmbarked(SQInt32 player, SQInt32 vehicle, SQInt32 slot) noexcept +{ + +} + +void Core::OnPlayerDisembark(SQInt32 player, SQInt32 vehicle) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPickupClaimed(SQInt32 pickup, SQInt32 player) noexcept +{ + +} + +void Core::OnPickupCollected(SQInt32 pickup, SQInt32 player) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnObjectShot(SQInt32 object, SQInt32 player, SQInt32 weapon) noexcept +{ + +} + +void Core::OnObjectBump(SQInt32 object, SQInt32 player) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnCheckpointEntered(SQInt32 checkpoint, SQInt32 player) noexcept +{ + +} + +void Core::OnCheckpointExited(SQInt32 checkpoint, SQInt32 player) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnSphereEntered(SQInt32 sphere, SQInt32 player) noexcept +{ + +} + +void Core::OnSphereExited(SQInt32 sphere, SQInt32 player) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnServerFrame(SQFloat delta) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnServerStartup() noexcept +{ + +} + +void Core::OnServerShutdown() noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnInternalCommand(SQInt32 type, const SQChar * text) noexcept +{ + +} + +void Core::OnLoginAttempt(const SQChar * name, const SQChar * passwd, const SQChar * ip) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnCustomEvent(SQInt32 group, SQInt32 header, const SqObj & payload) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnWorldOption(SQInt32 option, const SqObj & value) noexcept +{ + +} + +void Core::OnWorldToggle(SQInt32 option, bool value) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnScriptReload(SQInt32 header, const SqObj & payload) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnLogMessage(SQInt32 type, const SQChar * message) noexcept +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Core::OnPlayerUpdate(SQInt32 player, SQInt32 type) noexcept +{ + +} + +void Core::OnVehicleUpdate(SQInt32 vehicle, SQInt32 type) noexcept +{ + +} + +void Core::OnEntityPool(SQInt32 type, SQInt32 id, bool deleted) noexcept +{ + switch (type) + { + case SQMOD_ENTITY_POOL_VEHICLE: + if (deleted) + { + DestroyVehicle(id, SQMOD_DESTROY_POOL, SqObj()); + } + else if (EntMan< CVehicle >::Activate(id, false)) + { + OnVehicleCreated(id, SQMOD_CREATE_POOL, SqObj()); + } + break; + case SQMOD_ENTITY_POOL_OBJECT: + if (deleted) + { + DestroyObject(id, SQMOD_DESTROY_POOL, SqObj()); + } + else if (EntMan< CObject >::Activate(id, false)) + { + OnObjectCreated(id, SQMOD_CREATE_POOL, SqObj()); + } + break; + case SQMOD_ENTITY_POOL_PICKUP: + if (deleted) + { + DestroyPickup(id, SQMOD_DESTROY_POOL, SqObj()); + } + else if (EntMan< CPickup >::Activate(id, false)) + { + OnPickupCreated(id, SQMOD_CREATE_POOL, SqObj()); + } + break; + case SQMOD_ENTITY_POOL_RADIO: + // @TODO Implement... + break; + case SQMOD_ENTITY_POOL_SPRITE: + if (deleted) + { + DestroySprite(id, SQMOD_DESTROY_POOL, SqObj()); + } + else if (EntMan< CSprite >::Activate(id, false, "")) + { + OnSpriteCreated(id, SQMOD_CREATE_POOL, SqObj()); + } + break; + case SQMOD_ENTITY_POOL_TEXTDRAW: + if (deleted) + { + DestroyTextdraw(id, SQMOD_DESTROY_POOL, SqObj()); + } + else if (EntMan< CTextdraw >::Activate(id, false, "")) + { + OnTextdrawCreated(id, SQMOD_CREATE_POOL, SqObj()); + } + break; + case SQMOD_ENTITY_POOL_BLIP: + if (deleted) + { + DestroyBlip(id, SQMOD_DESTROY_POOL, SqObj()); + } + else + { + SQInt32 world, scale, sprite; + SQUint32 pcolor; + Vector3 pos; + Color4 color; + // Get the blip information from the server + _Func->GetCoordBlipInfo(id, &world, &pos.x, &pos.y, &pos.z, &scale, &pcolor, &sprite); + // Unpack the retrieved color + color.SetRGBA(pcolor); + + if (EntMan< CBlip >::Activate(id, false, world, scale, sprite, pos, color)) + { + OnBlipCreated(id, SQMOD_CREATE_POOL, SqObj()); + } + } + break; + default: + LogErr("Unknown change in the entity pool of type: %d", type); + } + +} + + +} // Namespace:: SqMod diff --git a/source/Core.hpp b/source/Core.hpp new file mode 100644 index 00000000..26732152 --- /dev/null +++ b/source/Core.hpp @@ -0,0 +1,623 @@ +#ifndef _CORE_HPP_ +#define _CORE_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" +#include "Signal.hpp" + +// ------------------------------------------------------------------------------------------------ +#include +#include +#include +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +class Core +{ +protected: + + // -------------------------------------------------------------------------------------------- + friend class std::unique_ptr; + + // -------------------------------------------------------------------------------------------- + struct TPlayer + { + SQInt32 Weapon; + SQFloat Health; + SQFloat Armour; + //Vector3 Position; + bool Fresh; + }; + + // -------------------------------------------------------------------------------------------- + struct TVehicle + { + SQFloat Health; + //Vector3 Position; + bool Fresh; + }; + + // -------------------------------------------------------------------------------------------- + typedef std::array TPlayerInstPool; + typedef std::array TVehicleInstPool; + + // -------------------------------------------------------------------------------------------- + typedef std::unique_ptr SqRootTable; + typedef std::unordered_map SqScriptPool; + + // -------------------------------------------------------------------------------------------- + typedef std::unordered_map OptionPool; + +public: + + // -------------------------------------------------------------------------------------------- + typedef std::vector< SQChar > Buffer; + typedef std::queue< Buffer > BufferPool; + +private: + + // -------------------------------------------------------------------------------------------- + SQInteger m_State; + + // -------------------------------------------------------------------------------------------- + OptionPool m_Options; + + // -------------------------------------------------------------------------------------------- + HSQUIRRELVM m_VM; + + // -------------------------------------------------------------------------------------------- + SqRootTable m_RootTable; + SqScriptPool m_Scripts; + + // -------------------------------------------------------------------------------------------- + String m_ErrorMsg; + + // -------------------------------------------------------------------------------------------- + TPlayerInstPool m_PlayerTrack; + TVehicleInstPool m_VehicleTrack; + + // -------------------------------------------------------------------------------------------- + BufferPool m_BufferPool; + +protected: + + // -------------------------------------------------------------------------------------------- + Core() noexcept; + + // -------------------------------------------------------------------------------------------- + ~Core() noexcept; + + // -------------------------------------------------------------------------------------------- + Core(Core const &) noexcept = delete; + Core(Core &&) noexcept = delete; + + // -------------------------------------------------------------------------------------------- + Core & operator=(Core const &) noexcept = delete; + Core & operator=(Core &&) noexcept = delete; + + // -------------------------------------------------------------------------------------------- + static void _Finalizer(Core * ptr) noexcept; + +public: + + // -------------------------------------------------------------------------------------------- + typedef std::unique_ptr Pointer; + + // -------------------------------------------------------------------------------------------- + static Pointer Inst() noexcept; + + // -------------------------------------------------------------------------------------------- + bool Init() noexcept; + bool Load() noexcept; + + // -------------------------------------------------------------------------------------------- + void Deinit() noexcept; + void Unload() noexcept; + + // -------------------------------------------------------------------------------------------- + void Terminate() noexcept; + + // -------------------------------------------------------------------------------------------- + void SetState(SQInteger val) noexcept; + SQInteger GetState() const noexcept; + + // -------------------------------------------------------------------------------------------- + String GetOption(const String & name) const noexcept; + void SetOption(const String & name, const String & value) noexcept; + + // -------------------------------------------------------------------------------------------- + Buffer PullBuffer(unsigned sz = 4096) noexcept; + void PushBuffer(Buffer && buf) noexcept; + void MakeBuffer(unsigned num, unsigned sz = 4096) noexcept; + + // -------------------------------------------------------------------------------------------- + void ConnectPlayer(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void DisconnectPlayer(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + +protected: + + // -------------------------------------------------------------------------------------------- + bool Configure() noexcept; + + // -------------------------------------------------------------------------------------------- + bool CreateVM() noexcept; + void DestroyVM() noexcept; + + // -------------------------------------------------------------------------------------------- + bool LoadScripts() noexcept; + + // -------------------------------------------------------------------------------------------- + bool Compile(const String & name) noexcept; + bool Execute() noexcept; + + // -------------------------------------------------------------------------------------------- + void PrintCallstack() noexcept; + +public: + + // -------------------------------------------------------------------------------------------- + static void PrintFunc(HSQUIRRELVM vm, const SQChar * str, ...) noexcept; + static void ErrorFunc(HSQUIRRELVM vm, const SQChar * str, ...) noexcept; + + // -------------------------------------------------------------------------------------------- + static SQInteger RuntimeErrorHandler(HSQUIRRELVM vm) noexcept; + static void CompilerErrorHandler(HSQUIRRELVM vm, const SQChar * desc, const SQChar * src, SQInteger line, SQInteger column) noexcept; + +protected: + + /* -------------------------------------------------------------------------------------------- + * Destroys a Player created by the server + */ + bool DestroyPlayer(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + +public: + + /* -------------------------------------------------------------------------------------------- + * Creates a new Blip on the server + */ + Reference< CBlip > CreateBlip(SQInt32 index, SQInt32 world, const Vector3 & pos, SQInt32 scale, \ + const Color4 & color, SQInt32 sprite, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Creates a new Checkpoint on the server + */ + Reference< CCheckpoint > CreateCheckpoint(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \ + const Color4 & color, SQFloat radius, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Creates a new Keybind on the server + */ + Reference< CKeybind > CreateKeybind(SQInt32 slot, bool release, SQInt32 primary, SQInt32 secondary, \ + SQInt32 alternative, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Creates a new Object on the server + */ + Reference< CObject > CreateObject(const CModel & model, SQInt32 world, const Vector3 & pos, SQInt32 alpha, \ + SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Creates a new Pickup on the server + */ + Reference< CPickup > CreatePickup(const CModel & model, SQInt32 world, SQInt32 quantity, const Vector3 & pos, \ + SQInt32 alpha, bool automatic, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Creates a new Sphere on the server + */ + Reference< CSphere > CreateSphere(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \ + const Color3 & color, SQFloat radius, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Creates a new Sprite on the server + */ + Reference< CSprite > CreateSprite(SQInt32 index, const String & file, const Vector2i & pos, const Vector2i & rot, \ + SQFloat angle, SQInt32 alpha, bool rel, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Creates a new Textdraw on the server + */ + Reference< CTextdraw > CreateTextdraw(SQInt32 index, const String & text, const Vector2i & pos, \ + const Color4 & color, bool rel, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Creates a new Vehicle on the server + */ + Reference< CVehicle > CreateVehicle(const CAutomobile & model, SQInt32 world, const Vector3 & pos, SQFloat angle, \ + SQInt32 primary, SQInt32 secondary, SQInt32 header, const SqObj & payload) noexcept; + +public: + + /* -------------------------------------------------------------------------------------------- + * Destroys a Blip created by the server + */ + bool DestroyBlip(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Destroys a Checkpoint created by the server + */ + bool DestroyCheckpoint(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Destroys a Keybind created by the server + */ + bool DestroyKeybind(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Destroys a Object created by the server + */ + bool DestroyObject(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Destroys a Pickup created by the server + */ + bool DestroyPickup(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Destroys a Sphere created by the server + */ + bool DestroySphere(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Destroys a Sprite created by the server + */ + bool DestroySprite(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Destroys a Textdraw created by the server + */ + bool DestroyTextdraw(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Destroys a Vehicle created by the server + */ + bool DestroyVehicle(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + +public: + + // -------------------------------------------------------------------------------------------- + void OnBlipCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnCheckpointCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnKeybindCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnObjectCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnPickupCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnPlayerCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnSphereCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnSpriteCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnTextdrawCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnVehicleCreated(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnBlipDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnCheckpointDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnKeybindDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnObjectDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnPickupDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnPlayerDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnSphereDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnSpriteDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnTextdrawDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnVehicleDestroyed(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnBlipCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnCheckpointCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnKeybindCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnObjectCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnPickupCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnPlayerCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnSphereCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnSpriteCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnTextdrawCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + void OnVehicleCustom(SQInt32 id, SQInt32 header, const SqObj & payload) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerAway(SQInt32 player, bool status) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerGameKeys(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept; + void OnPlayerName(SQInt32 player, const SQChar * previous, const SQChar * current) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerRequestClass(SQInt32 player, SQInt32 offset) noexcept; + void OnPlayerRequestSpawn(SQInt32 player) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerSpawn(SQInt32 player) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerStartTyping(SQInt32 player) noexcept; + void OnPlayerStopTyping(SQInt32 player) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerChat(SQInt32 player, const SQChar * message) noexcept; + void OnPlayerCommand(SQInt32 player, const SQChar * command) noexcept; + void OnPlayerMessage(SQInt32 player, SQInt32 receiver, const SQChar * message) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerHealth(SQInt32 player, SQFloat previous, SQFloat current) noexcept; + void OnPlayerArmour(SQInt32 player, SQFloat previous, SQFloat current) noexcept; + void OnPlayerWeapon(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept; + void OnPlayerMove(SQInt32 player, const Vector3 & previous, const Vector3 & current) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerWasted(SQInt32 player, SQInt32 reason) noexcept; + void OnPlayerKilled(SQInt32 player, SQInt32 killer, SQInt32 reason, SQInt32 body_part) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerSpectate(SQInt32 player, SQInt32 target) noexcept; + void OnPlayerCrashreport(SQInt32 player, const SQChar * report) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerBurning(SQInt32 player, bool state) noexcept; + void OnPlayerCrouching(SQInt32 player, bool state) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerState(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept; + void OnPlayerAction(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnStateNone(SQInt32 player, SQInt32 previous) noexcept; + void OnStateNormal(SQInt32 player, SQInt32 previous) noexcept; + void OnStateShooting(SQInt32 player, SQInt32 previous) noexcept; + void OnStateDriver(SQInt32 player, SQInt32 previous) noexcept; + void OnStatePassenger(SQInt32 player, SQInt32 previous) noexcept; + void OnStateEnterDriver(SQInt32 player, SQInt32 previous) noexcept; + void OnStateEnterPassenger(SQInt32 player, SQInt32 previous) noexcept; + void OnStateExitVehicle(SQInt32 player, SQInt32 previous) noexcept; + void OnStateUnspawned(SQInt32 player, SQInt32 previous) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnActionNone(SQInt32 player, SQInt32 previous) noexcept; + void OnActionNormal(SQInt32 player, SQInt32 previous) noexcept; + void OnActionAiming(SQInt32 player, SQInt32 previous) noexcept; + void OnActionShooting(SQInt32 player, SQInt32 previous) noexcept; + void OnActionJumping(SQInt32 player, SQInt32 previous) noexcept; + void OnActionLieDown(SQInt32 player, SQInt32 previous) noexcept; + void OnActionGettingUp(SQInt32 player, SQInt32 previous) noexcept; + void OnActionJumpVehicle(SQInt32 player, SQInt32 previous) noexcept; + void OnActionDriving(SQInt32 player, SQInt32 previous) noexcept; + void OnActionDying(SQInt32 player, SQInt32 previous) noexcept; + void OnActionWasted(SQInt32 player, SQInt32 previous) noexcept; + void OnActionEmbarking(SQInt32 player, SQInt32 previous) noexcept; + void OnActionDisembarking(SQInt32 player, SQInt32 previous) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnVehicleRespawn(SQInt32 vehicle) noexcept; + void OnVehicleExplode(SQInt32 vehicle) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnVehicleHealth(SQInt32 vehicle, SQFloat previous, SQFloat current) noexcept; + void OnVehicleMove(SQInt32 vehicle, const Vector3 & previous, const Vector3 & current) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPickupRespawn(SQInt32 pickup) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerKeyPress(SQInt32 player, SQInt32 keybind) noexcept; + void OnPlayerKeyRelease(SQInt32 player, SQInt32 keybind) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerEmbarking(SQInt32 player, SQInt32 vehicle, SQInt32 slot) noexcept; + void OnPlayerEmbarked(SQInt32 player, SQInt32 vehicle, SQInt32 slot) noexcept; + void OnPlayerDisembark(SQInt32 player, SQInt32 vehicle) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPickupClaimed(SQInt32 pickup, SQInt32 player) noexcept; + void OnPickupCollected(SQInt32 pickup, SQInt32 player) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnObjectShot(SQInt32 object, SQInt32 player, SQInt32 weapon) noexcept; + void OnObjectBump(SQInt32 object, SQInt32 player) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnCheckpointEntered(SQInt32 checkpoint, SQInt32 player) noexcept; + void OnCheckpointExited(SQInt32 checkpoint, SQInt32 player) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnSphereEntered(SQInt32 sphere, SQInt32 player) noexcept; + void OnSphereExited(SQInt32 sphere, SQInt32 player) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnServerFrame(SQFloat delta) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnServerStartup() noexcept; + void OnServerShutdown() noexcept; + + // -------------------------------------------------------------------------------------------- + void OnInternalCommand(SQInt32 type, const SQChar * text) noexcept; + void OnLoginAttempt(const SQChar * name, const SQChar * passwd, const SQChar * ip) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnCustomEvent(SQInt32 group, SQInt32 header, const SqObj & payload) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnWorldOption(SQInt32 option, const SqObj & value) noexcept; + void OnWorldToggle(SQInt32 option, bool value) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnScriptReload(SQInt32 header, const SqObj & payload) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnLogMessage(SQInt32 type, const SQChar * message) noexcept; + + // -------------------------------------------------------------------------------------------- + void OnPlayerUpdate(SQInt32 player, SQInt32 type) noexcept; + void OnVehicleUpdate(SQInt32 vehicle, SQInt32 type) noexcept; + void OnEntityPool(SQInt32 type, SQInt32 id, bool deleted) noexcept; + +public: + + // -------------------------------------------------------------------------------------------- + EBlipCreated BlipCreated; + ECheckpointCreated CheckpointCreated; + EKeybindCreated KeybindCreated; + EObjectCreated ObjectCreated; + EPickupCreated PickupCreated; + EPlayerCreated PlayerCreated; + ESphereCreated SphereCreated; + ESpriteCreated SpriteCreated; + ETextdrawCreated TextdrawCreated; + EVehicleCreated VehicleCreated; + + // -------------------------------------------------------------------------------------------- + EBlipDestroyed BlipDestroyed; + ECheckpointDestroyed CheckpointDestroyed; + EKeybindDestroyed KeybindDestroyed; + EObjectDestroyed ObjectDestroyed; + EPickupDestroyed PickupDestroyed; + EPlayerDestroyed PlayerDestroyed; + ESphereDestroyed SphereDestroyed; + ESpriteDestroyed SpriteDestroyed; + ETextdrawDestroyed TextdrawDestroyed; + EVehicleDestroyed VehicleDestroyed; + + // -------------------------------------------------------------------------------------------- + EBlipCustom BlipCustom; + ECheckpointCustom CheckpointCustom; + EKeybindCustom KeybindCustom; + EObjectCustom ObjectCustom; + EPickupCustom PickupCustom; + EPlayerCustom PlayerCustom; + ESphereCustom SphereCustom; + ESpriteCustom SpriteCustom; + ETextdrawCustom TextdrawCustom; + EVehicleCustom VehicleCustom; + + // -------------------------------------------------------------------------------------------- + EPlayerAway PlayerAway; + + // -------------------------------------------------------------------------------------------- + EPlayerGameKeys PlayerGameKeys; + EPlayerRename PlayerRename; + + // -------------------------------------------------------------------------------------------- + EPlayerRequestClass PlayerRequestClass; + EPlayerRequestSpawn PlayerRequestSpawn; + + // -------------------------------------------------------------------------------------------- + EPlayerSpawn PlayerSpawn; + + // -------------------------------------------------------------------------------------------- + EPlayerStartTyping PlayerStartTyping; + EPlayerStopTyping PlayerStopTyping; + + // -------------------------------------------------------------------------------------------- + EPlayerChat PlayerChat; + EPlayerCommand PlayerCommand; + EPlayerMessage PlayerMessage; + + // -------------------------------------------------------------------------------------------- + EPlayerHealth PlayerHealth; + EPlayerArmour PlayerArmour; + EPlayerWeapon PlayerWeapon; + EPlayerMove PlayerMove; + + // -------------------------------------------------------------------------------------------- + EPlayerWasted PlayerWasted; + EPlayerKilled PlayerKilled; + EPlayerTeamKill PlayerTeamKill; + + // -------------------------------------------------------------------------------------------- + EPlayerSpectate PlayerSpectate; + EPlayerCrashreport PlayerCrashreport; + + // -------------------------------------------------------------------------------------------- + EPlayerBurning PlayerBurning; + EPlayerCrouching PlayerCrouching; + + // -------------------------------------------------------------------------------------------- + EPlayerState PlayerState; + EPlayerAction PlayerAction; + + // -------------------------------------------------------------------------------------------- + EStateNone StateNone; + EStateNormal StateNormal; + EStateShooting StateShooting; + EStateDriver StateDriver; + EStatePassenger StatePassenger; + EStateEnterDriver StateEnterDriver; + EStateEnterPassenger StateEnterPassenger; + EStateExitVehicle StateExitVehicle; + EStateUnspawned StateUnspawned; + + // -------------------------------------------------------------------------------------------- + EActionNone ActionNone; + EActionNormal ActionNormal; + EActionAiming ActionAiming; + EActionShooting ActionShooting; + EActionJumping ActionJumping; + EActionLieDown ActionLieDown; + EActionGettingUp ActionGettingUp; + EActionJumpVehicle ActionJumpVehicle; + EActionDriving ActionDriving; + EActionDying ActionDying; + EActionWasted ActionWasted; + EActionEmbarking ActionEmbarking; + EActionDisembarking ActionDisembarking; + + // -------------------------------------------------------------------------------------------- + EVehicleRespawn VehicleRespawn; + EVehicleExplode VehicleExplode; + + // -------------------------------------------------------------------------------------------- + EVehicleHealth VehicleHealth; + EVehicleMove VehicleMove; + + // -------------------------------------------------------------------------------------------- + EPickupRespawn PickupRespawn; + + // -------------------------------------------------------------------------------------------- + EKeybindKeyPress KeybindKeyPress; + EKeybindKeyRelease KeybindKeyRelease; + + // -------------------------------------------------------------------------------------------- + EVehicleEmbarking VehicleEmbarking; + EVehicleEmbarked VehicleEmbarked; + EVehicleDisembark VehicleDisembark; + + // -------------------------------------------------------------------------------------------- + EPickupClaimed PickupClaimed; + EPickupCollected PickupCollected; + + // -------------------------------------------------------------------------------------------- + EObjectShot ObjectShot; + EObjectBump ObjectBump; + + // -------------------------------------------------------------------------------------------- + ECheckpointEntered CheckpointEntered; + ECheckpointExited CheckpointExited; + + // -------------------------------------------------------------------------------------------- + ESphereEntered SphereEntered; + ESphereExited SphereExited; + + // -------------------------------------------------------------------------------------------- + EServerFrame ServerFrame; + + // -------------------------------------------------------------------------------------------- + EServerStartup ServerStartup; + EServerShutdown ServerShutdown; + + // -------------------------------------------------------------------------------------------- + EInternalCommand InternalCommand; + ELoginAttempt LoginAttempt; + + // -------------------------------------------------------------------------------------------- + ECustomEvent CustomEvent; + + // -------------------------------------------------------------------------------------------- + EWorldOption WorldOption; + EWorldToggle WorldToggle; +}; + +// ------------------------------------------------------------------------------------------------ +extern const Core::Pointer _Core; + +} // Namespace:: SqMod + +#endif // _CORE_HPP_ diff --git a/source/Entity.cpp b/source/Entity.cpp new file mode 100644 index 00000000..c7d9c11b --- /dev/null +++ b/source/Entity.cpp @@ -0,0 +1,14 @@ +#include "Entity.hpp" +#include "Register.hpp" +#include "Core.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_Entity(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity.hpp b/source/Entity.hpp new file mode 100644 index 00000000..06684306 --- /dev/null +++ b/source/Entity.hpp @@ -0,0 +1,1548 @@ +#ifndef _ENTITY_HPP_ +#define _ENTITY_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" +#include "Signal.hpp" + +// ------------------------------------------------------------------------------------------------ +#include "Base/Vector3.hpp" +#include "Base/Color4.hpp" + +// ------------------------------------------------------------------------------------------------ +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +enum EntityType +{ + ENT_UNKNOWN = 0, + ENT_BLIP, + ENT_CHECKPOINT, + ENT_KEYBIND, + ENT_OBJECT, + ENT_PICKUP, + ENT_PLAYER, + ENT_SPHERE, + ENT_SPRITE, + ENT_TEXTDRAW, + ENT_VEHICLE, + ENT_COUNT +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template < class T > class Ent; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CBlip > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CBlip >; + friend class Reference< CBlip >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CBlip > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Blip + { + // ---------------------------------------------------------------------------------------- + Blip() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + SQInt32 World; + SQInt32 Scale; + + // ---------------------------------------------------------------------------------------- + SQInt32 SprID; + + // ---------------------------------------------------------------------------------------- + Vector3 Position; + Color4 Color; + + // ---------------------------------------------------------------------------------------- + EBlipCreated BlipCreated; + EBlipDestroyed BlipDestroyed; + EBlipCustom BlipCustom; + + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 world, SQInt32 scale, SQInt32 sprite, \ + const Vector3 & pos, const Color4 & color) noexcept + { + inst.World = world; + inst.Scale = scale; + inst.SprID = sprite; + inst.Position = pos; + inst.Color = color; + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.BlipCreated.Clear(); + inst.BlipDestroyed.Clear(); + inst.BlipCustom.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_BLIP; + static constexpr SQInt32 Limit = SQMOD_BLIP_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Blip"; + static constexpr const SQChar* CName = "CBlip"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CCheckpoint > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CCheckpoint >; + friend class Reference< CCheckpoint >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CCheckpoint > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Checkpoint + { + // ---------------------------------------------------------------------------------------- + Checkpoint() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + ECheckpointCreated CheckpointCreated; + ECheckpointDestroyed CheckpointDestroyed; + ECheckpointCustom CheckpointCustom; + ECheckpointEntered CheckpointEntered; + ECheckpointExited CheckpointExited; + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst) noexcept + { + /* ... */ + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.CheckpointCreated.Clear(); + inst.CheckpointDestroyed.Clear(); + inst.CheckpointCustom.Clear(); + inst.CheckpointEntered.Clear(); + inst.CheckpointExited.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_CHECKPOINT; + static constexpr SQInt32 Limit = SQMOD_CHECKPOINT_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Checkpoint"; + static constexpr const SQChar* CName = "CCheckpoint"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CKeybind > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CKeybind >; + friend class Reference< CKeybind >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CKeybind > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Keybind + { + // ---------------------------------------------------------------------------------------- + Keybind() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + SQInt32 Primary; + SQInt32 Secondary; + SQInt32 Alternative; + + // ---------------------------------------------------------------------------------------- + bool Release; + + // ---------------------------------------------------------------------------------------- + EKeybindCreated KeybindCreated; + EKeybindDestroyed KeybindDestroyed; + EKeybindCustom KeybindCustom; + EKeybindKeyPress KeybindKeyPress; + EKeybindKeyRelease KeybindKeyRelease; + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 primary, SQInt32 secondary, SQInt32 alternative, \ + bool release) noexcept + { + inst.Primary = primary; + inst.Secondary = secondary; + inst.Alternative = alternative; + inst.Release = release; + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.KeybindCreated.Clear(); + inst.KeybindDestroyed.Clear(); + inst.KeybindCustom.Clear(); + inst.KeybindKeyPress.Clear(); + inst.KeybindKeyRelease.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_KEYBIND; + static constexpr SQInt32 Limit = SQMOD_KEYBIND_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Keybind"; + static constexpr const SQChar* CName = "CKeybind"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CObject > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CObject >; + friend class Reference< CObject >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CObject > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Object + { + // ---------------------------------------------------------------------------------------- + Object() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + EObjectCreated ObjectCreated; + EObjectDestroyed ObjectDestroyed; + EObjectCustom ObjectCustom; + EObjectShot ObjectShot; + EObjectBump ObjectBump; + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst) noexcept + { + /* ... */ + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.ObjectCreated.Clear(); + inst.ObjectDestroyed.Clear(); + inst.ObjectCustom.Clear(); + inst.ObjectShot.Clear(); + inst.ObjectBump.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_OBJECT; + static constexpr SQInt32 Limit = SQMOD_OBJECT_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Object"; + static constexpr const SQChar* CName = "CObject"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CPickup > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CPickup >; + friend class Reference< CPickup >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CPickup > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Pickup + { + // ---------------------------------------------------------------------------------------- + Pickup() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + EPickupCreated PickupCreated; + EPickupDestroyed PickupDestroyed; + EPickupCustom PickupCustom; + EPickupRespawn PickupRespawn; + EPickupClaimed PickupClaimed; + EPickupCollected PickupCollected; + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst) noexcept + { + /* ... */ + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.PickupCreated.Clear(); + inst.PickupDestroyed.Clear(); + inst.PickupCustom.Clear(); + inst.PickupRespawn.Clear(); + inst.PickupClaimed.Clear(); + inst.PickupCollected.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_PICKUP; + static constexpr SQInt32 Limit = SQMOD_PICKUP_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Pickup"; + static constexpr const SQChar* CName = "CPickup"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CPlayer > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CPlayer >; + friend class Reference< CPlayer >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CPlayer > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Player + { + // ---------------------------------------------------------------------------------------- + Player() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; /* Useless but required by the instance activation system */ + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + EPlayerCreated PlayerCreated; + EPlayerDestroyed PlayerDestroyed; + EPlayerCustom PlayerCustom; + EPlayerAway PlayerAway; + EPlayerGameKeys PlayerGameKeys; + EPlayerRename PlayerRename; + EPlayerRequestClass PlayerRequestClass; + EPlayerRequestSpawn PlayerRequestSpawn; + EPlayerSpawn PlayerSpawn; + EPlayerStartTyping PlayerStartTyping; + EPlayerStopTyping PlayerStopTyping; + EPlayerChat PlayerChat; + EPlayerCommand PlayerCommand; + EPlayerMessage PlayerMessage; + EPlayerHealth PlayerHealth; + EPlayerArmour PlayerArmour; + EPlayerWeapon PlayerWeapon; + EPlayerMove PlayerMove; + EPlayerWasted PlayerWasted; + EPlayerKilled PlayerKilled; + EPlayerTeamKill PlayerTeamKill; + EPlayerSpectate PlayerSpectate; + EPlayerCrashreport PlayerCrashreport; + EPlayerBurning PlayerBurning; + EPlayerCrouching PlayerCrouching; + EPlayerState PlayerState; + EPlayerAction PlayerAction; + EStateNone StateNone; + EStateNormal StateNormal; + EStateShooting StateShooting; + EStateDriver StateDriver; + EStatePassenger StatePassenger; + EStateEnterDriver StateEnterDriver; + EStateEnterPassenger StateEnterPassenger; + EStateExitVehicle StateExitVehicle; + EStateUnspawned StateUnspawned; + EActionNone ActionNone; + EActionNormal ActionNormal; + EActionAiming ActionAiming; + EActionShooting ActionShooting; + EActionJumping ActionJumping; + EActionLieDown ActionLieDown; + EActionGettingUp ActionGettingUp; + EActionJumpVehicle ActionJumpVehicle; + EActionDriving ActionDriving; + EActionDying ActionDying; + EActionWasted ActionWasted; + EActionEmbarking ActionEmbarking; + EActionDisembarking ActionDisembarking; + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst) noexcept + { + /* ... */ + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.PlayerCreated.Clear(); + inst.PlayerDestroyed.Clear(); + inst.PlayerCustom.Clear(); + inst.PlayerAway.Clear(); + inst.PlayerGameKeys.Clear(); + inst.PlayerRename.Clear(); + inst.PlayerRequestClass.Clear(); + inst.PlayerRequestSpawn.Clear(); + inst.PlayerSpawn.Clear(); + inst.PlayerStartTyping.Clear(); + inst.PlayerStopTyping.Clear(); + inst.PlayerChat.Clear(); + inst.PlayerCommand.Clear(); + inst.PlayerMessage.Clear(); + inst.PlayerHealth.Clear(); + inst.PlayerArmour.Clear(); + inst.PlayerWeapon.Clear(); + inst.PlayerMove.Clear(); + inst.PlayerWasted.Clear(); + inst.PlayerKilled.Clear(); + inst.PlayerTeamKill.Clear(); + inst.PlayerSpectate.Clear(); + inst.PlayerCrashreport.Clear(); + inst.PlayerBurning.Clear(); + inst.PlayerCrouching.Clear(); + inst.PlayerState.Clear(); + inst.PlayerAction.Clear(); + inst.StateNone.Clear(); + inst.StateNormal.Clear(); + inst.StateShooting.Clear(); + inst.StateDriver.Clear(); + inst.StatePassenger.Clear(); + inst.StateEnterDriver.Clear(); + inst.StateEnterPassenger.Clear(); + inst.StateExitVehicle.Clear(); + inst.StateUnspawned.Clear(); + inst.ActionNone.Clear(); + inst.ActionNormal.Clear(); + inst.ActionAiming.Clear(); + inst.ActionShooting.Clear(); + inst.ActionJumping.Clear(); + inst.ActionLieDown.Clear(); + inst.ActionGettingUp.Clear(); + inst.ActionJumpVehicle.Clear(); + inst.ActionDriving.Clear(); + inst.ActionDying.Clear(); + inst.ActionWasted.Clear(); + inst.ActionEmbarking.Clear(); + inst.ActionDisembarking.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_PLAYER; + static constexpr SQInt32 Limit = SQMOD_PLAYER_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Player"; + static constexpr const SQChar* CName = "CPlayer"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CSphere > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CSphere >; + friend class Reference< CSphere >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CSphere > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Sphere + { + // ---------------------------------------------------------------------------------------- + Sphere() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + ESphereCreated SphereCreated; + ESphereDestroyed SphereDestroyed; + ESphereCustom SphereCustom; + ESphereEntered SphereEntered; + ESphereExited SphereExited; + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst) noexcept + { + /* ... */ + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.SphereCreated.Clear(); + inst.SphereDestroyed.Clear(); + inst.SphereCustom.Clear(); + inst.SphereEntered.Clear(); + inst.SphereExited.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_SPHERE; + static constexpr SQInt32 Limit = SQMOD_SPHERE_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Sphere"; + static constexpr const SQChar* CName = "CSphere"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CSprite > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CSprite >; + friend class Reference< CSprite >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CSprite > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Sprite + { + // ---------------------------------------------------------------------------------------- + Sprite() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + String Path; + + // ---------------------------------------------------------------------------------------- + ESpriteCreated SpriteCreated; + ESpriteDestroyed SpriteDestroyed; + ESpriteCustom SpriteCustom; + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, const String & path) noexcept + { + inst.Path = path; + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.SpriteCreated.Clear(); + inst.SpriteDestroyed.Clear(); + inst.SpriteCustom.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_SPRITE; + static constexpr SQInt32 Limit = SQMOD_SPRITE_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Sprite"; + static constexpr const SQChar* CName = "CSprite"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CTextdraw > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CTextdraw >; + friend class Reference< CTextdraw >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CTextdraw > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Textdraw + { + // ---------------------------------------------------------------------------------------- + Textdraw() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + String Text; + + // ---------------------------------------------------------------------------------------- + ETextdrawCreated TextdrawCreated; + ETextdrawDestroyed TextdrawDestroyed; + ETextdrawCustom TextdrawCustom; + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, const String & text) noexcept + { + inst.Text = text; + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.TextdrawCreated.Clear(); + inst.TextdrawDestroyed.Clear(); + inst.TextdrawCustom.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_TEXTDRAW; + static constexpr SQInt32 Limit = SQMOD_TEXTDRAW_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Textdraw"; + static constexpr const SQChar* CName = "CTextdraw"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template <> class Ent< CVehicle > +{ +private: + + // -------------------------------------------------------------------------------------------- + friend class EntMan< CVehicle >; + friend class Reference< CVehicle >; + + // -------------------------------------------------------------------------------------------- + typedef Reference< CVehicle > RefType; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + typedef struct Vehicle + { + // ---------------------------------------------------------------------------------------- + Vehicle() : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + SQInt32 ID; + + // ---------------------------------------------------------------------------------------- + RefType* Root; + + // ---------------------------------------------------------------------------------------- + bool Owned; + bool Fresh; + + // ---------------------------------------------------------------------------------------- + SqTag Tag; + SqObj Data; + + // ---------------------------------------------------------------------------------------- + EVehicleCreated VehicleCreated; + EVehicleDestroyed VehicleDestroyed; + EVehicleCustom VehicleCustom; + EVehicleRespawn VehicleRespawn; + EVehicleExplode VehicleExplode; + EVehicleHealth VehicleHealth; + EVehicleMove VehicleMove; + EVehicleEmbarking VehicleEmbarking; + EVehicleEmbarked VehicleEmbarked; + EVehicleDisembark VehicleDisembark; + } Instance; + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst) noexcept + { + + } + + // -------------------------------------------------------------------------------------------- + static void Clear(Instance & inst) noexcept + { + inst.VehicleCreated.Clear(); + inst.VehicleDestroyed.Clear(); + inst.VehicleCustom.Clear(); + inst.VehicleRespawn.Clear(); + inst.VehicleExplode.Clear(); + inst.VehicleHealth.Clear(); + inst.VehicleMove.Clear(); + inst.VehicleEmbarking.Clear(); + inst.VehicleEmbarked.Clear(); + inst.VehicleDisembark.Clear(); + } + +public: + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 TypeID = ENT_VEHICLE; + static constexpr SQInt32 Limit = SQMOD_VEHICLE_POOL; + + // -------------------------------------------------------------------------------------------- + static constexpr const SQChar* Name = "Vehicle"; + static constexpr const SQChar* CName = "CVehicle"; + + // -------------------------------------------------------------------------------------------- + typedef std::array< Instance, Limit > Instances; +}; + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +template < class T > class Reference +{ + // -------------------------------------------------------------------------------------------- + friend class EntMan< T >; + +public: + + // -------------------------------------------------------------------------------------------- + typedef T Type; + + // -------------------------------------------------------------------------------------------- + typedef Reference< T > RefType; + + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 Max = Ent< T >::Limit; + +protected: + + // -------------------------------------------------------------------------------------------- + static typename Ent< T >::Instances s_Instances; + +protected: + + // -------------------------------------------------------------------------------------------- + SQInt32 m_ID; + + // -------------------------------------------------------------------------------------------- + SqTag m_Tag; + SqObj m_Data; + + // -------------------------------------------------------------------------------------------- + Reference< T > * m_Prev; + Reference< T > * m_Next; + + // -------------------------------------------------------------------------------------------- + bool m_Persistent; + +protected: + + /* -------------------------------------------------------------------------------------------- + * ... + */ + void InsertIntoChain() noexcept + { + if (VALID_ENTITY(m_ID)) + { + if (s_Instances[m_ID].Root) + { + m_Next = s_Instances[m_ID].Root; + m_Prev = m_Next->m_Prev; + m_Next->m_Prev = this; + } + + s_Instances[m_ID].Root = this; + } + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + void RemoveFromChain() noexcept + { + if (VALID_ENTITY(m_ID)) + { + if (m_Next) + { + m_Next->m_Prev = m_Prev; + } + + if (m_Prev) + { + m_Prev->m_Next = m_Next; + } + + if (s_Instances[m_ID].Root == this) + { + s_Instances[m_ID].Root = (m_Next ? m_Next : (m_Prev ? m_Prev : 0)); + } + + m_Next = 0; + m_Prev = 0; + } + } + +public: + + /* -------------------------------------------------------------------------------------------- + * Verify that the specified entity instacne is active + */ + static bool Verify(SQInt32 id) noexcept + { + return (VALID_ENTITYEX(id, Max) && VALID_ENTITY(s_Instances[id].ID)); + } + +public: + + /* -------------------------------------------------------------------------------------------- + * ... + */ + Reference() noexcept + : Reference(SQMOD_UNKNOWN) + { + + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + Reference(SQInt32 id) noexcept + : m_ID(Verify(id) ? id : SQMOD_UNKNOWN) + , m_Tag() + , m_Data() + , m_Prev(0) + , m_Next(0) + , m_Persistent(false) + { + InsertIntoChain(); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + Reference(const Reference< T > & r) noexcept + : m_ID(r.m_ID) + , m_Tag(r.m_Tag) + , m_Data(r.m_Data) + , m_Prev(0) + , m_Next(0) + , m_Persistent(r.m_Persistent) + { + InsertIntoChain(); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + Reference(Reference< T > && r) noexcept + : m_ID(r.m_ID) + , m_Tag(r.m_Tag) + , m_Data(r.m_Data) + , m_Prev(0) + , m_Next(0) + , m_Persistent(r.m_Persistent) + { + InsertIntoChain(); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + ~Reference() + { + RemoveFromChain(); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + Reference< T > & operator = (const Reference< T > & r) noexcept + { + if (this != &r) + { + RemoveFromChain(); + + m_ID = r.m_ID; + m_Tag = r.m_Tag; + m_Data = r.m_Data; + m_Persistent = r.m_Persistent; + + InsertIntoChain(); + } + + return *this; + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + Reference< T > & operator = (Reference< T > &&) = delete; + + /* -------------------------------------------------------------------------------------------- + * ... + */ + operator SQInt32 () const noexcept + { + return m_ID; + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + operator SQUint32 () const noexcept + { + return static_cast< SQUint32 >(m_ID); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + operator bool () const noexcept + { + return VALID_ENTITYEX(m_ID, Max); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + bool operator ! () const noexcept + { + return INVALID_ENTITYEX(m_ID, Max); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + SQInteger Cmp(const Reference< T > & r) const noexcept + { + return m_ID == r.m_ID ? 0 : (m_ID > r.m_ID ? 1 : -1); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + const SQChar * ToString() const noexcept + { + return ToStringF("%d", m_ID); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + SQInteger GetID() const noexcept + { + return m_ID; + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + void SetID(SQInt32 id) noexcept + { + if (id != m_ID) + { + RemoveFromChain(); + m_ID = id; + InsertIntoChain(); + } + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + bool GetPersistent() const noexcept + { + return m_Persistent; + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + void SetPersistent(bool toggle) noexcept + { + m_Persistent = toggle; + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + const SQChar * GetGlobalTag() const noexcept + { + if (VALID_ENTITYEX(m_ID, Max)) + { + return s_Instances[m_ID].Tag.c_str(); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return _SC(""); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + void SetGlobalTag(const SQChar * tag) const noexcept + { + if (VALID_ENTITYEX(m_ID, Max)) + { + s_Instances[m_ID].Tag.assign(tag); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + SqObj & GetGlobalData() noexcept + { + if (VALID_ENTITYEX(m_ID, Max)) + { + return s_Instances[m_ID].Data; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return NullData(); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + void SetGlobalData(SqObj & data) const noexcept + { + if (VALID_ENTITYEX(m_ID, Max)) + { + s_Instances[m_ID].Data = data; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + const SQChar * GetLocalTag() const noexcept + { + return m_Tag.c_str(); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + void SetLocalTag(const SQChar * tag) noexcept + { + m_Tag.assign(tag); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + SqObj & GetLocalData() noexcept + { + return m_Data; + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + void SetLocalData(SqObj & data) noexcept + { + m_Data = data; + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + SQUint32 GetMax() const noexcept + { + return Max; + } + + /* -------------------------------------------------------------------------------------------- + * Return a new reference from the base reference + */ + T GetReference() const noexcept + { + return T(m_ID); + } + + /* -------------------------------------------------------------------------------------------- + * Returns whether this entity reference points to an active entity + */ + bool IsActive() const noexcept + { + return VALID_ENTITYEX(m_ID, Max); + } + + /* -------------------------------------------------------------------------------------------- + * Counts the number of active references for this entity + */ + SQUint32 CountRefs() const noexcept + { + SQUint32 refs = 0; + // Make sure the reference is valid + if (VALID_ENTITYEX(m_ID, Max)) + { + // Count this instance + ++refs; + // Count backward references + for (RefType * ref = m_Prev; ref; ref = ref->m_Prev) + { + ++refs; + } + // Count forward references + for (RefType * ref = m_Next; ref; ref = ref->m_Next) + { + ++refs; + } + } + return refs; + } + + /* -------------------------------------------------------------------------------------------- + * Counts the number of persistent references for this entity + */ SQUint32 CountPersistentRefs() const noexcept + { + SQUint32 refs = 0; + // Make sure the reference is valid + if (VALID_ENTITYEX(m_ID, Max)) + { + // Count this instance if persistent + if (m_Persistent) ++refs; + // Count backward references + for (RefType * ref = m_Prev; ref; ref = ref->m_Prev) + { + if (ref->m_Persistent) + { + ++refs; + } + } + // Count forward references + for (RefType * ref = m_Next; ref; ref = ref->m_Next) + { + if (ref->m_Persistent) + { + ++refs; + } + } + } + return refs; + } + +}; + +// ------------------------------------------------------------------------------------------------ +template < class T > typename Ent< T >::Instances Reference< T >::s_Instances; + +/* ------------------------------------------------------------------------------------------------ + * Utility meant to reduce the code duplication for entity management required by the Core class +*/ + +template < class T > class EntMan +{ + // -------------------------------------------------------------------------------------------- + friend class Core; + +public: + + // -------------------------------------------------------------------------------------------- + typedef Reference< T > RefType; + typedef Ent< T > EntType; + +private: + + // -------------------------------------------------------------------------------------------- + static RefType NullRef; + + /* -------------------------------------------------------------------------------------------- + * Deactivates the specified entity instance + */ + static bool Deactivate(SQInt32 id, SqObj & payload) noexcept + { + // Make sure this entity even exists + if (RefType::Verify(id)) + { + RefType * ref = 0, bkp = 0; + + ref = RefType::s_Instances[id].Root->m_Prev; + + // Deactivate backward references + while (ref) + { + if (ref->m_Persistent) + { + // Just disable the entity if persistent + ref->m_ID = SQMOD_UNKNOWN; + // Move to the previous reference + ref = ref->m_Prev; + } + else + { + // Backup the current reference + bkp = ref; + // Move to the previous reference before unchaining + ref = ref->m_Prev; + // Now it's safe to unchain the reference + bkp->RemoveFromChain(); + } + } + + ref = RefType::s_Instances[id].Root->m_Next; + + // Deactivate forward references + while (ref) + { + if (ref->m_Persistent) + { + // Just disable the entity if persistent + ref->m_ID = SQMOD_UNKNOWN; + // Move to the next reference + ref = ref->m_Next; + } + else + { + // Backup the current reference + bkp = ref; + // Move to the next reference before unchaining + ref = ref->m_Next; + // Now it's safe to unchain the reference + bkp->RemoveFromChain(); + } + } + + // Disable this entity instance + RefType::s_Instances[id].ID = SQMOD_UNKNOWN; + + // Clear any events that are still listening + EntType::Clear(RefType::s_Instances[id]); + + // Sucessfully deactivated the instance + return true; + } + else + { + LogErr("Cannot deactivate an already deactivated <%s> instance with identifier (%d)", EntType::Name, id); + } + // Failed to destroy the entity + return false; + } + + /* -------------------------------------------------------------------------------------------- + * Activates the specified entity instance + */ + template < typename... Args > static bool Activate(SQInt32 id, bool owned, Args&&... args) noexcept + { + // Validate the specified entity identifier + if (INVALID_ENTITYEX(id, EntType::Limit)) + { + LogErr("Cannot initialize <%s> instance (%d) with invalid identifier", EntType::Name, id); + } + // Make sure this entity instance isn't already activated + else if (!RefType::Verify(id)) + { + // See if there's any persistent references to activate + if (RefType::s_Instances[id].Root) + { + // Resurect backward references + for (RefType * ref = RefType::s_Instances[id].Root->m_Prev; ref; ref = ref->m_Prev) + { + // Unnecessary check, but just to be sure + if (ref->m_Persistent) + { + ref->m_ID = id; + } + } + // Resurect forward references + for (RefType * ref = RefType::s_Instances[id].Root->m_Next; ref; ref = ref->m_Next) + { + // Unnecessary check, but just to be sure + if (ref->m_Persistent) + { + ref->m_ID = id; + } + } + } + + // Enable this entity instance + RefType::s_Instances[id].ID = id; + // Set the instance ownership + RefType::s_Instances[id].Owned = owned; + + // See if the user data needs purging + if (RefType::s_Instances[id].Fresh) + { + RefType::s_Instances[id].Tag.clear(); + RefType::s_Instances[id].Data.Release(); + } + + // Store any specified values on the instance + EntType::Store(RefType::s_Instances[id], std::forward< Args >(args)...); + + // Initialization successful + return true; + } + else + { + LogErr("Cannot activate an already activated <%s> instance with identifier (%d)", EntType::Name, id); + } + // Failed to activate the entity + return false; + } +}; + +// ------------------------------------------------------------------------------------------------ +template < class T > typename EntMan< T >::RefType EntMan< T >::NullRef; + +// ------------------------------------------------------------------------------------------------ +template < class T > bool Register_Reference(HSQUIRRELVM vm, const SQChar * cname) +{ + // Typedef the reference type to simplify code + typedef Reference< T > Ref; + // Output debugging information + LogDbg("Beginning registration of <%s> type", cname); + // Attempt to register the specified type + Sqrat::RootTable(vm).Bind(cname, Sqrat::Class< Reference< T > >(vm, cname) + .Ctor() + .template Ctor< SQInt32 >() + + .Func(_SC("_cmp"), &Ref::Cmp) + .Func(_SC("_tostring"), &Ref::ToString) + + .Prop(_SC("id"), &Ref::GetID, &Ref::SetID) + .Prop(_SC("persistent"), &Ref::GetPersistent, &Ref::SetPersistent) + .Prop(_SC("gtag"), &Ref::GetGlobalTag, &Ref::SetGlobalTag) + .Prop(_SC("gdata"), &Ref::GetGlobalData, &Ref::SetGlobalData) + .Prop(_SC("ltag"), &Ref::GetLocalTag, &Ref::SetLocalTag) + .Prop(_SC("ldata"), &Ref::GetLocalData, &Ref::SetLocalData) + + .Prop(_SC("max"), &Ref::GetMax) + .Prop(_SC("sref"), &Ref::GetReference) + .Prop(_SC("active"), &Ref::IsActive) + .Prop(_SC("refs"), &Ref::CountRefs) + .Prop(_SC("prefs"), &Ref::CountPersistentRefs) + ); + // Output debugging information + LogDbg("Registration of <%s> type was successful", cname); + // Registration succeeded + return true; +} + +} // Namespace:: SqMod + +#endif // _ENTITY_HPP_ diff --git a/source/Entity/Blip.cpp b/source/Entity/Blip.cpp new file mode 100644 index 00000000..416601b4 --- /dev/null +++ b/source/Entity/Blip.cpp @@ -0,0 +1,28 @@ +#include "Entity/Blip.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CBlip(HSQUIRRELVM vm) +{ + if (!Register_Reference< CBlip >(vm, _SC("BaseBlip"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CBlip"), Sqrat::DerivedClass< CBlip, Reference< CBlip > >(vm, _SC("CBlip")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Blip.hpp b/source/Entity/Blip.hpp new file mode 100644 index 00000000..517d694c --- /dev/null +++ b/source/Entity/Blip.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_BLIP_HPP_ +#define _ENTITY_BLIP_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CBlip : public Reference< CBlip > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_BLIP_HPP_ diff --git a/source/Entity/Checkpoint.cpp b/source/Entity/Checkpoint.cpp new file mode 100644 index 00000000..48813ccf --- /dev/null +++ b/source/Entity/Checkpoint.cpp @@ -0,0 +1,29 @@ +#include "Entity/Checkpoint.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CCheckpoint(HSQUIRRELVM vm) +{ + if (!Register_Reference< CCheckpoint >(vm, _SC("BaseCheckpoint"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CCheckpoint"), Sqrat::DerivedClass< CCheckpoint, Reference< CCheckpoint > >(vm, _SC("CCheckpoint")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Checkpoint.hpp b/source/Entity/Checkpoint.hpp new file mode 100644 index 00000000..1fdca4a9 --- /dev/null +++ b/source/Entity/Checkpoint.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_CHECKPOINT_HPP_ +#define _ENTITY_CHECKPOINT_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CCheckpoint : public Reference< CCheckpoint > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_CHECKPOINT_HPP_ \ No newline at end of file diff --git a/source/Entity/Keybind.cpp b/source/Entity/Keybind.cpp new file mode 100644 index 00000000..f956a9cc --- /dev/null +++ b/source/Entity/Keybind.cpp @@ -0,0 +1,29 @@ +#include "Entity/Keybind.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CKeybind(HSQUIRRELVM vm) +{ + if (!Register_Reference< CKeybind >(vm, _SC("BaseKeybind"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CKeybind"), Sqrat::DerivedClass< CKeybind, Reference< CKeybind > >(vm, _SC("CKeybind")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Keybind.hpp b/source/Entity/Keybind.hpp new file mode 100644 index 00000000..592bf6bd --- /dev/null +++ b/source/Entity/Keybind.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_KEYBIND_HPP_ +#define _ENTITY_KEYBIND_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CKeybind : public Reference< CKeybind > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_KEYBIND_HPP_ \ No newline at end of file diff --git a/source/Entity/Object.cpp b/source/Entity/Object.cpp new file mode 100644 index 00000000..5b9558d5 --- /dev/null +++ b/source/Entity/Object.cpp @@ -0,0 +1,29 @@ +#include "Entity/Object.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CObject(HSQUIRRELVM vm) +{ + if (!Register_Reference< CObject >(vm, _SC("BaseObject"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CObject"), Sqrat::DerivedClass< CObject, Reference< CObject > >(vm, _SC("CObject")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Object.hpp b/source/Entity/Object.hpp new file mode 100644 index 00000000..0723fe3d --- /dev/null +++ b/source/Entity/Object.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_OBJECT_HPP_ +#define _ENTITY_OBJECT_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CObject : public Reference< CObject > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_OBJECT_HPP_ \ No newline at end of file diff --git a/source/Entity/Pickup.cpp b/source/Entity/Pickup.cpp new file mode 100644 index 00000000..53cc1ebe --- /dev/null +++ b/source/Entity/Pickup.cpp @@ -0,0 +1,29 @@ +#include "Entity/Pickup.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CPickup(HSQUIRRELVM vm) +{ + if (!Register_Reference< CPickup >(vm, _SC("BasePickup"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CPickup"), Sqrat::DerivedClass< CPickup, Reference< CPickup > >(vm, _SC("CPickup")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Pickup.hpp b/source/Entity/Pickup.hpp new file mode 100644 index 00000000..c9d73f27 --- /dev/null +++ b/source/Entity/Pickup.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_PICKUP_HPP_ +#define _ENTITY_PICKUP_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CPickup : public Reference< CPickup > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_PICKUP_HPP_ \ No newline at end of file diff --git a/source/Entity/Player.cpp b/source/Entity/Player.cpp new file mode 100644 index 00000000..938425a5 --- /dev/null +++ b/source/Entity/Player.cpp @@ -0,0 +1,29 @@ +#include "Entity/Player.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CPlayer(HSQUIRRELVM vm) +{ + if (!Register_Reference< CPlayer >(vm, _SC("BasePlayer"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CPlayer"), Sqrat::DerivedClass< CPlayer, Reference< CPlayer > >(vm, _SC("CPlayer")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Player.hpp b/source/Entity/Player.hpp new file mode 100644 index 00000000..641b5226 --- /dev/null +++ b/source/Entity/Player.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_PLAYER_HPP_ +#define _ENTITY_PLAYER_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CPlayer : public Reference< CPlayer > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_PLAYER_HPP_ \ No newline at end of file diff --git a/source/Entity/Sphere.cpp b/source/Entity/Sphere.cpp new file mode 100644 index 00000000..9987dad4 --- /dev/null +++ b/source/Entity/Sphere.cpp @@ -0,0 +1,29 @@ +#include "Entity/Sphere.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CSphere(HSQUIRRELVM vm) +{ + if (!Register_Reference< CSphere >(vm, _SC("BaseSphere"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CSphere"), Sqrat::DerivedClass< CSphere, Reference< CSphere > >(vm, _SC("CSphere")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Sphere.hpp b/source/Entity/Sphere.hpp new file mode 100644 index 00000000..787c882f --- /dev/null +++ b/source/Entity/Sphere.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_SPHERE_HPP_ +#define _ENTITY_SPHERE_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CSphere : public Reference< CSphere > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_SPHERE_HPP_ \ No newline at end of file diff --git a/source/Entity/Sprite.cpp b/source/Entity/Sprite.cpp new file mode 100644 index 00000000..9dff82ee --- /dev/null +++ b/source/Entity/Sprite.cpp @@ -0,0 +1,29 @@ +#include "Entity/Sprite.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CSprite(HSQUIRRELVM vm) +{ + if (!Register_Reference< CSprite >(vm, _SC("BaseSprite"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CSprite"), Sqrat::DerivedClass< CSprite, Reference< CSprite > >(vm, _SC("CSprite")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Sprite.hpp b/source/Entity/Sprite.hpp new file mode 100644 index 00000000..77ba142e --- /dev/null +++ b/source/Entity/Sprite.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_SPRITE_HPP_ +#define _ENTITY_SPRITE_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CSprite : public Reference< CSprite > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_SPRITE_HPP_ \ No newline at end of file diff --git a/source/Entity/Textdraw.cpp b/source/Entity/Textdraw.cpp new file mode 100644 index 00000000..31dd42a8 --- /dev/null +++ b/source/Entity/Textdraw.cpp @@ -0,0 +1,29 @@ +#include "Entity/Textdraw.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CTextdraw(HSQUIRRELVM vm) +{ + if (!Register_Reference< CTextdraw >(vm, _SC("BaseTextdraw"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CTextdraw"), Sqrat::DerivedClass< CTextdraw, Reference< CTextdraw > >(vm, _SC("CTextdraw")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Textdraw.hpp b/source/Entity/Textdraw.hpp new file mode 100644 index 00000000..e939d7b6 --- /dev/null +++ b/source/Entity/Textdraw.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_TEXTDRAW_HPP_ +#define _ENTITY_TEXTDRAW_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CTextdraw : public Reference< CTextdraw > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_TEXTDRAW_HPP_ \ No newline at end of file diff --git a/source/Entity/Vehicle.cpp b/source/Entity/Vehicle.cpp new file mode 100644 index 00000000..a19bc8bf --- /dev/null +++ b/source/Entity/Vehicle.cpp @@ -0,0 +1,29 @@ +#include "Entity/Vehicle.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CVehicle(HSQUIRRELVM vm) +{ + if (!Register_Reference< CVehicle >(vm, _SC("BaseVehicle"))) + { + LogDbg("Unable to register the base class for type"); + + return false; + } + + LogDbg("Beginning registration of type"); + + Sqrat::RootTable(vm).Bind(_SC("CVehicle"), Sqrat::DerivedClass< CVehicle, Reference< CVehicle > >(vm, _SC("CVehicle")) + .Ctor() + .Ctor< SQInt32 >() + ); + + LogDbg("Registration of type was successful"); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Entity/Vehicle.hpp b/source/Entity/Vehicle.hpp new file mode 100644 index 00000000..0a0b34fd --- /dev/null +++ b/source/Entity/Vehicle.hpp @@ -0,0 +1,22 @@ +#ifndef _ENTITY_VEHICLE_HPP_ +#define _ENTITY_VEHICLE_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CVehicle : public Reference< CVehicle > +{ +public: + // -------------------------------------------------------------------------------------------- + using RefType::Reference; +}; + +} // Namespace:: SqMod + +#endif // _ENTITY_VEHICLE_HPP_ \ No newline at end of file diff --git a/source/Iterators.cpp b/source/Iterators.cpp new file mode 100644 index 00000000..e69de29b diff --git a/source/Iterators.hpp b/source/Iterators.hpp new file mode 100644 index 00000000..e69de29b diff --git a/source/Library/CFG.cpp b/source/Library/CFG.cpp new file mode 100644 index 00000000..3b7f9f6b --- /dev/null +++ b/source/Library/CFG.cpp @@ -0,0 +1,13 @@ +#include "Library/CFG.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CFG(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/CFG.hpp b/source/Library/CFG.hpp new file mode 100644 index 00000000..4f04e67b --- /dev/null +++ b/source/Library/CFG.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_CFG_HPP_ +#define _LIBRARY_CFG_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_CFG_HPP_ \ No newline at end of file diff --git a/source/Library/Datetime.cpp b/source/Library/Datetime.cpp new file mode 100644 index 00000000..900fd8c3 --- /dev/null +++ b/source/Library/Datetime.cpp @@ -0,0 +1,13 @@ +#include "Library/Datetime.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_Datetime(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/Datetime.hpp b/source/Library/Datetime.hpp new file mode 100644 index 00000000..0243a4b6 --- /dev/null +++ b/source/Library/Datetime.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_DATETIME_HPP_ +#define _LIBRARY_DATETIME_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_DATETIME_HPP_ \ No newline at end of file diff --git a/source/Library/FileIO.cpp b/source/Library/FileIO.cpp new file mode 100644 index 00000000..af513f14 --- /dev/null +++ b/source/Library/FileIO.cpp @@ -0,0 +1,13 @@ +#include "Library/FileIO.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_FileIO(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/FileIO.hpp b/source/Library/FileIO.hpp new file mode 100644 index 00000000..d4eafac6 --- /dev/null +++ b/source/Library/FileIO.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_FILEIO_HPP_ +#define _LIBRARY_FILEIO_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_FILEIO_HPP_ \ No newline at end of file diff --git a/source/Library/Format.cpp b/source/Library/Format.cpp new file mode 100644 index 00000000..c85fda56 --- /dev/null +++ b/source/Library/Format.cpp @@ -0,0 +1,166 @@ +#include "Library/Format.hpp" +#include "Register.hpp" +#include "Logger.hpp" +#include "Core.hpp" + +// ------------------------------------------------------------------------------------------------ +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +static const SQChar * GetTypeName(SQObjectType type_id) noexcept +{ + switch (type_id) + { + case OT_INTEGER: + return _SC("integer"); + case OT_FLOAT: + return _SC("float"); + case OT_STRING: + return _SC("string"); + case OT_BOOL: + return _SC("boolean"); + case OT_USERPOINTER: + return _SC("user pointer"); + case OT_NULL: + return _SC("null"); + case OT_TABLE: + return _SC("table"); + case OT_ARRAY: + return _SC("array"); + case OT_CLOSURE: + return _SC("closure"); + case OT_NATIVECLOSURE: + return _SC("native closure"); + case OT_GENERATOR: + return _SC("generator"); + case OT_USERDATA: + return _SC("user data"); + case OT_THREAD: + return _SC("thread"); + case OT_CLASS: + return _SC("class"); + case OT_INSTANCE: + return _SC("instance"); + case OT_WEAKREF: + return _SC("weak reference"); + default: + return _SC("unknown"); + } +} + +// ------------------------------------------------------------------------------------------------ +String GetFormatStr(HSQUIRRELVM vm, SQInteger arg, SQInteger args) noexcept +{ + if (sq_gettype(vm, arg) == OT_STRING) + { + const SQChar * str = 0; + sq_getstring(vm, arg, &str); + return GetFormatStr(vm, (str == NULL ? "" : str), ++arg, args); + } + else + { + LogErr("Expecting format string but got: %s", GetTypeName(sq_gettype(vm, arg))); + } + return String(); +} + +// ------------------------------------------------------------------------------------------------ +String GetFormatStr(HSQUIRRELVM vm, const String & fstr, SQInteger arg, SQInteger args) noexcept +{ + using namespace fmt::internal; + + String str; + + if (args-arg > 15) + { + LogErr("Too many arguments to format"); + return str; + } + else if (fstr.empty()) + { + return str; + } + else if (arg == args) + { + // Unnecessary but should throw an error when trying to format something without arguments + try + { + str = fmt::format(fstr); + } + catch (const fmt::SystemError & e) + { + LogErr(e.what()); + } + return str; + } + + const SQChar * sval = 0; + SQInteger ival; + SQFloat fval; + SQUserPointer pval; + + std::vector< MakeValue< SQChar > > vlist; + vlist.reserve(args-arg); + std::uint64_t vtype = 0x0; + + for (unsigned sh = 0;arg <= args; arg++, sh += 4) + { + switch(sq_gettype(vm, arg)) + { + case OT_INTEGER: + sq_getinteger(vm, arg, &ival); + vlist.emplace_back(ival); + vtype |= (MakeValue< SQChar >::type(ival) << sh); + break; + case OT_FLOAT: + sq_getfloat(vm, arg, &fval); + vlist.emplace_back(fval); + vtype |= (MakeValue< SQChar >::type(fval) << sh); + break; + case OT_STRING: + sq_getstring(vm, arg, &sval); + vlist.emplace_back(sval); + vtype |= (MakeValue< SQChar >::type(sval) << sh); + break; + case OT_BOOL: + sq_getinteger(vm, arg, &ival); + vlist.emplace_back(static_cast(ival)); + vtype |= (MakeValue< SQChar >::type(static_cast(ival)) << sh); + break; + case OT_USERPOINTER: + sq_getuserpointer(vm, arg, &pval); + vlist.emplace_back(static_cast(pval)); + vtype |= (MakeValue< SQChar >::type(static_cast(pval)) << sh); + break; + default: + LogErr("Cannot format (%s) data type", GetTypeName(sq_gettype(vm, arg))); + return str; + } + } + + vlist.shrink_to_fit(); + + try + { + fmt::BasicMemoryWriter w; + w.write(fstr, fmt::ArgList(vtype, vlist.data())); + str = w.c_str(); + } + catch (const fmt::SystemError & e) + { + LogErr("%s", e.what()); + } + + return str; +} + +// ------------------------------------------------------------------------------------------------ +bool Register_Format(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod diff --git a/source/Library/Format.hpp b/source/Library/Format.hpp new file mode 100644 index 00000000..950f30ec --- /dev/null +++ b/source/Library/Format.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_FORMAT_HPP_ +#define _LIBRARY_FORMAT_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +String GetFormatStr(HSQUIRRELVM vm, SQInteger arg, SQInteger args) noexcept; +String GetFormatStr(HSQUIRRELVM vm, const String & fstr, SQInteger arg, SQInteger args) noexcept; + +} // Namespace:: SqMod + +#endif // _LIBRARY_FORMAT_HPP_ \ No newline at end of file diff --git a/source/Library/INI.cpp b/source/Library/INI.cpp new file mode 100644 index 00000000..4cbd5e35 --- /dev/null +++ b/source/Library/INI.cpp @@ -0,0 +1,13 @@ +#include "Library/INI.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_INI(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/INI.hpp b/source/Library/INI.hpp new file mode 100644 index 00000000..ac5a1acc --- /dev/null +++ b/source/Library/INI.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_INI_HPP_ +#define _LIBRARY_INI_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_INI_HPP_ \ No newline at end of file diff --git a/source/Library/JSON.cpp b/source/Library/JSON.cpp new file mode 100644 index 00000000..c95ec3fd --- /dev/null +++ b/source/Library/JSON.cpp @@ -0,0 +1,13 @@ +#include "Library/JSON.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_JSON(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/JSON.hpp b/source/Library/JSON.hpp new file mode 100644 index 00000000..32141d08 --- /dev/null +++ b/source/Library/JSON.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_JSON_HPP_ +#define _LIBRARY_JSON_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_JSON_HPP_ \ No newline at end of file diff --git a/source/Library/LongInt.cpp b/source/Library/LongInt.cpp new file mode 100644 index 00000000..5b9ad943 --- /dev/null +++ b/source/Library/LongInt.cpp @@ -0,0 +1,60 @@ +#include "Library/LongInt.hpp" +//#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_LongInt(HSQUIRRELVM vm) +{ +/* + Sqrat::RootTable(vm).Bind(_SC("SLongInt"), Sqrat::Class(vm, _SC("SLongInt")) + .Ctor() + .Ctor(SLongInt::Value) + .Ctor(const SQChar *, SQInteger) + + .Prop(_SC("str"), &SLongInt::GetCStr, &SLongInt::SetStr) + .Prop(_SC("num"), &SLongInt::GetSNum, &SLongInt::SetNum) + + .Func(_SC("_tostring"), &SLongInt::ToString) + .Func(_SC("_cmp"), &SLongInt::Cmp) + + .Func(_SC("_add"), &SLongInt::operator +) + .Func(_SC("_sub"), &SLongInt::operator -) + .Func(_SC("_mul"), &SLongInt::operator *) + .Func(_SC("_div"), &SLongInt::operator /) + .Func(_SC("_modulo"), &SLongInt::operator %) + + .Func(_SC("_unm"), &SLongInt::operator -) + + .Overload(_SC("random"), &SLongInt::Random) + .Overload(_SC("random"), &SLongInt::Random) + ); + + Sqrat::RootTable(vm).Bind(_SC("ULongInt"), Sqrat::Class(vm, _SC("ULongInt")) + .Ctor() + .Ctor(ULongInt::Value) + .Ctor(const SQChar *, SQInteger) + + .Prop(_SC("str"), &ULongInt::GetCStr, &ULongInt::SetStr) + .Prop(_SC("num"), &ULongInt::GetSNum, &ULongInt::SetNum) + + .Func(_SC("_tostring"), &ULongInt::ToString) + .Func(_SC("_cmp"), &ULongInt::Cmp) + + .Func(_SC("_add"), &ULongInt::operator +) + .Func(_SC("_sub"), &ULongInt::operator -) + .Func(_SC("_mul"), &ULongInt::operator *) + .Func(_SC("_div"), &ULongInt::operator /) + .Func(_SC("_modulo"), &ULongInt::operator %) + + .Func(_SC("_unm"), &ULongInt::operator -) + + .Overload(_SC("random"), &ULongInt::Random) + .Overload(_SC("random"), &ULongInt::Random) + ); +*/ + return true; +} + +} // Namespace:: SqMod diff --git a/source/Library/LongInt.hpp b/source/Library/LongInt.hpp new file mode 100644 index 00000000..3b18b9a9 --- /dev/null +++ b/source/Library/LongInt.hpp @@ -0,0 +1,243 @@ +#ifndef _LIBRARY_LONGINT_HPP_ +#define _LIBRARY_LONGINT_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" + +// ------------------------------------------------------------------------------------------------ +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +template class LongInt +{ +public: + // -------------------------------------------------------------------------------------------- + static_assert(std::is_integral::value, "LongInt type is not an integral type"); + + // -------------------------------------------------------------------------------------------- + typedef T Value; + + // -------------------------------------------------------------------------------------------- + LongInt() noexcept + : m_Data(0), m_Text() + { + + } + + template + LongInt(U data) noexcept + { + *this = data; + } + + // -------------------------------------------------------------------------------------------- + LongInt(const SQChar * text) noexcept + { + *this = text; + } + + LongInt(const SQChar * text, SQInteger overload = 0) noexcept + { + *this = text; + } + + // -------------------------------------------------------------------------------------------- + LongInt(const LongInt & i) noexcept + : m_Data(i.m_Data), m_Text(i.m_Text) + { + + } + + LongInt(LongInt && i) noexcept + : m_Data(i.m_Data), m_Text(std::move(i.m_Text)) + { + + } + + // -------------------------------------------------------------------------------------------- + ~LongInt() + { + + } + + // -------------------------------------------------------------------------------------------- + LongInt & operator = (const LongInt & i) noexcept + { + m_Data = i.m_Data; + m_Text = i.m_Text; + + return *this; + } + + LongInt & operator = (LongInt && i) noexcept + { + m_Data = i.m_Data; + m_Text = std::move(i.m_Text); + + return *this; + } + + // -------------------------------------------------------------------------------------------- + template ::value>::type* = nullptr> + LongInt & operator = (U data) noexcept + { + m_Data = static_cast(data); + m_Text = std::to_string(m_Data); + return *this; + } + + LongInt & operator = (const SQChar * text) noexcept + { + m_Text = text; + try + { + m_Data = SToI(text, 0, 10); + } + catch (const std::invalid_argument & e) + { + LogErr("Unable to extract number: %s", e.what()); + } + return *this; + } + + // -------------------------------------------------------------------------------------------- + bool operator == (const LongInt & x) const noexcept + { + return (m_Data == x.m_Data); + } + + bool operator != (const LongInt & x) const noexcept + { + return (m_Data != x.m_Data); + } + + bool operator < (const LongInt & x) const noexcept + { + return (m_Data < x.m_Data); + } + + bool operator > (const LongInt & x) const noexcept + { + return (m_Data > x.m_Data); + } + + bool operator <= (const LongInt & x) const noexcept + { + return (m_Data <= x.m_Data); + } + + bool operator >= (const LongInt & x) const noexcept + { + return (m_Data >= x.m_Data); + } + + // -------------------------------------------------------------------------------------------- + inline operator T () const noexcept + { + return m_Data; + } + + // -------------------------------------------------------------------------------------------- + LongInt operator + (const LongInt & x) const noexcept + { + return LongInt(m_Data + x.m_Data); + } + + LongInt operator - (const LongInt & x) const noexcept + { + return LongInt(m_Data - x.m_Data); + } + + LongInt operator * (const LongInt & x) const noexcept + { + return LongInt(m_Data * x.m_Data); + } + + LongInt operator / (const LongInt & x) const noexcept + { + return LongInt(m_Data / x.m_Data); + } + + LongInt operator % (const LongInt & x) const noexcept + { + return LongInt(m_Data % x.m_Data); + } + + // -------------------------------------------------------------------------------------------- + LongInt operator - () const noexcept + { + return LongInt(-m_Data); + } + + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const LongInt & x) const noexcept + { + return m_Data == x.m_Data ? 0 : (m_Data > x.m_Data ? 1 : -1); + } + + const SQChar * ToString() const noexcept + { + return m_Text.c_str(); + } + + // -------------------------------------------------------------------------------------------- + void SetNum(T data) noexcept + { + *this = data; + } + + T GetNum() const noexcept + { + return m_Data; + } + + SQInteger GetSNum() const noexcept + { + return static_cast(m_Data); + } + + // -------------------------------------------------------------------------------------------- + void SetStr(const SQChar * text) noexcept + { + *this = text; + } + + const String & GetStr() const noexcept + { + return m_Text; + } + + const SQChar * GetCStr() const noexcept + { + return m_Text.c_str(); + } + + // -------------------------------------------------------------------------------------------- + void Random() noexcept + { + m_Data = RandomVal::Get(); + m_Text = std::to_string(m_Data); + } + + void Random(T min, T max) noexcept + { + m_Data = RandomVal::Get(min, max); + m_Text = std::to_string(m_Data); + } + +private: + // -------------------------------------------------------------------------------------------- + T m_Data; + String m_Text; +}; + +// ------------------------------------------------------------------------------------------------ +typedef LongInt SLongInt; +typedef LongInt ULongInt; + +} // Namespace:: SqMod + +#endif // _LIBRARY_LONGINT_HPP_ diff --git a/source/Library/Math.cpp b/source/Library/Math.cpp new file mode 100644 index 00000000..cb804fc6 --- /dev/null +++ b/source/Library/Math.cpp @@ -0,0 +1,13 @@ +#include "Library/Math.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_Math(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/Math.hpp b/source/Library/Math.hpp new file mode 100644 index 00000000..b44ffbfd --- /dev/null +++ b/source/Library/Math.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_MATH_HPP_ +#define _LIBRARY_MATH_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_MATH_HPP_ \ No newline at end of file diff --git a/source/Library/Numeric.cpp b/source/Library/Numeric.cpp new file mode 100644 index 00000000..2516a77a --- /dev/null +++ b/source/Library/Numeric.cpp @@ -0,0 +1,13 @@ +#include "Library/Numeric.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_Numeric(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/Numeric.hpp b/source/Library/Numeric.hpp new file mode 100644 index 00000000..f212de19 --- /dev/null +++ b/source/Library/Numeric.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_NUMERIC_HPP_ +#define _LIBRARY_NUMERIC_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_NUMERIC_HPP_ \ No newline at end of file diff --git a/source/Library/Shared.cpp b/source/Library/Shared.cpp new file mode 100644 index 00000000..8d69bc92 --- /dev/null +++ b/source/Library/Shared.cpp @@ -0,0 +1,14 @@ +#include "Library/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_Library(HSQUIRRELVM vm) +{ + return true; +} + + +} // Namespace:: SqMod diff --git a/source/Library/Shared.hpp b/source/Library/Shared.hpp new file mode 100644 index 00000000..650e3f41 --- /dev/null +++ b/source/Library/Shared.hpp @@ -0,0 +1,12 @@ +#ifndef _LIBRARY_SHARED_HPP_ +#define _LIBRARY_SHARED_HPP_ + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ + + +} // Namespace:: SqMod + +#endif // _LIBRARY_SHARED_HPP_ \ No newline at end of file diff --git a/source/Library/String.cpp b/source/Library/String.cpp new file mode 100644 index 00000000..f5b51c36 --- /dev/null +++ b/source/Library/String.cpp @@ -0,0 +1,13 @@ +#include "Library/String.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_String(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/String.hpp b/source/Library/String.hpp new file mode 100644 index 00000000..da0ecf6f --- /dev/null +++ b/source/Library/String.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_STRING_HPP_ +#define _LIBRARY_STRING_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_STRING_HPP_ \ No newline at end of file diff --git a/source/Library/SysPath.cpp b/source/Library/SysPath.cpp new file mode 100644 index 00000000..baea1b82 --- /dev/null +++ b/source/Library/SysPath.cpp @@ -0,0 +1,13 @@ +#include "Library/SysPath.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_SysPath(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/SysPath.hpp b/source/Library/SysPath.hpp new file mode 100644 index 00000000..1a1f3259 --- /dev/null +++ b/source/Library/SysPath.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_SYSPATH_HPP_ +#define _LIBRARY_SYSPATH_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_SYSPATH_HPP_ \ No newline at end of file diff --git a/source/Library/System.cpp b/source/Library/System.cpp new file mode 100644 index 00000000..cc5c8d3d --- /dev/null +++ b/source/Library/System.cpp @@ -0,0 +1,13 @@ +#include "Library/System.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_System(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/System.hpp b/source/Library/System.hpp new file mode 100644 index 00000000..bed13615 --- /dev/null +++ b/source/Library/System.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_SYSTEM_HPP_ +#define _LIBRARY_SYSTEM_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_SYSTEM_HPP_ \ No newline at end of file diff --git a/source/Library/Timer.cpp b/source/Library/Timer.cpp new file mode 100644 index 00000000..5fc9b086 --- /dev/null +++ b/source/Library/Timer.cpp @@ -0,0 +1,13 @@ +#include "Library/Timer.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_Timer(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/Timer.hpp b/source/Library/Timer.hpp new file mode 100644 index 00000000..73fb939c --- /dev/null +++ b/source/Library/Timer.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_TIMER_HPP_ +#define _LIBRARY_TIMER_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_TIMER_HPP_ \ No newline at end of file diff --git a/source/Library/Utils.cpp b/source/Library/Utils.cpp new file mode 100644 index 00000000..2f0e8f50 --- /dev/null +++ b/source/Library/Utils.cpp @@ -0,0 +1,13 @@ +#include "Library/Utils.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_Utils(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/Utils.hpp b/source/Library/Utils.hpp new file mode 100644 index 00000000..a8b8e84c --- /dev/null +++ b/source/Library/Utils.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_UTILS_HPP_ +#define _LIBRARY_UTILS_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_UTILS_HPP_ \ No newline at end of file diff --git a/source/Library/XML.cpp b/source/Library/XML.cpp new file mode 100644 index 00000000..b11ecfc0 --- /dev/null +++ b/source/Library/XML.cpp @@ -0,0 +1,13 @@ +#include "Library/XML.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_XML(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Library/XML.hpp b/source/Library/XML.hpp new file mode 100644 index 00000000..eb4947f5 --- /dev/null +++ b/source/Library/XML.hpp @@ -0,0 +1,16 @@ +#ifndef _LIBRARY_XML_HPP_ +#define _LIBRARY_XML_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Config.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ + +} // Namespace:: SqMod + +#endif // _LIBRARY_XML_HPP_ \ No newline at end of file diff --git a/source/Logger.cpp b/source/Logger.cpp new file mode 100644 index 00000000..98ad05b6 --- /dev/null +++ b/source/Logger.cpp @@ -0,0 +1,381 @@ +#include "Logger.hpp" + +// ------------------------------------------------------------------------------------------------ +#include +#include +#include + +// ------------------------------------------------------------------------------------------------ +namespace { + +#ifdef SQMOD_OS_WINDOWS + #include + + enum + { + LOG_COLOR_NORMAL = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, + LOG_COLOR_WHITE = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, + LOG_COLOR_GRAY = FOREGROUND_INTENSITY, + LOG_COLOR_LIGHT_BLUE = FOREGROUND_INTENSITY | FOREGROUND_BLUE, + LOG_COLOR_DARK_BLUE = FOREGROUND_BLUE, + LOG_COLOR_LIGHT_GREEN = FOREGROUND_INTENSITY | FOREGROUND_GREEN, + LOG_COLOR_DARK_GREEN = FOREGROUND_GREEN, + LOG_COLOR_LIGHT_CYAN = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE, + LOG_COLOR_DARK_CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE, + LOG_COLOR_LIGHT_YELLOW = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN, + LOG_COLOR_DARK_YELLOW = FOREGROUND_RED | FOREGROUND_GREEN, + LOG_COLOR_LIGHT_RED = FOREGROUND_INTENSITY | FOREGROUND_RED, + LOG_COLOR_DARK_RED = FOREGROUND_RED, + LOG_COLOR_LIGHT_MAGENTA = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE, + LOG_COLOR_DARK_MAGENTA = FOREGROUND_RED | FOREGROUND_BLUE + }; + + enum + { + LOG_COLOR_DBG = LOG_COLOR_LIGHT_BLUE, + LOG_COLOR_MSG = LOG_COLOR_GRAY, + LOG_COLOR_SCS = LOG_COLOR_LIGHT_GREEN, + LOG_COLOR_INF = LOG_COLOR_LIGHT_CYAN, + LOG_COLOR_WRN = LOG_COLOR_LIGHT_YELLOW, + LOG_COLOR_ERR = LOG_COLOR_LIGHT_MAGENTA, + LOG_COLOR_FTL = LOG_COLOR_LIGHT_RED + }; + +#endif // SQMOD_OS_WINDOWS + +} // Namespace:: + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const Logger::Pointer _Log = Logger::Inst(); + +// ------------------------------------------------------------------------------------------------ +inline const char * GetLevelTag(Uint8 type) noexcept +{ + switch (type) + { + case Logger::LEVEL_DBG: return "[DBG]"; + case Logger::LEVEL_MSG: return "[MSG]"; + case Logger::LEVEL_SCS: return "[SCS]"; + case Logger::LEVEL_INF: return "[INF]"; + case Logger::LEVEL_WRN: return "[WRN]"; + case Logger::LEVEL_ERR: return "[ERR]"; + case Logger::LEVEL_FTL: return "[FTL]"; + default: return "[UNK]"; + } +} + +#ifdef SQMOD_OS_WINDOWS + +// ------------------------------------------------------------------------------------------------ +inline Uint16 GetLevelColor(Uint8 type) noexcept +{ + switch (type) + { + case Logger::LEVEL_DBG: return LOG_COLOR_DBG; + case Logger::LEVEL_MSG: return LOG_COLOR_MSG; + case Logger::LEVEL_SCS: return LOG_COLOR_SCS; + case Logger::LEVEL_INF: return LOG_COLOR_INF; + case Logger::LEVEL_WRN: return LOG_COLOR_WRN; + case Logger::LEVEL_ERR: return LOG_COLOR_ERR; + case Logger::LEVEL_FTL: return LOG_COLOR_FTL; + default: return LOG_COLOR_NORMAL; + } +} +#else + +// ------------------------------------------------------------------------------------------------ +inline const char * GetLevelColor(Uint8 type) noexcept +{ + return ""; +} + +#endif // SQMOD_OS_WINDOWS + +// ------------------------------------------------------------------------------------------------ +Logger::Logger() noexcept + : m_ConsoleTime(false), m_FileTime(true) + , m_ConsoleLevels(Logger::LEVEL_ANY), m_FileLevels(Logger::LEVEL_ANY) + , m_LogPath("./logs/"), m_DebugLevel(SQMOD_DEBUG_LEVEL), m_Verbosity(0) +{ + +} + +// ------------------------------------------------------------------------------------------------ +Logger::~Logger() +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Logger::_Finalizer(Logger * ptr) noexcept +{ + if (ptr) delete ptr; +} + +// ------------------------------------------------------------------------------------------------ +Logger::Pointer Logger::Inst() noexcept +{ + if (!_Log) return Pointer(new Logger(), &Logger::_Finalizer); + return Pointer(nullptr, &Logger::_Finalizer); +} + +// ------------------------------------------------------------------------------------------------ +bool Logger::Init() +{ + + return true; +} + +bool Logger::Load() +{ + + return true; +} + +// ------------------------------------------------------------------------------------------------ +void Logger::Deinit() +{ + +} + +void Logger::Unload() +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Logger::Terminate() +{ + +} + +// ------------------------------------------------------------------------------------------------ +void Logger::ToggleConsoleTime(bool enabled) noexcept +{ + m_ConsoleTime = enabled; +} + +void Logger::ToggleFileTime(bool enabled) noexcept +{ + m_FileTime = enabled; +} + +// ------------------------------------------------------------------------------------------------ +bool Logger::HasConsoleTime() const noexcept +{ + return m_ConsoleTime; +} + +bool Logger::HasFileTime()const noexcept +{ + return m_FileTime; +} + +// ------------------------------------------------------------------------------------------------ +void Logger::SetConsoleLevels(Uint8 levels) noexcept +{ + m_ConsoleLevels = levels; +} + +void Logger::SetFileLevels(Uint8 levels) noexcept +{ + m_FileLevels = levels; +} + +// ------------------------------------------------------------------------------------------------ +Uint8 Logger::GetConsoleLevels() const noexcept +{ + return m_ConsoleLevels; +} + +Uint8 Logger::GetFileLevels() const noexcept +{ + return m_FileLevels; +} + +// ------------------------------------------------------------------------------------------------ +void Logger::EnableConsoleLevel(Uint8 level) noexcept +{ + m_ConsoleLevels |= level; +} + +void Logger::EnableFileLevel(Uint8 level) noexcept +{ + m_FileLevels |= level; +} + +// ------------------------------------------------------------------------------------------------ +void Logger::DisableConsoleLevel(Uint8 level) noexcept +{ + if (m_ConsoleLevels & level) m_ConsoleLevels ^= level; +} + +void Logger::DisableFileLevel(Uint8 level) noexcept +{ + if (m_FileLevels & level) m_FileLevels ^= level; +} + +// ------------------------------------------------------------------------------------------------ +Uint8 Logger::GetDebugLevel() const noexcept +{ + return m_DebugLevel; +} + +void Logger::SetDebugLevel(Uint8 level) noexcept +{ + m_DebugLevel = level; +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 Logger::GetVerbosity() const noexcept +{ + return m_Verbosity; +} + +void Logger::SetVerbosity(SQInt32 level) noexcept +{ + m_Verbosity = level; +} + +// ------------------------------------------------------------------------------------------------ +void Logger::Send(Uint8 type, bool sub, const char * fmt, va_list args) noexcept +{ + // Verify that this level is allowed to be streamed + if (!(m_ConsoleLevels & type) && !(m_FileLevels & type)) return; + + // Allocate space for the time stamp string + char timebuff[80]; + + // Grab the local time into a string if required + if (m_ConsoleTime || m_FileTime) + { + // Create the variables required to retrieve the time. + time_t rawtime; + struct tm * timeinfo; + + // Retrieve the local time. + time(&rawtime); + timeinfo = localtime(&rawtime); + + // Format the retrieved time. + strftime(timebuff, 80, "%Y-%m-%d %H:%M:%S", timeinfo); + } + + // Output to console if streaming to console is enabled + if (m_ConsoleLevels & type) + { +#ifdef SQMOD_OS_WINDOWS + // Get the handle to the output stream + HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE); + + // Save the current state of the console screen buffer + CONSOLE_SCREEN_BUFFER_INFO csb_state; + GetConsoleScreenBufferInfo(hstdout, &csb_state); + + // Set the attributes for the message information + SetConsoleTextAttribute(hstdout, GetLevelColor(type)); + + // Output the message information + if (m_ConsoleTime) + { + printf("%s %s ", GetLevelTag(type), timebuff); + } + else + { + printf("%s ", GetLevelTag(type)); + } + + // Set the attributes for the message content + SetConsoleTextAttribute(hstdout, sub ? LOG_COLOR_NORMAL : LOG_COLOR_WHITE); + + // Print the specified message + vprintf(fmt, args); + + // Restore the state of the console screen buffer + SetConsoleTextAttribute(hstdout, csb_state.wAttributes); +#else + // Output the message information + if (m_ConsoleTime) + { + printf("%s %s ", GetLevelTag(type), timebuff); + } + else + { + printf("%s ", GetLevelTag(type)); + } + + // Print the specified message + vprintf(fmt, args); +#endif // SQMOD_OS_WINDOWS + + // Terminate the line + puts(""); + } +} + +// ------------------------------------------------------------------------------------------------ +#define SQMOD_LOG(N_, L_, S_) /* +*/ void Logger::N_(const char * fmt, ...) noexcept /* +*/ { /* +*/ va_list args; /* +*/ va_start(args, fmt); /* +*/ Send(L_, S_, fmt, args); /* +*/ va_end(args); /* +*/ } /* +*/ + +// ------------------------------------------------------------------------------------------------ +SQMOD_LOG(Dbg, LEVEL_DBG, false) +SQMOD_LOG(Msg, LEVEL_MSG, false) +SQMOD_LOG(Scs, LEVEL_SCS, false) +SQMOD_LOG(Inf, LEVEL_INF, false) +SQMOD_LOG(Wrn, LEVEL_WRN, false) +SQMOD_LOG(Err, LEVEL_ERR, false) +SQMOD_LOG(Ftl, LEVEL_FTL, false) + +// ------------------------------------------------------------------------------------------------ +SQMOD_LOG(SDbg, LEVEL_DBG, true) +SQMOD_LOG(SMsg, LEVEL_MSG, true) +SQMOD_LOG(SScs, LEVEL_SCS, true) +SQMOD_LOG(SInf, LEVEL_INF, true) +SQMOD_LOG(SWrn, LEVEL_WRN, true) +SQMOD_LOG(SErr, LEVEL_ERR, true) +SQMOD_LOG(SFtl, LEVEL_FTL, true) + +// ------------------------------------------------------------------------------------------------ +#define SQMOD_CLOG(N_, L_, S_) /* +*/bool Logger::N_(bool c, const char * fmt, ...) noexcept /* +*/ { /* +*/ if (c) /* +*/ { /* +*/ va_list args; /* +*/ va_start(args, fmt); /* +*/ Send(L_, S_, fmt, args); /* +*/ va_end(args); /* +*/ } /* +*/ return c; /* +*/ } /* +*/ + +// ------------------------------------------------------------------------------------------------ +SQMOD_CLOG(cDbg, LEVEL_DBG, false) +SQMOD_CLOG(cMsg, LEVEL_MSG, false) +SQMOD_CLOG(cScs, LEVEL_SCS, false) +SQMOD_CLOG(cInf, LEVEL_INF, false) +SQMOD_CLOG(cWrn, LEVEL_WRN, false) +SQMOD_CLOG(cErr, LEVEL_ERR, false) +SQMOD_CLOG(cFtl, LEVEL_FTL, false) + +// ------------------------------------------------------------------------------------------------ +SQMOD_CLOG(cSDbg, LEVEL_DBG, true) +SQMOD_CLOG(cSMsg, LEVEL_MSG, true) +SQMOD_CLOG(cSScs, LEVEL_SCS, true) +SQMOD_CLOG(cSInf, LEVEL_INF, true) +SQMOD_CLOG(cSWrn, LEVEL_WRN, true) +SQMOD_CLOG(cSErr, LEVEL_ERR, true) +SQMOD_CLOG(cSFtl, LEVEL_FTL, true) + +} // Namespace:: SqMod diff --git a/source/Logger.hpp b/source/Logger.hpp new file mode 100644 index 00000000..ea4ae5e6 --- /dev/null +++ b/source/Logger.hpp @@ -0,0 +1,147 @@ +#ifndef _LOGGER_HPP_ +#define _LOGGER_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +class Logger +{ +public: + // -------------------------------------------------------------------------------------------- + static constexpr Uint8 LEVEL_NIL = (1 << 0); + static constexpr Uint8 LEVEL_DBG = (1 << 1); + static constexpr Uint8 LEVEL_MSG = (1 << 2); + static constexpr Uint8 LEVEL_SCS = (1 << 3); + static constexpr Uint8 LEVEL_INF = (1 << 4); + static constexpr Uint8 LEVEL_WRN = (1 << 5); + static constexpr Uint8 LEVEL_ERR = (1 << 6); + static constexpr Uint8 LEVEL_FTL = (1 << 7); + static constexpr Uint8 LEVEL_ANY = 0xFF; + +private: + // -------------------------------------------------------------------------------------------- + friend class std::unique_ptr; + + // -------------------------------------------------------------------------------------------- + Logger() noexcept; + + // -------------------------------------------------------------------------------------------- + ~Logger(); + + // -------------------------------------------------------------------------------------------- + static void _Finalizer(Logger * ptr) noexcept; + + // -------------------------------------------------------------------------------------------- +public: + // -------------------------------------------------------------------------------------------- + typedef std::unique_ptr Pointer; + + // -------------------------------------------------------------------------------------------- + static Pointer Inst() noexcept; + + // -------------------------------------------------------------------------------------------- + bool Init(); + bool Load(); + + // -------------------------------------------------------------------------------------------- + void Deinit(); + void Unload(); + + // -------------------------------------------------------------------------------------------- + void Terminate(); + + // -------------------------------------------------------------------------------------------- + void ToggleConsoleTime(bool enabled) noexcept; + void ToggleFileTime(bool enabled) noexcept; + bool HasConsoleTime() const noexcept; + bool HasFileTime() const noexcept; + + // -------------------------------------------------------------------------------------------- + void SetConsoleLevels(Uint8 levels) noexcept; + void SetFileLevels(Uint8 levels) noexcept; + Uint8 GetConsoleLevels() const noexcept; + Uint8 GetFileLevels() const noexcept; + + // -------------------------------------------------------------------------------------------- + void EnableConsoleLevel(Uint8 level) noexcept; + void EnableFileLevel(Uint8 level) noexcept; + void DisableConsoleLevel(Uint8 level) noexcept; + void DisableFileLevel(Uint8 level) noexcept; + + // -------------------------------------------------------------------------------------------- + Uint8 GetDebugLevel() const noexcept; + void SetDebugLevel(Uint8 level) noexcept; + + // -------------------------------------------------------------------------------------------- + SQInt32 GetVerbosity() const noexcept; + void SetVerbosity(SQInt32 level) noexcept; + +public: + // -------------------------------------------------------------------------------------------- + void Send(Uint8 type, bool sub, const char * fmt, va_list args) noexcept; + + // -------------------------------------------------------------------------------------------- + void Dbg(const char * fmt, ...) noexcept; + void Msg(const char * fmt, ...) noexcept; + void Scs(const char * fmt, ...) noexcept; + void Inf(const char * fmt, ...) noexcept; + void Wrn(const char * fmt, ...) noexcept; + void Err(const char * fmt, ...) noexcept; + void Ftl(const char * fmt, ...) noexcept; + + // -------------------------------------------------------------------------------------------- + void SDbg(const char * fmt, ...) noexcept; + void SMsg(const char * fmt, ...) noexcept; + void SScs(const char * fmt, ...) noexcept; + void SInf(const char * fmt, ...) noexcept; + void SWrn(const char * fmt, ...) noexcept; + void SErr(const char * fmt, ...) noexcept; + void SFtl(const char * fmt, ...) noexcept; + + // -------------------------------------------------------------------------------------------- + bool cDbg(bool cond, const char * fmt, ...) noexcept; + bool cMsg(bool cond, const char * fmt, ...) noexcept; + bool cScs(bool cond, const char * fmt, ...) noexcept; + bool cInf(bool cond, const char * fmt, ...) noexcept; + bool cWrn(bool cond, const char * fmt, ...) noexcept; + bool cErr(bool cond, const char * fmt, ...) noexcept; + bool cFtl(bool cond, const char * fmt, ...) noexcept; + + // -------------------------------------------------------------------------------------------- + bool cSDbg(bool cond, const char * fmt, ...) noexcept; + bool cSMsg(bool cond, const char * fmt, ...) noexcept; + bool cSScs(bool cond, const char * fmt, ...) noexcept; + bool cSInf(bool cond, const char * fmt, ...) noexcept; + bool cSWrn(bool cond, const char * fmt, ...) noexcept; + bool cSErr(bool cond, const char * fmt, ...) noexcept; + bool cSFtl(bool cond, const char * fmt, ...) noexcept; + +private: + // -------------------------------------------------------------------------------------------- + bool m_ConsoleTime; + bool m_FileTime; + + // -------------------------------------------------------------------------------------------- + Uint8 m_ConsoleLevels; + Uint8 m_FileLevels; + + // -------------------------------------------------------------------------------------------- + String m_LogPath; + + // -------------------------------------------------------------------------------------------- + Uint8 m_DebugLevel; + + // -------------------------------------------------------------------------------------------- + SQInt32 m_Verbosity; +}; + +// -------------------------------------------------------------------------------------------- +extern const Logger::Pointer _Log; + +} // Namespace:: SqMod + +#endif // _LOGGER_HPP_ diff --git a/source/Misc/Automobile.cpp b/source/Misc/Automobile.cpp new file mode 100644 index 00000000..7a3ec352 --- /dev/null +++ b/source/Misc/Automobile.cpp @@ -0,0 +1,282 @@ +#include "Misc/Automobile.hpp" +#include "Base/Color3.hpp" +#include "Base/Vector3.hpp" +#include "Entity.hpp" +#include "Register.hpp" +#include "Core.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const CAutomobile CAutomobile::NIL; + +// ------------------------------------------------------------------------------------------------ +CAutomobile::CAutomobile() noexcept + : m_ID(SQMOD_UNKNOWN), m_Name() +{ + +} + +CAutomobile::CAutomobile(SQInt32 id) noexcept + : m_ID(VALID_ENTITYGETEX(id, Max)), m_Name(GetAutomobileName(id)) +{ + +} + +CAutomobile::CAutomobile(const SQChar * name, SQInt32 id) noexcept + : CAutomobile(IsAutomobileValid(GetAutomobileID(name)) ? GetAutomobileID(name) : id) +{ + +} + +// ------------------------------------------------------------------------------------------------ +CAutomobile::CAutomobile(const CAutomobile & a) noexcept + : m_ID(a.m_ID) + , m_Name(a.m_Name) + , m_Tag(a.m_Tag) + , m_Data(a.m_Data) +{ + +} + +CAutomobile::CAutomobile(CAutomobile && a) noexcept + : m_ID(a.m_ID) + , m_Name(a.m_Name) + , m_Tag(a.m_Tag) + , m_Data(a.m_Data) +{ + +} + +// ------------------------------------------------------------------------------------------------ +CAutomobile::~CAutomobile() +{ + +} + +// ------------------------------------------------------------------------------------------------ +CAutomobile & CAutomobile::operator = (const CAutomobile & a) noexcept +{ + m_ID = a.m_ID; + m_Name = a.m_Name; + m_Tag = a.m_Tag; + m_Data = a.m_Data; + + return *this; +} + +CAutomobile & CAutomobile::operator = (CAutomobile && a) noexcept +{ + m_ID = a.m_ID; + m_Name = a.m_Name; + m_Tag = a.m_Tag; + m_Data = a.m_Data; + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +CAutomobile & CAutomobile::operator = (SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetAutomobileName(id); + m_ID = id; + } + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +bool CAutomobile::operator == (const CAutomobile & a) const noexcept +{ + return (m_ID == a.m_ID); +} + +bool CAutomobile::operator != (const CAutomobile & a) const noexcept +{ + return (m_ID != a.m_ID); +} + +bool CAutomobile::operator < (const CAutomobile & a) const noexcept +{ + return (m_ID < a.m_ID); +} + +bool CAutomobile::operator > (const CAutomobile & a) const noexcept +{ + return (m_ID < a.m_ID); +} + +bool CAutomobile::operator <= (const CAutomobile & a) const noexcept +{ + return (m_ID <= a.m_ID); +} + +bool CAutomobile::operator >= (const CAutomobile & a) const noexcept +{ + return (m_ID >= a.m_ID); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CAutomobile::Cmp(const CAutomobile & a) const noexcept +{ + return m_ID == a.m_ID ? 0 : (m_ID > a.m_ID ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CAutomobile::ToString() const noexcept +{ + return m_Name.c_str(); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CAutomobile::GetID() const noexcept +{ + return m_ID; +} + +void CAutomobile::SetID(SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetAutomobileName(id); + m_ID = id; + } +} + +// ------------------------------------------------------------------------------------------------ +CAutomobile & CAutomobile::SetnGet(SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetAutomobileName(id); + m_ID = id; + } + return *this; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CAutomobile::GetGlobalTag() const noexcept +{ + return GlobalTag(m_ID); +} + +void CAutomobile::SetGlobalTag(const SQChar * tag) const noexcept +{ + GlobalTag(m_ID, tag); +} + +// ------------------------------------------------------------------------------------------------ +SqObj & CAutomobile::GetGlobalData() const noexcept +{ + return GlobalData(m_ID); +} + +void CAutomobile::SetGlobalData(SqObj & data) const noexcept +{ + GlobalData(m_ID, data); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CAutomobile::GetLocalTag() const noexcept +{ + return m_Tag.c_str(); +} + +void CAutomobile::SetLocalTag(const SQChar * tag) noexcept +{ + m_Tag = tag; +} + +// ------------------------------------------------------------------------------------------------ +SqObj & CAutomobile::GetLocalData() noexcept +{ + return m_Data; +} + +void CAutomobile::SetLocalData(SqObj & data) noexcept +{ + m_Data = data; +} + +// ------------------------------------------------------------------------------------------------ +bool CAutomobile::IsValid() const noexcept +{ + return (VALID_ENTITYEX(m_ID, SQMOD_VEHICLEID_CAP)); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CAutomobile::GetName() const noexcept +{ + return m_Name.c_str(); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ + SQInt32 header, const SqObj & payload) const noexcept +{ + return _Core->CreateVehicle(*this, world, pos, angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); +} + +Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ + SQInt32 primary, SQInt32 secondary, SQInt32 header, \ + const SqObj & payload) const noexcept +{ + return _Core->CreateVehicle(*this, world, pos, angle, primary, secondary, header, payload); +} + +Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ + SQInt32 header, const SqObj & payload) const noexcept +{ + return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); +} + +Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ + SQInt32 primary, SQInt32 secondary, SQInt32 header, \ + const SqObj & payload) const noexcept +{ + return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, primary, secondary, header, payload); +} + +// ================================================================================================ +bool Register_CAutomobile(HSQUIRRELVM vm) +{ + // Output debugging information + LogDbg("Beginning registration of type"); + // Attempt to register the specified type + Sqrat::RootTable(vm).Bind(_SC("CAutomobile"), Sqrat::Class< CAutomobile >(vm, _SC("CAutomobile")) + .Ctor() + .Ctor< SQInt32 >() + .Ctor< const SQChar *, SQInt32 >() + + .Func(_SC("_cmp"), &CAutomobile::Cmp) + .Func(_SC("_tostring"), &CAutomobile::ToString) + + .Prop(_SC("id"), &CAutomobile::GetID, &CAutomobile::SetID) + .Prop(_SC("gtag"), &CAutomobile::GetGlobalTag, &CAutomobile::SetGlobalTag) + .Prop(_SC("gdata"), &CAutomobile::GetGlobalData, &CAutomobile::SetGlobalData) + .Prop(_SC("ltag"), &CAutomobile::GetLocalTag, &CAutomobile::SetLocalTag) + .Prop(_SC("ldata"), &CAutomobile::GetLocalData, &CAutomobile::SetLocalData) + .Prop(_SC("valid"), &CAutomobile::IsValid) + .Prop(_SC("name"), &CAutomobile::GetName) + + .Func(_SC("setng"), &CAutomobile::SetnGet) + + .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, const SqObj &) const > \ + (_SC("vehicle"), &CAutomobile::Create) + .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, SQInt32, SQInt32, const SqObj &) const > \ + (_SC("vehicle"), &CAutomobile::Create) + .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, const SqObj &) const > \ + (_SC("vehicle"), &CAutomobile::Create) + .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, SQInt32, SQInt32, const SqObj &) const > \ + (_SC("vehicle"), &CAutomobile::Create) + ); + // Output debugging information + LogDbg("Registration of type was successful"); + // Registration succeeded + return true; +} + +} // Namespace:: SqMod diff --git a/source/Misc/Automobile.hpp b/source/Misc/Automobile.hpp new file mode 100644 index 00000000..d191caad --- /dev/null +++ b/source/Misc/Automobile.hpp @@ -0,0 +1,92 @@ +#ifndef _MISC_AUTOMOBILE_HPP_ +#define _MISC_AUTOMOBILE_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Misc/Shared.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +class CAutomobile : public IdentifierStorage< CAutomobile, SQMOD_VEHICLEID_CAP > +{ +public: + // -------------------------------------------------------------------------------------------- + static const CAutomobile NIL; + // -------------------------------------------------------------------------------------------- + CAutomobile() noexcept; + CAutomobile(SQInt32 id) noexcept; + CAutomobile(const SQChar * name, SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CAutomobile(const CAutomobile & a) noexcept; + CAutomobile(CAutomobile && a) noexcept; + // -------------------------------------------------------------------------------------------- + ~CAutomobile(); + // -------------------------------------------------------------------------------------------- + CAutomobile & operator = (const CAutomobile & a) noexcept; + CAutomobile & operator = (CAutomobile && a) noexcept; + // -------------------------------------------------------------------------------------------- + CAutomobile & operator = (SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const CAutomobile & a) const noexcept; + bool operator != (const CAutomobile & a) const noexcept; + bool operator < (const CAutomobile & a) const noexcept; + bool operator > (const CAutomobile & a) const noexcept; + bool operator <= (const CAutomobile & a) const noexcept; + bool operator >= (const CAutomobile & a) const noexcept; + // -------------------------------------------------------------------------------------------- + operator SQInt32 () const noexcept { return m_ID; } + operator bool () const noexcept { return IsAutomobileValid(m_ID); } + // -------------------------------------------------------------------------------------------- + bool operator ! () const noexcept { return !IsAutomobileValid(m_ID); } + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CAutomobile & a) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger GetID() const noexcept; + void SetID(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CAutomobile & SetnGet(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetGlobalTag() const noexcept; + void SetGlobalTag(const SQChar * tag) const noexcept; + // -------------------------------------------------------------------------------------------- + SqObj & GetGlobalData() const noexcept; + void SetGlobalData(SqObj & data) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetLocalTag() const noexcept; + void SetLocalTag(const SQChar * tag) noexcept; + // -------------------------------------------------------------------------------------------- + SqObj & GetLocalData() noexcept; + void SetLocalData(SqObj & data) noexcept; + // -------------------------------------------------------------------------------------------- + bool IsValid() const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetName() const noexcept; + // -------------------------------------------------------------------------------------------- + Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ + SQInt32 header, const SqObj & payload) const noexcept; + Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ + SQInt32 primary, SQInt32 secondary, SQInt32 header, \ + const SqObj & payload) const noexcept; + Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ + SQInt32 header, const SqObj & payload) const noexcept; + Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ + SQInt32 primary, SQInt32 secondary, SQInt32 header, \ + const SqObj & payload) const noexcept; +private: + // -------------------------------------------------------------------------------------------- + SQInt32 m_ID; + // -------------------------------------------------------------------------------------------- + String m_Name; + // -------------------------------------------------------------------------------------------- + SqTag m_Tag; + SqObj m_Data; +}; + +} // Namespace:: SqMod + +#endif // _MISC_AUTOMOBILE_HPP_ diff --git a/source/Misc/Constants.cpp b/source/Misc/Constants.cpp new file mode 100644 index 00000000..da89c6d0 --- /dev/null +++ b/source/Misc/Constants.cpp @@ -0,0 +1,936 @@ +#include "Misc/Constants.hpp" +#include "Signal.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +#include +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_Constants(HSQUIRRELVM vm) +{ + Sqrat::ConstTable(vm).Enum(_SC("SQMOD"), Sqrat::Enumeration(vm) + .Const(_SC("VERSION"), SQMOD_VERSION) + .Const(_SC("SUCCESS"), SQMOD_SUCCESS) + .Const(_SC("FAILURE"), SQMOD_FAILURE) + .Const(_SC("UNKNOWN"), SQMOD_UNKNOWN) + .Const(_SC("ARCH"), SQMOD_ARCHITECTURE) + .Const(_SC("PLATFORM"), SQMOD_PLATFORM) + .Const(_SC("MIN_CHAR"), _NLMIN(SQChar)) + .Const(_SC("MAX_CHAR"), _NLMAX(SQChar)) + .Const(_SC("MIN_SHORT"), _NLMIN(Int16)) + .Const(_SC("MAX_SHORT"), _NLMAX(Int16)) + .Const(_SC("MIN_USHORT"), _NLMIN(Uint16)) + .Const(_SC("MAX_USHORT"), _NLMAX(Uint16)) + .Const(_SC("MIN_INT"), _NLMIN(SQInteger)) + .Const(_SC("MAX_INT"), _NLMAX(SQInteger)) + .Const(_SC("MIN_INT32"), _NLMIN(SQInt32)) + .Const(_SC("MAX_INT32"), _NLMAX(SQInt32)) + .Const(_SC("MIN_FLOAT"), _NLMIN(SQFloat)) + .Const(_SC("MAX_FLOAT"), _NLMAX(SQFloat)) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EARCHITECTURE"), Sqrat::Enumeration(vm) + .Const(_SC("UNKNOWN"), SQMOD_ARCH_ID_UNKNOWN) + .Const(_SC("X32_BIT"), SQMOD_ARCH_ID_32_BIT) + .Const(_SC("X64_BIT"), SQMOD_ARCH_ID_64_BIT) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EPLATFORM"), Sqrat::Enumeration(vm) + .Const(_SC("UNKNOWN"), SQMOD_PLAT_ID_UNKNOWN) + .Const(_SC("WINDOWS"), SQMOD_PLAT_ID_WINDOWS) + .Const(_SC("LINUX"), SQMOD_PLAT_ID_LINUX) + .Const(_SC("MACOS"), SQMOD_PLAT_ID_MACOS) + .Const(_SC("UNIX"), SQMOD_PLAT_ID_UNIX) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EVENTID"), Sqrat::Enumeration(vm) + .Const(_SC("UNKNOWN"), EVT_UNKNOWN) + .Const(_SC("BLIPCREATED"), EVT_BLIPCREATED) + .Const(_SC("CHECKPOINTCREATED"), EVT_CHECKPOINTCREATED) + .Const(_SC("KEYBINDCREATED"), EVT_KEYBINDCREATED) + .Const(_SC("OBJECTCREATED"), EVT_OBJECTCREATED) + .Const(_SC("PICKUPCREATED"), EVT_PICKUPCREATED) + .Const(_SC("PLAYERCREATED"), EVT_PLAYERCREATED) + .Const(_SC("SPHERECREATED"), EVT_SPHERECREATED) + .Const(_SC("SPRITECREATED"), EVT_SPRITECREATED) + .Const(_SC("TEXTDRAWCREATED"), EVT_TEXTDRAWCREATED) + .Const(_SC("VEHICLECREATED"), EVT_VEHICLECREATED) + .Const(_SC("BLIPDESTROYED"), EVT_BLIPDESTROYED) + .Const(_SC("CHECKPOINTDESTROYED"), EVT_CHECKPOINTDESTROYED) + .Const(_SC("KEYBINDDESTROYED"), EVT_KEYBINDDESTROYED) + .Const(_SC("OBJECTDESTROYED"), EVT_OBJECTDESTROYED) + .Const(_SC("PICKUPDESTROYED"), EVT_PICKUPDESTROYED) + .Const(_SC("PLAYERDESTROYED"), EVT_PLAYERDESTROYED) + .Const(_SC("SPHEREDESTROYED"), EVT_SPHEREDESTROYED) + .Const(_SC("SPRITEDESTROYED"), EVT_SPRITEDESTROYED) + .Const(_SC("TEXTDRAWDESTROYED"), EVT_TEXTDRAWDESTROYED) + .Const(_SC("VEHICLEDESTROYED"), EVT_VEHICLEDESTROYED) + .Const(_SC("BLIPCUSTOM"), EVT_BLIPCUSTOM) + .Const(_SC("CHECKPOINTCUSTOM"), EVT_CHECKPOINTCUSTOM) + .Const(_SC("KEYBINDCUSTOM"), EVT_KEYBINDCUSTOM) + .Const(_SC("OBJECTCUSTOM"), EVT_OBJECTCUSTOM) + .Const(_SC("PICKUPCUSTOM"), EVT_PICKUPCUSTOM) + .Const(_SC("PLAYERCUSTOM"), EVT_PLAYERCUSTOM) + .Const(_SC("SPHERECUSTOM"), EVT_SPHERECUSTOM) + .Const(_SC("SPRITECUSTOM"), EVT_SPRITECUSTOM) + .Const(_SC("TEXTDRAWCUSTOM"), EVT_TEXTDRAWCUSTOM) + .Const(_SC("VEHICLECUSTOM"), EVT_VEHICLECUSTOM) + .Const(_SC("PLAYERAWAY"), EVT_PLAYERAWAY) + .Const(_SC("PLAYERGAMEKEYS"), EVT_PLAYERGAMEKEYS) + .Const(_SC("PLAYERRENAME"), EVT_PLAYERRENAME) + .Const(_SC("PLAYERREQUESTCLASS"), EVT_PLAYERREQUESTCLASS) + .Const(_SC("PLAYERREQUESTSPAWN"), EVT_PLAYERREQUESTSPAWN) + .Const(_SC("PLAYERSPAWN"), EVT_PLAYERSPAWN) + .Const(_SC("PLAYERSTARTTYPING"), EVT_PLAYERSTARTTYPING) + .Const(_SC("PLAYERSTOPTYPING"), EVT_PLAYERSTOPTYPING) + .Const(_SC("PLAYERCHAT"), EVT_PLAYERCHAT) + .Const(_SC("PLAYERCOMMAND"), EVT_PLAYERCOMMAND) + .Const(_SC("PLAYERMESSAGE"), EVT_PLAYERMESSAGE) + .Const(_SC("PLAYERHEALTH"), EVT_PLAYERHEALTH) + .Const(_SC("PLAYERARMOUR"), EVT_PLAYERARMOUR) + .Const(_SC("PLAYERWEAPON"), EVT_PLAYERWEAPON) + .Const(_SC("PLAYERMOVE"), EVT_PLAYERMOVE) + .Const(_SC("PLAYERWASTED"), EVT_PLAYERWASTED) + .Const(_SC("PLAYERKILLED"), EVT_PLAYERKILLED) + .Const(_SC("PLAYERTEAMKILL"), EVT_PLAYERTEAMKILL) + .Const(_SC("PLAYERSPECTATE"), EVT_PLAYERSPECTATE) + .Const(_SC("PLAYERCRASHREPORT"), EVT_PLAYERCRASHREPORT) + .Const(_SC("PLAYERBURNING"), EVT_PLAYERBURNING) + .Const(_SC("PLAYERCROUCHING"), EVT_PLAYERCROUCHING) + .Const(_SC("PLAYERSTATE"), EVT_PLAYERSTATE) + .Const(_SC("PLAYERACTION"), EVT_PLAYERACTION) + .Const(_SC("STATENONE"), EVT_STATENONE) + .Const(_SC("STATENORMAL"), EVT_STATENORMAL) + .Const(_SC("STATESHOOTING"), EVT_STATESHOOTING) + .Const(_SC("STATEDRIVER"), EVT_STATEDRIVER) + .Const(_SC("STATEPASSENGER"), EVT_STATEPASSENGER) + .Const(_SC("STATEENTERDRIVER"), EVT_STATEENTERDRIVER) + .Const(_SC("STATEENTERPASSENGER"), EVT_STATEENTERPASSENGER) + .Const(_SC("STATEEXITVEHICLE"), EVT_STATEEXITVEHICLE) + .Const(_SC("STATEUNSPAWNED"), EVT_STATEUNSPAWNED) + .Const(_SC("ACTIONNONE"), EVT_ACTIONNONE) + .Const(_SC("ACTIONNORMAL"), EVT_ACTIONNORMAL) + .Const(_SC("ACTIONAIMING"), EVT_ACTIONAIMING) + .Const(_SC("ACTIONSHOOTING"), EVT_ACTIONSHOOTING) + .Const(_SC("ACTIONJUMPING"), EVT_ACTIONJUMPING) + .Const(_SC("ACTIONLIEDOWN"), EVT_ACTIONLIEDOWN) + .Const(_SC("ACTIONGETTINGUP"), EVT_ACTIONGETTINGUP) + .Const(_SC("ACTIONJUMPVEHICLE"), EVT_ACTIONJUMPVEHICLE) + .Const(_SC("ACTIONDRIVING"), EVT_ACTIONDRIVING) + .Const(_SC("ACTIONDYING"), EVT_ACTIONDYING) + .Const(_SC("ACTIONWASTED"), EVT_ACTIONWASTED) + .Const(_SC("ACTIONEMBARKING"), EVT_ACTIONEMBARKING) + .Const(_SC("ACTIONDISEMBARKING"), EVT_ACTIONDISEMBARKING) + .Const(_SC("VEHICLERESPAWN"), EVT_VEHICLERESPAWN) + .Const(_SC("VEHICLEEXPLODE"), EVT_VEHICLEEXPLODE) + .Const(_SC("VEHICLEHEALTH"), EVT_VEHICLEHEALTH) + .Const(_SC("VEHICLEMOVE"), EVT_VEHICLEMOVE) + .Const(_SC("PICKUPRESPAWN"), EVT_PICKUPRESPAWN) + .Const(_SC("KEYBINDKEYPRESS"), EVT_KEYBINDKEYPRESS) + .Const(_SC("KEYBINDKEYRELEASE"), EVT_KEYBINDKEYRELEASE) + .Const(_SC("VEHICLEEMBARKING"), EVT_VEHICLEEMBARKING) + .Const(_SC("VEHICLEEMBARKED"), EVT_VEHICLEEMBARKED) + .Const(_SC("VEHICLEDISEMBARK"), EVT_VEHICLEDISEMBARK) + .Const(_SC("PICKUPCLAIMED"), EVT_PICKUPCLAIMED) + .Const(_SC("PICKUPCOLLECTED"), EVT_PICKUPCOLLECTED) + .Const(_SC("OBJECTSHOT"), EVT_OBJECTSHOT) + .Const(_SC("OBJECTBUMP"), EVT_OBJECTBUMP) + .Const(_SC("CHECKPOINTENTERED"), EVT_CHECKPOINTENTERED) + .Const(_SC("CHECKPOINTEXITED"), EVT_CHECKPOINTEXITED) + .Const(_SC("SPHEREENTERED"), EVT_SPHEREENTERED) + .Const(_SC("SPHEREEXITED"), EVT_SPHEREEXITED) + .Const(_SC("SERVERFRAME"), EVT_SERVERFRAME) + .Const(_SC("SERVERSTARTUP"), EVT_SERVERSTARTUP) + .Const(_SC("SERVERSHUTDOWN"), EVT_SERVERSHUTDOWN) + .Const(_SC("INTERNALCOMMAND"), EVT_INTERNALCOMMAND) + .Const(_SC("LOGINATTEMPT"), EVT_LOGINATTEMPT) + .Const(_SC("CUSTOMEVENT"), EVT_CUSTOMEVENT) + .Const(_SC("WORLDOPTION"), EVT_WORLDOPTION) + .Const(_SC("WORLDTOGGLE"), EVT_WORLDTOGGLE) + .Const(_SC("SCRIPTRELOAD"), EVT_SCRIPTRELOAD) + .Const(_SC("LOGMESSAGE"), EVT_LOGMESSAGE) + .Const(_SC("COUNT"), EVT_COUNT) + ); + + Sqrat::ConstTable(vm).Enum(_SC("ECREATEREASON"), Sqrat::Enumeration(vm) + .Const(_SC("DEFAULT"), SQMOD_CREATE_DEFAULT) + .Const(_SC("MANUAL"), SQMOD_CREATE_MANUAL) + .Const(_SC("POOL"), SQMOD_CREATE_POOL) + .Const(_SC("AUTOMATIC"), SQMOD_CREATE_AUTOMATIC) + .Const(_SC("OVERWRITE"), SQMOD_CREATE_OVERWRITE) + .Const(_SC("RESURECT"), SQMOD_CREATE_RESURECT) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EDESTROYREASON"), Sqrat::Enumeration(vm) + .Const(_SC("DEFAULT"), SQMOD_DESTROY_DEFAULT) + .Const(_SC("MANUAL"), SQMOD_DESTROY_MANUAL) + .Const(_SC("POOL"), SQMOD_DESTROY_POOL) + .Const(_SC("AUTOMATIC"), SQMOD_DESTROY_AUTOMATIC) + .Const(_SC("OVERWRITE"), SQMOD_DESTROY_OVERWRITE) + .Const(_SC("CLEANUP"), SQMOD_DESTROY_CLEANUP) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EENTITYPOOLUPD"), Sqrat::Enumeration(vm) + .Const(_SC("VEHICLE"), SQMOD_ENTITY_POOL_VEHICLE) + .Const(_SC("OBJECT"), SQMOD_ENTITY_POOL_OBJECT) + .Const(_SC("PICKUP"), SQMOD_ENTITY_POOL_PICKUP) + .Const(_SC("RADIO"), SQMOD_ENTITY_POOL_RADIO) + .Const(_SC("SPRITE"), SQMOD_ENTITY_POOL_SPRITE) + .Const(_SC("TEXTDRAW"), SQMOD_ENTITY_POOL_TEXTDRAW) + .Const(_SC("BLIP"), SQMOD_ENTITY_POOL_BLIP) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EVEHICLEUPD"), Sqrat::Enumeration(vm) + .Const(_SC("DRIVER"), SQMOD_VEHICLEUPD_DRIVER) + .Const(_SC("OTHER"), SQMOD_VEHICLEUPD_OTHER) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EPLAYERUPD"), Sqrat::Enumeration(vm) + .Const(_SC("ONFOOT"), SQMOD_PLAYERUPD_ONFOOT) + .Const(_SC("AIM"), SQMOD_PLAYERUPD_AIM) + .Const(_SC("DRIVER"), SQMOD_PLAYERUPD_DRIVER) + .Const(_SC("PASSENGER"), SQMOD_PLAYERUPD_PASSENGER) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EPARTREASON"), Sqrat::Enumeration(vm) + .Const(_SC("TIMEOUT"), SQMOD_PARTREASON_TIMEOUT) + .Const(_SC("DISCONNECTED"), SQMOD_PARTREASON_DISCONNECTED) + .Const(_SC("KICKEDBANNED"), SQMOD_PARTREASON_KICKEDBANNED) + .Const(_SC("CRASHED"), SQMOD_PARTREASON_CRASHED) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EBODYPART"), Sqrat::Enumeration(vm) + .Const(_SC("BODY"), SQMOD_BODYPART_BODY) + .Const(_SC("TORSO"), SQMOD_BODYPART_TORSO) + .Const(_SC("LEFTARM"), SQMOD_BODYPART_LEFTARM) + .Const(_SC("LARM"), SQMOD_BODYPART_LEFTARM) + .Const(_SC("RIGHTARM"), SQMOD_BODYPART_RIGHTARM) + .Const(_SC("RARM"), SQMOD_BODYPART_RIGHTARM) + .Const(_SC("LEFTLEG"), SQMOD_BODYPART_LEFTLEG) + .Const(_SC("LLEG"), SQMOD_BODYPART_LEFTLEG) + .Const(_SC("RIGHTLEG"), SQMOD_BODYPART_RIGHTLEG) + .Const(_SC("RLEG"), SQMOD_BODYPART_RIGHTLEG) + .Const(_SC("HEAD"), SQMOD_BODYPART_HEAD) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EPLAYERSTATE"), Sqrat::Enumeration(vm) + .Const(_SC("NONE"), SQMOD_PLAYER_STATE_NONE) + .Const(_SC("NORMAL"), SQMOD_PLAYER_STATE_NORMAL) + .Const(_SC("SHOOTING"), SQMOD_PLAYER_STATE_SHOOTING) + .Const(_SC("DRIVER"), SQMOD_PLAYER_STATE_DRIVER) + .Const(_SC("PASSENGER"), SQMOD_PLAYER_STATE_PASSENGER) + .Const(_SC("ENTERING_AS_DRIVER"), SQMOD_PLAYER_STATE_ENTERING_AS_DRIVER) + .Const(_SC("ENTERING_AS_PASSENGER"), SQMOD_PLAYER_STATE_ENTERING_AS_PASSENGER) + .Const(_SC("EXITING_VEHICLE"), SQMOD_PLAYER_STATE_EXITING_VEHICLE) + .Const(_SC("UNSPAWNED"), SQMOD_PLAYER_STATE_UNSPAWNED) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EPLAYERACTION"), Sqrat::Enumeration(vm) + .Const(_SC("NONE"), SQMOD_PLAYER_ACTION_NONE) + .Const(_SC("NORMAL"), SQMOD_PLAYER_ACTION_NORMAL) + .Const(_SC("AIMING"), SQMOD_PLAYER_ACTION_AIMING) + .Const(_SC("SHOOTING"), SQMOD_PLAYER_ACTION_SHOOTING) + .Const(_SC("JUMPING"), SQMOD_PLAYER_ACTION_JUMPING) + .Const(_SC("LYING_ON_GROUND"), SQMOD_PLAYER_ACTION_LYING_ON_GROUND) + .Const(_SC("GETTING_UP"), SQMOD_PLAYER_ACTION_GETTING_UP) + .Const(_SC("JUMPING_FROM_VEHICLE"), SQMOD_PLAYER_ACTION_JUMPING_FROM_VEHICLE) + .Const(_SC("DRIVING"), SQMOD_PLAYER_ACTION_DRIVING) + .Const(_SC("DYING"), SQMOD_PLAYER_ACTION_DYING) + .Const(_SC("WASTED"), SQMOD_PLAYER_ACTION_WASTED) + .Const(_SC("ENTERING_VEHICLE"), SQMOD_PLAYER_ACTION_ENTERING_VEHICLE) + .Const(_SC("EXITING_VEHICLE"), SQMOD_PLAYER_ACTION_EXITING_VEHICLE) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EWEATHER"), Sqrat::Enumeration(vm) + .Const(_SC("MOSTLYCLEAR"), SQMOD_WEATHER_MOSTLYCLEAR) + .Const(_SC("OVERCAST"), SQMOD_WEATHER_OVERCAST) + .Const(_SC("THUNDERSTORM"), SQMOD_WEATHER_THUNDERSTORM) + .Const(_SC("STORM"), SQMOD_WEATHER_STORM) + .Const(_SC("STORMY"), SQMOD_WEATHER_STORMY) + .Const(_SC("FOGGY"), SQMOD_WEATHER_FOGGY) + .Const(_SC("FOG"), SQMOD_WEATHER_FOG) + .Const(_SC("CLEAR"), SQMOD_WEATHER_CLEAR) + .Const(_SC("SUNNY"), SQMOD_WEATHER_SUNNY) + .Const(_SC("RAIN"), SQMOD_WEATHER_RAIN) + .Const(_SC("RAINY"), SQMOD_WEATHER_RAINY) + .Const(_SC("DARKCLOUDY"), SQMOD_WEATHER_DARKCLOUDY) + .Const(_SC("LIGHTCLOUDY"), SQMOD_WEATHER_LIGHTCLOUDY) + .Const(_SC("OVERCASTCLOUDY"), SQMOD_WEATHER_OVERCASTCLOUDY) + .Const(_SC("BLACKCLOUDS"), SQMOD_WEATHER_BLACKCLOUDS) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EWEAPON"), Sqrat::Enumeration(vm) + .Const(_SC("UNKNWON"), SQMOD_UNKNOWN) + .Const(_SC("UNARMED"), SQMOD_WEAPON_UNARMED) + .Const(_SC("BRASSKNUCKLES"), SQMOD_WEAPON_BRASSKNUCKLES) + .Const(_SC("SCREWDRIVER"), SQMOD_WEAPON_SCREWDRIVER) + .Const(_SC("GOLFCLUB"), SQMOD_WEAPON_GOLFCLUB) + .Const(_SC("NIGHTSTICK"), SQMOD_WEAPON_NIGHTSTICK) + .Const(_SC("KNIFE"), SQMOD_WEAPON_KNIFE) + .Const(_SC("BASEBALLBAT"), SQMOD_WEAPON_BASEBALLBAT) + .Const(_SC("HAMMER"), SQMOD_WEAPON_HAMMER) + .Const(_SC("MEATCLEAVER"), SQMOD_WEAPON_MEATCLEAVER) + .Const(_SC("MACHETE"), SQMOD_WEAPON_MACHETE) + .Const(_SC("KATANA"), SQMOD_WEAPON_KATANA) + .Const(_SC("CHAINSAW"), SQMOD_WEAPON_CHAINSAW) + .Const(_SC("GRENADE"), SQMOD_WEAPON_GRENADE) + .Const(_SC("REMOTE"), SQMOD_WEAPON_REMOTE) + .Const(_SC("TEARGAS"), SQMOD_WEAPON_TEARGAS) + .Const(_SC("MOLOTOV"), SQMOD_WEAPON_MOLOTOV) + .Const(_SC("ROCKET"), SQMOD_WEAPON_ROCKET) + .Const(_SC("COLT45"), SQMOD_WEAPON_COLT45) + .Const(_SC("PYTHON"), SQMOD_WEAPON_PYTHON) + .Const(_SC("SHOTGUN"), SQMOD_WEAPON_SHOTGUN) + .Const(_SC("SPAS12"), SQMOD_WEAPON_SPAS12) + .Const(_SC("STUBBY"), SQMOD_WEAPON_STUBBY) + .Const(_SC("TEC9"), SQMOD_WEAPON_TEC9) + .Const(_SC("UZI"), SQMOD_WEAPON_UZI) + .Const(_SC("INGRAM"), SQMOD_WEAPON_INGRAM) + .Const(_SC("MP5"), SQMOD_WEAPON_MP5) + .Const(_SC("M4"), SQMOD_WEAPON_M4) + .Const(_SC("RUGER"), SQMOD_WEAPON_RUGER) + .Const(_SC("SNIPER"), SQMOD_WEAPON_SNIPER) + .Const(_SC("LASERSCOPE"), SQMOD_WEAPON_LASERSCOPE) + .Const(_SC("ROCKETLAUNCHER"), SQMOD_WEAPON_ROCKETLAUNCHER) + .Const(_SC("FLAMETHROWER"), SQMOD_WEAPON_FLAMETHROWER) + .Const(_SC("M60"), SQMOD_WEAPON_M60) + .Const(_SC("MINIGUN"), SQMOD_WEAPON_MINIGUN) + .Const(_SC("BOMB"), SQMOD_WEAPON_BOMB) + .Const(_SC("HELICANNON"), SQMOD_WEAPON_HELICANNON) + .Const(_SC("CAMERA"), SQMOD_WEAPON_CAMERA) + .Const(_SC("VEHICLE"), SQMOD_WEAPON_VEHICLE) + .Const(_SC("EXPLOSION1"), SQMOD_WEAPON_EXPLOSION1) + .Const(_SC("DRIVEBY"), SQMOD_WEAPON_DRIVEBY) + .Const(_SC("DROWNED"), SQMOD_WEAPON_DROWNED) + .Const(_SC("FALL"), SQMOD_WEAPON_FALL) + .Const(_SC("EXPLOSION2"), SQMOD_WEAPON_EXPLOSION2) + .Const(_SC("SUICIDE"), SQMOD_WEAPON_SUICIDE) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EVEHICLE"), Sqrat::Enumeration(vm) + .Const(_SC("UNKNOWN"), SQMOD_UNKNOWN) + .Const(_SC("LANDSTALKER"), SQMOD_VEHICLE_LANDSTALKER) + .Const(_SC("IDAHO"), SQMOD_VEHICLE_IDAHO) + .Const(_SC("STINGER"), SQMOD_VEHICLE_STINGER) + .Const(_SC("LINERUNNER"), SQMOD_VEHICLE_LINERUNNER) + .Const(_SC("PERENNIAL"), SQMOD_VEHICLE_PERENNIAL) + .Const(_SC("SENTINEL"), SQMOD_VEHICLE_SENTINEL) + .Const(_SC("RIO"), SQMOD_VEHICLE_RIO) + .Const(_SC("FIRETRUCK"), SQMOD_VEHICLE_FIRETRUCK) + .Const(_SC("TRASHMASTER"), SQMOD_VEHICLE_TRASHMASTER) + .Const(_SC("STRETCH"), SQMOD_VEHICLE_STRETCH) + .Const(_SC("MANANA"), SQMOD_VEHICLE_MANANA) + .Const(_SC("INFERNUS"), SQMOD_VEHICLE_INFERNUS) + .Const(_SC("VOODOO"), SQMOD_VEHICLE_VOODOO) + .Const(_SC("PONY"), SQMOD_VEHICLE_PONY) + .Const(_SC("MULE"), SQMOD_VEHICLE_MULE) + .Const(_SC("CHEETAH"), SQMOD_VEHICLE_CHEETAH) + .Const(_SC("AMBULANCE"), SQMOD_VEHICLE_AMBULANCE) + .Const(_SC("FBIWASHINGTON"), SQMOD_VEHICLE_FBIWASHINGTON) + .Const(_SC("MOONBEAM"), SQMOD_VEHICLE_MOONBEAM) + .Const(_SC("ESPERANTO"), SQMOD_VEHICLE_ESPERANTO) + .Const(_SC("TAXI"), SQMOD_VEHICLE_TAXI) + .Const(_SC("WASHINGTON"), SQMOD_VEHICLE_WASHINGTON) + .Const(_SC("BOBCAT"), SQMOD_VEHICLE_BOBCAT) + .Const(_SC("MRWHOOPEE"), SQMOD_VEHICLE_MRWHOOPEE) + .Const(_SC("BFINJECTION"), SQMOD_VEHICLE_BFINJECTION) + .Const(_SC("HUNTER"), SQMOD_VEHICLE_HUNTER) + .Const(_SC("POLICE"), SQMOD_VEHICLE_POLICE) + .Const(_SC("ENFORCER"), SQMOD_VEHICLE_ENFORCER) + .Const(_SC("SECURICAR"), SQMOD_VEHICLE_SECURICAR) + .Const(_SC("BANSHEE"), SQMOD_VEHICLE_BANSHEE) + .Const(_SC("PREDATOR"), SQMOD_VEHICLE_PREDATOR) + .Const(_SC("BUS"), SQMOD_VEHICLE_BUS) + .Const(_SC("RHINO"), SQMOD_VEHICLE_RHINO) + .Const(_SC("BARRACKSOL"), SQMOD_VEHICLE_BARRACKSOL) + .Const(_SC("BARRACKS"), SQMOD_VEHICLE_BARRACKS) + .Const(_SC("CUBANHERMES"), SQMOD_VEHICLE_CUBANHERMES) + .Const(_SC("HELICOPTER"), SQMOD_VEHICLE_HELICOPTER) + .Const(_SC("ANGEL"), SQMOD_VEHICLE_ANGEL) + .Const(_SC("COACH"), SQMOD_VEHICLE_COACH) + .Const(_SC("CABBIE"), SQMOD_VEHICLE_CABBIE) + .Const(_SC("STALLION"), SQMOD_VEHICLE_STALLION) + .Const(_SC("RUMPO"), SQMOD_VEHICLE_RUMPO) + .Const(_SC("RCBANDIT"), SQMOD_VEHICLE_RCBANDIT) + .Const(_SC("HEARSE"), SQMOD_VEHICLE_HEARSE) + .Const(_SC("PACKER"), SQMOD_VEHICLE_PACKER) + .Const(_SC("SENTINELXS"), SQMOD_VEHICLE_SENTINELXS) + .Const(_SC("ADMIRAL"), SQMOD_VEHICLE_ADMIRAL) + .Const(_SC("SQUALO"), SQMOD_VEHICLE_SQUALO) + .Const(_SC("SEASPARROW"), SQMOD_VEHICLE_SEASPARROW) + .Const(_SC("PIZZABOY"), SQMOD_VEHICLE_PIZZABOY) + .Const(_SC("GANGBURRITO"), SQMOD_VEHICLE_GANGBURRITO) + .Const(_SC("AIRTRAIN"), SQMOD_VEHICLE_AIRTRAIN) + .Const(_SC("DEADDODO"), SQMOD_VEHICLE_DEADDODO) + .Const(_SC("SPEEDER"), SQMOD_VEHICLE_SPEEDER) + .Const(_SC("REEFER"), SQMOD_VEHICLE_REEFER) + .Const(_SC("TROPIC"), SQMOD_VEHICLE_TROPIC) + .Const(_SC("FLATBED"), SQMOD_VEHICLE_FLATBED) + .Const(_SC("YANKEE"), SQMOD_VEHICLE_YANKEE) + .Const(_SC("CADDY"), SQMOD_VEHICLE_CADDY) + .Const(_SC("ZEBRA"), SQMOD_VEHICLE_ZEBRA) + .Const(_SC("ZEBRACAB"), SQMOD_VEHICLE_ZEBRACAB) + .Const(_SC("TOPFUN"), SQMOD_VEHICLE_TOPFUN) + .Const(_SC("SKIMMER"), SQMOD_VEHICLE_SKIMMER) + .Const(_SC("PCJ600"), SQMOD_VEHICLE_PCJ600) + .Const(_SC("PCJ"), SQMOD_VEHICLE_PCJ) + .Const(_SC("FAGGIO"), SQMOD_VEHICLE_FAGGIO) + .Const(_SC("FREEWAY"), SQMOD_VEHICLE_FREEWAY) + .Const(_SC("RCBARON"), SQMOD_VEHICLE_RCBARON) + .Const(_SC("RCRAIDER"), SQMOD_VEHICLE_RCRAIDER) + .Const(_SC("GLENDALE"), SQMOD_VEHICLE_GLENDALE) + .Const(_SC("OCEANIC"), SQMOD_VEHICLE_OCEANIC) + .Const(_SC("SANCHEZ"), SQMOD_VEHICLE_SANCHEZ) + .Const(_SC("SPARROW"), SQMOD_VEHICLE_SPARROW) + .Const(_SC("PATRIOT"), SQMOD_VEHICLE_PATRIOT) + .Const(_SC("LOVEFIST"), SQMOD_VEHICLE_LOVEFIST) + .Const(_SC("COASTGUARD"), SQMOD_VEHICLE_COASTGUARD) + .Const(_SC("DINGHY"), SQMOD_VEHICLE_DINGHY) + .Const(_SC("HERMES"), SQMOD_VEHICLE_HERMES) + .Const(_SC("SABRE"), SQMOD_VEHICLE_SABRE) + .Const(_SC("SABRETURBO"), SQMOD_VEHICLE_SABRETURBO) + .Const(_SC("PHOENIX"), SQMOD_VEHICLE_PHOENIX) + .Const(_SC("WALTON"), SQMOD_VEHICLE_WALTON) + .Const(_SC("REGINA"), SQMOD_VEHICLE_REGINA) + .Const(_SC("COMET"), SQMOD_VEHICLE_COMET) + .Const(_SC("DELUXO"), SQMOD_VEHICLE_DELUXO) + .Const(_SC("BURRITO"), SQMOD_VEHICLE_BURRITO) + .Const(_SC("SPANDEX"), SQMOD_VEHICLE_SPANDEX) + .Const(_SC("SPANDEXPRESS"), SQMOD_VEHICLE_SPANDEXPRESS) + .Const(_SC("MARQUIS"), SQMOD_VEHICLE_MARQUIS) + .Const(_SC("BAGGAGE"), SQMOD_VEHICLE_BAGGAGE) + .Const(_SC("BAGGAGEHANDLER"), SQMOD_VEHICLE_BAGGAGEHANDLER) + .Const(_SC("KAUFMAN"), SQMOD_VEHICLE_KAUFMAN) + .Const(_SC("KAUFMANCAB"), SQMOD_VEHICLE_KAUFMANCAB) + .Const(_SC("MAVERICK"), SQMOD_VEHICLE_MAVERICK) + .Const(_SC("VCNMAVERICK"), SQMOD_VEHICLE_VCNMAVERICK) + .Const(_SC("RANCHER"), SQMOD_VEHICLE_RANCHER) + .Const(_SC("FBIRANCHER"), SQMOD_VEHICLE_FBIRANCHER) + .Const(_SC("VIRGO"), SQMOD_VEHICLE_VIRGO) + .Const(_SC("GREENWOOD"), SQMOD_VEHICLE_GREENWOOD) + .Const(_SC("CUBANJETMAX"), SQMOD_VEHICLE_CUBANJETMAX) + .Const(_SC("HOTRING1"), SQMOD_VEHICLE_HOTRING1) + .Const(_SC("HOTRINGRACER1"), SQMOD_VEHICLE_HOTRINGRACER1) + .Const(_SC("SANDKING"), SQMOD_VEHICLE_SANDKING) + .Const(_SC("BLISTA"), SQMOD_VEHICLE_BLISTA) + .Const(_SC("BLISTAC"), SQMOD_VEHICLE_BLISTAC) + .Const(_SC("BLISTACOMPACT"), SQMOD_VEHICLE_BLISTACOMPACT) + .Const(_SC("COMPACT"), SQMOD_VEHICLE_COMPACT) + .Const(_SC("POLICEMAV"), SQMOD_VEHICLE_POLICEMAV) + .Const(_SC("POLICEMAVERICK"), SQMOD_VEHICLE_POLICEMAVERICK) + .Const(_SC("BOXVILLE"), SQMOD_VEHICLE_BOXVILLE) + .Const(_SC("BENSON"), SQMOD_VEHICLE_BENSON) + .Const(_SC("MESA"), SQMOD_VEHICLE_MESA) + .Const(_SC("MESAGRANDE"), SQMOD_VEHICLE_MESAGRANDE) + .Const(_SC("RCGOBLIN"), SQMOD_VEHICLE_RCGOBLIN) + .Const(_SC("HOTRING2"), SQMOD_VEHICLE_HOTRING2) + .Const(_SC("HOTRINGRACER2"), SQMOD_VEHICLE_HOTRINGRACER2) + .Const(_SC("HOTRING3"), SQMOD_VEHICLE_HOTRING3) + .Const(_SC("HOTRINGRACER3"), SQMOD_VEHICLE_HOTRINGRACER3) + .Const(_SC("BLOODRING1"), SQMOD_VEHICLE_BLOODRING1) + .Const(_SC("BLOODRINGBANGER1"), SQMOD_VEHICLE_BLOODRINGBANGER1) + .Const(_SC("BLOODRING2"), SQMOD_VEHICLE_BLOODRING2) + .Const(_SC("BLOODRINGBANGER2"), SQMOD_VEHICLE_BLOODRINGBANGER2) + .Const(_SC("VICECHEE"), SQMOD_VEHICLE_VICECHEE) + .Const(_SC("POLICECHEETAH"), SQMOD_VEHICLE_POLICECHEETAH) + .Const(_SC("FBICHEETAH"), SQMOD_VEHICLE_FBICHEETAH) + .Const(_SC("CHEETAH2"), SQMOD_VEHICLE_CHEETAH2) + ); + + Sqrat::ConstTable(vm).Enum(_SC("ESKIN"), Sqrat::Enumeration(vm) + .Const(_SC("UNKNOWN"), SQMOD_UNKNOWN) + .Const(_SC("TOMMY_VERCETTI"), SQMOD_SKIN_TOMMY_VERCETTI) + .Const(_SC("COP"), SQMOD_SKIN_COP) + .Const(_SC("SWAT"), SQMOD_SKIN_SWAT) + .Const(_SC("FBI"), SQMOD_SKIN_FBI) + .Const(_SC("ARMY"), SQMOD_SKIN_ARMY) + .Const(_SC("PARAMEDIC"), SQMOD_SKIN_PARAMEDIC) + .Const(_SC("FIREMAN"), SQMOD_SKIN_FIREMAN) + .Const(_SC("GOLF_GUY_A"), SQMOD_SKIN_GOLF_GUY_A) + .Const(_SC("BUM_LADY_A"), SQMOD_SKIN_BUM_LADY_A) + .Const(_SC("BUM_LADY_B"), SQMOD_SKIN_BUM_LADY_B) + .Const(_SC("PUNK_A"), SQMOD_SKIN_PUNK_A) + .Const(_SC("LAWYER"), SQMOD_SKIN_LAWYER) + .Const(_SC("SPANISH_LADY_A"), SQMOD_SKIN_SPANISH_LADY_A) + .Const(_SC("SPANISH_LADY_B"), SQMOD_SKIN_SPANISH_LADY_B) + .Const(_SC("COOL_GUY_A"), SQMOD_SKIN_COOL_GUY_A) + .Const(_SC("ARABIC_GUY"), SQMOD_SKIN_ARABIC_GUY) + .Const(_SC("BEACH_LADY_A"), SQMOD_SKIN_BEACH_LADY_A) + .Const(_SC("BEACH_LADY_B"), SQMOD_SKIN_BEACH_LADY_B) + .Const(_SC("BEACH_GUY_A"), SQMOD_SKIN_BEACH_GUY_A) + .Const(_SC("BEACH_GUY_B"), SQMOD_SKIN_BEACH_GUY_B) + .Const(_SC("OFFICE_LADY_A"), SQMOD_SKIN_OFFICE_LADY_A) + .Const(_SC("WAITRESS_A"), SQMOD_SKIN_WAITRESS_A) + .Const(_SC("FOOD_LADY"), SQMOD_SKIN_FOOD_LADY) + .Const(_SC("PROSTITUTE_A"), SQMOD_SKIN_PROSTITUTE_A) + .Const(_SC("BUM_LADY_C"), SQMOD_SKIN_BUM_LADY_C) + .Const(_SC("BUM_GUY_A"), SQMOD_SKIN_BUM_GUY_A) + .Const(_SC("GARBAGEMAN_A"), SQMOD_SKIN_GARBAGEMAN_A) + .Const(_SC("TAXI_DRIVER_A"), SQMOD_SKIN_TAXI_DRIVER_A) + .Const(_SC("HATIAN_A"), SQMOD_SKIN_HATIAN_A) + .Const(_SC("CRIMINAL_A"), SQMOD_SKIN_CRIMINAL_A) + .Const(_SC("HOOD_LADY"), SQMOD_SKIN_HOOD_LADY) + .Const(_SC("GRANNY_A"), SQMOD_SKIN_GRANNY_A) + .Const(_SC("BUSINESS_MAN_A"), SQMOD_SKIN_BUSINESS_MAN_A) + .Const(_SC("CHURCH_GUY"), SQMOD_SKIN_CHURCH_GUY) + .Const(_SC("CLUB_LADY"), SQMOD_SKIN_CLUB_LADY) + .Const(_SC("CHURCH_LADY"), SQMOD_SKIN_CHURCH_LADY) + .Const(_SC("PIMP"), SQMOD_SKIN_PIMP) + .Const(_SC("BEACH_LADY_C"), SQMOD_SKIN_BEACH_LADY_C) + .Const(_SC("BEACH_GUY_C"), SQMOD_SKIN_BEACH_GUY_C) + .Const(_SC("BEACH_LADY_D"), SQMOD_SKIN_BEACH_LADY_D) + .Const(_SC("BEACH_GUY_D"), SQMOD_SKIN_BEACH_GUY_D) + .Const(_SC("BUSINESS_MAN_B"), SQMOD_SKIN_BUSINESS_MAN_B) + .Const(_SC("PROSTITUTE_B"), SQMOD_SKIN_PROSTITUTE_B) + .Const(_SC("BUM_LADY_D"), SQMOD_SKIN_BUM_LADY_D) + .Const(_SC("BUM_GUY_B"), SQMOD_SKIN_BUM_GUY_B) + .Const(_SC("HATIAN_B"), SQMOD_SKIN_HATIAN_B) + .Const(_SC("CONSTRUCTION_WORKER_A"), SQMOD_SKIN_CONSTRUCTION_WORKER_A) + .Const(_SC("PUNK_B"), SQMOD_SKIN_PUNK_B) + .Const(_SC("PROSTITUTE_C"), SQMOD_SKIN_PROSTITUTE_C) + .Const(_SC("GRANNY_B"), SQMOD_SKIN_GRANNY_B) + .Const(_SC("PUNK_C"), SQMOD_SKIN_PUNK_C) + .Const(_SC("BUSINESS_MAN_C"), SQMOD_SKIN_BUSINESS_MAN_C) + .Const(_SC("SPANISH_LADY_C"), SQMOD_SKIN_SPANISH_LADY_C) + .Const(_SC("SPANISH_LADY_D"), SQMOD_SKIN_SPANISH_LADY_D) + .Const(_SC("COOL_GUY_B"), SQMOD_SKIN_COOL_GUY_B) + .Const(_SC("BUSINESS_MAN_D"), SQMOD_SKIN_BUSINESS_MAN_D) + .Const(_SC("BEACH_LADY_E"), SQMOD_SKIN_BEACH_LADY_E) + .Const(_SC("BEACH_GUY_E"), SQMOD_SKIN_BEACH_GUY_E) + .Const(_SC("BEACH_LADY_F"), SQMOD_SKIN_BEACH_LADY_F) + .Const(_SC("BEACH_GUY_F"), SQMOD_SKIN_BEACH_GUY_F) + .Const(_SC("CONSTRUCTION_WORKER_B"), SQMOD_SKIN_CONSTRUCTION_WORKER_B) + .Const(_SC("GOLF_GUY_B"), SQMOD_SKIN_GOLF_GUY_B) + .Const(_SC("GOLF_LADY"), SQMOD_SKIN_GOLF_LADY) + .Const(_SC("GOLF_GUY_C"), SQMOD_SKIN_GOLF_GUY_C) + .Const(_SC("BEACH_LADY_G"), SQMOD_SKIN_BEACH_LADY_G) + .Const(_SC("BEACH_GUY_G"), SQMOD_SKIN_BEACH_GUY_G) + .Const(_SC("OFFICE_LADY_B"), SQMOD_SKIN_OFFICE_LADY_B) + .Const(_SC("BUSINESS_MAN_E"), SQMOD_SKIN_BUSINESS_MAN_E) + .Const(_SC("BUSINESS_MAN_F"), SQMOD_SKIN_BUSINESS_MAN_F) + .Const(_SC("PROSTITUTE_D"), SQMOD_SKIN_PROSTITUTE_D) + .Const(_SC("BUM_LADY_E"), SQMOD_SKIN_BUM_LADY_E) + .Const(_SC("BUM_GUY_C"), SQMOD_SKIN_BUM_GUY_C) + .Const(_SC("SPANISH_GUY"), SQMOD_SKIN_SPANISH_GUY) + .Const(_SC("TAXI_DRIVER_B"), SQMOD_SKIN_TAXI_DRIVER_B) + .Const(_SC("GYM_LADY"), SQMOD_SKIN_GYM_LADY) + .Const(_SC("GYM_GUY"), SQMOD_SKIN_GYM_GUY) + .Const(_SC("SKATE_LADY"), SQMOD_SKIN_SKATE_LADY) + .Const(_SC("SKATE_GUY"), SQMOD_SKIN_SKATE_GUY) + .Const(_SC("SHOPPER_A"), SQMOD_SKIN_SHOPPER_A) + .Const(_SC("SHOPPER_B"), SQMOD_SKIN_SHOPPER_B) + .Const(_SC("TOURIST_A"), SQMOD_SKIN_TOURIST_A) + .Const(_SC("TOURIST_B"), SQMOD_SKIN_TOURIST_B) + .Const(_SC("CUBAN_A"), SQMOD_SKIN_CUBAN_A) + .Const(_SC("CUBAN_B"), SQMOD_SKIN_CUBAN_B) + .Const(_SC("HATIAN_C"), SQMOD_SKIN_HATIAN_C) + .Const(_SC("HATIAN_D"), SQMOD_SKIN_HATIAN_D) + .Const(_SC("SHARK_A"), SQMOD_SKIN_SHARK_A) + .Const(_SC("SHARK_B"), SQMOD_SKIN_SHARK_B) + .Const(_SC("DIAZ_GUY_A"), SQMOD_SKIN_DIAZ_GUY_A) + .Const(_SC("DIAZ_GUY_B"), SQMOD_SKIN_DIAZ_GUY_B) + .Const(_SC("DBP_SECURITY_A"), SQMOD_SKIN_DBP_SECURITY_A) + .Const(_SC("DBP_SECURITY_B"), SQMOD_SKIN_DBP_SECURITY_B) + .Const(_SC("BIKER_A"), SQMOD_SKIN_BIKER_A) + .Const(_SC("BIKER_B"), SQMOD_SKIN_BIKER_B) + .Const(_SC("VERCETTI_GUY_A"), SQMOD_SKIN_VERCETTI_GUY_A) + .Const(_SC("VERCETTI_GUY_B"), SQMOD_SKIN_VERCETTI_GUY_B) + .Const(_SC("UNDERCOVER_COP_A"), SQMOD_SKIN_UNDERCOVER_COP_A) + .Const(_SC("UNDERCOVER_COP_B"), SQMOD_SKIN_UNDERCOVER_COP_B) + .Const(_SC("UNDERCOVER_COP_C"), SQMOD_SKIN_UNDERCOVER_COP_C) + .Const(_SC("UNDERCOVER_COP_D"), SQMOD_SKIN_UNDERCOVER_COP_D) + .Const(_SC("UNDERCOVER_COP_E"), SQMOD_SKIN_UNDERCOVER_COP_E) + .Const(_SC("UNDERCOVER_COP_F"), SQMOD_SKIN_UNDERCOVER_COP_F) + .Const(_SC("RICH_GUY"), SQMOD_SKIN_RICH_GUY) + .Const(_SC("COOL_GUY_C"), SQMOD_SKIN_COOL_GUY_C) + .Const(_SC("PROSTITUTE_E"), SQMOD_SKIN_PROSTITUTE_E) + .Const(_SC("PROSTITUTE_F"), SQMOD_SKIN_PROSTITUTE_F) + .Const(_SC("LOVE_FIST_A"), SQMOD_SKIN_LOVE_FIST_A) + .Const(_SC("KEN_ROSENBURG"), SQMOD_SKIN_KEN_ROSENBURG) + .Const(_SC("CANDY_SUXX"), SQMOD_SKIN_CANDY_SUXX) + .Const(_SC("HILARY"), SQMOD_SKIN_HILARY) + .Const(_SC("LOVE_FIST_B"), SQMOD_SKIN_LOVE_FIST_B) + .Const(_SC("PHIL"), SQMOD_SKIN_PHIL) + .Const(_SC("ROCKSTAR_GUY"), SQMOD_SKIN_ROCKSTAR_GUY) + .Const(_SC("SONNY"), SQMOD_SKIN_SONNY) + .Const(_SC("LANCE_A"), SQMOD_SKIN_LANCE_A) + .Const(_SC("MERCADES_A"), SQMOD_SKIN_MERCADES_A) + .Const(_SC("LOVE_FIST_C"), SQMOD_SKIN_LOVE_FIST_C) + .Const(_SC("ALEX_SRUB"), SQMOD_SKIN_ALEX_SRUB) + .Const(_SC("LANCE_COP"), SQMOD_SKIN_LANCE_COP) + .Const(_SC("LANCE_B"), SQMOD_SKIN_LANCE_B) + .Const(_SC("CORTEZ"), SQMOD_SKIN_CORTEZ) + .Const(_SC("LOVE_FIST_D"), SQMOD_SKIN_LOVE_FIST_D) + .Const(_SC("COLUMBIAN_GUY_A"), SQMOD_SKIN_COLUMBIAN_GUY_A) + .Const(_SC("HILARY_ROBBER"), SQMOD_SKIN_HILARY_ROBBER) + .Const(_SC("MERCADES_B"), SQMOD_SKIN_MERCADES_B) + .Const(_SC("CAM"), SQMOD_SKIN_CAM) + .Const(_SC("CAM_ROBBER"), SQMOD_SKIN_CAM_ROBBER) + .Const(_SC("PHIL_ONE_ARM"), SQMOD_SKIN_PHIL_ONE_ARM) + .Const(_SC("PHIL_ROBBER"), SQMOD_SKIN_PHIL_ROBBER) + .Const(_SC("COOL_GUY_D"), SQMOD_SKIN_COOL_GUY_D) + .Const(_SC("PIZZAMAN"), SQMOD_SKIN_PIZZAMAN) + .Const(_SC("TAXI_DRIVER_C"), SQMOD_SKIN_TAXI_DRIVER_C) + .Const(_SC("TAXI_DRIVER_D"), SQMOD_SKIN_TAXI_DRIVER_D) + .Const(_SC("SAILOR_A"), SQMOD_SKIN_SAILOR_A) + .Const(_SC("SAILOR_B"), SQMOD_SKIN_SAILOR_B) + .Const(_SC("SAILOR_C"), SQMOD_SKIN_SAILOR_C) + .Const(_SC("CHEF"), SQMOD_SKIN_CHEF) + .Const(_SC("CRIMINAL_B"), SQMOD_SKIN_CRIMINAL_B) + .Const(_SC("FRENCH_GUY"), SQMOD_SKIN_FRENCH_GUY) + .Const(_SC("GARBAGEMAN_B"), SQMOD_SKIN_GARBAGEMAN_B) + .Const(_SC("HATIAN_E"), SQMOD_SKIN_HATIAN_E) + .Const(_SC("WAITRESS_B"), SQMOD_SKIN_WAITRESS_B) + .Const(_SC("SONNY_GUY_A"), SQMOD_SKIN_SONNY_GUY_A) + .Const(_SC("SONNY_GUY_B"), SQMOD_SKIN_SONNY_GUY_B) + .Const(_SC("SONNY_GUY_C"), SQMOD_SKIN_SONNY_GUY_C) + .Const(_SC("COLUMBIAN_GUY_B"), SQMOD_SKIN_COLUMBIAN_GUY_B) + .Const(_SC("THUG_A"), SQMOD_SKIN_THUG_A) + .Const(_SC("BEACH_GUY_H"), SQMOD_SKIN_BEACH_GUY_H) + .Const(_SC("GARBAGEMAN_C"), SQMOD_SKIN_GARBAGEMAN_C) + .Const(_SC("GARBAGEMAN_D"), SQMOD_SKIN_GARBAGEMAN_D) + .Const(_SC("GARBAGEMAN_E"), SQMOD_SKIN_GARBAGEMAN_E) + .Const(_SC("TRANNY"), SQMOD_SKIN_TRANNY) + .Const(_SC("THUG_B"), SQMOD_SKIN_THUG_B) + .Const(_SC("SPANDEX_GUY_A"), SQMOD_SKIN_SPANDEX_GUY_A) + .Const(_SC("SPANDEX_GUY_B"), SQMOD_SKIN_SPANDEX_GUY_B) + .Const(_SC("STRIPPER_A"), SQMOD_SKIN_STRIPPER_A) + .Const(_SC("STRIPPER_B"), SQMOD_SKIN_STRIPPER_B) + .Const(_SC("STRIPPER_C"), SQMOD_SKIN_STRIPPER_C) + .Const(_SC("STORE_CLERK"), SQMOD_SKIN_STORE_CLERK) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EKEYCODE"), Sqrat::Enumeration(vm) + .Const(_SC("ABNT_C1"), SQMOD_KEYCODE_ABNT_C1) + .Const(_SC("ABNT_C2"), SQMOD_KEYCODE_ABNT_C2) + .Const(_SC("ADD"), SQMOD_KEYCODE_ADD) + .Const(_SC("ATTN"), SQMOD_KEYCODE_ATTN) + .Const(_SC("BACK"), SQMOD_KEYCODE_BACK) + .Const(_SC("CANCEL"), SQMOD_KEYCODE_CANCEL) + .Const(_SC("CLEAR"), SQMOD_KEYCODE_CLEAR) + .Const(_SC("CRSEL"), SQMOD_KEYCODE_CRSEL) + .Const(_SC("DECIMAL"), SQMOD_KEYCODE_DECIMAL) + .Const(_SC("DIVIDE"), SQMOD_KEYCODE_DIVIDE) + .Const(_SC("EREOF"), SQMOD_KEYCODE_EREOF) + .Const(_SC("ESCAPE"), SQMOD_KEYCODE_ESCAPE) + .Const(_SC("EXECUTE"), SQMOD_KEYCODE_EXECUTE) + .Const(_SC("EXSEL"), SQMOD_KEYCODE_EXSEL) + .Const(_SC("ICO_CLEAR"), SQMOD_KEYCODE_ICO_CLEAR) + .Const(_SC("ICO_HELP"), SQMOD_KEYCODE_ICO_HELP) + .Const(_SC("KEY_0"), SQMOD_KEYCODE_KEY_0) + .Const(_SC("KEY_1"), SQMOD_KEYCODE_KEY_1) + .Const(_SC("KEY_2"), SQMOD_KEYCODE_KEY_2) + .Const(_SC("KEY_3"), SQMOD_KEYCODE_KEY_3) + .Const(_SC("KEY_4"), SQMOD_KEYCODE_KEY_4) + .Const(_SC("KEY_5"), SQMOD_KEYCODE_KEY_5) + .Const(_SC("KEY_6"), SQMOD_KEYCODE_KEY_6) + .Const(_SC("KEY_7"), SQMOD_KEYCODE_KEY_7) + .Const(_SC("KEY_8"), SQMOD_KEYCODE_KEY_8) + .Const(_SC("KEY_9"), SQMOD_KEYCODE_KEY_9) + .Const(_SC("KEY_A"), SQMOD_KEYCODE_KEY_A) + .Const(_SC("KEY_B"), SQMOD_KEYCODE_KEY_B) + .Const(_SC("KEY_C"), SQMOD_KEYCODE_KEY_C) + .Const(_SC("KEY_D"), SQMOD_KEYCODE_KEY_D) + .Const(_SC("KEY_E"), SQMOD_KEYCODE_KEY_E) + .Const(_SC("KEY_F"), SQMOD_KEYCODE_KEY_F) + .Const(_SC("KEY_G"), SQMOD_KEYCODE_KEY_G) + .Const(_SC("KEY_H"), SQMOD_KEYCODE_KEY_H) + .Const(_SC("KEY_I"), SQMOD_KEYCODE_KEY_I) + .Const(_SC("KEY_J"), SQMOD_KEYCODE_KEY_J) + .Const(_SC("KEY_K"), SQMOD_KEYCODE_KEY_K) + .Const(_SC("KEY_L"), SQMOD_KEYCODE_KEY_L) + .Const(_SC("KEY_M"), SQMOD_KEYCODE_KEY_M) + .Const(_SC("KEY_N"), SQMOD_KEYCODE_KEY_N) + .Const(_SC("KEY_O"), SQMOD_KEYCODE_KEY_O) + .Const(_SC("KEY_P"), SQMOD_KEYCODE_KEY_P) + .Const(_SC("KEY_Q"), SQMOD_KEYCODE_KEY_Q) + .Const(_SC("KEY_R"), SQMOD_KEYCODE_KEY_R) + .Const(_SC("KEY_S"), SQMOD_KEYCODE_KEY_S) + .Const(_SC("KEY_T"), SQMOD_KEYCODE_KEY_T) + .Const(_SC("KEY_U"), SQMOD_KEYCODE_KEY_U) + .Const(_SC("KEY_V"), SQMOD_KEYCODE_KEY_V) + .Const(_SC("KEY_W"), SQMOD_KEYCODE_KEY_W) + .Const(_SC("KEY_X"), SQMOD_KEYCODE_KEY_X) + .Const(_SC("KEY_Y"), SQMOD_KEYCODE_KEY_Y) + .Const(_SC("KEY_Z"), SQMOD_KEYCODE_KEY_Z) + .Const(_SC("MULTIPLY"), SQMOD_KEYCODE_MULTIPLY) + .Const(_SC("NONAME"), SQMOD_KEYCODE_NONAME) + .Const(_SC("NUMPAD0"), SQMOD_KEYCODE_NUMPAD0) + .Const(_SC("NUMPAD1"), SQMOD_KEYCODE_NUMPAD1) + .Const(_SC("NUMPAD2"), SQMOD_KEYCODE_NUMPAD2) + .Const(_SC("NUMPAD3"), SQMOD_KEYCODE_NUMPAD3) + .Const(_SC("NUMPAD4"), SQMOD_KEYCODE_NUMPAD4) + .Const(_SC("NUMPAD5"), SQMOD_KEYCODE_NUMPAD5) + .Const(_SC("NUMPAD6"), SQMOD_KEYCODE_NUMPAD6) + .Const(_SC("NUMPAD7"), SQMOD_KEYCODE_NUMPAD7) + .Const(_SC("NUMPAD8"), SQMOD_KEYCODE_NUMPAD8) + .Const(_SC("NUMPAD9"), SQMOD_KEYCODE_NUMPAD9) + .Const(_SC("OEM_1"), SQMOD_KEYCODE_OEM_1) + .Const(_SC("OEM_102"), SQMOD_KEYCODE_OEM_102) + .Const(_SC("OEM_2"), SQMOD_KEYCODE_OEM_2) + .Const(_SC("OEM_3"), SQMOD_KEYCODE_OEM_3) + .Const(_SC("OEM_4"), SQMOD_KEYCODE_OEM_4) + .Const(_SC("OEM_5"), SQMOD_KEYCODE_OEM_5) + .Const(_SC("OEM_6"), SQMOD_KEYCODE_OEM_6) + .Const(_SC("OEM_7"), SQMOD_KEYCODE_OEM_7) + .Const(_SC("OEM_8"), SQMOD_KEYCODE_OEM_8) + .Const(_SC("OEM_ATTN"), SQMOD_KEYCODE_OEM_ATTN) + .Const(_SC("OEM_AUTO"), SQMOD_KEYCODE_OEM_AUTO) + .Const(_SC("OEM_AX"), SQMOD_KEYCODE_OEM_AX) + .Const(_SC("OEM_BACKTAB"), SQMOD_KEYCODE_OEM_BACKTAB) + .Const(_SC("OEM_CLEAR"), SQMOD_KEYCODE_OEM_CLEAR) + .Const(_SC("OEM_COMMA"), SQMOD_KEYCODE_OEM_COMMA) + .Const(_SC("OEM_COPY"), SQMOD_KEYCODE_OEM_COPY) + .Const(_SC("OEM_CUSEL"), SQMOD_KEYCODE_OEM_CUSEL) + .Const(_SC("OEM_ENLW"), SQMOD_KEYCODE_OEM_ENLW) + .Const(_SC("OEM_FINISH"), SQMOD_KEYCODE_OEM_FINISH) + .Const(_SC("OEM_FJ_LOYA"), SQMOD_KEYCODE_OEM_FJ_LOYA) + .Const(_SC("OEM_FJ_MASSHOU"), SQMOD_KEYCODE_OEM_FJ_MASSHOU) + .Const(_SC("OEM_FJ_ROYA"), SQMOD_KEYCODE_OEM_FJ_ROYA) + .Const(_SC("OEM_FJ_TOUROKU"), SQMOD_KEYCODE_OEM_FJ_TOUROKU) + .Const(_SC("OEM_JUMP"), SQMOD_KEYCODE_OEM_JUMP) + .Const(_SC("OEM_MINUS"), SQMOD_KEYCODE_OEM_MINUS) + .Const(_SC("OEM_PA1"), SQMOD_KEYCODE_OEM_PA1) + .Const(_SC("OEM_PA2"), SQMOD_KEYCODE_OEM_PA2) + .Const(_SC("OEM_PA3"), SQMOD_KEYCODE_OEM_PA3) + .Const(_SC("OEM_PERIOD"), SQMOD_KEYCODE_OEM_PERIOD) + .Const(_SC("OEM_PLUS"), SQMOD_KEYCODE_OEM_PLUS) + .Const(_SC("OEM_RESET"), SQMOD_KEYCODE_OEM_RESET) + .Const(_SC("OEM_WSCTRL"), SQMOD_KEYCODE_OEM_WSCTRL) + .Const(_SC("PA1"), SQMOD_KEYCODE_PA1) + .Const(_SC("PACKET"), SQMOD_KEYCODE_PACKET) + .Const(_SC("PLAY"), SQMOD_KEYCODE_PLAY) + .Const(_SC("PROCESSKEY"), SQMOD_KEYCODE_PROCESSKEY) + .Const(_SC("RETURN"), SQMOD_KEYCODE_RETURN) + .Const(_SC("SELECT"), SQMOD_KEYCODE_SELECT) + .Const(_SC("SEPARATOR"), SQMOD_KEYCODE_SEPARATOR) + .Const(_SC("SPACE"), SQMOD_KEYCODE_SPACE) + .Const(_SC("SUBTRACT"), SQMOD_KEYCODE_SUBTRACT) + .Const(_SC("TAB"), SQMOD_KEYCODE_TAB) + .Const(_SC("ZOOM"), SQMOD_KEYCODE_ZOOM) + .Const(_SC("ACCEPT"), SQMOD_KEYCODE_ACCEPT) + .Const(_SC("APPS"), SQMOD_KEYCODE_APPS) + .Const(_SC("BROWSER_BACK"), SQMOD_KEYCODE_BROWSER_BACK) + .Const(_SC("BROWSER_FAVORITES"), SQMOD_KEYCODE_BROWSER_FAVORITES) + .Const(_SC("BROWSER_FORWARD"), SQMOD_KEYCODE_BROWSER_FORWARD) + .Const(_SC("BROWSER_HOME"), SQMOD_KEYCODE_BROWSER_HOME) + .Const(_SC("BROWSER_REFRESH"), SQMOD_KEYCODE_BROWSER_REFRESH) + .Const(_SC("BROWSER_SEARCH"), SQMOD_KEYCODE_BROWSER_SEARCH) + .Const(_SC("BROWSER_STOP"), SQMOD_KEYCODE_BROWSER_STOP) + .Const(_SC("CAPITAL"), SQMOD_KEYCODE_CAPITAL) + .Const(_SC("CONVERT"), SQMOD_KEYCODE_CONVERT) + .Const(_SC("DELETE"), SQMOD_KEYCODE_DELETE) + .Const(_SC("DOWN"), SQMOD_KEYCODE_DOWN) + .Const(_SC("END"), SQMOD_KEYCODE_END) + .Const(_SC("F1"), SQMOD_KEYCODE_F1) + .Const(_SC("F10"), SQMOD_KEYCODE_F10) + .Const(_SC("F11"), SQMOD_KEYCODE_F11) + .Const(_SC("F12"), SQMOD_KEYCODE_F12) + .Const(_SC("F13"), SQMOD_KEYCODE_F13) + .Const(_SC("F14"), SQMOD_KEYCODE_F14) + .Const(_SC("F15"), SQMOD_KEYCODE_F15) + .Const(_SC("F16"), SQMOD_KEYCODE_F16) + .Const(_SC("F17"), SQMOD_KEYCODE_F17) + .Const(_SC("F18"), SQMOD_KEYCODE_F18) + .Const(_SC("F19"), SQMOD_KEYCODE_F19) + .Const(_SC("F2"), SQMOD_KEYCODE_F2) + .Const(_SC("F20"), SQMOD_KEYCODE_F20) + .Const(_SC("F21"), SQMOD_KEYCODE_F21) + .Const(_SC("F22"), SQMOD_KEYCODE_F22) + .Const(_SC("F23"), SQMOD_KEYCODE_F23) + .Const(_SC("F24"), SQMOD_KEYCODE_F24) + .Const(_SC("F3"), SQMOD_KEYCODE_F3) + .Const(_SC("F4"), SQMOD_KEYCODE_F4) + .Const(_SC("F5"), SQMOD_KEYCODE_F5) + .Const(_SC("F6"), SQMOD_KEYCODE_F6) + .Const(_SC("F7"), SQMOD_KEYCODE_F7) + .Const(_SC("F8"), SQMOD_KEYCODE_F8) + .Const(_SC("F9"), SQMOD_KEYCODE_F9) + .Const(_SC("FINAL"), SQMOD_KEYCODE_FINAL) + .Const(_SC("HELP"), SQMOD_KEYCODE_HELP) + .Const(_SC("HOME"), SQMOD_KEYCODE_HOME) + .Const(_SC("ICO_00"), SQMOD_KEYCODE_ICO_00) + .Const(_SC("INSERT"), SQMOD_KEYCODE_INSERT) + .Const(_SC("JUNJA"), SQMOD_KEYCODE_JUNJA) + .Const(_SC("KANA"), SQMOD_KEYCODE_KANA) + .Const(_SC("KANJI"), SQMOD_KEYCODE_KANJI) + .Const(_SC("LAUNCH_APP1"), SQMOD_KEYCODE_LAUNCH_APP1) + .Const(_SC("LAUNCH_APP2"), SQMOD_KEYCODE_LAUNCH_APP2) + .Const(_SC("LAUNCH_MAIL"), SQMOD_KEYCODE_LAUNCH_MAIL) + .Const(_SC("LAUNCH_MEDIA_SELECT"), SQMOD_KEYCODE_LAUNCH_MEDIA_SELECT) + .Const(_SC("LBUTTON"), SQMOD_KEYCODE_LBUTTON) + .Const(_SC("LCONTROL"), SQMOD_KEYCODE_LCONTROL) + .Const(_SC("LEFT"), SQMOD_KEYCODE_LEFT) + .Const(_SC("LMENU"), SQMOD_KEYCODE_LMENU) + .Const(_SC("LSHIFT"), SQMOD_KEYCODE_LSHIFT) + .Const(_SC("LWIN"), SQMOD_KEYCODE_LWIN) + .Const(_SC("MBUTTON"), SQMOD_KEYCODE_MBUTTON) + .Const(_SC("MEDIA_NEXT_TRACK"), SQMOD_KEYCODE_MEDIA_NEXT_TRACK) + .Const(_SC("MEDIA_PLAY_PAUSE"), SQMOD_KEYCODE_MEDIA_PLAY_PAUSE) + .Const(_SC("MEDIA_PREV_TRACK"), SQMOD_KEYCODE_MEDIA_PREV_TRACK) + .Const(_SC("MEDIA_STOP"), SQMOD_KEYCODE_MEDIA_STOP) + .Const(_SC("MODECHANGE"), SQMOD_KEYCODE_MODECHANGE) + .Const(_SC("NEXT"), SQMOD_KEYCODE_NEXT) + .Const(_SC("NONCONVERT"), SQMOD_KEYCODE_NONCONVERT) + .Const(_SC("NUMLOCK"), SQMOD_KEYCODE_NUMLOCK) + .Const(_SC("OEM_FJ_JISHO"), SQMOD_KEYCODE_OEM_FJ_JISHO) + .Const(_SC("PAUSE"), SQMOD_KEYCODE_PAUSE) + .Const(_SC("PRINT"), SQMOD_KEYCODE_PRINT) + .Const(_SC("PRIOR"), SQMOD_KEYCODE_PRIOR) + .Const(_SC("RBUTTON"), SQMOD_KEYCODE_RBUTTON) + .Const(_SC("RCONTROL"), SQMOD_KEYCODE_RCONTROL) + .Const(_SC("RIGHT"), SQMOD_KEYCODE_RIGHT) + .Const(_SC("RMENU"), SQMOD_KEYCODE_RMENU) + .Const(_SC("RSHIFT"), SQMOD_KEYCODE_RSHIFT) + .Const(_SC("RWIN"), SQMOD_KEYCODE_RWIN) + .Const(_SC("SCROLL"), SQMOD_KEYCODE_SCROLL) + .Const(_SC("SLEEP"), SQMOD_KEYCODE_SLEEP) + .Const(_SC("SNAPSHOT"), SQMOD_KEYCODE_SNAPSHOT) + .Const(_SC("UP"), SQMOD_KEYCODE_UP) + .Const(_SC("VOLUME_DOWN"), SQMOD_KEYCODE_VOLUME_DOWN) + .Const(_SC("VOLUME_MUTE"), SQMOD_KEYCODE_VOLUME_MUTE) + .Const(_SC("VOLUME_UP"), SQMOD_KEYCODE_VOLUME_UP) + .Const(_SC("XBUTTON1"), SQMOD_KEYCODE_XBUTTON1) + .Const(_SC("XBUTTON2"), SQMOD_KEYCODE_XBUTTON2) + .Const(_SC("NONE"), SQMOD_KEYCODE_NONE) + ); + + Sqrat::ConstTable(vm).Enum(_SC("EASCII"), Sqrat::Enumeration(vm) + .Const(_SC("NUL"), SQMOD_ASCII_NUL) + .Const(_SC("SOH"), SQMOD_ASCII_SOH) + .Const(_SC("STX"), SQMOD_ASCII_STX) + .Const(_SC("ETX"), SQMOD_ASCII_ETX) + .Const(_SC("EOT"), SQMOD_ASCII_EOT) + .Const(_SC("ENQ"), SQMOD_ASCII_ENQ) + .Const(_SC("ACK"), SQMOD_ASCII_ACK) + .Const(_SC("BEL"), SQMOD_ASCII_BEL) + .Const(_SC("BS"), SQMOD_ASCII_BS) + .Const(_SC("TAB"), SQMOD_ASCII_TAB) + .Const(_SC("LF"), SQMOD_ASCII_LF) + .Const(_SC("VT"), SQMOD_ASCII_VT) + .Const(_SC("FF"), SQMOD_ASCII_FF) + .Const(_SC("CR"), SQMOD_ASCII_CR) + .Const(_SC("SO"), SQMOD_ASCII_SO) + .Const(_SC("SI"), SQMOD_ASCII_SI) + .Const(_SC("DLE"), SQMOD_ASCII_DLE) + .Const(_SC("DC1"), SQMOD_ASCII_DC1) + .Const(_SC("DC2"), SQMOD_ASCII_DC2) + .Const(_SC("DC3"), SQMOD_ASCII_DC3) + .Const(_SC("DC4"), SQMOD_ASCII_DC4) + .Const(_SC("NAK"), SQMOD_ASCII_NAK) + .Const(_SC("SYN"), SQMOD_ASCII_SYN) + .Const(_SC("ETB"), SQMOD_ASCII_ETB) + .Const(_SC("CAN"), SQMOD_ASCII_CAN) + .Const(_SC("EM"), SQMOD_ASCII_EM) + .Const(_SC("SUB"), SQMOD_ASCII_SUB) + .Const(_SC("ESC"), SQMOD_ASCII_ESC) + .Const(_SC("FS"), SQMOD_ASCII_FS) + .Const(_SC("GS"), SQMOD_ASCII_GS) + .Const(_SC("RS"), SQMOD_ASCII_RS) + .Const(_SC("US"), SQMOD_ASCII_US) + .Const(_SC("SPACE"), SQMOD_ASCII_SPACE) + .Const(_SC("EXCLAMATION_POINT"), SQMOD_ASCII_EXCLAMATION_POINT) + .Const(_SC("DOUBLE_QUOTES"), SQMOD_ASCII_DOUBLE_QUOTES) + .Const(_SC("NUMBER_SIGN"), SQMOD_ASCII_NUMBER_SIGN) + .Const(_SC("DOLLAR_SIGN"), SQMOD_ASCII_DOLLAR_SIGN) + .Const(_SC("PERCENT_SIGN"), SQMOD_ASCII_PERCENT_SIGN) + .Const(_SC("AMPERSAND"), SQMOD_ASCII_AMPERSAND) + .Const(_SC("SINGLE_QUOTE"), SQMOD_ASCII_SINGLE_QUOTE) + .Const(_SC("OPENING_PARENTHESIS"), SQMOD_ASCII_OPENING_PARENTHESIS) + .Const(_SC("CLOSING_PARENTHESIS"), SQMOD_ASCII_CLOSING_PARENTHESIS) + .Const(_SC("ASTERISK"), SQMOD_ASCII_ASTERISK) + .Const(_SC("PLUS"), SQMOD_ASCII_PLUS) + .Const(_SC("COMMA"), SQMOD_ASCII_COMMA) + .Const(_SC("MINUS"), SQMOD_ASCII_MINUS) + .Const(_SC("PERIOD"), SQMOD_ASCII_PERIOD) + .Const(_SC("SLASH"), SQMOD_ASCII_SLASH) + .Const(_SC("ZERO"), SQMOD_ASCII_ZERO) + .Const(_SC("ONE"), SQMOD_ASCII_ONE) + .Const(_SC("TWO"), SQMOD_ASCII_TWO) + .Const(_SC("THREE"), SQMOD_ASCII_THREE) + .Const(_SC("FOUR"), SQMOD_ASCII_FOUR) + .Const(_SC("FIVE"), SQMOD_ASCII_FIVE) + .Const(_SC("SIX"), SQMOD_ASCII_SIX) + .Const(_SC("SEVEN"), SQMOD_ASCII_SEVEN) + .Const(_SC("EIGHT"), SQMOD_ASCII_EIGHT) + .Const(_SC("NINE"), SQMOD_ASCII_NINE) + .Const(_SC("COLON"), SQMOD_ASCII_COLON) + .Const(_SC("EMICOLON"), SQMOD_ASCII_EMICOLON) + .Const(_SC("LESS_THAN_SIGN"), SQMOD_ASCII_LESS_THAN_SIGN) + .Const(_SC("EQUAL_SIGN"), SQMOD_ASCII_EQUAL_SIGN) + .Const(_SC("GREATER_THAN_SIGN"), SQMOD_ASCII_GREATER_THAN_SIGN) + .Const(_SC("QUESTION_MARK"), SQMOD_ASCII_QUESTION_MARK) + .Const(_SC("AT"), SQMOD_ASCII_AT) + .Const(_SC("UPPER_A"), SQMOD_ASCII_UPPER_A) + .Const(_SC("UPPER_B"), SQMOD_ASCII_UPPER_B) + .Const(_SC("UPPER_C"), SQMOD_ASCII_UPPER_C) + .Const(_SC("UPPER_D"), SQMOD_ASCII_UPPER_D) + .Const(_SC("UPPER_E"), SQMOD_ASCII_UPPER_E) + .Const(_SC("UPPER_F"), SQMOD_ASCII_UPPER_F) + .Const(_SC("UPPER_G"), SQMOD_ASCII_UPPER_G) + .Const(_SC("UPPER_H"), SQMOD_ASCII_UPPER_H) + .Const(_SC("UPPER_I"), SQMOD_ASCII_UPPER_I) + .Const(_SC("UPPER_J"), SQMOD_ASCII_UPPER_J) + .Const(_SC("UPPER_K"), SQMOD_ASCII_UPPER_K) + .Const(_SC("UPPER_L"), SQMOD_ASCII_UPPER_L) + .Const(_SC("UPPER_M"), SQMOD_ASCII_UPPER_M) + .Const(_SC("UPPER_N"), SQMOD_ASCII_UPPER_N) + .Const(_SC("UPPER_O"), SQMOD_ASCII_UPPER_O) + .Const(_SC("UPPER_P"), SQMOD_ASCII_UPPER_P) + .Const(_SC("UPPER_Q"), SQMOD_ASCII_UPPER_Q) + .Const(_SC("UPPER_R"), SQMOD_ASCII_UPPER_R) + .Const(_SC("UPPER_S"), SQMOD_ASCII_UPPER_S) + .Const(_SC("UPPER_T"), SQMOD_ASCII_UPPER_T) + .Const(_SC("UPPER_U"), SQMOD_ASCII_UPPER_U) + .Const(_SC("UPPER_V"), SQMOD_ASCII_UPPER_V) + .Const(_SC("UPPER_W"), SQMOD_ASCII_UPPER_W) + .Const(_SC("UPPER_X"), SQMOD_ASCII_UPPER_X) + .Const(_SC("UPPER_Y"), SQMOD_ASCII_UPPER_Y) + .Const(_SC("UPPER_Z"), SQMOD_ASCII_UPPER_Z) + .Const(_SC("OPENING_BRACKET"), SQMOD_ASCII_OPENING_BRACKET) + .Const(_SC("BACKSLASH"), SQMOD_ASCII_BACKSLASH) + .Const(_SC("CLOSING_BRACKET"), SQMOD_ASCII_CLOSING_BRACKET) + .Const(_SC("CARET"), SQMOD_ASCII_CARET) + .Const(_SC("UNDERSCORE"), SQMOD_ASCII_UNDERSCORE) + .Const(_SC("GRAVE_ACCENT"), SQMOD_ASCII_GRAVE_ACCENT) + .Const(_SC("LOWER_A"), SQMOD_ASCII_LOWER_A) + .Const(_SC("LOWER_B"), SQMOD_ASCII_LOWER_B) + .Const(_SC("LOWER_C"), SQMOD_ASCII_LOWER_C) + .Const(_SC("LOWER_D"), SQMOD_ASCII_LOWER_D) + .Const(_SC("LOWER_E"), SQMOD_ASCII_LOWER_E) + .Const(_SC("LOWER_F"), SQMOD_ASCII_LOWER_F) + .Const(_SC("LOWER_G"), SQMOD_ASCII_LOWER_G) + .Const(_SC("LOWER_H"), SQMOD_ASCII_LOWER_H) + .Const(_SC("LOWER_I"), SQMOD_ASCII_LOWER_I) + .Const(_SC("LOWER_J"), SQMOD_ASCII_LOWER_J) + .Const(_SC("LOWER_K"), SQMOD_ASCII_LOWER_K) + .Const(_SC("LOWER_L"), SQMOD_ASCII_LOWER_L) + .Const(_SC("LOWER_M"), SQMOD_ASCII_LOWER_M) + .Const(_SC("LOWER_N"), SQMOD_ASCII_LOWER_N) + .Const(_SC("LOWER_O"), SQMOD_ASCII_LOWER_O) + .Const(_SC("LOWER_P"), SQMOD_ASCII_LOWER_P) + .Const(_SC("LOWER_Q"), SQMOD_ASCII_LOWER_Q) + .Const(_SC("LOWER_R"), SQMOD_ASCII_LOWER_R) + .Const(_SC("LOWER_S"), SQMOD_ASCII_LOWER_S) + .Const(_SC("LOWER_T"), SQMOD_ASCII_LOWER_T) + .Const(_SC("LOWER_U"), SQMOD_ASCII_LOWER_U) + .Const(_SC("LOWER_V"), SQMOD_ASCII_LOWER_V) + .Const(_SC("LOWER_W"), SQMOD_ASCII_LOWER_W) + .Const(_SC("LOWER_X"), SQMOD_ASCII_LOWER_X) + .Const(_SC("LOWER_Y"), SQMOD_ASCII_LOWER_Y) + .Const(_SC("LOWER_Z"), SQMOD_ASCII_LOWER_Z) + .Const(_SC("OPENING_BRACE"), SQMOD_ASCII_OPENING_BRACE) + .Const(_SC("VERTICAL_BAR"), SQMOD_ASCII_VERTICAL_BAR) + .Const(_SC("CLOSING_BRACE"), SQMOD_ASCII_CLOSING_BRACE) + .Const(_SC("TILDE"), SQMOD_ASCII_TILDE) + .Const(_SC("UNDEFINED"), SQMOD_ASCII_UNDEFINED) + ); + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Misc/Constants.hpp b/source/Misc/Constants.hpp new file mode 100644 index 00000000..903d5c47 --- /dev/null +++ b/source/Misc/Constants.hpp @@ -0,0 +1,14 @@ +#ifndef _MISC_CONSTANTS_HPP_ +#define _MISC_CONSTANTS_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ + +} // Namespace:: SqMod + +#endif // _MISC_CONSTANTS_HPP_ \ No newline at end of file diff --git a/source/Misc/Functions.cpp b/source/Misc/Functions.cpp new file mode 100644 index 00000000..3e08fa69 --- /dev/null +++ b/source/Misc/Functions.cpp @@ -0,0 +1,13 @@ +#include "Misc/Functions.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_Functions(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Misc/Functions.hpp b/source/Misc/Functions.hpp new file mode 100644 index 00000000..7eededf8 --- /dev/null +++ b/source/Misc/Functions.hpp @@ -0,0 +1,11 @@ +#ifndef _MISC_FUNCTIONS_HPP_ +#define _MISC_FUNCTIONS_HPP_ + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ + +} // Namespace:: SqMod + +#endif // _MISC_FUNCTIONS_HPP_ \ No newline at end of file diff --git a/source/Misc/Model.cpp b/source/Misc/Model.cpp new file mode 100644 index 00000000..d63866c9 --- /dev/null +++ b/source/Misc/Model.cpp @@ -0,0 +1,288 @@ +#include "Misc/Model.hpp" +#include "Base/Vector3.hpp" +#include "Entity.hpp" +#include "Register.hpp" +#include "Core.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const CModel CModel::NIL; + +// ------------------------------------------------------------------------------------------------ +CModel::CModel() noexcept + : m_ID(SQMOD_UNKNOWN), m_Name() +{ + +} + +CModel::CModel(SQInt32 id) noexcept + : m_ID(VALID_ENTITYGETEX(id, Max)), m_Name(GetModelName(id)) +{ + +} + +CModel::CModel(const SQChar * name, SQInt32 id) noexcept + : CModel(WeaponToModel(IsWeaponValid(GetWeaponID(name)) ? GetWeaponID(name) : id)) +{ + +} + +// ------------------------------------------------------------------------------------------------ +CModel::CModel(const CModel & m) noexcept + : m_ID(m.m_ID) + , m_Name(m.m_Name) + , m_Tag(m.m_Tag) + , m_Data(m.m_Data) +{ + +} + +CModel::CModel(CModel && m) noexcept + : m_ID(m.m_ID) + , m_Name(m.m_Name) + , m_Tag(m.m_Tag) + , m_Data(m.m_Data) +{ + +} + +// ------------------------------------------------------------------------------------------------ +CModel::~CModel() +{ + +} + +// ------------------------------------------------------------------------------------------------ +CModel & CModel::operator = (const CModel & m) noexcept +{ + m_ID = m.m_ID; + m_Name = m.m_Name; + m_Tag = m.m_Tag; + m_Data = m.m_Data; + return *this; +} + +CModel & CModel::operator = (CModel && m) noexcept +{ + m_ID = m.m_ID; + m_Name = m.m_Name; + m_Tag = m.m_Tag; + m_Data = m.m_Data; + return *this; +} + +// ------------------------------------------------------------------------------------------------ +CModel & CModel::operator = (SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetModelName(id); + m_ID = id; + } + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +bool CModel::operator == (const CModel & m) const noexcept +{ + return (m_ID == m.m_ID); +} + +bool CModel::operator != (const CModel & m) const noexcept +{ + return (m_ID != m.m_ID); +} + +bool CModel::operator < (const CModel & m) const noexcept +{ + return (m_ID < m.m_ID); +} + +bool CModel::operator > (const CModel & m) const noexcept +{ + return (m_ID < m.m_ID); +} + +bool CModel::operator <= (const CModel & m) const noexcept +{ + return (m_ID <= m.m_ID); +} + +bool CModel::operator >= (const CModel & m) const noexcept +{ + return (m_ID >= m.m_ID); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CModel::Cmp(const CModel & m) const noexcept +{ + return m_ID == m.m_ID ? 0 : (m_ID > m.m_ID ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CModel::ToString() const noexcept +{ + return m_Name.c_str(); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CModel::GetID() const noexcept +{ + return m_ID; +} + +void CModel::SetID(SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetModelName(id); + m_ID = id; + } +} + +// ------------------------------------------------------------------------------------------------ +CModel & CModel::SetnGet(SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetModelName(id); + m_ID = id; + } + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CModel::GetGlobalTag() const noexcept +{ + return GlobalTag(m_ID); +} + +void CModel::SetGlobalTag(const SQChar * tag) const noexcept +{ + GlobalTag(m_ID, tag); +} + +// ------------------------------------------------------------------------------------------------ +SqObj & CModel::GetGlobalData() const noexcept +{ + return GlobalData(m_ID); +} + +void CModel::SetGlobalData(SqObj & data) const noexcept +{ + GlobalData(m_ID, data); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CModel::GetLocalTag() const noexcept +{ + return m_Tag.c_str(); +} + +void CModel::SetLocalTag(const SQChar * tag) noexcept +{ + m_Tag = tag; +} + +// ------------------------------------------------------------------------------------------------ +SqObj & CModel::GetLocalData() noexcept +{ + return m_Data; +} + +void CModel::SetLocalData(SqObj & data) noexcept +{ + m_Data = data; +} + +// ------------------------------------------------------------------------------------------------ +bool CModel::IsValid() const noexcept +{ + return (m_ID > 0); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CModel::GetName() const noexcept +{ + return m_Name.c_str(); +} + +// ------------------------------------------------------------------------------------------------ +bool CModel::IsWeapon() const noexcept +{ + return IsModelWeapon(m_ID); +} + +bool CModel::IsActuallyWeapon() const noexcept +{ + return IsModelActuallyWeapon(m_ID); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CObject > CModel::Object(SQInt32 world, const Vector3 & pos, SQInt32 alpha, SQInt32 header, \ + const SqObj & payload) const noexcept +{ + return _Core->CreateObject(*this, world, pos, alpha, header, payload); +} + +Reference< CObject > CModel::Object(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQInt32 alpha, \ + SQInt32 header, const SqObj & payload) const noexcept +{ + return _Core->CreateObject(*this, world, Vector3(x, y, z), alpha, header, payload); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CPickup > CModel::Pickup(SQInt32 world, SQInt32 quantity, const Vector3 & pos, SQInt32 alpha, \ + bool automatic, SQInt32 header, const SqObj & payload) const noexcept +{ + return _Core->CreatePickup(*this, world, quantity, pos, alpha, automatic, header, payload); +} + +Reference< CPickup > CModel::Pickup(SQInt32 world, SQInt32 quantity, SQFloat x, SQFloat y, SQFloat z, \ + SQInt32 alpha, bool automatic, SQInt32 header, const SqObj & payload) const noexcept +{ + return _Core->CreatePickup(*this, world, quantity, Vector3(x, y, z), alpha, automatic, header, payload); +} + +// ================================================================================================ +bool Register_CModel(HSQUIRRELVM vm) +{ + // Output debugging information + LogDbg("Beginning registration of type"); + // Attempt to register the specified type + Sqrat::RootTable(vm).Bind(_SC("CModel"), Sqrat::Class< CModel >(vm, _SC("CModel")) + .Ctor() + .Ctor< SQInt32 >() + .Ctor< const SQChar *, SQInt32 >() + + .Func(_SC("_cmp"), &CModel::Cmp) + .Func(_SC("_tostring"), &CModel::ToString) + + .Prop(_SC("id"), &CModel::GetID, &CModel::SetID) + .Prop(_SC("gtag"), &CModel::GetGlobalTag, &CModel::SetGlobalTag) + .Prop(_SC("gdata"), &CModel::GetGlobalData, &CModel::SetGlobalData) + .Prop(_SC("ltag"), &CModel::GetLocalTag, &CModel::SetLocalTag) + .Prop(_SC("ldata"), &CModel::GetLocalData, &CModel::SetLocalData) + .Prop(_SC("valid"), &CModel::IsValid) + .Prop(_SC("name"), &CModel::GetName) + .Prop(_SC("weapon"), &CModel::IsWeapon) + .Prop(_SC("truly_weapon"), &CModel::IsActuallyWeapon) + + .Func(_SC("setng"), &CModel::SetnGet) + + .Overload< Reference< CObject > (CModel::*)(SQInt32, const Vector3 &, SQInt32, SQInt32, const SqObj &) const >(_SC("object"), &CModel::Object) + .Overload< Reference< CObject > (CModel::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, SQInt32, const SqObj &) const >(_SC("object"), &CModel::Object) + .Overload< Reference< CPickup > (CModel::*)(SQInt32, SQInt32, const Vector3 &, SQInt32, bool, SQInt32, const SqObj &) const >(_SC("pickup"), &CModel::Pickup) + .Overload< Reference< CPickup > (CModel::*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, bool, SQInt32, const SqObj &) const >(_SC("pickup"), &CModel::Pickup) + ); + // Output debugging information + LogDbg("Registration of type was successful"); + // Registration succeeded + return true; +} + +} // Namespace:: SqMod diff --git a/source/Misc/Model.hpp b/source/Misc/Model.hpp new file mode 100644 index 00000000..47aac001 --- /dev/null +++ b/source/Misc/Model.hpp @@ -0,0 +1,92 @@ +#ifndef _MISC_MODEL_HPP_ +#define _MISC_MODEL_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Misc/Shared.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +class CModel : public IdentifierStorage< CModel, SQMOD_MODELID_CAP > +{ +public: + // -------------------------------------------------------------------------------------------- + static const CModel NIL; + // -------------------------------------------------------------------------------------------- + CModel() noexcept; + CModel(SQInt32 id) noexcept; + CModel(const SQChar * name, SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CModel(const CModel & m) noexcept; + CModel(CModel && m) noexcept; + // -------------------------------------------------------------------------------------------- + ~CModel(); + // -------------------------------------------------------------------------------------------- + CModel & operator = (const CModel & m) noexcept; + CModel & operator = (CModel && m) noexcept; + // -------------------------------------------------------------------------------------------- + CModel & operator = (SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const CModel & m) const noexcept; + bool operator != (const CModel & m) const noexcept; + bool operator < (const CModel & m) const noexcept; + bool operator > (const CModel & m) const noexcept; + bool operator <= (const CModel & m) const noexcept; + bool operator >= (const CModel & m) const noexcept; + // -------------------------------------------------------------------------------------------- + operator SQInt32 () const noexcept { return m_ID; } + operator bool () const noexcept { return IsModelValid(m_ID); } + // -------------------------------------------------------------------------------------------- + bool operator ! () const noexcept { return !IsModelValid(m_ID); } + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CModel & m) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger GetID() const noexcept; + void SetID(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CModel & SetnGet(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetGlobalTag() const noexcept; + void SetGlobalTag(const SQChar * tag) const noexcept; + // -------------------------------------------------------------------------------------------- + SqObj & GetGlobalData() const noexcept; + void SetGlobalData(SqObj & data) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetLocalTag() const noexcept; + void SetLocalTag(const SQChar * tag) noexcept; + // -------------------------------------------------------------------------------------------- + SqObj & GetLocalData() noexcept; + void SetLocalData(SqObj & data) noexcept; + // -------------------------------------------------------------------------------------------- + bool IsValid() const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetName() const noexcept; + // -------------------------------------------------------------------------------------------- + bool IsWeapon() const noexcept; + bool IsActuallyWeapon() const noexcept; + // -------------------------------------------------------------------------------------------- + Reference< CObject > Object(SQInt32 world, const Vector3 & pos, SQInt32 alpha, SQInt32 header, \ + const SqObj & payload) const noexcept; + Reference< CObject > Object(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQInt32 alpha, \ + SQInt32 header, const SqObj & payload) const noexcept; + // -------------------------------------------------------------------------------------------- + Reference< CPickup > Pickup(SQInt32 world, SQInt32 quantity, const Vector3 & pos, SQInt32 alpha, \ + bool automatic, SQInt32 header, const SqObj & payload) const noexcept; + Reference< CPickup > Pickup(SQInt32 world, SQInt32 quantity, SQFloat x, SQFloat y, SQFloat z, \ + SQInt32 alpha, bool automatic, SQInt32 header, const SqObj & payload) const noexcept; +private: + // -------------------------------------------------------------------------------------------- + SQInt32 m_ID; + // -------------------------------------------------------------------------------------------- + String m_Name; + // -------------------------------------------------------------------------------------------- + SqTag m_Tag; + SqObj m_Data; +}; + +} // Namespace:: SqMod + +#endif // _MISC_MODEL_HPP_ diff --git a/source/Misc/PlayerImmunity.cpp b/source/Misc/PlayerImmunity.cpp new file mode 100644 index 00000000..c2d6b422 --- /dev/null +++ b/source/Misc/PlayerImmunity.cpp @@ -0,0 +1,12 @@ +#include "Misc/PlayerImmunity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CPlayerImmunity(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Misc/PlayerImmunity.hpp b/source/Misc/PlayerImmunity.hpp new file mode 100644 index 00000000..6662eb7b --- /dev/null +++ b/source/Misc/PlayerImmunity.hpp @@ -0,0 +1,68 @@ +#ifndef _MISC_PLAYER_IMMUNITY_HPP_ +#define _MISC_PLAYER_IMMUNITY_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +struct CPlayerImmunity +{ + // -------------------------------------------------------------------------------------------- + CPlayerImmunity() noexcept; + CPlayerImmunity(SQInt32 flags) noexcept; + // -------------------------------------------------------------------------------------------- + CPlayerImmunity(const CPlayerImmunity & x) noexcept; + CPlayerImmunity(CPlayerImmunity && x) noexcept; + // -------------------------------------------------------------------------------------------- + ~CPlayerImmunity(); + // -------------------------------------------------------------------------------------------- + CPlayerImmunity & operator = (const CPlayerImmunity & x) noexcept; + CPlayerImmunity & operator = (CPlayerImmunity && x) noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const CPlayerImmunity & x) const noexcept; + bool operator != (const CPlayerImmunity & x) const noexcept; + bool operator < (const CPlayerImmunity & x) const noexcept; + bool operator > (const CPlayerImmunity & x) const noexcept; + bool operator <= (const CPlayerImmunity & x) const noexcept; + bool operator >= (const CPlayerImmunity & x) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CPlayerImmunity & x) const noexcept; + // -------------------------------------------------------------------------------------------- + operator SQInt32 () const noexcept; + operator bool () const noexcept; + // -------------------------------------------------------------------------------------------- + SQInt32 GetFlags() const noexcept; + void SetFlags(SQInt32 flags) noexcept; + // -------------------------------------------------------------------------------------------- + CPlayerImmunity & SetnGet(SQInt32 flags) noexcept; + // -------------------------------------------------------------------------------------------- + void Apply(const CPlayer & player) const noexcept; + // -------------------------------------------------------------------------------------------- + bool GetBullet() const noexcept; + void SetBullet(bool toggle) noexcept; + // -------------------------------------------------------------------------------------------- + bool GetFire() const noexcept; + void SetFire(bool toggle) noexcept; + // -------------------------------------------------------------------------------------------- + bool GetExplosion() const noexcept; + void SetExplosion(bool toggle) noexcept; + // -------------------------------------------------------------------------------------------- + bool GetCollision() const noexcept; + void SetCollision(bool toggle) noexcept; + // -------------------------------------------------------------------------------------------- + bool GetMelee() const noexcept; + void SetMelee(bool toggle) noexcept; + // -------------------------------------------------------------------------------------------- + void EnableAll() noexcept; + void DisableAll() noexcept; +protected: + // -------------------------------------------------------------------------------------------- + SQInt32 m_Flags; +}; + +} // Namespace:: SqMod + +#endif // _MISC_PLAYER_IMMUNITY_HPP_ \ No newline at end of file diff --git a/source/Misc/Radio.cpp b/source/Misc/Radio.cpp new file mode 100644 index 00000000..ef031d39 --- /dev/null +++ b/source/Misc/Radio.cpp @@ -0,0 +1,12 @@ +#include "Misc/Radio.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CRadio(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Misc/Radio.hpp b/source/Misc/Radio.hpp new file mode 100644 index 00000000..690bdcd5 --- /dev/null +++ b/source/Misc/Radio.hpp @@ -0,0 +1,56 @@ +#ifndef _MISC_RADIO_HPP_ +#define _MISC_RADIO_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +class CRadio +{ +public: + // -------------------------------------------------------------------------------------------- + CRadio() noexcept; + CRadio(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CRadio(const CRadio & x) noexcept; + CRadio(CRadio && x) noexcept; + // -------------------------------------------------------------------------------------------- + ~CRadio(); + // -------------------------------------------------------------------------------------------- + CRadio & operator= (const CRadio & x) noexcept; + CRadio & operator= (CRadio && x) noexcept; + // -------------------------------------------------------------------------------------------- + CRadio operator+ (const CRadio & x) const noexcept; + CRadio operator- (const CRadio & x) const noexcept; + CRadio operator* (const CRadio & x) const noexcept; + CRadio operator/ (const CRadio & x) const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const CRadio & x) const noexcept; + bool operator != (const CRadio & x) const noexcept; + bool operator < (const CRadio & x) const noexcept; + bool operator > (const CRadio & x) const noexcept; + bool operator <= (const CRadio & x) const noexcept; + bool operator >= (const CRadio & x) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CRadio & x) const noexcept; + // -------------------------------------------------------------------------------------------- + operator SQInt32 () const noexcept; + operator bool () const noexcept; + // -------------------------------------------------------------------------------------------- + SQInt32 GetID() const noexcept; + void SetID(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CRadio & SetnGet(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + void Apply(const CVehicle & vehicle) const noexcept; +protected: + // -------------------------------------------------------------------------------------------- + SQInt32 m_ID; +}; + +} // Namespace:: SqMod + +#endif // _MISC_RADIO_HPP_ \ No newline at end of file diff --git a/source/Misc/Shared.cpp b/source/Misc/Shared.cpp new file mode 100644 index 00000000..37e4cb53 --- /dev/null +++ b/source/Misc/Shared.cpp @@ -0,0 +1,2482 @@ +#include "Misc/Shared.hpp" +#include "Register.hpp" + +// ------------------------------------------------------------------------------------------------ +#include +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetKeyCodeName(SQInt32 keycode) +{ + switch (keycode) + { + case SQMOD_KEYCODE_ABNT_C1: return _SC("Abnt C1"); + case SQMOD_KEYCODE_ABNT_C2: return _SC("Abnt C2"); + case SQMOD_KEYCODE_ADD: return _SC("Numpad +"); + case SQMOD_KEYCODE_ATTN: return _SC("Attn"); + case SQMOD_KEYCODE_BACK: return _SC("Backspace"); + case SQMOD_KEYCODE_CANCEL: return _SC("Break"); + case SQMOD_KEYCODE_CLEAR: return _SC("Clear"); + case SQMOD_KEYCODE_CRSEL: return _SC("Cr Sel"); + case SQMOD_KEYCODE_DECIMAL: return _SC("Numpad ."); + case SQMOD_KEYCODE_DIVIDE: return _SC("Numpad /"); + case SQMOD_KEYCODE_EREOF: return _SC("Er Eof"); + case SQMOD_KEYCODE_ESCAPE: return _SC("Esc"); + case SQMOD_KEYCODE_EXECUTE: return _SC("Execute"); + case SQMOD_KEYCODE_EXSEL: return _SC("Ex Sel"); + case SQMOD_KEYCODE_ICO_CLEAR: return _SC("IcoClr"); + case SQMOD_KEYCODE_ICO_HELP: return _SC("IcoHlp"); + case SQMOD_KEYCODE_KEY_0: return _SC("0"); + case SQMOD_KEYCODE_KEY_1: return _SC("1"); + case SQMOD_KEYCODE_KEY_2: return _SC("2"); + case SQMOD_KEYCODE_KEY_3: return _SC("3"); + case SQMOD_KEYCODE_KEY_4: return _SC("4"); + case SQMOD_KEYCODE_KEY_5: return _SC("5"); + case SQMOD_KEYCODE_KEY_6: return _SC("6"); + case SQMOD_KEYCODE_KEY_7: return _SC("7"); + case SQMOD_KEYCODE_KEY_8: return _SC("8"); + case SQMOD_KEYCODE_KEY_9: return _SC("9"); + case SQMOD_KEYCODE_KEY_A: return _SC("A"); + case SQMOD_KEYCODE_KEY_B: return _SC("B"); + case SQMOD_KEYCODE_KEY_C: return _SC("C"); + case SQMOD_KEYCODE_KEY_D: return _SC("D"); + case SQMOD_KEYCODE_KEY_E: return _SC("E"); + case SQMOD_KEYCODE_KEY_F: return _SC("F"); + case SQMOD_KEYCODE_KEY_G: return _SC("G"); + case SQMOD_KEYCODE_KEY_H: return _SC("H"); + case SQMOD_KEYCODE_KEY_I: return _SC("I"); + case SQMOD_KEYCODE_KEY_J: return _SC("J"); + case SQMOD_KEYCODE_KEY_K: return _SC("K"); + case SQMOD_KEYCODE_KEY_L: return _SC("L"); + case SQMOD_KEYCODE_KEY_M: return _SC("M"); + case SQMOD_KEYCODE_KEY_N: return _SC("N"); + case SQMOD_KEYCODE_KEY_O: return _SC("O"); + case SQMOD_KEYCODE_KEY_P: return _SC("P"); + case SQMOD_KEYCODE_KEY_Q: return _SC("Q"); + case SQMOD_KEYCODE_KEY_R: return _SC("R"); + case SQMOD_KEYCODE_KEY_S: return _SC("S"); + case SQMOD_KEYCODE_KEY_T: return _SC("T"); + case SQMOD_KEYCODE_KEY_U: return _SC("U"); + case SQMOD_KEYCODE_KEY_V: return _SC("V"); + case SQMOD_KEYCODE_KEY_W: return _SC("W"); + case SQMOD_KEYCODE_KEY_X: return _SC("X"); + case SQMOD_KEYCODE_KEY_Y: return _SC("Y"); + case SQMOD_KEYCODE_KEY_Z: return _SC("Z"); + case SQMOD_KEYCODE_MULTIPLY: return _SC("Numpad *"); + case SQMOD_KEYCODE_NONAME: return _SC("NoName"); + case SQMOD_KEYCODE_NUMPAD0: return _SC("Numpad 0"); + case SQMOD_KEYCODE_NUMPAD1: return _SC("Numpad 1"); + case SQMOD_KEYCODE_NUMPAD2: return _SC("Numpad 2"); + case SQMOD_KEYCODE_NUMPAD3: return _SC("Numpad 3"); + case SQMOD_KEYCODE_NUMPAD4: return _SC("Numpad 4"); + case SQMOD_KEYCODE_NUMPAD5: return _SC("Numpad 5"); + case SQMOD_KEYCODE_NUMPAD6: return _SC("Numpad 6"); + case SQMOD_KEYCODE_NUMPAD7: return _SC("Numpad 7"); + case SQMOD_KEYCODE_NUMPAD8: return _SC("Numpad 8"); + case SQMOD_KEYCODE_NUMPAD9: return _SC("Numpad 9"); + case SQMOD_KEYCODE_OEM_1: return _SC("OEM_1 (: ;)"); + case SQMOD_KEYCODE_OEM_102: return _SC("OEM_102 (> <)"); + case SQMOD_KEYCODE_OEM_2: return _SC("OEM_2 (? /)"); + case SQMOD_KEYCODE_OEM_3: return _SC("OEM_3 (~ `)"); + case SQMOD_KEYCODE_OEM_4: return _SC("OEM_4 ({ [)"); + case SQMOD_KEYCODE_OEM_5: return _SC("OEM_5 (| \\)"); + case SQMOD_KEYCODE_OEM_6: return _SC("OEM_6 (} ])"); + case SQMOD_KEYCODE_OEM_7: return _SC("OEM_7 (\" ')"); + case SQMOD_KEYCODE_OEM_8: return _SC("OEM_8 (ยง !)"); + case SQMOD_KEYCODE_OEM_ATTN: return _SC("Oem Attn"); + case SQMOD_KEYCODE_OEM_AUTO: return _SC("Auto"); + case SQMOD_KEYCODE_OEM_AX: return _SC("Ax"); + case SQMOD_KEYCODE_OEM_BACKTAB: return _SC("Back Tab"); + case SQMOD_KEYCODE_OEM_CLEAR: return _SC("OemClr"); + case SQMOD_KEYCODE_OEM_COMMA: return _SC("OEM_COMMA (< ,)"); + case SQMOD_KEYCODE_OEM_COPY: return _SC("Copy"); + case SQMOD_KEYCODE_OEM_CUSEL: return _SC("Cu Sel"); + case SQMOD_KEYCODE_OEM_ENLW: return _SC("Enlw"); + case SQMOD_KEYCODE_OEM_FINISH: return _SC("Finish"); + case SQMOD_KEYCODE_OEM_FJ_LOYA: return _SC("Loya"); + case SQMOD_KEYCODE_OEM_FJ_MASSHOU: return _SC("Mashu"); + case SQMOD_KEYCODE_OEM_FJ_ROYA: return _SC("Roya"); + case SQMOD_KEYCODE_OEM_FJ_TOUROKU: return _SC("Touroku"); + case SQMOD_KEYCODE_OEM_JUMP: return _SC("Jump"); + case SQMOD_KEYCODE_OEM_MINUS: return _SC("OEM_MINUS (_ -)"); + case SQMOD_KEYCODE_OEM_PA1: return _SC("OemPa1"); + case SQMOD_KEYCODE_OEM_PA2: return _SC("OemPa2"); + case SQMOD_KEYCODE_OEM_PA3: return _SC("OemPa3"); + case SQMOD_KEYCODE_OEM_PERIOD: return _SC("OEM_PERIOD (> .)"); + case SQMOD_KEYCODE_OEM_PLUS: return _SC("OEM_PLUS (+ =)"); + case SQMOD_KEYCODE_OEM_RESET: return _SC("Reset"); + case SQMOD_KEYCODE_OEM_WSCTRL: return _SC("WsCtrl"); + case SQMOD_KEYCODE_PA1: return _SC("Pa1"); + case SQMOD_KEYCODE_PACKET: return _SC("Packet"); + case SQMOD_KEYCODE_PLAY: return _SC("Play"); + case SQMOD_KEYCODE_PROCESSKEY: return _SC("Process"); + case SQMOD_KEYCODE_RETURN: return _SC("Enter"); + case SQMOD_KEYCODE_SELECT: return _SC("Select"); + case SQMOD_KEYCODE_SEPARATOR: return _SC("Separator"); + case SQMOD_KEYCODE_SPACE: return _SC("Space"); + case SQMOD_KEYCODE_SUBTRACT: return _SC("Num -"); + case SQMOD_KEYCODE_TAB: return _SC("Tab"); + case SQMOD_KEYCODE_ZOOM: return _SC("Zoom"); + case SQMOD_KEYCODE_ACCEPT: return _SC("Accept"); + case SQMOD_KEYCODE_APPS: return _SC("Context Menu"); + case SQMOD_KEYCODE_BROWSER_BACK: return _SC("Browser Back"); + case SQMOD_KEYCODE_BROWSER_FAVORITES: return _SC("Browser Favorites"); + case SQMOD_KEYCODE_BROWSER_FORWARD: return _SC("Browser Forward"); + case SQMOD_KEYCODE_BROWSER_HOME: return _SC("Browser Home"); + case SQMOD_KEYCODE_BROWSER_REFRESH: return _SC("Browser Refresh"); + case SQMOD_KEYCODE_BROWSER_SEARCH: return _SC("Browser Search"); + case SQMOD_KEYCODE_BROWSER_STOP: return _SC("Browser Stop"); + case SQMOD_KEYCODE_CAPITAL: return _SC("Caps Lock"); + case SQMOD_KEYCODE_CONVERT: return _SC("Convert"); + case SQMOD_KEYCODE_DELETE: return _SC("Delete"); + case SQMOD_KEYCODE_DOWN: return _SC("Arrow Down"); + case SQMOD_KEYCODE_END: return _SC("End"); + case SQMOD_KEYCODE_F1: return _SC("F1"); + case SQMOD_KEYCODE_F10: return _SC("F10"); + case SQMOD_KEYCODE_F11: return _SC("F11"); + case SQMOD_KEYCODE_F12: return _SC("F12"); + case SQMOD_KEYCODE_F13: return _SC("F13"); + case SQMOD_KEYCODE_F14: return _SC("F14"); + case SQMOD_KEYCODE_F15: return _SC("F15"); + case SQMOD_KEYCODE_F16: return _SC("F16"); + case SQMOD_KEYCODE_F17: return _SC("F17"); + case SQMOD_KEYCODE_F18: return _SC("F18"); + case SQMOD_KEYCODE_F19: return _SC("F19"); + case SQMOD_KEYCODE_F2: return _SC("F2"); + case SQMOD_KEYCODE_F20: return _SC("F20"); + case SQMOD_KEYCODE_F21: return _SC("F21"); + case SQMOD_KEYCODE_F22: return _SC("F22"); + case SQMOD_KEYCODE_F23: return _SC("F23"); + case SQMOD_KEYCODE_F24: return _SC("F24"); + case SQMOD_KEYCODE_F3: return _SC("F3"); + case SQMOD_KEYCODE_F4: return _SC("F4"); + case SQMOD_KEYCODE_F5: return _SC("F5"); + case SQMOD_KEYCODE_F6: return _SC("F6"); + case SQMOD_KEYCODE_F7: return _SC("F7"); + case SQMOD_KEYCODE_F8: return _SC("F8"); + case SQMOD_KEYCODE_F9: return _SC("F9"); + case SQMOD_KEYCODE_FINAL: return _SC("Final"); + case SQMOD_KEYCODE_HELP: return _SC("Help"); + case SQMOD_KEYCODE_HOME: return _SC("Home"); + case SQMOD_KEYCODE_ICO_00: return _SC("Ico00 *"); + case SQMOD_KEYCODE_INSERT: return _SC("Insert"); + case SQMOD_KEYCODE_JUNJA: return _SC("Junja"); + case SQMOD_KEYCODE_KANA: return _SC("Kana"); + case SQMOD_KEYCODE_KANJI: return _SC("Kanji"); + case SQMOD_KEYCODE_LAUNCH_APP1: return _SC("App1"); + case SQMOD_KEYCODE_LAUNCH_APP2: return _SC("App2"); + case SQMOD_KEYCODE_LAUNCH_MAIL: return _SC("Mail"); + case SQMOD_KEYCODE_LAUNCH_MEDIA_SELECT: return _SC("Media"); + case SQMOD_KEYCODE_LBUTTON: return _SC("Left Button **"); + case SQMOD_KEYCODE_LCONTROL: return _SC("Left Ctrl"); + case SQMOD_KEYCODE_LEFT: return _SC("Arrow Left"); + case SQMOD_KEYCODE_LMENU: return _SC("Left Alt"); + case SQMOD_KEYCODE_LSHIFT: return _SC("Left Shift"); + case SQMOD_KEYCODE_LWIN: return _SC("Left Win"); + case SQMOD_KEYCODE_MBUTTON: return _SC("Middle Button **"); + case SQMOD_KEYCODE_MEDIA_NEXT_TRACK: return _SC("Next Track"); + case SQMOD_KEYCODE_MEDIA_PLAY_PAUSE: return _SC("Play / Pause"); + case SQMOD_KEYCODE_MEDIA_PREV_TRACK: return _SC("Previous Track"); + case SQMOD_KEYCODE_MEDIA_STOP: return _SC("Stop"); + case SQMOD_KEYCODE_MODECHANGE: return _SC("Mode Change"); + case SQMOD_KEYCODE_NEXT: return _SC("Page Down"); + case SQMOD_KEYCODE_NONCONVERT: return _SC("Non Convert"); + case SQMOD_KEYCODE_NUMLOCK: return _SC("Num Lock"); + case SQMOD_KEYCODE_OEM_FJ_JISHO: return _SC("Jisho"); + case SQMOD_KEYCODE_PAUSE: return _SC("Pause"); + case SQMOD_KEYCODE_PRINT: return _SC("Print"); + case SQMOD_KEYCODE_PRIOR: return _SC("Page Up"); + case SQMOD_KEYCODE_RBUTTON: return _SC("Right Button **"); + case SQMOD_KEYCODE_RCONTROL: return _SC("Right Ctrl"); + case SQMOD_KEYCODE_RIGHT: return _SC("Arrow Right"); + case SQMOD_KEYCODE_RMENU: return _SC("Right Alt"); + case SQMOD_KEYCODE_RSHIFT: return _SC("Right Shift"); + case SQMOD_KEYCODE_RWIN: return _SC("Right Win"); + case SQMOD_KEYCODE_SCROLL: return _SC("Scrol Lock"); + case SQMOD_KEYCODE_SLEEP: return _SC("Sleep"); + case SQMOD_KEYCODE_SNAPSHOT: return _SC("Print Screen"); + case SQMOD_KEYCODE_UP: return _SC("Arrow Up"); + case SQMOD_KEYCODE_VOLUME_DOWN: return _SC("Volume Down"); + case SQMOD_KEYCODE_VOLUME_MUTE: return _SC("Volume Mute"); + case SQMOD_KEYCODE_VOLUME_UP: return _SC("Volume Up"); + case SQMOD_KEYCODE_XBUTTON1: return _SC("X Button 1 **"); + case SQMOD_KEYCODE_XBUTTON2: return _SC("X Button 2 **"); + case SQMOD_KEYCODE_NONE: return _SC("no mapping"); + default: return _SC(""); + } +} + + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetModelName(SQInt32 id) +{ + switch (id) + { + case 258: return _SC("Mobile CellPhone"); + case 259: return _SC("Brass Knuckles"); + case 260: return _SC("Screwdriver"); + case 261: return _SC("Golf Club"); + case 262: return _SC("Nigtht Stick"); + case 263: return _SC("Knife"); + case 264: return _SC("Baseball"); + case 265: return _SC("Hammer"); + case 266: return _SC("Meath Cleaver"); + case 267: return _SC("Machete"); + case 268: return _SC("Katana"); + case 269: return _SC("Chainsaw"); + case 270: return _SC("Grenades"); + case 271: return _SC("Tear Gas"); + case 272: return _SC("Molotovs"); + case 273: return _SC("Rocket"); + case 274: return _SC("Colt 45"); + case 275: return _SC("Python"); + case 276: return _SC("Ruger"); + case 277: return _SC("Chrome Shotgun"); + case 278: return _SC("Spaz Shotgun"); + case 279: return _SC("Stubby Shotgun"); + case 280: return _SC("M4"); + case 281: return _SC("Tec9"); + case 282: return _SC("Uzi"); + case 283: return _SC("Silenced Ingram"); + case 284: return _SC("MP5"); + case 285: return _SC("Sniper Rifle"); + case 286: return _SC("Laser Sniper Rifle"); + case 287: return _SC("Rocket Launcher"); + case 288: return _SC("Flamethrower"); + case 289: return _SC("M60"); + case 290: return _SC("Minigun"); + case 291: return _SC("Detonator + Grenades"); + case 292: return _SC("Camera"); + case 293: return _SC("Fists"); + case 294: return _SC("Helicannon"); + case 300: return _SC("bar_gatebar01"); + case 301: return _SC("bar_gatebox01"); + case 302: return _SC("barrier_turn"); + case 303: return _SC("Electricgate"); + case 304: return _SC("fence_small"); + case 305: return _SC("subwaygate"); + case 306: return _SC("tunnel_entrance"); + case 307: return _SC("sub_roadbarrier"); + case 308: return _SC("tall_fence"); + case 309: return _SC("Columbian_gate"); + case 310: return _SC("phils_compnd_gate"); + case 311: return _SC("towerdoor1"); + case 312: return _SC("sub_roadright"); + case 313: return _SC("sub_roadleft"); + case 314: return _SC("airport_gate"); + case 315: return _SC("helix_barrier"); + case 316: return _SC("bar_barrier12"); + case 317: return _SC("bar_barrier16"); + case 318: return _SC("bar_barriergate1"); + case 319: return _SC("bar_barrier10b"); + case 320: return _SC("lhouse_barrier1"); + case 321: return _SC("lhouse_barrier2"); + case 322: return _SC("lhouse_barrier3"); + case 323: return _SC("Gdyn_barrier17"); + case 324: return _SC("bar_barrier10"); + case 330: return _SC("tiny_rock"); + case 331: return _SC("washing_machane"); + case 332: return _SC("junk_tyre"); + case 333: return _SC("cooker1"); + case 334: return _SC("vending_machane"); + case 335: return _SC("briefcase"); + case 336: return _SC("fire_hydrant"); + case 337: return _SC("Money"); + case 338: return _SC("mine"); + case 339: return _SC("bollard"); + case 340: return _SC("bollard_light"); + case 341: return _SC("phonebooth1"); + case 342: return _SC("barrel2"); + case 343: return _SC("barrel1"); + case 344: return _SC("palette"); + case 345: return _SC("cardboardbox2"); + case 346: return _SC("cardboardbox4"); + case 347: return _SC("barrel3"); + case 348: return _SC("lampost_coast"); + case 349: return _SC("wooden_box"); + case 350: return _SC("barrel4"); + case 351: return _SC("lamppost3"); + case 352: return _SC("bin1"); + case 353: return _SC("dump1"); + case 354: return _SC("roadworkbarrier1"); + case 355: return _SC("bussign1"); + case 356: return _SC("cardboard_box"); + case 357: return _SC("Streetlamp2"); + case 358: return _SC("Streetlamp1"); + case 359: return _SC("noparkingsign1"); + case 360: return _SC("phone_sign"); + case 361: return _SC("waste_bin"); + case 362: return _SC("rcyclbank01"); + case 363: return _SC("strtbarrier01"); + case 364: return _SC("traffic_cone"); + case 365: return _SC("info"); + case 366: return _SC("health"); + case 367: return _SC("adrenaline"); + case 368: return _SC("bodyarmour"); + case 369: return _SC("bouy"); + case 370: return _SC("petrolpump"); + case 371: return _SC("newramp"); + case 372: return _SC("line"); + case 373: return _SC("rockpatch1"); + case 374: return _SC("rockpatch03"); + case 375: return _SC("bribe"); + case 376: return _SC("bonus"); + case 377: return _SC("faketarget"); + case 378: return _SC("smashbarpost"); + case 379: return _SC("smashbar"); + case 380: return _SC("barrelexpos"); + case 381: return _SC("glassfx_composh"); + case 382: return _SC("camerapickup"); + case 383: return _SC("killfrenzy"); + case 384: return _SC("telgrphpole02"); + case 385: return _SC("lounger"); + case 386: return _SC("Stonebench1"); + case 387: return _SC("miami_phone"); + case 388: return _SC("miami_hydrant"); + case 389: return _SC("bustop"); + case 390: return _SC("Mpostbox1"); + case 391: return _SC("BillBd1"); + case 392: return _SC("BillBd3"); + case 393: return _SC("LODlBd2"); + case 394: return _SC("MTraffic2"); + case 395: return _SC("Miamibin"); + case 396: return _SC("MTraffic4"); + case 397: return _SC("MTraffic3"); + case 398: return _SC("BlackBag1"); + case 399: return _SC("BlackBag2"); + case 400: return _SC("LODlBd3"); + case 401: return _SC("BillBd2"); + case 402: return _SC("LODlBd1"); + case 403: return _SC("parkingmeter"); + case 404: return _SC("parkingmeterg"); + case 405: return _SC("gunbox"); + case 406: return _SC("property_locked"); + case 407: return _SC("property_foresale"); + case 408: return _SC("bigdollar"); + case 409: return _SC("clothesp"); + case 410: return _SC("package1"); + case 411: return _SC("pickup_save"); + case 412: return _SC("postbox1"); + case 413: return _SC("newsstand1"); + case 414: return _SC("parkbench1"); + case 415: return _SC("papermachn01"); + case 416: return _SC("parktable1"); + case 417: return _SC("lamppost2"); + case 418: return _SC("garden_bench"); + case 419: return _SC("Barrier"); + case 420: return _SC("newstandnew1"); + case 421: return _SC("newstandnew4"); + case 422: return _SC("newstandnew3"); + case 423: return _SC("newstandnew5"); + case 424: return _SC("newstandnew2"); + case 425: return _SC("lamppost1"); + case 426: return _SC("doublestreetlght1"); + case 427: return _SC("trafficlight1"); + case 428: return _SC("MTraffic1"); + case 429: return _SC("lamp_post"); + case 430: return _SC("sea_light"); + case 431: return _SC("craig_package"); + case 432: return _SC("music_headsets"); + case 440: return _SC("veg_tree3"); + case 441: return _SC("veg_treea1"); + case 442: return _SC("veg_treeb1"); + case 443: return _SC("veg_treea3"); + case 444: return _SC("veg_palwee03"); + case 445: return _SC("veg_palm04"); + case 446: return _SC("veg_palm02"); + case 447: return _SC("veg_palm03"); + case 448: return _SC("veg_palwee01"); + case 449: return _SC("veg_palwee02"); + case 450: return _SC("veg_palmkb1"); + case 451: return _SC("veg_palmkb2"); + case 452: return _SC("veg_palmkb3"); + case 453: return _SC("veg_palmkb4"); + case 454: return _SC("veg_palmkb5"); + case 455: return _SC("veg_palmkb8"); + case 456: return _SC("veg_palmkb9"); + case 457: return _SC("veg_palmkb7"); + case 458: return _SC("veg_palmkb10"); + case 459: return _SC("veg_palmkbb11"); + case 460: return _SC("veg_fern_balcny_kb1"); + case 461: return _SC("veg_fern_balcny_kb2"); + case 462: return _SC("kb_pot_1"); + case 463: return _SC("kb_planterbush2"); + case 464: return _SC("kb_planterbox"); + case 465: return _SC("kb_planter+bush"); + case 466: return _SC("veg_ivy_balcny_kb3"); + case 467: return _SC("new_bushtest"); + case 468: return _SC("kb_planter+bush2"); + case 469: return _SC("veg_palmkb13"); + case 470: return _SC("kb_canopy_test"); + case 471: return _SC("kb_chr_tbl_test"); + case 472: return _SC("pot_02"); + case 473: return _SC("pot_01"); + case 474: return _SC("veg_palmbig14"); + case 475: return _SC("veg_palmkb14"); + case 476: return _SC("pot_03"); + case 477: return _SC("new_bushsm"); + case 478: return _SC("veg_palm01"); + case 500: return _SC("lf_mediastage"); + case 501: return _SC("trashcan"); + case 502: return _SC("drug_white"); + case 503: return _SC("drug_orange"); + case 504: return _SC("drug_yellow"); + case 505: return _SC("drug_green"); + case 506: return _SC("drug_blue"); + case 507: return _SC("drug_red"); + case 508: return _SC("keycard"); + case 509: return _SC("lf_banner"); + case 510: return _SC("pizzabox"); + case 511: return _SC("tar_gun2"); + case 512: return _SC("tar_gun1"); + case 513: return _SC("tar_civ2"); + case 514: return _SC("tar_civ1"); + case 515: return _SC("tar_frame"); + case 516: return _SC("tar_top"); + case 517: return _SC("tar_upright"); + case 518: return _SC("tar_upleft"); + case 519: return _SC("tar_downleft"); + case 520: return _SC("tar_downright"); + case 521: return _SC("plc_stinger"); + case 522: return _SC("chairsntable"); + case 523: return _SC("satdishbig"); + case 524: return _SC("satdishsml"); + case 525: return _SC("cntrlrsac1"); + case 526: return _SC("beachball"); + case 527: return _SC("fish1single"); + case 528: return _SC("fish2single"); + case 529: return _SC("fish3s"); + case 530: return _SC("jellyfish"); + case 531: return _SC("jellyfish01"); + case 532: return _SC("fish3single"); + case 533: return _SC("fish1s"); + case 534: return _SC("fish2s"); + case 535: return _SC("dolphin"); + case 536: return _SC("shark"); + case 537: return _SC("turtle"); + case 538: return _SC("sandcastle1"); + case 539: return _SC("sandcastle2"); + case 540: return _SC("submarine"); + case 541: return _SC("nt_firehose_01"); + case 542: return _SC("nt_alarm1_01"); + case 543: return _SC("nt_alarm2_01"); + case 544: return _SC("nt_securecam1_01"); + case 545: return _SC("nt_aircon1_01"); + case 546: return _SC("nt_aircon1_02"); + case 547: return _SC("nt_vent1_01"); + case 548: return _SC("nt_vent2_01"); + case 549: return _SC("nt_vent3_01"); + case 550: return _SC("nt_securecam2_01"); + case 551: return _SC("nt_aircon3_01"); + case 552: return _SC("nt_cablebox1_01"); + case 553: return _SC("nt_cablebox2_01"); + case 554: return _SC("nt_cablebox3_01"); + case 555: return _SC("nt_alarm3_01"); + case 556: return _SC("nt_cablebox4_01"); + case 557: return _SC("nt_cablebox5_01"); + case 558: return _SC("nt_cablebox6_01"); + case 559: return _SC("waterjump2"); + case 560: return _SC("waterjump1"); + case 561: return _SC("landjump"); + case 562: return _SC("landjump2"); + case 563: return _SC("nt_aircon1dbl"); + case 564: return _SC("rcbomb"); + case 565: return _SC("od_pat_hutb"); + case 566: return _SC("od_pat_hut"); + case 567: return _SC("od_vbnet"); + case 568: return _SC("beachtowel04"); + case 569: return _SC("beachtowel03"); + case 570: return _SC("beachtowel02"); + case 571: return _SC("beachtowel01"); + case 572: return _SC("lotion"); + case 573: return _SC("lounge_wood_up"); + case 574: return _SC("lounge_towel_up"); + case 575: return _SC("lounge_wood_dn"); + case 576: return _SC("groyne01"); + case 577: return _SC("wglasssmash"); + case 578: return _SC("petrolcan"); + case 579: return _SC("copwindows"); + case 580: return _SC("fence_haiti"); + case 581: return _SC("fence_haitis"); + case 582: return _SC("dynamite"); + case 583: return _SC("waterjumpx2"); + case 584: return _SC("Esculator_step"); + case 587: return _SC("htl_fan_static_dy"); + case 588: return _SC("ramp"); + case 589: return _SC("htl_fan_rotate_dy"); + case 590: return _SC("nt_roadblockCI"); + case 591: return _SC("swivel_chair_B"); + case 592: return _SC("propwinebotl2"); + case 593: return _SC("propashtray1"); + case 594: return _SC("propbeerglass1"); + case 595: return _SC("propwineglass1"); + case 596: return _SC("propvodkabotl1"); + case 597: return _SC("propwinebotl1"); + case 598: return _SC("propcollecttable"); + case 599: return _SC("swivelchair_A"); + case 600: return _SC("Gasgrenade"); + case 601: return _SC("roadsign"); + case 602: return _SC("lodxrefhse1"); + case 603: return _SC("wshxrefhse1"); + case 604: return _SC("wash_gaspump"); + case 605: return _SC("lodxrefhirise1"); + case 606: return _SC("wshxrefhirise1"); + case 607: return _SC("wshxrefhse2"); + case 608: return _SC("lodxrefhse2"); + case 609: return _SC("xod_beacon_dy"); + case 611: return _SC("xod_starlite_dy"); + case 613: return _SC("xod_leslie_nt"); + case 614: return _SC("xod_leslie_dy"); + case 615: return _SC("xod_majestic_dy"); + case 617: return _SC("xod_macalpin_dy"); + case 620: return _SC("xod_tides_dy"); + case 633: return _SC("jw_coffin"); + case 634: return _SC("chairsntableml"); + case 635: return _SC("LODjumbo_01"); + case 636: return _SC("ap_learjet1_01"); + case 637: return _SC("ap_radar1_01"); + case 638: return _SC("ap_jumbo_01"); + default: return _SC(""); + } +} + +bool IsModelWeapon(SQInt32 id) +{ + switch (id) + { + case 258: + case 259: + case 260: + case 261: + case 262: + case 263: + case 264: + case 265: + case 266: + case 267: + case 268: + case 269: + case 270: + case 271: + case 272: + case 273: + case 274: + case 275: + case 276: + case 277: + case 278: + case 279: + case 280: + case 281: + case 282: + case 283: + case 284: + case 285: + case 286: + case 287: + case 288: + case 289: + case 290: + case 291: + case 292: + case 293: + case 294: return SQTrue; + default: return SQFalse; + } +} + +bool IsModelActuallyWeapon(SQInt32 id) +{ + switch (id) + { + case 259: + case 260: + case 261: + case 262: + case 263: + case 264: + case 265: + case 266: + case 267: + case 268: + case 269: + case 270: + case 271: + case 272: + case 274: + case 275: + case 276: + case 277: + case 278: + case 279: + case 280: + case 281: + case 282: + case 283: + case 284: + case 285: + case 286: + case 287: + case 288: + case 289: + case 290: + case 291: return SQTrue; + default: return SQFalse; + } +} + +bool IsModelValid(SQInt32 id) +{ + return (strcmp(GetModelName(id), _SC("")) != 0) ? SQTrue : SQFalse; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetSkinName(SQInt32 id) +{ + switch(id) + { + case SQMOD_SKIN_TOMMY_VERCETTI: return _SC("Tommy Vercetti"); + case SQMOD_SKIN_COP: return _SC("Cop"); + case SQMOD_SKIN_SWAT: return _SC("SWAT"); + case SQMOD_SKIN_FBI: return _SC("FBI"); + case SQMOD_SKIN_ARMY: return _SC("Army"); + case SQMOD_SKIN_PARAMEDIC: return _SC("Paramedic"); + case SQMOD_SKIN_FIREMAN: return _SC("Firefighter"); + case SQMOD_SKIN_GOLF_GUY_A: return _SC("Golf Guy #1"); + case SQMOD_SKIN_BUM_LADY_A: return _SC("Bum Lady #1"); + case SQMOD_SKIN_BUM_LADY_B: return _SC("Bum Lady #2"); + case SQMOD_SKIN_PUNK_A: return _SC("Punk #1"); + case SQMOD_SKIN_LAWYER: return _SC("Lawyer"); + case SQMOD_SKIN_SPANISH_LADY_A: return _SC("Spanish Lady #1"); + case SQMOD_SKIN_SPANISH_LADY_B: return _SC("Spanish Lady #2"); + case SQMOD_SKIN_COOL_GUY_A: return _SC("Cool Guy #1"); + case SQMOD_SKIN_ARABIC_GUY: return _SC("Arabic Guy"); + case SQMOD_SKIN_BEACH_LADY_A: return _SC("Beach Lady #1"); + case SQMOD_SKIN_BEACH_LADY_B: return _SC("Beach Lady #2"); + case SQMOD_SKIN_BEACH_GUY_A: return _SC("Beach Guy #1"); + case SQMOD_SKIN_BEACH_GUY_B: return _SC("Beach Guy #2"); + case SQMOD_SKIN_OFFICE_LADY_A: return _SC("Office Lady #1"); + case SQMOD_SKIN_WAITRESS_A: return _SC("Waitress #1"); + case SQMOD_SKIN_FOOD_LADY: return _SC("Food Lady"); + case SQMOD_SKIN_PROSTITUTE_A: return _SC("Prostitute #1"); + case SQMOD_SKIN_BUM_LADY_C: return _SC("Bum Lady #3"); + case SQMOD_SKIN_BUM_GUY_A: return _SC("Bum Guy #1"); + case SQMOD_SKIN_GARBAGEMAN_A: return _SC("Garbageman #1"); + case SQMOD_SKIN_TAXI_DRIVER_A: return _SC("Taxi Driver #1"); + case SQMOD_SKIN_HATIAN_A: return _SC("Haitian #1"); + case SQMOD_SKIN_CRIMINAL_A: return _SC("Criminal #1"); + case SQMOD_SKIN_HOOD_LADY: return _SC("Hood Lady"); + case SQMOD_SKIN_GRANNY_A: return _SC("Granny #1"); + case SQMOD_SKIN_BUSINESS_MAN_A: return _SC("Businessman #1"); + case SQMOD_SKIN_CHURCH_GUY: return _SC("Church Guy"); + case SQMOD_SKIN_CLUB_LADY: return _SC("Club Lady"); + case SQMOD_SKIN_CHURCH_LADY: return _SC("Church Lady"); + case SQMOD_SKIN_PIMP: return _SC("Pimp"); + case SQMOD_SKIN_BEACH_LADY_C: return _SC("Beach Lady #3"); + case SQMOD_SKIN_BEACH_GUY_C: return _SC("Beach Guy #3"); + case SQMOD_SKIN_BEACH_LADY_D: return _SC("Beach Lady #4"); + case SQMOD_SKIN_BEACH_GUY_D: return _SC("Beach Guy #4"); + case SQMOD_SKIN_BUSINESS_MAN_B: return _SC("Businessman #2"); + case SQMOD_SKIN_PROSTITUTE_B: return _SC("Prostitute #2"); + case SQMOD_SKIN_BUM_LADY_D: return _SC("Bum Lady #4"); + case SQMOD_SKIN_BUM_GUY_B: return _SC("Bum Guy #2"); + case SQMOD_SKIN_HATIAN_B: return _SC("Haitian #2"); + case SQMOD_SKIN_CONSTRUCTION_WORKER_A: return _SC("Construction Worker #1"); + case SQMOD_SKIN_PUNK_B: return _SC("Punk #2"); + case SQMOD_SKIN_PROSTITUTE_C: return _SC("Prostitute #3"); + case SQMOD_SKIN_GRANNY_B: return _SC("Granny #2"); + case SQMOD_SKIN_PUNK_C: return _SC("Punk #3"); + case SQMOD_SKIN_BUSINESS_MAN_C: return _SC("Businessman #3"); + case SQMOD_SKIN_SPANISH_LADY_C: return _SC("Spanish Lady #3"); + case SQMOD_SKIN_SPANISH_LADY_D: return _SC("Spanish Lady #4"); + case SQMOD_SKIN_COOL_GUY_B: return _SC("Cool Guy #2"); + case SQMOD_SKIN_BUSINESS_MAN_D: return _SC("Businessman #4"); + case SQMOD_SKIN_BEACH_LADY_E: return _SC("Beach Lady #5"); + case SQMOD_SKIN_BEACH_GUY_E: return _SC("Beach Guy #5"); + case SQMOD_SKIN_BEACH_LADY_F: return _SC("Beach Lady #6"); + case SQMOD_SKIN_BEACH_GUY_F: return _SC("Beach Guy #6"); + case SQMOD_SKIN_CONSTRUCTION_WORKER_B: return _SC("Construction Worker #2"); + case SQMOD_SKIN_GOLF_GUY_B: return _SC("Golf Guy #2"); + case SQMOD_SKIN_GOLF_LADY: return _SC("Golf Lady"); + case SQMOD_SKIN_GOLF_GUY_C: return _SC("Golf Guy #3"); + case SQMOD_SKIN_BEACH_LADY_G: return _SC("Beach Lady #7"); + case SQMOD_SKIN_BEACH_GUY_G: return _SC("Beach Guy #7"); + case SQMOD_SKIN_OFFICE_LADY_B: return _SC("Office Lady #2"); + case SQMOD_SKIN_BUSINESS_MAN_E: return _SC("Businessman #5"); + case SQMOD_SKIN_BUSINESS_MAN_F: return _SC("Businessman #6"); + case SQMOD_SKIN_PROSTITUTE_D: return _SC("Prostitute #2"); + case SQMOD_SKIN_BUM_LADY_E: return _SC("Bum Lady #4"); + case SQMOD_SKIN_BUM_GUY_C: return _SC("Bum Guy #3"); + case SQMOD_SKIN_SPANISH_GUY: return _SC("Spanish Guy"); + case SQMOD_SKIN_TAXI_DRIVER_B: return _SC("Taxi Driver #2"); + case SQMOD_SKIN_GYM_LADY: return _SC("Gym Lady"); + case SQMOD_SKIN_GYM_GUY: return _SC("Gym Guy"); + case SQMOD_SKIN_SKATE_LADY: return _SC("Skate Lady"); + case SQMOD_SKIN_SKATE_GUY: return _SC("Skate Guy"); + case SQMOD_SKIN_SHOPPER_A: return _SC("Shopper #1"); + case SQMOD_SKIN_SHOPPER_B: return _SC("Shopper #2"); + case SQMOD_SKIN_TOURIST_A: return _SC("Tourist #1"); + case SQMOD_SKIN_TOURIST_B: return _SC("Tourist #2"); + case SQMOD_SKIN_CUBAN_A: return _SC("Cuban #1"); + case SQMOD_SKIN_CUBAN_B: return _SC("Cuban #2"); + case SQMOD_SKIN_HATIAN_C: return _SC("Haitian #3"); + case SQMOD_SKIN_HATIAN_D: return _SC("Haitian #4"); + case SQMOD_SKIN_SHARK_A: return _SC("Shark #1"); + case SQMOD_SKIN_SHARK_B: return _SC("Shark #2"); + case SQMOD_SKIN_DIAZ_GUY_A: return _SC("Diaz Guy #1"); + case SQMOD_SKIN_DIAZ_GUY_B: return _SC("Diaz Guy #2"); + case SQMOD_SKIN_DBP_SECURITY_A: return _SC("DBP Security #1"); + case SQMOD_SKIN_DBP_SECURITY_B: return _SC("DBP Security #2"); + case SQMOD_SKIN_BIKER_A: return _SC("Biker #1"); + case SQMOD_SKIN_BIKER_B: return _SC("Biker #2"); + case SQMOD_SKIN_VERCETTI_GUY_A: return _SC("Vercetti Guy #1"); + case SQMOD_SKIN_VERCETTI_GUY_B: return _SC("Vercetti Guy #2"); + case SQMOD_SKIN_UNDERCOVER_COP_A: return _SC("Undercover Cop #1"); + case SQMOD_SKIN_UNDERCOVER_COP_B: return _SC("Undercover Cop #2"); + case SQMOD_SKIN_UNDERCOVER_COP_C: return _SC("Undercover Cop #3"); + case SQMOD_SKIN_UNDERCOVER_COP_D: return _SC("Undercover Cop #4"); + case SQMOD_SKIN_UNDERCOVER_COP_E: return _SC("Undercover Cop #5"); + case SQMOD_SKIN_UNDERCOVER_COP_F: return _SC("Undercover Cop #6"); + case SQMOD_SKIN_RICH_GUY: return _SC("Rich Guy"); + case SQMOD_SKIN_COOL_GUY_C: return _SC("Cool Guy #3"); + case SQMOD_SKIN_PROSTITUTE_E: return _SC("Prostitute #3"); + case SQMOD_SKIN_PROSTITUTE_F: return _SC("Prostitute #4"); + case SQMOD_SKIN_LOVE_FIST_A: return _SC("Love Fist #1"); + case SQMOD_SKIN_KEN_ROSENBURG: return _SC("Ken Rosenburg"); + case SQMOD_SKIN_CANDY_SUXX: return _SC("Candy Suxx"); + case SQMOD_SKIN_HILARY: return _SC("Hilary"); + case SQMOD_SKIN_LOVE_FIST_B: return _SC("Love Fist #2"); + case SQMOD_SKIN_PHIL: return _SC("Phil"); + case SQMOD_SKIN_ROCKSTAR_GUY: return _SC("Rockstar Guy"); + case SQMOD_SKIN_SONNY: return _SC("Sonny"); + case SQMOD_SKIN_LANCE_A: return _SC("Lance"); + case SQMOD_SKIN_MERCADES_A: return _SC("Mercedes"); + case SQMOD_SKIN_LOVE_FIST_C: return _SC("Love Fist #3"); + case SQMOD_SKIN_ALEX_SRUB: return _SC("Alex Shrub"); + case SQMOD_SKIN_LANCE_COP: return _SC("Lance (Cop)"); + case SQMOD_SKIN_LANCE_B: return _SC("Lance"); + case SQMOD_SKIN_CORTEZ: return _SC("Cortez"); + case SQMOD_SKIN_LOVE_FIST_D: return _SC("Love Fist #4"); + case SQMOD_SKIN_COLUMBIAN_GUY_A: return _SC("Columbian Guy #1"); + case SQMOD_SKIN_HILARY_ROBBER: return _SC("Hilary (Robber)"); + case SQMOD_SKIN_MERCADES_B: return _SC("Mercedes"); + case SQMOD_SKIN_CAM: return _SC("Cam"); + case SQMOD_SKIN_CAM_ROBBER: return _SC("Cam (Robber)"); + case SQMOD_SKIN_PHIL_ONE_ARM: return _SC("Phil (One Arm)"); + case SQMOD_SKIN_PHIL_ROBBER: return _SC("Phil (Robber)"); + case SQMOD_SKIN_COOL_GUY_D: return _SC("Cool Guy #4"); + case SQMOD_SKIN_PIZZAMAN: return _SC("Pizza Man"); + case SQMOD_SKIN_TAXI_DRIVER_C: return _SC("Taxi Driver #1"); + case SQMOD_SKIN_TAXI_DRIVER_D: return _SC("Taxi Driver #2"); + case SQMOD_SKIN_SAILOR_A: return _SC("Sailor #1"); + case SQMOD_SKIN_SAILOR_B: return _SC("Sailor #2"); + case SQMOD_SKIN_SAILOR_C: return _SC("Sailor #3"); + case SQMOD_SKIN_CHEF: return _SC("Chef"); + case SQMOD_SKIN_CRIMINAL_B: return _SC("Criminal #2"); + case SQMOD_SKIN_FRENCH_GUY: return _SC("French Guy"); + case SQMOD_SKIN_GARBAGEMAN_B: return _SC("Garbageman #2"); + case SQMOD_SKIN_HATIAN_E: return _SC("Haitian #5"); + case SQMOD_SKIN_WAITRESS_B: return _SC("Waitress #2"); + case SQMOD_SKIN_SONNY_GUY_A: return _SC("Sonny Guy #1"); + case SQMOD_SKIN_SONNY_GUY_B: return _SC("Sonny Guy #2"); + case SQMOD_SKIN_SONNY_GUY_C: return _SC("Sonny Guy #3"); + case SQMOD_SKIN_COLUMBIAN_GUY_B: return _SC("Columbian Guy #2"); + case SQMOD_SKIN_THUG_A: return _SC("Haitian #6"); + case SQMOD_SKIN_BEACH_GUY_H: return _SC("Beach Guy #8"); + case SQMOD_SKIN_GARBAGEMAN_C: return _SC("Garbageman #3"); + case SQMOD_SKIN_GARBAGEMAN_D: return _SC("Garbageman #4"); + case SQMOD_SKIN_GARBAGEMAN_E: return _SC("Garbageman #5"); + case SQMOD_SKIN_TRANNY: return _SC("Tranny"); + case SQMOD_SKIN_THUG_B: return _SC("Thug #5"); + case SQMOD_SKIN_SPANDEX_GUY_A: return _SC("SpandEx Guy #1"); + case SQMOD_SKIN_SPANDEX_GUY_B: return _SC("SpandEx Guy #2"); + case SQMOD_SKIN_STRIPPER_A: return _SC("Stripper #1"); + case SQMOD_SKIN_STRIPPER_B: return _SC("Stripper #2"); + case SQMOD_SKIN_STRIPPER_C: return _SC("Stripper #3"); + case SQMOD_SKIN_STORE_CLERK: return _SC("Store Clerk"); + default: return _SC(""); + } +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 GetSkinID(const SQChar * name) +{ + // Clone the string into an editable version + String str(name); + // Strip non alphanumeric characters from the name + str.erase(std::remove_if(str.begin(), str.end(), std::not1(std::ptr_fun(::isalnum))), str.end()); + // Convert the string to lowercase + std::transform(str.begin(), str.end(), str.begin(), ::tolower); + // See if we still have a valid name after the cleanup + if(str.empty()) return SQMOD_UNKNOWN; + // Grab the actual length of the string + unsigned len = str.length(); + // Get the most significant characters used to identify a skin + SQChar a = str[0], b = 0, c = 0, d = str[len-1]; + // Look for deeper specifiers + if (str.length() >= 3) + { + b = str[1]; + c = str[2]; + } + else if (str.length() >= 2) + { + b = str[1]; + } + // Search for a pattern in the name + switch (a) + { + // [A]lex Srub, [A]rabic guy, [A]rmy + case 'a': + switch (b) + { + // [Al]ex [S]rub + case 'l': + case 's': return SQMOD_SKIN_ALEX_SRUB; + // [A]rabic [g]uy + case 'g': return SQMOD_SKIN_ARABIC_GUY; + // [Ara]bic guy, [Arm]y + case 'r': + if (c == 'a') return SQMOD_SKIN_ARABIC_GUY; + else if (c == 'm') return SQMOD_SKIN_ARMY; + } + // [B]each guy (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E)/(#6|F)/(#7|G)/(#8|H) + // [B]each lady (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E)/(#6|F)/(#7|G) + // [B]iker (#1|A)/(#2|B) + // [B]um guy (#1|A)/(#2|B)/(#3|C) + // [B]um lady (#1|A)/(#2|B)/(#2|C)/(#3|D)/(#4|E) + // [B]usiness man (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E)/(#6|F) + case 'b': + // [Be]ach [g]uy (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E)/(#6|F)/(#7|G)/(#8|H) + if (b == 'e' && (c == 'g' || (len > 4 && str[5] == 'g'))) + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_BEACH_GUY_A; + case '2': + case 'b': return SQMOD_SKIN_BEACH_GUY_B; + case '3': + case 'c': return SQMOD_SKIN_BEACH_GUY_C; + case '4': + case 'd': return SQMOD_SKIN_BEACH_GUY_D; + case '5': + case 'e': return SQMOD_SKIN_BEACH_GUY_E; + case '6': + case 'f': return SQMOD_SKIN_BEACH_GUY_F; + case '7': + case 'g': return SQMOD_SKIN_BEACH_GUY_G; + case '8': + case 'h': return SQMOD_SKIN_BEACH_GUY_H; + } + } + // [Be]ach [l]ady (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E)/(#6|F)/(#7|G) + else if (b == 'e' && (c == 'l' || (len > 4 && str[5] == 'l'))) + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_BEACH_LADY_A; + case '2': + case 'b': return SQMOD_SKIN_BEACH_LADY_B; + case '3': + case 'c': return SQMOD_SKIN_BEACH_LADY_C; + case '4': + case 'd': return SQMOD_SKIN_BEACH_LADY_D; + case '5': + case 'e': return SQMOD_SKIN_BEACH_LADY_E; + case '6': + case 'f': return SQMOD_SKIN_BEACH_LADY_F; + case '7': + case 'g': return SQMOD_SKIN_BEACH_LADY_G; + } + } + // [Bi]ker (#1|A)/(#2|B) + else if (b == 'i' && (d == '1' || d == 'a')) return SQMOD_SKIN_BIKER_A; + else if (b == 'i' && (d == '2' || d == 'b')) return SQMOD_SKIN_BIKER_B; + // [Bum] [g]uy (#1|A)/(#2|B)/(#3|C) + // [Bum] [l]ady (#1|A)/(#2|B)/(#2|C)/(#3|D)/(#4|E) + else if (b == 'u' && (c && (c == 'm' || c == 'g' || c == 'l'))) + { + // [Bum] [g]uy (#1|A)/(#2|B)/(#3|C) + if (c == 'g' || (len > 2 && str[3] == 'g')) + { + if (d == '1' || d == 'a') return SQMOD_SKIN_BUM_GUY_A; + else if (d == '2' || d == 'b') return SQMOD_SKIN_BUM_GUY_B; + else if (d == '3' || d == 'c') return SQMOD_SKIN_BUM_GUY_C; + } + // [Bum] [l]ady (#1|A)/(#2|B)/(#2|C)/(#3|D)/(#4|E) + else if (c == 'l' || (len > 2 && str[3] == 'l')) + { + if (d == '1' || d == 'a') return SQMOD_SKIN_BUM_LADY_A; + else if (d == '2' || d == 'b') return SQMOD_SKIN_BUM_LADY_B; + else if (d == '2' || d == 'c') return SQMOD_SKIN_BUM_LADY_C; + else if (d == '3' || d == 'd') return SQMOD_SKIN_BUM_LADY_D; + else if (d == '4' || d == 'e') return SQMOD_SKIN_BUM_LADY_E; + } + } + // [Bus]iness [m]an (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E)/(#6|F) + else if (b == 'u' && (c == 's' || (len > 8 && str[9] == 'm'))) + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_BUSINESS_MAN_A; + case '2': + case 'b': return SQMOD_SKIN_BUSINESS_MAN_B; + case '3': + case 'c': return SQMOD_SKIN_BUSINESS_MAN_C; + case '4': + case 'd': return SQMOD_SKIN_BUSINESS_MAN_D; + case '5': + case 'e': return SQMOD_SKIN_BUSINESS_MAN_E; + case '6': + case 'f': return SQMOD_SKIN_BUSINESS_MAN_F; + } + } + // [C]am, [C]am (Robber), [C]andy Suxx, [C]hef + // [C]hurch guy, [C]hurch lady, [C]lub lady + // [C]olumbian guy (#1|A)/(#2|B), + // [C]onstruction worker (#1|A)/(#2|B) + // [C]ool guy (#1|A)/(#2|B)/(#3|C)/(#4|D) + // [C]op, [C]ortez + // [C]riminal (#1|A)/(#2|B) + // [C]uban (#1|A)/(#2|B) + case 'c': + // [Ca]m, [Ca]m (Robber), [Ca]ndy Suxx + if (b == 'a') + { + // [Cam] ([R]obbe[r]) + if (c && (c == 'm' || c == 'r') && d == 'r') return SQMOD_SKIN_CAM_ROBBER; + // [Cam] + else if (c == 'm') return SQMOD_SKIN_CAM; + // [Can]dy [S]ux[x] + else if (c && (c == 'n' || c == 's' || d == 'x')) return SQMOD_SKIN_CANDY_SUXX; + } + // [Ch]ef, [Ch]urch guy, [Ch]urch lady + else if (b == 'h') + { + // [Che][f] + if (c && (c == 'e' || d == 'f')) return SQMOD_SKIN_CHEF; + // [Chu]rch [g]uy + else if (c && ((c == 'u' && len > 5 && str[6] == 'g') || (c == 'g'))) + return SQMOD_SKIN_CHURCH_GUY; + // [Chu]rch [l]ady + else if (c && ((c == 'u' && len > 5 && str[6] == 'l') || (c == 'l'))) + return SQMOD_SKIN_CHURCH_LADY; + } + // [Cl]ub [l]ady + else if (b == 'l') return SQMOD_SKIN_CLUB_LADY; + // [Co]lumbian guy (#1|A)/(#2|B) + // [Co]nstruction worker (#1|A)/(#2|B) + // [Co]ol guy (#1|A)/(#2|B)/(#3|C)/(#4|D) + // [Co]p, [Co]rtez + else if (b == 'o') + { + // [Col]umbian [g]uy (#1|A)/(#2|B) + if (c && ((c == 'l' && len > 8 && str[9] == 'g') || (c == 'g'))) + { + if (d == '1' || d == 'a') return SQMOD_SKIN_COLUMBIAN_GUY_A; + else if (d == '2' || d == 'b') return SQMOD_SKIN_COLUMBIAN_GUY_B; + } + // [Con]struction [w]orker (#1|A)/(#2|B) + else if (c && (c == 'n' || (len > 11 && str[12] == 'g'))) + { + if (d == '1' || d == 'a') return SQMOD_SKIN_CONSTRUCTION_WORKER_A; + else if (d == '2' || d == 'b') return SQMOD_SKIN_CONSTRUCTION_WORKER_B; + } + // [Coo]l guy (#1|A)/(#2|B)/(#3|C)/(#4|D) + else if (c == 'o') + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_COOL_GUY_A; + case '2': + case 'b': return SQMOD_SKIN_COOL_GUY_B; + case '3': + case 'c': return SQMOD_SKIN_COOL_GUY_C; + case '4': + case 'd': return SQMOD_SKIN_COOL_GUY_D; + } + } + // [Cop] + else if (c == 'p') return SQMOD_SKIN_COP; + // [Cor]te[z] + else if (c && (c == 'r' || c == 'z' || d == 'z')) return SQMOD_SKIN_CORTEZ; + } + // [Cr]iminal (#1|A)/(#2|B) + else if (b == 'r' && (d == '1' || d == 'a')) return SQMOD_SKIN_CRIMINAL_A; + else if (b == 'r' && (d == '2' || d == 'b')) return SQMOD_SKIN_CRIMINAL_B; + // [Cu]ban (#1|A)/(#2|B) + else if (b == 'u' && (d == '1' || d == 'a')) return SQMOD_SKIN_CUBAN_A; + else if (b == 'u' && (d == '2' || d == 'b')) return SQMOD_SKIN_CUBAN_B; + // [D]BP security (#1|A)/(#2|B) + // [D]iaz guy (#1|A)/(#2|B) + case 'd': + switch (b) + { + // [DB]P [s]ecurity (#1|A)/(#2|B) + case 'b': + case 's': + if (d == '1' || d == 'a') return SQMOD_SKIN_DBP_SECURITY_A; + else if (d == '2' || d == 'b') return SQMOD_SKIN_DBP_SECURITY_B; + // [Di]a[z] [g]uy (#1|A)/(#2|B) + case 'i': + case 'z': + case 'g': + if (d == '1' || d == 'a') return SQMOD_SKIN_DIAZ_GUY_A; + else if (d == '2' || d == 'b') return SQMOD_SKIN_DIAZ_GUY_B; + } + // [F]BI, [F]ireman, [F]ood lady, [F]rench guy + case 'f': + switch (b) + { + // [FB]I + case 'b': return SQMOD_SKIN_FBI; + // [Fi]re[m]an + case 'i': + case 'm': return SQMOD_SKIN_FIREMAN; + // [Fo]od [l]ady + case 'o': + case 'l': return SQMOD_SKIN_FOOD_LADY; + // [Fr]ench [g]uy + case 'r': + case 'g': return SQMOD_SKIN_FRENCH_GUY; + } + // [G]arbageman (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E) + // [G]olf guy (#1|A)/(#2|B)/(#3|C) + // [G]olf lady + // [G]ranny (#1|A)/(#2|B) + // [G]ym guy, [G]ym lady + case 'g': + // [Ga]rbage[m]an (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E) + if (b && (b == 'a' || b == 'm')) + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_GARBAGEMAN_A; + case '2': + case 'b': return SQMOD_SKIN_GARBAGEMAN_B; + case '3': + case 'c': return SQMOD_SKIN_GARBAGEMAN_C; + case '4': + case 'd': return SQMOD_SKIN_GARBAGEMAN_D; + case '5': + case 'e': return SQMOD_SKIN_GARBAGEMAN_E; + } + } + // [Go]lf [g]uy (#1|A)/(#2|B)/(#3|C) + else if (b == 'o' && ((c == 'g') || (len > 3 && str[4] == 'g'))) + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_GOLF_GUY_A; + case '2': + case 'b': return SQMOD_SKIN_GOLF_GUY_B; + case '3': + case 'c': return SQMOD_SKIN_GOLF_GUY_C; + } + } + // [Go]lf [l]ady + else if (b == 'o' && ((c == 'l') || (len > 3 && str[4] == 'l'))) + return SQMOD_SKIN_GOLF_LADY; + // [Gr]anny (#1|A)/(#2|B) + else if (b == 'r') + { + if (d == '1' || d == 'a') return SQMOD_SKIN_GRANNY_A; + else if (d == '2' || d == 'b') return SQMOD_SKIN_GRANNY_B; + } + // [Gy]m [g]uy + else if (b && (b == 'g' || (b == 'y' && len > 2 && str[3] == 'g'))) + return SQMOD_SKIN_GYM_GUY; + // [Gy]m [l]ady + else if (b && (b == 'l' || (b == 'y' && len > 2 && str[3] == 'l'))) + return SQMOD_SKIN_GYM_LADY; + // [H]atian (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E) + // [H]ilary, [H]ilary (Robber), [H]ood lady + case 'h': + // [H]atian (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E) + if (b == 'a') + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_HATIAN_A; + case '2': + case 'b': return SQMOD_SKIN_HATIAN_B; + case '3': + case 'c': return SQMOD_SKIN_HATIAN_C; + case '4': + case 'd': return SQMOD_SKIN_HATIAN_D; + case '5': + case 'e': return SQMOD_SKIN_HATIAN_E; + } + } + // [Hi]lary ([R]obbe[r]) + else if (b && (b == 'i' || b == 'r') && d == 'r') return SQMOD_SKIN_HILARY_ROBBER; + // [Hi]lary + else if (b == 'i') return SQMOD_SKIN_HILARY; + // [Ho]od [l]ady + if (b && (b == 'o' || b == 'l')) return SQMOD_SKIN_HOOD_LADY; + // [K]en Rosenburg + case 'k': + return SQMOD_SKIN_KEN_ROSENBURG; + // [L]ance (#1|A)/(#1|B) + // [L]ance (Cop) + // [L]awyer + // [L]ove Fist (#1|A)/(#2|B)/(#3|C)/(#3|D) + case 'l': + //[Lan]ce ([C]o[p]) + if ((b == 'a') && (c == 'n') && ((len > 4 && str[5] == 'c') || d == 'p')) + return SQMOD_SKIN_LANCE_COP; + else if (b && (b == 'c' || (b == 'a' && (c == 'n')))) + return SQMOD_SKIN_LANCE_COP; + // [La]nce (#1|A)/(#1|B) + else if (b == 'a' && c == 'n') + { + if (d == '1' || d == 'a') return SQMOD_SKIN_LANCE_A; + else if (d == '2' || d == 'b') return SQMOD_SKIN_LANCE_B; + } + // [Law]yer + else if (b && (b == 'w' || (b == 'a' && c == 'w'))) return SQMOD_SKIN_LAWYER; + // [Lo]ve [F]ist (#1|A)/(#2|B)/(#3|C)/(#3|D) + else if (b && (b == 'o' || b == 'f')) + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_LOVE_FIST_A; + case '2': + case 'b': return SQMOD_SKIN_LOVE_FIST_B; + case '3': + case 'c': return SQMOD_SKIN_LOVE_FIST_C; + case 'd': return SQMOD_SKIN_LOVE_FIST_D; + } + } + // [M]ercades + case 'm': + if (d == 'b') return SQMOD_SKIN_MERCADES_B; + else return SQMOD_SKIN_MERCADES_A; + // [O]ffice lady (#1|A)/(#2|B) + case 'o': + if (d == '1' || d == 'a') return SQMOD_SKIN_OFFICE_LADY_A; + else if (d == '2' || d == 'b') return SQMOD_SKIN_OFFICE_LADY_B; + // [P]aramedic, [P]hil, [P]hil (One arm), [P]hil (Robber) + // [P]imp, [P]izzaman + // [P]rostitute (#1|A)/(#2|B)/(#2|C)/(#2|D)/(#3|D)/(#4|D) + // [P]unk (#1|A)/(#2|B)/(#3|C) + case 'p': + // [Pa]ramedic + if (b == 'a') return SQMOD_SKIN_PARAMEDIC; + // [Ph]il (One arm), [Ph]il (Robber) + else if (b == 'h') + { + // [Ph]il ([O]ne ar[m]) + if (b == 'o' || (c == 'o') || (len > 3 && str[4] == 'o') || d == 'm') + return SQMOD_SKIN_PHIL_ONE_ARM; + // [Ph]il ([R]obbe[r]) + else if (c && (c == 'r' || d == 'r' || (len > 3 && str[4] == 'r'))) + return SQMOD_SKIN_PHIL_ROBBER; + // [Phi]l + else if (c == 'i') return SQMOD_SKIN_PHIL; + } + // [Pim][p] + else if (b == 'i' && ((c == 'm') || d == 'p')) return SQMOD_SKIN_PIMP; + // [Piz]zama[n] + else if (b == 'i' && ((c == 'z') || d == 'n')) return SQMOD_SKIN_PIZZAMAN; + // [Pr]ostitute (#1|A)/(#2|B)/(#2|C)/(#2|D)/(#3|D)/(#4|D) + else if (b == 'r') + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_PROSTITUTE_A; + case '2': + case 'b': return SQMOD_SKIN_PROSTITUTE_B; + case 'c': return SQMOD_SKIN_PROSTITUTE_C; + case 'd': return SQMOD_SKIN_PROSTITUTE_D; + case '3': + case 'e': return SQMOD_SKIN_PROSTITUTE_E; + case '4': + case 'f': return SQMOD_SKIN_PROSTITUTE_F; + } + } + // [Pu]nk (#1|A)/(#2|B)/(#3|C) + else if (b == 'u') + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_PUNK_A; + case '2': + case 'b': return SQMOD_SKIN_PUNK_B; + case '3': + case 'c': return SQMOD_SKIN_PUNK_C; + } + } + // [R]ich guy, [R]ockstar guy + case 'r': + // [Ri]ch guy + if (b == 'i') return SQMOD_SKIN_RICH_GUY; + // [Ro]ckstar guy + else if (b == 'o') return SQMOD_SKIN_ROCKSTAR_GUY; + // [S]ailor (#1|A)/(#2|B)/(#3|C) + // [S]hark (#1|A)/(#2|B) + // [S]hopper (#1|A)/(#2|B) + // [S]kate guy, [S]kate lady, [S]onny + // [S]onny guy (#1|A)/(#2|B)/(#3|C) + // [S]pandEx (#1|A)/(#2|B) + // [S]panish guy + // [S]panish lady (#1|A)/(#2|B)/(#3|C)/(#4|D) + // [S]tore clerk + // [S]tripper (#1|A)/(#2|B)/(#3|C) + // [S]wat + case 's': + // [Sa]ilor (#1|A)/(#2|B)/(#3|C) + if (b == 'a') + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_SAILOR_A; + case '2': + case 'b': return SQMOD_SKIN_SAILOR_B; + case '3': + case 'c': return SQMOD_SKIN_SAILOR_C; + } + } + // [S]hark (#1|A)/(#2|B) + else if (b == 'h' && c == 'a') + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_SHARK_A; + case '2': + case 'b': return SQMOD_SKIN_SHARK_B; + } + } + // [S]hopper (#1|A)/(#2|B) + else if (b == 'h' && c == 'o') + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_SHOPPER_A; + case '2': + case 'b': return SQMOD_SKIN_SHOPPER_B; + } + } + // [Sk]ate [g]uy + else if (b == 'k' && ((c == 'g') || (len > 4 && str[5] == 'g'))) + return SQMOD_SKIN_SKATE_GUY; + // [Sk]ate [l]ady + else if (b == 'k' && ((c == 'l') || (len > 4 && str[5] == 'l'))) + return SQMOD_SKIN_SKATE_LADY; + // [So]nny + // [So]nny guy (#1|A)/(#2|B)/(#3|C) + else if (b == 'o') + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_SONNY_GUY_A; + case '2': + case 'b': return SQMOD_SKIN_SONNY_GUY_B; + case '3': + case 'c': return SQMOD_SKIN_SONNY_GUY_C; + } + } + else if (b == 'g') + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_SONNY_GUY_A; + case '2': + case 'b': return SQMOD_SKIN_SONNY_GUY_B; + case '3': + case 'c': return SQMOD_SKIN_SONNY_GUY_C; + } + } + // [Sp]andE[x] (#1|A)/(#2|B) + else if (b == 'p' && ((c == 'x') || (len > 5 && str[6] == 'x'))) + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_SPANDEX_GUY_A; + case '2': + case 'b': return SQMOD_SKIN_SPANDEX_GUY_B; + } + } + // [Sp]anish [g]uy + else if (b == 'p' && ((c == 'g') || (len > 6 && str[7] == 'g'))) + return SQMOD_SKIN_SPANISH_GUY; + // [Sp]anish [l]ady (#1|A)/(#2|B)/(#3|C)/(#4|D) + else if (b == 'p' && ((c == 'l') || (len > 6 && str[7] == 'l'))) + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_SPANISH_LADY_A; + case '2': + case 'b': return SQMOD_SKIN_SPANISH_LADY_B; + case '3': + case 'c': return SQMOD_SKIN_SPANISH_LADY_C; + case '4': + case 'd': return SQMOD_SKIN_SPANISH_LADY_D; + } + } + // [Sto]re clerk + else if ((b == 't') && (c == 'o')) return SQMOD_SKIN_STORE_CLERK; + // [Str]ipper (#1|A)/(#2|B)/(#3|C) + else if ((b == 't') && (c == 'r')) + { + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_STRIPPER_A; + case '2': + case 'b': return SQMOD_SKIN_STRIPPER_B; + case '3': + case 'c': return SQMOD_SKIN_STRIPPER_C; + } + } + // [Sw]at + else if (b == 'w') return SQMOD_SKIN_SWAT; + // [T]axi driver (#1|A)/(#1|B)/(#2|C)/(#2|D) + // [T]hug (#1|A)/(#2|B) + // [T]ommy Vercetti + // [T]ourist (#1|A)/(#2|B) + // [T]ranny + case 't': + switch (b) + { + // [Ta]xi driver (#1|A)/(#1|B)/(#2|C)/(#2|D) + case 'a': + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_TAXI_DRIVER_A; + case '2': + case 'b': return SQMOD_SKIN_TAXI_DRIVER_B; + case 'c': return SQMOD_SKIN_TAXI_DRIVER_C; + case 'd': return SQMOD_SKIN_TAXI_DRIVER_D; + } + // [Th]ug (#1|A)/(#2|B) + case 'h': + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_THUG_A; + case '5': + case 'b': return SQMOD_SKIN_THUG_B; + } + // [To]mmy [V]ercetti + // [To]urist (#1|A)/(#2|B) + case 'v': return SQMOD_SKIN_TOMMY_VERCETTI; + case 'o': + if (c == 'm') return SQMOD_SKIN_TOMMY_VERCETTI; + else if (c == 'u' && (d == '1' || d == 'a')) return SQMOD_SKIN_TOURIST_A; + else if (c == 'u' && (d == '2' || d == 'b')) return SQMOD_SKIN_TOURIST_B; + case 'r': return SQMOD_SKIN_TRANNY; + } + // [U]ndercover cop (#1|A)/(#2|B)/(#3|C)/(#4|D)/(#5|E)/(#6|F) + case 'u': + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_UNDERCOVER_COP_A; + case '2': + case 'b': return SQMOD_SKIN_UNDERCOVER_COP_B; + case '3': + case 'c': return SQMOD_SKIN_UNDERCOVER_COP_C; + case '4': + case 'd': return SQMOD_SKIN_UNDERCOVER_COP_D; + case '5': + case 'e': return SQMOD_SKIN_UNDERCOVER_COP_E; + case '6': + case 'f': return SQMOD_SKIN_UNDERCOVER_COP_F; + } + // [V]ercetti guy (#1|A)/(#2|B) + case 'v': + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_VERCETTI_GUY_A; + case '2': + case 'b': return SQMOD_SKIN_VERCETTI_GUY_B; + } + // [W]aitress (#1|A)/(#2|B) + case 'w': + switch (d) + { + case '1': + case 'a': return SQMOD_SKIN_WAITRESS_A; + case '2': + case 'b': return SQMOD_SKIN_WAITRESS_B; + } + // Default to unknown + default: return SQMOD_UNKNOWN; + } +} + +// ------------------------------------------------------------------------------------------------ +bool IsSkinValid(SQInt32 id) +{ + return (strcmp(GetSkinName(id), _SC("")) != 0) ? SQTrue : SQFalse; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetAutomobileName(SQInt32 id) +{ + switch(id) + { + case SQMOD_VEHICLE_LANDSTALKER: return _SC("Landstalker"); + case SQMOD_VEHICLE_IDAHO: return _SC("Idaho"); + case SQMOD_VEHICLE_STINGER: return _SC("Stinger"); + case SQMOD_VEHICLE_LINERUNNER: return _SC("Linerunner"); + case SQMOD_VEHICLE_PERENNIAL: return _SC("Perennial"); + case SQMOD_VEHICLE_SENTINEL: return _SC("Sentinel"); + case SQMOD_VEHICLE_RIO: return _SC("Rio"); + case SQMOD_VEHICLE_FIRETRUCK: return _SC("Firetruck"); + case SQMOD_VEHICLE_TRASHMASTER: return _SC("Trashmaster"); + case SQMOD_VEHICLE_STRETCH: return _SC("Stretch"); + case SQMOD_VEHICLE_MANANA: return _SC("Manana"); + case SQMOD_VEHICLE_INFERNUS: return _SC("Infernus"); + case SQMOD_VEHICLE_VOODOO: return _SC("Voodoo"); + case SQMOD_VEHICLE_PONY: return _SC("Pony"); + case SQMOD_VEHICLE_MULE: return _SC("Mule"); + case SQMOD_VEHICLE_CHEETAH: return _SC("Cheetah"); + case SQMOD_VEHICLE_AMBULANCE: return _SC("Ambulance"); + case SQMOD_VEHICLE_FBIWASHINGTON: return _SC("FBI Washington"); + case SQMOD_VEHICLE_MOONBEAM: return _SC("Moonbeam"); + case SQMOD_VEHICLE_ESPERANTO: return _SC("Esperanto"); + case SQMOD_VEHICLE_TAXI: return _SC("Taxi"); + case SQMOD_VEHICLE_WASHINGTON: return _SC("Washington"); + case SQMOD_VEHICLE_BOBCAT: return _SC("Bobcat"); + case SQMOD_VEHICLE_MRWHOOPEE: return _SC("Mr. Whoopee"); + case SQMOD_VEHICLE_BFINJECTION: return _SC("BF Injection"); + case SQMOD_VEHICLE_HUNTER: return _SC("Hunter"); + case SQMOD_VEHICLE_POLICE: return _SC("Police"); + case SQMOD_VEHICLE_ENFORCER: return _SC("Enforcer"); + case SQMOD_VEHICLE_SECURICAR: return _SC("Securicar"); + case SQMOD_VEHICLE_BANSHEE: return _SC("Banshee"); + case SQMOD_VEHICLE_PREDATOR: return _SC("Predator"); + case SQMOD_VEHICLE_BUS: return _SC("Bus"); + case SQMOD_VEHICLE_RHINO: return _SC("Rhino"); + case SQMOD_VEHICLE_BARRACKSOL: return _SC("Barracks OL"); + case SQMOD_VEHICLE_CUBANHERMES: return _SC("Cuban Hermes"); + case SQMOD_VEHICLE_HELICOPTER: return _SC("Helicopter"); + case SQMOD_VEHICLE_ANGEL: return _SC("Angel"); + case SQMOD_VEHICLE_COACH: return _SC("Coach"); + case SQMOD_VEHICLE_CABBIE: return _SC("Cabbie"); + case SQMOD_VEHICLE_STALLION: return _SC("Stallion"); + case SQMOD_VEHICLE_RUMPO: return _SC("Rumpo"); + case SQMOD_VEHICLE_RCBANDIT: return _SC("RC Bandit"); + case SQMOD_VEHICLE_HEARSE: return _SC("Romero's Hearse"); + case SQMOD_VEHICLE_PACKER: return _SC("Packer"); + case SQMOD_VEHICLE_SENTINELXS: return _SC("Sentinel XS"); + case SQMOD_VEHICLE_ADMIRAL: return _SC("Admiral"); + case SQMOD_VEHICLE_SQUALO: return _SC("Squalo"); + case SQMOD_VEHICLE_SEASPARROW: return _SC("Sea Sparrow"); + case SQMOD_VEHICLE_PIZZABOY: return _SC("Pizza Boy"); + case SQMOD_VEHICLE_GANGBURRITO: return _SC("Gang Burrito"); + case SQMOD_VEHICLE_AIRTRAIN: return _SC("Airtrain"); + case SQMOD_VEHICLE_DEADDODO: return _SC("Deaddodo"); + case SQMOD_VEHICLE_SPEEDER: return _SC("Speeder"); + case SQMOD_VEHICLE_REEFER: return _SC("Reefer"); + case SQMOD_VEHICLE_TROPIC: return _SC("Tropic"); + case SQMOD_VEHICLE_FLATBED: return _SC("Flatbed"); + case SQMOD_VEHICLE_YANKEE: return _SC("Yankee"); + case SQMOD_VEHICLE_CADDY: return _SC("Caddy"); + case SQMOD_VEHICLE_ZEBRACAB: return _SC("Zebra Cab"); + case SQMOD_VEHICLE_TOPFUN: return _SC("Top Fun"); + case SQMOD_VEHICLE_SKIMMER: return _SC("Skimmer"); + case SQMOD_VEHICLE_PCJ600: return _SC("PCJ-600"); + case SQMOD_VEHICLE_FAGGIO: return _SC("Faggio"); + case SQMOD_VEHICLE_FREEWAY: return _SC("Freeway"); + case SQMOD_VEHICLE_RCBARON: return _SC("RC Baron"); + case SQMOD_VEHICLE_RCRAIDER: return _SC("RC Raider"); + case SQMOD_VEHICLE_GLENDALE: return _SC("Glendale"); + case SQMOD_VEHICLE_OCEANIC: return _SC("Oceanic"); + case SQMOD_VEHICLE_SANCHEZ: return _SC("Sanchez"); + case SQMOD_VEHICLE_SPARROW: return _SC("Sparrow"); + case SQMOD_VEHICLE_PATRIOT: return _SC("Patriot"); + case SQMOD_VEHICLE_LOVEFIST: return _SC("Love Fist"); + case SQMOD_VEHICLE_COASTGUARD: return _SC("Coast Guard"); + case SQMOD_VEHICLE_DINGHY: return _SC("Dinghy"); + case SQMOD_VEHICLE_HERMES: return _SC("Hermes"); + case SQMOD_VEHICLE_SABRE: return _SC("Sabre"); + case SQMOD_VEHICLE_SABRETURBO: return _SC("Sabre Turbo"); + case SQMOD_VEHICLE_PHOENIX: return _SC("Phoenix"); + case SQMOD_VEHICLE_WALTON: return _SC("Walton"); + case SQMOD_VEHICLE_REGINA: return _SC("Regina"); + case SQMOD_VEHICLE_COMET: return _SC("Comet"); + case SQMOD_VEHICLE_DELUXO: return _SC("Deluxo"); + case SQMOD_VEHICLE_BURRITO: return _SC("Burrito"); + case SQMOD_VEHICLE_SPANDEXPRESS: return _SC("Spand Express"); + case SQMOD_VEHICLE_MARQUIS: return _SC("Marquis"); + case SQMOD_VEHICLE_BAGGAGEHANDLER: return _SC("Baggage Handler"); + case SQMOD_VEHICLE_KAUFMANCAB: return _SC("Kaufman Cab"); + case SQMOD_VEHICLE_MAVERICK: return _SC("Maverick"); + case SQMOD_VEHICLE_VCNMAVERICK: return _SC("VCN Maverick"); + case SQMOD_VEHICLE_RANCHER: return _SC("Rancher"); + case SQMOD_VEHICLE_FBIRANCHER: return _SC("FBI Rancher"); + case SQMOD_VEHICLE_VIRGO: return _SC("Virgo"); + case SQMOD_VEHICLE_GREENWOOD: return _SC("Greenwood"); + case SQMOD_VEHICLE_CUBANJETMAX: return _SC("Cuban Jetmax"); + case SQMOD_VEHICLE_HOTRINGRACER1: return _SC("Hotring Racer #1"); + case SQMOD_VEHICLE_SANDKING: return _SC("Sandking"); + case SQMOD_VEHICLE_BLISTACOMPACT: return _SC("Blista Compact"); + case SQMOD_VEHICLE_POLICEMAVERICK: return _SC("Police Maverick"); + case SQMOD_VEHICLE_BOXVILLE: return _SC("Boxville"); + case SQMOD_VEHICLE_BENSON: return _SC("Benson"); + case SQMOD_VEHICLE_MESAGRANDE: return _SC("Mesa Grande"); + case SQMOD_VEHICLE_RCGOBLIN: return _SC("RC Goblin"); + case SQMOD_VEHICLE_HOTRINGRACER2: return _SC("Hotring Racer #2"); + case SQMOD_VEHICLE_HOTRINGRACER3: return _SC("Hotring Racer #3"); + case SQMOD_VEHICLE_BLOODRINGBANGER1: return _SC("Bloodring Banger #1"); + case SQMOD_VEHICLE_BLOODRINGBANGER2: return _SC("Bloodring Banger #2"); + case SQMOD_VEHICLE_POLICECHEETAH: return _SC("Vice Squad Cheetah"); + default: return _SC(""); + } +} + +SQInt32 GetAutomobileID(const SQChar * name) +{ + // Clone the string into an editable version + String str(name); + // Strip non alphanumeric characters from the name + str.erase(std::remove_if(str.begin(), str.end(), std::not1(std::ptr_fun(::isalnum))), str.end()); + // Convert the string to lowercase + std::transform(str.begin(), str.end(), str.begin(), ::tolower); + // See if we still have a valid name after the cleanup + if(str.empty()) return SQMOD_UNKNOWN; + // Grab the actual length of the string + unsigned len = str.length(); + // Get the most significant characters used to identify a vehicle + SQChar a = str[0], b = 0, c = 0, d = str[len-1]; + // Look for deeper specifiers + if(str.length() >= 3) + { + c = str[2]; + b = str[1]; + } + else if(str.length() >= 2) + { + b = str[1]; + } + // Search for a pattern in the name + switch (a) + { + // [A]dmiral + // [A]irtrain + // [A]mbulance + // [A]ngel + case 'a': + switch (b) + { + // [Ad]miral + case 'd': return SQMOD_VEHICLE_ADMIRAL; + // [Ai]rtrain + case 'i': return SQMOD_VEHICLE_AIRTRAIN; + // [Am]bulance + case 'm': return SQMOD_VEHICLE_AMBULANCE; + // [An]gel + case 'n': return SQMOD_VEHICLE_ANGEL; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + + // [B]aggage Handler + // [B]anshee + // [B]arracks OL + // [B]enson + // [B]F Injection + // [B]lista Compact + // [B]loodring Banger #1 + // [B]loodring Banger #2 + // [B]obcat + // [B]oxville + // [B]urrito + // [B]us + case 'b': + switch (b) + { + // [Ba]ggage Handler + // [Ba]nshee + // [Ba]rracks OL + case 'a': + // [Bag]gage Handler + if (c == 'g') return SQMOD_VEHICLE_BAGGAGEHANDLER; + // [Ban]shee + else if (c == 'n') return SQMOD_VEHICLE_BANSHEE; + // [Bar]racks OL + else if (c == 'r') return SQMOD_VEHICLE_BARRACKS; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Be]nson + case 'e': return SQMOD_VEHICLE_BENSON; + // [BF] [I]njection + case 'f': + case 'i': return SQMOD_VEHICLE_BFINJECTION; + // [Bl]ista Compact + // [Bl]oodring Banger #1 + // [Bl]oodring Banger #2 + case 'l': + // [Bli]sta [C]ompact + if (b == 'c' || c == 'i') return SQMOD_VEHICLE_BLISTACOMPACT; + // [Blo]odring [B]anger (#1|A) + else if ((b == 'b' || c == 'o') && (d == '1' || d == 'a')) return SQMOD_VEHICLE_BLOODRINGBANGER1; + // [Blo]odring [B]anger (#2|B) + else if ((b == 'b' || c == 'o') && (d == '2' || d == 'b')) return SQMOD_VEHICLE_BLOODRINGBANGER2; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Bo]bcat + // [Bo]xville + case 'o': + // [Bob]cat + if (c == 'b') return SQMOD_VEHICLE_BOBCAT; + // [Box]ville + else if (c == 'x') return SQMOD_VEHICLE_BOXVILLE; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Bu]rrito + // [Bu]s + case 'u': + // [Bur]rito + if (c == 'r') return SQMOD_VEHICLE_BURRITO; + // [Bus] + else if (c == 's') return SQMOD_VEHICLE_BUS; + // Default to unknwon + else return SQMOD_UNKNOWN; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [C]abbie + // [C]addy + // [C]heetah + // [C]oach + // [C]oast Guard + // [C]omet + // [C]uban Hermes + // [C]uban Jetmax + case 'c': + switch (b) + { + // [Ca]bbie + // [Ca]ddy + case 'a': + // [Cab]bie + if (c == 'b') return SQMOD_VEHICLE_CABBIE; + // [Cad]dy + else if (c == 'd') return SQMOD_VEHICLE_CADDY; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Ch]eetah + case 'h': return SQMOD_VEHICLE_CHEETAH; + // [Co]ach + // [Co]ast Guard + // [Co]met + case 'o': + // [Coa]c[h] + if (c == 'a' && d == 'h') return SQMOD_VEHICLE_COACH; + // [Coa]s[t] Guar[d] + else if (c == 'a' && (d == 't' || d == 'd')) return SQMOD_VEHICLE_COASTGUARD; + // [Co]met + else if (c == 'm') return SQMOD_VEHICLE_COMET; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Cu]ban Hermes + // [Cu]ban Jetmax + case 'u': + // [Cub]an [H]erme[s] + if ((len > 4 && str[5] == 'h') || (d == 's' || d == 'h')) return SQMOD_VEHICLE_CUBANHERMES; + // [Cub]an [J]etma[x] + if ((len > 4 && str[5] == 'j') || (d == 'x' || d == 'j')) return SQMOD_VEHICLE_CUBANJETMAX; + // Default to unknwon + else return SQMOD_UNKNOWN; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [D]eaddodo + // [D]eluxo + // [D]inghy + case 'd': + switch (b) + { + // [De]addodo + // [De]luxo + case 'e': + // [Dea]ddodo + if (c == 'a') return SQMOD_VEHICLE_DEADDODO; + // [Del]uxo + else if (c == 'l') return SQMOD_VEHICLE_DELUXO; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Di]nghy + case 'i': return SQMOD_VEHICLE_DINGHY; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [E]speranto + // [E]nforcer + case 'e': + // [Es]peranto + if (b && b == 's') return SQMOD_VEHICLE_ESPERANTO; + // [En]forcer + else if (b && b == 'n') return SQMOD_VEHICLE_ENFORCER; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [F]aggio + // [F]BI Rancher + // [F]BI Washington + // [F]iretruck + // [F]latbed + // [F]reeway + case 'f': + switch (b) + { + // [Fa]ggio + case 'a': return SQMOD_VEHICLE_FAGGIO; + // [FB]I Rancher + // [FB]I Washington + case 'b': + // [FB]I [R]anche[r] + if ((len > 2 && str[3] == 'r') || d == 'r') return SQMOD_VEHICLE_FBIRANCHER; + // [FB]I [W]ashingto[n] + else if ((len > 2 && str[3] == 'w') || (d == 'n' || d == 'w')) return SQMOD_VEHICLE_FBIWASHINGTON; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Fi]retruck + case 'i': return SQMOD_VEHICLE_FIRETRUCK; + // [Fl]atbed + case 'l': return SQMOD_VEHICLE_FLATBED; + // [Fr]eeway + case 'r': return SQMOD_VEHICLE_FREEWAY; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [G]ang Burrito + // [G]lendale + // [G]reenwood + case 'g': + switch (b) + { + // [Ga]ng Burrito + case 'a': return SQMOD_VEHICLE_GANGBURRITO; + // [Gl]endale + case 'l': return SQMOD_VEHICLE_GLENDALE; + // [Gr]eenwood + case 'r': return SQMOD_VEHICLE_GREENWOOD; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [H]elicopter + // [H]ermes + // [H]otring Racer (#1|A)(#2|B)(#3|C) + // [H]unter + case 'h': + switch (b) + { + // [He]licopter + // [He]rmes + case 'e': + // [Hel]icopter + if (c == 'l') return SQMOD_VEHICLE_HELICOPTER; + // [Her]mes + else if (c == 'r') return SQMOD_VEHICLE_HERMES; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Ho]tring Racer (#1|A)(#2|B)(#3|C) + case 'o': + switch (d) + { + case '1': + case 'a': return SQMOD_VEHICLE_HOTRINGRACER1; + case '2': + case 'b': return SQMOD_VEHICLE_HOTRINGRACER2; + case '3': + case 'c': return SQMOD_VEHICLE_HOTRINGRACER3; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [Hu]nter + case 'u': return SQMOD_VEHICLE_HUNTER; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [I]daho + // [I]nfernus + case 'i': + // [Id]aho + if (b && b == 'd') return SQMOD_VEHICLE_IDAHO; + // [In]fernus + else if (b && b == 'n') return SQMOD_VEHICLE_INFERNUS; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [K]aufman Cab + case 'k': return SQMOD_VEHICLE_KAUFMANCAB; + // [L]andstalker + // [L]inerunner + // [L]ove Fist + case 'l': + switch (b) + { + // [La]ndstalker + case 'a': return SQMOD_VEHICLE_LANDSTALKER; + // [Li]nerunner + case 'i': return SQMOD_VEHICLE_LINERUNNER; + // [Lo]ve Fist + case 'o': return SQMOD_VEHICLE_LOVEFIST; + // Default to unknwon + default: return SQMOD_UNKNOWN; + + } + // [M]anana + // [M]arquis + // [M]averick + // [M]esa Grande + // [M]oonbeam + // [M]r. Whoopee + // [M]ule + case 'm': + switch (b) + { + // [Ma]nana + // [Ma]rquis + // [Ma]verick + case 'a': + // [Man]ana + if (c == 'n') return SQMOD_VEHICLE_MANANA; + // [Mar]quis + else if (c == 'r') return SQMOD_VEHICLE_MARQUIS; + // [Mav]erick + else if (c == 'v') return SQMOD_VEHICLE_MAVERICK; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Me]sa Grande + case 'e': return SQMOD_VEHICLE_MESAGRANDE; + // [Mo]onbeam + case 'o': return SQMOD_VEHICLE_MOONBEAM; + // [Mr]. Whoopee + case 'r': return SQMOD_VEHICLE_MRWHOOPEE; + // [Mu]le + case 'u': return SQMOD_VEHICLE_MULE; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [O]ceanic + case 'o': return SQMOD_VEHICLE_OCEANIC; + // [P]acker + // [P]atriot + // [P]CJ-600 + // [P]erennial + // [P]hoenix + // [P]izza Boy + // [P]olice + // [P]olice Maverick + // [P]ony + // [P]redator + case 'p': + switch (b) + { + // [Pa]cker + // [Pa]triot + case 'a': + // [Pac]ker + if (c == 'c') return SQMOD_VEHICLE_PACKER; + // [Pat]riot + else if (c == 't') return SQMOD_VEHICLE_PATRIOT; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [PC]J-600 + case 'c': return SQMOD_VEHICLE_PCJ600; + // [Pe]rennial + case 'e': return SQMOD_VEHICLE_PERENNIAL; + // [Ph]oenix + case 'h': return SQMOD_VEHICLE_PHOENIX; + // [Pi]zza Boy + case 'i': + // [Po]lice + // [Po]lice Maverick + // [Po]ny + case 'o': + // [Po]lice + if (d == 'e') return SQMOD_VEHICLE_POLICE; + // [Po]lice Maverick + else if ((len > 5 && str[6] == 'm') || (d == 'k' || d == 'm')) return SQMOD_VEHICLE_POLICEMAVERICK; + // [Po]ny + else if (c == 'n') return SQMOD_VEHICLE_PONY; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Pr]edator + case 'r': return SQMOD_VEHICLE_PREDATOR; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [R]ancher + // [R]C Bandit + // [R]C Baron + // [R]C Goblin + // [R]C Raider + // [R]eefer + // [R]egina + // [R]hino + // [R]io + // [R]omero's Hearse + // [R]umpo + case 'r': + switch (b) + { + // [Ra]ncher + case 'a': return SQMOD_VEHICLE_RANCHER; + // [RC] Bandit + // [RC] Baron + // [RC] Goblin + // [RC] Raider + case 'c': + // [RC] [B]andi[t] + if (c == 'b' && d == 't') return SQMOD_VEHICLE_RCBANDIT; + // [RC] [B]aro[n] + else if (c == 'b' && d == 'n') return SQMOD_VEHICLE_RCBARON; + // [RC] [G]oblin + else if (c == 'g') return SQMOD_VEHICLE_RCGOBLIN; + // [RC] [R]aide[r] + else if (c == 'r' || d == 'r') return SQMOD_VEHICLE_RCRAIDER; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Re]efer + // [Re]gina + case 'e': + // [Ree]fer + if (c == 'e' || d == 'r') return SQMOD_VEHICLE_REEFER; + // [Reg]ina + else if (c == 'g' || d == 'a') return SQMOD_VEHICLE_REGINA; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Rh]ino + case 'h': return SQMOD_VEHICLE_RHINO; + // [Ri]o + case 'i': return SQMOD_VEHICLE_RIO; + // [Ro]mero's Hearse + case 'o': return SQMOD_VEHICLE_HEARSE; + // [Ru]mpo + case 'u': return SQMOD_VEHICLE_RUMPO; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [S]abre + // [S]abre Turbo + // [S]anchez + // [S]andking + // [S]ea Sparrow + // [S]ecuricar + // [S]entinel + // [S]entinel XS + // [S]kimmer + // [S]pand Express + // [S]parrow + // [S]peeder + // [S]qualo + // [S]tallion + // [S]tinger + // [S]tretch + case 's': + switch (b) + { + // [Sa]bre + // [Sa]bre Turbo + // [Sa]nchez + // [Sa]ndking + case 'a': + // [Sab]r[e] + if (c == 'b' && d == 'e') return SQMOD_VEHICLE_SABRE; + // [Sab]re [T]urb[o] + else if ((c == 'b' && d == 'o') || (len > 4 && str[5 ]== 't')) return SQMOD_VEHICLE_SABRETURBO; + // [Sa]n[c]he[z] + else if (d == 'c' || d == 'z') return SQMOD_VEHICLE_SANCHEZ; + // [Sa]n[d]kin[g] + else if (d == 'd' || d == 'g') return SQMOD_VEHICLE_SANDKING; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Se]a Sparrow + // [Se]curicar + // [Se]ntinel + // [Se]ntinel XS + case 'e': + // [Sea] Sparro[w] + if (c == 'e' || d == 'w') return SQMOD_VEHICLE_SEASPARROW; + // [Sec]urica[r] + else if (c == 'c' || d == 'r') return SQMOD_VEHICLE_SECURICAR; + // [Sen]tine[l] + else if (c == 'n' && d == 'l') return SQMOD_VEHICLE_SENTINEL; + // [Sen]tinel X[S] + else if (c == 'n' && d == 's') return SQMOD_VEHICLE_SENTINELXS; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Sk]immer + case 'k': return SQMOD_VEHICLE_SKIMMER; + // [Sp]and Express + // [Sp]arrow + // [Sp]eeder + case 'p': + // [Spa]nd [E]xpres[s] + if (c == 'a' || ((len > 4 && str[5] == 'e') || d == 's')) return SQMOD_VEHICLE_SPANDEXPRESS; + // [Spa]rro[w] + else if (d == 'w' && (c == 'a' && d == 'w')) return SQMOD_VEHICLE_SPARROW; + // [Spe]ede[r] + else if (c == 'e' || d == 'r') return SQMOD_VEHICLE_SPEEDER; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Sq]ualo + case 'q': return SQMOD_VEHICLE_SQUALO; + // [St]allion + // [St]inger + // [St]retch + case 't': + // [Sta]llion + if (c == 'a') return SQMOD_VEHICLE_STALLION; + // [Sti]nger + if (c == 'i') return SQMOD_VEHICLE_STINGER; + // [Str]etch + if (c == 'r') return SQMOD_VEHICLE_STRETCH; + // Default to unknwon + else return SQMOD_UNKNOWN; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [T]axi + // [T]op Fun + // [T]rashmaster + // [T]ropic + case 't': + switch (b) + { + // [Ta]xi + case 'a': return SQMOD_VEHICLE_TAXI; + // [To]p Fun + case 'o': return SQMOD_VEHICLE_TOPFUN; + // [Tr]ashmaster + // [Tr]opic + case 'r': + // [Tr]ashmaster + if (c == 'a') return SQMOD_VEHICLE_TRASHMASTER; + // [Tr]opic + if (c == 'o') return SQMOD_VEHICLE_TROPIC; + // Default to unknwon + else return SQMOD_UNKNOWN; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [V]CN Maverick + // [V]ice Squad Cheetah + // [V]irgo + // [V]oodoo + case 'v': + switch (b) + { + // [VC]N Maverick + case 'c': return SQMOD_VEHICLE_VCNMAVERICK; + // [Vi]ce Squad Cheetah + // [Vi]rgo + case 'i': + // [Vic]e Squad Cheetah + if (c == 'a') return SQMOD_VEHICLE_VICECHEE; + // [Vir]go + if (c == 'o') return SQMOD_VEHICLE_VIRGO; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Vo]odoo + case 'o': return SQMOD_VEHICLE_VOODOO; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } + // [W]alton + // [W]ashington + case 'w': + // [Wa]lton + if (b == 'a' && c == 'l') return SQMOD_VEHICLE_WALTON; + // [Wa]shington + else if (b == 'a' && c == 's') return SQMOD_VEHICLE_WASHINGTON; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [Y]ankee + case 'y': return SQMOD_VEHICLE_YANKEE; + // [Z]ebra Cab + case 'z': return SQMOD_VEHICLE_ZEBRACAB; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } +} + +bool IsAutomobileValid(SQInt32 id) +{ + return (strcmp(GetAutomobileName(id), _SC("")) != 0) ? SQTrue : SQFalse; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetWeaponName(SQInt32 id) +{ + switch (id) + { + case SQMOD_WEAPON_UNARMED: return _SC("Unarmed"); + case SQMOD_WEAPON_BRASSKNUCKLES: return _SC("Brass Knuckles"); + case SQMOD_WEAPON_SCREWDRIVER: return _SC("Screwdriver"); + case SQMOD_WEAPON_GOLFCLUB: return _SC("Golf Club"); + case SQMOD_WEAPON_NIGHTSTICK: return _SC("Nightstick"); + case SQMOD_WEAPON_KNIFE: return _SC("Knife"); + case SQMOD_WEAPON_BASEBALLBAT: return _SC("Baseball Bat"); + case SQMOD_WEAPON_HAMMER: return _SC("Hammer"); + case SQMOD_WEAPON_MEATCLEAVER: return _SC("Meat Cleaver"); + case SQMOD_WEAPON_MACHETE: return _SC("Machete"); + case SQMOD_WEAPON_KATANA: return _SC("Katana"); + case SQMOD_WEAPON_CHAINSAW: return _SC("Chainsaw"); + case SQMOD_WEAPON_GRENADE: return _SC("Grenade"); + case SQMOD_WEAPON_REMOTE: return _SC("Remote Detonation Grenade"); + case SQMOD_WEAPON_TEARGAS: return _SC("Tear Gas"); + case SQMOD_WEAPON_MOLOTOV: return _SC("Molotov Cocktails"); + case SQMOD_WEAPON_ROCKET: return _SC("Rocket"); + case SQMOD_WEAPON_COLT45: return _SC("Colt .45"); + case SQMOD_WEAPON_PYTHON: return _SC("Python"); + case SQMOD_WEAPON_SHOTGUN: return _SC("Pump-Action Shotgun"); + case SQMOD_WEAPON_SPAS12: return _SC("SPAS-12 Shotgun"); + case SQMOD_WEAPON_STUBBY: return _SC("Stubby Shotgun"); + case SQMOD_WEAPON_TEC9: return _SC("TEC-9"); + case SQMOD_WEAPON_UZI: return _SC("Uzi"); + case SQMOD_WEAPON_INGRAM: return _SC("Silenced Ingram"); + case SQMOD_WEAPON_MP5: return _SC("MP5"); + case SQMOD_WEAPON_M4: return _SC("M4"); + case SQMOD_WEAPON_RUGER: return _SC("Ruger"); + case SQMOD_WEAPON_SNIPER: return _SC("Sniper Rifle"); + case SQMOD_WEAPON_LASERSCOPE: return _SC("Laserscope Sniper Rifle"); + case SQMOD_WEAPON_ROCKETLAUNCHER: return _SC("Rocket Launcher"); + case SQMOD_WEAPON_FLAMETHROWER: return _SC("Flamethrower"); + case SQMOD_WEAPON_M60: return _SC("M60"); + case SQMOD_WEAPON_MINIGUN: return _SC("Minigun"); + case SQMOD_WEAPON_BOMB: return _SC("Bomb"); + case SQMOD_WEAPON_HELICANNON: return _SC("Helicannon"); + case SQMOD_WEAPON_CAMERA: return _SC("Camera"); + case SQMOD_WEAPON_VEHICLE: return _SC("Vehicle"); + case SQMOD_WEAPON_EXPLOSION1: return _SC("Explosion"); + case SQMOD_WEAPON_DRIVEBY: return _SC("Driveby"); + case SQMOD_WEAPON_DROWNED: return _SC("Drowned"); + case SQMOD_WEAPON_FALL: return _SC("Fall"); + case SQMOD_WEAPON_EXPLOSION2: return _SC("Explosion"); + case SQMOD_WEAPON_SUICIDE: return _SC("Suicide"); + default: return _SC(""); + } +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 GetWeaponID(const SQChar * name) +{ + // Clone the string into an editable version + String str(name); + // Strip non alphanumeric characters from the name + str.erase(std::remove_if(str.begin(), str.end(), std::not1(std::ptr_fun(::isalnum))), str.end()); + // Convert the string to lowercase + std::transform(str.begin(), str.end(), str.begin(), ::tolower); + // See if we still have a valid name after the cleanup + if(str.length() < 1) return SQMOD_UNKNOWN; + // Grab the actual length of the string + unsigned len = str.length(); + // 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 + if(str.length() >= 3) + { + c = str[2]; + b = str[1]; + } + else if(str.length() >= 2) + { + b = str[1]; + } + // Search for a pattern in the name + switch(a) + { + // [B]aseball Bat + // [B]omb + // [B]rass Knuckles + case 'b': + // [Ba]seball Bat + if (b == 'a') return SQMOD_WEAPON_BASEBALLBAT; + // [Bo]mb + else if (b == 'o') return SQMOD_WEAPON_BOMB; + // [Br]ass Knuckles + else if (b == 'r') return SQMOD_WEAPON_BRASSKNUCKLES; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [C]amera + // [C]hainsaw + // [C]olt .45 + case 'c': + // [Ca]mera + if (b == 'a') return SQMOD_WEAPON_CAMERA; + // [Ch]ainsaw + else if (b == 'h') return SQMOD_WEAPON_CHAINSAW; + // [Co]lt .45 + else if (b == 'o') return SQMOD_WEAPON_COLT45; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [D]riveby + // [D]rowned + case 'd': + // [Dr]iveby + if (b == 'r' && (c == 'i' || d == 'y')) return SQMOD_WEAPON_DRIVEBY; + // [Dr]owned + else if (b == 'r' && (c == 'o' || d == 'd')) return SQMOD_WEAPON_DROWNED; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [E]xplosion + case 'e': return SQMOD_WEAPON_EXPLOSION2; + // [F]all + // [F]lamethrower + case 'f': + // [Fa]ll + if (b == 'a') return SQMOD_WEAPON_FALL; + // [Fl]amethrower + else if (b == 'l') return SQMOD_WEAPON_FLAMETHROWER; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [G]olf Club + // [G]renade + case 'g': + // [Go]lf Club + if (b == 'o') return SQMOD_WEAPON_GOLFCLUB; + // [Gr]enade + else if (b == 'r') return SQMOD_WEAPON_GRENADE; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [H]ammer + // [H]elicannon + case 'h': + // [Ha]mmer + if (b == 'a') return SQMOD_WEAPON_HAMMER; + // [He]licannon + else if (b == 'e') return SQMOD_WEAPON_HELICANNON; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [K]atana + // [K]nife + case 'k': + // [Ka]tana + if (b == 'a') return SQMOD_WEAPON_KATANA; + // [Kn]ife + else if (b == 'n') return SQMOD_WEAPON_KNIFE; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [L]aserscope Sniper Rifle + case 'l': return SQMOD_WEAPON_LASERSCOPE; + // [M]4 + // [M]60 + // [M]achete + // [M]eat Cleaver + // [M]inigun + // [M]olotov Cocktails + // [M]P5 + case 'm': + // [M4] + if (b == '4') return SQMOD_WEAPON_M4; + // [M6]0 + else if (b == '6') return SQMOD_WEAPON_M60; + // [Ma]chete + else if (b == 'a') return SQMOD_WEAPON_MACHETE; + // [Me]at Cleaver + else if (b == 'e') return SQMOD_WEAPON_MEATCLEAVER; + // [Mi]nigun + else if (b == 'i') return SQMOD_WEAPON_MINIGUN; + // [Mo]lotov Cocktails + else if (b == 'o') return SQMOD_WEAPON_MOLOTOV; + // [MP]5 + else if (b == 'p') return SQMOD_WEAPON_MP5; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [N]ightstick + case 'n': return SQMOD_WEAPON_NIGHTSTICK; + // [P]ump-Action Shotgun + // [P]ython + case 'p': + // [Pu]mp-Action Shotgun + if (b == 'u') return SQMOD_WEAPON_SHOTGUN; + // [Py]thon + else if (b == 'y') return SQMOD_WEAPON_PYTHON; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [R]emote Detonation Grenade + // [R]ocket + // [R]ocket Launcher + // [R]uger + case 'r': + // [Re]mote Detonation Grenade + if (b == 'e') return SQMOD_WEAPON_REMOTE; + // [Ro]cke[t] + else if (b == 'o' && d == 't') return SQMOD_WEAPON_ROCKET; + // [Ro]cket [L]aunche[r] + else if (b == 'o' && (d == 'r' || d == 'l' || (len > 5 && str[6] == 'l'))) return SQMOD_WEAPON_ROCKETLAUNCHER; + // [Ru]ger + else if (b == 'u') return SQMOD_WEAPON_RUGER; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [S]crewdriver + // [S]ilenced Ingram + // [S]niper Rifle + // [S]PAS-12 Shotgun + // [S]tubby Shotgun + // [S]uicide + case 's': + // [Sc]rewdriver + if (b == 'c') return SQMOD_WEAPON_SCREWDRIVER; + // [Si]lenced Ingram + else if (b == 'i') return SQMOD_WEAPON_INGRAM; + // [Sn]iper Rifle + else if (b == 'n') return SQMOD_WEAPON_SNIPER; + // [SP]AS-12 Shotgun + else if (b == 'p') return SQMOD_WEAPON_SPAS12; + // [St]ubby Shotgun + else if (b == 't') return SQMOD_WEAPON_STUBBY; + // [Su]icide + else if (b == 'u') return SQMOD_WEAPON_SUICIDE; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [T]ear Gas + // [T]EC-9 + case 't': + // [Tea]r Ga[s] + if (b == 'e' && (c == 'a' || d == 's')) return SQMOD_WEAPON_TEARGAS; + // [TEC]-[9] + else if (b == 'e' && (c == 'c' || d == '9')) return SQMOD_WEAPON_TEC9; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [U]narmed + // [U]zi + case 'u': + // [Un]armed + if (b == 'n') return SQMOD_WEAPON_UNARMED; + // [Uz]i + else if (b == 'z') return SQMOD_WEAPON_UZI; + // Default to unknwon + else return SQMOD_UNKNOWN; + // [V]ehicle + case 'v': return SQMOD_WEAPON_VEHICLE; + // Default to unknwon + default: return SQMOD_UNKNOWN; + } +} + +// ------------------------------------------------------------------------------------------------ +bool IsWeaponValid(SQInt32 id) +{ + return (strcmp(GetWeaponName(id), _SC("")) != 0) ? SQTrue : SQFalse; +} + +// ------------------------------------------------------------------------------------------------ +bool IsWeaponNatural(SQInt32 id) +{ + switch (id) + { + case SQMOD_WEAPON_VEHICLE: + case SQMOD_WEAPON_DRIVEBY: + case SQMOD_WEAPON_DROWNED: + case SQMOD_WEAPON_FALL: + case SQMOD_WEAPON_EXPLOSION2: + case SQMOD_WEAPON_SUICIDE: return SQTrue; + default: return SQFalse; + } +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 WeaponToModel(SQInt32 id) +{ + switch (id) + { + case SQMOD_WEAPON_UNARMED: return 293; + case SQMOD_WEAPON_BRASSKNUCKLES: return 259; + case SQMOD_WEAPON_SCREWDRIVER: return 260; + case SQMOD_WEAPON_GOLFCLUB: return 261; + case SQMOD_WEAPON_NIGHTSTICK: return 262; + case SQMOD_WEAPON_KNIFE: return 263; + case SQMOD_WEAPON_BASEBALLBAT: return 264; + case SQMOD_WEAPON_HAMMER: return 265; + case SQMOD_WEAPON_MEATCLEAVER: return 266; + case SQMOD_WEAPON_MACHETE: return 267; + case SQMOD_WEAPON_KATANA: return 268; + case SQMOD_WEAPON_CHAINSAW: return 269; + case SQMOD_WEAPON_GRENADE: return 270; + case SQMOD_WEAPON_REMOTE: return 291; + case SQMOD_WEAPON_TEARGAS: return 271; + case SQMOD_WEAPON_MOLOTOV: return 272; + case SQMOD_WEAPON_ROCKET: return 273; + case SQMOD_WEAPON_COLT45: return 274; + case SQMOD_WEAPON_PYTHON: return 275; + case SQMOD_WEAPON_SHOTGUN: return 277; + case SQMOD_WEAPON_SPAS12: return 278; + case SQMOD_WEAPON_STUBBY: return 279; + case SQMOD_WEAPON_TEC9: return 281; + case SQMOD_WEAPON_UZI: return 282; + case SQMOD_WEAPON_INGRAM: return 283; + case SQMOD_WEAPON_MP5: return 284; + case SQMOD_WEAPON_M4: return 280; + case SQMOD_WEAPON_RUGER: return 276; + case SQMOD_WEAPON_SNIPER: return 285; + case SQMOD_WEAPON_LASERSCOPE: return 286; + case SQMOD_WEAPON_ROCKETLAUNCHER: return 287; + case SQMOD_WEAPON_FLAMETHROWER: return 288; + case SQMOD_WEAPON_M60: return 289; + case SQMOD_WEAPON_MINIGUN: return 290; + case SQMOD_WEAPON_BOMB: return SQMOD_UNKNOWN; + case SQMOD_WEAPON_HELICANNON: return 294; + case SQMOD_WEAPON_CAMERA: return 292; + case SQMOD_WEAPON_VEHICLE: return SQMOD_UNKNOWN; + case SQMOD_WEAPON_EXPLOSION1: return SQMOD_UNKNOWN; + case SQMOD_WEAPON_DRIVEBY: return SQMOD_UNKNOWN; + case SQMOD_WEAPON_DROWNED: return SQMOD_UNKNOWN; + case SQMOD_WEAPON_FALL: return SQMOD_UNKNOWN; + case SQMOD_WEAPON_EXPLOSION2: return SQMOD_UNKNOWN; + case SQMOD_WEAPON_SUICIDE: return SQMOD_UNKNOWN; + default: return SQMOD_UNKNOWN; + } +} + +bool Register_Misc(HSQUIRRELVM vm) +{ + // Output debugging information + LogDbg("Beginning registration of API"); + // Attempt to register the specified API + Sqrat::RootTable(vm) + + .Func(_SC("GetKeyCodeName"), &GetKeyCodeName) + .Func(_SC("GetModelName"), &GetModelName) + .Func(_SC("IsModelWeapon"), &IsModelWeapon) + .Func(_SC("IsModelActuallyWeapon"), &IsModelActuallyWeapon) + .Func(_SC("IsModelValid"), &IsModelValid) + .Func(_SC("GetSkinName"), &GetSkinName) + .Func(_SC("GetSkinID"), &GetSkinID) + .Func(_SC("IsSkinValid"), &IsSkinValid) + .Func(_SC("GetAutomobileName"), &GetAutomobileName) + .Func(_SC("GetAutomobileID"), &GetAutomobileID) + .Func(_SC("IsAutomobileValid"), &IsAutomobileValid) + .Func(_SC("GetWeaponName"), &GetWeaponName) + .Func(_SC("GetWeaponID"), &GetWeaponID) + .Func(_SC("IsWeaponValid"), &IsWeaponValid) + .Func(_SC("IsWeaponNatural"), &IsWeaponNatural) + .Func(_SC("WeaponToModel"), &WeaponToModel) + + /* END REGISTRATION STATEMENT */ ; + + // Output debugging information + LogDbg("Registration of API was successful"); + // Registration succeeded + return true; +} + +} // Namespace:: SqMod diff --git a/source/Misc/Shared.hpp b/source/Misc/Shared.hpp new file mode 100644 index 00000000..025e3300 --- /dev/null +++ b/source/Misc/Shared.hpp @@ -0,0 +1,120 @@ +#ifndef _MISC_SHARED_HPP_ +#define _MISC_SHARED_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" + +// ------------------------------------------------------------------------------------------------ +#include +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetKeyCodeName(SQInteger keycode); + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetModelName(SQInt32 id); +bool IsModelWeapon(SQInt32 id); +bool IsModelActuallyWeapon(SQInt32 id); +bool IsModelValid(SQInt32 id); + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetSkinName(SQInt32 id); +SQInt32 GetSkinID(const SQChar * name); +bool IsSkinValid(SQInt32 id); + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetAutomobileName(SQInt32 id); +SQInt32 GetAutomobileID(const SQChar * name); +bool IsAutomobileValid(SQInt32 id); + +// ------------------------------------------------------------------------------------------------ +const SQChar * GetWeaponName(SQInt32 id); +SQInt32 GetWeaponID(const SQChar * name); +bool IsWeaponValid(SQInt32 id); +bool IsWeaponNatural(SQInt32 id); + +// ------------------------------------------------------------------------------------------------ +SQInt32 WeaponToModel(SQInt32 id); + +// ------------------------------------------------------------------------------------------------ +template < class T, unsigned N > class IdentifierStorage +{ +public: + // -------------------------------------------------------------------------------------------- + static constexpr SQInt32 Max = N; + +protected: + + // -------------------------------------------------------------------------------------------- + typedef std::array< std::pair< SqTag, SqObj >, N > GlobalStorage; + + // -------------------------------------------------------------------------------------------- + static GlobalStorage s_Globals; + +protected: + + /* -------------------------------------------------------------------------------------------- + * ... + */ + static const SQChar * GlobalTag(SQUint32 id) noexcept + { + if (id < N) + { + return s_Globals[id].first.c_str(); + } + return _SC(""); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + static void GlobalTag(SQUint32 id, const SQChar * tag) noexcept + { + if (id < N) + { + s_Globals[id].first.assign(tag); + } + else + { + LogErr("Attempting to set global tag for invalid automobile id: %d", id); + } + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + static SqObj & GlobalData(SQUint32 id) noexcept + { + if (id < N) + { + return s_Globals[id].second; + } + return NullData(); + } + + /* -------------------------------------------------------------------------------------------- + * ... + */ + static void GlobalData(SQUint32 id, SqObj & data) noexcept + { + if (id < N) + { + s_Globals[id].second = data; + } + else + { + LogErr("Attempting to set global data for invalid automobile id: %d", id); + } + } +}; + +// ------------------------------------------------------------------------------------------------ +template < class T, unsigned N > + typename IdentifierStorage< T, N >::GlobalStorage IdentifierStorage< T, N >::s_Globals; + +} // Namespace:: SqMod + +#endif // _MISC_SHARED_HPP_ diff --git a/source/Misc/Skin.cpp b/source/Misc/Skin.cpp new file mode 100644 index 00000000..920f547f --- /dev/null +++ b/source/Misc/Skin.cpp @@ -0,0 +1,263 @@ +#include "Misc/Skin.hpp" +#include "Register.hpp" +#include "Entity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const CSkin CSkin::NIL = CSkin(); + +// ------------------------------------------------------------------------------------------------ +CSkin::CSkin() noexcept + : m_ID(SQMOD_UNKNOWN), m_Name() +{ + +} + +CSkin::CSkin(SQInt32 id) noexcept + : m_ID(VALID_ENTITYGETEX(id, Max)), m_Name(GetSkinName(id)) +{ + +} + +CSkin::CSkin(const SQChar * name, SQInt32 id) noexcept + : CSkin(IsSkinValid(GetSkinID(name)) ? GetSkinID(name) : id) +{ + +} + +// ------------------------------------------------------------------------------------------------ +CSkin::CSkin(const CSkin & s) noexcept + : m_ID(s.m_ID) + , m_Name(s.m_Name) + , m_Tag(s.m_Tag) + , m_Data(s.m_Data) +{ + +} + +CSkin::CSkin(CSkin && s) noexcept + : m_ID(s.m_ID) + , m_Name(s.m_Name) + , m_Tag(s.m_Tag) + , m_Data(s.m_Data) +{ + +} + +// ------------------------------------------------------------------------------------------------ +CSkin::~CSkin() +{ + +} + +// ------------------------------------------------------------------------------------------------ +CSkin & CSkin::operator = (const CSkin & s) noexcept +{ + m_ID = s.m_ID; + m_Name = s.m_Name; + m_Tag = s.m_Tag; + m_Data = s.m_Data; + + return *this; +} + +CSkin & CSkin::operator = (CSkin && s) noexcept +{ + m_ID = s.m_ID; + m_Name = s.m_Name; + m_Tag = s.m_Tag; + m_Data = s.m_Data; + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +CSkin & CSkin::operator = (SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetSkinName(id); + m_ID = id; + } + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +bool CSkin::operator == (const CSkin & s) const noexcept +{ + return (m_ID == s.m_ID); +} + +bool CSkin::operator != (const CSkin & s) const noexcept +{ + return (m_ID != s.m_ID); +} + +bool CSkin::operator < (const CSkin & s) const noexcept +{ + return (m_ID < s.m_ID); +} + +bool CSkin::operator > (const CSkin & s) const noexcept +{ + return (m_ID < s.m_ID); +} + +bool CSkin::operator <= (const CSkin & s) const noexcept +{ + return (m_ID <= s.m_ID); +} + +bool CSkin::operator >= (const CSkin & s) const noexcept +{ + return (m_ID >= s.m_ID); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CSkin::Cmp(const CSkin & s) const noexcept +{ + return m_ID == s.m_ID ? 0 : (m_ID > s.m_ID ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CSkin::GetID() const noexcept +{ + return m_ID; +} + +void CSkin::SetID(SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetSkinName(id); + m_ID = id; + } +} + +// ------------------------------------------------------------------------------------------------ +CSkin & CSkin::SetnGet(SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetSkinName(id); + m_ID = id; + } + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CSkin::GetGlobalTag() const noexcept +{ + return GlobalTag(m_ID); +} + +void CSkin::SetGlobalTag(const SQChar * tag) const noexcept +{ + GlobalTag(m_ID, tag); +} + +// ------------------------------------------------------------------------------------------------ +SqObj & CSkin::GetGlobalData() const noexcept +{ + return GlobalData(m_ID); +} + +void CSkin::SetGlobalData(SqObj & data) const noexcept +{ + GlobalData(m_ID, data); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CSkin::GetLocalTag() const noexcept +{ + return m_Tag.c_str(); +} + +void CSkin::SetLocalTag(const SQChar * tag) noexcept +{ + m_Tag = tag; +} + +// ------------------------------------------------------------------------------------------------ +SqObj & CSkin::GetLocalData() noexcept +{ + return m_Data; +} + +void CSkin::SetLocalData(SqObj & data) noexcept +{ + m_Data = data; +} + +// ------------------------------------------------------------------------------------------------ +bool CSkin::IsValid() const noexcept +{ + return (m_ID > 0); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CSkin::GetName() const noexcept +{ + return m_Name.c_str(); +} + +// ------------------------------------------------------------------------------------------------ +void CSkin::SetName(const SQChar * name) noexcept +{ + m_ID = GetSkinID(name); + m_Name = GetSkinName(m_ID); +} + +// ------------------------------------------------------------------------------------------------ +void CSkin::Apply(const Reference< CPlayer > & player) const noexcept +{ + if (player) + { + _Func->SetPlayerSkin(player, m_ID); + } + else if (!player) + { + LogErr(_SC("Attempting to using an invalid argument: {0:d}"), _SCI32(player)); + } + else + { + LogErr(_SC("Attempting to using an invalid instance: {0:d}"), m_ID); + } +} + +// ================================================================================================ +bool Register_CSkin(HSQUIRRELVM vm) +{ + // Output debugging information + LogDbg("Beginning registration of type"); + // Attempt to register the specified type + Sqrat::RootTable(vm).Bind(_SC("CSkin"), Sqrat::Class< CSkin >(vm, _SC("CSkin")) + .Ctor() + .Ctor< SQInt32 >() + .Ctor< const SQChar *, SQInt32 >() + + .Func(_SC("_cmp"), &CSkin::Cmp) + + .Prop(_SC("id"), &CSkin::GetID, &CSkin::SetID) + .Prop(_SC("gtag"), &CSkin::GetGlobalTag, &CSkin::SetGlobalTag) + .Prop(_SC("gdata"), &CSkin::GetGlobalData, &CSkin::SetGlobalData) + .Prop(_SC("ltag"), &CSkin::GetLocalTag, &CSkin::SetLocalTag) + .Prop(_SC("ldata"), &CSkin::GetLocalData, &CSkin::SetLocalData) + .Prop(_SC("valid"), &CSkin::IsValid) + .Prop(_SC("name"), &CSkin::GetName, &CSkin::SetName) + + .Func(_SC("setng"), &CSkin::SetnGet) + + .Func(_SC("apply"), &CSkin::Apply) + ); + // Output debugging information + LogDbg("Registration of type was successful"); + // Registration succeeded + return true; +} + +} // Namespace:: SqMod diff --git a/source/Misc/Skin.hpp b/source/Misc/Skin.hpp new file mode 100644 index 00000000..1f758b5a --- /dev/null +++ b/source/Misc/Skin.hpp @@ -0,0 +1,82 @@ +#ifndef _MISC_SKIN_HPP_ +#define _MISC_SKIN_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Shared.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +class CSkin : public IdentifierStorage< CSkin, SQMOD_SKINID_CAP > +{ +public: + // -------------------------------------------------------------------------------------------- + static const CSkin NIL; + // -------------------------------------------------------------------------------------------- + CSkin() noexcept; + CSkin(SQInt32 id) noexcept; + CSkin(const SQChar * name, SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CSkin(const CSkin & s) noexcept; + CSkin(CSkin && s) noexcept; + // -------------------------------------------------------------------------------------------- + ~CSkin() noexcept; + // -------------------------------------------------------------------------------------------- + CSkin & operator = (const CSkin & s) noexcept; + CSkin & operator = (CSkin && s) noexcept; + // -------------------------------------------------------------------------------------------- + CSkin & operator = (SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const CSkin & s) const noexcept; + bool operator != (const CSkin & s) const noexcept; + bool operator < (const CSkin & s) const noexcept; + bool operator > (const CSkin & s) const noexcept; + bool operator <= (const CSkin & s) const noexcept; + bool operator >= (const CSkin & s) const noexcept; + // -------------------------------------------------------------------------------------------- + operator SQInt32 () const noexcept { return m_ID; } + operator bool () const noexcept { return IsSkinValid(m_ID); } + // -------------------------------------------------------------------------------------------- + bool operator ! () const noexcept { return !IsSkinValid(m_ID); } + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CSkin & s) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger GetID() const noexcept; + void SetID(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CSkin & SetnGet(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetGlobalTag() const noexcept; + void SetGlobalTag(const SQChar * tag) const noexcept; + // -------------------------------------------------------------------------------------------- + SqObj & GetGlobalData() const noexcept; + void SetGlobalData(SqObj & data) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetLocalTag() const noexcept; + void SetLocalTag(const SQChar * tag) noexcept; + // -------------------------------------------------------------------------------------------- + SqObj & GetLocalData() noexcept; + void SetLocalData(SqObj & data) noexcept; + // -------------------------------------------------------------------------------------------- + bool IsValid() const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetName() const noexcept; + void SetName(const SQChar * name) noexcept; + // -------------------------------------------------------------------------------------------- + void Apply(const Reference< CPlayer > & player) const noexcept; +private: + // -------------------------------------------------------------------------------------------- + SQInt32 m_ID; + // -------------------------------------------------------------------------------------------- + String m_Name; + // -------------------------------------------------------------------------------------------- + SqTag m_Tag; + SqObj m_Data; +}; + +} // Namespace:: SqMod + +#endif // _MISC_SKIN_HPP_ diff --git a/source/Misc/Sound.cpp b/source/Misc/Sound.cpp new file mode 100644 index 00000000..42901fd9 --- /dev/null +++ b/source/Misc/Sound.cpp @@ -0,0 +1,12 @@ +#include "Misc/Sound.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CSound(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Misc/Sound.hpp b/source/Misc/Sound.hpp new file mode 100644 index 00000000..e1c649ce --- /dev/null +++ b/source/Misc/Sound.hpp @@ -0,0 +1,54 @@ +#ifndef _MISC_SOUND_HPP_ +#define _MISC_SOUND_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +class CSound +{ +public: + // -------------------------------------------------------------------------------------------- + CSound() noexcept; + CSound(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CSound(const CSound & x) noexcept; + CSound(CSound && x) noexcept; + // -------------------------------------------------------------------------------------------- + ~CSound(); + // -------------------------------------------------------------------------------------------- + CSound & operator= (const CSound & x) noexcept; + CSound & operator= (CSound && x) noexcept; + // -------------------------------------------------------------------------------------------- + CSound operator+ (const CSound & x) const noexcept; + CSound operator- (const CSound & x) const noexcept; + CSound operator* (const CSound & x) const noexcept; + CSound operator/ (const CSound & x) const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const CSound & x) const noexcept; + bool operator != (const CSound & x) const noexcept; + bool operator < (const CSound & x) const noexcept; + bool operator > (const CSound & x) const noexcept; + bool operator <= (const CSound & x) const noexcept; + bool operator >= (const CSound & x) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CSound & x) const noexcept; + // -------------------------------------------------------------------------------------------- + operator SQInt32 () const noexcept; + operator bool () const noexcept; + // -------------------------------------------------------------------------------------------- + SQInt32 GetID() const noexcept; + void SetID(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + void Play() const noexcept; +protected: + // -------------------------------------------------------------------------------------------- + SQInt32 m_ID; +}; + +} // Namespace:: SqMod + +#endif // _MISC_SOUND_HPP_ \ No newline at end of file diff --git a/source/Misc/VehicleImmunity.cpp b/source/Misc/VehicleImmunity.cpp new file mode 100644 index 00000000..4c8c1ded --- /dev/null +++ b/source/Misc/VehicleImmunity.cpp @@ -0,0 +1,12 @@ +#include "Misc/VehicleImmunity.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CVehicleImmunity(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Misc/VehicleImmunity.hpp b/source/Misc/VehicleImmunity.hpp new file mode 100644 index 00000000..15da0d58 --- /dev/null +++ b/source/Misc/VehicleImmunity.hpp @@ -0,0 +1,53 @@ +#ifndef _MISC_VEHICLE_IMMUNITY_HPP_ +#define _MISC_VEHICLE_IMMUNITY_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +struct CVehicleImmunity +{ + // -------------------------------------------------------------------------------------------- + CVehicleImmunity() noexcept; + CVehicleImmunity(SQInt32 flags) noexcept; + // -------------------------------------------------------------------------------------------- + CVehicleImmunity(const CVehicleImmunity & x) noexcept; + CVehicleImmunity(CVehicleImmunity && x) noexcept; + // -------------------------------------------------------------------------------------------- + ~CVehicleImmunity(); + // -------------------------------------------------------------------------------------------- + CVehicleImmunity & operator= (const CVehicleImmunity & x) noexcept; + CVehicleImmunity & operator= (CVehicleImmunity && x) noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const CVehicleImmunity & x) const noexcept; + bool operator != (const CVehicleImmunity & x) const noexcept; + bool operator < (const CVehicleImmunity & x) const noexcept; + bool operator > (const CVehicleImmunity & x) const noexcept; + bool operator <= (const CVehicleImmunity & x) const noexcept; + bool operator >= (const CVehicleImmunity & x) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CVehicleImmunity & x) const noexcept; + // -------------------------------------------------------------------------------------------- + operator SQInt32 () const noexcept; + operator bool () const noexcept; + // -------------------------------------------------------------------------------------------- + SQInt32 GetFlags() const noexcept; + void SetFlags(SQInt32 flags) noexcept; + // -------------------------------------------------------------------------------------------- + CVehicleImmunity & SetnGet(SQInt32 flags) noexcept; + // -------------------------------------------------------------------------------------------- + void Apply(const CVehicle & vehicle) const noexcept; + // -------------------------------------------------------------------------------------------- + void EnableAll() noexcept; + void DisableAll() noexcept; +protected: + // -------------------------------------------------------------------------------------------- + SQInt32 m_Flags; +}; + +} // Namespace:: SqMod + +#endif // _MISC_VEHICLE_IMMUNITY_HPP_ \ No newline at end of file diff --git a/source/Misc/WastedSettings.cpp b/source/Misc/WastedSettings.cpp new file mode 100644 index 00000000..a3b33306 --- /dev/null +++ b/source/Misc/WastedSettings.cpp @@ -0,0 +1,12 @@ +#include "Misc/WastedSettings.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CWastedSettings(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Misc/WastedSettings.hpp b/source/Misc/WastedSettings.hpp new file mode 100644 index 00000000..1da677d0 --- /dev/null +++ b/source/Misc/WastedSettings.hpp @@ -0,0 +1,51 @@ +#ifndef _MISC_WASTED_SETTINGS_HPP_ +#define _MISC_WASTED_SETTINGS_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" +#include "Base/Color3.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +struct CWastedSettings +{ + // -------------------------------------------------------------------------------------------- + typedef SQUnsignedInteger32 U32; + typedef SQFloat F32; + // -------------------------------------------------------------------------------------------- + U32 DeathTimer, FadeTimer; + F32 FadeInSpeed, FadeOutSpeed; + Color3 FadeColor; + U32 CorpseFadeStart, CorpseFadeTime; + // -------------------------------------------------------------------------------------------- + CWastedSettings() noexcept; + CWastedSettings(U32 dt, U32 ft, F32 fis, F32 fos, const Color3 & fc, U32 cfs, U32 cft) noexcept; + // -------------------------------------------------------------------------------------------- + CWastedSettings(const CWastedSettings & x) noexcept; + CWastedSettings(CWastedSettings && x) noexcept; + // -------------------------------------------------------------------------------------------- + ~CWastedSettings(); + // -------------------------------------------------------------------------------------------- + CWastedSettings & operator= (const CWastedSettings & x) noexcept; + CWastedSettings & operator= (CWastedSettings && x) noexcept; + // -------------------------------------------------------------------------------------------- + CWastedSettings operator+ (const CWastedSettings & x) const noexcept; + CWastedSettings operator- (const CWastedSettings & x) const noexcept; + CWastedSettings operator* (const CWastedSettings & x) const noexcept; + CWastedSettings operator/ (const CWastedSettings & x) const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator== (const CWastedSettings & x) const noexcept; + bool operator!= (const CWastedSettings & x) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CWastedSettings & x) const noexcept; + // -------------------------------------------------------------------------------------------- + void Set() const noexcept; + void Get() const noexcept; +}; + + +} // Namespace:: SqMod + +#endif // _MISC_WASTED_SETTINGS_HPP_ \ No newline at end of file diff --git a/source/Misc/Weapon.cpp b/source/Misc/Weapon.cpp new file mode 100644 index 00000000..7f6e3b06 --- /dev/null +++ b/source/Misc/Weapon.cpp @@ -0,0 +1,377 @@ +#include "Misc/Weapon.hpp" +#include "Entity.hpp" +#include "Register.hpp" +#include "Core.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +const CWeapon CWeapon::NIL = CWeapon(); + +// ------------------------------------------------------------------------------------------------ +CWeapon::CWeapon() noexcept + : m_ID(SQMOD_UNKNOWN), m_Ammo(0), m_Name() +{ + +} + +CWeapon::CWeapon(SQInt32 id) noexcept + : CWeapon(id, 0) +{ + +} + +CWeapon::CWeapon(SQInt32 id, SQInt32 ammo) noexcept + : m_ID(VALID_ENTITYGETEX(id, Max)), m_Ammo(ammo), m_Name(GetWeaponName(id)) +{ + +} + +CWeapon::CWeapon(const SQChar * name, SQInt32 id, SQInt32 ammo) noexcept + : CWeapon((IsWeaponValid(GetWeaponID(name)) ? GetWeaponID(name) : id), ammo) +{ + +} + +// ------------------------------------------------------------------------------------------------ +CWeapon::CWeapon(const CWeapon & w) noexcept + : m_ID(w.m_ID) + , m_Ammo(w.m_Ammo) + , m_Name(w.m_Name) + , m_Tag(w.m_Tag) + , m_Data(w.m_Data) +{ + +} + +CWeapon::CWeapon(CWeapon && w) noexcept + : m_ID(w.m_ID) + , m_Ammo(w.m_Ammo) + , m_Name(w.m_Name) + , m_Tag(w.m_Tag) + , m_Data(w.m_Data) +{ + +} + +// ------------------------------------------------------------------------------------------------ +CWeapon::~CWeapon() +{ + +} + +// ------------------------------------------------------------------------------------------------ +CWeapon & CWeapon::operator = (const CWeapon & w) noexcept +{ + m_ID = w.m_ID; + m_Ammo = w.m_Ammo; + m_Name = w.m_Name; + m_Tag = w.m_Tag; + m_Data = w.m_Data; + + return *this; +} + +CWeapon & CWeapon::operator = (CWeapon && w) noexcept +{ + m_ID = w.m_ID; + m_Ammo = w.m_Ammo; + m_Name = w.m_Name; + m_Tag = w.m_Tag; + m_Data = w.m_Data; + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +CWeapon & CWeapon::operator = (SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetWeaponName(id); + m_ID = id; + } + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +bool CWeapon::operator == (const CWeapon & w) const noexcept +{ + return (m_ID == w.m_ID); +} + +bool CWeapon::operator != (const CWeapon & w) const noexcept +{ + return (m_ID != w.m_ID); +} + +bool CWeapon::operator < (const CWeapon & w) const noexcept +{ + return (m_ID < w.m_ID); +} + +bool CWeapon::operator > (const CWeapon & w) const noexcept +{ + return (m_ID < w.m_ID); +} + +bool CWeapon::operator <= (const CWeapon & w) const noexcept +{ + return (m_ID <= w.m_ID); +} + +bool CWeapon::operator >= (const CWeapon & w) const noexcept +{ + return (m_ID >= w.m_ID); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CWeapon::Cmp(const CWeapon & w) const noexcept +{ + return m_ID == w.m_ID ? 0 : (m_ID > w.m_ID ? 1 : -1); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CWeapon::ToString() const noexcept +{ + return m_Name.c_str(); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CWeapon::GetID() const noexcept +{ + return m_ID; +} + +void CWeapon::SetID(SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetWeaponName(id); + m_ID = id; + } +} + +// ------------------------------------------------------------------------------------------------ +CWeapon & CWeapon::SetnGet(SQInt32 id) noexcept +{ + if (m_ID != id) + { + m_Name = GetWeaponName(id); + m_ID = id; + } + + return *this; +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CWeapon::GetGlobalTag() const noexcept +{ + return GlobalTag(m_ID); +} + +void CWeapon::SetGlobalTag(const SQChar * tag) const noexcept +{ + GlobalTag(m_ID, tag); +} + +// ------------------------------------------------------------------------------------------------ +SqObj & CWeapon::GetGlobalData() const noexcept +{ + return GlobalData(m_ID); +} + +void CWeapon::SetGlobalData(SqObj & data) const noexcept +{ + GlobalData(m_ID, data); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CWeapon::GetLocalTag() const noexcept +{ + return m_Tag.c_str(); +} + +void CWeapon::SetLocalTag(const SQChar * tag) noexcept +{ + m_Tag = tag; +} + +// ------------------------------------------------------------------------------------------------ +SqObj & CWeapon::GetLocalData() noexcept +{ + return m_Data; +} + +void CWeapon::SetLocalData(SqObj & data) noexcept +{ + m_Data = data; +} + +// ------------------------------------------------------------------------------------------------ +bool CWeapon::IsValid() const noexcept +{ + return (m_ID > 0); +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CWeapon::GetName() const noexcept +{ + return m_Name.c_str(); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CWeapon::GetAmmo() const noexcept +{ + return m_Ammo; +} + +void CWeapon::SetAmmo(SQInt32 amount) noexcept +{ + m_Ammo = amount; +} + +// ------------------------------------------------------------------------------------------------ +bool CWeapon::IsNatural() const noexcept +{ + return IsWeaponNatural(m_ID); +} + +// ------------------------------------------------------------------------------------------------ +SQFloat CWeapon::GetDataValue(SQInt32 field) const noexcept +{ + return _Func->GetWeaponDataValue(m_ID, field); +} + +void CWeapon::SetDataValue(SQInt32 field, SQFloat value) const noexcept +{ + _Func->SetWeaponDataValue(m_ID, field, value); +} + +// ------------------------------------------------------------------------------------------------ +void CWeapon::ResetData() const noexcept +{ + _Func->ResetWeaponData(m_ID); +} + +void CWeapon::ResetData(SQInt32 field) const noexcept +{ + _Func->ResetWeaponDataValue(m_ID, field); +} + +// ------------------------------------------------------------------------------------------------ +bool CWeapon::IsDataModified(SQInt32 field) const noexcept +{ + return _Func->IsWeaponDataValueModified(m_ID, field); +} + +// ------------------------------------------------------------------------------------------------ +void CWeapon::SetOn(const Reference< CPlayer > & player) const noexcept +{ + if (*this && player) + { + _Func->SetPlayerWeapon(player, m_ID, m_Ammo); + } + else if (!player) + { + LogErr(_SC("Attempting to using an invalid argument: %d"), _SCI32(player)); + } + else + { + LogErr(_SC("Attempting to using an invalid instance: %d"), m_ID); + } +} + +void CWeapon::GiveTo(const Reference< CPlayer > & player) const noexcept +{ + if (*this && player) + { + _Func->GivePlayerWeapon(player, m_ID, m_Ammo); + } + else if (!player) + { + LogErr(_SC("Attempting to using an invalid argument: %d"), _SCI32(player)); + } + else + { + LogErr(_SC("Attempting to using an invalid instance: %d"), m_ID); + } +} + +void CWeapon::SetOn(const Reference< CPlayer > & player, SQInt32 ammo) const noexcept +{ + if (*this && player) + { + _Func->SetPlayerWeapon(player, m_ID, ammo); + } + else if (!player) + { + LogErr(_SC("Attempting to using an invalid argument: %d"), _SCI32(player)); + } + else + { + LogErr(_SC("Attempting to using an invalid instance: %d"), m_ID); + } +} + +void CWeapon::GiveTo(const Reference< CPlayer > & player, SQInt32 ammo) const noexcept +{ + if (*this && player) + { + _Func->GivePlayerWeapon(player, m_ID, ammo); + } + else if (!player) + { + LogErr(_SC("Attempting to using an invalid argument: %d"), _SCI32(player)); + } + else + { + LogErr(_SC("Attempting to using an invalid instance: %d"), m_ID); + } +} + +// ================================================================================================ +bool Register_CWeapon(HSQUIRRELVM vm) +{ + // Output debugging information + LogDbg("Beginning registration of type"); + // Attempt to register the specified type + Sqrat::RootTable(vm).Bind(_SC("CWeapon"), Sqrat::Class< CWeapon >(vm, _SC("CWeapon")) + .Ctor() + .Ctor< SQInt32 >() + .Ctor< SQInt32, SQInt32 >() + .Ctor< const SQChar *, SQInt32, SQInt32 >() + + .Func(_SC("_cmp"), &CWeapon::Cmp) + + .Prop(_SC("id"), &CWeapon::GetID, &CWeapon::SetID) + .Prop(_SC("gtag"), &CWeapon::GetGlobalTag, &CWeapon::SetGlobalTag) + .Prop(_SC("gdata"), &CWeapon::GetGlobalData, &CWeapon::SetGlobalData) + .Prop(_SC("ltag"), &CWeapon::GetLocalTag, &CWeapon::SetLocalTag) + .Prop(_SC("ldata"), &CWeapon::GetLocalData, &CWeapon::SetLocalData) + .Prop(_SC("valid"), &CWeapon::IsValid) + .Prop(_SC("name"), &CWeapon::GetName) + .Prop(_SC("ammo"), &CWeapon::GetAmmo, &CWeapon::SetAmmo) + .Prop(_SC("natural"), &CWeapon::IsNatural) + + .Func(_SC("setng"), &CWeapon::SetnGet) + .Func(_SC("get_value"), &CWeapon::GetDataValue) + .Func(_SC("set_value"), &CWeapon::SetDataValue) + .Func(_SC("is_modified"), &CWeapon::IsDataModified) + + .Overload< void (CWeapon::*)(void) const >(_SC("reset_data"), &CWeapon::ResetData) + .Overload< void (CWeapon::*)(SQInt32) const >(_SC("reset_data"), &CWeapon::ResetData) + .Overload< void (CWeapon::*)(const Reference< CPlayer > &) const >(_SC("set_on"), &CWeapon::SetOn) + .Overload< void (CWeapon::*)(const Reference< CPlayer > &, SQInt32) const >(_SC("set_on"), &CWeapon::SetOn) + .Overload< void (CWeapon::*)(const Reference< CPlayer > &) const >(_SC("give_to"), &CWeapon::GiveTo) + .Overload< void (CWeapon::*)(const Reference< CPlayer > &, SQInt32) const >(_SC("give_to"), &CWeapon::GiveTo) + ); + // Output debugging information + LogDbg("Registration of type was successful"); + // Registration succeeded + return true; +} + +} // Namespace:: SqMod diff --git a/source/Misc/Weapon.hpp b/source/Misc/Weapon.hpp new file mode 100644 index 00000000..a12939c8 --- /dev/null +++ b/source/Misc/Weapon.hpp @@ -0,0 +1,99 @@ +#ifndef _MISC_WEAPON_HPP_ +#define _MISC_WEAPON_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Shared.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +class CWeapon : public IdentifierStorage< CWeapon, SQMOD_WEAPONID_CAP > +{ +public: + // -------------------------------------------------------------------------------------------- + static const CWeapon NIL; + // -------------------------------------------------------------------------------------------- + CWeapon() noexcept; + CWeapon(SQInt32 id) noexcept; + CWeapon(SQInt32 id, SQInt32 ammo) noexcept; + CWeapon(const SQChar * name, SQInt32 id, SQInt32 ammo) noexcept; + // -------------------------------------------------------------------------------------------- + CWeapon(const CWeapon & w) noexcept; + CWeapon(CWeapon && w) noexcept; + // -------------------------------------------------------------------------------------------- + ~CWeapon() noexcept; + // -------------------------------------------------------------------------------------------- + CWeapon & operator = (const CWeapon & w) noexcept; + CWeapon & operator = (CWeapon && w) noexcept; + // -------------------------------------------------------------------------------------------- + CWeapon & operator = (SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + bool operator == (const CWeapon & w) const noexcept; + bool operator != (const CWeapon & w) const noexcept; + bool operator < (const CWeapon & w) const noexcept; + bool operator > (const CWeapon & w) const noexcept; + bool operator <= (const CWeapon & w) const noexcept; + bool operator >= (const CWeapon & w) const noexcept; + // -------------------------------------------------------------------------------------------- + operator SQInt32 () const noexcept { return m_ID; } + operator bool () const noexcept { return IsWeaponValid(m_ID); } + // -------------------------------------------------------------------------------------------- + bool operator ! () const noexcept { return !IsWeaponValid(m_ID); } + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CWeapon & w) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * ToString() const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger GetID() const noexcept; + void SetID(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + CWeapon & SetnGet(SQInt32 id) noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetGlobalTag() const noexcept; + void SetGlobalTag(const SQChar * tag) const noexcept; + // -------------------------------------------------------------------------------------------- + SqObj & GetGlobalData() const noexcept; + void SetGlobalData(SqObj & data) const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetLocalTag() const noexcept; + void SetLocalTag(const SQChar * tag) noexcept; + // -------------------------------------------------------------------------------------------- + SqObj & GetLocalData() noexcept; + void SetLocalData(SqObj & data) noexcept; + // -------------------------------------------------------------------------------------------- + bool IsValid() const noexcept; + // -------------------------------------------------------------------------------------------- + const SQChar * GetName() const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger GetAmmo() const noexcept; + void SetAmmo(SQInt32 amount) noexcept; + // -------------------------------------------------------------------------------------------- + bool IsNatural() const noexcept; + // -------------------------------------------------------------------------------------------- + SQFloat GetDataValue(SQInt32 field) const noexcept; + void SetDataValue(SQInt32 field, SQFloat value) const noexcept; + // -------------------------------------------------------------------------------------------- + void ResetData() const noexcept; + void ResetData(SQInt32 field) const noexcept; + // -------------------------------------------------------------------------------------------- + bool IsDataModified(SQInt32 field) const noexcept; + // -------------------------------------------------------------------------------------------- + void SetOn(const Reference< CPlayer > & player) const noexcept; + void GiveTo(const Reference< CPlayer > & player) const noexcept; + void SetOn(const Reference< CPlayer > & player, SQInt32 ammo) const noexcept; + void GiveTo(const Reference< CPlayer > & player, SQInt32 ammo) const noexcept; +private: + // -------------------------------------------------------------------------------------------- + SQInt32 m_ID; + SQInt32 m_Ammo; + // -------------------------------------------------------------------------------------------- + String m_Name; + // -------------------------------------------------------------------------------------------- + SqTag m_Tag; + SqObj m_Data; +}; + +} // Namespace:: SqMod + +#endif // _MISC_WEAPON_HPP_ diff --git a/source/Misc/WorldBounds.cpp b/source/Misc/WorldBounds.cpp new file mode 100644 index 00000000..23e8c8c3 --- /dev/null +++ b/source/Misc/WorldBounds.cpp @@ -0,0 +1,12 @@ +#include "Misc/WorldBounds.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +bool Register_CWorldBounds(HSQUIRRELVM vm) +{ + return true; +} + +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Misc/WorldBounds.hpp b/source/Misc/WorldBounds.hpp new file mode 100644 index 00000000..6668dada --- /dev/null +++ b/source/Misc/WorldBounds.hpp @@ -0,0 +1,46 @@ +#ifndef _MISC_WORLD_BOUNDS_HPP_ +#define _MISC_WORLD_BOUNDS_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include "Common.hpp" +#include "Base/Vector2f.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +struct CWorldBounds +{ + // -------------------------------------------------------------------------------------------- + Vector2f min, max; + // -------------------------------------------------------------------------------------------- + CWorldBounds() noexcept; + CWorldBounds(const Vector2f & vec) noexcept; + CWorldBounds(const Vector2f & min, const Vector2f & max) noexcept; + // -------------------------------------------------------------------------------------------- + CWorldBounds(const CWorldBounds & x) noexcept; + CWorldBounds(CWorldBounds && x) noexcept; + // -------------------------------------------------------------------------------------------- + ~CWorldBounds(); + // -------------------------------------------------------------------------------------------- + CWorldBounds & operator= (const CWorldBounds & x) noexcept; + CWorldBounds & operator= (CWorldBounds && x) noexcept; + // -------------------------------------------------------------------------------------------- + CWorldBounds operator+ (const CWorldBounds & x) const noexcept; + CWorldBounds operator- (const CWorldBounds & x) const noexcept; + CWorldBounds operator* (const CWorldBounds & x) const noexcept; + CWorldBounds operator/ (const CWorldBounds & x) const noexcept; + // -------------------------------------------------------------------------------------------- + bool operator== (const CWorldBounds & x) const noexcept; + bool operator!= (const CWorldBounds & x) const noexcept; + // -------------------------------------------------------------------------------------------- + SQInteger Cmp(const CWorldBounds & x) const noexcept; + // -------------------------------------------------------------------------------------------- + void Set() const noexcept; + void Get() const noexcept; +}; + + +} // Namespace:: SqMod + +#endif // _MISC_WORLD_BOUNDS_HPP_ \ No newline at end of file diff --git a/source/Register.cpp b/source/Register.cpp new file mode 100644 index 00000000..1e0ae0b5 --- /dev/null +++ b/source/Register.cpp @@ -0,0 +1,78 @@ +#include "Register.hpp" +#include "Logger.hpp" + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +/* Snippet for registering a class in a single statement. + + Sqrat::RootTable(vm).Bind(_SC("CLSNAME"), Sqrat::Class(vm, _SC("CLSNAME")) + + ); +*/ + +// ------------------------------------------------------------------------------------------------ +bool RegisterAPI(HSQUIRRELVM vm) noexcept +{ + if (_Log->cFtl(!Register_AABB(vm), "Unable to register: AABB") || \ + _Log->cFtl(!Register_Circle(vm), "Unable to register: Circle") || \ + _Log->cFtl(!Register_Color3(vm), "Unable to register: Color3") || \ + _Log->cFtl(!Register_Color4(vm), "Unable to register: Color4") || \ + _Log->cFtl(!Register_Quaternion(vm), "Unable to register: Quaternion") || \ + _Log->cFtl(!Register_Sphere(vm), "Unable to register: Sphere") || \ + _Log->cFtl(!Register_Vector2f(vm), "Unable to register: Vector2f") || \ + _Log->cFtl(!Register_Vector2i(vm), "Unable to register: Vector2i") || \ + _Log->cFtl(!Register_Vector2u(vm), "Unable to register: Vector2u") || \ + _Log->cFtl(!Register_Vector3(vm), "Unable to register: Vector3") || \ + _Log->cFtl(!Register_Vector4(vm), "Unable to register: Vector4") || \ + _Log->cFtl(!Register_Base(vm), "Unable to register: Base") || \ + + _Log->cFtl(!Register_CBlip(vm), "Unable to register: Blip") || \ + _Log->cFtl(!Register_CCheckpoint(vm), "Unable to register: Checkpoint") || \ + _Log->cFtl(!Register_CKeybind(vm), "Unable to register: Keybind") || \ + _Log->cFtl(!Register_CObject(vm), "Unable to register: Object") || \ + _Log->cFtl(!Register_CPickup(vm), "Unable to register: Pickup") || \ + _Log->cFtl(!Register_CPlayer(vm), "Unable to register: Player") || \ + _Log->cFtl(!Register_CSphere(vm), "Unable to register: Sphere") || \ + _Log->cFtl(!Register_CSprite(vm), "Unable to register: Sprite") || \ + _Log->cFtl(!Register_CTextdraw(vm), "Unable to register: Textdraw") || \ + _Log->cFtl(!Register_CVehicle(vm), "Unable to register: Vehicle") || \ + _Log->cFtl(!Register_Entity(vm), "Unable to register: Entity") || \ + + _Log->cFtl(!Register_CFG(vm), "Unable to register: CFG") || \ + _Log->cFtl(!Register_Datetime(vm), "Unable to register: Datetime") || \ + _Log->cFtl(!Register_FileIO(vm), "Unable to register: FileIO") || \ + _Log->cFtl(!Register_Format(vm), "Unable to register: Format") || \ + _Log->cFtl(!Register_INI(vm), "Unable to register: INI") || \ + _Log->cFtl(!Register_JSON(vm), "Unable to register: JSON") || \ + _Log->cFtl(!Register_LongInt(vm), "Unable to register: LongInt") || \ + _Log->cFtl(!Register_Math(vm), "Unable to register: Math") || \ + _Log->cFtl(!Register_Numeric(vm), "Unable to register: Numeric") || \ + _Log->cFtl(!Register_String(vm), "Unable to register: String") || \ + _Log->cFtl(!Register_SysPath(vm), "Unable to register: SysPath") || \ + _Log->cFtl(!Register_System(vm), "Unable to register: System") || \ + _Log->cFtl(!Register_Timer(vm), "Unable to register: Timer") || \ + _Log->cFtl(!Register_Utils(vm), "Unable to register: Utils") || \ + _Log->cFtl(!Register_XML(vm), "Unable to register: XML") || \ + _Log->cFtl(!Register_Library(vm), "Unable to register: Library") || \ + + _Log->cFtl(!Register_CAutomobile(vm), "Unable to register: CAutomobile") || \ + _Log->cFtl(!Register_Constants(vm), "Unable to register: Functions") || \ + _Log->cFtl(!Register_Functions(vm), "Unable to register: Functions") || \ + _Log->cFtl(!Register_CModel(vm), "Unable to register: CModel") || \ + _Log->cFtl(!Register_CPlayerImmunity(vm), "Unable to register: CPlayerImmunity") || \ + _Log->cFtl(!Register_CRadio(vm), "Unable to register: CRadio") || \ + _Log->cFtl(!Register_CSkin(vm), "Unable to register: CSkin") || \ + _Log->cFtl(!Register_CSound(vm), "Unable to register: CSound") || \ + _Log->cFtl(!Register_CVehicleImmunity(vm), "Unable to register: CVehicleImmunity") || \ + _Log->cFtl(!Register_CWastedSettings(vm), "Unable to register: CWastedSettings") || \ + _Log->cFtl(!Register_CWeapon(vm), "Unable to register: CWeapon") || \ + _Log->cFtl(!Register_CWorldBounds(vm), "Unable to register: CWorldBounds") || \ + _Log->cFtl(!Register_Misc(vm), "Unable to register: Misc") + ) return false; + + return true; +} + +} // Namespace:: SqMod diff --git a/source/Register.hpp b/source/Register.hpp new file mode 100644 index 00000000..10d68455 --- /dev/null +++ b/source/Register.hpp @@ -0,0 +1,106 @@ +#ifndef _REGISTER_HPP_ +#define _REGISTER_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +using namespace Sqrat; + +// ------------------------------------------------------------------------------------------------ +bool RegisterAPI(HSQUIRRELVM vm) noexcept; + +// ------------------------------------------------------------------------------------------------ +bool Register_AABB(HSQUIRRELVM vm); +bool Register_Circle(HSQUIRRELVM vm); +bool Register_Color3(HSQUIRRELVM vm); +bool Register_Color4(HSQUIRRELVM vm); +bool Register_Quaternion(HSQUIRRELVM vm); +bool Register_Sphere(HSQUIRRELVM vm); +bool Register_Vector2f(HSQUIRRELVM vm); +bool Register_Vector2i(HSQUIRRELVM vm); +bool Register_Vector2u(HSQUIRRELVM vm); +bool Register_Vector3(HSQUIRRELVM vm); +bool Register_Vector4(HSQUIRRELVM vm); +bool Register_Base(HSQUIRRELVM vm); + +// ------------------------------------------------------------------------------------------------ +bool Register_CBlip(HSQUIRRELVM vm); +bool Register_CCheckpoint(HSQUIRRELVM vm); +bool Register_CKeybind(HSQUIRRELVM vm); +bool Register_CObject(HSQUIRRELVM vm); +bool Register_CPickup(HSQUIRRELVM vm); +bool Register_CPlayer(HSQUIRRELVM vm); +bool Register_CSphere(HSQUIRRELVM vm); +bool Register_CSprite(HSQUIRRELVM vm); +bool Register_CTextdraw(HSQUIRRELVM vm); +bool Register_CVehicle(HSQUIRRELVM vm); +bool Register_Entity(HSQUIRRELVM vm); + +// ------------------------------------------------------------------------------------------------ +bool Register_CFG(HSQUIRRELVM vm); +bool Register_Datetime(HSQUIRRELVM vm); +bool Register_FileIO(HSQUIRRELVM vm); +bool Register_Format(HSQUIRRELVM vm); +bool Register_INI(HSQUIRRELVM vm); +bool Register_JSON(HSQUIRRELVM vm); +bool Register_LongInt(HSQUIRRELVM vm); +bool Register_Math(HSQUIRRELVM vm); +bool Register_Numeric(HSQUIRRELVM vm); +bool Register_String(HSQUIRRELVM vm); +bool Register_SysPath(HSQUIRRELVM vm); +bool Register_System(HSQUIRRELVM vm); +bool Register_Timer(HSQUIRRELVM vm); +bool Register_Utils(HSQUIRRELVM vm); +bool Register_XML(HSQUIRRELVM vm); +bool Register_Library(HSQUIRRELVM vm); + +// ------------------------------------------------------------------------------------------------ +bool Register_CAutomobile(HSQUIRRELVM vm); +bool Register_Constants(HSQUIRRELVM vm); +bool Register_Functions(HSQUIRRELVM vm); +bool Register_CModel(HSQUIRRELVM vm); +bool Register_CPlayerImmunity(HSQUIRRELVM vm); +bool Register_CRadio(HSQUIRRELVM vm); +bool Register_CSkin(HSQUIRRELVM vm); +bool Register_CSound(HSQUIRRELVM vm); +bool Register_CVehicleImmunity(HSQUIRRELVM vm); +bool Register_CWastedSettings(HSQUIRRELVM vm); +bool Register_CWeapon(HSQUIRRELVM vm); +bool Register_CWorldBounds(HSQUIRRELVM vm); +bool Register_Misc(HSQUIRRELVM vm); + +// ------------------------------------------------------------------------------------------------ +bool Register_QBlip(HSQUIRRELVM vm); +bool Register_QCheckpoint(HSQUIRRELVM vm); +bool Register_QKeybind(HSQUIRRELVM vm); +bool Register_QObject(HSQUIRRELVM vm); +bool Register_QPickup(HSQUIRRELVM vm); +bool Register_QPlayer(HSQUIRRELVM vm); +bool Register_QSphere(HSQUIRRELVM vm); +bool Register_QSprite(HSQUIRRELVM vm); +bool Register_QTextdraw(HSQUIRRELVM vm); +bool Register_QVehicle(HSQUIRRELVM vm); +bool Register_Queue(HSQUIRRELVM vm); + +// ------------------------------------------------------------------------------------------------ +bool Register_SBlip(HSQUIRRELVM vm); +bool Register_SCheckpoint(HSQUIRRELVM vm); +bool Register_SKeybind(HSQUIRRELVM vm); +bool Register_SObject(HSQUIRRELVM vm); +bool Register_SPickup(HSQUIRRELVM vm); +bool Register_SPlayer(HSQUIRRELVM vm); +bool Register_SSphere(HSQUIRRELVM vm); +bool Register_SSprite(HSQUIRRELVM vm); +bool Register_STextdraw(HSQUIRRELVM vm); +bool Register_Selector(HSQUIRRELVM vm); + +// ------------------------------------------------------------------------------------------------ +bool Register_Utility(HSQUIRRELVM vm); + +} // Namespace:: SqMod + +#endif // _REGISTER_HPP_ diff --git a/source/Signal.hpp b/source/Signal.hpp new file mode 100644 index 00000000..ecc4ca8a --- /dev/null +++ b/source/Signal.hpp @@ -0,0 +1,556 @@ +#ifndef _SIGNALS_HPP_ +#define _SIGNALS_HPP_ + +// ------------------------------------------------------------------------------------------------ +#include + +// ------------------------------------------------------------------------------------------------ +#include + +// ------------------------------------------------------------------------------------------------ +namespace Sqrat +{ + class Object; +} + +// ------------------------------------------------------------------------------------------------ +namespace SqMod { + +// ------------------------------------------------------------------------------------------------ +using namespace Sqrat; + +// ------------------------------------------------------------------------------------------------ +struct Vector3; + +// ------------------------------------------------------------------------------------------------ +template < typename Ret > class SignalImpl; + +// ------------------------------------------------------------------------------------------------ +template < typename Ret, typename... Args > class SignalImpl< Ret (Args...) > +{ +protected: + // -------------------------------------------------------------------------------------------- + using Executor = Ret (*) (void *, Args...); + + // -------------------------------------------------------------------------------------------- + struct Node + { + // ---------------------------------------------------------------------------------------- + Executor m_Exec; + + // ---------------------------------------------------------------------------------------- + void * m_This; + + // ---------------------------------------------------------------------------------------- + Node * m_Next; + + // ---------------------------------------------------------------------------------------- + Node(Executor e, void * t, Node * n) noexcept + : m_Exec(e), m_This(t), m_Next(n) + { + /* ... */ + } + + // ---------------------------------------------------------------------------------------- + Node(const Node &) noexcept = default; + Node(Node &&) noexcept = default; + + // ---------------------------------------------------------------------------------------- + Node & operator = (const Node &) noexcept = default; + Node & operator = (Node &&) noexcept = default; + }; + + // -------------------------------------------------------------------------------------------- + struct Container + { + // ---------------------------------------------------------------------------------------- + Node * m_Head; + + // ---------------------------------------------------------------------------------------- + Container() noexcept : m_Head(0) { /* ... */ } + + Container(Node * n) noexcept : m_Head(n) { /* ... */ } + + // ---------------------------------------------------------------------------------------- + Container(const Container &) noexcept = default; + Container(Container &&) noexcept = default; + + // ---------------------------------------------------------------------------------------- + ~Container() + { + Clear(); + } + + // ---------------------------------------------------------------------------------------- + Container & operator = (const Container &) noexcept = default; + Container & operator = (Container &&) noexcept = default; + + // ---------------------------------------------------------------------------------------- + void Remove(Executor e, void * t) noexcept + { + for (Node * node = m_Head, * prev = 0; node; prev = node, node = node->m_Next) + { + if (node->m_This == t && node->m_Exec == e) + { + if (prev) { + prev->m_Next = node->m_Next; + } else { + m_Head = m_Head->m_Next; + } + delete node; + break; + } + } + } + + // ---------------------------------------------------------------------------------------- + void Clear() + { + for (Node * node = m_Head, * next = 0; node; node = next) + { + next = node->m_Next ? node->m_Next : 0; + delete node; + } + m_Head = 0; + } + }; + + // -------------------------------------------------------------------------------------------- + template < Ret (* FPtr) (Args...) > static inline Executor Free() noexcept + { + return [](void * /* NULL */, Args... args) -> Ret { + return (*FPtr)(std::forward(args)...); + }; + } + + // -------------------------------------------------------------------------------------------- + template < typename T, Ret (T::* MPtr) (Args...) > static inline Executor Member() noexcept + { + return [](void * thisptr, Args... args) -> Ret { + return (static_cast(thisptr)->*MPtr)(std::forward(args)...); + }; + } + + // -------------------------------------------------------------------------------------------- + template < typename T, Ret (T::* MPtr) (Args...) const> static inline Executor Member() noexcept + { + return [](void * thisptr, Args... args) -> Ret { + return (static_cast(thisptr)->*MPtr)(std::forward(args)...); + }; + } + + // -------------------------------------------------------------------------------------------- + template < typename L > static inline Executor Lambda() noexcept + { + return [](void * thisptr, Args... args) -> Ret { + return (static_cast(thisptr)->operator()(std::forward(args)...)); + }; + } + +public: + + // -------------------------------------------------------------------------------------------- + typedef Ret Return; + + // -------------------------------------------------------------------------------------------- + template < Ret (* FPtr) (Args...) > void Connect() noexcept + { + m_Nodes.m_Head = new Node(Free< FPtr >(), 0, m_Nodes.m_Head); + } + + // -------------------------------------------------------------------------------------------- + template < typename T, Ret (T::* MPtr) (Args...) > void Connect(T * ptr) noexcept + { + m_Nodes.m_Head = new Node(Member< T, MPtr >(), ptr, m_Nodes.m_Head); + } + + template < typename T, Ret (T::* MPtr) (Args...) > void Connect(T & ptr) noexcept + { + m_Nodes.m_Head = new Node(Member< T, MPtr >(), std::addressof(ptr), m_Nodes.m_Head); + } + + // -------------------------------------------------------------------------------------------- + template < typename T, Ret (T::* MPtr) (Args...) const > void Connect(T * ptr) noexcept + { + m_Nodes.m_Head = new Node(Member< T, MPtr >(), ptr, m_Nodes.m_Head); + } + + template < typename T, Ret (T::* MPtr) (Args...) const > void Connect(T & ptr) noexcept + { + m_Nodes.m_Head = new Node(Member< T, MPtr >(), std::addressof(ptr), m_Nodes.m_Head); + } + + // -------------------------------------------------------------------------------------------- + template < typename L > void Connect(L * ptr) noexcept + { + m_Nodes.m_Head = new Node(Lambda< L >(), ptr, m_Nodes.m_Head); + } + + template < typename L > void Connect(L & ptr) noexcept + { + m_Nodes.m_Head = new Node(Lambda< L >(), std::addressof(ptr), m_Nodes.m_Head); + } + + // -------------------------------------------------------------------------------------------- + template < Ret (* FPtr) (Args...) > void Disconnect() noexcept + { + m_Nodes.Remove(Free< FPtr >(), 0); + } + + // -------------------------------------------------------------------------------------------- + template < typename T, Ret (T::* MPtr) (Args...) > void Disconnect(T * ptr) noexcept + { + m_Nodes.Remove(Member< T, MPtr >(), ptr); + } + + template < typename T, Ret (T::* MPtr) (Args...) > void Disconnect(T & ptr) noexcept + { + m_Nodes.Remove(Member< T, MPtr >(), std::addressof(ptr)); + } + + // -------------------------------------------------------------------------------------------- + template < typename T, Ret (T::* MPtr) (Args...) const > void Disconnect(T * ptr) noexcept + { + m_Nodes.Remove(Member< T, MPtr >(), ptr); + } + + template < typename T, Ret (T::* MPtr) (Args...) const > void Disconnect(T & ptr) noexcept + { + m_Nodes.Remove(Member< T, MPtr >(), std::addressof(ptr)); + } + + // -------------------------------------------------------------------------------------------- + template < typename L > void Disconnect(L * ptr) noexcept + { + m_Nodes.Remove(Lambda< L >(), ptr); + } + + template < typename L > void Disconnect(L & ptr) noexcept + { + m_Nodes.Remove(Lambda< L >(), std::addressof(ptr)); + } + + // -------------------------------------------------------------------------------------------- + void Clear() noexcept + { + m_Nodes.Clear(); + } + + // -------------------------------------------------------------------------------------------- + void Emit(Args &&... args) + { + for (Node * node = m_Nodes.m_Head; node; node = node->m_Next) + { + (*node->m_Exec)(node->m_This, std::forward(args)...); + } + } + + // -------------------------------------------------------------------------------------------- + template void Query(T && collecter, Args &&... args) + { + for (Node * node = m_Nodes.m_Head; node; node = node->m_Next) + { + collecter( ( (*node->m_Exec) (node->m_This, std::forward(args)...) ) ); + } + } + + // -------------------------------------------------------------------------------------------- + void operator () (Args &&... args) + { + for (Node * node = m_Nodes.m_Head; node; node = node->m_Next) + { + (*node->m_Exec)(node->m_This, std::forward(args)...); + } + } + +private: + + // -------------------------------------------------------------------------------------------- + Container m_Nodes; +}; + +// ------------------------------------------------------------------------------------------------ +template < typename Sig, int I = 0 > class Signal : public SignalImpl< Sig > +{ + static constexpr int SignalID = I; +}; + +// ------------------------------------------------------------------------------------------------ +enum EventType +{ + EVT_UNKNOWN = 0, + EVT_BLIPCREATED, + EVT_CHECKPOINTCREATED, + EVT_KEYBINDCREATED, + EVT_OBJECTCREATED, + EVT_PICKUPCREATED, + EVT_PLAYERCREATED, + EVT_SPHERECREATED, + EVT_SPRITECREATED, + EVT_TEXTDRAWCREATED, + EVT_VEHICLECREATED, + EVT_BLIPDESTROYED, + EVT_CHECKPOINTDESTROYED, + EVT_KEYBINDDESTROYED, + EVT_OBJECTDESTROYED, + EVT_PICKUPDESTROYED, + EVT_PLAYERDESTROYED, + EVT_SPHEREDESTROYED, + EVT_SPRITEDESTROYED, + EVT_TEXTDRAWDESTROYED, + EVT_VEHICLEDESTROYED, + EVT_BLIPCUSTOM, + EVT_CHECKPOINTCUSTOM, + EVT_KEYBINDCUSTOM, + EVT_OBJECTCUSTOM, + EVT_PICKUPCUSTOM, + EVT_PLAYERCUSTOM, + EVT_SPHERECUSTOM, + EVT_SPRITECUSTOM, + EVT_TEXTDRAWCUSTOM, + EVT_VEHICLECUSTOM, + EVT_PLAYERAWAY, + EVT_PLAYERGAMEKEYS, + EVT_PLAYERRENAME, + EVT_PLAYERREQUESTCLASS, + EVT_PLAYERREQUESTSPAWN, + EVT_PLAYERSPAWN, + EVT_PLAYERSTARTTYPING, + EVT_PLAYERSTOPTYPING, + EVT_PLAYERCHAT, + EVT_PLAYERCOMMAND, + EVT_PLAYERMESSAGE, + EVT_PLAYERHEALTH, + EVT_PLAYERARMOUR, + EVT_PLAYERWEAPON, + EVT_PLAYERMOVE, + EVT_PLAYERWASTED, + EVT_PLAYERKILLED, + EVT_PLAYERTEAMKILL, + EVT_PLAYERSPECTATE, + EVT_PLAYERCRASHREPORT, + EVT_PLAYERBURNING, + EVT_PLAYERCROUCHING, + EVT_PLAYERSTATE, + EVT_PLAYERACTION, + EVT_STATENONE, + EVT_STATENORMAL, + EVT_STATESHOOTING, + EVT_STATEDRIVER, + EVT_STATEPASSENGER, + EVT_STATEENTERDRIVER, + EVT_STATEENTERPASSENGER, + EVT_STATEEXITVEHICLE, + EVT_STATEUNSPAWNED, + EVT_ACTIONNONE, + EVT_ACTIONNORMAL, + EVT_ACTIONAIMING, + EVT_ACTIONSHOOTING, + EVT_ACTIONJUMPING, + EVT_ACTIONLIEDOWN, + EVT_ACTIONGETTINGUP, + EVT_ACTIONJUMPVEHICLE, + EVT_ACTIONDRIVING, + EVT_ACTIONDYING, + EVT_ACTIONWASTED, + EVT_ACTIONEMBARKING, + EVT_ACTIONDISEMBARKING, + EVT_VEHICLERESPAWN, + EVT_VEHICLEEXPLODE, + EVT_VEHICLEHEALTH, + EVT_VEHICLEMOVE, + EVT_PICKUPRESPAWN, + EVT_KEYBINDKEYPRESS, + EVT_KEYBINDKEYRELEASE, + EVT_VEHICLEEMBARKING, + EVT_VEHICLEEMBARKED, + EVT_VEHICLEDISEMBARK, + EVT_PICKUPCLAIMED, + EVT_PICKUPCOLLECTED, + EVT_OBJECTSHOT, + EVT_OBJECTBUMP, + EVT_CHECKPOINTENTERED, + EVT_CHECKPOINTEXITED, + EVT_SPHEREENTERED, + EVT_SPHEREEXITED, + EVT_SERVERFRAME, + EVT_SERVERSTARTUP, + EVT_SERVERSHUTDOWN, + EVT_INTERNALCOMMAND, + EVT_LOGINATTEMPT, + EVT_CUSTOMEVENT, + EVT_WORLDOPTION, + EVT_WORLDTOGGLE, + EVT_SCRIPTRELOAD, + EVT_LOGMESSAGE, + EVT_COUNT +}; + +// ------------------------------------------------------------------------------------------------ +using EBlipCreated = Signal< void (SQInt32 /* blip */, SQInt32 /* header */, Object & /* payload */), EVT_BLIPCREATED >; +using ECheckpointCreated = Signal< void (SQInt32 /* checkpoint */, SQInt32 /* header */, Object & /* payload */), EVT_CHECKPOINTCREATED >; +using EKeybindCreated = Signal< void (SQInt32 /* keybind */, SQInt32 /* header */, Object & /* payload */), EVT_KEYBINDCREATED >; +using EObjectCreated = Signal< void (SQInt32 /* object */, SQInt32 /* header */, Object & /* payload */), EVT_OBJECTCREATED >; +using EPickupCreated = Signal< void (SQInt32 /* pickup */, SQInt32 /* header */, Object & /* payload */), EVT_PICKUPCREATED >; +using EPlayerCreated = Signal< void (SQInt32 /* player */, SQInt32 /* header */, Object & /* payload */), EVT_PLAYERCREATED >; +using ESphereCreated = Signal< void (SQInt32 /* sphere */, SQInt32 /* header */, Object & /* payload */), EVT_SPHERECREATED >; +using ESpriteCreated = Signal< void (SQInt32 /* sprite */, SQInt32 /* header */, Object & /* payload */), EVT_SPRITECREATED >; +using ETextdrawCreated = Signal< void (SQInt32 /* textdraw */, SQInt32 /* header */, Object & /* payload */), EVT_TEXTDRAWCREATED >; +using EVehicleCreated = Signal< void (SQInt32 /* vehicle */, SQInt32 /* header */, Object & /* payload */), EVT_VEHICLECREATED >; + +// ------------------------------------------------------------------------------------------------ +using EBlipDestroyed = Signal< void (SQInt32 /* blip */, SQInt32 /* header */, Object & /* payload */), EVT_BLIPDESTROYED >; +using ECheckpointDestroyed = Signal< void (SQInt32 /* checkpoint */, SQInt32 /* header */, Object & /* payload */), EVT_CHECKPOINTDESTROYED >; +using EKeybindDestroyed = Signal< void (SQInt32 /* keybind */, SQInt32 /* header */, Object & /* payload */), EVT_KEYBINDDESTROYED >; +using EObjectDestroyed = Signal< void (SQInt32 /* object */, SQInt32 /* header */, Object & /* payload */), EVT_OBJECTDESTROYED >; +using EPickupDestroyed = Signal< void (SQInt32 /* pickup */, SQInt32 /* header */, Object & /* payload */), EVT_PICKUPDESTROYED >; +using EPlayerDestroyed = Signal< void (SQInt32 /* player */, SQInt32 /* header */, Object & /* payload */), EVT_PLAYERDESTROYED >; +using ESphereDestroyed = Signal< void (SQInt32 /* sphere */, SQInt32 /* header */, Object & /* payload */), EVT_SPHEREDESTROYED >; +using ESpriteDestroyed = Signal< void (SQInt32 /* sprite */, SQInt32 /* header */, Object & /* payload */), EVT_SPRITEDESTROYED >; +using ETextdrawDestroyed = Signal< void (SQInt32 /* textdraw */, SQInt32 /* header */, Object & /* payload */), EVT_TEXTDRAWDESTROYED >; +using EVehicleDestroyed = Signal< void (SQInt32 /* vehicle */, SQInt32 /* header */, Object & /* payload */), EVT_VEHICLEDESTROYED >; + +// ------------------------------------------------------------------------------------------------ +using EBlipCustom = Signal< void (SQInt32 /* blip */, SQInt32 /* header */, Object & /* payload */), EVT_BLIPCUSTOM >; +using ECheckpointCustom = Signal< void (SQInt32 /* checkpoint */, SQInt32 /* header */, Object & /* payload */), EVT_CHECKPOINTCUSTOM >; +using EKeybindCustom = Signal< void (SQInt32 /* keybind */, SQInt32 /* header */, Object & /* payload */), EVT_KEYBINDCUSTOM >; +using EObjectCustom = Signal< void (SQInt32 /* object */, SQInt32 /* header */, Object & /* payload */), EVT_OBJECTCUSTOM >; +using EPickupCustom = Signal< void (SQInt32 /* pickup */, SQInt32 /* header */, Object & /* payload */), EVT_PICKUPCUSTOM >; +using EPlayerCustom = Signal< void (SQInt32 /* player */, SQInt32 /* header */, Object & /* payload */), EVT_PLAYERCUSTOM >; +using ESphereCustom = Signal< void (SQInt32 /* sphere */, SQInt32 /* header */, Object & /* payload */), EVT_SPHERECUSTOM >; +using ESpriteCustom = Signal< void (SQInt32 /* sprite */, SQInt32 /* header */, Object & /* payload */), EVT_SPRITECUSTOM >; +using ETextdrawCustom = Signal< void (SQInt32 /* textdraw */, SQInt32 /* header */, Object & /* payload */), EVT_TEXTDRAWCUSTOM >; +using EVehicleCustom = Signal< void (SQInt32 /* vehicle */, SQInt32 /* header */, Object & /* payload */), EVT_VEHICLECUSTOM >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerAway = Signal< void (SQInt32 /* player */, bool /* status */), EVT_PLAYERAWAY >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerGameKeys = Signal< void (SQInt32 /* player */, SQInt32 /* previous */, SQInt32 /* current */), EVT_PLAYERGAMEKEYS >; +using EPlayerRename = Signal< void (SQInt32 /* player */, const SQChar * /* previous */, const SQChar * /* current */), EVT_PLAYERRENAME >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerRequestClass = Signal< void (SQInt32 /* player */, SQInt32 /* offset */), EVT_PLAYERREQUESTCLASS >; +using EPlayerRequestSpawn = Signal< void (SQInt32 /* player */), EVT_PLAYERREQUESTSPAWN >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerSpawn = Signal< void (SQInt32 /* player */), EVT_PLAYERSPAWN >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerStartTyping = Signal< void (SQInt32 /* player */), EVT_PLAYERSTARTTYPING >; +using EPlayerStopTyping = Signal< void (SQInt32 /* player */), EVT_PLAYERSTOPTYPING >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerChat = Signal< void (SQInt32 /* player */, const SQChar * /* message */), EVT_PLAYERCHAT >; +using EPlayerCommand = Signal< void (SQInt32 /* player */, const SQChar * /* command */), EVT_PLAYERCOMMAND >; +using EPlayerMessage = Signal< void (SQInt32 /* player */, SQInt32 /* receiver */, const SQChar * /* message */), EVT_PLAYERMESSAGE >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerHealth = Signal< void (SQInt32 /* player */, SQFloat /* previous */, SQFloat /* current */), EVT_PLAYERHEALTH >; +using EPlayerArmour = Signal< void (SQInt32 /* player */, SQFloat /* previous */, SQFloat /* current */), EVT_PLAYERARMOUR >; +using EPlayerWeapon = Signal< void (SQInt32 /* player */, SQInt32 /* previous */, SQInt32 /* current */), EVT_PLAYERWEAPON >; +using EPlayerMove = Signal< void (SQInt32 /* player */, const Vector3 & /* previous */, const Vector3 & /* current */), EVT_PLAYERMOVE >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerWasted = Signal< void (SQInt32 /* player */, SQInt32 /* reason */), EVT_PLAYERWASTED >; +using EPlayerKilled = Signal< void (SQInt32 /* player */, SQInt32 /* killer */, SQInt32 /* reason */, SQInt32 /* body_part */), EVT_PLAYERKILLED >; +using EPlayerTeamKill = Signal< void (SQInt32 /* player */, SQInt32 /* killer */, SQInt32 /* reason */, SQInt32 /* body_part */), EVT_PLAYERTEAMKILL >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerSpectate = Signal< void (SQInt32 /* player */, SQInt32 /* target */), EVT_PLAYERSPECTATE >; +using EPlayerCrashreport = Signal< void (SQInt32 /* player */, const SQChar * /* report */), EVT_PLAYERCRASHREPORT >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerBurning = Signal< void (SQInt32 /* player */, bool /* state */ ), EVT_PLAYERBURNING >; +using EPlayerCrouching = Signal< void (SQInt32 /* player */, bool /* state */ ), EVT_PLAYERCROUCHING >; + +// ------------------------------------------------------------------------------------------------ +using EPlayerState = Signal< void (SQInt32 /* player */, SQInt32 /* previous */, SQInt32 /* current */), EVT_PLAYERSTATE >; +using EPlayerAction = Signal< void (SQInt32 /* player */, SQInt32 /* previous */, SQInt32 /* current */), EVT_PLAYERACTION >; + +// ------------------------------------------------------------------------------------------------ +using EStateNone = Signal< void (SQInt32 /* player */, SQInt32 /* previous */), EVT_STATENONE >; +using EStateNormal = Signal< void (SQInt32 /* player */, SQInt32 /* previous */), EVT_STATENORMAL >; +using EStateShooting = Signal< void (SQInt32 /* player */, SQInt32 /* previous */), EVT_STATESHOOTING >; +using EStateDriver = Signal< void (SQInt32 /* player */, SQInt32 /* previous */), EVT_STATEDRIVER >; +using EStatePassenger = Signal< void (SQInt32 /* player */, SQInt32 /* previous */), EVT_STATEPASSENGER >; +using EStateEnterDriver = Signal< void (SQInt32 /* player */, SQInt32 /* previous */), EVT_STATEENTERDRIVER >; +using EStateEnterPassenger = Signal< void (SQInt32 /* player */, SQInt32 /* previous */), EVT_STATEENTERPASSENGER >; +using EStateExitVehicle = Signal< void (SQInt32 /* player */, SQInt32 /* previous */), EVT_STATEEXITVEHICLE >; +using EStateUnspawned = Signal< void (SQInt32 /* player */, SQInt32 /* previous */), EVT_STATEUNSPAWNED >; + +// ------------------------------------------------------------------------------------------------ +using EActionNone = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONNONE >; +using EActionNormal = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONNORMAL >; +using EActionAiming = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONAIMING >; +using EActionShooting = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONSHOOTING >; +using EActionJumping = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONJUMPING >; +using EActionLieDown = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONLIEDOWN >; +using EActionGettingUp = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONGETTINGUP >; +using EActionJumpVehicle = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONJUMPVEHICLE >; +using EActionDriving = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONDRIVING >; +using EActionDying = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONDYING >; +using EActionWasted = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONWASTED >; +using EActionEmbarking = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONEMBARKING >; +using EActionDisembarking = Signal< void (SQInt32 /* player */, SQInt32 /* previous */ ), EVT_ACTIONDISEMBARKING >; + +// ------------------------------------------------------------------------------------------------ +using EVehicleRespawn = Signal< void (SQInt32 /* vehcle */), EVT_VEHICLERESPAWN >; +using EVehicleExplode = Signal< void (SQInt32 /* vehcle */), EVT_VEHICLEEXPLODE >; + +// ------------------------------------------------------------------------------------------------ +using EVehicleHealth = Signal< void (SQInt32 /* vehcle */, SQFloat, SQFloat), EVT_VEHICLEHEALTH >; +using EVehicleMove = Signal< void (SQInt32 /* vehcle */, const Vector3 &, const Vector3 &), EVT_VEHICLEMOVE >; + +// ------------------------------------------------------------------------------------------------ +using EPickupRespawn = Signal< void (SQInt32 /* pickup */), EVT_PICKUPRESPAWN >; + +// ------------------------------------------------------------------------------------------------ +using EKeybindKeyPress = Signal< void (SQInt32 /* player */, SQInt32 /* keybind */), EVT_KEYBINDKEYPRESS >; +using EKeybindKeyRelease = Signal< void (SQInt32 /* player */, SQInt32 /* keybind */), EVT_KEYBINDKEYRELEASE >; + +// ------------------------------------------------------------------------------------------------ +using EVehicleEmbarking = Signal< void (SQInt32 /* player */, SQInt32 /* vehcle */, SQInt32 /* slot */), EVT_VEHICLEEMBARKING >; +using EVehicleEmbarked = Signal< void (SQInt32 /* player */, SQInt32 /* vehcle */, SQInt32 /* slot */), EVT_VEHICLEEMBARKED >; +using EVehicleDisembark = Signal< void (SQInt32 /* player */, SQInt32 /* vehcle */), EVT_VEHICLEDISEMBARK >; + +// ------------------------------------------------------------------------------------------------ +using EPickupClaimed = Signal< void (SQInt32 /* player */, SQInt32 /* pickup */), EVT_PICKUPCLAIMED >; +using EPickupCollected = Signal< void (SQInt32 /* player */, SQInt32 /* pickup */), EVT_PICKUPCOLLECTED >; + +// ------------------------------------------------------------------------------------------------ +using EObjectShot = Signal< void (SQInt32 /* player */, SQInt32 /* object */, SQInt32 /* weapon */), EVT_OBJECTSHOT >; +using EObjectBump = Signal< void (SQInt32 /* player */, SQInt32 /* object */), EVT_OBJECTBUMP >; + +// ------------------------------------------------------------------------------------------------ +using ECheckpointEntered = Signal< void (SQInt32 /* player */, SQInt32 /* checkpoint */), EVT_CHECKPOINTENTERED >; +using ECheckpointExited = Signal< void (SQInt32 /* player */, SQInt32 /* checkpoint */), EVT_CHECKPOINTEXITED >; + +// ------------------------------------------------------------------------------------------------ +using ESphereEntered = Signal< void (SQInt32 /* player */, SQInt32 /* sphere */), EVT_SPHEREENTERED >; +using ESphereExited = Signal< void (SQInt32 /* player */, SQInt32 /* sphere */), EVT_SPHEREEXITED >; + +// ------------------------------------------------------------------------------------------------ +using EServerFrame = Signal< void (SQFloat /* delta */), EVT_SERVERFRAME >; + +// ------------------------------------------------------------------------------------------------ +using EServerStartup = Signal< void (void), EVT_SERVERSTARTUP >; +using EServerShutdown = Signal< void (void), EVT_SERVERSHUTDOWN >; + +// ------------------------------------------------------------------------------------------------ +using EInternalCommand = Signal< void (SQInt32 /* type */, const SQChar * /* text */), EVT_INTERNALCOMMAND >; +using ELoginAttempt = Signal< void (const SQChar * /* name */, const SQChar * /* pass */, const SQChar * /* addr */), EVT_LOGINATTEMPT >; + +// ------------------------------------------------------------------------------------------------ +using ECustomEvent = Signal< void (SQInt32 /* group */, SQInt32 /* header */, Object & /* payload */), EVT_CUSTOMEVENT >; + +// ------------------------------------------------------------------------------------------------ +using EWorldOption = Signal< void (SQInt32 /* option */, Object & /* value */), EVT_WORLDOPTION >; +using EWorldToggle = Signal< void (SQInt32 /* option */, bool /* value */), EVT_WORLDTOGGLE >; + +// ------------------------------------------------------------------------------------------------ +using ELogMessage = Signal< void (SQInt32 /* type */, const SQChar * /* message */), EVT_LOGMESSAGE >; + +} // Namespace:: SqMod + +#endif // _SIGNALS_HPP_ diff --git a/source/Utility/Shared.cpp b/source/Utility/Shared.cpp new file mode 100644 index 00000000..e69de29b diff --git a/source/Utility/Shared.hpp b/source/Utility/Shared.hpp new file mode 100644 index 00000000..e69de29b