2020-01-02 02:41:43 +00:00
|
|
|
//
|
|
|
|
// File: foldhaus_assembly.cpp
|
|
|
|
// Author: Peter Slattery
|
|
|
|
// Creation Date: 2020-01-01
|
|
|
|
//
|
|
|
|
#ifndef FOLDHAUS_ASSEMBLY_CPP
|
|
|
|
|
2020-06-10 03:33:51 +00:00
|
|
|
internal void
|
|
|
|
ConstructAssemblyFromDefinition (assembly* Assembly, string AssemblyName, v4 RootPosition)
|
2019-11-23 00:07:25 +00:00
|
|
|
{
|
2020-06-10 03:33:51 +00:00
|
|
|
Assembly->LEDBuffer.LEDCount = 0;
|
|
|
|
Assembly->LEDBuffer.Colors = PushArray(&Assembly->Arena, pixel, Assembly->LedCountTotal);
|
|
|
|
Assembly->LEDBuffer.LEDs = PushArray(&Assembly->Arena, led, Assembly->LedCountTotal);
|
|
|
|
Assembly->LEDUniverseMapCount = Assembly->LedCountTotal;
|
|
|
|
Assembly->LEDUniverseMap = PushArray(&Assembly->Arena, leds_in_universe_range, Assembly->LedCountTotal);
|
2019-11-23 00:07:25 +00:00
|
|
|
|
|
|
|
// Add LEDs
|
2020-06-10 03:33:51 +00:00
|
|
|
for (u32 StripIdx = 0; StripIdx < Assembly->StripCount; StripIdx++)
|
2019-11-23 00:07:25 +00:00
|
|
|
{
|
2020-06-10 03:33:51 +00:00
|
|
|
//led_strip_definition StripDef = Definition.LEDStrips[StripIdx];
|
|
|
|
v2_strip* StripAt = &Assembly->Strips[StripIdx];
|
2019-11-23 00:07:25 +00:00
|
|
|
|
2020-06-10 03:33:51 +00:00
|
|
|
leds_in_universe_range* LEDUniverseRange = &Assembly->LEDUniverseMap[StripIdx];
|
2019-11-23 07:33:48 +00:00
|
|
|
|
2020-06-10 03:33:51 +00:00
|
|
|
LEDUniverseRange->Universe = StripAt->StartUniverse;
|
|
|
|
LEDUniverseRange->RangeStart = Assembly->LEDBuffer.LEDCount;
|
|
|
|
LEDUniverseRange->RangeOnePastLast = Assembly->LEDBuffer.LEDCount + StripAt->LedCount;
|
2019-11-23 00:07:25 +00:00
|
|
|
|
2020-06-10 03:33:51 +00:00
|
|
|
v4 WS_StripStart = RootPosition + V4(StripAt->StartPosition * Assembly->Scale, 1);
|
|
|
|
v4 WS_StripEnd = RootPosition + V4(StripAt->EndPosition * Assembly->Scale, 1);
|
|
|
|
s32 LEDsInStripCount = StripAt->LedCount;
|
2019-11-23 00:07:25 +00:00
|
|
|
|
|
|
|
v4 SingleStep = (WS_StripEnd - WS_StripStart) / (r32)LEDsInStripCount;
|
|
|
|
for (s32 Step = 0; Step < LEDsInStripCount; Step++)
|
|
|
|
{
|
2020-06-10 03:33:51 +00:00
|
|
|
s32 LEDIndex = Assembly->LEDBuffer.LEDCount;
|
|
|
|
Assembly->LEDBuffer.LEDs[LEDIndex].Position = WS_StripStart + (SingleStep * Step);
|
|
|
|
Assembly->LEDBuffer.LEDs[LEDIndex].Index = LEDIndex;
|
|
|
|
Assembly->LEDBuffer.LEDCount += 1;
|
2019-11-23 00:07:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-26 22:45:27 +00:00
|
|
|
|
2020-02-05 20:29:48 +00:00
|
|
|
// NOTE(Peter): These are here so that if we load 2+ sculptures, they don't all
|
|
|
|
// end up on top of one another. Purely aesthetic. Can remove once we implement
|
|
|
|
// scene editing tools
|
2019-12-27 02:40:14 +00:00
|
|
|
static v4 TempAssemblyOffsets[] = { v4{0, 0, 0, 0}, v4{250, 0, 75, 0}, v4{-250, 0, 75, 0} };
|
|
|
|
s32 TempAssemblyOffsetsCount = 3;
|
|
|
|
|
2019-12-26 22:45:27 +00:00
|
|
|
internal void
|
2020-05-30 22:09:06 +00:00
|
|
|
LoadAssembly (app_state* State, context Context, string Path)
|
2019-12-26 22:45:27 +00:00
|
|
|
{
|
2020-05-30 21:54:37 +00:00
|
|
|
platform_memory_result AssemblyFile = ReadEntireFile(Context, Path);
|
2020-02-06 04:24:34 +00:00
|
|
|
if (AssemblyFile.Error == PlatformMemory_NoError)
|
2020-02-05 08:03:56 +00:00
|
|
|
{
|
2020-06-10 03:33:51 +00:00
|
|
|
string AssemblyFileText = MakeString((char*)AssemblyFile.Base);
|
2020-02-05 20:29:48 +00:00
|
|
|
|
2020-05-30 22:09:06 +00:00
|
|
|
s32 IndexOfLastSlash = FastLastIndexOfCharInCharArray(Path.Memory, Path.Length, '\\');
|
|
|
|
string FileName = Substring(Path, IndexOfLastSlash + 1);
|
2020-02-05 20:29:48 +00:00
|
|
|
|
2020-06-10 03:33:51 +00:00
|
|
|
assembly NewAssembly = {};
|
|
|
|
NewAssembly.Arena.Alloc = (gs_memory_alloc*)Context.PlatformAlloc;
|
|
|
|
NewAssembly.Arena.Realloc = (gs_memory_realloc*)Context.PlatformRealloc;
|
|
|
|
ParseAssemblyFile(&NewAssembly, AssemblyFileText, &State->Transient);
|
2020-02-05 20:29:48 +00:00
|
|
|
|
|
|
|
v4 Offset = TempAssemblyOffsets[State->ActiveAssemblyIndecies.Used % TempAssemblyOffsetsCount];
|
2020-06-10 03:33:51 +00:00
|
|
|
ConstructAssemblyFromDefinition(&NewAssembly, FileName, Offset);
|
2020-02-05 20:29:48 +00:00
|
|
|
gs_list_handle NewAssemblyHandle = State->AssemblyList.PushElementOnList(NewAssembly);
|
|
|
|
|
|
|
|
State->ActiveAssemblyIndecies.PushElementOnList(NewAssemblyHandle);
|
2020-03-08 21:44:28 +00:00
|
|
|
State->TotalLEDsCount += NewAssembly.LEDBuffer.LEDCount;
|
2020-02-05 20:29:48 +00:00
|
|
|
|
2020-02-06 04:24:34 +00:00
|
|
|
Context.PlatformFree(AssemblyFile.Base, AssemblyFile.Size);
|
2020-02-05 20:29:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-06 04:24:34 +00:00
|
|
|
LogError(State->GlobalLog, "Unable to load assembly file");
|
2020-02-05 08:03:56 +00:00
|
|
|
}
|
2019-12-26 22:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2019-12-31 04:26:28 +00:00
|
|
|
UnloadAssembly (u32 AssemblyIndex, app_state* State, context Context)
|
2019-12-26 22:45:27 +00:00
|
|
|
{
|
2019-12-31 04:26:28 +00:00
|
|
|
assembly* Assembly = State->AssemblyList.GetElementAtIndex(AssemblyIndex);
|
2020-03-08 21:44:28 +00:00
|
|
|
State->TotalLEDsCount -= Assembly->LEDBuffer.LEDCount;
|
2019-12-26 22:45:27 +00:00
|
|
|
FreeMemoryArena(&Assembly->Arena, (gs_memory_free*)Context.PlatformFree);
|
|
|
|
|
2019-12-31 04:26:28 +00:00
|
|
|
State->AssemblyList.FreeElementAtIndex(AssemblyIndex);
|
|
|
|
for (u32 i = 0; i < State->ActiveAssemblyIndecies.Used; i++)
|
2019-12-26 22:45:27 +00:00
|
|
|
{
|
2019-12-31 04:26:28 +00:00
|
|
|
gs_list_handle Handle = *State->ActiveAssemblyIndecies.GetElementAtIndex(i);
|
2019-12-26 22:45:27 +00:00
|
|
|
if (Handle.Index == AssemblyIndex)
|
|
|
|
{
|
2019-12-31 04:26:28 +00:00
|
|
|
State->ActiveAssemblyIndecies.FreeElementAtIndex(i);
|
2019-12-26 22:45:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-02 02:41:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define FOLDHAUS_ASSEMBLY_CPP
|
|
|
|
#endif // FOLDHAUS_ASSEMBLY_CPP
|