Skip to main content

scs_sdk_sys/
input.rs

1//! Raw ABI declarations for the SCS Input SDK 1.00 interface.
2//!
3//! These definitions mirror `scssdk_input.h`, `scssdk_input_device.h`,
4//! `scssdk_input_event.h`, and the ETS2/ATS input-version headers from the
5//! official SDK 1.14 distribution. The input API was introduced by SDK 1.14;
6//! none of the official SDK 1.0 through 1.13 archives contain these headers.
7
8use core::mem::{offset_of, size_of};
9
10use crate::{
11    ScsContext, ScsPadding, ScsResult, ScsSdkInitParamsV100, ScsString, ScsU8, ScsU32,
12    ScsValueBool, ScsValueFloat, ScsValueType, make_version,
13};
14
15/// Initial and current input API version declared by SDK 1.14.
16pub const SCS_INPUT_VERSION_1_00: ScsU32 = make_version(1, 0);
17/// Latest input API version declared by SDK 1.14.
18pub const SCS_INPUT_VERSION_CURRENT: ScsU32 = SCS_INPUT_VERSION_1_00;
19
20/// Initial and current ETS2 game version for the input API.
21pub const SCS_INPUT_EUT2_GAME_VERSION_1_00: ScsU32 = make_version(1, 0);
22/// Latest ETS2 input game version declared by SDK 1.14.
23pub const SCS_INPUT_EUT2_GAME_VERSION_CURRENT: ScsU32 = SCS_INPUT_EUT2_GAME_VERSION_1_00;
24
25/// Initial and current ATS game version for the input API.
26pub const SCS_INPUT_ATS_GAME_VERSION_1_00: ScsU32 = make_version(1, 0);
27/// Latest ATS input game version declared by SDK 1.14.
28pub const SCS_INPUT_ATS_GAME_VERSION_CURRENT: ScsU32 = SCS_INPUT_ATS_GAME_VERSION_1_00;
29
30/// Raw discriminator used by `scs_input_device_t::type`.
31pub type ScsInputDeviceType = ScsU32;
32
33pub const SCS_INPUT_DEVICE_TYPE_INVALID: ScsInputDeviceType = 0;
34pub const SCS_INPUT_DEVICE_TYPE_GENERIC: ScsInputDeviceType = 1;
35pub const SCS_INPUT_DEVICE_TYPE_SEMANTICAL: ScsInputDeviceType = 2;
36
37/// Maximum number of inputs accepted for one registered device.
38pub const SCS_INPUT_MAX_INPUT_COUNT: ScsU32 = 400;
39
40pub const SCS_INPUT_EVENT_CALLBACK_FLAG_FIRST_IN_FRAME: ScsU32 = 0x0000_0001;
41pub const SCS_INPUT_EVENT_CALLBACK_FLAG_FIRST_AFTER_ACTIVATION: ScsU32 = 0x0000_0002;
42
43/// Opaque common ancestor used by the loader-facing input init function.
44#[repr(C)]
45pub struct ScsInputInitParams {
46    _private: [u8; 0],
47}
48
49/// Information about one bool or float input exposed by a device.
50#[repr(C)]
51pub struct ScsInputDeviceInput {
52    pub name: ScsString,
53    pub display_name: ScsString,
54    pub value_type: ScsValueType,
55    pub padding: ScsPadding,
56}
57
58/// Callback used by SCS to notify a device that it became active or inactive.
59pub type ScsInputActiveCallback = unsafe extern "system" fn(active: ScsU8, context: ScsContext);
60
61/// Storage written by the plugin when SCS asks for the next input event.
62#[repr(C)]
63#[derive(Clone, Copy)]
64pub union ScsInputEventValue {
65    pub value_bool: ScsValueBool,
66    pub value_float: ScsValueFloat,
67    pub sizing_for_future_extensions: [f32; 6],
68}
69
70/// One event returned by an input device callback.
71#[repr(C)]
72#[derive(Clone, Copy)]
73pub struct ScsInputEvent {
74    pub input_index: ScsU32,
75    pub value: ScsInputEventValue,
76}
77
78/// Callback repeatedly invoked by SCS until it returns `SCS_RESULT_NOT_FOUND`.
79pub type ScsInputEventCallback = unsafe extern "system" fn(
80    event_info: *mut ScsInputEvent,
81    flags: ScsU32,
82    context: ScsContext,
83) -> ScsResult;
84
85/// Raw input-device registration structure.
86#[repr(C)]
87pub struct ScsInputDevice {
88    pub name: ScsString,
89    pub display_name: ScsString,
90    pub type_: ScsInputDeviceType,
91    pub input_count: ScsU32,
92    pub inputs: *const ScsInputDeviceInput,
93    pub callback_context: ScsContext,
94    pub input_active_callback: Option<ScsInputActiveCallback>,
95    pub input_event_callback: ScsInputEventCallback,
96}
97
98/// Function supplied by SCS for registering one input device during init.
99pub type ScsInputRegisterDevice =
100    unsafe extern "system" fn(device_info: *const ScsInputDevice) -> ScsResult;
101
102/// Initialization parameters for input API 1.00.
103#[repr(C)]
104pub struct ScsInputInitParamsV100 {
105    pub common: ScsSdkInitParamsV100,
106    pub register_device: ScsInputRegisterDevice,
107}
108
109const _: [(); 24] = [(); size_of::<ScsInputDeviceInput>()];
110const _: [(); 24] = [(); size_of::<ScsInputEventValue>()];
111const _: [(); 28] = [(); size_of::<ScsInputEvent>()];
112const _: [(); 56] = [(); size_of::<ScsInputDevice>()];
113const _: [(); 40] = [(); size_of::<ScsInputInitParamsV100>()];
114
115const _: [(); 0] = [(); offset_of!(ScsInputDeviceInput, name)];
116const _: [(); 8] = [(); offset_of!(ScsInputDeviceInput, display_name)];
117const _: [(); 16] = [(); offset_of!(ScsInputDeviceInput, value_type)];
118const _: [(); 20] = [(); offset_of!(ScsInputDeviceInput, padding)];
119const _: [(); 4] = [(); offset_of!(ScsInputEvent, value)];
120const _: [(); 0] = [(); offset_of!(ScsInputDevice, name)];
121const _: [(); 8] = [(); offset_of!(ScsInputDevice, display_name)];
122const _: [(); 16] = [(); offset_of!(ScsInputDevice, type_)];
123const _: [(); 20] = [(); offset_of!(ScsInputDevice, input_count)];
124const _: [(); 24] = [(); offset_of!(ScsInputDevice, inputs)];
125const _: [(); 32] = [(); offset_of!(ScsInputDevice, callback_context)];
126const _: [(); 40] = [(); offset_of!(ScsInputDevice, input_active_callback)];
127const _: [(); 48] = [(); offset_of!(ScsInputDevice, input_event_callback)];
128const _: [(); 0] = [(); offset_of!(ScsInputInitParamsV100, common)];
129const _: [(); 32] = [(); offset_of!(ScsInputInitParamsV100, register_device)];
130
131#[cfg(test)]
132mod tests {
133    use super::*;
134
135    #[test]
136    fn input_constants_match_the_sdk_1_14_headers() {
137        assert_eq!(SCS_INPUT_VERSION_CURRENT, make_version(1, 0));
138        assert_eq!(SCS_INPUT_EUT2_GAME_VERSION_CURRENT, make_version(1, 0));
139        assert_eq!(SCS_INPUT_ATS_GAME_VERSION_CURRENT, make_version(1, 0));
140        assert_eq!(SCS_INPUT_MAX_INPUT_COUNT, 400);
141        assert_eq!(SCS_INPUT_DEVICE_TYPE_GENERIC, 1);
142        assert_eq!(SCS_INPUT_DEVICE_TYPE_SEMANTICAL, 2);
143    }
144}