Skip to content
Newer
Older
100644 200 lines (143 sloc) 5.56 KB
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
1 /*
2 Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version
7 3 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "main.h"
19
20 int main(int argc, char *argv[]) {
21
dacde63 @acaudwell Generalized the error/info/help message printing code.
authored Jan 29, 2010
22 SDLAppInit("Gource", "gource");
23
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
24 ConfFile conf;
25 std::vector<std::string> files;
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
26
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
27 //convert args to a conf file
28 //read the conf file
29 //apply the conf file to settings
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
30
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
31 try {
32 gGourceSettings.parseArgs(argc, argv, conf, &files);
e5b0ad0 @acaudwell Added save-config and load-config options.
authored Mar 22, 2010
33
a1ed095 @acaudwell Detect config files if filename ends with .conf, .cfg or .ini.
authored Jul 8, 2010
34 if(gGourceSettings.load_config.empty() && !files.empty()) {
35 //see if file looks like a config file
36 for(std::vector<std::string>::iterator fit = files.begin(); fit != files.end(); fit++) {
37 std::string file = *fit;
38
7924878 @acaudwell Fixed config file detection incorrectly matching short file names.
authored Nov 10, 2011
39 int file_length = file.size();
34e413a @acaudwell -WIDTHxHEIGHT! creates a non-resizable window.
authored Jan 28, 2012
40
7924878 @acaudwell Fixed config file detection incorrectly matching short file names.
authored Nov 9, 2011
41 if( file.rfind(".conf") == (file_length-5) && file_length > 5
42 || file.rfind(".cfg") == (file_length-4) && file_length > 4
43 || file.rfind(".ini") == (file_length-4) && file_length > 4) {
34e413a @acaudwell -WIDTHxHEIGHT! creates a non-resizable window.
authored Jan 28, 2012
44
a1ed095 @acaudwell Detect config files if filename ends with .conf, .cfg or .ini.
authored Jul 8, 2010
45 bool is_conf=true;
46
47 try {
48 ConfFile conftest;
49 conftest.load(file);
50 } catch(ConfFileException& exception) {
51 is_conf = false;
52 }
53
54 if(is_conf) {
55 gGourceSettings.load_config = file;
56 files.erase(fit);
57 break;
58 }
59 }
60 }
61 }
92d5f62 @acaudwell Updated core.
authored May 21, 2012
62
613157e @acaudwell Added --log-level option. Removed new lines from debugLog() calls.
authored Jan 24, 2012
63 //set log level
92d5f62 @acaudwell Updated core.
authored May 21, 2012
64 Logger::getDefault()->setLevel(gGourceSettings.log_level);
613157e @acaudwell Added --log-level option. Removed new lines from debugLog() calls.
authored Jan 23, 2012
65
e5b0ad0 @acaudwell Added save-config and load-config options.
authored Mar 22, 2010
66 //load config
7705cb5 Efficiency improvements for Gource and some const correctness.
Jacob authored Jun 4, 2010
67 if(!gGourceSettings.load_config.empty()) {
e5b0ad0 @acaudwell Added save-config and load-config options.
authored Mar 22, 2010
68 conf.clear();
69 conf.load(gGourceSettings.load_config);
70
71 //apply args to loaded conf file
72 gGourceSettings.parseArgs(argc, argv, conf);
73 }
74
75 //set path
7705cb5 Efficiency improvements for Gource and some const correctness.
Jacob authored Jun 4, 2010
76 if(!files.empty()) {
e5b0ad0 @acaudwell Added save-config and load-config options.
authored Mar 22, 2010
77 std::string path = files[files.size()-1];
34e413a @acaudwell -WIDTHxHEIGHT! creates a non-resizable window.
authored Jan 28, 2012
78
e5b0ad0 @acaudwell Added save-config and load-config options.
authored Mar 22, 2010
79 ConfSectionList* sectionlist = conf.getSections("gource");
80
81 if(sectionlist!=0) {
82 for(ConfSectionList::iterator sit = sectionlist->begin(); sit != sectionlist->end(); sit++) {
83 (*sit)->setEntry("path", path);
84 }
85 } else {
86 conf.setEntry("gource", "path", path);
87 }
88 }
89
5156be3 @acaudwell Implemented --logo and --background-image options.
authored Mar 23, 2010
90 //apply the config / see if its valid
0273ef5 @acaudwell Method to export the current display settings.
authored Mar 25, 2010
91 gGourceSettings.importDisplaySettings(conf);
92 gGourceSettings.importGourceSettings(conf);
5156be3 @acaudwell Implemented --logo and --background-image options.
authored Mar 22, 2010
93
e5b0ad0 @acaudwell Added save-config and load-config options.
authored Mar 22, 2010
94 //save config
7705cb5 Efficiency improvements for Gource and some const correctness.
Jacob authored Jun 4, 2010
95 if(!gGourceSettings.save_config.empty()) {
e5b0ad0 @acaudwell Added save-config and load-config options.
authored Mar 22, 2010
96 conf.save(gGourceSettings.save_config);
97 exit(0);
98 }
e57f583 @acaudwell Using VBOs and shaders to speed up rendering performance (when availa…
authored Apr 17, 2011
99
7046c49 @acaudwell Added a bunch of new options:
authored Oct 15, 2010
100 //write custom log file
101 if(gGourceSettings.output_custom_filename.size() > 0 && gGourceSettings.path.size() > 0) {
102
103 Gource::writeCustomLog(gGourceSettings.path, gGourceSettings.output_custom_filename);
e57f583 @acaudwell Using VBOs and shaders to speed up rendering performance (when availa…
authored Apr 17, 2011
104 exit(0);
7046c49 @acaudwell Added a bunch of new options:
authored Oct 15, 2010
105 }
e5b0ad0 @acaudwell Added save-config and load-config options.
authored Mar 22, 2010
106
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
107 } catch(ConfFileException& exception) {
924452d @acaudwell Support 3 options for video framerate 25,30,60.
authored Oct 15, 2009
108
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
109 SDLAppQuit(exception.what());
110 }
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
111
112 // this causes corruption on some video drivers
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
113 if(gGourceSettings.multisample) {
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
114 display.multiSample(4);
115 }
116
5434ed1 @acaudwell Added basic screenshot taking and background alpha channel support fo…
authored Mar 21, 2010
117 //background needs alpha channel
ad2fa86 @acaudwell Added --transparent to make the background see-through (for screensho…
authored Mar 30, 2010
118 if(gGourceSettings.transparent) {
5434ed1 @acaudwell Added basic screenshot taking and background alpha channel support fo…
authored Mar 21, 2010
119 display.enableAlpha(true);
120 }
121
7857f6f @acaudwell Improved performance of PPM exporter by reducing disk IO.
authored Jan 9, 2010
122 //enable vsync
5f20ec3 @acaudwell Added --no-vsync option.
authored Apr 19, 2011
123 display.enableVsync(gGourceSettings.vsync);
34e413a @acaudwell -WIDTHxHEIGHT! creates a non-resizable window.
authored Jan 28, 2012
124
ae78f2a @acaudwell Disable fullscreen toggle and window resize if exporting video.
authored Jan 9, 2012
125 //allow resizing window if we are not recording
34e413a @acaudwell -WIDTHxHEIGHT! creates a non-resizable window.
authored Jan 28, 2012
126 if(gGourceSettings.resizable && gGourceSettings.output_ppm_filename.empty()) {
ae78f2a @acaudwell Disable fullscreen toggle and window resize if exporting video.
authored Jan 9, 2012
127 display.enableResize(true);
128 }
2f49144 @acaudwell Ensure 'gource' never points to a deleted reference.
authored Apr 12, 2012
129
2d690fb @acaudwell Added more exceptions.
authored Jan 28, 2010
130 try {
131
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
132 display.init("Gource", gGourceSettings.display_width, gGourceSettings.display_height, gGourceSettings.fullscreen);
2d690fb @acaudwell Added more exceptions.
authored Jan 28, 2010
133
134 } catch(SDLInitException& exception) {
135
136 char errormsg[1024];
137 snprintf(errormsg, 1024, "SDL initialization failed - %s", exception.what());
138
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
139 SDLAppQuit(errormsg);
2d690fb @acaudwell Added more exceptions.
authored Jan 28, 2010
140 }
7857f6f @acaudwell Improved performance of PPM exporter by reducing disk IO.
authored Jan 9, 2010
141
ef2a62a @acaudwell Attach Gource to console for output if ENV has TERM=msys.
authored Apr 9, 2012
142 #ifdef _WIN32
143 SDLAppAttachToConsole();
144 #endif
145
275b675 @acaudwell More idiomatic use of FrameExporter object.
authored Oct 14, 2009
146 //init frame exporter
4bad0ec @acaudwell Removed direct FFmpeg support.
authored Oct 20, 2009
147 FrameExporter* exporter = 0;
148
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
149 if(gGourceSettings.output_ppm_filename.size() > 0) {
e84972a @acaudwell Gource will stop at the end of the log by default when recording a vi…
authored Jan 28, 2010
150
2d690fb @acaudwell Added more exceptions.
authored Jan 28, 2010
151 try {
152
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
153 exporter = new PPMExporter(gGourceSettings.output_ppm_filename);
2d690fb @acaudwell Added more exceptions.
authored Jan 28, 2010
154
155 } catch(PPMExporterException& exception) {
156
157 char errormsg[1024];
158 snprintf(errormsg, 1024, "could not write to '%s'", exception.what());
159
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
160 SDLAppQuit(errormsg);
2d690fb @acaudwell Added more exceptions.
authored Jan 28, 2010
161 }
275b675 @acaudwell More idiomatic use of FrameExporter object.
authored Oct 13, 2009
162 }
34896ba @acaudwell Document video recording options. Added bitrate
authored Oct 12, 2009
163
1baa0d6 @acaudwell Recover from video mode failing to set due to multi-sampling (Siddhes…
authored Dec 8, 2010
164 if(display.multiSamplingEnabled()) {
165 glEnable(GL_MULTISAMPLE_ARB);
166 }
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
167
dfc3efe @acaudwell Renamed GourceDemo GourceShell, Gource always run inside GourceShell.
authored May 8, 2010
168 GourceShell* gourcesh = 0;
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
169
73ca016 @acaudwell Throw exceptions instead of exiting.
authored Jan 14, 2010
170 try {
2f49144 @acaudwell Ensure 'gource' never points to a deleted reference.
authored Apr 12, 2012
171 gourcesh = gGourceShell = new GourceShell(&conf, exporter);
dfc3efe @acaudwell Renamed GourceDemo GourceShell, Gource always run inside GourceShell.
authored May 8, 2010
172 gourcesh->run();
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
173
73ca016 @acaudwell Throw exceptions instead of exiting.
authored Jan 14, 2010
174 } catch(ResourceException& exception) {
175
176 char errormsg[1024];
2d690fb @acaudwell Added more exceptions.
authored Jan 28, 2010
177 snprintf(errormsg, 1024, "failed to load resource '%s'", exception.what());
73ca016 @acaudwell Throw exceptions instead of exiting.
authored Jan 14, 2010
178
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
179 SDLAppQuit(errormsg);
73ca016 @acaudwell Throw exceptions instead of exiting.
authored Jan 14, 2010
180
dacde63 @acaudwell Generalized the error/info/help message printing code.
authored Jan 28, 2010
181 } catch(SDLAppException& exception) {
73ca016 @acaudwell Throw exceptions instead of exiting.
authored Jan 14, 2010
182
183 if(exception.showHelp()) {
c8cae8b @acaudwell Made help() a method on GourceSettings.
authored Mar 25, 2010
184 gGourceSettings.help();
73ca016 @acaudwell Throw exceptions instead of exiting.
authored Jan 14, 2010
185 } else {
d3f0545 @acaudwell Work in progress adding config file support to Gource.
authored Mar 19, 2010
186 SDLAppQuit(exception.what());
73ca016 @acaudwell Throw exceptions instead of exiting.
authored Jan 14, 2010
187 }
188 }
2f49144 @acaudwell Ensure 'gource' never points to a deleted reference.
authored Apr 12, 2012
189
190 gGourceShell = 0;
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
191
dfc3efe @acaudwell Renamed GourceDemo GourceShell, Gource always run inside GourceShell.
authored May 8, 2010
192 if(gourcesh != 0) delete gourcesh;
9e783f3 @acaudwell Set stop_at_end in getNext() rather than in main.cpp, as it gets lost.
authored Jul 6, 2010
193 if(exporter != 0) delete exporter;
275b675 @acaudwell More idiomatic use of FrameExporter object.
authored Oct 13, 2009
194
a96ec4d @acaudwell Initial revision of Gource.
authored Sep 11, 2009
195 //free resources
196 display.quit();
197
198 return 0;
199 }
Something went wrong with that request. Please try again.