-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.h
160 lines (135 loc) · 4.02 KB
/
renderer.h
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
#pragma once
#include <vector>
#include "gloommap.h"
#include "gloommaths.h"
#include "quick.h"
#include "objectgraphics.h"
#include <SDL2/SDL.h>
class GloomMap;
class Camera
{
public:
Quick x;
int16_t y;
Quick z;
Quick rotquick;
};
class Wall
{
public:
int16_t wl_lsx; // leftmost screen X
int16_t wl_rsx; // rightmost screen X
int16_t wl_nz; // near Z!
int16_t wl_fz; // far Z!
int16_t wl_lx; //
int16_t wl_lz; //
int16_t wl_rx; //
int16_t wl_rz; //
uint16_t wl_a; //
uint16_t wl_b; //
uint32_t wl_c; //
uint16_t wl_sc; //
uint16_t wl_open;// 0 = door shut, $4000 = open!
uint8_t wl_t[8];// textures
// added this myself
int16_t len;
bool valid;
};
class Renderer
{
public:
void Init(SDL_Surface* nrendersurface, GloomMap* ngloommap, ObjectGraphics* nObjectGraphics);
void Render(Camera* Camera);
void SetTeleEffect(int32_t timer) {fadetimer = timer;};
void SetPlayerHit(bool hit) { playerhit = hit; };
void SetThermo(bool t) { thermo = t; };
//EXPERIMENTAL MULTITHREAD BUILD!
SDL_Thread* floorthread;
SDL_Thread* wallthread;
Camera* camerastash;
void DrawFloor(Camera* camera);
void RenderColumns(int32_t xstart, int32_t xinc)
{
for (int32_t x = xstart; x < renderwidth; x += xinc)
{
ProcessColumn(x, camerastash->y, ceilend, floorstart);
}
}
Renderer();
~Renderer();
private:
bool OriginSide(int16_t fx, int16_t fz, int16_t bx, int16_t bz);
bool PointInFront(int16_t fx, int16_t fz, Wall& z);
bool Intersect(int16_t t, int16_t x0, int16_t x1) { return (t >= x0) && (t <= x1); };
void DrawMap();
int16_t CastColumn(int32_t x, int16_t& zone, Quick& t);
void DrawColumn(int32_t x, int32_t ystart, int32_t h, Column* texturedata, int32_t z, int32_t palused);
void DrawCeil(Camera* camera);
void DrawObjects(Camera* camera);
void DrawBlood(Camera* camera);
Column* GetTexColumn(int hitzone, Quick texpos, int& basetexture);
void ProcessColumn(const uint32_t& x, const int16_t& y, std::vector<int32_t>& ceilend, std::vector<int32_t>& floorstart);
SDL_Surface* rendersurface;
GloomMap* gloommap;
ObjectGraphics* objectgraphics;
std::vector<Wall> walls;
int32_t renderwidth = 320;
int32_t renderheight = 256;
int32_t halfrenderwidth = 160;
int32_t halfrenderheight = 128;
int32_t focmult = 256;
std::vector<Quick> castgrads;
std::vector<int32_t> zbuff;
std::vector<int32_t> ceilend;
std::vector<int32_t> floorstart;
// I'm not sure how gloom does screen dimming, I've implemented my own lookup tables
static const uint32_t darkpalettes[16][16];
//for fadeout/in
int32_t fadetimer;
//for damage indication
bool playerhit;
// for thermo glasses effect
bool thermo;
// I've split these out to enable inlining better
inline uint32_t GetDimPalette(int32_t z)
{
auto p = z / 128; if (p > 15) p = 15;
return p;
}
inline void ColourModifyFade(const uint8_t& rin, const uint8_t& gin, const uint8_t& bin, uint32_t& col, const int32_t& p)
{
int32_t r = darkpalettes[p][rin >> 4];
int32_t g = darkpalettes[p][gin >> 4];
int32_t b = darkpalettes[p][bin >> 4];
// gloom deluxe fade to bluish
r = (r * (25 - fadetimer) + 128 * fadetimer) / 25;
g = (g * (25 - fadetimer) + 128 * fadetimer) / 25;
b = (b * (25 - fadetimer) + 255 * fadetimer) / 25;
if (playerhit)
{
g = 0; b = 0;
}
col = 0xFF000000 | (r << 16) | (g << 8) | b;
};
inline void ColourModify(const uint8_t& rin, const uint8_t& gin, const uint8_t& bin, uint32_t& col, const int32_t& p)
{
int32_t r = darkpalettes[p][rin >> 4];
int32_t g = darkpalettes[p][gin >> 4];
int32_t b = darkpalettes[p][bin >> 4];
//if (fadetimer)
//{
// // gloom deluxe fade to bluish
// r = (r * (25 - fadetimer) + 128 * fadetimer) / 25;
// g = (g * (25 - fadetimer) + 128 * fadetimer) / 25;
// b = (b * (25 - fadetimer) + 255 * fadetimer) / 25;
//}
if (playerhit)
{
g = 0; b = 0;
}
col = 0xFF000000 | (r << 16) | (g << 8) | b;
};
std::list<MapObject> strips;
// needed for pushing transparent strips
SDL_mutex* wallmutex;
};