1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-20 19:57:12 +01:00

Update the AABB type to use the new dynamic dispatching system for metamethods.

This commit is contained in:
Sandu Liviu Catalin 2016-08-24 23:16:53 +03:00
parent f88f8b9942
commit 67e8fa650f
2 changed files with 36 additions and 7 deletions

View File

@ -2,6 +2,7 @@
#include "Base/AABB.hpp"
#include "Base/Vector4.hpp"
#include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@ -38,7 +39,8 @@ AABB::AABB(Value sv)
// ------------------------------------------------------------------------------------------------
AABB::AABB(Value xv, Value yv, Value zv)
: min(-xv, -yv, -zv), max(std::fabs(xv), std::fabs(yv), std::fabs(zv))
: min(-std::fabs(xv), -std::fabs(yv), -std::fabs(zv))
, max(std::fabs(xv), std::fabs(yv), std::fabs(zv))
{
/* ... */
}
@ -493,13 +495,14 @@ void Register_AABB(HSQUIRRELVM vm)
// Core Meta-methods
.Func(_SC("_tostring"), &AABB::ToString)
.SquirrelFunc(_SC("_typename"), &AABB::Typename)
.Func(_SC("_cmp"), &AABB::Cmp)
// We cannot set _cmp for c++ classes so we use this instead
.SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< AABB >, SQFloat, SQInteger, bool, std::nullptr_t, AABB >)
// Meta-methods
.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 %)
.SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< AABB >, SQFloat, SQInteger, bool, std::nullptr_t, AABB >)
.SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< AABB >, SQFloat, SQInteger, bool, std::nullptr_t, AABB >)
.SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< AABB >, SQFloat, SQInteger, bool, std::nullptr_t, AABB >)
.SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< AABB >, SQFloat, SQInteger, bool, std::nullptr_t, AABB >)
.SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< AABB >, SQFloat, SQInteger, bool, std::nullptr_t, AABB >)
.Func< AABB (AABB::*)(void) const >(_SC("_unm"), &AABB::operator -)
// Properties
.Prop(_SC("Abs"), &AABB::Abs)

View File

@ -267,6 +267,32 @@ struct AABB
*/
Int32 Cmp(const AABB & b) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(Value s) const
{
return Cmp(AABB(s, s, s, s, s, s));
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(Int32 s) const
{
const Value v = static_cast< Value >(s);
return Cmp(AABB(v, v, v, v, v, v));
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare an instance of this type with a scalar value.
*/
Int32 Cmp(std::nullptr_t) const
{
const Value v = static_cast< Value >(0);
return Cmp(AABB(v, v, v, v, v, v));
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/