shattered_ruby 0.5.0.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/game_loader.rb +138 -103
- data/lib/rails_generator/generators/applications/shattered_app/shattered_app_generator.rb +1 -0
- data/lib/rails_generator/generators/components/state/templates/state.rb +8 -27
- data/lib/tasks/framework.rake +1 -2
- data/lib/templates/configs/ogre_plugins.mac.cfg +12 -0
- data/lib/templates/environments/environment.rb +7 -0
- metadata +3 -2
data/lib/game_loader.rb
CHANGED
@@ -5,114 +5,149 @@ include ShatteredView
|
|
5
5
|
include ShatteredModel
|
6
6
|
|
7
7
|
module Shatter #:nodoc:all
|
8
|
-
#This class is loads the view, controller, and model. It then loads
|
9
|
-
#and starts the game based on these.
|
10
|
-
class GameLoader
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
#This class is loads the view, controller, and model. It then loads
|
9
|
+
#and starts the game based on these.
|
10
|
+
class GameLoader
|
11
|
+
include Singleton
|
12
|
+
attr_writer :environment
|
13
|
+
attr_reader :media_paths, :input_manager, :key_manager, :key_converter
|
14
|
+
attr_accessor :current_state, :render_window
|
15
|
+
|
16
|
+
# This will recourse into the app/** directories and load all ruby files
|
17
|
+
# inside those directories.
|
18
|
+
def load_all_sources(shattered_root)
|
19
|
+
File.find_by_extension(shattered_root+"/app", "rb").each do |file|
|
20
|
+
require(file)
|
21
|
+
end
|
21
22
|
end
|
22
|
-
|
23
|
+
|
24
|
+
# start the game
|
25
|
+
def run
|
26
|
+
load_all_sources(SHATTERED_ROOT)
|
27
|
+
load_environment
|
28
|
+
|
29
|
+
# Create our initial state, as defined by the environment.
|
30
|
+
create_state(@environment[:start_state])
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
load_all_sources(SHATTERED_ROOT)
|
27
|
-
load_environment
|
28
|
-
|
29
|
-
# Create our initial state, as defined by the environment.
|
30
|
-
create_state(@environment[:start_state])
|
31
|
-
|
32
|
-
start_game
|
33
|
-
end
|
34
|
-
|
35
|
-
# Create a state from the given name
|
36
|
-
# :sample creates a new SampleState object
|
37
|
-
def create_state(state_name)
|
38
|
-
state_class = eval("#{state_name.to_s.camelize}State")
|
39
|
-
raise Error, "#{state_class} is not a class" unless state_class.is_a? Class
|
40
|
-
state = state_class.new
|
41
|
-
unless state.is_a? ShatteredState::Base
|
42
|
-
raise Error, "#{state_class} is an invalid State object (not of ShatteredState::Base)"
|
43
|
-
end
|
44
|
-
return state
|
45
|
-
end
|
46
|
-
|
47
|
-
def load_environment
|
48
|
-
#Setup Ogre and the scene for the state
|
49
|
-
raise Error, "Ogre failed to initialize" if !setup_ogre
|
50
|
-
setup_input
|
51
|
-
|
52
|
-
load_resources(@environment[:media])
|
53
|
-
end
|
54
|
-
|
55
|
-
# Given ['app/media', 'media'], searches those directories, recursively, for OGRE media
|
56
|
-
def load_resources(paths)
|
57
|
-
@media_paths = paths
|
58
|
-
# setup our resource paths specified in environment.rb
|
59
|
-
Resources.instance.add_resource_paths(*paths)
|
60
|
-
Resources.instance.setup
|
61
|
-
end
|
62
|
-
|
63
|
-
#Load the root, setup the render window
|
64
|
-
#TODO: allow for the user to specify whether the window dialogue pops up
|
65
|
-
#further TODO: allow the user to skin the render window dialogue
|
66
|
-
def setup_ogre
|
67
|
-
# TODO: create platform loader for other platforms
|
68
|
-
plugins = SHATTERED_ROOT + "/config/ogre_plugins.windows.cfg"
|
69
|
-
config_save=SHATTERED_ROOT + "/config/ogrerb_defaults.save"
|
70
|
-
log=SHATTERED_ROOT + "/log/ogrerb.log"
|
71
|
-
@root = ShatteredOgre.create_root(plugins, config_save, log)
|
72
|
-
return false if !@root.show_config_dialog
|
73
|
-
# TODO: allow application name to be set.
|
74
|
-
@render_window = @root.initialise(true)
|
32
|
+
start_game
|
33
|
+
end
|
75
34
|
|
76
|
-
|
77
|
-
|
35
|
+
# Create a state from the given name
|
36
|
+
# :sample creates a new SampleState object
|
37
|
+
def create_state(state_name)
|
38
|
+
state_class = eval("#{state_name.to_s.camelize}State")
|
39
|
+
raise Error, "#{state_class} is not a class" unless state_class.is_a? Class
|
40
|
+
state = state_class.new
|
41
|
+
unless state.is_a? ShatteredState::Base
|
42
|
+
raise Error, "#{state_class} is an invalid State object (not of ShatteredState::Base)"
|
43
|
+
end
|
44
|
+
return state
|
45
|
+
end
|
46
|
+
|
47
|
+
def load_environment
|
48
|
+
#Setup Ogre and the scene for the state
|
49
|
+
raise Error, "Ogre failed to initialize" if !setup_ogre
|
50
|
+
setup_input
|
51
|
+
|
52
|
+
load_resources(@environment[:media])
|
53
|
+
end
|
78
54
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
55
|
+
# Given ['app/media', 'media'], searches those directories, recursively, for OGRE media
|
56
|
+
def load_resources(paths)
|
57
|
+
@media_paths = paths
|
58
|
+
# setup our resource paths specified in environment.rb
|
59
|
+
Resources.instance.add_resource_paths(*paths)
|
60
|
+
Resources.instance.setup
|
61
|
+
end
|
62
|
+
|
63
|
+
#Load the root, setup the render window
|
64
|
+
#TODO: allow for the user to specify whether the window dialogue pops up
|
65
|
+
#further TODO: allow the user to skin the render window dialogue
|
66
|
+
def setup_ogre
|
67
|
+
# TODO: create platform loader for other platforms
|
68
|
+
plugins = SHATTERED_ROOT + "/config/ogre_plugins.windows.cfg"
|
69
|
+
config_save=SHATTERED_ROOT + "/config/ogrerb_defaults.save"
|
70
|
+
log=SHATTERED_ROOT + "/log/ogrerb.log"
|
71
|
+
@root = ShatteredOgre.create_root(plugins, config_save, log)
|
72
|
+
return false if !@root.show_config_dialog
|
73
|
+
# TODO: allow application name to be set.
|
74
|
+
@render_window = @root.initialise(true)
|
75
|
+
|
76
|
+
return true
|
77
|
+
end
|
78
|
+
|
79
|
+
#Every time this exits, a game dies.
|
80
|
+
def start_game
|
81
|
+
each_frame do |time_elapsed|
|
82
|
+
Ogre::WindowEventUtilities::message_pump
|
83
|
+
current_state.update_timers(time_elapsed)
|
84
|
+
@key_manager.flush
|
85
|
+
@keyboard.capture
|
86
|
+
end
|
87
|
+
shutdown!
|
85
88
|
end
|
89
|
+
|
90
|
+
# Main game loop
|
91
|
+
def each_frame
|
92
|
+
timer = Ogre::Timer.new
|
93
|
+
while !@environment[:quit] && Ogre::Root::instance.render_one_frame
|
94
|
+
return false if @render_window.closed?
|
95
|
+
seconds = timer.get_microseconds / 1000000.0
|
96
|
+
timer.reset
|
97
|
+
yield seconds
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Shutdown Ogre / OIS / Navi
|
102
|
+
def shutdown!
|
103
|
+
#@input_manager.destroy_input_object(@mouse)
|
104
|
+
@input_manager.destroy_input_object(@keyboard)
|
105
|
+
#@input_manager.destroy_input_object(@joy_stick)
|
106
|
+
|
107
|
+
OIS::InputManager.destroy_input_system(@input_manager)
|
108
|
+
|
109
|
+
#NEED TO UNREGISTER THE WINDOW LISTENER HERE!!!!!!!!!!!!
|
110
|
+
|
111
|
+
@input_manager = nil
|
112
|
+
end
|
113
|
+
|
114
|
+
# Leave the game
|
115
|
+
def quit!
|
116
|
+
@environment[:quit]=true
|
117
|
+
end
|
118
|
+
|
119
|
+
# load the input manager, the key manager, etc
|
120
|
+
# TODO: Investigate any use cases for non-buffered input
|
121
|
+
def setup_input
|
122
|
+
setup_window
|
123
|
+
@input_manager = OIS::InputManager.create_input_system(@environment[:window])
|
124
|
+
setup_keyboard
|
125
|
+
end
|
126
|
+
|
127
|
+
# Creates our window and our window event listener.
|
128
|
+
def setup_window
|
129
|
+
windowHnd = render_window.get_custom_attribute_unsigned_long("WINDOW")
|
130
|
+
@environment[:window]["WINDOW"] = windowHnd.to_s
|
131
|
+
#@window_listener = WindowEventsListener.new(@render_window)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Sets up our keyboard object in buffered mode.
|
135
|
+
def setup_keyboard
|
136
|
+
@keyboard = @input_manager.create_input_object(OIS::OISKeyboard, true)
|
137
|
+
@key_manager = OIS::KeyManager.new(@keyboard)
|
138
|
+
@key_converter = ShatteredPack::KeyConverter.new(@key_manager)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Handle window events - closed and resized
|
143
|
+
# TODO: This class belongs elsewhere...
|
144
|
+
class WindowEventsListener < Ogre::WindowEventListenerProxy
|
145
|
+
def window_resized(rw)
|
146
|
+
# GameLoader.instance.resize(rw)
|
147
|
+
end
|
148
|
+
def window_closed(rw)
|
149
|
+
GameLoader.instance.current_state.quit
|
150
|
+
end
|
86
151
|
end
|
87
152
|
|
88
|
-
# Main game loop
|
89
|
-
def each_frame
|
90
|
-
timer = Ogre::Timer.new
|
91
|
-
while !@environment[:quit] && Ogre::Root::instance.render_one_frame
|
92
|
-
seconds = timer.get_microseconds / 1000000.0
|
93
|
-
yield seconds
|
94
|
-
timer.reset
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Leave the game
|
99
|
-
def quit!
|
100
|
-
@environment[:quit]=true
|
101
|
-
end
|
102
|
-
|
103
|
-
# load the input manager, the key manager, etc
|
104
|
-
# TODO: Consider how to make input non-exclusive, as well as mouse, etc.
|
105
|
-
# TODO: Investigate any use cases for non-buffered input
|
106
|
-
def setup_input
|
107
|
-
windowHnd = render_window.get_custom_attribute_unsigned_long("WINDOW")
|
108
|
-
@input_manager = OIS::InputManager.create_input_system(
|
109
|
-
{ "WINDOW" => "#{windowHnd}",
|
110
|
-
"w32_mouse" => ["DISCL_FOREGROUND", "DISCL_NONEXCLUSIVE"],
|
111
|
-
"w32_keyboard" => ["DISCL_FOREGROUND", "DISCL_NONEXCLUSIVE"]
|
112
|
-
})
|
113
|
-
@keyboard = @input_manager.create_input_object(OIS::OISKeyboard, true)
|
114
|
-
@key_manager = OIS::KeyManager.new(@keyboard)
|
115
|
-
@key_converter = ShatteredPack::KeyConverter.new(@key_manager)
|
116
|
-
end
|
117
|
-
end
|
118
153
|
end
|
@@ -27,6 +27,7 @@ class ShatteredAppGenerator < Rails::Generator::Base #:nodoc:all
|
|
27
27
|
|
28
28
|
# ogre plugins and configuration
|
29
29
|
m.file "templates/configs/ogre_plugins.windows.cfg", "config/ogre_plugins.windows.cfg"
|
30
|
+
m.file "templates/configs/ogre_plugins.mac.cfg", "config/ogre_plugins.mac.cfg"
|
30
31
|
m.template "templates/configs/ogre.cfg", "config/ogre.cfg"
|
31
32
|
m.template "templates/configs/boot.rb", "config/boot.rb"
|
32
33
|
|
@@ -1,31 +1,12 @@
|
|
1
1
|
class <%= class_name %>State < ShatteredState::Base
|
2
|
-
|
3
|
-
|
2
|
+
scene_manager :general
|
3
|
+
camera :position => :z*300, :look_at => :zero
|
4
|
+
viewport :color => rgb(0.2, 0.2, 0.2)
|
5
|
+
|
6
|
+
key :pressed => :escape, :action => :quit
|
7
|
+
|
4
8
|
def initialize
|
5
|
-
|
6
|
-
# :general, :terrain, :nature, :paging, :indoor
|
7
|
-
@scene_manager = create_scene_manager :general
|
8
|
-
|
9
|
-
setup_camera
|
10
|
-
setup_viewport
|
9
|
+
# Create scene and actors
|
11
10
|
end
|
12
|
-
|
13
|
-
# Cameras are the renderers of the world.
|
14
|
-
# Scene managers can have many cameras - for example, in a first person racing game you could have
|
15
|
-
# a camera facing forward, and a camera facing backwards, rendering to the rear view window.
|
16
|
-
def setup_camera
|
17
|
-
@camera = scene_manager.create_camera("camera")
|
18
|
-
@camera.set_near_clip_distance 1
|
19
|
-
@camera.set_far_clip_distance 10000
|
20
|
-
@camera.position = v(0,0,-10)
|
21
|
-
@camera.look_at v(0,0,0)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Viewports are your windows into the world.
|
25
|
-
# Cameras can have many viewports, but usually the relationship is 1-1.
|
26
|
-
def setup_viewport
|
27
|
-
@viewport = create_viewport(@camera)
|
28
|
-
@viewport.set_background_colour Ogre::ColourValue.new(0.2, 0.2, 0.2)
|
29
|
-
end
|
30
|
-
|
11
|
+
|
31
12
|
end
|
data/lib/tasks/framework.rake
CHANGED
@@ -26,8 +26,7 @@ namespace :shattered do
|
|
26
26
|
end
|
27
27
|
mv(Dir.glob("shattered_ruby").first, "shatter")
|
28
28
|
end
|
29
|
-
end
|
30
|
-
|
29
|
+
end
|
31
30
|
desc "Lock to latest Shattered Edge or a specific revision with REVISION=X (ex: REVISION=4021) or a tag with TAG=Y (ex: TAG=rel_1-1-0)"
|
32
31
|
task :edge do
|
33
32
|
$verbose = false
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Defines plugins to load
|
2
|
+
|
3
|
+
# Define plugin folder, not needed for mac
|
4
|
+
#PluginFolder=.
|
5
|
+
|
6
|
+
# Define D3D rendering implementation plugin
|
7
|
+
Plugin=RenderSystem_GL
|
8
|
+
Plugin=Plugin_ParticleFX
|
9
|
+
Plugin=Plugin_BSPSceneManager
|
10
|
+
Plugin=Plugin_OctreeSceneManager
|
11
|
+
#Plugin=Plugin_CgProgramManager
|
12
|
+
|
@@ -7,4 +7,11 @@ game[:start_state] = :main_menu
|
|
7
7
|
|
8
8
|
game[:media] = ["app/media"]
|
9
9
|
|
10
|
+
# Here you can setup how you would like the window to act.
|
11
|
+
# DISCL_NONEXCLUSIVE means the mouse and keyboard are not bound to your program.
|
12
|
+
game[:window] = {
|
13
|
+
"w32_mouse" => ["DISCL_FOREGROUND", "DISCL_NONEXCLUSIVE"],
|
14
|
+
"w32_keyboard" => ["DISCL_FOREGROUND", "DISCL_NONEXCLUSIVE"]
|
15
|
+
}
|
16
|
+
|
10
17
|
Shatter::GameLoader.instance.environment=game
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: shattered_ruby
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.5.1
|
7
|
+
date: 2007-08-20 00:00:00 -06:00
|
8
8
|
summary: "Shattered: The main package tieing together controller, view, and model"
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/templates/configs/boot.rb
|
95
95
|
- lib/templates/configs/empty.log
|
96
96
|
- lib/templates/configs/ogre.cfg
|
97
|
+
- lib/templates/configs/ogre_plugins.mac.cfg
|
97
98
|
- lib/templates/configs/ogre_plugins.windows.cfg
|
98
99
|
- lib/templates/configs/runner.rb
|
99
100
|
- lib/templates/doc
|