Skip to content

Commit 2861c33

Browse files
committed
[iceshard] Introduced a few ProxyAllocators for better tracking.
1 parent bb64540 commit 2861c33

File tree

11 files changed

+47
-36
lines changed

11 files changed

+47
-36
lines changed

source/code/iceshard/iceshard/private/iceshard_trait_context.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
namespace ice
1111
{
1212

13-
IceshardWorldContext::IceshardWorldContext(ice::Allocator& alloc) noexcept
14-
: _allocator{ alloc }
13+
IceshardWorldContext::IceshardWorldContext(ice::Allocator& alloc, ice::StringID_Arg worldid) noexcept
14+
: _allocator{ alloc, ice::stringid_hint(worldid) }
1515
, _always_reached_checkpoint{ true }
1616
, _checkpoints{ alloc }
1717
, _frame_handlers{ alloc }

source/code/iceshard/iceshard/private/iceshard_trait_context.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ namespace ice
2020

2121
struct IceshardWorldContext
2222
{
23-
IceshardWorldContext(ice::Allocator& alloc) noexcept;
23+
IceshardWorldContext(ice::Allocator& alloc, ice::StringID_Arg worldid) noexcept;
2424

2525
void close_checkpoints() noexcept;
2626

27-
ice::Allocator& _allocator;
27+
ice::ProxyAllocator _allocator;
2828
ice::TaskCheckpoint _always_reached_checkpoint;
2929
ice::HashMap<ice::TaskCheckpoint*> _checkpoints;
3030
ice::HashMap<ice::IceshardEventHandler> _frame_handlers;

source/code/iceshard/iceshard/private/iceshard_world.cxx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ namespace ice
1111
ice::Allocator& alloc,
1212
ice::StringID_Arg worldid,
1313
ice::ecs::EntityStorage& entity_storage,
14-
ice::UniquePtr<ice::IceshardWorldContext> context,
14+
ice::IceshardWorldContext& context,
1515
ice::Array<ice::UniquePtr<ice::IceshardTraitContext>> traits,
1616
ice::detail::TraitTaskTracker* task_tracker
1717
) noexcept
1818
: worldID{ worldid }
19+
, _allocator{ alloc, "world-data" }
1920
, _entity_storage{ entity_storage }
20-
, _entity_operations{ alloc, 16 }
21-
, _context{ ice::move(context) }
21+
, _entity_operations{ _allocator, 16 }
2222
, _traits{ ice::move(traits) }
23-
, _tasks_launcher{ *_context, ice::array::slice(_traits), task_tracker }
24-
, _devui{ create_devui(alloc) }
23+
, _tasks_launcher{ context, ice::array::slice(_traits), task_tracker }
24+
, _devui{ create_devui(_allocator, context) }
2525
{
2626
}
2727

@@ -30,8 +30,6 @@ namespace ice
3030
_entity_storage.execute_operations(_entity_operations, out_shards);
3131
_entity_operations.clear();
3232

33-
_context->close_checkpoints();
34-
3533
// Sync trait events
3634
for (ice::UniquePtr<ice::IceshardTraitContext>& trait : _traits)
3735
{

source/code/iceshard/iceshard/private/iceshard_world.hxx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace ice
2222
ice::Allocator& alloc,
2323
ice::StringID_Arg worldid,
2424
ice::ecs::EntityStorage& entity_storage,
25-
ice::UniquePtr<ice::IceshardWorldContext> context,
25+
ice::IceshardWorldContext& context,
2626
ice::Array<ice::UniquePtr<ice::IceshardTraitContext>> traits,
2727
ice::detail::TraitTaskTracker* task_tracker
2828
) noexcept;
@@ -47,15 +47,18 @@ namespace ice
4747
auto devui() noexcept -> DevUI&;
4848

4949
private:
50+
ice::ProxyAllocator _allocator;
5051
ice::ecs::EntityStorage& _entity_storage;
5152
ice::ecs::EntityOperations _entity_operations;
52-
ice::UniquePtr<ice::IceshardWorldContext> _context;
5353
ice::Array<ice::UniquePtr<ice::IceshardTraitContext>> _traits;
5454
ice::IceshardTasksLauncher _tasks_launcher;
5555

5656
private:
5757
ice::UniquePtr<DevUI> _devui;
58-
auto create_devui(ice::Allocator& alloc) noexcept -> ice::UniquePtr<DevUI>;
58+
auto create_devui(
59+
ice::Allocator& alloc,
60+
ice::IceshardWorldContext& context
61+
) noexcept -> ice::UniquePtr<DevUI>;
5962
};
6063

6164
} // namespace ice

source/code/iceshard/iceshard/private/iceshard_world_devui.cxx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@ namespace ice
1616

1717
} // namespace detail
1818

19-
auto IceshardWorld::create_devui(ice::Allocator& alloc) noexcept -> ice::UniquePtr<IceshardWorld::DevUI>
19+
auto IceshardWorld::create_devui(
20+
ice::Allocator& alloc,
21+
ice::IceshardWorldContext& context
22+
) noexcept -> ice::UniquePtr<IceshardWorld::DevUI>
2023
{
2124
if (ice::devui_available())
2225
{
23-
return ice::make_unique<DevUI>(alloc, alloc, *this);
26+
return ice::make_unique<DevUI>(alloc, alloc, *this, context);
2427
}
2528
return {};
2629
}
2730

