1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-09-14 08:57:09 +02:00

Dumped the old implementation. Started with a more simple approach.

This commit is contained in:
Sandu Liviu Catalin
2016-02-21 00:25:00 +02:00
parent 96ded94026
commit 06e598acfb
293 changed files with 37439 additions and 92564 deletions

View File

@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------------------------
#include "Base/AABB.hpp"
#include "Base/Vector4.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -16,79 +16,50 @@ SQChar AABB::Delim = ',';
// ------------------------------------------------------------------------------------------------
AABB::AABB()
: min(-1), max(1)
: min(-1.0), max(1.0)
{
/* ... */
}
AABB::AABB(Value s)
: min(-s), max(std::fabs(s))
// ------------------------------------------------------------------------------------------------
AABB::AABB(Value sv)
: min(-sv), max(fabs(sv))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(Value xv, Value yv, Value zv)
: min(-xv, -yv, -zv), max(std::fabs(xv), std::fabs(yv), std::fabs(zv))
: min(-xv, -yv, -zv), max(fabs(xv), fabs(yv), fabs(zv))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax)
: min(xmin, ymin, zmin), max(xmax, ymax, zmax)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(const Vector3 & v)
: min(-v), max(v.Abs())
{
}
AABB::AABB(const Vector3 & vmin, const Vector3 & vmax)
: min(vmin), max(vmax)
{
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(const Vector4 & v)
: min(-v), max(v.Abs())
{
}
AABB::AABB(const Vector4 & vmin, const Vector4 & vmax)
: min(vmin), max(vmax)
{
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(const SQChar * values, SQChar delim)
: AABB(GetAABB(values, delim))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(const AABB & b)
: min(b.min), max(b.max)
{
}
AABB::AABB(AABB && b)
: min(b.min), max(b.max)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
AABB::~AABB()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
@@ -99,18 +70,11 @@ AABB & AABB::operator = (const AABB & b)
return *this;
}
AABB & AABB::operator = (AABB && b)
{
min = b.min;
max = b.max;
return *this;
}
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator = (Value s)
{
min.Set(-s);
max.Set(std::fabs(s));
max.Set(fabs(s));
return *this;
}
@@ -327,13 +291,18 @@ bool AABB::operator >= (const AABB & b) const
}
// ------------------------------------------------------------------------------------------------
SQInteger AABB::Cmp(const AABB & b) const
Int32 AABB::Cmp(const AABB & b) const
{
return *this == b ? 0 : (*this > b ? 1 : -1);
if (*this == b)
return 0;
else if (*this > b)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
const SQChar * AABB::ToString() const
CSStr AABB::ToString() const
{
return ToStringF("%f,%f,%f,%f,%f,%f", min.x, min.y, min.z, max.x, max.y, max.z);
}
@@ -342,13 +311,13 @@ const SQChar * AABB::ToString() const
void AABB::Set(Value ns)
{
min = -ns;
max = std::fabs(ns);
max = fabs(ns);
}
void AABB::Set(Value nx, Value ny, Value nz)
{
min.Set(-nx, -ny, -nz);
max.Set(std::fabs(nx), std::fabs(ny), std::fabs(nz));
max.Set(fabs(nx), fabs(ny), fabs(nz));
}
void AABB::Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax)
@@ -391,7 +360,7 @@ void AABB::Set(const Vector4 & nmin, const Vector4 & nmax)
}
// ------------------------------------------------------------------------------------------------
void AABB::Set(const SQChar * values, SQChar delim)
void AABB::Set(CSStr values, SQChar delim)
{
Set(GetAABB(values, delim));
}
@@ -403,48 +372,47 @@ AABB AABB::Abs() const
}
// ================================================================================================
bool Register_AABB(HSQUIRRELVM vm)
void Register_AABB(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <AABB> type");
typedef AABB::Value Val;
Sqrat::RootTable(vm).Bind(_SC("AABB"), Sqrat::Class<AABB>(vm, _SC("AABB"))
RootTable(vm).Bind(_SC("AABB"), Class< AABB >(vm, _SC("AABB"))
/* Constructors */
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<Val, Val, Val, Val, Val, Val>()
.Ctor<const Vector3 &, const Vector3 &>()
.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 */
.Func(_SC("_tostring"), &AABB::ToString)
.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 -)
.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("set_box"), &AABB::Set)
.Overload<void (AABB::*)(const Vector3 &)>(_SC("set_vec3"), &AABB::Set)
.Overload<void (AABB::*)(const Vector3 &, const Vector3 &)>(_SC("set_vec3"), &AABB::Set)
.Overload<void (AABB::*)(const Vector4 &)>(_SC("set_vec4"), &AABB::Set)
.Overload<void (AABB::*)(const Vector4 &, const Vector4 &)>(_SC("set_vec4"), &AABB::Set)
.Overload<void (AABB::*)(const SQChar *, SQChar)>(_SC("set_str"), &AABB::Set)
.Func(_SC("clear"), &AABB::Clear)
/* 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 *=)
@@ -483,10 +451,6 @@ bool Register_AABB(HSQUIRRELVM vm)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opLessEqual"), &AABB::operator <=)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opGreaterEqual"), &AABB::operator >=)
);
LogDbg("Registration of <AABB> type was successful");
return true;
}
} // Namespace:: SqMod

View File

@@ -2,28 +2,27 @@
#define _BASE_AABB_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "Base/Vector3.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct AABB
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef SQFloat Value;
typedef float Value;
/* --------------------------------------------------------------------------------------------
* ...
*/
static const AABB NIL;
static const AABB MIN;
static const AABB MAX;
static const AABB MIN;
static const AABB MAX;
/* --------------------------------------------------------------------------------------------
* ...
@@ -34,307 +33,277 @@ struct AABB
* ...
*/
Vector3 min, max;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
AABB();
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB(Value s);
AABB(Value sv);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB(Value x, Value y, Value z);
AABB(Value xv, Value yv, Value zv);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB(const Vector3 & b);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB(const Vector3 & vmin, const Vector3 & vmax);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
AABB(const Vector4 & b);
AABB(const AABB & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB(const Vector4 & vmin, const Vector4 & vmax);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB(const SQChar * values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB(const AABB & b);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB(AABB && b);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
~AABB();
/* --------------------------------------------------------------------------------------------
* ...
*
*/
AABB & operator = (const AABB & b);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator = (AABB && b);
AABB & operator = (const AABB & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator = (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator = (const Vector3 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator = (const Vector4 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator += (const AABB & b);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator -= (const AABB & b);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator *= (const AABB & b);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator /= (const AABB & b);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator %= (const AABB & b);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator += (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator -= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator *= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator /= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator %= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator ++ ();
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB & operator -- ();
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator ++ (int);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator -- (int);
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator + (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator - (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator * (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator / (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator % (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator + (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator - (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator * (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator / (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator % (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator + () const;
/* --------------------------------------------------------------------------------------------
* ...
*/
AABB operator - () const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator == (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator != (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator < (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator > (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator <= (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator >= (const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const AABB & b) const;
Int32 Cmp(const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(Value ns);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(Value nx, Value ny, Value nz);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const AABB & b);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector3 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector3 & nmin, const Vector3 & nmax);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector4 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector4 & nmin, const Vector4 & nmax);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * values, SQChar delim);
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/

View File

@@ -1,122 +1,553 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Buffer.hpp"
// ------------------------------------------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <exception>
#include <stdexcept>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
Buffer::Buffer()
: m_Data(nullptr), m_Size(0)
/* ------------------------------------------------------------------------------------------------
* Compute the next power of two for the specified number.
*/
static inline unsigned int NPow2(unsigned int num)
{
/* ... */
--num;
num |= num >> 1;
num |= num >> 2;
num |= num >> 4;
num |= num >> 8;
num |= num >> 16;
return ++num;
}
/* ------------------------------------------------------------------------------------------------
* Throw an memory exception.
*/
void ThrowMemExcept(const char * msg, ...)
{
// Exception messages should be concise
char buffer[128];
// Variable arguments structure
va_list args;
// Get the specified arguments
va_start (args, msg);
// Run the specified format
int ret = vsnprintf(buffer, sizeof(buffer), msg, args);
// Check for formatting errors
if (ret < 0)
{
throw std::runtime_error("Unknown memory error");
}
// Throw the actual exception
throw std::runtime_error(buffer);
}
/* ------------------------------------------------------------------------------------------------
* Allocate a memory buffer and return it.
*/
static Buffer::Pointer AllocMem(Buffer::SzType size)
{
// Attempt to allocate memory directly
Buffer::Pointer ptr = (Buffer::Pointer)malloc(size);
// Validate the allocated memory
if (!ptr)
{
ThrowMemExcept("Unable to allocate (%u) bytes of memory", size);
}
// Return the allocated memory
return ptr;
}
/* ------------------------------------------------------------------------------------------------
* ...
*/
class MemCat
{
// --------------------------------------------------------------------------------------------
friend class Memory;
friend class Buffer;
public:
// --------------------------------------------------------------------------------------------
typedef Buffer::Value Value;
// --------------------------------------------------------------------------------------------
typedef Buffer::Reference Reference;
typedef Buffer::ConstRef ConstRef;
// --------------------------------------------------------------------------------------------
typedef Buffer::Pointer Pointer;
typedef Buffer::ConstPtr ConstPtr;
// --------------------------------------------------------------------------------------------
typedef Buffer::SzType SzType;
private:
/* --------------------------------------------------------------------------------------------
*
*/
struct Node
{
// ----------------------------------------------------------------------------------------
SzType mCap;
Pointer mPtr;
Node* mNext;
/* ----------------------------------------------------------------------------------------
* Base constructor.
*/
Node(Node * next)
: mCap(0), mPtr(NULL), mNext(next)
{
/* ... */
}
};
// --------------------------------------------------------------------------------------------
static Node * s_Nodes; /* List of unused node instances. */
// --------------------------------------------------------------------------------------------
Node* m_Head; /* The head memory node. */
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
MemCat()
: m_Head(NULL)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~MemCat()
{
for (Node * node = m_Head, * next = NULL; node; node = next)
{
// Free the memory (if any)
if (node->mPtr)
{
free(node->mPtr);
}
// Save the next node
next = node->mNext;
// Release the node instance
delete node;
}
// Explicitly set the head node to null
m_Head = NULL;
}
/* --------------------------------------------------------------------------------------------
* Clear all memory buffers from the pool.
*/
void Clear()
{
for (Node * node = m_Head, * next = NULL; node; node = next)
{
// Free the memory (if any)
if (node->mPtr)
{
free(node->mPtr);
}
// Save the next node
next = node->mNext;
// Release the node instance
Push(node);
}
// Explicitly set the head node to null
m_Head = NULL;
}
/* --------------------------------------------------------------------------------------------
* Grab a memory buffer from the pool.
*/
void Grab(Pointer & ptr, SzType & size)
{
// NOTE: Function assumes (size > 0)
// Find a buffer large enough to satisfy the requested size
for (Node * node = m_Head, * prev = NULL; node; prev = node, node = node->mNext)
{
// Is this buffer large enough?
if (node->mCap >= size)
{
// Was there a previous node?
if (prev)
{
prev->mNext = node->mNext;
}
// Probably this was the head
else
{
m_Head = node->mNext;
}
// Assign the memory
ptr = node->mPtr;
// Assign the size
size = node->mCap;
// Release the node instance
Push(node);
// Exit the function
return;
}
}
// Round up the size to a power of two number
size = (size & (size - 1)) ? NPow2(size) : size;
// Allocate the memory directly
ptr = AllocMem(size);
// See if the memory could be allocated
if (!ptr)
{
// Revert the size
size = 0;
// Throw the exception
ThrowMemExcept("Unable to allocate (%u) bytes of memory", size);
}
}
/* --------------------------------------------------------------------------------------------
* Return a memory buffer to the pool.
*/
void Drop(Pointer & ptr, SzType & size)
{
if (!ptr)
{
ThrowMemExcept("Cannot store invalid memory buffer");
}
// Request a node instance
Node * node = Pull();
// Assign the specified memory
node->mPtr = ptr;
// Assign the specified size
node->mCap = size;
// Demote the current head node
node->mNext = m_Head;
// Promote as the head node
m_Head = node;
}
/* --------------------------------------------------------------------------------------------
* Allocate a group of nodes and pool them for later use.
*/
static void Make()
{
for (SzType n = 16; n; --n)
{
// Create a new node instance
s_Nodes = new Node(s_Nodes);
// Validate the head node
if (!s_Nodes)
{
ThrowMemExcept("Unable to allocate memory nodes");
}
}
}
/* --------------------------------------------------------------------------------------------
* Retrieve an unused node from the free list.
*/
static Node * Pull()
{
if (!s_Nodes)
{
Make();
}
// Grab the head node
Node * node = s_Nodes;
// Promote the next node as the head
s_Nodes = node->mNext;
// Return the node
return node;
}
/* --------------------------------------------------------------------------------------------
* Return a node to the free list.
*/
static void Push(Node * node)
{
// See if the node is even valid
if (!node)
{
ThrowMemExcept("Attempting to push invalid node");
}
// Demote the current head node
node->mNext = s_Nodes;
// Promote as the head node
s_Nodes = node;
}
};
// ------------------------------------------------------------------------------------------------
MemCat::Node * MemCat::s_Nodes = NULL;
/* ------------------------------------------------------------------------------------------------
* Lightweight memory allocator to reduce the overhead of small allocations.
*/
class Memory
{
// --------------------------------------------------------------------------------------------
friend class Buffer;
friend class MemRef;
private:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Memory()
: m_Small()
, m_Medium()
, m_Large()
{
// Allocate several nodes for when memory starts pooling
MemCat::Make();
}
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Memory()
{
for (MemCat::Node * node = MemCat::s_Nodes, * next = NULL; node; node = next)
{
// Save the next node
next = node->mNext;
// Release the node instance
delete node;
}
// Explicitly set the head node to null
MemCat::s_Nodes = NULL;
}
private:
// --------------------------------------------------------------------------------------------
MemCat m_Small, m_Medium, m_Large;
};
// ------------------------------------------------------------------------------------------------
MemRef MemRef::s_Mem;
// ------------------------------------------------------------------------------------------------
void MemRef::Grab()
{
if (m_Ptr)
{
++(*m_Ref);
}
}
// ------------------------------------------------------------------------------------------------
Buffer::Buffer(SzType sz)
: m_Data(Alloc(sz)), m_Size(m_Data == nullptr ? 0 : sz)
void MemRef::Drop()
{
/* ... */
if (m_Ptr && --(*m_Ref) == 0)
{
delete m_Ptr;
delete m_Ref;
m_Ptr = NULL;
m_Ref = NULL;
}
}
// ------------------------------------------------------------------------------------------------
Buffer::Buffer(Buffer && o)
: m_Data(o.m_Data), m_Size(o.m_Size)
const MemRef & MemRef::Get()
{
o.m_Data = nullptr;
if (!s_Mem.m_Ptr)
{
s_Mem.m_Ptr = new Memory();
s_Mem.m_Ref = new Counter(1);
}
return s_Mem;
}
// ------------------------------------------------------------------------------------------------
Buffer::Pointer Buffer::s_Ptr = NULL;
Buffer::SzType Buffer::s_Cap = 0;
// ------------------------------------------------------------------------------------------------
Buffer::Buffer(const Buffer & o)
: m_Ptr(NULL)
, m_Cap(0)
, m_Mem(o.m_Mem)
{
if (m_Cap)
{
Request(o.m_Cap);
memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
}
}
// ------------------------------------------------------------------------------------------------
Buffer::~Buffer()
{
Free(m_Data);
if (m_Ptr)
{
Release();
}
}
// ------------------------------------------------------------------------------------------------
Buffer & Buffer::operator = (Buffer && o)
Buffer & Buffer::operator = (const Buffer & o)
{
if (m_Data != o.m_Data)
if (m_Ptr != o.m_Ptr)
{
m_Data = o.m_Data;
m_Size = o.m_Size;
o.m_Data = nullptr;
if (m_Cap && o.m_Cap <= m_Cap)
{
memcpy(m_Ptr, o.m_Ptr, m_Cap);
}
else if (!o.m_Cap)
{
if (m_Ptr)
{
Release();
}
}
else
{
if (m_Ptr)
{
Release();
}
Request(o.m_Cap);
memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
}
}
return *this;
}
// ------------------------------------------------------------------------------------------------
void Buffer::Resize(SzType sz)
void Buffer::Request(SzType n)
{
if (!sz)
// NOTE: Function assumes (n > 0)
// Is there a memory manager available?
if (!m_Mem)
{
Free(m_Data);
// Round up the size to a power of two number
n = (n & (n - 1)) ? NPow2(n) : n;
// Allocate the memory directly
m_Ptr = AllocMem(n);
}
else if (sz != m_Size)
// Find out in which category does this buffer reside
else if (n <= 1024)
{
Pointer data = m_Data;
m_Data = Alloc(sz);
if (sz > m_Size)
{
Copy(data, m_Size);
}
else
{
Copy(data, sz);
}
m_Size = sz;
Free(data);
m_Mem->m_Small.Grab(m_Ptr, n);
}
else if (n <= 4096)
{
m_Mem->m_Medium.Grab(m_Ptr, n);
}
else
{
m_Mem->m_Large.Grab(m_Ptr, n);
}
// If no errors occured then we can set the size
m_Cap= n;
}
// ------------------------------------------------------------------------------------------------
void Buffer::Reserve(SzType sz)
void Buffer::Release()
{
if (!sz)
// Is there a memory manager available?
if (!m_Mem)
{
return;
// Deallocate the memory directly
free(m_Ptr);
}
else if (sz > m_Size)
// Find out to which category does this buffer belong
else if (m_Cap <= 1024)
{
Pointer data = m_Data;
m_Data = Alloc(sz);
Copy(data, m_Size);
m_Size = sz;
Free(data);
m_Mem->m_Small.Drop(m_Ptr, m_Cap);
}
else if (m_Cap <= 4096)
{
m_Mem->m_Medium.Drop(m_Ptr, m_Cap);
}
else
{
m_Mem->m_Large.Drop(m_Ptr, m_Cap);
}
// Explicitly reset the buffer
m_Ptr = NULL;
m_Cap = 0;
}
// ------------------------------------------------------------------------------------------------
void Buffer::Copy(ConstPtr buf, SzType sz)
Buffer::SzType Buffer::Write(SzType pos, ConstPtr data, SzType size)
{
memcpy(m_Data, buf, sz * sizeof(Value));
// Make sure the pos is not out of bounds
if (pos > m_Cap || !data || !size)
{
return 0;
}
// See if the buffer size must be adjusted
else if ((pos + size) >= m_Cap)
{
// Backup current data
Buffer bkp = Adjust< Value >(pos + size);
// Copy data back from the old buffer
memcpy(m_Ptr, bkp.m_Ptr, bkp.m_Cap);
}
// Copy the data into the internal buffer
memcpy(m_Ptr + pos, data, size);
// Return the amount of data written to the buffer
return size;
}
// ------------------------------------------------------------------------------------------------
Buffer::Pointer Buffer::Alloc(SzType sz)
Buffer::SzType Buffer::WriteF(SzType pos, const char * fmt, ...)
{
Pointer mem = reinterpret_cast< Pointer >(malloc(sz * sizeof(Value)));
if (!mem)
// Make sure the pos is not out of bounds
if (pos > m_Cap)
{
return nullptr;
return 0;
}
return mem;
// Initialize the arguments list
va_list args;
va_start(args, fmt);
// Initial attempt to write to the current buffer
// (if empty, it should tell us the necessary size)
int ret = vsnprintf(m_Ptr + pos, m_Cap - pos, fmt, args);
// Do we need a bigger buffer?
if ((pos + ret) >= m_Cap)
{
// Backup current data
Buffer bkp = Adjust< Value >(pos + ret);
// Copy data back from the old buffer
memcpy(m_Ptr, bkp.m_Ptr, bkp.m_Cap);
// Argument list was modified during the initial format
va_end(args);
va_start(args, fmt);
// Resume writting the requested information
ret = vsnprintf(m_Ptr + pos, m_Cap - pos, fmt, args);
}
// Finalize the arguments list
va_end(args);
// Return the size of the written data in bytes
return (ret < 0) ? 0 : (SzType)ret;
}
// ------------------------------------------------------------------------------------------------
void Buffer::Free(Pointer buf)
Buffer::SzType Buffer::WriteF(SzType pos, const char * fmt, va_list args)
{
if (buf != nullptr)
// Make sure the pos is not out of bounds
if (pos > m_Cap)
{
free(buf);
return 0;
}
// Attempt to write to the current buffer
int ret = vsnprintf(m_Ptr + pos, m_Cap - pos, fmt, args);
// Return the size of the written data in bytes
return (ret < 0) ? 0 : (SzType)ret;
}
} // Namespace:: SqMod
} // Namespace:: SQMod

View File

@@ -2,227 +2,464 @@
#define _BASE_BUFFER_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include <assert.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
class Memory;
class Buffer;
/* ------------------------------------------------------------------------------------------------
* ...
* A counted reference to a memory manager instance.
*/
class MemRef
{
private:
// --------------------------------------------------------------------------------------------
static MemRef s_Mem;
// --------------------------------------------------------------------------------------------
typedef unsigned int Counter;
// --------------------------------------------------------------------------------------------
Memory* m_Ptr; /* The memory manager instance. */
Counter* m_Ref; /* Reference count to the managed instance. */
/* --------------------------------------------------------------------------------------------
* Grab a strong reference to a memory manager.
*/
void Grab();
/* --------------------------------------------------------------------------------------------
* Drop a strong reference to a memory manager.
*/
void Drop();
public:
/* --------------------------------------------------------------------------------------------
* Get a reference to the global memory manager instance.
*/
static const MemRef & Get();
/* --------------------------------------------------------------------------------------------
* Default constructor (null).
*/
MemRef()
: m_Ptr(s_Mem.m_Ptr), m_Ref(s_Mem.m_Ref)
{
Grab();
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
MemRef(const MemRef & o)
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
{
Grab();
}
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~MemRef()
{
Drop();
}
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
MemRef & operator = (const MemRef & o)
{
if (m_Ptr != o.m_Ptr)
{
Drop();
m_Ptr = o.m_Ptr;
m_Ref = o.m_Ref;
Grab();
}
return *this;
}
/* --------------------------------------------------------------------------------------------
* Perform an equality comparison between two memory managers.
*/
bool operator == (const MemRef & o) const
{
return (m_Ptr == o.m_Ptr);
}
/* --------------------------------------------------------------------------------------------
* Perform an inequality comparison between two memory managers.
*/
bool operator != (const MemRef & o) const
{
return (m_Ptr != o.m_Ptr);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean for use in boolean operations.
*/
operator bool () const
{
return m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* Member operator for dereferencing the managed pointer.
*/
Memory * operator -> () const
{
assert(m_Ptr != NULL);
return m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* Indirection operator for obtaining a reference of the managed pointer.
*/
Memory & operator * () const
{
assert(m_Ptr != NULL);
return *m_Ptr;
}
};
// ------------------------------------------------------------------------------------------------
void ThrowMemExcept(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Reusable buffer memory for quick allocations.
*/
class Buffer
{
public:
// --------------------------------------------------------------------------------------------
typedef SQChar Value;
typedef char Value; /* The type of value used to represent a byte. */
// --------------------------------------------------------------------------------------------
typedef Value & Reference;
typedef const Value & ConstRef;
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;
typedef const Value * ConstPtr;
typedef Value * Pointer; /* A pointer to the stored value type. */
typedef const Value * ConstPtr; /* A const pointer to the stored value type. */
// --------------------------------------------------------------------------------------------
typedef SQUint32 SzType;
typedef unsigned int SzType; /* The type used to represent size in general. */
/* --------------------------------------------------------------------------------------------
* ...
* Default constructor (null). Not null of a previous buffer was marked as movable.
*/
Buffer();
Buffer()
: m_Ptr(s_Ptr)
, m_Cap(s_Cap)
, m_Mem(MemRef::Get())
{
s_Ptr = NULL;
s_Cap = 0;
}
/* --------------------------------------------------------------------------------------------
* ...
* Explicit size constructor.
*/
Buffer(SzType sz);
Buffer(SzType n)
: m_Ptr(NULL)
, m_Cap(0)
, m_Mem(MemRef::Get())
{
Request(n < 8 ? 8 : n);
}
/* --------------------------------------------------------------------------------------------
* ...
* Copy constructor.
*/
Buffer(const Buffer &) = delete;
Buffer(const Buffer & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Buffer(Buffer && o);
/* --------------------------------------------------------------------------------------------
* ...
* Destructor.
*/
~Buffer();
/* --------------------------------------------------------------------------------------------
* ...
* Copy assignment operator.
*/
Buffer & operator = (const Buffer &) = delete;
Buffer & operator = (const Buffer & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Buffer & operator = (Buffer && o);
/* --------------------------------------------------------------------------------------------
* ...
* Equality comparison operator.
*/
bool operator == (const Buffer & o) const
{
return (m_Size == o.m_Size);
return (m_Cap == o.m_Cap);
}
/* --------------------------------------------------------------------------------------------
* ...
* Inequality comparison operator.
*/
bool operator != (const Buffer & o) const
{
return (m_Size != o.m_Size);
return (m_Cap != o.m_Cap);
}
/* --------------------------------------------------------------------------------------------
* ...
* Less than comparison operator.
*/
bool operator < (const Buffer & o) const
{
return (m_Size < o.m_Size);
return (m_Cap < o.m_Cap);
}
/* --------------------------------------------------------------------------------------------
* ...
* Greater than comparison operator.
*/
bool operator > (const Buffer & o) const
{
return (m_Size > o.m_Size);
return (m_Cap > o.m_Cap);
}
/* --------------------------------------------------------------------------------------------
* ...
* Less than or equal comparison operator.
*/
bool operator <= (const Buffer & o) const
{
return (m_Size <= o.m_Size);
return (m_Cap <= o.m_Cap);
}
/* --------------------------------------------------------------------------------------------
* ...
* Greater than or equal comparison operator.
*/
bool operator >= (const Buffer & o) const
{
return (m_Size >= o.m_Size);
return (m_Cap >= o.m_Cap);
}
/* --------------------------------------------------------------------------------------------
* ...
* Implicit conversion to boolean.
*/
operator bool () const
{
return (m_Data != nullptr);
return m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* ...
* Retrieve the internal buffer casted as a different type.
*/
operator ! () const
template < typename T > T * Get()
{
return (m_Data == nullptr);
return reinterpret_cast< T * >(m_Ptr);
}
/* --------------------------------------------------------------------------------------------
* ...
* Retrieve the internal buffer casted as a different type.
*/
Pointer Begin()
template < typename T > const T * Get() const
{
return m_Data;
return reinterpret_cast< const T * >(m_Ptr);
}
/* --------------------------------------------------------------------------------------------
* ...
* Retrieve the a certain element.
*/
ConstPtr Begin() const
template < typename T > T & At(SzType n)
{
return m_Data;
assert(n < m_Cap);
return reinterpret_cast< T * >(m_Ptr)[n];
}
/* --------------------------------------------------------------------------------------------
* ...
* Retrieve the a certain element.
*/
Pointer End()
template < typename T > const T & At(SzType n) const
{
return m_Data + m_Size;
assert(n < m_Cap);
return reinterpret_cast< const T * >(m_Ptr)[n];
}
/* --------------------------------------------------------------------------------------------
* ...
* Retrieve the internal buffer casted as a different type.
*/
ConstPtr End() const
template < typename T > T * Begin()
{
return m_Data + m_Size;
return reinterpret_cast< T * >(m_Ptr);
}
/* --------------------------------------------------------------------------------------------
* ...
* Retrieve the internal buffer casted as a different type.
*/
template < typename T > const T * Begin() const
{
return reinterpret_cast< const T * >(m_Ptr);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer casted as a different type.
*/
template < typename T > T * End()
{
return reinterpret_cast< T * >(m_Ptr) + (m_Cap / sizeof(T));
}
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer casted as a different type.
*/
template < typename T > const T * End() const
{
return reinterpret_cast< const T * >(m_Ptr) + (m_Cap / sizeof(T));
}
/* --------------------------------------------------------------------------------------------
* Retrieve the internal buffer.
*/
Pointer Data()
{
return m_Data;
return m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* ...
* Retrieve the internal buffer.
*/
ConstPtr Data() const
{
return m_Data;
return m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* ...
* Retrieve maximum elements it can hold for a certain type.
*/
SzType Size() const
template < typename T > static SzType Max()
{
return m_Size;
return (0xFFFFFFFF / sizeof(T));
}
/* --------------------------------------------------------------------------------------------
* ...
* Retrieve the current buffer capacity in element count.
*/
void Resize(SzType sz);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Reserve(SzType sz);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Increase(SzType sz)
template < typename T > SzType Size() const
{
Reserve(m_Size + sz);
return (m_Cap / sizeof(T));
}
/* --------------------------------------------------------------------------------------------
* Retrieve the current buffer capacity in byte count.
*/
SzType Capacity() const
{
return m_Cap;
}
/* --------------------------------------------------------------------------------------------
* Makes sure there is enough capacity to hold the specified element count.
*/
template < typename T > Buffer Adjust(SzType n)
{
if (n < 8)
{
n = 8;
}
// See if the requested capacity doesn't exceed the limit
if (n > Max< T >())
{
ThrowMemExcept("Requested buffer of (%u) elements exceeds the (%u) limit", n, Max< T >());
}
// Is there an existing buffer?
else if (n && !m_Cap)
{
// Request the memory
Request(n * sizeof(T));
}
// Should the size be increased?
else if (n > m_Cap)
{
// Backup the current memory
Move();
// Request the memory
Request(n * sizeof(T));
}
// Return an empty buffer or the backup (if any)
return Buffer();
}
/* --------------------------------------------------------------------------------------------
* Release the managed memory.
*/
void Reset()
{
if (m_Ptr)
{
Release();
}
}
/* --------------------------------------------------------------------------------------------
* Swap the contents of two buffers.
*/
void Swap(Buffer & o)
{
Pointer p = m_Ptr;
SzType n = m_Cap;
m_Ptr = o.m_Ptr;
m_Cap = o.m_Cap;
o.m_Ptr = p;
o.m_Cap = n;
}
/* --------------------------------------------------------------------------------------------
* Write a portion of a buffet to the internal buffer.
*/
SzType Write(SzType pos, ConstPtr data, SzType size);
/* --------------------------------------------------------------------------------------------
* Write a formatted string to the internal buffer.
*/
SzType WriteF(SzType pos, const char * fmt, ...);
/* --------------------------------------------------------------------------------------------
* Write a formatted string to the internal buffer.
*/
SzType WriteF(SzType pos, const char * fmt, va_list args);
protected:
/* --------------------------------------------------------------------------------------------
* ...
* Request the memory specified in the capacity.
*/
void Copy(ConstPtr buf, SzType sz);
void Request(SzType n);
/* --------------------------------------------------------------------------------------------
* ...
* Release the managed memory buffer.
*/
static Pointer Alloc(SzType sz);
void Release();
/* --------------------------------------------------------------------------------------------
* ...
* Moves the internal buffer to the global members to be taken over by the next instance.
*/
static void Free(Pointer buf);
void Move()
{
s_Ptr = m_Ptr;
s_Cap = m_Cap;
m_Ptr = NULL;
m_Cap = 0;
}
private:
// --------------------------------------------------------------------------------------------
Pointer m_Data;
SzType m_Size;
Pointer m_Ptr; /* Pointer to the memory buffer. */
SzType m_Cap; /* The total size of the buffer. */
// --------------------------------------------------------------------------------------------
MemRef m_Mem;
// --------------------------------------------------------------------------------------------
static Pointer s_Ptr; /* Pointer to a moved memory buffer. */
static SzType s_Cap; /* The total size of the moved buffer. */
};
} // Namespace:: SqMod

View File

@@ -1,6 +1,7 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Circle.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -8,7 +9,7 @@ namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Circle Circle::NIL = Circle();
const Circle Circle::MIN = Circle(0.0);
const Circle Circle::MAX = Circle(std::numeric_limits<Circle::Value>::max());
const Circle Circle::MAX = Circle(NumLimit< Circle::Value >::Max);
// ------------------------------------------------------------------------------------------------
SQChar Circle::Delim = ',';
@@ -17,42 +18,33 @@ SQChar Circle::Delim = ',';
Circle::Circle()
: pos(0.0, 0.0), rad(0.0)
{
}
Circle::Circle(Value r)
: pos(0.0, 0.0), rad(r)
{
}
Circle::Circle(const Vector2f & p)
: pos(p), rad(0.0)
{
}
Circle::Circle(const Vector2f & p, Value r)
: pos(p), rad(r)
{
}
Circle::Circle(Value x, Value y, Value r)
: pos(x, y), rad(r)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Circle::Circle(const Circle & c)
: pos(c.pos), rad(c.rad)
Circle::Circle(Value rv)
: pos(0.0, 0.0), rad(rv)
{
/* ... */
}
Circle::Circle(Circle && c)
: pos(c.pos), rad(c.rad)
// ------------------------------------------------------------------------------------------------
Circle::Circle(const Vector2 & pv, Value rv)
: pos(pv), rad(rv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Circle::Circle(Value xv, Value yv, Value rv)
: pos(xv, yv), rad(rv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Circle::Circle(const Circle & o)
: pos(o.pos), rad(o.rad)
{
}
@@ -60,21 +52,14 @@ Circle::Circle(Circle && c)
// ------------------------------------------------------------------------------------------------
Circle::~Circle()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Circle & Circle::operator = (const Circle & c)
Circle & Circle::operator = (const Circle & o)
{
pos = c.pos;
rad = c.rad;
return *this;
}
Circle & Circle::operator = (Circle && c)
{
pos = c.pos;
rad = c.rad;
pos = o.pos;
rad = o.rad;
return *this;
}
@@ -85,7 +70,7 @@ Circle & Circle::operator = (Value r)
return *this;
}
Circle & Circle::operator = (const Vector2f & p)
Circle & Circle::operator = (const Vector2 & p)
{
pos = p;
return *this;
@@ -123,7 +108,7 @@ Circle & Circle::operator /= (const Circle & c)
Circle & Circle::operator %= (const Circle & c)
{
pos %= c.pos;
rad = std::fmod(rad, c.rad);
rad = fmod(rad, c.rad);
return *this;
}
@@ -155,36 +140,36 @@ Circle & Circle::operator /= (Value r)
Circle & Circle::operator %= (Value r)
{
rad = std::fmod(rad, r);
rad = fmod(rad, r);
return *this;
}
// ------------------------------------------------------------------------------------------------
Circle & Circle::operator += (const Vector2f & p)
Circle & Circle::operator += (const Vector2 & p)
{
pos += p;
return *this;
}
Circle & Circle::operator -= (const Vector2f & p)
Circle & Circle::operator -= (const Vector2 & p)
{
pos -= p;
return *this;
}
Circle & Circle::operator *= (const Vector2f & p)
Circle & Circle::operator *= (const Vector2 & p)
{
pos *= p;
return *this;
}
Circle & Circle::operator /= (const Vector2f & p)
Circle & Circle::operator /= (const Vector2 & p)
{
pos /= p;
return *this;
}
Circle & Circle::operator %= (const Vector2f & p)
Circle & Circle::operator %= (const Vector2 & p)
{
pos %= p;
return *this;
@@ -245,7 +230,7 @@ Circle Circle::operator / (const Circle & c) const
Circle Circle::operator % (const Circle & c) const
{
return Circle(pos % c.pos, std::fmod(rad, c.rad));
return Circle(pos % c.pos, fmod(rad, c.rad));
}
// ------------------------------------------------------------------------------------------------
@@ -271,39 +256,39 @@ Circle Circle::operator / (Value r) const
Circle Circle::operator % (Value r) const
{
return Circle(std::fmod(rad, r));
return Circle(fmod(rad, r));
}
// ------------------------------------------------------------------------------------------------
Circle Circle::operator + (const Vector2f & p) const
Circle Circle::operator + (const Vector2 & p) const
{
return Circle(pos + p);
return Circle(pos + p, rad);
}
Circle Circle::operator - (const Vector2f & p) const
Circle Circle::operator - (const Vector2 & p) const
{
return Circle(pos - p);
return Circle(pos - p, rad);
}
Circle Circle::operator * (const Vector2f & p) const
Circle Circle::operator * (const Vector2 & p) const
{
return Circle(pos * p);
return Circle(pos * p, rad);
}
Circle Circle::operator / (const Vector2f & p) const
Circle Circle::operator / (const Vector2 & p) const
{
return Circle(pos / p);
return Circle(pos / p, rad);
}
Circle Circle::operator % (const Vector2f & p) const
Circle Circle::operator % (const Vector2 & p) const
{
return Circle(pos % p);
return Circle(pos % p, rad);
}
// ------------------------------------------------------------------------------------------------
Circle Circle::operator + () const
{
return Circle(pos.Abs(), std::fabs(rad));
return Circle(pos.Abs(), fabs(rad));
}
Circle Circle::operator - () const
@@ -314,42 +299,47 @@ Circle Circle::operator - () const
// ------------------------------------------------------------------------------------------------
bool Circle::operator == (const Circle & c) const
{
return (rad == c.rad) && (pos == c.pos);
return EpsEq(rad, c.rad) && (pos == c.pos);
}
bool Circle::operator != (const Circle & c) const
{
return (rad != c.rad) && (pos != c.pos);
return !EpsEq(rad, c.rad) && (pos != c.pos);
}
bool Circle::operator < (const Circle & c) const
{
return (rad < c.rad) && (pos < c.pos);
return EpsLt(rad, c.rad) && (pos < c.pos);
}
bool Circle::operator > (const Circle & c) const
{
return (rad > c.rad) && (pos > c.pos);
return EpsGt(rad, c.rad) && (pos > c.pos);
}
bool Circle::operator <= (const Circle & c) const
{
return (rad <= c.rad) && (pos <= c.pos);
return EpsLtEq(rad, c.rad) && (pos <= c.pos);
}
bool Circle::operator >= (const Circle & c) const
{
return (rad >= c.rad) && (pos >= c.pos);
return EpsGtEq(rad, c.rad) && (pos >= c.pos);
}
// ------------------------------------------------------------------------------------------------
SQInteger Circle::Cmp(const Circle & c) const
Int32 Circle::Cmp(const Circle & o) const
{
return *this == c ? 0 : (*this > c ? 1 : -1);
if (*this == o)
return 0;
else if (*this > o)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
const SQChar * Circle::ToString() const
CSStr Circle::ToString() const
{
return ToStringF("%f,%f,%f", pos.x, pos.y, rad);
}
@@ -366,12 +356,12 @@ void Circle::Set(const Circle & nc)
rad = nc.rad;
}
void Circle::Set(const Vector2f & np)
void Circle::Set(const Vector2 & np)
{
pos = np;
}
void Circle::Set(const Vector2f & np, Value nr)
void Circle::Set(const Vector2 & np, Value nr)
{
pos = np;
rad = nr;
@@ -390,7 +380,7 @@ void Circle::Set(Value nx, Value ny, Value nr)
}
// ------------------------------------------------------------------------------------------------
void Circle::Set(const SQChar * values, SQChar delim)
void Circle::Set(CSStr values, SQChar delim)
{
Set(GetCircle(values, delim));
}
@@ -399,18 +389,18 @@ void Circle::Set(const SQChar * values, SQChar delim)
void Circle::Generate()
{
pos.Generate();
rad = RandomVal<Value>::Get();
rad = GetRandomFloat32();
}
void Circle::Generate(Value min, Value max, bool r)
{
if (max < min)
if (EpsLt(max, min))
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else if (r)
{
rad = RandomVal<Value>::Get(min, max);
rad = GetRandomFloat32(min, max);
}
else
{
@@ -425,63 +415,62 @@ 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 (std::isless(rmax, rmin))
if (EpsLt(rmax, rmin))
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
pos.Generate(xmin, xmax, ymin, ymax);
rad = RandomVal<Value>::Get(rmin, rmax);
rad = GetRandomFloat32(rmin, rmax);
}
}
// ------------------------------------------------------------------------------------------------
Circle Circle::Abs() const
{
return Circle(pos.Abs(), std::fabs(rad));
return Circle(pos.Abs(), fabs(rad));
}
// ------------------------------------------------------------------------------------------------
bool Register_Circle(HSQUIRRELVM vm)
// ================================================================================================
void Register_Circle(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Circle> type");
typedef Circle::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Circle"), Sqrat::Class<Circle>(vm, _SC("Circle"))
RootTable(vm).Bind(_SC("Circle"), Class< Circle >(vm, _SC("Circle"))
/* Constructors */
.Ctor()
.Ctor<Val>()
.Ctor<const Vector2f &, Val>()
.Ctor<Val, Val, Val>()
.SetStaticValue(_SC("delim"), &Circle::Delim)
.Ctor< Val >()
.Ctor< const Vector2 &, Val >()
.Ctor< Val, Val, Val >()
/* 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 */
.Func(_SC("_tostring"), &Circle::ToString)
.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 -)
.Overload<void (Circle::*)(const Circle &)>(_SC("set"), &Circle::Set)
.Overload<void (Circle::*)(const Vector2f &, Val)>(_SC("set"), &Circle::Set)
.Overload<void (Circle::*)(Val, Val, Val)>(_SC("set"), &Circle::Set)
.Overload<void (Circle::*)(Val)>(_SC("set_rad"), &Circle::Set)
.Overload<void (Circle::*)(const Vector2f &)>(_SC("set_vec2"), &Circle::Set)
.Overload<void (Circle::*)(Val, Val)>(_SC("set_vec2"), &Circle::Set)
.Overload<void (Circle::*)(const SQChar *, SQChar)>(_SC("set_str"), &Circle::Set)
.Func(_SC("clear"), &Circle::Clear)
/* 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 *=)
@@ -494,11 +483,11 @@ bool Register_Circle(HSQUIRRELVM vm)
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opDivAssignR"), &Circle::operator /=)
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opModAssignR"), &Circle::operator %=)
.Func<Circle & (Circle::*)(const Vector2f &)>(_SC("opAddAssignP"), &Circle::operator +=)
.Func<Circle & (Circle::*)(const Vector2f &)>(_SC("opSubAssignP"), &Circle::operator -=)
.Func<Circle & (Circle::*)(const Vector2f &)>(_SC("opMulAssignP"), &Circle::operator *=)
.Func<Circle & (Circle::*)(const Vector2f &)>(_SC("opDivAssignP"), &Circle::operator /=)
.Func<Circle & (Circle::*)(const Vector2f &)>(_SC("opModAssignP"), &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 --)
@@ -517,11 +506,11 @@ bool Register_Circle(HSQUIRRELVM vm)
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opDivR"), &Circle::operator /)
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opModR"), &Circle::operator %)
.Func<Circle (Circle::*)(const Vector2f &) const>(_SC("opAddP"), &Circle::operator +)
.Func<Circle (Circle::*)(const Vector2f &) const>(_SC("opSubP"), &Circle::operator -)
.Func<Circle (Circle::*)(const Vector2f &) const>(_SC("opMulP"), &Circle::operator *)
.Func<Circle (Circle::*)(const Vector2f &) const>(_SC("opDivP"), &Circle::operator /)
.Func<Circle (Circle::*)(const Vector2f &) const>(_SC("opModP"), &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 -)
@@ -533,10 +522,6 @@ bool Register_Circle(HSQUIRRELVM vm)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opLessEqual"), &Circle::operator <=)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opGreaterEqual"), &Circle::operator >=)
);
LogDbg("Registration of <Circle> type was successful");
return true;
}
} // Namespace:: SqMod

View File

@@ -2,21 +2,21 @@
#define _BASE_CIRCLE_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "Base/Vector2f.hpp"
#include "SqBase.hpp"
#include "Base/Vector2.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct Circle
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef SQFloat Value;
typedef float Value;
/* --------------------------------------------------------------------------------------------
* ...
@@ -33,58 +33,43 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f pos;
Vector2 pos;
Value rad;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Circle();
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle(Value r);
Circle(Value rv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle(const Vector2f & p);
Circle(const Vector2 & pv, Value rv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle(const Vector2f & p, Value r);
Circle(Value xv, Value yv, Value rv);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Circle(Value x, Value y, Value r);
Circle(const Circle & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle(const Circle & c);
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle(Circle && c);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
~Circle();
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Circle & operator = (const Circle & c);
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle & operator = (Circle && c);
Circle & operator = (const Circle & o);
/* --------------------------------------------------------------------------------------------
* ...
@@ -94,7 +79,7 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle & operator = (const Vector2f & p);
Circle & operator = (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* ...
@@ -149,27 +134,27 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle & operator += (const Vector2f & p);
Circle & operator += (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle & operator -= (const Vector2f & p);
Circle & operator -= (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle & operator *= (const Vector2f & p);
Circle & operator *= (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle & operator /= (const Vector2f & p);
Circle & operator /= (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle & operator %= (const Vector2f & p);
Circle & operator %= (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* ...
@@ -244,27 +229,27 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle operator + (const Vector2f & p) const;
Circle operator + (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle operator - (const Vector2f & p) const;
Circle operator - (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle operator * (const Vector2f & p) const;
Circle operator * (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle operator / (const Vector2f & p) const;
Circle operator / (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Circle operator % (const Vector2f & p) const;
Circle operator % (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -309,12 +294,12 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Circle & c) const;
Int32 Cmp(const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -329,12 +314,12 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector2f & np);
void Set(const Vector2 & np);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector2f & np, Value nr);
void Set(const Vector2 & np, Value nr);
/* --------------------------------------------------------------------------------------------
* ...
@@ -349,7 +334,7 @@ struct Circle
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * values, SQChar delim);
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...

View File

@@ -1,15 +1,16 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Color3.hpp"
#include "Base/Color4.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Color3 Color3::NIL = Color3();
const Color3 Color3::MIN = Color3(std::numeric_limits<Color3::Value>::min());
const Color3 Color3::MAX = Color3(std::numeric_limits<Color3::Value>::max());
const Color3 Color3::MIN = Color3(NumLimit< Color3::Value >::Min);
const Color3 Color3::MAX = Color3(NumLimit< Color3::Value >::Max);
// ------------------------------------------------------------------------------------------------
SQChar Color3::Delim = ',';
@@ -18,74 +19,42 @@ SQChar Color3::Delim = ',';
Color3::Color3()
: r(0), g(0), b(0)
{
/* ... */
}
Color3::Color3(Value s)
: r(s), g(s), b(s)
// ------------------------------------------------------------------------------------------------
Color3::Color3(Value sv)
: r(sv), g(sv), b(sv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color3::Color3(Value rv, Value gv, Value bv)
: r(rv), g(gv), b(bv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color3::Color3(const Color4 & c)
: r(c.r), g(c.g), b(c.b)
Color3::Color3(const Color3 & o)
: r(o.r), g(o.g), b(o.b)
{
}
// ------------------------------------------------------------------------------------------------
Color3::Color3(const SQChar * name)
: Color3(GetColor(name))
{
}
Color3::Color3(const SQChar * str, SQChar delim)
: Color3(GetColor3(str, delim))
{
}
// ------------------------------------------------------------------------------------------------
Color3::Color3(const Color3 & c)
: r(c.r), g(c.g), b(c.b)
{
}
Color3::Color3(Color3 && c)
: r(c.r), g(c.g), b(c.b)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color3::~Color3()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color3 & Color3::operator = (const Color3 & c)
Color3 & Color3::operator = (const Color3 & o)
{
r = c.r;
g = c.g;
b = c.b;
return *this;
}
Color3 & Color3::operator = (Color3 && c)
{
r = c.r;
g = c.g;
b = c.b;
r = o.r;
g = o.g;
b = o.b;
return *this;
}
@@ -98,7 +67,7 @@ Color3 & Color3::operator = (Value s)
return *this;
}
Color3 & Color3::operator = (const SQChar * name)
Color3 & Color3::operator = (CSStr name)
{
Set(GetColor(name));
return *this;
@@ -467,13 +436,18 @@ Color3::operator Color4 () const
}
// ------------------------------------------------------------------------------------------------
SQInteger Color3::Cmp(const Color3 & c) const
Int32 Color3::Cmp(const Color3 & o) const
{
return *this == c ? 0 : (*this > c ? 1 : -1);
if (*this == o)
return 0;
else if (*this > o)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
const SQChar * Color3::ToString() const
CSStr Color3::ToString() const
{
return ToStringF("%u,%u,%u", r, g, b);
}
@@ -509,75 +483,75 @@ void Color3::Set(const Color4 & c)
}
// ------------------------------------------------------------------------------------------------
void Color3::Set(const SQChar * str, SQChar delim)
void Color3::Set(CSStr str, SQChar delim)
{
Set(GetColor3(str, delim));
}
// ------------------------------------------------------------------------------------------------
void Color3::SetCol(const SQChar * name)
void Color3::SetCol(CSStr name)
{
Set(GetColor(name));
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color3::GetRGB() const
Uint32 Color3::GetRGB() const
{
return static_cast<SQUint32>(r << 16 | g << 8 | b);
return Uint32(r << 16 | g << 8 | b);
}
void Color3::SetRGB(SQUint32 p)
void Color3::SetRGB(Uint32 p)
{
r = static_cast<Value>((p >> 16) & 0xFF);
g = static_cast<Value>((p >> 8) & 0xFF);
b = static_cast<Value>((p) & 0xFF);
r = Value((p >> 16) & 0xFF);
g = Value((p >> 8) & 0xFF);
b = Value((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color3::GetRGBA() const
Uint32 Color3::GetRGBA() const
{
return static_cast<SQUint32>(r << 24 | g << 16 | b << 8 | 0x00);
return Uint32(r << 24 | g << 16 | b << 8 | 0x00);
}
void Color3::SetRGBA(SQUint32 p)
void Color3::SetRGBA(Uint32 p)
{
r = static_cast<Value>((p >> 24) & 0xFF);
g = static_cast<Value>((p >> 16) & 0xFF);
b = static_cast<Value>((p >> 8) & 0xFF);
r = Value((p >> 24) & 0xFF);
g = Value((p >> 16) & 0xFF);
b = Value((p >> 8) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color3::GetARGB() const
Uint32 Color3::GetARGB() const
{
return static_cast<SQUint32>(0x00 << 24 | r << 16 | g << 8 | b);
return Uint32(0x00 << 24 | r << 16 | g << 8 | b);
}
void Color3::SetARGB(SQUint32 p)
void Color3::SetARGB(Uint32 p)
{
r = static_cast<Value>((p >> 16) & 0xFF);
g = static_cast<Value>((p >> 8) & 0xFF);
b = static_cast<Value>((p) & 0xFF);
r = Value((p >> 16) & 0xFF);
g = Value((p >> 8) & 0xFF);
b = Value((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
void Color3::Generate()
{
r = RandomVal<Value>::Get();
g = RandomVal<Value>::Get();
b = RandomVal<Value>::Get();
r = GetRandomUint8();
g = GetRandomUint8();
b = GetRandomUint8();
}
void Color3::Generate(Value min, Value max)
{
if (max < min)
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
r = RandomVal<Value>::Get(min, max);
g = RandomVal<Value>::Get(min, max);
b = RandomVal<Value>::Get(min, max);
r = GetRandomUint8(min, max);
g = GetRandomUint8(min, max);
b = GetRandomUint8(min, max);
}
}
@@ -585,13 +559,13 @@ void Color3::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin
{
if (rmax < rmin || gmax < gmin || bmax < bmin)
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
r = RandomVal<Value>::Get(rmin, rmax);
g = RandomVal<Value>::Get(gmin, gmax);
b = RandomVal<Value>::Get(bmin, bmax);
r = GetRandomUint8(rmin, rmax);
g = GetRandomUint8(gmin, gmax);
b = GetRandomUint8(bmin, bmax);
}
}
@@ -604,59 +578,57 @@ void Color3::Random()
// ------------------------------------------------------------------------------------------------
void Color3::Inverse()
{
r = static_cast<Value>(~r);
g = static_cast<Value>(~g);
b = static_cast<Value>(~b);
r = Value(~r);
g = Value(~g);
b = Value(~b);
}
// ================================================================================================
bool Register_Color3(HSQUIRRELVM vm)
void Register_Color3(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Color3> type");
typedef Color3::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Color3"), Sqrat::Class<Color3>(vm, _SC("Color3"))
RootTable(vm).Bind(_SC("Color3"), Class< Color3 >(vm, _SC("Color3"))
/* Constructors */
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Color3::Delim)
.Ctor< Val >()
.Ctor< Val, Val, Val >()
/* 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 */
.Func(_SC("_tostring"), &Color3::ToString)
.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 -)
.Overload<void (Color3::*)(Val)>(_SC("set"), &Color3::Set)
.Overload<void (Color3::*)(Val, Val, Val)>(_SC("set"), &Color3::Set)
.Overload<void (Color3::*)(const Color3 &)>(_SC("set_col3"), &Color3::Set)
.Overload<void (Color3::*)(const Color4 &)>(_SC("set_col4"), &Color3::Set)
.Overload<void (Color3::*)(const SQChar *, SQChar)>(_SC("set_str"), &Color3::Set)
.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)
.Func(_SC("clear"), &Color3::Clear)
.Func(_SC("random"), &Color3::Random)
.Func(_SC("inverse"), &Color3::Inverse)
/* 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 *=)
@@ -717,10 +689,6 @@ bool Register_Color3(HSQUIRRELVM vm)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessEqual"), &Color3::operator <=)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterEqual"), &Color3::operator >=)
);
LogDbg("Registration of <Color3> type was successful");
return true;
}
} // Namespace:: SqMod

View File

@@ -2,20 +2,20 @@
#define _BASE_COLOR3_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct Color3
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef Uint8 Value;
typedef unsigned char Value;
/* --------------------------------------------------------------------------------------------
* ...
@@ -35,59 +35,34 @@ struct Color3
Value r, g, b;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Color3();
/* --------------------------------------------------------------------------------------------
* ...
*/
Color3(Value s);
Color3(Value sv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color3(Value r, Value g, Value b);
Color3(Value rv, Value gv, Value bv);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Color3(const Color4 & c);
Color3(const Color3 & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color3(const SQChar * name);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color3(const SQChar * str, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color3(const Color3 & c);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color3(Color3 && c);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
~Color3();
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Color3 & operator = (const Color3 & c);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color3 & operator = (Color3 && c);
Color3 & operator = (const Color3 & o);
/* --------------------------------------------------------------------------------------------
* ...
@@ -97,7 +72,7 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* ...
*/
Color3 & operator = (const SQChar * name);
Color3 & operator = (CSStr name);
/* --------------------------------------------------------------------------------------------
* ...
@@ -377,12 +352,12 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Color3 & c) const;
Int32 Cmp(const Color3 & c) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -407,42 +382,42 @@ struct Color3
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * str, SQChar delim);
void Set(CSStr str, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetCol(const SQChar * name);
void SetCol(CSStr name);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQUint32 GetRGB() const;
Uint32 GetRGB() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetRGB(SQUint32 p);
void SetRGB(Uint32 p);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQUint32 GetRGBA() const;
Uint32 GetRGBA() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetRGBA(SQUint32 p);
void SetRGBA(Uint32 p);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQUint32 GetARGB() const;
Uint32 GetARGB() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetARGB(SQUint32 p);
void SetARGB(Uint32 p);
/* --------------------------------------------------------------------------------------------
* ...

View File

@@ -1,15 +1,16 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Color4.hpp"
#include "Base/Color3.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Color4 Color4::NIL = Color4();
const Color4 Color4::MIN = Color4(std::numeric_limits<Color4::Value>::min());
const Color4 Color4::MAX = Color4(std::numeric_limits<Color4::Value>::max());
const Color4 Color4::MIN = Color4(NumLimit< Color4::Value >::Min);
const Color4 Color4::MAX = Color4(NumLimit< Color4::Value >::Max);
// ------------------------------------------------------------------------------------------------
SQChar Color4::Delim = ',';
@@ -18,82 +19,50 @@ SQChar Color4::Delim = ',';
Color4::Color4()
: r(0), g(0), b(0), a(0)
{
/* ... */
}
Color4::Color4(Value s)
: r(s), g(s), b(s), a(s)
// ------------------------------------------------------------------------------------------------
Color4::Color4(Value sv)
: r(sv), g(sv), b(sv), a(sv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color4::Color4(Value rv, Value gv, Value bv)
: r(rv), g(gv), b(bv), a(0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color4::Color4(Value rv, Value gv, Value bv, Value av)
: r(rv), g(gv), b(bv), a(av)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color4::Color4(const Color3 & c)
: r(c.r), g(c.g), b(c.b), a(0)
Color4::Color4(const Color4 & o)
: r(o.r), g(o.g), b(o.b), a(o.a)
{
}
// ------------------------------------------------------------------------------------------------
Color4::Color4(const SQChar * name)
: Color4(GetColor(name))
{
}
Color4::Color4(const SQChar * str, SQChar delim)
: Color4(GetColor4(str, delim))
{
}
// ------------------------------------------------------------------------------------------------
Color4::Color4(const Color4 & c)
: r(c.r), g(c.g), b(c.b), a(c.a)
{
}
Color4::Color4(Color4 && c)
: r(c.r), g(c.g), b(c.b), a(c.a)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color4::~Color4()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Color4 & Color4::operator = (const Color4 & c)
Color4 & Color4::operator = (const Color4 & o)
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
return *this;
}
Color4 & Color4::operator = (Color4 && c)
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
r = o.r;
g = o.g;
b = o.b;
a = o.a;
return *this;
}
@@ -107,7 +76,7 @@ Color4 & Color4::operator = (Value s)
return *this;
}
Color4 & Color4::operator = (const SQChar * name)
Color4 & Color4::operator = (CSStr name)
{
Set(GetColor(name));
return *this;
@@ -500,13 +469,18 @@ Color4::operator Color3 () const
}
// ------------------------------------------------------------------------------------------------
SQInteger Color4::Cmp(const Color4 & c) const
Int32 Color4::Cmp(const Color4 & o) const
{
return *this == c ? 0 : (*this > c ? 1 : -1);
if (*this == o)
return 0;
else if (*this > o)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
const SQChar * Color4::ToString() const
CSStr Color4::ToString() const
{
return ToStringF("%u,%u,%u,%u", r, g, b, a);
}
@@ -553,79 +527,79 @@ void Color4::Set(const Color3 & c)
}
// ------------------------------------------------------------------------------------------------
void Color4::Set(const SQChar * str, SQChar delim)
void Color4::Set(CSStr str, SQChar delim)
{
Set(GetColor4(str, delim));
}
// ------------------------------------------------------------------------------------------------
void Color4::SetCol(const SQChar * name)
void Color4::SetCol(CSStr name)
{
Set(GetColor(name));
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color4::GetRGB() const
Uint32 Color4::GetRGB() const
{
return static_cast<SQUint32>(r << 16 | g << 8 | b);
return Uint32(r << 16 | g << 8 | b);
}
void Color4::SetRGB(SQUint32 p)
void Color4::SetRGB(Uint32 p)
{
r = static_cast<Value>((p >> 16) & 0xFF);
g = static_cast<Value>((p >> 8) & 0xFF);
b = static_cast<Value>((p) & 0xFF);
r = Value((p >> 16) & 0xFF);
g = Value((p >> 8) & 0xFF);
b = Value((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color4::GetRGBA() const
Uint32 Color4::GetRGBA() const
{
return static_cast<SQUint32>(r << 24 | g << 16 | b << 8 | a);
return Uint32(r << 24 | g << 16 | b << 8 | a);
}
void Color4::SetRGBA(SQUint32 p)
void Color4::SetRGBA(Uint32 p)
{
r = static_cast<Value>((p >> 24) & 0xFF);
g = static_cast<Value>((p >> 16) & 0xFF);
b = static_cast<Value>((p >> 8) & 0xFF);
a = static_cast<Value>((p) & 0xFF);
r = Value((p >> 24) & 0xFF);
g = Value((p >> 16) & 0xFF);
b = Value((p >> 8) & 0xFF);
a = Value((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color4::GetARGB() const
Uint32 Color4::GetARGB() const
{
return static_cast<SQUint32>(a << 24 | r << 16 | g << 8 | b);
return Uint32(a << 24 | r << 16 | g << 8 | b);
}
void Color4::SetARGB(SQUint32 p)
void Color4::SetARGB(Uint32 p)
{
a = static_cast<Value>((p >> 24) & 0xFF);
r = static_cast<Value>((p >> 16) & 0xFF);
g = static_cast<Value>((p >> 8) & 0xFF);
b = static_cast<Value>((p) & 0xFF);
a = Value((p >> 24) & 0xFF);
r = Value((p >> 16) & 0xFF);
g = Value((p >> 8) & 0xFF);
b = Value((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
void Color4::Generate()
{
r = RandomVal<Value>::Get();
g = RandomVal<Value>::Get();
b = RandomVal<Value>::Get();
a = RandomVal<Value>::Get();
r = GetRandomUint8();
g = GetRandomUint8();
b = GetRandomUint8();
a = GetRandomUint8();
}
void Color4::Generate(Value min, Value max)
{
if (max < min)
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
r = RandomVal<Value>::Get(min, max);
g = RandomVal<Value>::Get(min, max);
b = RandomVal<Value>::Get(min, max);
a = RandomVal<Value>::Get(min, max);
r = GetRandomUint8(min, max);
g = GetRandomUint8(min, max);
b = GetRandomUint8(min, max);
a = GetRandomUint8(min, max);
}
}
@@ -633,14 +607,14 @@ void Color4::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin
{
if (rmax < rmin || gmax < gmin || bmax < bmin || amax < amin)
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
r = RandomVal<Value>::Get(rmin, rmax);
g = RandomVal<Value>::Get(gmin, gmax);
b = RandomVal<Value>::Get(bmin, bmax);
a = RandomVal<Value>::Get(bmin, bmax);
r = GetRandomUint8(rmin, rmax);
g = GetRandomUint8(gmin, gmax);
b = GetRandomUint8(bmin, bmax);
a = GetRandomUint8(bmin, bmax);
}
}
@@ -653,63 +627,61 @@ void Color4::Random()
// ------------------------------------------------------------------------------------------------
void Color4::Inverse()
{
r = static_cast<Value>(~r);
g = static_cast<Value>(~g);
b = static_cast<Value>(~b);
a = static_cast<Value>(~a);
r = Value(~r);
g = Value(~g);
b = Value(~b);
a = Value(~a);
}
// ================================================================================================
bool Register_Color4(HSQUIRRELVM vm)
void Register_Color4(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Color4> type");
typedef Color4::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Color4"), Sqrat::Class<Color4>(vm, _SC("Color4"))
RootTable(vm).Bind(_SC("Color4"), Class< Color4 >(vm, _SC("Color4"))
/* Constructors */
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<Val, Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Color4::Delim)
.Ctor< Val >()
.Ctor< Val, Val, Val >()
.Ctor< Val, Val, Val, Val >()
/* 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 */
.Func(_SC("_tostring"), &Color4::ToString)
.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 -)
.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("set_col4"), &Color4::Set)
.Overload<void (Color4::*)(const Color3 &)>(_SC("set_col3"), &Color4::Set)
.Overload<void (Color4::*)(const SQChar *, SQChar)>(_SC("set_str"), &Color4::Set)
.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)
.Func(_SC("clear"), &Color4::Clear)
.Func(_SC("random"), &Color4::Random)
.Func(_SC("inverse"), &Color4::Inverse)
/* 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 *=)
@@ -770,10 +742,6 @@ bool Register_Color4(HSQUIRRELVM vm)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opLessEqual"), &Color4::operator <=)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opGreaterEqual"), &Color4::operator >=)
);
LogDbg("Registration of <Color4> type was successful");
return true;
}
} // Namespace:: SqMod

View File

@@ -2,20 +2,20 @@
#define _BASE_COLOR4_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct Color4
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef Uint8 Value;
typedef unsigned char Value;
/* --------------------------------------------------------------------------------------------
* ...
@@ -35,64 +35,39 @@ struct Color4
Value r, g, b, a;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Color4();
/* --------------------------------------------------------------------------------------------
* ...
*/
Color4(Value s);
Color4(Value sv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color4(Value r, Value g, Value b);
Color4(Value rv, Value gv, Value bv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color4(Value r, Value g, Value b, Value a);
Color4(Value rv, Value gv, Value bv, Value av);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Color4(const Color3 & c);
Color4(const Color4 & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color4(const SQChar * name);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color4(const SQChar * str, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color4(const Color4 & c);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color4(Color4 && c);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
~Color4();
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Color4 & operator = (const Color4 & c);
/* --------------------------------------------------------------------------------------------
* ...
*/
Color4 & operator = (Color4 && c);
Color4 & operator = (const Color4 & o);
/* --------------------------------------------------------------------------------------------
* ...
@@ -102,7 +77,7 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* ...
*/
Color4 & operator = (const SQChar * name);
Color4 & operator = (CSStr name);
/* --------------------------------------------------------------------------------------------
* ...
@@ -382,12 +357,12 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Color4 & c) const;
Int32 Cmp(const Color4 & c) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -417,42 +392,42 @@ struct Color4
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * name, SQChar delim);
void Set(CSStr name, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetCol(const SQChar * name);
void SetCol(CSStr name);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQUint32 GetRGB() const;
Uint32 GetRGB() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetRGB(SQUint32 p);
void SetRGB(Uint32 p);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQUint32 GetRGBA() const;
Uint32 GetRGBA() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetRGBA(SQUint32 p);
void SetRGBA(Uint32 p);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQUint32 GetARGB() const;
Uint32 GetARGB() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetARGB(SQUint32 p);
void SetARGB(Uint32 p);
/* --------------------------------------------------------------------------------------------
* ...

View File

@@ -1,16 +1,17 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Quaternion.hpp"
#include "Base/Vector3.hpp"
#include "Base/Vector4.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Quaternion Quaternion::NIL = Quaternion(0);
const Quaternion Quaternion::MIN = Quaternion(std::numeric_limits<Quaternion::Value>::min());
const Quaternion Quaternion::MAX = Quaternion(std::numeric_limits<Quaternion::Value>::max());
const Quaternion Quaternion::MIN = Quaternion(NumLimit< Quaternion::Value >::Min);
const Quaternion Quaternion::MAX = Quaternion(NumLimit< Quaternion::Value >::Max);
// ------------------------------------------------------------------------------------------------
SQChar Quaternion::Delim = ',';
@@ -19,82 +20,50 @@ SQChar Quaternion::Delim = ',';
Quaternion::Quaternion()
: x(0.0), y(0.0), z(0.0), w(0.0)
{
/* ... */
}
Quaternion::Quaternion(Value s)
: x(s), y(s), z(s), w(s)
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(Value sv)
: x(sv), y(sv), z(sv), w(sv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(Value xv, Value yv, Value zv)
: x(xv), y(yv), z(zv), w(0.0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(Value xv, Value yv, Value zv, Value wv)
: x(xv), y(yv), z(zv), w(wv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(const Vector3 & v)
: x(v.x), y(v.y), z(v.z), w(0.0)
Quaternion::Quaternion(const Quaternion & o)
: x(o.x), y(o.y), z(o.z), w(o.w)
{
}
Quaternion::Quaternion(const Vector4 & v)
: x(v.x), y(v.y), z(v.z), w(v.w)
{
}
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(const SQChar * values, SQChar delim)
: Quaternion(GetQuaternion(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(const Quaternion & q)
: x(q.x), y(q.y), z(q.z), w(q.w)
{
}
Quaternion::Quaternion(Quaternion && q)
: x(q.x), y(q.y), z(q.z), w(q.w)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Quaternion::~Quaternion()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Quaternion & Quaternion::operator = (const Quaternion & q)
Quaternion & Quaternion::operator = (const Quaternion & o)
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
return *this;
}
Quaternion & Quaternion::operator = (Quaternion && q)
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
x = o.x;
y = o.y;
z = o.z;
w = o.w;
return *this;
}
@@ -165,10 +134,10 @@ Quaternion & Quaternion::operator /= (const Quaternion & q)
Quaternion & Quaternion::operator %= (const Quaternion & q)
{
x = std::fmod(x, q.x);
y = std::fmod(y, q.y);
z = std::fmod(z, q.z);
w = std::fmod(w, q.w);
x = fmod(x, q.x);
y = fmod(y, q.y);
z = fmod(z, q.z);
w = fmod(w, q.w);
return *this;
}
@@ -211,10 +180,10 @@ Quaternion & Quaternion::operator /= (Value s)
Quaternion & Quaternion::operator %= (Value s)
{
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
w = std::fmod(w, s);
x = fmod(x, s);
y = fmod(y, s);
z = fmod(z, s);
w = fmod(w, s);
return *this;
}
@@ -305,18 +274,18 @@ Quaternion Quaternion::operator / (Value s) const
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator % (const Quaternion & q) const
{
return Quaternion(std::fmod(x, q.x), std::fmod(y, q.y), std::fmod(z, q.z), std::fmod(w, q.w));
return Quaternion(fmod(x, q.x), fmod(y, q.y), fmod(z, q.z), fmod(w, q.w));
}
Quaternion Quaternion::operator % (Value s) const
{
return Quaternion(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s));
return Quaternion(fmod(x, s), fmod(y, s), fmod(z, s), fmod(w, s));
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator + () const
{
return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
return Quaternion(fabs(x), fabs(y), fabs(z), fabs(w));
}
Quaternion Quaternion::operator - () const
@@ -337,32 +306,37 @@ bool Quaternion::operator != (const Quaternion & q) const
bool Quaternion::operator < (const Quaternion & q) const
{
return std::isless(x, q.x) && std::isless(y, q.y) && std::isless(z, q.z) && std::isless(w, q.w);
return EpsLt(x, q.x) && EpsLt(y, q.y) && EpsLt(z, q.z) && EpsLt(w, q.w);
}
bool Quaternion::operator > (const Quaternion & q) const
{
return std::isgreater(x, q.x) && std::isgreater(y, q.y) && std::isgreater(z, q.z) && std::isgreater(w, q.w);
return EpsGt(x, q.x) && EpsGt(y, q.y) && EpsGt(z, q.z) && EpsGt(w, q.w);
}
bool Quaternion::operator <= (const Quaternion & q) const
{
return std::islessequal(x, q.x) && std::islessequal(y, q.y) && std::islessequal(z, q.z) && std::islessequal(w, q.w);
return EpsLtEq(x, q.x) && EpsLtEq(y, q.y) && EpsLtEq(z, q.z) && EpsLtEq(w, q.w);
}
bool Quaternion::operator >= (const Quaternion & q) const
{
return std::isgreaterequal(x, q.x) && std::isgreaterequal(y, q.y) && std::isgreaterequal(z, q.z) && std::isgreaterequal(w, q.w);
return EpsGtEq(x, q.x) && EpsGtEq(y, q.y) && EpsGtEq(z, q.z) && EpsGtEq(w, q.w);
}
// ------------------------------------------------------------------------------------------------
SQInteger Quaternion::Cmp(const Quaternion & q) const
Int32 Quaternion::Cmp(const Quaternion & o) const
{
return *this == q ? 0 : (*this > q ? 1 : -1);
if (*this == o)
return 0;
else if (*this > o)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
const SQChar * Quaternion::ToString() const
CSStr Quaternion::ToString() const
{
return ToStringF("%f,%f,%f,%f", x, y, z, w);
}
@@ -417,7 +391,7 @@ void Quaternion::Set(const Vector4 & v)
}
// ------------------------------------------------------------------------------------------------
void Quaternion::Set(const SQChar * values, SQChar delim)
void Quaternion::Set(CSStr values, SQChar delim)
{
Set(GetQuaternion(values, delim));
}
@@ -425,95 +399,93 @@ void Quaternion::Set(const SQChar * values, SQChar delim)
// ------------------------------------------------------------------------------------------------
void Quaternion::Generate()
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
z = RandomVal<Value>::Get();
w = RandomVal<Value>::Get();
x = GetRandomFloat32();
y = GetRandomFloat32();
z = GetRandomFloat32();
w = GetRandomFloat32();
}
void Quaternion::Generate(Value min, Value max)
{
if (max < min)
if (EpsLt(max, min))
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
z = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
z = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
}
}
void Quaternion::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
{
if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin) || std::isless(wmax, wmin))
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(xmin, xmax);
y = RandomVal<Value>::Get(ymin, ymax);
z = RandomVal<Value>::Get(zmin, zmax);
y = RandomVal<Value>::Get(ymin, ymax);
x = GetRandomFloat32(xmin, xmax);
y = GetRandomFloat32(ymin, ymax);
z = GetRandomFloat32(zmin, zmax);
y = GetRandomFloat32(ymin, ymax);
}
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::Abs() const
{
return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
return Quaternion(fabs(x), fabs(y), fabs(z), fabs(w));
}
// ================================================================================================
bool Register_Quaternion(HSQUIRRELVM vm)
void Register_Quaternion(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Quaternion> type");
typedef Quaternion::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Quaternion"), Sqrat::Class<Quaternion>(vm, _SC("Quaternion"))
RootTable(vm).Bind(_SC("Quaternion"), Class< Quaternion >(vm, _SC("Quaternion"))
/* Constructors */
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<Val, Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Quaternion::Delim)
.Ctor< Val >()
.Ctor< Val, Val, Val >()
.Ctor< Val, Val, Val, Val >()
/* 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 */
.Func(_SC("_tostring"), &Quaternion::ToString)
.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 -)
.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("set_quat"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const Vector3 &)>(_SC("set_vec3"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const Vector4 &)>(_SC("set_vec4"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const SQChar *, SQChar)>(_SC("set_str"), &Quaternion::Set)
.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)
.Func(_SC("clear"), &Quaternion::Clear)
/* 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 *=)
@@ -553,10 +525,6 @@ bool Register_Quaternion(HSQUIRRELVM vm)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opLessEqual"), &Quaternion::operator <=)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opGreaterEqual"), &Quaternion::operator >=)
);
LogDbg("Registration of <Quaternion> type was successful");
return true;
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@@ -2,20 +2,20 @@
#define _BASE_QUATERNION_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct Quaternion
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef SQFloat Value;
typedef float Value;
/* --------------------------------------------------------------------------------------------
* ...
@@ -35,14 +35,14 @@ struct Quaternion
Value x, y, z, w;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Quaternion();
/* --------------------------------------------------------------------------------------------
* ...
*/
Quaternion(Value s);
Quaternion(Value sv);
/* --------------------------------------------------------------------------------------------
* ...
@@ -55,44 +55,19 @@ struct Quaternion
Quaternion(Value xv, Value yv, Value zv, Value wv);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Quaternion(const Vector3 & v);
Quaternion(const Quaternion & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Quaternion(const Vector4 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Quaternion(const SQChar * values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
Quaternion(const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* ...
*/
Quaternion(Quaternion && q);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
~Quaternion();
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Quaternion & operator = (const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* ...
*/
Quaternion & operator = (Quaternion && q);
Quaternion & operator = (const Quaternion & o);
/* --------------------------------------------------------------------------------------------
* ...
@@ -272,12 +247,12 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Quaternion & q) const;
Int32 Cmp(const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -312,7 +287,7 @@ struct Quaternion
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * values, SQChar delim);
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
@@ -345,4 +320,4 @@ struct Quaternion
} // Namespace:: SqMod
#endif // _BASE_QUATERNION_HPP_
#endif // _BASE_QUATERNION_HPP_

1405
source/Base/Random.cpp Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,57 +2,52 @@
#define _BASE_SHARED_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
#include <cmath>
#include <limits>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <type_traits>
#include <math.h>
#include <assert.h>
// ------------------------------------------------------------------------------------------------
#include <vcmp.h>
#include <sqrat.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
#ifdef PI
#undef PI
#endif
extern const SQChar * g_EmptyStr;
/* ------------------------------------------------------------------------------------------------
* ...
* Proxies to comunicate with the server.
*/
const Float32 PI = 3.14159265359f;
const Float32 RECIPROCAL_PI = 1.0f/PI;
const Float32 HALF_PI = PI/2.0f;
extern PluginFuncs* _Func;
extern PluginCallbacks* _Clbk;
extern PluginInfo* _Info;
// ------------------------------------------------------------------------------------------------
#ifdef PI64
#undef PI64
#endif
template < typename T > struct NumLimit;
/* ------------------------------------------------------------------------------------------------
* ...
*/
const Float64 PI64 = 3.1415926535897932384626433832795028841971693993751;
const Float64 RECIPROCAL_PI64 = 1.0/PI64;
// ------------------------------------------------------------------------------------------------
template <> struct NumLimit< char > { static const char Min, Max; };
template <> struct NumLimit< signed char > { static const signed char Min, Max; };
template <> struct NumLimit< unsigned char > { static const unsigned char Min, Max; };
template <> struct NumLimit< signed short > { static const signed short Min, Max; };
template <> struct NumLimit< unsigned short > { static const unsigned short Min, Max; };
template <> struct NumLimit< signed int > { static const signed int Min, Max; };
template <> struct NumLimit< unsigned int > { static const unsigned int Min, Max; };
template <> struct NumLimit< signed long > { static const signed long Min, Max; };
template <> struct NumLimit< unsigned long > { static const unsigned long Min, Max; };
template <> struct NumLimit< signed long long > { static const signed long long Min, Max; };
template <> struct NumLimit< unsigned long long > { static const unsigned long long Min, Max; };
template <> struct NumLimit< float > { static const float Min, Max; };
template <> struct NumLimit< double > { static const double Min, Max; };
template <> struct NumLimit< long double > { static const long double Min, Max; };
/* ------------------------------------------------------------------------------------------------
* ...
*/
const Float32 DEGTORAD = PI / 180.0f;
const Float32 RADTODEG = 180.0f / PI;
const Float64 DEGTORAD64 = PI64 / 180.0;
const Float64 RADTODEG64 = 180.0 / PI64;
/* ------------------------------------------------------------------------------------------------
* ...
*/
// ------------------------------------------------------------------------------------------------
template< typename T > inline bool EpsEq(const T a, const T b)
{
return abs(a - b) <= std::numeric_limits<T>::epsilon();
return abs(a - b) <= 0;
}
template <> inline bool EpsEq(const Float32 a, const Float32 b)
@@ -65,361 +60,188 @@ template <> inline bool EpsEq(const Float64 a, const Float64 b)
return fabs(a - b) <= 0.000000001d;
}
/* ------------------------------------------------------------------------------------------------
* ...
*/
// ------------------------------------------------------------------------------------------------
template< typename T > inline bool EpsLt(const T a, const T b)
{
return !EpsEq(a, b) && (a < b);
}
template <> inline bool EpsLt(const Float32 a, const Float32 b)
{
return !EpsEq(a, b) && (a - b) < 0.000001f;
}
template <> inline bool EpsLt(const Float64 a, const Float64 b)
{
return !EpsEq(a, b) && (a - b) < 0.000000001d;
}
// ------------------------------------------------------------------------------------------------
template< typename T > inline bool EpsGt(const T a, const T b)
{
return !EpsEq(a, b) && (a > b);
}
template <> inline bool EpsGt(const Float32 a, const Float32 b)
{
return !EpsEq(a, b) && (a - b) > 0.000001f;
}
template <> inline bool EpsGt(const Float64 a, const Float64 b)
{
return !EpsEq(a, b) && (a - b) > 0.000000001d;
}
// ------------------------------------------------------------------------------------------------
template< typename T > inline bool EpsLtEq(const T a, const T b)
{
return !EpsEq(a, b) || (a < b);
}
template <> inline bool EpsLtEq(const Float32 a, const Float32 b)
{
return !EpsEq(a, b) || (a - b) < 0.000001f;
}
template <> inline bool EpsLtEq(const Float64 a, const Float64 b)
{
return !EpsEq(a, b) || (a - b) < 0.000000001d;
}
// ------------------------------------------------------------------------------------------------
template< typename T > inline bool EpsGtEq(const T a, const T b)
{
return !EpsEq(a, b) || (a > b);
}
template <> inline bool EpsGtEq(const Float32 a, const Float32 b)
{
return !EpsEq(a, b) || (a - b) > 0.000001f;
}
template <> inline bool EpsGtEq(const Float64 a, const Float64 b)
{
return !EpsEq(a, b) || (a - b) > 0.000000001d;
}
// ------------------------------------------------------------------------------------------------
template< typename T > inline T Clamp(T val, T min, T max)
{
return val < min ? min : (val > max ? max : val);
}
template<> inline Float32 Clamp(const Float32 val, const Float32 min, const Float32 max)
/* ------------------------------------------------------------------------------------------------
* Compute the next power of two for the specified number.
*/
inline Uint32 NextPow2(Uint32 num)
{
return std::isless(val, min) ? min : (std::isgreater(val, max) ? max : val);
--num;
num |= num >> 1;
num |= num >> 2;
num |= num >> 4;
num |= num >> 8;
num |= num >> 16;
return ++num;
}
template<> inline Float64 Clamp(const Float64 val, const Float64 min, const Float64 max)
// ------------------------------------------------------------------------------------------------
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, ...);
// ------------------------------------------------------------------------------------------------
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, ...);
// ------------------------------------------------------------------------------------------------
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, ...);
// ------------------------------------------------------------------------------------------------
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, ...);
// ------------------------------------------------------------------------------------------------
void SqThrow(CCStr fmt, ...);
// ------------------------------------------------------------------------------------------------
Object & NullObject();
// ------------------------------------------------------------------------------------------------
Array & NullArray();
// ------------------------------------------------------------------------------------------------
Function & NullFunction();
// ------------------------------------------------------------------------------------------------
template < typename T > Object MakeObject(const T & v)
{
return std::isless(val, min) ? min : (std::isgreater(val, max) ? max : val);
PushVar< T >(DefaultVM::Get(), v);
Var< Object > var(DefaultVM::Get(), -1);
sq_pop(DefaultVM::Get(), 1);
return var.value;
}
/* ------------------------------------------------------------------------------------------------
* Simple functions to quickly forward logging messages without including the logging system.
*/
void LogDbg(const char * fmt, ...);
void LogMsg(const char * fmt, ...);
void LogScs(const char * fmt, ...);
void LogInf(const char * fmt, ...);
void LogWrn(const char * fmt, ...);
void LogErr(const char * fmt, ...);
void LogFtl(const char * fmt, ...);
/* ------------------------------------------------------------------------------------------------
* Simple functions to quickly forward debugging messages without including the debugging system.
*/
void DbgWrn(const char * fmt, ...);
void DbgErr(const char * fmt, ...);
void DbgFtl(const char * fmt, ...);
void DbgWrn(const char * func, const char * fmt, ...);
void DbgErr(const char * func, const char * fmt, ...);
void DbgFtl(const char * func, const char * fmt, ...);
void DbgWrn(const char * type, const char * func, const char * fmt, ...);
void DbgErr(const char * type, const char * func, const char * fmt, ...);
void DbgFtl(const char * type, const char * func, const char * fmt, ...);
/* ------------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToStrF(const char * fmt, ...);
/* ------------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToStringF(const char * fmt, ...);
/* ------------------------------------------------------------------------------------------------
* ...
*/
void InitMTRG64();
void InitMTRG64();
/* ------------------------------------------------------------------------------------------------
* ...
*/
Int8 GetRandomInt8();
Int8 GetRandomInt8(Int8 min, Int8 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Uint8 GetRandomUint8();
Uint8 GetRandomUint8(Uint8 min, Uint8 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Int16 GetRandomInt16();
Int16 GetRandomInt16(Int16 min, Int16 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Uint16 GetRandomUint16();
Uint16 GetRandomUint16(Uint16 min, Uint16 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Int32 GetRandomInt32();
Int32 GetRandomInt32(Int32 min, Int32 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Uint32 GetRandomUint32();
Uint32 GetRandomUint32(Uint32 min, Uint32 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Int64 GetRandomInt64();
Int64 GetRandomInt64(Int64 min, Int64 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Uint64 GetRandomUint64();
Uint64 GetRandomUint64(Uint64 min, Uint64 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Float32 GetRandomFloat32();
Float32 GetRandomFloat32(Float32 min, Float32 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Float64 GetRandomFloat64();
Float64 GetRandomFloat64(Float64 min, Float64 max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
String GetRandomString(String::size_type len);
String GetRandomString(String::size_type len, String::value_type min, String::value_type max);
/* ------------------------------------------------------------------------------------------------
* ...
*/
bool GetRandomBool();
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <typename T> struct RandomVal
{ /* ... */ };
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Int8>
// ------------------------------------------------------------------------------------------------
template < typename T > Object MakeObject(HSQUIRRELVM vm, const T & v)
{
static inline Int8 Get() { return GetRandomInt8(); }
static inline Int8 Get(Int8 min, Int8 max) { return GetRandomInt8(min, max); }
};
template <> struct RandomVal<Uint8>
{
static inline Uint8 Get() { return GetRandomUint8(); }
static inline Uint8 Get(Uint8 min, Uint8 max) { return GetRandomUint8(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Int16>
{
static inline Int16 Get() { return GetRandomInt16(); }
static inline Int16 Get(Int16 min, Int16 max) { return GetRandomInt16(min, max); }
};
template <> struct RandomVal<Uint16>
{
static inline Uint16 Get() { return GetRandomUint16(); }
static inline Uint16 Get(Uint16 min, Uint16 max) { return GetRandomUint16(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Int32>
{
static inline Int32 Get() { return GetRandomInt32(); }
static inline Int32 Get(Int32 min, Int32 max) { return GetRandomInt32(min, max); }
};
template <> struct RandomVal<Uint32>
{
static inline Uint32 Get() { return GetRandomUint32(); }
static inline Uint32 Get(Uint32 min, Uint32 max) { return GetRandomUint32(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Int64>
{
static inline Int64 Get() { return GetRandomInt64(); }
static inline Int64 Get(Int64 min, Int64 max) { return GetRandomInt64(min, max); }
};
template <> struct RandomVal<Uint64>
{
static inline Uint64 Get() { return GetRandomUint64(); }
static inline Uint64 Get(Uint64 min, Uint64 max) { return GetRandomUint64(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Float32>
{
static inline Float32 Get() { return GetRandomFloat32(); }
static inline Float32 Get(Float32 min, Float32 max) { return GetRandomFloat32(min, max); }
};
template <> struct RandomVal<Float64>
{
static inline Float64 Get() { return GetRandomFloat64(); }
static inline Float64 Get(Float64 min, Float64 max) { return GetRandomFloat64(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<String>
{
static inline String Get(String::size_type len) { return GetRandomString(len); }
static inline String Get(String::size_type len, String::value_type min, String::value_type max)
{ return GetRandomString(len, min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<bool>
{
static inline bool Get() { return GetRandomBool(); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
const Color3 & GetRandomColor();
PushVar< T >(vm, v);
Var< Object > var(vm, -1);
sq_pop(vm, 1);
return var.value;
}
/* ------------------------------------------------------------------------------------------------
* Simple function to check whether the specified string can be considered as a boolean value
*/
bool SToB(const SQChar * str);
bool SToB(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Utility used to unify the string converstion functions under one name.
*
*/
template < typename T > struct SToI { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template < typename T > struct SToF { static constexpr auto Fn = static_cast< float(*)(const String &, std::size_t*) >(std::stof); };
CSStr ToStrF(CCStr fmt, ...);
/* ------------------------------------------------------------------------------------------------
*
*/
CSStr ToStringF(CCStr fmt, ...);
// ------------------------------------------------------------------------------------------------
template <> struct SToI < char > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < signed char > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < unsigned char > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < short > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < unsigned short > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < int > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < unsigned int > { static constexpr auto Fn = static_cast< unsigned long(*)(const String &, std::size_t*, int) >(std::stoul); };
template <> struct SToI < long > { static constexpr auto Fn = static_cast< long(*)(const String &, std::size_t*, int) >(std::stol); };
template <> struct SToI < unsigned long > { static constexpr auto Fn = static_cast< unsigned long(*)(const String &, std::size_t*, int) >(std::stoul); };
template <> struct SToI < long long > { static constexpr auto Fn = static_cast< long long(*)(const String &, std::size_t*, int b) >(std::stoll); };
template <> struct SToI < unsigned long long > { static constexpr auto Fn = static_cast< unsigned long long(*)(const String &, std::size_t*, int) >(std::stoull); };
template <> struct SToF < float > { static constexpr auto Fn = static_cast< float(*)(const String &, std::size_t*) >(std::stof); };
template <> struct SToF < double > { static constexpr auto Fn = static_cast< double(*)(const String &, std::size_t*) >(std::stod); };
template <> struct SToF < long double > { static constexpr auto Fn = static_cast< long double(*)(const String &, std::size_t*) >(std::stold); };
// ------------------------------------------------------------------------------------------------
template < typename T > inline String NToS(T n) { return std::to_string(n); }
template < typename T > inline const SQChar * NToCS(T n) { return std::to_string(n).c_str(); }
const Color3 & GetRandomColor();
/* ------------------------------------------------------------------------------------------------
* ...
* Value extractors.
*/
Color3 GetColor(const SQChar * name);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Circle GetCircle(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
AABB GetAABB(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Color3 GetColor3(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Color4 GetColor4(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Quaternion GetQuaternion(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Sphere GetSphere(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector2f GetVector2f(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector2i GetVector2i(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector2u GetVector2u(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector3 GetVector3(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector4 GetVector4(const SQChar * str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Fake deleter meant for classes that should not be deleted by smart pointers
*/
template <typename T> struct FakeDeleter
{
void operator () (T * /* ptr */) const { /* Ignored... */ }
};
/* ------------------------------------------------------------------------------------------------
* Utility used to generate a string with an arbitrary text surrounded by a specific character
*/
const SQChar * LeftStr(const SQChar * t, SQChar f, SQUint32 w = 72);
const SQChar * LeftStr(const SQChar * t, SQChar f, SQUint32 w = 72, SQUint32 o = 0);
const SQChar * RightStr(const SQChar * t, SQChar f, SQUint32 w = 72);
const SQChar * RightStr(const SQChar * t, SQChar f, SQUint32 w = 72, SQUint32 o = 0);
const SQChar * CenterStr(const SQChar * t, SQChar f, SQUint32 w = 72);
/* ------------------------------------------------------------------------------------------------
* Function used insert arbitrary text at certain positions within a string
*/
const SQChar * InsertStr(const SQChar * f, const std::vector< const SQChar * > & a);
// Utility for the <InsertStr> function
const SQChar * InsStr(const SQChar * f);
template < typename... Args > const SQChar * InsStr(const SQChar * f, Args... args)
{
return InsertStr(f, {{args...}});
}
Color3 GetColor(CSStr name);
AABB GetAABB(CSStr str, SQChar delim);
Circle GetCircle(CSStr str, SQChar delim);
Color3 GetColor3(CSStr str, SQChar delim);
Color4 GetColor4(CSStr str, SQChar delim);
Quaternion GetQuaternion(CSStr str, SQChar delim);
Sphere GetSphere(CSStr str, SQChar delim);
Vector2 GetVector2(CSStr str, SQChar delim);
Vector2i GetVector2i(CSStr str, SQChar delim);
Vector3 GetVector3(CSStr str, SQChar delim);
Vector4 GetVector4(CSStr str, SQChar delim);
} // Namespace:: SqMod

View File

@@ -1,6 +1,7 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Sphere.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -8,73 +9,57 @@ namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Sphere Sphere::NIL = Sphere();
const Sphere Sphere::MIN = Sphere(0.0);
const Sphere Sphere::MAX = Sphere(std::numeric_limits<Sphere::Value>::max());
const Sphere Sphere::MAX = Sphere(NumLimit< Sphere::Value >::Max);
// ------------------------------------------------------------------------------------------------
SQChar Sphere::Delim = ',';
// ------------------------------------------------------------------------------------------------
Sphere::Sphere()
: pos(0.0, 0.0, 0.0), rad(0.0)
: pos(0.0), rad(0.0)
{
}
Sphere::Sphere(Value r)
: pos(0.0, 0.0, 0.0), rad(r)
{
}
Sphere::Sphere(const Vector3 & p)
: pos(p), rad(0.0)
{
}
Sphere::Sphere(const Vector3 & p, Value r)
: pos(p), rad(r)
{
}
Sphere::Sphere(Value x, Value y, Value z, Value r)
: pos(x, y, z), rad(r)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Sphere::Sphere(const Sphere & s)
: pos(s.pos), rad(s.rad)
Sphere::Sphere(Value rv)
: pos(0.0), rad(rv)
{
/* ... */
}
Sphere::Sphere(Sphere && s)
: pos(s.pos), rad(s.rad)
// ------------------------------------------------------------------------------------------------
Sphere::Sphere(const Vector3 & pv, Value rv)
: pos(pv), rad(rv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Sphere::Sphere(Value xv, Value yv, Value zv, Value rv)
: pos(xv, yv, zv), rad(rv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Sphere::Sphere(const Sphere & o)
: pos(o.pos), rad(o.rad)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Sphere::~Sphere()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Sphere & Sphere::operator = (const Sphere & s)
Sphere & Sphere::operator = (const Sphere & o)
{
pos = s.pos;
rad = s.rad;
return *this;
}
Sphere & Sphere::operator = (Sphere && s)
{
pos = s.pos;
rad = s.rad;
pos = o.pos;
rad = o.rad;
return *this;
}
@@ -123,7 +108,7 @@ Sphere & Sphere::operator /= (const Sphere & s)
Sphere & Sphere::operator %= (const Sphere & s)
{
pos %= s.pos;
rad = std::fmod(rad, s.rad);
rad = fmod(rad, s.rad);
return *this;
}
@@ -155,7 +140,7 @@ Sphere & Sphere::operator /= (Value r)
Sphere & Sphere::operator %= (Value r)
{
rad = std::fmod(rad, r);
rad = fmod(rad, r);
return *this;
}
@@ -245,7 +230,7 @@ Sphere Sphere::operator / (const Sphere & s) const
Sphere Sphere::operator % (const Sphere & s) const
{
return Sphere(pos % s.pos, std::fmod(rad, s.rad));
return Sphere(pos % s.pos, fmod(rad, s.rad));
}
// ------------------------------------------------------------------------------------------------
@@ -271,39 +256,39 @@ Sphere Sphere::operator / (Value r) const
Sphere Sphere::operator % (Value r) const
{
return Sphere(std::fmod(rad, r));
return Sphere(fmod(rad, r));
}
// ------------------------------------------------------------------------------------------------
Sphere Sphere::operator + (const Vector3 & p) const
{
return Sphere(pos + p);
return Sphere(pos + p, rad);
}
Sphere Sphere::operator - (const Vector3 & p) const
{
return Sphere(pos - p);
return Sphere(pos - p, rad);
}
Sphere Sphere::operator * (const Vector3 & p) const
{
return Sphere(pos * p);
return Sphere(pos * p, rad);
}
Sphere Sphere::operator / (const Vector3 & p) const
{
return Sphere(pos / p);
return Sphere(pos / p, rad);
}
Sphere Sphere::operator % (const Vector3 & p) const
{
return Sphere(pos % p);
return Sphere(pos % p, rad);
}
// ------------------------------------------------------------------------------------------------
Sphere Sphere::operator + () const
{
return Sphere(pos.Abs(), std::fabs(rad));
return Sphere(pos.Abs(), fabs(rad));
}
Sphere Sphere::operator - () const
@@ -314,42 +299,47 @@ Sphere Sphere::operator - () const
// ------------------------------------------------------------------------------------------------
bool Sphere::operator == (const Sphere & s) const
{
return (rad == s.rad) && (pos == s.pos);
return EpsEq(rad, s.rad) && (pos == s.pos);
}
bool Sphere::operator != (const Sphere & s) const
{
return (rad != s.rad) && (pos != s.pos);
return !EpsEq(rad, s.rad) && (pos != s.pos);
}
bool Sphere::operator < (const Sphere & s) const
{
return (rad < s.rad) && (pos < s.pos);
return EpsLt(rad, s.rad) && (pos < s.pos);
}
bool Sphere::operator > (const Sphere & s) const
{
return (rad > s.rad) && (pos > s.pos);
return EpsGt(rad, s.rad) && (pos > s.pos);
}
bool Sphere::operator <= (const Sphere & s) const
{
return (rad <= s.rad) && (pos <= s.pos);
return EpsLtEq(rad, s.rad) && (pos <= s.pos);
}
bool Sphere::operator >= (const Sphere & s) const
{
return (rad >= s.rad) && (pos >= s.pos);
return EpsGtEq(rad, s.rad) && (pos >= s.pos);
}
// ------------------------------------------------------------------------------------------------
SQInteger Sphere::Cmp(const Sphere & s) const
Int32 Sphere::Cmp(const Sphere & o) const
{
return *this == s ? 0 : (*this > s ? 1 : -1);
if (*this == o)
return 0;
else if (*this > o)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
const SQChar * Sphere::ToString() const
CSStr Sphere::ToString() const
{
return ToStringF("%f,%f,%f,%f", pos.x, pos.y, pos.z, rad);
}
@@ -390,7 +380,7 @@ void Sphere::Set(Value nx, Value ny, Value nz, Value nr)
}
// ------------------------------------------------------------------------------------------------
void Sphere::Set(const SQChar * values, SQChar delim)
void Sphere::Set(CSStr values, SQChar delim)
{
Set(GetSphere(values, delim));
}
@@ -399,18 +389,18 @@ void Sphere::Set(const SQChar * values, SQChar delim)
void Sphere::Generate()
{
pos.Generate();
rad = RandomVal<Value>::Get();
rad = GetRandomFloat32();
}
void Sphere::Generate(Value min, Value max, bool r)
{
if (max < min)
if (EpsLt(max, min))
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else if (r)
{
rad = RandomVal<Value>::Get(min, max);
rad = GetRandomFloat32(min, max);
}
else
{
@@ -425,63 +415,62 @@ 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 (std::isless(rmax, rmin))
if (EpsLt(rmax, rmin))
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax);
rad = RandomVal<Value>::Get(rmin, rmax);
rad = GetRandomFloat32(rmin, rmax);
}
}
// ------------------------------------------------------------------------------------------------
Sphere Sphere::Abs() const
{
return Sphere(pos.Abs(), std::fabs(rad));
return Sphere(pos.Abs(), fabs(rad));
}
// ------------------------------------------------------------------------------------------------
bool Register_Sphere(HSQUIRRELVM vm)
// ================================================================================================
void Register_Sphere(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Sphere> type");
typedef Sphere::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Sphere"), Sqrat::Class<Sphere>(vm, _SC("Sphere"))
RootTable(vm).Bind(_SC("Sphere"), Class< Sphere >(vm, _SC("Sphere"))
/* Constructors */
.Ctor()
.Ctor<Val>()
.Ctor<const Vector3 &, Val>()
.Ctor<Val, Val, Val, Val>()
.SetStaticValue(_SC("delim"), &Sphere::Delim)
.Ctor< Val >()
.Ctor< const Vector3 &, Val >()
.Ctor< Val, Val, Val, Val >()
/* 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 */
.Func(_SC("_tostring"), &Sphere::ToString)
.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 -)
.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("set_rad"), &Sphere::Set)
.Overload<void (Sphere::*)(const Vector3 &)>(_SC("set_vec3"), &Sphere::Set)
.Overload<void (Sphere::*)(Val, Val, Val)>(_SC("set_vec3"), &Sphere::Set)
.Overload<void (Sphere::*)(const SQChar *, SQChar)>(_SC("set_str"), &Sphere::Set)
.Func(_SC("clear"), &Sphere::Clear)
/* 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 *=)
@@ -533,10 +522,6 @@ bool Register_Sphere(HSQUIRRELVM vm)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opLessEqual"), &Sphere::operator <=)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opGreaterEqual"), &Sphere::operator >=)
);
LogDbg("Registration of <Sphere> type was successful");
return true;
}
} // Namespace:: SqMod

View File

@@ -2,21 +2,21 @@
#define _BASE_SPHERE_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "SqBase.hpp"
#include "Base/Vector3.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct Sphere
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef SQFloat Value;
typedef float Value;
/* --------------------------------------------------------------------------------------------
* ...
@@ -37,54 +37,39 @@ struct Sphere
Value rad;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Sphere();
/* --------------------------------------------------------------------------------------------
* ...
*/
Sphere(Value r);
Sphere(Value rv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Sphere(const Vector3 & p);
Sphere(const Vector3 & pv, Value rv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Sphere(const Vector3 & p, Value r);
Sphere(Value xv, Value yv, Value zv, Value rv);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Sphere(Value x, Value y, Value z, Value r);
Sphere(const Sphere & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Sphere(const Sphere & s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Sphere(Sphere && s);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
~Sphere();
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Sphere & operator = (const Sphere & s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Sphere & operator = (Sphere && s);
Sphere & operator = (const Sphere & o);
/* --------------------------------------------------------------------------------------------
* ...
@@ -309,12 +294,12 @@ struct Sphere
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Sphere & s) const;
Int32 Cmp(const Sphere & s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -349,7 +334,7 @@ struct Sphere
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * values, SQChar delim);
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...

448
source/Base/Vector2.cpp Normal file
View File

@@ -0,0 +1,448 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Vector2.hpp"
#include "Base/Vector2i.hpp"
#include "Base/Shared.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector2 Vector2::NIL = Vector2(0);
const Vector2 Vector2::MIN = Vector2(NumLimit< Vector2::Value >::Min);
const Vector2 Vector2::MAX = Vector2(NumLimit< Vector2::Value >::Max);
// ------------------------------------------------------------------------------------------------
SQChar Vector2::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector2::Vector2()
: x(0.0), y(0.0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2::Vector2(Value sv)
: x(sv), y(sv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2::Vector2(Value xv, Value yv)
: x(xv), y(yv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2::Vector2(const Vector2 & o)
: x(o.x), y(o.y)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2::~Vector2()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2 & Vector2::operator = (const Vector2 & o)
{
x = o.x;
y = o.y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2 & Vector2::operator = (Value s)
{
x = s;
y = s;
return *this;
}
Vector2 & Vector2::operator = (CSStr values)
{
Set(GetVector2(values, Delim));
return *this;
}
Vector2 & Vector2::operator = (const Vector2i & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2 & Vector2::operator += (const Vector2 & v)
{
x += v.x;
y += v.y;
return *this;
}
Vector2 & Vector2::operator -= (const Vector2 & v)
{
x -= v.x;
y -= v.y;
return *this;
}
Vector2 & Vector2::operator *= (const Vector2 & v)
{
x *= v.x;
y *= v.y;
return *this;
}
Vector2 & Vector2::operator /= (const Vector2 & v)
{
x /= v.x;
y /= v.y;
return *this;
}
Vector2 & Vector2::operator %= (const Vector2 & v)
{
x = fmod(x, v.x);
y = fmod(y, v.y);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2 & Vector2::operator += (Value s)
{
x += s;
y += s;
return *this;
}
Vector2 & Vector2::operator -= (Value s)
{
x -= s;
y -= s;
return *this;
}
Vector2 & Vector2::operator *= (Value s)
{
x *= s;
y *= s;
return *this;
}
Vector2 & Vector2::operator /= (Value s)
{
x /= s;
y /= s;
return *this;
}
Vector2 & Vector2::operator %= (Value s)
{
x = fmod(x, s);
y = fmod(y, s);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2 & Vector2::operator ++ ()
{
++x;
++y;
return *this;
}
Vector2 & Vector2::operator -- ()
{
--x;
--y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::operator ++ (int)
{
Vector2 state(*this);
++x;
++y;
return state;
}
Vector2 Vector2::operator -- (int)
{
Vector2 state(*this);
--x;
--y;
return state;
}
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::operator + (const Vector2 & v) const
{
return Vector2(x + v.x, y + v.y);
}
Vector2 Vector2::operator - (const Vector2 & v) const
{
return Vector2(x - v.x, y - v.y);
}
Vector2 Vector2::operator * (const Vector2 & v) const
{
return Vector2(x * v.x, y * v.y);
}
Vector2 Vector2::operator / (const Vector2 & v) const
{
return Vector2(x / v.x, y / v.y);
}
Vector2 Vector2::operator % (const Vector2 & v) const
{
return Vector2(fmod(x, v.x), fmod(y, v.y));
}
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::operator + (Value s) const
{
return Vector2(x + s, y + s);
}
Vector2 Vector2::operator - (Value s) const
{
return Vector2(x - s, y - s);
}
Vector2 Vector2::operator * (Value s) const
{
return Vector2(x * s, y * s);
}
Vector2 Vector2::operator / (Value s) const
{
return Vector2(x / s, y / s);
}
Vector2 Vector2::operator % (Value s) const
{
return Vector2(fmod(x, s), fmod(y, s));
}
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::operator + () const
{
return Vector2(fabs(x), fabs(y));
}
Vector2 Vector2::operator - () const
{
return Vector2(-x, -y);
}
// ------------------------------------------------------------------------------------------------
bool Vector2::operator == (const Vector2 & v) const
{
return EpsEq(x, v.x) && EpsEq(y, v.y);
}
bool Vector2::operator != (const Vector2 & v) const
{
return !EpsEq(x, v.x) && !EpsEq(y, v.y);
}
bool Vector2::operator < (const Vector2 & v) const
{
return EpsLt(x, v.x) && EpsLt(y, v.y);
}
bool Vector2::operator > (const Vector2 & v) const
{
return EpsGt(x, v.x) && EpsGt(y, v.y);
}
bool Vector2::operator <= (const Vector2 & v) const
{
return EpsLtEq(x, v.x) && EpsLtEq(y, v.y);
}
bool Vector2::operator >= (const Vector2 & v) const
{
return EpsGtEq(x, v.x) && EpsGtEq(y, v.y);
}
// ------------------------------------------------------------------------------------------------
Int32 Vector2::Cmp(const Vector2 & o) const
{
if (*this == o)
return 0;
else if (*this > o)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
CSStr Vector2::ToString() const
{
return ToStringF("%f,%f", x, y);
}
// ------------------------------------------------------------------------------------------------
void Vector2::Set(Value ns)
{
x = ns;
y = ns;
}
void Vector2::Set(Value nx, Value ny)
{
x = nx;
y = ny;
}
// ------------------------------------------------------------------------------------------------
void Vector2::Set(const Vector2 & v)
{
x = v.x;
y = v.y;
}
void Vector2::Set(const Vector2i & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
}
// ------------------------------------------------------------------------------------------------
void Vector2::Set(CSStr values, SQChar delim)
{
Set(GetVector2(values, delim));
}
// ------------------------------------------------------------------------------------------------
void Vector2::Generate()
{
x = GetRandomFloat32();
y = GetRandomFloat32();
}
void Vector2::Generate(Value min, Value max)
{
if (EpsLt(max, min))
{
SqThrow("max value is lower than min value");
}
else
{
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
}
}
void Vector2::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin))
{
SqThrow("max value is lower than min value");
}
else
{
x = GetRandomFloat32(ymin, ymax);
y = GetRandomFloat32(xmin, xmax);
}
}
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::Abs() const
{
return Vector2(fabs(x), fabs(y));
}
// ================================================================================================
void Register_Vector2(HSQUIRRELVM vm)
{
typedef Vector2::Value Val;
RootTable(vm).Bind(_SC("Vector2"), Class< Vector2 >(vm, _SC("Vector2"))
/* Constructors */
.Ctor()
.Ctor< Val >()
.Ctor< Val, Val >()
/* 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 */
.Func(_SC("_tostring"), &Vector2::ToString)
.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 */
.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 >=)
);
}
} // Namespace:: SqMod

View File

@@ -1,28 +1,28 @@
#ifndef _BASE_VECTOR2F_HPP_
#define _BASE_VECTOR2F_HPP_
#ifndef _BASE_VECTOR2_HPP_
#define _BASE_VECTOR2_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct Vector2f
struct Vector2
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef SQFloat Value;
typedef float Value;
/* --------------------------------------------------------------------------------------------
* ...
*/
static const Vector2f NIL;
static const Vector2f MIN;
static const Vector2f MAX;
static const Vector2 NIL;
static const Vector2 MIN;
static const Vector2 MAX;
/* --------------------------------------------------------------------------------------------
* ...
@@ -35,249 +35,219 @@ struct Vector2f
Value x, y;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector2f();
Vector2();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f(Value s);
Vector2(Value sv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f(Value xv, Value yv);
Vector2(Value xv, Value yv);
/* --------------------------------------------------------------------------------------------
*
*/
Vector2(const Vector2 & o);
/* --------------------------------------------------------------------------------------------
*
*/
~Vector2();
/* --------------------------------------------------------------------------------------------
*
*/
Vector2 & operator = (const Vector2 & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f(const Vector2i & v);
Vector2 & operator = (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f(const Vector2u & v);
Vector2 & operator = (CSStr values);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f(const SQChar * values, SQChar delim);
Vector2 & operator = (const Vector2i & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f(const Vector2f & v);
Vector2 & operator += (const Vector2 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f(Vector2f && v);
Vector2 & operator -= (const Vector2 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
~Vector2f();
Vector2 & operator *= (const Vector2 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator = (const Vector2f & v);
Vector2 & operator /= (const Vector2 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator = (Vector2f && v);
Vector2 & operator %= (const Vector2 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator = (Value s);
Vector2 & operator += (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator = (const SQChar * values);
Vector2 & operator -= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator = (const Vector2i & v);
Vector2 & operator *= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator = (const Vector2u & v);
Vector2 & operator /= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator += (const Vector2f & v);
Vector2 & operator %= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator -= (const Vector2f & v);
Vector2 & operator ++ ();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator *= (const Vector2f & v);
Vector2 & operator -- ();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator /= (const Vector2f & v);
Vector2 operator ++ (int);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator %= (const Vector2f & v);
Vector2 operator -- (int);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator += (Value s);
Vector2 operator + (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator -= (Value s);
Vector2 operator - (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator *= (Value s);
Vector2 operator * (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator /= (Value s);
Vector2 operator / (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator %= (Value s);
Vector2 operator % (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator ++ ();
Vector2 operator + (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f & operator -- ();
Vector2 operator - (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator ++ (int);
Vector2 operator * (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator -- (int);
Vector2 operator / (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator + (const Vector2f & v) const;
Vector2 operator % (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator - (const Vector2f & v) const;
Vector2 operator + () const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator * (const Vector2f & v) const;
Vector2 operator - () const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator / (const Vector2f & v) const;
bool operator == (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator % (const Vector2f & v) const;
bool operator != (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator + (Value s) const;
bool operator < (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator - (Value s) const;
bool operator > (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator * (Value s) const;
bool operator <= (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator / (Value s) const;
bool operator >= (const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator % (Value s) const;
Int32 Cmp(const Vector2 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator + () const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f operator - () const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator == (const Vector2f & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator != (const Vector2f & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator < (const Vector2f & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator > (const Vector2f & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator <= (const Vector2f & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator >= (const Vector2f & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Vector2f & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -292,7 +262,7 @@ struct Vector2f
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector2f & v);
void Set(const Vector2 & v);
/* --------------------------------------------------------------------------------------------
* ...
@@ -302,12 +272,7 @@ struct Vector2f
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * values, SQChar delim);
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
@@ -335,9 +300,9 @@ struct Vector2f
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2f Abs() const;
Vector2 Abs() const;
};
} // Namespace:: SqMod
#endif // _BASE_VECTOR2F_HPP_
#endif // _BASE_VECTOR2_HPP_

View File

@@ -1,493 +0,0 @@
#include "Base/Vector2f.hpp"
#include "Base/Vector2i.hpp"
#include "Base/Vector2u.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector2f Vector2f::NIL = Vector2f(0);
const Vector2f Vector2f::MIN = Vector2f(std::numeric_limits<Vector2f::Value>::min());
const Vector2f Vector2f::MAX = Vector2f(std::numeric_limits<Vector2f::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Vector2f::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector2f::Vector2f()
: x(0.0), y(0.0)
{
}
Vector2f::Vector2f(Value s)
: x(s), y(s)
{
}
Vector2f::Vector2f(Value xv, Value yv)
: x(xv), y(yv)
{
}
// ------------------------------------------------------------------------------------------------
Vector2f::Vector2f(const Vector2i & v)
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
Vector2f::Vector2f(const Vector2u & v)
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
// ------------------------------------------------------------------------------------------------
Vector2f::Vector2f(const SQChar * values, SQChar delim)
: Vector2f(GetVector2f(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector2f::Vector2f(const Vector2f & v)
: x(v.x), y(v.y)
{
}
Vector2f::Vector2f(Vector2f && v)
: x(v.x), y(v.y)
{
}
// ------------------------------------------------------------------------------------------------
Vector2f::~Vector2f()
{
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator = (const Vector2f & v)
{
x = v.x;
y = v.y;
return *this;
}
Vector2f & Vector2f::operator = (Vector2f && v)
{
x = v.x;
y = v.y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator = (Value s)
{
x = s;
y = s;
return *this;
}
Vector2f & Vector2f::operator = (const SQChar * values)
{
Set(GetVector2f(values, Delim));
return *this;
}
Vector2f & Vector2f::operator = (const Vector2i & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
Vector2f & Vector2f::operator = (const Vector2u & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator += (const Vector2f & v)
{
x += v.x;
y += v.y;
return *this;
}
Vector2f & Vector2f::operator -= (const Vector2f & v)
{
x -= v.x;
y -= v.y;
return *this;
}
Vector2f & Vector2f::operator *= (const Vector2f & v)
{
x *= v.x;
y *= v.y;
return *this;
}
Vector2f & Vector2f::operator /= (const Vector2f & v)
{
x /= v.x;
y /= v.y;
return *this;
}
Vector2f & Vector2f::operator %= (const Vector2f & v)
{
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator += (Value s)
{
x += s;
y += s;
return *this;
}
Vector2f & Vector2f::operator -= (Value s)
{
x -= s;
y -= s;
return *this;
}
Vector2f & Vector2f::operator *= (Value s)
{
x *= s;
y *= s;
return *this;
}
Vector2f & Vector2f::operator /= (Value s)
{
x /= s;
y /= s;
return *this;
}
Vector2f & Vector2f::operator %= (Value s)
{
x = std::fmod(x, s);
y = std::fmod(y, s);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator ++ ()
{
++x;
++y;
return *this;
}
Vector2f & Vector2f::operator -- ()
{
--x;
--y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::operator ++ (int)
{
Vector2f state(*this);
++x;
++y;
return state;
}
Vector2f Vector2f::operator -- (int)
{
Vector2f state(*this);
--x;
--y;
return state;
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::operator + (const Vector2f & v) const
{
return Vector2f(x + v.x, y + v.y);
}
Vector2f Vector2f::operator - (const Vector2f & v) const
{
return Vector2f(x - v.x, y - v.y);
}
Vector2f Vector2f::operator * (const Vector2f & v) const
{
return Vector2f(x * v.x, y * v.y);
}
Vector2f Vector2f::operator / (const Vector2f & v) const
{
return Vector2f(x / v.x, y / v.y);
}
Vector2f Vector2f::operator % (const Vector2f & v) const
{
return Vector2f(std::fmod(x, v.x), std::fmod(y, v.y));
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::operator + (Value s) const
{
return Vector2f(x + s, y + s);
}
Vector2f Vector2f::operator - (Value s) const
{
return Vector2f(x - s, y - s);
}
Vector2f Vector2f::operator * (Value s) const
{
return Vector2f(x * s, y * s);
}
Vector2f Vector2f::operator / (Value s) const
{
return Vector2f(x / s, y / s);
}
Vector2f Vector2f::operator % (Value s) const
{
return Vector2f(std::fmod(x, s), std::fmod(y, s));
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::operator + () const
{
return Vector2f(std::fabs(x), std::fabs(y));
}
Vector2f Vector2f::operator - () const
{
return Vector2f(-x, -y);
}
// ------------------------------------------------------------------------------------------------
bool Vector2f::operator == (const Vector2f & v) const
{
return EpsEq(x, v.x) && EpsEq(y, v.y);
}
bool Vector2f::operator != (const Vector2f & v) const
{
return !EpsEq(x, v.x) && !EpsEq(y, v.y);
}
bool Vector2f::operator < (const Vector2f & v) const
{
return std::isless(x, v.x) && std::isless(y, v.y);
}
bool Vector2f::operator > (const Vector2f & v) const
{
return std::isgreater(x, v.x) && std::isgreater(y, v.y);
}
bool Vector2f::operator <= (const Vector2f & v) const
{
return std::islessequal(x, v.x) && std::islessequal(y, v.y);
}
bool Vector2f::operator >= (const Vector2f & v) const
{
return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y);
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector2f::Cmp(const Vector2f & v) const
{
return *this == v ? 0 : (*this > v ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector2f::ToString() const
{
return ToStringF("%f,%f", x, y);
}
// ------------------------------------------------------------------------------------------------
void Vector2f::Set(Value ns)
{
x = ns;
y = ns;
}
void Vector2f::Set(Value nx, Value ny)
{
x = nx;
y = ny;
}
// ------------------------------------------------------------------------------------------------
void Vector2f::Set(const Vector2f & v)
{
x = v.x;
y = v.y;
}
void Vector2f::Set(const Vector2i & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
}
void Vector2f::Set(const Vector2u & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
}
// ------------------------------------------------------------------------------------------------
void Vector2f::Set(const SQChar * values, SQChar delim)
{
Set(GetVector2f(values, delim));
}
// ------------------------------------------------------------------------------------------------
void Vector2f::Generate()
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
}
void Vector2f::Generate(Value min, Value max)
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
}
}
void Vector2f::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (xmax < xmin || ymax < ymin)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(ymin, ymax);
y = RandomVal<Value>::Get(xmin, xmax);
}
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::Abs() const
{
return Vector2f(std::fabs(x), std::fabs(y));
}
// ================================================================================================
bool Register_Vector2f(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector2f> type");
typedef Vector2f::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector2f"), Sqrat::Class<Vector2f>(vm, _SC("Vector2f"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val>()
.SetStaticValue(_SC("delim"), &Vector2f::Delim)
.Var(_SC("x"), &Vector2f::x)
.Var(_SC("y"), &Vector2f::y)
.Prop(_SC("abs"), &Vector2f::Abs)
.Func(_SC("_tostring"), &Vector2f::ToString)
.Func(_SC("_cmp"), &Vector2f::Cmp)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_add"), &Vector2f::operator +)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_sub"), &Vector2f::operator -)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_mul"), &Vector2f::operator *)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_div"), &Vector2f::operator /)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_modulo"), &Vector2f::operator %)
.Func<Vector2f (Vector2f::*)(void) const>(_SC("_unm"), &Vector2f::operator -)
.Overload<void (Vector2f::*)(Val)>(_SC("set"), &Vector2f::Set)
.Overload<void (Vector2f::*)(Val, Val)>(_SC("set"), &Vector2f::Set)
.Overload<void (Vector2f::*)(const Vector2f &)>(_SC("set_vec2f"), &Vector2f::Set)
.Overload<void (Vector2f::*)(const Vector2i &)>(_SC("set_vec2i"), &Vector2f::Set)
.Overload<void (Vector2f::*)(const Vector2u &)>(_SC("set_vec2u"), &Vector2f::Set)
.Overload<void (Vector2f::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector2f::Set)
.Overload<void (Vector2f::*)(void)>(_SC("generate"), &Vector2f::Generate)
.Overload<void (Vector2f::*)(Val, Val)>(_SC("generate"), &Vector2f::Generate)
.Overload<void (Vector2f::*)(Val, Val, Val, Val)>(_SC("generate"), &Vector2f::Generate)
.Func(_SC("clear"), &Vector2f::Clear)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opAddAssign"), &Vector2f::operator +=)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opSubAssign"), &Vector2f::operator -=)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opMulAssign"), &Vector2f::operator *=)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opDivAssign"), &Vector2f::operator /=)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opModAssign"), &Vector2f::operator %=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opAddAssignS"), &Vector2f::operator +=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opSubAssignS"), &Vector2f::operator -=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opMulAssignS"), &Vector2f::operator *=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opDivAssignS"), &Vector2f::operator /=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opModAssignS"), &Vector2f::operator %=)
.Func<Vector2f & (Vector2f::*)(void)>(_SC("opPreInc"), &Vector2f::operator ++)
.Func<Vector2f & (Vector2f::*)(void)>(_SC("opPreDec"), &Vector2f::operator --)
.Func<Vector2f (Vector2f::*)(int)>(_SC("opPostInc"), &Vector2f::operator ++)
.Func<Vector2f (Vector2f::*)(int)>(_SC("opPostDec"), &Vector2f::operator --)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opAdd"), &Vector2f::operator +)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opSub"), &Vector2f::operator -)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opMul"), &Vector2f::operator *)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opDiv"), &Vector2f::operator /)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opMod"), &Vector2f::operator %)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opAddS"), &Vector2f::operator +)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opSubS"), &Vector2f::operator -)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opMulS"), &Vector2f::operator *)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opDivS"), &Vector2f::operator /)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opModS"), &Vector2f::operator %)
.Func<Vector2f (Vector2f::*)(void) const>(_SC("opUnPlus"), &Vector2f::operator +)
.Func<Vector2f (Vector2f::*)(void) const>(_SC("opUnMinus"), &Vector2f::operator -)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opEqual"), &Vector2f::operator ==)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opNotEqual"), &Vector2f::operator !=)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opLessThan"), &Vector2f::operator <)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opGreaterThan"), &Vector2f::operator >)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opLessEqual"), &Vector2f::operator <=)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opGreaterEqual"), &Vector2f::operator >=)
);
LogDbg("Registration of <Vector2f> type was successful");
return true;
}
} // Namespace:: SqMod

View File

@@ -1,16 +1,16 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Vector2i.hpp"
#include "Base/Vector2u.hpp"
#include "Base/Vector2f.hpp"
#include "Base/Vector2.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector2i Vector2i::NIL = Vector2i(0);
const Vector2i Vector2i::MIN = Vector2i(std::numeric_limits<Vector2i::Value>::min());
const Vector2i Vector2i::MAX = Vector2i(std::numeric_limits<Vector2i::Value>::max());
const Vector2i Vector2i::MIN = Vector2i(NumLimit< Vector2i::Value >::Min);
const Vector2i Vector2i::MAX = Vector2i(NumLimit< Vector2i::Value >::Max);
// ------------------------------------------------------------------------------------------------
SQChar Vector2i::Delim = ',';
@@ -19,72 +19,41 @@ SQChar Vector2i::Delim = ',';
Vector2i::Vector2i()
: x(0), y(0)
{
/* ... */
}
Vector2i::Vector2i(Value s)
: x(s), y(s)
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i(Value sv)
: x(sv), y(sv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i(Value xv, Value yv)
: x(xv), y(yv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i(const Vector2u & v)
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
Vector2i::Vector2i(const Vector2i & o)
: x(o.x), y(o.y)
{
}
Vector2i::Vector2i(const Vector2f & v)
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i(const SQChar * values, SQChar delim)
: Vector2i(GetVector2i(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i(const Vector2i & v)
: x(v.x), y(v.y)
{
}
Vector2i::Vector2i(Vector2i && v)
: x(v.x), y(v.y)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2i::~Vector2i()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector2i & Vector2i::operator = (const Vector2i & v)
Vector2i & Vector2i::operator = (const Vector2i & o)
{
x = v.x;
y = v.y;
return *this;
}
Vector2i & Vector2i::operator = (Vector2i && v)
{
x = v.x;
y = v.y;
x = o.x;
y = o.y;
return *this;
}
@@ -96,23 +65,16 @@ Vector2i & Vector2i::operator = (Value s)
return *this;
}
Vector2i & Vector2i::operator = (const SQChar * values)
Vector2i & Vector2i::operator = (CSStr values)
{
Set(GetVector2i(values, Delim));
return *this;
}
Vector2i & Vector2i::operator = (const Vector2u & v)
Vector2i & Vector2i::operator = (const Vector2 & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
Vector2i & Vector2i::operator = (const Vector2f & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
x = Value(v.x);
y = Value(v.y);
return *this;
}
@@ -395,7 +357,7 @@ Vector2i Vector2i::operator >> (Value s) const
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::operator + () const
{
return Vector2i(std::abs(x), std::abs(y));
return Vector2i(abs(x), abs(y));
}
Vector2i Vector2i::operator - () const
@@ -441,13 +403,18 @@ bool Vector2i::operator >= (const Vector2i & v) const
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector2i::Cmp(const Vector2i & v) const
Int32 Vector2i::Cmp(const Vector2i & o) const
{
return *this == v ? 0 : (*this > v ? 1 : -1);
if (*this == o)
return 0;
else if (*this > o)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector2i::ToString() const
CSStr Vector2i::ToString() const
{
return ToStringF("%d,%d", x, y);
}
@@ -472,20 +439,14 @@ void Vector2i::Set(const Vector2i & v)
y = v.y;
}
void Vector2i::Set(const Vector2u & v)
void Vector2i::Set(const Vector2 & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
}
void Vector2i::Set(const Vector2f & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
x = Value(v.x);
y = Value(v.y);
}
// ------------------------------------------------------------------------------------------------
void Vector2i::Set(const SQChar * values, SQChar delim)
void Vector2i::Set(CSStr values, SQChar delim)
{
Set(GetVector2i(values, delim));
}
@@ -493,20 +454,20 @@ void Vector2i::Set(const SQChar * values, SQChar delim)
// ------------------------------------------------------------------------------------------------
void Vector2i::Generate()
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
x = GetRandomInt32();
y = GetRandomInt32();
}
void Vector2i::Generate(Value min, Value max)
{
if (max < min)
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
x = GetRandomInt32(min, max);
y = GetRandomInt32(min, max);
}
}
@@ -514,63 +475,61 @@ void Vector2i::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (xmax < xmin || ymax < ymin)
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(ymin, ymax);
y = RandomVal<Value>::Get(xmin, xmax);
x = GetRandomInt32(ymin, ymax);
y = GetRandomInt32(xmin, xmax);
}
}
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::Abs() const
{
return Vector2i(std::abs(x), std::abs(y));
return Vector2i(abs(x), abs(y));
}
// ================================================================================================
bool Register_Vector2i(HSQUIRRELVM vm)
void Register_Vector2i(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector2i> type");
typedef Vector2i::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector2i"), Sqrat::Class<Vector2i>(vm, _SC("Vector2i"))
RootTable(vm).Bind(_SC("Vector2i"), Class< Vector2i >(vm, _SC("Vector2i"))
/* Constructors */
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val>()
.SetStaticValue(_SC("delim"), &Vector2i::Delim)
.Ctor< Val >()
.Ctor< Val, Val >()
/* 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 */
.Func(_SC("_tostring"), &Vector2i::ToString)
.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 -)
.Overload<void (Vector2i::*)(Val)>(_SC("set"), &Vector2i::Set)
.Overload<void (Vector2i::*)(Val, Val)>(_SC("set"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const Vector2i &)>(_SC("set_vec2i"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const Vector2u &)>(_SC("set_vec2u"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const Vector2f &)>(_SC("set_vec2f"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector2i::Set)
.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)
.Func(_SC("clear"), &Vector2i::Clear)
/* 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 *=)
@@ -631,10 +590,6 @@ bool Register_Vector2i(HSQUIRRELVM vm)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opLessEqual"), &Vector2i::operator <=)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opGreaterEqual"), &Vector2i::operator >=)
);
LogDbg("Registration of <Vector2i> type was successful");
return true;
}
} // Namespace:: SqMod

View File

@@ -2,20 +2,20 @@
#define _BASE_VECTOR2I_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct Vector2i
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef SQInt32 Value;
typedef int Value;
/* --------------------------------------------------------------------------------------------
* ...
@@ -35,14 +35,14 @@ struct Vector2i
Value x, y;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector2i();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2i(Value s);
Vector2i(Value sv);
/* --------------------------------------------------------------------------------------------
* ...
@@ -50,44 +50,19 @@ struct Vector2i
Vector2i(Value xv, Value yv);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector2i(const Vector2u & v);
Vector2i(const Vector2i & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2i(const Vector2f & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2i(const SQChar * values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2i(const Vector2i & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2i(Vector2i && v);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
~Vector2i();
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector2i & operator = (const Vector2i & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2i & operator = (Vector2i && v);
Vector2i & operator = (const Vector2i & o);
/* --------------------------------------------------------------------------------------------
* ...
@@ -97,17 +72,12 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2i & operator = (const SQChar * values);
Vector2i & operator = (CSStr values);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2i & operator = (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2i & operator = (const Vector2f & v);
Vector2i & operator = (const Vector2 & v);
/* --------------------------------------------------------------------------------------------
* ...
@@ -377,12 +347,12 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Vector2i & v) const;
Int32 Cmp(const Vector2i & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -402,17 +372,12 @@ struct Vector2i
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector2u & v);
void Set(const Vector2 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector2f & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * values, SQChar delim);
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
@@ -445,4 +410,4 @@ struct Vector2i
} // Namespace:: SqMod
#endif // _BASE_VECTOR2I_HPP_
#endif // _BASE_VECTOR2I_HPP_

View File

@@ -1,640 +0,0 @@
#include "Base/Vector2u.hpp"
#include "Base/Vector2f.hpp"
#include "Base/Vector2i.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector2u Vector2u::NIL = Vector2u(0);
const Vector2u Vector2u::MIN = Vector2u(std::numeric_limits<Vector2u::Value>::min());
const Vector2u Vector2u::MAX = Vector2u(std::numeric_limits<Vector2u::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Vector2u::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector2u::Vector2u()
: x(0), y(0)
{
}
Vector2u::Vector2u(Value s)
: x(s), y(s)
{
}
Vector2u::Vector2u(Value xv, Value yv)
: x(xv), y(yv)
{
}
// ------------------------------------------------------------------------------------------------
Vector2u::Vector2u(const Vector2i & v)
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
Vector2u::Vector2u(const Vector2f & v)
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
// ------------------------------------------------------------------------------------------------
Vector2u::Vector2u(const SQChar * values, SQChar delim)
: Vector2u(GetVector2u(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector2u::Vector2u(const Vector2u & v)
: x(v.x), y(v.y)
{
}
Vector2u::Vector2u(Vector2u && v)
: x(v.x), y(v.y)
{
}
// ------------------------------------------------------------------------------------------------
Vector2u::~Vector2u()
{
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator = (const Vector2u & v)
{
x = v.x;
y = v.y;
return *this;
}
Vector2u & Vector2u::operator = (Vector2u && v)
{
x = v.x;
y = v.y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator = (Value s)
{
x = s;
y = s;
return *this;
}
Vector2u & Vector2u::operator = (const SQChar * values)
{
Set(GetVector2i(values, Delim));
return *this;
}
Vector2u & Vector2u::operator = (const Vector2i & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
Vector2u & Vector2u::operator = (const Vector2f & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator += (const Vector2u & v)
{
x += v.x;
y += v.y;
return *this;
}
Vector2u & Vector2u::operator -= (const Vector2u & v)
{
x -= v.x;
y -= v.y;
return *this;
}
Vector2u & Vector2u::operator *= (const Vector2u & v)
{
x *= v.x;
y *= v.y;
return *this;
}
Vector2u & Vector2u::operator /= (const Vector2u & v)
{
x /= v.x;
y /= v.y;
return *this;
}
Vector2u & Vector2u::operator %= (const Vector2u & v)
{
x %= v.x;
y %= v.y;
return *this;
}
Vector2u & Vector2u::operator &= (const Vector2u & v)
{
x &= v.x;
y &= v.y;
return *this;
}
Vector2u & Vector2u::operator |= (const Vector2u & v)
{
x |= v.x;
y |= v.y;
return *this;
}
Vector2u & Vector2u::operator ^= (const Vector2u & v)
{
x ^= v.x;
y ^= v.y;
return *this;
}
Vector2u & Vector2u::operator <<= (const Vector2u & v)
{
x <<= v.x;
y <<= v.y;
return *this;
}
Vector2u & Vector2u::operator >>= (const Vector2u & v)
{
x >>= v.x;
y >>= v.y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator += (Value s)
{
x += s;
y += s;
return *this;
}
Vector2u & Vector2u::operator -= (Value s)
{
x -= s;
y -= s;
return *this;
}
Vector2u & Vector2u::operator *= (Value s)
{
x *= s;
y *= s;
return *this;
}
Vector2u & Vector2u::operator /= (Value s)
{
x /= s;
y /= s;
return *this;
}
Vector2u & Vector2u::operator %= (Value s)
{
x %= s;
y %= s;
return *this;
}
Vector2u & Vector2u::operator &= (Value s)
{
x &= s;
y &= s;
return *this;
}
Vector2u & Vector2u::operator |= (Value s)
{
x |= s;
y |= s;
return *this;
}
Vector2u & Vector2u::operator ^= (Value s)
{
x ^= s;
y ^= s;
return *this;
}
Vector2u & Vector2u::operator <<= (Value s)
{
x <<= s;
y <<= s;
return *this;
}
Vector2u & Vector2u::operator >>= (Value s)
{
x >>= s;
y >>= s;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator ++ ()
{
++x;
++y;
return *this;
}
Vector2u & Vector2u::operator -- ()
{
--x;
--y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator ++ (int)
{
Vector2i state(*this);
++x;
++y;
return state;
}
Vector2u Vector2u::operator -- (int)
{
Vector2i state(*this);
--x;
--y;
return state;
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator + (const Vector2u & v) const
{
return Vector2i(x + v.x, y + v.y);
}
Vector2u Vector2u::operator - (const Vector2u & v) const
{
return Vector2i(x - v.x, y - v.y);
}
Vector2u Vector2u::operator * (const Vector2u & v) const
{
return Vector2i(x * v.x, y * v.y);
}
Vector2u Vector2u::operator / (const Vector2u & v) const
{
return Vector2i(x / v.x, y / v.y);
}
Vector2u Vector2u::operator % (const Vector2u & v) const
{
return Vector2i(x % v.x, y % v.y);
}
Vector2u Vector2u::operator & (const Vector2u & v) const
{
return Vector2i(x & v.x, y & v.y);
}
Vector2u Vector2u::operator | (const Vector2u & v) const
{
return Vector2i(x | v.x, y | v.y);
}
Vector2u Vector2u::operator ^ (const Vector2u & v) const
{
return Vector2i(x ^ v.x, y ^ v.y);
}
Vector2u Vector2u::operator << (const Vector2u & v) const
{
return Vector2i(x << v.x, y << v.y);
}
Vector2u Vector2u::operator >> (const Vector2u & v) const
{
return Vector2i(x >> v.x, y >> v.y);
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator + (Value s) const
{
return Vector2i(x + s, y + s);
}
Vector2u Vector2u::operator - (Value s) const
{
return Vector2i(x - s, y - s);
}
Vector2u Vector2u::operator * (Value s) const
{
return Vector2i(x - s, y - s);
}
Vector2u Vector2u::operator / (Value s) const
{
return Vector2i(x / s, y / s);
}
Vector2u Vector2u::operator % (Value s) const
{
return Vector2i(x % s, y % s);
}
Vector2u Vector2u::operator & (Value s) const
{
return Vector2i(x & s, y & s);
}
Vector2u Vector2u::operator | (Value s) const
{
return Vector2i(x | s, y | s);
}
Vector2u Vector2u::operator ^ (Value s) const
{
return Vector2i(x ^ s, y ^ s);
}
Vector2u Vector2u::operator << (Value s) const
{
return Vector2i(x << s, y << s);
}
Vector2u Vector2u::operator >> (Value s) const
{
return Vector2i(x >> s, y >> s);
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator + () const
{
return Vector2i(x, y);
}
Vector2u Vector2u::operator - () const
{
return Vector2i(0, 0);
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator ~ () const
{
return Vector2i(~x, ~y);
}
// ------------------------------------------------------------------------------------------------
bool Vector2u::operator == (const Vector2u & v) const
{
return (x == v.x) && (y == v.y);
}
bool Vector2u::operator != (const Vector2u & v) const
{
return (x != v.x) && (y != v.y);
}
bool Vector2u::operator < (const Vector2u & v) const
{
return (x < v.x) && (y < v.y);
}
bool Vector2u::operator > (const Vector2u & v) const
{
return (x > v.x) && (y > v.y);
}
bool Vector2u::operator <= (const Vector2u & v) const
{
return (x <= v.x) && (y <= v.y);
}
bool Vector2u::operator >= (const Vector2u & v) const
{
return (x >= v.x) && (y >= v.y);
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector2u::Cmp(const Vector2u & v) const
{
return *this == v ? 0 : (*this > v ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector2u::ToString() const
{
return ToStringF("%u,%u", x, y);
}
// ------------------------------------------------------------------------------------------------
void Vector2u::Set(Value ns)
{
x = ns;
y = ns;
}
void Vector2u::Set(Value nx, Value ny)
{
x = nx;
y = ny;
}
// ------------------------------------------------------------------------------------------------
void Vector2u::Set(const Vector2u & v)
{
x = v.x;
y = v.y;
}
void Vector2u::Set(const Vector2i & v)
{
x = static_cast<SQInt32>(v.x);
y = static_cast<SQInt32>(v.y);
}
void Vector2u::Set(const Vector2f & v)
{
x = static_cast<SQInt32>(v.x);
y = static_cast<SQInt32>(v.y);
}
// ------------------------------------------------------------------------------------------------
void Vector2u::Set(const SQChar * values, SQChar delim)
{
Set(GetVector2i(values, delim));
}
// ------------------------------------------------------------------------------------------------
void Vector2u::Generate()
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
}
void Vector2u::Generate(Value min, Value max)
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
}
}
void Vector2u::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (xmax < xmin || ymax < ymin)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(ymin, ymax);
y = RandomVal<Value>::Get(xmin, xmax);
}
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::Abs() const
{
return Vector2i(x, y);
}
// ================================================================================================
bool Register_Vector2u(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector2u> type");
typedef Vector2u::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector2u"), Sqrat::Class<Vector2u>(vm, _SC("Vector2u"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val>()
.SetStaticValue(_SC("delim"), &Vector2u::Delim)
.Var(_SC("x"), &Vector2u::x)
.Var(_SC("y"), &Vector2u::y)
.Prop(_SC("abs"), &Vector2u::Abs)
.Func(_SC("_tostring"), &Vector2u::ToString)
.Func(_SC("_cmp"), &Vector2u::Cmp)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_add"), &Vector2u::operator +)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_sub"), &Vector2u::operator -)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_mul"), &Vector2u::operator *)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_div"), &Vector2u::operator /)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_modulo"), &Vector2u::operator %)
.Func<Vector2u (Vector2u::*)(void) const>(_SC("_unm"), &Vector2u::operator -)
.Overload<void (Vector2u::*)(Val)>(_SC("set"), &Vector2u::Set)
.Overload<void (Vector2u::*)(Val, Val)>(_SC("set"), &Vector2u::Set)
.Overload<void (Vector2u::*)(const Vector2u &)>(_SC("set_vec2u"), &Vector2u::Set)
.Overload<void (Vector2u::*)(const Vector2i &)>(_SC("set_vec2i"), &Vector2u::Set)
.Overload<void (Vector2u::*)(const Vector2f &)>(_SC("set_vec2f"), &Vector2u::Set)
.Overload<void (Vector2u::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector2u::Set)
.Overload<void (Vector2u::*)(void)>(_SC("generate"), &Vector2u::Generate)
.Overload<void (Vector2u::*)(Val, Val)>(_SC("generate"), &Vector2u::Generate)
.Overload<void (Vector2u::*)(Val, Val, Val, Val)>(_SC("generate"), &Vector2u::Generate)
.Func(_SC("clear"), &Vector2u::Clear)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opAddAssign"), &Vector2u::operator +=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opSubAssign"), &Vector2u::operator -=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opMulAssign"), &Vector2u::operator *=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opDivAssign"), &Vector2u::operator /=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opModAssign"), &Vector2u::operator %=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opAndAssign"), &Vector2u::operator &=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opOrAssign"), &Vector2u::operator |=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opXorAssign"), &Vector2u::operator ^=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opShlAssign"), &Vector2u::operator <<=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opShrAssign"), &Vector2u::operator >>=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opAddAssignS"), &Vector2u::operator +=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opSubAssignS"), &Vector2u::operator -=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opMulAssignS"), &Vector2u::operator *=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opDivAssignS"), &Vector2u::operator /=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opModAssignS"), &Vector2u::operator %=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opAndAssignS"), &Vector2u::operator &=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opOrAssignS"), &Vector2u::operator |=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opXorAssignS"), &Vector2u::operator ^=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opShlAssignS"), &Vector2u::operator <<=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opShrAssignS"), &Vector2u::operator >>=)
.Func<Vector2u & (Vector2u::*)(void)>(_SC("opPreInc"), &Vector2u::operator ++)
.Func<Vector2u & (Vector2u::*)(void)>(_SC("opPreDec"), &Vector2u::operator --)
.Func<Vector2u (Vector2u::*)(int)>(_SC("opPostInc"), &Vector2u::operator ++)
.Func<Vector2u (Vector2u::*)(int)>(_SC("opPostDec"), &Vector2u::operator --)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opAdd"), &Vector2u::operator +)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opSub"), &Vector2u::operator -)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opMul"), &Vector2u::operator *)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opDiv"), &Vector2u::operator /)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opMod"), &Vector2u::operator %)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opAnd"), &Vector2u::operator &)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opOr"), &Vector2u::operator |)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opShl"), &Vector2u::operator ^)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opShl"), &Vector2u::operator <<)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opShr"), &Vector2u::operator >>)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opAddS"), &Vector2u::operator +)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opSubS"), &Vector2u::operator -)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opMulS"), &Vector2u::operator *)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opDivS"), &Vector2u::operator /)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opModS"), &Vector2u::operator %)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opAndS"), &Vector2u::operator &)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opOrS"), &Vector2u::operator |)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opShlS"), &Vector2u::operator ^)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opShlS"), &Vector2u::operator <<)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opShrS"), &Vector2u::operator >>)
.Func<Vector2u (Vector2u::*)(void) const>(_SC("opUnPlus"), &Vector2u::operator +)
.Func<Vector2u (Vector2u::*)(void) const>(_SC("opUnMinus"), &Vector2u::operator -)
.Func<Vector2u (Vector2u::*)(void) const>(_SC("opCom"), &Vector2u::operator ~)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opEqual"), &Vector2u::operator ==)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opNotEqual"), &Vector2u::operator !=)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opLessThan"), &Vector2u::operator <)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opGreaterThan"), &Vector2u::operator >)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opLessEqual"), &Vector2u::operator <=)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opGreaterEqual"), &Vector2u::operator >=)
);
LogDbg("Registration of <Vector2u> type was successful");
return true;
}
} // Namespace:: SqMod

View File

@@ -1,448 +0,0 @@
#ifndef _BASE_VECTOR2U_HPP_
#define _BASE_VECTOR2U_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Vector2u
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef SQUnsignedInteger32 Value;
/* --------------------------------------------------------------------------------------------
* ...
*/
static const Vector2u NIL;
static const Vector2u MIN;
static const Vector2u MAX;
/* --------------------------------------------------------------------------------------------
* ...
*/
static SQChar Delim;
/* --------------------------------------------------------------------------------------------
* ...
*/
Value x, y;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u(Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u(Value xv, Value yv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u(const Vector2i & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u(const Vector2f & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u(const SQChar * values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u(const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u(Vector2u && v);
/* --------------------------------------------------------------------------------------------
* ...
*/
~Vector2u();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator = (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator = (Vector2u && v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator = (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator = (const SQChar * values);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator = (const Vector2i & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator = (const Vector2f & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator += (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator -= (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator *= (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator /= (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator %= (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator &= (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator |= (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator ^= (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator <<= (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator >>= (const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator += (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator -= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator *= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator /= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator %= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator &= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator |= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator ^= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator <<= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator >>= (Value s);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator ++ ();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u & operator -- ();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator ++ (int);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator -- (int);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator + (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator + (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator - (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator - (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator * (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator * (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator / (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator / (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator % (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator % (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator & (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator & (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator | (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator | (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator ^ (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator ^ (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator << (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator << (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator >> (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator >> (Value s) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator + () const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator - () const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u operator ~ () const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator == (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator != (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator < (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator > (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator <= (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator >= (const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Vector2u & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(Value ns);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(Value nx, Value ny);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector2u & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector2i & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const Vector2f & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Generate();
/* --------------------------------------------------------------------------------------------
* ...
*/
void Generate(Value min, Value max);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Generate(Value xmin, Value xmax, Value ymin, Value ymax);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Clear()
{
x = 0, y = 0;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector2u Abs() const;
};
} // Namespace:: SqMod
#endif // _BASE_VECTOR2U_HPP_

View File

@@ -1,16 +1,17 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Vector3.hpp"
#include "Base/Vector4.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector3 Vector3::NIL = Vector3(0);
const Vector3 Vector3::MIN = Vector3(std::numeric_limits<Vector3::Value>::min());
const Vector3 Vector3::MAX = Vector3(std::numeric_limits<Vector3::Value>::max());
const Vector3 Vector3::MIN = Vector3(NumLimit< Vector3::Value >::Min);
const Vector3 Vector3::MAX = Vector3(NumLimit< Vector3::Value >::Max);
// ------------------------------------------------------------------------------------------------
SQChar Vector3::Delim = ',';
@@ -19,74 +20,42 @@ SQChar Vector3::Delim = ',';
Vector3::Vector3()
: x(0.0), y(0.0), z(0.0)
{
/* ... */
}
Vector3::Vector3(Value s)
: x(s), y(s), z(s)
// ------------------------------------------------------------------------------------------------
Vector3::Vector3(Value sv)
: x(sv), y(sv), z(sv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector3::Vector3(Value xv, Value yv, Value zv)
: x(xv), y(yv), z(zv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector3::Vector3(const Vector4 & v)
: x(v.x), y(v.y), z(v.z)
Vector3::Vector3(const Vector3 & o)
: x(o.x), y(o.y), z(o.z)
{
}
Vector3::Vector3(const Quaternion & q)
: x(q.x), y(q.y), z(q.z)
{
}
// ------------------------------------------------------------------------------------------------
Vector3::Vector3(const SQChar * values, char delim)
: Vector3(GetVector3(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector3::Vector3(const Vector3 & v)
: x(v.x), y(v.y), z(v.z)
{
}
Vector3::Vector3(Vector3 && v)
: x(v.x), y(v.y), z(v.z)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector3::~Vector3()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector3 & Vector3::operator = (const Vector3 & v)
Vector3 & Vector3::operator = (const Vector3 & o)
{
x = v.x;
y = v.y;
z = v.z;
return *this;
}
Vector3 & Vector3::operator = (Vector3 && v)
{
x = v.x;
y = v.y;
z = v.z;
x = o.x;
y = o.y;
z = o.z;
return *this;
}
@@ -150,9 +119,9 @@ Vector3 & Vector3::operator /= (const Vector3 & v)
Vector3 & Vector3::operator %= (const Vector3 & v)
{
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
z = std::fmod(z, v.z);
x = fmod(x, v.x);
y = fmod(y, v.y);
z = fmod(z, v.z);
return *this;
}
@@ -191,9 +160,9 @@ Vector3 & Vector3::operator /= (Value s)
Vector3 & Vector3::operator %= (Value s)
{
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
x = fmod(x, s);
y = fmod(y, s);
z = fmod(z, s);
return *this;
}
@@ -256,7 +225,7 @@ Vector3 Vector3::operator / (const Vector3 & v) const
Vector3 Vector3::operator % (const Vector3 & v) const
{
return Vector3(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z));
return Vector3(fmod(x, v.x), fmod(y, v.y), fmod(z, v.z));
}
// ------------------------------------------------------------------------------------------------
@@ -282,13 +251,13 @@ Vector3 Vector3::operator / (Value s) const
Vector3 Vector3::operator % (Value s) const
{
return Vector3(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s));
return Vector3(fmod(x, s), fmod(y, s), fmod(z, s));
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::operator + () const
{
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
return Vector3(fabs(x), fabs(y), fabs(z));
}
Vector3 Vector3::operator - () const
@@ -309,32 +278,37 @@ bool Vector3::operator != (const Vector3 & v) const
bool Vector3::operator < (const Vector3 & v) const
{
return std::isless(x, v.x) && std::isless(y, v.y) && std::isless(z, v.z);
return EpsLt(x, v.x) && EpsLt(y, v.y) && EpsLt(z, v.z);
}
bool Vector3::operator > (const Vector3 & v) const
{
return std::isgreater(x, v.x) && std::isgreater(y, v.y) && std::isgreater(z, v.z);
return EpsGt(x, v.x) && EpsGt(y, v.y) && EpsGt(z, v.z);
}
bool Vector3::operator <= (const Vector3 & v) const
{
return std::islessequal(x, v.x) && std::islessequal(y, v.y) && std::islessequal(z, v.z);
return EpsLtEq(x, v.x) && EpsLtEq(y, v.y) && EpsLtEq(z, v.z);
}
bool Vector3::operator >= (const Vector3 & v) const
{
return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y) && std::isgreaterequal(z, v.z);
return EpsGtEq(x, v.x) && EpsGtEq(y, v.y) && EpsGtEq(z, v.z);
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector3::Cmp(const Vector3 & v) const
Int32 Vector3::Cmp(const Vector3 & o) const
{
return *this == v ? 0 : (*this > v ? 1 : -1);
if (*this == o)
return 0;
else if (*this > o)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector3::ToString() const
CSStr Vector3::ToString() const
{
return ToStringF("%f,%f,%f", x, y, z);
}
@@ -377,7 +351,7 @@ void Vector3::Set(const Quaternion & q)
}
// ------------------------------------------------------------------------------------------------
void Vector3::Set(const SQChar * values, char delim)
void Vector3::Set(CSStr values, SQChar delim)
{
Set(GetVector3(values, delim));
}
@@ -385,89 +359,87 @@ void Vector3::Set(const SQChar * values, char delim)
// ------------------------------------------------------------------------------------------------
void Vector3::Generate()
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
z = RandomVal<Value>::Get();
x = GetRandomFloat32();
y = GetRandomFloat32();
z = GetRandomFloat32();
}
void Vector3::Generate(Value min, Value max)
{
if (max < min)
if (EpsLt(max, min))
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
z = RandomVal<Value>::Get(min, max);
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
z = GetRandomFloat32(min, max);
}
}
void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax)
{
if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin))
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin))
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(xmin, xmax);
y = RandomVal<Value>::Get(ymin, ymax);
z = RandomVal<Value>::Get(zmin, zmax);
x = GetRandomFloat32(xmin, xmax);
y = GetRandomFloat32(ymin, ymax);
z = GetRandomFloat32(zmin, zmax);
}
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::Abs() const
{
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
return Vector3(fabs(x), fabs(y), fabs(z));
}
// ================================================================================================
bool Register_Vector3(HSQUIRRELVM vm)
void Register_Vector3(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector3> type");
typedef Vector3::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector3"), Sqrat::Class<Vector3>(vm, _SC("Vector3"))
RootTable(vm).Bind(_SC("Vector3"), Class< Vector3 >(vm, _SC("Vector3"))
/* Constructors */
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Vector3::Delim)
.Ctor< Val >()
.Ctor< Val, Val, Val >()
/* 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 */
.Func(_SC("_tostring"), &Vector3::ToString)
.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 -)
.Overload<void (Vector3::*)(Val)>(_SC("set"), &Vector3::Set)
.Overload<void (Vector3::*)(Val, Val, Val)>(_SC("set"), &Vector3::Set)
.Overload<void (Vector3::*)(const Vector3 &)>(_SC("set_vec3"), &Vector3::Set)
.Overload<void (Vector3::*)(const Vector4 &)>(_SC("set_vec4"), &Vector3::Set)
.Overload<void (Vector3::*)(const Quaternion &)>(_SC("set_quat"), &Vector3::Set)
.Overload<void (Vector3::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector3::Set)
.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)
.Func(_SC("clear"), &Vector3::Clear)
/* 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 *=)
@@ -507,10 +479,6 @@ bool Register_Vector3(HSQUIRRELVM vm)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opLessEqual"), &Vector3::operator <=)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterEqual"), &Vector3::operator >=)
);
LogDbg("Registration of <Vector3> type was successful");
return true;
}
} // Namespace:: SqMod

View File

@@ -2,20 +2,20 @@
#define _BASE_VECTOR3_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct Vector3
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef SQFloat Value;
typedef float Value;
/* --------------------------------------------------------------------------------------------
* ...
@@ -35,14 +35,14 @@ struct Vector3
Value x, y, z;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector3();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector3(Value s);
Vector3(Value sv);
/* --------------------------------------------------------------------------------------------
* ...
@@ -50,44 +50,19 @@ struct Vector3
Vector3(Value xv, Value yv, Value zv);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector3(const Vector4 & v);
Vector3(const Vector3 & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector3(const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector3(const SQChar * values, char delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector3(const Vector3 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector3(Vector3 && v);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
~Vector3();
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector3 & operator = (const Vector3 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector3 & operator = (Vector3 && v);
Vector3 & operator = (const Vector3 & o);
/* --------------------------------------------------------------------------------------------
* ...
@@ -267,12 +242,12 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Vector3 & v) const;
Int32 Cmp(const Vector3 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -302,7 +277,7 @@ struct Vector3
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * values, char delim);
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
@@ -335,4 +310,4 @@ struct Vector3
} // Namespace:: SqMod
#endif // _BASE_VECTOR3_HPP_
#endif // _BASE_VECTOR3_HPP_

View File

@@ -1,16 +1,17 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Vector4.hpp"
#include "Base/Vector3.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector4 Vector4::NIL = Vector4(0);
const Vector4 Vector4::MIN = Vector4(std::numeric_limits<Vector4::Value>::min());
const Vector4 Vector4::MAX = Vector4(std::numeric_limits<Vector4::Value>::max());
const Vector4 Vector4::MIN = Vector4(NumLimit< Vector4::Value >::Min);
const Vector4 Vector4::MAX = Vector4(NumLimit< Vector4::Value >::Max);
// ------------------------------------------------------------------------------------------------
SQChar Vector4::Delim = ',';
@@ -19,82 +20,50 @@ SQChar Vector4::Delim = ',';
Vector4::Vector4()
: x(0.0), y(0.0), z(0.0), w(0.0)
{
/* ... */
}
Vector4::Vector4(Value s)
: x(s), y(s), z(s), w(s)
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(Value sv)
: x(sv), y(sv), z(sv), w(sv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(Value xv, Value yv, Value zv)
: x(xv), y(yv), z(zv), w(0.0)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(Value xv, Value yv, Value zv, Value wv)
: x(xv), y(yv), z(zv), w(wv)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(const Vector3 & v)
: x(v.x), y(v.y), z(v.z), w(0.0)
Vector4::Vector4(const Vector4 & o)
: x(o.x), y(o.y), z(o.z), w(o.w)
{
}
Vector4::Vector4(const Quaternion & q)
: x(q.x), y(q.y), z(q.z), w(q.w)
{
}
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(const SQChar * values, SQChar delim)
: Vector4(GetVector4(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(const Vector4 & v)
: x(v.x), y(v.y), z(v.z), w(v.w)
{
}
Vector4::Vector4(Vector4 && v)
: x(v.x), y(v.y), z(v.z), w(v.w)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector4::~Vector4()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Vector4 & Vector4::operator = (const Vector4 & v)
Vector4 & Vector4::operator = (const Vector4 & o)
{
x = v.x;
y = v.y;
z = v.z;
w = v.w;
return *this;
}
Vector4 & Vector4::operator = (Vector4 && v)
{
x = v.x;
y = v.y;
z = v.z;
w = v.w;
x = o.x;
y = o.y;
z = o.z;
w = o.w;
return *this;
}
@@ -165,10 +134,10 @@ Vector4 & Vector4::operator /= (const Vector4 & v)
Vector4 & Vector4::operator %= (const Vector4 & v)
{
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
z = std::fmod(z, v.z);
w = std::fmod(w, v.w);
x = fmod(x, v.x);
y = fmod(y, v.y);
z = fmod(z, v.z);
w = fmod(w, v.w);
return *this;
}
@@ -211,10 +180,10 @@ Vector4 & Vector4::operator /= (Value s)
Vector4 & Vector4::operator %= (Value s)
{
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
w = std::fmod(w, s);
x = fmod(x, s);
y = fmod(y, s);
z = fmod(z, s);
w = fmod(w, s);
return *this;
}
@@ -281,7 +250,7 @@ Vector4 Vector4::operator / (const Vector4 & v) const
Vector4 Vector4::operator % (const Vector4 & v) const
{
return Vector4(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z), std::fmod(w, v.w));
return Vector4(fmod(x, v.x), fmod(y, v.y), fmod(z, v.z), fmod(w, v.w));
}
// ------------------------------------------------------------------------------------------------
@@ -307,13 +276,13 @@ Vector4 Vector4::operator / (Value s) const
Vector4 Vector4::operator % (Value s) const
{
return Vector4(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s));
return Vector4(fmod(x, s), fmod(y, s), fmod(z, s), fmod(w, s));
}
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::operator + () const
{
return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
return Vector4(fabs(x), fabs(y), fabs(z), fabs(w));
}
Vector4 Vector4::operator - () const
@@ -334,32 +303,37 @@ bool Vector4::operator != (const Vector4 & v) const
bool Vector4::operator < (const Vector4 & v) const
{
return std::isless(x, v.x) && std::isless(y, v.y) && std::isless(z, v.z) && std::isless(w, v.w);
return EpsLt(x, v.x) && EpsLt(y, v.y) && EpsLt(z, v.z) && EpsLt(w, v.w);
}
bool Vector4::operator > (const Vector4 & v) const
{
return std::isgreater(x, v.x) && std::isgreater(y, v.y) && std::isgreater(z, v.z) && std::isgreater(w, v.w);
return EpsGt(x, v.x) && EpsGt(y, v.y) && EpsGt(z, v.z) && EpsGt(w, v.w);
}
bool Vector4::operator <= (const Vector4 & v) const
{
return std::islessequal(x, v.x) && std::islessequal(y, v.y) && std::islessequal(z, v.z) && std::islessequal(w, v.w);
return EpsLtEq(x, v.x) && EpsLtEq(y, v.y) && EpsLtEq(z, v.z) && EpsLtEq(w, v.w);
}
bool Vector4::operator >= (const Vector4 & v) const
{
return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y) && std::isgreaterequal(z, v.z) && std::isgreaterequal(w, v.w);
return EpsGtEq(x, v.x) && EpsGtEq(y, v.y) && EpsGtEq(z, v.z) && EpsGtEq(w, v.w);
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector4::Cmp(const Vector4 & v) const
Int32 Vector4::Cmp(const Vector4 & o) const
{
return *this == v ? 0 : (*this > v ? 1 : -1);
if (*this == o)
return 0;
else if (*this > o)
return 1;
else
return -1;
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector4::ToString() const
CSStr Vector4::ToString() const
{
return ToStringF("%f,%f,%f,%f", x, y, z, w);
}
@@ -414,7 +388,7 @@ void Vector4::Set(const Quaternion & q)
}
// ------------------------------------------------------------------------------------------------
void Vector4::Set(const SQChar * values, SQChar delim)
void Vector4::Set(CSStr values, SQChar delim)
{
Set(GetVector4(values, delim));
}
@@ -422,95 +396,93 @@ void Vector4::Set(const SQChar * values, SQChar delim)
// ------------------------------------------------------------------------------------------------
void Vector4::Generate()
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
z = RandomVal<Value>::Get();
w = RandomVal<Value>::Get();
x = GetRandomFloat32();
y = GetRandomFloat32();
z = GetRandomFloat32();
w = GetRandomFloat32();
}
void Vector4::Generate(Value min, Value max)
{
if (max < min)
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
z = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
z = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
}
}
void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
{
if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin) || std::isless(wmax, wmin))
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
{
LogErr("max value is lower than min value");
SqThrow("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(xmin, xmax);
y = RandomVal<Value>::Get(ymin, ymax);
z = RandomVal<Value>::Get(zmin, zmax);
y = RandomVal<Value>::Get(ymin, ymax);
x = GetRandomFloat32(xmin, xmax);
y = GetRandomFloat32(ymin, ymax);
z = GetRandomFloat32(zmin, zmax);
y = GetRandomFloat32(ymin, ymax);
}
}
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::Abs() const
{
return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
return Vector4(fabs(x), fabs(y), fabs(z), fabs(w));
}
// ================================================================================================
bool Register_Vector4(HSQUIRRELVM vm)
void Register_Vector4(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector4> type");
typedef Vector4::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector4"), Sqrat::Class<Vector4>(vm, _SC("Vector4"))
RootTable(vm).Bind(_SC("Vector4"), Class< Vector4 >(vm, _SC("Vector4"))
/* Constructors */
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<Val, Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Vector4::Delim)
.Ctor< Val >()
.Ctor< Val, Val, Val >()
.Ctor< Val, Val, Val, Val >()
/* Static Members */
.SetStaticValue(_SC("Delim"), &Vector4::Delim)
/* 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 */
.Func(_SC("_tostring"), &Vector4::ToString)
.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 -)
.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("set_vec4"), &Vector4::Set)
.Overload<void (Vector4::*)(const Vector3 &)>(_SC("set_vec3"), &Vector4::Set)
.Overload<void (Vector4::*)(const Quaternion &)>(_SC("set_quat"), &Vector4::Set)
.Overload<void (Vector4::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector4::Set)
.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)
.Func(_SC("clear"), &Vector4::Clear)
/* 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 *=)
@@ -550,10 +522,6 @@ bool Register_Vector4(HSQUIRRELVM vm)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opLessEqual"), &Vector4::operator <=)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opGreaterEqual"), &Vector4::operator >=)
);
LogDbg("Registration of <Vector4> type was successful");
return true;
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@@ -2,21 +2,20 @@
#define _BASE_VECTOR4_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*
*/
struct Vector4
{
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef SQFloat Value;
typedef float Value;
/* --------------------------------------------------------------------------------------------
* ...
@@ -36,14 +35,14 @@ struct Vector4
Value x, y, z, w;
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector4();
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector4(Value s);
Vector4(Value sv);
/* --------------------------------------------------------------------------------------------
* ...
@@ -56,44 +55,19 @@ struct Vector4
Vector4(Value xv, Value yv, Value zv, Value wv);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector4(const Vector3 & v);
Vector4(const Vector4 & o);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector4(const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector4(const SQChar * values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector4(const Vector4 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector4(Vector4 && v);
/* --------------------------------------------------------------------------------------------
* ...
*
*/
~Vector4();
/* --------------------------------------------------------------------------------------------
* ...
*
*/
Vector4 & operator = (const Vector4 & v);
/* --------------------------------------------------------------------------------------------
* ...
*/
Vector4 & operator = (Vector4 && v);
Vector4 & operator = (const Vector4 & o);
/* --------------------------------------------------------------------------------------------
* ...
@@ -273,12 +247,12 @@ struct Vector4
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const Vector4 & v) const;
Int32 Cmp(const Vector4 & v) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@@ -313,7 +287,7 @@ struct Vector4
/* --------------------------------------------------------------------------------------------
* ...
*/
void Set(const SQChar * values, SQChar delim);
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* ...
@@ -346,4 +320,4 @@ struct Vector4
} // Namespace:: SqMod
#endif // _BASE_VECTOR4_HPP_
#endif // _BASE_VECTOR4_HPP_

File diff suppressed because it is too large Load Diff

View File

@@ -2,75 +2,42 @@
#define _COMMAND_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
#include "Entity/Player.hpp"
#include "Base/Shared.hpp"
#include "Base/Buffer.hpp"
// ------------------------------------------------------------------------------------------------
#include <unordered_map>
#include <map>
#include <vector>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Flags of the types of values supported by the command arguments.
*/
enum CmdArgType
{
CMDARG_ANY = 0,
CMDARG_INTEGER = (1 << 1),
CMDARG_FLOAT = (1 << 2),
CMDARG_BOOLEAN = (1 << 3),
CMDARG_STRING = (1 << 4),
};
/* ------------------------------------------------------------------------------------------------
* Convert a command type specifier to a name string.
*/
const SQChar * CmdArgSpecToStr(Uint8 spec);
/* ------------------------------------------------------------------------------------------------
* The type of error that's being reported by the command manager.
*/
enum CmdError
{
CMDERR_UNKNOWN = 0,
CMDERR_SYNTAX_ERROR,
CMDERR_UNKNOWN_COMMAND,
CMDERR_MISSING_EXECUTER,
CMDERR_INSUFFICIENT_AUTH,
CMDERR_INCOMPLETE_ARGS,
CMDERR_EXTRANEOUS_ARGS,
CMDERR_UNSUPPORTED_ARG,
CMDERR_EXECUTION_FAILED,
};
// ------------------------------------------------------------------------------------------------
class CmdListener;
/* ------------------------------------------------------------------------------------------------
* Converts a command specifier to a string.
*/
CSStr CmdArgSpecToStr(Uint8 spec);
// ------------------------------------------------------------------------------------------------
#define MAX_CMD_ARGS 12
extern CmdManager * _Cmd;
/* ------------------------------------------------------------------------------------------------
* Helper class used to simplify the code for creating and managing commands.
* Manages command instances and processes executed commands.
*/
class CmdManager
{
/* --------------------------------------------------------------------------------------------
* Allow only the smart pointer to delete this class instance as soon as it's not needed.
*/
friend class std::unique_ptr< CmdManager, void(*)(CmdManager *) >;
// --------------------------------------------------------------------------------------------
friend class CmdListener;
protected:
private:
/* --------------------------------------------------------------------------------------------
* The type of container for storing command listeners.
*/
typedef std::unordered_map< String, CmdListener * > CmdPool;
// --------------------------------------------------------------------------------------------
typedef std::map< String, CmdListener * > CmdList;
/* --------------------------------------------------------------------------------------------
* The type of container for storing command arguments.
*/
typedef std::array< std::pair< Uint8, SqObj >, MAX_CMD_ARGS > CmdArgs;
// --------------------------------------------------------------------------------------------
typedef std::vector< std::pair< Uint8, Object > > CmdArgs;
/* --------------------------------------------------------------------------------------------
* Default constructor.
@@ -78,14 +45,24 @@ protected:
CmdManager();
/* --------------------------------------------------------------------------------------------
* Copy constructor (disabled).
* Copy constructor. (disabled)
*/
CmdManager(const CmdManager &) = delete;
CmdManager(const CmdManager &);
/* --------------------------------------------------------------------------------------------
* Move constructor (disabled).
* Copy assignment operator. (disabled)
*/
CmdManager(CmdManager &&) = delete;
CmdManager & operator = (const CmdManager &);
/* --------------------------------------------------------------------------------------------
* Attach a command listener to a certain name.
*/
void Attach(const String & name, CmdListener * cmd)
{
m_Commands[name] = cmd;
}
public:
/* --------------------------------------------------------------------------------------------
* Destructor.
@@ -93,234 +70,171 @@ protected:
~CmdManager();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled).
* Singleton retriever.
*/
CmdManager & operator = (const CmdManager &) = delete;
static CmdManager * Get()
{
if (!_Cmd)
{
_Cmd = new CmdManager();
}
return _Cmd;
}
/* --------------------------------------------------------------------------------------------
* Move assignment operator (disabled).
*/
CmdManager & operator = (CmdManager &&) = delete;
/* --------------------------------------------------------------------------------------------
* Called by the smart pointer to delete the instance of this class.
*/
static void _Finalizer(CmdManager * ptr);
public:
// --------------------------------------------------------------------------------------------
typedef std::unique_ptr< CmdManager, void(*)(CmdManager *) > Pointer;
/* --------------------------------------------------------------------------------------------
* Creates an instance of this type if one doesn't already exist and returns it.
*/
static Pointer Inst();
/* --------------------------------------------------------------------------------------------
* ...
*/
bool Init();
/* --------------------------------------------------------------------------------------------
* ...
*/
bool Load();
/* --------------------------------------------------------------------------------------------
* ...
*/
void Deinit();
/* --------------------------------------------------------------------------------------------
* ...
*/
void Unload();
/* --------------------------------------------------------------------------------------------
* ...
* Terminate current session.
*/
void Terminate();
/* --------------------------------------------------------------------------------------------
* Called by the core class before the VM is closed to release all resources.
* Dettach a command listener from a certain name.
*/
void VMClose();
void Detach(const String & name)
{
m_Commands.erase(name);
}
/* --------------------------------------------------------------------------------------------
* Bind a command listener to a certain command name.
* Retrieve the error callback.
*/
void Bind(const String & name, CmdListener * cmd);
Function & GetOnError()
{
return m_OnError;
}
/* --------------------------------------------------------------------------------------------
* Unbind a command listener from a certain command name.
* Modify the error callback.
*/
void Unbind(const String & name);
void SetOnError(Object & env, Function & func)
{
m_OnError = Function(env.GetVM(), env, func.GetFunc());
}
/* --------------------------------------------------------------------------------------------
* Retrieve the currently used error handler.
* Retrieve the authentication callback.
*/
Function & GetOnError();
Function & GetOnAuth()
{
return m_OnAuth;
}
/* --------------------------------------------------------------------------------------------
* Change the error handler.
* Modify the authentication callback.
*/
void SetOnError(Function & func);
void SetOnAuth(Object & env, Function & func)
{
m_OnAuth = Function(env.GetVM(), env, func.GetFunc());
}
/* --------------------------------------------------------------------------------------------
* Retrieve the default authority inspector.
* Retrieve the identifier of the last invoker.
*/
Function & GetOnAuth();
Int32 GetInvoker() const
{
return m_Invoker;
}
/* --------------------------------------------------------------------------------------------
* Change the default authority inspector.
* Retrieve the last executed command.
*/
void SetOnAuth(Function & func);
CSStr GetCommand() const
{
return m_Command.c_str();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the default authority inspector.
* Retrieve the argument of the last executed coommand.
*/
const CPlayer & GetInvoker() const;
CSStr GetArgument() const
{
return m_Argument.c_str();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the default authority inspector.
* Run a command under a speciffic player.
*/
SQInt32 GetInvokerID() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the name of the currently executed command.
*/
const SQChar * GetName();
/* --------------------------------------------------------------------------------------------
* Retrieve the argument text of the currently executed command.
*/
const SQChar * GetText();
/* --------------------------------------------------------------------------------------------
* Execute the specified command for the specified player.
*/
void Execute(SQInt32 invoker, const String & str);
Int32 Run(Int32 invoker, CSStr command);
protected:
/* --------------------------------------------------------------------------------------------
* Execute the specified command.
*/
void Exec(CmdListener & cmd);
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Forward the error message to the error handler.
* Forward error message to the error callback.
*/
template < typename... Args> void Error(SQInt32 type, const SQChar * msg, Args&&... args)
template < typename T > void SqError(Int32 type, CSStr msg, T data)
{
// Skip if there's no error handler
if (!m_OnError.IsNull())
{
m_OnError.Execute< SQInt32, const SQChar * >(type, ToStringF(msg, std::forward< Args >(args)...));
m_OnError.Execute< Int32, CSStr, T >(type, msg, data);
}
}
/* --------------------------------------------------------------------------------------------
* Parse the specified argument text and extract the arguments from it.
* Attempt to execute the specified command.
*/
bool Parse(SQUint32 max);
Int32 Exec();
/* --------------------------------------------------------------------------------------------
* Attempt to parse the specified argument.
*/
bool Parse();
private:
/* --------------------------------------------------------------------------------------------
* List of command listeners and their associated names.
*/
CmdPool m_Commands;
// --------------------------------------------------------------------------------------------
Buffer m_Buffer; /* Internal buffer used for parsing commands. */
CmdList m_Commands; /* List of attached commands. */
/* --------------------------------------------------------------------------------------------
* Currently and last command invoker.
*/
CPlayer m_Invoker;
// --------------------------------------------------------------------------------------------
Int32 m_Invoker; /* Current command invoker. */
String m_Command; /* Current command name. */
String m_Argument; /* Current command argument. */
CmdListener* m_Instance; /* Current command instance. */
/* --------------------------------------------------------------------------------------------
* Currently and last used command name.
*/
String m_Name;
// --------------------------------------------------------------------------------------------
CmdArgs m_Argv; /* Extracted command arguments. */
Uint32 m_Argc; /* Extracted arguments count. */
/* --------------------------------------------------------------------------------------------
* Currently and last used command argument text.
*/
String m_Text;
/* --------------------------------------------------------------------------------------------
* Extracted values from the argument text.
*/
CmdArgs m_Argv;
/* --------------------------------------------------------------------------------------------
* Number of values extracted from the argument text.
*/
SQUint32 m_Argc;
/* --------------------------------------------------------------------------------------------
* Custom error handler.
*/
Function m_OnError;
/* --------------------------------------------------------------------------------------------
* Default authority inspector for newly created commands.
*/
Function m_OnAuth;
// --------------------------------------------------------------------------------------------
Function m_OnError; /* Error handler. */
Function m_OnAuth; /* Authentication handler. */
};
// ------------------------------------------------------------------------------------------------
extern const CmdManager::Pointer _Cmd;
/* ------------------------------------------------------------------------------------------------
* Class used to bind to certain commands.
* Attaches to a command name and listens for invocations.
*/
class CmdListener
{
public:
// --------------------------------------------------------------------------------------------
friend class CmdManager;
/* --------------------------------------------------------------------------------------------
* Default constructor.
* Copy constructor. (disabled)
*/
CmdListener();
CmdListener(const CmdListener &);
/* --------------------------------------------------------------------------------------------
* Construct and instance and attach it to the specified name.
* Copy assignment operator. (disabled)
*/
CmdListener(const SQChar * name);
CmdListener & operator = (const CmdListener &);
/* --------------------------------------------------------------------------------------------
* Construct and instance and attach it to the specified name.
* Initialize the instance for the first time.
*/
CmdListener(const SQChar * name, const SQChar * spec);
void Init(CSStr name, CSStr spec, Array & tags, Uint8 min, Uint8 max);
public:
/* --------------------------------------------------------------------------------------------
* Construct and instance and attach it to the specified name.
* Base constructors.
*/
CmdListener(const SQChar * name, const SQChar * spec, Array & tags);
/* --------------------------------------------------------------------------------------------
* Construct and instance and attach it to the specified name.
*/
CmdListener(const SQChar * name, const SQChar * spec, Uint8 min, Uint8 max);
/* --------------------------------------------------------------------------------------------
* Construct and instance and attach it to the specified name.
*/
CmdListener(const SQChar * name, const SQChar * spec, Array & tags, Uint8 min, Uint8 max);
/* --------------------------------------------------------------------------------------------
* Copy constructor (disabled).
*/
CmdListener(const CmdListener & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor (disabled).
*/
CmdListener(CmdListener && o) = delete;
CmdListener(CSStr name);
CmdListener(CSStr name, CSStr spec);
CmdListener(CSStr name, CSStr spec, Array & tags);
CmdListener(CSStr name, CSStr spec, Uint8 min, Uint8 max);
CmdListener(CSStr name, CSStr spec, Array & tags, Uint8 min, Uint8 max);
/* --------------------------------------------------------------------------------------------
* Destructor.
@@ -328,310 +242,148 @@ public:
~CmdListener();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled).
* Used by the script engine to compare two instances of this type.
*/
CmdListener & operator = (const CmdListener & o) = delete;
Int32 Cmp(const CmdListener & o) const;
/* --------------------------------------------------------------------------------------------
* Move assignment operator (disabled).
* Used by the script engine to convert this instance to a string.
*/
CmdListener & operator = (CmdListener && o) = delete;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Used to released stored resources before the VM is closed.
*/
void VMClose();
// --------------------------------------------------------------------------------------------
Uint8 GetArgFlags(Uint32 idx) const;
/* --------------------------------------------------------------------------------------------
* Compare two instances of this type.
*/
SQInt32 Cmp(const CmdListener & o) const;
// --------------------------------------------------------------------------------------------
CSStr GetName() const;
void SetName(CSStr name);
/* --------------------------------------------------------------------------------------------
* Attempt to convert this instance to a string.
*/
const SQChar * ToString() const;
// --------------------------------------------------------------------------------------------
CSStr GetSpec() const;
void SetSpec(CSStr spec);
/* --------------------------------------------------------------------------------------------
* Retrieve the local tag.
*/
const SQChar * GetTag() const;
/* --------------------------------------------------------------------------------------------
* Change the local tag.
*/
void SetTag(const SQChar * tag);
/* --------------------------------------------------------------------------------------------
* Retrieve the local data.
*/
SqObj & GetData();
/* --------------------------------------------------------------------------------------------
* Change the local data.
*/
void SetData(SqObj & data);
/* --------------------------------------------------------------------------------------------
* Retrieve the name of the command.
*/
const SQChar * GetName() const;
/* --------------------------------------------------------------------------------------------
* Change the name of the command.
*/
void SetName(const SQChar * name);
/* --------------------------------------------------------------------------------------------
* Retrieve the argument type specifiers for this command as a string.
*/
const SQChar * GetSpec() const;
/* --------------------------------------------------------------------------------------------
* Change the argument type specifiers for this command by extracting them from a string.
*/
void SetSpec(const SQChar * spec);
/* --------------------------------------------------------------------------------------------
* Retrieve the tag/name of a command argument.
*/
const SQChar * GetArgTag(SQUint32 arg) const;
/* --------------------------------------------------------------------------------------------
* Change the tag/name of a command argument.
*/
void SetArgTag(SQUint32 arg, const SQChar * name);
/* --------------------------------------------------------------------------------------------
* Retrieve the tag/name of multiple command arguments.
*/
// --------------------------------------------------------------------------------------------
Array GetArgTags() const;
/* --------------------------------------------------------------------------------------------
* Change the tag/name of multiple command arguments.
*/
void SetArgTags(Array & tags);
/* --------------------------------------------------------------------------------------------
* Retrieve the help text associated with this command.
*/
const SQChar * GetHelp() const;
// --------------------------------------------------------------------------------------------
CSStr GetHelp() const;
void SetHelp(CSStr help);
/* --------------------------------------------------------------------------------------------
* Change the help text associated with this command.
*/
void SetHelp(const SQChar * help);
// --------------------------------------------------------------------------------------------
CSStr GetInfo() const;
void SetInfo(CSStr info);
/* --------------------------------------------------------------------------------------------
* Retrieve the informational text associated with this command.
*/
const SQChar * GetInfo() const;
// --------------------------------------------------------------------------------------------
Int32 GetAuthority() const;
void SetAuthority(Int32 level);
/* --------------------------------------------------------------------------------------------
* Change the informational text associated with this command.
*/
void SetInfo(const SQChar * info);
// --------------------------------------------------------------------------------------------
bool GetProtected() const;
void SetProtected(bool toggle);
/* --------------------------------------------------------------------------------------------
* Retrieve the function responsible for processing the command.
*/
Function & GetOnExec();
/* --------------------------------------------------------------------------------------------
* Change the function responsible for processing the command.
*/
void SetOnExec(Function & func);
/* --------------------------------------------------------------------------------------------
* Change the function responsible for processing the command.
*/
void SetOnExec_Env(SqObj & env, Function & func);
/* --------------------------------------------------------------------------------------------
* Retrieve the function responsible for testing the invoker authority.
*/
Function & GetOnAuth();
/* --------------------------------------------------------------------------------------------
* Change the function responsible for testing the invoker authority.
*/
void SetOnAuth(Function & func);
/* --------------------------------------------------------------------------------------------
* Change the function responsible for testing the invoker authority.
*/
void SetOnAuth_Env(SqObj & env, Function & func);
/* --------------------------------------------------------------------------------------------
* Retrieve the internal level required to execute this command.
*/
SQInt32 GetLevel() const;
/* --------------------------------------------------------------------------------------------
* Change the internal level required to execute this command.
*/
void SetLevel(SQInt32 level);
/* --------------------------------------------------------------------------------------------
* See whether this command needs explicit authority clearance to execute.
*/
bool GetAuthority() const;
/* --------------------------------------------------------------------------------------------
* Set whether this command needs explicit authority clearance to execute.
*/
void SetAuthority(bool toggle);
/* --------------------------------------------------------------------------------------------
* See whether this command listener is allowed to execute or not.
*/
// --------------------------------------------------------------------------------------------
bool GetSuspended() const;
/* --------------------------------------------------------------------------------------------
* Set whether this command listener is allowed to execute or not.
*/
void SetSuspended(bool toggle);
/* --------------------------------------------------------------------------------------------
* Retrieve the minimum arguments allowed required to execute this command.
*/
Uint8 GetMinArgC() const;
// --------------------------------------------------------------------------------------------
bool GetAssociate() const;
void SetAssociate(bool toggle);
/* --------------------------------------------------------------------------------------------
* Change the minimum arguments allowed required to execute this command.
*/
// --------------------------------------------------------------------------------------------
Uint8 GetMinArgC() const;
void SetMinArgC(Uint8 val);
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum arguments allowed required to execute this command.
*/
// --------------------------------------------------------------------------------------------
Uint8 GetMaxArgC() const;
/* --------------------------------------------------------------------------------------------
* Change the maximum arguments allowed required to execute this command.
*/
void SetMaxArgC(Uint8 val);
/* --------------------------------------------------------------------------------------------
* Makes use of the specified argument type specifiers and tags/names to generate an
* informational string with the allowed command syntax.
*/
// --------------------------------------------------------------------------------------------
bool GetLocked() const;
// --------------------------------------------------------------------------------------------
Function & GetOnExec();
void SetOnExec(Object & env, Function & func);
// --------------------------------------------------------------------------------------------
Function & GetOnAuth();
void SetOnAuth(Object & env, Function & func);
// --------------------------------------------------------------------------------------------
Function & GetOnPost();
void SetOnPost(Object & env, Function & func);
// --------------------------------------------------------------------------------------------
Function & GetOnFail();
void SetOnFail(Object & env, Function & func);
// --------------------------------------------------------------------------------------------
CSStr GetArgTag(Uint32 arg) const;
void SetArgTag(Uint32 arg, CSStr name);
// --------------------------------------------------------------------------------------------
void GenerateInfo(bool full);
/* --------------------------------------------------------------------------------------------
* Check whether the specified argument is compatible with the specified type.
*/
bool ArgCheck(SQUint32 arg, Uint8 mask) const;
// --------------------------------------------------------------------------------------------
bool ArgCheck(Uint32 arg, Uint8 flag) const;
/* --------------------------------------------------------------------------------------------
* Check whether the specified player is allowed to execute this command.
*/
bool AuthCheck(Reference< CPlayer > & player);
/* --------------------------------------------------------------------------------------------
* Check whether the specified player is allowed to execute this command.
*/
bool AuthCheckID(SQInt32 id);
/* --------------------------------------------------------------------------------------------
* Attempt to execute this command.
*/
bool Execute(CPlayer & invoker, Array & args);
// --------------------------------------------------------------------------------------------
bool AuthCheck(CPlayer & player);
bool AuthCheckID(Int32 id);
protected:
// --------------------------------------------------------------------------------------------
typedef std::array< Uint8 , MAX_CMD_ARGS > Args;
// --------------------------------------------------------------------------------------------
typedef std::array< String , MAX_CMD_ARGS > Argt;
typedef Uint8 ArgSpec[SQMOD_MAX_CMD_ARGS];
typedef String ArgTags[SQMOD_MAX_CMD_ARGS];
/* --------------------------------------------------------------------------------------------
* Process the specifiers string.
*
*/
bool ProcSpec(const SQChar * spec);
SQInteger Execute(Object & invoker, Array & args);
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger Execute(Object & invoker, Table & args);
/* --------------------------------------------------------------------------------------------
*
*/
bool ProcSpec(CSStr spec);
private:
/* --------------------------------------------------------------------------------------------
* Array of type specifiers for each of the command arguments.
*/
Args m_Args;
/* --------------------------------------------------------------------------------------------
* Array of strings to be used as the tag/name for each argument.
*/
Argt m_Argt;
/* --------------------------------------------------------------------------------------------
* Minimum arguments allowed to execute this command.
*/
Uint8 m_MinArgc;
/* --------------------------------------------------------------------------------------------
* Maximum arguments allowed to execute this command.
*/
Uint8 m_MaxArgc;
/* --------------------------------------------------------------------------------------------
* The name of the command.
*/
// --------------------------------------------------------------------------------------------
String m_Name;
/* --------------------------------------------------------------------------------------------
* The specifiers for each of the command arguments represented as a string.
*/
// --------------------------------------------------------------------------------------------
ArgSpec m_ArgSpec;
ArgTags m_ArgTags;
// --------------------------------------------------------------------------------------------
Uint8 m_MinArgc;
Uint8 m_MaxArgc;
// --------------------------------------------------------------------------------------------
String m_Spec;
/* --------------------------------------------------------------------------------------------
* Help about the purpose and requirements of the command.
*/
String m_Help;
/* --------------------------------------------------------------------------------------------
* Information for when the command execution failed.
*/
String m_Info;
/* --------------------------------------------------------------------------------------------
* Function responsible for processing the received command arguments.
*/
// --------------------------------------------------------------------------------------------
Function m_OnExec;
/* --------------------------------------------------------------------------------------------
* Function responsible for deciding whether the invoker is allowed to execute.
*/
Function m_OnAuth;
Function m_OnPost;
Function m_OnFail;
/* --------------------------------------------------------------------------------------------
* Arbitrary tag associated with this instance.
*/
String m_Tag;
// --------------------------------------------------------------------------------------------
Int32 m_Authority;
/* --------------------------------------------------------------------------------------------
* Arbitrary data associated with this instance.
*/
SqObj m_Data;
/* --------------------------------------------------------------------------------------------
* The level required to execute this command.
*/
SQInt32 m_Level;
/* --------------------------------------------------------------------------------------------
* Whether this command needs an explicit authority verification in order to execute.
*/
bool m_Authority;
/* --------------------------------------------------------------------------------------------
* Whether the command is allowed to execute or not.
*/
// --------------------------------------------------------------------------------------------
bool m_Protected;
bool m_Suspended;
/* --------------------------------------------------------------------------------------------
* Whether the command is allowed to change name.
*/
bool m_Lock;
bool m_Associate;
bool m_Locked;
};
} // Namespace:: SqMod

View File

@@ -1,73 +0,0 @@
#ifndef _COMMON_HPP_
#define _COMMON_HPP_
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
#include <vcmp.h>
#include <sqrat.h>
// ------------------------------------------------------------------------------------------------
#include <memory>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
using namespace Sqrat;
/* ------------------------------------------------------------------------------------------------
* ...
*/
typedef ::Sqrat::string SqTag;
typedef ::Sqrat::Object SqObj;
// ------------------------------------------------------------------------------------------------
extern PluginFuncs* _Func;
extern PluginCallbacks* _Clbk;
extern PluginInfo* _Info;
/* ------------------------------------------------------------------------------------------------
* ...
*/
SqObj & NullData();
/* ------------------------------------------------------------------------------------------------
* ...
*/
Array & NullArray();
/* ------------------------------------------------------------------------------------------------
* Utility used to transform values into script objects on the default VM
*/
template < typename T > SqObj MakeSqObj(const T & v)
{
// Push the specified value on the stack
Sqrat::PushVar< T >(Sqrat::DefaultVM::Get(), v);
// Get the object off the stack
Sqrat::Var< SqObj > var(Sqrat::DefaultVM::Get(), -1);
// Pop the object from the stack
sq_pop(Sqrat::DefaultVM::Get(), 1);
// Return the object
return var.value;
}
/* ------------------------------------------------------------------------------------------------
* Utility used to transform values into script objects
*/
template < typename T > SqObj MakeSqObj(HSQUIRRELVM vm, const T & v)
{
// Push the specified value on the stack
Sqrat::PushVar< T >(vm, v);
// Get the object off the stack
Sqrat::Var< SqObj > var(vm, -1);
// Pop the object from the stack
sq_pop(vm, 1);
// Return the object
return var.value;
}
} // Namespace:: SqMod
#endif // _COMMON_HPP_

953
source/Constants.cpp Normal file
View File

@@ -0,0 +1,953 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
void Register_Constants(HSQUIRRELVM vm)
{
ConstTable(vm).Enum(_SC("SqMod"), Enumeration(vm)
.Const(_SC("Version"), SQMOD_VERSION)
.Const(_SC("Success"), SQMOD_SUCCESS)
.Const(_SC("Failure"), SQMOD_FAILURE)
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
.Const(_SC("Arch"), SQMOD_ARCHITECTURE)
.Const(_SC("Platform"), SQMOD_PLATFORM)
.Const(_SC("MinChar"), NumLimit< SQChar>::Min)
.Const(_SC("MaxChar"), NumLimit< SQChar >::Max)
.Const(_SC("MinShort"), NumLimit< Int16>::Min)
.Const(_SC("MaxShort"), NumLimit< Int16 >::Max)
.Const(_SC("MinUshort"), NumLimit< Uint16>::Min)
.Const(_SC("MaxUshort"), NumLimit< Uint16 >::Max)
.Const(_SC("MinInt"), NumLimit< SQInteger>::Min)
.Const(_SC("MaxInt"), NumLimit< SQInteger >::Max)
.Const(_SC("MinInt32"), NumLimit< SQInt32>::Min)
.Const(_SC("MaxInt32"), NumLimit< SQInt32 >::Max)
.Const(_SC("MinFloat"), NumLimit< SQFloat>::Min)
.Const(_SC("MaxFloat"), NumLimit< SQFloat >::Max)
);
ConstTable(vm).Enum(_SC("SqArchitectre"), Enumeration(vm)
.Const(_SC("Unknown"), SQMOD_ARCH_ID_UNKNOWN)
.Const(_SC("X32Bit"), SQMOD_ARCH_ID_32_BIT)
.Const(_SC("X64Bit"), SQMOD_ARCH_ID_64_BIT)
);
ConstTable(vm).Enum(_SC("SqPlatform"), Enumeration(vm)
.Const(_SC("Unknown"), SQMOD_PLAT_ID_UNKNOWN)
.Const(_SC("Windows"), SQMOD_PLAT_ID_WINDOWS)
.Const(_SC("Linux"), SQMOD_PLAT_ID_LINUX)
.Const(_SC("MacOS"), SQMOD_PLAT_ID_MACOS)
.Const(_SC("Unix"), SQMOD_PLAT_ID_UNIX)
);
ConstTable(vm).Enum(_SC("SqEvent"), Enumeration(vm)
.Const(_SC("Unknown"), EVT_UNKNOWN)
.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("PlayerRequestClass"), EVT_PLAYERREQUESTCLASS)
.Const(_SC("PlayerRequestSpawn"), EVT_PLAYERREQUESTSPAWN)
.Const(_SC("PlayerSpawn"), EVT_PLAYERSPAWN)
.Const(_SC("PlayerStartTyping"), EVT_PLAYERSTARTTYPING)
.Const(_SC("PlayerStopTyping"), EVT_PLAYERSTOPTYPING)
.Const(_SC("PlayerChat"), EVT_PLAYERCHAT)
.Const(_SC("PlayerCommand"), EVT_PLAYERCOMMAND)
.Const(_SC("PlayerMessage"), EVT_PLAYERMESSAGE)
.Const(_SC("PlayerHealth"), EVT_PLAYERHEALTH)
.Const(_SC("PlayerArmour"), EVT_PLAYERARMOUR)
.Const(_SC("PlayerWeapon"), EVT_PLAYERWEAPON)
.Const(_SC("PlayerMove"), EVT_PLAYERMOVE)
.Const(_SC("PlayerWasted"), EVT_PLAYERWASTED)
.Const(_SC("PlayerKilled"), EVT_PLAYERKILLED)
.Const(_SC("PlayerTeamKill"), EVT_PLAYERTEAMKILL)
.Const(_SC("PlayerSpectate"), EVT_PLAYERSPECTATE)
.Const(_SC("PlayerCrashReport"), EVT_PLAYERCRASHREPORT)
.Const(_SC("PlayerBurning"), EVT_PLAYERBURNING)
.Const(_SC("PlayerCrouching"), EVT_PLAYERCROUCHING)
.Const(_SC("PlayerState"), EVT_PLAYERSTATE)
.Const(_SC("PlayerAction"), EVT_PLAYERACTION)
.Const(_SC("StateNone"), EVT_STATENONE)
.Const(_SC("StateNormal"), EVT_STATENORMAL)
.Const(_SC("StateShooting"), EVT_STATESHOOTING)
.Const(_SC("StateDriver"), EVT_STATEDRIVER)
.Const(_SC("StatePassenger"), EVT_STATEPASSENGER)
.Const(_SC("StateEnterDriver"), EVT_STATEENTERDRIVER)
.Const(_SC("StateEnterPassenger"), EVT_STATEENTERPASSENGER)
.Const(_SC("StateExitVehicle"), EVT_STATEEXITVEHICLE)
.Const(_SC("StateUnspawned"), EVT_STATEUNSPAWNED)
.Const(_SC("ActionNone"), EVT_ACTIONNONE)
.Const(_SC("ActionNormal"), EVT_ACTIONNORMAL)
.Const(_SC("ActionAiming"), EVT_ACTIONAIMING)
.Const(_SC("ActionShooting"), EVT_ACTIONSHOOTING)
.Const(_SC("ActionJumping"), EVT_ACTIONJUMPING)
.Const(_SC("ActionLiedown"), EVT_ACTIONLIEDOWN)
.Const(_SC("ActionGettingUp"), EVT_ACTIONGETTINGUP)
.Const(_SC("ActionJumpVehicle"), EVT_ACTIONJUMPVEHICLE)
.Const(_SC("ActionDriving"), EVT_ACTIONDRIVING)
.Const(_SC("ActionDying"), EVT_ACTIONDYING)
.Const(_SC("ActionWasted"), EVT_ACTIONWASTED)
.Const(_SC("ActionEmbarking"), EVT_ACTIONEMBARKING)
.Const(_SC("ActionDisembarking"), EVT_ACTIONDISEMBARKING)
.Const(_SC("VehicleRespawn"), EVT_VEHICLERESPAWN)
.Const(_SC("VehicleExplode"), EVT_VEHICLEEXPLODE)
.Const(_SC("VehicleHealth"), EVT_VEHICLEHEALTH)
.Const(_SC("VehicleMove"), EVT_VEHICLEMOVE)
.Const(_SC("PickupRespawn"), EVT_PICKUPRESPAWN)
.Const(_SC("KeybindKeyPress"), EVT_KEYBINDKEYPRESS)
.Const(_SC("KeybindKeyRelease"), EVT_KEYBINDKEYRELEASE)
.Const(_SC("VehicleEmbarking"), EVT_VEHICLEEMBARKING)
.Const(_SC("VehicleEmbarked"), EVT_VEHICLEEMBARKED)
.Const(_SC("VehicleDisembark"), EVT_VEHICLEDISEMBARK)
.Const(_SC("PickupClaimed"), EVT_PICKUPCLAIMED)
.Const(_SC("PickupCollected"), EVT_PICKUPCOLLECTED)
.Const(_SC("ObjectShot"), EVT_OBJECTSHOT)
.Const(_SC("ObjectBump"), EVT_OBJECTBUMP)
.Const(_SC("CheckpointEntered"), EVT_CHECKPOINTENTERED)
.Const(_SC("CheckpointExited"), EVT_CHECKPOINTEXITED)
.Const(_SC("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("ScriptReload"), EVT_SCRIPTRELOAD)
.Const(_SC("ScriptUnload"), EVT_SCRIPTUNLOAD)
.Const(_SC("Max"), EVT_MAX)
);
ConstTable(vm).Enum(_SC("SqCreate"), Enumeration(vm)
.Const(_SC("Default"), SQMOD_CREATE_DEFAULT)
.Const(_SC("Manual"), SQMOD_CREATE_MANUAL)
.Const(_SC("Pool"), SQMOD_CREATE_POOL)
.Const(_SC("Automatic"), SQMOD_CREATE_AUTOMATIC)
.Const(_SC("Overwrite"), SQMOD_CREATE_OVERWRITE)
.Const(_SC("Resurect"), SQMOD_CREATE_RESURECT)
);
ConstTable(vm).Enum(_SC("SqDestroy"), Enumeration(vm)
.Const(_SC("Default"), SQMOD_DESTROY_DEFAULT)
.Const(_SC("Manual"), SQMOD_DESTROY_MANUAL)
.Const(_SC("Pool"), SQMOD_DESTROY_POOL)
.Const(_SC("Automatic"), SQMOD_DESTROY_AUTOMATIC)
.Const(_SC("Overwrite"), SQMOD_DESTROY_OVERWRITE)
.Const(_SC("Cleanup"), SQMOD_DESTROY_CLEANUP)
);
ConstTable(vm).Enum(_SC("SqPoopUpdate"), 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)
);
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)
);
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)
);
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)
);
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)
);
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)
);
ConstTable(vm).Enum(_SC("SqPlayerAction"), Enumeration(vm)
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
.Const(_SC("None"), SQMOD_PLAYER_ACTION_NONE)
.Const(_SC("Normal"), SQMOD_PLAYER_ACTION_NORMAL)
.Const(_SC("Aiming"), SQMOD_PLAYER_ACTION_AIMING)
.Const(_SC("Shooting"), SQMOD_PLAYER_ACTION_SHOOTING)
.Const(_SC("Jumping"), SQMOD_PLAYER_ACTION_JUMPING)
.Const(_SC("LyingOnGround"), SQMOD_PLAYER_ACTION_LYING_ON_GROUND)
.Const(_SC("GettingUp"), SQMOD_PLAYER_ACTION_GETTING_UP)
.Const(_SC("JumpingFromVehicle"), SQMOD_PLAYER_ACTION_JUMPING_FROM_VEHICLE)
.Const(_SC("Driving"), SQMOD_PLAYER_ACTION_DRIVING)
.Const(_SC("Dying"), SQMOD_PLAYER_ACTION_DYING)
.Const(_SC("Wasted"), SQMOD_PLAYER_ACTION_WASTED)
.Const(_SC("EnteringVehicle"), SQMOD_PLAYER_ACTION_ENTERING_VEHICLE)
.Const(_SC("ExitingVehicle"), SQMOD_PLAYER_ACTION_EXITING_VEHICLE)
.Const(_SC("Max"), SQMOD_PLAYER_ACTION_MAX)
);
ConstTable(vm).Enum(_SC("SqWeather"), Enumeration(vm)
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
.Const(_SC("MostlyClear"), SQMOD_WEATHER_MOSTLYCLEAR)
.Const(_SC("Overcast"), SQMOD_WEATHER_OVERCAST)
.Const(_SC("ThunderStorm"), SQMOD_WEATHER_THUNDERSTORM)
.Const(_SC("Storm"), SQMOD_WEATHER_STORM)
.Const(_SC("Stormy"), SQMOD_WEATHER_STORMY)
.Const(_SC("Foggy"), SQMOD_WEATHER_FOGGY)
.Const(_SC("Fog"), SQMOD_WEATHER_FOG)
.Const(_SC("Clear"), SQMOD_WEATHER_CLEAR)
.Const(_SC("Sunny"), SQMOD_WEATHER_SUNNY)
.Const(_SC("Rain"), SQMOD_WEATHER_RAIN)
.Const(_SC("Rainy"), SQMOD_WEATHER_RAINY)
.Const(_SC("DarkCloudy"), SQMOD_WEATHER_DARKCLOUDY)
.Const(_SC("LightCloudy"), SQMOD_WEATHER_LIGHTCLOUDY)
.Const(_SC("OvercastCloudy"), SQMOD_WEATHER_OVERCASTCLOUDY)
.Const(_SC("BlackClouds"), SQMOD_WEATHER_BLACKCLOUDS)
.Const(_SC("Max"), SQMOD_WEATHER_MAX)
);
ConstTable(vm).Enum(_SC("SqWep"), Enumeration(vm)
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
.Const(_SC("Unarmed"), SQMOD_WEAPON_UNARMED)
.Const(_SC("BrassKnuckles"), SQMOD_WEAPON_BRASSKNUCKLES)
.Const(_SC("Screwdriver"), SQMOD_WEAPON_SCREWDRIVER)
.Const(_SC("GolfClub"), SQMOD_WEAPON_GOLFCLUB)
.Const(_SC("Nightstick"), SQMOD_WEAPON_NIGHTSTICK)
.Const(_SC("Knife"), SQMOD_WEAPON_KNIFE)
.Const(_SC("BaseballBat"), SQMOD_WEAPON_BASEBALLBAT)
.Const(_SC("Hammer"), SQMOD_WEAPON_HAMMER)
.Const(_SC("MeatCleaver"), SQMOD_WEAPON_MEATCLEAVER)
.Const(_SC("Machete"), SQMOD_WEAPON_MACHETE)
.Const(_SC("Katana"), SQMOD_WEAPON_KATANA)
.Const(_SC("Chainsaw"), SQMOD_WEAPON_CHAINSAW)
.Const(_SC("Grenade"), SQMOD_WEAPON_GRENADE)
.Const(_SC("Remote"), SQMOD_WEAPON_REMOTE)
.Const(_SC("Teargas"), SQMOD_WEAPON_TEARGAS)
.Const(_SC("Molotov"), SQMOD_WEAPON_MOLOTOV)
.Const(_SC("Rocket"), SQMOD_WEAPON_ROCKET)
.Const(_SC("Colt45"), SQMOD_WEAPON_COLT45)
.Const(_SC("Python"), SQMOD_WEAPON_PYTHON)
.Const(_SC("Shotgun"), SQMOD_WEAPON_SHOTGUN)
.Const(_SC("Spas12"), SQMOD_WEAPON_SPAS12)
.Const(_SC("Stubby"), SQMOD_WEAPON_STUBBY)
.Const(_SC("Tec9"), SQMOD_WEAPON_TEC9)
.Const(_SC("Uzi"), SQMOD_WEAPON_UZI)
.Const(_SC("Ingram"), SQMOD_WEAPON_INGRAM)
.Const(_SC("MP5"), SQMOD_WEAPON_MP5)
.Const(_SC("M4"), SQMOD_WEAPON_M4)
.Const(_SC("Ruger"), SQMOD_WEAPON_RUGER)
.Const(_SC("Sniper"), SQMOD_WEAPON_SNIPER)
.Const(_SC("Laserscope"), SQMOD_WEAPON_LASERSCOPE)
.Const(_SC("RocketLauncher"), SQMOD_WEAPON_ROCKETLAUNCHER)
.Const(_SC("FlameThrower"), SQMOD_WEAPON_FLAMETHROWER)
.Const(_SC("M60"), SQMOD_WEAPON_M60)
.Const(_SC("Minigun"), SQMOD_WEAPON_MINIGUN)
.Const(_SC("Bomb"), SQMOD_WEAPON_BOMB)
.Const(_SC("HeliCannon"), SQMOD_WEAPON_HELICANNON)
.Const(_SC("Camera"), SQMOD_WEAPON_CAMERA)
.Const(_SC("Vehicle"), SQMOD_WEAPON_VEHICLE)
.Const(_SC("Explosion1"), SQMOD_WEAPON_EXPLOSION1)
.Const(_SC("Driveby"), SQMOD_WEAPON_DRIVEBY)
.Const(_SC("Drowned"), SQMOD_WEAPON_DROWNED)
.Const(_SC("Fall"), SQMOD_WEAPON_FALL)
.Const(_SC("Explosion2"), SQMOD_WEAPON_EXPLOSION2)
.Const(_SC("Suicide"), SQMOD_WEAPON_SUICIDE)
.Const(_SC("Launcher"), SQMOD_WEAPON_ROCKETLAUNCHER)
.Const(_SC("Max"), SQMOD_WEAPON_MAX)
);
ConstTable(vm).Enum(_SC("SqVeh"), Enumeration(vm)
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
.Const(_SC("Landstalker"), SQMOD_VEHICLE_LANDSTALKER)
.Const(_SC("Idaho"), SQMOD_VEHICLE_IDAHO)
.Const(_SC("Stinger"), SQMOD_VEHICLE_STINGER)
.Const(_SC("Linerunner"), SQMOD_VEHICLE_LINERUNNER)
.Const(_SC("Perennial"), SQMOD_VEHICLE_PERENNIAL)
.Const(_SC("Sentinel"), SQMOD_VEHICLE_SENTINEL)
.Const(_SC("Rio"), SQMOD_VEHICLE_RIO)
.Const(_SC("Firetruck"), SQMOD_VEHICLE_FIRETRUCK)
.Const(_SC("Trashmaster"), SQMOD_VEHICLE_TRASHMASTER)
.Const(_SC("Stretch"), SQMOD_VEHICLE_STRETCH)
.Const(_SC("Manana"), SQMOD_VEHICLE_MANANA)
.Const(_SC("Infernus"), SQMOD_VEHICLE_INFERNUS)
.Const(_SC("Voodoo"), SQMOD_VEHICLE_VOODOO)
.Const(_SC("Pony"), SQMOD_VEHICLE_PONY)
.Const(_SC("Mule"), SQMOD_VEHICLE_MULE)
.Const(_SC("Cheetah"), SQMOD_VEHICLE_CHEETAH)
.Const(_SC("Ambulance"), SQMOD_VEHICLE_AMBULANCE)
.Const(_SC("Fbiwashington"), SQMOD_VEHICLE_FBIWASHINGTON)
.Const(_SC("Moonbeam"), SQMOD_VEHICLE_MOONBEAM)
.Const(_SC("Esperanto"), SQMOD_VEHICLE_ESPERANTO)
.Const(_SC("Taxi"), SQMOD_VEHICLE_TAXI)
.Const(_SC("Washington"), SQMOD_VEHICLE_WASHINGTON)
.Const(_SC("Bobcat"), SQMOD_VEHICLE_BOBCAT)
.Const(_SC("Mrwhoopee"), SQMOD_VEHICLE_MRWHOOPEE)
.Const(_SC("Bfinjection"), SQMOD_VEHICLE_BFINJECTION)
.Const(_SC("Hunter"), SQMOD_VEHICLE_HUNTER)
.Const(_SC("Police"), SQMOD_VEHICLE_POLICE)
.Const(_SC("Enforcer"), SQMOD_VEHICLE_ENFORCER)
.Const(_SC("Securicar"), SQMOD_VEHICLE_SECURICAR)
.Const(_SC("Banshee"), SQMOD_VEHICLE_BANSHEE)
.Const(_SC("Predator"), SQMOD_VEHICLE_PREDATOR)
.Const(_SC("Bus"), SQMOD_VEHICLE_BUS)
.Const(_SC("Rhino"), SQMOD_VEHICLE_RHINO)
.Const(_SC("Barracksol"), SQMOD_VEHICLE_BARRACKSOL)
.Const(_SC("Barracks"), SQMOD_VEHICLE_BARRACKS)
.Const(_SC("Cubanhermes"), SQMOD_VEHICLE_CUBANHERMES)
.Const(_SC("Helicopter"), SQMOD_VEHICLE_HELICOPTER)
.Const(_SC("Angel"), SQMOD_VEHICLE_ANGEL)
.Const(_SC("Coach"), SQMOD_VEHICLE_COACH)
.Const(_SC("Cabbie"), SQMOD_VEHICLE_CABBIE)
.Const(_SC("Stallion"), SQMOD_VEHICLE_STALLION)
.Const(_SC("Rumpo"), SQMOD_VEHICLE_RUMPO)
.Const(_SC("Rcbandit"), SQMOD_VEHICLE_RCBANDIT)
.Const(_SC("Hearse"), SQMOD_VEHICLE_HEARSE)
.Const(_SC("Packer"), SQMOD_VEHICLE_PACKER)
.Const(_SC("Sentinelxs"), SQMOD_VEHICLE_SENTINELXS)
.Const(_SC("Admiral"), SQMOD_VEHICLE_ADMIRAL)
.Const(_SC("Squalo"), SQMOD_VEHICLE_SQUALO)
.Const(_SC("Seasparrow"), SQMOD_VEHICLE_SEASPARROW)
.Const(_SC("Pizzaboy"), SQMOD_VEHICLE_PIZZABOY)
.Const(_SC("Gangburrito"), SQMOD_VEHICLE_GANGBURRITO)
.Const(_SC("Airtrain"), SQMOD_VEHICLE_AIRTRAIN)
.Const(_SC("Deaddodo"), SQMOD_VEHICLE_DEADDODO)
.Const(_SC("Speeder"), SQMOD_VEHICLE_SPEEDER)
.Const(_SC("Reefer"), SQMOD_VEHICLE_REEFER)
.Const(_SC("Tropic"), SQMOD_VEHICLE_TROPIC)
.Const(_SC("Flatbed"), SQMOD_VEHICLE_FLATBED)
.Const(_SC("Yankee"), SQMOD_VEHICLE_YANKEE)
.Const(_SC("Caddy"), SQMOD_VEHICLE_CADDY)
.Const(_SC("Zebra"), SQMOD_VEHICLE_ZEBRA)
.Const(_SC("Zebracab"), SQMOD_VEHICLE_ZEBRACAB)
.Const(_SC("Topfun"), SQMOD_VEHICLE_TOPFUN)
.Const(_SC("Skimmer"), SQMOD_VEHICLE_SKIMMER)
.Const(_SC("Pcj600"), SQMOD_VEHICLE_PCJ600)
.Const(_SC("Pcj"), SQMOD_VEHICLE_PCJ)
.Const(_SC("Faggio"), SQMOD_VEHICLE_FAGGIO)
.Const(_SC("Freeway"), SQMOD_VEHICLE_FREEWAY)
.Const(_SC("Rcbaron"), SQMOD_VEHICLE_RCBARON)
.Const(_SC("Rcraider"), SQMOD_VEHICLE_RCRAIDER)
.Const(_SC("Glendale"), SQMOD_VEHICLE_GLENDALE)
.Const(_SC("Oceanic"), SQMOD_VEHICLE_OCEANIC)
.Const(_SC("Sanchez"), SQMOD_VEHICLE_SANCHEZ)
.Const(_SC("Sparrow"), SQMOD_VEHICLE_SPARROW)
.Const(_SC("Patriot"), SQMOD_VEHICLE_PATRIOT)
.Const(_SC("Lovefist"), SQMOD_VEHICLE_LOVEFIST)
.Const(_SC("Coastguard"), SQMOD_VEHICLE_COASTGUARD)
.Const(_SC("Dinghy"), SQMOD_VEHICLE_DINGHY)
.Const(_SC("Hermes"), SQMOD_VEHICLE_HERMES)
.Const(_SC("Sabre"), SQMOD_VEHICLE_SABRE)
.Const(_SC("Sabreturbo"), SQMOD_VEHICLE_SABRETURBO)
.Const(_SC("Phoenix"), SQMOD_VEHICLE_PHOENIX)
.Const(_SC("Walton"), SQMOD_VEHICLE_WALTON)
.Const(_SC("Regina"), SQMOD_VEHICLE_REGINA)
.Const(_SC("Comet"), SQMOD_VEHICLE_COMET)
.Const(_SC("Deluxo"), SQMOD_VEHICLE_DELUXO)
.Const(_SC("Burrito"), SQMOD_VEHICLE_BURRITO)
.Const(_SC("Spandex"), SQMOD_VEHICLE_SPANDEX)
.Const(_SC("Spandexpress"), SQMOD_VEHICLE_SPANDEXPRESS)
.Const(_SC("Marquis"), SQMOD_VEHICLE_MARQUIS)
.Const(_SC("Baggage"), SQMOD_VEHICLE_BAGGAGE)
.Const(_SC("Baggagehandler"), SQMOD_VEHICLE_BAGGAGEHANDLER)
.Const(_SC("Kaufman"), SQMOD_VEHICLE_KAUFMAN)
.Const(_SC("Kaufmancab"), SQMOD_VEHICLE_KAUFMANCAB)
.Const(_SC("Maverick"), SQMOD_VEHICLE_MAVERICK)
.Const(_SC("Vcnmaverick"), SQMOD_VEHICLE_VCNMAVERICK)
.Const(_SC("Rancher"), SQMOD_VEHICLE_RANCHER)
.Const(_SC("Fbirancher"), SQMOD_VEHICLE_FBIRANCHER)
.Const(_SC("Virgo"), SQMOD_VEHICLE_VIRGO)
.Const(_SC("Greenwood"), SQMOD_VEHICLE_GREENWOOD)
.Const(_SC("Cubanjetmax"), SQMOD_VEHICLE_CUBANJETMAX)
.Const(_SC("Hotring1"), SQMOD_VEHICLE_HOTRING1)
.Const(_SC("Hotringracer1"), SQMOD_VEHICLE_HOTRINGRACER1)
.Const(_SC("Sandking"), SQMOD_VEHICLE_SANDKING)
.Const(_SC("Blista"), SQMOD_VEHICLE_BLISTA)
.Const(_SC("Blistac"), SQMOD_VEHICLE_BLISTAC)
.Const(_SC("Blistacompact"), SQMOD_VEHICLE_BLISTACOMPACT)
.Const(_SC("Compact"), SQMOD_VEHICLE_COMPACT)
.Const(_SC("Policemav"), SQMOD_VEHICLE_POLICEMAV)
.Const(_SC("Policemaverick"), SQMOD_VEHICLE_POLICEMAVERICK)
.Const(_SC("Boxville"), SQMOD_VEHICLE_BOXVILLE)
.Const(_SC("Benson"), SQMOD_VEHICLE_BENSON)
.Const(_SC("Mesa"), SQMOD_VEHICLE_MESA)
.Const(_SC("Mesagrande"), SQMOD_VEHICLE_MESAGRANDE)
.Const(_SC("Rcgoblin"), SQMOD_VEHICLE_RCGOBLIN)
.Const(_SC("Hotring2"), SQMOD_VEHICLE_HOTRING2)
.Const(_SC("Hotringracer2"), SQMOD_VEHICLE_HOTRINGRACER2)
.Const(_SC("Hotring3"), SQMOD_VEHICLE_HOTRING3)
.Const(_SC("Hotringracer3"), SQMOD_VEHICLE_HOTRINGRACER3)
.Const(_SC("Bloodring1"), SQMOD_VEHICLE_BLOODRING1)
.Const(_SC("Bloodringbanger1"), SQMOD_VEHICLE_BLOODRINGBANGER1)
.Const(_SC("Bloodring2"), SQMOD_VEHICLE_BLOODRING2)
.Const(_SC("Bloodringbanger2"), SQMOD_VEHICLE_BLOODRINGBANGER2)
.Const(_SC("Vicechee"), SQMOD_VEHICLE_VICECHEE)
.Const(_SC("PoliceCheetah"), SQMOD_VEHICLE_POLICECHEETAH)
.Const(_SC("FBICheetah"), SQMOD_VEHICLE_FBICHEETAH)
.Const(_SC("Cheetah2"), SQMOD_VEHICLE_CHEETAH2)
.Const(_SC("Max"), SQMOD_VEHICLE_MAX)
);
ConstTable(vm).Enum(_SC("SqSkin"), Enumeration(vm)
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
.Const(_SC("Tommy_vercetti"), SQMOD_SKIN_TOMMY_VERCETTI)
.Const(_SC("Cop"), SQMOD_SKIN_COP)
.Const(_SC("Swat"), SQMOD_SKIN_SWAT)
.Const(_SC("Fbi"), SQMOD_SKIN_FBI)
.Const(_SC("Army"), SQMOD_SKIN_ARMY)
.Const(_SC("Paramedic"), SQMOD_SKIN_PARAMEDIC)
.Const(_SC("Fireman"), SQMOD_SKIN_FIREMAN)
.Const(_SC("Golf_guy_a"), SQMOD_SKIN_GOLF_GUY_A)
.Const(_SC("Bum_lady_a"), SQMOD_SKIN_BUM_LADY_A)
.Const(_SC("Bum_lady_b"), SQMOD_SKIN_BUM_LADY_B)
.Const(_SC("Punk_a"), SQMOD_SKIN_PUNK_A)
.Const(_SC("Lawyer"), SQMOD_SKIN_LAWYER)
.Const(_SC("Spanish_lady_a"), SQMOD_SKIN_SPANISH_LADY_A)
.Const(_SC("Spanish_lady_b"), SQMOD_SKIN_SPANISH_LADY_B)
.Const(_SC("Cool_guy_a"), SQMOD_SKIN_COOL_GUY_A)
.Const(_SC("Arabic_guy"), SQMOD_SKIN_ARABIC_GUY)
.Const(_SC("Beach_lady_a"), SQMOD_SKIN_BEACH_LADY_A)
.Const(_SC("Beach_lady_b"), SQMOD_SKIN_BEACH_LADY_B)
.Const(_SC("Beach_guy_a"), SQMOD_SKIN_BEACH_GUY_A)
.Const(_SC("Beach_guy_b"), SQMOD_SKIN_BEACH_GUY_B)
.Const(_SC("Office_lady_a"), SQMOD_SKIN_OFFICE_LADY_A)
.Const(_SC("Waitress_a"), SQMOD_SKIN_WAITRESS_A)
.Const(_SC("Food_lady"), SQMOD_SKIN_FOOD_LADY)
.Const(_SC("Prostitute_a"), SQMOD_SKIN_PROSTITUTE_A)
.Const(_SC("Bum_lady_c"), SQMOD_SKIN_BUM_LADY_C)
.Const(_SC("Bum_guy_a"), SQMOD_SKIN_BUM_GUY_A)
.Const(_SC("Garbageman_a"), SQMOD_SKIN_GARBAGEMAN_A)
.Const(_SC("Taxi_driver_a"), SQMOD_SKIN_TAXI_DRIVER_A)
.Const(_SC("Hatian_a"), SQMOD_SKIN_HATIAN_A)
.Const(_SC("Criminal_a"), SQMOD_SKIN_CRIMINAL_A)
.Const(_SC("Hood_lady"), SQMOD_SKIN_HOOD_LADY)
.Const(_SC("Granny_a"), SQMOD_SKIN_GRANNY_A)
.Const(_SC("Business_man_a"), SQMOD_SKIN_BUSINESS_MAN_A)
.Const(_SC("Church_guy"), SQMOD_SKIN_CHURCH_GUY)
.Const(_SC("Club_lady"), SQMOD_SKIN_CLUB_LADY)
.Const(_SC("Church_lady"), SQMOD_SKIN_CHURCH_LADY)
.Const(_SC("Pimp"), SQMOD_SKIN_PIMP)
.Const(_SC("Beach_lady_c"), SQMOD_SKIN_BEACH_LADY_C)
.Const(_SC("Beach_guy_c"), SQMOD_SKIN_BEACH_GUY_C)
.Const(_SC("Beach_lady_d"), SQMOD_SKIN_BEACH_LADY_D)
.Const(_SC("Beach_guy_d"), SQMOD_SKIN_BEACH_GUY_D)
.Const(_SC("Business_man_b"), SQMOD_SKIN_BUSINESS_MAN_B)
.Const(_SC("Prostitute_b"), SQMOD_SKIN_PROSTITUTE_B)
.Const(_SC("Bum_lady_d"), SQMOD_SKIN_BUM_LADY_D)
.Const(_SC("Bum_guy_b"), SQMOD_SKIN_BUM_GUY_B)
.Const(_SC("Hatian_b"), SQMOD_SKIN_HATIAN_B)
.Const(_SC("Construction_worker_a"), SQMOD_SKIN_CONSTRUCTION_WORKER_A)
.Const(_SC("Punk_b"), SQMOD_SKIN_PUNK_B)
.Const(_SC("Prostitute_c"), SQMOD_SKIN_PROSTITUTE_C)
.Const(_SC("Granny_b"), SQMOD_SKIN_GRANNY_B)
.Const(_SC("Punk_c"), SQMOD_SKIN_PUNK_C)
.Const(_SC("Business_man_c"), SQMOD_SKIN_BUSINESS_MAN_C)
.Const(_SC("Spanish_lady_c"), SQMOD_SKIN_SPANISH_LADY_C)
.Const(_SC("Spanish_lady_d"), SQMOD_SKIN_SPANISH_LADY_D)
.Const(_SC("Cool_guy_b"), SQMOD_SKIN_COOL_GUY_B)
.Const(_SC("Business_man_d"), SQMOD_SKIN_BUSINESS_MAN_D)
.Const(_SC("Beach_lady_e"), SQMOD_SKIN_BEACH_LADY_E)
.Const(_SC("Beach_guy_e"), SQMOD_SKIN_BEACH_GUY_E)
.Const(_SC("Beach_lady_f"), SQMOD_SKIN_BEACH_LADY_F)
.Const(_SC("Beach_guy_f"), SQMOD_SKIN_BEACH_GUY_F)
.Const(_SC("Construction_worker_b"), SQMOD_SKIN_CONSTRUCTION_WORKER_B)
.Const(_SC("Golf_guy_b"), SQMOD_SKIN_GOLF_GUY_B)
.Const(_SC("Golf_lady"), SQMOD_SKIN_GOLF_LADY)
.Const(_SC("Golf_guy_c"), SQMOD_SKIN_GOLF_GUY_C)
.Const(_SC("Beach_lady_g"), SQMOD_SKIN_BEACH_LADY_G)
.Const(_SC("Beach_guy_g"), SQMOD_SKIN_BEACH_GUY_G)
.Const(_SC("Office_lady_b"), SQMOD_SKIN_OFFICE_LADY_B)
.Const(_SC("Business_man_e"), SQMOD_SKIN_BUSINESS_MAN_E)
.Const(_SC("Business_man_f"), SQMOD_SKIN_BUSINESS_MAN_F)
.Const(_SC("Prostitute_d"), SQMOD_SKIN_PROSTITUTE_D)
.Const(_SC("Bum_lady_e"), SQMOD_SKIN_BUM_LADY_E)
.Const(_SC("Bum_guy_c"), SQMOD_SKIN_BUM_GUY_C)
.Const(_SC("Spanish_guy"), SQMOD_SKIN_SPANISH_GUY)
.Const(_SC("Taxi_driver_b"), SQMOD_SKIN_TAXI_DRIVER_B)
.Const(_SC("Gym_lady"), SQMOD_SKIN_GYM_LADY)
.Const(_SC("Gym_guy"), SQMOD_SKIN_GYM_GUY)
.Const(_SC("Skate_lady"), SQMOD_SKIN_SKATE_LADY)
.Const(_SC("Skate_guy"), SQMOD_SKIN_SKATE_GUY)
.Const(_SC("Shopper_a"), SQMOD_SKIN_SHOPPER_A)
.Const(_SC("Shopper_b"), SQMOD_SKIN_SHOPPER_B)
.Const(_SC("Tourist_a"), SQMOD_SKIN_TOURIST_A)
.Const(_SC("Tourist_b"), SQMOD_SKIN_TOURIST_B)
.Const(_SC("Cuban_a"), SQMOD_SKIN_CUBAN_A)
.Const(_SC("Cuban_b"), SQMOD_SKIN_CUBAN_B)
.Const(_SC("Hatian_c"), SQMOD_SKIN_HATIAN_C)
.Const(_SC("Hatian_d"), SQMOD_SKIN_HATIAN_D)
.Const(_SC("Shark_a"), SQMOD_SKIN_SHARK_A)
.Const(_SC("Shark_b"), SQMOD_SKIN_SHARK_B)
.Const(_SC("Diaz_guy_a"), SQMOD_SKIN_DIAZ_GUY_A)
.Const(_SC("Diaz_guy_b"), SQMOD_SKIN_DIAZ_GUY_B)
.Const(_SC("Dbp_security_a"), SQMOD_SKIN_DBP_SECURITY_A)
.Const(_SC("Dbp_security_b"), SQMOD_SKIN_DBP_SECURITY_B)
.Const(_SC("Biker_a"), SQMOD_SKIN_BIKER_A)
.Const(_SC("Biker_b"), SQMOD_SKIN_BIKER_B)
.Const(_SC("Vercetti_guy_a"), SQMOD_SKIN_VERCETTI_GUY_A)
.Const(_SC("Vercetti_guy_b"), SQMOD_SKIN_VERCETTI_GUY_B)
.Const(_SC("Undercover_cop_a"), SQMOD_SKIN_UNDERCOVER_COP_A)
.Const(_SC("Undercover_cop_b"), SQMOD_SKIN_UNDERCOVER_COP_B)
.Const(_SC("Undercover_cop_c"), SQMOD_SKIN_UNDERCOVER_COP_C)
.Const(_SC("Undercover_cop_d"), SQMOD_SKIN_UNDERCOVER_COP_D)
.Const(_SC("Undercover_cop_e"), SQMOD_SKIN_UNDERCOVER_COP_E)
.Const(_SC("Undercover_cop_f"), SQMOD_SKIN_UNDERCOVER_COP_F)
.Const(_SC("Rich_guy"), SQMOD_SKIN_RICH_GUY)
.Const(_SC("Cool_guy_c"), SQMOD_SKIN_COOL_GUY_C)
.Const(_SC("Prostitute_e"), SQMOD_SKIN_PROSTITUTE_E)
.Const(_SC("Prostitute_f"), SQMOD_SKIN_PROSTITUTE_F)
.Const(_SC("Love_fist_a"), SQMOD_SKIN_LOVE_FIST_A)
.Const(_SC("Ken_rosenburg"), SQMOD_SKIN_KEN_ROSENBURG)
.Const(_SC("Candy_suxx"), SQMOD_SKIN_CANDY_SUXX)
.Const(_SC("Hilary"), SQMOD_SKIN_HILARY)
.Const(_SC("Love_fist_b"), SQMOD_SKIN_LOVE_FIST_B)
.Const(_SC("Phil"), SQMOD_SKIN_PHIL)
.Const(_SC("Rockstar_guy"), SQMOD_SKIN_ROCKSTAR_GUY)
.Const(_SC("Sonny"), SQMOD_SKIN_SONNY)
.Const(_SC("Lance_a"), SQMOD_SKIN_LANCE_A)
.Const(_SC("Mercades_a"), SQMOD_SKIN_MERCADES_A)
.Const(_SC("Love_fist_c"), SQMOD_SKIN_LOVE_FIST_C)
.Const(_SC("Alex_srub"), SQMOD_SKIN_ALEX_SRUB)
.Const(_SC("Lance_cop"), SQMOD_SKIN_LANCE_COP)
.Const(_SC("Lance_b"), SQMOD_SKIN_LANCE_B)
.Const(_SC("Cortez"), SQMOD_SKIN_CORTEZ)
.Const(_SC("Love_fist_d"), SQMOD_SKIN_LOVE_FIST_D)
.Const(_SC("Columbian_guy_a"), SQMOD_SKIN_COLUMBIAN_GUY_A)
.Const(_SC("Hilary_robber"), SQMOD_SKIN_HILARY_ROBBER)
.Const(_SC("Mercades_b"), SQMOD_SKIN_MERCADES_B)
.Const(_SC("Cam"), SQMOD_SKIN_CAM)
.Const(_SC("Cam_robber"), SQMOD_SKIN_CAM_ROBBER)
.Const(_SC("Phil_one_arm"), SQMOD_SKIN_PHIL_ONE_ARM)
.Const(_SC("Phil_robber"), SQMOD_SKIN_PHIL_ROBBER)
.Const(_SC("Cool_guy_d"), SQMOD_SKIN_COOL_GUY_D)
.Const(_SC("Pizzaman"), SQMOD_SKIN_PIZZAMAN)
.Const(_SC("Taxi_driver_c"), SQMOD_SKIN_TAXI_DRIVER_C)
.Const(_SC("Taxi_driver_d"), SQMOD_SKIN_TAXI_DRIVER_D)
.Const(_SC("Sailor_a"), SQMOD_SKIN_SAILOR_A)
.Const(_SC("Sailor_b"), SQMOD_SKIN_SAILOR_B)
.Const(_SC("Sailor_c"), SQMOD_SKIN_SAILOR_C)
.Const(_SC("Chef"), SQMOD_SKIN_CHEF)
.Const(_SC("Criminal_b"), SQMOD_SKIN_CRIMINAL_B)
.Const(_SC("French_guy"), SQMOD_SKIN_FRENCH_GUY)
.Const(_SC("Garbageman_b"), SQMOD_SKIN_GARBAGEMAN_B)
.Const(_SC("Hatian_e"), SQMOD_SKIN_HATIAN_E)
.Const(_SC("Waitress_b"), SQMOD_SKIN_WAITRESS_B)
.Const(_SC("Sonny_guy_a"), SQMOD_SKIN_SONNY_GUY_A)
.Const(_SC("Sonny_guy_b"), SQMOD_SKIN_SONNY_GUY_B)
.Const(_SC("Sonny_guy_c"), SQMOD_SKIN_SONNY_GUY_C)
.Const(_SC("Columbian_guy_b"), SQMOD_SKIN_COLUMBIAN_GUY_B)
.Const(_SC("Thug_a"), SQMOD_SKIN_THUG_A)
.Const(_SC("Beach_guy_h"), SQMOD_SKIN_BEACH_GUY_H)
.Const(_SC("Garbageman_c"), SQMOD_SKIN_GARBAGEMAN_C)
.Const(_SC("Garbageman_d"), SQMOD_SKIN_GARBAGEMAN_D)
.Const(_SC("Garbageman_e"), SQMOD_SKIN_GARBAGEMAN_E)
.Const(_SC("Tranny"), SQMOD_SKIN_TRANNY)
.Const(_SC("Thug_b"), SQMOD_SKIN_THUG_B)
.Const(_SC("Spandex_guy_a"), SQMOD_SKIN_SPANDEX_GUY_A)
.Const(_SC("Spandex_guy_b"), SQMOD_SKIN_SPANDEX_GUY_B)
.Const(_SC("Stripper_a"), SQMOD_SKIN_STRIPPER_A)
.Const(_SC("Stripper_b"), SQMOD_SKIN_STRIPPER_B)
.Const(_SC("Stripper_c"), SQMOD_SKIN_STRIPPER_C)
.Const(_SC("Store_clerk"), SQMOD_SKIN_STORE_CLERK)
.Const(_SC("Max"), SQMOD_SKIN_MAX)
);
ConstTable(vm).Enum(_SC("SqKeycode"), Enumeration(vm)
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
.Const(_SC("Abnt_c1"), SQMOD_KEYCODE_ABNT_C1)
.Const(_SC("Abnt_c2"), SQMOD_KEYCODE_ABNT_C2)
.Const(_SC("Add"), SQMOD_KEYCODE_ADD)
.Const(_SC("Attn"), SQMOD_KEYCODE_ATTN)
.Const(_SC("Back"), SQMOD_KEYCODE_BACK)
.Const(_SC("Cancel"), SQMOD_KEYCODE_CANCEL)
.Const(_SC("Clear"), SQMOD_KEYCODE_CLEAR)
.Const(_SC("Crsel"), SQMOD_KEYCODE_CRSEL)
.Const(_SC("Decimal"), SQMOD_KEYCODE_DECIMAL)
.Const(_SC("Divide"), SQMOD_KEYCODE_DIVIDE)
.Const(_SC("Ereof"), SQMOD_KEYCODE_EREOF)
.Const(_SC("Escape"), SQMOD_KEYCODE_ESCAPE)
.Const(_SC("Execute"), SQMOD_KEYCODE_EXECUTE)
.Const(_SC("Exsel"), SQMOD_KEYCODE_EXSEL)
.Const(_SC("Ico_clear"), SQMOD_KEYCODE_ICO_CLEAR)
.Const(_SC("Ico_help"), SQMOD_KEYCODE_ICO_HELP)
.Const(_SC("Key_0"), SQMOD_KEYCODE_KEY_0)
.Const(_SC("Key_1"), SQMOD_KEYCODE_KEY_1)
.Const(_SC("Key_2"), SQMOD_KEYCODE_KEY_2)
.Const(_SC("Key_3"), SQMOD_KEYCODE_KEY_3)
.Const(_SC("Key_4"), SQMOD_KEYCODE_KEY_4)
.Const(_SC("Key_5"), SQMOD_KEYCODE_KEY_5)
.Const(_SC("Key_6"), SQMOD_KEYCODE_KEY_6)
.Const(_SC("Key_7"), SQMOD_KEYCODE_KEY_7)
.Const(_SC("Key_8"), SQMOD_KEYCODE_KEY_8)
.Const(_SC("Key_9"), SQMOD_KEYCODE_KEY_9)
.Const(_SC("Key_a"), SQMOD_KEYCODE_KEY_A)
.Const(_SC("Key_b"), SQMOD_KEYCODE_KEY_B)
.Const(_SC("Key_c"), SQMOD_KEYCODE_KEY_C)
.Const(_SC("Key_d"), SQMOD_KEYCODE_KEY_D)
.Const(_SC("Key_e"), SQMOD_KEYCODE_KEY_E)
.Const(_SC("Key_f"), SQMOD_KEYCODE_KEY_F)
.Const(_SC("Key_g"), SQMOD_KEYCODE_KEY_G)
.Const(_SC("Key_h"), SQMOD_KEYCODE_KEY_H)
.Const(_SC("Key_i"), SQMOD_KEYCODE_KEY_I)
.Const(_SC("Key_j"), SQMOD_KEYCODE_KEY_J)
.Const(_SC("Key_k"), SQMOD_KEYCODE_KEY_K)
.Const(_SC("Key_l"), SQMOD_KEYCODE_KEY_L)
.Const(_SC("Key_m"), SQMOD_KEYCODE_KEY_M)
.Const(_SC("Key_n"), SQMOD_KEYCODE_KEY_N)
.Const(_SC("Key_o"), SQMOD_KEYCODE_KEY_O)
.Const(_SC("Key_p"), SQMOD_KEYCODE_KEY_P)
.Const(_SC("Key_q"), SQMOD_KEYCODE_KEY_Q)
.Const(_SC("Key_r"), SQMOD_KEYCODE_KEY_R)
.Const(_SC("Key_s"), SQMOD_KEYCODE_KEY_S)
.Const(_SC("Key_t"), SQMOD_KEYCODE_KEY_T)
.Const(_SC("Key_u"), SQMOD_KEYCODE_KEY_U)
.Const(_SC("Key_v"), SQMOD_KEYCODE_KEY_V)
.Const(_SC("Key_w"), SQMOD_KEYCODE_KEY_W)
.Const(_SC("Key_x"), SQMOD_KEYCODE_KEY_X)
.Const(_SC("Key_y"), SQMOD_KEYCODE_KEY_Y)
.Const(_SC("Key_z"), SQMOD_KEYCODE_KEY_Z)
.Const(_SC("Multiply"), SQMOD_KEYCODE_MULTIPLY)
.Const(_SC("Noname"), SQMOD_KEYCODE_NONAME)
.Const(_SC("Numpad0"), SQMOD_KEYCODE_NUMPAD0)
.Const(_SC("Numpad1"), SQMOD_KEYCODE_NUMPAD1)
.Const(_SC("Numpad2"), SQMOD_KEYCODE_NUMPAD2)
.Const(_SC("Numpad3"), SQMOD_KEYCODE_NUMPAD3)
.Const(_SC("Numpad4"), SQMOD_KEYCODE_NUMPAD4)
.Const(_SC("Numpad5"), SQMOD_KEYCODE_NUMPAD5)
.Const(_SC("Numpad6"), SQMOD_KEYCODE_NUMPAD6)
.Const(_SC("Numpad7"), SQMOD_KEYCODE_NUMPAD7)
.Const(_SC("Numpad8"), SQMOD_KEYCODE_NUMPAD8)
.Const(_SC("Numpad9"), SQMOD_KEYCODE_NUMPAD9)
.Const(_SC("Oem_1"), SQMOD_KEYCODE_OEM_1)
.Const(_SC("Oem_102"), SQMOD_KEYCODE_OEM_102)
.Const(_SC("Oem_2"), SQMOD_KEYCODE_OEM_2)
.Const(_SC("Oem_3"), SQMOD_KEYCODE_OEM_3)
.Const(_SC("Oem_4"), SQMOD_KEYCODE_OEM_4)
.Const(_SC("Oem_5"), SQMOD_KEYCODE_OEM_5)
.Const(_SC("Oem_6"), SQMOD_KEYCODE_OEM_6)
.Const(_SC("Oem_7"), SQMOD_KEYCODE_OEM_7)
.Const(_SC("Oem_8"), SQMOD_KEYCODE_OEM_8)
.Const(_SC("Oem_attn"), SQMOD_KEYCODE_OEM_ATTN)
.Const(_SC("Oem_auto"), SQMOD_KEYCODE_OEM_AUTO)
.Const(_SC("Oem_ax"), SQMOD_KEYCODE_OEM_AX)
.Const(_SC("Oem_backtab"), SQMOD_KEYCODE_OEM_BACKTAB)
.Const(_SC("Oem_clear"), SQMOD_KEYCODE_OEM_CLEAR)
.Const(_SC("Oem_comma"), SQMOD_KEYCODE_OEM_COMMA)
.Const(_SC("Oem_copy"), SQMOD_KEYCODE_OEM_COPY)
.Const(_SC("Oem_cusel"), SQMOD_KEYCODE_OEM_CUSEL)
.Const(_SC("Oem_enlw"), SQMOD_KEYCODE_OEM_ENLW)
.Const(_SC("Oem_finish"), SQMOD_KEYCODE_OEM_FINISH)
.Const(_SC("Oem_fj_loya"), SQMOD_KEYCODE_OEM_FJ_LOYA)
.Const(_SC("Oem_fj_masshou"), SQMOD_KEYCODE_OEM_FJ_MASSHOU)
.Const(_SC("Oem_fj_roya"), SQMOD_KEYCODE_OEM_FJ_ROYA)
.Const(_SC("Oem_fj_touroku"), SQMOD_KEYCODE_OEM_FJ_TOUROKU)
.Const(_SC("Oem_jump"), SQMOD_KEYCODE_OEM_JUMP)
.Const(_SC("Oem_minus"), SQMOD_KEYCODE_OEM_MINUS)
.Const(_SC("Oem_pa1"), SQMOD_KEYCODE_OEM_PA1)
.Const(_SC("Oem_pa2"), SQMOD_KEYCODE_OEM_PA2)
.Const(_SC("Oem_pa3"), SQMOD_KEYCODE_OEM_PA3)
.Const(_SC("Oem_period"), SQMOD_KEYCODE_OEM_PERIOD)
.Const(_SC("Oem_plus"), SQMOD_KEYCODE_OEM_PLUS)
.Const(_SC("Oem_reset"), SQMOD_KEYCODE_OEM_RESET)
.Const(_SC("Oem_wsctrl"), SQMOD_KEYCODE_OEM_WSCTRL)
.Const(_SC("Pa1"), SQMOD_KEYCODE_PA1)
.Const(_SC("Packet"), SQMOD_KEYCODE_PACKET)
.Const(_SC("Play"), SQMOD_KEYCODE_PLAY)
.Const(_SC("Processkey"), SQMOD_KEYCODE_PROCESSKEY)
.Const(_SC("Return"), SQMOD_KEYCODE_RETURN)
.Const(_SC("Select"), SQMOD_KEYCODE_SELECT)
.Const(_SC("Separator"), SQMOD_KEYCODE_SEPARATOR)
.Const(_SC("Space"), SQMOD_KEYCODE_SPACE)
.Const(_SC("Subtract"), SQMOD_KEYCODE_SUBTRACT)
.Const(_SC("Tab"), SQMOD_KEYCODE_TAB)
.Const(_SC("Zoom"), SQMOD_KEYCODE_ZOOM)
.Const(_SC("Accept"), SQMOD_KEYCODE_ACCEPT)
.Const(_SC("Apps"), SQMOD_KEYCODE_APPS)
.Const(_SC("Browser_back"), SQMOD_KEYCODE_BROWSER_BACK)
.Const(_SC("Browser_favorites"), SQMOD_KEYCODE_BROWSER_FAVORITES)
.Const(_SC("Browser_forward"), SQMOD_KEYCODE_BROWSER_FORWARD)
.Const(_SC("Browser_home"), SQMOD_KEYCODE_BROWSER_HOME)
.Const(_SC("Browser_refresh"), SQMOD_KEYCODE_BROWSER_REFRESH)
.Const(_SC("Browser_search"), SQMOD_KEYCODE_BROWSER_SEARCH)
.Const(_SC("Browser_stop"), SQMOD_KEYCODE_BROWSER_STOP)
.Const(_SC("Capital"), SQMOD_KEYCODE_CAPITAL)
.Const(_SC("Convert"), SQMOD_KEYCODE_CONVERT)
.Const(_SC("Delete"), SQMOD_KEYCODE_DELETE)
.Const(_SC("Down"), SQMOD_KEYCODE_DOWN)
.Const(_SC("End"), SQMOD_KEYCODE_END)
.Const(_SC("F1"), SQMOD_KEYCODE_F1)
.Const(_SC("F10"), SQMOD_KEYCODE_F10)
.Const(_SC("F11"), SQMOD_KEYCODE_F11)
.Const(_SC("F12"), SQMOD_KEYCODE_F12)
.Const(_SC("F13"), SQMOD_KEYCODE_F13)
.Const(_SC("F14"), SQMOD_KEYCODE_F14)
.Const(_SC("F15"), SQMOD_KEYCODE_F15)
.Const(_SC("F16"), SQMOD_KEYCODE_F16)
.Const(_SC("F17"), SQMOD_KEYCODE_F17)
.Const(_SC("F18"), SQMOD_KEYCODE_F18)
.Const(_SC("F19"), SQMOD_KEYCODE_F19)
.Const(_SC("F2"), SQMOD_KEYCODE_F2)
.Const(_SC("F20"), SQMOD_KEYCODE_F20)
.Const(_SC("F21"), SQMOD_KEYCODE_F21)
.Const(_SC("F22"), SQMOD_KEYCODE_F22)
.Const(_SC("F23"), SQMOD_KEYCODE_F23)
.Const(_SC("F24"), SQMOD_KEYCODE_F24)
.Const(_SC("F3"), SQMOD_KEYCODE_F3)
.Const(_SC("F4"), SQMOD_KEYCODE_F4)
.Const(_SC("F5"), SQMOD_KEYCODE_F5)
.Const(_SC("F6"), SQMOD_KEYCODE_F6)
.Const(_SC("F7"), SQMOD_KEYCODE_F7)
.Const(_SC("F8"), SQMOD_KEYCODE_F8)
.Const(_SC("F9"), SQMOD_KEYCODE_F9)
.Const(_SC("Final"), SQMOD_KEYCODE_FINAL)
.Const(_SC("Help"), SQMOD_KEYCODE_HELP)
.Const(_SC("Home"), SQMOD_KEYCODE_HOME)
.Const(_SC("Ico_00"), SQMOD_KEYCODE_ICO_00)
.Const(_SC("Insert"), SQMOD_KEYCODE_INSERT)
.Const(_SC("Junja"), SQMOD_KEYCODE_JUNJA)
.Const(_SC("Kana"), SQMOD_KEYCODE_KANA)
.Const(_SC("Kanji"), SQMOD_KEYCODE_KANJI)
.Const(_SC("Launch_app1"), SQMOD_KEYCODE_LAUNCH_APP1)
.Const(_SC("Launch_app2"), SQMOD_KEYCODE_LAUNCH_APP2)
.Const(_SC("Launch_mail"), SQMOD_KEYCODE_LAUNCH_MAIL)
.Const(_SC("Launch_media_select"), SQMOD_KEYCODE_LAUNCH_MEDIA_SELECT)
.Const(_SC("Lbutton"), SQMOD_KEYCODE_LBUTTON)
.Const(_SC("Lcontrol"), SQMOD_KEYCODE_LCONTROL)
.Const(_SC("Left"), SQMOD_KEYCODE_LEFT)
.Const(_SC("Lmenu"), SQMOD_KEYCODE_LMENU)
.Const(_SC("Lshift"), SQMOD_KEYCODE_LSHIFT)
.Const(_SC("Lwin"), SQMOD_KEYCODE_LWIN)
.Const(_SC("Mbutton"), SQMOD_KEYCODE_MBUTTON)
.Const(_SC("Media_next_track"), SQMOD_KEYCODE_MEDIA_NEXT_TRACK)
.Const(_SC("Media_play_pause"), SQMOD_KEYCODE_MEDIA_PLAY_PAUSE)
.Const(_SC("Media_prev_track"), SQMOD_KEYCODE_MEDIA_PREV_TRACK)
.Const(_SC("Media_stop"), SQMOD_KEYCODE_MEDIA_STOP)
.Const(_SC("Modechange"), SQMOD_KEYCODE_MODECHANGE)
.Const(_SC("Next"), SQMOD_KEYCODE_NEXT)
.Const(_SC("Nonconvert"), SQMOD_KEYCODE_NONCONVERT)
.Const(_SC("Numlock"), SQMOD_KEYCODE_NUMLOCK)
.Const(_SC("Oem_fj_jisho"), SQMOD_KEYCODE_OEM_FJ_JISHO)
.Const(_SC("Pause"), SQMOD_KEYCODE_PAUSE)
.Const(_SC("Print"), SQMOD_KEYCODE_PRINT)
.Const(_SC("Prior"), SQMOD_KEYCODE_PRIOR)
.Const(_SC("Rbutton"), SQMOD_KEYCODE_RBUTTON)
.Const(_SC("Rcontrol"), SQMOD_KEYCODE_RCONTROL)
.Const(_SC("Right"), SQMOD_KEYCODE_RIGHT)
.Const(_SC("Rmenu"), SQMOD_KEYCODE_RMENU)
.Const(_SC("Rshift"), SQMOD_KEYCODE_RSHIFT)
.Const(_SC("Rwin"), SQMOD_KEYCODE_RWIN)
.Const(_SC("Scroll"), SQMOD_KEYCODE_SCROLL)
.Const(_SC("Sleep"), SQMOD_KEYCODE_SLEEP)
.Const(_SC("Snapshot"), SQMOD_KEYCODE_SNAPSHOT)
.Const(_SC("Up"), SQMOD_KEYCODE_UP)
.Const(_SC("Volume_down"), SQMOD_KEYCODE_VOLUME_DOWN)
.Const(_SC("Volume_mute"), SQMOD_KEYCODE_VOLUME_MUTE)
.Const(_SC("Volume_up"), SQMOD_KEYCODE_VOLUME_UP)
.Const(_SC("Xbutton1"), SQMOD_KEYCODE_XBUTTON1)
.Const(_SC("Xbutton2"), SQMOD_KEYCODE_XBUTTON2)
.Const(_SC("None"), SQMOD_KEYCODE_NONE)
.Const(_SC("Max"), SQMOD_KEYCODE_MAX)
);
ConstTable(vm).Enum(_SC("SqASCII"), Enumeration(vm)
.Const(_SC("Unknown"), SQMOD_UNKNOWN)
.Const(_SC("Nul"), SQMOD_ASCII_NUL)
.Const(_SC("Soh"), SQMOD_ASCII_SOH)
.Const(_SC("Stx"), SQMOD_ASCII_STX)
.Const(_SC("Etx"), SQMOD_ASCII_ETX)
.Const(_SC("Eot"), SQMOD_ASCII_EOT)
.Const(_SC("Enq"), SQMOD_ASCII_ENQ)
.Const(_SC("Ack"), SQMOD_ASCII_ACK)
.Const(_SC("Bel"), SQMOD_ASCII_BEL)
.Const(_SC("Bs"), SQMOD_ASCII_BS)
.Const(_SC("Tab"), SQMOD_ASCII_TAB)
.Const(_SC("Lf"), SQMOD_ASCII_LF)
.Const(_SC("Vt"), SQMOD_ASCII_VT)
.Const(_SC("Ff"), SQMOD_ASCII_FF)
.Const(_SC("Cr"), SQMOD_ASCII_CR)
.Const(_SC("So"), SQMOD_ASCII_SO)
.Const(_SC("Si"), SQMOD_ASCII_SI)
.Const(_SC("Dle"), SQMOD_ASCII_DLE)
.Const(_SC("Dc1"), SQMOD_ASCII_DC1)
.Const(_SC("Dc2"), SQMOD_ASCII_DC2)
.Const(_SC("Dc3"), SQMOD_ASCII_DC3)
.Const(_SC("Dc4"), SQMOD_ASCII_DC4)
.Const(_SC("Nak"), SQMOD_ASCII_NAK)
.Const(_SC("Syn"), SQMOD_ASCII_SYN)
.Const(_SC("Etb"), SQMOD_ASCII_ETB)
.Const(_SC("Can"), SQMOD_ASCII_CAN)
.Const(_SC("Em"), SQMOD_ASCII_EM)
.Const(_SC("Sub"), SQMOD_ASCII_SUB)
.Const(_SC("Esc"), SQMOD_ASCII_ESC)
.Const(_SC("Fs"), SQMOD_ASCII_FS)
.Const(_SC("Gs"), SQMOD_ASCII_GS)
.Const(_SC("Rs"), SQMOD_ASCII_RS)
.Const(_SC("Us"), SQMOD_ASCII_US)
.Const(_SC("Space"), SQMOD_ASCII_SPACE)
.Const(_SC("Exclamation_point"), SQMOD_ASCII_EXCLAMATION_POINT)
.Const(_SC("Double_quotes"), SQMOD_ASCII_DOUBLE_QUOTES)
.Const(_SC("Number_sign"), SQMOD_ASCII_NUMBER_SIGN)
.Const(_SC("Dollar_sign"), SQMOD_ASCII_DOLLAR_SIGN)
.Const(_SC("Percent_sign"), SQMOD_ASCII_PERCENT_SIGN)
.Const(_SC("Ampersand"), SQMOD_ASCII_AMPERSAND)
.Const(_SC("Single_quote"), SQMOD_ASCII_SINGLE_QUOTE)
.Const(_SC("Opening_parenthesis"), SQMOD_ASCII_OPENING_PARENTHESIS)
.Const(_SC("Closing_parenthesis"), SQMOD_ASCII_CLOSING_PARENTHESIS)
.Const(_SC("Asterisk"), SQMOD_ASCII_ASTERISK)
.Const(_SC("Plus"), SQMOD_ASCII_PLUS)
.Const(_SC("Comma"), SQMOD_ASCII_COMMA)
.Const(_SC("Minus"), SQMOD_ASCII_MINUS)
.Const(_SC("Period"), SQMOD_ASCII_PERIOD)
.Const(_SC("Slash"), SQMOD_ASCII_SLASH)
.Const(_SC("Zero"), SQMOD_ASCII_ZERO)
.Const(_SC("One"), SQMOD_ASCII_ONE)
.Const(_SC("Two"), SQMOD_ASCII_TWO)
.Const(_SC("Three"), SQMOD_ASCII_THREE)
.Const(_SC("Four"), SQMOD_ASCII_FOUR)
.Const(_SC("Five"), SQMOD_ASCII_FIVE)
.Const(_SC("Six"), SQMOD_ASCII_SIX)
.Const(_SC("Seven"), SQMOD_ASCII_SEVEN)
.Const(_SC("Eight"), SQMOD_ASCII_EIGHT)
.Const(_SC("Nine"), SQMOD_ASCII_NINE)
.Const(_SC("Colon"), SQMOD_ASCII_COLON)
.Const(_SC("Emicolon"), SQMOD_ASCII_EMICOLON)
.Const(_SC("Less_than_sign"), SQMOD_ASCII_LESS_THAN_SIGN)
.Const(_SC("Equal_sign"), SQMOD_ASCII_EQUAL_SIGN)
.Const(_SC("Greater_than_sign"), SQMOD_ASCII_GREATER_THAN_SIGN)
.Const(_SC("Question_mark"), SQMOD_ASCII_QUESTION_MARK)
.Const(_SC("At"), SQMOD_ASCII_AT)
.Const(_SC("Upper_a"), SQMOD_ASCII_UPPER_A)
.Const(_SC("Upper_b"), SQMOD_ASCII_UPPER_B)
.Const(_SC("Upper_c"), SQMOD_ASCII_UPPER_C)
.Const(_SC("Upper_d"), SQMOD_ASCII_UPPER_D)
.Const(_SC("Upper_e"), SQMOD_ASCII_UPPER_E)
.Const(_SC("Upper_f"), SQMOD_ASCII_UPPER_F)
.Const(_SC("Upper_g"), SQMOD_ASCII_UPPER_G)
.Const(_SC("Upper_h"), SQMOD_ASCII_UPPER_H)
.Const(_SC("Upper_i"), SQMOD_ASCII_UPPER_I)
.Const(_SC("Upper_j"), SQMOD_ASCII_UPPER_J)
.Const(_SC("Upper_k"), SQMOD_ASCII_UPPER_K)
.Const(_SC("Upper_l"), SQMOD_ASCII_UPPER_L)
.Const(_SC("Upper_m"), SQMOD_ASCII_UPPER_M)
.Const(_SC("Upper_n"), SQMOD_ASCII_UPPER_N)
.Const(_SC("Upper_o"), SQMOD_ASCII_UPPER_O)
.Const(_SC("Upper_p"), SQMOD_ASCII_UPPER_P)
.Const(_SC("Upper_q"), SQMOD_ASCII_UPPER_Q)
.Const(_SC("Upper_r"), SQMOD_ASCII_UPPER_R)
.Const(_SC("Upper_s"), SQMOD_ASCII_UPPER_S)
.Const(_SC("Upper_t"), SQMOD_ASCII_UPPER_T)
.Const(_SC("Upper_u"), SQMOD_ASCII_UPPER_U)
.Const(_SC("Upper_v"), SQMOD_ASCII_UPPER_V)
.Const(_SC("Upper_w"), SQMOD_ASCII_UPPER_W)
.Const(_SC("Upper_x"), SQMOD_ASCII_UPPER_X)
.Const(_SC("Upper_y"), SQMOD_ASCII_UPPER_Y)
.Const(_SC("Upper_z"), SQMOD_ASCII_UPPER_Z)
.Const(_SC("Opening_bracket"), SQMOD_ASCII_OPENING_BRACKET)
.Const(_SC("Backslash"), SQMOD_ASCII_BACKSLASH)
.Const(_SC("Closing_bracket"), SQMOD_ASCII_CLOSING_BRACKET)
.Const(_SC("Caret"), SQMOD_ASCII_CARET)
.Const(_SC("Underscore"), SQMOD_ASCII_UNDERSCORE)
.Const(_SC("Grave_accent"), SQMOD_ASCII_GRAVE_ACCENT)
.Const(_SC("Lower_a"), SQMOD_ASCII_LOWER_A)
.Const(_SC("Lower_b"), SQMOD_ASCII_LOWER_B)
.Const(_SC("Lower_c"), SQMOD_ASCII_LOWER_C)
.Const(_SC("Lower_d"), SQMOD_ASCII_LOWER_D)
.Const(_SC("Lower_e"), SQMOD_ASCII_LOWER_E)
.Const(_SC("Lower_f"), SQMOD_ASCII_LOWER_F)
.Const(_SC("Lower_g"), SQMOD_ASCII_LOWER_G)
.Const(_SC("Lower_h"), SQMOD_ASCII_LOWER_H)
.Const(_SC("Lower_i"), SQMOD_ASCII_LOWER_I)
.Const(_SC("Lower_j"), SQMOD_ASCII_LOWER_J)
.Const(_SC("Lower_k"), SQMOD_ASCII_LOWER_K)
.Const(_SC("Lower_l"), SQMOD_ASCII_LOWER_L)
.Const(_SC("Lower_m"), SQMOD_ASCII_LOWER_M)
.Const(_SC("Lower_n"), SQMOD_ASCII_LOWER_N)
.Const(_SC("Lower_o"), SQMOD_ASCII_LOWER_O)
.Const(_SC("Lower_p"), SQMOD_ASCII_LOWER_P)
.Const(_SC("Lower_q"), SQMOD_ASCII_LOWER_Q)
.Const(_SC("Lower_r"), SQMOD_ASCII_LOWER_R)
.Const(_SC("Lower_s"), SQMOD_ASCII_LOWER_S)
.Const(_SC("Lower_t"), SQMOD_ASCII_LOWER_T)
.Const(_SC("Lower_u"), SQMOD_ASCII_LOWER_U)
.Const(_SC("Lower_v"), SQMOD_ASCII_LOWER_V)
.Const(_SC("Lower_w"), SQMOD_ASCII_LOWER_W)
.Const(_SC("Lower_x"), SQMOD_ASCII_LOWER_X)
.Const(_SC("Lower_y"), SQMOD_ASCII_LOWER_Y)
.Const(_SC("Lower_z"), SQMOD_ASCII_LOWER_Z)
.Const(_SC("Opening_brace"), SQMOD_ASCII_OPENING_BRACE)
.Const(_SC("Vertical_bar"), SQMOD_ASCII_VERTICAL_BAR)
.Const(_SC("Closing_brace"), SQMOD_ASCII_CLOSING_BRACE)
.Const(_SC("Tilde"), SQMOD_ASCII_TILDE)
.Const(_SC("Undefined"), SQMOD_ASCII_UNDEFINED)
.Const(_SC("Max"), SQMOD_ASCII_MAX)
);
}
} // Namespace:: SqMod

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,335 +0,0 @@
#include "Debug.hpp"
#include "Logger.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstdarg>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Debug::Pointer _Dbg = Debug::Inst();
// ------------------------------------------------------------------------------------------------
Debug::Debug()
: m_VM(NULL)
, m_Opts(PRINT_ALL | TRACE_ALL)
, m_Type()
, m_Func()
, m_RootName(_SC("root"))
, m_UnknownType(_SC("unknown"))
, m_UnknownFunc(_SC("unknown"))
{
}
// ------------------------------------------------------------------------------------------------
Debug::~Debug()
{
}
// ------------------------------------------------------------------------------------------------
void Debug::_Finalizer(Debug * ptr)
{
delete ptr; /* Assuming 'delete' checks for NULL */
}
// ------------------------------------------------------------------------------------------------
Debug::Pointer Debug::Inst()
{
if (!_Dbg)
{
return Pointer(new Debug(), &Debug::_Finalizer);
}
return Pointer(nullptr, &Debug::_Finalizer);
}
// ------------------------------------------------------------------------------------------------
HSQUIRRELVM Debug::GetVM()
{
return m_VM;
}
// ------------------------------------------------------------------------------------------------
void Debug::SetVM(HSQUIRRELVM vm)
{
m_VM = vm;
}
// ------------------------------------------------------------------------------------------------
void Debug::PrintTrace(SQInt32 lvl, SQInt32 end)
{
SQMOD_UNUSED_VAR(lvl);
SQMOD_UNUSED_VAR(end);
}
// ------------------------------------------------------------------------------------------------
void Debug::PrintCallstack(SQInt32 lvl, SQInt32 end)
{
SQMOD_UNUSED_VAR(lvl);
SQMOD_UNUSED_VAR(end);
}
// ------------------------------------------------------------------------------------------------
void Debug::SetInf(const char * type, const char * func)
{
if (type != NULL)
{
m_Type.assign(type);
}
else
{
m_Type.assign(m_UnknownType);
}
if (func != NULL)
{
m_Func.assign(func);
}
else
{
m_Func.assign(m_UnknownFunc);
}
}
// ------------------------------------------------------------------------------------------------
void Debug::Wrn(const char * type, const char * func, const char * fmt, va_list args)
{
// Store the information about the source
SetInf(type, func);
// Are warning messages enabled?
if (!(m_Opts & WRN_PRINT))
{
return;
}
// Send the message
_Log->Send(Logger::LEVEL_WRN, false, fmt, args);
// Is trace enabled for warning messages?
if (!(m_Opts & WRN_TRACE))
{
return;
}
// Do a traceback of the function call
InternalTrace();
}
// ------------------------------------------------------------------------------------------------
void Debug::Err(const char * type, const char * func, const char * fmt, va_list args)
{
// Store the information about the source
SetInf(type, func);
// Are warning messages enabled?
if (!(m_Opts & ERR_PRINT))
{
return;
}
// Send the message
_Log->Send(Logger::LEVEL_ERR, false, fmt, args);
// Is trace enabled for warning messages?
if (!(m_Opts & ERR_TRACE))
{
return;
}
// Do a traceback of the function call
InternalTrace();
}
// ------------------------------------------------------------------------------------------------
void Debug::Ftl(const char * type, const char * func, const char * fmt, va_list args)
{
// Store the information about the source
SetInf(type, func);
// Are warning messages enabled?
if (!(m_Opts & FTL_PRINT))
{
return;
}
// Send the message
_Log->Send(Logger::LEVEL_FTL, false, fmt, args);
// Is trace enabled for warning messages?
if (!(m_Opts & FTL_TRACE))
{
return;
}
// Do a traceback of the function call
InternalTrace();
}
// ------------------------------------------------------------------------------------------------
void Debug::Wrn(const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Wrn(NULL, NULL, fmt, args);
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Debug::Err(const char * fmt, ...)
{
SetInf(NULL, NULL);
va_list args;
va_start(args, fmt);
Err(NULL, NULL, fmt, args);
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Debug::Ftl(const char * fmt, ...)
{
SetInf(NULL, NULL);
va_list args;
va_start(args, fmt);
Ftl(NULL, NULL, fmt, args);
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Debug::Wrn(const char * func, const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Wrn(NULL, func, fmt, args);
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Debug::Err(const char * func, const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Err(NULL, func, fmt, args);
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Debug::Ftl(const char * func, const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Ftl(NULL, func, fmt, args);
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Debug::Wrn(const char * type, const char * func, const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Wrn(type, func, fmt, args);
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Debug::Err(const char * type, const char * func, const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Err(type, func, fmt, args);
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Debug::Ftl(const char * type, const char * func, const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
Ftl(type, func, fmt, args);
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Debug::InternalTrace()
{
// Structure that will contain informations about the queried stack level
SQStackInfos si;
// Output the base stack information before the actual trace
if (SQ_SUCCEEDED(sq_stackinfos(m_VM, 1, &si)))
{
if (m_Func.at(0) == '@')
{
_Log->SInf(" > 1 [ %s(%d) > %s::%s ]", si.source ? si.source : _SC("unknown"),
si.line, m_Type.c_str(), m_Func.c_str()+1);
}
else
{
_Log->SInf(" > 1 [ %s(%d) > %s::%s(...) ]", si.source ? si.source : _SC("unknown"),
si.line, m_Type.c_str(), m_Func.c_str());
}
}
// Keep outputting traceback information for the rest of the function calls
for (SQInt32 level = 2; SQ_SUCCEEDED(sq_stackinfos(m_VM, level, &si)); ++level)
{
_Log->SInf(" > %d [ %s(%d) > %s::%s(...) ]", level, si.source ? si.source : _SC("unknown"),
si.line, EnvName(level).c_str(), si.funcname ? si.funcname : _SC("unknown"));
}
}
// ------------------------------------------------------------------------------------------------
String Debug::EnvName(SQInt32 level)
{
// Obtain the top of the stack
const SQInteger top = sq_gettop(m_VM);
// Name of the retrieved local
const SQChar * name = NULL;
// Attempt to find the this environment
for (SQInt32 seq = 0; (name = sq_getlocal(m_VM, level, seq)); ++seq)
{
// Is this the `this` environment?
if (strcmp(name, "this") == 0)
{
// Found it!
break;
}
// Pop this useless local from the stack
sq_pop(m_VM, 1);
}
// Have we found anything?
if (name == NULL)
{
// Unable to find the `this` environment
return m_UnknownType;
}
// Push the root table on the stack
sq_pushroottable(m_VM);
// See if the `this` environment in the current level is the root table
if (sq_cmp(m_VM) == 0)
{
// Pop everything pushed onto the stack
sq_pop(m_VM, sq_gettop(m_VM) - top);
// Return the name specified for the root table
return m_RootName;
}
// Attempt to manually call the _typeof metamethod on the `this` environment
else if (SQ_SUCCEEDED(sq_typeof(m_VM, -2)))
{
// Treat the value returned by the the _typeof metamethod as a string
Var< String > str(m_VM, -1);
// Pop everything pushed onto the stack
sq_pop(m_VM, sq_gettop(m_VM) - top);
// If it was a valid string then return it as the name
if (!str.value.empty())
{
return str.value;
}
}
// Just pop everything pushed onto the stack
else
{
sq_pop(m_VM, sq_gettop(m_VM) - top);
}
// At this point the `this` environment is not recognized
return m_UnknownType;
}
// ================================================================================================
bool Register_Dbg(HSQUIRRELVM vm)
{
SQMOD_UNUSED_VAR(vm);
return true;
}
} // Namespace:: SqMod

View File

@@ -1,223 +0,0 @@
#ifndef _DEBUG_HPP_
#define _DEBUG_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class meant to help with the debugging process by offering tools for extracting information.
*/
class Debug
{
/* --------------------------------------------------------------------------------------------
* Allow only the smart pointer to delete this class instance as soon as it's not needed.
*/
friend class std::unique_ptr< Debug, void(*)(Debug *) >;
protected:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Debug();
/* --------------------------------------------------------------------------------------------
* Copy constructor (disabled).
*/
Debug(const Debug & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor (disabled).
*/
Debug(Debug && o) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Debug();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled).
*/
Debug & operator = (const Debug & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator (disabled).
*/
Debug & operator = (Debug && o) = delete;
/* --------------------------------------------------------------------------------------------
* Called by the smart pointer to delete the instance of this class.
*/
static void _Finalizer(Debug * ptr);
public:
// --------------------------------------------------------------------------------------------
typedef std::unique_ptr< Debug, void(*)(Debug *) > Pointer;
/* --------------------------------------------------------------------------------------------
* Creates an instance of this type if one doesn't already exist and returns it.
*/
static Pointer Inst();
/* --------------------------------------------------------------------------------------------
* ...
*/
static constexpr Uint8 WRN_PRINT = (1 << 0);
static constexpr Uint8 ERR_PRINT = (1 << 1);
static constexpr Uint8 FTL_PRINT = (1 << 2);
static constexpr Uint8 PRINT_ALL = (WRN_PRINT | ERR_PRINT | FTL_PRINT);
/* --------------------------------------------------------------------------------------------
* ...
*/
static constexpr Uint8 WRN_TRACE = (1 << 3);
static constexpr Uint8 ERR_TRACE = (1 << 4);
static constexpr Uint8 FTL_TRACE = (1 << 5);
static constexpr Uint8 TRACE_ALL = (WRN_TRACE | ERR_TRACE | FTL_TRACE);
/* --------------------------------------------------------------------------------------------
* ...
*/
HSQUIRRELVM GetVM();
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetVM(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PrintTrace(SQInt32 lvl, SQInt32 end);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PrintCallstack(SQInt32 lvl, SQInt32 end);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetInf(const char * type, const char * func);
/* --------------------------------------------------------------------------------------------
* Throws a warning message.
*/
void Wrn(const char * type, const char * func, const char * fmt, va_list args);
/* --------------------------------------------------------------------------------------------
* Throws a error message.
*/
void Err(const char * type, const char * func, const char * fmt, va_list args);
/* --------------------------------------------------------------------------------------------
* Throws a fatal message.
*/
void Ftl(const char * type, const char * func, const char * fmt, va_list args);
/* --------------------------------------------------------------------------------------------
* Throws a warning message.
*/
void Wrn(const char * fmt, ...);
/* --------------------------------------------------------------------------------------------
* Throws a error message.
*/
void Err(const char * fmt, ...);
/* --------------------------------------------------------------------------------------------
* Throws a fatal message.
*/
void Ftl(const char * fmt, ...);
/* --------------------------------------------------------------------------------------------
* Throws a warning message.
*/
void Wrn(const char * func, const char * fmt, ...);
/* --------------------------------------------------------------------------------------------
* Throws a error message.
*/
void Err(const char * func, const char * fmt, ...);
/* --------------------------------------------------------------------------------------------
* Throws a fatal message.
*/
void Ftl(const char * func, const char * fmt, ...);
/* --------------------------------------------------------------------------------------------
* Throws a warning message.
*/
void Wrn(const char * type, const char * func, const char * fmt, ...);
/* --------------------------------------------------------------------------------------------
* Throws a error message.
*/
void Err(const char * type, const char * func, const char * fmt, ...);
/* --------------------------------------------------------------------------------------------
* Throws a fatal message.
*/
void Ftl(const char * type, const char * func, const char * fmt, ...);
protected:
/* --------------------------------------------------------------------------------------------
* Internal function used to output a traceback of function calls when issues occur.
*/
void InternalTrace();
/* --------------------------------------------------------------------------------------------
* ...
*/
String EnvName(SQInt32 level);
private:
/* --------------------------------------------------------------------------------------------
* ...
*/
HSQUIRRELVM m_VM;
/* --------------------------------------------------------------------------------------------
* ...
*/
Uint8 m_Opts;
/* --------------------------------------------------------------------------------------------
* ...
*/
String m_Type;
/* --------------------------------------------------------------------------------------------
* ...
*/
String m_Func;
/* --------------------------------------------------------------------------------------------
* ...
*/
String m_RootName;
/* --------------------------------------------------------------------------------------------
* ...
*/
String m_UnknownType;
/* --------------------------------------------------------------------------------------------
* ...
*/
String m_UnknownFunc;
};
// ------------------------------------------------------------------------------------------------
extern const Debug::Pointer _Dbg;
} // Namespace:: SqMod
#endif // _DEBUG_HPP_

View File

@@ -1,183 +0,0 @@
#include "Entity.hpp"
#include "Register.hpp"
#include "Core.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
Ent< CPlayer >::MsgPrefix Ent< CPlayer >::Prefixes;
// ------------------------------------------------------------------------------------------------
SQUint32 Ent< CPlayer >::MessageColor;
SQInt32 Ent< CPlayer >::AnnounceStyle;
// ------------------------------------------------------------------------------------------------
EBlipCreated & GBlipCreated()
{
return _Core->BlipCreated;
}
ECheckpointCreated & GCheckpointCreated()
{
return _Core->CheckpointCreated;
}
EKeybindCreated & GKeybindCreated()
{
return _Core->KeybindCreated;
}
EObjectCreated & GObjectCreated()
{
return _Core->ObjectCreated;
}
EPickupCreated & GPickupCreated()
{
return _Core->PickupCreated;
}
EPlayerCreated & GPlayerCreated()
{
return _Core->PlayerCreated;
}
ESphereCreated & GSphereCreated()
{
return _Core->SphereCreated;
}
ESpriteCreated & GSpriteCreated()
{
return _Core->SpriteCreated;
}
ETextdrawCreated & GTextdrawCreated()
{
return _Core->TextdrawCreated;
}
EVehicleCreated & GVehicleCreated()
{
return _Core->VehicleCreated;
}
// ------------------------------------------------------------------------------------------------
EBlipDestroyed & GBlipDestroyed()
{
return _Core->BlipDestroyed;
}
ECheckpointDestroyed & GCheckpointDestroyed()
{
return _Core->CheckpointDestroyed;
}
EKeybindDestroyed & GKeybindDestroyed()
{
return _Core->KeybindDestroyed;
}
EObjectDestroyed & GObjectDestroyed()
{
return _Core->ObjectDestroyed;
}
EPickupDestroyed & GPickupDestroyed()
{
return _Core->PickupDestroyed;
}
EPlayerDestroyed & GPlayerDestroyed()
{
return _Core->PlayerDestroyed;
}
ESphereDestroyed & GSphereDestroyed()
{
return _Core->SphereDestroyed;
}
ESpriteDestroyed & GSpriteDestroyed()
{
return _Core->SpriteDestroyed;
}
ETextdrawDestroyed & GTextdrawDestroyed()
{
return _Core->TextdrawDestroyed;
}
EVehicleDestroyed & GVehicleDestroyed()
{
return _Core->VehicleDestroyed;
}
// ------------------------------------------------------------------------------------------------
EBlipCustom & GBlipCustom()
{
return _Core->BlipCustom;
}
ECheckpointCustom & GCheckpointCustom()
{
return _Core->CheckpointCustom;
}
EKeybindCustom & GKeybindCustom()
{
return _Core->KeybindCustom;
}
EObjectCustom & GObjectCustom()
{
return _Core->ObjectCustom;
}
EPickupCustom & GPickupCustom()
{
return _Core->PickupCustom;
}
EPlayerCustom & GPlayerCustom()
{
return _Core->PlayerCustom;
}
ESphereCustom & GSphereCustom()
{
return _Core->SphereCustom;
}
ESpriteCustom & GSpriteCustom()
{
return _Core->SpriteCustom;
}
ETextdrawCustom & GTextdrawCustom()
{
return _Core->TextdrawCustom;
}
EVehicleCustom & GVehicleCustom()
{
return _Core->VehicleCustom;
}
// ------------------------------------------------------------------------------------------------
static SQInt32 GetPlayerLevel(SQInt32 id)
{
return Reference< CPlayer >::Get(id).Level;
}
// ------------------------------------------------------------------------------------------------
bool Register_Entity(HSQUIRRELVM vm)
{
// Attempt to bind the namespace to the root table
Sqrat::RootTable(vm).Func(_SC("GetPlayerLevel"), GetPlayerLevel);
// Registration succeeded
return true;
}
} // Namespace:: SqMod

File diff suppressed because it is too large Load Diff

View File

@@ -6,364 +6,289 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
CBlip::CBlip(const Reference< CBlip > & o)
: Reference(o)
SQChar CBlip::s_StrID[SQMOD_BLIP_POOL][8];
// ------------------------------------------------------------------------------------------------
const Int32 CBlip::Max = SQMOD_BLIP_POOL;
// ------------------------------------------------------------------------------------------------
CBlip::CBlip(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_BLIP_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
SQInteger CBlip::GetWorld() const
CBlip::~CBlip()
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).World;
}
else
{
BadRef("@world", "get world");
}
return SQMOD_UNKNOWN;
/* ... */
}
// ------------------------------------------------------------------------------------------------
SQInteger CBlip::GetScale() const
Int32 CBlip::Cmp(const CBlip & o) const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Scale;
}
if (m_ID == o.m_ID)
return 0;
else if (m_ID > o.m_ID)
return 1;
else
{
BadRef("@scale", "get scale");
}
return -1;
}
return SQMOD_UNKNOWN;
CSStr CBlip::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_BLIP_POOL) ? s_StrID[m_ID] : _SC("-1");
}
// ------------------------------------------------------------------------------------------------
CSStr CBlip::GetTag() const
{
return m_Tag.c_str();
}
void CBlip::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
Object & CBlip::GetData()
{
if (Validate())
return m_Data;
return NullObject();
}
void CBlip::SetData(Object & data)
{
if (Validate())
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CBlip::Destroy(Int32 header, Object & payload)
{
return _Core->DelBlip(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CBlip::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
Function & event = _Core->GetBlipEvent(m_ID, evid);
if (func.IsNull())
event.Release();
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetWorld() const
{
if (Validate())
return _Core->GetBlip(m_ID).mWorld;
return -1;
}
Int32 CBlip::GetScale() const
{
if (Validate())
return _Core->GetBlip(m_ID).mScale;
return -1;
}
const Vector3 & CBlip::GetPosition() const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Position;
}
else
{
BadRef("@position", "get position");
}
if (Validate())
return _Core->GetBlip(m_ID).mPosition;
return Vector3::NIL;
}
// ------------------------------------------------------------------------------------------------
SQFloat CBlip::GetPositionX() const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Position.x;
}
else
{
BadRef("@pos_x", "get x axis");
}
return 0.0;
}
// ------------------------------------------------------------------------------------------------
SQFloat CBlip::GetPositionY() const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Position.y;
}
else
{
BadRef("@pos_y", "get y axis");
}
return 0.0;
}
// ------------------------------------------------------------------------------------------------
SQFloat CBlip::GetPositionZ() const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Position.z;
}
else
{
BadRef("@pos_z", "get z axis");
}
return 0.0;
}
// ------------------------------------------------------------------------------------------------
const Color4 & CBlip::GetColor() const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Color;
}
else
{
BadRef("@color", "get color");
}
if (Validate())
return _Core->GetBlip(m_ID).mColor;
return Color4::NIL;
}
// ------------------------------------------------------------------------------------------------
SQInt32 CBlip::GetSprID() const
Int32 CBlip::GetSprID() const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).SprID;
}
else
{
BadRef("@spr_id", "get sprite id");
}
return SQMOD_UNKNOWN;
if (Validate())
return _Core->GetBlip(m_ID).mSprID;
return -1;
}
// ------------------------------------------------------------------------------------------------
Reference< CBlip > CreateBaseBlip_ES(SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQInt32 sprid)
Float32 CBlip::GetPosX() const
{
return _Core->NewBlip(SQMOD_UNKNOWN, world, x, y, z, scale, PACK_RGBA(r, g, b, a), sprid,
SQMOD_CREATE_DEFAULT, NullData());
if (Validate())
return _Core->GetBlip(m_ID).mPosition.x;
return 0;
}
Reference< CBlip > CreateBaseBlip_ES(SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQInt32 sprid,
SQInt32 header, SqObj & payload)
Float32 CBlip::GetPosY() const
{
return _Core->NewBlip(SQMOD_UNKNOWN, world, x, y, z, scale, PACK_RGBA(r, g, b, a), sprid,
if (Validate())
return _Core->GetBlip(m_ID).mPosition.y;
return 0;
}
Float32 CBlip::GetPosZ() const
{
if (Validate())
return _Core->GetBlip(m_ID).mPosition.z;
return 0;
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetColorR() const
{
if (Validate())
return _Core->GetBlip(m_ID).mColor.r;
return 0;
}
Int32 CBlip::GetColorG() const
{
if (Validate())
return _Core->GetBlip(m_ID).mColor.g;
return 0;
}
Int32 CBlip::GetColorB() const
{
if (Validate())
return _Core->GetBlip(m_ID).mColor.b;
return 0;
}
Int32 CBlip::GetColorA() const
{
if (Validate())
return _Core->GetBlip(m_ID).mColor.a;
return 0;
}
// ------------------------------------------------------------------------------------------------
static Object & CreateBlipEx(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,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateBlipEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
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,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CBlip > CreateBaseBlip_EF(SQInt32 index, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQInt32 sprid)
static Object & CreateBlipEx(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, PACK_RGBA(r, g, b, a), sprid,
SQMOD_CREATE_DEFAULT, NullData());
return _Core->NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
}
Reference< CBlip > CreateBaseBlip_EF(SQInt32 index, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQInt32 sprid,
SQInt32 header, SqObj & payload)
static Object & CreateBlipEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid,
Int32 header, Object & payload)
{
return _Core->NewBlip(index, world, x, y, z, scale, PACK_RGBA(r, g, b, a), sprid,
return _Core->NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CBlip > CreateBaseBlip_CS(SQInt32 world, const Vector3 & pos,
SQInt32 scale, const Color4 & color, SQInt32 sprid)
static Object & CreateBlip(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
Int32 sprid)
{
return _Core->NewBlip(SQMOD_UNKNOWN, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
SQMOD_CREATE_DEFAULT, NullData());
return _Core->NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
}
Reference< CBlip > CreateBaseBlip_CS(SQInt32 world, const Vector3 & pos,
SQInt32 scale, const Color4 & color, SQInt32 sprid,
SQInt32 header, SqObj & payload)
static Object & CreateBlip(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
Int32 sprid, Int32 header, Object & payload)
{
return _Core->NewBlip(SQMOD_UNKNOWN, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
return _Core->NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CBlip > CreateBaseBlip_CF(SQInt32 index, SQInt32 world, const Vector3 & pos,
SQInt32 scale, const Color4 & color, SQInt32 sprid)
static Object & CreateBlip(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,
SQMOD_CREATE_DEFAULT, NullData());
SQMOD_CREATE_DEFAULT, NullObject());
}
Reference< CBlip > CreateBaseBlip_CF(SQInt32 index, SQInt32 world, const Vector3 & pos,
SQInt32 scale, const Color4 & color, SQInt32 sprid,
SQInt32 header, SqObj & payload)
{
return _Core->NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CBlip CreateBlip_ES(SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQInt32 sprid)
{
return _Core->NewBlip(SQMOD_UNKNOWN, world, x, y, z, scale, PACK_RGBA(r, g, b, a), sprid,
SQMOD_CREATE_DEFAULT, NullData());
}
CBlip CreateBlip_ES(SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQInt32 sprid,
SQInt32 header, SqObj & payload)
{
return _Core->NewBlip(SQMOD_UNKNOWN, world, x, y, z, scale, PACK_RGBA(r, g, b, a), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CBlip CreateBlip_EF(SQInt32 index, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQInt32 sprid)
{
return _Core->NewBlip(index, world, x, y, z, scale, PACK_RGBA(r, g, b, a), sprid,
SQMOD_CREATE_DEFAULT, NullData());
}
CBlip CreateBlip_EF(SQInt32 index, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQInt32 sprid,
SQInt32 header, SqObj & payload)
{
return _Core->NewBlip(index, world, x, y, z, scale, PACK_RGBA(r, g, b, a), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CBlip CreateBlip_CS(SQInt32 world, const Vector3 & pos,
SQInt32 scale, const Color4 & color, SQInt32 sprid)
{
return _Core->NewBlip(SQMOD_UNKNOWN, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
SQMOD_CREATE_DEFAULT, NullData());
}
CBlip CreateBlip_CS(SQInt32 world, const Vector3 & pos,
SQInt32 scale, const Color4 & color, SQInt32 sprid,
SQInt32 header, SqObj & payload)
{
return _Core->NewBlip(SQMOD_UNKNOWN, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CBlip CreateBlip_CF(SQInt32 index, SQInt32 world, const Vector3 & pos,
SQInt32 scale, const Color4 & color, SQInt32 sprid)
{
return _Core->NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
SQMOD_CREATE_DEFAULT, NullData());
}
CBlip CreateBlip_CF(SQInt32 index, SQInt32 world, const Vector3 & pos,
SQInt32 scale, const Color4 & color, SQInt32 sprid,
SQInt32 header, SqObj & payload)
static Object & CreateBlip(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,
header, payload);
}
// ================================================================================================
bool Register_CBlip(HSQUIRRELVM vm)
void Register_CBlip(HSQUIRRELVM vm)
{
// Attempt to register the base reference type before the actual implementation
if (!Register_Reference< CBlip >(vm, _SC("BaseBlip")))
{
LogFtl("Unable to register the base class <BaseBlip> for <CBlip> type");
// Registration failed
return false;
}
// Typedef the base reference type for simplicity
typedef Reference< CBlip > RefType;
// Output debugging information
LogDbg("Beginning registration of <CBlip> type");
// Attempt to register the actual reference that implements all of the entity functionality
Sqrat::RootTable(vm).Bind(_SC("CBlip"), Sqrat::DerivedClass< CBlip, RefType >(vm, _SC("CBlip"))
/* Constructors */
.Ctor()
.Ctor< SQInt32 >()
RootTable(vm).Bind(_SC("SqBlip"),
Class< CBlip, NoConstructor< CBlip > >(vm, _SC("SqBlip"))
/* Metamethods */
.Func(_SC("_cmp"), &CBlip::Cmp)
.Func(_SC("_tostring"), &CBlip::ToString)
/* Core Properties */
.Prop(_SC("ID"), &CBlip::GetID)
.Prop(_SC("Tag"), &CBlip::GetTag, &CBlip::SetTag)
.Prop(_SC("Data"), &CBlip::GetData, &CBlip::SetData)
.Prop(_SC("MaxID"), &CBlip::GetMaxID)
.Prop(_SC("Active"), &CBlip::IsActive)
/* Core Functions */
.Func(_SC("Bind"), &CBlip::BindEvent)
/* Core Overloads */
.Overload< bool (CBlip::*)(void) >(_SC("Destroy"), &CBlip::Destroy)
.Overload< bool (CBlip::*)(Int32) >(_SC("Destroy"), &CBlip::Destroy)
.Overload< bool (CBlip::*)(Int32, Object &) >(_SC("Destroy"), &CBlip::Destroy)
/* Properties */
.Prop(_SC("world"), &CBlip::GetWorld)
.Prop(_SC("scale"), &CBlip::GetScale)
.Prop(_SC("pos"), &CBlip::GetPosition)
.Prop(_SC("position"), &CBlip::GetPosition)
.Prop(_SC("color"), &CBlip::GetColor)
.Prop(_SC("spr_id"), &CBlip::GetSprID)
.Prop(_SC("pos_x"), &CBlip::GetPositionX)
.Prop(_SC("pos_y"), &CBlip::GetPositionY)
.Prop(_SC("pos_z"), &CBlip::GetPositionZ)
.Prop(_SC("World"), &CBlip::GetWorld)
.Prop(_SC("Scale"), &CBlip::GetScale)
.Prop(_SC("Pos"), &CBlip::GetPosition)
.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)
);
// Output debugging information
LogDbg("Registration of <CBlip> type was successful");
// Output debugging information
LogDbg("Beginning registration of <Blip> functions");
// Register global functions related to this entity type
Sqrat::RootTable(vm)
/* Create BaseBlip [E]xtended [S]ubstitute */
.Overload< RefType (*)(SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, Uint8, Uint8, Uint8, Uint8, SQInt32) >
(_SC("CreateBaseBlip_ES"), &CreateBaseBlip_ES)
.Overload< RefType (*)(SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, Uint8, Uint8, Uint8, Uint8, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBaseBlip_ES"), &CreateBaseBlip_ES)
/* Create BaseBlip [E]xtended [F]Full */
.Overload< RefType (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, Uint8, Uint8, Uint8, Uint8, SQInt32) >
(_SC("CreateBaseBlip_EF"), &CreateBaseBlip_EF)
.Overload< RefType (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, Uint8, Uint8, Uint8, Uint8, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBaseBlip_EF"), &CreateBaseBlip_EF)
/* Create BaseBlip [C]ompact [S]ubstitute */
.Overload< RefType (*)(SQInt32, const Vector3 &, SQInt32, const Color4 &, SQInt32) >
(_SC("CreateBaseBlip_CS"), &CreateBaseBlip_CS)
.Overload< RefType (*)(SQInt32, const Vector3 &, SQInt32, const Color4 &, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBaseBlip_CS"), &CreateBaseBlip_CS)
/* Create BaseBlip [C]ompact [F]ull */
.Overload< RefType (*)(SQInt32, SQInt32, const Vector3 &, SQInt32, const Color4 &, SQInt32) >
(_SC("CreateBaseBlip_CF"), &CreateBaseBlip_CF)
.Overload< RefType (*)(SQInt32, SQInt32, const Vector3 &, SQInt32, const Color4 &, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBaseBlip_CF"), &CreateBaseBlip_CF)
/* Create CBlip [E]xtended [S]ubstitute */
.Overload< CBlip (*)(SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, Uint8, Uint8, Uint8, Uint8, SQInt32) >
(_SC("CreateBlip_ES"), &CreateBlip_ES)
.Overload< CBlip (*)(SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, Uint8, Uint8, Uint8, Uint8, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBlip_ES"), &CreateBlip_ES)
/* Create CBlip [E]xtended [F]Full */
.Overload< CBlip (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, Uint8, Uint8, Uint8, Uint8, SQInt32) >
(_SC("CreateBlip_EF"), &CreateBlip_EF)
.Overload< CBlip (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, Uint8, Uint8, Uint8, Uint8, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBlip_EF"), &CreateBlip_EF)
/* Create CBlip [C]ompact [S]ubstitute */
.Overload< CBlip (*)(SQInt32, const Vector3 &, SQInt32, const Color4 &, SQInt32) >
(_SC("CreateBlip_CS"), &CreateBlip_CS)
.Overload< CBlip (*)(SQInt32, const Vector3 &, SQInt32, const Color4 &, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBlip_CS"), &CreateBlip_CS)
/* Create CBlip [C]ompact [F]ull */
.Overload< CBlip (*)(SQInt32, SQInt32, const Vector3 &, SQInt32, const Color4 &, SQInt32) >
(_SC("CreateBlip_CF"), &CreateBlip_CF)
.Overload< CBlip (*)(SQInt32, SQInt32, const Vector3 &, SQInt32, const Color4 &, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBlip_CF"), &CreateBlip_CF);
// Output debugging information
LogDbg("Registration of <Blip> functions was successful");
// Registration succeeded
return true;
RootTable(vm)
.Overload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateBlipEx"), &CreateBlipEx)
.Overload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, Object &) >
(_SC("CreateBlipEx"), &CreateBlipEx)
.Overload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateBlipEx"), &CreateBlipEx)
.Overload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, Object &) >
(_SC("CreateBlipEx"), &CreateBlipEx)
.Overload< Object & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("CreateBlip"), &CreateBlip)
.Overload< Object & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, Object &) >
(_SC("CreateBlip"), &CreateBlip)
.Overload< Object & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("CreateBlip"), &CreateBlip)
.Overload< Object & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, Object &) >
(_SC("CreateBlip"), &CreateBlip);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@@ -2,69 +2,145 @@
#define _ENTITY_BLIP_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced blip instance.
* Manages Blip instances.
*/
class CBlip : public Reference< CBlip >
class CBlip
{
// --------------------------------------------------------------------------------------------
friend class Core;
private:
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_BLIP_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CBlip(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CBlip(const CBlip &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CBlip & operator = (const CBlip &);
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
* Destructor.
*/
CBlip(const Reference< CBlip > & o);
~CBlip();
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced blip instance exists.
* See whether this instance manages a valid entity.
*/
SQInteger GetWorld() const;
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid blip reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the scale of the referenced blip instance.
* Used by the script engine to compare two instances of this type.
*/
SQInteger GetScale() const;
Int32 Cmp(const CBlip & o) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the referenced blip instance.
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_BLIP_POOL; }
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr 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 entity instance.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
Int32 GetWorld() const;
Int32 GetScale() const;
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the x axis position of the referenced blip instance.
*/
SQFloat GetPositionX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the y axis position of the referenced blip instance.
*/
SQFloat GetPositionY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the z axis position of the referenced blip instance.
*/
SQFloat GetPositionZ() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the referenced blip instance.
*/
const Color4 & GetColor() const;
Int32 GetSprID() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the sprite identifier of the referenced blip instance.
*/
SQInt32 GetSprID() const;
// --------------------------------------------------------------------------------------------
Float32 GetPosX() const;
Float32 GetPosY() const;
Float32 GetPosZ() const;
Int32 GetColorR() const;
Int32 GetColorG() const;
Int32 GetColorB() const;
Int32 GetColorA() const;
};
} // Namespace:: SqMod
#endif // _ENTITY_BLIP_HPP_
#endif // _ENTITY_BLIP_HPP_

View File

@@ -1,447 +1,403 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Checkpoint.hpp"
#include "Entity/Player.hpp"
#include "Base/Color4.hpp"
#include "Base/Vector3.hpp"
#include "Core.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
Color4 CCheckpoint::s_Color4;
Vector3 CCheckpoint::s_Vector3;
Color4 CCheckpoint::s_Color4;
Vector3 CCheckpoint::s_Vector3;
// ------------------------------------------------------------------------------------------------
SQUint32 CCheckpoint::s_ColorR;
SQUint32 CCheckpoint::s_ColorG;
SQUint32 CCheckpoint::s_ColorB;
SQUint32 CCheckpoint::s_ColorA;
Uint32 CCheckpoint::s_ColorR;
Uint32 CCheckpoint::s_ColorG;
Uint32 CCheckpoint::s_ColorB;
Uint32 CCheckpoint::s_ColorA;
// ------------------------------------------------------------------------------------------------
CCheckpoint::CCheckpoint(const Reference< CCheckpoint > & o)
: Reference(o)
SQChar CCheckpoint::s_StrID[SQMOD_CHECKPOINT_POOL][8];
// ------------------------------------------------------------------------------------------------
const Int32 CCheckpoint::Max = SQMOD_CHECKPOINT_POOL;
// ------------------------------------------------------------------------------------------------
CCheckpoint::CCheckpoint(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_CHECKPOINT_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::IsStreamedFor(const Reference< CPlayer > & player) const
CCheckpoint::~CCheckpoint()
{
if (VALID_ENTITY(m_ID) && player)
{
return _Func->IsCheckpointStreamedForPlayer(m_ID, player);
}
else if (!player)
{
BadArg("streamed_for", "see whether is streamed for player", _SCI32(player));
}
else
{
BadRef("streamed_for", "see whether is streamed for player");
}
/* ... */
}
// ------------------------------------------------------------------------------------------------
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;
}
CSStr CCheckpoint::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_CHECKPOINT_POOL) ? s_StrID[m_ID] : _SC("-1");
}
// ------------------------------------------------------------------------------------------------
CSStr CCheckpoint::GetTag() const
{
return m_Tag.c_str();
}
void CCheckpoint::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
Object & CCheckpoint::GetData()
{
if (Validate())
return m_Data;
return NullObject();
}
void CCheckpoint::SetData(Object & data)
{
if (Validate())
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::Destroy(Int32 header, Object & payload)
{
return _Core->DelCheckpoint(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
Function & event = _Core->GetCheckpointEvent(m_ID, evid);
if (func.IsNull())
event.Release();
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::IsStreamedFor(CPlayer & player) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
return _Func->IsCheckpointStreamedForPlayer(m_ID, player.GetID());
return false;
}
// ------------------------------------------------------------------------------------------------
SQInt32 CCheckpoint::GetWorld() const
Int32 CCheckpoint::GetWorld() const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
return _Func->GetCheckpointWorld(m_ID);
}
else
{
BadRef("@world", "get world");
}
return SQMOD_UNKNOWN;
return -1;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetWorld(SQInt32 world) const
void CCheckpoint::SetWorld(Int32 world) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->SetCheckpointWorld(m_ID, world);
}
else
{
BadRef("@world", "set world");
}
}
// ------------------------------------------------------------------------------------------------
const Color4 & CCheckpoint::GetColor() const
{
// Clear any previous color
s_Color4.Clear();
// Attempt to retrieve the color
if (VALID_ENTITY(m_ID))
if (Validate())
{
_Func->GetCheckpointColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB, &s_ColorA);
s_Color4.Set(s_ColorR, s_ColorG, s_ColorB, s_ColorA);
}
else
{
BadRef("@color", "get color");
}
// Return the color that could be retrieved
return s_Color4;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColor(const Color4 & col) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->SetCheckpointColor(m_ID, col.r, col.g, col.b, col.a);
}
else
{
BadRef("@color", "set color");
}
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColorEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->SetCheckpointColor(m_ID, r, g, b, a);
}
else
{
BadRef("set_color", "set color");
}
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CCheckpoint::GetPosition() const
{
// Clear any previous position
s_Vector3.Clear();
// Attempt to retrieve the position
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
}
else
{
BadRef("@position", "get position");
}
// Return the position that could be retrieved
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPosition(const Vector3 & pos) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->SetCheckpointPos(m_ID, pos.x, pos.y, pos.z);
}
else
{
BadRef("@position", "set position");
}
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const
void CCheckpoint::SetPositionEx(Float32 x, Float32 y, Float32 z) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->SetCheckpointPos(m_ID, x, y, z);
}
else
{
BadRef("set_position", "set position");
}
}
// ------------------------------------------------------------------------------------------------
SQFloat CCheckpoint::GetRadius() const
Float32 CCheckpoint::GetRadius() const
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetCheckpointRadius(m_ID);
}
else
{
BadRef("@radius", "get radius");
}
return 0.0;
if (Validate())
_Func->GetCheckpointRadius(m_ID);
return 0;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetRadius(SQFloat radius) const
void CCheckpoint::SetRadius(Float32 radius) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->SetCheckpointRadius(m_ID, radius);
}
else
{
BadRef("@radius", "set radius");
}
}
// ------------------------------------------------------------------------------------------------
Reference< CPlayer > CCheckpoint::GetOwner() const
Object & CCheckpoint::GetOwner() const
{
if (VALID_ENTITY(m_ID))
{
return Reference< CPlayer >(_Func->GetCheckpointOwner(m_ID));
}
else
{
BadRef("@owner", "get owner");
}
return Reference< CPlayer >();
if (Validate())
return _Core->GetPlayer(_Func->GetCheckpointOwner(m_ID)).mObj;
return NullObject();
}
// ------------------------------------------------------------------------------------------------
SQInt32 CCheckpoint::GetOwnerID() const
Int32 CCheckpoint::GetOwnerID() const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
return _Func->GetCheckpointOwner(m_ID);
}
else
return -1;
}
// ------------------------------------------------------------------------------------------------
Float32 CCheckpoint::GetPosX() const
{
s_Vector3.x = 0;
if (Validate())
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, NULL, NULL);
return s_Vector3.x;
}
Float32 CCheckpoint::GetPosY() const
{
s_Vector3.y = 0;
if (Validate())
_Func->GetCheckpointPos(m_ID, NULL, &s_Vector3.y, NULL);
return s_Vector3.y;
}
Float32 CCheckpoint::GetPosZ() const
{
s_Vector3.z = 0;
if (Validate())
_Func->GetCheckpointPos(m_ID, NULL, NULL, &s_Vector3.z);
return s_Vector3.z;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPosX(Float32 x) const
{
if (Validate())
{
BadRef("@owner_id", "get owner id");
_Func->GetCheckpointPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
_Func->SetCheckpointPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
}
return SQMOD_UNKNOWN;
void CCheckpoint::SetPosY(Float32 y) const
{
if (Validate())
{
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
_Func->SetCheckpointPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
}
void CCheckpoint::SetPosZ(Float32 z) const
{
if (Validate())
{
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
_Func->SetCheckpointPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
}
// ------------------------------------------------------------------------------------------------
Reference< CCheckpoint > CreateBaseCheckpoint_PEF(SQInt32 player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQFloat radius)
Uint32 CCheckpoint::GetColR() const
{
return _Core->NewCheckpoint(player, world, x, y, z, r, g, b, a, radius,
SQMOD_CREATE_DEFAULT, NullData());
s_ColorR = 0;
if (Validate())
_Func->GetCheckpointColor(m_ID, &s_ColorR, NULL, NULL, NULL);
return s_ColorR;
}
Reference< CCheckpoint > CreateBaseCheckpoint_PEF(SQInt32 player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQFloat radius,
SQInt32 header, SqObj & payload)
Uint32 CCheckpoint::GetColG() const
{
return _Core->NewCheckpoint(player, world, x, y, z, r, g, b, a, radius,
header, payload);
s_ColorG = 0;
if (Validate())
_Func->GetCheckpointColor(m_ID, NULL, &s_ColorG, NULL, NULL);
return s_ColorG;
}
Uint32 CCheckpoint::GetColB() const
{
s_ColorB = 0;
if (Validate())
_Func->GetCheckpointColor(m_ID, NULL, NULL, &s_ColorB, NULL);
return s_ColorB;
}
Uint32 CCheckpoint::GetColA() const
{
s_ColorA = 0;
if (Validate())
_Func->GetCheckpointColor(m_ID, NULL, NULL, NULL, &s_ColorA);
return s_ColorA;
}
// ------------------------------------------------------------------------------------------------
Reference< CCheckpoint > CreateBaseCheckpoint_PCF(SQInt32 player, SQInt32 world,
const Vector3 & pos, const Color4 & color, SQFloat radius)
void CCheckpoint::SetColR(Uint32 r) const
{
return _Core->NewCheckpoint(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius,
SQMOD_CREATE_DEFAULT, NullData());
if (Validate())
{
_Func->GetCheckpointColor(m_ID, NULL, &s_ColorG, &s_ColorB, &s_ColorA);
_Func->SetCheckpointColor(m_ID, r, s_ColorG, s_ColorB, s_ColorA);
}
}
Reference< CCheckpoint > CreateBaseCheckpoint_PCF(SQInt32 player, SQInt32 world,
const Vector3 & pos, const Color4 & color, SQFloat radius,
SQInt32 header, SqObj & payload)
void CCheckpoint::SetColG(Uint32 g) const
{
return _Core->NewCheckpoint(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius,
header, payload);
if (Validate())
{
_Func->GetCheckpointColor(m_ID, &s_ColorR, NULL, &s_ColorB, &s_ColorA);
_Func->SetCheckpointColor(m_ID, s_ColorR, g, s_ColorB, s_ColorA);
}
}
void CCheckpoint::SetColB(Uint32 b) const
{
if (Validate())
{
_Func->GetCheckpointColor(m_ID, &s_ColorB, &s_ColorG, NULL, &s_ColorA);
_Func->SetCheckpointColor(m_ID, s_ColorB, s_ColorG, b, s_ColorA);
}
}
void CCheckpoint::SetColA(Uint32 a) const
{
if (Validate())
{
_Func->GetCheckpointColor(m_ID, &s_ColorA, &s_ColorG, &s_ColorB, NULL);
_Func->SetCheckpointColor(m_ID, s_ColorA, s_ColorG, s_ColorB, a);
}
}
// ------------------------------------------------------------------------------------------------
Reference< CCheckpoint > CreateBaseCheckpoint_EF(const Reference< CPlayer > & player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQFloat radius)
static Object & CreateCheckpointEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius)
{
return _Core->NewCheckpoint(player, world, x, y, z, r, g, b, a, radius,
SQMOD_CREATE_DEFAULT, NullData());
return _Core->NewCheckpoint(player.GetID(), world, x, y, z, r, g, b, a, radius,
SQMOD_CREATE_DEFAULT, NullObject());
}
Reference< CCheckpoint > CreateBaseCheckpoint_EF(const Reference< CPlayer > & player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQFloat radius,
SQInt32 header, SqObj & payload)
static Object & CreateCheckpointEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, Object & payload)
{
return _Core->NewCheckpoint(player, world, x, y, z, r, g, b, a, radius,
header, payload);
return _Core->NewCheckpoint(player.GetID(), world, x, y, z, r, g, b, a, radius, header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CCheckpoint > CreateBaseCheckpoint_CF(const Reference< CPlayer > & player, SQInt32 world,
const Vector3 & pos, const Color4 & color, SQFloat radius)
static Object & CreateCheckpoint(CPlayer & player, Int32 world, const Vector3 & pos,
const Color4 & color, Float32 radius)
{
return _Core->NewCheckpoint(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius,
SQMOD_CREATE_DEFAULT, NullData());
return _Core->NewCheckpoint(player.GetID(), world, pos.x, pos.y, pos.z,
color.r, color.g, color.b, color.a, radius,
SQMOD_CREATE_DEFAULT, NullObject());
}
Reference< CCheckpoint > CreateBaseCheckpoint_CF(const Reference< CPlayer > & player, SQInt32 world,
const Vector3 & pos, const Color4 & color, SQFloat radius,
SQInt32 header, SqObj & payload)
static Object & CreateCheckpoint(CPlayer & player, Int32 world, const Vector3 & pos,
const Color4 & color, Float32 radius, Int32 header, Object & payload)
{
return _Core->NewCheckpoint(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CCheckpoint CreateCheckpoint_PEF(SQInt32 player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQFloat radius)
{
return _Core->NewCheckpoint(player, world, x, y, z, r, g, b, a, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
CCheckpoint CreateCheckpoint_PEF(SQInt32 player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewCheckpoint(player, world, x, y, z, r, g, b, a, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CCheckpoint CreateCheckpoint_PCF(SQInt32 player, SQInt32 world,
const Vector3 & pos, const Color4 & color, SQFloat radius)
{
return _Core->NewCheckpoint(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
CCheckpoint CreateCheckpoint_PCF(SQInt32 player, SQInt32 world,
const Vector3 & pos, const Color4 & color, SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewCheckpoint(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CCheckpoint CreateCheckpoint_EF(const Reference< CPlayer > & player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQFloat radius)
{
return _Core->NewCheckpoint(player, world, x, y, z, r, g, b, a, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
CCheckpoint CreateCheckpoint_EF(const Reference< CPlayer > & player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewCheckpoint(player, world, x, y, z, r, g, b, a, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CCheckpoint CreateCheckpoint_CF(const Reference< CPlayer > & player, SQInt32 world,
const Vector3 & pos, const Color4 & color, SQFloat radius)
{
return _Core->NewCheckpoint(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
CCheckpoint CreateCheckpoint_CF(const Reference< CPlayer > & player, SQInt32 world,
const Vector3 & pos, const Color4 & color, SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewCheckpoint(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius,
header, payload);
return _Core->NewCheckpoint(player.GetID(), world, pos.x, pos.y, pos.z,
color.r, color.g, color.b, color.a, radius, header, payload);
}
// ================================================================================================
bool Register_CCheckpoint(HSQUIRRELVM vm)
void Register_CCheckpoint(HSQUIRRELVM vm)
{
// Attempt to register the base reference type before the actual implementation
if (!Register_Reference< CCheckpoint >(vm, _SC("BaseCheckpoint")))
{
LogFtl("Unable to register the base class <BaseCheckpoint> for <CCheckpoint> type");
// Registration failed
return false;
}
// Typedef the base reference type for simplicity
typedef Reference< CCheckpoint > RefType;
// Output debugging information
LogDbg("Beginning registration of <CCheckpoint> type");
// Attempt to register the actual reference that implements all of the entity functionality
Sqrat::RootTable(vm).Bind(_SC("CCheckpoint"), Sqrat::DerivedClass< CCheckpoint, RefType >(vm, _SC("CCheckpoint"))
/* Constructors */
.Ctor()
.Ctor< SQInt32 >()
RootTable(vm).Bind(_SC("SqCheckpoint"),
Class< CCheckpoint, NoConstructor< CCheckpoint > >(vm, _SC("SqCheckpoint"))
/* Metamethods */
.Func(_SC("_cmp"), &CCheckpoint::Cmp)
.Func(_SC("_tostring"), &CCheckpoint::ToString)
/* Core Properties */
.Prop(_SC("ID"), &CCheckpoint::GetID)
.Prop(_SC("Tag"), &CCheckpoint::GetTag, &CCheckpoint::SetTag)
.Prop(_SC("Data"), &CCheckpoint::GetData, &CCheckpoint::SetData)
.Prop(_SC("MaxID"), &CCheckpoint::GetMaxID)
.Prop(_SC("Active"), &CCheckpoint::IsActive)
/* Core Functions */
.Func(_SC("Bind"), &CCheckpoint::BindEvent)
/* Core Overloads */
.Overload< bool (CCheckpoint::*)(void) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload< bool (CCheckpoint::*)(Int32) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload< bool (CCheckpoint::*)(Int32, Object &) >(_SC("Destroy"), &CCheckpoint::Destroy)
/* Properties */
.Prop(_SC("world"), &CCheckpoint::GetWorld, &CCheckpoint::SetWorld)
.Prop(_SC("color"), &CCheckpoint::GetColor, &CCheckpoint::SetColor)
.Prop(_SC("position"), &CCheckpoint::GetPosition, &CCheckpoint::SetPosition)
.Prop(_SC("radius"), &CCheckpoint::GetRadius, &CCheckpoint::SetRadius)
.Prop(_SC("owner"), &CCheckpoint::GetOwner)
.Prop(_SC("owner_id"), &CCheckpoint::GetOwnerID)
.Prop(_SC("World"), &CCheckpoint::GetWorld, &CCheckpoint::SetWorld)
.Prop(_SC("Color"), &CCheckpoint::GetColor, &CCheckpoint::SetColor)
.Prop(_SC("Pos"), &CCheckpoint::GetPosition, &CCheckpoint::SetPosition)
.Prop(_SC("Position"), &CCheckpoint::GetPosition, &CCheckpoint::SetPosition)
.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)
/* Functions */
.Func(_SC("streamed_for"), &CCheckpoint::IsStreamedFor)
.Func(_SC("set_color"), &CCheckpoint::SetColorEx)
.Func(_SC("set_position"), &CCheckpoint::SetPositionEx)
.Func(_SC("StreamedFor"), &CCheckpoint::IsStreamedFor)
.Func(_SC("SetColor"), &CCheckpoint::SetColorEx)
.Func(_SC("SetPos"), &CCheckpoint::SetPositionEx)
.Func(_SC("SetPosition"), &CCheckpoint::SetPositionEx)
);
// Output debugging information
LogDbg("Registration of <CCheckpoint> type was successful");
// Output debugging information
LogDbg("Beginning registration of <Checkpoint> functions");
// Register global functions related to this entity type
Sqrat::RootTable(vm)
/* Create BaseCheckpoint [P]rimitive [E]xtended [F]Full */
.Overload< RefType (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, Uint8, SQFloat) >
(_SC("CreateBaseCheckpoint_PEF"), &CreateBaseCheckpoint_PEF)
.Overload< RefType (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, Uint8, SQFloat, SQInt32, SqObj &) >
(_SC("CreateBaseCheckpoint_PEF"), &CreateBaseCheckpoint_PEF)
/* Create BaseCheckpoint [P]rimitive [C]ompact [F]ull */
.Overload< RefType (*)(SQInt32, SQInt32, const Vector3 &, const Color4 &, SQFloat) >
(_SC("CreateBaseCheckpoint_PCF"), &CreateBaseCheckpoint_PCF)
.Overload< RefType (*)(SQInt32, SQInt32, const Vector3 &, const Color4 &, SQFloat, SQInt32, SqObj &) >
(_SC("CreateBaseCheckpoint_PCF"), &CreateBaseCheckpoint_PCF)
/* Create BaseCheckpoint [E]xtended [F]Full */
.Overload< RefType (*)(const Reference< CPlayer > &, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, Uint8, SQFloat) >
(_SC("CreateBaseCheckpoint_EF"), &CreateBaseCheckpoint_EF)
.Overload< RefType (*)(const Reference< CPlayer > &, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, Uint8, SQFloat, SQInt32, SqObj &) >
(_SC("CreateBaseCheckpoint_EF"), &CreateBaseCheckpoint_EF)
/* Create BaseCheckpoint [C]ompact [F]ull */
.Overload< RefType (*)(const Reference< CPlayer > &, SQInt32, const Vector3 &, const Color4 &, SQFloat) >
(_SC("CreateBaseCheckpoint_CF"), &CreateBaseCheckpoint_CF)
.Overload< RefType (*)(const Reference< CPlayer > &, SQInt32, const Vector3 &, const Color4 &, SQFloat, SQInt32, SqObj &) >
(_SC("CreateBaseCheckpoint_CF"), &CreateBaseCheckpoint_CF)
/* Create CCheckpoint [P]rimitive [E]xtended [F]Full */
.Overload< CCheckpoint (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, Uint8, SQFloat) >
(_SC("CreateCheckpoint_PEF"), &CreateCheckpoint_PEF)
.Overload< CCheckpoint (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, Uint8, SQFloat, SQInt32, SqObj &) >
(_SC("CreateCheckpoint_PEF"), &CreateCheckpoint_PEF)
/* Create CCheckpoint [P]rimitive [C]ompact [F]ull */
.Overload< CCheckpoint (*)(SQInt32, SQInt32, const Vector3 &, const Color4 &, SQFloat) >
(_SC("CreateCheckpoint_PCF"), &CreateCheckpoint_PCF)
.Overload< CCheckpoint (*)(SQInt32, SQInt32, const Vector3 &, const Color4 &, SQFloat, SQInt32, SqObj &) >
(_SC("CreateCheckpoint_PCF"), &CreateCheckpoint_PCF)
/* Create CCheckpoint [E]xtended [F]Full */
.Overload< CCheckpoint (*)(const Reference< CPlayer > &, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, Uint8, SQFloat) >
(_SC("CreateCheckpoint_EF"), &CreateCheckpoint_EF)
.Overload< CCheckpoint (*)(const Reference< CPlayer > &, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, Uint8, SQFloat, SQInt32, SqObj &) >
(_SC("CreateCheckpoint_EF"), &CreateCheckpoint_EF)
/* Create CCheckpoint [C]ompact [F]ull */
.Overload< CCheckpoint (*)(const Reference< CPlayer > &, SQInt32, const Vector3 &, const Color4 &, SQFloat) >
(_SC("CreateCheckpoint_CF"), &CreateCheckpoint_CF)
.Overload< CCheckpoint (*)(const Reference< CPlayer > &, SQInt32, const Vector3 &, const Color4 &, SQFloat, SQInt32, SqObj &) >
(_SC("CreateCheckpoint_CF"), &CreateCheckpoint_CF);
// Output debugging information
LogDbg("Registration of <Checkpoint> functions was successful");
// Registration succeeded
return true;
RootTable(vm)
.Overload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateCheckpointEx"), &CreateCheckpointEx)
.Overload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
(_SC("CreateCheckpointEx"), &CreateCheckpointEx)
.Overload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color4 &, Float32) >
(_SC("CreateCheckpoint"), &CreateCheckpoint)
.Overload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color4 &, Float32, Int32, Object &) >
(_SC("CreateCheckpoint"), &CreateCheckpoint);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@@ -2,99 +2,164 @@
#define _ENTITY_CHECKPOINT_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced checkpoint instance.
* Manages Checkpoint instances.
*/
class CCheckpoint : public Reference< CCheckpoint >
class CCheckpoint
{
// --------------------------------------------------------------------------------------------
static Color4 s_Color4;
static Vector3 s_Vector3;
friend class Core;
private:
// --------------------------------------------------------------------------------------------
static SQUint32 s_ColorR, s_ColorG, s_ColorB, s_ColorA;
static Color4 s_Color4;
static Vector3 s_Vector3;
// --------------------------------------------------------------------------------------------
static Uint32 s_ColorR, s_ColorG, s_ColorB, s_ColorA;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_CHECKPOINT_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CCheckpoint(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CCheckpoint(const CCheckpoint &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CCheckpoint & operator = (const CCheckpoint &);
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
* Destructor.
*/
CCheckpoint(const Reference< CCheckpoint > & o);
~CCheckpoint();
/* --------------------------------------------------------------------------------------------
* See if the referenced checkpoint instance is streamed for the specified player.
* See whether this instance manages a valid entity.
*/
bool IsStreamedFor(const Reference< CPlayer > & player) const;
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid checkpoint reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced checkpoint instance exists.
* Used by the script engine to compare two instances of this type.
*/
SQInt32 GetWorld() const;
Int32 Cmp(const CCheckpoint & o) const;
/* --------------------------------------------------------------------------------------------
* Change the world in which the referenced checkpoint instance exists.
* Used by the script engine to convert an instance of this type to a string.
*/
void SetWorld(SQInt32 world) const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the referenced checkpoint instance.
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_CHECKPOINT_POOL; }
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr 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);
// --------------------------------------------------------------------------------------------
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
bool IsStreamedFor(CPlayer & player) const;
Int32 GetWorld() const;
void SetWorld(Int32 world) const;
const Color4 & GetColor() const;
/* --------------------------------------------------------------------------------------------
* Change the color of the referenced checkpoint instance.
*/
void SetColor(const Color4 & col) const;
/* --------------------------------------------------------------------------------------------
* Change the color of the referenced checkpoint instance.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the referenced checkpoint instance.
*/
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced checkpoint instance.
*/
void SetPosition(const Vector3 & pos) const;
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
Float32 GetRadius() const;
void SetRadius(Float32 radius) const;
Object & GetOwner() const;
Int32 GetOwnerID() const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced checkpoint instance.
*/
void SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const;
// --------------------------------------------------------------------------------------------
Float32 GetPosX() const;
Float32 GetPosY() const;
Float32 GetPosZ() const;
void SetPosX(Float32 x) const;
void SetPosY(Float32 y) const;
void SetPosZ(Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radius of the referenced checkpoint instance.
*/
SQFloat GetRadius() const;
/* --------------------------------------------------------------------------------------------
* Change the radius of the referenced checkpoint instance.
*/
void SetRadius(SQFloat radius) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner of the referenced checkpoint instance.
*/
Reference< CPlayer > GetOwner() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner identifier of the referenced checkpoint instance.
*/
SQInt32 GetOwnerID() const;
// --------------------------------------------------------------------------------------------
Uint32 GetColR() const;
Uint32 GetColG() const;
Uint32 GetColB() const;
Uint32 GetColA() const;
void SetColR(Uint32 r) const;
void SetColG(Uint32 g) const;
void SetColB(Uint32 b) const;
void SetColA(Uint32 a) const;
};
} // Namespace:: SqMod

View File

@@ -0,0 +1,383 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Forcefield.hpp"
#include "Entity/Player.hpp"
#include "Base/Color3.hpp"
#include "Base/Vector3.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;
// ------------------------------------------------------------------------------------------------
SQChar CForcefield::s_StrID[SQMOD_FORCEFIELD_POOL][8];
// ------------------------------------------------------------------------------------------------
const Int32 CForcefield::Max = SQMOD_FORCEFIELD_POOL;
// ------------------------------------------------------------------------------------------------
CForcefield::CForcefield(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_FORCEFIELD_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
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;
}
CSStr CForcefield::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_FORCEFIELD_POOL) ? s_StrID[m_ID] : _SC("-1");
}
// ------------------------------------------------------------------------------------------------
CSStr CForcefield::GetTag() const
{
return m_Tag.c_str();
}
void CForcefield::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
Object & CForcefield::GetData()
{
if (Validate())
return m_Data;
return NullObject();
}
void CForcefield::SetData(Object & data)
{
if (Validate())
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CForcefield::Destroy(Int32 header, Object & payload)
{
return _Core->DelForcefield(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CForcefield::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
Function & event = _Core->GetForcefieldEvent(m_ID, evid);
if (func.IsNull())
event.Release();
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
bool CForcefield::IsStreamedFor(CPlayer & player) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
return _Func->IsSphereStreamedForPlayer(m_ID, player.GetID());
return false;
}
Int32 CForcefield::GetWorld() const
{
if (Validate())
return _Func->GetSphereWorld(m_ID);
return -1;
}
void CForcefield::SetWorld(Int32 world) const
{
if (Validate())
_Func->SetSphereWorld(m_ID, world);
}
const Color3 & CForcefield::GetColor() const
{
s_Color3.Clear();
if (Validate())
{
_Func->GetSphereColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB);
s_Color3.Set(s_ColorR, s_ColorG, s_ColorB);
}
return s_Color3;
}
void CForcefield::SetColor(const Color3 & col) const
{
if (Validate())
_Func->SetSphereColor(m_ID, col.r, col.g, col.b);
}
void CForcefield::SetColorEx(Uint8 r, Uint8 g, Uint8 b) const
{
if (Validate())
_Func->SetSphereColor(m_ID, r, g, b);
}
const Vector3 & CForcefield::GetPosition() const
{
s_Vector3.Clear();
if (Validate())
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
return s_Vector3;
}
void CForcefield::SetPosition(const Vector3 & pos) const
{
if (Validate())
_Func->SetSpherePos(m_ID, pos.x, pos.y, pos.z);
}
void CForcefield::SetPositionEx(Float32 x, Float32 y, Float32 z) const
{
if (Validate())
_Func->SetSpherePos(m_ID, x, y, z);
}
Float32 CForcefield::GetRadius() const
{
if (Validate())
_Func->GetSphereRadius(m_ID);
return 0;
}
void CForcefield::SetRadius(Float32 radius) const
{
if (Validate())
_Func->SetSphereRadius(m_ID, radius);
}
Object & CForcefield::GetOwner() const
{
if (Validate())
return _Core->GetPlayer(_Func->GetSphereOwner(m_ID)).mObj;
return NullObject();
}
Int32 CForcefield::GetOwnerID() const
{
if (Validate())
_Func->GetSphereOwner(m_ID);
return -1;
}
// ------------------------------------------------------------------------------------------------
Float32 CForcefield::GetPosX() const
{
s_Vector3.x = 0;
if (Validate())
_Func->GetSpherePos(m_ID, &s_Vector3.x, NULL, NULL);
return s_Vector3.x;
}
Float32 CForcefield::GetPosY() const
{
s_Vector3.y = 0;
if (Validate())
_Func->GetSpherePos(m_ID, NULL, &s_Vector3.y, NULL);
return s_Vector3.y;
}
Float32 CForcefield::GetPosZ() const
{
s_Vector3.z = 0;
if (Validate())
_Func->GetSpherePos(m_ID, NULL, NULL, &s_Vector3.z);
return s_Vector3.z;
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetPosX(Float32 x) const
{
if (Validate())
{
_Func->GetSpherePos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
_Func->SetSpherePos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
}
void CForcefield::SetPosY(Float32 y) const
{
if (Validate())
{
_Func->GetSpherePos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
_Func->SetSpherePos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
}
void CForcefield::SetPosZ(Float32 z) const
{
if (Validate())
{
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
_Func->SetSpherePos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
}
// ------------------------------------------------------------------------------------------------
Uint32 CForcefield::GetColR() const
{
s_ColorR = 0;
if (Validate())
_Func->GetSphereColor(m_ID, &s_ColorR, NULL, NULL);
return s_ColorR;
}
Uint32 CForcefield::GetColG() const
{
s_ColorG = 0;
if (Validate())
_Func->GetSphereColor(m_ID, NULL, &s_ColorG, NULL);
return s_ColorG;
}
Uint32 CForcefield::GetColB() const
{
s_ColorB = 0;
if (Validate())
_Func->GetSphereColor(m_ID, NULL, NULL, &s_ColorB);
return s_ColorB;
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetColR(Uint32 r) const
{
if (Validate())
{
_Func->GetSphereColor(m_ID, NULL, &s_ColorG, &s_ColorB);
_Func->SetSphereColor(m_ID, r, s_ColorG, s_ColorB);
}
}
void CForcefield::SetColG(Uint32 g) const
{
if (Validate())
{
_Func->GetSphereColor(m_ID, &s_ColorR, NULL, &s_ColorB);
_Func->SetSphereColor(m_ID, s_ColorR, g, s_ColorB);
}
}
void CForcefield::SetColB(Uint32 b) const
{
if (Validate())
{
_Func->GetSphereColor(m_ID, &s_ColorB, &s_ColorG, NULL);
_Func->SetSphereColor(m_ID, s_ColorB, s_ColorG, b);
}
}
// ------------------------------------------------------------------------------------------------
static Object & CreateForcefieldEx(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 & CreateForcefieldEx(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 & CreateForcefield(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 & CreateForcefield(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);
}
// ================================================================================================
void Register_CForcefield(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqForcefield"),
Class< CForcefield, NoConstructor< CForcefield > >(vm, _SC("SqForcefield"))
/* Metamethods */
.Func(_SC("_cmp"), &CForcefield::Cmp)
.Func(_SC("_tostring"), &CForcefield::ToString)
/* Core Properties */
.Prop(_SC("ID"), &CForcefield::GetID)
.Prop(_SC("Tag"), &CForcefield::GetTag, &CForcefield::SetTag)
.Prop(_SC("Data"), &CForcefield::GetData, &CForcefield::SetData)
.Prop(_SC("MaxID"), &CForcefield::GetMaxID)
.Prop(_SC("Active"), &CForcefield::IsActive)
/* Core Functions */
.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)
/* Functions */
.Func(_SC("StreamedFor"), &CForcefield::IsStreamedFor)
.Func(_SC("SetColor"), &CForcefield::SetColorEx)
.Func(_SC("SetPos"), &CForcefield::SetPositionEx)
.Func(_SC("SetPosition"), &CForcefield::SetPositionEx)
);
RootTable(vm)
.Overload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateForcefieldEx"), &CreateForcefieldEx)
.Overload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
(_SC("CreateForcefieldEx"), &CreateForcefieldEx)
.Overload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color3 &, Float32) >
(_SC("CreateForcefield"), &CreateForcefield)
.Overload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color3 &, Float32, Int32, Object &) >
(_SC("CreateForcefield"), &CreateForcefield);
}
} // Namespace:: SqMod

View File

@@ -0,0 +1,166 @@
#ifndef _ENTITY_FORCEFIELD_HPP_
#define _ENTITY_FORCEFIELD_HPP_
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Forcefield instances.
*/
class CForcefield
{
// --------------------------------------------------------------------------------------------
friend class Core;
private:
// --------------------------------------------------------------------------------------------
static Color3 s_Color3;
static Vector3 s_Vector3;
// --------------------------------------------------------------------------------------------
static Uint32 s_ColorR, s_ColorG, s_ColorB;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_FORCEFIELD_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CForcefield(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CForcefield(const CForcefield &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CForcefield & operator = (const CForcefield &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~CForcefield();
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
*/
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid forcefield reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* 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.
*/
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_FORCEFIELD_POOL; }
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr 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);
// --------------------------------------------------------------------------------------------
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
bool IsStreamedFor(CPlayer & player) const;
Int32 GetWorld() const;
void SetWorld(Int32 world) const;
const Color3 & GetColor() const;
void SetColor(const Color3 & col) const;
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
const Vector3 & GetPosition() const;
void SetPosition(const Vector3 & pos) const;
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
Float32 GetRadius() const;
void SetRadius(Float32 radius) const;
Object & GetOwner() const;
Int32 GetOwnerID() const;
// --------------------------------------------------------------------------------------------
Float32 GetPosX() const;
Float32 GetPosY() const;
Float32 GetPosZ() const;
void SetPosX(Float32 x) const;
void SetPosY(Float32 y) const;
void SetPosZ(Float32 z) const;
// --------------------------------------------------------------------------------------------
Uint32 GetColR() const;
Uint32 GetColG() const;
Uint32 GetColB() const;
void SetColR(Uint32 r) const;
void SetColG(Uint32 g) const;
void SetColB(Uint32 b) const;
};
} // Namespace:: SqMod
#endif // _ENTITY_FORCEFIELD_HPP_

View File

@@ -1,197 +1,184 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Keybind.hpp"
#include "Core.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
CKeybind::CKeybind(const Reference< CKeybind > & o)
: Reference(o)
SQChar CKeybind::s_StrID[SQMOD_KEYBIND_POOL][8];
// ------------------------------------------------------------------------------------------------
const Int32 CKeybind::Max = SQMOD_KEYBIND_POOL;
// ------------------------------------------------------------------------------------------------
CKeybind::CKeybind(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_KEYBIND_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
SQInt32 CKeybind::GetPrimary() const
CKeybind::~CKeybind()
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Primary;
}
else
{
BadRef("@primary", "get primary keycode");
}
return SQMOD_UNKNOWN;
/* ... */
}
// ------------------------------------------------------------------------------------------------
SQInt32 CKeybind::GetSecondary() const
Int32 CKeybind::Cmp(const CKeybind & o) const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Secondary;
}
if (m_ID == o.m_ID)
return 0;
else if (m_ID > o.m_ID)
return 1;
else
{
BadRef("@secondary", "get secondary keycode");
}
return -1;
}
return SQMOD_UNKNOWN;
CSStr CKeybind::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_KEYBIND_POOL) ? s_StrID[m_ID] : _SC("-1");
}
// ------------------------------------------------------------------------------------------------
SQInt32 CKeybind::GetAlternative() const
CSStr CKeybind::GetTag() const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Alternative;
}
else
{
BadRef("@alternative", "get alternative keycode");
}
return m_Tag.c_str();
}
return SQMOD_UNKNOWN;
void CKeybind::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
Object & CKeybind::GetData()
{
if (Validate())
return m_Data;
return NullObject();
}
void CKeybind::SetData(Object & data)
{
if (Validate())
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CKeybind::Destroy(Int32 header, Object & payload)
{
return _Core->DelKeybind(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CKeybind::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
Function & event = _Core->GetKeybindEvent(m_ID, evid);
if (func.IsNull())
event.Release();
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
Int32 CKeybind::GetPrimary() const
{
if (Validate())
return _Core->GetKeybind(m_ID).mPrimary;
return -1;
}
Int32 CKeybind::GetSecondary() const
{
if (Validate())
return _Core->GetKeybind(m_ID).mSecondary;
return -1;
}
Int32 CKeybind::GetAlternative() const
{
if (Validate())
return _Core->GetKeybind(m_ID).mAlternative;
return -1;
}
bool CKeybind::IsRelease() const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Release;
}
else
{
BadRef("@is_release", "see whether it reacts on release");
}
if (Validate())
return _Core->GetKeybind(m_ID).mRelease;
return false;
}
// ------------------------------------------------------------------------------------------------
Reference< CKeybind > CreateBaseKeybind_ES(bool release,
SQInt32 primary, SQInt32 secondary, SQInt32 alternative)
static Object & CreateKeybindEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
Int32 alternative)
{
return _Core->NewKeybind(SQMOD_UNKNOWN, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullData());
return _Core->NewKeybind(slot, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullObject());
}
Reference< CKeybind > CreateBaseKeybind_ES(bool release,
SQInt32 primary, SQInt32 secondary, SQInt32 alternative,
SQInt32 header, SqObj & payload)
static Object & CreateKeybindEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
Int32 alternative, Int32 header, Object & payload)
{
return _Core->NewKeybind(SQMOD_UNKNOWN, release, primary, secondary, alternative,
header, payload);
return _Core->NewKeybind(slot, release, primary, secondary, alternative, header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CKeybind > CreateBaseKeybind_EF(SQInt32 slot, bool release,
SQInt32 primary, SQInt32 secondary, SQInt32 alternative)
static Object & CreateKeybind(bool release, Int32 primary, Int32 secondary, Int32 alternative)
{
return _Core->NewKeybind(slot, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullData());
return _Core->NewKeybind(-1, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullObject());
}
Reference< CKeybind > CreateBaseKeybind_EF(SQInt32 slot, bool release,
SQInt32 primary, SQInt32 secondary, SQInt32 alternative,
SQInt32 header, SqObj & payload)
static Object & CreateKeybind(bool release, Int32 primary, Int32 secondary, Int32 alternative,
Int32 header, Object & payload)
{
return _Core->NewKeybind(slot, release, primary, secondary, alternative,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CKeybind CreateKeybind_ES(bool release,
SQInt32 primary, SQInt32 secondary, SQInt32 alternative)
{
return _Core->NewKeybind(SQMOD_UNKNOWN, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullData());
}
CKeybind CreateKeybind_ES(bool release,
SQInt32 primary, SQInt32 secondary, SQInt32 alternative,
SQInt32 header, SqObj & payload)
{
return _Core->NewKeybind(SQMOD_UNKNOWN, release, primary, secondary, alternative,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CKeybind CreateKeybind_EF(SQInt32 slot, bool release,
SQInt32 primary, SQInt32 secondary, SQInt32 alternative)
{
return _Core->NewKeybind(slot, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullData());
}
CKeybind CreateKeybind_EF(SQInt32 slot, bool release,
SQInt32 primary, SQInt32 secondary, SQInt32 alternative,
SQInt32 header, SqObj & payload)
{
return _Core->NewKeybind(slot, release, primary, secondary, alternative,
header, payload);
return _Core->NewKeybind(-1, release, primary, secondary, alternative, header, payload);
}
// ================================================================================================
bool Register_CKeybind(HSQUIRRELVM vm)
void Register_CKeybind(HSQUIRRELVM vm)
{
// Attempt to register the base reference type before the actual implementation
if (!Register_Reference< CKeybind >(vm, _SC("BaseKeybind")))
{
LogFtl("Unable to register the base class <BaseKeybind> for <CKeybind> type");
// Registration failed
return false;
}
// Typedef the base reference type for simplicity
typedef Reference< CKeybind > RefType;
// Output debugging information
LogDbg("Beginning registration of <CKeybind> type");
// Attempt to register the actual reference that implements all of the entity functionality
Sqrat::RootTable(vm).Bind(_SC("CKeybind"), Sqrat::DerivedClass< CKeybind, RefType >(vm, _SC("CKeybind"))
/* Constructors */
.Ctor()
.Ctor< SQInt32 >()
RootTable(vm).Bind(_SC("SqKeybind"),
Class< CKeybind, NoConstructor< CKeybind > >(vm, _SC("SqKeybind"))
/* Metamethods */
.Func(_SC("_cmp"), &CKeybind::Cmp)
.Func(_SC("_tostring"), &CKeybind::ToString)
/* Core Properties */
.Prop(_SC("ID"), &CKeybind::GetID)
.Prop(_SC("Tag"), &CKeybind::GetTag, &CKeybind::SetTag)
.Prop(_SC("Data"), &CKeybind::GetData, &CKeybind::SetData)
.Prop(_SC("MaxID"), &CKeybind::GetMaxID)
.Prop(_SC("Active"), &CKeybind::IsActive)
/* Core Functions */
.Func(_SC("Bind"), &CKeybind::BindEvent)
/* Core Overloads */
.Overload< bool (CKeybind::*)(void) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload< bool (CKeybind::*)(Int32) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload< bool (CKeybind::*)(Int32, Object &) >(_SC("Destroy"), &CKeybind::Destroy)
/* Properties */
.Prop(_SC("primary"), &CKeybind::GetPrimary)
.Prop(_SC("secondary"), &CKeybind::GetSecondary)
.Prop(_SC("alternative"), &CKeybind::GetAlternative)
.Prop(_SC("is_release"), &CKeybind::IsRelease)
.Prop(_SC("Primary"), &CKeybind::GetPrimary)
.Prop(_SC("Secondary"), &CKeybind::GetSecondary)
.Prop(_SC("Alternative"), &CKeybind::GetAlternative)
.Prop(_SC("Release"), &CKeybind::IsRelease)
);
// Output debugging information
LogDbg("Registration of <CKeybind> type was successful");
// Output debugging information
LogDbg("Beginning registration of <Keybind> functions");
// Register global functions related to this entity type
Sqrat::RootTable(vm)
/* Create BaseKeybind [E]xtended [S]ubstitute */
.Overload< RefType (*)(bool, SQInt32, SQInt32, SQInt32) >
(_SC("CreateBaseKeybind_ES"), &CreateBaseKeybind_ES)
.Overload< RefType (*)(bool, SQInt32, SQInt32, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBaseKeybind_ES"), &CreateBaseKeybind_ES)
/* Create BaseKeybind [E]xtended [F]Full */
.Overload< RefType (*)(SQInt32, bool, SQInt32, SQInt32, SQInt32) >
(_SC("CreateBaseKeybind_EF"), &CreateBaseKeybind_EF)
.Overload< RefType (*)(SQInt32, bool, SQInt32, SQInt32, SQInt32, SQInt32, SqObj &) >
(_SC("CreateBaseKeybind_EF"), &CreateBaseKeybind_EF)
/* Create CKeybind [E]xtended [S]ubstitute */
.Overload< CKeybind (*)(bool, SQInt32, SQInt32, SQInt32) >
(_SC("CreateKeybind_ES"), &CreateKeybind_ES)
.Overload< CKeybind (*)(bool, SQInt32, SQInt32, SQInt32, SQInt32, SqObj &) >
(_SC("CreateKeybind_ES"), &CreateKeybind_ES)
/* Create CKeybind [E]xtended [F]Full */
.Overload< CKeybind (*)(SQInt32, bool, SQInt32, SQInt32, SQInt32) >
(_SC("CreateKeybind_EF"), &CreateKeybind_EF)
.Overload< CKeybind (*)(SQInt32, bool, SQInt32, SQInt32, SQInt32, SQInt32, SqObj &) >
(_SC("CreateKeybind_EF"), &CreateKeybind_EF);
// Output debugging information
LogDbg("Registration of <Keybind> functions was successful");
// Registration succeeded
return true;
RootTable(vm)
.Overload< Object & (*)(Int32, bool, Int32, Int32, Int32) >
(_SC("CreateKeybindEx"), &CreateKeybindEx)
.Overload< Object & (*)(Int32, bool, Int32, Int32, Int32, Int32, Object &) >
(_SC("CreateKeybindEx"), &CreateKeybindEx)
.Overload< Object & (*)(bool, Int32, Int32, Int32) >
(_SC("CreateKeybind"), &CreateKeybind)
.Overload< Object & (*)(bool, Int32, Int32, Int32, Int32, Object &) >
(_SC("CreateKeybind"), &CreateKeybind);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@@ -2,46 +2,130 @@
#define _ENTITY_KEYBIND_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced keybind instance.
* Manages Keybind instances.
*/
class CKeybind : public Reference< CKeybind >
class CKeybind
{
// --------------------------------------------------------------------------------------------
friend class Core;
private:
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_KEYBIND_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CKeybind(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CKeybind(const CKeybind &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CKeybind & operator = (const CKeybind &);
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
* Destructor.
*/
CKeybind(const Reference< CKeybind > & o);
~CKeybind();
/* --------------------------------------------------------------------------------------------
* Retrieve the primary key code of the referenced keybind instance.
* See whether this instance manages a valid entity.
*/
SQInt32 GetPrimary() const;
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid keybind reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the secondary key code of the referenced keybind instance.
* Used by the script engine to compare two instances of this type.
*/
SQInt32 GetSecondary() const;
Int32 Cmp(const CKeybind & o) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alternative key code of the referenced keybind instance.
* Used by the script engine to convert an instance of this type to a string.
*/
SQInt32 GetAlternative() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced keybind instance reacts to key press events.
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_KEYBIND_POOL; }
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr 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);
// --------------------------------------------------------------------------------------------
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
Int32 GetPrimary() const;
Int32 GetSecondary() const;
Int32 GetAlternative() const;
bool IsRelease() const;
};

File diff suppressed because it is too large Load Diff

View File

@@ -2,239 +2,176 @@
#define _ENTITY_OBJECT_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced object instance.
* Manages Object instances.
*/
class CObject : public Reference< CObject >
class CObject
{
// --------------------------------------------------------------------------------------------
static CModel s_Model;
friend class Core;
private:
// --------------------------------------------------------------------------------------------
static Vector3 s_Vector3;
static Quaternion s_Quaternion;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_OBJECT_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CObject(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CObject(const CObject &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CObject & operator = (const CObject &);
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
* Destructor.
*/
CObject(const Reference< CObject > & o);
~CObject();
/* --------------------------------------------------------------------------------------------
* See if the referenced object instance is streamed for the specified player.
* See whether this instance manages a valid entity.
*/
bool IsStreamedFor(const Reference< CPlayer > & player) const;
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid object reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the model of the referenced object instance.
* Used by the script engine to compare two instances of this type.
*/
const CModel & GetModel() const;
Int32 Cmp(const CObject & o) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the model identifier of the referenced object instance.
* Used by the script engine to convert an instance of this type to a string.
*/
SQInt32 GetModelID() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced object instance exists.
* Retrieve the identifier of the entity managed by this instance.
*/
SQInt32 GetWorld() const;
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Change the world in which the referenced object instance exists.
* Retrieve the maximum possible identifier to an entity of this type.
*/
void SetWorld(SQInt32 world) const;
Int32 GetMaxID() const { return SQMOD_OBJECT_POOL; }
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the referenced object instance.
* Check whether this instance manages a valid entity.
*/
SQInt32 GetAlpha() const;
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Change the alpha of the referenced object instance.
* Retrieve the associated user tag.
*/
void SetAlpha(SQInt32 alpha) const;
CSStr GetTag() const;
/* --------------------------------------------------------------------------------------------
* Change the alpha of the referenced object instance over the specified time.
* Modify the associated user tag.
*/
void SetAlphaEx(SQInt32 alpha, SQInt32 time) const;
void SetTag(CSStr tag);
/* --------------------------------------------------------------------------------------------
* Move the referenced object instance to the specified position instantly.
* Retrieve the associated user data.
*/
void MoveToPr(const Vector3 & pos) const;
Object & GetData();
/* --------------------------------------------------------------------------------------------
* Move the referenced object instance to the specified position over the specified time.
* Modify the associated user data.
*/
void MoveTo(const Vector3 & pos, SQInt32 time) const;
void SetData(Object & data);
/* --------------------------------------------------------------------------------------------
* Move the referenced object instance to the specified position instantly.
*/
void MoveToEx(SQFloat x, SQFloat y, SQFloat z) const;
// --------------------------------------------------------------------------------------------
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
/* --------------------------------------------------------------------------------------------
* Move the referenced object instance to the specified position over the specified time.
*/
void MoveToEx(SQFloat x, SQFloat y, SQFloat z, SQInt32 time) const;
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Move the referenced object instance by the specified position instantly.
*/
void MoveByPr(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Move the referenced object instance by the specified position over the specified time.
*/
void MoveBy(const Vector3 & pos, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Move the referenced object instance by the specified position instantly.
*/
void MoveByEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Move the referenced object instance by the specified position over the specified time.
*/
void MoveByEx(SQFloat x, SQFloat y, SQFloat z, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the referenced object instance.
*/
// --------------------------------------------------------------------------------------------
bool IsStreamedFor(CPlayer & player) const;
Int32 GetModel() const;
Int32 GetWorld() const;
void SetWorld(Int32 world) const;
Int32 GetAlpha() const;
void SetAlpha(Int32 alpha) const;
void SetAlphaEx(Int32 alpha, Int32 time) const;
void MoveTo(const Vector3 & pos, Int32 time) const;
void MoveToEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
void MoveBy(const Vector3 & pos, Int32 time) const;
void MoveByEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
const Vector3 & GetPosition();
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced object instance.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced object instance.
*/
void SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance to the specified rotation instantly.
*/
void RotateToPr(const Quaternion & rot) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance to the specified rotation over the specified time.
*/
void RotateTo(const Quaternion & rot, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance to the specified rotation instantly.
*/
void RotateToEx(SQFloat x, SQFloat y, SQFloat z, SQFloat w) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance to the specified rotation over the specified time.
*/
void RotateToEx(SQFloat x, SQFloat y, SQFloat z, SQFloat w, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance to the specified euler rotation instantly.
*/
void RotateToEulerPr(const Vector3 & rot) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance to the specified euler rotation over the specified time.
*/
void RotateToEuler(const Vector3 & rot, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance to the specified euler rotation instantly.
*/
void RotateToEulerEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance to the specified euler rotation over the specified time.
*/
void RotateToEulerEx(SQFloat x, SQFloat y, SQFloat z, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance by the specified rotation instantly.
*/
void RotateByPr(const Quaternion & rot) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance by the specified rotation over the specified time.
*/
void RotateBy(const Quaternion & rot, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance by the specified rotation instantly.
*/
void RotateByEx(SQFloat x, SQFloat y, SQFloat z, SQFloat w) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance by the specified rotation over the specified time.
*/
void RotateByEx(SQFloat x, SQFloat y, SQFloat z, SQFloat w, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance by the specified euler rotation instantly.
*/
void RotateByEulerPr(const Vector3 & rot) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance by the specified euler rotation over the specified time.
*/
void RotateByEuler(const Vector3 & rot, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance by the specified euler rotation instantly.
*/
void RotateByEulerEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Rotate the referenced object instance by the specified euler rotation over the specified time.
*/
void RotateByEulerEx(SQFloat x, SQFloat y, SQFloat z, SQInt32 time) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation of the referenced object instance.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
void RotateTo(const Quaternion & rot, Int32 time) const;
void RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const;
void RotateToEuler(const Vector3 & rot, Int32 time) const;
void RotateToEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
void RotateBy(const Quaternion & rot, Int32 time) const;
void RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const;
void RotateByEuler(const Vector3 & rot, Int32 time) const;
void RotateByEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
const Quaternion & GetRotation();
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation of the referenced object instance.
*/
const Vector3 & GetRotationEuler();
/* --------------------------------------------------------------------------------------------
* See whether the referenced object instance reports gunshots.
*/
bool GetShotReport() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced object instance reports gunshots.
*/
void SetShotReport(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced object instance reports player bumps.
*/
bool GetBumpReport() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced object instance reports player bumps.
*/
void SetBumpReport(bool toggle) const;
// --------------------------------------------------------------------------------------------
Float32 GetPosX() const;
Float32 GetPosY() const;
Float32 GetPosZ() const;
void SetPosX(Float32 x) const;
void SetPosY(Float32 y) const;
void SetPosZ(Float32 z) const;
// --------------------------------------------------------------------------------------------
Float32 GetRotX() const;
Float32 GetRotY() const;
Float32 GetRotZ() const;
Float32 GetRotW() const;
Float32 GetERotX() const;
Float32 GetERotY() const;
Float32 GetERotZ() const;
};
} // Namespace:: SqMod

View File

@@ -1,480 +1,332 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Pickup.hpp"
#include "Misc/Model.hpp"
#include "Entity/Player.hpp"
#include "Base/Vector3.hpp"
#include "Core.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
CModel CPickup::s_Model;
Vector3 CPickup::s_Vector3;
// ------------------------------------------------------------------------------------------------
Vector3 CPickup::s_Vector3;
SQChar CPickup::s_StrID[SQMOD_PICKUP_POOL][8];
// ------------------------------------------------------------------------------------------------
CPickup::CPickup(const Reference< CPickup > & o)
: Reference(o)
const Int32 CPickup::Max = SQMOD_PICKUP_POOL;
// ------------------------------------------------------------------------------------------------
CPickup::CPickup(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_PICKUP_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
bool CPickup::IsStreamedFor(const Reference< CPlayer > & player) const
CPickup::~CPickup()
{
if (VALID_ENTITY(m_ID) && player)
{
return _Func->IsPickupStreamedForPlayer(m_ID, player);
}
else if (!player)
{
BadArg("streamed_for", "see whether is streamed for player", _SCI32(player));
}
else
{
BadRef("streamed_for", "see whether is streamed for player");
}
/* ... */
}
// ------------------------------------------------------------------------------------------------
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;
}
CSStr CPickup::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_PICKUP_POOL) ? s_StrID[m_ID] : _SC("-1");
}
// ------------------------------------------------------------------------------------------------
CSStr CPickup::GetTag() const
{
return m_Tag.c_str();
}
void CPickup::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
Object & CPickup::GetData()
{
if (Validate())
return m_Data;
return NullObject();
}
void CPickup::SetData(Object & data)
{
if (Validate())
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CPickup::Destroy(Int32 header, Object & payload)
{
return _Core->DelPickup(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CPickup::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
Function & event = _Core->GetPickupEvent(m_ID, evid);
if (func.IsNull())
event.Release();
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
bool CPickup::IsStreamedFor(CPlayer & player) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
return _Func->IsPickupStreamedForPlayer(m_ID, player.GetID());
return false;
}
// ------------------------------------------------------------------------------------------------
const CModel & CPickup::GetModel() const
Int32 CPickup::GetModel() const
{
// Clear any previous model
s_Model.SetID(SQMOD_UNKNOWN);
// Attempt to retrieve the model
if (VALID_ENTITY(m_ID))
{
s_Model.SetID(_Func->PickupGetModel(m_ID));
}
else
{
BadRef("@model", "get model");
}
// Return the model that could be retrieved
return s_Model;
}
// ------------------------------------------------------------------------------------------------
SQInt32 CPickup::GetModelID() const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
return _Func->PickupGetModel(m_ID);
}
else
{
BadRef("@model", "get model id");
}
return SQMOD_UNKNOWN;
return -1;
}
// ------------------------------------------------------------------------------------------------
SQInt32 CPickup::GetWorld() const
Int32 CPickup::GetWorld() const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
return _Func->GetPickupWorld(m_ID);
}
else
{
BadRef("@world", "get world");
}
return SQMOD_UNKNOWN;
return -1;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetWorld(SQInt32 world) const
void CPickup::SetWorld(Int32 world) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->SetPickupWorld(m_ID, world);
}
else
{
BadRef("@world", "set world");
}
}
// ------------------------------------------------------------------------------------------------
SQInt32 CPickup::GetAlpha() const
Int32 CPickup::GetAlpha() const
{
if (VALID_ENTITY(m_ID))
{
return _Func->PickupGetAlpha(m_ID);
}
else
{
BadRef("@alpha", "get alpha");
}
return SQMOD_UNKNOWN;
if (Validate())
return _Func->GetVehicleModel(m_ID);
return -1;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAlpha(SQInt32 alpha) const
void CPickup::SetAlpha(Int32 alpha) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->PickupSetAlpha(m_ID, alpha);
}
else
{
BadRef("@alpha", "set alpha");
}
}
// ------------------------------------------------------------------------------------------------
bool CPickup::GetAutomatic() const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
return _Func->PickupIsAutomatic(m_ID);
}
else
{
BadRef("@automatic", "see if is automatic");
}
return false;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAutomatic(bool toggle) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->PickupSetAutomatic(m_ID, toggle);
}
else
{
BadRef("@automatic", "set whether is automatic");
}
}
// ------------------------------------------------------------------------------------------------
SQInt32 CPickup::GetAutoTimer() const
Int32 CPickup::GetAutoTimer() const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
return _Func->GetPickupAutoTimer(m_ID);
}
else
{
BadRef("@auto_timer", "get auto timer");
}
return SQMOD_UNKNOWN;
return -1;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAutoTimer(SQInt32 timer) const
void CPickup::SetAutoTimer(Int32 timer) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->SetPickupAutoTimer(m_ID, timer);
}
else
{
BadRef("@auto_timer", "set auto timer");
}
}
// ------------------------------------------------------------------------------------------------
void CPickup::Refresh() const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->PickupRefresh(m_ID);
}
else
{
BadRef("refresh", "refresh pickup");
}
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CPickup::GetPosition()
{
// Clear any previous position
s_Vector3.Clear();
// Attempt to retrieve the position
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
}
else
{
BadRef("@position", "get position");
}
// Return the position that could be retrieved
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPosition(const Vector3 & pos) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->PickupSetPos(m_ID, pos.x, pos.y, pos.z);
}
else
{
BadRef("@position", "set position");
}
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const
void CPickup::SetPositionEx(Float32 x, Float32 y, Float32 z) const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
_Func->PickupSetPos(m_ID, x, y, z);
}
else
{
BadRef("set_position", "set position");
}
}
// ------------------------------------------------------------------------------------------------
SQInt32 CPickup::GetQuantity() const
Int32 CPickup::GetQuantity() const
{
if (VALID_ENTITY(m_ID))
{
if (Validate())
return _Func->PickupGetQuantity(m_ID);
}
else
return -1;
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPosX() const
{
s_Vector3.x = 0;
if (Validate())
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, NULL);
return s_Vector3.x;
}
Float32 CPickup::GetPosY() const
{
s_Vector3.y = 0;
if (Validate())
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, NULL);
return s_Vector3.y;
}
Float32 CPickup::GetPosZ() const
{
s_Vector3.z = 0;
if (Validate())
_Func->PickupGetPos(m_ID, NULL, NULL, &s_Vector3.z);
return s_Vector3.z;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPosX(Float32 x) const
{
if (Validate())
{
BadRef("@quantity", "get quantity");
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
_Func->PickupSetPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
}
return SQMOD_UNKNOWN;
void CPickup::SetPosY(Float32 y) const
{
if (Validate())
{
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
_Func->PickupSetPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
}
void CPickup::SetPosZ(Float32 z) const
{
if (Validate())
{
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
_Func->PickupSetPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
}
// ------------------------------------------------------------------------------------------------
Reference< CPickup > CreateBasePickup_PEF(SQInt32 model, SQInt32 world, SQInt32 quantity,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 alpha, bool automatic)
static Object & CreatePickupEx(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,
SQMOD_CREATE_DEFAULT, NullData());
SQMOD_CREATE_DEFAULT, NullObject());
}
Reference< CPickup > CreateBasePickup_PEF(SQInt32 model, SQInt32 world, SQInt32 quantity,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 alpha, bool automatic,
SQInt32 header, SqObj & payload)
static Object & CreatePickupEx(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->NewPickup(model, world, quantity, x, y, z, alpha, automatic, header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CPickup > CreateBasePickup_PCF(SQInt32 model, SQInt32 world, SQInt32 quantity,
const Vector3 & pos, SQInt32 alpha, bool automatic)
static Object & CreatePickup(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,
SQMOD_CREATE_DEFAULT, NullData());
SQMOD_CREATE_DEFAULT, NullObject());
}
Reference< CPickup > CreateBasePickup_PCF(SQInt32 model, SQInt32 world, SQInt32 quantity,
const Vector3 & pos, SQInt32 alpha, bool automatic,
SQInt32 header, SqObj & payload)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CPickup > CreateBasePickup_EF(const CModel & model, SQInt32 world, SQInt32 quantity,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullData());
}
Reference< CPickup > CreateBasePickup_EF(const CModel & model, SQInt32 world, SQInt32 quantity,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 alpha, bool automatic,
SQInt32 header, SqObj & payload)
{
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CPickup > CreateBasePickup_CF(const CModel & model, SQInt32 world, SQInt32 quantity,
const Vector3 & pos, SQInt32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullData());
}
Reference< CPickup > CreateBasePickup_CF(const CModel & model, SQInt32 world, SQInt32 quantity,
const Vector3 & pos, SQInt32 alpha, bool automatic,
SQInt32 header, SqObj & payload)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CPickup CreatePickup_PEF(SQInt32 model, SQInt32 world, SQInt32 quantity,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullData());
}
CPickup CreatePickup_PEF(SQInt32 model, SQInt32 world, SQInt32 quantity,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 alpha, bool automatic,
SQInt32 header, SqObj & payload)
{
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CPickup CreatePickup_PCF(SQInt32 model, SQInt32 world, SQInt32 quantity,
const Vector3 & pos, SQInt32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullData());
}
CPickup CreatePickup_PCF(SQInt32 model, SQInt32 world, SQInt32 quantity,
const Vector3 & pos, SQInt32 alpha, bool automatic,
SQInt32 header, SqObj & payload)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CPickup CreatePickup_EF(const CModel & model, SQInt32 world, SQInt32 quantity,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullData());
}
CPickup CreatePickup_EF(const CModel & model, SQInt32 world, SQInt32 quantity,
SQFloat x, SQFloat y, SQFloat z,
SQInt32 alpha, bool automatic,
SQInt32 header, SqObj & payload)
{
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CPickup CreatePickup_CF(const CModel & model, SQInt32 world, SQInt32 quantity,
const Vector3 & pos, SQInt32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullData());
}
CPickup CreatePickup_CF(const CModel & model, SQInt32 world, SQInt32 quantity,
const Vector3 & pos, SQInt32 alpha, bool automatic,
SQInt32 header, SqObj & payload)
static Object & CreatePickup(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,
header, payload);
}
// ================================================================================================
bool Register_CPickup(HSQUIRRELVM vm)
void Register_CPickup(HSQUIRRELVM vm)
{
// Attempt to register the base reference type before the actual implementation
if (!Register_Reference< CPickup >(vm, _SC("BasePickup")))
{
LogFtl("Unable to register the base class <BasePickup> for <CPickup> type");
// Registration failed
return false;
}
// Typedef the base reference type for simplicity
typedef Reference< CPickup > RefType;
// Output debugging information
LogDbg("Beginning registration of <CPickup> type");
// Attempt to register the actual reference that implements all of the entity functionality
Sqrat::RootTable(vm).Bind(_SC("CPickup"), Sqrat::DerivedClass< CPickup, RefType >(vm, _SC("CPickup"))
/* Constructors */
.Ctor()
.Ctor< SQInt32 >()
RootTable(vm).Bind(_SC("SqPickup"),
Class< CPickup, NoConstructor< CPickup > >(vm, _SC("SqPickup"))
/* Metamethods */
.Func(_SC("_cmp"), &CPickup::Cmp)
.Func(_SC("_tostring"), &CPickup::ToString)
/* Core Properties */
.Prop(_SC("ID"), &CPickup::GetID)
.Prop(_SC("Tag"), &CPickup::GetTag, &CPickup::SetTag)
.Prop(_SC("Data"), &CPickup::GetData, &CPickup::SetData)
.Prop(_SC("MaxID"), &CPickup::GetMaxID)
.Prop(_SC("Active"), &CPickup::IsActive)
/* Core Functions */
.Func(_SC("Bind"), &CPickup::BindEvent)
/* Core Overloads */
.Overload< bool (CPickup::*)(void) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32, Object &) >(_SC("Destroy"), &CPickup::Destroy)
/* Properties */
.Prop(_SC("model"), &CPickup::GetModel)
.Prop(_SC("model_id"), &CPickup::GetModelID)
.Prop(_SC("world"), &CPickup::GetWorld, &CPickup::SetWorld)
.Prop(_SC("alpha"), &CPickup::GetAlpha, &CPickup::SetAlpha)
.Prop(_SC("automatic"), &CPickup::GetAutomatic, &CPickup::SetAutomatic)
.Prop(_SC("auto_timer"), &CPickup::GetAutoTimer, &CPickup::SetAutoTimer)
.Prop(_SC("position"), &CPickup::GetPosition, &CPickup::SetPosition)
.Prop(_SC("quantity"), &CPickup::GetQuantity)
.Prop(_SC("Model"), &CPickup::GetModel)
.Prop(_SC("World"), &CPickup::GetWorld, &CPickup::SetWorld)
.Prop(_SC("Alpha"), &CPickup::GetAlpha, &CPickup::SetAlpha)
.Prop(_SC("Auto"), &CPickup::GetAutomatic, &CPickup::SetAutomatic)
.Prop(_SC("Automatic"), &CPickup::GetAutomatic, &CPickup::SetAutomatic)
.Prop(_SC("Timer"), &CPickup::GetAutoTimer, &CPickup::SetAutoTimer)
.Prop(_SC("Autotimer"), &CPickup::GetAutoTimer, &CPickup::SetAutoTimer)
.Prop(_SC("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)
/* Functions */
.Func(_SC("streamed_for"), &CPickup::IsStreamedFor)
.Func(_SC("refresh"), &CPickup::Refresh)
.Func(_SC("set_position"), &CPickup::SetPositionEx)
.Func(_SC("StreamedFor"), &CPickup::IsStreamedFor)
.Func(_SC("Refresh"), &CPickup::Refresh)
.Func(_SC("SetPos"), &CPickup::SetPositionEx)
.Func(_SC("SetPosition"), &CPickup::SetPositionEx)
);
// Output debugging information
LogDbg("Registration of <CPickup> type was successful");
// Output debugging information
LogDbg("Beginning registration of <Pickup> functions");
// Register global functions related to this entity type
Sqrat::RootTable(vm)
/* Create BasePickup [P]rimitive [E]xtended [F]Full */
.Overload< RefType (*)(SQInt32, SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, bool) >
(_SC("CreateBasePickup_PEF"), &CreateBasePickup_PEF)
.Overload< RefType (*)(SQInt32, SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, bool, SQInt32, SqObj &) >
(_SC("CreateBasePickup_PEF"), &CreateBasePickup_PEF)
/* Create BasePickup [P]rimitive [C]ompact [F]ull */
.Overload< RefType (*)(SQInt32, SQInt32, SQInt32, const Vector3 &, SQInt32, bool) >
(_SC("CreateBasePickup_PCF"), &CreateBasePickup_PCF)
.Overload< RefType (*)(SQInt32, SQInt32, SQInt32, const Vector3 &, SQInt32, bool, SQInt32, SqObj &) >
(_SC("CreateBasePickup_PCF"), &CreateBasePickup_PCF)
/* Create BasePickup [E]xtended [F]Full */
.Overload< RefType (*)(const CModel &, SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, bool) >
(_SC("CreateBasePickup_EF"), &CreateBasePickup_EF)
.Overload< RefType (*)(const CModel &, SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, bool, SQInt32, SqObj &) >
(_SC("CreateBasePickup_EF"), &CreateBasePickup_EF)
/* Create BasePickup [C]ompact [F]ull */
.Overload< RefType (*)(const CModel &, SQInt32, SQInt32, const Vector3 &, SQInt32, bool) >
(_SC("CreateBasePickup_CF"), &CreateBasePickup_CF)
.Overload< RefType (*)(const CModel &, SQInt32, SQInt32, const Vector3 &, SQInt32, bool, SQInt32, SqObj &) >
(_SC("CreateBasePickup_CF"), &CreateBasePickup_CF)
/* Create CPickup [P]rimitive [E]xtended [F]Full */
.Overload< CPickup (*)(SQInt32, SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, bool) >
(_SC("CreatePickup_PEF"), &CreatePickup_PEF)
.Overload< CPickup (*)(SQInt32, SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, bool, SQInt32, SqObj &) >
(_SC("CreatePickup_PEF"), &CreatePickup_PEF)
/* Create CPickup [P]rimitive [C]ompact [F]ull */
.Overload< CPickup (*)(SQInt32, SQInt32, SQInt32, const Vector3 &, SQInt32, bool) >
(_SC("CreatePickup_PCF"), &CreatePickup_PCF)
.Overload< CPickup (*)(SQInt32, SQInt32, SQInt32, const Vector3 &, SQInt32, bool, SQInt32, SqObj &) >
(_SC("CreatePickup_PCF"), &CreatePickup_PCF)
/* Create CPickup [E]xtended [F]Full */
.Overload< CPickup (*)(const CModel &, SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, bool) >
(_SC("CreatePickup_EF"), &CreatePickup_EF)
.Overload< CPickup (*)(const CModel &, SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, SQInt32, bool, SQInt32, SqObj &) >
(_SC("CreatePickup_EF"), &CreatePickup_EF)
/* Create CPickup [C]ompact [F]ull */
.Overload< CPickup (*)(const CModel &, SQInt32, SQInt32, const Vector3 &, SQInt32, bool) >
(_SC("CreatePickup_CF"), &CreatePickup_CF)
.Overload< CPickup (*)(const CModel &, SQInt32, SQInt32, const Vector3 &, SQInt32, bool, SQInt32, SqObj &) >
(_SC("CreatePickup_CF"), &CreatePickup_CF);
// Output debugging information
LogDbg("Registration of <Pickup> functions was successful");
// Registration succeeded
return true;
RootTable(vm)
.Overload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
(_SC("CreatePickupEx"), &CreatePickupEx)
.Overload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool, Int32, Object &) >
(_SC("CreatePickupEx"), &CreatePickupEx)
.Overload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool) >
(_SC("CreatePickup"), &CreatePickup)
.Overload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool, Int32, Object &) >
(_SC("CreatePickup"), &CreatePickup);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@@ -2,113 +2,153 @@
#define _ENTITY_PICKUP_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced pickup instance.
* Manages Pickup instances.
*/
class CPickup : public Reference< CPickup >
class CPickup
{
// --------------------------------------------------------------------------------------------
static CModel s_Model;
friend class Core;
private:
// --------------------------------------------------------------------------------------------
static Vector3 s_Vector3;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_PICKUP_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CPickup(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CPickup(const CPickup &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CPickup & operator = (const CPickup &);
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
* Destructor.
*/
CPickup(const Reference< CPickup > & o);
~CPickup();
/* --------------------------------------------------------------------------------------------
* See if the referenced pickup instance is streamed for the specified player.
* See whether this instance manages a valid entity.
*/
bool IsStreamedFor(const Reference< CPlayer > & player) const;
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid pickup reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the model of the referenced pickup instance.
* Used by the script engine to compare two instances of this type.
*/
const CModel & GetModel() const;
Int32 Cmp(const CPickup & o) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the model identifier of the referenced pickup instance.
* Used by the script engine to convert an instance of this type to a string.
*/
SQInt32 GetModelID() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced pickup instance exists.
* Retrieve the identifier of the entity managed by this instance.
*/
SQInt32 GetWorld() const;
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Change the world in which the referenced pickup instance exists.
* Retrieve the maximum possible identifier to an entity of this type.
*/
void SetWorld(SQInt32 world) const;
Int32 GetMaxID() const { return SQMOD_PICKUP_POOL; }
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the referenced pickup instance.
* Check whether this instance manages a valid entity.
*/
SQInt32 GetAlpha() const;
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Change the alpha of the referenced pickup instance.
* Retrieve the associated user tag.
*/
void SetAlpha(SQInt32 alpha) const;
CSStr GetTag() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced pickup instance is automatic.
* 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);
// --------------------------------------------------------------------------------------------
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
bool IsStreamedFor(CPlayer & player) const;
Int32 GetModel() const;
Int32 GetWorld() const;
void SetWorld(Int32 world) const;
Int32 GetAlpha() const;
void SetAlpha(Int32 alpha) const;
bool GetAutomatic() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced pickup instance is automatic.
*/
void SetAutomatic(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the automatic timer of the referenced pickup instance.
*/
SQInt32 GetAutoTimer() const;
/* --------------------------------------------------------------------------------------------
* Change the automatic timer of the referenced pickup instance.
*/
void SetAutoTimer(SQInt32 timer) const;
/* --------------------------------------------------------------------------------------------
* Refresh the referenced pickup instance.
*/
Int32 GetAutoTimer() const;
void SetAutoTimer(Int32 timer) const;
void Refresh() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the referenced pickup instance.
*/
const Vector3 & GetPosition();
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced pickup instance.
*/
void SetPosition(const Vector3 & pos) const;
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
Int32 GetQuantity() const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced pickup instance.
*/
void SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the quantity of the referenced pickup instance.
*/
SQInt32 GetQuantity() const;
// --------------------------------------------------------------------------------------------
Float32 GetPosX() const;
Float32 GetPosY() const;
Float32 GetPosZ() const;
void SetPosX(Float32 x) const;
void SetPosY(Float32 y) const;
void SetPosZ(Float32 z) const;
};
} // Namespace:: SqMod

File diff suppressed because it is too large Load Diff

View File

@@ -2,738 +2,262 @@
#define _ENTITY_PLAYER_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced player instance.
* Manages Player instances.
*/
class CPlayer : public Reference< CPlayer >
class CPlayer
{
// --------------------------------------------------------------------------------------------
static CSkin s_Skin;
static CWeapon s_Weapon;
friend class Core;
private:
// --------------------------------------------------------------------------------------------
static Color3 s_Color3;
static Vector3 s_Vector3;
static Color3 s_Color3;
static Vector3 s_Vector3;
// --------------------------------------------------------------------------------------------
static SQChar s_Buffer[MAX_PLAYER_TEMPORARY_BUFFER];
static SQChar s_Buffer[SQMOD_PLAYER_TMP_BUFFER];
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_PLAYER_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CPlayer(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CPlayer(const CPlayer &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CPlayer & operator = (const CPlayer &);
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
* Destructor.
*/
CPlayer(const Reference< CPlayer > & o);
~CPlayer();
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance has administrator privileges.
* See whether this instance manages a valid entity.
*/
SQInt32 GetLevel() const;
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid player reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance has administrator privileges.
* Used by the script engine to compare two instances of this type.
*/
void SetLevel(SQInt32 toggle) const;
Int32 Cmp(const CPlayer & o) const;
/* --------------------------------------------------------------------------------------------
* Get whether referenced player instance uses the global or local message prefixes.
* Used by the script engine to convert an instance of this type to a string.
*/
bool GetLocalPrefixes() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Set whether referenced player instance uses the global or local message prefixes.
* Retrieve the identifier of the entity managed by this instance.
*/
void SetLocalPrefixes(bool toggle) const;
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Get whether referenced player instance uses the global or local message color.
* Retrieve the maximum possible identifier to an entity of this type.
*/
bool GetLocalMessageColor() const;
Int32 GetMaxID() const { return SQMOD_PLAYER_POOL; }
/* --------------------------------------------------------------------------------------------
* Set whether referenced player instance uses the global or local message color.
* Check whether this instance manages a valid entity.
*/
void SetLocalMessageColor(bool toggle) const;
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Get whether referenced player instance uses the global or local announcement style.
* Retrieve the associated user tag.
*/
bool GetLocalAnnounceStyle() const;
CSStr GetTag() const;
/* --------------------------------------------------------------------------------------------
* Set whether referenced player instance uses the global or local announcement style.
* Modify the associated user tag.
*/
void SetLocalAnnounceStyle(bool toggle) const;
void SetTag(CSStr tag);
/* --------------------------------------------------------------------------------------------
* Retrieve the local message prefix at the specified index for the referenced player instance.
* Retrieve the associated user data.
*/
const SQChar * GetMessagePrefix(SQUint32 index) const;
Object & GetData();
/* --------------------------------------------------------------------------------------------
* Change the local message prefix at the specified index for the referenced player instance.
* Modify the associated user data.
*/
void SetMessagePrefix(SQUint32 index, const SQChar * prefix) const;
void SetData(Object & data);
/* --------------------------------------------------------------------------------------------
* Retrieve the local message color for the referenced player instance.
*/
SQUint32 GetMessageColor() const;
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Change the local message color for the referenced player instance.
*/
void SetMessageColor(SQUint32 color) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the local announcement style for the referenced player instance.
*/
SQInt32 GetAnnounceStyle() const;
/* --------------------------------------------------------------------------------------------
* Change the local announcement style for the referenced player instance.
*/
void SetAnnounceStyle(SQInt32 style) const;
/* --------------------------------------------------------------------------------------------
* See if the referenced player instance is streamed for the specified player.
*/
bool IsStreamedFor(const Reference < CPlayer > & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the class of the referenced player instance.
*/
SQInt32 GetClass() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance has administrator privileges.
*/
// --------------------------------------------------------------------------------------------
bool IsStreamedFor(CPlayer & player) const;
Int32 GetClass() const;
bool GetAdmin() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance has administrator privileges.
*/
void SetAdmin(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the ip address of the referenced player instance.
*/
const SQChar * GetIP() const;
/* --------------------------------------------------------------------------------------------
* Kick the referenced player instance from the server.
*/
CSStr GetIP() const;
void Kick() const;
/* --------------------------------------------------------------------------------------------
* Ban the referenced player instance from the server.
*/
void Ban() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance is connected.
*/
bool IsConnected() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance is spawned.
*/
bool IsSpawned() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the key of the referenced player instance.
*/
SQUint32 GetKey() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced player instance exists.
*/
SQInt32 GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Change the world in which the referenced player instance exists.
*/
void SetWorld(SQInt32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the secondary world of the referenced player instance.
*/
SQInt32 GetSecWorld() const;
/* --------------------------------------------------------------------------------------------
* Change the secondary world of the referenced player instance.
*/
void SetSecWorld(SQInt32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the unique world of the referenced player instance.
*/
SQInt32 GetUniqueWorld() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance is compatible with the specified world.
*/
bool IsWorldCompatible(SQInt32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current state of the referenced player instance.
*/
SQInt32 GetState() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the nick name of the referenced player instance.
*/
const SQChar * GetName() const;
/* --------------------------------------------------------------------------------------------
* Change the nick name of the referenced player instance.
*/
void SetName(const SQChar * name) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the team of the referenced player instance.
*/
SQInt32 GetTeam() const;
/* --------------------------------------------------------------------------------------------
* Change the team of the referenced player instance.
*/
void SetTeam(SQInt32 team) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the skin of the referenced player instance.
*/
const CSkin & GetSkin() const;
/* --------------------------------------------------------------------------------------------
* Change the skin of the referenced player instance.
*/
void SetSkin(const CSkin & skin) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the skin identifier of the referenced player instance.
*/
SQInt32 GetSkinID() const;
/* --------------------------------------------------------------------------------------------
* Change the skin identifier of the referenced player instance.
*/
void SetSkinID(SQInt32 skin) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the referenced player instance.
*/
Uint32 GetKey() const;
Int32 GetWorld() const;
void SetWorld(Int32 world) const;
Int32 GetSecWorld() const;
void SetSecWorld(Int32 world) const;
Int32 GetUniqueWorld() const;
bool IsWorldCompatible(Int32 world) const;
CSStr GetName() const;
void SetName(CSStr name) const;
Int32 GetTeam() const;
void SetTeam(Int32 team) const;
Int32 GetSkin() const;
void SetSkin(Int32 skin) const;
const Color3 & GetColor() const;
/* --------------------------------------------------------------------------------------------
* Change the color of the referenced player instance.
*/
void SetColor(const Color3 & color) const;
/* --------------------------------------------------------------------------------------------
* Change the color of the referenced player instance.
*/
void SetColorEx(uint8 r, uint8 g, uint8 b) const;
/* --------------------------------------------------------------------------------------------
* Force the referenced player instance to spawn in the game.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
void ForceSpawn() const;
/* --------------------------------------------------------------------------------------------
* Force the referenced player instance to select a class.
*/
void ForceSelect() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the money amount of the referenced player instance.
*/
SQInt32 GetMoney() const;
/* --------------------------------------------------------------------------------------------
* Change the money amount of the referenced player instance.
*/
void SetMoney(SQInt32 amount) const;
/* --------------------------------------------------------------------------------------------
* Give a certain amount of money to the referenced player instance.
*/
void GiveMoney(SQInt32 amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the score of the referenced player instance.
*/
SQInt32 GetScore() const;
/* --------------------------------------------------------------------------------------------
* Change the score of the referenced player instance.
*/
void SetScore(SQInt32 score) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the connection latency of the referenced player instance.
*/
SQInt32 GetPing() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the frames per second of the referenced player instance.
*/
SQFloat GetFPS() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance is typing.
*/
Int32 GetMoney() const;
void SetMoney(Int32 amount) const;
void GiveMoney(Int32 amount) const;
Int32 GetScore() const;
void SetScore(Int32 score) const;
Int32 GetPing() const;
Float32 GetFPS() const;
bool IsTyping() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the unique user identifier of the referenced player instance.
*/
const SQChar * GetUID() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the unique user identifier version 2 of the referenced player instance.
*/
const SQChar * GetUID2() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current health of the referenced player instance.
*/
SQFloat GetHealth() const;
/* --------------------------------------------------------------------------------------------
* Change the health of the referenced player instance.
*/
void SetHealth(SQFloat amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current health of the referenced player instance.
*/
SQFloat GetArmour() const;
/* --------------------------------------------------------------------------------------------
* Change the health of the referenced player instance.
*/
void SetArmour(SQFloat amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the immunity flags of the referenced player instance.
*/
SQInt32 GetImmunity() const;
/* --------------------------------------------------------------------------------------------
* Change the immunity flags of the referenced player instance.
*/
void SetImmunity(SQInt32 flags) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the referenced player instance.
*/
CSStr GetUID() const;
CSStr GetUID2() const;
Float32 GetHealth() const;
void SetHealth(Float32 amount) const;
Float32 GetArmor() const;
void SetArmor(Float32 amount) const;
Int32 GetImmunity() const;
void SetImmunity(Int32 flags) const;
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced player instance.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced player instance.
*/
void SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the speed of the referenced player instance.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
const Vector3 & GetSpeed() const;
/* --------------------------------------------------------------------------------------------
* Change the speed of the referenced player instance.
*/
void SetSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the speed of the referenced player instance.
*/
void SetSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Change the speed of the referenced player instance.
*/
void SetSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the speed of the referenced player instance.
*/
void AddSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the heading angle of the referenced player instance.
*/
SQFloat GetHeading() const;
/* --------------------------------------------------------------------------------------------
* Change the heading angle of the referenced player instance.
*/
void SetHeading(SQFloat angle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the referenced player instance.
*/
SQInt32 GetAlpha() const;
/* --------------------------------------------------------------------------------------------
* Change the alpha of the referenced player instance.
*/
void SetAlpha(SQInt32 alpha, SQInt32 fade) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle status of the referenced player instance.
*/
SQInt32 GetVehicleStatus() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the occupied vehicle slot by the referenced player instance.
*/
SQInt32 GetOccupiedSlot() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle in which the referenced player instance is embarked.
*/
Reference < CVehicle > GetVehicle() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle identifier in which the referenced player instance is embarked.
*/
SQInt32 GetVehicleID() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance can be controlled.
*/
void AddSpeedEx(Float32 x, Float32 y, Float32 z) const;
Float32 GetHeading() const;
void SetHeading(Float32 angle) const;
Int32 GetAlpha() const;
void SetAlpha(Int32 alpha, Int32 fade) const;
Int32 GetVehicleStatus() const;
Int32 GetOccupiedSlot() const;
Object & GetVehicle() const;
Int32 GetVehicleID() const;
bool GetControllable() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance can be controlled.
*/
void SetControllable(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance can driveby.
*/
bool GetDriveby() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance can driveby.
*/
void SetDriveby(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance has white scanlines.
*/
bool GetWhiteScanlines() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance has white scanlines.
*/
void SetWhiteScanlines(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance has green scanlines.
*/
bool GetGreenScanlines() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance has green scanlines.
*/
void SetGreenScanlines(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance has widescreen.
*/
bool GetWidescreen() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance has widescreen.
*/
void SetWidescreen(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance displays markers.
*/
bool GetShowMarkers() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance displays markers.
*/
void SetShowMarkers(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance has attacking privileges.
*/
bool GetAttackPriv() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance has attacking privileges.
*/
void SetAttackPriv(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance has markers.
*/
bool GetHasMarker() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance has markers.
*/
void SetHasMarker(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance has chat tags.
*/
bool GetChatTags() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance has chat tags.
*/
void SetChatTags(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance is under drunk effects.
*/
bool GetDrunkEffects() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance is under drunk effects.
*/
void SetDrunkEffects(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the weapon of the referenced player instance.
*/
const CWeapon & GetWeapon() const;
/* --------------------------------------------------------------------------------------------
* Change the weapon of the referenced player instance.
*/
void SetWeapon(const CWeapon & wep) const;
/* --------------------------------------------------------------------------------------------
* Change the weapon of the referenced player instance.
*/
void SetWeaponEx(const CWeapon & wep, SQInt32 ammo) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the weapon identifier of the referenced player instance.
*/
SQInt32 GetWeaponID() const;
/* --------------------------------------------------------------------------------------------
* Change the weapon of the referenced player instance.
*/
void SetWeaponID(SQInt32 wep) const;
/* --------------------------------------------------------------------------------------------
* Change the weapon of the referenced player instance.
*/
void SetWeaponIDEx(SQInt32 wep, SQInt32 ammo) const;
/* --------------------------------------------------------------------------------------------
* Give a weapon of the referenced player instance.
*/
void GiveWeapon(const CWeapon & wep) const;
/* --------------------------------------------------------------------------------------------
* Give a weapon of the referenced player instance.
*/
void GiveWeaponEx(const CWeapon & wep, SQInt32 ammo) const;
/* --------------------------------------------------------------------------------------------
* Give a weapon of the referenced player instance.
*/
void GiveWeaponIDEx(SQInt32 wep, SQInt32 ammo) const;
/* --------------------------------------------------------------------------------------------
* Strip the referenced player instance of all weapons.
*/
Int32 GetWeapon() const;
void SetWeapon(Int32 wep, Int32 ammo) const;
void GiveWeapon(Int32 wep, Int32 ammo) const;
void StripWeapons() const;
/* --------------------------------------------------------------------------------------------
* Change the camera position of the referenced player instance.
*/
void SetCameraPosition(const Vector3 & pos, const Vector3 & aim) const;
/* --------------------------------------------------------------------------------------------
* Change the camera position of the referenced player instance.
*/
void SetCameraPosition(SQFloat xp, SQFloat yp, SQFloat zp, SQFloat xa, SQFloat ya, SQFloat za) const;
/* --------------------------------------------------------------------------------------------
* Restore the camera position of the referenced player instance.
*/
void SetCameraPosition(Float32 xp, Float32 yp, Float32 zp, Float32 xa, Float32 ya, Float32 za) const;
void RestoreCamera() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance has camera locked.
*/
bool IsCameraLocked() const;
/* --------------------------------------------------------------------------------------------
* Change the animation of the referenced player instance.
*/
void SetAnimation(SQInt32 group, SQInt32 anim) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the wanted level of the referenced player instance.
*/
SQInt32 GetWantedLevel() const;
/* --------------------------------------------------------------------------------------------
* Change the wanted level of the referenced player instance.
*/
void SetWantedLevel(SQInt32 level) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle that the referenced player instance is standing on.
*/
Reference < CVehicle > StandingOnVehicle() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the object that the referenced player instance is standing on.
*/
Reference < CObject > StandingOnObject() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance is away.
*/
void SetAnimation(Int32 group, Int32 anim) const;
Int32 GetWantedLevel() const;
void SetWantedLevel(Int32 level) const;
Object & StandingOnVehicle() const;
Object & StandingOnObject() const;
bool IsAway() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the player that the referenced player instance is spectating.
*/
Reference < CPlayer > GetSpectator() const;
/* --------------------------------------------------------------------------------------------
* Set the referenced player instance to spectate the specified player instance.
*/
void SetSpectator(const Reference < CPlayer > & target) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the player that the referenced player instance is spectating.
*/
Reference < CPlayer > Spectating() const;
/* --------------------------------------------------------------------------------------------
* Set the referenced player instance to spectate the specified player instance.
*/
void Spectate(const Reference < CPlayer > & target) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance is burning.
*/
Object & GetSpectator() const;
void SetSpectator(CPlayer & target) const;
bool IsBurning() const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced player instance is crouched.
*/
bool IsCrouched() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current action of the referenced player instance.
*/
SQInt32 GetAction() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the game keys of the referenced player instance.
*/
SQInt32 GetGameKeys() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the aim position of the referenced player instance.
*/
Int32 GetState() const;
Int32 GetAction() const;
Int32 GetGameKeys() const;
const Vector3 & GetAimPos() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the aim direction of the referenced player instance.
*/
const Vector3 & GetAimDir() const;
/* --------------------------------------------------------------------------------------------
* Embark the referenced player instance into the specified vehicle instance.
*/
void Embark(const Reference < CVehicle > & vehicle) const;
/* --------------------------------------------------------------------------------------------
* Embark the referenced player instance into the specified vehicle instance.
*/
void Embark(const Reference < CVehicle > & vehicle, SQInt32 slot, bool allocate, bool warp) const;
/* --------------------------------------------------------------------------------------------
* Disembark the referenced player instance from the currently embarked vehicle instance.
*/
void Embark(CVehicle & vehicle) const;
void Embark(CVehicle & vehicle, Int32 slot, bool allocate, bool warp) const;
void Disembark() const;
bool Redirect(CSStr ip, Uint32 port, CSStr nick, CSStr pass, CSStr user);
Int32 GetAuthority() const;
void SetAuthority(Int32 level) const;
CSStr GetMessagePrefix(Uint32 index) const;
void SetMessagePrefix(Uint32 index, CSStr prefix) const;
Uint32 GetMessageColor() const;
void SetMessageColor(Uint32 color) const;
Int32 GetAnnounceStyle() const;
void SetAnnounceStyle(Int32 style) const;
/* --------------------------------------------------------------------------------------------
* Redirect the referenced player instance to the specified server.
*/
bool Redirect(const SQChar * ip, SQUint32 port, const SQChar * nick, \
const SQChar * pass, const SQChar * user);
// --------------------------------------------------------------------------------------------
Float32 GetPosX() const;
Float32 GetPosY() const;
Float32 GetPosZ() const;
void SetPosX(Float32 x) const;
void SetPosY(Float32 y) const;
void SetPosZ(Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Send a normal colored message to the referenced player instance.
*/
// --------------------------------------------------------------------------------------------
static SQInteger Msg(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a normal prefixed message to the referenced player instance.
*/
static SQInteger MsgP(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a normal colored message to the referenced player instance.
*/
static SQInteger MsgEx(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a normal message to the referenced player instance.
*/
static SQInteger Message(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send an announcement message to the referenced player instance.
*/
static SQInteger Announce(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a styled announcement message to the referenced player instance.
*/
static SQInteger AnnounceEx(HSQUIRRELVM vm);
protected:
/* --------------------------------------------------------------------------------------------
* Fetch the message prefix that a certain player instance must use.
*/
static const SQChar * FetchMessagePrefix(SQInt32 player, SQUint32 index);
/* --------------------------------------------------------------------------------------------
* Fetch the message color that a certain player instance must use.
*/
static SQUint32 FetchMessageColor(SQInt32 player);
/* --------------------------------------------------------------------------------------------
* Fetch the announce type that a certain player instance must use.
*/
static SQInteger FetchAnnounceStyle(SQInt32 player);
};
} // Namespace:: SqMod
#endif // _ENTITY_PLAYER_HPP_
#endif // _ENTITY_PLAYER_HPP_

View File

@@ -1,446 +0,0 @@
#include "Entity/Sphere.hpp"
#include "Base/Color3.hpp"
#include "Core.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
Color3 CSphere::s_Color3;
Vector3 CSphere::s_Vector3;
// ------------------------------------------------------------------------------------------------
SQUint32 CSphere::s_ColorR;
SQUint32 CSphere::s_ColorG;
SQUint32 CSphere::s_ColorB;
// ------------------------------------------------------------------------------------------------
CSphere::CSphere(const Reference< CSphere > & o)
: Reference(o)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
bool CSphere::IsStreamedFor(const Reference< CPlayer > & player) const
{
if (VALID_ENTITY(m_ID) && player)
{
return _Func->IsSphereStreamedForPlayer(m_ID, player);
}
else if (!player)
{
BadArg("streamed_for", "see whether is streamed for player", _SCI32(player));
}
else
{
BadRef("streamed_for", "see whether is streamed for player");
}
return false;
}
// ------------------------------------------------------------------------------------------------
SQInt32 CSphere::GetWorld() const
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetSphereWorld(m_ID);
}
else
{
BadRef("@world", "get world");
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetWorld(SQInt32 world) const
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSphereWorld(m_ID, world);
}
else
{
BadRef("@world", "set world");
}
}
// ------------------------------------------------------------------------------------------------
const Color3 & CSphere::GetColor() const
{
// Clear any previous color
s_Color3.Clear();
// Attempt to retrieve the color
if (VALID_ENTITY(m_ID))
{
_Func->GetSphereColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB);
s_Color3.Set(s_ColorR, s_ColorG, s_ColorB);
}
else
{
BadRef("@color", "get color");
}
// Return the color that could be retrieved
return s_Color3;
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetColor(const Color3 & col) const
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSphereColor(m_ID, col.r, col.g, col.b);
}
else
{
BadRef("@color", "set color");
}
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetColorEx(Uint8 r, Uint8 g, Uint8 b) const
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSphereColor(m_ID, r, g, b);
}
else
{
BadRef("set_color", "set color");
}
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CSphere::GetPosition() const
{
// Clear any previous position
s_Vector3.Clear();
// Attempt to retrieve the position
if (VALID_ENTITY(m_ID))
{
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
}
else
{
BadRef("@position", "get position");
}
// Return the position that could be retrieved
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetPosition(const Vector3 & pos) const
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSpherePos(m_ID, pos.x, pos.y, pos.z);
}
else
{
BadRef("@position", "set position");
}
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSpherePos(m_ID, x, y, z);
}
else
{
BadRef("set_position", "set position");
}
}
// ------------------------------------------------------------------------------------------------
SQFloat CSphere::GetRadius() const
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetSphereRadius(m_ID);
}
else
{
BadRef("@radius", "get radius");
}
return 0.0;
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetRadius(SQFloat radius) const
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSphereRadius(m_ID, radius);
}
else
{
BadRef("@radius", "set radius");
}
}
// ------------------------------------------------------------------------------------------------
Reference< CPlayer > CSphere::GetOwner() const
{
if (VALID_ENTITY(m_ID))
{
return Reference< CPlayer >(_Func->GetSphereOwner(m_ID));
}
else
{
BadRef("@owner", "get owner");
}
return Reference< CPlayer >();
}
// ------------------------------------------------------------------------------------------------
SQInt32 CSphere::GetOwnerID() const
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetSphereOwner(m_ID);
}
else
{
BadRef("@owner_id", "get owner id");
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
Reference< CSphere > CreateBaseSphere_PEF(SQInt32 player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b,
SQFloat radius)
{
return _Core->NewSphere(player, world, x, y, z, r, g, b, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
Reference< CSphere > CreateBaseSphere_PEF(SQInt32 player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b,
SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewSphere(player, world, x, y, z, r, g, b, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CSphere > CreateBaseSphere_PCF(SQInt32 player, SQInt32 world,
const Vector3 & pos, const Color3 & color, SQFloat radius)
{
return _Core->NewSphere(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
Reference< CSphere > CreateBaseSphere_PCF(SQInt32 player, SQInt32 world,
const Vector3 & pos, const Color3 & color, SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewSphere(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CSphere > CreateBaseSphere_EF(const Reference< CPlayer > & player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b,
SQFloat radius)
{
return _Core->NewSphere(player, world, x, y, z, r, g, b, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
Reference< CSphere > CreateBaseSphere_EF(const Reference< CPlayer > & player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b,
SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewSphere(player, world, x, y, z, r, g, b, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CSphere > CreateBaseSphere_CF(const Reference< CPlayer > & player, SQInt32 world,
const Vector3 & pos, const Color3 & color, SQFloat radius)
{
return _Core->NewSphere(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
Reference< CSphere > CreateBaseSphere_CF(const Reference< CPlayer > & player, SQInt32 world,
const Vector3 & pos, const Color3 & color, SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewSphere(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CSphere CreateSphere_PEF(SQInt32 player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b,
SQFloat radius)
{
return _Core->NewSphere(player, world, x, y, z, r, g, b, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
CSphere CreateSphere_PEF(SQInt32 player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b,
SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewSphere(player, world, x, y, z, r, g, b, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CSphere CreateSphere_PCF(SQInt32 player, SQInt32 world,
const Vector3 & pos, const Color3 & color, SQFloat radius)
{
return _Core->NewSphere(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
CSphere CreateSphere_PCF(SQInt32 player, SQInt32 world,
const Vector3 & pos, const Color3 & color, SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewSphere(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CSphere CreateSphere_EF(const Reference< CPlayer > & player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b,
SQFloat radius)
{
return _Core->NewSphere(player, world, x, y, z, r, g, b, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
CSphere CreateSphere_EF(const Reference< CPlayer > & player, SQInt32 world,
SQFloat x, SQFloat y, SQFloat z,
Uint8 r, Uint8 g, Uint8 b,
SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewSphere(player, world, x, y, z, r, g, b, radius,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CSphere CreateSphere_CF(const Reference< CPlayer > & player, SQInt32 world,
const Vector3 & pos, const Color3 & color, SQFloat radius)
{
return _Core->NewSphere(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
SQMOD_CREATE_DEFAULT, NullData());
}
CSphere CreateSphere_CF(const Reference< CPlayer > & player, SQInt32 world,
const Vector3 & pos, const Color3 & color, SQFloat radius,
SQInt32 header, SqObj & payload)
{
return _Core->NewSphere(player, world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
header, payload);
}
// ================================================================================================
bool Register_CSphere(HSQUIRRELVM vm)
{
// Attempt to register the base reference type before the actual implementation
if (!Register_Reference< CSphere >(vm, _SC("BaseSphere")))
{
LogFtl("Unable to register the base class <BaseSphere> for <CSphere> type");
// Registration failed
return false;
}
// Typedef the base reference type for simplicity
typedef Reference< CSphere > RefType;
// Output debugging information
LogDbg("Beginning registration of <CSphere> type");
// Attempt to register the actual reference that implements all of the entity functionality
Sqrat::RootTable(vm).Bind(_SC("CSphere"), Sqrat::DerivedClass< CSphere, RefType >(vm, _SC("CSphere"))
/* Constructors */
.Ctor()
.Ctor< SQInt32 >()
/* Properties */
.Prop(_SC("world"), &CSphere::GetWorld, &CSphere::SetWorld)
.Prop(_SC("color"), &CSphere::GetColor, &CSphere::SetColor)
.Prop(_SC("position"), &CSphere::GetPosition, &CSphere::SetPosition)
.Prop(_SC("radius"), &CSphere::GetRadius, &CSphere::SetRadius)
.Prop(_SC("owner"), &CSphere::GetOwner)
.Prop(_SC("owner_id"), &CSphere::GetOwnerID)
/* Functions */
.Func(_SC("streamed_for"), &CSphere::IsStreamedFor)
.Func(_SC("set_color"), &CSphere::SetColorEx)
.Func(_SC("set_position"), &CSphere::SetPositionEx)
);
// Output debugging information
LogDbg("Registration of <CSphere> type was successful");
// Output debugging information
LogDbg("Beginning registration of <Sphere> functions");
// Register global functions related to this entity type
Sqrat::RootTable(vm)
/* Create BaseSphere [P]rimitive [E]xtended [F]Full */
.Overload< RefType (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, SQFloat) >
(_SC("CreateBaseSphere_PEF"), &CreateBaseSphere_PEF)
.Overload< RefType (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, SQFloat, SQInt32, SqObj &) >
(_SC("CreateBaseSphere_PEF"), &CreateBaseSphere_PEF)
/* Create BaseSphere [P]rimitive [C]ompact [F]ull */
.Overload< RefType (*)(SQInt32, SQInt32, const Vector3 &, const Color3 &, SQFloat) >
(_SC("CreateBaseSphere_PCF"), &CreateBaseSphere_PCF)
.Overload< RefType (*)(SQInt32, SQInt32, const Vector3 &, const Color3 &, SQFloat, SQInt32, SqObj &) >
(_SC("CreateBaseSphere_PCF"), &CreateBaseSphere_PCF)
/* Create BaseSphere [E]xtended [F]Full */
.Overload< RefType (*)(const Reference< CPlayer > &, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, SQFloat) >
(_SC("CreateBaseSphere_EF"), &CreateBaseSphere_EF)
.Overload< RefType (*)(const Reference< CPlayer > &, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, SQFloat, SQInt32, SqObj &) >
(_SC("CreateBaseSphere_EF"), &CreateBaseSphere_EF)
/* Create BaseSphere [C]ompact [F]ull */
.Overload< RefType (*)(const Reference< CPlayer > &, SQInt32, const Vector3 &, const Color3 &, SQFloat) >
(_SC("CreateBaseSphere_CF"), &CreateBaseSphere_CF)
.Overload< RefType (*)(const Reference< CPlayer > &, SQInt32, const Vector3 &, const Color3 &, SQFloat, SQInt32, SqObj &) >
(_SC("CreateBaseSphere_CF"), &CreateBaseSphere_CF)
/* Create CSphere [P]rimitive [E]xtended [F]Full */
.Overload< CSphere (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, SQFloat) >
(_SC("CreateSphere_PEF"), &CreateSphere_PEF)
.Overload< CSphere (*)(SQInt32, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, SQFloat, SQInt32, SqObj &) >
(_SC("CreateSphere_PEF"), &CreateSphere_PEF)
/* Create CSphere [P]rimitive [C]ompact [F]ull */
.Overload< CSphere (*)(SQInt32, SQInt32, const Vector3 &, const Color3 &, SQFloat) >
(_SC("CreateSphere_PCF"), &CreateSphere_PCF)
.Overload< CSphere (*)(SQInt32, SQInt32, const Vector3 &, const Color3 &, SQFloat, SQInt32, SqObj &) >
(_SC("CreateSphere_PCF"), &CreateSphere_PCF)
/* Create CSphere [E]xtended [F]Full */
.Overload< CSphere (*)(const Reference< CPlayer > &, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, SQFloat) >
(_SC("CreateSphere_EF"), &CreateSphere_EF)
.Overload< CSphere (*)(const Reference< CPlayer > &, SQInt32, SQFloat, SQFloat, SQFloat, Uint8, Uint8, Uint8, SQFloat, SQInt32, SqObj &) >
(_SC("CreateSphere_EF"), &CreateSphere_EF)
/* Create CSphere [C]ompact [F]ull */
.Overload< CSphere (*)(const Reference< CPlayer > &, SQInt32, const Vector3 &, const Color3 &, SQFloat) >
(_SC("CreateSphere_CF"), &CreateSphere_CF)
.Overload< CSphere (*)(const Reference< CPlayer > &, SQInt32, const Vector3 &, const Color3 &, SQFloat, SQInt32, SqObj &) >
(_SC("CreateSphere_CF"), &CreateSphere_CF);
// Output debugging information
LogDbg("Registration of <Sphere> functions was successful");
// Registration succeeded
return true;
}
} // Namespace:: SqMod

View File

@@ -1,102 +0,0 @@
#ifndef _ENTITY_SPHERE_HPP_
#define _ENTITY_SPHERE_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced sphere instance.
*/
class CSphere : public Reference< CSphere >
{
// --------------------------------------------------------------------------------------------
static Color3 s_Color3;
static Vector3 s_Vector3;
// --------------------------------------------------------------------------------------------
static SQUint32 s_ColorR, s_ColorG, s_ColorB;
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
*/
CSphere(const Reference< CSphere > & o);
/* --------------------------------------------------------------------------------------------
* See if the referenced sphere instance is streamed for the specified player.
*/
bool IsStreamedFor(const Reference< CPlayer > & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced sphere instance exists.
*/
SQInt32 GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Change the world in which the referenced sphere instance exists.
*/
void SetWorld(SQInt32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the referenced sphere instance.
*/
const Color3 & GetColor() const;
/* --------------------------------------------------------------------------------------------
* Change the color of the referenced sphere instance.
*/
void SetColor(const Color3 & col) const;
/* --------------------------------------------------------------------------------------------
* Change the color of the referenced sphere instance.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the referenced sphere instance.
*/
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced sphere instance.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced sphere instance.
*/
void SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radius of the referenced sphere instance.
*/
SQFloat GetRadius() const;
/* --------------------------------------------------------------------------------------------
* Change the radius of the referenced sphere instance.
*/
void SetRadius(SQFloat radius) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner of the referenced sphere instance.
*/
Reference< CPlayer > GetOwner() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner identifier of the referenced sphere instance.
*/
SQInt32 GetOwnerID() const;
};
} // Namespace:: SqMod
#endif // _ENTITY_SPHERE_HPP_

File diff suppressed because it is too large Load Diff

View File

@@ -2,142 +2,150 @@
#define _ENTITY_SPRITE_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced sprite instance.
* Manages Sprite instances.
*/
class CSprite : public Reference< CSprite >
class CSprite
{
// --------------------------------------------------------------------------------------------
friend class Core;
private:
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_SPRITE_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CSprite(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CSprite(const CSprite &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CSprite & operator = (const CSprite &);
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
* Destructor.
*/
CSprite(const Reference< CSprite > & o);
~CSprite();
/* --------------------------------------------------------------------------------------------
* Show the referenced sprite instance to all players on the server.
* See whether this instance manages a valid entity.
*/
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid sprite reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* 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.
*/
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_SPRITE_POOL; }
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr 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);
// --------------------------------------------------------------------------------------------
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
void ShowAll() const;
/* --------------------------------------------------------------------------------------------
* Show the referenced sprite instance to the specified player instance.
*/
void ShowFor(const Reference< CPlayer > & player) const;
/* --------------------------------------------------------------------------------------------
* Show the referenced sprite instance to all players in the specified range.
*/
void ShowRange(SQInt32 first, SQInt32 last) const;
/* --------------------------------------------------------------------------------------------
* Hide the referenced sprite instance from all players on the server.
*/
void ShowFor(CPlayer & player) const;
void ShowRange(Int32 first, Int32 last) const;
void HideAll() const;
/* --------------------------------------------------------------------------------------------
* Hide the referenced sprite instance from the specified player instance.
*/
void HideFor(const Reference< CPlayer > & player) const;
/* --------------------------------------------------------------------------------------------
* Hide the referenced sprite instance from all players in the specified range.
*/
void HideRange(SQInt32 first, SQInt32 last) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced sprite instance for all players on the server.
*/
void HideFor(CPlayer & player) const;
void HideRange(Int32 first, Int32 last) const;
void SetPositionAll(const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced sprite instance for all players on the server.
*/
void SetPositionAllEx(SQInt32 x, SQInt32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced sprite instance for the specified player instance.
*/
void SetPositionFor(const Reference< CPlayer > & player, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced sprite instance for the specified player instance.
*/
void SetPositionForEx(const Reference< CPlayer > & player, SQInt32 x, SQInt32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced sprite instance for all players in the specified range.
*/
void SetPositionRange(SQInt32 first, SQInt32 last, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the referenced sprite instance for all players on the server.
*/
void SetPositionAllEx(Int32 x, Int32 y) const;
void SetPositionFor(CPlayer & player, const Vector2i & pos) const;
void SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const;
void SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const;
void SetCenterAll(const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the referenced sprite instance for all players on the server.
*/
void SetCenterAllEx(SQInt32 x, SQInt32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the referenced sprite instance for the specified player instance.
*/
void SetCenterFor(const Reference< CPlayer > & player, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the referenced sprite instance for the specified player instance.
*/
void SetCenterForEx(const Reference< CPlayer > & player, SQInt32 x, SQInt32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the referenced sprite instance for all players in the specified range.
*/
void SetCenterRange(SQInt32 first, SQInt32 last, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the rotation of the referenced sprite instance for all players on the server.
*/
void SetCenterAllEx(Int32 x, Int32 y) const;
void SetCenterFor(CPlayer & player, const Vector2i & pos) const;
void SetCenterForEx(CPlayer & player, Int32 x, Int32 y) const;
void SetCenterRange(Int32 first, Int32 last, const Vector2i & pos) const;
void SetRotationAll(SQFloat rot) const;
/* --------------------------------------------------------------------------------------------
* Set the rotation of the referenced sprite instance for the specified player instance.
*/
void SetRotationFor(const Reference< CPlayer > & player, SQFloat rot) const;
/* --------------------------------------------------------------------------------------------
* Set the rotation of the referenced sprite instance for all players in the specified range.
*/
void SetRotationRange(SQInt32 first, SQInt32 last, SQFloat rot) const;
/* --------------------------------------------------------------------------------------------
* Set the rotation of the referenced sprite instance for all players on the server.
*/
void SetRotationFor(CPlayer & player, SQFloat rot) const;
void SetRotationRange(Int32 first, Int32 last, SQFloat rot) const;
void SetAlphaAll(Uint8 alpha) const;
/* --------------------------------------------------------------------------------------------
* Set the rotation of the referenced sprite instance for the specified player instance.
*/
void SetAlphaFor(const Reference< CPlayer > & player, Uint8 alpha) const;
/* --------------------------------------------------------------------------------------------
* Set the rotation of the referenced sprite instance for all players in the specified range.
*/
void SetAlphaRange(SQInt32 first, SQInt32 last, Uint8 alpha) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the file path of the texture used by the referenced sprite instance.
*/
const SQChar * GetFilePath() const;
void SetAlphaFor(CPlayer & player, Uint8 alpha) const;
void SetAlphaRange(Int32 first, Int32 last, Uint8 alpha) const;
CSStr GetFilePath() const;
};
} // Namespace:: SqMod

View File

@@ -1,551 +1,363 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Textdraw.hpp"
#include "Entity/Player.hpp"
#include "Base/Vector2i.hpp"
#include "Core.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
CTextdraw::CTextdraw(const Reference< CTextdraw > & o)
: Reference(o)
SQChar CTextdraw::s_StrID[SQMOD_TEXTDRAW_POOL][8];
// ------------------------------------------------------------------------------------------------
const Int32 CTextdraw::Max = SQMOD_TEXTDRAW_POOL;
// ------------------------------------------------------------------------------------------------
CTextdraw::CTextdraw(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_TEXTDRAW_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::ShowAll() const
CTextdraw::~CTextdraw()
{
if (VALID_ENTITY(m_ID))
{
_Func->ShowTextdraw(m_ID, SQMOD_UNKNOWN);
}
/* ... */
}
// ------------------------------------------------------------------------------------------------
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
{
BadRef("show_all", "show to all");
}
return -1;
}
CSStr CTextdraw::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_TEXTDRAW_POOL) ? s_StrID[m_ID] : _SC("-1");
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::ShowFor(const Reference< CPlayer > & player) const
CSStr CTextdraw::GetTag() const
{
if (VALID_ENTITY(m_ID) && player)
{
return _Func->ShowTextdraw(m_ID, player);
}
else if (!player)
{
BadArg("show_for", "show to player", _SCI32(player));
}
else
{
BadRef("show_for", "show to player");
}
return m_Tag.c_str();
}
void CTextdraw::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
Object & CTextdraw::GetData()
{
if (Validate())
return m_Data;
return NullObject();
}
void CTextdraw::SetData(Object & data)
{
if (Validate())
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::ShowRange(SQInt32 first, SQInt32 last) const
bool CTextdraw::Destroy(Int32 header, Object & payload)
{
if (VALID_ENTITY(m_ID) && (last >= first))
{
for (; first <= last; ++first)
{
if (Reference< CPlayer >::Verify(first))
{
_Func->ShowTextdraw(m_ID, first);
}
}
}
else if (first < last)
{
BadArg("show_range", "show to range", "using an out of range start", first, last);
}
else
{
BadRef("show_range", "show to range");
}
return _Core->DelTextdraw(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::HideAll() const
bool CTextdraw::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (VALID_ENTITY(m_ID))
{
_Func->HideTextdraw(m_ID, SQMOD_UNKNOWN);
}
else
{
BadRef("hide_all", "hide from all");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::HideFor(const Reference< CPlayer > & player) const
{
if (VALID_ENTITY(m_ID) && player)
{
return _Func->HideTextdraw(m_ID, player);
}
else if (!player)
{
BadArg("hide_for", "hide from player", _SCI32(player));
}
else
{
BadRef("hide_for", "hide from player");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::HideRange(SQInt32 first, SQInt32 last) const
{
if (VALID_ENTITY(m_ID) && (last >= first))
{
for (; first <= last; ++first)
{
if (Reference< CPlayer >::Verify(first))
{
_Func->HideTextdraw(m_ID, first);
}
}
}
else if (first < last)
{
BadArg("hide_range", "hide from range", "using an out of range start", first, last);
}
else
{
BadRef("hide_range", "hide from range");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionAll(const Vector2i & pos) const
{
if (VALID_ENTITY(m_ID))
{
_Func->MoveTextdraw(m_ID, SQMOD_UNKNOWN, pos.x, pos.y);
}
else
{
BadRef("set_position_all", "set position for all");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionAllEx(SQInt32 x, SQInt32 y) const
{
if (VALID_ENTITY(m_ID))
{
_Func->MoveTextdraw(m_ID, SQMOD_UNKNOWN, x, y);
}
else
{
BadRef("set_position_all", "set position for all");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionFor(const Reference< CPlayer > & player, const Vector2i & pos) const
{
if (VALID_ENTITY(m_ID) && player)
{
_Func->MoveTextdraw(m_ID, player, pos.x, pos.y);
}
else if (!player)
{
BadArg("set_position_for", "set position for player", _SCI32(player));
}
else
{
BadRef("set_position_for", "set position for player");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionForEx(const Reference< CPlayer > & player, SQInt32 x, SQInt32 y) const
{
if (VALID_ENTITY(m_ID) && player)
{
_Func->MoveTextdraw(m_ID, player, x, y);
}
else if (!player)
{
BadArg("set_position_for", "set position for player", _SCI32(player));
}
else
{
BadRef("set_position_for", "set position for player");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionRange(SQInt32 first, SQInt32 last, const Vector2i & pos) const
{
if (VALID_ENTITY(m_ID) && (last >= first))
{
for (; first <= last; ++first)
{
if (Reference< CPlayer >::Verify(first))
{
_Func->MoveTextdraw(m_ID, first, pos.x, pos.y);
}
}
}
else if (first < last)
{
BadArg("set_position_range", "set position for range", "using an out of range start", first, last);
}
else
{
BadRef("set_position_range", "set position for range");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorAll(const Color4 & col) const
{
if (VALID_ENTITY(m_ID))
{
_Func->SetTextdrawColour(m_ID, SQMOD_UNKNOWN, col.GetRGBA());
}
else
{
BadRef("set_color_all", "set color for all");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorAllEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
if (VALID_ENTITY(m_ID))
{
_Func->SetTextdrawColour(m_ID, SQMOD_UNKNOWN, PACK_RGBA(r, g, b, a));
}
else
{
BadRef("set_color_all", "set color for all");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorFor(const Reference< CPlayer > & player, const Color4 & col) const
{
if (VALID_ENTITY(m_ID) && player)
{
_Func->SetTextdrawColour(m_ID, player, col.GetRGBA());
}
else if (!player)
{
BadArg("set_color_for", "set color for player", _SCI32(player));
}
else
{
BadRef("set_color_for", "set color for player");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorForEx(const Reference< CPlayer > & player, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
if (VALID_ENTITY(m_ID) && player)
{
_Func->SetTextdrawColour(m_ID, player, PACK_RGBA(r, g, b, a));
}
else if (!player)
{
BadArg("set_color_for", "set color for player", _SCI32(player));
}
else
{
BadRef("set_color_for", "set color for player");
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorRange(SQInt32 first, SQInt32 last, const Color4 & col) const
{
if (VALID_ENTITY(m_ID) && (last >= first))
{
for (const SQUint32 color = col.GetRGBA(); first <= last; ++first)
{
if (Reference< CPlayer >::Verify(first))
{
_Func->SetTextdrawColour(m_ID, first, color);
}
}
}
else if (first < last)
{
BadArg("set_color_range", "set color for range", "using an out of range start", first, last);
}
else
{
BadRef("set_color_range", "set color for range");
}
}
// ------------------------------------------------------------------------------------------------
const SQChar * CTextdraw::GetText() const
{
if (VALID_ENTITY(m_ID))
{
RefType::Get(m_ID).Text.c_str();
}
else
{
BadRef("@text", "get text");
}
return _SC("");
}
// ------------------------------------------------------------------------------------------------
Reference< CTextdraw > CreateBaseTextdraw_ES(const SQChar * text,
SQInt32 xp, SQInt32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
bool rel)
{
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, xp, yp, PACK_ARGB(a, r, g, b), rel,
SQMOD_CREATE_DEFAULT, NullData());
}
Reference< CTextdraw > CreateBaseTextdraw_ES(const SQChar * text,
SQInt32 xp, SQInt32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
bool rel,
SQInt32 header, SqObj & payload)
{
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, xp, yp, PACK_ARGB(a, r, g, b), rel,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CTextdraw > CreateBaseTextdraw_EF(SQInt32 index, const SQChar * text,
SQInt32 xp, SQInt32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
bool rel)
{
return _Core->NewTextdraw(index,text, xp, yp, PACK_ARGB(a, r, g, b), rel,
SQMOD_CREATE_DEFAULT, NullData());
}
Reference< CTextdraw > CreateBaseTextdraw_EF(SQInt32 index, const SQChar * text,
SQInt32 xp, SQInt32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
bool rel,
SQInt32 header, SqObj & payload)
{
return _Core->NewTextdraw(index, text, xp, yp, PACK_ARGB(a, r, g, b), rel,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CTextdraw > CreateBaseTextdraw_CS(const SQChar * 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, NullData());
}
Reference< CTextdraw > CreateBaseTextdraw_CS(const SQChar * text,
const Vector2i & pos, const Color4 & color, bool rel,
SQInt32 header, SqObj & payload)
{
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, pos.x, pos.y, color.GetARGB(), rel,
header, payload);
}
// ------------------------------------------------------------------------------------------------
Reference< CTextdraw > CreateBaseTextdraw_CF(SQInt32 index, const SQChar * text,
const Vector2i & pos, const Color4 & color, bool rel)
{
return _Core->NewTextdraw(index, text, pos.x, pos.y, color.GetARGB(), rel,
SQMOD_CREATE_DEFAULT, NullData());
}
Reference< CTextdraw > CreateBaseTextdraw_CF(SQInt32 index, const SQChar * text,
const Vector2i & pos, const Color4 & color, bool rel,
SQInt32 header, SqObj & payload)
{
return _Core->NewTextdraw(index, text, pos.x, pos.y, color.GetARGB(), rel,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CTextdraw CreateTextdraw_ES(const SQChar * text,
SQInt32 xp, SQInt32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
bool rel)
{
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, xp, yp, PACK_ARGB(a, r, g, b), rel,
SQMOD_CREATE_DEFAULT, NullData());
}
CTextdraw CreateTextdraw_ES(const SQChar * text,
SQInt32 xp, SQInt32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
bool rel,
SQInt32 header, SqObj & payload)
{
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, xp, yp, PACK_ARGB(a, r, g, b), rel,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CTextdraw CreateTextdraw_EF(SQInt32 index, const SQChar * text,
SQInt32 xp, SQInt32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
bool rel)
{
return _Core->NewTextdraw(index,text, xp, yp, PACK_ARGB(a, r, g, b), rel,
SQMOD_CREATE_DEFAULT, NullData());
}
CTextdraw CreateTextdraw_EF(SQInt32 index, const SQChar * text,
SQInt32 xp, SQInt32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
bool rel,
SQInt32 header, SqObj & payload)
{
return _Core->NewTextdraw(index, text, xp, yp, PACK_ARGB(a, r, g, b), rel,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CTextdraw CreateTextdraw_CS(const SQChar * 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, NullData());
}
CTextdraw CreateTextdraw_CS(const SQChar * text,
const Vector2i & pos, const Color4 & color, bool rel,
SQInt32 header, SqObj & payload)
{
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, pos.x, pos.y, color.GetARGB(), rel,
header, payload);
}
// ------------------------------------------------------------------------------------------------
CTextdraw CreateTextdraw_CF(SQInt32 index, const SQChar * text,
const Vector2i & pos, const Color4 & color, bool rel)
{
return _Core->NewTextdraw(index, text, pos.x, pos.y, color.GetARGB(), rel,
SQMOD_CREATE_DEFAULT, NullData());
}
CTextdraw CreateTextdraw_CF(SQInt32 index, const SQChar * text,
const Vector2i & pos, const Color4 & color, bool rel,
SQInt32 header, SqObj & payload)
{
return _Core->NewTextdraw(index, text, pos.x, pos.y, color.GetARGB(), rel,
header, payload);
}
// ================================================================================================
bool Register_CTextdraw(HSQUIRRELVM vm)
{
// Attempt to register the base reference type before the actual implementation
if (!Register_Reference< CTextdraw >(vm, _SC("BaseTextdraw")))
{
LogFtl("Unable to register the base class <BaseTextdraw> for <CTextdraw> type");
// Registration failed
if (!Validate())
return false;
}
// Typedef the base reference type for simplicity
typedef Reference< CTextdraw > RefType;
// Output debugging information
LogDbg("Beginning registration of <CTextdraw> type");
// Attempt to register the actual reference that implements all of the entity functionality
Sqrat::RootTable(vm).Bind(_SC("CTextdraw"), Sqrat::DerivedClass< CTextdraw, RefType >(vm, _SC("CTextdraw"))
/* Constructors */
.Ctor()
.Ctor< SQInt32 >()
/* Properties */
.Prop(_SC("text"), &CTextdraw::GetText)
/* Functions */
.Func(_SC("show_all"), &CTextdraw::ShowAll)
.Func(_SC("show_to"), &CTextdraw::ShowFor)
.Func(_SC("show_for"), &CTextdraw::ShowFor)
.Func(_SC("show_range"), &CTextdraw::ShowRange)
.Func(_SC("hide_all"), &CTextdraw::HideAll)
.Func(_SC("hide_for"), &CTextdraw::HideFor)
.Func(_SC("hide_from"), &CTextdraw::HideFor)
.Func(_SC("hide_range"), &CTextdraw::HideRange)
/* Overloads */
.Overload< void (CTextdraw::*)(const Vector2i &) const >
(_SC("set_position_all"), &CTextdraw::SetPositionAll)
.Overload< void (CTextdraw::*)(SQInt32, SQInt32) const >
(_SC("set_position_all"), &CTextdraw::SetPositionAllEx)
.Overload< void (CTextdraw::*)(const Reference< CPlayer > &, const Vector2i &) const >
(_SC("set_position_for"), &CTextdraw::SetPositionFor)
.Overload< void (CTextdraw::*)(const Reference< CPlayer > &, SQInt32, SQInt32) const >
(_SC("set_position_for"), &CTextdraw::SetPositionForEx)
.Overload< void (CTextdraw::*)(SQInt32, SQInt32, const Vector2i &) const >
(_SC("set_position_range"), &CTextdraw::SetPositionRange)
.Overload< void (CTextdraw::*)(const Color4 &) const >
(_SC("set_color_all"), &CTextdraw::SetColorAll)
.Overload< void (CTextdraw::*)(Uint8, Uint8, Uint8, Uint8) const >
(_SC("set_color_all"), &CTextdraw::SetColorAllEx)
.Overload< void (CTextdraw::*)(const Reference< CPlayer > &, const Color4 &) const >
(_SC("set_color_for"), &CTextdraw::SetColorFor)
.Overload< void (CTextdraw::*)(const Reference< CPlayer > &, Uint8, Uint8, Uint8, Uint8) const >
(_SC("set_color_for"), &CTextdraw::SetColorForEx)
.Overload< void (CTextdraw::*)(SQInt32, SQInt32, const Color4 &) const >
(_SC("set_color_range"), &CTextdraw::SetColorRange)
);
// Output debugging information
LogDbg("Registration of <CTextdraw> type was successful");
// Output debugging information
LogDbg("Beginning registration of <Textdraw> functions");
// Register global functions related to this entity type
Sqrat::RootTable(vm)
/* Create BaseTextdraw [E]xtended [S]ubstitute */
.Overload< RefType (*)(const SQChar *, SQInt32, SQInt32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateBaseTextdraw_ES"), &CreateBaseTextdraw_ES)
.Overload< RefType (*)(const SQChar *, SQInt32, SQInt32, Uint8, Uint8, Uint8, Uint8, bool, SQInt32, SqObj &) >
(_SC("CreateBaseTextdraw_ES"), &CreateBaseTextdraw_ES)
/* Create BaseTextdraw [E]xtended [F]Full */
.Overload< RefType (*)(SQInt32, const SQChar *, SQInt32, SQInt32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateBaseTextdraw_EF"), &CreateBaseTextdraw_EF)
.Overload< RefType (*)(SQInt32, const SQChar *, SQInt32, SQInt32, Uint8, Uint8, Uint8, Uint8, bool, SQInt32, SqObj &) >
(_SC("CreateBaseTextdraw_EF"), &CreateBaseTextdraw_EF)
/* Create BaseTextdraw [C]ompact [S]ubstitute */
.Overload< RefType (*)(const SQChar *, const Vector2i &, const Color4 &, bool) >
(_SC("CreateBaseTextdraw_CS"), &CreateBaseTextdraw_CS)
.Overload< RefType (*)(const SQChar *, const Vector2i &, const Color4 &, bool, SQInt32, SqObj &) >
(_SC("CreateBaseTextdraw_CS"), &CreateBaseTextdraw_CS)
/* Create BaseTextdraw [C]ompact [F]ull */
.Overload< RefType (*)(SQInt32, const SQChar *, const Vector2i &, const Color4 &, bool) >
(_SC("CreateBaseTextdraw_CF"), &CreateBaseTextdraw_CF)
.Overload< RefType (*)(SQInt32, const SQChar *, const Vector2i &, const Color4 &, bool, SQInt32, SqObj &) >
(_SC("CreateBaseTextdraw_CF"), &CreateBaseTextdraw_CF)
/* Create CTextdraw [E]xtended [S]ubstitute */
.Overload< CTextdraw (*)(const SQChar *, SQInt32, SQInt32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateTextdraw_ES"), &CreateTextdraw_ES)
.Overload< CTextdraw (*)(const SQChar *, SQInt32, SQInt32, Uint8, Uint8, Uint8, Uint8, bool, SQInt32, SqObj &) >
(_SC("CreateTextdraw_ES"), &CreateTextdraw_ES)
/* Create CTextdraw [E]xtended [F]Full */
.Overload< CTextdraw (*)(SQInt32, const SQChar *, SQInt32, SQInt32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateTextdraw_EF"), &CreateTextdraw_EF)
.Overload< CTextdraw (*)(SQInt32, const SQChar *, SQInt32, SQInt32, Uint8, Uint8, Uint8, Uint8, bool, SQInt32, SqObj &) >
(_SC("CreateTextdraw_EF"), &CreateTextdraw_EF)
/* Create CTextdraw [C]ompact [S]ubstitute */
.Overload< CTextdraw (*)(const SQChar *, const Vector2i &, const Color4 &, bool) >
(_SC("CreateTextdraw_CS"), &CreateTextdraw_CS)
.Overload< CTextdraw (*)(const SQChar *, const Vector2i &, const Color4 &, bool, SQInt32, SqObj &) >
(_SC("CreateTextdraw_CS"), &CreateTextdraw_CS)
/* Create CTextdraw [C]ompact [F]ull */
.Overload< CTextdraw (*)(SQInt32, const SQChar *, const Vector2i &, const Color4 &, bool) >
(_SC("CreateTextdraw_CF"), &CreateTextdraw_CF)
.Overload< CTextdraw (*)(SQInt32, const SQChar *, const Vector2i &, const Color4 &, bool, SQInt32, SqObj &) >
(_SC("CreateTextdraw_CF"), &CreateTextdraw_CF);
// Output debugging information
LogDbg("Registration of <Textdraw> functions was successful");
// Registration succeeded
Function & event = _Core->GetTextdrawEvent(m_ID, evid);
if (func.IsNull())
event.Release();
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
} // Namespace:: SqMod
// ------------------------------------------------------------------------------------------------
void CTextdraw::ShowAll() const
{
if (Validate())
_Func->ShowTextdraw(m_ID, -1);
}
void CTextdraw::ShowFor(CPlayer & player) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->ShowTextdraw(m_ID, player.GetID());
}
void CTextdraw::ShowRange(Int32 first, Int32 last) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->ShowTextdraw(m_ID, first);
}
}
void CTextdraw::HideAll() const
{
if (Validate())
_Func->HideTextdraw(m_ID, -1);
}
void CTextdraw::HideFor(CPlayer & player) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->HideTextdraw(m_ID, player.GetID());
}
void CTextdraw::HideRange(Int32 first, Int32 last) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->HideTextdraw(m_ID, first);
}
}
void CTextdraw::SetPositionAll(const Vector2i & pos) const
{
if (Validate())
_Func->MoveTextdraw(m_ID, -1, pos.x, pos.y);
}
void CTextdraw::SetPositionAllEx(Int32 x, Int32 y) const
{
if (Validate())
_Func->MoveTextdraw(m_ID, -1, x, y);
}
void CTextdraw::SetPositionFor(CPlayer & player, const Vector2i & pos) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->MoveTextdraw(m_ID, player.GetID(), pos.x, pos.y);
}
void CTextdraw::SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->MoveTextdraw(m_ID, player.GetID(), x, y);
}
void CTextdraw::SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->MoveTextdraw(m_ID, first, pos.x, pos.y);
}
}
void CTextdraw::SetColorAll(const Color4 & col) const
{
if (Validate())
_Func->SetTextdrawColour(m_ID, -1, col.GetRGBA());
}
void CTextdraw::SetColorAllEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
if (Validate())
_Func->SetTextdrawColour(m_ID, -1, SQMOD_PACK_RGBA(r, g, b, a));
}
void CTextdraw::SetColorFor(CPlayer & player, const Color4 & col) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->SetTextdrawColour(m_ID, player.GetID(), col.GetRGBA());
}
void CTextdraw::SetColorForEx(CPlayer & player, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->SetTextdrawColour(m_ID, player.GetID(), SQMOD_PACK_RGBA(r, g, b, a));
}
void CTextdraw::SetColorRange(Int32 first, Int32 last, const Color4 & col) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (const Uint32 color = col.GetRGBA(); first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->SetTextdrawColour(m_ID, first, color);
}
}
CSStr CTextdraw::GetText() const
{
if (Validate())
_Core->GetTextdraw(m_ID).mText.c_str();
return g_EmptyStr;
}
// ------------------------------------------------------------------------------------------------
static Object & CreateTextdrawEx(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 & CreateTextdrawEx(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 & CreateTextdrawEx(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 & CreateTextdrawEx(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 & CreateTextdraw(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 & CreateTextdraw(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 & CreateTextdraw(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 & CreateTextdraw(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);
}
// ================================================================================================
void Register_CTextdraw(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqTextdraw"),
Class< CTextdraw, NoConstructor< CTextdraw > >(vm, _SC("SqTextdraw"))
/* Metamethods */
.Func(_SC("_cmp"), &CTextdraw::Cmp)
.Func(_SC("_tostring"), &CTextdraw::ToString)
/* Core Properties */
.Prop(_SC("ID"), &CTextdraw::GetID)
.Prop(_SC("Tag"), &CTextdraw::GetTag, &CTextdraw::SetTag)
.Prop(_SC("Data"), &CTextdraw::GetData, &CTextdraw::SetData)
.Prop(_SC("MaxID"), &CTextdraw::GetMaxID)
.Prop(_SC("Active"), &CTextdraw::IsActive)
/* Core Functions */
.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)
/* Functions */
.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)
/* 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)
);
RootTable(vm)
.Overload< Object & (*)(CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateTextdrawEx"), &CreateTextdrawEx)
.Overload< Object & (*)(CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool, Int32, Object &) >
(_SC("CreateTextdrawEx"), &CreateTextdrawEx)
.Overload< Object & (*)(Int32, CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateTextdrawEx"), &CreateTextdrawEx)
.Overload< Object & (*)(Int32, CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool, Int32, Object &) >
(_SC("CreateTextdrawEx"), &CreateTextdrawEx)
.Overload< Object & (*)(CSStr, const Vector2i &, const Color4 &, bool) >
(_SC("CreateTextdraw"), &CreateTextdraw)
.Overload< Object & (*)(CSStr, const Vector2i &, const Color4 &, bool, Int32, Object &) >
(_SC("CreateTextdraw"), &CreateTextdraw)
.Overload< Object & (*)(Int32, CSStr, const Vector2i &, const Color4 &, bool) >
(_SC("CreateTextdraw"), &CreateTextdraw)
.Overload< Object & (*)(Int32, CSStr, const Vector2i &, const Color4 &, bool, Int32, Object &) >
(_SC("CreateTextdraw"), &CreateTextdraw);
}
} // Namespace:: SqMod

View File

@@ -2,112 +2,144 @@
#define _ENTITY_TEXTDRAW_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced textdraw instance.
* Manages Textdraw instances.
*/
class CTextdraw : public Reference< CTextdraw >
class CTextdraw
{
// --------------------------------------------------------------------------------------------
friend class Core;
private:
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_TEXTDRAW_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CTextdraw(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CTextdraw(const CTextdraw &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CTextdraw & operator = (const CTextdraw &);
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
* Destructor.
*/
CTextdraw(const Reference< CTextdraw > & o);
~CTextdraw();
/* --------------------------------------------------------------------------------------------
* Show the referenced textdraw instance to all players on the server.
* See whether this instance manages a valid entity.
*/
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid textdraw reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* 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.
*/
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_TEXTDRAW_POOL; }
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr 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);
// --------------------------------------------------------------------------------------------
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
void ShowAll() const;
/* --------------------------------------------------------------------------------------------
* Show the referenced textdraw instance to the specified player instance.
*/
void ShowFor(const Reference< CPlayer > & player) const;
/* --------------------------------------------------------------------------------------------
* Show the referenced textdraw instance to all players in the specified range.
*/
void ShowRange(SQInt32 first, SQInt32 last) const;
/* --------------------------------------------------------------------------------------------
* Hide the referenced textdraw instance from all players on the server.
*/
void ShowFor(CPlayer & player) const;
void ShowRange(Int32 first, Int32 last) const;
void HideAll() const;
/* --------------------------------------------------------------------------------------------
* Hide the referenced textdraw instance from the specified player instance.
*/
void HideFor(const Reference< CPlayer > & player) const;
/* --------------------------------------------------------------------------------------------
* Hide the referenced textdraw instance from all players in the specified range.
*/
void HideRange(SQInt32 first, SQInt32 last) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced textdraw instance for all players on the server.
*/
void HideFor(CPlayer & player) const;
void HideRange(Int32 first, Int32 last) const;
void SetPositionAll(const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced textdraw instance for all players on the server.
*/
void SetPositionAllEx(SQInt32 x, SQInt32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced textdraw instance for the specified player instance.
*/
void SetPositionFor(const Reference< CPlayer > & player, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced textdraw instance for the specified player instance.
*/
void SetPositionForEx(const Reference< CPlayer > & player, SQInt32 x, SQInt32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the referenced textdraw instance for all players in the specified range.
*/
void SetPositionRange(SQInt32 first, SQInt32 last, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the referenced textdraw instance for all players on the server.
*/
void SetPositionAllEx(Int32 x, Int32 y) const;
void SetPositionFor(CPlayer & player, const Vector2i & pos) const;
void SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const;
void SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const;
void SetColorAll(const Color4 & col) const;
/* --------------------------------------------------------------------------------------------
* Set the color of the referenced textdraw instance for all players on the server.
*/
void SetColorAllEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
/* --------------------------------------------------------------------------------------------
* Set the color of the referenced textdraw instance for the specified player instance.
*/
void SetColorFor(const Reference< CPlayer > & player, const Color4 & col) const;
/* --------------------------------------------------------------------------------------------
* Set the color of the referenced textdraw instance for the specified player instance.
*/
void SetColorForEx(const Reference< CPlayer > & player, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
/* --------------------------------------------------------------------------------------------
* Set the color of the referenced textdraw instance for all players in the specified range.
*/
void SetColorRange(SQInt32 first, SQInt32 last, const Color4 & col) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the text string used by the referenced textdraw instance.
*/
const SQChar * GetText() const;
void SetColorFor(CPlayer & player, const Color4 & col) const;
void SetColorForEx(CPlayer & player, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
void SetColorRange(Int32 first, Int32 last, const Color4 & col) const;
CSStr GetText() const;
};
} // Namespace:: SqMod

File diff suppressed because it is too large Load Diff

View File

@@ -2,472 +2,246 @@
#define _ENTITY_VEHICLE_HPP_
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced vehicle instance.
* Manages Vehicle instances.
*/
class CVehicle : public Reference< CVehicle >
class CVehicle
{
// --------------------------------------------------------------------------------------------
static CAutomobile s_Automobile;
friend class Core;
private:
// --------------------------------------------------------------------------------------------
static Vector3 s_Vector3;
static Vector4 s_Vector4;
static Quaternion s_Quaternion;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_VEHICLE_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
*/
String m_Tag;
Object m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
CVehicle(Int32 id);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CVehicle(const CVehicle &);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CVehicle & operator = (const CVehicle &);
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
// --------------------------------------------------------------------------------------------
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Construct a reference from a base reference.
* Destructor.
*/
CVehicle(const Reference< CVehicle > & o);
~CVehicle();
/* --------------------------------------------------------------------------------------------
* See if the referenced vehicle instance is streamed for the specified player.
* See whether this instance manages a valid entity.
*/
bool IsStreamedFor(const Reference< CPlayer > & player) const;
bool Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid vehicle reference [%s]", m_Tag.c_str());
return false;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the synchronization source of the referenced vehicle instance.
* Used by the script engine to compare two instances of this type.
*/
SQInt32 GetSyncSource() const;
Int32 Cmp(const CVehicle & o) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the synchronization type of the referenced vehicle instance.
* Used by the script engine to convert an instance of this type to a string.
*/
SQInt32 GetSyncType() const;
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced vehicle instance exists.
* Retrieve the identifier of the entity managed by this instance.
*/
SQInt32 GetWorld() const;
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Change the world in which the referenced vehicle instance exists.
* Retrieve the maximum possible identifier to an entity of this type.
*/
void SetWorld(SQInt32 world) const;
Int32 GetMaxID() const { return SQMOD_VEHICLE_POOL; }
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle model of the referenced vehicle instance.
* Check whether this instance manages a valid entity.
*/
const CAutomobile & GetModel() const;
bool IsActive() const { return VALID_ENTITY(m_ID); }
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle model id of the referenced vehicle instance.
* Retrieve the associated user tag.
*/
SQInt32 GetModelID() const;
CSStr GetTag() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the slot occupant from the referenced vehicle instance.
* Modify the associated user tag.
*/
Reference< CPlayer > GetOccupant(SQInt32 slot) const;
void SetTag(CSStr tag);
/* --------------------------------------------------------------------------------------------
* Retrieve the slot occupant identifier from the referenced vehicle instance.
* Retrieve the associated user data.
*/
SQInt32 GetOccupantID(SQInt32 slot) const;
Object & GetData();
/* --------------------------------------------------------------------------------------------
* Respawn the referenced vehicle instance.
* Modify the associated user data.
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
bool IsStreamedFor(CPlayer & player) const;
Int32 GetSyncSource() const;
Int32 GetSyncType() const;
Int32 GetWorld() const;
void SetWorld(Int32 world) const;
Int32 GetModel() const;
Object & GetOccupant(Int32 slot) const;
Int32 GetOccupantID(Int32 slot) const;
void Respawn() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the immunity flags of the referenced vehicle instance.
*/
SQInt32 GetImmunity() const;
/* --------------------------------------------------------------------------------------------
* Change the immunity flags of the referenced vehicle instance.
*/
void SetImmunity(SQInt32 flags) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced vehicle instance is wrecked.
*/
Int32 GetImmunity() const;
void SetImmunity(Int32 flags) const;
bool IsWrecked() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the referenced vehicle instance.
*/
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced vehicle instance.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced vehicle instance.
*/
void SetPositionEx(const Vector3 & pos, bool empty) const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced vehicle instance.
*/
void SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced vehicle instance.
*/
void SetPositionEx(SQFloat x, SQFloat y, SQFloat z, bool empty) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation of the referenced vehicle instance.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
void SetPositionEx(Float32 x, Float32 y, Float32 z, bool empty) const;
const Quaternion & GetRotation() const;
/* --------------------------------------------------------------------------------------------
* Change the rotation of the referenced vehicle instance.
*/
void SetRotation(const Quaternion & rot) const;
/* --------------------------------------------------------------------------------------------
* Change the rotation of the referenced vehicle instance.
*/
void SetRotationEx(SQFloat x, SQFloat y, SQFloat z, SQFloat w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation of the referenced vehicle instance.
*/
void SetRotationEx(Float32 x, Float32 y, Float32 z, Float32 w) const;
const Vector3 & GetRotationEuler() const;
/* --------------------------------------------------------------------------------------------
* Change the euler rotation of the referenced vehicle instance.
*/
void SetRotationEuler(const Vector3 & rot) const;
/* --------------------------------------------------------------------------------------------
* Change the euler rotation of the referenced vehicle instance.
*/
void SetRotationEulerEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the speed of the referenced vehicle instance.
*/
void SetRotationEulerEx(Float32 x, Float32 y, Float32 z) const;
const Vector3 & GetSpeed() const;
/* --------------------------------------------------------------------------------------------
* Change the speed of the referenced vehicle instance.
*/
void SetSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the speed of the referenced vehicle instance.
*/
void SetSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Change the speed of the referenced vehicle instance.
*/
void SetSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the speed of the referenced vehicle instance.
*/
void AddSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative speed of the referenced vehicle instance.
*/
void AddSpeedEx(Float32 x, Float32 y, Float32 z) const;
const Vector3 & GetRelSpeed() const;
/* --------------------------------------------------------------------------------------------
* Change the relative speed of the referenced vehicle instance.
*/
void SetRelSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the relative speed of the referenced vehicle instance.
*/
void SetRelSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Change the relative speed of the referenced vehicle instance.
*/
void SetRelSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddRelSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the relative speed of the referenced vehicle instance.
*/
void AddRelSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the turn speed of the referenced vehicle instance.
*/
void AddRelSpeedEx(Float32 x, Float32 y, Float32 z) const;
const Vector3 & GetTurnSpeed() const;
/* --------------------------------------------------------------------------------------------
* Change the turn speed of the referenced vehicle instance.
*/
void SetTurnSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the turn speed of the referenced vehicle instance.
*/
void SetTurnSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Change the turn speed of the referenced vehicle instance.
*/
void SetTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddTurnSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the turn speed of the referenced vehicle instance.
*/
void AddTurnSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative turn speed of the referenced vehicle instance.
*/
void AddTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
const Vector3 & GetRelTurnSpeed() const;
/* --------------------------------------------------------------------------------------------
* Change the relative turn speed of the referenced vehicle instance.
*/
void SetRelTurnSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the relative turn speed of the referenced vehicle instance.
*/
void SetRelTurnSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Change the relative turn speed of the referenced vehicle instance.
*/
void SetRelTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
void AddRelTurnSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Change the relative turn speed of the referenced vehicle instance.
*/
void AddRelTurnSpeedEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the spawn position of the referenced vehicle instance.
*/
void AddRelTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
const Vector4 & GetSpawnPosition() const;
/* --------------------------------------------------------------------------------------------
* Change the spawn position of the referenced vehicle instance.
*/
void SetSpawnPosition(const Vector4 & pos) const;
/* --------------------------------------------------------------------------------------------
* Change the spawn position of the referenced vehicle instance.
*/
void SetSpawnPositionEx(SQFloat x, SQFloat y, SQFloat z, SQFloat w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the spawn rotation of the referenced vehicle instance.
*/
void SetSpawnPositionEx(Float32 x, Float32 y, Float32 z, Float32 w) const;
const Quaternion & GetSpawnRotation() const;
/* --------------------------------------------------------------------------------------------
* Change the spawn rotation of the referenced vehicle instance.
*/
void SetSpawnRotation(const Quaternion & rot) const;
/* --------------------------------------------------------------------------------------------
* Change the spawn rotation of the referenced vehicle instance.
*/
void SetSpawnRotationEx(SQFloat x, SQFloat y, SQFloat z, SQFloat w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler spawn rotation of the referenced vehicle instance.
*/
void SetSpawnRotationEx(Float32 x, Float32 y, Float32 z, Float32 w) const;
const Vector3 & GetSpawnRotationEuler() const;
/* --------------------------------------------------------------------------------------------
* Change the euler spawn rotation of the referenced vehicle instance.
*/
void SetSpawnRotationEuler(const Vector3 & rot) const;
/* --------------------------------------------------------------------------------------------
* Change the euler spawn rotation of the referenced vehicle instance.
*/
void SetSpawnRotationEulerEx(SQFloat x, SQFloat y, SQFloat z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the respawn timer of the referenced vehicle instance.
*/
SQUint32 GetRespawnTimer() const;
/* --------------------------------------------------------------------------------------------
* Change the respawn timer of the referenced vehicle instance.
*/
void SetRespawnTimer(SQUint32 timer) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the health of the referenced vehicle instance.
*/
SQFloat GetHealth() const;
/* --------------------------------------------------------------------------------------------
* Change the health of the referenced vehicle instance.
*/
void SetHealth(SQFloat amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the primary color of the referenced vehicle instance.
*/
SQInt32 GetPrimaryColor() const;
/* --------------------------------------------------------------------------------------------
* Change the primary color of the referenced vehicle instance.
*/
void SetPrimaryColor(SQInt32 col) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the secondary color of the referenced vehicle instance.
*/
SQInt32 GetSecondaryColor() const;
/* --------------------------------------------------------------------------------------------
* Change the secondary color of the referenced vehicle instance.
*/
void SetSecondaryColor(SQInt32 col) const;
/* --------------------------------------------------------------------------------------------
* Change the primary and secondary colors of the referenced vehicle instance.
*/
void SetColors(SQInt32 primary, SQInt32 secondary) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced vehicle instance is locked.
*/
void SetSpawnRotationEulerEx(Float32 x, Float32 y, Float32 z) const;
Uint32 GetRespawnTimer() const;
void SetRespawnTimer(Uint32 timer) const;
Float32 GetHealth() const;
void SetHealth(Float32 amount) const;
Int32 GetPrimaryColor() const;
void SetPrimaryColor(Int32 col) const;
Int32 GetSecondaryColor() const;
void SetSecondaryColor(Int32 col) const;
void SetColors(Int32 primary, Int32 secondary) const;
bool GetLocked() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced vehicle instance is locked.
*/
void SetLocked(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the part status of the referenced vehicle instance.
*/
SQInt32 GetPartStatus(SQInt32 part) const;
/* --------------------------------------------------------------------------------------------
* Change the part status of the referenced vehicle instance.
*/
void SetPartStatus(SQInt32 part, SQInt32 status) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the tyre status of the referenced vehicle instance.
*/
SQInt32 GetTyreStatus(SQInt32 tyre) const;
/* --------------------------------------------------------------------------------------------
* Change the tyre status of the referenced vehicle instance.
*/
void SetTyreStatus(SQInt32 tyre, SQInt32 status) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the damage data of the referenced vehicle instance.
*/
SQUint32 GetDamageData() const;
/* --------------------------------------------------------------------------------------------
* Change the damage data of the referenced vehicle instance.
*/
void SetDamageData(SQUint32 data) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced vehicle instance has alarm.
*/
Int32 GetPartStatus(Int32 part) const;
void SetPartStatus(Int32 part, Int32 status) const;
Int32 GetTyreStatus(Int32 tyre) const;
void SetTyreStatus(Int32 tyre, Int32 status) const;
Uint32 GetDamageData() const;
void SetDamageData(Uint32 data) const;
bool GetAlarm() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced vehicle instance has alarm.
*/
void SetAlarm(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced vehicle instance has lights.
*/
bool GetLights() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced vehicle instance has lights.
*/
void SetLights(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radio of the referenced vehicle instance.
*/
SQInt32 GetRadio() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radio of the referenced vehicle instance.
*/
void SetRadio(SQInt32 radio) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced vehicle instance has radio locked.
*/
Int32 GetRadio() const;
void SetRadio(Int32 radio) const;
bool GetRadioLocked() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced vehicle instance has radio locked.
*/
void SetRadioLocked(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the referenced vehicle instance is in ghost state.
*/
bool GetGhostState() const;
/* --------------------------------------------------------------------------------------------
* Set whether the referenced vehicle instance is in ghost state.
*/
void SetGhostState(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Reset all the handling rules for the referenced vehicle instance.
*/
void ResetHandling() const;
void ResetHandling(Int32 rule) const;
bool ExistsHandling(Int32 rule) const;
Float32 GetHandlingData(Int32 rule) const;
void SetHandlingData(Int32 rule, Float32 data) const;
void Embark(CPlayer & player) const;
void Embark(CPlayer & player, Int32 slot, bool allocate, bool warp) const;
/* --------------------------------------------------------------------------------------------
* Reset the specified handling rule for the referenced vehicle instance.
*/
void ResetHandling(SQInt32 rule) const;
// --------------------------------------------------------------------------------------------
Float32 GetPosX() const;
Float32 GetPosY() const;
Float32 GetPosZ() const;
void SetPosX(Float32 x) const;
void SetPosY(Float32 y) const;
void SetPosZ(Float32 z) const;
/* --------------------------------------------------------------------------------------------
* See whether the specified handling ruleexists in the referenced vehicle instance.
*/
bool ExistsHandling(SQInt32 rule) const;
// --------------------------------------------------------------------------------------------
Float32 GetRotX() const;
Float32 GetRotY() const;
Float32 GetRotZ() const;
Float32 GetRotW() const;
void SetRotX(Float32 x) const;
void SetRotY(Float32 y) const;
void SetRotZ(Float32 z) const;
void SetRotW(Float32 w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the handling data of the referenced vehicle instance.
*/
SQFloat GetHandlingData(SQInt32 rule) const;
/* --------------------------------------------------------------------------------------------
* Change the handling data of the referenced vehicle instance.
*/
void SetHandlingData(SQInt32 rule, SQFloat data) const;
/* --------------------------------------------------------------------------------------------
* Embark the specified player instance into the referenced vehicle instance.
*/
void Embark(const Reference< CPlayer > & player) const;
/* --------------------------------------------------------------------------------------------
* Embark the specified player instance into the referenced vehicle instance.
*/
void Embark(const Reference< CPlayer > & player, SQInt32 slot, bool allocate, bool warp) const;
// --------------------------------------------------------------------------------------------
Float32 GetERotX() const;
Float32 GetERotY() const;
Float32 GetERotZ() const;
void SetERotX(Float32 x) const;
void SetERotY(Float32 y) const;
void SetERotZ(Float32 z) const;
};
} // Namespace:: SqMod
#endif // _ENTITY_VEHICLE_HPP_
#endif // _ENTITY_VEHICLE_HPP_

File diff suppressed because it is too large Load Diff

View File

@@ -1,816 +0,0 @@
#ifndef _SQMOD_EVENT_BASIC_HPP_
#define _SQMOD_EVENT_BASIC_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
#include "Shared.hpp"
// ------------------------------------------------------------------------------------------------
#include <chrono>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
class BasicEvent
{
protected:
// --------------------------------------------------------------------------------------------
typedef std::chrono::time_point< std::chrono::steady_clock > TimePoint;
public:
/* --------------------------------------------------------------------------------------------
* ...
*/
BasicEvent();
/* --------------------------------------------------------------------------------------------
* ...
*/
BasicEvent(SQInt32 type);
/* --------------------------------------------------------------------------------------------
* ...
*/
BasicEvent(SQInt32 type, bool suspended);
/* --------------------------------------------------------------------------------------------
* ...
*/
BasicEvent(const BasicEvent &) = delete;
/* --------------------------------------------------------------------------------------------
* ...
*/
BasicEvent(BasicEvent &&) = delete;
/* --------------------------------------------------------------------------------------------
* ...
*/
~BasicEvent();
/* --------------------------------------------------------------------------------------------
* ...
*/
BasicEvent & operator = (const BasicEvent &) = delete;
/* --------------------------------------------------------------------------------------------
* ...
*/
BasicEvent & operator = (BasicEvent &&) = delete;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator == (const BasicEvent & o) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator != (const BasicEvent & o) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator < (const BasicEvent & o) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator > (const BasicEvent & o) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator <= (const BasicEvent & o) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator >= (const BasicEvent & o) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
operator SQInt32 () const
{
return m_Type;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
operator bool () const
{
return (m_Type != EVT_UNKNOWN && m_Type < EVT_COUNT);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
operator ! () const
{
return (m_Type == EVT_UNKNOWN || m_Type >= EVT_COUNT);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
void VMClose();
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Cmp(const BasicEvent & o) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * GetName() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * GetTag() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetTag(const SQChar * tag);
/* --------------------------------------------------------------------------------------------
* ...
*/
SqObj & GetData();
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetData(SqObj & data);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 GetType() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetType(SQInt32 type);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger GetIdle() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetIdle(SQInteger millis);
/* --------------------------------------------------------------------------------------------
* ...
*/
bool IsIdle() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 GetStride() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetStride(SQInt32 stride);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 GetIgnore() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetIgnore(SQInt32 ignore);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 GetPrimary() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetPrimary(SQInt32 subset);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 GetSecondary() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetSecondary(SQInt32 subset);
/* --------------------------------------------------------------------------------------------
* ...
*/
bool GetSuspended() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetSuspended(bool toggle);
/* --------------------------------------------------------------------------------------------
* ...
*/
Function GetOnTrigger() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnTrigger(Function & func);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnTrigger_Env(SqObj & env, Function & func);
/* --------------------------------------------------------------------------------------------
* ...
*/
bool Compatible(SQInt32 type) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
void BlipCreated(SQInt32 blip, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void CheckpointCreated(SQInt32 checkpoint, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void KeybindCreated(SQInt32 keybind, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ObjectCreated(SQInt32 object, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PickupCreated(SQInt32 pickup, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerCreated(SQInt32 player, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SphereCreated(SQInt32 sphere, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SpriteCreated(SQInt32 sprite, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void TextdrawCreated(SQInt32 textdraw, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleCreated(SQInt32 vehicle, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void BlipDestroyed(SQInt32 blip, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void CheckpointDestroyed(SQInt32 checkpoint, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void KeybindDestroyed(SQInt32 keybind, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ObjectDestroyed(SQInt32 object, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PickupDestroyed(SQInt32 pickup, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerDestroyed(SQInt32 player, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SphereDestroyed(SQInt32 sphere, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SpriteDestroyed(SQInt32 sprite, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void TextdrawDestroyed(SQInt32 textdraw, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleDestroyed(SQInt32 vehicle, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void BlipCustom(SQInt32 blip, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void CheckpointCustom(SQInt32 checkpoint, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void KeybindCustom(SQInt32 keybind, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ObjectCustom(SQInt32 object, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PickupCustom(SQInt32 pickup, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerCustom(SQInt32 player, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SphereCustom(SQInt32 sphere, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SpriteCustom(SQInt32 sprite, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void TextdrawCustom(SQInt32 textdraw, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleCustom(SQInt32 vehicle, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerAway(SQInt32 player, bool status);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerGameKeys(SQInt32 player, SQInt32 previous, SQInt32 current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerRename(SQInt32 player, const SQChar * previous, const SQChar * current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerRequestClass(SQInt32 player, SQInt32 offset);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerRequestSpawn(SQInt32 player);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerSpawn(SQInt32 player);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerStartTyping(SQInt32 player);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerStopTyping(SQInt32 player);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerChat(SQInt32 player, const SQChar * message);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerCommand(SQInt32 player, const SQChar * command);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerMessage(SQInt32 player, SQInt32 receiver, const SQChar * message);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerHealth(SQInt32 player, SQFloat previous, SQFloat current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerArmour(SQInt32 player, SQFloat previous, SQFloat current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerWeapon(SQInt32 player, SQInt32 previous, SQInt32 current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerMove(SQInt32 player, const Vector3 & previous, const Vector3 & current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerWasted(SQInt32 player, SQInt32 reason);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerKilled(SQInt32 player, SQInt32 killer, SQInt32 reason, SQInt32 body_part);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerTeamKill(SQInt32 player, SQInt32 killer, SQInt32 reason, SQInt32 body_part);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerSpectate(SQInt32 player, SQInt32 target);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerCrashreport(SQInt32 player, const SQChar * report);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerBurning(SQInt32 player, bool state);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerCrouching(SQInt32 player, bool state);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerState(SQInt32 player, SQInt32 previous, SQInt32 current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PlayerAction(SQInt32 player, SQInt32 previous, SQInt32 current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void StateNone(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void StateNormal(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void StateShooting(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void StateDriver(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void StatePassenger(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void StateEnterDriver(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void StateEnterPassenger(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void StateExitVehicle(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void StateUnspawned(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionNone(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionNormal(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionAiming(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionShooting(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionJumping(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionLieDown(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionGettingUp(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionJumpVehicle(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionDriving(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionDying(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionWasted(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionEmbarking(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ActionDisembarking(SQInt32 player, SQInt32 previous);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleRespawn(SQInt32 vehicle);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleExplode(SQInt32 vehicle);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleHealth(SQInt32 vehicle, SQFloat previous, SQFloat current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleMove(SQInt32 vehicle, const Vector3 & previous, const Vector3 &current);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PickupRespawn(SQInt32 pickup);
/* --------------------------------------------------------------------------------------------
* ...
*/
void KeybindKeyPress(SQInt32 player, SQInt32 keybind);
/* --------------------------------------------------------------------------------------------
* ...
*/
void KeybindKeyRelease(SQInt32 player, SQInt32 keybind);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleEmbarking(SQInt32 player, SQInt32 vehicle, SQInt32 slot);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleEmbarked(SQInt32 player, SQInt32 vehicle, SQInt32 slot);
/* --------------------------------------------------------------------------------------------
* ...
*/
void VehicleDisembark(SQInt32 player, SQInt32 vehicle);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PickupClaimed(SQInt32 player, SQInt32 pickup);
/* --------------------------------------------------------------------------------------------
* ...
*/
void PickupCollected(SQInt32 player, SQInt32 pickup);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ObjectShot(SQInt32 player, SQInt32 object, SQInt32 weapon);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ObjectBump(SQInt32 player, SQInt32 object);
/* --------------------------------------------------------------------------------------------
* ...
*/
void CheckpointEntered(SQInt32 player, SQInt32 checkpoint);
/* --------------------------------------------------------------------------------------------
* ...
*/
void CheckpointExited(SQInt32 player, SQInt32 checkpoint);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SphereEntered(SQInt32 player, SQInt32 sphere);
/* --------------------------------------------------------------------------------------------
* ...
*/
void SphereExited(SQInt32 player, SQInt32 sphere);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ServerFrame(SQFloat delta);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ServerStartup();
/* --------------------------------------------------------------------------------------------
* ...
*/
void ServerShutdown();
/* --------------------------------------------------------------------------------------------
* ...
*/
void InternalCommand(SQInt32 type, const SQChar * text);
/* --------------------------------------------------------------------------------------------
* ...
*/
void LoginAttempt(const SQChar * name, const SQChar * pass, const SQChar * addr);
/* --------------------------------------------------------------------------------------------
* ...
*/
void CustomEvent(SQInt32 group, SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void WorldOption(SQInt32 option, Object & value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void WorldToggle(SQInt32 option, bool value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void ScriptReload(SQInt32 header, Object & payload);
/* --------------------------------------------------------------------------------------------
* ...
*/
void LogMessage(SQInt32 type, const SQChar * message);
protected:
/* --------------------------------------------------------------------------------------------
* ...
*/
bool Trigger();
/* --------------------------------------------------------------------------------------------
* ...
*/
void Attach(const char * func);
/* --------------------------------------------------------------------------------------------
* ...
*/
void Detach(const char * func);
private:
// --------------------------------------------------------------------------------------------
SQInt32 m_Type;
// --------------------------------------------------------------------------------------------
SQInt32 m_Stride;
SQInt32 m_Ignore;
// --------------------------------------------------------------------------------------------
SQInt32 m_Primary;
SQInt32 m_Secondary;
// --------------------------------------------------------------------------------------------
TimePoint m_Idle;
// --------------------------------------------------------------------------------------------
Function m_OnTrigger;
// --------------------------------------------------------------------------------------------
SqTag m_Tag;
SqObj m_Data;
// --------------------------------------------------------------------------------------------
bool m_Suspended;
};
} // Namespace:: SqMod
#endif // _SQMOD_EVENT_BASIC_HPP_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,321 +0,0 @@
// ------------------------------------------------------------------------------------------------
#include "Event/Shared.hpp"
#include "Config.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const SQChar * GetEventName(SQInt32 type)
{
switch (type)
{
case EVT_BLIPCREATED: return _SC("Blip Created");
case EVT_CHECKPOINTCREATED: return _SC("Checkpoint Created");
case EVT_KEYBINDCREATED: return _SC("Keybind Created");
case EVT_OBJECTCREATED: return _SC("Object Created");
case EVT_PICKUPCREATED: return _SC("Pickup Created");
case EVT_PLAYERCREATED: return _SC("Player Created");
case EVT_SPHERECREATED: return _SC("Sphere Created");
case EVT_SPRITECREATED: return _SC("Sprite Created");
case EVT_TEXTDRAWCREATED: return _SC("Textdraw Created");
case EVT_VEHICLECREATED: return _SC("Vehicle Created");
case EVT_BLIPDESTROYED: return _SC("Blip Destroyed");
case EVT_CHECKPOINTDESTROYED: return _SC("Checkpoint Destroyed");
case EVT_KEYBINDDESTROYED: return _SC("Keybind Destroyed");
case EVT_OBJECTDESTROYED: return _SC("Object Destroyed");
case EVT_PICKUPDESTROYED: return _SC("Pickup Destroyed");
case EVT_PLAYERDESTROYED: return _SC("Player Destroyed");
case EVT_SPHEREDESTROYED: return _SC("Sphere Destroyed");
case EVT_SPRITEDESTROYED: return _SC("Sprite Destroyed");
case EVT_TEXTDRAWDESTROYED: return _SC("Textdraw Destroyed");
case EVT_VEHICLEDESTROYED: return _SC("Vehicle Destroyed");
case EVT_BLIPCUSTOM: return _SC("Blip Custom");
case EVT_CHECKPOINTCUSTOM: return _SC("Checkpoint Custom");
case EVT_KEYBINDCUSTOM: return _SC("Keybind Custom");
case EVT_OBJECTCUSTOM: return _SC("Object Custom");
case EVT_PICKUPCUSTOM: return _SC("Pickup Custom");
case EVT_PLAYERCUSTOM: return _SC("Player Custom");
case EVT_SPHERECUSTOM: return _SC("Sphere Custom");
case EVT_SPRITECUSTOM: return _SC("Sprite Custom");
case EVT_TEXTDRAWCUSTOM: return _SC("Textdraw Custom");
case EVT_VEHICLECUSTOM: return _SC("Vehicle Custom");
case EVT_PLAYERAWAY: return _SC("Player Away");
case EVT_PLAYERGAMEKEYS: return _SC("Player Game Keys");
case EVT_PLAYERRENAME: return _SC("Player Rename");
case EVT_PLAYERREQUESTCLASS: return _SC("Player Request Class");
case EVT_PLAYERREQUESTSPAWN: return _SC("Player Request Spawn");
case EVT_PLAYERSPAWN: return _SC("Player Spawn");
case EVT_PLAYERSTARTTYPING: return _SC("Player Start Typing");
case EVT_PLAYERSTOPTYPING: return _SC("Player Stop Typing");
case EVT_PLAYERCHAT: return _SC("Player Chat");
case EVT_PLAYERCOMMAND: return _SC("Player Command");
case EVT_PLAYERMESSAGE: return _SC("Player Message");
case EVT_PLAYERHEALTH: return _SC("Player Health");
case EVT_PLAYERARMOUR: return _SC("Player Armour");
case EVT_PLAYERWEAPON: return _SC("Player Weapon");
case EVT_PLAYERMOVE: return _SC("Player Move");
case EVT_PLAYERWASTED: return _SC("Player Wasted");
case EVT_PLAYERKILLED: return _SC("Player Killed");
case EVT_PLAYERTEAMKILL: return _SC("Player Team Kill");
case EVT_PLAYERSPECTATE: return _SC("Player Spectate");
case EVT_PLAYERCRASHREPORT: return _SC("Player Crash Report");
case EVT_PLAYERBURNING: return _SC("Player Burning");
case EVT_PLAYERCROUCHING: return _SC("Player Crouching");
case EVT_PLAYERSTATE: return _SC("Player State");
case EVT_PLAYERACTION: return _SC("Player Action");
case EVT_STATENONE: return _SC("State None");
case EVT_STATENORMAL: return _SC("State Normal");
case EVT_STATESHOOTING: return _SC("State Shooting");
case EVT_STATEDRIVER: return _SC("State Driver");
case EVT_STATEPASSENGER: return _SC("State Passenger");
case EVT_STATEENTERDRIVER: return _SC("State Enter Driver");
case EVT_STATEENTERPASSENGER: return _SC("State Enter Passenger");
case EVT_STATEEXITVEHICLE: return _SC("State Exit Vehicle");
case EVT_STATEUNSPAWNED: return _SC("State Unspawned");
case EVT_ACTIONNONE: return _SC("Action None");
case EVT_ACTIONNORMAL: return _SC("Action Normal");
case EVT_ACTIONAIMING: return _SC("Action Aiming");
case EVT_ACTIONSHOOTING: return _SC("Action Shooting");
case EVT_ACTIONJUMPING: return _SC("Action Jumping");
case EVT_ACTIONLIEDOWN: return _SC("Action Lie Down");
case EVT_ACTIONGETTINGUP: return _SC("Action Getting Up");
case EVT_ACTIONJUMPVEHICLE: return _SC("Action Jump Vehicle");
case EVT_ACTIONDRIVING: return _SC("Action Driving");
case EVT_ACTIONDYING: return _SC("Action Dying");
case EVT_ACTIONWASTED: return _SC("Action Wasted");
case EVT_ACTIONEMBARKING: return _SC("Action Embarking");
case EVT_ACTIONDISEMBARKING: return _SC("Action Disembarking");
case EVT_VEHICLERESPAWN: return _SC("Vehicle Respawn");
case EVT_VEHICLEEXPLODE: return _SC("Vehicle Explode");
case EVT_VEHICLEHEALTH: return _SC("Vehicle Health");
case EVT_VEHICLEMOVE: return _SC("Vehicle Move");
case EVT_PICKUPRESPAWN: return _SC("Pickup Respawn");
case EVT_KEYBINDKEYPRESS: return _SC("Keybind Key Press");
case EVT_KEYBINDKEYRELEASE: return _SC("Keybind Key Release");
case EVT_VEHICLEEMBARKING: return _SC("Vehicle Embarking");
case EVT_VEHICLEEMBARKED: return _SC("Vehicle Embarked");
case EVT_VEHICLEDISEMBARK: return _SC("Vehicle Disembark");
case EVT_PICKUPCLAIMED: return _SC("Pickup Claimed");
case EVT_PICKUPCOLLECTED: return _SC("Pickup Collected");
case EVT_OBJECTSHOT: return _SC("Object Shot");
case EVT_OBJECTBUMP: return _SC("Object Bump");
case EVT_CHECKPOINTENTERED: return _SC("Checkpoint Entered");
case EVT_CHECKPOINTEXITED: return _SC("Checkpoint Exited");
case EVT_SPHEREENTERED: return _SC("Sphere Entered");
case EVT_SPHEREEXITED: return _SC("Sphere Exited");
case EVT_SERVERFRAME: return _SC("Server Frame");
case EVT_SERVERSTARTUP: return _SC("Server Startup");
case EVT_SERVERSHUTDOWN: return _SC("Server Shutdown");
case EVT_INTERNALCOMMAND: return _SC("Internal Command");
case EVT_LOGINATTEMPT: return _SC("Login Attempt");
case EVT_CUSTOMEVENT: return _SC("Custom Event");
case EVT_WORLDOPTION: return _SC("World Option");
case EVT_WORLDTOGGLE: return _SC("World Toggle");
case EVT_SCRIPTRELOAD: return _SC("Script Reload");
default: return _SC("Unknown");
}
}
// ------------------------------------------------------------------------------------------------
bool IsEntityEvent(SQInt32 type)
{
switch (type)
{
case EVT_BLIPCREATED:
case EVT_CHECKPOINTCREATED:
case EVT_KEYBINDCREATED:
case EVT_OBJECTCREATED:
case EVT_PICKUPCREATED:
case EVT_PLAYERCREATED:
case EVT_SPHERECREATED:
case EVT_SPRITECREATED:
case EVT_TEXTDRAWCREATED:
case EVT_VEHICLECREATED:
case EVT_BLIPDESTROYED:
case EVT_CHECKPOINTDESTROYED:
case EVT_KEYBINDDESTROYED:
case EVT_OBJECTDESTROYED:
case EVT_PICKUPDESTROYED:
case EVT_PLAYERDESTROYED:
case EVT_SPHEREDESTROYED:
case EVT_SPRITEDESTROYED:
case EVT_TEXTDRAWDESTROYED:
case EVT_VEHICLEDESTROYED:
case EVT_BLIPCUSTOM:
case EVT_CHECKPOINTCUSTOM:
case EVT_KEYBINDCUSTOM:
case EVT_OBJECTCUSTOM:
case EVT_PICKUPCUSTOM:
case EVT_PLAYERCUSTOM:
case EVT_SPHERECUSTOM:
case EVT_SPRITECUSTOM:
case EVT_TEXTDRAWCUSTOM:
case EVT_VEHICLECUSTOM:
case EVT_PLAYERAWAY:
case EVT_PLAYERGAMEKEYS:
case EVT_PLAYERRENAME:
case EVT_PLAYERREQUESTCLASS:
case EVT_PLAYERREQUESTSPAWN:
case EVT_PLAYERSPAWN:
case EVT_PLAYERSTARTTYPING:
case EVT_PLAYERSTOPTYPING:
case EVT_PLAYERCHAT:
case EVT_PLAYERCOMMAND:
case EVT_PLAYERMESSAGE:
case EVT_PLAYERHEALTH:
case EVT_PLAYERARMOUR:
case EVT_PLAYERWEAPON:
case EVT_PLAYERMOVE:
case EVT_PLAYERWASTED:
case EVT_PLAYERKILLED:
case EVT_PLAYERTEAMKILL:
case EVT_PLAYERSPECTATE:
case EVT_PLAYERCRASHREPORT:
case EVT_PLAYERBURNING:
case EVT_PLAYERCROUCHING:
case EVT_PLAYERSTATE:
case EVT_PLAYERACTION:
case EVT_STATENONE:
case EVT_STATENORMAL:
case EVT_STATESHOOTING:
case EVT_STATEDRIVER:
case EVT_STATEPASSENGER:
case EVT_STATEENTERDRIVER:
case EVT_STATEENTERPASSENGER:
case EVT_STATEEXITVEHICLE:
case EVT_STATEUNSPAWNED:
case EVT_ACTIONNONE:
case EVT_ACTIONNORMAL:
case EVT_ACTIONAIMING:
case EVT_ACTIONSHOOTING:
case EVT_ACTIONJUMPING:
case EVT_ACTIONLIEDOWN:
case EVT_ACTIONGETTINGUP:
case EVT_ACTIONJUMPVEHICLE:
case EVT_ACTIONDRIVING:
case EVT_ACTIONDYING:
case EVT_ACTIONWASTED:
case EVT_ACTIONEMBARKING:
case EVT_ACTIONDISEMBARKING:
case EVT_VEHICLERESPAWN:
case EVT_VEHICLEEXPLODE:
case EVT_VEHICLEHEALTH:
case EVT_VEHICLEMOVE:
case EVT_PICKUPRESPAWN:
case EVT_KEYBINDKEYPRESS:
case EVT_KEYBINDKEYRELEASE:
case EVT_VEHICLEEMBARKING:
case EVT_VEHICLEEMBARKED:
case EVT_VEHICLEDISEMBARK:
case EVT_PICKUPCLAIMED:
case EVT_PICKUPCOLLECTED:
case EVT_OBJECTSHOT:
case EVT_OBJECTBUMP:
case EVT_CHECKPOINTENTERED:
case EVT_CHECKPOINTEXITED:
case EVT_SPHEREENTERED:
case EVT_SPHEREEXITED:
return true;
default:
return false;
}
}
// ------------------------------------------------------------------------------------------------
bool IsCreateEvent(SQInt32 type)
{
switch (type)
{
case EVT_BLIPCREATED:
case EVT_CHECKPOINTCREATED:
case EVT_KEYBINDCREATED:
case EVT_OBJECTCREATED:
case EVT_PICKUPCREATED:
case EVT_PLAYERCREATED:
case EVT_SPHERECREATED:
case EVT_SPRITECREATED:
case EVT_TEXTDRAWCREATED:
case EVT_VEHICLECREATED:
return true;
default:
return false;
}
}
// ------------------------------------------------------------------------------------------------
bool IsDestroyEvent(SQInt32 type)
{
switch (type)
{
case EVT_BLIPDESTROYED:
case EVT_CHECKPOINTDESTROYED:
case EVT_KEYBINDDESTROYED:
case EVT_OBJECTDESTROYED:
case EVT_PICKUPDESTROYED:
case EVT_PLAYERDESTROYED:
case EVT_SPHEREDESTROYED:
case EVT_SPRITEDESTROYED:
case EVT_TEXTDRAWDESTROYED:
case EVT_VEHICLEDESTROYED:
return true;
default:
return false;
}
}
// ------------------------------------------------------------------------------------------------
bool IsCustomEvent(SQInt32 type)
{
switch (type)
{
case EVT_BLIPCUSTOM:
case EVT_CHECKPOINTCUSTOM:
case EVT_KEYBINDCUSTOM:
case EVT_OBJECTCUSTOM:
case EVT_PICKUPCUSTOM:
case EVT_PLAYERCUSTOM:
case EVT_SPHERECUSTOM:
case EVT_SPRITECUSTOM:
case EVT_TEXTDRAWCUSTOM:
case EVT_VEHICLECUSTOM:
return true;
default:
return false;
}
}
// ------------------------------------------------------------------------------------------------
bool CanBeInversed(SQInt32 type)
{
switch (type)
{
case EVT_KEYBINDKEYPRESS:
case EVT_KEYBINDKEYRELEASE:
case EVT_VEHICLEEMBARKING:
case EVT_VEHICLEEMBARKED:
case EVT_VEHICLEDISEMBARK:
case EVT_PICKUPCLAIMED:
case EVT_PICKUPCOLLECTED:
case EVT_OBJECTSHOT:
case EVT_OBJECTBUMP:
case EVT_CHECKPOINTENTERED:
case EVT_CHECKPOINTEXITED:
case EVT_SPHEREENTERED:
case EVT_SPHEREEXITED:
return true;
default:
return false;
}
}
// ================================================================================================
bool Register_Event(HSQUIRRELVM vm)
{
SQMOD_UNUSED_VAR(vm);
return true;
}
} // Namespace:: SqMod

View File

@@ -1,42 +0,0 @@
#ifndef _SQMOD_EVENT_SHARED_HPP_
#define _SQMOD_EVENT_SHARED_HPP_
// ------------------------------------------------------------------------------------------------
#include "Signal.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
const SQChar * GetEventName(SQInt32 type);
/* ------------------------------------------------------------------------------------------------
* ...
*/
bool IsEntityEvent(SQInt32 type);
/* ------------------------------------------------------------------------------------------------
* ...
*/
bool IsCreateEvent(SQInt32 type);
/* ------------------------------------------------------------------------------------------------
* ...
*/
bool IsDestroyEvent(SQInt32 type);
/* ------------------------------------------------------------------------------------------------
* ...
*/
bool IsCustomEvent(SQInt32 type);
/* ------------------------------------------------------------------------------------------------
* ...
*/
bool CanBeInversed(SQInt32 type);
} // Namespace:: SqMod
#endif // _SQMOD_EVENT_SHARED_HPP_

View File

View File

View File

@@ -1,14 +0,0 @@
#include "Library/Datetime.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Register_Datetime(HSQUIRRELVM vm)
{
SQMOD_UNUSED_VAR(vm);
return true;
}
} // Namespace:: SqMod

View File

@@ -1,16 +0,0 @@
#ifndef _LIBRARY_DATETIME_HPP_
#define _LIBRARY_DATETIME_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
} // Namespace:: SqMod
#endif // _LIBRARY_DATETIME_HPP_

View File

@@ -1,14 +0,0 @@
#include "Library/FileIO.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Register_FileIO(HSQUIRRELVM vm)
{
SQMOD_UNUSED_VAR(vm);
return true;
}
} // Namespace:: SqMod

View File

@@ -1,16 +0,0 @@
#ifndef _LIBRARY_FILEIO_HPP_
#define _LIBRARY_FILEIO_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
} // Namespace:: SqMod
#endif // _LIBRARY_FILEIO_HPP_

View File

@@ -1,167 +0,0 @@
#include "Library/Format.hpp"
#include "Register.hpp"
#include "Logger.hpp"
#include "Core.hpp"
// ------------------------------------------------------------------------------------------------
#include <format.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
static const SQChar * GetTypeName(SQObjectType type_id)
{
switch (type_id)
{
case OT_INTEGER:
return _SC("integer");
case OT_FLOAT:
return _SC("float");
case OT_STRING:
return _SC("string");
case OT_BOOL:
return _SC("boolean");
case OT_USERPOINTER:
return _SC("user pointer");
case OT_NULL:
return _SC("null");
case OT_TABLE:
return _SC("table");
case OT_ARRAY:
return _SC("array");
case OT_CLOSURE:
return _SC("closure");
case OT_NATIVECLOSURE:
return _SC("native closure");
case OT_GENERATOR:
return _SC("generator");
case OT_USERDATA:
return _SC("user data");
case OT_THREAD:
return _SC("thread");
case OT_CLASS:
return _SC("class");
case OT_INSTANCE:
return _SC("instance");
case OT_WEAKREF:
return _SC("weak reference");
default:
return _SC("unknown");
}
}
// ------------------------------------------------------------------------------------------------
String GetFormatStr(HSQUIRRELVM vm, SQInteger arg, SQInteger args)
{
if (sq_gettype(vm, arg) == OT_STRING)
{
const SQChar * str = 0;
sq_getstring(vm, arg, &str);
return GetFormatStr(vm, (str == NULL ? "" : str), ++arg, args);
}
else
{
LogErr("Expecting format string but got: %s", GetTypeName(sq_gettype(vm, arg)));
}
return String();
}
// ------------------------------------------------------------------------------------------------
String GetFormatStr(HSQUIRRELVM vm, const String & fstr, SQInteger arg, SQInteger args)
{
using namespace fmt::internal;
String str;
if (args-arg > 15)
{
LogErr("Too many arguments to format");
return str;
}
else if (fstr.empty())
{
return str;
}
else if (arg == args)
{
// Unnecessary but should throw an error when trying to format something without arguments
try
{
str = fmt::format(fstr);
}
catch (const fmt::SystemError & e)
{
LogErr(e.what());
}
return str;
}
const SQChar * sval = 0;
SQInteger ival;
SQFloat fval;
SQUserPointer pval;
std::vector< MakeValue< SQChar > > vlist;
vlist.reserve(args-arg);
std::uint64_t vtype = 0x0;
for (unsigned sh = 0;arg <= args; arg++, sh += 4)
{
switch(sq_gettype(vm, arg))
{
case OT_INTEGER:
sq_getinteger(vm, arg, &ival);
vlist.emplace_back(ival);
vtype |= (MakeValue< SQChar >::type(ival) << sh);
break;
case OT_FLOAT:
sq_getfloat(vm, arg, &fval);
vlist.emplace_back(fval);
vtype |= (MakeValue< SQChar >::type(fval) << sh);
break;
case OT_STRING:
sq_getstring(vm, arg, &sval);
vlist.emplace_back(sval);
vtype |= (MakeValue< SQChar >::type(sval) << sh);
break;
case OT_BOOL:
sq_getinteger(vm, arg, &ival);
vlist.emplace_back(static_cast<unsigned char>(ival));
vtype |= (MakeValue< SQChar >::type(static_cast<unsigned char>(ival)) << sh);
break;
case OT_USERPOINTER:
sq_getuserpointer(vm, arg, &pval);
vlist.emplace_back(static_cast<void *>(pval));
vtype |= (MakeValue< SQChar >::type(static_cast<void *>(pval)) << sh);
break;
default:
LogErr("Cannot format (%s) data type", GetTypeName(sq_gettype(vm, arg)));
return str;
}
}
vlist.shrink_to_fit();
try
{
fmt::BasicMemoryWriter<SQChar> w;
w.write(fstr, fmt::ArgList(vtype, vlist.data()));
str = w.c_str();
}
catch (const fmt::SystemError & e)
{
LogErr("%s", e.what());
}
return str;
}
// ------------------------------------------------------------------------------------------------
bool Register_Format(HSQUIRRELVM vm)
{
SQMOD_UNUSED_VAR(vm);
return true;
}
} // Namespace:: SqMod

View File

@@ -1,16 +0,0 @@
#ifndef _LIBRARY_FORMAT_HPP_
#define _LIBRARY_FORMAT_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
String GetFormatStr(HSQUIRRELVM vm, SQInteger arg, SQInteger args);
String GetFormatStr(HSQUIRRELVM vm, const String & fstr, SQInteger arg, SQInteger args);
} // Namespace:: SqMod
#endif // _LIBRARY_FORMAT_HPP_

View File

@@ -1,5 +1,6 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Hashing.hpp"
#include "Register.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
#include <sqstdstring.h>
@@ -29,122 +30,74 @@ template < class T > T BaseHash< T >::Algo;
// ------------------------------------------------------------------------------------------------
template < class T > static SQInteger HashF(HSQUIRRELVM vm)
{
const SQInteger top = sq_gettop(vm);
// Are there any arguments on the stack?
const Int32 top = sq_gettop(vm);
Object ret;
if (top <= 1)
{
LogErr("Attempting to <hash string> without specifying a value");
// Push a null value on the stack
sq_pushnull(vm);
}
// Is there a single string or at least something that can convert to a string on the stack?
SqThrow("Missing the hash string");
else if (top == 2 && ((sq_gettype(vm, -1) == OT_STRING) || !SQ_FAILED(sq_tostring(vm, -1))))
{
// Variable where the resulted string will be retrieved
const SQChar * msg = 0;
// Attempt to retrieve the specified string from the stack
if (SQ_FAILED(sq_getstring(vm, -1, &msg)))
{
LogErr("Unable to <hash string> because : the string cannot be retrieved from the stack");
// Pop any pushed values pushed to the stack
sq_settop(vm, top);
// Push a null value on the stack
sq_pushnull(vm);
}
CCStr str = 0;
if (SQ_FAILED(sq_getstring(vm, -1, &str)))
SqThrow("Unable to retrieve the string");
else
{
// Pop any pushed values pushed to the stack
sq_settop(vm, top);
// Hash the specified string
sq_pushstring(vm, BaseHash< T >::Algo(msg).c_str(), -1);
}
ret = MakeObject(vm, BaseHash< T >::Algo(str));
sq_settop(vm, top);
}
else if (top > 2)
{
// Variables containing the resulted string
SQChar * msg = NULL;
CStr str = NULL;
SQInteger len = 0;
// Attempt to call the format function with the passed arguments
if (SQ_FAILED(sqstd_format(vm, 2, &len, &msg)))
{
LogErr("Unable to <hash string> because : %s", Error::Message(vm).c_str());
// Push a null value on the stack
sq_pushnull(vm);
}
if (SQ_FAILED(sqstd_format(vm, 2, &len, &str)))
SqThrow("Unable to generate the string [%s]", Error::Message(vm).c_str());
else
{
// Pop any pushed values pushed to the stack
sq_settop(vm, top);
// Hash the specified string
sq_pushstring(vm, BaseHash< T >::Algo(msg).c_str(), -1);
}
ret = MakeObject(vm, BaseHash< T >::Algo(str));
}
else
{
LogErr("Unable to <extract the log message> from the specified value");
// Push a null value on the stack
sq_pushnull(vm);
}
// At this point everything went correctly (probably)
SqThrow("Unable to extract the hash string");
Var< Object >::push(vm, ret);
return 1;
}
// ================================================================================================
template < class T > static bool RegisterWrapper(HSQUIRRELVM vm, const SQChar * cname)
template < class T > static void RegisterWrapper(Table & hashns, CCStr cname)
{
// Typedef the reference type to simplify code
typedef HashWrapper< T > Hash;
// Output debugging information
LogDbg("Beginning registration of <%s> type", cname);
// Attempt to register the specified type
Sqrat::RootTable(vm).Bind(cname, Sqrat::Class< Hash >(vm, cname)
hashns.Bind(cname, Class< Hash >(hashns.GetVM(), cname)
/* Constructors */
.Ctor()
/* Metamethods */
.Func(_SC("_tostring"), &Hash::ToString)
/* Properties */
.Prop(_SC("hash"), &Hash::GetHash)
.Prop(_SC("Hash"), &Hash::GetHash)
/* Functions */
.Func(_SC("reset"), &Hash::Reset)
.Func(_SC("compute"), &Hash::Compute)
.Func(_SC("get_hash"), &Hash::GetHash)
.Func(_SC("add"), &Hash::AddStr)
.Func(_SC("add_str"), &Hash::AddStr)
.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)
);
// Output debugging information
LogDbg("Registration of <%s> type was successful", cname);
// Registration succeeded
return true;
}
// ------------------------------------------------------------------------------------------------
bool Register_Hash(HSQUIRRELVM vm)
// ================================================================================================
void Register_Hash(HSQUIRRELVM vm)
{
// Attempt to register the hash wrapers
if (!RegisterWrapper< CRC32 >(vm, _SC("CHashCRC32")) ||
!RegisterWrapper< Keccak >(vm, _SC("CHashKeccak")) ||
!RegisterWrapper< MD5 >(vm, _SC("CHashMD5")) ||
!RegisterWrapper< SHA1 >(vm, _SC("CHashSHA1")) ||
!RegisterWrapper< SHA256 >(vm, _SC("CHashSHA256")) ||
!RegisterWrapper< SHA3 >(vm, _SC("CHashSHA3")))
{
return false;
}
// Output debugging information
LogDbg("Beginning registration of <Hashing functions> type");
// Attempt to register the free functions
Sqrat::RootTable(vm)
.SquirrelFunc(_SC("HashCRC32"), &HashF< CRC32 >)
.SquirrelFunc(_SC("HashKeccak"), &HashF< Keccak >)
.SquirrelFunc(_SC("HashMD5"), &HashF< MD5 >)
.SquirrelFunc(_SC("HashSHA1"), &HashF< SHA1 >)
.SquirrelFunc(_SC("HashSHA256"), &HashF< SHA256 >)
.SquirrelFunc(_SC("HashSHA3"), &HashF< SHA3 >);
// Output debugging information
LogDbg("Registration of <Hashing functions> type was successful");
// Registration succeeded
return true;
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("Hash"), hashns);
}
} // Namespace:: SqMod

View File

@@ -1,88 +1,51 @@
#ifndef _LIBRARY_CFG_HPP_
#define _LIBRARY_CFG_HPP_
#ifndef _LIBRARY_HASHING_HPP_
#define _LIBRARY_HASHING_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
// ------------------------------------------------------------------------------------------------
template < class T > class HashWrapper
{
public:
/* --------------------------------------------------------------------------------------------
* ...
*/
HashWrapper() = default;
/* --------------------------------------------------------------------------------------------
* ...
*/
HashWrapper(const HashWrapper & o) = default;
/* --------------------------------------------------------------------------------------------
* ...
*/
HashWrapper(HashWrapper && o) = default;
/* --------------------------------------------------------------------------------------------
* ...
*/
~HashWrapper() = default;
/* --------------------------------------------------------------------------------------------
* ...
*/
HashWrapper & operator = (const HashWrapper & o) = default;
/* --------------------------------------------------------------------------------------------
* ...
*/
HashWrapper & operator = (HashWrapper && o) = default;
/* --------------------------------------------------------------------------------------------
* ...
*/
String ToString()
// --------------------------------------------------------------------------------------------
HashWrapper()
: m_Encoder()
{
return m_Encoder.getHash();
}
/* --------------------------------------------------------------------------------------------
* ...
*/
void Reset()
// --------------------------------------------------------------------------------------------
HashWrapper(const HashWrapper & o)
: m_Encoder(o.m_Encoder)
{
m_Encoder.reset();
}
/* --------------------------------------------------------------------------------------------
* ...
*/
String Compute(const String & str)
// --------------------------------------------------------------------------------------------
~HashWrapper()
{
return m_Encoder(str);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
String GetHash()
// --------------------------------------------------------------------------------------------
HashWrapper & operator = (const HashWrapper & o)
{
return m_Encoder.getHash();
m_Encoder = o.m_Encoder;
return *this;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
// --------------------------------------------------------------------------------------------
String ToString() { return m_Encoder.getHash(); }
void Reset() { m_Encoder.reset(); }
String Compute(const String & str) { return m_Encoder(str); }
String GetHash() { return m_Encoder.getHash(); }
void AddStr(const String & str)
{
m_Encoder.add(str.data(), str.length() * sizeof(String::value_type));
}
{ m_Encoder.add(str.data(), str.length() * sizeof(String::value_type)); }
private:
@@ -92,4 +55,4 @@ private:
} // Namespace:: SqMod
#endif // _LIBRARY_CFG_HPP_
#endif // _LIBRARY_HASHING_HPP_

View File

@@ -1,14 +0,0 @@
#include "Library/INI.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Register_INI(HSQUIRRELVM vm)
{
SQMOD_UNUSED_VAR(vm);
return true;
}
} // Namespace:: SqMod

View File

@@ -1,16 +0,0 @@
#ifndef _LIBRARY_INI_HPP_
#define _LIBRARY_INI_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
} // Namespace:: SqMod
#endif // _LIBRARY_INI_HPP_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +0,0 @@
#include "Library/JSON.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Register_JSON(HSQUIRRELVM vm)
{
SQMOD_UNUSED_VAR(vm);
return true;
}
} // Namespace:: SqMod

View File

@@ -1,16 +0,0 @@
#ifndef _LIBRARY_JSON_HPP_
#define _LIBRARY_JSON_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
} // Namespace:: SqMod
#endif // _LIBRARY_JSON_HPP_

View File

@@ -1,62 +0,0 @@
#include "Library/LongInt.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Register_LongInt(HSQUIRRELVM vm)
{
// Output debugging information
LogDbg("Beginning registration of <Long integer> type");
// Attempt to register the specified type
Sqrat::RootTable(vm).Bind(_SC("SLongInt"), Sqrat::Class< SLongInt >(vm, _SC("SLongInt"))
/* Constructors */
.Ctor()
.Ctor< SLongInt::Type >()
.template Ctor< const SQChar *, SQInteger >()
/* Properties */
.Prop(_SC("str"), &SLongInt::GetCStr, &SLongInt::SetStr)
.Prop(_SC("num"), &SLongInt::GetSNum, &SLongInt::SetNum)
/* Metamethods */
.Func(_SC("_tostring"), &SLongInt::ToString)
.Func(_SC("_cmp"), &SLongInt::Cmp)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_add"), &SLongInt::operator +)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_sub"), &SLongInt::operator -)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_mul"), &SLongInt::operator *)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_div"), &SLongInt::operator /)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_modulo"), &SLongInt::operator %)
.Func< SLongInt (SLongInt::*)(void) const >(_SC("_unm"), &SLongInt::operator -)
/* Overloads */
.Overload< void (SLongInt::*)(void) >(_SC("random"), &SLongInt::Random)
.Overload< void (SLongInt::*)(SLongInt::Type, SLongInt::Type) >(_SC("random"), &SLongInt::Random)
);
// Attempt to register the specified type
Sqrat::RootTable(vm).Bind(_SC("ULongInt"), Sqrat::Class< ULongInt >(vm, _SC("ULongInt"))
/* Constructors */
.Ctor()
.Ctor< ULongInt::Type >()
.Ctor< const SQChar *, SQInteger >()
/* Properties */
.Prop(_SC("str"), &ULongInt::GetCStr, &ULongInt::SetStr)
.Prop(_SC("num"), &ULongInt::GetSNum, &ULongInt::SetNum)
/* Metamethods */
.Func(_SC("_tostring"), &ULongInt::ToString)
.Func(_SC("_cmp"), &ULongInt::Cmp)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_add"), &ULongInt::operator +)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_sub"), &ULongInt::operator -)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_mul"), &ULongInt::operator *)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_div"), &ULongInt::operator /)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_modulo"), &ULongInt::operator %)
.Func< ULongInt (ULongInt::*)(void) const >(_SC("_unm"), &ULongInt::operator -)
/* Overloads */
.Overload< void (ULongInt::*)(void) >(_SC("random"), &ULongInt::Random)
.Overload< void (ULongInt::*)(ULongInt::Type, ULongInt::Type) >(_SC("random"), &ULongInt::Random)
);
// Output debugging information
LogDbg("Registration of <IRCSession> type was successful");
// Registration succeeded
return true;
}
} // Namespace:: SqMod

View File

@@ -1,349 +0,0 @@
#ifndef _LIBRARY_LONGINT_HPP_
#define _LIBRARY_LONGINT_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <stdexcept>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
template < typename T > class LongInt
{
public:
// --------------------------------------------------------------------------------------------
static_assert(std::is_integral< T >::value, "LongInt type is not an integral type");
// --------------------------------------------------------------------------------------------
typedef T Type;
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt()
: m_Data(0), m_Text()
{
}
/* --------------------------------------------------------------------------------------------
* ...
*/
template <typename U> LongInt(U data)
{
*this = data;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt(const SQChar * text)
{
*this = text;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt(const SQChar * text, SQInteger overload)
{
SQMOD_UNUSED_VAR(overload);
*this = text;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt(const LongInt<T> & o)
: m_Data(o.m_Data), m_Text(o.m_Text)
{
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt(LongInt<T> && o)
: m_Data(o.m_Data), m_Text(std::move(o.m_Text))
{
}
/* --------------------------------------------------------------------------------------------
* ...
*/
~LongInt()
{
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt & operator = (const LongInt<T> & o)
{
m_Data = o.m_Data;
m_Text = o.m_Text;
return *this;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt & operator = (LongInt<T> && o)
{
m_Data = o.m_Data;
m_Text = std::move(o.m_Text);
return *this;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
template <typename U, typename std::enable_if<std::is_integral<U>::value>::type* = nullptr>
LongInt & operator = (U data)
{
m_Data = static_cast< Type >(data);
m_Text = std::to_string(m_Data);
return *this;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt & operator = (const SQChar * text)
{
m_Text = text;
try
{
m_Data = SToI< T >::Fn(text, 0, 10);
}
catch (const std::invalid_argument & e)
{
LogErr("Unable to extract number: %s", e.what());
}
return *this;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator == (const LongInt<T> & o) const
{
return (m_Data == o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator != (const LongInt<T> & o) const
{
return (m_Data != o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator < (const LongInt<T> & o) const
{
return (m_Data < o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator > (const LongInt<T> & o) const
{
return (m_Data > o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator <= (const LongInt<T> & o) const
{
return (m_Data <= o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
bool operator >= (const LongInt<T> & o) const
{
return (m_Data >= o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
inline operator T () const
{
return m_Data;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt<T> operator + (const LongInt<T> & o) const
{
return LongInt<T>(m_Data + o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt<T> operator - (const LongInt<T> & o) const
{
return LongInt<T>(m_Data - o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt<T> operator * (const LongInt<T> & o) const
{
return LongInt<T>(m_Data * o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt<T> operator / (const LongInt<T> & o) const
{
return LongInt<T>(m_Data / o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt<T> operator % (const LongInt<T> & o) const
{
return LongInt<T>(m_Data % o.m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
LongInt<T> operator - () const
{
return LongInt<T>(-m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger Cmp(const LongInt<T> & o) const
{
if (m_Data == o.m_Data)
{
return 0;
}
else if (m_Data > o.m_Data)
{
return 1;
}
else
{
return -1;
}
}
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const
{
return m_Text.c_str();
}
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetNum(T data)
{
*this = data;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
T GetNum() const
{
return m_Data;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger GetSNum() const
{
return static_cast< SQInteger >(m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetStr(const SQChar * text)
{
*this = text;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
const String & GetStr() const
{
return m_Text;
}
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * GetCStr() const
{
return m_Text.c_str();
}
/* --------------------------------------------------------------------------------------------
* ...
*/
void Random()
{
m_Data = RandomVal<T>::Get();
m_Text = std::to_string(m_Data);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
void Random(T min, T max)
{
m_Data = RandomVal<T>::Get(min, max);
m_Text = std::to_string(m_Data);
}
private:
/* --------------------------------------------------------------------------------------------
* ...
*/
T m_Data;
/* --------------------------------------------------------------------------------------------
* ...
*/
String m_Text;
};
// ------------------------------------------------------------------------------------------------
typedef LongInt< Int64 > SLongInt;
typedef LongInt< Uint64 > ULongInt;
} // Namespace:: SqMod
#endif // _LIBRARY_LONGINT_HPP_

View File

@@ -1,14 +0,0 @@
#include "Library/Math.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Register_Math(HSQUIRRELVM vm)
{
SQMOD_UNUSED_VAR(vm);
return true;
}
} // Namespace:: SqMod

View File

@@ -1,16 +0,0 @@
#ifndef _LIBRARY_MATH_HPP_
#define _LIBRARY_MATH_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
} // Namespace:: SqMod
#endif // _LIBRARY_MATH_HPP_

View File

@@ -1,14 +1,120 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Numeric.hpp"
#include "Register.hpp"
#include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Register_Numeric(HSQUIRRELVM vm)
LongInt< Int64 >::LongInt(CSStr text) : m_Data(0), m_Text()
{ m_Data = strtoll(text, NULL, 10); }
LongInt< Int64 >::LongInt(CSStr text, Object & /* null */) : m_Data(0), m_Text()
{ m_Data = strtoll(text, NULL, 10); }
// ------------------------------------------------------------------------------------------------
LongInt< Int64 > & LongInt< Int64 >::operator = (CSStr text)
{
SQMOD_UNUSED_VAR(vm);
return true;
m_Data = strtoll(text, NULL, 10);
return *this;
}
// ------------------------------------------------------------------------------------------------
CSStr LongInt< Int64 >::ToString()
{
if (snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0)
{
m_Text[0] = 0;
}
return m_Text;
}
// ------------------------------------------------------------------------------------------------
void LongInt< Int64 >::Random() { m_Data = GetRandomInt64(); }
void LongInt< Int64 >::Random(Type n) { m_Data = GetRandomInt64(n); }
void LongInt< Int64 >::Random(Type m, Type n) { m_Data = GetRandomInt64(m, n); }
// ------------------------------------------------------------------------------------------------
LongInt< Uint64 >::LongInt(CSStr text) : m_Data(0), m_Text()
{ m_Data = strtoll(text, NULL, 10); }
LongInt< Uint64 >::LongInt(CSStr text, Object & /* null */) : m_Data(0), m_Text()
{ m_Data = strtoll(text, NULL, 10); }
// ------------------------------------------------------------------------------------------------
LongInt< Uint64 > & LongInt< Uint64 >::operator = (CSStr text)
{
m_Data = strtoll(text, NULL, 10);
return *this;
}
// ------------------------------------------------------------------------------------------------
CSStr LongInt< Uint64 >::ToString()
{
if (snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0)
{
m_Text[0] = 0;
}
return m_Text;
}
// ------------------------------------------------------------------------------------------------
void LongInt< Uint64 >::Random() { m_Data = GetRandomUint64(); }
void LongInt< Uint64 >::Random(Type n) { m_Data = GetRandomUint64(n); }
void LongInt< Uint64 >::Random(Type m, Type n) { m_Data = GetRandomUint64(m, n); }
// ================================================================================================
void Register_Numeric(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SLongInt"), Class< SLongInt >(vm, _SC("SLongInt"))
/* Constructors */
.Ctor()
.Ctor< SLongInt::Type >()
.template Ctor< CCStr, Object & >()
/* Properties */
.Prop(_SC("Str"), &SLongInt::GetCStr, &SLongInt::SetStr)
.Prop(_SC("Num"), &SLongInt::GetSNum, &SLongInt::SetNum)
/* Metamethods */
.Func(_SC("_tostring"), &SLongInt::ToString)
.Func(_SC("_cmp"), &SLongInt::Cmp)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_add"), &SLongInt::operator +)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_sub"), &SLongInt::operator -)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_mul"), &SLongInt::operator *)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_div"), &SLongInt::operator /)
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_modulo"), &SLongInt::operator %)
.Func< SLongInt (SLongInt::*)(void) const >(_SC("_unm"), &SLongInt::operator -)
/* Overloads */
.Overload< void (SLongInt::*)(void) >(_SC("Random"), &SLongInt::Random)
.Overload< void (SLongInt::*)(SLongInt::Type) >(_SC("Random"), &SLongInt::Random)
.Overload< void (SLongInt::*)(SLongInt::Type, SLongInt::Type) >(_SC("Random"), &SLongInt::Random)
);
RootTable(vm).Bind(_SC("ULongInt"), Class< ULongInt >(vm, _SC("ULongInt"))
/* Constructors */
.Ctor()
.Ctor< ULongInt::Type >()
.Ctor< CCStr, Object & >()
/* Properties */
.Prop(_SC("Str"), &ULongInt::GetCStr, &ULongInt::SetStr)
.Prop(_SC("Num"), &ULongInt::GetSNum, &ULongInt::SetNum)
/* Metamethods */
.Func(_SC("_tostring"), &ULongInt::ToString)
.Func(_SC("_cmp"), &ULongInt::Cmp)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_add"), &ULongInt::operator +)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_sub"), &ULongInt::operator -)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_mul"), &ULongInt::operator *)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_div"), &ULongInt::operator /)
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_modulo"), &ULongInt::operator %)
.Func< ULongInt (ULongInt::*)(void) const >(_SC("_unm"), &ULongInt::operator -)
/* Overloads */
.Overload< void (ULongInt::*)(void) >(_SC("Random"), &ULongInt::Random)
.Overload< void (ULongInt::*)(ULongInt::Type) >(_SC("Random"), &ULongInt::Random)
.Overload< void (ULongInt::*)(ULongInt::Type, ULongInt::Type) >(_SC("Random"), &ULongInt::Random)
);
}
} // Namespace:: SqMod

View File

@@ -2,15 +2,440 @@
#define _LIBRARY_NUMERIC_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
// ------------------------------------------------------------------------------------------------
template < typename T > class LongInt;
// ------------------------------------------------------------------------------------------------
template <> class LongInt< Int64 >
{
public:
// --------------------------------------------------------------------------------------------
typedef Int64 Type;
/* --------------------------------------------------------------------------------------------
*
*/
LongInt()
: m_Data(0), m_Text()
{
/* ... */
}
LongInt(Type n)
: m_Data(n), m_Text()
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt(CSStr text);
LongInt(CSStr text, Object & /* null */);
/* --------------------------------------------------------------------------------------------
*
*/
LongInt(const LongInt< Type > & o)
: m_Data(o.m_Data), m_Text()
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
*
*/
~LongInt()
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt & operator = (const LongInt< Type > & o)
{
m_Data = o.m_Data;
return *this;
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt< Type > & operator = (Type data)
{
m_Data = data;
return *this;
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt< Type > & operator = (CSStr text);
/* --------------------------------------------------------------------------------------------
*
*/
bool operator == (const LongInt< Type > & o) const
{
return (m_Data == o.m_Data);
}
bool operator != (const LongInt< Type > & o) const
{
return (m_Data != o.m_Data);
}
bool operator < (const LongInt< Type > & o) const
{
return (m_Data < o.m_Data);
}
bool operator > (const LongInt< Type > & o) const
{
return (m_Data > o.m_Data);
}
bool operator <= (const LongInt< Type > & o) const
{
return (m_Data <= o.m_Data);
}
bool operator >= (const LongInt< Type > & o) const
{
return (m_Data >= o.m_Data);
}
/* --------------------------------------------------------------------------------------------
*
*/
operator Type () const { return m_Data; }
/* --------------------------------------------------------------------------------------------
*
*/
LongInt< Type > operator + (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data + o.m_Data);
}
LongInt< Type > operator - (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data - o.m_Data);
}
LongInt< Type > operator * (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data * o.m_Data);
}
LongInt< Type > operator / (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data / o.m_Data);
}
LongInt< Type > operator % (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data % o.m_Data);
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt< Type > operator - () const
{
return LongInt< Type >(-m_Data);
}
/* --------------------------------------------------------------------------------------------
*
*/
Int32 Cmp(const LongInt< Type > & o) const
{
if (m_Data == o.m_Data)
return 0;
else if (m_Data > o.m_Data)
return 1;
else
return -1;
}
/* --------------------------------------------------------------------------------------------
*
*/
CSStr ToString();
/* --------------------------------------------------------------------------------------------
*
*/
void SetNum(Type data)
{
m_Data = data;
}
Type GetNum() const
{
return m_Data;
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetSNum() const
{
return (SQInteger)(m_Data);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetStr(CSStr text)
{
*this = text;
}
CSStr GetCStr()
{
return ToString();
}
/* --------------------------------------------------------------------------------------------
*
*/
void Random();
void Random(Type n);
void Random(Type m, Type n);
private:
// --------------------------------------------------------------------------------------------
Type m_Data;
SQChar m_Text[32];
};
// ------------------------------------------------------------------------------------------------
template <> class LongInt< Uint64 >
{
public:
// --------------------------------------------------------------------------------------------
typedef Uint64 Type;
/* --------------------------------------------------------------------------------------------
*
*/
LongInt()
: m_Data(0), m_Text()
{
/* ... */
}
LongInt(Type n)
: m_Data(n), m_Text()
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt(CSStr text);
LongInt(CSStr text, Object & /* null */);
/* --------------------------------------------------------------------------------------------
*
*/
LongInt(const LongInt< Type > & o)
: m_Data(o.m_Data), m_Text()
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
*
*/
~LongInt()
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt & operator = (const LongInt< Type > & o)
{
m_Data = o.m_Data;
return *this;
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt< Type > & operator = (Type data)
{
m_Data = data;
return *this;
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt< Type > & operator = (CSStr text);
/* --------------------------------------------------------------------------------------------
*
*/
bool operator == (const LongInt< Type > & o) const
{
return (m_Data == o.m_Data);
}
bool operator != (const LongInt< Type > & o) const
{
return (m_Data != o.m_Data);
}
bool operator < (const LongInt< Type > & o) const
{
return (m_Data < o.m_Data);
}
bool operator > (const LongInt< Type > & o) const
{
return (m_Data > o.m_Data);
}
bool operator <= (const LongInt< Type > & o) const
{
return (m_Data <= o.m_Data);
}
bool operator >= (const LongInt< Type > & o) const
{
return (m_Data >= o.m_Data);
}
/* --------------------------------------------------------------------------------------------
*
*/
operator Type () const { return m_Data; }
/* --------------------------------------------------------------------------------------------
*
*/
LongInt< Type > operator + (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data + o.m_Data);
}
LongInt< Type > operator - (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data - o.m_Data);
}
LongInt< Type > operator * (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data * o.m_Data);
}
LongInt< Type > operator / (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data / o.m_Data);
}
LongInt< Type > operator % (const LongInt< Type > & o) const
{
return LongInt< Type >(m_Data % o.m_Data);
}
/* --------------------------------------------------------------------------------------------
*
*/
LongInt< Type > operator - () const
{
return LongInt< Type >(-m_Data);
}
/* --------------------------------------------------------------------------------------------
*
*/
Int32 Cmp(const LongInt< Type > & o) const
{
if (m_Data == o.m_Data)
return 0;
else if (m_Data > o.m_Data)
return 1;
else
return -1;
}
/* --------------------------------------------------------------------------------------------
*
*/
CSStr ToString();
/* --------------------------------------------------------------------------------------------
*
*/
void SetNum(Type data)
{
m_Data = data;
}
Type GetNum() const
{
return m_Data;
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetSNum() const
{
return (SQInteger)(m_Data);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetStr(CSStr text)
{
*this = text;
}
CSStr GetCStr()
{
return ToString();
}
/* --------------------------------------------------------------------------------------------
*
*/
void Random();
void Random(Type n);
void Random(Type m, Type n);
private:
// --------------------------------------------------------------------------------------------
Type m_Data;
SQChar m_Text[32];
};
// ------------------------------------------------------------------------------------------------
typedef LongInt< Int64 > SLongInt;
typedef LongInt< Uint64 > ULongInt;
} // Namespace:: SqMod
#endif // _LIBRARY_NUMERIC_HPP_
#endif // _LIBRARY_NUMERIC_HPP_

381
source/Library/Random.cpp Normal file
View File

@@ -0,0 +1,381 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Random.hpp"
#include "Base/Shared.hpp"
#include "Base/Buffer.hpp"
// ------------------------------------------------------------------------------------------------
#include <RandomLib/Random.hpp>
// ------------------------------------------------------------------------------------------------
#include <time.h>
#include <stdlib.h>
#ifdef SQMOD_OS_WINDOWS
#include <process.h>
#else
#include <sys/types.h>
#include <unistd.h>
#endif
// ------------------------------------------------------------------------------------------------
RandomLib::Random g_RGen;
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SizeT GenerateSeed()
{
Ulong a = clock();
Ulong b = time(NULL);
#ifdef SQMOD_OS_WINDOWS
Ulong c = _getpid();
#else
Ulong c = getpid();
#endif
// Mangle
a=a-b; a=a-c; a=a^(c >> 13);
b=b-c; b=b-a; b=b^(a << 8);
c=c-a; c=c-b; c=c^(b >> 13);
a=a-b; a=a-c; a=a^(c >> 12);
b=b-c; b=b-a; b=b^(a << 16);
c=c-a; c=c-b; c=c^(b >> 5);
a=a-b; a=a-c; a=a^(c >> 3);
b=b-c; b=b-a; b=b^(a << 10);
c=c-a; c=c-b; c=c^(b >> 15);
// Return result
return c;
}
// ------------------------------------------------------------------------------------------------
void ReseedRandom()
{
g_RGen.Reseed();
}
void ReseedRandom(Uint32 n)
{
g_RGen.Reseed(n);
}
// ------------------------------------------------------------------------------------------------
Int8 GetRandomInt8()
{
return g_RGen.Integer< Int8 >();
}
Int8 GetRandomInt8(Int8 n)
{
return g_RGen.Integer< Int8 >(n);
}
Int8 GetRandomInt8(Int8 m, Int8 n)
{
return g_RGen.IntegerC< Int8 >(m, n);
}
// ------------------------------------------------------------------------------------------------
Uint8 GetRandomUint8()
{
return g_RGen.Integer< Uint8 >();
}
Uint8 GetRandomUint8(Uint8 n)
{
return g_RGen.Integer< Uint8 >(n);
}
Uint8 GetRandomUint8(Uint8 m, Uint8 n)
{
return g_RGen.IntegerC< Uint8 >(m, n);
}
// ------------------------------------------------------------------------------------------------
Int16 GetRandomInt16()
{
return g_RGen.Integer< Int16 >();
}
Int16 GetRandomInt16(Int16 n)
{
return g_RGen.Integer< Int16 >(n);
}
Int16 GetRandomInt16(Int16 m, Int16 n)
{
return g_RGen.IntegerC< Int16 >(m, n);
}
// ------------------------------------------------------------------------------------------------
Uint16 GetRandomUint16()
{
return g_RGen.Integer< Uint16 >();
}
Uint16 GetRandomUint16(Uint16 n)
{
return g_RGen.Integer< Uint16 >(n);
}
Uint16 GetRandomUint16(Uint16 m, Uint16 n)
{
return g_RGen.IntegerC< Uint16 >(m, n);
}
// ------------------------------------------------------------------------------------------------
Int32 GetRandomInt32()
{
return g_RGen.Integer< Int32 >();
}
Int32 GetRandomInt32(Int32 n)
{
return g_RGen.Integer< Int32 >(n);
}
Int32 GetRandomInt32(Int32 m, Int32 n)
{
return g_RGen.IntegerC< Int32 >(m, n);
}
// ------------------------------------------------------------------------------------------------
Uint32 GetRandomUint32()
{
return g_RGen.Integer< Uint32 >();
}
Uint32 GetRandomUint32(Uint32 n)
{
return g_RGen.Integer< Uint32 >(n);
}
Uint32 GetRandomUint32(Uint32 m, Uint32 n)
{
return g_RGen.IntegerC< Uint32 >(m, n);
}
// ------------------------------------------------------------------------------------------------
Int64 GetRandomInt64()
{
return g_RGen.Integer< Int64 >();
}
Int64 GetRandomInt64(Int64 n)
{
return g_RGen.Integer< Int64 >(n);
}
Int64 GetRandomInt64(Int64 m, Int64 n)
{
return g_RGen.IntegerC< Int64 >(m, n);
}
// ------------------------------------------------------------------------------------------------
Uint64 GetRandomUint64()
{
return g_RGen.Integer< Uint64 >();
}
Uint64 GetRandomUint64(Uint64 n)
{
return g_RGen.Integer< Uint64 >(n);
}
Uint64 GetRandomUint64(Uint64 m, Uint64 n)
{
return g_RGen.IntegerC< Uint64 >(m, n);
}
// ------------------------------------------------------------------------------------------------
Float32 GetRandomFloat32()
{
static const Float32 m = NumLimit<Int32>::Min, n = NumLimit<Int32>::Max;
return (n - m) * (Float32(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float32(RAND_MAX)) + m;
}
Float32 GetRandomFloat32(Float32 n)
{
return Float32(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float32(RAND_MAX/n);
}
Float32 GetRandomFloat32(Float32 m, Float32 n)
{
return (n - m) * (Float32(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float32(RAND_MAX)) + m;
}
// ------------------------------------------------------------------------------------------------
Float64 GetRandomFloat64()
{
static const Float64 m = NumLimit<Int32>::Min, n = NumLimit<Int32>::Max;
return (n - m) * (Float64(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float64(RAND_MAX)) + m;
}
Float64 GetRandomFloat64(Float64 n)
{
return Float64(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float64(RAND_MAX/n);
}
Float64 GetRandomFloat64(Float64 m, Float64 n)
{
return (n - m) * (Float64(g_RGen.IntegerC< Int16 >(0, NumLimit< Int16 >::Max)) / Float64(RAND_MAX)) + m;
}
// ------------------------------------------------------------------------------------------------
void GetRandomString(String & str, String::size_type len)
{
str.reserve(len+1);
str.resize(len);
for (String::iterator itr = str.begin(); itr != str.end(); ++itr)
{
*itr = g_RGen.Integer< String::value_type >();
}
str.push_back(0);
}
void GetRandomString(String & str, String::size_type len, String::value_type n)
{
str.reserve(len+1);
str.resize(len);
for (String::iterator itr = str.begin(); itr != str.end(); ++itr)
{
*itr = g_RGen.Integer< String::value_type >(n);
}
str.push_back(0);
}
void GetRandomString(String & str, String::size_type len, String::value_type m, String::value_type n)
{
str.reserve(len+1);
str.resize(len);
for (String::iterator itr = str.begin(); itr != str.end(); ++itr)
{
*itr = g_RGen.IntegerC< String::value_type >(m, n);
}
str.push_back(0);
}
// ------------------------------------------------------------------------------------------------
bool GetRandomBool()
{
return g_RGen.Boolean();
}
// ------------------------------------------------------------------------------------------------
template < typename T > static T RandomValue()
{
return RandomVal< T >::Get();
}
template < typename T > static T RandomValue(T n)
{
return RandomVal< T >::Get(n);
}
template < typename T > static T RandomValue(T m, T n)
{
return RandomVal< T >::Get(m, n);
}
// ------------------------------------------------------------------------------------------------
static CSStr RandomString(Int32 len)
{
if (len <= 0)
{
return _SC("");
}
Buffer b(len+1);
SStr s = b.Get< SQChar >();
for (Int32 n = 0; n <= len; ++n, ++s)
{
*s = g_RGen.Integer< SQChar >();
}
b.At< SQChar >(len) = 0;
return b.Get< SQChar >();
}
// ------------------------------------------------------------------------------------------------
static CSStr RandomString(Int32 len, SQChar n)
{
if (len <= 0)
{
return _SC("");
}
Buffer b(len+1);
SStr s = b.Get< SQChar >();
for (Int32 n = 0; n <= len; ++n, ++s)
{
*s = g_RGen.Integer< SQChar >(n);
}
b.At< SQChar >(len) = 0;
return b.Get< SQChar >();
}
// ------------------------------------------------------------------------------------------------
static CSStr RandomString(Int32 len, SQChar m, SQChar n)
{
if (len <= 0)
{
return _SC("");
}
Buffer b(len+1);
SStr s = b.Get< SQChar >();
for (Int32 n = 0; n <= len; ++n, ++s)
{
*s = g_RGen.IntegerC< SQChar >(m, n);
}
b.At< SQChar >(len) = 0;
return b.Get< SQChar >();
}
// ------------------------------------------------------------------------------------------------
static bool RandomProbI(SQInteger p)
{
return g_RGen.Prob(p);
}
static bool RandomProbI(SQInteger m, SQInteger n)
{
return g_RGen.Prob(m, n);
}
// ------------------------------------------------------------------------------------------------
static bool RandomProbF(SQFloat p)
{
return g_RGen.Prob(p);
}
static bool RandomProbF(SQFloat m, SQFloat n)
{
return g_RGen.Prob(m, n);
}
// ------------------------------------------------------------------------------------------------
void Register_Random(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("Random"), Table(vm)
.Func(_SC("GenSeed"), &GenerateSeed)
.Overload< void (*)(void) >(_SC("Reseed"), &ReseedRandom)
.Overload< void (*)(Uint32) >(_SC("Reseed"), &ReseedRandom)
.Overload< SQInteger (*)(void) >(_SC("Integer"), &RandomValue< SQInteger >)
.Overload< SQInteger (*)(SQInteger) >(_SC("Integer"), &RandomValue< SQInteger >)
.Overload< SQInteger (*)(SQInteger, SQInteger) >(_SC("Integer"), &RandomValue< SQInteger >)
.Overload< SQFloat (*)(void) >(_SC("Float"), &RandomValue< SQFloat >)
.Overload< SQFloat (*)(SQFloat) >(_SC("Float"), &RandomValue< SQFloat >)
.Overload< SQFloat (*)(SQFloat, SQFloat) >(_SC("Float"), &RandomValue< SQFloat >)
.Overload< CSStr (*)(Int32) >(_SC("String"), &RandomString)
.Overload< CSStr (*)(Int32, SQChar) >(_SC("String"), &RandomString)
.Overload< CSStr (*)(Int32, SQChar, SQChar) >(_SC("String"), &RandomString)
.Func(_SC("Bool"), &GetRandomBool)
.Overload< bool (*)(SQInteger) >(_SC("ProbI"), &RandomProbI)
.Overload< bool (*)(SQInteger, SQInteger) >(_SC("ProbI"), &RandomProbI)
.Overload< bool (*)(SQFloat) >(_SC("ProbF"), &RandomProbF)
.Overload< bool (*)(SQFloat, SQFloat) >(_SC("ProbF"), &RandomProbF)
);
}
} // Namespace:: SqMod

164
source/Library/Random.hpp Normal file
View File

@@ -0,0 +1,164 @@
#ifndef _LIBRARY_RANDOM_HPP_
#define _LIBRARY_RANDOM_HPP_
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Attempt to generate a moderately unique number to be used as a seed for random numbers.
*/
Uint32 GenerateSeed();
// ------------------------------------------------------------------------------------------------
void ReseedRandom();
void ReseedRandom(Uint32 n);
// ------------------------------------------------------------------------------------------------
Int8 GetRandomInt8();
Int8 GetRandomInt8(Int8 n);
Int8 GetRandomInt8(Int8 m, Int8 n);
// ------------------------------------------------------------------------------------------------
Uint8 GetRandomUint8();
Uint8 GetRandomUint8(Uint8 n);
Uint8 GetRandomUint8(Uint8 m, Uint8 n);
// ------------------------------------------------------------------------------------------------
Int16 GetRandomInt16();
Int16 GetRandomInt16(Int16 n);
Int16 GetRandomInt16(Int16 m, Int16 n);
// ------------------------------------------------------------------------------------------------
Uint16 GetRandomUint16();
Uint16 GetRandomUint16(Uint16 n);
Uint16 GetRandomUint16(Uint16 m, Uint16 n);
// ------------------------------------------------------------------------------------------------
Int32 GetRandomInt32();
Int32 GetRandomInt32(Int32 n);
Int32 GetRandomInt32(Int32 m, Int32 n);
// ------------------------------------------------------------------------------------------------
Uint32 GetRandomUint32();
Uint32 GetRandomUint32(Uint32 n);
Uint32 GetRandomUint32(Uint32 m, Uint32 n);
// ------------------------------------------------------------------------------------------------
Int64 GetRandomInt64();
Int64 GetRandomInt64(Int64 n);
Int64 GetRandomInt64(Int64 m, Int64 n);
// ------------------------------------------------------------------------------------------------
Uint64 GetRandomUint64();
Uint64 GetRandomUint64(Uint64 n);
Uint64 GetRandomUint64(Uint64 m, Uint64 n);
// ------------------------------------------------------------------------------------------------
Float32 GetRandomFloat32();
Float32 GetRandomFloat32(Float32 n);
Float32 GetRandomFloat32(Float32 m, Float32 n);
// ------------------------------------------------------------------------------------------------
Float64 GetRandomFloat64();
Float64 GetRandomFloat64(Float64 n);
Float64 GetRandomFloat64(Float64 m, Float64 n);
// ------------------------------------------------------------------------------------------------
void GetRandomString(String & str, String::size_type len);
void GetRandomString(String & str, String::size_type len, String::value_type n);
void GetRandomString(String & str, String::size_type len, String::value_type m, String::value_type n);
// ------------------------------------------------------------------------------------------------
bool GetRandomBool();
// ------------------------------------------------------------------------------------------------
template <typename T> struct RandomVal
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template <> struct RandomVal< Int8 >
{
static inline Int8 Get() { return GetRandomInt8(); }
static inline Int8 Get(Int8 n) { return GetRandomInt8(n); }
static inline Int8 Get(Int8 m, Int8 n) { return GetRandomInt8(m, n); }
};
template <> struct RandomVal< Uint8 >
{
static inline Uint8 Get() { return GetRandomUint8(); }
static inline Uint8 Get(Uint8 n) { return GetRandomUint8(n); }
static inline Uint8 Get(Uint8 m, Uint8 n) { return GetRandomUint8(m, n); }
};
// ------------------------------------------------------------------------------------------------
template <> struct RandomVal< Int16 >
{
static inline Int16 Get() { return GetRandomInt16(); }
static inline Int16 Get(Int16 n) { return GetRandomInt16(n); }
static inline Int16 Get(Int16 m, Int16 n) { return GetRandomInt16(m, n); }
};
template <> struct RandomVal< Uint16 >
{
static inline Uint16 Get() { return GetRandomUint16(); }
static inline Uint16 Get(Uint16 n) { return GetRandomUint16(n); }
static inline Uint16 Get(Uint16 m, Uint16 n) { return GetRandomUint16(m, n); }
};
// ------------------------------------------------------------------------------------------------
template <> struct RandomVal< Int32 >
{
static inline Int32 Get() { return GetRandomInt32(); }
static inline Int32 Get(Int32 n) { return GetRandomInt32(n); }
static inline Int32 Get(Int32 m, Int32 n) { return GetRandomInt32(m, n); }
};
template <> struct RandomVal< Uint32 >
{
static inline Uint32 Get() { return GetRandomUint32(); }
static inline Uint32 Get(Uint32 n) { return GetRandomUint32(n); }
static inline Uint32 Get(Uint32 m, Uint32 n) { return GetRandomUint32(m, n); }
};
// ------------------------------------------------------------------------------------------------
template <> struct RandomVal< Int64 >
{
static inline Int64 Get() { return GetRandomInt64(); }
static inline Int64 Get(Int64 n) { return GetRandomInt64(n); }
static inline Int64 Get(Int64 m, Int64 n) { return GetRandomInt64(m, n); }
};
template <> struct RandomVal< Uint64 >
{
static inline Uint64 Get() { return GetRandomUint64(); }
static inline Uint64 Get(Uint64 n) { return GetRandomUint64(n); }
static inline Uint64 Get(Uint64 m, Uint64 n) { return GetRandomUint64(m, n); }
};
// ------------------------------------------------------------------------------------------------
template <> struct RandomVal< Float32 >
{
static inline Float32 Get() { return GetRandomFloat32(); }
static inline Float32 Get(Float32 n) { return GetRandomFloat32(n); }
static inline Float32 Get(Float32 m, Float32 n) { return GetRandomFloat32(m, n); }
};
template <> struct RandomVal< Float64 >
{
static inline Float64 Get() { return GetRandomFloat64(); }
static inline Float64 Get(Float64 n) { return GetRandomFloat64(n); }
static inline Float64 Get(Float64 m, Float64 n) { return GetRandomFloat64(m, n); }
};
// ------------------------------------------------------------------------------------------------
template <> struct RandomVal< bool >
{
static inline bool Get() { return GetRandomBool(); }
};
} // Namespace:: SqMod
#endif // _LIBRARY_RANDOM_HPP_

View File

@@ -1,961 +0,0 @@
#include "Library/SQLite/Connection.hpp"
#include "Library/SQLite/Statement.hpp"
// ------------------------------------------------------------------------------------------------
#include <sqstdstring.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace SQLite {
// ------------------------------------------------------------------------------------------------
Connection::Connection()
: m_Handle()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Connection::Connection(const SQChar * path)
: Connection(path, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Connection::Connection(const SQChar * path, SQInt32 flags)
: Connection(path, flags, NULL)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Connection::Connection(const SQChar * path, SQInt32 flags, const SQChar * vfs)
: m_Handle(path, flags, vfs)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Connection::Connection(const Handle & hnd)
: m_Handle(hnd)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
SQInteger Connection::Cmp(const Connection & o) const
{
if (m_Handle == o.m_Handle)
{
return 0;
}
else if (m_Handle && (m_Handle->Ptr > o.m_Handle->Ptr))
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
const SQChar * Connection::ToString() const
{
if (m_Handle)
{
return m_Handle->Path.c_str();
}
return _SC("");
}
// ------------------------------------------------------------------------------------------------
const SQChar * Connection::GetGlobalTag() const
{
if (m_Handle)
{
return m_Handle->Tag.c_str();
}
else
{
LogWrn("Attempting to <get connection tag> using an invalid reference");
}
return _SC("");
}
void Connection::SetGlobalTag(const SQChar * tag) const
{
if (m_Handle)
{
m_Handle->Tag.assign(tag);
}
else
{
LogWrn("Attempting to <set connection tag> using an invalid reference");
}
}
// ------------------------------------------------------------------------------------------------
SqObj & Connection::GetGlobalData() const
{
if (m_Handle)
{
return m_Handle->Data;
}
else
{
LogWrn("Attempting to <get connection data> using an invalid reference");
}
return NullData();
}
void Connection::SetGlobalData(SqObj & data) const
{
if (m_Handle)
{
m_Handle->Data = data;
}
else
{
LogWrn("Attempting to <set connection data> using an invalid reference");
}
}
// ------------------------------------------------------------------------------------------------
const SQChar * Connection::GetLocalTag() const
{
return m_Tag.c_str();
}
void Connection::SetLocalTag(const SQChar * tag)
{
m_Tag = tag;
}
// ------------------------------------------------------------------------------------------------
SqObj & Connection::GetLocalData()
{
return m_Data;
}
void Connection::SetLocalData(SqObj & data)
{
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetStatus() const
{
if (m_Handle)
{
return m_Handle->Status;
}
else
{
LogWrn("Attempting to <get connection status> using an invalid connection: null");
}
return 0;
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetFlags() const
{
if (m_Handle)
{
return m_Handle->Flags;
}
else
{
LogWrn("Attempting to <get connection flags> using an invalid connection: null");
}
return 0;
}
// ------------------------------------------------------------------------------------------------
const SQChar * Connection::GetPath() const
{
if (m_Handle)
{
return m_Handle->Path.c_str();
}
else
{
LogWrn("Attempting to <get connection file path> using an invalid connection: null");
}
return _SC("");
}
// ------------------------------------------------------------------------------------------------
const SQChar * Connection::GetVFS() const
{
if (m_Handle)
{
return m_Handle->VFS.c_str();
}
else
{
LogWrn("Attempting to <get connection vfs string> using an invalid connection: null");
}
return _SC("");
}
// ------------------------------------------------------------------------------------------------
const SQChar * Connection::GetErrStr() const
{
if (m_Handle)
{
return m_Handle.ErrStr();
}
else
{
LogWrn("Attempting to <get connection error string> using an invalid connection: null");
}
return _SC("");
}
// ------------------------------------------------------------------------------------------------
const SQChar * Connection::GetErrMsg() const
{
if (m_Handle)
{
return m_Handle.ErrMsg();
}
else
{
LogWrn("Attempting to <get connection error message> using an invalid connection: null");
}
return _SC("");
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::Exec(const SQChar * str)
{
if (m_Handle)
{
if ((m_Handle->Status = sqlite3_exec(m_Handle, static_cast< const char * >(str), NULL, NULL, NULL)) != SQLITE_OK)
{
LogErr("Unable to <execute database query> because: %s", m_Handle.ErrMsg());
}
else
{
return sqlite3_changes(m_Handle);
}
}
else
{
LogWrn("Attempting to <execute database query> using an invalid connection: null");
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
void Connection::Queue(const SQChar * str)
{
if (m_Handle)
{
m_Handle->Queue.emplace(str);
}
else
{
LogWrn("Attempting to <queue database query> using an invalid connection: null");
}
}
// ------------------------------------------------------------------------------------------------
bool Connection::TableExists(const SQChar * name) const
{
if (m_Handle)
{
// Create the statement which counts the tables with the specified name
Statement stmt(*this, "SELECT count(*) FROM [sqlite_master] WHERE [type]='table' AND [name]=?");
// See if the statement could be created
if (stmt.IsValid())
{
// Bind the table name
stmt.IndexBindS(1, name);
// Attempt to step the statement
if (stmt.Step())
{
LogErr("Unable to <see if table exists> because : the statement could not be stepped");
// Return the requested information
return (sqlite3_column_int(stmt, 0) == 1);
}
}
else
{
LogErr("Unable to <see if table exists> because : the statement could not be created");
}
}
else
{
LogWrn("Attempting to <see if table exists> using an invalid connection: null");
}
return false;
}
// ------------------------------------------------------------------------------------------------
bool Connection::IsReadOnly() const
{
if (m_Handle)
{
const int result = sqlite3_db_readonly(m_Handle, "main");
// Verify the result
if(result == -1)
{
LogErr("Unable to <see if database is read only> because : 'main' is not the name of a database on connection");
}
// Return the result
else
{
return (result != 1);
}
}
else
{
LogWrn("Attempting to <see if database is read only> using an invalid connection: null");
}
// It's invalid so at least fall-back to read-only
return true;
}
// ------------------------------------------------------------------------------------------------
bool Connection::GetAutoCommit() const
{
if (m_Handle)
{
return sqlite3_get_autocommit(m_Handle);
}
else if (!m_Handle)
{
LogWrn("Attempting to <see if database has autocommit activated> using an invalid connection: null");
}
return false;
}
// ------------------------------------------------------------------------------------------------
SLongInt Connection::GetLastInsertRowID() const
{
if (m_Handle)
{
return SLongInt(static_cast< SLongInt::Type >(sqlite3_last_insert_rowid(m_Handle)));
}
else if (!m_Handle)
{
LogWrn("Attempting to <get database changes> using an invalid connection: null");
}
return SLongInt(static_cast< SLongInt::Type >(SQMOD_UNKNOWN));
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetChanges() const
{
if (m_Handle)
{
return sqlite3_changes(m_Handle);
}
else if (!m_Handle)
{
LogWrn("Attempting to <get database changes> using an invalid connection: null");
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetTotalChanges() const
{
if (m_Handle)
{
return sqlite3_total_changes(m_Handle);
}
else if (!m_Handle)
{
LogWrn("Attempting to <get database total changes> using an invalid connection: null");
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetErrorCode() const
{
if (m_Handle)
{
return sqlite3_errcode(m_Handle);
}
else
{
LogWrn("Attempting to <get database error code> using an invalid connection: null");
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetExtendedErrorCode() const
{
if (m_Handle)
{
return sqlite3_extended_errcode(m_Handle);
}
else
{
LogWrn("Attempting to <get database extended error code> using an invalid connection: null");
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
bool Connection::GetTracing() const
{
if (m_Handle)
{
return m_Handle->Trace;
}
else
{
LogWrn("Attempting to <see if database has tracing activated> using an invalid connection: null");
}
return false;
}
// ------------------------------------------------------------------------------------------------
void Connection::SetTracing(bool toggle) const
{
if (m_Handle && m_Handle->Trace != toggle)
{
if (m_Handle->Trace)
{
sqlite3_trace(m_Handle, NULL, NULL);
}
else
{
sqlite3_trace(m_Handle, &Connection::TraceOutput, NULL);
}
}
else if (!m_Handle)
{
LogWrn("Attempting to <activate database tracing> using an invalid connection: null");
}
}
// ------------------------------------------------------------------------------------------------
bool Connection::GetProfiling() const
{
if (m_Handle)
{
return m_Handle->Profile;
}
else
{
LogWrn("Attempting to <see if database has profiling activated> using an invalid connection: null");
}
return false;
}
// ------------------------------------------------------------------------------------------------
void Connection::SetProfiling(bool toggle) const
{
if (m_Handle && m_Handle->Profile != toggle)
{
if (m_Handle->Profile)
{
sqlite3_profile(m_Handle, NULL, NULL);
}
else
{
sqlite3_profile(m_Handle, &Connection::ProfileOutput, NULL);
}
}
else if (!m_Handle)
{
LogWrn("Attempting to <activate database profiling> using an invalid connection: null");
}
}
// ------------------------------------------------------------------------------------------------
void Connection::SetBusyTimeout(SQInteger millis) const
{
if (m_Handle)
{
if ((m_Handle->Status = sqlite3_busy_timeout(m_Handle, millis)) != SQLITE_OK)
{
LogErr("Unable to <set database busy timeout> because : %s", m_Handle.ErrMsg());
}
}
else
{
LogWrn("Attempting to <set database busy timeout> using an invalid connection: null");
}
}
// ------------------------------------------------------------------------------------------------
void Connection::InterruptOperation() const
{
if (m_Handle)
{
sqlite3_interrupt(m_Handle);
}
else
{
LogWrn("Attempting to <interrupt database operation> using an invalid connection: null");
}
}
// ------------------------------------------------------------------------------------------------
void Connection::ReleaseMemory() const
{
if (m_Handle)
{
sqlite3_db_release_memory(m_Handle);
}
else
{
LogWrn("Attempting to <release database memory> using an invalid connection: null");
}
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetNumberOfCheckedOutLookasideMemorySlots() const
{
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_USED);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetHeapMemoryUsedByPagerCaches() const
{
return GetInfo(SQLITE_DBSTATUS_CACHE_USED);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetHeapMemoryUsedToStoreSchemas() const
{
return GetInfo(SQLITE_DBSTATUS_SCHEMA_USED);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetHeapAndLookasideMemoryUsedByPreparedStatements() const
{
return GetInfo(SQLITE_DBSTATUS_STMT_USED);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetPagerCacheHitCount() const
{
return GetInfo(SQLITE_DBSTATUS_CACHE_HIT);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetPagerCacheMissCount() const
{
return GetInfo(SQLITE_DBSTATUS_CACHE_MISS);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetNumberOfDirtyCacheEntries() const
{
return GetInfo(SQLITE_DBSTATUS_CACHE_WRITE);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetNumberOfUnresolvedForeignKeys() const
{
return GetInfo(SQLITE_DBSTATUS_DEFERRED_FKS);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetHighestNumberOfCheckedOutLookasideMemorySlots(bool reset)
{
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_USED, true, reset);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetLookasideMemoryHitCount(bool reset)
{
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_HIT, true, reset);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetLookasideMemoryMissCountDueToSmallSlotSize(bool reset)
{
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, true, reset);
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetLookasideMemoryMissCountDueToFullMemory(bool reset)
{
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, true, reset);
}
// ------------------------------------------------------------------------------------------------
Connection Connection::CopyToMemory()
{
if (m_Handle && !m_Handle->Memory)
{
// Attempt to open an in-memory database
Handle db(":memory:", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
// See if the database could be opened
if (!db)
{
LogErr("Unable to <open in-memory database> because : %s", db.ErrMsg());
}
// Begin a transaction to replicate the schema of origin database
else if ((m_Handle->Status = sqlite3_exec(m_Handle, "BEGIN", NULL, NULL, NULL)) != SQLITE_OK)
{
LogErr("Unable to <begin database schema replication> because : %s", m_Handle.ErrMsg());
}
// Attempt to replicate the schema of origin database to the in-memory one
else if ((m_Handle->Status = sqlite3_exec(m_Handle,
"SELECT [sql] FROM [sqlite_master] WHERE [sql] NOT NULL AND [tbl_name] != 'sqlite_sequence'",
&Connection::ProcessDDLRow, db, NULL)) != SQLITE_OK)
{
LogErr("Unable to <replicate database schema> because : %s", m_Handle.ErrMsg());
}
// Attempt to commit the changes to the database schema replication
else if ((m_Handle->Status = sqlite3_exec(m_Handle, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
{
LogErr("Unable to <commit database schema replication> because : %s", m_Handle.ErrMsg());
}
// Attempt to attach the origin database to the in-memory one
else if ((db->Status = sqlite3_exec(db, ToStringF("ATTACH DATABASE '%s' as origin",
m_Handle->Path.c_str()), NULL, NULL, NULL)) != SQLITE_OK)
{
LogErr("Unable to <attach database origin> because : %s", db.ErrMsg());
}
// Begin a transaction to replicate the data of origin database
else if ((db->Status = sqlite3_exec(db, "BEGIN", NULL, NULL, NULL) != SQLITE_OK))
{
LogErr("Unable to <begin database data replication> because : %s", db.ErrMsg());
}
// Attempt to replicate the data of origin database to the in-memory one
else if ((db->Status = sqlite3_exec(db, "SELECT [name] FROM [origin.sqlite_master] WHERE [type]='table'",
&Connection::ProcessDMLRow, db, NULL)) != SQLITE_OK)
{
LogErr("Unable to <replicate database data> because : %s", m_Handle.ErrMsg());
}
// Attempt to commit the changes to the database data replication
else if ((db->Status = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
{
LogErr("Unable to <commit database data replication> because : %s", db.ErrMsg());
// Attempt to rollback changes from the data copy operation
if ((db->Status = sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL)) != SQLITE_OK)
{
LogErr("Unable to <rollback database data replication> because : %s", db.ErrMsg());
}
// Attempt to detach the disk origin from in-memory database
else if ((db->Status = sqlite3_exec(db, "DETACH DATABASE origin", NULL, NULL, NULL)) != SQLITE_OK)
{
LogErr("Unable to <detach database origin> because : %s", db.ErrMsg());
}
}
else
{
// Return the new in-memory database
return db;
}
}
else if (!m_Handle)
{
LogWrn("Attempting to <copy database to memory> using an invalid connection: null");
}
else
{
LogWrn("Attempting to <copy database to memory> for a database which is already in memory");
}
// Fall-back to an invalid connection
return Connection();
}
// ------------------------------------------------------------------------------------------------
Connection Connection::CopyToDatabase(const SQChar * path)
{
if (m_Handle)
{
// See if the specified name is valid
if (strlen(path) <= 0)
{
LogWrn("Attempting to <replicate database> using an invalid path: null");
}
// Attempt to open the specified database
Handle db(path, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
// See if the database could be opened
if (!db)
{
LogErr("Unable to <open the specified database> because : %s", db.ErrMsg());
}
else
{
// Attempt to take snapshot of the database
TakeSnapshot(db);
// Return the database clone
return db;
}
}
else
{
LogWrn("Attempting to <replicate database> using an invalid connection: null");
}
// Fall-back to an invalid connection
return Connection();
}
// ------------------------------------------------------------------------------------------------
void Connection::TraceOutput(void * ptr, const char * sql)
{
SQMOD_UNUSED_VAR(ptr);
LogInf("SQLite Trace: %s", sql);
}
// ------------------------------------------------------------------------------------------------
void Connection::ProfileOutput(void * ptr, const char * sql, sqlite3_uint64 time)
{
SQMOD_UNUSED_VAR(ptr);
LogInf("SQLite profile (time: %llu): %s", time, sql);
}
// ------------------------------------------------------------------------------------------------
int Connection::ProcessDDLRow(void * db, int columns_count, char ** values, char ** columns)
{
SQMOD_UNUSED_VAR(columns);
if(columns_count != 1)
{
LogErr("Error occurred during DDL: columns != 1");
// Operation failed
return -1;
}
// Execute the sql statement in values[0] in the received database connection
if(sqlite3_exec(static_cast< sqlite3 * >(db), values[0], NULL, NULL, NULL) != SQLITE_OK)
{
LogErr("Error occurred during DDL execution: %s", sqlite3_errmsg(static_cast< sqlite3 * >(db)));
}
// Operation succeeded
return 0;
}
// ------------------------------------------------------------------------------------------------
int Connection::ProcessDMLRow(void * db, int columns_count, char ** values, char ** columns)
{
SQMOD_UNUSED_VAR(columns);
if(columns_count != 1)
{
LogErr("Error occurred during DML: columns != 1");
// Operation failed
return -1;
}
// Generate the query string with the received values
char * sql = sqlite3_mprintf("INSERT INTO main.%q SELECT * FROM origin.%q", values[0], values[0]);
// Attempt to execute the generated query string to the received database connection
if(sqlite3_exec(static_cast< sqlite3 * >(db), sql, NULL, NULL, NULL) != SQLITE_OK)
{
LogErr("Error occurred during DML execution: %s", sqlite3_errmsg(static_cast< sqlite3 * >(db)));
}
// Free the generated query string
sqlite3_free(sql);
// Operation succeeded
return 0;
}
// ------------------------------------------------------------------------------------------------
void Connection::TakeSnapshot(Handle & destination)
{
// Don't even bother to continue if there's no valid connection handle
if (m_Handle && destination)
{
// Attempt to initialize a backup structure
sqlite3_backup * backup = sqlite3_backup_init(destination, "main", m_Handle, "main");
// See if the backup structure could be created
if(backup)
{
// -1 to copy the entire source database to the destination
if((m_Handle->Status = sqlite3_backup_step(backup, -1)) != SQLITE_DONE)
{
LogErr("Unable to <copy database source> because: %s", sqlite3_errmsg(destination));
}
// clean up resources allocated by sqlite3_backup_init()
if((m_Handle->Status = sqlite3_backup_finish(backup)) != SQLITE_OK)
{
LogErr("Unable to <finalize database backup> because: %s", sqlite3_errmsg(destination));
}
}
}
else if (!destination)
{
LogWrn("Attempting to <take database snapshot> using an invalid destination: null");
}
else
{
LogWrn("Attempting to <take database snapshot> using an invalid connection: null");
}
}
// ------------------------------------------------------------------------------------------------
SQInt32 Connection::GetInfo(int operation, bool highwater, bool reset) const
{
// Don't even bother to continue if there's no valid connection handle
if (m_Handle)
{
int cur_value;
int hiwtr_value;
// Attempt to retrieve the specified information
if((m_Handle->Status = sqlite3_db_status(m_Handle, operation, &cur_value, &hiwtr_value, reset)) != SQLITE_OK)
{
LogErr("Unable to <get database runtime status information> because: %s", sqlite3_errmsg(m_Handle));
}
// Return what was requested
return highwater ? hiwtr_value : cur_value;
}
else
{
LogWrn("Attempting to <get database runtime status information> using an invalid connection: null");
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
SQInteger Connection::ExecF(HSQUIRRELVM vm)
{
const SQInteger top = sq_gettop(vm);
// Are there any arguments on the stack?
if (top <= 1)
{
LogErr("Attempting to <execute database query> without specifying a value");
// Push a null value on the stack
sq_pushnull(vm);
}
// Attempt to retrieve the connection instance
Var< Connection & > inst(vm, 1);
// Validate the connection instance
if (!inst.value)
{
LogErr("Attempting to <execute database query> using an invalid connection: null");
// Push a null value on the stack
sq_pushnull(vm);
}
// Is there a single string or at least something that can convert to a string on the stack?
else if (top == 2 && ((sq_gettype(vm, -1) == OT_STRING) || !SQ_FAILED(sq_tostring(vm, -1))))
{
// Variable where the resulted string will be retrieved
const SQChar * str = 0;
// Attempt to retrieve the specified message from the stack
if (SQ_FAILED(sq_getstring(vm, -1, &str)))
{
LogErr("Unable to <fetch database query> because : the string cannot be retrieved from the stack");
// Push a null value on the stack
sq_pushnull(vm);
}
else
{
// Attempt to execute the specified query string and push the result on the stack
sq_pushinteger(vm, inst.value.Exec(str));
}
// Pop any pushed values pushed to the stack
sq_settop(vm, top);
}
else if (top > 2)
{
// Variables containing the resulted string
SQChar * str = NULL;
SQInteger len = 0;
// Attempt to call the format function with the passed arguments
if (SQ_FAILED(sqstd_format(vm, 2, &len, &str)))
{
LogErr("Unable to <generate database query> because : %s", Error::Message(vm).c_str());
// Push a null value on the stack
sq_pushnull(vm);
}
else
{
// Attempt to execute the resulted query string and push the result on the stack
sq_pushinteger(vm, inst.value.Exec(str));
}
}
else
{
LogErr("Unable to <extract database query> from the specified value");
// Push a null value on the stack
sq_pushnull(vm);
}
// At this point everything went correctly (probably)
return 1;
}
// ------------------------------------------------------------------------------------------------
SQInteger Connection::QueueF(HSQUIRRELVM vm)
{
const SQInteger top = sq_gettop(vm);
// Are there any arguments on the stack?
if (top <= 1)
{
LogErr("Attempting to <queue database query> without specifying a value");
}
// Attempt to retrieve the connection instance
Var< Connection & > inst(vm, 1);
// Validate the connection instance
if (!inst.value)
{
LogErr("Attempting to <queue database query> using an invalid connection: null");
}
// Is there a single string or at least something that can convert to a string on the stack?
else if (top == 2 && ((sq_gettype(vm, -1) == OT_STRING) || !SQ_FAILED(sq_tostring(vm, -1))))
{
// Variable where the resulted string will be retrieved
const SQChar * str = 0;
// Attempt to retrieve the specified message from the stack
if (SQ_FAILED(sq_getstring(vm, -1, &str)))
{
LogErr("Unable to <fetch database query> because : the string cannot be retrieved from the stack");
}
else
{
// Attempt to queue the specified query string
inst.value.Queue(str);
}
// Pop any pushed values pushed to the stack
sq_settop(vm, top);
}
else if (top > 2)
{
// Variables containing the resulted string
SQChar * str = NULL;
SQInteger len = 0;
// Attempt to call the format function with the passed arguments
if (SQ_FAILED(sqstd_format(vm, 2, &len, &str)))
{
LogErr("Unable to <generate database query> because : %s", Error::Message(vm).c_str());
}
else
{
// Attempt to queue the specified query string
inst.value.Queue(str);
}
}
else
{
LogErr("Unable to <extract database query> from the specified value");
}
// At this point everything went correctly (probably)
return 0;
}
} // Namespace:: SQLite
} // Namespace:: SqMod

View File

@@ -1,447 +0,0 @@
#ifndef _LIBRARY_SQLITE_CONNECTION_HPP_
#define _LIBRARY_SQLITE_CONNECTION_HPP_
// ------------------------------------------------------------------------------------------------
#include "Library/SQLite/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace SQLite {
/* ------------------------------------------------------------------------------------------------
* Class used to manage a conenction to an SQLite database.
*/
class Connection
{
public:
/* --------------------------------------------------------------------------------------------
* The type of SQLite resource handle that this class uses.
*/
typedef ConnectionHandle Handle;
/* --------------------------------------------------------------------------------------------
* Default constructor (invalid).
*/
Connection();
/* --------------------------------------------------------------------------------------------
* Open a connection to a database using the specified path.
*/
Connection(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Open a connection to a database using the specified path and flags.
*/
Connection(const SQChar * path, SQInt32 flags);
/* --------------------------------------------------------------------------------------------
* Open a connection to a database using the specified path, flags and vfs.
*/
Connection(const SQChar * path, SQInt32 flags, const SQChar * vfs);
/* --------------------------------------------------------------------------------------------
* Construct and reference an existing connection.
*/
Connection(const Handle & hnd);
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
Connection(const Connection & o) = default;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
Connection(Connection && o) = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Connection() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
Connection & operator = (const Connection & o) = default;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
Connection & operator = (Connection && o) = default;
/* --------------------------------------------------------------------------------------------
* Implicit conversion to a handle reference.
*/
operator const Handle & () const
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to a raw SQLite connection handle.
*/
operator sqlite3 * ()
{
return static_cast< sqlite3 * >(m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to a raw SQLite connection handle.
*/
operator sqlite3 * () const
{
return static_cast< sqlite3 * >(m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Equality operator.
*/
bool operator == (const Connection & o) const
{
return (m_Handle == o.m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Inequality operator.
*/
bool operator != (const Connection & o) const
{
return (m_Handle != o.m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Used by the script to compare two instances of this type.
*/
SQInt32 Cmp(const Connection & o) const;
/* --------------------------------------------------------------------------------------------
* Convert this type to a string.
*/
const SQChar * ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the global tag.
*/
const SQChar * GetGlobalTag() const;
/* --------------------------------------------------------------------------------------------
* Change the global tag.
*/
void SetGlobalTag(const SQChar * tag) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the global data.
*/
SqObj & GetGlobalData() const;
/* --------------------------------------------------------------------------------------------
* Change the global data.
*/
void SetGlobalData(SqObj & data) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the local tag.
*/
const SQChar * GetLocalTag() const;
/* --------------------------------------------------------------------------------------------
* Change the local tag.
*/
void SetLocalTag(const SQChar * tag);
/* --------------------------------------------------------------------------------------------
* Retrieve the local data.
*/
SqObj & GetLocalData();
/* --------------------------------------------------------------------------------------------
* Change the local data.
*/
void SetLocalData(SqObj & data);
/* --------------------------------------------------------------------------------------------
* Retrieve the handle reference.
*/
const Handle & GetHandle() const
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the number of active references to this handle.
*/
SQUint32 GetRefs() const
{
return m_Handle ? m_Handle.Count() : 0;
}
/* --------------------------------------------------------------------------------------------
* Release the handle reference.
*/
void Release()
{
m_Handle.Release();
}
/* --------------------------------------------------------------------------------------------
* Attempt to execute the specified query.
*/
bool IsValid() const
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the last received error code.
*/
SQInt32 GetStatus() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the flags used to create this database connection.
*/
SQInt32 GetFlags() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the path used to create this database connection.
*/
const SQChar * GetPath() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the virtual file system used to create this database connection.
*/
const SQChar * GetVFS() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the message of the last received error code.
*/
const SQChar * GetErrStr() const;
/* --------------------------------------------------------------------------------------------
* Return the last error message associated with this database connection.
*/
const SQChar * GetErrMsg() const;
/* --------------------------------------------------------------------------------------------
* Attempt to execute the specified query.
*/
SQInt32 Exec(const SQChar * str);
/* --------------------------------------------------------------------------------------------
* Attempt to queue the specified query.
*/
void Queue(const SQChar * str);
/* --------------------------------------------------------------------------------------------
* Shortcut to test if a table exists.
*/
bool TableExists(const SQChar * name) const;
/* --------------------------------------------------------------------------------------------
* See if the database connection was opened in read-only mode.
*/
bool IsReadOnly() const;
/* --------------------------------------------------------------------------------------------
* See if the database connection is or is not in autocommit mode.
*/
bool GetAutoCommit() const;
/* --------------------------------------------------------------------------------------------
* Get the rowid of the most recent successful INSERT into the database from the current connection.
*/
SLongInt GetLastInsertRowID() const;
/* --------------------------------------------------------------------------------------------
* Returns the number of database rows that were changed, inserted or deleted
* by the most recently completed SQL statement.
*/
SQInt32 GetChanges() const;
/* --------------------------------------------------------------------------------------------
* Returns the total number of row changes caused by INSERT, UPDATE or DELETE statements
* since the database connection was opened.
*/
SQInt32 GetTotalChanges() const;
/* --------------------------------------------------------------------------------------------
* Return the numeric result code for the most recent failed API call (if any).
*/
SQInt32 GetErrorCode() const;
/* --------------------------------------------------------------------------------------------
* Return the extended numeric result code for the most recent failed API call (if any).
*/
SQInt32 GetExtendedErrorCode() const;
/* --------------------------------------------------------------------------------------------
* See if this database connection has tracing enabled.
*/
bool GetTracing() const;
/* --------------------------------------------------------------------------------------------
* Activate or deactivate tracing on this database connection.
*/
void SetTracing(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See if this database connection has profiling enabled.
*/
bool GetProfiling() const;
/* --------------------------------------------------------------------------------------------
* Activate or deactivate profiling on this database connection.
*/
void SetProfiling(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Set a busy handler that sleeps for a specified amount of time when a table is locked.
*/
void SetBusyTimeout(SQInteger millis) const;
/* --------------------------------------------------------------------------------------------
* Causes any pending database operation to abort and return at its earliest opportunity.
*/
void InterruptOperation() const;
/* --------------------------------------------------------------------------------------------
* Attempts to free as much heap memory as possible from the database connection.
*/
void ReleaseMemory() const;
/* --------------------------------------------------------------------------------------------
* Returns the number of lookaside memory slots currently checked out.
*/
SQInt32 GetNumberOfCheckedOutLookasideMemorySlots() const;
/* --------------------------------------------------------------------------------------------
* Returns the approximate number of bytes of heap memory used by all pager caches.
*/
SQInt32 GetHeapMemoryUsedByPagerCaches() const;
/* --------------------------------------------------------------------------------------------
* Returns the approximate number of bytes of heap memory used to store the schema for
* all databases associated with the connection - main, temp, and any ATTACH-ed databases.
*/
SQInt32 GetHeapMemoryUsedToStoreSchemas() const;
/* --------------------------------------------------------------------------------------------
* Returns the approximate number of bytes of heap and lookaside memory used by all
* prepared statements associated with the database connection.
*/
SQInt32 GetHeapAndLookasideMemoryUsedByPreparedStatements() const;
/* --------------------------------------------------------------------------------------------
* Returns the number of pager cache hits that have occurred.
*/
SQInt32 GetPagerCacheHitCount() const;
/* --------------------------------------------------------------------------------------------
* Returns the number of pager cache misses that have occurred.
*/
SQInt32 GetPagerCacheMissCount() const;
/* --------------------------------------------------------------------------------------------
* Returns the number of dirty cache entries that have been written to disk.
*/
SQInt32 GetNumberOfDirtyCacheEntries() const;
/* --------------------------------------------------------------------------------------------
* Returns zero if all foreign key constraints (deferred or immediate) have been resolved.
*/
SQInt32 GetNumberOfUnresolvedForeignKeys() const;
/* --------------------------------------------------------------------------------------------
* Returns the highest number of lookaside memory slots that has been checked out.
*/
SQInt32 GetHighestNumberOfCheckedOutLookasideMemorySlots(bool reset);
/* --------------------------------------------------------------------------------------------
* Returns the number malloc attempts that were satisfied using lookaside memory.
*/
SQInt32 GetLookasideMemoryHitCount(bool reset);
/* --------------------------------------------------------------------------------------------
* Returns the number malloc attempts that might have been satisfied using lookaside memory.
*/
SQInt32 GetLookasideMemoryMissCountDueToSmallSlotSize(bool reset);
/* --------------------------------------------------------------------------------------------
* Returns the number malloc attempts that might have been satisfied using lookaside memory
*/
SQInt32 GetLookasideMemoryMissCountDueToFullMemory(bool reset);
/* --------------------------------------------------------------------------------------------
* Move the whole database into memory.
*/
Connection CopyToMemory();
/* --------------------------------------------------------------------------------------------
* Takes a snapshot of a database which is located in memory and saves it to a database file.
*/
Connection CopyToDatabase(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Attempt to execute the specified query.
*/
static SQInteger ExecF(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Attempt to queue the specified query.
*/
static SQInteger QueueF(HSQUIRRELVM vm);
protected:
/* --------------------------------------------------------------------------------------------
* Callback function for ActivateTracing()
*/
static void TraceOutput(void * ptr, const char * sql);
/* --------------------------------------------------------------------------------------------
* Callback function for ActivateProfiling()
*/
static void ProfileOutput(void * ptr, const char * sql, sqlite3_uint64 time);
/* --------------------------------------------------------------------------------------------
* Build and modify the structure of tables and other objects in the memory database.
*/
static int ProcessDDLRow(void * db, int columns_count, char ** values, char ** columns);
/* --------------------------------------------------------------------------------------------
* Insert all data from the origin database into the memory database.
*/
static int ProcessDMLRow(void * db, int columns_count, char ** values, char ** columns);
/* --------------------------------------------------------------------------------------------
* Takes and saves a snapshot of the memory database in a file.
*/
void TakeSnapshot(Handle & destination);
/* --------------------------------------------------------------------------------------------
* Returns internal runtime status information associated with the current database connection.
*/
SQInt32 GetInfo(int operation, bool highwater = false, bool reset = false) const;
private:
/* --------------------------------------------------------------------------------------------
* Reference to the managed SQLite connection handle.
*/
Handle m_Handle;
/* --------------------------------------------------------------------------------------------
* The local tag associated with this instance.
*/
SqTag m_Tag;
/* --------------------------------------------------------------------------------------------
* The local data associated with this instance.
*/
SqObj m_Data;
};
} // Namespace:: SQLite
} // Namespace:: SqMod
#endif // _LIBRARY_SQLITE_CONNECTION_HPP_

View File

@@ -1,676 +0,0 @@
#include "Library/SQLite/Shared.hpp"
#include "Library/SQLite/Connection.hpp"
#include "Library/SQLite/Statement.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace SQLite {
// ------------------------------------------------------------------------------------------------
ConnectionHandle::ConnectionHandle()
: Hnd(nullptr)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
ConnectionHandle::ConnectionHandle(const SQChar * path, SQInt32 flags, const SQChar * vfs)
: Hnd(new Handle(path, flags, vfs != NULL ? vfs : _SC("")))
{
// See if a handle could be created
if (!Hnd)
{
LogErr("Attempting to <open database connection> without a valid handle");
Drop();
}
// At least the path must be valid
else if (Hnd->Path.empty())
{
LogErr("Attempting to <open database connection> without a valid path");
Drop();
}
// Attempt to open a connection
else if ((Hnd->Status = sqlite3_open_v2(path, &(*Hnd).Ptr, flags, vfs)) != SQLITE_OK)
{
LogErr("Unable to <open database> because : %d", sqlite3_errmsg(Hnd->Ptr));
Drop();
}
}
// ------------------------------------------------------------------------------------------------
ConnectionHandle::ConnectionHandle(const ConnectionHandle & o)
: Hnd(o.Hnd)
{
// Grab a reference to the new handle
Grab();
}
// ------------------------------------------------------------------------------------------------
ConnectionHandle::ConnectionHandle(ConnectionHandle && o)
: Hnd(o.Hnd)
{
// Prevent the other instance from releasing the stolen reference
o.Hnd = nullptr;
}
// ------------------------------------------------------------------------------------------------
ConnectionHandle::~ConnectionHandle()
{
// Drop the current handle reference if any
Drop();
}
// ------------------------------------------------------------------------------------------------
ConnectionHandle & ConnectionHandle::operator = (const ConnectionHandle & o)
{
// Make sure it's not the same handle instance in both
if (Hnd != o.Hnd)
{
// Drop the current handle reference if any
Drop();
// Assign the specified handle
Hnd = o.Hnd;
// Grab a reference to the new handle
Grab();
}
return *this;
}
// ------------------------------------------------------------------------------------------------
ConnectionHandle & ConnectionHandle::operator = (ConnectionHandle && o)
{
// Make sure it's not the same handle instance in both
if (Hnd != o.Hnd)
{
// Drop the current handle reference if any
Drop();
// Steal the handle reference from the other instance
Hnd = o.Hnd;
// Prevent the other instance from releasing the stolen reference
o.Hnd = nullptr;
}
return *this;
}
// ------------------------------------------------------------------------------------------------
Transaction::Transaction(const Connection & db)
: m_Connection(db), m_Commited(false)
{
}
// ------------------------------------------------------------------------------------------------
Transaction::~Transaction()
{
if (!m_Commited && m_Connection)
{
if ((m_Connection->Status = sqlite3_exec(m_Connection, "ROLLBACK", NULL, NULL, NULL)) != SQLITE_OK)
{
LogErr("Unable to <rollback transaction> because: %s", m_Connection.ErrMsg());
}
}
}
// ------------------------------------------------------------------------------------------------
void Transaction::Commit()
{
if (!m_Commited && m_Connection)
{
if ((m_Connection->Status = sqlite3_exec(m_Connection, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
{
LogErr("Unable to <commit transaction> because: %s", m_Connection.ErrMsg());
}
else
{
m_Commited = true;
}
}
else if (m_Commited)
{
LogWrn("Attempting to <commit transaction> which was already committed");
}
else
{
LogWrn("Attempting to <commit transaction> using an invalid connection");
}
}
// ------------------------------------------------------------------------------------------------
void SetSoftHeapLimit(SQInt32 limit)
{
sqlite3_soft_heap_limit(limit);
}
// ------------------------------------------------------------------------------------------------
SQInt32 ReleaseMemory(SQInt32 bytes)
{
return sqlite3_release_memory(bytes);
}
// ------------------------------------------------------------------------------------------------
SLongInt GetMemoryUsage()
{
return SLongInt(static_cast< SLongInt::Type >(sqlite3_memory_used()));
}
// ------------------------------------------------------------------------------------------------
SLongInt GetMemoryHighwaterMark(bool reset)
{
return SLongInt(static_cast< SLongInt::Type >(sqlite3_memory_highwater(reset)));
}
} // Namespace:: SQLite
// ================================================================================================
bool Register_SQLite(HSQUIRRELVM vm)
{
using namespace SQLite;
// Attempt to create the SQLite namespace
Sqrat::Table sqlns(vm);
// Output debugging information
LogDbg("Beginning registration of <SQLite Connection> type");
// Attempt to register the specified type
sqlns.Bind(_SC("Connection"), Sqrat::Class< Connection >(vm, _SC("Connection"))
/* Constructors */
.Ctor()
.Ctor< const SQChar * >()
.Ctor< const SQChar *, SQInt32 >()
.Ctor< const SQChar *, SQInt32, const SQChar * >()
/* Metamethods */
.Func(_SC("_cmp"), &Connection::Cmp)
.Func(_SC("_tostring"), &Connection::ToString)
/* Properties */
.Prop(_SC("gtag"), &Connection::GetGlobalTag, &Connection::SetGlobalTag)
.Prop(_SC("gdata"), &Connection::GetGlobalData, &Connection::SetGlobalData)
.Prop(_SC("ltag"), &Connection::GetLocalTag, &Connection::SetLocalTag)
.Prop(_SC("ldata"), &Connection::GetLocalData, &Connection::SetLocalData)
.Prop(_SC("refs"), &Connection::GetRefs)
.Prop(_SC("valid"), &Connection::IsValid)
.Prop(_SC("connected"), &Connection::IsValid)
.Prop(_SC("status"), &Connection::GetStatus)
.Prop(_SC("flags"), &Connection::GetFlags)
.Prop(_SC("path"), &Connection::GetPath)
.Prop(_SC("vfs"), &Connection::GetVFS)
.Prop(_SC("err_str"), &Connection::GetErrStr)
.Prop(_SC("err_msg"), &Connection::GetErrMsg)
.Prop(_SC("read_only"), &Connection::IsReadOnly)
.Prop(_SC("auto_commit"), &Connection::GetAutoCommit)
.Prop(_SC("last_insert_row_id"), &Connection::GetLastInsertRowID)
.Prop(_SC("changes"), &Connection::GetChanges)
.Prop(_SC("total_changes"), &Connection::GetTotalChanges)
.Prop(_SC("err_code"), &Connection::GetErrorCode)
.Prop(_SC("extended_err_code"), &Connection::GetExtendedErrorCode)
.Prop(_SC("trace"), &Connection::GetTracing, &Connection::SetTracing)
.Prop(_SC("profile"), &Connection::GetProfiling, &Connection::SetProfiling)
.Prop(_SC("busy_timeout"), &Connection::SetBusyTimeout)
.Prop(_SC("number_of_checked_out_lookaside_memory_slots"), &Connection::GetNumberOfCheckedOutLookasideMemorySlots)
.Prop(_SC("heap_memory_used_by_pager_caches"), &Connection::GetHeapMemoryUsedByPagerCaches)
.Prop(_SC("heap_memory_used_to_store_schemas"), &Connection::GetHeapMemoryUsedToStoreSchemas)
.Prop(_SC("heap_and_lookaside_memory_used_by_prepared_statements"), &Connection::GetHeapAndLookasideMemoryUsedByPreparedStatements)
.Prop(_SC("pagercache_hit_count"), &Connection::GetPagerCacheHitCount)
.Prop(_SC("pagercache_miss_count"), &Connection::GetPagerCacheMissCount)
.Prop(_SC("number_of_dirty_cache_entries"), &Connection::GetNumberOfDirtyCacheEntries)
.Prop(_SC("number_of_unresolved_foreign_keys"), &Connection::GetNumberOfUnresolvedForeignKeys)
.Prop(_SC("highest_number_of_checked_out_lookaside_memory_slots"), &Connection::GetHighestNumberOfCheckedOutLookasideMemorySlots)
.Prop(_SC("lookaside_memory_hit_count"), &Connection::GetLookasideMemoryHitCount)
.Prop(_SC("lookaside_memory_miss_count_due_to_small_slot_size"), &Connection::GetLookasideMemoryMissCountDueToSmallSlotSize)
.Prop(_SC("lookaside_memory_miss_count_due_to_full_memory"), &Connection::GetLookasideMemoryMissCountDueToFullMemory)
/* Functions */
.Func(_SC("release"), &Connection::Release)
.Func(_SC("exec"), &Connection::Exec)
.Func(_SC("queue"), &Connection::Queue)
.Func(_SC("table_exists"), &Connection::TableExists)
.Func(_SC("interrupt_operation"), &Connection::InterruptOperation)
.Func(_SC("release_memory"), &Connection::ReleaseMemory)
.Func(_SC("copy_to_memory"), &Connection::CopyToMemory)
.Func(_SC("copy_to_database"), &Connection::CopyToDatabase)
/* Raw Functions */
.SquirrelFunc(_SC("execf"), &Connection::ExecF)
.SquirrelFunc(_SC("queuef"), &Connection::QueueF)
);
// Output debugging information
LogDbg("Registration of <SQLite Connection> type was successful");
// Output debugging information
LogDbg("Beginning registration of <SQLite Statement> type");
// Attempt to register the specified type
sqlns.Bind(_SC("Statement"), Sqrat::Class< Statement, NoCopy< Statement > >(vm, _SC("Statement"))
/* Constructors */
.Ctor()
.Ctor< const Connection &, const SQChar * >()
/* Metamethods */
.Func(_SC("_cmp"), &Statement::Cmp)
.Func(_SC("_tostring"), &Statement::ToString)
/* Properties */
.Prop(_SC("ltag"), &Statement::GetLocalTag, &Statement::SetLocalTag)
.Prop(_SC("ldata"), &Statement::GetLocalData, &Statement::SetLocalData)
.Prop(_SC("valid"), &Statement::IsValid)
.Prop(_SC("status"), &Statement::GetStatus)
.Prop(_SC("columns"), &Statement::GetColumns)
.Prop(_SC("query"), &Statement::GetQuery)
.Prop(_SC("err_str"), &Statement::GetErrStr)
.Prop(_SC("err_msg"), &Statement::GetErrMsg)
.Prop(_SC("connection"), &Statement::GetConnection)
.Prop(_SC("good"), &Statement::GetGood)
.Prop(_SC("done"), &Statement::GetDone)
.Prop(_SC("err_code"), &Statement::GetErrorCode)
.Prop(_SC("extended_err_code"), &Statement::GetExtendedErrorCode)
/* Functions */
.Func(_SC("reset"), &Statement::Reset)
.Func(_SC("clear"), &Statement::Clear)
.Func(_SC("exec"), &Statement::Exec)
.Func(_SC("step"), &Statement::Step)
.Func(_SC("ibind_a"), &Statement::IndexBindA)
.Func(_SC("ibind_t"), &Statement::IndexBindT)
.Func(_SC("ibind_i"), &Statement::IndexBindI)
.Func(_SC("ibind_l"), &Statement::IndexBindL)
.Func(_SC("ibind_v"), &Statement::IndexBindV)
.Func(_SC("ibind_f"), &Statement::IndexBindF)
.Func(_SC("ibind_s"), &Statement::IndexBindS)
.Func(_SC("ibind_b"), &Statement::IndexBindB)
.Func(_SC("ibind_n"), &Statement::IndexBindN)
.Func(_SC("nbind_t"), &Statement::NameBindT)
.Func(_SC("nbind_i"), &Statement::NameBindI)
.Func(_SC("nbind_l"), &Statement::NameBindL)
.Func(_SC("nbind_v"), &Statement::NameBindV)
.Func(_SC("nbind_f"), &Statement::NameBindF)
.Func(_SC("nbind_s"), &Statement::NameBindS)
.Func(_SC("nbind_b"), &Statement::NameBindB)
.Func(_SC("nbind_n"), &Statement::NameBindN)
.Func(_SC("ibind"), &Statement::IndexBind)
.Func(_SC("nbind"), &Statement::NameBind)
.Func(_SC("fetchi"), &Statement::FetchColumnIndex)
.Func(_SC("fetchn"), &Statement::FetchColumnName)
.Func(_SC("fetcha"), &Statement::FetchArray)
.Func(_SC("fetcht"), &Statement::FetchTable)
.Func(_SC("is_column_null"), &Statement::IsColumnNull)
.Func(_SC("column_name"), &Statement::GetColumnName)
.Func(_SC("column_origin_name"), &Statement::GetColumnOriginName)
.Func(_SC("column_type"), &Statement::GetColumnType)
.Func(_SC("column_bytes"), &Statement::GetColumnBytes)
);
// Output debugging information
LogDbg("Registration of <SQLite Statement> type was successful");
// Output debugging information
LogDbg("Beginning registration of <SQLite Transaction> type");
// Attempt to register the specified type
sqlns.Bind(_SC("Transaction"), Sqrat::Class< Transaction, NoCopy< Transaction > >(vm, _SC("Transaction"))
/* Constructors */
.Ctor< const Connection & >()
/* Properties */
.Prop(_SC("committed"), &Transaction::Commited)
/* Functions */
.Func(_SC("commit"), &Transaction::Commit)
);
// Output debugging information
LogDbg("Registration of <SQLite Transaction> type was successful");
// Output debugging information
LogDbg("Beginning registration of <SQLite functions> type");
// Attempt to register the specified functions
sqlns.Func(_SC("set_soft_heap_limit"), &SetSoftHeapLimit);
sqlns.Func(_SC("release_memory"), &ReleaseMemory);
sqlns.Func(_SC("memory_usage"), &GetMemoryUsage);
sqlns.Func(_SC("memory_highwater_mark"), &GetMemoryHighwaterMark);
// Output debugging information
LogDbg("Registration of <SQLite functions> type was successful");
// Attempt to bind the namespace to the root table
Sqrat::RootTable(vm).Bind(_SC("SQLite"), sqlns);
// Output debugging information
LogDbg("Beginning registration of <SQLite Constants> type");
/*
// Attempt to register the SQLite constants enumeration
Sqrat::ConstTable(vm).Enum(_SC("ESQLITE"), Sqrat::Enumeration(vm)
.Const(_SC("ABORT"), SQLITE_ABORT)
.Const(_SC("ABORT_ROLLBACK"), SQLITE_ABORT_ROLLBACK)
.Const(_SC("ACCESS_EXISTS"), SQLITE_ACCESS_EXISTS)
.Const(_SC("ACCESS_READ"), SQLITE_ACCESS_READ)
.Const(_SC("ACCESS_READWRITE"), SQLITE_ACCESS_READWRITE)
.Const(_SC("ALTER_TABLE"), SQLITE_ALTER_TABLE)
.Const(_SC("ANALYZE"), SQLITE_ANALYZE)
.Const(_SC("ANY"), SQLITE_ANY)
.Const(_SC("ATTACH"), SQLITE_ATTACH)
.Const(_SC("AUTH"), SQLITE_AUTH)
.Const(_SC("AUTH_USER"), SQLITE_AUTH_USER)
.Const(_SC("BLOB"), SQLITE_BLOB)
.Const(_SC("BUSY"), SQLITE_BUSY)
.Const(_SC("BUSY_RECOVERY"), SQLITE_BUSY_RECOVERY)
.Const(_SC("BUSY_SNAPSHOT"), SQLITE_BUSY_SNAPSHOT)
.Const(_SC("CANTOPEN"), SQLITE_CANTOPEN)
.Const(_SC("CANTOPEN_CONVPATH"), SQLITE_CANTOPEN_CONVPATH)
.Const(_SC("CANTOPEN_FULLPATH"), SQLITE_CANTOPEN_FULLPATH)
.Const(_SC("CANTOPEN_ISDIR"), SQLITE_CANTOPEN_ISDIR)
.Const(_SC("CANTOPEN_NOTEMPDIR"), SQLITE_CANTOPEN_NOTEMPDIR)
.Const(_SC("CHECKPOINT_FULL"), SQLITE_CHECKPOINT_FULL)
.Const(_SC("CHECKPOINT_PASSIVE"), SQLITE_CHECKPOINT_PASSIVE)
.Const(_SC("CHECKPOINT_RESTART"), SQLITE_CHECKPOINT_RESTART)
.Const(_SC("CHECKPOINT_TRUNCATE"), SQLITE_CHECKPOINT_TRUNCATE)
.Const(_SC("CONFIG_COVERING_INDEX_SCAN"), SQLITE_CONFIG_COVERING_INDEX_SCAN)
.Const(_SC("CONFIG_GETMALLOC"), SQLITE_CONFIG_GETMALLOC)
.Const(_SC("CONFIG_GETMUTEX"), SQLITE_CONFIG_GETMUTEX)
.Const(_SC("CONFIG_GETPCACHE"), SQLITE_CONFIG_GETPCACHE)
.Const(_SC("CONFIG_GETPCACHE2"), SQLITE_CONFIG_GETPCACHE2)
.Const(_SC("CONFIG_HEAP"), SQLITE_CONFIG_HEAP)
.Const(_SC("CONFIG_LOG"), SQLITE_CONFIG_LOG)
.Const(_SC("CONFIG_LOOKASIDE"), SQLITE_CONFIG_LOOKASIDE)
.Const(_SC("CONFIG_MALLOC"), SQLITE_CONFIG_MALLOC)
.Const(_SC("CONFIG_MEMSTATUS"), SQLITE_CONFIG_MEMSTATUS)
.Const(_SC("CONFIG_MMAP_SIZE"), SQLITE_CONFIG_MMAP_SIZE)
.Const(_SC("CONFIG_MULTITHREAD"), SQLITE_CONFIG_MULTITHREAD)
.Const(_SC("CONFIG_MUTEX"), SQLITE_CONFIG_MUTEX)
.Const(_SC("CONFIG_PAGECACHE"), SQLITE_CONFIG_PAGECACHE)
.Const(_SC("CONFIG_PCACHE"), SQLITE_CONFIG_PCACHE)
.Const(_SC("CONFIG_PCACHE2"), SQLITE_CONFIG_PCACHE2)
.Const(_SC("CONFIG_PCACHE_HDRSZ"), SQLITE_CONFIG_PCACHE_HDRSZ)
.Const(_SC("CONFIG_PMASZ"), SQLITE_CONFIG_PMASZ)
.Const(_SC("CONFIG_SCRATCH"), SQLITE_CONFIG_SCRATCH)
.Const(_SC("CONFIG_SERIALIZED"), SQLITE_CONFIG_SERIALIZED)
.Const(_SC("CONFIG_SINGLETHREAD"), SQLITE_CONFIG_SINGLETHREAD)
.Const(_SC("CONFIG_SQLLOG"), SQLITE_CONFIG_SQLLOG)
.Const(_SC("CONFIG_URI"), SQLITE_CONFIG_URI)
.Const(_SC("CONFIG_WIN32_HEAPSIZE"), SQLITE_CONFIG_WIN32_HEAPSIZE)
.Const(_SC("CONSTRAINT"), SQLITE_CONSTRAINT)
.Const(_SC("CONSTRAINT_CHECK"), SQLITE_CONSTRAINT_CHECK)
.Const(_SC("CONSTRAINT_COMMITHOOK"), SQLITE_CONSTRAINT_COMMITHOOK)
.Const(_SC("CONSTRAINT_FOREIGNKEY"), SQLITE_CONSTRAINT_FOREIGNKEY)
.Const(_SC("CONSTRAINT_FUNCTION"), SQLITE_CONSTRAINT_FUNCTION)
.Const(_SC("CONSTRAINT_NOTNULL"), SQLITE_CONSTRAINT_NOTNULL)
.Const(_SC("CONSTRAINT_PRIMARYKEY"), SQLITE_CONSTRAINT_PRIMARYKEY)
.Const(_SC("CONSTRAINT_ROWID"), SQLITE_CONSTRAINT_ROWID)
.Const(_SC("CONSTRAINT_TRIGGER"), SQLITE_CONSTRAINT_TRIGGER)
.Const(_SC("CONSTRAINT_UNIQUE"), SQLITE_CONSTRAINT_UNIQUE)
.Const(_SC("CONSTRAINT_VTAB"), SQLITE_CONSTRAINT_VTAB)
.Const(_SC("COPY"), SQLITE_COPY)
.Const(_SC("CORRUPT"), SQLITE_CORRUPT)
.Const(_SC("CORRUPT_VTAB"), SQLITE_CORRUPT_VTAB)
.Const(_SC("CREATE_INDEX"), SQLITE_CREATE_INDEX)
.Const(_SC("CREATE_TABLE"), SQLITE_CREATE_TABLE)
.Const(_SC("CREATE_TEMP_INDEX"), SQLITE_CREATE_TEMP_INDEX)
.Const(_SC("CREATE_TEMP_TABLE"), SQLITE_CREATE_TEMP_TABLE)
.Const(_SC("CREATE_TEMP_TRIGGER"), SQLITE_CREATE_TEMP_TRIGGER)
.Const(_SC("CREATE_TEMP_VIEW"), SQLITE_CREATE_TEMP_VIEW)
.Const(_SC("CREATE_TRIGGER"), SQLITE_CREATE_TRIGGER)
.Const(_SC("CREATE_VIEW"), SQLITE_CREATE_VIEW)
.Const(_SC("CREATE_VTABLE"), SQLITE_CREATE_VTABLE)
.Const(_SC("DBCONFIG_ENABLE_FKEY"), SQLITE_DBCONFIG_ENABLE_FKEY)
.Const(_SC("DBCONFIG_ENABLE_TRIGGER"), SQLITE_DBCONFIG_ENABLE_TRIGGER)
.Const(_SC("DBCONFIG_LOOKASIDE"), SQLITE_DBCONFIG_LOOKASIDE)
.Const(_SC("DBSTATUS_CACHE_HIT"), SQLITE_DBSTATUS_CACHE_HIT)
.Const(_SC("DBSTATUS_CACHE_MISS"), SQLITE_DBSTATUS_CACHE_MISS)
.Const(_SC("DBSTATUS_CACHE_USED"), SQLITE_DBSTATUS_CACHE_USED)
.Const(_SC("DBSTATUS_CACHE_WRITE"), SQLITE_DBSTATUS_CACHE_WRITE)
.Const(_SC("DBSTATUS_DEFERRED_FKS"), SQLITE_DBSTATUS_DEFERRED_FKS)
.Const(_SC("DBSTATUS_LOOKASIDE_HIT"), SQLITE_DBSTATUS_LOOKASIDE_HIT)
.Const(_SC("DBSTATUS_LOOKASIDE_MISS_FULL"), SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL)
.Const(_SC("DBSTATUS_LOOKASIDE_MISS_SIZE"), SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE)
.Const(_SC("DBSTATUS_LOOKASIDE_USED"), SQLITE_DBSTATUS_LOOKASIDE_USED)
.Const(_SC("DBSTATUS_MAX"), SQLITE_DBSTATUS_MAX)
.Const(_SC("DBSTATUS_SCHEMA_USED"), SQLITE_DBSTATUS_SCHEMA_USED)
.Const(_SC("DBSTATUS_STMT_USED"), SQLITE_DBSTATUS_STMT_USED)
.Const(_SC("DELETE"), SQLITE_DELETE)
.Const(_SC("DENY"), SQLITE_DENY)
.Const(_SC("DETACH"), SQLITE_DETACH)
.Const(_SC("DETERMINISTIC"), SQLITE_DETERMINISTIC)
.Const(_SC("DONE"), SQLITE_DONE)
.Const(_SC("DROP_INDEX"), SQLITE_DROP_INDEX)
.Const(_SC("DROP_TABLE"), SQLITE_DROP_TABLE)
.Const(_SC("DROP_TEMP_INDEX"), SQLITE_DROP_TEMP_INDEX)
.Const(_SC("DROP_TEMP_TABLE"), SQLITE_DROP_TEMP_TABLE)
.Const(_SC("DROP_TEMP_TRIGGER"), SQLITE_DROP_TEMP_TRIGGER)
.Const(_SC("DROP_TEMP_VIEW"), SQLITE_DROP_TEMP_VIEW)
.Const(_SC("DROP_TRIGGER"), SQLITE_DROP_TRIGGER)
.Const(_SC("DROP_VIEW"), SQLITE_DROP_VIEW)
.Const(_SC("DROP_VTABLE"), SQLITE_DROP_VTABLE)
.Const(_SC("EMPTY"), SQLITE_EMPTY)
.Const(_SC("ERROR"), SQLITE_ERROR)
.Const(_SC("FAIL"), SQLITE_FAIL)
.Const(_SC("FCNTL_BUSYHANDLER"), SQLITE_FCNTL_BUSYHANDLER)
.Const(_SC("FCNTL_CHUNK_SIZE"), SQLITE_FCNTL_CHUNK_SIZE)
.Const(_SC("FCNTL_COMMIT_PHASETWO"), SQLITE_FCNTL_COMMIT_PHASETWO)
.Const(_SC("FCNTL_FILE_POINTER"), SQLITE_FCNTL_FILE_POINTER)
.Const(_SC("FCNTL_GET_LOCKPROXYFILE"), SQLITE_FCNTL_GET_LOCKPROXYFILE)
.Const(_SC("FCNTL_HAS_MOVED"), SQLITE_FCNTL_HAS_MOVED)
.Const(_SC("FCNTL_LAST_ERRNO"), SQLITE_FCNTL_LAST_ERRNO)
.Const(_SC("FCNTL_LOCKSTATE"), SQLITE_FCNTL_LOCKSTATE)
.Const(_SC("FCNTL_MMAP_SIZE"), SQLITE_FCNTL_MMAP_SIZE)
.Const(_SC("FCNTL_OVERWRITE"), SQLITE_FCNTL_OVERWRITE)
.Const(_SC("FCNTL_PERSIST_WAL"), SQLITE_FCNTL_PERSIST_WAL)
.Const(_SC("FCNTL_POWERSAFE_OVERWRITE"), SQLITE_FCNTL_POWERSAFE_OVERWRITE)
.Const(_SC("FCNTL_PRAGMA"), SQLITE_FCNTL_PRAGMA)
.Const(_SC("FCNTL_RBU"), SQLITE_FCNTL_RBU)
.Const(_SC("FCNTL_SET_LOCKPROXYFILE"), SQLITE_FCNTL_SET_LOCKPROXYFILE)
.Const(_SC("FCNTL_SIZE_HINT"), SQLITE_FCNTL_SIZE_HINT)
.Const(_SC("FCNTL_SYNC"), SQLITE_FCNTL_SYNC)
.Const(_SC("FCNTL_SYNC_OMITTED"), SQLITE_FCNTL_SYNC_OMITTED)
.Const(_SC("FCNTL_TEMPFILENAME"), SQLITE_FCNTL_TEMPFILENAME)
.Const(_SC("FCNTL_TRACE"), SQLITE_FCNTL_TRACE)
.Const(_SC("FCNTL_VFSNAME"), SQLITE_FCNTL_VFSNAME)
.Const(_SC("FCNTL_WAL_BLOCK"), SQLITE_FCNTL_WAL_BLOCK)
.Const(_SC("FCNTL_WIN32_AV_RETRY"), SQLITE_FCNTL_WIN32_AV_RETRY)
.Const(_SC("FCNTL_WIN32_SET_HANDLE"), SQLITE_FCNTL_WIN32_SET_HANDLE)
.Const(_SC("FCNTL_ZIPVFS"), SQLITE_FCNTL_ZIPVFS)
.Const(_SC("FLOAT"), SQLITE_FLOAT)
.Const(_SC("FORMAT"), SQLITE_FORMAT)
.Const(_SC("FULL"), SQLITE_FULL)
.Const(_SC("FUNCTION"), SQLITE_FUNCTION)
.Const(_SC("IGNORE"), SQLITE_IGNORE)
.Const(_SC("INDEX_CONSTRAINT_EQ"), SQLITE_INDEX_CONSTRAINT_EQ)
.Const(_SC("INDEX_CONSTRAINT_GE"), SQLITE_INDEX_CONSTRAINT_GE)
.Const(_SC("INDEX_CONSTRAINT_GT"), SQLITE_INDEX_CONSTRAINT_GT)
.Const(_SC("INDEX_CONSTRAINT_LE"), SQLITE_INDEX_CONSTRAINT_LE)
.Const(_SC("INDEX_CONSTRAINT_LT"), SQLITE_INDEX_CONSTRAINT_LT)
.Const(_SC("INDEX_CONSTRAINT_MATCH"), SQLITE_INDEX_CONSTRAINT_MATCH)
.Const(_SC("INDEX_SCAN_UNIQUE"), SQLITE_INDEX_SCAN_UNIQUE)
.Const(_SC("INSERT"), SQLITE_INSERT)
.Const(_SC("INTEGER"), SQLITE_INTEGER)
.Const(_SC("INTERNAL"), SQLITE_INTERNAL)
.Const(_SC("INTERRUPT"), SQLITE_INTERRUPT)
.Const(_SC("IOCAP_ATOMIC"), SQLITE_IOCAP_ATOMIC)
.Const(_SC("IOCAP_ATOMIC16K"), SQLITE_IOCAP_ATOMIC16K)
.Const(_SC("IOCAP_ATOMIC1K"), SQLITE_IOCAP_ATOMIC1K)
.Const(_SC("IOCAP_ATOMIC2K"), SQLITE_IOCAP_ATOMIC2K)
.Const(_SC("IOCAP_ATOMIC32K"), SQLITE_IOCAP_ATOMIC32K)
.Const(_SC("IOCAP_ATOMIC4K"), SQLITE_IOCAP_ATOMIC4K)
.Const(_SC("IOCAP_ATOMIC512"), SQLITE_IOCAP_ATOMIC512)
.Const(_SC("IOCAP_ATOMIC64K"), SQLITE_IOCAP_ATOMIC64K)
.Const(_SC("IOCAP_ATOMIC8K"), SQLITE_IOCAP_ATOMIC8K)
.Const(_SC("IOCAP_IMMUTABLE"), SQLITE_IOCAP_IMMUTABLE)
.Const(_SC("IOCAP_POWERSAFE_OVERWRITE"), SQLITE_IOCAP_POWERSAFE_OVERWRITE)
.Const(_SC("IOCAP_SAFE_APPEND"), SQLITE_IOCAP_SAFE_APPEND)
.Const(_SC("IOCAP_SEQUENTIAL"), SQLITE_IOCAP_SEQUENTIAL)
.Const(_SC("IOCAP_UNDELETABLE_WHEN_OPEN"), SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN)
.Const(_SC("IOERR"), SQLITE_IOERR)
.Const(_SC("IOERR_ACCESS"), SQLITE_IOERR_ACCESS)
.Const(_SC("IOERR_BLOCKED"), SQLITE_IOERR_BLOCKED)
.Const(_SC("IOERR_CHECKRESERVEDLOCK"), SQLITE_IOERR_CHECKRESERVEDLOCK)
.Const(_SC("IOERR_CLOSE"), SQLITE_IOERR_CLOSE)
.Const(_SC("IOERR_CONVPATH"), SQLITE_IOERR_CONVPATH)
.Const(_SC("IOERR_DELETE"), SQLITE_IOERR_DELETE)
.Const(_SC("IOERR_DELETE_NOENT"), SQLITE_IOERR_DELETE_NOENT)
.Const(_SC("IOERR_DIR_CLOSE"), SQLITE_IOERR_DIR_CLOSE)
.Const(_SC("IOERR_DIR_FSYNC"), SQLITE_IOERR_DIR_FSYNC)
.Const(_SC("IOERR_FSTAT"), SQLITE_IOERR_FSTAT)
.Const(_SC("IOERR_FSYNC"), SQLITE_IOERR_FSYNC)
.Const(_SC("IOERR_GETTEMPPATH"), SQLITE_IOERR_GETTEMPPATH)
.Const(_SC("IOERR_LOCK"), SQLITE_IOERR_LOCK)
.Const(_SC("IOERR_MMAP"), SQLITE_IOERR_MMAP)
.Const(_SC("IOERR_NOMEM"), SQLITE_IOERR_NOMEM)
.Const(_SC("IOERR_RDLOCK"), SQLITE_IOERR_RDLOCK)
.Const(_SC("IOERR_READ"), SQLITE_IOERR_READ)
.Const(_SC("IOERR_SEEK"), SQLITE_IOERR_SEEK)
.Const(_SC("IOERR_SHMLOCK"), SQLITE_IOERR_SHMLOCK)
.Const(_SC("IOERR_SHMMAP"), SQLITE_IOERR_SHMMAP)
.Const(_SC("IOERR_SHMOPEN"), SQLITE_IOERR_SHMOPEN)
.Const(_SC("IOERR_SHMSIZE"), SQLITE_IOERR_SHMSIZE)
.Const(_SC("IOERR_SHORT_READ"), SQLITE_IOERR_SHORT_READ)
.Const(_SC("IOERR_TRUNCATE"), SQLITE_IOERR_TRUNCATE)
.Const(_SC("IOERR_UNLOCK"), SQLITE_IOERR_UNLOCK)
.Const(_SC("IOERR_VNODE"), SQLITE_IOERR_VNODE)
.Const(_SC("IOERR_WRITE"), SQLITE_IOERR_WRITE)
.Const(_SC("LIMIT_ATTACHED"), SQLITE_LIMIT_ATTACHED)
.Const(_SC("LIMIT_COLUMN"), SQLITE_LIMIT_COLUMN)
.Const(_SC("LIMIT_COMPOUND_SELECT"), SQLITE_LIMIT_COMPOUND_SELECT)
.Const(_SC("LIMIT_EXPR_DEPTH"), SQLITE_LIMIT_EXPR_DEPTH)
.Const(_SC("LIMIT_FUNCTION_ARG"), SQLITE_LIMIT_FUNCTION_ARG)
.Const(_SC("LIMIT_LENGTH"), SQLITE_LIMIT_LENGTH)
.Const(_SC("LIMIT_LIKE_PATTERN_LENGTH"), SQLITE_LIMIT_LIKE_PATTERN_LENGTH)
.Const(_SC("LIMIT_SQL_LENGTH"), SQLITE_LIMIT_SQL_LENGTH)
.Const(_SC("LIMIT_TRIGGER_DEPTH"), SQLITE_LIMIT_TRIGGER_DEPTH)
.Const(_SC("LIMIT_VARIABLE_NUMBER"), SQLITE_LIMIT_VARIABLE_NUMBER)
.Const(_SC("LIMIT_VDBE_OP"), SQLITE_LIMIT_VDBE_OP)
.Const(_SC("LIMIT_WORKER_THREADS"), SQLITE_LIMIT_WORKER_THREADS)
.Const(_SC("LOCKED"), SQLITE_LOCKED)
.Const(_SC("LOCKED_SHAREDCACHE"), SQLITE_LOCKED_SHAREDCACHE)
.Const(_SC("LOCK_EXCLUSIVE"), SQLITE_LOCK_EXCLUSIVE)
.Const(_SC("LOCK_NONE"), SQLITE_LOCK_NONE)
.Const(_SC("LOCK_PENDING"), SQLITE_LOCK_PENDING)
.Const(_SC("LOCK_RESERVED"), SQLITE_LOCK_RESERVED)
.Const(_SC("LOCK_SHARED"), SQLITE_LOCK_SHARED)
.Const(_SC("MISMATCH"), SQLITE_MISMATCH)
.Const(_SC("MISUSE"), SQLITE_MISUSE)
.Const(_SC("MUTEX_FAST"), SQLITE_MUTEX_FAST)
.Const(_SC("MUTEX_RECURSIVE"), SQLITE_MUTEX_RECURSIVE)
.Const(_SC("MUTEX_STATIC_APP1"), SQLITE_MUTEX_STATIC_APP1)
.Const(_SC("MUTEX_STATIC_APP2"), SQLITE_MUTEX_STATIC_APP2)
.Const(_SC("MUTEX_STATIC_APP3"), SQLITE_MUTEX_STATIC_APP3)
.Const(_SC("MUTEX_STATIC_LRU"), SQLITE_MUTEX_STATIC_LRU)
.Const(_SC("MUTEX_STATIC_LRU2"), SQLITE_MUTEX_STATIC_LRU2)
.Const(_SC("MUTEX_STATIC_MASTER"), SQLITE_MUTEX_STATIC_MASTER)
.Const(_SC("MUTEX_STATIC_MEM"), SQLITE_MUTEX_STATIC_MEM)
.Const(_SC("MUTEX_STATIC_MEM2"), SQLITE_MUTEX_STATIC_MEM2)
.Const(_SC("MUTEX_STATIC_OPEN"), SQLITE_MUTEX_STATIC_OPEN)
.Const(_SC("MUTEX_STATIC_PMEM"), SQLITE_MUTEX_STATIC_PMEM)
.Const(_SC("MUTEX_STATIC_PRNG"), SQLITE_MUTEX_STATIC_PRNG)
.Const(_SC("MUTEX_STATIC_VFS1"), SQLITE_MUTEX_STATIC_VFS1)
.Const(_SC("MUTEX_STATIC_VFS2"), SQLITE_MUTEX_STATIC_VFS2)
.Const(_SC("MUTEX_STATIC_VFS3"), SQLITE_MUTEX_STATIC_VFS3)
.Const(_SC("NOLFS"), SQLITE_NOLFS)
.Const(_SC("NOMEM"), SQLITE_NOMEM)
.Const(_SC("NOTADB"), SQLITE_NOTADB)
.Const(_SC("NOTFOUND"), SQLITE_NOTFOUND)
.Const(_SC("NOTICE"), SQLITE_NOTICE)
.Const(_SC("NOTICE_RECOVER_ROLLBACK"), SQLITE_NOTICE_RECOVER_ROLLBACK)
.Const(_SC("NOTICE_RECOVER_WAL"), SQLITE_NOTICE_RECOVER_WAL)
.Const(_SC("NULL"), SQLITE_NULL)
.Const(_SC("OK"), SQLITE_OK)
.Const(_SC("OPEN_AUTOPROXY"), SQLITE_OPEN_AUTOPROXY)
.Const(_SC("OPEN_CREATE"), SQLITE_OPEN_CREATE)
.Const(_SC("OPEN_DELETEONCLOSE"), SQLITE_OPEN_DELETEONCLOSE)
.Const(_SC("OPEN_EXCLUSIVE"), SQLITE_OPEN_EXCLUSIVE)
.Const(_SC("OPEN_FULLMUTEX"), SQLITE_OPEN_FULLMUTEX)
.Const(_SC("OPEN_MAIN_DB"), SQLITE_OPEN_MAIN_DB)
.Const(_SC("OPEN_MAIN_JOURNAL"), SQLITE_OPEN_MAIN_JOURNAL)
.Const(_SC("OPEN_MASTER_JOURNAL"), SQLITE_OPEN_MASTER_JOURNAL)
.Const(_SC("OPEN_MEMORY"), SQLITE_OPEN_MEMORY)
.Const(_SC("OPEN_NOMUTEX"), SQLITE_OPEN_NOMUTEX)
.Const(_SC("OPEN_PRIVATECACHE"), SQLITE_OPEN_PRIVATECACHE)
.Const(_SC("OPEN_READONLY"), SQLITE_OPEN_READONLY)
.Const(_SC("OPEN_READWRITE"), SQLITE_OPEN_READWRITE)
.Const(_SC("OPEN_SHAREDCACHE"), SQLITE_OPEN_SHAREDCACHE)
.Const(_SC("OPEN_SUBJOURNAL"), SQLITE_OPEN_SUBJOURNAL)
.Const(_SC("OPEN_TEMP_DB"), SQLITE_OPEN_TEMP_DB)
.Const(_SC("OPEN_TEMP_JOURNAL"), SQLITE_OPEN_TEMP_JOURNAL)
.Const(_SC("OPEN_TRANSIENT_DB"), SQLITE_OPEN_TRANSIENT_DB)
.Const(_SC("OPEN_URI"), SQLITE_OPEN_URI)
.Const(_SC("OPEN_WAL"), SQLITE_OPEN_WAL)
.Const(_SC("PERM"), SQLITE_PERM)
.Const(_SC("PRAGMA"), SQLITE_PRAGMA)
.Const(_SC("PROTOCOL"), SQLITE_PROTOCOL)
.Const(_SC("RANGE"), SQLITE_RANGE)
.Const(_SC("READ"), SQLITE_READ)
.Const(_SC("READONLY"), SQLITE_READONLY)
.Const(_SC("READONLY_CANTLOCK"), SQLITE_READONLY_CANTLOCK)
.Const(_SC("READONLY_DBMOVED"), SQLITE_READONLY_DBMOVED)
.Const(_SC("READONLY_RECOVERY"), SQLITE_READONLY_RECOVERY)
.Const(_SC("READONLY_ROLLBACK"), SQLITE_READONLY_ROLLBACK)
.Const(_SC("RECURSIVE"), SQLITE_RECURSIVE)
.Const(_SC("REINDEX"), SQLITE_REINDEX)
.Const(_SC("REPLACE"), SQLITE_REPLACE)
.Const(_SC("ROLLBACK"), SQLITE_ROLLBACK)
.Const(_SC("ROW"), SQLITE_ROW)
.Const(_SC("SAVEPOINT"), SQLITE_SAVEPOINT)
.Const(_SC("SCANSTAT_EST"), SQLITE_SCANSTAT_EST)
.Const(_SC("SCANSTAT_EXPLAIN"), SQLITE_SCANSTAT_EXPLAIN)
.Const(_SC("SCANSTAT_NAME"), SQLITE_SCANSTAT_NAME)
.Const(_SC("SCANSTAT_NLOOP"), SQLITE_SCANSTAT_NLOOP)
.Const(_SC("SCANSTAT_NVISIT"), SQLITE_SCANSTAT_NVISIT)
.Const(_SC("SCANSTAT_SELECTID"), SQLITE_SCANSTAT_SELECTID)
.Const(_SC("SCHEMA"), SQLITE_SCHEMA)
.Const(_SC("SELECT"), SQLITE_SELECT)
.Const(_SC("SHM_EXCLUSIVE"), SQLITE_SHM_EXCLUSIVE)
.Const(_SC("SHM_LOCK"), SQLITE_SHM_LOCK)
.Const(_SC("SHM_NLOCK"), SQLITE_SHM_NLOCK)
.Const(_SC("SHM_SHARED"), SQLITE_SHM_SHARED)
.Const(_SC("SHM_UNLOCK"), SQLITE_SHM_UNLOCK)
.Const(_SC("SOURCE_ID"), SQLITE_SOURCE_ID)
.Const(_SC("STATUS_MALLOC_COUNT"), SQLITE_STATUS_MALLOC_COUNT)
.Const(_SC("STATUS_MALLOC_SIZE"), SQLITE_STATUS_MALLOC_SIZE)
.Const(_SC("STATUS_MEMORY_USED"), SQLITE_STATUS_MEMORY_USED)
.Const(_SC("STATUS_PAGECACHE_OVERFLOW"), SQLITE_STATUS_PAGECACHE_OVERFLOW)
.Const(_SC("STATUS_PAGECACHE_SIZE"), SQLITE_STATUS_PAGECACHE_SIZE)
.Const(_SC("STATUS_PAGECACHE_USED"), SQLITE_STATUS_PAGECACHE_USED)
.Const(_SC("STATUS_PARSER_STACK"), SQLITE_STATUS_PARSER_STACK)
.Const(_SC("STATUS_SCRATCH_OVERFLOW"), SQLITE_STATUS_SCRATCH_OVERFLOW)
.Const(_SC("STATUS_SCRATCH_SIZE"), SQLITE_STATUS_SCRATCH_SIZE)
.Const(_SC("STATUS_SCRATCH_USED"), SQLITE_STATUS_SCRATCH_USED)
.Const(_SC("STMTSTATUS_AUTOINDEX"), SQLITE_STMTSTATUS_AUTOINDEX)
.Const(_SC("STMTSTATUS_FULLSCAN_STEP"), SQLITE_STMTSTATUS_FULLSCAN_STEP)
.Const(_SC("STMTSTATUS_SORT"), SQLITE_STMTSTATUS_SORT)
.Const(_SC("STMTSTATUS_VM_STEP"), SQLITE_STMTSTATUS_VM_STEP)
.Const(_SC("SYNC_DATAONLY"), SQLITE_SYNC_DATAONLY)
.Const(_SC("SYNC_FULL"), SQLITE_SYNC_FULL)
.Const(_SC("SYNC_NORMAL"), SQLITE_SYNC_NORMAL)
.Const(_SC("TESTCTRL_ALWAYS"), SQLITE_TESTCTRL_ALWAYS)
.Const(_SC("TESTCTRL_ASSERT"), SQLITE_TESTCTRL_ASSERT)
.Const(_SC("TESTCTRL_BENIGN_MALLOC_HOOKS"), SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS)
.Const(_SC("TESTCTRL_BITVEC_TEST"), SQLITE_TESTCTRL_BITVEC_TEST)
.Const(_SC("TESTCTRL_BYTEORDER"), SQLITE_TESTCTRL_BYTEORDER)
.Const(_SC("TESTCTRL_EXPLAIN_STMT"), SQLITE_TESTCTRL_EXPLAIN_STMT)
.Const(_SC("TESTCTRL_FAULT_INSTALL"), SQLITE_TESTCTRL_FAULT_INSTALL)
.Const(_SC("TESTCTRL_FIRST"), SQLITE_TESTCTRL_FIRST)
.Const(_SC("TESTCTRL_IMPOSTER"), SQLITE_TESTCTRL_IMPOSTER)
.Const(_SC("TESTCTRL_ISINIT"), SQLITE_TESTCTRL_ISINIT)
.Const(_SC("TESTCTRL_ISKEYWORD"), SQLITE_TESTCTRL_ISKEYWORD)
.Const(_SC("TESTCTRL_LAST"), SQLITE_TESTCTRL_LAST)
.Const(_SC("TESTCTRL_LOCALTIME_FAULT"), SQLITE_TESTCTRL_LOCALTIME_FAULT)
.Const(_SC("TESTCTRL_NEVER_CORRUPT"), SQLITE_TESTCTRL_NEVER_CORRUPT)
.Const(_SC("TESTCTRL_OPTIMIZATIONS"), SQLITE_TESTCTRL_OPTIMIZATIONS)
.Const(_SC("TESTCTRL_PENDING_BYTE"), SQLITE_TESTCTRL_PENDING_BYTE)
.Const(_SC("TESTCTRL_PRNG_RESET"), SQLITE_TESTCTRL_PRNG_RESET)
.Const(_SC("TESTCTRL_PRNG_RESTORE"), SQLITE_TESTCTRL_PRNG_RESTORE)
.Const(_SC("TESTCTRL_PRNG_SAVE"), SQLITE_TESTCTRL_PRNG_SAVE)
.Const(_SC("TESTCTRL_RESERVE"), SQLITE_TESTCTRL_RESERVE)
.Const(_SC("TESTCTRL_SCRATCHMALLOC"), SQLITE_TESTCTRL_SCRATCHMALLOC)
.Const(_SC("TESTCTRL_SORTER_MMAP"), SQLITE_TESTCTRL_SORTER_MMAP)
.Const(_SC("TESTCTRL_VDBE_COVERAGE"), SQLITE_TESTCTRL_VDBE_COVERAGE)
.Const(_SC("TEXT"), SQLITE_TEXT)
.Const(_SC("TOOBIG"), SQLITE_TOOBIG)
.Const(_SC("TRANSACTION"), SQLITE_TRANSACTION)
.Const(_SC("UPDATE"), SQLITE_UPDATE)
.Const(_SC("UTF16"), SQLITE_UTF16)
.Const(_SC("UTF16BE"), SQLITE_UTF16BE)
.Const(_SC("UTF16LE"), SQLITE_UTF16LE)
.Const(_SC("UTF16_ALIGNED"), SQLITE_UTF16_ALIGNED)
.Const(_SC("UTF8"), SQLITE_UTF8)
.Const(_SC("VERSION"), SQLITE_VERSION)
.Const(_SC("VERSION_NUMBER"), SQLITE_VERSION_NUMBER)
.Const(_SC("VTAB_CONSTRAINT_SUPPORT"), SQLITE_VTAB_CONSTRAINT_SUPPORT)
.Const(_SC("WARNING"), SQLITE_WARNING)
.Const(_SC("WARNING_AUTOINDEX"), SQLITE_WARNING_AUTOINDEX)
);
*/
// Output debugging information
LogDbg("Registration of <SQLite Constants> type was successful");
// Registration succeeded
return true;
}
} // Namespace:: SqMod

View File

@@ -1,415 +0,0 @@
#ifndef _LIBRARY_SQLITE_SHARED_HPP_
#define _LIBRARY_SQLITE_SHARED_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
#include "Library/LongInt.hpp"
// ------------------------------------------------------------------------------------------------
#include <sqlite3.h>
// ------------------------------------------------------------------------------------------------
#include <queue>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace SQLite {
// ------------------------------------------------------------------------------------------------
class Connection;
class Statement;
class Result;
/* ------------------------------------------------------------------------------------------------
* A managed handle to a shared SQLite connection.
*/
class ConnectionHandle
{
// --------------------------------------------------------------------------------------------
friend class Connection;
protected:
/* --------------------------------------------------------------------------------------------
* Helper class responsible for managing the handle to an SQLite connection resource.
*/
struct Handle
{
friend class ConnectionHandle;
/* ----------------------------------------------------------------------------------------
* The type of container used to queue queries for group execution.
*/
typedef std::queue< String > QueryList;
/* ----------------------------------------------------------------------------------------
* The amount of references to this handle instance.
*/
mutable SQUint32 Ref;
/* ----------------------------------------------------------------------------------------
* The handle to the managed SQLite connection resource.
*/
sqlite3* Ptr;
/* ----------------------------------------------------------------------------------------
* The flags used to create the SQLite connection handle.
*/
SQInt32 Flags;
/* ----------------------------------------------------------------------------------------
* The specified path to be used as the database file.
*/
String Path;
/* ----------------------------------------------------------------------------------------
* The specified virtual file system.
*/
String VFS;
/* ----------------------------------------------------------------------------------------
* The last status code of this connection handle.
*/
SQInt32 Status;
/* ----------------------------------------------------------------------------------------
* A queue of queries to be executed in groups in order to reduce lag.
*/
QueryList Queue;
/* ----------------------------------------------------------------------------------------
* The global tag associated with this resource.
*/
SqTag Tag;
/* ----------------------------------------------------------------------------------------
* The global data associated with this resource.
*/
SqObj Data;
/* ----------------------------------------------------------------------------------------
* Whether the database exists in memory and not disk.
*/
bool Memory;
/* ----------------------------------------------------------------------------------------
* Whether tracing was activated on the database.
*/
bool Trace;
/* ----------------------------------------------------------------------------------------
* Whether profiling was activated on the database.
*/
bool Profile;
private:
/* ----------------------------------------------------------------------------------------
* Handle constructor.
*/
Handle(const String & path, SQInt32 flags, const String & vfs)
: Ref(1), Ptr(NULL), Flags(flags), Path(path), VFS(vfs)
, Status(SQLITE_OK), Queue(), Tag(), Data()
, Memory(path == ":memory:"), Trace(false), Profile(false)
{
/* ... */
}
/* ----------------------------------------------------------------------------------------
* Copy constructor (disabled)
*/
Handle(const Handle &) = delete;
/* ----------------------------------------------------------------------------------------
* Move constructor (disabled)
*/
Handle(Handle &&) = delete;
/* ----------------------------------------------------------------------------------------
* Handle destructor.
*/
~Handle()
{
// If a valid handle exists then attempt to release it
if (Ptr != NULL && (Status = sqlite3_close(Ptr)) != SQLITE_OK)
{
LogErr("Unable to <close database connection> because : %s", sqlite3_errmsg(Ptr));
}
}
/* ----------------------------------------------------------------------------------------
* Copy assignment operator (disabled)
*/
Handle & operator = (const Handle &) = delete;
/* ----------------------------------------------------------------------------------------
* Move assignment operator (disabled)
*/
Handle & operator = (Handle &&) = delete;
};
/* --------------------------------------------------------------------------------------------
* Acquire a strong reference to the resource handle.
*/
void Grab()
{
// If a valid handle exists then grab a reference to it
if (Hnd != nullptr)
{
++(Hnd->Ref);
}
}
/* --------------------------------------------------------------------------------------------
* Release the handle reference and therefore the handle it self if no more references exist.
*/
void Drop()
{
// If a valid handle exists then delete it if this is the last released reference
if (Hnd != nullptr && --(Hnd->Ref) == 0)
{
delete Hnd;
}
// Explicitly make sure the handle is null
Hnd = nullptr;
}
public:
/* --------------------------------------------------------------------------------------------
* The handle instance that manages the SQLite resource.
*/
Handle * Hnd;
/* --------------------------------------------------------------------------------------------
* Default constructor (invalid).
*/
ConnectionHandle();
/* --------------------------------------------------------------------------------------------
* Open a connection to a database using the specified path, flags and vfs.
*/
ConnectionHandle(const SQChar * path, SQInt32 flags, const SQChar * vfs);
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
ConnectionHandle(const ConnectionHandle & o);
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
ConnectionHandle(ConnectionHandle && o);
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~ConnectionHandle();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
ConnectionHandle & operator = (const ConnectionHandle & o);
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
ConnectionHandle & operator = (ConnectionHandle && o);
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean.
*/
operator bool () const
{
return (Hnd != nullptr) && (Hnd->Ptr != NULL);
}
/* --------------------------------------------------------------------------------------------
* Negation operator.
*/
operator ! () const
{
return (Hnd == nullptr) || (Hnd->Ptr == NULL);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to raw SQLite connection handle.
*/
operator sqlite3 * () const
{
return (Hnd != nullptr) ? Hnd->Ptr : NULL;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to integer status code.
*/
operator SQInt32 () const
{
return (Hnd != nullptr) ? Hnd->Status : 0;
}
/* --------------------------------------------------------------------------------------------
* Member of pointer operator.
*/
Handle * operator -> () const
{
return Hnd;
}
/* --------------------------------------------------------------------------------------------
* Indirection operator.
*/
Handle & operator * () const
{
return *Hnd;
}
/* --------------------------------------------------------------------------------------------
* Equality operator.
*/
bool operator == (const ConnectionHandle & o) const
{
return (Hnd == o.Hnd);
}
/* --------------------------------------------------------------------------------------------
* Inequality operator.
*/
bool operator != (const ConnectionHandle & o) const
{
return (Hnd != o.Hnd);
}
/* --------------------------------------------------------------------------------------------
* Reset this handle and release the internal reference.
*/
void Release()
{
Drop();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the number of active references to this handle.
*/
SQUint32 Count() const
{
return (Hnd != nullptr) ? Hnd->Ref : 0;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the error message associated with the value in status.
*/
const SQChar * ErrStr() const
{
return sqlite3_errstr(Hnd->Status);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the error message associated with the connection.
*/
const SQChar * ErrMsg() const
{
return sqlite3_errmsg(Hnd->Ptr);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the error code associated with the connection.
*/
SQInt32 ErrNo() const
{
return sqlite3_errcode(Hnd->Ptr);
}
};
/* ------------------------------------------------------------------------------------------------
* RAII encapsulation of a SQLite Transaction.
*/
class Transaction
{
public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Transaction(const Connection & db);
/* --------------------------------------------------------------------------------------------
* Copy constructor (disabled).
*/
Transaction(const Transaction & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor (disabled).
*/
Transaction(Transaction && o) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Transaction();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled).
*/
Transaction & operator = (const Transaction & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator (disabled).
*/
Transaction & operator = (Transaction && o) = delete;
/* --------------------------------------------------------------------------------------------
* Commit the transaction.
*/
void Commit();
/* --------------------------------------------------------------------------------------------
* See whether the transaction was committed.
*/
bool Commited() const
{
return m_Commited;
}
protected:
// --------------------------------------------------------------------------------------------
private:
/* --------------------------------------------------------------------------------------------
* The SQLite connection associated with this transaction.
*/
ConnectionHandle m_Connection;
/* --------------------------------------------------------------------------------------------
* Whether the changes were committed.
*/
bool m_Commited;
};
/* ------------------------------------------------------------------------------------------------
* Places a "soft" limit on the amount of heap memory that may be allocated by SQLite.
*/
void SetSoftHeapLimit(SQInt32 limit);
/* ------------------------------------------------------------------------------------------------
* Attempts to free N bytes of heap memory by deallocating non-essential memory allocations
* held by the database library.
*/
SQInt32 ReleaseMemory(SQInt32 bytes);
/* ------------------------------------------------------------------------------------------------
* Returns the number of bytes of memory currently outstanding (malloced but not freed).
*/
SLongInt GetMemoryUsage();
/* ------------------------------------------------------------------------------------------------
* Returns the maximum value of used bytes since the high-water mark was last reset.
*/
SLongInt GetMemoryHighwaterMark(bool reset);
} // Namespace:: SQLite
} // Namespace:: SqMod
#endif // _LIBRARY_SQLITE_SHARED_HPP_

File diff suppressed because it is too large Load Diff

View File

@@ -1,436 +0,0 @@
#ifndef _LIBRARY_SQLITE_STATEMENT_HPP_
#define _LIBRARY_SQLITE_STATEMENT_HPP_
// ------------------------------------------------------------------------------------------------
#include "Library/SQLite/Shared.hpp"
// ------------------------------------------------------------------------------------------------
#include <unordered_map>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace SQLite {
/* ------------------------------------------------------------------------------------------------
* Class used to manage a connection to an SQLite statement.
*/
class Statement
{
public:
/* --------------------------------------------------------------------------------------------
* Default constructor (invalid).
*/
Statement();
/* --------------------------------------------------------------------------------------------
* Create a statement on the specified connection and use the specified query.
*/
Statement(const Connection & db, const SQChar * query);
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
Statement(const Statement &) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
Statement(Statement &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Statement();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
Statement & operator = (const Statement &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
Statement & operator = (Statement &&) = delete;
/* --------------------------------------------------------------------------------------------
* Implicit conversion to a raw SQLite statement handle.
*/
operator sqlite3_stmt * () const
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to a raw SQLite connection handle.
*/
operator sqlite3 * () const
{
return static_cast< sqlite3 * >(m_Connection);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean.
*/
operator bool () const
{
return (m_Handle != NULL);
}
/* --------------------------------------------------------------------------------------------
* Negation operator.
*/
operator ! () const
{
return (m_Handle == NULL);
}
/* --------------------------------------------------------------------------------------------
* Equality operator.
*/
bool operator == (const Statement & o) const
{
return (m_Handle == o.m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Inequality operator.
*/
bool operator != (const Statement & o) const
{
return (m_Handle != o.m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Used by the script to compare two instances of this type.
*/
SQInt32 Cmp(const Statement & o) const;
/* --------------------------------------------------------------------------------------------
* Convert this type to a string.
*/
const SQChar * ToString() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the local tag.
*/
const SQChar * GetLocalTag() const;
/* --------------------------------------------------------------------------------------------
* Change the local tag.
*/
void SetLocalTag(const SQChar * tag);
/* --------------------------------------------------------------------------------------------
* Retrieve the local data.
*/
SqObj & GetLocalData();
/* --------------------------------------------------------------------------------------------
* Change the local data.
*/
void SetLocalData(SqObj & data);
/* --------------------------------------------------------------------------------------------
* ...
*/
bool IsValid()
{
return (m_Handle != NULL);
}
/* --------------------------------------------------------------------------------------------
* ...
*/
void Reset();
/* --------------------------------------------------------------------------------------------
* ...
*/
void Clear();
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 GetStatus() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 GetColumns() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * GetQuery() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * GetErrStr() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * GetErrMsg() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
Connection GetConnection() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool GetGood() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool GetDone() const;
/* --------------------------------------------------------------------------------------------
* Return the numeric result code for the most recent failed API call (if any).
*/
SQInt32 GetErrorCode() const;
/* --------------------------------------------------------------------------------------------
* Return the extended numeric result code for the most recent failed API call (if any).
*/
SQInt32 GetExtendedErrorCode() const;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Exec();
/* --------------------------------------------------------------------------------------------
* ...
*/
bool Step();
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBindA(const Array & arr);
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBindT(const Table & tbl);
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBindI(SQInt32 idx, SQInt32 value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBindL(SQInt32 idx, const SLongInt & value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBindV(SQInt32 idx, SQInteger value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBindF(SQInt32 idx, SQFloat value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBindS(SQInt32 idx, const SQChar * value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBindB(SQInt32 idx, bool value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBindN(SQInt32 idx);
/* --------------------------------------------------------------------------------------------
* ...
*/
void NameBindT(const Table & tbl);
/* --------------------------------------------------------------------------------------------
* ...
*/
void NameBindI(const SQChar * name, SQInt32 value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void NameBindL(const SQChar * name, const SLongInt & value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void NameBindV(const SQChar * name, SQInteger value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void NameBindF(const SQChar * name, SQFloat value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void NameBindS(const SQChar * name, const SQChar * value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void NameBindB(const SQChar * name, bool value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void NameBindN(const SQChar * name);
/* --------------------------------------------------------------------------------------------
* ...
*/
void IndexBind(SQInt32 idx, SqObj & value);
/* --------------------------------------------------------------------------------------------
* ...
*/
void NameBind(const SQChar * name, SqObj & value);
/* --------------------------------------------------------------------------------------------
* ...
*/
SqObj FetchColumnIndex(SQInt32 idx);
/* --------------------------------------------------------------------------------------------
* ...
*/
SqObj FetchColumnName(const SQChar * name);
/* --------------------------------------------------------------------------------------------
* ...
*/
Array FetchArray();
/* --------------------------------------------------------------------------------------------
* ...
*/
Table FetchTable();
/* --------------------------------------------------------------------------------------------
* ...
*/
bool CheckIndex(SQInt32 idx) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool IsColumnNull(SQInt32 idx) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 GetColumnIndex(const SQChar * name);
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * GetColumnName(SQInt32 idx);
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * GetColumnOriginName(SQInt32 idx);
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger GetColumnType(SQInt32 idx) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInteger GetColumnBytes(SQInt32 idx) const;
protected:
/* --------------------------------------------------------------------------------------------
* ...
*/
typedef std::unordered_map< String, SQInt32 > ColumnIndex;
/* --------------------------------------------------------------------------------------------
* ...
*/
template < typename... Args > void Status(const SQChar * msg, Args&&... args) const
{
if (m_Status != SQLITE_OK)
{
LogErr(msg, std::forward< Args >(args)...);
}
}
private:
/* --------------------------------------------------------------------------------------------
* The handle to the managed SQLite statement resource.
*/
sqlite3_stmt* m_Handle;
/* --------------------------------------------------------------------------------------------
* The SQLite connection associated with this statement.
*/
ConnectionHandle m_Connection;
/* --------------------------------------------------------------------------------------------
* The query string used to create this statement.
*/
String m_Query;
/* --------------------------------------------------------------------------------------------
* The last status code of this connection handle.
*/
SQInt32 m_Status;
/* --------------------------------------------------------------------------------------------
* The amount of columns available in this statement.
*/
SQInt32 m_Columns;
/* --------------------------------------------------------------------------------------------
* True when a row has been fetched with step.
*/
ColumnIndex m_ColIdx;
/* --------------------------------------------------------------------------------------------
* True when a row has been fetched with step.
*/
bool m_Good;
/* --------------------------------------------------------------------------------------------
* True when the last step had no more rows to fetch.
*/
bool m_Done;
/* --------------------------------------------------------------------------------------------
* The local tag associated with this instance.
*/
SqTag m_Tag;
/* --------------------------------------------------------------------------------------------
* The local data associated with this instance.
*/
SqObj m_Data;
};
} // Namespace:: SQLite
} // Namespace:: SqMod
#endif // _LIBRARY_SQLITE_STATEMENT_HPP_

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