Skip to content

Commit 035eae8

Browse files
committed
Started refactor of the InputAction script.
* Fixed deprecations of 'fmt::localtime'
1 parent e6765b6 commit 035eae8

File tree

11 files changed

+121
-78
lines changed

11 files changed

+121
-78
lines changed

source/code/core/utils/private/assert.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace ice::detail
5656
header_buffer_raw,
5757
128,
5858
LogFormat_AssertLineHeader,
59-
fmt::localtime(std::time(nullptr))
59+
ice::detail::local_time()
6060
);
6161

6262
if (LogState::minimal_header_length < format_result.size)

source/code/core/utils/private/log.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace ice::detail
9292
header_buffer_raw,
9393
256,
9494
fmt_string(LogFormat_LogLineHeader),
95-
fmt::localtime(std::time(nullptr)),
95+
ice::detail::local_time(),
9696
fmt_string(detail::severity_value[static_cast<ice::u32>(severity)]),
9797
fmt_string(base_tag_name),
9898
fmt_string(ice::string::empty(tag_name) || ice::string::empty(base_tag_name) ? "" : " | "),

source/code/core/utils/private/log_internal.hxx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <ice/log.hxx>
1111

1212
#include <fmt/format.h>
13+
#include <fmt/chrono.h>
1314

1415
namespace ice::detail
1516
{
@@ -136,4 +137,20 @@ namespace ice::detail
136137
"DEBG",
137138
};
138139

140+
#if ISP_WEBAPP || ISP_ANDROID
141+
auto local_time() noexcept -> std::tm
142+
{
143+
std::chrono::system_clock::time_point const now = std::chrono::system_clock::now();
144+
std::time_t const current_time = std::chrono::system_clock::to_time_t(now);
145+
std::tm const* localtime = std::localtime(&current_time);
146+
return *localtime;
147+
}
148+
#else
149+
auto local_time() noexcept
150+
{
151+
static auto const current_timezone = std::chrono::current_zone();
152+
return current_timezone->to_local(std::chrono::system_clock::now());
153+
}
154+
#endif
155+
139156
} // namespace ice::detail

source/code/core/utils/private/log_webasm.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#include <emscripten/console.h>
1212
#include <emscripten.h>
13-
#include <fmt/chrono.h>
1413
#include <fmt/core.h>
14+
#include <fmt/chrono.h>
1515

1616
namespace ice::detail::webasm
1717
{
@@ -74,7 +74,7 @@ namespace ice::detail::webasm
7474
header_buffer_raw,
7575
128,
7676
LogFormat_AssertLineHeader,
77-
fmt::localtime(std::time(nullptr))
77+
ice::detail::local_time()
7878
);
7979

8080
if (LogState::minimal_header_length < format_result.size)
@@ -160,7 +160,7 @@ namespace ice::detail::webasm
160160
header_buffer_raw,
161161
256,
162162
LogFormat_LogLineHeader,
163-
fmt::localtime(std::time(nullptr)),
163+
ice::detail::local_time(),
164164
fmt_string(detail::severity_value[static_cast<ice::u32>(severity)]),
165165
fmt_string(base_tag_name),
166166
fmt_string(ice::string::empty(tag_name) || ice::string::empty(base_tag_name) ? "" : " | "),

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,18 @@ namespace ice
4848
arctic::TokenType type;
4949
};
5050

