getting demo together

This commit is contained in:
Peter Slattery 2022-10-24 16:14:37 -07:00
parent 56a3bd2f52
commit 4a92c7d3c6
18 changed files with 283 additions and 144 deletions

View File

@ -85,7 +85,7 @@ ed_sculpture_visualizer(App_State* state)
{
Editor* ed = state->editor;
incenter_sculpture_visualizer_ui(state, ed);
if (state->user_space_desc.sculpture_visualizer_ui) state->user_space_desc.sculpture_visualizer_ui(state, ed);
#define SCULPTURE_VIZ_BLOOM 0
#if SCULPTURE_VIZ_BLOOM

View File

@ -180,6 +180,8 @@ ui_draw_panel(BSP* tree, BSP_Node_Id id, BSP_Node* node, u8* user_data)
if (ui->draw_panel_cb) ui->draw_panel_cb(ui->draw_panel_cb_data, id, *node, area);
#define DRAW_PANEL_OUTLINE 0
#if DRAW_PANEL_OUTLINE
r32 z = -1;
v3 l0p0 = (v3){ area.min.x, area.min.y, z }; // left side
v3 l0p1 = (v3){ area.min.x + 1, area.max.y, z };
@ -200,6 +202,7 @@ ui_draw_panel(BSP* tree, BSP_Node_Id id, BSP_Node* node, u8* user_data)
ui_sprite_push_color(ui, l1p0, l1p1, sid, c);
ui_sprite_push_color(ui, l2p0, l2p1, sid, c);
ui_sprite_push_color(ui, l3p0, l3p1, sid, c);
#endif
}
internal void

View File

@ -0,0 +1,101 @@
// Color Utils
Assembly_Pixel
color_v3_to_assembly_pixel(v3 c)
{
return (Assembly_Pixel){
.r = (u8)(c.x * 255),
.g = (u8)(c.y * 255),
.b = (u8)(c.z * 255),
};
}
Assembly_Pixel
color_v3_to_assembly_pixel_faded(v3 c, r32 b)
{
return (Assembly_Pixel){
.r = (u8)(c.x * b * 255),
.g = (u8)(c.y * b * 255),
.b = (u8)(c.z * b * 255),
};
}
u8
u8_add_safe(u8 a, u8 b)
{
u8 r = a + b;
if (r < a || r < b) r = 255;
return r;
}
Assembly_Pixel
assembly_pixel_add(Assembly_Pixel a, Assembly_Pixel b)
{
Assembly_Pixel result = {
.r = u8_add_safe(a.r, b.r),
.g = u8_add_safe(a.g, b.g),
.b = u8_add_safe(a.b, b.b),
};
return result;
}
Assembly_Pixel
assembly_pixel_add_multi(u32 count, ...)
{
Assembly_Pixel result = {};
va_list args;
va_start(args, count);
for (u32 i = 0; i < count; i++) {
Assembly_Pixel p = va_arg(args, Assembly_Pixel);
result.r = u8_add_safe(result.r, p.r);
result.g = u8_add_safe(result.g, p.g);
result.b = u8_add_safe(result.b, p.b);
}
return result;
}
Assembly_Pixel
assembly_pixel_scale(Assembly_Pixel p, r32 scale)
{
Assembly_Pixel result = {
.r = (u8)(clamp(0, p.r * scale, 255)),
.g = (u8)(clamp(0, p.g * scale, 255)),
.b = (u8)(clamp(0, p.b * scale, 255)),
};
return result;
}
Assembly_Pixel
assembly_pixel_scale_u8(u32 r, u32 g, u32 b, r32 scale)
{
Assembly_Pixel result = {
.r = (u8)(clamp(0, r * scale, 255)),
.g = (u8)(clamp(0, g * scale, 255)),
.b = (u8)(clamp(0, b * scale, 255)),
};
return result;
}
Assembly_Pixel
assembly_pixel_blend(Assembly_Pixel a, Assembly_Pixel b, r32 t)
{
r32 rf = lerp((r32)a.r, t, (r32)b.r);
r32 gf = lerp((r32)a.g, t, (r32)b.g);
r32 bf = lerp((r32)a.b, t, (r32)b.b);
r32 rc = clamp(0, rf, 255);
r32 gc = clamp(0, gf, 255);
Assembly_Pixel result = {
.r = (u8)rc,
.g = (u8)clamp(0, gf, 255),
.b = (u8)clamp(0, bf, 255),
};
return result;
}
Assembly_Pixel
color_ramp_eval_pixel(Color_Ramp ramp, r32 pct)
{
v3 c = color_ramp_eval(ramp, pct);
Assembly_Pixel r = color_v3_to_assembly_pixel(c);
return r;
}

