Skip to content

Commit 257d4f5

Browse files
committed
Implemeted modifiers in the script grammar.
* Added support for action flags 'once', 'toggled', 'accumulated'
1 parent 3024d7e commit 257d4f5

File tree

6 files changed

+140
-31
lines changed

6 files changed

+140
-31
lines changed

source/code/systems/input_action_system/private/input_action_dsl.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace ice
5050
{ "action", ice::grammar::UCT_Action },
5151
{ "active", ice::grammar::UCT_WhenActive },
5252
{ "activate", ice::grammar::UCT_StepActivate },
53+
{ "accumulated", ice::grammar::UCT_ActionFlagAccumulated },
5354
{ "deactivate", ice::grammar::UCT_StepDeactivate },
5455
{ "and", ice::grammar::UCT_WhenAnd },
5556
{ "axis1d", ice::grammar::UCT_InputTypeAxis1D },
@@ -65,16 +66,20 @@ namespace ice
6566
// { "gctrl", ice::grammar::UCT_InputBindingPad },
6667
{ "kb", ice::grammar::UCT_InputBindingKeyboard },
6768
{ "key", ice::grammar::UCT_InputBindingKeyboard },
68-
// { "keyboard", ice::grammar::UCT_InputBindingKeyboard },
69+
// { "keyboard", ice::grammar::UCT_InputBindingKeyboard },,
70+
{ "max", ice::grammar::UCT_ModifierOpMax },
71+
{ "min", ice::grammar::UCT_ModifierOpMin },
6972
{ "mouse", ice::grammar::UCT_InputBindingMouse },
7073
{ "mp", ice::grammar::UCT_InputBindingMouse },
7174
{ "gamepad", ice::grammar::UCT_InputBindingPad },
7275
{ "gp", ice::grammar::UCT_InputBindingPad },
7376
{ "layer", ice::grammar::UCT_Layer },
7477
{ "or", ice::grammar::UCT_WhenOr },
78+
{ "once", ice::grammar::UCT_ActionFlagOnce },
7579
{ "pressed", ice::grammar::UCT_WhenPressed },
7680
{ "released", ice::grammar::UCT_WhenReleased },
7781
{ "source", ice::grammar::UCT_Source },
82+
{ "toggled", ice::grammar::UCT_ActionFlagToggled },
7883
{ "when", ice::grammar::UCT_When },
7984
{ "reset", ice::grammar::UCT_StepReset },
8085
{ "series", ice::grammar::UCT_WhenFlagCheckSeries },

source/code/systems/input_action_system/private/input_action_dsl_grammar.hxx

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@ namespace ice::grammar
2929
static constexpr TokenType UCT_ActionTypeFloat1{ UCT_Base + 11 };
3030
static constexpr TokenType UCT_ActionTypeFloat2{ UCT_Base + 12 };
3131
static constexpr TokenType UCT_ActionTypeFloat3{ UCT_Base + 13 };
32-
static constexpr TokenType UCT_When{ UCT_Base + 14 };
33-
static constexpr TokenType UCT_WhenAnd{ UCT_Base + 15 };
34-
static constexpr TokenType UCT_WhenOr{ UCT_Base + 16 };
35-
static constexpr TokenType UCT_WhenPressed{ UCT_Base + 17 };
36-
static constexpr TokenType UCT_WhenReleased{ UCT_Base + 18 };
37-
static constexpr TokenType UCT_WhenActive{ UCT_Base + 19 };
38-
static constexpr TokenType UCT_WhenInactive{ UCT_Base + 20 };
39-
static constexpr TokenType UCT_WhenFlagCheckSeries{ UCT_Base + 21 };
40-
static constexpr TokenType UCT_StepActivate{ UCT_Base + 22 };
41-
static constexpr TokenType UCT_StepDeactivate{ UCT_Base + 23 };
42-
static constexpr TokenType UCT_StepReset{ UCT_Base + 24 };
43-
static constexpr TokenType UCT_Modifier{ UCT_Base + 25 };
32+
static constexpr TokenType UCT_ActionFlagOnce{ UCT_Base + 14 };
33+
static constexpr TokenType UCT_ActionFlagToggled{ UCT_Base + 15 };
34+
static constexpr TokenType UCT_ActionFlagAccumulated{ UCT_Base + 16 };
35+
static constexpr TokenType UCT_When{ UCT_Base + 17 };
36+
static constexpr TokenType UCT_WhenAnd{ UCT_Base + 18 };
37+
static constexpr TokenType UCT_WhenOr{ UCT_Base + 19 };
38+
static constexpr TokenType UCT_WhenPressed{ UCT_Base + 20 };
39+
static constexpr TokenType UCT_WhenReleased{ UCT_Base + 21 };
40+
static constexpr TokenType UCT_WhenActive{ UCT_Base + 22 };
41+
static constexpr TokenType UCT_WhenInactive{ UCT_Base + 23 };
42+
static constexpr TokenType UCT_WhenFlagCheckSeries{ UCT_Base + 24 };
43+
static constexpr TokenType UCT_StepActivate{ UCT_Base + 25 };
44+
static constexpr TokenType UCT_StepDeactivate{ UCT_Base + 26 };
45+
static constexpr TokenType UCT_StepReset{ UCT_Base + 27 };
46+
static constexpr TokenType UCT_Modifier{ UCT_Base + 28 };
47+
static constexpr TokenType UCT_ModifierOpMin{ UCT_Base + 29 };
48+
static constexpr TokenType UCT_ModifierOpMax{ UCT_Base + 30 };
4449

