Skip to content

Commit

Permalink
travis and tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Oct 28, 2019
1 parent 7293788 commit 22a00ef
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 135 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)),
Expand Down
16 changes: 8 additions & 8 deletions src/Overseer.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ECS
module Overseer
using Parameters

abstract type ComponentData end
Expand All @@ -9,25 +9,25 @@ 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")
include("entity.jl")
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
32 changes: 16 additions & 16 deletions src/component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -255,24 +255,24 @@ 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
end
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...)
Expand All @@ -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...)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/entity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 22a00ef

Please sign in to comment.