PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
perception_sensor_component.h
1#pragma once
2
3#include "pixelbullet/serialization/node.h"
4
5#include <algorithm>
6
7namespace pixelbullet
8{
10{
11 bool enabled = true;
12 float range = 8.0f;
13 float horizontal_fov_degrees = 90.0f;
14 float eye_height = 1.6f;
15 float lose_sight_grace_seconds = 0.35f;
16 float chase_stop_distance = 0.75f;
17
18 [[nodiscard]] bool operator==(const PerceptionSensorComponent&) const noexcept = default;
19};
20
21inline Node& operator<<(Node& node, const PerceptionSensorComponent& component)
22{
23 node["enabled"] << component.enabled;
24 node["range"] << component.range;
25 node["horizontalFovDegrees"] << component.horizontal_fov_degrees;
26 node["eyeHeight"] << component.eye_height;
27 node["loseSightGraceSeconds"] << component.lose_sight_grace_seconds;
28 node["chaseStopDistance"] << component.chase_stop_distance;
29 return node;
30}
31
32inline const Node& operator>>(const Node& node, PerceptionSensorComponent& component)
33{
34 if (node.HasProperty("enabled"))
35 {
36 node["enabled"] >> component.enabled;
37 }
38 else
39 {
40 component.enabled = true;
41 }
42
43 if (node.HasProperty("range"))
44 {
45 node["range"] >> component.range;
46 }
47 else
48 {
49 component.range = 8.0f;
50 }
51
52 if (node.HasProperty("horizontalFovDegrees"))
53 {
54 node["horizontalFovDegrees"] >> component.horizontal_fov_degrees;
55 }
56 else
57 {
58 component.horizontal_fov_degrees = 90.0f;
59 }
60
61 if (node.HasProperty("eyeHeight"))
62 {
63 node["eyeHeight"] >> component.eye_height;
64 }
65 else
66 {
67 component.eye_height = 1.6f;
68 }
69
70 if (node.HasProperty("loseSightGraceSeconds"))
71 {
72 node["loseSightGraceSeconds"] >> component.lose_sight_grace_seconds;
73 }
74 else
75 {
76 component.lose_sight_grace_seconds = 0.35f;
77 }
78
79 if (node.HasProperty("chaseStopDistance"))
80 {
81 node["chaseStopDistance"] >> component.chase_stop_distance;
82 }
83 else
84 {
85 component.chase_stop_distance = 0.75f;
86 }
87
88 component.range = std::max(component.range, 0.0001f);
89 component.horizontal_fov_degrees = std::clamp(component.horizontal_fov_degrees, 1.0f, 359.0f);
90 component.eye_height = std::max(component.eye_height, 0.0f);
91 component.lose_sight_grace_seconds = std::max(component.lose_sight_grace_seconds, 0.0f);
92 component.chase_stop_distance = std::max(component.chase_stop_distance, 0.0f);
93 return node;
94}
95} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:45
Definition perception_sensor_component.h:10