Imported vanilla contents from upstream
[construo.git] / construo_main.cxx
blob444b62ea5c188178047206d145cbc87fa5136ef6
1 // $Id: construo_main.cxx,v 1.27 2003/07/28 10:24:00 grumbel Exp $
2 //
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <fstream>
21 #include "construo.hxx"
22 #include "particle.hxx"
23 #include "config.h"
24 #include "world.hxx"
25 #include "path_manager.hxx"
26 #include "construo_error.hxx"
28 #if defined(USE_X11_DISPLAY)
29 # include "x11_display.hxx"
30 # include "unix_system.hxx"
31 #elif defined(USE_GLUT_DISPLAY)
32 # include "glut_display.hxx"
33 # include "unix_system.hxx"
34 #else
35 # error "No Display target defined!"
36 #endif
38 #include "controller.hxx"
39 #include "command_line.hxx"
40 #include "settings.hxx"
41 #include "gui_manager.hxx"
43 #include "construo_main.hxx"
45 ConstruoMain* construo_main;
46 Controller* controller;
48 ConstruoMain::ConstruoMain ()
49 : do_quit(false),
50 gui_manager(0)
54 ConstruoMain::~ConstruoMain ()
58 char*
59 ConstruoMain::get_title ()
61 return "Construo " VERSION;
64 void
65 ConstruoMain::exit()
67 on_exit();
68 delete gui_manager;
69 deinit_system();
70 ::exit(EXIT_SUCCESS);
73 void
74 ConstruoMain::on_exit()
76 std::cout << "Calling on_exit()" << std::endl;
78 //if (!controller->has_been_run())
80 controller->save_world("/user/laststate.construo");
83 std::cout << "\n\n Thank you for playing Construo!\n\n\n"
84 << " New versions and more information can be found at:\n\n"
85 << " * http://fs.fsf.org/construo/\n\n"
86 << " Comments, critique, suggestions self build\n construction and patches can be send to:\n\n"
87 << " * Ingo Ruhnke <grumbel@gmx.de>\n\n" << std::endl;
90 void
91 ConstruoMain::init_system()
93 std::cout << "ConstruoMain::init_system()" << std::endl;
94 system = new UnixSystem();
95 #ifdef USE_X11_DISPLAY
96 display = new X11Display(settings.screen_width, settings.screen_height,
97 settings.fullscreen);
98 #elif USE_GLUT_DISPLAY
99 display = new GlutDisplay(settings.screen_width, settings.screen_height, settings.fullscreen);
100 #else
101 # error "No display type defined"
102 #endif
104 // Init the display, input systems
105 graphic_context = display;
106 input_context = display;
107 system_context = system;
110 void
111 ConstruoMain::deinit_system()
113 std::cout << "ConstruoMain::deinit_system()" << std::endl;
114 delete display;
115 delete system;
118 int
119 ConstruoMain::main (int argc, char* argv[]) // FIXME: pass an option class, instead command line arguments
121 CommandLine::parse(argc, argv);
123 try {
124 // Init the System
125 init_system();
127 std::cout << PACKAGE_STRING"\n" << std::endl;
128 std::cout << "If you have throuble with programm startup, delete the file:\n\n"
129 << " " << system_context->get_construo_rc_path() << "laststate.construo\n" << std::endl;
131 if (!settings.datadir.empty())
132 path_manager.add_path(settings.datadir);
134 path_manager.add_path(".");
135 path_manager.add_path("..");
136 path_manager.add_path(CONSTRUO_DATADIR);
137 if (!path_manager.find_path("examples/"))
139 std::cout << "Couldn't find Construo Datadir, use '--datadir DIR' to set it manually." << std::endl;
140 ::exit(EXIT_FAILURE);
143 gui_manager = new GUIManager ();
145 if (!settings.startup_file.empty())
147 controller = new Controller (settings.startup_file);
149 else
151 try
153 controller = new Controller ("/user/laststate.construo");
155 catch (ConstruoError& err)
157 std::cout << "ConstruoMain: " << err.msg << std::endl;
158 controller = new Controller ();
162 // For some targets this will never return
163 display->run();
165 // Shutdown the system and exit
166 exit();
167 } catch (ConstruoError& err) {
168 std::cout << "Error ocurred: " << err.msg << std::endl;
169 return EXIT_FAILURE;
172 return 0;
175 ////////////////////////
176 // Real Main Function //
177 ////////////////////////
178 int main (int argc, char** argv)
180 ConstruoMain app;
181 construo_main = &app;
182 return app.main (argc, argv);
185 /* EOF */