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.

178 lines
3.7 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: util.cxx
  3. *
  4. * Misc. utility functions
  5. *
  6. * Copyright (c) 1996 Microsoft Corporation
  7. *
  8. \**************************************************************************/
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <windows.h>
  13. #include <GL/gl.h>
  14. #include <sys/types.h>
  15. #include <sys/timeb.h>
  16. #include <time.h>
  17. #include <math.h>
  18. #include "mtk.h"
  19. #include "util.hxx"
  20. // Debug util stuff
  21. #if DBG
  22. #define SS_DEBUG 1
  23. #ifdef SS_DEBUG
  24. long ssDebugMsg = 1;
  25. long ssDebugLevel = SS_LEVEL_INFO;
  26. #else
  27. long ssDebugMsg = 0;
  28. long ssDebugLevel = SS_LEVEL_ERROR;
  29. #endif
  30. #endif
  31. /******************************Public*Routine******************************\
  32. * ss_Rand
  33. *
  34. * Generates integer random number 0..(max-1)
  35. *
  36. \**************************************************************************/
  37. int ss_iRand( int max )
  38. {
  39. return (int) ( max * ( ((float)rand()) / ((float)(RAND_MAX+1)) ) );
  40. }
  41. /******************************Public*Routine******************************\
  42. * ss_Rand2
  43. *
  44. * Generates integer random number min..max
  45. *
  46. \**************************************************************************/
  47. int ss_iRand2( int min, int max )
  48. {
  49. if( min == max )
  50. return min;
  51. else if( max < min ) {
  52. int temp = min;
  53. min = max;
  54. max = temp;
  55. }
  56. return min + (int) ( (max-min+1) * ( ((float)rand()) / ((float)(RAND_MAX+1)) ) );
  57. }
  58. /******************************Public*Routine******************************\
  59. * ss_fRand
  60. *
  61. * Generates float random number min...max
  62. *
  63. \**************************************************************************/
  64. FLOAT ss_fRand( FLOAT min, FLOAT max )
  65. {
  66. FLOAT diff;
  67. diff = max - min;
  68. return min + ( diff * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
  69. }
  70. /******************************Public*Routine******************************\
  71. * ss_RandInit
  72. *
  73. * Initializes the randomizer
  74. *
  75. \**************************************************************************/
  76. void ss_RandInit( void )
  77. {
  78. struct _timeb time;
  79. _ftime( &time );
  80. srand( time.millitm );
  81. for( int i = 0; i < 10; i ++ )
  82. rand();
  83. }
  84. /******************************Public*Routine******************************\
  85. * mtkQuit
  86. *
  87. * Harsh way to kill the app, just exits the process, no cleanup done
  88. *
  89. \**************************************************************************/
  90. void
  91. mtkQuit()
  92. {
  93. ExitProcess( 0 );
  94. }
  95. /******************************Public*Routine******************************\
  96. * mtk_ChangeDisplaySettings
  97. *
  98. * Try changing display settings.
  99. * If bitDepth is 0, use current bit depth
  100. *
  101. \**************************************************************************/
  102. BOOL
  103. mtk_ChangeDisplaySettings( int width, int height, int bitDepth )
  104. {
  105. int change;
  106. DEVMODE dm = {0};
  107. dm.dmSize = sizeof(dm);
  108. dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
  109. dm.dmPelsWidth = width;
  110. dm.dmPelsHeight = height;
  111. if( bitDepth != 0 ) {
  112. dm.dmFields |= DM_BITSPERPEL;
  113. dm.dmBitsPerPel = bitDepth;
  114. }
  115. change = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
  116. if( change == DISP_CHANGE_SUCCESSFUL )
  117. return TRUE;
  118. else
  119. return FALSE;
  120. }
  121. void
  122. mtk_RestoreDisplaySettings()
  123. {
  124. ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
  125. }
  126. #if DBG
  127. /******************************Public*Routine******************************\
  128. * DbgPrint
  129. *
  130. * Formatted string output to the debugger.
  131. *
  132. * History:
  133. * 26-Jan-1996 -by- Gilman Wong [gilmanw]
  134. * Wrote it.
  135. \**************************************************************************/
  136. ULONG
  137. DbgPrint(PCH DebugMessage, ...)
  138. {
  139. va_list ap;
  140. char buffer[256];
  141. va_start(ap, DebugMessage);
  142. vsprintf(buffer, DebugMessage, ap);
  143. OutputDebugStringA(buffer);
  144. va_end(ap);
  145. return(0);
  146. }
  147. #endif