Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.1 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: sspipes.cxx
  3. *
  4. * Startup code
  5. *
  6. * Copyright (c) 1994 Microsoft Corporation
  7. *
  8. \**************************************************************************/
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <math.h>
  13. #include <sys/types.h>
  14. #include <sys/timeb.h>
  15. #include <time.h>
  16. #include <windows.h>
  17. #include "sspipes.h"
  18. #include "dialog.h"
  19. #include "state.h"
  20. #ifdef DO_TIMING
  21. int pipeCount;
  22. #endif
  23. void InitPipes( void *data );
  24. /******************************Public*Routine******************************\
  25. * ss_Init
  26. *
  27. * Initialize - called on first entry into ss.
  28. * Called BEFORE gl is initialized!
  29. * Just do basic stuff here, like set up callbacks, verify dialog stuff, etc.
  30. *
  31. * Fills global SSContext structure with required data, and returns ptr
  32. * to it.
  33. *
  34. \**************************************************************************/
  35. static SSContext ssc;
  36. SSContext *
  37. ss_Init( void )
  38. {
  39. // validate some initial dialog settings
  40. getIniSettings(); // also called on dialog init
  41. if( ulSurfStyle == SURFSTYLE_TEX ) {
  42. // Texture verification has to go here, before gl is loaded, in case
  43. // error msgs are displayed.
  44. for( int i = 0; i < gnTextures; i ++ ) {
  45. if( !ss_VerifyTextureFile( &gTexFile[i]) ) {
  46. // user texture is invalid - substitute resource texture ?
  47. // If gnTextures > nRes
  48. // get rid of this one - move the others up
  49. gnTextures--;
  50. for( int j = i; j < gnTextures; j++ )
  51. gTexFile[j] = gTexFile[j+1];
  52. }
  53. }
  54. }
  55. ss_InitFunc( InitPipes );
  56. // set configuration info to return
  57. ssc.bDoubleBuf = FALSE;
  58. ssc.depthType = SS_DEPTH16;
  59. ssc.bFloater = FALSE;
  60. return &ssc;
  61. }
  62. static void
  63. Draw( void *data )
  64. {
  65. // don't need data here, but I was hoping to be able to use the STATE
  66. // member functions directly as callbacks
  67. ((STATE *) data)->Draw(data);
  68. }
  69. static void
  70. Reshape( int width, int height, void *data )
  71. {
  72. ((STATE *) data)->Reshape( width, height, data );
  73. }
  74. static void
  75. Repaint( LPRECT pRect, void *data )
  76. {
  77. ((STATE *) data)->Repaint( pRect, data );
  78. }
  79. static void
  80. Finish( void *data )
  81. {
  82. ((STATE *) data)->Finish( data );
  83. }
  84. /******************************Public*Routine******************************\
  85. * InitPipes
  86. *
  87. * - Called when GL window has been initialized
  88. *
  89. \**************************************************************************/
  90. void
  91. InitPipes( void *data )
  92. {
  93. // create world of pipes
  94. //mf: for now, bFlexMode used to choose between normal/flex
  95. STATE *pPipeWorld = new STATE( bFlexMode, bMultiPipes );
  96. #if 0
  97. //mf: compiler doesn't like me using class member functions as callbacks
  98. ss_UpdateFunc( pState->Draw );
  99. ss_ReshapeFunc( pState->Reshape );
  100. ss_FinishFunc( pState->Finish );
  101. #else
  102. // mf: use wrappers for now
  103. ss_UpdateFunc( Draw );
  104. ss_ReshapeFunc( Reshape );
  105. ss_RepaintFunc( Repaint );
  106. ss_FinishFunc( Finish );
  107. #endif
  108. //mf: this should no longer be necessary
  109. ss_DataPtr( pPipeWorld );
  110. }
  111. #ifdef DO_TIMING
  112. void CalcPipeRate( struct _timeb baseTime, int pipeCount ) {
  113. static struct _timeb thisTime;
  114. double elapsed, pipeRate;
  115. char buf[100];
  116. _ftime( &thisTime );
  117. elapsed = thisTime.time + thisTime.millitm/1000.0 -
  118. (baseTime.time + baseTime.millitm/1000.0);
  119. if( elapsed == 0.0 )
  120. pipeRate = 0.0;
  121. else
  122. pipeRate = pipeCount / elapsed;
  123. sprintf( buf, "Last frame's pipe rate = %4.1f pps", pipeRate );
  124. #ifdef SS_DEBUG
  125. SendMessage(ss_GetHWND(), WM_SETTEXT, 0, (LPARAM)buf);
  126. #endif
  127. }
  128. void Timer( int mode )
  129. {
  130. static struct _timeb baseTime;
  131. switch( mode ) {
  132. case TIMER_START:
  133. pipeCount = 0;
  134. _ftime( &baseTime );
  135. break;
  136. case TIMER_STOP:
  137. CalcPipeRate( baseTime, pipeCount );
  138. break;
  139. case TIMER_TIMING:
  140. break;
  141. case TIMER_RESET:
  142. default:
  143. break;
  144. }
  145. }
  146. #endif