_ic.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. I AM ARCHAIC - INCLUDE ORANGE/QUICKMATH/FIXEDPOINT.H instead!
  19. // This is an internal BLiT header. Don't get confused by it - it's not up to user level yet.
  20. #ifndef ic_h
  21. #define ic_h
  22. #include "System.h"
  23. //========================== Here are some fraction inlines...
  24. // add two fractions of identical denominators...
  25. // both fraction MUST be PROPER!
  26. //
  27. inline void Add(u16Frac& pDst,u16Frac& pAdd,short sDen)
  28. {
  29. pDst.delta += pAdd.delta;
  30. if ( (pDst.frac += pAdd.frac) >= sDen)
  31. {
  32. pDst.delta++; // ONLY adding proper fractions
  33. pDst.frac -= sDen;
  34. }
  35. }
  36. // Creates a proper fraction from an improper one:
  37. // The sizes MUST be appropriate!
  38. //
  39. inline void MakeProper(u16Frac& pDst,USHORT usNum,USHORT usDen)
  40. {
  41. pDst.delta = usNum / usDen;
  42. pDst.frac = usNum % usDen;
  43. //pDst.frac = usNum - pDst.delta * usDen;// overflow problem
  44. }
  45. // Creates an array of 256 fractions, uch that 0 is 0,
  46. // 1 is tha base fraction, and 255 is 255 * the base fraction.
  47. // Both must be unsigned! (uses calloc)
  48. //
  49. inline u16Frac* u16fStrafe256(USHORT usNum,USHORT usDen)
  50. {
  51. u16Frac* pu16fNew = (u16Frac*) calloc(256,sizeof(u16Frac));
  52. u16Frac u16fInc;
  53. MakeProper(u16fInc,usNum,usDen); // the 2 part delta
  54. ULONG ulNumInc = 0;
  55. for (short i = 1; i < 256 ; i++)
  56. {
  57. pu16fNew[i].delta = pu16fNew[i-1].delta + u16fInc.delta;
  58. pu16fNew[i].frac = pu16fNew[i-1].frac + u16fInc.frac;
  59. if (pu16fNew[i].frac >= usDen)
  60. {
  61. pu16fNew[i].frac -= usDen;
  62. pu16fNew[i].delta++; // unsigned positive increment only!
  63. }
  64. }
  65. return pu16fNew;
  66. }
  67. //===========================
  68. #endif