- [NEW] res() without arguments returns width and height of window.
- [NEW] camera() without arguments returns 'x' and 'y' of camera. - [NEW] palcolor() to set or get a color from the palette (replaces setcolor() & getcolor() ). - [NEW] paltrans() to set or get which color index is transparent (replaces settrans() & gettrans() ). - [RENAME] sspr() to blit(), spr_r() to blit_r() - [NEW] mouse() returns both x and y mouse coordinates. - [DEPRECATED] setcolor(), getcolor(), settrans(), gettrans(), spr(), sspr(), spr_r(), mousex(), mousey(), abs(), ceil(), flr(), sgn(), sin(), cos(), atan2(), sqrt(), max(), mid(), min(), tostr(), ascii(), strlen(), fopen(), fopenres(), fclose(), feof(), fwritei(), fwrited(), fwrites(), fwritew(), fwriteb(), fwriteln(), freadi(), freadd(), freads(), freadw(), freadb() - [FIX] Now the background on resizable windows is filled with black instead of garbage. - [FIX] Compiling on Linux uses POSIX functions.
This commit is contained in:
4
Makefile
4
Makefile
@@ -20,8 +20,8 @@ macos_bundle:
|
||||
clang++ $(source) -D MACOS_BUNDLE -Wall -Os -std=c++11 -framework SDL2 -framework SDL2_mixer -F /Library/Frameworks -ffunction-sections -fdata-sections -o mini_bundle -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
|
||||
|
||||
linux:
|
||||
g++ $(source) -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lSDL2 -lSDL2_mixer -o "$(executable)"
|
||||
g++ $(source) -D LUA_USE_LINUX -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lSDL2 -lSDL2_mixer -o "$(executable)"
|
||||
strip -s -R .comment -R .gnu.version --strip-unneeded "$(executable)"
|
||||
|
||||
linux_debug:
|
||||
g++ $(source) -D DEBUG -g -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lSDL2 -lSDL2_mixer -o "$(executable)_debug"
|
||||
g++ $(source) -D LUA_USE_LINUX -D DEBUG -g -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lSDL2 -lSDL2_mixer -o "$(executable)_debug"
|
||||
|
||||
@@ -8,6 +8,8 @@ function _init()
|
||||
keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT
|
||||
_update=normal_update
|
||||
turbo(false)
|
||||
local perico = "péricòñ"
|
||||
print(utf8.len(perico))
|
||||
end
|
||||
|
||||
function _update()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
return {
|
||||
peiv = function()
|
||||
setcolor(1, 1, 1, 1)
|
||||
return "HOLA OTHER UNIT"
|
||||
end
|
||||
}
|
||||
|
||||
211
lua.cpp
211
lua.cpp
@@ -109,31 +109,49 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_setcolor(lua_State *L) {
|
||||
static int cpp_palcolor(lua_State *L) {
|
||||
if (lua_gettop(L) >= 1) {
|
||||
uint8_t index = luaL_checkinteger(L, 1);
|
||||
if (lua_gettop(L) > 1) {
|
||||
uint8_t r = luaL_checkinteger(L, 2);
|
||||
uint8_t g = luaL_checkinteger(L, 3);
|
||||
uint8_t b = luaL_checkinteger(L, 4);
|
||||
uint8_t g = luaL_optinteger(L, 3, 0);
|
||||
uint8_t b = luaL_optinteger(L, 4, 0);
|
||||
uint32_t color = (r<<16) + (g<<8) + b;
|
||||
setcolor(index, color);
|
||||
return 0;
|
||||
}
|
||||
static int cpp_getcolor(lua_State *L) {
|
||||
uint8_t index = luaL_checkinteger(L, 1);
|
||||
} else {
|
||||
uint32_t color = getcolor(index);
|
||||
lua_pushinteger(L, (color>>16)&0xff);
|
||||
lua_pushinteger(L, (color>>8)&0xff);
|
||||
lua_pushinteger(L, color&0xff);
|
||||
return 3;
|
||||
}
|
||||
static int cpp_settrans(lua_State *L) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_paltrans(lua_State *L) {
|
||||
if (lua_gettop(L) == 0) {
|
||||
lua_pushinteger(L, gettrans());
|
||||
return 1;
|
||||
} else {
|
||||
uint8_t index = luaL_checkinteger(L, 1);
|
||||
settrans(index);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int cpp_setcolor(lua_State *L) {
|
||||
return luaL_error(L, "Function 'setcolor' is DEPRECATED. Use 'palcolor' instead.");
|
||||
}
|
||||
static int cpp_getcolor(lua_State *L) {
|
||||
return luaL_error(L, "Function 'getcolor' is DEPRECATED. Use 'palcolor' instead.");
|
||||
}
|
||||
static int cpp_settrans(lua_State *L) {
|
||||
return luaL_error(L, "Function 'settrans' is DEPRECATED. Use 'paltrans' instead.");
|
||||
}
|
||||
static int cpp_gettrans(lua_State *L) {
|
||||
lua_pushinteger(L, gettrans());
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'gettrans' is DEPRECATED. Use 'paltrans' instead.");
|
||||
}
|
||||
static int cpp_subpal(lua_State *L) {
|
||||
const int numargs = lua_gettop(L);
|
||||
@@ -282,11 +300,17 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_camera(lua_State *L) {
|
||||
if (lua_gettop(L) == 0) {
|
||||
lua_pushinteger(L, camx());
|
||||
lua_pushinteger(L, camy());
|
||||
return 2;
|
||||
} else {
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
camera(x, y);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int cpp_view(lua_State *L) {
|
||||
if (lua_gettop(L) == 0) {
|
||||
@@ -390,18 +414,18 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_spr(lua_State *L) {
|
||||
uint8_t n = luaL_checkinteger(L, 1);
|
||||
int x = luaL_checknumber(L, 2);
|
||||
int y = luaL_checknumber(L, 3);
|
||||
float w = luaL_optnumber(L, 4, 1.0f);
|
||||
float h = luaL_optnumber(L, 5, 1.0f);
|
||||
bool flip_x = lua_toboolean(L, 6);
|
||||
bool flip_y = lua_toboolean(L, 7);
|
||||
spr(n, x, y, w, h, flip_x, flip_y);
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'spr' is DEPRECATED. No direct replacement. Use 'blit' instead.");
|
||||
}
|
||||
|
||||
static int cpp_sspr(lua_State *L) {
|
||||
return luaL_error(L, "Function 'sspr' is DEPRECATED. Use 'blit' instead.");
|
||||
}
|
||||
|
||||
static int cpp_spr_r(lua_State *L) {
|
||||
return luaL_error(L, "Function 'spr_r' is DEPRECATED. Use 'blit_r' instead.");
|
||||
}
|
||||
|
||||
static int cpp_blit(lua_State *L) {
|
||||
int sx = luaL_checknumber(L, 1);
|
||||
int sy = luaL_checknumber(L, 2);
|
||||
int sw = luaL_checknumber(L, 3);
|
||||
@@ -413,11 +437,11 @@ extern "C" {
|
||||
bool flip_x = lua_toboolean(L, 9);
|
||||
bool flip_y = lua_toboolean(L, 10);
|
||||
bool invert = lua_toboolean(L, 11);
|
||||
sspr(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, invert);
|
||||
blit(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, invert);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_spr_r(lua_State *L) {
|
||||
static int cpp_blit_r(lua_State *L) {
|
||||
int sx = luaL_checknumber(L, 1);
|
||||
int sy = luaL_checknumber(L, 2);
|
||||
int sw = luaL_checknumber(L, 3);
|
||||
@@ -425,7 +449,7 @@ extern "C" {
|
||||
int dx = luaL_checknumber(L, 5);
|
||||
int dy = luaL_checknumber(L, 6);
|
||||
float a = luaL_checknumber(L, 7);
|
||||
spr_r(sx, sy, sw, sh, dx, dy, a);
|
||||
blit_r(sx, sy, sw, sh, dx, dy, a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -530,14 +554,18 @@ extern "C" {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_mousex(lua_State *L) {
|
||||
static int cpp_mouse(lua_State *L) {
|
||||
lua_pushinteger(L, mousex());
|
||||
return 1;
|
||||
lua_pushinteger(L, mousey());
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int cpp_mousex(lua_State *L) {
|
||||
return luaL_error(L, "Function 'mousex' is DEPRECATED. Use 'mouse' instead.");
|
||||
}
|
||||
|
||||
static int cpp_mousey(lua_State *L) {
|
||||
lua_pushinteger(L, mousey());
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'mousey' is DEPRECATED. Use 'mouse' instead.");
|
||||
}
|
||||
|
||||
static int cpp_mwheel(lua_State *L) {
|
||||
@@ -569,64 +597,37 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_abs(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
lua_pushnumber(L, abs(x));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'abs' is DEPRECATED. Use 'math.abs' instead.");
|
||||
}
|
||||
static int cpp_ceil(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
lua_pushnumber(L, ceil(x));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'ceil' is DEPRECATED. Use 'math.ceil' instead.");
|
||||
}
|
||||
static int cpp_flr(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
lua_pushnumber(L, flr(x));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'flr' is DEPRECATED. Use 'math.floor' instead.");
|
||||
}
|
||||
static int cpp_sgn(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
lua_pushnumber(L, sgn(x));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'sgn' is DEPRECATED. No direct replacement though...");
|
||||
}
|
||||
static int cpp_sin(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
lua_pushnumber(L, sin(x));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'sin' is DEPRECATED. Use 'math.sin' instead.");
|
||||
}
|
||||
static int cpp_cos(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
lua_pushnumber(L, cos(x));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'cos' is DEPRECATED. Use 'math.cos' instead.");
|
||||
}
|
||||
static int cpp_atan2(lua_State *L) {
|
||||
float dx = luaL_checknumber(L, 1);
|
||||
float dy = luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, atan2(dx, dy));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'atan2' is DEPRECATED. Use 'math.atan2' instead.");
|
||||
}
|
||||
static int cpp_sqrt(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
lua_pushnumber(L, sqrt(x));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'sqrt' is DEPRECATED. Use 'math.sqrt' instead.");
|
||||
}
|
||||
static int cpp_max(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
float y = luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, max(x, y));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'max' is DEPRECATED. Use 'math.max' instead.");
|
||||
}
|
||||
static int cpp_mid(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
float y = luaL_checknumber(L, 2);
|
||||
float z = luaL_checknumber(L, 3);
|
||||
lua_pushnumber(L, mid(x, y, z));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'mid' is DEPRECATED. No direct replacement though...");
|
||||
}
|
||||
static int cpp_min(lua_State *L) {
|
||||
float x = luaL_checknumber(L, 1);
|
||||
float y = luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, min(x, y));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'min' is DEPRECATED. Use 'math.min' instead.");
|
||||
}
|
||||
static int cpp_rnd(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
@@ -639,101 +640,71 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
static int cpp_tostr(lua_State *L) {
|
||||
int val = luaL_checknumber(L, 1);
|
||||
lua_pushstring(L, tostr(val));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'tostr' is DEPRECATED. Use Lua's own methods instead.");
|
||||
}
|
||||
static int cpp_ascii(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
int index = luaL_checkinteger(L, 2);
|
||||
lua_pushinteger(L, ascii(str, index));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'ascii' is DEPRECATED. Use 'string.byte' instead (1 based indexing though...).");
|
||||
}
|
||||
static int cpp_strlen(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
lua_pushinteger(L, utfstrlen(str));
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'strlen' is DEPRECATED. Use 'utf8.len' instead.");
|
||||
}
|
||||
|
||||
static int cpp_fopen(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
uint8_t mode = luaL_optinteger(L, 2, 0);
|
||||
fopen(str, mode);
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'fopen' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
static int cpp_fopenres(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
fopenres(str);
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'fopenres' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
static int cpp_fclose(lua_State *L) {
|
||||
fclose();
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'fclose' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_feof(lua_State *L) {
|
||||
lua_pushboolean(L,feof());
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'feof' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_fwritei(lua_State *L) {
|
||||
int value = luaL_checkinteger(L, 1);
|
||||
fwritei(value);
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'fwritei' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_fwrited(lua_State *L) {
|
||||
float value = luaL_checknumber(L, 1);
|
||||
fwrited(value);
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'fwrited' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_fwrites(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
fwrites(str);
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'fwrites' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_fwritew(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
fwritew(str);
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'fwritew' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_fwriteb(lua_State *L) {
|
||||
bool value = lua_toboolean(L, 1);
|
||||
fwriteb(value);
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'fwriteb' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_fwriteln(lua_State *L) {
|
||||
fwriteln();
|
||||
return 0;
|
||||
return luaL_error(L, "Function 'fwriteln' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_freadi(lua_State *L) {
|
||||
lua_pushinteger(L,freadi());
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'freadi' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_freadd(lua_State *L) {
|
||||
lua_pushnumber(L,freadd());
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'freadd' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_freads(lua_State *L) {
|
||||
lua_pushstring(L,freads());
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'freads' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_freadw(lua_State *L) {
|
||||
lua_pushstring(L,freadw());
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'freadw' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_freadb(lua_State *L) {
|
||||
lua_pushboolean(L,freadb());
|
||||
return 1;
|
||||
return luaL_error(L, "Function 'freadb' is DEPRECATED. Use Lua's own io methods instead.");
|
||||
}
|
||||
|
||||
static int cpp_playmusic(lua_State *L) {
|
||||
@@ -826,10 +797,16 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_res(lua_State *L) {
|
||||
if (lua_gettop(L) >= 2) {
|
||||
const int w = luaL_optinteger(L, 1, 160);
|
||||
const int h = luaL_optinteger(L, 2, 120);
|
||||
setres(w, h);
|
||||
return 0;
|
||||
} else {
|
||||
lua_pushinteger(L, scrw());
|
||||
lua_pushinteger(L, scrh());
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
static int cpp_getconf(lua_State *L) {
|
||||
@@ -906,6 +883,8 @@ void push_lua_funcs() {
|
||||
|
||||
lua_pushcfunction(L,cpp_loadpal); lua_setglobal(L, "loadpal");
|
||||
lua_pushcfunction(L,cpp_setpal); lua_setglobal(L, "setpal");
|
||||
lua_pushcfunction(L,cpp_palcolor); lua_setglobal(L, "palcolor");
|
||||
lua_pushcfunction(L,cpp_paltrans); lua_setglobal(L, "paltrans");
|
||||
lua_pushcfunction(L,cpp_setcolor); lua_setglobal(L, "setcolor");
|
||||
lua_pushcfunction(L,cpp_getcolor); lua_setglobal(L, "getcolor");
|
||||
lua_pushcfunction(L,cpp_settrans); lua_setglobal(L, "settrans");
|
||||
@@ -935,6 +914,8 @@ void push_lua_funcs() {
|
||||
lua_pushcfunction(L,cpp_spr); lua_setglobal(L, "spr");
|
||||
lua_pushcfunction(L,cpp_sspr); lua_setglobal(L, "sspr");
|
||||
lua_pushcfunction(L,cpp_spr_r); lua_setglobal(L, "spr_r");
|
||||
lua_pushcfunction(L,cpp_blit); lua_setglobal(L, "blit");
|
||||
lua_pushcfunction(L,cpp_blit_r); lua_setglobal(L, "blit_r");
|
||||
lua_pushcfunction(L,cpp_tline); lua_setglobal(L, "tline");
|
||||
lua_pushcfunction(L,cpp_thline); lua_setglobal(L, "thline");
|
||||
lua_pushcfunction(L,cpp_tvline); lua_setglobal(L, "tvline");
|
||||
@@ -946,6 +927,7 @@ void push_lua_funcs() {
|
||||
lua_pushcfunction(L,cpp_anykey); lua_setglobal(L, "anykey");
|
||||
lua_pushcfunction(L,cpp_pad); lua_setglobal(L, "pad");
|
||||
lua_pushcfunction(L,cpp_padp); lua_setglobal(L, "padp");
|
||||
lua_pushcfunction(L,cpp_mouse); lua_setglobal(L, "mouse");
|
||||
lua_pushcfunction(L,cpp_mousex); lua_setglobal(L, "mousex");
|
||||
lua_pushcfunction(L,cpp_mousey); lua_setglobal(L, "mousey");
|
||||
lua_pushcfunction(L,cpp_mwheel); lua_setglobal(L, "mwheel");
|
||||
@@ -954,6 +936,9 @@ void push_lua_funcs() {
|
||||
|
||||
lua_pushcfunction(L,cpp_time); lua_setglobal(L, "time");
|
||||
lua_pushcfunction(L,cpp_beat); lua_setglobal(L, "beat");
|
||||
|
||||
|
||||
/* [BEGIN DEPRECADES] */
|
||||
lua_pushcfunction(L,cpp_abs); lua_setglobal(L, "abs");
|
||||
lua_pushcfunction(L,cpp_ceil); lua_setglobal(L, "ceil");
|
||||
lua_pushcfunction(L,cpp_flr); lua_setglobal(L, "flr");
|
||||
@@ -965,12 +950,15 @@ void push_lua_funcs() {
|
||||
lua_pushcfunction(L,cpp_max); lua_setglobal(L, "max");
|
||||
lua_pushcfunction(L,cpp_mid); lua_setglobal(L, "mid");
|
||||
lua_pushcfunction(L,cpp_min); lua_setglobal(L, "min");
|
||||
/* [END DEPRECADES] */
|
||||
|
||||
lua_pushcfunction(L,cpp_rnd); lua_setglobal(L, "rnd");
|
||||
lua_pushcfunction(L,cpp_srand); lua_setglobal(L, "srand");
|
||||
lua_pushcfunction(L,cpp_tostr); lua_setglobal(L, "tostr");
|
||||
lua_pushcfunction(L,cpp_ascii); lua_setglobal(L, "ascii");
|
||||
lua_pushcfunction(L,cpp_strlen); lua_setglobal(L, "strlen");
|
||||
|
||||
/* [BEGIN DEPRECADES] */
|
||||
lua_pushcfunction(L,cpp_fopen); lua_setglobal(L, "fopen");
|
||||
lua_pushcfunction(L,cpp_fopenres); lua_setglobal(L, "fopenres");
|
||||
lua_pushcfunction(L,cpp_fclose); lua_setglobal(L, "fclose");
|
||||
@@ -986,6 +974,7 @@ void push_lua_funcs() {
|
||||
lua_pushcfunction(L,cpp_freads); lua_setglobal(L, "freads");
|
||||
lua_pushcfunction(L,cpp_freadw); lua_setglobal(L, "freadw");
|
||||
lua_pushcfunction(L,cpp_freadb); lua_setglobal(L, "freadb");
|
||||
/* [END DEPRECADES] */
|
||||
|
||||
lua_pushcfunction(L,cpp_playmusic); lua_setglobal(L, "playmusic");
|
||||
lua_pushcfunction(L,cpp_pausemusic); lua_setglobal(L, "pausemusic");
|
||||
|
||||
154
mini.cpp
154
mini.cpp
@@ -412,6 +412,8 @@ int main(int argc,char*argv[]){
|
||||
mouse_just_pressed = 0;
|
||||
pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
}
|
||||
SDL_SetRenderDrawColor(mini_ren, 0, 0, 0, 255);
|
||||
SDL_RenderClear(mini_ren);
|
||||
SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch);
|
||||
for (uint32_t i=0;i<screen_surface->size;++i) pixels[i] = palette[screen_surface->p[i]];
|
||||
SDL_UnlockTexture(mini_bak);
|
||||
@@ -877,7 +879,7 @@ void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) {
|
||||
}
|
||||
}
|
||||
|
||||
void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y, bool invert) {
|
||||
void blit(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y, bool invert) {
|
||||
if (dw==0) dw=sw;
|
||||
if (dh==0) dh=sh;
|
||||
float sdx = float(sw)/float(dw);
|
||||
@@ -898,7 +900,7 @@ void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool f
|
||||
}
|
||||
}
|
||||
|
||||
void spr_r(int sx, int sy, int sw, int sh, int x, int y, float a)
|
||||
void blit_r(int sx, int sy, int sw, int sh, int x, int y, float a)
|
||||
{
|
||||
const int x0 = sw>>1;
|
||||
const int y0 = sh>>1;
|
||||
@@ -1103,158 +1105,10 @@ bool beat(int16_t i) {
|
||||
}
|
||||
}
|
||||
|
||||
/*float abs(float x) {
|
||||
return SDL_fabsf(x);
|
||||
}*/
|
||||
|
||||
float flr(float x) {
|
||||
return SDL_floorf(x);
|
||||
}
|
||||
|
||||
float sgn(float x) {
|
||||
return x >= 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
float ceil(float x) {
|
||||
return SDL_ceilf(x);
|
||||
}
|
||||
|
||||
float sin(float x) {
|
||||
return SDL_sinf(x);
|
||||
}
|
||||
|
||||
float cos(float x) {
|
||||
return SDL_cosf(x);
|
||||
}
|
||||
|
||||
float atan2(float dx, float dy) {
|
||||
return SDL_atan2f(dx, dy);
|
||||
}
|
||||
|
||||
float sqrt(float x) {
|
||||
return SDL_sqrtf(x);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
float max(float x, float y) {
|
||||
return SDL_max(x, y);
|
||||
}
|
||||
|
||||
float mid(float x, float y, float z) {
|
||||
return max(x, min(y, z));
|
||||
}
|
||||
|
||||
float min(float x, float y) {
|
||||
return SDL_min(x, y);
|
||||
}
|
||||
|
||||
int utfstrlen(const char *str) {
|
||||
const int size_in_bytes = SDL_strlen(str);
|
||||
int size_in_utfchars = 0;
|
||||
for (int i=0;i<size_in_bytes;++i) if ((unsigned char)str[i] != 194 && (unsigned char)str[i] != 195) size_in_utfchars++;
|
||||
return size_in_utfchars;
|
||||
}
|
||||
|
||||
int rnd(int x) {
|
||||
return rand()%x;
|
||||
}
|
||||
|
||||
/*void srand(int x) {
|
||||
srand(x);
|
||||
}*/
|
||||
|
||||
char tostr_tmp[1024];
|
||||
const char* tostr(int val) {
|
||||
return SDL_itoa(val, tostr_tmp, 10);
|
||||
}
|
||||
|
||||
/*void debug(const char *str) {
|
||||
printf("%s\n",str);
|
||||
}*/
|
||||
|
||||
uint8_t ascii(const char *str, uint8_t index) {
|
||||
return str[index];
|
||||
}
|
||||
|
||||
char fstr[1024];
|
||||
|
||||
void fopen(const char *filename, uint8_t mode) {
|
||||
if (file != NULL) fclose(file);
|
||||
file = fopen(filename, mode==0?"r":"w");
|
||||
}
|
||||
|
||||
void fopenres(const char *filename) {
|
||||
if (file != NULL) fclose(file);
|
||||
int size;
|
||||
file = file_getfilepointer(filename, size);
|
||||
}
|
||||
|
||||
void fclose() {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
bool feof() {
|
||||
return feof(file);
|
||||
}
|
||||
|
||||
void fwritei(int value) {
|
||||
sprintf(fstr, "%i ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwrited(float value) {
|
||||
sprintf(fstr, "%f ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
void fwrites(const char *value) {
|
||||
sprintf(fstr, "\"%s\" ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwritew(const char *value) {
|
||||
sprintf(fstr, "%s ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwriteb(bool value) {
|
||||
sprintf(fstr, value?"true ":"false ");
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwriteln() {
|
||||
fwrite("\n", 1, 1, file);
|
||||
}
|
||||
|
||||
int freadi() {
|
||||
int value;
|
||||
fscanf(file, "%i", &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
float freadd() {
|
||||
float value;
|
||||
fscanf(file, "%f", &value);
|
||||
return value;
|
||||
}
|
||||
const char *freads() {
|
||||
fscanf(file, " \"%[^\"]\"", &fstr[0]);
|
||||
//fscanf(file, "\"%[^\"]\"", &fstr);
|
||||
return fstr;
|
||||
}
|
||||
|
||||
const char *freadw() {
|
||||
fscanf(file, "%s", &fstr[0]);
|
||||
return fstr;
|
||||
}
|
||||
|
||||
bool freadb() {
|
||||
fscanf(file, "%s", &fstr[0]);
|
||||
return strcmp(fstr, "true")==0?true:false;
|
||||
}
|
||||
|
||||
void playmusic(const char *filename, const int loop) {
|
||||
int size;
|
||||
char *buffer = file_getfilebuffer(filename, size);
|
||||
|
||||
47
mini.h
47
mini.h
@@ -188,8 +188,8 @@ void sset(int x, int y);
|
||||
void sset(int x, int y, uint8_t color);
|
||||
|
||||
void spr(uint8_t n, int x, int y, float w = 1.0f, float h = 1.0f, bool flip_x = false, bool flip_y = false);
|
||||
void sspr(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 spr_r(int sx, int sy, int sw, int sh, int x, int y, float a);
|
||||
void blit(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 blit_r(int sx, int sy, int sw, int sh, int x, int y, float a);
|
||||
|
||||
void tline(int x0, int y0, int x1, int y1, 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);
|
||||
@@ -221,53 +221,10 @@ bool mbtnp(uint8_t i);
|
||||
float time();
|
||||
bool beat(int16_t i);
|
||||
|
||||
//float abs(float x);
|
||||
|
||||
float flr(float x);
|
||||
float sgn(float x);
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
float ceil(float x);
|
||||
float sin(float x);
|
||||
float cos(float x);
|
||||
float atan2(float dx, float dy);
|
||||
float sqrt(float x);
|
||||
#endif
|
||||
|
||||
float max(float x, float y);
|
||||
float mid(float x, float y, float z);
|
||||
float min(float x, float y);
|
||||
|
||||
int utfstrlen(const char *str);
|
||||
|
||||
int rnd(int x);
|
||||
//void srand(int x);
|
||||
|
||||
const char* tostr(int val);
|
||||
|
||||
//void debug(const char *str);
|
||||
#define debug printf
|
||||
|
||||
uint8_t ascii(const char *str, uint8_t index);
|
||||
|
||||
void fopen(const char *filename, uint8_t mode=0);
|
||||
void fopenres(const char *filename);
|
||||
void fclose();
|
||||
bool feof();
|
||||
|
||||
void fwritei(int value);
|
||||
void fwrited(float value);
|
||||
void fwrites(const char *value);
|
||||
void fwritew(const char *value);
|
||||
void fwriteb(bool value);
|
||||
void fwriteln();
|
||||
|
||||
int freadi();
|
||||
float freadd();
|
||||
const char *freads();
|
||||
const char *freadw();
|
||||
bool freadb();
|
||||
|
||||
void playmusic(const char *filename, const int loop=-1);
|
||||
void pausemusic();
|
||||
void resumemusic();
|
||||
|
||||
Reference in New Issue
Block a user