- [DEPRECATED] camera()

- [DEPRECATED] view()
- [FIX] la regió de clip ara es calcula sempre ajustada a la surface de destí, siga la que siga encara que es canvie
This commit is contained in:
2024-11-28 17:04:04 +01:00
parent c07e09cebd
commit e36caf566c
5 changed files with 52 additions and 90 deletions

View File

@@ -7,7 +7,7 @@ function _init()
keyRight = tonumber(getconf("keyright")) or KEY_RIGHT keyRight = tonumber(getconf("keyright")) or KEY_RIGHT
keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT
_update=normal_update _update=normal_update
turbo(false) --turbo(false)
local perico = "péricòñ" local perico = "péricòñ"
print(utf8.len(perico)) print(utf8.len(perico))
end end
@@ -35,14 +35,15 @@ function normal_update()
if x>160 then x=-strlen(text)*4 end if x>160 then x=-strlen(text)*4 end
view() clip()
origin(0,0)
cls(20) cls(20)
view(10,10,140,100) clip(10,10,140,100)
cls(3) cls(3)
color(5) color(5)
prnt("HOLA",0,0) prnt("HOLA",0,0)
origin(70,50) origin(-70,-50)
prnt("ORIGIN",0,0) prnt("ORÍGIN",0,0)
prnt(text,x,10) prnt(text,x,10)
color(10) color(10)
bcolor(15) bcolor(15)

30
lua.cpp
View File

