16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00

toggleable lua support during build

This commit is contained in:
milek7
2021-03-06 03:49:24 +01:00
parent 16f856c833
commit 994b1446c1
6 changed files with 34 additions and 8 deletions

View File

@@ -50,6 +50,7 @@ option(USE_IMGUI_GL3 "Use OpenGL3+ imgui implementation" ON)
option(WITH_OPENGL_MODERN "Compile with OpenGL modern renderer" ON) option(WITH_OPENGL_MODERN "Compile with OpenGL modern renderer" ON)
option(WITH_OPENGL_LEGACY "Compile with OpenGL legacy renderer" ON) option(WITH_OPENGL_LEGACY "Compile with OpenGL legacy renderer" ON)
option(WITH_UART "Compile with libserialport" ON) option(WITH_UART "Compile with libserialport" ON)
option(WITH_LUA "Compile with lua scripting support" ON)
option(WITH_OPENVR "Compile with OpenVR" ON) option(WITH_OPENVR "Compile with OpenVR" ON)
option(WITH_ZMQ "Compile with cppzmq" OFF) option(WITH_ZMQ "Compile with cppzmq" OFF)
option(WITH_CRASHPAD "Compile with crashpad" OFF) option(WITH_CRASHPAD "Compile with crashpad" OFF)
@@ -108,7 +109,6 @@ set(SOURCES
"drivermouseinput.cpp" "drivermouseinput.cpp"
"translation.cpp" "translation.cpp"
"material.cpp" "material.cpp"
"lua.cpp"
"stdafx.cpp" "stdafx.cpp"
"messaging.cpp" "messaging.cpp"
"scene.cpp" "scene.cpp"
@@ -232,6 +232,11 @@ if (WITH_OPENVR)
set(SOURCES ${SOURCES} "vr/openvr_imp.cpp") set(SOURCES ${SOURCES} "vr/openvr_imp.cpp")
endif() endif()
if (WITH_LUA)
add_definitions(-DWITH_LUA)
set(SOURCES ${SOURCES} "lua.cpp")
endif()
if (WITH_OPENGL_MODERN) if (WITH_OPENGL_MODERN)
set(SOURCES ${SOURCES} set(SOURCES ${SOURCES}
"opengl33geometrybank.cpp" "opengl33geometrybank.cpp"
@@ -424,9 +429,11 @@ endif()
find_package(SndFile REQUIRED) find_package(SndFile REQUIRED)
target_link_libraries(${PROJECT_NAME} SndFile::sndfile) target_link_libraries(${PROJECT_NAME} SndFile::sndfile)
find_package(LuaJIT REQUIRED) if (WITH_LUA)
include_directories(${LUAJIT_INCLUDE_DIR}) find_package(LuaJIT REQUIRED)
target_link_libraries(${PROJECT_NAME} ${LUAJIT_LIBRARIES}) include_directories(${LUAJIT_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${LUAJIT_LIBRARIES})
endif()
if (WITH_UART) if (WITH_UART)
find_package(libserialport REQUIRED) find_package(libserialport REQUIRED)

View File

@@ -2075,6 +2075,7 @@ friction_event::export_as_text_( std::ostream &Output ) const {
Output << m_friction << ' '; Output << m_friction << ' ';
} }
#ifdef WITH_LUA
lua_event::lua_event(lua::eventhandler_t func) { lua_event::lua_event(lua::eventhandler_t func) {
lua_func = func; lua_func = func;
} }
@@ -2118,6 +2119,7 @@ lua_event::export_as_text_( std::ostream &Output ) const {
bool lua_event::is_instant() const { bool lua_event::is_instant() const {
return m_delay == 0.0 && m_delayrandom == 0.0; return m_delay == 0.0 && m_delayrandom == 0.0;
} }
#endif
// prepares event for use // prepares event for use
void void

View File

@@ -14,10 +14,13 @@ http://mozilla.org/MPL/2.0/.
#include "Names.h" #include "Names.h"
#include "EvLaunch.h" #include "EvLaunch.h"
#include "Logs.h" #include "Logs.h"
#include "lua.h"
#include "command.h" #include "command.h"
#include "comparison.h" #include "comparison.h"
#ifdef WITH_LUA
#include "lua.h"
#endif
// common event interface // common event interface
class basic_event { class basic_event {
@@ -585,6 +588,7 @@ private:
float m_friction{ -1.f }; float m_friction{ -1.f };
}; };
#ifdef WITH_LUA
class lua_event : public basic_event { class lua_event : public basic_event {
public: public:
lua_event(lua::eventhandler_t func); lua_event(lua::eventhandler_t func);
@@ -599,6 +603,7 @@ private:
lua::eventhandler_t lua_func = nullptr; lua::eventhandler_t lua_func = nullptr;
}; };
#endif
class message_event : public basic_event { class message_event : public basic_event {

View File

@@ -41,9 +41,12 @@ instance_table Instances;
vehicle_table Vehicles; vehicle_table Vehicles;
train_table Trains; train_table Trains;
light_array Lights; light_array Lights;
lua Lua;
particle_manager Particles; particle_manager Particles;
#ifdef WITH_LUA
lua Lua;
#endif
scene::basic_region *Region { nullptr }; scene::basic_region *Region { nullptr };
TTrain *Train { nullptr }; TTrain *Train { nullptr };

View File

@@ -11,11 +11,14 @@ http://mozilla.org/MPL/2.0/.
#include "simulationstateserializer.h" #include "simulationstateserializer.h"
#include "Classes.h" #include "Classes.h"
#include "lua.h"
#include "Event.h" #include "Event.h"
#include "Train.h" #include "Train.h"
#include "particles.h" #include "particles.h"
#ifdef WITH_LUA
#include "lua.h"
#endif
namespace simulation { namespace simulation {
class state_manager { class state_manager {
@@ -78,8 +81,10 @@ extern vehicle_table Vehicles;
extern train_table Trains; extern train_table Trains;
extern light_array Lights; extern light_array Lights;
extern sound_table Sounds; extern sound_table Sounds;
extern lua Lua;
extern particle_manager Particles; extern particle_manager Particles;
#ifdef WITH_LUA
extern lua Lua;
#endif
extern scene::basic_region *Region; extern scene::basic_region *Region;
extern TTrain *Train; extern TTrain *Train;

View File

@@ -319,7 +319,11 @@ void state_serializer::deserialize_lua( cParser &Input, scene::scratch_data &Scr
Input.getTokens(1, false); Input.getTokens(1, false);
std::string file; std::string file;
Input >> file; Input >> file;
#ifdef WITH_LUA
simulation::Lua.interpret(Global.asCurrentSceneryPath + file); simulation::Lua.interpret(Global.asCurrentSceneryPath + file);
#else
ErrorLog(file + ": lua scripts not supported in this build.");
#endif
} }
void void