View File

@ -1,5 +1,5 @@
#include "lumenarium_first.h"
#include "user_space/incenter_user_space.c"
#include "user_space/demo/demo_user_space.c"
void
sculpture_updated(App_State* state, r32 scale, r32 led_size)
@ -18,14 +18,13 @@ lumenarium_init(Editor_Desc* ed_desc)
global_scratch_ = bump_allocator_create_reserve(GB(1));
run_tests();
//cvtcsv_convert(lit_str("./data/incenter_test_data_clean.csv"));
scratch_get(scratch);
App_Init_Desc desc = incenter_get_init_desc();
App_Init_Desc desc = user_space_get_init_desc();
// TODO(PS): make sure the values make sense in desc
state = allocator_alloc_struct(permanent, App_State);
state->user_space_desc = desc;
add_flag(state->flags, AppState_IsRunning);
#if !defined(PLATFORM_raspi)
@ -69,7 +68,7 @@ lumenarium_init(Editor_Desc* ed_desc)
#if defined(PLATFORM_SUPPORTS_EDITOR)
if (has_flag(state->flags, AppState_RunEditor)) ed_init(state, ed_desc);
#endif
if (has_flag(state->flags, AppState_RunUserSpace)) incenter_init(state);
if (has_flag(state->flags, AppState_RunUserSpace) && state->user_space_desc.init) state->user_space_desc.init(state);
scratch_release(scratch);
return state;
}
@ -85,7 +84,7 @@ lumenarium_frame_prepare(App_State* state)
#if defined(PLATFORM_SUPPORTS_EDITOR)
if (has_flag(state->flags, AppState_RunEditor)) ed_frame_prepare(state);
#endif
if (has_flag(state->flags, AppState_RunUserSpace)) incenter_frame_prepare(state);
if (has_flag(state->flags, AppState_RunUserSpace) && state->user_space_desc.frame_prepare) state->user_space_desc.frame_prepare(state);
file_async_jobs_do_work(&state->file_async_job_system, 4, (u8*)state);
}
@ -93,7 +92,7 @@ lumenarium_frame_prepare(App_State* state)
internal void
lumenarium_frame(App_State* state)
{
if (has_flag(state->flags, AppState_RunUserSpace)) incenter_frame(state);
if (has_flag(state->flags, AppState_RunUserSpace) && state->user_space_desc.frame) state->user_space_desc.frame(state);
en_frame(state);
#if defined(PLATFORM_SUPPORTS_EDITOR)
if (has_flag(state->flags, AppState_RunEditor)) ed_frame(state);
@ -147,7 +146,7 @@ lumenarium_event(Window_Event evt, App_State* state)
internal void
lumenarium_cleanup(App_State* state)
{
if (has_flag(state->flags, AppState_RunUserSpace)) incenter_cleanup(state);
if (has_flag(state->flags, AppState_RunUserSpace) && state->user_space_desc.cleanup) state->user_space_desc.cleanup(state);
en_cleanup(state);
#if defined(PLATFORM_SUPPORTS_EDITOR)
if (has_flag(state->flags, AppState_RunEditor)) ed_cleanup(state);

View File

@ -70,16 +70,30 @@ enum
AppState_RunUserSpace = 4,
};
typedef struct App_State App_State;
typedef void User_Space_Callback(App_State* state);
#if defined(PLATFORM_SUPPORTS_EDITOR)
typedef void User_Space_Editor_Callback(App_State* state, Editor* ed);
#endif
typedef struct App_Init_Desc App_Init_Desc;
struct App_Init_Desc
{
u32 assembly_cap;
User_Space_Callback* init;
User_Space_Callback* frame_prepare;
#if defined(PLATFORM_SUPPORTS_EDITOR)
User_Space_Editor_Callback* sculpture_visualizer_ui;
#endif
User_Space_Callback* frame;
User_Space_Callback* cleanup;
};
typedef struct App_State App_State;
struct App_State
{
r64 target_seconds_per_frame;
App_Init_Desc user_space_desc;
App_State_Flags flags;
File_Async_Job_System file_async_job_system;
@ -104,17 +118,16 @@ struct Editor_Desc
void sculpture_updated(App_State* state, r32 scale, r32 led_size);
#include "user_space/incenter_user_space.h"
//#include "../run_tree/data/incenter_test_data.c"
#include "user_space/demo/demo_user_space.h"
#include "engine/lumenarium_engine_assembly.c"
#include "engine/lumenarium_engine_assembly_pixel.c"
#include "engine/lumenarium_engine.c"
#include "engine/lumenarium_engine_output.c"
#include "engine/output/lumenarium_output_uart.c"
#include "engine/output/lumenarium_output_sacn.c"
#if defined(PLATFORM_SUPPORTS_EDITOR)
internal void incenter_sculpture_visualizer_ui(App_State* state, Editor* ed);
# include "editor/lumenarium_editor_ui.c"
# include "editor/lumenarium_editor_renderer.c"
# include "editor/lumenarium_editor_sculpture_visualizer.c"

View File

@ -61,6 +61,8 @@ pm_easeinout_cubic_r32(r32 v)
}
}
///// vector extensions
v2 pm_lerp_v2(v2 a, r32 t, v2 b) {

View File

@ -0,0 +1,113 @@
#define DEMO_STRIP_LEDS_CAP 123
internal void
demo_push_strip(Assembly_Array* aa, Assembly_Handle ah, u32 universe, v3 start, v3 end)
{
Assembly_Strip* strip = assembly_add_strip(aa, ah, DEMO_STRIP_LEDS_CAP);
strip->output_kind = OutputData_NetworkSACN;
strip->sacn_universe = universe;
assembly_strip_append_leds(aa, ah, strip, start, end, DEMO_STRIP_LEDS_CAP);
}
internal void
demo_init(App_State* state)
{
Assembly_Array* aa = &state->assemblies;
u32 strips_dim = 9;
u32 strips_cap = strips_dim * strips_dim;
Assembly_Handle ah = assembly_add(aa, lit_str("Demo"), strips_cap * DEMO_STRIP_LEDS_CAP, strips_cap);
scratch_get(scratch);
Allocator* s = scratch.a;
r32 r = 0.5f;
s32 start = -(strips_dim / 2);
s32 end = strips_dim / 2;
r32 z_min = -((r * strips_dim) / 2.0f);
r32 z_max = ((r * strips_dim) / 2.0f);
for (s32 y = start; y < end; y++)
{
for (s32 x = start; x < end; x++)
{
demo_push_strip(aa, ah, 1, (v3){x * r, y * r, z_min}, (v3){ x * r, y * r, z_max});
}
}
sculpture_updated(state, 5, 0.1f);
}
internal void
demo_frame_prepare(App_State* state)
{
}
#if defined(PLATFORM_SUPPORTS_EDITOR)
internal void
demo_sculpture_visualizer_ui(App_State* state, Editor* ed)
{
}
#endif
global Color_Ramp aurora_ramp = {
.anchors = {
[0] = { .pct = 0, .color = { 0, 0, 0 } },
[1] = { .pct = .4f, .color = { 0, 0, 0 } },
[2] = { .pct = .55f, .color = { 176.f / 255.f, 65.f / 255.f, 36.f / 255.f } },
[3] = { .pct = .7f, .color = { 237.f / 255.f, 201.f / 255.f, 138.f / 255.f } },
[4] = { .pct = .80f, .color = { 49.f / 255.f, 156.f / 255.f, 255.f / 255.f } },
[5] = { .pct = 1.0f, .color = { 49.f / 255.f, 156.f / 255.f, 255.f / 255.f } },
},
.anchors_count = 5,
};
void
pattern_aurora(Assembly_Pixel_Buffer pixels, Assembly_Strip_Array strips, r32 scene_time)
{
for (u32 i = 0; i < pixels.len; i++)
{
v3 p = pixels.positions[i].xyz;
v3 p_offset = HMM_AddVec3(p, (v3){ 213.145f, 99.321f, 71.3f });
v3 p_scaled = HMM_MultiplyVec3f(p_offset, 0.25f);
r32 v = pm_fmb_3d(p_scaled, scene_time);
r32 vv = pm_smoothstep_r32(v);
v3 color = color_ramp_eval(aurora_ramp, vv);
pixels.pixels[i] = color_v3_to_assembly_pixel(color);
}
}
internal void
demo_frame(App_State* state)
{
local_persist r64 t = 0;
t += state->target_seconds_per_frame;
Assembly_Array assemblies = state->assemblies;
for (u32 assembly_i = 0; assembly_i < assemblies.len; assembly_i++)
{
Assembly_Strip_Array* strips = assemblies.strip_arrays + assembly_i;
Assembly_Pixel_Buffer* pixels = assemblies.pixel_buffers + assembly_i;
pattern_aurora(*pixels, *strips, (r32)t);
}
}
internal void
demo_cleanup(App_State* state)
{
}
internal App_Init_Desc
user_space_get_init_desc()
{
return (App_Init_Desc){
.assembly_cap = 1,
.init = demo_init,
.frame_prepare = demo_frame_prepare,
#if defined(PLATFORM_SUPPORTS_EDITOR)
.sculpture_visualizer_ui = demo_sculpture_visualizer_ui,
#endif
.frame = demo_frame,
.cleanup = demo_cleanup,
};
}

View File

View File

@ -38,106 +38,6 @@ pattern_debug(Assembly_Pixel_Buffer pixels)
}
}
Assembly_Pixel
color_v3_to_assembly_pixel(v3 c)
{
return (Assembly_Pixel){
.r = (u8)(c.x * 255),
.g = (u8)(c.y * 255),
.b = (u8)(c.z * 255),
};
}
Assembly_Pixel
color_v3_to_assembly_pixel_faded(v3 c, r32 b)
{
return (Assembly_Pixel){
.r = (u8)(c.x * b * 255),
.g = (u8)(c.y * b * 255),
.b = (u8)(c.z * b * 255),
};
}
u8
u8_add_safe(u8 a, u8 b)
{
u8 r = a + b;
if (r < a || r < b) r = 255;
return r;
}
Assembly_Pixel
assembly_pixel_add(Assembly_Pixel a, Assembly_Pixel b)
{
Assembly_Pixel result = {
.r = u8_add_safe(a.r, b.r),
.g = u8_add_safe(a.g, b.g),
.b = u8_add_safe(a.b, b.b),
};
return result;
}
Assembly_Pixel
assembly_pixel_add_multi(u32 count, ...)
{
Assembly_Pixel result = {};
va_list args;
va_start(args, count);
for (u32 i = 0; i < count; i++) {
Assembly_Pixel p = va_arg(args, Assembly_Pixel);
result.r = u8_add_safe(result.r, p.r);
result.g = u8_add_safe(result.g, p.g);
result.b = u8_add_safe(result.b, p.b);
}
return result;
}
Assembly_Pixel
assembly_pixel_scale(Assembly_Pixel p, r32 scale)
{
Assembly_Pixel result = {
.r = (u8)(clamp(0, p.r * scale, 255)),
.g = (u8)(clamp(0, p.g * scale, 255)),
.b = (u8)(clamp(0, p.b * scale, 255)),
};
return result;
}
Assembly_Pixel
assembly_pixel_scale_u8(u32 r, u32 g, u32 b, r32 scale)
{
Assembly_Pixel result = {
.r = (u8)(clamp(0, r * scale, 255)),
.g = (u8)(clamp(0, g * scale, 255)),
.b = (u8)(clamp(0, b * scale, 255)),
};
return result;
}
Assembly_Pixel
assembly_pixel_blend(Assembly_Pixel a, Assembly_Pixel b, r32 t)
{
r32 rf = lerp((r32)a.r, t, (r32)b.r);
r32 gf = lerp((r32)a.g, t, (r32)b.g);
r32 bf = lerp((r32)a.b, t, (r32)b.b);
r32 rc = clamp(0, rf, 255);
r32 gc = clamp(0, gf, 255);
Assembly_Pixel result = {
.r = (u8)rc,
.g = (u8)clamp(0, gf, 255),
.b = (u8)clamp(0, bf, 255),
};
return result;
}
Assembly_Pixel
color_ramp_eval_pixel(Color_Ramp ramp, r32 pct)
{
v3 c = color_ramp_eval(ramp, pct);
Assembly_Pixel r = color_v3_to_assembly_pixel(c);
return r;
}
v3
sun_center_for_pos(v4 p, v4 center, r32 radius, r32 falloff)
{

View File

@ -4,8 +4,8 @@ u32 secondary_strips_len = 0;
Assembly_Strip* secondary_city_strips[SECONDARY_CITY_CAP];
#include "incenter_scenes.h"
#include "../user_space/incenter_patterns.c"
#include "../user_space/incenter_secondary_patterns.c"
#include "incenter_patterns.c"
#include "incenter_secondary_patterns.c"
#include "incenter_scenes.c"
#include "incenter_live_answers.c"
@ -135,14 +135,6 @@ incenter_scene_render(App_State* state, Incenter_State* ins)
////////////////////////////////////////////////
// INCENTER LIFECYCLE
internal App_Init_Desc
incenter_get_init_desc()
{
App_Init_Desc result = {};
result.assembly_cap = 4;
return result;
}
#define INCENTER_RADIUS INCENTER_FEET(10)
internal Assembly_Strip*
incenter_add_secondary_city_strip(Assembly_Array* assemblies, Assembly_Handle ah, u32 universe, u32 count, Incenter_City_Id city)
@ -378,4 +370,20 @@ incenter_cleanup(App_State* state)
ins->running = false;
os_thread_end(ins->interface_thread);
incenter_interface_connection_cleanup(ins);
}
internal App_Init_Desc
user_space_get_init_desc()
{
App_Init_Desc result = {
.assembly_cap = 4,
.init = incenter_init,
.frame_prepare = incenter_frame_prepare,
#if defined(PLATFORM_SUPPORTS_EDITOR)
.sculpture_visualizer_ui = incenter_sculpture_visualizer_ui,
#endif
.frame = incenter_frame,
.cleanup = incenter_cleanup,
};
return result;
}

