Class: Chingu::GameStates::NetworkState

Inherits:
Chingu::GameState show all
Defined in:
lib/chingu/game_states/network_state.rb

Overview

Abstract state, parent of NetworkClient and NetworkServer.

Direct Known Subclasses

NetworkClient, NetworkServer

Defined Under Namespace

Classes: PacketBuffer

Constant Summary

PACKET_HEADER_LENGTH =
4
PACKET_HEADER_FORMAT =
"N"
DEFAULT_PORT =
7778

Instance Attribute Summary collapse

Attributes inherited from Chingu::GameState

#game_objects, #game_state_manager, #options, #previous_game_state

Attributes included from Helpers::InputDispatcher

#input_clients

Attributes included from Helpers::GameObject

#game_objects

Instance Method Summary collapse

Methods inherited from Chingu::GameState

#button_down, #button_up, #close, #close_game, #draw, #draw_trait, #filename, #setup, #setup_trait, #to_s, #to_sym, trait, #trait_options, traits, #update, #update_trait

Methods included from Helpers::ClassInheritableAccessor

included

Methods included from Helpers::InputClient

#add_inputs, #holding?, #holding_all?, #holding_any?, #input, #input=, #on_input

Methods included from Helpers::InputDispatcher

#add_input_client, #dispatch_button_down, #dispatch_button_up, #dispatch_input_for, #remove_input_client

Methods included from Helpers::GameObject

#game_objects_of_class, #load_game_objects, #save_game_objects

Methods included from Helpers::GFX

#draw_arc, #draw_circle, #draw_rect, #fill, #fill_arc, #fill_circle, #fill_gradient, #fill_rect

Constructor Details

#initialize(options = {}) ⇒ NetworkState

Returns a new instance of NetworkState



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chingu/game_states/network_state.rb', line 51

def initialize(options = {})
  raise "Can't instantiate abstract class" if self.class == NetworkState

  super(options)

  reset_counters

  @address = options[:address] || "0.0.0.0"
  @port = options[:port] || DEFAULT_PORT
  @debug = options[:debug]
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address



47
48
49
# File 'lib/chingu/game_states/network_state.rb', line 47

def address
  @address
end

#bytes_receivedObject (readonly)

Returns the value of attribute bytes_received



48
49
50
# File 'lib/chingu/game_states/network_state.rb', line 48

def bytes_received
  @bytes_received
end

#bytes_sentObject (readonly)

Returns the value of attribute bytes_sent



48
49
50
# File 'lib/chingu/game_states/network_state.rb', line 48

def bytes_sent
  @bytes_sent
end

#packets_receivedObject (readonly)

Returns the value of attribute packets_received



49
50
51
# File 'lib/chingu/game_states/network_state.rb', line 49

def packets_received
  @packets_received
end

#packets_sentObject (readonly)

Returns the value of attribute packets_sent



49
50
51
# File 'lib/chingu/game_states/network_state.rb', line 49

def packets_sent
  @packets_sent
end

#portObject (readonly)

Returns the value of attribute port



47
48
49
# File 'lib/chingu/game_states/network_state.rb', line 47

def port
  @port
end

Instance Method Details

#reset_countersObject

Resets #bytes_sent, #bytes_received, #packets_sent and #packets_received to zero.



64
65
66
67
68
# File 'lib/chingu/game_states/network_state.rb', line 64

def reset_counters
  @bytes_sent = @bytes_received = 0
  @packets_sent = @packets_received = 0
  0
end