Compare commits

..

9 Commits

29 changed files with 236 additions and 14 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/.idea
/.bundle/
/.yardoc
/_yardoc/

View File

@@ -1,25 +1,37 @@
PATH
remote: .
specs:
cyberarm_engine (0.24.5)
cyberarm_engine (0.30.0)
gosu (~> 1.1)
GEM
remote: https://rubygems.org/
specs:
gosu (1.4.6)
minitest (5.25.5)
rake (13.2.1)
ffi (1.17.4-x86_64-linux-gnu)
ffi (1.17.4-x86_64-linux-musl)
gosu (1.5.0-x86_64-linux)
ffi (~> 1.12)
minitest (5.27.0)
rake (13.4.2)
PLATFORMS
x64-mingw-ucrt
x86_64-linux
x86_64-linux-gnu
x86_64-linux-musl
DEPENDENCIES
bundler (~> 2.2)
bundler (~> 4)
cyberarm_engine!
minitest (~> 5.0)
rake (~> 13.0)
CHECKSUMS
bundler (4.1.0.beta1) sha256=8a2dac8ca276ff4eff5efc2c6457b0044080fc1e431534ad7c5cc6187232b800
cyberarm_engine (0.30.0)
ffi (1.17.4-x86_64-linux-gnu) sha256=9d3db14c2eae074b382fa9c083fe95aec6e0a1451da249eab096c34002bc752d
ffi (1.17.4-x86_64-linux-musl) sha256=3fdf9888483de005f8ef8d1cf2d3b20d86626af206cbf780f6a6a12439a9c49e
gosu (1.5.0-x86_64-linux)
minitest (5.27.0) sha256=2d3b17f8a36fe7801c1adcffdbc38233b938eb0b4966e97a6739055a45fa77d5
rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701
BUNDLED WITH
2.6.8
4.1.0.beta1

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 430 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

View File

@@ -28,9 +28,8 @@ Gem::Specification.new do |spec|
spec.require_paths = %w[lib assets]
spec.add_dependency "gosu", "~> 1.1"
# spec.add_dependency "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows
spec.add_development_dependency "bundler", "~> 2.2"
spec.add_development_dependency "bundler", "~> 4"
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "rake", "~> 13.0"
end

View File

@@ -42,6 +42,13 @@ require_relative "cyberarm_engine/console/command"
require_relative "cyberarm_engine/console/subcommand"
require_relative "cyberarm_engine/console/commands/help_command"
require_relative "cyberarm_engine/pathfinding/graph"
require_relative "cyberarm_engine/pathfinding/graphs/grid"
require_relative "cyberarm_engine/pathfinding/graph_search"
require_relative "cyberarm_engine/pathfinding/graph_searches/breadth_first_search"
require_relative "cyberarm_engine/pathfinding/graph_searches/dijkstra_search"
require_relative "cyberarm_engine/pathfinding/graph_searches/astar_search"
require_relative "cyberarm_engine/ui/dsl"
require_relative "cyberarm_engine/ui/theme"

View File

@@ -33,6 +33,9 @@ module CyberarmEngine
@timers.delete_if(&:dead?)
end
def fixed_update(dt)
end
def needs_redraw?
true
end

View File

@@ -0,0 +1,64 @@
module CyberarmEngine
module Pathfinding
class Graph
class Node
KEY_FORMAT = "%s:%s:%s".freeze
attr_reader :x, :y, :z, :cost, :key, :edge_nodes
def initialize(x:, y:, z: 0, cost: 0)
@x = x
@y = y
@z = z
@cost = cost
@key = format(KEY_FORMAT, @x, @y, @z).freeze
@edge_nodes = []
end
def add_edge_node(node)
index = @edge_nodes.find_index { |n| n.key == node.key }
return if index
@edge_nodes.push(node)
end
def remove_edge_node(node)
index = @edge_nodes.find_index { |n| n.key == node.key }
return unless index
@edge_nodes.delete(index)
end
def inspect
format "#<%<class>s:%<id>#018x @key=%<key>s @cost=%<cost>s @edge_nodes=%<edge_nodes>s>",
class: self.class,
id: object_id << 1,
key: key.inspect,
cost: cost.inspect,
edge_nodes: edge_nodes.map { |n| n&.key }
end
end
def initialize(nodes: {})
@nodes = nodes
end
def node(key)
@nodes[key]
end
def node_at(x, y, z = 0)
key = format(Node::KEY_FORMAT, x, y, z)
@nodes[key]
end
def neighbors(node)
node.edge_nodes
end
end
end
end

View File

@@ -0,0 +1,6 @@
module CyberarmEngine
module Pathfinding
class GraphSearch
end
end
end

View File

@@ -0,0 +1,6 @@
module CyberarmEngine
module Pathfinding
class AStarSearch < GraphSearch
end
end
end

View File

@@ -0,0 +1,27 @@
module CyberarmEngine
module Pathfinding
class BreadthFirstSearch < GraphSearch
def self.search(graph:, start:, goal: nil)
frontier = []
came_from = {}
frontier.push(start)
came_from[start.key] = start
while(current = frontier.shift)
# early exit if we reach our goal
break if current == goal
graph.neighbors(current).each do |neighbor|
next if came_from[neighbor.key]
frontier.push(neighbor)
came_from[neighbor.key] = current
end
end
came_from
end
end
end
end

