From e36caf566c6bb99857e7d9348ffe5f7d0161cc5b Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 28 Nov 2024 17:04:04 +0100 Subject: [PATCH] =?UTF-8?q?-=20[DEPRECATED]=20camera()=20-=20[DEPRECATED]?= =?UTF-8?q?=20view()=20-=20[FIX]=20la=20regi=C3=B3=20de=20clip=20ara=20es?= =?UTF-8?q?=20calcula=20sempre=20ajustada=20a=20la=20surface=20de=20dest?= =?UTF-8?q?=C3=AD,=20siga=20la=20que=20siga=20encara=20que=20es=20canvie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/main.lua | 11 +++--- lua.cpp | 30 +++++------------ mini.cpp | 92 ++++++++++++++++++++------------------------------- mini.h | 7 ---- version.h | 2 +- 5 files changed, 52 insertions(+), 90 deletions(-) diff --git a/data/main.lua b/data/main.lua index b900180..9be4afa 100644 --- a/data/main.lua +++ b/data/main.lua @@ -7,7 +7,7 @@ function _init() keyRight = tonumber(getconf("keyright")) or KEY_RIGHT keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT _update=normal_update - turbo(false) + --turbo(false) local perico = "péricòñ" print(utf8.len(perico)) end @@ -35,14 +35,15 @@ function normal_update() if x>160 then x=-strlen(text)*4 end - view() + clip() + origin(0,0) cls(20) - view(10,10,140,100) + clip(10,10,140,100) cls(3) color(5) prnt("HOLA",0,0) - origin(70,50) - prnt("ORIGIN",0,0) + origin(-70,-50) + prnt("ORÍGIN",0,0) prnt(text,x,10) color(10) bcolor(15) diff --git a/lua.cpp b/lua.cpp index ca7df56..22728b3 100644 --- a/lua.cpp +++ b/lua.cpp @@ -300,6 +300,14 @@ extern "C" { } 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) { lua_pushinteger(L, camx()); lua_pushinteger(L, camy()); @@ -307,31 +315,11 @@ extern "C" { } else { int x = luaL_checknumber(L, 1); int y = luaL_checknumber(L, 2); - camera(x, y); + origin(x, y); 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) { int x = luaL_checknumber(L, 1); int y = luaL_checknumber(L, 2); diff --git a/mini.cpp b/mini.cpp index 89b6042..21a427d 100644 --- a/mini.cpp +++ b/mini.cpp @@ -56,9 +56,9 @@ void (*do_pset)(int,int); namespace ds { uint8_t pen_color = 6; uint8_t back_color = 0; - int cam[2] = {0, 0}; - int clip[4] = {0, 0, screen_width, screen_height}; - int clp[4] = {0, 0, screen_width-1, screen_height-1}; + 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' + int clp[4] = {0, 0, screen_width, screen_height}; // clip (x1,y1,w,h) que ha especificat l'usuari uint8_t trans = 0; uint16_t fill_pattern = 0b1111111111111111; bool fill_trans = false; @@ -157,9 +157,9 @@ void reinit() { do_pset = pset_fast; ds::pen_color = 6; ds::back_color = 0; - 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; + 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::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width; ds::clp[3] = screen_height; ds::trans=0; ds::fill_pattern = 0b1111111111111111; ds::fill_trans = false; @@ -173,10 +173,10 @@ void reinit() { } void initaudio() { - SDL_Log("Iniciant JailAudio..."); JA_Init(48000, AUDIO_S16, 1); for (int i=0;i=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) { dest_surface = &surfaces[surface]; + recalculate_clip(); } 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) { - x -= ds::cam[0]; y -= ds::cam[1]; - if (x < ds::clip[0] || x >= ds::clip[2] || y < ds::clip[1] || y >= ds::clip[3]) return; + 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 < 0 || x >= dest_surface->w || y < 0 || y >= dest_surface->h) return; DEST(x, y) = color; } void cls(uint8_t color) { const uint8_t col = ds::draw_palette[color]; - for (int y=ds::clip[1]+ds::cam[1]; y= ds::clip[2] || y < ds::clip[1] || y >= ds::clip[3]) return; + 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); } @@ -559,9 +569,9 @@ void pset(int x, int y, uint8_t color) { } 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 < 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); } @@ -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) { - 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-x-1; ds::clp[3] = h-y-1; + ds::clp[0] = x; ds::clp[1] = y; ds::clp[2] = w; ds::clp[3] = h; + recalculate_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] = screen_width-1; ds::clp[3] = screen_height-1; -} - -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; + ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = dest_surface->w; ds::clp[3] = dest_surface->h; + recalculate_clip(); } void origin(int x, int y) { - ds::cam[0] = -(ds::clip[0]+x); - ds::cam[1] = -(ds::clip[1]+y); + ds::origin[0] = x; + ds::origin[1] = y; } int camx() { - return ds::cam[0]; + return ds::origin[0]; } int camy() { - return ds::cam[1]; + return ds::origin[1]; } 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) { if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return 0; 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) { if (map_surface==NULL) return; //if (celw <= 0 || celh <= 0 || celw >= TILES_WIDTH || celh >= TILES_HEIGHT) return; - sx -= ds::cam[0]; sy -= ds::cam[1]; - if (sx+celw*8 < ds::clp[0] || sx > ds::clp[2] || sy+celh*8 < ds::clp[1] || sy > ds::clp[3]) return; + sx -= ds::origin[0]; sy -= ds::origin[1]; + 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) { int diff = -sx/8; 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; sy += diff*8; } - sx += ds::cam[0]; sy += ds::cam[1]; + sx += ds::origin[0]; sy += ds::origin[1]; for (int y=0; y