Architecture:Main Module: Difference between revisions
No edit summary |
|||
Line 61: | Line 61: | ||
# '''Parse command line parameters'''<br>As some parameters override defaults or supply otherwise important information, they are read first. The backend used or the configuration file loaded can be influenced that way. | # '''Parse command line parameters'''<br>As some parameters override defaults or supply otherwise important information, they are read first. The backend used or the configuration file loaded can be influenced that way. | ||
# '''Initialize base module'''<br>Amongst other things, the path to the configuration directory – required for the next step – will be set up. Other game related paths will be initialized too. | # '''Initialize base module'''<br>Amongst other things, the path to the configuration directory – required for the next step – will be set up. Other game related paths will be initialized too. | ||
# '''Read configuration file'''<br>Unless given on the command line, the backend to use is read from the configuration file adonthell.xml. A different config file can be chosen via the command line. | # '''Read configuration file'''<br>Unless given on the command line, the backend to use is read from the configuration file ''adonthell.xml''. A different config file can be chosen via the command line. | ||
# '''Perform platform specifc initialization'''<br>The main module’s backend is loaded. If none was given via command line or configuration file, so it is used as the fallback. Once loaded, it performs the operating system dependent initialization. | # '''Perform platform specifc initialization'''<br>The main module’s backend is loaded. If none was given via command line or configuration file, so it is used as the fallback. Once loaded, it performs the operating system dependent initialization. | ||
# '''Call user-supplied main method'''<br>If all went well so far, the user supplied main method is executed. It should call the <tt>init_modules</tt> method to further initialize those parts of the engine it requires. Once the main method returns, the engine does some cleanup and finally exits. | # '''Call user-supplied main method'''<br>If all went well so far, the user supplied main method is executed. It should call the <tt>init_modules</tt> method to further initialize those parts of the engine it requires. Once the main method returns, the engine does some cleanup and finally exits. |
Revision as of 19:59, 17 May 2005
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 ...
Engine Startup
After having seen how the main module can be used, lets see what happens when using it.
- Parse command line parameters
As some parameters override defaults or supply otherwise important information, they are read first. The backend used or the configuration file loaded can be influenced that way. - Initialize base module
Amongst other things, the path to the configuration directory – required for the next step – will be set up. Other game related paths will be initialized too. - Read configuration file
Unless given on the command line, the backend to use is read from the configuration file adonthell.xml. A different config file can be chosen via the command line. - Perform platform specifc initialization
The main module’s backend is loaded. If none was given via command line or configuration file, so it is used as the fallback. Once loaded, it performs the operating system dependent initialization. - Call user-supplied main method
If all went well so far, the user supplied main method is executed. It should call the init_modules method to further initialize those parts of the engine it requires. Once the main method returns, the engine does some cleanup and finally exits.