View File

@ -50,27 +50,27 @@ struct Incenter_Data_Row
#include "incenter_gen_cities.h"
// Data
#include "../../run_tree/data/incenter_data/c/question_1.h"
#include "../../run_tree/data/incenter_data/c/question_2.h"
#include "../../run_tree/data/incenter_data/c/question_3.h"
#include "../../run_tree/data/incenter_data/c/question_4.h"
#include "../../run_tree/data/incenter_data/c/question_5.h"
#include "../../run_tree/data/incenter_data/c/question_6.h"
#include "../../run_tree/data/incenter_data/c/question_7.h"
#include "../../run_tree/data/incenter_data/c/question_8.h"
#include "../../run_tree/data/incenter_data/c/question_9.h"
#include "../../run_tree/data/incenter_data/c/question_10.h"
#include "../../run_tree/data/incenter_data/c/question_11.h"
#include "../../run_tree/data/incenter_data/c/question_12.h"
#include "../../run_tree/data/incenter_data/c/question_13.h"
#include "../../run_tree/data/incenter_data/c/question_14.h"
#include "../../run_tree/data/incenter_data/c/question_15.h"
#include "../../run_tree/data/incenter_data/c/question_16.h"
#include "../../run_tree/data/incenter_data/c/question_17.h"
#include "../../run_tree/data/incenter_data/c/question_18.h"
#include "../../run_tree/data/incenter_data/c/question_19.h"
#include "../../run_tree/data/incenter_data/c/question_20.h"
#include "../../run_tree/data/incenter_data/c/question_21.h"
#include "../../../run_tree/data/incenter_data/c/question_1.h"
#include "../../../run_tree/data/incenter_data/c/question_2.h"
#include "../../../run_tree/data/incenter_data/c/question_3.h"
#include "../../../run_tree/data/incenter_data/c/question_4.h"
#include "../../../run_tree/data/incenter_data/c/question_5.h"
#include "../../../run_tree/data/incenter_data/c/question_6.h"
#include "../../../run_tree/data/incenter_data/c/question_7.h"
#include "../../../run_tree/data/incenter_data/c/question_8.h"
#include "../../../run_tree/data/incenter_data/c/question_9.h"
#include "../../../run_tree/data/incenter_data/c/question_10.h"
#include "../../../run_tree/data/incenter_data/c/question_11.h"
#include "../../../run_tree/data/incenter_data/c/question_12.h"
#include "../../../run_tree/data/incenter_data/c/question_13.h"
#include "../../../run_tree/data/incenter_data/c/question_14.h"
#include "../../../run_tree/data/incenter_data/c/question_15.h"
#include "../../../run_tree/data/incenter_data/c/question_16.h"
#include "../../../run_tree/data/incenter_data/c/question_17.h"
#include "../../../run_tree/data/incenter_data/c/question_18.h"
#include "../../../run_tree/data/incenter_data/c/question_19.h"
#include "../../../run_tree/data/incenter_data/c/question_20.h"
#include "../../../run_tree/data/incenter_data/c/question_21.h"
typedef struct Incenter_State Incenter_State;