Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/code/core/collections/public/ice/sort.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ namespace ice
return false;
}

template<typename T, typename Comp, typename... U>
constexpr bool search_with(ice::Span<T> values, Comp&& comp, ice::ucount& out_index, U const&... params) noexcept
{
for (ice::u32 idx = 0; idx < ice::span::count(values); ++idx)
{
if (ice::forward<Comp>(comp)(values[idx], idx, params...))
{
out_index = idx;
return true;
}
}
return false;
}

namespace detail
{

Expand Down
4 changes: 2 additions & 2 deletions source/code/core/devui/private/devui_widget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace ice
{

DevUIWidget::DevUIWidget(ice::DevUIWidgetInfo const& info) noexcept
: info{ info }
: widget_info{ info }
{
}

void DevUIWidget::build_widget(ice::DevUIFrame& frame, ice::DevUIWidgetState& state) noexcept
{
if (frame.begin(info, state))
if (frame.begin(widget_info, state))
{
this->build_menu();
this->build_content();
Expand Down
2 changes: 1 addition & 1 deletion source/code/core/devui/public/ice/devui_widget.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace ice

virtual bool build_mainmenu(ice::DevUIWidgetState& state) noexcept;

ice::DevUIWidgetInfo const info;
ice::DevUIWidgetInfo const widget_info;
};

} // namespace ice
29 changes: 27 additions & 2 deletions source/code/core/math/public/ice/math/matrix.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@ namespace ice::math
struct mat
{
using value_type = T;
static constexpr auto count_rows = Rows;
static constexpr auto count_columns = Cols;
static constexpr u32 count_rows = Rows;
static constexpr u32 count_columns = Cols;

T v[count_columns][count_rows];
};

template<typename T>
struct mat<2, 2, T>
{
using value_type = T;
static constexpr u32 count_rows = 3;
static constexpr u32 count_columns = 3;

T v[count_columns][count_rows];

template<typename U>
constexpr operator mat<3, 3, U>() noexcept;
};


template<typename Mat>
constexpr auto identity() noexcept;
Expand All @@ -31,6 +44,18 @@ namespace ice::math
using mat4x4 = mat<4, 4, f32>;
using mat4 = mat4x4;

template<typename T>
template<typename U>
constexpr mat<2, 2, T>::operator mat<3, 3, U>() noexcept
{
mat<3, 3, U> result;
result.v[0][0] = v[0][0];
result.v[0][1] = v[0][1];
result.v[1][0] = v[1][0];
result.v[1][1] = v[1][1];
result.v[2][2] = 1;
return result;
}

template<typename Mat>
constexpr auto identity() noexcept
Expand Down
20 changes: 20 additions & 0 deletions source/code/core/math/public/ice/math/rotate.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,38 @@
namespace ice::math
{

inline auto rotate2d(rad rad) noexcept -> mat<2, 2, f32>;
inline auto rotate(rad rad, vec<3, f32> v) noexcept -> mat<4, 4, f32>;

inline auto rotate2d(mat<2, 2, f32> left, rad rad) noexcept -> mat<2, 2, f32>;
inline auto rotate(mat<4, 4, f32> left, rad rad, vec<3, f32> v) noexcept -> mat<4, 4, f32>;

inline auto rotation(mat<4, 4, f32> const& matrix) noexcept -> vec<3, rad>;


inline auto rotate2d(rad rad) noexcept -> mat<2, 2, f32>
{
return rotate2d(mat2x2_identity, rad);
}

inline auto rotate(rad rad, vec<3, f32> v) noexcept -> mat<4, 4, f32>
{
return rotate(mat4x4_identity, rad, v);
}

inline auto rotate2d(mat<2, 2, f32> left, rad rad) noexcept -> mat<2, 2, f32>
{
f32 const cosv = cos(rad);
f32 const sinv = sin(rad);

mat<2, 2, f32> rm = mat2x2_identity;
rm.v[0][0] = cosv;
rm.v[0][1] = sinv;
rm.v[1][0] = -sinv;
rm.v[1][1] = cosv;
return mul(left, rm);
}

inline auto rotate(mat<4, 4, f32> left, rad rad, vec<3, f32> v) noexcept -> mat<4, 4, f32>
{
f32 const cosv = cos(rad);
Expand Down
15 changes: 15 additions & 0 deletions source/code/core/math/public/ice/math/scale.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,33 @@
namespace ice::math
{

constexpr auto scale2d(vec<2, f32> v) noexcept -> mat<2, 2, f32>;
constexpr auto scale(vec<3, f32> v) noexcept -> mat<4, 4, f32>;

constexpr auto scale2d(mat<2, 2, f32> left, vec<2, f32> right) noexcept -> mat<2, 2, f32>;
constexpr auto scale(mat<4, 4, f32> left, vec<3, f32> right) noexcept -> mat<4, 4, f32>;

constexpr auto scale(mat<4, 4, f32> const& matrix) noexcept -> vec<3, f32>;


constexpr auto scale2d(vec<2, f32> v) noexcept -> mat<2, 2, f32>
{
return scale2d(mat2x2_identity, v);
}

constexpr auto scale(vec<3, f32> v) noexcept -> mat<4, 4, f32>
{
return scale(mat4x4_identity, v);
}

constexpr auto scale2d(mat<2, 2, f32> left, vec<2, f32> right) noexcept -> mat<2, 2, f32>
{
mat<2, 2, f32> temp{ };
temp.v[0][0] = right.v[0][0];
temp.v[1][1] = right.v[0][1];
return mul(left, temp);
}

constexpr auto scale(mat<4, 4, f32> left, vec<3, f32> right) noexcept -> mat<4, 4, f32>
{
mat<4, 4, f32> temp{ };
Expand Down
20 changes: 20 additions & 0 deletions source/code/core/math/public/ice/math/translate.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,33 @@
namespace ice::math
{

constexpr auto translate(vec<2, f32> displacement) noexcept -> mat<3, 3, f32>;
constexpr auto translate(vec<3, f32> displacement) noexcept -> mat<4, 4, f32>;

constexpr auto translate(mat<3, 3, f32> left, vec<2, f32> right) noexcept -> mat<3, 3, f32>;
constexpr auto translate(mat<4, 4, f32> left, vec<3, f32> right) noexcept -> mat<4, 4, f32>;

constexpr auto translation(mat<3, 3, f32> const& matrix) noexcept -> vec<2, f32>;
constexpr auto translation(mat<4, 4, f32> const& matrix) noexcept -> vec<3, f32>;


constexpr auto translate(vec<2, f32> displacement) noexcept -> mat<3, 3, f32>
{
return translate(mat3x3_identity, displacement);
}

constexpr auto translate(vec<3, f32> displacement) noexcept -> mat<4, 4, f32>
{
return translate(mat4x4_identity, displacement);
}

constexpr auto translate(mat<3, 3, f32> left, vec<2, f32> right) noexcept -> mat<3, 3, f32>
{
left.v[2][0] += right.v[0][0];
left.v[2][1] += right.v[0][1];
return left;
}

constexpr auto translate(mat<4, 4, f32> left, vec<3, f32> right) noexcept -> mat<4, 4, f32>
{
left.v[3][0] += right.v[0][0];
Expand All @@ -27,6 +42,11 @@ namespace ice::math
return left;
}

constexpr auto translation(mat<3, 3, f32> const& matrix) noexcept -> vec<2, f32>
{
return { matrix.v[2][0], matrix.v[2][1] };
}

constexpr auto translation(mat<4, 4, f32> const& matrix) noexcept -> vec<3, f32>
{
return { matrix.v[3][0], matrix.v[3][1], matrix.v[3][2] };
Expand Down
4 changes: 4 additions & 0 deletions source/code/core/math/public/ice/math/vector.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ namespace ice::math
: v{ { static_cast<T>(other.x), static_cast<T>(other.y) } }
{ }

constexpr explicit mat(T const(&array)[3]) noexcept
: v{ { array[0] / array[2], array[1] / array[2] } }
{ }

union
{
T v[count_columns][count_rows];
Expand Down
17 changes: 17 additions & 0 deletions source/code/core/utils/public/ice/algorithm.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// Copyright 2025 - 2025, Dandielo <[email protected]>
/// SPDX-License-Identifier: MIT

#pragma once
#include <algorithm>
#include <numeric>

namespace ice
{

template<typename T, typename U = T>
constexpr auto accumulate(ice::Span<T const> range, U val) noexcept
{
return ::std::accumulate(ice::begin(range), ice::end(range), val);
}

} // namespace ice
9 changes: 3 additions & 6 deletions source/code/example/webasm/private/example_webasm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct TestTrait : public ice::Trait
ice::Timer timer;

using TestArchetype = ice::ecs::ArchetypeDefinition<C1, C2>;
static constexpr ice::ecs::ArchetypeDefinition Archetype_TestArchetype = TestArchetype{};
static constexpr ice::ecs::ArchetypeDefinition Archetype_TestArchetype = TestArchetype{ "test-arch" };

ice::ecs::EntityOperations* _ops;
ice::ecs::Entity _my_entity[10000];
Expand All @@ -123,8 +123,7 @@ struct TestTrait : public ice::Trait

update.engine.entity_index().create_many(_my_entity);
_ops = ice::addressof(update.world.entity_operations());

ice::ecs::queue_set_archetype(*_ops, _my_entity, Archetype_TestArchetype);
_ops->set("test-arch", _my_entity);

ICE_LOG(LogSeverity::Retail, LogTag::Game, "Test Activated!");
timer = ice::timer::create_timer(update.clock, 100_Tms);
Expand All @@ -138,7 +137,7 @@ struct TestTrait : public ice::Trait
query<ice::ecs::Entity>().tags<C1, C2>().for_each_block(
[&](ice::ucount count, ice::ecs::Entity const* entities) noexcept
{
ice::ecs::queue_batch_remove_entities(*_ops, { entities, count });
_ops->destroy({ entities, count });
}
);

Expand Down Expand Up @@ -187,9 +186,7 @@ struct TestTrait : public ice::Trait
ICE_LOG(LogSeverity::Info, LogTag::Game, "TestTrait::logic {}", x.load());
}

ICE_LOG(LogSeverity::Debug, LogTag::Game, "{}", std::hash<std::thread::id>{}(std::this_thread::get_id()));
co_await ice::await_scheduled_on(tasks, update.thread.tasks, update.thread.main);
ICE_LOG(LogSeverity::Debug, LogTag::Game, "{}", std::hash<std::thread::id>{}(std::this_thread::get_id()));
co_return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ auto ice_game_frame(
state.platform.core->refresh_events();
ice::ShardContainer const& system_events = state.platform.core->system_events();

// Update the system clock
ice::clock::update(runtime.clock);
ice::clock::update(runtime.game_clock);

ice::UniquePtr<ice::EngineFrame> new_frame = co_await logic.aquire_frame();
Expand Down Expand Up @@ -636,9 +638,6 @@ auto ice_update(
ice::app::Runtime& runtime
) noexcept -> ice::Result
{
// Update the system clock
ice::clock::update(runtime.clock);

// Process any awaiting main thread tasks.
runtime.main_queue.process_all();

Expand Down
33 changes: 12 additions & 21 deletions source/code/iceshard/engine/private/ecs/ecs_archetype_index.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ namespace ice::ecs
return base_offset;
}

auto contains_required_components(
bool contains_required_components(
ice::Span<ice::ecs::detail::QueryTypeInfo const> in_conditions,
ice::Span<ice::StringID const> in_required_tags,
ice::Span<ice::StringID const> checked_identifiers
) noexcept -> ice::u32
) noexcept
{
using QueryTypeInfo = ice::ecs::detail::QueryTypeInfo;

Expand Down Expand Up @@ -65,6 +65,7 @@ namespace ice::ecs
}

// As long as we have something to check and we did not fail search for the next ID
[[maybe_unused]]
ice::u32 matched_components = 0;

// Reset for checking the remaining conditions
Expand Down Expand Up @@ -93,7 +94,7 @@ namespace ice::ecs
matched_components += (identifier_hash == condition_hash);
}

return result ? matched_components : 0;
return result;
}

} // namespace detail
Expand Down Expand Up @@ -171,6 +172,7 @@ namespace ice::ecs

auto ArchetypeIndex::register_archetype(
ice::ecs::ArchetypeInfo const& archetype_info,
ice::ecs::detail::DataBlockFilter data_block_filter,
ice::ecs::detail::DataBlockPool* data_block_pool
) noexcept -> ice::ecs::Archetype
{
Expand Down Expand Up @@ -255,6 +257,7 @@ namespace ice::ecs

data_header->archetype_name = ice::String{ (char const*) mem_archetype_name.location, ice::size(archetype_info.name) };
data_header->archetype_identifier = archetype_info.identifier;
data_header->archetype_info.data_block_filter = data_block_filter;
data_header->archetype_info.component_identifiers = ice::Span<ice::StringID const>{ component_identifiers, component_count };
data_header->archetype_info.component_sizes = ice::Span<ice::u32 const>{ component_sizes, component_count };
data_header->archetype_info.component_alignments = ice::Span<ice::u32 const>{ component_alignments, component_count };
Expand All @@ -264,23 +267,11 @@ namespace ice::ecs
// We need now to calculate the number of entities that we can store in the remaining memory.
// Additionally calculate the offets each component array will be located at.
{
ice::u32 const component_size_sum = std::accumulate(
component_sizes,
component_sizes + component_count,
0
);

ice::u32 const component_alignment_sum = std::accumulate(
component_alignments,
component_alignments + component_count,
0
ice::ucount const component_entity_count_max = ice::ecs::detail::calculate_entity_count_for_space(
data_header->archetype_info,
data_block_pool->provided_block_size()
);

ice::usize const block_size = data_block_pool->provided_block_size();
ice::usize const available_block_size = { block_size.value - component_alignment_sum };

data_header->archetype_info.component_entity_count_max = ice::ucount(available_block_size.value / component_size_sum);

ice::u32 next_component_offset = 0;
for (ice::u32 idx = 0; idx < component_count; ++idx)
{
Expand All @@ -300,7 +291,7 @@ namespace ice::ecs
next_component_offset = ice::ecs::detail::align_forward_u32(next_component_offset, component_alignments[idx]);
component_offsets[idx] = next_component_offset;

next_component_offset += component_sizes[idx] * data_header->archetype_info.component_entity_count_max;
next_component_offset += component_sizes[idx] * component_entity_count_max;
}
}
}
Expand Down Expand Up @@ -377,15 +368,15 @@ namespace ice::ecs
continue;
}

ice::u32 const matched_components = ice::ecs::detail::contains_required_components(
bool const was_matched = ice::ecs::detail::contains_required_components(
query_info,
query_tags,
archetype_info.component_identifiers
);

// If we don't match any component in a full optional query, we still skip this archetype.
// #todo: we should probably also check for the existance of the EntityHandle in the query. Then the check should be `> 1`
if (matched_components > 0)
if (was_matched)
{
ice::array::push_back(out_archetypes, entry->archetype_identifier);
}
Expand Down
Loading