Fixed some CSV parsing errors and implemented white and black colors

This commit is contained in:
PS 2021-04-08 10:07:41 -10:00
parent bbf07cc6e2
commit f45be27edc
5 changed files with 107 additions and 48 deletions

View File

@ -42,6 +42,7 @@ typedef struct panel panel;
#include "engine/animation/foldhaus_animation_renderer.cpp" #include "engine/animation/foldhaus_animation_renderer.cpp"
#include "engine/user_space.h" #include "engine/user_space.h"
#include "ss_blumen_lumen/gfx_math.h"
#include "ss_blumen_lumen/phrase_hue_map.h" #include "ss_blumen_lumen/phrase_hue_map.h"
#include "ss_blumen_lumen/blumen_lumen.h" #include "ss_blumen_lumen/blumen_lumen.h"
@ -95,7 +96,6 @@ LoadAssembly(gs_const_string Path, app_state* State, context Context)
#include "engine/user_space.cpp" #include "engine/user_space.cpp"
#include "ss_blumen_lumen/gfx_math.h"
#include "ss_blumen_lumen/sdf.h" #include "ss_blumen_lumen/sdf.h"
#include "patterns/blumen_patterns.h" #include "patterns/blumen_patterns.h"
#include "ss_blumen_lumen/blumen_lumen.cpp" #include "ss_blumen_lumen/blumen_lumen.cpp"

View File

@ -127,9 +127,9 @@ Pattern_BasicFlowers(led_buffer* Leds, led_buffer_range Range, assembly Assembly
Time = Time * BLState->PatternSpeed; Time = Time * BLState->PatternSpeed;
phrase_hue Hue = BLState->AssemblyColors[Assembly.AssemblyIndex % 3]; phrase_hue Hue = BLState->AssemblyColors[Assembly.AssemblyIndex % 3];
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1}); v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1}); v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1}); v4 C2 = RGBFromPhraseHue(Hue.Hue2);
for (u32 StripIndex = 0; StripIndex < Assembly.StripCount; StripIndex++) for (u32 StripIndex = 0; StripIndex < Assembly.StripCount; StripIndex++)
{ {
@ -166,9 +166,9 @@ Pattern_Wavy(led_buffer* Leds, led_buffer_range Range, assembly Assembly, r32 Ti
Time = Time * BLState->PatternSpeed; Time = Time * BLState->PatternSpeed;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly); phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1}); v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1}); v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1}); v4 C2 = RGBFromPhraseHue(Hue.Hue2);
r32 Top = 120 + (SinR32(Time) * 10); r32 Top = 120 + (SinR32(Time) * 10);
r32 Mid = 70 + (CosR32(Time * 2.13) * 20); r32 Mid = 70 + (CosR32(Time * 2.13) * 20);
@ -228,8 +228,9 @@ Pattern_Patchy(led_buffer* Leds, led_buffer_range Range, assembly Assembly, r32
Time = Time * BLState->PatternSpeed; Time = Time * BLState->PatternSpeed;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly); phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1}); v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1}); v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = RGBFromPhraseHue(Hue.Hue2);
for (u32 LedIndex = Range.First; LedIndex < Range.OnePastLast; LedIndex++) for (u32 LedIndex = Range.First; LedIndex < Range.OnePastLast; LedIndex++)
{ {
@ -290,9 +291,9 @@ Pattern_Leafy(led_buffer* Leds, led_buffer_range Range, assembly Assembly, r32 T
Time = Time * BLState->PatternSpeed; Time = Time * BLState->PatternSpeed;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly); phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1}); v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1}); v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1}); v4 C2 = RGBFromPhraseHue(Hue.Hue2);
for (u32 LedIndex = Range.First; LedIndex < Range.OnePastLast; LedIndex++) for (u32 LedIndex = Range.First; LedIndex < Range.OnePastLast; LedIndex++)
{ {
@ -326,9 +327,9 @@ Pattern_LeafyPatchy(led_buffer* Leds, led_buffer_range Range, assembly Assembly,
Time = Time * BLState->PatternSpeed; Time = Time * BLState->PatternSpeed;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly); phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1}); v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1}); v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1}); v4 C2 = RGBFromPhraseHue(Hue.Hue2);
for (u32 LedIndex = Range.First; LedIndex < Range.OnePastLast; LedIndex++) for (u32 LedIndex = Range.First; LedIndex < Range.OnePastLast; LedIndex++)
{ {
@ -609,9 +610,9 @@ Pattern_VoicePattern(led_buffer* Leds, led_buffer_range Range, assembly Assembly
Time = Time * BLState->PatternSpeed; Time = Time * BLState->PatternSpeed;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly); phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1}); v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1}); v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1}); v4 C2 = RGBFromPhraseHue(Hue.Hue2);
for (u32 LedIndex = Range.First; LedIndex < Range.OnePastLast; LedIndex++) for (u32 LedIndex = Range.First; LedIndex < Range.OnePastLast; LedIndex++)
{ {

View File

@ -380,10 +380,14 @@ BlumenLumen_CustomInit(app_state* State, context Context)
BLState->ModeAnimations[BlumenPattern_VoiceCommand] = LoadAllAnimationsInDir(VoicePatternFolder, BLState, State, Context); BLState->ModeAnimations[BlumenPattern_VoiceCommand] = LoadAllAnimationsInDir(VoicePatternFolder, BLState, State, Context);
AnimationSystem_LoadAnimationFromFile(&State->AnimationSystem, State->Patterns, Context, ConstString("data/blumen_animations/anim_demo.foldanim")); AnimationSystem_LoadAnimationFromFile(&State->AnimationSystem, State->Patterns, Context, ConstString("data/blumen_animations/anim_demo.foldanim"));
BlumenLumen_SetPatternMode(BlumenPattern_VoiceCommand, 5, &State->AnimationSystem, BLState); BlumenLumen_SetPatternMode(BlumenPattern_Standard, 5, &State->AnimationSystem, BLState);
#endif #endif
State->AnimationSystem.TimelineShouldAdvance = true; State->AnimationSystem.TimelineShouldAdvance = true;
BLState->StandardPatternHues.Hue0.Flags = Hue_Value;
BLState->StandardPatternHues.Hue1.Flags = Hue_Value;
BLState->StandardPatternHues.Hue2.Flags = Hue_Value;
BlumenLumen_AppendBootupLog(State, BLState, Context); BlumenLumen_AppendBootupLog(State, BLState, Context);
return Result; return Result;
} }
@ -510,9 +514,9 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
r32 ColorRelOscSpeed = 1 * ColorSpeed;; r32 ColorRelOscSpeed = 1 * ColorSpeed;;
r32 ColorOscillation = (SinR32(BaseTime * ColorOscSpeed) + 1) / 2; r32 ColorOscillation = (SinR32(BaseTime * ColorOscSpeed) + 1) / 2;
r32 ColorRelationship = 30 + (((1 + SinR32(BaseTime * ColorRelOscSpeed)) / 2) * 300); r32 ColorRelationship = 30 + (((1 + SinR32(BaseTime * ColorRelOscSpeed)) / 2) * 300);
BLState->StandardPatternHues.Hue0 = ModR32(ColorOscillation * 360, 360); BLState->StandardPatternHues.Hue0.Hue = ModR32(ColorOscillation * 360, 360);
BLState->StandardPatternHues.Hue1 = ModR32(BaseTime + ColorRelationship, 360); BLState->StandardPatternHues.Hue1.Hue = ModR32(BaseTime + ColorRelationship, 360);
BLState->StandardPatternHues.Hue2 = LerpR32(.3f, BLState->StandardPatternHues.Hue0, BLState->StandardPatternHues.Hue1); BLState->StandardPatternHues.Hue2.Hue = LerpR32(.3f, BLState->StandardPatternHues.Hue0.Hue, BLState->StandardPatternHues.Hue1.Hue);
// Transition back to standard mode after some time // Transition back to standard mode after some time
if (BLState->PatternMode == BlumenPattern_VoiceCommand) if (BLState->PatternMode == BlumenPattern_VoiceCommand)

