1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-15 22:57:12 +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_