Skip to content

Commit f06991a

Browse files
committed
Fixing remaining compilation issues and bugs.
Closing work on this feature, and might revisit it again once required.
1 parent 36d63e1 commit f06991a

File tree

12 files changed

+133
-48
lines changed

12 files changed

+133
-48
lines changed

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

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

11+
auto compare(
12+
ice::String left,
13+
ice::String right,
14+
ice::u64 count,
15+
ice::CaseSensitive check_case /*= CaseSensitive::No*/
16+
) noexcept -> ice::CompareResult
17+
{
18+
#if ISP_WINDOWS
19+
ice::u32 const comp_result = check_case == CaseSensitive::Yes
20+
? strncmp(ice::string::begin(left), ice::string::begin(right), count)
21+
: strnicmp(ice::string::begin(left), ice::string::begin(right), count);
22+
#elif ISP_UNIX
23+
ice::u32 const comp_result = check_case == CaseSensitive::Yes
24+
? strncmp(ice::string::begin(left), ice::string::begin(right), count)
25+
: strncasecmp(ice::string::begin(left), ice::string::begin(right), count);
26+
#endif
27+
return comp_result == 0 ? CompareResult::Equal :
28+
(comp_result < 0 ? CompareResult::Smaller : CompareResult::Larger);
29+
}
30+
31+
auto compare(
32+
ice::String left,
33+
ice::String right,
34+
ice::CaseSensitive check_case /*= CaseSensitive::No*/
35+
) noexcept -> ice::CompareResult
36+
{
37+
ice::u32 const max_size = ice::min(ice::size(left), ice::size(right));
38+
#if ISP_WINDOWS
39+
ice::u32 const comp_result = check_case == CaseSensitive::Yes
40+
? strncmp(ice::string::begin(left), ice::string::begin(right), max_size)
41+
: strnicmp(ice::string::begin(left), ice::string::begin(right), max_size);
42+
#elif ISP_UNIX
43+
ice::u32 const comp_result = check_case == CaseSensitive::Yes
44+
? strncmp(ice::string::begin(left), ice::string::begin(right), max_size)
45+
: strncasecmp(ice::string::begin(left), ice::string::begin(right), max_size);
46+
#endif
47+
return comp_result == 0 ? CompareResult::Equal :
48+
(comp_result < 0 ? CompareResult::Smaller : CompareResult::Larger);
49+
}
50+
1151
auto utf8_to_wide_size(
1252
ice::String utf8_str
1353
) noexcept -> ice::u32

source/code/core/utils/public/ice/string_utils.hxx

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ namespace ice
3232

3333
} // namespace string
3434

