cyberarm_engine 0.19.0 → 0.19.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +39 -39
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +179 -179
- data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
- data/lib/cyberarm_engine/cache/download_manager.rb +121 -121
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +113 -113
- data/lib/cyberarm_engine/config_file.rb +46 -46
- data/lib/cyberarm_engine/console/command.rb +157 -157
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
- data/lib/cyberarm_engine/console/subcommand.rb +99 -99
- data/lib/cyberarm_engine/console.rb +248 -248
- data/lib/cyberarm_engine/game_object.rb +248 -248
- data/lib/cyberarm_engine/game_state.rb +97 -97
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/model_object.rb +131 -131
- data/lib/cyberarm_engine/model/parser.rb +74 -74
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
- data/lib/cyberarm_engine/model.rb +212 -212
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/opengl/light.rb +50 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -164
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +298 -298
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -22
- data/lib/cyberarm_engine/opengl/shader.rb +406 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +28 -28
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +21 -21
- data/lib/cyberarm_engine/text.rb +197 -197
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +139 -139
- data/lib/cyberarm_engine/ui/element.rb +488 -488
- data/lib/cyberarm_engine/ui/elements/button.rb +97 -97
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +256 -256
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +263 -263
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
- data/lib/cyberarm_engine/ui/elements/list_box.rb +88 -82
- data/lib/cyberarm_engine/ui/elements/progress.rb +51 -51
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +104 -104
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +162 -162
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -65
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +256 -256
- data/lib/cyberarm_engine/ui/style.rb +49 -49
- data/lib/cyberarm_engine/ui/theme.rb +207 -207
- data/lib/cyberarm_engine/vector.rb +293 -293
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +120 -120
- data/lib/cyberarm_engine.rb +71 -71
- metadata +3 -3
@@ -1,69 +1,69 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Texture
|
3
|
-
DEFAULT_TEXTURE = "#{CYBERARM_ENGINE_ROOT_PATH}/assets/textures/default.png".freeze
|
4
|
-
|
5
|
-
CACHE = {}
|
6
|
-
|
7
|
-
def self.release_textures
|
8
|
-
CACHE.values.each do |id|
|
9
|
-
glDeleteTextures(id)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.from_cache(path, retro)
|
14
|
-
CACHE.dig("#{path}?retro=#{retro}")
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :id
|
18
|
-
|
19
|
-
def initialize(path: nil, image: nil, retro: false)
|
20
|
-
raise "keyword :path or :image must be provided!" if path.nil? && image.nil?
|
21
|
-
|
22
|
-
@retro = retro
|
23
|
-
@path = path
|
24
|
-
|
25
|
-
if @path
|
26
|
-
unless File.exist?(@path)
|
27
|
-
warn "Missing texture at: #{@path}"
|
28
|
-
@retro = true # override retro setting
|
29
|
-
@path = DEFAULT_TEXTURE
|
30
|
-
end
|
31
|
-
|
32
|
-
if texture = Texture.from_cache(@path, @retro)
|
33
|
-
@id = texture.id
|
34
|
-
return
|
35
|
-
end
|
36
|
-
|
37
|
-
image = load_image(@path)
|
38
|
-
@id = create_from_image(image)
|
39
|
-
else
|
40
|
-
@id = create_from_image(image)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def load_image(path)
|
45
|
-
CACHE["#{path}?retro=#{@retro}"] = self
|
46
|
-
Gosu::Image.new(path, retro: @retro)
|
47
|
-
end
|
48
|
-
|
49
|
-
def create_from_image(image)
|
50
|
-
array_of_pixels = image.to_blob
|
51
|
-
|
52
|
-
tex_names_buf = " " * 4
|
53
|
-
glGenTextures(1, tex_names_buf)
|
54
|
-
texture_id = tex_names_buf.unpack1("L2")
|
55
|
-
|
56
|
-
glBindTexture(GL_TEXTURE_2D, texture_id)
|
57
|
-
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array_of_pixels)
|
58
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
59
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
60
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) if @retro
|
61
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) unless @retro
|
62
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
|
63
|
-
glGenerateMipmap(GL_TEXTURE_2D)
|
64
|
-
gl_error?
|
65
|
-
|
66
|
-
texture_id
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Texture
|
3
|
+
DEFAULT_TEXTURE = "#{CYBERARM_ENGINE_ROOT_PATH}/assets/textures/default.png".freeze
|
4
|
+
|
5
|
+
CACHE = {}
|
6
|
+
|
7
|
+
def self.release_textures
|
8
|
+
CACHE.values.each do |id|
|
9
|
+
glDeleteTextures(id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.from_cache(path, retro)
|
14
|
+
CACHE.dig("#{path}?retro=#{retro}")
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :id
|
18
|
+
|
19
|
+
def initialize(path: nil, image: nil, retro: false)
|
20
|
+
raise "keyword :path or :image must be provided!" if path.nil? && image.nil?
|
21
|
+
|
22
|
+
@retro = retro
|
23
|
+
@path = path
|
24
|
+
|
25
|
+
if @path
|
26
|
+
unless File.exist?(@path)
|
27
|
+
warn "Missing texture at: #{@path}"
|
28
|
+
@retro = true # override retro setting
|
29
|
+
@path = DEFAULT_TEXTURE
|
30
|
+
end
|
31
|
+
|
32
|
+
if texture = Texture.from_cache(@path, @retro)
|
33
|
+
@id = texture.id
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
image = load_image(@path)
|
38
|
+
@id = create_from_image(image)
|
39
|
+
else
|
40
|
+
@id = create_from_image(image)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_image(path)
|
45
|
+
CACHE["#{path}?retro=#{@retro}"] = self
|
46
|
+
Gosu::Image.new(path, retro: @retro)
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_from_image(image)
|
50
|
+
array_of_pixels = image.to_blob
|
51
|
+
|
52
|
+
tex_names_buf = " " * 4
|
53
|
+
glGenTextures(1, tex_names_buf)
|
54
|
+
texture_id = tex_names_buf.unpack1("L2")
|
55
|
+
|
56
|
+
glBindTexture(GL_TEXTURE_2D, texture_id)
|
57
|
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array_of_pixels)
|
58
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
59
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
60
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) if @retro
|
61
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) unless @retro
|
62
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
|
63
|
+
glGenerateMipmap(GL_TEXTURE_2D)
|
64
|
+
gl_error?
|
65
|
+
|
66
|
+
texture_id
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
begin
|
2
|
-
require "opengl"
|
3
|
-
rescue LoadError
|
4
|
-
puts "Required gem is not installed, please install 'opengl-bindings' and try again."
|
5
|
-
exit(1)
|
6
|
-
end
|
7
|
-
|
8
|
-
module CyberarmEngine
|
9
|
-
def gl_error?
|
10
|
-
e = glGetError
|
11
|
-
if e != GL_NO_ERROR
|
12
|
-
warn "OpenGL error detected by handler at: #{caller[0]}"
|
13
|
-
warn " #{gluErrorString(e)} (#{e})\n"
|
14
|
-
exit if window.exit_on_opengl_error?
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
require_relative "opengl/shader"
|
20
|
-
require_relative "opengl/texture"
|
21
|
-
require_relative "opengl/light"
|
22
|
-
require_relative "opengl/perspective_camera"
|
23
|
-
require_relative "opengl/orthographic_camera"
|
24
|
-
|
25
|
-
require_relative "opengl/renderer/g_buffer"
|
26
|
-
require_relative "opengl/renderer/bounding_box_renderer"
|
27
|
-
require_relative "opengl/renderer/opengl_renderer"
|
28
|
-
require_relative "opengl/renderer/renderer"
|
1
|
+
begin
|
2
|
+
require "opengl"
|
3
|
+
rescue LoadError
|
4
|
+
puts "Required gem is not installed, please install 'opengl-bindings' and try again."
|
5
|
+
exit(1)
|
6
|
+
end
|
7
|
+
|
8
|
+
module CyberarmEngine
|
9
|
+
def gl_error?
|
10
|
+
e = glGetError
|
11
|
+
if e != GL_NO_ERROR
|
12
|
+
warn "OpenGL error detected by handler at: #{caller[0]}"
|
13
|
+
warn " #{gluErrorString(e)} (#{e})\n"
|
14
|
+
exit if window.exit_on_opengl_error?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require_relative "opengl/shader"
|
20
|
+
require_relative "opengl/texture"
|
21
|
+
require_relative "opengl/light"
|
22
|
+
require_relative "opengl/perspective_camera"
|
23
|
+
require_relative "opengl/orthographic_camera"
|
24
|
+
|
25
|
+
require_relative "opengl/renderer/g_buffer"
|
26
|
+
require_relative "opengl/renderer/bounding_box_renderer"
|
27
|
+
require_relative "opengl/renderer/opengl_renderer"
|
28
|
+
require_relative "opengl/renderer/renderer"
|
data/lib/cyberarm_engine/ray.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Ray
|
3
|
-
def initialize(origin, direction, range = Float::INFINITY)
|
4
|
-
raise "Origin must be a Vector!" unless origin.is_a?(Vector)
|
5
|
-
raise "Direction must be a Vector!" unless direction.is_a?(Vector)
|
6
|
-
|
7
|
-
@origin = origin
|
8
|
-
@direction = direction
|
9
|
-
@range = range
|
10
|
-
|
11
|
-
@inverse_direction = @direction.inverse
|
12
|
-
end
|
13
|
-
|
14
|
-
def intersect?(intersectable)
|
15
|
-
if intersectable.is_a?(BoundingBox)
|
16
|
-
intersect_bounding_box?(intersectable)
|
17
|
-
else
|
18
|
-
raise NotImplementedError, "Ray intersection test for #{intersectable.class} not implemented."
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Based on: https://tavianator.com/fast-branchless-raybounding-box-intersections/
|
23
|
-
def intersect_bounding_box?(box)
|
24
|
-
tmin = -@range
|
25
|
-
tmax = @range
|
26
|
-
|
27
|
-
tx1 = (box.min.x - @origin.x) * @inverse_direction.x
|
28
|
-
tx2 = (box.max.x - @origin.x) * @inverse_direction.x
|
29
|
-
|
30
|
-
tmin = max(tmin, min(tx1, tx2))
|
31
|
-
tmax = min(tmax, max(tx1, tx2))
|
32
|
-
|
33
|
-
ty1 = (box.min.y - @origin.y) * @inverse_direction.y
|
34
|
-
ty2 = (box.max.y - @origin.y) * @inverse_direction.y
|
35
|
-
|
36
|
-
tmin = max(tmin, min(ty1, ty2))
|
37
|
-
tmax = min(tmax, max(ty1, ty2))
|
38
|
-
|
39
|
-
tz1 = (box.min.z - @origin.z) * @inverse_direction.z
|
40
|
-
tz2 = (box.max.z - @origin.z) * @inverse_direction.z
|
41
|
-
|
42
|
-
tmin = max(tmin, min(tz1, tz2))
|
43
|
-
tmax = min(tmax, max(tz1, tz2))
|
44
|
-
|
45
|
-
tmax >= max(tmin, 0.0)
|
46
|
-
end
|
47
|
-
|
48
|
-
def min(x, y)
|
49
|
-
((x) < (y) ? x : y)
|
50
|
-
end
|
51
|
-
|
52
|
-
def max(x, y)
|
53
|
-
((x) > (y) ? x : y)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Ray
|
3
|
+
def initialize(origin, direction, range = Float::INFINITY)
|
4
|
+
raise "Origin must be a Vector!" unless origin.is_a?(Vector)
|
5
|
+
raise "Direction must be a Vector!" unless direction.is_a?(Vector)
|
6
|
+
|
7
|
+
@origin = origin
|
8
|
+
@direction = direction
|
9
|
+
@range = range
|
10
|
+
|
11
|
+
@inverse_direction = @direction.inverse
|
12
|
+
end
|
13
|
+
|
14
|
+
def intersect?(intersectable)
|
15
|
+
if intersectable.is_a?(BoundingBox)
|
16
|
+
intersect_bounding_box?(intersectable)
|
17
|
+
else
|
18
|
+
raise NotImplementedError, "Ray intersection test for #{intersectable.class} not implemented."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Based on: https://tavianator.com/fast-branchless-raybounding-box-intersections/
|
23
|
+
def intersect_bounding_box?(box)
|
24
|
+
tmin = -@range
|
25
|
+
tmax = @range
|
26
|
+
|
27
|
+
tx1 = (box.min.x - @origin.x) * @inverse_direction.x
|
28
|
+
tx2 = (box.max.x - @origin.x) * @inverse_direction.x
|
29
|
+
|
30
|
+
tmin = max(tmin, min(tx1, tx2))
|
31
|
+
tmax = min(tmax, max(tx1, tx2))
|
32
|
+
|
33
|
+
ty1 = (box.min.y - @origin.y) * @inverse_direction.y
|
34
|
+
ty2 = (box.max.y - @origin.y) * @inverse_direction.y
|
35
|
+
|
36
|
+
tmin = max(tmin, min(ty1, ty2))
|
37
|
+
tmax = min(tmax, max(ty1, ty2))
|
38
|
+
|
39
|
+
tz1 = (box.min.z - @origin.z) * @inverse_direction.z
|
40
|
+
tz2 = (box.max.z - @origin.z) * @inverse_direction.z
|
41
|
+
|
42
|
+
tmin = max(tmin, min(tz1, tz2))
|
43
|
+
tmax = min(tmax, max(tz1, tz2))
|
44
|
+
|
45
|
+
tmax >= max(tmin, 0.0)
|
46
|
+
end
|
47
|
+
|
48
|
+
def min(x, y)
|
49
|
+
((x) < (y) ? x : y)
|
50
|
+
end
|
51
|
+
|
52
|
+
def max(x, y)
|
53
|
+
((x) > (y) ? x : y)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Stats
|
3
|
-
@@hash = {
|
4
|
-
gui_recalculations_last_frame: 0
|
5
|
-
}
|
6
|
-
|
7
|
-
def self.get(key)
|
8
|
-
@@hash.dig(key)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.increment(key, n)
|
12
|
-
@@hash[key] += n
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.clear
|
16
|
-
@@hash.each do |key, _value|
|
17
|
-
@@hash[key] = 0
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Stats
|
3
|
+
@@hash = {
|
4
|
+
gui_recalculations_last_frame: 0
|
5
|
+
}
|
6
|
+
|
7
|
+
def self.get(key)
|
8
|
+
@@hash.dig(key)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.increment(key, n)
|
12
|
+
@@hash[key] += n
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.clear
|
16
|
+
@@hash.each do |key, _value|
|
17
|
+
@@hash[key] = 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|