formatting
This commit is contained in:
parent
d18281b6bf
commit
5b07284d02
@ -156,8 +156,6 @@ void P_AppStartup(String args_str)
|
||||
(UNUSED)connect_address;
|
||||
(UNUSED)GetDefaultAppWindowSettings;
|
||||
|
||||
|
||||
|
||||
#if !RtcIsEnabled
|
||||
/* Verify test modes aren't left on by accident in release mode */
|
||||
StaticAssert(BITBUFF_DEBUG == 0);
|
||||
|
||||
@ -6,11 +6,11 @@
|
||||
////////////////////////////////
|
||||
//~ Shared constants
|
||||
|
||||
Global Readonly u32 Ase_huff_hclen_order[] = {
|
||||
Global Readonly u32 ASE_huff_hclen_order[] = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||
};
|
||||
|
||||
Global Readonly Ase_HuffEntry Ase_huff_length_table[] = {
|
||||
Global Readonly ASE_HuffEntry ASE_huff_length_table[] = {
|
||||
{3, 0}, /* 257 */
|
||||
{4, 0}, /* 258 */
|
||||
{5, 0}, /* 259 */
|
||||
@ -42,7 +42,7 @@ Global Readonly Ase_HuffEntry Ase_huff_length_table[] = {
|
||||
{258, 0}, /* 285 */
|
||||
};
|
||||
|
||||
Global Readonly Ase_HuffEntry Ase_huff_dist_table[] = {
|
||||
Global Readonly ASE_HuffEntry ASE_huff_dist_table[] = {
|
||||
{1, 0}, /* 0 */
|
||||
{2, 0}, /* 1 */
|
||||
{3, 0}, /* 2 */
|
||||
@ -75,7 +75,7 @@ Global Readonly Ase_HuffEntry Ase_huff_dist_table[] = {
|
||||
{24577, 13}, /* 29 */
|
||||
};
|
||||
|
||||
Global Readonly u32 Ase_huff_bl_counts[][2] = {
|
||||
Global Readonly u32 ASE_huff_bl_counts[][2] = {
|
||||
{143, 8},
|
||||
{255, 9},
|
||||
{279, 7},
|
||||
@ -86,7 +86,7 @@ Global Readonly u32 Ase_huff_bl_counts[][2] = {
|
||||
////////////////////////////////
|
||||
//~ Ase bitbuff
|
||||
|
||||
u32 Ase_PeekBits(Ase_Bitbuff *bb, u32 nbits)
|
||||
u32 ASE_PeekBits(ASE_Bitbuff *bb, u32 nbits)
|
||||
{
|
||||
Assert(nbits <= 32);
|
||||
|
||||
@ -102,14 +102,14 @@ u32 Ase_PeekBits(Ase_Bitbuff *bb, u32 nbits)
|
||||
return val32;
|
||||
}
|
||||
|
||||
u32 Ase_ConsumeBits(Ase_Bitbuff *bb, u32 nbits)
|
||||
u32 ASE_ConsumeBits(ASE_Bitbuff *bb, u32 nbits)
|
||||
{
|
||||
u32 val = Ase_PeekBits(bb, nbits);
|
||||
u32 val = ASE_PeekBits(bb, nbits);
|
||||
bb->cur_bit += nbits;
|
||||
return val;
|
||||
}
|
||||
|
||||
void Ase_SkipBits(Ase_Bitbuff *bb, u32 nbits)
|
||||
void ASE_SkipBits(ASE_Bitbuff *bb, u32 nbits)
|
||||
{
|
||||
bb->cur_bit += nbits;
|
||||
}
|
||||
@ -117,7 +117,7 @@ void Ase_SkipBits(Ase_Bitbuff *bb, u32 nbits)
|
||||
////////////////////////////////
|
||||
//~ Inflate
|
||||
|
||||
u32 Ase_ReverseBits(u32 v, u32 bit_count)
|
||||
u32 ASE_ReverseBits(u32 v, u32 bit_count)
|
||||
{
|
||||
/* 7 & 15 seem to be the most common bit_counts, so a
|
||||
* more optimal path is layed out for them. */
|
||||
@ -157,16 +157,16 @@ u32 Ase_ReverseBits(u32 v, u32 bit_count)
|
||||
}
|
||||
}
|
||||
|
||||
Ase_HuffDict Ase_InitHuffDict(Arena *arena, u32 max_code_bits, u32 *bl_counts, u32 bl_counts_count)
|
||||
ASE_HuffDict ASE_InitHuffDict(Arena *arena, u32 max_code_bits, u32 *bl_counts, u32 bl_counts_count)
|
||||
{
|
||||
__prof;
|
||||
|
||||
Ase_HuffDict result = ZI;
|
||||
ASE_HuffDict result = ZI;
|
||||
result.max_code_bits = max_code_bits;
|
||||
result.entries_count = (1 << max_code_bits);
|
||||
result.entries = PushStructsNoZero(arena, Ase_HuffEntry, result.entries_count);
|
||||
result.entries = PushStructsNoZero(arena, ASE_HuffEntry, result.entries_count);
|
||||
|
||||
u32 code_length_hist[Ase_HuffBitCount] = ZI;
|
||||
u32 code_length_hist[ASE_HuffBitCount] = ZI;
|
||||
for (u32 i = 0; i < bl_counts_count; ++i)
|
||||
{
|
||||
u32 count = bl_counts[i];
|
||||
@ -174,7 +174,7 @@ Ase_HuffDict Ase_InitHuffDict(Arena *arena, u32 max_code_bits, u32 *bl_counts, u
|
||||
++code_length_hist[count];
|
||||
}
|
||||
|
||||
u32 next_code[Ase_HuffBitCount] = ZI;
|
||||
u32 next_code[ASE_HuffBitCount] = ZI;
|
||||
next_code[0] = 0;
|
||||
code_length_hist[0] = 0;
|
||||
for (u32 i = 1; i < countof(next_code); ++i)
|
||||
@ -195,8 +195,8 @@ Ase_HuffDict Ase_InitHuffDict(Arena *arena, u32 max_code_bits, u32 *bl_counts, u
|
||||
{
|
||||
/* TODO: Optimize this. It's bloating up the loading times. */
|
||||
u32 base_index = (code << arbitrary_bits) | entry_index;
|
||||
u32 index = Ase_ReverseBits(base_index, result.max_code_bits);
|
||||
Ase_HuffEntry *entry = &result.entries[index];
|
||||
u32 index = ASE_ReverseBits(base_index, result.max_code_bits);
|
||||
ASE_HuffEntry *entry = &result.entries[index];
|
||||
entry->symbol = (u16)i;
|
||||
entry->bits_used = (u16)code_bits;
|
||||
}
|
||||
@ -206,34 +206,34 @@ Ase_HuffDict Ase_InitHuffDict(Arena *arena, u32 max_code_bits, u32 *bl_counts, u
|
||||
return result;
|
||||
}
|
||||
|
||||
u16 Ase_DecodeHuffDict(Ase_HuffDict *huffman, Ase_Bitbuff *bb)
|
||||
u16 ASE_DecodeHuffDict(ASE_HuffDict *huffman, ASE_Bitbuff *bb)
|
||||
{
|
||||
u32 index = Ase_PeekBits(bb, huffman->max_code_bits);
|
||||
u32 index = ASE_PeekBits(bb, huffman->max_code_bits);
|
||||
Assert(index < huffman->entries_count);
|
||||
|
||||
Ase_HuffEntry *entry = &huffman->entries[index];
|
||||
ASE_HuffEntry *entry = &huffman->entries[index];
|
||||
u16 result = entry->symbol;
|
||||
Ase_SkipBits(bb, entry->bits_used);
|
||||
ASE_SkipBits(bb, entry->bits_used);
|
||||
Assert(entry->bits_used > 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Ase_Inflate(u8 *dst, u8 *encoded)
|
||||
void ASE_Inflate(u8 *dst, u8 *encoded)
|
||||
{
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
__prof;
|
||||
Ase_Bitbuff bb = { .data = encoded };
|
||||
ASE_Bitbuff bb = { .data = encoded };
|
||||
|
||||
/* ZLIB header */
|
||||
u32 cm = Ase_ConsumeBits(&bb, 4);
|
||||
u32 cinfo = Ase_ConsumeBits(&bb, 4);
|
||||
u32 cm = ASE_ConsumeBits(&bb, 4);
|
||||
u32 cinfo = ASE_ConsumeBits(&bb, 4);
|
||||
Assert(cm == 8);
|
||||
Assert(cinfo == 7);
|
||||
|
||||
u32 fcheck = Ase_ConsumeBits(&bb, 5);
|
||||
u32 fdict = Ase_ConsumeBits(&bb, 1);
|
||||
u32 flevl = Ase_ConsumeBits(&bb, 2);
|
||||
u32 fcheck = ASE_ConsumeBits(&bb, 5);
|
||||
u32 fdict = ASE_ConsumeBits(&bb, 1);
|
||||
u32 flevl = ASE_ConsumeBits(&bb, 2);
|
||||
Assert(fdict == 0);
|
||||
|
||||
u8 cmf = (u8)(cm | (cinfo << 4));
|
||||
@ -245,48 +245,48 @@ void Ase_Inflate(u8 *dst, u8 *encoded)
|
||||
u8 bfinal = 0;
|
||||
while (!bfinal)
|
||||
{
|
||||
bfinal = Ase_ConsumeBits(&bb, 1);
|
||||
u8 btype = Ase_ConsumeBits(&bb, 2);
|
||||
bfinal = ASE_ConsumeBits(&bb, 1);
|
||||
u8 btype = ASE_ConsumeBits(&bb, 2);
|
||||
switch (btype)
|
||||
{
|
||||
case Ase_BlockType_Uncompressed:
|
||||
case ASE_BlockType_Uncompressed:
|
||||
{
|
||||
Ase_SkipBits(&bb, (8 - (bb.cur_bit % 8)) % 8);
|
||||
i16 len = Ase_ConsumeBits(&bb, 16);
|
||||
i16 nlen = Ase_ConsumeBits(&bb, 16);
|
||||
ASE_SkipBits(&bb, (8 - (bb.cur_bit % 8)) % 8);
|
||||
i16 len = ASE_ConsumeBits(&bb, 16);
|
||||
i16 nlen = ASE_ConsumeBits(&bb, 16);
|
||||
Assert(len == ~nlen); /* Validation */
|
||||
(UNUSED)nlen;
|
||||
while (len-- > 0)
|
||||
{
|
||||
*dst++ = Ase_ConsumeBits(&bb, 8);
|
||||
*dst++ = ASE_ConsumeBits(&bb, 8);
|
||||
}
|
||||
} break;
|
||||
|
||||
case Ase_BlockType_CompressedFixed:
|
||||
case Ase_BlockType_CompressedDynamic:
|
||||
case ASE_BlockType_CompressedFixed:
|
||||
case ASE_BlockType_CompressedDynamic:
|
||||
{
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
u32 lit_len_dist_table[512] = ZI;
|
||||
u32 hlit;
|
||||
u32 hdist;
|
||||
|
||||
if (btype == Ase_BlockType_CompressedDynamic)
|
||||
if (btype == ASE_BlockType_CompressedDynamic)
|
||||
{
|
||||
/* Dynamic table */
|
||||
|
||||
/* Read huffman table */
|
||||
hlit = Ase_ConsumeBits(&bb, 5) + 257;
|
||||
hdist = Ase_ConsumeBits(&bb, 5) + 1;
|
||||
u32 hclen = Ase_ConsumeBits(&bb, 4) + 4;
|
||||
hlit = ASE_ConsumeBits(&bb, 5) + 257;
|
||||
hdist = ASE_ConsumeBits(&bb, 5) + 1;
|
||||
u32 hclen = ASE_ConsumeBits(&bb, 4) + 4;
|
||||
|
||||
/* Init dict huffman (hclen) */
|
||||
u32 hclen_bl_counts[19] = ZI;
|
||||
for (u32 i = 0; i < hclen; ++i)
|
||||
{
|
||||
u32 code = Ase_huff_hclen_order[i];
|
||||
hclen_bl_counts[code] = Ase_ConsumeBits(&bb, 3);
|
||||
u32 code = ASE_huff_hclen_order[i];
|
||||
hclen_bl_counts[code] = ASE_ConsumeBits(&bb, 3);
|
||||
}
|
||||
Ase_HuffDict dict_huffman = Ase_InitHuffDict(temp.arena, 7, hclen_bl_counts, countof(hclen_bl_counts));
|
||||
ASE_HuffDict dict_huffman = ASE_InitHuffDict(temp.arena, 7, hclen_bl_counts, countof(hclen_bl_counts));
|
||||
|
||||
/* Decode dict huffman */
|
||||
u32 lit_len_count = 0;
|
||||
@ -296,24 +296,24 @@ void Ase_Inflate(u8 *dst, u8 *encoded)
|
||||
{
|
||||
u32 rep_count = 1;
|
||||
u32 rep_val = 0;
|
||||
u32 encoded_len = Ase_DecodeHuffDict(&dict_huffman, &bb);
|
||||
u32 encoded_len = ASE_DecodeHuffDict(&dict_huffman, &bb);
|
||||
if (encoded_len <= 15)
|
||||
{
|
||||
rep_val = encoded_len;
|
||||
}
|
||||
else if (encoded_len == 16)
|
||||
{
|
||||
rep_count = 3 + Ase_ConsumeBits(&bb, 2);
|
||||
rep_count = 3 + ASE_ConsumeBits(&bb, 2);
|
||||
Assert(lit_len_count > 0);
|
||||
rep_val = lit_len_dist_table[lit_len_count - 1];
|
||||
}
|
||||
else if (encoded_len == 17)
|
||||
{
|
||||
rep_count = 3 + Ase_ConsumeBits(&bb, 3);
|
||||
rep_count = 3 + ASE_ConsumeBits(&bb, 3);
|
||||
}
|
||||
else if (encoded_len == 18)
|
||||
{
|
||||
rep_count = 11 + Ase_ConsumeBits(&bb, 7);
|
||||
rep_count = 11 + ASE_ConsumeBits(&bb, 7);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -334,10 +334,10 @@ void Ase_Inflate(u8 *dst, u8 *encoded)
|
||||
hlit = 288;
|
||||
hdist = 32;
|
||||
u32 index = 0;
|
||||
for (u32 i = 0; i < countof(Ase_huff_bl_counts); ++i)
|
||||
for (u32 i = 0; i < countof(ASE_huff_bl_counts); ++i)
|
||||
{
|
||||
u32 bit_count = Ase_huff_bl_counts[i][1];
|
||||
u32 last_valuie = Ase_huff_bl_counts[i][0];
|
||||
u32 bit_count = ASE_huff_bl_counts[i][1];
|
||||
u32 last_valuie = ASE_huff_bl_counts[i][0];
|
||||
while (index <= last_valuie)
|
||||
{
|
||||
lit_len_dist_table[index++] = bit_count;
|
||||
@ -346,12 +346,12 @@ void Ase_Inflate(u8 *dst, u8 *encoded)
|
||||
}
|
||||
|
||||
/* Decode */
|
||||
Ase_HuffDict lit_len_huffman = Ase_InitHuffDict(temp.arena, 15, lit_len_dist_table, hlit);
|
||||
Ase_HuffDict dist_huffman = Ase_InitHuffDict(temp.arena, 15, lit_len_dist_table + hlit, hdist);
|
||||
ASE_HuffDict lit_len_huffman = ASE_InitHuffDict(temp.arena, 15, lit_len_dist_table, hlit);
|
||||
ASE_HuffDict dist_huffman = ASE_InitHuffDict(temp.arena, 15, lit_len_dist_table + hlit, hdist);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
u32 lit_len = Ase_DecodeHuffDict(&lit_len_huffman, &bb);
|
||||
u32 lit_len = ASE_DecodeHuffDict(&lit_len_huffman, &bb);
|
||||
if (lit_len <= 255)
|
||||
{
|
||||
*dst++ = lit_len & 0xFF;
|
||||
@ -359,20 +359,20 @@ void Ase_Inflate(u8 *dst, u8 *encoded)
|
||||
else if (lit_len >= 257)
|
||||
{
|
||||
u32 length_index = (lit_len - 257);
|
||||
Ase_HuffEntry length_entry = Ase_huff_length_table[length_index];
|
||||
ASE_HuffEntry length_entry = ASE_huff_length_table[length_index];
|
||||
u32 length = length_entry.symbol;
|
||||
if (length_entry.bits_used > 0)
|
||||
{
|
||||
u32 extra_bits = Ase_ConsumeBits(&bb, length_entry.bits_used);
|
||||
u32 extra_bits = ASE_ConsumeBits(&bb, length_entry.bits_used);
|
||||
length += extra_bits;
|
||||
}
|
||||
|
||||
u32 dist_index = Ase_DecodeHuffDict(&dist_huffman, &bb);
|
||||
Ase_HuffEntry dist_entry = Ase_huff_dist_table[dist_index];
|
||||
u32 dist_index = ASE_DecodeHuffDict(&dist_huffman, &bb);
|
||||
ASE_HuffEntry dist_entry = ASE_huff_dist_table[dist_index];
|
||||
u32 distance = dist_entry.symbol;
|
||||
if (dist_entry.bits_used > 0)
|
||||
{
|
||||
u32 extra_bits = Ase_ConsumeBits(&bb, dist_entry.bits_used);
|
||||
u32 extra_bits = ASE_ConsumeBits(&bb, dist_entry.bits_used);
|
||||
distance += extra_bits;
|
||||
}
|
||||
u8 *src = dst - distance;
|
||||
@ -390,7 +390,7 @@ void Ase_Inflate(u8 *dst, u8 *encoded)
|
||||
EndTempArena(temp);
|
||||
} break;
|
||||
|
||||
case Ase_BlockType_Reserved:
|
||||
case ASE_BlockType_Reserved:
|
||||
{
|
||||
/* TODO */
|
||||
Assert(0);
|
||||
@ -404,9 +404,9 @@ void Ase_Inflate(u8 *dst, u8 *encoded)
|
||||
////////////////////////////////
|
||||
//~ Error handling
|
||||
|
||||
void Ase_PushError(Arena *arena, Ase_ErrorList *list, String msg_src)
|
||||
void ASE_PushError(Arena *arena, ASE_ErrorList *list, String msg_src)
|
||||
{
|
||||
Ase_Error *e = PushStruct(arena, Ase_Error);
|
||||
ASE_Error *e = PushStruct(arena, ASE_Error);
|
||||
e->msg = CopyString(arena, msg_src);
|
||||
if (!list->first)
|
||||
{
|
||||
@ -423,13 +423,13 @@ void Ase_PushError(Arena *arena, Ase_ErrorList *list, String msg_src)
|
||||
////////////////////////////////
|
||||
//~ Decode image
|
||||
|
||||
u32 Ase_BlendMulU8(u32 a, u32 b)
|
||||
u32 ASE_BlendMulU8(u32 a, u32 b)
|
||||
{
|
||||
u32 t = (a * b) + 0x80;
|
||||
return ((t >> 8) + t) >> 8;
|
||||
}
|
||||
|
||||
u32 Ase_Blend(u32 src, u32 dst, u8 opacity)
|
||||
u32 ASE_Blend(u32 src, u32 dst, u8 opacity)
|
||||
{
|
||||
u32 dst_r = (dst & 0xff);
|
||||
u32 dst_g = (dst >> 8) & 0xff;
|
||||
@ -441,8 +441,8 @@ u32 Ase_Blend(u32 src, u32 dst, u8 opacity)
|
||||
u32 src_b = (src >> 16) & 0xff;
|
||||
u32 src_a = (src >> 24) & 0xff;
|
||||
|
||||
src_a = (u8)Ase_BlendMulU8(src_a, opacity);
|
||||
u32 a = src_a + dst_a - Ase_BlendMulU8(src_a, dst_a);
|
||||
src_a = (u8)ASE_BlendMulU8(src_a, opacity);
|
||||
u32 a = src_a + dst_a - ASE_BlendMulU8(src_a, dst_a);
|
||||
u32 r, g, b;
|
||||
if (a == 0)
|
||||
{
|
||||
@ -458,7 +458,7 @@ u32 Ase_Blend(u32 src, u32 dst, u8 opacity)
|
||||
return r | (g << 8) | (b << 16) | (a << 24);
|
||||
}
|
||||
|
||||
void Ase_MakeDimensionsSquareish(Ase_Header *header, u32 *frames_x, u32 *frames_y, u64 *image_width, u64 *image_height)
|
||||
void ASE_MakeDimensionsSquareish(ASE_Header *header, u32 *frames_x, u32 *frames_y, u64 *image_width, u64 *image_height)
|
||||
{
|
||||
/* Try and get image resolution into as much of a square as possible by
|
||||
* separating frames into multiple rows. */
|
||||
@ -482,21 +482,21 @@ void Ase_MakeDimensionsSquareish(Ase_Header *header, u32 *frames_x, u32 *frames_
|
||||
}
|
||||
}
|
||||
|
||||
Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
ASE_DecodedImage ASE_DecodeImage(Arena *arena, String encoded)
|
||||
{
|
||||
__prof;
|
||||
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
Ase_DecodedImage result = ZI;
|
||||
ASE_DecodedImage result = ZI;
|
||||
|
||||
BB_Buff bb = BitbuffFromString(encoded);
|
||||
BB_Reader br = BB_ReaderFromBuffNoDebug(&bb);
|
||||
Ase_Header ase_header;
|
||||
ASE_Header ase_header;
|
||||
BB_ReadBytes(&br, StringFromStruct(&ase_header));
|
||||
|
||||
if (ase_header.magic != 0xA5E0)
|
||||
{
|
||||
Ase_PushError(arena, &result.errors, Lit("Not a valid aseprite file"));
|
||||
ASE_PushError(arena, &result.errors, Lit("Not a valid aseprite file"));
|
||||
goto abort;
|
||||
}
|
||||
|
||||
@ -505,7 +505,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
String msg = StringFormat(scratch.arena,
|
||||
Lit("Only 32 bit rgba color mode is supported (got %F)"),
|
||||
FmtUint(ase_header.color_depth));
|
||||
Ase_PushError(arena, &result.errors, msg);
|
||||
ASE_PushError(arena, &result.errors, msg);
|
||||
goto abort;
|
||||
}
|
||||
|
||||
@ -516,7 +516,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
u32 frames_y = 1;
|
||||
u64 image_width = frame_width * frames_x;
|
||||
u64 image_height = frame_height * frames_y;
|
||||
Ase_MakeDimensionsSquareish(&ase_header, &frames_x, &frames_y, &image_width, &image_height);
|
||||
ASE_MakeDimensionsSquareish(&ase_header, &frames_x, &frames_y, &image_width, &image_height);
|
||||
|
||||
result.width = image_width;
|
||||
result.height = image_height;
|
||||
@ -524,7 +524,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
result.pixels = PushStructs(arena, u32, image_width * image_height);
|
||||
|
||||
u32 num_layers = 0;
|
||||
Ase_Layer *layer_head = 0;
|
||||
ASE_Layer *layer_head = 0;
|
||||
|
||||
Ace_Cel *cel_head = 0;
|
||||
Ace_Cel *cel_tail = 0;
|
||||
@ -533,7 +533,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
u32 num_frames = 0;
|
||||
for (u16 i = 0; i < ase_header.frames; ++i)
|
||||
{
|
||||
Ase_FrameHeader frame_header;
|
||||
ASE_FrameHeader frame_header;
|
||||
BB_ReadBytes(&br, StringFromStruct(&frame_header));
|
||||
|
||||
u32 num_chunks = frame_header.chunks_new;
|
||||
@ -547,7 +547,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
for (u32 j = 0; j < num_chunks; ++j)
|
||||
{
|
||||
u32 chunk_size = BB_ReadUBits(&br, 32);
|
||||
Ase_ChunkKind chunk_type = BB_ReadUBits(&br, 16);
|
||||
ASE_ChunkKind chunk_type = BB_ReadUBits(&br, 16);
|
||||
|
||||
/* Chunk size includes size & type */
|
||||
Assert(chunk_size >= 6);
|
||||
@ -558,9 +558,9 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
switch (chunk_type)
|
||||
{
|
||||
//- Decode layer
|
||||
case Ase_ChunkKind_Layer:
|
||||
case ASE_ChunkKind_Layer:
|
||||
{
|
||||
Ase_Layer *layer = PushStruct(scratch.arena, Ase_Layer);
|
||||
ASE_Layer *layer = PushStruct(scratch.arena, ASE_Layer);
|
||||
layer->next = layer_head;
|
||||
layer_head = layer;
|
||||
|
||||
@ -574,7 +574,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
layer->blend_mode = BB_ReadUBits(&br, 16);
|
||||
if (layer->blend_mode != 0)
|
||||
{
|
||||
Ase_PushError(arena,
|
||||
ASE_PushError(arena,
|
||||
&result.errors,
|
||||
Lit("Layer has unsupported blend mode (only 'Normal' mode is supported). Tip: Try using 'merge down' to create a normal layer as a workaround"));
|
||||
goto abort;
|
||||
@ -601,7 +601,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
} break;
|
||||
|
||||
//- Decode cel
|
||||
case Ase_ChunkKind_Cel:
|
||||
case ASE_ChunkKind_Cel:
|
||||
{
|
||||
Ace_Cel *cel = PushStruct(scratch.arena, Ace_Cel);
|
||||
if (cel_tail)
|
||||
@ -626,19 +626,19 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
|
||||
switch (cel->type)
|
||||
{
|
||||
case Ase_CelKind_RawImage:
|
||||
case ASE_CelKind_RawImage:
|
||||
{
|
||||
/* Unsupported */
|
||||
BB_SeekToByte(&br, chunk_end_pos);
|
||||
} break;
|
||||
|
||||
case Ase_CelKind_Linked:
|
||||
case ASE_CelKind_Linked:
|
||||
{
|
||||
cel->frame_pos = BB_ReadUBits(&br, 16);
|
||||
/* Actual linking happens later after iteration */
|
||||
} break;
|
||||
|
||||
case Ase_CelKind_CompressedImage:
|
||||
case ASE_CelKind_CompressedImage:
|
||||
{
|
||||
cel->width = BB_ReadUBits(&br, 16);
|
||||
cel->height = BB_ReadUBits(&br, 16);
|
||||
@ -647,14 +647,14 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
u8 *huffman_encoded = BB_ReadBytesRaw(&br, chunk_end_pos - BB_GetCurrentReaderByte(&br));
|
||||
if (huffman_encoded)
|
||||
{
|
||||
Ase_Inflate((u8 *)cel->pixels, huffman_encoded);
|
||||
ASE_Inflate((u8 *)cel->pixels, huffman_encoded);
|
||||
}
|
||||
} break;
|
||||
|
||||
case Ase_CelKind_CompressedTilemap:
|
||||
case ASE_CelKind_CompressedTilemap:
|
||||
{
|
||||
/* Unsupported */
|
||||
Ase_PushError(arena, &result.errors, Lit("Tilemaps are not supported"));
|
||||
ASE_PushError(arena, &result.errors, Lit("Tilemaps are not supported"));
|
||||
goto abort;
|
||||
} break;
|
||||
}
|
||||
@ -670,8 +670,8 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
}
|
||||
|
||||
//- Create ordered layers array
|
||||
Ase_Layer **layers_ordered = PushStructsNoZero(scratch.arena, Ase_Layer *, num_layers);
|
||||
for (Ase_Layer *layer = layer_head; layer; layer = layer->next)
|
||||
ASE_Layer **layers_ordered = PushStructsNoZero(scratch.arena, ASE_Layer *, num_layers);
|
||||
for (ASE_Layer *layer = layer_head; layer; layer = layer->next)
|
||||
{
|
||||
layers_ordered[layer->index] = layer;
|
||||
}
|
||||
@ -681,7 +681,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
for (Ace_Cel *cel = cel_head; cel; cel = cel->next)
|
||||
{
|
||||
cels_ordered[(cel->frame_index * num_layers) + cel->layer_index] = cel;
|
||||
if (cel->type == Ase_CelKind_Linked)
|
||||
if (cel->type == ASE_CelKind_Linked)
|
||||
{
|
||||
Ace_Cel *ref_cel = cels_ordered[(cel->frame_pos * num_layers) + cel->layer_index];
|
||||
cel->width = ref_cel->width;
|
||||
@ -695,7 +695,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
__profn("Build image from cels");
|
||||
for (Ace_Cel *cel = cel_head; cel; cel = cel->next)
|
||||
{
|
||||
Ase_Layer *layer = layers_ordered[cel->layer_index];
|
||||
ASE_Layer *layer = layers_ordered[cel->layer_index];
|
||||
/* Only draw visible layers */
|
||||
if (layer->flags & 1)
|
||||
{
|
||||
@ -753,7 +753,7 @@ Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded)
|
||||
i32 image_x = image_left + cel_x;
|
||||
u32 cel_pixel = cel->pixels[cel_x + cel_stride];
|
||||
u32 *image_pixel = &result.pixels[image_x + image_stride];
|
||||
*image_pixel = Ase_Blend(cel_pixel, *image_pixel, opacity);
|
||||
*image_pixel = ASE_Blend(cel_pixel, *image_pixel, opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -777,15 +777,15 @@ abort:
|
||||
////////////////////////////////
|
||||
//~ Decode sheet
|
||||
|
||||
Ase_DecodedSheet Ase_DecodeSheet(Arena *arena, String encoded)
|
||||
ASE_DecodedSheet ASE_DecodeSheet(Arena *arena, String encoded)
|
||||
{
|
||||
__prof;
|
||||
|
||||
Ase_DecodedSheet result = ZI;
|
||||
ASE_DecodedSheet result = ZI;
|
||||
|
||||
BB_Buff bb = BitbuffFromString(encoded);
|
||||
BB_Reader br = BB_ReaderFromBuffNoDebug(&bb);
|
||||
Ase_Header ase_header;
|
||||
ASE_Header ase_header;
|
||||
BB_ReadBytes(&br, StringFromStruct(&ase_header));
|
||||
|
||||
u64 frame_width = ase_header.width;
|
||||
@ -795,21 +795,21 @@ Ase_DecodedSheet Ase_DecodeSheet(Arena *arena, String encoded)
|
||||
u32 frames_y = 1;
|
||||
u64 image_width = frame_width * frames_x;
|
||||
u64 image_height = frame_height * frames_y;
|
||||
Ase_MakeDimensionsSquareish(&ase_header, &frames_x, &frames_y, &image_width, &image_height);
|
||||
ASE_MakeDimensionsSquareish(&ase_header, &frames_x, &frames_y, &image_width, &image_height);
|
||||
|
||||
u32 num_frames = 0;
|
||||
Ase_Frame *frame_head = 0;
|
||||
ASE_Frame *frame_head = 0;
|
||||
|
||||
u32 num_spans = 0;
|
||||
Ase_Span *span_head = 0;
|
||||
ASE_Span *span_head = 0;
|
||||
|
||||
u32 num_slice_keys = 0;
|
||||
Ase_SliceKey *slice_key_head = 0;
|
||||
ASE_SliceKey *slice_key_head = 0;
|
||||
|
||||
//- Iterate frames
|
||||
for (u16 i = 0; i < ase_header.frames; ++i)
|
||||
{
|
||||
Ase_FrameHeader frame_header;
|
||||
ASE_FrameHeader frame_header;
|
||||
BB_ReadBytes(&br, StringFromStruct(&frame_header));
|
||||
|
||||
u32 num_chunks = frame_header.chunks_new;
|
||||
@ -819,7 +819,7 @@ Ase_DecodedSheet Ase_DecodeSheet(Arena *arena, String encoded)
|
||||
num_chunks = frame_header.chunks_old;
|
||||
}
|
||||
|
||||
Ase_Frame *frame = PushStruct(arena, Ase_Frame);
|
||||
ASE_Frame *frame = PushStruct(arena, ASE_Frame);
|
||||
frame->next = frame_head;
|
||||
frame_head = frame;
|
||||
|
||||
@ -845,7 +845,7 @@ Ase_DecodedSheet Ase_DecodeSheet(Arena *arena, String encoded)
|
||||
for (u32 j = 0; j < num_chunks; ++j)
|
||||
{
|
||||
u32 chunk_size = BB_ReadUBits(&br, 32);
|
||||
Ase_ChunkKind chunk_type = BB_ReadUBits(&br, 16);
|
||||
ASE_ChunkKind chunk_type = BB_ReadUBits(&br, 16);
|
||||
|
||||
/* Chunk size includes size & type */
|
||||
Assert(chunk_size >= 6);
|
||||
@ -856,14 +856,14 @@ Ase_DecodedSheet Ase_DecodeSheet(Arena *arena, String encoded)
|
||||
switch (chunk_type)
|
||||
{
|
||||
//- Decode tags
|
||||
case Ase_ChunkKind_Tags:
|
||||
case ASE_ChunkKind_Tags:
|
||||
{
|
||||
u16 frame_span_count = BB_ReadUBits(&br, 16);
|
||||
BB_SeekBytes(&br, 8);
|
||||
|
||||
for (u16 k = 0; k < frame_span_count; ++k)
|
||||
{
|
||||
Ase_Span *span = PushStruct(arena, Ase_Span);
|
||||
ASE_Span *span = PushStruct(arena, ASE_Span);
|
||||
span->next = span_head;
|
||||
span_head = span;
|
||||
|
||||
@ -881,9 +881,9 @@ Ase_DecodedSheet Ase_DecodeSheet(Arena *arena, String encoded)
|
||||
} break;
|
||||
|
||||
//- Decode slice
|
||||
case Ase_ChunkKind_Slice:
|
||||
case ASE_ChunkKind_Slice:
|
||||
{
|
||||
Ase_SliceKey *slice_key = PushStruct(arena, Ase_SliceKey);
|
||||
ASE_SliceKey *slice_key = PushStruct(arena, ASE_SliceKey);
|
||||
slice_key->next = slice_key_head;
|
||||
slice_key_head = slice_key;
|
||||
|
||||
@ -899,7 +899,7 @@ Ase_DecodedSheet Ase_DecodeSheet(Arena *arena, String encoded)
|
||||
|
||||
for (u32 k = 0; k < num_slices; ++k)
|
||||
{
|
||||
Ase_Slice *slice = PushStruct(arena, Ase_Slice);
|
||||
ASE_Slice *slice = PushStruct(arena, ASE_Slice);
|
||||
slice->next = slice_key->slice_head;
|
||||
slice_key->slice_head = slice;
|
||||
|
||||
@ -930,7 +930,7 @@ Ase_DecodedSheet Ase_DecodeSheet(Arena *arena, String encoded)
|
||||
} break;
|
||||
|
||||
/* TODO */
|
||||
//case Ase_ChunkKind_Userdata
|
||||
//case ASE_ChunkKind_Userdata
|
||||
|
||||
default:
|
||||
{
|
||||
|
||||
@ -1,33 +1,25 @@
|
||||
////////////////////////////////
|
||||
//~ Sheet types
|
||||
|
||||
Struct(Ase_Slice)
|
||||
Struct(ASE_Slice)
|
||||
{
|
||||
u32 start;
|
||||
i32 x1;
|
||||
i32 y1;
|
||||
i32 x2;
|
||||
i32 y2;
|
||||
Ase_Slice *next;
|
||||
ASE_Slice *next;
|
||||
};
|
||||
|
||||
Struct(Ase_SliceKey)
|
||||
{
|
||||
String name;
|
||||
u32 num_slices;
|
||||
Ase_Slice *slice_head;
|
||||
Ase_SliceKey *next;
|
||||
};
|
||||
|
||||
Struct(Ase_Span)
|
||||
Struct(ASE_Span)
|
||||
{
|
||||
String name;
|
||||
u32 start;
|
||||
u32 end;
|
||||
Ase_Span *next;
|
||||
ASE_Span *next;
|
||||
};
|
||||
|
||||
Struct(Ase_Frame)
|
||||
Struct(ASE_Frame)
|
||||
{
|
||||
u32 index;
|
||||
u32 x1;
|
||||
@ -35,84 +27,92 @@ Struct(Ase_Frame)
|
||||
u32 x2;
|
||||
u32 y2;
|
||||
f64 duration;
|
||||
Ase_Frame *next;
|
||||
ASE_Frame *next;
|
||||
};
|
||||
|
||||
Struct(ASE_SliceKey)
|
||||
{
|
||||
String name;
|
||||
u32 num_slices;
|
||||
ASE_Slice *slice_head;
|
||||
ASE_SliceKey *next;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Decoder result types
|
||||
|
||||
Struct(Ase_Error)
|
||||
Struct(ASE_Error)
|
||||
{
|
||||
String msg;
|
||||
Ase_Error *next;
|
||||
ASE_Error *next;
|
||||
};
|
||||
|
||||
Struct(Ase_ErrorList)
|
||||
Struct(ASE_ErrorList)
|
||||
{
|
||||
u64 count;
|
||||
Ase_Error *first;
|
||||
Ase_Error *last;
|
||||
ASE_Error *first;
|
||||
ASE_Error *last;
|
||||
};
|
||||
|
||||
Struct(Ase_DecodedImage)
|
||||
Struct(ASE_DecodedImage)
|
||||
{
|
||||
u32 width;
|
||||
u32 height;
|
||||
u32 *pixels; /* Array of [width * height] pixels */
|
||||
Ase_ErrorList errors;
|
||||
ASE_ErrorList errors;
|
||||
b32 success;
|
||||
};
|
||||
|
||||
Struct(Ase_DecodedSheet)
|
||||
Struct(ASE_DecodedSheet)
|
||||
{
|
||||
Vec2 image_size;
|
||||
Vec2 frame_size;
|
||||
u32 num_frames;
|
||||
u32 num_spans;
|
||||
u32 num_slice_keys;
|
||||
Ase_Frame *frame_head;
|
||||
Ase_Span *span_head;
|
||||
Ase_SliceKey *slice_key_head;
|
||||
Ase_ErrorList errors;
|
||||
ASE_Frame *frame_head;
|
||||
ASE_Span *span_head;
|
||||
ASE_SliceKey *slice_key_head;
|
||||
ASE_ErrorList errors;
|
||||
b32 success;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Inflator types
|
||||
|
||||
#define Ase_HuffBitCount 16
|
||||
#define ASE_HuffBitCount 16
|
||||
|
||||
Struct(Ase_Bitbuff)
|
||||
Struct(ASE_Bitbuff)
|
||||
{
|
||||
u8 *data;
|
||||
u64 cur_bit;
|
||||
};
|
||||
|
||||
typedef i32 Ase_BlockType; enum
|
||||
typedef i32 ASE_BlockType; enum
|
||||
{
|
||||
Ase_BlockType_Uncompressed = 0,
|
||||
Ase_BlockType_CompressedFixed = 1,
|
||||
Ase_BlockType_CompressedDynamic = 2,
|
||||
Ase_BlockType_Reserved = 3
|
||||
ASE_BlockType_Uncompressed = 0,
|
||||
ASE_BlockType_CompressedFixed = 1,
|
||||
ASE_BlockType_CompressedDynamic = 2,
|
||||
ASE_BlockType_Reserved = 3
|
||||
};
|
||||
|
||||
Struct(Ase_HuffEntry)
|
||||
Struct(ASE_HuffEntry)
|
||||
{
|
||||
u16 symbol;
|
||||
u16 bits_used;
|
||||
};
|
||||
|
||||
Struct(Ase_HuffDict)
|
||||
Struct(ASE_HuffDict)
|
||||
{
|
||||
u32 max_code_bits;
|
||||
u32 entries_count;
|
||||
Ase_HuffEntry *entries;
|
||||
ASE_HuffEntry *entries;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Header types
|
||||
|
||||
Packed(Struct(Ase_Header)
|
||||
Packed(Struct(ASE_Header)
|
||||
{
|
||||
u32 file_size;
|
||||
u16 magic;
|
||||
@ -136,7 +136,7 @@ Packed(Struct(Ase_Header)
|
||||
u8 _4[84];
|
||||
});
|
||||
|
||||
Packed(Struct(Ase_FrameHeader)
|
||||
Packed(Struct(ASE_FrameHeader)
|
||||
{
|
||||
u32 bytes;
|
||||
u16 magic;
|
||||
@ -149,33 +149,33 @@ Packed(Struct(Ase_FrameHeader)
|
||||
////////////////////////////////
|
||||
//~ Image decoder types
|
||||
|
||||
typedef i32 Ase_ChunkKind; enum
|
||||
typedef i32 ASE_ChunkKind; enum
|
||||
{
|
||||
Ase_ChunkKind_OldPalette1 = 0x0004,
|
||||
Ase_ChunkKind_OldPalette2 = 0x0011,
|
||||
Ase_ChunkKind_Layer = 0x2004,
|
||||
Ase_ChunkKind_Cel = 0x2005,
|
||||
Ase_ChunkKind_CelExtra = 0x2006,
|
||||
Ase_ChunkKind_ColorProfile = 0x2007,
|
||||
Ase_ChunkKind_ExternalFiles = 0x2008,
|
||||
Ase_ChunkKind_Mask = 0x2016,
|
||||
Ase_ChunkKind_Path = 0x2017,
|
||||
Ase_ChunkKind_Tags = 0x2018,
|
||||
Ase_ChunkKind_Palette = 0x2019,
|
||||
Ase_ChunkKind_Userdata = 0x2020,
|
||||
Ase_ChunkKind_Slice = 0x2022,
|
||||
Ase_ChunkKind_Tileset = 0x2023
|
||||
ASE_ChunkKind_OldPalette1 = 0x0004,
|
||||
ASE_ChunkKind_OldPalette2 = 0x0011,
|
||||
ASE_ChunkKind_Layer = 0x2004,
|
||||
ASE_ChunkKind_Cel = 0x2005,
|
||||
ASE_ChunkKind_CelExtra = 0x2006,
|
||||
ASE_ChunkKind_ColorProfile = 0x2007,
|
||||
ASE_ChunkKind_ExternalFiles = 0x2008,
|
||||
ASE_ChunkKind_Mask = 0x2016,
|
||||
ASE_ChunkKind_Path = 0x2017,
|
||||
ASE_ChunkKind_Tags = 0x2018,
|
||||
ASE_ChunkKind_Palette = 0x2019,
|
||||
ASE_ChunkKind_Userdata = 0x2020,
|
||||
ASE_ChunkKind_Slice = 0x2022,
|
||||
ASE_ChunkKind_Tileset = 0x2023
|
||||
};
|
||||
|
||||
typedef i32 Ase_CelKind; enum
|
||||
typedef i32 ASE_CelKind; enum
|
||||
{
|
||||
Ase_CelKind_RawImage = 0,
|
||||
Ase_CelKind_Linked = 1,
|
||||
Ase_CelKind_CompressedImage = 2,
|
||||
Ase_CelKind_CompressedTilemap = 3
|
||||
ASE_CelKind_RawImage = 0,
|
||||
ASE_CelKind_Linked = 1,
|
||||
ASE_CelKind_CompressedImage = 2,
|
||||
ASE_CelKind_CompressedTilemap = 3
|
||||
};
|
||||
|
||||
Struct(Ase_Layer)
|
||||
Struct(ASE_Layer)
|
||||
{
|
||||
u16 flags;
|
||||
u16 type;
|
||||
@ -186,7 +186,7 @@ Struct(Ase_Layer)
|
||||
u32 tileset_index;
|
||||
|
||||
u32 index;
|
||||
Ase_Layer *next;
|
||||
ASE_Layer *next;
|
||||
};
|
||||
|
||||
Struct(Ace_Cel)
|
||||
@ -195,7 +195,7 @@ Struct(Ace_Cel)
|
||||
i16 x_pos;
|
||||
i16 y_pos;
|
||||
u8 opacity;
|
||||
Ase_CelKind type;
|
||||
ASE_CelKind type;
|
||||
i16 z_index;
|
||||
|
||||
/* Linked cel */
|
||||
@ -213,29 +213,29 @@ Struct(Ace_Cel)
|
||||
////////////////////////////////
|
||||
//~ Ase bitbuff operations
|
||||
|
||||
u32 Ase_PeekBits(Ase_Bitbuff *bb, u32 nbits);
|
||||
u32 Ase_ConsumeBits(Ase_Bitbuff *bb, u32 nbits);
|
||||
void Ase_SkipBits(Ase_Bitbuff *bb, u32 nbits);
|
||||
u32 ASE_PeekBits(ASE_Bitbuff *bb, u32 nbits);
|
||||
u32 ASE_ConsumeBits(ASE_Bitbuff *bb, u32 nbits);
|
||||
void ASE_SkipBits(ASE_Bitbuff *bb, u32 nbits);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Inflate operations
|
||||
|
||||
u32 Ase_ReverseBits(u32 v, u32 bit_count);
|
||||
Ase_HuffDict Ase_InitHuffDict(Arena *arena, u32 max_code_bits, u32 *bl_counts, u32 bl_counts_count);
|
||||
u16 Ase_DecodeHuffDict(Ase_HuffDict *huffman, Ase_Bitbuff *bb);
|
||||
void Ase_Inflate(u8 *dst, u8 *encoded);
|
||||
u32 ASE_ReverseBits(u32 v, u32 bit_count);
|
||||
ASE_HuffDict ASE_InitHuffDict(Arena *arena, u32 max_code_bits, u32 *bl_counts, u32 bl_counts_count);
|
||||
u16 ASE_DecodeHuffDict(ASE_HuffDict *huffman, ASE_Bitbuff *bb);
|
||||
void ASE_Inflate(u8 *dst, u8 *encoded);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Error handling operations
|
||||
|
||||
//- Helpers
|
||||
void Ase_PushError(Arena *arena, Ase_ErrorList *list, String msg_src);
|
||||
u32 Ase_BlendMulU8(u32 a, u32 b);
|
||||
u32 Ase_Blend(u32 src, u32 dst, u8 opacity);
|
||||
void Ase_MakeDimensionsSquareish(Ase_Header *header, u32 *frames_x, u32 *frames_y, u64 *image_width, u64 *image_height);
|
||||
void ASE_PushError(Arena *arena, ASE_ErrorList *list, String msg_src);
|
||||
u32 ASE_BlendMulU8(u32 a, u32 b);
|
||||
u32 ASE_Blend(u32 src, u32 dst, u8 opacity);
|
||||
void ASE_MakeDimensionsSquareish(ASE_Header *header, u32 *frames_x, u32 *frames_y, u64 *image_width, u64 *image_height);
|
||||
|
||||
//- Decode image
|
||||
Ase_DecodedImage Ase_DecodeImage(Arena *arena, String encoded);
|
||||
ASE_DecodedImage ASE_DecodeImage(Arena *arena, String encoded);
|
||||
|
||||
//- Decode sheet
|
||||
Ase_DecodedSheet Ase_DecodeSheet(Arena *arena, String encoded);
|
||||
ASE_DecodedSheet ASE_DecodeSheet(Arena *arena, String encoded);
|
||||
|
||||
@ -14,7 +14,8 @@ typedef i32 P_Pool; enum
|
||||
P_Pool_Inherit = -1,
|
||||
|
||||
/* The floating pool contains a large number of lower priority threads that have affinity over the entire CPU.
|
||||
* Other pools should push jobs that only block and do no work here so that they can yield on the blocking job rather than blocking themselves. */
|
||||
* Other pools should push jobs that only block and do no work here so that they can yield on the blocking job
|
||||
* rather than blocking themselves. */
|
||||
P_Pool_Floating = 0,
|
||||
|
||||
P_Pool_Background = 1,
|
||||
|
||||
@ -335,11 +335,11 @@ internal void cache_entry_load_texture(struct cache_ref ref, S_Tag tag)
|
||||
u64 memory_size = 0;
|
||||
{
|
||||
/* Decode */
|
||||
Ase_DecodedImage decoded = ZI;
|
||||
ASE_DecodedImage decoded = ZI;
|
||||
{
|
||||
RES_Resource texture_rs = RES_OpenResource(path);
|
||||
if (RES_ResourceExists(&texture_rs)) {
|
||||
decoded = Ase_DecodeImage(scratch.arena, RES_GetResourceData(&texture_rs));
|
||||
decoded = ASE_DecodeImage(scratch.arena, RES_GetResourceData(&texture_rs));
|
||||
} else {
|
||||
P_LogErrorF("Sprite texture for \"%F\" not found", FmtString(path));
|
||||
}
|
||||
@ -390,7 +390,7 @@ internal void cache_entry_load_texture(struct cache_ref ref, S_Tag tag)
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
internal S_Sheet init_sheet_from_ase_result(Arena *arena, ASE_DecodedSheet ase)
|
||||
{
|
||||
__prof;
|
||||
S_Sheet sheet = ZI;
|
||||
@ -407,7 +407,7 @@ internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
sheet.frame_size = ase.frame_size;
|
||||
sheet.frames = PushStructs(arena, S_SheetFrame, ase.num_frames);
|
||||
sheet.frames_count = ase.num_frames;
|
||||
for (Ase_Frame *ase_frame = ase.frame_head; ase_frame; ase_frame = ase_frame->next) {
|
||||
for (ASE_Frame *ase_frame = ase.frame_head; ase_frame; ase_frame = ase_frame->next) {
|
||||
u32 index = ase_frame->index;
|
||||
|
||||
Vec2 clip_p1 = { (f32)ase_frame->x1 / (f32)ase.image_size.x, (f32)ase_frame->y1 / (f32)ase.image_size.y };
|
||||
@ -428,7 +428,7 @@ internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
sheet.spans = PushStructs(arena, S_SheetSpan, sheet.spans_count);
|
||||
sheet.spans_dict = InitDict(arena, (u64)(ase.num_spans * SHEET_SPAN_LOOKUP_TABLE_BIN_RATIO));
|
||||
u64 index = 0;
|
||||
for (Ase_Span *ase_span = ase.span_head; ase_span; ase_span = ase_span->next) {
|
||||
for (ASE_Span *ase_span = ase.span_head; ase_span; ase_span = ase_span->next) {
|
||||
String name = CopyString(arena, ase_span->name);
|
||||
S_SheetSpan *span = &sheet.spans[index];
|
||||
span->name = name;
|
||||
@ -446,7 +446,7 @@ internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
struct temp_ase_slice_key_node {
|
||||
Ase_SliceKey *key;
|
||||
ASE_SliceKey *key;
|
||||
struct temp_ase_slice_key_node *next;
|
||||
|
||||
u32 index_in_frame;
|
||||
@ -467,7 +467,7 @@ internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
struct temp_slice_group_node *temp_slice_group_head = 0;
|
||||
{
|
||||
Dict *temp_slice_dict = InitDict(scratch.arena, (u64)(ase.num_slice_keys * 2));
|
||||
for (Ase_SliceKey *ase_slice_key = ase.slice_key_head; ase_slice_key; ase_slice_key = ase_slice_key->next) {
|
||||
for (ASE_SliceKey *ase_slice_key = ase.slice_key_head; ase_slice_key; ase_slice_key = ase_slice_key->next) {
|
||||
String name = ase_slice_key->name;
|
||||
u64 hash = HashFnv64(Fnv64Basis, name);
|
||||
struct temp_slice_group_node *temp_slice_group_node = (struct temp_slice_group_node *)DictValueFromHash(temp_slice_dict, hash);
|
||||
@ -507,9 +507,9 @@ internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
|
||||
u64 index_in_frame = 0;
|
||||
for (struct temp_ase_slice_key_node *node = temp_slice_group_node->temp_ase_slice_key_head; node; node = node->next) {
|
||||
Ase_SliceKey *key = node->key;
|
||||
ASE_SliceKey *key = node->key;
|
||||
|
||||
for (Ase_Slice *ase_slice = key->slice_head; ase_slice; ase_slice = ase_slice->next) {
|
||||
for (ASE_Slice *ase_slice = key->slice_head; ase_slice; ase_slice = ase_slice->next) {
|
||||
u32 start = ase_slice->start;
|
||||
|
||||
S_SheetSlice *slice = &slice_group->frame_slices[(start * slice_group->per_frame_count) + index_in_frame];
|
||||
@ -567,9 +567,9 @@ internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
S_SheetSliceGroup *slice_group = temp_slice_group_node->final_slice_group;
|
||||
|
||||
for (struct temp_ase_slice_key_node *node = temp_slice_group_node->temp_ase_slice_key_head; node; node = node->next) {
|
||||
Ase_SliceKey *key = node->key;
|
||||
ASE_SliceKey *key = node->key;
|
||||
u32 index_in_frame = node->index_in_frame;
|
||||
for (Ase_Slice *ase_slice = key->slice_head; ase_slice; ase_slice = ase_slice->next) {
|
||||
for (ASE_Slice *ase_slice = key->slice_head; ase_slice; ase_slice = ase_slice->next) {
|
||||
u32 start = ase_slice->start;
|
||||
|
||||
S_SheetSlice *slice = &slice_group->frame_slices[(start * slice_group->per_frame_count) + index_in_frame];
|
||||
@ -655,11 +655,11 @@ internal void cache_entry_load_sheet(struct cache_ref ref, S_Tag tag)
|
||||
e->arena = AllocArena(SHEET_ARENA_RESERVE);
|
||||
{
|
||||
/* Decode */
|
||||
Ase_DecodedSheet decoded = ZI;
|
||||
ASE_DecodedSheet decoded = ZI;
|
||||
{
|
||||
RES_Resource sheet_rs = RES_OpenResource(path);
|
||||
if (RES_ResourceExists(&sheet_rs)) {
|
||||
decoded = Ase_DecodeSheet(scratch.arena, RES_GetResourceData(&sheet_rs));
|
||||
decoded = ASE_DecodeSheet(scratch.arena, RES_GetResourceData(&sheet_rs));
|
||||
} else {
|
||||
P_LogErrorF("Sprite sheet for \"%F\" not found", FmtString(path));
|
||||
}
|
||||
@ -668,7 +668,7 @@ internal void cache_entry_load_sheet(struct cache_ref ref, S_Tag tag)
|
||||
|
||||
if (decoded.success) {
|
||||
RES_Resource sheet_rs = RES_OpenResource(path);
|
||||
decoded = Ase_DecodeSheet(scratch.arena, RES_GetResourceData(&sheet_rs));
|
||||
decoded = ASE_DecodeSheet(scratch.arena, RES_GetResourceData(&sheet_rs));
|
||||
RES_CloseResource(&sheet_rs);
|
||||
|
||||
/* Initialize */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user