rSysDep Class Reference

#include <rSysdep.h>

List of all members.

Public Types

enum  rSwapMode { rSwap_Fastest = 0, rSwap_glFlush = 1, rSwap_glFinish = 2 }

Static Public Member Functions

static bool InitGL ()
static void ExitGL ()
static void SwapGL ()
static void ClearGL ()
static void StartNetSyncThread (rNetIdler *idler)
static void StopNetSyncThread ()

Static Public Attributes

static rSwapMode swapMode_ = rSysDep::rSwap_glFlush

Classes

class  rNetIdler


Detailed Description

Definition at line 31 of file rSysdep.h.


Member Enumeration Documentation

enum rSysDep::rSwapMode

Enumerator:
rSwap_Fastest 
rSwap_glFlush 
rSwap_glFinish 

Definition at line 34 of file rSysdep.h.

00035     {
00036         rSwap_Fastest = 0,
00037         rSwap_glFlush = 1,
00038         rSwap_glFinish = 2
00039                          /*
00040                                  rSwap_150Hz = 5,
00041                                  rSwap_100Hz = 7,
00042                                  rSwap_80Hz  = 9,
00043                                  rSwap_60Hz  = 11
00044                          */
00045     };


Member Function Documentation

bool rSysDep::InitGL (  )  [static]

Definition at line 102 of file rSysdep.cpp.

References rScreenSettings::colorDepth, currentScreensetting, and NULL.

Referenced by lowlevel_sr_InitDisplay().

00102                                       :
00103 bool  rSysDep::InitGL(){
00104     SDL_SysWMinfo system;
00105     SDL_VERSION(&system.version);
00106     if (!SDL_GetWMInfo(&system)){
00107         std::cerr << "Video information not available!\n";
00108         return(false);
00109     }
00110 
00111     /*
00112     con << "SDL version: " << (int)system.version.major
00113          << "." <<  (int)system.version.minor << "." <<  (int)system.version.patch << '\n';
00114     */
00115 
00116     /*
00117     //#ifdef HAVE_FXMESA
00118     if(!ctx){
00119       int x=fxQueryHardware();
00120       if(x){
00121         std::cerr << "No 3Dfx hardware available.\n" << x << '\n';
00122         return(false);
00123       }
00124 
00125       GLint attribs[]={FXMESA_DOUBLEBUFFER,FXMESA_DEPTH_SIZE,16,FXMESA_NONE};
00126       ctx=fxMesaCreateBestContext(0,sr_screenWidth,sr_screenHeight,attribs);
00127 
00128       if (!ctx){
00129         std::cerr << "Could not create FX rendering context!\n";
00130         return(false);
00131       }
00132 
00133       fxMesaMakeCurrent(ctx);
00134     }
00135     */
00136 #ifdef WIN32
00137     // windows GL initialisation stolen from
00138     // http://www.geocities.com/SiliconValley/Code/1219/opengl32.html
00139 
00140     if (!hRC){
00141         HWND hWnd=system.window;
00142 
00143         PIXELFORMATDESCRIPTOR pfd;
00144         int iFormat;
00145 
00146         // get the device context (DC)
00147         hDC = GetDC( hWnd );
00148         if (!hDC) return false;
00149 
00150         // set the pixel format for the DC
00151         ZeroMemory( &pfd, sizeof( pfd ) );
00152         pfd.nSize = sizeof( pfd );
00153         pfd.nVersion = 1;
00154         pfd.dwFlags = PFD_DRAW_TO_WINDOW |
00155                       PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
00156         pfd.iPixelType = PFD_TYPE_RGBA;
00157         pfd.cColorBits = currentScreensetting.colorDepth ? 24 : 16;
00158         pfd.cDepthBits = 16;
00159         pfd.iLayerType = PFD_MAIN_PLANE;
00160         iFormat = ChoosePixelFormat( hDC, &pfd );
00161         SetPixelFormat( hDC, iFormat, &pfd );
00162 
00163         // create and enable the render context (RC)
00164         hRC = wglCreateContext( hDC );
00165         if (!hRC || !wglMakeCurrent( hDC, hRC ))
00166             return false;
00167     }
00168 
00169 #elif defined(unix) || defined(__unix__)
00170     if (system.subsystem!=SDL_SYSWM_X11){
00171         std::cerr << "System is not X11!\n";
00172         std::cerr << (int)system.subsystem << "!=" << (int)SDL_SYSWM_X11 <<'\n';
00173         return false;
00174     }
00175 
00176     if (!dpy){
00177 
00178         dpy=system.info.x11.display;
00179         win=system.info.x11.window;
00180 
00181         int errorbase,tEventbase;
00182         if (glXQueryExtension(dpy,&errorbase,&tEventbase) == False){
00183             std::cerr << "OpenGL through GLX not supported.\n";
00184             return false;
00185         }
00186 
00187         int configuration[]={GLX_DOUBLEBUFFER,GLX_RGBA,GLX_DEPTH_SIZE ,12, GLX_RED_SIZE,1,
00188                              GLX_BLUE_SIZE,1,GLX_GREEN_SIZE,1,None
00189                             };
00190 
00191         XVisualInfo *vi=glXChooseVisual(dpy,DefaultScreen(dpy),configuration);
00192 
00193         if (vi== NULL){
00194             std::cerr << "Could not initialize Visual.\n";
00195             return false;
00196         }
00197 
00198         cx=glXCreateContext(dpy,vi,
00199                             NULL,True);
00200 
00201         if (cx== NULL){
00202             std::cerr << "Could not initialize GL context.\n";
00203             return false;
00204         }
00205 
00206         if (!glXMakeCurrent(dpy,win,cx)){
00207             dpy=0;
00208             return false;
00209         }
00210     }
00211 
00212 #endif
00213 
00214     return true;
}

