Skip to content

Commit b145bd7

Browse files
committed
Added unsafe functions
1 parent 8599a22 commit b145bd7

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed

examples/clfps.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ int main()
366366
{
367367
// Each Row
368368
if (y <= nCeiling)
369-
pluto_unset_pix(x, y);
369+
pluto_unset_upix(x, y);
370370
else if (y > nCeiling && y <= nFloor)
371-
pluto_set_cpix(x, y, nShade, nShade, nShade);
371+
pluto_set_ucpix(x, y, nShade, nShade, nShade);
372372
else // Floor
373373
{
374374
// Shade floor based on distance
@@ -384,7 +384,7 @@ int main()
384384
else
385385
nShade = 15;
386386
//screen[y*nScreenWidth + x] = nShade;
387-
pluto_set_cpix(x, y, nShade, nShade, nShade);
387+
pluto_set_ucpix(x, y, nShade, nShade, nShade);
388388
}
389389
}
390390
}

examples/clfps_rgb.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ int main()
268268
for (int y = 0; y < n_screen_height; y++)
269269
{
270270
if (y <= nCeiling)
271-
pluto_unset_pix(x, y);
271+
pluto_unset_upix(x, y);
272272
else if (y > nCeiling && y <= nFloor)
273-
pluto_set_cpix(x, y, shades[shade_n][0], shades[shade_n][1], shades[shade_n][2]);
273+
pluto_set_ucpix(x, y, shades[shade_n][0], shades[shade_n][1], shades[shade_n][2]);
274274
else
275275
{
276276
float b = 1.0f - (((float)y - n_screen_height / 2.0f) / ((float)n_screen_height / 2.0f));
@@ -285,7 +285,7 @@ int main()
285285
else
286286
shade_n = 15;
287287

288-
pluto_set_cpix(x, y, shade_n, shade_n, shade_n);
288+
pluto_set_ucpix(x, y, shade_n, shade_n, shade_n);
289289
}
290290
}
291291
}

src/drw.c

+31-7
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,53 @@ void pluto_set_pix(int x, int y)
4242
{
4343
if (PIX_OOB(x, y))
4444
return;
45+
46+
pluto_set_upix(x, y);
47+
}
48+
49+
void pluto_set_upix(int x, int y)
50+
{
4551
_pluto_canvas.bitmap[(y >> 2) * _pluto_canvas.width + (x >> 1)] |= _pluto_pixmap[y % 4][x % 2];
4652
}
4753

54+
void pluto_unset_pix(int x, int y)
55+
{
56+
if (PIX_OOB(x, y))
57+
return;
58+
59+
pluto_unset_upix(x, y);
60+
}
61+
62+
void pluto_unset_upix(int x, int y)
63+
{
64+
_pluto_canvas.bitmap[(y >> 2) * _pluto_canvas.width + (x >> 1)] &= ~_pluto_pixmap[y % 4][x % 2];
65+
}
66+
4867
void pluto_set_pix_colour(int x, int y, uint8_t red, uint8_t green, uint8_t blue)
4968
{
5069
if (PIX_OOB(x, y))
5170
return;
71+
72+
pluto_set_upix_colour(x, y, red, green, blue);
73+
}
74+
75+
void pluto_set_upix_colour(int x, int y, uint8_t red, uint8_t green, uint8_t blue)
76+
{
5277
_pluto_canvas.pix_colour[y * (_pluto_canvas.width << 1) + x] = (pluto_colour_t){red, green, blue};
5378
}
5479

5580
void pluto_set_cpix(int x, int y, uint8_t red, uint8_t green, uint8_t blue)
5681
{
5782
if (PIX_OOB(x, y))
5883
return;
59-
pluto_set_pix(x, y);
60-
pluto_set_pix_colour(x, y, red, green, blue);
84+
85+
pluto_set_ucpix(x, y, red, green, blue);
6186
}
6287

63-
void pluto_unset_pix(int x, int y)
88+
void pluto_set_ucpix(int x, int y, uint8_t red, uint8_t green, uint8_t blue)
6489
{
65-
if (PIX_OOB(x, y))
66-
return;
67-
_pluto_canvas.bitmap[(y >> 2) * _pluto_canvas.width + (x >> 1)] &= ~_pluto_pixmap[y % 4][x % 2];
90+
pluto_set_upix(x, y);
91+
pluto_set_upix_colour(x, y, red, green, blue);
6892
}
6993

70-
void pluto_sigwinch(int);
94+
void pluto_sigwinch(int);

src/pluto.h

+22
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ extern void pluto_clear_buffers();
8585
extern void pluto_deinit();
8686
/* Free resources and restore states */
8787

88+
/* Pixel functions where 'pix' is prefixed with 'u' are unsafe functions (without bounds checking) */
89+
8890
extern void pluto_set_pix_colour(int x, int y, uint8_t red, uint8_t green, uint8_t blue);
91+
/* Set a pixel's colour to a 24-bit value
92+
* Same as pluto_set_upix_colour()
93+
*/
94+
95+
extern void pluto_set_upix_colour(int x, int y, uint8_t red, uint8_t green, uint8_t blue);
8996
/* Set a pixel's colour to a 24-bit value
9097
* The colours of the pixels in a block are averaged
9198
* - int x: x position from origin
@@ -96,18 +103,33 @@ extern void pluto_set_pix_colour(int x, int y, uint8_t red, uint8_t green, uint8
96103
*/
97104

98105
extern void pluto_set_cpix(int x, int y, uint8_t red, uint8_t green, uint8_t blue);
106+
/* Set a pixel, and it's colour to a 24-bit value
107+
* Same as pluto_set_ucpix()
108+
*/
109+
110+
extern void pluto_set_ucpix(int x, int y, uint8_t red, uint8_t green, uint8_t blue);
99111
/* Set a pixel, and it's colour to a 24-bit value
100112
* A wrapper for pluto_set_pix and pluto_set_pix_colour
101113
* Parameters are same as those for pluto_set_pix_colour
102114
*/
103115

104116
extern void pluto_set_pix(int x, int y);
117+
/* Set a pixel in the bitmap buffer:
118+
* Same as pluto_set_upix()
119+
*/
120+
121+
extern void pluto_set_upix(int x, int y);
105122
/* Set a pixel in the bitmap buffer:
106123
* - int x: x position from origin
107124
* - int y: y position from origin
108125
*/
109126

110127
extern void pluto_unset_pix(int x, int y);
128+
/* Unset a pixel in the bitmap buffer:
129+
* Same as pluto_unset_upix()
130+
*/
131+
132+
extern void pluto_unset_upix(int x, int y);
111133
/* Unset a pixel in the bitmap buffer:
112134
* - int x: x position from origin
113135
* - int y: y position from origin

0 commit comments

Comments
 (0)