diff --git a/src/Javis.jl b/src/Javis.jl index c14e4b0e9..ed2f74594 100644 --- a/src/Javis.jl +++ b/src/Javis.jl @@ -225,14 +225,16 @@ function render( dev_mode = get(CURRENT_VIDEO[1].defs, :dev_mode, false) if dev_mode last_frames = get(CURRENT_VIDEO[1].defs, :last_frames, frames) - tempdirectory = ".dev" end @showprogress 1 "Rendering frames..." for frame in frames - if compute_frames == :latest && frame in last_frames - frame_image = Images.load("$(tempdirectory)/$(lpad(filecounter, 10, "0")).png") + if compute_frames == :latest && size(last_frames)[1] != 0 + frame_image = CURRENT_VIDEO[1].frame_images[frame] else frame_image = convert.(RGB, get_javis_frame(video, objects, frame)) + if dev_mode + CURRENT_VIDEO[1].frame_images[frame] = frame_image + end if !isempty(tempdirectory) Images.save( "$(tempdirectory)/$(lpad(filecounter, 10, "0")).png", diff --git a/src/structs/Object.jl b/src/structs/Object.jl index 3c0014b73..51eb7026a 100644 --- a/src/structs/Object.jl +++ b/src/structs/Object.jl @@ -130,13 +130,13 @@ Here the scaling is applied to the rectangle for the first fifty frames. - `action::Vector{<:AbstractAction}` - the actions applied to the objects """ function act!(object::AbstractObject, action::AbstractAction) - update_lastframes(action.frames) + update_lastframes(action.frames.frames) push!(object.actions, copy(action)) end function act!(object::AbstractObject, actions::Vector{<:AbstractAction}) for action in actions - update_lastframes(action.frames) + update_lastframes(action.frames.frames) act!(object, action) end end diff --git a/src/structs/Video.jl b/src/structs/Video.jl index 262c6db08..749140db6 100644 --- a/src/structs/Video.jl +++ b/src/structs/Video.jl @@ -16,6 +16,7 @@ mutable struct Video objects::Vector{AbstractObject} background_frames::Vector{Int} defs::Dict{Symbol,Any} + frame_images::Dict{Int, Any} end """ @@ -45,6 +46,7 @@ function Video(width, height; dev_mode = false) AbstractObject[], Int[], Dict{Symbol,Any}(:dev_mode => dev_mode), + Dict{Int, Any}() ) if isempty(CURRENT_VIDEO) push!(CURRENT_VIDEO, video) @@ -70,8 +72,12 @@ function update_lastframes(frames::Any) frames = Vector{Int}(frames) end if get(CURRENT_VIDEO[1].defs, :dev_mode, false) + last_frames = get(CURRENT_VIDEO[1].defs, :last_frames, Vector{Int}()) CURRENT_VIDEO[1].defs[:last_frames] = - setdiff(get(CURRENT_VIDEO[1].defs, :last_frames, Vector{Int}()), frames) + setdiff(last_frames, frames) + for frame in frames + delete!(CURRENT_VIDEO[1].frame_images, frame) + end end catch e @warn "Argument `frames` with type $(typeof(frames)) passed to `update_lastframes` must have integer vector like type hence ignoring update."