fix sim.NUM_PARTS, other small changes

This commit is contained in:
jacob1 2013-06-05 23:17:34 -04:00
parent c7ce3fa4b2
commit 2119343b6a
4 changed files with 14 additions and 18 deletions

View File

@ -485,7 +485,6 @@ void LuaScriptInterface::initSimulationAPI()
{NULL, NULL} {NULL, NULL}
}; };
luaL_register(l, "simulation", simulationAPIMethods); luaL_register(l, "simulation", simulationAPIMethods);
int simulationAPI = lua_gettop(l);
//Sim shortcut //Sim shortcut
lua_getglobal(l, "simulation"); lua_getglobal(l, "simulation");
@ -495,7 +494,6 @@ void LuaScriptInterface::initSimulationAPI()
SETCONST(l, XRES); SETCONST(l, XRES);
SETCONST(l, YRES); SETCONST(l, YRES);
SETCONST(l, PT_NUM); SETCONST(l, PT_NUM);
lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, simulationAPI, "NUM_PARTS");
SETCONST(l, R_TEMP); SETCONST(l, R_TEMP);
SETCONST(l, MAX_TEMP); SETCONST(l, MAX_TEMP);
SETCONST(l, MIN_TEMP); SETCONST(l, MIN_TEMP);
@ -506,7 +504,7 @@ void LuaScriptInterface::initSimulationAPI()
SETCONST(l, TOOL_AIR); SETCONST(l, TOOL_AIR);
SETCONST(l, TOOL_PGRV); SETCONST(l, TOOL_PGRV);
SETCONST(l, TOOL_NGRV); SETCONST(l, TOOL_NGRV);
lua_pushinteger(l, luacon_sim->tools.size()); lua_setfield(l, simulationAPI, "TOOL_WIND"); lua_pushinteger(l, luacon_sim->tools.size()); lua_setfield(l, -2, "TOOL_WIND");
SETCONST(l, DECO_DRAW); SETCONST(l, DECO_DRAW);
SETCONST(l, DECO_CLEAR); SETCONST(l, DECO_CLEAR);
SETCONST(l, DECO_ADD); SETCONST(l, DECO_ADD);
@ -524,7 +522,7 @@ void LuaScriptInterface::initSimulationAPI()
std::string propertyName = (*iter).Name; std::string propertyName = (*iter).Name;
std::transform(propertyName.begin(), propertyName.end(), propertyName.begin(), ::toupper); std::transform(propertyName.begin(), propertyName.end(), propertyName.begin(), ::toupper);
lua_pushinteger(l, particlePropertiesCount); lua_pushinteger(l, particlePropertiesCount);
lua_setfield(l, simulationAPI, ("FIELD_"+propertyName).c_str()); lua_setfield(l, -2, ("FIELD_"+propertyName).c_str());
particleProperties[particlePropertiesCount++] = *iter; particleProperties[particlePropertiesCount++] = *iter;
} }
} }
@ -1717,8 +1715,6 @@ void LuaScriptInterface::initElementsAPI()
lua_getglobal(l, "elements"); lua_getglobal(l, "elements");
lua_setglobal(l, "elem"); lua_setglobal(l, "elem");
int elementsAPI = lua_gettop(l);
//Static values //Static values
//Element types/properties/states //Element types/properties/states
SETCONST(l, TYPE_PART); SETCONST(l, TYPE_PART);
@ -1770,13 +1766,13 @@ void LuaScriptInterface::initElementsAPI()
if(luacon_sim->elements[i].Enabled) if(luacon_sim->elements[i].Enabled)
{ {
lua_pushinteger(l, i); lua_pushinteger(l, i);
lua_setfield(l, elementsAPI, luacon_sim->elements[i].Identifier); lua_setfield(l, -2, luacon_sim->elements[i].Identifier);
char realIdentifier[20]; char realIdentifier[20];
sprintf(realIdentifier, "DEFAULT_PT_%s", luacon_sim->elements[i].Name); sprintf(realIdentifier, "DEFAULT_PT_%s", luacon_sim->elements[i].Name);
if (i != 0 && i != PT_NBHL && i != PT_NWHL && strcmp(luacon_sim->elements[i].Identifier, realIdentifier)) if (i != 0 && i != PT_NBHL && i != PT_NWHL && strcmp(luacon_sim->elements[i].Identifier, realIdentifier))
{ {
lua_pushinteger(l, i); lua_pushinteger(l, i);
lua_setfield(l, elementsAPI, realIdentifier); lua_setfield(l, -2, realIdentifier);
} }
} }
} }
@ -2321,10 +2317,8 @@ void LuaScriptInterface::initGraphicsAPI()
lua_getglobal(l, "graphics"); lua_getglobal(l, "graphics");
lua_setglobal(l, "gfx"); lua_setglobal(l, "gfx");
int graphicsAPI = lua_gettop(l); lua_pushinteger(l, XRES+BARSIZE); lua_setfield(l, -2, "WIDTH");
lua_pushinteger(l, YRES+MENUSIZE); lua_setfield(l, -2, "HEIGHT");
lua_pushinteger(l, XRES+BARSIZE); lua_setfield(l, graphicsAPI, "WIDTH");
lua_pushinteger(l, YRES+MENUSIZE); lua_setfield(l, graphicsAPI, "HEIGHT");
} }
int LuaScriptInterface::graphics_textSize(lua_State * l) int LuaScriptInterface::graphics_textSize(lua_State * l)
@ -2781,6 +2775,8 @@ bool LuaScriptInterface::OnKeyRelease(int key, Uint16 character, bool shift, boo
void LuaScriptInterface::OnTick() void LuaScriptInterface::OnTick()
{ {
lua_getglobal(l, "simulation");
lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, -2, "NUM_PARTS");
ui::Engine::Ref().LastTick(clock()); ui::Engine::Ref().LastTick(clock());
if(luacon_mousedown) if(luacon_mousedown)
luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0); luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0);

View File

@ -40,7 +40,7 @@ class Tool;
// idea from mniip, makes things much simpler // idea from mniip, makes things much simpler
#define SETCONST(L, NAME)\ #define SETCONST(L, NAME)\
lua_pushinteger(L, NAME);\ lua_pushinteger(L, NAME);\
lua_setfield(L, -2, #NAME); lua_setfield(L, -2, #NAME)
class TPTScriptInterface; class TPTScriptInterface;
class LuaScriptInterface: public CommandInterface class LuaScriptInterface: public CommandInterface

View File

@ -27,6 +27,11 @@
#include "gui/interface/Keys.h" #include "gui/interface/Keys.h"
#include "simulation/Snapshot.h" #include "simulation/Snapshot.h"
#include "debug/DebugInfo.h" #include "debug/DebugInfo.h"
#ifdef LUACONSOLE
#include "cat/LuaScriptInterface.h"
#else
#include "cat/TPTScriptInterface.h"
#endif
//#include "debug/ElementPopulation.h" //#include "debug/ElementPopulation.h"
using namespace std; using namespace std;

View File

@ -14,11 +14,6 @@
#include "gui/console/ConsoleController.h" #include "gui/console/ConsoleController.h"
#include "gui/localbrowser/LocalBrowserController.h" #include "gui/localbrowser/LocalBrowserController.h"
#include "gui/options/OptionsController.h" #include "gui/options/OptionsController.h"
#ifdef LUACONSOLE
#include "cat/LuaScriptInterface.h"
#else
#include "cat/TPTScriptInterface.h"
#endif
#include "client/ClientListener.h" #include "client/ClientListener.h"
#include "RenderPreset.h" #include "RenderPreset.h"
#include "Menu.h" #include "Menu.h"