Start of config implementation
parent
539949d396
commit
1fa199512d
10
code/vn.cpp
10
code/vn.cpp
|
@ -1,6 +1,7 @@
|
||||||
#include "vn_platform.h"
|
#include "vn_platform.h"
|
||||||
#include "vn_platform.cpp"
|
#include "vn_platform.cpp"
|
||||||
|
|
||||||
|
#include "vn_config.h"
|
||||||
#include "vn_font.h"
|
#include "vn_font.h"
|
||||||
#include "vn_text_op.h"
|
#include "vn_text_op.h"
|
||||||
#include "vn_ui.h"
|
#include "vn_ui.h"
|
||||||
|
@ -8,6 +9,7 @@
|
||||||
#include "vn_theme_dark.h"
|
#include "vn_theme_dark.h"
|
||||||
#include "vn_animation_curve.h"
|
#include "vn_animation_curve.h"
|
||||||
|
|
||||||
|
#include "vn_config.cpp"
|
||||||
#include "vn_render.cpp"
|
#include "vn_render.cpp"
|
||||||
#include "vn_font.cpp"
|
#include "vn_font.cpp"
|
||||||
#include "vn_ui.cpp"
|
#include "vn_ui.cpp"
|
||||||
|
@ -20,6 +22,8 @@ struct vn_state
|
||||||
memory_arena Arena;
|
memory_arena Arena;
|
||||||
glyph_atlas *GlyphAtlas;
|
glyph_atlas *GlyphAtlas;
|
||||||
|
|
||||||
|
config *Config;
|
||||||
|
|
||||||
ui UI;
|
ui UI;
|
||||||
workspace Workspace;
|
workspace Workspace;
|
||||||
animation_curve_state AnimationCurveState;
|
animation_curve_state AnimationCurveState;
|
||||||
|
@ -37,8 +41,9 @@ VN_UPDATE_AND_RENDER(VN_UpdateAndRender)
|
||||||
State = Memory->State = BootstrapPushStruct(vn_state, Arena);
|
State = Memory->State = BootstrapPushStruct(vn_state, Arena);
|
||||||
|
|
||||||
State->GlyphAtlas = CreateGlyphAtlas(RenderCommands);
|
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);
|
Workspace_Init(&State->Workspace);
|
||||||
}
|
}
|
||||||
|
@ -47,8 +52,7 @@ VN_UPDATE_AND_RENDER(VN_UpdateAndRender)
|
||||||
UI_NewFrame(&State->UI, Input->EventList, Input->MouseP);
|
UI_NewFrame(&State->UI, Input->EventList, Input->MouseP);
|
||||||
|
|
||||||
Workspace_Update(&State->Workspace, RenderCommands, Input, State->GlyphAtlas);
|
Workspace_Update(&State->Workspace, RenderCommands, Input, State->GlyphAtlas);
|
||||||
// sixten(NOTE): This allows us to check for
|
UI_SignalFromBox(UI_GetState()->ContainerNode); // sixten(TODO): Move elsewhere.
|
||||||
UI_SignalFromBox(UI_GetState()->ContainerNode);
|
|
||||||
|
|
||||||
for(platform_event *Event = Input->EventList->First;
|
for(platform_event *Event = Input->EventList->First;
|
||||||
Event != 0;
|
Event != 0;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -3,27 +3,40 @@
|
||||||
#ifndef VN_CONFIG_H
|
#ifndef VN_CONFIG_H
|
||||||
#define VN_CONFIG_H
|
#define VN_CONFIG_H
|
||||||
|
|
||||||
|
enum config_entry_type
|
||||||
|
{
|
||||||
|
Config_Entry_S32,
|
||||||
|
Config_Entry_S64,
|
||||||
|
Config_Entry_B32,
|
||||||
|
};
|
||||||
|
|
||||||
struct config_entry
|
struct config_entry
|
||||||
{
|
{
|
||||||
string Name;
|
string Name;
|
||||||
buffer Target;
|
void *Target;
|
||||||
|
config_entry_type Type;
|
||||||
|
|
||||||
config_entry *Next;
|
config_entry *Next;
|
||||||
config_entry *Prev;
|
config_entry *Prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct config
|
struct config_entry_bucket
|
||||||
{
|
{
|
||||||
memory_arena Arena;
|
|
||||||
|
|
||||||
config_entry *First;
|
config_entry *First;
|
||||||
config_entry *Last;
|
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_ReadFile(config *Config, string Path);
|
||||||
static void Config_WriteFile(config *Config);
|
static void Config_WriteFile(config *Config);
|
||||||
|
|
||||||
static void Config_AddEntry(config *Config, string Name, buffer Target);
|
static void Config_BindEntry(config *Config, string Name, config_entry_type, void *Target);
|
||||||
static void Config_AddS64(config *Config, string Name, s64 *Target);
|
|
||||||
|
|
||||||
#endif //VN_CONFIG_H
|
#endif //VN_CONFIG_H
|
||||||
|
|
|
@ -200,7 +200,7 @@ struct vn_input
|
||||||
r32 dtForFrame;
|
r32 dtForFrame;
|
||||||
|
|
||||||
// sixten: Application to platform
|
// sixten: Application to platform
|
||||||
s32 TargetRefreshRate;
|
s32 RefreshRate;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vn_memory
|
struct vn_memory
|
||||||
|
|
|
@ -240,7 +240,7 @@ static void Workspace_BuildSettingsTabButton(workspace_view_settings *Settings,
|
||||||
{
|
{
|
||||||
Platform.SetCursor(PlatformCursor_Hand);
|
Platform.SetCursor(PlatformCursor_Hand);
|
||||||
}
|
}
|
||||||
if(Signal.Clicked)
|
if(Signal.Pressed)
|
||||||
{
|
{
|
||||||
Settings->Category = Category;
|
Settings->Category = Category;
|
||||||
}
|
}
|
||||||
|
@ -420,6 +420,7 @@ static void Workspace_BuildView(workspace *Workspace, workspace_view *View)
|
||||||
r32 ViewHighlightTransition =
|
r32 ViewHighlightTransition =
|
||||||
AnimationCurve_AnimateValueF(Workspace_ViewIsCurrent(Workspace, View), 0, 0.25, "Workspace View Highlight %p", View);
|
AnimationCurve_AnimateValueF(Workspace_ViewIsCurrent(Workspace, View), 0, 0.25, "Workspace View Highlight %p", View);
|
||||||
UI_SetNextBorderColor(LinearBlend(Theme_BorderColor, Theme_HighlightBorderColor, ViewHighlightTransition));
|
UI_SetNextBorderColor(LinearBlend(Theme_BorderColor, Theme_HighlightBorderColor, ViewHighlightTransition));
|
||||||
|
UI_SetNextBackgroundColor(Theme_BackgroundColor);
|
||||||
UI_SetNextCornerRadius(3);
|
UI_SetNextCornerRadius(3);
|
||||||
|
|
||||||
ui_box *ViewBox = UI_MakeBoxF(UI_BoxFlag_Clickable |
|
ui_box *ViewBox = UI_MakeBoxF(UI_BoxFlag_Clickable |
|
||||||
|
|
|
@ -658,17 +658,17 @@ int WinMain(HINSTANCE Instance, HINSTANCE PreviousInstance, LPSTR CommandLine, i
|
||||||
LoadedCode.UpdateAndRender(&ThreadContext, &Memory, &Input, &RenderCommands);
|
LoadedCode.UpdateAndRender(&ThreadContext, &Memory, &Input, &RenderCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
b32 UseVSync = (Input.TargetRefreshRate == 0);
|
b32 UseVSync = (Input.RefreshRate == 0);
|
||||||
wglSwapIntervalEXT(UseVSync);
|
wglSwapIntervalEXT(UseVSync);
|
||||||
|
|
||||||
OpenGL_EndFrame(&OpenGLContext, &RenderCommands);
|
OpenGL_EndFrame(&OpenGLContext, &RenderCommands);
|
||||||
wglSwapLayerBuffers(DeviceContext, WGL_SWAP_MAIN_PLANE);
|
wglSwapLayerBuffers(DeviceContext, WGL_SWAP_MAIN_PLANE);
|
||||||
}
|
}
|
||||||
|
|
||||||
b32 ShouldLimitFrameRate = (Input.TargetRefreshRate > 0);
|
b32 ShouldLimitFrameRate = (Input.RefreshRate > 0);
|
||||||
if(ShouldLimitFrameRate)
|
if(ShouldLimitFrameRate)
|
||||||
{
|
{
|
||||||
Win32_EnforceFrameRate(CurrentTime, Input.TargetRefreshRate);
|
Win32_EnforceFrameRate(CurrentTime, Input.RefreshRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue