diff options
Diffstat (limited to 'engines/cruise/polys.cpp')
-rw-r--r-- | engines/cruise/polys.cpp | 63 |
1 files changed, 25 insertions, 38 deletions
diff --git a/engines/cruise/polys.cpp b/engines/cruise/polys.cpp index 664b2dc004..98d64cdeba 100644 --- a/engines/cruise/polys.cpp +++ b/engines/cruise/polys.cpp @@ -23,6 +23,7 @@ */ #include "cruise/cruise_main.h" +#include "common/util.h" namespace Cruise { @@ -34,10 +35,6 @@ typedef char ColorP; #define SCREENHEIGHT 200 #define MAXPTS 10 #define putdot(x,y) {if ((y >= 0) && (y < SCREENHEIGHT)) dots[y][counters[y]++] = x;} -#define SWAP(x,y) {int temp = x; x = y; y = temp;} - -int MAX(int x, int y) {if(x>y){return x;}else{return y;}} -int MIN(int x, int y) {if(x<y){return x;}else{return y;}} void hline(int x1, int x2, int y, char c) { for (; x1 <= x2; x1++) { @@ -75,6 +72,7 @@ void bsubline_1(int x1, int y1, int x2, int y2, char c) { } } + void bsubline_2(int x1, int y1, int x2, int y2, char c) { int x, y, ddx, ddy, e; @@ -88,7 +86,6 @@ void bsubline_2(int x1, int y1, int x2, int y2, char c) { SWAP(y1, y2); } - for (y = y1, x = x1; y <= y2; y++) { pixel(x, y, c); @@ -108,7 +105,7 @@ void bsubline_3(int x1, int y1, int x2, int y2, char c) { ddx = abs(x1 - x2) << 1; ddy = abs(y2 - y1); - e = ddy - ddx; + e = ddy - ddx; ddy <<= 1; if (y1 > y2) { @@ -116,7 +113,6 @@ void bsubline_3(int x1, int y1, int x2, int y2, char c) { SWAP(y1, y2); } - for (y = y1, x = x1; y <= y2; y++) { pixel(x, y, c); @@ -136,7 +132,7 @@ void bsubline_4(int x1, int y1, int x2, int y2, char c) { ddy = abs(y2 - y1) << 1; ddx = abs(x1 - x2); - e = ddx - ddy; + e = ddx - ddy; ddx <<= 1; if (x1 > x2) { @@ -185,35 +181,32 @@ void line(int x1, int y1, int x2, int y2, char c) { bsubline_4(x1, y1, x2, y2, c); } else { bsubline_3(x1, y1, x2, y2, c); - } + } } -void fillpoly(short int* datas, int lineCount, ColorP color) -{ +void fillpoly(short int *datas, int lineCount, ColorP color) { static int dots[SCREENHEIGHT][MAXPTS]; static int counters[SCREENHEIGHT]; short int x1, y1, x2, y2; int i, j, k, dir = -2; double step, curx; - switch (lineCount) - { - case 0: // do nothing - return; - case 1: // draw pixel - pixel(datas[0], datas[1], color); - return; - case 2: // draw line - line(datas[0], datas[1], datas[2], datas[3], color); - return; - default: // go on and draw polygon - break; + switch (lineCount) { + case 0: // do nothing + return; + case 1: // draw pixel + pixel(datas[0], datas[1], color); + return; + case 2: // draw line + line(datas[0], datas[1], datas[2], datas[3], color); + return; + default: // go on and draw polygon + break; } // Reinit array counters - for (i = 0; i < SCREENHEIGHT; i++) - { + for (i = 0; i < SCREENHEIGHT; i++) { counters[i] = 0; } // Drawing lines @@ -230,18 +223,14 @@ void fillpoly(short int* datas, int lineCount, ColorP color) // line(x1, y1, x2, y2, color); // continue; - if (y1 == y2) - { + if (y1 == y2) { // printf("Horizontal line. x1: %i, y1: %i, x2: %i, y2: %i\n", x1, y1, x2, y2); - if (dir) - { + if (dir) { putdot(x1, y1); dir = 0; } - } - else - { - step = (double) (x2 - x1) / (y2 - y1); + } else { + step = (double)(x2 - x1) / (y2 - y1); // printf("x1: %i, y1 = %i, x2 = %i, y2 = %i, step: %f\n", x1, y1, x2, y2, step); @@ -276,11 +265,11 @@ void fillpoly(short int* datas, int lineCount, ColorP color) x2 = datas[0]; y2 = datas[1]; - if (((y1 < y2) && (dir == -1)) || ((y1 > y2) && (dir == 1)) || ((y1 == y2) && (dir == 0))) { + if (((y1 < y2) && (dir == -1)) || ((y1 > y2) && (dir == 1)) + || ((y1 == y2) && (dir == 0))) { // printf("Adding final extra (%i, %i)\n", x1, y1); putdot(x1, y1); } - // NOTE: all counters should be even now. If not, this is a bad (color) thing :-P // Sorting datas @@ -289,8 +278,7 @@ void fillpoly(short int* datas, int lineCount, ColorP color) // Very bad sorting... but arrays are very small (0, 2 or 4), so it's no quite use... for (j = 0; j < (counters[i] - 1); j++) { for (k = 0; k < (counters[i] - 1); k++) { - if (dots[i][k] > dots[i][k + 1]) - { + if (dots[i][k] > dots[i][k + 1]) { int temp; temp = dots[i][k]; dots[i][k] = dots[i][k + 1]; @@ -320,4 +308,3 @@ void fillpoly(short int* datas, int lineCount, ColorP color) } } // End of namespace Cruise - |