Skip to content

Commit

Permalink
Notes. Extra specs. Assure engine is accessible in systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernestas Monkevicius committed Sep 5, 2021
1 parent 5e97d50 commit b46c146
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: fast-ecs
version: 0.1.0
version: 0.1.1

authors:
- Ernestas Monkevicius <[email protected]>
Expand Down
21 changes: 17 additions & 4 deletions spec/engine_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ class TestyComponentB < Fast::ECS::Component
end
end

module TestyComponentC
class C < Fast::ECS::Component
property :number

def initialize(id : Int32, number : Int32)
super(id)
@number = number
end
end
end

Spectator.describe Fast::ECS::Engine do
mock TestySystem do
# stub instance_method(some_number : Int32)
Expand Down Expand Up @@ -326,22 +337,24 @@ Spectator.describe Fast::ECS::Engine do
describe "#query" do
let(:testy_component_b1) { TestyComponentB.new(testy_component_a1.id, 123) }
let(:testy_component_b2) { TestyComponentB.new(testy_component_a2.id, 123) }
let(:testy_component_cc1) { TestyComponentC::C.new(testy_component_a1.id, 123) }

context "when there is at least one entity with requested components" do
before_each do
subject.add_component(testy_component_a1)
subject.add_component(testy_component_b1)
subject.add_component(testy_component_cc1)
end

it "does finds those components" do
components = [] of Array(Fast::ECS::Component)

subject.query(TestyComponentA, TestyComponentB) do |query_set|
compA, compB = query_set
components.push([compA, compB])
subject.query(TestyComponentA, TestyComponentB, TestyComponentC::C) do |query_set|
compA, compB, compCC = query_set
components.push([compA, compB, compCC])
end

expect(components).to eq [[testy_component_a1, testy_component_b1]]
expect(components).to eq [[testy_component_a1, testy_component_b1, testy_component_cc1]]
end
end

Expand Down
4 changes: 4 additions & 0 deletions src/fast_ecs/component.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

# TODO: suggestion was to use flyweight pattern for components to increase RAM efficiency?
# https://refactoring.guru/design-patterns/flyweight

module Fast::ECS
# NOTE: custom components will extend this.
# NOTE: NO METHODS ON COMPONENTS !!!
Expand Down
5 changes: 4 additions & 1 deletion src/fast_ecs/system.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module Fast::ECS
abstract class System
getter :engine
delegate delta_time, to: @engine.not_nil!

def add_engine(engine : Engine)
@engine = engine
end

def engine
@engine.not_nil!
end

# init stuff, engine should run this when system right after system is added
abstract def start

Expand Down

0 comments on commit b46c146

Please sign in to comment.