Skip to main content

scs_sdk_sys/
telemetry.rs

1use core::ffi::c_void;
2use core::mem::{offset_of, size_of};
3
4use crate::{
5    ScsContext, ScsEvent, ScsLogType, ScsNamedValue, ScsResult, ScsString, ScsTimestamp, ScsU32,
6    ScsValue, ScsValueType,
7};
8
9pub type ScsLog = unsafe extern "system" fn(log_type: ScsLogType, message: ScsString);
10
11pub type ScsTelemetryEventCallback =
12    unsafe extern "system" fn(event: ScsEvent, event_info: *const c_void, context: ScsContext);
13
14pub type ScsTelemetryChannelCallback = unsafe extern "system" fn(
15    name: ScsString,
16    index: ScsU32,
17    value: *const ScsValue,
18    context: ScsContext,
19);
20
21pub type ScsTelemetryRegisterForEvent = unsafe extern "system" fn(
22    event: ScsEvent,
23    callback: ScsTelemetryEventCallback,
24    context: ScsContext,
25) -> ScsResult;
26
27pub type ScsTelemetryUnregisterFromEvent = unsafe extern "system" fn(event: ScsEvent) -> ScsResult;
28
29pub type ScsTelemetryRegisterForChannel = unsafe extern "system" fn(
30    name: ScsString,
31    index: ScsU32,
32    type_: ScsValueType,
33    flags: ScsU32,
34    callback: ScsTelemetryChannelCallback,
35    context: ScsContext,
36) -> ScsResult;
37
38pub type ScsTelemetryUnregisterFromChannel =
39    unsafe extern "system" fn(name: ScsString, index: ScsU32, type_: ScsValueType) -> ScsResult;
40
41#[repr(C)]
42pub struct ScsSdkInitParamsV100 {
43    pub game_name: ScsString,
44    pub game_id: ScsString,
45    pub game_version: ScsU32,
46    pub padding: crate::ScsPadding,
47    pub log: ScsLog,
48}
49
50#[repr(C)]
51pub struct ScsTelemetryInitParams {
52    _private: [u8; 0],
53}
54
55// The C++ base class is empty and uses the empty-base optimization, so the common
56// fields begin at offset zero in the concrete v1.00/v1.01 parameter structure.
57#[repr(C)]
58pub struct ScsTelemetryInitParamsV100 {
59    pub common: ScsSdkInitParamsV100,
60    pub register_for_event: ScsTelemetryRegisterForEvent,
61    pub unregister_from_event: ScsTelemetryUnregisterFromEvent,
62    pub register_for_channel: ScsTelemetryRegisterForChannel,
63    pub unregister_from_channel: ScsTelemetryUnregisterFromChannel,
64}
65
66pub type ScsTelemetryInitParamsV101 = ScsTelemetryInitParamsV100;
67
68#[repr(C)]
69#[derive(Clone, Copy)]
70pub struct ScsTelemetryFrameStart {
71    pub flags: ScsU32,
72    pub padding: crate::ScsPadding,
73    pub render_time: ScsTimestamp,
74    pub simulation_time: ScsTimestamp,
75    pub paused_simulation_time: ScsTimestamp,
76}
77
78#[repr(C)]
79pub struct ScsTelemetryConfiguration {
80    pub id: ScsString,
81    pub attributes: *const ScsNamedValue,
82}
83
84#[repr(C)]
85pub struct ScsTelemetryGameplayEvent {
86    pub id: ScsString,
87    pub attributes: *const ScsNamedValue,
88}
89
90const _: [(); 32] = [(); size_of::<ScsSdkInitParamsV100>()];
91const _: [(); 64] = [(); size_of::<ScsTelemetryInitParamsV100>()];
92const _: [(); 32] = [(); size_of::<ScsTelemetryFrameStart>()];
93const _: [(); 16] = [(); size_of::<ScsTelemetryConfiguration>()];
94const _: [(); 16] = [(); size_of::<ScsTelemetryGameplayEvent>()];
95
96const _: [(); 0] = [(); offset_of!(ScsSdkInitParamsV100, game_name)];
97const _: [(); 8] = [(); offset_of!(ScsSdkInitParamsV100, game_id)];
98const _: [(); 16] = [(); offset_of!(ScsSdkInitParamsV100, game_version)];
99const _: [(); 24] = [(); offset_of!(ScsSdkInitParamsV100, log)];
100const _: [(); 0] = [(); offset_of!(ScsTelemetryInitParamsV100, common)];
101const _: [(); 32] = [(); offset_of!(ScsTelemetryInitParamsV100, register_for_event)];
102const _: [(); 40] = [(); offset_of!(ScsTelemetryInitParamsV100, unregister_from_event)];
103const _: [(); 48] = [(); offset_of!(ScsTelemetryInitParamsV100, register_for_channel)];
104const _: [(); 56] = [(); offset_of!(ScsTelemetryInitParamsV100, unregister_from_channel)];