From 17cd0e74f26b28101edf1ded343e83820d3f4357 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Wed, 16 Jan 2013 23:48:09 -0500 Subject: [PATCH] add gravmap setting. Getting doesn't work right now, and maybe i should check if gravx/y can be modified too --- src/cat/LuaScriptInterface.cpp | 37 +++++++++++++++++++++++++++++++++- src/cat/LuaScriptInterface.h | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 4528b2b09..88fe9344f 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -410,6 +410,7 @@ void LuaScriptInterface::initSimulationAPI() {"ambientHeat", simulation_ambientHeat}, {"velocityX", simulation_velocityX}, {"velocityY", simulation_velocityY}, + {"gravMap", simulation_gravMap}, {NULL, NULL} }; luaL_register(l, "simulation", simulationAPIMethods); @@ -452,7 +453,8 @@ void LuaScriptInterface::set_map(int x, int y, int width, int height, float valu luacon_sim->vx[ny][nx] = value; else if (map == 4) luacon_sim->vy[ny][nx] = value; - + else if (map == 5) + luacon_sim->gravmap[ny*XRES/CELL+nx] = value; //gravx/y don't seem to work, but this does. opposite of tpt } } @@ -671,6 +673,39 @@ int LuaScriptInterface::simulation_velocityY(lua_State* l) return 0; } +int LuaScriptInterface::simulation_gravMap(lua_State* l) +{ + int argCount = lua_gettop(l); + luaL_checktype(l, 1, LUA_TNUMBER); + luaL_checktype(l, 2, LUA_TNUMBER); + int x = lua_tointeger(l, 1); + int y = lua_tointeger(l, 2); + if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES) + return luaL_error(l, "coordinates out of range (%d,%d)", x, y); + + /*if (argCount == 2) + { + lua_pushnumber(l, luacon_sim->gravmap[y*XRES/CELL+x]); + return 1; + }*/ + int width = 1, height = 1; + float value; + luaL_checktype(l, 3, LUA_TNUMBER); + if (argCount == 3) + value = (float)lua_tonumber(l, 3); + else + { + luaL_checktype(l, 4, LUA_TNUMBER); + luaL_checktype(l, 5, LUA_TNUMBER); + width = lua_tointeger(l, 3); + height = lua_tointeger(l, 4); + value = (float)lua_tonumber(l, 5); + } + + set_map(x, y, width, height, value, 5); + return 0; +} + //// Begin Renderer API void LuaScriptInterface::initRendererAPI() diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index c88b973d4..f7b1a13d3 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -63,6 +63,7 @@ class LuaScriptInterface: public CommandInterface static int simulation_pressure(lua_State * l); static int simulation_velocityX(lua_State * l); static int simulation_velocityY(lua_State * l); + static int simulation_gravMap(lua_State * l); static int simulation_ambientHeat(lua_State * l); //Renderer