View File

@ -16,8 +16,8 @@ gs_const_string Flower2AssemblyPath = ConstString("data/ss_blumen_three.fold");
// The path to the phrase map CSV. Can be an absolute path, or relative // The path to the phrase map CSV. Can be an absolute path, or relative
// to the app_run_tree folder // to the app_run_tree folder
gs_const_string PhraseMapCSVPath = ConstString("data/flower_codes.csv"); gs_const_string PhraseMapCSVPath = ConstString("data/flower_codes.tsv");
char PhraseMapCSVSeparator = ','; char PhraseMapCSVSeparator = '\t';
// Search Strings for which folders to find ambient animation files and // Search Strings for which folders to find ambient animation files and
// voice animation files in. // voice animation files in.

View File

@ -3,58 +3,112 @@
#ifndef PHRASE_HUE_MAP_H #ifndef PHRASE_HUE_MAP_H
#define PHRASE_HUE_MAP_H #define PHRASE_HUE_MAP_H
enum p_hue_flag
{
Hue_Value = 0,
Hue_White = 1,
Hue_Black = 2,
};
typedef struct p_hue
{
r64 Hue;
p_hue_flag Flags;
} p_hue;
typedef struct phrase_hue_map typedef struct phrase_hue_map
{ {
u64 CountMax;
u64 Count; u64 Count;
gs_const_string* Phrases; gs_const_string* Phrases;
u64* PhraseHashes; u64* PhraseHashes;
r32* Hue0; p_hue* Hue0;
r32* Hue1; p_hue* Hue1;
r32* Hue2; p_hue* Hue2;
} phrase_hue_map; } phrase_hue_map;
typedef struct phrase_hue typedef struct phrase_hue
{ {
gs_const_string Phrase; gs_const_string Phrase;
u64 PhraseHash; u64 PhraseHash;
r32 Hue0; p_hue Hue0;
r32 Hue1; p_hue Hue1;
r32 Hue2; p_hue Hue2;
} phrase_hue; } phrase_hue;
internal p_hue
CreateHueFromString(gs_const_string Str)
{
p_hue Result = {};
if (Str.Str[0] == 'b') {
Result.Flags = Hue_Black;
} else if (Str.Str[0] == 'w') {
Result.Flags = Hue_White;
} else {
Result.Flags = Hue_Value;
Result.Hue = (r64)ParseFloat(Str);
}
return Result;
}
internal v4
RGBFromPhraseHue (p_hue H)
{
v4 Result = {};
switch (H.Flags)
{
case Hue_Black: { Result = v4{1, 0, 0, 1}; } break;
case Hue_White: { Result = v4{1, 0, 1, 1}; } break;
case Hue_Value: { Result = v4{(r32)H.Hue, 1, 1, 1}; } break;
InvalidDefaultCase;
}
Result = HSVToRGB(Result);
return Result;
}
internal phrase_hue_map internal phrase_hue_map
PhraseHueMap_GenFromCSV(gscsv_sheet Sheet, gs_memory_arena* Arena) PhraseHueMap_GenFromCSV(gscsv_sheet Sheet, gs_memory_arena* Arena)
{ {
phrase_hue_map Result = {}; phrase_hue_map Result = {};
Result.Count = Sheet.RowCount - 1; // we don't include the header row Result.CountMax = Sheet.RowCount - 1; // we don't include the header row
Result.Phrases = PushArray(Arena, gs_const_string, Result.Count); Result.Phrases = PushArray(Arena, gs_const_string, Result.CountMax);
Result.PhraseHashes = PushArray(Arena, u64, Result.Count); Result.PhraseHashes = PushArray(Arena, u64, Result.CountMax);
Result.Hue0 = PushArray(Arena, r32, Result.Count); Result.Hue0 = PushArray(Arena, p_hue, Result.CountMax);
Result.Hue1 = PushArray(Arena, r32, Result.Count); Result.Hue1 = PushArray(Arena, p_hue, Result.CountMax);
Result.Hue2 = PushArray(Arena, r32, Result.Count); Result.Hue2 = PushArray(Arena, p_hue, Result.CountMax);
s32 DestOffset = 0;
for (u32 Row = 1; Row < Sheet.RowCount; Row++) for (u32 Row = 1; Row < Sheet.RowCount; Row++)
{ {
u32 Index = Row - 1; s32 Index = (Row - 1) - DestOffset;
Assert(Index >= 0 && Index < Result.CountMax);
gs_const_string Phrase = CSVSheet_GetCell(Sheet, gs_const_string Phrase = CSVSheet_GetCell(Sheet,
0, Row); 0, Row);
u64 PhraseHash = HashDJB2ToU32(StringExpand(Phrase)); u64 PhraseHash = HashDJB2ToU32(StringExpand(Phrase));
gs_const_string Hue0Str = CSVSheet_GetCell(Sheet,
1, Row); gs_const_string Hue0Str = CSVSheet_GetCell(Sheet, 1, Row);
gs_const_string Hue1Str = CSVSheet_GetCell(Sheet, gs_const_string Hue1Str = CSVSheet_GetCell(Sheet, 2, Row);
2, Row); gs_const_string Hue2Str = CSVSheet_GetCell(Sheet, 3, Row);
gs_const_string Hue2Str = CSVSheet_GetCell(Sheet, gs_const_string Homonyms = CSVSheet_GetCell(Sheet, 4, Row);
3, Row); if (Phrase.Length == 0 ||
gs_const_string Homonyms = CSVSheet_GetCell(Sheet, Hue0Str.Length == 0 ||
4, Row); Hue1Str.Length == 0 ||
Hue2Str.Length == 0)
{
DestOffset++;
continue;
}
Result.Phrases[Index] = PushStringF(Arena, Phrase.Length, "%S", Phrase).ConstString; Result.Phrases[Index] = PushStringF(Arena, Phrase.Length, "%S", Phrase).ConstString;
Result.PhraseHashes[Index] = PhraseHash; Result.PhraseHashes[Index] = PhraseHash;
Result.Hue0[Index] = (r64)ParseFloat(Hue0Str); Result.Hue0[Index] = CreateHueFromString(Hue0Str);
Result.Hue1[Index] = (r64)ParseFloat(Hue1Str); Result.Hue1[Index] = CreateHueFromString(Hue1Str);
Result.Hue2[Index] = (r64)ParseFloat(Hue2Str); Result.Hue2[Index] = CreateHueFromString(Hue2Str);
} }
Result.Count = Result.CountMax + DestOffset;
return Result; return Result;
} }