From c5eecff13133bc20987ddc0a52bf133f4dd83d06 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Wed, 23 Jan 2013 16:48:21 -0500 Subject: fix "i" argument to graphics functions. Also, they don't overwrite the default one, you can pass in nil to tpt.element/graphics_func for the function to restore the original. diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index 5492e2e..506c910 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -671,16 +671,29 @@ int luatpt_element_func(lua_State *l) return luaL_error(l, "Invalid element"); } } + else if(lua_isnil(l, 1)) + { + int element = luaL_optint(l, 2, 0); + if(element > 0 && element < PT_NUM) + { + lua_el_func[element] = 0; + lua_el_mode[element] = 0; + } + else + { + return luaL_error(l, "Invalid element"); + } + } else return luaL_error(l, "Not a function"); return 0; } -int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS) +int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS, int i) { int cache = 0, callret; lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, lua_gr_func[cpart->type]); - lua_pushinteger(luacon_ci->l, 0); + lua_pushinteger(luacon_ci->l, i); lua_pushinteger(luacon_ci->l, *colr); lua_pushinteger(luacon_ci->l, *colg); lua_pushinteger(luacon_ci->l, *colb); @@ -715,7 +728,20 @@ int luatpt_graphics_func(lua_State *l) { lua_gr_func[element] = function; luacon_ren->graphicscache[element].isready = 0; - luacon_sim->elements[element].Graphics = &luacon_graphicsReplacement; + return 0; + } + else + { + return luaL_error(l, "Invalid element"); + } + } + else if (lua_isnil(l, 1)) + { + int element = luaL_optint(l, 2, 0); + if(element > 0 && element < PT_NUM) + { + lua_gr_func[element] = 0; + luacon_ren->graphicscache[element].isready = 0; return 0; } else diff --git a/src/cat/LuaScriptHelper.h b/src/cat/LuaScriptHelper.h index b55329f..39be806 100644 --- a/src/cat/LuaScriptHelper.h +++ b/src/cat/LuaScriptHelper.h @@ -55,7 +55,7 @@ int luacon_element_getproperty(char * key, int * format, unsigned int * modified int luatpt_test(lua_State* l); int luatpt_getelement(lua_State *l); -int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS); +int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS, int i); int luatpt_graphics_func(lua_State *l); int luacon_elementReplacement(UPDATE_FUNC_ARGS); diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index d24dc85..e4bf3c2 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -315,6 +315,7 @@ tpt.partsdata = nil"); for(i = 0; i < PT_NUM; i++) { lua_el_mode[i] = 0; + lua_gr_func[i] = 0; } } @@ -1163,7 +1164,6 @@ int LuaScriptInterface::elements_element(lua_State * l) if(lua_type(l, -1) == LUA_TFUNCTION) { lua_gr_func[id] = luaL_ref(l, LUA_REGISTRYINDEX); - luacon_sim->elements[id].Graphics = &luacon_graphicsReplacement; } else if(lua_type(l, -1) == LUA_TBOOLEAN && !lua_toboolean(l, -1)) { @@ -1332,7 +1332,6 @@ int LuaScriptInterface::elements_property(lua_State * l) { lua_pushvalue(l, 3); lua_gr_func[id] = luaL_ref(l, LUA_REGISTRYINDEX); - luacon_sim->elements[id].Graphics = &luacon_graphicsReplacement; } else if(lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, -1)) { diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 98b94b1..14a64be 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -15,6 +15,8 @@ #include "simulation/Elements.h" #include "simulation/ElementGraphics.h" #include "simulation/Air.h" +#include "cat/LuaScriptInterface.h" +#include "cat/LuaScriptHelper.h" extern "C" { #include "hmap.h" @@ -1158,7 +1160,11 @@ void Renderer::render_parts() { if (elements[t].Graphics) { - if ((*(elements[t].Graphics))(this, &(sim->parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb)) //That's a lot of args, a struct might be better + if (lua_gr_func[t]) + { + luacon_graphicsReplacement(this, &(sim->parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb, i); + } + else if ((*(elements[t].Graphics))(this, &(sim->parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb)) //That's a lot of args, a struct might be better { graphicscache[t].isready = 1; graphicscache[t].pixel_mode = pixel_mode; -- cgit v0.9.2-21-gd62e From ea38fc2d8662f62e30344a3f9a8d71771ca8bb8a Mon Sep 17 00:00:00 2001 From: jacob1 Date: Wed, 23 Jan 2013 21:54:15 -0500 Subject: fix possible crash with LIGH diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp index f697ebe..a6b77de 100644 --- a/src/simulation/elements/LIGH.cpp +++ b/src/simulation/elements/LIGH.cpp @@ -296,7 +296,7 @@ bool Element_LIGH::create_LIGH(Simulation * sim, int x, int y, int c, int temp, sim->parts[p].tmp = tmp; sim->parts[p].tmp2 = tmp2; } - else + else if (x >= 0 && x < XRES && y >= 0 && y < YRES) { int r = sim->pmap[y][x]; if ((((r&0xFF)==PT_VOID || ((r&0xFF)==PT_PVOD && sim->parts[r>>8].life >= 10)) && (!sim->parts[r>>8].ctype || (sim->parts[r>>8].ctype==c)!=(sim->parts[r>>8].tmp&1))) || (r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) // VOID, PVOD, VACU, and BHOL eat LIGH here -- cgit v0.9.2-21-gd62e From 4f59211ba8ec4e41262554f6611b971748cdb73f Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 25 Jan 2013 22:45:23 -0500 Subject: Fix brush not being visible when using CTRL to change the size diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index a037d05..6312f4a 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -1818,7 +1818,7 @@ void GameView::OnDraw() { activeBrush->RenderFill(ren, finalCurrentMouse); } - if (drawMode == DrawPoints || drawMode==DrawLine) + if (drawMode == DrawPoints || drawMode==DrawLine || (drawMode == DrawRect && !isMouseDown)) { if(wallBrush) { -- cgit v0.9.2-21-gd62e From 1d97f1c9853960ba99a8808263cc6443d9d09ef1 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 25 Jan 2013 22:57:51 -0500 Subject: typing '~' doesn't close the lua console diff --git a/.gitignore b/.gitignore index c7fe9f4..9ac6e38 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,8 @@ Makefile.me *.project *.cproject *.settings +*.cbp +*.layout config.log *.sconsign.dblite *.sconf_temp diff --git a/src/console/ConsoleView.cpp b/src/console/ConsoleView.cpp index 67c83de..5390cbd 100644 --- a/src/console/ConsoleView.cpp +++ b/src/console/ConsoleView.cpp @@ -37,7 +37,10 @@ void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, b { case KEY_ESCAPE: case '`': - c->CloseConsole(); + if (character != '~') + c->CloseConsole(); + else + Window::DoKeyPress(key, character, shift, ctrl, alt); break; case KEY_RETURN: case KEY_ENTER: -- cgit v0.9.2-21-gd62e From 46b767da0c14745a6cd807637249ec0b5b57b8f1 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 25 Jan 2013 23:15:33 -0500 Subject: clear persistent effects when it's display mode is removed diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 14a64be..50c9ba4 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -2630,9 +2630,14 @@ std::vector Renderer::GetRenderMode() void Renderer::CompileDisplayMode() { + int old_display_mode = display_mode; display_mode = 0; for(int i = 0; i < display_modes.size(); i++) display_mode |= display_modes[i]; + if(!(display_mode & DISPLAY_PERS) && (old_display_mode & DISPLAY_PERS)) + { + ClearAccumulation(); + } } void Renderer::AddDisplayMode(unsigned int mode) -- cgit v0.9.2-21-gd62e