2023-06-17 17:00:55 +00:00
|
|
|
#include "vn_platform.h"
|
|
|
|
#include "vn_platform.cpp"
|
|
|
|
|
2023-07-19 15:09:41 +00:00
|
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
|
|
#include "third_party/stb_image.h"
|
2023-06-19 17:12:26 +00:00
|
|
|
|
2023-07-19 15:09:41 +00:00
|
|
|
#if VN_INTERNAL
|
2023-06-19 17:12:26 +00:00
|
|
|
struct debug_settings
|
|
|
|
{
|
2023-12-23 07:27:22 +00:00
|
|
|
b32 RenderUIDebugRects;
|
|
|
|
b32 RenderFPSCounter;
|
|
|
|
b32 ListHotAndActive;
|
|
|
|
b32 ShowWelcomeMessage;
|
2023-06-19 17:12:26 +00:00
|
|
|
};
|
|
|
|
|
2023-08-06 10:35:09 +00:00
|
|
|
global debug_settings *DEBUG_DebugSettings = 0;
|
2023-06-19 17:12:26 +00:00
|
|
|
#endif
|
|
|
|
|
2023-10-29 10:00:34 +00:00
|
|
|
#include "generated/vn_character.meta.h"
|
|
|
|
|
2023-12-07 15:50:57 +00:00
|
|
|
#include "vn_asset.h"
|
2023-06-19 17:12:26 +00:00
|
|
|
#include "vn_tokenizer.h"
|
2023-07-19 15:09:41 +00:00
|
|
|
#include "vn_config.h"
|
2023-06-17 17:00:55 +00:00
|
|
|
#include "vn_font.h"
|
|
|
|
#include "vn_text_op.h"
|
|
|
|
#include "vn_ui.h"
|
2023-06-27 14:14:28 +00:00
|
|
|
#include "vn_ui_utils.h"
|
2024-01-20 11:18:57 +00:00
|
|
|
#include "vn_scene2.h"
|
2023-08-22 03:19:51 +00:00
|
|
|
#include "vn_scene_view.h"
|
2023-06-17 17:00:55 +00:00
|
|
|
#include "vn_animation_curve.h"
|
2023-07-24 13:50:57 +00:00
|
|
|
#include "vn_theme_dark.h"
|
2023-06-17 17:00:55 +00:00
|
|
|
|
2023-10-29 10:00:34 +00:00
|
|
|
#if VN_INTERNAL
|
|
|
|
#include "vn_workspace.h"
|
2023-12-23 07:27:22 +00:00
|
|
|
#include "vn_debug_info.h"
|
|
|
|
|
|
|
|
global vn_render_commands *GlobalRenderCommands = 0;
|
2023-10-29 10:00:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "generated/vn_character.meta.c"
|
|
|
|
|
2023-12-07 15:50:57 +00:00
|
|
|
#include "vn_asset.cpp"
|
2023-07-19 15:09:41 +00:00
|
|
|
#include "vn_tokenizer.cpp"
|
2023-06-18 10:09:36 +00:00
|
|
|
#include "vn_config.cpp"
|
2023-06-17 17:00:55 +00:00
|
|
|
#include "vn_render.cpp"
|
|
|
|
#include "vn_font.cpp"
|
|
|
|
#include "vn_ui.cpp"
|
|
|
|
#include "vn_ui_utils.cpp"
|
|
|
|
#include "vn_animation_curve.cpp"
|
2024-01-20 11:18:57 +00:00
|
|
|
#include "vn_scene2.cpp"
|
2023-08-22 03:19:51 +00:00
|
|
|
#include "vn_scene_view.cpp"
|
2023-10-29 10:00:34 +00:00
|
|
|
|
|
|
|
#if VN_INTERNAL
|
2023-08-22 03:19:51 +00:00
|
|
|
#include "vn_workspace.cpp"
|
2023-12-23 07:27:22 +00:00
|
|
|
#include "vn_debug_info.cpp"
|
2023-10-29 10:00:34 +00:00
|
|
|
#endif
|
2023-06-17 17:00:55 +00:00
|
|
|
|
|
|
|
struct vn_state
|
|
|
|
{
|
2023-12-23 07:27:22 +00:00
|
|
|
arena *Arena;
|
|
|
|
arena *FrameArena;
|
|
|
|
|
|
|
|
assets Assets;
|
|
|
|
|
|
|
|
glyph_atlas *GlyphAtlas;
|
|
|
|
|
|
|
|
config *Config;
|
|
|
|
|
|
|
|
ui UI;
|
|
|
|
animation_curve_state AnimationCurveState;
|
|
|
|
b32 EditorMode;
|
|
|
|
|
|
|
|
scene_view SceneView;
|
|
|
|
|
2023-06-19 17:12:26 +00:00
|
|
|
#if VN_INTERNAL
|
2023-12-23 07:27:22 +00:00
|
|
|
debug_info *DebugInfo;
|
|
|
|
workspace Workspace;
|
|
|
|
debug_settings DebugSettings;
|
2023-06-19 17:12:26 +00:00
|
|
|
#endif
|
2023-06-17 17:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
VN_UPDATE_AND_RENDER(VN_UpdateAndRender)
|
|
|
|
{
|
2023-12-23 07:27:22 +00:00
|
|
|
SetThreadContext(ThreadContext);
|
|
|
|
Platform = Memory->PlatformAPI;
|
|
|
|
|
2023-06-19 17:12:26 +00:00
|
|
|
#if VN_INTERNAL
|
2023-12-23 07:27:22 +00:00
|
|
|
GlobalRenderCommands = RenderCommands;
|
2023-06-19 17:12:26 +00:00
|
|
|
#endif
|
2023-12-23 07:27:22 +00:00
|
|
|
|
|
|
|
vn_state *State = Memory->State;
|
|
|
|
|
|
|
|
//- sixten: initialize application state
|
|
|
|
if(!Memory->State)
|
|
|
|
{
|
2024-01-20 11:18:57 +00:00
|
|
|
arena *Arena = ArenaAlloc(Kilobytes(24), true, "VN State Arena");
|
2023-12-23 07:27:22 +00:00
|
|
|
State = Memory->State = PushStruct(Arena, vn_state);
|
|
|
|
State->Arena = Arena;
|
2024-01-20 11:18:57 +00:00
|
|
|
State->FrameArena = ArenaAlloc(Kilobytes(1), true, "VN Frame Arena");
|
2023-12-23 07:27:22 +00:00
|
|
|
|
2024-01-20 11:18:57 +00:00
|
|
|
State->GlyphAtlas = F_CreateGlyphAtlas(RenderCommands, 2048, 128);
|
2023-12-23 07:27:22 +00:00
|
|
|
State->Config = CreateConfig();
|
|
|
|
|
|
|
|
//- sixten: load assets
|
|
|
|
State->Assets.AllocateTexture = RenderCommands->AllocateTexture;
|
|
|
|
LoadPermanentAssets(&State->Assets);
|
|
|
|
|
|
|
|
//- sixten: setup config binds and load current config
|
|
|
|
{
|
|
|
|
Config_BindS32(State->Config, StrLit("Platform/RefreshRate"), &Input->RefreshRate, 60);
|
2023-10-29 10:00:34 +00:00
|
|
|
#if VN_INTERNAL
|
2023-12-23 07:27:22 +00:00
|
|
|
State->DebugInfo = DI_DebugInfoAlloc();
|
|
|
|
|
|
|
|
DEBUG_DebugSettings = &State->DebugSettings;
|
|
|
|
Config_BindB32(State->Config, StrLit("Dev/RenderUIDebugRects"), &DEBUG_DebugSettings->RenderUIDebugRects, 0);
|
|
|
|
Config_BindB32(State->Config, StrLit("Dev/RenderFPSCounter"), &DEBUG_DebugSettings->RenderFPSCounter, 0);
|
|
|
|
Config_BindB32(State->Config, StrLit("Dev/ListHotAndActive"), &DEBUG_DebugSettings->ListHotAndActive, 0);
|
|
|
|
Config_BindB32(State->Config, StrLit("Dev/ShowWelcomeMessage"), &DEBUG_DebugSettings->ShowWelcomeMessage, 1);
|
2023-10-29 10:00:34 +00:00
|
|
|
#endif
|
2023-12-23 07:27:22 +00:00
|
|
|
|
|
|
|
Config_ReadFile(State->Config, StrLit("config.vn"));
|
|
|
|
}
|
|
|
|
|
2024-01-20 11:18:57 +00:00
|
|
|
SV_Init(&State->SceneView);
|
2023-12-23 07:27:22 +00:00
|
|
|
UI_Init(&State->UI);
|
|
|
|
AC_Init(&State->AnimationCurveState);
|
|
|
|
|
2023-06-19 17:12:26 +00:00
|
|
|
#if VN_INTERNAL
|
2023-12-23 07:27:22 +00:00
|
|
|
W_Init(&State->Workspace);
|
2023-06-19 17:12:26 +00:00
|
|
|
#endif
|
2024-01-20 11:18:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
//- sixten: load startup scene
|
|
|
|
temp Scratch = GetScratch();
|
2024-01-21 20:01:00 +00:00
|
|
|
compiled_scene2 Scene = S2_CompiledFromString(Scratch.Arena, Platform_ReadEntireFile(Scratch.Arena, StrLit("data/omori.vns")));
|
2024-01-20 11:18:57 +00:00
|
|
|
SV_SetCurrentSource(&Scene);
|
|
|
|
ReleaseScratch(Scratch);
|
|
|
|
|
2023-12-23 07:27:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-29 10:00:34 +00:00
|
|
|
#if VN_INTERNAL
|
2023-12-23 07:27:22 +00:00
|
|
|
DI_BeginFrame(State->DebugInfo);
|
|
|
|
DEBUG_DebugSettings = &State->DebugSettings;
|
2023-10-29 10:00:34 +00:00
|
|
|
#endif
|
2023-12-23 07:27:22 +00:00
|
|
|
|
|
|
|
//- sixten: begin new frame
|
|
|
|
ArenaClear(State->FrameArena);
|
|
|
|
SetAssets(&State->Assets);
|
|
|
|
AC_NewFrame(&State->AnimationCurveState, Input->dtForFrame);
|
|
|
|
UI_NewFrame(&State->UI, Input->EventList, Input->MouseP, Input->dtForFrame, State->GlyphAtlas);
|
|
|
|
SV_NewFrame(&State->SceneView, Input->EventList, Input->dtForFrame);
|
|
|
|
|
|
|
|
//- sixten: check for toggle between modes
|
|
|
|
if(Platform_KeyPress(Input->EventList, Key_Return, PlatformModifier_Ctrl))
|
|
|
|
{
|
|
|
|
State->EditorMode = !State->EditorMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
//- sixten: update the scene
|
|
|
|
SV_Update(State->FrameArena);
|
|
|
|
|
|
|
|
//- sixten: build the ui
|
|
|
|
UI_BeginBuild(RenderCommands->RenderDim);
|
|
|
|
{
|
2023-10-29 10:00:34 +00:00
|
|
|
#if VN_INTERNAL
|
2023-12-23 07:27:22 +00:00
|
|
|
DI_BuildInfo();
|
|
|
|
if(State->EditorMode)
|
|
|
|
{
|
|
|
|
W_Update(&State->Workspace, RenderCommands, Input, State->GlyphAtlas);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-29 10:00:34 +00:00
|
|
|
#endif
|
2023-12-23 07:27:22 +00:00
|
|
|
SV_BuildSceneView(Input);
|
|
|
|
#if VN_INTERNAL
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
UI_EndBuild();
|
|
|
|
|
|
|
|
|
|
|
|
//- sixten: consume all remaining evetns
|
|
|
|
for(platform_event *Event = Input->EventList->First;
|
2023-12-26 08:11:41 +00:00
|
|
|
Event != 0;
|
|
|
|
Event = Event->Next)
|
2023-12-23 07:27:22 +00:00
|
|
|
{
|
|
|
|
if(Event->Type == PlatformEvent_WindowClose)
|
|
|
|
{
|
|
|
|
Config_WriteFile(State->Config, StrLit("config.vn"));
|
|
|
|
Input->ExitRequested = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Platform_ConsumeEvent(Input->EventList, Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//- sixten: render the frame
|
|
|
|
{
|
|
|
|
render_group Group = BeginRenderGroup(RenderCommands);
|
2024-01-20 11:18:57 +00:00
|
|
|
PushClear(&Group, V3R32(0.1, 0.1, 0.1));
|
2023-12-23 07:27:22 +00:00
|
|
|
|
|
|
|
UI_RenderFrame(&Group, State->GlyphAtlas);
|
|
|
|
|
2023-12-26 08:11:41 +00:00
|
|
|
#if VN_INTERNAL
|
|
|
|
r32 DEBUGDisplayOffsetY = 20;
|
2023-12-23 07:27:22 +00:00
|
|
|
if(DEBUG_DebugSettings->ListHotAndActive)
|
|
|
|
{
|
2024-01-20 11:18:57 +00:00
|
|
|
PushText(&Group, State->GlyphAtlas, Font_Regular, V2R32(5, RenderCommands->RenderDim.y - DEBUGDisplayOffsetY), 15, Color_Grey,
|
2023-12-26 08:11:41 +00:00
|
|
|
PushFormat(State->UI.FrameArena, "Hot: %S:%llu", UI_BoxStringFromKey(UI_HotKey()), UI_HotKey()));
|
|
|
|
DEBUGDisplayOffsetY += 20;
|
2024-01-20 11:18:57 +00:00
|
|
|
PushText(&Group, State->GlyphAtlas, Font_Regular, V2R32(5, RenderCommands->RenderDim.y - DEBUGDisplayOffsetY), 15, Color_Grey,
|
2023-12-26 08:11:41 +00:00
|
|
|
PushFormat(State->UI.FrameArena, "Active: %S:%llu", UI_BoxStringFromKey(UI_ActiveKey()), UI_ActiveKey()));
|
|
|
|
DEBUGDisplayOffsetY += 20;
|
2023-12-23 07:27:22 +00:00
|
|
|
}
|
2023-12-26 08:11:41 +00:00
|
|
|
|
|
|
|
if(DEBUG_DebugSettings->RenderFPSCounter)
|
|
|
|
{
|
2024-01-20 11:18:57 +00:00
|
|
|
PushText(&Group, State->GlyphAtlas, Font_Regular, V2R32(5, RenderCommands->RenderDim.y - DEBUGDisplayOffsetY), 15, Color_Grey,
|
2023-12-26 08:11:41 +00:00
|
|
|
PushFormat(State->UI.FrameArena, "FPS: %.2f", 1.0f/Input->dtForFrame));
|
|
|
|
DEBUGDisplayOffsetY += 20;
|
|
|
|
|
|
|
|
}
|
2023-12-23 07:27:22 +00:00
|
|
|
#endif
|
2023-12-26 08:11:41 +00:00
|
|
|
|
2023-12-23 07:27:22 +00:00
|
|
|
#if VN_INTERNAL
|
2023-12-26 08:11:41 +00:00
|
|
|
DI_EndFrame();
|
2023-10-29 10:00:34 +00:00
|
|
|
#endif
|
2023-12-26 08:11:41 +00:00
|
|
|
|
2023-12-23 07:27:22 +00:00
|
|
|
}
|
2023-06-17 17:00:55 +00:00
|
|
|
}
|