diff --git a/source/mini/draw/draw.cpp b/source/mini/draw/draw.cpp index 1acb7fe..f6fa4b0 100644 --- a/source/mini/draw/draw.cpp +++ b/source/mini/draw/draw.cpp @@ -403,6 +403,31 @@ namespace mini } } + void tileblit(uint8_t n, int x, int y, int tw, int th) { + //const int tw = tile_width; + //const int th = tile_height; + + const int tiles_per_row = mini::surf::state.source_surface->w / tw; + + // Coordenadas del tile dentro del spritesheet + int tx = (n % tiles_per_row) * tw; + int ty = (n / tiles_per_row) * th; + + int src_y = ty; + + for (int yi = 0; yi < th; ++yi) { + int src_x = tx; + + for (int xi = 0; xi < tw; ++xi) { + uint8_t c = mini::draw::pixel::get(src_x, src_y); + mini::draw::pixel::subst_pset(x + xi, y + yi, c); + src_x++; + } + + src_y++; + } + } + const uint8_t printchar(uint8_t c, int x, int y) { font::char_t &chr = font::current_font->chars[c]; draw::surf(chr.x, chr.y, chr.w, chr.h, x, y-chr.base); diff --git a/source/mini/draw/draw.h b/source/mini/draw/draw.h index 55a28cb..c0a93cb 100644 --- a/source/mini/draw/draw.h +++ b/source/mini/draw/draw.h @@ -47,7 +47,8 @@ namespace mini void surf(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 surfrot(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 tileblit(uint8_t n, int x, int y, int tw, int th); + void text(const char *str, int x, int y, uint8_t color); namespace mode diff --git a/source/aux/default_font_fnt.h b/source/mini/font/default_font_fnt.h similarity index 100% rename from source/aux/default_font_fnt.h rename to source/mini/font/default_font_fnt.h diff --git a/source/aux/default_font_gif.h b/source/mini/font/default_font_gif.h similarity index 100% rename from source/aux/default_font_gif.h rename to source/mini/font/default_font_gif.h diff --git a/source/mini/font/font.cpp b/source/mini/font/font.cpp index b6141bd..8d89ded 100644 --- a/source/mini/font/font.cpp +++ b/source/mini/font/font.cpp @@ -1,4 +1,7 @@ #include "font.h" +#include "default_font_gif.h" +#include "default_font_fnt.h" + #include "mini/surf/surf.h" #include "mini/file/file.h" #include "aux/log.h" @@ -99,6 +102,14 @@ namespace mini return i; } + void init() { + //uint8_t font_surf = + surf::load(default_font_gif, "default_font"); + //surfaces[font_surf].flags |= SURF_GENERATED; + font::load_from_buffer((const char*)default_font_fnt, 0, "default_font"); + current_font = &fonts[0]; + } + namespace current { void set(uint8_t font) { current_font = &fonts[font]; diff --git a/source/mini/font/font.h b/source/mini/font/font.h index b1e4fda..79826a0 100644 --- a/source/mini/font/font.h +++ b/source/mini/font/font.h @@ -18,6 +18,8 @@ namespace mini }; extern font_t *current_font; + void init(); + uint8_t load(const char *filename); namespace current { diff --git a/source/mini/key/key.cpp b/source/mini/key/key.cpp index 690af4a..c3216e6 100644 --- a/source/mini/key/key.cpp +++ b/source/mini/key/key.cpp @@ -1,5 +1,6 @@ #include "key.h" #include "mini/pad/pad.h" +#include "mini/win/win.h" #include @@ -34,11 +35,10 @@ namespace mini } void text(const bool enable) { - // [TODO] - //if (enable) - // SDL_StartTextInput(mini_win); - //else - // SDL_StopTextInput(mini_win); + if (enable) + SDL_StartTextInput(win::state.window); + else + SDL_StopTextInput(win::state.window); } const char* utf8char() { diff --git a/source/mini/lua/lua.cpp b/source/mini/lua/lua.cpp index 33ae023..43536b5 100644 --- a/source/mini/lua/lua.cpp +++ b/source/mini/lua/lua.cpp @@ -132,6 +132,8 @@ namespace mini lua_pop(L,1); lua_pop(L,1); + debug::init(L); + //std::thread(debugCommandThread).detach(); printf("stdin isatty: %d\n", isatty(0)); is_playing = true; diff --git a/source/mini/lua/lua.debug.cpp b/source/mini/lua/lua.debug.cpp index c440ee0..faedc15 100644 --- a/source/mini/lua/lua.debug.cpp +++ b/source/mini/lua/lua.debug.cpp @@ -143,9 +143,13 @@ namespace mini //const char* src = chunkToPath(ar.source).c_str(); json frame = { - { "file", chunkToPath(ar.source).c_str() }, + { "id", depth + 1 }, + { "name", ar.name ? ar.name : "?" }, { "line", ar.currentline }, - { "name", ar.name ? ar.name : "?" } + { "column", 1 }, + { "source", { + { "path", chunkToPath(ar.source) } + }} }; frames.push_back(frame); @@ -153,7 +157,8 @@ namespace mini } return json{ - { "frames", frames } + { "stackFrames", frames }, + { "totalFrames", depth } }; } @@ -1340,6 +1345,10 @@ namespace mini } } + void init(lua_State* L) { + lua_sethook(L, luaHook, LUA_MASKCALL | LUA_MASKRET, 0); + } + void kill_thread() { g_running = false; stdinThread.request_stop(); diff --git a/source/mini/lua/lua.debug.h b/source/mini/lua/lua.debug.h index fdb81ce..9fc8b75 100644 --- a/source/mini/lua/lua.debug.h +++ b/source/mini/lua/lua.debug.h @@ -8,6 +8,7 @@ namespace mini namespace debug { bool call_and_handle_exceptions(lua_State* L); + void init(lua_State* L); void kill_thread(); void process_commands(lua_State* L); void toggle(lua_State* L); diff --git a/source/mini/lua/lua.wrappers.cpp b/source/mini/lua/lua.wrappers.cpp index 8b8151a..815ab29 100644 --- a/source/mini/lua/lua.wrappers.cpp +++ b/source/mini/lua/lua.wrappers.cpp @@ -2,6 +2,10 @@ #include "external/lua/lua.hpp" #include "mini/mini.h" +#include "mini/surf/surf.h" +#include "mini/draw/draw.h" +#include "mini/pal/pal.h" +#include "mini/font/font.h" #include "mini/win/win.h" #include "mini/view/view.h" #include "mini/shader/shader.h" @@ -198,21 +202,6 @@ namespace mini return 0; } } - - static int pixel(lua_State *L) { - if (lua_gettop(L)==2) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - lua_pushinteger(L, mini::surf::pixel::get(x, y)); - return 1; - } else { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - uint8_t color = luaL_checkinteger(L, 3); - mini::surf::pixel::set(x, y, color); - return 0; - } - } } namespace map @@ -400,6 +389,21 @@ namespace mini namespace draw { + static int pixel(lua_State *L) { + if (lua_gettop(L)==2) { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + lua_pushinteger(L, mini::draw::pixel::get(x, y)); + return 1; + } else { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + uint8_t color = luaL_checkinteger(L, 3); + mini::draw::pixel::set(x, y, color); + return 0; + } + } + static int line(lua_State *L) { int x0 = luaL_checknumber(L, 1); int y0 = luaL_checknumber(L, 2); @@ -1033,7 +1037,6 @@ namespace mini lua_pushcfunction(L,wrappers::surf::source); lua_setfield(L, -2, "source"); lua_pushcfunction(L,wrappers::surf::cls); lua_setfield(L, -2, "cls"); lua_pushcfunction(L,wrappers::surf::clip); lua_setfield(L, -2, "clip"); - lua_pushcfunction(L,wrappers::surf::pixel); lua_setfield(L, -2, "pixel"); lua_pushinteger(L, 0); lua_setfield(L, -2, "SCREEN"); lua_setglobal(L, "surf"); @@ -1059,6 +1062,7 @@ namespace mini lua_setglobal(L, "view"); lua_newtable(L); + lua_pushcfunction(L,wrappers::draw::pixel); lua_setfield(L, -2, "pixel"); lua_pushcfunction(L,wrappers::draw::line); lua_setfield(L, -2, "line"); lua_pushcfunction(L,wrappers::draw::hline); lua_setfield(L, -2, "hline"); lua_pushcfunction(L,wrappers::draw::vline); lua_setfield(L, -2, "vline"); diff --git a/source/mini/main.cpp b/source/mini/main.cpp index 3d189bc..c1aedc2 100644 --- a/source/mini/main.cpp +++ b/source/mini/main.cpp @@ -1,6 +1,9 @@ #include "mini.h" #include "win/win.h" #include "view/view.h" +#include "surf/surf.h" +#include "pal/pal.h" +#include "draw/draw.h" uint16_t ants = 0xc936; float t = 0; @@ -19,13 +22,13 @@ void exception_loop() { pal::color::set(1,0xff000000); const int w=win::res::getw(); const int h=win::res::geth(); - mini::draw::mode::set(0); - mini::draw::rect(0,0,w,h,1); - mini::draw::rect(1,1,w-2,h-2,1); - mini::draw::mode::set(1); + draw::mode::set(0); + draw::rect(0,0,w,h,1); + draw::rect(1,1,w-2,h-2,1); + draw::mode::set(1); draw::pattern::set(ants); - mini::draw::rect(0,0,w,h,0); - mini::draw::rect(1,1,w-2,h-2,0); + draw::rect(0,0,w,h,0); + draw::rect(1,1,w-2,h-2,0); ants = (ants<<12) | (ants>>4); } } \ No newline at end of file diff --git a/source/mini/mini.cpp b/source/mini/mini.cpp index 2350803..bed3472 100644 --- a/source/mini/mini.cpp +++ b/source/mini/mini.cpp @@ -2,6 +2,7 @@ #include "version.h" #include "surf/surf.h" +#include "pal/pal.h" #include "font/font.h" #include "draw/draw.h" #include "win/win.h" @@ -15,8 +16,6 @@ #include "file/file.h" #include "lua/lua.h" #include "aux/log.h" -#include "aux/default_font_gif.h" -#include "aux/default_font_fnt.h" #include @@ -60,11 +59,8 @@ bool should_quit = false; Uint32 *pixels; int pitch; -uint32_t palette[256] = { 0xFF1a1c2c, 0xFF5d275d, 0xFFb13e53, 0xFFef7d57, 0xFFffcd75, 0xFFa7f070, 0xFF38b764, 0xFF257179, - 0xFF29366f, 0xFF3b5dc9, 0xFF41a6f6, 0xFF73eff7, 0xFFf4f4f4, 0xFF94b0c2, 0xFF566c86, 0xFF333c57 }; - -surf::surface_t* map_surface = NULL; +mini::surf::surface_t* map_surface = NULL; int16_t beats, num_beats = 0; @@ -124,31 +120,6 @@ namespace mini } } - static inline void tileblit(uint8_t n, int x, int y) { - const int tw = tile_width; - const int th = tile_height; - - const int tiles_per_row = mini::surf::state.source_surface->w / tw; - - // Coordenadas del tile dentro del spritesheet - int tx = (n % tiles_per_row) * tw; - int ty = (n / tiles_per_row) * th; - - int src_y = ty; - - for (int yi = 0; yi < th; ++yi) { - int src_x = tx; - - for (int xi = 0; xi < tw; ++xi) { - uint8_t c = mini::draw::pixel::get(src_x, src_y); - mini::draw::pixel::subst_pset(x + xi, y + yi, c); - src_x++; - } - - src_y++; - } - } - void draw() { if (!map_surface || !mini::surf::state.source_surface) return; @@ -205,7 +176,7 @@ namespace mini uint8_t tile = tile::get(celx + x, cely + y); if (!tile) continue; int tx = sx + x * tw; - tileblit(tile, tx - ox, ty - oy); + draw::tileblit(tile, tx - ox, ty - oy, tile_width, tile_height); } } } @@ -236,53 +207,6 @@ namespace mini } - namespace pal - { - uint32_t *load(const char* filename, uint16_t *palsize) { - int size; - uint8_t *buffer = (uint8_t*)file::getfilebuffer(filename, size); - // [TODO] - uint32_t *pal = nullptr; //LoadPalette(buffer, palsize); - free(buffer); - return pal; - } - - void set(uint32_t *pal) { - for (int i=0; i<256; ++i) palette[i] = pal[i] | 0xff000000; - } - - namespace color { - void set(uint8_t index, uint32_t color) { - palette[index] = color | 0xff000000; - } - - uint32_t get(uint8_t index) { - return palette[index]; - } - } - - namespace trans { - void set(uint8_t index) { - ds::trans = index; - } - - uint8_t get() { - return ds::trans; - } - } - - namespace subpal { - uint8_t set(uint8_t index, uint8_t color) { - const uint8_t old = ds::draw_palette[SDL_clamp(index,0,255)]; - ds::draw_palette[SDL_clamp(index,0,255)] = SDL_clamp(color,0,255); - return old; - } - - void reset() { - for (int i=0;i<256;++i) ds::draw_palette[i]=i; - } - } - } @@ -337,8 +261,8 @@ void reinit() { mini::view::init(); // Reset draw state - ds::mode = DRAWMODE_NORMAL; - ds::fill_pattern = 0b1111111111111111; + mini::draw::state.mode = DRAWMODE_NORMAL; + mini::draw::state.fill_pattern = 0b1111111111111111; // Reset surf state for (unsigned int i=0; i13) { dt = SDL_GetTicks(); @@ -523,7 +444,7 @@ int main(int argc,char*argv[]){ SDL_SetRenderDrawColor(win::state.renderer, 0, 0, 0, 255); SDL_RenderClear(win::state.renderer); SDL_LockTexture(win::state.tex_back, NULL, (void**)&pixels, &pitch); - for (uint32_t i=0;isize;++i) pixels[i] = palette[surf::state.screen_surface->p[i]]; + for (uint32_t i=0;isize;++i) pixels[i] = pal::palette[surf::state.screen_surface->p[i]]; SDL_UnlockTexture(win::state.tex_back); SDL_RenderTexture(win::state.renderer, win::state.tex_back, NULL, NULL); //NEW diff --git a/source/mini/mini.h b/source/mini/mini.h index 42f1c83..66363a6 100644 --- a/source/mini/mini.h +++ b/source/mini/mini.h @@ -27,24 +27,6 @@ namespace mini } } - namespace pal - { - uint32_t *load(const char* filename, uint16_t *palsize=nullptr); - void set(uint32_t *pal); - namespace color { - void set(uint8_t index, uint32_t color); - uint32_t get(uint8_t index); - } - namespace trans { - void set(uint8_t index); - uint8_t get(); - } - namespace subpal { - uint8_t set(uint8_t index, uint8_t color); - void reset(); - } - } - namespace sys { float delta(); diff --git a/source/mini/mouse/mouse.cpp b/source/mini/mouse/mouse.cpp index 83bf86e..af79e6a 100644 --- a/source/mini/mouse/mouse.cpp +++ b/source/mini/mouse/mouse.cpp @@ -1,4 +1,5 @@ #include "mouse.h" +#include "mini/view/view.h" #include @@ -9,11 +10,11 @@ namespace mini state_t state; int posx() { - return state.x; + return state.x-view::state.origin[0]; } int posy() { - return state.y; + return state.y-view::state.origin[1]; } int wheel() { @@ -38,7 +39,9 @@ namespace mini } bool inside(int x, int y, int w, int h) { - return (state.x>=x) && (state.y>=y) && (state.x=x) && (my>=y) && (mx + +#include + +namespace mini +{ + namespace pal + { + uint32_t palette[256] = { 0xFF1a1c2c, 0xFF5d275d, 0xFFb13e53, 0xFFef7d57, 0xFFffcd75, 0xFFa7f070, 0xFF38b764, 0xFF257179, + 0xFF29366f, 0xFF3b5dc9, 0xFF41a6f6, 0xFF73eff7, 0xFFf4f4f4, 0xFF94b0c2, 0xFF566c86, 0xFF333c57 }; + + uint32_t* LoadPalette(uint8_t *buffer, uint16_t *size = NULL ) + { + buffer += 10; + const uint8_t fields = *buffer; + + uint32_t *global_color_table = (uint32_t *)calloc(1, 1024);; + + if (size) *size = 0; + if (fields & 0x80) { + int global_color_table_size = 1 << (((fields & 0x07) + 1)); + if (size) *size = global_color_table_size; + + for (int i=0; i + +namespace mini +{ + namespace pal + { + extern uint32_t palette[256]; + + uint32_t *load(const char* filename, uint16_t *palsize=nullptr); + void set(uint32_t *pal); + namespace color { + void set(uint8_t index, uint32_t color); + uint32_t get(uint8_t index); + } + namespace trans { + void set(uint8_t index); + uint8_t get(); + } + namespace subpal { + uint8_t set(uint8_t index, uint8_t color); + void reset(); + } + } +} diff --git a/source/mini/surf/surf.cpp b/source/mini/surf/surf.cpp index 5e4c9df..063e65a 100644 --- a/source/mini/surf/surf.cpp +++ b/source/mini/surf/surf.cpp @@ -3,8 +3,8 @@ #include "aux/gif.h" #include "aux/gifenc.h" #include "aux/log.h" -#include "file/file.h" -#include "draw/draw.h" +#include "mini/file/file.h" +#include "mini/draw/draw.h" #include @@ -179,8 +179,8 @@ namespace mini void set(int x, int y, int w, int h) { state.dest_surface->clip[0]=x; state.dest_surface->clip[1]=y; - state.dest_surface->clip[2]=w-x-1; - state.dest_surface->clip[3]=h-y-1; + state.dest_surface->clip[2]=x+(w-1); + state.dest_surface->clip[3]=y+(h-1); recalculate(); } void reset(int surface) { diff --git a/source/mini/surf/surf.h b/source/mini/surf/surf.h index fb85b77..ff90297 100644 --- a/source/mini/surf/surf.h +++ b/source/mini/surf/surf.h @@ -25,12 +25,14 @@ namespace mini surface_t surfaces[MAX_SURFACES]; surface_t* screen_surface = &surfaces[0]; surface_t* dest_surface = screen_surface; - surface_t* source_surface = NULL; + surface_t* source_surface = nullptr; }; extern state_t state; uint8_t create(int w, int h); uint8_t load(const char* filename, const bool external = false); + uint8_t load(uint8_t* buffer, const char* name); + void reloadsurfs(); void save(uint8_t surface, const char* filename, uint8_t *pal, uint8_t colors=0); void destroy(uint8_t surface); int width(uint8_t surface); diff --git a/source/mini/version.h b/source/mini/version.h index d2cbf1c..20248a9 100644 --- a/source/mini/version.h +++ b/source/mini/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "1.4.10" +#define MINI_VERSION "1.5.0" diff --git a/source/mini/win/win.cpp b/source/mini/win/win.cpp index 9ee41a6..647fa99 100644 --- a/source/mini/win/win.cpp +++ b/source/mini/win/win.cpp @@ -18,7 +18,7 @@ namespace mini while (state.width*state.zoom > dm->w || state.height*state.zoom > dm->h) state.zoom--; // Crear SDL_Window i SDL_Renderer - state.window = SDL_CreateWindow(state.title, state.width*state.zoom, state.height*state.zoom, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE|(state.fullscreen?SDL_WINDOW_FULLSCREEN:0)); + state.window = SDL_CreateWindow(state.title, state.width*state.zoom, state.height*state.zoom, SDL_WINDOW_OPENGL|(state.fullscreen?SDL_WINDOW_FULLSCREEN:0)); //windowID = SDL_GetWindowID(mini_win); SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); state.renderer = SDL_CreateRenderer(state.window, NULL); diff --git a/vscode/library.lua b/vscode/library.lua index 8b638a5..eaa9084 100644 --- a/vscode/library.lua +++ b/vscode/library.lua @@ -71,18 +71,6 @@ function surf.clip() end ---Set the clipping region of the current target surface function surf.clip(x, y, w, h) end ----@param x number ----@param y number ----@return number color ----Get color of pixel (x,y) on the source surface. -function surf.pixel(x, y) end - ----@param x number ----@param y number ----@param color number ----Set the color for pixel (x,y) on the target surface. -function surf.pixel(x, y, color) end - surf.SCREEN = 0 @@ -204,6 +192,18 @@ function view.tolocal(x, y) end draw = {} +---@param x number +---@param y number +---@return number color +---Get color of pixel (x,y) on the source surface. +function draw.pixel(x, y) end + +---@param x number +---@param y number +---@param color number +---Set the color for pixel (x,y) on the target surface. +function draw.pixel(x, y, color) end + ---@param x1 number ---@param y1 number ---@param x2 number