~ian-mcintosh/luz/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env ruby

 ###############################################################################
 #  Copyright 2011 Ian McIntosh <ian@openanswers.org>
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
 #  the Free Software Foundation; either version 2 of the License, or
 #  (at your option) any later version.
 #
 #  This program is distributed in the hope that it will be useful,
 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #  GNU Library General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
 #  along with this program; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 ###############################################################################

Dir.chdir(File.dirname(__FILE__))	# So that this file can be run from anywhere
$LOAD_PATH << './utils'
$LOAD_PATH << './user-object-settings'
$LOAD_PATH << './gui'
$LOAD_PATH << './engine'

###################################################################
# Constants
###################################################################
APP_NAME			= 'Luz Studio'
APP_COPYRIGHT	= "Copyright (c) #{Time.now.year} Ian McIntosh"
APP_VERSION		= 0.91

DEFAULT_GTK_RC_FILE = 'luz.rc'

require 'reloadable_require'		# NOTE: also adds the ability to require multiple files at once
require 'addons_ruby', 'method_piping', 'boolean_accessor'

# Application basics
require 'constants', 'application', 'settings'
require 'gtk2', 'gtkglext', 'builder'

# Extensions to GUI related objects
load_directory(Dir.pwd + '/utils/addons/', '**.rb')

require 'addons_gl'

class LuzEditor < Application
	def initialize
		super

		GC.disable

		Gtk.init
		Gtk::RC.parse(DEFAULT_GTK_RC_FILE)
		Gtk::GL.init

		require 'error_window'
		@error_window = ErrorWindow.new

		require 'engine'
		$engine = Engine.new
		$engine.post_initialize

		require 'gui'
		$gui = GUI.new
		$gui.create_treeview_models
		$gui.create_windows		# Remove this, create windows separately

		$engine.load_plugins
		$engine.add_default_objects

		$engine.on_user_object_exception { |obj,e| on_user_object_exception(obj,e) }

		@frames_per_second = $settings['editor-fps']
		@animating = true

		GC.enable
	end

	def end_animation
		@animating = false
	end

	#
	# application-level exception handling
	#
	def on_user_object_exception(object, exception)
		puts sprintf(Engine::USER_OBJECT_EXCEPTION_FORMAT, exception.report_format, "#{object.class}:#{object.title}")
	end

	def handle_exception(e)
		# Report in GUI
		@error_window.show_with_message(e.report_format)

		# Report in control terminal
		e.report("exception requiring user notification")

		# Stop processing frames, etc., just remain with a basic GUI
		end_animation
		$engine.crash_notify
	end

	empty_method :get_framebuffer_rgb
end

require 'optparse'

options = {}
OptionParser.new do |opts|
	opts.banner = "Usage: luz_editor.rb [project.luz]"
end.parse!

project = ARGV.last

settings_path = File.join(Dir.home, SETTINGS_DIRECTORY, SETTINGS_FILENAME)
$settings = Settings.new.load(settings_path)
$application = LuzEditor.new
$engine.load_from_path(project) if (project and File.extname(project) == '.luz')
$application.run
$settings.save(settings_path)