4550
static constexpr SyntaxRule Rule_ColonOrCommaRules[]{ // , or :
4651
SyntaxRule{ TokenType::CT_Colon },
@@ -219,13 +224,33 @@ namespace ice::grammar
219224
SyntaxRule{ UCT_WhenOr },
220225
};
221226

227+
static constexpr SyntaxRule Rule_LayerActionFlagsListRules[]{
228+
SyntaxRule{ UCT_ActionFlagOnce, &syntax::LayerAction::flag_once },
229+
SyntaxRule{ UCT_ActionFlagToggled, &syntax::LayerAction::flag_toggled },
230+
SyntaxRule{ UCT_ActionFlagAccumulated, &syntax::LayerAction::flag_accumulated },
231+
};
232+
233+
static constexpr SyntaxRule Rule_LayerActionFlagsRules[]{
234+
SyntaxRule{ grammar::TokenType::CT_Comma },
235+
SyntaxRule{ Rule_LayerActionFlagsListRules, MatchFirst }
236+
};
237+
238+
static constexpr SyntaxRule Rule_LayerActionWhenFlagsListRules[]{
239+
SyntaxRule{ UCT_WhenFlagCheckSeries, &syntax::LayerActionWhen::flag_series }
240+
};
241+
242+
static constexpr SyntaxRule Rule_LayerActionWhenFlagsRules[]{
243+
SyntaxRule{ grammar::TokenType::CT_Comma },
244+
SyntaxRule{ Rule_LayerActionWhenFlagsListRules, MatchFirst }
245+
};
246+
222247
static constexpr SyntaxRule Rule_LayerActionWhenRules[]{
223248
// Just to create the child node we need to succeed once.
224249
SyntaxRule{ [](auto const&, auto& ctx) noexcept{ return arctic::ParseState::Success; } }.noadvance(),
225250
SyntaxRule{ Rule_LayerActionWhenBlockRules, MatchFirst, &syntax::LayerActionWhen::type },
226251
SyntaxRule{ Rule_LayerActionWhenTargetRules, MatchAll },
227252
SyntaxRule{ Rule_LayerActionWhenTargetActionRules, MatchAll },
228-
SyntaxRule{ UCT_WhenFlagCheckSeries, &syntax::LayerActionWhen::check_series }.optional(),
253+
SyntaxRule{ Rule_LayerActionWhenFlagsRules, MatchAll }.optional(),
229254
SyntaxRule{ TokenType::ST_EndOfLine }.repeat(),
230255
SyntaxRule{ Rule_LayerActionStepRules, MatchChild<syntax::LayerActionStep> }.optional().repeat(),
231256
};
@@ -234,8 +259,25 @@ namespace ice::grammar
234259
// Action modifier rules
235260
////////////////////////////////////////////////////////////////
236261

262+
static constexpr SyntaxRule Rule_LayerActionModifierComponentRules[]{
263+
SyntaxRule{ TokenType::CT_Dot, &syntax::LayerActionModifier::component },
264+
SyntaxRule{ Rule_LayerActionComponentListRules, MatchFirst, &syntax::LayerActionModifier::component, arctic::SyntaxRule::store_value_extend<arctic::String> }
265+
};
266+
267+
static constexpr SyntaxRule Rule_LayerActionModifierOperationListRules[]{
268+
SyntaxRule{ TokenType::OP_Div },
269+
SyntaxRule{ TokenType::OP_Mul },
270+
SyntaxRule{ TokenType::OP_Plus },
271+
SyntaxRule{ TokenType::OP_Minus },
272+
SyntaxRule{ UCT_ModifierOpMin },
273+
SyntaxRule{ UCT_ModifierOpMax },
274+
};
275+
237276
static constexpr SyntaxRule Rule_LayerActionModifierRules[]{
238277
SyntaxRule{ UCT_Modifier },
278+
SyntaxRule{ Rule_LayerActionModifierComponentRules, MatchAll },
279+
SyntaxRule{ Rule_LayerActionModifierOperationListRules, MatchFirst, &syntax::LayerActionModifier::operation },
280+
SyntaxRule{ Rule_LayerActionWhenParamNumberTokenListRules, MatchFirst, &syntax::LayerActionModifier::param },
239281
SyntaxRule{ TokenType::ST_EndOfLine }.repeat(),
240282
};
241283

