Class: GBRb::Graphics::ScreenClient

Inherits:
Object
  • Object
show all
Defined in:
lib/gbrb/graphics/screen_client.rb

Instance Method Summary collapse

Constructor Details

#initializeScreenClient

Returns a new instance of ScreenClient.



8
9
10
11
12
13
14
# File 'lib/gbrb/graphics/screen_client.rb', line 8

def initialize
  trap(:PIPE) { exit }
  @connection = UNIXSocket.new SOCKET_PATH
rescue Errno::ECONNREFUSED, Errno::ENOENT
  sleep 0.1
  retry
end

Instance Method Details

#format(data) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gbrb/graphics/screen_client.rb', line 20

def format data
  raise WrongPixelCount unless data.length == HEIGHT and data.first.length == WIDTH

  d = "P6 #{WIDTH} #{HEIGHT} #{MAX_COLOR} "
  data.each do |row|
    row.each do |pixel|
      d << PPM_PALETTE[pixel].chr * 3
    end
  end
  d << "\n"
end

#write(data) ⇒ Object



16
17
18
# File 'lib/gbrb/graphics/screen_client.rb', line 16

def write data
  @connection.write format data
end