cyberarm_engine 0.19.0 → 0.19.1

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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -8
  3. data/.rubocop.yml +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/LICENSE.txt +21 -21
  7. data/README.md +74 -74
  8. data/Rakefile +10 -10
  9. data/bin/console +14 -14
  10. data/bin/setup +8 -8
  11. data/cyberarm_engine.gemspec +39 -39
  12. data/lib/cyberarm_engine/animator.rb +219 -219
  13. data/lib/cyberarm_engine/background.rb +179 -179
  14. data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
  15. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  16. data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
  17. data/lib/cyberarm_engine/cache/download_manager.rb +121 -121
  18. data/lib/cyberarm_engine/cache.rb +4 -4
  19. data/lib/cyberarm_engine/common.rb +113 -113
  20. data/lib/cyberarm_engine/config_file.rb +46 -46
  21. data/lib/cyberarm_engine/console/command.rb +157 -157
  22. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
  23. data/lib/cyberarm_engine/console/subcommand.rb +99 -99
  24. data/lib/cyberarm_engine/console.rb +248 -248
  25. data/lib/cyberarm_engine/game_object.rb +248 -248
  26. data/lib/cyberarm_engine/game_state.rb +97 -97
  27. data/lib/cyberarm_engine/model/material.rb +21 -21
  28. data/lib/cyberarm_engine/model/model_object.rb +131 -131
  29. data/lib/cyberarm_engine/model/parser.rb +74 -74
  30. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
  31. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
  32. data/lib/cyberarm_engine/model.rb +212 -212
  33. data/lib/cyberarm_engine/model_cache.rb +31 -31
  34. data/lib/cyberarm_engine/opengl/light.rb +50 -50
  35. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
  36. data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -38
  37. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
  38. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -164
  39. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +298 -298
  40. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -22
  41. data/lib/cyberarm_engine/opengl/shader.rb +406 -406
  42. data/lib/cyberarm_engine/opengl/texture.rb +69 -69
  43. data/lib/cyberarm_engine/opengl.rb +28 -28
  44. data/lib/cyberarm_engine/ray.rb +56 -56
  45. data/lib/cyberarm_engine/stats.rb +21 -21
  46. data/lib/cyberarm_engine/text.rb +197 -197
  47. data/lib/cyberarm_engine/timer.rb +23 -23
  48. data/lib/cyberarm_engine/transform.rb +296 -296
  49. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
  50. data/lib/cyberarm_engine/ui/dsl.rb +139 -139
  51. data/lib/cyberarm_engine/ui/element.rb +488 -488
  52. data/lib/cyberarm_engine/ui/elements/button.rb +97 -97
  53. data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
  54. data/lib/cyberarm_engine/ui/elements/container.rb +256 -256
  55. data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
  56. data/lib/cyberarm_engine/ui/elements/edit_line.rb +263 -263
  57. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
  58. data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
  59. data/lib/cyberarm_engine/ui/elements/list_box.rb +88 -82
  60. data/lib/cyberarm_engine/ui/elements/progress.rb +51 -51
  61. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
  62. data/lib/cyberarm_engine/ui/elements/slider.rb +104 -104
  63. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
  64. data/lib/cyberarm_engine/ui/elements/text_block.rb +162 -162
  65. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -65
  66. data/lib/cyberarm_engine/ui/event.rb +54 -54
  67. data/lib/cyberarm_engine/ui/gui_state.rb +256 -256
  68. data/lib/cyberarm_engine/ui/style.rb +49 -49
  69. data/lib/cyberarm_engine/ui/theme.rb +207 -207
  70. data/lib/cyberarm_engine/vector.rb +293 -293
  71. data/lib/cyberarm_engine/version.rb +4 -4
  72. data/lib/cyberarm_engine/window.rb +120 -120
  73. data/lib/cyberarm_engine.rb +71 -71
  74. metadata +3 -3
