diff --git a/.travis.yml b/.travis.yml index de1ba0e..7d5119b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,12 +37,12 @@ env: # - julia -e 'Pkg.clone(pwd()); Pkg.build("PStdLib"); Pkg.test("PStdLib"; coverage=true)' after_success: # push coverage results to Coveralls - - julia -e 'using ECS; using Pkg; cd(dirname(dirname(pathof(ECS)))); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())' + - julia -e 'using Overseer; using Pkg; cd(dirname(dirname(pathof(Overseer)))); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())' # push coverage results to Codecov - - julia -e 'using ECS; using Pkg; cd(dirname(dirname(pathof(ECS)))); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' + - julia -e 'using Overseer; using Pkg; cd(dirname(dirname(pathof(Overseer)))); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' - julia -e 'Pkg.add("Documenter")' - - julia -e 'using ECS; cd(dirname(dirname(pathof(ECS)))); include(joinpath("docs", "make.jl"))' + - julia -e 'using Overseer; cd(dirname(dirname(pathof(Overseer)))); include(joinpath("docs", "make.jl"))' # jobs: # include: diff --git a/README.md b/README.md index 2b67978..6f618ae 100644 --- a/README.md +++ b/README.md @@ -12,23 +12,23 @@ The main idea of an ECS is to have a very clear separation between data and logi ECS can be implemented in a lot of ways, each with slightly different behaviors. This is a small introduction to the specifics of this implementation, since it's important to understand it to be used effectively. ### Entity -Purely an identifier, an index. +Purely an identifier, used as an index. ### Component & ComponentData The data that can be attached to Entities is a subtype of `ComponentData` and is stored in `Component`. An `Entity` can be used as an index into the `Component` to retrieve its data. Each `ComponentData` should be purely a store for data, with no more logic attached to it than for creation and accessing. -### System & SystemStage +### System & Stage This where all the logic should take place. Each system should be an empty struct [(except for maybe holding settings info)](https://github.com/louisponet/Glimpse.jl/blob/43d9e0d6f116343324b4a083d3cb80943225ac4e/src/systems/rendering/depthpeeling.jl#L18) that subtypes `System` and overloads 2 functions: -- `Overseer.update(::System, m::AbstractOverseer)` -- `Overseer.requested_components(::System)` + - `Overseer.update(::System, m::AbstractLedger)` + - `Overseer.requested_components(::System)` -The first one will be used to perform each update, i.e. perform the system's main logic, while the latter is used when the system is added to an `AbstractOverseer` to make sure that all `Component`s that the system cares for are present. +The first one will be used to perform each update, i.e. perform the system's main logic, while the latter is used when the system is added to an `AbstractLedger` to make sure that all `Component`s that the system cares for are present. -Systems are then grouped together into a `SystemStage` which is really just a `Pair{Symbol, Vector{System}}`, which is just to allow for updating specific groups of systems together if desired. +Systems are then grouped together into a `Stage` which is really just a `Pair{Symbol, Vector{System}}`, which is just to allow for updating specific groups of systems together if desired. -### AbstractOverseer -All Entities, Components and SystemStages are grouped in an `AbstractOverseer` which takes care of creating new entities, accessing components, updating systems and generally making sure that everything runs. +### AbstractLedger +All Entities, Components and Stages are grouped in an `AbstractLedger` which takes care of creating new entities, accessing components, updating systems and generally making sure that everything runs. ## Example To get a better understanding of how all of this works, it's best to see it in action in an example. @@ -63,7 +63,7 @@ struct Oscillator <: System end Overseer.requested_components(::Oscillator) = (Spatial, Spring) -function Overseer.update(::Oscillator, m::AbstractOverseer) +function Overseer.update(::Oscillator, m::AbstractLedger) spatial = m[Spatial] spring = m[Spring] for e in @entities_in(spatial && spring) @@ -78,7 +78,7 @@ end struct Rotator <: System end Overseer.requested_components(::Rotator) = (Spatial, Rotation) -function Overseer.update(::Rotator, dio::AbstractOverseer) +function Overseer.update(::Rotator, dio::AbstractLedger) rotation = dio[Rotation] spatial = dio[Spatial] dt = 0.01 @@ -97,7 +97,7 @@ struct Mover <: System end Overseer.requested_components(::Mover) = (Spatial, ) -function Overseer.update(::Mover, m::AbstractOverseer) +function Overseer.update(::Mover, m::AbstractLedger) dt = 0.01 spat = m[Spatial] for e in @entities_in(spat) @@ -113,10 +113,10 @@ given the velocity. Each system iterates over the entities that have the components like given to the rules for `@entities_in`. For example `@entities_in(a && b || c && !d)` will iterate through all the entities that are in component `a` and `b` or `c` but not in `d`. -Now we group these systems in a `:simulation` stage, construct a `Overseer` which is a basic `AbstractOverseer` and generate some entities. +Now we group these systems in a `:simulation` stage, construct a `Ledger` which is a basic `AbstractLedger` and generate some entities. ```julia -stage = SystemStage(:simulation, [Oscillator(), Rotator(), Mover()]) -m = Overseer(stage) #this creates the Overseer with the system stage, and also makes sure all requested components are added. +stage = Stage(:simulation, [Oscillator(), Rotator(), Mover()]) +m = Ledger(stage) #this creates the Overseer with the system stage, and also makes sure all requested components are added. e1 = Entity(m, Spatial(Point3(1.0, 1.0, 1.0), Vec3(0.0, 0.0, 0.0)), diff --git a/src/Overseer.jl b/src/Overseer.jl index 7540b24..05f3be0 100644 --- a/src/Overseer.jl +++ b/src/Overseer.jl @@ -1,4 +1,4 @@ -module ECS +module Overseer using Parameters abstract type ComponentData end @@ -9,11 +9,11 @@ module ECS abstract type System end """ - Abstract type for all entity, component and system overseers. In order to use the interface, - make sure that every subtype of AbstractOverseer has an overload for the function `overseer` that - points towards the fields needed for functionality (see overseer.jl for more info) + Abstract type for all entity, component and system ledgers. In order to use the interface, + make sure that every subtype of AbstractLedger has an overload for the function `ledger` that + points towards the fields needed for functionality (see ledger.jl for more info). """ - abstract type AbstractOverseer end + abstract type AbstractLedger end include("utils.jl") include("indices.jl") @@ -21,13 +21,13 @@ module ECS include("component.jl") include("group.jl") include("system.jl") - include("overseer.jl") + include("ledger.jl") - export AbstractOverseer, Overseer, System, SystemStage, Component, SharedComponent, ComponentData, Entity + export AbstractLedger, Ledger, System, Stage, Component, SharedComponent, ComponentData, Entity export @component, @shared_component, @component_with_kw, @shared_component_with_kw export @entities_in - export update, schedule_delete!, delete_scheduled!, empty_entities!, system_stage, components, entities, system_stages + export update, schedule_delete!, delete_scheduled!, empty_entities!, stage, components, entities, stages export prepare, singleton, valid_entities, groups, group, create_group!, regroup!, remove_group! end # module diff --git a/src/component.jl b/src/component.jl index d4dacc5..c50b27b 100644 --- a/src/component.jl +++ b/src/component.jl @@ -187,13 +187,13 @@ end macro entities_in(indices_expr) expr, t_sets, t_orsets = expand_indices_bool(indices_expr) if length(t_sets) == 1 && isempty(t_orsets) && expr.args[2] isa Symbol - return esc(:(ECS.EntityIterator(ECS.indices_iterator($(t_sets[1]))))) + return esc(:(Overseer.EntityIterator(Overseer.indices_iterator($(t_sets[1]))))) else return esc(quote t_comps = $(Expr(:tuple, t_sets...)) t_or_comps = $(Expr(:tuple, t_orsets...)) - sets = map(ECS.indices_iterator, t_comps) - orsets = map(ECS.indices_iterator, t_or_comps) + sets = map(Overseer.indices_iterator, t_comps) + orsets = map(Overseer.indices_iterator, t_or_comps) if isempty(sets) minlen, minid = findmin(map(length, orsets)) t_shortest = orsets[minid] @@ -209,7 +209,7 @@ macro entities_in(indices_expr) else shortest = t_shortest end - ECS.EntityIterator(ECS.IndicesIterator(shortest, x -> $expr, length(shortest))) + Overseer.EntityIterator(Overseer.IndicesIterator(shortest, x -> $expr, length(shortest))) end) end end @@ -237,14 +237,14 @@ function typename(typedef::Expr) end function process_typedef(typedef, mod, with_kw=false) - tn = ECS.typename(typedef) + tn = Overseer.typename(typedef) ctypes = COMPONENTDATA_TYPES if !(tn in ctypes) push!(ctypes, tn) if typedef.args[2] isa Symbol - typedef.args[2] = Expr(Symbol("<:"), tn, ECS.ComponentData) + typedef.args[2] = Expr(Symbol("<:"), tn, Overseer.ComponentData) elseif typedef.args[2].head == Symbol("<:") - if !Base.eval(mod, :($(typedef.args[2].args[2]) <: ECS.ComponentData)) + if !Base.eval(mod, :($(typedef.args[2].args[2]) <: Overseer.ComponentData)) error("Components can only have supertypes which are subtypes of ComponentData.") end else @@ -255,13 +255,13 @@ function process_typedef(typedef, mod, with_kw=false) id = length(COMPONENTDATA_TYPES) if with_kw tq = quote - ECS.Parameters.@with_kw $typedef - ECS.component_id(::Type{$tn}) = $id + Overseer.Parameters.@with_kw $typedef + Overseer.component_id(::Type{$tn}) = $id end else tq = quote $typedef - ECS.component_id(::Type{$tn}) = $id + Overseer.component_id(::Type{$tn}) = $id end end return tq, tn @@ -269,10 +269,10 @@ function process_typedef(typedef, mod, with_kw=false) end macro component(typedef) - return esc(ECS._component(typedef, __module__)) + return esc(Overseer._component(typedef, __module__)) end macro component_with_kw(typedef) - return esc(ECS._component(typedef, __module__, true)) + return esc(Overseer._component(typedef, __module__, true)) end function _component(typedef, mod::Module, args...) @@ -281,17 +281,17 @@ function _component(typedef, mod::Module, args...) t1, tn = t return quote $t1 - ECS.component_type(::Type{$tn}) = ECS.Component + Overseer.component_type(::Type{$tn}) = Overseer.Component end end end macro shared_component(typedef) - return esc(ECS._shared_component(typedef, __module__)) + return esc(Overseer._shared_component(typedef, __module__)) end macro shared_component_with_kw(typedef) - return esc(ECS._shared_component(typedef, __module__, true)) + return esc(Overseer._shared_component(typedef, __module__, true)) end function _shared_component(typedef, mod::Module, args...) @@ -300,7 +300,7 @@ function _shared_component(typedef, mod::Module, args...) t1, tn = t return quote $t1 - ECS.component_type(::Type{$tn}) = ECS.SharedComponent + Overseer.component_type(::Type{$tn}) = Overseer.SharedComponent end end end diff --git a/src/entity.jl b/src/entity.jl index 9c1f4ab..87b1d3e 100644 --- a/src/entity.jl +++ b/src/entity.jl @@ -2,7 +2,7 @@ struct Entity id::Int end -function Entity(m::AbstractOverseer) +function Entity(m::AbstractLedger) if !isempty(free_entities(m)) e = pop!(free_entities(m)) entities(m)[e.id] = e @@ -14,7 +14,7 @@ function Entity(m::AbstractOverseer) return e end -function Entity(m::AbstractOverseer, datas::ComponentData...) +function Entity(m::AbstractLedger, datas::ComponentData...) e = Entity(m) for d in datas m[e] = d diff --git a/src/group.jl b/src/group.jl index c9d7095..7921d73 100644 --- a/src/group.jl +++ b/src/group.jl @@ -47,9 +47,9 @@ Base.length(g::OrderedGroup) = g.len Base.in(c::AbstractComponent, g::OrderedGroup) = c in g.components -group(m::AbstractOverseer, cs::Type{<:ComponentData}...; ordered=true) = group(m, map(x -> m[x], cs)) +group(m::AbstractLedger, cs::Type{<:ComponentData}...; ordered=true) = group(m, map(x -> m[x], cs)) -function group(m::AbstractOverseer, comps) +function group(m::AbstractLedger, comps) for g in groups(m) if !(g isa OrderedGroup) continue diff --git a/src/indices.jl b/src/indices.jl index 795f693..b530f92 100644 --- a/src/indices.jl +++ b/src/indices.jl @@ -271,7 +271,7 @@ macro indices_in(indices_expr) else shortest = t_shortest end - ECS.IndicesIterator(shortest, x -> $expr, length(shortest)) + Overseer.IndicesIterator(shortest, x -> $expr, length(shortest)) end) end diff --git a/src/overseer.jl b/src/ledger.jl similarity index 53% rename from src/overseer.jl rename to src/ledger.jl index 104b4df..1800036 100644 --- a/src/overseer.jl +++ b/src/ledger.jl @@ -1,12 +1,12 @@ -#To implement AbstractOverseer interface, the subtype should just define the function manager +#To implement AbstractLedger interface, the subtype should just define the function ledger #where all the fields are like in this one """ - Basic Overseer. This takes care of creating and destroying entities, + Basic Ledger. This takes care of creating and destroying entities, making sure all the requested components for the systems are initialized, and updates the systems. """ -mutable struct Overseer <: AbstractOverseer +mutable struct Ledger <: AbstractLedger entities ::Vector{Entity} free_entities::Vector{Entity} to_delete ::Vector{Entity} @@ -14,22 +14,22 @@ mutable struct Overseer <: AbstractOverseer groups ::Vector{AbstractGroup} # components ::Dict{DataType, Union{Component,SharedComponent}} - system_stages::Vector{SystemStage} + stages::Vector{Stage} end -Overseer() = Overseer(Entity[], +Ledger() = Ledger(Entity[], Entity[], Entity[], Union{Component,SharedComponent}[], AbstractGroup[], Pair{Symbol, Vector{System}}[]) -function Overseer(comps::Vector{Union{Component, SharedComponent}}) - out = Overseer() +function Ledger(comps::Vector{Union{Component, SharedComponent}}) + out = Ledger() out.components = comps return out end -function Overseer(cs::AbstractComponent...) +function Ledger(cs::AbstractComponent...) maxid = length(COMPONENTDATA_TYPES) comps = Vector{Union{Component, SharedComponent}}(undef, maxid) @@ -41,55 +41,55 @@ function Overseer(cs::AbstractComponent...) comps[i] = EMPTY_COMPONENT end end - return Overseer(comps) + return Ledger(comps) end -Overseer(components::Type{<:ComponentData}...) = Overseer(map(x -> component_type(x){x}(), components)...) +Ledger(components::Type{<:ComponentData}...) = Ledger(map(x -> component_type(x){x}(), components)...) -function Overseer(system_stages::SystemStage...) +function Ledger(stages::Stage...) comps = Type{<:ComponentData}[] - for stage in system_stages + for stage in stages append!(comps, requested_components(stage)) end - m = Overseer(comps...) - m.system_stages=[system_stages...] + m = Ledger(comps...) + m.stages=[stages...] prepare(m) return m end -manager(m::Overseer) = m +ledger(m::Ledger) = m -components(m::AbstractOverseer) = manager(m).components -entities(m::AbstractOverseer) = manager(m).entities -free_entities(m::AbstractOverseer) = manager(m).free_entities -to_delete(m::AbstractOverseer) = manager(m).to_delete -valid_entities(m::AbstractOverseer) = filter(x -> x.id != 0, entities(m)) -system_stages(m::AbstractOverseer) = manager(m).system_stages -system_stage(m::AbstractOverseer, s::Symbol) = manager(m).system_stages[s] -singleton(m::AbstractOverseer, ::Type{T}) where {T<:ComponentData} = m[T][1] -groups(m::AbstractOverseer) = manager(m).groups +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 +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<:ComponentData} = m[T][1] ##### BASE Extensions #### -function Base.in(::Type{R}, m::AbstractOverseer) where {R<:ComponentData} +function Base.in(::Type{R}, m::AbstractLedger) where {R<:ComponentData} cid = component_id(R) return cid <= length(components(m)) && components(m)[cid] !== EMPTY_COMPONENT end -function Base.empty!(m::AbstractOverseer) +function Base.empty!(m::AbstractLedger) empty!(entities(m)) empty!(free_entities(m)) empty!(to_delete(m)) empty!(components(m)) - empty!(system_stages(m)) + empty!(stages(m)) empty!(groups(m)) end -function Base.getindex(m::AbstractOverseer, ::Type{T}) where {T<:ComponentData} +function Base.getindex(m::AbstractLedger, ::Type{T}) where {T<:ComponentData} id = component_id(T) return components(m)[id]::component_type(T){T} end -function Base.getindex(m::AbstractOverseer, e::Entity) +function Base.getindex(m::AbstractLedger, e::Entity) entity_assert(m, e) data = ComponentData[] for c in components(m) @@ -100,7 +100,7 @@ function Base.getindex(m::AbstractOverseer, e::Entity) return data end -function Base.getindex(v::Vector{SystemStage}, s::Symbol) +function Base.getindex(v::Vector{Stage}, s::Symbol) id = findfirst(x->first(x) == s, v) if id === nothing error("Stage $s not found.") @@ -108,7 +108,7 @@ function Base.getindex(v::Vector{SystemStage}, s::Symbol) return v[id] end -function Base.setindex!(m::AbstractOverseer, v::T, e::Entity) where {T<:ComponentData} +function Base.setindex!(m::AbstractLedger, v::T, e::Entity) where {T<:ComponentData} entity_assert(m, e) ensure_component!(m, T) if !in(e, m[T]) @@ -119,7 +119,7 @@ function Base.setindex!(m::AbstractOverseer, v::T, e::Entity) where {T<:Componen return m[T][e] = v end -function register_new!(m::AbstractOverseer, ::Type{T}, e::Entity) where {T<:ComponentData} +function register_new!(m::AbstractLedger, ::Type{T}, e::Entity) where {T<:ComponentData} for g in groups(m) if !(g isa OrderedGroup) continue @@ -130,7 +130,7 @@ function register_new!(m::AbstractOverseer, ::Type{T}, e::Entity) where {T<:Comp end end -function ensure_component!(m::AbstractOverseer, c::Type{<:ComponentData}) +function ensure_component!(m::AbstractLedger, c::Type{<:ComponentData}) if !(c in m) m_comps = components(m) id = component_id(c) @@ -143,36 +143,36 @@ function ensure_component!(m::AbstractOverseer, c::Type{<:ComponentData}) end end -function Base.push!(m::AbstractOverseer, stage::SystemStage) +function Base.push!(m::AbstractLedger, stage::Stage) comps = requested_components(stage) for c in comps ensure_component!(m, c) end - push!(system_stages(m), stage) + push!(stages(m), stage) prepare(stage, m) end -function Base.insert!(m::AbstractOverseer, i::Integer, stage::SystemStage) +function Base.insert!(m::AbstractLedger, i::Integer, stage::Stage) comps = requested_components(stage) for c in comps ensure_component!(m, c) end - insert!(system_stages(m), i, stage) + insert!(stages(m), i, stage) prepare(stage, m) end -function Base.push!(m::AbstractOverseer, stage::Symbol, sys::System) - stage = system_stage(m, stage) +function Base.push!(m::AbstractLedger, s::Symbol, sys::System) + st = stage(m, s) comps = requested_components(sys) for c in comps ensure_component!(m, c) end - push!(stage, sys) + push!(st, sys) prepare(sys, m) end -function Base.insert!(m::AbstractOverseer, stage::Symbol, i::Int, sys::System) - insert!(system_stage(m, stage), i, sys) +function Base.insert!(m::AbstractLedger, s::Symbol, i::Int, sys::System) + insert!(stage(m, s), i, sys) comps = requested_components(sys) for c in comps ensure_component!(m, c) @@ -180,7 +180,7 @@ function Base.insert!(m::AbstractOverseer, stage::Symbol, i::Int, sys::System) prepare(sys, m) end -function Base.delete!(m::AbstractOverseer, e::Entity) +function Base.delete!(m::AbstractLedger, e::Entity) entity_assert(m, e) push!(free_entities(m), e) entities(m)[e.id] = EMPTY_ENTITY @@ -191,7 +191,7 @@ function Base.delete!(m::AbstractOverseer, e::Entity) end end -function empty_entities!(m::AbstractOverseer) +function empty_entities!(m::AbstractLedger) empty!(entities(m)) empty!(free_entities(m)) for c in components(m) @@ -199,9 +199,9 @@ function empty_entities!(m::AbstractOverseer) end end -function components(manager::AbstractOverseer, ::Type{T}) where {T<:ComponentData} +function components(ledger::AbstractLedger, ::Type{T}) where {T<:ComponentData} comps = AbstractComponent[] - for c in components(manager) + for c in components(ledger) if eltype(c) <: T push!(comps, c) end @@ -209,18 +209,18 @@ function components(manager::AbstractOverseer, ::Type{T}) where {T<:ComponentDat return comps end -function entity_assert(m::AbstractOverseer, e::Entity) +function entity_assert(m::AbstractLedger, e::Entity) es = entities(m) @assert length(es) >= e.id "$e was never initiated." @assert es[e.id] != EMPTY_ENTITY "$e was removed previously." end -function schedule_delete!(m::AbstractOverseer, e::Entity) +function schedule_delete!(m::AbstractLedger, e::Entity) entity_assert(m, e) push!(to_delete(m), e) end -function delete_scheduled!(m::AbstractOverseer) +function delete_scheduled!(m::AbstractLedger) for c in components(m) delete!(c, to_delete(m)) end @@ -230,20 +230,20 @@ function delete_scheduled!(m::AbstractOverseer) end end -function update(s::SystemStage, m::AbstractOverseer) +function update(s::Stage, m::AbstractLedger) for s in last(s) update(s, m) end end -function update(m::AbstractOverseer) - for stage in system_stages(m) +function update(m::AbstractLedger) + for stage in stages(m) update(stage, m) end end -function prepare(m::AbstractOverseer) - for s in system_stages(m) +function prepare(m::AbstractLedger) + for s in stages(m) prepare(s, m) end end diff --git a/src/system.jl b/src/system.jl index 7ea0640..c309bbe 100644 --- a/src/system.jl +++ b/src/system.jl @@ -1,14 +1,14 @@ -update(::S, m::AbstractOverseer) where {S<:System}= error("No update method implemented for $S") +update(::S, m::AbstractLedger) where {S<:System}= error("No update method implemented for $S") requested_components(::System) = () -const SystemStage = Pair{Symbol, Vector{System}} +const Stage = Pair{Symbol, Vector{System}} -Base.push!(s::SystemStage, sys) = push!(last(s), sys) +Base.push!(s::Stage, sys) = push!(last(s), sys) -Base.insert!(s::SystemStage, i::Integer, sys) = insert!(last(s), i, sys) +Base.insert!(s::Stage, i::Integer, sys) = insert!(last(s), i, sys) -function requested_components(stage::SystemStage) +function requested_components(stage::Stage) comps = Type{<:ComponentData}[] for s in last(stage) for c in requested_components(s) @@ -18,10 +18,10 @@ function requested_components(stage::SystemStage) return comps end -function prepare(s::SystemStage, m::AbstractOverseer) +function prepare(s::Stage, m::AbstractLedger) for sys in last(s) prepare(sys, m) end end -prepare(::System, ::AbstractOverseer) = nothing +prepare(::System, ::AbstractLedger) = nothing diff --git a/test/runtests.jl b/test/runtests.jl index 0805296..e5ff94a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,7 @@ using Test -using ECS +using Overseer @testset "Indices" begin include("test_indices.jl") end @testset "Components" begin include("test_components.jl") end -@testset "Overseer" begin include("test_overseer.jl") end +@testset "Ledger" begin include("test_ledger.jl") end diff --git a/test/test_components.jl b/test/test_components.jl index f37fa1c..d20a9f4 100644 --- a/test/test_components.jl +++ b/test/test_components.jl @@ -1,5 +1,5 @@ -using ECS: Component, SharedComponent, Entity -using ECS: @component, @component_with_kw, @shared_component, @shared_component_with_kw, component_id, component_type, @entities_in +using Overseer: Component, SharedComponent, Entity +using Overseer: @component, @component_with_kw, @shared_component, @shared_component_with_kw, component_id, component_type, @entities_in @component struct Test1 @@ -31,10 +31,10 @@ end @test component_type(Test3) == SharedComponent @test component_type(Test4) == SharedComponent -c1 = ECS.component_type(Test1){Test1}() -c2 = ECS.component_type(Test2){Test2}() -c3 = ECS.component_type(Test3){Test3}() -c4 = ECS.component_type(Test4){Test4}() +c1 = Overseer.component_type(Test1){Test1}() +c2 = Overseer.component_type(Test2){Test2}() +c3 = Overseer.component_type(Test3){Test3}() +c4 = Overseer.component_type(Test4){Test4}() entities1 = [Entity(i) for i in 2:2:10] entities2 = [Entity(i) for i in 10:3:20] diff --git a/test/test_indices.jl b/test/test_indices.jl index bc244f3..4cc1539 100644 --- a/test/test_indices.jl +++ b/test/test_indices.jl @@ -1,4 +1,4 @@ -using ECS: Indices, @indices_in +using Overseer: Indices, @indices_in @testset "Construction, collect" begin data_in = (1,5,100) @@ -47,7 +47,7 @@ end push!(s, 5000) push!(s, 2000) pop!(s, 5000) - @test s.reverse[end] === ECS.NULL_INT_PAGE + @test s.reverse[end] === Overseer.NULL_INT_PAGE b = 1:1000 s = Indices(b) @test collect(s) == collect(b) diff --git a/test/test_overseer.jl b/test/test_ledger.jl similarity index 83% rename from test/test_overseer.jl rename to test/test_ledger.jl index 45b7fb3..47dc977 100644 --- a/test/test_overseer.jl +++ b/test/test_ledger.jl @@ -1,4 +1,4 @@ -using ECS +using Overseer abstract type TComp <: ComponentData end @@ -9,15 +9,15 @@ abstract type TComp <: ComponentData end struct TSys <: System end -function ECS.prepare(::TSys, m::AbstractOverseer) +function Overseer.prepare(::TSys, m::AbstractLedger) if isempty(entities(m)) Entity(m, T4()) end end -ECS.requested_components(::TSys) = (T1, T2, T3, T4) +Overseer.requested_components(::TSys) = (T1, T2, T3, T4) -function ECS.update(::TSys, m::AbstractOverseer) +function Overseer.update(::TSys, m::AbstractLedger) t1 = m[T1] t2 = m[T2] t3 = m[T3] @@ -27,7 +27,7 @@ function ECS.update(::TSys, m::AbstractOverseer) end end -m = Overseer(SystemStage(:default, [TSys()])) +m = Ledger(Stage(:default, [TSys()])) Entity(m, T1(), T2()) Entity(m, T2(), T3()) @@ -44,18 +44,18 @@ update(m) @test length(m[T4]) == 11 empty!(m[T4]) -update(system_stage(m, :default), m) +update(stage(m, :default), m) @test length(m[T4]) == 10 @test length(m[Entity(4)]) == 4 delete!(m, Entity(4)) -@test !isempty(ECS.free_entities(m)) +@test !isempty(Overseer.free_entities(m)) @test length(filter(x->x==Entity(0), m.entities)) == 1 Entity(m, T3()) @test m[T3][Entity(4)] == T3() -@test isempty(ECS.free_entities(m)) +@test isempty(Overseer.free_entities(m)) @test length(m[T4]) == 9 @@ -70,10 +70,10 @@ delete_scheduled!(m) empty!(m) @test isempty(m.entities) -@test isempty(m.system_stages) +@test isempty(m.stages) @test isempty(m.components) -push!(m, SystemStage(:default, [TSys()])) +push!(m, Stage(:default, [TSys()])) @test length(m.components) == 8 @@ -81,15 +81,15 @@ struct TSys2 <: System end push!(m, :default, TSys()) -@test length(last(system_stage(m, :default))) == 2 +@test length(last(stage(m, :default))) == 2 insert!(m, :default, 1, TSys2()) -@test last(system_stage(m, :default))[1] == TSys2() +@test last(stage(m, :default))[1] == TSys2() -insert!(m, 1, SystemStage(:test, [TSys(), TSys2()])) +insert!(m, 1, Stage(:test, [TSys(), TSys2()])) -@test first(m.system_stages[1]) == :test +@test first(m.stages[1]) == :test @test eltype(m[T4]) == T4 @@ -100,11 +100,11 @@ prepare(m) struct SmallSys <: System end -ECS.requested_components(::SmallSys) = (T1, T3) +Overseer.requested_components(::SmallSys) = (T1, T3) -m2 = Overseer(SystemStage(:default, [SmallSys()])) +m2 = Ledger(Stage(:default, [SmallSys()])) -@test m2.components[2] === ECS.EMPTY_COMPONENT +@test m2.components[2] === Overseer.EMPTY_COMPONENT e = Entity(m2) m2[e] = T2() @@ -192,7 +192,7 @@ m[test_entity] = Test3(test_entity.id) # tg = create_group!(m, Test1, Test2; ordered=true) # @test length(groups(m)) == 2 -# @test groups(m)[1] isa ECS.OrderedGroup +# @test groups(m)[1] isa Overseer.OrderedGroup # tg = group(m, Test1, Test2, Test3) # beforelen = length(tg)