mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-15 20:52:35 +00:00
Compare commits
11 Commits
c2330ed9a9
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 498cf06916 | |||
| 1f57dfd38c | |||
| 76a8bf95c7 | |||
| 1c25eeb32b | |||
| eabad4abd4 | |||
| b3561f02c1 | |||
| 9694cc2270 | |||
| a7df9a660d | |||
| d2f757eb23 | |||
| 0d70177de7 | |||
| dcefaeae4d |
25
Gemfile.lock
Normal file
25
Gemfile.lock
Normal file
@@ -0,0 +1,25 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
cyberarm_engine (0.24.5)
|
||||
gosu (~> 1.1)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
gosu (1.4.6)
|
||||
minitest (5.25.5)
|
||||
rake (13.2.1)
|
||||
|
||||
PLATFORMS
|
||||
x64-mingw-ucrt
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
bundler (~> 2.2)
|
||||
cyberarm_engine!
|
||||
minitest (~> 5.0)
|
||||
rake (~> 13.0)
|
||||
|
||||
BUNDLED WITH
|
||||
2.6.8
|
||||
@@ -1,14 +1,15 @@
|
||||
#version 330 core
|
||||
@include "light_struct"
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
@include "light_struct"
|
||||
const int DIRECTIONAL = 0;
|
||||
const int POINT = 1;
|
||||
const int SPOT = 2;
|
||||
|
||||
flat in Light out_lights[7];
|
||||
in vec2 out_tex_coords;
|
||||
flat in int out_light_count;
|
||||
flat in Light out_lights[7];
|
||||
|
||||
uniform sampler2D diffuse, position, texcoord, normal, depth;
|
||||
|
||||
@@ -27,43 +28,88 @@ vec4 directionalLight(Light light) {
|
||||
return vec4(_diffuse + _ambient + _specular, 1.0);
|
||||
}
|
||||
|
||||
vec4 pointLight(Light light) {
|
||||
return vec4(0.25, 0.25, 0.25, 1);
|
||||
}
|
||||
|
||||
vec4 spotLight(Light light) {
|
||||
return vec4(0.5, 0.5, 0.5, 1);
|
||||
}
|
||||
|
||||
vec4 calculateLighting(Light light) {
|
||||
vec4 result;
|
||||
|
||||
// switch(light.type) {
|
||||
// case DIRECTIONAL: {
|
||||
// result = directionalLight(light);
|
||||
// }
|
||||
// case SPOT: {
|
||||
// result = spotLight(light);
|
||||
// }
|
||||
// default: {
|
||||
// result = pointLight(light);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (light.type == DIRECTIONAL) {
|
||||
result = directionalLight(light);
|
||||
} else {
|
||||
result = pointLight(light);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void main() {
|
||||
frag_color = vec4(0.0);
|
||||
Light light;
|
||||
light.type = DIRECTIONAL;
|
||||
|
||||
for(int i = 0; i < out_light_count; i++)
|
||||
{
|
||||
frag_color += texture(diffuse, out_tex_coords) * calculateLighting(out_lights[i]);
|
||||
}
|
||||
light.position = vec3(100, 100, 100);
|
||||
|
||||
light.diffuse = vec3(0.5, 0.5, 0.5);
|
||||
light.ambient = vec3(0.8, 0.8, 0.8);
|
||||
light.specular = vec3(0.2, 0.2, 0.2);
|
||||
|
||||
light.intensity = 1.0;
|
||||
|
||||
frag_color = texture(diffuse, out_tex_coords) * directionalLight(light);
|
||||
}
|
||||
|
||||
// #version 330 core
|
||||
// @include "light_struct"
|
||||
|
||||
// out vec4 frag_color;
|
||||
|
||||
// const int DIRECTIONAL = 0;
|
||||
// const int POINT = 1;
|
||||
// const int SPOT = 2;
|
||||
|
||||
// in vec2 out_tex_coords;
|
||||
// flat in int out_light_count;
|
||||
// flat in Light out_lights[7];
|
||||
|
||||
// uniform sampler2D diffuse, position, texcoord, normal, depth;
|
||||
|
||||
// vec4 directionalLight(Light light) {
|
||||
// vec3 norm = normalize(texture(normal, out_tex_coords).rgb);
|
||||
// vec3 diffuse_color = texture(diffuse, out_tex_coords).rgb;
|
||||
// vec3 frag_pos = texture(position, out_tex_coords).rgb;
|
||||
|
||||
// vec3 lightDir = normalize(light.position - frag_pos);
|
||||
// float diff = max(dot(norm, lightDir), 0);
|
||||
|
||||
// vec3 _ambient = light.ambient;
|
||||
// vec3 _diffuse = light.diffuse * diff;
|
||||
// vec3 _specular = light.specular;
|
||||
|
||||
// return vec4(_diffuse + _ambient + _specular, 1.0);
|
||||
// }
|
||||
|
||||
// vec4 pointLight(Light light) {
|
||||
// return vec4(0.25, 0.25, 0.25, 1);
|
||||
// }
|
||||
|
||||
// vec4 spotLight(Light light) {
|
||||
// return vec4(0.5, 0.5, 0.5, 1);
|
||||
// }
|
||||
|
||||
// vec4 calculateLighting(Light light) {
|
||||
// vec4 result;
|
||||
|
||||
// // switch(light.type) {
|
||||
// // case DIRECTIONAL: {
|
||||
// // result = directionalLight(light);
|
||||
// // }
|
||||
// // case SPOT: {
|
||||
// // result = spotLight(light);
|
||||
// // }
|
||||
// // default: {
|
||||
// // result = pointLight(light);
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// if (light.type == DIRECTIONAL) {
|
||||
// result = directionalLight(light);
|
||||
// } else {
|
||||
// result = pointLight(light);
|
||||
// }
|
||||
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// void main() {
|
||||
// frag_color = vec4(0.0);
|
||||
|
||||
// for(int i = 0; i < out_light_count; i++)
|
||||
// {
|
||||
// frag_color += texture(diffuse, out_tex_coords) * calculateLighting(out_lights[i]);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# version 330 core
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec3 in_color;
|
||||
|
||||
@@ -67,12 +67,4 @@ require_relative "cyberarm_engine/ui/elements/menu_item"
|
||||
require_relative "cyberarm_engine/game_state"
|
||||
require_relative "cyberarm_engine/ui/gui_state"
|
||||
|
||||
require_relative "cyberarm_engine/model"
|
||||
require_relative "cyberarm_engine/model_cache"
|
||||
require_relative "cyberarm_engine/model/material"
|
||||
require_relative "cyberarm_engine/model/model_object"
|
||||
require_relative "cyberarm_engine/model/parser"
|
||||
require_relative "cyberarm_engine/model/parsers/wavefront_parser"
|
||||
require_relative "cyberarm_engine/model/parsers/collada_parser" if RUBY_ENGINE != "mruby" && defined?(Nokogiri)
|
||||
|
||||
require_relative "cyberarm_engine/builtin/intro_state"
|
||||
|
||||
@@ -170,10 +170,11 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
# Add <=> method to support Range based gradients
|
||||
module Gosu
|
||||
class Color
|
||||
def <=>(_other)
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
# NOTE: Disabled, causes stack overflow 🙃
|
||||
# module Gosu
|
||||
# class Color
|
||||
# def <=>(_other)
|
||||
# self
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
module CyberarmEngine
|
||||
module Common
|
||||
ImageBlob = Data.define(:to_blob, :columns, :rows)
|
||||
|
||||
def push_state(klass, options = {})
|
||||
window.push_state(klass, options)
|
||||
end
|
||||
@@ -85,7 +87,8 @@ module CyberarmEngine
|
||||
unless asset
|
||||
instance = nil
|
||||
instance = if klass == Gosu::Image
|
||||
klass.new(path, retro: retro, tileable: tileable)
|
||||
path_or_blob = path.is_a?(String) ? path : ImageBlob.new(path.to_blob, path.width, path.height)
|
||||
klass.new(path_or_blob, retro: retro, tileable: tileable)
|
||||
else
|
||||
klass.new(path)
|
||||
end
|
||||
|
||||
@@ -33,12 +33,23 @@ module Gosu
|
||||
#
|
||||
# @return [void]
|
||||
def self.draw_arc(x, y, radius, percentage = 1.0, segments = 128, thickness = 4, color = Gosu::Color::WHITE, z = 0, mode = :default)
|
||||
segments = 360.0 / segments
|
||||
|
||||
return if percentage == 0.0
|
||||
|
||||
0.step((359 * percentage), percentage > 0 ? segments : -segments) do |angle|
|
||||
angle2 = angle + segments
|
||||
angle_per_segment = 360.0 / segments
|
||||
arc_completion = 360 * percentage
|
||||
next_segment_angle = angle_per_segment
|
||||
|
||||
angle = 0
|
||||
loop do
|
||||
break if angle >= arc_completion
|
||||
|
||||
if angle + angle_per_segment > arc_completion
|
||||
next_segment_angle = arc_completion - angle
|
||||
else
|
||||
next_segment_angle = angle_per_segment
|
||||
end
|
||||
|
||||
angle2 = angle + next_segment_angle
|
||||
|
||||
point_a_left_x = x + Gosu.offset_x(angle, radius - thickness)
|
||||
point_a_left_y = y + Gosu.offset_y(angle, radius - thickness)
|
||||
@@ -93,6 +104,8 @@ module Gosu
|
||||
z, mode
|
||||
)
|
||||
end
|
||||
|
||||
angle += next_segment_angle
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
module CyberarmEngine
|
||||
class Model
|
||||
include OpenGL
|
||||
include CyberarmEngine
|
||||
|
||||
attr_accessor :objects, :materials, :vertices, :uvs, :texures, :normals, :faces, :colors, :bones, :material_file,
|
||||
:current_material, :current_object, :vertex_count, :smoothing
|
||||
attr_reader :position, :bounding_box, :textured_material, :file_path, :positions_buffer_id, :colors_buffer_id,
|
||||
@@ -49,9 +52,9 @@ module CyberarmEngine
|
||||
|
||||
@objects.each { |o| @vertex_count += o.vertices.size }
|
||||
|
||||
# start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
||||
# build_collision_tree
|
||||
# puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_time) / 1000.0).round(2)} seconds"
|
||||
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
||||
build_collision_tree
|
||||
puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_time) / 1000.0).round(2)} seconds"
|
||||
end
|
||||
|
||||
def parse(parser)
|
||||
@@ -178,7 +181,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def build_collision_tree
|
||||
@aabb_tree = IMICFPS::AABBTree.new
|
||||
@aabb_tree = AABBTree.new
|
||||
|
||||
@faces.each do |face|
|
||||
box = BoundingBox.new
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module CyberarmEngine
|
||||
class Model
|
||||
class ModelObject
|
||||
class Mesh
|
||||
attr_reader :id, :name, :vertices, :uvs, :normals, :materials, :bounding_box, :debug_color
|
||||
attr_accessor :faces, :scale
|
||||
|
||||
@@ -48,12 +48,12 @@ module CyberarmEngine
|
||||
if _model
|
||||
@model.current_object = _model
|
||||
else
|
||||
raise "Couldn't find ModelObject!"
|
||||
raise "Couldn't find Mesh!"
|
||||
end
|
||||
end
|
||||
|
||||
def change_object(id, name)
|
||||
@model.objects << Model::ModelObject.new(id, name)
|
||||
@model.objects << Model::Mesh.new(id, name)
|
||||
@model.current_object = @model.objects.last
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
begin
|
||||
require "opengl"
|
||||
require "glu"
|
||||
rescue LoadError
|
||||
puts "Required gem is not installed, please install 'opengl-bindings' and try again."
|
||||
exit(1)
|
||||
@@ -8,7 +9,7 @@ end
|
||||
module CyberarmEngine
|
||||
def gl_error?
|
||||
e = glGetError
|
||||
if e != GL_NO_ERROR
|
||||
if e != OpenGL::GL_NO_ERROR
|
||||
warn "OpenGL error detected by handler at: #{caller[0]}"
|
||||
warn " #{gluErrorString(e)} (#{e})\n"
|
||||
exit if Window.instance&.exit_on_opengl_error?
|
||||
@@ -38,3 +39,15 @@ require_relative "opengl/renderer/g_buffer"
|
||||
require_relative "opengl/renderer/bounding_box_renderer"
|
||||
require_relative "opengl/renderer/opengl_renderer"
|
||||
require_relative "opengl/renderer/renderer"
|
||||
|
||||
require_relative "trees/aabb_tree_debug"
|
||||
require_relative "trees/aabb_node"
|
||||
require_relative "trees/aabb_tree"
|
||||
|
||||
require_relative "model"
|
||||
require_relative "model_cache"
|
||||
require_relative "model/material"
|
||||
require_relative "model/mesh"
|
||||
require_relative "model/parser"
|
||||
require_relative "model/parsers/wavefront_parser"
|
||||
require_relative "model/parsers/collada_parser" if RUBY_ENGINE != "mruby" && defined?(Nokogiri)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
module CyberarmEngine
|
||||
class Light
|
||||
include OpenGL
|
||||
|
||||
DIRECTIONAL = 0
|
||||
POINT = 1
|
||||
SPOT = 2
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
module CyberarmEngine
|
||||
class PerspectiveCamera
|
||||
include OpenGL
|
||||
include GLU
|
||||
|
||||
attr_accessor :position, :orientation, :aspect_ratio, :field_of_view,
|
||||
:min_view_distance, :max_view_distance
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
module CyberarmEngine
|
||||
class GBuffer
|
||||
include OpenGL
|
||||
|
||||
attr_reader :screen_vbo, :vertices, :uvs
|
||||
attr_reader :width, :height
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
module CyberarmEngine
|
||||
class OpenGLRenderer
|
||||
include OpenGL
|
||||
include CyberarmEngine
|
||||
|
||||
@@immediate_mode_warning = false
|
||||
|
||||
attr_accessor :show_wireframe
|
||||
|
||||
@@ -2,6 +2,7 @@ module CyberarmEngine
|
||||
# Ref: https://github.com/vaiorabbit/ruby-opengl/blob/master/sample/OrangeBook/brick.rb
|
||||
class Shader
|
||||
include OpenGL
|
||||
|
||||
@@shaders = {} # Cache for {Shader} instances
|
||||
PREPROCESSOR_CHARACTER = "@".freeze # magic character for preprocessor phase of {Shader} compilation
|
||||
|
||||
@@ -298,6 +299,7 @@ module CyberarmEngine
|
||||
# @see Shader.use Shader.use
|
||||
def use(&block)
|
||||
return unless compiled?
|
||||
|
||||
raise "Another shader is already in use! #{Shader.active_shader.name.inspect}" if Shader.active_shader
|
||||
|
||||
Shader.active_shader = self
|
||||
|
||||
126
lib/cyberarm_engine/trees/aabb_node.rb
Normal file
126
lib/cyberarm_engine/trees/aabb_node.rb
Normal file
@@ -0,0 +1,126 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
class AABBTree
|
||||
class AABBNode
|
||||
attr_accessor :bounding_box, :parent, :object
|
||||
attr_reader :a, :b
|
||||
|
||||
def initialize(parent:, object:, bounding_box:)
|
||||
@parent = parent
|
||||
@object = object
|
||||
@bounding_box = bounding_box
|
||||
|
||||
@a = nil
|
||||
@b = nil
|
||||
end
|
||||
|
||||
def a=(leaf)
|
||||
@a = leaf
|
||||
@a.parent = self
|
||||
end
|
||||
|
||||
def b=(leaf)
|
||||
@b = leaf
|
||||
@b.parent = self
|
||||
end
|
||||
|
||||
def leaf?
|
||||
@object
|
||||
end
|
||||
|
||||
def insert_subtree(leaf)
|
||||
if leaf?
|
||||
new_node = AABBNode.new(parent: nil, object: nil, bounding_box: @bounding_box.union(leaf.bounding_box))
|
||||
|
||||
new_node.a = self
|
||||
new_node.b = leaf
|
||||
|
||||
new_node
|
||||
else
|
||||
cost_a = @a.bounding_box.volume + @b.bounding_box.union(leaf.bounding_box).volume
|
||||
cost_b = @b.bounding_box.volume + @a.bounding_box.union(leaf.bounding_box).volume
|
||||
|
||||
if cost_a == cost_b
|
||||
cost_a = @a.proximity(leaf)
|
||||
cost_b = @b.proximity(leaf)
|
||||
end
|
||||
|
||||
if cost_b < cost_a
|
||||
self.b = @b.insert_subtree(leaf)
|
||||
else
|
||||
self.a = @a.insert_subtree(leaf)
|
||||
end
|
||||
|
||||
@bounding_box = @bounding_box.union(leaf.bounding_box)
|
||||
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
def search_subtree(collider, items = [])
|
||||
if @bounding_box.intersect?(collider)
|
||||
if leaf?
|
||||
items << self
|
||||
else
|
||||
@a.search_subtree(collider, items)
|
||||
@b.search_subtree(collider, items)
|
||||
end
|
||||
end
|
||||
|
||||
items
|
||||
end
|
||||
|
||||
def remove_subtree(leaf)
|
||||
if leaf
|
||||
self
|
||||
elsif leaf.parent == self
|
||||
other_child = other(leaf)
|
||||
other_child.parent = @parent
|
||||
other_child
|
||||
else
|
||||
leaf.parent.disown_child(leaf)
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
def other(leaf)
|
||||
@a == leaf ? @b : @a
|
||||
end
|
||||
|
||||
def disown_child(leaf)
|
||||
value = other(leaf)
|
||||
raise "Can not replace child of a leaf!" if @parent.leaf?
|
||||
raise "Node is not a child of parent!" unless leaf.child_of?(@parent)
|
||||
|
||||
if @parent.a == self
|
||||
@parent.a = value
|
||||
else
|
||||
@parent.b = value
|
||||
end
|
||||
|
||||
@parent.update_bounding_box
|
||||
end
|
||||
|
||||
def child_of?(leaf)
|
||||
self == leaf.a || self == leaf.b
|
||||
end
|
||||
|
||||
def proximity(leaf)
|
||||
(@bounding_box - leaf.bounding_box).sum.abs
|
||||
end
|
||||
|
||||
def update_bounding_box
|
||||
node = self
|
||||
|
||||
unless node.leaf?
|
||||
node.bounding_box = node.a.bounding_box.union(node.b.bounding_box)
|
||||
|
||||
while (node = node.parent)
|
||||
node.bounding_box = node.a.bounding_box.union(node.b.bounding_box)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
55
lib/cyberarm_engine/trees/aabb_tree.rb
Normal file
55
lib/cyberarm_engine/trees/aabb_tree.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
class AABBTree
|
||||
include AABBTreeDebug
|
||||
|
||||
attr_reader :root, :objects, :branches, :leaves
|
||||
|
||||
def initialize
|
||||
@objects = {}
|
||||
@root = nil
|
||||
@branches = 0
|
||||
@leaves = 0
|
||||
end
|
||||
|
||||
def insert(object, bounding_box)
|
||||
raise "BoundingBox can't be nil!" unless bounding_box
|
||||
raise "Object can't be nil!" unless object
|
||||
# raise "Object already in tree!" if @objects[object] # FIXME
|
||||
|
||||
leaf = AABBNode.new(parent: nil, object: object, bounding_box: bounding_box.dup)
|
||||
@objects[object] = leaf
|
||||
|
||||
insert_leaf(leaf)
|
||||
end
|
||||
|
||||
def insert_leaf(leaf)
|
||||
@root = @root ? @root.insert_subtree(leaf) : leaf
|
||||
end
|
||||
|
||||
def update(object, bounding_box)
|
||||
leaf = remove(object)
|
||||
leaf.bounding_box = bounding_box
|
||||
insert_leaf(leaf)
|
||||
end
|
||||
|
||||
# Returns a list of all objects that collided with collider
|
||||
def search(collider, return_nodes = false)
|
||||
items = []
|
||||
if @root
|
||||
items = @root.search_subtree(collider)
|
||||
items.map!(&:object) unless return_nodes
|
||||
end
|
||||
|
||||
items
|
||||
end
|
||||
|
||||
def remove(object)
|
||||
leaf = @objects.delete(object)
|
||||
@root = @root.remove_subtree(leaf) if leaf
|
||||
|
||||
leaf
|
||||
end
|
||||
end
|
||||
end
|
||||
29
lib/cyberarm_engine/trees/aabb_tree_debug.rb
Normal file
29
lib/cyberarm_engine/trees/aabb_tree_debug.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
# Gets included into AABBTree
|
||||
module AABBTreeDebug
|
||||
def inspect
|
||||
@branches = 0
|
||||
@leaves = 0
|
||||
if @root
|
||||
node = @root
|
||||
|
||||
debug_search(node.a)
|
||||
debug_search(node.b)
|
||||
end
|
||||
|
||||
puts "<#{self.class}:#{object_id}> has #{@branches} branches and #{@leaves} leaves"
|
||||
end
|
||||
|
||||
def debug_search(node)
|
||||
if node.leaf?
|
||||
@leaves += 1
|
||||
else
|
||||
@branches += 1
|
||||
debug_search(node.a)
|
||||
debug_search(node.b)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -331,8 +331,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def debug_draw
|
||||
# FIXME
|
||||
return# if const_defined?(GUI_DEBUG_ONLY_ELEMENT) && self.class == GUI_DEBUG_ONLY_ELEMENT
|
||||
return if CyberarmEngine.const_defined?("GUI_DEBUG_ONLY_ELEMENT") && self.class == GUI_DEBUG_ONLY_ELEMENT
|
||||
|
||||
Gosu.draw_line(
|
||||
x, y, @debug_color,
|
||||
@@ -350,7 +349,7 @@ module CyberarmEngine
|
||||
Float::INFINITY
|
||||
)
|
||||
Gosu.draw_line(
|
||||
x, outer_height, @debug_color,
|
||||
x, y + outer_height, @debug_color,
|
||||
x, y, @debug_color,
|
||||
Float::INFINITY
|
||||
)
|
||||
|
||||
@@ -7,13 +7,13 @@ module CyberarmEngine
|
||||
attr_reader :children, :gui_state, :scroll_position, :scroll_target_position
|
||||
|
||||
def self.current_container
|
||||
@@current_container
|
||||
@current_container
|
||||
end
|
||||
|
||||
def self.current_container=(container)
|
||||
raise ArgumentError, "Expected container to an an instance of CyberarmEngine::Element::Container, got #{container.class}" unless container.is_a?(CyberarmEngine::Element::Container)
|
||||
|
||||
@@current_container = container
|
||||
@current_container = container
|
||||
end
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
@@ -26,6 +26,11 @@ module CyberarmEngine
|
||||
@scroll_chunk = 120
|
||||
@scroll_speed = 40
|
||||
|
||||
if @gui_state
|
||||
@width = window.width
|
||||
@height = window.height
|
||||
end
|
||||
|
||||
@text_color = options[:color]
|
||||
|
||||
@children = []
|
||||
@@ -34,7 +39,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def build
|
||||
@block.call(self) if @block
|
||||
@block&.call(self)
|
||||
|
||||
root.gui_state.request_recalculate_for(self)
|
||||
end
|
||||
@@ -53,7 +58,7 @@ module CyberarmEngine
|
||||
old_container = CyberarmEngine::Element::Container.current_container
|
||||
|
||||
CyberarmEngine::Element::Container.current_container = self
|
||||
block.call(self) if block
|
||||
block&.call(self)
|
||||
|
||||
CyberarmEngine::Element::Container.current_container = old_container
|
||||
|
||||
@@ -66,7 +71,7 @@ module CyberarmEngine
|
||||
old_container = CyberarmEngine::Element::Container.current_container
|
||||
|
||||
CyberarmEngine::Element::Container.current_container = self
|
||||
block.call(self) if block
|
||||
block&.call(self)
|
||||
|
||||
CyberarmEngine::Element::Container.current_container = old_container
|
||||
|
||||
@@ -89,9 +94,7 @@ module CyberarmEngine
|
||||
def debug_draw
|
||||
super
|
||||
|
||||
@children.each do |child|
|
||||
child.debug_draw
|
||||
end
|
||||
@children.each(&:debug_draw)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -111,7 +114,7 @@ module CyberarmEngine
|
||||
|
||||
case child
|
||||
when Container
|
||||
if element = child.hit_element?(child_x, child_y)
|
||||
if (element = child.hit_element?(child_x, child_y))
|
||||
return element
|
||||
end
|
||||
else
|
||||
@@ -151,10 +154,6 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def recalculate
|
||||
return if @in_recalculate
|
||||
|
||||
@in_recalculate = true
|
||||
|
||||
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
|
||||
|
||||
return unless visible?
|
||||
@@ -211,7 +210,7 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
# t = Gosu.milliseconds
|
||||
t = Gosu.milliseconds
|
||||
# Move children to parent after positioning
|
||||
@children.each do |child|
|
||||
child.x += (@x + @style.border_thickness_left) - style.margin_left
|
||||
@@ -225,7 +224,7 @@ module CyberarmEngine
|
||||
|
||||
update_child_element_visibity(child)
|
||||
end
|
||||
# puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}'s #{@children.count} children"
|
||||
puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{object_id.to_s(16)}'s #{@children.count} children"
|
||||
|
||||
update_background
|
||||
|
||||
@@ -243,8 +242,6 @@ module CyberarmEngine
|
||||
recalculate_if_size_changed
|
||||
|
||||
# puts "TOOK: #{Gosu.milliseconds - s}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}"
|
||||
|
||||
@in_recalculate = false
|
||||
end
|
||||
|
||||
def layout
|
||||
@@ -305,15 +302,15 @@ module CyberarmEngine
|
||||
return unless @style.scroll
|
||||
|
||||
# Allow overscrolling UP, only if one can scroll DOWN
|
||||
if height < scroll_height
|
||||
if @scroll_target_position.y > 0
|
||||
@scroll_target_position.y = @scroll_chunk
|
||||
else
|
||||
@scroll_target_position.y += @scroll_chunk
|
||||
end
|
||||
return unless height < scroll_height
|
||||
|
||||
return :handled
|
||||
if @scroll_target_position.y.positive?
|
||||
@scroll_target_position.y = @scroll_chunk
|
||||
else
|
||||
@scroll_target_position.y += @scroll_chunk
|
||||
end
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
def mouse_wheel_down(sender, x, y)
|
||||
@@ -321,13 +318,13 @@ module CyberarmEngine
|
||||
|
||||
return unless height < scroll_height
|
||||
|
||||
if @scroll_target_position.y > 0
|
||||
if @scroll_target_position.y.positive?
|
||||
@scroll_target_position.y = -@scroll_chunk
|
||||
else
|
||||
@scroll_target_position.y -= @scroll_chunk
|
||||
end
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_jump_to_top(sender, x, y)
|
||||
@@ -336,7 +333,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = 0
|
||||
@scroll_target_position.y = 0
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_jump_to_end(sender, x, y)
|
||||
@@ -345,7 +342,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = -max_scroll_height
|
||||
@scroll_target_position.y = -max_scroll_height
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_page_up(sender, x, y)
|
||||
@@ -355,7 +352,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = 0 if @scroll_position.y > 0
|
||||
@scroll_target_position.y = @scroll_position.y
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_page_down(sender, x, y)
|
||||
@@ -365,7 +362,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = -max_scroll_height if @scroll_position.y < -max_scroll_height
|
||||
@scroll_target_position.y = @scroll_position.y
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_top
|
||||
|
||||
@@ -168,7 +168,7 @@ module CyberarmEngine
|
||||
@last_text = @text.text
|
||||
@last_pos = caret_pos
|
||||
|
||||
if caret_pos.between?(@offset_x, @width + @offset_x)
|
||||
if caret_pos.between?(@offset_x + 1, @width + @offset_x)
|
||||
# Do nothing
|
||||
|
||||
elsif caret_pos < @offset_x
|
||||
@@ -197,7 +197,7 @@ module CyberarmEngine
|
||||
|
||||
def text_input_position_for(method)
|
||||
if @type == :password
|
||||
@text.x + @text.width(default(:password_character) * @text_input.text[0...@text_input.send(method)].length)
|
||||
@text.x + @text.width(default(:password_character) * @text_input.text[0...@text_input.send(method)].length) - @style.border_thickness_left
|
||||
else
|
||||
@text.x + @text.width(@text_input.text[0...@text_input.send(method)]) - @style.border_thickness_left
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :step_size, :value
|
||||
attr_reader :value
|
||||
attr_accessor :range, :step_size
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
@@ -47,7 +47,7 @@ module CyberarmEngine
|
||||
add(@handle)
|
||||
end
|
||||
|
||||
def layout
|
||||
def recalculate
|
||||
_width = dimensional_size(@style.width, :width)
|
||||
_height = dimensional_size(@style.height, :height)
|
||||
|
||||
@@ -55,7 +55,7 @@ module CyberarmEngine
|
||||
@height = _height
|
||||
|
||||
position_handle
|
||||
@handle.layout
|
||||
@handle.recalculate
|
||||
@handle.update_background
|
||||
|
||||
update_background
|
||||
|
||||
@@ -57,7 +57,8 @@ module CyberarmEngine
|
||||
Stats.frame.start_timing(:gui_element_recalculate_requests)
|
||||
|
||||
# puts "PENDING REQUESTS: #{@pending_element_recalculate_requests.size}" if @pending_element_recalculate_requests.size.positive?
|
||||
@pending_element_recalculate_requests.each(&:recalculate)
|
||||
@pending_recalculate_request = true if @pending_element_recalculate_requests.size.positive?
|
||||
# @pending_element_recalculate_requests.each(&:recalculate)
|
||||
@pending_element_recalculate_requests.clear
|
||||
|
||||
Stats.frame.end_timing(:gui_element_recalculate_requests)
|
||||
@@ -85,8 +86,7 @@ module CyberarmEngine
|
||||
@tip.draw
|
||||
end
|
||||
|
||||
# FIXME
|
||||
if false# defined?(GUI_DEBUG)
|
||||
if CyberarmEngine.const_defined?("GUI_DEBUG")
|
||||
Gosu.flush
|
||||
|
||||
@root_container.debug_draw
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module CyberarmEngine
|
||||
NAME = "InDev".freeze
|
||||
VERSION = "0.24.2".freeze
|
||||
VERSION = "0.24.5".freeze
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user