summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp90
1 files changed, 58 insertions, 32 deletions
diff --git a/src/main.cpp b/src/main.cpp
index a3b3724..1b13405 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -270,11 +270,6 @@ AV_Retrieve(project_state *State, memory *Memory, uint32 SourceIndex)
return AV;
}
-static void
-File_RetrieveBitmap(project_data *File, project_state *State, memory *Memory, block_source *Source, int32 FrameToSeek, void *Bitmap, uint32 LayerIndex)
-{
-}
-
static void *
Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_file Sorted, ui *UI, SDL_Window *window, GLuint textureID, ImGuiIO io,
sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray,
@@ -285,29 +280,57 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
void *CompBuffer = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry_Main->Block_StartIndex);
uint64 Size = Comp->Width * Comp->Height * Comp->BytesPerPixel;
- if (Entry_Main->IsCached)
- return CompBuffer;
-
- Arbitrary_Zero((uint8 *)CompBuffer, Size);
-
- uint64 Comp_TimeStart = GetCPUTime();
-
sorted_comp_array *SortedCompStart = &SortedCompArray[CompIndex];
sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, CompIndex);
+ // NOTE(fox): We have to re-evalute keyframes even when the frame is
+ // cached, since we aren't caching the values and the UI needs to have
+ // them. Make sure that the cache is always purged if keyframes are
+ // updated.
+
for (int i = 0; i < SortedCompStart->LayerCount; i++) {
sorted_layer_array SortEntry = SortedLayerStart[i];
uint32 Index_Physical = SortEntry.Block_Layer_Index;
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
- if (Layer->Frame_Start <= Frame_Current &&
- Layer->Frame_End > Frame_Current && Layer->IsVisible)
+
+ int32 Frame_Start = Layer->Frame_Start;
+ int32 Frame_End = Layer->Frame_End;
+ if (Layer->IsSelected)
+ Interact_Evaluate_Layer(Memory, State, Index_Physical, *SortedCompStart, SortedLayerStart, &Frame_Start, &Frame_End);
+ int FrameToSeek = State->Frame_Current - Frame_Start;
+
+ if (Frame_Start <= Frame_Current &&
+ Frame_End > Frame_Current && Layer->IsVisible)
{
if (State->UpdateKeyframes) {
sorted_property_array *SortedLayerProperties = SortedPropertyStart + SortEntry.SortedPropertyStart;
uint16 *SortedLayerKeyframes = SortedKeyframeArray + SortEntry.SortedKeyframeStart;
Layer_UpdateAllKeyframes(File, State, Memory, Layer, Index_Physical, SortedLayerProperties, SortedLayerKeyframes, Frame_Current);
}
+ }
+ }
+
+ if (Entry_Main->IsCached)
+ return CompBuffer;
+ Arbitrary_Zero((uint8 *)CompBuffer, Size);
+
+ uint64 Comp_TimeStart = GetCPUTime();
+
+ for (int i = 0; i < SortedCompStart->LayerCount; i++) {
+ sorted_layer_array SortEntry = SortedLayerStart[i];
+ uint32 Index_Physical = SortEntry.Block_Layer_Index;
+ block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
+
+ int32 Frame_Start = Layer->Frame_Start;
+ int32 Frame_End = Layer->Frame_End;
+ if (Layer->IsSelected)
+ Interact_Evaluate_Layer(Memory, State, Index_Physical, *SortedCompStart, SortedLayerStart, &Frame_Start, &Frame_End);
+ int FrameToSeek = State->Frame_Current - Frame_Start;
+
+ if (Frame_Start <= Frame_Current &&
+ Frame_End > Frame_Current && Layer->IsVisible)
+ {
layer_bitmap_state *BitmapState = &State->Render.Bitmap[Index_Physical];
void *BitmapAddress = NULL;
void *RenderAddress = NULL; // result of masking, effects, and intermediate paint stroke
@@ -326,11 +349,12 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
State->AVCount++;
}
}
- if (Source->HasAudio && !Source->HasVideo) {
+ if (Source->HasAudio) {
Assert(Source->Type == source_type_file);
if (State->AudioLayerIndex == -1)
State->AudioLayerIndex = Index_Physical;
- continue;
+ if (!Source->HasVideo)
+ continue;
}
// if ((State->PreviewSource != -1) && Layer->IsSelected) {
// Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, State->PreviewSource);
@@ -339,10 +363,9 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
if (Source->Type == source_type_principal || Source->Type == source_type_principal_temp) {
BitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0);
} else {
- cache_entry *CacheEntry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, State->Frame_Current);
+ cache_entry *CacheEntry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, FrameToSeek);
BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, CacheEntry->Block_StartIndex);
if (!CacheEntry->IsCached) {
- int FrameToSeek = State->Frame_Current - Layer->Frame_Start;
AV_LoadVideoFrame(Memory, Source, AV, FrameToSeek, BitmapAddress);
CacheEntry->IsCached = true;
}
@@ -411,6 +434,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
Memory_PopScratch(Memory, ScratchSize);
}
}
+
Entry_Main->CycleTime = GetCPUTime() - Comp_TimeStart;
Entry_Main->IsCached = true;
@@ -689,8 +713,13 @@ int main(int argc, char *argv[]) {
// 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.
- // io.IniFilename = NULL;
- // ImGui::LoadIniSettingsFromMemory(ImGuiPrefs);
+#if DEBUG
+ io.IniFilename = NULL;
+ ImGui::LoadIniSettingsFromMemory(ImGuiPrefs);
+#else
+ io.IniFilename = NULL;
+ ImGui::LoadIniSettingsFromMemory(ImGuiPrefs);
+#endif
// ImGui::SaveIniSettingsToDisk("imgui.ini");
ImGui::StyleColorsDark();
@@ -723,8 +752,9 @@ int main(int argc, char *argv[]) {
sprintf(State->DummyName, "test");
File_Open(File, State, &Memory, State->DummyName);
State->UpdateFrame = true;
- State->MostRecentlySelectedLayer = 0;
- uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/24.mp4");
+ // State->MostRecentlySelectedLayer = 0;
+#else
+ uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/yu.webm");
block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, SourceIndex);
Source->IsSelected = true;
Source_UICreateButton(File, State, &Memory);
@@ -761,10 +791,7 @@ int main(int argc, char *argv[]) {
// NextEffect->Index -= 1;
// History_Entry_End(Memory);
// } break;
- case hotkey_newpaintlayer:
- {
- Project_PaintLayer_New(File, State, &Memory);
- } break;
+ case hotkey_newpaintlayer: { Project_PaintLayer_New(File, State, &Memory); } break;
case hotkey_newlayerfromsource:
{
Source_UICreateButton(File, State, &Memory);
@@ -805,24 +832,23 @@ int main(int argc, char *argv[]) {
State->UpdateKeyframes = true;
}
- if ((State->AudioLayerIndex != -1) &&
- (State->CachedFrameCount == (MainComp->Frame_End - MainComp->Frame_Start)))
+ bool32 FullyCached = (State->CachedFrameCount == (MainComp->Frame_End - MainComp->Frame_Start));
+ if ((State->AudioLayerIndex != -1) && FullyCached)
{
block_layer *AudioLayer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, State->AudioLayerIndex);
- // block_source *AudioSource = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, SourceIndex);
av_info *AV = AV_Retrieve(State, &Memory, AudioLayer->Block_Source_Index);
int32 LayerPos = AudioLayer->Frame_Start;
if (State->Frame_Current >= LayerPos) {
if (State->Frame_Current == LayerPos) {
SDL_ClearQueuedAudio(1);
- AV_SeekAudio(AV, 60, 0);
+ AV_SeekAudio(AV, MainComp->FPS, 0);
}
if (State->HotFramePerf == 1) {
SDL_ClearQueuedAudio(1);
int32 FrameToSeek = State->Frame_Current - LayerPos;
if (FrameToSeek > -1)
- AV_SeekAudio(AV, 60, FrameToSeek);
+ AV_SeekAudio(AV, MainComp->FPS, FrameToSeek);
}
uint32 QueuedAudioSize = SDL_GetQueuedAudioSize(1);
@@ -877,7 +903,7 @@ int main(int argc, char *argv[]) {
Assert(Debug.ScratchState == 0);
- if (State->IsPlaying && State->HotFramePerf > 1) {
+ if (State->IsPlaying && State->HotFramePerf > 1 && FullyCached) {
uint64 RenderTime = SDL_GetPerformanceCounter() - State->HotFramePerf;
real64 FrameMS = (1000.0f * (real64)RenderTime) / (real64)PerfFrequency;
real64 TargetMS = (1000.0f / MainComp->FPS);