Skip to content

Commit

Permalink
Fixes, added threaded Stage evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Sep 28, 2022
1 parent e1b9894 commit ac2f499
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 33 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: 3
permissions:
contents: write
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Overseer"
uuid = "1ada24be-c16d-4464-9f61-27c2e0f16645"
authors = ["louisponet <[email protected]>"]
version = "0.2.2"
version = "0.2.3"

[deps]
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Expand Down
2 changes: 0 additions & 2 deletions src/component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ npools(c::PooledComponent) = length(c.data)
Base.@propagate_inbounds @inline Base.getindex(c::PooledComponent, e::AbstractEntity) = c.data[pool(c, e)]
Base.@propagate_inbounds @inline Base.getindex(c::PooledComponent, i::Integer) = c.data[c.pool[i]]

entity(c::PooledComponent, i::Int) = parent(c, i)

Base.@propagate_inbounds @inline function Base.parent(c::PooledComponent, i::Int)
@boundscheck if i > length(c.data)
throw(BoundsError(c, i))
Expand Down
19 changes: 6 additions & 13 deletions src/ledger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Ledger() = Ledger(Entity[],
Entity[],
Dict{DataType, AbstractComponent}(),
AbstractGroup[],
Pair{Symbol, Vector{System}}[])
Stage[])

function Ledger(comps::Dict{DataType, AbstractComponent})
out = Ledger()
Expand Down Expand Up @@ -54,14 +54,14 @@ components(m::AbstractLedger) = ledger(m).components
entities(m::AbstractLedger) = ledger(m).entities
free_entities(m::AbstractLedger) = ledger(m).free_entities
to_delete(m::AbstractLedger) = ledger(m).to_delete
stage(m::AbstractLedger, name) = stage(ledger(m), name)
valid_entities(m::AbstractLedger) = filter(x -> x.id != 0, entities(m))
stages(m::AbstractLedger) = ledger(m).stages
stage(m::AbstractLedger, s::Symbol) = ledger(m).stages[s]
groups(m::AbstractLedger) = ledger(m).groups
singleton(m::AbstractLedger, ::Type{T}) where {T} = m[T][1]

##### BASE Extensions ####
function Base.show(io::IO, mime::MIME{Symbol("text/plain")}, l::AbstractLedger)
function Base.show(io::IO, l::AbstractLedger)
summary(io, l)
println(io)
println(io, "Components:")
Expand Down Expand Up @@ -107,12 +107,12 @@ function Base.getindex(m::AbstractLedger, e::AbstractEntity)
return EntityState(convert(Entity, e), (data...,))
end

function Base.getindex(v::Vector{Stage}, s::Symbol)
id = findfirst(x->first(x) == s, v)
function stage(l::Ledger, s::Symbol)
id = findfirst(x-> x.name == s, l.stages)
if id === nothing
error("Stage $s not found.")
end
return v[id]
return l.stages[id]
end

function Base.setindex!(m::AbstractLedger, v::T, e::AbstractEntity) where {T}
Expand All @@ -130,7 +130,6 @@ function Base.setindex!(m::AbstractLedger, v::C, ::Type{T}) where {T, C <: Abstr
return components(m)[T] = v
end


function register_new!(m::AbstractLedger, ::Type{T}, e::AbstractEntity) where {T}
for g in groups(m)
if !(g isa OrderedGroup)
Expand Down Expand Up @@ -256,12 +255,6 @@ function delete_scheduled!(m::AbstractLedger)
empty!(to_delete(m))
end

function update(s::Stage, m::AbstractLedger)
for s in last(s)
update(s, m)
end
end

function update(m::AbstractLedger)
for stage in stages(m)
update(stage, m)
Expand Down
46 changes: 32 additions & 14 deletions src/system.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
update(::S, m::AbstractLedger) where {S<:System}= error("No update method implemented for $S")
update(::S, l::AbstractLedger) where {S<:System}= error("No update method implemented for $S")

"""
requested_components(::System)
Expand All @@ -24,26 +24,44 @@ Components:
"""
requested_components(::System) = ()

const Stage = Pair{Symbol, Vector{System}}
struct Stage
name::Symbol
steps::Vector{Union{System, Stage, Vector}}
end

Base.push!(s::Stage, sys) = push!(last(s), sys)
Base.push!(s::Stage, step) = push!(s.steps, step)

Base.insert!(s::Stage, i::Integer, sys) = insert!(last(s), i, sys)
Base.insert!(s::Stage, i::Integer, step) = insert!(s.steps, i, step)

function requested_components(stage::Stage)
function requested_components(systems::Vector)
comps = Type[]
for s in last(stage)
for c in requested_components(s)
push!(comps, c)
end
end
return comps
for s in systems
append!(comps, requested_components(s))
end
return comps
end
requested_components(stage::Stage) = requested_components(stage.steps)

function prepare(s::Stage, m::AbstractLedger)
for sys in last(s)
prepare(sys, m)
function prepare(systems::Vector, l::AbstractLedger)
for sys in systems
prepare(sys, l)
end
end

prepare(s::Stage, l::AbstractLedger) = prepare(s.steps, l)

prepare(::System, ::AbstractLedger) = nothing

function update(stage::Stage, l::AbstractLedger)
# Steps in a stage get executed in sequence, but if
# a step is a vector they are threaded
for step in stage.steps
if step isa Vector
Threads.@threads for t in step
update(t, l)
end
else
update(step, l)
end
end
end
6 changes: 3 additions & 3 deletions test/test_ledger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ struct TSys2 <: System end

push!(m, :default, TSys())

@test length(last(stage(m, :default))) == 2
@test length(stage(m, :default).steps) == 2

insert!(m, :default, 1, TSys2())

@test last(stage(m, :default))[1] == TSys2()
@test stage(m, :default).steps[1] == TSys2()

insert!(m, 1, Stage(:test, [TSys(), TSys2()]))

@test first(m.stages[1]) == :test
@test m.stages[1].name == :test

@test eltype(m[T4]) == T4

Expand Down

2 comments on commit ac2f499

@louisponet
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/69119

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.3 -m "<description of version>" ac2f4996095bbf75be3a013251635fd1fac2ad8d
git push origin v0.2.3

Please sign in to comment.