- [NEW] spr_r per a rotar sprites (retalla cantos)

- [NEW] sspr admet un nou paràmetre "invert", per a invertir la x i la y.
This commit is contained in:
2024-02-07 14:20:12 +01:00
parent 63eaaa857e
commit 8618e922c8
4 changed files with 44 additions and 35 deletions

40
lua.cpp
View File

@@ -160,30 +160,6 @@ extern "C" {
}
return 0;
}
/* static int cpp_pal(lua_State *L) {
int numargs = lua_gettop(L);
switch (numargs) {
case 0: pal(); return 0;
case 1: luaL_error(L, "not enough arguments"); return 0;
}
uint8_t c0 = luaL_checkinteger(L, 1);
uint8_t c1 = luaL_checkinteger(L, 2);
uint8_t p = luaL_optinteger(L, 3, 0);
pal(c0, c1, p);
return 0;
}
static int cpp_palt(lua_State *L) {
int numargs = lua_gettop(L);
switch (numargs) {
case 0: palt(); return 0;
case 1: uint16_t bits = luaL_checkinteger(L, 1); palt(bits); return 0;
}
uint8_t col = luaL_checkinteger(L, 1);
bool t = lua_toboolean(L, 2);
palt(col, t);
return 0;
}*/
static int cpp_pset(lua_State *L) {
int x = luaL_checknumber(L, 1);
@@ -436,7 +412,20 @@ extern "C" {
int dh = luaL_optnumber(L, 8, 0);
bool flip_x = lua_toboolean(L, 9);
bool flip_y = lua_toboolean(L, 10);
sspr(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y);
bool invert = lua_toboolean(L, 11);
sspr(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, invert);
return 0;
}
static int cpp_spr_r(lua_State *L) {
int sx = luaL_checknumber(L, 1);
int sy = luaL_checknumber(L, 2);
int sw = luaL_checknumber(L, 3);
int sh = luaL_checknumber(L, 4);
int dx = luaL_checknumber(L, 5);
int dy = luaL_checknumber(L, 6);
float a = luaL_checknumber(L, 7);
spr_r(sx, sy, sw, sh, dx, dy, a);
return 0;
}
@@ -934,6 +923,7 @@ void push_lua_funcs() {
lua_pushcfunction(L,cpp_sget); lua_setglobal(L, "sget");
lua_pushcfunction(L,cpp_spr); lua_setglobal(L, "spr");
lua_pushcfunction(L,cpp_sspr); lua_setglobal(L, "sspr");
lua_pushcfunction(L,cpp_spr_r); lua_setglobal(L, "spr_r");
lua_pushcfunction(L,cpp_tline); lua_setglobal(L, "tline");
lua_pushcfunction(L,cpp_thline); lua_setglobal(L, "thline");
lua_pushcfunction(L,cpp_tvline); lua_setglobal(L, "tvline");

View File

@@ -872,7 +872,7 @@ void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) {
}
}
void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y) {
void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y, bool invert) {
if (dw==0) dw=sw;
if (dh==0) dh=sh;
float sdx = float(sw)/float(dw);
@@ -885,13 +885,37 @@ void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool f
for(int y=dy;y<dy+dh;++y) {
csx = ssx;
for(int x=dx;x<dx+dw;++x) {
pset(x, y, sget(SDL_max(sx, csx), SDL_max(sy,csy)));
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);
csx += sdx;
}
csy += sdy;
}
}
void spr_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 tline(int x0, int y0, int x1, int y1, float mx, float my, float mdx, float mdy) {
int x, y;
int dx, dy;

9
mini.h
View File

@@ -137,12 +137,6 @@ uint8_t gettrans();
void subpal(uint8_t index, uint8_t color);
void reset_subpal();
/*void pal();
void pal(uint8_t c0, uint8_t c1, uint8_t p = 0);
void palt();
void palt(uint16_t bits);
void palt(uint8_t col, bool t);*/
void pset(int x, int y);
void pset(int x, int y, uint8_t color);
@@ -194,7 +188,8 @@ 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);
void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw=0, int dh=0, bool flip_x = false, bool flip_y = false);
void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw=0, int dh=0, bool flip_x = false, bool flip_y = false, bool invert = false);
void spr_r(int sx, int sy, int sw, int sh, int x, int y, float a);
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);

View File

@@ -1,3 +1,3 @@
#pragma once
#define MINI_VERSION "0.9.86d"
#define MINI_VERSION "0.9.89d"