Skip to content

Commit a9174a9

Browse files
committed
[iceshard] Improvements to the engine.
1 parent 8b25a88 commit a9174a9

File tree

69 files changed

+1249
-457
lines changed

Some content is hidden

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

69 files changed

+1249
-457
lines changed

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

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

11+
template<typename CharType>
12+
inline void clear(ice::HeapVarString<CharType>& str) noexcept;
13+
14+
template<typename CharType>
15+
inline auto begin(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::Iterator;
16+
17+
template<typename CharType>
18+
inline auto end(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::Iterator;
19+
20+
template<typename CharType>
21+
inline auto rbegin(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::ReverseIterator;
22+
23+
template<typename CharType>
24+
inline auto rend(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::ReverseIterator;
25+
26+
template<typename CharType>
27+
inline auto deserialize(ice::HeapVarString<CharType>& str, ice::Data data) noexcept -> ice::Data;
1128

1229
} // namespace ice::string
1330

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

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
/// Copyright 2024 - 2024, Dandielo <dandielo@iceshard.net>
22
/// SPDX-License-Identifier: MIT
33

4-
54
namespace ice
65
{
76

87
namespace string::detail
98
{
109

11-
inline auto write_varstring_size(void* data, ice::ucount size) noexcept -> ice::ucount
12-
{
13-
ice::ucount bytes = 0;
14-
ice::u8* var_byte = reinterpret_cast<ice::u8*>(data);
15-
while(size > 0x7f)
16-
{
17-
var_byte[bytes] = (size & 0x7f) | 0x80;
18-
size >>= 7;
19-
bytes += 1;
20-
}
21-
var_byte[bytes] = size & 0x7f;
22-
return bytes + 1;
23-
}
24-
2510
inline auto allocate_varstring_exact(ice::Allocator& alloc, ice::ucount size, ice::ucount& out_size_bytes) noexcept -> char*
2611
{
2712
if (size == 0)
@@ -66,6 +51,19 @@ namespace ice
6651
{
6752
}
6853

54+
template<typename CharType>
55+
inline HeapVarString<CharType>::HeapVarString(ice::HeapVarString<CharType>&& other) noexcept
56+
: _allocator{ other._allocator }
57+
, _data{ ice::exchange(other._data, nullptr) }
58+
{
59+
}
60+
61+
template<typename CharType>
62+
inline HeapVarString<CharType>::HeapVarString(ice::HeapVarString<CharType> const& other) noexcept
63+
: HeapVarString{ other._allocator, ice::String{ other } }
64+
{
65+
}
66+
6967
template<typename CharType>
7068
inline HeapVarString<CharType>::~HeapVarString() noexcept
7169
{
@@ -87,6 +85,24 @@ namespace ice
8785
return *this;
8886
}
8987

88+
template<typename CharType>
89+
inline bool operator==(ice::HeapVarString<CharType> const& left, CharType const* right) noexcept
90+
{
91+
return ice::BasicString<CharType>{ left } == ice::BasicString<CharType>{ right };
92+
}
93+
94+
template<typename CharType>
95+
inline bool operator==(ice::HeapVarString<CharType> const& left, ice::BasicString<CharType> right) noexcept
96+
{
97+
return ice::BasicString<CharType>{ left } == right;
98+
}
99+
100+
template<typename CharType>
101+
inline bool operator==(ice::BasicString<CharType> left, ice::HeapVarString<CharType> const& right) noexcept
102+
{
103+
return left == ice::BasicString<CharType>{ right };
104+
}
105+
90106
template<typename CharType>
91107
inline HeapVarString<CharType>::operator ice::BasicString<CharType>() const noexcept
92108
{
@@ -102,5 +118,59 @@ namespace ice
102118
}
103119
}
104120

121+
template<typename CharType>
122+
inline HeapVarString<CharType>::operator ice::VarStringBase<CharType>() const noexcept
123+
{
124+
return _data;
125+
}
126+
127+
namespace string
128+
{
129+
130+
template<typename CharType>
131+
inline void clear(ice::HeapVarString<CharType>& str) noexcept
132+
{
133+
str._allocator->deallocate(ice::exchange(str._data, nullptr));
134+
}
135+
136+
template<typename CharType>
137+
inline auto begin(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::Iterator
138+
{
139+
return ice::string::detail::data_varstring(str._data);
140+
}
141+
142+
template<typename CharType>
143+
inline auto end(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::Iterator
144+
{
145+
ice::ucount bytes;
146+
ice::ucount const size = ice::string::detail::read_varstring_size(str._data, bytes);
147+
return str._data + bytes + size;
148+
}
149+
150+
template<typename CharType>
151+
auto deserialize(ice::HeapVarString<CharType>& str, ice::Data data) noexcept -> ice::Data
152+
{
153+
ICE_ASSERT_CORE(data.size >= 2_B); // 1 byte for size + 1 for a single character
154+
ice::string::clear(str); // Clear the current contents
155+
156+
ice::ucount bytes;
157+
ice::ucount const size = ice::string::detail::read_varstring_size(
158+
reinterpret_cast<char const*>(data.location), bytes
159+
);
160+
if (size > 0)
161+
{
162+
char* const new_str = ice::string::detail::allocate_varstring_exact(*str._allocator, size, bytes);
163+
if (new_str != nullptr)
164+
{
165+
ice::memcpy(new_str + bytes, ice::ptr_add(data.location, ice::usize{ bytes }), size);
166+
new_str[bytes + size] = '\0';
167+
}
168+
str._data = new_str; // Assign the new allocated data
169+
}
170+
171+
return ice::ptr_add(data, { bytes + size });
172+
}
173+
174+
} // namespace string
105175

106176
} // namespace ice

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@ namespace ice
9292
return false;
9393
}
9494

95-
template<typename CharType>
96-
constexpr bool BasicString<CharType>::operator!=(BasicString other) const noexcept
97-
{
98-
return !(*this == other);
99-
}
100-
10195
template<typename CharType>
10296
constexpr BasicString<CharType>::operator std::basic_string_view<CharType>() const noexcept
10397
{

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ namespace ice
5555
return data + bytes;
5656
}
5757

58+
inline auto write_varstring_size(void* data, ice::ucount size) noexcept -> ice::ucount
59+
{
60+
ice::ucount bytes = 0;
61+
ice::u8* var_byte = reinterpret_cast<ice::u8*>(data);
62+
while (size > 0x7f)
63+
{
64+
var_byte[bytes] = (size & 0x7f) | 0x80;
65+
size >>= 7;
66+
bytes += 1;
67+
}
68+
var_byte[bytes] = size & 0x7f;
69+
return bytes + 1;
70+
}
71+
5872
} // namespace detail
5973

6074
template<typename CharType>
@@ -107,10 +121,7 @@ namespace ice
107121
template<ice::string::VarStringType StringType>
108122
inline auto begin(StringType const& str) noexcept -> typename StringType::ConstIterator
109123
{
110-
ice::ucount bytes = 0;
111-
[[maybe_unused]]
112-
ice::ucount const size = ice::string::detail::read_varstring_size(str._data, bytes);
113-
return str._data + bytes;
124+
return ice::string::detail::data_varstring(str._data);
114125
}
115126

116127
template<ice::string::VarStringType StringType>
@@ -133,6 +144,24 @@ namespace ice
133144
};
134145
}
135146

147+
auto serialize(ice::string::VarStringType auto const& str, ice::Memory target) noexcept -> ice::Memory
148+
{
149+
ice::ucount const size = ice::string::size(str);
150+
ICE_ASSERT_CORE(
151+
ice::string::detail::calc_varstring_required_size(size) <= target.size.value
152+
);
153+
154+
ice::ucount const sizebytes = ice::string::detail::write_varstring_size(target.location, size);
155+
target.location = ice::ptr_add(target.location, ice::usize{ sizebytes });
156+
target.size.value -= sizebytes;
157+
158+
ice::memcpy(target.location, str._data + sizebytes, size);
159+
target.location = ice::ptr_add(target.location, ice::usize{ size });
160+
target.size.value -= size;
161+
target.alignment = ice::ualign::b_1;
162+
return target;
163+
}
164+
136165
} // namespace string
137166

138167
} // namespace ice

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,6 @@ namespace ice::string
4848
template<typename CharType>
4949
inline void pop_back(ice::HeapVarString<CharType>& str, ice::ucount count = 1) noexcept;
5050

