1 // ID_VL.C
2
3 #include <string.h>
4 #include "c_cvars.h"
5 #include "wl_def.h"
6 #include "id_in.h"
7 #include "id_vl.h"
8 #include "id_vh.h"
9 #include "w_wad.h"
10 #include "r_2d/r_main.h"
11 #include "r_data/colormaps.h"
12 #include "v_font.h"
13 #include "v_video.h"
14 #include "v_palette.h"
15 #include "wl_draw.h"
16 #include "wl_game.h"
17 #include "wl_main.h"
18 #include "wl_play.h"
19
20
21 // Uncomment the following line, if you get destination out of bounds
22 // assertion errors and want to ignore them during debugging
23 //#define IGNORE_BAD_DEST
24
25 #ifdef IGNORE_BAD_DEST
26 #undef assert
27 #define assert(x) if(!(x)) return
28 #define assert_ret(x) if(!(x)) return 0
29 #else
30 #define assert_ret(x) assert(x)
31 #endif
32
33 bool fullscreen = true;
34 bool usedoublebuffering = true;
35 unsigned screenWidth = 640;
36 unsigned screenHeight = 480;
37 unsigned screenBits = static_cast<unsigned> (-1); // use "best" color depth according to libSDL
38 float screenGamma = 1.0f;
39
40 SDL_Surface *curSurface = NULL;
41 unsigned curPitch;
42
43 unsigned scaleFactorX, scaleFactorY;
44
45 bool screenfaded;
46
47 static struct
48 {
49 uint8_t r,g,b;
50 int amount;
51 } currentBlend;
52
53 //===========================================================================
54
VL_ReadPalette(const char * lump)55 void VL_ReadPalette(const char* lump)
56 {
57 InitPalette(lump);
58 if(currentBlend.amount)
59 V_SetBlend(currentBlend.r, currentBlend.g, currentBlend.b, currentBlend.amount);
60 R_InitColormaps();
61 V_RetranslateFonts();
62 }
63
64 /*
65 =======================
66 =
67 = VL_SetVGAPlaneMode
68 =
69 =======================
70 */
71
72 void I_InitGraphics ();
VL_SetVGAPlaneMode(bool forSignon)73 void VL_SetVGAPlaneMode (bool forSignon)
74 {
75 I_InitGraphics();
76 Video->SetResolution(screenWidth, screenHeight, 8);
77 screen->Lock(true);
78 R_SetupBuffer ();
79 screen->Unlock();
80
81 scaleFactorX = CleanXfac;
82 scaleFactorY = CleanYfac;
83
84 pixelangle = (short *) malloc(SCREENWIDTH * sizeof(short));
85 CHECKMALLOCRESULT(pixelangle);
86 wallheight = (int *) malloc(SCREENWIDTH * sizeof(int));
87 CHECKMALLOCRESULT(wallheight);
88
89 NewViewSize(viewsize);
90 }
91
92 /*
93 =============================================================================
94
95 PALETTE OPS
96
97 To avoid snow, do a WaitVBL BEFORE calling these
98
99 =============================================================================
100 */
101
102 /*
103 =================
104 =
105 = VL_FadeOut
106 =
107 = Fades the current palette to the given color in the given number of steps
108 =
109 =================
110 */
111
112 static int fadeR = 0, fadeG = 0, fadeB = 0;
VL_Fade(int start,int end,int red,int green,int blue,int steps)113 void VL_Fade (int start, int end, int red, int green, int blue, int steps)
114 {
115 end <<= FRACBITS;
116 start <<= FRACBITS;
117
118 const fixed aStep = (end-start)/steps;
119
120 VL_WaitVBL(1);
121
122 //
123 // fade through intermediate frames
124 //
125 for (int a = start;(aStep < 0 ? a > end : a < end);a += aStep)
126 {
127 if(!usedoublebuffering || screenBits == 8) VL_WaitVBL(1);
128 V_SetBlend(red, green, blue, a>>FRACBITS);
129 VH_UpdateScreen();
130 }
131
132 //
133 // final color
134 //
135 V_SetBlend (red,green,blue,end>>FRACBITS);
136 // Not quite sure why I need to call this twice.
137 VH_UpdateScreen();
138 VH_UpdateScreen();
139
140 screenfaded = end != 0;
141
142 // Clear out any input at this point that may be stored up. This solves
143 // issues such as starting facing the wrong angle in super 3d noah's ark.
144 IN_ProcessEvents();
145 }
146
VL_FadeOut(int start,int end,int red,int green,int blue,int steps)147 void VL_FadeOut (int start, int end, int red, int green, int blue, int steps)
148 {
149 fadeR = red;
150 fadeG = green;
151 fadeB = blue;
152 VL_Fade(start, end, red, green, blue, steps);
153 }
154
155
156 /*
157 =================
158 =
159 = VL_FadeIn
160 =
161 =================
162 */
163
VL_FadeIn(int start,int end,int steps)164 void VL_FadeIn (int start, int end, int steps)
165 {
166 if(screenfaded)
167 VL_Fade(end, start, fadeR, fadeG, fadeB, steps);
168 }
169
170 /*
171 =============================================================================
172
173 PIXEL OPS
174
175 =============================================================================
176 */
177
VL_LockSurface()178 byte *VL_LockSurface()
179 {
180 screen->Lock(false);
181 return (byte *) screen->GetBuffer();
182 }
183
VL_UnlockSurface()184 void VL_UnlockSurface()
185 {
186 screen->Unlock();
187 }
188