Debian Codegraph @

prboom2/src/tables.h

raw
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
47 #ifndef __TABLES__
48 #define __TABLES__
49
50 #include "m_fixed.h"
51
52 #define FINEANGLES 8192
53 #define FINEMASK (FINEANGLES-1)
54
55 // 0x100000000 to 0x2000
56 #define ANGLETOFINESHIFT 19
57
58 // Binary Angle Measument, BAM.
59 #define ANG45 0x20000000
60 #define ANG90 0x40000000
61 #define ANG135 0x60000000
62 #define ANG180 0x80000000
63 #define ANG225 0xa0000000
64 #define ANG270 0xc0000000
65 #define ANG315 0xe0000000
66 #define ANG1 (ANG45/45)
67 #define ANG60 (ANG180 / 3)
68 #define ANGLE_MAX 0xffffffff
69 #ifndef M_PI
70 #define M_PI 3.14159265358979323846
71 #endif
72
73 #define FIXED_PI 205887
74
75 #define SLOPERANGE 2048
76 #define SLOPEBITS 11
77 #define DBITS (FRACBITS-SLOPEBITS)
78
79 typedef unsigned angle_t;
80
81 #define ANGLE_T_TO_PITCH_F(x) ((float) ((x) >> ANGLETOFINESHIFT) * 360.0f / FINEANGLES)
82 #define ANGLE_T_TO_LOOKDIR(x) ((int) -((int) (x) * M_PI / ANG1))
83
84 // lookdir range is -110 (down) to 90 (up)
85 // pitch is -lookdir * ang1 / pi
86 // precomputed to avoid compiler-dependent floating point operation!
87 static const angle_t raven_angle_down_limit = 0x18e70000; // (angle_t) (int) (110 * ANG1 / M_PI);
88 static const angle_t raven_angle_up_limit = 0xeba00000; // (angle_t) (int) (-90 * ANG1 / M_PI);
89
90 // Load trig tables if needed
91 void R_LoadTrigTables(void);
92
93 // Effective size is 10240.
94 extern fixed_t finesine[5*FINEANGLES/4];
95
96 // Re-use data, is just PI/2 phase shift.
97 static fixed_t *const finecosine = finesine + (FINEANGLES/4);
98
99 // Effective size is 4096.
100 extern fixed_t finetangent[FINEANGLES/2];
101
102 // Effective size is 2049;
103 // The +1 size is to handle the case when x==y without additional checking.
104
105 extern angle_t tantoangle[SLOPERANGE+1];
106
107 // Utility function, called by R_PointToAngle.
108 typedef int (*slope_div_fn)(unsigned int num, unsigned int den);
109 int SlopeDiv(unsigned int num, unsigned int den);
110 int SlopeDivEx(unsigned int num, unsigned int den);
111
112 // More utility functions, courtesy of Quasar (James Haley).
113 // These are straight from Eternity so demos stay in sync.
114 inline static angle_t FixedToAngle(fixed_t a)
115 {
116 return (angle_t)(((uint64_t)a * ANG1) >> FRACBITS);
117 }
118
119 inline static fixed_t AngleToFixed(angle_t a)
120 {
121 return (fixed_t)(((uint64_t)a << FRACBITS) / ANG1);
122 }
123
124 // [XA] Clamped angle->slope, for convenience
125 inline static fixed_t AngleToSlope(int a)
126 {
127 if (a > ANG90)
128 return finetangent[0];
129 else if (-a > ANG90)
130 return finetangent[FINEANGLES / 2 - 1];
131 else
132 return finetangent[(ANG90 - a) >> ANGLETOFINESHIFT];
133 }
134
135 // [XA] Ditto, using fixed-point-degrees input
136 inline static fixed_t DegToSlope(fixed_t a)
137 {
138 if (a >= 0)
139 return AngleToSlope(FixedToAngle(a));
140 else
141 return AngleToSlope(-(int)FixedToAngle(-a));
142 }
143
144 #endif