mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 21:22:33 +00:00
Compare commits
21 Commits
v0.22.0
...
2e690d7d33
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e690d7d33 | |||
| a9f9e20235 | |||
| 25c36d3788 | |||
| c26ddeef4d | |||
| 5e3e06b74e | |||
| 72037efc73 | |||
| 1462f89e24 | |||
| 98948c891a | |||
| da16ab1ec9 | |||
| eb5d170733 | |||
| 14e9d4946f | |||
| e3b8a9b102 | |||
| 458731a534 | |||
| d1d87db070 | |||
| 6e8948bd81 | |||
| 01a9187a57 | |||
| 186ad220cc | |||
| f82c0953b2 | |||
| a2d44ea2dc | |||
| c46664778a | |||
| c597a67ca6 |
30
assets/shaders/fragment/g_buffer.glsl
Normal file
30
assets/shaders/fragment/g_buffer.glsl
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# version 330 core
|
||||||
|
|
||||||
|
layout(location = 0) out vec3 fragPosition;
|
||||||
|
layout (location = 1) out vec4 fragColor;
|
||||||
|
layout (location = 2) out vec3 fragNormal;
|
||||||
|
layout (location = 3) out vec3 fragUV;
|
||||||
|
|
||||||
|
in vec3 outPosition, outColor, outNormal, outUV, outFragPos, outCameraPos;
|
||||||
|
out vec4 outputFragColor;
|
||||||
|
flat in int outHasTexture;
|
||||||
|
|
||||||
|
uniform sampler2D diffuse_texture;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec3 result;
|
||||||
|
|
||||||
|
if (outHasTexture == 0) {
|
||||||
|
result = outColor;
|
||||||
|
} else {
|
||||||
|
result = texture(diffuse_texture, outUV.xy).xyz + 0.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
fragPosition = outPosition;
|
||||||
|
fragColor = vec4(result, 1.0);
|
||||||
|
fragNormal = outNormal;
|
||||||
|
fragUV = outUV;
|
||||||
|
|
||||||
|
float gamma = 2.2;
|
||||||
|
outputFragColor.rgb = pow(fragColor.rgb, vec3(1.0 / gamma));
|
||||||
|
}
|
||||||
63
assets/shaders/fragment/lighting.glsl
Normal file
63
assets/shaders/fragment/lighting.glsl
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#version 330 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
@include "light_struct"
|
||||||
|
const int DIRECTIONAL = 0;
|
||||||
|
const int POINT = 1;
|
||||||
|
const int SPOT = 2;
|
||||||
|
|
||||||
|
in vec2 outTexCoords;
|
||||||
|
flat in Light outLight[1];
|
||||||
|
|
||||||
|
uniform sampler2D diffuse, position, texcoord, normal, depth;
|
||||||
|
|
||||||
|
vec4 directionalLight(Light light) {
|
||||||
|
vec3 norm = normalize(texture(normal, outTexCoords).rgb);
|
||||||
|
vec3 diffuse_color = texture(diffuse, outTexCoords).rgb;
|
||||||
|
vec3 fragPos = texture(position, outTexCoords).rgb;
|
||||||
|
|
||||||
|
vec3 lightDir = normalize(light.position - fragPos);
|
||||||
|
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() {
|
||||||
|
FragColor = texture(diffuse, outTexCoords) * calculateLighting(outLight[0]);
|
||||||
|
}
|
||||||
11
assets/shaders/include/light_struct.glsl
Normal file
11
assets/shaders/include/light_struct.glsl
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
struct Light {
|
||||||
|
int type;
|
||||||
|
vec3 direction;
|
||||||
|
vec3 position;
|
||||||
|
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 specular;
|
||||||
|
|
||||||
|
float intensity;
|
||||||
|
};
|
||||||
28
assets/shaders/vertex/g_buffer.glsl
Normal file
28
assets/shaders/vertex/g_buffer.glsl
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# version 330 core
|
||||||
|
|
||||||
|
layout(location = 0) in vec3 inPosition;
|
||||||
|
layout(location = 1) in vec3 inColor;
|
||||||
|
layout(location = 2) in vec3 inNormal;
|
||||||
|
layout(location = 3) in vec3 inUV;
|
||||||
|
|
||||||
|
uniform mat4 projection, view, model;
|
||||||
|
uniform int hasTexture;
|
||||||
|
uniform vec3 cameraPos;
|
||||||
|
|
||||||
|
out vec3 outPosition, outColor, outNormal, outUV;
|
||||||
|
out vec3 outFragPos, outViewPos, outCameraPos;
|
||||||
|
flat out int outHasTexture;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// projection * view * model * position
|
||||||
|
outPosition = inPosition;
|
||||||
|
outColor = inColor;
|
||||||
|
outNormal= normalize(transpose(inverse(mat3(model))) * inNormal);
|
||||||
|
outUV = inUV;
|
||||||
|
outHasTexture = hasTexture;
|
||||||
|
outCameraPos = cameraPos;
|
||||||
|
|
||||||
|
outFragPos = vec3(model * vec4(inPosition, 1.0));
|
||||||
|
|
||||||
|
gl_Position = projection * view * model * vec4(inPosition, 1.0);
|
||||||
|
}
|
||||||
17
assets/shaders/vertex/lighting.glsl
Normal file
17
assets/shaders/vertex/lighting.glsl
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#version 330 core
|
||||||
|
@include "light_struct"
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 inPosition;
|
||||||
|
layout (location = 1) in vec2 inTexCoords;
|
||||||
|
|
||||||
|
uniform sampler2D diffuse, position, texcoord, normal, depth;
|
||||||
|
uniform Light light[1];
|
||||||
|
|
||||||
|
out vec2 outTexCoords;
|
||||||
|
flat out Light outLight[1];
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
|
||||||
|
outTexCoords = inTexCoords;
|
||||||
|
outLight = light;
|
||||||
|
}
|
||||||
@@ -66,6 +66,6 @@ require_relative "cyberarm_engine/model/material"
|
|||||||
require_relative "cyberarm_engine/model/model_object"
|
require_relative "cyberarm_engine/model/model_object"
|
||||||
require_relative "cyberarm_engine/model/parser"
|
require_relative "cyberarm_engine/model/parser"
|
||||||
require_relative "cyberarm_engine/model/parsers/wavefront_parser"
|
require_relative "cyberarm_engine/model/parsers/wavefront_parser"
|
||||||
require_relative "cyberarm_engine/model/parsers/collada_parser" if defined?(Nokogiri)
|
require_relative "cyberarm_engine/model/parsers/collada_parser" if RUBY_ENGINE != "mruby" && defined?(Nokogiri)
|
||||||
|
|
||||||
require_relative "cyberarm_engine/builtin/intro_state"
|
require_relative "cyberarm_engine/builtin/intro_state"
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw_fill
|
def draw_fill
|
||||||
if @width * width_scale > height * height_scale
|
if (@image.width * width_scale) >= @width && (@image.height * width_scale) >= @height
|
||||||
draw_fill_width
|
draw_fill_width
|
||||||
else
|
else
|
||||||
draw_fill_height
|
draw_fill_height
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ module CyberarmEngine
|
|||||||
@title_size = 56
|
@title_size = 56
|
||||||
@caption_size = 24
|
@caption_size = 24
|
||||||
|
|
||||||
@title = CyberarmEngine::Text.new("", size: @title_size, shadow_color: 0xaa_222222)
|
@title = CyberarmEngine::Text.new("", size: @title_size, shadow_color: 0xaa_222222, static: true)
|
||||||
@caption = CyberarmEngine::Text.new("", size: @caption_size, shadow_color: 0xaa_222222)
|
@caption = CyberarmEngine::Text.new("", size: @caption_size, shadow_color: 0xaa_222222, static: true)
|
||||||
|
|
||||||
@spacer_width = 256
|
@spacer_width = 256
|
||||||
@spacer_height = 6
|
@spacer_height = 6
|
||||||
@@ -18,7 +18,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
@gosu_logo = generate_proxy("Gosu", "Game Library", 0xff_111111)
|
@gosu_logo = generate_proxy("Gosu", "Game Library", 0xff_111111)
|
||||||
@ruby_logo = generate_proxy("Ruby", "Programming Language", 0xff_880000)
|
@ruby_logo = generate_proxy("Ruby", "Programming Language", 0xff_880000)
|
||||||
@opengl_logo = generate_proxy("OpenGL", "Graphics API", 0xff_5586a4) if defined?(OpenGL)
|
@opengl_logo = generate_proxy("OpenGL", "Graphics API", 0xff_5586a4) if RUBY_ENGINE != "mruby" && defined?(OpenGL)
|
||||||
|
|
||||||
base_time = Gosu.milliseconds
|
base_time = Gosu.milliseconds
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,18 @@ module CyberarmEngine
|
|||||||
window.show_cursor = boolean
|
window.show_cursor = boolean
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_element_by_tag(container, tag, list = [])
|
||||||
|
return unless container
|
||||||
|
|
||||||
|
container.children.each do |child|
|
||||||
|
list << child if child.style.tag == tag
|
||||||
|
|
||||||
|
find_element_by_tag(child, tag, list) if child.is_a?(CyberarmEngine::Element::Container)
|
||||||
|
end
|
||||||
|
|
||||||
|
list.first
|
||||||
|
end
|
||||||
|
|
||||||
def draw_rect(x, y, width, height, color, z = 0, mode = :default)
|
def draw_rect(x, y, width, height, color, z = 0, mode = :default)
|
||||||
Gosu.draw_rect(x, y, width, height, color, z, mode)
|
Gosu.draw_rect(x, y, width, height, color, z, mode)
|
||||||
end
|
end
|
||||||
@@ -40,7 +52,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def lighten(color, amount = 25)
|
def lighten(color, amount = 25)
|
||||||
if defined?(color.alpha)
|
if color.respond_to?(:alpha)
|
||||||
Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
|
Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
|
||||||
else
|
else
|
||||||
Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
|
Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
|
||||||
@@ -48,7 +60,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def darken(color, amount = 25)
|
def darken(color, amount = 25)
|
||||||
if defined?(color.alpha)
|
if color.respond_to?(:alpha)
|
||||||
Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
|
Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
|
||||||
else
|
else
|
||||||
Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
|
Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def button_down(id)
|
def button_down(id)
|
||||||
case id
|
case id
|
||||||
when Gosu::KbEnter, Gosu::KbReturn
|
when Gosu::KB_ENTER, Gosu::KB_RETURN
|
||||||
return unless @text_input.text.length.positive?
|
return unless @text_input.text.length.positive?
|
||||||
|
|
||||||
@history.text += "\n<c=999999>> #{@text_input.text}</c>"
|
@history.text += "\n<c=999999>> #{@text_input.text}</c>"
|
||||||
@@ -113,12 +113,12 @@ module CyberarmEngine
|
|||||||
handle_command
|
handle_command
|
||||||
@text_input.text = ""
|
@text_input.text = ""
|
||||||
|
|
||||||
when Gosu::KbUp
|
when Gosu::KB_UP
|
||||||
@command_history_index -= 1
|
@command_history_index -= 1
|
||||||
@command_history_index = 0 if @command_history_index.negative?
|
@command_history_index = 0 if @command_history_index.negative?
|
||||||
@text_input.text = @command_history[@command_history_index]
|
@text_input.text = @command_history[@command_history_index]
|
||||||
|
|
||||||
when Gosu::KbDown
|
when Gosu::KB_DOWN
|
||||||
@command_history_index += 1
|
@command_history_index += 1
|
||||||
if @command_history_index > @command_history.size - 1
|
if @command_history_index > @command_history.size - 1
|
||||||
@text_input.text = "" unless @command_history_index > @command_history.size
|
@text_input.text = "" unless @command_history_index > @command_history.size
|
||||||
@@ -127,7 +127,7 @@ module CyberarmEngine
|
|||||||
@text_input.text = @command_history[@command_history_index]
|
@text_input.text = @command_history[@command_history_index]
|
||||||
end
|
end
|
||||||
|
|
||||||
when Gosu::KbTab
|
when Gosu::KB_TAB
|
||||||
split = @text_input.text.split(" ")
|
split = @text_input.text.split(" ")
|
||||||
|
|
||||||
if !@text_input.text.end_with?(" ") && split.size == 1
|
if !@text_input.text.end_with?(" ") && split.size == 1
|
||||||
@@ -142,7 +142,7 @@ module CyberarmEngine
|
|||||||
cmd.autocomplete(self)
|
cmd.autocomplete(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
when Gosu::KbBacktick
|
when Gosu::KB_BACKTICK
|
||||||
# Remove backtick character from input
|
# Remove backtick character from input
|
||||||
@text_input.text = if @text_input.text.size > 1
|
@text_input.text = if @text_input.text.size > 1
|
||||||
@text_input.text[0..@text_input.text.size - 2]
|
@text_input.text[0..@text_input.text.size - 2]
|
||||||
@@ -151,7 +151,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Copy
|
# Copy
|
||||||
when Gosu::KbC
|
when Gosu::KB_C
|
||||||
if control_down? && shift_down?
|
if control_down? && shift_down?
|
||||||
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
||||||
p @memory
|
p @memory
|
||||||
@@ -160,7 +160,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Paste
|
# Paste
|
||||||
when Gosu::KbV
|
when Gosu::KB_V
|
||||||
if control_down? && shift_down?
|
if control_down? && shift_down?
|
||||||
string = @text_input.text.chars.insert(caret_pos, @memory).join
|
string = @text_input.text.chars.insert(caret_pos, @memory).join
|
||||||
_caret_pos = caret_pos
|
_caret_pos = caret_pos
|
||||||
@@ -170,7 +170,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Cut
|
# Cut
|
||||||
when Gosu::KbX
|
when Gosu::KB_X
|
||||||
if control_down? && shift_down?
|
if control_down? && shift_down?
|
||||||
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
||||||
string = @text_input.text.chars
|
string = @text_input.text.chars
|
||||||
@@ -182,7 +182,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Delete word to left of caret
|
# Delete word to left of caret
|
||||||
when Gosu::KbW
|
when Gosu::KB_W
|
||||||
if control_down?
|
if control_down?
|
||||||
split = @text_input.text.split(" ")
|
split = @text_input.text.split(" ")
|
||||||
split.delete(split.last)
|
split.delete(split.last)
|
||||||
@@ -190,7 +190,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Clear history
|
# Clear history
|
||||||
when Gosu::KbL
|
when Gosu::KB_L
|
||||||
@history.text = "" if control_down?
|
@history.text = "" if control_down?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ module CyberarmEngine
|
|||||||
@radius = if options[:radius]
|
@radius = if options[:radius]
|
||||||
options[:radius]
|
options[:radius]
|
||||||
else
|
else
|
||||||
defined?(@image.width) ? ((@image.width + @image.height) / 4) * scale : 1
|
@image.respond_to?(:width) ? ((@image.width + @image.height) / 4) * scale : 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ module CyberarmEngine
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def needs_repaint?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def drop(filename)
|
def drop(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ module CyberarmEngine
|
|||||||
@objects.each { |o| @vertex_count += o.vertices.size }
|
@objects.each { |o| @vertex_count += o.vertices.size }
|
||||||
|
|
||||||
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
||||||
# build_collision_tree
|
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
|
end
|
||||||
|
|
||||||
def parse(parser)
|
def parse(parser)
|
||||||
@@ -177,7 +178,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def build_collision_tree
|
def build_collision_tree
|
||||||
@aabb_tree = AABBTree.new
|
@aabb_tree = IMICFPS::AABBTree.new
|
||||||
|
|
||||||
@faces.each do |face|
|
@faces.each do |face|
|
||||||
box = BoundingBox.new
|
box = BoundingBox.new
|
||||||
|
|||||||
@@ -11,7 +11,19 @@ module CyberarmEngine
|
|||||||
if e != GL_NO_ERROR
|
if e != GL_NO_ERROR
|
||||||
warn "OpenGL error detected by handler at: #{caller[0]}"
|
warn "OpenGL error detected by handler at: #{caller[0]}"
|
||||||
warn " #{gluErrorString(e)} (#{e})\n"
|
warn " #{gluErrorString(e)} (#{e})\n"
|
||||||
exit if window.exit_on_opengl_error?
|
exit if Window.instance&.exit_on_opengl_error?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def preload_default_shaders
|
||||||
|
shaders = %w[g_buffer lighting]
|
||||||
|
shaders.each do |shader|
|
||||||
|
Shader.new(
|
||||||
|
name: shader,
|
||||||
|
includes_dir: "#{CYBERARM_ENGINE_ROOT_PATH}/assets/shaders/include",
|
||||||
|
vertex: "#{CYBERARM_ENGINE_ROOT_PATH}/assets/shaders/vertex/#{shader}.glsl",
|
||||||
|
fragment: "#{CYBERARM_ENGINE_ROOT_PATH}/assets/shaders/fragment/#{shader}.glsl"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
class GBuffer
|
class GBuffer
|
||||||
attr_reader :screen_vbo, :vertices, :uvs
|
attr_reader :screen_vbo, :vertices, :uvs
|
||||||
|
attr_reader :width, :height
|
||||||
|
|
||||||
def initialize(width:, height:)
|
def initialize(width:, height:)
|
||||||
@width = width
|
@width = width
|
||||||
|
|||||||
@@ -8,8 +8,19 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw(camera, lights, entities)
|
def draw(camera, lights, entities)
|
||||||
|
Stats.frame.start_timing(:opengl_renderer)
|
||||||
|
|
||||||
|
Stats.frame.start_timing(:opengl_model_renderer)
|
||||||
@opengl_renderer.render(camera, lights, entities)
|
@opengl_renderer.render(camera, lights, entities)
|
||||||
@bounding_box_renderer.render(entities) if @show_bounding_boxes
|
Stats.frame.end_timing(:opengl_model_renderer)
|
||||||
|
|
||||||
|
if @show_bounding_boxes
|
||||||
|
Stats.frame.start_timing(:opengl_boundingbox_renderer)
|
||||||
|
@bounding_box_renderer.render(entities)
|
||||||
|
Stats.frame.end_timing(:opengl_boundingbox_renderer)
|
||||||
|
end
|
||||||
|
|
||||||
|
Stats.frame.end_timing(:opengl_renderer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def canvas_size_changed
|
def canvas_size_changed
|
||||||
|
|||||||
@@ -1,20 +1,191 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
class Stats
|
class Stats
|
||||||
@@hash = {
|
@frames = []
|
||||||
gui_recalculations_last_frame: 0
|
@frame_index = -1
|
||||||
}
|
@max_frame_history = 1024
|
||||||
|
|
||||||
def self.get(key)
|
def self.new_frame
|
||||||
@@hash.dig(key)
|
if @frames.size < @max_frame_history
|
||||||
|
@frames << Frame.new
|
||||||
|
else
|
||||||
|
@frames[@frame_index] = Frame.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.increment(key, n)
|
def self.frame
|
||||||
@@hash[key] += n
|
@frames[@frame_index]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.clear
|
def self.end_frame
|
||||||
@@hash.each do |key, _value|
|
frame&.complete
|
||||||
@@hash[key] = 0
|
|
||||||
|
@frame_index += 1
|
||||||
|
@frame_index %= @max_frame_history
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.frames
|
||||||
|
if @frames.size < @max_frame_history
|
||||||
|
@frames
|
||||||
|
else
|
||||||
|
@frames.rotate(@frame_index - (@max_frame_history - (@frames.size - 1)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.frame_index
|
||||||
|
@frame_index
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.max_frame_history
|
||||||
|
@max_frame_history
|
||||||
|
end
|
||||||
|
|
||||||
|
class Frame
|
||||||
|
Timing = Struct.new(:start_time, :end_time, :duration)
|
||||||
|
|
||||||
|
attr_reader :frame_timing, :counters, :timings, :multitimings
|
||||||
|
def initialize
|
||||||
|
@frame_timing = Timing.new(Gosu.milliseconds, -1, -1)
|
||||||
|
@attempted_multitiming = false
|
||||||
|
|
||||||
|
@counters = {
|
||||||
|
gui_recalculations: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
@timings = {}
|
||||||
|
@multitimings = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def increment(key, number = 1)
|
||||||
|
@counters[key] ||= 0
|
||||||
|
@counters[key] += number
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_timing(key)
|
||||||
|
raise "key must be a symbol!" unless key.is_a?(Symbol)
|
||||||
|
if @timings[key]
|
||||||
|
# FIXME: Make it not spammy...
|
||||||
|
# warn "Only one timing per key per frame. (Timing for #{key.inspect} already exists!)"
|
||||||
|
@attempted_multitiming = true
|
||||||
|
@multitimings[key] = true
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
@timings[key] = Timing.new(Gosu.milliseconds, -1, -1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_timing(key)
|
||||||
|
timing = @timings[key]
|
||||||
|
|
||||||
|
# FIXME: Make it not spammy...
|
||||||
|
# warn "Timing #{key.inspect} already ended!" if timing.end_time != -1
|
||||||
|
|
||||||
|
timing.end_time = Gosu.milliseconds
|
||||||
|
timing.duration = timing.end_time - timing.start_time
|
||||||
|
end
|
||||||
|
|
||||||
|
def complete
|
||||||
|
@frame_timing.end_time = Gosu.milliseconds
|
||||||
|
@frame_timing.duration = @frame_timing.end_time - @frame_timing.start_time
|
||||||
|
|
||||||
|
# Lock data structures
|
||||||
|
@frame_timing.freeze
|
||||||
|
@counters.freeze
|
||||||
|
@timings.freeze
|
||||||
|
@multitimings.freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def complete?
|
||||||
|
@frame_timing.duration != -1
|
||||||
|
end
|
||||||
|
|
||||||
|
def attempted_multitiming?
|
||||||
|
@attempted_multitiming
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class StatsPlotter
|
||||||
|
attr_reader :position
|
||||||
|
|
||||||
|
def initialize(x, y, z = Float::INFINITY, width = 128, height = 128)
|
||||||
|
@position = Vector.new(x, y, z)
|
||||||
|
@width = width
|
||||||
|
@height = height
|
||||||
|
|
||||||
|
@padding = 2
|
||||||
|
@text_size = 16
|
||||||
|
|
||||||
|
@max_timing_label = CyberarmEngine::Text.new("", x: x + @padding + 1, y: y + @padding, z: z, size: @text_size, border: true)
|
||||||
|
@avg_timing_label = CyberarmEngine::Text.new("", x: x + @padding + 1, y: y + @padding + @height / 2 - @text_size / 2, z: z, size: @text_size, border: true)
|
||||||
|
@min_timing_label = CyberarmEngine::Text.new("", x: x + @padding + 1, y: y + @height - (@text_size + @padding / 2), z: z, size: @text_size, border: true)
|
||||||
|
|
||||||
|
@timings_label = CyberarmEngine::Text.new("", x: x + @padding + @width + @padding, y: y + @padding, z: z, size: @text_size, border: true)
|
||||||
|
|
||||||
|
@frame_stats = []
|
||||||
|
@graphs = {
|
||||||
|
frame_timings: []
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_graphs
|
||||||
|
calculate_frame_timings_graph
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_frame_timings_graph
|
||||||
|
@graphs[:frame_timings].clear
|
||||||
|
|
||||||
|
samples = @width - @padding
|
||||||
|
nodes = Array.new(samples.ceil) { [] }
|
||||||
|
|
||||||
|
slice = 0
|
||||||
|
@frame_stats.each_slice((CyberarmEngine::Stats.max_frame_history / samples.to_f).ceil) do |bucket|
|
||||||
|
bucket.each do |frame|
|
||||||
|
nodes[slice] << frame.frame_timing.duration
|
||||||
|
end
|
||||||
|
|
||||||
|
slice += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
nodes.each_with_index do |cluster, i|
|
||||||
|
break if cluster.empty?
|
||||||
|
|
||||||
|
@graphs[:frame_timings] << CyberarmEngine::Vector.new(@position.x + @padding + 1 * i, (@position.y + @height - @padding) - cluster.max)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
@frame_stats = CyberarmEngine::Stats.frames.select(&:complete?)
|
||||||
|
return if @frame_stats.empty?
|
||||||
|
|
||||||
|
calculate_graphs
|
||||||
|
|
||||||
|
@max_timing_label.text = "Max: #{@frame_stats.map { |f| f.frame_timing.duration }.max.to_s.rjust(3, " ")}ms"
|
||||||
|
@avg_timing_label.text = "Avg: #{(@frame_stats.map { |f| f.frame_timing.duration }.sum / @frame_stats.size).to_s.rjust(3, " ")}ms"
|
||||||
|
@min_timing_label.text = "Min: #{@frame_stats.map { |f| f.frame_timing.duration }.min.to_s.rjust(3, " ")}ms"
|
||||||
|
|
||||||
|
Gosu.draw_rect(@position.x, @position.y, @width, @height, 0xaa_222222, @position.z)
|
||||||
|
Gosu.draw_rect(@position.x + @padding, @position.y + @padding, @width - @padding * 2, @height - @padding * 2, 0xaa_222222, @position.z)
|
||||||
|
|
||||||
|
draw_graphs
|
||||||
|
|
||||||
|
@max_timing_label.draw
|
||||||
|
@avg_timing_label.draw
|
||||||
|
@min_timing_label.draw
|
||||||
|
|
||||||
|
# TODO: Make this optional
|
||||||
|
draw_timings
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw_graphs
|
||||||
|
Gosu.draw_path(@graphs[:frame_timings], Gosu::Color::WHITE, Float::INFINITY)
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw_timings
|
||||||
|
frame = @frame_stats.last
|
||||||
|
|
||||||
|
@timings_label.text = "#{frame.attempted_multitiming? ? "<c=d00>Attempted Multitiming!\nTimings may be inaccurate for:\n#{frame.multitimings.map { |m, _| m}.join("\n") }</c>\n\n" : ''}#{frame.timings.map { |t, v| "#{t}: #{v.duration}ms" }.join("\n")}"
|
||||||
|
Gosu.draw_rect(@timings_label.x - @padding, @timings_label.y - @padding, @timings_label.width + @padding * 2, @timings_label.height + @padding * 2, 0xdd_222222, @position.z)
|
||||||
|
@timings_label.draw
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ module CyberarmEngine
|
|||||||
@size = size
|
@size = size
|
||||||
@font = font_name
|
@font = font_name
|
||||||
|
|
||||||
|
invalidate_cache!
|
||||||
@textobject = check_cache(size, font_name)
|
@textobject = check_cache(size, font_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -149,6 +150,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def markup_width(text = @text)
|
def markup_width(text = @text)
|
||||||
|
text = text.to_s
|
||||||
|
|
||||||
spacing = 0
|
spacing = 0
|
||||||
spacing += @border_size if @border
|
spacing += @border_size if @border
|
||||||
spacing += @shadow_size if @shadow
|
spacing += @shadow_size if @shadow
|
||||||
|
|||||||
@@ -62,11 +62,11 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
# TOP
|
# TOP
|
||||||
@top.x = @element.x # + @element.border_thickness_left
|
@top.x = @element.x + @element.style.border_thickness_left
|
||||||
@top.y = @element.y
|
@top.y = @element.y
|
||||||
@top.z = @element.z
|
@top.z = @element.z
|
||||||
|
|
||||||
@top.width = @element.width
|
@top.width = @element.width - @element.style.border_thickness_left
|
||||||
@top.height = @element.style.border_thickness_top
|
@top.height = @element.style.border_thickness_top
|
||||||
|
|
||||||
# RIGHT
|
# RIGHT
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ module CyberarmEngine
|
|||||||
|
|
||||||
set_border_thickness
|
set_border_thickness
|
||||||
set_border_color
|
set_border_color
|
||||||
|
|
||||||
|
root.gui_state.request_repaint
|
||||||
end
|
end
|
||||||
|
|
||||||
def safe_style_fetch(*args)
|
def safe_style_fetch(*args)
|
||||||
@@ -166,10 +168,10 @@ module CyberarmEngine
|
|||||||
return if self.is_a?(ToolTip)
|
return if self.is_a?(ToolTip)
|
||||||
|
|
||||||
if old_width != width || old_height != height
|
if old_width != width || old_height != height
|
||||||
(root&.gui_state || @gui_state).request_recalculate
|
root.gui_state.request_recalculate
|
||||||
else
|
|
||||||
stylize
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
stylize
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_events
|
def default_events
|
||||||
@@ -194,7 +196,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def enter(_sender)
|
def enter(_sender)
|
||||||
@focus = false unless window.button_down?(Gosu::MsLeft)
|
@focus = false unless Gosu.button_down?(Gosu::MS_LEFT)
|
||||||
|
|
||||||
if !@enabled
|
if !@enabled
|
||||||
update_styles(:disabled)
|
update_styles(:disabled)
|
||||||
@@ -256,6 +258,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def enabled=(boolean)
|
def enabled=(boolean)
|
||||||
|
root.gui_state.request_repaint if @enabled != boolean
|
||||||
|
|
||||||
@enabled = boolean
|
@enabled = boolean
|
||||||
|
|
||||||
recalculate
|
recalculate
|
||||||
@@ -267,6 +271,10 @@ module CyberarmEngine
|
|||||||
@enabled
|
@enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def focused?
|
||||||
|
@focus
|
||||||
|
end
|
||||||
|
|
||||||
def visible?
|
def visible?
|
||||||
@visible
|
@visible
|
||||||
end
|
end
|
||||||
@@ -278,18 +286,21 @@ module CyberarmEngine
|
|||||||
def toggle
|
def toggle
|
||||||
@visible = !@visible
|
@visible = !@visible
|
||||||
root.gui_state.request_recalculate
|
root.gui_state.request_recalculate
|
||||||
|
root.gui_state.request_repaint
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
bool = visible?
|
bool = visible?
|
||||||
@visible = true
|
@visible = true
|
||||||
root.gui_state.request_recalculate unless bool
|
root.gui_state.request_recalculate unless bool
|
||||||
|
root.gui_state.request_repaint unless bool
|
||||||
end
|
end
|
||||||
|
|
||||||
def hide
|
def hide
|
||||||
bool = visible?
|
bool = visible?
|
||||||
@visible = false
|
@visible = false
|
||||||
root.gui_state.request_recalculate if bool
|
root.gui_state.request_recalculate if bool
|
||||||
|
root.gui_state.request_repaint if bool
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
@@ -305,7 +316,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def debug_draw
|
def debug_draw
|
||||||
return if defined?(GUI_DEBUG_ONLY_ELEMENT) && self.class == GUI_DEBUG_ONLY_ELEMENT
|
# FIXME
|
||||||
|
return# if const_defined?(GUI_DEBUG_ONLY_ELEMENT) && self.class == GUI_DEBUG_ONLY_ELEMENT
|
||||||
|
|
||||||
Gosu.draw_line(
|
Gosu.draw_line(
|
||||||
x, y, @debug_color,
|
x, y, @debug_color,
|
||||||
@@ -423,9 +435,9 @@ module CyberarmEngine
|
|||||||
|
|
||||||
pairs_ << a_ unless pairs_.last == a_
|
pairs_ << a_ unless pairs_.last == a_
|
||||||
|
|
||||||
pairs_.sum { |pair| pair.map(&:outer_height).max } + @style.padding_bottom + @style.border_thickness_bottom
|
pairs_.sum { |pair| + @style.padding_top + @style.border_thickness_top + pair.map(&:outer_height).max } + @style.padding_bottom + @style.border_thickness_bottom
|
||||||
else
|
else
|
||||||
@children.sum(&:outer_height) + @style.padding_bottom + @style.border_thickness_bottom
|
@style.padding_top + @style.border_thickness_top + @children.sum(&:outer_height) + @style.padding_bottom + @style.border_thickness_bottom
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -440,24 +452,22 @@ module CyberarmEngine
|
|||||||
def dimensional_size(size, dimension)
|
def dimensional_size(size, dimension)
|
||||||
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
|
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
|
||||||
|
|
||||||
new_size = if size.is_a?(Numeric) && size.between?(0.0, 1.0)
|
new_size = if size.is_a?(Float) && size.between?(0.0, 1.0)
|
||||||
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
|
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
|
||||||
else
|
else
|
||||||
size
|
size
|
||||||
|
end
|
||||||
|
|
||||||
|
# Handle fill behavior
|
||||||
|
if @parent && @style.fill &&
|
||||||
|
(dimension == :width && @parent.is_a?(Flow) ||
|
||||||
|
dimension == :height && @parent.is_a?(Stack))
|
||||||
|
new_size = space_available_width - noncontent_width if dimension == :width && @parent.is_a?(Flow)
|
||||||
|
new_size = space_available_height - noncontent_height if dimension == :height && @parent.is_a?(Stack)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @parent && @style.fill # Handle fill behavior
|
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size.to_f < @style.send(:"min_#{dimension}")
|
||||||
if dimension == :width && @parent.is_a?(Flow)
|
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size.to_f > @style.send(:"max_#{dimension}")
|
||||||
return space_available_width - noncontent_width
|
|
||||||
|
|
||||||
elsif dimension == :height && @parent.is_a?(Stack)
|
|
||||||
return space_available_height - noncontent_height
|
|
||||||
end
|
|
||||||
|
|
||||||
else # Handle min_width/height and max_width/height
|
|
||||||
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size.to_f < @style.send(:"min_#{dimension}")
|
|
||||||
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size.to_f > @style.send(:"max_#{dimension}")
|
|
||||||
end
|
|
||||||
|
|
||||||
new_size
|
new_size
|
||||||
end
|
end
|
||||||
@@ -479,6 +489,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def background=(_background)
|
def background=(_background)
|
||||||
|
root.gui_state.request_repaint
|
||||||
|
|
||||||
@style.background_canvas.background = _background
|
@style.background_canvas.background = _background
|
||||||
update_background
|
update_background
|
||||||
end
|
end
|
||||||
@@ -497,6 +509,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def background_nine_slice=(_image_path)
|
def background_nine_slice=(_image_path)
|
||||||
|
root.gui_state.request_repaint
|
||||||
|
|
||||||
@style.background_nine_slice_canvas.image = _image_path
|
@style.background_nine_slice_canvas.image = _image_path
|
||||||
update_background_nine_slice
|
update_background_nine_slice
|
||||||
end
|
end
|
||||||
@@ -521,6 +535,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def background_image=(image_path)
|
def background_image=(image_path)
|
||||||
|
root.gui_state.request_repaint
|
||||||
|
|
||||||
@style.background_image = image_path.is_a?(Gosu::Image) ? image_path : get_image(image_path)
|
@style.background_image = image_path.is_a?(Gosu::Image) ? image_path : get_image(image_path)
|
||||||
update_background_image
|
update_background_image
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ module CyberarmEngine
|
|||||||
root.gui_state.request_recalculate
|
root.gui_state.request_recalculate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove(element)
|
||||||
|
root.gui_state.request_recalculate if @children.delete(element)
|
||||||
|
end
|
||||||
|
|
||||||
def clear(&block)
|
def clear(&block)
|
||||||
@children.clear
|
@children.clear
|
||||||
|
|
||||||
@@ -114,7 +118,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
return unless visible?
|
return unless visible?
|
||||||
|
|
||||||
Stats.increment(:gui_recalculations_last_frame, 1)
|
Stats.frame.increment(:gui_recalculations)
|
||||||
|
|
||||||
stylize
|
stylize
|
||||||
|
|
||||||
@@ -122,6 +126,9 @@ module CyberarmEngine
|
|||||||
|
|
||||||
layout
|
layout
|
||||||
|
|
||||||
|
old_width = @width
|
||||||
|
old_height = @height
|
||||||
|
|
||||||
if is_root?
|
if is_root?
|
||||||
@width = @style.width = window.width
|
@width = @style.width = window.width
|
||||||
@height = @style.height = window.height
|
@height = @style.height = window.height
|
||||||
@@ -169,7 +176,7 @@ module CyberarmEngine
|
|||||||
child.recalculate
|
child.recalculate
|
||||||
child.reposition # TODO: Implement top,bottom,left,center, and right positioning
|
child.reposition # TODO: Implement top,bottom,left,center, and right positioning
|
||||||
|
|
||||||
Stats.increment(:gui_recalculations_last_frame, 1)
|
Stats.frame.increment(:gui_recalculations)
|
||||||
|
|
||||||
child.element_visible = child.x >= @x - child.width && child.x <= @x + width &&
|
child.element_visible = child.x >= @x - child.width && child.x <= @x + width &&
|
||||||
child.y >= @y - child.height && child.y <= @y + height
|
child.y >= @y - child.height && child.y <= @y + height
|
||||||
@@ -178,6 +185,11 @@ module CyberarmEngine
|
|||||||
# puts "TOOK: #{Gosu.milliseconds - s}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}"
|
# puts "TOOK: #{Gosu.milliseconds - s}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}"
|
||||||
|
|
||||||
update_background
|
update_background
|
||||||
|
|
||||||
|
# Fixes resized container scrolled past bottom
|
||||||
|
self.scroll_top = -@scroll_position.y
|
||||||
|
|
||||||
|
root.gui_state.request_repaint if @width != old_width || @height != old_height
|
||||||
end
|
end
|
||||||
|
|
||||||
def layout
|
def layout
|
||||||
@@ -242,6 +254,7 @@ module CyberarmEngine
|
|||||||
@scroll_position.y = 0 if @scroll_position.y > 0
|
@scroll_position.y = 0 if @scroll_position.y > 0
|
||||||
|
|
||||||
root.gui_state.request_recalculate_for(self)
|
root.gui_state.request_recalculate_for(self)
|
||||||
|
root.gui_state.request_repaint
|
||||||
|
|
||||||
return :handled
|
return :handled
|
||||||
end
|
end
|
||||||
@@ -257,6 +270,7 @@ module CyberarmEngine
|
|||||||
@scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
|
@scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
|
||||||
|
|
||||||
root.gui_state.request_recalculate_for(self)
|
root.gui_state.request_recalculate_for(self)
|
||||||
|
root.gui_state.request_repaint
|
||||||
|
|
||||||
return :handled
|
return :handled
|
||||||
end
|
end
|
||||||
@@ -278,7 +292,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
@children.map { |c| c.class }.join(", ")
|
@children.map(&:class).join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|||||||
@@ -80,16 +80,22 @@ module CyberarmEngine
|
|||||||
@show_caret = true
|
@show_caret = true
|
||||||
@caret_last_interval = Gosu.milliseconds
|
@caret_last_interval = Gosu.milliseconds
|
||||||
|
|
||||||
|
root.gui_state.request_repaint
|
||||||
|
|
||||||
publish(:changed, value)
|
publish(:changed, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @last_caret_position != @text_input.caret_pos
|
if @last_caret_position != @text_input.caret_pos
|
||||||
@last_caret_position = @text_input.caret_pos
|
@last_caret_position = @text_input.caret_pos
|
||||||
|
root.gui_state.request_repaint
|
||||||
|
|
||||||
@show_caret = true
|
@show_caret = true
|
||||||
@caret_last_interval = Gosu.milliseconds
|
@caret_last_interval = Gosu.milliseconds
|
||||||
end
|
end
|
||||||
|
|
||||||
if Gosu.milliseconds >= @caret_last_interval + @caret_interval
|
if Gosu.milliseconds >= @caret_last_interval + @caret_interval
|
||||||
|
root.gui_state.request_repaint
|
||||||
|
|
||||||
@caret_last_interval = Gosu.milliseconds
|
@caret_last_interval = Gosu.milliseconds
|
||||||
|
|
||||||
@show_caret = !@show_caret
|
@show_caret = !@show_caret
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ module CyberarmEngine
|
|||||||
@scale_y = 1
|
@scale_y = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@width = _width || @image.width.floor * @scale_x
|
@width = _width || (@image.width * @scale_x).floor
|
||||||
@height = _height || @image.height.floor * @scale_y
|
@height = _height || (@image.height * @scale_y).floor
|
||||||
|
|
||||||
update_background
|
update_background
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ module CyberarmEngine
|
|||||||
@marquee_animation_time = Gosu.milliseconds if @marquee_offset > range
|
@marquee_animation_time = Gosu.milliseconds if @marquee_offset > range
|
||||||
|
|
||||||
update_background
|
update_background
|
||||||
|
root.gui_state.request_repaint
|
||||||
end
|
end
|
||||||
|
|
||||||
def type=(type)
|
def type=(type)
|
||||||
@@ -77,9 +78,13 @@ module CyberarmEngine
|
|||||||
def value=(decimal)
|
def value=(decimal)
|
||||||
raise "value must be number" unless decimal.is_a?(Numeric)
|
raise "value must be number" unless decimal.is_a?(Numeric)
|
||||||
|
|
||||||
|
old_value = @fraction
|
||||||
|
|
||||||
@fraction = decimal.clamp(0.0, 1.0)
|
@fraction = decimal.clamp(0.0, 1.0)
|
||||||
update_background
|
update_background
|
||||||
|
|
||||||
|
root.gui_state.request_repaint if @fraction != old_value
|
||||||
|
|
||||||
publish(:changed, @fraction)
|
publish(:changed, @fraction)
|
||||||
@fraction
|
@fraction
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :range, :step_size, :value
|
attr_reader :step_size, :value
|
||||||
|
attr_accessor :range, :step_size
|
||||||
|
|
||||||
def initialize(options = {}, block = nil)
|
def initialize(options = {}, block = nil)
|
||||||
super(options, block)
|
super(options, block)
|
||||||
@@ -76,7 +77,7 @@ module CyberarmEngine
|
|||||||
def update
|
def update
|
||||||
super
|
super
|
||||||
|
|
||||||
@tip = value.to_s
|
@tip = format("%.2f", value.to_f)
|
||||||
@handle.tip = @tip
|
@handle.tip = @tip
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -87,7 +88,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def handle_dragged_to(x, _y)
|
def handle_dragged_to(x, _y)
|
||||||
@ratio = ((x - @handle.width / 2) - @x) / (content_width - @handle.outer_width)
|
@ratio = ((x - @handle.width / 2.0) - @x) / (content_width - @handle.outer_width.to_f)
|
||||||
|
|
||||||
self.value = @ratio.clamp(0.0, 1.0) * (@range.max - @range.min) + @range.min
|
self.value = @ratio.clamp(0.0, 1.0) * (@range.max - @range.min) + @range.min
|
||||||
end
|
end
|
||||||
@@ -97,6 +98,8 @@ module CyberarmEngine
|
|||||||
position_handle
|
position_handle
|
||||||
@handle.recalculate
|
@handle.recalculate
|
||||||
|
|
||||||
|
root.gui_state.request_repaint
|
||||||
|
|
||||||
publish(:changed, @value)
|
publish(:changed, @value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,6 +18,15 @@ module CyberarmEngine
|
|||||||
@raw_text = text
|
@raw_text = text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
super
|
||||||
|
|
||||||
|
if @text.textobject.name != safe_style_fetch(:font)
|
||||||
|
set_font
|
||||||
|
root.gui_state.request_recalculate
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def render
|
def render
|
||||||
# Gosu.clip_to is too expensive to always use so check if we actually need it.
|
# Gosu.clip_to is too expensive to always use so check if we actually need it.
|
||||||
if @text.width > width || @text.height > height
|
if @text.width > width || @text.height > height
|
||||||
@@ -36,6 +45,9 @@ module CyberarmEngine
|
|||||||
@text.color = @style.color
|
@text.color = @style.color
|
||||||
end
|
end
|
||||||
|
|
||||||
|
old_width = @width
|
||||||
|
old_height = @height
|
||||||
|
|
||||||
@width = 0
|
@width = 0
|
||||||
@height = 0
|
@height = 0
|
||||||
|
|
||||||
@@ -79,6 +91,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
update_background
|
update_background
|
||||||
|
|
||||||
|
root.gui_state.request_repaint if @width != old_width || @height != old_height
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_text_wrapping(max_width)
|
def handle_text_wrapping(max_width)
|
||||||
@@ -151,7 +165,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def line_width(text)
|
def line_width(text)
|
||||||
(@text.textobject.markup_width(text) + noncontent_width)
|
(@text.textobject.markup_width(text.to_s) + noncontent_width)
|
||||||
end
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
@@ -159,6 +173,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def value=(value)
|
def value=(value)
|
||||||
|
old_value = @raw_text
|
||||||
@raw_text = value.to_s.chomp
|
@raw_text = value.to_s.chomp
|
||||||
|
|
||||||
old_width = width
|
old_width = width
|
||||||
@@ -170,6 +185,8 @@ module CyberarmEngine
|
|||||||
recalculate
|
recalculate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
root.gui_state.request_repaint if old_value != @raw_text
|
||||||
|
|
||||||
publish(:changed, self.value)
|
publish(:changed, self.value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ module CyberarmEngine
|
|||||||
@pending_recalculate_request = false
|
@pending_recalculate_request = false
|
||||||
@pending_element_recalculate_requests = []
|
@pending_element_recalculate_requests = []
|
||||||
|
|
||||||
|
@needs_repaint = false
|
||||||
|
|
||||||
@menu = nil
|
@menu = nil
|
||||||
@min_drag_distance = 0
|
@min_drag_distance = 0
|
||||||
@mouse_pos = Vector.new
|
@mouse_pos = Vector.new
|
||||||
@@ -55,31 +57,45 @@ module CyberarmEngine
|
|||||||
@menu.draw
|
@menu.draw
|
||||||
end
|
end
|
||||||
|
|
||||||
if @tip.value.length.positive?
|
if @tip && @tip.value.length.positive?
|
||||||
Gosu.flush
|
Gosu.flush
|
||||||
|
|
||||||
@tip.draw
|
@tip.draw
|
||||||
end
|
end
|
||||||
|
|
||||||
if defined?(GUI_DEBUG)
|
# FIXME
|
||||||
|
if false# defined?(GUI_DEBUG)
|
||||||
Gosu.flush
|
Gosu.flush
|
||||||
|
|
||||||
@root_container.debug_draw
|
@root_container.debug_draw
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@needs_repaint = false
|
||||||
|
end
|
||||||
|
|
||||||
|
def needs_repaint?
|
||||||
|
@needs_repaint
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @pending_recalculate_request
|
if @pending_recalculate_request
|
||||||
|
Stats.frame.start_timing(:gui_recalculate)
|
||||||
@root_container.recalculate
|
@root_container.recalculate
|
||||||
@root_container.recalculate
|
@root_container.recalculate
|
||||||
@root_container.recalculate
|
@root_container.recalculate
|
||||||
|
|
||||||
@pending_recalculate_request = false
|
@pending_recalculate_request = false
|
||||||
|
|
||||||
|
Stats.frame.end_timing(:gui_recalculate)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Stats.frame.start_timing(:gui_element_recalculate_requests)
|
||||||
|
|
||||||
@pending_element_recalculate_requests.each(&:recalculate)
|
@pending_element_recalculate_requests.each(&:recalculate)
|
||||||
@pending_element_recalculate_requests.clear
|
@pending_element_recalculate_requests.clear
|
||||||
|
|
||||||
|
Stats.frame.end_timing(:gui_element_recalculate_requests)
|
||||||
|
|
||||||
if @pending_focus_request
|
if @pending_focus_request
|
||||||
@pending_focus_request = false
|
@pending_focus_request = false
|
||||||
|
|
||||||
@@ -88,9 +104,19 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
@menu&.update
|
@menu&.update
|
||||||
|
|
||||||
super
|
super
|
||||||
|
|
||||||
|
if @active_width != window.width || @active_height != window.height
|
||||||
|
request_recalculate
|
||||||
|
@root_container.publish(:window_size_changed)
|
||||||
|
end
|
||||||
|
|
||||||
|
@active_width = window.width
|
||||||
|
@active_height = window.height
|
||||||
|
|
||||||
return unless window.has_focus?
|
return unless window.has_focus?
|
||||||
|
return unless window.current_state == self
|
||||||
|
|
||||||
new_mouse_over = @menu.hit_element?(window.mouse_x, window.mouse_y) if @menu
|
new_mouse_over = @menu.hit_element?(window.mouse_x, window.mouse_y) if @menu
|
||||||
new_mouse_over ||= @root_container.hit_element?(window.mouse_x, window.mouse_y)
|
new_mouse_over ||= @root_container.hit_element?(window.mouse_x, window.mouse_y)
|
||||||
@@ -103,9 +129,9 @@ module CyberarmEngine
|
|||||||
@mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over
|
@mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over
|
||||||
@mouse_over = new_mouse_over
|
@mouse_over = new_mouse_over
|
||||||
|
|
||||||
redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MsLeft)
|
redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MS_LEFT)
|
||||||
redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MsMiddle)
|
redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MS_MIDDLE)
|
||||||
redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MsRight)
|
redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MS_RIGHT)
|
||||||
|
|
||||||
if Vector.new(window.mouse_x, window.mouse_y) == @last_mouse_pos
|
if Vector.new(window.mouse_x, window.mouse_y) == @last_mouse_pos
|
||||||
if @mouse_over && (Gosu.milliseconds - @mouse_moved_at) > tool_tip_delay
|
if @mouse_over && (Gosu.milliseconds - @mouse_moved_at) > tool_tip_delay
|
||||||
@@ -127,27 +153,19 @@ module CyberarmEngine
|
|||||||
|
|
||||||
@last_mouse_pos = Vector.new(window.mouse_x, window.mouse_y)
|
@last_mouse_pos = Vector.new(window.mouse_x, window.mouse_y)
|
||||||
@mouse_pos = @last_mouse_pos.clone
|
@mouse_pos = @last_mouse_pos.clone
|
||||||
|
|
||||||
if @active_width != window.width || @active_height != window.height
|
|
||||||
request_recalculate
|
|
||||||
@root_container.publish(:window_size_changed)
|
|
||||||
end
|
|
||||||
|
|
||||||
@active_width = window.width
|
|
||||||
@active_height = window.height
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def button_down(id)
|
def button_down(id)
|
||||||
super
|
super
|
||||||
|
|
||||||
case id
|
case id
|
||||||
when Gosu::MsLeft
|
when Gosu::MS_LEFT
|
||||||
redirect_mouse_button(:left)
|
redirect_mouse_button(:left)
|
||||||
when Gosu::MsMiddle
|
when Gosu::MS_MIDDLE
|
||||||
redirect_mouse_button(:middle)
|
redirect_mouse_button(:middle)
|
||||||
when Gosu::MsRight
|
when Gosu::MS_RIGHT
|
||||||
redirect_mouse_button(:right)
|
redirect_mouse_button(:right)
|
||||||
when Gosu::KbF5
|
when Gosu::KB_F5
|
||||||
request_recalculate
|
request_recalculate
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -158,15 +176,15 @@ module CyberarmEngine
|
|||||||
super
|
super
|
||||||
|
|
||||||
case id
|
case id
|
||||||
when Gosu::MsLeft
|
when Gosu::MS_LEFT
|
||||||
redirect_released_mouse_button(:left)
|
redirect_released_mouse_button(:left)
|
||||||
when Gosu::MsMiddle
|
when Gosu::MS_MIDDLE
|
||||||
redirect_released_mouse_button(:middle)
|
redirect_released_mouse_button(:middle)
|
||||||
when Gosu::MsRight
|
when Gosu::MS_RIGHT
|
||||||
redirect_released_mouse_button(:right)
|
redirect_released_mouse_button(:right)
|
||||||
when Gosu::MsWheelUp
|
when Gosu::MS_WHEEL_UP
|
||||||
redirect_mouse_wheel(:up)
|
redirect_mouse_wheel(:up)
|
||||||
when Gosu::MsWheelDown
|
when Gosu::MS_WHEEL_DOWN
|
||||||
redirect_mouse_wheel(:down)
|
redirect_mouse_wheel(:down)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -253,6 +271,12 @@ module CyberarmEngine
|
|||||||
@pending_focus_element = element
|
@pending_focus_element = element
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def request_repaint
|
||||||
|
# puts caller[0..4]
|
||||||
|
# puts
|
||||||
|
@needs_repaint = true
|
||||||
|
end
|
||||||
|
|
||||||
def show_menu(list_box)
|
def show_menu(list_box)
|
||||||
@menu = list_box
|
@menu = list_box
|
||||||
end
|
end
|
||||||
@@ -260,6 +284,8 @@ module CyberarmEngine
|
|||||||
def hide_menu
|
def hide_menu
|
||||||
return unless @menu
|
return unless @menu
|
||||||
|
|
||||||
|
request_repaint
|
||||||
|
|
||||||
@hid_menu_for = @menu.parent
|
@hid_menu_for = @menu.parent
|
||||||
@menu = nil
|
@menu = nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ module CyberarmEngine
|
|||||||
attr_reader :hash
|
attr_reader :hash
|
||||||
|
|
||||||
def initialize(hash = {})
|
def initialize(hash = {})
|
||||||
h = Marshal.load(Marshal.dump(hash))
|
h = hash
|
||||||
|
# h = Marshal.load(Marshal.dump(hash))
|
||||||
|
|
||||||
h[:default] = {}
|
h[:default] = {}
|
||||||
|
|
||||||
|
|||||||
@@ -95,39 +95,58 @@ module CyberarmEngine
|
|||||||
Vector.new(@x, @y)
|
Vector.new(@x, @y)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Performs math operation, excluding {weight}
|
|
||||||
private def operator(function, other)
|
|
||||||
if other.is_a?(Numeric)
|
|
||||||
Vector.new(
|
|
||||||
@x.send(:"#{function}", other),
|
|
||||||
@y.send(:"#{function}", other),
|
|
||||||
@z.send(:"#{function}", other)
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Vector.new(
|
|
||||||
@x.send(:"#{function}", other.x),
|
|
||||||
@y.send(:"#{function}", other.y),
|
|
||||||
@z.send(:"#{function}", other.z)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Adds Vector and Numeric or Vector and Vector, excluding {weight}
|
# Adds Vector and Numeric or Vector and Vector, excluding {weight}
|
||||||
# @return [CyberarmEngine::Vector]
|
# @return [CyberarmEngine::Vector]
|
||||||
def +(other)
|
def +(other)
|
||||||
operator("+", other)
|
if other.is_a?(Numeric)
|
||||||
|
Vector.new(
|
||||||
|
@x + other,
|
||||||
|
@y + other,
|
||||||
|
@z + other
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Vector.new(
|
||||||
|
@x + other.x,
|
||||||
|
@y + other.y,
|
||||||
|
@z + other.z
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Subtracts Vector and Numeric or Vector and Vector, excluding {weight}
|
# Subtracts Vector and Numeric or Vector and Vector, excluding {weight}
|
||||||
# @return [CyberarmEngine::Vector]
|
# @return [CyberarmEngine::Vector]
|
||||||
def -(other)
|
def -(other)
|
||||||
operator("-", other)
|
if other.is_a?(Numeric)
|
||||||
|
Vector.new(
|
||||||
|
@x - other,
|
||||||
|
@y - other,
|
||||||
|
@z - other
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Vector.new(
|
||||||
|
@x - other.x,
|
||||||
|
@y - other.y,
|
||||||
|
@z - other.z
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Multiplies Vector and Numeric or Vector and Vector, excluding {weight}
|
# Multiplies Vector and Numeric or Vector and Vector, excluding {weight}
|
||||||
# @return [CyberarmEngine::Vector]
|
# @return [CyberarmEngine::Vector]
|
||||||
def *(other)
|
def *(other)
|
||||||
operator("*", other)
|
if other.is_a?(Numeric)
|
||||||
|
Vector.new(
|
||||||
|
@x * other,
|
||||||
|
@y * other,
|
||||||
|
@z * other
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Vector.new(
|
||||||
|
@x * other.x,
|
||||||
|
@y * other.y,
|
||||||
|
@z * other.z
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def multiply_transform(transform)
|
def multiply_transform(transform)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
NAME = "InDev".freeze
|
NAME = "InDev".freeze
|
||||||
VERSION = "0.22.0".freeze
|
VERSION = "0.23.0".freeze
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ module CyberarmEngine
|
|||||||
SAMPLES = {}
|
SAMPLES = {}
|
||||||
SONGS = {}
|
SONGS = {}
|
||||||
|
|
||||||
attr_accessor :show_cursor
|
attr_accessor :show_cursor, :show_stats_plotter
|
||||||
attr_writer :exit_on_opengl_error
|
attr_writer :exit_on_opengl_error
|
||||||
attr_reader :last_frame_time, :states
|
attr_reader :last_frame_time, :delta_time, :states
|
||||||
|
|
||||||
def self.now
|
def self.now
|
||||||
Gosu.milliseconds
|
Gosu.milliseconds
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.dt
|
def self.dt
|
||||||
instance.last_frame_time / 1000.0
|
instance.dt
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.instance=(window)
|
def self.instance=(window)
|
||||||
@@ -31,31 +31,57 @@ module CyberarmEngine
|
|||||||
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
|
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
|
||||||
@show_cursor = false
|
@show_cursor = false
|
||||||
@has_focus = false
|
@has_focus = false
|
||||||
|
@show_stats_plotter = false
|
||||||
|
|
||||||
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable, borderless: borderless)
|
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable, borderless: borderless)
|
||||||
Window.instance = self
|
Window.instance = self
|
||||||
|
|
||||||
@last_frame_time = Gosu.milliseconds - 1
|
@last_frame_time = Gosu.milliseconds - 1
|
||||||
@current_frame_time = Gosu.milliseconds
|
@current_frame_time = Gosu.milliseconds
|
||||||
self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.language}"
|
@delta_time = @last_frame_time
|
||||||
|
self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.user_languages.join(', ')}"
|
||||||
|
|
||||||
@states = []
|
@states = []
|
||||||
@exit_on_opengl_error = false
|
@exit_on_opengl_error = false
|
||||||
|
preload_default_shaders if respond_to?(:preload_default_shaders)
|
||||||
|
@stats_plotter = Stats::StatsPlotter.new(2, 28) # FIXME: Make positioning easy
|
||||||
|
|
||||||
setup if defined?(setup)
|
setup
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
|
Stats.frame.start_timing(:draw)
|
||||||
|
|
||||||
current_state&.draw
|
current_state&.draw
|
||||||
|
Stats.frame.start_timing(:engine_stats_renderer)
|
||||||
|
@stats_plotter&.draw if @show_stats_plotter
|
||||||
|
Stats.frame.end_timing(:engine_stats_renderer)
|
||||||
|
|
||||||
|
Stats.frame.end_timing(:draw)
|
||||||
|
Stats.frame.start_timing(:interframe_sleep)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
Stats.clear
|
# Gosu calls update() then (optionally) draw(),
|
||||||
|
# so always end last frame and start next frame when update() is called.
|
||||||
|
Stats.frame&.end_timing(:interframe_sleep)
|
||||||
|
Stats.end_frame
|
||||||
|
|
||||||
current_state&.update
|
Stats.new_frame
|
||||||
|
|
||||||
|
@delta_time = (Gosu.milliseconds - @current_frame_time) * 0.001
|
||||||
|
|
||||||
@last_frame_time = Gosu.milliseconds - @current_frame_time
|
@last_frame_time = Gosu.milliseconds - @current_frame_time
|
||||||
@current_frame_time = Gosu.milliseconds
|
@current_frame_time = Gosu.milliseconds
|
||||||
|
|
||||||
|
Stats.frame.start_timing(:update)
|
||||||
|
current_state&.update
|
||||||
|
Stats.frame.end_timing(:update)
|
||||||
|
|
||||||
|
Stats.frame.start_timing(:interframe_sleep) unless needs_redraw?
|
||||||
end
|
end
|
||||||
|
|
||||||
def needs_cursor?
|
def needs_cursor?
|
||||||
@@ -119,7 +145,7 @@ module CyberarmEngine
|
|||||||
def push_state(klass, options = {})
|
def push_state(klass, options = {})
|
||||||
options = { setup: true }.merge(options)
|
options = { setup: true }.merge(options)
|
||||||
|
|
||||||
if klass.instance_of?(klass.class) && defined?(klass.options)
|
if klass.instance_of?(klass.class) && klass.respond_to?(:options)
|
||||||
@states << klass
|
@states << klass
|
||||||
klass.setup if options[:setup]
|
klass.setup if options[:setup]
|
||||||
klass.post_setup if options[:setup]
|
klass.post_setup if options[:setup]
|
||||||
@@ -132,6 +158,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
private def child_of?(input, klass)
|
private def child_of?(input, klass)
|
||||||
|
return false unless input
|
||||||
|
|
||||||
input.ancestors.detect { |c| c == klass }
|
input.ancestors.detect { |c| c == klass }
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -141,10 +169,14 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def pop_state
|
def pop_state
|
||||||
@states.pop
|
@states.pop
|
||||||
|
|
||||||
|
current_state.request_repaint if current_state&.is_a?(GuiState)
|
||||||
end
|
end
|
||||||
|
|
||||||
def shift_state
|
def shift_state
|
||||||
@states.shift
|
@states.shift
|
||||||
|
|
||||||
|
current_state.request_repaint if current_state&.is_a?(GuiState)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_focus?
|
def has_focus?
|
||||||
|
|||||||
29
mrbgem.rake
Normal file
29
mrbgem.rake
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
MRuby::Gem::Specification.new("mruby-cyberarm_engine") do |spec|
|
||||||
|
spec.license = "MIT"
|
||||||
|
spec.authors = "cyberarm"
|
||||||
|
spec.summary = " Yet another framework for building games with Gosu"
|
||||||
|
|
||||||
|
lib_rbfiles = []
|
||||||
|
# Dir.glob("#{File.expand_path("..", __FILE__)}/lib/**/*.rb").reject do |f|
|
||||||
|
# File.basename(f.downcase, ".rb") == "cyberarm_engine" ||
|
||||||
|
# File.basename(f.downcase, ".rb") == "opengl" ||
|
||||||
|
# f.downcase.include?("/opengl/")
|
||||||
|
# end.reverse!
|
||||||
|
|
||||||
|
local_path = File.expand_path("..", __FILE__)
|
||||||
|
File.read("#{local_path}/lib/cyberarm_engine.rb").each_line do |line|
|
||||||
|
line = line.strip
|
||||||
|
|
||||||
|
next unless line.start_with?("require_relative")
|
||||||
|
|
||||||
|
file = line.split("require_relative").last.strip.gsub("\"", "")
|
||||||
|
|
||||||
|
next if file.include?(" if ")
|
||||||
|
|
||||||
|
lib_rbfiles << "#{local_path}/lib/#{file}.rb"
|
||||||
|
end
|
||||||
|
|
||||||
|
pp lib_rbfiles
|
||||||
|
|
||||||
|
spec.rbfiles = lib_rbfiles
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user