Lumenarium/src_v2/lumenarium_first.cpp

109 lines
2.3 KiB
C++
Raw Normal View History

2022-03-22 18:13:06 +00:00
#include "lumenarium_first.h"
#include "user_space/user_space_incenter.cpp"
2022-03-22 18:13:06 +00:00
internal App_State*
lumenarium_init()
{
App_State* state = 0;
permanent = bump_allocator_create_reserve(GB(1));
scratch = bump_allocator_create_reserve(KB(64));
platform_file_jobs_init();
2022-03-22 18:13:06 +00:00
run_tests();
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-03-22 18:13:06 +00:00
state->input_state = input_state_create(permanent);
2022-03-22 18:13:06 +00:00
en_init(state, desc);
2022-03-29 16:09:50 +00:00
if (has_flag(state->flags, AppState_RunEditor))
2022-03-22 18:13:06 +00:00
{
ed_init(state);
}
incenter_init(state);
2022-03-22 18:13:06 +00:00
return state;
}
internal void
lumenarium_frame_prepare(App_State* state)
{
allocator_clear(scratch);
input_state_swap_frames(state->input_state);
2022-03-22 18:13:06 +00:00
en_frame_prepare(state);
2022-03-29 16:09:50 +00:00
if (has_flag(state->flags, AppState_RunEditor))
2022-03-22 18:13:06 +00:00
{
ed_frame_prepare(state);
}
incenter_frame_prepare(state);
2022-04-07 12:02:12 +00:00
platform_file_async_jobs_do_work(4, (u8*)state);
2022-03-22 18:13:06 +00:00
}
internal void
lumenarium_frame(App_State* state)
{
//en_frame(state);
2022-03-29 16:09:50 +00:00
if (has_flag(state->flags, AppState_RunEditor))
2022-03-22 18:13:06 +00:00
{
2022-03-29 16:09:50 +00:00
ed_frame(state);
2022-03-22 18:13:06 +00:00
}
incenter_frame(state);
2022-03-22 18:13:06 +00:00
}
internal void
lumenarium_event(Platform_Window_Event evt, App_State* state)
{
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;
case WindowEvent_MouseMoved:
{
v2 mouse_pos_old = frame->mouse_pos;
frame->mouse_pos = v2{ (r32)evt.mouse_x, (r32)evt.mouse_y };
state->input_state->mouse_pos_delta = frame->mouse_pos - mouse_pos_old;
} break;
2022-03-22 18:13:06 +00:00
case WindowEvent_ButtonDown:
case WindowEvent_ButtonUp:
{
frame->key_flags[evt.key_code] = evt.key_flags;
} 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)
{
incenter_cleanup(state);
2022-03-22 18:13:06 +00:00
en_cleanup(state);
2022-03-29 16:09:50 +00:00
if (has_flag(state->flags, AppState_RunEditor))
2022-03-22 18:13:06 +00:00
{
ed_cleanup(state);
}
}