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/user_space.h"
#include "ss_blumen_lumen/gfx_math.h"
#include "ss_blumen_lumen/phrase_hue_map.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 "ss_blumen_lumen/gfx_math.h"
#include "ss_blumen_lumen/sdf.h"
#include "patterns/blumen_patterns.h"
#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;
phrase_hue Hue = BLState->AssemblyColors[Assembly.AssemblyIndex % 3];
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1});
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1});
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1});
v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = RGBFromPhraseHue(Hue.Hue2);
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;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1});
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1});
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1});
v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = RGBFromPhraseHue(Hue.Hue2);
r32 Top = 120 + (SinR32(Time) * 10);
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;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1});
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1});
v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = RGBFromPhraseHue(Hue.Hue2);
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;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1});
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1});
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1});
v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = RGBFromPhraseHue(Hue.Hue2);
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;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1});
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1});
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1});
v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = RGBFromPhraseHue(Hue.Hue2);
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;
phrase_hue Hue = BlumenLumen_GetCurrentHue(BLState, Assembly);
v4 C0 = HSVToRGB({Hue.Hue0, 1, 1, 1});
v4 C1 = HSVToRGB({Hue.Hue1, 1, 1, 1});
v4 C2 = HSVToRGB({Hue.Hue2, 1, 1, 1});
v4 C0 = RGBFromPhraseHue(Hue.Hue0);
v4 C1 = RGBFromPhraseHue(Hue.Hue1);
v4 C2 = RGBFromPhraseHue(Hue.Hue2);
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);
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
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);
return Result;
}
@ -510,9 +514,9 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
r32 ColorRelOscSpeed = 1 * ColorSpeed;;
r32 ColorOscillation = (SinR32(BaseTime * ColorOscSpeed) + 1) / 2;
r32 ColorRelationship = 30 + (((1 + SinR32(BaseTime * ColorRelOscSpeed)) / 2) * 300);
BLState->StandardPatternHues.Hue0 = ModR32(ColorOscillation * 360, 360);
BLState->StandardPatternHues.Hue1 = ModR32(BaseTime + ColorRelationship, 360);
BLState->StandardPatternHues.Hue2 = LerpR32(.3f, BLState->StandardPatternHues.Hue0, BLState->StandardPatternHues.Hue1);
BLState->StandardPatternHues.Hue0.Hue = ModR32(ColorOscillation * 360, 360);
BLState->StandardPatternHues.Hue1.Hue = ModR32(BaseTime + ColorRelationship, 360);
BLState->StandardPatternHues.Hue2.Hue = LerpR32(.3f, BLState->StandardPatternHues.Hue0.Hue, BLState->StandardPatternHues.Hue1.Hue);
// Transition back to standard mode after some time
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
// to the app_run_tree folder
gs_const_string PhraseMapCSVPath = ConstString("data/flower_codes.csv");
char PhraseMapCSVSeparator = ',';
gs_const_string PhraseMapCSVPath = ConstString("data/flower_codes.tsv");
char PhraseMapCSVSeparator = '\t';
// Search Strings for which folders to find ambient animation files and
// voice animation files in.

View File

@ -3,58 +3,112 @@
#ifndef 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
{
u64 CountMax;
u64 Count;
gs_const_string* Phrases;
u64* PhraseHashes;
r32* Hue0;
r32* Hue1;
r32* Hue2;
p_hue* Hue0;
p_hue* Hue1;
p_hue* Hue2;
} phrase_hue_map;
typedef struct phrase_hue
{
gs_const_string Phrase;
u64 PhraseHash;
r32 Hue0;
r32 Hue1;
r32 Hue2;
p_hue Hue0;
p_hue Hue1;
p_hue Hue2;
} 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
PhraseHueMap_GenFromCSV(gscsv_sheet Sheet, gs_memory_arena* Arena)
{
phrase_hue_map Result = {};
Result.Count = Sheet.RowCount - 1; // we don't include the header row
Result.Phrases = PushArray(Arena, gs_const_string, Result.Count);
Result.PhraseHashes = PushArray(Arena, u64, Result.Count);
Result.Hue0 = PushArray(Arena, r32, Result.Count);
Result.Hue1 = PushArray(Arena, r32, Result.Count);
Result.Hue2 = PushArray(Arena, r32, Result.Count);
Result.CountMax = Sheet.RowCount - 1; // we don't include the header row
Result.Phrases = PushArray(Arena, gs_const_string, Result.CountMax);
Result.PhraseHashes = PushArray(Arena, u64, Result.CountMax);
Result.Hue0 = PushArray(Arena, p_hue, Result.CountMax);
Result.Hue1 = PushArray(Arena, p_hue, Result.CountMax);
Result.Hue2 = PushArray(Arena, p_hue, Result.CountMax);
s32 DestOffset = 0;
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,
0, Row);
u64 PhraseHash = HashDJB2ToU32(StringExpand(Phrase));
gs_const_string Hue0Str = CSVSheet_GetCell(Sheet,
1, Row);
gs_const_string Hue1Str = CSVSheet_GetCell(Sheet,
2, Row);
gs_const_string Hue2Str = CSVSheet_GetCell(Sheet,
3, Row);
gs_const_string Homonyms = CSVSheet_GetCell(Sheet,
4, Row);
gs_const_string Hue0Str = CSVSheet_GetCell(Sheet, 1, Row);
gs_const_string Hue1Str = CSVSheet_GetCell(Sheet, 2, Row);
gs_const_string Hue2Str = CSVSheet_GetCell(Sheet, 3, Row);
gs_const_string Homonyms = CSVSheet_GetCell(Sheet, 4, Row);
if (Phrase.Length == 0 ||
Hue0Str.Length == 0 ||
Hue1Str.Length == 0 ||
Hue2Str.Length == 0)
{
DestOffset++;
continue;
}
Result.Phrases[Index] = PushStringF(Arena, Phrase.Length, "%S", Phrase).ConstString;
Result.PhraseHashes[Index] = PhraseHash;
Result.Hue0[Index] = (r64)ParseFloat(Hue0Str);
Result.Hue1[Index] = (r64)ParseFloat(Hue1Str);
Result.Hue2[Index] = (r64)ParseFloat(Hue2Str);
Result.Hue0[Index] = CreateHueFromString(Hue0Str);
Result.Hue1[Index] = CreateHueFromString(Hue1Str);
Result.Hue2[Index] = CreateHueFromString(Hue2Str);
}
Result.Count = Result.CountMax + DestOffset;
return Result;
}