2022-03-22 18:13:06 +00:00
|
|
|
#include "lumenarium_first.h"
|
2022-03-27 10:47:18 +00:00
|
|
|
#include "user_space/user_space_incenter.cpp"
|
|
|
|
|
2022-03-22 18:13:06 +00:00
|
|
|
internal App_State*
|
2022-04-17 14:24:22 +00:00
|
|
|
lumenarium_init(Editor_Desc* ed_desc)
|
2022-03-22 18:13:06 +00:00
|
|
|
{
|
2022-03-27 10:47:18 +00:00
|
|
|
App_State* state = 0;
|
|
|
|
|
2022-04-12 05:53:32 +00:00
|
|
|
permanent = bump_allocator_create_reserve(GB(2));
|
2022-04-16 11:00:32 +00:00
|
|
|
global_scratch_ = bump_allocator_create_reserve(GB(4));
|
2022-03-27 10:47:18 +00:00
|
|
|
|
2022-04-16 12:14:55 +00:00
|
|
|
//run_tests();
|
2022-04-12 05:53:32 +00:00
|
|
|
scratch_get(scratch);
|
2022-03-27 10:47:18 +00:00
|
|
|
App_Init_Desc desc = incenter_get_init_desc();
|
|
|
|
// TODO(PS): make sure the values make sense in desc
|
|
|
|
|
|
|
|
state = allocator_alloc_struct(permanent, App_State);
|
2022-03-22 18:13:06 +00:00
|
|
|
add_flag(state->flags, AppState_IsRunning);
|
2022-03-29 16:09:50 +00:00
|
|
|
add_flag(state->flags, AppState_RunEditor);
|
2022-04-16 11:00:32 +00:00
|
|
|
add_flag(state->flags, AppState_RunUserSpace);
|
2022-03-22 18:13:06 +00:00
|
|
|
|
2022-04-16 11:00:32 +00:00
|
|
|
state->file_async_job_system = os_file_jobs_init();
|
2022-04-06 18:29:32 +00:00
|
|
|
state->input_state = input_state_create(permanent);
|
2022-03-22 18:13:06 +00:00
|
|
|
|
2022-04-16 11:00:32 +00:00
|
|
|
String exe_file_path = os_get_exe_path(scratch.a);
|
2022-04-12 05:53:32 +00:00
|
|
|
u64 run_tree_start = string_find_substring(exe_file_path, lit_str("run_tree"), 0, StringMatch_FindLast);
|
2022-04-16 12:14:55 +00:00
|
|
|
if (run_tree_start >= exe_file_path.cap)
|
|
|
|
{
|
|
|
|
u64 exe_path_start = string_find_substring(exe_file_path, lit_str("lumenarium"), 0, StringMatch_FindLast);
|
|
|
|
if (exe_path_start < exe_file_path.cap)
|
|
|
|
{
|
|
|
|
String run_tree_path = string_get_prefix(exe_file_path, exe_path_start);
|
|
|
|
String run_tree_path_nullterm = string_copy(run_tree_path, scratch.a);
|
|
|
|
os_pwd_set(run_tree_path_nullterm);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Unable to set working directory\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u64 run_tree_end = run_tree_start + lit_str("run_tree").len;
|
|
|
|
String run_tree_path = string_get_prefix(exe_file_path, run_tree_end);
|
|
|
|
String run_tree_path_nullterm = string_copy(run_tree_path, scratch.a);
|
|
|
|
os_pwd_set(run_tree_path_nullterm);
|
|
|
|
}
|
|
|
|
|
2022-04-16 11:00:32 +00:00
|
|
|
|
2022-03-27 10:47:18 +00:00
|
|
|
en_init(state, desc);
|
2022-04-17 14:24:22 +00:00
|
|
|
if (has_flag(state->flags, AppState_RunEditor)) ed_init(state, ed_desc);
|
2022-04-16 11:00:32 +00:00
|
|
|
if (has_flag(state->flags, AppState_RunUserSpace)) incenter_init(state);
|
|
|
|
scratch_release(scratch);
|
2022-03-22 18:13:06 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
lumenarium_frame_prepare(App_State* state)
|
|
|
|
{
|
2022-04-12 06:01:17 +00:00
|
|
|
allocator_clear(global_scratch_);
|
2022-03-27 10:47:18 +00:00
|
|
|
|
2022-04-06 18:29:32 +00:00
|
|
|
input_state_swap_frames(state->input_state);
|
2022-04-16 11:00:32 +00:00
|
|
|
|
2022-03-22 18:13:06 +00:00
|
|
|
en_frame_prepare(state);
|
2022-04-16 11:00:32 +00:00
|
|
|
if (has_flag(state->flags, AppState_RunEditor)) ed_frame_prepare(state);
|
|
|
|
if (has_flag(state->flags, AppState_RunUserSpace)) incenter_frame_prepare(state);
|
2022-04-06 18:29:32 +00:00
|
|
|
|
2022-04-16 11:00:32 +00:00
|
|
|
file_async_jobs_do_work(&state->file_async_job_system, 4, (u8*)state);
|
2022-03-22 18:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
lumenarium_frame(App_State* state)
|
|
|
|
{
|
2022-04-12 05:53:32 +00:00
|
|
|
en_frame(state);
|
2022-04-16 11:00:32 +00:00
|
|
|
if (has_flag(state->flags, AppState_RunEditor)) ed_frame(state);
|
|
|
|
if (has_flag(state->flags, AppState_RunUserSpace)) incenter_frame(state);
|
2022-03-22 18:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2022-04-16 11:00:32 +00:00
|
|
|
lumenarium_event(Window_Event evt, App_State* state)
|
2022-03-22 18:13:06 +00:00
|
|
|
{
|
2022-04-06 18:29:32 +00:00
|
|
|
Input_Frame* frame = state->input_state->frame_hot;
|
2022-03-22 18:13:06 +00:00
|
|
|
switch (evt.kind)
|
|
|
|
{
|
|
|
|
case WindowEvent_MouseScroll:
|
|
|
|
{
|
|
|
|
frame->mouse_scroll = evt.scroll_amt;
|
|
|
|
} break;
|
|
|
|
|
2022-04-06 18:29:32 +00:00
|
|
|
case WindowEvent_MouseMoved:
|
|
|
|
{
|
|
|
|
v2 mouse_pos_old = frame->mouse_pos;
|
2022-04-16 11:00:32 +00:00
|
|
|
frame->mouse_pos = (v2){ (r32)evt.mouse_x, (r32)evt.mouse_y };
|
|
|
|
state->input_state->mouse_pos_delta = HMM_SubtractVec2(frame->mouse_pos, mouse_pos_old);
|
2022-04-06 18:29:32 +00:00
|
|
|
} break;
|
|
|
|
|
2022-03-22 18:13:06 +00:00
|
|
|
case WindowEvent_ButtonDown:
|
|
|
|
case WindowEvent_ButtonUp:
|
|
|
|
{
|
|
|
|
frame->key_flags[evt.key_code] = evt.key_flags;
|
2022-04-07 17:51:15 +00:00
|
|
|
if (evt.key_code == KeyCode_MouseLeftButton)
|
|
|
|
{
|
2022-04-16 11:00:32 +00:00
|
|
|
state->input_state->mouse_pos_down = (v2){
|
2022-04-07 17:51:15 +00:00
|
|
|
(r32)evt.mouse_x, (r32)evt.mouse_y
|
|
|
|
};
|
|
|
|
}
|
2022-03-22 18:13:06 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WindowEvent_Char:
|
|
|
|
{
|
|
|
|
frame->string_input[frame->string_input_len++] = evt.char_value;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WindowEvent_WindowClosed:
|
|
|
|
{
|
|
|
|
rem_flag(state->flags, AppState_IsRunning);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
invalid_default_case;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
lumenarium_cleanup(App_State* state)
|
|
|
|
{
|
2022-04-16 11:00:32 +00:00
|
|
|
if (has_flag(state->flags, AppState_RunUserSpace)) incenter_cleanup(state);
|
2022-03-22 18:13:06 +00:00
|
|
|
en_cleanup(state);
|
2022-04-16 11:00:32 +00:00
|
|
|
if (has_flag(state->flags, AppState_RunEditor)) ed_cleanup(state);
|
2022-03-22 18:13:06 +00:00
|
|
|
}
|