]> 4ch.mooo.com Git - 16.git/blob - src/v2/source/verge/MAPED/SSAVER.C
b2ce0a55dd823a2f99e0a9d5e668b720e36db18e
[16.git] / src / v2 / source / verge / MAPED / SSAVER.C
1 /*\r
2 Copyright (C) 1998 BJ Eirich (aka vecna)\r
3 This program is free software; you can redistribute it and/or\r
4 modify it under the terms of the GNU General Public License\r
5 as published by the Free Software Foundation; either version 2\r
6 of the License, or (at your option) any later version.\r
7 This program is distributed in the hope that it will be useful,\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
10 See the GNU General Public Lic\r
11 See the GNU General Public License for more details.\r
12 You should have received a copy of the GNU General Public License\r
13 along with this program; if not, write to the Free Software\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
15 */\r
16 \r
17 #include <math.h>\r
18 #include <malloc.h>\r
19 #include <string.h>\r
20 \r
21 #include "maped.h"\r
22 #include "timer.h"\r
23 #include "vdriver.h"\r
24 \r
25 #include "mouse.h"\r
26 \r
27 // ================================= Data ====================================\r
28 \r
29 static int *dmapx = NULL;\r
30 static int *dmapy = NULL;\r
31 static unsigned char *dscr = NULL;\r
32 static int recalc_distort = 1;\r
33 static long build = 0;\r
34 \r
35 // ================================= Code ====================================\r
36 \r
37 // aen\r
38 static void init_distort(void)\r
39   {\r
40   int x = 0;\r
41   int y = 0;\r
42   int *dx = NULL;\r
43   int *dy = NULL;\r
44 \r
45   if (dmapx) vfree(dmapx); dmapx=NULL;\r
46   if (dmapy) vfree(dmapy); dmapy=NULL;\r
47   if (dscr) vfree(dscr); dscr=NULL;\r
48 \r
49   // allocate distort lookups\r
50   dmapx = (int *) valloc(tsx*tsy*4,"ssaver X",0);\r
51   dmapy = (int *) valloc(tsx*tsy*4,"ssaver Y",0);\r
52 \r
53   // allocate distort image buffer\r
54   dscr = (unsigned char *) valloc(tsx*tsy,"ssaver scrn",0);\r
55 \r
56   // copy viewport into distort buffer\r
57   memcpy(dscr, screen, tsx*tsy);\r
58 \r
59   dx = dmapx;\r
60   dy = dmapy;\r
61 \r
62   // generate distort lookups\r
63   for (y=0; y<tsy; ++y) {\r
64     for (x=0; x<tsx; ++x) {\r
65       *dx++ = sin(y*5*(360.0/tsy)*(3.14/180))*10;\r
66       *dy++ = sin(x*5*(360.0/tsx)*(3.14/180))*10;\r
67       }\r
68     }\r
69   }\r
70 \r
71 // aen\r
72 static void do_distort(void)\r
73   {\r
74   unsigned char *ds=NULL;\r
75   int x=0;\r
76   int y=0;\r
77   static int xt=0;\r
78   static int yt=0;\r
79   int xx=0;\r
80   int yy=0;\r
81   static int thresh=0;\r
82 \r
83   if (recalc_distort) {\r
84     init_distort();\r
85     recalc_distort=0;\r
86     }\r
87 \r
88   ds=screen; //+(tsx*16)+16;\r
89 \r
90   do {\r
91     yy = (y+thresh);\r
92     if (yy >= tsy) yy -= tsy;\r
93     xt += (dmapx[(yy*tsx)+x] * build) >> 16;\r
94 \r
95     xx = (x+((thresh*tsx)/tsy));\r
96     if (xx >= tsx) xx -= tsx;\r
97     yt += (dmapy[(yy*tsx)+xx] * build) >> 16;\r
98 \r
99     if (xt < 0) xt += tsx;\r
100     if (yt < 0) yt += tsy;\r
101     if (xt >= tsx) xt -= tsx;\r
102     if (yt >= tsy) yt -= tsy;\r
103 \r
104     *ds++ = dscr[(yt*tsx)+xt];\r
105 \r
106     ++x;\r
107     if (x >= tsx) {\r
108       x = 0;\r
109       ++y;\r
110       //ds+=32;\r
111       }\r
112 \r
113     xt = x;\r
114     yt = y;\r
115 \r
116     } while (y < tsy);\r
117 \r
118   thresh += 2;\r
119   if (thresh >= tsy)\r
120     thresh -= tsy;\r
121 \r
122   if (build < 85196) //1.5\r
123     build += 3276;\r
124   }\r
125 \r
126 void ScreenSaver(void)\r
127   {\r
128   while (idlect > 750)\r
129     {\r
130     ReadMouse();\r
131     do_distort();\r
132     ShowPage();\r
133     }\r
134   recalc_distort=1;\r
135   build = 0;\r
136   }\r