incenter - live data capture works!

This commit is contained in:
Cameron Tacklind 2022-08-30 16:25:05 -07:00
parent 7d54794c1f
commit 382ed2615f
8 changed files with 81 additions and 24 deletions

Binary file not shown.

View File

@ -127,10 +127,11 @@ incenter_handle_sliding_scale_msg(Incenter_State* ins, Incenter_Scene scene, cha
case 'C': { case 'C': {
live_answers_input_r32(ins, scene, ins->input_pct); live_answers_input_r32(ins, scene, ins->input_pct);
ins->scene_mode = Incenter_SceneMode_Passive;
ins->scene_time = 0;
} break; } break;
} }
ins->scene_mode = Incenter_SceneMode_Passive;
ins->scene_time = 0;
ins->input_pct = clamp(0, ins->input_pct, 1); ins->input_pct = clamp(0, ins->input_pct, 1);
} }

View File

@ -71,7 +71,22 @@ live_answers_load(Incenter_Scene scene, Allocator* allocator)
Live_Answers_File result = {0}; Live_Answers_File result = {0};
// Read the File // Read the File
#define USING_PLATFORM_LAYER 0
#if !USING_PLATFORM_LAYER
result.path = string_f(allocator, "data/live_data/%s.incenterdata", scene.name); result.path = string_f(allocator, "data/live_data/%s.incenterdata", scene.name);
Data file_data = {0};
FILE* file = fopen((const char*)result.path.str, "rb");
if (file) {
fseek(file, 0, SEEK_END);
s32 size = ftell(file);
fseek(file, 0, SEEK_SET);
file_data.base = allocator_alloc(allocator, size);
file_data.size = fread((void*)file_data.base, size, 1, file);
fclose(file);
} else {
printf("Creating live data file: %s\n", (char*)result.path.str);
}
#else
File_Handle file = os_file_open(result.path, FileAccess_Read, FileCreate_OpenExisting); File_Handle file = os_file_open(result.path, FileAccess_Read, FileCreate_OpenExisting);
Data file_data = {0}; Data file_data = {0};
if (file.value != 0) if (file.value != 0)
@ -79,6 +94,7 @@ live_answers_load(Incenter_Scene scene, Allocator* allocator)
file_data = os_file_read_all(file, allocator); file_data = os_file_read_all(file, allocator);
os_file_close(file); os_file_close(file);
} }
#endif
// Obtain structure of file data // Obtain structure of file data
if (file_data.size > 1) { if (file_data.size > 1) {
@ -114,6 +130,14 @@ live_answers_save(Live_Answers_File file, Live_Answers_File_Bucket* new_bucket)
return; return;
} }
#if !USING_PLATFORM_LAYER
FILE* fh = fopen((const char*)file.path.str, "wb");
if (!fh) {
printf("Error: Unable to open live data file for writing\n");
printf(" Live Data File: %.*s\n", str_varg(file.path));
return;
}
#else
File_Handle fh = os_file_open(file.path, FileAccess_Write, FileCreate_OpenAlways); File_Handle fh = os_file_open(file.path, FileAccess_Write, FileCreate_OpenAlways);
if (fh.value == 0) { if (fh.value == 0) {
printf("Error: Unable to open live data file for writing\n"); printf("Error: Unable to open live data file for writing\n");
@ -124,31 +148,52 @@ live_answers_save(Live_Answers_File file, Live_Answers_File_Bucket* new_bucket)
return; return;
} }
#endif
Data existing_data = { Data existing_data = {
.base = (u8*)file.header, .base = (u8*)file.header,
.size = sizeof(Live_Answers_File_Header) + (sizeof(Live_Answers_File_Bucket) * file.header->buckets_count) .size = sizeof(Live_Answers_File_Header) + (sizeof(Live_Answers_File_Bucket) * file.header->buckets_count)
}; };
#if !USING_PLATFORM_LAYER
s32 size_written = fwrite((void*)existing_data.base, 1, existing_data.size, fh);
if (size_written != existing_data.size) {
printf("Unable to write full file: %.*s\n", str_varg(file.path));
printf(" Size Needed: %lu, Size Written: %d\n", existing_data.size, size_written);
}
#else
if (!os_file_write(fh, existing_data)) { if (!os_file_write(fh, existing_data)) {
printf("Error: Could not write existing data to Live Data File\n"); printf("Error: Could not write existing data to Live Data File\n");
printf(" Live Data File: %.*s\n", str_varg(file.path)); printf(" Live Data File: %.*s\n", str_varg(file.path));
} }
#endif
if (new_bucket) { if (new_bucket) {
Data new_data = { Data new_data = {
.base = (u8*)new_bucket, .base = (u8*)new_bucket,
.size = sizeof(Live_Answers_File_Bucket) .size = sizeof(Live_Answers_File_Bucket)
}; };
#if !USING_PLATFORM_LAYER
size_written = fwrite(new_data.base, 1, new_data.size, fh);
if (size_written != new_data.size) {
printf("Unable to add new data to file %.*s\n", str_varg(file.path));
printf(" Size Needed: %lu, Size Written: %d\n", new_data.size, size_written);
}
#else
if (!os_file_write(fh, new_data)) { if (!os_file_write(fh, new_data)) {
printf("Error: Could not write new bucket data to Live Data File\n"); printf("Error: Could not write new bucket data to Live Data File\n");
printf(" Live Data File: %.*s\n", str_varg(file.path)); printf(" Live Data File: %.*s\n", str_varg(file.path));
} }
#endif
} }
#if !USING_PLATFORM_LAYER
fclose(fh);
#else
os_file_close(fh); os_file_close(fh);
#endif
} }
#if 0 #if 1
# define MAYBE_SKIP_SAVING_INPUT # define MAYBE_SKIP_SAVING_INPUT
#else #else
# define MAYBE_SKIP_SAVING_INPUT return # define MAYBE_SKIP_SAVING_INPUT return
@ -188,7 +233,7 @@ live_answers_input_u32(Incenter_State* ins, Incenter_Scene scene, u32 value)
live_answers_save(file, new_bucket); live_answers_save(file, new_bucket);
scratch_release(scratch); 4scratch_release(scratch);
} }
internal void internal void

