diff options
Diffstat (limited to 'src/tables.c')
-rw-r--r-- | src/tables.c | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/tables.c b/src/tables.c new file mode 100644 index 0000000..2cf59e1 --- /dev/null +++ b/src/tables.c | |||
@@ -0,0 +1,128 @@ | |||
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 | |||
48 | #ifdef HAVE_CONFIG_H | ||
49 | #include "config.h" | ||
50 | #endif | ||
51 | |||
52 | #include <stddef.h> | ||
53 | #include "w_wad.h" | ||
54 | #include "tables.h" | ||
55 | |||
56 | // killough 5/3/98: reformatted | ||
57 | |||
58 | int SlopeDiv(unsigned num, unsigned den) | ||
59 | { | ||
60 | unsigned ans; | ||
61 | |||
62 | if (den < 512) | ||
63 | return SLOPERANGE; | ||
64 | ans = (num<<3)/(den>>8); | ||
65 | return ans <= SLOPERANGE ? ans : SLOPERANGE; | ||
66 | } | ||
67 | |||
68 | fixed_t finetangent[4096]; | ||
69 | |||
70 | //const fixed_t *const finecosine = &finesine[FINEANGLES/4]; | ||
71 | |||
72 | fixed_t finesine[10240]; | ||
73 | |||
74 | angle_t tantoangle[2049]; | ||
75 | |||
76 | #include "m_swap.h" | ||
77 | #include "lprintf.h" | ||
78 | |||
79 | // R_LoadTrigTables | ||
80 | // Load trig tables from a wad file lump | ||
81 | // CPhipps 24/12/98 - fix endianness (!) | ||
82 | // | ||
83 | void R_LoadTrigTables(void) | ||
84 | { | ||
85 | int lump; | ||
86 | { | ||
87 | lump = (W_CheckNumForName)("SINETABL",ns_prboom); | ||
88 | if (lump == -1) I_Error("Failed to locate trig tables"); | ||
89 | if (W_LumpLength(lump) != sizeof(finesine)) | ||
90 | I_Error("R_LoadTrigTables: Invalid SINETABL"); | ||
91 | W_ReadLump(lump,(unsigned char*)finesine); | ||
92 | } | ||
93 | { | ||
94 | lump = (W_CheckNumForName)("TANGTABL",ns_prboom); | ||
95 | if (lump == -1) I_Error("Failed to locate trig tables"); | ||
96 | if (W_LumpLength(lump) != sizeof(finetangent)) | ||
97 | I_Error("R_LoadTrigTables: Invalid TANGTABL"); | ||
98 | W_ReadLump(lump,(unsigned char*)finetangent); | ||
99 | } | ||
100 | { | ||
101 | lump = (W_CheckNumForName)("TANTOANG",ns_prboom); | ||
102 | if (lump == -1) I_Error("Failed to locate trig tables"); | ||
103 | if (W_LumpLength(lump) != sizeof(tantoangle)) | ||
104 | I_Error("R_LoadTrigTables: Invalid TANTOANG"); | ||
105 | W_ReadLump(lump,(unsigned char*)tantoangle); | ||
106 | } | ||
107 | // Endianness correction - might still be non-portable, but is fast where possible | ||
108 | { | ||
109 | size_t n; | ||
110 | lprintf(LO_INFO, "Endianness..."); | ||
111 | |||
112 | // This test doesn't assume the endianness of the tables, but deduces them from | ||
113 | // en entry. I hope this is portable. | ||
114 | if ((10 < finesine[1]) && (finesine[1] < 100)) { | ||
115 | lprintf(LO_INFO, "ok."); | ||
116 | return; // Endianness is correct | ||
117 | } | ||
118 | |||
119 | // Must correct endianness of every long loaded (!) | ||
120 | #define CORRECT_TABLE_ENDIAN(tbl) \ | ||
121 | for (n = 0; n<sizeof(tbl)/sizeof(tbl[0]); n++) tbl[n] = doom_swap_l(tbl[n]) | ||
122 | |||
123 | CORRECT_TABLE_ENDIAN(finesine); | ||
124 | CORRECT_TABLE_ENDIAN(finetangent); | ||
125 | CORRECT_TABLE_ENDIAN(tantoangle); | ||
126 | lprintf(LO_INFO, "corrected."); | ||
127 | } | ||
128 | } | ||