2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-01-01 01:25:47 +03:00

Simplification natives members

This commit is contained in:
s1lentq 2017-01-11 20:47:13 +07:00
parent ecdb7e9f96
commit f93e992674
5 changed files with 39 additions and 36 deletions

View File

@ -1031,7 +1031,7 @@ enum CSGameRules_Members
/* /*
* Description: - * Description: -
* Member type: int [100] * Member type: int [100]
* Get params: get_member_game(member); * Get params: get_member_game(member, element);
* Set params: set_member_game(member, value, element); * Set params: set_member_game(member, value, element);
*/ */
m_iMapVotes, m_iMapVotes,
@ -1119,7 +1119,7 @@ enum CSGameRules_Members
/* /*
* Description: - * Description: -
* Member type: int [5] * Member type: int [5]
* Get params: get_member_game(member); * Get params: get_member_game(member, element);
* Set params: set_member_game(member, value, element); * Set params: set_member_game(member, value, element);
*/ */
m_pVIPQueue, m_pVIPQueue,
@ -1232,8 +1232,8 @@ enum CSGameRules_Members
/* /*
* Description: - * Description: -
* Member type: float * Member type: float
* Get params: Float:get_member(index, member); * Get params: Float:get_member_game(member);
* Set params: set_member(index, member, Float:value); * Set params: set_member_game(member, Float:value);
*/ */
m_flEscapeRatio m_flEscapeRatio
}; };

View File

@ -1,9 +1,17 @@
#include "precompiled.h" #include "precompiled.h"
#define CLASS_MEMBERS(cx, mx, postf, pref) ((!(postf & (MAX_REGION_RANGE - 1)) ? regmember::current_cell = 1, true : false) || (postf & (MAX_REGION_RANGE - 1)) == regmember::current_cell++) ? regmember([](member_t* ptr){ decltype(##cx::##pref##mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(##cx, ##pref##mx);ptr->type = getMemberType(f);ptr->name = #postf;}) : regmember(#pref#mx) #if _MSC_VER <= 1800 && __INTEL_COMPILER < 1500
// BUG BUG
// http://connect.microsoft.com/VisualStudio/feedbackdetail/view/797682/c-decltype-of-class-member-access-incompletely-implemented
#define decltypefx(cx, pref, dt, mx) decltype(std::declval<cx>()dt##pref##mx)
#else
#define decltypefx(cx, pref, dt, mx) decltype(cx::pref##mx)
#endif
#define CLASS_MEMBERS(cx, mx, postf, pref) ((!(postf & (MAX_REGION_RANGE - 1)) ? regmember::current_cell = 1, true : false) || (postf & (MAX_REGION_RANGE - 1)) == regmember::current_cell++) ? regmember([](member_t* ptr){ decltypefx(cx, pref, ., mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(##cx, ##pref##mx);ptr->type = getMemberType(f);ptr->name = #postf;}) : regmember(#pref#mx)
#define GM_MEMBERS(mx) CLASS_MEMBERS(CHalfLifeMultiplay, mx, mx,) #define GM_MEMBERS(mx) CLASS_MEMBERS(CHalfLifeMultiplay, mx, mx,)
#define GM_VOICE_MEMBERS(mx) CLASS_MEMBERS(CVoiceGameMgr, mx, mx,) #define GM_VOICE_MEMBERS(mx) CLASS_MEMBERS(CHalfLifeMultiplay, mx, mx, m_VoiceGameMgr.)
#define BASE_MEMBERS(mx) CLASS_MEMBERS(CBaseEntity, mx, mx,) #define BASE_MEMBERS(mx) CLASS_MEMBERS(CBaseEntity, mx, mx,)
#define ANIM_MEMBERS(mx) CLASS_MEMBERS(CBaseAnimating, mx, mx,) #define ANIM_MEMBERS(mx) CLASS_MEMBERS(CBaseAnimating, mx, mx,)
#define MONST_MEMBERS(mx) CLASS_MEMBERS(CBaseMonster, mx, mx,) #define MONST_MEMBERS(mx) CLASS_MEMBERS(CBaseMonster, mx, mx,)

View File

