baku 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +46 -9
- data/CHANGELOG.md +5 -1
- data/baku.gemspec +17 -17
- data/lib/baku/component_system.rb +35 -0
- data/lib/baku/entity.rb +1 -1
- data/lib/baku/entity_manager.rb +16 -8
- data/lib/baku/system.rb +7 -15
- data/lib/baku/tag_system.rb +24 -0
- data/lib/baku/version.rb +1 -1
- data/lib/baku/world.rb +2 -4
- data/lib/baku.rb +3 -2
- metadata +22 -8
- data/lib/baku/event_dispatcher.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 53f4e7b623eac99e2c4ecbbc31d94cfddb83f385ce312b4dcd140d53b22c9ba7
|
4
|
+
data.tar.gz: a0e5df631d32755e2cf7c783981bede609d92e6bb1526229e1936bfe2549cb12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fe0db7915bc10d2f523a6a8961b63a0ab4bb013d1cec3c4b28d3dfa922f785dd4b54ab7365fa80d518d302b7473c5f2fd01bc2f4ecb53b5500cbce9a49cac7b
|
7
|
+
data.tar.gz: a8f2c0261f124e16045135205dc87955b18818cb0e12f18f227b159a2e6718b9047e713478c6058da2a191dc27704b1dcc7251e469b10e1ef05117cae043422f
|
data/.gitignore
CHANGED
@@ -1,15 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
/_yardoc/
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
5
4
|
/coverage/
|
6
|
-
/
|
5
|
+
/InstalledFiles
|
7
6
|
/pkg/
|
8
7
|
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
9
11
|
/tmp/
|
10
12
|
|
11
|
-
#
|
12
|
-
.
|
13
|
-
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
Gemfile.lock
|
14
46
|
.ruby-version
|
15
|
-
.ruby-gemset
|
47
|
+
.ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
51
|
+
|
52
|
+
.rspec_status
|
data/CHANGELOG.md
CHANGED
data/baku.gemspec
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require 'baku/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'baku'
|
8
7
|
spec.version = Baku::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['John Tuttle']
|
9
|
+
spec.email = ['jtuttle.develops@gmail.com']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
11
|
+
spec.summary = 'An Entity Component System framework for Ruby'
|
12
|
+
spec.description = 'An Entity Component System framework for Ruby'
|
13
|
+
spec.homepage = 'https://github.com/jtuttle/baku'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
|
16
|
+
# use double quotes for "\x0" (https://github.com/bundler/bundler/issues/4133)
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
18
|
f.match(%r{^(test|spec|features)/})
|
19
19
|
end
|
20
|
-
spec.
|
21
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = ["lib"]
|
20
|
+
spec.require_paths = ['lib']
|
23
21
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', '~> 2.0.2'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.5.0'
|
26
|
+
|
27
|
+
spec.add_dependency 'miru', '~> 0.1.0'
|
28
28
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'system'
|
2
|
+
|
3
|
+
module Baku
|
4
|
+
class ComponentSystem < System
|
5
|
+
attr_reader :components
|
6
|
+
|
7
|
+
def initialize(components, game_loop_step)
|
8
|
+
@components = components
|
9
|
+
@game_loop_step = game_loop_step
|
10
|
+
end
|
11
|
+
|
12
|
+
def register_world(world)
|
13
|
+
super(world)
|
14
|
+
|
15
|
+
world.entity_manager.register_component_mask(component_mask)
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_entities(entities)
|
19
|
+
entities.each do |entity|
|
20
|
+
entity_components = @components.map { |c| entity.get_component(c) }
|
21
|
+
process_entity(entity, *entity_components)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def component_mask
|
26
|
+
@component_mask ||= ComponentMask.from_components(@components)
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def retrieve_entities
|
32
|
+
@world.entity_manager.get_entities(component_mask)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/baku/entity.rb
CHANGED
data/lib/baku/entity_manager.rb
CHANGED
@@ -21,10 +21,14 @@ module Baku
|
|
21
21
|
def add_entity(entity)
|
22
22
|
add_entity_to_matching_component_lists(entity)
|
23
23
|
|
24
|
-
entity.add_event_listener(
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
entity.add_event_listener(
|
25
|
+
:component_added,
|
26
|
+
method(:on_entity_component_added)
|
27
|
+
)
|
28
|
+
entity.add_event_listener(
|
29
|
+
:component_removed,
|
30
|
+
method(:on_entity_component_removed)
|
31
|
+
)
|
28
32
|
|
29
33
|
entity.tags.each do |tag|
|
30
34
|
@entities_by_tag[tag] ||= []
|
@@ -37,10 +41,14 @@ module Baku
|
|
37
41
|
@entities_by_tag[tag].delete(entity)
|
38
42
|
end
|
39
43
|
|
40
|
-
entity.remove_event_listener(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
entity.remove_event_listener(
|
45
|
+
:component_added,
|
46
|
+
method(:on_entity_component_added)
|
47
|
+
)
|
48
|
+
entity.remove_event_listener(
|
49
|
+
:component_removed,
|
50
|
+
method(:on_entity_component_removed)
|
51
|
+
)
|
44
52
|
|
45
53
|
@entities_by_component_mask.each do |component_mask, entities|
|
46
54
|
if component_mask.matches?(entity.component_mask)
|
data/lib/baku/system.rb
CHANGED
@@ -1,42 +1,34 @@
|
|
1
1
|
module Baku
|
2
2
|
class System
|
3
3
|
attr_reader :components, :game_loop_step
|
4
|
-
attr_writer :world
|
5
4
|
|
6
5
|
def initialize(components, game_loop_step)
|
7
6
|
@components = components
|
8
7
|
@game_loop_step = game_loop_step
|
9
8
|
end
|
10
9
|
|
10
|
+
def register_world(world)
|
11
|
+
@world = world
|
12
|
+
end
|
13
|
+
|
11
14
|
def execute
|
12
15
|
if @world.nil?
|
13
16
|
raise StandardError.new("Must set :world property of System.")
|
14
17
|
end
|
15
18
|
|
16
|
-
entities =
|
19
|
+
entities = retrieve_entities
|
17
20
|
|
18
21
|
process_entities(entities)
|
19
22
|
end
|
20
|
-
|
21
|
-
def process_entities(entities)
|
22
|
-
entities.each do |entity|
|
23
|
-
entity_components = @components.map { |c| entity.get_component(c) }
|
24
|
-
process_entity(entity, *entity_components)
|
25
|
-
end
|
26
|
-
end
|
27
23
|
|
28
24
|
def process_entity(entity)
|
29
25
|
raise NotImplementedError
|
30
26
|
end
|
31
27
|
|
32
|
-
|
33
|
-
@component_mask ||= ComponentMask.from_components(@components)
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
28
|
+
protected
|
37
29
|
|
38
30
|
def retrieve_entities
|
39
|
-
|
31
|
+
raise NotImplementedError
|
40
32
|
end
|
41
33
|
end
|
42
34
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'system'
|
2
|
+
|
3
|
+
module Baku
|
4
|
+
class TagSystem < System
|
5
|
+
attr_reader :tag
|
6
|
+
|
7
|
+
def initialize(tag, game_loop_step)
|
8
|
+
@tag = tag
|
9
|
+
@game_loop_step = game_loop_step
|
10
|
+
end
|
11
|
+
|
12
|
+
def process_entities(entities)
|
13
|
+
entities.each do |entity|
|
14
|
+
process_entity(entity)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def retrieve_entities
|
21
|
+
@world.entity_manager.get_entities_by_tag(@tag)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/baku/version.rb
CHANGED
data/lib/baku/world.rb
CHANGED
@@ -31,12 +31,10 @@ module Baku
|
|
31
31
|
if system_list.map(&:class).include?(system.class)
|
32
32
|
raise StandardError.new("Already added #{system.class} system to world.")
|
33
33
|
end
|
34
|
-
|
35
|
-
system_list << system
|
36
34
|
|
37
|
-
|
35
|
+
system.register_world(self)
|
38
36
|
|
39
|
-
|
37
|
+
system_list << system
|
40
38
|
end
|
41
39
|
|
42
40
|
def create_entity(tags = [])
|
data/lib/baku.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Tuttle
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.2
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.5.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: miru
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.1.0
|
69
83
|
description: An Entity Component System framework for Ruby
|
70
84
|
email:
|
71
85
|
- jtuttle.develops@gmail.com
|
@@ -87,10 +101,11 @@ files:
|
|
87
101
|
- lib/baku.rb
|
88
102
|
- lib/baku/component.rb
|
89
103
|
- lib/baku/component_mask.rb
|
104
|
+
- lib/baku/component_system.rb
|
90
105
|
- lib/baku/entity.rb
|
91
106
|
- lib/baku/entity_manager.rb
|
92
|
-
- lib/baku/event_dispatcher.rb
|
93
107
|
- lib/baku/system.rb
|
108
|
+
- lib/baku/tag_system.rb
|
94
109
|
- lib/baku/version.rb
|
95
110
|
- lib/baku/world.rb
|
96
111
|
homepage: https://github.com/jtuttle/baku
|
@@ -112,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
127
|
- !ruby/object:Gem::Version
|
113
128
|
version: '0'
|
114
129
|
requirements: []
|
115
|
-
|
116
|
-
rubygems_version: 2.6.12
|
130
|
+
rubygems_version: 3.0.6
|
117
131
|
signing_key:
|
118
132
|
specification_version: 4
|
119
133
|
summary: An Entity Component System framework for Ruby
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Baku
|
2
|
-
module EventDispatcher
|
3
|
-
def add_event_listener(event_name, method)
|
4
|
-
@event_listeners ||= {}
|
5
|
-
@event_listeners[event_name] ||= []
|
6
|
-
|
7
|
-
@event_listeners[event_name] << method
|
8
|
-
end
|
9
|
-
|
10
|
-
def remove_event_listener(event_name, method)
|
11
|
-
@event_listeners[event_name].delete(method)
|
12
|
-
end
|
13
|
-
|
14
|
-
def dispatch_event(event_name, *args)
|
15
|
-
return unless @event_listeners && @event_listeners.has_key?(event_name)
|
16
|
-
@event_listeners[event_name].each { |f| f.call(*args) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|