remove buffer struct, use string struct instead
This commit is contained in:
parent
a1a1430fd8
commit
d7f1ac06cb
26
src/app.c
26
src/app.c
@ -50,7 +50,7 @@ INTERNAL struct string initialize_write_directory(struct arena *arena, struct st
|
||||
|
||||
/* Create write path */
|
||||
struct string base_write_dir = sys_get_write_path(scratch.arena);
|
||||
struct string write_path_fmt = base_write_dir.len > 0 ? STR("%F/%F/") : STR("%F%F/");
|
||||
struct string write_path_fmt = base_write_dir.len > 0 ? LIT("%F/%F/") : LIT("%F%F/");
|
||||
struct string write_path = string_format(
|
||||
arena,
|
||||
write_path_fmt,
|
||||
@ -148,12 +148,12 @@ void app_entry_point(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
G.write_path = initialize_write_directory(&G.arena, STR(WRITE_DIR));
|
||||
G.write_path = initialize_write_directory(&G.arena, LIT(WRITE_DIR));
|
||||
|
||||
/* Startup logging */
|
||||
{
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct string logfile_path = app_write_path_cat(temp.arena, STR("log.txt"));
|
||||
struct string logfile_path = app_write_path_cat(temp.arena, LIT("log.txt"));
|
||||
struct log_startup_receipt log_sr = log_startup(logfile_path);
|
||||
(UNUSED)log_sr;
|
||||
logf_info("Start of logs");
|
||||
@ -168,20 +168,20 @@ void app_entry_point(void)
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
struct sys_window_settings window_settings = ZI;
|
||||
struct string settings_path = app_write_path_cat(temp.arena, STR(SETTINGS_FILENAME));
|
||||
struct string settings_path = app_write_path_cat(temp.arena, LIT(SETTINGS_FILENAME));
|
||||
logf_info("Looking for settings file \"%F\"", FMT_STR(settings_path));
|
||||
if (sys_is_file(settings_path)) {
|
||||
logf_info("Settings file found");
|
||||
struct sys_file settings_file = sys_file_open_read(settings_path);
|
||||
struct buffer file_data = sys_file_read_all(temp.arena, settings_file);
|
||||
struct string file_data = sys_file_read_all(temp.arena, settings_file);
|
||||
sys_file_close(settings_file);
|
||||
logf_info("Deserializing settings file data: %F", FMT_STR(STRING_FROM_BUFFER(file_data)));
|
||||
logf_info("Deserializing settings file data: %F", FMT_STR(file_data));
|
||||
struct string error = ZI;
|
||||
struct sys_window_settings *res = settings_deserialize(temp.arena, file_data, &error);
|
||||
if (error.len > 0) {
|
||||
logf_info("Failed to load settings file with error - %F", FMT_STR(error));
|
||||
struct string msg = string_format(temp.arena,
|
||||
STR(
|
||||
LIT(
|
||||
"Failed to loading settings file \"%F\":\n"
|
||||
"------------\n"
|
||||
"%F\n"
|
||||
@ -198,7 +198,7 @@ void app_entry_point(void)
|
||||
logf_info("Settings file not found, loading default");
|
||||
window_settings = default_window_settings(&window);
|
||||
}
|
||||
string_copy_buff(BUFFER_FROM_ARRAY(window_settings.title), STR(WINDOW_TITLE));
|
||||
string_copy_to_string(STRING_FROM_ARRAY(window_settings.title), LIT(WINDOW_TITLE));
|
||||
sys_window_update_settings(&window, &window_settings);
|
||||
|
||||
arena_temp_end(temp);
|
||||
@ -240,7 +240,7 @@ void app_entry_point(void)
|
||||
|
||||
/* Start callback threads */
|
||||
for (struct exit_callback *callback = G.exit_callbacks_head; callback; callback = callback->next) {
|
||||
callback->thread = sys_thread_alloc(&exit_callback_thread_entry_point, callback, STR("[P4] Exit callback thread"));
|
||||
callback->thread = sys_thread_alloc(&exit_callback_thread_entry_point, callback, LIT("[P4] Exit callback thread"));
|
||||
}
|
||||
|
||||
/* Wait on callback threads */
|
||||
@ -255,15 +255,15 @@ void app_entry_point(void)
|
||||
{
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
struct string window_settings_path = app_write_path_cat(temp.arena, STR(SETTINGS_FILENAME));
|
||||
struct string window_settings_path = app_write_path_cat(temp.arena, LIT(SETTINGS_FILENAME));
|
||||
|
||||
struct sys_window_settings settings = sys_window_get_settings(&window);
|
||||
struct buffer buff = settings_serialize(temp.arena, &settings);
|
||||
logf_info("Serialized window settings: %F", FMT_STR(STRING_FROM_BUFFER(buff)));
|
||||
struct string str = settings_serialize(temp.arena, &settings);
|
||||
logf_info("Serialized window settings: %F", FMT_STR(str));
|
||||
|
||||
logf_info("Writing settings file to path \"%F\"", FMT_STR(window_settings_path));
|
||||
struct sys_file settings_file = sys_file_open_write(window_settings_path);
|
||||
sys_file_write(settings_file, buff);
|
||||
sys_file_write(settings_file, str);
|
||||
sys_file_close(settings_file);
|
||||
logf_info("Finished writing settings file");
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ struct arena arena_alloc(u64 reserve)
|
||||
arena.base = sys_memory_reserve(reserve);
|
||||
if (!arena.base) {
|
||||
/* Hard fail on memory reserve failure for now */
|
||||
sys_panic(STR("Failed to reserve memory"));
|
||||
sys_panic(LIT("Failed to reserve memory"));
|
||||
}
|
||||
arena.reserved = reserve;
|
||||
|
||||
@ -32,7 +32,7 @@ struct arena arena_alloc(u64 reserve)
|
||||
ASAN_POISON(arena.base, ARENA_BLOCK_SIZE);
|
||||
if (!arena.base) {
|
||||
/* Hard fail on commit failure */
|
||||
sys_panic(STR("Failed to commit initial memory block: System may be out of memory"));
|
||||
sys_panic(LIT("Failed to commit initial memory block: System may be out of memory"));
|
||||
}
|
||||
arena.committed = ARENA_BLOCK_SIZE;
|
||||
|
||||
@ -72,12 +72,12 @@ void *_arena_push_bytes(struct arena *arena, u64 size, u64 align)
|
||||
u64 new_capacity = arena->committed + commit_bytes;
|
||||
if (new_capacity > arena->reserved) {
|
||||
/* Hard fail if we overflow reserved memory for now */
|
||||
sys_panic(STR("Failed to commit new memory block: Overflow of reserved memory"));
|
||||
sys_panic(LIT("Failed to commit new memory block: Overflow of reserved memory"));
|
||||
}
|
||||
void *commit_address = arena->base + arena->committed;
|
||||
if (!sys_memory_commit(commit_address, commit_bytes)) {
|
||||
/* Hard fail on memory allocation failure for now */
|
||||
sys_panic(STR("Failed to commit new memory block: System may be out of memory"));
|
||||
sys_panic(LIT("Failed to commit new memory block: System may be out of memory"));
|
||||
}
|
||||
__proffree(arena->base);
|
||||
__profalloc(arena->base, arena->committed + commit_bytes);
|
||||
|
||||
@ -102,11 +102,11 @@ INLINE void arena_reset(struct arena *arena)
|
||||
arena_pop_to(arena, 0);
|
||||
}
|
||||
|
||||
INLINE struct buffer arena_to_buffer(struct arena *arena)
|
||||
INLINE struct string arena_to_string(struct arena *arena)
|
||||
{
|
||||
struct buffer b;
|
||||
b.data = arena->base;
|
||||
b.size = arena->pos;
|
||||
struct string b;
|
||||
b.text = arena->base;
|
||||
b.len = arena->pos;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
14
src/ase.c
14
src/ase.c
@ -270,7 +270,7 @@ INTERNAL void inflate(u8 *dest, u8 *encoded)
|
||||
u8 btype = consume_bits(&bb, 2);
|
||||
switch (btype) {
|
||||
case BLOCK_TYPE_UNCOMPRESSED: {
|
||||
sys_panic(STR("Unsupported block type while inflating ase: BLOCK_TYPE_UNCOMPRESSED"));
|
||||
sys_panic(LIT("Unsupported block type while inflating ase: BLOCK_TYPE_UNCOMPRESSED"));
|
||||
} break;
|
||||
|
||||
case BLOCK_TYPE_COMPRESSED_FIXED:
|
||||
@ -551,7 +551,7 @@ INTERNAL void make_image_dimensions_squareish(struct ase_header *header, u32 *fr
|
||||
}
|
||||
}
|
||||
|
||||
struct ase_decode_image_result ase_decode_image(struct arena *arena, struct buffer encoded)
|
||||
struct ase_decode_image_result ase_decode_image(struct arena *arena, struct string encoded)
|
||||
{
|
||||
__prof;
|
||||
|
||||
@ -563,13 +563,13 @@ struct ase_decode_image_result ase_decode_image(struct arena *arena, struct buff
|
||||
br_read_to_struct(&br, &ase_header);
|
||||
|
||||
if (ase_header.magic != 0xA5E0) {
|
||||
push_error_copy_msg(arena, &res.errors, STR("Not a valid aseprite file"));
|
||||
push_error_copy_msg(arena, &res.errors, LIT("Not a valid aseprite file"));
|
||||
goto abort;
|
||||
}
|
||||
|
||||
if (ase_header.color_depth != 32) {
|
||||
struct string msg = string_format(scratch.arena,
|
||||
STR("Only 32 bit rgba color mode is supported (got %F)"),
|
||||
LIT("Only 32 bit rgba color mode is supported (got %F)"),
|
||||
FMT_UINT(ase_header.color_depth));
|
||||
push_error_copy_msg(arena, &res.errors, msg);
|
||||
goto abort;
|
||||
@ -635,7 +635,7 @@ struct ase_decode_image_result ase_decode_image(struct arena *arena, struct buff
|
||||
if (layer->blend_mode != 0) {
|
||||
push_error_copy_msg(arena,
|
||||
&res.errors,
|
||||
STR("Layer has unsupported blend mode (only 'Normal' mode is supported). Tip: Try using 'merge down' to create a normal layer as a workaround"));
|
||||
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;
|
||||
}
|
||||
|
||||
@ -706,7 +706,7 @@ struct ase_decode_image_result ase_decode_image(struct arena *arena, struct buff
|
||||
|
||||
case CEL_TYPE_COMPRESSED_TILEMAP: {
|
||||
/* Unsupported */
|
||||
push_error_copy_msg(arena, &res.errors, STR("Tilemaps are not supported"));
|
||||
push_error_copy_msg(arena, &res.errors, LIT("Tilemaps are not supported"));
|
||||
goto abort;
|
||||
} break;
|
||||
}
|
||||
@ -814,7 +814,7 @@ struct ase_decode_image_result ase_decode_image(struct arena *arena, struct buff
|
||||
* Decode sheet
|
||||
* ========================== */
|
||||
|
||||
struct ase_decode_sheet_result ase_decode_sheet(struct arena *arena, struct buffer encoded)
|
||||
struct ase_decode_sheet_result ase_decode_sheet(struct arena *arena, struct string encoded)
|
||||
{
|
||||
__prof;
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ struct ase_decode_sheet_result {
|
||||
struct ase_error_list errors;
|
||||
};
|
||||
|
||||
struct ase_decode_image_result ase_decode_image(struct arena *arena, struct buffer encoded);
|
||||
struct ase_decode_sheet_result ase_decode_sheet(struct arena *arena, struct buffer encoded);
|
||||
struct ase_decode_image_result ase_decode_image(struct arena *arena, struct string encoded);
|
||||
struct ase_decode_sheet_result ase_decode_sheet(struct arena *arena, struct string encoded);
|
||||
|
||||
#endif
|
||||
|
||||
@ -103,7 +103,7 @@ INTERNAL struct asset *asset_cache_get_slot_locked(struct sys_lock *lock, struct
|
||||
u64 asset_cache_hash(struct string key)
|
||||
{
|
||||
/* TODO: Better hash */
|
||||
return hash_fnv64(HASH_FNV64_BASIS, BUFFER_FROM_STRING(key));
|
||||
return hash_fnv64(HASH_FNV64_BASIS, key);
|
||||
}
|
||||
|
||||
/* `key` text is copied by this function
|
||||
@ -137,7 +137,7 @@ struct asset *asset_cache_touch(struct string key, u64 hash, b32 *is_first_touch
|
||||
|
||||
if (!asset->hash) {
|
||||
if (G.num_assets >= MAX_ASSETS) {
|
||||
sys_panic(STR("Max assets reached"));
|
||||
sys_panic(LIT("Max assets reached"));
|
||||
}
|
||||
struct string key_stored = ZI;
|
||||
{
|
||||
|
||||
38
src/byteio.c
38
src/byteio.c
@ -13,7 +13,7 @@ INTERNAL b32 write_check_overflow(struct byte_writer *bw, i64 amount)
|
||||
overflowed = true;
|
||||
bw->overflowed = true;
|
||||
} else {
|
||||
u8 *end = bw->buff.data + bw->buff.size;
|
||||
u8 *end = bw->buff.text + bw->buff.len;
|
||||
u8 *new_pos = bw->at + amount;
|
||||
i64 new_space_left = end - new_pos;
|
||||
if (new_space_left < 0) {
|
||||
@ -21,7 +21,7 @@ INTERNAL b32 write_check_overflow(struct byte_writer *bw, i64 amount)
|
||||
if (arena) {
|
||||
if ((arena->base + arena->pos) == end) {
|
||||
arena_push_array(arena, u8, -new_space_left);
|
||||
bw->buff.size += -new_space_left;
|
||||
bw->buff.len += -new_space_left;
|
||||
} else {
|
||||
/* Writer memory must be contiguous in arena */
|
||||
overflowed = true;
|
||||
@ -46,11 +46,11 @@ INTERNAL void write(struct byte_writer *bw, void *v, u64 size)
|
||||
bw->at += size;
|
||||
}
|
||||
|
||||
struct byte_writer bw_from_buffer(struct buffer buff)
|
||||
struct byte_writer bw_from_buffer(struct string buff)
|
||||
{
|
||||
struct byte_writer bw = ZI;
|
||||
bw.buff = buff;
|
||||
bw.at = buff.data;
|
||||
bw.at = buff.text;
|
||||
return bw;
|
||||
}
|
||||
|
||||
@ -59,16 +59,16 @@ struct byte_writer bw_from_arena(struct arena *arena)
|
||||
{
|
||||
struct byte_writer bw = ZI;
|
||||
bw.arena = arena;
|
||||
bw.buff.data = arena->base + arena->pos;
|
||||
bw.buff.size = 0;
|
||||
bw.at = bw.buff.data;
|
||||
bw.buff.text = arena->base + arena->pos;
|
||||
bw.buff.len = 0;
|
||||
bw.at = bw.buff.text;
|
||||
return bw;
|
||||
}
|
||||
|
||||
/* Seeks forward and returns a new writer pointing to the skipped bytes */
|
||||
struct byte_writer bw_branch(struct byte_writer *bw, u64 size)
|
||||
{
|
||||
struct buffer buff = BUFFER(size, bw->at);
|
||||
struct string buff = STRING(size, bw->at);
|
||||
struct byte_writer branch = bw_from_buffer(buff);
|
||||
bw_seek(bw, size);
|
||||
branch.overflowed = bw->overflowed;
|
||||
@ -85,15 +85,15 @@ void bw_seek(struct byte_writer *bw, u64 amount)
|
||||
|
||||
void bw_seek_to(struct byte_writer *bw, u64 pos)
|
||||
{
|
||||
if (write_check_overflow(bw, (i64)pos - (i64)(bw->at - bw->buff.data))) {
|
||||
if (write_check_overflow(bw, (i64)pos - (i64)(bw->at - bw->buff.text))) {
|
||||
return;
|
||||
}
|
||||
bw->at = bw->buff.data + pos;
|
||||
bw->at = bw->buff.text + pos;
|
||||
}
|
||||
|
||||
void bw_write_buffer(struct byte_writer *bw, struct buffer buff)
|
||||
void bw_write_string(struct byte_writer *bw, struct string s)
|
||||
{
|
||||
write(bw, buff.data, buff.size);
|
||||
write(bw, s.text, s.len);
|
||||
}
|
||||
|
||||
void bw_write_u8(struct byte_writer *bw, u8 v)
|
||||
@ -171,7 +171,7 @@ void bw_write_v2(struct byte_writer *bw, struct v2 v)
|
||||
INTERNAL b32 read_check_overflow(struct byte_reader *br, i64 amount)
|
||||
{
|
||||
b32 overflowed = br->overflowed;
|
||||
if (overflowed || amount < 0 || (br->at + amount) > (br->buff.data + br->buff.size) ){
|
||||
if (overflowed || amount < 0 || (br->at + amount) > (br->buff.text + br->buff.len) ){
|
||||
ASSERT(false);
|
||||
br->overflowed = true;
|
||||
overflowed = true;
|
||||
@ -188,11 +188,11 @@ INTERNAL void read(struct byte_reader *br, void *dst, u64 size)
|
||||
br->at += size;
|
||||
}
|
||||
|
||||
struct byte_reader br_from_buffer(struct buffer buff)
|
||||
struct byte_reader br_from_buffer(struct string buff)
|
||||
{
|
||||
struct byte_reader br = ZI;
|
||||
br.buff = buff;
|
||||
br.at = buff.data;
|
||||
br.at = buff.text;
|
||||
return br;
|
||||
}
|
||||
|
||||
@ -212,18 +212,18 @@ void *br_seek(struct byte_reader *br, u64 amount)
|
||||
void *br_seek_to(struct byte_reader *br, u64 pos)
|
||||
{
|
||||
void *ptr = NULL;
|
||||
if (read_check_overflow(br, (i64)pos - (i64)(br->at - br->buff.data))) {
|
||||
if (read_check_overflow(br, (i64)pos - (i64)(br->at - br->buff.text))) {
|
||||
return ptr;
|
||||
}
|
||||
ptr = br->at;
|
||||
br->at = br->buff.data + pos;
|
||||
br->at = br->buff.text + pos;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* Will fill buff with zeroes on overflow */
|
||||
void br_read_to_buffer(struct byte_reader *br, struct buffer buff)
|
||||
void br_read_to_string(struct byte_reader *br, struct string buff)
|
||||
{
|
||||
read(br, buff.data, buff.size);
|
||||
read(br, buff.text, buff.len);
|
||||
}
|
||||
|
||||
u8 br_read_u8(struct byte_reader *br)
|
||||
|
||||
30
src/byteio.h
30
src/byteio.h
@ -3,13 +3,13 @@
|
||||
|
||||
struct byte_writer {
|
||||
struct arena *arena; /* If arena is set, then the writer cannot overflow and will instead allocate more memory as it grows */
|
||||
struct buffer buff;
|
||||
struct string buff;
|
||||
b32 overflowed;
|
||||
u8 *at;
|
||||
};
|
||||
|
||||
struct byte_reader {
|
||||
struct buffer buff;
|
||||
struct string buff;
|
||||
b32 overflowed;
|
||||
u8 *at;
|
||||
};
|
||||
@ -18,14 +18,14 @@ struct byte_reader {
|
||||
* Writer
|
||||
* ========================== */
|
||||
|
||||
struct byte_writer bw_from_buffer(struct buffer buff);
|
||||
struct byte_writer bw_from_buffer(struct string buff);
|
||||
struct byte_writer bw_from_arena(struct arena *arena);
|
||||
struct byte_writer bw_branch(struct byte_writer *bw, u64 size);
|
||||
|
||||
void bw_seek(struct byte_writer *bw, u64 amount);
|
||||
void bw_seek_to(struct byte_writer *bw, u64 pos);
|
||||
|
||||
void bw_write_buffer(struct byte_writer *bw, struct buffer buff);
|
||||
void bw_write_string(struct byte_writer *bw, struct string s);
|
||||
void bw_write_u8(struct byte_writer *bw, u8 v);
|
||||
void bw_write_u16(struct byte_writer *bw, u16 v);
|
||||
void bw_write_u32(struct byte_writer *bw, u32 v);
|
||||
@ -40,18 +40,18 @@ void bw_write_f32(struct byte_writer *bw, f32 v);
|
||||
void bw_write_f64(struct byte_writer *bw, f64 v);
|
||||
void bw_write_v2(struct byte_writer *bw, struct v2 v);
|
||||
|
||||
/* Returns a buffer containing written bytes only */
|
||||
INLINE struct buffer bw_get_written(struct byte_writer *bw)
|
||||
/* Returns a string containing written bytes only */
|
||||
INLINE struct string bw_get_written(struct byte_writer *bw)
|
||||
{
|
||||
struct buffer buff = ZI;
|
||||
buff.data = bw->buff.data;
|
||||
buff.size = bw->at - bw->buff.data;
|
||||
struct string buff = ZI;
|
||||
buff.text = bw->buff.text;
|
||||
buff.len = bw->at - bw->buff.text;
|
||||
return buff;
|
||||
}
|
||||
|
||||
INLINE u64 bw_pos(struct byte_writer *bw)
|
||||
{
|
||||
return bw->at - bw->buff.data;
|
||||
return bw->at - bw->buff.text;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -59,14 +59,14 @@ INLINE u64 bw_pos(struct byte_writer *bw)
|
||||
* ========================== */
|
||||
|
||||
/* Will fill struct with zeroes on overflow */
|
||||
#define br_read_to_struct(br_ptr, var_ptr) (br_read_to_buffer(br_ptr, BUFFER(sizeof(*var_ptr), (u8 *)var_ptr)))
|
||||
#define br_read_to_struct(br_ptr, var_ptr) (br_read_to_string(br_ptr, STRING(sizeof(*var_ptr), (u8 *)var_ptr)))
|
||||
|
||||
struct byte_reader br_from_buffer(struct buffer buff);
|
||||
struct byte_reader br_from_buffer(struct string buff);
|
||||
|
||||
void *br_seek(struct byte_reader *br, u64 amount);
|
||||
void *br_seek_to(struct byte_reader *br, u64 pos);
|
||||
|
||||
void br_read_to_buffer(struct byte_reader *br, struct buffer buff);
|
||||
void br_read_to_string(struct byte_reader *br, struct string s);
|
||||
u8 br_read_u8(struct byte_reader *br);
|
||||
u16 br_read_u16(struct byte_reader *br);
|
||||
u32 br_read_u32(struct byte_reader *br);
|
||||
@ -83,12 +83,12 @@ struct v2 br_read_v2(struct byte_reader *br);
|
||||
|
||||
INLINE u64 br_bytes_left(const struct byte_reader *br)
|
||||
{
|
||||
return br->overflowed ? 0 : br->buff.size - (br->at - br->buff.data);
|
||||
return br->overflowed ? 0 : br->buff.len - (br->at - br->buff.text);
|
||||
}
|
||||
|
||||
INLINE u64 br_pos(struct byte_reader *br)
|
||||
{
|
||||
return br->at - br->buff.data;
|
||||
return br->at - br->buff.text;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
46
src/common.h
46
src/common.h
@ -496,11 +496,6 @@ struct pcm {
|
||||
i16 *samples;
|
||||
};
|
||||
|
||||
struct buffer {
|
||||
u64 size;
|
||||
u8 *data;
|
||||
};
|
||||
|
||||
struct entity_handle {
|
||||
u64 idx;
|
||||
u64 gen;
|
||||
@ -521,42 +516,31 @@ struct sprite_tag {
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Buffer utils
|
||||
* String utils
|
||||
* ========================== */
|
||||
|
||||
/* Utility buffer constructor */
|
||||
#define BUFFER(size, data) (CPPCOMPAT_INITLIST_TYPE(struct buffer) { (size), (data) })
|
||||
/* Expand C string literal with size for string initialization */
|
||||
#define LIT(cstr_lit) CPPCOMPAT_INITLIST_TYPE(struct string) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) }
|
||||
|
||||
/* Utility buffer constructor from static array */
|
||||
#define BUFFER_FROM_ARRAY(a) \
|
||||
/* Same as `STR`, but works with static variable initialization */
|
||||
#define LIT_NOCAST(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) }
|
||||
|
||||
#define STRING(size, data) (CPPCOMPAT_INITLIST_TYPE(struct string) { (size), (data) })
|
||||
|
||||
#define STRING_FROM_POINTERS(p0, p1) (CPPCOMPAT_INITLIST_TYPE(struct string) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 })
|
||||
|
||||
#define STRING_FROM_STRUCT(ptr) (CPPCOMPAT_INITLIST_TYPE(struct string) { sizeof(*(ptr)), (u8 *)(ptr) })
|
||||
|
||||
/* String from static array */
|
||||
#define STRING_FROM_ARRAY(a) \
|
||||
( \
|
||||
/* Must be array */ \
|
||||
ASSERT(IS_ARRAY(a)), \
|
||||
/* Must be array of bytes */ \
|
||||
ASSERT(sizeof((a)[0]) == sizeof(u8)), \
|
||||
((struct buffer) { .size = ARRAY_COUNT(a), .data = (u8 *)(a) }) \
|
||||
((struct string) { .len = ARRAY_COUNT(a), .text = (u8 *)(a) }) \
|
||||
)
|
||||
|
||||
#define BUFFER_FROM_STRING(str) (CPPCOMPAT_INITLIST_TYPE(struct buffer) { (str).len, (str).text })
|
||||
|
||||
#define BUFFER_FROM_POINTERS(p0, p1) (CPPCOMPAT_INITLIST_TYPE(struct buffer) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 })
|
||||
|
||||
#define BUFFER_FROM_STRUCT(ptr) (CPPCOMPAT_INITLIST_TYPE(struct buffer) { sizeof(*(ptr)), (u8 *)(ptr) })
|
||||
|
||||
/* ========================== *
|
||||
* String utils
|
||||
* ========================== */
|
||||
|
||||
/* Expand C string literal with size for string initialization */
|
||||
#define STR(cstr_lit) CPPCOMPAT_INITLIST_TYPE(struct string) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) }
|
||||
|
||||
/* Same as `STR`, but works with static variable initialization */
|
||||
#define STR_NOCAST(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) }
|
||||
|
||||
#define STRING_FROM_BUFFER(buff) (CPPCOMPAT_INITLIST_TYPE(struct string) { buff.size, buff.data })
|
||||
|
||||
#define STRING_FROM_ARRAY(a) STRING_FROM_BUFFER(BUFFER_FROM_ARRAY(a))
|
||||
|
||||
/* ========================== *
|
||||
* Math types
|
||||
* ========================== */
|
||||
|
||||
@ -498,8 +498,8 @@ void entity_lookup_remove(struct entity_lookup *l, struct entity_lookup_entry *e
|
||||
struct entity_lookup_key entity_lookup_key_from_two_handles(struct entity_handle h0, struct entity_handle h1)
|
||||
{
|
||||
struct entity_lookup_key key = ZI;
|
||||
struct buffer b0 = BUFFER_FROM_STRUCT(&h0);
|
||||
struct buffer b1 = BUFFER_FROM_STRUCT(&h1);
|
||||
struct string b0 = STRING_FROM_STRUCT(&h0);
|
||||
struct string b1 = STRING_FROM_STRUCT(&h1);
|
||||
key.hash = hash_fnv64(HASH_FNV64_BASIS, b0);
|
||||
key.hash = hash_fnv64(key.hash, b1);
|
||||
return key;
|
||||
|
||||
14
src/font.c
14
src/font.c
@ -104,11 +104,11 @@ INTERNAL WORK_TASK_FUNC_DEF(font_load_asset_task, vparams)
|
||||
logf_info("Loading font \"%F\" (point size %F)", FMT_STR(path), FMT_FLOAT((f64)point_size));
|
||||
i64 start_ns = sys_time_ns();
|
||||
|
||||
ASSERT(string_ends_with(path, STR(".ttf")));
|
||||
ASSERT(string_ends_with(path, LIT(".ttf")));
|
||||
if (!resource_exists(path)) {
|
||||
/* FIME: Load baked font instead of panicking */
|
||||
sys_panic(string_format(scratch.arena,
|
||||
STR("Font \"%F\" not found"),
|
||||
LIT("Font \"%F\" not found"),
|
||||
FMT_STR(path)));
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ INTERNAL WORK_TASK_FUNC_DEF(font_load_asset_task, vparams)
|
||||
|
||||
/* Decode */
|
||||
struct resource res = resource_open(path);
|
||||
struct ttf_decode_result result = ttf_decode(scratch.arena, res.bytes, point_size, g_font_codes, ARRAY_COUNT(g_font_codes));
|
||||
struct ttf_decode_result result = ttf_decode(scratch.arena, res.data, point_size, g_font_codes, ARRAY_COUNT(g_font_codes));
|
||||
resource_close(res);
|
||||
|
||||
/* Send texture to GPU */
|
||||
@ -142,7 +142,7 @@ INTERNAL WORK_TASK_FUNC_DEF(font_load_asset_task, vparams)
|
||||
/* FIXME: Load baked font instead of panicking */
|
||||
if (font->glyphs_count <= 0) {
|
||||
sys_panic(string_format(scratch.arena,
|
||||
STR("Parsed 0 glyphs from font \"%F\"!"),
|
||||
LIT("Parsed 0 glyphs from font \"%F\"!"),
|
||||
FMT_STR(path)));
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ struct asset *font_load_asset(struct string path, f32 point_size, b32 help)
|
||||
|
||||
/* Concatenate point_size to path for key */
|
||||
struct string key = string_format(scratch.arena,
|
||||
STR("%F%F_font"),
|
||||
LIT("%F%F_font"),
|
||||
FMT_STR(path),
|
||||
FMT_FLOAT_P((f64)point_size, 3));
|
||||
u64 hash = asset_cache_hash(key);
|
||||
@ -184,10 +184,10 @@ struct asset *font_load_asset(struct string path, f32 point_size, b32 help)
|
||||
struct font_task_params *params = font_task_params_alloc();
|
||||
if (path.len > (sizeof(params->path_cstr) - 1)) {
|
||||
sys_panic(string_format(scratch.arena,
|
||||
STR("Font path \"%F\" too long!"),
|
||||
LIT("Font path \"%F\" too long!"),
|
||||
FMT_STR(path)));
|
||||
}
|
||||
cstr_buff_from_string(BUFFER_FROM_ARRAY(params->path_cstr), path);
|
||||
cstr_buff_from_string(STRING_FROM_ARRAY(params->path_cstr), path);
|
||||
params->path_len = path.len;
|
||||
params->asset = asset;
|
||||
params->point_size = point_size;
|
||||
|
||||
76
src/game.c
76
src/game.c
@ -84,7 +84,7 @@ struct game_startup_receipt game_startup(struct mixer_startup_receipt *mixer_sr,
|
||||
arena_set_readonly(&G.prev_tick.entity_store->arena);
|
||||
G.prev_tick_mutex = sys_mutex_alloc();
|
||||
|
||||
G.game_thread = sys_thread_alloc(&game_thread_entry_point, NULL, STR("[P2] Game thread"));
|
||||
G.game_thread = sys_thread_alloc(&game_thread_entry_point, NULL, LIT("[P2] Game thread"));
|
||||
app_register_exit_callback(&game_shutdown);
|
||||
|
||||
return (struct game_startup_receipt) { 0 };
|
||||
@ -157,16 +157,16 @@ INTERNAL void spawn_test_entities(void)
|
||||
if (!G.extra_spawn) {
|
||||
entity_enable_prop(e, ENTITY_PROP_PLAYER_CONTROLLED);
|
||||
entity_enable_prop(e, ENTITY_PROP_TEST);
|
||||
e->sprite = sprite_tag_from_path(STR("res/graphics/tim.ase"));
|
||||
e->sprite = sprite_tag_from_path(LIT("res/graphics/tim.ase"));
|
||||
e->mass_unscaled = 10;
|
||||
e->inertia_unscaled = 5;
|
||||
} else {
|
||||
entity_enable_prop(e, ENTITY_PROP_TEST);
|
||||
e->sprite = sprite_tag_from_path(STR("res/graphics/tim.ase"));
|
||||
e->sprite = sprite_tag_from_path(LIT("res/graphics/tim.ase"));
|
||||
e->mass_unscaled = 10;
|
||||
e->inertia_unscaled = 5;
|
||||
#if 0
|
||||
e->sprite = sprite_tag_from_path(STR("res/graphics/box.ase"));
|
||||
e->sprite = sprite_tag_from_path(LIT("res/graphics/box.ase"));
|
||||
e->mass_unscaled = 100;
|
||||
e->inertia_unscaled = 100;
|
||||
#endif
|
||||
@ -177,10 +177,10 @@ INTERNAL void spawn_test_entities(void)
|
||||
e->local_collider.count = 2;
|
||||
e->local_collider.radius = 0.075f;
|
||||
|
||||
//e->sprite = sprite_tag_from_path(STR("res/graphics/box_rounded.ase"));
|
||||
//e->sprite_span_name = STR("idle.unarmed");
|
||||
//e->sprite_span_name = STR("idle.one_handed");
|
||||
e->sprite_span_name = STR("idle.two_handed");
|
||||
//e->sprite = sprite_tag_from_path(LIT("res/graphics/box_rounded.ase"));
|
||||
//e->sprite_span_name = LIT("idle.unarmed");
|
||||
//e->sprite_span_name = LIT("idle.one_handed");
|
||||
e->sprite_span_name = LIT("idle.two_handed");
|
||||
e->layer = GAME_LAYER_SHOULDERS;
|
||||
|
||||
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
|
||||
@ -212,8 +212,8 @@ INTERNAL void spawn_test_entities(void)
|
||||
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
|
||||
entity_set_xform(e, xf);
|
||||
|
||||
e->sprite = sprite_tag_from_path(STR("res/graphics/tim.ase"));
|
||||
e->sprite_collider_slice = STR("shape");
|
||||
e->sprite = sprite_tag_from_path(LIT("res/graphics/tim.ase"));
|
||||
e->sprite_collider_slice = LIT("shape");
|
||||
e->layer = GAME_LAYER_SHOULDERS;
|
||||
|
||||
entity_enable_prop(e, ENTITY_PROP_PHYSICAL_DYNAMIC);
|
||||
@ -235,8 +235,8 @@ INTERNAL void spawn_test_entities(void)
|
||||
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
|
||||
entity_set_xform(e, xf);
|
||||
|
||||
e->sprite = sprite_tag_from_path(STR("res/graphics/box.ase"));
|
||||
e->sprite_collider_slice = STR("shape");
|
||||
e->sprite = sprite_tag_from_path(LIT("res/graphics/box.ase"));
|
||||
e->sprite_collider_slice = LIT("shape");
|
||||
e->layer = GAME_LAYER_SHOULDERS;
|
||||
|
||||
entity_enable_prop(e, ENTITY_PROP_PHYSICAL_DYNAMIC);
|
||||
@ -258,8 +258,8 @@ INTERNAL void spawn_test_entities(void)
|
||||
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
|
||||
entity_set_xform(e, xf);
|
||||
|
||||
e->sprite = sprite_tag_from_path(STR("res/graphics/bullet.ase"));
|
||||
e->sprite_collider_slice = STR("shape");
|
||||
e->sprite = sprite_tag_from_path(LIT("res/graphics/bullet.ase"));
|
||||
e->sprite_collider_slice = LIT("shape");
|
||||
e->layer = GAME_LAYER_SHOULDERS;
|
||||
|
||||
entity_enable_prop(e, ENTITY_PROP_PHYSICAL_DYNAMIC);
|
||||
@ -272,10 +272,10 @@ INTERNAL void spawn_test_entities(void)
|
||||
/* Player weapon */
|
||||
if (player_ent->valid) {
|
||||
struct entity *e = entity_alloc(player_ent);
|
||||
e->sprite = sprite_tag_from_path(STR("res/graphics/gun.ase"));
|
||||
e->sprite = sprite_tag_from_path(LIT("res/graphics/gun.ase"));
|
||||
|
||||
entity_enable_prop(e, ENTITY_PROP_ATTACHED);
|
||||
e->attach_slice = STR("attach.wep");
|
||||
e->attach_slice = LIT("attach.wep");
|
||||
e->layer = GAME_LAYER_RELATIVE_WEAPON;
|
||||
|
||||
entity_enable_prop(e, ENTITY_PROP_WEAPON);
|
||||
@ -411,7 +411,7 @@ INTERNAL PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, array)
|
||||
{
|
||||
struct xform xf = XFORM_TRS(.t = point, .r = rng_rand_f32(0, TAU));
|
||||
struct entity *decal = entity_alloc(root);
|
||||
decal->sprite = sprite_tag_from_path(STR("res/graphics/blood.ase"));
|
||||
decal->sprite = sprite_tag_from_path(LIT("res/graphics/blood.ase"));
|
||||
decal->sprite_tint = RGBA_32_F(1, 1, 1, 0.25f);
|
||||
decal->layer = GAME_LAYER_FLOOR_DECALS;
|
||||
entity_set_xform(decal, xf);
|
||||
@ -611,7 +611,7 @@ INTERNAL void game_update(struct game_cmd_list game_cmds)
|
||||
|
||||
/* Update sprite local xform */
|
||||
{
|
||||
struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("pivot"), ent->animation_frame);
|
||||
struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, LIT("pivot"), ent->animation_frame);
|
||||
struct v2 sprite_size = v2_div(sheet->frame_size, (f32)IMAGE_PIXELS_PER_UNIT);
|
||||
|
||||
struct v2 dir = v2_mul_v2(sprite_size, slice.dir);
|
||||
@ -838,7 +838,7 @@ INTERNAL void game_update(struct game_cmd_list game_cmds)
|
||||
|
||||
struct xform sprite_local_xform = ent->sprite_local_xform;
|
||||
|
||||
struct sprite_sheet_slice out_slice = sprite_sheet_get_slice(sheet, STR("out"), animation_frame);
|
||||
struct sprite_sheet_slice out_slice = sprite_sheet_get_slice(sheet, LIT("out"), animation_frame);
|
||||
struct v2 rel_pos = xform_mul_v2(sprite_local_xform, out_slice.center);
|
||||
struct v2 rel_dir = xform_basis_mul_v2(sprite_local_xform, out_slice.dir);
|
||||
|
||||
@ -861,8 +861,8 @@ INTERNAL void game_update(struct game_cmd_list game_cmds)
|
||||
bullet->local_collider.points[0] = V2(0, 0);
|
||||
bullet->local_collider.count = 1;
|
||||
#else
|
||||
bullet->sprite = sprite_tag_from_path(STR("res/graphics/bullet.ase"));
|
||||
bullet->sprite_collider_slice = STR("shape");
|
||||
bullet->sprite = sprite_tag_from_path(LIT("res/graphics/bullet.ase"));
|
||||
bullet->sprite_collider_slice = LIT("shape");
|
||||
#endif
|
||||
|
||||
entity_enable_prop(bullet, ENTITY_PROP_BULLET);
|
||||
@ -972,7 +972,7 @@ INTERNAL void game_update(struct game_cmd_list game_cmds)
|
||||
struct v2 sprite_hold_dir;
|
||||
{
|
||||
struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite);
|
||||
struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("attach.wep"), ent->animation_frame);
|
||||
struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, LIT("attach.wep"), ent->animation_frame);
|
||||
sprite_hold_pos = slice.center;
|
||||
sprite_hold_dir = slice.dir;
|
||||
}
|
||||
@ -1315,7 +1315,7 @@ INTERNAL void game_update(struct game_cmd_list game_cmds)
|
||||
* Game cmd
|
||||
* ========================== */
|
||||
|
||||
struct buffer game_string_from_cmds(struct arena *arena, struct game_cmd_list *cmds)
|
||||
struct string game_string_from_cmds(struct arena *arena, struct game_cmd_list *cmds)
|
||||
{
|
||||
struct byte_writer bw = bw_from_arena(arena);
|
||||
|
||||
@ -1346,16 +1346,14 @@ struct buffer game_string_from_cmds(struct arena *arena, struct game_cmd_list *c
|
||||
}
|
||||
|
||||
u64 size = bw_pos(&bw) - start;
|
||||
if (size > 100) {
|
||||
DEBUGBREAKABLE;
|
||||
}
|
||||
bw_write_u64(&bw_size, size);
|
||||
}
|
||||
|
||||
return bw.buff;
|
||||
|
||||
return bw_get_written(&bw);
|
||||
}
|
||||
|
||||
struct game_cmd_list game_cmds_from_string(struct arena *arena, struct buffer str)
|
||||
struct game_cmd_list game_cmds_from_string(struct arena *arena, struct string str)
|
||||
{
|
||||
struct game_cmd_list l = ZI;
|
||||
|
||||
@ -1404,24 +1402,24 @@ struct game_cmd_list game_cmds_from_string(struct arena *arena, struct buffer st
|
||||
* Game cmd
|
||||
* ========================== */
|
||||
|
||||
INTERNAL void push_input_string(struct buffer input)
|
||||
INTERNAL void push_input_string(struct string input)
|
||||
{
|
||||
struct sys_lock lock = sys_mutex_lock_e(&G.game_input_mutex);
|
||||
u8 *dst = arena_push_array(&G.game_input_arena, u8, input.size);
|
||||
MEMCPY(dst, input.data, input.size);
|
||||
u8 *dst = arena_push_array(&G.game_input_arena, u8, input.len);
|
||||
MEMCPY(dst, input.text, input.len);
|
||||
sys_mutex_unlock(&lock);
|
||||
}
|
||||
|
||||
INTERNAL struct buffer pop_input_string(struct arena *arena)
|
||||
INTERNAL struct string pop_input_string(struct arena *arena)
|
||||
{
|
||||
struct buffer buff = ZI;
|
||||
struct string s = ZI;
|
||||
struct sys_lock lock = sys_mutex_lock_e(&G.game_input_mutex);
|
||||
buff.size = G.game_input_arena.pos;
|
||||
buff.data = arena_push_array(arena, u8, buff.size);
|
||||
MEMCPY(buff.data, G.game_input_arena.base, buff.size);
|
||||
s.len = G.game_input_arena.pos;
|
||||
s.text = arena_push_array(arena, u8, s.len);
|
||||
MEMCPY(s.text, G.game_input_arena.base, s.len);
|
||||
arena_reset(&G.game_input_arena);
|
||||
sys_mutex_unlock(&lock);
|
||||
return buff;
|
||||
return s;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -1446,7 +1444,7 @@ u64 game_get_latest_tick_continuity_gen(void)
|
||||
return atomic_u64_eval(&G.prev_tick_continuity_gen);
|
||||
}
|
||||
|
||||
void game_push_cmds_string(struct buffer str)
|
||||
void game_push_cmds_string(struct string str)
|
||||
{
|
||||
push_input_string(str);
|
||||
}
|
||||
@ -1468,7 +1466,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(game_thread_entry_point, arg)
|
||||
sleep_frame(last_frame_ns, target_dt_ns);
|
||||
last_frame_ns = sys_time_ns();
|
||||
{
|
||||
struct buffer input_str = pop_input_string(temp.arena);
|
||||
struct string input_str = pop_input_string(temp.arena);
|
||||
struct game_cmd_list cmds = game_cmds_from_string(temp.arena, input_str);
|
||||
if (!G.paused) {
|
||||
game_update(cmds);
|
||||
|
||||
@ -78,12 +78,12 @@ struct game_cmd_list {
|
||||
* Interface
|
||||
* ========================== */
|
||||
|
||||
struct buffer game_string_from_cmds(struct arena *arena, struct game_cmd_list *cmds);
|
||||
struct game_cmd_list game_cmds_from_string(struct arena *arena, struct buffer str);
|
||||
struct string game_string_from_cmds(struct arena *arena, struct game_cmd_list *cmds);
|
||||
struct game_cmd_list game_cmds_from_string(struct arena *arena, struct string str);
|
||||
|
||||
void game_get_latest_tick(struct world *dest);
|
||||
u64 game_get_latest_tick_id(void);
|
||||
u64 game_get_latest_tick_continuity_gen(void);
|
||||
void game_push_cmds_string(struct buffer str);
|
||||
void game_push_cmds_string(struct string str);
|
||||
|
||||
#endif
|
||||
|
||||
@ -8,14 +8,14 @@
|
||||
|
||||
#if RESOURCES_EMBEDDED
|
||||
INCBIN_INCLUDE(res_tar, INCBIN_DIR "res.tar");
|
||||
struct buffer inc_res_tar(void)
|
||||
struct string inc_res_tar(void)
|
||||
{
|
||||
return INCBIN_GET(res_tar);
|
||||
}
|
||||
#endif
|
||||
|
||||
INCBIN_INCLUDE(shaders_tar, INCBIN_DIR "shaders.tar");
|
||||
struct buffer inc_shaders_tar(void)
|
||||
struct string inc_shaders_tar(void)
|
||||
{
|
||||
return INCBIN_GET(shaders_tar);
|
||||
}
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
#define INC_H
|
||||
|
||||
#if RESOURCES_EMBEDDED
|
||||
struct buffer inc_res_tar(void);
|
||||
struct string inc_res_tar(void);
|
||||
#endif
|
||||
|
||||
struct buffer inc_shaders_tar(void);
|
||||
struct string inc_shaders_tar(void);
|
||||
|
||||
#endif
|
||||
|
||||
12
src/incbin.c
12
src/incbin.c
@ -19,7 +19,7 @@ struct rc_search_params {
|
||||
struct string name_lower;
|
||||
/* Out */
|
||||
b32 found;
|
||||
struct buffer data;
|
||||
struct string data;
|
||||
};
|
||||
|
||||
/* Find first resource with `type` and return the data in `udata`. */
|
||||
@ -29,15 +29,15 @@ INTERNAL BOOL CALLBACK enum_func(HMODULE module, LPCWSTR type, LPCWSTR wstr_entr
|
||||
struct rc_search_params *params = (struct rc_search_params *)udata;
|
||||
struct string entry_name_lower = string_lower(scratch.arena, string_from_wstr(scratch.arena, (LPWSTR)wstr_entry_name));
|
||||
params->found = false;
|
||||
params->data = BUFFER(0, 0);
|
||||
params->data = STRING(0, 0);
|
||||
if (string_eq(entry_name_lower, params->name_lower)) {
|
||||
HRSRC hres = FindResourceW(module, wstr_entry_name, type);
|
||||
if (hres) {
|
||||
HGLOBAL hg = LoadResource(module, hres);
|
||||
if (hg) {
|
||||
params->found = true;
|
||||
params->data.size = SizeofResource(module, hres);
|
||||
params->data.data = LockResource(hg);
|
||||
params->data.len = SizeofResource(module, hres);
|
||||
params->data.text = LockResource(hg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,7 +45,7 @@ INTERNAL BOOL CALLBACK enum_func(HMODULE module, LPCWSTR type, LPCWSTR wstr_entr
|
||||
return !params->found;
|
||||
}
|
||||
|
||||
struct buffer _incbin_get(struct _incbin_rc_resource *inc)
|
||||
struct string _incbin_get(struct _incbin_rc_resource *inc)
|
||||
{
|
||||
enum inc_state state = atomic_i32_eval(&inc->state);
|
||||
if (state != INCBIN_STATE_SEARCHED) {
|
||||
@ -60,7 +60,7 @@ struct buffer _incbin_get(struct _incbin_rc_resource *inc)
|
||||
EnumResourceNamesW(NULL, RT_RCDATA, &enum_func, (LONG_PTR)¶ms);
|
||||
if (!params.found) {
|
||||
sys_panic(string_format(scratch.arena,
|
||||
STR("INCBIN include not found in RC file: \"%F\""),
|
||||
LIT("INCBIN include not found in RC file: \"%F\""),
|
||||
FMT_STR(inc->rc_name)));
|
||||
}
|
||||
inc->data = params.data;
|
||||
|
||||
10
src/incbin.h
10
src/incbin.h
@ -12,7 +12,7 @@
|
||||
* file).
|
||||
* ========================== */
|
||||
|
||||
#define INCBIN_INCLUDE(var, _rc_name) static struct _incbin_rc_resource _incbin_ ## var = { .rc_name = STR_NOCAST((_rc_name)) }
|
||||
#define INCBIN_INCLUDE(var, _rc_name) static struct _incbin_rc_resource _incbin_ ## var = { .rc_name = LIT_NOCAST((_rc_name)) }
|
||||
#define INCBIN_GET(var) _incbin_get(&_incbin_ ## var)
|
||||
|
||||
enum _incbin_state {
|
||||
@ -24,10 +24,10 @@ enum _incbin_state {
|
||||
struct _incbin_rc_resource {
|
||||
struct atomic_i32 state;
|
||||
struct string rc_name;
|
||||
struct buffer data;
|
||||
struct string data;
|
||||
};
|
||||
|
||||
struct buffer _incbin_get(struct _incbin_rc_resource *inc);
|
||||
struct string _incbin_get(struct _incbin_rc_resource *inc);
|
||||
|
||||
#else
|
||||
|
||||
@ -62,8 +62,8 @@ struct buffer _incbin_get(struct _incbin_rc_resource *inc);
|
||||
extern __attribute((aligned(16))) const char _incbin_ ## var ## _start[]; \
|
||||
extern const char _incbin_ ## var ## _end[]
|
||||
|
||||
/* Retrieve a buffer for included data using the variable supplied to INCBIN_INCLUDE */
|
||||
#define INCBIN_GET(var) BUFFER_FROM_POINTERS(_incbin_ ## var ## _start, _incbin_ ## var ## _end)
|
||||
/* Retrieve a string from included data using the variable supplied to INCBIN_INCLUDE */
|
||||
#define INCBIN_GET(var) STRING_FROM_POINTERS(_incbin_ ## var ## _start, _incbin_ ## var ## _end)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
22
src/json.c
22
src/json.c
@ -70,9 +70,9 @@ enum lex_number_state {
|
||||
};
|
||||
|
||||
GLOBAL READONLY struct string g_keyword_strings[] = {
|
||||
['t'] = STR_NOCAST("true"),
|
||||
['f'] = STR_NOCAST("false"),
|
||||
['n'] = STR_NOCAST("null")
|
||||
['t'] = LIT_NOCAST("true"),
|
||||
['f'] = LIT_NOCAST("false"),
|
||||
['n'] = LIT_NOCAST("null")
|
||||
};
|
||||
|
||||
GLOBAL READONLY enum token_type g_keyword_types[] = {
|
||||
@ -537,7 +537,7 @@ INTERNAL struct string interpret_string(struct arena *arena, struct string src,
|
||||
|
||||
if (src.len < 2) {
|
||||
if (error) {
|
||||
*error = STR("Malformed string.");
|
||||
*error = LIT("Malformed string.");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -599,7 +599,7 @@ INTERNAL struct string interpret_string(struct arena *arena, struct string src,
|
||||
|
||||
default: {
|
||||
if (error) {
|
||||
*error = STR("Invalid escape character in string.");
|
||||
*error = LIT("Invalid escape character in string.");
|
||||
return res;
|
||||
}
|
||||
} break;
|
||||
@ -627,7 +627,7 @@ INTERNAL struct string interpret_string(struct arena *arena, struct string src,
|
||||
|
||||
if (!valid_close) {
|
||||
if (error) {
|
||||
*error = STR("Expected end of string.");
|
||||
*error = LIT("Expected end of string.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -695,7 +695,7 @@ INTERNAL void parse(struct arena *arena, struct parser *p)
|
||||
if (at->type == tok_close_type) {
|
||||
at = at->next;
|
||||
} else {
|
||||
push_error(arena, p, at, STR("Expected comma."));
|
||||
push_error(arena, p, at, LIT("Expected comma."));
|
||||
at = at->next;
|
||||
goto abort;
|
||||
}
|
||||
@ -715,7 +715,7 @@ INTERNAL void parse(struct arena *arena, struct parser *p)
|
||||
at = at->next;
|
||||
}
|
||||
} else {
|
||||
push_error(arena, p, at, STR("Key expected."));
|
||||
push_error(arena, p, at, LIT("Key expected."));
|
||||
goto abort;
|
||||
}
|
||||
|
||||
@ -723,7 +723,7 @@ INTERNAL void parse(struct arena *arena, struct parser *p)
|
||||
if (at->type == TOKEN_TYPE_COLON) {
|
||||
at = at->next;
|
||||
} else {
|
||||
push_error(arena, p, at, STR("Colon expected."));
|
||||
push_error(arena, p, at, LIT("Colon expected."));
|
||||
goto abort;
|
||||
}
|
||||
}
|
||||
@ -790,7 +790,7 @@ INTERNAL void parse(struct arena *arena, struct parser *p)
|
||||
} break;
|
||||
|
||||
default: {
|
||||
push_error(arena, p, at, STR("Value expected."));
|
||||
push_error(arena, p, at, LIT("Value expected."));
|
||||
at = at->next;
|
||||
goto abort;
|
||||
} break;
|
||||
@ -847,7 +847,7 @@ struct json_parse_result json_from_string(struct arena *arena, struct string src
|
||||
|
||||
/* Verify end of file */
|
||||
if (p.errors.count == 0 && p.at->type != TOKEN_TYPE_EOF) {
|
||||
push_error(arena, &p, p.at, STR("Expected end of file."));
|
||||
push_error(arena, &p, p.at, LIT("Expected end of file."));
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
|
||||
26
src/log.c
26
src/log.c
@ -24,27 +24,27 @@ GLOBAL struct {
|
||||
|
||||
GLOBAL READONLY struct log_level_settings g_log_level_settings[LOG_LEVEL_COUNT] = {
|
||||
[LOG_LEVEL_CRITICAL] = {
|
||||
STR_NOCAST("CRITICAL"),
|
||||
LIT_NOCAST("CRITICAL"),
|
||||
0xFFFF00FF
|
||||
},
|
||||
|
||||
[LOG_LEVEL_ERROR] = {
|
||||
STR_NOCAST("ERROR"),
|
||||
LIT_NOCAST("ERROR"),
|
||||
0xFFFF0000
|
||||
},
|
||||
|
||||
[LOG_LEVEL_WARNING] = {
|
||||
STR_NOCAST("WARNING"),
|
||||
LIT_NOCAST("WARNING"),
|
||||
0xFFFFFF00
|
||||
},
|
||||
|
||||
[LOG_LEVEL_INFO] = {
|
||||
STR_NOCAST("INFO"),
|
||||
LIT_NOCAST("INFO"),
|
||||
0xFFFFFFFF
|
||||
},
|
||||
|
||||
[LOG_LEVEL_DEBUG] = {
|
||||
STR_NOCAST("DEBUG"),
|
||||
LIT_NOCAST("DEBUG"),
|
||||
0xFF30D5C8
|
||||
}
|
||||
};
|
||||
@ -96,8 +96,8 @@ INTERNAL void append_to_logfile(struct string msg)
|
||||
|
||||
if (G.file_valid) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct string msg_line = string_cat(scratch.arena, msg, STR("\n"));
|
||||
sys_file_write(G.file, BUFFER_FROM_STRING(msg_line));
|
||||
struct string msg_line = string_cat(scratch.arena, msg, LIT("\n"));
|
||||
sys_file_write(G.file, msg_line);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
@ -109,9 +109,9 @@ void _log_panic(struct string msg)
|
||||
if (!atomic_i32_eval(&G.initialized)) { return; }
|
||||
|
||||
if (G.file_valid) {
|
||||
sys_file_write(G.file, BUFFER_FROM_STRING(STR("******** PANICKING ********\n")));
|
||||
sys_file_write(G.file, BUFFER_FROM_STRING(msg));
|
||||
sys_file_write(G.file, BUFFER_FROM_STRING(STR("\n***************************\n")));
|
||||
sys_file_write(G.file, LIT("******** PANICKING ********\n"));
|
||||
sys_file_write(G.file, msg);
|
||||
sys_file_write(G.file, LIT("\n***************************\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ void _log(i32 level, struct string msg)
|
||||
if (!atomic_i32_eval(&G.initialized)) { return; }
|
||||
|
||||
if (level < 0 || level >= LOG_LEVEL_COUNT) {
|
||||
sys_panic(STR("Invalid log level"));
|
||||
sys_panic(LIT("Invalid log level"));
|
||||
}
|
||||
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
@ -139,7 +139,7 @@ void _log(i32 level, struct string msg)
|
||||
#if LOG_INCLUDE_SOURCE_LOCATION
|
||||
struct string msg_formatted = string_format(
|
||||
scratch.arena,
|
||||
STR("%F:%F:%F |Thread %F| [%F] <%F:%F> %F"),
|
||||
LIT("%F:%F:%F |Thread %F| [%F] <%F:%F> %F"),
|
||||
|
||||
/* Time */
|
||||
FMT_UINT(lt.hour),
|
||||
@ -162,7 +162,7 @@ void _log(i32 level, struct string msg)
|
||||
#else
|
||||
struct string msg_formatted = string_format(
|
||||
scratch.arena,
|
||||
STR("%F:%F:%F |Thread %F| [%F] %F"),
|
||||
LIT("%F:%F:%F |Thread %F| [%F] %F"),
|
||||
|
||||
/* Time */
|
||||
FMT_UINT(lt.hour),
|
||||
|
||||
30
src/log.h
30
src/log.h
@ -58,11 +58,11 @@ void log_register_callback(log_event_callback_func *func);
|
||||
|
||||
#if LOG_LEVEL(LOG_LEVEL_CRITICAL)
|
||||
# if LOG_INCLUDE_SOURCE_LOCATION
|
||||
# define log_critical(msg) _log(LOG_LEVEL_CRITICAL, STR(__FILE__), __LINE__, msg)
|
||||
# define logf_critical(fmt, ...) _logf(LOG_LEVEL_CRITICAL, STR(__FILE__), __LINE__, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define log_critical(msg) _log(LOG_LEVEL_CRITICAL, LIT(__FILE__), __LINE__, msg)
|
||||
# define logf_critical(fmt, ...) _logf(LOG_LEVEL_CRITICAL, LIT(__FILE__), __LINE__, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# else
|
||||
# define log_critical(msg) _log(LOG_LEVEL_CRITICAL, msg)
|
||||
# define logf_critical(fmt, ...) _logf(LOG_LEVEL_CRITICAL, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define logf_critical(fmt, ...) _logf(LOG_LEVEL_CRITICAL, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# endif
|
||||
#else
|
||||
# define log_critical(msg)
|
||||
@ -71,11 +71,11 @@ void log_register_callback(log_event_callback_func *func);
|
||||
|
||||
#if LOG_LEVEL(LOG_LEVEL_ERROR)
|
||||
# if LOG_INCLUDE_SOURCE_LOCATION
|
||||
# define log_error(msg) _log(LOG_LEVEL_ERROR, STR(__FILE__), __LINE__, msg)
|
||||
# define logf_error(fmt, ...) _logf(LOG_LEVEL_ERROR, STR(__FILE__), __LINE__, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define log_error(msg) _log(LOG_LEVEL_ERROR, LIT(__FILE__), __LINE__, msg)
|
||||
# define logf_error(fmt, ...) _logf(LOG_LEVEL_ERROR, LIT(__FILE__), __LINE__, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# else
|
||||
# define log_error(msg) _log(LOG_LEVEL_ERROR, msg)
|
||||
# define logf_error(fmt, ...) _logf(LOG_LEVEL_ERROR, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define logf_error(fmt, ...) _logf(LOG_LEVEL_ERROR, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# endif
|
||||
#else
|
||||
# define log_error(msg)
|
||||
@ -84,11 +84,11 @@ void log_register_callback(log_event_callback_func *func);
|
||||
|
||||
#if LOG_LEVEL(LOG_LEVEL_WARNING)
|
||||
# if LOG_INCLUDE_SOURCE_LOCATION
|
||||
# define log_warning(msg) _log(LOG_LEVEL_WARNING, STR(__FILE__), __LINE__, msg)
|
||||
# define logf_warning(fmt, ...) _logf(LOG_LEVEL_WARNING, STR(__FILE__), __LINE__, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define log_warning(msg) _log(LOG_LEVEL_WARNING, LIT(__FILE__), __LINE__, msg)
|
||||
# define logf_warning(fmt, ...) _logf(LOG_LEVEL_WARNING, LIT(__FILE__), __LINE__, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# else
|
||||
# define log_warning(msg) _log(LOG_LEVEL_WARNING, msg)
|
||||
# define logf_warning(fmt, ...) _logf(LOG_LEVEL_WARNING, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define logf_warning(fmt, ...) _logf(LOG_LEVEL_WARNING, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# endif
|
||||
#else
|
||||
# define log_warning(msg)
|
||||
@ -97,11 +97,11 @@ void log_register_callback(log_event_callback_func *func);
|
||||
|
||||
#if LOG_LEVEL(LOG_LEVEL_DEBUG)
|
||||
# if LOG_INCLUDE_SOURCE_LOCATION
|
||||
# define log_debug(msg) _log(LOG_LEVEL_DEBUG, STR(__FILE__), __LINE__, msg)
|
||||
# define logf_debug(fmt, ...) _logf(LOG_LEVEL_DEBUG, STR(__FILE__), __LINE__, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define log_debug(msg) _log(LOG_LEVEL_DEBUG, LIT(__FILE__), __LINE__, msg)
|
||||
# define logf_debug(fmt, ...) _logf(LOG_LEVEL_DEBUG, LIT(__FILE__), __LINE__, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# else
|
||||
# define log_debug(msg) _log(LOG_LEVEL_DEBUG, msg)
|
||||
# define logf_debug(fmt, ...) _logf(LOG_LEVEL_DEBUG, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define logf_debug(fmt, ...) _logf(LOG_LEVEL_DEBUG, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# endif
|
||||
#else
|
||||
# define log_debug(msg)
|
||||
@ -111,11 +111,11 @@ void log_register_callback(log_event_callback_func *func);
|
||||
|
||||
#if LOG_LEVEL(LOG_LEVEL_INFO)
|
||||
# if LOG_INCLUDE_SOURCE_LOCATION
|
||||
# define log_info(msg) _log(LOG_LEVEL_INFO, STR(__FILE__), __LINE__, msg)
|
||||
# define logf_info(fmt, ...) _logf(LOG_LEVEL_INFO, STR(__FILE__), __LINE__, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define log_info(msg) _log(LOG_LEVEL_INFO, LIT(__FILE__), __LINE__, msg)
|
||||
# define logf_info(fmt, ...) _logf(LOG_LEVEL_INFO, LIT(__FILE__), __LINE__, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# else
|
||||
# define log_info(msg) _log(LOG_LEVEL_INFO, msg)
|
||||
# define logf_info(fmt, ...) _logf(LOG_LEVEL_INFO, STR(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# define logf_info(fmt, ...) _logf(LOG_LEVEL_INFO, LIT(fmt) , ## __VA_ARGS__, FMT_END)
|
||||
# endif
|
||||
#else
|
||||
# define log_info(msg)
|
||||
|
||||
@ -9,6 +9,6 @@ struct mp3_decode_result {
|
||||
b32 success;
|
||||
};
|
||||
|
||||
struct mp3_decode_result mp3_decode(struct arena *arena, struct buffer encoded, u32 flags);
|
||||
struct mp3_decode_result mp3_decode(struct arena *arena, struct string encoded, u32 flags);
|
||||
|
||||
#endif
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
#pragma comment(lib, "mfreadwrite")
|
||||
#pragma comment(lib, "shlwapi")
|
||||
|
||||
struct mp3_decode_result mp3_decode(struct arena *arena, struct buffer encoded, u32 flags)
|
||||
struct mp3_decode_result mp3_decode(struct arena *arena, struct string encoded, u32 flags)
|
||||
{
|
||||
struct mp3_decode_result res = ZI;
|
||||
|
||||
@ -47,8 +47,8 @@ struct mp3_decode_result mp3_decode(struct arena *arena, struct buffer encoded,
|
||||
|
||||
MFStartup(MF_VERSION, MFSTARTUP_LITE);
|
||||
|
||||
/* Create IStream from buffer */
|
||||
IStream *i_stream = SHCreateMemStream(encoded.data, encoded.size);
|
||||
/* Create IStream from encoded string */
|
||||
IStream *i_stream = SHCreateMemStream(encoded.text, encoded.len);
|
||||
|
||||
/* Create IMFByteStream from IStream */
|
||||
IMFByteStream *byte_stream = NULL;
|
||||
|
||||
@ -60,7 +60,7 @@ struct playback_startup_receipt playback_startup(struct mixer_startup_receipt *m
|
||||
(UNUSED)mixer_sr;
|
||||
|
||||
wasapi_initialize();
|
||||
G.playback_thread = sys_thread_alloc(&playback_thread_entry_point, NULL, STR("[P3] Audio thread"));
|
||||
G.playback_thread = sys_thread_alloc(&playback_thread_entry_point, NULL, LIT("[P3] Audio thread"));
|
||||
app_register_exit_callback(&playback_shutdown);
|
||||
|
||||
return (struct playback_startup_receipt) { 0 };
|
||||
|
||||
@ -196,7 +196,7 @@ INTERNAL void send_constant_buffer_data(ID3D11Buffer *buffer, struct mat4x4 vp)
|
||||
INTERNAL void process_shader_compilation_error(ID3DBlob *error_blob)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct string error_prefix = string_copy(scratch.arena, STR("Failed to compile shader:\n"));
|
||||
struct string error_prefix = string_copy(scratch.arena, LIT("Failed to compile shader:\n"));
|
||||
if (error_blob) {
|
||||
char *compile_error_cstr = (char *)ID3D10Blob_GetBufferPointer(error_blob);
|
||||
struct string error_msg = string_cat(scratch.arena, error_prefix, string_from_cstr(compile_error_cstr));
|
||||
@ -259,21 +259,21 @@ INTERNAL void shader_init(struct dx11_shader *shader, enum shader_kind kind)
|
||||
struct tar_entry *tar_entry = tar_get(&G.shaders_archive, name);
|
||||
if (!tar_entry) {
|
||||
sys_panic(string_format(scratch.arena,
|
||||
STR("Could not find shader \"%F\""),
|
||||
LIT("Could not find shader \"%F\""),
|
||||
FMT_STR(name)));
|
||||
}
|
||||
struct buffer shader_src = tar_entry->buff;
|
||||
struct string shader_src = tar_entry->data;
|
||||
|
||||
|
||||
logf_info("Compiling shader \"%F\"", FMT_STR(name));
|
||||
/* Compile shader */
|
||||
/* TODO: pre-compile shaders w/ FXC? */
|
||||
ID3DBlob *error_blob;
|
||||
HRESULT v_res = D3DCompile(shader_src.data, shader_src.size, NULL, NULL, NULL, "vs_main", "vs_5_0", flags, 0, &vs_blob, &error_blob);
|
||||
HRESULT v_res = D3DCompile(shader_src.text, shader_src.len, NULL, NULL, NULL, "vs_main", "vs_5_0", flags, 0, &vs_blob, &error_blob);
|
||||
if (FAILED(v_res)) {
|
||||
process_shader_compilation_error(error_blob);
|
||||
}
|
||||
HRESULT p_res = D3DCompile(shader_src.data, shader_src.size, NULL, NULL, NULL, "ps_main", "ps_5_0", flags, 0, &ps_blob, &error_blob);
|
||||
HRESULT p_res = D3DCompile(shader_src.text, shader_src.len, NULL, NULL, NULL, "ps_main", "ps_5_0", flags, 0, &ps_blob, &error_blob);
|
||||
if (FAILED(p_res)) {
|
||||
process_shader_compilation_error(error_blob);
|
||||
}
|
||||
@ -316,9 +316,9 @@ struct renderer_startup_receipt renderer_startup(struct sys_window *window)
|
||||
G.textures_arena = arena_alloc(GIGABYTE(64));
|
||||
|
||||
/* Load shader archive */
|
||||
struct buffer embedded_data = inc_shaders_tar();
|
||||
if (embedded_data.size > 0) {
|
||||
G.shaders_archive = tar_parse(&G.arena, embedded_data, STR("shaders/"));
|
||||
struct string embedded_data = inc_shaders_tar();
|
||||
if (embedded_data.len > 0) {
|
||||
G.shaders_archive = tar_parse(&G.arena, embedded_data, LIT("shaders/"));
|
||||
}
|
||||
|
||||
/* Initialize shader table */
|
||||
@ -421,7 +421,7 @@ struct renderer_startup_receipt renderer_startup(struct sys_window *window)
|
||||
if (!SUCCEEDED(hr) || !device || !context || !swapchain) {
|
||||
/* Renderer initialization failure */
|
||||
/* TODO: Better message */
|
||||
sys_panic(STR("Failed to initialize renderer"));
|
||||
sys_panic(LIT("Failed to initialize renderer"));
|
||||
}
|
||||
G.dev = device;
|
||||
G.devcon = context;
|
||||
@ -866,7 +866,7 @@ struct renderer_cmd_buffer *renderer_cmd_buffer_alloc(void)
|
||||
}
|
||||
|
||||
if (!cmdbuff) {
|
||||
sys_panic(STR("Max renderer cmdbuffs reached"));
|
||||
sys_panic(LIT("Max renderer cmdbuffs reached"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -18,16 +18,16 @@ GLOBAL struct {
|
||||
struct resource_startup_receipt resource_startup(void)
|
||||
{
|
||||
#if RESOURCES_EMBEDDED
|
||||
struct buffer embedded_data = inc_res_tar();
|
||||
struct string embedded_data = inc_res_tar();
|
||||
G.arena = arena_alloc(GIGABYTE(64));
|
||||
if (embedded_data.size <= 0) {
|
||||
sys_panic(STR("No embedded resources found"));
|
||||
if (embedded_data.len <= 0) {
|
||||
sys_panic(LIT("No embedded resources found"));
|
||||
}
|
||||
G.archive = tar_parse(&G.arena, embedded_data, STR("res/"));
|
||||
G.archive = tar_parse(&G.arena, embedded_data, LIT("res/"));
|
||||
#else
|
||||
/* Ensure we have the right working directory */
|
||||
if (!sys_is_dir(STR("res"))) {
|
||||
sys_panic(STR("Resource directory \"res\" not found"));
|
||||
if (!sys_is_dir(LIT("res"))) {
|
||||
sys_panic(LIT("Resource directory \"res\" not found"));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -51,14 +51,14 @@ struct resource resource_open(struct string path)
|
||||
#if RESOURCES_EMBEDDED
|
||||
struct tar_entry *entry = tar_get(&G.archive, path);
|
||||
return (struct resource) {
|
||||
.bytes = entry ? entry->buff : BUFFER(0, 0)
|
||||
.data = entry ? entry->data : STRING(0, 0)
|
||||
};
|
||||
#else
|
||||
struct sys_file file = sys_file_open_read_wait(path);
|
||||
struct sys_file_map file_map = sys_file_map_open_read(file);
|
||||
struct buffer bytes = sys_file_map_data(file_map);
|
||||
struct string data = sys_file_map_data(file_map);
|
||||
return (struct resource) {
|
||||
.bytes = bytes,
|
||||
.data = data,
|
||||
.file = file,
|
||||
.file_map = file_map
|
||||
};
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* Represents raw bytes that can back a resource. This can be file data or embedded
|
||||
* data in the executable. */
|
||||
struct resource {
|
||||
struct buffer bytes;
|
||||
struct string data;
|
||||
|
||||
/* Internal */
|
||||
#if !RESOURCES_EMBEDDED
|
||||
|
||||
16
src/rng.c
16
src/rng.c
@ -20,13 +20,13 @@ INTERNAL void gen_random_file(struct string path, u32 count)
|
||||
{
|
||||
/* Clear file */
|
||||
struct sys_file f = sys_file_open_write(path);
|
||||
sys_file_write(f, BUFFER(0, 0));
|
||||
sys_file_write(f, STRING(0, 0));
|
||||
sys_file_close(f);
|
||||
}
|
||||
struct sys_file f = sys_file_open_append(path);
|
||||
for (u32 i = 0; i < count; ++i) {
|
||||
u64 rand = rng_rand_u64();
|
||||
sys_file_write(f, BUFFER_FROM_STRUCT(&rand));
|
||||
sys_file_write(f, STRING_FROM_STRUCT(&rand));
|
||||
}
|
||||
sys_file_close(f);
|
||||
}
|
||||
@ -40,15 +40,15 @@ struct rng_startup_receipt rng_startup(struct resource_startup_receipt *resource
|
||||
{
|
||||
(UNUSED)resource_sr;
|
||||
G.arena = arena_alloc(GIGABYTE(64));
|
||||
struct string noise_path = STR("res/noise.dat");
|
||||
struct string noise_path = LIT("res/noise.dat");
|
||||
if (resource_exists(noise_path)) {
|
||||
struct resource r = resource_open(noise_path);
|
||||
G.noise_count = r.bytes.size / sizeof(*G.noise);
|
||||
G.noise_count = r.data.len / sizeof(*G.noise);
|
||||
G.noise = arena_push_array(&G.arena, u64, G.noise_count);
|
||||
MEMCPY(G.noise, r.bytes.data, r.bytes.size);
|
||||
MEMCPY(G.noise, r.data.text, r.data.len);
|
||||
resource_close(r);
|
||||
} else {
|
||||
sys_panic(STR("Failed to locate pre-computed noise resource"));
|
||||
sys_panic(LIT("Failed to locate pre-computed noise resource"));
|
||||
}
|
||||
return (struct rng_startup_receipt) { 0 };
|
||||
}
|
||||
@ -60,14 +60,14 @@ struct rng_startup_receipt rng_startup(struct resource_startup_receipt *resource
|
||||
u32 rng_rand_u32(void)
|
||||
{
|
||||
u32 v = 0;
|
||||
sys_rand(BUFFER_FROM_STRUCT(&v));
|
||||
sys_rand(STRING_FROM_STRUCT(&v));
|
||||
return v;
|
||||
}
|
||||
|
||||
u64 rng_rand_u64(void)
|
||||
{
|
||||
u64 v = 0;
|
||||
sys_rand(BUFFER_FROM_STRUCT(&v));
|
||||
sys_rand(STRING_FROM_STRUCT(&v));
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ INLINE void scratch_dbg_push(struct scratch_ctx *ctx, struct temp_arena *temp)
|
||||
{
|
||||
#if RTC
|
||||
if (ctx->scratch_id_stack_count >= ARRAY_COUNT(ctx->scratch_id_stack)) {
|
||||
sys_panic(STR("Max debug scratch depth reached"));
|
||||
sys_panic(LIT("Max debug scratch depth reached"));
|
||||
}
|
||||
temp->scratch_id = ctx->next_scratch_id++;
|
||||
ctx->scratch_id_stack[ctx->scratch_id_stack_count++] = temp->scratch_id;
|
||||
|
||||
@ -5,19 +5,19 @@
|
||||
#include "scratch.h"
|
||||
#include "math.h"
|
||||
|
||||
struct buffer settings_serialize(struct arena *arena, const struct sys_window_settings *settings)
|
||||
struct string settings_serialize(struct arena *arena, const struct sys_window_settings *settings)
|
||||
{
|
||||
__prof;
|
||||
|
||||
struct string minimized = settings->flags & SYS_WINDOW_SETTINGS_FLAG_MINIMIZED ? STR("true") : STR("false");
|
||||
struct string maximized = settings->flags & SYS_WINDOW_SETTINGS_FLAG_MAXIMIZED ? STR("true") : STR("false");
|
||||
struct string fullscreen = settings->flags & SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN ? STR("true") : STR("false");
|
||||
struct string minimized = settings->flags & SYS_WINDOW_SETTINGS_FLAG_MINIMIZED ? LIT("true") : LIT("false");
|
||||
struct string maximized = settings->flags & SYS_WINDOW_SETTINGS_FLAG_MAXIMIZED ? LIT("true") : LIT("false");
|
||||
struct string fullscreen = settings->flags & SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN ? LIT("true") : LIT("false");
|
||||
i32 x = settings->floating_x;
|
||||
i32 y = settings->floating_y;
|
||||
i32 width = settings->floating_width;
|
||||
i32 height = settings->floating_height;
|
||||
|
||||
struct string fmt = STR(
|
||||
struct string fmt = LIT(
|
||||
"{\n"
|
||||
" \"window\": {\n"
|
||||
" \"minimized\": %F,\n"
|
||||
@ -41,10 +41,10 @@ struct buffer settings_serialize(struct arena *arena, const struct sys_window_se
|
||||
FMT_SINT(width),
|
||||
FMT_SINT(height));
|
||||
|
||||
return BUFFER_FROM_STRING(formatted);
|
||||
return formatted;
|
||||
}
|
||||
|
||||
struct sys_window_settings *settings_deserialize(struct arena *arena, struct buffer src, struct string *error_out)
|
||||
struct sys_window_settings *settings_deserialize(struct arena *arena, struct string src, struct string *error_out)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
@ -53,7 +53,7 @@ struct sys_window_settings *settings_deserialize(struct arena *arena, struct buf
|
||||
struct json_error json_error = ZI;
|
||||
|
||||
struct sys_window_settings *settings = arena_push_zero(arena, struct sys_window_settings);
|
||||
struct json_parse_result parse_res = json_from_string(scratch.arena, STRING_FROM_BUFFER(src));
|
||||
struct json_parse_result parse_res = json_from_string(scratch.arena, src);
|
||||
|
||||
if (parse_res.errors.count > 0) {
|
||||
json_error = *parse_res.errors.first;
|
||||
@ -62,13 +62,13 @@ struct sys_window_settings *settings_deserialize(struct arena *arena, struct buf
|
||||
|
||||
struct json *root = parse_res.root;
|
||||
if (!root) {
|
||||
error = STR("Root object not found.");
|
||||
error = LIT("Root object not found.");
|
||||
goto abort;
|
||||
}
|
||||
|
||||
struct json *window = root->child_first;
|
||||
if (!window || window->type != JSON_TYPE_OBJECT || !string_eq(window->key, STR("window"))) {
|
||||
error = STR("\"window\" object not found");
|
||||
if (!window || window->type != JSON_TYPE_OBJECT || !string_eq(window->key, LIT("window"))) {
|
||||
error = LIT("\"window\" object not found");
|
||||
goto abort;
|
||||
}
|
||||
|
||||
@ -81,48 +81,48 @@ struct sys_window_settings *settings_deserialize(struct arena *arena, struct buf
|
||||
for (struct json *child = window->child_first; child; child = child->next) {
|
||||
struct string key = child->key;
|
||||
|
||||
if (string_eq(key, STR("maximized"))) {
|
||||
if (string_eq(key, LIT("maximized"))) {
|
||||
if (child->type != JSON_TYPE_BOOL) {
|
||||
error = STR("Expected boolean for \"maximized\"");
|
||||
error = LIT("Expected boolean for \"maximized\"");
|
||||
goto abort;
|
||||
}
|
||||
if (child->value.boolean) {
|
||||
settings->flags |= SYS_WINDOW_SETTINGS_FLAG_MAXIMIZED;
|
||||
}
|
||||
found_maximized = true;
|
||||
} else if (string_eq(key, STR("fullscreen"))) {
|
||||
} else if (string_eq(key, LIT("fullscreen"))) {
|
||||
if (child->type != JSON_TYPE_BOOL) {
|
||||
error = STR("Expected boolean for \"fulscreen\"");
|
||||
error = LIT("Expected boolean for \"fulscreen\"");
|
||||
goto abort;
|
||||
}
|
||||
if (child->value.boolean) {
|
||||
settings->flags |= SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN;
|
||||
}
|
||||
found_fullscreen = true;
|
||||
} else if (string_eq(key, STR("x"))) {
|
||||
} else if (string_eq(key, LIT("x"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
error = STR("Expected number for \"x\"");
|
||||
error = LIT("Expected number for \"x\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_x = math_round_to_int(child->value.number);
|
||||
found_x = true;
|
||||
} else if (string_eq(key, STR("y"))) {
|
||||
} else if (string_eq(key, LIT("y"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
error = STR("Expected number for \"y\"");
|
||||
error = LIT("Expected number for \"y\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_y = math_round_to_int(child->value.number);
|
||||
found_y = true;
|
||||
} else if (string_eq(key, STR("width"))) {
|
||||
} else if (string_eq(key, LIT("width"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
error = STR("Expected number for \"width\"");
|
||||
error = LIT("Expected number for \"width\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_width = math_round_to_int(child->value.number);
|
||||
found_width = true;
|
||||
} else if (string_eq(key, STR("height"))) {
|
||||
} else if (string_eq(key, LIT("height"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
error = STR("Expected number for \"height\"");
|
||||
error = LIT("Expected number for \"height\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_height = math_round_to_int(child->value.number);
|
||||
@ -130,19 +130,19 @@ struct sys_window_settings *settings_deserialize(struct arena *arena, struct buf
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_maximized) { error = STR("Missing \"maximized\""); goto abort; }
|
||||
if (!found_fullscreen) { error = STR("Missing \"fullscreen\""); goto abort; }
|
||||
if (!found_x) { error = STR("Missing \"x\""); goto abort; }
|
||||
if (!found_y) { error = STR("Missing \"y\""); goto abort; }
|
||||
if (!found_width) { error = STR("Missing \"width\""); goto abort; }
|
||||
if (!found_height) { error = STR("Missing \"height\""); goto abort; }
|
||||
if (!found_maximized) { error = LIT("Missing \"maximized\""); goto abort; }
|
||||
if (!found_fullscreen) { error = LIT("Missing \"fullscreen\""); goto abort; }
|
||||
if (!found_x) { error = LIT("Missing \"x\""); goto abort; }
|
||||
if (!found_y) { error = LIT("Missing \"y\""); goto abort; }
|
||||
if (!found_width) { error = LIT("Missing \"width\""); goto abort; }
|
||||
if (!found_height) { error = LIT("Missing \"height\""); goto abort; }
|
||||
|
||||
abort:
|
||||
|
||||
if (error_out && (error.len > 0 || json_error.msg.len > 0)) {
|
||||
if (json_error.msg.len > 0) {
|
||||
*error_out = string_format(arena,
|
||||
STR("%F\n(%F:%F)"),
|
||||
LIT("%F\n(%F:%F)"),
|
||||
FMT_STR(json_error.msg),
|
||||
FMT_UINT(json_error.start),
|
||||
FMT_UINT(json_error.end));
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
struct sys_window_settings;
|
||||
|
||||
struct buffer settings_serialize(struct arena *arena, const struct sys_window_settings *settings);
|
||||
struct sys_window_settings *settings_deserialize(struct arena *arena, struct buffer src, struct string *error_out);
|
||||
struct string settings_serialize(struct arena *arena, const struct sys_window_settings *settings);
|
||||
struct sys_window_settings *settings_deserialize(struct arena *arena, struct string src, struct string *error_out);
|
||||
|
||||
#endif
|
||||
|
||||
16
src/sound.c
16
src/sound.c
@ -94,9 +94,9 @@ INTERNAL WORK_TASK_FUNC_DEF(sound_load_asset_task, vparams)
|
||||
i64 start_ns = sys_time_ns();
|
||||
|
||||
b32 success = true;
|
||||
struct string error_msg = STR("Unknown error");
|
||||
struct string error_msg = LIT("Unknown error");
|
||||
|
||||
ASSERT(string_ends_with(path, STR(".mp3")));
|
||||
ASSERT(string_ends_with(path, LIT(".mp3")));
|
||||
if (resource_exists(path)) {
|
||||
u64 decode_flags = 0;
|
||||
if (flags & SOUND_FLAG_STEREO) {
|
||||
@ -105,12 +105,12 @@ INTERNAL WORK_TASK_FUNC_DEF(sound_load_asset_task, vparams)
|
||||
|
||||
/* Decode */
|
||||
struct resource sound_rs = resource_open(path);
|
||||
struct mp3_decode_result decoded = mp3_decode(scratch.arena, sound_rs.bytes, decode_flags);
|
||||
struct mp3_decode_result decoded = mp3_decode(scratch.arena, sound_rs.data, decode_flags);
|
||||
resource_close(sound_rs);
|
||||
|
||||
if (!decoded.success) {
|
||||
success = false;
|
||||
error_msg = STR("Failed to decode sound file");
|
||||
error_msg = LIT("Failed to decode sound file");
|
||||
goto abort;
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ INTERNAL WORK_TASK_FUNC_DEF(sound_load_asset_task, vparams)
|
||||
asset_cache_mark_ready(asset, sound);
|
||||
} else {
|
||||
success = false;
|
||||
error_msg = STR("Resource not found");
|
||||
error_msg = LIT("Resource not found");
|
||||
goto abort;
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ struct asset *sound_load_asset(struct string path, u32 flags, b32 help)
|
||||
|
||||
/* Generate and append sound flags to path key */
|
||||
struct string key = string_format(scratch.arena,
|
||||
STR("%F%F_sound"),
|
||||
LIT("%F%F_sound"),
|
||||
FMT_STR(path),
|
||||
FMT_UINT((u64)flags));
|
||||
u64 hash = asset_cache_hash(key);
|
||||
@ -183,10 +183,10 @@ struct asset *sound_load_asset(struct string path, u32 flags, b32 help)
|
||||
struct sound_task_params *params = sound_task_params_alloc();
|
||||
if (path.len > (sizeof(params->path_cstr) - 1)) {
|
||||
sys_panic(string_format(scratch.arena,
|
||||
STR("Sound path \"%F\" too long!"),
|
||||
LIT("Sound path \"%F\" too long!"),
|
||||
FMT_STR(path)));
|
||||
}
|
||||
cstr_buff_from_string(BUFFER_FROM_ARRAY(params->path_cstr), path);
|
||||
cstr_buff_from_string(STRING_FROM_ARRAY(params->path_cstr), path);
|
||||
params->path_len = path.len;
|
||||
params->asset = asset;
|
||||
params->flags = flags;
|
||||
|
||||
20
src/sprite.c
20
src/sprite.c
@ -259,7 +259,7 @@ struct sprite_startup_receipt sprite_startup(struct renderer_startup_receipt *re
|
||||
G.evictor_mutex = sys_mutex_alloc();
|
||||
G.evictor_cv = sys_condition_variable_alloc();
|
||||
|
||||
G.evictor_thread = sys_thread_alloc(sprite_evictor_thread_entry_point, NULL, STR("[P0] Sprite evictor"));
|
||||
G.evictor_thread = sys_thread_alloc(sprite_evictor_thread_entry_point, NULL, LIT("[P0] Sprite evictor"));
|
||||
|
||||
app_register_exit_callback(&sprite_shutdown);
|
||||
|
||||
@ -287,7 +287,7 @@ struct sprite_tag sprite_tag_from_path(struct string path)
|
||||
{
|
||||
struct sprite_tag res = ZI;
|
||||
res.hash = HASH_FNV128_BASIS;
|
||||
res.hash = hash_fnv128(res.hash, BUFFER_FROM_STRING(path));
|
||||
res.hash = hash_fnv128(res.hash, path);
|
||||
res.path = path;
|
||||
return res;
|
||||
}
|
||||
@ -304,7 +304,7 @@ b32 sprite_tag_eq(struct sprite_tag t1, struct sprite_tag t2)
|
||||
|
||||
INTERNAL struct cache_node_hash cache_node_hash_from_tag_hash(u128 tag_hash, enum cache_node_kind kind)
|
||||
{
|
||||
return (struct cache_node_hash) { .v = hash_fnv128(tag_hash, BUFFER(1, (u8 *)&kind)) };
|
||||
return (struct cache_node_hash) { .v = hash_fnv128(tag_hash, STRING(1, (u8 *)&kind)) };
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -344,7 +344,7 @@ INTERNAL void cache_node_load_texture(struct cache_node *n, struct sprite_tag ta
|
||||
logf_info("Loading sprite texture \"%F\"", FMT_STR(path));
|
||||
i64 start_ns = sys_time_ns();
|
||||
|
||||
ASSERT(string_ends_with(path, STR(".ase")));
|
||||
ASSERT(string_ends_with(path, LIT(".ase")));
|
||||
ASSERT(n->kind == CACHE_NODE_KIND_TEXTURE);
|
||||
|
||||
/* TODO: Arena probably overkill. Just using it to store texture struct. */
|
||||
@ -355,7 +355,7 @@ INTERNAL void cache_node_load_texture(struct cache_node *n, struct sprite_tag ta
|
||||
struct ase_decode_image_result decoded = ZI;
|
||||
if (resource_exists(path)) {
|
||||
struct resource texture_rs = resource_open(path);
|
||||
decoded = ase_decode_image(scratch.arena, texture_rs.bytes);
|
||||
decoded = ase_decode_image(scratch.arena, texture_rs.data);
|
||||
#if RESOURCE_RELOADING
|
||||
n->initial_resource_file_modified_time = sys_file_get_time(texture_rs.file).modified;
|
||||
#endif
|
||||
@ -602,7 +602,7 @@ INTERNAL struct sprite_sheet init_sheet_from_ase_result(struct arena *arena, str
|
||||
|
||||
/* Calculate dirs */
|
||||
for (struct temp_slice_group_node *temp_slice_group_node = temp_slice_group_head; temp_slice_group_node; temp_slice_group_node = temp_slice_group_node->next) {
|
||||
struct string ray_suffix = STR(".ray");
|
||||
struct string ray_suffix = LIT(".ray");
|
||||
|
||||
struct sprite_sheet_slice_group *ray_slice_group = temp_slice_group_node->final_slice_group;
|
||||
struct string ray_slice_name = ray_slice_group->name;
|
||||
@ -650,7 +650,7 @@ INTERNAL void cache_node_load_sheet(struct cache_node *n, struct sprite_tag tag)
|
||||
logf_info("Loading sprite sheet \"%F\"", FMT_STR(path));
|
||||
i64 start_ns = sys_time_ns();
|
||||
|
||||
//ASSERT(string_ends_with(path, STR(".ase")));
|
||||
//ASSERT(string_ends_with(path, LIT(".ase")));
|
||||
ASSERT(n->kind == CACHE_NODE_KIND_SHEET);
|
||||
|
||||
n->arena = arena_alloc(SHEET_ARENA_RESERVE);
|
||||
@ -659,7 +659,7 @@ INTERNAL void cache_node_load_sheet(struct cache_node *n, struct sprite_tag tag)
|
||||
struct ase_decode_sheet_result decoded = ZI;
|
||||
if (resource_exists(path)) {
|
||||
struct resource sheet_rs = resource_open(path);
|
||||
decoded = ase_decode_sheet(scratch.arena, sheet_rs.bytes);
|
||||
decoded = ase_decode_sheet(scratch.arena, sheet_rs.data);
|
||||
#if RESOURCE_RELOADING
|
||||
n->initial_resource_file_modified_time = sys_file_get_time(sheet_rs.file).modified;
|
||||
#endif
|
||||
@ -975,14 +975,14 @@ struct sprite_sheet_slice sprite_sheet_get_slice(struct sprite_sheet *sheet, str
|
||||
|
||||
/* Return 'pivot' by default */
|
||||
struct sprite_sheet_slice res = ZI;
|
||||
if (string_eq(name, STR("pivot"))) {
|
||||
if (string_eq(name, LIT("pivot"))) {
|
||||
/* 'pivot' slice does not exist, return center */
|
||||
res.center = V2(0, 0);
|
||||
res.center_px = v2_mul(sheet->frame_size, 0.5f);
|
||||
res.dir_px = V2(res.center_px.x, 0);
|
||||
res.dir = V2(0, -0.5);
|
||||
} else {
|
||||
res = sprite_sheet_get_slice(sheet, STR("pivot"), frame_index);
|
||||
res = sprite_sheet_get_slice(sheet, LIT("pivot"), frame_index);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
46
src/string.c
46
src/string.c
@ -11,7 +11,7 @@
|
||||
* All string functions return a new string as a result. Any strings used as
|
||||
* an argument (IE: in string_cat) will not be modified.
|
||||
*
|
||||
* Use the STR macro to create strings from string literals
|
||||
* Use the LIT macro to create strings from string literals
|
||||
*
|
||||
* NOTE: It is valid for a string to have len 0 but a non-NULL text pointer.
|
||||
* Always check string.len rather than string.text for string presence.
|
||||
@ -86,7 +86,7 @@ struct string string_from_int(struct arena *arena, i64 n, u32 base)
|
||||
|
||||
struct string string_from_ptr(struct arena *arena, void *ptr)
|
||||
{
|
||||
struct string prepend = string_copy(arena, STR("0x"));
|
||||
struct string prepend = string_copy(arena, LIT("0x"));
|
||||
struct string uint_str = string_from_uint(arena, (u64)ptr, 16);
|
||||
return (struct string) {
|
||||
.len = prepend.len + uint_str.len,
|
||||
@ -101,11 +101,11 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision)
|
||||
u64 final_len = 0;
|
||||
|
||||
if (F32_IS_NAN(f)) {
|
||||
final_len += string_copy(arena, STR("NaN")).len;
|
||||
final_len += string_copy(arena, LIT("NaN")).len;
|
||||
} else if (f == F64_INFINITY) {
|
||||
final_len += string_copy(arena, STR("inf")).len;
|
||||
final_len += string_copy(arena, LIT("inf")).len;
|
||||
} else if (f == -F64_INFINITY) {
|
||||
final_len += string_copy(arena, STR("-inf")).len;
|
||||
final_len += string_copy(arena, LIT("-inf")).len;
|
||||
} else {
|
||||
if (f < 0) {
|
||||
string_from_char(arena, '-');
|
||||
@ -173,15 +173,13 @@ struct string string_copy(struct arena *arena, struct string src)
|
||||
return str;
|
||||
}
|
||||
|
||||
struct string string_copy_buff(struct buffer dest_buff, struct string src)
|
||||
struct string string_copy_to_string(struct string dst, struct string src)
|
||||
{
|
||||
u64 len = min_u64(dest_buff.size, src.len);
|
||||
struct string str = {
|
||||
.len = len,
|
||||
.text = dest_buff.data
|
||||
};
|
||||
MEMCPY(str.text, src.text, src.len);
|
||||
return str;
|
||||
struct string res = ZI;
|
||||
res.len = min_u64(dst.len, src.len);
|
||||
res.text = dst.text;
|
||||
MEMCPY(res.text, src.text, res.len);
|
||||
return res;
|
||||
}
|
||||
|
||||
struct string string_repeat(struct arena *arena, struct string src, u64 count)
|
||||
@ -256,7 +254,7 @@ struct string string_indent(struct arena *arena, struct string str, u32 indent)
|
||||
u64 final_len = 0;
|
||||
u8 *final_text = arena_dry_push(arena, u8);
|
||||
|
||||
struct string_array split = string_split(scratch.arena, str, STR("\n"));
|
||||
struct string_array split = string_split(scratch.arena, str, LIT("\n"));
|
||||
for (u64 i = 0; i < split.count; ++i) {
|
||||
struct string piece = split.strings[i];
|
||||
for (u32 j = 0; j < indent; ++j) {
|
||||
@ -390,8 +388,8 @@ b32 string_ends_with(struct string str, struct string substring)
|
||||
*
|
||||
* Example:
|
||||
* string_format(arena,
|
||||
* STR("Hello there %F. You are %F feet %F inches tall!"),
|
||||
* FMT_STR(STR("George")),
|
||||
* LIT("Hello there %F. You are %F feet %F inches tall!"),
|
||||
* FMT_STR(LIT("George")),
|
||||
* FMT_UINT(6),
|
||||
* FMT_FLOAT(5.375));
|
||||
*
|
||||
@ -470,14 +468,14 @@ struct string string_formatv(struct arena *arena, struct string fmt, va_list arg
|
||||
case FMT_TYPE_END: {
|
||||
/* Unexpected end. Not enough FMT args passed to function. */
|
||||
ASSERT(false);
|
||||
parsed_str = string_copy(arena, STR("<?>"));
|
||||
parsed_str = string_copy(arena, LIT("<?>"));
|
||||
no_more_args = true;
|
||||
} break;
|
||||
|
||||
default: {
|
||||
/* Unknown format type */
|
||||
ASSERT(false);
|
||||
parsed_str = string_copy(arena, STR("<?>"));
|
||||
parsed_str = string_copy(arena, LIT("<?>"));
|
||||
no_more_args = true;
|
||||
} break;
|
||||
}
|
||||
@ -668,14 +666,14 @@ char *cstr_from_string(struct arena *arena, struct string src)
|
||||
return (char *)text;
|
||||
}
|
||||
|
||||
char *cstr_buff_from_string(struct buffer dest_buff, struct string src)
|
||||
char *cstr_buff_from_string(struct string dest_buff, struct string src)
|
||||
{
|
||||
if (dest_buff.size > 0) {
|
||||
u64 len = min_u64(src.len, dest_buff.size - 1);
|
||||
MEMCPY(dest_buff.data, src.text, len);
|
||||
dest_buff.data[len] = 0;
|
||||
if (dest_buff.len > 0) {
|
||||
u64 len = min_u64(src.len, dest_buff.len - 1);
|
||||
MEMCPY(dest_buff.text, src.text, len);
|
||||
dest_buff.text[len] = 0;
|
||||
}
|
||||
return (char *)dest_buff.data;
|
||||
return (char *)dest_buff.text;
|
||||
}
|
||||
|
||||
struct string string_from_cstr(char *cstr)
|
||||
|
||||
@ -21,7 +21,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision);
|
||||
* ========================== */
|
||||
|
||||
struct string string_copy(struct arena *arena, struct string src);
|
||||
struct string string_copy_buff(struct buffer dest_buff, struct string src);
|
||||
struct string string_copy_to_string(struct string dst, struct string src);
|
||||
struct string string_repeat(struct arena *arena, struct string src, u64 count);
|
||||
struct string string_cat(struct arena *arena, struct string str1, struct string str2);
|
||||
struct string_array string_split(struct arena *arena, struct string str, struct string delim);
|
||||
@ -112,7 +112,7 @@ struct string32 string32_from_string(struct arena *arena, struct string str8);
|
||||
|
||||
u64 cstr_len(char *cstr);
|
||||
char *cstr_from_string(struct arena *arena, struct string src);
|
||||
char *cstr_buff_from_string(struct buffer dest_buff, struct string src);
|
||||
char *cstr_buff_from_string(struct string dest_buff, struct string src);
|
||||
struct string string_from_cstr(char *cstr);
|
||||
struct string string_from_cstr_len(char *cstr, u64 len);
|
||||
|
||||
|
||||
10
src/sys.h
10
src/sys.h
@ -219,8 +219,8 @@ struct sys_file sys_file_open_write(struct string path);
|
||||
struct sys_file sys_file_open_append(struct string path);
|
||||
void sys_file_close(struct sys_file file);
|
||||
|
||||
struct buffer sys_file_read_all(struct arena *arena, struct sys_file file);
|
||||
void sys_file_write(struct sys_file file, struct buffer data);
|
||||
struct string sys_file_read_all(struct arena *arena, struct sys_file file);
|
||||
void sys_file_write(struct sys_file file, struct string data);
|
||||
u64 sys_file_get_size(struct sys_file file);
|
||||
struct sys_file_time sys_file_get_time(struct sys_file file);
|
||||
|
||||
@ -229,13 +229,13 @@ struct sys_file_time sys_file_get_time(struct sys_file file);
|
||||
* ========================== */
|
||||
|
||||
struct sys_file_map {
|
||||
struct buffer mapped_memory;
|
||||
struct string mapped_memory;
|
||||
u64 handle;
|
||||
};
|
||||
|
||||
struct sys_file_map sys_file_map_open_read(struct sys_file file);
|
||||
void sys_file_map_close(struct sys_file_map map);
|
||||
struct buffer sys_file_map_data(struct sys_file_map map);
|
||||
struct string sys_file_map_data(struct sys_file_map map);
|
||||
|
||||
/* ========================== *
|
||||
* Dir iter
|
||||
@ -442,7 +442,7 @@ struct string sys_get_clipboard_text(struct arena *arena);
|
||||
* Util
|
||||
* ========================== */
|
||||
|
||||
void sys_rand(struct buffer b);
|
||||
void sys_rand(struct string b);
|
||||
u32 sys_num_logical_processors(void);
|
||||
void sys_exit(void);
|
||||
void sys_panic(struct string msg);
|
||||
|
||||
@ -328,26 +328,26 @@ void sys_mkdir(struct string path)
|
||||
struct string err = ZI;
|
||||
switch (err_code) {
|
||||
case ERROR_BAD_PATHNAME: {
|
||||
err = STR("Bad path name");
|
||||
err = LIT("Bad path name");
|
||||
} break;
|
||||
|
||||
case ERROR_FILENAME_EXCED_RANGE: {
|
||||
err = STR("Path name too long");
|
||||
err = LIT("Path name too long");
|
||||
} break;
|
||||
|
||||
case ERROR_FILE_EXISTS: {
|
||||
err = STR("A file already exists at this location");
|
||||
err = LIT("A file already exists at this location");
|
||||
} break;
|
||||
|
||||
case ERROR_CANCELLED: {
|
||||
err = STR("User canceled the operation");
|
||||
err = LIT("User canceled the operation");
|
||||
} break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
if (err.len > 0) {
|
||||
struct string msg = string_format(scratch.arena,
|
||||
STR("Failed to create directory \"%F\": %F"),
|
||||
LIT("Failed to create directory \"%F\": %F"),
|
||||
FMT_STR(path),
|
||||
FMT_STR(err));
|
||||
sys_panic(msg);
|
||||
@ -447,52 +447,52 @@ void sys_file_close(struct sys_file file)
|
||||
CloseHandle((HANDLE)file.handle);
|
||||
}
|
||||
|
||||
struct buffer sys_file_read_all(struct arena *arena, struct sys_file file)
|
||||
struct string sys_file_read_all(struct arena *arena, struct sys_file file)
|
||||
{
|
||||
__prof;
|
||||
i64 size = 0;
|
||||
GetFileSizeEx((HANDLE)file.handle, (PLARGE_INTEGER)&size);
|
||||
|
||||
struct buffer buff = {
|
||||
.size = size,
|
||||
.data = NULL
|
||||
struct string s = {
|
||||
.len = size,
|
||||
.text = NULL
|
||||
};
|
||||
|
||||
if (size > 0) {
|
||||
/* ReadFile returns non-zero on success */
|
||||
/* TODO: error checking */
|
||||
arena_align(arena, 16);
|
||||
buff.data = arena_push_array(arena, u8, size);
|
||||
s.text = arena_push_array(arena, u8, size);
|
||||
(UNUSED)ReadFile(
|
||||
(HANDLE)file.handle,
|
||||
buff.data,
|
||||
(DWORD)buff.size,
|
||||
s.text,
|
||||
(DWORD)s.len,
|
||||
NULL, /* lpNumberOfBytesRead */
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
return buff;
|
||||
return s;
|
||||
}
|
||||
|
||||
void sys_file_write(struct sys_file file, struct buffer data)
|
||||
void sys_file_write(struct sys_file file, struct string data)
|
||||
{
|
||||
__prof;
|
||||
/* TODO: Check what the real data limit is and chunk sequentially based on
|
||||
* that (rather than failing) */
|
||||
if (data.size >= 0x7FFF) {
|
||||
if (data.len >= 0x7FFF) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
sys_panic(string_format(scratch.arena,
|
||||
STR("Tried to write too many bytes to disk (%F)"),
|
||||
FMT_UINT(data.size)));
|
||||
LIT("Tried to write too many bytes to disk (%F)"),
|
||||
FMT_UINT(data.len)));
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
/* WriteFile returns TRUE on success */
|
||||
(UNUSED)WriteFile(
|
||||
(HANDLE)file.handle,
|
||||
data.data,
|
||||
(DWORD)data.size,
|
||||
data.text,
|
||||
(DWORD)data.len,
|
||||
NULL, /* lpNumberOfBytesWritten */
|
||||
NULL
|
||||
);
|
||||
@ -587,21 +587,21 @@ struct sys_file_map sys_file_map_open_read(struct sys_file file)
|
||||
|
||||
return (struct sys_file_map) {
|
||||
.handle = (u64)map_handle,
|
||||
.mapped_memory = BUFFER(size, base_ptr)
|
||||
.mapped_memory = STRING(size, base_ptr)
|
||||
};
|
||||
}
|
||||
|
||||
void sys_file_map_close(struct sys_file_map map)
|
||||
{
|
||||
if (map.mapped_memory.data) {
|
||||
UnmapViewOfFile(map.mapped_memory.data);
|
||||
if (map.mapped_memory.text) {
|
||||
UnmapViewOfFile(map.mapped_memory.text);
|
||||
}
|
||||
if (map.handle) {
|
||||
CloseHandle((HANDLE)map.handle);
|
||||
}
|
||||
}
|
||||
|
||||
struct buffer sys_file_map_data(struct sys_file_map map)
|
||||
struct string sys_file_map_data(struct sys_file_map map)
|
||||
{
|
||||
return map.mapped_memory;
|
||||
}
|
||||
@ -640,7 +640,7 @@ b32 sys_file_filter_next(struct arena *arena, struct sys_file_filter *filter)
|
||||
|
||||
if (found) {
|
||||
struct string file_name = string_from_wstr(arena, find_file_data.cFileName);
|
||||
if (string_eq(file_name, STR(".")) || string_eq(file_name, STR(".."))) {
|
||||
if (string_eq(file_name, LIT(".")) || string_eq(file_name, LIT(".."))) {
|
||||
/* Skip initial '.' and '..' matches */
|
||||
found = sys_file_filter_next(arena, filter);
|
||||
} else {
|
||||
@ -815,7 +815,7 @@ INTERNAL struct win32_window *win32_window_alloc(void)
|
||||
window->event_callbacks_mutex = sys_mutex_alloc();
|
||||
|
||||
/* Start window thread for processing events */
|
||||
window->event_thread = sys_thread_alloc(&window_thread_entry_point, window, STR("[P8] Window thread"));
|
||||
window->event_thread = sys_thread_alloc(&window_thread_entry_point, window, LIT("[P8] Window thread"));
|
||||
|
||||
/* Wait for event thread to create actual window */
|
||||
sync_flag_wait(&window->ready_sf);
|
||||
@ -1215,7 +1215,7 @@ void sys_window_register_event_callback(struct sys_window *sys_window, sys_windo
|
||||
struct sys_lock lock = sys_mutex_lock_e(&window->event_callbacks_mutex);
|
||||
{
|
||||
if (window->event_callbacks_count + 1 > ARRAY_COUNT(window->event_callbacks)) {
|
||||
sys_panic(STR("Too many window event callbacks registered"));
|
||||
sys_panic(LIT("Too many window event callbacks registered"));
|
||||
} else {
|
||||
window->event_callbacks[window->event_callbacks_count++] = func;
|
||||
}
|
||||
@ -1721,7 +1721,7 @@ struct sys_thread sys_thread_alloc(sys_thread_entry_point_func *entry_point, voi
|
||||
t->thread_data = thread_data;
|
||||
|
||||
/* Copy thread name to params */
|
||||
cstr_buff_from_string(BUFFER_FROM_ARRAY(t->thread_name_cstr), thread_name);
|
||||
cstr_buff_from_string(STRING_FROM_ARRAY(t->thread_name_cstr), thread_name);
|
||||
|
||||
t->handle = CreateThread(
|
||||
NULL,
|
||||
@ -1733,7 +1733,7 @@ struct sys_thread sys_thread_alloc(sys_thread_entry_point_func *entry_point, voi
|
||||
);
|
||||
|
||||
if (!t->handle) {
|
||||
sys_panic(STR("Failed to create thread"));
|
||||
sys_panic(LIT("Failed to create thread"));
|
||||
}
|
||||
|
||||
res.handle = (u64)t;
|
||||
@ -1861,9 +1861,9 @@ struct string sys_get_clipboard_text(struct arena *arena)
|
||||
* RNG
|
||||
* ========================== */
|
||||
|
||||
void sys_rand(struct buffer b)
|
||||
void sys_rand(struct string b)
|
||||
{
|
||||
BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, (PUCHAR)b.data, b.size, 0);
|
||||
BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, (PUCHAR)b.text, b.len, 0);
|
||||
}
|
||||
|
||||
u32 sys_num_logical_processors(void)
|
||||
@ -2149,7 +2149,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
||||
/* Call app thread and wait for return */
|
||||
{
|
||||
/* Start app thread */
|
||||
struct sys_thread app_thread = sys_thread_alloc(&app_thread_entry_point, NULL, STR("[P9] App thread"));
|
||||
struct sys_thread app_thread = sys_thread_alloc(&app_thread_entry_point, NULL, LIT("[P9] App thread"));
|
||||
|
||||
/* Get app thread handle */
|
||||
HANDLE app_thread_handle = 0;
|
||||
|
||||
@ -65,7 +65,7 @@ INTERNAL u64 str_oct_to_u64(struct string str)
|
||||
* copying is done. Accessing the archive assumes that the data it's derived
|
||||
* from is valid (AKA open if from a file / memory map).
|
||||
*/
|
||||
struct tar_archive tar_parse(struct arena *arena, struct buffer data, struct string prefix)
|
||||
struct tar_archive tar_parse(struct arena *arena, struct string data, struct string prefix)
|
||||
{
|
||||
__prof;
|
||||
|
||||
@ -78,7 +78,7 @@ struct tar_archive tar_parse(struct arena *arena, struct buffer data, struct str
|
||||
struct tar_header header = ZI;
|
||||
br_read_to_struct(&br, &header);
|
||||
|
||||
if (!string_eq(STRING_FROM_ARRAY(header.ustar_indicator), STR("ustar\0"))) {
|
||||
if (!string_eq(STRING_FROM_ARRAY(header.ustar_indicator), LIT("ustar\0"))) {
|
||||
/* Invalid header */
|
||||
ASSERT(false);
|
||||
continue;
|
||||
@ -97,7 +97,7 @@ struct tar_archive tar_parse(struct arena *arena, struct buffer data, struct str
|
||||
if (!file_data_ptr) {
|
||||
file_size = 0;
|
||||
}
|
||||
struct buffer file_data = BUFFER(file_size, file_data_ptr);
|
||||
struct string file_data = STRING(file_size, file_data_ptr);
|
||||
|
||||
/* Skip sector padding */
|
||||
u64 remaining = (512 - (file_size % 512)) % 512;
|
||||
@ -123,7 +123,7 @@ struct tar_archive tar_parse(struct arena *arena, struct buffer data, struct str
|
||||
*entry = (struct tar_entry) {
|
||||
.is_dir = is_dir,
|
||||
.file_name = file_name,
|
||||
.buff = file_data
|
||||
.data = file_data
|
||||
};
|
||||
|
||||
entry->next = archive.head;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
struct tar_entry {
|
||||
struct string file_name;
|
||||
struct buffer buff;
|
||||
struct string data;
|
||||
|
||||
b32 is_dir;
|
||||
struct tar_entry *next;
|
||||
@ -17,7 +17,7 @@ struct tar_archive {
|
||||
struct tar_entry *head;
|
||||
};
|
||||
|
||||
struct tar_archive tar_parse(struct arena *arena, struct buffer data, struct string prefix);
|
||||
struct tar_archive tar_parse(struct arena *arena, struct string data, struct string prefix);
|
||||
struct tar_entry *tar_get(const struct tar_archive *archive, struct string name);
|
||||
|
||||
#endif
|
||||
|
||||
@ -72,7 +72,7 @@ void *_thread_local_var_eval(struct thread_local_var_meta *meta)
|
||||
if (id_plus_one == 0) {
|
||||
id = G.metas_count++;
|
||||
if (id >= MAX_THREAD_LOCAL_VARS) {
|
||||
sys_panic(STR("Maximum number of thread local variables reached"));
|
||||
sys_panic(LIT("Maximum number of thread local variables reached"));
|
||||
}
|
||||
atomic_u64_eval_exchange(&meta->id_plus_one, id + 1);
|
||||
G.metas[id] = *meta;
|
||||
|
||||
@ -14,6 +14,6 @@ struct ttf_decode_result {
|
||||
|
||||
struct ttf_startup_receipt { i32 _; };
|
||||
struct ttf_startup_receipt ttf_startup(void);
|
||||
struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded, f32 point_size, u32 *cache_codes, u32 cache_codes_count);
|
||||
struct ttf_decode_result ttf_decode(struct arena *arena, struct string encoded, f32 point_size, u32 *cache_codes, u32 cache_codes_count);
|
||||
|
||||
#endif
|
||||
|
||||
@ -68,13 +68,13 @@ struct ttf_startup_receipt ttf_startup(void)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
if (error != S_OK) {
|
||||
sys_panic(STR("Error creating DWrite factory"));
|
||||
sys_panic(LIT("Error creating DWrite factory"));
|
||||
}
|
||||
|
||||
return { 0 };
|
||||
}
|
||||
|
||||
struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded, f32 point_size, u32 *cache_codes, u32 cache_codes_count)
|
||||
struct ttf_decode_result ttf_decode(struct arena *arena, struct string encoded, f32 point_size, u32 *cache_codes, u32 cache_codes_count)
|
||||
{
|
||||
COLORREF bg_color = RGB_32(0,0,0);
|
||||
COLORREF fg_color = RGB_32(255,255,255);
|
||||
@ -95,7 +95,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded,
|
||||
|
||||
IDWriteFontSetBuilder1 *builder = NULL;
|
||||
error = factory->CreateFontSetBuilder(&builder);
|
||||
error = loader->CreateInMemoryFontFileReference(factory, encoded.data, (u32)encoded.size, NULL, &font_file);
|
||||
error = loader->CreateInMemoryFontFileReference(factory, encoded.text, (u32)encoded.len, NULL, &font_file);
|
||||
error = builder->AddFontFile(font_file);
|
||||
}
|
||||
|
||||
|
||||
68
src/user.c
68
src/user.c
@ -163,7 +163,7 @@ struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
|
||||
|
||||
G.debug_draw = true;
|
||||
|
||||
G.user_thread = sys_thread_alloc(&user_thread_entry_point, NULL, STR("[P1] User thread"));
|
||||
G.user_thread = sys_thread_alloc(&user_thread_entry_point, NULL, LIT("[P1] User thread"));
|
||||
app_register_exit_callback(&user_shutdown);
|
||||
|
||||
return (struct user_startup_receipt) { 0 };
|
||||
@ -185,11 +185,11 @@ INTERNAL struct sys_event_array pop_sys_events(struct arena *arena)
|
||||
struct sys_event_array array = ZI;
|
||||
struct sys_lock lock = sys_mutex_lock_e(&G.sys_events_mutex);
|
||||
{
|
||||
struct buffer events_buff = arena_to_buffer(&G.sys_events_arena);
|
||||
struct string events_buff = arena_to_string(&G.sys_events_arena);
|
||||
arena_align(arena, alignof(struct sys_event));
|
||||
array.events = (struct sys_event *)arena_push_array(arena, u8, events_buff.size);
|
||||
array.count = events_buff.size / sizeof(struct sys_event);
|
||||
MEMCPY(array.events, events_buff.data, events_buff.size);
|
||||
array.events = (struct sys_event *)arena_push_array(arena, u8, events_buff.len);
|
||||
array.count = events_buff.len / sizeof(struct sys_event);
|
||||
MEMCPY(array.events, events_buff.text, events_buff.len);
|
||||
arena_reset(&G.sys_events_arena);
|
||||
}
|
||||
sys_mutex_unlock(&lock);
|
||||
@ -375,8 +375,8 @@ INTERNAL void queue_game_cmd(struct arena *arena, struct game_cmd_list *list, st
|
||||
INTERNAL void pubilsh_game_cmds(struct game_cmd_list *list)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct buffer buff = game_string_from_cmds(scratch.arena, list);
|
||||
game_push_cmds_string(buff);
|
||||
struct string s = game_string_from_cmds(scratch.arena, list);
|
||||
game_push_cmds_string(s);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
@ -722,7 +722,7 @@ INTERNAL void user_update(void)
|
||||
i64 frequency_ns = NS_FROM_SECONDS(0.01f);
|
||||
f32 shake = ent->shake;
|
||||
if (shake > 0) {
|
||||
u64 basis = hash_fnv64(HASH_FNV64_BASIS, BUFFER_FROM_STRUCT(&ent->handle));
|
||||
u64 basis = hash_fnv64(HASH_FNV64_BASIS, STRING_FROM_STRUCT(&ent->handle));
|
||||
u64 angle_seed0 = basis + (u64)(G.world.time_ns / frequency_ns);
|
||||
u64 angle_seed1 = angle_seed0 + 1;
|
||||
f32 angle0 = rng_noise_f32(angle_seed0, 0, TAU);
|
||||
@ -1005,7 +1005,7 @@ INTERNAL void user_update(void)
|
||||
/* Draw focus arrow */
|
||||
if (entity_has_prop(ent, ENTITY_PROP_PLAYER_CONTROLLED)) {
|
||||
struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, ent->sprite);
|
||||
struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("attach.wep"), ent->animation_frame);
|
||||
struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, LIT("attach.wep"), ent->animation_frame);
|
||||
struct v2 start = xform_mul_v2(sprite_xform, slice.center);
|
||||
start = xform_mul_v2(G.world_to_ui_xf, start);
|
||||
struct v2 end = v2_add(xf.og, ent->control.focus);
|
||||
@ -1028,7 +1028,7 @@ INTERNAL void user_update(void)
|
||||
|
||||
for (u64 i = 0; i < sheet->slice_groups_count; ++i) {
|
||||
struct sprite_sheet_slice_group *group = &sheet->slice_groups[i];
|
||||
if (string_ends_with(group->name, STR(".ray"))) continue;
|
||||
if (string_ends_with(group->name, LIT(".ray"))) continue;
|
||||
|
||||
for (u32 j = 0; j < group->per_frame_count; ++j) {
|
||||
struct sprite_sheet_slice slice = group->frame_slices[(ent->animation_frame * group->per_frame_count) + j];
|
||||
@ -1135,11 +1135,11 @@ INTERNAL void user_update(void)
|
||||
#if 0
|
||||
/* Draw contact info */
|
||||
{
|
||||
struct font *disp_font = font_load_async(STR("res/fonts/fixedsys.ttf"), 12.0f);
|
||||
struct font *disp_font = font_load_async(LIT("res/fonts/fixedsys.ttf"), 12.0f);
|
||||
if (disp_font) {
|
||||
f32 offset_px = 10;
|
||||
|
||||
struct string fmt = STR(
|
||||
struct string fmt = LIT(
|
||||
"e0 index: %F\n"
|
||||
"e1 index: %F\n"
|
||||
"id: 0x%F\n"
|
||||
@ -1251,10 +1251,10 @@ INTERNAL void user_update(void)
|
||||
#if 0
|
||||
/* Test info */
|
||||
{
|
||||
struct font *disp_font = font_load_async(STR("res/fonts/fixedsys.ttf"), 12.0f);
|
||||
struct font *disp_font = font_load_async(LIT("res/fonts/fixedsys.ttf"), 12.0f);
|
||||
if (disp_font) {
|
||||
f32 offset_px = 10;
|
||||
struct string fmt = STR(
|
||||
struct string fmt = LIT(
|
||||
"e0 pos: (%F, %F)\n"
|
||||
"e0 rot: %F\n"
|
||||
"e1 pos: (%F, %F)\n"
|
||||
@ -1393,7 +1393,7 @@ INTERNAL void user_update(void)
|
||||
struct v2 crosshair_pos = G.ui_cursor;
|
||||
u32 tint = RGBA_32_F(1, 1, 1, 1);
|
||||
|
||||
struct sprite_tag crosshair_tag = sprite_tag_from_path(STR("res/graphics/crosshair.ase"));
|
||||
struct sprite_tag crosshair_tag = sprite_tag_from_path(LIT("res/graphics/crosshair.ase"));
|
||||
struct sprite_texture *t = sprite_texture_from_tag_async(sprite_frame_scope, crosshair_tag);
|
||||
|
||||
struct v2 size = V2(t->width, t->height);
|
||||
@ -1514,66 +1514,66 @@ INTERNAL void user_update(void)
|
||||
|
||||
f32 spacing = 20;
|
||||
struct v2 pos = V2(10, 8);
|
||||
struct font *font = font_load_async(STR("res/fonts/fixedsys.ttf"), 12.0f);
|
||||
struct font *font = font_load_async(LIT("res/fonts/fixedsys.ttf"), 12.0f);
|
||||
if (font) {
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("time: %F"), FMT_FLOAT(SECONDS_FROM_NS(G.time_ns))));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("time: %F"), FMT_FLOAT(SECONDS_FROM_NS(G.time_ns))));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("world time: %F"), FMT_FLOAT(SECONDS_FROM_NS(G.world.time_ns))));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("world time: %F"), FMT_FLOAT(SECONDS_FROM_NS(G.world.time_ns))));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("entities: %F/%F"), FMT_UINT(G.world.entity_store->allocated), FMT_UINT(G.world.entity_store->reserved)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("entities: %F/%F"), FMT_UINT(G.world.entity_store->allocated), FMT_UINT(G.world.entity_store->reserved)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("screen_size: (%F, %F)"), FMT_FLOAT((f64)G.screen_size.x), FMT_FLOAT((f64)G.screen_size.y)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("screen_size: (%F, %F)"), FMT_FLOAT((f64)G.screen_size.x), FMT_FLOAT((f64)G.screen_size.y)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("screen_cursor: (%F, %F)"), FMT_FLOAT((f64)G.screen_cursor.x), FMT_FLOAT((f64)G.screen_cursor.y)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("screen_cursor: (%F, %F)"), FMT_FLOAT((f64)G.screen_cursor.x), FMT_FLOAT((f64)G.screen_cursor.y)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("ui_screen_offset: (%F, %F)"), FMT_FLOAT((f64)G.ui_screen_offset.x), FMT_FLOAT((f64)G.ui_screen_offset.y)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("ui_screen_offset: (%F, %F)"), FMT_FLOAT((f64)G.ui_screen_offset.x), FMT_FLOAT((f64)G.ui_screen_offset.y)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("ui_size: (%F, %F)"), FMT_FLOAT((f64)G.ui_size.x), FMT_FLOAT((f64)G.ui_size.y)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("ui_size: (%F, %F)"), FMT_FLOAT((f64)G.ui_size.x), FMT_FLOAT((f64)G.ui_size.y)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("ui_center: (%F, %F)"), FMT_FLOAT((f64)G.ui_center.x), FMT_FLOAT((f64)G.ui_center.y)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("ui_center: (%F, %F)"), FMT_FLOAT((f64)G.ui_center.x), FMT_FLOAT((f64)G.ui_center.y)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("ui_cursor: (%F, %F)"), FMT_FLOAT((f64)G.ui_cursor.x), FMT_FLOAT((f64)G.ui_cursor.y)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("ui_cursor: (%F, %F)"), FMT_FLOAT((f64)G.ui_cursor.x), FMT_FLOAT((f64)G.ui_cursor.y)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("world_to_ui_xf.og: (%F, %F)"), FMT_FLOAT((f64)G.world_to_ui_xf.og.x), FMT_FLOAT((f64)G.world_to_ui_xf.og.y)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("world_to_ui_xf.og: (%F, %F)"), FMT_FLOAT((f64)G.world_to_ui_xf.og.x), FMT_FLOAT((f64)G.world_to_ui_xf.og.y)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("world_to_ui_xf rotation: %F"), FMT_FLOAT((f64)xform_get_rotation(G.world_to_ui_xf))));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("world_to_ui_xf rotation: %F"), FMT_FLOAT((f64)xform_get_rotation(G.world_to_ui_xf))));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("world_to_ui_xf scale: (%F, %F)"), FMT_FLOAT((f64)xform_get_scale(G.world_to_ui_xf).x), FMT_FLOAT((f64)xform_get_scale(G.world_to_ui_xf).x)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("world_to_ui_xf scale: (%F, %F)"), FMT_FLOAT((f64)xform_get_scale(G.world_to_ui_xf).x), FMT_FLOAT((f64)xform_get_scale(G.world_to_ui_xf).x)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("world_cursor: (%F, %F)"), FMT_FLOAT((f64)G.world_cursor.x), FMT_FLOAT((f64)G.world_cursor.y)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("world_cursor: (%F, %F)"), FMT_FLOAT((f64)G.world_cursor.x), FMT_FLOAT((f64)G.world_cursor.y)));
|
||||
pos.y += spacing;
|
||||
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("debug_camera: %F"), FMT_STR(G.debug_camera ? STR("true") : STR("false"))));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("debug_camera: %F"), FMT_STR(G.debug_camera ? LIT("true") : LIT("false"))));
|
||||
pos.y += spacing;
|
||||
|
||||
struct v2 player_linear_vel = entity_find_first_match_one(store, ENTITY_PROP_PLAYER_CONTROLLED)->linear_velocity;
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("player linear velocity: (%F, %F)"), FMT_FLOAT_P((f64)player_linear_vel.x, 12), FMT_FLOAT_P((f64)player_linear_vel.y, 12)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("player linear velocity: (%F, %F)"), FMT_FLOAT_P((f64)player_linear_vel.x, 12), FMT_FLOAT_P((f64)player_linear_vel.y, 12)));
|
||||
pos.y += spacing;
|
||||
|
||||
f32 player_angular_vel = entity_find_first_match_one(store, ENTITY_PROP_PLAYER_CONTROLLED)->angular_velocity;
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("player angular velocity: %F"), FMT_FLOAT_P((f64)player_angular_vel, 12)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("player angular velocity: %F"), FMT_FLOAT_P((f64)player_angular_vel, 12)));
|
||||
pos.y += spacing;
|
||||
|
||||
struct v2 player_pos = entity_get_xform(entity_find_first_match_one(store, ENTITY_PROP_PLAYER_CONTROLLED)).og;
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("player pos: (%F, %F)"), FMT_FLOAT_P((f64)player_pos.x, 12), FMT_FLOAT_P((f64)player_pos.y, 12)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("player pos: (%F, %F)"), FMT_FLOAT_P((f64)player_pos.x, 12), FMT_FLOAT_P((f64)player_pos.y, 12)));
|
||||
pos.y += spacing;
|
||||
|
||||
#if COLLIDER_DEBUG
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, STR("collider gjk steps: %F"), FMT_UINT(collider_debug_steps)));
|
||||
draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("collider gjk steps: %F"), FMT_UINT(collider_debug_steps)));
|
||||
pos.y += spacing;
|
||||
#endif
|
||||
|
||||
|
||||
16
src/util.h
16
src/util.h
@ -20,23 +20,23 @@
|
||||
*/
|
||||
|
||||
#define HASH_FNV64_BASIS 0xCBF29CE484222325
|
||||
INLINE u64 hash_fnv64(u64 seed, struct buffer buff)
|
||||
INLINE u64 hash_fnv64(u64 seed, struct string s)
|
||||
{
|
||||
u64 hash = seed;
|
||||
for (u64 i = 0; i < buff.size; ++i) {
|
||||
hash ^= (u8)buff.data[i];
|
||||
for (u64 i = 0; i < s.len; ++i) {
|
||||
hash ^= (u8)s.text[i];
|
||||
hash *= 0x100000001B3;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
#define HASH_FNV128_BASIS U128(0x6C62272E07BB0142, 0x62B821756295C58D)
|
||||
INLINE u128 hash_fnv128(u128 seed, struct buffer buff)
|
||||
INLINE u128 hash_fnv128(u128 seed, struct string s)
|
||||
{
|
||||
/* FIXME: Verify MSVC version of 128 is same */
|
||||
u128 hash = seed;
|
||||
for (u64 i = 0; i < buff.size; ++i) {
|
||||
u8 c = (u8)buff.data[i];
|
||||
for (u64 i = 0; i < s.len; ++i) {
|
||||
u8 c = (u8)s.text[i];
|
||||
hash = u128_xor_u8(hash, c);
|
||||
hash = u128_mul(hash, U128(0x1000000, 0x000000000000013B));
|
||||
}
|
||||
@ -149,7 +149,7 @@ INLINE void fixed_dict_set(struct arena *arena, struct fixed_dict *dict, struct
|
||||
{
|
||||
__prof;
|
||||
|
||||
u64 hash = hash_fnv64(HASH_FNV64_BASIS, BUFFER_FROM_STRING(key));
|
||||
u64 hash = hash_fnv64(HASH_FNV64_BASIS, key);
|
||||
u64 index = hash % dict->buckets_count;
|
||||
struct fixed_dict_bucket *bucket = &dict->buckets[index];
|
||||
|
||||
@ -178,7 +178,7 @@ INLINE void *fixed_dict_get(const struct fixed_dict *dict, struct string key)
|
||||
{
|
||||
__prof;
|
||||
|
||||
u64 hash = hash_fnv64(HASH_FNV64_BASIS, BUFFER_FROM_STRING(key));
|
||||
u64 hash = hash_fnv64(HASH_FNV64_BASIS, key);
|
||||
u64 index = hash % dict->buckets_count;
|
||||
struct fixed_dict_bucket *bucket = &dict->buckets[index];
|
||||
|
||||
|
||||
@ -106,7 +106,7 @@ struct work_startup_receipt work_startup(u32 num_worker_threads)
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
|
||||
if (num_worker_threads <= 0) {
|
||||
sys_panic(STR("Tried to start up worker pool with 0 threads"));
|
||||
sys_panic(LIT("Tried to start up worker pool with 0 threads"));
|
||||
}
|
||||
|
||||
G.arena = arena_alloc(GIGABYTE(64));
|
||||
@ -122,7 +122,7 @@ struct work_startup_receipt work_startup(u32 num_worker_threads)
|
||||
struct worker *prev = NULL;
|
||||
for (u32 i = 0; i < num_worker_threads; ++i) {
|
||||
struct string thread_name = string_format(scratch.arena,
|
||||
STR("[P0] Worker %F"),
|
||||
LIT("[P0] Worker %F"),
|
||||
FMT_UINT(i));
|
||||
|
||||
struct worker *worker = arena_push_zero(&G.arena, struct worker);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user