Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 * 00027 */ 00028 00033 #ifndef __KX_KETSJI_ENGINE 00034 #define __KX_KETSJI_ENGINE 00035 00036 #include "MT_CmMatrix4x4.h" 00037 #include "MT_Matrix4x4.h" 00038 #include "STR_String.h" 00039 #include "KX_ISystem.h" 00040 #include "KX_Scene.h" 00041 #include "KX_Python.h" 00042 #include "KX_WorldInfo.h" 00043 #include <vector> 00044 #include <set> 00045 00046 class KX_TimeCategoryLogger; 00047 00048 #define LEFT_EYE 1 00049 #define RIGHT_EYE 2 00050 00051 enum KX_ExitRequestMode 00052 { 00053 KX_EXIT_REQUEST_NO_REQUEST = 0, 00054 KX_EXIT_REQUEST_QUIT_GAME, 00055 KX_EXIT_REQUEST_RESTART_GAME, 00056 KX_EXIT_REQUEST_START_OTHER_GAME, 00057 KX_EXIT_REQUEST_NO_SCENES_LEFT, 00058 KX_EXIT_REQUEST_BLENDER_ESC, 00059 KX_EXIT_REQUEST_OUTSIDE, 00060 KX_EXIT_REQUEST_MAX 00061 }; 00062 00063 typedef struct { 00064 short matmode; 00065 short glslflag; 00066 } GlobalSettings; 00067 00071 class KX_KetsjiEngine 00072 { 00073 00074 private: 00075 class RAS_ICanvas* m_canvas; // 2D Canvas (2D Rendering Device Context) 00076 class RAS_IRasterizer* m_rasterizer; // 3D Rasterizer (3D Rendering) 00077 class KX_ISystem* m_kxsystem; 00078 class RAS_IRenderTools* m_rendertools; 00079 class KX_ISceneConverter* m_sceneconverter; 00080 class NG_NetworkDeviceInterface* m_networkdevice; 00081 #ifdef WITH_PYTHON 00082 /* borrowed from sys.modules["__main__"], dont manage ref's */ 00083 PyObject* m_pythondictionary; 00084 #endif 00085 class SCA_IInputDevice* m_keyboarddevice; 00086 class SCA_IInputDevice* m_mousedevice; 00087 class KX_Dome* m_dome; // dome stereo mode 00088 00090 std::set<STR_String> m_removingScenes; 00092 std::set<STR_String> m_addingOverlayScenes; 00094 std::set<STR_String> m_addingBackgroundScenes; 00096 std::set<std::pair<STR_String,STR_String> > m_replace_scenes; 00097 00098 /* The current list of scenes. */ 00099 KX_SceneList m_scenes; 00100 /* State variable recording the presence of object debug info in the current scene list. */ 00101 bool m_propertiesPresent; 00102 00103 bool m_bInitialized; 00104 int m_activecam; 00105 bool m_bFixedTime; 00106 00107 00108 bool m_firstframe; 00109 int m_currentFrame; 00110 00111 double m_frameTime;//discrete timestamp of the 'game logic frame' 00112 double m_clockTime;//current time 00113 double m_previousClockTime;//previous clock time 00114 double m_previousAnimTime; //the last time animations were updated 00115 double m_remainingTime; 00116 00117 static int m_maxLogicFrame; /* maximum number of consecutive logic frame */ 00118 static int m_maxPhysicsFrame; /* maximum number of consecutive physics frame */ 00119 static double m_ticrate; 00120 static double m_anim_framerate; /* for animation playback only - ipo and action */ 00121 00122 static bool m_restrict_anim_fps; 00123 00124 static double m_suspendedtime; 00125 static double m_suspendeddelta; 00126 00127 static short m_exitkey; /* Key used to exit the BGE */ 00128 00129 int m_exitcode; 00130 STR_String m_exitstring; 00136 int m_drawingmode; 00137 float m_cameraZoom; 00138 00139 bool m_overrideCam; 00140 STR_String m_overrideSceneName; 00141 00142 bool m_overrideCamUseOrtho; 00143 MT_CmMatrix4x4 m_overrideCamProjMat; 00144 MT_CmMatrix4x4 m_overrideCamViewMat; 00145 float m_overrideCamNear; 00146 float m_overrideCamFar; 00147 float m_overrideCamLens; 00148 00149 bool m_stereo; 00150 int m_curreye; 00151 00153 typedef enum 00154 { 00155 tc_first = 0, 00156 tc_physics = 0, 00157 tc_logic, 00158 tc_animations, 00159 tc_network, 00160 tc_scenegraph, 00161 tc_rasterizer, 00162 tc_services, // time spend in miscelaneous activities 00163 tc_overhead, // profile info drawing overhead 00164 tc_outside, // time spend outside main loop 00165 tc_numCategories 00166 } KX_TimeCategory; 00167 00169 KX_TimeCategoryLogger* m_logger; 00170 00172 static const char m_profileLabels[tc_numCategories][15]; 00174 static double m_average_framerate; 00176 bool m_show_framerate; 00178 bool m_show_profile; 00180 bool m_showProperties; 00182 bool m_showBackground; 00183 00184 bool m_show_debug_properties; 00185 00187 bool m_animation_record; 00188 00190 bool m_hideCursor; 00191 00193 bool m_overrideFrameColor; 00195 float m_overrideFrameColorR; 00197 float m_overrideFrameColorG; 00199 float m_overrideFrameColorB; 00200 00202 GlobalSettings m_globalsettings; 00203 00204 void RenderFrame(KX_Scene* scene, KX_Camera* cam); 00205 void PostRenderScene(KX_Scene* scene); 00206 void RenderDebugProperties(); 00207 void RenderShadowBuffers(KX_Scene *scene); 00208 void SetBackGround(KX_WorldInfo* worldinfo); 00209 void RenderFonts(KX_Scene* scene); 00210 00211 public: 00212 KX_KetsjiEngine(class KX_ISystem* system); 00213 virtual ~KX_KetsjiEngine(); 00214 00215 // set the devices and stuff. the client must take care of creating these 00216 void SetWorldSettings(KX_WorldInfo* worldinfo); 00217 void SetKeyboardDevice(SCA_IInputDevice* keyboarddevice); 00218 void SetMouseDevice(SCA_IInputDevice* mousedevice); 00219 void SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice); 00220 void SetCanvas(RAS_ICanvas* canvas); 00221 void SetRenderTools(RAS_IRenderTools* rendertools); 00222 void SetRasterizer(RAS_IRasterizer* rasterizer); 00223 #ifdef WITH_PYTHON 00224 void SetPyNamespace(PyObject* pythondictionary); 00225 PyObject* GetPyNamespace(){return m_pythondictionary;}; 00226 #endif 00227 void SetSceneConverter(KX_ISceneConverter* sceneconverter); 00228 void SetAnimRecordMode(bool animation_record, int startFrame); 00229 00230 RAS_IRasterizer* GetRasterizer(){return m_rasterizer;}; 00231 RAS_ICanvas* GetCanvas(){return m_canvas;}; 00232 RAS_IRenderTools* GetRenderTools(){return m_rendertools;}; 00233 SCA_IInputDevice* GetKeyboardDevice(){return m_keyboarddevice;}; 00234 SCA_IInputDevice* GetMouseDevice(){return m_mousedevice;}; 00235 00237 void InitDome(short res, short mode, short angle, float resbuf, short tilt, struct Text* text); 00238 void EndDome(); 00239 void RenderDome(); 00240 bool m_usedome; 00241 00243 bool NextFrame(); 00244 void Render(); 00245 00246 void StartEngine(bool clearIpo); 00247 void StopEngine(); 00248 void Export(const STR_String& filename); 00249 00250 void RequestExit(int exitrequestmode); 00251 void SetNameNextGame(const STR_String& nextgame); 00252 int GetExitCode(); 00253 const STR_String& GetExitString(); 00254 00255 KX_SceneList* CurrentScenes(); 00256 KX_Scene* FindScene(const STR_String& scenename); 00257 void AddScene(class KX_Scene* scene); 00258 void ConvertAndAddScene(const STR_String& scenename,bool overlay); 00259 00260 void RemoveScene(const STR_String& scenename); 00261 void ReplaceScene(const STR_String& oldscene,const STR_String& newscene); 00262 void SuspendScene(const STR_String& scenename); 00263 void ResumeScene(const STR_String& scenename); 00264 00265 void GetSceneViewport(KX_Scene* scene, KX_Camera* cam, RAS_Rect& area, RAS_Rect& viewport); 00266 00267 void SetDrawType(int drawingtype); 00268 int GetDrawType(){return m_drawingmode;}; 00269 00270 void SetCameraZoom(float camzoom); 00271 00272 void EnableCameraOverride(const STR_String& forscene); 00273 00274 void SetCameraOverrideUseOrtho(bool useOrtho); 00275 void SetCameraOverrideProjectionMatrix(const MT_CmMatrix4x4& mat); 00276 void SetCameraOverrideViewMatrix(const MT_CmMatrix4x4& mat); 00277 void SetCameraOverrideClipping(float near, float far); 00278 void SetCameraOverrideLens(float lens); 00279 00284 void SetUseFixedTime(bool bUseFixedTime); 00285 00290 bool GetUseFixedTime(void) const; 00291 00295 double GetClockTime(void) const; 00299 double GetFrameTime(void) const; 00300 00301 double GetRealTime(void) const; 00306 static double GetSuspendedDelta(); 00307 00311 static double GetTicRate(); 00315 static void SetTicRate(double ticrate); 00319 static int GetMaxLogicFrame(); 00323 static void SetMaxLogicFrame(int frame); 00327 static int GetMaxPhysicsFrame(); 00331 static void SetMaxPhysicsFrame(int frame); 00332 00336 static bool GetRestrictAnimationFPS(); 00337 00341 static void SetRestrictAnimationFPS(bool bRestrictAnimFPS); 00342 00346 static double GetAnimFrameRate(); 00350 static void SetAnimFrameRate(double framerate); 00351 00355 static double GetAverageFrameRate(); 00356 00357 static void SetExitKey(short key); 00358 00359 static short GetExitKey(); 00360 00367 void SetTimingDisplay(bool frameRate, bool profile, bool properties); 00368 00375 void GetTimingDisplay(bool& frameRate, bool& profile, bool& properties) const; 00376 00381 void SetHideCursor(bool hideCursor); 00382 00387 bool GetHideCursor(void) const; 00388 00393 void SetUseOverrideFrameColor(bool overrideFrameColor); 00394 00398 bool GetUseOverrideFrameColor(void) const; 00399 00406 void SetOverrideFrameColor(float r, float g, float b); 00407 00414 void GetOverrideFrameColor(float& r, float& g, float& b) const; 00415 00416 KX_Scene* CreateScene(const STR_String& scenename); 00417 KX_Scene* CreateScene(Scene *scene); 00418 00419 GlobalSettings* GetGlobalSettings(void); 00420 void SetGlobalSettings(GlobalSettings* gs); 00421 00422 protected: 00429 void ProcessScheduledScenes(void); 00430 00434 void SceneListsChanged(void); 00435 00436 void RemoveScheduledScenes(void); 00437 void AddScheduledScenes(void); 00438 void ReplaceScheduledScenes(void); 00439 void PostProcessScene(class KX_Scene* scene); 00440 00441 bool BeginFrame(); 00442 void ClearFrame(); 00443 void EndFrame(); 00444 00445 00446 #ifdef WITH_CXX_GUARDEDALLOC 00447 public: 00448 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:KX_KetsjiEngine"); } 00449 void operator delete( void *mem ) { MEM_freeN(mem); } 00450 #endif 00451 }; 00452 00453 #endif //__KX_KETSJI_ENGINE 00454 00455