Skip to content

Commit

Permalink
extend SV_TraceEntity() function with ability to choose desired col…
Browse files Browse the repository at this point in the history
…lision kind: solid, trigger, or both

fix #116
  • Loading branch information
alexey-lysiuk committed Nov 10, 2023
1 parent b00333f commit 48c0784
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
3 changes: 1 addition & 2 deletions Quake/ls_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,7 @@ static int LS_global_player_setpos(lua_State* state)

static int LS_global_player_traceentity(lua_State* state)
{
edict_t* SV_TraceEntity(void);
edict_t* ed = SV_TraceEntity();
edict_t* ed = SV_TraceEntity(SV_TRACE_ENTITY_ALL);

if (ed == NULL)
lua_pushnil(state);
Expand Down
46 changes: 35 additions & 11 deletions Quake/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,11 +1146,21 @@ static vec_t ET_DistanceToEntity(et_state_t* storage, const edict_t* entity, qbo
return DotProduct(dir, storage->forward);
}

edict_t* SV_TraceEntity(void)
#define SV_TRACE_ENTITY_SOLID 1
#define SV_TRACE_ENTITY_TRIGGER 2
#define SV_TRACE_ENTITY_ALL (SV_TRACE_ENTITY_SOLID | SV_TRACE_ENTITY_TRIGGER)

edict_t* SV_TraceEntity(int kind)
{
if (svs.clients == NULL || !svs.clients[0].active)
return NULL;

qboolean trace_solid = kind & SV_TRACE_ENTITY_SOLID;
qboolean trace_trigger = kind & SV_TRACE_ENTITY_TRIGGER;

if (!trace_solid && !trace_trigger)
return NULL;

et_state_t state;
memset(&state, 0, sizeof state);

Expand All @@ -1162,14 +1172,24 @@ edict_t* SV_TraceEntity(void)
state.initialtrace = clip->trace;

// Trace solid entity
SV_ClipToLinks(sv_areanodes, clip);
edict_t* solid_ent = clip->trace.ent;
edict_t* solid_ent = NULL;

clip->trace = state.initialtrace;
if (trace_solid)
{
SV_ClipToLinks(sv_areanodes, clip);
solid_ent = clip->trace.ent;

clip->trace = state.initialtrace;
}

// Trace trigger entity
ET_TraceTriger(sv_areanodes, clip);
edict_t* trigger_ent = clip->trace.ent;
edict_t* trigger_ent = NULL;

if (trace_trigger)
{
ET_TraceTriger(sv_areanodes, clip);
trigger_ent = clip->trace.ent;
}

// Choose entity, solid or trigger, depending on tracing results and proximity
edict_t* ent = NULL;
Expand Down Expand Up @@ -1204,12 +1224,16 @@ edict_t* SV_TraceEntity(void)
if (dist < bestdist)
continue; // to far to turn

clip->trace = state.initialtrace;

if (check->v.solid == SOLID_TRIGGER)
if (check->v.solid == SOLID_TRIGGER && trace_trigger)
{
clip->trace = state.initialtrace;
ET_TraceTriger(sv_areanodes, clip);
else
}
else if (trace_solid)
{
clip->trace = state.initialtrace;
SV_ClipToLinks(sv_areanodes, clip);
}

if (clip->trace.ent == check)
{
Expand Down Expand Up @@ -1270,7 +1294,7 @@ void SV_UpdateTracedEntityInfo(void)

SV_ResetTracedEntityInfo(NULL);

edict_t* ent = SV_TraceEntity();
edict_t* ent = SV_TraceEntity(SV_TRACE_ENTITY_ALL);

if (ent == NULL)
return;
Expand Down
6 changes: 6 additions & 0 deletions Quake/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,11 @@ trace_t SV_Move (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, e

qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace);

#define SV_TRACE_ENTITY_SOLID 1
#define SV_TRACE_ENTITY_TRIGGER 2
#define SV_TRACE_ENTITY_ALL (SV_TRACE_ENTITY_SOLID | SV_TRACE_ENTITY_TRIGGER)

edict_t* SV_TraceEntity(int kind);

#endif /* _QUAKE_WORLD_H */

0 comments on commit 48c0784

Please sign in to comment.