@@ -300,6 +300,14 @@ extern "C" {
} }
static int cpp_camera(lua_State *L) { static int cpp_camera(lua_State *L) {
return luaL_error(L, "Function 'camera' is DEPRECATED. Use 'origin' and 'clip' instead.");
}
static int cpp_view(lua_State *L) {
return luaL_error(L, "Function 'view' is DEPRECATED. Use 'origin' and 'clip' instead.");
}
static int cpp_origin(lua_State *L) {
if (lua_gettop(L) == 0) { if (lua_gettop(L) == 0) {
lua_pushinteger(L, camx()); lua_pushinteger(L, camx());
lua_pushinteger(L, camy()); lua_pushinteger(L, camy());
@@ -307,31 +315,11 @@ extern "C" {
} else { } else {
int x = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2); int y = luaL_checknumber(L, 2);
camera(x, y); origin(x, y);
return 0; return 0;
} }
} }
static int cpp_view(lua_State *L) {
if (lua_gettop(L) == 0) {
view();
} else {
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int w = luaL_checknumber(L, 3);
int h = luaL_checknumber(L, 4);
view(x, y, w, h);
}
return 0;
}
static int cpp_origin(lua_State *L) {
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
origin(x, y);
return 0;
}
static int cpp_tolocal(lua_State *L) { static int cpp_tolocal(lua_State *L) {
int x = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2); int y = luaL_checknumber(L, 2);

View File

@@ -56,9 +56,9 @@ void (*do_pset)(int,int);
namespace ds { namespace ds {
uint8_t pen_color = 6; uint8_t pen_color = 6;
uint8_t back_color = 0; uint8_t back_color = 0;
int cam[2] = {0, 0}; int origin[2] = {0, 0};
int clip[4] = {0, 0, screen_width, screen_height}; 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'
int clp[4] = {0, 0, screen_width-1, screen_height-1}; int clp[4] = {0, 0, screen_width, screen_height}; // clip (x1,y1,w,h) que ha especificat l'usuari
uint8_t trans = 0; uint8_t trans = 0;
uint16_t fill_pattern = 0b1111111111111111; uint16_t fill_pattern = 0b1111111111111111;
bool fill_trans = false; bool fill_trans = false;
@@ -157,9 +157,9 @@ void reinit() {
do_pset = pset_fast; do_pset = pset_fast;
ds::pen_color = 6; ds::pen_color = 6;
ds::back_color = 0; ds::back_color = 0;
ds::cam[0] = ds::cam[1] = 0; ds::origin[0] = ds::origin[1] = 0;
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height; ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width-1; ds::clip[3] = screen_height-1;
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1; ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width; ds::clp[3] = screen_height;
ds::trans=0; ds::trans=0;
ds::fill_pattern = 0b1111111111111111; ds::fill_pattern = 0b1111111111111111;
ds::fill_trans = false; ds::fill_trans = false;
@@ -173,10 +173,10 @@ void reinit() {
} }
void initaudio() { void initaudio() {
SDL_Log("Iniciant JailAudio...");
JA_Init(48000, AUDIO_S16, 1); JA_Init(48000, AUDIO_S16, 1);
for (int i=0;i<MAX_SOUNDS;++i) sounds[i] = NULL; for (int i=0;i<MAX_SOUNDS;++i) sounds[i] = NULL;
} }
void quitaudio() { void quitaudio() {
if (music != NULL) JA_DeleteMusic(music); if (music != NULL) JA_DeleteMusic(music);
for (int i=0;i<MAX_SOUNDS;++i) if (sounds[i]!=NULL) JA_DeleteSound(sounds[i]); for (int i=0;i<MAX_SOUNDS;++i) if (sounds[i]!=NULL) JA_DeleteSound(sounds[i]);
@@ -221,8 +221,18 @@ void freesurf(uint8_t surface) {
surfaces[surface].p = NULL; surfaces[surface].p = NULL;
} }
void recalculate_clip()
{
ds::clip[0] = ds::clp[0]; ds::clip[1] = ds::clp[1]; ds::clip[2] = ds::clp[2]-ds::clp[0]-1; ds::clip[3] = ds::clp[3]-ds::clp[1]-1;
if (ds::clip[0]<0) ds::clip[0]=0;
if (ds::clip[1]<0) ds::clip[1]=0;
if (ds::clip[2]>=dest_surface->w) ds::clip[2]=dest_surface->w-1;
if (ds::clip[3]>=dest_surface->h) ds::clip[3]=dest_surface->h-1;
}
void setdest(uint8_t surface) { void setdest(uint8_t surface) {
dest_surface = &surfaces[surface]; dest_surface = &surfaces[surface];
recalculate_clip();
} }
void setsource(uint8_t surface) { void setsource(uint8_t surface) {
@@ -445,16 +455,16 @@ int main(int argc,char*argv[]){
} }
void simple_pset(int x, int y, uint8_t color) { void simple_pset(int x, int y, uint8_t color) {
x -= ds::cam[0]; y -= ds::cam[1]; 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; if (x < ds::clip[0] || x > ds::clip[2] || y < ds::clip[1] || y > ds::clip[3]) return;
if (x < 0 || x >= dest_surface->w || y < 0 || y >= dest_surface->h) return; if (x < 0 || x >= dest_surface->w || y < 0 || y >= dest_surface->h) return;
DEST(x, y) = color; DEST(x, y) = color;
} }
void cls(uint8_t color) { void cls(uint8_t color) {
const uint8_t col = ds::draw_palette[color]; const uint8_t col = ds::draw_palette[color];
for (int y=ds::clip[1]+ds::cam[1]; y<ds::clip[3]+ds::cam[1];++y) { for (int y=ds::clip[1]; y<=ds::clip[3];++y) {
for (int x=ds::clip[0]+ds::cam[0]; x<ds::clip[2]+ds::cam[0];++x) { for (int x=ds::clip[0]; x<=ds::clip[2];++x) {
simple_pset(x,y,col); simple_pset(x,y,col);
} }
} }
@@ -548,8 +558,8 @@ void palt(uint8_t col, bool t) {
*/ */
void pset(int x, int y) { void pset(int x, int y) {
x -= ds::cam[0]; y -= ds::cam[1]; 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; if (x < ds::clip[0] || x > ds::clip[2] || y < ds::clip[1] || y > ds::clip[3]) return;
do_pset(x,y); do_pset(x,y);
} }
@@ -559,9 +569,9 @@ void pset(int x, int y, uint8_t color) {
} }
uint8_t pget(int x, int y) { uint8_t pget(int x, int y) {
x -= ds::cam[0]; y -= ds::cam[1]; 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 < 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; if (x < ds::clip[0] || x > ds::clip[2] || y < ds::clip[1] || y > ds::clip[3]) return 0;
return DEST(x, y); return DEST(x, y);
} }
@@ -714,44 +724,26 @@ void print(const char *str, int x, int y, uint8_t color) {
} }
void clip(int x, int y, int w, int h) { void clip(int x, int y, int w, int h) {
ds::clip[0] = x; ds::clip[1] = y; ds::clip[2] = w; ds::clip[3] = h; ds::clp[0] = x; ds::clp[1] = y; ds::clp[2] = w; ds::clp[3] = h;
ds::clp[0] = x; ds::clp[1] = y; ds::clp[2] = w-x-1; ds::clp[3] = h-y-1; recalculate_clip();
} }
void clip() { void clip() {
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height; ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = dest_surface->w; ds::clp[3] = dest_surface->h;
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1; recalculate_clip();
}
void camera(int x, int y) {
ds::cam[0] = x;
ds::cam[1] = y;
}
void view(int x, int y, int w, int h) {
ds::cam[0] = -x;
ds::cam[1] = -y;
ds::clip[0] = x; ds::clip[1] = y; ds::clip[2] = w+x; ds::clip[3] = h+y;
ds::clp[0] = x; ds::clp[1] = y; ds::clp[2] = w-1; ds::clp[3] = h-1;
}
void view() {
ds::cam[0] = ds::cam[1] = 0;
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height;
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1;
} }
void origin(int x, int y) { void origin(int x, int y) {
ds::cam[0] = -(ds::clip[0]+x); ds::origin[0] = x;
ds::cam[1] = -(ds::clip[1]+y); ds::origin[1] = y;
} }
int camx() { int camx() {
return ds::cam[0]; return ds::origin[0];
} }
int camy() { int camy() {
return ds::cam[1]; return ds::origin[1];
} }
void _drawcirc(int xc, int yc, int x, int y) { void _drawcirc(int xc, int yc, int x, int y) {
@@ -993,18 +985,6 @@ void tvline(int x, int y0, int y1, float mx, float my, float mdx, float mdy) {
} }
} }
void cline(int x0, int y0, int x1, int y1, uint8_t c0, uint8_t c1) {
}
void chline(int x0, int y, int x1, uint8_t c0, uint8_t c1) {
}
void cvline(int x, int y0, int y1, uint8_t c0, uint8_t c1) {
}
uint8_t mget(int celx, int cely) { uint8_t mget(int celx, int cely) {
if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return 0; if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return 0;
return TILES(celx, cely); return TILES(celx, cely);
@@ -1018,8 +998,8 @@ void mset(int celx, int cely, uint8_t snum) {
void map(int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer) { void map(int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer) {
if (map_surface==NULL) return; if (map_surface==NULL) return;
//if (celw <= 0 || celh <= 0 || celw >= TILES_WIDTH || celh >= TILES_HEIGHT) return; //if (celw <= 0 || celh <= 0 || celw >= TILES_WIDTH || celh >= TILES_HEIGHT) return;
sx -= ds::cam[0]; sy -= ds::cam[1]; sx -= ds::origin[0]; sy -= ds::origin[1];
if (sx+celw*8 < ds::clp[0] || sx > ds::clp[2] || sy+celh*8 < ds::clp[1] || sy > ds::clp[3]) return; if (sx+celw*8 < ds::clip[0] || sx > ds::clip[2] || sy+celh*8 < ds::clip[1] || sy > ds::clip[3]) return;
if (sx<0) { if (sx<0) {
int diff = -sx/8; int diff = -sx/8;
celx += diff; celx += diff;
@@ -1032,7 +1012,7 @@ void map(int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t
celh -= diff; celh -= diff;
sy += diff*8; sy += diff*8;
} }
sx += ds::cam[0]; sy += ds::cam[1]; sx += ds::origin[0]; sy += ds::origin[1];
for (int y=0; y<celh; ++y) { for (int y=0; y<celh; ++y) {
for (int x=0; x<celw; ++x) { for (int x=0; x<celw; ++x) {
spr(mget(celx+x, cely+y), sx+x*8, sy+y*8); spr(mget(celx+x, cely+y), sx+x*8, sy+y*8);

7
mini.h
View File

@@ -164,9 +164,6 @@ void print(const char *str, int x, int y, uint8_t color);
void clip(int x, int y, int w, int h); void clip(int x, int y, int w, int h);
void clip(); void clip();
void camera(int x, int y);
void view(int x, int y, int w, int h);
void view();
void origin(int x, int y); void origin(int x, int y);
int camx(); int camx();
int camy(); int camy();
@@ -195,10 +192,6 @@ void tline(int x0, int y0, int x1, int y1, float mx, float my, float mdx=0.125f,
void thline(int x0, int y, int x1, 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); void tvline(int x, int y0, int y1, float mx, float my, float mdx=0.0f, float mdy=0.125f);
void cline(int x0, int y0, int x1, int y1, uint8_t c0, uint8_t c1);
void chline(int x0, int y, int x1, uint8_t c0, uint8_t c1);
void cvline(int x, int y0, int y1, uint8_t c0, uint8_t c1);
uint8_t mget(int celx, int cely); uint8_t mget(int celx, int cely);
void mset(int celx, int cely, uint8_t snum); void mset(int celx, int cely, uint8_t snum);
void map(int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer=0); void map(int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer=0);

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define MINI_VERSION "0.9.97e" #define MINI_VERSION "0.9.98a"