@@ -255,6 +297,7 @@ namespace ice::grammar
255297
SyntaxRule{ TokenType::CT_Symbol, &syntax::LayerAction::name },
256298
SyntaxRule{ TokenType::CT_Colon },
257299
SyntaxRule{ Rule_LayerActionTypeRules, MatchFirst, &syntax::LayerAction::type },
300+
SyntaxRule{ Rule_LayerActionFlagsRules, MatchAll }.optional(),
258301
SyntaxRule{ TokenType::ST_EndOfLine }.repeat(),
259302
SyntaxRule{ Rule_LayerActionWhenRules, MatchChild<syntax::LayerActionWhen> }.repeat().optional(),
260303
SyntaxRule{ Rule_LayerActionModifierRules, MatchChild<syntax::LayerActionModifier> }.repeat().optional(),

source/code/systems/input_action_system/private/input_action_dsl_layer_builder.cxx

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace ice
1616

1717
auto condition_from_dsl(arctic::Token token, bool action_condition) noexcept -> ice::InputActionCondition;
1818
auto step_from_dsl(arctic::Token token) noexcept -> ice::InputActionStep;
19+
auto modifier_from_dsl(arctic::Token token) noexcept -> ice::InputActionModifier;
1920

2021
} // namespace detail
2122

@@ -96,13 +97,28 @@ namespace ice
9697
void InputActionDSLLayerBuilder::visit(arctic::SyntaxNode<ice::syntax::LayerAction> node) noexcept
9798
{
9899
ice::InputActionData action_datatype = InputActionData::Bool;
99-
if (node.data().type.type == ice::grammar::UCT_ActionTypeFloat2)
100+
ice::syntax::LayerAction const& action_info = node.data();
101+
if (action_info.type.type == ice::grammar::UCT_ActionTypeFloat2)
100102
{
101103
action_datatype = InputActionData::Float2;
102104
}
103105

104-
ICE_LOG(LogSeverity::Info, LogTag::Engine, "Action: {}", node.data().name);
105-
ice::InputActionLayerBuilder::ActionBuilder action = _builder->define_action(node.data().name, action_datatype);
106+
ICE_LOG(LogSeverity::Info, LogTag::Engine, "Action: {}", action_info.name);
107+
ice::InputActionLayerBuilder::ActionBuilder action = _builder->define_action(action_info.name, action_datatype);
108+
ice::InputActionBehavior behavior = InputActionBehavior::Default;
109+
if (action_info.flag_once)
110+
{
111+
behavior = InputActionBehavior::ActiveOnce;
112+
}
113+
else if (action_info.flag_toggled)
114+
{
115+
behavior = InputActionBehavior::Toggled;
116+
}
117+
else if (action_info.flag_accumulated)
118+
{
119+
behavior = InputActionBehavior::Accumulated;
120+
}
121+
action.set_behavior(behavior);
106122

107123
arctic::SyntaxNode<> child = node.child();
108124
while(child != false)
@@ -121,6 +137,10 @@ namespace ice
121137
steps = steps.sibling();
122138
}
123139
}
140+
else if (child.type() == ice::syntax::SyntaxEntity_LayerActionModifier)
141+
{
142+
visit(action, child.to<ice::syntax::LayerActionModifier>());
143+
}
124144
child = child.sibling();
125145
}
126146
}
@@ -149,7 +169,7 @@ namespace ice
149169
{
150170
flags |= InputActionConditionFlags::RunSteps;
151171
}
152-
if (cond.check_series)
172+
if (cond.flag_series)
153173
{
154174
flags |= InputActionConditionFlags::SeriesCheck;
155175
}
@@ -171,7 +191,7 @@ namespace ice
171191
|| condition == Lower || condition == LowerOrEqual;
172192
if (is_param_condition)
173193
{
174-
param = ice::from_chars(cond.param.value, param);
194+
ice::from_chars(cond.param.value, param);
175195
}
176196

177197
action.add_condition(cond.source_name, condition, flags, param, from_action);
@@ -194,6 +214,23 @@ namespace ice
194214
}
195215
}
196216

