Class: RuGUI::BaseMainController

Inherits:
BaseController show all
Defined in:
lib/rugui/base_controller.rb,
lib/rugui/framework_adapters/Rubygame.rb

Overview

A base class for main controllers.

Provides a method for running the application as well as a method to quit.

Direct Known Subclasses

MainController

Instance Attribute Summary collapse

Attributes inherited from BaseController

#controllers, #main_models, #models, #parent_controller, #views

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseController

controllers, #main_controller, main_models, models, #post_registration, #register_controller, #register_main_model, #register_model, #register_view, views

Methods included from InitializeHooks

included, #initialize_with_hooks, update_initialize_method

Methods included from EntityRegistrationSupport

included

Methods included from SignalSupport

#autoconnect_declared_signals, included

Methods included from LogSupport

included, #logger

Methods included from PropertyObserver

included, #named_observable_property_updated, #property_updated

Methods included from FrameworkAdapters::FrameworkAdapterSupport

#framework_adapter_for, included, #load_framework_adapter

Methods inherited from BaseObject

#inspect

Constructor Details

#initializeBaseMainController

Returns a new instance of BaseMainController.



73
74
75
76
77
78
79
80
81
82
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 73

def initialize
  super

  setup_clock
  setup_event_queue
  setup_screen
  setup_quit_events
  setup_autoload_resources
  setup_main_view_screen
end

Instance Attribute Details

#screenObject

Returns the value of attribute screen.



71
72
73
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 71

def screen
  @screen
end

Class Method Details

.framerate(frames_per_second = nil) ⇒ Object



111
112
113
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 111

def framerate(frames_per_second=nil)
  @framerate ||= frames_per_second || 30
end

.ignored_events(*args) ⇒ Object



105
106
107
108
109
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 105

def ignored_events(*args)
  @ignored_events ||= []
  @ignored_events += args unless args.empty?
  @ignored_events
end

.quit_hooks(quit_hooks = nil) ⇒ Object



135
136
137
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 135

def quit_hooks(quit_hooks=nil)
  @quit_hooks ||= quit_hooks || [:escape, :q, Rubygame::Events::QuitRequested]
end

.screen_depth(depth = nil) ⇒ Object



123
124
125
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 123

def screen_depth(depth=nil)
  @screen_depth ||= depth || 0
end

.screen_flags(flags = nil) ⇒ Object



127
128
129
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 127

def screen_flags(flags=nil)
  @screen_flags ||= flags || [Rubygame::HWSURFACE, Rubygame::DOUBLEBUF]
end

.screen_height(height = nil) ⇒ Object



119
120
121
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 119

def screen_height(height=nil)
  @screen_height ||= height || 480
end

.screen_title(title = nil) ⇒ Object



131
132
133
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 131

def screen_title(title=nil)
  @screen_title ||= title || "RuGUI Game!"
end

.screen_width(width = nil) ⇒ Object



115
116
117
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 115

def screen_width(width=nil)
  @screen_width ||= width || 640
end

Instance Method Details

#clockObject



96
97
98
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 96

def clock
  @clock ||= Rubygame::Clock.new
end

#event_queueObject



100
101
102
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 100

def event_queue
  @event_queue ||= Rubygame::EventQueue.new
end

#framework_adapterObject

Returns the framework_adapter for this class.



222
223
224
# File 'lib/rugui/base_controller.rb', line 222

def framework_adapter
  framework_adapter_for('BaseMainController')
end

#quitObject

Exits from the application.



247
248
249
250
251
# File 'lib/rugui/base_controller.rb', line 247

def quit
  logger.info "Exiting the application through #{self.class.name}."
  self.framework_adapter.quit
  logger.info "Application finished."
end

#refreshObject

Refreshes the GUI application, running just one event loop.

This method is mostly useful when writing tests. It shouldn’t be used in normal applications.



240
241
242
# File 'lib/rugui/base_controller.rb', line 240

def refresh
  self.framework_adapter.refresh
end

#runObject

Runs the application.



229
230
231
232
# File 'lib/rugui/base_controller.rb', line 229

def run
  logger.info "Starting the application through #{self.class.name}."
  self.framework_adapter.run
end

#stepObject



84
85
86
87
88
89
90
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 84

def step
  clear_screen
  tick
  handle_events
  update
  screen.update
end

#tickObject



92
93
94
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 92

def tick
  event_queue << clock.tick
end