Skip to content

Commit 7bc1e28

Browse files
authored
InputActions (#195)
Introducing the InputAction system that is build on top of the existing Input system. It provides a simpler way of defining inputs, by using names and simple conditions. Actions can be defined either using a script or builder type. Example script can be found under 'source/data/code/example_input_actions.ias' Features: * Introduction of InputActionLayers that can enable InputActions depending on the game state. * Introduction of InputActions that are send as shard with types (bool, float, float2, object) * Introduction of IAS script to quickly define new action layers. * Active actions will be pushed to the active frame's shards container. * Traits can define their action layers, register them, and push onto the input action stack. Improvements: * Introduced new 'ice::PimplType' type that hides most of the boilerplate of the Pimpl design pattern. * Introduced 'ice::ref8/16/32' types, which contain a size and offset field. These types allow quicker access to parts of strings, arrays and similar. * Introduced formatting of 'ice::isize' types. * Introduced 'from_app' check to module loading API. (limit loading of modules to app contexts) * Introduced new constants for '0' values of various numeric types. (ex.: ice::i32_0) * Introduced new error-code constants. * Introduced 'ice::compare' function that should be used instead of 'strncmp' and 'strnicmp'. * Modifier keys (shift, alt, ctrl, win) are now also sent as key events, not only mod events. * Expanded on Array and String API's introducing more function overloads. * Refactored the 'from_chars' implementation for floating-point types. Fixes: * Fixed crash by disabling custom vulkan allocator on windows. (#197) * Fixed deprecations of 'fmt::localtime' used in the log format. * Fixes build issues on GH Workers failing on creating a symlink. Known Issues: * Key mod events reported by SDL2 seem to be quite laggy, and are not refreshed often enough? Other: * Updated IBT to v1.11.1
1 parent 618e5e6 commit 7bc1e28

File tree

75 files changed

+4952
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4952
-77
lines changed

source/code/core/collections/public/ice/container/array.hxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ namespace ice::array
4949
requires std::copy_constructible<Type>
5050
inline void push_back(ice::Array<Type, Logic>& arr, ice::Span<Type const> items) noexcept;
5151

52+
template<typename Type, ice::ContainerLogic Logic, typename Source>
53+
requires std::copy_constructible<Type> && (std::is_same_v<Type, Source> == false)
54+
inline void push_back(ice::Array<Type, Logic>& arr, ice::Span<Source const> items, Type(*fn)(Source const&) noexcept) noexcept;
55+
5256
template<typename Type, ice::ContainerLogic Logic>
5357
inline void pop_back(ice::Array<Type, Logic>& arr, ice::ucount count = 1) noexcept;
5458

@@ -123,6 +127,9 @@ namespace ice::array
123127
template<typename Type>
124128
inline auto memset(ice::Array<Type, ice::ContainerLogic::Trivial>& arr, ice::u8 value) noexcept -> ice::Memory;
125129

130+
template<typename Type, ice::ContainerLogic Logic>
131+
inline auto meminfo(ice::Array<Type, Logic> const& arr) noexcept -> ice::meminfo;
132+
126133
} // namespace ice::array
127134

128135
namespace ice

source/code/core/collections/public/ice/container/impl/array_impl.inl

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,23 @@ namespace ice
376376
arr._count += ice::span::count(items);
377377
}
378378

379+
template<typename Type, ice::ContainerLogic Logic, typename Source>
380+
requires std::copy_constructible<Type> && (std::is_same_v<Type, Source> == false)
381+
inline void push_back(ice::Array<Type, Logic>& arr, ice::Span<Source const> items, Type(*fn)(Source const&) noexcept) noexcept
382+
{
383+
ice::ucount const required_capacity = arr._count + ice::span::count(items);
384+
if (required_capacity > arr._capacity)
385+
{
386+
ice::array::grow(arr, required_capacity);
387+
}
388+
389+
ice::ucount const missing_items = required_capacity - arr._count;
390+
for (ice::u32 src_idx = 0; src_idx < missing_items; ++src_idx)
391+
{
392+
ice::array::push_back(arr, fn(items[src_idx]));
393+
}
394+
}
395+
379396
template<typename Type, ice::ContainerLogic Logic>
380397
inline void pop_back(ice::Array<Type, Logic>& arr, ice::ucount count /*= 1*/) noexcept
381398
{
@@ -466,9 +483,15 @@ namespace ice
466483
}
467484

