Statistics.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Statistics.cpp
  24. /*---------------------------------------------------------------------------*/
  25. /* EA Pacific */
  26. /* Confidential Information */
  27. /* Copyright (C) 2001 - All Rights Reserved */
  28. /* DO NOT DISTRIBUTE */
  29. /*---------------------------------------------------------------------------*/
  30. /* Project: RTS3 */
  31. /* File name: Statistics.cpp */
  32. /* Created: John K. McDonald, Jr., 4/2/2002 */
  33. /* Desc: Statistical functions should live here */
  34. /* Revision History: */
  35. /* 4/2/2002 : Initial creation */
  36. /*---------------------------------------------------------------------------*/
  37. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  38. #include "GameClient/Statistics.h"
  39. // Solution taken from http://www.epanorama.net/documents/telecom/ulaw_alaw.html
  40. Real MuLaw(Real valueToRun, Real maxValueForVal, Real mu)
  41. {
  42. Real testVal = (valueToRun - maxValueForVal / 2) / (maxValueForVal / 2);
  43. return (sign(testVal) * log(1 + mu * fabs(testVal)) /
  44. log(1 + mu));
  45. }
  46. // from my head. jkmcd
  47. Real Normalize(Real valueToNormalize, Real minRange, Real maxRange)
  48. {
  49. return ((valueToNormalize - minRange) / (maxRange - minRange));
  50. }
  51. // from my head again. jkmcd
  52. Real NormalizeToRange(Real valueToNormalize, Real minRange, Real maxRange, Real outRangeMin, Real outRangeMax)
  53. {
  54. return (Normalize(valueToNormalize, minRange, maxRange) * (outRangeMax - outRangeMin)) + outRangeMin;
  55. }