@ -71,7 +71,7 @@ cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params)
cell* arg3 = getAmxAddr(amx, params[arg_3]); cell* arg3 = getAmxAddr(amx, params[arg_3]);
if (isTypeReturnable(member->type)) { if (isTypeReturnable(member->type)) {
dest = (member->type != MEMBER_FLOAT) ? nullptr : arg3; dest = nullptr;
element = *arg3; element = *arg3;
} }
else { else {
@ -123,7 +123,7 @@ cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params)
// native get_member_game(any:_member, any:...); // native get_member_game(any:_member, any:...);
cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params) cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params)
{ {
enum args_e { arg_count, arg_member, arg_3, arg_4 }; enum args_e { arg_count, arg_member, arg_2 };
CHECK_GAMERULES(); CHECK_GAMERULES();
@ -137,16 +137,11 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params)
size_t element; size_t element;
size_t length; size_t length;
if (PARAMS_COUNT == 4) { if (PARAMS_COUNT == 2)
dest = getAmxAddr(amx, params[arg_3]); {
length = *getAmxAddr(amx, params[arg_4]); cell* arg3 = getAmxAddr(amx, params[arg_2]);
element = 0;
}
else if (PARAMS_COUNT == 3) {
cell* arg3 = getAmxAddr(amx, params[arg_3]);
if (isTypeReturnable(member->type)) { if (isTypeReturnable(member->type)) {
dest = (member->type != MEMBER_FLOAT) ? nullptr : arg3; dest = nullptr;
element = *arg3; element = *arg3;
} }
else { else {
@ -154,22 +149,13 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params)
element = 0; element = 0;
} }
length = 0; length = 0;
} } else {
else {
dest = nullptr; dest = nullptr;
element = 0; element = 0;
length = 0; length = 0;
} }
void* data; return get_member(g_pGameRules, member, dest, element, length);
// members of m_VoiceGameMgr
if (params[arg_member] >= m_msgPlayerVoiceMask && params[arg_member] <= m_UpdateInterval) {
data = &CSGameRules()->m_VoiceGameMgr;
} else {
data = g_pGameRules;
}
return get_member(data, member, dest, element, length);
} }
// native set_entvar(const index, const EntVars:var, any:...); // native set_entvar(const index, const EntVars:var, any:...);
@ -227,10 +213,16 @@ cell AMX_NATIVE_CALL get_entvar(AMX *amx, cell *params)
else if (PARAMS_COUNT == 3) { else if (PARAMS_COUNT == 3) {
cell* arg3 = getAmxAddr(amx, params[arg_3]); cell* arg3 = getAmxAddr(amx, params[arg_3]);
if (isTypeReturnable(member->type)) { if (isTypeReturnable(member->type))
dest = (member->type != MEMBER_FLOAT) ? nullptr : arg3; {
if (member->type == MEMBER_FLOAT) {
dest = arg3;
element = 0;
} else {
dest = nullptr;
element = *arg3; element = *arg3;
} }
}
else { else {
dest = arg3; dest = arg3;
element = 0; element = 0;
@ -672,8 +664,11 @@ cell get_member(void* pdata, const member_t *member, cell* dest, size_t element,
// native any:get_member(_index, any:_member, element); // native any:get_member(_index, any:_member, element);
return get_member<bool>(pdata, member->offset, element); return get_member<bool>(pdata, member->offset, element);
case MEMBER_DOUBLE: case MEMBER_DOUBLE:
{
// native any:get_member(_index, any:_member, element); // native any:get_member(_index, any:_member, element);
return get_member<double>(pdata, member->offset, element); auto ret = (float)get_member<double>(pdata, member->offset, element);
return (cell &)ret;
}
case MEMBER_SIGNALS: case MEMBER_SIGNALS:
{ {
enum { _Signal, _State }; enum { _Signal, _State };

View File

@ -93,7 +93,7 @@ rootProject.ext.createMsvcConfig = { boolean release, BinaryKind binKind ->
'WIN32': null, 'WIN32': null,
'_MBCS': null, '_MBCS': null,
'_DEBUG': null, '_DEBUG': null,
'NOMINMAX': null, 'NOMINMAX': null
] ]
), ),