Togglable lua scripting

This commit is contained in:
Simon Robertshaw 2013-05-11 11:52:35 +01:00
parent d1c8978a34
commit c2cdec9e62
17 changed files with 71 additions and 25 deletions

View File

@ -44,6 +44,7 @@ AddOption('--sse2',dest="sse2",action='store_true',default=False,help="Enable SS
AddOption('--sse3',dest="sse3",action='store_true',default=False,help="Enable SSE3 optimisations") AddOption('--sse3',dest="sse3",action='store_true',default=False,help="Enable SSE3 optimisations")
AddOption('--x86',dest="x86",action='store_true',default=True,help="Target Intel x86 platform") AddOption('--x86',dest="x86",action='store_true',default=True,help="Target Intel x86 platform")
AddOption('--nofft',dest="nofft", action='store_true',default=False,help="Do not use fftw3f for gravity.") AddOption('--nofft',dest="nofft", action='store_true',default=False,help="Do not use fftw3f for gravity.")
AddOption('--nolua',dest="nolua", action='store_true',default=False,help="Disable all lua scripting features.")
AddOption('--debugging', dest="debug", action="store_true", default=False, help="Enable debug options") AddOption('--debugging', dest="debug", action="store_true", default=False, help="Enable debug options")
AddOption('--beta',dest="beta",action='store_true',default=False,help="Beta build.") AddOption('--beta',dest="beta",action='store_true',default=False,help="Beta build.")
@ -90,15 +91,16 @@ if not GetOption("macosx"):
env.Append(CPPPATH=[GetOption("sdl-dir")]) env.Append(CPPPATH=[GetOption("sdl-dir")])
#Find correct lua include dir #Find correct lua include dir
try: if not GetOption("nolua"):
env.ParseConfig('pkg-config --cflags lua5.1') try:
except: env.ParseConfig('pkg-config --cflags lua5.1')
if(GetOption("lua-dir")): except:
if not conf.CheckCHeader(GetOption("lua-dir") + '/lua.h'): if(GetOption("lua-dir")):
print "lua5.1 headers not found or not installed" if not conf.CheckCHeader(GetOption("lua-dir") + '/lua.h'):
raise SystemExit(1) print "lua5.1 headers not found or not installed"
else: raise SystemExit(1)
env.Append(CPPPATH=[GetOption("lua-dir")]) else:
env.Append(CPPPATH=[GetOption("lua-dir")])
if not GetOption('nofft'): if not GetOption('nofft'):
#Check for FFT lib #Check for FFT lib
@ -121,7 +123,7 @@ if not GetOption("macosx"):
raise SystemExit(1) raise SystemExit(1)
#Check for Lua lib #Check for Lua lib
if not GetOption("macosx"): if not GetOption("macosx") and not GetOption("nolua"):
if not conf.CheckLib('lua5.1') and not conf.CheckLib('lua-5.1') and not conf.CheckLib('lua51') and not conf.CheckLib('lua'): if not conf.CheckLib('lua5.1') and not conf.CheckLib('lua-5.1') and not conf.CheckLib('lua51') and not conf.CheckLib('lua'):
print "liblua not found or not installed" print "liblua not found or not installed"
raise SystemExit(1) raise SystemExit(1)
@ -135,9 +137,11 @@ else:
env.Append(CPPPATH=['src/', 'data/', 'generated/']) env.Append(CPPPATH=['src/', 'data/', 'generated/'])
env.Append(CCFLAGS=['-w', '-std=c++98', '-fkeep-inline-functions']) env.Append(CCFLAGS=['-w', '-std=c++98', '-fkeep-inline-functions'])
env.Append(LIBS=['pthread', 'm']) env.Append(LIBS=['pthread', 'm'])
env.Append(CPPDEFINES=["LUACONSOLE", "_GNU_SOURCE", "USE_STDINT", "_POSIX_C_SOURCE=200112L"]) env.Append(CPPDEFINES=["_GNU_SOURCE", "USE_STDINT", "_POSIX_C_SOURCE=200112L"])
if not GetOption('nofft'): if not GetOption('nofft'):
env.Append(CPPDEFINES=["GRAVFFT"]) env.Append(CPPDEFINES=["GRAVFFT"])
if not GetOption('nolua'):
env.Append(CPPDEFINED=["LUACONSOLE"])
if GetOption("ptw32-static"): if GetOption("ptw32-static"):
env.Append(CPPDEFINES=['PTW32_STATIC_LIB']); env.Append(CPPDEFINES=['PTW32_STATIC_LIB']);
@ -267,7 +271,8 @@ sources+=Glob("src/gui/*/*.cpp")
sources+=Glob("src/simulation/elements/*.cpp") sources+=Glob("src/simulation/elements/*.cpp")
sources+=Glob("src/simulation/tools/*.cpp") sources+=Glob("src/simulation/tools/*.cpp")
sources+=Glob("src/client/requestbroker/*.cpp") sources+=Glob("src/client/requestbroker/*.cpp")
sources+=Glob("src/socket/*.c") if not GetOption('nolua'):
sources+=Glob("src/socket/*.c")
#for source in sources: #for source in sources:
# print str(source) # print str(source)

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
#include <string> #include <string>
#include <iomanip> #include <iomanip>
#include <vector> #include <vector>
@ -1983,4 +1984,4 @@ int luatpt_screenshot(lua_State* l)
Client::Ref().WriteFile(data, filename.str()); Client::Ref().WriteFile(data, filename.str());
return 0; return 0;
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
/* /*
** Lua BitOp -- a bit operations library for Lua 5.1/5.2. ** Lua BitOp -- a bit operations library for Lua 5.1/5.2.
** http://bitop.luajit.org/ ** http://bitop.luajit.org/
@ -189,4 +190,4 @@ int luaopen_bit(lua_State *L)
#endif #endif
return 1; return 1;
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
extern "C" extern "C"
{ {
#include "lua.h" #include "lua.h"
@ -112,3 +113,4 @@ void LuaButton::triggerAction()
LuaButton::~LuaButton() LuaButton::~LuaButton()
{ {
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
extern "C" extern "C"
{ {
#include "lua.h" #include "lua.h"
@ -110,3 +111,4 @@ void LuaCheckbox::triggerAction()
LuaCheckbox::~LuaCheckbox() LuaCheckbox::~LuaCheckbox()
{ {
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
extern "C" extern "C"
{ {
#include "lua.h" #include "lua.h"
@ -80,3 +81,4 @@ LuaComponent::~LuaComponent()
component->GetParentWindow()->RemoveComponent(component); component->GetParentWindow()->RemoveComponent(component);
delete component; delete component;
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
extern "C" extern "C"
{ {
#include "lua.h" #include "lua.h"
@ -53,3 +54,4 @@ int LuaLabel::text(lua_State * l)
LuaLabel::~LuaLabel() LuaLabel::~LuaLabel()
{ {
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
extern "C" extern "C"
{ {
#include "lua.h" #include "lua.h"
@ -69,3 +70,4 @@ int LuaProgressBar::status(lua_State * l)
LuaProgressBar::~LuaProgressBar() LuaProgressBar::~LuaProgressBar()
{ {
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
#include <string> #include <string>
#include <iomanip> #include <iomanip>
#include <vector> #include <vector>
@ -2201,3 +2202,4 @@ std::string LuaScriptInterface::FormatCommand(std::string command)
LuaScriptInterface::~LuaScriptInterface() { LuaScriptInterface::~LuaScriptInterface() {
delete legacy; delete legacy;
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
extern "C" extern "C"
{ {
#include "lua.h" #include "lua.h"
@ -110,3 +111,4 @@ void LuaSlider::triggerOnValueChanged()
LuaSlider::~LuaSlider() LuaSlider::~LuaSlider()
{ {
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
extern "C" extern "C"
{ {
#include "lua.h" #include "lua.h"
@ -113,3 +114,4 @@ int LuaTextbox::text(lua_State * l)
LuaTextbox::~LuaTextbox() LuaTextbox::~LuaTextbox()
{ {
} }
#endif

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
extern "C" extern "C"
{ {
#include "lua.h" #include "lua.h"
@ -591,3 +592,4 @@ LuaWindow::~LuaWindow()
ui::Engine::Ref().CloseWindow(); ui::Engine::Ref().CloseWindow();
delete window; delete window;
} }
#endif

View File

@ -9,8 +9,10 @@
#include "simulation/Elements.h" #include "simulation/Elements.h"
#include "simulation/ElementGraphics.h" #include "simulation/ElementGraphics.h"
#include "simulation/Air.h" #include "simulation/Air.h"
#ifdef LUACONSOLE
#include "cat/LuaScriptInterface.h" #include "cat/LuaScriptInterface.h"
#include "cat/LuaScriptHelper.h" #include "cat/LuaScriptHelper.h"
#endif
extern "C" extern "C"
{ {
#include "hmap.h" #include "hmap.h"
@ -1212,7 +1214,7 @@ void Renderer::render_parts()
{ {
if (elements[t].Graphics) if (elements[t].Graphics)
{ {
#ifndef RENDERER #if !defined(RENDERER) && defined(LUACONSOLE)
if (lua_gr_func[t]) if (lua_gr_func[t])
{ {
luacon_graphicsReplacement(this, &(sim->parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb, i); luacon_graphicsReplacement(this, &(sim->parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb, i);

View File

@ -145,8 +145,12 @@ GameController::GameController():
gameView->AttachController(this); gameView->AttachController(this);
gameModel->AddObserver(gameView); gameModel->AddObserver(gameView);
commandInterface = new LuaScriptInterface(this, gameModel);//new TPTScriptInterface(); #ifdef LUACONSOLE
commandInterface = new LuaScriptInterface(this, gameModel);
((LuaScriptInterface*)commandInterface)->SetWindow(gameView); ((LuaScriptInterface*)commandInterface)->SetWindow(gameView);
#else
commandInterface = new TPTScriptInterface(this, gameModel);
#endif
commandInterface->OnBrushChanged(gameModel->GetBrushID(), gameModel->GetBrush()->GetRadius().X, gameModel->GetBrush()->GetRadius().X); commandInterface->OnBrushChanged(gameModel->GetBrushID(), gameModel->GetBrush()->GetRadius().X, gameModel->GetBrush()->GetRadius().X);
ActiveToolChanged(0, gameModel->GetActiveTool(0)); ActiveToolChanged(0, gameModel->GetActiveTool(0));
@ -706,7 +710,9 @@ void GameController::Tick()
{ {
if(firstTick) if(firstTick)
{ {
#ifdef LUACONSOLE
((LuaScriptInterface*)commandInterface)->Init(); ((LuaScriptInterface*)commandInterface)->Init();
#endif
if(!Client::Ref().GetPrefBool("InstallCheck", false)) if(!Client::Ref().GetPrefBool("InstallCheck", false))
{ {
Client::Ref().SetPref("InstallCheck", true); Client::Ref().SetPref("InstallCheck", true);

View File

@ -14,8 +14,11 @@
#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"
//#include "cat/TPTScriptInterface.h" #ifdef LUACONSOLE
#include "cat/LuaScriptInterface.h" #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"

View File

@ -24,8 +24,10 @@
#include "Snapshot.h" #include "Snapshot.h"
//#include "StorageClasses.h" //#include "StorageClasses.h"
#ifdef LUACONSOLE
#include "cat/LuaScriptInterface.h" #include "cat/LuaScriptInterface.h"
#include "cat/LuaScriptHelper.h" #include "cat/LuaScriptHelper.h"
#endif
int Simulation::Load(GameSave * save) int Simulation::Load(GameSave * save)
{ {
@ -4196,7 +4198,11 @@ void Simulation::update_particles_i(int start, int inc)
} }
//call the particle update function, if there is one //call the particle update function, if there is one
#if !defined(RENDERER) && defined(LUACONSOLE)
if (elements[t].Update && lua_el_mode[t] != 2) if (elements[t].Update && lua_el_mode[t] != 2)
#else
if (elements[t].Update)
#endif
{ {
if ((*(elements[t].Update))(this, i, x, y, surround_space, nt, parts, pmap)) if ((*(elements[t].Update))(this, i, x, y, surround_space, nt, parts, pmap))
continue; continue;
@ -4207,6 +4213,7 @@ void Simulation::update_particles_i(int start, int inc)
y = (int)(parts[i].y+0.5f); y = (int)(parts[i].y+0.5f);
} }
} }
#if !defined(RENDERER) && defined(LUACONSOLE)
if(lua_el_mode[t]) if(lua_el_mode[t])
{ {
if(luacon_elementReplacement(this, i, x, y, surround_space, nt, parts, pmap)) if(luacon_elementReplacement(this, i, x, y, surround_space, nt, parts, pmap))
@ -4215,6 +4222,7 @@ void Simulation::update_particles_i(int start, int inc)
x = (int)(parts[i].x+0.5f); x = (int)(parts[i].x+0.5f);
y = (int)(parts[i].y+0.5f); y = (int)(parts[i].y+0.5f);
} }
#endif
if(legacy_enable)//if heat sim is off if(legacy_enable)//if heat sim is off
Element::legacyUpdate(this, i,x,y,surround_space,nt, parts, pmap); Element::legacyUpdate(this, i,x,y,surround_space,nt, parts, pmap);

View File

@ -1,3 +1,4 @@
#ifdef LUACONSOLE
// socket.lua from luasocket compiled into a cpp file // socket.lua from luasocket compiled into a cpp file
extern "C" { extern "C" {
#include "lua.h" #include "lua.h"
@ -10,3 +11,4 @@ void luaopen_socket(lua_State *l){
luaL_loadbuffer(l, socket_luac, socket_luac_sz, "@builtin socket.lua"); luaL_loadbuffer(l, socket_luac, socket_luac_sz, "@builtin socket.lua");
lua_call(l, 0, 0); lua_call(l, 0, 0);
} }
#endif