Start of config implementation

main
sixten.hugosson 2023-06-18 12:09:36 +02:00
parent 539949d396
commit 1fa199512d
6 changed files with 80 additions and 14 deletions

View File

@ -1,6 +1,7 @@
#include "vn_platform.h"
#include "vn_platform.cpp"
#include "vn_config.h"
#include "vn_font.h"
#include "vn_text_op.h"
#include "vn_ui.h"
@ -8,6 +9,7 @@
#include "vn_theme_dark.h"
#include "vn_animation_curve.h"
#include "vn_config.cpp"
#include "vn_render.cpp"
#include "vn_font.cpp"
#include "vn_ui.cpp"
@ -20,6 +22,8 @@ struct vn_state
memory_arena Arena;
glyph_atlas *GlyphAtlas;
config *Config;
ui UI;
workspace Workspace;
animation_curve_state AnimationCurveState;
@ -37,8 +41,9 @@ VN_UPDATE_AND_RENDER(VN_UpdateAndRender)
State = Memory->State = BootstrapPushStruct(vn_state, Arena);
State->GlyphAtlas = CreateGlyphAtlas(RenderCommands);
State->Config = BootstrapPushStruct(config, Arena);
//Config_AddS64(&State->Config, StrLit("Platform/RefreshRate"), &Input->RefreshRate);
Config_BindEntry(State->Config, StrLit("Platform/RefreshRate"), Config_Entry_S32, &Input->RefreshRate);
Workspace_Init(&State->Workspace);
}
@ -47,8 +52,7 @@ VN_UPDATE_AND_RENDER(VN_UpdateAndRender)
UI_NewFrame(&State->UI, Input->EventList, Input->MouseP);
Workspace_Update(&State->Workspace, RenderCommands, Input, State->GlyphAtlas);
// sixten(NOTE): This allows us to check for
UI_SignalFromBox(UI_GetState()->ContainerNode);
UI_SignalFromBox(UI_GetState()->ContainerNode); // sixten(TODO): Move elsewhere.
for(platform_event *Event = Input->EventList->First;
Event != 0;

View File

@ -0,0 +1,48 @@
static config_entry *Config_FindEntryByName(config *Config, string Name)
{
config_entry *Result = 0;
u32 BucketSlot = HashString(Name) % ArrayCount(Config->EntryBuckets);
config_entry_bucket *Bucket = Config->EntryBuckets + BucketSlot;
for(config_entry *Entry = Bucket->First;
Entry != 0;
Entry = Entry->Next)
{
if(AreEqual(Entry->Name, Name))
{
Result = Entry;
break;
}
}
return(Result);
}
static void Config_ReadFile(config *Config, string Path)
{
}
static void Config_WriteFile(config *Config)
{
}
static void Config_BindEntry(config *Config, string Name, config_entry_type Type, void *Target)
{
config_entry *Entry = Config_FindEntryByName(Config, Name);
if(!Entry)
{
Entry = PushStruct(&Config->Arena, config_entry);
Entry->Name = Name;
Entry->Type = Type;
u32 BucketSlot = HashString(Name) % ArrayCount(Config->EntryBuckets);
config_entry_bucket *Bucket = Config->EntryBuckets + BucketSlot;
DLLInsertLast(Bucket->First, Bucket->Last, Entry);
}
Assert(Entry->Type == Type);
Entry->Target = Target;
}

View File

@ -3,27 +3,40 @@
#ifndef VN_CONFIG_H
#define VN_CONFIG_H
enum config_entry_type
{
Config_Entry_S32,
Config_Entry_S64,
Config_Entry_B32,
};
struct config_entry
{
string Name;
buffer Target;
void *Target;
config_entry_type Type;
config_entry *Next;
config_entry *Prev;
};
struct config
struct config_entry_bucket
{
memory_arena Arena;
config_entry *First;
config_entry *Last;
};
struct config
{
memory_arena Arena;
config_entry_bucket EntryBuckets[32];
};
static config_entry *Config_FindEntryByName(config *Config, string Name);
static void Config_ReadFile(config *Config, string Path);
static void Config_WriteFile(config *Config);
static void Config_AddEntry(config *Config, string Name, buffer Target);
static void Config_AddS64(config *Config, string Name, s64 *Target);
static void Config_BindEntry(config *Config, string Name, config_entry_type, void *Target);
#endif //VN_CONFIG_H

View File

@ -200,7 +200,7 @@ struct vn_input
r32 dtForFrame;
// sixten: Application to platform
s32 TargetRefreshRate;
s32 RefreshRate;
};
struct vn_memory

View File

@ -240,7 +240,7 @@ static void Workspace_BuildSettingsTabButton(workspace_view_settings *Settings,
{
Platform.SetCursor(PlatformCursor_Hand);
}
if(Signal.Clicked)
if(Signal.Pressed)
{
Settings->Category = Category;
}
@ -420,6 +420,7 @@ static void Workspace_BuildView(workspace *Workspace, workspace_view *View)
r32 ViewHighlightTransition =
AnimationCurve_AnimateValueF(Workspace_ViewIsCurrent(Workspace, View), 0, 0.25, "Workspace View Highlight %p", View);
UI_SetNextBorderColor(LinearBlend(Theme_BorderColor, Theme_HighlightBorderColor, ViewHighlightTransition));
UI_SetNextBackgroundColor(Theme_BackgroundColor);
UI_SetNextCornerRadius(3);
ui_box *ViewBox = UI_MakeBoxF(UI_BoxFlag_Clickable |

View File

@ -658,17 +658,17 @@ int WinMain(HINSTANCE Instance, HINSTANCE PreviousInstance, LPSTR CommandLine, i
LoadedCode.UpdateAndRender(&ThreadContext, &Memory, &Input, &RenderCommands);
}
b32 UseVSync = (Input.TargetRefreshRate == 0);
b32 UseVSync = (Input.RefreshRate == 0);
wglSwapIntervalEXT(UseVSync);
OpenGL_EndFrame(&OpenGLContext, &RenderCommands);
wglSwapLayerBuffers(DeviceContext, WGL_SWAP_MAIN_PLANE);
}
b32 ShouldLimitFrameRate = (Input.TargetRefreshRate > 0);
b32 ShouldLimitFrameRate = (Input.RefreshRate > 0);
if(ShouldLimitFrameRate)
{
Win32_EnforceFrameRate(CurrentTime, Input.TargetRefreshRate);
Win32_EnforceFrameRate(CurrentTime, Input.RefreshRate);
}
}
}