Hi everyone,
I have been working on an asset system I have architected similarly to the one Casey did in Handmade Hero.
The requirements in my system turned out to be different though, since I don't store "raw" decoded data along with its size in files like Casey does for .hha files. (Maybe this has changed in newer episodes though?)
For instance, I store glyphs in ttf-s and rasterize them with
freetype2 on the fly.
Here's an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 | internal_fn void
load_font(Assets *assets, Font_ID id)
{
if (interlocked_exchange(assets->fonts[id.value].state, Asset_State_Queued, Asset_State_Unloaded)) {
// NOTE(Matyas): Allocate font slot, from the Asset stack arena
Loaded_Font *font = Push_Struct(&assets->arena, Loaded_Font);
// NOTE(Matyas): Initialize font struct...
Load_Font_Work *work = Push_Freelist_Node(&assets->work_freelist, Load_Font_Work);
// NOTE(Matyas): Initialize work struct...
// NOTE(Matyas): Start thread
Platform->add_entry(assets->high_queue, decode_font_work, work);
} else {
assets->fonts[id.value].state = Asset_State_Unloaded;
}
}
// NOTE(Matyas): This is called by load_font, runs on a separate thread!
thread_safe internal_fn
WORK_QUEUE_CALLBACK(decode_font_work)
{
// NOTE(Matyas): Load the font from file, then decode it
}
|
The issue I have is that I am decoding data on-the-fly, so I don't _actually know_ what size I should allocate for in
load_font for the decoded asset. This means of course that I can't actually make my allocation in load_font implying I have to do it in
decode_font_work.
The issue with this is that since
decode_font_work can allocate at any time from any thread, a simple stack or free list allocation strategy wouldn't work... (at least that's my assumption)
Can anyone suggest a good way to architect such a system memory/allocation-wise?
Any suggestion is much much appreciated!
PS.
Sorry if this issue came up before, I haven't found anything similar to this case.