summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2022-12-22 13:29:02 -0500
committerFox Caminiti <fox@foxcam.net>2022-12-22 13:29:02 -0500
commit375c120d30456738897c4bd775e38aa1db7d239c (patch)
tree5b365a6233cf736db15fa52fcfac4ba80a986217 /src/main.cpp
parent4854647d659f75ac6cf4575b61d1dcfd25865791 (diff)
v3.1
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp74
1 files changed, 49 insertions, 25 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 1b13405..88bc3ef 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -141,6 +141,11 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_
ImGui::NewFrame();
+ ImGuiID DockID = ImGui::DockSpaceOverViewport(ImGui::GetMainViewport(), ImGuiDockNodeFlags_AutoHideTabBar);
+ if (State->FirstFrame) {
+ ImGui::MyWindowSetup(DockID);
+ }
+
if (State->Warp_WantSetPos) {
ImGui_WarpMouseFinish(State, io.MousePos);
io.MouseDelta = {};
@@ -150,7 +155,12 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_
if (!io.WantCaptureKeyboard)
ImGui_ProcessInputs(File, State, UI, Memory, io, Sorted);
- ImGui::DockSpaceOverViewport();
+ // The windows don't seem to draw properly on the frame after startup, so
+ // we need to delay a bit.
+ if (State->FirstFrame) {
+ ImGui::EndFrame();
+ return;
+ }
#if DEBUG
if (Debug.ToggleWindow) {
@@ -163,8 +173,8 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_
ImGui_Viewport(File, State, UI, Memory, io, textureID, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyArray);
ImGui_Timeline(File, State, Memory, UI, io, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyStart, Sorted.PropertyArray);
- ImGui_File(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray);
ImGui_PropertiesPanel(File, State, UI, Memory, io, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyStart, Sorted.PropertyArray);
+ ImGui_File(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray);
ImGui_ColorPanel(File, State, UI, Memory, io);
ImGui_EffectsPanel(File, State, Memory, UI, io);
#if STABLE
@@ -295,12 +305,15 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
int32 Frame_Start = Layer->Frame_Start;
int32 Frame_End = Layer->Frame_End;
+ int32 Frame_Offset = Layer->Frame_Offset;
if (Layer->IsSelected)
- Interact_Evaluate_Layer(Memory, State, Index_Physical, *SortedCompStart, SortedLayerStart, &Frame_Start, &Frame_End);
- int FrameToSeek = State->Frame_Current - Frame_Start;
+ Interact_Evaluate_Layer(Memory, State, Index_Physical, *SortedCompStart, SortedLayerStart, &Frame_Start, &Frame_End, &Frame_Offset);
+ int32 Frame_Start_Abs = Frame_Start + Frame_Offset;
+ int32 Frame_End_Abs = Frame_End + Frame_Offset;
+ int FrameToSeek = State->Frame_Current - Frame_Start_Abs;
- if (Frame_Start <= Frame_Current &&
- Frame_End > Frame_Current && Layer->IsVisible)
+ if (Frame_Start_Abs <= Frame_Current &&
+ Frame_End_Abs > Frame_Current && Layer->IsVisible)
{
if (State->UpdateKeyframes) {
sorted_property_array *SortedLayerProperties = SortedPropertyStart + SortEntry.SortedPropertyStart;
@@ -324,12 +337,15 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
int32 Frame_Start = Layer->Frame_Start;
int32 Frame_End = Layer->Frame_End;
+ int32 Frame_Offset = Layer->Frame_Offset;
if (Layer->IsSelected)
- Interact_Evaluate_Layer(Memory, State, Index_Physical, *SortedCompStart, SortedLayerStart, &Frame_Start, &Frame_End);
- int FrameToSeek = State->Frame_Current - Frame_Start;
+ Interact_Evaluate_Layer(Memory, State, Index_Physical, *SortedCompStart, SortedLayerStart, &Frame_Start, &Frame_End, &Frame_Offset);
+ int32 Frame_Start_Abs = Frame_Start + Frame_Offset;
+ int32 Frame_End_Abs = Frame_End + Frame_Offset;
+ int FrameToSeek = State->Frame_Current - Frame_Start_Abs;
- if (Frame_Start <= Frame_Current &&
- Frame_End > Frame_Current && Layer->IsVisible)
+ if (Frame_Start_Abs <= Frame_Current &&
+ Frame_End_Abs > Frame_Current && Layer->IsVisible)
{
layer_bitmap_state *BitmapState = &State->Render.Bitmap[Index_Physical];
void *BitmapAddress = NULL;
@@ -438,8 +454,10 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
Entry_Main->CycleTime = GetCPUTime() - Comp_TimeStart;
Entry_Main->IsCached = true;
- if (CompIndex == File->PrincipalCompIndex)
+ if (CompIndex == File->PrincipalCompIndex && State->LastCachedFrame != State->Frame_Current) {
State->CachedFrameCount++;
+ State->LastCachedFrame = State->Frame_Current;
+ }
return CompBuffer;
}
@@ -488,7 +506,6 @@ Render_Blit(project_data *File, project_state *State, memory *Memory, sorted_fil
static void
Main_Renderer(project_data *File, project_state *State, memory *Memory, sorted_file Sorted, ui *UI, SDL_Window *window, GLuint textureID, ImGuiIO io)
{
- State->UpdateFrame = false;
block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex);
@@ -506,10 +523,11 @@ Main_Renderer(project_data *File, project_state *State, memory *Memory, sorted_f
// TODO(fox): garbage collect AV state!
+ State->UpdateFrame = false;
State->UpdateKeyframes = false;
-
}
+static int pp = -2;
int main(int argc, char *argv[]) {
@@ -604,7 +622,7 @@ int main(int argc, char *argv[]) {
MainComp->FPS = 60;
MainComp->BytesPerPixel = 4;
MainComp->Frame_Count = 80;
- MainComp->Frame_End = 80;
+ MainComp->Frame_End = 79;
MainComp->Occupied = 1;
MainComp->Name_String_Index = String_AddToFile(&Memory, "Main comp");
@@ -708,18 +726,12 @@ int main(int argc, char *argv[]) {
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_NavEnableSetMousePos;
(void)io;
- // NOTE(fox): Instead of constructing the position of the windows on
- // startup with Docking API calls (which is experimental and incomplete)
- // I'm loading the window positions from this convenient tool. ImGui by
- // default saves window position to an external .ini file, which can be
- // loaded from disk or memory.
+ // NOTE(fox): Window construction is done in MyWindowSetup().
#if DEBUG
- io.IniFilename = NULL;
- ImGui::LoadIniSettingsFromMemory(ImGuiPrefs);
#else
io.IniFilename = NULL;
- ImGui::LoadIniSettingsFromMemory(ImGuiPrefs);
#endif
+ // ImGui::LoadIniSettingsFromMemory(ImGuiPrefs);
// ImGui::SaveIniSettingsToDisk("imgui.ini");
ImGui::StyleColorsDark();
@@ -730,6 +742,11 @@ int main(int argc, char *argv[]) {
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
ImGui_ImplOpenGL3_Init(glsl_version);
+ // ImGuiPlatformIO &plat_io = ImGui::GetPlatformIO();
+ // printf("Scale: %.2f * 96 dpi", plat_io.Monitors[0].DpiScale);
+ // io.FontGlobalScale = plat_io.Monitors[0].DpiScale;
+ // printf("global: %.2f", io.FontGlobalScale);
+
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
@@ -748,7 +765,7 @@ int main(int argc, char *argv[]) {
#endif
#if DEBUG
-#if 1
+#if 0
sprintf(State->DummyName, "test");
File_Open(File, State, &Memory, State->DummyName);
State->UpdateFrame = true;
@@ -761,6 +778,7 @@ int main(int argc, char *argv[]) {
#endif
#endif
+
while (State->IsRunning)
{
uint64 PerfFrequency = SDL_GetPerformanceFrequency();
@@ -806,12 +824,14 @@ int main(int argc, char *argv[]) {
History_Undo(&Memory);
Memory_Cache_Purge(File, State, &Memory);
State->UpdateFrame = true;
+ State->UpdateKeyframes = true;
} break;
case hotkey_redo:
{
History_Redo(&Memory);
Memory_Cache_Purge(File, State, &Memory);
State->UpdateFrame = true;
+ State->UpdateKeyframes = true;
} break;
default:
{
@@ -832,9 +852,10 @@ int main(int argc, char *argv[]) {
State->UpdateKeyframes = true;
}
- bool32 FullyCached = (State->CachedFrameCount == (MainComp->Frame_End - MainComp->Frame_Start));
+ bool32 FullyCached = (State->CachedFrameCount == (MainComp->Frame_End - MainComp->Frame_Start + 1));
if ((State->AudioLayerIndex != -1) && FullyCached)
{
+ Assert(0);
block_layer *AudioLayer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, State->AudioLayerIndex);
av_info *AV = AV_Retrieve(State, &Memory, AudioLayer->Block_Source_Index);
int32 LayerPos = AudioLayer->Frame_Start;
@@ -858,9 +879,10 @@ int main(int argc, char *argv[]) {
int BytesToWrite = TargetAudioSize - QueuedAudioSize;
printf("%i bytes in queue.\n", QueuedAudioSize);
int BytePlayhead = 0;
+ int32 InitialFrameToSeek = State->Frame_Current - LayerPos;
while (BytePlayhead < BytesToWrite) {
uint8 *Data = (uint8 *)AudioData + BytePlayhead;
- int SampleCount = AV_AudioTest(AV, Data, AudioBufferSize - BytePlayhead);
+ int SampleCount = AV_AudioTest(AV, Data, AudioBufferSize - BytePlayhead, MainComp->FPS, InitialFrameToSeek);
int Size = SampleCount * BytesPerSample;
BytePlayhead += Size;
}
@@ -884,6 +906,8 @@ int main(int argc, char *argv[]) {
if (State->Interact_Active) {
Memory_Cache_Purge(File, State, &Memory, State->Frame_Current);
}
+ // Assert(pp != State->Frame_Current);
+ pp = State->Frame_Current;
Main_Renderer(File, State, &Memory, Sorted, &File->UI, window, textureID, io);
} else if (Item.Type == 1) {
Assert(State->Interact_Active == interact_type_brush);