From e1b98945b35c9b53c7c05bcb2efb253ab9448176 Mon Sep 17 00:00:00 2001 From: Louis Ponet Date: Tue, 6 Sep 2022 18:08:52 +0200 Subject: [PATCH] updates --- Project.toml | 2 +- src/component.jl | 17 ++++++++++++----- src/entity.jl | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 1b9c118..10fd402 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Overseer" uuid = "1ada24be-c16d-4464-9f61-27c2e0f16645" authors = ["louisponet "] -version = "0.2.1" +version = "0.2.2" [deps] MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" diff --git a/src/component.jl b/src/component.jl index b021536..dc6a7da 100644 --- a/src/component.jl +++ b/src/component.jl @@ -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) @@ -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...) @@ -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 diff --git a/src/entity.jl b/src/entity.jl index a6986f4..8bcf4b6 100644 --- a/src/entity.jl +++ b/src/entity.jl @@ -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)