PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
first_person_pawn_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 bool primary = true;
13 float move_speed = 4.5f;
14 float sprint_multiplier = 1.75f;
15 float eye_height = 1.6f;
16 float min_pitch_degrees = -85.0f;
17 float max_pitch_degrees = 85.0f;
18
19 [[nodiscard]] bool operator==(const FirstPersonPawnComponent&) const noexcept = default;
20};
21
22inline Node& operator<<(Node& node, const FirstPersonPawnComponent& component)
23{
24 node["enabled"] << component.enabled;
25 node["primary"] << component.primary;
26 node["moveSpeed"] << component.move_speed;
27 node["sprintMultiplier"] << component.sprint_multiplier;
28 node["eyeHeight"] << component.eye_height;
29 node["minPitchDegrees"] << component.min_pitch_degrees;
30 node["maxPitchDegrees"] << component.max_pitch_degrees;
31 return node;
32}
33
34inline const Node& operator>>(const Node& node, FirstPersonPawnComponent& component)
35{
36 if (node.HasProperty("enabled"))
37 {
38 node["enabled"] >> component.enabled;
39 }
40 if (node.HasProperty("primary"))
41 {
42 node["primary"] >> component.primary;
43 }
44 if (node.HasProperty("moveSpeed"))
45 {
46 node["moveSpeed"] >> component.move_speed;
47 }
48 if (node.HasProperty("sprintMultiplier"))
49 {
50 node["sprintMultiplier"] >> component.sprint_multiplier;
51 }
52 if (node.HasProperty("eyeHeight"))
53 {
54 node["eyeHeight"] >> component.eye_height;
55 }
56 if (node.HasProperty("minPitchDegrees"))
57 {
58 node["minPitchDegrees"] >> component.min_pitch_degrees;
59 }
60 if (node.HasProperty("maxPitchDegrees"))
61 {
62 node["maxPitchDegrees"] >> component.max_pitch_degrees;
63 }
64 component.move_speed = std::max(component.move_speed, 0.0f);
65 component.sprint_multiplier = std::max(component.sprint_multiplier, 1.0f);
66 component.eye_height = std::max(component.eye_height, 0.0f);
67 if (component.max_pitch_degrees < component.min_pitch_degrees)
68 {
69 std::swap(component.min_pitch_degrees, component.max_pitch_degrees);
70 }
71 return node;
72}
73} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:45
Definition first_person_pawn_component.h:10