View File

@@ -0,0 +1,6 @@
module CyberarmEngine
module Pathfinding
class DijkstraSearch < GraphSearch
end
end
end

View File

@@ -0,0 +1,52 @@
module CyberarmEngine
module Pathfinding
class Grid < Graph
def add_node(x:, y:, z: 0, cost: 0, replace: false)
key = format(Node::KEY_FORMAT, x, y, z)
node = @nodes[key]
raise "Node at: #{key} already exists! (#{node})" if node && !replace
node = Node.new(x: x, y: y, z: z, cost: cost)
@nodes[key] = node
update_node_edge_nodes(node)
node
end
def remove_node(node)
update_node_edge_nodes(node, remove_node: true)
@nodes.delete(node.key)
end
def update_node_edge_nodes(node, remove_node: false)
x = node.x
y = node.y
z = node.z
# add node to neighbors
# 2D
left = @nodes[format(Node::KEY_FORMAT, x - 1, y, z)]
right = @nodes[format(Node::KEY_FORMAT, x + 1, y, z)]
top = @nodes[format(Node::KEY_FORMAT, x, y - 1, z)]
bottom = @nodes[format(Node::KEY_FORMAT, x, y + 1, z)]
# 3D
front = @nodes[format(Node::KEY_FORMAT, x, y, z - 1)]
back = @nodes[format(Node::KEY_FORMAT, x, y, z + 1)]
possible_edge_nodes = [left, right, top, bottom, front, back]
if remove_node
possible_edge_nodes.each { |n| n&.remove_edge_node(node) }
else
possible_edge_nodes.each { |n| n&.add_edge_node(node) }
end
end
def update_edge_nodes
@nodes.each { |k, n| update_node_edge_nodes(n) }
end
end
end
end

View File

@@ -46,7 +46,7 @@ module CyberarmEngine
end
def value=(bool)
old_value = this.value
old_value = self.value
@toggle_button.value = bool
publish(:changed, bool) if bool != old_value

View File

@@ -94,7 +94,7 @@ module CyberarmEngine
end
def value=(n)
old_value = this.value
old_value = self.value
@value = n
position_handle

View File

@@ -1,4 +1,4 @@
module CyberarmEngine
NAME = "InDev".freeze
VERSION = "0.25.1".freeze
VERSION = "0.30.0".freeze
end

View File

@@ -6,6 +6,9 @@ module CyberarmEngine
SAMPLES = {}
SONGS = {}
FixedUpdateProperties = Data.define(:fixed_timestep, :fixed_timestep_int_ms, :max_timestep)
FixedUpdate = Struct.new(:milliseconds, :accumulator, :interpolation, :alpha)
attr_accessor :show_cursor, :show_stats_plotter
attr_writer :exit_on_opengl_error
attr_reader :last_frame_time, :delta_time, :states
@@ -28,7 +31,7 @@ module CyberarmEngine
@@instance
end
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, fixed_update_timestep: 1.0 / 125, fixed_update_timestep_int_ms: 8, fixed_max_timestep: 1.0 / 60)
@show_cursor = false
@has_focus = false
@show_stats_plotter = false
@@ -46,6 +49,9 @@ module CyberarmEngine
preload_default_shaders if respond_to?(:preload_default_shaders)
@stats_plotter = Stats::StatsPlotter.new(2, 28) # FIXME: Make positioning easy
@fixed_timestep_data = FixedUpdateProperties.new(1.0 / 125, 8, 1.0 / 60)
@fixed_update = FixedUpdate.new(0, 0.0, 0.0, 1.0)
setup
end
@@ -79,11 +85,44 @@ module CyberarmEngine
Stats.frame.start_timing(:update)
current_state&.update
Stats.frame.start_timing(:fixed_update)
fixed_update
Stats.frame.end_timing(:fixed_update)
Stats.frame.end_timing(:update)
Stats.frame.start_timing(:interframe_sleep) unless needs_redraw?
end
def fixed_update
@delta_time = @fixed_timestep_data.max_timestep if @delta_time > @fixed_timestep_data.max_timestep
@fixed_update.accumulator += @delta_time
while @fixed_update.accumulator >= @fixed_timestep_data.fixed_timestep
@fixed_update.accumulator -= @fixed_timestep_data.fixed_timestep
@fixed_update.alpha = @fixed_update.accumulator / @fixed_timestep_data.fixed_timestep
@fixed_update.milliseconds += @fixed_timestep_data.fixed_timestep_int_ms
current_state&.fixed_update(@fixed_timestep_data.fixed_timestep)
end
end
def fixed_update_milliseconds
@fixed_update.milliseconds
end
def fixed_update_accumulator
@fixed_update.accumulator
end
def fixed_update_interpolation
@fixed_update.interpolation
end
def fixed_update_alpha
@fixed_update.alpha
end
def needs_cursor?
@show_cursor
end