35+
enum class CaseSensitive : bool { No, Yes };
36+
enum class CompareResult : ice::i8 { Smaller = -1, Equal = 0, Larger = 1 };
37+
auto compare(ice::String left, ice::String right, ice::CaseSensitive = CaseSensitive::No) noexcept -> ice::CompareResult;
38+
auto compare(ice::String left, ice::String right, ice::u64 count, ice::CaseSensitive = CaseSensitive::No) noexcept -> ice::CompareResult;
39+
3540
auto utf8_to_wide_size(ice::String path) noexcept -> ice::u32;
3641
bool utf8_to_wide_append(ice::String path, ice::HeapString<ice::wchar>& out_str) noexcept;
3742
auto utf8_to_wide(ice::Allocator& alloc, ice::String path) noexcept -> ice::HeapString<ice::wchar>;
@@ -57,11 +62,34 @@ namespace ice
5762
auto from_chars(ice::String str, T& out_value) noexcept -> ice::FromCharsResult<ice::String>
5863
{
5964
ice::ErrorCode res = ice::S_Ok;
60-
std::from_chars_result const fc_res = std::from_chars(
61-
ice::string::begin(str),
62-
ice::string::end(str),
63-
out_value
64-
);
65+
std::from_chars_result fc_res;
66+
if constexpr (std::is_integral_v<T>)
67+
{
68+
fc_res = std::from_chars(
69+
ice::string::begin(str),
70+
ice::string::end(str),
71+
out_value
72+
);
73+
}
74+
else
75+
{
76+
#if ISP_COMPILER_CLANG <= 20 || ISP_WEBAPP || ISP_ANDROID
77+
// Because Libc++ did not support from_chars for floats up until clang.20 we need to use the old C style approach...
78+
// We don't try to handle errors in this version.
79+
fc_res.ec = std::errc{};
80+
char* ptr_end = nullptr; // Why the hell is this a char ptr?
81+
out_value = strtof(ice::string::begin(str), &ptr_end);
82+
ICE_ASSERT_CORE(ice::ptr_distance(ice::string::begin(str), ptr_end).value <= ice::size(str));
83+
fc_res.ptr = ptr_end;
84+
#else
85+
fc_res = std::from_chars(
86+
ice::string::begin(str),
87+
ice::string::end(str),
88+
out_value,
89+
std::chars_format::general
90+
);
91+
#endif
92+
}
6593

6694
if (fc_res.ec == std::errc::result_out_of_range)
6795
{
@@ -83,11 +111,25 @@ namespace ice
83111
auto from_chars(char const* str_beg, char const* str_end, T& out_value) noexcept -> ice::FromCharsResult<char const*>
84112
{
85113
ice::ErrorCode res = ice::S_Ok;
86-
std::from_chars_result const fc_res = std::from_chars(
87-
str_beg,
88-
str_end,
89-
out_value
90-
);
114+
std::from_chars_result fc_res;
115+
if constexpr (std::is_integral_v<T>)
116+
{
117+
fc_res = std::from_chars(str_beg, str_end, out_value);
118+
}
119+
else
120+
{
121+
#if ISP_COMPILER_CLANG <= 20 || ISP_WEBAPP || ISP_ANDROID
122+
// Because Libc++ did not support from_chars for floats up until clang.20 we need to use the old C style approach...
123+
// We don't try to handle errors in this version.
124+
fc_res.ec = std::errc{};
125+
char* ptr_end = nullptr; // Why the hell is this a char ptr?
126+
out_value = strtof(str_beg, &ptr_end);
127+
ICE_ASSERT_CORE(ice::ptr_distance(str_beg, ptr_end) <= ice::ptr_distance(str_beg, str_end));
128+
fc_res.ptr = ptr_end;
129+
#else
130+
fc_res = std::from_chars(str_beg, str_end, out_value, std::chars_format::general);
131+
#endif
132+
}
91133

92134
if (fc_res.ec == std::errc::result_out_of_range)
93135
{

source/code/framework/framework_base/private/framework_main.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ auto ice_setup(
436436
ice::EngineCreateInfo engine_create_info{
437437
.states = ice::create_state_tracker(state.alloc),
438438
.archetypes = ice::move(archetypes),
439-
.action_stack = ice::move(ice::create_input_action_stack(alloc, ""))
439+
.action_stack = ice::create_input_action_stack(alloc, "")
440440
};
441441
{
442442
ice::UniquePtr<ice::AssetCategoryArchive> asset_categories = ice::create_asset_category_archive(state.engine_alloc);

source/code/framework/framework_base/private/traits/ui/render_ui_trait.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,6 @@ namespace ice
128128
} // namespace ice
129129

130130
template<>
131-
constexpr ice::ShardPayloadID ice::Constant_ShardPayloadID<ice::RenderUIRequest const*> = ice::shard_payloadid("ice::RenderUIRequest const*");
131+
constexpr inline ice::ShardPayloadID ice::Constant_ShardPayloadID<ice::RenderUIRequest const*> = ice::shard_payloadid("ice::RenderUIRequest const*");
132132

133133
#endif

source/code/framework/framework_base/public/ice/game_render_traits.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace ice
9595
} // namespace ice
9696

9797
template<>
98-
constexpr ice::ShardPayloadID ice::Constant_ShardPayloadID<ice::DebugDrawCommandList const*> = ice::shard_payloadid("ice::DebugDrawCommandList const*");
98+
constexpr inline ice::ShardPayloadID ice::Constant_ShardPayloadID<ice::DebugDrawCommandList const*> = ice::shard_payloadid("ice::DebugDrawCommandList const*");
9999

100100
template<>
101-
constexpr ice::ShardPayloadID ice::Constant_ShardPayloadID<ice::DrawTextCommand const*> = ice::shard_payloadid("ice::DrawTextCommand const*");
101+
constexpr inline ice::ShardPayloadID ice::Constant_ShardPayloadID<ice::DrawTextCommand const*> = ice::shard_payloadid("ice::DrawTextCommand const*");

source/code/framework/framework_base/public/ice/game_ui.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ namespace ice
4545
} // namespace ice
4646

4747
template<>
48-
constexpr ice::ShardPayloadID ice::Constant_ShardPayloadID<ice::UpdateUIResource const*> = ice::shard_payloadid("ice::UpdateUIResource const*");
48+
constexpr inline ice::ShardPayloadID ice::Constant_ShardPayloadID<ice::UpdateUIResource const*> = ice::shard_payloadid("ice::UpdateUIResource const*");

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#include <arctic/arctic_parser.hxx>
77
#include <arctic/arctic_syntax_node_allocator.hxx>
88
#include <arctic/arctic_word_matcher.hxx>
9+
#include <ice/string_utils.hxx>
910
#include <ice/sort.hxx>
11+
#include <ice/log.hxx>
1012

1113
namespace ice
1214
{
@@ -111,7 +113,7 @@ namespace ice
111113

112114
static auto const pred = [](ice::TokenInfo const& hay, arctic::Word const& needle) noexcept
113115
{
114-
return strnicmp(hay.value.data(), needle.value.data(), hay.value.size()) == 0;
116+
return ice::compare(hay.value, needle.value, hay.value.size()) == CompareResult::Equal;
115117
};
116118

117119
ice::ucount idx;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ice
2929
ActionInputParserEventsBase::visit(node);
3030
}
3131

32-
void visit(arctic::SyntaxNode<ice::syntax::Layer> node) noexcept = 0;
32+
void visit(arctic::SyntaxNode<ice::syntax::Layer> node) noexcept override = 0;
3333
};
3434

3535
} // namespace ice

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ namespace ice
2525
InputActionDSLLayerBuilder::InputActionDSLLayerBuilder(
2626
ice::UniquePtr<ice::InputActionLayerBuilder> builder
2727
) noexcept
28-
: _builder{ ice::move(builder) }
28+
: ActionInputParserEvents{ }
29+
, _builder{ ice::move(builder) }
2930
{
3031
}
3132

@@ -35,21 +36,21 @@ namespace ice
3536
_builder->set_name(node.data().name);
3637

3738
arctic::SyntaxNode<> child = node.child();
38-
while(child != false)
39+
while (child != false)
3940
{
4041
if (child.type() == ice::syntax::SyntaxEntity_LayerSource)
4142
{
42-
visit(child.to<ice::syntax::LayerSource>());
43+
visit_source(child.to<ice::syntax::LayerSource>());
4344
}
4445
else if (child.type() == ice::syntax::SyntaxEntity_LayerAction)
4546
{
46-
visit(child.to<ice::syntax::LayerAction>());
47+
visit_layer(child.to<ice::syntax::LayerAction>());
4748
}
4849
child = child.sibling();
4950
}
5051
}
5152