51-
template<typename CharType>
52-
inline auto begin(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::Iterator;
53-
54-
template<typename CharType>
55-
inline auto end(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::Iterator;
56-
57-
template<typename CharType>
58-
inline auto rbegin(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::ReverseIterator;
59-
60-
template<typename CharType>
61-
inline auto rend(ice::HeapVarString<CharType>& str) noexcept -> typename ice::HeapVarString<CharType>::ReverseIterator;
62-
6351

6452
inline auto size(ice::string::VarStringType auto const& str) noexcept -> ice::ucount;
6553

@@ -114,6 +102,8 @@ namespace ice::string
114102
template<typename CharType>
115103
inline auto extract_memory(ice::VarStringBase<CharType>& str) noexcept -> ice::Memory;
116104

105+
inline auto serialize(ice::string::VarStringType auto const& str, ice::Memory target) noexcept -> ice::Memory;
106+
117107
} // namespace ice::string
118108

119109
namespace ice

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55
#include <ice/mem_data.hxx>
66
#include <ice/mem_allocator.hxx>
7+
#include <ice/mem_utils.hxx>
78
#include <ice/container_logic.hxx>
89
#include <ice/stringid.hxx>
910

@@ -42,7 +43,6 @@ namespace ice
4243
constexpr auto operator[](ice::ucount index) const noexcept -> CharType const&;
4344

4445
constexpr bool operator==(BasicString other) const noexcept;
45-
constexpr bool operator!=(BasicString other) const noexcept;
4646

4747
constexpr operator std::basic_string_view<CharType>() const noexcept;
4848
};
@@ -189,6 +189,7 @@ namespace ice
189189
inline auto operator[](ice::ucount idx) const noexcept -> CharType const&;
190190

191191
inline operator ice::BasicString<CharType>() const noexcept;
192+
inline operator ice::VarStringBase<CharType>() const noexcept;
192193
};
193194

