Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

KX_BlenderSystem.cpp

Go to the documentation of this file.
00001 
00002 #pragma warning (disable :4786)
00003 
00004 #include "SCA_ISystem.h"
00005 
00006 #ifdef WIN32
00007 #include <windows.h>
00008 #endif //WIN32
00009 
00010 
00011 #if !defined __BEOS__ && !defined WIN32
00012 /* patch voor struct Object */
00013 #define _XtObject_h
00014 #include <X11/Xlib.h>
00015 #include <X11/StringDefs.h>
00016 #include <X11/keysym.h>  
00017 /*#include <GL/glx.h>  */
00018 #endif
00019 
00020 #include <iostream>
00021 #include <stdio.h>
00022 #include "KX_BlenderDevice.h"
00023 #include "KX_BlenderInputDevice.h"
00024 #include "KX_BlenderSystem.h"
00025 
00026 void KX_BlenderSystem::Sleep(int millisec)

00027 {
00028         BL_usleep(millisec);
00029 }
00030 
00031 SCA_ISystem* NewKX_System()

00032 {
00033         return new KX_BlenderSystem();
00034 }
00035 
00036 void KX_BlenderSystem::StartMainLoop()

00037 {
00038         // here the looping is done
00039         while (!m_exitrequested)
00040         {
00041                 DoMainLoopCallback();
00042         }
00043 }
00044 
00045 void KX_BlenderSystem::NextFrame()

00046 {
00047         std::vector<SCA_IInputDevice*>::iterator idev;
00048         for (idev = m_inputDevices.begin();!(idev == m_inputDevices.end());idev++) {
00049                         (*idev)->NextFrame();
00050         }
00051                 
00052 
00053         while (BL_qtest()) 
00054         {
00055         
00056                 short val; 
00057                 unsigned short BLevent;    // extracted from Blender!
00058 
00059 
00060                 BL_UpdateKeyboard(BLevent,val);
00061                 
00062 
00063                 for (idev = m_inputDevices.begin();!(idev == m_inputDevices.end());idev++) {
00064                         if ( ((BL_BlenderInputDevice*) *idev)->ConvertBlenderEvent(BLevent,val))
00065                         {
00066                                 m_exitrequested=true;
00067                         }
00068                         
00069                 }
00070         }
00071         
00072 } /* end of KX_BlenderSystem::NextFrame() */
00073 
00074 
00075 double KX_BlenderSystem::GetTimeInSeconds()
00076 #ifndef WIN32
00077 
00078 {
00079         int curtime = blender_timer();
00080         double result = 0.;
00081         if (curtime <= m_starttime)
00082         {
00083                 // something is wrong, time is not proceeding or even going back ?!
00084 
00085         } else
00086         {
00087                 result = (curtime - m_starttime)/100.0;
00088         }
00089 
00090 
00091         return result;
00092 }
00093 #else //WIN32
00094 
00095 
00096 
00097 {
00098 //03/20/1999 Thomas Hieber: completely redone to get true Millisecond 
00099   //accuracy instead of very rough ticks. This routine will also provide
00100   //correct wrap around at the end of "long"
00101 #if defined(__CYGWIN32__)
00102 #       define __int64 long long
00103 #endif
00104 
00105   static __int64 Freq      = 0;
00106   static __int64 LastCount = 0;
00107   static __int64 LastRest  = 0;
00108   static long    LastTime  = 0;
00109 
00110   //Freq was set to -1, if the current Hardware does not support 
00111   //high resolution timers. We will use GetTickCount instead then.
00112   if (Freq < 0)
00113   {
00114     return GetTickCount();
00115   }
00116 
00117   //Freq is 0, the first time this function is being called.
00118   if (Freq == 0)
00119   {
00120     //try to determine the frequency of the high resulution timer
00121     if (!QueryPerformanceFrequency((LARGE_INTEGER*)&Freq))
00122     {
00123       //There is no such timer....
00124       Freq=-1;
00125       return 0;//Time();
00126     }
00127   }
00128 
00129   //retrieve current count
00130   __int64 Count = 0;
00131   QueryPerformanceCounter((LARGE_INTEGER*)&Count);
00132   
00133   //calculate the time passed since last call, and add the rest of
00134   //those tics that didn't make it into the last reported time.
00135   __int64 Delta = 1000*(Count-LastCount)+LastRest;
00136 
00137   LastTime += (long)(Delta/Freq); //save the new value
00138   LastRest  = Delta%Freq;         //save those ticks not being counted
00139   LastCount = Count;              //save last count
00140 
00141   return LastTime/1000.0; //return a high quality measurement of time. 
00142   }
00143 #endif //WIN32

Generated at Thu Feb 1 13:03:04 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000