Lumenarium/src_v2/user_space/incenter_user_space.c

231 lines
6.5 KiB
C
Raw Normal View History

2022-08-08 09:39:42 +00:00
#include "../user_space/incenter_patterns.c"
#include "../user_space/incenter_secondary_patterns.c"
#include "incenter_scenes.h"
2022-08-21 23:34:15 +00:00
#include "incenter_live_answers.c"
2022-08-08 09:39:42 +00:00
////////////////////////////////////////////////
// INCENTER SCENES
internal void
incenter_scenes_init(Incenter_State* ins, u32 cap, Allocator* a)
{
incenter_scene_descs_init();
ins->scenes = incenter_scene_descs;
ins->scenes_cap = Incenter_Scene_Count;
2022-08-21 23:34:15 +00:00
ins->scene_at = Incenter_Scene_Question_LostAccessToResources;
2022-08-08 09:39:42 +00:00
}
internal void
incenter_scene_go_to(Incenter_State* ins, u32 index)
{
ins->transition_time = 0;
ins->scene_next = index % ins->scenes_cap;
ins->scene_mode = Incenter_SceneMode_TransitioningOut;
2022-08-21 23:34:15 +00:00
printf("Switching To: %d:%s\n", ins->scene_next, ins->scenes[ins->scene_next].name);
2022-08-08 09:39:42 +00:00
}
internal void
incenter_scene_go_to_next(Incenter_State* ins)
{
incenter_scene_go_to(ins, ins->scene_at + 1);
}
internal void
incenter_scene_go_to_prev(Incenter_State* ins)
{
incenter_scene_go_to(ins, ins->scene_at - 1);
}
internal void
incenter_scene_set_mode(Incenter_State* ins, Incenter_Scene_Mode mode)
{
ins->scene_mode = mode;
}
internal void
incenter_scene_render(App_State* state, Incenter_State* ins)
{
assert(ins->scene_mode != Incenter_SceneMode_Count);
Incenter_Pattern* pattern = 0;
if (ins->scene_mode > Incenter_SceneMode_Count)
{
// Update the transition if necessary
if (ins->transition_time >= INCENTER_TRANSITION_DURATION) {
if (ins->scene_mode == Incenter_SceneMode_TransitioningOut) {
ins->transition_time = 0;
ins->scene_mode = Incenter_SceneMode_TransitioningIn;
ins->scene_at = ins->scene_next;
ins->scene_time = 0;
2022-08-21 23:34:15 +00:00
// reset inputs
ins->input_pct = 0.5f;
ins->input_option = 0;
ins->input_advance = false;
2022-08-08 09:39:42 +00:00
} else {
2022-08-21 23:34:15 +00:00
ins->scene_mode = Incenter_SceneMode_Input;
2022-08-08 09:39:42 +00:00
}
}
}
2022-08-21 23:34:15 +00:00
2022-08-08 09:39:42 +00:00
// DRaw the transition
switch (ins->scene_mode)
{
case Incenter_SceneMode_TransitioningOut: pattern = pattern_sun_transition_shrink; break;
case Incenter_SceneMode_TransitioningIn: pattern = pattern_sun_transition_grow; break;
2022-08-21 23:34:15 +00:00
case Incenter_SceneMode_Input: pattern = pattern_scene_input; break;
2022-08-08 09:39:42 +00:00
default: {
Incenter_Scene scene = ins->scenes[ins->scene_at];
pattern = scene.patterns[ins->scene_mode];
} break;
}
2022-08-21 23:34:15 +00:00
2022-08-08 09:39:42 +00:00
Assembly_Array assemblies = state->assemblies;
if (pattern)
{
pattern(assemblies.pixel_buffers[0], assemblies.strip_arrays[0], ins);
}
else
{
pattern_color(assemblies.pixel_buffers[0], assemblies.strip_arrays[0], 0, 0, 0);
}
}
2022-08-21 23:34:15 +00:00
#include "incenter_interface_connection.h"
#include "incenter_interface_connection.c"
2022-08-08 09:39:42 +00:00
////////////////////////////////////////////////
// INCENTER LIFECYCLE
internal App_Init_Desc
incenter_get_init_desc()
{
App_Init_Desc result = {};
result.assembly_cap = 4;
return result;
}
internal void
incenter_init(App_State* state)
{
// create user space data
Incenter_State* ins = allocator_alloc_struct(permanent, Incenter_State);
state->user_space_data = (u8*)ins;
incenter_scenes_init(ins, 8, permanent);
2022-08-21 23:34:15 +00:00
2022-08-08 09:39:42 +00:00
// create the sculpture
u32 lights_per_primary_city = 123;
u32 primary_city_lights = (city_count + 1) * lights_per_primary_city;
u32 secondary_city_count = (city_secondary_count - city_secondary_first) + 1;
u32 secondary_city_lights = secondary_city_count;
u32 lights_cap = primary_city_lights + secondary_city_lights;
Assembly_Handle ah = assembly_add(&state->assemblies, lit_str("incenter"), lights_cap, city_count + 2);
scratch_get(scratch);
Allocator* s = scratch.a;
v3 start_p = (v3){0, 0, 0};
Assembly_Strip* vertical_strip = assembly_add_strip(&state->assemblies, ah, 123);
assembly_strip_create_leds(
2022-08-21 23:34:15 +00:00
&state->assemblies,
2022-08-08 09:39:42 +00:00
ah,
vertical_strip,
start_p,
(v3){0, INCENTER_FEET(-4.5f), 0},
123
);
// ADDING PRIMARY CITIES
r32 radius = INCENTER_FEET(10);
for (u32 i = 0; i < city_count; i++)
{
Incenter_City_Desc city = city_descs[i];
v3 end_p = incenter_latlng_to_cartesian(city.lat, city.lon, radius).xyz;
2022-08-21 23:34:15 +00:00
2022-08-08 09:39:42 +00:00
Assembly_Strip* strip = assembly_add_strip(&state->assemblies, ah, 123);
strip->output_kind = OutputData_NetworkSACN;
strip->sacn_universe = city.sacn_universe;
assembly_strip_create_leds(&state->assemblies, ah, strip, start_p, end_p, 123);
}
// ADDING SECONDARY CITIES
// TODO: This probably isn't how these lights will be hooked up
Assembly_Strip* secondary_strip = assembly_add_strip(&state->assemblies, ah, secondary_city_lights);
secondary_strip->output_kind = OutputData_NetworkSACN;
secondary_strip->sacn_universe = incenter_secondary_city_universe;
for (u32 i = city_secondary_first; i < city_secondary_count; i++)
{
Incenter_City_Desc city = city_descs[i];
v4 light_p = incenter_latlng_to_cartesian(city.lat, city.lon, radius);
assembly_add_led(&state->assemblies, ah, secondary_strip, light_p);
}
// PATTERN INIT
pattern_random_fill_prep();
2022-08-21 23:34:15 +00:00
2022-08-08 09:39:42 +00:00
r32 rad = 0.05f;
sculpture_updated(state, 5, rad);
2022-08-21 23:34:15 +00:00
ins->running = true;
incenter_interface_connection_init(state, ins);
2022-08-10 00:12:28 +00:00
printf("Incenter Initialized\n");
2022-08-21 23:34:15 +00:00
scratch_release(scratch);
2022-08-08 09:39:42 +00:00
}
internal void
incenter_frame_prepare(App_State* state)
{
}
#if defined(PLATFORM_SUPPORTS_EDITOR)
2022-08-08 09:39:42 +00:00
internal void
incenter_sculpture_visualizer_ui(App_State* state, Editor* ed)
{
UI_Layout layout = *ed->ui.layout;
layout.mode = UILayout_Columns,
layout.bounds_min = (v2){0, 0},
layout.bounds_max.x = 250;
ui_layout_push(&ed->ui, &layout);
2022-08-21 23:34:15 +00:00
2022-08-08 09:39:42 +00:00
Incenter_State* ins = (Incenter_State*)state->user_space_data;
ui_text_f(&ed->ui, WHITE_V4, "Scene Time: %fs", ins->scene_time);
ui_text_f(&ed->ui, WHITE_V4, "Scene: %s", ins->scenes[ins->scene_at].name);
2022-08-21 23:34:15 +00:00
2022-08-08 09:39:42 +00:00
ui_layout_pop(&ed->ui);
}
#endif
2022-08-08 09:39:42 +00:00
internal void
incenter_frame(App_State* state)
{
Incenter_State* ins = (Incenter_State*)state->user_space_data;
Assembly_Array assemblies = state->assemblies;
2022-08-21 23:34:15 +00:00
2022-08-08 09:39:42 +00:00
{ // INPUT HANDLING
Input_State* is = state->input_state;
if (input_key_went_down(is, KeyCode_LeftArrow)) incenter_scene_go_to_prev(ins);
if (input_key_went_down(is, KeyCode_RightArrow)) incenter_scene_go_to_next(ins);
}
2022-08-21 23:34:15 +00:00
incenter_interface_connection_frame(state, ins);
2022-08-08 09:39:42 +00:00
ins->scene_time += state->target_seconds_per_frame;
ins->transition_time += state->target_seconds_per_frame;
incenter_scene_render(state, ins);
2022-08-21 23:34:15 +00:00
2022-08-08 09:39:42 +00:00
}
internal void
incenter_cleanup(App_State* state)
{
2022-08-21 23:34:15 +00:00
Incenter_State* ins = (Incenter_State*)state->user_space_data;
ins->running = false;
os_thread_end(ins->interface_thread);
incenter_interface_connection_cleanup(ins);
2022-08-08 09:39:42 +00:00
}