194195
static_assert(ice::TrivialContainerLogicAllowed<ice::String>);

source/code/core/devui/devui.bff

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,18 @@
2121
'imgui'
2222
}
2323
]
24+
25+
.Rule_Win32Editor =
26+
[
27+
.Name = 'EditorPlugins'
28+
.Requires = { 'Windows' }
29+
.Public =
30+
[
31+
.Modules = {
32+
'imguizmo'
33+
}
34+
]
35+
]
36+
.Rules = { .Rule_Win32Editor }
2437
]
2538
.Projects + .Project

source/code/core/devui/private/devui_context.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <ice/log.hxx>
88
#include <imgui/imgui.h>
99

10+
#if ISP_WINDOWS
11+
#include <imguizmo/ImGuizmo.h>
12+
#endif
13+
1014
namespace ice
1115
{
1216

@@ -76,10 +80,18 @@ namespace ice
7680
if (context_name == "devui-context/imgui"_sid)
7781
{
7882
ICE_ASSERT_CORE(ImGui::GetCurrentContext() == nullptr || ImGui::GetCurrentContext() == params.native_context);
83+
// TODO: Try to move it away from here
7984
ImGui::SetAllocatorFunctions(params.fn_alloc, params.fn_dealloc, params.alloc_userdata);
8085
ImGui::SetCurrentContext((ImGuiContext*)params.native_context);
8186
return true;
8287
}
88+
#if ISP_WINDOWS
89+
else if (context_name == "devui-context/imguizmo"_sid)
90+
{
91+
ImGuizmo::SetImGuizmoContext((ImGuizmo::ImGuizmoContext*)params.native_context);
92+
return true;
93+
}
94+
#endif
8395
return false;
8496
}
8597

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <ice/math/translate.hxx>
1616
#include <ice/math/scale.hxx>
1717
#include <ice/math/rotate.hxx>
18+
#include <ice/math/decompose.hxx>
1819
#include <ice/shard.hxx>
1920

2021
namespace ice

source/code/core/math/public/ice/math/common.hxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace ice::math
1111

1212
constexpr auto radians(deg degrees) noexcept -> rad;
1313

14+
constexpr auto degrees(rad radians) noexcept -> deg;
15+
1416
inline auto sqrt(f32 val) noexcept -> f32;
1517

1618
inline auto sin(rad radians) noexcept -> f32;
@@ -19,12 +21,19 @@ namespace ice::math
1921

2022
inline auto tan(rad radians) noexcept -> f32;
2123

24+
inline auto atan2(f32 x, f32 y) noexcept -> f32;
25+
2226

2327
constexpr auto radians(deg degrees) noexcept -> rad
2428
{
2529
return rad{ degrees.value * (ice::math::const_pi / 180.f) };
2630
}
2731

32+
constexpr auto degrees(rad radians) noexcept -> deg
33+
{
34+
return deg{ (radians.value * 180.f) / ice::math::const_pi };
35+
}
36+
2837
inline auto sqrt(f32 val) noexcept -> f32
2938
{
3039
return std::sqrt(val);
@@ -45,4 +54,9 @@ namespace ice::math
4554
return std::tan(radians.value);
4655
}
4756

57+
inline auto atan2(f32 x, f32 y) noexcept -> f32
58+
{
59+
return std::atan2(x, y);
60+
}
61+
4862
} // namespace ice::math

0 commit comments

Comments
 (0)