pixelflut 0.0.10 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/TODO.md +1 -0
- data/bin/pxf-info +55 -0
- data/lib/pixelflut.rb +6 -6
- data/lib/pixelflut/app.rb +2 -2
- data/lib/pixelflut/canvas/base.rb +1 -3
- data/lib/pixelflut/client.rb +1 -1
- data/lib/pixelflut/client/socket.rb +48 -14
- data/lib/pixelflut/converter.rb +11 -4
- data/lib/pixelflut/server/connection.rb +1 -1
- data/lib/pixelflut/version.rb +1 -1
- data/pixelflut.gemspec +11 -7
- metadata +6 -6
- data/lib/pixelflut/canvas/color.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46bc6d8430a0a37a766f925558d1279fbf69457f859f9f6286c2fb4a3f3a9e81
|
4
|
+
data.tar.gz: f634ffe53ec48385c8c9b42f032f3fa0e56d91155cf075a05b2b9c15794d8dbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53bb74856603e0d46563b707726cdb8d5d96f5192ebd641c00ebba463e45ba5165536f4b95ea60d28e0468f8735acb32d3439802541791faf9a2dcbe13b94dab
|
7
|
+
data.tar.gz: 2f26150a3d40045e6030018cbcbf807dcbb1f415f193f156d1c45d8c4eea5e5c6d56e5205d764b701b6d644346d0892042f5fb1cdd9ce0d9cd6ee5ba4fbad099
|
data/README.md
CHANGED
data/TODO.md
CHANGED
data/bin/pxf-info
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
def options(cfg)
|
5
|
+
require 'optparse'
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.summary_indent = ' '
|
8
|
+
opts.banner = 'usage: pxf info [options]'
|
9
|
+
opts.separator(nil)
|
10
|
+
opts.separator('valid options:')
|
11
|
+
opts.on('-h', '--host HOST', String, 'target host name (default localhost)'){ |v| cfg[:host] = v }
|
12
|
+
opts.on('-p', '--port PORT', Integer, 'target port (default 1234)'){ |v| cfg[:port] = v }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def help(short)
|
17
|
+
puts(options(nil), nil) unless short
|
18
|
+
puts('Get info about a Pixelflut server.')
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
|
22
|
+
def err(msg, code = 1)
|
23
|
+
$stderr.puts("pxf: #{msg}")
|
24
|
+
exit(code)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_options
|
28
|
+
{port: 1234}.tap{ |cfg| options(cfg).parse! }
|
29
|
+
rescue OptionParser::ParseError => e
|
30
|
+
err(e)
|
31
|
+
end
|
32
|
+
|
33
|
+
help(false) if '--help' == ARGV[0]
|
34
|
+
help(true) if '--short-help' == ARGV[0]
|
35
|
+
options = create_options
|
36
|
+
require File.realdirpath('../../lib/pixelflut/client/socket.rb', __FILE__)
|
37
|
+
begin
|
38
|
+
socket = Pixelflut::Client::Socket.new(Addrinfo.tcp(options[:host], options[:port]))
|
39
|
+
|
40
|
+
|
41
|
+
err("unable to connect - #{options[:host]}:options[:port])", 2) unless socket.connect? || socket.wait_writable(5)
|
42
|
+
err("server busy - #{options[:host]}:options[:port])", 3) unless socket.write_with_timout("SIZE\n", 5)
|
43
|
+
line = socket.readline_with_timeout(5)
|
44
|
+
socket.close
|
45
|
+
err("server does not respond - #{options[:host]}:options[:port])", 4) unless line
|
46
|
+
mark, width, height = line.split(' ', 3)
|
47
|
+
width = width.to_i
|
48
|
+
height = height.to_i
|
49
|
+
err("no Pixelflut server - #{options[:host]}:options[:port])", 5) if mark != 'SIZE' || width <= 0 || height <= 0
|
50
|
+
puts "canvas size: #{width}x#{height}"
|
51
|
+
rescue SocketError, SystemCallError => e
|
52
|
+
err(e.message, 2)
|
53
|
+
rescue Interrupt
|
54
|
+
exit
|
55
|
+
end
|
data/lib/pixelflut.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Pixelflut
|
2
|
-
|
3
|
-
autoload :App, File.join(
|
4
|
-
autoload :Server, File.join(
|
5
|
-
autoload :Canvas, File.join(
|
6
|
-
autoload :Converter, File.join(
|
7
|
-
autoload :VERSION, File.join(
|
2
|
+
LIB_DIR = File.realdirpath('../pixelflut', __FILE__).freeze
|
3
|
+
autoload :App, File.join(LIB_DIR, 'app.rb')
|
4
|
+
autoload :Server, File.join(LIB_DIR, 'server.rb')
|
5
|
+
autoload :Canvas, File.join(LIB_DIR, 'canvas.rb')
|
6
|
+
autoload :Converter, File.join(LIB_DIR, 'converter.rb')
|
7
|
+
autoload :VERSION, File.join(LIB_DIR, 'version.rb')
|
8
8
|
end
|
data/lib/pixelflut/app.rb
CHANGED
@@ -42,7 +42,7 @@ module Pixelflut
|
|
42
42
|
|
43
43
|
def update
|
44
44
|
# self.caption = @image.changes
|
45
|
-
@draw_image = nil unless
|
45
|
+
@draw_image = nil unless @image.changes.zero?
|
46
46
|
end
|
47
47
|
|
48
48
|
def draw
|
@@ -65,7 +65,7 @@ module Pixelflut
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def needs_redraw?
|
68
|
-
|
68
|
+
@draw_image.nil?
|
69
69
|
end
|
70
70
|
|
71
71
|
def needs_cursor?
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'color'
|
4
|
-
|
5
3
|
module Pixelflut
|
6
4
|
module Canvas
|
7
5
|
class Base
|
@@ -13,7 +11,7 @@ module Pixelflut
|
|
13
11
|
|
14
12
|
def clear!
|
15
13
|
@offset_x = @offset_y = 0
|
16
|
-
@color =
|
14
|
+
@color = 'ffffffff'
|
17
15
|
end
|
18
16
|
|
19
17
|
def translate(x, y)
|
data/lib/pixelflut/client.rb
CHANGED
@@ -5,15 +5,56 @@ require 'socket'
|
|
5
5
|
module Pixelflut
|
6
6
|
class Client
|
7
7
|
class Socket < ::Socket
|
8
|
+
def initialize(address)
|
9
|
+
super(address.ipv6? ? :INET6 : :INET, :STREAM)
|
10
|
+
@addr = ::Socket.pack_sockaddr_in(address.ip_port, address.ip_address)
|
11
|
+
configure
|
12
|
+
end
|
13
|
+
|
14
|
+
def write_with_timout(data, timeout)
|
15
|
+
return true if write_nonblock(data, exception: false) == data.bytesize
|
16
|
+
return false unless wait_writable(timeout)
|
17
|
+
write_nonblock(data, exception: false) == data.bytesize
|
18
|
+
end
|
19
|
+
|
20
|
+
def readline_with_timeout(timeout)
|
21
|
+
deadline = Time.now + timeout
|
22
|
+
ret = ''
|
23
|
+
loop do
|
24
|
+
got = read_nonblock(16, exception: false)
|
25
|
+
if got == :wait_readable
|
26
|
+
remaining_time = deadline - Time.now
|
27
|
+
return nil if remaining_time <= 0 || wait_readable(remaining_time).nil?
|
28
|
+
next
|
29
|
+
end
|
30
|
+
idx = got.index("\n")
|
31
|
+
next ret += got unless idx
|
32
|
+
return ret + got[0, idx]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def connect?
|
37
|
+
:wait_writable != connect_nonblock(@addr, exception: false)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def configure
|
43
|
+
self.sync = true
|
44
|
+
setsockopt(:TCP, :NODELAY, 1)
|
45
|
+
setsockopt(:SOCKET, :KEEPALIVE, 0)
|
46
|
+
self.do_not_reverse_lookup = true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class NonblockSocket < Socket
|
8
51
|
attr_reader :state
|
9
52
|
|
10
53
|
def initialize(address, data)
|
11
|
-
super(address
|
12
|
-
|
13
|
-
@addr = ::Socket.pack_sockaddr_in(address.ip_port, address.ip_address)
|
54
|
+
super(address)
|
55
|
+
@state = :not_connected
|
14
56
|
@data = data
|
15
57
|
@size = data.bytesize
|
16
|
-
@state = :not_connected
|
17
58
|
end
|
18
59
|
|
19
60
|
def call
|
@@ -33,27 +74,20 @@ module Pixelflut
|
|
33
74
|
private
|
34
75
|
|
35
76
|
def do_connect
|
36
|
-
@state =
|
77
|
+
@state = connect? ? :write : :wait_connect
|
37
78
|
end
|
38
79
|
|
39
80
|
def do_wait_for_connect
|
40
|
-
@state = :
|
81
|
+
@state = :not_connected unless wait_writable(0.1).nil?
|
41
82
|
end
|
42
83
|
|
43
84
|
def do_write
|
44
85
|
written = write_nonblock(@data, exception: false)
|
45
|
-
return if Symbol === written
|
86
|
+
return written if Symbol === written
|
46
87
|
@size -= written
|
47
88
|
return @state = :write_finished if @size <= 0
|
48
89
|
@data = @data.byteslice(written, @data.bytesize - written)
|
49
90
|
end
|
50
|
-
|
51
|
-
def configure
|
52
|
-
self.sync = true
|
53
|
-
setsockopt(:TCP, :NODELAY, 1)
|
54
|
-
setsockopt(:SOCKET, :KEEPALIVE, 0)
|
55
|
-
self.do_not_reverse_lookup = true
|
56
|
-
end
|
57
91
|
end
|
58
92
|
end
|
59
93
|
end
|
data/lib/pixelflut/converter.rb
CHANGED
@@ -22,14 +22,21 @@ module Pixelflut
|
|
22
22
|
def each_pixel
|
23
23
|
return to_enum(__method__) unless block_given?
|
24
24
|
@images.each do |image|
|
25
|
-
image.each_pixel
|
26
|
-
yield(x, y, color.to_color(Magick::AllCompliance, true, 8, true)[1, 8]) unless 0xffff == color.opacity
|
27
|
-
end
|
25
|
+
image.each_pixel{ |color, x, y| yield(x, y, color) }
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
29
|
+
def each_rgba_pixel
|
30
|
+
return to_enum(__method__) unless block_given?
|
31
|
+
each_pixel{ |x, y, color| yield(x, y, as_rgba(color)) unless 0xffff == color.opacity }
|
32
|
+
end
|
33
|
+
|
31
34
|
def draw(canvas)
|
32
|
-
|
35
|
+
each_rgba_pixel{ |x, y, rgba| canvas[x, y] = rgba }
|
36
|
+
end
|
37
|
+
|
38
|
+
def as_rgba(color)
|
39
|
+
color.to_color(Magick::AllCompliance, true, 8, true)[1, 8]
|
33
40
|
end
|
34
41
|
|
35
42
|
private
|
@@ -38,7 +38,7 @@ module Pixelflut
|
|
38
38
|
str = @socket.recv_nonblock(read_size, exception: false)
|
39
39
|
now = Time.now.to_f
|
40
40
|
return (now - @last_tm > @config.keep_alive_time ? close(:timeout) : nil) if Symbol === str
|
41
|
-
return close(:closed_by_peer) if
|
41
|
+
return close(:closed_by_peer) if str.size.zero?
|
42
42
|
@buffer += str
|
43
43
|
@last_tm = now
|
44
44
|
rescue Errno::ECONNRESET
|
data/lib/pixelflut/version.rb
CHANGED
data/pixelflut.gemspec
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'lib/pixelflut/version'
|
4
4
|
|
5
5
|
GemSpec = Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'pixelflut'
|
7
7
|
spec.version = Pixelflut::VERSION
|
8
|
-
spec.summary = 'A Pixelflut server written in Ruby.'
|
9
|
-
spec.description = <<~
|
8
|
+
spec.summary = 'A Pixelflut server & client tool collection written in Ruby.'
|
9
|
+
spec.description = <<~DESCRIPTION
|
10
10
|
Based on the idea of a simple server protocol to collaborate on a shared canvas named
|
11
11
|
[Pixel Flut](https://cccgoe.de/wiki/Pixelflut) this gem implements a Ruby version.
|
12
|
-
|
12
|
+
DESCRIPTION
|
13
13
|
spec.author = 'Mike Blumtritt'
|
14
14
|
spec.email = 'mike.blumtritt@invision.de'
|
15
15
|
spec.homepage = 'https://github.com/mblumtritt/pixelflut'
|
16
|
-
spec.metadata = {
|
16
|
+
spec.metadata = {
|
17
|
+
'issue_tracker' => 'https://github.com/mblumtritt/pixelflut/issues'
|
18
|
+
}
|
17
19
|
spec.rubyforge_project = spec.name
|
18
20
|
|
19
21
|
spec.add_runtime_dependency 'gosu', '>= 0.13.2'
|
@@ -26,12 +28,14 @@ GemSpec = Gem::Specification.new do |spec|
|
|
26
28
|
|
27
29
|
spec.require_paths = %w[lib]
|
28
30
|
spec.bindir = 'bin'
|
29
|
-
spec.executables =
|
31
|
+
spec.executables =
|
32
|
+
Dir
|
33
|
+
.glob(File.expand_path('../bin/*', __FILE__))
|
34
|
+
.map!{ |fn| File.basename(fn) }
|
30
35
|
|
31
36
|
all_files = %x(git ls-files -z).split(0.chr)
|
32
37
|
spec.test_files = all_files.grep(%r{^(spec|test)/})
|
33
38
|
spec.files = all_files - spec.test_files
|
34
39
|
|
35
|
-
spec.has_rdoc = false
|
36
40
|
spec.extra_rdoc_files = %w[README.md]
|
37
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixelflut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -64,6 +64,7 @@ executables:
|
|
64
64
|
- pxf-help
|
65
65
|
- pxf-send
|
66
66
|
- pxf-version
|
67
|
+
- pxf-info
|
67
68
|
extensions: []
|
68
69
|
extra_rdoc_files:
|
69
70
|
- README.md
|
@@ -75,6 +76,7 @@ files:
|
|
75
76
|
- bin/pxf-convert
|
76
77
|
- bin/pxf-generate
|
77
78
|
- bin/pxf-help
|
79
|
+
- bin/pxf-info
|
78
80
|
- bin/pxf-send
|
79
81
|
- bin/pxf-server
|
80
82
|
- bin/pxf-version
|
@@ -84,7 +86,6 @@ files:
|
|
84
86
|
- lib/pixelflut/canvas.rb
|
85
87
|
- lib/pixelflut/canvas/base.rb
|
86
88
|
- lib/pixelflut/canvas/buffered.rb
|
87
|
-
- lib/pixelflut/canvas/color.rb
|
88
89
|
- lib/pixelflut/canvas/streamed.rb
|
89
90
|
- lib/pixelflut/client.rb
|
90
91
|
- lib/pixelflut/client/socket.rb
|
@@ -115,9 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
- !ruby/object:Gem::Version
|
116
117
|
version: 1.3.6
|
117
118
|
requirements: []
|
118
|
-
|
119
|
-
rubygems_version: 2.7.3
|
119
|
+
rubygems_version: 3.0.1
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
|
-
summary: A Pixelflut server written in Ruby.
|
122
|
+
summary: A Pixelflut server & client tool collection written in Ruby.
|
123
123
|
test_files: []
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Pixelflut
|
2
|
-
module Canvas
|
3
|
-
class Base
|
4
|
-
module Color
|
5
|
-
class << self
|
6
|
-
def from_rgb(r, g, b)
|
7
|
-
from_rgba(r, g, b, 0xff)
|
8
|
-
end
|
9
|
-
|
10
|
-
def from_rgba(r, g, b, a)
|
11
|
-
as_hex(r) + as_hex(g) + as_hex(b) + as_hex(a)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def as_hex(int)
|
17
|
-
ret = int.to_s(16)
|
18
|
-
ret = '0' + ret if 1 == ret.size
|
19
|
-
ret
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
Black = from_rgba(0, 0, 0, 0xff)
|
24
|
-
White = from_rgba(0xff, 0xff, 0xff, 0xff)
|
25
|
-
Red = from_rgba(0xff, 0, 0, 0xff)
|
26
|
-
Green = from_rgba(0, 0xff, 0, 0xff)
|
27
|
-
Blue = from_rgba(0, 0, 0xff, 0xff)
|
28
|
-
Yellow = from_rgba(0xff, 0xff, 0, 0xff)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|