From 069b0ede183b4337e450c949a7af5761f47a9f08 Mon Sep 17 00:00:00 2001 From: SlidyBat <25954912+SlidyBat@users.noreply.github.com> Date: Mon, 22 Jan 2018 08:36:19 +1100 Subject: [PATCH 1/5] Add TR_EnumerateEntities and TR_ClipRayToEntity natives --- extensions/sdktools/trnatives.cpp | 111 ++++++++++++++++++++++++++++- plugins/include/sdktools_trace.inc | 51 ++++++++++++- 2 files changed, 158 insertions(+), 4 deletions(-) diff --git a/extensions/sdktools/trnatives.cpp b/extensions/sdktools/trnatives.cpp index fc9dcfb9cd..8e1c2ae453 100644 --- a/extensions/sdktools/trnatives.cpp +++ b/extensions/sdktools/trnatives.cpp @@ -74,6 +74,28 @@ class CSMTraceFilter : public CTraceFilter cell_t m_Data; }; +class CSMTraceEnum : public IEntityEnumerator +{ +public: + bool EnumEntity(IHandleEntity *pEntity) override + { + cell_t res = 1; + m_pFunc->PushCell(gamehelpers->EntityToBCompatRef(reinterpret_cast(pEntity))); + m_pFunc->PushCell(m_Data); + m_pFunc->Execute(&res); + + return (res) ? true : false; + } + void SetFunctionPtr(IPluginFunction *pFunc, cell_t data) + { + m_pFunc = pFunc; + m_Data = data; + } +private: + IPluginFunction *m_pFunc; + cell_t m_Data; +}; + /* Used for the global trace version */ Ray_t g_Ray; sm_trace_t g_Trace; @@ -83,7 +105,8 @@ Vector g_HullMins; Vector g_HullMaxs; QAngle g_DirAngles; CTraceFilterHitAll g_HitAllFilter; -CSMTraceFilter g_SMTraceFilter; +CSMTraceFilter g_SMTraceFilter; +CSMTraceEnum g_SMTraceEnum; enum { @@ -145,6 +168,86 @@ static cell_t smn_TRTraceHull(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t smn_TREnumerateEntities(IPluginContext *pContext, const cell_t *params) +{ + IPluginFunction *pFunc = pContext->GetFunctionById(params[5]); + if (!pFunc) + { + return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); + } + + cell_t data; + if (params[0] >= 6) + { + data = params[6]; + } + else + { + data = 0; + } + + g_SMTraceEnum.SetFunctionPtr(pFunc, data); + + cell_t *startaddr, *endaddr; + pContext->LocalToPhysAddr(params[1], &startaddr); + pContext->LocalToPhysAddr(params[2], &endaddr); + + g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); + + switch (params[4]) + { + case RayType_EndPoint: + { + g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + break; + } + case RayType_Infinite: + { + g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + AngleVectors(g_DirAngles, &g_EndVec); + + /* Make it unitary and get the ending point */ + g_EndVec.NormalizeInPlace(); + g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; + break; + } + } + + g_Ray.Init(g_StartVec, g_EndVec); + + bool triggers = (params[3]) ? true : false; + enginetrace->EnumerateEntities(g_Ray, triggers, &g_SMTraceEnum); + + return 1; +} + +static cell_t smn_TRClipRayToEntity(IPluginContext *pContext, const cell_t *params) +{ + sm_trace_t *tr; + HandleError err; + HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); + + if (params[3] == BAD_HANDLE) + { + tr = &g_Trace; + } + else if ((err = handlesys->ReadHandle(params[3], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) + { + return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[3], err); + } + + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); + if (!pEdict || pEdict->IsFree()) + { + return pContext->ThrowNativeError("Entity %d is invalid", params[2]); + } + + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + enginetrace->ClipRayToEntity(g_Ray, params[1], pEnt, tr); + + return 1; +} + static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *params) { cell_t *startaddr, *endaddr; @@ -603,14 +706,16 @@ static cell_t smn_TRPointOutsideWorld(IPluginContext *pContext, const cell_t *pa sp_nativeinfo_t g_TRNatives[] = { {"TR_TraceRay", smn_TRTraceRay}, - {"TR_TraceHull", smn_TRTraceHull}, + {"TR_TraceHull", smn_TRTraceHull}, + {"TR_EnumerateEntities", smn_TREnumerateEntities}, {"TR_TraceRayEx", smn_TRTraceRayEx}, {"TR_TraceHullEx", smn_TRTraceHullEx}, {"TR_GetFraction", smn_TRGetFraction}, {"TR_GetEndPosition", smn_TRGetEndPosition}, {"TR_GetEntityIndex", smn_TRGetEntityIndex}, {"TR_DidHit", smn_TRDidHit}, - {"TR_GetHitGroup", smn_TRGetHitGroup}, + {"TR_GetHitGroup", smn_TRGetHitGroup}, + {"TR_ClipRayToEntity", smn_TRClipRayToEntity}, {"TR_GetPointContents", smn_TRGetPointContents}, {"TR_GetPointContentsEnt", smn_TRGetPointContentsEnt}, {"TR_TraceRayFilter", smn_TRTraceRayFilter}, diff --git a/plugins/include/sdktools_trace.inc b/plugins/include/sdktools_trace.inc index 3b9d5ee121..ec4a1a7201 100644 --- a/plugins/include/sdktools_trace.inc +++ b/plugins/include/sdktools_trace.inc @@ -132,6 +132,26 @@ typeset TraceEntityFilter function bool (int entity, int contentsMask, any data); }; +typeset TraceEntityEnumerator +{ + /** + * Called on entity enumerating. + * + * @param entity Entity index. + * @return True to continue enumerating entities, otherwise false. + */ + function bool (int entity); + + /** + * Called on entity enumerating. + * + * @param entity Entity index. + * @param data Data value, if used. + * @return True to continue enumerating entities, otherwise false. + */ + function bool (int entity, any data); +} + /** * Get the contents mask and the entity index at the given position. * @@ -179,6 +199,25 @@ native void TR_TraceHull(const float pos[3], const float maxs[3], int flags); +/** + * Enumerates over all entities along a ray + * + * @param pos Starting position of the ray. + * @param vec Depending on RayType, it will be used as the ending + * point, or the direction angle. + * @param triggers If triggers == true, it enumerates all triggers along a ray + * @param rtype Method to calculate the ray direction. + * @param enumerator Function to use as enumerator. For each entity found along ray, this entity is called. + * @param data Arbitrary data value to pass through to the filter + * function. + */ +native void TR_EnumerateEntities(const float pos[3], + const float vec[3], + bool triggers, + RayType rtype, + TraceEntityEnumerator enumerator, + any data=0); + /** * Starts up a new trace ray using a global trace result and a customized * trace ray filter. @@ -226,7 +265,7 @@ native void TR_TraceHullFilter(const float pos[3], int flags, TraceEntityFilter filter, any data=0); - + /** * Starts up a new trace ray using a new trace result. * @@ -359,6 +398,16 @@ native int TR_GetHitGroup(Handle hndl=INVALID_HANDLE); */ native void TR_GetPlaneNormal(Handle hndl, float normal[3]); +/** + * Traces a ray against a particular edict. + * + * @param flags Trace flags. + * @param entity Entity to trace against + * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result. + * @error Invalid Handle + */ +native void TR_ClipRayToEntity(int flags, int entity, Handle hndl=INVALID_HANDLE); + /** * Tests a point to see if it's outside any playable area * From 94559163e2e7c6f60808f366dff8513ca4a0b5aa Mon Sep 17 00:00:00 2001 From: SlidyBat <25954912+SlidyBat@users.noreply.github.com> Date: Mon, 12 Feb 2018 09:35:17 +1100 Subject: [PATCH 2/5] Split ClipRayToEntity into 2 groups of natives --- extensions/sdktools/trnatives.cpp | 144 ++++++++++++++++++++++++++--- plugins/include/sdktools_trace.inc | 60 ++++++++++-- 2 files changed, 179 insertions(+), 25 deletions(-) diff --git a/extensions/sdktools/trnatives.cpp b/extensions/sdktools/trnatives.cpp index 8e1c2ae453..54f10d56c6 100644 --- a/extensions/sdktools/trnatives.cpp +++ b/extensions/sdktools/trnatives.cpp @@ -196,7 +196,7 @@ static cell_t smn_TREnumerateEntities(IPluginContext *pContext, const cell_t *pa switch (params[4]) { - case RayType_EndPoint: + case RayType_EndPoint: { g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); break; @@ -223,27 +223,57 @@ static cell_t smn_TREnumerateEntities(IPluginContext *pContext, const cell_t *pa static cell_t smn_TRClipRayToEntity(IPluginContext *pContext, const cell_t *params) { - sm_trace_t *tr; - HandleError err; - HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); - - if (params[3] == BAD_HANDLE) - { - tr = &g_Trace; - } - else if ((err = handlesys->ReadHandle(params[3], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) - { - return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[3], err); + cell_t *startaddr; + pContext->LocalToPhysAddr(params[1], &startaddr); + cell_t *endaddr; + pContext->LocalToPhysAddr(params[2], &endaddr); + + g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); + + switch (params[4]) + { + case RayType_EndPoint: + { + g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + break; + } + case RayType_Infinite: + { + g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + AngleVectors(g_DirAngles, &g_EndVec); + + /* Make it unitary and get the ending point */ + g_EndVec.NormalizeInPlace(); + g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; + break; + } } - edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[5])); if (!pEdict || pEdict->IsFree()) { - return pContext->ThrowNativeError("Entity %d is invalid", params[2]); + return pContext->ThrowNativeError("Entity %d is invalid", params[5]); } IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); - enginetrace->ClipRayToEntity(g_Ray, params[1], pEnt, tr); + g_Ray.Init(g_StartVec, g_EndVec); + enginetrace->ClipRayToEntity(g_Ray, params[3], pEnt, &g_Trace); + g_Trace.UpdateEntRef(); + + return 1; +} + +static cell_t smn_TRClipCurrRayToEntity( IPluginContext *pContext, const cell_t *params ) +{ + edict_t *pEdict = PEntityOfEntIndex( gamehelpers->ReferenceToIndex( params[2] ) ); + if( !pEdict || pEdict->IsFree() ) + { + return pContext->ThrowNativeError( "Entity %d is invalid", params[2] ); + } + + IHandleEntity *pEnt = reinterpret_cast( pEdict->GetUnknown()->GetBaseEntity() ); + enginetrace->ClipRayToEntity( g_Ray, params[1], pEnt, &g_Trace ); + g_Trace.UpdateEntRef(); return 1; } @@ -414,6 +444,87 @@ static cell_t smn_TRTraceHullEx(IPluginContext *pContext, const cell_t *params) return hndl; } +static cell_t smn_TRClipRayToEntityEx( IPluginContext *pContext, const cell_t *params ) +{ + cell_t *startaddr; + pContext->LocalToPhysAddr(params[1], &startaddr); + cell_t *endaddr; + pContext->LocalToPhysAddr(params[2], &endaddr); + + Vector StartVec, EndVec; + + StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); + + switch (params[4]) + { + case RayType_EndPoint: + { + EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + break; + } + case RayType_Infinite: + { + QAngle DirAngles; + DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + AngleVectors(DirAngles, &EndVec); + + /* Make it unitary and get the ending point */ + EndVec.NormalizeInPlace(); + EndVec = StartVec + EndVec * MAX_TRACE_LENGTH; + break; + } + } + + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[5])); + if (!pEdict || pEdict->IsFree()) + { + return pContext->ThrowNativeError("Entity %d is invalid", params[5]); + } + + Ray_t ray; + sm_trace_t *tr = new sm_trace_t; + + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + ray.Init(StartVec, EndVec); + enginetrace->ClipRayToEntity(ray, params[3], pEnt, tr); + tr->UpdateEntRef(); + + HandleError herr; + Handle_t hndl; + if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) + { + delete tr; + return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); + } + + return hndl; +} + +static cell_t smn_TRClipCurrRayToEntityEx( IPluginContext *pContext, const cell_t *params ) +{ + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); + if (!pEdict || pEdict->IsFree()) + { + return pContext->ThrowNativeError("Entity %d is invalid", params[2]); + } + + sm_trace_t *tr = new sm_trace_t; + + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + enginetrace->ClipRayToEntity(g_Ray, params[1], pEnt, tr); + tr->UpdateEntRef(); + + HandleError herr; + Handle_t hndl; + if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) + { + delete tr; + return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); + } + + return hndl; +} + static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *params) { IPluginFunction *pFunc; @@ -716,6 +827,9 @@ sp_nativeinfo_t g_TRNatives[] = {"TR_DidHit", smn_TRDidHit}, {"TR_GetHitGroup", smn_TRGetHitGroup}, {"TR_ClipRayToEntity", smn_TRClipRayToEntity}, + {"TR_ClipRayToEntityEx", smn_TRClipRayToEntityEx}, + {"TR_ClipCurrRayToEntity", smn_TRClipCurrRayToEntity}, + {"TR_ClipCurrRayToEntityEx",smn_TRClipCurrRayToEntityEx}, {"TR_GetPointContents", smn_TRGetPointContents}, {"TR_GetPointContentsEnt", smn_TRGetPointContentsEnt}, {"TR_TraceRayFilter", smn_TRTraceRayFilter}, diff --git a/plugins/include/sdktools_trace.inc b/plugins/include/sdktools_trace.inc index ec4a1a7201..862d915ff8 100644 --- a/plugins/include/sdktools_trace.inc +++ b/plugins/include/sdktools_trace.inc @@ -266,6 +266,30 @@ native void TR_TraceHullFilter(const float pos[3], TraceEntityFilter filter, any data=0); +/** + * Traces a ray against a particular edict. + * + * @param pos Starting position of the ray. + * @param vec Depending on RayType, it will be used as the ending + * point, or the direction angle. + * @param flags Trace flags. + * @param rtype Method to calculate the ray direction. + * @param entity Entity to trace against + */ +native void TR_ClipRayToEntity(const float pos[3], + const float vec[3], + int flags, + RayType rtype, + int entity); + +/** + * Traces the current global ray against a particular edict. + * + * @param flags Trace flags. + * @param entity Entity to trace against + */ +native void TR_ClipCurrRayToEntity(int flags, int entity); + /** * Starts up a new trace ray using a new trace result. * @@ -343,6 +367,32 @@ native Handle TR_TraceHullFilterEx(const float pos[3], int flags, TraceEntityFilter filter, any data=0); + +/** + * Traces a ray against a particular edict. + * + * @param pos Starting position of the ray. + * @param vec Depending on RayType, it will be used as the ending + * point, or the direction angle. + * @param flags Trace flags. + * @param rtype Method to calculate the ray direction. + * @param entity Entity to trace against + * @return Ray trace handle, which must be closed via CloseHandle(). + */ +native Handle TR_ClipRayToEntityEx(const float pos[3], + const float vec[3], + int flags, + RayType rtype, + int entity); + +/** + * Traces current global ray against a particular edict. + * + * @param flags Trace flags. + * @param entity Entity to trace against + * @return Ray trace handle, which must be closed via CloseHandle(). + */ +native Handle TR_ClipCurrRayToEntityEx(int flags, int entity); /** * Returns the time fraction from a trace result (1.0 means no collision). @@ -398,16 +448,6 @@ native int TR_GetHitGroup(Handle hndl=INVALID_HANDLE); */ native void TR_GetPlaneNormal(Handle hndl, float normal[3]); -/** - * Traces a ray against a particular edict. - * - * @param flags Trace flags. - * @param entity Entity to trace against - * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result. - * @error Invalid Handle - */ -native void TR_ClipRayToEntity(int flags, int entity, Handle hndl=INVALID_HANDLE); - /** * Tests a point to see if it's outside any playable area * From 554dcb0b89bd4736928b1a037bf4b38c6f5e7a8a Mon Sep 17 00:00:00 2001 From: rio Date: Thu, 29 Mar 2018 19:12:14 -0500 Subject: [PATCH 3/5] Add hull variants for new trace natives, clean up include docstrings --- extensions/sdktools/trnatives.cpp | 111 +++++++++++++++++++ plugins/include/sdktools_trace.inc | 168 +++++++++++++++++++---------- 2 files changed, 225 insertions(+), 54 deletions(-) diff --git a/extensions/sdktools/trnatives.cpp b/extensions/sdktools/trnatives.cpp index 54f10d56c6..7a8203a211 100644 --- a/extensions/sdktools/trnatives.cpp +++ b/extensions/sdktools/trnatives.cpp @@ -221,6 +221,45 @@ static cell_t smn_TREnumerateEntities(IPluginContext *pContext, const cell_t *pa return 1; } +static cell_t smn_TREnumerateEntitiesHull(IPluginContext *pContext, const cell_t *params) +{ + IPluginFunction *pFunc = pContext->GetFunctionById(params[6]); + if (!pFunc) + { + return pContext->ThrowNativeError("Invalid function id (%X)", params[6]); + } + + cell_t data; + if (params[0] >= 7) + { + data = params[7]; + } + else + { + data = 0; + } + + g_SMTraceEnum.SetFunctionPtr(pFunc, data); + + cell_t *startaddr, *endaddr, *mins, *maxs; + pContext->LocalToPhysAddr(params[1], &startaddr); + pContext->LocalToPhysAddr(params[2], &endaddr); + pContext->LocalToPhysAddr(params[3], &mins); + pContext->LocalToPhysAddr(params[4], &maxs); + + g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); + g_HullMins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2])); + g_HullMaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2])); + g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + + g_Ray.Init(g_StartVec, g_EndVec, g_HullMins, g_HullMaxs); + + bool triggers = (params[5]) ? true : false; + enginetrace->EnumerateEntities(g_Ray, triggers, &g_SMTraceEnum); + + return 1; +} + static cell_t smn_TRClipRayToEntity(IPluginContext *pContext, const cell_t *params) { cell_t *startaddr; @@ -263,6 +302,34 @@ static cell_t smn_TRClipRayToEntity(IPluginContext *pContext, const cell_t *para return 1; } +static cell_t smn_TRClipRayHullToEntity(IPluginContext *pContext, const cell_t *params) +{ + cell_t *startaddr, *endaddr, *mins, *maxs; + pContext->LocalToPhysAddr(params[1], &startaddr); + pContext->LocalToPhysAddr(params[2], &endaddr); + pContext->LocalToPhysAddr(params[3], &mins); + pContext->LocalToPhysAddr(params[4], &maxs); + + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[6])); + if (!pEdict || pEdict->IsFree()) + { + return pContext->ThrowNativeError("Entity %d is invalid", params[6]); + } + + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + + g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); + g_HullMins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2])); + g_HullMaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2])); + g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + + g_Ray.Init(g_StartVec, g_EndVec, g_HullMins, g_HullMaxs); + enginetrace->ClipRayToEntity(g_Ray, params[5], pEnt, &g_Trace); + g_Trace.UpdateEntRef(); + + return 1; +} + static cell_t smn_TRClipCurrRayToEntity( IPluginContext *pContext, const cell_t *params ) { edict_t *pEdict = PEntityOfEntIndex( gamehelpers->ReferenceToIndex( params[2] ) ); @@ -500,6 +567,47 @@ static cell_t smn_TRClipRayToEntityEx( IPluginContext *pContext, const cell_t *p return hndl; } +static cell_t smn_TRClipRayHullToEntityEx(IPluginContext *pContext, const cell_t *params) +{ + cell_t *startaddr, *endaddr, *mins, *maxs; + pContext->LocalToPhysAddr(params[1], &startaddr); + pContext->LocalToPhysAddr(params[2], &endaddr); + pContext->LocalToPhysAddr(params[3], &mins); + pContext->LocalToPhysAddr(params[4], &maxs); + + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[6])); + if (!pEdict || pEdict->IsFree()) + { + return pContext->ThrowNativeError("Entity %d is invalid", params[6]); + } + + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + + Ray_t ray; + Vector StartVec, EndVec, vmins, vmaxs; + + StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); + vmins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2])); + vmaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2])); + EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + + ray.Init(StartVec, EndVec, vmins, vmaxs); + + sm_trace_t *tr = new sm_trace_t; + enginetrace->ClipRayToEntity(ray, params[5], pEnt, tr); + tr->UpdateEntRef(); + + HandleError herr; + Handle_t hndl; + if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) + { + delete tr; + return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); + } + + return hndl; +} + static cell_t smn_TRClipCurrRayToEntityEx( IPluginContext *pContext, const cell_t *params ) { edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); @@ -819,6 +927,7 @@ sp_nativeinfo_t g_TRNatives[] = {"TR_TraceRay", smn_TRTraceRay}, {"TR_TraceHull", smn_TRTraceHull}, {"TR_EnumerateEntities", smn_TREnumerateEntities}, + {"TR_EnumerateEntitiesHull",smn_TREnumerateEntitiesHull}, {"TR_TraceRayEx", smn_TRTraceRayEx}, {"TR_TraceHullEx", smn_TRTraceHullEx}, {"TR_GetFraction", smn_TRGetFraction}, @@ -828,6 +937,8 @@ sp_nativeinfo_t g_TRNatives[] = {"TR_GetHitGroup", smn_TRGetHitGroup}, {"TR_ClipRayToEntity", smn_TRClipRayToEntity}, {"TR_ClipRayToEntityEx", smn_TRClipRayToEntityEx}, + {"TR_ClipRayHullToEntity", smn_TRClipRayHullToEntity}, + {"TR_ClipRayHullToEntityEx",smn_TRClipRayHullToEntityEx}, {"TR_ClipCurrRayToEntity", smn_TRClipCurrRayToEntity}, {"TR_ClipCurrRayToEntityEx",smn_TRClipCurrRayToEntityEx}, {"TR_GetPointContents", smn_TRGetPointContents}, diff --git a/plugins/include/sdktools_trace.inc b/plugins/include/sdktools_trace.inc index 862d915ff8..8be372f885 100644 --- a/plugins/include/sdktools_trace.inc +++ b/plugins/include/sdktools_trace.inc @@ -9,7 +9,7 @@ * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, version 3.0, as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more @@ -120,7 +120,7 @@ typeset TraceEntityFilter * @return True to allow the current entity to be hit, otherwise false. */ function bool (int entity, int contentsMask); - + /** * Called on entity filtering. * @@ -135,19 +135,19 @@ typeset TraceEntityFilter typeset TraceEntityEnumerator { /** - * Called on entity enumerating. + * Called for each entity enumerated with EnumerateEntities*. * * @param entity Entity index. - * @return True to continue enumerating entities, otherwise false. + * @return True to continue enumerating, otherwise false. */ function bool (int entity); - + /** - * Called on entity enumerating. + * Called for each entity enumerated with EnumerateEntities*. * * @param entity Entity index. * @param data Data value, if used. - * @return True to continue enumerating entities, otherwise false. + * @return True to continue enumerating, otherwise false. */ function bool (int entity, any data); } @@ -183,7 +183,7 @@ native void TR_TraceRay(const float pos[3], const float vec[3], int flags, RayType rtype); - + /** * Starts up a new trace hull using a global trace result. * @@ -200,16 +200,19 @@ native void TR_TraceHull(const float pos[3], int flags); /** - * Enumerates over all entities along a ray + * Enumerates over entities along a ray. This may find entities that are + * close to the ray but do not actually intersect it. Use TR_Clip*RayToEntity + * with TR_DidHit to check if the ray actually intersects the entity. * * @param pos Starting position of the ray. - * @param vec Depending on RayType, it will be used as the ending + * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. - * @param triggers If triggers == true, it enumerates all triggers along a ray + * @param triggers If true, enumerate only triggers. Otherwise, enumerate + * only non-triggers. * @param rtype Method to calculate the ray direction. - * @param enumerator Function to use as enumerator. For each entity found along ray, this entity is called. - * @param data Arbitrary data value to pass through to the filter - * function. + * @param enumerator Function to use as enumerator. For each entity found + * along the ray, this function is called. + * @param data Arbitrary data value to pass through to the enumerator. */ native void TR_EnumerateEntities(const float pos[3], const float vec[3], @@ -217,21 +220,44 @@ native void TR_EnumerateEntities(const float pos[3], RayType rtype, TraceEntityEnumerator enumerator, any data=0); - + +/** + * Enumerates over entities along a ray hull. This may find entities that are + * close to the ray but do not actually intersect it. Use TR_Clip*RayToEntity + * with TR_DidHit to check if the ray actually intersects the entity. + * + * @param pos Starting position of the ray. + * @param vec Ending position of the ray. + * @param mins Hull minimum size. + * @param maxs Hull maximum size. + * @param triggers If true, enumerate only triggers. Otherwise, enumerate + * only non-triggers. + * @param enumerator Function to use as enumerator. For each entity found + * along the ray, this function is called. + * @param data Arbitrary data value to pass through to the enumerator. + */ +native void TR_EnumerateEntitiesHull(const float pos[3], + const float vec[3], + const float mins[3], + const float maxs[3], + bool triggers, + TraceEntityEnumerator enumerator, + any data=0); + /** - * Starts up a new trace ray using a global trace result and a customized + * Starts up a new trace ray using a global trace result and a customized * trace ray filter. * - * Calling TR_Trace*Filter or TR_Trace*FilterEx from inside a filter + * Calling TR_Trace*Filter or TR_Trace*FilterEx from inside a filter * function is currently not allowed and may not work. * * @param pos Starting position of the ray. - * @param vec Depending on RayType, it will be used as the ending + * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. * @param flags Trace flags. * @param rtype Method to calculate the ray direction. * @param filter Function to use as a filter. - * @param data Arbitrary data value to pass through to the filter + * @param data Arbitrary data value to pass through to the filter * function. */ native void TR_TraceRayFilter(const float pos[3], @@ -240,22 +266,21 @@ native void TR_TraceRayFilter(const float pos[3], RayType rtype, TraceEntityFilter filter, any data=0); - + /** - * Starts up a new trace hull using a global trace result and a customized + * Starts up a new trace hull using a global trace result and a customized * trace ray filter. * - * Calling TR_Trace*Filter or TR_Trace*FilterEx from inside a filter + * Calling TR_Trace*Filter or TR_Trace*FilterEx from inside a filter * function is currently not allowed and may not work. * * @param pos Starting position of the ray. - * @param vec Depending on RayType, it will be used as the ending - * point, or the direction angle. + * @param vec Ending position of the ray. * @param mins Hull minimum size. * @param maxs Hull maximum size. * @param flags Trace flags. * @param filter Function to use as a filter. - * @param data Arbitrary data value to pass through to the filter + * @param data Arbitrary data value to pass through to the filter * function. */ native void TR_TraceHullFilter(const float pos[3], @@ -265,36 +290,53 @@ native void TR_TraceHullFilter(const float pos[3], int flags, TraceEntityFilter filter, any data=0); - + /** - * Traces a ray against a particular edict. + * Clips a ray to a particular entity. * * @param pos Starting position of the ray. - * @param vec Depending on RayType, it will be used as the ending + * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. * @param flags Trace flags. * @param rtype Method to calculate the ray direction. - * @param entity Entity to trace against + * @param entity Entity to clip to. */ native void TR_ClipRayToEntity(const float pos[3], const float vec[3], int flags, RayType rtype, int entity); - + +/** + * Clips a ray hull to a particular entity. + * + * @param pos Starting position of the ray. + * @param vec Ending position of the ray. + * @param mins Hull minimum size. + * @param maxs Hull maximum size. + * @param flags Trace flags. + * @param entity Entity to clip to. + */ +native void TR_ClipRayHullToEntity(const float pos[3], + const float vec[3], + const float mins[3], + const float maxs[3], + int flags, + int entity); + /** - * Traces the current global ray against a particular edict. + * Clips the current global ray (or hull) to a particular entity. * * @param flags Trace flags. - * @param entity Entity to trace against + * @param entity Entity to clip to. */ native void TR_ClipCurrRayToEntity(int flags, int entity); - + /** * Starts up a new trace ray using a new trace result. * * @param pos Starting position of the ray. - * @param vec Depending on RayType, it will be used as the ending + * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. * @param flags Trace flags. * @param rtype Method to calculate the ray direction. @@ -304,7 +346,7 @@ native Handle TR_TraceRayEx(const float pos[3], const float vec[3], int flags, RayType rtype); - + /** * Starts up a new trace hull using a new trace result. * @@ -322,14 +364,14 @@ native Handle TR_TraceHullEx(const float pos[3], int flags); /** - * Starts up a new trace ray using a new trace result and a customized + * Starts up a new trace ray using a new trace result and a customized * trace ray filter. * - * Calling TR_Trace*Filter or TR_TraceRay*Ex from inside a filter + * Calling TR_Trace*Filter or TR_TraceRay*Ex from inside a filter * function is currently not allowed and may not work. * * @param pos Starting position of the ray. - * @param vec Depending on RayType, it will be used as the ending + * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. * @param flags Trace flags. * @param rtype Method to calculate the ray direction. @@ -337,18 +379,18 @@ native Handle TR_TraceHullEx(const float pos[3], * @param data Arbitrary data value to pass through to the filter function. * @return Ray trace handle, which must be closed via CloseHandle(). */ -native Handle TR_TraceRayFilterEx(const float pos[3], +native Handle TR_TraceRayFilterEx(const float pos[3], const float vec[3], - int flags, - RayType rtype, + int flags, + RayType rtype, TraceEntityFilter filter, any data=0); - + /** - * Starts up a new trace hull using a new trace result and a customized + * Starts up a new trace hull using a new trace result and a customized * trace ray filter. * - * Calling TR_Trace*Filter or TR_Trace*FilterEx from inside a filter + * Calling TR_Trace*Filter or TR_Trace*FilterEx from inside a filter * function is currently not allowed and may not work. * * @param pos Starting position of the ray. @@ -360,23 +402,23 @@ native Handle TR_TraceRayFilterEx(const float pos[3], * @param data Arbitrary data value to pass through to the filter function. * @return Ray trace handle, which must be closed via CloseHandle(). */ -native Handle TR_TraceHullFilterEx(const float pos[3], +native Handle TR_TraceHullFilterEx(const float pos[3], const float vec[3], const float mins[3], const float maxs[3], - int flags, + int flags, TraceEntityFilter filter, any data=0); - + /** - * Traces a ray against a particular edict. + * Clips a ray to a particular entity. * * @param pos Starting position of the ray. - * @param vec Depending on RayType, it will be used as the ending + * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. * @param flags Trace flags. * @param rtype Method to calculate the ray direction. - * @param entity Entity to trace against + * @param entity Entity to clip to. * @return Ray trace handle, which must be closed via CloseHandle(). */ native Handle TR_ClipRayToEntityEx(const float pos[3], @@ -384,12 +426,30 @@ native Handle TR_ClipRayToEntityEx(const float pos[3], int flags, RayType rtype, int entity); - + +/** + * Clips a ray hull to a particular entity. + * + * @param pos Starting position of the ray. + * @param vec Ending position of the ray. + * @param mins Hull minimum size. + * @param maxs Hull maximum size. + * @param flags Trace flags. + * @param entity Entity to clip to. + * @return Ray trace handle, which must be closed via CloseHandle(). + */ +native Handle TR_ClipRayHullToEntityEx(const float pos[3], + const float vec[3], + const float mins[3], + const float maxs[3], + int flags, + int entity); + /** - * Traces current global ray against a particular edict. + * Clips the current global ray (or hull) to a particular entity. * * @param flags Trace flags. - * @param entity Entity to trace against + * @param entity Entity to clip to. * @return Ray trace handle, which must be closed via CloseHandle(). */ native Handle TR_ClipCurrRayToEntityEx(int flags, int entity); @@ -452,6 +512,6 @@ native void TR_GetPlaneNormal(Handle hndl, float normal[3]); * Tests a point to see if it's outside any playable area * * @param pos Vector buffer to store data in. - * @return True if outside world, otherwise false. + * @return True if outside world, otherwise false. */ native bool TR_PointOutsideWorld(float pos[3]); From 0065e7b2ce05591f554fc27b1336f9103db05a07 Mon Sep 17 00:00:00 2001 From: Asher Baker Date: Mon, 13 Aug 2018 21:48:39 +0100 Subject: [PATCH 4/5] Fix line endings --- extensions/sdktools/trnatives.cpp | 310 +++++++++++++++--------------- 1 file changed, 155 insertions(+), 155 deletions(-) diff --git a/extensions/sdktools/trnatives.cpp b/extensions/sdktools/trnatives.cpp index 7a8203a211..702a8375a2 100644 --- a/extensions/sdktools/trnatives.cpp +++ b/extensions/sdktools/trnatives.cpp @@ -74,26 +74,26 @@ class CSMTraceFilter : public CTraceFilter cell_t m_Data; }; -class CSMTraceEnum : public IEntityEnumerator -{ -public: - bool EnumEntity(IHandleEntity *pEntity) override - { - cell_t res = 1; - m_pFunc->PushCell(gamehelpers->EntityToBCompatRef(reinterpret_cast(pEntity))); - m_pFunc->PushCell(m_Data); - m_pFunc->Execute(&res); - - return (res) ? true : false; - } - void SetFunctionPtr(IPluginFunction *pFunc, cell_t data) - { - m_pFunc = pFunc; - m_Data = data; - } -private: - IPluginFunction *m_pFunc; - cell_t m_Data; +class CSMTraceEnum : public IEntityEnumerator +{ +public: + bool EnumEntity(IHandleEntity *pEntity) override + { + cell_t res = 1; + m_pFunc->PushCell(gamehelpers->EntityToBCompatRef(reinterpret_cast(pEntity))); + m_pFunc->PushCell(m_Data); + m_pFunc->Execute(&res); + + return (res) ? true : false; + } + void SetFunctionPtr(IPluginFunction *pFunc, cell_t data) + { + m_pFunc = pFunc; + m_Data = data; + } +private: + IPluginFunction *m_pFunc; + cell_t m_Data; }; /* Used for the global trace version */ @@ -105,7 +105,7 @@ Vector g_HullMins; Vector g_HullMaxs; QAngle g_DirAngles; CTraceFilterHitAll g_HitAllFilter; -CSMTraceFilter g_SMTraceFilter; +CSMTraceFilter g_SMTraceFilter; CSMTraceEnum g_SMTraceEnum; enum @@ -168,57 +168,57 @@ static cell_t smn_TRTraceHull(IPluginContext *pContext, const cell_t *params) return 1; } -static cell_t smn_TREnumerateEntities(IPluginContext *pContext, const cell_t *params) -{ - IPluginFunction *pFunc = pContext->GetFunctionById(params[5]); - if (!pFunc) - { - return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); - } - - cell_t data; - if (params[0] >= 6) - { - data = params[6]; - } - else - { - data = 0; - } - - g_SMTraceEnum.SetFunctionPtr(pFunc, data); - - cell_t *startaddr, *endaddr; - pContext->LocalToPhysAddr(params[1], &startaddr); - pContext->LocalToPhysAddr(params[2], &endaddr); - - g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); - - switch (params[4]) - { - case RayType_EndPoint: - { - g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); - break; - } - case RayType_Infinite: - { - g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); - AngleVectors(g_DirAngles, &g_EndVec); - - /* Make it unitary and get the ending point */ - g_EndVec.NormalizeInPlace(); - g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; - break; - } - } - - g_Ray.Init(g_StartVec, g_EndVec); - - bool triggers = (params[3]) ? true : false; - enginetrace->EnumerateEntities(g_Ray, triggers, &g_SMTraceEnum); - - return 1; +static cell_t smn_TREnumerateEntities(IPluginContext *pContext, const cell_t *params) +{ + IPluginFunction *pFunc = pContext->GetFunctionById(params[5]); + if (!pFunc) + { + return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); + } + + cell_t data; + if (params[0] >= 6) + { + data = params[6]; + } + else + { + data = 0; + } + + g_SMTraceEnum.SetFunctionPtr(pFunc, data); + + cell_t *startaddr, *endaddr; + pContext->LocalToPhysAddr(params[1], &startaddr); + pContext->LocalToPhysAddr(params[2], &endaddr); + + g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); + + switch (params[4]) + { + case RayType_EndPoint: + { + g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + break; + } + case RayType_Infinite: + { + g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); + AngleVectors(g_DirAngles, &g_EndVec); + + /* Make it unitary and get the ending point */ + g_EndVec.NormalizeInPlace(); + g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; + break; + } + } + + g_Ray.Init(g_StartVec, g_EndVec); + + bool triggers = (params[3]) ? true : false; + enginetrace->EnumerateEntities(g_Ray, triggers, &g_SMTraceEnum); + + return 1; } static cell_t smn_TREnumerateEntitiesHull(IPluginContext *pContext, const cell_t *params) @@ -260,8 +260,8 @@ static cell_t smn_TREnumerateEntitiesHull(IPluginContext *pContext, const cell_t return 1; } -static cell_t smn_TRClipRayToEntity(IPluginContext *pContext, const cell_t *params) -{ +static cell_t smn_TRClipRayToEntity(IPluginContext *pContext, const cell_t *params) +{ cell_t *startaddr; pContext->LocalToPhysAddr(params[1], &startaddr); cell_t *endaddr; @@ -286,20 +286,20 @@ static cell_t smn_TRClipRayToEntity(IPluginContext *pContext, const cell_t *para g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; break; } - } - - edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[5])); - if (!pEdict || pEdict->IsFree()) - { - return pContext->ThrowNativeError("Entity %d is invalid", params[5]); - } - - IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); - g_Ray.Init(g_StartVec, g_EndVec); - enginetrace->ClipRayToEntity(g_Ray, params[3], pEnt, &g_Trace); - g_Trace.UpdateEntRef(); - - return 1; + } + + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[5])); + if (!pEdict || pEdict->IsFree()) + { + return pContext->ThrowNativeError("Entity %d is invalid", params[5]); + } + + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + g_Ray.Init(g_StartVec, g_EndVec); + enginetrace->ClipRayToEntity(g_Ray, params[3], pEnt, &g_Trace); + g_Trace.UpdateEntRef(); + + return 1; } static cell_t smn_TRClipRayHullToEntity(IPluginContext *pContext, const cell_t *params) @@ -330,19 +330,19 @@ static cell_t smn_TRClipRayHullToEntity(IPluginContext *pContext, const cell_t * return 1; } -static cell_t smn_TRClipCurrRayToEntity( IPluginContext *pContext, const cell_t *params ) -{ - edict_t *pEdict = PEntityOfEntIndex( gamehelpers->ReferenceToIndex( params[2] ) ); - if( !pEdict || pEdict->IsFree() ) - { - return pContext->ThrowNativeError( "Entity %d is invalid", params[2] ); - } - - IHandleEntity *pEnt = reinterpret_cast( pEdict->GetUnknown()->GetBaseEntity() ); - enginetrace->ClipRayToEntity( g_Ray, params[1], pEnt, &g_Trace ); - g_Trace.UpdateEntRef(); - - return 1; +static cell_t smn_TRClipCurrRayToEntity( IPluginContext *pContext, const cell_t *params ) +{ + edict_t *pEdict = PEntityOfEntIndex( gamehelpers->ReferenceToIndex( params[2] ) ); + if( !pEdict || pEdict->IsFree() ) + { + return pContext->ThrowNativeError( "Entity %d is invalid", params[2] ); + } + + IHandleEntity *pEnt = reinterpret_cast( pEdict->GetUnknown()->GetBaseEntity() ); + enginetrace->ClipRayToEntity( g_Ray, params[1], pEnt, &g_Trace ); + g_Trace.UpdateEntRef(); + + return 1; } static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *params) @@ -511,8 +511,8 @@ static cell_t smn_TRTraceHullEx(IPluginContext *pContext, const cell_t *params) return hndl; } -static cell_t smn_TRClipRayToEntityEx( IPluginContext *pContext, const cell_t *params ) -{ +static cell_t smn_TRClipRayToEntityEx( IPluginContext *pContext, const cell_t *params ) +{ cell_t *startaddr; pContext->LocalToPhysAddr(params[1], &startaddr); cell_t *endaddr; @@ -540,31 +540,31 @@ static cell_t smn_TRClipRayToEntityEx( IPluginContext *pContext, const cell_t *p EndVec = StartVec + EndVec * MAX_TRACE_LENGTH; break; } - } - - edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[5])); - if (!pEdict || pEdict->IsFree()) - { - return pContext->ThrowNativeError("Entity %d is invalid", params[5]); - } - - Ray_t ray; - sm_trace_t *tr = new sm_trace_t; - - IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); - ray.Init(StartVec, EndVec); - enginetrace->ClipRayToEntity(ray, params[3], pEnt, tr); - tr->UpdateEntRef(); - + } + + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[5])); + if (!pEdict || pEdict->IsFree()) + { + return pContext->ThrowNativeError("Entity %d is invalid", params[5]); + } + + Ray_t ray; + sm_trace_t *tr = new sm_trace_t; + + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + ray.Init(StartVec, EndVec); + enginetrace->ClipRayToEntity(ray, params[3], pEnt, tr); + tr->UpdateEntRef(); + HandleError herr; Handle_t hndl; if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) { delete tr; return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); - } - - return hndl; + } + + return hndl; } static cell_t smn_TRClipRayHullToEntityEx(IPluginContext *pContext, const cell_t *params) @@ -608,29 +608,29 @@ static cell_t smn_TRClipRayHullToEntityEx(IPluginContext *pContext, const cell_t return hndl; } -static cell_t smn_TRClipCurrRayToEntityEx( IPluginContext *pContext, const cell_t *params ) -{ - edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); - if (!pEdict || pEdict->IsFree()) - { - return pContext->ThrowNativeError("Entity %d is invalid", params[2]); - } - - sm_trace_t *tr = new sm_trace_t; - - IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); - enginetrace->ClipRayToEntity(g_Ray, params[1], pEnt, tr); - tr->UpdateEntRef(); - +static cell_t smn_TRClipCurrRayToEntityEx( IPluginContext *pContext, const cell_t *params ) +{ + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); + if (!pEdict || pEdict->IsFree()) + { + return pContext->ThrowNativeError("Entity %d is invalid", params[2]); + } + + sm_trace_t *tr = new sm_trace_t; + + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + enginetrace->ClipRayToEntity(g_Ray, params[1], pEnt, tr); + tr->UpdateEntRef(); + HandleError herr; Handle_t hndl; if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) { delete tr; return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); - } - - return hndl; + } + + return hndl; } static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *params) @@ -908,24 +908,24 @@ static cell_t smn_TRGetPointContentsEnt(IPluginContext *pContext, const cell_t * return enginetrace->GetPointContents_Collideable(pEdict->GetCollideable(), pos); } -static cell_t smn_TRPointOutsideWorld(IPluginContext *pContext, const cell_t *params) -{ - cell_t *vec; - Vector pos; - - pContext->LocalToPhysAddr(params[1], &vec); - - pos.x = sp_ctof(vec[0]); - pos.y = sp_ctof(vec[1]); - pos.z = sp_ctof(vec[2]); - - return enginetrace->PointOutsideWorld(pos); -} - +static cell_t smn_TRPointOutsideWorld(IPluginContext *pContext, const cell_t *params) +{ + cell_t *vec; + Vector pos; + + pContext->LocalToPhysAddr(params[1], &vec); + + pos.x = sp_ctof(vec[0]); + pos.y = sp_ctof(vec[1]); + pos.z = sp_ctof(vec[2]); + + return enginetrace->PointOutsideWorld(pos); +} + sp_nativeinfo_t g_TRNatives[] = { {"TR_TraceRay", smn_TRTraceRay}, - {"TR_TraceHull", smn_TRTraceHull}, + {"TR_TraceHull", smn_TRTraceHull}, {"TR_EnumerateEntities", smn_TREnumerateEntities}, {"TR_EnumerateEntitiesHull",smn_TREnumerateEntitiesHull}, {"TR_TraceRayEx", smn_TRTraceRayEx}, @@ -934,7 +934,7 @@ sp_nativeinfo_t g_TRNatives[] = {"TR_GetEndPosition", smn_TRGetEndPosition}, {"TR_GetEntityIndex", smn_TRGetEntityIndex}, {"TR_DidHit", smn_TRDidHit}, - {"TR_GetHitGroup", smn_TRGetHitGroup}, + {"TR_GetHitGroup", smn_TRGetHitGroup}, {"TR_ClipRayToEntity", smn_TRClipRayToEntity}, {"TR_ClipRayToEntityEx", smn_TRClipRayToEntityEx}, {"TR_ClipRayHullToEntity", smn_TRClipRayHullToEntity}, From d6411d72297a5c76ede45532e3ce4cca2603c528 Mon Sep 17 00:00:00 2001 From: Asher Baker Date: Mon, 13 Aug 2018 21:54:24 +0100 Subject: [PATCH 5/5] Style changes --- extensions/sdktools/trnatives.cpp | 136 ++++++++++++++--------------- plugins/include/sdktools_trace.inc | 27 +++--- 2 files changed, 77 insertions(+), 86 deletions(-) diff --git a/extensions/sdktools/trnatives.cpp b/extensions/sdktools/trnatives.cpp index 702a8375a2..555319d1e5 100644 --- a/extensions/sdktools/trnatives.cpp +++ b/extensions/sdktools/trnatives.cpp @@ -8,7 +8,7 @@ * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, version 3.0, as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more @@ -74,7 +74,7 @@ class CSMTraceFilter : public CTraceFilter cell_t m_Data; }; -class CSMTraceEnum : public IEntityEnumerator +class CSMTraceEnumerator : public IEntityEnumerator { public: bool EnumEntity(IHandleEntity *pEntity) override @@ -106,7 +106,7 @@ Vector g_HullMaxs; QAngle g_DirAngles; CTraceFilterHitAll g_HitAllFilter; CSMTraceFilter g_SMTraceFilter; -CSMTraceEnum g_SMTraceEnum; +CSMTraceEnumerator g_SMTraceEnumerator; enum { @@ -176,17 +176,13 @@ static cell_t smn_TREnumerateEntities(IPluginContext *pContext, const cell_t *pa return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); } - cell_t data; + cell_t data = 0; if (params[0] >= 6) { data = params[6]; } - else - { - data = 0; - } - g_SMTraceEnum.SetFunctionPtr(pFunc, data); + g_SMTraceEnumerator.SetFunctionPtr(pFunc, data); cell_t *startaddr, *endaddr; pContext->LocalToPhysAddr(params[1], &startaddr); @@ -216,7 +212,7 @@ static cell_t smn_TREnumerateEntities(IPluginContext *pContext, const cell_t *pa g_Ray.Init(g_StartVec, g_EndVec); bool triggers = (params[3]) ? true : false; - enginetrace->EnumerateEntities(g_Ray, triggers, &g_SMTraceEnum); + enginetrace->EnumerateEntities(g_Ray, triggers, &g_SMTraceEnumerator); return 1; } @@ -228,35 +224,31 @@ static cell_t smn_TREnumerateEntitiesHull(IPluginContext *pContext, const cell_t { return pContext->ThrowNativeError("Invalid function id (%X)", params[6]); } - - cell_t data; + + cell_t data = 0; if (params[0] >= 7) { data = params[7]; } - else - { - data = 0; - } - - g_SMTraceEnum.SetFunctionPtr(pFunc, data); - + + g_SMTraceEnumerator.SetFunctionPtr(pFunc, data); + cell_t *startaddr, *endaddr, *mins, *maxs; pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[2], &endaddr); pContext->LocalToPhysAddr(params[3], &mins); pContext->LocalToPhysAddr(params[4], &maxs); - + g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); g_HullMins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2])); g_HullMaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2])); g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); - + g_Ray.Init(g_StartVec, g_EndVec, g_HullMins, g_HullMaxs); - - bool triggers = (params[5]) ? true : false; - enginetrace->EnumerateEntities(g_Ray, triggers, &g_SMTraceEnum); - + + bool triggers = (params[5]) ? true : false; + enginetrace->EnumerateEntities(g_Ray, triggers, &g_SMTraceEnumerator); + return 1; } @@ -317,29 +309,29 @@ static cell_t smn_TRClipRayHullToEntity(IPluginContext *pContext, const cell_t * } IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); - + g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); g_HullMins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2])); g_HullMaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2])); g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); - + g_Ray.Init(g_StartVec, g_EndVec, g_HullMins, g_HullMaxs); enginetrace->ClipRayToEntity(g_Ray, params[5], pEnt, &g_Trace); g_Trace.UpdateEntRef(); - + return 1; } -static cell_t smn_TRClipCurrRayToEntity( IPluginContext *pContext, const cell_t *params ) +static cell_t smn_TRClipCurrentRayToEntity(IPluginContext *pContext, const cell_t *params) { - edict_t *pEdict = PEntityOfEntIndex( gamehelpers->ReferenceToIndex( params[2] ) ); - if( !pEdict || pEdict->IsFree() ) + edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); + if (!pEdict || pEdict->IsFree()) { - return pContext->ThrowNativeError( "Entity %d is invalid", params[2] ); + return pContext->ThrowNativeError("Entity %d is invalid", params[2]); } - IHandleEntity *pEnt = reinterpret_cast( pEdict->GetUnknown()->GetBaseEntity() ); - enginetrace->ClipRayToEntity( g_Ray, params[1], pEnt, &g_Trace ); + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + enginetrace->ClipRayToEntity(g_Ray, params[1], pEnt, &g_Trace); g_Trace.UpdateEntRef(); return 1; @@ -511,7 +503,7 @@ static cell_t smn_TRTraceHullEx(IPluginContext *pContext, const cell_t *params) return hndl; } -static cell_t smn_TRClipRayToEntityEx( IPluginContext *pContext, const cell_t *params ) +static cell_t smn_TRClipRayToEntityEx(IPluginContext *pContext, const cell_t *params) { cell_t *startaddr; pContext->LocalToPhysAddr(params[1], &startaddr); @@ -581,22 +573,22 @@ static cell_t smn_TRClipRayHullToEntityEx(IPluginContext *pContext, const cell_t return pContext->ThrowNativeError("Entity %d is invalid", params[6]); } - IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); - + IHandleEntity *pEnt = reinterpret_cast(pEdict->GetUnknown()->GetBaseEntity()); + Ray_t ray; Vector StartVec, EndVec, vmins, vmaxs; - + StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); vmins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2])); vmaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2])); EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); - - ray.Init(StartVec, EndVec, vmins, vmaxs); - + + ray.Init(StartVec, EndVec, vmins, vmaxs); + sm_trace_t *tr = new sm_trace_t; enginetrace->ClipRayToEntity(ray, params[5], pEnt, tr); tr->UpdateEntRef(); - + HandleError herr; Handle_t hndl; if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) @@ -604,11 +596,11 @@ static cell_t smn_TRClipRayHullToEntityEx(IPluginContext *pContext, const cell_t delete tr; return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); } - + return hndl; } -static cell_t smn_TRClipCurrRayToEntityEx( IPluginContext *pContext, const cell_t *params ) +static cell_t smn_TRClipCurrentRayToEntityEx(IPluginContext *pContext, const cell_t *params) { edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); if (!pEdict || pEdict->IsFree()) @@ -912,7 +904,7 @@ static cell_t smn_TRPointOutsideWorld(IPluginContext *pContext, const cell_t *pa { cell_t *vec; Vector pos; - + pContext->LocalToPhysAddr(params[1], &vec); pos.x = sp_ctof(vec[0]); @@ -922,32 +914,32 @@ static cell_t smn_TRPointOutsideWorld(IPluginContext *pContext, const cell_t *pa return enginetrace->PointOutsideWorld(pos); } -sp_nativeinfo_t g_TRNatives[] = +sp_nativeinfo_t g_TRNatives[] = { - {"TR_TraceRay", smn_TRTraceRay}, - {"TR_TraceHull", smn_TRTraceHull}, - {"TR_EnumerateEntities", smn_TREnumerateEntities}, - {"TR_EnumerateEntitiesHull",smn_TREnumerateEntitiesHull}, - {"TR_TraceRayEx", smn_TRTraceRayEx}, - {"TR_TraceHullEx", smn_TRTraceHullEx}, - {"TR_GetFraction", smn_TRGetFraction}, - {"TR_GetEndPosition", smn_TRGetEndPosition}, - {"TR_GetEntityIndex", smn_TRGetEntityIndex}, - {"TR_DidHit", smn_TRDidHit}, - {"TR_GetHitGroup", smn_TRGetHitGroup}, - {"TR_ClipRayToEntity", smn_TRClipRayToEntity}, - {"TR_ClipRayToEntityEx", smn_TRClipRayToEntityEx}, - {"TR_ClipRayHullToEntity", smn_TRClipRayHullToEntity}, - {"TR_ClipRayHullToEntityEx",smn_TRClipRayHullToEntityEx}, - {"TR_ClipCurrRayToEntity", smn_TRClipCurrRayToEntity}, - {"TR_ClipCurrRayToEntityEx",smn_TRClipCurrRayToEntityEx}, - {"TR_GetPointContents", smn_TRGetPointContents}, - {"TR_GetPointContentsEnt", smn_TRGetPointContentsEnt}, - {"TR_TraceRayFilter", smn_TRTraceRayFilter}, - {"TR_TraceRayFilterEx", smn_TRTraceRayFilterEx}, - {"TR_TraceHullFilter", smn_TRTraceHullFilter}, - {"TR_TraceHullFilterEx", smn_TRTraceHullFilterEx}, - {"TR_GetPlaneNormal", smn_TRGetPlaneNormal}, - {"TR_PointOutsideWorld", smn_TRPointOutsideWorld}, - {NULL, NULL} + {"TR_TraceRay", smn_TRTraceRay}, + {"TR_TraceHull", smn_TRTraceHull}, + {"TR_EnumerateEntities", smn_TREnumerateEntities}, + {"TR_EnumerateEntitiesHull", smn_TREnumerateEntitiesHull}, + {"TR_TraceRayEx", smn_TRTraceRayEx}, + {"TR_TraceHullEx", smn_TRTraceHullEx}, + {"TR_GetFraction", smn_TRGetFraction}, + {"TR_GetEndPosition", smn_TRGetEndPosition}, + {"TR_GetEntityIndex", smn_TRGetEntityIndex}, + {"TR_DidHit", smn_TRDidHit}, + {"TR_GetHitGroup", smn_TRGetHitGroup}, + {"TR_ClipRayToEntity", smn_TRClipRayToEntity}, + {"TR_ClipRayToEntityEx", smn_TRClipRayToEntityEx}, + {"TR_ClipRayHullToEntity", smn_TRClipRayHullToEntity}, + {"TR_ClipRayHullToEntityEx", smn_TRClipRayHullToEntityEx}, + {"TR_ClipCurrentRayToEntity", smn_TRClipCurrentRayToEntity}, + {"TR_ClipCurrentRayToEntityEx", smn_TRClipCurrentRayToEntityEx}, + {"TR_GetPointContents", smn_TRGetPointContents}, + {"TR_GetPointContentsEnt", smn_TRGetPointContentsEnt}, + {"TR_TraceRayFilter", smn_TRTraceRayFilter}, + {"TR_TraceRayFilterEx", smn_TRTraceRayFilterEx}, + {"TR_TraceHullFilter", smn_TRTraceHullFilter}, + {"TR_TraceHullFilterEx", smn_TRTraceHullFilterEx}, + {"TR_GetPlaneNormal", smn_TRGetPlaneNormal}, + {"TR_PointOutsideWorld", smn_TRPointOutsideWorld}, + {NULL, NULL} }; diff --git a/plugins/include/sdktools_trace.inc b/plugins/include/sdktools_trace.inc index 8be372f885..afa1541f0b 100644 --- a/plugins/include/sdktools_trace.inc +++ b/plugins/include/sdktools_trace.inc @@ -116,19 +116,19 @@ typeset TraceEntityFilter * Called on entity filtering. * * @param entity Entity index. - * @param contentsMask Contents Mask. - * @return True to allow the current entity to be hit, otherwise false. - */ + * @param contentsMask Contents Mask. + * @return True to allow the current entity to be hit, otherwise false. + */ function bool (int entity, int contentsMask); /** * Called on entity filtering. * * @param entity Entity index. - * @param contentsMask Contents Mask. - * @param data Data value, if used. - * @return True to allow the current entity to be hit, otherwise false. - */ + * @param contentsMask Contents Mask. + * @param data Data value, if used. + * @return True to allow the current entity to be hit, otherwise false. + */ function bool (int entity, int contentsMask, any data); }; @@ -138,17 +138,16 @@ typeset TraceEntityEnumerator * Called for each entity enumerated with EnumerateEntities*. * * @param entity Entity index. - * @return True to continue enumerating, otherwise false. - */ + * @return True to continue enumerating, otherwise false. + */ function bool (int entity); /** * Called for each entity enumerated with EnumerateEntities*. * * @param entity Entity index. - * @param data Data value, if used. - * @return True to continue enumerating, otherwise false. - */ + * @param data Data value, if used. + * @return True to continue enumerating, otherwise false. */ function bool (int entity, any data); } @@ -330,7 +329,7 @@ native void TR_ClipRayHullToEntity(const float pos[3], * @param flags Trace flags. * @param entity Entity to clip to. */ -native void TR_ClipCurrRayToEntity(int flags, int entity); +native void TR_ClipCurrentRayToEntity(int flags, int entity); /** * Starts up a new trace ray using a new trace result. @@ -452,7 +451,7 @@ native Handle TR_ClipRayHullToEntityEx(const float pos[3], * @param entity Entity to clip to. * @return Ray trace handle, which must be closed via CloseHandle(). */ -native Handle TR_ClipCurrRayToEntityEx(int flags, int entity); +native Handle TR_ClipCurrentRayToEntityEx(int flags, int entity); /** * Returns the time fraction from a trace result (1.0 means no collision).