1717namespace ice
1818{
1919
20- struct StandardInputActionLayerParams
20+ struct InputActionLayerInfo
2121 {
22+ ice::String name;
2223 ice::Span<ice::InputActionSourceInputInfo const > sources;
2324 ice::Span<ice::InputActionInfo const > actions;
2425 ice::Span<ice::InputActionConditionData const > conditions;
@@ -27,30 +28,37 @@ namespace ice
2728 ice::String strings;
2829 };
2930
30- auto params_from_data (ice::Data memory) noexcept -> ice::Expected<ice::StandardInputActionLayerParams>
31+ template <typename T>
32+ auto load_field_from_data (ice::Span<T const >& out_span, ice::Data data, ice::usize offset, ice::ucount count) noexcept
3133 {
32- ice::InputActionLayerInfo const * layer_info = reinterpret_cast <ice::InputActionLayerInfo const *>(memory.location );
33- if (layer_info == nullptr )
34+ out_span = ice::span::from_data<T>(data, count, offset);
35+ return ice::span::data_view (out_span).size ;
36+ }
37+
38+ auto load_from_data (ice::Data data) noexcept -> ice::Expected<ice::InputActionLayerInfo>
39+ {
40+ if (data.location == nullptr )
3441 {
35- return E_Fail ;
42+ return E_NullPointerData ;
3643 }
3744
38- ice::usize offset = ice::size_of<ice::InputActionLayerInfo>;
39- ice::StandardInputActionLayerParams result{};
40-
41- result.sources = ice::span::from_data<ice::InputActionSourceInputInfo>(memory, layer_info->count_sources , offset);
42- offset += ice::span::data_view (result.sources ).size ;
43- result.actions = ice::span::from_data<ice::InputActionInfo>(memory, layer_info->count_actions , offset);
44- offset += ice::span::data_view (result.actions ).size ;
45- result.conditions = ice::span::from_data<ice::InputActionConditionData>(memory, layer_info->count_conditions , offset);
46- offset += ice::span::data_view (result.conditions ).size ;
47- result.steps = ice::span::from_data<ice::InputActionStepData>(memory, layer_info->count_steps , offset);
48- offset += ice::span::data_view (result.steps ).size ;
49- result.modifiers = ice::span::from_data<ice::InputActionModifierData>(memory, layer_info->count_modifiers , offset);
50- offset += ice::span::data_view (result.modifiers ).size ;
51-
52- ICE_ASSERT_CORE (offset == ice::usize{ layer_info->offset_strings });
53- result.strings = ice::string::from_data (memory, { layer_info->offset_strings }, ice::ucount (memory.size .value - layer_info->offset_strings ));
45+ ice::InputActionLayerInfoHeader const & header = *reinterpret_cast <ice::InputActionLayerInfoHeader const *>(data.location );
46+ ice::usize offset = ice::size_of<ice::InputActionLayerInfoHeader>;
47+
48+ ice::InputActionLayerInfo result{};
49+ offset += load_field_from_data (result.sources , data, offset, header.count_sources );
50+ offset += load_field_from_data (result.actions , data, offset, header.count_actions );
51+ offset += load_field_from_data (result.conditions , data, offset, header.count_conditions );
52+ offset += load_field_from_data (result.steps , data, offset, header.count_steps );
53+ offset += load_field_from_data (result.modifiers , data, offset, header.count_modifiers );
54+
55+ ICE_ASSERT_CORE (offset == ice::usize{ header.offset_strings });
56+ result.strings = ice::string::from_data (
57+ data,
58+ ice::usize{ header.offset_strings },
59+ ice::ucount ( data.size .value - header.offset_strings )
60+ );
61+ result.name = ice::string::substr (result.strings , 0 , header.size_name );
5462 return result;
5563 }
5664
@@ -60,21 +68,18 @@ namespace ice
6068 StandardInputActionLayer (
6169 ice::Allocator& alloc,
6270 ice::Memory memory,
63- ice::StandardInputActionLayerParams const & params
71+ ice::InputActionLayerInfo const & info
6472 ) noexcept
6573 : _allocator{ alloc }
6674 , _rawdata{ memory }
67- , _sources{ params.sources }
68- , _actions{ params.actions }
69- , _conditions{ params.conditions }
70- , _steps{ params.steps }
71- , _modifiers{ params.modifiers }
72- , _strings{ params.strings }
73- , _runtime_sources{ alloc }
74- {
75- ice::array::resize (_runtime_sources, ice::count (_sources));
76- ice::array::memset (_runtime_sources, 0 );
77- }
75+ , _name{ info.name }
76+ , _sources{ info.sources }
77+ , _actions{ info.actions }
78+ , _conditions{ info.conditions }
79+ , _steps{ info.steps }
80+ , _modifiers{ info.modifiers }
81+ , _strings{ info.strings }
82+ { }
7883
7984 ~StandardInputActionLayer () noexcept override
8085 {
@@ -83,7 +88,7 @@ namespace ice
8388
8489 auto name () const noexcept -> ice::String override
8590 {
86- return " Default " ;
91+ return _name ;
8792 }
8893
8994 auto sources () const noexcept -> ice::Span<ice::InputActionSourceInputInfo const > override
@@ -106,14 +111,15 @@ namespace ice
106111 return ice::string::substr (_strings, action.name );
107112 }
108113
109- bool process_inputs (
110- ice::Span<ice::input::InputEvent const > input_events,
114+ auto process_inputs (
115+ ice::Span<ice::input::InputEvent> input_events,
111116 ice::Span<ice::InputActionSource* const > source_values
112- ) const noexcept override
117+ ) const noexcept -> ice::ucount override
113118 {
114119 IPT_ZONE_SCOPED;
115120
116121 ice::ucount event_index = 0 ;
122+ ice::ucount processed_count = 0 ;
117123 ice::ucount const event_count = ice::count (input_events);
118124
119125 while (event_index < event_count)
@@ -170,20 +176,15 @@ namespace ice
170176 };
171177 }
172178
173- // ICE_LOG(LogSeverity::Debug, LogTag::Engine, "SRC: '{}', VAL = {}", ice::string::substr(_strings, src.name_offset, src.name_length), value.value);
174-
175- // Remove the processed input
176- // if (ice::exchange(removed, true) == false)
177- // {
178- // ice::array::remove_at(inputs, index);
179- // count -= 1;
180- // }
179+ // Clear the processed event
180+ input_events[event_index] = ice::input::InputEvent{};
181+ processed_count += 1 ;
181182 }
182183
183184 event_index += 1 ;
184185 }
185186
186- return event_count != ice::count (input_events) ;
187+ return processed_count ;
187188 }
188189
189190 bool update_actions (
@@ -366,14 +367,13 @@ namespace ice
366367 ice::Allocator& _allocator;
367368 ice::Memory _rawdata;
368369
370+ ice::String _name;
369371 ice::Span<ice::InputActionSourceInputInfo const > _sources;
370372 ice::Span<ice::InputActionInfo const > _actions;
371373 ice::Span<ice::InputActionConditionData const > _conditions;
372374 ice::Span<ice::InputActionStepData const > _steps;
373375 ice::Span<ice::InputActionModifierData const > _modifiers;
374376 ice::String _strings;
375-
376- ice::Array<ice::InputActionSource> _runtime_sources;
377377 };
378378
379379 auto create_input_action_layer (
@@ -384,7 +384,7 @@ namespace ice
384384 ice::Memory const data_copy = alloc.allocate ({ layer_data.size , layer_data.alignment });
385385 ice::memcpy (data_copy, layer_data);
386386
387- ice::Expected<ice::StandardInputActionLayerParams > params = ice::params_from_data (ice::data_view (data_copy));
387+ ice::Expected<ice::InputActionLayerInfo > params = ice::load_from_data (ice::data_view (data_copy));
388388 if (params.succeeded () == false )
389389 {
390390 return {};
@@ -398,7 +398,7 @@ namespace ice
398398 ice::Memory layer_data
399399 ) noexcept -> ice::UniquePtr<ice::InputActionLayer>
400400 {
401- ice::Expected<ice::StandardInputActionLayerParams > params = ice::params_from_data (ice::data_view (layer_data));
401+ ice::Expected<ice::InputActionLayerInfo > params = ice::load_from_data (ice::data_view (layer_data));
402402 if (params.succeeded () == false )
403403 {
404404 return {};
@@ -412,7 +412,7 @@ namespace ice
412412 ice::String definition
413413 ) noexcept -> ice::UniquePtr<ice::InputActionLayer>
414414 {
415- InputActionDSLLayerBuilder dsl_builder{ ice::create_input_action_layer_builder (alloc) };
415+ InputActionDSLLayerBuilder dsl_builder{ ice::create_input_action_layer_builder (alloc, " " ) };
416416 if (ice::parse_action_input_definition (definition, dsl_builder))
417417 {
418418 return dsl_builder.finalize (alloc);
0 commit comments