Debian Codegraph @

prboom2/src/tables.c

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
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 int num, unsigned int 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 // [crispy] catch SlopeDiv overflows, only used in rendering
69 int SlopeDivEx(unsigned int num, unsigned int den)
70 {
71 uint64_t ans;
72 if (den < 512)
73 return SLOPERANGE;
74 ans = ((uint64_t)num<<3)/(den>>8);
75 return ans <= SLOPERANGE ? (int)ans : SLOPERANGE;
76 }
77
78 fixed_t finetangent[4096];
79
80 //const fixed_t *const finecosine = &finesine[FINEANGLES/4];
81
82 fixed_t finesine[10240];
83
84 angle_t tantoangle[2049];
85
86 #include "m_swap.h"
87 #include "lprintf.h"
88
89 // R_LoadTrigTables
90 // Load trig tables from a wad file lump
91 // CPhipps 24/12/98 - fix endianness (!)
92 //
93 void R_LoadTrigTables(void)
94 {
95 int lump;
96 {
97 lump = W_CheckNumForName2("SINETABL",ns_prboom);
98 if (lump == LUMP_NOT_FOUND)
99 I_Error("Failed to locate trig tables");
100 if (W_LumpLength(lump) != sizeof(finesine))
101 I_Error("R_LoadTrigTables: Invalid SINETABL");
102 W_ReadLump(lump,(unsigned char*)finesine);
103 }
104 {
105 lump = W_CheckNumForName2("TANGTABL",ns_prboom);
106 if (lump == LUMP_NOT_FOUND)
107 I_Error("Failed to locate trig tables");
108 if (W_LumpLength(lump) != sizeof(finetangent))
109 I_Error("R_LoadTrigTables: Invalid TANGTABL");
110 W_ReadLump(lump,(unsigned char*)finetangent);
111 }
112 {
113 lump = W_CheckNumForName2("TANTOANG",ns_prboom);
114 if (lump == LUMP_NOT_FOUND)
115 I_Error("Failed to locate trig tables");
116 if (W_LumpLength(lump) != sizeof(tantoangle))
117 I_Error("R_LoadTrigTables: Invalid TANTOANG");
118 W_ReadLump(lump,(unsigned char*)tantoangle);
119 }
120 // Endianness correction - might still be non-portable, but is fast where possible
121 {
122 size_t n;
123 lprintf(LO_DEBUG, "Endianness...");
124
125 // This test doesn't assume the endianness of the tables, but deduces them from
126 // en entry. I hope this is portable.
127 if ((10 < finesine[1]) && (finesine[1] < 100)) {
128 lprintf(LO_DEBUG, "ok.");
129 return; // Endianness is correct
130 }
131
132 // Must correct endianness of every long loaded (!)
133 #define CORRECT_TABLE_ENDIAN(tbl) \
134 for (n = 0; n<sizeof(tbl)/sizeof(tbl[0]); n++) tbl[n] = doom_swap_l(tbl[n])
135
136 CORRECT_TABLE_ENDIAN(finesine);
137 CORRECT_TABLE_ENDIAN(finetangent);
138 CORRECT_TABLE_ENDIAN(tantoangle);
139 lprintf(LO_DEBUG, "corrected.");
140 }
141 }