2e0c5d713dc40665b5539c56925d6e2601917c57
[blender.git] / source / gameengine / Ketsji / KX_KetsjiEngine.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  * The engine ties all game modules together. 
32  */
33
34 #ifdef WIN32
35 #pragma warning (disable : 4786)
36 #endif //WIN32
37
38 #include <iostream>
39
40 #include "KX_KetsjiEngine.h"
41
42 #include "ListValue.h"
43 #include "IntValue.h"
44 #include "VectorValue.h"
45 #include "BoolValue.h"
46 #include "FloatValue.h"
47
48 #define KX_NUM_ITERATIONS 4
49 #include "RAS_BucketManager.h"
50 #include "RAS_Rect.h"
51 #include "RAS_IRasterizer.h"
52 #include "RAS_IRenderTools.h"
53 #include "RAS_ICanvas.h"
54 #include "STR_String.h"
55 #include "MT_Vector3.h"
56 #include "MT_Transform.h"
57 #include "SCA_IInputDevice.h"
58 #include "KX_Scene.h"
59 #include "MT_CmMatrix4x4.h"
60 #include "KX_Camera.h"
61 #include "KX_PythonInit.h"
62 #include "KX_PyConstraintBinding.h"
63 #include "PHY_IPhysicsEnvironment.h"
64 #include "SumoPhysicsEnvironment.h"
65
66 #include "SND_Scene.h"
67 #include "SND_IAudioDevice.h"
68
69 #include "NG_NetworkScene.h"
70 #include "NG_NetworkDeviceInterface.h"
71
72 #include "KX_WorldInfo.h"
73 #include "KX_ISceneConverter.h"
74 #include "KX_TimeCategoryLogger.h"
75
76 #include "RAS_FramingManager.h"
77
78 // If define: little test for Nzc: guarded drawing. If the canvas is
79 // not valid, skip rendering this frame.
80 //#define NZC_GUARDED_OUTPUT
81 #define DEFAULT_LOGIC_TIC_RATE 60.0
82 #define DEFAULT_PHYSICS_TIC_RATE 60.0
83
84 const char KX_KetsjiEngine::m_profileLabels[tc_numCategories][15] = {
85         "Physics:",             // tc_physics
86         "Logic",                // tc_logic
87         "Network:",             // tc_network
88         "Scenegraph:",  // tc_scenegraph
89         "Sound:",               // tc_sound
90         "Rasterizer:",  // tc_rasterizer
91         "Services:",    // tc_services
92         "Overhead:",    // tc_overhead
93         "Outside:"              // tc_outside
94 };
95
96 double KX_KetsjiEngine::m_ticrate = DEFAULT_LOGIC_TIC_RATE;
97
98 double KX_KetsjiEngine::m_suspendedtime = 0.0;
99 double KX_KetsjiEngine::m_suspendeddelta = 0.0;
100
101
102 /**
103  *      Constructor of the Ketsji Engine
104  */
105 KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system)
106      :  m_canvas(NULL),
107         m_rasterizer(NULL),
108         m_kxsystem(system),
109         m_rendertools(NULL),
110         m_sceneconverter(NULL),
111         m_networkdevice(NULL),
112         m_audiodevice(NULL),
113         m_pythondictionary(NULL),
114         m_keyboarddevice(NULL),
115         m_mousedevice(NULL),
116
117         m_propertiesPresent(false),
118
119         m_bInitialized(false),
120         m_activecam(0),
121         m_bFixedTime(false),
122         m_game2ipo(false),
123         
124         m_firstframe(true),
125         
126         m_frameTime(0.f),
127         m_clockTime(0.f),
128         m_previousClockTime(0.f),
129
130
131         m_exitcode(KX_EXIT_REQUEST_NO_REQUEST),
132         m_exitstring(""),
133         
134         m_drawingmode(5),
135         m_cameraZoom(1.0),
136         
137         m_overrideCam(false),
138         m_overrideCamUseOrtho(false),
139
140         m_stereo(false),
141         m_curreye(0),
142
143         m_logger(NULL),
144         
145         // Set up timing info display variables
146         m_show_framerate(false),
147         m_show_profile(false),
148         m_showProperties(false),
149         m_showBackground(false),
150         m_show_debug_properties(false),
151
152         // Default behavior is to hide the cursor every frame.
153         m_hideCursor(false),
154
155         m_overrideFrameColor(false),
156         m_overrideFrameColorR(0.0),
157         m_overrideFrameColorG(0.0),
158         m_overrideFrameColorB(0.0)
159 {
160         // Initialize the time logger
161         m_logger = new KX_TimeCategoryLogger (25);
162
163         for (int i = tc_first; i < tc_numCategories; i++)
164                 m_logger->AddCategory((KX_TimeCategory)i);
165                 
166 }
167
168
169
170 /**
171  *      Destructor of the Ketsji Engine, release all memory
172  */
173 KX_KetsjiEngine::~KX_KetsjiEngine()
174 {
175         delete m_logger;
176 }
177
178
179
180 void KX_KetsjiEngine::SetKeyboardDevice(SCA_IInputDevice* keyboarddevice)
181 {
182         MT_assert(keyboarddevice);
183         m_keyboarddevice = keyboarddevice;
184 }
185
186
187
188 void KX_KetsjiEngine::SetMouseDevice(SCA_IInputDevice* mousedevice)
189 {
190         MT_assert(mousedevice);
191         m_mousedevice = mousedevice;
192 }
193
194
195
196 void KX_KetsjiEngine::SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice)
197 {
198         MT_assert(networkdevice);
199         m_networkdevice = networkdevice;
200 }
201
202
203
204 void KX_KetsjiEngine::SetAudioDevice(SND_IAudioDevice* audiodevice)
205 {
206         MT_assert(audiodevice);
207         m_audiodevice = audiodevice;
208 }
209
210
211
212 void KX_KetsjiEngine::SetCanvas(RAS_ICanvas* canvas)
213 {
214         MT_assert(canvas);
215         m_canvas = canvas;
216 }
217
218
219
220 void KX_KetsjiEngine::SetRenderTools(RAS_IRenderTools* rendertools)
221 {
222         MT_assert(rendertools);
223         m_rendertools = rendertools;
224 }
225
226
227
228 void KX_KetsjiEngine::SetRasterizer(RAS_IRasterizer* rasterizer)
229 {
230         MT_assert(rasterizer);
231         m_rasterizer = rasterizer;
232 }
233
234
235
236 void KX_KetsjiEngine::SetPythonDictionary(PyObject* pythondictionary)
237 {
238         MT_assert(pythondictionary);
239         m_pythondictionary = pythondictionary;
240 }
241
242
243
244 void KX_KetsjiEngine::SetSceneConverter(KX_ISceneConverter* sceneconverter)
245 {
246         MT_assert(sceneconverter);
247         m_sceneconverter = sceneconverter;
248 }
249
250
251
252 /**
253  * Ketsji Init(), Initializes datastructures and converts data from
254  * Blender into Ketsji native (realtime) format also sets up the
255  * graphics context
256  */
257 void KX_KetsjiEngine::StartEngine(bool clearIpo)
258 {
259         m_clockTime = m_kxsystem->GetTimeInSeconds();
260         m_frameTime = m_kxsystem->GetTimeInSeconds();
261         m_previousClockTime = m_kxsystem->GetTimeInSeconds();
262
263         m_firstframe = true;
264         m_bInitialized = true;
265         m_ticrate = DEFAULT_LOGIC_TIC_RATE;
266         
267         if (m_game2ipo)
268         {
269                 m_sceneconverter->ResetPhysicsObjectsAnimationIpo(clearIpo);
270                 m_sceneconverter->WritePhysicsObjectToAnimationIpo(m_currentFrame);
271         }
272
273 }
274
275 bool KX_KetsjiEngine::BeginFrame()
276 {
277         bool result = false;
278
279         RAS_Rect vp;
280         KX_Scene* firstscene = *m_scenes.begin();
281         const RAS_FrameSettings &framesettings = firstscene->GetFramingType();
282
283         // set the area used for rendering
284         m_rasterizer->SetRenderArea();
285
286         RAS_FramingManager::ComputeViewport(framesettings, m_canvas->GetDisplayArea(), vp);
287
288         if (m_canvas->BeginDraw())
289         {
290                 result = true;
291
292                 m_canvas->SetViewPort(vp.GetLeft(), vp.GetBottom(), vp.GetRight(), vp.GetTop());
293                 SetBackGround( firstscene->GetWorldInfo() );
294                 m_rasterizer->BeginFrame( m_drawingmode , m_kxsystem->GetTimeInSeconds());
295                 m_rendertools->BeginFrame( m_rasterizer);
296         }
297         
298         return result;
299 }               
300
301
302 void KX_KetsjiEngine::EndFrame()
303 {
304         // Show profiling info
305         m_logger->StartLog(tc_overhead, m_kxsystem->GetTimeInSeconds(), true);
306         if (m_show_framerate || m_show_profile || (m_show_debug_properties && m_propertiesPresent))
307         {
308                 RenderDebugProperties();
309         }
310         // Go to next profiling measurement, time spend after this call is shown in the next frame.
311         m_logger->NextMeasurement(m_kxsystem->GetTimeInSeconds());
312
313         m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
314         m_rasterizer->EndFrame();
315         // swap backbuffer (drawing into this buffer) <-> front/visible buffer
316         m_rasterizer->SwapBuffers();
317         m_rendertools->EndFrame(m_rasterizer);
318
319         
320         m_canvas->EndDraw();
321         
322
323 }
324
325 //#include "PIL_time.h"
326 //#include "LinearMath/btQuickprof.h"
327
328
329 bool KX_KetsjiEngine::NextFrame()
330 {
331
332 //      static hidden::Clock sClock;
333
334 m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(),true);
335
336 //float dt = sClock.getTimeMicroseconds() * 0.000001f;
337 //sClock.reset();
338
339 if (m_bFixedTime)
340         m_clockTime += 1./m_ticrate;
341 else
342 {
343
344 //      m_clockTime += dt;
345         m_clockTime = m_kxsystem->GetTimeInSeconds();
346 }
347         
348         double deltatime = m_clockTime - m_frameTime;
349         if (deltatime<0.f)
350         {
351                 printf("problem with clock\n");
352                 deltatime = 0.f;
353                 m_clockTime = 0.f;
354                 m_frameTime = 0.f;
355         }
356
357
358         // Compute the number of logic frames to do each update (fixed tic bricks)
359         int frames =int(deltatime*m_ticrate);
360 //      if (frames>1)
361 //              printf("****************************************");
362 //      printf("dt = %f, deltatime = %f, frames = %d\n",dt, deltatime,frames);
363         
364 //      if (!frames)
365 //              PIL_sleep_ms(1);
366         
367         KX_SceneList::iterator sceneit;
368         int frameOut = 5;
369         
370         if (frames>frameOut)
371         {
372         
373         //      printf("framedOut: %d\n",frames);
374                 m_frameTime+=(frames-frameOut)*(1.0/m_ticrate);
375                 frames = frameOut;
376         }
377         
378
379         bool doRender = frames>0;
380
381         while (frames)
382         {
383         
384
385                 m_frameTime += 1.0/m_ticrate;
386                 
387                 for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
388                 // for each scene, call the proceed functions
389                 {
390                         KX_Scene* scene = *sceneit;
391         
392                         /* Suspension holds the physics and logic processing for an
393                         * entire scene. Objects can be suspended individually, and
394                         * the settings for that preceed the logic and physics
395                         * update. */
396                         m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
397                         scene->UpdateObjectActivity();
398         
399                         if (!scene->IsSuspended())
400                         {
401                                 // if the scene was suspended recalcutlate the delta tu "curtime"
402                                 m_suspendedtime = scene->getSuspendedTime();
403                                 if (scene->getSuspendedTime()!=0.0)
404                                         scene->setSuspendedDelta(scene->getSuspendedDelta()+m_clockTime-scene->getSuspendedTime());
405                                 m_suspendeddelta = scene->getSuspendedDelta();
406
407                                 
408                                 m_logger->StartLog(tc_network, m_kxsystem->GetTimeInSeconds(), true);
409                                 scene->GetNetworkScene()->proceed(m_frameTime);
410         
411                                 m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
412                                 scene->UpdateParents(m_frameTime);
413                                 
414                                 m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
415                                 // set Python hooks for each scene
416                                 PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
417                                 PHY_SetActiveScene(scene);
418         
419                                 scene->GetPhysicsEnvironment()->endFrame();
420                                 
421                                 // Update scenegraph after physics step. This maps physics calculations
422                                 // into node positions.         
423                                 m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
424                                 scene->UpdateParents(m_frameTime);
425                                 
426                                 // Process sensors, and controllers
427                                 m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
428                                 scene->LogicBeginFrame(m_frameTime);
429         
430                                 // Scenegraph needs to be updated again, because Logic Controllers 
431                                 // can affect the local matrices.
432                                 m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
433                                 scene->UpdateParents(m_frameTime);
434         
435                                 // Process actuators
436         
437                                 // Do some cleanup work for this logic frame
438                                 m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
439                                 scene->LogicUpdateFrame(m_frameTime, true);
440                                 
441                                 scene->LogicEndFrame();
442         
443                                 // Actuators can affect the scenegraph
444                                 m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
445                                 scene->UpdateParents(m_frameTime);
446                                 
447                                 m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
448                                 scene->GetPhysicsEnvironment()->beginFrame();
449                 
450                                 // Perform physics calculations on the scene. This can involve 
451                                 // many iterations of the physics solver.
452                                 scene->GetPhysicsEnvironment()->proceedDeltaTime(m_frameTime,1.0/m_ticrate);//m_deltatimerealDeltaTime);
453
454                                 m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
455                                 scene->UpdateParents(m_frameTime);
456                         
457                         
458                                 if (m_game2ipo)
459                                 {
460                                         m_sceneconverter->WritePhysicsObjectToAnimationIpo(++m_currentFrame);
461                                 }
462
463                                 scene->setSuspendedTime(0.0);
464                         } // suspended
465                         else
466                                 if(scene->getSuspendedTime()==0.0)
467                                         scene->setSuspendedTime(m_clockTime);
468         
469                         DoSound(scene);
470                         
471                         m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true);
472                 }
473
474                 // update system devices
475                 m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
476                 if (m_keyboarddevice)
477                         m_keyboarddevice->NextFrame();
478         
479                 if (m_mousedevice)
480                         m_mousedevice->NextFrame();
481                 
482                 if (m_networkdevice)
483                         m_networkdevice->NextFrame();
484         
485                 if (m_audiodevice)
486                         m_audiodevice->NextFrame();
487         
488                 // scene management
489                 ProcessScheduledScenes();
490                 
491                 frames--;
492         }
493
494         bool bUseAsyncLogicBricks= false;//true;
495
496         if (bUseAsyncLogicBricks)
497         {       
498                 // Logic update sub frame: this will let some logic bricks run at the
499                 // full frame rate.
500                 for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
501                 // for each scene, call the proceed functions
502                 {
503                         KX_Scene* scene = *sceneit;
504
505                         if (!scene->IsSuspended())
506                         {
507                                 // if the scene was suspended recalcutlate the delta tu "curtime"
508                                 m_suspendedtime = scene->getSuspendedTime();
509                                 if (scene->getSuspendedTime()!=0.0)
510                                         scene->setSuspendedDelta(scene->getSuspendedDelta()+m_clockTime-scene->getSuspendedTime());
511                                 m_suspendeddelta = scene->getSuspendedDelta();
512                                 
513                                 // set Python hooks for each scene
514                                 PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
515                                 PHY_SetActiveScene(scene);
516                                 
517                                 m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
518                                 scene->UpdateParents(m_clockTime);
519
520                                 // Perform physics calculations on the scene. This can involve 
521                                 // many iterations of the physics solver.
522                                 m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
523                                 scene->GetPhysicsEnvironment()->proceedDeltaTime(m_clockTime,0.f);
524                                 // Update scenegraph after physics step. This maps physics calculations
525                                 // into node positions.         
526                                 m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
527                                 scene->UpdateParents(m_clockTime);
528                                 
529                                 // Do some cleanup work for this logic frame
530                                 m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
531                                 scene->LogicUpdateFrame(m_clockTime, false);
532
533                                 // Actuators can affect the scenegraph
534                                 m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
535                                 scene->UpdateParents(m_clockTime);
536                                  
537                                 scene->setSuspendedTime(0.0);
538                         } // suspended
539                         else
540                                 if(scene->getSuspendedTime()==0.0)
541                                         scene->setSuspendedTime(m_clockTime);
542
543                         DoSound(scene);
544
545                         m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true);
546                 }
547         }
548
549
550         m_previousClockTime = m_clockTime;
551         
552         // Start logging time spend outside main loop
553         m_logger->StartLog(tc_outside, m_kxsystem->GetTimeInSeconds(), true);
554         
555         return doRender;
556 }
557
558
559
560 void KX_KetsjiEngine::Render()
561 {
562         KX_Scene* firstscene = *m_scenes.begin();
563         const RAS_FrameSettings &framesettings = firstscene->GetFramingType();
564
565         m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
566
567         // hiding mouse cursor each frame
568         // (came back when going out of focus and then back in again)
569         if (m_hideCursor)
570                 m_canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
571
572         // clear the entire game screen with the border color
573         // only once per frame
574         m_canvas->BeginDraw();
575         if (m_drawingmode == RAS_IRasterizer::KX_TEXTURED) {
576                 m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight());
577                 if (m_overrideFrameColor)
578                 {
579                         // Do not use the framing bar color set in the Blender scenes
580                         m_canvas->ClearColor(
581                                 m_overrideFrameColorR,
582                                 m_overrideFrameColorG,
583                                 m_overrideFrameColorB,
584                                 1.0
585                                 );
586                 }
587                 else
588                 {
589                         // Use the framing bar color set in the Blender scenes
590                         m_canvas->ClearColor(
591                                 framesettings.BarRed(),
592                                 framesettings.BarGreen(),
593                                 framesettings.BarBlue(),
594                                 1.0
595                                 );
596                 }
597                 // clear the -whole- viewport
598                 m_canvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER);
599         }
600
601         m_rasterizer->SetEye(RAS_IRasterizer::RAS_STEREO_LEFTEYE);
602
603         // BeginFrame() sets the actual drawing area. You can use a part of the window
604         if (!BeginFrame())
605                 return;
606
607         KX_SceneList::iterator sceneit;
608         for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++)
609         // for each scene, call the proceed functions
610         {
611                 KX_Scene* scene = *sceneit;
612                 KX_Camera* cam = scene->GetActiveCamera();
613                 // pass the scene's worldsettings to the rasterizer
614                 SetWorldSettings(scene->GetWorldInfo());
615
616                 // Avoid drawing the scene with the active camera twice when it's viewport is enabled
617                 if(!cam->GetViewport())
618                 {
619                         if (scene->IsClearingZBuffer())
620                                 m_rasterizer->ClearDepthBuffer();
621         
622                         m_rendertools->SetAuxilaryClientInfo(scene);
623         
624                         //Initialize scene viewport.
625                         SetupRenderFrame(scene, cam);
626         
627                         // do the rendering
628                         RenderFrame(scene, cam);
629                 }
630                 
631                 set<class KX_Camera*>* cameras = scene->GetCameras();
632                 
633                 // Draw the scene once for each camera with an enabled viewport
634                 set<KX_Camera*>::iterator it = cameras->begin();
635                 while(it != cameras->end())
636                 {
637                         if((*it)->GetViewport())
638                         {
639                                 if (scene->IsClearingZBuffer())
640                                         m_rasterizer->ClearDepthBuffer();
641                 
642                                 m_rendertools->SetAuxilaryClientInfo(scene);
643                 
644                                 //Initialize scene viewport.
645                                 SetupRenderFrame(scene, (*it));
646                 
647                                 // do the rendering
648                                 RenderFrame(scene, (*it));
649                         }
650                         
651                         it++;
652                 }
653         }
654
655         // only one place that checks for stereo
656         if(m_rasterizer->Stereo())
657         {
658                 m_rasterizer->SetEye(RAS_IRasterizer::RAS_STEREO_RIGHTEYE);
659
660                 if (!BeginFrame())
661                         return;
662
663                 KX_SceneList::iterator sceneit;
664                 for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++)
665                 // for each scene, call the proceed functions
666                 {
667                         KX_Scene* scene = *sceneit;
668                         KX_Camera* cam = scene->GetActiveCamera();
669
670                         // pass the scene's worldsettings to the rasterizer
671                         SetWorldSettings(scene->GetWorldInfo());
672                 
673                         if (scene->IsClearingZBuffer())
674                                 m_rasterizer->ClearDepthBuffer();
675
676                         //pass the scene, for picking and raycasting (shadows)
677                         m_rendertools->SetAuxilaryClientInfo(scene);
678
679                         //Initialize scene viewport.
680                         //SetupRenderFrame(scene);
681                         SetupRenderFrame(scene, cam);
682
683                         // do the rendering
684                         //RenderFrame(scene);
685                         RenderFrame(scene, cam);
686                 }
687         } // if(m_rasterizer->Stereo())
688
689         EndFrame();
690 }
691
692
693
694 void KX_KetsjiEngine::RequestExit(int exitrequestmode)
695 {
696         m_exitcode = exitrequestmode;
697 }
698
699
700
701 void KX_KetsjiEngine::SetNameNextGame(const STR_String& nextgame)
702 {
703         m_exitstring = nextgame;
704 }
705
706
707
708 int KX_KetsjiEngine::GetExitCode()
709 {
710         // if a gameactuator has set an exitcode or if there are no scenes left
711         if (!m_exitcode)
712         {
713                 if (m_scenes.begin()==m_scenes.end())
714                         m_exitcode = KX_EXIT_REQUEST_NO_SCENES_LEFT;
715         }
716
717         return m_exitcode;
718 }
719
720
721
722 const STR_String& KX_KetsjiEngine::GetExitString()
723 {
724         return m_exitstring;
725 }
726
727
728
729 void KX_KetsjiEngine::DoSound(KX_Scene* scene)
730 {
731         m_logger->StartLog(tc_sound, m_kxsystem->GetTimeInSeconds(), true);
732
733         KX_Camera* cam = scene->GetActiveCamera();
734         if (!cam)
735                 return;
736         MT_Point3 listenerposition = cam->NodeGetWorldPosition();
737         MT_Vector3 listenervelocity = cam->GetLinearVelocity();
738         MT_Matrix3x3 listenerorientation = cam->NodeGetWorldOrientation();
739
740         SND_Scene* soundscene = scene->GetSoundScene();
741         soundscene->SetListenerTransform(
742                 listenerposition,
743                 listenervelocity,
744                 listenerorientation);
745
746         soundscene->Proceed();
747 }
748
749
750
751 void KX_KetsjiEngine::SetBackGround(KX_WorldInfo* wi)
752 {
753         if (wi->hasWorld())
754         {
755                 if (m_drawingmode == RAS_IRasterizer::KX_TEXTURED)
756                 {       
757                         m_rasterizer->SetBackColor(
758                                 wi->getBackColorRed(),
759                                 wi->getBackColorGreen(),
760                                 wi->getBackColorBlue(),
761                                 0.0
762                         );
763                 }
764         }
765 }
766
767
768
769 void KX_KetsjiEngine::SetWorldSettings(KX_WorldInfo* wi)
770 {
771         if (wi->hasWorld())
772         {
773                 // ...
774                 m_rasterizer->SetAmbientColor(
775                         wi->getAmbientColorRed(),
776                         wi->getAmbientColorGreen(),
777                         wi->getAmbientColorBlue()
778                 );
779
780                 if (m_drawingmode == RAS_IRasterizer::KX_TEXTURED)
781                 {       
782                         if (wi->hasMist())
783                         {
784                                 m_rasterizer->SetFog(
785                                         wi->getMistStart(),
786                                         wi->getMistDistance(),
787                                         wi->getMistColorRed(),
788                                         wi->getMistColorGreen(),
789                                         wi->getMistColorBlue()
790                                 );
791                         }
792                         else
793                         {
794                                 m_rasterizer->DisableFog();
795                         }
796                 }
797         }
798 }
799
800
801
802 void KX_KetsjiEngine::SetDrawType(int drawingmode)
803 {
804         m_drawingmode = drawingmode;
805 }
806
807
808         
809 void KX_KetsjiEngine::EnableCameraOverride(const STR_String& forscene)
810 {
811         m_overrideCam = true;
812         m_overrideSceneName = forscene;
813 }
814
815
816
817 void KX_KetsjiEngine::SetCameraZoom(float camzoom)
818 {
819         m_cameraZoom = camzoom;
820 }
821
822
823
824 void KX_KetsjiEngine::SetCameraOverrideUseOrtho(bool useOrtho)
825 {
826         m_overrideCamUseOrtho = useOrtho;
827 }
828
829
830
831 void KX_KetsjiEngine::SetCameraOverrideProjectionMatrix(const MT_CmMatrix4x4& mat)
832 {
833         m_overrideCamProjMat = mat;
834 }
835
836
837 void KX_KetsjiEngine::SetCameraOverrideViewMatrix(const MT_CmMatrix4x4& mat)
838 {
839         m_overrideCamViewMat = mat;
840 }
841
842         
843 void KX_KetsjiEngine::SetupRenderFrame(KX_Scene *scene, KX_Camera* cam)
844 {
845         // In this function we make sure the rasterizer settings are upto
846         // date. We compute the viewport so that logic
847         // using this information is upto date.
848
849         // Note we postpone computation of the projection matrix
850         // so that we are using the latest camera position.
851
852         RAS_Rect viewport;
853
854         if (cam->GetViewport()) {
855                 viewport.SetLeft(cam->GetViewportLeft()); 
856                 viewport.SetBottom(cam->GetViewportBottom());
857                 viewport.SetRight(cam->GetViewportRight());
858                 viewport.SetTop(cam->GetViewportTop());
859         }
860         else if ( m_overrideCam || (scene->GetName() != m_overrideSceneName) ||  m_overrideCamUseOrtho ) {
861                 RAS_FramingManager::ComputeViewport(
862                         scene->GetFramingType(),
863                         m_canvas->GetDisplayArea(),
864                         viewport
865                 );
866         } else {
867                 viewport.SetLeft(0); 
868                 viewport.SetBottom(0);
869                 viewport.SetRight(int(m_canvas->GetWidth()));
870                 viewport.SetTop(int(m_canvas->GetHeight()));
871         }
872         // store the computed viewport in the scene
873
874         scene->SetSceneViewport(viewport);      
875
876         // set the viewport for this frame and scene
877         m_canvas->SetViewPort(
878                 viewport.GetLeft(),
879                 viewport.GetBottom(),
880                 viewport.GetRight(),
881                 viewport.GetTop()
882         );      
883
884 }               
885
886         
887 // update graphics
888 void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam)
889 {
890         float left, right, bottom, top, nearfrust, farfrust;
891         const float ortho = 100.0;
892 //      KX_Camera* cam = scene->GetActiveCamera();
893         
894         if (!cam)
895                 return;
896         
897         // see KX_BlenderMaterial::Activate
898         //m_rasterizer->SetAmbient();
899         m_rasterizer->DisplayFog();
900
901         if (m_overrideCam && (scene->GetName() == m_overrideSceneName) && m_overrideCamUseOrtho) {
902                 MT_CmMatrix4x4 projmat = m_overrideCamProjMat;
903                 m_rasterizer->SetProjectionMatrix(projmat);
904         } else if (cam->hasValidProjectionMatrix() && !cam->GetViewport() )
905         {
906                 m_rasterizer->SetProjectionMatrix(cam->GetProjectionMatrix());
907         } else
908         {
909                 RAS_FrameFrustum frustum;
910                 float lens = cam->GetLens();
911                 nearfrust = cam->GetCameraNear();
912                 farfrust = cam->GetCameraFar();
913
914                 if (!cam->GetCameraData()->m_perspective)
915                 {
916                         lens *= ortho;
917                         nearfrust = (nearfrust + 1.0)*ortho;
918                         farfrust *= ortho;
919                 }
920                 
921                 RAS_FramingManager::ComputeFrustum(
922                         scene->GetFramingType(),
923                         m_canvas->GetDisplayArea(),
924                         scene->GetSceneViewport(),
925                         lens,
926                         nearfrust,
927                         farfrust,
928                         frustum
929                 );
930
931                 left = frustum.x1 * m_cameraZoom;
932                 right = frustum.x2 * m_cameraZoom;
933                 bottom = frustum.y1 * m_cameraZoom;
934                 top = frustum.y2 * m_cameraZoom;
935                 nearfrust = frustum.camnear;
936                 farfrust = frustum.camfar;
937
938                 MT_Matrix4x4 projmat = m_rasterizer->GetFrustumMatrix(
939                         left, right, bottom, top, nearfrust, farfrust);
940         
941                 cam->SetProjectionMatrix(projmat);
942                 
943                 // Otherwise the projection matrix for each eye will be the same...
944                 if (m_rasterizer->Stereo())
945                         cam->InvalidateProjectionMatrix();
946         }
947
948         MT_Transform camtrans(cam->GetWorldToCamera());
949         if (!cam->GetCameraData()->m_perspective)
950                 camtrans.getOrigin()[2] *= ortho;
951         MT_Matrix4x4 viewmat(camtrans);
952         
953         m_rasterizer->SetViewMatrix(viewmat, cam->NodeGetWorldPosition(),
954                 cam->GetCameraLocation(), cam->GetCameraOrientation());
955         cam->SetModelviewMatrix(viewmat);
956
957         scene->UpdateMeshTransformations();
958
959         // The following actually reschedules all vertices to be
960         // redrawn. There is a cache between the actual rescheduling
961         // and this call though. Visibility is imparted when this call
962         // runs through the individual objects.
963         scene->CalculateVisibleMeshes(m_rasterizer,cam);
964
965         scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
966 }
967
968
969
970 void KX_KetsjiEngine::StopEngine()
971 {
972         if (m_bInitialized)
973         {
974
975                 if (m_game2ipo)
976                 {
977 //                      printf("TestHandlesPhysicsObjectToAnimationIpo\n");
978                         m_sceneconverter->TestHandlesPhysicsObjectToAnimationIpo();
979                 }
980
981                 KX_SceneList::iterator sceneit;
982                 for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
983                 {
984                         KX_Scene* scene = *sceneit;
985                         delete scene;
986                 }       
987                 m_scenes.clear();
988
989                 // cleanup all the stuff                
990                 m_rasterizer->Exit();
991         }
992 }
993
994 // Scene Management is able to switch between scenes
995 // and have several scene's running in parallel
996 void KX_KetsjiEngine::AddScene(KX_Scene* scene)
997
998         m_scenes.push_back(scene);
999         PostProcessScene(scene);
1000         SceneListsChanged();
1001 }
1002
1003
1004
1005 void KX_KetsjiEngine::PostProcessScene(KX_Scene* scene)
1006 {
1007         bool override_camera = (m_overrideCam && (scene->GetName() == m_overrideSceneName));
1008         
1009                 // if there is no activecamera, or the camera is being
1010                 // overridden we need to construct a temporarily camera
1011         if (!scene->GetActiveCamera() || override_camera)
1012         {
1013                 KX_Camera* activecam = NULL;
1014
1015                 RAS_CameraData camdata = RAS_CameraData();
1016                 activecam = new KX_Camera(scene,KX_Scene::m_callbacks,camdata, false);
1017                 activecam->SetName("__default__cam__");
1018         
1019                         // set transformation
1020                 if (override_camera) {
1021                         const MT_CmMatrix4x4& cammatdata = m_overrideCamViewMat;
1022                         MT_Transform trans = MT_Transform(cammatdata.getPointer());
1023                         MT_Transform camtrans;
1024                         camtrans.invert(trans);
1025                         
1026                         activecam->NodeSetLocalPosition(camtrans.getOrigin());
1027                         activecam->NodeSetLocalOrientation(camtrans.getBasis());
1028                         activecam->NodeUpdateGS(0,true);
1029                 } else {
1030                         activecam->NodeSetLocalPosition(MT_Point3(0.0, 0.0, 0.0));
1031                         activecam->NodeSetLocalOrientation(MT_Vector3(0.0, 0.0, 0.0));
1032                         activecam->NodeUpdateGS(0,true);
1033                 }
1034
1035                 scene->AddCamera(activecam);
1036                 scene->SetActiveCamera(activecam);
1037                 scene->GetObjectList()->Add(activecam->AddRef());
1038                 scene->GetRootParentList()->Add(activecam->AddRef());
1039         }
1040         
1041         scene->UpdateParents(0.0);
1042 }
1043
1044
1045
1046 void KX_KetsjiEngine::RenderDebugProperties()
1047 {
1048         STR_String debugtxt;
1049         int xcoord = 10;        // mmmm, these constants were taken from blender source
1050         int ycoord = 14;        // to 'mimic' behaviour
1051
1052         float tottime = m_logger->GetAverage();
1053         if (tottime < 1e-6f) {
1054                 tottime = 1e-6f;
1055         }
1056
1057         // Set viewport to entire canvas
1058         RAS_Rect viewport;
1059         m_canvas->SetViewPort(0, 0, int(m_canvas->GetWidth()), int(m_canvas->GetHeight()));
1060         
1061         /* Framerate display */
1062         if (m_show_framerate) {
1063                 debugtxt.Format("swap : %.3f (%.3f frames per second)", tottime, 1.0/tottime);
1064                 m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, 
1065                                                                         debugtxt.Ptr(),
1066                                                                         xcoord,
1067                                                                         ycoord, 
1068                                                                         m_canvas->GetWidth() /* RdV, TODO ?? */, 
1069                                                                         m_canvas->GetHeight() /* RdV, TODO ?? */);
1070                 ycoord += 14;
1071         }
1072
1073         /* Profile and framerate display */
1074         if (m_show_profile)
1075         {               
1076                 for (int j = tc_first; j < tc_numCategories; j++)
1077                 {
1078                         debugtxt.Format(m_profileLabels[j]);
1079                         m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, 
1080                                                                                 debugtxt.Ptr(),
1081                                                                                 xcoord,ycoord,
1082                                                                                 m_canvas->GetWidth(), 
1083                                                                                 m_canvas->GetHeight());
1084                         double time = m_logger->GetAverage((KX_TimeCategory)j);
1085                         debugtxt.Format("%2.2f %%", time/tottime * 100.f);
1086                         m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, 
1087                                                                                 debugtxt.Ptr(),
1088                                                                                 xcoord + 60 ,ycoord,
1089                                                                                 m_canvas->GetWidth(), 
1090                                                                                 m_canvas->GetHeight());
1091                         ycoord += 14;
1092                 }
1093         }
1094
1095         /* Property display*/
1096         if (m_show_debug_properties && m_propertiesPresent)
1097         {
1098                 KX_SceneList::iterator sceneit;
1099                 for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
1100                 {
1101                         KX_Scene* scene = *sceneit;
1102                         /* the 'normal' debug props */
1103                         vector<SCA_DebugProp*>& debugproplist = scene->GetDebugProperties();
1104                         
1105                         for (vector<SCA_DebugProp*>::iterator it = debugproplist.begin();
1106                                  !(it==debugproplist.end());it++)
1107                         {
1108                                 CValue* propobj = (*it)->m_obj;
1109                                 STR_String objname = propobj->GetName();
1110                                 STR_String propname = (*it)->m_name;
1111                                 CValue* propval = propobj->GetProperty(propname);
1112                                 if (propval)
1113                                 {
1114                                         STR_String text = propval->GetText();
1115                                         debugtxt = objname + "." + propname + " = " + text;
1116                                         m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, 
1117                                                                                                 debugtxt.Ptr(),
1118                                                                                                 xcoord,
1119                                                                                                 ycoord,
1120                                                                                                 m_canvas->GetWidth(),
1121                                                                                                 m_canvas->GetHeight());
1122                                         ycoord += 14;
1123                                 }
1124                         }
1125                 }
1126         }
1127 }
1128
1129
1130 KX_SceneList* KX_KetsjiEngine::CurrentScenes()
1131 {
1132         return &m_scenes;       
1133 }
1134
1135
1136
1137 KX_Scene* KX_KetsjiEngine::FindScene(const STR_String& scenename)
1138 {
1139         KX_SceneList::iterator sceneit = m_scenes.begin();
1140
1141         // bit risky :) better to split the second clause 
1142         while ( (sceneit != m_scenes.end()) 
1143                         && ((*sceneit)->GetName() != scenename))
1144         {
1145                 sceneit++;
1146         }
1147
1148         return ((sceneit == m_scenes.end()) ? NULL : *sceneit); 
1149 }
1150
1151
1152
1153 void KX_KetsjiEngine::ConvertAndAddScene(const STR_String& scenename,bool overlay)
1154 {
1155         // only add scene when it doesn't exist!
1156         if (FindScene(scenename))
1157         {
1158                 STR_String tmpname = scenename;
1159                 printf("warning: scene %s already exists, not added!\n",tmpname.Ptr());
1160         }
1161         else
1162         {
1163                 if (overlay)
1164                 {
1165                         m_addingOverlayScenes.insert(scenename);
1166                 }
1167                 else
1168                 {
1169                         m_addingBackgroundScenes.insert(scenename);
1170                 }
1171         }
1172 }
1173
1174
1175
1176
1177 void KX_KetsjiEngine::RemoveScene(const STR_String& scenename)
1178 {
1179         if (FindScene(scenename))
1180         {
1181                 m_removingScenes.insert(scenename);
1182         }
1183         else
1184         {
1185 //              STR_String tmpname = scenename;
1186                 std::cout << "warning: scene " << scenename << " does not exist, not removed!" << std::endl;
1187         }
1188 }
1189
1190
1191
1192 void KX_KetsjiEngine::RemoveScheduledScenes()
1193 {
1194         if (m_removingScenes.size())
1195         {
1196                 set<STR_String>::iterator scenenameit;
1197                 for (scenenameit=m_removingScenes.begin();scenenameit != m_removingScenes.end();scenenameit++)
1198                 {
1199                         STR_String scenename = *scenenameit;
1200
1201                         KX_SceneList::iterator sceneit;
1202                         for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
1203                         {
1204                                 KX_Scene* scene = *sceneit;
1205                                 if (scene->GetName()==scenename)
1206                                 {
1207                                         delete scene;
1208                                         m_scenes.erase(sceneit);
1209                                         break;
1210                                 }
1211                         }       
1212                 }
1213                 m_removingScenes.clear();
1214         }
1215 }
1216
1217
1218
1219 KX_Scene* KX_KetsjiEngine::CreateScene(const STR_String& scenename)
1220 {
1221
1222         KX_Scene* tmpscene = new KX_Scene(m_keyboarddevice,
1223                                                                           m_mousedevice,
1224                                                                           m_networkdevice,
1225                                                                           m_audiodevice,
1226                                                                           scenename);
1227
1228         m_sceneconverter->ConvertScene(scenename,
1229                                                           tmpscene,
1230                                                           m_pythondictionary,
1231                                                           m_keyboarddevice,
1232                                                           m_rendertools,
1233                                                           m_canvas);
1234
1235         return tmpscene;
1236 }
1237
1238
1239
1240 void KX_KetsjiEngine::AddScheduledScenes()
1241 {
1242         set<STR_String>::iterator scenenameit;
1243
1244         if (m_addingOverlayScenes.size())
1245         {
1246                 for (scenenameit = m_addingOverlayScenes.begin();
1247                         scenenameit != m_addingOverlayScenes.end();
1248                         scenenameit++)
1249                 {
1250                         STR_String scenename = *scenenameit;
1251                         KX_Scene* tmpscene = CreateScene(scenename);
1252                         m_scenes.push_back(tmpscene);
1253                         PostProcessScene(tmpscene);
1254                 }
1255                 m_addingOverlayScenes.clear();
1256         }
1257         
1258         if (m_addingBackgroundScenes.size())
1259         {
1260                 for (scenenameit = m_addingBackgroundScenes.begin();
1261                         scenenameit != m_addingBackgroundScenes.end();
1262                         scenenameit++)
1263                 {
1264                         STR_String scenename = *scenenameit;
1265                         KX_Scene* tmpscene = CreateScene(scenename);
1266                         m_scenes.insert(m_scenes.begin(),tmpscene);
1267                         PostProcessScene(tmpscene);
1268
1269                 }
1270                 m_addingBackgroundScenes.clear();
1271         }
1272 }
1273
1274
1275
1276 void KX_KetsjiEngine::ReplaceScene(const STR_String& oldscene,const STR_String& newscene)
1277 {
1278         m_replace_scenes.insert(std::make_pair(oldscene,newscene));
1279 }
1280
1281 // replace scene is not the same as removing and adding because the
1282 // scene must be in exact the same place (to maintain drawingorder)
1283 // (nzc) - should that not be done with a scene-display list? It seems
1284 // stupid to rely on the mem allocation order...
1285 void KX_KetsjiEngine::ReplaceScheduledScenes()
1286 {
1287         if (m_replace_scenes.size())
1288         {
1289                 set<pair<STR_String,STR_String> >::iterator scenenameit;
1290                 
1291                 for (scenenameit = m_replace_scenes.begin();
1292                         scenenameit != m_replace_scenes.end();
1293                         scenenameit++)
1294                 {
1295                         STR_String oldscenename = (*scenenameit).first;
1296                         STR_String newscenename = (*scenenameit).second;
1297                         int i=0;
1298                         /* Scenes are not supposed to be included twice... I think */
1299                         KX_SceneList::iterator sceneit;
1300                         for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
1301                         {
1302                                 KX_Scene* scene = *sceneit;
1303                                 if (scene->GetName() == oldscenename)
1304                                 {
1305                                         delete scene;
1306                                         KX_Scene* tmpscene = CreateScene(newscenename);
1307                                         m_scenes[i]=tmpscene;
1308                                         PostProcessScene(tmpscene);
1309                                 }
1310                                 i++;
1311                         }
1312                 }
1313                 m_replace_scenes.clear();
1314         }       
1315 }
1316
1317
1318
1319 void KX_KetsjiEngine::SuspendScene(const STR_String& scenename)
1320 {
1321         KX_Scene*  scene = FindScene(scenename);
1322         if (scene) scene->Suspend();
1323 }
1324
1325
1326
1327 void KX_KetsjiEngine::ResumeScene(const STR_String& scenename)
1328 {
1329         KX_Scene*  scene = FindScene(scenename);
1330         if (scene) scene->Resume();
1331 }
1332
1333
1334
1335 void KX_KetsjiEngine::SetUseFixedTime(bool bUseFixedTime)
1336 {
1337         m_bFixedTime = bUseFixedTime;
1338 }
1339
1340
1341 void    KX_KetsjiEngine::SetGame2IpoMode(bool game2ipo,int startFrame)
1342 {
1343         m_game2ipo = game2ipo;
1344         if (game2ipo)
1345         {
1346                 //when recording physics keyframes, always run at a fixed framerate
1347                 m_bFixedTime = true;
1348         }
1349         m_currentFrame = startFrame;
1350 }
1351
1352 bool KX_KetsjiEngine::GetUseFixedTime(void) const
1353 {
1354         return m_bFixedTime;
1355 }
1356
1357 double KX_KetsjiEngine::GetSuspendedDelta()
1358 {
1359         return m_suspendeddelta;
1360 }
1361
1362 double KX_KetsjiEngine::GetTicRate()
1363 {
1364         return m_ticrate;
1365 }
1366
1367 void KX_KetsjiEngine::SetTicRate(double ticrate)
1368 {
1369         m_ticrate = ticrate;
1370 }
1371
1372 void KX_KetsjiEngine::SetTimingDisplay(bool frameRate, bool profile, bool properties)
1373 {
1374         m_show_framerate = frameRate;
1375         m_show_profile = profile;
1376         m_show_debug_properties = properties;
1377 }
1378
1379
1380
1381 void KX_KetsjiEngine::GetTimingDisplay(bool& frameRate, bool& profile, bool& properties) const
1382 {
1383         frameRate = m_show_framerate;
1384         profile = m_show_profile;
1385         properties = m_show_debug_properties;
1386 }
1387
1388
1389
1390 void KX_KetsjiEngine::ProcessScheduledScenes(void)
1391 {
1392         // Check whether there will be changes to the list of scenes
1393         if (m_addingOverlayScenes.size() ||
1394                 m_addingBackgroundScenes.size() ||
1395                 m_replace_scenes.size() ||
1396                 m_removingScenes.size()) {
1397
1398                 // Change the scene list
1399                 ReplaceScheduledScenes();
1400                 RemoveScheduledScenes();
1401                 AddScheduledScenes();
1402
1403                 // Notify
1404                 SceneListsChanged();
1405         }
1406 }
1407
1408
1409
1410 void KX_KetsjiEngine::SceneListsChanged(void)
1411 {
1412         m_propertiesPresent = false;
1413         KX_SceneList::iterator sceneit = m_scenes.begin();
1414         while ((sceneit != m_scenes.end()) && (!m_propertiesPresent))
1415         {
1416                 KX_Scene* scene = *sceneit;
1417                 vector<SCA_DebugProp*>& debugproplist = scene->GetDebugProperties();    
1418                 m_propertiesPresent = !debugproplist.empty();
1419                 sceneit++;
1420         }
1421 }
1422
1423
1424 void KX_KetsjiEngine::SetHideCursor(bool hideCursor)
1425 {
1426         m_hideCursor = hideCursor;
1427 }
1428
1429
1430 bool KX_KetsjiEngine::GetHideCursor(void) const
1431 {
1432         return m_hideCursor;
1433 }
1434
1435
1436 void KX_KetsjiEngine::SetUseOverrideFrameColor(bool overrideFrameColor)
1437 {
1438         m_overrideFrameColor = overrideFrameColor;
1439 }
1440
1441
1442 bool KX_KetsjiEngine::GetUseOverrideFrameColor(void) const
1443 {
1444         return m_overrideFrameColor;
1445 }
1446
1447
1448 void KX_KetsjiEngine::SetOverrideFrameColor(float r, float g, float b)
1449 {
1450         m_overrideFrameColorR = r;
1451         m_overrideFrameColorG = g;
1452         m_overrideFrameColorB = b;
1453 }
1454
1455
1456 void KX_KetsjiEngine::GetOverrideFrameColor(float& r, float& g, float& b) const
1457 {
1458         r = m_overrideFrameColorR;
1459         g = m_overrideFrameColorG;
1460         b = m_overrideFrameColorB;
1461 }
1462