Adonthell  0.4
adonthell.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 1999/2000/2001 Alexandre Courbot
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file adonthell.h
21  *
22  * @author Alexandre Courbot
23  * @author Kai Sterker
24  * @brief Declares the adonthell class.
25  */
26 
27 #ifndef __ADONTHELL_H__
28 #define __ADONTHELL_H__
29 
30 #include "win_mapview.h"
31 
32 /**
33  * This is the heart of the Adonthell engine. All activities,
34  * be it checking for user input, calculating a new %game state
35  * and finally rendering a scene are done in the
36  * \ref main_loop "main loop".
37  *
38  * This class works together closely with the
39  * \ref win_manager "window manager" which provides the basic
40  * GUI control methods and the \ref gametime class which is
41  * responsible for synchronising Adonthell to the machine it
42  * is running on.
43  */
44 class adonthell
45 {
46  public:
47  /**
48  * Standard constructor
49  */
50  adonthell ();
51 
52  /**
53  * @name The engine's main loop
54  *
55  */
56  //@{
57  /**
58  * Starts the main loop. Since having the mainloop running
59  * without a window to display seems to make no sense, you'll
60  * have to pass an inital window when starting the main loop.
61  * This method can be called multiple times. Only those windows
62  * belonging to the outermost main loop are updated and recieve
63  * user input. However, all windows are drawn in correct order,
64  * i.e. innermost first, outermost last.
65  *
66  * See the \ref win_manager "window manager" for more details.
67  *
68  * @param wnd The window to display initially
69  * @param name A name for that window (currently unused)
70  */
71  void main (win_base *wnd = NULL, const string name = "");
72 
73  /**
74  * The actual main loop. First, any user %input is processed,
75  * then the new %game state is calculated and finally all
76  * open (and visible) windows are rendered and displayed on
77  * screen. This (currently) happens up to 50 times per second.
78  */
79  void main_loop ();
80 
81  /**
82  * Quit the main loop. This stops the outermost main loop
83  * and closes all windows associated with that loop. It does
84  * not delete them however. For that you'll have to call
85  * win_manager::destroy ().
86  */
87  void main_quit ();
88  //@}
89 
90  /**
91  * @name Fading
92  *
93  */
94  //@{
95  /**
96  * Fades the screen to black
97  */
98  void fade_out ();
99 
100  /**
101  * Fades in from a black screen
102  */
103  void fade_in ();
104  //@}
105 
106  /**
107  * @name Saving and Loading
108  *
109  */
110  //@{
111  /**
112  * Restore the engine's state. Loads the previously displayed map,
113  * it's state and the state of the mapview from mapengine.data.
114  *
115  * @param file The opened engine state file (mapengine.data).
116  */
117  s_int8 get_state (igzstream& file);
118 
119  /**
120  * Save the engine's state. Writes the current map w/ it's state
121  * and the state of the mapview to mapengine.data.
122  *
123  * @param file The opened engine state file (mapengine.data).
124  */
125  s_int8 put_state (ogzstream& file);
126  //@}
127 
128  /**
129  * @name Additional game control
130  *
131  */
132  //@{
133  /**
134  * Returns whether the control script is active or not.
135  *
136  * @return
137  * @li true if that is the case.
138  * @li false otherwise.
139  */
141  {
142  return control_active_;
143  }
144 
145  /**
146  * Set whether the control script should be executed or
147  * not. This script provides functionality that is not
148  * directly related to contolling the main character,
149  * like opening the main menu, the load or save screen,
150  * etc.
151  *
152  * @param c Pass true to enable the control script, false
153  * to disable it.
154  */
155  void set_control_active (bool c)
156  {
157  control_active_ = c;
158  }
159  //@}
160 
161  /**
162  * @todo move landmap handling somewhere else
163  */
165  {
166  return &lmap;
167  }
168 
169  /**
170  * @todo move landmap handling somewhere else
171  */
172  bool update_map ()
173  {
174  return update_map_;
175  }
176 
177  /**
178  * @todo move landmap handling somewhere else
179  */
180  void set_update_map (bool u)
181  {
182  update_map_ = u;
183  }
184 
185  /**
186  * @todo move mapview handling somewhere else
187  */
189  {
190  return (mapview*) &view;
191  }
192 
193  /**
194  * @todo move mapview handling somewhere else
195  */
196  void draw (s_int16 x, s_int16 y, drawing_area * da_opt = NULL,
197  surface * target = NULL)
198  {
199  view.mapview::draw (x, y, da_opt, target);
200  }
201 
202  /**
203  * @todo move mapview handling somewhere else
204  */
205  void set_mapview_schedule (string s, PyObject * args = NULL)
206  {
207  view.mapview::set_schedule (s, args);
208  }
209 
210  /**
211  * @todo move mapview handling somewhere else
212  */
213  void mapview_start ();
214 
215  /**
216  * @todo move mapview handling somewhere else
217  */
218  void mapview_stop ();
219 
220  private:
221  py_object control;
222  // flag to indicate whether the control script is active or not
223  bool control_active_;
224  // flag to indicate whether to exit the main loop
225  bool letsexit;
226  // indicates whether the map should be updated or not
227  bool update_map_;
228  // the current map
229  landmap lmap;
230  // the current mapview
231  win_mapview view;
232 };
233 
234 #ifndef SWIG
235 namespace data
236 {
237  /**
238  * Engine used during the game.
239  *
240  */
241  extern adonthell *engine;
242 }
243 #endif // SWIG
244 
245 #endif // __ADONTHELL_H__
void mapview_start()
Definition: adonthell.cc:208
void main(win_base *wnd=NULL, const string name="")
Starts the main loop.
Definition: adonthell.cc:49
Class to write data from a Gzip compressed file.
Definition: fileops.h:227
void fade_in()
Fades in from a black screen.
Definition: adonthell.cc:138
Class to read data from a Gzip compressed file.
Definition: fileops.h:135
void fade_out()
Fades the screen to black.
Definition: adonthell.cc:120
Python object class.
Definition: py_object.h:45
void draw(s_int16 x, s_int16 y, drawing_area *da_opt=NULL, surface *target=NULL)
Definition: adonthell.h:196
Class where drawables can actually be drawn to.
Definition: surface.h:85
mapview * get_mapview()
Definition: adonthell.h:188
void main_quit()
Quit the main loop.
Definition: adonthell.cc:114
Allows you to display a landmap on a specified area of a surface.
Definition: mapview.h:48
adonthell()
Standard constructor.
Definition: adonthell.cc:38
Implements "drawing zones" for drawing operations.
Definition: drawing_area.h:54
s_int8 get_state(igzstream &file)
Restore the engine&#39;s state.
Definition: adonthell.cc:164
void set_control_active(bool c)
Set whether the control script should be executed or not.
Definition: adonthell.h:155
#define s_int16
16 bits long signed integer
Definition: types.h:47
Map where the world takes place.
Definition: landmap.h:56
landmap * get_landmap()
Definition: adonthell.h:164
void main_loop()
The actual main loop.
Definition: adonthell.cc:84
void set_update_map(bool u)
Definition: adonthell.h:180
void set_mapview_schedule(string s, PyObject *args=NULL)
Definition: adonthell.h:205
void mapview_stop()
Definition: adonthell.cc:221
s_int8 put_state(ogzstream &file)
Save the engine&#39;s state.
Definition: adonthell.cc:189
Common properties for each win_base&#39;s object.
Definition: win_base.h:51
#define s_int8
8 bits long signed integer
Definition: types.h:44
bool update_map()
Definition: adonthell.h:172
This is the heart of the Adonthell engine.
Definition: adonthell.h:44
bool control_active()
Returns whether the control script is active or not.
Definition: adonthell.h:140