468485
template<typename Type, ice::ContainerLogic Logic>
469-
inline auto slice(ice::Array<Type, Logic> const& arr, ice::ucount from_idx, ice::ucount to) noexcept -> ice::Span<Type const>
486+
inline auto slice(ice::Array<Type, Logic> const& arr, ice::ucount from_idx, ice::ucount count) noexcept -> ice::Span<Type const>
487+
{
488+
return ice::span::subspan<Type const>(arr, from_idx, count);
489+
}
490+
491+
template<typename Type, ice::ContainerLogic Logic>
492+
inline auto slice(ice::Array<Type, Logic> const& arr, ice::ref32 ref) noexcept -> ice::Span<Type const>
470493
{
471-
return ice::span::subspan<Type const>(arr, from_idx, to);
494+
return ice::span::subspan<Type const>(arr, ref);
472495
}
473496

474497
template<typename Type, ice::ContainerLogic Logic>
@@ -539,6 +562,12 @@ namespace ice
539562
return mem;
540563
}
541564

565+
template<typename Type, ice::ContainerLogic Logic>
566+
inline auto meminfo(ice::Array<Type, Logic> const& arr) noexcept -> ice::meminfo
567+
{
568+
return ice::meminfo_of<Type> * ice::array::count(arr);
569+
}
570+
542571
} // namespace array
543572

544573
} // namespace ice

source/code/core/collections/public/ice/span.hxx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ namespace ice
8585
template<typename Type>
8686
constexpr auto subspan(ice::Span<Type> span, ice::ucount from_idx, ice::ucount count = ice::ucount_max) noexcept -> ice::Span<Type>;
8787

88+
template<typename Type>
89+
constexpr auto subspan(ice::Span<Type> span, ice::ref32 ref) noexcept -> ice::Span<Type>;
90+
8891
template<typename Type>
8992
constexpr auto begin(ice::Span<Type> span) noexcept -> typename ice::Span<Type>::Iterator;
9093

@@ -257,6 +260,12 @@ namespace ice
257260
return { span._data + from_start, new_count };
258261
}
259262

263+
template<typename Type>
264+
constexpr auto subspan(ice::Span<Type> span, ice::ref32 ref) noexcept -> ice::Span<Type>
265+
{
266+
return ice::span::subspan(span, ref.offset, ref.size);
267+
}
268+
260269
template<typename Type>
261270
constexpr auto begin(ice::Span<Type> span) noexcept -> typename ice::Span<Type>::Iterator
262271
{
@@ -330,12 +339,26 @@ namespace ice
330339
}
331340

332341
template<typename Type>
333-
constexpr auto from_memory(ice::Memory const& mem, ice::meminfo meminfo, ice::usize offset) noexcept
342+
constexpr auto from_memory(ice::Memory const& mem, ice::ucount count, ice::usize offset) noexcept -> ice::Span<Type>
334343
{
344+
static ice::meminfo minfo = ice::meminfo_of<Type>;
345+
335346
void* const ptr = ice::ptr_add(mem.location, offset);
336-
ICE_ASSERT_CORE(ice::is_aligned(ptr, meminfo.alignment));
337-
ICE_ASSERT_CORE(ice::ptr_add(mem.location, mem.size) >= ice::ptr_add(ptr, meminfo.size));
338-
return ice::Span<Type>{ reinterpret_cast<Type*>(ptr), ice::ucount((meminfo.size / ice::size_of<Type>).value) };
347+
ICE_ASSERT_CORE(ice::is_aligned(ptr, minfo.alignment));
348+
ICE_ASSERT_CORE(ice::ptr_add(mem.location, mem.size) >= ice::ptr_add(ptr, minfo.size * count));
349+
return ice::Span<Type>{ reinterpret_cast<Type*>(ptr), count };
350+
}
351+
352+
// TODO: Move to another location or rename? Not sure this is properly named
353+
template<typename Type>
354+
constexpr auto from_data(ice::Data const& mem, ice::ucount count, ice::usize offset) noexcept -> ice::Span<Type const>
355+
{
356+
static ice::meminfo constexpr minfo = ice::meminfo_of<Type>;
357+
358+
void const* const ptr = ice::ptr_add(mem.location, offset);
359+
ICE_ASSERT_CORE(ice::is_aligned(ptr, minfo.alignment));
360+
ICE_ASSERT_CORE(ice::ptr_add(mem.location, mem.size) >= ice::ptr_add(ptr, minfo.size * count));
361+
return { reinterpret_cast<Type const*>(ptr), count };
339362
}
340363

