chingu 0.9rc2 → 0.9rc3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -16,8 +16,6 @@ begin
16
16
  gemspec.version = Chingu::VERSION
17
17
 
18
18
  gemspec.add_dependency 'gosu', '>= 0.7.27.1'
19
- gemspec.add_dependency 'rest-client'
20
- gemspec.add_dependency 'crack'
21
19
  gemspec.add_development_dependency 'rspec', '>= 2.1.0'
22
20
  gemspec.add_development_dependency 'watchr'
23
21
  gemspec.add_development_dependency 'rcov'
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chingu}
8
- s.version = "0.9rc2"
8
+ s.version = "0.9rc3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ippa"]
@@ -270,23 +270,17 @@ Gem::Specification.new do |s|
270
270
 
271
271
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
272
272
  s.add_runtime_dependency(%q<gosu>, [">= 0.7.27.1"])
273
- s.add_runtime_dependency(%q<rest-client>, [">= 0"])
274
- s.add_runtime_dependency(%q<crack>, [">= 0"])
275
273
  s.add_development_dependency(%q<rspec>, [">= 2.1.0"])
276
274
  s.add_development_dependency(%q<watchr>, [">= 0"])
277
275
  s.add_development_dependency(%q<rcov>, [">= 0"])
278
276
  else
279
277
  s.add_dependency(%q<gosu>, [">= 0.7.27.1"])
280
- s.add_dependency(%q<rest-client>, [">= 0"])
281
- s.add_dependency(%q<crack>, [">= 0"])
282
278
  s.add_dependency(%q<rspec>, [">= 2.1.0"])
283
279
  s.add_dependency(%q<watchr>, [">= 0"])
284
280
  s.add_dependency(%q<rcov>, [">= 0"])
285
281
  end
286
282
  else
287
283
  s.add_dependency(%q<gosu>, [">= 0.7.27.1"])
288
- s.add_dependency(%q<rest-client>, [">= 0"])
289
- s.add_dependency(%q<crack>, [">= 0"])
290
284
  s.add_dependency(%q<rspec>, [">= 2.1.0"])
291
285
  s.add_dependency(%q<watchr>, [">= 0"])
292
286
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -25,9 +25,8 @@ ROOT = File.dirname(File.expand_path($0))
25
25
  require 'rubygems' unless RUBY_VERSION =~ /1\.9/
26
26
  require 'gosu'
27
27
  require 'yaml'
28
- require 'rest_client'
29
- require 'crack/xml'
30
-
28
+ require 'timeout'
29
+ require 'socket'
31
30
  require File.join(CHINGU_ROOT,"chingu","require_all") # Thanks to http://github.com/tarcieri/require_all !
32
31
 
33
32
  # Seems like we need to include chingu/helpers first for BasicGameObject
@@ -39,7 +38,7 @@ require_all "#{CHINGU_ROOT}/chingu/async_tasks"
39
38
  require_all "#{CHINGU_ROOT}/chingu"
40
39
 
41
40
  module Chingu
42
- VERSION = "0.9rc2"
41
+ VERSION = "0.9rc3"
43
42
 
44
43
  DEBUG_COLOR = Gosu::Color.new(0xFFFF0000)
45
44
  DEBUG_ZORDER = 9999
@@ -92,8 +92,8 @@ module Chingu
92
92
  # 3) #on_data(data) will call #on_msgs(msg)
93
93
  #
94
94
  def update
95
- super
96
95
  handle_incoming_data
96
+ super
97
97
  end
98
98
 
99
99
  #
@@ -80,6 +80,7 @@ module Chingu
80
80
  @socket = nil
81
81
  @sockets = []
82
82
  @buffered_output = YAML::Stream.new
83
+ @max_read_per_update = options[:max_read_per_update] || 20000
83
84
 
84
85
  @packet_counter = 0
85
86
  @packet_buffers = Hash.new
@@ -130,11 +131,13 @@ module Chingu
130
131
  # 5) send all buffered broadcast data in one fell swoop
131
132
  #
132
133
  def update
133
- super
134
134
  if @socket && !@socket.closed?
135
135
  handle_incoming_connections
136
136
  handle_incoming_data
137
+ super
137
138
  handle_outgoing_data
139
+ else
140
+ super
138
141
  end
139
142
  end
140
143
 
@@ -166,7 +169,7 @@ module Chingu
166
169
  # Call this from your update() to read from socket.
167
170
  # handle_incoming_data will call on_data(raw_data) when stuff comes on on the socket.
168
171
  #
169
- def handle_incoming_data(max_size = 1500)
172
+ def handle_incoming_data(max_size = @max_read_per_update)
170
173
  @sockets.each do |socket|
