Formalized a system for user space sculpture code

This commit is contained in:
PS 2021-01-30 15:10:46 -08:00
parent 751ee2e27a
commit 4836f7550d
6 changed files with 117 additions and 44 deletions

View File

@ -47,6 +47,31 @@ BlumenLumen_MicListenJob(gs_thread_context* Ctx, u8* UserData)
CloseSocket(Data->SocketManager, Data->ListenSocket); CloseSocket(Data->SocketManager, Data->ListenSocket);
} }
internal void
BlumenLumen_LoadPatterns(app_state* State)
{
animation_pattern_array* Patterns = &State->Patterns;
if (Patterns->CountMax == 0)
{
*Patterns = Patterns_Create(&State->Permanent, 32);
}
Patterns->Count = 0;
Patterns_PushPattern(Patterns, TestPatternOne);
Patterns_PushPattern(Patterns, TestPatternTwo);
Patterns_PushPattern(Patterns, TestPatternThree);
Patterns_PushPattern(Patterns, Pattern_AllGreen);
Patterns_PushPattern(Patterns, Pattern_HueShift);
Patterns_PushPattern(Patterns, Pattern_HueFade);
Patterns_PushPattern(Patterns, Pattern_Spots);
Patterns_PushPattern(Patterns, Pattern_LighthouseRainbow);
Patterns_PushPattern(Patterns, Pattern_SmoothGrowRainbow);
Patterns_PushPattern(Patterns, Pattern_GrowAndFade);
Patterns_PushPattern(Patterns, Pattern_ColorToWhite);
Patterns_PushPattern(Patterns, Pattern_Blue);
Patterns_PushPattern(Patterns, Pattern_Green);
}
internal gs_data internal gs_data
BlumenLumen_CustomInit(app_state* State, context Context) BlumenLumen_CustomInit(app_state* State, context Context)
{ {
@ -176,6 +201,15 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
} }
} }
internal user_space_desc
BlumenLumen_UserSpaceCreate()
{
user_space_desc Result = {};
Result.LoadPatterns = BlumenLumen_LoadPatterns;
Result.CustomInit = BlumenLumen_CustomInit;
Result.CustomUpdate = BlumenLumen_CustomUpdate;
return Result;
}
#define BLUMEN_LUMEN_CPP #define BLUMEN_LUMEN_CPP
#endif // BLUMEN_LUMEN_CPP #endif // BLUMEN_LUMEN_CPP

View File

@ -0,0 +1,36 @@
//
// File: userspace.cpp
// Author: Peter Slattery
// Creation Date: 2021-01-30
//
#ifndef USERSPACE_CPP
internal void
US_LoadPatterns(user_space_desc* Desc, app_state* State, context Context)
{
if (Desc->LoadPatterns)
{
Desc->LoadPatterns(State);
}
}
internal void
US_CustomInit(user_space_desc* Desc, app_state* State, context Context)
{
if (Desc->CustomInit)
{
Desc->UserData = Desc->CustomInit(State, Context);
}
}
internal void
US_CustomUpdate(user_space_desc* Desc, app_state* State, context* Context)
{
if (Desc->CustomUpdate)
{
Desc->CustomUpdate(Desc->UserData, State, Context);
}
}
#define USERSPACE_CPP
#endif // USERSPACE_CPP

View File

@ -0,0 +1,27 @@
//
// File: userspace.h
// Author: Peter Slattery
// Creation Date: 2021-01-30
//
#ifndef USERSPACE_H
#define US_LOAD_PATTERNS(name) void name(app_state* State)
typedef US_LOAD_PATTERNS(us_load_patterns_proc);
#define US_CUSTOM_INIT(name) gs_data name (app_state* State, context Context)
typedef US_CUSTOM_INIT(us_custom_init_proc);
#define US_CUSTOM_UPDATE(name) void name(gs_data UserData, app_state* State, context* Context)
typedef US_CUSTOM_UPDATE(us_custom_update_proc);
typedef struct user_space_desc
{
us_load_patterns_proc* LoadPatterns;
us_custom_init_proc* CustomInit;
us_custom_update_proc* CustomUpdate;
gs_data UserData;
} user_space_desc;
#define USERSPACE_H
#endif // USERSPACE_H

