Various stability + it segfaults now :3
This commit is contained in:
parent
5cea5b1487
commit
a51ba73710
1 changed files with 93 additions and 11 deletions
102
main.rb
102
main.rb
|
|
@ -1,4 +1,5 @@
|
|||
require 'gosu'
|
||||
require 'securerandom'
|
||||
|
||||
puts "Hexagonal Terminal Emulator"
|
||||
puts "---------------------------"
|
||||
|
|
@ -117,6 +118,38 @@ class HexEditXref_BgGrphStore
|
|||
) unless @hex_bgs.has_key? argb
|
||||
return @hex_bgs[argb]
|
||||
end
|
||||
# Debug methods
|
||||
def debug_get_refs(color)
|
||||
raise TypeError, ("color must be a Gosu::Color, not a '#{color.class}'"
|
||||
) unless color.is_a? Gosu::Color
|
||||
argb = color.argb
|
||||
return nil unless @hex_refs.has_key? argb
|
||||
return Set.new(@hex_refs[argb])
|
||||
end
|
||||
def debug_get_argb_for_id(hexid)
|
||||
return nil unless @hex_ids.has_key? hexid
|
||||
return @hex_ids[hexid]
|
||||
end
|
||||
def debug_get_bg_for_id(hexid)
|
||||
return nil unless @hex_ids.has_key? hexid
|
||||
argb = @hex_ids[hexid]
|
||||
return nil unless @hex_bgs.has_key? argb
|
||||
return @hex_bgs[argb]
|
||||
end
|
||||
def debug_get_bg_for_color(color)
|
||||
raise TypeError, ("color must be a Gosu::Color, not a '#{color.class}'"
|
||||
) unless color.is_a? Gosu::Color
|
||||
argb = color.argb
|
||||
return nil unless @hex_bgs.has_key? argb
|
||||
return @hex_bgs[argb]
|
||||
end
|
||||
def debug_get_stats
|
||||
return {
|
||||
'b' => @hex_bgs.size,
|
||||
'i' => @hex_ids.size,
|
||||
'r' => @hex_refs.size,
|
||||
}
|
||||
end
|
||||
private
|
||||
def render(argb)
|
||||
color = Gosu::Color.new(argb)
|
||||
|
|
@ -143,14 +176,14 @@ end
|
|||
class TextProps
|
||||
attr_accessor \
|
||||
:font, :bg_color, :fg_color,
|
||||
:hex_border_color,
|
||||
:hex_border_colors,
|
||||
:bold, :italic, :underline, :overline, :strikethrough
|
||||
def initialize(font, text_props=nil)
|
||||
if text_props != nil
|
||||
@font = font
|
||||
@fg_color = text_props.fg_color
|
||||
@bg_color = text_props.bg_color
|
||||
@hex_border_color = text_props.hex_border_color
|
||||
@hex_border_colors = text_props.hex_border_colors
|
||||
@bold = text_props.bold
|
||||
@italic = text_props.italic
|
||||
@underline = text_props.underline
|
||||
|
|
@ -161,7 +194,10 @@ class TextProps
|
|||
@font = font
|
||||
@fg_color = $fg_color
|
||||
@bg_color = $bg_color
|
||||
@hex_border_color = $hex_color
|
||||
@hex_border_colors = [
|
||||
$hex_color, $hex_color,
|
||||
$hex_color, $hex_color,
|
||||
$hex_color, $hex_color]
|
||||
@bold = false
|
||||
@italic = false
|
||||
@underline = false
|
||||
|
|
@ -178,14 +214,48 @@ class Hex
|
|||
@y = y
|
||||
@char = char
|
||||
@text_props = text_props
|
||||
@hexid = SecureRandom.uuid
|
||||
@dead = false
|
||||
end
|
||||
|
||||
def draw
|
||||
|
||||
amidead?
|
||||
$hex_bgs.register(@hexid, @text_props.bg_color)
|
||||
$hex_bgs[@text_props.bg_color].draw(
|
||||
@x, @y, 0, 1, 1, Gosu::Color::WHITE
|
||||
) # layer 0: hex-bg
|
||||
for i1 in 0..5
|
||||
i2 = (i1+1)%6
|
||||
x1=$hex_points[i1][0]+@x; y1=$hex_points[i1][1]+@y
|
||||
x2=$hex_points[i2][0]+@x; y2=$hex_points[i2][1]+@y
|
||||
Gosu::draw_line(
|
||||
x1, y1, @text_props.hex_border_colors[i1],
|
||||
x2, y2, @text_props.hex_border_colors[i1],
|
||||
1
|
||||
) # layer 1: hex-border
|
||||
end
|
||||
@text_props.font.draw_text(
|
||||
@char, @x, @y+$hex_tip,
|
||||
2, 1.0, 1.0, @text_props.fg_color
|
||||
) # layer 2: hex-text
|
||||
end
|
||||
|
||||
def cleanup!
|
||||
$hex_bgs.unregister @hexid
|
||||
@dead = true
|
||||
end
|
||||
|
||||
private
|
||||
def amidead?
|
||||
if @dead
|
||||
raise StandardError, (
|
||||
"Hexagon #{@hexid} at (#{@x}, #{@y}) has been "+
|
||||
"cleaned up, and should not have been called '"+
|
||||
"draw' on."
|
||||
)
|
||||
@text_props.font.draw_text(@char, @x, @y+$hex_tip, 2, 1.0, 1.0, @text_props.fg_color)
|
||||
return true # technically unreachable, but here for clarity
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -238,12 +308,15 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
end
|
||||
|
||||
def needs_redraw?
|
||||
# Quads are expensive; Avoid redrawing.
|
||||
return @do_redraw
|
||||
end
|
||||
|
||||
def update
|
||||
$hex_bgs.clean
|
||||
hbgdb = $hex_bgs.debug_get_stats
|
||||
puts "ids: #{hbgdb['i']}"
|
||||
puts "ref: #{hbgdb['r']}"
|
||||
puts "bgs: #{hbgdb['b']}"
|
||||
|
||||
if @output_buffer.length > 0
|
||||
render_output
|
||||
@do_redraw = true
|
||||
|
|
@ -322,17 +395,26 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
end
|
||||
|
||||
def scroll_with_new_line
|
||||
@active_styling.hex_border_color =\
|
||||
Gosu::Color.new(rand(255), rand(255), rand(255))
|
||||
@active_styling.hex_border_colors = [
|
||||
Gosu::Color::WHITE,
|
||||
Gosu::Color::WHITE,
|
||||
Gosu::Color::WHITE,
|
||||
Gosu::Color::WHITE,
|
||||
Gosu::Color::WHITE,
|
||||
Gosu::Color::WHITE
|
||||
]
|
||||
@hexes.each do |rex|
|
||||
rex.each do |hex|
|
||||
hex.y -= $hex_y_offset
|
||||
end
|
||||
end
|
||||
for hex in @hexes[0]
|
||||
hex.cleanup!
|
||||
end
|
||||
@hexes = @hexes[1..-1]
|
||||
@hexes << []
|
||||
for i in 0..@xexes-1
|
||||
@active_styling.bg_color = Gosu::Color.new(rand(255), rand(255), rand(255))
|
||||
@active_styling.bg_color = Gosu::Color::BLACK
|
||||
@hexes[-1] << Hex.new(
|
||||
(i*$hex_width) + (@next_row_is_shifted? $hex_x_offset : 0),
|
||||
(@yexes-1)*$hex_y_offset,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue