Added a default tag to every strip specifying which assembly it is a part of

This commit is contained in:
Peter Slattery 2020-09-07 12:37:32 -07:00
parent cc41442923
commit c7522bfa4b
5 changed files with 53 additions and 39 deletions

View File

@ -370,6 +370,15 @@ ReadStructClosing(assembly_tokenizer* T)
return Result;
}
internal void
StripSetTag(v2_strip* Strip, u32 TagIndex, gs_const_string TagName, gs_const_string TagValue)
{
Assert(TagIndex < Strip->TagsCount);
v2_tag* TagAt = &Strip->Tags[TagIndex];
TagAt->NameHash = HashDJB2ToU32(StringExpand(TagName));
TagAt->ValueHash = HashDJB2ToU32(StringExpand(TagValue));
}
internal bool
ParseAssemblyFile(assembly* Assembly, gs_const_string FileName, gs_string FileText, gs_memory_arena* Transient)
{
@ -420,19 +429,21 @@ ParseAssemblyFile(assembly* Assembly, gs_const_string FileName, gs_string FileTe
StripAt->LedCount = ReadIntField(AssemblyField_LedCount, &Tokenizer);
Assembly->LedCountTotal += StripAt->LedCount;
StripAt->TagsCount = ReadIntField(AssemblyField_TagsCount, &Tokenizer);
// NOTE(pjs): Always add one tag to the input to leave room for the assembly name
StripAt->TagsCount += 1;
StripAt->Tags = PushArray(&Assembly->Arena, v2_tag, StripAt->TagsCount);
for (u32 Tag = 0; Tag < StripAt->TagsCount; Tag++)
StripSetTag(StripAt, 0, ConstString("assembly"), Assembly->Name.ConstString);
for (u32 Tag = 1; Tag < StripAt->TagsCount; Tag++)
{
v2_tag* TagAt = StripAt->Tags + Tag;
if (ReadStructOpening(AssemblyField_Tag, &Tokenizer))
{
// TODO(Peter): Need to store the gs_string somewhere we can look it up for display in the interface
// right now they are stored in temp memory and won't persist
gs_string TagName = ReadStringField(AssemblyField_Name, &Tokenizer, Transient);
gs_string TagValue = ReadStringField(AssemblyField_Value, &Tokenizer, Transient);
TagAt->NameHash = HashDJB2ToU32(StringExpand(TagName));
TagAt->ValueHash = HashDJB2ToU32(StringExpand(TagValue));
StripSetTag(StripAt, Tag, TagName.ConstString, TagValue.ConstString);
if (!ReadStructClosing(&Tokenizer))
{
TokenizerPushError(&Tokenizer, "Struct doesn't close where expected");
@ -444,6 +455,7 @@ ParseAssemblyFile(assembly* Assembly, gs_const_string FileName, gs_string FileTe
}
}
if (!ReadStructClosing(&Tokenizer))
{
TokenizerPushError(&Tokenizer, "Struct doesn't close where expected");

View File

@ -77,7 +77,7 @@ LedBufferSetLed(led_buffer* Buffer, u32 Led, v4 Position)
}
internal void
ConstructAssemblyFromDefinition (assembly* Assembly, gs_const_string AssemblyName, led_system* LedSystem)
ConstructAssemblyFromDefinition (assembly* Assembly, led_system* LedSystem)
{
Assembly->LedBufferIndex = LedSystemTakeFreeBuffer(LedSystem, Assembly->LedCountTotal);
led_buffer* LedBuffer = LedSystemGetBuffer(LedSystem, Assembly->LedBufferIndex);
@ -88,7 +88,6 @@ ConstructAssemblyFromDefinition (assembly* Assembly, gs_const_string AssemblyNam
u32 LedsAdded = 0;
for (u32 StripIdx = 0; StripIdx < Assembly->StripCount; StripIdx++)
{
//led_strip_definition StripDef = Definition.LedStrips[StripIdx];
v2_strip* StripAt = &Assembly->Strips[StripIdx];
StripAt->LedLUT = PushArray(&Assembly->Arena, u32, StripAt->LedCount);
@ -120,16 +119,16 @@ LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, gs_memory_arena
{
gs_string AssemblyFileText = MakeString((char*)AssemblyFile.Memory);
Assert(Assemblies->Count < Assemblies->CountMax);
assembly* NewAssembly = &Assemblies->Values[Assemblies->Count++];
s32 IndexOfLastSlash = FindLast(Path, '\\');
gs_const_string FileName = Substring(Path, IndexOfLastSlash + 1, Path.Length);
Assert(Assemblies->Count < Assemblies->CountMax);
assembly* NewAssembly = &Assemblies->Values[Assemblies->Count++];
NewAssembly->Arena = CreateMemoryArena(Context.ThreadContext.Allocator);
if (ParseAssemblyFile(NewAssembly, FileName, AssemblyFileText, Scratch))
{
ConstructAssemblyFromDefinition(NewAssembly, FileName, LedSystem);
ConstructAssemblyFromDefinition(NewAssembly, LedSystem);
AllocatorFree(Context.ThreadContext.Allocator, AssemblyFile.Memory, AssemblyFile.Size);
}
else

View File

@ -155,6 +155,9 @@ INITIALIZE_APPLICATION(InitializeApplication)
#if 1
gs_const_string SculpturePath = ConstString("data/blumen_lumen_v2.fold");
LoadAssembly(&State->Assemblies, &State->LedSystem, &State->Transient, Context, SculpturePath, State->GlobalLog);
SculpturePath = ConstString("data/radialumia_v2.fold");
LoadAssembly(&State->Assemblies, &State->LedSystem, &State->Transient, Context, SculpturePath, State->GlobalLog);
#endif
State->PixelsToWorldScale = .01f;

View File

@ -79,24 +79,33 @@ internal void OpenColorPicker(app_state* State, v4* Address);
internal void
TestPatternOne(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient)
{
led_strip_list StemStrips = AssemblyStripsGetWithTagValue(Assembly, ConstString("section"), ConstString("stem"), Transient);
led_strip_list BlumenStrips = AssemblyStripsGetWithTagValue(Assembly, ConstString("assembly"), ConstString("Blumen Lumen"), Transient);
led_strip_list RadiaStrips = AssemblyStripsGetWithTagValue(Assembly, ConstString("assembly"), ConstString("Radialumia"), Transient);
for (u32 i = 0; i < StemStrips.Count; i++)
for (u32 i = 0; i < BlumenStrips.Count; i++)
{
u32 StripIndex = StemStrips.StripIndices[i];
u32 StripIndex = BlumenStrips.StripIndices[i];
v2_strip StripAt = Assembly.Strips[StripIndex];
for (u32 j = 0; j < StripAt.LedCount; j++)
{
u32 LedIndex = StripAt.LedLUT[j];
v4 LedPosition = Leds->Positions[LedIndex];
float PercentX = RemapClampedR32(LedPosition.x, -150.0f, 150.0f, 0.0f, 1.0f);
float PercentY = RemapClampedR32(LedPosition.y, -150.0f, 150.0f, 0.0f, 1.0f);
Leds->Colors[LedIndex].R = (u8)(PercentX * 255);
Leds->Colors[LedIndex].G = (u8)(PercentY * 255);
Leds->Colors[LedIndex] = { 255, 0, 0 };
}
}
for (u32 i = 0; i < RadiaStrips.Count; i++)
{
u32 StripIndex = RadiaStrips.StripIndices[i];
v2_strip StripAt = Assembly.Strips[StripIndex];
for (u32 j = 0; j < StripAt.LedCount; j++)
{
u32 LedIndex = StripAt.LedLUT[j];
Leds->Colors[LedIndex] = { 0, 255, 0 };
}
}
#if 0
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
{

View File

@ -1,15 +1,5 @@
TODO FOLDHAUS
STREAM #0: Metaprogramming
- Metaprogramming
- fix memory layout (remeber to profile before and after)
- Make everything truly platform agnostic
- Application DLL
- math.h: present for trig functions (though this is part of the c-std lib, so it should be everywhere)
- windows.h: only thing left is InterlockedIncrement and InterlockedAdd
- Meta Layer
- ???
STREAM #1: 3D Overhaul
- Rendering (Working on this elsewhere)
- OpenGL 3
@ -24,6 +14,7 @@ STREAM #1: 3D Overhaul
- leds always face camera
- Sculptures
- implicitly add a tag equal to the sculpture name to each strip of leds
- cache led vertex buffers
- custom sculpture update functions (for motion)
- editing sculpture files (change universe output)
@ -33,7 +24,6 @@ STREAM #1: 3D Overhaul
- mouse spatial interaction - handles, and hover for info
- debug capabilities (toggle strip/led/universe colors)
STREAM #2: Memory
- Buckets & Lists
- On second thought, I just really don't like these. Lets get rid of them, and put custom structures in place
@ -44,11 +34,11 @@ STREAM #2: Memory
- Create a bar that displays the most recent error message
- :ErrorLogging
STREAM #3: Nodes
- Animation System
- blending between animation
- layers
- layer masks by sculpture
- layer masks by tag / value
- interface for animation system
- add/remove layers
- select blend modes
@ -57,17 +47,8 @@ STREAM #3: Nodes
- clips can have parameters that drive them?
- clips cannot overlap eachother on the same layer
- Node System
- automatic node layout
- blending node layouts
- workspace -> animation block
- generating node workspace as code
- compiling node workspace
- hotload compiled pattern sets
- Serialization
- saving scenes
- saving node graphs
- saving animation timelines
- saving projects
@ -157,3 +138,13 @@ Name
- Splash screen (like blender) (thisll be fun)
- - Image importer (stb image? or find a png > bmp converter for the image you have)
- - Display on startup
STREAM #0: Metaprogramming
- Metaprogramming
- fix memory layout (remeber to profile before and after)
- Make everything truly platform agnostic
- Application DLL
- math.h: present for trig functions (though this is part of the c-std lib, so it should be everywhere)
- windows.h: only thing left is InterlockedIncrement and InterlockedAdd
- Meta Layer
- ???