217+
void InputActionDSLLayerBuilder::visit(
218+
ice::InputActionLayerBuilder::ActionBuilder& action,
219+
arctic::SyntaxNode<ice::syntax::LayerActionModifier> node
220+
) noexcept
221+
{
222+
ice::syntax::LayerActionModifier const& info = node.data();
223+
ice::InputActionModifier const modifier = detail::modifier_from_dsl(info.operation);
224+
225+
ice::f32 param_value = 0.0f;
226+
if (ice::from_chars(info.param, param_value) == false)
227+
{
228+
ICE_ASSERT_CORE(false);
229+
}
230+
231+
action.add_modifier(modifier, param_value, info.component);
232+
}
233+
197234
auto detail::key_from_dsl(arctic::String value) noexcept -> ice::input::KeyboardKey
198235
{
199236
using ice::input::KeyboardKey;
@@ -307,4 +344,19 @@ namespace ice
307344
return InputActionStep::Invalid;
308345
}
309346

347+
auto detail::modifier_from_dsl(arctic::Token token) noexcept -> ice::InputActionModifier
348+
{
349+
switch (token.type)
350+
{
351+
case grammar::UCT_ModifierOpMax: return InputActionModifier::Max;
352+
case arctic::TokenType::OP_Div: return InputActionModifier::Div;
353+
// Not implemented yet
354+
case grammar::UCT_ModifierOpMin:
355+
case arctic::TokenType::OP_Mul:
356+
case arctic::TokenType::OP_Plus:
357+
case arctic::TokenType::OP_Minus:
358+
default: ICE_ASSERT_CORE("Not Implemented!" && false); return InputActionModifier::Invalid;
359+
}
360+
}
361+
310362
} // namespace ice

source/code/systems/input_action_system/private/input_action_dsl_layer_builder.hxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace ice
1515
void visit(arctic::SyntaxNode<ice::syntax::Layer> node) noexcept override;
1616

1717
void visit(arctic::SyntaxNode<ice::syntax::LayerSource> node) noexcept;
18-
1918
void visit(arctic::SyntaxNode<ice::syntax::LayerAction> node) noexcept;
2019

2120
void visit(
@@ -28,6 +27,11 @@ namespace ice
2827
arctic::SyntaxNode<ice::syntax::LayerActionStep> node
2928
) noexcept;
3029

30+
void visit(
31+
ice::InputActionLayerBuilder::ActionBuilder& action,
32+
arctic::SyntaxNode<ice::syntax::LayerActionModifier> node
33+
) noexcept;
34+
3135
auto finalize(ice::Allocator& alloc) noexcept { return _builder->finalize(alloc); }
3236

3337
private:

source/code/systems/input_action_system/private/input_action_dsl_syntax_nodes.hxx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ namespace ice::syntax
5252

5353
arctic::String name;
5454
arctic::Token type;
55+
bool flag_toggled = false;
56+
bool flag_once = false;
57+
bool flag_accumulated = false;
5558
};
5659

5760
struct LayerActionWhen : SyntaxNodeData
@@ -65,7 +68,7 @@ namespace ice::syntax
6568
arctic::String source_component; // x/y/z
6669
arctic::Token condition; // .pressed/released/active/inactive/</>/==/>=/<=/!=
6770
arctic::Token param; // int/float
68-
bool check_series = false;
71+
bool flag_series = false;
6972
};
7073

7174
struct LayerActionStep : SyntaxNodeData
@@ -84,7 +87,9 @@ namespace ice::syntax
8487
static constexpr SyntaxEntity RepresentedSyntaxEntity = SyntaxEntity_LayerActionModifier;
8588
using SyntaxNodeData::SyntaxNodeData;
8689

87-
arctic::String name;
90+
arctic::String component;
91+
arctic::Token operation;
92+
arctic::String param;
8893
};
8994

9095
} // namespace ice::syntax

source/code/test/private/input_actions.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ namespace ice
111111
112112
// <symbol>[(.pressed)|.released|.active|.inactive|[.[x|y|z] [<|>|<=|>=|==|!=] <param:number>]]
113113
114-
action Jump: float1
114+
action Jump: float1, accumulated
115115
when Jump.released
116+
.x = Jump
116117
.deactivate
117-
.reset
118118
119119
when Jump.pressed
120-
.x = Jump
120+
.x + Jump
121121
.activate
122122
123-
mod
124-
mod
123+
mod .x / 60
124+
mod .x max 2
125125
126126
action Move: float2
127127
when Left.pressed
@@ -130,16 +130,16 @@ namespace ice
130130
.x + Right.x
131131
or Up.pressed
132132
.y + Up.x
133-
or Down.pressed series
133+
or Down.pressed, series
134134
.y - Down.x
135135
.activate
136136
137137
when .true // only executed if the previous condition series are not valid
138138
.reset
139139
140-
action Click: bool
141-
when Click.released
142-
.deactivate
140+
action Click: bool, once
141+
//when Click.released
142+
// .deactivate
143143
144144
when Click.pressed
145145
.x = Pos.x

0 commit comments

Comments
 (0)