Skip to content

Commit

Permalink
Add in memory frame storage
Browse files Browse the repository at this point in the history
  • Loading branch information
codejaeger committed Apr 1, 2021
1 parent 52ca40a commit ea3b1ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/Javis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,17 @@ 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"
print(last_frames)
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",
Expand Down
4 changes: 2 additions & 2 deletions src/structs/Object.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/structs/Video.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mutable struct Video
objects::Vector{AbstractObject}
background_frames::Vector{Int}
defs::Dict{Symbol,Any}
frame_images::Dict{Int, Any}
end

"""
Expand Down Expand Up @@ -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)
Expand All @@ -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."
Expand Down

0 comments on commit ea3b1ec

Please sign in to comment.