- Seguim treballant en polir bugs i deixar guapeta la API

This commit is contained in:
2025-02-17 14:01:34 +01:00
parent 29a90f4b46
commit 88e406dae0
5 changed files with 575 additions and 516 deletions

View File

@@ -2,7 +2,7 @@
x=0 x=0
function _init() function mini.init()
--text=other.peiv() --text=other.peiv()
--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
@@ -10,23 +10,34 @@ function _init()
--turbo(false) --turbo(false)
--local perico = "péricòñ" --local perico = "péricòñ"
--print(utf8.len(perico)) --print(utf8.len(perico))
ants = 0xc936;
s = surface.load("tiles01.gif") s = surface.load("tiles01.gif")
--surface.source(s) --surface.source(s)
p = palette.load("tiles01.gif") p = palette.load("tiles01.gif")
palette.set(p) palette.set(p)
palette.setTransparent(255)
print(#p) print(#p)
surface.save(s, "data/copy.gif", p) surface.save(s, "data/copy.gif")
s = surface.load("copy.gif") s = surface.load("copy.gif")
--draw.source(s) --draw.source(s)
system.setBeat(4)
end end
function _update() function mini.update()
if key.press(key.ESCAPE) then if keyboard.keyPressed(key.ESCAPE) then
sys.quit() system.quit()
end end
draw.cls(5) if system.isBeat() then
draw.blit(s, 0, 0, 64, 64, 10, 10) ants = (ants >> 12) | ((ants<<4)&0xffff)
end
surface.cls(5)
draw.surface(s, 0, 0, 64, 64, 10, 10)
draw.rect(10, 10, 73, 73, 8)
draw.setPattern(ants)
draw.rect(10, 10, 73, 73, 0)
draw.setPattern(0xffff)
--draw.print(#p,0,0,2) --draw.print(#p,0,0,2)
end end

View File

@@ -47,7 +47,7 @@ namespace gif
static void put_loop(gif_t *gif, uint16_t loop); static void put_loop(gif_t *gif, uint16_t loop);
gif_t *create(const char *fname, uint16_t width, uint16_t height, uint8_t *palette, uint8_t depth, uint8_t bgindex, int loop) gif_t *create(const char *fname, uint16_t width, uint16_t height, uint8_t *palette, uint8_t depth, int16_t bgindex, int loop)
{ {
gif_t *gif = (gif_t*)calloc(1, sizeof(*gif) + (bgindex < 0 ? 2 : 1)*width*height); gif_t *gif = (gif_t*)calloc(1, sizeof(*gif) + (bgindex < 0 ? 2 : 1)*width*height);
gif->w = width; gif->h = height; gif->w = width; gif->h = height;

1035
lua.cpp

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,8 @@
//#include "SDL2/SDL_mixer.h" //#include "SDL2/SDL_mixer.h"
#include "jail_audio.h" #include "jail_audio.h"
#define MAX_TEXTURES 10
#ifdef MACOS_BUNDLE #ifdef MACOS_BUNDLE
#include <libgen.h> #include <libgen.h>
#endif #endif
@@ -33,7 +35,7 @@ bool screen_cursor = true;
int desktop_width = 0; int desktop_width = 0;
int desktop_height = 0; int desktop_height = 0;
surface_t surfaces[10]; surface_t surfaces[MAX_TEXTURES];
surface_t *screen_surface = &surfaces[0]; surface_t *screen_surface = &surfaces[0];
surface_t *dest_surface = screen_surface; surface_t *dest_surface = screen_surface;
surface_t *source_surface = NULL; surface_t *source_surface = NULL;
@@ -164,7 +166,7 @@ void reinit() {
ds::trans=0; ds::trans=0;
ds::fill_pattern = 0b1111111111111111; ds::fill_pattern = 0b1111111111111111;
ds::fill_trans = false; ds::fill_trans = false;
for (int i=1; i<10; ++i) { for (int i=1; i<MAX_TEXTURES; ++i) {
if (surfaces[i].p != NULL) free(surfaces[i].p); if (surfaces[i].p != NULL) free(surfaces[i].p);
surfaces[i].p = NULL; surfaces[i].p = NULL;
} }
@@ -194,7 +196,7 @@ int scrh() {
uint8_t newsurf(int w, int h) { uint8_t newsurf(int w, int h) {
int i = 0; int i = 0;
while (i<10 && surfaces[i].p != NULL) ++i; while (i<MAX_TEXTURES && surfaces[i].p != NULL) ++i;
//[TODO] Gestionar el cas en que no queden surfaces lliures //[TODO] Gestionar el cas en que no queden surfaces lliures
surfaces[i].w = w; surfaces[i].w = w;
surfaces[i].h = h; surfaces[i].h = h;
@@ -205,7 +207,7 @@ uint8_t newsurf(int w, int h) {
uint8_t loadsurf(const char* filename) { uint8_t loadsurf(const char* filename) {
int i = 0; int i = 0;
while (i<10 && surfaces[i].p != NULL) ++i; while (i<MAX_TEXTURES && surfaces[i].p != NULL) ++i;
//[TODO] Gestionar el cas en que no queden surfaces lliures //[TODO] Gestionar el cas en que no queden surfaces lliures
int size; int size;
@@ -217,9 +219,11 @@ uint8_t loadsurf(const char* filename) {
return i; return i;
} }
void savesurf(uint8_t surface, const char* filename, uint8_t *pal) void savesurf(uint8_t surface, const char* filename, uint8_t *pal, uint8_t colors)
{ {
gif::gif_t *file = gif::create(filename, surfaces[surface].w, surfaces[surface].h, pal, (pal?8:0), 0, -1); uint8_t depth=colors;
do { depth = depth >> 1; } while (depth!=0);
gif::gif_t *file = gif::create(filename, surfaces[surface].w, surfaces[surface].h, pal, (pal?depth:0), -1, -1);
memcpy(file->frame, surfaces[surface].p, surfaces[surface].w*surfaces[surface].h); memcpy(file->frame, surfaces[surface].p, surfaces[surface].w*surfaces[surface].h);
gif::addFrame(file, 0); gif::addFrame(file, 0);
gif::close(file); gif::close(file);
@@ -260,6 +264,12 @@ void setmap(uint8_t surface) {
map_surface = &surfaces[surface]; map_surface = &surfaces[surface];
} }
uint8_t getmap()
{
for (int i=0; i<MAX_TEXTURES; ++i) if (map_surface == &surfaces[i]) return i;
return 0;
}
void createDisplay() { void createDisplay() {
if (screen_zoom <= 0) screen_zoom = 1; if (screen_zoom <= 0) screen_zoom = 1;
while (screen_width*screen_zoom > desktop_width || screen_height*screen_zoom > desktop_height) screen_zoom--; while (screen_width*screen_zoom > desktop_width || screen_height*screen_zoom > desktop_height) screen_zoom--;
@@ -468,7 +478,7 @@ int main(int argc,char*argv[]){
//Mix_Quit(); //Mix_Quit();
for (int i=0;i<10;++i) freesurf(i); for (int i=0;i<MAX_TEXTURES;++i) freesurf(i);
dest_surface = source_surface = map_surface = NULL; dest_surface = source_surface = map_surface = NULL;
destroyDisplay(); destroyDisplay();
SDL_Quit(); SDL_Quit();
@@ -684,7 +694,7 @@ void rectfill(int x0, int y0, int x1, int y1, uint8_t color) {
} }
void fillp(uint16_t pat, bool transparent) { void fillp(uint16_t pat, bool transparent) {
ds::fill_trans = transparent; ds::fill_trans = true; //transparent;
ds::fill_pattern = pat; ds::fill_pattern = pat;
do_pset=(pat==0xffff?pset_fast:pset_pattern); do_pset=(pat==0xffff?pset_fast:pset_pattern);
} }

3
mini.h
View File

@@ -119,7 +119,7 @@ int scrh();
uint8_t newsurf(int w, int h); uint8_t newsurf(int w, int h);
uint8_t loadsurf(const char* filename); uint8_t loadsurf(const char* filename);
void savesurf(uint8_t surface, const char* filename, uint8_t *pal); void savesurf(uint8_t surface, const char* filename, uint8_t *pal, uint8_t colors=0);
void freesurf(uint8_t surface); void freesurf(uint8_t surface);
int surfw(uint8_t surface); int surfw(uint8_t surface);
int surfh(uint8_t surface); int surfh(uint8_t surface);
@@ -127,6 +127,7 @@ int surfh(uint8_t surface);
void setdest(uint8_t surface); void setdest(uint8_t surface);
void setsource(uint8_t surface); void setsource(uint8_t surface);
void setmap(uint8_t surface); void setmap(uint8_t surface);
uint8_t getmap();
void cls(uint8_t color=0); void cls(uint8_t color=0);
void color(uint8_t color=6); void color(uint8_t color=6);