Architecture:Main Module

From Adonthell
Revision as of 21:27, 10 May 2005 by Ksterker (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Although the various Adonthell modules can be used from custom programs without utilizing the main module, this is highly discouraged. Not only provides the main module convenient initialization methods, it also contains code to prepare the environment for modules like gfx and input on different operating systems.

Using the Engine from C++

The main module provides a main function (hence the name), so your program will not need one when linking to the main module. Instead, it must provide a special class serving as entry point to your code once the startup process is complete. It should look as follows:

   #include "main/adonthell.h" 
   
   class AdonthellApp : public adonthell::app 
   { 
       // your application entry point 
       int main () 
       { 
           init_modules (GFX | ...); 
           ... 
       } 
   } theApp;

It must extend adonthell::app and implement the pure virtual method int main(). This is the method called after basic engine initialization. Exactly one instance of that class, called theApp must be provided, so that the main module can find it. adonthell::app gives you access to commandline arguments and further initialization methods, described in more detail in the API.

Using the Engine from Python

The main module provides roughly the same functionality when being used from within a python script, althuogh a few more lines of code are required:

   from adonthell import main 
   
   class App (main.AdonthellApp): 
       def __init__ (self): 
           main.AdonthellApp.__init__ (self) 
   
       # -- your application entry point 
       def main (self): 
           self.init_modules (self.GFX | ...) 
           ... 
   
   if __name__ == ’__main__’: 
       theApp = App () 
       theApp.init (theApp.main)

The first difference to the C++ code is that we extend the class AdonthellApp, which is only available in the main module on Python side. It is in turn derived from the aforementioned class adonthell::app, so the methods it provides are available to Python too. The second difference is the call to theApp.init, which makes the applications entry point known to AdonthellApp. It also triggers the startup procedure described below, which will finally call the user supplied method. Note that code placed after theApp.init, will not be executed until the engine quits – if it is executed at all! You have been warned ...