MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DrawProceduralLine

Function DrawProceduralLine

Descent3/procedurals.cpp:275–337  ·  view source on GitHub ↗

Draws a line into the passed in bitmap

Source from the content-addressed store, hash-verified

273}
274// Draws a line into the passed in bitmap
275void DrawProceduralLine(int x1, int y1, int x2, int y2, uint8_t color) {
276 int DY, DX;
277 int i, x, y, yinc = 1, xinc = 1, error_term;
278
279 uint8_t *surface_ptr = ProcDestData;
280
281 int xmask = PROC_SIZE - 1;
282 int ymask = PROC_SIZE - 1;
283
284 // Check to see if our x coords are reversed
285 if (x1 > x2) {
286 std::swap(x1, x2);
287 std::swap(y1, y2);
288 }
289 DX = x2 - x1;
290 DY = y2 - y1;
291 if (DX < 0) {
292 xinc = -1;
293 DX = -DX;
294 }
295 if (DY < 0) {
296 yinc = -1;
297 DY = -DY;
298 }
299 if (DX >= DY) // X is greater than y
300 {
301 error_term = 0;
302 x = x1 & xmask;
303 y = y1 & ymask;
304 surface_ptr += y * PROC_SIZE;
305 for (i = 0; i < DX; i++) {
306
307 *(surface_ptr + x) = color;
308 x += xinc;
309 x &= xmask;
310 error_term += DY;
311 if (error_term >= DX) {
312 y += yinc;
313 y &= ymask;
314 surface_ptr = ProcDestData + (y * PROC_SIZE);
315 error_term -= DX;
316 }
317 }
318 } else {
319 error_term = 0;
320 x = x1 & xmask;
321 y = y1 & ymask;
322 surface_ptr += y * PROC_SIZE;
323
324 for (i = 0; i < DY; i++) {
325 *(surface_ptr + x) = color;
326 y += yinc;
327 y &= ymask;
328 error_term += DX;
329 surface_ptr = ProcDestData + (y * PROC_SIZE);
330 if (error_term >= DY) {
331 x += xinc;
332 x &= xmask;

Callers 1

AddProcLightningFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected