- [NEW] Neteja de estats interns i reimplementació del sistema de pset i primitives
This commit is contained in:
484
source/mini.cpp
484
source/mini.cpp
@@ -83,13 +83,10 @@ bool override_ini = false;
|
||||
void (*do_pset)(int,int);
|
||||
|
||||
namespace ds {
|
||||
uint8_t pen_color = 6;
|
||||
uint8_t back_color = 0;
|
||||
int origin[2] = {0, 0};
|
||||
int clip[4] = {0, 0, screen_width-1, screen_height-1}; // clip (x1,y1,x2,y2) calculat intersectat amb el tamany de la surface 'dest'
|
||||
uint8_t trans = 0;
|
||||
uint16_t fill_pattern = 0b1111111111111111;
|
||||
bool fill_trans = false;
|
||||
uint8_t draw_palette[256];
|
||||
uint8_t mode = DRAWMODE_NORMAL;
|
||||
}
|
||||
@@ -180,21 +177,21 @@ void read_ini() {
|
||||
//SDL_Log("'game.ini' carregat!\n");
|
||||
}
|
||||
|
||||
void pset_fast(int x, int y) {
|
||||
if (ds::trans != ds::pen_color) DEST(x, y) = ds::draw_palette[ds::pen_color];
|
||||
static inline void pset_fast(int x, int y, uint8_t color) {
|
||||
if (ds::trans != color) DEST(x, y) = ds::draw_palette[color];
|
||||
}
|
||||
|
||||
void pset_bool(int x, int y) {
|
||||
if (ds::trans != ds::pen_color) {
|
||||
static inline void pset_bool(int x, int y, uint8_t color) {
|
||||
if (ds::trans != color) {
|
||||
switch (ds::mode) {
|
||||
case DRAWMODE_AND:
|
||||
DEST(x, y) = DEST(x, y) & ds::draw_palette[ds::pen_color];
|
||||
DEST(x, y) = DEST(x, y) & color;
|
||||
break;
|
||||
case DRAWMODE_OR:
|
||||
DEST(x, y) = DEST(x, y) | ds::draw_palette[ds::pen_color];
|
||||
DEST(x, y) = DEST(x, y) | color;
|
||||
break;
|
||||
case DRAWMODE_XOR:
|
||||
DEST(x, y) = DEST(x, y) ^ ds::draw_palette[ds::pen_color];
|
||||
DEST(x, y) = DEST(x, y) ^ color;
|
||||
break;
|
||||
case DRAWMODE_NOT:
|
||||
DEST(x, y) = ~DEST(x, y);
|
||||
@@ -203,47 +200,23 @@ void pset_bool(int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
void pset_pattern(int x, int y) {
|
||||
static inline void pset_pattern(int x, int y, uint8_t color) {
|
||||
int pbx = x % 4, pby = y % 4;
|
||||
int pb = pbx+pby*4;
|
||||
if (ds::fill_pattern & (1 << pb)) {
|
||||
if (ds::trans != ds::pen_color) DEST(x, y) = ds::draw_palette[ds::pen_color];
|
||||
} else {
|
||||
if (!ds::fill_trans) DEST(x, y) = ds::draw_palette[ds::back_color];
|
||||
}
|
||||
if (ds::fill_pattern & (1 << pb)) if (ds::trans != color) DEST(x, y) = color;
|
||||
}
|
||||
|
||||
void set_draw_mode(uint8_t mode) {
|
||||
ds::mode = mode;
|
||||
switch (mode) {
|
||||
case DRAWMODE_NORMAL:
|
||||
do_pset = pset_fast;
|
||||
break;
|
||||
case DRAWMODE_PATTERN:
|
||||
do_pset = pset_pattern;
|
||||
break;
|
||||
case DRAWMODE_AND:
|
||||
case DRAWMODE_OR:
|
||||
case DRAWMODE_XOR:
|
||||
case DRAWMODE_NOT:
|
||||
do_pset = pset_bool;
|
||||
break;
|
||||
default:
|
||||
do_pset = pset_fast;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void reinit() {
|
||||
log_msg(LOG_INFO, "STARTING A SYSTEM REINITIALIZATION\n");
|
||||
do_pset = pset_fast;
|
||||
ds::pen_color = 6;
|
||||
ds::back_color = 0;
|
||||
ds::mode = DRAWMODE_NORMAL;
|
||||
ds::origin[0] = ds::origin[1] = 0;
|
||||
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width-1; ds::clip[3] = screen_height-1;
|
||||
ds::trans=0;
|
||||
ds::fill_pattern = 0b1111111111111111;
|
||||
ds::fill_trans = false;
|
||||
for (unsigned int i=0; i<MAX_SURFACES; ++i) freesurf(i);
|
||||
setdest(newsurf(screen_width, screen_height));
|
||||
dest_surface = screen_surface;
|
||||
@@ -815,14 +788,6 @@ void cls(uint8_t color) {
|
||||
SDL_memset(dest_surface->p, col, dest_surface->size);
|
||||
}
|
||||
|
||||
void color(uint8_t color) {
|
||||
ds::pen_color=color;
|
||||
}
|
||||
|
||||
void bcolor(uint8_t color) {
|
||||
ds::back_color=color;
|
||||
}
|
||||
|
||||
uint32_t *loadpal(const char* filename, uint16_t *palsize) {
|
||||
int size;
|
||||
uint8_t *buffer = (uint8_t*)file_getfilebuffer(filename, size);
|
||||
@@ -904,30 +869,39 @@ void palt(uint8_t col, bool t) {
|
||||
}
|
||||
*/
|
||||
|
||||
void pset(int x, int y) {
|
||||
// Per a les funcions que pinten tot del mateix color
|
||||
static inline void direct_pset(int x, int y, uint8_t color) {
|
||||
x += ds::origin[0]; y += ds::origin[1];
|
||||
if (x < ds::clip[0] || x > ds::clip[2] || y < ds::clip[1] || y > ds::clip[3]) return;
|
||||
do_pset(x,y);
|
||||
switch (ds::mode) {
|
||||
case DRAWMODE_NORMAL: pset_fast(x,y,color); break;
|
||||
case DRAWMODE_PATTERN: pset_pattern(x,y,color); break;
|
||||
default: pset_bool(x,y,color); break;
|
||||
}
|
||||
}
|
||||
|
||||
// Per a les funcions que van canviant de color (surf.pixel i draw.surf, bàsicament)
|
||||
static inline void subst_pset(int x, int y, uint8_t color) {
|
||||
direct_pset(x,y,ds::draw_palette[color]);
|
||||
}
|
||||
|
||||
void pset(int x, int y, uint8_t color) {
|
||||
ds::pen_color = color;
|
||||
pset(x, y);
|
||||
subst_pset(x,y,color);
|
||||
}
|
||||
|
||||
uint8_t pget(int x, int y) {
|
||||
x += ds::origin[0]; y += ds::origin[1];
|
||||
//if (x < 0 || x > (dest_surface->w-1) || y < 0 || y > (dest_surface->h-1)) return 0;
|
||||
if (x < ds::clip[0] || x > ds::clip[2] || y < ds::clip[1] || y > ds::clip[3]) return 0;
|
||||
return DEST(x, y);
|
||||
}
|
||||
|
||||
// Bresenham Line Algorithm
|
||||
void line(int x0, int y0, int x1, int y1) {
|
||||
void line(int x0, int y0, int x1, int y1, uint8_t color) {
|
||||
int x, y;
|
||||
int dx, dy;
|
||||
int incx, incy;
|
||||
int balance;
|
||||
color = ds::draw_palette[color];
|
||||
|
||||
if (x1 >= x0) { dx = x1 - x0; incx = 1; } else { dx = x0 - x1; incx = -1; }
|
||||
if (y1 >= y0) { dy = y1 - y0; incy = 1; } else { dy = y0 - y1; incy = -1; }
|
||||
@@ -940,79 +914,55 @@ void line(int x0, int y0, int x1, int y1) {
|
||||
dx <<= 1;
|
||||
|
||||
while (x != x1) {
|
||||
pset(x, y);
|
||||
direct_pset(x, y, color);
|
||||
if (balance >= 0) { y += incy; balance -= dx; }
|
||||
balance += dy;
|
||||
x += incx;
|
||||
}
|
||||
pset(x, y);
|
||||
direct_pset(x, y, color);
|
||||
} else {
|
||||
dx <<= 1;
|
||||
balance = dx - dy;
|
||||
dy <<= 1;
|
||||
|
||||
while (y != y1) {
|
||||
pset(x, y);
|
||||
direct_pset(x, y, color);
|
||||
if (balance >= 0) { x += incx; balance -= dy; }
|
||||
balance += dx;
|
||||
y += incy;
|
||||
}
|
||||
pset(x, y);
|
||||
direct_pset(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
void line(int x0, int y0, int x1, int y1, uint8_t color) {
|
||||
ds::pen_color = color;
|
||||
line(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
void hline(int x0, int y, int x1) {
|
||||
if (x0>x1) { const int tmp=x0;x0=x1;x1=tmp; }
|
||||
for (int x=x0; x<=x1; ++x) pset(x, y);
|
||||
}
|
||||
|
||||
void hline(int x0, int y, int x1, uint8_t color) {
|
||||
ds::pen_color = color;
|
||||
hline(x0, y, x1);
|
||||
}
|
||||
|
||||
void vline(int x, int y0, int y1) {
|
||||
if (y0>y1) { const int tmp=y0;y0=y1;y1=tmp; }
|
||||
for (int y=y0; y<=y1; ++y) pset(x, y);
|
||||
color = ds::draw_palette[color];
|
||||
if (x0>x1) { const int tmp=x0;x0=x1;x1=tmp; }
|
||||
for (int x=x0; x<=x1; ++x) direct_pset(x, y, color);
|
||||
}
|
||||
|
||||
void vline(int x, int y0, int y1, uint8_t color) {
|
||||
ds::pen_color = color;
|
||||
vline(x, y0, y1);
|
||||
}
|
||||
|
||||
void rect(int x, int y, int w, int h) {
|
||||
int x1 = w+x-1;
|
||||
int y1 = h+y-1;
|
||||
hline(x, y, x1);
|
||||
hline(x, y1, x1);
|
||||
vline(x, y, y1);
|
||||
vline(x1, y, y1);
|
||||
color = ds::draw_palette[color];
|
||||
if (y0>y1) { const int tmp=y0;y0=y1;y1=tmp; }
|
||||
for (int y=y0; y<=y1; ++y) direct_pset(x, y, color);
|
||||
}
|
||||
|
||||
void rect(int x, int y, int w, int h, uint8_t color) {
|
||||
ds::pen_color = color;
|
||||
rect(x, y, w, h);
|
||||
}
|
||||
|
||||
void rectfill(int x, int y, int w, int h) {
|
||||
int x1 = w+x-1;
|
||||
int y1 = h+y-1;
|
||||
for (int i=y; i<=y1; ++i) hline(x, i, x1);
|
||||
hline(x, y, x1, color);
|
||||
hline(x, y1, x1, color);
|
||||
vline(x, y, y1, color);
|
||||
vline(x1, y, y1, color);
|
||||
}
|
||||
|
||||
void rectfill(int x, int y, int w, int h, uint8_t color) {
|
||||
ds::pen_color = color;
|
||||
rectfill(x, y, w, h);
|
||||
int x1 = w+x-1;
|
||||
int y1 = h+y-1;
|
||||
for (int i=y; i<=y1; ++i) hline(x, i, x1, color);
|
||||
}
|
||||
|
||||
void fillp(uint16_t pat, bool transparent) {
|
||||
ds::fill_trans = true; //transparent;
|
||||
ds::fill_pattern = pat;
|
||||
}
|
||||
|
||||
@@ -1072,85 +1022,47 @@ int camy() {
|
||||
return ds::origin[1];
|
||||
}
|
||||
|
||||
void _drawcirc(int xc, int yc, int x, int y) {
|
||||
pset(xc+x, yc+y);
|
||||
pset(xc-x, yc+y);
|
||||
pset(xc+x, yc-y);
|
||||
pset(xc-x, yc-y);
|
||||
pset(xc+y, yc+x);
|
||||
pset(xc-y, yc+x);
|
||||
pset(xc+y, yc-x);
|
||||
pset(xc-y, yc-x);
|
||||
}
|
||||
|
||||
void _fillcirc(int xc, int yc, int x, int y) {
|
||||
hline(xc-x, yc+y, xc+x);
|
||||
hline(xc-x, yc-y, xc+x);
|
||||
hline(xc-y, yc+x, xc+y);
|
||||
hline(xc-y, yc-x, xc+y);
|
||||
}
|
||||
|
||||
void _anycirc(int x, int y, uint8_t r, void (*fun_ptr)(int, int, int, int)) {
|
||||
int xi=0, yi=r;
|
||||
int d=3-2*r;
|
||||
(*fun_ptr)(x, y, xi, yi);
|
||||
while (yi>=xi++) {
|
||||
d += d>0 ? 4*(xi-yi--)+10 : 4*xi+6;
|
||||
(*fun_ptr)(x, y, xi, yi);
|
||||
}
|
||||
}
|
||||
|
||||
void circ(int x, int y, uint8_t r) {
|
||||
_anycirc(x, y, r, &_drawcirc);
|
||||
static inline void circ_scanline(int xc, int yc, int x, int y, uint8_t color) {
|
||||
direct_pset(xc+x, yc+y, color);
|
||||
direct_pset(xc-x, yc+y, color);
|
||||
direct_pset(xc+x, yc-y, color);
|
||||
direct_pset(xc-x, yc-y, color);
|
||||
direct_pset(xc+y, yc+x, color);
|
||||
direct_pset(xc-y, yc+x, color);
|
||||
direct_pset(xc+y, yc-x, color);
|
||||
direct_pset(xc-y, yc-x, color);
|
||||
}
|
||||
|
||||
void circ(int x, int y, uint8_t r, uint8_t color) {
|
||||
ds::pen_color=color;
|
||||
circ(x, y, r);
|
||||
}
|
||||
|
||||
void circfill(int x, int y, uint8_t r) {
|
||||
_anycirc(x, y, r, &_fillcirc);
|
||||
}
|
||||
|
||||
void circfill(int x, int y, uint8_t r, uint8_t color) {
|
||||
ds::pen_color=color;
|
||||
circfill(x, y, r);
|
||||
}
|
||||
|
||||
|
||||
void roundrect(int x, int y, int w, int h, uint8_t r) {
|
||||
color = ds::draw_palette[color];
|
||||
int xi=0, yi=r;
|
||||
int d=3-2*r;
|
||||
|
||||
int xf = w+x-1;
|
||||
int yf = h+y-1;
|
||||
int x1 = x+r, y1 = y+r;
|
||||
int x2 = xf-r, y2 = yf-r;
|
||||
hline(x1, y, x2);
|
||||
hline(x1, yf, x2);
|
||||
vline(x, y1, y2);
|
||||
vline(xf, y1, y2);
|
||||
|
||||
circ_scanline(x, y, xi, yi, color);
|
||||
while (yi>=xi++) {
|
||||
d += d>0 ? 4*(xi-yi--)+10 : 4*xi+6;
|
||||
pset(x2+xi, y2+yi);
|
||||
pset(x1-xi, y2+yi);
|
||||
pset(x2+xi, y1-yi);
|
||||
pset(x1-xi, y1-yi);
|
||||
pset(x2+yi, y2+xi);
|
||||
pset(x1-yi, y2+xi);
|
||||
pset(x2+yi, y1-xi);
|
||||
pset(x1-yi, y1-xi);
|
||||
circ_scanline(x, y, xi, yi, color);
|
||||
}
|
||||
}
|
||||
|
||||
void roundrect(int x, int y, int w, int h, uint8_t r, uint8_t color) {
|
||||
ds::pen_color=color;
|
||||
roundrect(x, y, w, h, r);
|
||||
static inline void circfill_scanline(int xc, int yc, int x, int y, uint8_t color) {
|
||||
hline(xc-x, yc+y, xc+x, color);
|
||||
hline(xc-x, yc-y, xc+x, color);
|
||||
hline(xc-y, yc+x, xc+y, color);
|
||||
hline(xc-y, yc-x, xc+y, color);
|
||||
}
|
||||
|
||||
void roundrectfill(int x, int y, int w, int h, uint8_t r) {
|
||||
void circfill(int x, int y, uint8_t r, uint8_t color) {
|
||||
int xi=0, yi=r;
|
||||
int d=3-2*r;
|
||||
circfill_scanline(x, y, xi, yi, color);
|
||||
while (yi>=xi++) {
|
||||
d += d>0 ? 4*(xi-yi--)+10 : 4*xi+6;
|
||||
circfill_scanline(x, y, xi, yi, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void roundrect(int x, int y, int w, int h, uint8_t r, uint8_t color) {
|
||||
int xi=0, yi=r;
|
||||
int d=3-2*r;
|
||||
|
||||
@@ -1158,56 +1070,57 @@ void roundrectfill(int x, int y, int w, int h, uint8_t r) {
|
||||
int yf = h+y-1;
|
||||
int x1 = x+r, y1 = y+r;
|
||||
int x2 = xf-r, y2 = yf-r;
|
||||
for (int i=y1; i<=y2; ++i) hline(x, i, xf);
|
||||
hline(x1, y, x2, color);
|
||||
hline(x1, yf, x2, color);
|
||||
vline(x, y1, y2, color);
|
||||
vline(xf, y1, y2, color);
|
||||
|
||||
color = ds::draw_palette[color];
|
||||
while (yi>=xi++) {
|
||||
d += d>0 ? 4*(xi-yi--)+10 : 4*xi+6;
|
||||
hline(x1-xi, y2+yi, x2+xi);
|
||||
hline(x1-xi, y1-yi, x2+xi);
|
||||
hline(x1-yi, y2+xi, x2+yi);
|
||||
hline(x1-yi, y1-xi, x2+yi);
|
||||
direct_pset(x2+xi, y2+yi, color);
|
||||
direct_pset(x1-xi, y2+yi, color);
|
||||
direct_pset(x2+xi, y1-yi, color);
|
||||
direct_pset(x1-xi, y1-yi, color);
|
||||
direct_pset(x2+yi, y2+xi, color);
|
||||
direct_pset(x1-yi, y2+xi, color);
|
||||
direct_pset(x2+yi, y1-xi, color);
|
||||
direct_pset(x1-yi, y1-xi, color);
|
||||
}
|
||||
}
|
||||
|
||||
void roundrectfill(int x, int y, int w, int h, uint8_t r, uint8_t color) {
|
||||
ds::pen_color=color;
|
||||
roundrectfill(x, y, w, h, r);
|
||||
}
|
||||
/*
|
||||
void roundrectfill(int x, int y, uint8_t r) {
|
||||
int xi=0, yi=r;
|
||||
int d=3-2*r;
|
||||
(*fun_ptr)(x, y, xi, yi);
|
||||
|
||||
int xf = w+x-1;
|
||||
int yf = h+y-1;
|
||||
int x1 = x+r, y1 = y+r;
|
||||
int x2 = xf-r, y2 = yf-r;
|
||||
for (int i=y1; i<=y2; ++i) hline(x, i, xf, color);
|
||||
|
||||
while (yi>=xi++) {
|
||||
d += d>0 ? 4*(xi-yi--)+10 : 4*xi+6;
|
||||
(*fun_ptr)(x, y, xi, yi);
|
||||
hline(x1-xi, y2+yi, x2+xi, color);
|
||||
hline(x1-xi, y1-yi, x2+xi, color);
|
||||
hline(x1-yi, y2+xi, x2+yi, color);
|
||||
hline(x1-yi, y1-xi, x2+yi, color);
|
||||
}
|
||||
}
|
||||
|
||||
void roundrectfill(int x, int y, uint8_t r, uint8_t color) {
|
||||
ds::pen_color=color;
|
||||
roundrectfill(x, y, r);
|
||||
}
|
||||
*/
|
||||
void _drawoval(int xc, int yc, int x, int y, float xf, float yf) {
|
||||
pset((xc+x)*xf, (yc+y)*yf);
|
||||
pset((xc-x)*xf, (yc+y)*yf);
|
||||
pset((xc+x)*xf, (yc-y)*yf);
|
||||
pset((xc-x)*xf, (yc-y)*yf);
|
||||
pset((xc+y)*xf, (yc+x)*yf);
|
||||
pset((xc-y)*xf, (yc+x)*yf);
|
||||
pset((xc+y)*xf, (yc-x)*yf);
|
||||
pset((xc-y)*xf, (yc-x)*yf);
|
||||
void oval_scanline(int xc, int yc, int x, int y, float xf, float yf, uint8_t color) {
|
||||
direct_pset((xc+x)*xf, (yc+y)*yf, color);
|
||||
direct_pset((xc-x)*xf, (yc+y)*yf, color);
|
||||
direct_pset((xc+x)*xf, (yc-y)*yf, color);
|
||||
direct_pset((xc-x)*xf, (yc-y)*yf, color);
|
||||
direct_pset((xc+y)*xf, (yc+x)*yf, color);
|
||||
direct_pset((xc-y)*xf, (yc+x)*yf, color);
|
||||
direct_pset((xc+y)*xf, (yc-x)*yf, color);
|
||||
direct_pset((xc-y)*xf, (yc-x)*yf, color);
|
||||
}
|
||||
|
||||
void _filloval(int xc, int yc, int x, int y, float xf, float yf) {
|
||||
hline((xc-x)*xf, (yc+y)*yf, (xc+x)*xf);
|
||||
hline((xc-x)*xf, (yc-y)*yf, (xc+x)*xf);
|
||||
hline((xc-y)*xf, (yc+x)*yf, (xc+y)*xf);
|
||||
hline((xc-y)*xf, (yc-x)*yf, (xc+y)*xf);
|
||||
}
|
||||
|
||||
void _anyoval(int x0, int y0, int x1, int y1, void (*fun_ptr)(int, int, int, int, float, float)) {
|
||||
void oval(int x0, int y0, int x1, int y1, uint8_t color) {
|
||||
color = ds::draw_palette[color];
|
||||
int rx = (x1-x0)/2;
|
||||
int ry = (y1-y0)/2;
|
||||
int r = rx;
|
||||
@@ -1217,29 +1130,35 @@ void _anyoval(int x0, int y0, int x1, int y1, void (*fun_ptr)(int, int, int, int
|
||||
if (rx>=ry) {r=rx;yf=float(ry)/float(rx);} else {r=ry;xf=float(rx)/float(ry);}
|
||||
int xi=0, yi=r;
|
||||
int d=3-2*r;
|
||||
(*fun_ptr)(x, y, xi, yi, xf, yf);
|
||||
oval_scanline(x, y, xi, yi, xf, yf, color);
|
||||
while (yi>=xi++) {
|
||||
d += d>0 ? 4*(xi-yi--)+10 : 4*xi+6;
|
||||
(*fun_ptr)(x, y, xi, yi, xf, yf);
|
||||
oval_scanline(x, y, xi, yi, xf, yf, color);
|
||||
}
|
||||
}
|
||||
|
||||
void oval(int x0, int y0, int x1, int y1) {
|
||||
_anyoval(x0, y0, x1, y1, &_drawoval);
|
||||
}
|
||||
|
||||
void oval(int x0, int y0, int x1, int y1, uint8_t color) {
|
||||
ds::pen_color=color;
|
||||
oval(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
void ovalfill(int x0, int y0, int x1, int y1) {
|
||||
_anyoval(x0, y0, x1, y1, &_filloval);
|
||||
static inline void ovalfill_scanline(int xc, int yc, int x, int y, float xf, float yf, uint8_t color) {
|
||||
hline((xc-x)*xf, (yc+y)*yf, (xc+x)*xf, color);
|
||||
hline((xc-x)*xf, (yc-y)*yf, (xc+x)*xf, color);
|
||||
hline((xc-y)*xf, (yc+x)*yf, (xc+y)*xf, color);
|
||||
hline((xc-y)*xf, (yc-x)*yf, (xc+y)*xf, color);
|
||||
}
|
||||
|
||||
void ovalfill(int x0, int y0, int x1, int y1, uint8_t color) {
|
||||
ds::pen_color=color;
|
||||
ovalfill(x0, y0, x1, y1);
|
||||
int rx = (x1-x0)/2;
|
||||
int ry = (y1-y0)/2;
|
||||
int r = rx;
|
||||
int x = x0 + rx;
|
||||
int y = y0 + ry;
|
||||
float xf = 1.0f, yf = 1.0f;
|
||||
if (rx>=ry) {r=rx;yf=float(ry)/float(rx);} else {r=ry;xf=float(rx)/float(ry);}
|
||||
int xi=0, yi=r;
|
||||
int d=3-2*r;
|
||||
ovalfill_scanline(x, y, xi, yi, xf, yf, color);
|
||||
while (yi>=xi++) {
|
||||
d += d>0 ? 4*(xi-yi--)+10 : 4*xi+6;
|
||||
ovalfill_scanline(x, y, xi, yi, xf, yf, color);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t sget(int x, int y) {
|
||||
@@ -1248,15 +1167,10 @@ uint8_t sget(int x, int y) {
|
||||
return SOURCE(x, y);
|
||||
}
|
||||
|
||||
void sset(int x, int y) {
|
||||
void sset(int x, int y, uint8_t color) {
|
||||
if (!source_surface) return;
|
||||
if (x < 0 || x > (source_surface->w-1) || y < 0 || y > (source_surface->h-1)) return;
|
||||
SOURCE(x, y) = ds::pen_color;
|
||||
}
|
||||
|
||||
void sset(int x, int y, uint8_t color) {
|
||||
ds::pen_color=color;
|
||||
sset(x, y);
|
||||
SOURCE(x, y) = color;
|
||||
}
|
||||
|
||||
void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) {
|
||||
@@ -1274,7 +1188,7 @@ void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) {
|
||||
for (int yi=0; yi<=th; ++yi) {
|
||||
int ttx = tx;
|
||||
for (int xi=0; xi<=tw; ++xi) {
|
||||
pset(x+xi, y+yi, sget(ttx, ty));
|
||||
subst_pset(x+xi, y+yi, sget(ttx, ty));
|
||||
ttx += txd;
|
||||
}
|
||||
ty += tyd;
|
||||
@@ -1295,38 +1209,13 @@ void blit(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool f
|
||||
csx = ssx;
|
||||
for(int x=dx;x<dx+dw;++x) {
|
||||
uint8_t color = invert ? sget(SDL_max(sy,csy),SDL_max(sx, csx)) : sget(SDL_max(sx, csx), SDL_max(sy,csy));
|
||||
pset(x, y, color);
|
||||
subst_pset(x, y, color);
|
||||
csx += sdx;
|
||||
}
|
||||
csy += sdy;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void blit_r(int sx, int sy, int sw, int sh, int x, int y, float a)
|
||||
{
|
||||
const int x0 = sw>>1;
|
||||
const int y0 = sh>>1;
|
||||
|
||||
const float sa = SDL_sinf(a);
|
||||
const float ca = SDL_cosf(a);
|
||||
|
||||
for (int ix=0; ix<=sw; ++ix)
|
||||
{
|
||||
for (int iy=0; iy<=sh; ++iy)
|
||||
{
|
||||
const float dx = ix-x0;
|
||||
const float dy = iy-y0;
|
||||
const float xx = dx*ca - dy*sa + float(x0);
|
||||
const float yy = dx*sa + dy*ca + float(y0);
|
||||
|
||||
if (xx>=0 && xx<sw-1 && yy>=0 && yy<=sh-1)
|
||||
pset(x+ix, y+iy, sget(sx+xx, sy+yy));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void blit_r(int sx, int sy, int sw, int sh,
|
||||
int dx, int dy, int dw, int dh,
|
||||
bool flip_x, bool flip_y,
|
||||
@@ -1408,120 +1297,11 @@ void blit_r(int sx, int sy, int sw, int sh,
|
||||
continue; // no pintamos nada
|
||||
|
||||
uint8_t color = sget((int)sxp, (int)syp);
|
||||
pset(x, y, color);
|
||||
subst_pset(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*void blit_r(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y, float angle_deg)
|
||||
{
|
||||
if (dw == 0) dw = sw;
|
||||
if (dh == 0) dh = sh;
|
||||
|
||||
// Escalado origen→destino
|
||||
float sdx = float(sw) / float(dw);
|
||||
float sdy = float(sh) / float(dh);
|
||||
|
||||
// Centro del destino
|
||||
float dcx = dx + dw * 0.5f;
|
||||
float dcy = dy + dh * 0.5f;
|
||||
|
||||
// Centro del origen
|
||||
float scx = sx + sw * 0.5f;
|
||||
float scy = sy + sh * 0.5f;
|
||||
|
||||
// Flips: invertir escala
|
||||
if (flip_x) sdx = -sdx;
|
||||
if (flip_y) sdy = -sdy;
|
||||
|
||||
// Ángulo en radianes
|
||||
float a = angle_deg * 3.14159265f / 180.0f;
|
||||
float ca = SDL_cosf(a);
|
||||
float sa = SDL_sinf(a);
|
||||
|
||||
// Bucle principal
|
||||
for (int y = dy; y < dy + dh; ++y) {
|
||||
for (int x = dx; x < dx + dw; ++x) {
|
||||
|
||||
// Coordenadas destino relativas al centro
|
||||
float rx = x - dcx;
|
||||
float ry = y - dcy;
|
||||
|
||||
// Rotación inversa (para muestreo)
|
||||
float orx = rx * ca + ry * sa;
|
||||
float ory = -rx * sa + ry * ca;
|
||||
|
||||
// Convertir a coordenadas de la fuente
|
||||
float sxp = scx + orx * sdx;
|
||||
float syp = scy + ory * sdy;
|
||||
|
||||
// Muestreo nearest neighbor
|
||||
uint8_t color = sget(int(sxp), int(syp));
|
||||
pset(x, y, color);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
void tline(int x0, int y0, int x1, int y1, float mx, float my, float mdx, float mdy) {
|
||||
int x, y;
|
||||
int dx, dy;
|
||||
int incx, incy;
|
||||
int balance;
|
||||
|
||||
if (x1 >= x0) { dx = x1 - x0; incx = 1; } else { dx = x0 - x1; incx = -1; }
|
||||
if (y1 >= y0) { dy = y1 - y0; incy = 1; } else { dy = y0 - y1; incy = -1; }
|
||||
|
||||
x = x0; y = y0;
|
||||
|
||||
if (dx >= dy) {
|
||||
dy <<= 1;
|
||||
balance = dy - dx;
|
||||
dx <<= 1;
|
||||
|
||||
while (x != x1) {
|
||||
pset(x, y, sget(mx*8, my*8));
|
||||
if (balance >= 0) { y += incy; balance -= dx; }
|
||||
balance += dy;
|
||||
x += incx;
|
||||
mx += mdx;
|
||||
my += mdy;
|
||||
}
|
||||
pset(x, y, sget(mx*8, my*8));
|
||||
} else {
|
||||
dx <<= 1;
|
||||
balance = dx - dy;
|
||||
dy <<= 1;
|
||||
|
||||
while (y != y1) {
|
||||
pset(x, y, sget(mx*8, my*8));
|
||||
if (balance >= 0) { x += incx; balance -= dy; }
|
||||
balance += dx;
|
||||
y += incy;
|
||||
mx += mdx;
|
||||
my += mdy;
|
||||
}
|
||||
pset(x, y, sget(mx*8, my*8));
|
||||
}
|
||||
}
|
||||
|
||||
void thline(int x0, int y, int x1, float mx, float my, float mdx, float mdy) {
|
||||
if (x0>x1) { const int tmp=x0;x0=x1;x1=tmp; }
|
||||
for (int x=x0; x<=x1; ++x) {
|
||||
pset(x, y, sget(mx*8, my*8));
|
||||
mx += mdx;
|
||||
my += mdy;
|
||||
}
|
||||
}
|
||||
|
||||
void tvline(int x, int y0, int y1, float mx, float my, float mdx, float mdy) {
|
||||
if (y0>y1) { const int tmp=y0;y0=y1;y1=tmp; }
|
||||
for (int y=y0; y<=y1; ++y) {
|
||||
pset(x, y, sget(mx*8, my*8));
|
||||
mx += mdx;
|
||||
my += mdy;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t mget(int celx, int cely) {
|
||||
if (!map_surface) return 0;
|
||||
if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return 0;
|
||||
|
||||
@@ -151,8 +151,6 @@ uint8_t getfontspacing();
|
||||
void setfontspacing(uint8_t spacing);
|
||||
|
||||
void cls(uint8_t color=0);
|
||||
void color(uint8_t color=6);
|
||||
void bcolor(uint8_t color=0);
|
||||
|
||||
uint32_t *loadpal(const char* filename, uint16_t *palsize=NULL);
|
||||
void setpal(uint32_t *pal);
|
||||
@@ -164,29 +162,19 @@ uint8_t subpal(uint8_t index, uint8_t color);
|
||||
void reset_subpal();
|
||||
|
||||
void set_draw_mode(uint8_t mode);
|
||||
void pset(int x, int y);
|
||||
void pset(int x, int y, uint8_t color);
|
||||
|
||||
uint8_t pget(int x, int y);
|
||||
|
||||
void line(int x0, int y0, int x1, int y1);
|
||||
void line(int x0, int y0, int x1, int y1, uint8_t color);
|
||||
|
||||
void hline(int x0, int y, int x1);
|
||||
void hline(int x0, int y, int x1, uint8_t color);
|
||||
|
||||
void vline(int x, int y0, int y1);
|
||||
void vline(int x, int y0, int y1, uint8_t color);
|
||||
|
||||
void rect(int x, int y, int w, int h);
|
||||
void rect(int x, int y, int w, int h, uint8_t color);
|
||||
|
||||
void rectfill(int x, int y, int w, int h);
|
||||
void rectfill(int x, int y, int w, int h, uint8_t color);
|
||||
|
||||
void fillp(uint16_t pat, bool transparent = false);
|
||||
|
||||
void print(const char *str, int x, int y);
|
||||
void print(const char *str, int x, int y, uint8_t color);
|
||||
|
||||
void clip(int x, int y, int w, int h);
|
||||
@@ -195,26 +183,15 @@ void origin(int x, int y);
|
||||
int camx();
|
||||
int camy();
|
||||
|
||||
void circ(int x, int y, uint8_t r = 4);
|
||||
void circ(int x, int y, uint8_t r, uint8_t color);
|
||||
|
||||
void circfill(int x, int y, uint8_t r = 4);
|
||||
void circfill(int x, int y, uint8_t r, uint8_t color);
|
||||
|
||||
void roundrect(int x, int y, int w, int h, uint8_t r);
|
||||
void roundrect(int x, int y, int w, int h, uint8_t r, uint8_t color);
|
||||
|
||||
void roundrectfill(int x, int y, int w, int h, uint8_t r);
|
||||
void roundrectfill(int x, int y, int w, int h, uint8_t r, uint8_t color);
|
||||
|
||||
void oval(int x0, int y0, int x1, int y1);
|
||||
void oval(int x0, int y0, int x1, int y1, uint8_t color);
|
||||
|
||||
void ovalfill(int x0, int y0, int x1, int y1);
|
||||
void ovalfill(int x0, int y0, int x1, int y1, uint8_t color);
|
||||
|
||||
uint8_t sget(int x, int y);
|
||||
void sset(int x, int y);
|
||||
void sset(int x, int y, uint8_t color);
|
||||
|
||||
void spr(uint8_t n, int x, int y, float w = 1.0f, float h = 1.0f, bool flip_x = false, bool flip_y = false);
|
||||
@@ -222,10 +199,6 @@ void blit(int sx, int sy, int sw, int sh, int dx, int dy, int dw=0, int dh=0, bo
|
||||
//void blit_r(int sx, int sy, int sw, int sh, int x, int y, float a);
|
||||
void blit_r(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y, float angle_deg);
|
||||
|
||||
void tline(int x0, int y0, int x1, int y1, float mx, float my, float mdx=0.125f, float mdy=0.0f);
|
||||
void thline(int x0, int y, int x1, float mx, float my, float mdx=0.125f, float mdy=0.0f);
|
||||
void tvline(int x, int y0, int y1, float mx, float my, float mdx=0.0f, float mdy=0.125f);
|
||||
|
||||
uint8_t mget(int celx, int cely);
|
||||
void mset(int celx, int cely, uint8_t snum);
|
||||
uint8_t gettilew();
|
||||
|
||||
Reference in New Issue
Block a user