52-
void InputActionDSLLayerBuilder::visit(arctic::SyntaxNode<ice::syntax::LayerSource> node) noexcept
53+
void InputActionDSLLayerBuilder::visit_source(arctic::SyntaxNode<ice::syntax::LayerSource> node) noexcept
5354
{
5455
ice::InputActionSourceType type = InputActionSourceType::Key;
5556
switch(node.data().type.type)
@@ -107,7 +108,7 @@ namespace ice
107108
ICE_LOG(LogSeverity::Info, LogTag::Engine, "Source: {}", node.data().name);
108109
}
109110

110-
void InputActionDSLLayerBuilder::visit(arctic::SyntaxNode<ice::syntax::LayerAction> node) noexcept
111+
void InputActionDSLLayerBuilder::visit_layer(arctic::SyntaxNode<ice::syntax::LayerAction> node) noexcept
111112
{
112113
ice::syntax::LayerAction const& action_info = node.data();
113114
ice::InputActionDataType const action_datatype = detail::datatype_from_dsl(action_info.type);
@@ -134,27 +135,27 @@ namespace ice
134135
{
135136
if (child.type() == ice::syntax::SyntaxEntity_LayerActionCondition)
136137
{
137-
visit(action, child.to<ice::syntax::LayerActionWhen>());
138+
visit_cond(action, child.to<ice::syntax::LayerActionWhen>());
138139

139140
arctic::SyntaxNode<> steps = child.child();
140141
while (steps != false)
141142
{
142143
if (steps.type() == ice::syntax::SyntaxEntity_LayerActionStep)
143144
{
144-
visit(action, steps.to<ice::syntax::LayerActionStep>());
145+
visit_step(action, steps.to<ice::syntax::LayerActionStep>());
145146
}
146147
steps = steps.sibling();
147148
}
148149
}
149150
else if (child.type() == ice::syntax::SyntaxEntity_LayerActionModifier)
150151
{
151-
visit(action, child.to<ice::syntax::LayerActionModifier>());
152+
visit_mod(action, child.to<ice::syntax::LayerActionModifier>());
152153
}
153154
child = child.sibling();
154155
}
155156
}
156157

157-
void InputActionDSLLayerBuilder::visit(
158+
void InputActionDSLLayerBuilder::visit_cond(
158159
ice::InputActionLayerBuilder::ActionBuilder& action,
159160
arctic::SyntaxNode<ice::syntax::LayerActionWhen> node
160161
) noexcept
@@ -206,7 +207,7 @@ namespace ice
206207
action.add_condition(cond.source_name, condition, flags, param, from_action);
207208
}
208209

