This repository has been archived by the owner on Jul 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffects.c
230 lines (205 loc) · 7.48 KB
/
effects.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <math.h>
#include <SDL/SDL_timer.h>
#include "ZeDemo.h"
#include "effects.h"
#include "precalcs.h"
#include "engine3d.h"
#define SWAP8(x) ( (((x) >> 4) & 0x0F) | (((x) << 4) & 0xF0) )
#define SWAP16(x) ( (((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00) )
#define SWAP32(x)( (((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) )
extern unsigned int fsin1[2048], fsin2[2048], fsin3[2048];
extern int prticks;
extern unsigned short sky1[];
extern unsigned short sky2[];
short floorstuff[2*WIDTH*HEIGHT];
unsigned char dist_angle[2*WIDTH*HEIGHT];
extern unsigned char rbmp[SSIZE];
extern unsigned char gbmp[SSIZE];
extern unsigned char bbmp[SSIZE];
extern unsigned char rbuffer[SSIZE];
extern unsigned char gbuffer[SSIZE];
extern unsigned char bbuffer[SSIZE];
extern short radir0[SSIZE];
extern short radir1[SSIZE];
extern short radir2[SSIZE];
extern short radir3[SSIZE];
extern short radir4[SSIZE];
extern short radir5[SSIZE];
void Polarplasma(unsigned short *vram, unsigned short shade[])
{
int x,y;
unsigned char c;
unsigned int c0;
unsigned int *vram32 = (unsigned int*)vram;
unsigned int k = prticks>>3;
int i, j = 0;
for (i=0; i<WIDTH*HEIGHT; i+=2)
{
c = dist_angle[j] + dist_angle[j+1] + k;
c0 = shade[c];
c = dist_angle[j+2] + dist_angle[j+3] + k;
*vram32++ = (shade[c]<<16) | c0;
j+=4;
}
}
void Plasma(unsigned short *vram, unsigned short shade[])
{
unsigned int *vram32 = (unsigned int*)vram;
unsigned int k = (prticks>>4)%438;
unsigned int x, y;
for (y=0; y<240; y++)
for (x=0; x<320; x+=8)
{
*vram32++ = shade[(fsin1[x] + fsin2[y] + fsin3[x+y+k]) & 255] | (shade[(fsin1[x+1] + fsin2[y] + fsin3[x+y+k+1]) & 255]<<16);
*vram32++ = shade[(fsin1[x+2] + fsin2[y] + fsin3[x+y+k+2]) & 255] | (shade[(fsin1[x+3] + fsin2[y] + fsin3[x+y+k+3]) & 255]<<16);
*vram32++ = shade[(fsin1[x+4] + fsin2[y] + fsin3[x+y+k+4]) & 255] | (shade[(fsin1[x+5] + fsin2[y] + fsin3[x+y+k+5]) & 255]<<16);
*vram32++ = shade[(fsin1[x+6] + fsin2[y] + fsin3[x+y+k+6]) & 255] | (shade[(fsin1[x+7] + fsin2[y] + fsin3[x+y+k+7]) & 255]<<16);
}
}
void DrawSky(unsigned short *vram)
{
int x, y, xp, yp = 256*255;
unsigned int *vram32 = (unsigned int*)vram;
unsigned int c0;
for (y=0; y<HEIGHT; y++)
{
for (x=0; x<WIDTH; x+=2)
{
xp = (x-(WIDTH>>1)) & 255;
c0 = sky1[xp + yp];
xp = (x+1-(WIDTH>>1)) & 255;
*vram32++ = (sky1[xp + yp]<<16) | c0;
}
yp-=256;
}
}
void Floor(unsigned short *vram, float ra, float zm)
{
int x,y;
int u,v;
int ira = SDL_GetTicks()>>4;
int izm = zm;
unsigned int c,i;
unsigned int *vram32 = (unsigned int*)vram;
i=0;
for (y=0;y<HEIGHT - (HEIGHT>>2);y++)
{
for (x=0;x<WIDTH;x+=2)
{
u = floorstuff[i+1] & 127;
v = (floorstuff[i] + ira) & 127;
c = sky2[u + (v<<7)];
u = floorstuff[i+3] & 127;
v = (floorstuff[i+2] + ira) & 127;
c = c | (sky2[u + (v<<7)]<<16);
i+=4;
*vram32++=c;
}
}
}
void Radial(unsigned short *avram, int fick)
{
int x,y,i,ri,sum;
int r,g,b;
int k = prticks/12;
int dcx = sin((double)k/73.0)*(WIDTH>>1);
int dcy = fick * sin((double)k/112.0)*(HEIGHT>>1);
int dci = dcx + dcy*WIDTH;
unsigned short *vram;
//Initialize the buffer or something
unsigned int *rbuffer32 = (unsigned int*)rbuffer, *gbuffer32 = (unsigned int*)gbuffer, *bbuffer32 = (unsigned int*)bbuffer;
for (i=0; i<SSIZE; i+=4)
{
*rbuffer32++ = rbmp[i] | (rbmp[i+1]<<8) | (rbmp[i+2]<<16) | (rbmp[i+3]<<24);
*gbuffer32++ = gbmp[i] | (gbmp[i+1]<<8) | (gbmp[i+2]<<16) | (gbmp[i+3]<<24);
*bbuffer32++ = bbmp[i] | (bbmp[i+1]<<8) | (bbmp[i+2]<<16) | (bbmp[i+3]<<24);
}
/*
Quadrants:
Q2 | Q1
---|--- <= The Screen
Q3 | Q4
Q1 and Q4 are kinda broken rn.
*/
// Quadrant 1
vram=(unsigned short*)avram + WIDTH/2 + (HEIGHT/2-1)*WIDTH + dci;
i=WIDTH/2 + (HEIGHT/2-1)*WIDTH + dci;
ri=0;
for (y=HEIGHT/2-1+dcy; y>=0; y--)
{
for (x=WIDTH/2+dcx; x<WIDTH; x++)
{
rbuffer[i] = (rbuffer[i] + rbuffer[i + radir3[ri]] + rbuffer[i + radir4[ri]] + rbuffer[i + radir5[ri]])>>2;
gbuffer[i] = (gbuffer[i] + gbuffer[i + radir3[ri]] + gbuffer[i + radir4[ri]] + gbuffer[i + radir5[ri]])>>2;
bbuffer[i] = (bbuffer[i] + bbuffer[i + radir3[ri]] + bbuffer[i + radir4[ri]] + bbuffer[i + radir5[ri]])>>2;
//RGB565 0xFFFF
*vram++ = ((rbuffer[i] >> 3) << 11) | ((gbuffer[i] >> 2) << 5) | (bbuffer[i] >> 3);
i++;
ri++;
}
i=i-3*(WIDTH/2)+dcx;
ri+=WIDTH/2+dcx;
vram=vram-3*(WIDTH/2)+dcx;
}
// Quadrant 2
vram=(unsigned short*)avram + (WIDTH/2 - 1) + (HEIGHT/2 - 1)*WIDTH + dci;
i=(WIDTH/2-1) + (HEIGHT/2-1)*WIDTH + dci;
ri=0;
for (y=HEIGHT/2-1+dcy; y>=0; y--)
{
for (x=WIDTH/2-1+dcx; x>=0; x--)
{
rbuffer[i] = (rbuffer[i] + rbuffer[i - radir0[ri]] + rbuffer[i - radir1[ri]] + rbuffer[i - radir2[ri]])>>2;
gbuffer[i] = (gbuffer[i] + gbuffer[i - radir0[ri]] + gbuffer[i - radir1[ri]] + gbuffer[i - radir2[ri]])>>2;
bbuffer[i] = (bbuffer[i] + bbuffer[i - radir0[ri]] + bbuffer[i - radir1[ri]] + bbuffer[i - radir2[ri]])>>2;
//RGB565 0xFFFF
//correct
*vram-- = ((rbuffer[i] >> 3) << 11) | ((gbuffer[i] >> 2) << 5) | (bbuffer[i] >> 3);
i--;
ri++;
}
i=i-WIDTH/2+dcx;
ri+=WIDTH/2-dcx;
vram=vram-WIDTH/2+dcx;
}
// Quadrant 3
vram=(unsigned short*)avram + (WIDTH/2 - 1) + (HEIGHT/2)*WIDTH + dci;
i=(WIDTH/2-1) + (HEIGHT/2)*WIDTH + dci;
ri=0;
for (y=HEIGHT/2+dcy; y<HEIGHT; y++)
{
for (x=WIDTH/2-1+dcx; x>=0; x--)
{
rbuffer[i] = (rbuffer[i] + rbuffer[i - radir3[ri]] + rbuffer[i - radir4[ri]] + rbuffer[i - radir5[ri]])>>2;
gbuffer[i] = (gbuffer[i] + gbuffer[i - radir3[ri]] + gbuffer[i - radir4[ri]] + gbuffer[i - radir5[ri]])>>2;
bbuffer[i] = (bbuffer[i] + bbuffer[i - radir3[ri]] + bbuffer[i - radir4[ri]] + bbuffer[i - radir5[ri]])>>2;
//RGB565 0xFFFF
*vram-- = ((rbuffer[i] >> 3) << 11) | ((gbuffer[i] >> 2) << 5) | (bbuffer[i] >> 3);
i--;
ri++;
}
i+=3*(WIDTH/2)+dcx;
ri+=WIDTH/2-dcx;
vram+=3*(WIDTH/2)+dcx;
}
// Quadrant 4
vram=(unsigned short*)avram + WIDTH/2 + (HEIGHT/2)*WIDTH + dci;
i=WIDTH/2 + (HEIGHT/2)*WIDTH + dci;
ri=0;
for (y=HEIGHT/2+dcy; y<HEIGHT; y++)
{
for (x=WIDTH/2+dcx; x<WIDTH; x++)
{
rbuffer[i] = (rbuffer[i] + rbuffer[i + radir0[ri]] + rbuffer[i + radir1[ri]] + rbuffer[i + radir2[ri]])>>2;
gbuffer[i] = (gbuffer[i] + gbuffer[i + radir0[ri]] + gbuffer[i + radir1[ri]] + gbuffer[i + radir2[ri]])>>2;
bbuffer[i] = (bbuffer[i] + bbuffer[i + radir0[ri]] + bbuffer[i + radir1[ri]] + bbuffer[i + radir2[ri]])>>2;
//RGB565 0xFFFF
*vram++ = ((rbuffer[i] >> 3) << 11) | ((gbuffer[i] >> 2) << 5) | (bbuffer[i] >> 3);
i++;
ri++;
}
i+=WIDTH/2+dcx;
ri+=WIDTH/2+dcx;
vram+=WIDTH/2+dcx;
}
}