341364
} // namespace span

source/code/core/collections/public/ice/string/impl/string.inl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,15 @@ namespace ice
180180
}
181181

182182
template<typename CharType>
183-
constexpr auto starts_with(ice::BasicString<CharType> str, ice::BasicString<CharType> prefix) noexcept
183+
constexpr auto substr(ice::BasicString<CharType> str, ice::ref32 ref) noexcept -> ice::BasicString<CharType>
184184
{
185-
return ice::string::substr(str, 0, ice::string::size(prefix)) == prefix;
185+
return ice::string::substr(str, ref.offset, ref.size);
186+
}
187+
188+
template<typename CharType>
189+
constexpr auto starts_with(ice::BasicString<CharType> str, ice::concepts::StringType<CharType> auto prefix) noexcept
190+
{
191+
return ice::string::substr(str, 0, prefix._size) == prefix;
186192
}
187193

188194

@@ -384,6 +390,14 @@ namespace ice
384390
};
385391
}
386392

393+
template<typename CharType>
394+
constexpr auto meminfo(ice::BasicString<CharType> str) noexcept -> ice::meminfo
395+
{
396+
return ice::meminfo{
397+
ice::meminfo_of<CharType> * ice::string::size(str)
398+
};
399+
}
400+
387401
} // namespace string
388402

389403
} // namespace ice

source/code/core/collections/public/ice/string/string.hxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ namespace ice::string
4141
constexpr auto substr(ice::BasicString<CharType> str, ice::ucount pos, ice::ucount len = ice::String_NPos) noexcept -> ice::BasicString<CharType>;
4242

4343
template<typename CharType>
44-
constexpr auto starts_with(ice::BasicString<CharType> str, ice::BasicString<CharType> prefix) noexcept;
44+
constexpr auto substr(ice::BasicString<CharType> str, ice::ref32 ref) noexcept -> ice::BasicString<CharType>;
45+
46+
template<typename CharType>
47+
constexpr auto starts_with(ice::BasicString<CharType> str, ice::concepts::StringType<CharType> auto prefix) noexcept;
4548

4649
template<typename CharType>
4750
constexpr auto find_first_of(
@@ -109,6 +112,9 @@ namespace ice::string
109112
template<typename CharType>
110113
constexpr auto data_view(ice::BasicString<CharType> str) noexcept -> typename ice::Data;
111114

115+
template<typename CharType>
116+
constexpr auto meminfo(ice::BasicString<CharType> str) noexcept -> ice::meminfo;
117+
112118
} // namespace ice::string
113119

114120
namespace ice

source/code/core/collections/public/ice/string_types.hxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,15 @@ namespace ice
222222
}
223223

224224
} // namespace ice
225+
226+
namespace ice::concepts
227+
{
228+
229+
template<typename Type, typename CharType>
230+
concept StringType = std::is_same_v<ice::BasicString<CharType>, Type>
231+
|| std::is_same_v<ice::HeapString<CharType>, Type>
232+
&& requires(Type t) {
233+
{ t._size } -> std::convertible_to<ice::ucount>;
234+
};
235+
236+
} // namespace ice::concepts
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#pragma once
2+
#include <ice/concept/enum_flags.hxx>
3+
4+
namespace ice::concepts
5+
{
6+
7+
enum class PimplFlags : ice::u8
8+
{
9+
None = 0x0,
10+
Default = None,
11+
12+
NoMoveSemantics = 0x01,
13+
NoCopySemantics = 0x02,
14+
NoMoveCopySemantics = NoMoveSemantics | NoCopySemantics,
15+
};
16+
17+
class PimplType
18+
{
19+
protected:
20+
template<typename T>
21+
struct Internal;
22+
23+
public:
24+
template<typename T>
25+
PimplType(Internal<T>* data) noexcept;
26+
27+
// TODO: Move this somewhere else!
28+
PimplType(PimplType&& other) noexcept = delete;
29+
auto operator=(PimplType&& other) noexcept -> PimplType& = delete;
30+
PimplType(PimplType const& other) noexcept = delete;
31+
auto operator=(PimplType const& other) noexcept -> PimplType& = delete;
32+
33+
protected:
34+
template<typename Self>
35+
auto internal(this Self& self) noexcept -> Internal<Self>&;
36+
37+
private:
38+
void* _internal;
39+
};
40+
41+
42+
template<typename Self>
43+
inline PimplType::PimplType(Internal<Self>* data) noexcept
44+
: _internal{ data }
45+
{
46+
}
47+
48+
template<typename Self>
49+
auto PimplType::internal(this Self& self) noexcept -> Internal<Self>&
50+
{
51+
return *reinterpret_cast<Internal<Self>*>(self._internal);
52+
}
53+
54+
} // namespace ice::concepts

