always.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Code/wwlib/always.h $*
  25. * *
  26. * $Author:: Steve_t $*
  27. * *
  28. * $Modtime:: 8/28/01 3:21p $*
  29. * *
  30. * $Revision:: 13 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if _MSC_VER >= 1000
  36. #pragma once
  37. #endif // _MSC_VER >= 1000
  38. #ifndef ALWAYS_H
  39. #define ALWAYS_H
  40. // Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
  41. #pragma warning(disable : 4530)
  42. /*
  43. ** Define for debug memory allocation to include __FILE__ and __LINE__ for every memory allocation.
  44. ** This helps find leaks.
  45. */
  46. //#define STEVES_NEW_CATCHER
  47. #ifdef _DEBUG
  48. #ifdef _MSC_VER
  49. #ifdef STEVES_NEW_CATCHER
  50. #include <crtdbg.h>
  51. #include <stdlib.h>
  52. #include <malloc.h>
  53. #define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
  54. #define calloc(c, s) _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  55. #define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  56. #define _expand(p, s) _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  57. #define free(p) _free_dbg(p, _NORMAL_BLOCK)
  58. #define _msize(p) _msize_dbg(p, _NORMAL_BLOCK)
  59. void* __cdecl operator new(unsigned int s);
  60. #endif //STEVES_NEW_CATCHER
  61. #endif //_MSC_VER
  62. #endif //_DEBUG
  63. // Jani: Intel's C++ compiler issues too many warnings in WW libraries when using warning level 4
  64. #if defined (__ICL) // Detect Intel compiler
  65. #pragma warning (3)
  66. #pragma warning ( disable: 981 ) // parameters defined in unspecified order
  67. #pragma warning ( disable: 279 ) // controlling expressaion is constant
  68. #pragma warning ( disable: 271 ) // trailing comma is nonstandard
  69. #pragma warning ( disable: 171 ) // invalid type conversion
  70. #pragma warning ( disable: 1 ) // last line of file ends without a newline
  71. #endif
  72. // Jani: MSVC doesn't necessarily inline code with inline keyword. Using __forceinline results better inlining
  73. // and also prints out a warning if inlining wasn't possible. __forceinline is MSVC specific.
  74. #if defined(_MSC_VER)
  75. #define WWINLINE __forceinline
  76. #else
  77. #define WWINLINE inline
  78. #endif
  79. /*
  80. ** Define the MIN and MAX macros.
  81. ** NOTE: Joe used to #include <minmax.h> in the various compiler header files. This
  82. ** header defines 'min' and 'max' macros which conflict with the surrender code so
  83. ** I'm relpacing all occurances of 'min' and 'max with 'MIN' and 'MAX'. For code which
  84. ** is out of our domain (e.g. Max sdk) I'm declaring template functions for 'min' and 'max'
  85. */
  86. #define NOMINMAX
  87. #ifndef MAX
  88. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  89. #endif
  90. #ifndef MIN
  91. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  92. #endif
  93. #ifdef min
  94. #undef min
  95. #endif
  96. #ifdef max
  97. #undef max
  98. #endif
  99. template <class T> T min(T a,T b)
  100. {
  101. if (a<b) {
  102. return a;
  103. } else {
  104. return b;
  105. }
  106. }
  107. template <class T> T max(T a,T b)
  108. {
  109. if (a>b) {
  110. return a;
  111. } else {
  112. return b;
  113. }
  114. }
  115. /*
  116. ** This includes the minimum set of compiler defines and pragmas in order to bring the
  117. ** various compilers to a common behavior such that the C&C engine will compile without
  118. ** error or warning.
  119. */
  120. #if defined(__BORLANDC__)
  121. #include "borlandc.h"
  122. #endif
  123. #if defined(_MSC_VER)
  124. #include "visualc.h"
  125. #endif
  126. #if defined(__WATCOMC__)
  127. #include "watcom.h"
  128. #endif
  129. #ifndef NULL
  130. #define NULL 0
  131. #endif
  132. /**********************************************************************
  133. ** This macro serves as a general way to determine the number of elements
  134. ** within an array.
  135. */
  136. #ifndef ARRAY_SIZE
  137. #define ARRAY_SIZE(x) int(sizeof(x)/sizeof(x[0]))
  138. #endif
  139. #ifndef size_of
  140. #define size_of(typ,id) sizeof(((typ*)0)->id)
  141. #endif
  142. #endif