4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
30 #ifndef __KX_KETSJI_ENGINE
31 #define __KX_KETSJI_ENGINE
33 #include "MT_CmMatrix4x4.h"
34 #include "MT_Matrix4x4.h"
35 #include "STR_String.h"
36 #include "KX_ISystem.h"
38 #include "KX_Python.h"
39 #include "KX_WorldInfo.h"
43 class KX_TimeCategoryLogger;
48 enum KX_ExitRequestMode
50 KX_EXIT_REQUEST_NO_REQUEST = 0,
51 KX_EXIT_REQUEST_QUIT_GAME,
52 KX_EXIT_REQUEST_RESTART_GAME,
53 KX_EXIT_REQUEST_START_OTHER_GAME,
54 KX_EXIT_REQUEST_NO_SCENES_LEFT,
55 KX_EXIT_REQUEST_BLENDER_ESC,
56 KX_EXIT_REQUEST_OUTSIDE,
61 * KX_KetsjiEngine is the core game engine class.
67 class RAS_ICanvas* m_canvas; // 2D Canvas (2D Rendering Device Context)
68 class RAS_IRasterizer* m_rasterizer; // 3D Rasterizer (3D Rendering)
69 class KX_ISystem* m_kxsystem;
70 class RAS_IRenderTools* m_rendertools;
71 class KX_ISceneConverter* m_sceneconverter;
72 class NG_NetworkDeviceInterface* m_networkdevice;
73 class SND_IAudioDevice* m_audiodevice;
74 PyObject* m_pythondictionary;
75 class SCA_IInputDevice* m_keyboarddevice;
76 class SCA_IInputDevice* m_mousedevice;
77 class KX_Dome* m_dome; // dome stereo mode
79 /** Lists of scenes scheduled to be removed at the end of the frame. */
80 std::set<STR_String> m_removingScenes;
81 /** Lists of overley scenes scheduled to be added at the end of the frame. */
82 std::set<STR_String> m_addingOverlayScenes;
83 /** Lists of background scenes scheduled to be added at the end of the frame. */
84 std::set<STR_String> m_addingBackgroundScenes;
85 /** Lists of scenes scheduled to be replaced at the end of the frame. */
86 std::set<std::pair<STR_String,STR_String> > m_replace_scenes;
88 /* The current list of scenes. */
89 KX_SceneList m_scenes;
90 /* State variable recording the presence of object debug info in the current scene list. */
91 bool m_propertiesPresent;
101 double m_frameTime;//discrete timestamp of the 'game logic frame'
102 double m_clockTime;//current time
103 double m_previousClockTime;//previous clock time
104 double m_remainingTime;
106 static double m_ticrate;
107 static double m_anim_framerate; /* for animation playback only - ipo and action */
109 static double m_suspendedtime;
110 static double m_suspendeddelta;
113 STR_String m_exitstring;
115 * Some drawing parameters, the drawing mode
116 * (wire/flat/texture), and the camera zoom
123 STR_String m_overrideSceneName;
125 bool m_overrideCamUseOrtho;
126 MT_CmMatrix4x4 m_overrideCamProjMat;
127 MT_CmMatrix4x4 m_overrideCamViewMat;
128 float m_overrideCamNear;
129 float m_overrideCamFar;
134 /** Categories for profiling display. */
144 tc_services, // time spend in miscelaneous activities
145 tc_overhead, // profile info drawing overhead
146 tc_outside, // time spend outside main loop
151 KX_TimeCategoryLogger* m_logger;
153 /** Labels for profiling display. */
154 static const char m_profileLabels[tc_numCategories][15];
155 /** Last estimated framerate */
156 static double m_average_framerate;
157 /** Show the framerate on the game display? */
158 bool m_show_framerate;
159 /** Show profiling info on the game display? */
161 /** Show any debug (scene) object properties on the game display? */
162 bool m_showProperties;
163 /** Show background behind text for readability? */
164 bool m_showBackground;
166 bool m_show_debug_properties;
168 /** record physics into keyframes */
171 /** Hide cursor every frame? */
174 /** Override framing bars color? */
175 bool m_overrideFrameColor;
176 /** Red component of framing bar color. */
177 float m_overrideFrameColorR;
178 /** Green component of framing bar color. */
179 float m_overrideFrameColorG;
180 /** Blue component of framing bar color. */
181 float m_overrideFrameColorB;
183 void RenderFrame(KX_Scene* scene, KX_Camera* cam);
184 void PostRenderFrame();
185 void RenderDebugProperties();
186 void RenderShadowBuffers(KX_Scene *scene);
187 void SetBackGround(KX_WorldInfo* worldinfo);
188 void DoSound(KX_Scene* scene);
192 KX_KetsjiEngine(class KX_ISystem* system);
193 virtual ~KX_KetsjiEngine();
195 // set the devices and stuff. the client must take care of creating these
196 void SetWorldSettings(KX_WorldInfo* worldinfo);
197 void SetKeyboardDevice(SCA_IInputDevice* keyboarddevice);
198 void SetMouseDevice(SCA_IInputDevice* mousedevice);
199 void SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice);
200 void SetAudioDevice(SND_IAudioDevice* audiodevice);
201 void SetCanvas(RAS_ICanvas* canvas);
202 void SetRenderTools(RAS_IRenderTools* rendertools);
203 void SetRasterizer(RAS_IRasterizer* rasterizer);
204 void SetPythonDictionary(PyObject* pythondictionary);
205 void SetSceneConverter(KX_ISceneConverter* sceneconverter);
206 void SetGame2IpoMode(bool game2ipo,int startFrame);
208 RAS_IRasterizer* GetRasterizer(){return m_rasterizer;};
209 RAS_ICanvas* GetCanvas(){return m_canvas;};
210 RAS_IRenderTools* GetRenderTools(){return m_rendertools;};
213 void InitDome(float size, short res, short mode, short angle, float resbuf, struct Text* text);
218 ///returns true if an update happened to indicate -> Render
222 void StartEngine(bool clearIpo);
224 void Export(const STR_String& filename);
226 void RequestExit(int exitrequestmode);
227 void SetNameNextGame(const STR_String& nextgame);
229 const STR_String& GetExitString();
231 KX_SceneList* CurrentScenes();
232 KX_Scene* FindScene(const STR_String& scenename);
233 void AddScene(class KX_Scene* scene);
234 void ConvertAndAddScene(const STR_String& scenename,bool overlay);
236 void RemoveScene(const STR_String& scenename);
237 void ReplaceScene(const STR_String& oldscene,const STR_String& newscene);
238 void SuspendScene(const STR_String& scenename);
239 void ResumeScene(const STR_String& scenename);
241 void GetSceneViewport(KX_Scene* scene, KX_Camera* cam, RAS_Rect& area, RAS_Rect& viewport);
243 void SetDrawType(int drawingtype);
244 int GetDrawType(){return m_drawingmode;};
246 void SetCameraZoom(float camzoom);
248 void EnableCameraOverride(const STR_String& forscene);
250 void SetCameraOverrideUseOrtho(bool useOrtho);
251 void SetCameraOverrideProjectionMatrix(const MT_CmMatrix4x4& mat);
252 void SetCameraOverrideViewMatrix(const MT_CmMatrix4x4& mat);
253 void SetCameraOverrideClipping(float near, float far);
256 * Sets display of all frames.
257 * @param bUseFixedTime New setting for display all frames.
259 void SetUseFixedTime(bool bUseFixedTime);
262 * Returns display of all frames.
263 * @return Current setting for display all frames.
265 bool GetUseFixedTime(void) const;
268 * Returns current render frame clock time
270 double GetClockTime(void) const;
273 * Returns the difference between the local time of the scene (when it
274 * was running and not suspended) and the "curtime"
276 static double GetSuspendedDelta();
279 * Gets the number of logic updates per second.
281 static double GetTicRate();
283 * Sets the number of logic updates per second.
285 static void SetTicRate(double ticrate);
288 * Gets the framerate for playing animations. (actions and ipos)
290 static double GetAnimFrameRate();
292 * Sets the framerate for playing animations. (actions and ipos)
294 static void SetAnimFrameRate(double framerate);
297 * Gets the last estimated average framerate
299 static double GetAverageFrameRate();
302 * Activates or deactivates timing information display.
303 * @param frameRate Display for frame rate on or off.
304 * @param profile Display for individual components on or off.
305 * @param properties Display of scene object debug properties on or off.
307 void SetTimingDisplay(bool frameRate, bool profile, bool properties);
310 * Returns status of timing information display.
311 * @param frameRate Display for frame rate on or off.
312 * @param profile Display for individual components on or off.
313 * @param properties Display of scene object debug properties on or off.
315 void GetTimingDisplay(bool& frameRate, bool& profile, bool& properties) const;
318 * Sets cursor hiding on every frame.
319 * @param hideCursor Turns hiding on or off.
321 void SetHideCursor(bool hideCursor);
324 * Returns the current setting for cursor hiding.
325 * @return The current setting for cursor hiding.
327 bool GetHideCursor(void) const;
330 * Enables/disables the use of the framing bar color of the Blender file's scenes.
331 * @param overrideFrameColor The new setting.
333 void SetUseOverrideFrameColor(bool overrideFrameColor);
336 * Enables/disables the use of the framing bar color of the Blender file's scenes.
337 * @param useSceneFrameColor The new setting.
339 bool GetUseOverrideFrameColor(void) const;
342 * Set the color used for framing bar color instead of the one in the Blender file's scenes.
343 * @param r Red component of the override color.
344 * @param g Green component of the override color.
345 * @param b Blue component of the override color.
347 void SetOverrideFrameColor(float r, float g, float b);
350 * Returns the color used for framing bar color instead of the one in the Blender file's scenes.
351 * @param r Red component of the override color.
352 * @param g Green component of the override color.
353 * @param b Blue component of the override color.
355 void GetOverrideFrameColor(float& r, float& g, float& b) const;
359 * Processes all scheduled scene activity.
360 * At the end, if the scene lists have changed,
361 * SceneListsChanged(void) is called.
362 * @see SceneListsChanged(void).
364 void ProcessScheduledScenes(void);
367 * This method is invoked when the scene lists have changed.
369 void SceneListsChanged(void);
371 void RemoveScheduledScenes(void);
372 void AddScheduledScenes(void);
373 void ReplaceScheduledScenes(void);
374 void PostProcessScene(class KX_Scene* scene);
375 KX_Scene* CreateScene(const STR_String& scenename);
382 #endif //__KX_KETSJI_ENGINE