bubblezone 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +347 -16
- data/bubblezone.gemspec +2 -0
- data/ext/bubblezone/extconf.rb +65 -0
- data/ext/bubblezone/extension.c +107 -0
- data/ext/bubblezone/extension.h +36 -0
- data/ext/bubblezone/manager.c +127 -0
- data/ext/bubblezone/zone_info.c +100 -0
- data/go/bubblezone.go +369 -0
- data/go/go.mod +28 -0
- data/go/go.sum +47 -0
- data/lib/bubblezone/manager.rb +56 -0
- data/lib/bubblezone/version.rb +1 -1
- data/lib/bubblezone/zone_info.rb +25 -0
- data/lib/bubblezone.rb +52 -1
- metadata +14 -2
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bubblezone
|
|
4
|
+
class Manager
|
|
5
|
+
def zone_ids_set
|
|
6
|
+
@zone_ids_set ||= Set.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def zone_ids_mutex
|
|
10
|
+
@zone_ids_mutex ||= Mutex.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
alias _native_mark mark
|
|
14
|
+
|
|
15
|
+
def mark(zone_id, text)
|
|
16
|
+
zone_ids_mutex.synchronize { zone_ids_set.add(zone_id) }
|
|
17
|
+
_native_mark(zone_id, text)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
alias _native_clear clear
|
|
21
|
+
|
|
22
|
+
def clear(zone_id)
|
|
23
|
+
zone_ids_mutex.synchronize { zone_ids_set.delete(zone_id) }
|
|
24
|
+
_native_clear(zone_id)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def clear_all
|
|
28
|
+
zone_ids_mutex.synchronize do
|
|
29
|
+
zone_ids_set.each { |id| _native_clear(id) }
|
|
30
|
+
zone_ids_set.clear
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def zone_ids
|
|
35
|
+
zone_ids_mutex.synchronize { zone_ids_set.to_a }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def each_in_bounds(x, y)
|
|
39
|
+
return enum_for(:each_in_bounds, x, y) unless block_given?
|
|
40
|
+
|
|
41
|
+
ids = zone_ids_mutex.synchronize { zone_ids_set.to_a.sort }
|
|
42
|
+
ids.each do |id|
|
|
43
|
+
zone = get(id)
|
|
44
|
+
yield(id, zone) if zone&.in_bounds?(x, y)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def any_in_bounds?(x, y)
|
|
49
|
+
each_in_bounds(x, y).any?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def find_in_bounds(x, y)
|
|
53
|
+
each_in_bounds(x, y).first
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
data/lib/bubblezone/version.rb
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bubblezone
|
|
4
|
+
class ZoneInfo
|
|
5
|
+
def width
|
|
6
|
+
end_x - start_x + 1
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def height
|
|
10
|
+
end_y - start_y + 1
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def size
|
|
14
|
+
[width, height]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_s
|
|
18
|
+
"ZoneInfo(start: (#{start_x}, #{start_y}), end: (#{end_x}, #{end_y}))"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def inspect
|
|
22
|
+
"#<#{self.class} start_x=#{start_x} start_y=#{start_y} end_x=#{end_x} end_y=#{end_y}>"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/bubblezone.rb
CHANGED
|
@@ -1,8 +1,59 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "bubblezone/version"
|
|
4
|
+
require_relative "bubblezone/bubblezone"
|
|
5
|
+
require_relative "bubblezone/manager"
|
|
6
|
+
require_relative "bubblezone/zone_info"
|
|
4
7
|
|
|
5
8
|
module Bubblezone
|
|
6
9
|
class Error < StandardError; end
|
|
7
|
-
|
|
10
|
+
|
|
11
|
+
@global_zone_ids = Set.new
|
|
12
|
+
@global_zone_ids_mutex = Mutex.new
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
alias _native_mark mark
|
|
16
|
+
|
|
17
|
+
def mark(zone_id, text)
|
|
18
|
+
@global_zone_ids_mutex.synchronize { @global_zone_ids.add(zone_id) }
|
|
19
|
+
_native_mark(zone_id, text)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
alias _native_clear clear
|
|
23
|
+
|
|
24
|
+
def clear(zone_id)
|
|
25
|
+
@global_zone_ids_mutex.synchronize { @global_zone_ids.delete(zone_id) }
|
|
26
|
+
_native_clear(zone_id)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def clear_all
|
|
30
|
+
@global_zone_ids_mutex.synchronize do
|
|
31
|
+
@global_zone_ids.each { |id| _native_clear(id) }
|
|
32
|
+
@global_zone_ids.clear
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def zone_ids
|
|
37
|
+
@global_zone_ids_mutex.synchronize { @global_zone_ids.to_a }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def each_in_bounds(x, y)
|
|
41
|
+
return enum_for(:each_in_bounds, x, y) unless block_given?
|
|
42
|
+
|
|
43
|
+
ids = @global_zone_ids_mutex.synchronize { @global_zone_ids.to_a.sort }
|
|
44
|
+
|
|
45
|
+
ids.each do |id|
|
|
46
|
+
zone = get(id)
|
|
47
|
+
yield(id, zone) if zone&.in_bounds?(x, y)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def any_in_bounds?(x, y)
|
|
52
|
+
each_in_bounds(x, y).any?
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def find_in_bounds(x, y)
|
|
56
|
+
each_in_bounds(x, y).first
|
|
57
|
+
end
|
|
58
|
+
end
|
|
8
59
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bubblezone
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marco Roth
|
|
@@ -28,13 +28,25 @@ description: Ruby bindings for the bubblezone, providing zone management for ter
|
|
|
28
28
|
email:
|
|
29
29
|
- marco.roth@intergga.ch
|
|
30
30
|
executables: []
|
|
31
|
-
extensions:
|
|
31
|
+
extensions:
|
|
32
|
+
- ext/bubblezone/extconf.rb
|
|
32
33
|
extra_rdoc_files: []
|
|
33
34
|
files:
|
|
35
|
+
- LICENSE.txt
|
|
34
36
|
- README.md
|
|
35
37
|
- bubblezone.gemspec
|
|
38
|
+
- ext/bubblezone/extconf.rb
|
|
39
|
+
- ext/bubblezone/extension.c
|
|
40
|
+
- ext/bubblezone/extension.h
|
|
41
|
+
- ext/bubblezone/manager.c
|
|
42
|
+
- ext/bubblezone/zone_info.c
|
|
43
|
+
- go/bubblezone.go
|
|
44
|
+
- go/go.mod
|
|
45
|
+
- go/go.sum
|
|
36
46
|
- lib/bubblezone.rb
|
|
47
|
+
- lib/bubblezone/manager.rb
|
|
37
48
|
- lib/bubblezone/version.rb
|
|
49
|
+
- lib/bubblezone/zone_info.rb
|
|
38
50
|
homepage: https://github.com/marcoroth/bubblezone-ruby
|
|
39
51
|
licenses:
|
|
40
52
|
- MIT
|