2
0
mirror of https://github.com/rehlds/reapi.git synced 2024-12-29 16:15:34 +03:00

Add new native CheckVisibilityInOrigin

This commit is contained in:
s1lentq 2024-01-27 20:56:17 +07:00
parent 9bbebe1741
commit 16afeded60
3 changed files with 91 additions and 12 deletions

View File

@ -165,6 +165,22 @@ native GetBodygroup(const entity, const group);
*/ */
native bool:GetSequenceInfo(const entity, &piFlags, &Float:pflFrameRate, &Float:pflGroundSpeed); native bool:GetSequenceInfo(const entity, &piFlags, &Float:pflFrameRate, &Float:pflGroundSpeed);
/*
* Test visibility of an entity from a given origin using either PVS or PAS
*
* @param entity Entity index
* @param origin Vector representing the origin from which visibility is checked
* @param type Type of visibility check: VisibilityInPVS (Potentially Visible Set) or VisibilityInPAS (Potentially Audible Set)
*
* @return 0 - Not visible
* 1 - Visible, passed by a leafnum
* 2 - Visible, passed by a headnode
*
* @remarks This function checks the visibility of the specified entity from the given origin, using either
* the Potentially Visible Set (PVS) or the Potentially Audible Set (PAS) depending on the provided type
*/
native CheckVisibilityInOrigin(const ent, Float:origin[3], CheckVisibilityType:type = VisibilityInPVS);
/* /*
* Sets the name of the map. * Sets the name of the map.
* *

View File

@ -13,6 +13,15 @@ enum MapNameType
MNT_SET // return the name of the current map MNT_SET // return the name of the current map
}; };
/**
* For native CheckVisibilityInOrigin
*/
enum CheckVisibilityType
{
VisibilityInPVS = 0, // Check in Potentially Visible Set (PVS)
VisibilityInPAS // Check in Potentially Audible Set (PAS)
};
/* /*
* For RH_SV_AddResource hook * For RH_SV_AddResource hook
*/ */

View File

@ -634,6 +634,58 @@ cell AMX_NATIVE_CALL amx_SetMoveDone(AMX *amx, cell *params)
return (cell)EntityCallbackDispatcher().SetMoveDone(amx, pEntity, funcname, pParams, params[arg_len]); return (cell)EntityCallbackDispatcher().SetMoveDone(amx, pEntity, funcname, pParams, params[arg_len]);
} }
enum class CheckVisibilityType {
PVS = 0, // Check in Potentially Visible Set (PVS)
PAS // Check in Potentially Audible Set (PAS)
};
/*
* Test visibility of an entity from a given origin using either PVS or PAS
*
* @param entity Entity index
* @param origin Vector representing the origin from which visibility is checked
* @param type Type of visibility check: VisibilityInPVS (Potentially Visible Set) or VisibilityInPAS (Potentially Audible Set)
*
* @return 0 - Not visible
* 1 - Visible, passed by a leafnum
* 2 - Visible, passed by a headnode
*
* @remarks This function checks the visibility of the specified entity from the given origin, using either
* the Potentially Visible Set (PVS) or the Potentially Audible Set (PAS) depending on the provided type
*
* native CheckVisibilityInOrigin(const ent, Float:origin[3], CheckVisibilityType:type = VisibilityInPVS);
*/
cell AMX_NATIVE_CALL amx_CheckVisibilityInOrigin(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_origin, arg_type };
CHECK_ISENTITY(arg_index);
CBaseEntity *pEntity = getPrivate<CBaseEntity>(params[arg_index]);
if (unlikely(pEntity == nullptr)) {
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__);
return FALSE;
}
CheckVisibilityType type = static_cast<CheckVisibilityType>(params[arg_type]);
if (type < CheckVisibilityType::PVS || type > CheckVisibilityType::PAS) {
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid visibility check type %d. Use either VisibilityInPVS or VisibilityInPAS.", __FUNCTION__, params[arg_type]);
return FALSE;
}
Vector &origin = *(Vector *)getAmxAddr(amx, params[arg_origin]);
unsigned char *pSet = NULL;
switch (type)
{
case CheckVisibilityType::PVS: pSet = ENGINE_SET_PVS(origin); break;
case CheckVisibilityType::PAS: pSet = ENGINE_SET_PAS(origin); break;
default: break;
}
return ENGINE_CHECK_VISIBILITY(pEntity->edict(), pSet);
}
AMX_NATIVE_INFO Natives_Common[] = AMX_NATIVE_INFO Natives_Common[] =
{ {
{ "FClassnameIs", amx_FClassnameIs }, { "FClassnameIs", amx_FClassnameIs },
@ -655,6 +707,8 @@ AMX_NATIVE_INFO Natives_Common[] =
{ "SetBlocked", amx_SetBlocked }, { "SetBlocked", amx_SetBlocked },
{ "SetMoveDone", amx_SetMoveDone }, { "SetMoveDone", amx_SetMoveDone },
{ "CheckVisibilityInOrigin", amx_CheckVisibilityInOrigin },
{ nullptr, nullptr } { nullptr, nullptr }
}; };