View File

@ -995,6 +995,12 @@ pattern_bar_chart(Assembly_Pixel_Buffer pixels, Assembly_Strip_Array strips, Inc
pattern_add_bar_chart(pixels, strips, ins, scene, scene.data[0].year, scene.data[0].month, xray_ramp); pattern_add_bar_chart(pixels, strips, ins, scene, scene.data[0].year, scene.data[0].month, xray_ramp);
} }
global bool needs_reset = true;
global u32 year_max = 0;
global Incenter_Month_Id month_max = 0;
global u32 year_at = 0;
global Incenter_Month_Id month_at = 0;
global r32 month_start_time = 0;
void void
pattern_bar_chart_over_time(Assembly_Pixel_Buffer pixels, Assembly_Strip_Array strips, Incenter_State* ins) pattern_bar_chart_over_time(Assembly_Pixel_Buffer pixels, Assembly_Strip_Array strips, Incenter_State* ins)
@ -1002,15 +1008,9 @@ pattern_bar_chart_over_time(Assembly_Pixel_Buffer pixels, Assembly_Strip_Array s
Incenter_Scene scene = ins->scenes[ins->scene_at]; Incenter_Scene scene = ins->scenes[ins->scene_at];
if (!scene.data) return; if (!scene.data) return;
local_persist s32 last_scene_at = -1; if (needs_reset)
local_persist u32 year_max = 0;
local_persist Incenter_Month_Id month_max = 0;
local_persist u32 year_at = 0;
local_persist Incenter_Month_Id month_at = 0;
local_persist r32 month_start_time = 0;
if (last_scene_at != ins->scene_at)
{ {
last_scene_at = ins->scene_at; needs_reset = false;
// Determine what the end of the data set is // Determine what the end of the data set is
for (u32 row_i = 0; row_i < scene.data_len; row_i++) for (u32 row_i = 0; row_i < scene.data_len; row_i++)
@ -1027,7 +1027,7 @@ pattern_bar_chart_over_time(Assembly_Pixel_Buffer pixels, Assembly_Strip_Array s
month_start_time = ins->scene_time; month_start_time = ins->scene_time;
} }
r32 month_duration = 2; r32 month_duration = 1;
r32 time_at_month = ins->scene_time - month_start_time; r32 time_at_month = ins->scene_time - month_start_time;
if (time_at_month > month_duration) if (time_at_month > month_duration)
{ {
@ -1136,7 +1136,7 @@ pattern_felt_isolated_passive(Assembly_Pixel_Buffer pixels, Assembly_Strip_Array
{ {
Incenter_Data_Row row = scene.data[row_i]; Incenter_Data_Row row = scene.data[row_i];
Assembly_Strip strip = strips.strips[row.id]; Assembly_Strip strip = strips.strips[row.id];
u32 pixel_start = strip.pixels_len - (row.prop * strip.pixels_len); s32 pixel_start = (row.prop * strip.pixels_len);
r32 row_offset = (.1439f * row_i); r32 row_offset = (.1439f * row_i);
r32 b = pm_sinf_01(ins->scene_time + row_offset); r32 b = pm_sinf_01(ins->scene_time + row_offset);
@ -1146,9 +1146,10 @@ pattern_felt_isolated_passive(Assembly_Pixel_Buffer pixels, Assembly_Strip_Array
r32 grow_pct = clamp(0, grow_time, grow_duration) / grow_duration; r32 grow_pct = clamp(0, grow_time, grow_duration) / grow_duration;
r32 grow_pct_smoothed = pm_easeinout_cubic_r32(grow_pct); r32 grow_pct_smoothed = pm_easeinout_cubic_r32(grow_pct);
u32 pixels_on = (strip.pixels_len - pixel_start) * grow_pct_smoothed; s32 pixels_on = pixel_start * grow_pct_smoothed;
u32 pixel_stop = clamp(pixel_start + 1, pixel_start + pixels_on, strip.pixels_len); s32 pixel_stop = clamp(0, pixel_start - pixels_on, pixel_start - 1);
for (u32 pixel_i = pixel_start; pixel_i < pixel_stop; pixel_i++) for (u32 pixel_i =
pixel_stop; pixel_i < pixel_start; pixel_i++)
{ {
u32 pixel_index = strip.pixels[pixel_i]; u32 pixel_index = strip.pixels[pixel_i];
pixels.pixels[pixel_index] = pattern_felt_isolated_color( pixels.pixels[pixel_index] = pattern_felt_isolated_color(

View File

@ -105,7 +105,7 @@ incenter_scene_descs_init()
}, },
.data = question_7_data, .data = question_7_data,
.data_len = question_7_len, .data_len = question_7_len,
.kind = Incenter_SceneKind_SlidingScale, .kind = Incenter_SceneKind_YesOrNo,
}; };
incenter_scene_descs[Incenter_Scene_Question_ConnectionFriendsFamily] = (Incenter_Scene){ incenter_scene_descs[Incenter_Scene_Question_ConnectionFriendsFamily] = (Incenter_Scene){
@ -186,14 +186,14 @@ incenter_scene_descs_init()
}, },
.data = question_18_data, .data = question_18_data,
.data_len = question_18_len, .data_len = question_18_len,
.kind = Incenter_SceneKind_YesOrNo, .kind = Incenter_SceneKind_SlidingScale,
}; };
incenter_scene_descs[Incenter_Scene_Question_BelieveScienceRenewableTech] = (Incenter_Scene){ incenter_scene_descs[Incenter_Scene_Question_BelieveScienceRenewableTech] = (Incenter_Scene){
.name = "BelieveScienceRenewableTech", .name = "BelieveScienceRenewableTech",
.patterns = { .patterns = {
[Incenter_SceneMode_Intro] = pattern_bar_chart_random_fill, [Incenter_SceneMode_Intro] = pattern_felt_isolated_intro ,
[Incenter_SceneMode_Passive] = pattern_bar_chart_random_fill, [Incenter_SceneMode_Passive] = pattern_felt_isolated_passive,
}, },
.data = question_19_data, .data = question_19_data,
.data_len = question_19_len, .data_len = question_19_len,
@ -203,8 +203,8 @@ incenter_scene_descs_init()
incenter_scene_descs[Incenter_Scene_Question_StriveMoreEcoFriendly] = (Incenter_Scene){ incenter_scene_descs[Incenter_Scene_Question_StriveMoreEcoFriendly] = (Incenter_Scene){
.name = "StriveMoreEcoFriendly", .name = "StriveMoreEcoFriendly",
.patterns = { .patterns = {
[Incenter_SceneMode_Intro] = pattern_bar_chart, [Incenter_SceneMode_Intro] = pattern_bar_chart_over_time,
[Incenter_SceneMode_Passive] = pattern_bar_chart, [Incenter_SceneMode_Passive] = pattern_bar_chart_over_time,
}, },
// .data = question_22_data, // .data = question_22_data,
// .data_len = question_22_len, // .data_len = question_22_len,

View File

@ -25,6 +25,14 @@ incenter_scenes_init(Incenter_State* ins, u32 cap, Allocator* a)
internal void internal void
incenter_reset_inputs(Incenter_State* ins) incenter_reset_inputs(Incenter_State* ins)
{ {
// reset bar chart over time
needs_reset = true;
year_max = 0;
month_max = 0;
year_at = 0;
month_at = 0;
month_start_time = 0;
// reset inputs // reset inputs
ins->input_pct = 0.5f; ins->input_pct = 0.5f;
ins->input_option = 0; ins->input_option = 0;

View File

@ -3,6 +3,8 @@
- FILE IO bugs - FILE IO bugs
x Timeout to idle x Timeout to idle
LUSIO Light festival
- kids love this thing "THATS THE COOLEST" - kids love this thing "THATS THE COOLEST"
- conversation about "People probably haven't talked about their covid experience yet, this is really good." - conversation about "People probably haven't talked about their covid experience yet, this is really good."
- "This is the most peaceful I've felt in a long time" - "This is the most peaceful I've felt in a long time"