/[adonthell]/adonthell/src/main/adonthell.cc
ViewVC logotype

Diff of /adonthell/src/main/adonthell.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by ksterker, Mon Nov 15 08:54:33 2004 UTC revision 1.9 by ksterker, Tue Dec 7 16:46:27 2004 UTC
# Line 15  Line 15 
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
18     along with Adonthell; if not, write to the Free Software     along with Adonthell; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */  */
21    
# Line 23  Line 23 
23  /**  /**
24   * @file   main/adonthell.cc   * @file   main/adonthell.cc
25   * @author Kai Sterker <kaisterker@linuxgames.com>   * @author Kai Sterker <kaisterker@linuxgames.com>
26   *   *
27   * @brief  The main application class for programs using the Adonthell framework.   * @brief  The main application class for programs using the Adonthell framework.
28   */   */
29    
# Line 47  using std::endl; Line 47  using std::endl;
47    
48  /// The handler of our library file.  /// The handler of our library file.
49  static lt_dlhandle dlhandle = 0;  static lt_dlhandle dlhandle = 0;
50                
51  /// pointer to method with backend/platform specific intialization code.  /// pointer to method with backend/platform specific intialization code.
52  static bool (*init_p)(adonthell::app* application) = 0;  static bool (*init_p)(adonthell::app* application) = 0;
53    
# Line 58  app::~app () Line 58  app::~app ()
58      lt_dlexit ();      lt_dlexit ();
59  }  }
60    
61  // initialize engine subsystems  // initialize engine subsystems
62  bool app::init_modules (const u_int16 & modules)  bool app::init_modules (const u_int16 & modules)
63  {  {
64      // don't initialize previously loaded modules      // don't initialize previously loaded modules
65      u_int16 m = Modules ^ modules;      u_int16 m = Modules ^ modules;
66      Modules |= m;      Modules |= m;
67        
68      // startup python      // startup python
69      if (m & PYTHON)      if (m & PYTHON)
70      {      {
# Line 86  bool app::init_modules (const u_int16 & Line 86  bool app::init_modules (const u_int16 &
86      {      {
87          if (!gfx::init (Backend)) return false;          if (!gfx::init (Backend)) return false;
88      }      }
89        
90      // startup input      // startup input
91      if (m & INPUT)      if (m & INPUT)
92      {      {
93          if (!input::init (Backend)) return false;          if (!input::init (Backend)) return false;
94      }      }
95        
96      // startup event system      // startup event system
97      if (m & EVENT)      if (m & EVENT)
98      {      {
99          event::manager::init ();          events::manager::init ();
100      }      }
101        
102      return true;      return true;
103  }  }
104    
# Line 106  bool app::init_modules (const u_int16 & Line 106  bool app::init_modules (const u_int16 &
106  void app::parse_args (int & argc, char *argv[])  void app::parse_args (int & argc, char *argv[])
107  {  {
108      int c;      int c;
109        
110      Argc = argc;      Argc = argc;
111      Argv = argv;      Argv = argv;
112    
# Line 117  void app::parse_args (int & argc, char * Line 117  void app::parse_args (int & argc, char *
117    
118      // Check for options      // Check for options
119      while ((c = getopt (argc, argv, "b:c:g:hv")) != -1)      while ((c = getopt (argc, argv, "b:c:g:hv")) != -1)
120      {              {
121          switch (c)          switch (c)
122          {          {
123              // backend:              // backend:
124              case 'b':              case 'b':
125                  Backend = optarg;                  Backend = optarg;
# Line 146  void app::parse_args (int & argc, char * Line 146  void app::parse_args (int & argc, char *
146                  break;                  break;
147          }          }
148      }      }
149        
150      // check whether the GAME parameter is given      // check whether the GAME parameter is given
151      if (argc - optind == 1)      if (argc - optind == 1)
152      {      {
# Line 159  bool app::init () Line 159  bool app::init ()
159  {  {
160      Modules = 0;      Modules = 0;
161      dlhandle = NULL;      dlhandle = NULL;
162        
163      // init libltdl      // init libltdl
164      if (lt_dlinit ())      if (lt_dlinit ())
165      {      {
166          cerr << lt_dlerror() << endl;          cerr << lt_dlerror() << endl;
167          cerr << "Error initializing liblt!" << endl;          cerr << "Error initializing liblt!" << endl;
168          return false;          return false;
169      }      }
170    
171      // init base module (required for reading config file)      // init base module (required for reading config file)
172      base::init (Userdatadir, Game);      base::init (Userdatadir, Game);
173            
174      // load configuration file      // load configuration file
175      if (!Cfg.read (Config))      if (!Cfg.read (Config))
176      {      {
177          // print message if that fails, but don't panic yet ...          // print message if that fails, but don't panic yet ...
178          cerr << "Error reading configuration '" << Config << ".xml'" << endl;          cerr << "Error reading configuration '" << Config << ".xml'" << endl;
179      }      }
180        
181      // if we have been given no backend on the command line,      // if we have been given no backend on the command line,
182      // try to get it from config file; fallback to sdl if that fails      // try to get it from config file; fallback to sdl if that fails
183      if (Backend == "")      if (Backend == "")
184      {      {
# Line 186  bool app::init () Line 186  bool app::init ()
186          // set type of config option (free form text entry)          // set type of config option (free form text entry)
187          Cfg.option ("General", "Backend", base::cfg_option::FREE);          Cfg.option ("General", "Backend", base::cfg_option::FREE);
188      }      }
189        
190      // load backend init module      // load backend init module
191      dlhandle = base::get_module (string ("/main/") + Backend);      dlhandle = base::get_module (string ("/main/") + Backend);
192      if (!dlhandle)      if (!dlhandle)
# Line 194  bool app::init () Line 194  bool app::init ()
194          cerr << lt_dlerror() << endl;          cerr << lt_dlerror() << endl;
195          return false;          return false;
196      }      }
197        
198      // get pointer to init method      // get pointer to init method
199      init_p = (bool (*)(app*)) lt_dlsym (dlhandle, "main_init");      init_p = (bool (*)(app*)) lt_dlsym (dlhandle, "main_init");
200      if (!init_p)      if (!init_p)
# Line 202  bool app::init () Line 202  bool app::init ()
202          cerr << lt_dlerror() << endl;          cerr << lt_dlerror() << endl;
203          return false;          return false;
204      }      }
205        
206      // platform / backend specific initialization      // platform / backend specific initialization
207      return init_p (this);      return init_p (this);
208  }  }
# Line 214  void app::cleanup () const Line 214  void app::cleanup () const
214      Cfg.write (Config);      Cfg.write (Config);
215    
216      // cleanup modules      // cleanup modules
217      if (Modules & EVENT) event::manager::cleanup ();      if (Modules & EVENT) events::manager::cleanup ();
218          if (Modules & INPUT) input::cleanup ();          if (Modules & INPUT) input::cleanup ();
219      if (Modules & GFX) gfx::cleanup ();      if (Modules & GFX) gfx::cleanup ();
220      if (Modules & PYTHON) python::cleanup ();      if (Modules & PYTHON) python::cleanup ();

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26