View File

@ -8,27 +8,6 @@
#include "foldhaus_platform.h" #include "foldhaus_platform.h"
#include "foldhaus_app.h" #include "foldhaus_app.h"
internal void
ClearAndPushPatterns(animation_pattern_array* Patterns)
{
if (Patterns->CountMax == 0) { return; }
Patterns->Count = 0;
Patterns_PushPattern(Patterns, TestPatternOne);
Patterns_PushPattern(Patterns, TestPatternTwo);
Patterns_PushPattern(Patterns, TestPatternThree);
Patterns_PushPattern(Patterns, Pattern_AllGreen);
Patterns_PushPattern(Patterns, Pattern_HueShift);
Patterns_PushPattern(Patterns, Pattern_HueFade);
Patterns_PushPattern(Patterns, Pattern_Spots);
Patterns_PushPattern(Patterns, Pattern_LighthouseRainbow);
Patterns_PushPattern(Patterns, Pattern_SmoothGrowRainbow);
Patterns_PushPattern(Patterns, Pattern_GrowAndFade);
Patterns_PushPattern(Patterns, Pattern_ColorToWhite);
Patterns_PushPattern(Patterns, Pattern_Blue);
Patterns_PushPattern(Patterns, Pattern_Green);
}
RELOAD_STATIC_DATA(ReloadStaticData) RELOAD_STATIC_DATA(ReloadStaticData)
{ {
app_state* State = (app_state*)Context.MemoryBase; app_state* State = (app_state*)Context.MemoryBase;
@ -37,7 +16,7 @@ RELOAD_STATIC_DATA(ReloadStaticData)
State->PanelSystem.PanelDefs = GlobalPanelDefs; State->PanelSystem.PanelDefs = GlobalPanelDefs;
State->PanelSystem.PanelDefsCount = GlobalPanelDefsCount; State->PanelSystem.PanelDefsCount = GlobalPanelDefsCount;
ClearAndPushPatterns(&State->Patterns); US_LoadPatterns(&State->UserSpaceDesc, State, Context);
} }
INITIALIZE_APPLICATION(InitializeApplication) INITIALIZE_APPLICATION(InitializeApplication)
@ -53,8 +32,11 @@ INITIALIZE_APPLICATION(InitializeApplication)
State->CommandQueue = CommandQueue_Create(&State->Permanent, 32); State->CommandQueue = CommandQueue_Create(&State->Permanent, 32);
State->Patterns = Patterns_Create(&State->Permanent, 32); animation_system_desc AnimSysDesc = {};
ClearAndPushPatterns(&State->Patterns); AnimSysDesc.Storage = &State->Permanent;
AnimSysDesc.AnimArrayCount = 32;
AnimSysDesc.SecondsPerFrame = 1.0f / 24.0f;
State->AnimationSystem = AnimationSystem_Init(AnimSysDesc);
interface_config IConfig = {0}; interface_config IConfig = {0};
IConfig.FontSize = 14; IConfig.FontSize = 14;
@ -81,19 +63,10 @@ INITIALIZE_APPLICATION(InitializeApplication)
PanelSystem_PushPanel(&State->PanelSystem, PanelType_SculptureView, State, Context); PanelSystem_PushPanel(&State->PanelSystem, PanelType_SculptureView, State, Context);
State->Modes = OperationModeSystemInit(&State->Permanent, Context.ThreadContext); State->Modes = OperationModeSystemInit(&State->Permanent, Context.ThreadContext);
State->UserSpaceDesc = BlumenLumen_UserSpaceCreate();
ReloadStaticData(Context, GlobalDebugServices); ReloadStaticData(Context, GlobalDebugServices);
US_CustomInit(&State->UserSpaceDesc, State, Context);
animation_system_desc AnimSysDesc = {};
AnimSysDesc.Storage = &State->Permanent;
AnimSysDesc.AnimArrayCount = 32;
AnimSysDesc.SecondsPerFrame = 1.0f / 24.0f;
State->AnimationSystem = AnimationSystem_Init(AnimSysDesc);
State->UserData = BlumenLumen_CustomInit(State, Context);
// TEMP
blumen_lumen_state* BLState = (blumen_lumen_state*)State->UserData.Memory;
return (temp_job_req*)&BLState->JobReq;
} }
UPDATE_AND_RENDER(UpdateAndRender) UPDATE_AND_RENDER(UpdateAndRender)
@ -101,6 +74,8 @@ UPDATE_AND_RENDER(UpdateAndRender)
DEBUG_TRACK_FUNCTION; DEBUG_TRACK_FUNCTION;
app_state* State = (app_state*)Context->MemoryBase; app_state* State = (app_state*)Context->MemoryBase;
OutputDebugStringA("Test");
// NOTE(Peter): We do this at the beginning because all the render commands are stored in Transient, // NOTE(Peter): We do this at the beginning because all the render commands are stored in Transient,
// and need to persist beyond the end of the UpdateAndRender call. In the release version, we won't // and need to persist beyond the end of the UpdateAndRender call. In the release version, we won't
// zero the Transient arena when we clear it so it wouldn't be a problem, but it is technically // zero the Transient arena when we clear it so it wouldn't be a problem, but it is technically
@ -117,10 +92,10 @@ UPDATE_AND_RENDER(UpdateAndRender)
&State->LedSystem, &State->LedSystem,
State->Patterns, State->Patterns,
State->Transient, State->Transient,
State->UserData.Memory); State->UserSpaceDesc.UserData.Memory);
} }
BlumenLumen_CustomUpdate(State->UserData, State, Context); US_CustomUpdate(&State->UserSpaceDesc, State, Context);
AssemblyDebug_OverrideOutput(State->AssemblyDebugState, AssemblyDebug_OverrideOutput(State->AssemblyDebugState,
State->Assemblies, State->Assemblies,

View File

@ -41,6 +41,7 @@ typedef struct panel panel;
#include "engine/animation/foldhaus_animation_serializer.cpp" #include "engine/animation/foldhaus_animation_serializer.cpp"
#include "engine/animation/foldhaus_animation_renderer.cpp" #include "engine/animation/foldhaus_animation_renderer.cpp"
#include "engine/user_space.h"
#include "blumen_lumen.h" #include "blumen_lumen.h"
struct app_state struct app_state
@ -70,15 +71,15 @@ struct app_state
panel_system PanelSystem; panel_system PanelSystem;
panel* HotPanel; panel* HotPanel;
// User Space user_space_desc UserSpaceDesc;
//
gs_data UserData;
}; };
internal void OpenColorPicker(app_state* State, v4* Address); internal void OpenColorPicker(app_state* State, v4* Address);
#include "engine/assembly/foldhaus_assembly.cpp" #include "engine/assembly/foldhaus_assembly.cpp"
#include "engine/user_space.cpp"
#include "patterns/blumen_patterns.h" #include "patterns/blumen_patterns.h"
#include "blumen_lumen.cpp" #include "blumen_lumen.cpp"

View File

@ -5,10 +5,10 @@
// //
#ifndef FOLDHAUS_PLATFORM_H #ifndef FOLDHAUS_PLATFORM_H
// TODO Remove
#include <math.h>
#include <windows.h> #include <windows.h>
#include <math.h> // TODO Remove
#include "..\gs_libs\gs_types.h" #include "..\gs_libs\gs_types.h"
#include "..\gs_libs\gs_types.cpp" #include "..\gs_libs\gs_types.cpp"
@ -66,7 +66,7 @@ struct packet_ringbuffer
u32 WriteHead; u32 WriteHead;
}; };
#define INITIALIZE_APPLICATION(name) temp_job_req* name(context Context) #define INITIALIZE_APPLICATION(name) void name(context Context)
typedef INITIALIZE_APPLICATION(initialize_application); typedef INITIALIZE_APPLICATION(initialize_application);
#define UPDATE_AND_RENDER(name) void name(context* Context, input_queue InputQueue, render_command_buffer* RenderBuffer, addressed_data_buffer_list* OutputData) #define UPDATE_AND_RENDER(name) void name(context* Context, input_queue InputQueue, render_command_buffer* RenderBuffer, addressed_data_buffer_list* OutputData)