From b0e489a979051a20b537d88d8aac308cf7c24223 Mon Sep 17 00:00:00 2001 From: Kelvin Shadewing Date: Thu, 26 Oct 2023 23:39:50 -0400 Subject: [PATCH] Add deleteTexture --- rte/src/api/graphics.cpp | 24 +++++++++ rte/src/api/graphics.hpp | 3 ++ rte/src/brux/global.cpp | 2 +- rte/src/brux/graphics.cpp | 2 +- rte/src/brux/main.cpp | 8 +-- rte/src/squirrel/wrapper.cpp | 96 ++++++++++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 6 deletions(-) diff --git a/rte/src/api/graphics.cpp b/rte/src/api/graphics.cpp index c755f86..1547ba2 100644 --- a/rte/src/api/graphics.cpp +++ b/rte/src/api/graphics.cpp @@ -191,6 +191,10 @@ int findTexture(const std::string& name) { return 0; } +void deleteTexture(int tex) { + xyDeleteImage(tex); +} + std::string getTextureName(int texture) { if (texture > 0 && texture < vcTextureNames.size()) { return vcTextureNames[texture]; @@ -199,6 +203,26 @@ std::string getTextureName(int texture) { return ""; } +int getTextureFilter(int tex) { + SDL_ScaleMode sm = (SDL_ScaleMode)0; + + if(tex > 0 && tex < vcTextures.size() && vcTextures[tex] != 0) + SDL_GetTextureScaleMode(vcTextures[tex], &sm); + else + xyPrint("WARNING: Texture not found!"); + + return (int)sm; +} + +void setTextureFilter(int tex, int filter) { + SDL_ScaleMode sm = (SDL_ScaleMode)min(max(filter, 0), 2); + + if(tex > 0 && tex < vcTextures.size() && vcTextures[tex] != 0) + SDL_SetTextureScaleMode(vcTextures[tex], sm); + else + xyPrint("WARNING: Texture not found!"); +} + void printTextureNames() { for (int i = 0; i < vcTextureNames.size(); i++) { xyPrint("%d - %s", i, vcTextureNames[i].c_str()); diff --git a/rte/src/api/graphics.hpp b/rte/src/api/graphics.hpp index 62c0971..0866b8e 100644 --- a/rte/src/api/graphics.hpp +++ b/rte/src/api/graphics.hpp @@ -51,7 +51,10 @@ int windowH(); int newTexture(int w, int h); // Doc'd void textureSetBlendMode(int texture, int blend); // Doc'd int findTexture(const std::string& name); +void deleteTexture(int tex); std::string getTextureName(int texture); +int getTextureFilter(int tex); +void setTextureFilter(int tex, int filter); void printTextureNames(); } // namespace BruxAPI diff --git a/rte/src/brux/global.cpp b/rte/src/brux/global.cpp index 37ef40e..d82e619 100644 --- a/rte/src/brux/global.cpp +++ b/rte/src/brux/global.cpp @@ -81,7 +81,7 @@ Uint32 gvFrames = 0; // Brux version string -const char *gvVNo = "v0.3.5"; +const char *gvVNo = "v0.3.6"; // Should it clear the screen? If true, then the answer is yes. diff --git a/rte/src/brux/graphics.cpp b/rte/src/brux/graphics.cpp index 3d55ed1..df917f3 100644 --- a/rte/src/brux/graphics.cpp +++ b/rte/src/brux/graphics.cpp @@ -466,7 +466,7 @@ Uint32 xyNewTexture(Uint32 w, Uint32 h) { // Return the texture index - vcTextureNames.push_back("new-texture-" + std::to_string(vcTextures.size() - 1)); + vcTextureNames.push_back("new-texture-" + std::to_string(vcTextures.size())); vcTextures.push_back(nimg); return vcTextures.size() - 1; diff --git a/rte/src/brux/main.cpp b/rte/src/brux/main.cpp index b5d7b98..3057629 100644 --- a/rte/src/brux/main.cpp +++ b/rte/src/brux/main.cpp @@ -134,10 +134,10 @@ int main(int argc, char* argv[]) { // Handle situations where a main file can't be found - if (!shouldLoad) { - puts("ERROR: Unable to load the main file. Make sure that it exists."); - return 1; - } + // if (!shouldLoad) { + // puts("ERROR: Unable to load the main file. Make sure that it exists."); + // return 1; + // } // Initialize everything diff --git a/rte/src/squirrel/wrapper.cpp b/rte/src/squirrel/wrapper.cpp index 1a34405..d8b9948 100644 --- a/rte/src/squirrel/wrapper.cpp +++ b/rte/src/squirrel/wrapper.cpp @@ -1508,6 +1508,29 @@ static SQInteger findTexture_wrapper(HSQUIRRELVM vm) } +static SQInteger deleteTexture_wrapper(HSQUIRRELVM vm) +{ + SQInteger arg0; + if(SQ_FAILED(sq_getinteger(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not an integer")); + return SQ_ERROR; + } + + try { + BruxAPI::deleteTexture(static_cast (arg0)); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'deleteTexture'")); + return SQ_ERROR; + } + +} + static SQInteger getTextureName_wrapper(HSQUIRRELVM vm) { SQInteger arg0; @@ -1533,6 +1556,58 @@ static SQInteger getTextureName_wrapper(HSQUIRRELVM vm) } +static SQInteger getTextureFilter_wrapper(HSQUIRRELVM vm) +{ + SQInteger arg0; + if(SQ_FAILED(sq_getinteger(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not an integer")); + return SQ_ERROR; + } + + try { + int return_value = BruxAPI::getTextureFilter(static_cast (arg0)); + + sq_pushinteger(vm, return_value); + return 1; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'getTextureFilter'")); + return SQ_ERROR; + } + +} + +static SQInteger setTextureFilter_wrapper(HSQUIRRELVM vm) +{ + SQInteger arg0; + if(SQ_FAILED(sq_getinteger(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not an integer")); + return SQ_ERROR; + } + SQInteger arg1; + if(SQ_FAILED(sq_getinteger(vm, 3, &arg1))) { + sq_throwerror(vm, _SC("Argument 2 not an integer")); + return SQ_ERROR; + } + + try { + BruxAPI::setTextureFilter(static_cast (arg0), static_cast (arg1)); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'setTextureFilter'")); + return SQ_ERROR; + } + +} + static SQInteger printTextureNames_wrapper(HSQUIRRELVM vm) { (void) vm; @@ -4536,6 +4611,13 @@ void register_brux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'findTexture'"); } + sq_pushstring(v, "deleteTexture", -1); + sq_newclosure(v, &deleteTexture_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".b|n"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'deleteTexture'"); + } + sq_pushstring(v, "getTextureName", -1); sq_newclosure(v, &getTextureName_wrapper, 0); sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".b|n"); @@ -4543,6 +4625,20 @@ void register_brux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'getTextureName'"); } + sq_pushstring(v, "getTextureFilter", -1); + sq_newclosure(v, &getTextureFilter_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".b|n"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'getTextureFilter'"); + } + + sq_pushstring(v, "setTextureFilter", -1); + sq_newclosure(v, &setTextureFilter_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".b|nb|n"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'setTextureFilter'"); + } + sq_pushstring(v, "printTextureNames", -1); sq_newclosure(v, &printTextureNames_wrapper, 0); sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".");