~ubuntu-branches/ubuntu/karmic/rott/karmic-proposed

« back to all changes in this revision

Viewing changes to rott/lookups.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabian Greffrath
  • Date: 2008-01-27 20:00:00 UTC
  • mfrom: (1.1.1 upstream) (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080127200000-myle9y0099o45sfv
Tags: 1.0+dfsg-2
* debian/patches/01-custom-datapath.dpatch,
  debian/patches/13-improve-makefile.dpatch:
  + Changed DATADIR back to "/usr/share/games/rott/".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Copyright (C) 1994-1995 Apogee Software, Ltd.
3
 
 
4
 
This program is free software; you can redistribute it and/or
5
 
modify it under the terms of the GNU General Public License
6
 
as published by the Free Software Foundation; either version 2
7
 
of the License, or (at your option) any later version.
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.
12
 
 
13
 
See the GNU General Public License for more details.
14
 
 
15
 
You should have received a copy of the GNU General Public License
16
 
along with this program; if not, write to the Free Software
17
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
 
 
19
 
*/
20
 
#include "rt_def.h"
21
 
#include "rt_util.h"
22
 
#include "rt_view.h"
23
 
#include <math.h>
24
 
#include <dos.h>
25
 
#include <stdio.h>
26
 
#include <stdarg.h>
27
 
#include <fcntl.h>
28
 
#include <errno.h>
29
 
#include <conio.h>
30
 
#include <string.h>
31
 
#include <stdio.h>
32
 
#include <ctype.h>
33
 
#include <io.h>
34
 
#include <stdlib.h>
35
 
#include <sys\stat.h>
36
 
 
37
 
//MED
38
 
#include "memcheck.h"
39
 
 
40
 
#define PANGLES 512
41
 
#define NUMSINANGLES FINEANGLES+FINEANGLEQUAD+1
42
 
 
43
 
fixed  pangle[PANGLES];
44
 
long   sintable[NUMSINANGLES];
45
 
short  tantable[FINEANGLES];
46
 
byte   gammatable[GAMMAENTRIES];
47
 
 
48
 
extern  int      _argc;
49
 
extern  char **  _argv;
50
 
 
51
 
/*
52
 
=================
53
 
=
54
 
= Error
55
 
=
56
 
= For abnormal program terminations
57
 
=
58
 
=================
59
 
*/
60
 
 
61
 
void Error (char *error, ...)
62
 
{
63
 
        va_list argptr;
64
 
 
65
 
        va_start (argptr,error);
66
 
        vprintf (error,argptr);
67
 
        va_end (argptr);
68
 
        printf ("\n");
69
 
        exit (1);
70
 
}
71
 
 
72
 
 
73
 
int SafeOpenWrite (char *_filename)
74
 
{
75
 
        int     handle;
76
 
    char filename[MAX_PATH];
77
 
    strncpy(filename, _filename, sizeof (filename));
78
 
    filename[sizeof (filename) - 1] = '\0';
79
 
    FixFilePath(filename);
80
 
 
81
 
        handle = open(filename,O_RDWR | O_BINARY | O_CREAT | O_TRUNC
82
 
        , S_IREAD | S_IWRITE);
83
 
 
84
 
        if (handle == -1)
85
 
                Error ("Error opening %s: %s",filename,strerror(errno));
86
 
 
87
 
        return handle;
88
 
}
89
 
 
90
 
 
91
 
void SafeWrite (int handle, void *buffer, long count)
92
 
{
93
 
        unsigned        iocount;
94
 
 
95
 
        while (count)
96
 
        {
97
 
                iocount = count > 0x8000 ? 0x8000 : count;
98
 
                if (write (handle,buffer,iocount) != iocount)
99
 
                        Error ("File write failure");
100
 
                buffer = (void *)( (byte *)buffer + iocount );
101
 
                count -= iocount;
102
 
        }
103
 
}
104
 
 
105
 
 
106
 
 
107
 
 
108
 
void CalcPixelAngles ( void )
109
 
{
110
 
    int   i;
111
 
    long  intang;
112
 
    double  angle;
113
 
    double  tang;
114
 
 
115
 
    const   double radtoint = (double)FINEANGLES/2/PI;
116
 
 
117
 
 
118
 
    for (i=0;i<PANGLES;i++)
119
 
       {
120
 
       // start 1/2 pixel over, so viewangle bisects two middle pixels
121
 
       tang = ((((double)i*160.0)+80.0)/(FPFOCALWIDTH*(double)PANGLES));
122
 
       angle = atan(tang);
123
 
       intang = ((long)(angle*radtoint));
124
 
       pangle[i] = intang;
125
 
       }
126
 
}
127
 
 
128
 
 
129
 
 
130
 
void BuildSinTable (void)
131
 
{
132
 
   int   i;
133
 
   double  angle,anglestep;
134
 
   double  sinangle;
135
 
   fixed  value;
136
 
 
137
 
   angle = 0;
138
 
   anglestep = (double)(PI/2/FINEANGLEQUAD);
139
 
   for (i=0;i<=FINEANGLEQUAD;i++)
140
 
      {
141
 
      sinangle=sin(angle);
142
 
      value=(fixed)((double)GLOBAL1*sinangle);
143
 
      sintable[i]     =
144
 
      sintable[i+FINEANGLES]  =
145
 
      sintable[FINEANGLES/2-i] = value;
146
 
      sintable[FINEANGLES-i] = -value;
147
 
      sintable[FINEANGLES/2+i] = -value;
148
 
      angle += anglestep;
149
 
      }
150
 
}
151
 
 
152
 
void BuildTanTable (void)
153
 
{
154
 
   int   i;
155
 
   double  angle,anglestep;
156
 
   double  tanangle;
157
 
   fixed  value;
158
 
 
159
 
   angle = 0;
160
 
   anglestep = (double)(PI*2/FINEANGLES);
161
 
   for (i=0;i<FINEANGLES;i++)
162
 
      {
163
 
      tanangle=tan(angle);
164
 
      value=(fixed)((double)GLOBAL1*tanangle);
165
 
      tantable[i] =(short) (value>>1);
166
 
      angle += anglestep;
167
 
      }
168
 
}
169
 
 
170
 
void BuildGammaTable (void)
171
 
{
172
 
   int     l, i, inf;
173
 
   int     j;
174
 
   int     gGamma=0x100;
175
 
   j=0;
176
 
   for (l=0 ; l<NUMGAMMALEVELS ; l++,gGamma+=32)
177
 
      {
178
 
      double nGamma = (double)256 / gGamma;
179
 
      double nScale = (double)63  / pow(63, nGamma);
180
 
 
181
 
      for ( i = 0; i < 64; i++ )
182
 
         {
183
 
         inf = pow(i, nGamma) * nScale;
184
 
         if (inf < 0)
185
 
            inf = 0;
186
 
         if (inf > 63)
187
 
            inf = 63;
188
 
         gammatable[j++]=inf;
189
 
         }
190
 
      }
191
 
}
192
 
 
193
 
void main ()
194
 
{
195
 
   int handle;
196
 
   int size;
197
 
 
198
 
   if (_argc!=2)
199
 
      {
200
 
      printf("LOOKUPS -- Apogee Software (c) 1994\n");
201
 
      printf("\n USAGE:    lookups <name.dat>\n");
202
 
      exit(0);
203
 
      }
204
 
   handle=SafeOpenWrite (_argv[1]);
205
 
   CalcPixelAngles();
206
 
   BuildSinTable();
207
 
   BuildTanTable();
208
 
   BuildGammaTable();
209
 
   size=PANGLES;
210
 
   SafeWrite(handle,&size,sizeof(int));
211
 
   SafeWrite(handle,&pangle[0],sizeof(fixed)*size);
212
 
   size=NUMSINANGLES;
213
 
   SafeWrite(handle,&size,sizeof(int));
214
 
   SafeWrite(handle,&sintable[0],sizeof(fixed)*size);
215
 
   size=FINEANGLES;
216
 
   SafeWrite(handle,&size,sizeof(int));
217
 
   SafeWrite(handle,&tantable[0],sizeof(short)*size);
218
 
   size=GAMMAENTRIES;
219
 
   SafeWrite(handle,&size,sizeof(int));
220
 
   SafeWrite(handle,&gammatable[0],sizeof(byte)*size);
221
 
   close (handle);
222
 
}