Adonthell 0.4

adonthell.h

Go to the documentation of this file.
00001 /*
00002    $Id: adonthell.h,v 1.6 2003/02/23 23:14:34 ksterker Exp $
00003 
00004    Copyright (C) 1999/2000/2001 Alexandre Courbot
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 /** 
00016  * @file adonthell.h
00017  *
00018  * @author Alexandre Courbot
00019  * @author Kai Sterker
00020  * @brief Declares the adonthell class.
00021  */
00022 
00023 #ifndef __ADONTHELL_H__
00024 #define __ADONTHELL_H__
00025 
00026 #include "win_mapview.h"
00027 
00028 /**
00029  * This is the heart of the Adonthell engine. All activities,
00030  * be it checking for user input, calculating a new %game state
00031  * and finally rendering a scene are done in the 
00032  * \ref main_loop "main loop".
00033  *
00034  * This class works together closely with the 
00035  * \ref win_manager "window manager" which provides the basic
00036  * GUI control methods and the \ref gametime class which is
00037  * responsible for synchronising Adonthell to the machine it
00038  * is running on.
00039  */
00040 class adonthell
00041 {
00042   public:
00043     /**
00044      * Standard constructor
00045      */
00046     adonthell ();
00047    
00048     /**
00049      * @name The engine's main loop
00050      * 
00051      */ 
00052     //@{
00053     /**
00054      * Starts the main loop. Since having the mainloop running
00055      * without a window to display seems to make no sense, you'll
00056      * have to pass an inital window when starting the main loop.
00057      * This method can be called multiple times. Only those windows
00058      * belonging to the outermost main loop are updated and recieve
00059      * user input. However, all windows are drawn in correct order,
00060      * i.e. innermost first, outermost last. 
00061      *
00062      * See the \ref win_manager "window manager" for more details.
00063      *
00064      * @param wnd The window to display initially
00065      * @param name A name for that window (currently unused)
00066      */
00067     void main (win_base *wnd = NULL, const string name = "");
00068     
00069     /**
00070      * The actual main loop. First, any user %input is processed,
00071      * then the new %game state is calculated and finally all
00072      * open (and visible) windows are rendered and displayed on
00073      * screen. This (currently) happens up to 50 times per second.
00074      */
00075     void main_loop ();
00076     
00077     /**
00078      * Quit the main loop. This stops the outermost main loop
00079      * and closes all windows associated with that loop. It does
00080      * not delete them however. For that you'll have to call
00081      * win_manager::destroy ().
00082      */
00083     void main_quit ();
00084     //@}
00085     
00086     /**
00087      * @name Fading
00088      * 
00089      */ 
00090     //@{
00091     /**
00092      * Fades the screen to black
00093      */
00094     void fade_out ();
00095 
00096     /**
00097      * Fades in from a black screen
00098      */
00099     void fade_in ();
00100     //@}
00101 
00102     /**
00103      * @name Saving and Loading
00104      * 
00105      */ 
00106     //@{
00107     /**
00108      * Restore the engine's state. Loads the previously displayed map,
00109      * it's state and the state of the mapview from mapengine.data. 
00110      *
00111      * @param file The opened engine state file (mapengine.data).
00112      */
00113     s_int8 get_state (igzstream& file);
00114 
00115     /**
00116      * Save the engine's state. Writes the current map w/ it's state
00117      * and the state of the mapview to mapengine.data.
00118      *
00119      * @param file The opened engine state file (mapengine.data).
00120      */
00121     s_int8 put_state (ogzstream& file);
00122     //@}
00123     
00124     /**
00125      * @name Additional game control
00126      * 
00127      */ 
00128     //@{
00129     /**
00130      * Returns whether the control script is active or not.
00131      *
00132      * @return 
00133      *      @li true if that is the case.
00134      *      @li false otherwise.
00135      */
00136     bool control_active ()
00137     {
00138         return control_active_;
00139     }
00140     
00141     /**
00142      * Set whether the control script should be executed or
00143      * not. This script provides functionality that is not
00144      * directly related to contolling the main character,
00145      * like opening the main menu, the load or save screen,
00146      * etc.
00147      *
00148      * @param c Pass true to enable the control script, false
00149      *          to disable it.
00150      */
00151     void set_control_active (bool c)
00152     {
00153         control_active_ = c;
00154     }
00155     //@}
00156 
00157     /**
00158      * @todo move landmap handling somewhere else
00159      */
00160     landmap *get_landmap ()
00161     {
00162         return &lmap;
00163     }
00164 
00165     /**
00166      * @todo move landmap handling somewhere else
00167      */
00168     bool update_map ()
00169     {
00170         return update_map_;
00171     }
00172     
00173     /**
00174      * @todo move landmap handling somewhere else
00175      */
00176     void set_update_map (bool u)
00177     {
00178         update_map_ = u;
00179     }
00180     
00181     /**
00182      * @todo move mapview handling somewhere else
00183      */
00184     mapview *get_mapview ()
00185     {
00186         return (mapview*) &view;
00187     }
00188 
00189     /**
00190      * @todo move mapview handling somewhere else
00191      */
00192     void draw (s_int16 x, s_int16 y, drawing_area * da_opt = NULL,
00193                surface * target = NULL)
00194     {
00195         view.mapview::draw (x, y, da_opt, target); 
00196     }
00197     
00198     /**
00199      * @todo move mapview handling somewhere else
00200      */
00201     void set_mapview_schedule (string s, PyObject * args = NULL)
00202     {
00203         view.mapview::set_schedule (s, args); 
00204     }
00205 
00206     /**
00207      * @todo move mapview handling somewhere else
00208      */
00209     void mapview_start ();
00210     
00211     /**
00212      * @todo move mapview handling somewhere else
00213      */
00214     void mapview_stop ();
00215 
00216   private:
00217     py_object control;
00218     // flag to indicate whether the control script is active or not
00219     bool control_active_;
00220     // flag to indicate whether to exit the main loop
00221     bool letsexit;
00222     // indicates whether the map should be updated or not
00223     bool update_map_;
00224     // the current map
00225     landmap lmap;
00226     // the current mapview
00227     win_mapview view;
00228 };
00229 
00230 #ifndef SWIG
00231 namespace data
00232 {
00233     /**
00234      * Engine used during the game.
00235      * 
00236      */ 
00237     extern adonthell *engine;
00238 }
00239 #endif // SWIG
00240 
00241 #endif // __ADONTHELL_H__