Refactor 2 - Duplicate get_member_* for each set of natives for consistency

This commit is contained in:
Arkshine 2015-10-29 11:55:25 +01:00
parent c07b269c94
commit dc6f171f20
2 changed files with 67 additions and 15 deletions

View File

@ -269,6 +269,30 @@ static cell AMX_NATIVE_CALL set_ent_data_string(AMX *amx, cell *params)
}
// native get_ent_data_size(const class[], const member[]);
static cell AMX_NATIVE_CALL get_ent_data_size(AMX *amx, cell *params)
{
TypeDescription data;
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::None, ENTITY);
return data.fieldSize;
}
// native find_ent_data_info(const class[], const member[], &FieldType:type = FIELD_NONE, &arraysize = 0, &bool:unsigned = false);
static cell AMX_NATIVE_CALL find_ent_data_info(AMX *amx, cell *params)
{
TypeDescription data;
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::None, ENTITY);
*MF_GetAmxAddr(amx, params[3]) = static_cast<cell>(data.fieldType);
*MF_GetAmxAddr(amx, params[4]) = ke::Max<int>(0, data.fieldSize);
*MF_GetAmxAddr(amx, params[5]) = data.fieldUnsigned != 0;
return data.fieldOffset;
}
// native any:get_gamerules_int(const class[], const member[], element = 0);
static cell AMX_NATIVE_CALL get_gamerules_int(AMX *amx, cell *params)
@ -451,25 +475,24 @@ static cell AMX_NATIVE_CALL set_gamerules_string(AMX *amx, cell *params)
}
// native get_member_size(const class[], const member[]);
static cell AMX_NATIVE_CALL get_member_size(AMX *amx, cell *params)
// native get_gamerules_size(const class[], const member[]);
static cell AMX_NATIVE_CALL get_gamerules_size(AMX *amx, cell *params)
{
CHECK_GAMERULES();
TypeDescription data;
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::None, ALL);
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::None, GAMERULES);
return data.fieldSize;
}
// native find_member_info(const class[], const member[], &FieldType:type = FIELD_NONE, &arraysize = 0, &bool:unsigned = false);
static cell AMX_NATIVE_CALL find_member_info(AMX *amx, cell *params)
// native find_gamerules_info(const class[], const member[], &FieldType:type = FIELD_NONE, &arraysize = 0, &bool:unsigned = false);
static cell AMX_NATIVE_CALL find_gamerules_info(AMX *amx, cell *params)
{
CHECK_GAMERULES();
TypeDescription data;
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::None, ALL);
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::None, GAMERULES);
*MF_GetAmxAddr(amx, params[3]) = static_cast<cell>(data.fieldType);
*MF_GetAmxAddr(amx, params[4]) = ke::Max<int>(0, data.fieldSize);
@ -491,6 +514,8 @@ AMX_NATIVE_INFO pdata_gc_natives[] =
{ "set_ent_data_entity" , set_ent_data_entity },
{ "get_ent_data_string" , get_ent_data_string },
{ "set_ent_data_string" , set_ent_data_string },
{ "get_ent_data_size" , get_ent_data_size },
{ "find_ent_data_info" , find_ent_data_info },
{ "get_gamerules_int" , get_gamerules_int },
{ "set_gamerules_int" , set_gamerules_int },
@ -502,9 +527,8 @@ AMX_NATIVE_INFO pdata_gc_natives[] =
{ "set_gamerules_entity", set_gamerules_entity },
{ "get_gamerules_string", get_gamerules_string },
{ "set_gamerules_string", set_gamerules_string },
{ "get_gamerules_size" , get_gamerules_size },
{ "find_gamerules_info" , find_gamerules_info },
{ "get_member_size" , get_member_size },
{ "find_member_info" , find_member_info },
{ nullptr , nullptr }
{ nullptr , nullptr }
};

View File

@ -808,6 +808,34 @@ native get_ent_data_string(entity, const class[], const member[], value[], maxle
*/
native set_ent_data_string(entity, const class[], const member[], const value[], element = 0);
/**
* Retrieves the size of array of n entity class member.
*
* @param class Class name
* @param member Member name
*
* @return Size of array (in elements), otherwise 1 if member is not an array
* @error If either class or member is empty, no offset is found or an invalid
* offset is retrieved, an error will be thrown.
*/
native get_ent_data_size(const class[], const member[]);
/**
* Finds a offset based off an entity class and member name.
*
* @param class Class name
* @param member Member name
* @param type Optional variable to store member type in (FIELD_* constants)
* @param arraysize Optional variable to store array size in, if member is an array
* @param unsigned Optional variable to store whether member is unsigned (short and char types only)
*
* @return Class member offset
* @error If either class or member is empty, no offset is found or an invalid
* offset is retrieved, an error will be thrown.
*/
native find_ent_data_info(const class[], const member[], &FieldType:type = FIELD_NONE, &arraysize = 0, &bool:unsigned = false);
/**
* Retrieves an integer value from the gamerules object based off a class
* and member name.
@ -986,7 +1014,7 @@ native get_gamerules_string(const class[], const member[], value[], maxlen, elem
native set_gamerules_string(const class[], const member[], const value[], element = 0);
/**
* Retrieves the size of array of a class member.
* Retrieves the size of array of a gamerules class member.
*
* @param class Class name
* @param member Member name
@ -995,10 +1023,10 @@ native set_gamerules_string(const class[], const member[], const value[], elemen
* @error If either class or member is empty, no offset is found or an invalid
* offset is retrieved, an error will be thrown.
*/
native get_member_size(const class[], const member[]);
native get_gamerules_size(const class[], const member[]);
/**
* Finds an offset based off a class and member name.
* Finds a gamerules offset based off a class and member name.
*
* @param class Class name
* @param member Member name
@ -1010,7 +1038,7 @@ native get_member_size(const class[], const member[]);
* @error If either class or member is empty, no offset is found or an invalid
* offset is retrieved, an error will be thrown.
*/
native find_member_info(const class[], const member[], &FieldType:type = FIELD_NONE, &arraysize = 0, &bool:unsigned = false);
native find_gamerules_info(const class[], const member[], &FieldType:type = FIELD_NONE, &arraysize = 0, &bool:unsigned = false);
/**
* Returns the data field base type based off a specific field type.