From 4a3450e11674dd29fba4b4ea2eadedd43ba1a598 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 19 Mar 2026 11:29:08 +0100 Subject: [PATCH] =?UTF-8?q?VERSI=C3=93=201.4.7=20-=20[NEW]=20map.cell()=20?= =?UTF-8?q?per=20a=20establir=20o=20llegir=20el=20tamany=20dels=20tiles=20?= =?UTF-8?q?del=20mapa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua.cpp | 17 ++++++++++++++++- mini.cpp | 35 ++++++++++++++++++++++------------- mini.h | 3 +++ version.h | 2 +- vscode/library.lua | 9 +++++++++ 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/lua.cpp b/lua.cpp index 3fcc13e..9221b70 100644 --- a/lua.cpp +++ b/lua.cpp @@ -217,7 +217,21 @@ extern "C" { return 0; } } - + + static int cpp_map_cell(lua_State *L) { + if (lua_gettop(L)==2) { + int celx = luaL_checknumber(L, 1); + int cely = luaL_checknumber(L, 2); + settilesize(celx, cely); + lua_pushinteger(L, mget(celx, cely)); + return 0; + } else { + lua_pushinteger(L, gettilew()); + lua_pushinteger(L, gettileh()); + return 2; + } + } + // palette // =============================================== @@ -1120,6 +1134,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_map_surf); lua_setfield(L, -2, "surf"); lua_pushcfunction(L,cpp_map_draw); lua_setfield(L, -2, "draw"); lua_pushcfunction(L,cpp_map_tile); lua_setfield(L, -2, "tile"); + lua_pushcfunction(L,cpp_map_cell); lua_setfield(L, -2, "cell"); lua_setglobal(L, "map"); lua_newtable(L); diff --git a/mini.cpp b/mini.cpp index b4bcfdc..544f493 100644 --- a/mini.cpp +++ b/mini.cpp @@ -60,6 +60,8 @@ surface_t *screen_surface = &surfaces[0]; surface_t *dest_surface = screen_surface; surface_t *source_surface = NULL; surface_t *map_surface = NULL; +uint8_t tile_width = 8; +uint8_t tile_height = 8; font_t fonts[MAX_FONTS]; font_t *current_font; @@ -1308,10 +1310,10 @@ void sset(int x, int y, uint8_t color) { void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) { if (!source_surface) return; - int tx = (n%(source_surface->w >> 3))<<3; - int ty = (n/(source_surface->w >> 3))<<3; - int tw = w*8 - 1; - int th = h*8 - 1; + int tx = (n%(source_surface->w / tile_width))*tile_width; + int ty = (n/(source_surface->w / tile_height))*tile_height; + int tw = w*tile_width - 1; + int th = h*tile_height - 1; //int tx2 = tx1 + tw; //int ty2 = ty1 + th; int txd = 1; @@ -1444,6 +1446,13 @@ void mset(int celx, int cely, uint8_t snum) { TILES(celx, cely) = snum; } +uint8_t gettilew() { return tile_width; } +uint8_t gettileh() { return tile_height; } +void settilesize(int w, int h) { + tile_width = w; + tile_height = h; +} + void map() { //int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer) { if (map_surface==NULL) return; int celw = map_surface->w;// >> 3; @@ -1452,28 +1461,28 @@ void map() { //int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, u int cely = 0; //if (celw <= 0 || celh <= 0 || celw >= TILES_WIDTH || celh >= TILES_HEIGHT) return; int sx = ds::origin[0]; int 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+celw*tile_width < ds::clip[0] || sx > ds::clip[2] || sy+celh*tile_height < ds::clip[1] || sy > ds::clip[3]) return; if (sx<0) { - int diff = -sx/8; + int diff = -sx/tile_width; celx += diff; celw -= diff; - sx += diff*8; + sx += diff*tile_width; } if (sy<0) { - int diff = -sy/8; + int diff = -sy/tile_height; cely += diff; celh -= diff; - sy += diff*8; + sy += diff*tile_height; } sx -= ds::origin[0]; sy -= ds::origin[1]; for (int y=0; yds::clip[2]) || (fy>ds::clip[3]) ) continue; - spr(tile, sx+x*8, sy+y*8); + const int fx = sx+(x*tile_width)+ds::origin[0]; + const int fy = sy+(y*tile_height)+ds::origin[1]; + if ( (fx+tile_widthds::clip[2]) || (fy>ds::clip[3]) ) continue; + spr(tile, sx+x*tile_width, sy+y*tile_height); } } } diff --git a/mini.h b/mini.h index 5a4ec20..a051a8f 100644 --- a/mini.h +++ b/mini.h @@ -225,6 +225,9 @@ void tvline(int x, int y0, int y1, float mx, float my, float mdx=0.0f, float mdy uint8_t mget(int celx, int cely); void mset(int celx, int cely, uint8_t snum); +uint8_t gettilew(); +uint8_t gettileh(); +void settilesize(int w, int h); void map(); //int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer=0); bool btn(uint8_t i); diff --git a/version.h b/version.h index 21e0f01..3bd2f34 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "1.4.6" +#define MINI_VERSION "1.4.7" diff --git a/vscode/library.lua b/vscode/library.lua index 5997d44..bfae7e5 100644 --- a/vscode/library.lua +++ b/vscode/library.lua @@ -102,6 +102,15 @@ function map.tile(x, y) end ---Set the tile at the position (x,y) in the current tilemap function map.tile(x, y, tile) end +---@param w number +---@param h number +---Set current tile size +function map.cell(w, h) end + +---@return number w, number h +---Set current tile size +function map.cell() end + ---@class pal pal = {}