1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-18 19:47:15 +01:00

Documented the Automobile type and made minor fixes.

This commit is contained in:
Sandu Liviu Catalin 2015-10-29 22:58:13 +02:00
parent 031f82b9df
commit 6cecf4ad77
2 changed files with 244 additions and 80 deletions

View File

@ -13,27 +13,29 @@ const CAutomobile CAutomobile::NIL;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
CAutomobile::CAutomobile() noexcept CAutomobile::CAutomobile() noexcept
: m_ID(SQMOD_UNKNOWN), m_Name() : m_ID(SQMOD_UNKNOWN)
{ {
} }
CAutomobile::CAutomobile(SQInt32 id) noexcept CAutomobile::CAutomobile(SQInt32 id) noexcept
: m_ID(VALID_ENTITYGETEX(id, Max)), m_Name(GetAutomobileName(id)) : m_ID(VALID_ENTITYGETEX(id, Max))
{ {
} }
CAutomobile::CAutomobile(const SQChar * name, SQInt32 id) noexcept CAutomobile::CAutomobile(const SQChar * name, SQInt32 id) noexcept
: CAutomobile(IsAutomobileValid(GetAutomobileID(name)) ? GetAutomobileID(name) : id) : m_ID(GetAutomobileID(name))
{ {
if (VALID_ENTITYEX(m_ID, Max))
{
m_ID = id;
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
CAutomobile::CAutomobile(const CAutomobile & a) noexcept CAutomobile::CAutomobile(const CAutomobile & a) noexcept
: m_ID(a.m_ID) : m_ID(a.m_ID)
, m_Name(a.m_Name)
, m_Tag(a.m_Tag) , m_Tag(a.m_Tag)
, m_Data(a.m_Data) , m_Data(a.m_Data)
{ {
@ -42,7 +44,6 @@ CAutomobile::CAutomobile(const CAutomobile & a) noexcept
CAutomobile::CAutomobile(CAutomobile && a) noexcept CAutomobile::CAutomobile(CAutomobile && a) noexcept
: m_ID(a.m_ID) : m_ID(a.m_ID)
, m_Name(a.m_Name)
, m_Tag(a.m_Tag) , m_Tag(a.m_Tag)
, m_Data(a.m_Data) , m_Data(a.m_Data)
{ {
@ -59,7 +60,6 @@ CAutomobile::~CAutomobile()
CAutomobile & CAutomobile::operator = (const CAutomobile & a) noexcept CAutomobile & CAutomobile::operator = (const CAutomobile & a) noexcept
{ {
m_ID = a.m_ID; m_ID = a.m_ID;
m_Name = a.m_Name;
m_Tag = a.m_Tag; m_Tag = a.m_Tag;
m_Data = a.m_Data; m_Data = a.m_Data;
@ -69,7 +69,6 @@ CAutomobile & CAutomobile::operator = (const CAutomobile & a) noexcept
CAutomobile & CAutomobile::operator = (CAutomobile && a) noexcept CAutomobile & CAutomobile::operator = (CAutomobile && a) noexcept
{ {
m_ID = a.m_ID; m_ID = a.m_ID;
m_Name = a.m_Name;
m_Tag = a.m_Tag; m_Tag = a.m_Tag;
m_Data = a.m_Data; m_Data = a.m_Data;
@ -79,11 +78,7 @@ CAutomobile & CAutomobile::operator = (CAutomobile && a) noexcept
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
CAutomobile & CAutomobile::operator = (SQInt32 id) noexcept CAutomobile & CAutomobile::operator = (SQInt32 id) noexcept
{ {
if (m_ID != id) m_ID = VALID_ENTITYGETEX(id, Max);
{
m_Name = GetAutomobileName(id);
m_ID = id;
}
return *this; return *this;
} }
@ -122,13 +117,24 @@ bool CAutomobile::operator >= (const CAutomobile & a) const noexcept
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQInteger CAutomobile::Cmp(const CAutomobile & a) const noexcept SQInteger CAutomobile::Cmp(const CAutomobile & a) const noexcept
{ {
return m_ID == a.m_ID ? 0 : (m_ID > a.m_ID ? 1 : -1); if (m_ID == a.m_ID)
{
return 0;
}
else if (m_ID > a.m_ID)
{
return 1;
}
else
{
return -1;
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const SQChar * CAutomobile::ToString() const noexcept const SQChar * CAutomobile::ToString() const noexcept
{ {
return m_Name.c_str(); return GetAutomobileName(m_ID);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -139,21 +145,14 @@ SQInteger CAutomobile::GetID() const noexcept
void CAutomobile::SetID(SQInt32 id) noexcept void CAutomobile::SetID(SQInt32 id) noexcept
{ {
if (m_ID != id) m_ID = VALID_ENTITYGETEX(id, Max);
{
m_Name = GetAutomobileName(id);
m_ID = id;
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
CAutomobile & CAutomobile::SetnGet(SQInt32 id) noexcept CAutomobile & CAutomobile::SetnGet(SQInt32 id) noexcept
{ {
if (m_ID != id) m_ID = VALID_ENTITYGETEX(id, Max);
{
m_Name = GetAutomobileName(id);
m_ID = id;
}
return *this; return *this;
} }
@ -204,37 +203,44 @@ void CAutomobile::SetLocalData(SqObj & data) noexcept
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool CAutomobile::IsValid() const noexcept bool CAutomobile::IsValid() const noexcept
{ {
return (VALID_ENTITYEX(m_ID, SQMOD_VEHICLEID_CAP)); return (VALID_ENTITYEX(m_ID, Max));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const SQChar * CAutomobile::GetName() const noexcept const SQChar * CAutomobile::GetName() const noexcept
{ {
return m_Name.c_str(); return GetAutomobileName(m_ID);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ void CAutomobile::SetName(const SQChar * name) noexcept
{
m_ID = GetAutomobileID(name);
m_ID = VALID_ENTITYGETEX(m_ID, Max);
}
// ------------------------------------------------------------------------------------------------
Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle,
SQInt32 header, SqObj & payload) const noexcept SQInt32 header, SqObj & payload) const noexcept
{ {
return _Core->CreateVehicle(*this, world, pos, angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); return _Core->CreateVehicle(*this, world, pos, angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload);
} }
Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle,
SQInt32 primary, SQInt32 secondary, SQInt32 header, \ SQInt32 primary, SQInt32 secondary, SQInt32 header,
SqObj & payload) const noexcept SqObj & payload) const noexcept
{ {
return _Core->CreateVehicle(*this, world, pos, angle, primary, secondary, header, payload); return _Core->CreateVehicle(*this, world, pos, angle, primary, secondary, header, payload);
} }
Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle,
SQInt32 header, SqObj & payload) const noexcept SQInt32 header, SqObj & payload) const noexcept
{ {
return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload);
} }
Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle,
SQInt32 primary, SQInt32 secondary, SQInt32 header, \ SQInt32 primary, SQInt32 secondary, SQInt32 header,
SqObj & payload) const noexcept SqObj & payload) const noexcept
{ {
return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, primary, secondary, header, payload); return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, primary, secondary, header, payload);
@ -247,31 +253,32 @@ bool Register_CAutomobile(HSQUIRRELVM vm)
LogDbg("Beginning registration of <CAutomobile> type"); LogDbg("Beginning registration of <CAutomobile> type");
// Attempt to register the specified type // Attempt to register the specified type
Sqrat::RootTable(vm).Bind(_SC("CAutomobile"), Sqrat::Class< CAutomobile >(vm, _SC("CAutomobile")) Sqrat::RootTable(vm).Bind(_SC("CAutomobile"), Sqrat::Class< CAutomobile >(vm, _SC("CAutomobile"))
/* Constructors */
.Ctor() .Ctor()
.Ctor< SQInt32 >() .Ctor< SQInt32 >()
.Ctor< const SQChar *, SQInt32 >() .Ctor< const SQChar *, SQInt32 >()
/* Metamethods */
.Func(_SC("_cmp"), &CAutomobile::Cmp) .Func(_SC("_cmp"), &CAutomobile::Cmp)
.Func(_SC("_tostring"), &CAutomobile::ToString) .Func(_SC("_tostring"), &CAutomobile::ToString)
/* Properties */
.Prop(_SC("id"), &CAutomobile::GetID, &CAutomobile::SetID) .Prop(_SC("id"), &CAutomobile::GetID, &CAutomobile::SetID)
.Prop(_SC("gtag"), &CAutomobile::GetGlobalTag, &CAutomobile::SetGlobalTag) .Prop(_SC("gtag"), &CAutomobile::GetGlobalTag, &CAutomobile::SetGlobalTag)
.Prop(_SC("gdata"), &CAutomobile::GetGlobalData, &CAutomobile::SetGlobalData) .Prop(_SC("gdata"), &CAutomobile::GetGlobalData, &CAutomobile::SetGlobalData)
.Prop(_SC("ltag"), &CAutomobile::GetLocalTag, &CAutomobile::SetLocalTag) .Prop(_SC("ltag"), &CAutomobile::GetLocalTag, &CAutomobile::SetLocalTag)
.Prop(_SC("ldata"), &CAutomobile::GetLocalData, &CAutomobile::SetLocalData) .Prop(_SC("ldata"), &CAutomobile::GetLocalData, &CAutomobile::SetLocalData)
.Prop(_SC("valid"), &CAutomobile::IsValid) .Prop(_SC("valid"), &CAutomobile::IsValid)
.Prop(_SC("name"), &CAutomobile::GetName) .Prop(_SC("name"), &CAutomobile::GetName, &CAutomobile::SetName)
/* Functions */
.Func(_SC("setng"), &CAutomobile::SetnGet) .Func(_SC("setng"), &CAutomobile::SetnGet)
/* Overloads */
.Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, SqObj &) const > \ .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, SqObj &) const >
(_SC("vehicle"), &CAutomobile::Create) (_SC("vehicle"), &CAutomobile::Create)
.Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, SQInt32, SQInt32, SqObj &) const > \ .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, SQInt32, SQInt32, SqObj &) const >
(_SC("vehicle"), &CAutomobile::Create) (_SC("vehicle"), &CAutomobile::Create)
.Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, SqObj &) const > \ .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, SqObj &) const >
(_SC("vehicle"), &CAutomobile::Create) (_SC("vehicle"), &CAutomobile::Create)
.Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, SQInt32, SQInt32, SqObj &) const > \ .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, SQInt32, SQInt32, SqObj &) const >
(_SC("vehicle"), &CAutomobile::Create) (_SC("vehicle"), &CAutomobile::Create)
); );
// Output debugging information // Output debugging information
LogDbg("Registration of <CAutomobile> type was successful"); LogDbg("Registration of <CAutomobile> type was successful");

View File

@ -8,82 +8,239 @@
namespace SqMod { namespace SqMod {
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* ... * Class responsible for managing and interacting with vehicle models.
*/ */
class CAutomobile : public IdentifierStorage< CAutomobile, SQMOD_VEHICLEID_CAP > class CAutomobile : public IdentifierStorage< CAutomobile, SQMOD_VEHICLEID_CAP >
{ {
public: public:
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Helper member for times when a null reference to an instance of this type is needed.
*/
static const CAutomobile NIL; static const CAutomobile NIL;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
CAutomobile() noexcept; CAutomobile() noexcept;
/* --------------------------------------------------------------------------------------------
* Construct an instance of this type and reference the model specified.
*/
CAutomobile(SQInt32 id) noexcept; CAutomobile(SQInt32 id) noexcept;
/* --------------------------------------------------------------------------------------------
* Construct an instance of this type and reference the model extracted from the specified name.
*/
CAutomobile(const SQChar * name, SQInt32 id) noexcept; CAutomobile(const SQChar * name, SQInt32 id) noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
CAutomobile(const CAutomobile & a) noexcept; CAutomobile(const CAutomobile & a) noexcept;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
CAutomobile(CAutomobile && a) noexcept; CAutomobile(CAutomobile && a) noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~CAutomobile(); ~CAutomobile();
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
CAutomobile & operator = (const CAutomobile & a) noexcept; CAutomobile & operator = (const CAutomobile & a) noexcept;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
CAutomobile & operator = (CAutomobile && a) noexcept; CAutomobile & operator = (CAutomobile && a) noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Model identifier assignment operator.
*/
CAutomobile & operator = (SQInt32 id) noexcept; CAutomobile & operator = (SQInt32 id) noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Equality comparison operator.
*/
bool operator == (const CAutomobile & a) const noexcept; bool operator == (const CAutomobile & a) const noexcept;
/* --------------------------------------------------------------------------------------------
* Inequality comparison operator.
*/
bool operator != (const CAutomobile & a) const noexcept; bool operator != (const CAutomobile & a) const noexcept;
/* --------------------------------------------------------------------------------------------
* Less than comparison operator.
*/
bool operator < (const CAutomobile & a) const noexcept; bool operator < (const CAutomobile & a) const noexcept;
/* --------------------------------------------------------------------------------------------
* Greater than comparison operator.
*/
bool operator > (const CAutomobile & a) const noexcept; bool operator > (const CAutomobile & a) const noexcept;
/* --------------------------------------------------------------------------------------------
* Less than or equal comparison operator.
*/
bool operator <= (const CAutomobile & a) const noexcept; bool operator <= (const CAutomobile & a) const noexcept;
/* --------------------------------------------------------------------------------------------
* Greater than or equal comparison operator.
*/
bool operator >= (const CAutomobile & a) const noexcept; bool operator >= (const CAutomobile & a) const noexcept;
// --------------------------------------------------------------------------------------------
operator SQInt32 () const noexcept { return m_ID; } /* --------------------------------------------------------------------------------------------
operator bool () const noexcept { return IsAutomobileValid(m_ID); } * Implicit conversion to model identifier.
// -------------------------------------------------------------------------------------------- */
bool operator ! () const noexcept { return !IsAutomobileValid(m_ID); } operator SQInt32 () const noexcept
// -------------------------------------------------------------------------------------------- {
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean.
*/
operator bool () const noexcept
{
return IsAutomobileValid(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Negation operator.
*/
bool operator ! () const noexcept
{
return !IsAutomobileValid(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Used by the script to compare two instances of this type.
*/
SQInteger Cmp(const CAutomobile & a) const noexcept; SQInteger Cmp(const CAutomobile & a) const noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Convert this type to a string.
*/
const SQChar * ToString() const noexcept; const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier referenced by this instance.
*/
SQInteger GetID() const noexcept; SQInteger GetID() const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the identifier referenced by this instance.
*/
void SetID(SQInt32 id) noexcept; void SetID(SQInt32 id) noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Set the identifier that this insance should reference and
* get a reference to the instance to chain operations.
*/
CAutomobile & SetnGet(SQInt32 id) noexcept; CAutomobile & SetnGet(SQInt32 id) noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the global tag.
*/
const SQChar * GetGlobalTag() const noexcept; const SQChar * GetGlobalTag() const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the global tag.
*/
void SetGlobalTag(const SQChar * tag) const noexcept; void SetGlobalTag(const SQChar * tag) const noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the global data.
*/
SqObj & GetGlobalData() const noexcept; SqObj & GetGlobalData() const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the global data.
*/
void SetGlobalData(SqObj & data) const noexcept; void SetGlobalData(SqObj & data) const noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the local tag.
*/
const SQChar * GetLocalTag() const noexcept; const SQChar * GetLocalTag() const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the local tag.
*/
void SetLocalTag(const SQChar * tag) noexcept; void SetLocalTag(const SQChar * tag) noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the local data.
*/
SqObj & GetLocalData() noexcept; SqObj & GetLocalData() noexcept;
/* --------------------------------------------------------------------------------------------
* Change the local data.
*/
void SetLocalData(SqObj & data) noexcept; void SetLocalData(SqObj & data) noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* See whether the referenced model identifier is valid.
*/
bool IsValid() const noexcept; bool IsValid() const noexcept;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the name of the referenced model.
*/
const SQChar * GetName() const noexcept; const SQChar * GetName() const noexcept;
// --------------------------------------------------------------------------------------------
Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ /* --------------------------------------------------------------------------------------------
* Change the identifier of the referenced model.
*/
void SetName(const SQChar * name) noexcept;
/* --------------------------------------------------------------------------------------------
* Create a vehicle instance using the referenced model.
*/
Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle,
SQInt32 header, SqObj & payload) const noexcept; SQInt32 header, SqObj & payload) const noexcept;
Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \
SQInt32 primary, SQInt32 secondary, SQInt32 header, \ /* --------------------------------------------------------------------------------------------
* Create a vehicle instance using the referenced model.
*/
Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle,
SQInt32 primary, SQInt32 secondary, SQInt32 header,
SqObj & payload) const noexcept; SqObj & payload) const noexcept;
Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \
/* --------------------------------------------------------------------------------------------
* Create a vehicle instance using the referenced model.
*/
Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle,
SQInt32 header, SqObj & payload) const noexcept; SQInt32 header, SqObj & payload) const noexcept;
Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \
SQInt32 primary, SQInt32 secondary, SQInt32 header, \ /* --------------------------------------------------------------------------------------------
* Create a vehicle instance using the referenced model.
*/
Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle,
SQInt32 primary, SQInt32 secondary, SQInt32 header,
SqObj & payload) const noexcept; SqObj & payload) const noexcept;
private: private:
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* The identifier of the referenced model.
*/
SQInt32 m_ID; SQInt32 m_ID;
// --------------------------------------------------------------------------------------------
String m_Name; /* --------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------- * The local tag associated with this instance.
*/
SqTag m_Tag; SqTag m_Tag;
/* --------------------------------------------------------------------------------------------
* The local data associated with this instance.
*/
SqObj m_Data; SqObj m_Data;
}; };