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;
78 /** Lists of scenes scheduled to be removed at the end of the frame. */
79 std::set<STR_String> m_removingScenes;
80 /** Lists of overley scenes scheduled to be added at the end of the frame. */
81 std::set<STR_String> m_addingOverlayScenes;
82 /** Lists of background scenes scheduled to be added at the end of the frame. */
83 std::set<STR_String> m_addingBackgroundScenes;
84 /** Lists of scenes scheduled to be replaced at the end of the frame. */
85 std::set<std::pair<STR_String,STR_String> > m_replace_scenes;
87 /* The current list of scenes. */
88 KX_SceneList m_scenes;
89 /* State variable recording the presence of object debug info in the current scene list. */
90 bool m_propertiesPresent;
100 double m_frameTime;//discrete timestamp of the 'game logic frame'
101 double m_clockTime;//current time
102 double m_previousClockTime;//previous clock time
103 double m_remainingTime;
105 static double m_ticrate;
106 static double m_anim_framerate; /* for animation playback only - ipo and action */
108 static double m_suspendedtime;
109 static double m_suspendeddelta;
112 STR_String m_exitstring;
114 * Some drawing parameters, the drawing mode
115 * (wire/flat/texture), and the camera zoom
122 STR_String m_overrideSceneName;
124 bool m_overrideCamUseOrtho;
125 MT_CmMatrix4x4 m_overrideCamProjMat;
126 MT_CmMatrix4x4 m_overrideCamViewMat;
131 /** Categories for profiling display. */
141 tc_services, // time spend in miscelaneous activities
142 tc_overhead, // profile info drawing overhead
143 tc_outside, // time spend outside main loop
148 KX_TimeCategoryLogger* m_logger;
150 /** Labels for profiling display. */
151 static const char m_profileLabels[tc_numCategories][15];
152 /** Show the framerate on the game display? */
153 bool m_show_framerate;
154 /** Show profiling info on the game display? */
156 /** Show any debug (scene) object properties on the game display? */
157 bool m_showProperties;
158 /** Show background behind text for readability? */
159 bool m_showBackground;
161 bool m_show_debug_properties;
163 /** record physics into keyframes */
166 /** Hide cursor every frame? */
169 /** Override framing bars color? */
170 bool m_overrideFrameColor;
171 /** Red component of framing bar color. */
172 float m_overrideFrameColorR;
173 /** Green component of framing bar color. */
174 float m_overrideFrameColorG;
175 /** Blue component of framing bar color. */
176 float m_overrideFrameColorB;
178 void SetupRenderFrame(KX_Scene *scene, KX_Camera* cam);
179 void RenderFrame(KX_Scene* scene, KX_Camera* cam);
180 void PostRenderFrame();
181 void RenderDebugProperties();
182 void RenderShadowBuffers(KX_Scene *scene);
183 void SetBackGround(KX_WorldInfo* worldinfo);
184 void SetWorldSettings(KX_WorldInfo* worldinfo);
185 void DoSound(KX_Scene* scene);
189 KX_KetsjiEngine(class KX_ISystem* system);
190 virtual ~KX_KetsjiEngine();
192 // set the devices and stuff. the client must take care of creating these
193 void SetKeyboardDevice(SCA_IInputDevice* keyboarddevice);
194 void SetMouseDevice(SCA_IInputDevice* mousedevice);
195 void SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice);
196 void SetAudioDevice(SND_IAudioDevice* audiodevice);
197 void SetCanvas(RAS_ICanvas* canvas);
198 void SetRenderTools(RAS_IRenderTools* rendertools);
199 void SetRasterizer(RAS_IRasterizer* rasterizer);
200 void SetPythonDictionary(PyObject* pythondictionary);
201 void SetSceneConverter(KX_ISceneConverter* sceneconverter);
202 void SetGame2IpoMode(bool game2ipo,int startFrame);
204 RAS_IRasterizer* GetRasterizer(){return m_rasterizer;};
206 ///returns true if an update happened to indicate -> Render
210 void StartEngine(bool clearIpo);
212 void Export(const STR_String& filename);
214 void RequestExit(int exitrequestmode);
215 void SetNameNextGame(const STR_String& nextgame);
217 const STR_String& GetExitString();
219 KX_SceneList* CurrentScenes();
220 KX_Scene* FindScene(const STR_String& scenename);
221 void AddScene(class KX_Scene* scene);
222 void ConvertAndAddScene(const STR_String& scenename,bool overlay);
224 void RemoveScene(const STR_String& scenename);
225 void ReplaceScene(const STR_String& oldscene,const STR_String& newscene);
226 void SuspendScene(const STR_String& scenename);
227 void ResumeScene(const STR_String& scenename);
229 void SetDrawType(int drawingtype);
230 void SetCameraZoom(float camzoom);
232 void EnableCameraOverride(const STR_String& forscene);
234 void SetCameraOverrideUseOrtho(bool useOrtho);
235 void SetCameraOverrideProjectionMatrix(const MT_CmMatrix4x4& mat);
236 void SetCameraOverrideViewMatrix(const MT_CmMatrix4x4& mat);
239 * Sets display of all frames.
240 * @param bUseFixedTime New setting for display all frames.
242 void SetUseFixedTime(bool bUseFixedTime);
245 * Returns display of all frames.
246 * @return Current setting for display all frames.
248 bool GetUseFixedTime(void) const;
251 * Returns the difference between the local time of the scene (when it
252 * was running and not suspended) and the "curtime"
254 static double GetSuspendedDelta();
257 * Gets the number of logic updates per second.
259 static double GetTicRate();
261 * Sets the number of logic updates per second.
263 static void SetTicRate(double ticrate);
266 * Gets the framerate for playing animations. (actions and ipos)
268 static double GetAnimFrameRate();
270 * Sets the framerate for playing animations. (actions and ipos)
272 static void SetAnimFrameRate(double framerate);
275 * Activates or deactivates timing information display.
276 * @param frameRate Display for frame rate on or off.
277 * @param profile Display for individual components on or off.
278 * @param properties Display of scene object debug properties on or off.
280 void SetTimingDisplay(bool frameRate, bool profile, bool properties);
283 * Returns status of timing information display.
284 * @param frameRate Display for frame rate on or off.
285 * @param profile Display for individual components on or off.
286 * @param properties Display of scene object debug properties on or off.
288 void GetTimingDisplay(bool& frameRate, bool& profile, bool& properties) const;
291 * Sets cursor hiding on every frame.
292 * @param hideCursor Turns hiding on or off.
294 void SetHideCursor(bool hideCursor);
297 * Returns the current setting for cursor hiding.
298 * @return The current setting for cursor hiding.
300 bool GetHideCursor(void) const;
303 * Enables/disables the use of the framing bar color of the Blender file's scenes.
304 * @param overrideFrameColor The new setting.
306 void SetUseOverrideFrameColor(bool overrideFrameColor);
309 * Enables/disables the use of the framing bar color of the Blender file's scenes.
310 * @param useSceneFrameColor The new setting.
312 bool GetUseOverrideFrameColor(void) const;
315 * Set the color used for framing bar color instead of the one in the Blender file's scenes.
316 * @param r Red component of the override color.
317 * @param g Green component of the override color.
318 * @param b Blue component of the override color.
320 void SetOverrideFrameColor(float r, float g, float b);
323 * Returns the color used for framing bar color instead of the one in the Blender file's scenes.
324 * @param r Red component of the override color.
325 * @param g Green component of the override color.
326 * @param b Blue component of the override color.
328 void GetOverrideFrameColor(float& r, float& g, float& b) const;
332 * Processes all scheduled scene activity.
333 * At the end, if the scene lists have changed,
334 * SceneListsChanged(void) is called.
335 * @see SceneListsChanged(void).
337 void ProcessScheduledScenes(void);
340 * This method is invoked when the scene lists have changed.
342 void SceneListsChanged(void);
344 void RemoveScheduledScenes(void);
345 void AddScheduledScenes(void);
346 void ReplaceScheduledScenes(void);
347 void PostProcessScene(class KX_Scene* scene);
348 KX_Scene* CreateScene(const STR_String& scenename);
354 #endif //__KX_KETSJI_ENGINE