1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1997, 2005 - 3D Realms Entertainment
4
5 This file is part of Shadow Warrior version 1.2
6
7 Shadow Warrior is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 Original Source: 1997 - Frank Maddin and Jim Norwood
23 Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
24 */
25 //-------------------------------------------------------------------------
26
27 #include "compat.h"
28 #include "pragmas.h"
29
30 #include "interp.h"
31
32 #define MAXINTERPOLATIONS 1024
33 int numinterpolations = 0, startofdynamicinterpolations = 0;
34 int oldipos[MAXINTERPOLATIONS];
35 int bakipos[MAXINTERPOLATIONS];
36 int *curipos[MAXINTERPOLATIONS];
37
setinterpolation(int * posptr)38 void setinterpolation(int *posptr)
39 {
40 int i;
41
42 if (numinterpolations >= MAXINTERPOLATIONS)
43 return;
44
45 for (i = numinterpolations - 1; i >= 0; i--)
46 {
47 if (curipos[i] == posptr)
48 return;
49 }
50
51 curipos[numinterpolations] = posptr;
52 oldipos[numinterpolations] = *posptr;
53 numinterpolations++;
54 }
55
stopinterpolation(int * posptr)56 void stopinterpolation(int *posptr)
57 {
58 int i;
59
60 for (i = numinterpolations - 1; i >= startofdynamicinterpolations; i--)
61 {
62 if (curipos[i] == posptr)
63 {
64 numinterpolations--;
65 oldipos[i] = oldipos[numinterpolations];
66 bakipos[i] = bakipos[numinterpolations];
67 curipos[i] = curipos[numinterpolations];
68 }
69 }
70 }
71
updateinterpolations(void)72 void updateinterpolations(void) // Stick at beginning of domovethings
73 {
74 int i;
75
76 for (i = numinterpolations - 1; i >= 0; i--)
77 oldipos[i] = *curipos[i];
78 }
79
80 // must call restore for every do interpolations
81 // make sure you don't exit
dointerpolations(int smoothratio)82 void dointerpolations(int smoothratio) // Stick at beginning of drawscreen
83 {
84 int i, j, odelta, ndelta;
85
86 ndelta = 0;
87 j = 0;
88
89 for (i = numinterpolations - 1; i >= 0; i--)
90 {
91 bakipos[i] = *curipos[i];
92
93 odelta = ndelta;
94 ndelta = (*curipos[i]) - oldipos[i];
95
96 if (odelta != ndelta)
97 j = mulscale16(ndelta, smoothratio);
98
99 *curipos[i] = oldipos[i] + j;
100 }
101 }
102
restoreinterpolations(void)103 void restoreinterpolations(void) // Stick at end of drawscreen
104 {
105 int i;
106
107 for (i = numinterpolations - 1; i >= 0; i--)
108 *curipos[i] = bakipos[i];
109 }
110