51+
using TokenType = ice::asl::TokenType;
52+
5153
static constexpr ice::TokenInfo Constant_Tokens[]{
52-
{ "action", ice::grammar::UCT_Action },
54+
{ "action", TokenType::ASL_KW_Action },
5355
{ "active", ice::grammar::UCT_WhenActive },
5456
{ "activate", ice::grammar::UCT_StepActivate },
5557
//{ "accumulated", ice::grammar::UCT_ActionFlagAccumulated },
5658
{ "deactivate", ice::grammar::UCT_StepDeactivate },
5759
{ "and", ice::grammar::UCT_WhenAnd },
58-
{ "axis1d", ice::grammar::UCT_InputTypeAxis1D },
59-
{ "axis2d", ice::grammar::UCT_InputTypeAxis2D },
60-
{ "axis3d", ice::grammar::UCT_InputTypeAxis3D },
60+
{ "axis1d", TokenType::ASL_NT_Axis1D },
61+
{ "axis2d", TokenType::ASL_NT_Axis2D },
62+
{ "axis3d", TokenType::ASL_NT_Axis3D },
6163
{ "bool", ice::grammar::UCT_ActionTypeBool },
6264
{ "button", ice::grammar::UCT_InputTypeButton },
6365
{ "inactive", ice::grammar::UCT_WhenInactive },
@@ -77,13 +79,13 @@ namespace ice
7779
{ "mp", ice::grammar::UCT_InputBindingMouse },
7880
{ "gamepad", ice::grammar::UCT_InputBindingPad },
7981
{ "gp", ice::grammar::UCT_InputBindingPad },
80-
{ "layer", ice::grammar::UCT_Layer },
82+
{ "layer", TokenType::ASL_KW_Layer },
8183
{ "object", ice::grammar::UCT_ActionTypeObject },
8284
{ "or", ice::grammar::UCT_WhenOr },
8385
{ "once", ice::grammar::UCT_ActionFlagOnce },
8486
{ "pressed", ice::grammar::UCT_WhenPressed },
8587
{ "released", ice::grammar::UCT_WhenReleased },
86-
{ "source", ice::grammar::UCT_Source },
88+
{ "source", TokenType::ASL_KW_Source },
8789
{ "toggled", ice::grammar::UCT_ActionFlagToggled },
8890
{ "toggle", ice::grammar::UCT_StepToggle },
8991
{ "when", ice::grammar::UCT_When },

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,19 @@
1111
namespace ice
1212
{
1313

14-
struct ActionInputParserEvents;
15-
16-
bool parse_action_input_definition(
17-
ice::String definition,
18-
ice::ActionInputParserEvents& handler
19-
) noexcept;
20-
21-
using ActionInputParserEventsBase = arctic::SyntaxVisitorGroup<
22-
ice::syntax::Layer
23-
>;
24-
25-
struct ActionInputParserEvents : ice::ActionInputParserEventsBase
14+
struct ActionInputParserEvents : arctic::SyntaxVisitorGroup<ice::syntax::Layer>
2615
{
2716
void visit(arctic::SyntaxNode<> node) noexcept override final
2817
{
29-
ActionInputParserEventsBase::visit(node);
18+
SyntaxVisitorGroup::visit(node);
3019
}
3120

3221
void visit(arctic::SyntaxNode<ice::syntax::Layer> node) noexcept override = 0;
3322
};
3423

24+
bool parse_action_input_definition(
25+
ice::String definition,
26+
ice::ActionInputParserEvents& handler
27+
) noexcept;
28+
3529
} // namespace ice

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

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,20 @@
11
#pragma once
22
#include "input_action_dsl_syntax_nodes.hxx"
3+
#include "input_action_script_tokens.hxx"
34

45
#include <arctic/arctic_token.hxx>
56
#include <arctic/arctic_syntax_rule_matchers.hxx>
67

78
namespace ice::grammar
89
{
10+
using namespace ice::asl;
911

1012
using arctic::MatchAll;
1113
using arctic::MatchFirst;
1214
using arctic::MatchChild;
1315
using arctic::MatchSibling;
1416
using arctic::SyntaxRule;
15-
using arctic::TokenType;
16-
17-
static constexpr ice::u32 UCT_Base = static_cast<ice::u32>(TokenType::ST_Any) + 1;
18-
static constexpr TokenType UCT_Layer{ UCT_Base + 0 };
19-
static constexpr TokenType UCT_Source{ UCT_Base + 1 };
20-
static constexpr TokenType UCT_InputTypeButton{ UCT_Base + 2 };
21-
static constexpr TokenType UCT_InputTypeAxis1D{ UCT_Base + 3 };
22-
static constexpr TokenType UCT_InputTypeAxis2D{ UCT_Base + 4 };
23-
static constexpr TokenType UCT_InputTypeAxis3D{ UCT_Base + 5 };
24-
static constexpr TokenType UCT_InputBindingKeyboard{ UCT_Base + 6 };
25-
static constexpr TokenType UCT_InputBindingMouse{ UCT_Base + 7 };
26-
static constexpr TokenType UCT_InputBindingPad{ UCT_Base + 8 };
27-
static constexpr TokenType UCT_Action{ UCT_Base + 9 };
28-
static constexpr TokenType UCT_ActionTypeBool{ UCT_Base + 10 };
29-
static constexpr TokenType UCT_ActionTypeFloat1{ UCT_Base + 11 };
30-
static constexpr TokenType UCT_ActionTypeFloat2{ UCT_Base + 12 };
31-
static constexpr TokenType UCT_ActionTypeFloat3{ UCT_Base + 13 };
32-
static constexpr TokenType UCT_ActionTypeObject{ UCT_Base + 14 };
33-
static constexpr TokenType UCT_ActionFlagOnce{ UCT_Base + 15 };
34-
static constexpr TokenType UCT_ActionFlagToggled{ UCT_Base + 16 };
35-
//static constexpr TokenType UCT_ActionFlagAccumulated{ UCT_Base + 17 };
36-
static constexpr TokenType UCT_When{ UCT_Base + 18 };
37-
static constexpr TokenType UCT_WhenAnd{ UCT_Base + 19 };
38-
static constexpr TokenType UCT_WhenOr{ UCT_Base + 20 };
39-
static constexpr TokenType UCT_WhenPressed{ UCT_Base + 21 };
40-
static constexpr TokenType UCT_WhenReleased{ UCT_Base + 22 };
41-
static constexpr TokenType UCT_WhenActive{ UCT_Base + 23 };
42-
static constexpr TokenType UCT_WhenInactive{ UCT_Base + 24 };
43-
static constexpr TokenType UCT_WhenFlagCheckSeries{ UCT_Base + 25 };
44-
static constexpr TokenType UCT_StepActivate{ UCT_Base + 26 };
45-
static constexpr TokenType UCT_StepDeactivate{ UCT_Base + 27 };
46-
static constexpr TokenType UCT_StepToggle{ UCT_Base + 28 };
47-
static constexpr TokenType UCT_StepReset{ UCT_Base + 29 };
48-
static constexpr TokenType UCT_StepTime{ UCT_Base + 30 };
49-
static constexpr TokenType UCT_Modifier{ UCT_Base + 31 };
50-
static constexpr TokenType UCT_ModifierOpMin{ UCT_Base + 32 };
51-
static constexpr TokenType UCT_ModifierOpMax{ UCT_Base + 33 };
17+
//using TokenType = ::ice::asl::TokenType;
5218

5319
static constexpr SyntaxRule Rule_ColonOrCommaRules[]{ // , or :
5420
SyntaxRule{ TokenType::CT_Colon },
@@ -75,13 +41,13 @@ namespace ice::grammar
7541

7642
static constexpr SyntaxRule Rule_LayerInputTypeRules[]{ // button, axis1d, axis2d or axis3d
7743
SyntaxRule{ UCT_InputTypeButton },
78-
SyntaxRule{ UCT_InputTypeAxis1D },
79-
SyntaxRule{ UCT_InputTypeAxis2D },
80-
SyntaxRule{ UCT_InputTypeAxis3D },
44+
SyntaxRule{ TokenType::ASL_NT_Axis1D },
45+
SyntaxRule{ TokenType::ASL_NT_Axis2D },
46+
SyntaxRule{ TokenType::ASL_NT_Axis3D },
8147
};
8248

8349
static constexpr SyntaxRule Rule_LayerSourceRules[]{ // source <type> <name>: <binding>...
84-
SyntaxRule{ UCT_Source },
50+
SyntaxRule{ TokenType::ASL_KW_Source },
8551
SyntaxRule{ Rule_LayerInputTypeRules, MatchFirst, &syntax::LayerSource::type }, // TODO: Additional types
8652
SyntaxRule{ TokenType::CT_Symbol, &syntax::LayerSource::name },
8753
SyntaxRule{ TokenType::CT_Colon }.noadvance().optional(),
@@ -116,8 +82,8 @@ namespace ice::grammar
11682
////////////////////////////////////////////////////////////////
11783

11884
static constexpr SyntaxRule Rule_LayerActionStepTargetTypeRules[]{
119-
SyntaxRule{ UCT_Source }, // TODO: Set action target type
120-
SyntaxRule{ UCT_Action }, // TODO: Set action target type
85+
SyntaxRule{ TokenType::ASL_KW_Source }, // TODO: Set action target type
86+
SyntaxRule{ TokenType::ASL_KW_Action }, // TODO: Set action target type
12187
};
12288

12389
static constexpr SyntaxRule Rule_LayerActionStepTargetExplicitRules[]{
@@ -171,8 +137,8 @@ namespace ice::grammar
171137
////////////////////////////////////////////////////////////////
172138

173139
static constexpr SyntaxRule Rule_LayerActionWhenTargetTypeRules[]{
174-
SyntaxRule{ UCT_Source },
175-
SyntaxRule{ UCT_Action },
140+
SyntaxRule{ TokenType::ASL_KW_Source },
141+
SyntaxRule{ TokenType::ASL_KW_Action },
176142
};
177143

178144
static constexpr SyntaxRule Rule_LayerActionWhenTargetExplicitRules[]{
@@ -299,7 +265,7 @@ namespace ice::grammar
299265
};
300266

301267
static constexpr SyntaxRule Rule_LayerActionRules[]{ // action <name>: <native_type>
302-
SyntaxRule{ UCT_Action },
268+
SyntaxRule{ TokenType::ASL_KW_Action },
303269
SyntaxRule{ TokenType::CT_Symbol, &syntax::LayerAction::name },
304270
SyntaxRule{ TokenType::CT_Colon },
305271
SyntaxRule{ Rule_LayerActionTypeRules, MatchFirst, &syntax::LayerAction::type },
@@ -311,7 +277,7 @@ namespace ice::grammar
311277
};
312278

313279
static constexpr SyntaxRule Rule_LayerRules[]{ // layer <name>: <sources...> <actions...>
314-
SyntaxRule{ UCT_Layer },
280+
SyntaxRule{ TokenType::ASL_KW_Layer },
315281
SyntaxRule{ TokenType::CT_Symbol, &syntax::Layer::name },
316282
SyntaxRule{ TokenType::CT_Colon },
317283
SyntaxRule{ TokenType::ST_EndOfLine }.repeat(),

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace ice
99
{
1010

11+
using TokenType = ice::asl::TokenType;
12+
1113
namespace detail
1214
{
1315

@@ -56,8 +58,8 @@ namespace ice
5658
switch(node.data().type.type)
5759
{
5860
case ice::grammar::UCT_InputTypeButton: type = InputActionSourceType::Button; break;
59-
case ice::grammar::UCT_InputTypeAxis1D: type = InputActionSourceType::Axis1d; break;
60-
case ice::grammar::UCT_InputTypeAxis2D: type = InputActionSourceType::Axis2d; break;
61+
case TokenType::ASL_NT_Axis1D: type = InputActionSourceType::Axis1d; break;
62+
case TokenType::ASL_NT_Axis2D: type = InputActionSourceType::Axis2d; break;
6163
}
6264

6365
ice::InputActionBuilder::Source source = _builder->define_source(node.data().name, type);
@@ -167,7 +169,7 @@ namespace ice
167169
ice::syntax::LayerActionWhen const& cond = cond_node.data();
168170
ICE_LOG(LogSeverity::Debug, LogTag::Tool, "- {} {}.{} {} {}", cond.type.value, cond.source_type.value, cond.source_name, cond.condition.value, cond.param.value);
169171

170-
bool const from_action = cond.source_type.type == grammar::UCT_Action
172+
bool const from_action = cond.source_type.type == TokenType::ASL_KW_Action
171173
|| (cond.source_type.type == arctic::TokenType::Invalid && cond.source_name.empty()); // "self"
172174
ice::InputActionCondition const condition = detail::condition_from_dsl(cond.condition, from_action);
173175

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
2+
#include <ice/base.hxx>
23
#include <arctic/arctic_token.hxx>
34
#include <arctic/arctic_syntax_node_types.hxx>
45
#include <arctic/arctic_syntax_entity.hxx>
5-
#include <ice/base.hxx>
66

77
namespace ice::syntax
88
{
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#pragma once
2+
#include <ice/base.hxx>
3+
#include <arctic/arctic_token.hxx>
4+
5+
namespace ice::asl
6+
{
7+
8+
static constexpr ice::u32 ASLT_Base = ice::u32(arctic::TokenType::ST_Any) + 1;
9+
static constexpr ice::u32 ASLT_Keywords = ASLT_Base + 1000;
10+
static constexpr ice::u32 ASLT_Operators = ASLT_Base + 2000;
11+
static constexpr ice::u32 ASLT_NativeTypes = ASLT_Base + 3000;
12+
13+
struct TokenType
14+
{
15+
using enum arctic::TokenType;
16+
17+
static constexpr arctic::TokenType ASL_KW_Layer{ ASLT_Keywords + 0 };
18+
static constexpr arctic::TokenType ASL_KW_Source{ ASLT_Keywords + 1 };
19+
static constexpr arctic::TokenType ASL_KW_Action{ ASLT_Keywords + 2 };
20+
21+
static constexpr arctic::TokenType ASL_OP_Pressed{ ASLT_Operators + 0 };
22+
static constexpr arctic::TokenType ASL_OP_Released{ ASLT_Operators + 1 };
23+
static constexpr arctic::TokenType ASL_OP_Active{ ASLT_Operators + 2 };
24+
static constexpr arctic::TokenType ASL_OP_Inactive{ ASLT_Operators + 3 };
25+
26+
static constexpr arctic::TokenType ASL_NT_Axis1D{ ASLT_NativeTypes + 0 };
27+
static constexpr arctic::TokenType ASL_NT_Axis2D{ ASLT_NativeTypes + 1 };
28+
static constexpr arctic::TokenType ASL_NT_Axis3D{ ASLT_NativeTypes + 2 };
29+
};
30+
31+
32+
static constexpr ice::u32 UCT_Base = ASLT_Base;
33+
static constexpr arctic::TokenType UCT_InputTypeButton{ UCT_Base + 2 };
34+
static constexpr arctic::TokenType UCT_InputBindingKeyboard{ UCT_Base + 6 };
35+
static constexpr arctic::TokenType UCT_InputBindingMouse{ UCT_Base + 7 };
36+
static constexpr arctic::TokenType UCT_InputBindingPad{ UCT_Base + 8 };
37+
static constexpr arctic::TokenType UCT_ActionTypeBool{ UCT_Base + 10 };
38+
static constexpr arctic::TokenType UCT_ActionTypeFloat1{ UCT_Base + 11 };
39+
static constexpr arctic::TokenType UCT_ActionTypeFloat2{ UCT_Base + 12 };
40+
static constexpr arctic::TokenType UCT_ActionTypeFloat3{ UCT_Base + 13 };
41+
static constexpr arctic::TokenType UCT_ActionTypeObject{ UCT_Base + 14 };
42+
static constexpr arctic::TokenType UCT_ActionFlagOnce{ UCT_Base + 15 };
43+
static constexpr arctic::TokenType UCT_ActionFlagToggled{ UCT_Base + 16 };
44+
//static constexparctic::r TokenType UCT_ActionFlagAccumulated{ UCT_Base + 17 };
45+
static constexpr arctic::TokenType UCT_When{ UCT_Base + 18 };
46+
static constexpr arctic::TokenType UCT_WhenAnd{ UCT_Base + 19 };
47+
static constexpr arctic::TokenType UCT_WhenOr{ UCT_Base + 20 };
48+
static constexpr arctic::TokenType UCT_WhenPressed{ UCT_Base + 21 };
49+
static constexpr arctic::TokenType UCT_WhenReleased{ UCT_Base + 22 };
50+
static constexpr arctic::TokenType UCT_WhenActive{ UCT_Base + 23 };
51+
static constexpr arctic::TokenType UCT_WhenInactive{ UCT_Base + 24 };
52+
static constexpr arctic::TokenType UCT_WhenFlagCheckSeries{ UCT_Base + 25 };
53+
static constexpr arctic::TokenType UCT_StepActivate{ UCT_Base + 26 };
54+
static constexpr arctic::TokenType UCT_StepDeactivate{ UCT_Base + 27 };
55+
static constexpr arctic::TokenType UCT_StepToggle{ UCT_Base + 28 };
56+
static constexpr arctic::TokenType UCT_StepReset{ UCT_Base + 29 };
57+
static constexpr arctic::TokenType UCT_StepTime{ UCT_Base + 30 };
58+
static constexpr arctic::TokenType UCT_Modifier{ UCT_Base + 31 };
59+
static constexpr arctic::TokenType UCT_ModifierOpMin{ UCT_Base + 32 };
60+
static constexpr arctic::TokenType UCT_ModifierOpMax{ UCT_Base + 33 };
61+
62+
} // namespace ice::asl

0 commit comments

Comments
 (0)