Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Sep 6, 2022
1 parent 7607b30 commit e1b9894
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 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.1"
version = "0.2.2"

[deps]
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Expand Down
17 changes: 12 additions & 5 deletions src/component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function test_abstractcomponent_interface(::Type{T}) where {T<:AbstractComponent
@test c[Entity(2)] isa TestCompData

@test entity(c, 1) isa Entity
@test pop!(c, Entity(2)) isa TestCompData
@test pop!(c) isa TestCompData
@test pop!(c, Entity(2)) == TestCompData(1)
@test pop!(c) == EntityState(Entity(1), TestCompData(1))
@test isempty(c)

c[Entity(1)] = TestCompData(1)
Expand Down Expand Up @@ -165,7 +165,14 @@ function Base.pop!(c::Component, e::AbstractEntity)
end
end

Base.pop!(c::AbstractComponent) = @inbounds pop!(c, entity(c, length(c)))
function Base.pop!(c::AbstractComponent)
@boundscheck if isempty(c)
throw(BoundsError(c))
end
@inbounds begin
return EntityState(Entity(pop!(c.indices)), pop!(c.data))
end
end

@inline Base.iterate(c::Component, args...) = iterate(c.data, args...)

Expand Down Expand Up @@ -367,12 +374,12 @@ function Base.pop!(c::PooledComponent)
throw(BoundsError(c))
end
@inbounds begin
pop!(c.indices)
e = Entity(pop!(c.indices))
g = pop!(c.pool)
val = c.data[g]
c.pool_size[g] -= 1
maybe_cleanup_empty_pool!(c, g)
return val
return EntityState(e, val)
end
end

Expand Down
1 change: 1 addition & 0 deletions src/entity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct EntityState{TT<:Tuple} <: AbstractEntity
e::Entity
components::TT
end
EntityState(e::Entity, comps...) = EntityState(e, comps)

Entity(e::EntityState) = e.e
Base.convert(::Type{Entity}, e::EntityState) = Entity(e)
Expand Down

2 comments on commit e1b9894

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

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.2 -m "<description of version>" e1b98945b35c9b53c7c05bcb2efb253ab9448176
git push origin v0.2.2

Please sign in to comment.