control.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/control.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 2/21/02 5:06p $*
  29. * *
  30. * $Revision:: 36 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef CONTROL_H
  36. #define CONTROL_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef WWMATH_H
  41. #include "wwmath.h"
  42. #endif
  43. #ifndef WWDEBUG_H
  44. #include "wwdebug.h"
  45. #endif
  46. /*
  47. **
  48. */
  49. class BitStreamClass;
  50. class ChunkSaveClass;
  51. class ChunkLoadClass;
  52. /*
  53. ** ControlClass
  54. */
  55. class ControlClass {
  56. public:
  57. typedef enum {
  58. BOOLEAN_ONE_TIME_FIRST,
  59. BOOLEAN_JUMP = BOOLEAN_ONE_TIME_FIRST,
  60. // BOOLEAN_CROUCH,
  61. BOOLEAN_WEAPON_NEXT,
  62. BOOLEAN_WEAPON_PREV,
  63. BOOLEAN_WEAPON_RELOAD,
  64. BOOLEAN_WEAPON_USE,
  65. BOOLEAN_DIVE_FORWARD,
  66. BOOLEAN_DIVE_BACKWARD,
  67. BOOLEAN_DIVE_LEFT,
  68. BOOLEAN_DIVE_RIGHT,
  69. BOOLEAN_ACTION, // was LADDER
  70. BOOLEAN_SELECT_NO_WEAPON,
  71. BOOLEAN_SELECT_WEAPON_0,
  72. BOOLEAN_SELECT_WEAPON_1,
  73. BOOLEAN_SELECT_WEAPON_2,
  74. BOOLEAN_SELECT_WEAPON_3,
  75. BOOLEAN_SELECT_WEAPON_4,
  76. BOOLEAN_SELECT_WEAPON_5,
  77. BOOLEAN_SELECT_WEAPON_6,
  78. BOOLEAN_SELECT_WEAPON_7,
  79. BOOLEAN_SELECT_WEAPON_8,
  80. BOOLEAN_SELECT_WEAPON_9,
  81. BOOLEAN_DROP_FLAG,
  82. BOOLEAN_VEHICLE_TOGGLE_GUNNER,
  83. BOOLEAN_CONTINUOUS_FIRST,
  84. BOOLEAN_WEAPON_FIRE_PRIMARY = BOOLEAN_CONTINUOUS_FIRST,
  85. BOOLEAN_WEAPON_FIRE_SECONDARY,
  86. BOOLEAN_WALK,
  87. BOOLEAN_CROUCH,
  88. BOOLEAN_TOTAL, // Number of boolean channels
  89. NUM_BOOLEAN_ONE_TIME = BOOLEAN_CONTINUOUS_FIRST - BOOLEAN_ONE_TIME_FIRST,
  90. NUM_BOOLEAN_CONTINUOUS = BOOLEAN_TOTAL - BOOLEAN_CONTINUOUS_FIRST,
  91. } BooleanControl;
  92. typedef enum {
  93. ANALOG_MOVE_FORWARD,
  94. ANALOG_MOVE_LEFT,
  95. ANALOG_MOVE_UP,
  96. ANALOG_TURN_LEFT,
  97. ANALOG_CONTROL_COUNT // Number of analog channels
  98. } AnalogControl;
  99. ControlClass( void ) : PendingOneTimeBooleanBits( 0 ) { Clear_Control(); }
  100. ~ControlClass( void ) {}
  101. bool Save( ChunkSaveClass & csave );
  102. bool Load( ChunkLoadClass & cload );
  103. void Clear_Control( void );
  104. void Clear_Boolean( void );
  105. ControlClass & operator = (const ControlClass & src);
  106. // Boolean Controls
  107. void Set_Boolean( BooleanControl control, bool state = true );
  108. bool Get_Boolean( BooleanControl control );
  109. void Clear_One_Time_Boolean( void ) {OneTimeBooleanBits = 0;}
  110. unsigned long Get_One_Time_Boolean_Bits(void) {return OneTimeBooleanBits;}
  111. unsigned char Get_Continuous_Boolean_Bits(void) {return ContinuousBooleanBits;}
  112. // Analog Controls
  113. void Set_Analog( AnalogControl control, float value );
  114. float Get_Analog( AnalogControl control );
  115. //float Get_Clamp( AnalogControl control );
  116. //unsigned char Scale_Analog(float clamp, float unscaled);
  117. //float Unscale_Analog(float clamp, unsigned char scaled);
  118. // Import & Export
  119. void Import_Cs( BitStreamClass & packet );
  120. void Export_Cs( BitStreamClass & packet );
  121. void Import_Sc( BitStreamClass & packet );
  122. void Export_Sc( BitStreamClass & packet );
  123. static void Set_Precision(void);
  124. private:
  125. unsigned long OneTimeBooleanBits;
  126. unsigned long PendingOneTimeBooleanBits;
  127. unsigned char ContinuousBooleanBits;
  128. unsigned char PendingContinuousBooleanBits;
  129. float AnalogValues[ ANALOG_CONTROL_COUNT ];
  130. };
  131. inline void ControlClass::Set_Analog( AnalogControl control, float value )
  132. {
  133. WWASSERT(WWMath::Is_Valid_Float(value));
  134. AnalogValues[ control ] = value;
  135. }
  136. inline float ControlClass::Get_Analog( AnalogControl control )
  137. {
  138. WWASSERT(WWMath::Is_Valid_Float(AnalogValues[ control ]));
  139. return AnalogValues[ control ];
  140. }
  141. #endif // CONTROL_H