source/code/core/core/public/ice/constants.hxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,16 @@ namespace ice
4646
constexpr ice::f32 const f32_nan = std::numeric_limits<ice::f32>::signaling_NaN();
4747
constexpr ice::f64 const f64_nan = std::numeric_limits<ice::f64>::signaling_NaN();
4848

49+
// Typed zero values
50+
constexpr ice::f32 const f32_0 = ice::f32(0.0f);
51+
constexpr ice::f64 const f64_0 = ice::f64(0.0);
52+
constexpr ice::i8 const i8_0 = ice::i8(0);
53+
constexpr ice::i16 const i16_0 = ice::i16(0);
54+
constexpr ice::i32 const i32_0 = ice::i32(0);
55+
constexpr ice::i64 const i64_0 = ice::i64(0);
56+
constexpr ice::u8 const u8_0 = ice::u8(0);
57+
constexpr ice::u16 const u16_0 = ice::u16(0);
58+
constexpr ice::u32 const u32_0 = ice::u32(0);
59+
constexpr ice::u64 const u64_0 = ice::u64(0);
60+
4961
} // namespace ice

source/code/core/core/public/ice/error_codes.hxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace ice
1616
static constexpr ice::ErrorCode E_InvalidArgument{ "E.0002:General:Invalid argument provided" };
1717
static constexpr ice::ErrorCode E_OutOfRange{ "E.0003:General:Accessing value out of range" };
1818
static constexpr ice::ErrorCode E_NotImplemented{ "E.0004:General:Function or method is not implemented" };
19+
static constexpr ice::ErrorCode E_NullPointer{ "E.0005:General:Passed '{nullptr}' to function expecting valid pointer." };
20+
static constexpr ice::ErrorCode E_NullPointerData{ "E.0006:General:Passed 'Data{nullptr}' object to function expecting valid data." };
21+
static constexpr ice::ErrorCode E_NullPointerMemory{ "E.0007:General:Passed 'Memory{nullptr}' object to function expecting valid memory." };
1922
static constexpr ice::ErrorCode E_TaskCanceled{ "E.1001:Tasks:Task canceled" };
2023

2124
// Aliases are comparable

source/code/core/core/public/ice/types.hxx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ namespace ice
2828

2929
using uptr = std::uintptr_t;
3030

31+
// Declaration of ref types
32+
33+
//! \brief Holds 'offset' and 'size' fields (u32) to access data stored in a buffer-like object.
34+
using ref32 = struct { ice::u32 offset; ice::u32 size; };
35+
36+
//! \brief Holds 'offset' and 'size' fields (u16) to access data stored in a buffer-like object.
37+
struct ref16
38+
{
39+
ice::u16 offset;
40+
ice::u16 size;
41+
42+
constexpr operator ice::ref32() const noexcept { return ref32{ offset, size }; }
43+
};
44+
45+
//! \brief Holds 'offset' and 'size' fields (u8) to access data stored in a buffer-like object.
46+
struct ref8
47+
{
48+
ice::u8 offset;
49+
ice::u8 size;
50+
51+
constexpr operator ice::ref16() const noexcept { return ref16{ offset, size }; }
52+
constexpr operator ice::ref32() const noexcept { return ref32{ offset, size }; }
53+
};
54+
3155
// Forward declaration of time-types
3256
struct Ts;
3357
struct Tms;

0 commit comments

Comments
 (0)