2831
IceshardWorld::DevUI::DevUI(
2932
ice::Allocator& alloc,
30-
ice::IceshardWorld& world
33+
ice::IceshardWorld& world,
34+
ice::IceshardWorldContext& context
3135
) noexcept
3236
: DevUIWidget{ {.category = "Engine/Worlds", .name=ice::stringid_hint(world.worldID)} }
3337
, _allocator{ alloc }
3438
, _world{ world }
39+
, _context{ context }
3540
{
3641
ice::devui_register_widget(this);
3742
}
@@ -71,7 +76,7 @@ namespace ice
7176

7277
if (ImGui::CollapsingHeader("Handlers"))
7378
{
74-
IceshardWorldContext const& ctx = *_world._context;
79+
IceshardWorldContext const& ctx = _context;
7580
ImGui::TextT("Frame handlers (count: {})", ice::hashmap::count(ctx._frame_handlers));
7681
if (ice::hashmap::any(ctx._frame_handlers))
7782
{

source/code/iceshard/iceshard/private/iceshard_world_devui.hxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace ice
1414
public:
1515
DevUI(
1616
ice::Allocator& alloc,
17-
ice::IceshardWorld& world
17+
ice::IceshardWorld& world,
18+
ice::IceshardWorldContext& context
1819
) noexcept;
1920

2021
void build_content() noexcept override;
@@ -23,6 +24,7 @@ namespace ice
2324
private:
2425
ice::Allocator& _allocator;
2526
ice::IceshardWorld& _world;
27+
ice::IceshardWorldContext& _context;
2628
};
2729

2830
} // namespace ice

source/code/iceshard/iceshard/private/iceshard_world_manager.cxx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ namespace ice
102102
world_template.name
103103
);
104104

105-
ice::UniquePtr<ice::IceshardWorldContext> world_context = ice::make_unique<ice::IceshardWorldContext>(_allocator, _allocator);
105+
ice::UniquePtr<ice::IceshardWorldContext> world_context = ice::make_unique<ice::IceshardWorldContext>(
106+
_allocator, _allocator, world_template.name
107+
);
106108
ice::Array<ice::UniquePtr<ice::IceshardTraitContext>, ice::ContainerLogic::Complex> world_traits{ _allocator };
107109
for (ice::StringID_Arg traitid : world_template.traits)
108110
{
@@ -115,9 +117,9 @@ namespace ice
115117
if (desc != nullptr)
116118
{
117119
ice::UniquePtr<ice::IceshardTraitContext> trait_context = ice::make_unique<ice::IceshardTraitContext>(
118-
_allocator, *world_context.get(), ice::array::count(world_traits)
120+
world_context->_allocator, *world_context.get(), ice::array::count(world_traits)
119121
);
120-
ice::UniquePtr<ice::Trait> trait = desc->fn_factory(_allocator, *trait_context.get(), desc->fn_factory_userdata);
122+
ice::UniquePtr<ice::Trait> trait = desc->fn_factory(world_context->_allocator, *trait_context.get(), desc->fn_factory_userdata);
121123
if (trait != nullptr)
122124
{
123125
trait_context->trait = ice::move(trait);
@@ -129,17 +131,16 @@ namespace ice
129131
_state_tracker.register_subname(world_template.name);
130132
//_state_tracker.initialize_subname_state(ice::StateGraph_WorldState, world_template.name);
131133

132-
Entry world_entry{
133-
.world = ice::make_unique<ice::IceshardWorld>(
134-
_allocator,
135-
_allocator,
136-
world_template.name,
137-
world_template.entity_storage,
138-
ice::move(world_context),
139-
ice::move(world_traits),
140-
_devui_tasks.get()
141-
),
142-
};
134+
Entry world_entry{ .context = ice::move(world_context) };
135+
world_entry.world = ice::make_unique<ice::IceshardWorld>(
136+
_allocator,
137+
world_entry.context->_allocator,
138+
world_template.name,
139+
world_template.entity_storage,
140+
*world_entry.context,
141+
ice::move(world_traits),
142+
_devui_tasks.get()
143+
);
143144

144145
// Add a new pending event
145146
ice::shards::push_back(
@@ -205,6 +206,7 @@ namespace ice
205206
{
206207
for (Entry& world_entry : ice::hashmap::values(_worlds))
207208
{
209+
world_entry.context->close_checkpoints();
208210
world_entry.world->pre_update(out_shards);
209211
}
210212
}

source/code/iceshard/iceshard/private/iceshard_world_manager.hxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace ice
7171

7272
struct Entry
7373
{
74+
ice::UniquePtr<ice::IceshardWorldContext> context;
7475
ice::UniquePtr<ice::IceshardWorld> world;
7576
bool is_active;
7677
};

source/code/modules/imgui_module/private/imgui_trait.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace ice::devui
3232
ImGuiTrait::ImGuiTrait(ice::TraitContext& ctx, ice::Allocator& alloc, ImGuiSystem& system) noexcept
3333
: ice::Trait{ ctx }
3434
, ice::TraitDevUI{ {.category="Traits/Debug",.name="ImGUI-DevUI"} }
35-
, _allocator{ alloc }
35+
, _allocator{ alloc, "trait:devui-imgui" }
3636
, _system{ system }
3737
, _imgui_gfx_stage{ }
3838
, _resized{ false }

source/code/modules/imgui_module/private/imgui_trait.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace ice::devui
5050
void build_internal_command_list(ice::Span<ImGuiGfxStage::DrawCommand> draw_cmds) noexcept;
5151

5252
private:
53-
ice::Allocator& _allocator;
53+
ice::ProxyAllocator _allocator;
5454
ice::devui::ImGuiSystem& _system;
5555
ice::devui::ImGuiStats _stats;
5656
ice::UniquePtr<ImGuiGfxStage> _imgui_gfx_stage;

0 commit comments

Comments
 (0)