diff --git a/source/jshader.cpp b/source/jshader.cpp index 0a1a41d..7e33005 100644 --- a/source/jshader.cpp +++ b/source/jshader.cpp @@ -16,238 +16,241 @@ #include #endif -namespace shader +namespace mini { - SDL_Window *win = nullptr; - SDL_Renderer *renderer = nullptr; - GLuint programId = 0; - SDL_Texture* backBuffer = nullptr; - SDL_Point win_size = {640, 480}; - SDL_FPoint tex_size = {320, 240}; - bool can_use_opengl = false; - bool using_opengl = false; - GLuint texture_number; - GLuint nose; - - #ifndef __APPLE__ - - // I'm avoiding the use of GLEW or some extensions handler, but that - // doesn't mean you should... - PFNGLCREATESHADERPROC glCreateShader; - PFNGLSHADERSOURCEPROC glShaderSource; - PFNGLCOMPILESHADERPROC glCompileShader; - PFNGLGETSHADERIVPROC glGetShaderiv; - PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; - PFNGLDELETESHADERPROC glDeleteShader; - PFNGLATTACHSHADERPROC glAttachShader; - PFNGLCREATEPROGRAMPROC glCreateProgram; - PFNGLDELETEPROGRAMPROC glDeleteProgram; - PFNGLLINKPROGRAMPROC glLinkProgram; - PFNGLVALIDATEPROGRAMPROC glValidateProgram; - PFNGLGETPROGRAMIVPROC glGetProgramiv; - PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; - PFNGLUSEPROGRAMPROC glUseProgram; - PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; - PFNGLACTIVETEXTUREPROC glActiveTexture; - - - bool initGLExtensions() { - glCreateShader = (PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader"); - glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource"); - glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader"); - glGetShaderiv = (PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv"); - glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)SDL_GL_GetProcAddress("glGetShaderInfoLog"); - glDeleteShader = (PFNGLDELETESHADERPROC)SDL_GL_GetProcAddress("glDeleteShader"); - glAttachShader = (PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader"); - glCreateProgram = (PFNGLCREATEPROGRAMPROC)SDL_GL_GetProcAddress("glCreateProgram"); - glDeleteProgram = (PFNGLDELETEPROGRAMPROC)SDL_GL_GetProcAddress("glDeleteProgram"); - glLinkProgram = (PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram"); - glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)SDL_GL_GetProcAddress("glValidateProgram"); - glGetProgramiv = (PFNGLGETPROGRAMIVPROC)SDL_GL_GetProcAddress("glGetProgramiv"); - glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)SDL_GL_GetProcAddress("glGetProgramInfoLog"); - glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram"); - glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)SDL_GL_GetProcAddress("glGetUniformLocation"); - glActiveTexture = (PFNGLACTIVETEXTUREPROC)SDL_GL_GetProcAddress("glActiveTexture"); - - return glCreateShader && glShaderSource && glCompileShader && glGetShaderiv && - glGetShaderInfoLog && glDeleteShader && glAttachShader && glCreateProgram && - glDeleteProgram && glLinkProgram && glValidateProgram && glGetProgramiv && - glGetProgramInfoLog && glUseProgram && glGetUniformLocation; - } - - #endif - - GLuint compileShader(const char* source, GLuint shaderType) { - // Create ID for shader - GLuint result = glCreateShader(shaderType); - // Add define depending on shader type - const char *sources[2] = { shaderType==GL_VERTEX_SHADER?"#define VERTEX\n":"#define FRAGMENT\n", source }; - // Define shader text - glShaderSource(result, 2, sources, NULL); - // Compile shader - glCompileShader(result); - - //Check vertex shader for errors - GLint shaderCompiled = GL_FALSE; - glGetShaderiv( result, GL_COMPILE_STATUS, &shaderCompiled ); - if (shaderCompiled != GL_TRUE) - { - std::cout << "Error en la compilación: " << result << "!" << std::endl; - GLint logLength; - glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength); - if (logLength > 0) - { - GLchar *log = (GLchar*)malloc(logLength); - glGetShaderInfoLog(result, logLength, &logLength, log); - std::cout << "Shader compile log:" << log << std::endl; - //std::cout << source << std::endl; - free(log); - } - glDeleteShader(result); - result = 0; - } - return result; - } - - GLuint compileProgram(const char* vertexShaderSource, const char* fragmentShaderSource) + namespace shader { + SDL_Window *win = nullptr; + SDL_Renderer *renderer = nullptr; GLuint programId = 0; - GLuint vtxShaderId, fragShaderId; + SDL_Texture* backBuffer = nullptr; + SDL_Point win_size = {640, 480}; + SDL_FPoint tex_size = {320, 240}; + bool can_use_opengl = false; + bool using_opengl = false; + GLuint texture_number; + GLuint nose; - if (programId != 0) glDeleteProgram(programId); - programId = glCreateProgram(); - + #ifndef __APPLE__ - vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER); - fragShaderId = compileShader(fragmentShaderSource?fragmentShaderSource:vertexShaderSource, GL_FRAGMENT_SHADER); + // I'm avoiding the use of GLEW or some extensions handler, but that + // doesn't mean you should... + PFNGLCREATESHADERPROC glCreateShader; + PFNGLSHADERSOURCEPROC glShaderSource; + PFNGLCOMPILESHADERPROC glCompileShader; + PFNGLGETSHADERIVPROC glGetShaderiv; + PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; + PFNGLDELETESHADERPROC glDeleteShader; + PFNGLATTACHSHADERPROC glAttachShader; + PFNGLCREATEPROGRAMPROC glCreateProgram; + PFNGLDELETEPROGRAMPROC glDeleteProgram; + PFNGLLINKPROGRAMPROC glLinkProgram; + PFNGLVALIDATEPROGRAMPROC glValidateProgram; + PFNGLGETPROGRAMIVPROC glGetProgramiv; + PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; + PFNGLUSEPROGRAMPROC glUseProgram; + PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; + PFNGLACTIVETEXTUREPROC glActiveTexture; - if(vtxShaderId && fragShaderId) - { - // Associate shader with program - glAttachShader(programId, vtxShaderId); - glAttachShader(programId, fragShaderId); - glLinkProgram(programId); - glValidateProgram(programId); - // Check the status of the compile/link - GLint logLen; - glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen); - if (logLen > 0) + bool initGLExtensions() { + glCreateShader = (PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader"); + glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource"); + glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader"); + glGetShaderiv = (PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv"); + glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)SDL_GL_GetProcAddress("glGetShaderInfoLog"); + glDeleteShader = (PFNGLDELETESHADERPROC)SDL_GL_GetProcAddress("glDeleteShader"); + glAttachShader = (PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader"); + glCreateProgram = (PFNGLCREATEPROGRAMPROC)SDL_GL_GetProcAddress("glCreateProgram"); + glDeleteProgram = (PFNGLDELETEPROGRAMPROC)SDL_GL_GetProcAddress("glDeleteProgram"); + glLinkProgram = (PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram"); + glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)SDL_GL_GetProcAddress("glValidateProgram"); + glGetProgramiv = (PFNGLGETPROGRAMIVPROC)SDL_GL_GetProcAddress("glGetProgramiv"); + glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)SDL_GL_GetProcAddress("glGetProgramInfoLog"); + glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram"); + glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)SDL_GL_GetProcAddress("glGetUniformLocation"); + glActiveTexture = (PFNGLACTIVETEXTUREPROC)SDL_GL_GetProcAddress("glActiveTexture"); + + return glCreateShader && glShaderSource && glCompileShader && glGetShaderiv && + glGetShaderInfoLog && glDeleteShader && glAttachShader && glCreateProgram && + glDeleteProgram && glLinkProgram && glValidateProgram && glGetProgramiv && + glGetProgramInfoLog && glUseProgram && glGetUniformLocation; + } + + #endif + + GLuint compileShader(const char* source, GLuint shaderType) { + // Create ID for shader + GLuint result = glCreateShader(shaderType); + // Add define depending on shader type + const char *sources[2] = { shaderType==GL_VERTEX_SHADER?"#define VERTEX\n":"#define FRAGMENT\n", source }; + // Define shader text + glShaderSource(result, 2, sources, NULL); + // Compile shader + glCompileShader(result); + + //Check vertex shader for errors + GLint shaderCompiled = GL_FALSE; + glGetShaderiv( result, GL_COMPILE_STATUS, &shaderCompiled ); + if (shaderCompiled != GL_TRUE) { - char* log = (char*) malloc(logLen * sizeof(char)); - // Show any errors as appropriate - glGetProgramInfoLog(programId, logLen, &logLen, log); - std::cout << "Prog Info Log: " << std::endl << log << std::endl; - free(log); + std::cout << "Error en la compilación: " << result << "!" << std::endl; + GLint logLength; + glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) + { + GLchar *log = (GLchar*)malloc(logLength); + glGetShaderInfoLog(result, logLength, &logLength, log); + std::cout << "Shader compile log:" << log << std::endl; + //std::cout << source << std::endl; + free(log); + } + glDeleteShader(result); + result = 0; } + return result; } - if (vtxShaderId) glDeleteShader(vtxShaderId); - if (fragShaderId) glDeleteShader(fragShaderId); - return programId; - } - const bool init(SDL_Window* win, SDL_Texture* backBuffer, const char* vertexShader, const char* fragmentShader) - { - shader::win = win; - shader::renderer = SDL_GetRenderer(win); - shader::backBuffer = backBuffer; - SDL_GetWindowSize(win, &win_size.x, &win_size.y); - SDL_GetTextureSize(backBuffer, &tex_size.x, &tex_size.y); - //printf("tex size: %fx%f\n", tex_size.x, tex_size.y); - SDL_PropertiesID props = SDL_GetTextureProperties(backBuffer); - texture_number = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER, -1); - //printf("texture number: %i\n", texture_number); - int access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, -1); - nose = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER, -1); - //printf("texture target number: %i\n", nose); - - if (access != SDL_TEXTUREACCESS_TARGET) + GLuint compileProgram(const char* vertexShaderSource, const char* fragmentShaderSource) { - std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl; - exit(1); + GLuint programId = 0; + GLuint vtxShaderId, fragShaderId; + + if (programId != 0) glDeleteProgram(programId); + programId = glCreateProgram(); + + + vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER); + fragShaderId = compileShader(fragmentShaderSource?fragmentShaderSource:vertexShaderSource, GL_FRAGMENT_SHADER); + + if(vtxShaderId && fragShaderId) + { + // Associate shader with program + glAttachShader(programId, vtxShaderId); + glAttachShader(programId, fragShaderId); + glLinkProgram(programId); + glValidateProgram(programId); + + // Check the status of the compile/link + GLint logLen; + glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen); + if (logLen > 0) + { + char* log = (char*) malloc(logLen * sizeof(char)); + // Show any errors as appropriate + glGetProgramInfoLog(programId, logLen, &logLen, log); + std::cout << "Prog Info Log: " << std::endl << log << std::endl; + free(log); + } + } + if (vtxShaderId) glDeleteShader(vtxShaderId); + if (fragShaderId) glDeleteShader(fragShaderId); + return programId; } - const char * renderer_name = SDL_GetRendererName(renderer); - //printf("rendererInfo.name: %s\n", renderer_name); + const bool init(SDL_Window* win, SDL_Texture* backBuffer, const char* vertexShader, const char* fragmentShader) + { + shader::win = win; + shader::renderer = SDL_GetRenderer(win); + shader::backBuffer = backBuffer; + SDL_GetWindowSize(win, &win_size.x, &win_size.y); + SDL_GetTextureSize(backBuffer, &tex_size.x, &tex_size.y); + //printf("tex size: %fx%f\n", tex_size.x, tex_size.y); + SDL_PropertiesID props = SDL_GetTextureProperties(backBuffer); + texture_number = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER, -1); + //printf("texture number: %i\n", texture_number); + int access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, -1); + nose = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER, -1); + //printf("texture target number: %i\n", nose); - if(!strncmp(renderer_name, "opengl", 6)) { -#ifndef __APPLE__ - static bool gl_extensions_initialized = false; - if (!gl_extensions_initialized) { - if (!initGLExtensions()) { - std::cout << "WARNING: No s'han pogut inicialitzar les extensions d'OpenGL!" << std::endl; + if (access != SDL_TEXTUREACCESS_TARGET) + { + std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl; + exit(1); + } + + const char * renderer_name = SDL_GetRendererName(renderer); + //printf("rendererInfo.name: %s\n", renderer_name); + + if(!strncmp(renderer_name, "opengl", 6)) { + #ifndef __APPLE__ + static bool gl_extensions_initialized = false; + if (!gl_extensions_initialized) { + if (!initGLExtensions()) { + std::cout << "WARNING: No s'han pogut inicialitzar les extensions d'OpenGL!" << std::endl; + can_use_opengl = false; + return false; + } + gl_extensions_initialized = true; + } + #endif + // Compilar el shader y dejarlo listo para usar. + if (!vertexShader) { can_use_opengl = false; return false; } - gl_extensions_initialized = true; - } -#endif - // Compilar el shader y dejarlo listo para usar. - if (!vertexShader) { + programId = compileProgram(vertexShader, fragmentShader); + } else { + std::cout << "WARNING: El driver del renderer no es OpenGL." << std::endl; can_use_opengl = false; return false; } - programId = compileProgram(vertexShader, fragmentShader); - } else { - std::cout << "WARNING: El driver del renderer no es OpenGL." << std::endl; - can_use_opengl = false; - return false; + can_use_opengl = true; + return true; } - can_use_opengl = true; - return true; - } - unsigned char pixels[512*240*4]; + unsigned char pixels[512*240*4]; - void enable() { if (can_use_opengl) using_opengl = true; } - void disable() { using_opengl = false; } + void enable() { if (can_use_opengl) using_opengl = true; } + void disable() { using_opengl = false; } - void render() - { - SDL_FlushRenderer(renderer); - SDL_SetRenderTarget(renderer, NULL); - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); - SDL_RenderClear(renderer); - SDL_FlushRenderer(renderer); - - if (using_opengl) + void render() { - GLint oldProgramId; - if (programId != 0) + SDL_FlushRenderer(renderer); + SDL_SetRenderTarget(renderer, NULL); + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); + SDL_FlushRenderer(renderer); + + if (using_opengl) { - glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId); - glUseProgram(programId); + GLint oldProgramId; + if (programId != 0) + { + glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId); + glUseProgram(programId); + } + + glEnable(GL_TEXTURE_2D); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, 1); + //glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels); + //if (glGetError()) { printf("GLGETERROR!\n"); exit(1);} + //GLint param; + //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, ¶m); + //printf("tex width: %i\n", param); + glViewport(0, 0, win_size.x, win_size.y); + + glBegin(GL_TRIANGLE_STRIP); + glTexCoord2f(0.0f, 0.0f); + glVertex2f(-1.0f, -1.0f); + glTexCoord2f(tex_size.x, 0.0f); + glVertex2f(1.0f, -1.0f); + glTexCoord2f(0.0f, tex_size.y); + glVertex2f(-1.0f, 1.0f); + glTexCoord2f(tex_size.x, tex_size.y); + glVertex2f(1.0f, 1.0f); + glEnd(); + + SDL_GL_SwapWindow(win); + + if (programId != 0) glUseProgram(oldProgramId); + + } else { + SDL_RenderTexture(renderer, backBuffer, NULL, NULL); + SDL_RenderPresent(renderer); } - - glEnable(GL_TEXTURE_2D); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, 1); - //glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels); - //if (glGetError()) { printf("GLGETERROR!\n"); exit(1);} - //GLint param; - //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, ¶m); - //printf("tex width: %i\n", param); - glViewport(0, 0, win_size.x, win_size.y); - - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(0.0f, 0.0f); - glVertex2f(-1.0f, -1.0f); - glTexCoord2f(tex_size.x, 0.0f); - glVertex2f(1.0f, -1.0f); - glTexCoord2f(0.0f, tex_size.y); - glVertex2f(-1.0f, 1.0f); - glTexCoord2f(tex_size.x, tex_size.y); - glVertex2f(1.0f, 1.0f); - glEnd(); - - SDL_GL_SwapWindow(win); - - if (programId != 0) glUseProgram(oldProgramId); - - } else { - SDL_RenderTexture(renderer, backBuffer, NULL, NULL); - SDL_RenderPresent(renderer); + if (glGetError()) { printf("GLERROR!\n"); exit(1); } } - if (glGetError()) { printf("GLERROR!\n"); exit(1); } } -} +} \ No newline at end of file diff --git a/source/jshader.h b/source/jshader.h index f0f6a03..12f600d 100644 --- a/source/jshader.h +++ b/source/jshader.h @@ -35,14 +35,17 @@ // Ah! una cosa mes: al compilar, en Linux afegir "-lGL", en Windows afegir "-lopengl32". // En Mac ni idea -namespace shader +namespace mini { - const bool init(SDL_Window* win, SDL_Texture* backBuffer, - const char* vertexShader, const char* fragmentShader=nullptr); + namespace shader + { + const bool init(SDL_Window* win, SDL_Texture* backBuffer, + const char* vertexShader, const char* fragmentShader=nullptr); - - void enable(); - void disable(); + + //void enable(); + //void disable(); - void render(); + void render(); + } } diff --git a/source/lua.cpp b/source/lua.cpp index 245c4ff..5507d0e 100644 --- a/source/lua.cpp +++ b/source/lua.cpp @@ -37,7 +37,7 @@ namespace mini static int create(lua_State *L) { int w = luaL_checknumber(L, 1); int h = luaL_checknumber(L, 2); - uint8_t s = newsurf(w, h); + uint8_t s = mini::surf::create(w, h); if (s==255) { luaL_error(L, "Error while creating new surface: Max surfaces reached"); return 0; @@ -46,954 +46,945 @@ namespace mini return 1; } + static int load(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + uint8_t s = mini::surf::load(str); + if (s==255) { + luaL_error(L, "Error while loading surface: Max surfaces reached"); + return 0; + } + lua_pushinteger(L, s); + return 1; + } + + static int loadex(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + uint8_t s = mini::surf::load(str, true); + if (s==255) { + luaL_error(L, "Error while loading surface: Max surfaces reached"); + return 0; + } + lua_pushinteger(L, s); + return 1; + } + + static int save(lua_State *L) { + uint8_t surface = luaL_checkinteger(L, 1); + const char* str = luaL_checkstring(L, 2); + + if (lua_istable(L, -1)) { + const int len = SDL_min(256, lua_rawlen(L, -1)); + uint8_t *pal = (uint8_t*)malloc(len*3); + uint8_t *p=pal; + for (int i=1;i<=len;++i) { + lua_rawgeti(L, -1, i); + lua_getfield(L, -1, "r"); + *(p++) = luaL_checknumber(L, -1); + lua_pop(L, 1); + lua_getfield(L, -1, "g"); + *(p++) = luaL_checknumber(L, -1); + lua_pop(L, 1); + lua_getfield(L, -1, "b"); + *(p++) = luaL_checknumber(L, -1); + lua_pop(L, 1); + lua_pop(L, 1); + //pal[i-1] = (r<<16)+(g<<8)+b; + } + mini::surf::save(surface, str, pal, len); + } else { + mini::surf::save(surface, str, nullptr); + } + + return 0; + } + + static int free(lua_State *L) { + uint8_t surface = luaL_checkinteger(L, 1); + mini::surf::destroy(surface); + return 0; + } + + static int size(lua_State *L) { + uint8_t surface = luaL_checkinteger(L, 1); + lua_pushinteger(L, mini::surf::width(surface)); + lua_pushinteger(L, mini::surf::height(surface)); + return 2; + } + + static int target(lua_State *L) { + const int numargs = lua_gettop(L); + switch (numargs) { + case 0: { + lua_pushinteger(L, mini::surf::target::get()); + return 1; + } + case 1: { + uint8_t surface = luaL_checkinteger(L, 1); + mini::surf::target::set(surface); + return 0; + } + default: + return luaL_error(L, "Function 'surface.target' Unexpected number of parameters."); + }; + } + + static int source(lua_State *L) { + const int numargs = lua_gettop(L); + switch (numargs) { + case 0: { + lua_pushinteger(L, mini::surf::source::get()); + return 1; + } + case 1: { + uint8_t surface = luaL_checkinteger(L, 1); + mini::surf::source::set(surface); + return 0; + } + default: + return luaL_error(L, "Function 'surface.source' Unexpected number of parameters."); + }; + } + + static int cls(lua_State *L) { + uint8_t color = luaL_optinteger(L, 1, 0); + mini::surf::cls(color); + 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 + { + static int surf(lua_State *L) { + if (lua_gettop(L)==1) { + uint8_t surface = luaL_checkinteger(L, 1); + mini::map::surf::set(surface); + } else { + lua_pushinteger(L, mini::map::surf::get()); + return 1; + } + + return 0; + } + + static int draw(lua_State *L) { + mini::map::draw(); + return 0; + } + + static int tile(lua_State *L) { + if (lua_gettop(L)==2) { + int celx = luaL_checknumber(L, 1); + int cely = luaL_checknumber(L, 2); + lua_pushinteger(L, mini::map::tile::get(celx, cely)); + return 1; + } else { + int celx = luaL_checknumber(L, 1); + int cely = luaL_checknumber(L, 2); + uint8_t snum = luaL_checkinteger(L, 3); + mini::map::tile::set(celx, cely, snum); + return 0; + } + } + + static int cell(lua_State *L) { + if (lua_gettop(L)==2) { + int celx = luaL_checknumber(L, 1); + int cely = luaL_checknumber(L, 2); + mini::map::cell::set(celx, cely); + return 0; + } else { + lua_pushinteger(L, mini::map::cell::getw()); + lua_pushinteger(L, mini::map::cell::geth()); + return 2; + } + } + + } + + namespace pal + { + static int load(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + uint16_t size; + uint32_t *pal = mini::pal::load(str, &size); + lua_createtable(L, 2, 0); + for (int i=0;i>16)&0xff); + lua_setfield(L, -2, "r"); + + lua_pushinteger(L, (color>>8)&0xff); + lua_setfield(L, -2, "g"); + + lua_pushinteger(L, color&0xff); + lua_setfield(L, -2, "b"); + + lua_rawseti(L, -2, i+1); + } + free(pal); + return 1; + } + + static int set(lua_State *L) { + int r,g,b; + if (lua_istable(L, -1)) { + uint32_t pal[256]; + const int len = SDL_min(256, lua_rawlen(L, -1)); + for (int i=0;i>16)&0xff); + lua_pushinteger(L, (color>>8)&0xff); + lua_pushinteger(L, color&0xff); + return 3; + } else { + uint8_t index = luaL_checkinteger(L, 1); + uint8_t r = luaL_checkinteger(L, 2); + uint8_t g = luaL_optinteger(L, 3, 0); + uint8_t b = luaL_optinteger(L, 4, 0); + uint32_t color = (r<<16) + (g<<8) + b; + mini::pal::color::set(index, color); + return 0; + } + } + + static int trans(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushinteger(L, mini::pal::trans::get()); + return 1; + } else { + uint8_t index = luaL_checkinteger(L, 1); + mini::pal::trans::set(index); + return 0; + } + } + + static int subpal(lua_State *L) { + const int num_params = lua_gettop(L); + uint8_t index, index2, color; + switch (num_params) { + case 0: + mini::pal::subpal::reset(); + break; + case 1: + index = luaL_checkinteger(L, 1); + lua_pushinteger(L, mini::pal::subpal::set(index,index)); + return 1; + break; + case 2: + index = luaL_checkinteger(L, 1); + color = luaL_checkinteger(L, 2); + lua_pushinteger(L, mini::pal::subpal::set(index, color)); + return 1; + break; + case 3: + index = luaL_checkinteger(L, 1); + index2 = luaL_checkinteger(L, 2); + color = luaL_checkinteger(L, 3); + for (int i=index;i<=index2;++i) mini::pal::subpal::set(i, color); + break; + } + return 0; + } + } + + namespace view + { + static int clip(lua_State *L) { + if (lua_gettop(L)==0) { + mini::view::clip::reset(); + return 0; + } 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); + mini::view::clip::set(x, y, w, h); + return 0; + } + } + + static int origin(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushinteger(L, mini::view::origin::getx()); + lua_pushinteger(L, mini::view::origin::gety()); + return 2; + } else { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + mini::view::origin::set(x, y); + return 0; + } + } + + static int tolocal(lua_State *L) { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + lua_pushinteger(L, x+mini::view::origin::getx()); + lua_pushinteger(L, y+mini::view::origin::gety()); + return 2; + } + } + + namespace draw + { + static int line(lua_State *L) { + int x0 = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + int y1 = luaL_checknumber(L, 4); + uint8_t color = luaL_checkinteger(L, 5); + mini::draw::line(x0, y0, x1, y1, color); + return 0; + } + + static int hline(lua_State *L) { + int x0 = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + uint8_t color = luaL_checkinteger(L, 4); + mini::draw::hline(x0, y, x1, color); + return 0; + } + + static int vline(lua_State *L) { + int x = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int y1 = luaL_checknumber(L, 3); + uint8_t color = luaL_checkinteger(L, 4); + mini::draw::vline(x, y0, y1, color); + return 0; + } + + static int rect(lua_State *L) { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int w = luaL_checknumber(L, 3); + int h = luaL_checknumber(L, 4); + uint8_t color = luaL_checkinteger(L, 5); + mini::draw::rect(x, y, w, h, color); + return 0; + } + + static int rectf(lua_State *L) { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int w = luaL_checknumber(L, 3); + int h = luaL_checknumber(L, 4); + uint8_t color = luaL_checkinteger(L, 5); + mini::draw::rectf(x, y, w, h, color); + return 0; + } + + static int circ(lua_State *L) { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int r = luaL_optnumber(L, 3, 4); + uint8_t color = luaL_checkinteger(L, 4); + mini::draw::circ(x, y, r, color); + return 0; + } + + static int circf(lua_State *L) { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int r = luaL_optnumber(L, 3, 4); + uint8_t color = luaL_checkinteger(L, 4); + mini::draw::circf(x, y, r, color); + return 0; + } + + static int roundrect(lua_State *L) { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int w = luaL_checknumber(L, 3); + int h = luaL_checknumber(L, 4); + int r = luaL_optnumber(L, 5, 4); + uint8_t color = luaL_checkinteger(L, 6); + mini::draw::roundrect(x, y, w, h, r, color); + return 0; + } + + static int roundrectf(lua_State *L) { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int w = luaL_checknumber(L, 3); + int h = luaL_checknumber(L, 4); + int r = luaL_optnumber(L, 5, 4); + uint8_t color = luaL_checkinteger(L, 6); + mini::draw::roundrectf(x, y, w, h, r, color); + return 0; + } + + static int oval(lua_State *L) { + int x0 = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + int y1 = luaL_checknumber(L, 4); + uint8_t color = luaL_checkinteger(L, 5); + mini::draw::oval(x0, y0, x1, y1, color); + return 0; + } + + static int ovalf(lua_State *L) { + int x0 = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + int y1 = luaL_checknumber(L, 4); + uint8_t color = luaL_checkinteger(L, 5); + mini::draw::ovalf(x0, y0, x1, y1, color); + return 0; + } + + static int pattern(lua_State *L) { + if (lua_gettop(L) == 0) { + mini::draw::pattern::set(0xffff); + } else { + uint16_t pat = luaL_checkinteger(L, 1); + bool transparent = lua_toboolean(L, 2); + mini::draw::pattern::set(pat, transparent); + } + return 0; + } + + static int surf(lua_State *L) { + int sx = luaL_checknumber(L, 1); + int sy = luaL_checknumber(L, 2); + int sw = luaL_checknumber(L, 3); + int sh = luaL_checknumber(L, 4); + int dx = luaL_checknumber(L, 5); + int dy = luaL_checknumber(L, 6); + int dw = luaL_optnumber(L, 7, 0); + int dh = luaL_optnumber(L, 8, 0); + bool flip_x = lua_toboolean(L, 9); + bool flip_y = lua_toboolean(L, 10); + bool invert = lua_toboolean(L, 11); + mini::draw::surf(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, invert); + return 0; + } + + static int surfrot(lua_State *L) { + int sx = luaL_checknumber(L, 1); + int sy = luaL_checknumber(L, 2); + int sw = luaL_checknumber(L, 3); + int sh = luaL_checknumber(L, 4); + int dx = luaL_checknumber(L, 5); + int dy = luaL_checknumber(L, 6); + float a = luaL_checknumber(L, 7); + int dw = luaL_optnumber(L, 8, 0); + int dh = luaL_optnumber(L, 9, 0); + bool flip_x = lua_toboolean(L, 10); + bool flip_y = lua_toboolean(L, 11); + mini::draw::surfrot(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, a); + return 0; + } + + static int text(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + int x = luaL_checknumber(L, 2); + int y = luaL_checknumber(L, 3); + uint8_t color = luaL_checkinteger(L, 4); + mini::draw::text(str, x, y, color); + return 0; + } + + static int mode(lua_State *L) { + int mode = luaL_checknumber(L, 1); + mini::draw::mode::set(mode); + return 0; + } + } + + namespace shader + { + static int init(lua_State *L) { + const char* vstr = luaL_optstring(L, 1, NULL); + const char* fstr = luaL_optstring(L, 2, NULL); + mini::shader::init(vstr, fstr); + return 0; + } + + static int enable(lua_State *L) { + mini::shader::enable(); + return 0; + } + + static int disable(lua_State *L) { + mini::shader::disable(); + return 0; + } + } + + namespace music + { + static int play(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + const int loop = luaL_optinteger(L, 2, -1); + mini::audio::music::play(str, loop); + return 0; + } + + static int pause(lua_State *L) { + mini::audio::music::pause(); + return 0; + } + + static int resume(lua_State *L) { + mini::audio::music::resume(); + return 0; + } + + static int stop(lua_State *L) { + const int time = luaL_optinteger(L, 1, 1000); + mini::audio::music::stop(time); + return 0; + } + + static int pos(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushnumber(L, mini::audio::music::pos::get()); + return 1; + } else { + mini::audio::music::pos::set(luaL_checknumber(L, 1)); + return 0; + } + } + + static int enable(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushboolean(L, mini::audio::music::enable::get()); + return 1; + } else { + mini::audio::music::enable::set(lua_toboolean(L, 1)); + return 0; + } + } + } + + namespace sound + { + static int load(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + lua_pushinteger(L, mini::audio::sound::load(str)); + return 1; + } + + static int free(lua_State *L) { + const int sound = luaL_checknumber(L, 1); + mini::audio::sound::free(sound); + return 0; + } + + static int play(lua_State *L) { + const int sound = luaL_checknumber(L, 1); + const int volume = luaL_optinteger(L, 2, -1); + lua_pushinteger(L, mini::audio::sound::play(sound, volume)); + return 1; + } + + static int stop(lua_State *L) { + const int sound = luaL_checknumber(L, 1); + mini::audio::sound::stop(sound); + return 0; + } + + static int enable(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushboolean(L, mini::audio::sound::enable::get()); + return 1; + } else { + mini::audio::sound::enable::set(lua_toboolean(L, 1)); + return 0; + } + } + } + + namespace sys + { + static int delta(lua_State *L) { + lua_pushnumber(L, mini::sys::delta()); + return 1; + } + + static int time(lua_State *L) { + lua_pushnumber(L, mini::sys::time()); + return 1; + } + + static uint32_t chrono_time = 0; + static int chrono(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushnumber(L, float(SDL_GetTicks()-chrono_time)/1000.0f); + return 1; + } else { + chrono_time = SDL_GetTicks(); + return 0; + } + } + + static int beat(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushboolean(L, mini::sys::beat(-1)); + return 1; + } else { + int16_t beats = luaL_optnumber(L, 1, -1); + mini::sys::beat(beats); + return 0; + } + } + + static int update(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushinteger(L, mini::sys::update::get()); + return 1; + } else { + int mode = luaL_checknumber(L, 1); + int interval = luaL_optinteger(L, 2, 0); + mini::sys::update::set(mode, interval); + return 0; + } + } + + namespace fs = std::filesystem; + static int dir(lua_State *L) { + std::string path = "./data"; + if (lua_gettop(L) > 0) path = luaL_checkstring(L, 1); + + // Collect entries + std::vector entries; + for (const auto& entry : fs::directory_iterator(path)) { + entries.push_back(entry); + } + + // Sort: directories first, then files; both alphabetically + std::sort(entries.begin(), entries.end(), + [](const fs::directory_entry& a, const fs::directory_entry& b) { + bool adir = a.is_directory(); + bool bdir = b.is_directory(); + if (adir != bdir) return adir > bdir; // directories before files + return a.path().filename().string() < b.path().filename().string(); + }); + + // Build Lua table + lua_newtable(L); + int i = 1; + for (const auto& entry : entries) { + lua_newtable(L); + + // name field (canonical absolute path) + lua_pushstring(L, (const char*)fs::canonical(entry.path()).u8string().c_str()); + lua_setfield(L, -2, "name"); + + // dir field + lua_pushboolean(L, entry.is_directory()); + lua_setfield(L, -2, "dir"); + + lua_rawseti(L, -2, i++); + } + + return 1; + } + + static int exit(lua_State *L) { + mini::sys::exit(); + return 0; + } + + static int fps(lua_State *L) { + lua_pushnumber(L, mini::sys::getfps()); + return 1; + } + + static int debug(lua_State *L) { + #ifdef DEBUG + lua_pushboolean(L, true); + #else + lua_pushboolean(L, false); + #endif + return 1; + } + + static int clipboard(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushstring(L, SDL_GetClipboardText()); + return 1; + } else { + const char* value = luaL_checkstring(L, 1); + SDL_SetClipboardText(value); + return 0; + } + } + + static int version(lua_State *L) { + lua_pushstring(L, MINI_VERSION); + return 1; + } + } + + namespace win + { + static int zoom(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushinteger(L, mini::win::zoom::get()); + return 1; + } else { + const int value = luaL_optinteger(L, 1, 0); + mini::win::zoom::set(value); + return 0; + } + } + + static int fullscreen(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushboolean(L, mini::win::fullscreen::get()); + return 1; + } else { + mini::win::fullscreen::set(lua_toboolean(L, 1)); + return 0; + } + } + + static int cursor(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushboolean(L, mini::win::cursor::get()); + return 1; + } else { + mini::win::cursor::set(lua_toboolean(L, 1)); + return 0; + } + } + + static int res(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushinteger(L, mini::win::res::getw()); + lua_pushinteger(L, mini::win::res::geth()); + return 2; + } else { + const int w = luaL_optinteger(L, 1, 160); + const int h = luaL_optinteger(L, 2, 120); + mini::win::res::set(w, h); + return 0; + } + } + } + + namespace conf + { + static int key(lua_State *L) { + const char* key = luaL_checkstring(L, 1); + if (lua_gettop(L) > 1) { + const char* value = luaL_checkstring(L, 2); + mini::config::key::set(key, value); + return 0; + } else { + const char* value = mini::config::key::get(key); + if (value==NULL) { + lua_pushnil(L); + } else { + lua_pushstring(L, value); + } + return 1; + } + } + + static int folder(lua_State *L) { + lua_pushstring(L, mini::config::folder()); + return 1; + } + } + + namespace font + { + static int load(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + uint8_t s = mini::font::load(str); + if (s==255) { + luaL_error(L, "Error while loading font: Max fonts reached"); + return 0; + } + lua_pushinteger(L, s); + return 1; + } + + static int current(lua_State *L) { + const int numargs = lua_gettop(L); + switch (numargs) { + case 0: { + lua_pushinteger(L, mini::font::current::get()); + return 1; + } + case 1: { + uint8_t font = luaL_checkinteger(L, 1); + mini::font::current::set(font); + return 0; + } + default: + return luaL_error(L, "Function 'font.current' Unexpected number of parameters."); + }; + } + + static int spacing(lua_State *L) { + const int numargs = lua_gettop(L); + switch (numargs) { + case 0: { + lua_pushinteger(L, mini::font::spacing::get()); + return 1; + } + case 1: { + uint8_t spacing = luaL_checkinteger(L, 1); + mini::font::spacing::set(spacing); + return 0; + } + default: + return luaL_error(L, "Function 'font.spacing' Unexpected number of parameters."); + }; + } + } + + namespace mouse + { + static int pos(lua_State *L) { + lua_pushinteger(L, mini::mouse::posx()); + lua_pushinteger(L, mini::mouse::posy()); + return 2; + } + + static int wheel(lua_State *L) { + lua_pushinteger(L, mini::mouse::wheel()); + return 1; + } + + static int down(lua_State *L) { + uint8_t i = luaL_checkinteger(L, 1); + lua_pushboolean(L, mini::mouse::down(i)); + return 1; + } + + static int press(lua_State *L) { + uint8_t i = luaL_checkinteger(L, 1); + lua_pushboolean(L, mini::mouse::press(i)); + return 1; + } + + static int dblclick(lua_State *L) { + lua_pushboolean(L, mini::mouse::dblclick()); + return 1; + } + + static int discard(lua_State *L) { + mini::mouse::discard(); + return 0; + } + + static int inside(lua_State *L) { + int x = luaL_checkinteger(L, 1); + int y = luaL_checkinteger(L, 2); + int w = luaL_checkinteger(L, 3); + int h = luaL_checkinteger(L, 4); + lua_pushboolean(L, mini::mouse::inside(x,y,w,h)); + return 1; + } + } + + namespace key + { + static int down(lua_State *L) { + uint8_t i = luaL_checkinteger(L, 1); + lua_pushboolean(L, mini::key::down(i)); + return 1; + } + + static int press(lua_State *L) { + if (lua_gettop(L) >=1 ) { + uint8_t i = luaL_checkinteger(L, 1); + lua_pushboolean(L, mini::key::press(i)); + } else { + lua_pushinteger(L, mini::key::press()); + } + return 1; + } + + static int any(lua_State *L) { + lua_pushboolean(L, mini::key::any()); + return 1; + } + + static int text(lua_State *L) { + mini::key::text(lua_toboolean(L, 1)); + return 0; + } + + static int utf8char(lua_State *L) { + lua_pushstring(L, mini::key::utf8char()); + return 1; + } + } + + namespace pad + { + static int down(lua_State *L) { + int8_t i = luaL_checkinteger(L, 1); + lua_pushboolean(L, mini::pad::down(i)); + return 1; + } + + static int press(lua_State *L) { + if (lua_gettop(L) >=1 ) { + int8_t i = luaL_checkinteger(L, 1); + lua_pushboolean(L, mini::pad::press(i)); + } else { + lua_pushinteger(L, mini::pad::press()); + } + return 1; + } + + static int any(lua_State *L) { + lua_pushinteger(L, mini::pad::press()); + return 1; + } + } } } } - // surface - // =============================================== - - - static int cpp_surf_load(lua_State *L) { - const char* str = luaL_checkstring(L, 1); - uint8_t s = loadsurf(str); - if (s==255) { - luaL_error(L, "Error while loading surface: Max surfaces reached"); - return 0; - } - lua_pushinteger(L, s); - return 1; - } - - static int cpp_surf_loadex(lua_State *L) { - const char* str = luaL_checkstring(L, 1); - uint8_t s = loadsurf(str, true); - if (s==255) { - luaL_error(L, "Error while loading surface: Max surfaces reached"); - return 0; - } - lua_pushinteger(L, s); - return 1; - } - - static int cpp_surf_save(lua_State *L) { - uint8_t surface = luaL_checkinteger(L, 1); - const char* str = luaL_checkstring(L, 2); - - if (lua_istable(L, -1)) { - const int len = SDL_min(256, lua_rawlen(L, -1)); - uint8_t *pal = (uint8_t*)malloc(len*3); - uint8_t *p=pal; - for (int i=1;i<=len;++i) { - lua_rawgeti(L, -1, i); - lua_getfield(L, -1, "r"); - *(p++) = luaL_checknumber(L, -1); - lua_pop(L, 1); - lua_getfield(L, -1, "g"); - *(p++) = luaL_checknumber(L, -1); - lua_pop(L, 1); - lua_getfield(L, -1, "b"); - *(p++) = luaL_checknumber(L, -1); - lua_pop(L, 1); - lua_pop(L, 1); - //pal[i-1] = (r<<16)+(g<<8)+b; - } - savesurf(surface, str, pal, len); - } else { - savesurf(surface, str, nullptr); - } - - return 0; - } - - static int cpp_surf_free(lua_State *L) { - uint8_t surface = luaL_checkinteger(L, 1); - freesurf(surface); - return 0; - } - - static int cpp_surf_size(lua_State *L) { - uint8_t surface = luaL_checkinteger(L, 1); - lua_pushinteger(L, surfw(surface)); - lua_pushinteger(L, surfh(surface)); - return 2; - } - - static int cpp_surf_target(lua_State *L) { - const int numargs = lua_gettop(L); - switch (numargs) { - case 0: { - lua_pushinteger(L, getdest()); - return 1; - } - case 1: { - uint8_t surface = luaL_checkinteger(L, 1); - setdest(surface); - return 0; - } - default: - return luaL_error(L, "Function 'surface.target' Unexpected number of parameters."); - }; - } - - static int cpp_surf_source(lua_State *L) { - const int numargs = lua_gettop(L); - switch (numargs) { - case 0: { - lua_pushinteger(L, getsource()); - return 1; - } - case 1: { - uint8_t surface = luaL_checkinteger(L, 1); - setsource(surface); - return 0; - } - default: - return luaL_error(L, "Function 'surface.source' Unexpected number of parameters."); - }; - } - - static int cpp_surf_cls(lua_State *L) { - uint8_t color = luaL_optinteger(L, 1, 0); - cls(color); - return 0; - } - - static int cpp_surf_pixel(lua_State *L) { - if (lua_gettop(L)==2) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - lua_pushinteger(L, sget(x, y)); - return 1; - } else { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - uint8_t color = luaL_checkinteger(L, 3); - pset(x, y, color); - return 0; - } - } - - // map - // =============================================== - - static int cpp_map_surf(lua_State *L) { - if (lua_gettop(L)==1) { - uint8_t surface = luaL_checkinteger(L, 1); - setmap(surface); - } else { - lua_pushinteger(L, getmap()); - return 1; - } - - return 0; - } - - static int cpp_map_draw(lua_State *L) { - map(); - return 0; - } - - static int cpp_map_tile(lua_State *L) { - if (lua_gettop(L)==2) { - int celx = luaL_checknumber(L, 1); - int cely = luaL_checknumber(L, 2); - lua_pushinteger(L, mget(celx, cely)); - return 1; - } else { - int celx = luaL_checknumber(L, 1); - int cely = luaL_checknumber(L, 2); - uint8_t snum = luaL_checkinteger(L, 3); - mset(celx, cely, snum); - 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 - // =============================================== - - static int cpp_pal_load(lua_State *L) { - const char* str = luaL_checkstring(L, 1); - uint16_t size; - uint32_t *pal = loadpal(str, &size); - lua_createtable(L, 2, 0); - for (int i=0;i>16)&0xff); - lua_setfield(L, -2, "r"); - - lua_pushinteger(L, (color>>8)&0xff); - lua_setfield(L, -2, "g"); - - lua_pushinteger(L, color&0xff); - lua_setfield(L, -2, "b"); - - lua_rawseti(L, -2, i+1); - } - free(pal); - return 1; - } - - static int cpp_pal_set(lua_State *L) { - int r,g,b; - if (lua_istable(L, -1)) { - uint32_t pal[256]; - const int len = SDL_min(256, lua_rawlen(L, -1)); - for (int i=0;i>16)&0xff); - lua_pushinteger(L, (color>>8)&0xff); - lua_pushinteger(L, color&0xff); - return 3; - } else { - uint8_t index = luaL_checkinteger(L, 1); - uint8_t r = luaL_checkinteger(L, 2); - 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_pal_trans(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_pal_subpal(lua_State *L) { - const int num_params = lua_gettop(L); - uint8_t index, index2, color; - switch (num_params) { - case 0: - reset_subpal(); - break; - case 1: - index = luaL_checkinteger(L, 1); - lua_pushinteger(L, subpal(index,index)); - return 1; - break; - case 2: - index = luaL_checkinteger(L, 1); - color = luaL_checkinteger(L, 2); - lua_pushinteger(L, subpal(index, color)); - return 1; - break; - case 3: - index = luaL_checkinteger(L, 1); - index2 = luaL_checkinteger(L, 2); - color = luaL_checkinteger(L, 3); - for (int i=index;i<=index2;++i) subpal(i, color); - break; - } - return 0; - } - - // viewport - // =============================================== - - static int cpp_viewport_clip(lua_State *L) { - if (lua_gettop(L)==0) { - clip(); - return 0; - } 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); - clip(x, y, w, h); - return 0; - } - } - - static int cpp_viewport_origin(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); - origin(x, y); - return 0; - } - } - - static int cpp_viewport_tolocal(lua_State *L) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - lua_pushinteger(L, x+camx()); - lua_pushinteger(L, y+camy()); - return 2; - } - - - static int cpp_draw_line(lua_State *L) { - int x0 = luaL_checknumber(L, 1); - int y0 = luaL_checknumber(L, 2); - int x1 = luaL_checknumber(L, 3); - int y1 = luaL_checknumber(L, 4); - uint8_t color = luaL_checkinteger(L, 5); - mini::draw::line(x0, y0, x1, y1, color); - return 0; - } - - static int cpp_draw_hline(lua_State *L) { - int x0 = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - int x1 = luaL_checknumber(L, 3); - uint8_t color = luaL_checkinteger(L, 4); - mini::draw::hline(x0, y, x1, color); - return 0; - } - - static int cpp_draw_vline(lua_State *L) { - int x = luaL_checknumber(L, 1); - int y0 = luaL_checknumber(L, 2); - int y1 = luaL_checknumber(L, 3); - uint8_t color = luaL_checkinteger(L, 4); - mini::draw::vline(x, y0, y1, color); - return 0; - } - - static int cpp_draw_rect(lua_State *L) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - int w = luaL_checknumber(L, 3); - int h = luaL_checknumber(L, 4); - uint8_t color = luaL_checkinteger(L, 5); - mini::draw::rect(x, y, w, h, color); - return 0; - } - - static int cpp_draw_rectfill(lua_State *L) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - int w = luaL_checknumber(L, 3); - int h = luaL_checknumber(L, 4); - uint8_t color = luaL_checkinteger(L, 5); - mini::draw::rectf(x, y, w, h, color); - return 0; - } - - static int cpp_draw_circ(lua_State *L) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - int r = luaL_optnumber(L, 3, 4); - uint8_t color = luaL_checkinteger(L, 4); - mini::draw::circ(x, y, r, color); - return 0; - } - - static int cpp_draw_circfill(lua_State *L) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - int r = luaL_optnumber(L, 3, 4); - uint8_t color = luaL_checkinteger(L, 4); - mini::draw::circf(x, y, r, color); - return 0; - } - - static int cpp_draw_roundrect(lua_State *L) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - int w = luaL_checknumber(L, 3); - int h = luaL_checknumber(L, 4); - int r = luaL_optnumber(L, 5, 4); - uint8_t color = luaL_checkinteger(L, 6); - mini::draw::roundrect(x, y, w, h, r, color); - return 0; - } - - static int cpp_draw_roundrectfill(lua_State *L) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - int w = luaL_checknumber(L, 3); - int h = luaL_checknumber(L, 4); - int r = luaL_optnumber(L, 5, 4); - uint8_t color = luaL_checkinteger(L, 6); - mini::draw::roundrectf(x, y, w, h, r, color); - return 0; - } - - static int cpp_draw_oval(lua_State *L) { - int x0 = luaL_checknumber(L, 1); - int y0 = luaL_checknumber(L, 2); - int x1 = luaL_checknumber(L, 3); - int y1 = luaL_checknumber(L, 4); - uint8_t color = luaL_checkinteger(L, 5); - mini::draw::oval(x0, y0, x1, y1, color); - return 0; - } - - static int cpp_draw_ovalfill(lua_State *L) { - int x0 = luaL_checknumber(L, 1); - int y0 = luaL_checknumber(L, 2); - int x1 = luaL_checknumber(L, 3); - int y1 = luaL_checknumber(L, 4); - uint8_t color = luaL_checkinteger(L, 5); - mini::draw::ovalf(x0, y0, x1, y1, color); - return 0; - } - - static int cpp_draw_pattern(lua_State *L) { - if (lua_gettop(L) == 0) { - fillp(0xffff); - } else { - uint16_t pat = luaL_checkinteger(L, 1); - bool transparent = lua_toboolean(L, 2); - fillp(pat, transparent); - } - return 0; - } - - static int cpp_draw_surface(lua_State *L) { - int sx = luaL_checknumber(L, 1); - int sy = luaL_checknumber(L, 2); - int sw = luaL_checknumber(L, 3); - int sh = luaL_checknumber(L, 4); - int dx = luaL_checknumber(L, 5); - int dy = luaL_checknumber(L, 6); - int dw = luaL_optnumber(L, 7, 0); - int dh = luaL_optnumber(L, 8, 0); - bool flip_x = lua_toboolean(L, 9); - bool flip_y = lua_toboolean(L, 10); - bool invert = lua_toboolean(L, 11); - blit(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, invert); - return 0; - } - - static int cpp_draw_surfaceRotated(lua_State *L) { - int sx = luaL_checknumber(L, 1); - int sy = luaL_checknumber(L, 2); - int sw = luaL_checknumber(L, 3); - int sh = luaL_checknumber(L, 4); - int dx = luaL_checknumber(L, 5); - int dy = luaL_checknumber(L, 6); - float a = luaL_checknumber(L, 7); - int dw = luaL_optnumber(L, 8, 0); - int dh = luaL_optnumber(L, 9, 0); - bool flip_x = lua_toboolean(L, 10); - bool flip_y = lua_toboolean(L, 11); - blit_r(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, a); - return 0; - } - - static int cpp_draw_text(lua_State *L) { - const char* str = luaL_checkstring(L, 1); - int x = luaL_checknumber(L, 2); - int y = luaL_checknumber(L, 3); - uint8_t color = luaL_checkinteger(L, 4); - print(str, x, y, color); - return 0; - } - - static int cpp_draw_mode(lua_State *L) { - int mode = luaL_checknumber(L, 1); - mini::draw::mode::set(mode); - return 0; - } - - - // shaders - // =============================================== - - static int cpp_shader_init(lua_State *L) { - const char* vstr = luaL_optstring(L, 1, NULL); - const char* fstr = luaL_optstring(L, 2, NULL); - shader_init(vstr, fstr); - return 0; - } - - static int cpp_shader_enable(lua_State *L) { - shader_enable(); - return 0; - } - - static int cpp_shader_disable(lua_State *L) { - shader_disable(); - return 0; - } - - - // music - // =============================================== - - static int cpp_music_play(lua_State *L) { - const char* str = luaL_checkstring(L, 1); - const int loop = luaL_optinteger(L, 2, -1); - playmusic(str, loop); - return 0; - } - - static int cpp_music_pause(lua_State *L) { - pausemusic(); - return 0; - } - - static int cpp_music_resume(lua_State *L) { - resumemusic(); - return 0; - } - - static int cpp_music_stop(lua_State *L) { - const int time = luaL_optinteger(L, 1, 1000); - stopmusic(time); - return 0; - } - - static int cpp_music_pos(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushnumber(L, musicpos()); - return 1; - } else { - musicpos(luaL_checknumber(L, 1)); - return 0; - } - } - - static int cpp_music_enable(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushboolean(L, ismusicenabled()); - return 1; - } else { - enablemusic(lua_toboolean(L, 1)); - return 0; - } - } - - - // sound - // =============================================== - - static int cpp_sound_load(lua_State *L) { - const char* str = luaL_checkstring(L, 1); - lua_pushinteger(L,loadsound(str)); - return 1; - } - - static int cpp_sound_free(lua_State *L) { - const int sound = luaL_checknumber(L, 1); - freesound(sound); - return 0; - } - - static int cpp_sound_play(lua_State *L) { - const int sound = luaL_checknumber(L, 1); - const int volume = luaL_optinteger(L, 2, -1); - lua_pushinteger(L,playsound(sound, volume)); - return 1; - } - - static int cpp_sound_stop(lua_State *L) { - const int sound = luaL_checknumber(L, 1); - stopsound(sound); - return 0; - } - - static int cpp_sound_enable(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushboolean(L, issoundenabled()); - return 1; - } else { - enablesound(lua_toboolean(L, 1)); - return 0; - } - } - - - // sys - // =============================================== - - static int cpp_sys_delta(lua_State *L) { - lua_pushnumber(L, delta()); - return 1; - } - - static int cpp_sys_time(lua_State *L) { - lua_pushnumber(L, time()); - return 1; - } - - static uint32_t chrono_time = 0; - static int cpp_sys_chrono(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushnumber(L, float(SDL_GetTicks()-chrono_time)/1000.0f); - return 1; - } else { - chrono_time = SDL_GetTicks(); - return 0; - } - } - - static int cpp_sys_beat(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushboolean(L, beat(-1)); - return 1; - } else { - int16_t beats = luaL_optnumber(L, 1, -1); - beat(beats); - return 0; - } - } - - static int cpp_sys_update(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushinteger(L, getupdatemode()); - return 1; - } else { - int mode = luaL_checknumber(L, 1); - int interval = luaL_optinteger(L, 2, 0); - setupdatemode(mode, interval); - return 0; - } - } - - namespace fs = std::filesystem; - static int cpp_sys_dir(lua_State *L) { - std::string path = "./data"; - if (lua_gettop(L) > 0) path = luaL_checkstring(L, 1); - - // Collect entries - std::vector entries; - for (const auto& entry : fs::directory_iterator(path)) { - entries.push_back(entry); - } - - // Sort: directories first, then files; both alphabetically - std::sort(entries.begin(), entries.end(), - [](const fs::directory_entry& a, const fs::directory_entry& b) { - bool adir = a.is_directory(); - bool bdir = b.is_directory(); - if (adir != bdir) return adir > bdir; // directories before files - return a.path().filename().string() < b.path().filename().string(); - }); - - // Build Lua table - lua_newtable(L); - int i = 1; - for (const auto& entry : entries) { - lua_newtable(L); - - // name field (canonical absolute path) - lua_pushstring(L, (const char*)fs::canonical(entry.path()).u8string().c_str()); - lua_setfield(L, -2, "name"); - - // dir field - lua_pushboolean(L, entry.is_directory()); - lua_setfield(L, -2, "dir"); - - lua_rawseti(L, -2, i++); - } - - return 1; - } - - static int cpp_sys_exit(lua_State *L) { - exit(); - return 0; - } - - static int cpp_sys_fps(lua_State *L) { - lua_pushnumber(L, getfps()); - return 1; - } - - static int cpp_sys_debug(lua_State *L) { - #ifdef DEBUG - lua_pushboolean(L, true); - #else - lua_pushboolean(L, false); - #endif - return 1; - } - - static int cpp_sys_clipboard(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushstring(L, SDL_GetClipboardText()); - return 1; - } else { - const char* value = luaL_checkstring(L, 1); - SDL_SetClipboardText(value); - return 0; - } - } - - static int cpp_sys_version(lua_State *L) { - lua_pushstring(L, MINI_VERSION); - return 1; - } - - // win - // =============================================== - - static int cpp_win_zoom(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushinteger(L, getzoom()); - return 1; - } else { - const int value = luaL_optinteger(L, 1, 0); - setzoom(value); - return 0; - } - } - - static int cpp_win_fullscreen(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushboolean(L, getfullscreen()); - return 1; - } else { - setfullscreen(lua_toboolean(L, 1)); - return 0; - } - } - - static int cpp_win_cursor(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushboolean(L, getcursor()); - return 1; - } else { - setcursor(lua_toboolean(L, 1)); - return 0; - } - } - - static int cpp_win_res(lua_State *L) { - if (lua_gettop(L) == 0) { - lua_pushinteger(L, scrw()); - lua_pushinteger(L, scrh()); - return 2; - } else { - const int w = luaL_optinteger(L, 1, 160); - const int h = luaL_optinteger(L, 2, 120); - setres(w, h); - return 0; - } - } - - // conf - // =============================================== - - static int cpp_conf_key(lua_State *L) { - const char* key = luaL_checkstring(L, 1); - if (lua_gettop(L) > 1) { - const char* value = luaL_checkstring(L, 2); - setconfig(key, value); - return 0; - } else { - const char* value = getconfig(key); - if (value==NULL) { - lua_pushnil(L); - } else { - lua_pushstring(L, value); - } - return 1; - } - } - - static int cpp_conf_folder(lua_State *L) { - lua_pushstring(L, configfolder()); - return 1; - } - - - // font - // =============================================== - static int cpp_font_load(lua_State *L) { - const char* str = luaL_checkstring(L, 1); - uint8_t s = loadfont(str); - if (s==255) { - luaL_error(L, "Error while loading font: Max fonts reached"); - return 0; - } - lua_pushinteger(L, s); - return 1; - } - - static int cpp_font_current(lua_State *L) { - const int numargs = lua_gettop(L); - switch (numargs) { - case 0: { - lua_pushinteger(L, getfont()); - return 1; - } - case 1: { - uint8_t font = luaL_checkinteger(L, 1); - setfont(font); - return 0; - } - default: - return luaL_error(L, "Function 'font.current' Unexpected number of parameters."); - }; - } - - static int cpp_font_spacing(lua_State *L) { - const int numargs = lua_gettop(L); - switch (numargs) { - case 0: { - lua_pushinteger(L, getfontspacing()); - return 1; - } - case 1: { - uint8_t spacing = luaL_checkinteger(L, 1); - setfontspacing(spacing); - return 0; - } - default: - return luaL_error(L, "Function 'font.spacing' Unexpected number of parameters."); - }; - } - - - // mouse - // =============================================== - - static int cpp_mouse_pos(lua_State *L) { - lua_pushinteger(L, mousex()); - lua_pushinteger(L, mousey()); - return 2; - } - - static int cpp_mouse_wheel(lua_State *L) { - lua_pushinteger(L, mwheel()); - return 1; - } - - static int cpp_mouse_down(lua_State *L) { - uint8_t i = luaL_checkinteger(L, 1); - lua_pushboolean(L, mbtn(i)); - return 1; - } - - static int cpp_mouse_press(lua_State *L) { - uint8_t i = luaL_checkinteger(L, 1); - lua_pushboolean(L, mbtnp(i)); - return 1; - } - - static int cpp_mouse_dblclick(lua_State *L) { - lua_pushboolean(L, doubleclick()); - return 1; - } - - static int cpp_mouse_discard(lua_State *L) { - mdiscard(); - return 0; - } - - static int cpp_mouse_inside(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int w = luaL_checkinteger(L, 3); - int h = luaL_checkinteger(L, 4); - lua_pushboolean(L, minside(x,y,w,h)); - return 1; - } - - - // key - // =============================================== - - static int cpp_key_down(lua_State *L) { - uint8_t i = luaL_checkinteger(L, 1); - lua_pushboolean(L, btn(i)); - return 1; - } - - static int cpp_key_press(lua_State *L) { - if (lua_gettop(L) >=1 ) { - uint8_t i = luaL_checkinteger(L, 1); - lua_pushboolean(L, btnp(i)); - } else { - lua_pushinteger(L, wbtnp()); - } - return 1; - } - - static int cpp_key_any(lua_State *L) { - lua_pushboolean(L, anykey()); - return 1; - } - - static int cpp_key_text(lua_State *L) { - textenable(lua_toboolean(L, 1)); - return 0; - } - - static int cpp_key_utf8char(lua_State *L) { - lua_pushstring(L, textinput()); - return 1; - } - - - // pad - // =============================================== - - static int cpp_pad_down(lua_State *L) { - int8_t i = luaL_checkinteger(L, 1); - lua_pushboolean(L, pad(i)); - return 1; - } - - static int cpp_pad_press(lua_State *L) { - if (lua_gettop(L) >=1 ) { - int8_t i = luaL_checkinteger(L, 1); - lua_pushboolean(L, padp(i)); - } else { - lua_pushinteger(L, wpad()); - } - return 1; - } - - static int cpp_pad_any(lua_State *L) { - lua_pushinteger(L, wpad()); - return 1; - } static int cpp_utf8_sub(lua_State *L) { size_t slen; @@ -1052,298 +1043,292 @@ namespace mini lua_setglobal(L, "mini"); lua_newtable(L); - lua_pushcfunction(L,wrappers::surf::create); lua_setfield(L, -2, "new"); - lua_pushcfunction(L,cpp_surf_load); lua_setfield(L, -2, "load"); - lua_pushcfunction(L,cpp_surf_loadex); lua_setfield(L, -2, "loadex"); - lua_pushcfunction(L,cpp_surf_save); lua_setfield(L, -2, "save"); - lua_pushcfunction(L,cpp_surf_free); lua_setfield(L, -2, "free"); - lua_pushcfunction(L,cpp_surf_size); lua_setfield(L, -2, "size"); - lua_pushcfunction(L,cpp_surf_target); lua_setfield(L, -2, "target"); - lua_pushcfunction(L,cpp_surf_source); lua_setfield(L, -2, "source"); - lua_pushcfunction(L,cpp_surf_cls); lua_setfield(L, -2, "cls"); - lua_pushcfunction(L,cpp_surf_pixel); lua_setfield(L, -2, "pixel"); + lua_pushcfunction(L,wrappers::surf::create); lua_setfield(L, -2, "new"); + lua_pushcfunction(L,wrappers::surf::load); lua_setfield(L, -2, "load"); + lua_pushcfunction(L,wrappers::surf::loadex); lua_setfield(L, -2, "loadex"); + lua_pushcfunction(L,wrappers::surf::save); lua_setfield(L, -2, "save"); + lua_pushcfunction(L,wrappers::surf::free); lua_setfield(L, -2, "free"); + lua_pushcfunction(L,wrappers::surf::size); lua_setfield(L, -2, "size"); + lua_pushcfunction(L,wrappers::surf::target); lua_setfield(L, -2, "target"); + 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::pixel); lua_setfield(L, -2, "pixel"); - lua_pushinteger(L, 0); lua_setfield(L, -2, "SCREEN"); + lua_pushinteger(L, 0); lua_setfield(L, -2, "SCREEN"); lua_setglobal(L, "surf"); lua_newtable(L); - //lua_pushcfunction(L,cpp_map_new); lua_setfield(L, -2, "new"); - //lua_pushcfunction(L,cpp_map_load); lua_setfield(L, -2, "load"); - //lua_pushcfunction(L,cpp_map_save); lua_setfield(L, -2, "save"); - 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_pushcfunction(L,wrappers::map::surf); lua_setfield(L, -2, "surf"); + lua_pushcfunction(L,wrappers::map::draw); lua_setfield(L, -2, "draw"); + lua_pushcfunction(L,wrappers::map::tile); lua_setfield(L, -2, "tile"); + lua_pushcfunction(L,wrappers::map::cell); lua_setfield(L, -2, "cell"); lua_setglobal(L, "map"); lua_newtable(L); - lua_pushcfunction(L,cpp_pal_load); lua_setfield(L, -2, "load"); - lua_pushcfunction(L,cpp_pal_set); lua_setfield(L, -2, "set"); - lua_pushcfunction(L,cpp_pal_color); lua_setfield(L, -2, "color"); - lua_pushcfunction(L,cpp_pal_trans); lua_setfield(L, -2, "trans"); - lua_pushcfunction(L,cpp_pal_subpal); lua_setfield(L, -2, "subpal"); + lua_pushcfunction(L,wrappers::pal::load); lua_setfield(L, -2, "load"); + lua_pushcfunction(L,wrappers::pal::set); lua_setfield(L, -2, "set"); + lua_pushcfunction(L,wrappers::pal::color); lua_setfield(L, -2, "color"); + lua_pushcfunction(L,wrappers::pal::trans); lua_setfield(L, -2, "trans"); + lua_pushcfunction(L,wrappers::pal::subpal); lua_setfield(L, -2, "subpal"); lua_setglobal(L, "pal"); lua_newtable(L); - lua_pushcfunction(L,cpp_viewport_clip); lua_setfield(L, -2, "clip"); - lua_pushcfunction(L,cpp_viewport_origin); lua_setfield(L, -2, "origin"); - lua_pushcfunction(L,cpp_viewport_tolocal); lua_setfield(L, -2, "tolocal"); + lua_pushcfunction(L,wrappers::view::clip); lua_setfield(L, -2, "clip"); + lua_pushcfunction(L,wrappers::view::origin); lua_setfield(L, -2, "origin"); + lua_pushcfunction(L,wrappers::view::tolocal); lua_setfield(L, -2, "tolocal"); lua_setglobal(L, "view"); lua_newtable(L); - lua_pushcfunction(L,cpp_draw_line); lua_setfield(L, -2, "line"); - lua_pushcfunction(L,cpp_draw_hline); lua_setfield(L, -2, "hline"); - lua_pushcfunction(L,cpp_draw_vline); lua_setfield(L, -2, "vline"); - lua_pushcfunction(L,cpp_draw_rect); lua_setfield(L, -2, "rect"); - lua_pushcfunction(L,cpp_draw_rectfill); lua_setfield(L, -2, "rectf"); - lua_pushcfunction(L,cpp_draw_circ); lua_setfield(L, -2, "circ"); - lua_pushcfunction(L,cpp_draw_circfill); lua_setfield(L, -2, "circf"); - lua_pushcfunction(L,cpp_draw_roundrect); lua_setfield(L, -2, "rrect"); - lua_pushcfunction(L,cpp_draw_roundrectfill); lua_setfield(L, -2, "rrectf"); - lua_pushcfunction(L,cpp_draw_oval); lua_setfield(L, -2, "oval"); - lua_pushcfunction(L,cpp_draw_ovalfill); lua_setfield(L, -2, "ovalf"); - lua_pushcfunction(L,cpp_draw_pattern); lua_setfield(L, -2, "pattern"); - //lua_pushcfunction(L,cpp_draw_tline); lua_setfield(L, -2, "tline"); - //lua_pushcfunction(L,cpp_draw_thline); lua_setfield(L, -2, "thline"); - //lua_pushcfunction(L,cpp_draw_tvline); lua_setfield(L, -2, "tvline"); - lua_pushcfunction(L,cpp_draw_surface); lua_setfield(L, -2, "surf"); - lua_pushcfunction(L,cpp_draw_surfaceRotated); lua_setfield(L, -2, "surfrot"); - lua_pushcfunction(L,cpp_draw_text); lua_setfield(L, -2, "text"); - lua_pushcfunction(L,cpp_draw_mode); lua_setfield(L, -2, "mode"); + 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"); + lua_pushcfunction(L,wrappers::draw::rect); lua_setfield(L, -2, "rect"); + lua_pushcfunction(L,wrappers::draw::rectf); lua_setfield(L, -2, "rectf"); + lua_pushcfunction(L,wrappers::draw::circ); lua_setfield(L, -2, "circ"); + lua_pushcfunction(L,wrappers::draw::circf); lua_setfield(L, -2, "circf"); + lua_pushcfunction(L,wrappers::draw::roundrect); lua_setfield(L, -2, "rrect"); + lua_pushcfunction(L,wrappers::draw::roundrectf); lua_setfield(L, -2, "rrectf"); + lua_pushcfunction(L,wrappers::draw::oval); lua_setfield(L, -2, "oval"); + lua_pushcfunction(L,wrappers::draw::ovalf); lua_setfield(L, -2, "ovalf"); + lua_pushcfunction(L,wrappers::draw::pattern); lua_setfield(L, -2, "pattern"); + lua_pushcfunction(L,wrappers::draw::surf); lua_setfield(L, -2, "surf"); + lua_pushcfunction(L,wrappers::draw::surfrot); lua_setfield(L, -2, "surfrot"); + lua_pushcfunction(L,wrappers::draw::text); lua_setfield(L, -2, "text"); + lua_pushcfunction(L,wrappers::draw::mode); lua_setfield(L, -2, "mode"); - lua_pushinteger(L, 0); lua_setfield(L, -2, "NORMAL"); - lua_pushinteger(L, 1); lua_setfield(L, -2, "PATTERN"); - lua_pushinteger(L, 2); lua_setfield(L, -2, "AND"); - lua_pushinteger(L, 3); lua_setfield(L, -2, "OR"); - lua_pushinteger(L, 4); lua_setfield(L, -2, "XOR"); - lua_pushinteger(L, 5); lua_setfield(L, -2, "NOT"); + lua_pushinteger(L, 0); lua_setfield(L, -2, "NORMAL"); + lua_pushinteger(L, 1); lua_setfield(L, -2, "PATTERN"); + lua_pushinteger(L, 2); lua_setfield(L, -2, "AND"); + lua_pushinteger(L, 3); lua_setfield(L, -2, "OR"); + lua_pushinteger(L, 4); lua_setfield(L, -2, "XOR"); + lua_pushinteger(L, 5); lua_setfield(L, -2, "NOT"); lua_setglobal(L, "draw"); lua_newtable(L); - lua_pushcfunction(L,cpp_shader_init); lua_setfield(L, -2, "init"); - lua_pushcfunction(L,cpp_shader_enable); lua_setfield(L, -2, "enable"); - lua_pushcfunction(L,cpp_shader_disable); lua_setfield(L, -2, "disable"); + lua_pushcfunction(L,wrappers::shader::init); lua_setfield(L, -2, "init"); + lua_pushcfunction(L,wrappers::shader::enable); lua_setfield(L, -2, "enable"); + lua_pushcfunction(L,wrappers::shader::disable); lua_setfield(L, -2, "disable"); lua_setglobal(L, "shader"); lua_newtable(L); - lua_pushcfunction(L,cpp_music_play); lua_setfield(L, -2, "play"); - lua_pushcfunction(L,cpp_music_pause); lua_setfield(L, -2, "pause"); - lua_pushcfunction(L,cpp_music_resume); lua_setfield(L, -2, "resume"); - lua_pushcfunction(L,cpp_music_stop); lua_setfield(L, -2, "stop"); - lua_pushcfunction(L,cpp_music_pos); lua_setfield(L, -2, "pos"); - lua_pushcfunction(L,cpp_music_enable); lua_setfield(L, -2, "enabled"); + lua_pushcfunction(L,wrappers::music::play); lua_setfield(L, -2, "play"); + lua_pushcfunction(L,wrappers::music::pause); lua_setfield(L, -2, "pause"); + lua_pushcfunction(L,wrappers::music::resume); lua_setfield(L, -2, "resume"); + lua_pushcfunction(L,wrappers::music::stop); lua_setfield(L, -2, "stop"); + lua_pushcfunction(L,wrappers::music::pos); lua_setfield(L, -2, "pos"); + lua_pushcfunction(L,wrappers::music::enable); lua_setfield(L, -2, "enabled"); lua_setglobal(L, "music"); lua_newtable(L); - lua_pushcfunction(L,cpp_sound_load); lua_setfield(L, -2, "load"); - lua_pushcfunction(L,cpp_sound_free); lua_setfield(L, -2, "free"); - lua_pushcfunction(L,cpp_sound_play); lua_setfield(L, -2, "play"); - lua_pushcfunction(L,cpp_sound_stop); lua_setfield(L, -2, "stop"); - lua_pushcfunction(L,cpp_sound_enable); lua_setfield(L, -2, "enabled"); + lua_pushcfunction(L,wrappers::sound::load); lua_setfield(L, -2, "load"); + lua_pushcfunction(L,wrappers::sound::free); lua_setfield(L, -2, "free"); + lua_pushcfunction(L,wrappers::sound::play); lua_setfield(L, -2, "play"); + lua_pushcfunction(L,wrappers::sound::stop); lua_setfield(L, -2, "stop"); + lua_pushcfunction(L,wrappers::sound::enable); lua_setfield(L, -2, "enabled"); lua_setglobal(L, "sound"); lua_newtable(L); - lua_pushcfunction(L,cpp_sys_delta); lua_setfield(L, -2, "delta"); - lua_pushcfunction(L,cpp_sys_time); lua_setfield(L, -2, "time"); - lua_pushcfunction(L,cpp_sys_chrono); lua_setfield(L, -2, "chrono"); - lua_pushcfunction(L,cpp_sys_beat); lua_setfield(L, -2, "beat"); - lua_pushcfunction(L,cpp_sys_update); lua_setfield(L, -2, "update"); - lua_pushcfunction(L,cpp_sys_dir); lua_setfield(L, -2, "dir"); - lua_pushcfunction(L,cpp_sys_exit); lua_setfield(L, -2, "quit"); - lua_pushcfunction(L,cpp_sys_fps); lua_setfield(L, -2, "fps"); - lua_pushcfunction(L,cpp_sys_debug); lua_setfield(L, -2, "debug"); - lua_pushcfunction(L,cpp_sys_clipboard); lua_setfield(L, -2, "clipboard"); - lua_pushcfunction(L,cpp_sys_version); lua_setfield(L, -2, "version"); + lua_pushcfunction(L,wrappers::sys::delta); lua_setfield(L, -2, "delta"); + lua_pushcfunction(L,wrappers::sys::time); lua_setfield(L, -2, "time"); + lua_pushcfunction(L,wrappers::sys::chrono); lua_setfield(L, -2, "chrono"); + lua_pushcfunction(L,wrappers::sys::beat); lua_setfield(L, -2, "beat"); + lua_pushcfunction(L,wrappers::sys::update); lua_setfield(L, -2, "update"); + lua_pushcfunction(L,wrappers::sys::dir); lua_setfield(L, -2, "dir"); + lua_pushcfunction(L,wrappers::sys::exit); lua_setfield(L, -2, "quit"); + lua_pushcfunction(L,wrappers::sys::fps); lua_setfield(L, -2, "fps"); + lua_pushcfunction(L,wrappers::sys::debug); lua_setfield(L, -2, "debug"); + lua_pushcfunction(L,wrappers::sys::clipboard); lua_setfield(L, -2, "clipboard"); + lua_pushcfunction(L,wrappers::sys::version); lua_setfield(L, -2, "version"); - lua_pushinteger(L, 0); lua_setfield(L, -2, "UPDATE_ALWAYS"); - lua_pushinteger(L, 1); lua_setfield(L, -2, "UPDATE_WAIT"); - lua_pushinteger(L, 2); lua_setfield(L, -2, "UPDATE_TIMEOUT"); + lua_pushinteger(L, 0); lua_setfield(L, -2, "UPDATE_ALWAYS"); + lua_pushinteger(L, 1); lua_setfield(L, -2, "UPDATE_WAIT"); + lua_pushinteger(L, 2); lua_setfield(L, -2, "UPDATE_TIMEOUT"); lua_setglobal(L, "sys"); lua_newtable(L); - lua_pushcfunction(L,cpp_win_zoom); lua_setfield(L, -2, "zoom"); - lua_pushcfunction(L,cpp_win_fullscreen); lua_setfield(L, -2, "fullscreen"); - lua_pushcfunction(L,cpp_win_cursor); lua_setfield(L, -2, "cursor"); - lua_pushcfunction(L,cpp_win_res); lua_setfield(L, -2, "res"); + lua_pushcfunction(L,wrappers::win::zoom); lua_setfield(L, -2, "zoom"); + lua_pushcfunction(L,wrappers::win::fullscreen); lua_setfield(L, -2, "fullscreen"); + lua_pushcfunction(L,wrappers::win::cursor); lua_setfield(L, -2, "cursor"); + lua_pushcfunction(L,wrappers::win::res); lua_setfield(L, -2, "res"); lua_setglobal(L, "win"); lua_newtable(L); - lua_pushcfunction(L,cpp_conf_key); lua_setfield(L, -2, "key"); - lua_pushcfunction(L,cpp_conf_folder); lua_setfield(L, -2, "folder"); + lua_pushcfunction(L,wrappers::conf::key); lua_setfield(L, -2, "key"); + lua_pushcfunction(L,wrappers::conf::folder); lua_setfield(L, -2, "folder"); lua_setglobal(L, "config"); lua_newtable(L); - lua_pushcfunction(L,cpp_font_load); lua_setfield(L, -2, "load"); - lua_pushcfunction(L,cpp_font_current); lua_setfield(L, -2, "current"); - lua_pushcfunction(L,cpp_font_spacing); lua_setfield(L, -2, "spacing"); + lua_pushcfunction(L,wrappers::font::load); lua_setfield(L, -2, "load"); + lua_pushcfunction(L,wrappers::font::current); lua_setfield(L, -2, "current"); + lua_pushcfunction(L,wrappers::font::spacing); lua_setfield(L, -2, "spacing"); - lua_pushinteger(L, 0); lua_setfield(L, -2, "DEFAULT"); + lua_pushinteger(L, 0); lua_setfield(L, -2, "DEFAULT"); lua_setglobal(L, "font"); lua_newtable(L); - lua_pushcfunction(L,cpp_mouse_pos); lua_setfield(L, -2, "pos"); - lua_pushcfunction(L,cpp_mouse_wheel); lua_setfield(L, -2, "wheel"); - lua_pushcfunction(L,cpp_mouse_down); lua_setfield(L, -2, "down"); - lua_pushcfunction(L,cpp_mouse_press); lua_setfield(L, -2, "press"); - lua_pushcfunction(L,cpp_mouse_dblclick); lua_setfield(L, -2, "dblclick"); - lua_pushcfunction(L,cpp_mouse_discard); lua_setfield(L, -2, "discard"); - lua_pushcfunction(L,cpp_mouse_inside); lua_setfield(L, -2, "inside"); + lua_pushcfunction(L,wrappers::mouse::pos); lua_setfield(L, -2, "pos"); + lua_pushcfunction(L,wrappers::mouse::wheel); lua_setfield(L, -2, "wheel"); + lua_pushcfunction(L,wrappers::mouse::down); lua_setfield(L, -2, "down"); + lua_pushcfunction(L,wrappers::mouse::press); lua_setfield(L, -2, "press"); + lua_pushcfunction(L,wrappers::mouse::dblclick); lua_setfield(L, -2, "dblclick"); + lua_pushcfunction(L,wrappers::mouse::discard); lua_setfield(L, -2, "discard"); + lua_pushcfunction(L,wrappers::mouse::inside); lua_setfield(L, -2, "inside"); - lua_pushinteger(L, 1); lua_setfield(L, -2, "LEFT"); - lua_pushinteger(L, 2); lua_setfield(L, -2, "MIDDLE"); - lua_pushinteger(L, 3); lua_setfield(L, -2, "RIGHT"); + lua_pushinteger(L, 1); lua_setfield(L, -2, "LEFT"); + lua_pushinteger(L, 2); lua_setfield(L, -2, "MIDDLE"); + lua_pushinteger(L, 3); lua_setfield(L, -2, "RIGHT"); lua_setglobal(L, "mouse"); lua_newtable(L); - lua_pushcfunction(L,cpp_key_down); lua_setfield(L, -2, "down"); - lua_pushcfunction(L,cpp_key_press); lua_setfield(L, -2, "press"); - lua_pushcfunction(L,cpp_key_any); lua_setfield(L, -2, "any"); - lua_pushcfunction(L,cpp_key_text); lua_setfield(L, -2, "text"); - lua_pushcfunction(L,cpp_key_utf8char); lua_setfield(L, -2, "utf8char"); + lua_pushcfunction(L,wrappers::key::down); lua_setfield(L, -2, "down"); + lua_pushcfunction(L,wrappers::key::press); lua_setfield(L, -2, "press"); + lua_pushcfunction(L,wrappers::key::any); lua_setfield(L, -2, "any"); + lua_pushcfunction(L,wrappers::key::text); lua_setfield(L, -2, "text"); + lua_pushcfunction(L,wrappers::key::utf8char); lua_setfield(L, -2, "utf8char"); //lua_setglobal(L, "key"); //lua_newtable(L); - lua_pushinteger(L, 0); lua_setfield(L, -2, "UNKNOWN"); - lua_pushinteger(L, 4); lua_setfield(L, -2, "A"); - lua_pushinteger(L, 5); lua_setfield(L, -2, "B"); - lua_pushinteger(L, 6); lua_setfield(L, -2, "C"); - lua_pushinteger(L, 7); lua_setfield(L, -2, "D"); - lua_pushinteger(L, 8); lua_setfield(L, -2, "E"); - lua_pushinteger(L, 9); lua_setfield(L, -2, "F"); - lua_pushinteger(L, 10); lua_setfield(L, -2, "G"); - lua_pushinteger(L, 11); lua_setfield(L, -2, "H"); - lua_pushinteger(L, 12); lua_setfield(L, -2, "I"); - lua_pushinteger(L, 13); lua_setfield(L, -2, "J"); - lua_pushinteger(L, 14); lua_setfield(L, -2, "K"); - lua_pushinteger(L, 15); lua_setfield(L, -2, "L"); - lua_pushinteger(L, 16); lua_setfield(L, -2, "M"); - lua_pushinteger(L, 17); lua_setfield(L, -2, "N"); - lua_pushinteger(L, 18); lua_setfield(L, -2, "O"); - lua_pushinteger(L, 19); lua_setfield(L, -2, "P"); - lua_pushinteger(L, 20); lua_setfield(L, -2, "Q"); - lua_pushinteger(L, 21); lua_setfield(L, -2, "R"); - lua_pushinteger(L, 22); lua_setfield(L, -2, "S"); - lua_pushinteger(L, 23); lua_setfield(L, -2, "T"); - lua_pushinteger(L, 24); lua_setfield(L, -2, "U"); - lua_pushinteger(L, 25); lua_setfield(L, -2, "V"); - lua_pushinteger(L, 26); lua_setfield(L, -2, "W"); - lua_pushinteger(L, 27); lua_setfield(L, -2, "X"); - lua_pushinteger(L, 28); lua_setfield(L, -2, "Y"); - lua_pushinteger(L, 29); lua_setfield(L, -2, "Z"); - lua_pushinteger(L, 30); lua_setfield(L, -2, "N1"); - lua_pushinteger(L, 31); lua_setfield(L, -2, "N2"); - lua_pushinteger(L, 32); lua_setfield(L, -2, "N3"); - lua_pushinteger(L, 33); lua_setfield(L, -2, "N4"); - lua_pushinteger(L, 34); lua_setfield(L, -2, "N5"); - lua_pushinteger(L, 35); lua_setfield(L, -2, "N6"); - lua_pushinteger(L, 36); lua_setfield(L, -2, "N7"); - lua_pushinteger(L, 37); lua_setfield(L, -2, "N8"); - lua_pushinteger(L, 38); lua_setfield(L, -2, "N9"); - lua_pushinteger(L, 39); lua_setfield(L, -2, "N0"); - lua_pushinteger(L, 40); lua_setfield(L, -2, "RETURN"); - lua_pushinteger(L, 41); lua_setfield(L, -2, "ESCAPE"); - lua_pushinteger(L, 42); lua_setfield(L, -2, "BACKSPACE"); - lua_pushinteger(L, 43); lua_setfield(L, -2, "TAB"); - lua_pushinteger(L, 44); lua_setfield(L, -2, "SPACE"); - lua_pushinteger(L, 45); lua_setfield(L, -2, "MINUS"); - lua_pushinteger(L, 46); lua_setfield(L, -2, "EQUALS"); - lua_pushinteger(L, 47); lua_setfield(L, -2, "LEFTBRACKET"); - lua_pushinteger(L, 48); lua_setfield(L, -2, "RIGHTBRACKET"); - lua_pushinteger(L, 49); lua_setfield(L, -2, "BACKSLASH"); - lua_pushinteger(L, 50); lua_setfield(L, -2, "NONUSHASH"); - lua_pushinteger(L, 51); lua_setfield(L, -2, "SEMICOLON"); - lua_pushinteger(L, 52); lua_setfield(L, -2, "APOSTROPHE"); - lua_pushinteger(L, 53); lua_setfield(L, -2, "GRAVE"); - lua_pushinteger(L, 54); lua_setfield(L, -2, "COMMA"); - lua_pushinteger(L, 55); lua_setfield(L, -2, "PERIOD"); - lua_pushinteger(L, 56); lua_setfield(L, -2, "SLASH"); - lua_pushinteger(L, 57); lua_setfield(L, -2, "CAPSLOCK"); - lua_pushinteger(L, 58); lua_setfield(L, -2, "F1"); - lua_pushinteger(L, 59); lua_setfield(L, -2, "F2"); - lua_pushinteger(L, 60); lua_setfield(L, -2, "F3"); - lua_pushinteger(L, 61); lua_setfield(L, -2, "F4"); - lua_pushinteger(L, 62); lua_setfield(L, -2, "F5"); - lua_pushinteger(L, 63); lua_setfield(L, -2, "F6"); - lua_pushinteger(L, 64); lua_setfield(L, -2, "F7"); - lua_pushinteger(L, 65); lua_setfield(L, -2, "F8"); - lua_pushinteger(L, 66); lua_setfield(L, -2, "F9"); - lua_pushinteger(L, 67); lua_setfield(L, -2, "F10"); - lua_pushinteger(L, 68); lua_setfield(L, -2, "F11"); - lua_pushinteger(L, 69); lua_setfield(L, -2, "F12"); - lua_pushinteger(L, 70); lua_setfield(L, -2, "PRINTSCREEN"); - lua_pushinteger(L, 71); lua_setfield(L, -2, "SCROLLLOCK"); - lua_pushinteger(L, 72); lua_setfield(L, -2, "PAUSE"); - lua_pushinteger(L, 73); lua_setfield(L, -2, "INSERT"); - lua_pushinteger(L, 74); lua_setfield(L, -2, "HOME"); - lua_pushinteger(L, 75); lua_setfield(L, -2, "PAGEUP"); - lua_pushinteger(L, 76); lua_setfield(L, -2, "DELETE"); - lua_pushinteger(L, 77); lua_setfield(L, -2, "END"); - lua_pushinteger(L, 78); lua_setfield(L, -2, "PAGEDOWN"); - lua_pushinteger(L, 79); lua_setfield(L, -2, "RIGHT"); - lua_pushinteger(L, 80); lua_setfield(L, -2, "LEFT"); - lua_pushinteger(L, 81); lua_setfield(L, -2, "DOWN"); - lua_pushinteger(L, 82); lua_setfield(L, -2, "UP"); - lua_pushinteger(L, 83); lua_setfield(L, -2, "NUMLOCKCLEAR"); - lua_pushinteger(L, 84); lua_setfield(L, -2, "KP_DIVIDE"); - lua_pushinteger(L, 85); lua_setfield(L, -2, "KP_MULTIPLY"); - lua_pushinteger(L, 86); lua_setfield(L, -2, "KP_MINUS"); - lua_pushinteger(L, 87); lua_setfield(L, -2, "KP_PLUS"); - lua_pushinteger(L, 88); lua_setfield(L, -2, "KP_ENTER"); - lua_pushinteger(L, 89); lua_setfield(L, -2, "KP_1"); - lua_pushinteger(L, 90); lua_setfield(L, -2, "KP_2"); - lua_pushinteger(L, 91); lua_setfield(L, -2, "KP_3"); - lua_pushinteger(L, 92); lua_setfield(L, -2, "KP_4"); - lua_pushinteger(L, 93); lua_setfield(L, -2, "KP_5"); - lua_pushinteger(L, 94); lua_setfield(L, -2, "KP_6"); - lua_pushinteger(L, 95); lua_setfield(L, -2, "KP_7"); - lua_pushinteger(L, 96); lua_setfield(L, -2, "KP_8"); - lua_pushinteger(L, 97); lua_setfield(L, -2, "KP_9"); - lua_pushinteger(L, 98); lua_setfield(L, -2, "KP_0"); - lua_pushinteger(L, 99); lua_setfield(L, -2, "KP_PERIOD"); - lua_pushinteger(L, 100); lua_setfield(L, -2, "NONUSBACKSLASH"); - lua_pushinteger(L, 101); lua_setfield(L, -2, "APPLICATION"); - lua_pushinteger(L, 224); lua_setfield(L, -2, "LCTRL"); - lua_pushinteger(L, 225); lua_setfield(L, -2, "LSHIFT"); - lua_pushinteger(L, 226); lua_setfield(L, -2, "LALT"); - lua_pushinteger(L, 227); lua_setfield(L, -2, "LGUI"); - lua_pushinteger(L, 228); lua_setfield(L, -2, "RCTRL"); - lua_pushinteger(L, 229); lua_setfield(L, -2, "RSHIFT"); - lua_pushinteger(L, 230); lua_setfield(L, -2, "RALT"); - lua_pushinteger(L, 231); lua_setfield(L, -2, "RGUI"); + lua_pushinteger(L, 0); lua_setfield(L, -2, "UNKNOWN"); + lua_pushinteger(L, 4); lua_setfield(L, -2, "A"); + lua_pushinteger(L, 5); lua_setfield(L, -2, "B"); + lua_pushinteger(L, 6); lua_setfield(L, -2, "C"); + lua_pushinteger(L, 7); lua_setfield(L, -2, "D"); + lua_pushinteger(L, 8); lua_setfield(L, -2, "E"); + lua_pushinteger(L, 9); lua_setfield(L, -2, "F"); + lua_pushinteger(L, 10); lua_setfield(L, -2, "G"); + lua_pushinteger(L, 11); lua_setfield(L, -2, "H"); + lua_pushinteger(L, 12); lua_setfield(L, -2, "I"); + lua_pushinteger(L, 13); lua_setfield(L, -2, "J"); + lua_pushinteger(L, 14); lua_setfield(L, -2, "K"); + lua_pushinteger(L, 15); lua_setfield(L, -2, "L"); + lua_pushinteger(L, 16); lua_setfield(L, -2, "M"); + lua_pushinteger(L, 17); lua_setfield(L, -2, "N"); + lua_pushinteger(L, 18); lua_setfield(L, -2, "O"); + lua_pushinteger(L, 19); lua_setfield(L, -2, "P"); + lua_pushinteger(L, 20); lua_setfield(L, -2, "Q"); + lua_pushinteger(L, 21); lua_setfield(L, -2, "R"); + lua_pushinteger(L, 22); lua_setfield(L, -2, "S"); + lua_pushinteger(L, 23); lua_setfield(L, -2, "T"); + lua_pushinteger(L, 24); lua_setfield(L, -2, "U"); + lua_pushinteger(L, 25); lua_setfield(L, -2, "V"); + lua_pushinteger(L, 26); lua_setfield(L, -2, "W"); + lua_pushinteger(L, 27); lua_setfield(L, -2, "X"); + lua_pushinteger(L, 28); lua_setfield(L, -2, "Y"); + lua_pushinteger(L, 29); lua_setfield(L, -2, "Z"); + lua_pushinteger(L, 30); lua_setfield(L, -2, "N1"); + lua_pushinteger(L, 31); lua_setfield(L, -2, "N2"); + lua_pushinteger(L, 32); lua_setfield(L, -2, "N3"); + lua_pushinteger(L, 33); lua_setfield(L, -2, "N4"); + lua_pushinteger(L, 34); lua_setfield(L, -2, "N5"); + lua_pushinteger(L, 35); lua_setfield(L, -2, "N6"); + lua_pushinteger(L, 36); lua_setfield(L, -2, "N7"); + lua_pushinteger(L, 37); lua_setfield(L, -2, "N8"); + lua_pushinteger(L, 38); lua_setfield(L, -2, "N9"); + lua_pushinteger(L, 39); lua_setfield(L, -2, "N0"); + lua_pushinteger(L, 40); lua_setfield(L, -2, "RETURN"); + lua_pushinteger(L, 41); lua_setfield(L, -2, "ESCAPE"); + lua_pushinteger(L, 42); lua_setfield(L, -2, "BACKSPACE"); + lua_pushinteger(L, 43); lua_setfield(L, -2, "TAB"); + lua_pushinteger(L, 44); lua_setfield(L, -2, "SPACE"); + lua_pushinteger(L, 45); lua_setfield(L, -2, "MINUS"); + lua_pushinteger(L, 46); lua_setfield(L, -2, "EQUALS"); + lua_pushinteger(L, 47); lua_setfield(L, -2, "LEFTBRACKET"); + lua_pushinteger(L, 48); lua_setfield(L, -2, "RIGHTBRACKET"); + lua_pushinteger(L, 49); lua_setfield(L, -2, "BACKSLASH"); + lua_pushinteger(L, 50); lua_setfield(L, -2, "NONUSHASH"); + lua_pushinteger(L, 51); lua_setfield(L, -2, "SEMICOLON"); + lua_pushinteger(L, 52); lua_setfield(L, -2, "APOSTROPHE"); + lua_pushinteger(L, 53); lua_setfield(L, -2, "GRAVE"); + lua_pushinteger(L, 54); lua_setfield(L, -2, "COMMA"); + lua_pushinteger(L, 55); lua_setfield(L, -2, "PERIOD"); + lua_pushinteger(L, 56); lua_setfield(L, -2, "SLASH"); + lua_pushinteger(L, 57); lua_setfield(L, -2, "CAPSLOCK"); + lua_pushinteger(L, 58); lua_setfield(L, -2, "F1"); + lua_pushinteger(L, 59); lua_setfield(L, -2, "F2"); + lua_pushinteger(L, 60); lua_setfield(L, -2, "F3"); + lua_pushinteger(L, 61); lua_setfield(L, -2, "F4"); + lua_pushinteger(L, 62); lua_setfield(L, -2, "F5"); + lua_pushinteger(L, 63); lua_setfield(L, -2, "F6"); + lua_pushinteger(L, 64); lua_setfield(L, -2, "F7"); + lua_pushinteger(L, 65); lua_setfield(L, -2, "F8"); + lua_pushinteger(L, 66); lua_setfield(L, -2, "F9"); + lua_pushinteger(L, 67); lua_setfield(L, -2, "F10"); + lua_pushinteger(L, 68); lua_setfield(L, -2, "F11"); + lua_pushinteger(L, 69); lua_setfield(L, -2, "F12"); + lua_pushinteger(L, 70); lua_setfield(L, -2, "PRINTSCREEN"); + lua_pushinteger(L, 71); lua_setfield(L, -2, "SCROLLLOCK"); + lua_pushinteger(L, 72); lua_setfield(L, -2, "PAUSE"); + lua_pushinteger(L, 73); lua_setfield(L, -2, "INSERT"); + lua_pushinteger(L, 74); lua_setfield(L, -2, "HOME"); + lua_pushinteger(L, 75); lua_setfield(L, -2, "PAGEUP"); + lua_pushinteger(L, 76); lua_setfield(L, -2, "DELETE"); + lua_pushinteger(L, 77); lua_setfield(L, -2, "END"); + lua_pushinteger(L, 78); lua_setfield(L, -2, "PAGEDOWN"); + lua_pushinteger(L, 79); lua_setfield(L, -2, "RIGHT"); + lua_pushinteger(L, 80); lua_setfield(L, -2, "LEFT"); + lua_pushinteger(L, 81); lua_setfield(L, -2, "DOWN"); + lua_pushinteger(L, 82); lua_setfield(L, -2, "UP"); + lua_pushinteger(L, 83); lua_setfield(L, -2, "NUMLOCKCLEAR"); + lua_pushinteger(L, 84); lua_setfield(L, -2, "KP_DIVIDE"); + lua_pushinteger(L, 85); lua_setfield(L, -2, "KP_MULTIPLY"); + lua_pushinteger(L, 86); lua_setfield(L, -2, "KP_MINUS"); + lua_pushinteger(L, 87); lua_setfield(L, -2, "KP_PLUS"); + lua_pushinteger(L, 88); lua_setfield(L, -2, "KP_ENTER"); + lua_pushinteger(L, 89); lua_setfield(L, -2, "KP_1"); + lua_pushinteger(L, 90); lua_setfield(L, -2, "KP_2"); + lua_pushinteger(L, 91); lua_setfield(L, -2, "KP_3"); + lua_pushinteger(L, 92); lua_setfield(L, -2, "KP_4"); + lua_pushinteger(L, 93); lua_setfield(L, -2, "KP_5"); + lua_pushinteger(L, 94); lua_setfield(L, -2, "KP_6"); + lua_pushinteger(L, 95); lua_setfield(L, -2, "KP_7"); + lua_pushinteger(L, 96); lua_setfield(L, -2, "KP_8"); + lua_pushinteger(L, 97); lua_setfield(L, -2, "KP_9"); + lua_pushinteger(L, 98); lua_setfield(L, -2, "KP_0"); + lua_pushinteger(L, 99); lua_setfield(L, -2, "KP_PERIOD"); + lua_pushinteger(L, 100); lua_setfield(L, -2, "NONUSBACKSLASH"); + lua_pushinteger(L, 101); lua_setfield(L, -2, "APPLICATION"); + lua_pushinteger(L, 224); lua_setfield(L, -2, "LCTRL"); + lua_pushinteger(L, 225); lua_setfield(L, -2, "LSHIFT"); + lua_pushinteger(L, 226); lua_setfield(L, -2, "LALT"); + lua_pushinteger(L, 227); lua_setfield(L, -2, "LGUI"); + lua_pushinteger(L, 228); lua_setfield(L, -2, "RCTRL"); + lua_pushinteger(L, 229); lua_setfield(L, -2, "RSHIFT"); + lua_pushinteger(L, 230); lua_setfield(L, -2, "RALT"); + lua_pushinteger(L, 231); lua_setfield(L, -2, "RGUI"); lua_setglobal(L, "key"); lua_newtable(L); - lua_pushcfunction(L,cpp_pad_down); lua_setfield(L, -2, "down"); - lua_pushcfunction(L,cpp_pad_press); lua_setfield(L, -2, "press"); - lua_pushcfunction(L,cpp_pad_any); lua_setfield(L, -2, "any"); + lua_pushcfunction(L,wrappers::pad::down); lua_setfield(L, -2, "down"); + lua_pushcfunction(L,wrappers::pad::press); lua_setfield(L, -2, "press"); + lua_pushcfunction(L,wrappers::pad::any); lua_setfield(L, -2, "any"); //lua_setglobal(L, "gamepad"); //lua_newtable(L); - lua_pushinteger(L, -1); lua_setfield(L, -2, "INVALID"); - lua_pushinteger(L, 0); lua_setfield(L, -2, "A"); - lua_pushinteger(L, 1); lua_setfield(L, -2, "B"); - lua_pushinteger(L, 2); lua_setfield(L, -2, "X"); - lua_pushinteger(L, 3); lua_setfield(L, -2, "Y"); - lua_pushinteger(L, 4); lua_setfield(L, -2, "BACK"); - lua_pushinteger(L, 5); lua_setfield(L, -2, "GUIDE"); - lua_pushinteger(L, 6); lua_setfield(L, -2, "START"); - lua_pushinteger(L, 7); lua_setfield(L, -2, "LEFTSTICK"); - lua_pushinteger(L, 8); lua_setfield(L, -2, "RIGHTSTICK"); - lua_pushinteger(L, 9); lua_setfield(L, -2, "LEFTSHOULDER"); - lua_pushinteger(L, 10); lua_setfield(L, -2, "RIGHTSHOULDER"); - lua_pushinteger(L, 11); lua_setfield(L, -2, "UP"); - lua_pushinteger(L, 12); lua_setfield(L, -2, "DOWN"); - lua_pushinteger(L, 13); lua_setfield(L, -2, "LEFT"); - lua_pushinteger(L, 14); lua_setfield(L, -2, "RIGHT"); - lua_pushinteger(L, 15); lua_setfield(L, -2, "MISC1"); - lua_pushinteger(L, 16); lua_setfield(L, -2, "PADDLE1"); - lua_pushinteger(L, 17); lua_setfield(L, -2, "PADDLE2"); - lua_pushinteger(L, 18); lua_setfield(L, -2, "PADDLE3"); - lua_pushinteger(L, 19); lua_setfield(L, -2, "PADDLE4"); - lua_pushinteger(L, 20); lua_setfield(L, -2, "TOUCHPAD"); + lua_pushinteger(L, -1); lua_setfield(L, -2, "INVALID"); + lua_pushinteger(L, 0); lua_setfield(L, -2, "A"); + lua_pushinteger(L, 1); lua_setfield(L, -2, "B"); + lua_pushinteger(L, 2); lua_setfield(L, -2, "X"); + lua_pushinteger(L, 3); lua_setfield(L, -2, "Y"); + lua_pushinteger(L, 4); lua_setfield(L, -2, "BACK"); + lua_pushinteger(L, 5); lua_setfield(L, -2, "GUIDE"); + lua_pushinteger(L, 6); lua_setfield(L, -2, "START"); + lua_pushinteger(L, 7); lua_setfield(L, -2, "LEFTSTICK"); + lua_pushinteger(L, 8); lua_setfield(L, -2, "RIGHTSTICK"); + lua_pushinteger(L, 9); lua_setfield(L, -2, "LEFTSHOULDER"); + lua_pushinteger(L, 10); lua_setfield(L, -2, "RIGHTSHOULDER"); + lua_pushinteger(L, 11); lua_setfield(L, -2, "UP"); + lua_pushinteger(L, 12); lua_setfield(L, -2, "DOWN"); + lua_pushinteger(L, 13); lua_setfield(L, -2, "LEFT"); + lua_pushinteger(L, 14); lua_setfield(L, -2, "RIGHT"); + lua_pushinteger(L, 15); lua_setfield(L, -2, "MISC1"); + lua_pushinteger(L, 16); lua_setfield(L, -2, "PADDLE1"); + lua_pushinteger(L, 17); lua_setfield(L, -2, "PADDLE2"); + lua_pushinteger(L, 18); lua_setfield(L, -2, "PADDLE3"); + lua_pushinteger(L, 19); lua_setfield(L, -2, "PADDLE4"); + lua_pushinteger(L, 20); lua_setfield(L, -2, "TOUCHPAD"); lua_setglobal(L, "pad"); diff --git a/source/lua.h b/source/lua.h index 8ce7573..99347b8 100644 --- a/source/lua.h +++ b/source/lua.h @@ -4,7 +4,7 @@ namespace mini { namespace lua { - bool runnning(); + bool running(); void init(const char* main_lua_file = "main.lua"); void quit(); void cleanup(); diff --git a/source/main.cpp b/source/main.cpp index a763408..458e725 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -3,23 +3,25 @@ uint16_t ants = 0xc936; float t = 0; +using namespace mini; + void exception_loop() { //if (t==0) t= time(); - if (time()-t > 0.25) { - t = time(); - clip(); - origin(0,0); - setdest(0); - settrans(255); - setcolor(0,0xffffff00); - setcolor(1,0xff000000); - const int w=scrw(); - const int h=scrh(); + if (sys::time()-t > 0.25) { + t = sys::time(); + view::clip::reset(); + view::origin::set(0,0); + surf::target::set(0); + pal::trans::set(255); + pal::color::set(0,0xffffff00); + 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); - fillp(ants); + draw::pattern::set(ants); mini::draw::rect(0,0,w,h,0); mini::draw::rect(1,1,w-2,h-2,0); ants = (ants<<12) | (ants>>4); diff --git a/source/mini.cpp b/source/mini.cpp index b23c297..57abd5d 100644 --- a/source/mini.cpp +++ b/source/mini.cpp @@ -127,12 +127,13 @@ SDL_Gamepad *gamepad = NULL; int8_t pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID; #define MAX_SOUNDS 50 -JA_Music_t *music = NULL; JA_Sound_t *sounds[MAX_SOUNDS]; int16_t beats, num_beats = 0; void createNewProject(); +void createDisplay(); +void destroyDisplay(); void raisewindow() { SDL_RaiseWindow(mini_win); @@ -408,6 +409,31 @@ 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 = 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::surf::pixel::get(src_x, src_y); + mini::surf::pixel::subst_pset(x + xi, y + yi, c); + src_x++; + } + + src_y++; + } + } + void draw() { if (!map_surface || !source_surface) return; @@ -461,7 +487,7 @@ namespace mini for (int y = 0; y < celh; ++y) { int ty = sy + y * th; for (int x = 0; x < celw; ++x) { - uint8_t tile = mget(celx + x, cely + y); + uint8_t tile = tile::get(celx + x, cely + y); if (!tile) continue; int tx = sx + x * tw; tileblit(tile, tx - ox, ty - oy); @@ -495,6 +521,83 @@ namespace mini } + namespace pal + { + uint32_t *load(const char* filename, uint16_t *palsize) { + int size; + uint8_t *buffer = (uint8_t*)file_getfilebuffer(filename, size); + uint32_t *pal = 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; + } + } + } + + namespace view + { + namespace clip { + void set(int x, int y, int w, int h) { + ds::clip[0] = x; ds::clip[1] = y; ds::clip[2] = w-x-1; ds::clip[3] = h-y-1; + surf::target::recalculate_clip(); + } + + void reset() { + ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = dest_surface->w-1; ds::clip[3] = dest_surface->h-1; + surf::target::recalculate_clip(); + } + } + + namespace origin { + void set(int x, int y) { + ds::origin[0] = x; + ds::origin[1] = y; + } + + int getx() { + return ds::origin[0]; + } + + int gety() { + return ds::origin[1]; + } + } + } + namespace draw { // Bresenham Line Algorithm @@ -516,37 +619,37 @@ namespace mini dx <<= 1; while (x != x1) { - direct_pset(x, y, color); + surf::pixel::direct_pset(x, y, color); if (balance >= 0) { y += incy; balance -= dx; } balance += dy; x += incx; } - direct_pset(x, y, color); + surf::pixel::direct_pset(x, y, color); } else { dx <<= 1; balance = dx - dy; dy <<= 1; while (y != y1) { - direct_pset(x, y, color); + surf::pixel::direct_pset(x, y, color); if (balance >= 0) { x += incx; balance -= dy; } balance += dx; y += incy; } - direct_pset(x, y, color); + surf::pixel::direct_pset(x, y, color); } } void hline(int x0, int y, int x1, uint8_t color) { color = ds::draw_palette[color]; if (x0>x1) { const int tmp=x0;x0=x1;x1=tmp; } - for (int x=x0; x<=x1; ++x) direct_pset(x, y, color); + for (int x=x0; x<=x1; ++x) surf::pixel::direct_pset(x, y, color); } void vline(int x, int y0, int y1, uint8_t color) { color = ds::draw_palette[color]; if (y0>y1) { const int tmp=y0;y0=y1;y1=tmp; } - for (int y=y0; y<=y1; ++y) direct_pset(x, y, color); + for (int y=y0; y<=y1; ++y) surf::pixel::direct_pset(x, y, color); } void rect(int x, int y, int w, int h, uint8_t color) { @@ -565,14 +668,14 @@ namespace mini } static inline void circ_scanline(int xc, int yc, int x, int y, uint8_t color) { - direct_pset(xc+x, yc+y, color); - direct_pset(xc-x, yc+y, color); - direct_pset(xc+x, yc-y, color); - direct_pset(xc-x, yc-y, color); - direct_pset(xc+y, yc+x, color); - direct_pset(xc-y, yc+x, color); - direct_pset(xc+y, yc-x, color); - direct_pset(xc-y, yc-x, color); + surf::pixel::direct_pset(xc+x, yc+y, color); + surf::pixel::direct_pset(xc-x, yc+y, color); + surf::pixel::direct_pset(xc+x, yc-y, color); + surf::pixel::direct_pset(xc-x, yc-y, color); + surf::pixel::direct_pset(xc+y, yc+x, color); + surf::pixel::direct_pset(xc-y, yc+x, color); + surf::pixel::direct_pset(xc+y, yc-x, color); + surf::pixel::direct_pset(xc-y, yc-x, color); } void circ(int x, int y, uint8_t r, uint8_t color) { @@ -603,7 +706,6 @@ namespace mini } } - void roundrect(int x, int y, int w, int h, uint8_t r, uint8_t color) { int xi=0, yi=r; int d=3-2*r; @@ -620,14 +722,14 @@ namespace mini color = ds::draw_palette[color]; while (yi>=xi++) { d += d>0 ? 4*(xi-yi--)+10 : 4*xi+6; - direct_pset(x2+xi, y2+yi, color); - direct_pset(x1-xi, y2+yi, color); - direct_pset(x2+xi, y1-yi, color); - direct_pset(x1-xi, y1-yi, color); - direct_pset(x2+yi, y2+xi, color); - direct_pset(x1-yi, y2+xi, color); - direct_pset(x2+yi, y1-xi, color); - direct_pset(x1-yi, y1-xi, color); + surf::pixel::direct_pset(x2+xi, y2+yi, color); + surf::pixel::direct_pset(x1-xi, y2+yi, color); + surf::pixel::direct_pset(x2+xi, y1-yi, color); + surf::pixel::direct_pset(x1-xi, y1-yi, color); + surf::pixel::direct_pset(x2+yi, y2+xi, color); + surf::pixel::direct_pset(x1-yi, y2+xi, color); + surf::pixel::direct_pset(x2+yi, y1-xi, color); + surf::pixel::direct_pset(x1-yi, y1-xi, color); } } @@ -651,14 +753,14 @@ namespace mini } void oval_scanline(int xc, int yc, int x, int y, float xf, float yf, uint8_t color) { - direct_pset((xc+x)*xf, (yc+y)*yf, color); - direct_pset((xc-x)*xf, (yc+y)*yf, color); - direct_pset((xc+x)*xf, (yc-y)*yf, color); - direct_pset((xc-x)*xf, (yc-y)*yf, color); - direct_pset((xc+y)*xf, (yc+x)*yf, color); - direct_pset((xc-y)*xf, (yc+x)*yf, color); - direct_pset((xc+y)*xf, (yc-x)*yf, color); - direct_pset((xc-y)*xf, (yc-x)*yf, color); + surf::pixel::direct_pset((xc+x)*xf, (yc+y)*yf, color); + surf::pixel::direct_pset((xc-x)*xf, (yc+y)*yf, color); + surf::pixel::direct_pset((xc+x)*xf, (yc-y)*yf, color); + surf::pixel::direct_pset((xc-x)*xf, (yc-y)*yf, color); + surf::pixel::direct_pset((xc+y)*xf, (yc+x)*yf, color); + surf::pixel::direct_pset((xc-y)*xf, (yc+x)*yf, color); + surf::pixel::direct_pset((xc+y)*xf, (yc-x)*yf, color); + surf::pixel::direct_pset((xc-y)*xf, (yc-x)*yf, color); } void oval(int x0, int y0, int x1, int y1, uint8_t color) { @@ -703,149 +805,620 @@ namespace mini } } + namespace pattern { + void set(uint16_t pat, bool transparent) { + ds::fill_pattern = pat; + } + } + + void surf(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; + + // 16.16 fixed point + int sdx = (sw << 16) / dw; + int sdy = (sh << 16) / dh; + + if (flip_x) sdx = -sdx; + if (flip_y) sdy = -sdy; + + int ssx = flip_x ? ((sx + sw - 1) << 16) : (sx << 16); + int ssy = flip_y ? ((sy + sh - 1) << 16) : (sy << 16); + + int csy = ssy; + + if (!invert) { + for (int y = dy; y < dy + dh; ++y) { + int csx = ssx; + for (int x = dx; x < dx + dw; ++x) { + uint8_t color = surf::pixel::get(csx >> 16, csy >> 16); + surf::pixel::subst_pset(x, y, color); + csx += sdx; + } + csy += sdy; + } + } else { + for (int y = dy; y < dy + dh; ++y) { + int csx = ssx; + for (int x = dx; x < dx + dw; ++x) { + uint8_t color = surf::pixel::get(csy >> 16, csx >> 16); + surf::pixel::subst_pset(x, y, color); + csx += sdx; + } + csy += sdy; + } + } + } + + 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) { + if (dw == 0) dw = sw; + if (dh == 0) dh = sh; + + // Centro del destino (rectángulo sin rotar) + float dcx = dx + dw * 0.5f; + float dcy = dy + dh * 0.5f; + + // Centro del subrectángulo origen + float scx = sx + sw * 0.5f; + float scy = sy + sh * 0.5f; + + // Escalado destino -> origen + float inv_scale_x = float(sw) / float(dw); + float inv_scale_y = float(sh) / float(dh); + + // Flips integrados en la escala + if (flip_x) inv_scale_x = -inv_scale_x; + if (flip_y) inv_scale_y = -inv_scale_y; + + // Ángulo en radianes + float a = angle_deg * 3.14159265f / 180.0f; + float ca = SDL_cosf(a); + float sa = SDL_sinf(a); + + // --- 1. Bounding box rotado del rectángulo destino --- + + float hx = dw * 0.5f; + float hy = dh * 0.5f; + + float vx[4] = { -hx, hx, -hx, hx }; + float vy[4] = { -hy, -hy, hy, hy }; + + float min_x = 1e9f, max_x = -1e9f; + float min_y = 1e9f, max_y = -1e9f; + + for (int i = 0; i < 4; ++i) { + float rr_x = vx[i] * ca - vy[i] * sa; + float rr_y = vx[i] * sa + vy[i] * ca; + + float dxp = dcx + rr_x; + float dyp = dcy + rr_y; + + if (dxp < min_x) min_x = dxp; + if (dxp > max_x) max_x = dxp; + if (dyp < min_y) min_y = dyp; + if (dyp > max_y) max_y = dyp; + } + + int bb_x0 = (int)SDL_floorf(min_x); + int bb_x1 = (int)SDL_ceilf (max_x); + int bb_y0 = (int)SDL_floorf(min_y); + int bb_y1 = (int)SDL_ceilf (max_y); + + // --- 2. Rotación inversa + escalado + clipping estricto --- + + for (int y = bb_y0; y <= bb_y1; ++y) { + for (int x = bb_x0; x <= bb_x1; ++x) { + + // Coordenadas relativas al centro destino + float rx = x - dcx; + float ry = y - dcy; + + // Rotación inversa + float ux = rx * ca + ry * sa; + float uy = -rx * sa + ry * ca; + + // Escalado destino -> origen (con flips) + float sxp = scx + ux * inv_scale_x; + float syp = scy + uy * inv_scale_y; + + // Clipping estricto al subrectángulo origen + if (sxp < sx || sxp >= sx + sw || + syp < sy || syp >= sy + sh) + continue; // no pintamos nada + + uint8_t color = surf::pixel::get((int)sxp, (int)syp); + surf::pixel::subst_pset(x, y, color); + } + } + } + + const uint8_t printchar(uint8_t c, int x, int y) { + char_t &chr = current_font->chars[c]; + draw::surf(chr.x, chr.y, chr.w, chr.h, x, y-chr.base); + return chr.w; + } + + void text(const char* str, int x, int y, uint8_t color) { + + const unsigned char* p = (const unsigned char*)str; + uint8_t cp; + uint8_t xpos = x; + + uint8_t old_source = surf::source::get(); + surf::source::set(current_font->surface); + uint8_t old_color = ds::draw_palette[1]; + ds::draw_palette[1] = color; + uint8_t old_trans = ds::trans; + ds::trans = 0; + while (p[0]!=0) { + if (p[0] < 0x80) { + cp = p[0]; + p+=1; + } else if ((p[0] & 0xE0) == 0xC0) { + cp = (p[0] << 6) | (p[1] & 0x3F); + p+=2; + } + xpos += printchar(cp, xpos, y) + current_font->spacing; + } + ds::trans = old_trans; + ds::draw_palette[1] = old_color; + surf::source::set(old_source); + } + namespace mode { void set(uint8_t mode) { ds::mode = mode; } } } -} -void initaudio() { - JA_Init(48000, SDL_AUDIO_S16, 1); - for (int i=0;i 0 && line[len - 1] == '\r') line[len - 1] = '\0'; + char *fshaderfile = nullptr; + if (fshader) { fshaderfile = file_getfilebuffer(fshader, filesize, true); } + init(mini_win, mini_shadertex, vshaderfile, fshaderfile); + } - if (strncmp(line, "bitmap=", 7) != 0) return false; // Parse first line - - fonts[index].surface = loadsurf(line + 7); - - fonts[index].name = (char*)malloc(strlen(name)+1); - strcpy(fonts[index].name, name); + //void enable() { shader::enable(); } + //void disable() { shader::disable(); } } - // --- Read character lines --- - while (*ptr) { - // Extract next line - int len = 0; - while (ptr[len] && ptr[len] != '\n' && len < 255) len++; + namespace audio + { + JA_Music_t *current_music = NULL; - memcpy(line, ptr, len); - line[len] = '\0'; - ptr += (ptr[len] == '\n') ? len + 1 : len; // Advance pointer - if (len > 0 && line[len - 1] == '\r') line[len - 1] = '\0'; + void init() { + JA_Init(48000, SDL_AUDIO_S16, 1); + for (int i=0;i= 0 && code < 256) { - fonts[index].chars[code] = { (uint8_t)x, (uint8_t)y, (uint8_t)w, (uint8_t)h, (uint8_t)base }; + namespace music + { + void play(const char *filename, const int loop) { + int size; + char *buffer = file_getfilebuffer(filename, size); + if (current_music != NULL) JA_DeleteMusic(current_music); + current_music = JA_LoadMusic((Uint8*)buffer, size); + JA_PlayMusic(current_music, loop); + } + + void pause() { + JA_PauseMusic(); + } + + void resume() { + JA_ResumeMusic(); + } + + void stop(const int t) { + JA_StopMusic(); + } + + namespace pos { + void set(float value) + { + JA_SetMusicPosition(value); + } + + float get() + { + return JA_GetMusicPosition(); + } + } + + namespace enable { + void set(const bool value) + { + JA_EnableMusic(value); + file_setconfigvalue("music", value?"true":"false"); + } + + const bool get() + { + return JA_IsMusicEnabled(); + } + } + } + + namespace sound + { + int load(const char *filename) { + int size; + char *buffer = file_getfilebuffer(filename, size); + int i=0; + while (i 0 && line[len - 1] == '\r') line[len - 1] = '\0'; + + if (strncmp(line, "bitmap=", 7) != 0) return false; // Parse first line + + fonts[index].surface = surf::load(line + 7); + + fonts[index].name = (char*)malloc(strlen(name)+1); + strcpy(fonts[index].name, name); + } + + // --- Read character lines --- + while (*ptr) { + // Extract next line + int len = 0; + while (ptr[len] && ptr[len] != '\n' && len < 255) len++; + + memcpy(line, ptr, len); + line[len] = '\0'; + ptr += (ptr[len] == '\n') ? len + 1 : len; // Advance pointer + if (len > 0 && line[len - 1] == '\r') line[len - 1] = '\0'; + + // Remove comments + char* hash = strchr(line, '#'); + if (hash) *hash = '\0'; + + // Parse + int code, x, y, w, h, base; + if (sscanf(line, "%d: %d %d %d %d %d", &code, &x, &y, &w, &h, &base) == 6) { + if (code >= 0 && code < 256) { + fonts[index].chars[code] = { (uint8_t)x, (uint8_t)y, (uint8_t)w, (uint8_t)h, (uint8_t)base }; + } + } + } + return index; + } + + uint8_t load(const char *filename) { + // Si la font ja s'ha carregat, tornem eixa font + for (unsigned int i=0; ispacing = spacing; + } + uint8_t get() { + return current_font->spacing; + } + } } - loadfont_from_buffer(buffer, i, filename); - free(buffer); - - log_msg(LOG_INFO, "Arxiu '%s' carregat en font: %i.\n", filename, i); - return i; + namespace mouse + { + int posx() { + return mouse_x-ds::origin[0]; + } + + int posy() { + return mouse_y-ds::origin[1]; + } + + int wheel() { + return mouse_wheel; + } + + bool down(uint8_t i) { + if (mouse_discard) return false; + return mouse_buttons & SDL_BUTTON_MASK(i); + } + + bool press(uint8_t i) { + return mouse_just_pressed == i; + } + + bool dblclick() { + return double_click; + } + + void discard() { + mouse_discard = true; + } + + bool inside(int x, int y, int w, int h) { + const int mx = mouse_x-ds::origin[0]; + const int my = mouse_y-ds::origin[1]; + return (mx>=x) && (my>=y) && (mxspacing; -} - -void setfontspacing(uint8_t spacing) { - current_font->spacing = spacing; -} void createDisplay() { if (screen_zoom <= 0) screen_zoom = 1; @@ -868,7 +1441,7 @@ void createDisplay() { } mini_shadertex = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, screen_width*screen_zoom, screen_height*screen_zoom); SDL_SetTextureScaleMode(mini_shadertex, SDL_SCALEMODE_NEAREST); - shader::init(mini_win, mini_shadertex, nullptr); + mini::shader::init(mini_win, mini_shadertex, nullptr); log_msg(LOG_OK, "Graphics subsystem initialized\n"); } @@ -880,21 +1453,18 @@ void destroyDisplay() { SDL_DestroyWindow(mini_win); } -void initGamePad() { - int num_joysticks; - SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks); - if (joysticks) { - for (int i=0; i13) { dt = SDL_GetTicks(); - if (mini::lua::runnning()) { + if (mini::lua::running()) { delta_time = float(SDL_GetTicks() - last_update)/1000.0f; last_update = SDL_GetTicks(); @@ -1073,7 +1643,7 @@ int main(int argc,char*argv[]){ SDL_UnlockTexture(mini_bak); SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL); //NEW - shader::render(); + mini::shader::render(); //SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL); //SDL_RenderPresent(mini_ren); @@ -1085,11 +1655,11 @@ int main(int argc,char*argv[]){ } } mini::lua::quit(); - quitaudio(); + mini::audio::quit(); //Mix_Quit(); - for (unsigned int i=0;ichars[c]; - blit(chr.x, chr.y, chr.w, chr.h, x, y-chr.base); - return chr.w; -} - -void print(const char* str, int x, int y, uint8_t color) { - - const unsigned char* p = (const unsigned char*)str; - uint8_t cp; - uint8_t xpos = x; - - uint8_t old_source = getsource(); - setsource(current_font->surface); - uint8_t old_color = ds::draw_palette[1]; - ds::draw_palette[1] = color; - uint8_t old_trans = ds::trans; - ds::trans = 0; - while (p[0]!=0) { - if (p[0] < 0x80) { - cp = p[0]; - p+=1; - } else if ((p[0] & 0xE0) == 0xC0) { - cp = (p[0] << 6) | (p[1] & 0x3F); - p+=2; - } - xpos += printchar(cp, xpos, y) + current_font->spacing; - } - ds::trans = old_trans; - ds::draw_palette[1] = old_color; - setsource(old_source); -} - -void clip(int x, int y, int w, int h) { - ds::clip[0] = x; ds::clip[1] = y; ds::clip[2] = w-x-1; ds::clip[3] = h-y-1; - recalculate_clip(); -} - -void clip() { - ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = dest_surface->w-1; ds::clip[3] = dest_surface->h-1; - recalculate_clip(); -} - -void origin(int x, int y) { - ds::origin[0] = x; - ds::origin[1] = y; -} - -int camx() { - return ds::origin[0]; -} - -int camy() { - return ds::origin[1]; -} - - -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 = 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 = sget(src_x, src_y); - subst_pset(x + xi, y + yi, c); - src_x++; - } - - src_y++; - } -} - -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; - - // 16.16 fixed point - int sdx = (sw << 16) / dw; - int sdy = (sh << 16) / dh; - - if (flip_x) sdx = -sdx; - if (flip_y) sdy = -sdy; - - int ssx = flip_x ? ((sx + sw - 1) << 16) : (sx << 16); - int ssy = flip_y ? ((sy + sh - 1) << 16) : (sy << 16); - - int csy = ssy; - - if (!invert) { - for (int y = dy; y < dy + dh; ++y) { - int csx = ssx; - for (int x = dx; x < dx + dw; ++x) { - uint8_t color = sget(csx >> 16, csy >> 16); - subst_pset(x, y, color); - csx += sdx; - } - csy += sdy; - } - } else { - for (int y = dy; y < dy + dh; ++y) { - int csx = ssx; - for (int x = dx; x < dx + dw; ++x) { - uint8_t color = sget(csy >> 16, csx >> 16); - subst_pset(x, y, color); - csx += sdx; - } - csy += sdy; - } - } -} - -void blit_r(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) -{ - if (dw == 0) dw = sw; - if (dh == 0) dh = sh; - - // Centro del destino (rectángulo sin rotar) - float dcx = dx + dw * 0.5f; - float dcy = dy + dh * 0.5f; - - // Centro del subrectángulo origen - float scx = sx + sw * 0.5f; - float scy = sy + sh * 0.5f; - - // Escalado destino -> origen - float inv_scale_x = float(sw) / float(dw); - float inv_scale_y = float(sh) / float(dh); - - // Flips integrados en la escala - if (flip_x) inv_scale_x = -inv_scale_x; - if (flip_y) inv_scale_y = -inv_scale_y; - - // Ángulo en radianes - float a = angle_deg * 3.14159265f / 180.0f; - float ca = SDL_cosf(a); - float sa = SDL_sinf(a); - - // --- 1. Bounding box rotado del rectángulo destino --- - - float hx = dw * 0.5f; - float hy = dh * 0.5f; - - float vx[4] = { -hx, hx, -hx, hx }; - float vy[4] = { -hy, -hy, hy, hy }; - - float min_x = 1e9f, max_x = -1e9f; - float min_y = 1e9f, max_y = -1e9f; - - for (int i = 0; i < 4; ++i) { - float rr_x = vx[i] * ca - vy[i] * sa; - float rr_y = vx[i] * sa + vy[i] * ca; - - float dxp = dcx + rr_x; - float dyp = dcy + rr_y; - - if (dxp < min_x) min_x = dxp; - if (dxp > max_x) max_x = dxp; - if (dyp < min_y) min_y = dyp; - if (dyp > max_y) max_y = dyp; - } - - int bb_x0 = (int)SDL_floorf(min_x); - int bb_x1 = (int)SDL_ceilf (max_x); - int bb_y0 = (int)SDL_floorf(min_y); - int bb_y1 = (int)SDL_ceilf (max_y); - - // --- 2. Rotación inversa + escalado + clipping estricto --- - - for (int y = bb_y0; y <= bb_y1; ++y) { - for (int x = bb_x0; x <= bb_x1; ++x) { - - // Coordenadas relativas al centro destino - float rx = x - dcx; - float ry = y - dcy; - - // Rotación inversa - float ux = rx * ca + ry * sa; - float uy = -rx * sa + ry * ca; - - // Escalado destino -> origen (con flips) - float sxp = scx + ux * inv_scale_x; - float syp = scy + uy * inv_scale_y; - - // Clipping estricto al subrectángulo origen - if (sxp < sx || sxp >= sx + sw || - syp < sy || syp >= sy + sh) - continue; // no pintamos nada - - uint8_t color = sget((int)sxp, (int)syp); - subst_pset(x, y, color); - } - } -} - - -bool btn(uint8_t i) { - return keys[i]; -} - -int wbtnp() { - return key_just_pressed; -} - -bool btnp(uint8_t i) { - if (key_just_pressed == i) { - key_just_pressed=0; - return true; - } else { - return false; - } -} - -bool anykey() { - const bool something_pressed = (key_just_pressed != 0) || (pad_just_pressed != -1); - key_just_pressed=0; - pad_just_pressed=-1; - return something_pressed; -} - -void textenable(const bool enable) { - if (enable) - SDL_StartTextInput(mini_win); - else - SDL_StopTextInput(mini_win); -} - -const char* textinput() { - return has_text_input ? text_input_buffer : nullptr; -} - -bool pad(int8_t i) { - if (!gamepad) return false; - return SDL_GetGamepadButton(gamepad, SDL_GamepadButton(i)) == 1; -} - -bool padp(int8_t i) { - if (pad_just_pressed == i) { - pad_just_pressed=-1; - return true; - } else { - return false; - } -} - -int wpad() { - return pad_just_pressed; -} - -int mousex() { - return mouse_x-ds::origin[0]; -} - -int mousey() { - return mouse_y-ds::origin[1]; -} - -int mwheel() { - return mouse_wheel; -} - -bool mbtn(uint8_t i) { - if (mouse_discard) return false; - return mouse_buttons & SDL_BUTTON_MASK(i); -} - -bool mbtnp(uint8_t i) { - return mouse_just_pressed == i; -} - -bool doubleclick() { - return double_click; -} - -void mdiscard() { - mouse_discard = true; -} - -bool minside(int x, int y, int w, int h) { - const int mx = mouse_x-ds::origin[0]; - const int my = mouse_y-ds::origin[1]; - return (mx>=x) && (my>=y) && (mx - #include "version.h" - - void exception_loop(); -int scrw(); -int scrh(); - void raisewindow(); namespace mini @@ -59,33 +52,40 @@ namespace mini uint8_t geth(); void set(int w, int h); } - } -} + namespace pal + { + uint32_t *load(const char* filename, uint16_t *palsize=NULL); + 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(); + } + } -void shader_init(const char* vshader, const char* fshader); -void shader_enable(); -void shader_disable(); + namespace view + { + namespace clip { + void set(int x, int y, int w, int h); + void reset(); + } -uint8_t loadfont(const char *filename); -uint8_t getfont(); -void setfont(uint8_t font); -uint8_t getfontspacing(); -void setfontspacing(uint8_t spacing); + namespace origin { + void set(int x, int y); + int getx(); + int gety(); + } + } - -uint32_t *loadpal(const char* filename, uint16_t *palsize=NULL); -void setpal(uint32_t *pal); -void setcolor(uint8_t index, uint32_t color); -uint32_t getcolor(uint8_t index); -void settrans(uint8_t index); -uint8_t gettrans(); -uint8_t subpal(uint8_t index, uint8_t color); -void reset_subpal(); - -namespace mini -{ namespace draw { void line(int x0, int y0, int x1, int y1, uint8_t color); @@ -103,84 +103,150 @@ namespace mini void oval(int x0, int y0, int x1, int y1, uint8_t color); void ovalf(int x0, int y0, int x1, int y1, uint8_t color); + namespace pattern { + void set(uint16_t pat, bool transparent = false); + } + + 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 text(const char *str, int x, int y, uint8_t color); + namespace mode { void set(uint8_t mode); } } + + namespace shader + { + void init(const char* vshader, const char* fshader); + void enable(); + void disable(); + } + + namespace audio + { + namespace music + { + void play(const char *filename, const int loop=-1); + void pause(); + void resume(); + void stop(const int t=1000); + namespace pos { + void set(float value); + float get(); + } + namespace enable { + void set(const bool value); + const bool get(); + } + } + + namespace sound + { + int load(const char *filename); + void free(int soundfile); + int play(int soundfile, const int volume=-1); + void stop(int soundchannel); + namespace enable { + void set(const bool value); + const bool get(); + } + } + } + + namespace sys + { + float delta(); + float time(); + bool beat(int16_t i); + + int getfps(); + + namespace update { + void set(const int value, const int t=0); + int get(); + } + + void exit(); + } + + namespace win + { + namespace zoom { + void set(const int value); + int get(); + } + + namespace fullscreen { + void set(const bool value); + bool get(); + } + + namespace cursor { + void set(const bool value); + bool get(); + } + + namespace res { + void set(const int w, const int h); + int getw(); + int geth(); + } + } + + namespace config + { + namespace key { + void set(const char* key, const char* value); + const char *get(const char* key); + } + + const char *folder(); + } + + namespace font + { + uint8_t load(const char *filename); + + namespace current { + void set(uint8_t font); + uint8_t get(); + } + + namespace spacing { + void set(uint8_t spacing); + uint8_t get(); + } + } + + namespace mouse + { + int posx(); + int posy(); + int wheel(); + bool down(uint8_t i); + bool press(uint8_t i); + bool dblclick(); + void discard(); + bool inside(int x, int y, int w, int h); + } + + namespace key + { + bool down(uint8_t i); + bool press(uint8_t i); + int press(); + bool any(); + void text(const bool enable); + const char *utf8char(); + } + + namespace pad + { + bool down(int8_t i); + bool press(int8_t i); + int press(); + } } - - -void fillp(uint16_t pat, bool transparent = false); - -void print(const char *str, int x, int y, uint8_t color); - -void clip(int x, int y, int w, int h); -void clip(); -void origin(int x, int y); -int camx(); -int camy(); - -uint8_t sget(int x, int y); - -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 dx, int dy, int dw, int dh, bool flip_x, bool flip_y, float angle_deg); - -bool btn(uint8_t i); -int wbtnp(); -bool btnp(uint8_t i); -bool anykey(); -void textenable(const bool enable); -const char *textinput(); - -bool pad(int8_t i); -bool padp(int8_t i); -int wpad(); - -int mousex(); -int mousey(); -int mwheel(); -bool mbtn(uint8_t i); -bool mbtnp(uint8_t i); -bool doubleclick(); -void mdiscard(); -bool minside(int x, int y, int w, int h); - -float time(); -float delta(); -bool beat(int16_t i); - -int getfps(); - -void playmusic(const char *filename, const int loop=-1); -void pausemusic(); -void resumemusic(); -void stopmusic(const int t=1000); -void musicpos(float value); -float musicpos(); -void enablemusic(const bool value); -const bool ismusicenabled(); - -int loadsound(const char *filename); -void freesound(int soundfile); -int playsound(int soundfile, const int volume=-1); -void stopsound(int soundchannel); -void enablesound(const bool value); -const bool issoundenabled(); - -int getzoom(); -void setzoom(const int value); -void setres(const int w, const int h); -bool getfullscreen(); -void setfullscreen(const bool value); -bool getcursor(); -void setcursor(const bool value); - -const char *getconfig(const char* key); -void setconfig(const char* key, const char* value); -const char *configfolder(); - -void setupdatemode(const int value, const int t=0); -int getupdatemode(); - -void exit();