171
174
  if IO.select([socket], nil, nil, 0.0)
172
175
  begin
@@ -37,7 +37,7 @@ module Chingu
37
37
  @file = options[:file] || "high_score_list.yml"
38
38
  @size = options[:size] || 100
39
39
  @sort_on = options[:sort_on] || :score
40
- @high_scores = Array.new
40
+ @high_scores = Array.new
41
41
  end
42
42
 
43
43
  #
@@ -37,6 +37,17 @@ module Chingu
37
37
  @login = options[:login] || options[:user]
38
38
  @password = options[:password]
39
39
  @game_id = options[:game_id]
40
+
41
+ begin
42
+ require 'rest_client'
43
+ require 'crack/xml'
44
+ rescue
45
+ puts "HighScoreList requires 2 gems, please install with:"
46
+ puts "gem install rest-client"
47
+ puts "gem install crack"
48
+ exit
49
+ end
50
+
40
51
  @resource = RestClient::Resource.new("http://api.gamercv.com/games/#{@game_id}/high_scores",
41
52
  :user => @login, :password => @password, :timeout => 20, :open_timeout => 5)
42
53
 
@@ -1,30 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
+ def data_set
4
+ {
5
+ "a Hash" => [{ :foo => :bar }],
6
+ "a String" => ["Woof!"],
7
+ "an Array" => [[1, 2, 3]],
8
+ "a stream of packets" => [{ :foo => :bar }, "Woof!", [1, 2, 3]],
9
+ "huge packet" => [[:frogspawn] * 1000]
10
+ }
11
+ end
12
+
3
13
  module Chingu
4
14
  describe "Network" do
5
15
 
6
- describe "Network Server" do
7
-
16
+ describe Chingu::GameStates::NetworkServer do
8
17
  it "should open listening port on start()" do
9
- @server = Chingu::GameStates::NetworkServer.new(:ip => "0.0.0.0", :port => 9999)
18
+ @server = described_class.new(:ip => "0.0.0.0", :port => 9999)
10
19
  @server.should_receive(:on_start)
11
20
  @server.start
12
21
  @server.stop
13
22
  end
14
23
 
15
24
  it "should call on_start_error() if failing" do
16
- @server = Chingu::GameStates::NetworkServer.new(:ip => "1.2.3.999", :port => 12345678) # crazy ip:port
25
+ @server = described_class.new(:ip => "1.2.3.999", :port => 12345678) # crazy ip:port
17
26
  @server.should_receive(:on_start_error)
18
27
  @server.start
19
28
  @server.stop
20
29
  end
21
30
 
22
31
  it "should call on_connect() and on_disconnect() when client connects" do
23
- @server = Chingu::GameStates::NetworkServer.new(:ip => "0.0.0.0", :port => 9999)
32
+ @server = described_class.new(:ip => "0.0.0.0", :port => 9999)
24
33
  @client = Chingu::GameStates::NetworkClient.new(:ip => "127.0.0.1", :port => 9999)
25
34
 
26
35
  @server.should_receive(:on_start)
27
- @server.should_receive(:on_connect).with(anything()) # anything() == a socket
36
+ @server.should_receive(:on_connect).with(an_instance_of(TCPSocket))
28
37
  @client.should_receive(:on_connect)
29
38
  @server.start
30
39
  @client.connect
@@ -36,43 +45,69 @@ module Chingu
36
45
 
37
46
  end
38
47
 
39
- describe "Network Client" do
48
+ describe Chingu::GameStates::NetworkClient do
40
49
  it "should call on_connection_refused callback when connecting to closed port" do
41
- @client = Chingu::GameStates::NetworkClient.new(:ip => "127.0.0.1", :port => 55421) # closed we assume
50
+ @client = described_class.new(:ip => "127.0.0.1", :port => 55421) # closed we assume
42
51
  @client.should_receive(:on_connection_refused)
43
52
  @client.connect
44
53
  end
45
54
  end
46
55
 
47
56
  describe "Network communication" do
48
- before do
49
- @server = Chingu::GameStates::NetworkServer.new(:ip => "0.0.0.0", :port => 9999).start
57
+ before :each do
58
+ @server = Chingu::GameStates::NetworkServer.new(:port => 9999).start
50
59
  @client = Chingu::GameStates::NetworkClient.new(:ip => "127.0.0.1", :port => 9999).connect
60
+ @client2 = Chingu::GameStates::NetworkClient.new(:ip => "127.0.0.1", :port => 9999).connect
51
61
  end
52
62
 
53
- after do
63
+ after :each do
54
64
  @server.close
55
65
  @client.close
66
+ @client2.close
56
67
  end