Here is the caller graph for this function:

void rSysDep::ExitGL (  )  [static]

Definition at line 216 of file rSysdep.cpp.

References NULL.

Referenced by sr_ExitDisplay().

00217                      {
00218     SDL_SysWMinfo system;
00219     SDL_GetWMInfo(&system);
00220 
00221     /*
00222     #ifdef HAVE_FXMESA
00223 
00224     if(ctx){
00225       fxMesaDestroyContext(ctx);
00226       ctx=NULL;
00227       fxCloseHardware();
00228     }
00229     */
00230 
00231 #if defined(WIN32)
00232     HWND hWnd=system.window;
00233 
00234     // windows GL cleanup stolen from
00235     // http://www.geocities.com/SiliconValley/Code/1219/opengl32.html
00236     if (hRC){
00237 
00238         wglMakeCurrent( NULL, NULL );
00239         wglDeleteContext( hRC );
00240         ReleaseDC( hWnd, hDC );
00241 
00242         hRC=NULL;
00243         hDC=NULL;
00244     }
00245 #elif defined(unix) || defined(__unix__)
00246     if (dpy){
00247 
00248         //    glXReleaseBuffersMESA( dpy, win );
00249         glXMakeCurrent(dpy,None,NULL);
00250         glXDestroyContext(dpy, cx );
00251         dpy=NULL;
00252     }
00253 #endif

Here is the caller graph for this function:

void rSysDep::SwapGL (  )  [static]

Definition at line 807 of file rSysdep.cpp.

References breakpoint(), ClearGL(), PerformanceCounter::Count(), rPerFrameTask::DoPerFrameTasks(), tRecorderBase::IsPlayingBack(), tRecorderBase::IsRunning(), lastSuccess, make_screenshot(), rSwap_Fastest, rSwap_glFinish, rSwap_glFlush, s_benchmark, s_fastForward, s_fastForwardTo, s_nextFastForwardFrameReal, s_nextFastForwardFrameRecorded, s_videoout, sr_FF_Maxstep, sr_FF_MaxstepReal, sr_FF_MaxstepRel, sr_glOut, sr_LockSDL(), sr_MotionBlur(), sr_netLock, sr_screenshotIsPlanned, sr_UnlockSDL(), st_Breakpoint(), swapMode_, tDelayForce(), tRealSysTimeFloat(), tSysTimeFloat(), and rScreenSettings::useSDL.

Referenced by gServerBrowser::BrowseLAN(), gServerBrowser::BrowseSpecialMaster(), ConnectToServerCore(), gGame::GameLoop(), uMenu::Message(), uMenu::OnEnter(), Render(), and welcome().

00808                     {
00809     static std::auto_ptr< rTextureRenderTarget > blurTarget(0);
00810 
00811     if ( s_benchmark )
00812     {
00813         static PerformanceCounter counter;
00814         counter.Count();
00815     }
00816 
00817     double time = tSysTimeFloat();
00818     double realTime = tRealSysTimeFloat();
00819 
00820     bool next_glOut = sr_glOut;
00821 
00822     /* static double mytime = time; //ljr
00823     if (false && time < mytime + 1. / 29.97) {
00824         printf("skipping! %f %f\n", time, mytime);
00825         next_glOut = false;
00826     } else {
00827         printf("rendering %f %f\n", time, mytime);
00828         mytime = time;
00829         next_glOut = true;
00830     } */
00831 
00832     // adapt playback speed to recorded speed
00833     if ( !s_benchmark && !s_fastForward && tRecorder::IsPlayingBack() )
00834     {
00835         static double timeOffset=0;
00836         static double lastRendered=0;
00837 
00838         // calculate how much we're behind the rendering schedule
00839         double behind = - time + realTime + timeOffset;
00840         // std::cout << behind << " " << sr_glOut << "\n";
00841 
00842         // large delays can only be caused by breakpoints or map downloads; ignore them
00843         if ( behind > .5 || realTime > lastRendered + .2 )
00844         {
00845             timeOffset -= behind;
00846             next_glOut = true;
00847         }
00848         else
00849         {
00850             // we're a bit behind, skip the next frame
00851             if ( behind > .1 )
00852             {
00853                 next_glOut = false;
00854             }
00855             else if ( sr_glOut )
00856             {
00857                 lastRendered=realTime;
00858                 // we're ahead, pause a bit
00859                 if  ( behind < -.5 )
00860                     timeOffset -= behind;
00861                 else if ( behind < -.1 )
00862                 {
00863                     int delay = int( -( behind + .1 ) * 1000000 );
00864                     // std::cout << behind << ":" << delay << "\n";
00865                     tDelayForce( delay );
00866                 }
00867             }
00868             else
00869             {
00870                 // we're not behind any more. Reactivate rendering.
00871                 next_glOut = true;
00872             }
00873         }
00874 
00875         if ( next_glOut )
00876             lastRendered=realTime;
00877     }
00878 
00879     if (!sr_glOut)
00880     {
00881         // display next frame in fast foward mode
00882         if ( s_fastForward && ( time > s_nextFastForwardFrameRecorded || realTime > s_nextFastForwardFrameReal ) || next_glOut )
00883         {
00884             sr_glOut = true;
00885             rSysDep::ClearGL();
00886         }
00887 
00888         // in playback or recording mode, always execute frame tasks, they may be improtant for consistency
00889         if ( tRecorder::IsRunning() ) {
00890             rPerFrameTask::DoPerFrameTasks();
00891 #ifdef HAVE_LIBRUBY
00892             rPerFrameTaskRuby::DoPerFrameTasks();
00893 #endif
00894         }
00895 
00896 
00897         return;
00898     }
00899 
00900 
00901     rPerFrameTask::DoPerFrameTasks();
00902 #ifdef HAVE_LIBRUBY
00903     rPerFrameTaskRuby::DoPerFrameTasks();
00904 #endif
00905 
00906     // unlock the mutex while waiting for the swap operation to finish
00907     SDL_mutexV(  sr_netLock );
00908     sr_LockSDL();
00909 
00910     // actiate motion blur (does not use the game state, so it's OK to call here )
00911     bool shouldSwap = sr_MotionBlur( time, blurTarget );
00912 
00913     switch ( swapMode_ )
00914     {
00915     case rSwap_Fastest:
00916         break;
00917     case rSwap_glFlush:
00918         glFlush();
00919         break;
00920     case rSwap_glFinish:
00921         glFinish();
00922         break;
00923     }
00924 
00925     if ( shouldSwap )
00926     {
00927 #if defined(SDL_OPENGL)
00928         if (lastSuccess.useSDL)
00929             SDL_GL_SwapBuffers();
00930         //#elif defined(HAVE_FXMESA)
00931         //fxMesaSwapBuffers();
00932 #endif
00933 
00934 #ifdef DIRTY
00935         if (!lastSuccess.useSDL){
00936 #if defined(WIN32)
00937             SwapBuffers( hDC );
00938 #elif defined(unix) || defined(__unix__)
00939             glXSwapBuffers(dpy,win);
00940 #endif
00941         }
00942 #endif
00943     }
00944 
00945     if (sr_screenshotIsPlanned){
00946         make_screenshot();
00947         sr_screenshotIsPlanned=false;
00948     }
00949     else if (s_videoout)
00950         make_screenshot();
00951 
00952     sr_UnlockSDL();
00953     // lock mutex again
00954     SDL_mutexP(  sr_netLock );
00955 
00956 
00957     // disable output in fast forward mode
00958     if ( s_fastForward && tRecorder::IsPlayingBack() )
00959     {
00960         if ( time < s_fastForwardTo )
00961         {
00962             // next displayed frame should be ten percent closer to the target, but at most 10 seconds
00963             s_nextFastForwardFrameRecorded = ( s_fastForwardTo - time ) * sr_FF_MaxstepRel;
00964             if ( s_nextFastForwardFrameRecorded > sr_FF_Maxstep )
00965                 s_nextFastForwardFrameRecorded = sr_FF_Maxstep ;
00966             s_nextFastForwardFrameRecorded += time;
00967             s_nextFastForwardFrameReal = realTime + sr_FF_MaxstepReal ;
00968 
00969             next_glOut = false;
00970         }
00971         else
00972         {
00973             std::cout << "End of fast forward mode.\n";
00974             st_Breakpoint();
00975             s_fastForward = false;
00976         }
00977     }
00978 
00979     //#ifdef DEBUG
00980     if ( !s_fastForward )
00981     {
00982         breakpoint();
00983     }
00984     //#endif
00985 
00986     // store frame time for next frame
00987     // lastFrame = tRealSysTimeFloat();
00988 
00989     sr_glOut = next_glOut;

Here is the call graph for this function:

Here is the caller graph for this function:

void rSysDep::ClearGL (  )  [static]

Definition at line 1023 of file rSysdep.cpp.

References sr_glOut.

Referenced by gServerBrowser::BrowseLAN(), gServerBrowser::BrowseSpecialMaster(), ConnectToServerCore(), gGame::GameLoop(), uMenu::Message(), uMenu::OnEnter(), Render(), SwapGL(), and welcome().

01024                       {
01025     if (sr_glOut){
01026 
01027         /*
01028         if (sr_screenshotIsPlanned){
01029           make_screenshot();
01030           sr_screenshotIsPlanned=false;
01031         }
01032         */
01033 
01034         glClearColor(0.0,0.0,0.0,1.0);
01035         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
01036     }

Here is the caller graph for this function:

void rSysDep::StartNetSyncThread ( rNetIdler idler  )  [static]

Definition at line 556 of file rSysdep.cpp.

References tRecorderBase::IsRunning(), sr_netLock, sr_NetSyncThread(), and sr_netSyncThread.

00558 {
00559     sr_netIdler = idler;
00560 
00561     return; // BUG This thread is crashing ruby
00562 
00563     // can't use thrading trouble while recording
00564     if ( tRecorder::IsRunning() )
00565         return;
00566 
00567     if ( sr_netSyncThread )
00568         return;
00569 
00570     // create lock
00571     if ( !sr_netLock )
00572         sr_netLock = SDL_CreateMutex();
00573 
00574     // start thread
00575     sr_netSyncThread = SDL_CreateThread( sr_NetSyncThread, sr_netLock );
00576     if ( !sr_netSyncThread )
00577         return;
00578 
00579     // lock mutex, the thread should only do work while the main thread is waiting for the refresh
00580     SDL_mutexP( sr_netLock );

Here is the call graph for this function:

void rSysDep::StopNetSyncThread (  )  [static]

Definition at line 582 of file rSysdep.cpp.

References NULL, sr_netLock, sr_netSyncThread, and sr_netSyncThreadGoOn.

Referenced by net_game().

00584 {
00585     // stop and delete thread
00586     if ( sr_netSyncThread )
00587     {
00588         SDL_mutexV(  sr_netLock );
00589         sr_netSyncThreadGoOn = false;
00590         SDL_WaitThread( sr_netSyncThread, NULL );
00591         sr_netSyncThread = NULL;
00592         sr_netIdler = NULL;
00593     }
00594 
00595     // delete lock
00596     if ( sr_netLock )
00597     {
00598         SDL_DestroyMutex( sr_netLock );
00599         sr_netLock = NULL;
00600     }

Here is the caller graph for this function:


Member Data Documentation

rSysDep::rSwapMode rSysDep::swapMode_ = rSysDep::rSwap_glFlush [static]

Definition at line 69 of file rSysdep.h.

Referenced by sr_LoadDefaultConfig(), and SwapGL().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:53:49 2008 for Armagetron Advanced by  doxygen 1.5.4