mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2026-01-20 22:24:38 +01:00
Untested update to the new plugin API.
Various other changes to the plugin as well.
This commit is contained in:
@@ -17,7 +17,7 @@ SQChar AABB::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger AABB::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("AABB");
|
||||
static const SQChar name[] = _SC("AABB");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -31,14 +31,14 @@ AABB::AABB()
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AABB::AABB(Value sv)
|
||||
: min(-sv), max(fabs(sv))
|
||||
: min(-sv), max(std::fabs(sv))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AABB::AABB(Value xv, Value yv, Value zv)
|
||||
: min(-xv, -yv, -zv), max(fabs(xv), fabs(yv), fabs(zv))
|
||||
: min(-xv, -yv, -zv), max(std::fabs(xv), std::fabs(yv), std::fabs(zv))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@@ -61,7 +61,7 @@ AABB::AABB(const Vector3 & vmin, const Vector3 & vmax)
|
||||
AABB & AABB::operator = (Value s)
|
||||
{
|
||||
min.Set(-s);
|
||||
max.Set(fabs(s));
|
||||
max.Set(std::fabs(s));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -281,11 +281,17 @@ bool AABB::operator >= (const AABB & b) const
|
||||
Int32 AABB::Cmp(const AABB & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -298,13 +304,13 @@ CSStr AABB::ToString() const
|
||||
void AABB::Set(Value ns)
|
||||
{
|
||||
min = -ns;
|
||||
max = fabs(ns);
|
||||
max = std::fabs(ns);
|
||||
}
|
||||
|
||||
void AABB::Set(Value nx, Value ny, Value nz)
|
||||
{
|
||||
min.Set(-nx, -ny, -nz);
|
||||
max.Set(fabs(nx), fabs(ny), fabs(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)
|
||||
@@ -349,7 +355,7 @@ void AABB::Set(const Vector4 & nmin, const Vector4 & nmax)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void AABB::Set(CSStr values, SQChar delim)
|
||||
{
|
||||
Set(GetAABB(values, delim));
|
||||
Set(AABB::Get(values, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -359,13 +365,13 @@ AABB AABB::Abs() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const AABB & GetAABB(CSStr str)
|
||||
const AABB & AABB::Get(CSStr str)
|
||||
{
|
||||
return GetAABB(str, AABB::Delim);
|
||||
return AABB::Get(str, AABB::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const AABB & GetAABB(CSStr str, SQChar delim)
|
||||
const AABB & AABB::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %f , %f , %f , %f , %f , %f ");
|
||||
@@ -389,89 +395,132 @@ const AABB & GetAABB(CSStr str, SQChar delim)
|
||||
return box;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const AABB & GetAABB()
|
||||
{
|
||||
static AABB box;
|
||||
box.Clear();
|
||||
return box;
|
||||
}
|
||||
|
||||
const AABB & GetAABB(Float32 sv)
|
||||
{
|
||||
static AABB box;
|
||||
box.Set(sv);
|
||||
return box;
|
||||
}
|
||||
|
||||
const AABB & GetAABB(Float32 xv, Float32 yv, Float32 zv)
|
||||
{
|
||||
static AABB box;
|
||||
box.Set(xv, yv, zv);
|
||||
return box;
|
||||
}
|
||||
|
||||
const AABB & GetAABB(Float32 xmin, Float32 ymin, Float32 zmin, Float32 xmax, Float32 ymax, Float32 zmax)
|
||||
{
|
||||
static AABB box;
|
||||
box.Set(xmin, ymin, zmin, xmax, ymax, zmax);
|
||||
return box;
|
||||
}
|
||||
|
||||
const AABB & GetAABB(const Vector3 & vmin, const Vector3 & vmax)
|
||||
{
|
||||
static AABB box;
|
||||
box.Set(vmin, vmax);
|
||||
return box;
|
||||
}
|
||||
|
||||
const AABB & GetAABB(const AABB & o)
|
||||
{
|
||||
static AABB box;
|
||||
box.Set(o);
|
||||
return box;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_AABB(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef AABB::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("AABB"), Class< AABB >(vm, _SC("AABB"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< Val, Val, Val >()
|
||||
.Ctor< Val, Val, Val, Val, Val, Val >()
|
||||
.Ctor< const Vector3 &, const Vector3 & >()
|
||||
/* Static Members */
|
||||
.SetStaticValue(_SC("delim"), &AABB::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("min"), &AABB::min)
|
||||
.Var(_SC("max"), &AABB::max)
|
||||
/* Properties */
|
||||
.Prop(_SC("abs"), &AABB::Abs)
|
||||
/* Core Metamethods */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &AABB::Delim)
|
||||
// Member Variables
|
||||
.Var(_SC("Min"), &AABB::min)
|
||||
.Var(_SC("Max"), &AABB::max)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &AABB::Abs)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &AABB::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &AABB::Typename)
|
||||
.Func(_SC("_cmp"), &AABB::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_add"), &AABB::operator +)
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_sub"), &AABB::operator -)
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_mul"), &AABB::operator *)
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_div"), &AABB::operator /)
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_modulo"), &AABB::operator %)
|
||||
.Func<AABB (AABB::*)(void) const>(_SC("_unm"), &AABB::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (AABB::*)(Val)>(_SC("Set"), &AABB::Set)
|
||||
.Overload<void (AABB::*)(Val, Val, Val)>(_SC("Set"), &AABB::Set)
|
||||
.Overload<void (AABB::*)(Val, Val, Val, Val, Val, Val)>(_SC("Set"), &AABB::Set)
|
||||
.Overload<void (AABB::*)(const AABB &)>(_SC("SetBox"), &AABB::Set)
|
||||
.Overload<void (AABB::*)(const Vector3 &)>(_SC("SetVec3"), &AABB::Set)
|
||||
.Overload<void (AABB::*)(const Vector3 &, const Vector3 &)>(_SC("SetVec3"), &AABB::Set)
|
||||
.Overload<void (AABB::*)(const Vector4 &)>(_SC("SetVec4"), &AABB::Set)
|
||||
.Overload<void (AABB::*)(const Vector4 &, const Vector4 &)>(_SC("SetVec4"), &AABB::Set)
|
||||
.Overload<void (AABB::*)(CSStr, SQChar)>(_SC("SetStr"), &AABB::Set)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_add"), &AABB::operator +)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_sub"), &AABB::operator -)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_mul"), &AABB::operator *)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_div"), &AABB::operator /)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_modulo"), &AABB::operator %)
|
||||
.Func< AABB (AABB::*)(void) const >(_SC("_unm"), &AABB::operator -)
|
||||
// Setters
|
||||
.Overload< void (AABB::*)(Val) >(_SC("Set"), &AABB::Set)
|
||||
.Overload< void (AABB::*)(Val, Val, Val) >(_SC("Set"), &AABB::Set)
|
||||
.Overload< void (AABB::*)(Val, Val, Val, Val, Val, Val) >(_SC("Set"), &AABB::Set)
|
||||
.Overload< void (AABB::*)(const AABB &) >(_SC("SetBox"), &AABB::Set)
|
||||
.Overload< void (AABB::*)(const Vector3 &) >(_SC("SetVec3"), &AABB::Set)
|
||||
.Overload< void (AABB::*)(const Vector3 &, const Vector3 &) >(_SC("SetVec3"), &AABB::Set)
|
||||
.Overload< void (AABB::*)(const Vector4 &) >(_SC("SetVec4"), &AABB::Set)
|
||||
.Overload< void (AABB::*)(const Vector4 &, const Vector4 &) >(_SC("SetVec4"), &AABB::Set)
|
||||
.Overload< void (AABB::*)(CSStr, SQChar) >(_SC("SetStr"), &AABB::Set)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &AABB::Clear)
|
||||
/* Operator Exposure */
|
||||
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opAddAssign"), &AABB::operator +=)
|
||||
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opSubAssign"), &AABB::operator -=)
|
||||
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opMulAssign"), &AABB::operator *=)
|
||||
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opDivAssign"), &AABB::operator /=)
|
||||
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opModAssign"), &AABB::operator %=)
|
||||
|
||||
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opAddAssignS"), &AABB::operator +=)
|
||||
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opSubAssignS"), &AABB::operator -=)
|
||||
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opMulAssignS"), &AABB::operator *=)
|
||||
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opDivAssignS"), &AABB::operator /=)
|
||||
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opModAssignS"), &AABB::operator %=)
|
||||
|
||||
.Func<AABB & (AABB::*)(void)>(_SC("opPreInc"), &AABB::operator ++)
|
||||
.Func<AABB & (AABB::*)(void)>(_SC("opPreDec"), &AABB::operator --)
|
||||
.Func<AABB (AABB::*)(int)>(_SC("opPostInc"), &AABB::operator ++)
|
||||
.Func<AABB (AABB::*)(int)>(_SC("opPostDec"), &AABB::operator --)
|
||||
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opAdd"), &AABB::operator +)
|
||||
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opAddS"), &AABB::operator +)
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opSub"), &AABB::operator -)
|
||||
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opSubS"), &AABB::operator -)
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opMul"), &AABB::operator *)
|
||||
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opMulS"), &AABB::operator *)
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opDiv"), &AABB::operator /)
|
||||
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opDivS"), &AABB::operator /)
|
||||
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opMod"), &AABB::operator %)
|
||||
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opModS"), &AABB::operator %)
|
||||
|
||||
.Func<AABB (AABB::*)(void) const>(_SC("opUnPlus"), &AABB::operator +)
|
||||
.Func<AABB (AABB::*)(void) const>(_SC("opUnMinus"), &AABB::operator -)
|
||||
|
||||
.Func<bool (AABB::*)(const AABB &) const>(_SC("opEqual"), &AABB::operator ==)
|
||||
.Func<bool (AABB::*)(const AABB &) const>(_SC("opNotEqual"), &AABB::operator !=)
|
||||
.Func<bool (AABB::*)(const AABB &) const>(_SC("opLessThan"), &AABB::operator <)
|
||||
.Func<bool (AABB::*)(const AABB &) const>(_SC("opGreaterThan"), &AABB::operator >)
|
||||
.Func<bool (AABB::*)(const AABB &) const>(_SC("opLessEqual"), &AABB::operator <=)
|
||||
.Func<bool (AABB::*)(const AABB &) const>(_SC("opGreaterEqual"), &AABB::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const AABB & (*)(CSStr) >(_SC("FromStr"), &GetAABB)
|
||||
.StaticOverload< const AABB & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetAABB)
|
||||
.StaticOverload< const AABB & (*)(CSStr) >(_SC("FromStr"), &AABB::Get)
|
||||
.StaticOverload< const AABB & (*)(CSStr, SQChar) >(_SC("FromStr"), &AABB::Get)
|
||||
// Operator Exposure
|
||||
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opAddAssign"), &AABB::operator +=)
|
||||
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opSubAssign"), &AABB::operator -=)
|
||||
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opMulAssign"), &AABB::operator *=)
|
||||
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opDivAssign"), &AABB::operator /=)
|
||||
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opModAssign"), &AABB::operator %=)
|
||||
|
||||
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opAddAssignS"), &AABB::operator +=)
|
||||
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opSubAssignS"), &AABB::operator -=)
|
||||
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opMulAssignS"), &AABB::operator *=)
|
||||
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opDivAssignS"), &AABB::operator /=)
|
||||
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opModAssignS"), &AABB::operator %=)
|
||||
|
||||
.Func< AABB & (AABB::*)(void) >(_SC("opPreInc"), &AABB::operator ++)
|
||||
.Func< AABB & (AABB::*)(void) >(_SC("opPreDec"), &AABB::operator --)
|
||||
.Func< AABB (AABB::*)(int) >(_SC("opPostInc"), &AABB::operator ++)
|
||||
.Func< AABB (AABB::*)(int) >(_SC("opPostDec"), &AABB::operator --)
|
||||
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opAdd"), &AABB::operator +)
|
||||
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opAddS"), &AABB::operator +)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opSub"), &AABB::operator -)
|
||||
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opSubS"), &AABB::operator -)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opMul"), &AABB::operator *)
|
||||
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opMulS"), &AABB::operator *)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opDiv"), &AABB::operator /)
|
||||
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opDivS"), &AABB::operator /)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opMod"), &AABB::operator %)
|
||||
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opModS"), &AABB::operator %)
|
||||
|
||||
.Func< AABB (AABB::*)(void) const >(_SC("opUnPlus"), &AABB::operator +)
|
||||
.Func< AABB (AABB::*)(void) const >(_SC("opUnMinus"), &AABB::operator -)
|
||||
|
||||
.Func< bool (AABB::*)(const AABB &) const >(_SC("opEqual"), &AABB::operator ==)
|
||||
.Func< bool (AABB::*)(const AABB &) const >(_SC("opNotEqual"), &AABB::operator !=)
|
||||
.Func< bool (AABB::*)(const AABB &) const >(_SC("opLessThan"), &AABB::operator <)
|
||||
.Func< bool (AABB::*)(const AABB &) const >(_SC("opGreaterThan"), &AABB::operator >)
|
||||
.Func< bool (AABB::*)(const AABB &) const >(_SC("opLessEqual"), &AABB::operator <=)
|
||||
.Func< bool (AABB::*)(const AABB &) const >(_SC("opGreaterEqual"), &AABB::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the AABB type from a string.
|
||||
*/
|
||||
const AABB & GetAABB(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the AABB type from a string.
|
||||
*/
|
||||
const AABB & GetAABB(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to represent an axis aligned bounding box in three-dimensional space.
|
||||
*/
|
||||
@@ -351,6 +341,17 @@ struct AABB
|
||||
* Retrieve a new instance of this type with absolute component values.
|
||||
*/
|
||||
AABB Abs() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the AABB type from a string.
|
||||
*/
|
||||
static const AABB & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the AABB type from a string.
|
||||
*/
|
||||
static const AABB & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -35,9 +34,9 @@ void ThrowMemExcept(const char * msg, ...)
|
||||
// Variable arguments structure
|
||||
va_list args;
|
||||
// Get the specified arguments
|
||||
va_start (args, msg);
|
||||
va_start(args, msg);
|
||||
// Run the specified format
|
||||
int ret = vsnprintf(buffer, sizeof(buffer), msg, args);
|
||||
int ret = std::vsnprintf(buffer, sizeof(buffer), msg, args);
|
||||
// Check for formatting errors
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -53,7 +52,7 @@ void ThrowMemExcept(const char * msg, ...)
|
||||
static Buffer::Pointer AllocMem(Buffer::SzType size)
|
||||
{
|
||||
// Attempt to allocate memory directly
|
||||
Buffer::Pointer ptr = reinterpret_cast< Buffer::Pointer >(malloc(size));
|
||||
Buffer::Pointer ptr = reinterpret_cast< Buffer::Pointer >(std::malloc(size));
|
||||
// Validate the allocated memory
|
||||
if (!ptr)
|
||||
{
|
||||
@@ -96,9 +95,9 @@ private:
|
||||
struct Node
|
||||
{
|
||||
// ----------------------------------------------------------------------------------------
|
||||
SzType mCap; /* The size of the memory chunk. */
|
||||
Pointer mPtr; /* Pointer to the memory chunk. */
|
||||
Node* mNext; /* The next node in the list. */
|
||||
SzType mCap; // The size of the memory chunk.
|
||||
Pointer mPtr; // Pointer to the memory chunk.
|
||||
Node* mNext; // The next node in the list.
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
@@ -137,7 +136,7 @@ private:
|
||||
// Free the memory (if any)
|
||||
if (node->mPtr)
|
||||
{
|
||||
free(node->mPtr);
|
||||
std::free(node->mPtr);
|
||||
}
|
||||
// Save the next node
|
||||
next = node->mNext;
|
||||
@@ -385,7 +384,7 @@ Buffer::Buffer(const Buffer & o)
|
||||
if (m_Cap)
|
||||
{
|
||||
Request(o.m_Cap);
|
||||
memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
|
||||
std::memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,7 +407,7 @@ Buffer & Buffer::operator = (const Buffer & o)
|
||||
if (m_Cap && o.m_Cap <= m_Cap)
|
||||
{
|
||||
// It's safe to copy the data
|
||||
memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
|
||||
std::memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
|
||||
}
|
||||
// Do we even have data to copy?
|
||||
else if (!o.m_Cap)
|
||||
@@ -429,7 +428,7 @@ Buffer & Buffer::operator = (const Buffer & o)
|
||||
// Request a larger buffer
|
||||
Request(o.m_Cap);
|
||||
// Now it's safe to copy the data
|
||||
memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
|
||||
std::memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
|
||||
}
|
||||
// Also copy the edit cursor
|
||||
m_Cur = o.m_Cur;
|
||||
@@ -446,7 +445,7 @@ void Buffer::Grow(SzType n)
|
||||
// Acquire a bigger buffer
|
||||
Request(bkp.m_Cap + n);
|
||||
// Copy the data from the old buffer
|
||||
memcpy(m_Ptr, bkp.m_Ptr, bkp.m_Cap);
|
||||
std::memcpy(m_Ptr, bkp.m_Ptr, bkp.m_Cap);
|
||||
// Copy the previous edit cursor
|
||||
m_Cur = bkp.m_Cur;
|
||||
}
|
||||
@@ -487,7 +486,7 @@ void Buffer::Release()
|
||||
// Is there a memory manager available?
|
||||
if (!m_Mem)
|
||||
{
|
||||
free(m_Ptr); // Deallocate the memory directly
|
||||
std::free(m_Ptr); // Deallocate the memory directly
|
||||
}
|
||||
// Find out to which category does this buffer belong
|
||||
else if (m_Cap <= 1024)
|
||||
@@ -523,7 +522,7 @@ Buffer::SzType Buffer::Write(SzType pos, ConstPtr data, SzType size)
|
||||
Grow((pos + size) - m_Cap + 32);
|
||||
}
|
||||
// Copy the data into the internal buffer
|
||||
memcpy(m_Ptr + pos, data, size);
|
||||
std::memcpy(m_Ptr + pos, data, size);
|
||||
// Return the amount of data written to the buffer
|
||||
return size;
|
||||
}
|
||||
@@ -556,14 +555,14 @@ Buffer::SzType Buffer::WriteF(SzType pos, const char * fmt, va_list args)
|
||||
va_copy(args_cpy, args);
|
||||
// Attempt to write to the current buffer
|
||||
// (if empty, it should tell us the necessary size)
|
||||
int ret = vsnprintf(m_Ptr + pos, m_Cap, fmt, args);
|
||||
int ret = std::vsnprintf(m_Ptr + pos, m_Cap, fmt, args);
|
||||
// Do we need a bigger buffer?
|
||||
if ((pos + ret) >= m_Cap)
|
||||
{
|
||||
// Acquire a larger buffer
|
||||
Grow((pos + ret) - m_Cap + 32);
|
||||
// Retry writing the requested information
|
||||
ret = vsnprintf(m_Ptr + pos, m_Cap, fmt, args_cpy);
|
||||
ret = std::vsnprintf(m_Ptr + pos, m_Cap, fmt, args_cpy);
|
||||
}
|
||||
// Return the value 0 if data could not be written
|
||||
if (ret < 0)
|
||||
@@ -581,7 +580,7 @@ Buffer::SzType Buffer::WriteS(SzType pos, ConstPtr str)
|
||||
if (str && *str != '\0')
|
||||
{
|
||||
// Forward this to the regular write function
|
||||
return Write(pos, str, strlen(str));
|
||||
return Write(pos, str, std::strlen(str));
|
||||
}
|
||||
// Nothing to write
|
||||
return 0;
|
||||
@@ -605,7 +604,7 @@ void Buffer::AppendS(const char * str)
|
||||
// Is there any string to write?
|
||||
if (str)
|
||||
{
|
||||
m_Cur += Write(m_Cur, str, strlen(str));
|
||||
m_Cur += Write(m_Cur, str, std::strlen(str));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -161,6 +161,17 @@ public:
|
||||
assert(m_Ptr);
|
||||
return *m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release the reference to the managed instance.
|
||||
*/
|
||||
void Reset()
|
||||
{
|
||||
if (m_Ptr)
|
||||
{
|
||||
Drop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -206,7 +217,7 @@ private:
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor (null). Not null of a previous buffer was marked as movable.
|
||||
* Default constructor. (null)
|
||||
*/
|
||||
Buffer()
|
||||
: m_Ptr(nullptr)
|
||||
@@ -365,20 +376,20 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the a certain element.
|
||||
* Retrieve a certain element type at the specified position.
|
||||
*/
|
||||
template < typename T = Value > T & At(SzType n)
|
||||
{
|
||||
assert(n < m_Cap);
|
||||
assert(n < static_cast< SzType >(m_Cap / sizeof(T)));
|
||||
return reinterpret_cast< T * >(m_Ptr)[n];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the a certain element.
|
||||
* Retrieve a certain element type at the specified position.
|
||||
*/
|
||||
template < typename T = Value > const T & At(SzType n) const
|
||||
{
|
||||
assert(n < m_Cap);
|
||||
assert(n < static_cast< SzType >(m_Cap / sizeof(T)));
|
||||
return reinterpret_cast< const T * >(m_Ptr)[n];
|
||||
}
|
||||
|
||||
@@ -456,7 +467,7 @@ public:
|
||||
template < typename T = Value > T & Back()
|
||||
{
|
||||
assert(m_Cap >= sizeof(T));
|
||||
return reinterpret_cast< T * >(m_Ptr)[m_Cap-1];
|
||||
return reinterpret_cast< T * >(m_Ptr)[(m_Cap / sizeof(T))-1];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -465,7 +476,7 @@ public:
|
||||
template < typename T = Value > const T & Back() const
|
||||
{
|
||||
assert(m_Cap >= sizeof(T));
|
||||
return reinterpret_cast< const T * >(m_Ptr)[m_Cap-1];
|
||||
return reinterpret_cast< const T * >(m_Ptr)[(m_Cap / sizeof(T))-1];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -474,7 +485,7 @@ public:
|
||||
template < typename T = Value > T & Prev()
|
||||
{
|
||||
assert(m_Cap >= (sizeof(T) * 2));
|
||||
return reinterpret_cast< T * >(m_Ptr)[m_Cap-2];
|
||||
return reinterpret_cast< T * >(m_Ptr)[(m_Cap / sizeof(T))-2];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -483,7 +494,7 @@ public:
|
||||
template < typename T = Value > const T & Prev() const
|
||||
{
|
||||
assert(m_Cap >= (sizeof(T) * 2));
|
||||
return reinterpret_cast< const T * >(m_Ptr)[m_Cap-2];
|
||||
return reinterpret_cast< const T * >(m_Ptr)[(m_Cap / sizeof(T))-2];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -532,7 +543,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reposition the edit cursor to a fixed position within the buffer.
|
||||
* Append a value to the current cursor location and advance the cursor.
|
||||
*/
|
||||
template < typename T = Value > void Push(T v)
|
||||
{
|
||||
@@ -571,7 +582,7 @@ public:
|
||||
template < typename T = Value > T & Before()
|
||||
{
|
||||
assert(m_Cur >= sizeof(T));
|
||||
return reinterpret_cast< T * >(m_Ptr)[m_Cur-1];
|
||||
return reinterpret_cast< T * >(m_Ptr)[(m_Cur / sizeof(T))-1];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -580,7 +591,7 @@ public:
|
||||
template < typename T = Value > const T & Before() const
|
||||
{
|
||||
assert(m_Cur >= sizeof(T));
|
||||
return reinterpret_cast< const T * >(m_Ptr)[m_Cur-1];
|
||||
return reinterpret_cast< const T * >(m_Ptr)[(m_Cur / sizeof(T))-1];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -588,8 +599,8 @@ public:
|
||||
*/
|
||||
template < typename T = Value > T & After()
|
||||
{
|
||||
assert((m_Cur + sizeof(T)) <= (m_Cap - sizeof(T)));
|
||||
return reinterpret_cast< T * >(m_Ptr)[m_Cur+1];
|
||||
assert(m_Cap >= sizeof(T) && (m_Cur + sizeof(T)) <= (m_Cap - sizeof(T)));
|
||||
return reinterpret_cast< T * >(m_Ptr)[(m_Cur / sizeof(T))+1];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -597,8 +608,8 @@ public:
|
||||
*/
|
||||
template < typename T = Value > const T & After() const
|
||||
{
|
||||
assert((m_Cur + sizeof(T)) <= (m_Cap - sizeof(T)));
|
||||
return reinterpret_cast< const T * >(m_Ptr)[m_Cur+1];
|
||||
assert(m_Cap >= sizeof(T) && (m_Cur + sizeof(T)) <= (m_Cap - sizeof(T)));
|
||||
return reinterpret_cast< const T * >(m_Ptr)[(m_Cur / sizeof(T))+1];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -691,6 +702,18 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release the managed memory and manager.
|
||||
*/
|
||||
void ResetAll()
|
||||
{
|
||||
if (m_Ptr)
|
||||
{
|
||||
Release();
|
||||
}
|
||||
m_Mem.Reset();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Swap the contents of two buffers.
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,7 @@ SQChar Circle::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Circle::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("Circle");
|
||||
static const SQChar name[] = _SC("Circle");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ Circle & Circle::operator /= (const Circle & c)
|
||||
Circle & Circle::operator %= (const Circle & c)
|
||||
{
|
||||
pos %= c.pos;
|
||||
rad = fmod(rad, c.rad);
|
||||
rad = std::fmod(rad, c.rad);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ Circle & Circle::operator /= (Value r)
|
||||
|
||||
Circle & Circle::operator %= (Value r)
|
||||
{
|
||||
rad = fmod(rad, r);
|
||||
rad = std::fmod(rad, r);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ Circle Circle::operator / (const Circle & c) const
|
||||
|
||||
Circle Circle::operator % (const Circle & c) const
|
||||
{
|
||||
return Circle(pos % c.pos, fmod(rad, c.rad));
|
||||
return Circle(pos % c.pos, std::fmod(rad, c.rad));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -246,7 +246,7 @@ Circle Circle::operator / (Value r) const
|
||||
|
||||
Circle Circle::operator % (Value r) const
|
||||
{
|
||||
return Circle(fmod(rad, r));
|
||||
return Circle(std::fmod(rad, r));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -278,7 +278,7 @@ Circle Circle::operator % (const Vector2 & p) const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Circle Circle::operator + () const
|
||||
{
|
||||
return Circle(pos.Abs(), fabs(rad));
|
||||
return Circle(pos.Abs(), std::fabs(rad));
|
||||
}
|
||||
|
||||
Circle Circle::operator - () const
|
||||
@@ -321,11 +321,17 @@ bool Circle::operator >= (const Circle & c) const
|
||||
Int32 Circle::Cmp(const Circle & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -372,7 +378,7 @@ void Circle::Set(Value nx, Value ny, Value nr)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Circle::Set(CSStr values, SQChar delim)
|
||||
{
|
||||
Set(GetCircle(values, delim));
|
||||
Set(Circle::Get(values, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -385,17 +391,25 @@ void Circle::Generate()
|
||||
void Circle::Generate(Value min, Value max, bool r)
|
||||
{
|
||||
if (EpsLt(max, min))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
else if (r)
|
||||
{
|
||||
rad = GetRandomFloat32(min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos.Generate(min, max);
|
||||
}
|
||||
}
|
||||
|
||||
void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
|
||||
{
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
pos.Generate(xmin, xmax, ymin, ymax);
|
||||
}
|
||||
@@ -403,7 +417,9 @@ void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
|
||||
void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin, Value rmax)
|
||||
{
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(rmax, rmin))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
pos.Generate(xmin, xmax, ymin, ymax);
|
||||
rad = GetRandomFloat32(rmin, rmax);
|
||||
@@ -412,17 +428,17 @@ void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Circle Circle::Abs() const
|
||||
{
|
||||
return Circle(pos.Abs(), fabs(rad));
|
||||
return Circle(pos.Abs(), std::fabs(rad));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Circle & GetCircle(CSStr str)
|
||||
const Circle & Circle::Get(CSStr str)
|
||||
{
|
||||
return GetCircle(str, Circle::Delim);
|
||||
return Circle::Get(str, Circle::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Circle & GetCircle(CSStr str, SQChar delim)
|
||||
const Circle & Circle::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %f , %f , %f ");
|
||||
@@ -443,99 +459,135 @@ const Circle & GetCircle(CSStr str, SQChar delim)
|
||||
return circle;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Circle & GetCircle()
|
||||
{
|
||||
static Circle circle;
|
||||
circle.Clear();
|
||||
return circle;
|
||||
}
|
||||
|
||||
const Circle & GetCircle(Float32 rv)
|
||||
{
|
||||
static Circle circle;
|
||||
circle.Set(rv);
|
||||
return circle;
|
||||
}
|
||||
|
||||
const Circle & GetCircle(const Vector2 & pv, Float32 rv)
|
||||
{
|
||||
static Circle circle;
|
||||
circle.Set(pv, rv);
|
||||
return circle;
|
||||
}
|
||||
|
||||
const Circle & GetCircle(Float32 xv, Float32 yv, Float32 rv)
|
||||
{
|
||||
static Circle circle;
|
||||
circle.Set(xv, yv, rv);
|
||||
return circle;
|
||||
}
|
||||
|
||||
const Circle & GetCircle(const Circle & o)
|
||||
{
|
||||
static Circle circle;
|
||||
circle.Set(o);
|
||||
return circle;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Circle(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef Circle::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("Circle"), Class< Circle >(vm, _SC("Circle"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< const Vector2 &, Val >()
|
||||
.Ctor< Val, Val, Val >()
|
||||
/* Static Members */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &Circle::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("pos"), &Circle::pos)
|
||||
.Var(_SC("rad"), &Circle::rad)
|
||||
/* Properties */
|
||||
.Prop(_SC("abs"), &Circle::Abs)
|
||||
/* Core Metamethods */
|
||||
// Member Variables
|
||||
.Var(_SC("Pos"), &Circle::pos)
|
||||
.Var(_SC("Rad"), &Circle::rad)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Circle::Abs)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &Circle::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Circle::Typename)
|
||||
.Func(_SC("_cmp"), &Circle::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_add"), &Circle::operator +)
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_sub"), &Circle::operator -)
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_mul"), &Circle::operator *)
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_div"), &Circle::operator /)
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_modulo"), &Circle::operator %)
|
||||
.Func<Circle (Circle::*)(void) const>(_SC("_unm"), &Circle::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (Circle::*)(const Circle &)>(_SC("Set"), &Circle::Set)
|
||||
.Overload<void (Circle::*)(const Vector2 &, Val)>(_SC("Set"), &Circle::Set)
|
||||
.Overload<void (Circle::*)(Val, Val, Val)>(_SC("Set"), &Circle::Set)
|
||||
.Overload<void (Circle::*)(Val)>(_SC("SetRad"), &Circle::Set)
|
||||
.Overload<void (Circle::*)(const Vector2 &)>(_SC("SetVec2"), &Circle::Set)
|
||||
.Overload<void (Circle::*)(Val, Val)>(_SC("SetVec2"), &Circle::Set)
|
||||
.Overload<void (Circle::*)(CSStr, SQChar)>(_SC("SetStr"), &Circle::Set)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_add"), &Circle::operator +)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_sub"), &Circle::operator -)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_mul"), &Circle::operator *)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_div"), &Circle::operator /)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_modulo"), &Circle::operator %)
|
||||
.Func< Circle (Circle::*)(void) const >(_SC("_unm"), &Circle::operator -)
|
||||
// Setters
|
||||
.Overload< void (Circle::*)(const Circle &) >(_SC("Set"), &Circle::Set)
|
||||
.Overload< void (Circle::*)(const Vector2 &, Val) >(_SC("Set"), &Circle::Set)
|
||||
.Overload< void (Circle::*)(Val, Val, Val) >(_SC("Set"), &Circle::Set)
|
||||
.Overload< void (Circle::*)(Val) >(_SC("SetRad"), &Circle::Set)
|
||||
.Overload< void (Circle::*)(const Vector2 &) >(_SC("SetVec2"), &Circle::Set)
|
||||
.Overload< void (Circle::*)(Val, Val) >(_SC("SetVec2"), &Circle::Set)
|
||||
.Overload< void (Circle::*)(CSStr, SQChar) >(_SC("SetStr"), &Circle::Set)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Circle::Clear)
|
||||
/* Operator Exposure */
|
||||
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opAddAssign"), &Circle::operator +=)
|
||||
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opSubAssign"), &Circle::operator -=)
|
||||
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opMulAssign"), &Circle::operator *=)
|
||||
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opDivAssign"), &Circle::operator /=)
|
||||
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opModAssign"), &Circle::operator %=)
|
||||
|
||||
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opAddAssignR"), &Circle::operator +=)
|
||||
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opSubAssignR"), &Circle::operator -=)
|
||||
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opMulAssignR"), &Circle::operator *=)
|
||||
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opDivAssignR"), &Circle::operator /=)
|
||||
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opModAssignR"), &Circle::operator %=)
|
||||
|
||||
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opAddAssignP"), &Circle::operator +=)
|
||||
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opSubAssignP"), &Circle::operator -=)
|
||||
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opMulAssignP"), &Circle::operator *=)
|
||||
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opDivAssignP"), &Circle::operator /=)
|
||||
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opModAssignP"), &Circle::operator %=)
|
||||
|
||||
.Func<Circle & (Circle::*)(void)>(_SC("opPreInc"), &Circle::operator ++)
|
||||
.Func<Circle & (Circle::*)(void)>(_SC("opPreDec"), &Circle::operator --)
|
||||
.Func<Circle (Circle::*)(int)>(_SC("opPostInc"), &Circle::operator ++)
|
||||
.Func<Circle (Circle::*)(int)>(_SC("opPostDec"), &Circle::operator --)
|
||||
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opAdd"), &Circle::operator +)
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opSub"), &Circle::operator -)
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opMul"), &Circle::operator *)
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opDiv"), &Circle::operator /)
|
||||
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opMod"), &Circle::operator %)
|
||||
|
||||
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opAddR"), &Circle::operator +)
|
||||
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opSubR"), &Circle::operator -)
|
||||
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opMulR"), &Circle::operator *)
|
||||
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opDivR"), &Circle::operator /)
|
||||
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opModR"), &Circle::operator %)
|
||||
|
||||
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opAddP"), &Circle::operator +)
|
||||
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opSubP"), &Circle::operator -)
|
||||
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opMulP"), &Circle::operator *)
|
||||
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opDivP"), &Circle::operator /)
|
||||
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opModP"), &Circle::operator %)
|
||||
|
||||
.Func<Circle (Circle::*)(void) const>(_SC("opUnPlus"), &Circle::operator +)
|
||||
.Func<Circle (Circle::*)(void) const>(_SC("opUnMinus"), &Circle::operator -)
|
||||
|
||||
.Func<bool (Circle::*)(const Circle &) const>(_SC("opEqual"), &Circle::operator ==)
|
||||
.Func<bool (Circle::*)(const Circle &) const>(_SC("opNotEqual"), &Circle::operator !=)
|
||||
.Func<bool (Circle::*)(const Circle &) const>(_SC("opLessThan"), &Circle::operator <)
|
||||
.Func<bool (Circle::*)(const Circle &) const>(_SC("opGreaterThan"), &Circle::operator >)
|
||||
.Func<bool (Circle::*)(const Circle &) const>(_SC("opLessEqual"), &Circle::operator <=)
|
||||
.Func<bool (Circle::*)(const Circle &) const>(_SC("opGreaterEqual"), &Circle::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Circle & (*)(CSStr) >(_SC("FromStr"), &GetCircle)
|
||||
.StaticOverload< const Circle & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetCircle)
|
||||
.StaticOverload< const Circle & (*)(CSStr) >(_SC("FromStr"), &Circle::Get)
|
||||
.StaticOverload< const Circle & (*)(CSStr, SQChar) >(_SC("FromStr"), &Circle::Get)
|
||||
// Operator Exposure
|
||||
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opAddAssign"), &Circle::operator +=)
|
||||
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opSubAssign"), &Circle::operator -=)
|
||||
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opMulAssign"), &Circle::operator *=)
|
||||
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opDivAssign"), &Circle::operator /=)
|
||||
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opModAssign"), &Circle::operator %=)
|
||||
|
||||
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opAddAssignR"), &Circle::operator +=)
|
||||
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opSubAssignR"), &Circle::operator -=)
|
||||
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opMulAssignR"), &Circle::operator *=)
|
||||
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opDivAssignR"), &Circle::operator /=)
|
||||
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opModAssignR"), &Circle::operator %=)
|
||||
|
||||
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opAddAssignP"), &Circle::operator +=)
|
||||
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opSubAssignP"), &Circle::operator -=)
|
||||
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opMulAssignP"), &Circle::operator *=)
|
||||
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opDivAssignP"), &Circle::operator /=)
|
||||
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opModAssignP"), &Circle::operator %=)
|
||||
|
||||
.Func< Circle & (Circle::*)(void) >(_SC("opPreInc"), &Circle::operator ++)
|
||||
.Func< Circle & (Circle::*)(void) >(_SC("opPreDec"), &Circle::operator --)
|
||||
.Func< Circle (Circle::*)(int) >(_SC("opPostInc"), &Circle::operator ++)
|
||||
.Func< Circle (Circle::*)(int) >(_SC("opPostDec"), &Circle::operator --)
|
||||
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opAdd"), &Circle::operator +)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opSub"), &Circle::operator -)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opMul"), &Circle::operator *)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opDiv"), &Circle::operator /)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opMod"), &Circle::operator %)
|
||||
|
||||
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opAddR"), &Circle::operator +)
|
||||
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opSubR"), &Circle::operator -)
|
||||
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opMulR"), &Circle::operator *)
|
||||
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opDivR"), &Circle::operator /)
|
||||
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opModR"), &Circle::operator %)
|
||||
|
||||
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opAddP"), &Circle::operator +)
|
||||
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opSubP"), &Circle::operator -)
|
||||
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opMulP"), &Circle::operator *)
|
||||
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opDivP"), &Circle::operator /)
|
||||
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opModP"), &Circle::operator %)
|
||||
|
||||
.Func< Circle (Circle::*)(void) const >(_SC("opUnPlus"), &Circle::operator +)
|
||||
.Func< Circle (Circle::*)(void) const >(_SC("opUnMinus"), &Circle::operator -)
|
||||
|
||||
.Func< bool (Circle::*)(const Circle &) const >(_SC("opEqual"), &Circle::operator ==)
|
||||
.Func< bool (Circle::*)(const Circle &) const >(_SC("opNotEqual"), &Circle::operator !=)
|
||||
.Func< bool (Circle::*)(const Circle &) const >(_SC("opLessThan"), &Circle::operator <)
|
||||
.Func< bool (Circle::*)(const Circle &) const >(_SC("opGreaterThan"), &Circle::operator >)
|
||||
.Func< bool (Circle::*)(const Circle &) const >(_SC("opLessEqual"), &Circle::operator <=)
|
||||
.Func< bool (Circle::*)(const Circle &) const >(_SC("opGreaterEqual"), &Circle::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,16 +8,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Circle type from a string.
|
||||
*/
|
||||
const Circle & GetCircle(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Circle type from a string.
|
||||
*/
|
||||
const Circle & GetCircle(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to represent a two-dimensional circle.
|
||||
*/
|
||||
@@ -386,13 +376,25 @@ struct Circle
|
||||
*/
|
||||
void Clear()
|
||||
{
|
||||
pos.Clear(); rad = 0.0;
|
||||
pos.Clear();
|
||||
rad = 0.0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a new instance of this type with absolute component values.
|
||||
*/
|
||||
Circle Abs() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Circle type from a string.
|
||||
*/
|
||||
static const Circle & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Circle type from a string.
|
||||
*/
|
||||
static const Circle & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -21,7 +21,7 @@ SQChar Color3::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Color3::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("Color3");
|
||||
static const SQChar name[] = _SC("Color3");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -428,11 +428,17 @@ Color3::operator Color4 () const
|
||||
Int32 Color3::Cmp(const Color3 & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -474,7 +480,7 @@ void Color3::Set(const Color4 & c)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Color3::Set(CSStr str, SQChar delim)
|
||||
{
|
||||
Set(GetColor3(str, delim));
|
||||
Set(Color3::Get(str, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -533,7 +539,9 @@ void Color3::Generate()
|
||||
void Color3::Generate(Value min, Value max)
|
||||
{
|
||||
if (max < min)
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
r = GetRandomUint8(min, max);
|
||||
g = GetRandomUint8(min, max);
|
||||
@@ -543,7 +551,9 @@ void Color3::Generate(Value min, Value max)
|
||||
void Color3::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax)
|
||||
{
|
||||
if (rmax < rmin || gmax < gmin || bmax < bmin)
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
r = GetRandomUint8(rmin, rmax);
|
||||
g = GetRandomUint8(gmin, gmax);
|
||||
@@ -565,13 +575,13 @@ void Color3::Inverse()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color3 & GetColor3(CSStr str)
|
||||
const Color3 & Color3::Get(CSStr str)
|
||||
{
|
||||
return GetColor3(str, Color3::Delim);
|
||||
return Color3::Get(str, Color3::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color3 & GetColor3(CSStr str, SQChar delim)
|
||||
const Color3 & Color3::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %u , %u , %u ");
|
||||
@@ -601,115 +611,144 @@ const Color3 & GetColor3(CSStr str, SQChar delim)
|
||||
return col;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color3 & GetColor3()
|
||||
{
|
||||
static Color3 col;
|
||||
col.Clear();
|
||||
return col;
|
||||
}
|
||||
|
||||
const Color3 & GetColor3(Uint8 sv)
|
||||
{
|
||||
static Color3 col;
|
||||
col.Set(sv);
|
||||
return col;
|
||||
}
|
||||
|
||||
const Color3 & GetColor3(Uint8 rv, Uint8 gv, Uint8 bv)
|
||||
{
|
||||
static Color3 col;
|
||||
col.Set(rv, gv, bv);
|
||||
return col;
|
||||
}
|
||||
|
||||
const Color3 & GetColor3(const Color3 & o)
|
||||
{
|
||||
static Color3 col;
|
||||
col.Set(o);
|
||||
return col;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Color3(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef Color3::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("Color3"), Class< Color3 >(vm, _SC("Color3"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< Val, Val, Val >()
|
||||
/* Static Members */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &Color3::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("r"), &Color3::r)
|
||||
.Var(_SC("g"), &Color3::g)
|
||||
.Var(_SC("b"), &Color3::b)
|
||||
/* Properties */
|
||||
.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)
|
||||
/* Core Metamethods */
|
||||
// Member Variables
|
||||
.Var(_SC("R"), &Color3::r)
|
||||
.Var(_SC("G"), &Color3::g)
|
||||
.Var(_SC("B"), &Color3::b)
|
||||
// Properties
|
||||
.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)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &Color3::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Color3::Typename)
|
||||
.Func(_SC("_cmp"), &Color3::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_add"), &Color3::operator +)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_sub"), &Color3::operator -)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_mul"), &Color3::operator *)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_div"), &Color3::operator /)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_modulo"), &Color3::operator %)
|
||||
.Func<Color3 (Color3::*)(void) const>(_SC("_unm"), &Color3::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (Color3::*)(Val)>(_SC("Set"), &Color3::Set)
|
||||
.Overload<void (Color3::*)(Val, Val, Val)>(_SC("Set"), &Color3::Set)
|
||||
.Overload<void (Color3::*)(const Color3 &)>(_SC("SetCol3"), &Color3::Set)
|
||||
.Overload<void (Color3::*)(const Color4 &)>(_SC("SetCol4"), &Color3::Set)
|
||||
.Overload<void (Color3::*)(CSStr, SQChar)>(_SC("SetStr"), &Color3::Set)
|
||||
/* Random Generators */
|
||||
.Overload<void (Color3::*)(void)>(_SC("Generate"), &Color3::Generate)
|
||||
.Overload<void (Color3::*)(Val, Val)>(_SC("Generate"), &Color3::Generate)
|
||||
.Overload<void (Color3::*)(Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Color3::Generate)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_add"), &Color3::operator +)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_sub"), &Color3::operator -)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_mul"), &Color3::operator *)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_div"), &Color3::operator /)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_modulo"), &Color3::operator %)
|
||||
.Func< Color3 (Color3::*)(void) const >(_SC("_unm"), &Color3::operator -)
|
||||
// Setters
|
||||
.Overload< void (Color3::*)(Val) >(_SC("Set"), &Color3::Set)
|
||||
.Overload< void (Color3::*)(Val, Val, Val) >(_SC("Set"), &Color3::Set)
|
||||
.Overload< void (Color3::*)(const Color3 &) >(_SC("SetCol3"), &Color3::Set)
|
||||
.Overload< void (Color3::*)(const Color4 &) >(_SC("SetCol4"), &Color3::Set)
|
||||
.Overload< void (Color3::*)(CSStr, SQChar) >(_SC("SetStr"), &Color3::Set)
|
||||
// Random Generators
|
||||
.Overload< void (Color3::*)(void) >(_SC("Generate"), &Color3::Generate)
|
||||
.Overload< void (Color3::*)(Val, Val) >(_SC("Generate"), &Color3::Generate)
|
||||
.Overload< void (Color3::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Color3::Generate)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Color3::Clear)
|
||||
.Func(_SC("Random"), &Color3::Random)
|
||||
.Func(_SC("Inverse"), &Color3::Inverse)
|
||||
/* Operator Exposure */
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opAddAssign"), &Color3::operator +=)
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opSubAssign"), &Color3::operator -=)
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opMulAssign"), &Color3::operator *=)
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opDivAssign"), &Color3::operator /=)
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opModAssign"), &Color3::operator %=)
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opAndAssign"), &Color3::operator &=)
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opOrAssign"), &Color3::operator |=)
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opXorAssign"), &Color3::operator ^=)
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opShlAssign"), &Color3::operator <<=)
|
||||
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opShrAssign"), &Color3::operator >>=)
|
||||
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opAddAssignS"), &Color3::operator +=)
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opSubAssignS"), &Color3::operator -=)
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opMulAssignS"), &Color3::operator *=)
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opDivAssignS"), &Color3::operator /=)
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opModAssignS"), &Color3::operator %=)
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opAndAssignS"), &Color3::operator &=)
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opOrAssignS"), &Color3::operator |=)
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opXorAssignS"), &Color3::operator ^=)
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opShlAssignS"), &Color3::operator <<=)
|
||||
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opShrAssignS"), &Color3::operator >>=)
|
||||
|
||||
.Func<Color3 & (Color3::*)(void)>(_SC("opPreInc"), &Color3::operator ++)
|
||||
.Func<Color3 & (Color3::*)(void)>(_SC("opPreDec"), &Color3::operator --)
|
||||
.Func<Color3 (Color3::*)(int)>(_SC("opPostInc"), &Color3::operator ++)
|
||||
.Func<Color3 (Color3::*)(int)>(_SC("opPostDec"), &Color3::operator --)
|
||||
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opAdd"), &Color3::operator +)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opSub"), &Color3::operator -)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opMul"), &Color3::operator *)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opDiv"), &Color3::operator /)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opMod"), &Color3::operator %)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opAnd"), &Color3::operator &)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opOr"), &Color3::operator |)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShl"), &Color3::operator ^)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShl"), &Color3::operator <<)
|
||||
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShr"), &Color3::operator >>)
|
||||
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opAddS"), &Color3::operator +)
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opSubS"), &Color3::operator -)
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opMulS"), &Color3::operator *)
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opDivS"), &Color3::operator /)
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opModS"), &Color3::operator %)
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opAndS"), &Color3::operator &)
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opOrS"), &Color3::operator |)
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShlS"), &Color3::operator ^)
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShlS"), &Color3::operator <<)
|
||||
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShrS"), &Color3::operator >>)
|
||||
|
||||
.Func<Color3 (Color3::*)(void) const>(_SC("opUnPlus"), &Color3::operator +)
|
||||
.Func<Color3 (Color3::*)(void) const>(_SC("opUnMinus"), &Color3::operator -)
|
||||
.Func<Color3 (Color3::*)(void) const>(_SC("opCom"), &Color3::operator ~)
|
||||
|
||||
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opEqual"), &Color3::operator ==)
|
||||
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opNotEqual"), &Color3::operator !=)
|
||||
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessThan"), &Color3::operator <)
|
||||
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterThan"), &Color3::operator >)
|
||||
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessEqual"), &Color3::operator <=)
|
||||
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterEqual"), &Color3::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Color3 & (*)(CSStr) >(_SC("FromStr"), &GetColor3)
|
||||
.StaticOverload< const Color3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetColor3)
|
||||
.StaticOverload< const Color3 & (*)(CSStr) >(_SC("FromStr"), &Color3::Get)
|
||||
.StaticOverload< const Color3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Color3::Get)
|
||||
// Operator Exposure
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opAddAssign"), &Color3::operator +=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opSubAssign"), &Color3::operator -=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opMulAssign"), &Color3::operator *=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opDivAssign"), &Color3::operator /=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opModAssign"), &Color3::operator %=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opAndAssign"), &Color3::operator &=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opOrAssign"), &Color3::operator |=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opXorAssign"), &Color3::operator ^=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opShlAssign"), &Color3::operator <<=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opShrAssign"), &Color3::operator >>=)
|
||||
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opAddAssignS"), &Color3::operator +=)
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opSubAssignS"), &Color3::operator -=)
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opMulAssignS"), &Color3::operator *=)
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opDivAssignS"), &Color3::operator /=)
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opModAssignS"), &Color3::operator %=)
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opAndAssignS"), &Color3::operator &=)
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opOrAssignS"), &Color3::operator |=)
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opXorAssignS"), &Color3::operator ^=)
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opShlAssignS"), &Color3::operator <<=)
|
||||
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opShrAssignS"), &Color3::operator >>=)
|
||||
|
||||
.Func< Color3 & (Color3::*)(void) >(_SC("opPreInc"), &Color3::operator ++)
|
||||
.Func< Color3 & (Color3::*)(void) >(_SC("opPreDec"), &Color3::operator --)
|
||||
.Func< Color3 (Color3::*)(int) >(_SC("opPostInc"), &Color3::operator ++)
|
||||
.Func< Color3 (Color3::*)(int) >(_SC("opPostDec"), &Color3::operator --)
|
||||
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opAdd"), &Color3::operator +)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opSub"), &Color3::operator -)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opMul"), &Color3::operator *)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opDiv"), &Color3::operator /)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opMod"), &Color3::operator %)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opAnd"), &Color3::operator &)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opOr"), &Color3::operator |)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opShl"), &Color3::operator ^)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opShl"), &Color3::operator <<)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opShr"), &Color3::operator >>)
|
||||
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opAddS"), &Color3::operator +)
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opSubS"), &Color3::operator -)
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opMulS"), &Color3::operator *)
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opDivS"), &Color3::operator /)
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opModS"), &Color3::operator %)
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opAndS"), &Color3::operator &)
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opOrS"), &Color3::operator |)
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opShlS"), &Color3::operator ^)
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opShlS"), &Color3::operator <<)
|
||||
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opShrS"), &Color3::operator >>)
|
||||
|
||||
.Func< Color3 (Color3::*)(void) const >(_SC("opUnPlus"), &Color3::operator +)
|
||||
.Func< Color3 (Color3::*)(void) const >(_SC("opUnMinus"), &Color3::operator -)
|
||||
.Func< Color3 (Color3::*)(void) const >(_SC("opCom"), &Color3::operator ~)
|
||||
|
||||
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opEqual"), &Color3::operator ==)
|
||||
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opNotEqual"), &Color3::operator !=)
|
||||
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opLessThan"), &Color3::operator <)
|
||||
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opGreaterThan"), &Color3::operator >)
|
||||
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opLessEqual"), &Color3::operator <=)
|
||||
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opGreaterEqual"), &Color3::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color3 type from a string.
|
||||
*/
|
||||
const Color3 & GetColor3(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color3 type from a string.
|
||||
*/
|
||||
const Color3 & GetColor3(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to represent an opaque RGB color.
|
||||
*/
|
||||
@@ -476,6 +466,17 @@ struct Color3
|
||||
* Inverse the color.
|
||||
*/
|
||||
void Inverse();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color3 type from a string.
|
||||
*/
|
||||
static const Color3 & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color3 type from a string.
|
||||
*/
|
||||
static const Color3 & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -21,7 +21,7 @@ SQChar Color4::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Color4::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("Color4");
|
||||
static const SQChar name[] = _SC("Color4");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -460,11 +460,17 @@ Color4::operator Color3 () const
|
||||
Int32 Color4::Cmp(const Color4 & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -517,7 +523,7 @@ void Color4::Set(const Color3 & c)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Color4::Set(CSStr str, SQChar delim)
|
||||
{
|
||||
Set(GetColor4(str, delim));
|
||||
Set(Color4::Get(str, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -579,7 +585,9 @@ void Color4::Generate()
|
||||
void Color4::Generate(Value min, Value max)
|
||||
{
|
||||
if (max < min)
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
r = GetRandomUint8(min, max);
|
||||
g = GetRandomUint8(min, max);
|
||||
@@ -590,7 +598,9 @@ void Color4::Generate(Value min, Value max)
|
||||
void Color4::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax, Value amin, Value amax)
|
||||
{
|
||||
if (rmax < rmin || gmax < gmin || bmax < bmin || amax < amin)
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
r = GetRandomUint8(rmin, rmax);
|
||||
g = GetRandomUint8(gmin, gmax);
|
||||
@@ -614,13 +624,13 @@ void Color4::Inverse()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color4 & GetColor4(CSStr str)
|
||||
const Color4 & Color4::Get(CSStr str)
|
||||
{
|
||||
return GetColor4(str, Color4::Delim);
|
||||
return Color4::Get(str, Color4::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color4 & GetColor4(CSStr str, SQChar delim)
|
||||
const Color4 & Color4::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %u , %u , %u , %u ");
|
||||
@@ -642,7 +652,7 @@ const Color4 & GetColor4(CSStr str, SQChar delim)
|
||||
// The sscanf function requires at least 32 bit integers
|
||||
Uint32 r = 0, g = 0, b = 0, a = 0;
|
||||
// Attempt to extract the component values from the specified string
|
||||
sscanf(str, fs, &r, &g, &b, &a);
|
||||
std::sscanf(str, fs, &r, &g, &b, &a);
|
||||
// Cast the extracted integers to the value used by the Color4 type
|
||||
col.r = static_cast< Color4::Value >(Clamp(r, min, max));
|
||||
col.g = static_cast< Color4::Value >(Clamp(g, min, max));
|
||||
@@ -652,118 +662,154 @@ const Color4 & GetColor4(CSStr str, SQChar delim)
|
||||
return col;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color4 & GetColor4()
|
||||
{
|
||||
static Color4 col;
|
||||
col.Clear();
|
||||
return col;
|
||||
}
|
||||
|
||||
const Color4 & GetColor4(Uint8 sv)
|
||||
{
|
||||
static Color4 col;
|
||||
col.Set(sv);
|
||||
return col;
|
||||
}
|
||||
|
||||
const Color4 & GetColor4(Uint8 rv, Uint8 gv, Uint8 bv)
|
||||
{
|
||||
static Color4 col;
|
||||
col.Set(rv, gv, bv);
|
||||
return col;
|
||||
}
|
||||
|
||||
const Color4 & GetColor4(Uint8 rv, Uint8 gv, Uint8 bv, Uint8 av)
|
||||
{
|
||||
static Color4 col;
|
||||
col.Set(rv, gv, bv, av);
|
||||
return col;
|
||||
}
|
||||
|
||||
const Color4 & GetColor4(const Color4 & o)
|
||||
{
|
||||
static Color4 col;
|
||||
col.Set(o);
|
||||
return col;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Color4(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef Color4::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("Color4"), Class< Color4 >(vm, _SC("Color4"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< Val, Val, Val >()
|
||||
.Ctor< Val, Val, Val, Val >()
|
||||
/* Static Members */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &Color4::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("r"), &Color4::r)
|
||||
.Var(_SC("g"), &Color4::g)
|
||||
.Var(_SC("b"), &Color4::b)
|
||||
.Var(_SC("a"), &Color4::a)
|
||||
/* Properties */
|
||||
.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)
|
||||
/* Core Metamethods */
|
||||
// Member Variables
|
||||
.Var(_SC("R"), &Color4::r)
|
||||
.Var(_SC("G"), &Color4::g)
|
||||
.Var(_SC("B"), &Color4::b)
|
||||
.Var(_SC("A"), &Color4::a)
|
||||
// Properties
|
||||
.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)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &Color4::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Color4::Typename)
|
||||
.Func(_SC("_cmp"), &Color4::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_add"), &Color4::operator +)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_sub"), &Color4::operator -)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_mul"), &Color4::operator *)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_div"), &Color4::operator /)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_modulo"), &Color4::operator %)
|
||||
.Func<Color4 (Color4::*)(void) const>(_SC("_unm"), &Color4::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (Color4::*)(Val)>(_SC("Set"), &Color4::Set)
|
||||
.Overload<void (Color4::*)(Val, Val, Val)>(_SC("Set"), &Color4::Set)
|
||||
.Overload<void (Color4::*)(Val, Val, Val, Val)>(_SC("Set"), &Color4::Set)
|
||||
.Overload<void (Color4::*)(const Color4 &)>(_SC("SetCol4"), &Color4::Set)
|
||||
.Overload<void (Color4::*)(const Color3 &)>(_SC("SetCol3"), &Color4::Set)
|
||||
.Overload<void (Color4::*)(CSStr, SQChar)>(_SC("SetStr"), &Color4::Set)
|
||||
/* Random Generators */
|
||||
.Overload<void (Color4::*)(void)>(_SC("Generate"), &Color4::Generate)
|
||||
.Overload<void (Color4::*)(Val, Val)>(_SC("Generate"), &Color4::Generate)
|
||||
.Overload<void (Color4::*)(Val, Val, Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Color4::Generate)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_add"), &Color4::operator +)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_sub"), &Color4::operator -)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_mul"), &Color4::operator *)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_div"), &Color4::operator /)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_modulo"), &Color4::operator %)
|
||||
.Func< Color4 (Color4::*)(void) const >(_SC("_unm"), &Color4::operator -)
|
||||
// Setters
|
||||
.Overload< void (Color4::*)(Val) >(_SC("Set"), &Color4::Set)
|
||||
.Overload< void (Color4::*)(Val, Val, Val) >(_SC("Set"), &Color4::Set)
|
||||
.Overload< void (Color4::*)(Val, Val, Val, Val) >(_SC("Set"), &Color4::Set)
|
||||
.Overload< void (Color4::*)(const Color4 &) >(_SC("SetCol4"), &Color4::Set)
|
||||
.Overload< void (Color4::*)(const Color3 &) >(_SC("SetCol3"), &Color4::Set)
|
||||
.Overload< void (Color4::*)(CSStr, SQChar) >(_SC("SetStr"), &Color4::Set)
|
||||
// Random Generators
|
||||
.Overload< void (Color4::*)(void) >(_SC("Generate"), &Color4::Generate)
|
||||
.Overload< void (Color4::*)(Val, Val) >(_SC("Generate"), &Color4::Generate)
|
||||
.Overload< void (Color4::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Color4::Generate)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Color4::Clear)
|
||||
.Func(_SC("Random"), &Color4::Random)
|
||||
.Func(_SC("Inverse"), &Color4::Inverse)
|
||||
/* Operator Exposure */
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opAddAssign"), &Color4::operator +=)
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opSubAssign"), &Color4::operator -=)
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opMulAssign"), &Color4::operator *=)
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opDivAssign"), &Color4::operator /=)
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opModAssign"), &Color4::operator %=)
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opAndAssign"), &Color4::operator &=)
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opOrAssign"), &Color4::operator |=)
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opXorAssign"), &Color4::operator ^=)
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opShlAssign"), &Color4::operator <<=)
|
||||
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opShrAssign"), &Color4::operator >>=)
|
||||
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opAddAssignS"), &Color4::operator +=)
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opSubAssignS"), &Color4::operator -=)
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opMulAssignS"), &Color4::operator *=)
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opDivAssignS"), &Color4::operator /=)
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opModAssignS"), &Color4::operator %=)
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opAndAssignS"), &Color4::operator &=)
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opOrAssignS"), &Color4::operator |=)
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opXorAssignS"), &Color4::operator ^=)
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opShlAssignS"), &Color4::operator <<=)
|
||||
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opShrAssignS"), &Color4::operator >>=)
|
||||
|
||||
.Func<Color4 & (Color4::*)(void)>(_SC("opPreInc"), &Color4::operator ++)
|
||||
.Func<Color4 & (Color4::*)(void)>(_SC("opPreDec"), &Color4::operator --)
|
||||
.Func<Color4 (Color4::*)(int)>(_SC("opPostInc"), &Color4::operator ++)
|
||||
.Func<Color4 (Color4::*)(int)>(_SC("opPostDec"), &Color4::operator --)
|
||||
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opAdd"), &Color4::operator +)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opSub"), &Color4::operator -)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opMul"), &Color4::operator *)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opDiv"), &Color4::operator /)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opMod"), &Color4::operator %)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opAnd"), &Color4::operator &)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opOr"), &Color4::operator |)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opShl"), &Color4::operator ^)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opShl"), &Color4::operator <<)
|
||||
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opShr"), &Color4::operator >>)
|
||||
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opAddS"), &Color4::operator +)
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opSubS"), &Color4::operator -)
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opMulS"), &Color4::operator *)
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opDivS"), &Color4::operator /)
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opModS"), &Color4::operator %)
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opAndS"), &Color4::operator &)
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opOrS"), &Color4::operator |)
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opShlS"), &Color4::operator ^)
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opShlS"), &Color4::operator <<)
|
||||
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opShrS"), &Color4::operator >>)
|
||||
|
||||
.Func<Color4 (Color4::*)(void) const>(_SC("opUnPlus"), &Color4::operator +)
|
||||
.Func<Color4 (Color4::*)(void) const>(_SC("opUnMinus"), &Color4::operator -)
|
||||
.Func<Color4 (Color4::*)(void) const>(_SC("opCom"), &Color4::operator ~)
|
||||
|
||||
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opEqual"), &Color4::operator ==)
|
||||
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opNotEqual"), &Color4::operator !=)
|
||||
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opLessThan"), &Color4::operator <)
|
||||
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opGreaterThan"), &Color4::operator >)
|
||||
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opLessEqual"), &Color4::operator <=)
|
||||
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opGreaterEqual"), &Color4::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Color4 & (*)(CSStr) >(_SC("FromStr"), &GetColor4)
|
||||
.StaticOverload< const Color4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetColor4)
|
||||
.StaticOverload< const Color4 & (*)(CSStr) >(_SC("FromStr"), &Color4::Get)
|
||||
.StaticOverload< const Color4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Color4::Get)
|
||||
// Operator Exposure
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opAddAssign"), &Color4::operator +=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opSubAssign"), &Color4::operator -=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opMulAssign"), &Color4::operator *=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opDivAssign"), &Color4::operator /=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opModAssign"), &Color4::operator %=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opAndAssign"), &Color4::operator &=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opOrAssign"), &Color4::operator |=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opXorAssign"), &Color4::operator ^=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opShlAssign"), &Color4::operator <<=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opShrAssign"), &Color4::operator >>=)
|
||||
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opAddAssignS"), &Color4::operator +=)
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opSubAssignS"), &Color4::operator -=)
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opMulAssignS"), &Color4::operator *=)
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opDivAssignS"), &Color4::operator /=)
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opModAssignS"), &Color4::operator %=)
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opAndAssignS"), &Color4::operator &=)
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opOrAssignS"), &Color4::operator |=)
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opXorAssignS"), &Color4::operator ^=)
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opShlAssignS"), &Color4::operator <<=)
|
||||
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opShrAssignS"), &Color4::operator >>=)
|
||||
|
||||
.Func< Color4 & (Color4::*)(void) >(_SC("opPreInc"), &Color4::operator ++)
|
||||
.Func< Color4 & (Color4::*)(void) >(_SC("opPreDec"), &Color4::operator --)
|
||||
.Func< Color4 (Color4::*)(int) >(_SC("opPostInc"), &Color4::operator ++)
|
||||
.Func< Color4 (Color4::*)(int) >(_SC("opPostDec"), &Color4::operator --)
|
||||
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opAdd"), &Color4::operator +)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opSub"), &Color4::operator -)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opMul"), &Color4::operator *)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opDiv"), &Color4::operator /)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opMod"), &Color4::operator %)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opAnd"), &Color4::operator &)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opOr"), &Color4::operator |)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opShl"), &Color4::operator ^)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opShl"), &Color4::operator <<)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opShr"), &Color4::operator >>)
|
||||
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opAddS"), &Color4::operator +)
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opSubS"), &Color4::operator -)
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opMulS"), &Color4::operator *)
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opDivS"), &Color4::operator /)
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opModS"), &Color4::operator %)
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opAndS"), &Color4::operator &)
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opOrS"), &Color4::operator |)
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opShlS"), &Color4::operator ^)
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opShlS"), &Color4::operator <<)
|
||||
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opShrS"), &Color4::operator >>)
|
||||
|
||||
.Func< Color4 (Color4::*)(void) const >(_SC("opUnPlus"), &Color4::operator +)
|
||||
.Func< Color4 (Color4::*)(void) const >(_SC("opUnMinus"), &Color4::operator -)
|
||||
.Func< Color4 (Color4::*)(void) const >(_SC("opCom"), &Color4::operator ~)
|
||||
|
||||
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opEqual"), &Color4::operator ==)
|
||||
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opNotEqual"), &Color4::operator !=)
|
||||
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opLessThan"), &Color4::operator <)
|
||||
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opGreaterThan"), &Color4::operator >)
|
||||
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opLessEqual"), &Color4::operator <=)
|
||||
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opGreaterEqual"), &Color4::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color4 type from a string.
|
||||
*/
|
||||
const Color4 & GetColor4(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color4 type from a string.
|
||||
*/
|
||||
const Color4 & GetColor4(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to represent a transparent RGBA color.
|
||||
*/
|
||||
@@ -486,6 +476,17 @@ struct Color4
|
||||
* Inverse the color.
|
||||
*/
|
||||
void Inverse();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color4 type from a string.
|
||||
*/
|
||||
static const Color4 & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color4 type from a string.
|
||||
*/
|
||||
static const Color4 & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -22,7 +22,7 @@ SQChar Quaternion::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Quaternion::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("Quaternion");
|
||||
static const SQChar name[] = _SC("Quaternion");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -122,10 +122,10 @@ Quaternion & Quaternion::operator /= (const Quaternion & q)
|
||||
|
||||
Quaternion & Quaternion::operator %= (const Quaternion & q)
|
||||
{
|
||||
x = fmod(x, q.x);
|
||||
y = fmod(y, q.y);
|
||||
z = fmod(z, q.z);
|
||||
w = fmod(w, q.w);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -168,10 +168,10 @@ Quaternion & Quaternion::operator /= (Value s)
|
||||
|
||||
Quaternion & Quaternion::operator %= (Value s)
|
||||
{
|
||||
x = fmod(x, s);
|
||||
y = fmod(y, s);
|
||||
z = fmod(z, s);
|
||||
w = fmod(w, s);
|
||||
x = std::fmod(x, s);
|
||||
y = std::fmod(y, s);
|
||||
z = std::fmod(z, s);
|
||||
w = std::fmod(w, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -262,18 +262,18 @@ Quaternion Quaternion::operator / (Value s) const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Quaternion Quaternion::operator % (const Quaternion & q) const
|
||||
{
|
||||
return Quaternion(fmod(x, q.x), fmod(y, q.y), fmod(z, q.z), fmod(w, q.w));
|
||||
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
|
||||
{
|
||||
return Quaternion(fmod(x, s), fmod(y, s), fmod(z, s), fmod(w, s));
|
||||
return Quaternion(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Quaternion Quaternion::operator + () const
|
||||
{
|
||||
return Quaternion(fabs(x), fabs(y), fabs(z), fabs(w));
|
||||
return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator - () const
|
||||
@@ -316,11 +316,17 @@ bool Quaternion::operator >= (const Quaternion & q) const
|
||||
Int32 Quaternion::Cmp(const Quaternion & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -381,7 +387,7 @@ void Quaternion::Set(const Vector4 & v)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Quaternion::Set(CSStr values, SQChar delim)
|
||||
{
|
||||
Set(GetQuaternion(values, delim));
|
||||
Set(Quaternion::Get(values, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -396,7 +402,9 @@ void Quaternion::Generate()
|
||||
void Quaternion::Generate(Value min, Value max)
|
||||
{
|
||||
if (EpsLt(max, min))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomFloat32(min, max);
|
||||
y = GetRandomFloat32(min, max);
|
||||
@@ -407,7 +415,9 @@ void Quaternion::Generate(Value min, Value max)
|
||||
void Quaternion::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
|
||||
{
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomFloat32(xmin, xmax);
|
||||
y = GetRandomFloat32(ymin, ymax);
|
||||
@@ -418,17 +428,17 @@ void Quaternion::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Quaternion Quaternion::Abs() const
|
||||
{
|
||||
return Quaternion(fabs(x), fabs(y), fabs(z), fabs(w));
|
||||
return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Quaternion & GetQuaternion(CSStr str)
|
||||
const Quaternion & Quaternion::Get(CSStr str)
|
||||
{
|
||||
return GetQuaternion(str, Quaternion::Delim);
|
||||
return Quaternion::Get(str, Quaternion::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Quaternion & GetQuaternion(CSStr str, SQChar delim)
|
||||
const Quaternion & Quaternion::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
|
||||
@@ -445,98 +455,134 @@ const Quaternion & GetQuaternion(CSStr str, SQChar delim)
|
||||
fs[9] = delim;
|
||||
fs[14] = delim;
|
||||
// Attempt to extract the component values from the specified string
|
||||
sscanf(str, fs, &quat.x, &quat.y, &quat.z, &quat.w);
|
||||
std::sscanf(str, fs, &quat.x, &quat.y, &quat.z, &quat.w);
|
||||
// Return the resulted value
|
||||
return quat;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Quaternion & GetQuaternion()
|
||||
{
|
||||
static Quaternion quat;
|
||||
quat.Clear();
|
||||
return quat;
|
||||
}
|
||||
|
||||
const Quaternion & GetQuaternion(Float32 sv)
|
||||
{
|
||||
static Quaternion quat;
|
||||
quat.Set(sv);
|
||||
return quat;
|
||||
}
|
||||
|
||||
const Quaternion & GetQuaternion(Float32 xv, Float32 yv, Float32 zv)
|
||||
{
|
||||
static Quaternion quat;
|
||||
quat.Set(xv, yv, zv);
|
||||
return quat;
|
||||
}
|
||||
|
||||
const Quaternion & GetQuaternion(Float32 xv, Float32 yv, Float32 zv, Float32 wv)
|
||||
{
|
||||
static Quaternion quat;
|
||||
quat.Set(xv, yv, zv, wv);
|
||||
return quat;
|
||||
}
|
||||
|
||||
const Quaternion & GetQuaternion(const Quaternion & o)
|
||||
{
|
||||
static Quaternion quat;
|
||||
quat.Set(o);
|
||||
return quat;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Quaternion(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef Quaternion::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("Quaternion"), Class< Quaternion >(vm, _SC("Quaternion"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< Val, Val, Val >()
|
||||
.Ctor< Val, Val, Val, Val >()
|
||||
/* Static Members */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &Quaternion::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("x"), &Quaternion::x)
|
||||
.Var(_SC("y"), &Quaternion::y)
|
||||
.Var(_SC("z"), &Quaternion::z)
|
||||
.Var(_SC("w"), &Quaternion::w)
|
||||
/* Properties */
|
||||
.Prop(_SC("abs"), &Quaternion::Abs)
|
||||
/* Core Metamethods */
|
||||
// Member Variables
|
||||
.Var(_SC("X"), &Quaternion::x)
|
||||
.Var(_SC("Y"), &Quaternion::y)
|
||||
.Var(_SC("Z"), &Quaternion::z)
|
||||
.Var(_SC("W"), &Quaternion::w)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Quaternion::Abs)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &Quaternion::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Quaternion::Typename)
|
||||
.Func(_SC("_cmp"), &Quaternion::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_add"), &Quaternion::operator +)
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_sub"), &Quaternion::operator -)
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_mul"), &Quaternion::operator *)
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_div"), &Quaternion::operator /)
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_modulo"), &Quaternion::operator %)
|
||||
.Func<Quaternion (Quaternion::*)(void) const>(_SC("_unm"), &Quaternion::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (Quaternion::*)(Val)>(_SC("Set"), &Quaternion::Set)
|
||||
.Overload<void (Quaternion::*)(Val, Val, Val)>(_SC("Set"), &Quaternion::Set)
|
||||
.Overload<void (Quaternion::*)(Val, Val, Val, Val)>(_SC("Set"), &Quaternion::Set)
|
||||
.Overload<void (Quaternion::*)(const Quaternion &)>(_SC("SetQuat"), &Quaternion::Set)
|
||||
.Overload<void (Quaternion::*)(const Vector3 &)>(_SC("SetVec3"), &Quaternion::Set)
|
||||
.Overload<void (Quaternion::*)(const Vector4 &)>(_SC("SetVec4"), &Quaternion::Set)
|
||||
.Overload<void (Quaternion::*)(CSStr, SQChar)>(_SC("SetStr"), &Quaternion::Set)
|
||||
/* Random Generators */
|
||||
.Overload<void (Quaternion::*)(void)>(_SC("Generate"), &Quaternion::Generate)
|
||||
.Overload<void (Quaternion::*)(Val, Val)>(_SC("Generate"), &Quaternion::Generate)
|
||||
.Overload<void (Quaternion::*)(Val, Val, Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Quaternion::Generate)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_add"), &Quaternion::operator +)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_sub"), &Quaternion::operator -)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_mul"), &Quaternion::operator *)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_div"), &Quaternion::operator /)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_modulo"), &Quaternion::operator %)
|
||||
.Func< Quaternion (Quaternion::*)(void) const >(_SC("_unm"), &Quaternion::operator -)
|
||||
// Setters
|
||||
.Overload< void (Quaternion::*)(Val) >(_SC("Set"), &Quaternion::Set)
|
||||
.Overload< void (Quaternion::*)(Val, Val, Val) >(_SC("Set"), &Quaternion::Set)
|
||||
.Overload< void (Quaternion::*)(Val, Val, Val, Val) >(_SC("Set"), &Quaternion::Set)
|
||||
.Overload< void (Quaternion::*)(const Quaternion &) >(_SC("SetQuat"), &Quaternion::Set)
|
||||
.Overload< void (Quaternion::*)(const Vector3 &) >(_SC("SetVec3"), &Quaternion::Set)
|
||||
.Overload< void (Quaternion::*)(const Vector4 &) >(_SC("SetVec4"), &Quaternion::Set)
|
||||
.Overload< void (Quaternion::*)(CSStr, SQChar) >(_SC("SetStr"), &Quaternion::Set)
|
||||
// Random Generators
|
||||
.Overload< void (Quaternion::*)(void) >(_SC("Generate"), &Quaternion::Generate)
|
||||
.Overload< void (Quaternion::*)(Val, Val) >(_SC("Generate"), &Quaternion::Generate)
|
||||
.Overload< void (Quaternion::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Quaternion::Generate)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Quaternion::Clear)
|
||||
/* Operator Exposure */
|
||||
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opAddAssign"), &Quaternion::operator +=)
|
||||
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opSubAssign"), &Quaternion::operator -=)
|
||||
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opMulAssign"), &Quaternion::operator *=)
|
||||
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opDivAssign"), &Quaternion::operator /=)
|
||||
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opModAssign"), &Quaternion::operator %=)
|
||||
|
||||
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opAddAssignS"), &Quaternion::operator +=)
|
||||
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opSubAssignS"), &Quaternion::operator -=)
|
||||
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opMulAssignS"), &Quaternion::operator *=)
|
||||
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opDivAssignS"), &Quaternion::operator /=)
|
||||
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opModAssignS"), &Quaternion::operator %=)
|
||||
|
||||
.Func<Quaternion & (Quaternion::*)(void)>(_SC("opPreInc"), &Quaternion::operator ++)
|
||||
.Func<Quaternion & (Quaternion::*)(void)>(_SC("opPreDec"), &Quaternion::operator --)
|
||||
.Func<Quaternion (Quaternion::*)(int)>(_SC("opPostInc"), &Quaternion::operator ++)
|
||||
.Func<Quaternion (Quaternion::*)(int)>(_SC("opPostDec"), &Quaternion::operator --)
|
||||
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opAdd"), &Quaternion::operator +)
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opSub"), &Quaternion::operator -)
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opMul"), &Quaternion::operator *)
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opDiv"), &Quaternion::operator /)
|
||||
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opMod"), &Quaternion::operator %)
|
||||
|
||||
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opAddS"), &Quaternion::operator +)
|
||||
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opSubS"), &Quaternion::operator -)
|
||||
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opMulS"), &Quaternion::operator *)
|
||||
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opDivS"), &Quaternion::operator /)
|
||||
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opModS"), &Quaternion::operator %)
|
||||
|
||||
.Func<Quaternion (Quaternion::*)(void) const>(_SC("opUnPlus"), &Quaternion::operator +)
|
||||
.Func<Quaternion (Quaternion::*)(void) const>(_SC("opUnMinus"), &Quaternion::operator -)
|
||||
|
||||
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opEqual"), &Quaternion::operator ==)
|
||||
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opNotEqual"), &Quaternion::operator !=)
|
||||
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opLessThan"), &Quaternion::operator <)
|
||||
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opGreaterThan"), &Quaternion::operator >)
|
||||
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opLessEqual"), &Quaternion::operator <=)
|
||||
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opGreaterEqual"), &Quaternion::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Quaternion & (*)(CSStr) >(_SC("FromStr"), &GetQuaternion)
|
||||
.StaticOverload< const Quaternion & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetQuaternion)
|
||||
.StaticOverload< const Quaternion & (*)(CSStr) >(_SC("FromStr"), &Quaternion::Get)
|
||||
.StaticOverload< const Quaternion & (*)(CSStr, SQChar) >(_SC("FromStr"), &Quaternion::Get)
|
||||
// Operator Exposure
|
||||
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opAddAssign"), &Quaternion::operator +=)
|
||||
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opSubAssign"), &Quaternion::operator -=)
|
||||
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opMulAssign"), &Quaternion::operator *=)
|
||||
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opDivAssign"), &Quaternion::operator /=)
|
||||
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opModAssign"), &Quaternion::operator %=)
|
||||
|
||||
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opAddAssignS"), &Quaternion::operator +=)
|
||||
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opSubAssignS"), &Quaternion::operator -=)
|
||||
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opMulAssignS"), &Quaternion::operator *=)
|
||||
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opDivAssignS"), &Quaternion::operator /=)
|
||||
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opModAssignS"), &Quaternion::operator %=)
|
||||
|
||||
.Func< Quaternion & (Quaternion::*)(void) >(_SC("opPreInc"), &Quaternion::operator ++)
|
||||
.Func< Quaternion & (Quaternion::*)(void) >(_SC("opPreDec"), &Quaternion::operator --)
|
||||
.Func< Quaternion (Quaternion::*)(int) >(_SC("opPostInc"), &Quaternion::operator ++)
|
||||
.Func< Quaternion (Quaternion::*)(int) >(_SC("opPostDec"), &Quaternion::operator --)
|
||||
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opAdd"), &Quaternion::operator +)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opSub"), &Quaternion::operator -)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opMul"), &Quaternion::operator *)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opDiv"), &Quaternion::operator /)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opMod"), &Quaternion::operator %)
|
||||
|
||||
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opAddS"), &Quaternion::operator +)
|
||||
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opSubS"), &Quaternion::operator -)
|
||||
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opMulS"), &Quaternion::operator *)
|
||||
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opDivS"), &Quaternion::operator /)
|
||||
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opModS"), &Quaternion::operator %)
|
||||
|
||||
.Func< Quaternion (Quaternion::*)(void) const >(_SC("opUnPlus"), &Quaternion::operator +)
|
||||
.Func< Quaternion (Quaternion::*)(void) const >(_SC("opUnMinus"), &Quaternion::operator -)
|
||||
|
||||
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opEqual"), &Quaternion::operator ==)
|
||||
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opNotEqual"), &Quaternion::operator !=)
|
||||
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opLessThan"), &Quaternion::operator <)
|
||||
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opGreaterThan"), &Quaternion::operator >)
|
||||
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opLessEqual"), &Quaternion::operator <=)
|
||||
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opGreaterEqual"), &Quaternion::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Quaternion type from a string.
|
||||
*/
|
||||
const Quaternion & GetQuaternion(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Quaternion type from a string.
|
||||
*/
|
||||
const Quaternion & GetQuaternion(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Quaternion class for representing rotations.
|
||||
*/
|
||||
@@ -341,6 +331,17 @@ struct Quaternion
|
||||
* Retrieve a new instance of this type with absolute component values.
|
||||
*/
|
||||
Quaternion Abs() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Quaternion type from a string.
|
||||
*/
|
||||
static const Quaternion & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Quaternion type from a string.
|
||||
*/
|
||||
static const Quaternion & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
#include "Base/Color3.hpp"
|
||||
#include "Library/Random.hpp"
|
||||
#include "Library/String.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Color3.hpp"
|
||||
#include "Library/Numeric.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <ctime>
|
||||
@@ -22,13 +21,9 @@
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const SQChar EMPTY_STR_CHAR = 0;
|
||||
const SQChar * g_EmptyStr = &EMPTY_STR_CHAR;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
PluginFuncs* _Func = NULL;
|
||||
PluginCallbacks* _Clbk = NULL;
|
||||
PluginInfo* _Info = NULL;
|
||||
PluginFuncs* _Func = nullptr;
|
||||
PluginCallbacks* _Clbk = nullptr;
|
||||
PluginInfo* _Info = nullptr;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Common buffer to reduce memory allocations. To be immediately copied upon return!
|
||||
@@ -36,108 +31,6 @@ PluginInfo* _Info = NULL;
|
||||
static SQChar g_Buffer[4096];
|
||||
static SQChar g_NumBuff[1024];
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & NullObject()
|
||||
{
|
||||
static Object o;
|
||||
o.Release();
|
||||
return o;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Array & NullArray()
|
||||
{
|
||||
static Array a;
|
||||
a.Release();
|
||||
return a;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & NullFunction()
|
||||
{
|
||||
static Function f;
|
||||
f.Release();
|
||||
return f;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool SToB(CSStr str)
|
||||
{
|
||||
// Temporary buffer to store the lowercase string
|
||||
SQChar buffer[8];
|
||||
// The currently processed character
|
||||
unsigned i = 0;
|
||||
// Convert only the necessary characters to lowercase
|
||||
while (i < 7 && *str != '\0')
|
||||
{
|
||||
buffer[i++] = static_cast< SQChar >(std::tolower(*(str++)));
|
||||
}
|
||||
// Add the null terminator
|
||||
buffer[i] = '\0';
|
||||
// Compare the lowercase string and return the result
|
||||
return (std::strcmp(buffer, "true") == 0 || std::strcmp(buffer, "yes") == 0 ||
|
||||
std::strcmp(buffer, "on") == 0 || std::strcmp(buffer, "1") == 0) ? true : false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SqThrowF(CSStr fmt, ...)
|
||||
{
|
||||
// Acquire a moderately sized buffer
|
||||
Buffer b(128);
|
||||
// Initialize the argument list
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
// Attempt to run the specified format
|
||||
if (b.WriteF(0, fmt, args) == 0)
|
||||
{
|
||||
// Attempt to write a generic message at least
|
||||
b.At(b.WriteS(0, "Unknown error has occurred")) = '\0';
|
||||
}
|
||||
// Release the argument list
|
||||
va_end(args);
|
||||
// Throw the exception with the resulted message
|
||||
throw Sqrat::Exception(b.Get< SQChar >());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ToStrF(CSStr fmt, ...)
|
||||
{
|
||||
// Prepare the arguments list
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
// Attempt to run the specified format
|
||||
int ret = vsnprintf(g_Buffer, sizeof(g_Buffer), fmt, args);
|
||||
// See if the format function failed
|
||||
if (ret < 0)
|
||||
{
|
||||
STHROWF("Failed to run the specified string format");
|
||||
}
|
||||
// Finalized the arguments list
|
||||
va_end(args);
|
||||
// Return the resulted string
|
||||
return g_Buffer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ToStringF(CSStr fmt, ...)
|
||||
{
|
||||
// Acquire a moderately sized buffer
|
||||
Buffer b(128);
|
||||
// Prepare the arguments list
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
// Attempt to run the specified format
|
||||
if (b.WriteF(0, fmt, args) == 0)
|
||||
{
|
||||
// Make sure the string is null terminated
|
||||
b.At(0) = 0;
|
||||
}
|
||||
// Finalized the arguments list
|
||||
va_end(args);
|
||||
// Return the resulted string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Color3 SQ_Color_List[] =
|
||||
{
|
||||
@@ -283,6 +176,158 @@ static const Color3 SQ_Color_List[] =
|
||||
Color3(154, 205, 50)
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SLongInt & GetSLongInt()
|
||||
{
|
||||
static SLongInt l;
|
||||
l.SetNum(0);
|
||||
return l;
|
||||
}
|
||||
|
||||
const SLongInt & GetSLongInt(Int64 n)
|
||||
{
|
||||
static SLongInt l;
|
||||
l.SetNum(n);
|
||||
return l;
|
||||
}
|
||||
|
||||
const SLongInt & GetSLongInt(CSStr s)
|
||||
{
|
||||
static SLongInt l;
|
||||
l = s;
|
||||
return l;
|
||||
}
|
||||
|
||||
const ULongInt & GetULongInt()
|
||||
{
|
||||
static ULongInt l;
|
||||
l.SetNum(0);
|
||||
return l;
|
||||
}
|
||||
|
||||
const ULongInt & GetULongInt(Uint64 n)
|
||||
{
|
||||
static ULongInt l;
|
||||
l.SetNum(n);
|
||||
return l;
|
||||
}
|
||||
|
||||
const ULongInt & GetULongInt(CSStr s)
|
||||
{
|
||||
static ULongInt l;
|
||||
l = s;
|
||||
return l;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & NullObject()
|
||||
{
|
||||
static Object o;
|
||||
o.Release();
|
||||
return o;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Table & NullTable()
|
||||
{
|
||||
static Table t;
|
||||
t.Release();
|
||||
return t;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Array & NullArray()
|
||||
{
|
||||
static Array a;
|
||||
a.Release();
|
||||
return a;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & NullFunction()
|
||||
{
|
||||
static Function f;
|
||||
f.Release();
|
||||
return f;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool SToB(CSStr str)
|
||||
{
|
||||
// Temporary buffer to store the lowercase string
|
||||
SQChar buffer[8];
|
||||
// The currently processed character
|
||||
unsigned i = 0;
|
||||
// Convert only the necessary characters to lowercase
|
||||
while (i < 7 && *str != '\0')
|
||||
{
|
||||
buffer[i++] = static_cast< SQChar >(std::tolower(*(str++)));
|
||||
}
|
||||
// Add the null terminator
|
||||
buffer[i] = '\0';
|
||||
// Compare the lowercase string and return the result
|
||||
return (std::strcmp(buffer, "true") == 0 || std::strcmp(buffer, "yes") == 0 ||
|
||||
std::strcmp(buffer, "on") == 0 || std::strcmp(buffer, "1") == 0) ? true : false;
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SqThrowF(CSStr fmt, ...)
|
||||
{
|
||||
// Acquire a moderately sized buffer
|
||||
Buffer b(128);
|
||||
// Initialize the argument list
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
// Attempt to run the specified format
|
||||
if (b.WriteF(0, fmt, args) == 0)
|
||||
{
|
||||
// Attempt to write a generic message at least
|
||||
b.At(b.WriteS(0, "Unknown error has occurred")) = '\0';
|
||||
}
|
||||
// Release the argument list
|
||||
va_end(args);
|
||||
// Throw the exception with the resulted message
|
||||
throw Sqrat::Exception(b.Get< SQChar >());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ToStrF(CSStr fmt, ...)
|
||||
{
|
||||
// Prepare the arguments list
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
// Attempt to run the specified format
|
||||
int ret = vsnprintf(g_Buffer, sizeof(g_Buffer), fmt, args);
|
||||
// See if the format function failed
|
||||
if (ret < 0)
|
||||
{
|
||||
STHROWF("Failed to run the specified string format");
|
||||
}
|
||||
// Finalized the arguments list
|
||||
va_end(args);
|
||||
// Return the resulted string
|
||||
return g_Buffer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ToStringF(CSStr fmt, ...)
|
||||
{
|
||||
// Acquire a moderately sized buffer
|
||||
Buffer b(128);
|
||||
// Prepare the arguments list
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
// Attempt to run the specified format
|
||||
if (b.WriteF(0, fmt, args) == 0)
|
||||
{
|
||||
// Make sure the string is null terminated
|
||||
b.At(0) = 0;
|
||||
}
|
||||
// Finalized the arguments list
|
||||
va_end(args);
|
||||
// Return the resulted string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color3 & GetRandomColor()
|
||||
{
|
||||
@@ -1190,13 +1235,17 @@ bool ConvNum< bool >::FromStr(CSStr s, Int32 /*base*/)
|
||||
void Register_Base(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm)
|
||||
.Func(_SC("EpsEq"), &EpsEq<SQFloat>)
|
||||
.Func(_SC("EpsLt"), &EpsLt<SQFloat>)
|
||||
.Func(_SC("EpsGt"), &EpsGt<SQFloat>)
|
||||
.Func(_SC("EpsLtEq"), &EpsLtEq<SQFloat>)
|
||||
.Func(_SC("EpsGtEq"), &EpsGtEq<SQFloat>)
|
||||
.Func(_SC("ClampI"), &Clamp<SQInteger>)
|
||||
.Func(_SC("ClampF"), &Clamp<SQFloat>)
|
||||
.Func(_SC("EpsEq"), &EpsEq< SQFloat >)
|
||||
.Func(_SC("EpsLt"), &EpsLt< SQFloat >)
|
||||
.Func(_SC("EpsGt"), &EpsGt< SQFloat >)
|
||||
.Func(_SC("EpsLtEq"), &EpsLtEq< SQFloat >)
|
||||
.Func(_SC("EpsGtEq"), &EpsGtEq< SQFloat >)
|
||||
.Func(_SC("ClampI"), &Clamp< SQInteger >)
|
||||
.Func(_SC("ClampF"), &Clamp< SQFloat >)
|
||||
.Func(_SC("ClampMinI"), &ClampMin< SQInteger >)
|
||||
.Func(_SC("ClampMinF"), &ClampMin< SQFloat >)
|
||||
.Func(_SC("ClampMaxI"), &ClampMax< SQInteger >)
|
||||
.Func(_SC("ClampMaxF"), &ClampMax< SQFloat >)
|
||||
.Func(_SC("NextPow2"), &NextPow2)
|
||||
.Func(_SC("SToB"), &SToB)
|
||||
.Func(_SC("GetColor"), &GetColor);
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern const SQChar * g_EmptyStr;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Proxies to communicate with the server.
|
||||
*/
|
||||
@@ -25,6 +22,176 @@ extern PluginFuncs* _Func;
|
||||
extern PluginCallbacks* _Clbk;
|
||||
extern PluginInfo* _Info;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
||||
* Primary logging functions.
|
||||
*/
|
||||
extern void LogDbg(CCStr fmt, ...);
|
||||
extern void LogUsr(CCStr fmt, ...);
|
||||
extern void LogScs(CCStr fmt, ...);
|
||||
extern void LogInf(CCStr fmt, ...);
|
||||
extern void LogWrn(CCStr fmt, ...);
|
||||
extern void LogErr(CCStr fmt, ...);
|
||||
extern void LogFtl(CCStr fmt, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
||||
* Secondary logging functions.
|
||||
*/
|
||||
extern void LogSDbg(CCStr fmt, ...);
|
||||
extern void LogSUsr(CCStr fmt, ...);
|
||||
extern void LogSScs(CCStr fmt, ...);
|
||||
extern void LogSInf(CCStr fmt, ...);
|
||||
extern void LogSWrn(CCStr fmt, ...);
|
||||
extern void LogSErr(CCStr fmt, ...);
|
||||
extern void LogSFtl(CCStr fmt, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
||||
* Primary conditional logging functions.
|
||||
*/
|
||||
extern bool cLogDbg(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogUsr(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogScs(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogInf(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogWrn(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogErr(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogFtl(bool exp, CCStr fmt, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
||||
* Secondary conditional logging functions.
|
||||
*/
|
||||
extern bool cLogSDbg(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogSUsr(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogSScs(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogSInf(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogSWrn(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogSErr(bool exp, CCStr fmt, ...);
|
||||
extern bool cLogSFtl(bool exp, CCStr fmt, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Output a message only if the _DEBUG was defined.
|
||||
*/
|
||||
extern void OutputDebug(const char * msg, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Output a formatted user message to the console.
|
||||
*/
|
||||
extern void OutputMessage(const char * msg, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Output a formatted error message to the console.
|
||||
*/
|
||||
extern void OutputError(const char * msg, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent AABB instance with the given values.
|
||||
*/
|
||||
extern const AABB & GetAABB();
|
||||
extern const AABB & GetAABB(Float32 sv);
|
||||
extern const AABB & GetAABB(Float32 xv, Float32 yv, Float32 zv);
|
||||
extern const AABB & GetAABB(Float32 xmin, Float32 ymin, Float32 zmin, Float32 xmax, Float32 ymax, Float32 zmax);
|
||||
extern const AABB & GetAABB(const Vector3 & vmin, const Vector3 & vmax);
|
||||
extern const AABB & GetAABB(const AABB & o);
|
||||
extern const AABB & GetAABB(AABB && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent Circle instance with the given values.
|
||||
*/
|
||||
extern const Circle & GetCircle();
|
||||
extern const Circle & GetCircle(Float32 rv);
|
||||
extern const Circle & GetCircle(const Vector2 & pv, Float32 rv);
|
||||
extern const Circle & GetCircle(Float32 xv, Float32 yv, Float32 rv);
|
||||
extern const Circle & GetCircle(const Circle & o);
|
||||
extern const Circle & GetCircle(Circle && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent Color3 instance with the given values.
|
||||
*/
|
||||
extern const Color3 & GetColor3();
|
||||
extern const Color3 & GetColor3(Uint8 sv);
|
||||
extern const Color3 & GetColor3(Uint8 rv, Uint8 gv, Uint8 bv);
|
||||
extern const Color3 & GetColor3(const Color3 & o);
|
||||
extern const Color3 & GetColor3(Color3 && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent Color4 instance with the given values.
|
||||
*/
|
||||
extern const Color4 & GetColor4();
|
||||
extern const Color4 & GetColor4(Uint8 sv);
|
||||
extern const Color4 & GetColor4(Uint8 rv, Uint8 gv, Uint8 bv);
|
||||
extern const Color4 & GetColor4(Uint8 rv, Uint8 gv, Uint8 bv, Uint8 av);
|
||||
extern const Color4 & GetColor4(const Color4 & o);
|
||||
extern const Color4 & GetColor4(Color4 && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent Quaternion instance with the given values.
|
||||
*/
|
||||
extern const Quaternion & GetQuaternion();
|
||||
extern const Quaternion & GetQuaternion(Float32 sv);
|
||||
extern const Quaternion & GetQuaternion(Float32 xv, Float32 yv, Float32 zv);
|
||||
extern const Quaternion & GetQuaternion(Float32 xv, Float32 yv, Float32 zv, Float32 wv);
|
||||
extern const Quaternion & GetQuaternion(const Quaternion & o);
|
||||
extern const Quaternion & GetQuaternion(Quaternion && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent Sphere instance with the given values.
|
||||
*/
|
||||
extern const Sphere & GetSphere();
|
||||
extern const Sphere & GetSphere(Float32 rv);
|
||||
extern const Sphere & GetSphere(const Vector3 & pv, Float32 rv);
|
||||
extern const Sphere & GetSphere(Float32 xv, Float32 yv, Float32 zv, Float32 rv);
|
||||
extern const Sphere & GetSphere(const Sphere & o);
|
||||
extern const Sphere & GetSphere(Sphere && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent Vector2 instance with the given values.
|
||||
*/
|
||||
extern const Vector2 & GetVector2();
|
||||
extern const Vector2 & GetVector2(Float32 sv);
|
||||
extern const Vector2 & GetVector2(Float32 xv, Float32 yv);
|
||||
extern const Vector2 & GetVector2(const Vector2 & o);
|
||||
extern const Vector2 & GetVector2(Vector2 && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent Vector2i instance with the given values.
|
||||
*/
|
||||
extern const Vector2i & GetVector2i();
|
||||
extern const Vector2i & GetVector2i(Int32 sv);
|
||||
extern const Vector2i & GetVector2i(Int32 xv, Int32 yv);
|
||||
extern const Vector2i & GetVector2i(const Vector2i & o);
|
||||
extern const Vector2i & GetVector2i(Vector2i && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent Vector3 instance with the given values.
|
||||
*/
|
||||
extern const Vector3 & GetVector3();
|
||||
extern const Vector3 & GetVector3(Float32 sv);
|
||||
extern const Vector3 & GetVector3(Float32 xv, Float32 yv, Float32 zv);
|
||||
extern const Vector3 & GetVector3(const Vector3 & o);
|
||||
extern const Vector3 & GetVector3(Vector3 && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent Vector4 instance with the given values.
|
||||
*/
|
||||
extern const Vector4 & GetVector4();
|
||||
extern const Vector4 & GetVector4(Float32 sv);
|
||||
extern const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv);
|
||||
extern const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv, Float32 wv);
|
||||
extern const Vector4 & GetVector4(const Vector4 & o);
|
||||
extern const Vector4 & GetVector4(Vector4 && o);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent LongInt instance with the given values.
|
||||
*/
|
||||
const SLongInt & GetSLongInt();
|
||||
const SLongInt & GetSLongInt(Int64 n);
|
||||
const SLongInt & GetSLongInt(CSStr s);
|
||||
const ULongInt & GetULongInt();
|
||||
const ULongInt & GetULongInt(Uint64 n);
|
||||
const ULongInt & GetULongInt(CSStr s);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the maximum value of a fundamental type.
|
||||
*/
|
||||
@@ -1000,6 +1167,34 @@ template< typename T > inline T Clamp(T val, T min, T max)
|
||||
return val;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Force a value to be higher then than the imposed limit.
|
||||
*/
|
||||
template< typename T > inline T ClampMin(T val, T min)
|
||||
{
|
||||
// Is the specified value bellow the minimum?
|
||||
if (val < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
// Return the value as is
|
||||
return val;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Force a value to be smaller then than the imposed limit.
|
||||
*/
|
||||
template< typename T > inline T ClampMax(T val, T max)
|
||||
{
|
||||
// Is the specified value above the maximum?
|
||||
if (val > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
// Return the value as is
|
||||
return val;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Force a value to be within a certain range.
|
||||
*/
|
||||
@@ -1060,26 +1255,16 @@ inline Uint32 NextPow2(Uint32 num)
|
||||
return ++num;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Output a message only if the _DEBUG was defined.
|
||||
*/
|
||||
void OutputDebug(const char * msg, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Output a formatted user message to the console.
|
||||
*/
|
||||
void OutputMessage(const char * msg, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Output a formatted error message to the console.
|
||||
*/
|
||||
void OutputError(const char * msg, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve a reference to a null script object.
|
||||
*/
|
||||
Object & NullObject();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve a reference to a null/empty script table.
|
||||
*/
|
||||
Table & NullTable();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve a reference to a null/empty script array.
|
||||
*/
|
||||
@@ -1120,54 +1305,6 @@ const Color3 & GetRandomColor();
|
||||
*/
|
||||
Color3 GetColor(CSStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
||||
* Primary logging functions.
|
||||
*/
|
||||
void LogDbg(CCStr fmt, ...);
|
||||
void LogUsr(CCStr fmt, ...);
|
||||
void LogScs(CCStr fmt, ...);
|
||||
void LogInf(CCStr fmt, ...);
|
||||
void LogWrn(CCStr fmt, ...);
|
||||
void LogErr(CCStr fmt, ...);
|
||||
void LogFtl(CCStr fmt, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
||||
* Secondary logging functions.
|
||||
*/
|
||||
void LogSDbg(CCStr fmt, ...);
|
||||
void LogSUsr(CCStr fmt, ...);
|
||||
void LogSScs(CCStr fmt, ...);
|
||||
void LogSInf(CCStr fmt, ...);
|
||||
void LogSWrn(CCStr fmt, ...);
|
||||
void LogSErr(CCStr fmt, ...);
|
||||
void LogSFtl(CCStr fmt, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
||||
* Primary conditional logging functions.
|
||||
*/
|
||||
bool cLogDbg(bool cond, CCStr fmt, ...);
|
||||
bool cLogUsr(bool cond, CCStr fmt, ...);
|
||||
bool cLogScs(bool cond, CCStr fmt, ...);
|
||||
bool cLogInf(bool cond, CCStr fmt, ...);
|
||||
bool cLogWrn(bool cond, CCStr fmt, ...);
|
||||
bool cLogErr(bool cond, CCStr fmt, ...);
|
||||
bool cLogFtl(bool cond, CCStr fmt, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
||||
* Secondary conditional logging functions.
|
||||
*/
|
||||
bool cLogSDbg(bool cond, CCStr fmt, ...);
|
||||
bool cLogSUsr(bool cond, CCStr fmt, ...);
|
||||
bool cLogSScs(bool cond, CCStr fmt, ...);
|
||||
bool cLogSInf(bool cond, CCStr fmt, ...);
|
||||
bool cLogSWrn(bool cond, CCStr fmt, ...);
|
||||
bool cLogSErr(bool cond, CCStr fmt, ...);
|
||||
bool cLogSFtl(bool cond, CCStr fmt, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Helper class allows the use of functions with ctype style as predicate for algorithms.
|
||||
*/
|
||||
@@ -1234,6 +1371,52 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Utility implementing RAII to toggle a bit mask on and off at all costs.
|
||||
*/
|
||||
template < typename T > struct BitGuard
|
||||
{
|
||||
private:
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* The lock to be toggled.
|
||||
*/
|
||||
T & m_Lock;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* The mask to be applied.
|
||||
*/
|
||||
T m_Mask;
|
||||
|
||||
public:
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
BitGuard(T & lock, T mask)
|
||||
: m_Lock(lock), m_Mask(mask)
|
||||
{
|
||||
// Apply the specified mask
|
||||
m_Lock |= m_Mask;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~BitGuard()
|
||||
{
|
||||
// In case one of the bits was turned off in the meantime
|
||||
m_Lock |= m_Mask;
|
||||
// Now turn off all the bits in the mask
|
||||
m_Lock ^= m_Mask;
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
typedef BitGuard< Uint8 > BitGuardU8;
|
||||
typedef BitGuard< Uint16 > BitGuardU16;
|
||||
typedef BitGuard< Uint32 > BitGuardU32;
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _BASE_SHARED_HPP_
|
||||
|
||||
@@ -20,7 +20,7 @@ SQChar Sphere::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Sphere::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("Sphere");
|
||||
static const SQChar name[] = _SC("Sphere");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ Sphere & Sphere::operator /= (const Sphere & s)
|
||||
Sphere & Sphere::operator %= (const Sphere & s)
|
||||
{
|
||||
pos %= s.pos;
|
||||
rad = fmod(rad, s.rad);
|
||||
rad = std::fmod(rad, s.rad);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ Sphere & Sphere::operator /= (Value r)
|
||||
|
||||
Sphere & Sphere::operator %= (Value r)
|
||||
{
|
||||
rad = fmod(rad, r);
|
||||
rad = std::fmod(rad, r);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ Sphere Sphere::operator / (const Sphere & s) const
|
||||
|
||||
Sphere Sphere::operator % (const Sphere & s) const
|
||||
{
|
||||
return Sphere(pos % s.pos, fmod(rad, s.rad));
|
||||
return Sphere(pos % s.pos, std::fmod(rad, s.rad));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -246,7 +246,7 @@ Sphere Sphere::operator / (Value r) const
|
||||
|
||||
Sphere Sphere::operator % (Value r) const
|
||||
{
|
||||
return Sphere(fmod(rad, r));
|
||||
return Sphere(std::fmod(rad, r));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -278,7 +278,7 @@ Sphere Sphere::operator % (const Vector3 & p) const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Sphere Sphere::operator + () const
|
||||
{
|
||||
return Sphere(pos.Abs(), fabs(rad));
|
||||
return Sphere(pos.Abs(), std::fabs(rad));
|
||||
}
|
||||
|
||||
Sphere Sphere::operator - () const
|
||||
@@ -321,11 +321,17 @@ bool Sphere::operator >= (const Sphere & s) const
|
||||
Int32 Sphere::Cmp(const Sphere & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -372,7 +378,7 @@ void Sphere::Set(Value nx, Value ny, Value nz, Value nr)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Sphere::Set(CSStr values, SQChar delim)
|
||||
{
|
||||
Set(GetSphere(values, delim));
|
||||
Set(Sphere::Get(values, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -385,17 +391,25 @@ void Sphere::Generate()
|
||||
void Sphere::Generate(Value min, Value max, bool r)
|
||||
{
|
||||
if (EpsLt(max, min))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
else if (r)
|
||||
{
|
||||
rad = GetRandomFloat32(min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos.Generate(min, max);
|
||||
}
|
||||
}
|
||||
|
||||
void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax)
|
||||
{
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax);
|
||||
}
|
||||
@@ -403,7 +417,9 @@ void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin
|
||||
void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value rmin, Value rmax)
|
||||
{
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(rmax, rmin))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax);
|
||||
rad = GetRandomFloat32(rmin, rmax);
|
||||
@@ -412,17 +428,17 @@ void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Sphere Sphere::Abs() const
|
||||
{
|
||||
return Sphere(pos.Abs(), fabs(rad));
|
||||
return Sphere(pos.Abs(), std::fabs(rad));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Sphere & GetSphere(CSStr str)
|
||||
const Sphere & Sphere::Get(CSStr str)
|
||||
{
|
||||
return GetSphere(str, Sphere::Delim);
|
||||
return Sphere::Get(str, Sphere::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Sphere & GetSphere(CSStr str, SQChar delim)
|
||||
const Sphere & Sphere::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
|
||||
@@ -439,104 +455,140 @@ const Sphere & GetSphere(CSStr str, SQChar delim)
|
||||
fs[9] = delim;
|
||||
fs[14] = delim;
|
||||
// Attempt to extract the component values from the specified string
|
||||
sscanf(str, fs, &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad);
|
||||
std::sscanf(str, fs, &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad);
|
||||
// Return the resulted value
|
||||
return sphere;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Sphere & GetSphere()
|
||||
{
|
||||
static Sphere sphere;
|
||||
sphere.Clear();
|
||||
return sphere;
|
||||
}
|
||||
|
||||
const Sphere & GetSphere(Float32 rv)
|
||||
{
|
||||
static Sphere sphere;
|
||||
sphere.Set(rv);
|
||||
return sphere;
|
||||
}
|
||||
|
||||
const Sphere & GetSphere(const Vector3 & pv, Float32 rv)
|
||||
{
|
||||
static Sphere sphere;
|
||||
sphere.Set(pv, rv);
|
||||
return sphere;
|
||||
}
|
||||
|
||||
const Sphere & GetSphere(Float32 xv, Float32 yv, Float32 zv, Float32 rv)
|
||||
{
|
||||
static Sphere sphere;
|
||||
sphere.Set(xv, yv, zv, rv);
|
||||
return sphere;
|
||||
}
|
||||
|
||||
const Sphere & GetSphere(const Sphere & o)
|
||||
{
|
||||
static Sphere sphere;
|
||||
sphere.Set(o);
|
||||
return sphere;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Sphere(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef Sphere::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("Sphere"), Class< Sphere >(vm, _SC("Sphere"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< const Vector3 &, Val >()
|
||||
.Ctor< Val, Val, Val, Val >()
|
||||
/* Static Members */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &Sphere::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("pos"), &Sphere::pos)
|
||||
.Var(_SC("rad"), &Sphere::rad)
|
||||
/* Properties */
|
||||
.Prop(_SC("abs"), &Sphere::Abs)
|
||||
/* Core Metamethods */
|
||||
// Member Variables
|
||||
.Var(_SC("Pos"), &Sphere::pos)
|
||||
.Var(_SC("Rad"), &Sphere::rad)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Sphere::Abs)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &Sphere::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Sphere::Typename)
|
||||
.Func(_SC("_cmp"), &Sphere::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_add"), &Sphere::operator +)
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_sub"), &Sphere::operator -)
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_mul"), &Sphere::operator *)
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_div"), &Sphere::operator /)
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_modulo"), &Sphere::operator %)
|
||||
.Func<Sphere (Sphere::*)(void) const>(_SC("_unm"), &Sphere::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (Sphere::*)(const Sphere &)>(_SC("Set"), &Sphere::Set)
|
||||
.Overload<void (Sphere::*)(const Vector3 &, Val)>(_SC("Set"), &Sphere::Set)
|
||||
.Overload<void (Sphere::*)(Val, Val, Val, Val)>(_SC("Set"), &Sphere::Set)
|
||||
.Overload<void (Sphere::*)(Val)>(_SC("SetRad"), &Sphere::Set)
|
||||
.Overload<void (Sphere::*)(const Vector3 &)>(_SC("SetVec3"), &Sphere::Set)
|
||||
.Overload<void (Sphere::*)(Val, Val, Val)>(_SC("SetVec3"), &Sphere::Set)
|
||||
.Overload<void (Sphere::*)(CSStr, SQChar)>(_SC("SetStr"), &Sphere::Set)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_add"), &Sphere::operator +)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_sub"), &Sphere::operator -)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_mul"), &Sphere::operator *)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_div"), &Sphere::operator /)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_modulo"), &Sphere::operator %)
|
||||
.Func< Sphere (Sphere::*)(void) const >(_SC("_unm"), &Sphere::operator -)
|
||||
// Setters
|
||||
.Overload< void (Sphere::*)(const Sphere &) >(_SC("Set"), &Sphere::Set)
|
||||
.Overload< void (Sphere::*)(const Vector3 &, Val) >(_SC("Set"), &Sphere::Set)
|
||||
.Overload< void (Sphere::*)(Val, Val, Val, Val) >(_SC("Set"), &Sphere::Set)
|
||||
.Overload< void (Sphere::*)(Val) >(_SC("SetRad"), &Sphere::Set)
|
||||
.Overload< void (Sphere::*)(const Vector3 &) >(_SC("SetVec3"), &Sphere::Set)
|
||||
.Overload< void (Sphere::*)(Val, Val, Val) >(_SC("SetVec3"), &Sphere::Set)
|
||||
.Overload< void (Sphere::*)(CSStr, SQChar) >(_SC("SetStr"), &Sphere::Set)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Sphere::Clear)
|
||||
/* Operator Exposure */
|
||||
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opAddAssign"), &Sphere::operator +=)
|
||||
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opSubAssign"), &Sphere::operator -=)
|
||||
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opMulAssign"), &Sphere::operator *=)
|
||||
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opDivAssign"), &Sphere::operator /=)
|
||||
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opModAssign"), &Sphere::operator %=)
|
||||
|
||||
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opAddAssignR"), &Sphere::operator +=)
|
||||
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opSubAssignR"), &Sphere::operator -=)
|
||||
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opMulAssignR"), &Sphere::operator *=)
|
||||
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opDivAssignR"), &Sphere::operator /=)
|
||||
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opModAssignR"), &Sphere::operator %=)
|
||||
|
||||
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opAddAssignP"), &Sphere::operator +=)
|
||||
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opSubAssignP"), &Sphere::operator -=)
|
||||
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opMulAssignP"), &Sphere::operator *=)
|
||||
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opDivAssignP"), &Sphere::operator /=)
|
||||
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opModAssignP"), &Sphere::operator %=)
|
||||
|
||||
.Func<Sphere & (Sphere::*)(void)>(_SC("opPreInc"), &Sphere::operator ++)
|
||||
.Func<Sphere & (Sphere::*)(void)>(_SC("opPreDec"), &Sphere::operator --)
|
||||
.Func<Sphere (Sphere::*)(int)>(_SC("opPostInc"), &Sphere::operator ++)
|
||||
.Func<Sphere (Sphere::*)(int)>(_SC("opPostDec"), &Sphere::operator --)
|
||||
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opAdd"), &Sphere::operator +)
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opSub"), &Sphere::operator -)
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opMul"), &Sphere::operator *)
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opDiv"), &Sphere::operator /)
|
||||
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opMod"), &Sphere::operator %)
|
||||
|
||||
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opAddR"), &Sphere::operator +)
|
||||
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opSubR"), &Sphere::operator -)
|
||||
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opMulR"), &Sphere::operator *)
|
||||
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opDivR"), &Sphere::operator /)
|
||||
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opModR"), &Sphere::operator %)
|
||||
|
||||
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opAddP"), &Sphere::operator +)
|
||||
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opSubP"), &Sphere::operator -)
|
||||
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opMulP"), &Sphere::operator *)
|
||||
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opDivP"), &Sphere::operator /)
|
||||
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opModP"), &Sphere::operator %)
|
||||
|
||||
.Func<Sphere (Sphere::*)(void) const>(_SC("opUnPlus"), &Sphere::operator +)
|
||||
.Func<Sphere (Sphere::*)(void) const>(_SC("opUnMinus"), &Sphere::operator -)
|
||||
|
||||
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opEqual"), &Sphere::operator ==)
|
||||
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opNotEqual"), &Sphere::operator !=)
|
||||
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opLessThan"), &Sphere::operator <)
|
||||
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opGreaterThan"), &Sphere::operator >)
|
||||
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opLessEqual"), &Sphere::operator <=)
|
||||
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opGreaterEqual"), &Sphere::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Sphere & (*)(CSStr) >(_SC("FromStr"), &GetSphere)
|
||||
.StaticOverload< const Sphere & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetSphere)
|
||||
.StaticOverload< const Sphere & (*)(CSStr) >(_SC("FromStr"), &Sphere::Get)
|
||||
.StaticOverload< const Sphere & (*)(CSStr, SQChar) >(_SC("FromStr"), &Sphere::Get)
|
||||
// Operator Exposure
|
||||
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opAddAssign"), &Sphere::operator +=)
|
||||
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opSubAssign"), &Sphere::operator -=)
|
||||
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opMulAssign"), &Sphere::operator *=)
|
||||
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opDivAssign"), &Sphere::operator /=)
|
||||
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opModAssign"), &Sphere::operator %=)
|
||||
|
||||
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opAddAssignR"), &Sphere::operator +=)
|
||||
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opSubAssignR"), &Sphere::operator -=)
|
||||
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opMulAssignR"), &Sphere::operator *=)
|
||||
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opDivAssignR"), &Sphere::operator /=)
|
||||
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opModAssignR"), &Sphere::operator %=)
|
||||
|
||||
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opAddAssignP"), &Sphere::operator +=)
|
||||
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opSubAssignP"), &Sphere::operator -=)
|
||||
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opMulAssignP"), &Sphere::operator *=)
|
||||
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opDivAssignP"), &Sphere::operator /=)
|
||||
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opModAssignP"), &Sphere::operator %=)
|
||||
|
||||
.Func< Sphere & (Sphere::*)(void) >(_SC("opPreInc"), &Sphere::operator ++)
|
||||
.Func< Sphere & (Sphere::*)(void) >(_SC("opPreDec"), &Sphere::operator --)
|
||||
.Func< Sphere (Sphere::*)(int) >(_SC("opPostInc"), &Sphere::operator ++)
|
||||
.Func< Sphere (Sphere::*)(int) >(_SC("opPostDec"), &Sphere::operator --)
|
||||
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opAdd"), &Sphere::operator +)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opSub"), &Sphere::operator -)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opMul"), &Sphere::operator *)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opDiv"), &Sphere::operator /)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opMod"), &Sphere::operator %)
|
||||
|
||||
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opAddR"), &Sphere::operator +)
|
||||
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opSubR"), &Sphere::operator -)
|
||||
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opMulR"), &Sphere::operator *)
|
||||
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opDivR"), &Sphere::operator /)
|
||||
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opModR"), &Sphere::operator %)
|
||||
|
||||
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opAddP"), &Sphere::operator +)
|
||||
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opSubP"), &Sphere::operator -)
|
||||
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opMulP"), &Sphere::operator *)
|
||||
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opDivP"), &Sphere::operator /)
|
||||
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opModP"), &Sphere::operator %)
|
||||
|
||||
.Func< Sphere (Sphere::*)(void) const >(_SC("opUnPlus"), &Sphere::operator +)
|
||||
.Func< Sphere (Sphere::*)(void) const >(_SC("opUnMinus"), &Sphere::operator -)
|
||||
|
||||
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opEqual"), &Sphere::operator ==)
|
||||
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opNotEqual"), &Sphere::operator !=)
|
||||
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opLessThan"), &Sphere::operator <)
|
||||
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opGreaterThan"), &Sphere::operator >)
|
||||
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opLessEqual"), &Sphere::operator <=)
|
||||
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opGreaterEqual"), &Sphere::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,16 +8,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Sphere type from a string.
|
||||
*/
|
||||
const Sphere & GetSphere(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Sphere type from a string.
|
||||
*/
|
||||
const Sphere & GetSphere(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to represent a three-dimensional sphere.
|
||||
*/
|
||||
@@ -393,6 +383,17 @@ struct Sphere
|
||||
* Retrieve a new instance of this type with absolute component values.
|
||||
*/
|
||||
Sphere Abs() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Sphere type from a string.
|
||||
*/
|
||||
static const Sphere & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Sphere type from a string.
|
||||
*/
|
||||
static const Sphere & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -21,7 +21,7 @@ SQChar Vector2::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Vector2::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("Vector2");
|
||||
static const SQChar name[] = _SC("Vector2");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -57,14 +57,14 @@ Vector2 & Vector2::operator = (Value s)
|
||||
|
||||
Vector2 & Vector2::operator = (CSStr values)
|
||||
{
|
||||
Set(GetVector2(values, Delim));
|
||||
Set(Vector2::Get(values, Delim));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2 & Vector2::operator = (const Vector2i & v)
|
||||
{
|
||||
x = static_cast<Value>(v.x);
|
||||
y = static_cast<Value>(v.y);
|
||||
x = ConvTo< Value >::From(v.x);
|
||||
y = ConvTo< Value >::From(v.y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ Vector2 & Vector2::operator /= (const Vector2 & v)
|
||||
|
||||
Vector2 & Vector2::operator %= (const Vector2 & v)
|
||||
{
|
||||
x = fmod(x, v.x);
|
||||
y = fmod(y, v.y);
|
||||
x = std::fmod(x, v.x);
|
||||
y = std::fmod(y, v.y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -135,8 +135,8 @@ Vector2 & Vector2::operator /= (Value s)
|
||||
|
||||
Vector2 & Vector2::operator %= (Value s)
|
||||
{
|
||||
x = fmod(x, s);
|
||||
y = fmod(y, s);
|
||||
x = std::fmod(x, s);
|
||||
y = std::fmod(y, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ Vector2 Vector2::operator / (const Vector2 & v) const
|
||||
|
||||
Vector2 Vector2::operator % (const Vector2 & v) const
|
||||
{
|
||||
return Vector2(fmod(x, v.x), fmod(y, v.y));
|
||||
return Vector2(std::fmod(x, v.x), std::fmod(y, v.y));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -221,13 +221,13 @@ Vector2 Vector2::operator / (Value s) const
|
||||
|
||||
Vector2 Vector2::operator % (Value s) const
|
||||
{
|
||||
return Vector2(fmod(x, s), fmod(y, s));
|
||||
return Vector2(std::fmod(x, s), std::fmod(y, s));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector2 Vector2::operator + () const
|
||||
{
|
||||
return Vector2(fabs(x), fabs(y));
|
||||
return Vector2(std::fabs(x), std::fabs(y));
|
||||
}
|
||||
|
||||
Vector2 Vector2::operator - () const
|
||||
@@ -270,11 +270,17 @@ bool Vector2::operator >= (const Vector2 & v) const
|
||||
Int32 Vector2::Cmp(const Vector2 & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -305,14 +311,14 @@ void Vector2::Set(const Vector2 & v)
|
||||
|
||||
void Vector2::Set(const Vector2i & v)
|
||||
{
|
||||
x = static_cast<Value>(v.x);
|
||||
y = static_cast<Value>(v.y);
|
||||
x = ConvTo< Value >::From(v.x);
|
||||
y = ConvTo< Value >::From(v.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector2::Set(CSStr values, SQChar delim)
|
||||
{
|
||||
Set(GetVector2(values, delim));
|
||||
Set(Vector2::Get(values, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -325,7 +331,9 @@ void Vector2::Generate()
|
||||
void Vector2::Generate(Value min, Value max)
|
||||
{
|
||||
if (EpsLt(max, min))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomFloat32(min, max);
|
||||
y = GetRandomFloat32(min, max);
|
||||
@@ -334,7 +342,9 @@ void Vector2::Generate(Value min, Value max)
|
||||
void Vector2::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
|
||||
{
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomFloat32(ymin, ymax);
|
||||
y = GetRandomFloat32(xmin, xmax);
|
||||
@@ -343,17 +353,17 @@ void Vector2::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector2 Vector2::Abs() const
|
||||
{
|
||||
return Vector2(fabs(x), fabs(y));
|
||||
return Vector2(std::fabs(x), std::fabs(y));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2 & GetVector2(CSStr str)
|
||||
const Vector2 & Vector2::Get(CSStr str)
|
||||
{
|
||||
return GetVector2(str, Vector2::Delim);
|
||||
return Vector2::Get(str, Vector2::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2 & GetVector2(CSStr str, SQChar delim)
|
||||
const Vector2 & Vector2::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %f , %f ");
|
||||
@@ -368,93 +378,122 @@ const Vector2 & GetVector2(CSStr str, SQChar delim)
|
||||
// Assign the specified delimiter
|
||||
fs[4] = delim;
|
||||
// Attempt to extract the component values from the specified string
|
||||
sscanf(str, fs, &vec.x, &vec.y);
|
||||
std::sscanf(str, fs, &vec.x, &vec.y);
|
||||
// Return the resulted value
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2 & GetVector2()
|
||||
{
|
||||
static Vector2 vec;
|
||||
vec.Clear();
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector2 & GetVector2(Float32 sv)
|
||||
{
|
||||
static Vector2 vec;
|
||||
vec.Set(sv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector2 & GetVector2(Float32 xv, Float32 yv)
|
||||
{
|
||||
static Vector2 vec;
|
||||
vec.Set(xv, yv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector2 & GetVector2(const Vector2 & o)
|
||||
{
|
||||
static Vector2 vec;
|
||||
vec.Set(o);
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Vector2(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef Vector2::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("Vector2"), Class< Vector2 >(vm, _SC("Vector2"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< Val, Val >()
|
||||
/* Static Members */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &Vector2::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("x"), &Vector2::x)
|
||||
.Var(_SC("y"), &Vector2::y)
|
||||
/* Properties */
|
||||
.Prop(_SC("abs"), &Vector2::Abs)
|
||||
/* Core Metamethods */
|
||||
// Member Variables
|
||||
.Var(_SC("X"), &Vector2::x)
|
||||
.Var(_SC("Y"), &Vector2::y)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Vector2::Abs)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &Vector2::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Vector2::Typename)
|
||||
.Func(_SC("_cmp"), &Vector2::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_add"), &Vector2::operator +)
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_sub"), &Vector2::operator -)
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_mul"), &Vector2::operator *)
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_div"), &Vector2::operator /)
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_modulo"), &Vector2::operator %)
|
||||
.Func<Vector2 (Vector2::*)(void) const>(_SC("_unm"), &Vector2::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (Vector2::*)(Val)>(_SC("Set"), &Vector2::Set)
|
||||
.Overload<void (Vector2::*)(Val, Val)>(_SC("Set"), &Vector2::Set)
|
||||
.Overload<void (Vector2::*)(const Vector2 &)>(_SC("SetVec2"), &Vector2::Set)
|
||||
.Overload<void (Vector2::*)(const Vector2i &)>(_SC("SetVec2i"), &Vector2::Set)
|
||||
.Overload<void (Vector2::*)(CSStr, SQChar)>(_SC("SetStr"), &Vector2::Set)
|
||||
/* Random Generators */
|
||||
.Overload<void (Vector2::*)(void)>(_SC("Generate"), &Vector2::Generate)
|
||||
.Overload<void (Vector2::*)(Val, Val)>(_SC("Generate"), &Vector2::Generate)
|
||||
.Overload<void (Vector2::*)(Val, Val, Val, Val)>(_SC("Generate"), &Vector2::Generate)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_add"), &Vector2::operator +)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_sub"), &Vector2::operator -)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_mul"), &Vector2::operator *)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_div"), &Vector2::operator /)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_modulo"), &Vector2::operator %)
|
||||
.Func< Vector2 (Vector2::*)(void) const >(_SC("_unm"), &Vector2::operator -)
|
||||
// Setters
|
||||
.Overload< void (Vector2::*)(Val) >(_SC("Set"), &Vector2::Set)
|
||||
.Overload< void (Vector2::*)(Val, Val) >(_SC("Set"), &Vector2::Set)
|
||||
.Overload< void (Vector2::*)(const Vector2 &) >(_SC("SetVec2"), &Vector2::Set)
|
||||
.Overload< void (Vector2::*)(const Vector2i &) >(_SC("SetVec2i"), &Vector2::Set)
|
||||
.Overload< void (Vector2::*)(CSStr, SQChar) >(_SC("SetStr"), &Vector2::Set)
|
||||
// Random Generators
|
||||
.Overload< void (Vector2::*)(void) >(_SC("Generate"), &Vector2::Generate)
|
||||
.Overload< void (Vector2::*)(Val, Val) >(_SC("Generate"), &Vector2::Generate)
|
||||
.Overload< void (Vector2::*)(Val, Val, Val, Val) >(_SC("Generate"), &Vector2::Generate)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Vector2::Clear)
|
||||
/* Operator Exposure */
|
||||
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opAddAssign"), &Vector2::operator +=)
|
||||
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opSubAssign"), &Vector2::operator -=)
|
||||
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opMulAssign"), &Vector2::operator *=)
|
||||
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opDivAssign"), &Vector2::operator /=)
|
||||
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opModAssign"), &Vector2::operator %=)
|
||||
|
||||
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opAddAssignS"), &Vector2::operator +=)
|
||||
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opSubAssignS"), &Vector2::operator -=)
|
||||
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opMulAssignS"), &Vector2::operator *=)
|
||||
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opDivAssignS"), &Vector2::operator /=)
|
||||
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opModAssignS"), &Vector2::operator %=)
|
||||
|
||||
.Func<Vector2 & (Vector2::*)(void)>(_SC("opPreInc"), &Vector2::operator ++)
|
||||
.Func<Vector2 & (Vector2::*)(void)>(_SC("opPreDec"), &Vector2::operator --)
|
||||
.Func<Vector2 (Vector2::*)(int)>(_SC("opPostInc"), &Vector2::operator ++)
|
||||
.Func<Vector2 (Vector2::*)(int)>(_SC("opPostDec"), &Vector2::operator --)
|
||||
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opAdd"), &Vector2::operator +)
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opSub"), &Vector2::operator -)
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opMul"), &Vector2::operator *)
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opDiv"), &Vector2::operator /)
|
||||
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opMod"), &Vector2::operator %)
|
||||
|
||||
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opAddS"), &Vector2::operator +)
|
||||
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opSubS"), &Vector2::operator -)
|
||||
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opMulS"), &Vector2::operator *)
|
||||
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opDivS"), &Vector2::operator /)
|
||||
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opModS"), &Vector2::operator %)
|
||||
|
||||
.Func<Vector2 (Vector2::*)(void) const>(_SC("opUnPlus"), &Vector2::operator +)
|
||||
.Func<Vector2 (Vector2::*)(void) const>(_SC("opUnMinus"), &Vector2::operator -)
|
||||
|
||||
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opEqual"), &Vector2::operator ==)
|
||||
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opNotEqual"), &Vector2::operator !=)
|
||||
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opLessThan"), &Vector2::operator <)
|
||||
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opGreaterThan"), &Vector2::operator >)
|
||||
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opLessEqual"), &Vector2::operator <=)
|
||||
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opGreaterEqual"), &Vector2::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Vector2 & (*)(CSStr) >(_SC("FromStr"), &GetVector2)
|
||||
.StaticOverload< const Vector2 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector2)
|
||||
.StaticOverload< const Vector2 & (*)(CSStr) >(_SC("FromStr"), &Vector2::Get)
|
||||
.StaticOverload< const Vector2 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector2::Get)
|
||||
// Operator Exposure
|
||||
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opAddAssign"), &Vector2::operator +=)
|
||||
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opSubAssign"), &Vector2::operator -=)
|
||||
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opMulAssign"), &Vector2::operator *=)
|
||||
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opDivAssign"), &Vector2::operator /=)
|
||||
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opModAssign"), &Vector2::operator %=)
|
||||
|
||||
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opAddAssignS"), &Vector2::operator +=)
|
||||
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opSubAssignS"), &Vector2::operator -=)
|
||||
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opMulAssignS"), &Vector2::operator *=)
|
||||
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opDivAssignS"), &Vector2::operator /=)
|
||||
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opModAssignS"), &Vector2::operator %=)
|
||||
|
||||
.Func< Vector2 & (Vector2::*)(void) >(_SC("opPreInc"), &Vector2::operator ++)
|
||||
.Func< Vector2 & (Vector2::*)(void) >(_SC("opPreDec"), &Vector2::operator --)
|
||||
.Func< Vector2 (Vector2::*)(int) >(_SC("opPostInc"), &Vector2::operator ++)
|
||||
.Func< Vector2 (Vector2::*)(int) >(_SC("opPostDec"), &Vector2::operator --)
|
||||
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opAdd"), &Vector2::operator +)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opSub"), &Vector2::operator -)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opMul"), &Vector2::operator *)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opDiv"), &Vector2::operator /)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opMod"), &Vector2::operator %)
|
||||
|
||||
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opAddS"), &Vector2::operator +)
|
||||
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opSubS"), &Vector2::operator -)
|
||||
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opMulS"), &Vector2::operator *)
|
||||
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opDivS"), &Vector2::operator /)
|
||||
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opModS"), &Vector2::operator %)
|
||||
|
||||
.Func< Vector2 (Vector2::*)(void) const >(_SC("opUnPlus"), &Vector2::operator +)
|
||||
.Func< Vector2 (Vector2::*)(void) const >(_SC("opUnMinus"), &Vector2::operator -)
|
||||
|
||||
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opEqual"), &Vector2::operator ==)
|
||||
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opNotEqual"), &Vector2::operator !=)
|
||||
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opLessThan"), &Vector2::operator <)
|
||||
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opGreaterThan"), &Vector2::operator >)
|
||||
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opLessEqual"), &Vector2::operator <=)
|
||||
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opGreaterEqual"), &Vector2::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2 type from a string.
|
||||
*/
|
||||
const Vector2 & GetVector2(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2 type from a string.
|
||||
*/
|
||||
const Vector2 & GetVector2(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to represent a two-dimensional vector.
|
||||
*/
|
||||
@@ -326,6 +316,17 @@ struct Vector2
|
||||
* Retrieve a new instance of this type with absolute component values.
|
||||
*/
|
||||
Vector2 Abs() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2 type from a string.
|
||||
*/
|
||||
static const Vector2 & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2 type from a string.
|
||||
*/
|
||||
static const Vector2 & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -21,7 +21,7 @@ SQChar Vector2i::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Vector2i::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("Vector2i");
|
||||
static const SQChar name[] = _SC("Vector2i");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -57,14 +57,14 @@ Vector2i & Vector2i::operator = (Value s)
|
||||
|
||||
Vector2i & Vector2i::operator = (CSStr values)
|
||||
{
|
||||
Set(GetVector2i(values, Delim));
|
||||
Set(Vector2i::Get(values, Delim));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2i & Vector2i::operator = (const Vector2 & v)
|
||||
{
|
||||
x = Value(v.x);
|
||||
y = Value(v.y);
|
||||
x = ConvTo< Value >::From(v.x);
|
||||
y = ConvTo< Value >::From(v.y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ Vector2i Vector2i::operator >> (Value s) const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector2i Vector2i::operator + () const
|
||||
{
|
||||
return Vector2i(abs(x), abs(y));
|
||||
return Vector2i(std::abs(x), std::abs(y));
|
||||
}
|
||||
|
||||
Vector2i Vector2i::operator - () const
|
||||
@@ -396,11 +396,17 @@ bool Vector2i::operator >= (const Vector2i & v) const
|
||||
Int32 Vector2i::Cmp(const Vector2i & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -431,14 +437,14 @@ void Vector2i::Set(const Vector2i & v)
|
||||
|
||||
void Vector2i::Set(const Vector2 & v)
|
||||
{
|
||||
x = Value(v.x);
|
||||
y = Value(v.y);
|
||||
x = ConvTo< Value >::From(v.x);
|
||||
y = ConvTo< Value >::From(v.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector2i::Set(CSStr values, SQChar delim)
|
||||
{
|
||||
Set(GetVector2i(values, delim));
|
||||
Set(Vector2i::Get(values, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -451,7 +457,9 @@ void Vector2i::Generate()
|
||||
void Vector2i::Generate(Value min, Value max)
|
||||
{
|
||||
if (max < min)
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomInt32(min, max);
|
||||
y = GetRandomInt32(min, max);
|
||||
@@ -460,7 +468,9 @@ void Vector2i::Generate(Value min, Value max)
|
||||
void Vector2i::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
|
||||
{
|
||||
if (xmax < xmin || ymax < ymin)
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomInt32(ymin, ymax);
|
||||
y = GetRandomInt32(xmin, xmax);
|
||||
@@ -469,17 +479,17 @@ void Vector2i::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector2i Vector2i::Abs() const
|
||||
{
|
||||
return Vector2i(abs(x), abs(y));
|
||||
return Vector2i(std::abs(x), std::abs(y));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2i & GetVector2i(CSStr str)
|
||||
const Vector2i & Vector2i::Get(CSStr str)
|
||||
{
|
||||
return GetVector2i(str, Vector2i::Delim);
|
||||
return Vector2i::Get(str, Vector2i::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2i & GetVector2i(CSStr str, SQChar delim)
|
||||
const Vector2i & Vector2i::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %d , %d ");
|
||||
@@ -494,114 +504,143 @@ const Vector2i & GetVector2i(CSStr str, SQChar delim)
|
||||
// Assign the specified delimiter
|
||||
fs[4] = delim;
|
||||
// Attempt to extract the component values from the specified string
|
||||
sscanf(str, &fs[0], &vec.x, &vec.y);
|
||||
std::sscanf(str, &fs[0], &vec.x, &vec.y);
|
||||
// Return the resulted value
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2i & GetVector2i()
|
||||
{
|
||||
static Vector2i vec;
|
||||
vec.Clear();
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector2i & GetVector2i(Int32 sv)
|
||||
{
|
||||
static Vector2i vec;
|
||||
vec.Set(sv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector2i & GetVector2i(Int32 xv, Int32 yv)
|
||||
{
|
||||
static Vector2i vec;
|
||||
vec.Set(xv, yv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector2i & GetVector2i(const Vector2i & o)
|
||||
{
|
||||
static Vector2i vec;
|
||||
vec.Set(o);
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Vector2i(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef Vector2i::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("Vector2i"), Class< Vector2i >(vm, _SC("Vector2i"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< Val, Val >()
|
||||
/* Static Members */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &Vector2i::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("x"), &Vector2i::x)
|
||||
.Var(_SC("y"), &Vector2i::y)
|
||||
/* Properties */
|
||||
.Prop(_SC("abs"), &Vector2i::Abs)
|
||||
/* Core Metamethods */
|
||||
// Member Variables
|
||||
.Var(_SC("X"), &Vector2i::x)
|
||||
.Var(_SC("Y"), &Vector2i::y)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Vector2i::Abs)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &Vector2i::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Vector2i::Typename)
|
||||
.Func(_SC("_cmp"), &Vector2i::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_add"), &Vector2i::operator +)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_sub"), &Vector2i::operator -)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_mul"), &Vector2i::operator *)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_div"), &Vector2i::operator /)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_modulo"), &Vector2i::operator %)
|
||||
.Func<Vector2i (Vector2i::*)(void) const>(_SC("_unm"), &Vector2i::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (Vector2i::*)(Val)>(_SC("Set"), &Vector2i::Set)
|
||||
.Overload<void (Vector2i::*)(Val, Val)>(_SC("Set"), &Vector2i::Set)
|
||||
.Overload<void (Vector2i::*)(const Vector2i &)>(_SC("SetVec2i"), &Vector2i::Set)
|
||||
.Overload<void (Vector2i::*)(const Vector2 &)>(_SC("SetVec2"), &Vector2i::Set)
|
||||
.Overload<void (Vector2i::*)(CSStr, SQChar)>(_SC("SetStr"), &Vector2i::Set)
|
||||
/* Random Generators */
|
||||
.Overload<void (Vector2i::*)(void)>(_SC("Generate"), &Vector2i::Generate)
|
||||
.Overload<void (Vector2i::*)(Val, Val)>(_SC("Generate"), &Vector2i::Generate)
|
||||
.Overload<void (Vector2i::*)(Val, Val, Val, Val)>(_SC("Generate"), &Vector2i::Generate)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_add"), &Vector2i::operator +)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_sub"), &Vector2i::operator -)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_mul"), &Vector2i::operator *)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_div"), &Vector2i::operator /)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_modulo"), &Vector2i::operator %)
|
||||
.Func< Vector2i (Vector2i::*)(void) const >(_SC("_unm"), &Vector2i::operator -)
|
||||
// Setters
|
||||
.Overload< void (Vector2i::*)(Val) >(_SC("Set"), &Vector2i::Set)
|
||||
.Overload< void (Vector2i::*)(Val, Val) >(_SC("Set"), &Vector2i::Set)
|
||||
.Overload< void (Vector2i::*)(const Vector2i &) >(_SC("SetVec2i"), &Vector2i::Set)
|
||||
.Overload< void (Vector2i::*)(const Vector2 &) >(_SC("SetVec2"), &Vector2i::Set)
|
||||
.Overload< void (Vector2i::*)(CSStr, SQChar) >(_SC("SetStr"), &Vector2i::Set)
|
||||
// Random Generators
|
||||
.Overload< void (Vector2i::*)(void) >(_SC("Generate"), &Vector2i::Generate)
|
||||
.Overload< void (Vector2i::*)(Val, Val) >(_SC("Generate"), &Vector2i::Generate)
|
||||
.Overload< void (Vector2i::*)(Val, Val, Val, Val) >(_SC("Generate"), &Vector2i::Generate)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Vector2i::Clear)
|
||||
/* Operator Exposure */
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opAddAssign"), &Vector2i::operator +=)
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opSubAssign"), &Vector2i::operator -=)
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opMulAssign"), &Vector2i::operator *=)
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opDivAssign"), &Vector2i::operator /=)
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opModAssign"), &Vector2i::operator %=)
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opAndAssign"), &Vector2i::operator &=)
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opOrAssign"), &Vector2i::operator |=)
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opXorAssign"), &Vector2i::operator ^=)
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opShlAssign"), &Vector2i::operator <<=)
|
||||
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opShrAssign"), &Vector2i::operator >>=)
|
||||
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opAddAssignS"), &Vector2i::operator +=)
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opSubAssignS"), &Vector2i::operator -=)
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opMulAssignS"), &Vector2i::operator *=)
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opDivAssignS"), &Vector2i::operator /=)
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opModAssignS"), &Vector2i::operator %=)
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opAndAssignS"), &Vector2i::operator &=)
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opOrAssignS"), &Vector2i::operator |=)
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opXorAssignS"), &Vector2i::operator ^=)
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opShlAssignS"), &Vector2i::operator <<=)
|
||||
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opShrAssignS"), &Vector2i::operator >>=)
|
||||
|
||||
.Func<Vector2i & (Vector2i::*)(void)>(_SC("opPreInc"), &Vector2i::operator ++)
|
||||
.Func<Vector2i & (Vector2i::*)(void)>(_SC("opPreDec"), &Vector2i::operator --)
|
||||
.Func<Vector2i (Vector2i::*)(int)>(_SC("opPostInc"), &Vector2i::operator ++)
|
||||
.Func<Vector2i (Vector2i::*)(int)>(_SC("opPostDec"), &Vector2i::operator --)
|
||||
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opAdd"), &Vector2i::operator +)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opSub"), &Vector2i::operator -)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opMul"), &Vector2i::operator *)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opDiv"), &Vector2i::operator /)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opMod"), &Vector2i::operator %)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opAnd"), &Vector2i::operator &)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opOr"), &Vector2i::operator |)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opShl"), &Vector2i::operator ^)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opShl"), &Vector2i::operator <<)
|
||||
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opShr"), &Vector2i::operator >>)
|
||||
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opAddS"), &Vector2i::operator +)
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opSubS"), &Vector2i::operator -)
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opMulS"), &Vector2i::operator *)
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opDivS"), &Vector2i::operator /)
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opModS"), &Vector2i::operator %)
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opAndS"), &Vector2i::operator &)
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opOrS"), &Vector2i::operator |)
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opShlS"), &Vector2i::operator ^)
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opShlS"), &Vector2i::operator <<)
|
||||
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opShrS"), &Vector2i::operator >>)
|
||||
|
||||
.Func<Vector2i (Vector2i::*)(void) const>(_SC("opUnPlus"), &Vector2i::operator +)
|
||||
.Func<Vector2i (Vector2i::*)(void) const>(_SC("opUnMinus"), &Vector2i::operator -)
|
||||
.Func<Vector2i (Vector2i::*)(void) const>(_SC("opCom"), &Vector2i::operator ~)
|
||||
|
||||
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opEqual"), &Vector2i::operator ==)
|
||||
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opNotEqual"), &Vector2i::operator !=)
|
||||
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opLessThan"), &Vector2i::operator <)
|
||||
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opGreaterThan"), &Vector2i::operator >)
|
||||
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opLessEqual"), &Vector2i::operator <=)
|
||||
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opGreaterEqual"), &Vector2i::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Vector2i & (*)(CSStr) >(_SC("FromStr"), &GetVector2i)
|
||||
.StaticOverload< const Vector2i & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector2i)
|
||||
.StaticOverload< const Vector2i & (*)(CSStr) >(_SC("FromStr"), &Vector2i::Get)
|
||||
.StaticOverload< const Vector2i & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector2i::Get)
|
||||
// Operator Exposure
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opAddAssign"), &Vector2i::operator +=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opSubAssign"), &Vector2i::operator -=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opMulAssign"), &Vector2i::operator *=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opDivAssign"), &Vector2i::operator /=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opModAssign"), &Vector2i::operator %=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opAndAssign"), &Vector2i::operator &=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opOrAssign"), &Vector2i::operator |=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opXorAssign"), &Vector2i::operator ^=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opShlAssign"), &Vector2i::operator <<=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opShrAssign"), &Vector2i::operator >>=)
|
||||
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opAddAssignS"), &Vector2i::operator +=)
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opSubAssignS"), &Vector2i::operator -=)
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opMulAssignS"), &Vector2i::operator *=)
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opDivAssignS"), &Vector2i::operator /=)
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opModAssignS"), &Vector2i::operator %=)
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opAndAssignS"), &Vector2i::operator &=)
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opOrAssignS"), &Vector2i::operator |=)
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opXorAssignS"), &Vector2i::operator ^=)
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opShlAssignS"), &Vector2i::operator <<=)
|
||||
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opShrAssignS"), &Vector2i::operator >>=)
|
||||
|
||||
.Func< Vector2i & (Vector2i::*)(void) >(_SC("opPreInc"), &Vector2i::operator ++)
|
||||
.Func< Vector2i & (Vector2i::*)(void) >(_SC("opPreDec"), &Vector2i::operator --)
|
||||
.Func< Vector2i (Vector2i::*)(int) >(_SC("opPostInc"), &Vector2i::operator ++)
|
||||
.Func< Vector2i (Vector2i::*)(int) >(_SC("opPostDec"), &Vector2i::operator --)
|
||||
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opAdd"), &Vector2i::operator +)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opSub"), &Vector2i::operator -)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opMul"), &Vector2i::operator *)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opDiv"), &Vector2i::operator /)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opMod"), &Vector2i::operator %)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opAnd"), &Vector2i::operator &)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opOr"), &Vector2i::operator |)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opShl"), &Vector2i::operator ^)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opShl"), &Vector2i::operator <<)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opShr"), &Vector2i::operator >>)
|
||||
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opAddS"), &Vector2i::operator +)
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opSubS"), &Vector2i::operator -)
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opMulS"), &Vector2i::operator *)
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opDivS"), &Vector2i::operator /)
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opModS"), &Vector2i::operator %)
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opAndS"), &Vector2i::operator &)
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opOrS"), &Vector2i::operator |)
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opShlS"), &Vector2i::operator ^)
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opShlS"), &Vector2i::operator <<)
|
||||
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opShrS"), &Vector2i::operator >>)
|
||||
|
||||
.Func< Vector2i (Vector2i::*)(void) const >(_SC("opUnPlus"), &Vector2i::operator +)
|
||||
.Func< Vector2i (Vector2i::*)(void) const >(_SC("opUnMinus"), &Vector2i::operator -)
|
||||
.Func< Vector2i (Vector2i::*)(void) const >(_SC("opCom"), &Vector2i::operator ~)
|
||||
|
||||
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opEqual"), &Vector2i::operator ==)
|
||||
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opNotEqual"), &Vector2i::operator !=)
|
||||
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opLessThan"), &Vector2i::operator <)
|
||||
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opGreaterThan"), &Vector2i::operator >)
|
||||
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opLessEqual"), &Vector2i::operator <=)
|
||||
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opGreaterEqual"), &Vector2i::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2i type from a string.
|
||||
*/
|
||||
const Vector2i & GetVector2i(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2i type from a string.
|
||||
*/
|
||||
const Vector2i & GetVector2i(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to represent a two-dimensional vector using integral values.
|
||||
*/
|
||||
@@ -431,6 +421,17 @@ struct Vector2i
|
||||
* Retrieve a new instance of this type with absolute component values.
|
||||
*/
|
||||
Vector2i Abs() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2i type from a string.
|
||||
*/
|
||||
static const Vector2i & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2i type from a string.
|
||||
*/
|
||||
static const Vector2i & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -22,7 +22,7 @@ SQChar Vector3::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Vector3::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("Vector3");
|
||||
static const SQChar name[] = _SC("Vector3");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -108,9 +108,9 @@ Vector3 & Vector3::operator /= (const Vector3 & v)
|
||||
|
||||
Vector3 & Vector3::operator %= (const Vector3 & v)
|
||||
{
|
||||
x = fmod(x, v.x);
|
||||
y = fmod(y, v.y);
|
||||
z = fmod(z, v.z);
|
||||
x = std::fmod(x, v.x);
|
||||
y = std::fmod(y, v.y);
|
||||
z = std::fmod(z, v.z);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -149,9 +149,9 @@ Vector3 & Vector3::operator /= (Value s)
|
||||
|
||||
Vector3 & Vector3::operator %= (Value s)
|
||||
{
|
||||
x = fmod(x, s);
|
||||
y = fmod(y, s);
|
||||
z = fmod(z, s);
|
||||
x = std::fmod(x, s);
|
||||
y = std::fmod(y, s);
|
||||
z = std::fmod(z, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ Vector3 Vector3::operator / (const Vector3 & v) const
|
||||
|
||||
Vector3 Vector3::operator % (const Vector3 & v) const
|
||||
{
|
||||
return Vector3(fmod(x, v.x), fmod(y, v.y), fmod(z, v.z));
|
||||
return Vector3(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -240,13 +240,13 @@ Vector3 Vector3::operator / (Value s) const
|
||||
|
||||
Vector3 Vector3::operator % (Value s) const
|
||||
{
|
||||
return Vector3(fmod(x, s), fmod(y, s), fmod(z, s));
|
||||
return Vector3(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3 Vector3::operator + () const
|
||||
{
|
||||
return Vector3(fabs(x), fabs(y), fabs(z));
|
||||
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
|
||||
}
|
||||
|
||||
Vector3 Vector3::operator - () const
|
||||
@@ -289,11 +289,17 @@ bool Vector3::operator >= (const Vector3 & v) const
|
||||
Int32 Vector3::Cmp(const Vector3 & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -342,7 +348,7 @@ void Vector3::Set(const Quaternion & q)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector3::Set(CSStr values, SQChar delim)
|
||||
{
|
||||
Set(GetVector3(values, delim));
|
||||
Set(Vector3::Get(values, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -356,7 +362,9 @@ void Vector3::Generate()
|
||||
void Vector3::Generate(Value min, Value max)
|
||||
{
|
||||
if (EpsLt(max, min))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomFloat32(min, max);
|
||||
y = GetRandomFloat32(min, max);
|
||||
@@ -366,7 +374,9 @@ void Vector3::Generate(Value min, Value max)
|
||||
void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax)
|
||||
{
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomFloat32(xmin, xmax);
|
||||
y = GetRandomFloat32(ymin, ymax);
|
||||
@@ -376,17 +386,17 @@ void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmi
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3 Vector3::Abs() const
|
||||
{
|
||||
return Vector3(fabs(x), fabs(y), fabs(z));
|
||||
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector3 & GetVector3(CSStr str)
|
||||
const Vector3 & Vector3::Get(CSStr str)
|
||||
{
|
||||
return GetVector3(str, Vector3::Delim);
|
||||
return Vector3::Get(str, Vector3::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector3 & GetVector3(CSStr str, SQChar delim)
|
||||
const Vector3 & Vector3::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %f , %f , %f ");
|
||||
@@ -402,95 +412,124 @@ const Vector3 & GetVector3(CSStr str, SQChar delim)
|
||||
fs[4] = delim;
|
||||
fs[9] = delim;
|
||||
// Attempt to extract the component values from the specified string
|
||||
sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z);
|
||||
std::sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z);
|
||||
// Return the resulted value
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector3 & GetVector3()
|
||||
{
|
||||
static Vector3 vec;
|
||||
vec.Clear();
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector3 & GetVector3(Float32 sv)
|
||||
{
|
||||
static Vector3 vec;
|
||||
vec.Set(sv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector3 & GetVector3(Float32 xv, Float32 yv, Float32 zv)
|
||||
{
|
||||
static Vector3 vec;
|
||||
vec.Set(xv, yv, zv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector3 & GetVector3(const Vector3 & o)
|
||||
{
|
||||
static Vector3 vec;
|
||||
vec.Set(o);
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Vector3(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef Vector3::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("Vector3"), Class< Vector3 >(vm, _SC("Vector3"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< Val, Val, Val >()
|
||||
/* Static Members */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &Vector3::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("x"), &Vector3::x)
|
||||
.Var(_SC("y"), &Vector3::y)
|
||||
.Var(_SC("z"), &Vector3::z)
|
||||
/* Properties */
|
||||
.Prop(_SC("abs"), &Vector3::Abs)
|
||||
/* Core Metamethods */
|
||||
// Member Variables
|
||||
.Var(_SC("X"), &Vector3::x)
|
||||
.Var(_SC("Y"), &Vector3::y)
|
||||
.Var(_SC("Z"), &Vector3::z)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Vector3::Abs)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &Vector3::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Vector3::Typename)
|
||||
.Func(_SC("_cmp"), &Vector3::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_add"), &Vector3::operator +)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_sub"), &Vector3::operator -)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_mul"), &Vector3::operator *)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_div"), &Vector3::operator /)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_modulo"), &Vector3::operator %)
|
||||
.Func<Vector3 (Vector3::*)(void) const>(_SC("_unm"), &Vector3::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (Vector3::*)(Val)>(_SC("Set"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(Val, Val, Val)>(_SC("Set"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const Vector3 &)>(_SC("SetVec3"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const Vector4 &)>(_SC("SetVec4"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const Quaternion &)>(_SC("SetQuat"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(CSStr, SQChar)>(_SC("SetStr"), &Vector3::Set)
|
||||
/* Random Generators */
|
||||
.Overload<void (Vector3::*)(void)>(_SC("Generate"), &Vector3::Generate)
|
||||
.Overload<void (Vector3::*)(Val, Val)>(_SC("Generate"), &Vector3::Generate)
|
||||
.Overload<void (Vector3::*)(Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Vector3::Generate)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_add"), &Vector3::operator +)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_sub"), &Vector3::operator -)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_mul"), &Vector3::operator *)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_div"), &Vector3::operator /)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_modulo"), &Vector3::operator %)
|
||||
.Func< Vector3 (Vector3::*)(void) const >(_SC("_unm"), &Vector3::operator -)
|
||||
// Setters
|
||||
.Overload< void (Vector3::*)(Val) >(_SC("Set"), &Vector3::Set)
|
||||
.Overload< void (Vector3::*)(Val, Val, Val) >(_SC("Set"), &Vector3::Set)
|
||||
.Overload< void (Vector3::*)(const Vector3 &) >(_SC("SetVec3"), &Vector3::Set)
|
||||
.Overload< void (Vector3::*)(const Vector4 &) >(_SC("SetVec4"), &Vector3::Set)
|
||||
.Overload< void (Vector3::*)(const Quaternion &) >(_SC("SetQuat"), &Vector3::Set)
|
||||
.Overload< void (Vector3::*)(CSStr, SQChar) >(_SC("SetStr"), &Vector3::Set)
|
||||
// Random Generators
|
||||
.Overload< void (Vector3::*)(void) >(_SC("Generate"), &Vector3::Generate)
|
||||
.Overload< void (Vector3::*)(Val, Val) >(_SC("Generate"), &Vector3::Generate)
|
||||
.Overload< void (Vector3::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Vector3::Generate)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Vector3::Clear)
|
||||
/* Operator Exposure */
|
||||
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opAddAssign"), &Vector3::operator +=)
|
||||
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opSubAssign"), &Vector3::operator -=)
|
||||
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opMulAssign"), &Vector3::operator *=)
|
||||
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opDivAssign"), &Vector3::operator /=)
|
||||
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opModAssign"), &Vector3::operator %=)
|
||||
|
||||
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opAddAssignS"), &Vector3::operator +=)
|
||||
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opSubAssignS"), &Vector3::operator -=)
|
||||
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opMulAssignS"), &Vector3::operator *=)
|
||||
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opDivAssignS"), &Vector3::operator /=)
|
||||
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opModAssignS"), &Vector3::operator %=)
|
||||
|
||||
.Func<Vector3 & (Vector3::*)(void)>(_SC("opPreInc"), &Vector3::operator ++)
|
||||
.Func<Vector3 & (Vector3::*)(void)>(_SC("opPreDec"), &Vector3::operator --)
|
||||
.Func<Vector3 (Vector3::*)(int)>(_SC("opPostInc"), &Vector3::operator ++)
|
||||
.Func<Vector3 (Vector3::*)(int)>(_SC("opPostDec"), &Vector3::operator --)
|
||||
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opAdd"), &Vector3::operator +)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opSub"), &Vector3::operator -)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opMul"), &Vector3::operator *)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opDiv"), &Vector3::operator /)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opMod"), &Vector3::operator %)
|
||||
|
||||
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opAddS"), &Vector3::operator +)
|
||||
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opSubS"), &Vector3::operator -)
|
||||
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opMulS"), &Vector3::operator *)
|
||||
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opDivS"), &Vector3::operator /)
|
||||
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opModS"), &Vector3::operator %)
|
||||
|
||||
.Func<Vector3 (Vector3::*)(void) const>(_SC("opUnPlus"), &Vector3::operator +)
|
||||
.Func<Vector3 (Vector3::*)(void) const>(_SC("opUnMinus"), &Vector3::operator -)
|
||||
|
||||
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opEqual"), &Vector3::operator ==)
|
||||
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opNotEqual"), &Vector3::operator !=)
|
||||
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opLessThan"), &Vector3::operator <)
|
||||
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterThan"), &Vector3::operator >)
|
||||
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opLessEqual"), &Vector3::operator <=)
|
||||
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterEqual"), &Vector3::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Vector3 & (*)(CSStr) >(_SC("FromStr"), &GetVector3)
|
||||
.StaticOverload< const Vector3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector3)
|
||||
.StaticOverload< const Vector3 & (*)(CSStr) >(_SC("FromStr"), &Vector3::Get)
|
||||
.StaticOverload< const Vector3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector3::Get)
|
||||
// Operator Exposure
|
||||
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opAddAssign"), &Vector3::operator +=)
|
||||
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opSubAssign"), &Vector3::operator -=)
|
||||
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opMulAssign"), &Vector3::operator *=)
|
||||
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opDivAssign"), &Vector3::operator /=)
|
||||
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opModAssign"), &Vector3::operator %=)
|
||||
|
||||
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opAddAssignS"), &Vector3::operator +=)
|
||||
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opSubAssignS"), &Vector3::operator -=)
|
||||
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opMulAssignS"), &Vector3::operator *=)
|
||||
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opDivAssignS"), &Vector3::operator /=)
|
||||
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opModAssignS"), &Vector3::operator %=)
|
||||
|
||||
.Func< Vector3 & (Vector3::*)(void) >(_SC("opPreInc"), &Vector3::operator ++)
|
||||
.Func< Vector3 & (Vector3::*)(void) >(_SC("opPreDec"), &Vector3::operator --)
|
||||
.Func< Vector3 (Vector3::*)(int) >(_SC("opPostInc"), &Vector3::operator ++)
|
||||
.Func< Vector3 (Vector3::*)(int) >(_SC("opPostDec"), &Vector3::operator --)
|
||||
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opAdd"), &Vector3::operator +)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opSub"), &Vector3::operator -)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opMul"), &Vector3::operator *)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opDiv"), &Vector3::operator /)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opMod"), &Vector3::operator %)
|
||||
|
||||
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opAddS"), &Vector3::operator +)
|
||||
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opSubS"), &Vector3::operator -)
|
||||
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opMulS"), &Vector3::operator *)
|
||||
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opDivS"), &Vector3::operator /)
|
||||
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opModS"), &Vector3::operator %)
|
||||
|
||||
.Func< Vector3 (Vector3::*)(void) const >(_SC("opUnPlus"), &Vector3::operator +)
|
||||
.Func< Vector3 (Vector3::*)(void) const >(_SC("opUnMinus"), &Vector3::operator -)
|
||||
|
||||
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opEqual"), &Vector3::operator ==)
|
||||
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opNotEqual"), &Vector3::operator !=)
|
||||
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opLessThan"), &Vector3::operator <)
|
||||
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opGreaterThan"), &Vector3::operator >)
|
||||
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opLessEqual"), &Vector3::operator <=)
|
||||
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opGreaterEqual"), &Vector3::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector3 type from a string.
|
||||
*/
|
||||
const Vector3 & GetVector3(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector3 type from a string.
|
||||
*/
|
||||
const Vector3 & GetVector3(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to represent a three-dimensional vector.
|
||||
*/
|
||||
@@ -331,6 +321,17 @@ struct Vector3
|
||||
* Retrieve a new instance of this type with absolute component values.
|
||||
*/
|
||||
Vector3 Abs() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector3 type from a string.
|
||||
*/
|
||||
static const Vector3 & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector3 type from a string.
|
||||
*/
|
||||
static const Vector3 & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -22,7 +22,7 @@ SQChar Vector4::Delim = ',';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Vector4::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("Vector4");
|
||||
static const SQChar name[] = _SC("Vector4");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -122,10 +122,10 @@ Vector4 & Vector4::operator /= (const Vector4 & v)
|
||||
|
||||
Vector4 & Vector4::operator %= (const Vector4 & v)
|
||||
{
|
||||
x = fmod(x, v.x);
|
||||
y = fmod(y, v.y);
|
||||
z = fmod(z, v.z);
|
||||
w = fmod(w, v.w);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -168,10 +168,10 @@ Vector4 & Vector4::operator /= (Value s)
|
||||
|
||||
Vector4 & Vector4::operator %= (Value s)
|
||||
{
|
||||
x = fmod(x, s);
|
||||
y = fmod(y, s);
|
||||
z = fmod(z, s);
|
||||
w = fmod(w, s);
|
||||
x = std::fmod(x, s);
|
||||
y = std::fmod(y, s);
|
||||
z = std::fmod(z, s);
|
||||
w = std::fmod(w, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ Vector4 Vector4::operator / (const Vector4 & v) const
|
||||
|
||||
Vector4 Vector4::operator % (const Vector4 & v) const
|
||||
{
|
||||
return Vector4(fmod(x, v.x), fmod(y, v.y), fmod(z, v.z), fmod(w, v.w));
|
||||
return Vector4(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z), std::fmod(w, v.w));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -264,13 +264,13 @@ Vector4 Vector4::operator / (Value s) const
|
||||
|
||||
Vector4 Vector4::operator % (Value s) const
|
||||
{
|
||||
return Vector4(fmod(x, s), fmod(y, s), fmod(z, s), fmod(w, s));
|
||||
return Vector4(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator + () const
|
||||
{
|
||||
return Vector4(fabs(x), fabs(y), fabs(z), fabs(w));
|
||||
return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator - () const
|
||||
@@ -313,11 +313,17 @@ bool Vector4::operator >= (const Vector4 & v) const
|
||||
Int32 Vector4::Cmp(const Vector4 & o) const
|
||||
{
|
||||
if (*this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*this > o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -378,7 +384,7 @@ void Vector4::Set(const Quaternion & q)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::Set(CSStr values, SQChar delim)
|
||||
{
|
||||
Set(GetVector4(values, delim));
|
||||
Set(Vector4::Get(values, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -393,7 +399,9 @@ void Vector4::Generate()
|
||||
void Vector4::Generate(Value min, Value max)
|
||||
{
|
||||
if (max < min)
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomFloat32(min, max);
|
||||
y = GetRandomFloat32(min, max);
|
||||
@@ -404,7 +412,9 @@ void Vector4::Generate(Value min, Value max)
|
||||
void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
|
||||
{
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
|
||||
{
|
||||
STHROWF("max value is lower than min value");
|
||||
}
|
||||
|
||||
x = GetRandomFloat32(xmin, xmax);
|
||||
y = GetRandomFloat32(ymin, ymax);
|
||||
@@ -415,17 +425,17 @@ void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmi
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::Abs() const
|
||||
{
|
||||
return Vector4(fabs(x), fabs(y), fabs(z), fabs(w));
|
||||
return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector4 & GetVector4(CSStr str)
|
||||
const Vector4 & Vector4::Get(CSStr str)
|
||||
{
|
||||
return GetVector4(str, Vector4::Delim);
|
||||
return Vector4::Get(str, Vector4::Delim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector4 & GetVector4(CSStr str, SQChar delim)
|
||||
const Vector4 & Vector4::Get(CSStr str, SQChar delim)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
|
||||
@@ -442,98 +452,134 @@ const Vector4 & GetVector4(CSStr str, SQChar delim)
|
||||
fs[9] = delim;
|
||||
fs[14] = delim;
|
||||
// Attempt to extract the component values from the specified string
|
||||
sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w);
|
||||
std::sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w);
|
||||
// Return the resulted value
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector4 & GetVector4()
|
||||
{
|
||||
static Vector4 vec;
|
||||
vec.Clear();
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector4 & GetVector4(Float32 sv)
|
||||
{
|
||||
static Vector4 vec;
|
||||
vec.Set(sv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv)
|
||||
{
|
||||
static Vector4 vec;
|
||||
vec.Set(xv, yv, zv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv, Float32 wv)
|
||||
{
|
||||
static Vector4 vec;
|
||||
vec.Set(xv, yv, zv, wv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
const Vector4 & GetVector4(const Vector4 & o)
|
||||
{
|
||||
static Vector4 vec;
|
||||
vec.Set(o);
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Vector4(HSQUIRRELVM vm)
|
||||
{
|
||||
typedef Vector4::Value Val;
|
||||
|
||||
RootTable(vm).Bind(_SC("Vector4"), Class< Vector4 >(vm, _SC("Vector4"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< Val >()
|
||||
.Ctor< Val, Val, Val >()
|
||||
.Ctor< Val, Val, Val, Val >()
|
||||
/* Static Members */
|
||||
// Static Members
|
||||
.SetStaticValue(_SC("Delim"), &Vector4::Delim)
|
||||
/* Member Variables */
|
||||
// Member Variables
|
||||
.Var(_SC("x"), &Vector4::x)
|
||||
.Var(_SC("y"), &Vector4::y)
|
||||
.Var(_SC("z"), &Vector4::z)
|
||||
.Var(_SC("w"), &Vector4::w)
|
||||
/* Properties */
|
||||
.Prop(_SC("abs"), &Vector4::Abs)
|
||||
/* Core Metamethods */
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Vector4::Abs)
|
||||
// Core Metamethods
|
||||
.Func(_SC("_tostring"), &Vector4::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Vector4::Typename)
|
||||
.Func(_SC("_cmp"), &Vector4::Cmp)
|
||||
/* Metamethods */
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_add"), &Vector4::operator +)
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_sub"), &Vector4::operator -)
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_mul"), &Vector4::operator *)
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_div"), &Vector4::operator /)
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_modulo"), &Vector4::operator %)
|
||||
.Func<Vector4 (Vector4::*)(void) const>(_SC("_unm"), &Vector4::operator -)
|
||||
/* Setters */
|
||||
.Overload<void (Vector4::*)(Val)>(_SC("Set"), &Vector4::Set)
|
||||
.Overload<void (Vector4::*)(Val, Val, Val)>(_SC("Set"), &Vector4::Set)
|
||||
.Overload<void (Vector4::*)(Val, Val, Val, Val)>(_SC("Set"), &Vector4::Set)
|
||||
.Overload<void (Vector4::*)(const Vector4 &)>(_SC("SetVec4"), &Vector4::Set)
|
||||
.Overload<void (Vector4::*)(const Vector3 &)>(_SC("SetVec3"), &Vector4::Set)
|
||||
.Overload<void (Vector4::*)(const Quaternion &)>(_SC("SetQuat"), &Vector4::Set)
|
||||
.Overload<void (Vector4::*)(CSStr, SQChar)>(_SC("SetStr"), &Vector4::Set)
|
||||
/* Random Generators */
|
||||
.Overload<void (Vector4::*)(void)>(_SC("Generate"), &Vector4::Generate)
|
||||
.Overload<void (Vector4::*)(Val, Val)>(_SC("Generate"), &Vector4::Generate)
|
||||
.Overload<void (Vector4::*)(Val, Val, Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Vector4::Generate)
|
||||
/* Utility Methods */
|
||||
// Metamethods
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_add"), &Vector4::operator +)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_sub"), &Vector4::operator -)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_mul"), &Vector4::operator *)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_div"), &Vector4::operator /)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_modulo"), &Vector4::operator %)
|
||||
.Func< Vector4 (Vector4::*)(void) const >(_SC("_unm"), &Vector4::operator -)
|
||||
// Setters
|
||||
.Overload< void (Vector4::*)(Val) >(_SC("Set"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(Val, Val, Val) >(_SC("Set"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(Val, Val, Val, Val) >(_SC("Set"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(const Vector4 &) >(_SC("SetVec4"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(const Vector3 &) >(_SC("SetVec3"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(const Quaternion &) >(_SC("SetQuat"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(CSStr, SQChar) >(_SC("SetStr"), &Vector4::Set)
|
||||
// Random Generators
|
||||
.Overload< void (Vector4::*)(void) >(_SC("Generate"), &Vector4::Generate)
|
||||
.Overload< void (Vector4::*)(Val, Val) >(_SC("Generate"), &Vector4::Generate)
|
||||
.Overload< void (Vector4::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Vector4::Generate)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Vector4::Clear)
|
||||
/* Operator Exposure */
|
||||
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opAddAssign"), &Vector4::operator +=)
|
||||
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opSubAssign"), &Vector4::operator -=)
|
||||
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opMulAssign"), &Vector4::operator *=)
|
||||
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opDivAssign"), &Vector4::operator /=)
|
||||
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opModAssign"), &Vector4::operator %=)
|
||||
|
||||
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opAddAssignS"), &Vector4::operator +=)
|
||||
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opSubAssignS"), &Vector4::operator -=)
|
||||
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opMulAssignS"), &Vector4::operator *=)
|
||||
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opDivAssignS"), &Vector4::operator /=)
|
||||
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opModAssignS"), &Vector4::operator %=)
|
||||
|
||||
.Func<Vector4 & (Vector4::*)(void)>(_SC("opPreInc"), &Vector4::operator ++)
|
||||
.Func<Vector4 & (Vector4::*)(void)>(_SC("opPreDec"), &Vector4::operator --)
|
||||
.Func<Vector4 (Vector4::*)(int)>(_SC("opPostInc"), &Vector4::operator ++)
|
||||
.Func<Vector4 (Vector4::*)(int)>(_SC("opPostDec"), &Vector4::operator --)
|
||||
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opAdd"), &Vector4::operator +)
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opSub"), &Vector4::operator -)
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opMul"), &Vector4::operator *)
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opDiv"), &Vector4::operator /)
|
||||
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opMod"), &Vector4::operator %)
|
||||
|
||||
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opAddS"), &Vector4::operator +)
|
||||
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opSubS"), &Vector4::operator -)
|
||||
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opMulS"), &Vector4::operator *)
|
||||
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opDivS"), &Vector4::operator /)
|
||||
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opModS"), &Vector4::operator %)
|
||||
|
||||
.Func<Vector4 (Vector4::*)(void) const>(_SC("opUnPlus"), &Vector4::operator +)
|
||||
.Func<Vector4 (Vector4::*)(void) const>(_SC("opUnMinus"), &Vector4::operator -)
|
||||
|
||||
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opEqual"), &Vector4::operator ==)
|
||||
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opNotEqual"), &Vector4::operator !=)
|
||||
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opLessThan"), &Vector4::operator <)
|
||||
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opGreaterThan"), &Vector4::operator >)
|
||||
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opLessEqual"), &Vector4::operator <=)
|
||||
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opGreaterEqual"), &Vector4::operator >=)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Vector4 & (*)(CSStr) >(_SC("FromStr"), &GetVector4)
|
||||
.StaticOverload< const Vector4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector4)
|
||||
.StaticOverload< const Vector4 & (*)(CSStr) >(_SC("FromStr"), &Vector4::Get)
|
||||
.StaticOverload< const Vector4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector4::Get)
|
||||
// Operator Exposure
|
||||
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opAddAssign"), &Vector4::operator +=)
|
||||
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opSubAssign"), &Vector4::operator -=)
|
||||
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opMulAssign"), &Vector4::operator *=)
|
||||
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opDivAssign"), &Vector4::operator /=)
|
||||
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opModAssign"), &Vector4::operator %=)
|
||||
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opAddAssignS"), &Vector4::operator +=)
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opSubAssignS"), &Vector4::operator -=)
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opMulAssignS"), &Vector4::operator *=)
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opDivAssignS"), &Vector4::operator /=)
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opModAssignS"), &Vector4::operator %=)
|
||||
|
||||
.Func< Vector4 & (Vector4::*)(void) >(_SC("opPreInc"), &Vector4::operator ++)
|
||||
.Func< Vector4 & (Vector4::*)(void) >(_SC("opPreDec"), &Vector4::operator --)
|
||||
.Func< Vector4 (Vector4::*)(int) >(_SC("opPostInc"), &Vector4::operator ++)
|
||||
.Func< Vector4 (Vector4::*)(int) >(_SC("opPostDec"), &Vector4::operator --)
|
||||
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opAdd"), &Vector4::operator +)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opSub"), &Vector4::operator -)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opMul"), &Vector4::operator *)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opDiv"), &Vector4::operator /)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opMod"), &Vector4::operator %)
|
||||
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opAddS"), &Vector4::operator +)
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opSubS"), &Vector4::operator -)
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opMulS"), &Vector4::operator *)
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opDivS"), &Vector4::operator /)
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opModS"), &Vector4::operator %)
|
||||
|
||||
.Func< Vector4 (Vector4::*)(void) const >(_SC("opUnPlus"), &Vector4::operator +)
|
||||
.Func< Vector4 (Vector4::*)(void) const >(_SC("opUnMinus"), &Vector4::operator -)
|
||||
|
||||
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opEqual"), &Vector4::operator ==)
|
||||
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opNotEqual"), &Vector4::operator !=)
|
||||
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opLessThan"), &Vector4::operator <)
|
||||
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opGreaterThan"), &Vector4::operator >)
|
||||
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opLessEqual"), &Vector4::operator <=)
|
||||
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opGreaterEqual"), &Vector4::operator >=)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector4 type from a string.
|
||||
*/
|
||||
const Vector4 & GetVector4(CSStr str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector4 type from a string.
|
||||
*/
|
||||
const Vector4 & GetVector4(CSStr str, SQChar delim);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class used to represent a four-dimensional vector.
|
||||
*/
|
||||
@@ -341,6 +331,17 @@ struct Vector4
|
||||
* Retrieve a new instance of this type with absolute component values.
|
||||
*/
|
||||
Vector4 Abs() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector4 type from a string.
|
||||
*/
|
||||
static const Vector4 & Get(CSStr str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector4 type from a string.
|
||||
*/
|
||||
static const Vector4 & Get(CSStr str, SQChar delim);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
#include "Entity/Player.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_MANAGEDPTR_TYPE(CmdManager) _Cmd = SQMOD_MANAGEDPTR_MAKE(CmdManager, nullptr);
|
||||
CmdManager CmdManager::s_Inst;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CmdListener::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqCmdListener");
|
||||
static const SQChar name[] = _SC("SqCmdListener");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ static void ValidateName(CSStr name)
|
||||
while (*name != '\0')
|
||||
{
|
||||
// Does it contain spaces?
|
||||
if (isspace(*name) != 0)
|
||||
if (std::isspace(*name) != 0)
|
||||
{
|
||||
STHROWF("Command names cannot contain spaces");
|
||||
}
|
||||
@@ -63,36 +63,29 @@ CSStr CmdArgSpecToStr(Uint8 spec)
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward the call to initialize the command manager.
|
||||
*/
|
||||
void InitializeCmdManager()
|
||||
{
|
||||
CmdManager::Get().Initialize();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward the call to terminate the command manager.
|
||||
*/
|
||||
void TerminateCmdManager()
|
||||
{
|
||||
CmdManager::Get().Deinitialize();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CmdManager::Guard::~Guard()
|
||||
{
|
||||
// Release the command instance
|
||||
_Cmd->m_Instance = nullptr;
|
||||
CmdManager::Get().m_Instance = nullptr;
|
||||
// Release the reference to the script object
|
||||
_Cmd->m_Object.Release();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CmdManager::CmdManager()
|
||||
: m_Buffer(512)
|
||||
, m_Commands()
|
||||
, m_Invoker(SQMOD_UNKNOWN)
|
||||
, m_Command(64, '\0')
|
||||
, m_Argument(512, '\0')
|
||||
, m_Instance(nullptr)
|
||||
, m_Object()
|
||||
, m_Argv()
|
||||
, m_Argc(0)
|
||||
, m_OnError()
|
||||
, m_OnAuth()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CmdManager::~CmdManager()
|
||||
{
|
||||
/* ... */
|
||||
CmdManager::Get().m_Object.Release();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -205,6 +198,59 @@ bool CmdManager::Attached(const CmdListener * ptr) const
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CmdManager::CmdManager()
|
||||
: m_Buffer(512)
|
||||
, m_Commands()
|
||||
, m_Invoker(SQMOD_UNKNOWN)
|
||||
, m_Command(64, '\0')
|
||||
, m_Argument(512, '\0')
|
||||
, m_Instance(nullptr)
|
||||
, m_Object()
|
||||
, m_Argv()
|
||||
, m_Argc(0)
|
||||
, m_OnFail()
|
||||
, m_OnAuth()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CmdManager::~CmdManager()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CmdManager::Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CmdManager::Deinitialize()
|
||||
{
|
||||
// Release the script resources from command instances
|
||||
for (const auto & cmd : m_Commands)
|
||||
{
|
||||
if (cmd.mPtr)
|
||||
{
|
||||
// Release the local command callbacks
|
||||
cmd.mPtr->m_OnExec.ReleaseGently();
|
||||
cmd.mPtr->m_OnAuth.ReleaseGently();
|
||||
cmd.mPtr->m_OnPost.ReleaseGently();
|
||||
cmd.mPtr->m_OnFail.ReleaseGently();
|
||||
}
|
||||
}
|
||||
// Clear the command list and release all references
|
||||
m_Commands.clear();
|
||||
// Release the script resources from this class
|
||||
m_Argv.clear();
|
||||
// Release the global callbacks
|
||||
m_OnFail.ReleaseGently();
|
||||
m_OnAuth.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CmdManager::Sort()
|
||||
{
|
||||
@@ -232,30 +278,6 @@ const Object & CmdManager::FindByName(const String & name)
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CmdManager::Terminate()
|
||||
{
|
||||
// Release the script resources from command instances
|
||||
for (const auto & cmd : m_Commands)
|
||||
{
|
||||
if (cmd.mPtr)
|
||||
{
|
||||
// Release the local command callbacks
|
||||
cmd.mPtr->m_OnExec.ReleaseGently();
|
||||
cmd.mPtr->m_OnAuth.ReleaseGently();
|
||||
cmd.mPtr->m_OnPost.ReleaseGently();
|
||||
cmd.mPtr->m_OnFail.ReleaseGently();
|
||||
}
|
||||
}
|
||||
// Clear the command list and release all references
|
||||
m_Commands.clear();
|
||||
// Release the script resources from this class
|
||||
m_Argv.clear();
|
||||
// Release the global callbacks
|
||||
m_OnError.ReleaseGently();
|
||||
m_OnAuth.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CmdManager::Run(Int32 invoker, CCStr command)
|
||||
{
|
||||
@@ -270,7 +292,10 @@ Int32 CmdManager::Run(Int32 invoker, CCStr command)
|
||||
// Save the invoker identifier
|
||||
m_Invoker = invoker;
|
||||
// Skip white-space until the command name
|
||||
while (isspace(*command)) ++command;
|
||||
while (std::isspace(*command))
|
||||
{
|
||||
++command;
|
||||
}
|
||||
// Anything left to process?
|
||||
if (*command == '\0')
|
||||
{
|
||||
@@ -282,14 +307,20 @@ Int32 CmdManager::Run(Int32 invoker, CCStr command)
|
||||
// Where the name ends and argument begins
|
||||
CCStr split = command;
|
||||
// Find where the command name ends
|
||||
while (!isspace(*split) && *split != '\0') ++split;
|
||||
while (*split != '\0' && !std::isspace(*split))
|
||||
{
|
||||
++split;
|
||||
}
|
||||
// Are there any arguments specified?
|
||||
if (split != nullptr)
|
||||
if (split != '\0')
|
||||
{
|
||||
// Save the command name
|
||||
m_Command.assign(command, (split - command));
|
||||
// Skip white space after command name
|
||||
while (isspace(*split)) ++split;
|
||||
while (std::isspace(*split))
|
||||
{
|
||||
++split;
|
||||
}
|
||||
// Save the command argument
|
||||
m_Argument.assign(split);
|
||||
}
|
||||
@@ -299,13 +330,20 @@ Int32 CmdManager::Run(Int32 invoker, CCStr command)
|
||||
// Save the command name
|
||||
m_Command.assign(command);
|
||||
// Leave argument empty
|
||||
m_Argument.assign("");
|
||||
m_Argument.assign(_SC(""));
|
||||
}
|
||||
// Do we have a valid command name?
|
||||
try
|
||||
{
|
||||
ValidateName(m_Command.c_str());
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
SqError(CMDERR_INVALID_COMMAND, ToStrF("%s", e.Message().c_str()), invoker);
|
||||
// Execution failed!
|
||||
return -1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
@@ -408,7 +446,7 @@ Int32 CmdManager::Exec()
|
||||
// Result of the command execution
|
||||
SQInteger result = -1;
|
||||
// Clear any data from the buffer to make room for the error message
|
||||
m_Buffer.At(0) = 0;
|
||||
m_Buffer.At(0) = '\0';
|
||||
// Whether the command execution failed
|
||||
bool failed = false;
|
||||
// Do we have to call the command with an associative container?
|
||||
@@ -433,7 +471,7 @@ Int32 CmdManager::Exec()
|
||||
// Attempt to execute the command with the specified arguments
|
||||
try
|
||||
{
|
||||
result = m_Instance->Execute(_Core->GetPlayer(m_Invoker).mObj, args);
|
||||
result = m_Instance->Execute(Core::Get().GetPlayer(m_Invoker).mObj, args);
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
@@ -442,6 +480,13 @@ Int32 CmdManager::Exec()
|
||||
// Specify that the command execution failed
|
||||
failed = true;
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
// Let's store the exception message
|
||||
m_Buffer.WriteF(0, "Application exception occurred [%s]", e.what());
|
||||
// Specify that the command execution failed
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -455,7 +500,7 @@ Int32 CmdManager::Exec()
|
||||
// Attempt to execute the command with the specified arguments
|
||||
try
|
||||
{
|
||||
result = m_Instance->Execute(_Core->GetPlayer(m_Invoker).mObj, args);
|
||||
result = m_Instance->Execute(Core::Get().GetPlayer(m_Invoker).mObj, args);
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
@@ -464,6 +509,13 @@ Int32 CmdManager::Exec()
|
||||
// Specify that the command execution failed
|
||||
failed = true;
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
// Let's store the exception message
|
||||
m_Buffer.WriteF(0, "Application exception occurred [%s]", e.what());
|
||||
// Specify that the command execution failed
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
// Was there a runtime exception during the execution?
|
||||
if (failed)
|
||||
@@ -476,13 +528,18 @@ Int32 CmdManager::Exec()
|
||||
// Then attempt to relay the result to that function
|
||||
try
|
||||
{
|
||||
m_Instance->m_OnFail.Execute(_Core->GetPlayer(m_Invoker).mObj, result);
|
||||
m_Instance->m_OnFail.Execute(Core::Get().GetPlayer(m_Invoker).mObj, result);
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
SqError(CMDERR_UNRESOLVED_FAILURE, _SC("Unable to resolve command failure"), e.Message());
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
SqError(CMDERR_UNRESOLVED_FAILURE, _SC("Unable to resolve command failure"), e.what());
|
||||
}
|
||||
}
|
||||
// Result is invalid at this point
|
||||
result = -1;
|
||||
@@ -498,13 +555,18 @@ Int32 CmdManager::Exec()
|
||||
// Then attempt to relay the result to that function
|
||||
try
|
||||
{
|
||||
m_Instance->m_OnFail.Execute(_Core->GetPlayer(m_Invoker).mObj, result);
|
||||
m_Instance->m_OnFail.Execute(Core::Get().GetPlayer(m_Invoker).mObj, result);
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
SqError(CMDERR_UNRESOLVED_FAILURE, _SC("Unable to resolve command failure"), e.Message());
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
SqError(CMDERR_UNRESOLVED_FAILURE, _SC("Unable to resolve command failure"), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Is there a callback that must be executed after a successful execution?
|
||||
@@ -513,16 +575,21 @@ Int32 CmdManager::Exec()
|
||||
// Then attempt to relay the result to that function
|
||||
try
|
||||
{
|
||||
m_Instance->m_OnPost.Execute(_Core->GetPlayer(m_Invoker).mObj, result);
|
||||
m_Instance->m_OnPost.Execute(Core::Get().GetPlayer(m_Invoker).mObj, result);
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
SqError(CMDERR_POST_PROCESSING_FAILED, _SC("Unable to complete command post processing"), e.Message());
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
SqError(CMDERR_POST_PROCESSING_FAILED, _SC("Unable to complete command post processing"), e.what());
|
||||
}
|
||||
}
|
||||
// Return the result
|
||||
return static_cast< Int32 >(result);
|
||||
return ConvTo< Int32 >::From(result);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -536,11 +603,11 @@ bool CmdManager::Parse()
|
||||
// Obtain the flags of the currently processed argument
|
||||
Uint8 arg_flags = m_Instance->m_ArgSpec[m_Argc];
|
||||
// Adjust the internal buffer if necessary (mostly never)
|
||||
m_Buffer.Adjust< SQChar >(m_Argument.size());
|
||||
m_Buffer.Adjust(m_Argument.size());
|
||||
// The iterator to the currently processed character
|
||||
String::iterator itr = m_Argument.begin();
|
||||
String::const_iterator itr = m_Argument.cbegin();
|
||||
// Previous and currently processed character
|
||||
SQChar prev = 0, elem = 0;
|
||||
String::value_type prev = 0, elem = 0;
|
||||
// Maximum arguments allowed to be processed
|
||||
const Uint8 max_arg = m_Instance->m_MaxArgc;
|
||||
// Process loop result
|
||||
@@ -550,37 +617,31 @@ bool CmdManager::Parse()
|
||||
{
|
||||
// Extract the current characters before advancing
|
||||
prev = elem, elem = *itr;
|
||||
// See if there's anything left to parse
|
||||
if (elem == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
// Early check to prevent parsing extraneous arguments
|
||||
else if (m_Argc >= max_arg)
|
||||
// See if we have anything left to parse or we have what we need already
|
||||
if (elem == '\0' || m_Argc >= max_arg)
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
SqError(CMDERR_EXTRANEOUS_ARGS, _SC("Extraneous command arguments"), max_arg);
|
||||
// Parsing aborted
|
||||
good = false;
|
||||
// Stop parsing
|
||||
break;
|
||||
break; // We only parse what we need or what we have!
|
||||
}
|
||||
// Is this a greedy argument?
|
||||
else if (arg_flags & CMDARG_GREEDY)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Skip white-space characters
|
||||
while (itr != m_Argument.end() && isspace(*itr)) ++itr;
|
||||
itr = std::find_if(itr, m_Argument.cend(), IsNotCType(std::isspace));
|
||||
// Anything left to copy to the argument?
|
||||
if (itr != m_Argument.end())
|
||||
{
|
||||
// Transform it into a script object
|
||||
sq_pushstring(DefaultVM::Get(), &(*itr), std::distance(itr, m_Argument.end()));
|
||||
sq_pushstring(DefaultVM::Get(), &(*itr), std::distance(itr, m_Argument.cend()));
|
||||
}
|
||||
// Just push an empty string
|
||||
else
|
||||
{
|
||||
sq_pushstring(DefaultVM::Get(), _SC(""), 0);
|
||||
}
|
||||
// Get the object from the stack and add it to the argument list along with it's type
|
||||
m_Argv.emplace_back(CMDARG_STRING, Var< Object >(DefaultVM::Get(), -1).value);
|
||||
// Pop the created object from the stack
|
||||
sq_pop(DefaultVM::Get(), 1);
|
||||
// Include this argument into the count
|
||||
++m_Argc;
|
||||
// Nothing left to parse
|
||||
@@ -591,9 +652,9 @@ bool CmdManager::Parse()
|
||||
{
|
||||
// Obtain the beginning and ending of the internal buffer
|
||||
SStr str = m_Buffer.Begin< SQChar >();
|
||||
CSStr end = (m_Buffer.End< SQChar >()-1); // + null terminator
|
||||
SStr end = (m_Buffer.End< SQChar >() - 1); // + null terminator
|
||||
// Save the closing quote type
|
||||
SQChar close = elem;
|
||||
const SQChar close = elem;
|
||||
// Skip the opening quote
|
||||
++itr;
|
||||
// Attempt to consume the string argument
|
||||
@@ -602,7 +663,7 @@ bool CmdManager::Parse()
|
||||
// Extract the current characters before advancing
|
||||
prev = elem, elem = *itr;
|
||||
// See if there's anything left to parse
|
||||
if (elem == 0)
|
||||
if (elem == '\0')
|
||||
{
|
||||
// Tell the script callback to deal with the error
|
||||
SqError(CMDERR_SYNTAX_ERROR, _SC("String argument not closed properly"), m_Argc);
|
||||
@@ -618,13 +679,15 @@ bool CmdManager::Parse()
|
||||
if (prev != '\\')
|
||||
{
|
||||
// Terminate the string value in the internal buffer
|
||||
*str = 0;
|
||||
*str = '\0';
|
||||
// Stop parsing
|
||||
break;
|
||||
}
|
||||
// Overwrite last character when replicating
|
||||
else
|
||||
{
|
||||
--str;
|
||||
}
|
||||
}
|
||||
// See if the internal buffer needs to scale
|
||||
else if (str >= end)
|
||||
@@ -637,157 +700,194 @@ bool CmdManager::Parse()
|
||||
break;
|
||||
}
|
||||
// Simply replicate the character to the internal buffer
|
||||
*(str++) = elem;
|
||||
*str = elem;
|
||||
// Advance to the next character
|
||||
++itr;
|
||||
++str, ++itr;
|
||||
}
|
||||
// See if the argument was valid
|
||||
if (!good)
|
||||
// Propagate failure
|
||||
break;
|
||||
// Do we have to make the string lowercase?
|
||||
else if (arg_flags & CMDARG_LOWER)
|
||||
{
|
||||
for (SStr chr = m_Buffer.Begin< SQChar >(); chr <= str; ++chr)
|
||||
*chr = static_cast< SQChar >(tolower(*chr));
|
||||
break; // Propagate the failure!
|
||||
}
|
||||
// Swap the beginning and ending of the extracted string
|
||||
end = str, str = m_Buffer.Begin();
|
||||
// Make sure the string is null terminated
|
||||
*end = '\0';
|
||||
// Do we have to make the string lowercase?
|
||||
if (arg_flags & CMDARG_LOWER)
|
||||
{
|
||||
for (CStr chr = str; chr < end; ++chr)
|
||||
{
|
||||
*chr = static_cast< SQChar >(std::tolower(*chr));
|
||||
}
|
||||
}
|
||||
// Do we have to make the string uppercase?
|
||||
else if (arg_flags & CMDARG_UPPER)
|
||||
{
|
||||
for (SStr chr = m_Buffer.Begin< SQChar >(); chr <= str; ++chr)
|
||||
*chr = static_cast< SQChar >(toupper(*chr));
|
||||
for (CStr chr = str; chr < end; ++chr)
|
||||
{
|
||||
*chr = static_cast< SQChar >(std::toupper(*chr));
|
||||
}
|
||||
}
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Was the specified string empty?
|
||||
if (str >= end)
|
||||
{
|
||||
// Just push an empty string
|
||||
sq_pushstring(DefaultVM::Get(), _SC(""), 0);
|
||||
}
|
||||
// Add it to the argument list along with it's type
|
||||
else
|
||||
{
|
||||
// Transform it into a script object
|
||||
sq_pushstring(DefaultVM::Get(), str, end - str - 1);
|
||||
}
|
||||
// Transform it into a script object
|
||||
sq_pushstring(DefaultVM::Get(), m_Buffer.Get< SQChar >(), str - m_Buffer.Begin< SQChar >());
|
||||
// Get the object from the stack and add it to the argument list along with it's type
|
||||
m_Argv.emplace_back(CMDARG_STRING, Var< Object >(DefaultVM::Get(), -1).value);
|
||||
// Pop the created object from the stack
|
||||
sq_pop(DefaultVM::Get(), 1);
|
||||
// Advance to the next argument and obtain its flags
|
||||
arg_flags = m_Instance->m_ArgSpec[++m_Argc];
|
||||
}
|
||||
// Ignore white-space characters until another valid character is found
|
||||
else if (!isspace(elem) && (isspace(prev) || prev == 0))
|
||||
else if (!std::isspace(elem) && (std::isspace(prev) || prev == '\0'))
|
||||
{
|
||||
// Find the first space character that marks the end of the argument
|
||||
String::iterator pos = std::find(String::iterator(itr), m_Argument.end(), ' ');
|
||||
// Copy all characters within range into the internal buffer
|
||||
const Uint32 sz = m_Buffer.Write(0, &(*itr), std::distance(itr, pos));
|
||||
String::const_iterator pos = std::find_if(itr, m_Argument.cend(), IsCType(std::isspace));
|
||||
// Obtain both ends of the argument string
|
||||
CCStr str = &(*itr), end = &(*pos);
|
||||
// Compute the argument string size
|
||||
const Uint32 sz = std::distance(itr, pos);
|
||||
// Update the main iterator position
|
||||
itr = pos;
|
||||
// Update the current character
|
||||
// Update the currently processed character
|
||||
elem = *itr;
|
||||
// Make sure the argument string is null terminated
|
||||
m_Buffer.At< SQChar >(sz) = 0;
|
||||
// Used to exclude all other checks when a valid type was identified
|
||||
bool identified = false;
|
||||
// Attempt to treat the value as an integer number
|
||||
if (!identified)
|
||||
// Attempt to treat the value as an integer number if possible
|
||||
if (!identified && (arg_flags & CMDARG_INTEGER))
|
||||
{
|
||||
// Let's us know if the whole argument was part of the resulted value
|
||||
CStr next = nullptr;
|
||||
// Attempt to extract the integer value from the string
|
||||
LongI value = strtol(m_Buffer.Data(), &next, 10);
|
||||
const Int64 value = std::strtoll(str, &next, 10);
|
||||
// See if this whole string was indeed an integer
|
||||
if (next == &m_Buffer.At< SQChar >(sz))
|
||||
if (next == end)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform it into a script object
|
||||
sq_pushinteger(DefaultVM::Get(), static_cast< SQInteger >(value));
|
||||
sq_pushinteger(DefaultVM::Get(), ConvTo< SQInteger >::From(value));
|
||||
// Get the object from the stack and add it to the argument list along with it's type
|
||||
m_Argv.emplace_back(CMDARG_INTEGER, Var< Object >(DefaultVM::Get(), -1).value);
|
||||
// Pop the created object from the stack
|
||||
sq_pop(DefaultVM::Get(), 1);
|
||||
// We identified the correct value
|
||||
identified = true;
|
||||
// We've identified the correct value type
|
||||
identified = false;
|
||||
}
|
||||
}
|
||||
// Attempt to treat the value as an floating point number
|
||||
if (!identified)
|
||||
// Attempt to treat the value as an floating point number if possible
|
||||
if (!identified && (arg_flags & CMDARG_FLOAT))
|
||||
{
|
||||
// Let's us know if the whole argument was part of the resulted value
|
||||
CStr next = nullptr;
|
||||
// Attempt to extract the floating point value from the string
|
||||
// Attempt to extract the integer value from the string
|
||||
#ifdef SQUSEDOUBLE
|
||||
Float64 value = strtod(m_Buffer.Data(), &next);
|
||||
const Float64 value = std::strtod(str, &next);
|
||||
#else
|
||||
Float32 value = strtof(m_Buffer.Data(), &next);
|
||||
const Float32 value = std::strtof(str, &next);
|
||||
#endif // SQUSEDOUBLE
|
||||
// See if this whole string was indeed an floating point
|
||||
if (next == &m_Buffer.At< SQChar >(sz))
|
||||
// See if this whole string was indeed an integer
|
||||
if (next == end)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform it into a script object
|
||||
sq_pushfloat(DefaultVM::Get(), static_cast< SQFloat >(value));
|
||||
sq_pushfloat(DefaultVM::Get(), ConvTo< SQFloat >::From(value));
|
||||
// Get the object from the stack and add it to the argument list along with it's type
|
||||
m_Argv.emplace_back(CMDARG_FLOAT, Var< Object >(DefaultVM::Get(), -1).value);
|
||||
// Pop the created object from the stack
|
||||
sq_pop(DefaultVM::Get(), 1);
|
||||
// We identified the correct value
|
||||
identified = true;
|
||||
// We've identified the correct value type
|
||||
identified = false;
|
||||
}
|
||||
|
||||
}
|
||||
// Attempt to treat the value as a boolean if possible
|
||||
if (!identified && sz <= 6)
|
||||
if (!identified && (arg_flags & CMDARG_BOOLEAN) && sz <= 5)
|
||||
{
|
||||
// Allocate memory for enough data to form a boolean value
|
||||
SQChar lc[6];
|
||||
CharT lc[6];
|
||||
// Fill the temporary buffer with data from the internal buffer
|
||||
snprintf (lc, 6, "%.5s", m_Buffer.Data());
|
||||
std::snprintf(lc, 6, "%.5s", str);
|
||||
// Convert all characters to lowercase
|
||||
for (Uint32 i = 0; i < 5; ++i)
|
||||
lc[i] = tolower(lc[i]);
|
||||
{
|
||||
lc[i] = std::tolower(lc[i]);
|
||||
}
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Is this a boolean true value?
|
||||
if (strcmp(m_Buffer.Data(), "true") == 0 || strcmp(m_Buffer.Data(), "on") == 0)
|
||||
if (std::strcmp(lc, "true") == 0 || std::strcmp(lc, "on") == 0)
|
||||
{
|
||||
// Transform it into a script object
|
||||
sq_pushbool(DefaultVM::Get(), true);
|
||||
// Get the object from the stack and add it to the argument list along with it's type
|
||||
m_Argv.emplace_back(CMDARG_BOOLEAN, Var< Object >(DefaultVM::Get(), -1).value);
|
||||
// Pop the created object from the stack
|
||||
sq_pop(DefaultVM::Get(), 1);
|
||||
// We identified the correct value
|
||||
// We've identified the correct value type
|
||||
identified = true;
|
||||
}
|
||||
// Is this a boolean false value?
|
||||
else if (strcmp(m_Buffer.Data(), "false") == 0 || strcmp(m_Buffer.Data(), "off") == 0)
|
||||
else if (std::strcmp(lc, "false") == 0 || std::strcmp(lc, "off") == 0)
|
||||
{
|
||||
// Transform it into a script object
|
||||
sq_pushbool(DefaultVM::Get(), false);
|
||||
// We've identified the correct value type
|
||||
identified = true;
|
||||
}
|
||||
// Could the value inside the string be interpreted as a boolean?
|
||||
if (identified)
|
||||
{
|
||||
// Get the object from the stack and add it to the argument list along with it's type
|
||||
m_Argv.emplace_back(CMDARG_BOOLEAN, Var< Object >(DefaultVM::Get(), -1).value);
|
||||
// Pop the created object from the stack
|
||||
sq_pop(DefaultVM::Get(), 1);
|
||||
// We identified the correct value
|
||||
identified = true;
|
||||
}
|
||||
}
|
||||
// If everything else failed then simply treat the value as a string
|
||||
if (!identified)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Do we have to make the string lowercase?
|
||||
if (arg_flags & CMDARG_LOWER)
|
||||
{
|
||||
for (Uint32 n = 0; n < sz; ++n)
|
||||
m_Buffer.At< SQChar >(n) = static_cast< SQChar >(tolower(m_Buffer.At< SQChar >(n)));
|
||||
// Convert all characters from the argument string into the buffer
|
||||
for (CStr chr = m_Buffer.Data(); str < end; ++str, ++chr)
|
||||
{
|
||||
*chr = static_cast< CharT >(std::tolower(*str));
|
||||
}
|
||||
// Transform it into a script object
|
||||
sq_pushstring(DefaultVM::Get(), m_Buffer.Get< SQChar >(), sz);
|
||||
}
|
||||
// Do we have to make the string uppercase?
|
||||
else if (arg_flags & CMDARG_UPPER)
|
||||
{
|
||||
for (Uint32 n = 0; n < sz; ++n)
|
||||
m_Buffer.At< SQChar >(n) = static_cast< SQChar >(toupper(m_Buffer.At< SQChar >(n)));
|
||||
// Convert all characters from the argument string into the buffer
|
||||
for (CStr chr = m_Buffer.Data(); str < end; ++str, ++chr)
|
||||
{
|
||||
*chr = static_cast< CharT >(std::toupper(*str));
|
||||
}
|
||||
// Transform it into a script object
|
||||
sq_pushstring(DefaultVM::Get(), m_Buffer.Get< SQChar >(), sz);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Transform it into a script object
|
||||
sq_pushstring(DefaultVM::Get(), str, sz);
|
||||
}
|
||||
// Transform it into a script object
|
||||
sq_pushstring(DefaultVM::Get(), m_Buffer.Get< SQChar >(), sz);
|
||||
// Get the object from the stack and add it to the argument list along with it's type
|
||||
m_Argv.emplace_back(CMDARG_STRING, Var< Object >(DefaultVM::Get(), -1).value);
|
||||
// Pop the created object from the stack
|
||||
sq_pop(DefaultVM::Get(), 1);
|
||||
}
|
||||
// Advance to the next argument and obtain its flags
|
||||
arg_flags = m_Instance->m_ArgSpec[++m_Argc];
|
||||
}
|
||||
// Is there anything left to parse?
|
||||
if (itr >= m_Argument.end())
|
||||
{
|
||||
break;
|
||||
}
|
||||
// Advance to the next character
|
||||
++itr;
|
||||
}
|
||||
@@ -887,7 +987,7 @@ CmdListener::CmdListener(CSStr name, CSStr spec, Array & tags, Uint8 min, Uint8
|
||||
CmdListener::~CmdListener()
|
||||
{
|
||||
// Detach this command (shouldn't be necessary!)
|
||||
_Cmd->Detach(this);
|
||||
CmdManager::Get().Detach(this);
|
||||
// Release callbacks
|
||||
m_OnExec.ReleaseGently();
|
||||
m_OnAuth.ReleaseGently();
|
||||
@@ -899,11 +999,17 @@ CmdListener::~CmdListener()
|
||||
Int32 CmdListener::Cmp(const CmdListener & o) const
|
||||
{
|
||||
if (m_Name == o.m_Name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_Name.size() > o.m_Name.size())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -921,19 +1027,19 @@ void CmdListener::Attach()
|
||||
STHROWF("Invalid or empty command name");
|
||||
}
|
||||
// Are we already attached?
|
||||
else if (_Cmd->Attached(this))
|
||||
else if (CmdManager::Get().Attached(this))
|
||||
{
|
||||
STHROWF("Command is already attached");
|
||||
}
|
||||
// Attempt to attach this command
|
||||
_Cmd->Attach(m_Name, this, false);
|
||||
CmdManager::Get().Attach(m_Name, this, false);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CmdListener::Detach()
|
||||
{
|
||||
// Detach this command
|
||||
_Cmd->Detach(this);
|
||||
CmdManager::Get().Detach(this);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -956,14 +1062,14 @@ void CmdListener::SetName(CSStr name)
|
||||
// Validate the specified name
|
||||
ValidateName(name);
|
||||
// Is this command already attached to a name?
|
||||
if (_Cmd->Attached(this))
|
||||
if (CmdManager::Get().Attached(this))
|
||||
{
|
||||
// Detach from the current name if necessary
|
||||
_Cmd->Detach(this);
|
||||
CmdManager::Get().Detach(this);
|
||||
// Now it's safe to assign the new name
|
||||
m_Name.assign(name);
|
||||
// We know the new name is valid
|
||||
_Cmd->Attach(m_Name, this, false);
|
||||
CmdManager::Get().Attach(m_Name, this, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1029,7 +1135,7 @@ void CmdListener::SetArgTags(Array & tags)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CmdListener::Attached() const
|
||||
{
|
||||
return _Cmd->Attached(this);
|
||||
return CmdManager::Get().Attached(this);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -1401,22 +1507,22 @@ bool CmdListener::AuthCheckID(Int32 id)
|
||||
if (!m_OnAuth.IsNull())
|
||||
{
|
||||
// Ask the specified authority inspector if this execution should be allowed
|
||||
SharedPtr< bool > ret = m_OnAuth.Evaluate< bool, Object & >(_Core->GetPlayer(id).mObj);
|
||||
SharedPtr< bool > ret = m_OnAuth.Evaluate< bool, Object & >(Core::Get().GetPlayer(id).mObj);
|
||||
// See what the custom authority inspector said or default to disallow
|
||||
allow = (!ret ? false : *ret);
|
||||
}
|
||||
// Was there a global authority inspector specified?
|
||||
else if (!_Cmd->GetOnAuth().IsNull())
|
||||
else if (!CmdManager::Get().GetOnAuth().IsNull())
|
||||
{
|
||||
// Ask the specified authority inspector if this execution should be allowed
|
||||
SharedPtr< bool > ret = _Cmd->GetOnAuth().Evaluate< bool, Object & >(_Core->GetPlayer(id).mObj);
|
||||
SharedPtr< bool > ret = CmdManager::Get().GetOnAuth().Evaluate< bool, Object & >(Core::Get().GetPlayer(id).mObj);
|
||||
// See what the custom authority inspector said or default to disallow
|
||||
allow = (!ret ? false : *ret);
|
||||
}
|
||||
// Can we use the default authority system?
|
||||
else if (m_Authority >= 0)
|
||||
{
|
||||
allow = (_Core->GetPlayer(id).mAuthority >= m_Authority);
|
||||
allow = (Core::Get().GetPlayer(id).mAuthority >= m_Authority);
|
||||
}
|
||||
// Return result
|
||||
return allow;
|
||||
@@ -1571,29 +1677,21 @@ void CmdListener::ProcSpec(CSStr str)
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward the call to run a command.
|
||||
*/
|
||||
Int32 RunCommand(Int32 invoker, CSStr command)
|
||||
static Int32 Cmd_Run(Int32 invoker, CSStr command)
|
||||
{
|
||||
return _Cmd->Run(invoker, command);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward the call to terminate the command system.
|
||||
*/
|
||||
void TerminateCommand()
|
||||
{
|
||||
_Cmd->Terminate();
|
||||
return CmdManager::Get().Run(invoker, command);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static void Cmd_Sort()
|
||||
{
|
||||
_Cmd->Sort();
|
||||
CmdManager::Get().Sort();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Uint32 Cmd_Count()
|
||||
{
|
||||
return _Cmd->Count();
|
||||
return CmdManager::Get().Count();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -1602,87 +1700,87 @@ static const Object & Cmd_FindByName(CSStr name)
|
||||
// Validate the specified name
|
||||
ValidateName(name);
|
||||
// Now perform the requested search
|
||||
return _Cmd->FindByName(name);
|
||||
return CmdManager::Get().FindByName(name);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Function & Cmd_GetOnError()
|
||||
static Function & Cmd_GetOnFail()
|
||||
{
|
||||
return _Cmd->GetOnError();
|
||||
return CmdManager::Get().GetOnFail();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static void Cmd_SetOnError(Object & env, Function & func)
|
||||
static void Cmd_SetOnFail(Object & env, Function & func)
|
||||
{
|
||||
_Cmd->SetOnError(env, func);
|
||||
CmdManager::Get().SetOnFail(env, func);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Function & Cmd_GetOnAuth()
|
||||
{
|
||||
return _Cmd->GetOnAuth();
|
||||
return CmdManager::Get().GetOnAuth();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static void Cmd_SetOnAuth(Object & env, Function & func)
|
||||
{
|
||||
_Cmd->SetOnAuth(env, func);
|
||||
CmdManager::Get().SetOnAuth(env, func);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Cmd_GetInvoker()
|
||||
{
|
||||
return _Core->GetPlayer(_Cmd->GetInvoker()).mObj;
|
||||
return Core::Get().GetPlayer(CmdManager::Get().GetInvoker()).mObj;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Int32 Cmd_GetInvokerID()
|
||||
{
|
||||
return _Cmd->GetInvoker();
|
||||
return CmdManager::Get().GetInvoker();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Object & Cmd_GetObject()
|
||||
{
|
||||
return _Cmd->GetObject();
|
||||
return CmdManager::Get().GetObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const String & Cmd_GetCommand()
|
||||
{
|
||||
return _Cmd->GetCommand();
|
||||
return CmdManager::Get().GetCommand();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const String & Cmd_GetArgument()
|
||||
{
|
||||
return _Cmd->GetArgument();
|
||||
return CmdManager::Get().GetArgument();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & Cmd_Create(CSStr name)
|
||||
{
|
||||
return _Cmd->Create(name);
|
||||
return CmdManager::Get().Create(name);
|
||||
}
|
||||
|
||||
Object & Cmd_Create(CSStr name, CSStr spec)
|
||||
{
|
||||
return _Cmd->Create(name, spec);
|
||||
return CmdManager::Get().Create(name, spec);
|
||||
}
|
||||
|
||||
Object & Cmd_Create(CSStr name, CSStr spec, Array & tags)
|
||||
{
|
||||
return _Cmd->Create(name, spec, tags);
|
||||
return CmdManager::Get().Create(name, spec, tags);
|
||||
}
|
||||
|
||||
Object & Cmd_Create(CSStr name, CSStr spec, Uint8 min, Uint8 max)
|
||||
{
|
||||
return _Cmd->Create(name,spec, min, max);
|
||||
return CmdManager::Get().Create(name,spec, min, max);
|
||||
}
|
||||
|
||||
Object & Cmd_Create(CSStr name, CSStr spec, Array & tags, Uint8 min, Uint8 max)
|
||||
{
|
||||
return _Cmd->Create(name, spec, tags, min, max);
|
||||
return CmdManager::Get().Create(name, spec, tags, min, max);
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
@@ -1691,11 +1789,11 @@ void Register_Command(HSQUIRRELVM vm)
|
||||
Table cmdns(vm);
|
||||
|
||||
cmdns.Bind(_SC("Listener"), Class< CmdListener, NoConstructor< CmdListener > >(vm, _SC("SqCmdListener"))
|
||||
/* Metamethods */
|
||||
// Metamethods
|
||||
.Func(_SC("_cmp"), &CmdListener::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CmdListener::Typename)
|
||||
.Func(_SC("_tostring"), &CmdListener::ToString)
|
||||
/* Properties */
|
||||
// Member Properties
|
||||
.Prop(_SC("Attached"), &CmdListener::Attached)
|
||||
.Prop(_SC("Name"), &CmdListener::GetName, &CmdListener::SetName)
|
||||
.Prop(_SC("Spec"), &CmdListener::GetSpec, &CmdListener::SetSpec)
|
||||
@@ -1713,7 +1811,7 @@ void Register_Command(HSQUIRRELVM vm)
|
||||
.Prop(_SC("OnAuth"), &CmdListener::GetOnAuth)
|
||||
.Prop(_SC("OnPost"), &CmdListener::GetOnPost)
|
||||
.Prop(_SC("OnFail"), &CmdListener::GetOnFail)
|
||||
/* Functions */
|
||||
// Member Methods
|
||||
.Func(_SC("Attach"), &CmdListener::Attach)
|
||||
.Func(_SC("Detach"), &CmdListener::Detach)
|
||||
.Func(_SC("BindExec"), &CmdListener::SetOnExec)
|
||||
@@ -1728,12 +1826,13 @@ void Register_Command(HSQUIRRELVM vm)
|
||||
.Func(_SC("AuthCheckID"), &CmdListener::AuthCheckID)
|
||||
);
|
||||
|
||||
cmdns.Func(_SC("Run"), &Cmd_Run);
|
||||
cmdns.Func(_SC("Sort"), &Cmd_Sort);
|
||||
cmdns.Func(_SC("Count"), &Cmd_Count);
|
||||
cmdns.Func(_SC("FindByName"), &Cmd_FindByName);
|
||||
cmdns.Func(_SC("GetOnError"), &Cmd_GetOnError);
|
||||
cmdns.Func(_SC("SetOnError"), &Cmd_SetOnError);
|
||||
cmdns.Func(_SC("BindError"), &Cmd_SetOnError);
|
||||
cmdns.Func(_SC("GetOnFail"), &Cmd_GetOnFail);
|
||||
cmdns.Func(_SC("SetOnFail"), &Cmd_SetOnFail);
|
||||
cmdns.Func(_SC("BindFail"), &Cmd_SetOnFail);
|
||||
cmdns.Func(_SC("GetOnAuth"), &Cmd_GetOnAuth);
|
||||
cmdns.Func(_SC("SetOnAuth"), &Cmd_SetOnAuth);
|
||||
cmdns.Func(_SC("BindAuth"), &Cmd_SetOnAuth);
|
||||
|
||||
@@ -15,14 +15,6 @@ namespace SqMod {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class CmdListener;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Converts a command specifier to a string.
|
||||
*/
|
||||
CSStr CmdArgSpecToStr(Uint8 spec);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern SQMOD_MANAGEDPTR_TYPE(CmdManager) _Cmd;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Manages command instances and processes executed commands.
|
||||
*/
|
||||
@@ -33,6 +25,50 @@ class CmdManager
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static CmdManager s_Inst; // Command manager instance.
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Helper class implementing RAII to release the command object and instance.
|
||||
*/
|
||||
struct Guard
|
||||
{
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
Guard() = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
Guard(const Guard & o) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
Guard(Guard && o) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Guard();
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
Guard & operator = (const Guard & o) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Guard & operator = (Guard && o) = delete;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
friend class Guard; // Allow the guard to access the member it's supposed to release.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Structure that represents a unique command in the pool.
|
||||
*/
|
||||
@@ -95,59 +131,28 @@ private:
|
||||
typedef std::pair< Uint8, Object > CmdArg;
|
||||
typedef std::vector< CmdArg > CmdArgs;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Helper class implementing RAII to release the command object and instance.
|
||||
*/
|
||||
struct Guard
|
||||
{
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
Guard() = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
Guard(const Guard & o) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
Guard(Guard && o) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Guard();
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
Guard & operator = (const Guard & o) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Guard & operator = (Guard && o) = delete;
|
||||
};
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
friend class Guard;
|
||||
Buffer m_Buffer; // Shared buffer used to extract arguments.
|
||||
CmdList m_Commands; // List of available command instances.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
CmdManager();
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Int32 m_Invoker; // The identifier of the last player that invoked a command.
|
||||
String m_Command; // The extracted command name.
|
||||
String m_Argument; // The extracted command argument.
|
||||
CmdListener* m_Instance; // Pointer to the currently executed command.
|
||||
Object m_Object; // Script object of the currently exectued command.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
CmdManager(const CmdManager &);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
CmdArgs m_Argv; // Extracted command arguments.
|
||||
Uint32 m_Argc; // Extracted arguments count.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
CmdManager & operator = (const CmdManager &);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Function m_OnFail; // Callback when something failed while running a command.
|
||||
Function m_OnAuth; // Callback if an invoker failed to authenticate properly.
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attach a command listener to a certain name.
|
||||
@@ -174,7 +179,42 @@ private:
|
||||
*/
|
||||
bool Attached(const CmdListener * ptr) const;
|
||||
|
||||
public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Forward error message to the error callback.
|
||||
*/
|
||||
template < typename T > void SqError(Int32 type, CSStr msg, T data)
|
||||
{
|
||||
// Is there a callback that deals with errors?
|
||||
if (m_OnFail.IsNull())
|
||||
return;
|
||||
// Attempt to forward the error to that callback
|
||||
try
|
||||
{
|
||||
m_OnFail.Execute< Int32, CSStr, T >(type, msg, data);
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
// We can only log this incident and in the future maybe also include the location
|
||||
LogErr("Command error callback failed [%s]", e.Message().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
CmdManager();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
CmdManager(const CmdManager & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
CmdManager(CmdManager && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
@@ -182,18 +222,35 @@ public:
|
||||
~CmdManager();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Singleton retriever.
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
static CmdManager * Get()
|
||||
{
|
||||
if (!_Cmd)
|
||||
{
|
||||
_Cmd = SQMOD_MANAGEDPTR_MAKE(CmdManager, new CmdManager());
|
||||
}
|
||||
CmdManager & operator = (const CmdManager & o) = delete;
|
||||
|
||||
return SQMOD_MANAGEDPTR_GET(_Cmd);
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
CmdManager & operator = (CmdManager && o) = delete;
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the command manager instance.
|
||||
*/
|
||||
static CmdManager & Get()
|
||||
{
|
||||
return s_Inst;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Initialize the command manager instance.
|
||||
*/
|
||||
void Initialize();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Terminate the command manager instance.
|
||||
*/
|
||||
void Deinitialize();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Sort the command list in an ascending order.
|
||||
*/
|
||||
@@ -212,25 +269,20 @@ public:
|
||||
*/
|
||||
const Object & FindByName(const String & name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Terminate current session.
|
||||
*/
|
||||
void Terminate();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the error callback.
|
||||
*/
|
||||
Function & GetOnError()
|
||||
Function & GetOnFail()
|
||||
{
|
||||
return m_OnError;
|
||||
return m_OnFail;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the error callback.
|
||||
*/
|
||||
void SetOnError(Object & env, Function & func)
|
||||
void SetOnFail(Object & env, Function & func)
|
||||
{
|
||||
m_OnError = Function(env.GetVM(), env, func.GetFunc());
|
||||
m_OnFail = Function(env.GetVM(), env, func.GetFunc());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -296,28 +348,6 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Forward error message to the error callback.
|
||||
*/
|
||||
template < typename T > void SqError(Int32 type, CSStr msg, T data)
|
||||
{
|
||||
// Is there a callback that deals with errors?
|
||||
if (m_OnError.IsNull())
|
||||
return;
|
||||
// Attempt to forward the error to that callback
|
||||
try
|
||||
{
|
||||
m_OnError.Execute< Int32, CSStr, T >(type, msg, data);
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
// We can only log this incident and in the future maybe also include the location
|
||||
LogErr("Command error callback failed [%s]", e.Message().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to execute the specified command.
|
||||
*/
|
||||
@@ -328,27 +358,6 @@ protected:
|
||||
*/
|
||||
bool Parse();
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Buffer m_Buffer; // Internal buffer used for parsing commands.
|
||||
CmdList m_Commands; // List of created commands.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Int32 m_Invoker; // Current command invoker.
|
||||
String m_Command; // Current command name.
|
||||
String m_Argument; // Current command argument.
|
||||
CmdListener* m_Instance; // Current command instance.
|
||||
Object m_Object; // Current command script object.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
CmdArgs m_Argv; // Extracted command arguments.
|
||||
Uint32 m_Argc; // Extracted arguments count.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Function m_OnError; // Error handler.
|
||||
Function m_OnAuth; // Authentication handler.
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -663,6 +672,11 @@ private:
|
||||
bool m_Associate;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Converts a command specifier to a string.
|
||||
*/
|
||||
CSStr CmdArgSpecToStr(Uint8 spec);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _COMMAND_HPP_
|
||||
|
||||
@@ -26,8 +26,8 @@ void Register_Constants(HSQUIRRELVM vm)
|
||||
.Const(_SC("MaxByte"), std::numeric_limits< Uint8 >::max())
|
||||
.Const(_SC("MinShort"), std::numeric_limits< Int16 >::min())
|
||||
.Const(_SC("MaxShort"), std::numeric_limits< Int16 >::max())
|
||||
.Const(_SC("MinUshort"), std::numeric_limits< Uint16 >::min())
|
||||
.Const(_SC("MaxUshort"), std::numeric_limits< Uint16 >::max())
|
||||
.Const(_SC("MinWord"), std::numeric_limits< Uint16 >::min())
|
||||
.Const(_SC("MaxWord"), std::numeric_limits< Uint16 >::max())
|
||||
.Const(_SC("MinInt"), std::numeric_limits< SQInteger >::min())
|
||||
.Const(_SC("MaxInt"), std::numeric_limits< SQInteger >::max())
|
||||
.Const(_SC("MinInteger"), std::numeric_limits< SQInteger >::min())
|
||||
@@ -70,75 +70,58 @@ void Register_Constants(HSQUIRRELVM vm)
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqEvent"), Enumeration(vm)
|
||||
.Const(_SC("Unknown"), EVT_UNKNOWN)
|
||||
.Const(_SC("CustomEvent"), EVT_CUSTOMEVENT)
|
||||
.Const(_SC("BlipCreated"), EVT_BLIPCREATED)
|
||||
.Const(_SC("CheckpointCreated"), EVT_CHECKPOINTCREATED)
|
||||
.Const(_SC("ForcefieldCreated"), EVT_FORCEFIELDCREATED)
|
||||
.Const(_SC("KeybindCreated"), EVT_KEYBINDCREATED)
|
||||
.Const(_SC("ObjectCreated"), EVT_OBJECTCREATED)
|
||||
.Const(_SC("PickupCreated"), EVT_PICKUPCREATED)
|
||||
.Const(_SC("PlayerCreated"), EVT_PLAYERCREATED)
|
||||
.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("ForcefieldDestroyed"), EVT_FORCEFIELDDESTROYED)
|
||||
.Const(_SC("KeybindDestroyed"), EVT_KEYBINDDESTROYED)
|
||||
.Const(_SC("ObjectDestroyed"), EVT_OBJECTDESTROYED)
|
||||
.Const(_SC("PickupDestroyed"), EVT_PICKUPDESTROYED)
|
||||
.Const(_SC("PlayerDestroyed"), EVT_PLAYERDESTROYED)
|
||||
.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("ForcefieldCustom"), EVT_FORCEFIELDCUSTOM)
|
||||
.Const(_SC("KeybindCustom"), EVT_KEYBINDCUSTOM)
|
||||
.Const(_SC("ObjectCustom"), EVT_OBJECTCUSTOM)
|
||||
.Const(_SC("PickupCustom"), EVT_PICKUPCUSTOM)
|
||||
.Const(_SC("PlayerCustom"), EVT_PLAYERCUSTOM)
|
||||
.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("ServerStartup"), EVT_SERVERSTARTUP)
|
||||
.Const(_SC("ServerShutdown"), EVT_SERVERSHUTDOWN)
|
||||
.Const(_SC("ServerFrame"), EVT_SERVERFRAME)
|
||||
.Const(_SC("IncomingConnection"), EVT_INCOMINGCONNECTION)
|
||||
.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("PlayerEmbarking"), EVT_PLAYEREMBARKING)
|
||||
.Const(_SC("PlayerEmbarked"), EVT_PLAYEREMBARKED)
|
||||
.Const(_SC("PlayerDisembark"), EVT_PLAYERDISEMBARK)
|
||||
.Const(_SC("PlayerRename"), EVT_PLAYERRENAME)
|
||||
.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("StateAim"), EVT_STATEAIM)
|
||||
.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("StateExit"), EVT_STATEEXIT)
|
||||
.Const(_SC("StateUnspawned"), EVT_STATEUNSPAWNED)
|
||||
.Const(_SC("PlayerAction"), EVT_PLAYERACTION)
|
||||
.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("ActionLieDown"), EVT_ACTIONLIEDOWN)
|
||||
.Const(_SC("ActionGettingUp"), EVT_ACTIONGETTINGUP)
|
||||
.Const(_SC("ActionJumpVehicle"), EVT_ACTIONJUMPVEHICLE)
|
||||
.Const(_SC("ActionDriving"), EVT_ACTIONDRIVING)
|
||||
@@ -146,32 +129,44 @@ void Register_Constants(HSQUIRRELVM vm)
|
||||
.Const(_SC("ActionWasted"), EVT_ACTIONWASTED)
|
||||
.Const(_SC("ActionEmbarking"), EVT_ACTIONEMBARKING)
|
||||
.Const(_SC("ActionDisembarking"), EVT_ACTIONDISEMBARKING)
|
||||
.Const(_SC("VehicleRespawn"), EVT_VEHICLERESPAWN)
|
||||
.Const(_SC("PlayerBurning"), EVT_PLAYERBURNING)
|
||||
.Const(_SC("PlayerCrouching"), EVT_PLAYERCROUCHING)
|
||||
.Const(_SC("PlayerGameKeys"), EVT_PLAYERGAMEKEYS)
|
||||
.Const(_SC("PlayerStartTyping"), EVT_PLAYERSTARTTYPING)
|
||||
.Const(_SC("PlayerStopTyping"), EVT_PLAYERSTOPTYPING)
|
||||
.Const(_SC("PlayerAway"), EVT_PLAYERAWAY)
|
||||
.Const(_SC("PlayerMessage"), EVT_PLAYERMESSAGE)
|
||||
.Const(_SC("PlayerCommand"), EVT_PLAYERCOMMAND)
|
||||
.Const(_SC("PlayerPrivateMessage"), EVT_PLAYERPRIVATEMESSAGE)
|
||||
.Const(_SC("PlayerKeyPress"), EVT_PLAYERKEYPRESS)
|
||||
.Const(_SC("PlayerKeyRelease"), EVT_PLAYERKEYRELEASE)
|
||||
.Const(_SC("PlayerSpectate"), EVT_PLAYERSPECTATE)
|
||||
.Const(_SC("PlayerCrashReport"), EVT_PLAYERCRASHREPORT)
|
||||
.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("VehicleRespawn"), EVT_VEHICLERESPAWN)
|
||||
.Const(_SC("ObjectShot"), EVT_OBJECTSHOT)
|
||||
.Const(_SC("ObjectTouched"), EVT_OBJECTTOUCHED)
|
||||
.Const(_SC("PickupClaimed"), EVT_PICKUPCLAIMED)
|
||||
.Const(_SC("PickupCollected"), EVT_PICKUPCOLLECTED)
|
||||
.Const(_SC("ObjectShot"), EVT_OBJECTSHOT)
|
||||
.Const(_SC("ObjectBump"), EVT_OBJECTBUMP)
|
||||
.Const(_SC("PickupRespawn"), EVT_PICKUPRESPAWN)
|
||||
.Const(_SC("CheckpointEntered"), EVT_CHECKPOINTENTERED)
|
||||
.Const(_SC("CheckpointExited"), EVT_CHECKPOINTEXITED)
|
||||
.Const(_SC("ForcefieldEntered"), EVT_FORCEFIELDENTERED)
|
||||
.Const(_SC("ForcefieldExited"), EVT_FORCEFIELDEXITED)
|
||||
.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("EntityPool"), EVT_ENTITYPOOL)
|
||||
.Const(_SC("ClientScriptData"), EVT_CLIENTSCRIPTDATA)
|
||||
.Const(_SC("PlayerUpdate"), EVT_PLAYERUPDATE)
|
||||
.Const(_SC("VehicleUpdate"), EVT_VEHICLEUPDATE)
|
||||
.Const(_SC("PlayerHealth"), EVT_PLAYERHEALTH)
|
||||
.Const(_SC("PlayerArmour"), EVT_PLAYERARMOUR)
|
||||
.Const(_SC("PlayerWeapon"), EVT_PLAYERWEAPON)
|
||||
.Const(_SC("PlayerHeading"), EVT_PLAYERHEADING)
|
||||
.Const(_SC("PlayerPosition"), EVT_PLAYERPOSITION)
|
||||
.Const(_SC("PlayerOption"), EVT_PLAYEROPTION)
|
||||
.Const(_SC("VehicleColour"), EVT_VEHICLECOLOUR)
|
||||
.Const(_SC("VehicleHealth"), EVT_VEHICLEHEALTH)
|
||||
.Const(_SC("VehiclePosition"), EVT_VEHICLEPOSITION)
|
||||
.Const(_SC("VehicleRotation"), EVT_VEHICLEROTATION)
|
||||
.Const(_SC("VehicleOption"), EVT_VEHICLEOPTION)
|
||||
.Const(_SC("ServerOption"), EVT_SERVEROPTION)
|
||||
.Const(_SC("ScriptReload"), EVT_SCRIPTRELOAD)
|
||||
.Const(_SC("ScriptLoaded"), EVT_SCRIPTLOADED)
|
||||
.Const(_SC("Max"), EVT_MAX)
|
||||
@@ -195,71 +190,76 @@ void Register_Constants(HSQUIRRELVM vm)
|
||||
.Const(_SC("Cleanup"), SQMOD_DESTROY_CLEANUP)
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqPoopUpdate"), Enumeration(vm)
|
||||
ConstTable(vm).Enum(_SC("SqPoolUpdate"), Enumeration(vm)
|
||||
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
|
||||
.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)
|
||||
.Const(_SC("Max"), SQMOD_ENTITY_POOL_MAX)
|
||||
.Const(_SC("Vehicle"), vcmpEntityPoolVehicle)
|
||||
.Const(_SC("Object"), vcmpEntityPoolObject)
|
||||
.Const(_SC("Pickup"), vcmpEntityPoolPickup)
|
||||
.Const(_SC("Radio"), vcmpEntityPoolRadio)
|
||||
.Const(_SC("Blip"), vcmpEntityPoolBlip)
|
||||
.Const(_SC("Checkpoint"), vcmpEntityPoolCheckPoint)
|
||||
.Const(_SC("Max"), vcmpEntityPoolCheckPoint)
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqVehicleUpd"), Enumeration(vm)
|
||||
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
|
||||
.Const(_SC("Driver"), SQMOD_VEHICLEUPD_DRIVER)
|
||||
.Const(_SC("Other"), SQMOD_VEHICLEUPD_OTHER)
|
||||
.Const(_SC("Max"), SQMOD_VEHICLEUPD_MAX)
|
||||
.Const(_SC("DriverSync"), vcmpVehicleUpdateDriverSync)
|
||||
.Const(_SC("OtherSync"), vcmpVehicleUpdateOtherSync)
|
||||
.Const(_SC("Position"), vcmpVehicleUpdatePosition)
|
||||
.Const(_SC("Health"), vcmpVehicleUpdateHealth)
|
||||
.Const(_SC("Colour"), vcmpVehicleUpdateColour)
|
||||
.Const(_SC("Rotation"), vcmpVehicleUpdateRotation)
|
||||
.Const(_SC("Max"), vcmpVehicleUpdateRotation)
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqPlayerUpd"), Enumeration(vm)
|
||||
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
|
||||
.Const(_SC("OnFoot"), SQMOD_PLAYERUPD_ONFOOT)
|
||||
.Const(_SC("Aim"), SQMOD_PLAYERUPD_AIM)
|
||||
.Const(_SC("Driver"), SQMOD_PLAYERUPD_DRIVER)
|
||||
.Const(_SC("Passenger"), SQMOD_PLAYERUPD_PASSENGER)
|
||||
.Const(_SC("Max"), SQMOD_PLAYERUPD_MAX)
|
||||
.Const(_SC("Normal"), vcmpPlayerUpdateNormal)
|
||||
.Const(_SC("Aiming"), vcmpPlayerUpdateAiming)
|
||||
.Const(_SC("Driver"), vcmpPlayerUpdateDriver)
|
||||
.Const(_SC("Passenger"), vcmpPlayerUpdatePassenger)
|
||||
.Const(_SC("Max"), vcmpPlayerUpdatePassenger)
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqPartReason"), Enumeration(vm)
|
||||
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
|
||||
.Const(_SC("Timeout"), SQMOD_PARTREASON_TIMEOUT)
|
||||
.Const(_SC("Disconnected"), SQMOD_PARTREASON_DISCONNECTED)
|
||||
.Const(_SC("KickedBanned"), SQMOD_PARTREASON_KICKEDBANNED)
|
||||
.Const(_SC("Crashed"), SQMOD_PARTREASON_CRASHED)
|
||||
.Const(_SC("Max"), SQMOD_PARTREASON_MAX)
|
||||
.Const(_SC("Timeout"), vcmpDisconnectReasonTimeout)
|
||||
.Const(_SC("Quit"), vcmpDisconnectReasonQuit)
|
||||
.Const(_SC("Kick"), vcmpDisconnectReasonKick)
|
||||
.Const(_SC("Crash"), vcmpDisconnectReasonCrash)
|
||||
.Const(_SC("AntiCheat"), vcmpDisconnectReasonAntiCheat)
|
||||
.Const(_SC("Max"), vcmpDisconnectReasonAntiCheat)
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqBodypart"), Enumeration(vm)
|
||||
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
|
||||
.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)
|
||||
.Const(_SC("Max"), SQMOD_BODYPART_MAX)
|
||||
.Const(_SC("Body"), vcmpBodyPartBody)
|
||||
.Const(_SC("Torso"), vcmpBodyPartTorso)
|
||||
.Const(_SC("LeftArm"), vcmpBodyPartLeftArm)
|
||||
.Const(_SC("RightArm"), vcmpBodyPartRightArm)
|
||||
.Const(_SC("LeftLeg"), vcmpBodyPartLeftLeg)
|
||||
.Const(_SC("RightLeg"), vcmpBodyPartRightLeg)
|
||||
.Const(_SC("Head"), vcmpBodyPartHead)
|
||||
.Const(_SC("LArm"), vcmpBodyPartLeftArm)
|
||||
.Const(_SC("RArm"), vcmpBodyPartRightArm)
|
||||
.Const(_SC("LLeg"), vcmpBodyPartLeftLeg)
|
||||
.Const(_SC("RLeg"), vcmpBodyPartRightLeg)
|
||||
.Const(_SC("InVehicle"), vcmpBodyPartInVehicle)
|
||||
.Const(_SC("Max"), vcmpBodyPartInVehicle)
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqPlayerState"), Enumeration(vm)
|
||||
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
|
||||
.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("EnteringAsDriver"), SQMOD_PLAYER_STATE_ENTERING_AS_DRIVER)
|
||||
.Const(_SC("EnteringAsPassenger"), SQMOD_PLAYER_STATE_ENTERING_AS_PASSENGER)
|
||||
.Const(_SC("ExitingVehicle"), SQMOD_PLAYER_STATE_EXITING_VEHICLE)
|
||||
.Const(_SC("Unspawned"), SQMOD_PLAYER_STATE_UNSPAWNED)
|
||||
.Const(_SC("Max"), SQMOD_PLAYER_STATE_MAX)
|
||||
.Const(_SC("None"), vcmpPlayerStateNone)
|
||||
.Const(_SC("Normal"), vcmpPlayerStateNormal)
|
||||
.Const(_SC("Aim"), vcmpPlayerStateAim)
|
||||
.Const(_SC("Driver"), vcmpPlayerStateDriver)
|
||||
.Const(_SC("Passenger"), vcmpPlayerStatePassenger)
|
||||
.Const(_SC("EnterDriver"), vcmpPlayerStateEnterDriver)
|
||||
.Const(_SC("EnterPassenger"), vcmpPlayerStateEnterPassenger)
|
||||
.Const(_SC("Exit"), vcmpPlayerStateExit)
|
||||
.Const(_SC("Unspawned"), vcmpPlayerStateUnspawned)
|
||||
.Const(_SC("Max"), vcmpPlayerStateUnspawned)
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqPlayerAction"), Enumeration(vm)
|
||||
|
||||
3338
source/Core.cpp
3338
source/Core.cpp
File diff suppressed because it is too large
Load Diff
809
source/Core.hpp
809
source/Core.hpp
File diff suppressed because it is too large
Load Diff
963
source/CoreEntity.cpp
Normal file
963
source/CoreEntity.cpp
Normal file
@@ -0,0 +1,963 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Entity/Blip.hpp"
|
||||
#include "Entity/Checkpoint.hpp"
|
||||
#include "Entity/Keybind.hpp"
|
||||
#include "Entity/Object.hpp"
|
||||
#include "Entity/Pickup.hpp"
|
||||
#include "Entity/Player.hpp"
|
||||
#include "Entity/Vehicle.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Core::ImportBlips()
|
||||
{
|
||||
// Information about the blip entity
|
||||
Int32 world = -1, scale = -1, sprid = -1;
|
||||
Uint32 color = 0;
|
||||
Float32 x = 0.0, y = 0.0, z = 0.0;
|
||||
|
||||
for (Int32 i = 0; i < SQMOD_BLIP_POOL; ++i)
|
||||
{
|
||||
// See if this entity exists on the server and whether was not allocated already
|
||||
if (_Func->CheckEntityExists(vcmpEntityPoolBlip, i) && INVALID_ENTITY(m_Blips[i].mID))
|
||||
{
|
||||
_Func->GetCoordBlipInfo(i, &world, &x, &y, &z, &scale, &color, &sprid);
|
||||
// Make the properties available before triggering the event
|
||||
m_Blips[i].mWorld = world;
|
||||
m_Blips[i].mScale = scale;
|
||||
m_Blips[i].mSprID = sprid;
|
||||
m_Blips[i].mPosition.Set(x, y, z);
|
||||
m_Blips[i].mColor.SetRGBA(color);
|
||||
// Attempt to allocate the instance
|
||||
AllocBlip(i, false, SQMOD_CREATE_IMPORT, NullObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ImportCheckpoints()
|
||||
{
|
||||
for (Int32 i = 0; i < SQMOD_CHECKPOINT_POOL; ++i)
|
||||
{
|
||||
// See if this entity exists on the server and whether was not allocated already
|
||||
if (_Func->CheckEntityExists(vcmpEntityPoolCheckPoint, i) && INVALID_ENTITY(m_Checkpoints[i].mID))
|
||||
{
|
||||
AllocCheckpoint(i, false, SQMOD_CREATE_IMPORT, NullObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ImportKeybinds()
|
||||
{
|
||||
// Information about the key-bind entity
|
||||
Uint8 release = 0;
|
||||
Int32 first = -1, second = -1, third = -1;
|
||||
|
||||
for (Int32 i = 0; i < SQMOD_KEYBIND_POOL; ++i)
|
||||
{
|
||||
// See if this entity exists on the server and whether was not allocated already
|
||||
if ((_Func->GetKeyBindData(i, &release, &first, &second, &third) != vcmpErrorNoSuchEntity)
|
||||
&& (INVALID_ENTITY(m_Keybinds[i].mID)))
|
||||
{
|
||||
// Make the properties available before triggering the event
|
||||
m_Keybinds[i].mFirst = first;
|
||||
m_Keybinds[i].mSecond = second;
|
||||
m_Keybinds[i].mThird = third;
|
||||
m_Keybinds[i].mRelease = release;
|
||||
// Attempt to allocate the instance
|
||||
AllocKeybind(i, false, SQMOD_CREATE_IMPORT, NullObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ImportObjects()
|
||||
{
|
||||
for (Int32 i = 0; i < SQMOD_OBJECT_POOL; ++i)
|
||||
{
|
||||
// See if this entity exists on the server and whether was not allocated already
|
||||
if (_Func->CheckEntityExists(vcmpEntityPoolObject, i) && INVALID_ENTITY(m_Objects[i].mID))
|
||||
{
|
||||
AllocObject(i, false, SQMOD_CREATE_IMPORT, NullObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ImportPickups()
|
||||
{
|
||||
for (Int32 i = 0; i < SQMOD_PICKUP_POOL; ++i)
|
||||
{
|
||||
// See if this entity exists on the server and whether was not allocated already
|
||||
if (_Func->CheckEntityExists(vcmpEntityPoolPickup, i) && (INVALID_ENTITY(m_Pickups[i].mID)))
|
||||
{
|
||||
AllocPickup(i, false, SQMOD_CREATE_IMPORT, NullObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ImportPlayers()
|
||||
{
|
||||
for (Int32 i = 0; i < SQMOD_PLAYER_POOL; ++i)
|
||||
{
|
||||
// See if this entity exists on the server and whether was not allocated already
|
||||
if (_Func->IsPlayerConnected(i) && (INVALID_ENTITY(m_Players[i].mID)))
|
||||
{
|
||||
ConnectPlayer(i, SQMOD_CREATE_IMPORT, NullObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ImportVehicles()
|
||||
{
|
||||
for (Int32 i = 0; i < SQMOD_VEHICLE_POOL; ++i)
|
||||
{
|
||||
// See if this entity exists on the server and whether was not allocated already
|
||||
if (_Func->CheckEntityExists(vcmpEntityPoolVehicle, i) && INVALID_ENTITY(m_Vehicles[i].mID))
|
||||
{
|
||||
AllocVehicle(i, false, SQMOD_CREATE_IMPORT, NullObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::AllocBlip(Int32 id, bool owned, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
|
||||
{
|
||||
STHROWF("Cannot allocate blip with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
BlipInst & inst = m_Blips[id];
|
||||
// Make sure that the instance isn't already allocated
|
||||
if (VALID_ENTITY(inst.mID))
|
||||
{
|
||||
return inst.mObj; // Return the existing instance
|
||||
}
|
||||
// Instantiate the entity manager
|
||||
inst.mInst = new CBlip(id);
|
||||
// Create the script object
|
||||
inst.mObj = Object(inst.mInst, m_VM);
|
||||
// Make sure that both the instance and script object could be created
|
||||
if (!inst.mInst || inst.mObj.IsNull())
|
||||
{
|
||||
ResetInst(inst);
|
||||
STHROWF("Unable to create a blip instance for: %d", id);
|
||||
}
|
||||
// Assign the specified entity identifier
|
||||
inst.mID = id;
|
||||
// Specify whether the entity is owned by this plug-in
|
||||
if (owned)
|
||||
{
|
||||
inst.mFlags |= ENF_OWNED;
|
||||
}
|
||||
else if (inst.mFlags & ENF_OWNED)
|
||||
{
|
||||
inst.mFlags ^= ENF_OWNED;
|
||||
}
|
||||
// Let the script callbacks know about this entity
|
||||
EmitBlipCreated(id, header, payload);
|
||||
// Return the script object
|
||||
return inst.mObj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::AllocCheckpoint(Int32 id, bool owned, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
|
||||
{
|
||||
STHROWF("Cannot allocate checkpoint with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
CheckpointInst & inst = m_Checkpoints[id];
|
||||
// Make sure that the instance isn't already allocated
|
||||
if (VALID_ENTITY(inst.mID))
|
||||
{
|
||||
return inst.mObj; // Return the existing instance
|
||||
}
|
||||
// Instantiate the entity manager
|
||||
inst.mInst = new CCheckpoint(id);
|
||||
// Create the script object
|
||||
inst.mObj = Object(inst.mInst, m_VM);
|
||||
// Make sure that both the instance and script object could be created
|
||||
if (!inst.mInst || inst.mObj.IsNull())
|
||||
{
|
||||
ResetInst(inst);
|
||||
STHROWF("Unable to create a checkpoint instance for: %d", id);
|
||||
}
|
||||
// Assign the specified entity identifier
|
||||
inst.mID = id;
|
||||
// Specify whether the entity is owned by this plug-in
|
||||
if (owned)
|
||||
{
|
||||
inst.mFlags |= ENF_OWNED;
|
||||
}
|
||||
else if (inst.mFlags & ENF_OWNED)
|
||||
{
|
||||
inst.mFlags ^= ENF_OWNED;
|
||||
}
|
||||
// Let the script callbacks know about this entity
|
||||
EmitCheckpointCreated(id, header, payload);
|
||||
// Return the script object
|
||||
return inst.mObj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::AllocKeybind(Int32 id, bool owned, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
|
||||
{
|
||||
STHROWF("Cannot allocate keybind with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
KeybindInst & inst = m_Keybinds[id];
|
||||
// Make sure that the instance isn't already allocated
|
||||
if (VALID_ENTITY(inst.mID))
|
||||
{
|
||||
return inst.mObj; // Return the existing instance
|
||||
}
|
||||
// Instantiate the entity manager
|
||||
inst.mInst = new CKeybind(id);
|
||||
// Create the script object
|
||||
inst.mObj = Object(inst.mInst, m_VM);
|
||||
// Make sure that both the instance and script object could be created
|
||||
if (!inst.mInst || inst.mObj.IsNull())
|
||||
{
|
||||
ResetInst(inst);
|
||||
STHROWF("Unable to create a keybind instance for: %d", id);
|
||||
}
|
||||
// Assign the specified entity identifier
|
||||
inst.mID = id;
|
||||
// Specify whether the entity is owned by this plug-in
|
||||
if (owned)
|
||||
{
|
||||
inst.mFlags |= ENF_OWNED;
|
||||
}
|
||||
else if (inst.mFlags & ENF_OWNED)
|
||||
{
|
||||
inst.mFlags ^= ENF_OWNED;
|
||||
}
|
||||
// Let the script callbacks know about this entity
|
||||
EmitKeybindCreated(id, header, payload);
|
||||
// Return the script object
|
||||
return inst.mObj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::AllocObject(Int32 id, bool owned, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
|
||||
{
|
||||
STHROWF("Cannot allocate object with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
ObjectInst & inst = m_Objects[id];
|
||||
// Make sure that the instance isn't already allocated
|
||||
if (VALID_ENTITY(inst.mID))
|
||||
{
|
||||
return inst.mObj; // Return the existing instance
|
||||
}
|
||||
// Instantiate the entity manager
|
||||
inst.mInst = new CObject(id);
|
||||
// Create the script object
|
||||
inst.mObj = Object(inst.mInst, m_VM);
|
||||
// Make sure that both the instance and script object could be created
|
||||
if (!inst.mInst || inst.mObj.IsNull())
|
||||
{
|
||||
ResetInst(inst);
|
||||
STHROWF("Unable to create a object instance for: %d", id);
|
||||
}
|
||||
// Assign the specified entity identifier
|
||||
inst.mID = id;
|
||||
// Specify whether the entity is owned by this plug-in
|
||||
if (owned)
|
||||
{
|
||||
inst.mFlags |= ENF_OWNED;
|
||||
}
|
||||
else if (inst.mFlags & ENF_OWNED)
|
||||
{
|
||||
inst.mFlags ^= ENF_OWNED;
|
||||
}
|
||||
// Let the script callbacks know about this entity
|
||||
EmitObjectCreated(id, header, payload);
|
||||
// Return the script object
|
||||
return inst.mObj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::AllocPickup(Int32 id, bool owned, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
|
||||
{
|
||||
STHROWF("Cannot allocate pickup with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
PickupInst & inst = m_Pickups[id];
|
||||
// Make sure that the instance isn't already allocated
|
||||
if (VALID_ENTITY(inst.mID))
|
||||
{
|
||||
return inst.mObj; // Return the existing instance
|
||||
}
|
||||
// Instantiate the entity manager
|
||||
inst.mInst = new CPickup(id);
|
||||
// Create the script object
|
||||
inst.mObj = Object(inst.mInst, m_VM);
|
||||
// Make sure that both the instance and script object could be created
|
||||
if (!inst.mInst || inst.mObj.IsNull())
|
||||
{
|
||||
ResetInst(inst);
|
||||
STHROWF("Unable to create a pickup instance for: %d", id);
|
||||
}
|
||||
// Assign the specified entity identifier
|
||||
inst.mID = id;
|
||||
// Specify whether the entity is owned by this plug-in
|
||||
if (owned)
|
||||
{
|
||||
inst.mFlags |= ENF_OWNED;
|
||||
}
|
||||
else if (inst.mFlags & ENF_OWNED)
|
||||
{
|
||||
inst.mFlags ^= ENF_OWNED;
|
||||
}
|
||||
// Let the script callbacks know about this entity
|
||||
EmitPickupCreated(id, header, payload);
|
||||
// Return the script object
|
||||
return inst.mObj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::AllocVehicle(Int32 id, bool owned, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
|
||||
{
|
||||
STHROWF("Cannot allocate vehicle with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
VehicleInst & inst = m_Vehicles[id];
|
||||
// Make sure that the instance isn't already allocated
|
||||
if (VALID_ENTITY(inst.mID))
|
||||
{
|
||||
return inst.mObj; // Return the existing instance
|
||||
}
|
||||
// Instantiate the entity manager
|
||||
inst.mInst = new CVehicle(id);
|
||||
// Create the script object
|
||||
inst.mObj = Object(inst.mInst, m_VM);
|
||||
// Make sure that both the instance and script object could be created
|
||||
if (!inst.mInst || inst.mObj.IsNull())
|
||||
{
|
||||
ResetInst(inst);
|
||||
STHROWF("Unable to create a vehicle instance for: %d", id);
|
||||
}
|
||||
// Assign the specified entity identifier
|
||||
inst.mID = id;
|
||||
// Specify whether the entity is owned by this plug-in
|
||||
if (owned)
|
||||
{
|
||||
inst.mFlags |= ENF_OWNED;
|
||||
}
|
||||
else if (inst.mFlags & ENF_OWNED)
|
||||
{
|
||||
inst.mFlags ^= ENF_OWNED;
|
||||
}
|
||||
// Let the script callbacks know about this entity
|
||||
EmitVehicleCreated(id, header, payload);
|
||||
// Return the script object
|
||||
return inst.mObj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Core::DeallocBlip(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
|
||||
{
|
||||
STHROWF("Cannot deallocate blip with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
BlipInst & inst = m_Blips[id];
|
||||
// Make sure that the instance is even allocated
|
||||
if (INVALID_ENTITY(inst.mID) || (inst.mFlags & ENF_LOCKED))
|
||||
{
|
||||
return; // Nothing to deallocate!
|
||||
}
|
||||
// Prevent further attempts to delete this entity
|
||||
const BitGuardU16 bg(inst.mFlags, static_cast< Uint16 >(ENF_LOCKED));
|
||||
// Let the script callbacks know this entity should no longer be used
|
||||
try
|
||||
{
|
||||
EmitBlipDestroyed(id, header, payload);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// The error was probably dealt with already
|
||||
}
|
||||
// Is there a manager instance associated with this entity?
|
||||
if (inst.mInst)
|
||||
{
|
||||
// Prevent further use of this entity
|
||||
inst.mInst->m_ID = -1;
|
||||
// Release user data to avoid dangling or circular references
|
||||
inst.mInst->m_Data.Release();
|
||||
}
|
||||
// Should we delete this entity from the server as well?
|
||||
if (destroy || (inst.mFlags & ENF_OWNED))
|
||||
{
|
||||
_Func->DestroyCoordBlip(inst.mID);
|
||||
}
|
||||
// Reset the entity instance
|
||||
ResetInst(inst);
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Core::DeallocCheckpoint(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
|
||||
{
|
||||
STHROWF("Cannot deallocate checkpoint with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
CheckpointInst & inst = m_Checkpoints[id];
|
||||
// Make sure that the instance is even allocated
|
||||
if (INVALID_ENTITY(inst.mID) || (inst.mFlags & ENF_LOCKED))
|
||||
{
|
||||
return; // Nothing to deallocate!
|
||||
}
|
||||
// Prevent further attempts to delete this entity
|
||||
const BitGuardU16 bg(inst.mFlags, static_cast< Uint16 >(ENF_LOCKED));
|
||||
// Let the script callbacks know this entity should no longer be used
|
||||
try
|
||||
{
|
||||
EmitCheckpointDestroyed(id, header, payload);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// The error was probably dealt with already
|
||||
}
|
||||
// Is there a manager instance associated with this entity?
|
||||
if (inst.mInst)
|
||||
{
|
||||
// Prevent further use of this entity
|
||||
inst.mInst->m_ID = -1;
|
||||
// Release user data to avoid dangling or circular references
|
||||
inst.mInst->m_Data.Release();
|
||||
}
|
||||
// Should we delete this entity from the server as well?
|
||||
if (destroy || (inst.mFlags & ENF_OWNED))
|
||||
{
|
||||
_Func->DeleteCheckPoint(inst.mID);
|
||||
}
|
||||
// Reset the entity instance
|
||||
ResetInst(inst);
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Core::DeallocKeybind(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
|
||||
{
|
||||
STHROWF("Cannot deallocate keybind with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
KeybindInst & inst = m_Keybinds[id];
|
||||
// Make sure that the instance is even allocated
|
||||
if (INVALID_ENTITY(inst.mID) || (inst.mFlags & ENF_LOCKED))
|
||||
{
|
||||
return; // Nothing to deallocate!
|
||||
}
|
||||
// Prevent further attempts to delete this entity
|
||||
const BitGuardU16 bg(inst.mFlags, static_cast< Uint16 >(ENF_LOCKED));
|
||||
// Let the script callbacks know this entity should no longer be used
|
||||
try
|
||||
{
|
||||
EmitBlipDestroyed(id, header, payload);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// The error was dealt with already
|
||||
}
|
||||
// Is there a manager instance associated with this entity?
|
||||
if (inst.mInst)
|
||||
{
|
||||
// Prevent further use of this entity
|
||||
inst.mInst->m_ID = -1;
|
||||
// Release user data to avoid dangling or circular references
|
||||
inst.mInst->m_Data.Release();
|
||||
}
|
||||
// Should we delete this entity from the server as well?
|
||||
if (destroy || (inst.mFlags & ENF_OWNED))
|
||||
{
|
||||
_Func->RemoveKeyBind(inst.mID);
|
||||
}
|
||||
// Reset the entity instance
|
||||
ResetInst(inst);
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Core::DeallocObject(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
|
||||
{
|
||||
STHROWF("Cannot deallocate object with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
ObjectInst & inst = m_Objects[id];
|
||||
// Make sure that the instance is even allocated
|
||||
if (INVALID_ENTITY(inst.mID) || (inst.mFlags & ENF_LOCKED))
|
||||
{
|
||||
return; // Nothing to deallocate!
|
||||
}
|
||||
// Prevent further attempts to delete this entity
|
||||
const BitGuardU16 bg(inst.mFlags, static_cast< Uint16 >(ENF_LOCKED));
|
||||
// Let the script callbacks know this entity should no longer be used
|
||||
try
|
||||
{
|
||||
EmitObjectDestroyed(id, header, payload);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// The error was probably dealt with already
|
||||
}
|
||||
// Is there a manager instance associated with this entity?
|
||||
if (inst.mInst)
|
||||
{
|
||||
// Prevent further use of this entity
|
||||
inst.mInst->m_ID = -1;
|
||||
// Release user data to avoid dangling or circular references
|
||||
inst.mInst->m_Data.Release();
|
||||
}
|
||||
// Should we delete this entity from the server as well?
|
||||
if (destroy || (inst.mFlags & ENF_OWNED))
|
||||
{
|
||||
_Func->DeleteObject(inst.mID);
|
||||
}
|
||||
// Reset the entity instance
|
||||
ResetInst(inst);
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Core::DeallocPickup(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
|
||||
{
|
||||
STHROWF("Cannot deallocate pickup with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
PickupInst & inst = m_Pickups[id];
|
||||
// Make sure that the instance is even allocated
|
||||
if (INVALID_ENTITY(inst.mID) || (inst.mFlags & ENF_LOCKED))
|
||||
{
|
||||
return; // Nothing to deallocate!
|
||||
}
|
||||
// Prevent further attempts to delete this entity
|
||||
const BitGuardU16 bg(inst.mFlags, static_cast< Uint16 >(ENF_LOCKED));
|
||||
// Let the script callbacks know this entity should no longer be used
|
||||
try
|
||||
{
|
||||
EmitPickupDestroyed(id, header, payload);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// The error was probably dealt with already
|
||||
}
|
||||
// Is there a manager instance associated with this entity?
|
||||
if (inst.mInst)
|
||||
{
|
||||
// Prevent further use of this entity
|
||||
inst.mInst->m_ID = -1;
|
||||
// Release user data to avoid dangling or circular references
|
||||
inst.mInst->m_Data.Release();
|
||||
}
|
||||
// Should we delete this entity from the server as well?
|
||||
if (destroy || (inst.mFlags & ENF_OWNED))
|
||||
{
|
||||
_Func->DeletePickup(inst.mID);
|
||||
}
|
||||
// Reset the entity instance
|
||||
ResetInst(inst);
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Core::DeallocVehicle(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
|
||||
{
|
||||
STHROWF("Cannot deallocate vehicle with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
VehicleInst & inst = m_Vehicles[id];
|
||||
// Make sure that the instance is even allocated
|
||||
if (INVALID_ENTITY(inst.mID) || (inst.mFlags & ENF_LOCKED))
|
||||
{
|
||||
return; // Nothing to deallocate!
|
||||
}
|
||||
// Prevent further attempts to delete this entity
|
||||
const BitGuardU16 bg(inst.mFlags, static_cast< Uint16 >(ENF_LOCKED));
|
||||
// Let the script callbacks know this entity should no longer be used
|
||||
try
|
||||
{
|
||||
EmitVehicleDestroyed(id, header, payload);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// The error was probably dealt with already
|
||||
}
|
||||
// Is there a manager instance associated with this entity?
|
||||
if (inst.mInst)
|
||||
{
|
||||
// Prevent further use of this entity
|
||||
inst.mInst->m_ID = -1;
|
||||
// Release user data to avoid dangling or circular references
|
||||
inst.mInst->m_Data.Release();
|
||||
}
|
||||
// Should we delete this entity from the server as well?
|
||||
if (destroy || (inst.mFlags & ENF_OWNED))
|
||||
{
|
||||
_Func->DeleteVehicle(inst.mID);
|
||||
}
|
||||
// Reset the entity instance
|
||||
ResetInst(inst);
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::NewBlip(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
|
||||
Int32 scale, Uint32 color, Int32 sprid,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
// Request the server to create this entity
|
||||
const Int32 id = _Func->CreateCoordBlip(index, world, x, y, z, scale, color, sprid);
|
||||
// See if the entity creation failed on the server
|
||||
if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
||||
{
|
||||
STHROWF("Blip pool was exhausted: %d", id);
|
||||
}
|
||||
// Validate the identifier returned by the server
|
||||
else if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
|
||||
{
|
||||
STHROWF("Server returned invalid blip: %d", id);
|
||||
}
|
||||
// Attempt to allocate this entity and return the result
|
||||
return AllocBlip(id, true, header, payload);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::NewCheckpoint(Int32 player, Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
// Request the server to create this entity
|
||||
const Int32 id = _Func->CreateCheckPoint(player, world, sphere, x, y, z, r, g, b, a, radius);
|
||||
// See if the entity creation failed on the server
|
||||
if (_Func->GetLastError() == vcmpErrorNoSuchEntity)
|
||||
{
|
||||
STHROWF("Invalid player reference: %d", player);
|
||||
}
|
||||
else if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
||||
{
|
||||
STHROWF("Checkpoint pool was exhausted: %d", id);
|
||||
}
|
||||
// Validate the identifier returned by the server
|
||||
else if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
|
||||
{
|
||||
STHROWF("Server returned invalid checkpoint: %d", id);
|
||||
}
|
||||
// Attempt to allocate this entity and return the result
|
||||
return AllocCheckpoint(id, true, header, payload);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::NewKeybind(Int32 slot, bool release, Int32 primary, Int32 secondary, Int32 alternative,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
// Request the server to create this entity
|
||||
const Int32 id = _Func->RegisterKeyBind(slot, release, primary, secondary, alternative);
|
||||
// See if the entity creation failed on the server
|
||||
if (_Func->GetLastError() == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Out of bounds keybind argument: %d", id);
|
||||
}
|
||||
// Validate the identifier returned by the server
|
||||
else if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
|
||||
{
|
||||
STHROWF("Server returned invalid keybind: %d", id);
|
||||
}
|
||||
// Attempt to allocate this entity and return the result
|
||||
return AllocKeybind(id, true, header, payload);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::NewObject(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Int32 alpha,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
// Request the server to create this entity
|
||||
const Int32 id = _Func->CreateObject(model, world, x, y, z, alpha);
|
||||
// See if the entity creation failed on the server
|
||||
if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
||||
{
|
||||
STHROWF("Object pool was exhausted: %d", id);
|
||||
}
|
||||
// Validate the identifier returned by the server
|
||||
else if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
|
||||
{
|
||||
STHROWF("Server returned invalid object: %d", id);
|
||||
}
|
||||
// Attempt to allocate this entity and return the result
|
||||
return AllocObject(id, true, header, payload);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::NewPickup(Int32 model, Int32 world, Int32 quantity,
|
||||
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
// Request the server to create this entity
|
||||
const Int32 id = _Func->CreatePickup(model, world, quantity, x, y, z, alpha, automatic);
|
||||
// See if the entity creation failed on the server
|
||||
if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
||||
{
|
||||
STHROWF("Pickup pool was exhausted: %d", id);
|
||||
}
|
||||
// Validate the identifier returned by the server
|
||||
else if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
|
||||
{
|
||||
STHROWF("Server returned invalid pickup: %d", id);
|
||||
}
|
||||
// Attempt to allocate this entity and return the result
|
||||
return AllocPickup(id, true, header, payload);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object & Core::NewVehicle(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
|
||||
Float32 angle, Int32 primary, Int32 secondary,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
// Request the server to create this entity
|
||||
const Int32 id = _Func->CreateVehicle(model, world, x, y, z, angle, primary, secondary);
|
||||
// See if the entity creation failed on the server
|
||||
if (_Func->GetLastError() == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Out of bounds vehicle argument: %d", id);
|
||||
}
|
||||
else if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
||||
{
|
||||
STHROWF("Vehicle pool was exhausted: %d", id);
|
||||
}
|
||||
// Validate the identifier returned by the server
|
||||
else if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
|
||||
{
|
||||
STHROWF("Server returned invalid vehicle: %d", id);
|
||||
}
|
||||
// Attempt to allocate this entity and return the result
|
||||
return AllocVehicle(id, true, header, payload);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
bool Core::DelBlip(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
// Attempt to destroy and deallocate the specified entity instance
|
||||
DeallocBlip(id, true, header, payload);
|
||||
// The entity could be destroyed
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Core::DelCheckpoint(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
// Attempt to destroy and deallocate the specified entity instance
|
||||
DeallocCheckpoint(id, true, header, payload);
|
||||
// The entity could be destroyed
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Core::DelKeybind(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
// Attempt to destroy and deallocate the specified entity instance
|
||||
DeallocKeybind(id, true, header, payload);
|
||||
// The entity could be destroyed
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Core::DelObject(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
// Attempt to destroy and deallocate the specified entity instance
|
||||
DeallocObject(id, true, header, payload);
|
||||
// The entity could be destroyed
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Core::DelPickup(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
// Attempt to destroy and deallocate the specified entity instance
|
||||
DeallocPickup(id, true, header, payload);
|
||||
// The entity could be destroyed
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Core::DelVehicle(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
// Attempt to destroy and deallocate the specified entity instance
|
||||
DeallocVehicle(id, true, header, payload);
|
||||
// The entity could be destroyed
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::BindEvent(Int32 id, Object & env, Function & func)
|
||||
{
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = GetEvent(id);
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
event.Release(); // Then release the current callback
|
||||
}
|
||||
// Assign the specified environment and function
|
||||
else
|
||||
{
|
||||
event = Function(env.GetVM(), env, func.GetFunc());
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Core::ConnectPlayer(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
|
||||
{
|
||||
STHROWF("Cannot allocate player with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
PlayerInst & inst = m_Players[id];
|
||||
// Make sure that the instance isn't already allocated
|
||||
if (VALID_ENTITY(inst.mID))
|
||||
{
|
||||
return; // Nothing to allocate!
|
||||
}
|
||||
// Instantiate the entity manager
|
||||
inst.mInst = new CPlayer(id);
|
||||
// Create the script object
|
||||
inst.mObj = Object(inst.mInst, m_VM);
|
||||
// Make sure that both the instance and script object could be created
|
||||
if (!inst.mInst || inst.mObj.IsNull())
|
||||
{
|
||||
ResetInst(inst);
|
||||
STHROWF("Unable to create a player instance for: %d", id);
|
||||
}
|
||||
// Assign the specified entity identifier
|
||||
inst.mID = id;
|
||||
// Initialize the position
|
||||
_Func->GetPlayerPosition(id, &inst.mLastPosition.x, &inst.mLastPosition.y, &inst.mLastPosition.z);
|
||||
// Initialize the remaining attributes
|
||||
inst.mLastWeapon = _Func->GetPlayerWeapon(id);
|
||||
inst.mLastHealth = _Func->GetPlayerHealth(id);
|
||||
inst.mLastArmour = _Func->GetPlayerArmour(id);
|
||||
inst.mLastHeading = _Func->GetPlayerHeading(id);
|
||||
// Let the script callbacks know about this entity
|
||||
EmitPlayerCreated(id, header, payload);
|
||||
}
|
||||
|
||||
void Core::DisconnectPlayer(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
// Make sure that the specified entity identifier is valid
|
||||
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
|
||||
{
|
||||
STHROWF("Cannot deallocate player with invalid identifier: %d", id);
|
||||
}
|
||||
// Retrieve the specified entity instance
|
||||
PlayerInst & inst = m_Players[id];
|
||||
// Make sure that the instance is even allocated and we're allowed to deallocate it
|
||||
if (INVALID_ENTITY(inst.mID) || (inst.mFlags & ENF_LOCKED))
|
||||
{
|
||||
return; // Nothing to deallocate!
|
||||
}
|
||||
// Prevent further attempts to delete this entity
|
||||
const BitGuardU16 bg(inst.mFlags, static_cast< Uint16 >(ENF_LOCKED));
|
||||
// Let the script callbacks know this entity should no longer be used
|
||||
try
|
||||
{
|
||||
EmitPlayerDestroyed(id, header, payload);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// The error was probably dealt with already
|
||||
}
|
||||
// Is there a manager instance associated with this entity?
|
||||
if (inst.mInst)
|
||||
{
|
||||
// Prevent further use of this entity
|
||||
inst.mInst->m_ID = -1;
|
||||
// Release user data to avoid dangling or circular references
|
||||
inst.mInst->m_Data.Release();
|
||||
// Release the used memory buffer
|
||||
inst.mInst->m_Buffer.ResetAll();
|
||||
}
|
||||
// Reset the entity instance
|
||||
ResetInst(inst);
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
1055
source/CoreEvents.cpp
Normal file
1055
source/CoreEvents.cpp
Normal file
File diff suppressed because it is too large
Load Diff
587
source/CoreUtils.cpp
Normal file
587
source/CoreUtils.cpp
Normal file
@@ -0,0 +1,587 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetInst(BlipInst & inst)
|
||||
{
|
||||
inst.mID = -1;
|
||||
inst.mFlags = ENF_DEFAULT;
|
||||
inst.mWorld = -1;
|
||||
inst.mScale = -1;
|
||||
inst.mSprID = -1;
|
||||
inst.mPosition.Clear();
|
||||
inst.mColor.Clear();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetInst(CheckpointInst & inst)
|
||||
{
|
||||
inst.mID = -1;
|
||||
inst.mFlags = ENF_DEFAULT;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetInst(KeybindInst & inst)
|
||||
{
|
||||
inst.mID = -1;
|
||||
inst.mFlags = ENF_DEFAULT;
|
||||
inst.mFirst = -1;
|
||||
inst.mSecond = -1;
|
||||
inst.mThird = -1;
|
||||
inst.mRelease = -1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetInst(ObjectInst & inst)
|
||||
{
|
||||
inst.mID = -1;
|
||||
inst.mFlags = ENF_DEFAULT;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetInst(PickupInst & inst)
|
||||
{
|
||||
inst.mID = -1;
|
||||
inst.mFlags = ENF_DEFAULT;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetInst(PlayerInst & inst)
|
||||
{
|
||||
inst.mID = -1;
|
||||
inst.mFlags = ENF_DEFAULT;
|
||||
inst.mLastWeapon = -1;
|
||||
inst.mLastHealth = 0.0;
|
||||
inst.mLastArmour = 0.0;
|
||||
inst.mLastHeading = 0.0;
|
||||
inst.mLastPosition.Clear();
|
||||
inst.mAuthority = 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetInst(VehicleInst & inst)
|
||||
{
|
||||
inst.mID = -1;
|
||||
inst.mFlags = ENF_DEFAULT;
|
||||
inst.mLastPrimaryColour = -1;
|
||||
inst.mLastSecondaryColour = -1;
|
||||
inst.mLastHealth = 0.0;
|
||||
inst.mLastPosition.Clear();
|
||||
inst.mLastRotation.Clear();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetFunc(BlipInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetFunc(CheckpointInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnEntered.ReleaseGently();
|
||||
inst.mOnExited.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetFunc(KeybindInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnKeyPress.ReleaseGently();
|
||||
inst.mOnKeyRelease.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetFunc(ObjectInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnShot.ReleaseGently();
|
||||
inst.mOnTouched.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetFunc(PickupInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnRespawn.ReleaseGently();
|
||||
inst.mOnClaimed.ReleaseGently();
|
||||
inst.mOnCollected.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetFunc(PlayerInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnRequestClass.ReleaseGently();
|
||||
inst.mOnRequestSpawn.ReleaseGently();
|
||||
inst.mOnSpawn.ReleaseGently();
|
||||
inst.mOnWasted.ReleaseGently();
|
||||
inst.mOnKilled.ReleaseGently();
|
||||
inst.mOnEmbarking.ReleaseGently();
|
||||
inst.mOnEmbarked.ReleaseGently();
|
||||
inst.mOnDisembark.ReleaseGently();
|
||||
inst.mOnRename.ReleaseGently();
|
||||
inst.mOnState.ReleaseGently();
|
||||
inst.mOnStateNone.ReleaseGently();
|
||||
inst.mOnStateNormal.ReleaseGently();
|
||||
inst.mOnStateAim.ReleaseGently();
|
||||
inst.mOnStateDriver.ReleaseGently();
|
||||
inst.mOnStatePassenger.ReleaseGently();
|
||||
inst.mOnStateEnterDriver.ReleaseGently();
|
||||
inst.mOnStateEnterPassenger.ReleaseGently();
|
||||
inst.mOnStateExit.ReleaseGently();
|
||||
inst.mOnStateUnspawned.ReleaseGently();
|
||||
inst.mOnAction.ReleaseGently();
|
||||
inst.mOnActionNone.ReleaseGently();
|
||||
inst.mOnActionNormal.ReleaseGently();
|
||||
inst.mOnActionAiming.ReleaseGently();
|
||||
inst.mOnActionShooting.ReleaseGently();
|
||||
inst.mOnActionJumping.ReleaseGently();
|
||||
inst.mOnActionLieDown.ReleaseGently();
|
||||
inst.mOnActionGettingUp.ReleaseGently();
|
||||
inst.mOnActionJumpVehicle.ReleaseGently();
|
||||
inst.mOnActionDriving.ReleaseGently();
|
||||
inst.mOnActionDying.ReleaseGently();
|
||||
inst.mOnActionWasted.ReleaseGently();
|
||||
inst.mOnActionEmbarking.ReleaseGently();
|
||||
inst.mOnActionDisembarking.ReleaseGently();
|
||||
inst.mOnBurning.ReleaseGently();
|
||||
inst.mOnCrouching.ReleaseGently();
|
||||
inst.mOnGameKeys.ReleaseGently();
|
||||
inst.mOnStartTyping.ReleaseGently();
|
||||
inst.mOnStopTyping.ReleaseGently();
|
||||
inst.mOnAway.ReleaseGently();
|
||||
inst.mOnMessage.ReleaseGently();
|
||||
inst.mOnCommand.ReleaseGently();
|
||||
inst.mOnPrivateMessage.ReleaseGently();
|
||||
inst.mOnKeyPress.ReleaseGently();
|
||||
inst.mOnKeyRelease.ReleaseGently();
|
||||
inst.mOnSpectate.ReleaseGently();
|
||||
inst.mOnCrashreport.ReleaseGently();
|
||||
inst.mOnObjectShot.ReleaseGently();
|
||||
inst.mOnObjectTouched.ReleaseGently();
|
||||
inst.mOnPickupClaimed.ReleaseGently();
|
||||
inst.mOnPickupCollected.ReleaseGently();
|
||||
inst.mOnCheckpointEntered.ReleaseGently();
|
||||
inst.mOnCheckpointExited.ReleaseGently();
|
||||
inst.mOnClientScriptData.ReleaseGently();
|
||||
inst.mOnUpdate.ReleaseGently();
|
||||
inst.mOnHealth.ReleaseGently();
|
||||
inst.mOnArmour.ReleaseGently();
|
||||
inst.mOnWeapon.ReleaseGently();
|
||||
inst.mOnHeading.ReleaseGently();
|
||||
inst.mOnPosition.ReleaseGently();
|
||||
inst.mOnOption.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetFunc(VehicleInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnEmbarking.ReleaseGently();
|
||||
inst.mOnEmbarked.ReleaseGently();
|
||||
inst.mOnDisembark.ReleaseGently();
|
||||
inst.mOnExplode.ReleaseGently();
|
||||
inst.mOnRespawn.ReleaseGently();
|
||||
inst.mOnUpdate.ReleaseGently();
|
||||
inst.mOnColour.ReleaseGently();
|
||||
inst.mOnHealth.ReleaseGently();
|
||||
inst.mOnPosition.ReleaseGently();
|
||||
inst.mOnRotation.ReleaseGently();
|
||||
inst.mOnOption.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetFunc()
|
||||
{
|
||||
Core::Get().mOnCustomEvent.ReleaseGently();
|
||||
Core::Get().mOnBlipCreated.ReleaseGently();
|
||||
Core::Get().mOnCheckpointCreated.ReleaseGently();
|
||||
Core::Get().mOnKeybindCreated.ReleaseGently();
|
||||
Core::Get().mOnObjectCreated.ReleaseGently();
|
||||
Core::Get().mOnPickupCreated.ReleaseGently();
|
||||
Core::Get().mOnPlayerCreated.ReleaseGently();
|
||||
Core::Get().mOnVehicleCreated.ReleaseGently();
|
||||
Core::Get().mOnBlipDestroyed.ReleaseGently();
|
||||
Core::Get().mOnCheckpointDestroyed.ReleaseGently();
|
||||
Core::Get().mOnKeybindDestroyed.ReleaseGently();
|
||||
Core::Get().mOnObjectDestroyed.ReleaseGently();
|
||||
Core::Get().mOnPickupDestroyed.ReleaseGently();
|
||||
Core::Get().mOnPlayerDestroyed.ReleaseGently();
|
||||
Core::Get().mOnVehicleDestroyed.ReleaseGently();
|
||||
Core::Get().mOnBlipCustom.ReleaseGently();
|
||||
Core::Get().mOnCheckpointCustom.ReleaseGently();
|
||||
Core::Get().mOnKeybindCustom.ReleaseGently();
|
||||
Core::Get().mOnObjectCustom.ReleaseGently();
|
||||
Core::Get().mOnPickupCustom.ReleaseGently();
|
||||
Core::Get().mOnPlayerCustom.ReleaseGently();
|
||||
Core::Get().mOnVehicleCustom.ReleaseGently();
|
||||
Core::Get().mOnServerStartup.ReleaseGently();
|
||||
Core::Get().mOnServerShutdown.ReleaseGently();
|
||||
Core::Get().mOnServerFrame.ReleaseGently();
|
||||
Core::Get().mOnIncomingConnection.ReleaseGently();
|
||||
Core::Get().mOnPlayerRequestClass.ReleaseGently();
|
||||
Core::Get().mOnPlayerRequestSpawn.ReleaseGently();
|
||||
Core::Get().mOnPlayerSpawn.ReleaseGently();
|
||||
Core::Get().mOnPlayerWasted.ReleaseGently();
|
||||
Core::Get().mOnPlayerKilled.ReleaseGently();
|
||||
Core::Get().mOnPlayerEmbarking.ReleaseGently();
|
||||
Core::Get().mOnPlayerEmbarked.ReleaseGently();
|
||||
Core::Get().mOnPlayerDisembark.ReleaseGently();
|
||||
Core::Get().mOnPlayerRename.ReleaseGently();
|
||||
Core::Get().mOnPlayerState.ReleaseGently();
|
||||
Core::Get().mOnStateNone.ReleaseGently();
|
||||
Core::Get().mOnStateNormal.ReleaseGently();
|
||||
Core::Get().mOnStateAim.ReleaseGently();
|
||||
Core::Get().mOnStateDriver.ReleaseGently();
|
||||
Core::Get().mOnStatePassenger.ReleaseGently();
|
||||
Core::Get().mOnStateEnterDriver.ReleaseGently();
|
||||
Core::Get().mOnStateEnterPassenger.ReleaseGently();
|
||||
Core::Get().mOnStateExit.ReleaseGently();
|
||||
Core::Get().mOnStateUnspawned.ReleaseGently();
|
||||
Core::Get().mOnPlayerAction.ReleaseGently();
|
||||
Core::Get().mOnActionNone.ReleaseGently();
|
||||
Core::Get().mOnActionNormal.ReleaseGently();
|
||||
Core::Get().mOnActionAiming.ReleaseGently();
|
||||
Core::Get().mOnActionShooting.ReleaseGently();
|
||||
Core::Get().mOnActionJumping.ReleaseGently();
|
||||
Core::Get().mOnActionLieDown.ReleaseGently();
|
||||
Core::Get().mOnActionGettingUp.ReleaseGently();
|
||||
Core::Get().mOnActionJumpVehicle.ReleaseGently();
|
||||
Core::Get().mOnActionDriving.ReleaseGently();
|
||||
Core::Get().mOnActionDying.ReleaseGently();
|
||||
Core::Get().mOnActionWasted.ReleaseGently();
|
||||
Core::Get().mOnActionEmbarking.ReleaseGently();
|
||||
Core::Get().mOnActionDisembarking.ReleaseGently();
|
||||
Core::Get().mOnPlayerBurning.ReleaseGently();
|
||||
Core::Get().mOnPlayerCrouching.ReleaseGently();
|
||||
Core::Get().mOnPlayerGameKeys.ReleaseGently();
|
||||
Core::Get().mOnPlayerStartTyping.ReleaseGently();
|
||||
Core::Get().mOnPlayerStopTyping.ReleaseGently();
|
||||
Core::Get().mOnPlayerAway.ReleaseGently();
|
||||
Core::Get().mOnPlayerMessage.ReleaseGently();
|
||||
Core::Get().mOnPlayerCommand.ReleaseGently();
|
||||
Core::Get().mOnPlayerPrivateMessage.ReleaseGently();
|
||||
Core::Get().mOnPlayerKeyPress.ReleaseGently();
|
||||
Core::Get().mOnPlayerKeyRelease.ReleaseGently();
|
||||
Core::Get().mOnPlayerSpectate.ReleaseGently();
|
||||
Core::Get().mOnPlayerCrashreport.ReleaseGently();
|
||||
Core::Get().mOnVehicleExplode.ReleaseGently();
|
||||
Core::Get().mOnVehicleRespawn.ReleaseGently();
|
||||
Core::Get().mOnObjectShot.ReleaseGently();
|
||||
Core::Get().mOnObjectTouched.ReleaseGently();
|
||||
Core::Get().mOnPickupClaimed.ReleaseGently();
|
||||
Core::Get().mOnPickupCollected.ReleaseGently();
|
||||
Core::Get().mOnPickupRespawn.ReleaseGently();
|
||||
Core::Get().mOnCheckpointEntered.ReleaseGently();
|
||||
Core::Get().mOnCheckpointExited.ReleaseGently();
|
||||
Core::Get().mOnEntityPool.ReleaseGently();
|
||||
Core::Get().mOnClientScriptData.ReleaseGently();
|
||||
Core::Get().mOnPlayerUpdate.ReleaseGently();
|
||||
Core::Get().mOnVehicleUpdate.ReleaseGently();
|
||||
Core::Get().mOnPlayerHealth.ReleaseGently();
|
||||
Core::Get().mOnPlayerArmour.ReleaseGently();
|
||||
Core::Get().mOnPlayerWeapon.ReleaseGently();
|
||||
Core::Get().mOnPlayerHeading.ReleaseGently();
|
||||
Core::Get().mOnPlayerPosition.ReleaseGently();
|
||||
Core::Get().mOnPlayerOption.ReleaseGently();
|
||||
Core::Get().mOnVehicleColour.ReleaseGently();
|
||||
Core::Get().mOnVehicleHealth.ReleaseGently();
|
||||
Core::Get().mOnVehiclePosition.ReleaseGently();
|
||||
Core::Get().mOnVehicleRotation.ReleaseGently();
|
||||
Core::Get().mOnVehicleOption.ReleaseGently();
|
||||
Core::Get().mOnServerOption.ReleaseGently();
|
||||
Core::Get().mOnScriptReload.ReleaseGently();
|
||||
Core::Get().mOnScriptLoaded.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & Core::GetEvent(Int32 evid)
|
||||
{
|
||||
switch (evid)
|
||||
{
|
||||
case EVT_CUSTOMEVENT: return mOnCustomEvent;
|
||||
case EVT_BLIPCREATED: return mOnBlipCreated;
|
||||
case EVT_CHECKPOINTCREATED: return mOnCheckpointCreated;
|
||||
case EVT_KEYBINDCREATED: return mOnKeybindCreated;
|
||||
case EVT_OBJECTCREATED: return mOnObjectCreated;
|
||||
case EVT_PICKUPCREATED: return mOnPickupCreated;
|
||||
case EVT_PLAYERCREATED: return mOnPlayerCreated;
|
||||
case EVT_VEHICLECREATED: return mOnVehicleCreated;
|
||||
case EVT_BLIPDESTROYED: return mOnBlipDestroyed;
|
||||
case EVT_CHECKPOINTDESTROYED: return mOnCheckpointDestroyed;
|
||||
case EVT_KEYBINDDESTROYED: return mOnKeybindDestroyed;
|
||||
case EVT_OBJECTDESTROYED: return mOnObjectDestroyed;
|
||||
case EVT_PICKUPDESTROYED: return mOnPickupDestroyed;
|
||||
case EVT_PLAYERDESTROYED: return mOnPlayerDestroyed;
|
||||
case EVT_VEHICLEDESTROYED: return mOnVehicleDestroyed;
|
||||
case EVT_BLIPCUSTOM: return mOnBlipCustom;
|
||||
case EVT_CHECKPOINTCUSTOM: return mOnCheckpointCustom;
|
||||
case EVT_KEYBINDCUSTOM: return mOnKeybindCustom;
|
||||
case EVT_OBJECTCUSTOM: return mOnObjectCustom;
|
||||
case EVT_PICKUPCUSTOM: return mOnPickupCustom;
|
||||
case EVT_PLAYERCUSTOM: return mOnPlayerCustom;
|
||||
case EVT_VEHICLECUSTOM: return mOnVehicleCustom;
|
||||
case EVT_SERVERSTARTUP: return mOnServerStartup;
|
||||
case EVT_SERVERSHUTDOWN: return mOnServerShutdown;
|
||||
case EVT_SERVERFRAME: return mOnServerFrame;
|
||||
case EVT_INCOMINGCONNECTION: return mOnIncomingConnection;
|
||||
case EVT_PLAYERREQUESTCLASS: return mOnPlayerRequestClass;
|
||||
case EVT_PLAYERREQUESTSPAWN: return mOnPlayerRequestSpawn;
|
||||
case EVT_PLAYERSPAWN: return mOnPlayerSpawn;
|
||||
case EVT_PLAYERWASTED: return mOnPlayerWasted;
|
||||
case EVT_PLAYERKILLED: return mOnPlayerKilled;
|
||||
case EVT_PLAYEREMBARKING: return mOnPlayerEmbarking;
|
||||
case EVT_PLAYEREMBARKED: return mOnPlayerEmbarked;
|
||||
case EVT_PLAYERDISEMBARK: return mOnPlayerDisembark;
|
||||
case EVT_PLAYERRENAME: return mOnPlayerRename;
|
||||
case EVT_PLAYERSTATE: return mOnPlayerState;
|
||||
case EVT_STATENONE: return mOnStateNone;
|
||||
case EVT_STATENORMAL: return mOnStateNormal;
|
||||
case EVT_STATEAIM: return mOnStateAim;
|
||||
case EVT_STATEDRIVER: return mOnStateDriver;
|
||||
case EVT_STATEPASSENGER: return mOnStatePassenger;
|
||||
case EVT_STATEENTERDRIVER: return mOnStateEnterDriver;
|
||||
case EVT_STATEENTERPASSENGER: return mOnStateEnterPassenger;
|
||||
case EVT_STATEEXIT: return mOnStateExit;
|
||||
case EVT_STATEUNSPAWNED: return mOnStateUnspawned;
|
||||
case EVT_PLAYERACTION: return mOnPlayerAction;
|
||||
case EVT_ACTIONNONE: return mOnActionNone;
|
||||
case EVT_ACTIONNORMAL: return mOnActionNormal;
|
||||
case EVT_ACTIONAIMING: return mOnActionAiming;
|
||||
case EVT_ACTIONSHOOTING: return mOnActionShooting;
|
||||
case EVT_ACTIONJUMPING: return mOnActionJumping;
|
||||
case EVT_ACTIONLIEDOWN: return mOnActionLieDown;
|
||||
case EVT_ACTIONGETTINGUP: return mOnActionGettingUp;
|
||||
case EVT_ACTIONJUMPVEHICLE: return mOnActionJumpVehicle;
|
||||
case EVT_ACTIONDRIVING: return mOnActionDriving;
|
||||
case EVT_ACTIONDYING: return mOnActionDying;
|
||||
case EVT_ACTIONWASTED: return mOnActionWasted;
|
||||
case EVT_ACTIONEMBARKING: return mOnActionEmbarking;
|
||||
case EVT_ACTIONDISEMBARKING: return mOnActionDisembarking;
|
||||
case EVT_PLAYERBURNING: return mOnPlayerBurning;
|
||||
case EVT_PLAYERCROUCHING: return mOnPlayerCrouching;
|
||||
case EVT_PLAYERGAMEKEYS: return mOnPlayerGameKeys;
|
||||
case EVT_PLAYERSTARTTYPING: return mOnPlayerStartTyping;
|
||||
case EVT_PLAYERSTOPTYPING: return mOnPlayerStopTyping;
|
||||
case EVT_PLAYERAWAY: return mOnPlayerAway;
|
||||
case EVT_PLAYERMESSAGE: return mOnPlayerMessage;
|
||||
case EVT_PLAYERCOMMAND: return mOnPlayerCommand;
|
||||
case EVT_PLAYERPRIVATEMESSAGE: return mOnPlayerPrivateMessage;
|
||||
case EVT_PLAYERKEYPRESS: return mOnPlayerKeyPress;
|
||||
case EVT_PLAYERKEYRELEASE: return mOnPlayerKeyRelease;
|
||||
case EVT_PLAYERSPECTATE: return mOnPlayerSpectate;
|
||||
case EVT_PLAYERCRASHREPORT: return mOnPlayerCrashreport;
|
||||
case EVT_VEHICLEEXPLODE: return mOnVehicleExplode;
|
||||
case EVT_VEHICLERESPAWN: return mOnVehicleRespawn;
|
||||
case EVT_OBJECTSHOT: return mOnObjectShot;
|
||||
case EVT_OBJECTTOUCHED: return mOnObjectTouched;
|
||||
case EVT_PICKUPCLAIMED: return mOnPickupClaimed;
|
||||
case EVT_PICKUPCOLLECTED: return mOnPickupCollected;
|
||||
case EVT_PICKUPRESPAWN: return mOnPickupRespawn;
|
||||
case EVT_CHECKPOINTENTERED: return mOnCheckpointEntered;
|
||||
case EVT_CHECKPOINTEXITED: return mOnCheckpointExited;
|
||||
case EVT_ENTITYPOOL: return mOnEntityPool;
|
||||
case EVT_CLIENTSCRIPTDATA: return mOnClientScriptData;
|
||||
case EVT_PLAYERUPDATE: return mOnPlayerUpdate;
|
||||
case EVT_VEHICLEUPDATE: return mOnVehicleUpdate;
|
||||
case EVT_PLAYERHEALTH: return mOnPlayerHealth;
|
||||
case EVT_PLAYERARMOUR: return mOnPlayerArmour;
|
||||
case EVT_PLAYERWEAPON: return mOnPlayerWeapon;
|
||||
case EVT_PLAYERHEADING: return mOnPlayerHeading;
|
||||
case EVT_PLAYERPOSITION: return mOnPlayerPosition;
|
||||
case EVT_PLAYEROPTION: return mOnPlayerOption;
|
||||
case EVT_VEHICLECOLOUR: return mOnVehicleColour;
|
||||
case EVT_VEHICLEHEALTH: return mOnVehicleHealth;
|
||||
case EVT_VEHICLEPOSITION: return mOnVehiclePosition;
|
||||
case EVT_VEHICLEROTATION: return mOnVehicleRotation;
|
||||
case EVT_VEHICLEOPTION: return mOnVehicleOption;
|
||||
case EVT_SERVEROPTION: return mOnServerOption;
|
||||
case EVT_SCRIPTRELOAD: return mOnScriptReload;
|
||||
case EVT_SCRIPTLOADED: return mOnScriptLoaded;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & Core::GetBlipEvent(Int32 id, Int32 evid)
|
||||
{
|
||||
BlipInst & inst = m_Blips.at(id);
|
||||
|
||||
switch (evid)
|
||||
{
|
||||
case EVT_BLIPDESTROYED: return inst.mOnDestroyed;
|
||||
case EVT_BLIPCUSTOM: return inst.mOnCustom;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & Core::GetCheckpointEvent(Int32 id, Int32 evid)
|
||||
{
|
||||
CheckpointInst & inst = m_Checkpoints.at(id);
|
||||
|
||||
switch (evid)
|
||||
{
|
||||
case EVT_CHECKPOINTDESTROYED: return inst.mOnDestroyed;
|
||||
case EVT_CHECKPOINTCUSTOM: return inst.mOnCustom;
|
||||
case EVT_CHECKPOINTENTERED: return inst.mOnEntered;
|
||||
case EVT_CHECKPOINTEXITED: return inst.mOnExited;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & Core::GetKeybindEvent(Int32 id, Int32 evid)
|
||||
{
|
||||
KeybindInst & inst = m_Keybinds.at(id);
|
||||
|
||||
switch (evid)
|
||||
{
|
||||
case EVT_KEYBINDDESTROYED: return inst.mOnDestroyed;
|
||||
case EVT_KEYBINDCUSTOM: return inst.mOnCustom;
|
||||
case EVT_PLAYERKEYPRESS: return inst.mOnKeyPress;
|
||||
case EVT_PLAYERKEYRELEASE: return inst.mOnKeyRelease;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & Core::GetObjectEvent(Int32 id, Int32 evid)
|
||||
{
|
||||
ObjectInst & inst = m_Objects.at(id);
|
||||
|
||||
switch (evid)
|
||||
{
|
||||
case EVT_OBJECTDESTROYED: return inst.mOnDestroyed;
|
||||
case EVT_OBJECTCUSTOM: return inst.mOnCustom;
|
||||
case EVT_OBJECTSHOT: return inst.mOnShot;
|
||||
case EVT_OBJECTTOUCHED: return inst.mOnTouched;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & Core::GetPickupEvent(Int32 id, Int32 evid)
|
||||
{
|
||||
PickupInst & inst = m_Pickups.at(id);
|
||||
|
||||
switch (evid)
|
||||
{
|
||||
case EVT_PICKUPDESTROYED: return inst.mOnDestroyed;
|
||||
case EVT_PICKUPCUSTOM: return inst.mOnCustom;
|
||||
case EVT_PICKUPRESPAWN: return inst.mOnRespawn;
|
||||
case EVT_PICKUPCLAIMED: return inst.mOnClaimed;
|
||||
case EVT_PICKUPCOLLECTED: return inst.mOnCollected;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
|
||||
{
|
||||
PlayerInst & inst = m_Players.at(id);
|
||||
|
||||
switch (evid)
|
||||
{
|
||||
case EVT_PLAYERDESTROYED: return inst.mOnDestroyed;
|
||||
case EVT_PLAYERCUSTOM: return inst.mOnCustom;
|
||||
case EVT_PLAYERREQUESTCLASS: return inst.mOnRequestClass;
|
||||
case EVT_PLAYERREQUESTSPAWN: return inst.mOnRequestSpawn;
|
||||
case EVT_PLAYERSPAWN: return inst.mOnSpawn;
|
||||
case EVT_PLAYERWASTED: return inst.mOnWasted;
|
||||
case EVT_PLAYERKILLED: return inst.mOnKilled;
|
||||
case EVT_PLAYEREMBARKING: return inst.mOnEmbarking;
|
||||
case EVT_PLAYEREMBARKED: return inst.mOnEmbarked;
|
||||
case EVT_PLAYERDISEMBARK: return inst.mOnDisembark;
|
||||
case EVT_PLAYERRENAME: return inst.mOnRename;
|
||||
case EVT_PLAYERSTATE: return inst.mOnState;
|
||||
case EVT_STATENONE: return inst.mOnStateNone;
|
||||
case EVT_STATENORMAL: return inst.mOnStateNormal;
|
||||
case EVT_STATEAIM: return inst.mOnStateAim;
|
||||
case EVT_STATEDRIVER: return inst.mOnStateDriver;
|
||||
case EVT_STATEPASSENGER: return inst.mOnStatePassenger;
|
||||
case EVT_STATEENTERDRIVER: return inst.mOnStateEnterDriver;
|
||||
case EVT_STATEENTERPASSENGER: return inst.mOnStateEnterPassenger;
|
||||
case EVT_STATEEXIT: return inst.mOnStateExit;
|
||||
case EVT_STATEUNSPAWNED: return inst.mOnStateUnspawned;
|
||||
case EVT_PLAYERACTION: return inst.mOnAction;
|
||||
case EVT_ACTIONNONE: return inst.mOnActionNone;
|
||||
case EVT_ACTIONNORMAL: return inst.mOnActionNormal;
|
||||
case EVT_ACTIONAIMING: return inst.mOnActionAiming;
|
||||
case EVT_ACTIONSHOOTING: return inst.mOnActionShooting;
|
||||
case EVT_ACTIONJUMPING: return inst.mOnActionJumping;
|
||||
case EVT_ACTIONLIEDOWN: return inst.mOnActionLieDown;
|
||||
case EVT_ACTIONGETTINGUP: return inst.mOnActionGettingUp;
|
||||
case EVT_ACTIONJUMPVEHICLE: return inst.mOnActionJumpVehicle;
|
||||
case EVT_ACTIONDRIVING: return inst.mOnActionDriving;
|
||||
case EVT_ACTIONDYING: return inst.mOnActionDying;
|
||||
case EVT_ACTIONWASTED: return inst.mOnActionWasted;
|
||||
case EVT_ACTIONEMBARKING: return inst.mOnActionEmbarking;
|
||||
case EVT_ACTIONDISEMBARKING: return inst.mOnActionDisembarking;
|
||||
case EVT_PLAYERBURNING: return inst.mOnBurning;
|
||||
case EVT_PLAYERCROUCHING: return inst.mOnCrouching;
|
||||
case EVT_PLAYERGAMEKEYS: return inst.mOnGameKeys;
|
||||
case EVT_PLAYERSTARTTYPING: return inst.mOnStartTyping;
|
||||
case EVT_PLAYERSTOPTYPING: return inst.mOnStopTyping;
|
||||
case EVT_PLAYERAWAY: return inst.mOnAway;
|
||||
case EVT_PLAYERMESSAGE: return inst.mOnMessage;
|
||||
case EVT_PLAYERCOMMAND: return inst.mOnCommand;
|
||||
case EVT_PLAYERPRIVATEMESSAGE: return inst.mOnPrivateMessage;
|
||||
case EVT_PLAYERKEYPRESS: return inst.mOnKeyPress;
|
||||
case EVT_PLAYERKEYRELEASE: return inst.mOnKeyRelease;
|
||||
case EVT_PLAYERSPECTATE: return inst.mOnSpectate;
|
||||
case EVT_PLAYERCRASHREPORT: return inst.mOnCrashreport;
|
||||
case EVT_OBJECTSHOT: return inst.mOnObjectShot;
|
||||
case EVT_OBJECTTOUCHED: return inst.mOnObjectTouched;
|
||||
case EVT_PICKUPCLAIMED: return inst.mOnPickupClaimed;
|
||||
case EVT_PICKUPCOLLECTED: return inst.mOnPickupCollected;
|
||||
case EVT_CHECKPOINTENTERED: return inst.mOnCheckpointEntered;
|
||||
case EVT_CHECKPOINTEXITED: return inst.mOnCheckpointExited;
|
||||
case EVT_CLIENTSCRIPTDATA: return inst.mOnClientScriptData;
|
||||
case EVT_PLAYERUPDATE: return inst.mOnUpdate;
|
||||
case EVT_PLAYERHEALTH: return inst.mOnHealth;
|
||||
case EVT_PLAYERARMOUR: return inst.mOnArmour;
|
||||
case EVT_PLAYERWEAPON: return inst.mOnWeapon;
|
||||
case EVT_PLAYERHEADING: return inst.mOnHeading;
|
||||
case EVT_PLAYERPOSITION: return inst.mOnPosition;
|
||||
case EVT_PLAYEROPTION: return inst.mOnOption;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Function & Core::GetVehicleEvent(Int32 id, Int32 evid)
|
||||
{
|
||||
VehicleInst & inst = m_Vehicles.at(id);
|
||||
|
||||
switch (evid)
|
||||
{
|
||||
case EVT_PLAYEREMBARKING: return inst.mOnEmbarking;
|
||||
case EVT_PLAYEREMBARKED: return inst.mOnEmbarked;
|
||||
case EVT_PLAYERDISEMBARK: return inst.mOnDisembark;
|
||||
case EVT_VEHICLEEXPLODE: return inst.mOnExplode;
|
||||
case EVT_VEHICLERESPAWN: return inst.mOnRespawn;
|
||||
case EVT_VEHICLEUPDATE: return inst.mOnUpdate;
|
||||
case EVT_VEHICLECOLOUR: return inst.mOnColour;
|
||||
case EVT_VEHICLEHEALTH: return inst.mOnHealth;
|
||||
case EVT_VEHICLEPOSITION: return inst.mOnPosition;
|
||||
case EVT_VEHICLEROTATION: return inst.mOnRotation;
|
||||
case EVT_VEHICLEOPTION: return inst.mOnOption;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
@@ -12,7 +12,7 @@ const Int32 CBlip::Max = SQMOD_BLIP_POOL;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CBlip::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqBlip");
|
||||
static const SQChar name[] = _SC("SqBlip");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -35,11 +35,17 @@ CBlip::~CBlip()
|
||||
Int32 CBlip::Cmp(const CBlip & o) const
|
||||
{
|
||||
if (m_ID == o.m_ID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_ID > o.m_ID)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -84,7 +90,7 @@ bool CBlip::Destroy(Int32 header, Object & payload)
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return _Core->DelBlip(m_ID, header, payload);
|
||||
return Core::Get().DelBlip(m_ID, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -93,7 +99,7 @@ void CBlip::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = _Core->GetBlipEvent(m_ID, evid);
|
||||
Function & event = Core::Get().GetBlipEvent(m_ID, evid);
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
@@ -112,7 +118,7 @@ Int32 CBlip::GetWorld() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mWorld;
|
||||
return Core::Get().GetBlip(m_ID).mWorld;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -121,7 +127,7 @@ Int32 CBlip::GetScale() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mScale;
|
||||
return Core::Get().GetBlip(m_ID).mScale;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -130,7 +136,7 @@ const Vector3 & CBlip::GetPosition() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mPosition;
|
||||
return Core::Get().GetBlip(m_ID).mPosition;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -139,7 +145,7 @@ const Color4 & CBlip::GetColor() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mColor;
|
||||
return Core::Get().GetBlip(m_ID).mColor;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -148,34 +154,34 @@ Int32 CBlip::GetSprID() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mSprID;
|
||||
return Core::Get().GetBlip(m_ID).mSprID;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CBlip::GetPosX() const
|
||||
Float32 CBlip::GetPositionX() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mPosition.x;
|
||||
return Core::Get().GetBlip(m_ID).mPosition.x;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CBlip::GetPosY() const
|
||||
Float32 CBlip::GetPositionY() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mPosition.y;
|
||||
return Core::Get().GetBlip(m_ID).mPosition.y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CBlip::GetPosZ() const
|
||||
Float32 CBlip::GetPositionZ() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mPosition.z;
|
||||
return Core::Get().GetBlip(m_ID).mPosition.z;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -184,7 +190,7 @@ Int32 CBlip::GetColorR() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mColor.r;
|
||||
return Core::Get().GetBlip(m_ID).mColor.r;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -193,7 +199,7 @@ Int32 CBlip::GetColorG() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mColor.g;
|
||||
return Core::Get().GetBlip(m_ID).mColor.g;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -202,7 +208,7 @@ Int32 CBlip::GetColorB() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mColor.b;
|
||||
return Core::Get().GetBlip(m_ID).mColor.b;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -211,14 +217,14 @@ Int32 CBlip::GetColorA() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetBlip(m_ID).mColor.a;
|
||||
return Core::Get().GetBlip(m_ID).mColor.a;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid)
|
||||
{
|
||||
return _Core->NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
|
||||
return Core::Get().NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
@@ -226,7 +232,7 @@ static Object & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int3
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
|
||||
return Core::Get().NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
|
||||
header, payload);
|
||||
}
|
||||
|
||||
@@ -234,7 +240,7 @@ static Object & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int3
|
||||
static Object & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
|
||||
Int32 scale, Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid)
|
||||
{
|
||||
return _Core->NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
|
||||
return Core::Get().NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
@@ -242,7 +248,7 @@ static Object & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Fl
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
|
||||
return Core::Get().NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
|
||||
header, payload);
|
||||
}
|
||||
|
||||
@@ -250,14 +256,14 @@ static Object & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Fl
|
||||
static Object & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
|
||||
Int32 sprid)
|
||||
{
|
||||
return _Core->NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
|
||||
return Core::Get().NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
|
||||
Int32 sprid, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
|
||||
return Core::Get().NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
|
||||
header, payload);
|
||||
}
|
||||
|
||||
@@ -265,14 +271,14 @@ static Object & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const
|
||||
static Object & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
|
||||
const Color4 & color, Int32 sprid)
|
||||
{
|
||||
return _Core->NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
|
||||
return Core::Get().NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
|
||||
const Color4 & color, Int32 sprid, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
|
||||
return Core::Get().NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
|
||||
header, payload);
|
||||
}
|
||||
|
||||
@@ -283,8 +289,8 @@ static const Object & Blip_FindByID(Int32 id)
|
||||
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
|
||||
STHROWF("The specified blip identifier is invalid: %d", id);
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Blips::const_iterator itr = _Core->GetBlips().cbegin();
|
||||
Core::Blips::const_iterator end = _Core->GetBlips().cend();
|
||||
Core::Blips::const_iterator itr = Core::Get().GetBlips().cbegin();
|
||||
Core::Blips::const_iterator end = Core::Get().GetBlips().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -306,8 +312,8 @@ static const Object & Blip_FindByTag(CSStr tag)
|
||||
STHROWF("The specified blip tag is invalid: null/empty");
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Blips::const_iterator itr = _Core->GetBlips().cbegin();
|
||||
Core::Blips::const_iterator end = _Core->GetBlips().cend();
|
||||
Core::Blips::const_iterator itr = Core::Get().GetBlips().cbegin();
|
||||
Core::Blips::const_iterator end = Core::Get().GetBlips().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -330,8 +336,8 @@ static const Object & Blip_FindBySprID(Int32 sprid)
|
||||
STHROWF("The specified sprite identifier is invalid: %d", sprid);
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Blips::const_iterator itr = _Core->GetBlips().cbegin();
|
||||
Core::Blips::const_iterator end = _Core->GetBlips().cend();
|
||||
Core::Blips::const_iterator itr = Core::Get().GetBlips().cbegin();
|
||||
Core::Blips::const_iterator end = Core::Get().GetBlips().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -351,8 +357,8 @@ static Array Blip_FindActive()
|
||||
// Remember the initial stack size
|
||||
StackGuard sg;
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Blips::const_iterator itr = _Core->GetBlips().cbegin();
|
||||
Core::Blips::const_iterator end = _Core->GetBlips().cend();
|
||||
Core::Blips::const_iterator itr = Core::Get().GetBlips().cbegin();
|
||||
Core::Blips::const_iterator end = Core::Get().GetBlips().cend();
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
@@ -403,13 +409,13 @@ void Register_CBlip(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Position"), &CBlip::GetPosition)
|
||||
.Prop(_SC("Color"), &CBlip::GetColor)
|
||||
.Prop(_SC("SprID"), &CBlip::GetSprID)
|
||||
.Prop(_SC("X"), &CBlip::GetPosX)
|
||||
.Prop(_SC("Y"), &CBlip::GetPosY)
|
||||
.Prop(_SC("Z"), &CBlip::GetPosZ)
|
||||
.Prop(_SC("R"), &CBlip::GetColorR)
|
||||
.Prop(_SC("G"), &CBlip::GetColorG)
|
||||
.Prop(_SC("B"), &CBlip::GetColorB)
|
||||
.Prop(_SC("A"), &CBlip::GetColorA)
|
||||
.Prop(_SC("PosX"), &CBlip::GetPositionX)
|
||||
.Prop(_SC("PosY"), &CBlip::GetPositionY)
|
||||
.Prop(_SC("PosZ"), &CBlip::GetPositionZ)
|
||||
.Prop(_SC("Red"), &CBlip::GetColorR)
|
||||
.Prop(_SC("Green"), &CBlip::GetColorG)
|
||||
.Prop(_SC("Blue"), &CBlip::GetColorB)
|
||||
.Prop(_SC("Alpha"), &CBlip::GetColorA)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("FindByID"), &Blip_FindByID)
|
||||
.StaticFunc(_SC("FindByTag"), &Blip_FindByTag)
|
||||
|
||||
@@ -185,17 +185,17 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the x axis of the managed blip entity.
|
||||
*/
|
||||
Float32 GetPosX() const;
|
||||
Float32 GetPositionX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the y axis of the managed blip entity.
|
||||
*/
|
||||
Float32 GetPosY() const;
|
||||
Float32 GetPositionY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the z axis of the managed blip entity.
|
||||
*/
|
||||
Float32 GetPosZ() const;
|
||||
Float32 GetPositionZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the red color of the managed blip entity.
|
||||
|
||||
@@ -14,10 +14,10 @@ Color4 CCheckpoint::s_Color4;
|
||||
Vector3 CCheckpoint::s_Vector3;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 CCheckpoint::s_ColorR;
|
||||
Uint32 CCheckpoint::s_ColorG;
|
||||
Uint32 CCheckpoint::s_ColorB;
|
||||
Uint32 CCheckpoint::s_ColorA;
|
||||
Int32 CCheckpoint::s_ColorR;
|
||||
Int32 CCheckpoint::s_ColorG;
|
||||
Int32 CCheckpoint::s_ColorB;
|
||||
Int32 CCheckpoint::s_ColorA;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Int32 CCheckpoint::Max = SQMOD_CHECKPOINT_POOL;
|
||||
@@ -25,7 +25,7 @@ const Int32 CCheckpoint::Max = SQMOD_CHECKPOINT_POOL;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CCheckpoint::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqCheckpoint");
|
||||
static const SQChar name[] = _SC("SqCheckpoint");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -48,11 +48,17 @@ CCheckpoint::~CCheckpoint()
|
||||
Int32 CCheckpoint::Cmp(const CCheckpoint & o) const
|
||||
{
|
||||
if (m_ID == o.m_ID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_ID > o.m_ID)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -97,7 +103,7 @@ bool CCheckpoint::Destroy(Int32 header, Object & payload)
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return _Core->DelCheckpoint(m_ID, header, payload);
|
||||
return Core::Get().DelCheckpoint(m_ID, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -106,7 +112,7 @@ void CCheckpoint::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = _Core->GetCheckpointEvent(m_ID, evid);
|
||||
Function & event = Core::Get().GetCheckpointEvent(m_ID, evid);
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
@@ -130,7 +136,16 @@ bool CCheckpoint::IsStreamedFor(CPlayer & player) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->IsCheckpointStreamedForPlayer(m_ID, player.GetID());
|
||||
return _Func->IsCheckPointStreamedForPlayer(m_ID, player.GetID());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CCheckpoint::IsSphere() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->IsCheckPointSphere(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -139,7 +154,7 @@ Int32 CCheckpoint::GetWorld() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->GetCheckpointWorld(m_ID);
|
||||
return _Func->GetCheckPointWorld(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -148,7 +163,7 @@ void CCheckpoint::SetWorld(Int32 world) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointWorld(m_ID, world);
|
||||
_Func->SetCheckPointWorld(m_ID, world);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -157,9 +172,9 @@ const Color4 & CCheckpoint::GetColor() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous color information, if any
|
||||
s_Color4.Clear();
|
||||
s_ColorR = s_ColorG = s_ColorB = s_ColorA = 0;
|
||||
// Query the server for the color values
|
||||
_Func->GetCheckpointColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB, &s_ColorA);
|
||||
_Func->GetCheckPointColour(m_ID, &s_ColorR, &s_ColorG, &s_ColorB, &s_ColorA);
|
||||
// Convert and assign the retrieved values
|
||||
s_Color4.Set(s_ColorR, s_ColorG, s_ColorB, s_ColorA);
|
||||
// Return the requested information
|
||||
@@ -172,7 +187,16 @@ void CCheckpoint::SetColor(const Color4 & col) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointColor(m_ID, col.r, col.g, col.b, col.a);
|
||||
_Func->SetCheckPointColour(m_ID, col.r, col.g, col.b, col.a);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CCheckpoint::SetColorEx(Uint8 r, Uint8 g, Uint8 b) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckPointColour(m_ID, r, g, b, 0xFF);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -181,7 +205,7 @@ void CCheckpoint::SetColorEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointColor(m_ID, r, g, b, a);
|
||||
_Func->SetCheckPointColour(m_ID, r, g, b, a);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -192,7 +216,7 @@ const Vector3 & CCheckpoint::GetPosition() const
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.Clear();
|
||||
// Query the server for the position values
|
||||
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
||||
_Func->GetCheckPointPosition(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3;
|
||||
}
|
||||
@@ -203,7 +227,7 @@ void CCheckpoint::SetPosition(const Vector3 & pos) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointPos(m_ID, pos.x, pos.y, pos.z);
|
||||
_Func->SetCheckPointPosition(m_ID, pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -212,7 +236,7 @@ void CCheckpoint::SetPositionEx(Float32 x, Float32 y, Float32 z) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointPos(m_ID, x, y, z);
|
||||
_Func->SetCheckPointPosition(m_ID, x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -221,7 +245,7 @@ Float32 CCheckpoint::GetRadius() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->GetCheckpointRadius(m_ID);
|
||||
return _Func->GetCheckPointRadius(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -230,7 +254,7 @@ void CCheckpoint::SetRadius(Float32 radius) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointRadius(m_ID, radius);
|
||||
_Func->SetCheckPointRadius(m_ID, radius);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -239,7 +263,7 @@ Object & CCheckpoint::GetOwner() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetPlayer(_Func->GetCheckpointOwner(m_ID)).mObj;
|
||||
return Core::Get().GetPlayer(_Func->GetCheckPointOwner(m_ID)).mObj;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -248,205 +272,208 @@ Int32 CCheckpoint::GetOwnerID() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->GetCheckpointOwner(m_ID);
|
||||
return _Func->GetCheckPointOwner(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CCheckpoint::GetPosX() const
|
||||
Float32 CCheckpoint::GetPositionX() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.x = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, NULL, NULL);
|
||||
_Func->GetCheckPointPosition(m_ID, &s_Vector3.x, nullptr, nullptr);
|
||||
// Return the requested information
|
||||
return s_Vector3.x;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CCheckpoint::GetPosY() const
|
||||
Float32 CCheckpoint::GetPositionY() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.y = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetCheckpointPos(m_ID, NULL, &s_Vector3.y, NULL);
|
||||
_Func->GetCheckPointPosition(m_ID, nullptr, &s_Vector3.y, nullptr);
|
||||
// Return the requested information
|
||||
return s_Vector3.y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CCheckpoint::GetPosZ() const
|
||||
Float32 CCheckpoint::GetPositionZ() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.z = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetCheckpointPos(m_ID, NULL, NULL, &s_Vector3.z);
|
||||
_Func->GetCheckPointPosition(m_ID, nullptr, nullptr, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3.z;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CCheckpoint::SetPosX(Float32 x) const
|
||||
void CCheckpoint::SetPositionX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetCheckpointPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
|
||||
_Func->GetCheckPointPosition(m_ID, nullptr, &s_Vector3.y, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointPos(m_ID, x, s_Vector3.y, s_Vector3.z);
|
||||
_Func->SetCheckPointPosition(m_ID, x, s_Vector3.y, s_Vector3.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CCheckpoint::SetPosY(Float32 y) const
|
||||
void CCheckpoint::SetPositionY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
|
||||
_Func->GetCheckPointPosition(m_ID, &s_Vector3.x, nullptr, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointPos(m_ID, s_Vector3.x, y, s_Vector3.z);
|
||||
_Func->SetCheckPointPosition(m_ID, s_Vector3.x, y, s_Vector3.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CCheckpoint::SetPosZ(Float32 z) const
|
||||
void CCheckpoint::SetPositionZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
|
||||
_Func->GetCheckPointPosition(m_ID, &s_Vector3.x, &s_Vector3.y, nullptr);
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointPos(m_ID, s_Vector3.z, s_Vector3.y, z);
|
||||
_Func->SetCheckPointPosition(m_ID, s_Vector3.z, s_Vector3.y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 CCheckpoint::GetColR() const
|
||||
Int32 CCheckpoint::GetColorR() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous color information, if any
|
||||
s_ColorR = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetCheckpointColor(m_ID, &s_ColorR, NULL, NULL, NULL);
|
||||
_Func->GetCheckPointColour(m_ID, &s_ColorR, NULL, NULL, NULL);
|
||||
// Return the requested information
|
||||
return s_ColorR;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 CCheckpoint::GetColG() const
|
||||
Int32 CCheckpoint::GetColorG() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous color information, if any
|
||||
s_ColorG = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetCheckpointColor(m_ID, NULL, &s_ColorG, NULL, NULL);
|
||||
_Func->GetCheckPointColour(m_ID, NULL, &s_ColorG, NULL, NULL);
|
||||
// Return the requested information
|
||||
return s_ColorG;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 CCheckpoint::GetColB() const
|
||||
Int32 CCheckpoint::GetColorB() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous color information, if any
|
||||
s_ColorB = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetCheckpointColor(m_ID, NULL, NULL, &s_ColorB, NULL);
|
||||
_Func->GetCheckPointColour(m_ID, NULL, NULL, &s_ColorB, NULL);
|
||||
// Return the requested information
|
||||
return s_ColorB;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 CCheckpoint::GetColA() const
|
||||
Int32 CCheckpoint::GetColorA() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous color information, if any
|
||||
s_ColorA = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetCheckpointColor(m_ID, NULL, NULL, NULL, &s_ColorA);
|
||||
_Func->GetCheckPointColour(m_ID, NULL, NULL, NULL, &s_ColorA);
|
||||
// Return the requested information
|
||||
return s_ColorA;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CCheckpoint::SetColR(Uint32 r) const
|
||||
void CCheckpoint::SetColorR(Int32 r) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetCheckpointColor(m_ID, NULL, &s_ColorG, &s_ColorB, &s_ColorA);
|
||||
_Func->GetCheckPointColour(m_ID, NULL, &s_ColorG, &s_ColorB, &s_ColorA);
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointColor(m_ID, r, s_ColorG, s_ColorB, s_ColorA);
|
||||
_Func->SetCheckPointColour(m_ID, r, s_ColorG, s_ColorB, s_ColorA);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CCheckpoint::SetColG(Uint32 g) const
|
||||
void CCheckpoint::SetColorG(Int32 g) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetCheckpointColor(m_ID, &s_ColorR, NULL, &s_ColorB, &s_ColorA);
|
||||
_Func->GetCheckPointColour(m_ID, &s_ColorR, NULL, &s_ColorB, &s_ColorA);
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointColor(m_ID, s_ColorR, g, s_ColorB, s_ColorA);
|
||||
_Func->SetCheckPointColour(m_ID, s_ColorR, g, s_ColorB, s_ColorA);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CCheckpoint::SetColB(Uint32 b) const
|
||||
void CCheckpoint::SetColorB(Int32 b) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetCheckpointColor(m_ID, &s_ColorB, &s_ColorG, NULL, &s_ColorA);
|
||||
_Func->GetCheckPointColour(m_ID, &s_ColorB, &s_ColorG, NULL, &s_ColorA);
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointColor(m_ID, s_ColorB, s_ColorG, b, s_ColorA);
|
||||
_Func->SetCheckPointColour(m_ID, s_ColorB, s_ColorG, b, s_ColorA);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CCheckpoint::SetColA(Uint32 a) const
|
||||
void CCheckpoint::SetColorA(Int32 a) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetCheckpointColor(m_ID, &s_ColorA, &s_ColorG, &s_ColorB, NULL);
|
||||
_Func->GetCheckPointColour(m_ID, &s_ColorA, &s_ColorG, &s_ColorB, NULL);
|
||||
// Perform the requested operation
|
||||
_Func->SetCheckpointColor(m_ID, s_ColorA, s_ColorG, s_ColorB, a);
|
||||
_Func->SetCheckPointColour(m_ID, s_ColorA, s_ColorG, s_ColorB, a);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Checkpoint_CreateEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
|
||||
static Object & Checkpoint_CreateEx(CPlayer & player, Int32 world, bool sphere,
|
||||
Float32 x, Float32 y, Float32 z,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius)
|
||||
{
|
||||
return _Core->NewCheckpoint(player.GetID(), world, x, y, z, r, g, b, a, radius,
|
||||
return Core::Get().NewCheckpoint(player.GetID(), world, sphere, x, y, z, r, g, b, a, radius,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Checkpoint_CreateEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
|
||||
static Object & Checkpoint_CreateEx(CPlayer & player, Int32 world, bool sphere,
|
||||
Float32 x, Float32 y, Float32 z,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewCheckpoint(player.GetID(), world, x, y, z, r, g, b, a, radius, header, payload);
|
||||
return Core::Get().NewCheckpoint(player.GetID(), world, sphere, x, y, z, r, g, b, a,
|
||||
radius, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Checkpoint_Create(CPlayer & player, Int32 world, const Vector3 & pos,
|
||||
static Object & Checkpoint_Create(CPlayer & player, Int32 world, bool sphere, const Vector3 & pos,
|
||||
const Color4 & color, Float32 radius)
|
||||
{
|
||||
return _Core->NewCheckpoint(player.GetID(), world, pos.x, pos.y, pos.z,
|
||||
return Core::Get().NewCheckpoint(player.GetID(), world, sphere, pos.x, pos.y, pos.z,
|
||||
color.r, color.g, color.b, color.a, radius,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Checkpoint_Create(CPlayer & player, Int32 world, const Vector3 & pos,
|
||||
static Object & Checkpoint_Create(CPlayer & player, Int32 world, bool sphere, const Vector3 & pos,
|
||||
const Color4 & color, Float32 radius, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewCheckpoint(player.GetID(), world, pos.x, pos.y, pos.z,
|
||||
return Core::Get().NewCheckpoint(player.GetID(), world, sphere, pos.x, pos.y, pos.z,
|
||||
color.r, color.g, color.b, color.a, radius, header, payload);
|
||||
}
|
||||
|
||||
@@ -459,8 +486,8 @@ static const Object & Checkpoint_FindByID(Int32 id)
|
||||
STHROWF("The specified checkpoint identifier is invalid: %d", id);
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Checkpoints::const_iterator itr = _Core->GetCheckpoints().cbegin();
|
||||
Core::Checkpoints::const_iterator end = _Core->GetCheckpoints().cend();
|
||||
Core::Checkpoints::const_iterator itr = Core::Get().GetCheckpoints().cbegin();
|
||||
Core::Checkpoints::const_iterator end = Core::Get().GetCheckpoints().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -483,8 +510,8 @@ static const Object & Checkpoint_FindByTag(CSStr tag)
|
||||
STHROWF("The specified checkpoint tag is invalid: null/empty");
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Checkpoints::const_iterator itr = _Core->GetCheckpoints().cbegin();
|
||||
Core::Checkpoints::const_iterator end = _Core->GetCheckpoints().cend();
|
||||
Core::Checkpoints::const_iterator itr = Core::Get().GetCheckpoints().cbegin();
|
||||
Core::Checkpoints::const_iterator end = Core::Get().GetCheckpoints().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -504,8 +531,8 @@ static Array Checkpoint_FindActive()
|
||||
// Remember the initial stack size
|
||||
StackGuard sg;
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Checkpoints::const_iterator itr = _Core->GetCheckpoints().cbegin();
|
||||
Core::Checkpoints::const_iterator end = _Core->GetCheckpoints().cend();
|
||||
Core::Checkpoints::const_iterator itr = Core::Get().GetCheckpoints().cbegin();
|
||||
Core::Checkpoints::const_iterator end = Core::Get().GetCheckpoints().cend();
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
@@ -550,6 +577,7 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
|
||||
.Overload< bool (CCheckpoint::*)(Int32) >(_SC("Destroy"), &CCheckpoint::Destroy)
|
||||
.Overload< bool (CCheckpoint::*)(Int32, Object &) >(_SC("Destroy"), &CCheckpoint::Destroy)
|
||||
// Properties
|
||||
.Prop(_SC("Sphere"), &CCheckpoint::IsSphere)
|
||||
.Prop(_SC("World"), &CCheckpoint::GetWorld, &CCheckpoint::SetWorld)
|
||||
.Prop(_SC("Color"), &CCheckpoint::GetColor, &CCheckpoint::SetColor)
|
||||
.Prop(_SC("Pos"), &CCheckpoint::GetPosition, &CCheckpoint::SetPosition)
|
||||
@@ -557,30 +585,34 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Radius"), &CCheckpoint::GetRadius, &CCheckpoint::SetRadius)
|
||||
.Prop(_SC("Owner"), &CCheckpoint::GetOwner)
|
||||
.Prop(_SC("OwnerID"), &CCheckpoint::GetOwnerID)
|
||||
.Prop(_SC("X"), &CCheckpoint::GetPosX, &CCheckpoint::SetPosX)
|
||||
.Prop(_SC("Y"), &CCheckpoint::GetPosY, &CCheckpoint::SetPosY)
|
||||
.Prop(_SC("Z"), &CCheckpoint::GetPosZ, &CCheckpoint::SetPosZ)
|
||||
.Prop(_SC("R"), &CCheckpoint::GetColR, &CCheckpoint::SetColR)
|
||||
.Prop(_SC("G"), &CCheckpoint::GetColG, &CCheckpoint::SetColG)
|
||||
.Prop(_SC("B"), &CCheckpoint::GetColB, &CCheckpoint::SetColB)
|
||||
.Prop(_SC("A"), &CCheckpoint::GetColA, &CCheckpoint::SetColA)
|
||||
.Prop(_SC("PosX"), &CCheckpoint::GetPositionX, &CCheckpoint::SetPositionX)
|
||||
.Prop(_SC("PosY"), &CCheckpoint::GetPositionY, &CCheckpoint::SetPositionY)
|
||||
.Prop(_SC("PosZ"), &CCheckpoint::GetPositionZ, &CCheckpoint::SetPositionZ)
|
||||
.Prop(_SC("Red"), &CCheckpoint::GetColorR, &CCheckpoint::SetColorR)
|
||||
.Prop(_SC("Green"), &CCheckpoint::GetColorG, &CCheckpoint::SetColorG)
|
||||
.Prop(_SC("Blue"), &CCheckpoint::GetColorB, &CCheckpoint::SetColorB)
|
||||
.Prop(_SC("Alpha"), &CCheckpoint::GetColorA, &CCheckpoint::SetColorA)
|
||||
// Member Methods
|
||||
.Func(_SC("StreamedFor"), &CCheckpoint::IsStreamedFor)
|
||||
.Func(_SC("SetColor"), &CCheckpoint::SetColorEx)
|
||||
.Func(_SC("SetPos"), &CCheckpoint::SetPositionEx)
|
||||
.Func(_SC("SetPosition"), &CCheckpoint::SetPositionEx)
|
||||
// Member Overloads
|
||||
.Overload< void (CCheckpoint::*)(Uint8, Uint8, Uint8) const >
|
||||
(_SC("SetColor"), &CCheckpoint::SetColorEx)
|
||||
.Overload< void (CCheckpoint::*)(Uint8, Uint8, Uint8, Uint8) const >
|
||||
(_SC("SetColor"), &CCheckpoint::SetColorEx)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("FindByID"), &Checkpoint_FindByID)
|
||||
.StaticFunc(_SC("FindByTag"), &Checkpoint_FindByTag)
|
||||
.StaticFunc(_SC("FindActive"), &Checkpoint_FindActive)
|
||||
// Static Overloads
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
|
||||
(_SC("CreateEx"), &Checkpoint_CreateEx)
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
|
||||
(_SC("CreateEx"), &Checkpoint_CreateEx)
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color4 &, Float32) >
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, bool, const Vector3 &, const Color4 &, Float32) >
|
||||
(_SC("Create"), &Checkpoint_Create)
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color4 &, Float32, Int32, Object &) >
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, bool, const Vector3 &, const Color4 &, Float32, Int32, Object &) >
|
||||
(_SC("Create"), &Checkpoint_Create)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ private:
|
||||
static Vector3 s_Vector3;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static Uint32 s_ColorR, s_ColorG, s_ColorB, s_ColorA;
|
||||
static Int32 s_ColorR, s_ColorG, s_ColorB, s_ColorA;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Identifier of the managed entity.
|
||||
@@ -169,6 +169,11 @@ public:
|
||||
*/
|
||||
bool IsStreamedFor(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if the managed checkpoint entity of sphere type.
|
||||
*/
|
||||
bool IsSphere() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the world in which the managed checkpoint entity exists.
|
||||
*/
|
||||
@@ -189,6 +194,11 @@ public:
|
||||
*/
|
||||
void SetColor(const Color4 & col) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the color of the managed checkpoint entity.
|
||||
*/
|
||||
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the color of the managed checkpoint entity.
|
||||
*/
|
||||
@@ -232,72 +242,72 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the x axis of the managed checkpoint entity.
|
||||
*/
|
||||
Float32 GetPosX() const;
|
||||
Float32 GetPositionX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the y axis of the managed checkpoint entity.
|
||||
*/
|
||||
Float32 GetPosY() const;
|
||||
Float32 GetPositionY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the z axis of the managed checkpoint entity.
|
||||
*/
|
||||
Float32 GetPosZ() const;
|
||||
Float32 GetPositionZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the x axis of the managed checkpoint entity.
|
||||
*/
|
||||
void SetPosX(Float32 x) const;
|
||||
void SetPositionX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the y axis of the managed checkpoint entity.
|
||||
*/
|
||||
void SetPosY(Float32 y) const;
|
||||
void SetPositionY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the z axis of the managed checkpoint entity.
|
||||
*/
|
||||
void SetPosZ(Float32 z) const;
|
||||
void SetPositionZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the red color of the managed checkpoint entity.
|
||||
*/
|
||||
Uint32 GetColR() const;
|
||||
Int32 GetColorR() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the green color of the managed checkpoint entity.
|
||||
*/
|
||||
Uint32 GetColG() const;
|
||||
Int32 GetColorG() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the blue color of the managed checkpoint entity.
|
||||
*/
|
||||
Uint32 GetColB() const;
|
||||
Int32 GetColorB() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the alpha transparency of the managed checkpoint entity.
|
||||
*/
|
||||
Uint32 GetColA() const;
|
||||
Int32 GetColorA() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the red color of the managed checkpoint entity.
|
||||
*/
|
||||
void SetColR(Uint32 r) const;
|
||||
void SetColorR(Int32 r) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the green color of the managed checkpoint entity.
|
||||
*/
|
||||
void SetColG(Uint32 g) const;
|
||||
void SetColorG(Int32 g) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the blue color of the managed checkpoint entity.
|
||||
*/
|
||||
void SetColB(Uint32 b) const;
|
||||
void SetColorB(Int32 b) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the alpha transparency of the managed checkpoint entity.
|
||||
*/
|
||||
void SetColA(Uint32 a) const;
|
||||
void SetColorA(Int32 a) const;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -1,561 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Entity/Forcefield.hpp"
|
||||
#include "Entity/Player.hpp"
|
||||
#include "Base/Color3.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Color3 CForcefield::s_Color3;
|
||||
Vector3 CForcefield::s_Vector3;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 CForcefield::s_ColorR;
|
||||
Uint32 CForcefield::s_ColorG;
|
||||
Uint32 CForcefield::s_ColorB;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Int32 CForcefield::Max = SQMOD_FORCEFIELD_POOL;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CForcefield::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqForcefield");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CForcefield::CForcefield(Int32 id)
|
||||
: m_ID(VALID_ENTITYGETEX(id, SQMOD_FORCEFIELD_POOL))
|
||||
, m_Tag(ToStrF("%d", id))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CForcefield::~CForcefield()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CForcefield::Cmp(const CForcefield & o) const
|
||||
{
|
||||
if (m_ID == o.m_ID)
|
||||
return 0;
|
||||
else if (m_ID > o.m_ID)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const String & CForcefield::ToString() const
|
||||
{
|
||||
return m_Tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const String & CForcefield::GetTag() const
|
||||
{
|
||||
return m_Tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetTag(CSStr tag)
|
||||
{
|
||||
m_Tag.assign(tag);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & CForcefield::GetData()
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetData(Object & data)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Apply the specified value
|
||||
m_Data = data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CForcefield::Destroy(Int32 header, Object & payload)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return _Core->DelForcefield(m_ID, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = _Core->GetForcefieldEvent(m_ID, evid);
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
event.Release(); // Then release the current callback
|
||||
}
|
||||
// Assign the specified environment and function
|
||||
else
|
||||
{
|
||||
event = Function(env.GetVM(), env, func.GetFunc());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CForcefield::IsStreamedFor(CPlayer & player) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->IsSphereStreamedForPlayer(m_ID, player.GetID());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CForcefield::GetWorld() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->GetSphereWorld(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetWorld(Int32 world) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSphereWorld(m_ID, world);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color3 & CForcefield::GetColor() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous color information, if any
|
||||
s_Color3.Clear();
|
||||
// Query the server for the color values
|
||||
_Func->GetSphereColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB);
|
||||
// Convert and assign the retrieved values
|
||||
s_Color3.Set(s_ColorR, s_ColorG, s_ColorB);
|
||||
// Return the requested information
|
||||
return s_Color3;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetColor(const Color3 & col) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSphereColor(m_ID, col.r, col.g, col.b);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetColorEx(Uint8 r, Uint8 g, Uint8 b) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSphereColor(m_ID, r, g, b);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector3 & CForcefield::GetPosition() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.Clear();
|
||||
// Query the server for the position values
|
||||
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetPosition(const Vector3 & pos) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSpherePos(m_ID, pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetPositionEx(Float32 x, Float32 y, Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSpherePos(m_ID, x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CForcefield::GetRadius() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->GetSphereRadius(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetRadius(Float32 radius) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSphereRadius(m_ID, radius);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & CForcefield::GetOwner() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetPlayer(_Func->GetSphereOwner(m_ID)).mObj;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CForcefield::GetOwnerID() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->GetSphereOwner(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CForcefield::GetPosX() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.x = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetSpherePos(m_ID, &s_Vector3.x, NULL, NULL);
|
||||
// Return the requested information
|
||||
return s_Vector3.x;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CForcefield::GetPosY() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.y = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetSpherePos(m_ID, NULL, &s_Vector3.y, NULL);
|
||||
// Return the requested information
|
||||
return s_Vector3.y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CForcefield::GetPosZ() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.z = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetSpherePos(m_ID, NULL, NULL, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3.z;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetPosX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetSpherePos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->SetSpherePos(m_ID, x, s_Vector3.y, s_Vector3.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetPosY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetSpherePos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->SetSpherePos(m_ID, s_Vector3.x, y, s_Vector3.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetPosZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
|
||||
// Perform the requested operation
|
||||
_Func->SetSpherePos(m_ID, s_Vector3.z, s_Vector3.y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 CForcefield::GetColR() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous color information, if any
|
||||
s_ColorR = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetSphereColor(m_ID, &s_ColorR, NULL, NULL);
|
||||
// Return the requested information
|
||||
return s_ColorR;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 CForcefield::GetColG() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Query the server for the requested component value
|
||||
s_ColorG = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetSphereColor(m_ID, NULL, &s_ColorG, NULL);
|
||||
// Return the requested information
|
||||
return s_ColorG;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 CForcefield::GetColB() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Query the server for the requested component value
|
||||
s_ColorB = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetSphereColor(m_ID, NULL, NULL, &s_ColorB);
|
||||
// Return the requested information
|
||||
return s_ColorB;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetColR(Uint32 r) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetSphereColor(m_ID, NULL, &s_ColorG, &s_ColorB);
|
||||
// Perform the requested operation
|
||||
_Func->SetSphereColor(m_ID, r, s_ColorG, s_ColorB);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetColG(Uint32 g) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetSphereColor(m_ID, &s_ColorR, NULL, &s_ColorB);
|
||||
// Perform the requested operation
|
||||
_Func->SetSphereColor(m_ID, s_ColorR, g, s_ColorB);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CForcefield::SetColB(Uint32 b) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetSphereColor(m_ID, &s_ColorB, &s_ColorG, NULL);
|
||||
// Perform the requested operation
|
||||
_Func->SetSphereColor(m_ID, s_ColorB, s_ColorG, b);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Forcefield_CreateEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
|
||||
Uint8 r, Uint8 g, Uint8 b, Float32 radius)
|
||||
{
|
||||
return _Core->NewForcefield(player.GetID(), world, x, y, z, r, g, b, radius,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Forcefield_CreateEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
|
||||
Uint8 r, Uint8 g, Uint8 b, Float32 radius,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewForcefield(player.GetID(), world, x, y, z, r, g, b, radius, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Forcefield_Create(CPlayer & player, Int32 world, const Vector3 & pos,
|
||||
const Color3 & color, Float32 radius)
|
||||
{
|
||||
return _Core->NewForcefield(player.GetID(), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Forcefield_Create(CPlayer & player, Int32 world, const Vector3 & pos,
|
||||
const Color3 & color, Float32 radius, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewForcefield(player.GetID(), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
|
||||
header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Object & Forcefield_FindByID(Int32 id)
|
||||
{
|
||||
// Perform a range check on the specified identifier
|
||||
if (INVALID_ENTITYEX(id, SQMOD_FORCEFIELD_POOL))
|
||||
{
|
||||
STHROWF("The specified forcefield identifier is invalid: %d", id);
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Forcefields::const_iterator itr = _Core->GetForcefields().cbegin();
|
||||
Core::Forcefields::const_iterator end = _Core->GetForcefields().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
// Does the identifier match the specified one?
|
||||
if (itr->mID == id)
|
||||
{
|
||||
return itr->mObj; // Stop searching and return this entity
|
||||
}
|
||||
}
|
||||
// Unable to locate a forcefield matching the specified identifier
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Object & Forcefield_FindByTag(CSStr tag)
|
||||
{
|
||||
// Perform a validity check on the specified tag
|
||||
if (!tag || *tag == '\0')
|
||||
{
|
||||
STHROWF("The specified forcefield tag is invalid: null/empty");
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Forcefields::const_iterator itr = _Core->GetForcefields().cbegin();
|
||||
Core::Forcefields::const_iterator end = _Core->GetForcefields().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
// Does this entity even exist and does the tag match the specified one?
|
||||
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
|
||||
{
|
||||
return itr->mObj; // Stop searching and return this entity
|
||||
}
|
||||
}
|
||||
// Unable to locate a forcefield matching the specified tag
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Array Forcefield_FindActive()
|
||||
{
|
||||
// Remember the initial stack size
|
||||
StackGuard sg;
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Forcefields::const_iterator itr = _Core->GetForcefields().cbegin();
|
||||
Core::Forcefields::const_iterator end = _Core->GetForcefields().cend();
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
// Is this entity instance active?
|
||||
if (VALID_ENTITY(itr->mID))
|
||||
{
|
||||
// Push the script object on the stack
|
||||
sq_pushobject(DefaultVM::Get(), (HSQOBJECT &)((*itr).mObj));
|
||||
// Append the object at the back of the array
|
||||
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -1)))
|
||||
{
|
||||
STHROWF("Unable to append entity instance to the list");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_CForcefield(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqForcefield"),
|
||||
Class< CForcefield, NoConstructor< CForcefield > >(vm, _SC("SqForcefield"))
|
||||
// Metamethods
|
||||
.Func(_SC("_cmp"), &CForcefield::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CForcefield::Typename)
|
||||
.Func(_SC("_tostring"), &CForcefield::ToString)
|
||||
// Static Values
|
||||
.SetStaticValue(_SC("MaxID"), CForcefield::Max)
|
||||
// Core Properties
|
||||
.Prop(_SC("ID"), &CForcefield::GetID)
|
||||
.Prop(_SC("Tag"), &CForcefield::GetTag, &CForcefield::SetTag)
|
||||
.Prop(_SC("Data"), &CForcefield::GetData, &CForcefield::SetData)
|
||||
.Prop(_SC("Active"), &CForcefield::IsActive)
|
||||
// Core Methods
|
||||
.Func(_SC("Bind"), &CForcefield::BindEvent)
|
||||
// Core Overloads
|
||||
.Overload< bool (CForcefield::*)(void) >(_SC("Destroy"), &CForcefield::Destroy)
|
||||
.Overload< bool (CForcefield::*)(Int32) >(_SC("Destroy"), &CForcefield::Destroy)
|
||||
.Overload< bool (CForcefield::*)(Int32, Object &) >(_SC("Destroy"), &CForcefield::Destroy)
|
||||
// Properties
|
||||
.Prop(_SC("World"), &CForcefield::GetWorld, &CForcefield::SetWorld)
|
||||
.Prop(_SC("Color"), &CForcefield::GetColor, &CForcefield::SetColor)
|
||||
.Prop(_SC("Pos"), &CForcefield::GetPosition, &CForcefield::SetPosition)
|
||||
.Prop(_SC("Position"), &CForcefield::GetPosition, &CForcefield::SetPosition)
|
||||
.Prop(_SC("Radius"), &CForcefield::GetRadius, &CForcefield::SetRadius)
|
||||
.Prop(_SC("Owner"), &CForcefield::GetOwner)
|
||||
.Prop(_SC("OwnerID"), &CForcefield::GetOwnerID)
|
||||
.Prop(_SC("X"), &CForcefield::GetPosX, &CForcefield::SetPosX)
|
||||
.Prop(_SC("Y"), &CForcefield::GetPosY, &CForcefield::SetPosY)
|
||||
.Prop(_SC("Z"), &CForcefield::GetPosZ, &CForcefield::SetPosZ)
|
||||
.Prop(_SC("R"), &CForcefield::GetColR, &CForcefield::SetColR)
|
||||
.Prop(_SC("G"), &CForcefield::GetColG, &CForcefield::SetColG)
|
||||
.Prop(_SC("B"), &CForcefield::GetColB, &CForcefield::SetColB)
|
||||
// Member Methods
|
||||
.Func(_SC("StreamedFor"), &CForcefield::IsStreamedFor)
|
||||
.Func(_SC("SetColor"), &CForcefield::SetColorEx)
|
||||
.Func(_SC("SetPos"), &CForcefield::SetPositionEx)
|
||||
.Func(_SC("SetPosition"), &CForcefield::SetPositionEx)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("FindByID"), &Forcefield_FindByID)
|
||||
.StaticFunc(_SC("FindByTag"), &Forcefield_FindByTag)
|
||||
.StaticFunc(_SC("FindActive"), &Forcefield_FindActive)
|
||||
// Static Overloads
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Float32) >
|
||||
(_SC("CreateEx"), &Forcefield_CreateEx)
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
|
||||
(_SC("CreateEx"), &Forcefield_CreateEx)
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color3 &, Float32) >
|
||||
(_SC("Create"), &Forcefield_Create)
|
||||
.StaticOverload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color3 &, Float32, Int32, Object &) >
|
||||
(_SC("Create"), &Forcefield_Create)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
@@ -1,295 +0,0 @@
|
||||
#ifndef _ENTITY_FORCEFIELD_HPP_
|
||||
#define _ENTITY_FORCEFIELD_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Manages a single forcefield entity.
|
||||
*/
|
||||
class CForcefield
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
friend class Core;
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static Color3 s_Color3;
|
||||
static Vector3 s_Vector3;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static Uint32 s_ColorR, s_ColorG, s_ColorB;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Identifier of the managed entity.
|
||||
*/
|
||||
Int32 m_ID;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* User tag associated with this instance.
|
||||
*/
|
||||
String m_Tag;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* User data associated with this instance.
|
||||
*/
|
||||
Object m_Data;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
CForcefield(Int32 id);
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Maximum possible number that could represent an identifier for this entity type.
|
||||
*/
|
||||
static const Int32 Max;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
CForcefield(const CForcefield &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
CForcefield(CForcefield &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~CForcefield();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
CForcefield & operator = (const CForcefield &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
CForcefield & operator = (CForcefield &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether this instance manages a valid entity otherwise throw an exception.
|
||||
*/
|
||||
void Validate() const
|
||||
{
|
||||
if (INVALID_ENTITY(m_ID))
|
||||
{
|
||||
STHROWF("Invalid forcefield reference [%s]", m_Tag.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare two instances of this type.
|
||||
*/
|
||||
Int32 Cmp(const CForcefield & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
const String & ToString() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to retrieve the name from instances of this type.
|
||||
*/
|
||||
static SQInteger Typename(HSQUIRRELVM vm);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the identifier of the entity managed by this instance.
|
||||
*/
|
||||
Int32 GetID() const
|
||||
{
|
||||
return m_ID;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether this instance manages a valid entity.
|
||||
*/
|
||||
bool IsActive() const
|
||||
{
|
||||
return VALID_ENTITY(m_ID);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated user tag.
|
||||
*/
|
||||
const String & GetTag() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user tag.
|
||||
*/
|
||||
void SetTag(CSStr tag);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated user data.
|
||||
*/
|
||||
Object & GetData();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user data.
|
||||
*/
|
||||
void SetData(Object & data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroy the managed forcefield entity.
|
||||
*/
|
||||
bool Destroy()
|
||||
{
|
||||
return Destroy(0, NullObject());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroy the managed forcefield entity.
|
||||
*/
|
||||
bool Destroy(Int32 header)
|
||||
{
|
||||
return Destroy(header, NullObject());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroy the managed forcefield entity.
|
||||
*/
|
||||
bool Destroy(Int32 header, Object & payload);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Bind to an event supported by this entity type.
|
||||
*/
|
||||
void BindEvent(Int32 evid, Object & env, Function & func) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if the managed forcefield entity is streamed for the specified player.
|
||||
*/
|
||||
bool IsStreamedFor(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the world in which the managed forcefield entity exists.
|
||||
*/
|
||||
Int32 GetWorld() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the world in which the managed forcefield entity exists.
|
||||
*/
|
||||
void SetWorld(Int32 world) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the color of the managed forcefield entity.
|
||||
*/
|
||||
const Color3 & GetColor() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the color of the managed forcefield entity.
|
||||
*/
|
||||
void SetColor(const Color3 & col) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the color of the managed forcefield entity.
|
||||
*/
|
||||
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position of the managed forcefield entity.
|
||||
*/
|
||||
const Vector3 & GetPosition() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position of the managed forcefield entity.
|
||||
*/
|
||||
void SetPosition(const Vector3 & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position of the managed forcefield entity.
|
||||
*/
|
||||
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the radius of the managed forcefield entity.
|
||||
*/
|
||||
Float32 GetRadius() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the radius of the managed forcefield entity.
|
||||
*/
|
||||
void SetRadius(Float32 radius) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the owner of the managed forcefield entity.
|
||||
*/
|
||||
Object & GetOwner() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the owner identifier of the managed forcefield entity.
|
||||
*/
|
||||
Int32 GetOwnerID() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the x axis of the managed forcefield entity.
|
||||
*/
|
||||
Float32 GetPosX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the y axis of the managed forcefield entity.
|
||||
*/
|
||||
Float32 GetPosY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the z axis of the managed forcefield entity.
|
||||
*/
|
||||
Float32 GetPosZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the x axis of the managed forcefield entity.
|
||||
*/
|
||||
void SetPosX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the y axis of the managed forcefield entity.
|
||||
*/
|
||||
void SetPosY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the z axis of the managed forcefield entity.
|
||||
*/
|
||||
void SetPosZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the red color of the managed forcefield entity.
|
||||
*/
|
||||
Uint32 GetColR() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the green color of the managed forcefield entity.
|
||||
*/
|
||||
Uint32 GetColG() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the blue color of the managed forcefield entity.
|
||||
*/
|
||||
Uint32 GetColB() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the red color of the managed forcefield entity.
|
||||
*/
|
||||
void SetColR(Uint32 r) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the green color of the managed forcefield entity.
|
||||
*/
|
||||
void SetColG(Uint32 g) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the blue color of the managed forcefield entity.
|
||||
*/
|
||||
void SetColB(Uint32 b) const;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _ENTITY_FORCEFIELD_HPP_
|
||||
@@ -12,7 +12,7 @@ const Int32 CKeybind::Max = SQMOD_KEYBIND_POOL;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CKeybind::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqKeybind");
|
||||
static const SQChar name[] = _SC("SqKeybind");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -35,11 +35,17 @@ CKeybind::~CKeybind()
|
||||
Int32 CKeybind::Cmp(const CKeybind & o) const
|
||||
{
|
||||
if (m_ID == o.m_ID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_ID > o.m_ID)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -84,7 +90,7 @@ bool CKeybind::Destroy(Int32 header, Object & payload)
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return _Core->DelKeybind(m_ID, header, payload);
|
||||
return Core::Get().DelKeybind(m_ID, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -93,7 +99,7 @@ void CKeybind::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = _Core->GetKeybindEvent(m_ID, evid);
|
||||
Function & event = Core::Get().GetKeybindEvent(m_ID, evid);
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
@@ -112,7 +118,7 @@ Int32 CKeybind::GetFirst() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetKeybind(m_ID).mFirst;
|
||||
return Core::Get().GetKeybind(m_ID).mFirst;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -121,7 +127,7 @@ Int32 CKeybind::GetSecond() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetKeybind(m_ID).mSecond;
|
||||
return Core::Get().GetKeybind(m_ID).mSecond;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -130,7 +136,7 @@ Int32 CKeybind::GetThird() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetKeybind(m_ID).mThird;
|
||||
return Core::Get().GetKeybind(m_ID).mThird;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -139,34 +145,34 @@ bool CKeybind::IsRelease() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetKeybind(m_ID).mRelease;
|
||||
return Core::Get().GetKeybind(m_ID).mRelease;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
|
||||
Int32 alternative)
|
||||
{
|
||||
return _Core->NewKeybind(slot, release, primary, secondary, alternative,
|
||||
return Core::Get().NewKeybind(slot, release, primary, secondary, alternative,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
|
||||
Int32 alternative, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewKeybind(slot, release, primary, secondary, alternative, header, payload);
|
||||
return Core::Get().NewKeybind(slot, release, primary, secondary, alternative, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative)
|
||||
{
|
||||
return _Core->NewKeybind(-1, release, primary, secondary, alternative,
|
||||
return Core::Get().NewKeybind(-1, release, primary, secondary, alternative,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewKeybind(-1, release, primary, secondary, alternative, header, payload);
|
||||
return Core::Get().NewKeybind(-1, release, primary, secondary, alternative, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -178,8 +184,8 @@ static const Object & Keybind_FindByID(Int32 id)
|
||||
STHROWF("The specified keybind identifier is invalid: %d", id);
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Keybinds::const_iterator itr = _Core->GetKeybinds().cbegin();
|
||||
Core::Keybinds::const_iterator end = _Core->GetKeybinds().cend();
|
||||
Core::Keybinds::const_iterator itr = Core::Get().GetKeybinds().cbegin();
|
||||
Core::Keybinds::const_iterator end = Core::Get().GetKeybinds().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -202,8 +208,8 @@ static const Object & Keybind_FindByTag(CSStr tag)
|
||||
STHROWF("The specified keybind tag is invalid: null/empty");
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Keybinds::const_iterator itr = _Core->GetKeybinds().cbegin();
|
||||
Core::Keybinds::const_iterator end = _Core->GetKeybinds().cend();
|
||||
Core::Keybinds::const_iterator itr = Core::Get().GetKeybinds().cbegin();
|
||||
Core::Keybinds::const_iterator end = Core::Get().GetKeybinds().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -223,8 +229,8 @@ static Array Keybind_FindActive()
|
||||
// Remember the initial stack size
|
||||
StackGuard sg;
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Keybinds::const_iterator itr = _Core->GetKeybinds().cbegin();
|
||||
Core::Keybinds::const_iterator end = _Core->GetKeybinds().cend();
|
||||
Core::Keybinds::const_iterator itr = Core::Get().GetKeybinds().cbegin();
|
||||
Core::Keybinds::const_iterator end = Core::Get().GetKeybinds().cend();
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
|
||||
@@ -19,7 +19,7 @@ const Int32 CObject::Max = SQMOD_OBJECT_POOL;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CObject::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqObject");
|
||||
static const SQChar name[] = _SC("SqObject");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -27,7 +27,13 @@ SQInteger CObject::Typename(HSQUIRRELVM vm)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CObject::CObject(Int32 id)
|
||||
: m_ID(VALID_ENTITYGETEX(id, SQMOD_OBJECT_POOL))
|
||||
, m_Tag(ToStrF("%d", id))
|
||||
, m_Tag(ToStrF("%d", id)), m_Data()
|
||||
, mMoveToDuration(0)
|
||||
, mMoveByDuration(0)
|
||||
, mRotateToDuration(0)
|
||||
, mRotateByDuration(0)
|
||||
, mRotateToEulerDuration(0)
|
||||
, mRotateByEulerDuration(0)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@@ -42,11 +48,17 @@ CObject::~CObject()
|
||||
Int32 CObject::Cmp(const CObject & o) const
|
||||
{
|
||||
if (m_ID == o.m_ID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_ID > o.m_ID)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -91,7 +103,7 @@ bool CObject::Destroy(Int32 header, Object & payload)
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return _Core->DelObject(m_ID, header, payload);
|
||||
return Core::Get().DelObject(m_ID, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -100,7 +112,7 @@ void CObject::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = _Core->GetObjectEvent(m_ID, evid);
|
||||
Function & event = Core::Get().GetObjectEvent(m_ID, evid);
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
@@ -173,7 +185,7 @@ void CObject::SetAlpha(Int32 alpha) const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::SetAlphaEx(Int32 alpha, Int32 time) const
|
||||
void CObject::SetAlphaEx(Int32 alpha, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
@@ -182,7 +194,7 @@ void CObject::SetAlphaEx(Int32 alpha, Int32 time) const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveTo(const Vector3 & pos, Int32 time) const
|
||||
void CObject::MoveTo(const Vector3 & pos, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
@@ -191,7 +203,7 @@ void CObject::MoveTo(const Vector3 & pos, Int32 time) const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveToEx(Float32 x, Float32 y, Float32 z, Int32 time) const
|
||||
void CObject::MoveToEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
@@ -200,7 +212,7 @@ void CObject::MoveToEx(Float32 x, Float32 y, Float32 z, Int32 time) const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveBy(const Vector3 & pos, Int32 time) const
|
||||
void CObject::MoveBy(const Vector3 & pos, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
@@ -209,7 +221,7 @@ void CObject::MoveBy(const Vector3 & pos, Int32 time) const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveByEx(Float32 x, Float32 y, Float32 z, Int32 time) const
|
||||
void CObject::MoveByEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
@@ -222,10 +234,10 @@ const Vector3 & CObject::GetPosition()
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information
|
||||
// Clear previous information, if any
|
||||
s_Vector3.Clear();
|
||||
// Query the server for the position values
|
||||
_Func->GetObjectPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
||||
// Query the server for the values
|
||||
_Func->GetObjectPosition(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3;
|
||||
}
|
||||
@@ -236,7 +248,7 @@ void CObject::SetPosition(const Vector3 & pos) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetObjectPos(m_ID, pos.x, pos.y, pos.z);
|
||||
_Func->SetObjectPosition(m_ID, pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -245,79 +257,79 @@ void CObject::SetPositionEx(Float32 x, Float32 y, Float32 z) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetObjectPos(m_ID, x, y, z);
|
||||
_Func->SetObjectPosition(m_ID, x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateTo(const Quaternion & rot, Int32 time) const
|
||||
void CObject::RotateTo(const Quaternion & rot, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotObjectTo(m_ID, rot.x, rot.y, rot.z, rot.w, time);
|
||||
_Func->RotateObjectTo(m_ID, rot.x, rot.y, rot.z, rot.w, time);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const
|
||||
void CObject::RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotObjectTo(m_ID, x, y, z, w, time);
|
||||
_Func->RotateObjectTo(m_ID, x, y, z, w, time);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToEuler(const Vector3 & rot, Int32 time) const
|
||||
void CObject::RotateToEuler(const Vector3 & rot, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotObjectToEuler(m_ID, rot.x, rot.y, rot.z, time);
|
||||
_Func->RotateObjectToEuler(m_ID, rot.x, rot.y, rot.z, time);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const
|
||||
void CObject::RotateToEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotObjectToEuler(m_ID, x, y, z, time);
|
||||
_Func->RotateObjectToEuler(m_ID, x, y, z, time);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateBy(const Quaternion & rot, Int32 time) const
|
||||
void CObject::RotateBy(const Quaternion & rot, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotObjectBy(m_ID, rot.x, rot.y, rot.z, rot.w, time);
|
||||
_Func->RotateObjectBy(m_ID, rot.x, rot.y, rot.z, rot.w, time);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const
|
||||
void CObject::RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotObjectBy(m_ID, x, y, z, w, time);
|
||||
_Func->RotateObjectBy(m_ID, x, y, z, w, time);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByEuler(const Vector3 & rot, Int32 time) const
|
||||
void CObject::RotateByEuler(const Vector3 & rot, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotObjectByEuler(m_ID, rot.x, rot.y, rot.z, time);
|
||||
_Func->RotateObjectByEuler(m_ID, rot.x, rot.y, rot.z, time);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const
|
||||
void CObject::RotateByEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotObjectByEuler(m_ID, x, y, z, time);
|
||||
_Func->RotateObjectByEuler(m_ID, x, y, z, time);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -325,10 +337,10 @@ const Quaternion & CObject::GetRotation()
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous rotation information
|
||||
// Clear previous information, if any
|
||||
s_Quaternion.Clear();
|
||||
// Query the server for the rotation values
|
||||
_Func->GetObjectRot(m_ID, &s_Quaternion.x, &s_Quaternion.y, &s_Quaternion.z, &s_Quaternion.w);
|
||||
// Query the server for the values
|
||||
_Func->GetObjectRotation(m_ID, &s_Quaternion.x, &s_Quaternion.y, &s_Quaternion.z, &s_Quaternion.w);
|
||||
// Return the requested information
|
||||
return s_Quaternion;
|
||||
}
|
||||
@@ -338,10 +350,10 @@ const Vector3 & CObject::GetRotationEuler()
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous rotation information
|
||||
// Clear previous information, if any
|
||||
s_Vector3.Clear();
|
||||
// Query the server for the rotation values
|
||||
_Func->GetObjectRotEuler(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
||||
// Query the server for the values
|
||||
_Func->GetObjectRotationEuler(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3;
|
||||
}
|
||||
@@ -352,7 +364,7 @@ bool CObject::GetShotReport() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->IsObjectShotReport(m_ID);
|
||||
return _Func->IsObjectShotReportEnabled(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -361,214 +373,434 @@ void CObject::SetShotReport(bool toggle) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetObjectShotReport(m_ID, toggle);
|
||||
_Func->SetObjectShotReportEnabled(m_ID, toggle);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CObject::GetBumpReport() const
|
||||
bool CObject::GetTouchedReport() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->IsObjectBumpReport(m_ID);
|
||||
return _Func->IsObjectTouchedReportEnabled(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::SetBumpReport(bool toggle) const
|
||||
void CObject::SetTouchedReport(bool toggle) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetObjectBumpReport(m_ID, toggle);
|
||||
_Func->SetObjectTouchedReportEnabled(m_ID, toggle);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetPosX() const
|
||||
Float32 CObject::GetPositionX() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.x = 0;
|
||||
// Clear previous information, if any
|
||||
s_Vector3.x = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectPos(m_ID, &s_Vector3.x, NULL, NULL);
|
||||
_Func->GetObjectPosition(m_ID, &s_Vector3.x, nullptr, nullptr);
|
||||
// Return the requested information
|
||||
return s_Vector3.x;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetPosY() const
|
||||
Float32 CObject::GetPositionY() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.y = 0;
|
||||
// Clear previous information, if any
|
||||
s_Vector3.y = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectPos(m_ID, NULL, &s_Vector3.y, NULL);
|
||||
_Func->GetObjectPosition(m_ID, nullptr, &s_Vector3.y, nullptr);
|
||||
// Return the requested information
|
||||
return s_Vector3.y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetPosZ() const
|
||||
Float32 CObject::GetPositionZ() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.z = 0;
|
||||
// Clear previous information, if any
|
||||
s_Vector3.z = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectPos(m_ID, NULL, NULL, &s_Vector3.z);
|
||||
_Func->GetObjectPosition(m_ID, nullptr, nullptr, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3.z;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::SetPosX(Float32 x) const
|
||||
void CObject::SetPositionX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
|
||||
_Func->GetObjectPosition(m_ID, nullptr, &s_Vector3.y, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->SetObjectPos(m_ID, x, s_Vector3.y, s_Vector3.z);
|
||||
_Func->SetObjectPosition(m_ID, x, s_Vector3.y, s_Vector3.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::SetPosY(Float32 y) const
|
||||
void CObject::SetPositionY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
|
||||
_Func->GetObjectPosition(m_ID, &s_Vector3.x, nullptr, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->SetObjectPos(m_ID, s_Vector3.x, y, s_Vector3.z);
|
||||
_Func->SetObjectPosition(m_ID, s_Vector3.x, y, s_Vector3.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::SetPosZ(Float32 z) const
|
||||
void CObject::SetPositionZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
|
||||
_Func->GetObjectPosition(m_ID, &s_Vector3.x, &s_Vector3.y, nullptr);
|
||||
// Perform the requested operation
|
||||
_Func->SetObjectPos(m_ID, s_Vector3.z, s_Vector3.y, z);
|
||||
_Func->SetObjectPosition(m_ID, s_Vector3.z, s_Vector3.y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetRotX() const
|
||||
Float32 CObject::GetRotationX() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous rotation information, if any
|
||||
s_Quaternion.x = 0;
|
||||
// Clear previous information, if any
|
||||
s_Quaternion.x = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectRot(m_ID, &s_Quaternion.x, NULL, NULL, NULL);
|
||||
_Func->GetObjectRotation(m_ID, &s_Quaternion.x, nullptr, nullptr, nullptr);
|
||||
// Return the requested information
|
||||
return s_Quaternion.x;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetRotY() const
|
||||
Float32 CObject::GetRotationY() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous rotation information, if any
|
||||
s_Quaternion.y = 0;
|
||||
// Clear previous information, if any
|
||||
s_Quaternion.y = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectRot(m_ID, NULL, &s_Quaternion.y, NULL, NULL);
|
||||
_Func->GetObjectRotation(m_ID, nullptr, &s_Quaternion.y, nullptr, nullptr);
|
||||
// Return the requested information
|
||||
return s_Quaternion.y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetRotZ() const
|
||||
Float32 CObject::GetRotationZ() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous rotation information, if any
|
||||
s_Quaternion.z = 0;
|
||||
// Clear previous information, if any
|
||||
s_Quaternion.z = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectRot(m_ID, NULL, NULL, &s_Quaternion.z, NULL);
|
||||
_Func->GetObjectRotation(m_ID, nullptr, nullptr, &s_Quaternion.z, nullptr);
|
||||
// Return the requested information
|
||||
return s_Quaternion.z;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetRotW() const
|
||||
Float32 CObject::GetRotationW() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous rotation information, if any
|
||||
s_Quaternion.w = 0;
|
||||
// Clear previous information, if any
|
||||
s_Quaternion.w = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectRot(m_ID, NULL, NULL, NULL, &s_Quaternion.w);
|
||||
_Func->GetObjectRotation(m_ID, nullptr, nullptr, nullptr, &s_Quaternion.w);
|
||||
// Return the requested information
|
||||
return s_Quaternion.w;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetERotX() const
|
||||
Float32 CObject::GetEulerRotationX() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous rotation information, if any
|
||||
s_Vector3.x = 0;
|
||||
// Clear previous information, if any
|
||||
s_Vector3.x = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectRotEuler(m_ID, &s_Vector3.x, NULL, NULL);
|
||||
_Func->GetObjectRotationEuler(m_ID, &s_Vector3.x, nullptr, nullptr);
|
||||
// Return the requested information
|
||||
return s_Vector3.x;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetERotY() const
|
||||
Float32 CObject::GetEulerRotationY() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous rotation information, if any
|
||||
s_Vector3.y = 0;
|
||||
// Clear previous information, if any
|
||||
s_Vector3.y = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectRotEuler(m_ID, NULL, &s_Vector3.y, NULL);
|
||||
_Func->GetObjectRotationEuler(m_ID, nullptr, &s_Vector3.y, nullptr);
|
||||
// Return the requested information
|
||||
return s_Vector3.y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CObject::GetERotZ() const
|
||||
Float32 CObject::GetEulerRotationZ() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous rotation information, if any
|
||||
s_Vector3.z = 0;
|
||||
// Clear previous information, if any
|
||||
s_Vector3.z = 0.0f;
|
||||
// Query the server for the requested component value
|
||||
_Func->GetObjectRotEuler(m_ID, NULL, NULL, &s_Vector3.z);
|
||||
_Func->GetObjectRotationEuler(m_ID, nullptr, nullptr, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3.z;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveToX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Vector3.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectPosition(m_ID, nullptr, &s_Vector3.y, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->MoveObjectTo(m_ID, x, s_Vector3.y, s_Vector3.z, mMoveToDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveToY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Vector3.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectPosition(m_ID, &s_Vector3.x, nullptr, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->MoveObjectTo(m_ID, s_Vector3.x, y, s_Vector3.z, mMoveToDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveToZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Vector3.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectPosition(m_ID, &s_Vector3.x, &s_Vector3.y, nullptr);
|
||||
// Perform the requested operation
|
||||
_Func->MoveObjectTo(m_ID, s_Vector3.z, s_Vector3.y, z, mMoveToDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveByX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveObjectBy(m_ID, x, 0.0f, 0.0f, mMoveByDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveByY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveObjectBy(m_ID, 0.0f, y, 0.0f, mMoveByDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::MoveByZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveObjectBy(m_ID, 0.0f, 0.0f, z, mMoveByDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Quaternion.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectRotation(m_ID, nullptr, &s_Quaternion.y, &s_Quaternion.z, &s_Quaternion.w);
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectTo(m_ID, x, s_Quaternion.y, s_Quaternion.z, s_Quaternion.w, mRotateToDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Quaternion.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectRotation(m_ID, &s_Quaternion.x, nullptr, &s_Quaternion.z, &s_Quaternion.w);
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectTo(m_ID, s_Quaternion.x, y, s_Quaternion.z, s_Quaternion.w, mRotateToDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Quaternion.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectRotation(m_ID, &s_Quaternion.x, &s_Quaternion.y, nullptr, &s_Quaternion.w);
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectTo(m_ID, s_Quaternion.x, s_Quaternion.y, z, s_Quaternion.w, mRotateToDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToW(Float32 w) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Quaternion.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectRotation(m_ID, &s_Quaternion.x, &s_Quaternion.y, &s_Quaternion.z, nullptr);
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectTo(m_ID, s_Quaternion.x, s_Quaternion.y, s_Quaternion.z, w, mRotateToDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectBy(m_ID, x, 0.0f, 0.0f, 0.0f, mRotateByDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectBy(m_ID, 0.0f, y, 0.0f, 0.0f, mRotateByDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectBy(m_ID, 0.0f, 0.0f, z, 0.0f, mRotateByDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByW(Float32 w) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectBy(m_ID, 0.0f, 0.0f, 0.0f, w, mRotateByDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToEulerX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Vector3.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectRotationEuler(m_ID, nullptr, &s_Vector3.y, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectToEuler(m_ID, x, s_Vector3.y, s_Vector3.z, mRotateToEulerDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToEulerY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Vector3.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectRotationEuler(m_ID, &s_Vector3.x, nullptr, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectToEuler(m_ID, s_Vector3.x, y, s_Vector3.z, mRotateToEulerDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateToEulerZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous information, if any
|
||||
s_Vector3.Clear();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->GetObjectRotationEuler(m_ID, &s_Vector3.x, &s_Vector3.y, nullptr);
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectToEuler(m_ID, s_Vector3.z, s_Vector3.y, z, mRotateToEulerDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByEulerX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectByEuler(m_ID, x, 0.0f, 0.0f, mRotateByEulerDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByEulerY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectByEuler(m_ID, 0.0f, y, 0.0f, mRotateByEulerDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CObject::RotateByEulerZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotateObjectByEuler(m_ID, 0.0f, 0.0f, z, mRotateByEulerDuration);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
|
||||
Int32 alpha)
|
||||
{
|
||||
return _Core->NewObject(model, world, x, y, z, alpha, SQMOD_CREATE_DEFAULT, NullObject());
|
||||
return Core::Get().NewObject(model, world, x, y, z, alpha, SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
|
||||
Int32 alpha, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewObject(model, world, x, y, z, alpha, header, payload);
|
||||
return Core::Get().NewObject(model, world, x, y, z, alpha, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha)
|
||||
{
|
||||
return _Core->NewObject(model, world, pos.x, pos.y, pos.z, alpha,
|
||||
return Core::Get().NewObject(model, world, pos.x, pos.y, pos.z, alpha,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewObject(model, world, pos.x, pos.y, pos.z, alpha, header, payload);
|
||||
return Core::Get().NewObject(model, world, pos.x, pos.y, pos.z, alpha, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -580,8 +812,8 @@ static const Object & Object_FindByID(Int32 id)
|
||||
STHROWF("The specified object identifier is invalid: %d", id);
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Objects::const_iterator itr = _Core->GetObjects().cbegin();
|
||||
Core::Objects::const_iterator end = _Core->GetObjects().cend();
|
||||
Core::Objects::const_iterator itr = Core::Get().GetObjects().cbegin();
|
||||
Core::Objects::const_iterator end = Core::Get().GetObjects().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -602,8 +834,8 @@ static const Object & Object_FindByTag(CSStr tag)
|
||||
if (!tag || *tag == '\0')
|
||||
STHROWF("The specified object tag is invalid: null/empty");
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Objects::const_iterator itr = _Core->GetObjects().cbegin();
|
||||
Core::Objects::const_iterator end = _Core->GetObjects().cend();
|
||||
Core::Objects::const_iterator itr = Core::Get().GetObjects().cbegin();
|
||||
Core::Objects::const_iterator end = Core::Get().GetObjects().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -623,8 +855,8 @@ static Array Object_FindActive()
|
||||
// Remember the initial stack size
|
||||
StackGuard sg;
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Objects::const_iterator itr = _Core->GetObjects().cbegin();
|
||||
Core::Objects::const_iterator end = _Core->GetObjects().cend();
|
||||
Core::Objects::const_iterator itr = Core::Get().GetObjects().cbegin();
|
||||
Core::Objects::const_iterator end = Core::Get().GetObjects().cend();
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
@@ -657,6 +889,13 @@ void Register_CObject(HSQUIRRELVM vm)
|
||||
.Func(_SC("_tostring"), &CObject::ToString)
|
||||
// Static Values
|
||||
.SetStaticValue(_SC("MaxID"), CObject::Max)
|
||||
// Member Variables
|
||||
.Var(_SC("MoveToDuration"), &CObject::mMoveToDuration)
|
||||
.Var(_SC("MoveByDuration"), &CObject::mMoveByDuration)
|
||||
.Var(_SC("RotateToDuration"), &CObject::mRotateToDuration)
|
||||
.Var(_SC("RotateByDuration"), &CObject::mRotateByDuration)
|
||||
.Var(_SC("RotateToEulerDuration"), &CObject::mRotateToEulerDuration)
|
||||
.Var(_SC("RotateByEulerDuration"), &CObject::mRotateByEulerDuration)
|
||||
// Core Properties
|
||||
.Prop(_SC("ID"), &CObject::GetID)
|
||||
.Prop(_SC("Tag"), &CObject::GetTag, &CObject::SetTag)
|
||||
@@ -674,49 +913,71 @@ void Register_CObject(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Alpha"), &CObject::GetAlpha, &CObject::SetAlpha)
|
||||
.Prop(_SC("Pos"), &CObject::GetPosition, &CObject::SetPosition)
|
||||
.Prop(_SC("Position"), &CObject::GetPosition, &CObject::SetPosition)
|
||||
.Prop(_SC("ERot"), &CObject::GetRotation)
|
||||
.Prop(_SC("Rot"), &CObject::GetRotation)
|
||||
.Prop(_SC("Rotation"), &CObject::GetRotation)
|
||||
.Prop(_SC("RotationEuler"), &CObject::GetRotationEuler)
|
||||
.Prop(_SC("EulerRot"), &CObject::GetRotationEuler)
|
||||
.Prop(_SC("EulerRotation"), &CObject::GetRotationEuler)
|
||||
.Prop(_SC("ShotReport"), &CObject::GetShotReport, &CObject::SetShotReport)
|
||||
.Prop(_SC("BumpReport"), &CObject::GetBumpReport, &CObject::SetBumpReport)
|
||||
.Prop(_SC("X"), &CObject::GetPosX, &CObject::SetPosX)
|
||||
.Prop(_SC("Y"), &CObject::GetPosY, &CObject::SetPosY)
|
||||
.Prop(_SC("Z"), &CObject::GetPosZ, &CObject::SetPosZ)
|
||||
.Prop(_SC("RX"), &CObject::GetRotX)
|
||||
.Prop(_SC("RY"), &CObject::GetRotY)
|
||||
.Prop(_SC("RZ"), &CObject::GetRotZ)
|
||||
.Prop(_SC("RW"), &CObject::GetRotW)
|
||||
.Prop(_SC("EX"), &CObject::GetERotX)
|
||||
.Prop(_SC("EY"), &CObject::GetERotY)
|
||||
.Prop(_SC("EZ"), &CObject::GetERotZ)
|
||||
.Prop(_SC("BumpReport"), &CObject::GetTouchedReport, &CObject::SetTouchedReport)
|
||||
.Prop(_SC("TouchedReport"), &CObject::GetTouchedReport, &CObject::SetTouchedReport)
|
||||
.Prop(_SC("PosX"), &CObject::GetPositionX, &CObject::SetPositionX)
|
||||
.Prop(_SC("PosY"), &CObject::GetPositionY, &CObject::SetPositionY)
|
||||
.Prop(_SC("PosZ"), &CObject::GetPositionZ, &CObject::SetPositionZ)
|
||||
.Prop(_SC("RotX"), &CObject::GetRotationX)
|
||||
.Prop(_SC("RotY"), &CObject::GetRotationY)
|
||||
.Prop(_SC("RotZ"), &CObject::GetRotationZ)
|
||||
.Prop(_SC("RotW"), &CObject::GetRotationW)
|
||||
.Prop(_SC("EulerRotX"), &CObject::GetEulerRotationX)
|
||||
.Prop(_SC("EulerRotY"), &CObject::GetEulerRotationY)
|
||||
.Prop(_SC("EulerRotZ"), &CObject::GetEulerRotationZ)
|
||||
.Prop(_SC("MoveToX"), &CObject::GetPositionX, &CObject::MoveToX)
|
||||
.Prop(_SC("MoveToY"), &CObject::GetPositionY, &CObject::MoveToY)
|
||||
.Prop(_SC("MoveToZ"), &CObject::GetPositionZ, &CObject::MoveToZ)
|
||||
.Prop(_SC("MoveByX"), &CObject::GetPositionX, &CObject::MoveByX)
|
||||
.Prop(_SC("MoveByY"), &CObject::GetPositionY, &CObject::MoveByY)
|
||||
.Prop(_SC("MoveByZ"), &CObject::GetPositionZ, &CObject::MoveByZ)
|
||||
.Prop(_SC("RotateToX"), &CObject::GetRotationX, &CObject::RotateToX)
|
||||
.Prop(_SC("RotateToY"), &CObject::GetRotationY, &CObject::RotateToY)
|
||||
.Prop(_SC("RotateToZ"), &CObject::GetRotationZ, &CObject::RotateToZ)
|
||||
.Prop(_SC("RotateToW"), &CObject::GetRotationW, &CObject::RotateToW)
|
||||
.Prop(_SC("RotateByX"), &CObject::GetRotationX, &CObject::RotateByX)
|
||||
.Prop(_SC("RotateByY"), &CObject::GetRotationY, &CObject::RotateByY)
|
||||
.Prop(_SC("RotateByZ"), &CObject::GetRotationZ, &CObject::RotateByZ)
|
||||
.Prop(_SC("RotateByW"), &CObject::GetRotationW, &CObject::RotateByW)
|
||||
.Prop(_SC("RotateToEulerX"), &CObject::GetEulerRotationX, &CObject::RotateToEulerX)
|
||||
.Prop(_SC("RotateToEulerY"), &CObject::GetEulerRotationY, &CObject::RotateToEulerY)
|
||||
.Prop(_SC("RotateToEulerZ"), &CObject::GetEulerRotationZ, &CObject::RotateToEulerZ)
|
||||
.Prop(_SC("RotateByEulerX"), &CObject::GetEulerRotationX, &CObject::RotateByEulerX)
|
||||
.Prop(_SC("RotateByEulerY"), &CObject::GetEulerRotationY, &CObject::RotateByEulerY)
|
||||
.Prop(_SC("RotateByEulerZ"), &CObject::GetEulerRotationZ, &CObject::RotateByEulerZ)
|
||||
// Member Methods
|
||||
.Func(_SC("StreamedFor"), &CObject::IsStreamedFor)
|
||||
.Func(_SC("SetAlpha"), &CObject::SetAlphaEx)
|
||||
.Func(_SC("SetPosition"), &CObject::SetPositionEx)
|
||||
// Member Overloads
|
||||
.Overload< void (CObject::*)(const Vector3 &, Int32) const >
|
||||
.Overload< void (CObject::*)(const Vector3 &, Uint32) const >
|
||||
(_SC("MoveTo"), &CObject::MoveTo)
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Int32) const >
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
|
||||
(_SC("MoveTo"), &CObject::MoveToEx)
|
||||
.Overload< void (CObject::*)(const Vector3 &, Int32) const >
|
||||
.Overload< void (CObject::*)(const Vector3 &, Uint32) const >
|
||||
(_SC("MoveBy"), &CObject::MoveBy)
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Int32) const >
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
|
||||
(_SC("MoveBy"), &CObject::MoveByEx)
|
||||
.Overload< void (CObject::*)(const Quaternion &, Int32) const >
|
||||
.Overload< void (CObject::*)(const Quaternion &, Uint32) const >
|
||||
(_SC("RotateTo"), &CObject::RotateTo)
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Float32, Int32) const >
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Float32, Uint32) const >
|
||||
(_SC("RotateTo"), &CObject::RotateToEx)
|
||||
.Overload< void (CObject::*)(const Vector3 &, Int32) const >
|
||||
.Overload< void (CObject::*)(const Vector3 &, Uint32) const >
|
||||
(_SC("RotateToEuler"), &CObject::RotateToEuler)
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Int32) const >
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
|
||||
(_SC("RotateToEuler"), &CObject::RotateToEulerEx)
|
||||
.Overload< void (CObject::*)(const Quaternion &, Int32) const >
|
||||
.Overload< void (CObject::*)(const Quaternion &, Uint32) const >
|
||||
(_SC("RotateBy"), &CObject::RotateBy)
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Float32, Int32) const >
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Float32, Uint32) const >
|
||||
(_SC("RotateBy"), &CObject::RotateByEx)
|
||||
.Overload< void (CObject::*)(const Vector3 &, Int32) const >
|
||||
.Overload< void (CObject::*)(const Vector3 &, Uint32) const >
|
||||
(_SC("RotateByEuler"), &CObject::RotateByEuler)
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Int32) const >
|
||||
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
|
||||
(_SC("RotateByEuler"), &CObject::RotateByEulerEx)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("FindByID"), &Object_FindByID)
|
||||
|
||||
@@ -43,6 +43,24 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The default duration to use when moving the object.
|
||||
*/
|
||||
Uint32 mMoveToDuration;
|
||||
Uint32 mMoveByDuration;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The default duration to use when rotating the object to Quaternion.
|
||||
*/
|
||||
Uint32 mRotateToDuration;
|
||||
Uint32 mRotateByDuration;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The default duration to use when rotating the object to Euler.
|
||||
*/
|
||||
Uint32 mRotateToEulerDuration;
|
||||
Uint32 mRotateByEulerDuration;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Maximum possible number that could represent an identifier for this entity type.
|
||||
*/
|
||||
@@ -194,27 +212,27 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the alpha of the managed object entity over the specified time.
|
||||
*/
|
||||
void SetAlphaEx(Int32 alpha, Int32 time) const;
|
||||
void SetAlphaEx(Int32 alpha, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move the managed object entity to the specified position over the specified time.
|
||||
*/
|
||||
void MoveTo(const Vector3 & pos, Int32 time) const;
|
||||
void MoveTo(const Vector3 & pos, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move the managed object entity to the specified position over the specified time.
|
||||
*/
|
||||
void MoveToEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
|
||||
void MoveToEx(Float32 x, Float32 y, Float32 z, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move the managed object entity by the specified position over the specified time.
|
||||
*/
|
||||
void MoveBy(const Vector3 & pos, Int32 time) const;
|
||||
void MoveBy(const Vector3 & pos, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move the managed object entity by the specified position over the specified time.
|
||||
*/
|
||||
void MoveByEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
|
||||
void MoveByEx(Float32 x, Float32 y, Float32 z, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position of the managed object entity.
|
||||
@@ -234,42 +252,42 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Rotate the managed object entity to the specified rotation over the specified time.
|
||||
*/
|
||||
void RotateTo(const Quaternion & rot, Int32 time) const;
|
||||
void RotateTo(const Quaternion & rot, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Rotate the managed object entity to the specified rotation over the specified time.
|
||||
*/
|
||||
void RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const;
|
||||
void RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Rotate the managed object entity to the specified euler rotation over the specified time.
|
||||
* Rotate the managed object entity to the specified Euler rotation over the specified time.
|
||||
*/
|
||||
void RotateToEuler(const Vector3 & rot, Int32 time) const;
|
||||
void RotateToEuler(const Vector3 & rot, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Rotate the managed object entity to the specified euler rotation over the specified time.
|
||||
* Rotate the managed object entity to the specified Euler rotation over the specified time.
|
||||
*/
|
||||
void RotateToEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
|
||||
void RotateToEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Rotate the managed object entity by the specified rotation over the specified time.
|
||||
*/
|
||||
void RotateBy(const Quaternion & rot, Int32 time) const;
|
||||
void RotateBy(const Quaternion & rot, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Rotate the managed object entity by the specified rotation over the specified time.
|
||||
*/
|
||||
void RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const;
|
||||
void RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Rotate the managed object entity by the specified euler rotation over the specified time.
|
||||
* Rotate the managed object entity by the specified Euler rotation over the specified time.
|
||||
*/
|
||||
void RotateByEuler(const Vector3 & rot, Int32 time) const;
|
||||
void RotateByEuler(const Vector3 & rot, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Rotate the managed object entity by the specified euler rotation over the specified time.
|
||||
* Rotate the managed object entity by the specified Euler rotation over the specified time.
|
||||
*/
|
||||
void RotateByEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
|
||||
void RotateByEulerEx(Float32 x, Float32 y, Float32 z, Uint32 time) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the rotation of the managed object entity.
|
||||
@@ -277,7 +295,7 @@ public:
|
||||
const Quaternion & GetRotation();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the euler rotation of the managed object entity.
|
||||
* Retrieve the Euler rotation of the managed object entity.
|
||||
*/
|
||||
const Vector3 & GetRotationEuler();
|
||||
|
||||
@@ -294,77 +312,177 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed object entity reports player bumps.
|
||||
*/
|
||||
bool GetBumpReport() const;
|
||||
bool GetTouchedReport() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed object entity reports player bumps.
|
||||
*/
|
||||
void SetBumpReport(bool toggle) const;
|
||||
void SetTouchedReport(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the x axis of the managed object entity.
|
||||
*/
|
||||
Float32 GetPosX() const;
|
||||
Float32 GetPositionX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the y axis of the managed object entity.
|
||||
*/
|
||||
Float32 GetPosY() const;
|
||||
Float32 GetPositionY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the z axis of the managed object entity.
|
||||
*/
|
||||
Float32 GetPosZ() const;
|
||||
Float32 GetPositionZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the x axis of the managed object entity.
|
||||
*/
|
||||
void SetPosX(Float32 x) const;
|
||||
void SetPositionX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the y axis of the managed object entity.
|
||||
*/
|
||||
void SetPosY(Float32 y) const;
|
||||
void SetPositionY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the z axis of the managed object entity.
|
||||
*/
|
||||
void SetPosZ(Float32 z) const;
|
||||
void SetPositionZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the rotation on the x axis of the managed object entity.
|
||||
*/
|
||||
Float32 GetRotX() const;
|
||||
Float32 GetRotationX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the rotation on the y axis of the managed object entity.
|
||||
*/
|
||||
Float32 GetRotY() const;
|
||||
Float32 GetRotationY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the rotation on the z axis of the managed object entity.
|
||||
*/
|
||||
Float32 GetRotZ() const;
|
||||
Float32 GetRotationZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the rotation amount of the managed object entity.
|
||||
*/
|
||||
Float32 GetRotW() const;
|
||||
Float32 GetRotationW() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the euler rotation on the x axis of the managed object entity.
|
||||
* Retrieve the Euler rotation on the x axis of the managed object entity.
|
||||
*/
|
||||
Float32 GetERotX() const;
|
||||
Float32 GetEulerRotationX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the euler rotation on the y axis of the managed object entity.
|
||||
* Retrieve the Euler rotation on the y axis of the managed object entity.
|
||||
*/
|
||||
Float32 GetERotY() const;
|
||||
Float32 GetEulerRotationY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the euler rotation on the z axis of the managed object entity.
|
||||
* Retrieve the Euler rotation on the z axis of the managed object entity.
|
||||
*/
|
||||
Float32 GetERotZ() const;
|
||||
Float32 GetEulerRotationZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the x axis of the managed object entity.
|
||||
*/
|
||||
void MoveToX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the y axis of the managed object entity.
|
||||
*/
|
||||
void MoveToY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the z axis of the managed object entity.
|
||||
*/
|
||||
void MoveToZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the x axis of the managed object entity.
|
||||
*/
|
||||
void MoveByX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the y axis of the managed object entity.
|
||||
*/
|
||||
void MoveByY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the z axis of the managed object entity.
|
||||
*/
|
||||
void MoveByZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the x axis of the managed object entity.
|
||||
*/
|
||||
void RotateToX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the y axis of the managed object entity.
|
||||
*/
|
||||
void RotateToY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the z axis of the managed object entity.
|
||||
*/
|
||||
void RotateToZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the w axis of the managed object entity.
|
||||
*/
|
||||
void RotateToW(Float32 w) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the x axis of the managed object entity.
|
||||
*/
|
||||
void RotateByX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the y axis of the managed object entity.
|
||||
*/
|
||||
void RotateByY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the z axis of the managed object entity.
|
||||
*/
|
||||
void RotateByZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the w axis of the managed object entity.
|
||||
*/
|
||||
void RotateByW(Float32 w) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the x axis of the managed object entity.
|
||||
*/
|
||||
void RotateToEulerX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the y axis of the managed object entity.
|
||||
*/
|
||||
void RotateToEulerY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the z axis of the managed object entity.
|
||||
*/
|
||||
void RotateToEulerZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the x axis of the managed object entity.
|
||||
*/
|
||||
void RotateByEulerX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the y axis of the managed object entity.
|
||||
*/
|
||||
void RotateByEulerY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the z axis of the managed object entity.
|
||||
*/
|
||||
void RotateByEulerZ(Float32 z) const;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -17,7 +17,7 @@ const Int32 CPickup::Max = SQMOD_PICKUP_POOL;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CPickup::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqPickup");
|
||||
static const SQChar name[] = _SC("SqPickup");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
@@ -40,11 +40,17 @@ CPickup::~CPickup()
|
||||
Int32 CPickup::Cmp(const CPickup & o) const
|
||||
{
|
||||
if (m_ID == o.m_ID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_ID > o.m_ID)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -89,7 +95,7 @@ bool CPickup::Destroy(Int32 header, Object & payload)
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return _Core->DelPickup(m_ID, header, payload);
|
||||
return Core::Get().DelPickup(m_ID, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -98,7 +104,7 @@ void CPickup::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = _Core->GetPickupEvent(m_ID, evid);
|
||||
Function & event = Core::Get().GetPickupEvent(m_ID, evid);
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
@@ -125,15 +131,6 @@ bool CPickup::IsStreamedFor(CPlayer & player) const
|
||||
return _Func->IsPickupStreamedForPlayer(m_ID, player.GetID());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CPickup::GetModel() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->PickupGetModel(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CPickup::GetWorld() const
|
||||
{
|
||||
@@ -158,7 +155,7 @@ Int32 CPickup::GetAlpha() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->GetVehicleModel(m_ID);
|
||||
return _Func->GetPickupAlpha(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -167,7 +164,7 @@ void CPickup::SetAlpha(Int32 alpha) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->PickupSetAlpha(m_ID, alpha);
|
||||
_Func->SetPickupAlpha(m_ID, alpha);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -176,7 +173,7 @@ bool CPickup::GetAutomatic() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->PickupIsAutomatic(m_ID);
|
||||
return _Func->IsPickupAutomatic(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -185,7 +182,7 @@ void CPickup::SetAutomatic(bool toggle) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->PickupSetAutomatic(m_ID, toggle);
|
||||
_Func->SetPickupIsAutomatic(m_ID, toggle);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -212,7 +209,7 @@ void CPickup::Refresh() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->PickupRefresh(m_ID);
|
||||
_Func->RefreshPickup(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -223,7 +220,7 @@ const Vector3 & CPickup::GetPosition()
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.Clear();
|
||||
// Query the server for the position values
|
||||
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
||||
_Func->GetPickupPosition(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3;
|
||||
}
|
||||
@@ -234,7 +231,7 @@ void CPickup::SetPosition(const Vector3 & pos) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->PickupSetPos(m_ID, pos.x, pos.y, pos.z);
|
||||
_Func->SetPickupPosition(m_ID, pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -243,7 +240,16 @@ void CPickup::SetPositionEx(Float32 x, Float32 y, Float32 z) const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->PickupSetPos(m_ID, x, y, z);
|
||||
_Func->SetPickupPosition(m_ID, x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CPickup::GetModel() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->GetPickupModel(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -252,86 +258,86 @@ Int32 CPickup::GetQuantity() const
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Func->PickupGetQuantity(m_ID);
|
||||
return _Func->GetPickupQuantity(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CPickup::GetPosX() const
|
||||
Float32 CPickup::GetPositionX() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.x = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, NULL);
|
||||
_Func->GetPickupPosition(m_ID, &s_Vector3.x, NULL, NULL);
|
||||
// Return the requested information
|
||||
return s_Vector3.x;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CPickup::GetPosY() const
|
||||
Float32 CPickup::GetPositionY() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.y = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, NULL);
|
||||
_Func->GetPickupPosition(m_ID, NULL, &s_Vector3.y, NULL);
|
||||
// Return the requested information
|
||||
return s_Vector3.y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CPickup::GetPosZ() const
|
||||
Float32 CPickup::GetPositionZ() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Clear previous position information, if any
|
||||
s_Vector3.z = 0;
|
||||
// Query the server for the requested component value
|
||||
_Func->PickupGetPos(m_ID, NULL, NULL, &s_Vector3.z);
|
||||
_Func->GetPickupPosition(m_ID, NULL, NULL, &s_Vector3.z);
|
||||
// Return the requested information
|
||||
return s_Vector3.z;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPickup::SetPosX(Float32 x) const
|
||||
void CPickup::SetPositionX(Float32 x) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
|
||||
_Func->GetPickupPosition(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->PickupSetPos(m_ID, x, s_Vector3.y, s_Vector3.z);
|
||||
_Func->SetPickupPosition(m_ID, x, s_Vector3.y, s_Vector3.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPickup::SetPosY(Float32 y) const
|
||||
void CPickup::SetPositionY(Float32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
|
||||
_Func->GetPickupPosition(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
|
||||
// Perform the requested operation
|
||||
_Func->PickupSetPos(m_ID, s_Vector3.x, y, s_Vector3.z);
|
||||
_Func->SetPickupPosition(m_ID, s_Vector3.x, y, s_Vector3.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPickup::SetPosZ(Float32 z) const
|
||||
void CPickup::SetPositionZ(Float32 z) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Retrieve the current values for unchanged components
|
||||
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
|
||||
_Func->GetPickupPosition(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
|
||||
// Perform the requested operation
|
||||
_Func->PickupSetPos(m_ID, s_Vector3.z, s_Vector3.y, z);
|
||||
_Func->SetPickupPosition(m_ID, s_Vector3.z, s_Vector3.y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
|
||||
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic)
|
||||
{
|
||||
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic,
|
||||
return Core::Get().NewPickup(model, world, quantity, x, y, z, alpha, automatic,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
@@ -339,21 +345,21 @@ static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
|
||||
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic, header, payload);
|
||||
return Core::Get().NewPickup(model, world, quantity, x, y, z, alpha, automatic, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
|
||||
Int32 alpha, bool automatic)
|
||||
{
|
||||
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
|
||||
return Core::Get().NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
|
||||
Int32 alpha, bool automatic, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
|
||||
return Core::Get().NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
|
||||
header, payload);
|
||||
}
|
||||
|
||||
@@ -366,8 +372,8 @@ static const Object & Pickup_FindByID(Int32 id)
|
||||
STHROWF("The specified pickup identifier is invalid: %d", id);
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Pickups::const_iterator itr = _Core->GetPickups().cbegin();
|
||||
Core::Pickups::const_iterator end = _Core->GetPickups().cend();
|
||||
Core::Pickups::const_iterator itr = Core::Get().GetPickups().cbegin();
|
||||
Core::Pickups::const_iterator end = Core::Get().GetPickups().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -390,8 +396,8 @@ static const Object & Pickup_FindByTag(CSStr tag)
|
||||
STHROWF("The specified pickup tag is invalid: null/empty");
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Pickups::const_iterator itr = _Core->GetPickups().cbegin();
|
||||
Core::Pickups::const_iterator end = _Core->GetPickups().cend();
|
||||
Core::Pickups::const_iterator itr = Core::Get().GetPickups().cbegin();
|
||||
Core::Pickups::const_iterator end = Core::Get().GetPickups().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
@@ -411,8 +417,8 @@ static Array Pickup_FindActive()
|
||||
// Remember the initial stack size
|
||||
StackGuard sg;
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Pickups::const_iterator itr = _Core->GetPickups().cbegin();
|
||||
Core::Pickups::const_iterator end = _Core->GetPickups().cend();
|
||||
Core::Pickups::const_iterator itr = Core::Get().GetPickups().cbegin();
|
||||
Core::Pickups::const_iterator end = Core::Get().GetPickups().cend();
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
@@ -467,9 +473,9 @@ void Register_CPickup(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Pos"), &CPickup::GetPosition, &CPickup::SetPosition)
|
||||
.Prop(_SC("Position"), &CPickup::GetPosition, &CPickup::SetPosition)
|
||||
.Prop(_SC("Quantity"), &CPickup::GetQuantity)
|
||||
.Prop(_SC("X"), &CPickup::GetPosX, &CPickup::SetPosX)
|
||||
.Prop(_SC("Y"), &CPickup::GetPosY, &CPickup::SetPosY)
|
||||
.Prop(_SC("Z"), &CPickup::GetPosZ, &CPickup::SetPosZ)
|
||||
.Prop(_SC("PosX"), &CPickup::GetPositionX, &CPickup::SetPositionX)
|
||||
.Prop(_SC("PosY"), &CPickup::GetPositionY, &CPickup::SetPositionY)
|
||||
.Prop(_SC("PosZ"), &CPickup::GetPositionZ, &CPickup::SetPositionZ)
|
||||
// Member Methods
|
||||
.Func(_SC("StreamedFor"), &CPickup::IsStreamedFor)
|
||||
.Func(_SC("Refresh"), &CPickup::Refresh)
|
||||
|
||||
@@ -165,11 +165,6 @@ public:
|
||||
*/
|
||||
bool IsStreamedFor(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the model of the managed pickup entity.
|
||||
*/
|
||||
Int32 GetModel() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the world in which the managed pickup entity exists.
|
||||
*/
|
||||
@@ -230,6 +225,11 @@ public:
|
||||
*/
|
||||
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the model of the managed pickup entity.
|
||||
*/
|
||||
Int32 GetModel() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the quantity of the managed pickup entity.
|
||||
*/
|
||||
@@ -238,32 +238,32 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the x axis of the managed pickup entity.
|
||||
*/
|
||||
Float32 GetPosX() const;
|
||||
Float32 GetPositionX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the y axis of the managed pickup entity.
|
||||
*/
|
||||
Float32 GetPosY() const;
|
||||
Float32 GetPositionY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the z axis of the managed pickup entity.
|
||||
*/
|
||||
Float32 GetPosZ() const;
|
||||
Float32 GetPositionZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the x axis of the managed pickup entity.
|
||||
*/
|
||||
void SetPosX(Float32 x) const;
|
||||
void SetPositionX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the y axis of the managed pickup entity.
|
||||
*/
|
||||
void SetPosY(Float32 y) const;
|
||||
void SetPositionY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the z axis of the managed pickup entity.
|
||||
*/
|
||||
void SetPosZ(Float32 z) const;
|
||||
void SetPositionZ(Float32 z) const;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,10 +3,19 @@
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Circular locks employed by the player manager.
|
||||
*/
|
||||
enum PlayerCircularLocks
|
||||
{
|
||||
PCL_EMIT_PLAYER_OPTION = (1 << 0)
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Manages a single player entity.
|
||||
*/
|
||||
@@ -39,6 +48,16 @@ private:
|
||||
*/
|
||||
Object m_Data;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Buffer used to generate client data.
|
||||
*/
|
||||
Buffer m_Buffer;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Prevent events from triggering themselves.
|
||||
*/
|
||||
Uint32 m_CircularLocks;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
@@ -46,11 +65,64 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef String MsgPrefix[SQMOD_PLAYER_MSG_PREFIXES];
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Maximum possible number that could represent an identifier for this entity type.
|
||||
*/
|
||||
static const Int32 Max;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The initial size of the allocated memory buffer when starting a new stream.
|
||||
*/
|
||||
Uint32 mBufferInitSize;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default color to use in client messages.
|
||||
*/
|
||||
Uint32 mMessageColor;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default style to use in client announcements.
|
||||
*/
|
||||
Int32 mAnnounceStyle;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default ammo to give to the managed player when not specifying any.
|
||||
*/
|
||||
Int32 mDefaultAmmo;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set of strings to add before a client message automatically.
|
||||
*/
|
||||
String mMessagePrefix;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set of strings to add before a client message automatically.
|
||||
*/
|
||||
String mMessagePostfix;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set of strings to add before a client announcement automatically.
|
||||
*/
|
||||
String mAnnouncePrefix;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set of strings to add before a client announcement automatically.
|
||||
*/
|
||||
String mAnnouncePostfix;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set of strings to add before a client message automatically.
|
||||
*/
|
||||
MsgPrefix mMessagePrefixes;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Don't include the auto message prefix/postfix in already prefixed messages.
|
||||
*/
|
||||
bool mLimitPrefixPostfixMessage;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
@@ -143,16 +215,16 @@ public:
|
||||
*/
|
||||
void BindEvent(Int32 evid, Object & env, Function & func) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is connected.
|
||||
*/
|
||||
bool IsConnected() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if the managed player entity is streamed for the specified player.
|
||||
*/
|
||||
bool IsStreamedFor(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the class of the managed player entity.
|
||||
*/
|
||||
Int32 GetClass() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity has administrator privileges.
|
||||
*/
|
||||
@@ -168,6 +240,16 @@ public:
|
||||
*/
|
||||
CSStr GetIP() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the unique user identifier of the managed player entity.
|
||||
*/
|
||||
CSStr GetUID() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the unique user identifier version 2 of the managed player entity.
|
||||
*/
|
||||
CSStr GetUID2() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Kick the managed player entity from the server.
|
||||
*/
|
||||
@@ -178,21 +260,41 @@ public:
|
||||
*/
|
||||
void Ban() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is connected.
|
||||
*/
|
||||
bool IsConnected() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is spawned.
|
||||
*/
|
||||
bool IsSpawned() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the key of the managed player entity.
|
||||
*/
|
||||
Uint32 GetKey() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the nick name of the managed player entity.
|
||||
*/
|
||||
CSStr GetName() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the nick name of the managed player entity.
|
||||
*/
|
||||
void SetName(CSStr name) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current state of the managed player entity.
|
||||
*/
|
||||
Int32 GetState() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current option value of the managed player entity.
|
||||
*/
|
||||
Int32 GetOption(Int32 option_id) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the current option value of the managed player entity.
|
||||
*/
|
||||
void SetOption(Int32 option_id, bool toggle);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the current option value of the managed player entity.
|
||||
*/
|
||||
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the world in which the managed player entity exists.
|
||||
*/
|
||||
@@ -206,12 +308,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the secondary world of the managed player entity.
|
||||
*/
|
||||
Int32 GetSecWorld() const;
|
||||
Int32 GetSecondaryWorld() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the secondary world of the managed player entity.
|
||||
*/
|
||||
void SetSecWorld(Int32 world) const;
|
||||
void SetSecondaryWorld(Int32 world) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the unique world of the managed player entity.
|
||||
@@ -224,14 +326,9 @@ public:
|
||||
bool IsWorldCompatible(Int32 world) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the nick name of the managed player entity.
|
||||
* Retrieve the class of the managed player entity.
|
||||
*/
|
||||
CSStr GetName() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the nick name of the managed player entity.
|
||||
*/
|
||||
void SetName(CSStr name) const;
|
||||
Int32 GetClass() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the team of the managed player entity.
|
||||
@@ -268,6 +365,11 @@ public:
|
||||
*/
|
||||
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is spawned.
|
||||
*/
|
||||
bool IsSpawned() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Force the managed player entity to spawn in the game.
|
||||
*/
|
||||
@@ -278,6 +380,11 @@ public:
|
||||
*/
|
||||
void ForceSelect() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is typing.
|
||||
*/
|
||||
bool IsTyping() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the money amount of the managed player entity.
|
||||
*/
|
||||
@@ -303,6 +410,16 @@ public:
|
||||
*/
|
||||
void SetScore(Int32 score) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the wanted level of the managed player entity.
|
||||
*/
|
||||
Int32 GetWantedLevel() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the wanted level of the managed player entity.
|
||||
*/
|
||||
void SetWantedLevel(Int32 level) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the connection latency of the managed player entity.
|
||||
*/
|
||||
@@ -313,21 +430,6 @@ public:
|
||||
*/
|
||||
Float32 GetFPS() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is typing.
|
||||
*/
|
||||
bool IsTyping() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the unique user identifier of the managed player entity.
|
||||
*/
|
||||
CSStr GetUID() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the unique user identifier version 2 of the managed player entity.
|
||||
*/
|
||||
CSStr GetUID2() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current health of the managed player entity.
|
||||
*/
|
||||
@@ -418,6 +520,51 @@ public:
|
||||
*/
|
||||
void SetAlpha(Int32 alpha, Int32 fade) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the aim position of the managed player entity.
|
||||
*/
|
||||
const Vector3 & GetAimPosition() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the aim direction of the managed player entity.
|
||||
*/
|
||||
const Vector3 & GetAimDirection() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is burning.
|
||||
*/
|
||||
bool IsBurning() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is crouched.
|
||||
*/
|
||||
bool IsCrouched() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current action of the managed player entity.
|
||||
*/
|
||||
Int32 GetAction() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the game keys of the managed player entity.
|
||||
*/
|
||||
Int32 GetGameKeys() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Embark the managed player entity into the specified vehicle entity.
|
||||
*/
|
||||
bool Embark(CVehicle & vehicle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Embark the managed player entity into the specified vehicle entity.
|
||||
*/
|
||||
bool Embark(CVehicle & vehicle, Int32 slot, bool allocate, bool warp) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Disembark the managed player entity from the currently embarked vehicle entity.
|
||||
*/
|
||||
void Disembark() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the vehicle status of the managed player entity.
|
||||
*/
|
||||
@@ -426,7 +573,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the occupied vehicle slot by the managed player entity.
|
||||
*/
|
||||
Int32 GetOccupiedSlot() const;
|
||||
Int32 GetVehicleSlot() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the vehicle in which the managed player entity is embarked.
|
||||
@@ -438,106 +585,6 @@ public:
|
||||
*/
|
||||
Int32 GetVehicleID() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity can be controlled.
|
||||
*/
|
||||
bool GetControllable() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity can be controlled.
|
||||
*/
|
||||
void SetControllable(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity can driveby.
|
||||
*/
|
||||
bool GetDriveby() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity can driveby.
|
||||
*/
|
||||
void SetDriveby(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity has white scanlines.
|
||||
*/
|
||||
bool GetWhiteScanlines() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity has white scanlines.
|
||||
*/
|
||||
void SetWhiteScanlines(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity has green scanlines.
|
||||
*/
|
||||
bool GetGreenScanlines() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity has green scanlines.
|
||||
*/
|
||||
void SetGreenScanlines(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity has widescreen.
|
||||
*/
|
||||
bool GetWidescreen() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity has widescreen.
|
||||
*/
|
||||
void SetWidescreen(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity displays markers.
|
||||
*/
|
||||
bool GetShowMarkers() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity displays markers.
|
||||
*/
|
||||
void SetShowMarkers(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity has attacking privileges.
|
||||
*/
|
||||
bool GetAttackPriv() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity has attacking privileges.
|
||||
*/
|
||||
void SetAttackPriv(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity has markers.
|
||||
*/
|
||||
bool GetHasMarker() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity has markers.
|
||||
*/
|
||||
void SetHasMarker(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity has chat tags.
|
||||
*/
|
||||
bool GetChatTags() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity has chat tags.
|
||||
*/
|
||||
void SetChatTags(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is under drunk effects.
|
||||
*/
|
||||
bool GetDrunkEffects() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed player entity is under drunk effects.
|
||||
*/
|
||||
void SetDrunkEffects(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the weapon identifier of the managed player entity.
|
||||
*/
|
||||
@@ -546,13 +593,48 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the weapon of the managed player entity.
|
||||
*/
|
||||
void SetWeapon(Int32 wep, Int32 ammo) const;
|
||||
void SetWeapon(Int32 wep) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the weapon of the managed player entity.
|
||||
*/
|
||||
void SetWeaponEx(Int32 wep, Int32 ammo) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Give a weapon of the managed player entity.
|
||||
*/
|
||||
void GiveWeapon(Int32 wep, Int32 ammo) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the active weapon ammo of the managed player entity.
|
||||
*/
|
||||
Int32 GetAmmo() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the weapon slot of the managed player entity.
|
||||
*/
|
||||
Int32 GetWeaponSlot() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the weapon slot of the managed player entity.
|
||||
*/
|
||||
void SetWeaponSlot(Int32 slot) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the weapon identifier at the specified slot for the managed player entity.
|
||||
*/
|
||||
Int32 GetWeaponAtSlot(Int32 slot) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the ammo from the weapon at the specified slot for the managed player entity.
|
||||
*/
|
||||
Int32 GetAmmoAtSlot(Int32 slot) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Remove a certain weapon from the managed player entity.
|
||||
*/
|
||||
void RemoveWeapon(Int32 wep) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Strip the managed player entity of all weapons.
|
||||
*/
|
||||
@@ -583,16 +665,6 @@ public:
|
||||
*/
|
||||
void SetAnimation(Int32 group, Int32 anim) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the wanted level of the managed player entity.
|
||||
*/
|
||||
Int32 GetWantedLevel() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the wanted level of the managed player entity.
|
||||
*/
|
||||
void SetWantedLevel(Int32 level) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the vehicle that the managed player entity is standing on.
|
||||
*/
|
||||
@@ -618,60 +690,10 @@ public:
|
||||
*/
|
||||
void SetSpectator(CPlayer & target) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is burning.
|
||||
*/
|
||||
bool IsBurning() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed player entity is crouched.
|
||||
*/
|
||||
bool IsCrouched() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current state of the managed player entity.
|
||||
*/
|
||||
Int32 GetState() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current action of the managed player entity.
|
||||
*/
|
||||
Int32 GetAction() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the game keys of the managed player entity.
|
||||
*/
|
||||
Int32 GetGameKeys() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the aim position of the managed player entity.
|
||||
*/
|
||||
const Vector3 & GetAimPos() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the aim direction of the managed player entity.
|
||||
*/
|
||||
const Vector3 & GetAimDir() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Embark the managed player entity into the specified vehicle entity.
|
||||
*/
|
||||
void Embark(CVehicle & vehicle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Embark the managed player entity into the specified vehicle entity.
|
||||
*/
|
||||
void Embark(CVehicle & vehicle, Int32 slot, bool allocate, bool warp) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Disembark the managed player entity from the currently embarked vehicle entity.
|
||||
*/
|
||||
void Disembark() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Redirect the managed player entity to the specified server.
|
||||
*/
|
||||
bool Redirect(CSStr ip, Uint32 port, CSStr nick, CSStr pass, CSStr user);
|
||||
void Redirect(CSStr ip, Uint32 port, CSStr nick, CSStr server_pass, CSStr user_pass);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the authority level of the managed player entity.
|
||||
@@ -686,61 +708,162 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the message prefix at the specified index for the managed player entity.
|
||||
*/
|
||||
CSStr GetMessagePrefix(Uint32 index) const;
|
||||
const String & GetMessagePrefix(Uint32 index) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the message prefix at the specified index for the managed player entity.
|
||||
*/
|
||||
void SetMessagePrefix(Uint32 index, CSStr prefix) const;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the message color for the managed player entity.
|
||||
*/
|
||||
Uint32 GetMessageColor() const;
|
||||
void SetMessagePrefix(Uint32 index, CSStr prefix);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the message color for the managed player entity.
|
||||
* Retrieve the last known weapon for the managed player entity.
|
||||
*/
|
||||
void SetMessageColor(Uint32 color) const;
|
||||
Int32 GetLastWeapon() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the announcement style for the managed player entity.
|
||||
* Retrieve the last known health for the managed player entity.
|
||||
*/
|
||||
Int32 GetAnnounceStyle() const;
|
||||
Float32 GetLastHealth() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the announcement style for the managed player entity.
|
||||
* Retrieve the last known armour for the managed player entity.
|
||||
*/
|
||||
void SetAnnounceStyle(Int32 style) const;
|
||||
Float32 GetLastArmour() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the last known heading for the managed player entity.
|
||||
*/
|
||||
Float32 GetLastHeading() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the last known position for the managed player entity.
|
||||
*/
|
||||
const Vector3 & GetLastPosition() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Start a new stream with the default size.
|
||||
*/
|
||||
void StartStream();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Start a new stream with a custom size.
|
||||
*/
|
||||
void StartStream(Uint32 size);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current cursor position of the stream buffer.
|
||||
*/
|
||||
Int32 GetBufferCursor() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current cursor position of the stream buffer.
|
||||
*/
|
||||
void SetBufferCursor(Int32 pos);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a 8bit byte to the stream buffer.
|
||||
*/
|
||||
void StreamByte(SQInteger val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a 16bit short to the stream buffer.
|
||||
*/
|
||||
void StreamShort(SQInteger val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a 32bit integer to the stream buffer.
|
||||
*/
|
||||
void StreamInt(SQInteger val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a 32bit float to the stream buffer.
|
||||
*/
|
||||
void StreamFloat(SQFloat val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a string to the stream buffer.
|
||||
*/
|
||||
void StreamString(CSStr val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a raw string to the stream buffer.
|
||||
*/
|
||||
void StreamRawString(CSStr val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Send the data in the stream buffer to the client.
|
||||
*/
|
||||
void FlushStream(bool reset);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the total capacity of the buffer stream in bytes.
|
||||
*/
|
||||
Uint32 GetBufferCapacity() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Send the specified buffer contents to the managed player entity.
|
||||
*/
|
||||
void SendBuffer(const BufferWrapper & buffer) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the x axis of the managed player entity.
|
||||
*/
|
||||
Float32 GetPosX() const;
|
||||
Float32 GetPositionX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the y axis of the managed player entity.
|
||||
*/
|
||||
Float32 GetPosY() const;
|
||||
Float32 GetPositionY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the z axis of the managed player entity.
|
||||
*/
|
||||
Float32 GetPosZ() const;
|
||||
Float32 GetPositionZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the x axis of the managed player entity.
|
||||
*/
|
||||
void SetPosX(Float32 x) const;
|
||||
void SetPositionX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the y axis of the managed player entity.
|
||||
*/
|
||||
void SetPosY(Float32 y) const;
|
||||
void SetPositionY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the z axis of the managed player entity.
|
||||
*/
|
||||
void SetPosZ(Float32 z) const;
|
||||
void SetPositionZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the red color of the managed player entity.
|
||||
*/
|
||||
Int32 GetColorR() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the green color of the managed player entity.
|
||||
*/
|
||||
Int32 GetColorG() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the blue color of the managed player entity.
|
||||
*/
|
||||
Int32 GetColorB() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the red color of the managed player entity.
|
||||
*/
|
||||
void SetColorR(Int32 r) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the green color of the managed player entity.
|
||||
*/
|
||||
void SetColorG(Int32 g) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the blue color of the managed player entity.
|
||||
*/
|
||||
void SetColorB(Int32 b) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Send a formatted colored message to the managed player entity.
|
||||
|
||||
@@ -1,656 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Entity/Sprite.hpp"
|
||||
#include "Entity/Player.hpp"
|
||||
#include "Base/Vector2i.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Int32 CSprite::Max = SQMOD_SPRITE_POOL;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CSprite::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqSprite");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSprite::CSprite(Int32 id)
|
||||
: m_ID(VALID_ENTITYGETEX(id, SQMOD_SPRITE_POOL))
|
||||
, m_Tag(ToStrF("%d", id))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSprite::~CSprite()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CSprite::Cmp(const CSprite & o) const
|
||||
{
|
||||
if (m_ID == o.m_ID)
|
||||
return 0;
|
||||
else if (m_ID > o.m_ID)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const String & CSprite::ToString() const
|
||||
{
|
||||
return m_Tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const String & CSprite::GetTag() const
|
||||
{
|
||||
return m_Tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetTag(CSStr tag)
|
||||
{
|
||||
m_Tag.assign(tag);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & CSprite::GetData()
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetData(Object & data)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Apply the specified value
|
||||
m_Data = data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CSprite::Destroy(Int32 header, Object & payload)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return _Core->DelSprite(m_ID, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = _Core->GetSpriteEvent(m_ID, evid);
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
event.Release(); // Then release the current callback
|
||||
}
|
||||
// Assign the specified environment and function
|
||||
else
|
||||
{
|
||||
event = Function(env.GetVM(), env, func.GetFunc());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::ShowAll() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->ShowSprite(m_ID, -1);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::ShowFor(CPlayer & player) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->ShowSprite(m_ID, player.GetID());
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::ShowRange(Int32 first, Int32 last) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (; first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then show this textdraw on his client
|
||||
_Func->ShowSprite(m_ID, first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::HideAll() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->HideSprite(m_ID, -1);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::HideFor(CPlayer & player) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->HideSprite(m_ID, player.GetID());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::HideRange(Int32 first, Int32 last) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (; first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then hide this textdraw on his client
|
||||
_Func->HideSprite(m_ID, first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetPositionAll(const Vector2i & pos) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveSprite(m_ID, -1, pos.x, pos.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetPositionAllEx(Int32 x, Int32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveSprite(m_ID, -1, x, y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetPositionFor(CPlayer & player, const Vector2i & pos) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveSprite(m_ID, player.GetID(), pos.x, pos.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveSprite(m_ID, player.GetID(), x, y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (; first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then move this textdraw on his client
|
||||
_Func->MoveSprite(m_ID, first, pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetCenterAll(const Vector2i & pos) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSpriteCenter(m_ID, -1, pos.x, pos.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetCenterAllEx(Int32 x, Int32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSpriteCenter(m_ID, -1, x, y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetCenterFor(CPlayer & player, const Vector2i & pos) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSpriteCenter(m_ID, player.GetID(), pos.x, pos.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetCenterForEx(CPlayer & player, Int32 x, Int32 y) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSpriteCenter(m_ID, player.GetID(), x, y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetCenterRange(Int32 first, Int32 last, const Vector2i & pos) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (; first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then center this textdraw on his client
|
||||
_Func->SetSpriteCenter(m_ID, first, pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetRotationAll(Float32 rot) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotateSprite(m_ID, -1, rot);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetRotationFor(CPlayer & player, Float32 rot) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->RotateSprite(m_ID, player.GetID(), rot);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetRotationRange(Int32 first, Int32 last, Float32 rot) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (; first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then rotate this textdraw on his client
|
||||
_Func->RotateSprite(m_ID, first, rot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetAlphaAll(Uint8 alpha) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSpriteAlpha(m_ID, -1, alpha);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetAlphaFor(CPlayer & player, Uint8 alpha) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetSpriteAlpha(m_ID, player.GetID(), alpha);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CSprite::SetAlphaRange(Int32 first, Int32 last, Uint8 alpha) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (; first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then colorize this textdraw on his client
|
||||
_Func->SetSpriteAlpha(m_ID, first, alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const String & CSprite::GetFilePath() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetSprite(m_ID).mPath;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Sprite_CreateEx(CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
|
||||
Float32 angle, Int32 alpha, bool rel)
|
||||
{
|
||||
return _Core->NewSprite(-1, file, xp, yp, xr, yr, angle, alpha, rel,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Sprite_CreateEx(CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
|
||||
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewSprite(-1, file, xp, yp, xr, yr, angle, alpha, rel, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Sprite_CreateEx(Int32 index, CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
|
||||
Float32 angle, Int32 alpha, bool rel)
|
||||
{
|
||||
return _Core->NewSprite(index, file, xp, yp, xr, yr, angle, alpha, rel,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Sprite_CreateEx(Int32 index, CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
|
||||
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewSprite(index, file, xp, yp, xr, yr, angle, alpha, rel, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Sprite_Create(CSStr file, const Vector2i & pos, const Vector2i & rot,
|
||||
Float32 angle, Int32 alpha, bool rel)
|
||||
{
|
||||
return _Core->NewSprite(-1, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Sprite_Create(CSStr file, const Vector2i & pos, const Vector2i & rot,
|
||||
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewSprite(-1, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Sprite_Create(Int32 index, CSStr file, const Vector2i & pos, const Vector2i & rot,
|
||||
Float32 angle, Int32 alpha, bool rel)
|
||||
{
|
||||
return _Core->NewSprite(index, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Sprite_Create(Int32 index, CSStr file, const Vector2i & pos, const Vector2i & rot,
|
||||
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewSprite(index, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Object & Sprite_FindByID(Int32 id)
|
||||
{
|
||||
// Perform a range check on the specified identifier
|
||||
if (INVALID_ENTITYEX(id, SQMOD_SPRITE_POOL))
|
||||
{
|
||||
STHROWF("The specified sprite identifier is invalid: %d", id);
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Sprites::const_iterator itr = _Core->GetSprites().cbegin();
|
||||
Core::Sprites::const_iterator end = _Core->GetSprites().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
// Does the identifier match the specified one?
|
||||
if (itr->mID == id)
|
||||
{
|
||||
return itr->mObj; // Stop searching and return this entity
|
||||
}
|
||||
}
|
||||
// Unable to locate a sprite matching the specified identifier
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Object & Sprite_FindByTag(CSStr tag)
|
||||
{
|
||||
// Perform a validity check on the specified tag
|
||||
if (!tag || *tag == '\0')
|
||||
{
|
||||
STHROWF("The specified sprite tag is invalid: null/empty");
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Sprites::const_iterator itr = _Core->GetSprites().cbegin();
|
||||
Core::Sprites::const_iterator end = _Core->GetSprites().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
// Does this entity even exist and does the tag match the specified one?
|
||||
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
|
||||
{
|
||||
return itr->mObj; // Stop searching and return this entity
|
||||
}
|
||||
}
|
||||
// Unable to locate a sprite matching the specified tag
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Array Sprite_FindActive()
|
||||
{
|
||||
// Remember the initial stack size
|
||||
StackGuard sg;
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Sprites::const_iterator itr = _Core->GetSprites().cbegin();
|
||||
Core::Sprites::const_iterator end = _Core->GetSprites().cend();
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
// Is this entity instance active?
|
||||
if (VALID_ENTITY(itr->mID))
|
||||
{
|
||||
// Push the script object on the stack
|
||||
sq_pushobject(DefaultVM::Get(), (HSQOBJECT &)((*itr).mObj));
|
||||
// Append the object at the back of the array
|
||||
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -1)))
|
||||
{
|
||||
STHROWF("Unable to append entity instance to the list");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_CSprite(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqSprite"),
|
||||
Class< CSprite, NoConstructor< CSprite > >(vm, _SC("SqSprite"))
|
||||
// Metamethods
|
||||
.Func(_SC("_cmp"), &CSprite::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CSprite::Typename)
|
||||
.Func(_SC("_tostring"), &CSprite::ToString)
|
||||
// Static Values
|
||||
.SetStaticValue(_SC("MaxID"), CSprite::Max)
|
||||
// Core Properties
|
||||
.Prop(_SC("ID"), &CSprite::GetID)
|
||||
.Prop(_SC("Tag"), &CSprite::GetTag, &CSprite::SetTag)
|
||||
.Prop(_SC("Data"), &CSprite::GetData, &CSprite::SetData)
|
||||
.Prop(_SC("Active"), &CSprite::IsActive)
|
||||
// Core Methods
|
||||
.Func(_SC("Bind"), &CSprite::BindEvent)
|
||||
// Core Overloads
|
||||
.Overload< bool (CSprite::*)(void) >(_SC("Destroy"), &CSprite::Destroy)
|
||||
.Overload< bool (CSprite::*)(Int32) >(_SC("Destroy"), &CSprite::Destroy)
|
||||
.Overload< bool (CSprite::*)(Int32, Object &) >(_SC("Destroy"), &CSprite::Destroy)
|
||||
// Properties
|
||||
.Prop(_SC("Path"), &CSprite::GetFilePath)
|
||||
// Member Methods
|
||||
.Func(_SC("ShowAll"), &CSprite::ShowAll)
|
||||
.Func(_SC("ShowTo"), &CSprite::ShowFor)
|
||||
.Func(_SC("ShowFor"), &CSprite::ShowFor)
|
||||
.Func(_SC("ShowRange"), &CSprite::ShowRange)
|
||||
.Func(_SC("HideAll"), &CSprite::HideAll)
|
||||
.Func(_SC("HideFor"), &CSprite::HideFor)
|
||||
.Func(_SC("HideFrom"), &CSprite::HideFor)
|
||||
.Func(_SC("HideRange"), &CSprite::HideRange)
|
||||
.Func(_SC("SetPositionRange"), &CSprite::SetPositionRange)
|
||||
.Func(_SC("SetCenterRange"), &CSprite::SetCenterRange)
|
||||
.Func(_SC("SetRotationAll"), &CSprite::SetRotationAll)
|
||||
.Func(_SC("SetRotationFor"), &CSprite::SetRotationFor)
|
||||
.Func(_SC("SetRotationRange"), &CSprite::SetRotationRange)
|
||||
.Func(_SC("SetAlphaAll"), &CSprite::SetAlphaAll)
|
||||
.Func(_SC("SetAlphaFor"), &CSprite::SetAlphaFor)
|
||||
.Func(_SC("SetAlphaRange"), &CSprite::SetAlphaRange)
|
||||
// Member Overloads
|
||||
.Overload< void (CSprite::*)(const Vector2i &) const >
|
||||
(_SC("SetPositionAll"), &CSprite::SetPositionAll)
|
||||
.Overload< void (CSprite::*)(Int32, Int32) const >
|
||||
(_SC("SetPositionAll"), &CSprite::SetPositionAllEx)
|
||||
.Overload< void (CSprite::*)(CPlayer &, const Vector2i &) const >
|
||||
(_SC("SetPositionFor"), &CSprite::SetPositionFor)
|
||||
.Overload< void (CSprite::*)(CPlayer &, Int32, Int32) const >
|
||||
(_SC("SetPositionFor"), &CSprite::SetPositionForEx)
|
||||
.Overload< void (CSprite::*)(const Vector2i &) const >
|
||||
(_SC("SetCenterAll"), &CSprite::SetCenterAll)
|
||||
.Overload< void (CSprite::*)(Int32, Int32) const >
|
||||
(_SC("SetCenterAll"), &CSprite::SetCenterAllEx)
|
||||
.Overload< void (CSprite::*)(CPlayer &, const Vector2i &) const >
|
||||
(_SC("SetCenterFor"), &CSprite::SetCenterFor)
|
||||
.Overload< void (CSprite::*)(CPlayer &, Int32, Int32) const >
|
||||
(_SC("SetCenterFor"), &CSprite::SetCenterForEx)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("FindByID"), &Sprite_FindByID)
|
||||
.StaticFunc(_SC("FindByTag"), &Sprite_FindByTag)
|
||||
.StaticFunc(_SC("FindActive"), &Sprite_FindActive)
|
||||
// Static Overloads
|
||||
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel) >
|
||||
(_SC("CreateEx"), &Sprite_CreateEx)
|
||||
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel, Int32, Object &) >
|
||||
(_SC("CreateEx"), &Sprite_CreateEx)
|
||||
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel) >
|
||||
(_SC("CreateEx"), &Sprite_CreateEx)
|
||||
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel, Int32, Object &) >
|
||||
(_SC("CreateEx"), &Sprite_CreateEx)
|
||||
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool) >
|
||||
(_SC("Create"), &Sprite_Create)
|
||||
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool, Int32, Object &) >
|
||||
(_SC("Create"), &Sprite_Create)
|
||||
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool) >
|
||||
(_SC("Create"), &Sprite_Create)
|
||||
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool, Int32, Object &) >
|
||||
(_SC("Create"), &Sprite_Create)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
@@ -1,278 +0,0 @@
|
||||
#ifndef _ENTITY_SPRITE_HPP_
|
||||
#define _ENTITY_SPRITE_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Manages a single sprite entity.
|
||||
*/
|
||||
class CSprite
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
friend class Core;
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Identifier of the managed entity.
|
||||
*/
|
||||
Int32 m_ID;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* User tag associated with this instance.
|
||||
*/
|
||||
String m_Tag;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* User data associated with this instance.
|
||||
*/
|
||||
Object m_Data;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
CSprite(Int32 id);
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Maximum possible number that could represent an identifier for this entity type.
|
||||
*/
|
||||
static const Int32 Max;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
CSprite(const CSprite &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
CSprite(CSprite &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~CSprite();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
CSprite & operator = (const CSprite &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
CSprite & operator = (CSprite &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether this instance manages a valid entity.
|
||||
*/
|
||||
void Validate() const
|
||||
{
|
||||
if (INVALID_ENTITY(m_ID))
|
||||
{
|
||||
STHROWF("Invalid sprite reference [%s]", m_Tag.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare two instances of this type.
|
||||
*/
|
||||
Int32 Cmp(const CSprite & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
const String & ToString() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to retrieve the name from instances of this type.
|
||||
*/
|
||||
static SQInteger Typename(HSQUIRRELVM vm);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the identifier of the entity managed by this instance.
|
||||
*/
|
||||
Int32 GetID() const
|
||||
{
|
||||
return m_ID;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether this instance manages a valid entity.
|
||||
*/
|
||||
bool IsActive() const
|
||||
{
|
||||
return VALID_ENTITY(m_ID);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated user tag.
|
||||
*/
|
||||
const String & GetTag() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user tag.
|
||||
*/
|
||||
void SetTag(CSStr tag);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated user data.
|
||||
*/
|
||||
Object & GetData();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user data.
|
||||
*/
|
||||
void SetData(Object & data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroy the managed sprite entity.
|
||||
*/
|
||||
bool Destroy()
|
||||
{
|
||||
return Destroy(0, NullObject());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroy the managed sprite entity.
|
||||
*/
|
||||
bool Destroy(Int32 header)
|
||||
{
|
||||
return Destroy(header, NullObject());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroy the managed sprite entity.
|
||||
*/
|
||||
bool Destroy(Int32 header, Object & payload);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Bind to an event supported by this entity type.
|
||||
*/
|
||||
void BindEvent(Int32 evid, Object & env, Function & func) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Show the managed sprite entity to all players on the server.
|
||||
*/
|
||||
void ShowAll() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Show the managed sprite entity to the specified player entity.
|
||||
*/
|
||||
void ShowFor(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Show the managed sprite entity to all players in the specified range.
|
||||
*/
|
||||
void ShowRange(Int32 first, Int32 last) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Hide the managed sprite entity from all players on the server.
|
||||
*/
|
||||
void HideAll() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Hide the managed sprite entity from the specified player entity.
|
||||
*/
|
||||
void HideFor(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Hide the managed sprite entity from all players in the specified range.
|
||||
*/
|
||||
void HideRange(Int32 first, Int32 last) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed sprite entity for all players on the server.
|
||||
*/
|
||||
void SetPositionAll(const Vector2i & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed sprite entity for all players on the server.
|
||||
*/
|
||||
void SetPositionAllEx(Int32 x, Int32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed sprite entity for the specified player entity.
|
||||
*/
|
||||
void SetPositionFor(CPlayer & player, const Vector2i & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed sprite entity for the specified player entity.
|
||||
*/
|
||||
void SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed sprite entity for all players in the specified range.
|
||||
*/
|
||||
void SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the center of the managed sprite entity for all players on the server.
|
||||
*/
|
||||
void SetCenterAll(const Vector2i & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the center of the managed sprite entity for all players on the server.
|
||||
*/
|
||||
void SetCenterAllEx(Int32 x, Int32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the center of the managed sprite entity for the specified player entity.
|
||||
*/
|
||||
void SetCenterFor(CPlayer & player, const Vector2i & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the center of the managed sprite entity for the specified player entity.
|
||||
*/
|
||||
void SetCenterForEx(CPlayer & player, Int32 x, Int32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the center of the managed sprite entity for all players in the specified range.
|
||||
*/
|
||||
void SetCenterRange(Int32 first, Int32 last, const Vector2i & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the rotation of the managed sprite entity for all players on the server.
|
||||
*/
|
||||
void SetRotationAll(Float32 rot) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the rotation of the managed sprite entity for the specified player entity.
|
||||
*/
|
||||
void SetRotationFor(CPlayer & player, Float32 rot) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the rotation of the managed sprite entity for all players in the specified range.
|
||||
*/
|
||||
void SetRotationRange(Int32 first, Int32 last, Float32 rot) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the alpha of the managed sprite entity for all players on the server.
|
||||
*/
|
||||
void SetAlphaAll(Uint8 alpha) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the alpha of the managed sprite entity for the specified player entity.
|
||||
*/
|
||||
void SetAlphaFor(CPlayer & player, Uint8 alpha) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the alpha of the managed sprite entity for all players in the specified range.
|
||||
*/
|
||||
void SetAlphaRange(Int32 first, Int32 last, Uint8 alpha) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the file path of the texture used by the managed sprite entity.
|
||||
*/
|
||||
const String & GetFilePath() const;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _ENTITY_SPRITE_HPP_
|
||||
@@ -1,563 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Entity/Textdraw.hpp"
|
||||
#include "Entity/Player.hpp"
|
||||
#include "Base/Vector2i.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Int32 CTextdraw::Max = SQMOD_TEXTDRAW_POOL;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CTextdraw::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqTextdraw");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CTextdraw::CTextdraw(Int32 id)
|
||||
: m_ID(VALID_ENTITYGETEX(id, SQMOD_TEXTDRAW_POOL))
|
||||
, m_Tag(ToStrF("%d", id))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CTextdraw::~CTextdraw()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CTextdraw::Cmp(const CTextdraw & o) const
|
||||
{
|
||||
if (m_ID == o.m_ID)
|
||||
return 0;
|
||||
else if (m_ID > o.m_ID)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const String & CTextdraw::ToString() const
|
||||
{
|
||||
return m_Tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const String & CTextdraw::GetTag() const
|
||||
{
|
||||
return m_Tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetTag(CSStr tag)
|
||||
{
|
||||
m_Tag.assign(tag);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & CTextdraw::GetData()
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetData(Object & data)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Apply the specified value
|
||||
m_Data = data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CTextdraw::Destroy(Int32 header, Object & payload)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return _Core->DelTextdraw(m_ID, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = _Core->GetTextdrawEvent(m_ID, evid);
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
event.Release(); // Then release the current callback
|
||||
}
|
||||
// Assign the specified environment and function
|
||||
else
|
||||
{
|
||||
event = Function(env.GetVM(), env, func.GetFunc());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::ShowAll() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->ShowTextdraw(m_ID, -1);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::ShowFor(CPlayer & player) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->ShowTextdraw(m_ID, player.GetID());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::ShowRange(Int32 first, Int32 last) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (; first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then show this textdraw on his client
|
||||
_Func->ShowTextdraw(m_ID, first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::HideAll() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->HideTextdraw(m_ID, -1);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::HideFor(CPlayer & player) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->HideTextdraw(m_ID, player.GetID());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::HideRange(Int32 first, Int32 last) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (; first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then hide this textdraw on his client
|
||||
_Func->HideTextdraw(m_ID, first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetPositionAll(const Vector2i & pos) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveTextdraw(m_ID, -1, pos.x, pos.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetPositionAllEx(Int32 x, Int32 y) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveTextdraw(m_ID, -1, x, y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetPositionFor(CPlayer & player, const Vector2i & pos) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveTextdraw(m_ID, player.GetID(), pos.x, pos.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->MoveTextdraw(m_ID, player.GetID(), x, y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (; first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then move this textdraw on his client
|
||||
_Func->MoveTextdraw(m_ID, first, pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetColorAll(const Color4 & col) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetTextdrawColour(m_ID, -1, col.GetRGBA());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetColorAllEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetTextdrawColour(m_ID, -1, SQMOD_PACK_RGBA(r, g, b, a));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetColorFor(CPlayer & player, const Color4 & col) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetTextdrawColour(m_ID, player.GetID(), col.GetRGBA());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetColorForEx(CPlayer & player, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
|
||||
{
|
||||
// Is the specified player even valid?
|
||||
if (!player.IsActive())
|
||||
{
|
||||
STHROWF("Invalid player argument: null");
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
_Func->SetTextdrawColour(m_ID, player.GetID(), SQMOD_PACK_RGBA(r, g, b, a));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CTextdraw::SetColorRange(Int32 first, Int32 last, const Color4 & col) const
|
||||
{
|
||||
// Validate the specified range
|
||||
if (first > last)
|
||||
{
|
||||
STHROWF("Invalid player range: %d > %d", first, last);
|
||||
}
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
for (const Uint32 color = col.GetRGBA(); first <= last; ++first)
|
||||
{
|
||||
// Is the currently processed player even connected?
|
||||
if (_Func->IsPlayerConnected(first))
|
||||
{
|
||||
// Then colorize this textdraw on his client
|
||||
_Func->SetTextdrawColour(m_ID, first, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const String & CTextdraw::GetText() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetTextdraw(m_ID).mText;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Textdraw_CreateEx(CSStr text, Int32 xp, Int32 yp,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool rel)
|
||||
{
|
||||
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, xp, yp, SQMOD_PACK_ARGB(a, r, g, b), rel,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Textdraw_CreateEx(CSStr text, Int32 xp, Int32 yp,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool rel,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, xp, yp, SQMOD_PACK_ARGB(a, r, g, b), rel,
|
||||
header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Textdraw_CreateEx(Int32 index, CSStr text, Int32 xp, Int32 yp,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool rel)
|
||||
{
|
||||
return _Core->NewTextdraw(index,text, xp, yp, SQMOD_PACK_ARGB(a, r, g, b), rel,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Textdraw_CreateEx(Int32 index, CSStr text, Int32 xp, Int32 yp,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool rel,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewTextdraw(index, text, xp, yp, SQMOD_PACK_ARGB(a, r, g, b), rel,
|
||||
header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Textdraw_Create(CSStr text, const Vector2i & pos, const Color4 & color, bool rel)
|
||||
{
|
||||
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, pos.x, pos.y, color.GetARGB(), rel,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Textdraw_Create(CSStr text, const Vector2i & pos, const Color4 & color, bool rel,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, pos.x, pos.y, color.GetARGB(), rel,
|
||||
header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Textdraw_Create(Int32 index, CSStr text, const Vector2i & pos, const Color4 & color,
|
||||
bool rel)
|
||||
{
|
||||
return _Core->NewTextdraw(index, text, pos.x, pos.y, color.GetARGB(), rel,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & Textdraw_Create(Int32 index, CSStr text, const Vector2i & pos, const Color4 & color,
|
||||
bool rel, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewTextdraw(index, text, pos.x, pos.y, color.GetARGB(), rel, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Object & Textdraw_FindByID(Int32 id)
|
||||
{
|
||||
// Perform a range check on the specified identifier
|
||||
if (INVALID_ENTITYEX(id, SQMOD_TEXTDRAW_POOL))
|
||||
{
|
||||
STHROWF("The specified textdraw identifier is invalid: %d", id);
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Textdraws::const_iterator itr = _Core->GetTextdraws().cbegin();
|
||||
Core::Textdraws::const_iterator end = _Core->GetTextdraws().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
// Does the identifier match the specified one?
|
||||
if (itr->mID == id)
|
||||
{
|
||||
return itr->mObj; // Stop searching and return this entity
|
||||
}
|
||||
}
|
||||
// Unable to locate a textdraw matching the specified identifier
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Object & Textdraw_FindByTag(CSStr tag)
|
||||
{
|
||||
// Perform a validity check on the specified tag
|
||||
if (!tag || *tag == '\0')
|
||||
{
|
||||
STHROWF("The specified textdraw tag is invalid: null/empty");
|
||||
}
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Textdraws::const_iterator itr = _Core->GetTextdraws().cbegin();
|
||||
Core::Textdraws::const_iterator end = _Core->GetTextdraws().cend();
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
// Does this entity even exist and does the tag match the specified one?
|
||||
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
|
||||
{
|
||||
return itr->mObj; // Stop searching and return this entity
|
||||
}
|
||||
}
|
||||
// Unable to locate a textdraw matching the specified tag
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Array Textdraw_FindActive()
|
||||
{
|
||||
// Remember the initial stack size
|
||||
StackGuard sg;
|
||||
// Obtain the ends of the entity pool
|
||||
Core::Textdraws::const_iterator itr = _Core->GetTextdraws().cbegin();
|
||||
Core::Textdraws::const_iterator end = _Core->GetTextdraws().cend();
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
// Is this entity instance active?
|
||||
if (VALID_ENTITY(itr->mID))
|
||||
{
|
||||
// Push the script object on the stack
|
||||
sq_pushobject(DefaultVM::Get(), (HSQOBJECT &)((*itr).mObj));
|
||||
// Append the object at the back of the array
|
||||
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -1)))
|
||||
{
|
||||
STHROWF("Unable to append entity instance to the list");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_CTextdraw(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqTextdraw"),
|
||||
Class< CTextdraw, NoConstructor< CTextdraw > >(vm, _SC("SqTextdraw"))
|
||||
// Metamethods
|
||||
.Func(_SC("_cmp"), &CTextdraw::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CTextdraw::Typename)
|
||||
.Func(_SC("_tostring"), &CTextdraw::ToString)
|
||||
// Static Values
|
||||
.SetStaticValue(_SC("MaxID"), CTextdraw::Max)
|
||||
// Core Properties
|
||||
.Prop(_SC("ID"), &CTextdraw::GetID)
|
||||
.Prop(_SC("Tag"), &CTextdraw::GetTag, &CTextdraw::SetTag)
|
||||
.Prop(_SC("Data"), &CTextdraw::GetData, &CTextdraw::SetData)
|
||||
.Prop(_SC("Active"), &CTextdraw::IsActive)
|
||||
// Core Methods
|
||||
.Func(_SC("Bind"), &CTextdraw::BindEvent)
|
||||
// Core Overloads
|
||||
.Overload< bool (CTextdraw::*)(void) >(_SC("Destroy"), &CTextdraw::Destroy)
|
||||
.Overload< bool (CTextdraw::*)(Int32) >(_SC("Destroy"), &CTextdraw::Destroy)
|
||||
.Overload< bool (CTextdraw::*)(Int32, Object &) >(_SC("Destroy"), &CTextdraw::Destroy)
|
||||
// Properties
|
||||
.Prop(_SC("Text"), &CTextdraw::GetText)
|
||||
// Member Methods
|
||||
.Func(_SC("ShowAll"), &CTextdraw::ShowAll)
|
||||
.Func(_SC("ShowTo"), &CTextdraw::ShowFor)
|
||||
.Func(_SC("ShowFor"), &CTextdraw::ShowFor)
|
||||
.Func(_SC("ShowRange"), &CTextdraw::ShowRange)
|
||||
.Func(_SC("HideAll"), &CTextdraw::HideAll)
|
||||
.Func(_SC("HideFor"), &CTextdraw::HideFor)
|
||||
.Func(_SC("HideFrom"), &CTextdraw::HideFor)
|
||||
.Func(_SC("HideRange"), &CTextdraw::HideRange)
|
||||
.Func(_SC("SetPositionRange"), &CTextdraw::SetPositionRange)
|
||||
.Func(_SC("SetColorRange"), &CTextdraw::SetColorRange)
|
||||
// Member Overloads
|
||||
.Overload< void (CTextdraw::*)(const Vector2i &) const >
|
||||
(_SC("SetPositionAll"), &CTextdraw::SetPositionAll)
|
||||
.Overload< void (CTextdraw::*)(Int32, Int32) const >
|
||||
(_SC("SetPositionAll"), &CTextdraw::SetPositionAllEx)
|
||||
.Overload< void (CTextdraw::*)(CPlayer &, const Vector2i &) const >
|
||||
(_SC("SetPositionFor"), &CTextdraw::SetPositionFor)
|
||||
.Overload< void (CTextdraw::*)(CPlayer &, Int32, Int32) const >
|
||||
(_SC("SetPositionFor"), &CTextdraw::SetPositionForEx)
|
||||
.Overload< void (CTextdraw::*)(const Color4 &) const >
|
||||
(_SC("SetColorAll"), &CTextdraw::SetColorAll)
|
||||
.Overload< void (CTextdraw::*)(Uint8, Uint8, Uint8, Uint8) const >
|
||||
(_SC("SetColorAll"), &CTextdraw::SetColorAllEx)
|
||||
.Overload< void (CTextdraw::*)(CPlayer &, const Color4 &) const >
|
||||
(_SC("SetColorFor"), &CTextdraw::SetColorFor)
|
||||
.Overload< void (CTextdraw::*)(CPlayer &, Uint8, Uint8, Uint8, Uint8) const >
|
||||
(_SC("SetColorFor"), &CTextdraw::SetColorForEx)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("FindByID"), &Textdraw_FindByID)
|
||||
.StaticFunc(_SC("FindByTag"), &Textdraw_FindByTag)
|
||||
.StaticFunc(_SC("FindActive"), &Textdraw_FindActive)
|
||||
// Static Overloads
|
||||
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool) >
|
||||
(_SC("CreateEx"), &Textdraw_CreateEx)
|
||||
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool, Int32, Object &) >
|
||||
(_SC("CreateEx"), &Textdraw_CreateEx)
|
||||
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool) >
|
||||
(_SC("CreateEx"), &Textdraw_CreateEx)
|
||||
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool, Int32, Object &) >
|
||||
(_SC("CreateEx"), &Textdraw_CreateEx)
|
||||
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Color4 &, bool) >
|
||||
(_SC("Create"), &Textdraw_Create)
|
||||
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Color4 &, bool, Int32, Object &) >
|
||||
(_SC("Create"), &Textdraw_Create)
|
||||
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Color4 &, bool) >
|
||||
(_SC("Create"), &Textdraw_Create)
|
||||
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Color4 &, bool, Int32, Object &) >
|
||||
(_SC("Create"), &Textdraw_Create)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
@@ -1,248 +0,0 @@
|
||||
#ifndef _ENTITY_TEXTDRAW_HPP_
|
||||
#define _ENTITY_TEXTDRAW_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Manages a single textdraw entity.
|
||||
*/
|
||||
class CTextdraw
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
friend class Core;
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Identifier of the managed entity.
|
||||
*/
|
||||
Int32 m_ID;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* User tag associated with this instance.
|
||||
*/
|
||||
String m_Tag;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* User data associated with this instance.
|
||||
*/
|
||||
Object m_Data;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
CTextdraw(Int32 id);
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Maximum possible number that could represent an identifier for this entity type.
|
||||
*/
|
||||
static const Int32 Max;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
CTextdraw(const CTextdraw &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
CTextdraw(CTextdraw &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~CTextdraw();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
CTextdraw & operator = (const CTextdraw &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
CTextdraw & operator = (CTextdraw &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether this instance manages a valid entity.
|
||||
*/
|
||||
void Validate() const
|
||||
{
|
||||
if (INVALID_ENTITY(m_ID))
|
||||
{
|
||||
STHROWF("Invalid textdraw reference [%s]", m_Tag.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare two instances of this type.
|
||||
*/
|
||||
Int32 Cmp(const CTextdraw & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
const String & ToString() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to retrieve the name from instances of this type.
|
||||
*/
|
||||
static SQInteger Typename(HSQUIRRELVM vm);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the identifier of the entity managed by this instance.
|
||||
*/
|
||||
Int32 GetID() const
|
||||
{
|
||||
return m_ID;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether this instance manages a valid entity.
|
||||
*/
|
||||
bool IsActive() const
|
||||
{
|
||||
return VALID_ENTITY(m_ID);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated user tag.
|
||||
*/
|
||||
const String & GetTag() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user tag.
|
||||
*/
|
||||
void SetTag(CSStr tag);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated user data.
|
||||
*/
|
||||
Object & GetData();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user data.
|
||||
*/
|
||||
void SetData(Object & data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroy the managed textdraw entity.
|
||||
*/
|
||||
bool Destroy()
|
||||
{
|
||||
return Destroy(0, NullObject());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroy the managed textdraw entity.
|
||||
*/
|
||||
bool Destroy(Int32 header)
|
||||
{
|
||||
return Destroy(header, NullObject());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroy the managed textdraw entity.
|
||||
*/
|
||||
bool Destroy(Int32 header, Object & payload);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Bind to an event supported by this entity type.
|
||||
*/
|
||||
void BindEvent(Int32 evid, Object & env, Function & func) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Show the managed textdraw entity to all players on the server.
|
||||
*/
|
||||
void ShowAll() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Show the managed textdraw entity to the specified player entity.
|
||||
*/
|
||||
void ShowFor(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Show the managed textdraw entity to all players in the specified range.
|
||||
*/
|
||||
void ShowRange(Int32 first, Int32 last) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Hide the managed textdraw entity from all players on the server.
|
||||
*/
|
||||
void HideAll() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Hide the managed textdraw entity from the specified player entity.
|
||||
*/
|
||||
void HideFor(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Hide the managed textdraw entity from all players in the specified range.
|
||||
*/
|
||||
void HideRange(Int32 first, Int32 last) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed textdraw entity for all players on the server.
|
||||
*/
|
||||
void SetPositionAll(const Vector2i & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed textdraw entity for all players on the server.
|
||||
*/
|
||||
void SetPositionAllEx(Int32 x, Int32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed textdraw entity for the specified player entity.
|
||||
*/
|
||||
void SetPositionFor(CPlayer & player, const Vector2i & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed textdraw entity for the specified player entity.
|
||||
*/
|
||||
void SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the position of the managed textdraw entity for all players in the specified range.
|
||||
*/
|
||||
void SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the center of the managed textdraw entity for all players on the server.
|
||||
*/
|
||||
void SetColorAll(const Color4 & col) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the color of the managed textdraw entity for all players on the server.
|
||||
*/
|
||||
void SetColorAllEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the color of the managed textdraw entity for the specified player entity.
|
||||
*/
|
||||
void SetColorFor(CPlayer & player, const Color4 & col) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the color of the managed textdraw entity for the specified player entity.
|
||||
*/
|
||||
void SetColorForEx(CPlayer & player, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the color of the managed textdraw entity for all players in the specified range.
|
||||
*/
|
||||
void SetColorRange(Int32 first, Int32 last, const Color4 & col) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the text string used by the managed textdraw entity.
|
||||
*/
|
||||
const String & GetText() const;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _ENTITY_TEXTDRAW_HPP_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,14 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Circular locks employed by the vehicle manager.
|
||||
*/
|
||||
enum VehicleCircularLocks
|
||||
{
|
||||
VCL_EMIT_VEHICLE_OPTION = (1 << 0)
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Manages a single vehicle entity.
|
||||
*/
|
||||
@@ -18,8 +26,8 @@ class CVehicle
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static Vector2 s_Vector2;
|
||||
static Vector3 s_Vector3;
|
||||
static Vector4 s_Vector4;
|
||||
static Quaternion s_Quaternion;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -37,6 +45,11 @@ private:
|
||||
*/
|
||||
Object m_Data;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Prevent events from triggering themselves.
|
||||
*/
|
||||
Uint32 m_CircularLocks;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
@@ -167,6 +180,21 @@ public:
|
||||
*/
|
||||
bool IsStreamedFor(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current option value of the managed vehicle entity.
|
||||
*/
|
||||
bool GetOption(Int32 option_id) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the current option value of the managed vehicle entity.
|
||||
*/
|
||||
void SetOption(Int32 option_id, bool toggle);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the current option value of the managed vehicle entity.
|
||||
*/
|
||||
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the synchronization source of the managed vehicle entity.
|
||||
*/
|
||||
@@ -217,6 +245,11 @@ public:
|
||||
*/
|
||||
void SetImmunity(Int32 flags) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explode the managed vehicle entity.
|
||||
*/
|
||||
void Explode() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed vehicle entity is wrecked.
|
||||
*/
|
||||
@@ -305,27 +338,27 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the relative speed of the managed vehicle entity.
|
||||
*/
|
||||
const Vector3 & GetRelSpeed() const;
|
||||
const Vector3 & GetRelativeSpeed() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative speed of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelSpeed(const Vector3 & vel) const;
|
||||
void SetRelativeSpeed(const Vector3 & vel) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative speed of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelSpeedEx(Float32 x, Float32 y, Float32 z) const;
|
||||
void SetRelativeSpeedEx(Float32 x, Float32 y, Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative speed of the managed vehicle entity.
|
||||
*/
|
||||
void AddRelSpeed(const Vector3 & vel) const;
|
||||
void AddRelativeSpeed(const Vector3 & vel) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative speed of the managed vehicle entity.
|
||||
*/
|
||||
void AddRelSpeedEx(Float32 x, Float32 y, Float32 z) const;
|
||||
void AddRelativeSpeedEx(Float32 x, Float32 y, Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the turn speed of the managed vehicle entity.
|
||||
@@ -355,42 +388,42 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the relative turn speed of the managed vehicle entity.
|
||||
*/
|
||||
const Vector3 & GetRelTurnSpeed() const;
|
||||
const Vector3 & GetRelativeTurnSpeed() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative turn speed of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelTurnSpeed(const Vector3 & vel) const;
|
||||
void SetRelativeTurnSpeed(const Vector3 & vel) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative turn speed of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
|
||||
void SetRelativeTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative turn speed of the managed vehicle entity.
|
||||
*/
|
||||
void AddRelTurnSpeed(const Vector3 & vel) const;
|
||||
void AddRelativeTurnSpeed(const Vector3 & vel) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative turn speed of the managed vehicle entity.
|
||||
*/
|
||||
void AddRelTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
|
||||
void AddRelativeTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the spawn position of the managed vehicle entity.
|
||||
*/
|
||||
const Vector4 & GetSpawnPosition() const;
|
||||
const Vector3 & GetSpawnPosition() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the spawn position of the managed vehicle entity.
|
||||
*/
|
||||
void SetSpawnPosition(const Vector4 & pos) const;
|
||||
void SetSpawnPosition(const Vector3 & pos) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the spawn position of the managed vehicle entity.
|
||||
*/
|
||||
void SetSpawnPositionEx(Float32 x, Float32 y, Float32 z, Float32 w) const;
|
||||
void SetSpawnPositionEx(Float32 x, Float32 y, Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the spawn rotation of the managed vehicle entity.
|
||||
@@ -425,12 +458,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the respawn timer of the managed vehicle entity.
|
||||
*/
|
||||
Uint32 GetRespawnTimer() const;
|
||||
Uint32 GetIdleRespawnTimer() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the respawn timer of the managed vehicle entity.
|
||||
*/
|
||||
void SetRespawnTimer(Uint32 timer) const;
|
||||
void SetIdleRespawnTimer(Uint32 millis) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the health of the managed vehicle entity.
|
||||
@@ -467,16 +500,6 @@ public:
|
||||
*/
|
||||
void SetColors(Int32 primary, Int32 secondary) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed vehicle entity is locked.
|
||||
*/
|
||||
bool GetLocked() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed vehicle entity is locked.
|
||||
*/
|
||||
void SetLocked(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the part status of the managed vehicle entity.
|
||||
*/
|
||||
@@ -507,26 +530,6 @@ public:
|
||||
*/
|
||||
void SetDamageData(Uint32 data) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed vehicle entity has alarm.
|
||||
*/
|
||||
bool GetAlarm() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed vehicle entity has alarm.
|
||||
*/
|
||||
void SetAlarm(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed vehicle entity has lights.
|
||||
*/
|
||||
bool GetLights() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed vehicle entity has lights.
|
||||
*/
|
||||
void SetLights(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the radio of the managed vehicle entity.
|
||||
*/
|
||||
@@ -538,159 +541,274 @@ public:
|
||||
void SetRadio(Int32 radio) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed vehicle entity has radio locked.
|
||||
* Retrieve the turret rotation of the managed vehicle entity.
|
||||
*/
|
||||
bool GetRadioLocked() const;
|
||||
const Vector2 & GetTurretRotation() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed vehicle entity has radio locked.
|
||||
* Retrieve the horizontal turret rotation of the managed vehicle entity.
|
||||
*/
|
||||
void SetRadioLocked(bool toggle) const;
|
||||
Float32 GetHorizontalTurretRotation() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the managed vehicle entity is in ghost state.
|
||||
* Retrieve the vertical turret rotation of the managed vehicle entity.
|
||||
*/
|
||||
bool GetGhostState() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the managed vehicle entity is in ghost state.
|
||||
*/
|
||||
void SetGhostState(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset all the handling rules for the managed vehicle entity.
|
||||
*/
|
||||
void ResetHandling() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset the specified handling rule for the managed vehicle entity.
|
||||
*/
|
||||
void ResetHandling(Int32 rule) const;
|
||||
Float32 GetVerticalTurretRotation() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the specified handling ruleexists in the managed vehicle entity.
|
||||
*/
|
||||
bool ExistsHandling(Int32 rule) const;
|
||||
bool ExistsHandlingRule(Int32 rule) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the handling data of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetHandlingData(Int32 rule) const;
|
||||
Float32 GetHandlingRule(Int32 rule) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the handling data of the managed vehicle entity.
|
||||
*/
|
||||
void SetHandlingData(Int32 rule, Float32 data) const;
|
||||
void SetHandlingRule(Int32 rule, Float32 data) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset the specified handling rule for the managed vehicle entity.
|
||||
*/
|
||||
void ResetHandlingRule(Int32 rule) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset all the handling rules for the managed vehicle entity.
|
||||
*/
|
||||
void ResetHandlings() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Embark the specified player entity into the managed vehicle entity.
|
||||
*/
|
||||
void Embark(CPlayer & player) const;
|
||||
bool Embark(CPlayer & player) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Embark the specified player entity into the managed vehicle entity.
|
||||
*/
|
||||
void Embark(CPlayer & player, Int32 slot, bool allocate, bool warp) const;
|
||||
bool Embark(CPlayer & player, Int32 slot, bool allocate, bool warp) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetPosX() const;
|
||||
Float32 GetPositionX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetPosY() const;
|
||||
Float32 GetPositionY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetPosZ() const;
|
||||
Float32 GetPositionZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetPosX(Float32 x) const;
|
||||
void SetPositionX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetPosY(Float32 y) const;
|
||||
void SetPositionY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the position on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetPosZ(Float32 z) const;
|
||||
void SetPositionZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the rotation on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRotX() const;
|
||||
Float32 GetRotationX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the rotation on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRotY() const;
|
||||
Float32 GetRotationY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the rotation on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRotZ() const;
|
||||
Float32 GetRotationZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the rotation amount of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRotW() const;
|
||||
Float32 GetRotationW() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetRotX(Float32 x) const;
|
||||
void SetRotationX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetRotY(Float32 y) const;
|
||||
void SetRotationY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetRotZ(Float32 z) const;
|
||||
void SetRotationZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the rotation amount of the managed vehicle entity.
|
||||
*/
|
||||
void SetRotW(Float32 w) const;
|
||||
void SetRotationW(Float32 w) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the euler rotation on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetERotX() const;
|
||||
Float32 GetEulerRotationX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the euler rotation on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetERotY() const;
|
||||
Float32 GetEulerRotationY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the euler rotation on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetERotZ() const;
|
||||
Float32 GetEulerRotationZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the euler rotation on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetERotX(Float32 x) const;
|
||||
void SetEulerRotationX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the euler rotation on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetERotY(Float32 y) const;
|
||||
void SetEulerRotationY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the euler rotation on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetERotZ(Float32 z) const;
|
||||
void SetEulerRotationZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the velocity on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetSpeedX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the velocity on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetSpeedY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the velocity on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetSpeedZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the velocity on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetSpeedX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the velocity on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetSpeedY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the velocity on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetSpeedZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the relative velocity on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRelativeSpeedX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the relative velocity on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRelativeSpeedY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the relative velocity on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRelativeSpeedZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative velocity on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelativeSpeedX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative velocity on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelativeSpeedY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative velocity on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelativeSpeedZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the turn velocity on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetTurnSpeedX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the turn velocity on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetTurnSpeedY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the turn velocity on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetTurnSpeedZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the turn velocity on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetTurnSpeedX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the turn velocity on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetTurnSpeedY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the turn velocity on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetTurnSpeedZ(Float32 z) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the relative turn velocity on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRelativeTurnSpeedX() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the relative turn velocity on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRelativeTurnSpeedY() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the relative turn velocity on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
Float32 GetRelativeTurnSpeedZ() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative turn velocity on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelativeTurnSpeedX(Float32 x) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative turn velocity on the y axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelativeTurnSpeedY(Float32 y) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the relative turn velocity on the z axis of the managed vehicle entity.
|
||||
*/
|
||||
void SetRelativeTurnSpeedZ(Float32 z) const;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -33,20 +33,14 @@ static HSQAPI GetSquirrelAPI()
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static HSQUIRRELVM GetSquirrelVM()
|
||||
{
|
||||
// Do we even have a core instance?
|
||||
if (_Core)
|
||||
{
|
||||
return _Core->GetVM();
|
||||
}
|
||||
// No idea ho we got here but we have to return something!
|
||||
return NULL;
|
||||
return Core::Get().GetVM();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static SQRESULT SqEx_LoadScript(const SQChar * filepath)
|
||||
{
|
||||
// Attempt to add the specified script to the load queue
|
||||
if (_Core->LoadScript(filepath))
|
||||
if (Core::Get().LoadScript(filepath))
|
||||
{
|
||||
return SQ_OK; // The script as added or already existed
|
||||
}
|
||||
@@ -286,7 +280,9 @@ void InitExports()
|
||||
g_SqExports.PushTimestamp = SqEx_PushTimestamp;
|
||||
|
||||
// Export them to the server
|
||||
_Func->ExportFunctions(_Info->nPluginId, (void **)(&sqexports), sizeof(SQEXPORTS));
|
||||
_Func->ExportFunctions(_Info->pluginId,
|
||||
const_cast< const void ** >(reinterpret_cast< void ** >(&sqexports)),
|
||||
sizeof(SQEXPORTS));
|
||||
|
||||
//vm
|
||||
g_SqAPI.open = sq_open;
|
||||
|
||||
@@ -7,231 +7,17 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <crc32.h>
|
||||
#include <keccak.h>
|
||||
#include <md5.h>
|
||||
#include <sha1.h>
|
||||
#include <sha256.h>
|
||||
#include <sha3.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger AES256::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqAES256");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AES256::AES256()
|
||||
: m_Context(), m_Buffer()
|
||||
{
|
||||
aes256_done(&m_Context);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AES256::AES256(CSStr key)
|
||||
: m_Context(), m_Buffer()
|
||||
{
|
||||
Init(key);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 AES256::Cmp(const AES256 & o) const
|
||||
{
|
||||
return std::memcmp(m_Buffer, o.m_Buffer, sizeof(m_Buffer));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr AES256::ToString() const
|
||||
{
|
||||
return ToStrF("%s", m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr AES256::GetKey() const
|
||||
{
|
||||
return reinterpret_cast< CSStr >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool AES256::Init(CSStr key)
|
||||
{
|
||||
// Clear current key, if any
|
||||
aes256_done(&m_Context);
|
||||
// Is the specified key empty?
|
||||
if (!key || *key == '\0')
|
||||
{
|
||||
return false; // Leave the context with an empty key
|
||||
}
|
||||
// Obtain the specified key size
|
||||
const Uint32 size = (std::strlen(key) * sizeof(SQChar));
|
||||
// See if the key size is accepted
|
||||
if (size > sizeof(m_Buffer))
|
||||
{
|
||||
STHROWF("The specified key is out of bounds: %u > %u", size, sizeof(m_Buffer));
|
||||
}
|
||||
// Initialize the key buffer to 0
|
||||
std::memset(m_Buffer, 0, sizeof(m_Buffer));
|
||||
// Copy the key into the key buffer
|
||||
std::memcpy(m_Buffer, key, size);
|
||||
// Initialize the context with the specified key
|
||||
aes256_init(&m_Context, m_Buffer);
|
||||
// This context was successfully initialized
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void AES256::Done()
|
||||
{
|
||||
aes256_done(&m_Context);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
String AES256::Encrypt(CSStr data)
|
||||
{
|
||||
// Is there any data to encrypt?
|
||||
if (!data || *data == 0)
|
||||
{
|
||||
return String();
|
||||
}
|
||||
// Copy the data into an editable string
|
||||
String str(data);
|
||||
// Make sure that we have a size with a multiple of 16
|
||||
if ((str.size() % 16) != 0)
|
||||
{
|
||||
str.resize(str.size() - (str.size() % 16) + 16);
|
||||
}
|
||||
// Encrypt in chunks of 16 characters
|
||||
for (Uint32 n = 0; n < str.size(); n += 16)
|
||||
{
|
||||
aes256_encrypt_ecb(&m_Context, reinterpret_cast< Uint8 * >(&str[n]));
|
||||
}
|
||||
// Return ownership of the encrypted string
|
||||
return std::move(str);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
String AES256::Decrypt(CSStr data)
|
||||
{
|
||||
// Is there any data to decrypt?
|
||||
if (!data || *data == 0)
|
||||
{
|
||||
return String();
|
||||
}
|
||||
// Copy the data into an editable string
|
||||
String str(data);
|
||||
// Make sure that we have a size with a multiple of 16
|
||||
if ((str.size() % 16) != 0)
|
||||
{
|
||||
str.resize(str.size() - (str.size() % 16) + 16);
|
||||
}
|
||||
// Decrypt inc chunks of 16 characters
|
||||
for (Uint32 n = 0; n < str.size(); n += 16)
|
||||
{
|
||||
aes256_decrypt_ecb(&m_Context, reinterpret_cast< Uint8 * >(&str[n]));
|
||||
}
|
||||
// Remove null characters in case the string was not a multiple of 16 when encrypted
|
||||
while (!str.empty() && str.back() == 0)
|
||||
{
|
||||
str.pop_back();
|
||||
}
|
||||
// Return ownership of the encrypted string
|
||||
return std::move(str);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Utility to avoid creating encoder instances for each call.
|
||||
*/
|
||||
template < class T > struct BaseHash
|
||||
{
|
||||
static T Algo;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < class T > T BaseHash< T >::Algo;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Hash the specified value or the result of a formatted string.
|
||||
*/
|
||||
template < class T > static SQInteger HashF(HSQUIRRELVM vm)
|
||||
{
|
||||
// Attempt to retrieve the value from the stack as a string
|
||||
StackStrF val(vm, 2);
|
||||
// Have we failed to retrieve the string?
|
||||
if (SQ_FAILED(val.mRes))
|
||||
{
|
||||
return val.mRes; // Propagate the error!
|
||||
}
|
||||
// Forward the call to the actual implementation and store the string
|
||||
String str(BaseHash< T >::Algo(val.mPtr));
|
||||
// Push the string on the stack
|
||||
sq_pushstring(vm, str.data(), str.size());
|
||||
// At this point we have a valid string on the stack
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
template < class T > static void RegisterWrapper(Table & hashns, CCStr cname)
|
||||
{
|
||||
typedef HashWrapper< T > Hash;
|
||||
hashns.Bind(cname, Class< Hash >(hashns.GetVM(), cname)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Metamethods
|
||||
.Func(_SC("_tostring"), &Hash::ToString)
|
||||
// Properties
|
||||
.Prop(_SC("Hash"), &Hash::GetHash)
|
||||
// Functions
|
||||
.Func(_SC("Reset"), &Hash::Reset)
|
||||
.Func(_SC("Compute"), &Hash::Compute)
|
||||
.Func(_SC("GetHash"), &Hash::GetHash)
|
||||
.Func(_SC("Add"), &Hash::AddStr)
|
||||
.Func(_SC("AddStr"), &Hash::AddStr)
|
||||
);
|
||||
}
|
||||
extern void Register_Hash(HSQUIRRELVM vm);
|
||||
extern void Register_AES(HSQUIRRELVM vm);
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Crypt(HSQUIRRELVM vm)
|
||||
{
|
||||
Table hashns(vm);
|
||||
|
||||
RegisterWrapper< CRC32 >(hashns, _SC("CRC32"));
|
||||
RegisterWrapper< Keccak >(hashns, _SC("Keccak"));
|
||||
RegisterWrapper< MD5 >(hashns, _SC("MD5"));
|
||||
RegisterWrapper< SHA1 >(hashns, _SC("SHA1"));
|
||||
RegisterWrapper< SHA256 >(hashns, _SC("SHA256"));
|
||||
RegisterWrapper< SHA3 >(hashns, _SC("SHA3"));
|
||||
|
||||
hashns.SquirrelFunc(_SC("GetCRC32"), &HashF< CRC32 >);
|
||||
hashns.SquirrelFunc(_SC("GetKeccak"), &HashF< Keccak >);
|
||||
hashns.SquirrelFunc(_SC("GetMD5"), &HashF< MD5 >);
|
||||
hashns.SquirrelFunc(_SC("GetSHA1"), &HashF< SHA1 >);
|
||||
hashns.SquirrelFunc(_SC("GetSHA256"), &HashF< SHA256 >);
|
||||
hashns.SquirrelFunc(_SC("GetSHA3"), &HashF< SHA3 >);
|
||||
|
||||
RootTable(vm).Bind(_SC("SqHash"), hashns);
|
||||
|
||||
RootTable(vm).Bind("SqAES256", Class< AES256 >(vm, "SqAES256")
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< CSStr >()
|
||||
// Metamethods
|
||||
.Func(_SC("_cmp"), &AES256::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &AES256::Typename)
|
||||
.Func(_SC("_tostring"), &AES256::ToString)
|
||||
/* Properties */
|
||||
.Prop(_SC("Key"), &AES256::GetKey)
|
||||
/* Functions */
|
||||
.Func(_SC("Init"), &AES256::Init)
|
||||
.Func(_SC("Done"), &AES256::Done)
|
||||
.Func(_SC("Encrypt"), &AES256::Encrypt)
|
||||
.Func(_SC("Decrypt"), &AES256::Decrypt)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -4,196 +4,10 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "SqBase.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <aes256.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Simple class to maintain the state of an encoder.
|
||||
*/
|
||||
template < class T > class HashWrapper
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
HashWrapper()
|
||||
: m_Encoder()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy operator.
|
||||
*/
|
||||
HashWrapper(const HashWrapper & o)
|
||||
: m_Encoder(o.m_Encoder)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~HashWrapper()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
HashWrapper & operator = (const HashWrapper & o)
|
||||
{
|
||||
m_Encoder = o.m_Encoder;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
String ToString()
|
||||
{
|
||||
return m_Encoder.getHash();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset the encoder state.
|
||||
*/
|
||||
void Reset()
|
||||
{
|
||||
m_Encoder.reset();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Compute the hash of the specified string.
|
||||
*/
|
||||
String Compute(const String & str)
|
||||
{
|
||||
return m_Encoder(str);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the hash value of the data hashed so far.
|
||||
*/
|
||||
String GetHash()
|
||||
{
|
||||
return m_Encoder.getHash();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Add a string value to be hashed.
|
||||
*/
|
||||
void AddStr(const String & str)
|
||||
{
|
||||
m_Encoder.add(str.data(), str.length() * sizeof(String::value_type));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The managed encoder state.
|
||||
*/
|
||||
T m_Encoder;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Simple wrapper around a the AES encryption context.
|
||||
*/
|
||||
class AES256
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
AES256();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct with an explicit key.
|
||||
*/
|
||||
AES256(CSStr key);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
AES256(const AES256 & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
AES256(AES256 && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~AES256() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
AES256 & operator = (const AES256 & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
AES256 & operator = (AES256 && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare two instances of this type.
|
||||
*/
|
||||
Int32 Cmp(const AES256 & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
CSStr ToString() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to retrieve the name from instances of this type.
|
||||
*/
|
||||
static SQInteger Typename(HSQUIRRELVM vm);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated key.
|
||||
*/
|
||||
CSStr GetKey() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Initialize the context key.
|
||||
*/
|
||||
bool Init(CSStr key);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset the associated context.
|
||||
*/
|
||||
void Done();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Encrypt the specified string.
|
||||
*/
|
||||
String Encrypt(CSStr data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Decrypt the specified string.
|
||||
*/
|
||||
String Decrypt(CSStr data);
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The managed encryption context.
|
||||
*/
|
||||
aes256_context m_Context;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The key used to encrypt data.
|
||||
*/
|
||||
Uint8 m_Buffer[32]{0};
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
|
||||
160
source/Library/Crypt/AES.cpp
Normal file
160
source/Library/Crypt/AES.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Crypt/AES.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger AES256::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqAES256");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AES256::AES256()
|
||||
: m_Context(), m_Buffer()
|
||||
{
|
||||
aes256_done(&m_Context);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AES256::AES256(CSStr key)
|
||||
: m_Context(), m_Buffer()
|
||||
{
|
||||
Init(key);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 AES256::Cmp(const AES256 & o) const
|
||||
{
|
||||
return std::memcmp(m_Buffer, o.m_Buffer, sizeof(m_Buffer));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr AES256::ToString() const
|
||||
{
|
||||
return ToStrF("%s", m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr AES256::GetKey() const
|
||||
{
|
||||
return reinterpret_cast< CSStr >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool AES256::Init(CSStr key)
|
||||
{
|
||||
// Clear current key, if any
|
||||
aes256_done(&m_Context);
|
||||
// Is the specified key empty?
|
||||
if (!key || *key == '\0')
|
||||
{
|
||||
return false; // Leave the context with an empty key
|
||||
}
|
||||
// Obtain the specified key size
|
||||
const Uint32 size = (std::strlen(key) * sizeof(SQChar));
|
||||
// See if the key size is accepted
|
||||
if (size > sizeof(m_Buffer))
|
||||
{
|
||||
STHROWF("The specified key is out of bounds: %u > %u", size, sizeof(m_Buffer));
|
||||
}
|
||||
// Initialize the key buffer to 0
|
||||
std::memset(m_Buffer, 0, sizeof(m_Buffer));
|
||||
// Copy the key into the key buffer
|
||||
std::memcpy(m_Buffer, key, size);
|
||||
// Initialize the context with the specified key
|
||||
aes256_init(&m_Context, m_Buffer);
|
||||
// This context was successfully initialized
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void AES256::Done()
|
||||
{
|
||||
aes256_done(&m_Context);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
String AES256::Encrypt(CSStr data)
|
||||
{
|
||||
// Is there any data to encrypt?
|
||||
if (!data || *data == 0)
|
||||
{
|
||||
return String();
|
||||
}
|
||||
// Copy the data into an editable string
|
||||
String str(data);
|
||||
// Make sure that we have a size with a multiple of 16
|
||||
if ((str.size() % 16) != 0)
|
||||
{
|
||||
str.resize(str.size() - (str.size() % 16) + 16);
|
||||
}
|
||||
// Encrypt in chunks of 16 characters
|
||||
for (Uint32 n = 0; n < str.size(); n += 16)
|
||||
{
|
||||
aes256_encrypt_ecb(&m_Context, reinterpret_cast< Uint8 * >(&str[n]));
|
||||
}
|
||||
// Return ownership of the encrypted string
|
||||
return std::move(str);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
String AES256::Decrypt(CSStr data)
|
||||
{
|
||||
// Is there any data to decrypt?
|
||||
if (!data || *data == 0)
|
||||
{
|
||||
return String();
|
||||
}
|
||||
// Copy the data into an editable string
|
||||
String str(data);
|
||||
// Make sure that we have a size with a multiple of 16
|
||||
if ((str.size() % 16) != 0)
|
||||
{
|
||||
str.resize(str.size() - (str.size() % 16) + 16);
|
||||
}
|
||||
// Decrypt inc chunks of 16 characters
|
||||
for (Uint32 n = 0; n < str.size(); n += 16)
|
||||
{
|
||||
aes256_decrypt_ecb(&m_Context, reinterpret_cast< Uint8 * >(&str[n]));
|
||||
}
|
||||
// Remove null characters in case the string was not a multiple of 16 when encrypted
|
||||
while (!str.empty() && str.back() == 0)
|
||||
{
|
||||
str.pop_back();
|
||||
}
|
||||
// Return ownership of the encrypted string
|
||||
return std::move(str);
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_AES(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind("SqAES256", Class< AES256 >(vm, "SqAES256")
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< CSStr >()
|
||||
// Metamethods
|
||||
.Func(_SC("_cmp"), &AES256::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &AES256::Typename)
|
||||
.Func(_SC("_tostring"), &AES256::ToString)
|
||||
/* Properties */
|
||||
.Prop(_SC("Key"), &AES256::GetKey)
|
||||
/* Functions */
|
||||
.Func(_SC("Init"), &AES256::Init)
|
||||
.Func(_SC("Done"), &AES256::Done)
|
||||
.Func(_SC("Encrypt"), &AES256::Encrypt)
|
||||
.Func(_SC("Decrypt"), &AES256::Decrypt)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
110
source/Library/Crypt/AES.hpp
Normal file
110
source/Library/Crypt/AES.hpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#ifndef _LIBRARY_CRYPT_AES_HPP_
|
||||
#define _LIBRARY_CRYPT_AES_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "SqBase.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <aes256.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Simple wrapper around a the AES encryption context.
|
||||
*/
|
||||
class AES256
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
AES256();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct with an explicit key.
|
||||
*/
|
||||
AES256(CSStr key);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
AES256(const AES256 & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
AES256(AES256 && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~AES256() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
AES256 & operator = (const AES256 & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
AES256 & operator = (AES256 && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare two instances of this type.
|
||||
*/
|
||||
Int32 Cmp(const AES256 & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
CSStr ToString() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to retrieve the name from instances of this type.
|
||||
*/
|
||||
static SQInteger Typename(HSQUIRRELVM vm);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated key.
|
||||
*/
|
||||
CSStr GetKey() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Initialize the context key.
|
||||
*/
|
||||
bool Init(CSStr key);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset the associated context.
|
||||
*/
|
||||
void Done();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Encrypt the specified string.
|
||||
*/
|
||||
String Encrypt(CSStr data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Decrypt the specified string.
|
||||
*/
|
||||
String Decrypt(CSStr data);
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The managed encryption context.
|
||||
*/
|
||||
aes256_context m_Context;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The key used to encrypt data.
|
||||
*/
|
||||
Uint8 m_Buffer[32]{0};
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_CRYPT_AES_HPP_
|
||||
94
source/Library/Crypt/Hash.cpp
Normal file
94
source/Library/Crypt/Hash.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Crypt/Hash.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <crc32.h>
|
||||
#include <keccak.h>
|
||||
#include <md5.h>
|
||||
#include <sha1.h>
|
||||
#include <sha256.h>
|
||||
#include <sha3.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Utility to avoid creating encoder instances for each call.
|
||||
*/
|
||||
template < class T > struct BaseHash
|
||||
{
|
||||
static T Algo;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < class T > T BaseHash< T >::Algo;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Hash the specified value or the result of a formatted string.
|
||||
*/
|
||||
template < class T > static SQInteger HashF(HSQUIRRELVM vm)
|
||||
{
|
||||
// Attempt to retrieve the value from the stack as a string
|
||||
StackStrF val(vm, 2);
|
||||
// Have we failed to retrieve the string?
|
||||
if (SQ_FAILED(val.mRes))
|
||||
{
|
||||
return val.mRes; // Propagate the error!
|
||||
}
|
||||
// Forward the call to the actual implementation and store the string
|
||||
String str(BaseHash< T >::Algo(val.mPtr));
|
||||
// Push the string on the stack
|
||||
sq_pushstring(vm, str.data(), str.size());
|
||||
// At this point we have a valid string on the stack
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
template < class T > static void RegisterWrapper(Table & hashns, CCStr cname)
|
||||
{
|
||||
typedef HashWrapper< T > Hash;
|
||||
hashns.Bind(cname, Class< Hash >(hashns.GetVM(), cname)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Metamethods
|
||||
.Func(_SC("_tostring"), &Hash::ToString)
|
||||
// Properties
|
||||
.Prop(_SC("Hash"), &Hash::GetHash)
|
||||
// Functions
|
||||
.Func(_SC("Reset"), &Hash::Reset)
|
||||
.Func(_SC("Compute"), &Hash::Compute)
|
||||
.Func(_SC("GetHash"), &Hash::GetHash)
|
||||
.Func(_SC("Add"), &Hash::AddStr)
|
||||
.Func(_SC("AddStr"), &Hash::AddStr)
|
||||
);
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Hash(HSQUIRRELVM vm)
|
||||
{
|
||||
Table hashns(vm);
|
||||
|
||||
RegisterWrapper< CRC32 >(hashns, _SC("CRC32"));
|
||||
RegisterWrapper< Keccak >(hashns, _SC("Keccak"));
|
||||
RegisterWrapper< MD5 >(hashns, _SC("MD5"));
|
||||
RegisterWrapper< SHA1 >(hashns, _SC("SHA1"));
|
||||
RegisterWrapper< SHA256 >(hashns, _SC("SHA256"));
|
||||
RegisterWrapper< SHA3 >(hashns, _SC("SHA3"));
|
||||
|
||||
hashns.SquirrelFunc(_SC("GetCRC32"), &HashF< CRC32 >);
|
||||
hashns.SquirrelFunc(_SC("GetKeccak"), &HashF< Keccak >);
|
||||
hashns.SquirrelFunc(_SC("GetMD5"), &HashF< MD5 >);
|
||||
hashns.SquirrelFunc(_SC("GetSHA1"), &HashF< SHA1 >);
|
||||
hashns.SquirrelFunc(_SC("GetSHA256"), &HashF< SHA256 >);
|
||||
hashns.SquirrelFunc(_SC("GetSHA3"), &HashF< SHA3 >);
|
||||
|
||||
RootTable(vm).Bind(_SC("SqHash"), hashns);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
102
source/Library/Crypt/Hash.hpp
Normal file
102
source/Library/Crypt/Hash.hpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#ifndef _LIBRARY_CRYPT_HASH_HPP_
|
||||
#define _LIBRARY_CRYPT_HASH_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "SqBase.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Simple class to maintain the state of an encoder.
|
||||
*/
|
||||
template < class T > class HashWrapper
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
HashWrapper()
|
||||
: m_Encoder()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy operator.
|
||||
*/
|
||||
HashWrapper(const HashWrapper & o)
|
||||
: m_Encoder(o.m_Encoder)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~HashWrapper()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
HashWrapper & operator = (const HashWrapper & o)
|
||||
{
|
||||
m_Encoder = o.m_Encoder;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
String ToString()
|
||||
{
|
||||
return m_Encoder.getHash();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset the encoder state.
|
||||
*/
|
||||
void Reset()
|
||||
{
|
||||
m_Encoder.reset();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Compute the hash of the specified string.
|
||||
*/
|
||||
String Compute(const String & str)
|
||||
{
|
||||
return m_Encoder(str);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the hash value of the data hashed so far.
|
||||
*/
|
||||
String GetHash()
|
||||
{
|
||||
return m_Encoder.getHash();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Add a string value to be hashed.
|
||||
*/
|
||||
void AddStr(const String & str)
|
||||
{
|
||||
m_Encoder.add(str.data(), str.length() * sizeof(String::value_type));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The managed encoder state.
|
||||
*/
|
||||
T m_Encoder;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_CRYPT_HASH_HPP_
|
||||
109
source/Library/System.cpp
Normal file
109
source/Library/System.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/System.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern void Register_SysEnv(HSQUIRRELVM vm);
|
||||
extern void Register_SysPath(HSQUIRRELVM vm);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static SQInteger SqSysExec(HSQUIRRELVM vm)
|
||||
{
|
||||
// Attempt to retrieve the value from the stack as a string
|
||||
StackStrF val(vm, 2);
|
||||
// Have we failed to retrieve the string?
|
||||
if (SQ_FAILED(val.mRes))
|
||||
{
|
||||
return val.mRes; // Propagate the error!
|
||||
}
|
||||
// Allocate a temp buffer to retrieve chunks from output
|
||||
char buffer[128];
|
||||
// Allocate a buffer which will contain the final output
|
||||
Buffer b(128);
|
||||
// Attempt to open the specified process
|
||||
FILE * pipe = popen(val.mPtr, "r");
|
||||
// The process return status
|
||||
Int32 status = -1;
|
||||
// Did we fail to open the process?
|
||||
if (!pipe)
|
||||
{
|
||||
return sq_throwerror(vm, ToStrF("Unable to open process [%s]", val.mPtr));
|
||||
}
|
||||
// Attempt to read process output
|
||||
try
|
||||
{
|
||||
while (!std::feof(pipe))
|
||||
{
|
||||
if (std::fgets(buffer, 128, pipe) != NULL)
|
||||
{
|
||||
b.AppendS(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Close the process
|
||||
status = pclose(pipe);
|
||||
// Now throw the error
|
||||
return sq_throwerror(vm, ToStrF("Unable read process output [%d]", status));
|
||||
}
|
||||
// Close the process and obtain the exit status
|
||||
status = pclose(pipe);
|
||||
// Remember the top of the stack
|
||||
const Int32 top = sq_gettop(vm);
|
||||
// Create a new table on the stack
|
||||
sq_newtable(vm);
|
||||
// Push the element name
|
||||
sq_pushstring(vm, _SC("Status"), -1);
|
||||
// Push the element value
|
||||
sq_pushinteger(vm, status);
|
||||
// Create the element in the table
|
||||
SQRESULT res = sq_rawset(vm, -3);
|
||||
// Check the result
|
||||
if (SQ_FAILED(res))
|
||||
{
|
||||
// Clean the stack
|
||||
sq_settop(vm, top);
|
||||
// Return the error
|
||||
return res;
|
||||
}
|
||||
// Push the element name
|
||||
sq_pushstring(vm, _SC("Output"), -1);
|
||||
// Push the element value
|
||||
sq_pushstring(vm, b.Get< SQChar >(), b.Position());
|
||||
// Create the element in the table
|
||||
res = sq_rawset(vm, -3);
|
||||
// Check the result
|
||||
if (SQ_FAILED(res))
|
||||
{
|
||||
// Clean the stack
|
||||
sq_settop(vm, top);
|
||||
// Return the error
|
||||
return res;
|
||||
}
|
||||
// Specify that we want to return the table we created
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_System(HSQUIRRELVM vm)
|
||||
{
|
||||
Register_SysEnv(vm);
|
||||
Register_SysPath(vm);
|
||||
|
||||
RootTable(vm).SquirrelFunc(_SC("SysExec"), &SqSysExec);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
14
source/Library/System.hpp
Normal file
14
source/Library/System.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _LIBRARY_SYSTEM_HPP_
|
||||
#define _LIBRARY_SYSTEM_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SYSTEM_HPP_
|
||||
@@ -1,5 +1,5 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/SysEnv.hpp"
|
||||
#include "Library/System/Environment.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -1,6 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/SysPath.hpp"
|
||||
#include "Library/SysEnv.hpp"
|
||||
#include "Library/System/Path.hpp"
|
||||
#include "Library/System/Environment.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,16 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Utils.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern void Register_Buffer(HSQUIRRELVM vm);
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Utils(HSQUIRRELVM vm)
|
||||
{
|
||||
Register_Buffer(vm);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -7,34 +7,7 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
class Blob
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
Blob(const Blob &);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
Blob & operator = (const Blob &);
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
Blob();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
~Blob();
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
|
||||
63
source/Library/Utils/BufferInterpreter.cpp
Normal file
63
source/Library/Utils/BufferInterpreter.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Utils/BufferInterpreter.hpp"
|
||||
#include "Library/Utils/BufferWrapper.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SharedPtr< Buffer > & GetBufferBufferRef(const BufferWrapper & buffer)
|
||||
{
|
||||
return buffer.GetRef();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < typename T > static void RegisterInterpreter(Table & bns, CSStr cname, CSStr bname)
|
||||
{
|
||||
typedef BufferInterpreter< T > Interpreter;
|
||||
|
||||
bns.Bind(bname,
|
||||
Class< Interpreter >(bns.GetVM(), cname)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Properties
|
||||
.Prop(_SC("Front"), &Interpreter::GetFront, &Interpreter::SetFront)
|
||||
.Prop(_SC("Next"), &Interpreter::GetNext, &Interpreter::SetNext)
|
||||
.Prop(_SC("Back"), &Interpreter::GetBack, &Interpreter::SetBack)
|
||||
.Prop(_SC("Prev"), &Interpreter::GetPrev, &Interpreter::SetPrev)
|
||||
.Prop(_SC("Cursor"), &Interpreter::GetCursor, &Interpreter::SetCursor)
|
||||
.Prop(_SC("Before"), &Interpreter::GetBefore, &Interpreter::SetBefore)
|
||||
.Prop(_SC("After"), &Interpreter::GetAfter, &Interpreter::SetAfter)
|
||||
.Prop(_SC("Max"), &Interpreter::GetMax)
|
||||
.Prop(_SC("Size"), &Interpreter::GetSize)
|
||||
.Prop(_SC("Capacity"), &Interpreter::GetCapacity)
|
||||
.Prop(_SC("Position"), &Interpreter::GetPosition)
|
||||
.Prop(_SC("Remaining"), &Interpreter::GetRemaining)
|
||||
// Member Methods
|
||||
.Func(_SC("Use"), &Interpreter::UseBuffer)
|
||||
.Func(_SC("Get"), &Interpreter::Get)
|
||||
.Func(_SC("Set"), &Interpreter::Set)
|
||||
.Func(_SC("Advance"), &Interpreter::Advance)
|
||||
.Func(_SC("Retreat"), &Interpreter::Retreat)
|
||||
.Func(_SC("Push"), &Interpreter::Push)
|
||||
.Func(_SC("Grow"), &Interpreter::Grow)
|
||||
.Func(_SC("Adjust"), &Interpreter::Adjust)
|
||||
);
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_BufferInterpreter(Table & bns)
|
||||
{
|
||||
RegisterInterpreter< Int8 >(bns, _SC("SqBufferInterpreterS8"), _SC("S8Interpreter"));
|
||||
RegisterInterpreter< Uint8 >(bns, _SC("SqBufferInterpreterU8"), _SC("U8Interpreter"));
|
||||
RegisterInterpreter< Int16 >(bns, _SC("SqBufferInterpreterS16"), _SC("S16Interpreter"));
|
||||
RegisterInterpreter< Uint16 >(bns, _SC("SqBufferInterpreterU16"), _SC("U16Interpreter"));
|
||||
RegisterInterpreter< Int32 >(bns, _SC("SqBufferInterpreterS32"), _SC("S32Interpreter"));
|
||||
RegisterInterpreter< Uint32 >(bns, _SC("SqBufferInterpreterU32"), _SC("U32Interpreter"));
|
||||
RegisterInterpreter< Int64 >(bns, _SC("SqBufferInterpreterS64"), _SC("S64Interpreter"));
|
||||
RegisterInterpreter< Uint64 >(bns, _SC("SqBufferInterpreterU64"), _SC("U64Interpreter"));
|
||||
RegisterInterpreter< Float32 >(bns, _SC("SqBufferInterpreterF32"), _SC("F32Interpreter"));
|
||||
RegisterInterpreter< Float64 >(bns, _SC("SqBufferInterpreterF64"), _SC("F64Interpreter"));
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
542
source/Library/Utils/BufferInterpreter.hpp
Normal file
542
source/Library/Utils/BufferInterpreter.hpp
Normal file
@@ -0,0 +1,542 @@
|
||||
#ifndef _LIBRARY_UTILS_BUFFERINTERPRETER_HPP_
|
||||
#define _LIBRARY_UTILS_BUFFERINTERPRETER_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class BufferWrapper;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Used internally to obtain a reference to the memory buffer without including the wrapper header.
|
||||
*/
|
||||
const SharedPtr< Buffer > & GetBufferBufferRef(const BufferWrapper & buffer);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Utility class used to interpret a memory buffer in different ways.
|
||||
*/
|
||||
template < typename T > class BufferInterpreter
|
||||
{
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef SharedPtr< Buffer > SRef; // Strong reference type to the interpreted memory buffer.
|
||||
typedef WeakPtr< Buffer > WRef; // Weak reference type to the interpreted memory buffer.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
WRef m_Buffer; // The interpreted memory buffer.
|
||||
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef T Value; // The type of value used to represent a byte.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Value & Reference; // A reference to the stored value type.
|
||||
typedef const Value & ConstRef; // A const reference to the stored value type.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Value * Pointer; // A pointer to the stored value type.
|
||||
typedef const Value * ConstPtr; // A const pointer to the stored value type.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Buffer::SzType SzType; // The type used to represent size in general.
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to obtain a strong reference to the memory buffer at all costs.
|
||||
*/
|
||||
SRef Validate() const
|
||||
{
|
||||
// Did the buffer that we reference expired?
|
||||
if (m_Buffer.Expired())
|
||||
{
|
||||
STHROWF("Invalid memory buffer reference");
|
||||
}
|
||||
// Obtain a strong reference to it
|
||||
return m_Buffer.Lock();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to obtain a strong reference to a valid memory buffer at all costs.
|
||||
*/
|
||||
SRef ValidateDeeper() const
|
||||
{
|
||||
// Did the buffer that we reference expired?
|
||||
if (m_Buffer.Expired())
|
||||
{
|
||||
STHROWF("Invalid memory buffer reference");
|
||||
}
|
||||
// Obtain a strong reference to it
|
||||
SRef ref = m_Buffer.Lock();
|
||||
// Validate the buffer itself
|
||||
if (!(*ref))
|
||||
{
|
||||
STHROWF("Invalid memory buffer");
|
||||
}
|
||||
// Return the reference
|
||||
return ref;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor. (null)
|
||||
*/
|
||||
BufferInterpreter()
|
||||
: m_Buffer()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
BufferInterpreter(const WRef & ref)
|
||||
: m_Buffer(ref)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
BufferInterpreter(const SRef & ref)
|
||||
: m_Buffer(ref)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
BufferInterpreter(const BufferInterpreter & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
BufferInterpreter(BufferInterpreter && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~BufferInterpreter() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
BufferInterpreter & operator = (const BufferInterpreter & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
BufferInterpreter & operator = (BufferInterpreter && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a reference to the managed memory buffer.
|
||||
*/
|
||||
const WRef & GetRef() const
|
||||
{
|
||||
return m_Buffer;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assign a different memory buffer to interpret from.
|
||||
*/
|
||||
void UseBuffer(const BufferWrapper & buffer)
|
||||
{
|
||||
m_Buffer = GetBufferBufferRef(buffer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a certain element type at the specified position.
|
||||
*/
|
||||
T Get(SzType n) const
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (n >= b->Size< T >())
|
||||
{
|
||||
STHROWF("Index (%u) is out of bounds (%u)", n, b->Size< T >());
|
||||
}
|
||||
// Return the requested element
|
||||
return b->At< T >(n);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify a certain element type at the specified position.
|
||||
*/
|
||||
void Set(SzType n, T v)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (n >= b->Size< T >())
|
||||
{
|
||||
STHROWF("Index (%u) is out of bounds (%u)", n, b->Size< T >());
|
||||
}
|
||||
// Return the requested element
|
||||
b->At< T >(n) = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element at the front of the buffer.
|
||||
*/
|
||||
T GetFront() const
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < sizeof(T))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return b->Front< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element at the front of the buffer.
|
||||
*/
|
||||
void SetFront(T v)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < sizeof(T))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
b->Front< T >() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element after the first element in the buffer.
|
||||
*/
|
||||
T GetNext() const
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < (sizeof(T) * 2))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(T), sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return b->Next< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element after the first element in the buffer.
|
||||
*/
|
||||
void SetNext(T v)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < (sizeof(T) * 2))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(T), sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
b->Next< T >() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element at the back of the buffer.
|
||||
*/
|
||||
T GetBack() const
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < sizeof(T))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return b->Back< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element at the back of the buffer.
|
||||
*/
|
||||
void SetBack(T v)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < sizeof(T))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
b->Back< T >() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element before the last element in the buffer.
|
||||
*/
|
||||
T GetPrev() const
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < (sizeof(T) * 2))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(T), sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return b->Prev< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element before the last element in the buffer.
|
||||
*/
|
||||
void SetPrev(T v)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < (sizeof(T) * 2))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(T), sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
b->Prev< T >() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reposition the edit cursor to the specified number of elements ahead.
|
||||
*/
|
||||
void Advance(SzType n)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Perform the requested operation
|
||||
b->Advance< T >(n);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reposition the edit cursor to the specified number of elements behind.
|
||||
*/
|
||||
void Retreat(SzType n)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Perform the requested operation
|
||||
b->Retreat< T >(n);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reposition the edit cursor to a fixed position within the buffer.
|
||||
*/
|
||||
void Move(SzType n)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Perform the requested operation
|
||||
b->Move< T >(n);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Append a value to the current cursor location and advance the cursor.
|
||||
*/
|
||||
void Push(T v)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Perform the requested operation
|
||||
b->Push< T >(v);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element at the cursor position.
|
||||
*/
|
||||
T GetCursor() const
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Position< T >() >= b->Size< T >())
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(T), b->Position(), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return b->Cursor< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element at the cursor position.
|
||||
*/
|
||||
void SetCursor(T v)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Position< T >() >= b->Size< T >())
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(T), b->Position(), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
b->Cursor< T >() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element before the cursor position.
|
||||
*/
|
||||
T GetBefore() const
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Position() < sizeof(T))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return b->Before< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element before the cursor position.
|
||||
*/
|
||||
void SetBefore(T v)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Position() < sizeof(T))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(T), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
b->Before< T >() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element after the cursor position.
|
||||
*/
|
||||
T GetAfter() const
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < sizeof(T) || (b->Position() + sizeof(T)) > (b->Capacity() - sizeof(T)))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(T), b->Position(), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return b->After< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element after the cursor position.
|
||||
*/
|
||||
void SetAfter(T v)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Are we out of the memory buffer range?
|
||||
if (b->Capacity() < sizeof(T) || (b->Position() + sizeof(T)) > (b->Capacity() - sizeof(T)))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(T), b->Position(), b->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
b->After< T >() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve maximum elements it can hold for a certain type.
|
||||
*/
|
||||
SzType GetMax() const
|
||||
{
|
||||
return Buffer::Max< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current buffer capacity in element count.
|
||||
*/
|
||||
SzType GetSize() const
|
||||
{
|
||||
return Validate()->template Size< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current buffer capacity in byte count.
|
||||
*/
|
||||
SzType GetCapacity() const
|
||||
{
|
||||
return Validate()->Capacity();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current position of the cursor in the buffer.
|
||||
*/
|
||||
SzType GetPosition() const
|
||||
{
|
||||
return Validate()->template Position< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the amount of unused buffer after the edit cursor.
|
||||
*/
|
||||
SzType GetRemaining() const
|
||||
{
|
||||
return Validate()->template Remaining< T >();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Grow the size of the internal buffer by the specified amount of bytes.
|
||||
*/
|
||||
void Grow(SzType n)
|
||||
{
|
||||
return Validate()->Grow(n * sizeof(T));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Makes sure there is enough capacity to hold the specified element count.
|
||||
*/
|
||||
void Adjust(SzType n)
|
||||
{
|
||||
// Acquire a reference to the memory buffer
|
||||
SRef b(Validate());
|
||||
// Attempt to perform the requested operation
|
||||
try
|
||||
{
|
||||
Buffer bkp(b->Adjust(n * sizeof(T)));
|
||||
// Copy the data into the new buffer
|
||||
b->Write(0, bkp.Data(), bkp.Capacity());
|
||||
b->Move(bkp.Position());
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
STHROWF("%s", e.what()); // Re-package
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_UTILS_BUFFERINTERPRETER_HPP_
|
||||
357
source/Library/Utils/BufferWrapper.cpp
Normal file
357
source/Library/Utils/BufferWrapper.cpp
Normal file
@@ -0,0 +1,357 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Utils/BufferWrapper.hpp"
|
||||
#include "Library/Utils/BufferInterpreter.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstring>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern void Register_BufferInterpreter(Table & bns);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object BufferWrapper::Create(SzType n)
|
||||
{
|
||||
// Attempt to create the requested buffer
|
||||
try
|
||||
{
|
||||
return MakeObject(BufferWrapper(SRef(new Buffer(n))));
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
throw e; // Re-throw
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
STHROWF("%s", e.what()); // Re-package
|
||||
}
|
||||
// Shouldn't really reach this point
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void BufferWrapper::WriteByte(SQInteger val)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
m_Buffer->Push< Uint8 >(ConvTo< Uint8 >::From(val));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void BufferWrapper::WriteShort(SQInteger val)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
m_Buffer->Push< Int16 >(ConvTo< Int16 >::From(val));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void BufferWrapper::WriteInt(SQInteger val)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
m_Buffer->Push< Int32 >(ConvTo< Int32 >::From(val));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void BufferWrapper::WriteFloat(SQFloat val)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
m_Buffer->Push< Float32 >(ConvTo< Float32 >::From(val));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void BufferWrapper::WriteString(CSStr val)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Is the given string value even valid?
|
||||
if (!val)
|
||||
{
|
||||
STHROWF("Invalid string argument: null");
|
||||
}
|
||||
// Calculate the string length
|
||||
Uint16 length = ConvTo< Uint16 >::From(std::strlen(val));
|
||||
// Change the size endianness to big endian
|
||||
Uint16 size = ((length >> 8) & 0xFF) | ((length & 0xFF) << 8);
|
||||
// Write the size and then the string contents
|
||||
m_Buffer->Push< Uint16 >(size);
|
||||
m_Buffer->AppendS(val, length);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void BufferWrapper::WriteRawString(CSStr val)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Is the given string value even valid?
|
||||
if (!val)
|
||||
{
|
||||
STHROWF("Invalid string argument: null");
|
||||
}
|
||||
// Calculate the string length
|
||||
Uint16 length = ConvTo< Uint16 >::From(std::strlen(val));
|
||||
// Write the the string contents
|
||||
m_Buffer->AppendS(val, length);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger BufferWrapper::ReadByte()
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
ValidateDeeper();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Position< Int8 >() >= m_Buffer->Size< Int8 >())
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Int8), m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Read one element from the buffer
|
||||
const Int8 value = m_Buffer->Cursor< Int8 >();
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Int8 >(1);
|
||||
// Return the requested information
|
||||
return value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger BufferWrapper::ReadShort()
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
ValidateDeeper();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Position< Int16 >() >= m_Buffer->Size< Int16 >())
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Int16), m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Read one element from the buffer
|
||||
const Int16 value = m_Buffer->Cursor< Int16 >();
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Int16 >(1);
|
||||
// Return the requested information
|
||||
return value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger BufferWrapper::ReadInt()
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
ValidateDeeper();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Position< Int32 >() >= m_Buffer->Size< Int32 >())
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Int32), m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Read one element from the buffer
|
||||
const Int32 value = m_Buffer->Cursor< Int32 >();
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Int32 >(1);
|
||||
// Return the requested information
|
||||
return value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQFloat BufferWrapper::ReadFloat()
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
ValidateDeeper();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Position< Float32 >() >= m_Buffer->Size< Float32 >())
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Float32), m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Read one element from the buffer
|
||||
const Float32 value = m_Buffer->Cursor< Float32 >();
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Float32 >(1);
|
||||
// Return the requested information
|
||||
return value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object BufferWrapper::ReadString()
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
ValidateDeeper();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Position< Int16 >() >= m_Buffer->Size< Int16 >())
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Int16), m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Read one element from the buffer
|
||||
Int16 length = m_Buffer->Cursor< Int16 >();
|
||||
// Convert the length to little endian
|
||||
length = ((length >> 8) & 0xFF) | ((length & 0xFF) << 8);
|
||||
// Validate the obtained length
|
||||
if ((m_Buffer->Position() + sizeof(Int16) + length) >= m_Buffer->Size())
|
||||
{
|
||||
STHROWF("String size (%u starting at %u) is out of bounds (%u)",
|
||||
length, m_Buffer->Position() + sizeof(Int16), m_Buffer->Capacity());
|
||||
}
|
||||
// Advance the buffer to the actual string
|
||||
m_Buffer->Advance< Int16 >(1);
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Attempt to create the string as an object
|
||||
sq_pushstring(DefaultVM::Get(), &m_Buffer->Cursor(), length);
|
||||
// Advance the cursor after the string
|
||||
m_Buffer->Advance(length);
|
||||
// Return the resulted object
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object BufferWrapper::ReadRawString(Uint32 len)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
ValidateDeeper();
|
||||
// Validate the obtained length
|
||||
if ((m_Buffer->Position() + len) >= m_Buffer->Size())
|
||||
{
|
||||
STHROWF("String size (%u starting at %u) is out of bounds (%u)",
|
||||
len, m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Attempt to create the string as an object
|
||||
sq_pushstring(DefaultVM::Get(), &m_Buffer->Cursor(), len);
|
||||
// Advance the cursor after the string
|
||||
m_Buffer->Advance(len);
|
||||
// Return the resulted object
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Int8 > BufferWrapper::GetInt8Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Int8 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Uint8 > BufferWrapper::GetUint8Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Uint8 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Int16 > BufferWrapper::GetInt16Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Int16 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Uint16 > BufferWrapper::GetUint16Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Uint16 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Int32 > BufferWrapper::GetInt32Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Int32 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Uint32 > BufferWrapper::GetUint32Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Uint32 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Int64 > BufferWrapper::GetInt64Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Int64 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Uint64 > BufferWrapper::GetUint64Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Uint64 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Float32 > BufferWrapper::GetFloat32Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Float32 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BufferInterpreter< Float64 > BufferWrapper::GetFloat64Interpreter() const
|
||||
{
|
||||
return BufferInterpreter< Float64 >(m_Buffer);
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Buffer(HSQUIRRELVM vm)
|
||||
{
|
||||
Table bns(vm);
|
||||
|
||||
bns.Bind(_SC("Wrapper"),
|
||||
Class< BufferWrapper >(vm, _SC("SqBufferWrapper"))
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Properties
|
||||
.Prop(_SC("Front"), &BufferWrapper::GetFront, &BufferWrapper::SetFront)
|
||||
.Prop(_SC("Next"), &BufferWrapper::GetNext, &BufferWrapper::SetNext)
|
||||
.Prop(_SC("Back"), &BufferWrapper::GetBack, &BufferWrapper::SetBack)
|
||||
.Prop(_SC("Prev"), &BufferWrapper::GetPrev, &BufferWrapper::SetPrev)
|
||||
.Prop(_SC("Cursor"), &BufferWrapper::GetCursor, &BufferWrapper::SetCursor)
|
||||
.Prop(_SC("Before"), &BufferWrapper::GetBefore, &BufferWrapper::SetBefore)
|
||||
.Prop(_SC("After"), &BufferWrapper::GetAfter, &BufferWrapper::SetAfter)
|
||||
.Prop(_SC("Max"), &BufferWrapper::GetMax)
|
||||
.Prop(_SC("Size"), &BufferWrapper::GetSize)
|
||||
.Prop(_SC("Capacity"), &BufferWrapper::GetCapacity)
|
||||
.Prop(_SC("Position"), &BufferWrapper::GetPosition)
|
||||
.Prop(_SC("Remaining"), &BufferWrapper::GetRemaining)
|
||||
.Prop(_SC("Int8"), &BufferWrapper::GetInt8Interpreter)
|
||||
.Prop(_SC("Uint8"), &BufferWrapper::GetUint8Interpreter)
|
||||
.Prop(_SC("Int16"), &BufferWrapper::GetInt16Interpreter)
|
||||
.Prop(_SC("Uint16"), &BufferWrapper::GetUint16Interpreter)
|
||||
.Prop(_SC("Int32"), &BufferWrapper::GetInt32Interpreter)
|
||||
.Prop(_SC("Uint32"), &BufferWrapper::GetUint32Interpreter)
|
||||
.Prop(_SC("Int64"), &BufferWrapper::GetInt64Interpreter)
|
||||
.Prop(_SC("Uint64"), &BufferWrapper::GetUint64Interpreter)
|
||||
.Prop(_SC("Float32"), &BufferWrapper::GetFloat32Interpreter)
|
||||
.Prop(_SC("Float64"), &BufferWrapper::GetFloat64Interpreter)
|
||||
// Member Methods
|
||||
.Func(_SC("Get"), &BufferWrapper::Get)
|
||||
.Func(_SC("Set"), &BufferWrapper::Set)
|
||||
.Func(_SC("Advance"), &BufferWrapper::Advance)
|
||||
.Func(_SC("Retreat"), &BufferWrapper::Retreat)
|
||||
.Func(_SC("Push"), &BufferWrapper::Push)
|
||||
.Func(_SC("Grow"), &BufferWrapper::Grow)
|
||||
.Func(_SC("Adjust"), &BufferWrapper::Adjust)
|
||||
.Func(_SC("WriteByte"), &BufferWrapper::WriteByte)
|
||||
.Func(_SC("WriteShort"), &BufferWrapper::WriteShort)
|
||||
.Func(_SC("WriteInt"), &BufferWrapper::WriteInt)
|
||||
.Func(_SC("WriteFloat"), &BufferWrapper::WriteFloat)
|
||||
.Func(_SC("WriteString"), &BufferWrapper::WriteString)
|
||||
.Func(_SC("WriteRawString"), &BufferWrapper::WriteRawString)
|
||||
.Func(_SC("ReadByte"), &BufferWrapper::ReadByte)
|
||||
.Func(_SC("ReadShort"), &BufferWrapper::ReadShort)
|
||||
.Func(_SC("ReadInt"), &BufferWrapper::ReadInt)
|
||||
.Func(_SC("ReadFloat"), &BufferWrapper::ReadFloat)
|
||||
.Func(_SC("ReadString"), &BufferWrapper::ReadString)
|
||||
.Func(_SC("ReadRawString"), &BufferWrapper::ReadRawString)
|
||||
);
|
||||
|
||||
Register_BufferInterpreter(bns);
|
||||
|
||||
bns.Func(_SC("Create"), &BufferWrapper::Create);
|
||||
|
||||
RootTable(vm).Bind(_SC("SqBuffer"), bns);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
644
source/Library/Utils/BufferWrapper.hpp
Normal file
644
source/Library/Utils/BufferWrapper.hpp
Normal file
@@ -0,0 +1,644 @@
|
||||
#ifndef _LIBRARY_UTILS_BUFFERWRAPPER_HPP_
|
||||
#define _LIBRARY_UTILS_BUFFERWRAPPER_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < typename T > class BufferInterpreter;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Squirrel wrapper for the shared buffer class.
|
||||
*/
|
||||
class BufferWrapper
|
||||
{
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef SharedPtr< Buffer > SRef; // Strong reference type to the managed memory buffer.
|
||||
typedef WeakPtr< Buffer > WRef; // Weak reference type to the managed memory buffer.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
SRef m_Buffer; // The managed memory buffer.
|
||||
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Buffer::Value Value; // The type of value used to represent a byte.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Value & Reference; // A reference to the stored value type.
|
||||
typedef const Value & ConstRef; // A const reference to the stored value type.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Value * Pointer; // A pointer to the stored value type.
|
||||
typedef const Value * ConstPtr; // A const pointer to the stored value type.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Buffer::SzType SzType; // The type used to represent size in general.
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create a memory buffer with the requested size.
|
||||
*/
|
||||
static Object Create(SzType n);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
BufferWrapper(const SRef & ref)
|
||||
: m_Buffer(ref)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Buffer constructor.
|
||||
*/
|
||||
BufferWrapper(Buffer && b)
|
||||
: m_Buffer(new Buffer(std::move(b)))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
BufferWrapper(const BufferWrapper & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
BufferWrapper(BufferWrapper && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~BufferWrapper() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
BufferWrapper & operator = (const BufferWrapper & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
BufferWrapper & operator = (BufferWrapper && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a reference to the managed memory buffer.
|
||||
*/
|
||||
const SRef & GetRef() const
|
||||
{
|
||||
return m_Buffer;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed memory buffer reference.
|
||||
*/
|
||||
void Validate() const
|
||||
{
|
||||
// Do we even point to a valid buffer?
|
||||
if (!m_Buffer)
|
||||
{
|
||||
STHROWF("Invalid memory buffer reference");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed memory buffer reference and the buffer itself.
|
||||
*/
|
||||
void ValidateDeeper() const
|
||||
{
|
||||
// Do we even point to a valid buffer?
|
||||
if (!m_Buffer)
|
||||
{
|
||||
STHROWF("Invalid memory buffer reference");
|
||||
}
|
||||
// Validate the buffer itself
|
||||
else if (!(*m_Buffer))
|
||||
{
|
||||
STHROWF("Invalid memory buffer");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a certain element type at the specified position.
|
||||
*/
|
||||
Value Get(SzType n) const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (n >= m_Buffer->Size())
|
||||
{
|
||||
STHROWF("Index (%u) is out of bounds (%u)", n, m_Buffer->Size());
|
||||
}
|
||||
// Return the requested element
|
||||
return m_Buffer->At(n);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify a certain element type at the specified position.
|
||||
*/
|
||||
void Set(SzType n, Value v)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (n >= m_Buffer->Size())
|
||||
{
|
||||
STHROWF("Index (%u) is out of bounds (%u)", n, m_Buffer->Size());
|
||||
}
|
||||
// Return the requested element
|
||||
m_Buffer->At(n) = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element at the front of the buffer.
|
||||
*/
|
||||
Value GetFront() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < sizeof(Value))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return m_Buffer->Front();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element at the front of the buffer.
|
||||
*/
|
||||
void SetFront(Value v)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < sizeof(Value))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
m_Buffer->Front() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element after the first element in the buffer.
|
||||
*/
|
||||
Value GetNext() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < (sizeof(Value) * 2))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Value), sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return m_Buffer->Next();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element after the first element in the buffer.
|
||||
*/
|
||||
void SetNext(Value v)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < (sizeof(Value) * 2))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Value), sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
m_Buffer->Next() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element at the back of the buffer.
|
||||
*/
|
||||
Value GetBack() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < sizeof(Value))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return m_Buffer->Back();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element at the back of the buffer.
|
||||
*/
|
||||
void SetBack(Value v)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < sizeof(Value))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
m_Buffer->Back() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element before the last element in the buffer.
|
||||
*/
|
||||
Value GetPrev() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < (sizeof(Value) * 2))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Value), sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return m_Buffer->Prev();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element before the last element in the buffer.
|
||||
*/
|
||||
void SetPrev(Value v)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < (sizeof(Value) * 2))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Value), sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
m_Buffer->Prev() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reposition the edit cursor to the specified number of elements ahead.
|
||||
*/
|
||||
void Advance(SzType n)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
m_Buffer->Advance(n);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reposition the edit cursor to the specified number of elements behind.
|
||||
*/
|
||||
void Retreat(SzType n)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
m_Buffer->Retreat(n);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reposition the edit cursor to a fixed position within the buffer.
|
||||
*/
|
||||
void Move(SzType n)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
m_Buffer->Move(n);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Append a value to the current cursor location and advance the cursor.
|
||||
*/
|
||||
void Push(Value v)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
m_Buffer->Push(v);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element at the cursor position.
|
||||
*/
|
||||
Value GetCursor() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Position() >= m_Buffer->Size())
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return m_Buffer->Cursor();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element at the cursor position.
|
||||
*/
|
||||
void SetCursor(Value v)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Position() >= m_Buffer->Size())
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
m_Buffer->Cursor() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element before the cursor position.
|
||||
*/
|
||||
Value GetBefore() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Position() < sizeof(Value))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return m_Buffer->Before();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element before the cursor position.
|
||||
*/
|
||||
void SetBefore(Value v)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Position() < sizeof(Value))
|
||||
{
|
||||
STHROWF("Value size (%u starting at 0) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
m_Buffer->Before() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the element after the cursor position.
|
||||
*/
|
||||
Value GetAfter() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < sizeof(Value) ||
|
||||
(m_Buffer->Position() + sizeof(Value)) > (m_Buffer->Capacity() - sizeof(Value)))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
return m_Buffer->After();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the element after the cursor position.
|
||||
*/
|
||||
void SetAfter(Value v)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Are we out of the memory buffer range?
|
||||
if (m_Buffer->Capacity() < sizeof(Value) ||
|
||||
(m_Buffer->Position() + sizeof(Value)) > (m_Buffer->Capacity() - sizeof(Value)))
|
||||
{
|
||||
STHROWF("Value size (%u starting at %u) is out of bounds (%u)",
|
||||
sizeof(Value), m_Buffer->Position(), m_Buffer->Capacity());
|
||||
}
|
||||
// Return the requested element
|
||||
m_Buffer->After() = v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve maximum elements it can hold for a certain type.
|
||||
*/
|
||||
SzType GetMax() const
|
||||
{
|
||||
return Buffer::Max();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current buffer capacity in element count.
|
||||
*/
|
||||
SzType GetSize() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return m_Buffer->Size();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current buffer capacity in byte count.
|
||||
*/
|
||||
SzType GetCapacity() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return m_Buffer->Capacity();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current position of the cursor in the buffer.
|
||||
*/
|
||||
SzType GetPosition() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return m_Buffer->Position();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the amount of unused buffer after the edit cursor.
|
||||
*/
|
||||
SzType GetRemaining() const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return m_Buffer->Remaining();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Grow the size of the internal buffer by the specified amount of bytes.
|
||||
*/
|
||||
void Grow(SzType n)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return m_Buffer->Grow(n * sizeof(Value));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Makes sure there is enough capacity to hold the specified element count.
|
||||
*/
|
||||
void Adjust(SzType n)
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
Validate();
|
||||
// Attempt to perform the requested operation
|
||||
try
|
||||
{
|
||||
Buffer bkp(m_Buffer->Adjust(n * sizeof(Value)));
|
||||
// Copy the data into the new buffer
|
||||
m_Buffer->Write(0, bkp.Data(), bkp.Capacity());
|
||||
m_Buffer->Move(bkp.Position());
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
STHROWF("%s", e.what()); // Re-package
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a 8 bit byte to the stream buffer.
|
||||
*/
|
||||
void WriteByte(SQInteger val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a 16 bit short to the stream buffer.
|
||||
*/
|
||||
void WriteShort(SQInteger val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a 32 bit integer to the stream buffer.
|
||||
*/
|
||||
void WriteInt(SQInteger val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a 32 bit float to the stream buffer.
|
||||
*/
|
||||
void WriteFloat(SQFloat val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a string to the stream buffer.
|
||||
*/
|
||||
void WriteString(CSStr val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a raw string to the stream buffer.
|
||||
*/
|
||||
void WriteRawString(CSStr val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Read a 8 bit byte to the stream buffer.
|
||||
*/
|
||||
SQInteger ReadByte();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Read a 16 bit short to the stream buffer.
|
||||
*/
|
||||
SQInteger ReadShort();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Read a 32 bit integer to the stream buffer.
|
||||
*/
|
||||
SQInteger ReadInt();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Read a 32 bit float to the stream buffer.
|
||||
*/
|
||||
SQFloat ReadFloat();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Read a string to the stream buffer.
|
||||
*/
|
||||
Object ReadString();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Read a raw string to the stream buffer.
|
||||
*/
|
||||
Object ReadRawString(Uint32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a signed 8 bit interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Int8 > GetInt8Interpreter() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve an unsigned 8 bit interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Uint8 > GetUint8Interpreter() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a signed 16 bit interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Int16 > GetInt16Interpreter() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve an unsigned 16 bit interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Uint16 > GetUint16Interpreter() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a signed 32 bit interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Int32 > GetInt32Interpreter() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve an unsigned 32 bit interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Uint32 > GetUint32Interpreter() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a signed 64 bit interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Int64 > GetInt64Interpreter() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve an unsigned 64 bit interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Uint64 > GetUint64Interpreter() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a 32 bit floating point interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Float32 > GetFloat32Interpreter() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a 64 bit floating point interpreter to this buffer.
|
||||
*/
|
||||
BufferInterpreter< Float64 > GetFloat64Interpreter() const;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_UTILS_BUFFERWRAPPER_HPP_
|
||||
@@ -1,22 +1,26 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Logger.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctime>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace {
|
||||
#include <sqrat.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <Windows.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Common windows colors.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
@@ -38,84 +42,188 @@ enum
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Logging colors.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
LC_DBG = LC_LIGHT_BLUE,
|
||||
LC_USER = LC_GRAY,
|
||||
LC_USR = LC_GRAY,
|
||||
LC_SCS = LC_LIGHT_GREEN,
|
||||
LC_INF = LC_LIGHT_CYAN,
|
||||
LC_WRN = LC_LIGHT_YELLOW,
|
||||
LC_ERR = LC_LIGHT_MAGENTA,
|
||||
LC_FTL = LC_LIGHT_RED
|
||||
LC_ERR = LC_LIGHT_RED,
|
||||
LC_FTL = LC_LIGHT_MAGENTA
|
||||
};
|
||||
|
||||
#endif // SQMOD_OS_WINDOWS
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Identify the associated message color.
|
||||
*/
|
||||
inline WORD GetLevelColor(BYTE level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case SqMod::LOGL_DBG: return LC_DBG;
|
||||
case SqMod::LOGL_USR: return LC_USR;
|
||||
case SqMod::LOGL_SCS: return LC_SCS;
|
||||
case SqMod::LOGL_INF: return LC_INF;
|
||||
case SqMod::LOGL_WRN: return LC_WRN;
|
||||
case SqMod::LOGL_ERR: return LC_ERR;
|
||||
case SqMod::LOGL_FTL: return LC_FTL;
|
||||
default: return LC_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
} // Namespace::
|
||||
|
||||
#endif // SQMOD_OS_WINDOWS
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
SQMOD_MANAGEDPTR_TYPE(Logger) _Log = SQMOD_MANAGEDPTR_MAKE(Logger, nullptr);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Identify the message prefix.
|
||||
*/
|
||||
inline CCStr GetLevelTag(Uint8 type)
|
||||
static inline CCStr GetLevelTag(Uint8 level)
|
||||
{
|
||||
switch (type)
|
||||
switch (level)
|
||||
{
|
||||
case LL_DBG: return "[DBG]";
|
||||
case LL_USR: return "[USR]";
|
||||
case LL_SCS: return "[SCS]";
|
||||
case LL_INF: return "[INF]";
|
||||
case LL_WRN: return "[WRN]";
|
||||
case LL_ERR: return "[ERR]";
|
||||
case LL_FTL: return "[FTL]";
|
||||
case LOGL_DBG: return "[DBG]";
|
||||
case LOGL_USR: return "[USR]";
|
||||
case LOGL_SCS: return "[SCS]";
|
||||
case LOGL_INF: return "[INF]";
|
||||
case LOGL_WRN: return "[WRN]";
|
||||
case LOGL_ERR: return "[ERR]";
|
||||
case LOGL_FTL: return "[FTL]";
|
||||
default: return "[UNK]";
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Identify the message prefix and color.
|
||||
*/
|
||||
inline Uint16 GetLevelColor(Uint8 type)
|
||||
static inline CCStr GetColoredLevelTag(Uint8 level)
|
||||
{
|
||||
switch (type)
|
||||
switch (level)
|
||||
{
|
||||
case LL_DBG: return LC_DBG;
|
||||
case LL_USR: return LC_USER;
|
||||
case LL_SCS: return LC_SCS;
|
||||
case LL_INF: return LC_INF;
|
||||
case LL_WRN: return LC_WRN;
|
||||
case LL_ERR: return LC_ERR;
|
||||
case LL_FTL: return LC_FTL;
|
||||
default: return LC_NORMAL;
|
||||
case LOGL_DBG: return "\033[21;94m[[DBG]\033[0m";
|
||||
case LOGL_USR: return "\033[21;37m[[USR]\033[0m";
|
||||
case LOGL_SCS: return "\033[21;92m[[SCS]\033[0m";
|
||||
case LOGL_INF: return "\033[21;96m[[INF]\033[0m";
|
||||
case LOGL_WRN: return "\033[21;93m[[WRN]\033[0m";
|
||||
case LOGL_ERR: return "\033[21;91m[[ERR]\033[0m";
|
||||
case LOGL_FTL: return "\033[21;95m[[FTL]\033[0m";
|
||||
default: return "\033[21;0m[[UNK]\033[0m";
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Output a logging message to the console window.
|
||||
*/
|
||||
inline CCStr GetLevelColor(Uint8 /*type*/)
|
||||
static inline void OutputConsoleMessage(Uint8 level, bool sub, CCStr tms, CCStr msg)
|
||||
{
|
||||
return g_EmptyStr;
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_state;
|
||||
GetConsoleScreenBufferInfo(hstdout, &csb_state);
|
||||
SetConsoleTextAttribute(hstdout, GetLevelColor(level));
|
||||
if (tms)
|
||||
{
|
||||
std::printf("%s %s ", GetLevelTag(level), tms);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::printf("%s ", GetLevelTag(level));
|
||||
}
|
||||
SetConsoleTextAttribute(hstdout, sub ? LC_NORMAL : LC_WHITE);
|
||||
std::puts(msg);
|
||||
SetConsoleTextAttribute(hstdout, csb_state.wAttributes);
|
||||
#else
|
||||
if (tms)
|
||||
{
|
||||
std::printf("%s %s ", GetColoredLevelTag(level), tms);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::printf("%s ", GetColoredLevelTag(level));
|
||||
}
|
||||
std::puts(msg);
|
||||
#endif // SQMOD_OS_WINDOWS
|
||||
}
|
||||
|
||||
#endif // SQMOD_OS_WINDOWS
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Raw console message output.
|
||||
*/
|
||||
static inline void OutputMessageImpl(CCStr msg, va_list args)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
|
||||
std::printf("[SQMOD] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
std::vprintf(msg, args);
|
||||
std::puts("");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
||||
#else
|
||||
std::printf("\033[21;32m[SQMOD]\033[0m");
|
||||
std::vprintf(msg, args);
|
||||
std::puts("");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Raw console error output.
|
||||
*/
|
||||
static inline void OutputErrorImpl(CCStr msg, va_list args)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
std::printf("[SQMOD] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
std::vprintf(msg, args);
|
||||
std::puts("");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
||||
#else
|
||||
std::printf("\033[21;91m[SQMOD]\033[0m");
|
||||
std::vprintf(msg, args);
|
||||
std::puts("");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Identify the associated message color.
|
||||
*/
|
||||
static inline CCStr GetTimeStampStr()
|
||||
{
|
||||
static CharT tmbuff[80];
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::strftime(tmbuff, sizeof(tmbuff), "%Y-%m-%d %H:%M:%S", std::localtime(&t));
|
||||
// Return the resulted buffer
|
||||
return tmbuff;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Logger Logger::s_Inst;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Logger::Logger()
|
||||
: m_Buffer(4096)
|
||||
, m_TmBuff()
|
||||
, m_Levels(LL_ANY)
|
||||
, m_Time(false)
|
||||
: m_Buffer()
|
||||
, m_ConsoleLevels(LOGL_ANY)
|
||||
, m_LogFileLevels(~LOGL_DBG)
|
||||
, m_ConsoleTime(false)
|
||||
, m_LogFileTime(true)
|
||||
, m_File(nullptr)
|
||||
, m_Filename()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@@ -123,57 +231,174 @@ Logger::Logger()
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Logger::~Logger()
|
||||
{
|
||||
/* ... */
|
||||
Close();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Send(Uint8 type, bool sub, CCStr fmt, va_list args)
|
||||
void Logger::Close()
|
||||
{
|
||||
if (!(m_Levels & type))
|
||||
return;
|
||||
m_Buffer.WriteF(0, fmt, args);
|
||||
Proccess(type, sub);
|
||||
// Is there a file handle to close?
|
||||
if (m_File)
|
||||
{
|
||||
// Flush buffered data
|
||||
std::fflush(m_File);
|
||||
// Close the file handle
|
||||
std::fclose(m_File);
|
||||
// Prevent further use of this file handle
|
||||
m_File = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Message(Uint8 type, bool sub, CCStr fmt, ...)
|
||||
void Logger::SetLogFilename(CCStr filename)
|
||||
{
|
||||
if (!(m_Levels & type))
|
||||
return;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
m_Buffer.WriteF(0, fmt, args);
|
||||
Proccess(type, sub);
|
||||
va_end(args);
|
||||
// Close the current logging file, if any
|
||||
Close();
|
||||
// Clear the current name
|
||||
m_Filename.clear();
|
||||
// Was there a name specified?
|
||||
if (!filename || *filename == '\0')
|
||||
{
|
||||
return; // We're done here!
|
||||
}
|
||||
// Make sure the internal buffer has some memory
|
||||
m_Buffer.Adjust(1024);
|
||||
// Generate the filename using the current timestamp
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::strftime(m_Buffer.Data(), m_Buffer.Size(), filename, std::localtime(&t));
|
||||
// Is the resulted filename valid?
|
||||
if (m_Buffer.At(0) != '\0')
|
||||
{
|
||||
m_Filename.assign(m_Buffer.Data());
|
||||
}
|
||||
else
|
||||
{
|
||||
return; // We're done here!
|
||||
}
|
||||
// Attempt to open the file for writing
|
||||
m_File = std::fopen(m_Filename.c_str(), "w");
|
||||
// See if the file could be opened
|
||||
if (!m_File)
|
||||
{
|
||||
OutputError("Unable to open the log file (%s) : %s", m_Filename.c_str(), std::strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Initialize(CCStr filename)
|
||||
{
|
||||
// Close the logging file
|
||||
Close();
|
||||
// Allocate some memory in the buffer
|
||||
m_Buffer.Adjust(1024);
|
||||
// Set the log file name and open the file if necessary
|
||||
SetLogFilename(filename);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Terminate()
|
||||
{
|
||||
// Release all the buffer resources and references
|
||||
m_Buffer.ResetAll();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Proccess(Uint8 level, bool sub)
|
||||
{
|
||||
// Obtain the time-stamp if necessary
|
||||
CCStr tms = (m_ConsoleTime || m_LogFileTime) ? GetTimeStampStr() : nullptr;
|
||||
// Are we allowed to send this message level to console?
|
||||
if (m_ConsoleLevels & level)
|
||||
{
|
||||
OutputConsoleMessage(level, sub, (m_ConsoleTime ? tms : nullptr), m_Buffer.Get());
|
||||
}
|
||||
// Are we allowed to write it to a file?
|
||||
if (m_File && (m_LogFileLevels & level))
|
||||
{
|
||||
// Write the level tag
|
||||
std::fputs(GetLevelTag(level), m_File);
|
||||
std::fputc(' ', m_File);
|
||||
// Should we include the time-stamp?
|
||||
if (m_LogFileTime && tms)
|
||||
{
|
||||
std::fputs(tms, m_File);
|
||||
std::fputc(' ', m_File);
|
||||
}
|
||||
// Write the message
|
||||
std::fputs(m_Buffer.Get(), m_File);
|
||||
// Append a new line
|
||||
std::fputc('\n', m_File);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Send(Uint8 level, bool sub, CCStr fmt, va_list args)
|
||||
{
|
||||
// Is this level even allowed?
|
||||
if ((m_ConsoleLevels & level) || (m_LogFileLevels & level))
|
||||
{
|
||||
// Generate the message in the buffer
|
||||
m_Buffer.WriteF(0, fmt, args);
|
||||
// Process the message in the buffer
|
||||
Proccess(level, sub);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Write(Uint8 level, bool sub, CCStr fmt, ...)
|
||||
{
|
||||
if ((m_ConsoleLevels & level) || (m_LogFileLevels & level))
|
||||
{
|
||||
// Initialize the variable argument list
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
// Generate the message in the buffer
|
||||
m_Buffer.WriteF(0, fmt, args);
|
||||
// Finalize the variable argument list
|
||||
va_end(args);
|
||||
// Process the message in the buffer
|
||||
Proccess(level, sub);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Debug(CCStr fmt, ...)
|
||||
{
|
||||
// Initialize the variable argument list
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
// Forward the call to the actual debug function
|
||||
Debug(fmt, args);
|
||||
// Finalize the variable argument list
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Logger::Debug(CCStr fmt, va_list args)
|
||||
{
|
||||
using namespace Sqrat;
|
||||
// Retrieve the default Squirrel VM
|
||||
HSQUIRRELVM vm = DefaultVM::Get();
|
||||
// Used to acquire
|
||||
SQStackInfos si;
|
||||
// Write the message to the buffer
|
||||
Int32 ret = m_Buffer.WriteF(0, fmt, args);
|
||||
|
||||
// Obtain information about the current stack level
|
||||
if (SQ_SUCCEEDED(sq_stackinfos(vm, 1, &si)))
|
||||
{
|
||||
m_Buffer.WriteF(ret, "\n[\n=>Location: %s\n=>Line: %d\n=>Function: %s\n]"
|
||||
, si.source ? si.source : _SC("unknown")
|
||||
, si.line
|
||||
, si.funcname ? si.funcname : _SC("unknown"));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Buffer.WriteF(ret, "\n[\n=>Location: unknown\n=>Line: unknown\n=>Function: unknown\n]");
|
||||
|
||||
Proccess(LL_ERR, true);
|
||||
|
||||
}
|
||||
// Process the message in the buffer
|
||||
Proccess(LOGL_ERR, true);
|
||||
// Begin the traceback process
|
||||
ret = m_Buffer.WriteF(0, "Traceback:\n[\n");
|
||||
|
||||
// Traceback the function call
|
||||
for (Int32 level = 1; SQ_SUCCEEDED(sq_stackinfos(vm, level, &si)); ++level)
|
||||
{
|
||||
ret += m_Buffer.WriteF(ret, "=> [%d] %s (%d) [%s]\n", level
|
||||
@@ -181,20 +406,22 @@ void Logger::Debug(CCStr fmt, va_list args)
|
||||
, si.line
|
||||
, si.funcname ? si.funcname : _SC("unknown"));
|
||||
}
|
||||
|
||||
// End the function call traceback
|
||||
m_Buffer.WriteF(ret, "]");
|
||||
Proccess(LL_INF, true);
|
||||
|
||||
CCStr s_ = 0, name = 0;
|
||||
// Process the message in the buffer
|
||||
Proccess(LOGL_INF, true);
|
||||
// Temporary variables to retrieve stack information
|
||||
CSStr s_ = 0, name = 0;
|
||||
SQInteger i_, seq = 0;
|
||||
SQFloat f_;
|
||||
SQUserPointer p_;
|
||||
|
||||
// Begin the local variables information
|
||||
ret = m_Buffer.WriteF(0, "Locals:\n[\n");
|
||||
|
||||
// Process each stack level
|
||||
for (Int32 level = 0; level < 10; level++)
|
||||
{
|
||||
seq = 0;
|
||||
// Display all locals in the current stack level
|
||||
while((name = sq_getlocal(vm, level, seq)))
|
||||
{
|
||||
++seq;
|
||||
@@ -260,43 +487,10 @@ void Logger::Debug(CCStr fmt, va_list args)
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// End the variables information
|
||||
m_Buffer.WriteF(ret, "]");
|
||||
Proccess(LL_INF, true);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Proccess(Uint8 type, bool sub)
|
||||
{
|
||||
if (m_Time)
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
strftime(m_TmBuff, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
|
||||
}
|
||||
else
|
||||
m_TmBuff[0] = 0;
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_state;
|
||||
GetConsoleScreenBufferInfo(hstdout, &csb_state);
|
||||
SetConsoleTextAttribute(hstdout, GetLevelColor(type));
|
||||
if (m_Time)
|
||||
printf("%s %s ", GetLevelTag(type), m_TmBuff);
|
||||
else
|
||||
printf("%s ", GetLevelTag(type));
|
||||
SetConsoleTextAttribute(hstdout, sub ? LC_NORMAL : LC_WHITE);
|
||||
puts(m_Buffer.Data());
|
||||
SetConsoleTextAttribute(hstdout, csb_state.wAttributes);
|
||||
#else
|
||||
if (m_Time)
|
||||
printf("%s %s ", GetLevelTag(type), m_TmBuff);
|
||||
else
|
||||
printf("%s ", GetLevelTag(type));
|
||||
puts(m_Buffer.Data());
|
||||
#endif // SQMOD_OS_WINDOWS
|
||||
// Process the message in the buffer
|
||||
Proccess(LOGL_INF, true);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -305,115 +499,65 @@ void Logger::Proccess(Uint8 type, bool sub)
|
||||
*/ { /*
|
||||
*/ va_list args; /*
|
||||
*/ va_start(args, fmt); /*
|
||||
*/ if (_Log) /*
|
||||
*/ _Log->Send(L_, S_, fmt, args); /*
|
||||
*/ else /*
|
||||
*/ vprintf(fmt, args); /*
|
||||
*/ Logger::Get().Send(L_, S_, fmt, args); /*
|
||||
*/ va_end(args); /*
|
||||
*/ } /*
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_LOG(LogDbg, LL_DBG, false)
|
||||
SQMOD_LOG(LogUsr, LL_USR, false)
|
||||
SQMOD_LOG(LogScs, LL_SCS, false)
|
||||
SQMOD_LOG(LogInf, LL_INF, false)
|
||||
SQMOD_LOG(LogWrn, LL_WRN, false)
|
||||
SQMOD_LOG(LogErr, LL_ERR, false)
|
||||
SQMOD_LOG(LogFtl, LL_FTL, false)
|
||||
SQMOD_LOG(LogDbg, LOGL_DBG, false)
|
||||
SQMOD_LOG(LogUsr, LOGL_USR, false)
|
||||
SQMOD_LOG(LogScs, LOGL_SCS, false)
|
||||
SQMOD_LOG(LogInf, LOGL_INF, false)
|
||||
SQMOD_LOG(LogWrn, LOGL_WRN, false)
|
||||
SQMOD_LOG(LogErr, LOGL_ERR, false)
|
||||
SQMOD_LOG(LogFtl, LOGL_FTL, false)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_LOG(LogSDbg, LL_DBG, true)
|
||||
SQMOD_LOG(LogSUsr, LL_USR, true)
|
||||
SQMOD_LOG(LogSScs, LL_SCS, true)
|
||||
SQMOD_LOG(LogSInf, LL_INF, true)
|
||||
SQMOD_LOG(LogSWrn, LL_WRN, true)
|
||||
SQMOD_LOG(LogSErr, LL_ERR, true)
|
||||
SQMOD_LOG(LogSFtl, LL_FTL, true)
|
||||
SQMOD_LOG(LogSDbg, LOGL_DBG, true)
|
||||
SQMOD_LOG(LogSUsr, LOGL_USR, true)
|
||||
SQMOD_LOG(LogSScs, LOGL_SCS, true)
|
||||
SQMOD_LOG(LogSInf, LOGL_INF, true)
|
||||
SQMOD_LOG(LogSWrn, LOGL_WRN, true)
|
||||
SQMOD_LOG(LogSErr, LOGL_ERR, true)
|
||||
SQMOD_LOG(LogSFtl, LOGL_FTL, true)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#define SQMOD_CLOG(N_, L_, S_) /*
|
||||
*/bool N_(bool c, CCStr fmt, ...) /*
|
||||
*/ { /*
|
||||
*/ if (!c) /*
|
||||
*/ return c; /*
|
||||
*/ { /*
|
||||
*/ return c; /*
|
||||
*/ } /*
|
||||
*/ va_list args; /*
|
||||
*/ va_start(args, fmt); /*
|
||||
*/ if (_Log) /*
|
||||
*/ _Log->Send(L_, S_, fmt, args); /*
|
||||
*/ else /*
|
||||
*/ vprintf(fmt, args); /*
|
||||
*/ Logger::Get().Send(L_, S_, fmt, args); /*
|
||||
*/ va_end(args); /*
|
||||
*/ return c; /*
|
||||
*/ } /*
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_CLOG(cLogDbg, LL_DBG, false)
|
||||
SQMOD_CLOG(cLogUsr, LL_USR, false)
|
||||
SQMOD_CLOG(cLogScs, LL_SCS, false)
|
||||
SQMOD_CLOG(cLogInf, LL_INF, false)
|
||||
SQMOD_CLOG(cLogWrn, LL_WRN, false)
|
||||
SQMOD_CLOG(cLogErr, LL_ERR, false)
|
||||
SQMOD_CLOG(cLogFtl, LL_FTL, false)
|
||||
SQMOD_CLOG(cLogDbg, LOGL_DBG, false)
|
||||
SQMOD_CLOG(cLogUsr, LOGL_USR, false)
|
||||
SQMOD_CLOG(cLogScs, LOGL_SCS, false)
|
||||
SQMOD_CLOG(cLogInf, LOGL_INF, false)
|
||||
SQMOD_CLOG(cLogWrn, LOGL_WRN, false)
|
||||
SQMOD_CLOG(cLogErr, LOGL_ERR, false)
|
||||
SQMOD_CLOG(cLogFtl, LOGL_FTL, false)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_CLOG(cLogSDbg, LL_DBG, true)
|
||||
SQMOD_CLOG(cLogSUsr, LL_USR, true)
|
||||
SQMOD_CLOG(cLogSScs, LL_SCS, true)
|
||||
SQMOD_CLOG(cLogSInf, LL_INF, true)
|
||||
SQMOD_CLOG(cLogSWrn, LL_WRN, true)
|
||||
SQMOD_CLOG(cLogSErr, LL_ERR, true)
|
||||
SQMOD_CLOG(cLogSFtl, LL_FTL, true)
|
||||
SQMOD_CLOG(cLogSDbg, LOGL_DBG, true)
|
||||
SQMOD_CLOG(cLogSUsr, LOGL_USR, true)
|
||||
SQMOD_CLOG(cLogSScs, LOGL_SCS, true)
|
||||
SQMOD_CLOG(cLogSInf, LOGL_INF, true)
|
||||
SQMOD_CLOG(cLogSWrn, LOGL_WRN, true)
|
||||
SQMOD_CLOG(cLogSErr, LOGL_ERR, true)
|
||||
SQMOD_CLOG(cLogSFtl, LOGL_FTL, true)
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputMessageImpl(const char * msg, va_list args)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
|
||||
printf("[SQMOD] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
vprintf(msg, args);
|
||||
puts("");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
||||
#else
|
||||
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
|
||||
vprintf(msg, args);
|
||||
puts("");
|
||||
#endif
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputErrorImpl(const char * msg, va_list args)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
printf("[SQMOD] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
vprintf(msg, args);
|
||||
puts("");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
||||
#else
|
||||
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
|
||||
vprintf(msg, args);
|
||||
puts("");
|
||||
#endif
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputDebug(const char * msg, ...)
|
||||
void OutputDebug(CCStr msg, ...)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
// Initialize the arguments list
|
||||
@@ -429,7 +573,7 @@ void OutputDebug(const char * msg, ...)
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputMessage(const char * msg, ...)
|
||||
void OutputMessage(CCStr msg, ...)
|
||||
{
|
||||
// Initialize the arguments list
|
||||
va_list args;
|
||||
@@ -441,7 +585,7 @@ void OutputMessage(const char * msg, ...)
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputError(const char * msg, ...)
|
||||
void OutputError(CCStr msg, ...)
|
||||
{
|
||||
// Initialize the arguments list
|
||||
va_list args;
|
||||
|
||||
@@ -2,99 +2,301 @@
|
||||
#define _LOGGER_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
#include "SqBase.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Supported levels of logging.
|
||||
*/
|
||||
enum LogLvl
|
||||
{
|
||||
LL_NIL = (1 << 0),
|
||||
LL_DBG = (1 << 1),
|
||||
LL_USR = (1 << 2),
|
||||
LL_SCS = (1 << 3),
|
||||
LL_INF = (1 << 4),
|
||||
LL_WRN = (1 << 5),
|
||||
LL_ERR = (1 << 6),
|
||||
LL_FTL = (1 << 7),
|
||||
LL_ANY = 0xFF
|
||||
LOGL_NIL = (1 << 0),
|
||||
LOGL_DBG = (1 << 1),
|
||||
LOGL_USR = (1 << 2),
|
||||
LOGL_SCS = (1 << 3),
|
||||
LOGL_INF = (1 << 4),
|
||||
LOGL_WRN = (1 << 5),
|
||||
LOGL_ERR = (1 << 6),
|
||||
LOGL_FTL = (1 << 7),
|
||||
LOGL_ANY = 0xFF
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
extern SQMOD_MANAGEDPTR_TYPE(Logger) _Log;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class responsible for logging output.
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static Logger s_Inst; // Logger instance.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
Logger();
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
Logger(const Logger & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
Logger(Logger && o) = delete;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Logger & operator= (const Logger & o) = delete;
|
||||
Logger & operator= (Logger && o) = delete;
|
||||
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Logger();
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static Logger * Get()
|
||||
{
|
||||
if (!_Log)
|
||||
{
|
||||
return _Log = SQMOD_MANAGEDPTR_MAKE(Logger, new Logger());
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
Logger & operator = (const Logger & o) = delete;
|
||||
|
||||
return SQMOD_MANAGEDPTR_GET(_Log);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void ToggleTime(bool enabled) { m_Time = enabled; }
|
||||
bool HasTime() const { return m_Time; }
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void SetLevels(Uint8 levels) { m_Levels = levels; }
|
||||
Uint8 GetLevels() const { return m_Levels; }
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void EnableLevel(Uint8 level) { m_Levels |= level; }
|
||||
void DisableLevel(Uint8 level) { if (m_Levels & level) m_Levels ^= level; }
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Send(Uint8 type, bool sub, CCStr fmt, va_list args);
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Message(Uint8 type, bool sub, CCStr fmt, ...);
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Debug(CCStr fmt, ...);
|
||||
void Debug(CCStr fmt, va_list args);
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void Proccess(Uint8 type, bool sub);
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
Logger & operator = (Logger && o) = delete;
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Buffer m_Buffer;
|
||||
SQChar m_TmBuff[80];
|
||||
Buffer m_Buffer; // Common buffer where the message is written.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Uint8 m_Levels;
|
||||
bool m_Time;
|
||||
Uint8 m_ConsoleLevels; // The levels allowed to be outputted to console.
|
||||
Uint8 m_LogFileLevels; // The levels allowed to be outputted to log file.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
bool m_ConsoleTime; // Whether console messages should be timestamped.
|
||||
bool m_LogFileTime; // Whether log file messages should be timestamped.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
std::FILE* m_File; // Handle to the file where the logs should be saved.
|
||||
std::string m_Filename; // The name of the file where the logs are saved.
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process the message in the internal buffer.
|
||||
*/
|
||||
void Proccess(Uint8 level, bool sub);
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the logger instance.
|
||||
*/
|
||||
static Logger & Get()
|
||||
{
|
||||
return s_Inst;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Flush buffered data and close the logging file.
|
||||
*/
|
||||
void Close();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Initialize the logging utility.
|
||||
*/
|
||||
void Initialize(CCStr filename);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Terminate the logging utility.
|
||||
*/
|
||||
void Terminate();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Enable or disable console message time stamping.
|
||||
*/
|
||||
void ToggleConsoleTime(bool enabled)
|
||||
{
|
||||
m_ConsoleTime = enabled;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether console message time stamping is enabled.
|
||||
*/
|
||||
bool ConsoleHasTime() const
|
||||
{
|
||||
return m_ConsoleTime;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Enable or disable log file message time stamping.
|
||||
*/
|
||||
void ToggleLogFileTime(bool enabled)
|
||||
{
|
||||
m_LogFileTime = enabled;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether log file message time stamping is enabled.
|
||||
*/
|
||||
bool LogFileHasTime() const
|
||||
{
|
||||
return m_LogFileTime;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the console level flags.
|
||||
*/
|
||||
void SetConsoleLevels(Uint8 levels)
|
||||
{
|
||||
m_ConsoleLevels = levels;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the console level flags.
|
||||
*/
|
||||
Uint8 GetConsoleLevels() const
|
||||
{
|
||||
return m_ConsoleLevels;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the log file level flags.
|
||||
*/
|
||||
void SetLogFileLevels(Uint8 levels)
|
||||
{
|
||||
m_LogFileLevels = levels;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the log file level flags.
|
||||
*/
|
||||
Uint8 GetLogFileLevels() const
|
||||
{
|
||||
return m_LogFileLevels;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Enable a certain console logging level.
|
||||
*/
|
||||
void EnableConsoleLevel(Uint8 level)
|
||||
{
|
||||
m_ConsoleLevels |= level;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Disable a certain console logging level.
|
||||
*/
|
||||
void DisableConsoleLevel(Uint8 level)
|
||||
{
|
||||
if (m_ConsoleLevels & level)
|
||||
{
|
||||
m_ConsoleLevels ^= level;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Toggle a certain console logging level.
|
||||
*/
|
||||
void ToggleConsoleLevel(Uint8 level, bool toggle)
|
||||
{
|
||||
if (toggle)
|
||||
{
|
||||
EnableConsoleLevel(level);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableConsoleLevel(level);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Enable a certain log file logging level.
|
||||
*/
|
||||
void EnableLogFileLevel(Uint8 level)
|
||||
{
|
||||
m_LogFileLevels |= level;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Disable a certain log file logging level.
|
||||
*/
|
||||
void DisableLogFileLevel(Uint8 level)
|
||||
{
|
||||
m_LogFileLevels |= level;
|
||||
m_LogFileLevels ^= level;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Toggle a certain log file logging level.
|
||||
*/
|
||||
void ToggleLogFileLevel(Uint8 level, bool toggle)
|
||||
{
|
||||
if (toggle)
|
||||
{
|
||||
EnableLogFileLevel(level);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableLogFileLevel(level);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the log file name.
|
||||
*/
|
||||
const std::string & GetLogFilename() const
|
||||
{
|
||||
return m_Filename;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the log file name.
|
||||
*/
|
||||
void SetLogFilename(CCStr filename);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Send a log message.
|
||||
*/
|
||||
void Send(Uint8 level, bool sub, CCStr fmt, va_list args);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Write a log message.
|
||||
*/
|
||||
void Write(Uint8 level, bool sub, CCStr fmt, ...);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Generate a debug message.
|
||||
*/
|
||||
void Debug(CCStr fmt, ...);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Generate a debug message.
|
||||
*/
|
||||
void Debug(CCStr fmt, va_list args);
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Raw console message output.
|
||||
*/
|
||||
void OutputDebug(CCStr msg, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Raw console message output.
|
||||
*/
|
||||
void OutputMessage(CCStr msg, ...);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Raw console message output.
|
||||
*/
|
||||
void OutputError(CCStr msg, ...);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LOGGER_HPP_
|
||||
|
||||
1779
source/Main.cpp
1779
source/Main.cpp
File diff suppressed because it is too large
Load Diff
125
source/Misc.cpp
125
source/Misc.cpp
@@ -1,6 +1,7 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core.hpp"
|
||||
#include "Logger.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqstdstring.h>
|
||||
@@ -14,94 +15,76 @@ extern void DisableReload();
|
||||
extern bool ReloadEnabled();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & GetBlip(Int32 id) { return _Core->GetBlip(id).mObj; }
|
||||
static Object & GetCheckpoint(Int32 id) { return _Core->GetCheckpoint(id).mObj; }
|
||||
static Object & GetForcefield(Int32 id) { return _Core->GetForcefield(id).mObj; }
|
||||
static Object & GetKeybind(Int32 id) { return _Core->GetKeybind(id).mObj; }
|
||||
static Object & GetObject(Int32 id) { return _Core->GetObject(id).mObj; }
|
||||
static Object & GetPickup(Int32 id) { return _Core->GetPickup(id).mObj; }
|
||||
static Object & GetPlayer(Int32 id) { return _Core->GetPlayer(id).mObj; }
|
||||
static Object & GetSprite(Int32 id) { return _Core->GetSprite(id).mObj; }
|
||||
static Object & GetTextdraw(Int32 id) { return _Core->GetTextdraw(id).mObj; }
|
||||
static Object & GetVehicle(Int32 id) { return _Core->GetVehicle(id).mObj; }
|
||||
static Object & GetBlip(Int32 id) { return Core::Get().GetBlip(id).mObj; }
|
||||
static Object & GetCheckpoint(Int32 id) { return Core::Get().GetCheckpoint(id).mObj; }
|
||||
static Object & GetKeybind(Int32 id) { return Core::Get().GetKeybind(id).mObj; }
|
||||
static Object & GetObject(Int32 id) { return Core::Get().GetObject(id).mObj; }
|
||||
static Object & GetPickup(Int32 id) { return Core::Get().GetPickup(id).mObj; }
|
||||
static Object & GetPlayer(Int32 id) { return Core::Get().GetPlayer(id).mObj; }
|
||||
static Object & GetVehicle(Int32 id) { return Core::Get().GetVehicle(id).mObj; }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static bool DelBlip(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->DelBlip(id, header, payload);
|
||||
return Core::Get().DelBlip(id, header, payload);
|
||||
}
|
||||
|
||||
static bool DelCheckpoint(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->DelCheckpoint(id, header, payload);
|
||||
}
|
||||
|
||||
static bool DelForcefield(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->DelForcefield(id, header, payload);
|
||||
return Core::Get().DelCheckpoint(id, header, payload);
|
||||
}
|
||||
|
||||
static bool DelKeybind(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->DelKeybind(id, header, payload);
|
||||
return Core::Get().DelKeybind(id, header, payload);
|
||||
}
|
||||
|
||||
static bool DelObject(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->DelObject(id, header, payload);
|
||||
return Core::Get().DelObject(id, header, payload);
|
||||
}
|
||||
|
||||
static bool DelPickup(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->DelPickup(id, header, payload);
|
||||
}
|
||||
|
||||
static bool DelSprite(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->DelSprite(id, header, payload);
|
||||
}
|
||||
|
||||
static bool DelTextdraw(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->DelTextdraw(id, header, payload);
|
||||
return Core::Get().DelPickup(id, header, payload);
|
||||
}
|
||||
|
||||
static bool DelVehicle(Int32 id, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->DelVehicle(id, header, payload);
|
||||
return Core::Get().DelVehicle(id, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static void BindEvent(Int32 id, Object & env, Function & func)
|
||||
{
|
||||
_Core->BindEvent(id, env, func);
|
||||
Core::Get().BindEvent(id, env, func);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Int32 GetState()
|
||||
{
|
||||
return _Core->GetState();
|
||||
return Core::Get().GetState();
|
||||
}
|
||||
|
||||
static void SetState(Int32 value)
|
||||
{
|
||||
return _Core->SetState(value);
|
||||
return Core::Get().SetState(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static CSStr GetOption(CSStr name)
|
||||
{
|
||||
return _Core->GetOption(name);
|
||||
return Core::Get().GetOption(name);
|
||||
}
|
||||
|
||||
static CSStr GetOptionOr(CSStr name, CSStr value)
|
||||
{
|
||||
return _Core->GetOption(name, value);
|
||||
return Core::Get().GetOption(name, value);
|
||||
}
|
||||
|
||||
static void SetOption(CSStr name, CSStr value)
|
||||
{
|
||||
return _Core->SetOption(name, value);
|
||||
return Core::Get().SetOption(name, value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -145,22 +128,16 @@ void Register_Core(HSQUIRRELVM vm)
|
||||
.Func(_SC("SetOption"), &SetOption)
|
||||
.Func(_SC("GetBlip"), &GetBlip)
|
||||
.Func(_SC("GetCheckpoint"), &GetCheckpoint)
|
||||
.Func(_SC("GetForcefield"), &GetForcefield)
|
||||
.Func(_SC("GetKeybind"), &GetKeybind)
|
||||
.Func(_SC("GetObject"), &GetObject)
|
||||
.Func(_SC("GetPickup"), &GetPickup)
|
||||
.Func(_SC("GetPlayer"), &GetPlayer)
|
||||
.Func(_SC("GetSprite"), &GetSprite)
|
||||
.Func(_SC("GetTextdraw"), &GetTextdraw)
|
||||
.Func(_SC("GetVehicle"), &GetVehicle)
|
||||
.Func(_SC("DestroyBlip"), &DelBlip)
|
||||
.Func(_SC("DestroyCheckpoint"), &DelCheckpoint)
|
||||
.Func(_SC("DestroyForcefield"), &DelForcefield)
|
||||
.Func(_SC("DestroyKeybind"), &DelKeybind)
|
||||
.Func(_SC("DestroyObject"), &DelObject)
|
||||
.Func(_SC("DestroyPickup"), &DelPickup)
|
||||
.Func(_SC("DestroySprite"), &DelSprite)
|
||||
.Func(_SC("DestroyTextdraw"), &DelTextdraw)
|
||||
.Func(_SC("DestroyVehicle"), &DelVehicle)
|
||||
);
|
||||
}
|
||||
@@ -174,35 +151,17 @@ template < Uint8 L, bool S > static SQInteger LogBasicMessage(HSQUIRRELVM vm)
|
||||
{
|
||||
return sq_throwerror(vm, "Missing message value");
|
||||
}
|
||||
// Do we have enough values to call the format function?
|
||||
else if (top > 2)
|
||||
// Attempt to generate the string value
|
||||
StackStrF val(vm, 2);
|
||||
// Have we failed to retrieve the string?
|
||||
if (SQ_FAILED(val.mRes))
|
||||
{
|
||||
SStr msg = NULL;
|
||||
SQInteger len = 0;
|
||||
// Attempt to generate the specified string format
|
||||
SQRESULT ret = sqstd_format(vm, 2, &len, &msg);
|
||||
// Did the format failed?
|
||||
if (SQ_FAILED(ret))
|
||||
{
|
||||
return ret; // Propagate the exception
|
||||
}
|
||||
// Log the resulted string value
|
||||
_Log->Message(L, S, "%s", msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Attempt to retrieve the value from the stack as a string
|
||||
Var< CSStr > msg(vm, 2);
|
||||
// See if the obtained value is a valid string
|
||||
if (!msg.value)
|
||||
{
|
||||
return sq_throwerror(vm, "Unable to retrieve the value");
|
||||
}
|
||||
// Log the resulted string value
|
||||
_Log->Message(L, S, "%s", msg.value);
|
||||
return val.mRes; // Propagate the error!
|
||||
}
|
||||
// Forward the resulted string value to the logger
|
||||
Logger::Get().Write(L, S, "%s", val.mPtr);
|
||||
// This function does not return a value
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
@@ -210,20 +169,20 @@ void Register_Log(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm)
|
||||
.Bind(_SC("SqLog"), Table(vm)
|
||||
.SquirrelFunc(_SC("Dbg"), &LogBasicMessage< LL_DBG, false >)
|
||||
.SquirrelFunc(_SC("Usr"), &LogBasicMessage< LL_USR, false >)
|
||||
.SquirrelFunc(_SC("Scs"), &LogBasicMessage< LL_SCS, false >)
|
||||
.SquirrelFunc(_SC("Inf"), &LogBasicMessage< LL_INF, false >)
|
||||
.SquirrelFunc(_SC("Wrn"), &LogBasicMessage< LL_WRN, false >)
|
||||
.SquirrelFunc(_SC("Err"), &LogBasicMessage< LL_ERR, false >)
|
||||
.SquirrelFunc(_SC("Ftl"), &LogBasicMessage< LL_FTL, false >)
|
||||
.SquirrelFunc(_SC("SDbg"), &LogBasicMessage< LL_DBG, true >)
|
||||
.SquirrelFunc(_SC("SUsr"), &LogBasicMessage< LL_USR, true >)
|
||||
.SquirrelFunc(_SC("SScs"), &LogBasicMessage< LL_SCS, true >)
|
||||
.SquirrelFunc(_SC("SInf"), &LogBasicMessage< LL_INF, true >)
|
||||
.SquirrelFunc(_SC("SWrn"), &LogBasicMessage< LL_WRN, true >)
|
||||
.SquirrelFunc(_SC("SErr"), &LogBasicMessage< LL_ERR, true >)
|
||||
.SquirrelFunc(_SC("SFtl"), &LogBasicMessage< LL_FTL, true >)
|
||||
.SquirrelFunc(_SC("Dbg"), &LogBasicMessage< LOGL_DBG, false >)
|
||||
.SquirrelFunc(_SC("Usr"), &LogBasicMessage< LOGL_USR, false >)
|
||||
.SquirrelFunc(_SC("Scs"), &LogBasicMessage< LOGL_SCS, false >)
|
||||
.SquirrelFunc(_SC("Inf"), &LogBasicMessage< LOGL_INF, false >)
|
||||
.SquirrelFunc(_SC("Wrn"), &LogBasicMessage< LOGL_WRN, false >)
|
||||
.SquirrelFunc(_SC("Err"), &LogBasicMessage< LOGL_ERR, false >)
|
||||
.SquirrelFunc(_SC("Ftl"), &LogBasicMessage< LOGL_FTL, false >)
|
||||
.SquirrelFunc(_SC("SDbg"), &LogBasicMessage< LOGL_DBG, true >)
|
||||
.SquirrelFunc(_SC("SUsr"), &LogBasicMessage< LOGL_USR, true >)
|
||||
.SquirrelFunc(_SC("SScs"), &LogBasicMessage< LOGL_SCS, true >)
|
||||
.SquirrelFunc(_SC("SInf"), &LogBasicMessage< LOGL_INF, true >)
|
||||
.SquirrelFunc(_SC("SWrn"), &LogBasicMessage< LOGL_WRN, true >)
|
||||
.SquirrelFunc(_SC("SErr"), &LogBasicMessage< LOGL_ERR, true >)
|
||||
.SquirrelFunc(_SC("SFtl"), &LogBasicMessage< LOGL_FTL, true >)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Misc/Functions.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Base/Color3.hpp"
|
||||
#include "Base/Vector2.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
#include "Library/Numeric.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "Entity/Player.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static ServerSettings g_SvSettings;
|
||||
static ServerSettings g_SvSettings;
|
||||
static PluginInfo g_PluginInfo;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static SQChar g_SvNameBuff[SQMOD_SVNAMELENGTH] = {0};
|
||||
static SQChar g_PasswdBuff[SQMOD_PASSWDLENGTH] = {0};
|
||||
static SQChar g_GmNameBuff[SQMOD_GMNAMELENGTH] = {0};
|
||||
@@ -72,65 +76,166 @@ static String CS_Keycode_Names[] = {"", /* index 0 is not used */
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CCStr GetKeyCodeName(Uint8 keycode)
|
||||
{ return CS_Keycode_Names[keycode].c_str(); }
|
||||
void SetKeyCodeName(Uint8 keycode, CCStr name)
|
||||
{ CS_Keycode_Names[keycode].assign(name); }
|
||||
CSStr GetKeyCodeName(Uint8 keycode)
|
||||
{
|
||||
return CS_Keycode_Names[keycode].c_str();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetPluginVersion()
|
||||
{ return SQMOD_VERSION; }
|
||||
CCStr GetPluginVersionStr()
|
||||
{ return SQMOD_VERSION_STR; }
|
||||
CCStr GetPluginName()
|
||||
{ return SQMOD_NAME; }
|
||||
CCStr GetPluginAuthor()
|
||||
{ return SQMOD_AUTHOR; }
|
||||
Int32 GetPluginID()
|
||||
{ return _Info->nPluginId; }
|
||||
Uint32 GetNumberOfPlugins()
|
||||
{ return _Func->GetNumberOfPlugins(); }
|
||||
Int32 FindPlugin(CCStr name)
|
||||
{ return _Func->FindPlugin(const_cast< CStr >(name)); }
|
||||
void SetKeyCodeName(Uint8 keycode, CSStr name)
|
||||
{
|
||||
CS_Keycode_Names[keycode].assign(name);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetServerVersion()
|
||||
{ return _Func->GetServerVersion(); }
|
||||
{
|
||||
return _Func->GetServerVersion();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Table GetServerSettings()
|
||||
{
|
||||
// Update the server settings structure
|
||||
_Func->GetServerSettings(&g_SvSettings);
|
||||
// Allocate a script table
|
||||
Table tbl;
|
||||
// Add the structure members to the script table
|
||||
tbl.SetValue(_SC("Name"), g_SvSettings.serverName);
|
||||
tbl.SetValue(_SC("MaxPlayers"), g_SvSettings.maxPlayers);
|
||||
tbl.SetValue(_SC("Port"), g_SvSettings.port);
|
||||
tbl.SetValue(_SC("Flags"), g_SvSettings.flags);
|
||||
// Return the resulted table
|
||||
return tbl;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetNumberOfPlugins()
|
||||
{
|
||||
return _Func->GetNumberOfPlugins();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Table GetPluginInfo(Int32 plugin_id)
|
||||
{
|
||||
// Attempt to update the plug-in info structure
|
||||
if (_Func->GetPluginInfo(plugin_id, &g_PluginInfo) == vcmpErrorNoSuchEntity)
|
||||
{
|
||||
STHROWF("Unknown plug-in identifier: %d", plugin_id);
|
||||
}
|
||||
// Allocate a script table
|
||||
Table tbl;
|
||||
// Add the structure members to the script table
|
||||
tbl.SetValue(_SC("Id"), g_PluginInfo.pluginId);
|
||||
tbl.SetValue(_SC("Name"), g_PluginInfo.name);
|
||||
tbl.SetValue(_SC("Version"), g_PluginInfo.pluginVersion);
|
||||
tbl.SetValue(_SC("MajorAPI"), g_PluginInfo.apiMajorVersion);
|
||||
tbl.SetValue(_SC("MinorAPI"), g_PluginInfo.apiMinorVersion);
|
||||
// Return the resulted table
|
||||
return tbl;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 FindPlugin(CSStr name)
|
||||
{
|
||||
return _Func->FindPlugin(name);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SendPluginCommand(Uint32 identifier, CSStr payload)
|
||||
{
|
||||
_Func->SendPluginCommand(identifier, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const ULongInt & GetTime()
|
||||
{
|
||||
return GetULongInt(_Func->GetTime());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger SendLogMessage(HSQUIRRELVM vm)
|
||||
{
|
||||
const Int32 top = sq_gettop(vm);
|
||||
// Was the message value specified?
|
||||
if (top <= 1)
|
||||
{
|
||||
return sq_throwerror(vm, "Missing message value");
|
||||
}
|
||||
// Attempt to generate the string value
|
||||
StackStrF val(vm, 2);
|
||||
// Have we failed to retrieve the string?
|
||||
if (SQ_FAILED(val.mRes))
|
||||
{
|
||||
return val.mRes; // Propagate the error!
|
||||
}
|
||||
// Forward the resulted string value
|
||||
else if (_Func->LogMessage("%s", val.mPtr) == vcmpErrorTooLargeInput)
|
||||
{
|
||||
STHROWF("Input is too big");
|
||||
}
|
||||
// This function does not return a value
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetLastError()
|
||||
{
|
||||
return _Func->GetLastError();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetPluginVersion()
|
||||
{
|
||||
return SQMOD_VERSION;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr GetPluginVersionStr()
|
||||
{
|
||||
return SQMOD_VERSION_STR;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr GetPluginName()
|
||||
{
|
||||
return SQMOD_NAME;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr GetPluginAuthor()
|
||||
{
|
||||
return SQMOD_AUTHOR;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetPluginID()
|
||||
{
|
||||
return _Info->pluginId;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetServerPort()
|
||||
{
|
||||
// Update the server settings structure
|
||||
_Func->GetServerSettings(&g_SvSettings);
|
||||
return g_SvSettings.uPort;
|
||||
// Return the requested information
|
||||
return g_SvSettings.port;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetServerFlags()
|
||||
{
|
||||
// Update the server settings structure
|
||||
_Func->GetServerSettings(&g_SvSettings);
|
||||
return g_SvSettings.uFlags;
|
||||
// Return the requested information
|
||||
return g_SvSettings.flags;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetServerName(CCStr name)
|
||||
{ _Func->SetServerName(name); }
|
||||
CCStr GetServerName()
|
||||
Int32 GetMaxPlayers(void)
|
||||
{
|
||||
_Func->GetServerName(g_SvNameBuff, SQMOD_SVNAMELENGTH);
|
||||
return g_SvNameBuff;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ULongInt GetTime()
|
||||
{
|
||||
std::uint64_t time = 0;
|
||||
_Func->GetTime(&time);
|
||||
return ULongInt(time);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SendCustomCommand(Uint32 type, CCStr cmd)
|
||||
{
|
||||
_Func->SendCustomCommand(type, cmd);
|
||||
return _Func->GetMaxPlayers();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -139,39 +244,534 @@ void SetMaxPlayers(Int32 max)
|
||||
_Func->SetMaxPlayers(max);
|
||||
}
|
||||
|
||||
Int32 GetMaxPlayers(void)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr GetServerName()
|
||||
{
|
||||
return _Func->GetMaxPlayers();
|
||||
// Populate the buffer
|
||||
if (_Func->GetServerName(g_SvNameBuff, SQMOD_SVNAMELENGTH) == vcmpErrorBufferTooSmall)
|
||||
{
|
||||
STHROWF("Server name was too big for the available buffer: %u", sizeof(g_SvNameBuff));
|
||||
}
|
||||
// Return the result
|
||||
return g_SvNameBuff;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetServerPassword(CCStr passwd)
|
||||
{ _Func->SetServerPassword(const_cast< CStr >(passwd)); }
|
||||
CCStr GetServerPassword()
|
||||
void SetServerName(CSStr name)
|
||||
{
|
||||
_Func->GetServerPassword(g_PasswdBuff, SQMOD_PASSWDLENGTH);
|
||||
_Func->SetServerName(name);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr GetServerPassword()
|
||||
{
|
||||
// Populate the buffer
|
||||
if (_Func->GetServerPassword(g_PasswdBuff, SQMOD_PASSWDLENGTH) == vcmpErrorBufferTooSmall)
|
||||
{
|
||||
STHROWF("Server password was too big for the available buffer: %u", sizeof(g_PasswdBuff));
|
||||
}
|
||||
// Return the result
|
||||
return g_PasswdBuff;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetGameModeText(CCStr text)
|
||||
{ _Func->SetGameModeText(text); }
|
||||
CCStr GetGameModeText()
|
||||
void SetServerPassword(CSStr passwd)
|
||||
{
|
||||
_Func->GetGameModeText(g_GmNameBuff, SQMOD_GMNAMELENGTH);
|
||||
_Func->SetServerPassword(passwd);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr GetGameModeText()
|
||||
{
|
||||
// Populate the buffer
|
||||
if (_Func->GetGameModeText(g_GmNameBuff, SQMOD_GMNAMELENGTH) == vcmpErrorBufferTooSmall)
|
||||
{
|
||||
STHROWF("Game-mode text was too big for the available buffer: %u", sizeof(g_GmNameBuff));
|
||||
}
|
||||
// Return the result
|
||||
return g_GmNameBuff;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 PlaySound(Int32 world, Int32 sound, const Vector3 & pos)
|
||||
{ return _Func->PlaySound(world, sound, pos.x, pos.y, pos.z); }
|
||||
Int32 PlaySoundEx(Int32 world, Int32 sound, Float32 x, Float32 y, Float32 z)
|
||||
{ return _Func->PlaySound(world, sound, x, y, z); }
|
||||
void SetGameModeText(CSStr text)
|
||||
{
|
||||
_Func->SetGameModeText(text);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 AddRadioStream(Int32 id, CCStr name, CCStr url, bool listed)
|
||||
{ return _Func->AddRadioStream(id, name, url, listed); }
|
||||
Int32 RemoveRadioStream(Int32 id)
|
||||
{ return _Func->RemoveRadioStream(id); }
|
||||
void CreateRadioStream(CSStr name, CSStr url, bool listed)
|
||||
{
|
||||
if (_Func->AddRadioStream(-1, name, url, listed) == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Invalid radio stream identifier");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CreateRadioStreamEx(Int32 id, CSStr name, CSStr url, bool listed)
|
||||
{
|
||||
if (_Func->AddRadioStream(id, name, url, listed) == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Invalid radio stream identifier");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void RemoveRadioStream(Int32 id)
|
||||
{
|
||||
if (_Func->RemoveRadioStream(id) == vcmpErrorNoSuchEntity)
|
||||
{
|
||||
STHROWF("No such radio stream exists");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ShutdownServer()
|
||||
{
|
||||
_Func->ShutdownServer();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool GetServerOption(Int32 option_id)
|
||||
{
|
||||
// Attempt to obtain the current value of the specified option
|
||||
const bool value = _Func->GetServerOption(static_cast< vcmpServerOption >(option_id));
|
||||
// Check for errors
|
||||
if (_Func->GetLastError() == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Unknown option identifier: %d", option_id);
|
||||
}
|
||||
// Return the obtained value
|
||||
return value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetServerOption(Int32 option_id, bool toggle)
|
||||
{
|
||||
if (_Func->SetServerOption(static_cast< vcmpServerOption >(option_id),
|
||||
toggle) == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Unknown option identifier: %d", option_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Core::Get().EmitServerOption(option_id, toggle, 0, NullObject());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetServerOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload)
|
||||
{
|
||||
if (_Func->SetServerOption(static_cast< vcmpServerOption >(option_id),
|
||||
toggle) == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Unknown option identifier: %d", option_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Core::Get().EmitServerOption(option_id, toggle, header, payload);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Table GetWorldBounds()
|
||||
{
|
||||
Vector2 max, min;
|
||||
// Retrieve the current world bounds
|
||||
_Func->GetWorldBounds(&max.x, &min.x, &max.y, &min.y);
|
||||
// Allocate a script table
|
||||
Table tbl;
|
||||
// Populate the table with the obtained values
|
||||
tbl.SetValue(_SC("max"), max);
|
||||
tbl.SetValue(_SC("min"), min);
|
||||
// Return the result
|
||||
return tbl;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWorldBounds(const Vector2 & max, const Vector2 & min)
|
||||
{
|
||||
_Func->SetWorldBounds(max.x, min.x, max.y, min.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWorldBoundsEx(Float32 max_x, Float32 max_y, Float32 min_x, Float32 min_y)
|
||||
{
|
||||
_Func->SetWorldBounds(max_x, min_x, max_y, min_y);
|
||||
}
|
||||
|
||||
Table GetWastedSettings()
|
||||
{
|
||||
Uint32 fc, dt, ft, cfs, cft;
|
||||
Float32 fis, fos;
|
||||
Color3 c;
|
||||
// Retrieve the current wasted settings bounds
|
||||
_Func->GetWastedSettings(&dt, &ft, &fis, &fos, &fc, &cfs, &cft);
|
||||
// Convert the packed color
|
||||
c.SetRGB(fc);
|
||||
// Allocate a script table
|
||||
Table tbl;
|
||||
// Populate the table with the obtained values
|
||||
tbl.SetValue(_SC("DeathTimerOut"), dt);
|
||||
tbl.SetValue(_SC("FadeTimer"), ft);
|
||||
tbl.SetValue(_SC("FadeInSpeed"), fis);
|
||||
tbl.SetValue(_SC("FadeOutSpeed"), fos);
|
||||
tbl.SetValue(_SC("FadeColour"), c);
|
||||
tbl.SetValue(_SC("CorpseFadeStart"), cfs);
|
||||
tbl.SetValue(_SC("CorpseFadeTime"), cft);
|
||||
// Return the result
|
||||
return tbl;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWastedSettings(Uint32 dt, Uint32 ft, Float32 fis, Float32 fos,
|
||||
const Color3 & fc, Uint32 cfs, Uint32 cft)
|
||||
{
|
||||
_Func->SetWastedSettings(dt, ft, fis, fos, fc.GetRGB(), cfs, cft);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetTimeRate(void)
|
||||
{
|
||||
return _Func->GetTimeRate();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetTimeRate(Uint32 rate)
|
||||
{
|
||||
_Func->SetTimeRate(rate);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetHour(void)
|
||||
{
|
||||
return _Func->GetHour();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetHour(Int32 hour)
|
||||
{
|
||||
_Func->SetHour(hour);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetMinute(void)
|
||||
{
|
||||
return _Func->GetMinute();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetMinute(Int32 minute)
|
||||
{
|
||||
_Func->SetMinute(minute);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetWeather(void)
|
||||
{
|
||||
return _Func->GetWeather();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWeather(Int32 weather)
|
||||
{
|
||||
_Func->SetWeather(weather);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 GetGravity(void)
|
||||
{
|
||||
return _Func->GetGravity();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetGravity(Float32 gravity)
|
||||
{
|
||||
_Func->SetGravity(gravity);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 GetGameSpeed(void)
|
||||
{
|
||||
return _Func->GetGameSpeed();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetGameSpeed(Float32 speed)
|
||||
{
|
||||
_Func->SetGameSpeed(speed);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 GetWaterLevel(void)
|
||||
{
|
||||
return _Func->GetWaterLevel();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWaterLevel(Float32 level)
|
||||
{
|
||||
_Func->SetWaterLevel(level);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 GetMaximumFlightAltitude(void)
|
||||
{
|
||||
return _Func->GetMaximumFlightAltitude();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetMaximumFlightAltitude(Float32 height)
|
||||
{
|
||||
_Func->SetMaximumFlightAltitude(height);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetKillCommandDelay(void)
|
||||
{
|
||||
return _Func->GetKillCommandDelay();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetKillCommandDelay(Int32 delay)
|
||||
{
|
||||
_Func->SetKillCommandDelay(delay);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 GetVehiclesForcedRespawnHeight(void)
|
||||
{
|
||||
return _Func->GetVehiclesForcedRespawnHeight();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetVehiclesForcedRespawnHeight(Float32 height)
|
||||
{
|
||||
_Func->SetVehiclesForcedRespawnHeight(height);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CreateExplosion(Int32 world, Int32 type, const Vector3 & pos, CPlayer & source, bool grounded)
|
||||
{
|
||||
// Validate the specified player
|
||||
source.Validate();
|
||||
// Perform the requested operation
|
||||
if (_Func->CreateExplosion(world, type, pos.x, pos.y, pos.z,
|
||||
source.GetID(), grounded) == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Argument value out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CreateExplosionEx(Int32 world, Int32 type, Float32 x, Float32 y, Float32 z, CPlayer & source, bool grounded)
|
||||
{
|
||||
// Validate the specified player
|
||||
source.Validate();
|
||||
// Perform the requested operation
|
||||
if (_Func->CreateExplosion(world, type, x, y, z,
|
||||
source.GetID(), grounded) == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Argument value out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void PlaySound(Int32 world, Int32 sound, const Vector3 & pos)
|
||||
{
|
||||
if (_Func->PlaySound(world, sound, pos.x, pos.y, pos.z) == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Argument value out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void PlaySoundEx(Int32 world, Int32 sound, Float32 x, Float32 y, Float32 z)
|
||||
{
|
||||
if (_Func->PlaySound(world, sound, x, y, z) == vcmpErrorArgumentOutOfBounds)
|
||||
{
|
||||
STHROWF("Argument value out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void HideMapObject(Int32 model, const Vector3 & pos)
|
||||
{
|
||||
_Func->HideMapObject(model,
|
||||
static_cast< Int16 >(std::floor(pos.x * 10.0f) + 0.5f),
|
||||
static_cast< Int16 >(std::floor(pos.y * 10.0f) + 0.5f),
|
||||
static_cast< Int16 >(std::floor(pos.z * 10.0f) + 0.5f)
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void HideMapObjectEx(Int32 model, Float32 x, Float32 y, Float32 z)
|
||||
{
|
||||
_Func->HideMapObject(model,
|
||||
static_cast< Int16 >(std::floor(x * 10.0f) + 0.5f),
|
||||
static_cast< Int16 >(std::floor(y * 10.0f) + 0.5f),
|
||||
static_cast< Int16 >(std::floor(z * 10.0f) + 0.5f)
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void HideMapObjectRaw(Int32 model, Int16 x, Int16 y, Int16 z)
|
||||
{
|
||||
_Func->HideMapObject(model, x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ShowMapObject(Int32 model, const Vector3 & pos)
|
||||
{
|
||||
_Func->ShowMapObject(model,
|
||||
static_cast< Int16 >(std::floor(pos.x * 10.0f) + 0.5f),
|
||||
static_cast< Int16 >(std::floor(pos.y * 10.0f) + 0.5f),
|
||||
static_cast< Int16 >(std::floor(pos.z * 10.0f) + 0.5f)
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ShowMapObjectEx(Int32 model, Float32 x, Float32 y, Float32 z)
|
||||
{
|
||||
_Func->ShowMapObject(model,
|
||||
static_cast< Int16 >(std::floor(x * 10.0f) + 0.5f),
|
||||
static_cast< Int16 >(std::floor(y * 10.0f) + 0.5f),
|
||||
static_cast< Int16 >(std::floor(z * 10.0f) + 0.5f)
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ShowMapObjectRaw(Int32 model, Int16 x, Int16 y, Int16 z)
|
||||
{
|
||||
_Func->ShowMapObject(model, x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ShowAllMapObjects(void)
|
||||
{
|
||||
_Func->ShowAllMapObjects();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQFloat GetWeaponDataValue(Int32 weapon, Int32 field)
|
||||
{
|
||||
return ConvTo< SQFloat >::From(_Func->GetWeaponDataValue(weapon, field));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool SetWeaponDataValue(Int32 weapon, Int32 field, SQFloat value)
|
||||
{
|
||||
return (_Func->SetWeaponDataValue(weapon, field, value) != vcmpErrorArgumentOutOfBounds);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool ResetWeaponDataValue(Int32 weapon, Int32 field)
|
||||
{
|
||||
return (_Func->ResetWeaponDataValue(weapon, field) != vcmpErrorArgumentOutOfBounds);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool IsWeaponDataValueModified(Int32 weapon, Int32 field)
|
||||
{
|
||||
return _Func->IsWeaponDataValueModified(weapon, field);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool ResetWeaponData(Int32 weapon)
|
||||
{
|
||||
return (_Func->ResetWeaponData(weapon) != vcmpErrorArgumentOutOfBounds);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ResetAllWeaponData()
|
||||
{
|
||||
_Func->ResetAllWeaponData();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 AddPlayerClass(Int32 team, const Color3 & color, Int32 skin, const Vector3 & pos, Float32 angle,
|
||||
Int32 wep1, Int32 ammo1, Int32 wep2, Int32 ammo2, Int32 wep3, Int32 ammo3)
|
||||
{
|
||||
return _Func->AddPlayerClass(team, color.GetRGB(), skin, pos.x, pos.y, pos.z, angle,
|
||||
wep1, ammo1, wep2, ammo2, wep3, ammo3);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnPlayerPosition(const Vector3 & pos)
|
||||
{
|
||||
_Func->SetSpawnPlayerPosition(pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnCameraPosition(const Vector3 & pos)
|
||||
{
|
||||
_Func->SetSpawnCameraPosition(pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnCameraLookAt(const Vector3 & pos)
|
||||
{
|
||||
_Func->SetSpawnCameraLookAt(pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnPlayerPositionEx(Float32 x, Float32 y, Float32 z)
|
||||
{
|
||||
_Func->SetSpawnPlayerPosition(x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnCameraPositionEx(Float32 x, Float32 y, Float32 z)
|
||||
{
|
||||
_Func->SetSpawnCameraPosition(x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnCameraLookAtEx(Float32 x, Float32 y, Float32 z)
|
||||
{
|
||||
_Func->SetSpawnPlayerPosition(x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void BanIP(CSStr addr)
|
||||
{
|
||||
_Func->BanIP(const_cast< SStr >(addr));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool UnbanIP(CSStr addr)
|
||||
{
|
||||
return _Func->UnbanIP(const_cast< SStr >(addr));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool IsIPBanned(CSStr addr)
|
||||
{
|
||||
return _Func->IsIPBanned(const_cast< SStr >(addr));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetPlayerIdFromName(CSStr name)
|
||||
{
|
||||
return _Func->GetPlayerIdFromName(name);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool IsPlayerConnected(Int32 player_id)
|
||||
{
|
||||
return _Func->IsPlayerConnected(player_id);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ForceAllSelect()
|
||||
{
|
||||
_Func->ForceAllSelect();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CheckEntityExists(Int32 type, Int32 index)
|
||||
{
|
||||
return _Func->CheckEntityExists(static_cast< vcmpEntityPool >(type), index);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -7,55 +7,452 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CCStr GetKeyCodeName(Uint8 keycode);
|
||||
void SetKeyCodeName(Uint8 keycode, CCStr name);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the name of a certain key-code.
|
||||
*/
|
||||
CSStr GetKeyCodeName(Uint8 keycode);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetPluginVersion();
|
||||
CCStr GetPluginVersionStr();
|
||||
CCStr GetPluginName();
|
||||
CCStr GetPluginAuthor();
|
||||
Int32 GetPluginID();
|
||||
Uint32 GetNumberOfPlugins();
|
||||
Int32 FindPlugin(CCStr name);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the name of a certain key-code.
|
||||
*/
|
||||
void SetKeyCodeName(Uint8 keycode, CSStr name);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the server version.
|
||||
*/
|
||||
Uint32 GetServerVersion();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the server settings.
|
||||
*/
|
||||
Table GetServerSettings();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of loaded plug-ins.
|
||||
*/
|
||||
Uint32 GetNumberOfPlugins();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve information about a certain plug-in.
|
||||
*/
|
||||
Table GetPluginInfo(Int32 plugin_id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempt to find a plug-in identifier by it's name.
|
||||
*/
|
||||
Int32 FindPlugin(CSStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Send a custom command to the loaded plug-ins.
|
||||
*/
|
||||
void SendPluginCommand(Uint32 identifier, CSStr payload);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the server time.
|
||||
*/
|
||||
const ULongInt & GetTime();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Send a log message to the server.
|
||||
*/
|
||||
SQInteger SendLogMessage(HSQUIRRELVM vm);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the last error that occurred on the server.
|
||||
*/
|
||||
Int32 GetLastError();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the version of the host Squirrel plug-in as an integer.
|
||||
*/
|
||||
Uint32 GetPluginVersion();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the version of the host Squirrel plug-in as a string.
|
||||
*/
|
||||
CSStr GetPluginVersionStr();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the name of the host Squirrel plug-in.
|
||||
*/
|
||||
CSStr GetPluginName();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the author of the host Squirrel plug-in.
|
||||
*/
|
||||
CSStr GetPluginAuthor();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the id of the host Squirrel plug-in.
|
||||
*/
|
||||
Int32 GetPluginID();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the port onto which the server was binded.
|
||||
*/
|
||||
Uint32 GetServerPort();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the server flags.
|
||||
*/
|
||||
Uint32 GetServerFlags();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetServerName(CCStr name);
|
||||
CCStr GetServerName();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ULongInt GetTime();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SendCustomCommand(Uint32 type, CCStr cmd);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetMaxPlayers(Int32 max);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the maximum number of clients allowed on the server.
|
||||
*/
|
||||
Int32 GetMaxPlayers(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetServerPassword(CCStr passwd);
|
||||
CCStr GetServerPassword();
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the maximum number of clients allowed on the server.
|
||||
*/
|
||||
void SetMaxPlayers(Int32 max);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetGameModeText(CCStr text);
|
||||
CCStr GetGameModeText();
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the server name.
|
||||
*/
|
||||
CSStr GetServerName();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 PlaySound(Int32 world, Int32 sound, const Vector3 & pos);
|
||||
Int32 PlaySoundEx(Int32 world, Int32 sound, Float32 x, Float32 y, Float32 z);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the server name.
|
||||
*/
|
||||
void SetServerName(CSStr name);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 AddRadioStream(Int32 id, CCStr name, CCStr url, bool listed);
|
||||
Int32 RemoveRadioStream(Int32 id);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the server password.
|
||||
*/
|
||||
CSStr GetServerPassword();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the server password.
|
||||
*/
|
||||
void SetServerPassword(CSStr passwd);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the game-mode text.
|
||||
*/
|
||||
CSStr GetGameModeText();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the game-mode text.
|
||||
*/
|
||||
void SetGameModeText(CSStr text);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a radio stream.
|
||||
*/
|
||||
void CreateRadioStream(CSStr name, CSStr url, bool listed);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a radio stream.
|
||||
*/
|
||||
void CreateRadioStreamEx(Int32 id, CSStr name, CSStr url, bool listed);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Remove a radio stream.
|
||||
*/
|
||||
void RemoveRadioStream(Int32 id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Shutdown the server.
|
||||
*/
|
||||
void ShutdownServer();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve a server option.
|
||||
*/
|
||||
bool GetServerOption(Int32 option_id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify a server option.
|
||||
*/
|
||||
void SetServerOption(Int32 option_id, bool toggle);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify a server option.
|
||||
*/
|
||||
void SetServerOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the world bounds.
|
||||
*/
|
||||
Table GetWorldBounds();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the world bounds.
|
||||
*/
|
||||
void SetWorldBounds(const Vector2 & max, const Vector2 & min);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the world bounds.
|
||||
*/
|
||||
void SetWorldBoundsEx(Float32 max_x, Float32 max_y, Float32 min_x, Float32 min_y);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the wasted settings.
|
||||
*/
|
||||
Table GetWastedSettings();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the wasted settings.
|
||||
*/
|
||||
void SetWastedSettings(Uint32 dt, Uint32 ft, Float32 fis, Float32 fos,
|
||||
const Color3 & fc, Uint32 cfs, Uint32 cft);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the current time-rate.
|
||||
*/
|
||||
Uint32 GetTimeRate(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the current time-rate.
|
||||
*/
|
||||
void SetTimeRate(Uint32 rate);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the game hour.
|
||||
*/
|
||||
Int32 GetHour(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the game hour.
|
||||
*/
|
||||
void SetHour(Int32 hour);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the game minute.
|
||||
*/
|
||||
Int32 GetMinute(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the game minute.
|
||||
*/
|
||||
void SetMinute(Int32 minute);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the weather effects.
|
||||
*/
|
||||
Int32 GetWeather(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the weather effects.
|
||||
*/
|
||||
void SetWeather(Int32 weather);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the game gravity.
|
||||
*/
|
||||
Float32 GetGravity(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the game gravity.
|
||||
*/
|
||||
void SetGravity(Float32 gravity);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the game speed.
|
||||
*/
|
||||
Float32 GetGameSpeed(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the game speed.
|
||||
*/
|
||||
void SetGameSpeed(Float32 speed);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the water level.
|
||||
*/
|
||||
Float32 GetWaterLevel(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the water level.
|
||||
*/
|
||||
void SetWaterLevel(Float32 level);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the maximum flight altitude.
|
||||
*/
|
||||
Float32 GetMaximumFlightAltitude(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the maximum flight altitude.
|
||||
*/
|
||||
void SetMaximumFlightAltitude(Float32 height);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the kill command delay.
|
||||
*/
|
||||
Int32 GetKillCommandDelay(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the kill command delay.
|
||||
*/
|
||||
void SetKillCommandDelay(Int32 delay);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the vehicles forced respawn height.
|
||||
*/
|
||||
Float32 GetVehiclesForcedRespawnHeight(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the vehicles forced respawn height.
|
||||
*/
|
||||
void SetVehiclesForcedRespawnHeight(Float32 height);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a game explosion.
|
||||
*/
|
||||
void CreateExplosion(Int32 world, Int32 type, const Vector3 & pos, CPlayer & source, bool grounded);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a game explosion.
|
||||
*/
|
||||
void CreateExplosionEx(Int32 world, Int32 type, Float32 x, Float32 y, Float32 z, CPlayer & source, bool grounded);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Play a game sound.
|
||||
*/
|
||||
void PlaySound(Int32 world, Int32 sound, const Vector3 & pos);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Play a game sound.
|
||||
*/
|
||||
void PlaySoundEx(Int32 world, Int32 sound, Float32 x, Float32 y, Float32 z);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Make a map object invisible.
|
||||
*/
|
||||
void HideMapObject(Int32 model, const Vector3 & pos);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Make a map object invisible.
|
||||
*/
|
||||
void HideMapObjectEx(Int32 model, Float32 x, Float32 y, Float32 z);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Make a map object invisible.
|
||||
*/
|
||||
void HideMapObjectRaw(Int32 model, Int16 x, Int16 y, Int16 z);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Make a map object visible again.
|
||||
*/
|
||||
void ShowMapObject(Int32 model, const Vector3 & pos);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Make a map object visible again.
|
||||
*/
|
||||
void ShowMapObjectEx(Int32 model, Float32 x, Float32 y, Float32 z);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Make a map object visible again.
|
||||
*/
|
||||
void ShowMapObjectRaw(Int32 model, Int16 x, Int16 y, Int16 z);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Make all map objects visible again.
|
||||
*/
|
||||
void ShowAllMapObjects(void);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve field data of a certain weapon.
|
||||
*/
|
||||
SQFloat GetWeaponDataValue(Int32 weapon, Int32 field);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify field data of a certain weapon.
|
||||
*/
|
||||
bool SetWeaponDataValue(Int32 weapon, Int32 field, SQFloat value);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Reset field data of a certain weapon.
|
||||
*/
|
||||
bool ResetWeaponDataValue(Int32 weapon, Int32 field);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See whether field data of a certain weapon was modified.
|
||||
*/
|
||||
bool IsWeaponDataValueModified(Int32 weapon, Int32 field);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Reset all fields data of a certain weapon.
|
||||
*/
|
||||
bool ResetWeaponData(Int32 weapon);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Reset all fields data of a all weapons.
|
||||
*/
|
||||
void ResetAllWeaponData();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a new player class.
|
||||
*/
|
||||
Int32 AddPlayerClass(Int32 team, const Color3 & color, Int32 skin, const Vector3 & pos, Float32 angle,
|
||||
Int32 wep1, Int32 ammo1, Int32 wep2, Int32 ammo2, Int32 wep3, Int32 ammo3);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Set the player position when spawning.
|
||||
*/
|
||||
void SetSpawnPlayerPosition(const Vector3 & pos);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Set the camera position when spawning.
|
||||
*/
|
||||
void SetSpawnCameraPosition(const Vector3 & pos);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Set the camera focus when spawning.
|
||||
*/
|
||||
void SetSpawnCameraLookAt(const Vector3 & pos);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Set the player position when spawning.
|
||||
*/
|
||||
void SetSpawnPlayerPositionEx(Float32 x, Float32 y, Float32 z);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Set the camera position when spawning.
|
||||
*/
|
||||
void SetSpawnCameraPositionEx(Float32 x, Float32 y, Float32 z);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Set the camera focus when spawning.
|
||||
*/
|
||||
void SetSpawnCameraLookAtEx(Float32 x, Float32 y, Float32 z);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Ban an IP address from the server.
|
||||
*/
|
||||
void BanIP(CSStr addr);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Unban an IP address from the server.
|
||||
*/
|
||||
bool UnbanIP(CSStr addr);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See if an IP address is banned from the server.
|
||||
*/
|
||||
bool IsIPBanned(CSStr addr);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the identifier of the player with the specified name.
|
||||
*/
|
||||
Int32 GetPlayerIdFromName(CSStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See if a player with the specified identifier is connected.
|
||||
*/
|
||||
bool IsPlayerConnected(Int32 player_id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Force all players on the server to select a class.
|
||||
*/
|
||||
void ForceAllSelect();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See if an entity exists on the server.
|
||||
*/
|
||||
bool CheckEntityExists(Int32 type, Int32 index);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
|
||||
@@ -9,19 +9,16 @@
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CCStr GetModelName(Int32 id)
|
||||
CSStr GetModelName(Int32 /*id*/)
|
||||
{
|
||||
// @TODO Implement...
|
||||
SQMOD_UNUSED_VAR(id);
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetModelName(Int32 id, CCStr name)
|
||||
void SetModelName(Int32 /*id*/, CSStr /*name*/)
|
||||
{
|
||||
// @TODO Implement...
|
||||
SQMOD_UNUSED_VAR(id);
|
||||
SQMOD_UNUSED_VAR(name);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -71,6 +68,44 @@ bool IsModelWeapon(Int32 id)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IsModelActuallyWeapon(Int32 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 true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -7,12 +7,25 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CCStr GetModelName(Int32 id);
|
||||
void SetModelName(Int32 id, CCStr name);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the name associated with a model identifier.
|
||||
*/
|
||||
CSStr GetModelName(Int32 id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the name associated with a model identifier.
|
||||
*/
|
||||
void SetModelName(Int32 id, CSStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See whether the given model identifier is used a weapon model.
|
||||
*/
|
||||
bool IsModelWeapon(Int32 id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See whether the given model identifier is an actual weapon model.
|
||||
*/
|
||||
bool IsModelActuallyWeapon(Int32 id);
|
||||
bool IsWeaponNatural(Int32 id);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
|
||||
@@ -47,42 +47,10 @@ static String CS_Skin_Names[] = {
|
||||
""
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetUseClasses(bool toggle)
|
||||
{ _Func->SetUseClasses(toggle); }
|
||||
bool GetUseClasses(void)
|
||||
{ return _Func->GetUseClasses(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 AddPlayerClass(Int32 team, const Color3 & color, Int32 skin, const Vector3 & pos, Float32 angle,
|
||||
Int32 w1, Int32 a1, Int32 w2, Int32 a2, Int32 w3, Int32 a3)
|
||||
{
|
||||
return _Func->AddPlayerClass(team, color.GetRGB(), skin, pos.x, pos.y, pos.z, angle,
|
||||
w1, a1, w2, a2, w3, a3);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnPlayerPos(const Vector3 & pos)
|
||||
{ _Func->SetSpawnPlayerPos(pos.x, pos.y, pos.z); }
|
||||
void SetSpawnPlayerPosEx(Float32 x, Float32 y, Float32 z)
|
||||
{ _Func->SetSpawnPlayerPos(x, y, z); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnCameraPos(const Vector3 & pos)
|
||||
{ _Func->SetSpawnCameraPos(pos.x, pos.y, pos.z); }
|
||||
void SetSpawnCameraPosEx(Float32 x, Float32 y, Float32 z)
|
||||
{ _Func->SetSpawnCameraPos(x, y, z); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnCameraLookAt(const Vector3 & pos)
|
||||
{ _Func->SetSpawnCameraLookAt(pos.x, pos.y, pos.z); }
|
||||
void SetSpawnCameraLookAtEx(Float32 x, Float32 y, Float32 z)
|
||||
{ _Func->SetSpawnCameraLookAt(x, y, z); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CCStr GetSkinName(Uint32 id)
|
||||
{
|
||||
return (id > 159) ? g_EmptyStr : CS_Skin_Names[id].c_str();
|
||||
return (id > 159) ? _SC("") : CS_Skin_Names[id].c_str();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -721,29 +689,8 @@ Int32 GetSkinID(CCStr name)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool IsSkinValid(Int32 id)
|
||||
{
|
||||
return (strlen(GetSkinName(id)) > 0);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & FindPlayer(Object & by)
|
||||
{
|
||||
switch (by.GetType())
|
||||
{
|
||||
case OT_INTEGER:
|
||||
return _Core->GetPlayer(by.Cast< Int32 >()).mObj;
|
||||
case OT_FLOAT:
|
||||
return _Core->GetPlayer(round(by.Cast< Float32 >())).mObj;
|
||||
case OT_STRING:
|
||||
{
|
||||
String str(by.Cast< String >());
|
||||
Int32 id = _Func->GetPlayerIDFromName(&str[0]);
|
||||
if (VALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
|
||||
_Core->GetPlayer(id).mObj;
|
||||
} break;
|
||||
default:
|
||||
STHROWF("Unsupported search identifier");
|
||||
}
|
||||
return NullObject();
|
||||
CSStr name = GetSkinName(id);
|
||||
return (name && *name != '\0');
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -7,34 +7,25 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetUseClasses(bool toggle);
|
||||
bool GetUseClasses(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 AddPlayerClass(Int32 team, const Color3 & color, Int32 skin, const Vector3 & pos, Float32 angle,
|
||||
Int32 w1, Int32 a1, Int32 w2, Int32 a2, Int32 w3, Int32 a3);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnPlayerPos(const Vector3 & pos);
|
||||
void SetSpawnPlayerPosEx(Float32 x, Float32 y, Float32 z);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnCameraPos(const Vector3 & pos);
|
||||
void SetSpawnCameraPosEx(Float32 x, Float32 y, Float32 z);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSpawnCameraLookAt(const Vector3 & pos);
|
||||
void SetSpawnCameraLookAtEx(Float32 x, Float32 y, Float32 z);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the name associated with a skin model identifier.
|
||||
*/
|
||||
CCStr GetSkinName(Uint32 id);
|
||||
void SetSkinName(Uint32 id, CCStr name);
|
||||
Int32 GetSkinID(CCStr name);
|
||||
bool IsSkinValid(Int32 id);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & FindPlayer(Object & by);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the name associated with a skin model identifier.
|
||||
*/
|
||||
void SetSkinName(Uint32 id, CCStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert a vehicle model name to a skin model identifier.
|
||||
*/
|
||||
Int32 GetSkinID(CCStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See whether the specified skin model identifier is valid.
|
||||
*/
|
||||
bool IsSkinValid(Int32 id);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Color3.hpp"
|
||||
#include "Base/Vector2.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
@@ -11,126 +13,148 @@
|
||||
#include "Misc/Player.hpp"
|
||||
#include "Misc/Vehicle.hpp"
|
||||
#include "Misc/Weapon.hpp"
|
||||
#include "Misc/World.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Object & FindPlayer(Object & by)
|
||||
{
|
||||
switch (by.GetType())
|
||||
{
|
||||
case OT_INTEGER:
|
||||
{
|
||||
return Core::Get().GetPlayer(by.Cast< Int32 >()).mObj;
|
||||
} break;
|
||||
case OT_FLOAT:
|
||||
{
|
||||
return Core::Get().GetPlayer(std::round(by.Cast< Float32 >())).mObj;
|
||||
} break;
|
||||
case OT_STRING:
|
||||
{
|
||||
// Obtain the argument as a string
|
||||
String str(by.Cast< String >());
|
||||
// Attempt to locate the player with this name
|
||||
Int32 id = _Func->GetPlayerIdFromName(&str[0]);
|
||||
// Was there a player with this name?
|
||||
if (VALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
|
||||
{
|
||||
Core::Get().GetPlayer(id).mObj;
|
||||
}
|
||||
} break;
|
||||
default: STHROWF("Unsupported search identifier");
|
||||
}
|
||||
// Default to a null object
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Misc(HSQUIRRELVM vm)
|
||||
{
|
||||
Table srvns(vm);
|
||||
|
||||
srvns.Func(_SC("SetTimeRate"), &SetTimeRate)
|
||||
.Func(_SC("GetTimeRate"), &GetTimeRate)
|
||||
.Func(_SC("SetHour"), &SetHour)
|
||||
.Func(_SC("GetHour"), &GetHour)
|
||||
.Func(_SC("SetMinute"), &SetMinute)
|
||||
.Func(_SC("GetMinute"), &GetMinute)
|
||||
.Func(_SC("SetWeather"), &SetWeather)
|
||||
.Func(_SC("GetWeather"), &GetWeather)
|
||||
.Func(_SC("SetGravity"), &SetGravity)
|
||||
.Func(_SC("GetGravity"), &GetGravity)
|
||||
.Func(_SC("SetGamespeed"), &SetGamespeed)
|
||||
.Func(_SC("GetGamespeed"), &GetGamespeed)
|
||||
.Func(_SC("SetWaterLevel"), &SetWaterLevel)
|
||||
.Func(_SC("GetWaterLevel"), &GetWaterLevel)
|
||||
.Func(_SC("SetMaxHeight"), &SetMaxHeight)
|
||||
.Func(_SC("GetMaxHeight"), &GetMaxHeight)
|
||||
.Func(_SC("SetKillCmdDelay"), &SetKillCmdDelay)
|
||||
.Func(_SC("GetKillCmdDelay"), &GetKillCmdDelay)
|
||||
.Func(_SC("SetVehiclesForcedRespawnHeight"), &SetVehiclesForcedRespawnHeight)
|
||||
.Func(_SC("GetVehiclesForcedRespawnHeight"), &GetVehiclesForcedRespawnHeight)
|
||||
.Func(_SC("ToggleSyncFrameLimiter"), &ToggleSyncFrameLimiter)
|
||||
.Func(_SC("EnabledSyncFrameLimiter"), &EnabledSyncFrameLimiter)
|
||||
.Func(_SC("ToggleFrameLimiter"), &ToggleFrameLimiter)
|
||||
.Func(_SC("EnabledFrameLimiter"), &EnabledFrameLimiter)
|
||||
.Func(_SC("ToggleTaxiBoostJump"), &ToggleTaxiBoostJump)
|
||||
.Func(_SC("EnabledTaxiBoostJump"), &EnabledTaxiBoostJump)
|
||||
.Func(_SC("ToggleDriveOnWater"), &ToggleDriveOnWater)
|
||||
.Func(_SC("EnabledDriveOnWater"), &EnabledDriveOnWater)
|
||||
.Func(_SC("ToggleFastSwitch"), &ToggleFastSwitch)
|
||||
.Func(_SC("EnabledFastSwitch"), &EnabledFastSwitch)
|
||||
.Func(_SC("ToggleFriendlyFire"), &ToggleFriendlyFire)
|
||||
.Func(_SC("EnabledFriendlyFire"), &EnabledFriendlyFire)
|
||||
.Func(_SC("ToggleDisableDriveby"), &ToggleDisableDriveby)
|
||||
.Func(_SC("EnabledDisableDriveby"), &EnabledDisableDriveby)
|
||||
.Func(_SC("TogglePerfectHandling"), &TogglePerfectHandling)
|
||||
.Func(_SC("EnabledPerfectHandling"), &EnabledPerfectHandling)
|
||||
.Func(_SC("ToggleFlyingCars"), &ToggleFlyingCars)
|
||||
.Func(_SC("EnabledFlyingCars"), &EnabledFlyingCars)
|
||||
.Func(_SC("ToggleJumpSwitch"), &ToggleJumpSwitch)
|
||||
.Func(_SC("EnabledJumpSwitch"), &EnabledJumpSwitch)
|
||||
.Func(_SC("ToggleShowMarkers"), &ToggleShowMarkers)
|
||||
.Func(_SC("EnabledShowMarkers"), &EnabledShowMarkers)
|
||||
.Func(_SC("ToggleStuntBike"), &ToggleStuntBike)
|
||||
.Func(_SC("EnabledStuntBike"), &EnabledStuntBike)
|
||||
.Func(_SC("ToggleShootInAir"), &ToggleShootInAir)
|
||||
.Func(_SC("EnabledShootInAir"), &EnabledShootInAir)
|
||||
.Func(_SC("ToggleShowNametags"), &ToggleShowNametags)
|
||||
.Func(_SC("EnabledShowNametags"), &EnabledShowNametags)
|
||||
.Func(_SC("ToggleJoinMessages"), &ToggleJoinMessages)
|
||||
.Func(_SC("EnabledJoinMessages"), &EnabledJoinMessages)
|
||||
.Func(_SC("ToggleDeathMessages"), &ToggleDeathMessages)
|
||||
.Func(_SC("EnabledDeathMessages"), &EnabledDeathMessages)
|
||||
.Func(_SC("ToggleChatTagsByDefaultEnabled"), &ToggleChatTagsByDefaultEnabled)
|
||||
.Func(_SC("EnabledChatTagsByDefault"), &EnabledChatTagsByDefault)
|
||||
.Func(_SC("CreateExplosion"), &CreateExplosion)
|
||||
.Func(_SC("CreateExplosionEx"), &CreateExplosionEx)
|
||||
.Func(_SC("HideMapObject"), &HideMapObject)
|
||||
.Func(_SC("HideMapObjectEx"), &HideMapObjectEx)
|
||||
.Func(_SC("HideMapObjectRaw"), &HideMapObjectRaw)
|
||||
.Func(_SC("ShowMapObject"), &ShowMapObject)
|
||||
.Func(_SC("ShowMapObjectEx"), &ShowMapObjectEx)
|
||||
.Func(_SC("ShowAllMapObjects"), &ShowAllMapObjects)
|
||||
.Func(_SC("SetWastedSettings"), &SetWastedSettings)
|
||||
.Func(_SC("GetWastedSettings"), &GetWastedSettings)
|
||||
.Func(_SC("SetWorldBounds"), &SetWorldBounds)
|
||||
.Func(_SC("SetWorldBoundsEx"), &SetWorldBoundsEx)
|
||||
.Func(_SC("GetWorldBounds"), &GetWorldBounds)
|
||||
srvns.SquirrelFunc(_SC("SendLogMessage"), &SendLogMessage)
|
||||
.Func(_SC("GetVersion"), &GetServerVersion)
|
||||
.Func(_SC("GetSettings"), &GetServerSettings)
|
||||
.Func(_SC("GetNumberOfPlugins"), &GetNumberOfPlugins)
|
||||
.Func(_SC("GetPluginInfo"), &GetPluginInfo)
|
||||
.Func(_SC("FindPlugin"), &FindPlugin)
|
||||
.Func(_SC("SendPluginCommand"), &SendPluginCommand)
|
||||
.Func(_SC("GetTime"), &GetTime)
|
||||
.Func(_SC("GetLastError"), &GetLastError)
|
||||
.Func(_SC("GetPluginVersion"), &GetPluginVersion)
|
||||
.Func(_SC("GetPluginVersionStr"), &GetPluginVersionStr)
|
||||
.Func(_SC("GetPluginName"), &GetPluginName)
|
||||
.Func(_SC("GetPluginAuthor"), &GetPluginAuthor)
|
||||
.Func(_SC("GetPluginID"), &GetPluginID)
|
||||
.Func(_SC("GetNumberOfPlugins"), &GetNumberOfPlugins)
|
||||
.Func(_SC("FindPlugin"), &FindPlugin)
|
||||
.Func(_SC("GetVersion"), &GetServerVersion)
|
||||
.Func(_SC("GetPort"), &GetServerPort)
|
||||
.Func(_SC("GetFlags"), &GetServerFlags)
|
||||
.Func(_SC("SetName"), &SetServerName)
|
||||
.Func(_SC("GetName"), &GetServerName)
|
||||
.Func(_SC("GetTime"), &GetTime)
|
||||
.Func(_SC("SendCustomCommand"), &SendCustomCommand)
|
||||
.Func(_SC("SetMaxPlayers"), &SetMaxPlayers)
|
||||
.Func(_SC("GetServerPort"), &GetServerPort)
|
||||
.Func(_SC("GetServerFlags"), &GetServerFlags)
|
||||
.Func(_SC("GetMaxPlayers"), &GetMaxPlayers)
|
||||
.Func(_SC("SetServerPassword"), &SetServerPassword)
|
||||
.Func(_SC("GetServerPassword"), &GetServerPassword)
|
||||
.Func(_SC("SetGameModeText"), &SetGameModeText)
|
||||
.Func(_SC("SetMaxPlayers"), &SetMaxPlayers)
|
||||
.Func(_SC("GetServerName"), &GetServerName)
|
||||
.Func(_SC("SetServerName"), &SetServerName)
|
||||
.Func(_SC("GetPassword"), &GetServerPassword)
|
||||
.Func(_SC("SetPassword"), &SetServerPassword)
|
||||
.Func(_SC("GetGameModeText"), &GetGameModeText)
|
||||
.Func(_SC("AddRadioStream"), &AddRadioStream)
|
||||
.Func(_SC("RemoveRadioStream"), &RemoveRadioStream);
|
||||
.Func(_SC("SetGameModeText"), &SetGameModeText)
|
||||
.Func(_SC("CreateRadioStream"), &CreateRadioStream)
|
||||
.Func(_SC("CreateRadioStreamEx"), &CreateRadioStreamEx)
|
||||
.Func(_SC("RemoveRadioStream"), &RemoveRadioStream)
|
||||
.Func(_SC("Shutdown"), &ShutdownServer)
|
||||
.Func(_SC("GetOption"), &GetServerOption)
|
||||
.Func(_SC("SetOption"), &SetServerOption)
|
||||
.Func(_SC("SetOptionEx"), &SetServerOptionEx)
|
||||
.Func(_SC("GetWorldBounds"), &GetWorldBounds)
|
||||
.Func(_SC("SetWorldBounds"), &SetWorldBounds)
|
||||
.Func(_SC("SetWorldBoundsEx"), &SetWorldBoundsEx)
|
||||
.Func(_SC("GetWastedSettings"), &GetWastedSettings)
|
||||
.Func(_SC("SetWastedSettings"), &SetWastedSettings)
|
||||
.Func(_SC("GetTimeRate"), &GetTimeRate)
|
||||
.Func(_SC("SetTimeRate"), &SetTimeRate)
|
||||
.Func(_SC("GetHour"), &GetHour)
|
||||
.Func(_SC("SetHour"), &SetHour)
|
||||
.Func(_SC("GetMinute"), &GetMinute)
|
||||
.Func(_SC("SetMinute"), &SetMinute)
|
||||
.Func(_SC("GetWeather"), &GetWeather)
|
||||
.Func(_SC("SetWeather"), &SetWeather)
|
||||
.Func(_SC("GetGravity"), &GetGravity)
|
||||
.Func(_SC("SetGravity"), &SetGravity)
|
||||
.Func(_SC("GetGameSpeed"), &GetGameSpeed)
|
||||
.Func(_SC("SetGameSpeed"), &SetGameSpeed)
|
||||
.Func(_SC("GetWaterLevel"), &GetWaterLevel)
|
||||
.Func(_SC("SetWaterLevel"), &SetWaterLevel)
|
||||
.Func(_SC("GetMaximumFlightAltitude"), &GetMaximumFlightAltitude)
|
||||
.Func(_SC("SetMaximumFlightAltitude"), &SetMaximumFlightAltitude)
|
||||
.Func(_SC("GetKillCommandDelay"), &GetKillCommandDelay)
|
||||
.Func(_SC("SetKillCommandDelay"), &SetKillCommandDelay)
|
||||
.Func(_SC("GetVehiclesForcedRespawnHeight"), &GetVehiclesForcedRespawnHeight)
|
||||
.Func(_SC("SetVehiclesForcedRespawnHeight"), &SetVehiclesForcedRespawnHeight)
|
||||
.Func(_SC("CreateExplosion"), &CreateExplosion)
|
||||
.Func(_SC("CreateExplosionEx"), &CreateExplosionEx)
|
||||
.Func(_SC("PlaySound"), &PlaySound)
|
||||
.Func(_SC("PlaySoundEx"), &PlaySoundEx)
|
||||
.Func(_SC("HideMapObject"), &HideMapObject)
|
||||
.Func(_SC("HideMapObjectEx"), &SetKeyCodeName)
|
||||
.Func(_SC("HideMapObjectRaw"), &HideMapObjectRaw)
|
||||
.Func(_SC("ShowMapObject"), &ShowMapObject)
|
||||
.Func(_SC("ShowMapObjectEx"), &ShowMapObjectEx)
|
||||
.Func(_SC("ShowMapObjectRaw"), &ShowMapObjectRaw)
|
||||
.Func(_SC("ShowAllMapObjects"), &ShowAllMapObjects)
|
||||
.Func(_SC("GetWeaponDataValue"), &GetWeaponDataValue)
|
||||
.Func(_SC("SetWeaponDataValue"), &SetWeaponDataValue)
|
||||
.Func(_SC("ResetWeaponDataValue"), &ResetWeaponDataValue)
|
||||
.Func(_SC("IsWeaponDataValueModified"), &IsWeaponDataValueModified)
|
||||
.Func(_SC("ResetWeaponData"), &ResetWeaponData)
|
||||
.Func(_SC("ResetAllWeaponData"), &ResetAllWeaponData)
|
||||
.Func(_SC("AddPlayerClass"), &AddPlayerClass)
|
||||
.Func(_SC("SetSpawnPlayerPosition"), &SetSpawnPlayerPosition)
|
||||
.Func(_SC("SetSpawnCameraPosition"), &SetSpawnCameraPosition)
|
||||
.Func(_SC("SetSpawnCameraLookAt"), &SetSpawnCameraLookAt)
|
||||
.Func(_SC("SetSpawnPlayerPositionEx"), &SetSpawnPlayerPositionEx)
|
||||
.Func(_SC("SetSpawnCameraPositionEx"), &SetSpawnCameraPositionEx)
|
||||
.Func(_SC("SetSpawnCameraLookAtEx"), &SetSpawnCameraLookAtEx)
|
||||
.Func(_SC("BanIP"), &BanIP)
|
||||
.Func(_SC("UnbanIP"), &UnbanIP)
|
||||
.Func(_SC("IsIPBanned"), &IsIPBanned)
|
||||
.Func(_SC("GetPlayerIdFromName"), &GetPlayerIdFromName)
|
||||
.Func(_SC("IsPlayerConnected"), &IsPlayerConnected)
|
||||
.Func(_SC("ForceAllSelect"), &ForceAllSelect)
|
||||
.Func(_SC("CheckEntityExists"), &SetKeyCodeName);
|
||||
|
||||
RootTable(vm).Bind(_SC("SqServer"), srvns);
|
||||
|
||||
RootTable(vm)
|
||||
.Func(_SC("FindPlayer"), &FindPlayer)
|
||||
.Func(_SC("GetKeyCodeName"), &GetKeyCodeName)
|
||||
.Func(_SC("SetKeyCodeName"), &SetKeyCodeName)
|
||||
.Func(_SC("GetModelName"), &GetModelName)
|
||||
.Func(_SC("SetModelName"), &SetModelName)
|
||||
.Func(_SC("IsModelWeapon"), &IsModelWeapon)
|
||||
.Func(_SC("IsModelActuallyWeapon"), &IsModelActuallyWeapon)
|
||||
.Func(_SC("IsWeaponNatural"), &IsWeaponNatural)
|
||||
.Func(_SC("SetUseClasses"), &SetUseClasses)
|
||||
.Func(_SC("GetUseClasses"), &GetUseClasses)
|
||||
.Func(_SC("AddPlayerClass"), &AddPlayerClass)
|
||||
.Func(_SC("SetSpawnPlayerPos"), &SetSpawnPlayerPos)
|
||||
.Func(_SC("SetSpawnPlayerPosEx"), &SetSpawnPlayerPosEx)
|
||||
.Func(_SC("SetSpawnCameraPos"), &SetSpawnCameraPos)
|
||||
.Func(_SC("SetSpawnCameraPosEx"), &SetSpawnCameraPosEx)
|
||||
.Func(_SC("GetSkinName"), &GetSkinName)
|
||||
.Func(_SC("SetSkinName"), &SetSkinName)
|
||||
.Func(_SC("GetSkinID"), &GetSkinID)
|
||||
.Func(_SC("IsSkinValid"), &IsSkinValid)
|
||||
.Func(_SC("FindPlayer"), &FindPlayer)
|
||||
.Func(_SC("GetAutomobileName"), &GetAutomobileName)
|
||||
.Func(_SC("SetAutomobileName"), &SetAutomobileName)
|
||||
.Func(_SC("GetAutomobileID"), &GetAutomobileID)
|
||||
@@ -140,8 +164,11 @@ void Register_Misc(HSQUIRRELVM vm)
|
||||
.Func(_SC("GetWeaponID"), &GetWeaponID)
|
||||
.Func(_SC("IsWeaponValid"), &IsWeaponValid)
|
||||
.Func(_SC("WeaponToModel"), &WeaponToModel)
|
||||
.Func(_SC("IsWeaponNatural"), &IsWeaponNatural)
|
||||
.Func(_SC("PlaySound"), &PlaySound)
|
||||
.Func(_SC("PlaySoundEx"), &PlaySoundEx);
|
||||
.Func(_SC("PlaySoundEx"), &PlaySoundEx)
|
||||
.Func(_SC("CreateExplosion"), &CreateExplosion)
|
||||
.Func(_SC("CreateExplosionEx"), &CreateExplosionEx);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -35,20 +35,22 @@ static String CS_Vehicle_Names[] = {
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CCStr GetAutomobileName(Uint32 id)
|
||||
CSStr GetAutomobileName(Uint32 id)
|
||||
{
|
||||
return (id < 130 || id > 236) ? _SC("") : CS_Vehicle_Names[id-130].c_str();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetAutomobileName(Uint32 id, CCStr name)
|
||||
void SetAutomobileName(Uint32 id, CSStr name)
|
||||
{
|
||||
if (id >= 130 || id <= 236)
|
||||
{
|
||||
CS_Vehicle_Names[id-130].assign(name);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetAutomobileID(CCStr name)
|
||||
Int32 GetAutomobileID(CSStr name)
|
||||
{
|
||||
// Clone the string into an editable version
|
||||
String str(name);
|
||||
@@ -58,7 +60,9 @@ Int32 GetAutomobileID(CCStr name)
|
||||
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
|
||||
Uint32 len = static_cast< Uint32 >(str.length());
|
||||
// Get the most significant characters used to identify a vehicle
|
||||
@@ -70,7 +74,9 @@ Int32 GetAutomobileID(CCStr name)
|
||||
b = str[1];
|
||||
}
|
||||
else if(str.length() >= 2)
|
||||
{
|
||||
b = str[1];
|
||||
}
|
||||
// Search for a pattern in the name
|
||||
switch (a)
|
||||
{
|
||||
@@ -618,51 +624,8 @@ Int32 GetAutomobileID(CCStr name)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool IsAutomobileValid(Int32 id)
|
||||
{
|
||||
return (strlen(GetAutomobileName(id)) > 0);
|
||||
CSStr name = GetAutomobileName(id);
|
||||
return (name && *name != '\0');
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool IsModelActuallyWeapon(Int32 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 true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -7,10 +7,24 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CCStr GetAutomobileName(Uint32 id);
|
||||
void SetAutomobileName(Uint32 id, CCStr name);
|
||||
Int32 GetAutomobileID(CCStr name);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the name associated with a vehicle model identifier.
|
||||
*/
|
||||
CSStr GetAutomobileName(Uint32 id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the name associated with a vehicle model identifier.
|
||||
*/
|
||||
void SetAutomobileName(Uint32 id, CSStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert a vehicle model name to a vehicle model identifier.
|
||||
*/
|
||||
Int32 GetAutomobileID(CSStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See whether the specified vehicle model identifier is valid.
|
||||
*/
|
||||
bool IsAutomobileValid(Int32 id);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -40,7 +40,9 @@ CCStr GetWeaponName(Uint32 id)
|
||||
void SetWeaponName(Uint32 id, CCStr name)
|
||||
{
|
||||
if (id <= 70)
|
||||
{
|
||||
CS_Weapon_Names[id].assign(name);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -54,7 +56,9 @@ Int32 GetWeaponID(CCStr name)
|
||||
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
|
||||
Uint32 len = static_cast< Uint32 >(str.length());
|
||||
// Get the most significant characters used to identify a weapon
|
||||
@@ -66,7 +70,9 @@ Int32 GetWeaponID(CCStr name)
|
||||
b = str[1];
|
||||
}
|
||||
else if(str.length() >= 2)
|
||||
{
|
||||
b = str[1];
|
||||
}
|
||||
// Search for a pattern in the name
|
||||
switch(a)
|
||||
{
|
||||
@@ -242,22 +248,8 @@ Int32 GetWeaponID(CCStr name)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool IsWeaponValid(Int32 id)
|
||||
{
|
||||
return (strlen(GetWeaponName(id)) > 0);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool IsWeaponNatural(Int32 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 true;
|
||||
default: return false;
|
||||
}
|
||||
CSStr name = GetWeaponName(id);
|
||||
return (name && *name != '\0');
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -299,21 +291,25 @@ Int32 WeaponToModel(Int32 id)
|
||||
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 IsWeaponNatural(Int32 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 true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -7,13 +7,36 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CCStr GetWeaponName(Uint32 id);
|
||||
void SetWeaponName(Uint32 id, CCStr name);
|
||||
Int32 GetWeaponID(CCStr name);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the name associated with a weapon identifier.
|
||||
*/
|
||||
CSStr GetWeaponName(Uint32 id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Modify the name associated with a weapon identifier.
|
||||
*/
|
||||
void SetWeaponName(Uint32 id, CSStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert a weapon name to a weapon identifier.
|
||||
*/
|
||||
Int32 GetWeaponID(CSStr name);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See whether the specified weapon identifier is valid.
|
||||
*/
|
||||
bool IsWeaponValid(Int32 id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert the given weapon identifier to it's associated model identifier.
|
||||
*/
|
||||
Int32 WeaponToModel(Int32 id);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* See whether the given weapon identifier cannot be used by another player to inflict damage.
|
||||
*/
|
||||
bool IsWeaponNatural(Int32 id);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _MISC_WEAPON_HPP_
|
||||
|
||||
@@ -1,254 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Misc/World.hpp"
|
||||
#include "Base/Color3.hpp"
|
||||
#include "Base/Vector2.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
#include "Entity/Player.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetTimeRate(Uint32 rate) { _Func->SetTimeRate(rate); }
|
||||
Uint32 GetTimeRate(void) { return _Func->GetTimeRate(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetHour(Int32 hour) { _Func->SetHour(hour); }
|
||||
Int32 GetHour(void) { return _Func->GetHour(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetMinute(Int32 minute) { _Func->SetMinute(minute); }
|
||||
Int32 GetMinute(void) { return _Func->GetMinute(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWeather(Int32 weather) { _Func->SetWeather(weather); }
|
||||
Int32 GetWeather(void) { return _Func->GetWeather(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetGravity(Float32 gravity) { _Func->SetGamespeed(gravity); }
|
||||
Float32 GetGravity(void) { return _Func->GetGamespeed(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetGamespeed(Float32 speed) { _Func->SetGamespeed(speed); }
|
||||
Float32 GetGamespeed(void) { return _Func->GetGamespeed(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWaterLevel(Float32 level) { _Func->SetWaterLevel(level); }
|
||||
Float32 GetWaterLevel(void) { return _Func->GetWaterLevel(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetMaxHeight(Float32 height) { _Func->SetMaxHeight(height); }
|
||||
Float32 GetMaxHeight(void) { return _Func->GetMaxHeight(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetKillCmdDelay(Int32 delay) { _Func->SetKillCmdDelay(delay); }
|
||||
Int32 GetKillCmdDelay(void) { return _Func->GetKillCmdDelay(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetVehiclesForcedRespawnHeight(Float32 height)
|
||||
{ _Func->SetVehiclesForcedRespawnHeight(height); }
|
||||
Float32 GetVehiclesForcedRespawnHeight(void)
|
||||
{ return _Func->GetVehiclesForcedRespawnHeight(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleSyncFrameLimiter(bool toggle)
|
||||
{ _Func->ToggleSyncFrameLimiter(toggle); }
|
||||
bool EnabledSyncFrameLimiter(void)
|
||||
{ return _Func->EnabledSyncFrameLimiter(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleFrameLimiter(bool toggle)
|
||||
{ _Func->ToggleFrameLimiter(toggle); }
|
||||
bool EnabledFrameLimiter(void)
|
||||
{ return _Func->EnabledFrameLimiter(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleTaxiBoostJump(bool toggle)
|
||||
{ _Func->ToggleTaxiBoostJump(toggle); }
|
||||
bool EnabledTaxiBoostJump(void)
|
||||
{ return _Func->EnabledTaxiBoostJump(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleDriveOnWater(bool toggle)
|
||||
{ _Func->ToggleDriveOnWater(toggle); }
|
||||
bool EnabledDriveOnWater(void)
|
||||
{ return _Func->EnabledDriveOnWater(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleFastSwitch(bool toggle)
|
||||
{ _Func->ToggleFastSwitch(toggle); }
|
||||
bool EnabledFastSwitch(void)
|
||||
{ return _Func->EnabledFastSwitch(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleFriendlyFire(bool toggle)
|
||||
{ _Func->ToggleFriendlyFire(toggle); }
|
||||
bool EnabledFriendlyFire(void)
|
||||
{ return _Func->EnabledFriendlyFire(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleDisableDriveby(bool toggle)
|
||||
{ _Func->ToggleDisableDriveby(toggle); }
|
||||
bool EnabledDisableDriveby(void)
|
||||
{ return _Func->EnabledDisableDriveby(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void TogglePerfectHandling(bool toggle)
|
||||
{ _Func->TogglePerfectHandling(toggle); }
|
||||
bool EnabledPerfectHandling(void)
|
||||
{ return _Func->EnabledPerfectHandling(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleFlyingCars(bool toggle)
|
||||
{ _Func->ToggleFlyingCars(toggle); }
|
||||
bool EnabledFlyingCars(void)
|
||||
{ return _Func->EnabledFlyingCars(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleJumpSwitch(bool toggle)
|
||||
{ _Func->ToggleJumpSwitch(toggle); }
|
||||
bool EnabledJumpSwitch(void)
|
||||
{ return _Func->EnabledJumpSwitch(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleShowMarkers(bool toggle)
|
||||
{ _Func->ToggleShowMarkers(toggle); }
|
||||
bool EnabledShowMarkers(void)
|
||||
{ return _Func->EnabledShowMarkers(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleStuntBike(bool toggle)
|
||||
{ _Func->ToggleStuntBike(toggle); }
|
||||
bool EnabledStuntBike(void)
|
||||
{ return _Func->EnabledStuntBike(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleShootInAir(bool toggle)
|
||||
{ _Func->ToggleShootInAir(toggle); }
|
||||
bool EnabledShootInAir(void)
|
||||
{ return _Func->EnabledShootInAir(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleShowNametags(bool toggle)
|
||||
{ _Func->ToggleShowNametags(toggle); }
|
||||
bool EnabledShowNametags(void)
|
||||
{ return _Func->EnabledShowNametags(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleJoinMessages(bool toggle)
|
||||
{ _Func->ToggleJoinMessages(toggle); }
|
||||
bool EnabledJoinMessages(void)
|
||||
{ return _Func->EnabledJoinMessages(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleDeathMessages(bool toggle)
|
||||
{ _Func->ToggleDeathMessages(toggle); }
|
||||
bool EnabledDeathMessages(void)
|
||||
{ return _Func->EnabledDeathMessages(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleChatTagsByDefaultEnabled(bool toggle)
|
||||
{ _Func->ToggleChatTagsByDefaultEnabled(toggle); }
|
||||
bool EnabledChatTagsByDefault(void)
|
||||
{ return _Func->EnabledChatTagsByDefault(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CreateExplosion(Int32 world, Int32 type, const Vector3 & pos, CPlayer & source, Uint32 level)
|
||||
{
|
||||
// Validate the specified player
|
||||
source.Validate();
|
||||
// Perform the requested operation
|
||||
_Func->CreateExplosion(world, type, pos.x, pos.y, pos.z, source.GetID(), level);
|
||||
}
|
||||
|
||||
void CreateExplosionEx(Int32 world, Int32 type, Float32 x, Float32 y, Float32 z, CPlayer & source, Uint32 level)
|
||||
{
|
||||
// Validate the specified player
|
||||
source.Validate();
|
||||
// Perform the requested operation
|
||||
_Func->CreateExplosion(world, type, x, y, z, source.GetID(), level);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void HideMapObject(Int32 model, const Vector3 & pos)
|
||||
{
|
||||
_Func->HideMapObject(model,
|
||||
static_cast< Int32 >(std::floor(pos.x * 10.0f) + 0.5f),
|
||||
static_cast< Int32 >(std::floor(pos.y * 10.0f) + 0.5f),
|
||||
static_cast< Int32 >(std::floor(pos.z * 10.0f) + 0.5f)
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void HideMapObjectEx(Int32 model, Float32 x, Float32 y, Float32 z)
|
||||
{
|
||||
_Func->HideMapObject(model,
|
||||
static_cast< Int32 >(std::floor(x * 10.0f) + 0.5f),
|
||||
static_cast< Int32 >(std::floor(y * 10.0f) + 0.5f),
|
||||
static_cast< Int32 >(std::floor(z * 10.0f) + 0.5f)
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void HideMapObjectRaw(Int32 model, Int32 x, Int32 y, Int32 z)
|
||||
{
|
||||
_Func->HideMapObject(model, x, y, z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ShowMapObject(Int32 model, const Vector3 & pos)
|
||||
{ _Func->ShowMapObject(model, pos.x, pos.y, pos.z); }
|
||||
void ShowMapObjectEx(Int32 model, Float32 x, Float32 y, Float32 z)
|
||||
{ _Func->ShowMapObject(model, x, y, z); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ShowAllMapObjects(void)
|
||||
{ _Func->ShowAllMapObjects(); }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWastedSettings(Uint32 dt, Uint32 ft, Float32 fis, Float32 fos,
|
||||
const Color3 & fc, Uint32 cfs, Uint32 cft)
|
||||
{
|
||||
_Func->SetWastedSettings(dt, ft, fis, fos, fc.GetRGB(), cfs, cft);
|
||||
}
|
||||
|
||||
Table GetWastedSettings()
|
||||
{
|
||||
Uint32 fc, dt, ft, cfs, cft;
|
||||
Float32 fis, fos;
|
||||
Color3 c;
|
||||
_Func->GetWastedSettings(&dt, &ft, &fis, &fos, &fc, &cfs, &cft);
|
||||
c.SetRGB(fc);
|
||||
Table t(DefaultVM::Get());
|
||||
t.SetValue(_SC("dt"), dt);
|
||||
t.SetValue(_SC("ft"), ft);
|
||||
t.SetValue(_SC("fis"), fis);
|
||||
t.SetValue(_SC("fos"), fos);
|
||||
t.SetValue(_SC("fc"), c);
|
||||
t.SetValue(_SC("cfs"), cfs);
|
||||
t.SetValue(_SC("cft"), cft);
|
||||
return t;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWorldBounds(const Vector2 & max, const Vector2 & min)
|
||||
{
|
||||
_Func->SetWorldBounds(max.x, min.x, max.y, min.y);
|
||||
}
|
||||
|
||||
void SetWorldBoundsEx(Float32 max_x, Float32 max_y, Float32 min_x, Float32 min_y)
|
||||
{
|
||||
_Func->SetWorldBounds(max_x, min_x, max_y, min_y);
|
||||
}
|
||||
|
||||
Table GetWorldBounds()
|
||||
{
|
||||
Vector2 max, min;
|
||||
_Func->GetWorldBounds(&max.x, &min.x, &max.y, &min.y);
|
||||
Table t(DefaultVM::Get());
|
||||
t.SetValue(_SC("max"),max);
|
||||
t.SetValue(_SC("min"), min);
|
||||
return t;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
@@ -1,114 +0,0 @@
|
||||
#ifndef _MISC_WORLD_HPP_
|
||||
#define _MISC_WORLD_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "SqBase.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetTimeRate(Uint32 rate);
|
||||
Uint32 GetTimeRate(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetHour(Int32 hour);
|
||||
Int32 GetHour(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetMinute(Int32 minute);
|
||||
Int32 GetMinute(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWeather(Int32 weather);
|
||||
Int32 GetWeather(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetGravity(Float32 gravity);
|
||||
Float32 GetGravity(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetGamespeed(Float32 speed);
|
||||
Float32 GetGamespeed(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWaterLevel(Float32 level);
|
||||
Float32 GetWaterLevel(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetMaxHeight(Float32 height);
|
||||
Float32 GetMaxHeight(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetKillCmdDelay(Int32 delay);
|
||||
Int32 GetKillCmdDelay(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetVehiclesForcedRespawnHeight(Float32 height);
|
||||
Float32 GetVehiclesForcedRespawnHeight(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ToggleSyncFrameLimiter(bool toggle);
|
||||
bool EnabledSyncFrameLimiter(void);
|
||||
void ToggleFrameLimiter(bool toggle);
|
||||
bool EnabledFrameLimiter(void);
|
||||
void ToggleTaxiBoostJump(bool toggle);
|
||||
bool EnabledTaxiBoostJump(void);
|
||||
void ToggleDriveOnWater(bool toggle);
|
||||
bool EnabledDriveOnWater(void);
|
||||
void ToggleFastSwitch(bool toggle);
|
||||
bool EnabledFastSwitch(void);
|
||||
void ToggleFriendlyFire(bool toggle);
|
||||
bool EnabledFriendlyFire(void);
|
||||
void ToggleDisableDriveby(bool toggle);
|
||||
bool EnabledDisableDriveby(void);
|
||||
void TogglePerfectHandling(bool toggle);
|
||||
bool EnabledPerfectHandling(void);
|
||||
void ToggleFlyingCars(bool toggle);
|
||||
bool EnabledFlyingCars(void);
|
||||
void ToggleJumpSwitch(bool toggle);
|
||||
bool EnabledJumpSwitch(void);
|
||||
void ToggleShowMarkers(bool toggle);
|
||||
bool EnabledShowMarkers(void);
|
||||
void ToggleStuntBike(bool toggle);
|
||||
bool EnabledStuntBike(void);
|
||||
void ToggleShootInAir(bool toggle);
|
||||
bool EnabledShootInAir(void);
|
||||
void ToggleShowNametags(bool toggle);
|
||||
bool EnabledShowNametags(void);
|
||||
void ToggleJoinMessages(bool toggle);
|
||||
bool EnabledJoinMessages(void);
|
||||
void ToggleDeathMessages(bool toggle);
|
||||
bool EnabledDeathMessages(void);
|
||||
void ToggleChatTagsByDefaultEnabled(bool toggle);
|
||||
bool EnabledChatTagsByDefault(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CreateExplosion(Int32 world, Int32 type, const Vector3 & pos, CPlayer & source, Uint32 level);
|
||||
void CreateExplosionEx(Int32 world, Int32 type, Float32 x, Float32 y, Float32 z, CPlayer & source, Uint32 level);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void HideMapObject(Int32 model, const Vector3 & pos);
|
||||
void HideMapObjectEx(Int32 model, Float32 x, Float32 y, Float32 z);
|
||||
void HideMapObjectRaw(Int32 model, Int32 x, Int32 y, Int32 z);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ShowMapObject(Int32 model, const Vector3 & pos);
|
||||
void ShowMapObjectEx(Int32 model, Float32 x, Float32 y, Float32 z);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ShowAllMapObjects(void);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWastedSettings(Uint32 dt, Uint32 ft, Float32 fis, Float32 fos,
|
||||
const Color3 & fc, Uint32 cfs, Uint32 cft);
|
||||
Table GetWastedSettings();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetWorldBounds(const Vector2 & max, const Vector2 & min);
|
||||
void SetWorldBoundsEx(Float32 max_x, Float32 max_y, Float32 min_x, Float32 min_y);
|
||||
Table GetWorldBounds();
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _MISC_WORLD_HPP_
|
||||
@@ -40,8 +40,7 @@ extern void Register_Numeric(HSQUIRRELVM vm);
|
||||
extern void Register_Math(HSQUIRRELVM vm);
|
||||
extern void Register_Random(HSQUIRRELVM vm);
|
||||
extern void Register_String(HSQUIRRELVM vm);
|
||||
extern void Register_SysEnv(HSQUIRRELVM vm);
|
||||
extern void Register_SysPath(HSQUIRRELVM vm);
|
||||
extern void Register_System(HSQUIRRELVM vm);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern void Register_Constants(HSQUIRRELVM vm);
|
||||
@@ -70,13 +69,10 @@ bool RegisterAPI(HSQUIRRELVM vm)
|
||||
|
||||
Register_CBlip(vm);
|
||||
Register_CCheckpoint(vm);
|
||||
Register_CForcefield(vm);
|
||||
Register_CKeybind(vm);
|
||||
Register_CObject(vm);
|
||||
Register_CPickup(vm);
|
||||
Register_CPlayer(vm);
|
||||
Register_CSprite(vm);
|
||||
Register_CTextdraw(vm);
|
||||
Register_CVehicle(vm);
|
||||
|
||||
Register_Chrono(vm);
|
||||
@@ -85,8 +81,7 @@ bool RegisterAPI(HSQUIRRELVM vm)
|
||||
Register_Numeric(vm);
|
||||
Register_Math(vm);
|
||||
Register_String(vm);
|
||||
Register_SysEnv(vm);
|
||||
Register_SysPath(vm);
|
||||
Register_System(vm);
|
||||
|
||||
Register_Constants(vm);
|
||||
Register_Log(vm);
|
||||
|
||||
1286
source/Routine.cpp
1286
source/Routine.cpp
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,9 @@
|
||||
#include "Base/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <array>
|
||||
#include <utility>
|
||||
#include <unordered_map>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
@@ -21,183 +22,37 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Simplify future changes to a single point of change.
|
||||
*/
|
||||
typedef SQInteger Interval;
|
||||
typedef Uint32 Iterate;
|
||||
typedef std::vector< Routine * > Routines;
|
||||
typedef Int64 Time;
|
||||
typedef SQInteger Interval;
|
||||
typedef Uint32 Iterator;
|
||||
typedef std::pair< Interval, Routine * > Element;
|
||||
typedef std::array< Element, SQMOD_MAX_ROUTINES > Routines;
|
||||
typedef std::unordered_map< Routine *, Object > Objects;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all active routines and update elapsed time.
|
||||
*/
|
||||
static void Process();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Initialize all resources and prepare for startup.
|
||||
*/
|
||||
static void Initialize();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release all resources and prepare for shutdown.
|
||||
*/
|
||||
static void TerminateAll();
|
||||
static void Deinitialize();
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Commands that can be performed when the buckets are unlocked.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
CMD_REMOVE = 1,
|
||||
CMD_DETACH = 2,
|
||||
CMD_ATTACH = 3
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Group of routines that have the same interval.
|
||||
*/
|
||||
struct Bucket
|
||||
{
|
||||
// ----------------------------------------------------------------------------------------
|
||||
Interval mInterval; /* The interval of time between calls. */
|
||||
Interval mElapsed; /* Time elapsed since the last pulse. */
|
||||
Routines mRoutines; /* Routines to trigger on completion. */
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
Bucket(Interval interval)
|
||||
: mInterval(interval), mElapsed(0), mRoutines()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
Bucket(const Bucket & o) = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
Bucket(Bucket && o) = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Bucket() = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
Bucket & operator = (const Bucket & o) = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Bucket & operator = (Bucket && o) = default;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* A command to perform certain actions when the buckets are unlocked.
|
||||
*/
|
||||
struct Cmd
|
||||
{
|
||||
// ----------------------------------------------------------------------------------------
|
||||
Routine* mRoutine; /* The routine to which this command applies */
|
||||
Interval mInterval; /* The bucket where this routine is stored. */
|
||||
Uint16 mCommand; /* The command that must be performed. */
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
Cmd(Routine * routine, Interval interval, Uint16 command)
|
||||
: mRoutine(routine), mInterval(interval), mCommand(command)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
Cmd(const Cmd & o) = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
Cmd(Cmd && o) = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Cmd() = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
Cmd & operator = (const Cmd & o) = default;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Cmd & operator = (Cmd && o) = default;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Int64 Time;
|
||||
typedef std::vector< Cmd > Queue;
|
||||
typedef std::vector< Bucket > Buckets;
|
||||
typedef std::unordered_map< Routine *, Object > Objects;
|
||||
static Time s_Last; // Last time point.
|
||||
static Time s_Prev; // Previous time point.
|
||||
static Routines s_Routines; // Buckets of routines grouped by similar intervals.
|
||||
static Objects s_Objects; // List of existing routines and their associated object.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Functor used to search for buckets with a certain interval.
|
||||
*/
|
||||
struct IntrvFunc
|
||||
{
|
||||
private:
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
const Interval m_Interval; /* The interval to be matched. */
|
||||
|
||||
public:
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
IntrvFunc(Interval interval)
|
||||
: m_Interval(interval)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Function call operator.
|
||||
*/
|
||||
bool operator () (Buckets::reference elem) const
|
||||
{
|
||||
return (elem.mInterval == m_Interval);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Function call operator.
|
||||
*/
|
||||
bool operator () (Buckets::const_reference elem) const
|
||||
{
|
||||
return (elem.mInterval == m_Interval);
|
||||
}
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static bool s_Lock; /* Avoid further changes to the bucket pool. */
|
||||
static Time s_Last; /* Last time point. */
|
||||
static Time s_Prev; /* Previous time point. */
|
||||
static Queue s_Queue; /* Actions to be performed when the buckets aren't locked */
|
||||
static Buckets s_Buckets; /* Buckets of routines grouped by similar intervals. */
|
||||
static Objects s_Objects; /* List of existing routines and their associated object. */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attach a routine to a certain bucket.
|
||||
*/
|
||||
static void Attach(Routine * routine, Interval interval);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Detach a routine from a certain bucket.
|
||||
*/
|
||||
static void Detach(Routine * routine, Interval interval);
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create or locate the object for the specified routine and keep a strong reference to it.
|
||||
@@ -220,9 +75,24 @@ protected:
|
||||
static void Forget(Routine * routine);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process queue commands.
|
||||
* Insert a routine instance into the pool to be processed.
|
||||
*/
|
||||
static void ProcQueue();
|
||||
static void Insert(Routine * routine, bool associate = true);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Insert a routine instance from the pool to not be processed.
|
||||
*/
|
||||
static void Remove(Routine * routine);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release routine resources.
|
||||
*/
|
||||
void Release();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Execute the binded callback.
|
||||
*/
|
||||
void Execute();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether this routine is valid otherwise throw an exception.
|
||||
@@ -245,73 +115,88 @@ private:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Constructor with just an interval and explicit iterations.
|
||||
*/
|
||||
Routine(Object & env, Function & func, Interval interval, Iterate iterations);
|
||||
Routine(Object & env, Function & func, Interval interval, Iterator iterations);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Constructor with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
Routine(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
Routine(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Constructor with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
Routine(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
Routine(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1, Object & a2);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Constructor with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
Routine(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
Routine(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1, Object & a2, Object & a3);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Constructor with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
Routine(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
Routine(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1, Object & a2, Object & a3, Object & a4);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Constructor with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
Routine(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
Routine(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1, Object & a2, Object & a3, Object & a4, Object & a5);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
Routine(const Routine &);
|
||||
Routine(const Routine & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
Routine(Routine && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
Routine & operator = (const Routine &);
|
||||
Routine & operator = (const Routine & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
Routine & operator = (Routine && o) = delete;
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Number of iterations before self destruct.
|
||||
*/
|
||||
Iterate m_Iterations;
|
||||
*/
|
||||
Iterator m_Iterations;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Interval between calls.
|
||||
*/
|
||||
*/
|
||||
Interval m_Interval;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The index of the slot in the pool.
|
||||
*/
|
||||
Uint16 m_Slot;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Number of arguments to forward.
|
||||
*/
|
||||
Uint8 m_Arguments;
|
||||
*/
|
||||
Uint16 m_Arguments;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether calls should be ignored.
|
||||
*/
|
||||
*/
|
||||
bool m_Suspended;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the routine was terminated.
|
||||
*/
|
||||
*/
|
||||
bool m_Terminated;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -388,19 +273,34 @@ public:
|
||||
Routine & ApplyData(Object & data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Terminate this routine by releasing all resources and scheduling it for detachment.
|
||||
* Activate the routine instance.
|
||||
*/
|
||||
void Terminate();
|
||||
Routine & Activate();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Deactivate the routine instance.
|
||||
*/
|
||||
Routine & Deactivate();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Terminate this routine by deactivating and releasing all resources.
|
||||
*/
|
||||
Routine & Terminate();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Unmark this routine as terminated and allow to be activated.
|
||||
*/
|
||||
Routine & Reanimate();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify an explicit value to be passed as the specified argument.
|
||||
*/
|
||||
Routine & SetArg(Uint8 num, Object & val);
|
||||
Routine & SetArg(Uint16 num, Object & val);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the value that is passed as the specified argument.
|
||||
*/
|
||||
Object & GetArg(Uint8 num);
|
||||
Object & GetArg(Uint16 num);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the amount of time required to wait between calls to the routine.
|
||||
@@ -415,22 +315,22 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of times that the routine can be called before terminating itself.
|
||||
*/
|
||||
Iterate GetIterations() const;
|
||||
Iterator GetIterations() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the number of times that the routine can be called before terminating itself.
|
||||
*/
|
||||
void SetIterations(Iterate iterations);
|
||||
void SetIterations(Iterator iterations);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of arguments that are forwarded when executing the callback.
|
||||
*/
|
||||
Uint8 GetArguments() const;
|
||||
Uint16 GetArguments() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the number of arguments that are forwarded when executing the callback.
|
||||
*/
|
||||
void SetArguments(Uint8 num);
|
||||
void SetArguments(Uint16 num);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the routine is suspended from further calls.
|
||||
@@ -457,33 +357,6 @@ public:
|
||||
*/
|
||||
void SetCallback(Object & env, Function & func);
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release routine resources.
|
||||
*/
|
||||
void Release();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create the routine for the first time.
|
||||
*/
|
||||
void Create();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attach the routine to the associated bucket.
|
||||
*/
|
||||
void Attach();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attach the routine from the associated bucket.
|
||||
*/
|
||||
void Detach();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Execute the binded callback.
|
||||
*/
|
||||
void Execute();
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@@ -494,78 +367,42 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create a routine with just an interval and explicit iterations.
|
||||
*/
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterate iterations);
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterator iterations);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create a routine with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create a routine with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1, Object & a2);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create a routine with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1, Object & a2, Object & a3);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create a routine with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1, Object & a2, Object & a3, Object & a4);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create a routine with just an interval, explicit iterations and arguments.
|
||||
*/
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterate iterations
|
||||
static Object Create(Object & env, Function & func, Interval interval, Iterator iterations
|
||||
, Object & a1, Object & a2, Object & a3, Object & a4, Object & a5);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Flush queued commands manually.
|
||||
*/
|
||||
static void Flush();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the number of queued commands.
|
||||
*/
|
||||
static Uint32 QueueSize();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the number of known routines.
|
||||
*/
|
||||
static Uint32 GetCount();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the number of known buckets.
|
||||
*/
|
||||
static Uint32 GetBuckets();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the number of known routines in bucket.
|
||||
*/
|
||||
static Uint32 GetInBucket(Interval interval);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the number of known buckets.
|
||||
*/
|
||||
static Array GetBucketsList();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the number of known buckets.
|
||||
*/
|
||||
static Table GetBucketsTable();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to find a certain routine by its associated tag.
|
||||
*/
|
||||
static Object FindByTag(CSStr tag);
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
@@ -111,8 +111,8 @@
|
||||
*/
|
||||
|
||||
#define SQMOD_NAME "Squirrel Module"
|
||||
#define SQMOD_AUTHOR "Sandu Liviu Catalin"
|
||||
#define SQMOD_COPYRIGHT "Copyright (C) 2015 Sandu Liviu Catalin"
|
||||
#define SQMOD_AUTHOR "Sandu Liviu Catalin (S.L.C)"
|
||||
#define SQMOD_COPYRIGHT "Copyright (C) 2016 Sandu Liviu Catalin"
|
||||
#define SQMOD_HOST_NAME "SqModHost"
|
||||
#define SQMOD_VERSION 001
|
||||
#define SQMOD_VERSION_STR "0.0.1"
|
||||
@@ -123,6 +123,7 @@
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* SQUIRREL FORWARD DECLARATIONS
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
typedef struct tagSQObject SQObject;
|
||||
struct SQVM;
|
||||
@@ -133,6 +134,7 @@ extern "C" {
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* SQRAT FORWARD DECLARATIONS
|
||||
*/
|
||||
|
||||
namespace Sqrat {
|
||||
class Array;
|
||||
class Object;
|
||||
@@ -204,6 +206,7 @@ typedef Uint32 SizeT;
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* STRING TYPE
|
||||
*/
|
||||
|
||||
typedef std::basic_string<SQChar> String;
|
||||
|
||||
typedef char * CStr;
|
||||
@@ -215,6 +218,7 @@ typedef const SQChar * CSStr;
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* SHORT SQUIRREL TYPENAMES
|
||||
*/
|
||||
|
||||
typedef SQUnsignedInteger32 SQUint32;
|
||||
typedef SQUnsignedInteger SQUint;
|
||||
typedef SQInteger SQInt;
|
||||
@@ -222,6 +226,12 @@ typedef SQInteger SQInt;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
using namespace Sqrat;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Squirrel compatible stl string.
|
||||
*/
|
||||
|
||||
typedef std::basic_string< SQChar > String;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* FORWARD DECLARATIONS
|
||||
*/
|
||||
@@ -265,217 +275,62 @@ template < typename T > class LongInt;
|
||||
typedef LongInt< Int64 > SLongInt;
|
||||
typedef LongInt< Uint64 > ULongInt;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
typedef std::basic_string< SQChar > String;
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* A simple managed pointer used to identify if components are still used after shutdown.
|
||||
*/
|
||||
template < typename T > class ManagedPtr
|
||||
{
|
||||
private:
|
||||
|
||||
T * m_Ptr;
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
ManagedPtr(T * ptr)
|
||||
: m_Ptr(ptr)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
ManagedPtr(const ManagedPtr & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
ManagedPtr(ManagedPtr && o)
|
||||
: m_Ptr(o.m_Ptr)
|
||||
{
|
||||
o.m_Ptr = nullptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~ManagedPtr()
|
||||
{
|
||||
if (m_Ptr)
|
||||
{
|
||||
delete m_Ptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
ManagedPtr & operator = (const ManagedPtr & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
ManagedPtr & operator = (ManagedPtr && o)
|
||||
{
|
||||
if (m_Ptr != o.m_Ptr)
|
||||
{
|
||||
if (m_Ptr)
|
||||
{
|
||||
delete m_Ptr;
|
||||
}
|
||||
m_Ptr = o.m_Ptr;
|
||||
o.m_Ptr = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to boolean for use in boolean operations.
|
||||
*/
|
||||
operator bool () const
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to the managed pointer type.
|
||||
*/
|
||||
operator T * () const
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to the managed pointer type.
|
||||
*/
|
||||
operator const T * () const
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Member operator for dereferencing the managed pointer.
|
||||
*/
|
||||
T * operator -> () const
|
||||
{
|
||||
assert(m_Ptr != nullptr);
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Indirection operator for obtaining a reference of the managed pointer.
|
||||
*/
|
||||
T & operator * () const
|
||||
{
|
||||
assert(m_Ptr != nullptr);
|
||||
return *m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the managed pointer in it's raw form.
|
||||
*/
|
||||
T * Get() const
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#define SQMOD_MANAGEDPTR_TYPE(t) ManagedPtr< t >
|
||||
#define SQMOD_MANAGEDPTR_REF(t) ManagedPtr< t > &
|
||||
#define SQMOD_MANAGEDPTR_MAKE(t, p) ManagedPtr< t >(p)
|
||||
#define SQMOD_MANAGEDPTR_DEL(t, p) p = ManagedPtr< t >(nullptr)
|
||||
#define SQMOD_MANAGEDPTR_GET(p) p.Get();
|
||||
|
||||
#else
|
||||
|
||||
#define SQMOD_MANAGEDPTR_TYPE(t) t *
|
||||
#define SQMOD_MANAGEDPTR_REF(t) t *
|
||||
#define SQMOD_MANAGEDPTR_MAKE(t, p) p
|
||||
#define SQMOD_MANAGEDPTR_DEL(t, p) delete p
|
||||
#define SQMOD_MANAGEDPTR_GET(p) p
|
||||
|
||||
#endif // _DEBUG
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class BufferWrapper;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* FORWARD DECLARATIONS
|
||||
*/
|
||||
|
||||
enum EventType
|
||||
{
|
||||
EVT_UNKNOWN = 0,
|
||||
EVT_CUSTOMEVENT,
|
||||
EVT_BLIPCREATED,
|
||||
EVT_CHECKPOINTCREATED,
|
||||
EVT_FORCEFIELDCREATED,
|
||||
EVT_KEYBINDCREATED,
|
||||
EVT_OBJECTCREATED,
|
||||
EVT_PICKUPCREATED,
|
||||
EVT_PLAYERCREATED,
|
||||
EVT_SPRITECREATED,
|
||||
EVT_TEXTDRAWCREATED,
|
||||
EVT_VEHICLECREATED,
|
||||
EVT_BLIPDESTROYED,
|
||||
EVT_CHECKPOINTDESTROYED,
|
||||
EVT_FORCEFIELDDESTROYED,
|
||||
EVT_KEYBINDDESTROYED,
|
||||
EVT_OBJECTDESTROYED,
|
||||
EVT_PICKUPDESTROYED,
|
||||
EVT_PLAYERDESTROYED,
|
||||
EVT_SPRITEDESTROYED,
|
||||
EVT_TEXTDRAWDESTROYED,
|
||||
EVT_VEHICLEDESTROYED,
|
||||
EVT_BLIPCUSTOM,
|
||||
EVT_CHECKPOINTCUSTOM,
|
||||
EVT_FORCEFIELDCUSTOM,
|
||||
EVT_KEYBINDCUSTOM,
|
||||
EVT_OBJECTCUSTOM,
|
||||
EVT_PICKUPCUSTOM,
|
||||
EVT_PLAYERCUSTOM,
|
||||
EVT_SPRITECUSTOM,
|
||||
EVT_TEXTDRAWCUSTOM,
|
||||
EVT_VEHICLECUSTOM,
|
||||
EVT_PLAYERAWAY,
|
||||
EVT_PLAYERGAMEKEYS,
|
||||
EVT_PLAYERRENAME,
|
||||
EVT_SERVERSTARTUP,
|
||||
EVT_SERVERSHUTDOWN,
|
||||
EVT_SERVERFRAME,
|
||||
EVT_INCOMINGCONNECTION,
|
||||
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_PLAYEREMBARKING,
|
||||
EVT_PLAYEREMBARKED,
|
||||
EVT_PLAYERDISEMBARK,
|
||||
EVT_PLAYERRENAME,
|
||||
EVT_PLAYERSTATE,
|
||||
EVT_PLAYERACTION,
|
||||
EVT_STATENONE,
|
||||
EVT_STATENORMAL,
|
||||
EVT_STATESHOOTING,
|
||||
EVT_STATEAIM,
|
||||
EVT_STATEDRIVER,
|
||||
EVT_STATEPASSENGER,
|
||||
EVT_STATEENTERDRIVER,
|
||||
EVT_STATEENTERPASSENGER,
|
||||
EVT_STATEEXITVEHICLE,
|
||||
EVT_STATEEXIT,
|
||||
EVT_STATEUNSPAWNED,
|
||||
EVT_PLAYERACTION,
|
||||
EVT_ACTIONNONE,
|
||||
EVT_ACTIONNORMAL,
|
||||
EVT_ACTIONAIMING,
|
||||
@@ -489,32 +344,44 @@ enum EventType
|
||||
EVT_ACTIONWASTED,
|
||||
EVT_ACTIONEMBARKING,
|
||||
EVT_ACTIONDISEMBARKING,
|
||||
EVT_VEHICLERESPAWN,
|
||||
EVT_PLAYERBURNING,
|
||||
EVT_PLAYERCROUCHING,
|
||||
EVT_PLAYERGAMEKEYS,
|
||||
EVT_PLAYERSTARTTYPING,
|
||||
EVT_PLAYERSTOPTYPING,
|
||||
EVT_PLAYERAWAY,
|
||||
EVT_PLAYERMESSAGE,
|
||||
EVT_PLAYERCOMMAND,
|
||||
EVT_PLAYERPRIVATEMESSAGE,
|
||||
EVT_PLAYERKEYPRESS,
|
||||
EVT_PLAYERKEYRELEASE,
|
||||
EVT_PLAYERSPECTATE,
|
||||
EVT_PLAYERCRASHREPORT,
|
||||
EVT_VEHICLEEXPLODE,
|
||||
EVT_VEHICLEHEALTH,
|
||||
EVT_VEHICLEMOVE,
|
||||
EVT_PICKUPRESPAWN,
|
||||
EVT_KEYBINDKEYPRESS,
|
||||
EVT_KEYBINDKEYRELEASE,
|
||||
EVT_VEHICLEEMBARKING,
|
||||
EVT_VEHICLEEMBARKED,
|
||||
EVT_VEHICLEDISEMBARK,
|
||||
EVT_VEHICLERESPAWN,
|
||||
EVT_OBJECTSHOT,
|
||||
EVT_OBJECTTOUCHED,
|
||||
EVT_PICKUPCLAIMED,
|
||||
EVT_PICKUPCOLLECTED,
|
||||
EVT_OBJECTSHOT,
|
||||
EVT_OBJECTBUMP,
|
||||
EVT_PICKUPRESPAWN,
|
||||
EVT_CHECKPOINTENTERED,
|
||||
EVT_CHECKPOINTEXITED,
|
||||
EVT_FORCEFIELDENTERED,
|
||||
EVT_FORCEFIELDEXITED,
|
||||
EVT_SERVERFRAME,
|
||||
EVT_SERVERSTARTUP,
|
||||
EVT_SERVERSHUTDOWN,
|
||||
EVT_INTERNALCOMMAND,
|
||||
EVT_LOGINATTEMPT,
|
||||
EVT_CUSTOMEVENT,
|
||||
EVT_WORLDOPTION,
|
||||
EVT_WORLDTOGGLE,
|
||||
EVT_ENTITYPOOL,
|
||||
EVT_CLIENTSCRIPTDATA,
|
||||
EVT_PLAYERUPDATE,
|
||||
EVT_VEHICLEUPDATE,
|
||||
EVT_PLAYERHEALTH,
|
||||
EVT_PLAYERARMOUR,
|
||||
EVT_PLAYERWEAPON,
|
||||
EVT_PLAYERHEADING,
|
||||
EVT_PLAYERPOSITION,
|
||||
EVT_PLAYEROPTION,
|
||||
EVT_VEHICLECOLOUR,
|
||||
EVT_VEHICLEHEALTH,
|
||||
EVT_VEHICLEPOSITION,
|
||||
EVT_VEHICLEROTATION,
|
||||
EVT_VEHICLEOPTION,
|
||||
EVT_SERVEROPTION,
|
||||
EVT_SCRIPTRELOAD,
|
||||
EVT_SCRIPTLOADED,
|
||||
EVT_MAX
|
||||
@@ -730,13 +597,10 @@ enum CmdError
|
||||
|
||||
#define SQMOD_BLIP_POOL 128
|
||||
#define SQMOD_CHECKPOINT_POOL 2000
|
||||
#define SQMOD_FORCEFIELD_POOL 2000
|
||||
#define SQMOD_KEYBIND_POOL 256
|
||||
#define SQMOD_OBJECT_POOL 3000
|
||||
#define SQMOD_PICKUP_POOL 2000
|
||||
#define SQMOD_PLAYER_POOL 100
|
||||
#define SQMOD_SPRITE_POOL 128
|
||||
#define SQMOD_TEXTDRAW_POOL 256
|
||||
#define SQMOD_VEHICLE_POOL 1000
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@@ -779,36 +643,11 @@ enum CmdError
|
||||
*/
|
||||
|
||||
#define SQMOD_STACK_SIZE 2048
|
||||
#define SQMOD_MAX_ROUTINES 1024
|
||||
#define SQMOD_MAX_CMD_ARGS 12
|
||||
#define SQMOD_PLAYER_MSG_PREFIXES 16
|
||||
#define SQMOD_PLAYER_TMP_BUFFER 128
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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
|
||||
#define SQMOD_ENTITY_POOL_MAX 8
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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
|
||||
#define SQMOD_PLAYER_STATE_MAX 9
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* PLAYER ACTION IDENTIFIERS
|
||||
*/
|
||||
@@ -827,43 +666,6 @@ enum CmdError
|
||||
#define SQMOD_PLAYER_ACTION_EXITING_VEHICLE 60
|
||||
#define SQMOD_PLAYER_ACTION_MAX 61
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* VEHICLE UPDATE IDENTIFIERS
|
||||
*/
|
||||
#define SQMOD_VEHICLEUPD_DRIVER 0
|
||||
#define SQMOD_VEHICLEUPD_OTHER 1
|
||||
#define SQMOD_VEHICLEUPD_MAX 2
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* PLAYER UPDATE IDENTIFIERS
|
||||
*/
|
||||
#define SQMOD_PLAYERUPD_ONFOOT 0
|
||||
#define SQMOD_PLAYERUPD_AIM 1
|
||||
#define SQMOD_PLAYERUPD_DRIVER 2
|
||||
#define SQMOD_PLAYERUPD_PASSENGER 3
|
||||
#define SQMOD_PLAYERUPD_MAX 4
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* PART REASON IDENTIFIERS
|
||||
*/
|
||||
#define SQMOD_PARTREASON_TIMEOUT 0
|
||||
#define SQMOD_PARTREASON_DISCONNECTED 1
|
||||
#define SQMOD_PARTREASON_KICKEDBANNED 2
|
||||
#define SQMOD_PARTREASON_CRASHED 3
|
||||
#define SQMOD_PARTREASON_MAX 4
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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
|
||||
#define SQMOD_BODYPART_MAX 7
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* WEATHER IDENTIFIERS
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user