57
-
58
- it "should send/recv strings" do
59
- @server.should_receive(:on_msg).with(anything(), "woff!")
60
- @client.send_msg("woff!")
61
- @server.update
62
- end
63
-
64
- it "should send/recv hashes" do
65
- @server.should_receive(:on_msg).with(anything(), {:foo => :bar})
66
- @client.send_msg({:foo => :bar})
67
- @server.update
68
+
69
+ describe "From client to server" do
70
+ data_set.each do |name, data|
71
+ it "should send/recv #{name}" do
72
+ data.each {|packet| @server.should_receive(:on_msg).with(an_instance_of(TCPSocket), packet) }
73
+ data.each {|packet| @client.send_msg(packet) }
74
+
75
+ @server.update
76
+ end
77
+ end
68
78
  end
69
79
 
70
- it "should send/recv arrays" do
71
- @server.should_receive(:on_msg).with(anything(), [1,2,3])
72
- @client.send_msg([1,2,3])
73
- @server.update
80
+ describe "From server to a specific client" do
81
+ data_set.each do |name, data|
82
+ it "should send/recv #{name}" do
83
+ data.each {|packet| @client.should_receive(:on_msg).with(packet) }
84
+ @server.update # Accept the client before sending, so we know of its socket.
85
+ data.each { |packet| @server.send_msg(@server.sockets[0], packet) }
86
+
87
+ @client.update
88
+ end
89
+ end
74
90
  end
75
91
 
92
+ describe "From server to all clients" do
93
+ data_set.each do |name, data|
94
+ it "should send/recv #{name}" do
95
+ @server.update # Accept the clients, so know about their existence to broadcast.
96
+
97
+ # Data should be cached.
98
+ data.each {|packet| @server.broadcast_msg(packet) }
99
+
100
+ data.each do |packet|
101
+ @client.should_receive(:on_msg).with(packet)
102
+ @client2.should_receive(:on_msg).with(packet)
103
+ end
104
+
105
+ @server.update # Push the cached messages.
106
+ @client.update
107
+ @client2.update
108
+ end
109
+ end
110
+ end
76
111
  end
77
112
  end
78
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chingu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9rc2
4
+ version: 0.9rc3
5
5
  prerelease: 3
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gosu
17
- requirement: &24735936 !ruby/object:Gem::Requirement
17
+ requirement: &24030588 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,32 +22,10 @@ dependencies:
22
22
  version: 0.7.27.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *24735936
26
- - !ruby/object:Gem::Dependency
27
- name: rest-client
28
- requirement: &24735504 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: *24735504
37
- - !ruby/object:Gem::Dependency
38
- name: crack
39
- requirement: &24735072 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
45
- type: :runtime
46
- prerelease: false
47
- version_requirements: *24735072
25
+ version_requirements: *24030588
48
26
  - !ruby/object:Gem::Dependency
49
27
  name: rspec
50
- requirement: &24734628 !ruby/object:Gem::Requirement
28
+ requirement: &24030108 !ruby/object:Gem::Requirement
51
29
  none: false
52
30
  requirements:
53
31
  - - ! '>='
@@ -55,10 +33,10 @@ dependencies:
55
33
  version: 2.1.0
56
34
  type: :development
57
35
  prerelease: false
58
- version_requirements: *24734628
36
+ version_requirements: *24030108
59
37
  - !ruby/object:Gem::Dependency
60
38
  name: watchr
61
- requirement: &24734268 !ruby/object:Gem::Requirement
39
+ requirement: &24029616 !ruby/object:Gem::Requirement
62
40
  none: false
63
41
  requirements:
64
42
  - - ! '>='
@@ -66,10 +44,10 @@ dependencies:
66
44
  version: '0'
67
45
  type: :development
68
46
  prerelease: false
69
- version_requirements: *24734268
47
+ version_requirements: *24029616
70
48
  - !ruby/object:Gem::Dependency
71
49
  name: rcov
72
- requirement: &24733848 !ruby/object:Gem::Requirement
50
+ requirement: &24029220 !ruby/object:Gem::Requirement
73
51
  none: false
74
52
  requirements:
75
53
  - - ! '>='
@@ -77,7 +55,7 @@ dependencies:
77
55
  version: '0'
78
56
  type: :development
79
57
  prerelease: false
80
- version_requirements: *24733848
58
+ version_requirements: *24029220
81
59
  description: OpenGL accelerated 2D game framework for Ruby. Builds on Gosu (Ruby/C++)
82
60
  which provides all the core functionality. Chingu adds simple yet powerful game
83
61
  states, prettier input handling, deployment safe asset-handling, a basic re-usable