1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use std::io::{Result as Res};

use endio::{Deserialize, Serialize};
use endio_bit::BEBitWriter;
use lu_packets_derive::{BitVariantTests, ReplicaSerde};

use crate::world::{Vector3, Quaternion};
use super::{ComponentConstruction, ComponentProtocol, ComponentSerialization};
use super::controllable_physics::{LocalSpaceInfo};

#[derive(Debug, Deserialize, PartialEq, Serialize)]
#[repr(u8)]
pub enum EndOfRaceBehaviorType {
	DriveStraight,
	StopStraight,
	SlideLeft,
	SlideRight,
	Do360Left,
	Do360Right,
	TwoWheels,
	Jump,
}

#[derive(Debug, PartialEq, ReplicaSerde)]
pub struct RemoteInputInfo {
	pub remote_input_x: f32,
	pub remote_input_y: f32,
	pub do_powerslide: bool,
	pub is_modified: bool,
}

#[derive(Debug, PartialEq, ReplicaSerde)]
pub struct VehicleFrameStats {
	pub position: Vector3,
	pub rotation: Quaternion,
	pub is_on_ground: bool,
	pub is_on_rail: bool,
	pub linear_velocity: Option<Vector3>,
	pub angular_velocity: Option<Vector3>,
	pub local_space_info: Option<LocalSpaceInfo>,
	pub remote_input_info: Option<RemoteInputInfo>,
	pub remote_input_ping: f32,
}

#[derive(BitVariantTests, Debug, PartialEq, ReplicaSerde)]
pub struct VehiclePhysicsConstruction {
	pub vehicle_frame_stats: Option<VehicleFrameStats>,
	pub end_of_race_behavior_type: EndOfRaceBehaviorType,
	pub is_input_locked: bool,
	pub wheel_lock_extra_friction: Option<bool>,
}

#[derive(Debug, PartialEq, ReplicaSerde)]
pub struct VehicleFrameStatsTeleportInfo {
	pub vehicle_frame_stats: VehicleFrameStats,
	pub is_teleporting: bool,
}

#[derive(BitVariantTests, Debug, PartialEq, ReplicaSerde)]
pub struct VehiclePhysicsSerialization {
	pub vehicle_frame_stats_teleport_info: Option<VehicleFrameStatsTeleportInfo>,
	pub wheel_lock_extra_friction: Option<bool>,
}

impl ComponentConstruction for VehiclePhysicsConstruction {
	fn ser(&self, writer: &mut BEBitWriter<Vec<u8>>) -> Res<()> {
		self.serialize(writer)
	}
}

impl ComponentSerialization for VehiclePhysicsSerialization {
	fn ser(&self, writer: &mut BEBitWriter<Vec<u8>>) -> Res<()> {
		self.serialize(writer)
	}
}

pub struct VehiclePhysicsProtocol;

impl ComponentProtocol for VehiclePhysicsProtocol {
	type Construction = VehiclePhysicsConstruction;
	type Serialization = VehiclePhysicsSerialization;
}