VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Trace.hpp
Go to the documentation of this file.
1#pragma once
2
9
10namespace VoltMod
11{
12
13/** Which interaction layers a trace stops at. */
14enum class TraceLayers
15{
16 Sight, ///< what hides one player from another
17 Solid, ///< what a player body collides with, players included
18 Surfaces, ///< every drawn surface and the sky; no player clips or players
19};
20
22{
26 /** Also skips everything this entity owns; see @ref PropSpec::Owner. */
28};
29
31{
32 bool Hit = false; ///< also true when the start is inside a solid
33 float Fraction = 1.0f; ///< share of the path travelled
35 Vector Normal; ///< zero without a hit
36 EntityRef HitEntity; ///< the world included
37 bool HitWorld = false;
38};
39
40/**
41 * @brief `runtime.Trace`: line and box traces against the physics world. Game-thread only.
42 *
43 * @code
44 * const auto clear = runtime.Trace.Clear(eye, target, {.Ignore1 = self, .Ignore2 = other});
45 * if (clear && *clear)
46 * ...
47 * @endcode
48 */
49class Trace
50{
51public:
52 /** @p bindings must outlive this service. */
53 explicit Trace(const Bindings& bindings) : _bindings(bindings) {}
54 Trace(const Trace&) = delete;
55 Trace& operator=(const Trace&) = delete;
56
57 /** Unsupported when the Nav_TraceLine slot did not bind. */
58 Status Available() const;
59
60 Result<TraceHit> Line(const Vector& from, const Vector& to, const TraceOptions& options = {}) const;
61
62 /** Sweeps @p mins..@p maxs along the path; `End` is the box origin. Unsupported when the
63 * Nav_TraceShape slot did not bind. */
64 Result<TraceHit> Box(const Vector& from, const Vector& to, const Vector& mins, const Vector& maxs,
65 const TraceOptions& options = {}) const;
66
67 /** Along @p pawn's aim, ignoring the pawn. */
69
70 Result<bool> Clear(const Vector& from, const Vector& to, const TraceOptions& options = {}) const;
71
72private:
73 const Bindings& _bindings;
74};
75
76} // namespace VoltMod
A live entity, valid for this frame only.
Definition Entity.hpp:29
runtime.Trace: line and box traces against the physics world. Game-thread only.
Definition Trace.hpp:50
Result< TraceHit > Line(const Vector &from, const Vector &to, const TraceOptions &options={}) const
Definition Trace.cpp:76
Result< TraceHit > Box(const Vector &from, const Vector &to, const Vector &mins, const Vector &maxs, const TraceOptions &options={}) const
Definition Trace.cpp:91
Trace(const Bindings &bindings)
Definition Trace.hpp:53
Result< bool > Clear(const Vector &from, const Vector &to, const TraceOptions &options={}) const
Definition Trace.cpp:113
Status Available() const
Definition Trace.cpp:67
Trace & operator=(const Trace &)=delete
Result< TraceHit > FromEyes(const Pawn &pawn, float distance, TraceLayers layers=TraceLayers::Solid) const
Definition Trace.cpp:107
Trace(const Trace &)=delete
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
::Vector Vector
Definition Math.hpp:11
TraceLayers
Definition Trace.hpp:15
@ Sight
what hides one player from another
@ Surfaces
every drawn surface and the sky; no player clips or players
@ Solid
what a player body collides with, players included
std::expected< T, Error > Result
Definition Result.hpp:64
Vector Normal
zero without a hit
Definition Trace.hpp:35
EntityRef HitEntity
the world included
Definition Trace.hpp:36
float Fraction
share of the path travelled
Definition Trace.hpp:33
bool Hit
also true when the start is inside a solid
Definition Trace.hpp:32
TraceLayers Layers
Definition Trace.hpp:23