@@ -1,121 +1,121 @@
1
- module CyberarmEngine
2
- module Cache
3
- class DownloadManager
4
- attr_reader :downloads
5
-
6
- def initialize(max_parallel_downloads: 4)
7
- @max_parallel_downloads = max_parallel_downloads
8
- @downloads = []
9
- end
10
-
11
- def download(url:, save_as: nil, &callback)
12
- uri = URI(url)
13
- save_as ||= "filename_path" # TODO: if no save_as path is provided, then get one from the Cache controller
14
-
15
- @downloads << Download.new(uri: uri, save_as: save_as, callback: callback)
16
- end
17
-
18
- def status
19
- if active_downloads > 0
20
- :busy
21
- else
22
- :idle
23
- end
24
- end
25
-
26
- def progress
27
- remaining_bytes = @downloads.map { |d| d.remaining_bytes }.sum
28
- total_bytes = @downloads.map { |d| d.total_bytes }.sum
29
-
30
- v = 1.0 - (remaining_bytes.to_f / total_bytes)
31
- return 0.0 if v.nan?
32
-
33
- v
34
- end
35
-
36
- def active_downloads
37
- @downloads.select { |d| %i[pending downloading].include?(d.status) }
38
- end
39
-
40
- def update
41
- @downloads.each do |download|
42
- if download.status == :pending && active_downloads.size <= @max_parallel_downloads
43
- download.status = :downloading
44
- Thread.start { download.download }
45
- end
46
- end
47
- end
48
-
49
- def prune
50
- @downloads.delete_if { |d| d.status == :finished || d.status == :failed }
51
- end
52
-
53
- class Download
54
- attr_accessor :status
55
- attr_reader :uri, :save_as, :callback, :remaining_bytes, :total_downloaded_bytes, :total_bytes,
56
- :error_message, :started_at, :finished_at
57
-
58
- def initialize(uri:, save_as:, callback: nil)
59
- @uri = uri
60
- @save_as = save_as
61
- @callback = callback
62
-
63
- @status = :pending
64
-
65
- @remaining_bytes = 0.0
66
- @total_downloaded_bytes = 0.0
67
- @total_bytes = 0.0
68
-
69
- @error_message = ""
70
- end
71
-
72
- def progress
73
- v = 1.0 - (@remaining_bytes.to_f / total_bytes)
74
- return 0.0 if v.nan?
75
-
76
- v
77
- end
78
-
79
- def download
80
- @status = :downloading
81
- @started_at = Time.now # TODO: monotonic time
82
-
83
- io = File.open(@save_as, "w")
84
- streamer = lambda do |chunk, remaining_bytes, total_bytes|
85
- io.write(chunk)
86
-
87
- @remaining_bytes = remaining_bytes.to_f
88
- @total_downloaded_bytes += chunk.size
89
- @total_bytes = total_bytes.to_f
90
- end
91
-
92
- begin
93
- response = Excon.get(
94
- @uri.to_s,
95
- middlewares: Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
96
- response_block: streamer
97
- )
98
-
99
- if response.status == 200
100
- @status = :finished
101
- @finished_at = Time.now # TODO: monotonic time
102
- @callback.call(self) if @callback
103
- else
104
- @error_message = "Got a non 200 HTTP status of #{response.status}"
105
- @status = :failed
106
- @finished_at = Time.now # TODO: monotonic time
107
- @callback.call(self) if @callback
108
- end
109
- rescue StandardError => e # TODO: cherrypick errors to cature
110
- @status = :failed
111
- @finished_at = Time.now # TODO: monotonic time
112
- @error_message = e.message
113
- @callback.call(self) if @callback
114
- end
115
- ensure
116
- io.close if io
117
- end
118
- end
119
- end
120
- end
121
- end
1
+ module CyberarmEngine
2
+ module Cache
3
+ class DownloadManager
4
+ attr_reader :downloads
5
+
6
+ def initialize(max_parallel_downloads: 4)
7
+ @max_parallel_downloads = max_parallel_downloads
8
+ @downloads = []
9
+ end
10
+
11
+ def download(url:, save_as: nil, &callback)
12
+ uri = URI(url)
13
+ save_as ||= "filename_path" # TODO: if no save_as path is provided, then get one from the Cache controller
14
+
15
+ @downloads << Download.new(uri: uri, save_as: save_as, callback: callback)
16
+ end
17
+
18
+ def status
19
+ if active_downloads > 0
20
+ :busy
21
+ else
22
+ :idle
23
+ end
24
+ end
25
+
26
+ def progress
27
+ remaining_bytes = @downloads.map { |d| d.remaining_bytes }.sum
28
+ total_bytes = @downloads.map { |d| d.total_bytes }.sum
29
+
30
+ v = 1.0 - (remaining_bytes.to_f / total_bytes)
31
+ return 0.0 if v.nan?
32
+
33
+ v
34
+ end
35
+
36
+ def active_downloads
37
+ @downloads.select { |d| %i[pending downloading].include?(d.status) }
38
+ end
39
+
40
+ def update
41
+ @downloads.each do |download|
42
+ if download.status == :pending && active_downloads.size <= @max_parallel_downloads
43
+ download.status = :downloading
44
+ Thread.start { download.download }
45
+ end
46
+ end
47
+ end
48
+
49
+ def prune
50
+ @downloads.delete_if { |d| d.status == :finished || d.status == :failed }
51
+ end
52
+
53
+ class Download
54
+ attr_accessor :status
55
+ attr_reader :uri, :save_as, :callback, :remaining_bytes, :total_downloaded_bytes, :total_bytes,
56
+ :error_message, :started_at, :finished_at
57
+
58
+ def initialize(uri:, save_as:, callback: nil)
59
+ @uri = uri
60
+ @save_as = save_as
61
+ @callback = callback
62
+
63
+ @status = :pending
64
+
65
+ @remaining_bytes = 0.0
66
+ @total_downloaded_bytes = 0.0
67
+ @total_bytes = 0.0
68
+
69
+ @error_message = ""
70
+ end
71
+
72
+ def progress
73
+ v = 1.0 - (@remaining_bytes.to_f / total_bytes)
74
+ return 0.0 if v.nan?
75
+
76
+ v
77
+ end
78
+
79
+ def download
80
+ @status = :downloading
81
+ @started_at = Time.now # TODO: monotonic time
82
+
83
+ io = File.open(@save_as, "w")
84
+ streamer = lambda do |chunk, remaining_bytes, total_bytes|
85
+ io.write(chunk)
86
+
87
+ @remaining_bytes = remaining_bytes.to_f
88
+ @total_downloaded_bytes += chunk.size
89
+ @total_bytes = total_bytes.to_f
90
+ end
91
+
92
+ begin
93
+ response = Excon.get(
94
+ @uri.to_s,
95
+ middlewares: Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
96
+ response_block: streamer
97
+ )
98
+
99
+ if response.status == 200
100
+ @status = :finished
101
+ @finished_at = Time.now # TODO: monotonic time
102
+ @callback.call(self) if @callback
103
+ else
104
+ @error_message = "Got a non 200 HTTP status of #{response.status}"
105
+ @status = :failed
106
+ @finished_at = Time.now # TODO: monotonic time
107
+ @callback.call(self) if @callback
108
+ end
109
+ rescue StandardError => e # TODO: cherrypick errors to cature
110
+ @status = :failed
111
+ @finished_at = Time.now # TODO: monotonic time
112
+ @error_message = e.message
113
+ @callback.call(self) if @callback
114
+ end
115
+ ensure
116
+ io.close if io
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -1,4 +1,4 @@
1
- module CyberarmEngine
2
- module Cache
3
- end
4
- end
1
+ module CyberarmEngine
2
+ module Cache
3
+ end
4
+ end
@@ -1,113 +1,113 @@
1
- module CyberarmEngine
2
- module Common
3
- def push_state(klass, options = {})
4
- window.push_state(klass, options)
5
- end
6
-
7
- def current_state
8
- window.current_state
9
- end
10
-
11
- def previous_state
12
- window.previous_state
13
- end
14
-
15
- def pop_state
16
- window.pop_state
17
- end
18
-
19
- def shift_state
20
- window.shift_state
21
- end
22
-
23
- def show_cursor
24
- window.show_cursor
25
- end
26
-
27
- def show_cursor=(boolean)
28
- window.show_cursor = boolean
29
- end
30
-
31
- def draw_rect(x, y, width, height, color, z = 0, mode = :default)
32
- Gosu.draw_rect(x, y, width, height, color, z, mode)
33
- end
34
-
35
- def fill(color, z = 0)
36
- draw_rect(0, 0, window.width, window.height, color, z)
37
- end
38
-
39
- def lighten(color, amount = 25)
40
- if defined?(color.alpha)
41
- Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
42
- else
43
- Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
44
- end
45
- end
46
-
47
- def darken(color, amount = 25)
48
- if defined?(color.alpha)
49
- Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
50
- else
51
- Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
52
- end
53
- end
54
-
55
- def opacity(color, ratio = 1.0)
56
- alpha = 255 * ratio
57
-
58
- Gosu::Color.rgba(color.red, color.green, color.blue, alpha)
59
- end
60
-
61
- def get_asset(path, hash, klass, retro = false, tileable = false)
62
- asset = nil
63
- hash.detect do |_asset, instance|
64
- if _asset == path
65
- asset = instance
66
- true
67
- end
68
- end
69
-
70
- unless asset
71
- instance = nil
72
- instance = if klass == Gosu::Image
73
- klass.new(path, retro: retro, tileable: tileable)
74
- else
75
- klass.new(path)
76
- end
77
-
78
- hash[path] = instance
79
- asset = instance
80
- end
81
-
82
- asset
83
- end
84
-
85
- def get_image(path, retro: false, tileable: false)
86
- get_asset(path, Window::IMAGES, Gosu::Image, retro, tileable)
87
- end
88
-
89
- def get_sample(path)
90
- get_asset(path, Window::SAMPLES, Gosu::Sample)
91
- end
92
-
93
- def get_song(path)
94
- get_asset(path, Window::SONGS, Gosu::Song)
95
- end
96
-
97
- def window
98
- $window
99
- end
100
-
101
- def control_down?
102
- Gosu.button_down?(Gosu::KB_LEFT_CONTROL) || Gosu.button_down?(Gosu::KB_RIGHT_CONTROL)
103
- end
104
-
105
- def shift_down?
106
- Gosu.button_down?(Gosu::KB_LEFT_SHIFT) || Gosu.button_down?(Gosu::KB_RIGHT_SHIFT)
107
- end
108
-
109
- def alt_down?
110
- Gosu.button_down?(Gosu::KB_LEFT_ALT) || Gosu.button_down?(Gosu::KB_RIGHT_ALT)
111
- end
112
- end
113
- end
1
+ module CyberarmEngine
2
+ module Common
3
+ def push_state(klass, options = {})
4
+ window.push_state(klass, options)
5
+ end
6
+
7
+ def current_state
8
+ window.current_state
9
+ end
10
+
11
+ def previous_state
12
+ window.previous_state
13
+ end
14
+
15
+ def pop_state
16
+ window.pop_state
17
+ end
18
+
19
+ def shift_state
20
+ window.shift_state
21
+ end
22
+
23
+ def show_cursor
24
+ window.show_cursor
25
+ end
26
+
27
+ def show_cursor=(boolean)
28
+ window.show_cursor = boolean
29
+ end
30
+
31
+ def draw_rect(x, y, width, height, color, z = 0, mode = :default)
32
+ Gosu.draw_rect(x, y, width, height, color, z, mode)
33
+ end
34
+
35
+ def fill(color, z = 0)
36
+ draw_rect(0, 0, window.width, window.height, color, z)
37
+ end
38
+
39
+ def lighten(color, amount = 25)
40
+ if defined?(color.alpha)
41
+ Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
42
+ else
43
+ Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
44
+ end
45
+ end
46
+
47
+ def darken(color, amount = 25)
48
+ if defined?(color.alpha)
49
+ Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
50
+ else
51
+ Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
52
+ end
53
+ end
54
+
55
+ def opacity(color, ratio = 1.0)
56
+ alpha = 255 * ratio
57
+
58
+ Gosu::Color.rgba(color.red, color.green, color.blue, alpha)
59
+ end
60
+
61
+ def get_asset(path, hash, klass, retro = false, tileable = false)
62
+ asset = nil
63
+ hash.detect do |_asset, instance|
64
+ if _asset == path
65
+ asset = instance
66
+ true
67
+ end
68
+ end
69
+
70
+ unless asset
71
+ instance = nil
72
+ instance = if klass == Gosu::Image
73
+ klass.new(path, retro: retro, tileable: tileable)
74
+ else
75
+ klass.new(path)
76
+ end
77
+
78
+ hash[path] = instance
79
+ asset = instance
80
+ end
81
+
82
+ asset
83
+ end
84
+
85
+ def get_image(path, retro: false, tileable: false)
86
+ get_asset(path, Window::IMAGES, Gosu::Image, retro, tileable)
87
+ end
88
+
89
+ def get_sample(path)
90
+ get_asset(path, Window::SAMPLES, Gosu::Sample)
91
+ end
92
+
93
+ def get_song(path)
94
+ get_asset(path, Window::SONGS, Gosu::Song)
95
+ end
96
+
97
+ def window
98
+ $window
99
+ end
100
+
101
+ def control_down?
102
+ Gosu.button_down?(Gosu::KB_LEFT_CONTROL) || Gosu.button_down?(Gosu::KB_RIGHT_CONTROL)
103
+ end
104
+
105
+ def shift_down?
106
+ Gosu.button_down?(Gosu::KB_LEFT_SHIFT) || Gosu.button_down?(Gosu::KB_RIGHT_SHIFT)
107
+ end
108
+
109
+ def alt_down?
110
+ Gosu.button_down?(Gosu::KB_LEFT_ALT) || Gosu.button_down?(Gosu::KB_RIGHT_ALT)
111
+ end
112
+ end
113
+ end
@@ -1,46 +1,46 @@
1
- module CyberarmEngine
2
- class ConfigFile
3
- def initialize(file:)
4
- @file = file
5
-
6
- if File.exist?(@file)
7
- deserialize
8
- else
9
- @data = {}
10
- end
11
- end
12
-
13
- def []=(*keys, value)
14
- last_key = keys.last
15
-
16
- if keys.size == 1
17
- hash = @data
18
- else
19
- keys.pop
20
- hash = @data[keys.shift] ||= {}
21
-
22
- keys.each do |key|
23
- hash = hash[key] ||= {}
24
- end
25
- end
26
-
27
- hash[last_key] = value
28
- end
29
-
30
- def get(*keys)
31
- @data.dig(*keys)
32
- end
33
-
34
- def serialize
35
- JSON.dump(@data)
36
- end
37
-
38
- def deserialize
39
- @data = JSON.parse(File.read(@file), symbolize_names: true)
40
- end
41
-
42
- def save!
43
- File.open(@file, "w") { |f| f.write(serialize) }
44
- end
45
- end
46
- end
1
+ module CyberarmEngine
2
+ class ConfigFile
3
+ def initialize(file:)
4
+ @file = file
5
+
6
+ if File.exist?(@file)
7
+ deserialize
8
+ else
9
+ @data = {}
10
+ end
11
+ end
12
+
13
+ def []=(*keys, value)
14
+ last_key = keys.last
15
+
16
+ if keys.size == 1
17
+ hash = @data
18
+ else
19
+ keys.pop
20
+ hash = @data[keys.shift] ||= {}
21
+
22
+ keys.each do |key|
23
+ hash = hash[key] ||= {}
24
+ end
25
+ end
26
+
27
+ hash[last_key] = value
28
+ end
29
+
30
+ def get(*keys)
31
+ @data.dig(*keys)
32
+ end
33
+
34
+ def serialize
35
+ JSON.dump(@data)
36
+ end
37
+
38
+ def deserialize
39
+ @data = JSON.parse(File.read(@file), symbolize_names: true)
40
+ end
41
+
42
+ def save!
43
+ File.open(@file, "w") { |f| f.write(serialize) }
44
+ end
45
+ end
46
+ end