reformatting

This commit is contained in:
silverweed 2024-07-10 21:47:37 +02:00
parent 790c7b9214
commit d673229cf4
5 changed files with 34 additions and 9 deletions

View file

@ -13,4 +13,4 @@ d:
$(MOLD) $(CXX) -DDEBUG -g -O0 $(CFLAGS) -fsanitize=undefined $(INC) $(shell root-config --cflags) -o rntviewer src/rntviewer.cpp build/imgui.o -lasan $(shell root-config --libs) $(LIBS) $(MOLD) $(CXX) -DDEBUG -g -O0 $(CFLAGS) -fsanitize=undefined $(INC) $(shell root-config --cflags) -o rntviewer src/rntviewer.cpp build/imgui.o -lasan $(shell root-config --libs) $(LIBS)
r: r:
$(MOLD) $(CXX) -O2 $(CFLAGS) $(INC) -o rntviewer src/rntviewer.cpp $(shell root-config --cflags --libs) $(LIBS) $(MOLD) $(CXX) -O2 $(CFLAGS) $(INC) -o rntviewer src/rntviewer.cpp build/imgui.o $(shell root-config --cflags --libs) $(LIBS)

View file

@ -1,4 +1,5 @@
internal inline void monitor_key(GLFWwindow *window, u16 *key_state, i32 glfw_key, Input_Key haru_key) { internal
void monitor_key(GLFWwindow *window, u16 *key_state, i32 glfw_key, Input_Key haru_key) {
u16& state = key_state[haru_key]; u16& state = key_state[haru_key];
if (glfwGetKey(window, glfw_key) == GLFW_PRESS) { if (glfwGetKey(window, glfw_key) == GLFW_PRESS) {
if (!(state & KEY_STATE_IS_DOWN)) state |= KEY_STATE_JUST_PRESSED; if (!(state & KEY_STATE_IS_DOWN)) state |= KEY_STATE_JUST_PRESSED;
@ -9,7 +10,8 @@ internal inline void monitor_key(GLFWwindow *window, u16 *key_state, i32 glfw_ke
} }
} }
internal inline void monitor_mouse_btn(GLFWwindow *window, u16 *mouse_btn_state, i32 glfw_btn, Mouse_Button haru_btn) { internal
void monitor_mouse_btn(GLFWwindow *window, u16 *mouse_btn_state, i32 glfw_btn, Mouse_Button haru_btn) {
u16& state = mouse_btn_state[haru_btn]; u16& state = mouse_btn_state[haru_btn];
if (glfwGetMouseButton(window, glfw_btn) == GLFW_PRESS) { if (glfwGetMouseButton(window, glfw_btn) == GLFW_PRESS) {
if (!(state & MOUSE_BTN_STATE_IS_DOWN)) state |= MOUSE_BTN_STATE_JUST_PRESSED; if (!(state & MOUSE_BTN_STATE_IS_DOWN)) state |= MOUSE_BTN_STATE_JUST_PRESSED;
@ -20,7 +22,8 @@ internal inline void monitor_mouse_btn(GLFWwindow *window, u16 *mouse_btn_state,
} }
} }
internal void run_main_loop(GLFWwindow *window, Arena *arena, App_State &app) internal
void run_main_loop(GLFWwindow *window, Arena *arena, App_State &app)
{ {
f32 delta_time; f32 delta_time;
chr::time_point last_saved_time = chr::high_resolution_clock::now(); chr::time_point last_saved_time = chr::high_resolution_clock::now();

View file

@ -12,16 +12,19 @@
#define asan_unpoison_memory_region(mem, cmt) #define asan_unpoison_memory_region(mem, cmt)
#endif #endif
internal
void *os_reserve(u64 size) void *os_reserve(u64 size)
{ {
return mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); return mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
} }
internal
void os_release(void *mem, u64 size) void os_release(void *mem, u64 size)
{ {
munmap(mem, size); munmap(mem, size);
} }
internal
b32x os_commit(void *addr, u64 size) b32x os_commit(void *addr, u64 size)
{ {
return mprotect(addr, size, PROT_READ|PROT_WRITE) == 0; return mprotect(addr, size, PROT_READ|PROT_WRITE) == 0;
@ -29,6 +32,7 @@ b32x os_commit(void *addr, u64 size)
// init_res: initial reserved size // init_res: initial reserved size
// init_cmt: initial committed size // init_cmt: initial committed size
internal
Arena *arena_alloc_sized(u64 init_res, u64 init_cmt) Arena *arena_alloc_sized(u64 init_res, u64 init_cmt)
{ {
assert(ARENA_HEADER_SIZE < init_cmt && init_cmt <= init_res); assert(ARENA_HEADER_SIZE < init_cmt && init_cmt <= init_res);
@ -59,11 +63,13 @@ Arena *arena_alloc_sized(u64 init_res, u64 init_cmt)
return arena; return arena;
} }
internal
Arena *arena_alloc() Arena *arena_alloc()
{ {
return arena_alloc_sized(ARENA_RESERVE_SIZE, ARENA_COMMIT_SIZE); return arena_alloc_sized(ARENA_RESERVE_SIZE, ARENA_COMMIT_SIZE);
} }
internal
void arena_release(Arena *arena) void arena_release(Arena *arena)
{ {
for (Arena *node = arena->cur, *prev = 0; node; node = prev) { for (Arena *node = arena->cur, *prev = 0; node; node = prev) {
@ -72,6 +78,7 @@ void arena_release(Arena *arena)
} }
} }
internal
u64 arena_huge_push_threshold() u64 arena_huge_push_threshold()
{ {
u64 res = ARENA_RESERVE_SIZE; u64 res = ARENA_RESERVE_SIZE;
@ -79,6 +86,7 @@ u64 arena_huge_push_threshold()
return threshold; return threshold;
} }
internal
void *arena_push_impl(Arena *arena, u64 size) void *arena_push_impl(Arena *arena, u64 size)
{ {
Arena *cur = arena->cur; Arena *cur = arena->cur;
@ -125,6 +133,7 @@ void *arena_push_impl(Arena *arena, u64 size)
} }
template <typename T> template <typename T>
internal
T *arena_push(Arena *arena) T *arena_push(Arena *arena)
{ {
void *mem = arena_push_impl(arena, sizeof(T)); void *mem = arena_push_impl(arena, sizeof(T));
@ -132,6 +141,7 @@ T *arena_push(Arena *arena)
} }
template <typename T> template <typename T>
internal
T *arena_push_array_no_zero(Arena *arena, u64 count) T *arena_push_array_no_zero(Arena *arena, u64 count)
{ {
void *mem = arena_push_impl(arena, sizeof(T) * count); void *mem = arena_push_impl(arena, sizeof(T) * count);
@ -139,6 +149,7 @@ T *arena_push_array_no_zero(Arena *arena, u64 count)
} }
template <typename T> template <typename T>
internal
T *arena_push_array(Arena *arena, u64 count) T *arena_push_array(Arena *arena, u64 count)
{ {
T *ary = arena_push_array_no_zero<T>(arena, count); T *ary = arena_push_array_no_zero<T>(arena, count);
@ -146,6 +157,7 @@ T *arena_push_array(Arena *arena, u64 count)
return ary; return ary;
} }
internal
u8 *arena_push_contiguous(Arena *arena, u64 size) u8 *arena_push_contiguous(Arena *arena, u64 size)
{ {
b32 restore = arena->grow; b32 restore = arena->grow;
@ -155,6 +167,7 @@ u8 *arena_push_contiguous(Arena *arena, u64 size)
return (u8 *)mem; return (u8 *)mem;
} }
internal
u64 arena_pos(Arena *arena) u64 arena_pos(Arena *arena)
{ {
Arena *cur = arena->cur; Arena *cur = arena->cur;
@ -162,6 +175,7 @@ u64 arena_pos(Arena *arena)
return pos; return pos;
} }
internal
void arena_pop_to(Arena *arena, u64 big_pos_unclamped) void arena_pop_to(Arena *arena, u64 big_pos_unclamped)
{ {
u64 big_pos = min(ARENA_HEADER_SIZE, big_pos_unclamped); u64 big_pos = min(ARENA_HEADER_SIZE, big_pos_unclamped);
@ -186,6 +200,7 @@ void arena_pop_to(Arena *arena, u64 big_pos_unclamped)
current->pos = new_pos; current->pos = new_pos;
} }
internal
Temp temp_begin(Arena *arena) Temp temp_begin(Arena *arena)
{ {
u64 pos = arena_pos(arena); u64 pos = arena_pos(arena);
@ -193,6 +208,7 @@ Temp temp_begin(Arena *arena)
return temp; return temp;
} }
internal
void temp_end(Temp temp) void temp_end(Temp temp)
{ {
arena_pop_to(temp.arena, temp.pos); arena_pop_to(temp.arena, temp.pos);

View file

@ -1,3 +1,4 @@
internal
MemoryEditor make_memory_editor() MemoryEditor make_memory_editor()
{ {
MemoryEditor mem_edit; MemoryEditor mem_edit;
@ -6,7 +7,8 @@ MemoryEditor make_memory_editor()
return mem_edit; return mem_edit;
} }
internal void update_and_render(Arena *arena, App_State &app, f32 delta_time) internal
void update_and_render(Arena *arena, App_State &app, f32 delta_time)
{ {
ImGui::SetNextWindowPos({ 0, 0 }); ImGui::SetNextWindowPos({ 0, 0 });
ImGui::SetNextWindowSize({ (f32)app.win_data.width, (f32)app.win_data.height }); ImGui::SetNextWindowSize({ (f32)app.win_data.width, (f32)app.win_data.height });

View file

@ -34,7 +34,8 @@ namespace chr = std::chrono;
using namespace ROOT::Experimental; using namespace ROOT::Experimental;
internal size_t file_size(FILE *f) internal
size_t file_size(FILE *f)
{ {
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
size_t res = ftell(f); size_t res = ftell(f);
@ -42,7 +43,8 @@ internal size_t file_size(FILE *f)
return res; return res;
} }
internal b8 init_imgui(GLFWwindow* window) { internal
b8 init_imgui(GLFWwindow* window) {
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void) io; ImGuiIO& io = ImGui::GetIO(); (void) io;
@ -56,11 +58,13 @@ internal b8 init_imgui(GLFWwindow* window) {
return true; return true;
} }
internal void glfw_error_callback(i32 error, const char *description) { internal
void glfw_error_callback(i32 error, const char *description) {
fprintf(stderr, "GLFW error %d: %s\n", error, description); fprintf(stderr, "GLFW error %d: %s\n", error, description);
} }
internal GLFWwindow* init_glfw(i32 desired_win_width, i32 desired_win_height) internal
GLFWwindow* init_glfw(i32 desired_win_width, i32 desired_win_height)
{ {
glfwSetErrorCallback(glfw_error_callback); glfwSetErrorCallback(glfw_error_callback);
glfwInit(); glfwInit();