tables.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. * Lookup tables.
  31. * Do not try to look them up :-).
  32. * In the order of appearance:
  33. *
  34. * int finetangent[4096] - Tangens LUT.
  35. * Should work with BAM fairly well (12 of 16bit,
  36. * effectively, by shifting).
  37. *
  38. * int finesine[10240] - Sine lookup.
  39. * Guess what, serves as cosine, too.
  40. * Remarkable thing is, how to use BAMs with this?
  41. *
  42. * int tantoangle[2049] - ArcTan LUT,
  43. * maps tan(angle) to angle fast. Gotta search.
  44. *
  45. *-----------------------------------------------------------------------------*/
  46. #ifndef __TABLES__
  47. #define __TABLES__
  48. #include "m_fixed.h"
  49. #define FINEANGLES 8192
  50. #define FINEMASK (FINEANGLES-1)
  51. // 0x100000000 to 0x2000
  52. #define ANGLETOFINESHIFT 19
  53. // Binary Angle Measument, BAM.
  54. #define ANG45 0x20000000
  55. #define ANG90 0x40000000
  56. #define ANG180 0x80000000
  57. #define ANG270 0xc0000000
  58. #define ANG1 (ANG45/45)
  59. #define ANGLE_MAX 0xffffffff
  60. #ifndef M_PI
  61. #define M_PI 3.14159265358979323846
  62. #endif
  63. #define SLOPERANGE 2048
  64. #define SLOPEBITS 11
  65. #define DBITS (FRACBITS-SLOPEBITS)
  66. typedef unsigned angle_t;
  67. // Load trig tables if needed
  68. void R_LoadTrigTables(void);
  69. // Effective size is 10240.
  70. extern fixed_t finesine[5*FINEANGLES/4];
  71. // Re-use data, is just PI/2 phase shift.
  72. static fixed_t *const finecosine = finesine + (FINEANGLES/4);
  73. // Effective size is 4096.
  74. extern fixed_t finetangent[FINEANGLES/2];
  75. // Effective size is 2049;
  76. // The +1 size is to handle the case when x==y without additional checking.
  77. extern angle_t tantoangle[SLOPERANGE+1];
  78. // Utility function, called by R_PointToAngle.
  79. typedef int (*slope_div_fn)(unsigned int num, unsigned int den);
  80. int SlopeDiv(unsigned int num, unsigned int den);
  81. int SlopeDivEx(unsigned int num, unsigned int den);
  82. #endif