Class: InteractiveTerm::VirtualScreen
- Inherits:
-
Object
- Object
- InteractiveTerm::VirtualScreen
- Defined in:
- lib/interactive_term.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#sprites ⇒ Object
readonly
Returns the value of attribute sprites.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #add_sprite(sprite) ⇒ Object
- #cleanup ⇒ Object
- #draw(char, x, y) ⇒ Object
-
#initialize(width, height) ⇒ VirtualScreen
constructor
A new instance of VirtualScreen.
- #update! ⇒ Object
Constructor Details
#initialize(width, height) ⇒ VirtualScreen
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/interactive_term.rb', line 155 def initialize(width, height) @width = width @height = height @sprites = [] @draw_mutex = Mutex.new @screen_buffer = ScreenBuffer.new(@width, @height) end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
153 154 155 |
# File 'lib/interactive_term.rb', line 153 def height @height end |
#sprites ⇒ Object (readonly)
Returns the value of attribute sprites.
153 154 155 |
# File 'lib/interactive_term.rb', line 153 def sprites @sprites end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
153 154 155 |
# File 'lib/interactive_term.rb', line 153 def width @width end |
Instance Method Details
#add_sprite(sprite) ⇒ Object
166 167 168 169 170 |
# File 'lib/interactive_term.rb', line 166 def add_sprite(sprite) # might want to simply give sprite a reference to screen sprite.set_screen_dimensions(@width, @height) @sprites << sprite end |
#cleanup ⇒ Object
186 187 188 189 |
# File 'lib/interactive_term.rb', line 186 def cleanup @draw_mutex.unlock if @draw_mutex.locked? #TODO: might want to do a full clean up of screen here end |
#draw(char, x, y) ⇒ Object
180 181 182 183 184 |
# File 'lib/interactive_term.rb', line 180 def draw(char, x, y) @draw_mutex.synchronize do print "\e[#{y+1};#{x+1}H#{char}" end end |
#update! ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/interactive_term.rb', line 172 def update! new_buffer = ScreenBuffer.new(@width, @height) new_buffer.render(sprites) deltas = @screen_buffer.deltas(new_buffer) deltas.each {|d| draw(*d)} @screen_buffer = new_buffer end |