Skip to content

Commit

Permalink
implemented pure Entity, varargs update
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Apr 8, 2023
1 parent 1bf0b76 commit 5207798
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
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.9"
version = "0.2.10"

[deps]
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Expand Down
4 changes: 3 additions & 1 deletion src/entity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ end

Entity(e::Entity) = e

Base.@propagate_inbounds Entity(c::AbstractComponent, i::Int) = Entity(c.indices.packed[i])

Base.iterate(e::Entity, state=1) = state > 1 ? nothing : (e, state+1)

const EMPTY_ENTITY = Entity(0)
Expand Down Expand Up @@ -184,7 +186,7 @@ end
@inline Base.@propagate_inbounds Base.getindex(e::EntityState, i::Int) = e.components[i][e.e]

function entity(c::AbstractComponent, i::Integer)
return EntityState(Entity(c.indices.packed[i]), c)
return EntityState(Entity(c, i), c)
end

"""
Expand Down
6 changes: 2 additions & 4 deletions src/ledger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function Base.empty!(m::AbstractLedger)
end

function Base.getindex(m::AbstractLedger, ::Type{T}) where {T}
return components(m)[T]::component_type(T)
return get!(components(m), T, component_type(T)())
end

Base.copy(m::AbstractLedger) = Ledger(copy(entities(m)),
Expand Down Expand Up @@ -142,9 +142,7 @@ end

function ensure_component!(m::AbstractLedger, c::Type{T}) where {T}
if !(c in m)
m_comps = components(m)
comp = component_type(c)()
m_comps[T] = comp
components(m)[T] = component_type(c)()
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ prepare(s::Stage, l::AbstractLedger) = prepare(s.steps, l)

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

function update(stage::Stage, l::AbstractLedger)
function update(stage::Stage, l::AbstractLedger, args...)
# 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)
update(t, l, args...)
end
else
update(step, l)
update(step, l, args...)
end
end
end
Expand Down

2 comments on commit 5207798

@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/81247

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.10 -m "<description of version>" 52077984a8c452897610df2a2bdc2e3072ee8765
git push origin v0.2.10

Please sign in to comment.