summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp59
1 files changed, 44 insertions, 15 deletions
diff --git a/src/main.cpp b/src/main.cpp
index f8dd546..77a405a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -69,11 +69,14 @@ Main_RenderUI(ImGuiIO io, ImVec4 clear_color, SDL_Window *window)
SDL_GL_SwapWindow(window);
}
-static void
+// NOTE(fox): Many state changes require the frame after the input event to be rendered.
+
+static bool32
Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_file Sorted, ui *UI, SDL_Window *window, GLuint textureID)
{
ImGuiIO& io = ImGui::GetIO();
SDL_Event event = {};
+ int test = 0;
while (SDL_PollEvent(&event))
{
ImGui_ImplSDL2_ProcessEvent(&event);
@@ -86,8 +89,12 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_
State->IsRunning = false;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
State->IsRunning = false;
+ test++;
}
+ if (State->UpdateScreen == 0 && test == 0)
+ return 0;
+
if (State->Warp_WantSetPos) {
ImGui::GetIO().WantSetMousePos = true;
io.MousePos = State->Warp_PositionToSet;
@@ -117,7 +124,7 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_
// we need to delay a bit.
if (State->FirstFrame) {
ImGui::EndFrame();
- return;
+ return 2;
}
#if DEBUG
@@ -159,6 +166,12 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_
Memory_Cache_Purge(File, State, Memory);
Memory->PurgeCache = false;
}
+
+ if (test)
+ test += 1;
+ if (State->UpdateScreen)
+ test = 0;
+ return test;
}
static void
@@ -257,7 +270,7 @@ Render_SortKeyframes(project_data *File, project_state *State, memory *Memory,
int32 Frame_Start = Layer->Frame_Start;
int32 Frame_End = Layer->Frame_End;
int32 Frame_Offset = Layer->Frame_Offset;
- if (Layer->IsSelected)
+ if (Layer->IsSelected & 0x01)
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;
@@ -383,7 +396,7 @@ LayerIterate_DeepestPrecomp(project_state *State, memory *Memory, uint32 CompInd
Position = XAxis + YAxis;
layer_transforms T = Layer_GetTransforms(Layer);
v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Width, Height, Center / V2(Comp->Width, Comp->Height));
- if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && Layer->IsSelected)
+ if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && (Layer->IsSelected & 0x01))
{
*SelectionCount += 1;
*SelectedLayerIndex = i;
@@ -426,7 +439,7 @@ LayerIterate_SelectionStatus(project_state *State, memory *Memory, uint32 CompIn
Position = XAxis + YAxis;
layer_transforms T = Layer_GetTransforms(Layer);
v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Width, Height, Center / V2(Comp->Width, Comp->Height));
- if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && Layer->IsSelected && !Layer->IsLocked)
+ if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && (Layer->IsSelected & 0x03) && !Layer->IsLocked)
{
*SelectionCount += 1;
*SelectedLayerIndex = i;
@@ -452,7 +465,7 @@ LayerIterate_SelectionAct(project_state *State, memory *Memory, uint32 CompIndex
Assert(Layer->Block_Composition_Index == CompIndex);
int Width = 0, Height = 0;
Layer_GetDimensions(Memory, Layer, &Width, &Height);
- if (Layer->IsPrecomp && Layer->IsSelected) {
+ if (Layer->IsPrecomp && (Layer->IsSelected & 0x03)) {
// only like 20% sure how this works...
layer_transforms NewExtraT = Layer_GetTransforms(Layer);
v2 NewCenter = T_CompPosToLayerPos(NewExtraT, Comp->Width, Comp->Height, Width, Height, Center.x, Center.y);
@@ -460,7 +473,7 @@ LayerIterate_SelectionAct(project_state *State, memory *Memory, uint32 CompIndex
NewExtraT.scale = ExtraT.scale / NewExtraT.scale;
LayerIndex = LayerIterate_SelectionAct(State, Memory, Layer->Block_Source_Index, NewExtraT, NewCenter, SortedCompArray, SortedLayerArray, SelectionCount, SelectedLayerIndex, SelectedPrecompIndex, BelowOnly);
if (LayerIndex != -1) {
- Layer->IsSelected = -1;
+ Layer->IsSelected = 0x02;
return LayerIndex;
}
}
@@ -471,7 +484,7 @@ LayerIterate_SelectionAct(project_state *State, memory *Memory, uint32 CompIndex
Position = XAxis + YAxis;
layer_transforms T = Layer_GetTransforms(Layer);
v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Width, Height, Center / V2(Comp->Width, Comp->Height));
- if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && !Layer->IsSelected && !Layer->IsLocked)
+ if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && !(Layer->IsSelected & 0x01) && !Layer->IsLocked)
{
if (!BelowOnly && SelectionCount == 1) {
if (i < SelectedLayerIndex || SelectedPrecompIndex != CompIndex) {
@@ -524,7 +537,7 @@ LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, layer_trans
NewExtraT.scale = ExtraT.scale / NewExtraT.scale;
LayerIterate(State, Memory, Layer->Block_Source_Index, NewExtraT, NewCenter, SortedCompArray, SortedLayerArray);
}
- if (Layer->IsSelected == 1) {
+ if (Layer->IsSelected & 0x01) {
#if DEBUG
if (Layer->IsPrecomp)
PostMsg(State, "DEBUG: Precomp transformed!");
@@ -568,7 +581,7 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
int32 Frame_Start = Layer->Frame_Start;
int32 Frame_End = Layer->Frame_End;
int32 Frame_Offset = Layer->Frame_Offset;
- if (Layer->IsSelected)
+ if (Layer->IsSelected & 0x01)
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;
@@ -713,7 +726,7 @@ 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)
+ if (Layer->IsSelected & 0x01)
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;
@@ -1163,6 +1176,7 @@ int main(int argc, char *argv[]) {
State->UpdateFrame = true;
State->MostRecentlySelectedLayer = 0;
}
+ File->UI.LayerColors[3] = 0xff203d6a;
// File->PrincipalCompIndex = 1;
#else
// uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/yu.webm");
@@ -1302,7 +1316,13 @@ int main(int argc, char *argv[]) {
sorted_file Sorted = File_Sort_Push(File, State, &Memory);
- Main_InputTest(File, State, &Memory, Sorted, &File->UI, window, textureID);
+ if (State->FirstFrame)
+ State->UpdateScreen = 2;
+
+ // TODO(fox): Do the same thing with the timeline and viewport to
+ // reduce wasted rendering further; for now I am at least pausing all
+ // UI when no inputs happen.
+ State->UpdateScreen += Main_InputTest(File, State, &Memory, Sorted, &File->UI, window, textureID);
if (State->IsPlaying) {
block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(&Memory, F_Precomps, File->PrincipalCompIndex);
@@ -1390,7 +1410,7 @@ int main(int argc, char *argv[]) {
} else if (State_ExecuteAtEnd == 2) {
History_Entry_Commit(&Memory, "Duplicate layers");
v2 Offset = V2(State->Interact_Dup_Previous[0], State->Interact_Dup_Previous[1]);
- Project_Layer_Duplicate(File, State, &Memory, Sorted.CompArray, Sorted.LayerArray, Offset, 0);
+ Project_Layer_Duplicate(File, State, &Memory, Sorted.CompArray, Sorted.LayerArray, Offset, 0, io.KeyCtrl);
State->Interact_Transform = {};
History_Entry_End(&Memory);
}
@@ -1403,6 +1423,7 @@ int main(int argc, char *argv[]) {
// frames, but we'd have to make sure the pop order stays the same in all scenarios.
Assert(Debug.ScratchState == 0);
+ bool32 UpdateScreen = 0;
if (State->IsPlaying && State->HotFramePerf > 1 && FullyCached) {
uint64 RenderTime = SDL_GetPerformanceCounter() - State->HotFramePerf;
real64 FrameMS = (1000.0f * (real64)RenderTime) / (real64)PerfFrequency;
@@ -1412,7 +1433,11 @@ int main(int argc, char *argv[]) {
Main_RenderUI(io, clear_color, window);
State->HotFramePerf = 1;
} else {
- Main_RenderUI(io, clear_color, window);
+ if (State->UpdateScreen) {
+ Main_RenderUI(io, clear_color, window);
+ State->UpdateScreen--;
+ UpdateScreen = 1;
+ }
}
if (State->HotFramePerf == 1) {
@@ -1429,7 +1454,11 @@ int main(int argc, char *argv[]) {
uint64 PerfTime = PerfEnd - PerfStart;
real64 FrameMS = (1000.0f * (real64)PerfTime) / (real64)PerfFrequency;
real64 FPS = PerfFrequency / PerfTime;
- // printf("%.02f ms/f, %.02f frames\n", FrameMS, FPS);
+ if (!UpdateScreen) {
+ real64 TargetMS = (1000.0f / 60);
+ if (TargetMS > FrameMS)
+ SDL_Delay((uint64)(TargetMS - FrameMS));
+ }
}
for (int i = 0; i < 7; i++) {