209-
void InputActionDSLLayerBuilder::visit(
210+
void InputActionDSLLayerBuilder::visit_step(
210211
ice::InputActionLayerBuilder::ActionBuilder& action,
211212
arctic::SyntaxNode<ice::syntax::LayerActionStep> node
212213
) noexcept
@@ -223,7 +224,7 @@ namespace ice
223224
}
224225
}
225226

226-
void InputActionDSLLayerBuilder::visit(
227+
void InputActionDSLLayerBuilder::visit_mod(
227228
ice::InputActionLayerBuilder::ActionBuilder& action,
228229
arctic::SyntaxNode<ice::syntax::LayerActionModifier> node
229230
) noexcept
@@ -270,7 +271,7 @@ namespace ice
270271
result = static_cast<KeyboardKey>(static_cast<ice::u16>(KeyboardKey::Key0) + key_diff);
271272
}
272273
}
273-
else if (strnicmp(value.data(), "space", 5) == 0)
274+
else if (ice::compare(value, "space") == CompareResult::Equal)
274275
{
275276
result = KeyboardKey::Space;
276277
}
@@ -290,15 +291,15 @@ namespace ice
290291
{
291292
result = KeyboardKey::Right;
292293
}
293-
else if (strnicmp(value.data(), "mode", 4) == 0)
294+
else if (ice::compare(value, "mode") == CompareResult::Equal)
294295
{
295296
return KeyboardKey::KeyMode;
296297
}
297-
else if (strnicmp(value.data(), "numlock", 4) == 0)
298+
else if (ice::compare(value, "numlock") == CompareResult::Equal)
298299
{
299300
return KeyboardKey::NumPadNumlockClear;
300301
}
301-
else if (strnicmp(value.data(), "capslock", 4) == 0)
302+
else if (ice::compare(value, "capslock") == CompareResult::Equal)
302303
{
303304
return KeyboardKey::KeyCapsLock;
304305
}
@@ -307,19 +308,19 @@ namespace ice
307308
ice::u8 const mod_left = value[0] == 'l';
308309
value = value.substr(1);
309310

310-
if (strnicmp(value.data(), "shift", 5) == 0)
311+
if (ice::compare(value, "shift") == CompareResult::Equal)
311312
{
312313
result = mod_left ? KeyboardKey::KeyLeftShift : KeyboardKey::KeyRightShift;
313314
}
314-
else if (strnicmp(value.data(), "ctrl", 4) == 0)
315+
else if (ice::compare(value, "ctrl") == CompareResult::Equal)
315316
{
316317
result = mod_left ? KeyboardKey::KeyLeftCtrl : KeyboardKey::KeyRightCtrl;
317318
}
318-
else if (strnicmp(value.data(), "alt", 3) == 0)
319+
else if (ice::compare(value, "alt") == CompareResult::Equal)
319320
{
320321
result = mod_left ? KeyboardKey::KeyLeftAlt : KeyboardKey::KeyRightAlt;
321322
}
322-
else if (strnicmp(value.data(), "gui", 3) == 0)
323+
else if (ice::compare(value, "gui") == CompareResult::Equal)
323324
{
324325
result = mod_left ? KeyboardKey::KeyLeftGui : KeyboardKey::KeyRightGui;
325326
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ namespace ice
1414

1515
void visit(arctic::SyntaxNode<ice::syntax::Layer> node) noexcept override;
1616

17-
void visit(arctic::SyntaxNode<ice::syntax::LayerSource> node) noexcept;
18-
void visit(arctic::SyntaxNode<ice::syntax::LayerAction> node) noexcept;
17+
void visit_source(arctic::SyntaxNode<ice::syntax::LayerSource> node) noexcept;
18+
void visit_layer(arctic::SyntaxNode<ice::syntax::LayerAction> node) noexcept;
1919

20-
void visit(
20+
void visit_cond(
2121
ice::InputActionLayerBuilder::ActionBuilder& action,
2222
arctic::SyntaxNode<ice::syntax::LayerActionWhen> node
2323
) noexcept;
2424

25-
void visit(
25+
void visit_step(
2626
ice::InputActionLayerBuilder::ActionBuilder& action,
2727
arctic::SyntaxNode<ice::syntax::LayerActionStep> node
2828
) noexcept;
2929

30-
void visit(
30+
void visit_mod(
3131
ice::InputActionLayerBuilder::ActionBuilder& action,
3232
arctic::SyntaxNode<ice::syntax::LayerActionModifier> node
3333
) noexcept;

0 commit comments

Comments
 (0)