Skip to content

Commit 550cf0a

Browse files
committed
feat: use client trace wherever possible
improving orange huds n stuff
1 parent 4991651 commit 550cf0a

File tree

7 files changed

+17
-121
lines changed

7 files changed

+17
-121
lines changed

src/Features/Demo/GhostEntity.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ void GhostEntity::FollowPov(ViewSetup *view) {
419419
// want to view from; that way, we can avoid the camera clipping
420420
// into a wall
421421

422-
void *player = server->GetPlayer(1);
422+
void *player = client->GetPlayer(GET_SLOT() + 1);
423423
if (!player) return; // Probably shouldn't ever happen
424424

425-
angles = engine->GetAngles(0);
425+
angles = engine->GetAngles(GET_SLOT());
426426

427427
CTraceFilterSimple filter;
428428
filter.SetPassEntity(player);
@@ -445,7 +445,7 @@ void GhostEntity::FollowPov(ViewSetup *view) {
445445

446446
CGameTrace tr;
447447

448-
engine->TraceRay(engine->engineTrace->ThisPtr(), ray, MASK_SOLID_BRUSHONLY, &filter, &tr);
448+
engine->TraceRayClient(engine->engineTraceClient->ThisPtr(), ray, MASK_SOLID_BRUSHONLY, &filter, &tr);
449449

450450
Vector campos = tr.endpos + forward * cam_wall_dist;
451451

@@ -464,7 +464,7 @@ void GhostEntity::StopFollowing() {
464464
r_portalsopenall.SetValue(r_portalsopenall_value);
465465
r_drawviewmodel.SetValue(r_drawviewmodel_value);
466466
crosshairVariable.SetValue(crosshair_value);
467-
void *player = server->GetPlayer(1);
467+
void *player = server->GetPlayer(GET_SLOT() + 1);
468468
if (player) {
469469
SE(player)->field<int>("m_fFlags") &= ~FL_GODMODE;
470470
SE(player)->field<int>("m_fFlags") &= ~FL_NOTARGET;
@@ -690,12 +690,12 @@ ON_EVENT(PRE_TICK) {
690690
GhostEntity *ghost = GhostEntity::GetFollowTarget();
691691
if (!ghost) return;
692692

693-
void *player = server->GetPlayer(1);
693+
void *player = server->GetPlayer(GET_SLOT() + 1);
694694
if (!player) return;
695695

696696
// We use ent_setpos to prevent 'setpos into world' errors being
697697
// spewed in console
698-
auto cmd = Utils::ssprintf("ent_setpos 1 %.6f %.6f %.6f", ghost->data.position.x, ghost->data.position.y, ghost->data.position.z);
698+
auto cmd = Utils::ssprintf("ent_setpos %d %.6f %.6f %.6f", GET_SLOT() + 1, ghost->data.position.x, ghost->data.position.y, ghost->data.position.z);
699699
engine->ExecuteCommand(cmd.c_str());
700700

701701
// Make sure we have godmode so we can't die while spectating someone

src/Features/Demo/GhostRenderer.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,29 +174,9 @@ CON_COMMAND(ghost_locator, "ghost_locator - Sends a coop-like ping to other ghos
174174
return console->Print("Must be connected to a ghost server.\n");
175175
}
176176

177-
Vector cam_pos;
178-
QAngle cam_ang;
179-
camera->GetEyePos<false>(GET_SLOT(), cam_pos, cam_ang);
180-
181-
Vector dir;
182-
Math::AngleVectors(cam_ang, &dir);
183-
dir *= 8192.0f;
184-
185177
CGameTrace tr;
186-
187-
Ray_t ray;
188-
ray.m_IsRay = true;
189-
ray.m_IsSwept = true;
190-
ray.m_Start = VectorAligned(cam_pos.x, cam_pos.y, cam_pos.z);
191-
ray.m_Delta = VectorAligned(dir.x, dir.y, dir.z);
192-
ray.m_StartOffset = VectorAligned();
193-
ray.m_Extents = VectorAligned();
194-
195-
CTraceFilterSimple filter;
196-
filter.SetPassEntity(server->GetPlayer(GET_SLOT() + 1)); // TODO: orange?
197-
198-
engine->TraceRay(engine->engineTrace->ThisPtr(), ray, MASK_SHOT_PORTAL, &filter, &tr);
199-
200-
client->ShowLocator(tr.endpos, tr.plane.normal, GhostEntity::set_color);
201-
networkManager.NotifyLocator(tr.endpos, tr.plane.normal);
178+
if (engine->TraceFromCamera<false>(8192.0f, MASK_SHOT_PORTAL, tr)) {
179+
client->ShowLocator(tr.endpos, tr.plane.normal, GhostEntity::set_color);
180+
networkManager.NotifyLocator(tr.endpos, tr.plane.normal);
181+
}
202182
}

src/Features/Hud/AimPointHud.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,8 @@ static bool shouldDraw() {
4747
static bool updateTrace(int slot) {
4848
if (!session->isRunning) return false;
4949

50-
void *player = server->GetPlayer(slot + 1);
51-
if (!player) return false;
52-
53-
g_last_trace_valid = false;
54-
55-
Vector cam_pos;
56-
QAngle cam_ang;
57-
camera->GetEyePos<false>(GET_SLOT(), cam_pos, cam_ang);
58-
59-
Vector dir;
60-
Math::AngleVectors(cam_ang, &dir);
61-
dir *= TRACE_LENGTH;
62-
6350
CGameTrace tr;
64-
65-
Ray_t ray;
66-
ray.m_IsRay = true;
67-
ray.m_IsSwept = true;
68-
ray.m_Start = VectorAligned(cam_pos.x, cam_pos.y, cam_pos.z);
69-
ray.m_Delta = VectorAligned(dir.x, dir.y, dir.z);
70-
ray.m_StartOffset = VectorAligned();
71-
ray.m_Extents = VectorAligned();
72-
73-
CTraceFilterSimple filter;
74-
filter.SetPassEntity(player);
75-
76-
engine->TraceRay(engine->engineTrace->ThisPtr(), ray, MASK_VISIBLE, &filter, &tr);
51+
engine->TraceFromCamera<false>(TRACE_LENGTH, MASK_VISIBLE, tr);
7752

7853
g_last_trace = tr;
7954
g_last_trace_valid = tr.plane.normal.Length() > 0.9;

src/Features/Hud/Crosshair.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,8 @@ bool Crosshair::GetCurrentSize(int &xSize, int &ySize) {
6868
}
6969

7070
bool Crosshair::IsSurfacePortalable() {
71-
void *player = server->GetPlayer(GET_SLOT() + 1);
72-
73-
if (player == nullptr || (int)player == -1)
74-
return false;
75-
76-
Vector camPos = server->GetAbsOrigin(player) + server->GetViewOffset(player);
77-
78-
QAngle angle = engine->GetAngles(GET_SLOT());
79-
80-
float X = DEG2RAD(angle.x), Y = DEG2RAD(angle.y);
81-
auto cosX = std::cos(X), cosY = std::cos(Y);
82-
auto sinX = std::sin(X), sinY = std::sin(Y);
83-
84-
Vector dir(cosY * cosX, sinY * cosX, -sinX);
85-
86-
Vector finalDir = Vector(dir.x, dir.y, dir.z).Normalize() * 65536.0;
87-
88-
Ray_t ray;
89-
ray.m_IsRay = true;
90-
ray.m_IsSwept = true;
91-
ray.m_Start = VectorAligned(camPos.x, camPos.y, camPos.z);
92-
ray.m_Delta = VectorAligned(finalDir.x, finalDir.y, finalDir.z);
93-
ray.m_StartOffset = VectorAligned();
94-
ray.m_Extents = VectorAligned();
95-
96-
CTraceFilterSimple filter;
97-
filter.SetPassEntity(server->GetPlayer(GET_SLOT() + 1));
98-
9971
CGameTrace tr;
100-
engine->TraceRay(engine->engineTrace->ThisPtr(), ray, MASK_SHOT_PORTAL, &filter, &tr);
101-
102-
if (tr.fraction >= 1) {
72+
if (!engine->TraceFromCamera<false>(65536.0, MASK_SHOT_PORTAL, tr)) {
10373
return false;
10474
}
10575

src/Features/PlacementScanner.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,9 @@
2121
static std::optional<CGameTrace> camTrace() {
2222
if (!session->isRunning) return {};
2323

24-
void *player = server->GetPlayer(1);
25-
if (!player) return {};
26-
27-
CTraceFilterSimple filter;
28-
filter.SetPassEntity(player);
29-
30-
Vector cam = camera->GetPosition(GET_SLOT());
31-
Vector delta = camera->GetForwardVector(GET_SLOT()) * TRACE_LENGTH;
32-
33-
Ray_t ray;
34-
ray.m_IsRay = true;
35-
ray.m_IsSwept = true;
36-
ray.m_Start = VectorAligned(cam.x, cam.y, cam.z);
37-
ray.m_Delta = VectorAligned(delta.x, delta.y, delta.z);
38-
ray.m_StartOffset = VectorAligned();
39-
4024
CGameTrace tr;
4125

42-
engine->TraceRay(engine->engineTrace->ThisPtr(), ray, MASK_SHOT_PORTAL, &filter, &tr);
26+
engine->TraceFromCamera<false>(TRACE_LENGTH, MASK_SHOT_PORTAL, tr);
4327

4428
return tr.plane.normal.Length() > 0.9 ? tr : std::optional<CGameTrace>{};
4529
}

src/Features/Routing/Ruler.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,7 @@ void RulerManager::UpdateCreator() {
8787
dir *= sar_ruler_max_trace_dist.GetFloat();
8888

8989
CGameTrace tr;
90-
91-
Ray_t ray;
92-
ray.m_IsRay = true;
93-
ray.m_IsSwept = true;
94-
ray.m_Start = VectorAligned(cam_pos.x, cam_pos.y, cam_pos.z);
95-
ray.m_Delta = VectorAligned(dir.x, dir.y, dir.z);
96-
ray.m_StartOffset = VectorAligned();
97-
ray.m_Extents = VectorAligned();
98-
99-
CTraceFilterSimple filter;
100-
filter.SetPassEntity(server->GetPlayer(GET_SLOT() + 1));
101-
102-
engine->TraceRay(engine->engineTrace->ThisPtr(), ray, MASK_SHOT_PORTAL, &filter, &tr);
90+
engine->TraceFromCamera<false>(sar_ruler_max_trace_dist.GetFloat(), MASK_SHOT_PORTAL, tr);
10391

10492
// valid trace
10593
if (tr.plane.normal.Length() > 0.9) {

src/Features/Routing/SeamshotFind.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "Modules/Client.hpp"
99
#include "Modules/Console.hpp"
1010
#include "Modules/Engine.hpp"
11-
#include "Modules/Server.hpp"
1211
#include "Variable.hpp"
1312

1413
Variable sar_seamshot_finder("sar_seamshot_finder", "0", 0, 1, "Enables or disables seamshot finder overlay.\n");
@@ -33,9 +32,9 @@ CGameTrace TracePortalShot(const Vector &start, const Vector &dir, float length)
3332
ray.m_Extents = VectorAligned();
3433

3534
CTraceFilterSimple filter;
36-
filter.SetPassEntity(server->GetPlayer(GET_SLOT() + 1));
35+
filter.SetPassEntity(client->GetPlayer(GET_SLOT() + 1));
3736

38-
engine->TraceRay(engine->engineTrace->ThisPtr(), ray, MASK_SHOT_PORTAL, &filter, &tr);
37+
engine->TraceRayClient(engine->engineTraceClient->ThisPtr(), ray, MASK_SHOT_PORTAL, &filter, &tr);
3938

4039
//hack
4140
if (ray.m_Start.y == start.y) {
@@ -46,7 +45,7 @@ CGameTrace TracePortalShot(const Vector &start, const Vector &dir, float length)
4645

4746
ON_EVENT(RENDER) {
4847
if (sv_cheats.GetBool() && sar_seamshot_finder.GetBool()) {
49-
void *player = server->GetPlayer(GET_SLOT() + 1);
48+
void *player = client->GetPlayer(GET_SLOT() + 1);
5049

5150
if (player == nullptr || (int)player == -1)
5251
return;

0 commit comments

Comments
 (0)