1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Untested implementation of the Sphere type.

This commit is contained in:
Sandu Liviu Catalin 2015-10-29 22:11:47 +02:00
parent 772822415b
commit e708ff8050
2 changed files with 303 additions and 11 deletions

View File

@ -1,28 +1,245 @@
#include "Entity/Sphere.hpp"
#include "Base/Color3.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Register_CSphere(HSQUIRRELVM vm)
{
if (!Register_Reference< CSphere >(vm, _SC("BaseSphere")))
{
LogDbg("Unable to register the base class <BaseSphere> for <CSphere> type");
Color3 CSphere::s_Color3;
Vector3 CSphere::s_Vector3;
return false;
// ------------------------------------------------------------------------------------------------
SQUint32 CSphere::s_ColorR;
SQUint32 CSphere::s_ColorG;
SQUint32 CSphere::s_ColorB;
// ------------------------------------------------------------------------------------------------
bool CSphere::IsStreamedFor(const Reference< CPlayer > & player) const noexcept
{
if (VALID_ENTITY(m_ID) && player)
{
return _Func->IsSphereStreamedForPlayer(m_ID, player);
}
else if (!player)
{
LogWrn(_SC("Attempting to <see if sphere is streamed for player> using an invalid argument: %d"), _SCI32(player));
}
else
{
LogWrn(_SC("Attempting to <see if sphere is streamed for player> using an invalid reference: %d"), m_ID);
}
LogDbg("Beginning registration of <CSphere> type");
return false;
}
// ------------------------------------------------------------------------------------------------
SQInt32 CSphere::GetWorld() const noexcept
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetSphereWorld(m_ID);
}
else
{
LogWrn(_SC("Attempting to <get sphere world> using an invalid reference: %d"), m_ID);
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetWorld(SQInt32 world) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSphereWorld(m_ID, world);
}
else
{
LogWrn(_SC("Attempting to <set sphere world> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
const Color3 & CSphere::GetColor() const noexcept
{
// Clear any previous color
s_Color3.Clear();
// Attempt to retrieve the color
if (VALID_ENTITY(m_ID))
{
_Func->GetSphereColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB);
s_Color3.Set(s_ColorR, s_ColorG, s_ColorB);
}
else
{
LogWrn(_SC("Attempting to <get sphere color> using an invalid reference: %d"), m_ID);
}
// Return the color that could be retrieved
return s_Color3;
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetColor(const Color3 & col) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSphereColor(m_ID, col.r, col.g, col.b);
}
else
{
LogWrn(_SC("Attempting to <set sphere color> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetColorEx(Uint8 r, Uint8 g, Uint8 b) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSphereColor(m_ID, r, g, b);
}
else
{
LogWrn(_SC("Attempting to <set sphere color> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CSphere::GetPosition() const noexcept
{
// Clear any previous position
s_Vector3.Clear();
// Attempt to retrieve the position
if (VALID_ENTITY(m_ID))
{
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
}
else
{
LogWrn(_SC("Attempting to <get sphere position> using an invalid reference: %d"), m_ID);
}
// Return the position that could be retrieved
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetPosition(const Vector3 & pos) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSpherePos(m_ID, pos.x, pos.y, pos.z);
}
else
{
LogWrn(_SC("Attempting to <set sphere position> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSpherePos(m_ID, x, y, z);
}
else
{
LogWrn(_SC("Attempting to <set sphere position> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
SQFloat CSphere::GetRadius() const noexcept
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetSphereRadius(m_ID);
}
else
{
LogWrn(_SC("Attempting to <get sphere radius> using an invalid reference: %d"), m_ID);
}
return 0.0;
}
// ------------------------------------------------------------------------------------------------
void CSphere::SetRadius(SQFloat radius) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetSphereRadius(m_ID, radius);
}
else
{
LogWrn(_SC("Attempting to <set sphere radius> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
Reference< CPlayer > CSphere::GetOwner() const noexcept
{
if (VALID_ENTITY(m_ID))
{
return Reference< CPlayer >(_Func->GetSphereOwner(m_ID));
}
else
{
LogWrn(_SC("Attempting to <get sphere owner> using an invalid reference: %d"), m_ID);
}
return Reference< CPlayer >();
}
// ------------------------------------------------------------------------------------------------
SQInt32 CSphere::GetOwnerID() const noexcept
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetSphereOwner(m_ID);
}
else
{
LogWrn(_SC("Attempting to <get sphere owner id> using an invalid reference: %d"), m_ID);
}
return SQMOD_UNKNOWN;
}
// ================================================================================================
bool Register_CSphere(HSQUIRRELVM vm)
{
// Attempt to register the base reference type before the actual implementation
if (!Register_Reference< CSphere >(vm, _SC("BaseSphere")))
{
LogFtl("Unable to register the base class <BaseSphere> for <CSphere> type");
// Registration failed
return false;
}
// Output debugging information
LogDbg("Beginning registration of <CSphere> type");
// Attempt to register the actual reference that implements all of the entity functionality
Sqrat::RootTable(vm).Bind(_SC("CSphere"), Sqrat::DerivedClass< CSphere, Reference< CSphere > >(vm, _SC("CSphere"))
/* Constructors */
.Ctor()
.Ctor< SQInt32 >()
/* Properties */
.Prop(_SC("world"), &CSphere::GetWorld, &CSphere::SetWorld)
.Prop(_SC("color"), &CSphere::GetColor, &CSphere::SetColor)
.Prop(_SC("position"), &CSphere::GetPosition, &CSphere::SetPosition)
.Prop(_SC("radius"), &CSphere::GetRadius, &CSphere::SetRadius)
.Prop(_SC("owner"), &CSphere::GetOwner)
.Prop(_SC("owner_id"), &CSphere::GetOwnerID)
/* Functions */
.Func(_SC("streamed_for"), &CSphere::IsStreamedFor)
.Func(_SC("set_color"), &CSphere::SetColorEx)
.Func(_SC("set_position"), &CSphere::SetPositionEx)
);
// Output debugging information
LogDbg("Registration of <CSphere> type was successful");
// Registration succeeded
return true;
}

View File

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