Archived
1
Fork 0

Remove sol library and lua scripting support

This commit is contained in:
redstrate 2020-08-14 20:53:22 -04:00
parent 0e008a1beb
commit 82a7d41dbc
12 changed files with 6 additions and 26017 deletions

View file

@ -21,12 +21,6 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(ENABLE_LINUX TRUE) set(ENABLE_LINUX TRUE)
endif() endif()
FetchContent_Declare(
lua
GIT_REPOSITORY https://github.com/NLua/lua.git
GIT_TAG master
)
FetchContent_Declare( FetchContent_Declare(
bullet bullet
GIT_REPOSITORY https://github.com/bulletphysics/bullet3.git GIT_REPOSITORY https://github.com/bulletphysics/bullet3.git
@ -59,17 +53,12 @@ macro(manual_download)
set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "" FORCE) set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "" FORCE)
set(USE_MSVC_RUNTIME_LIBRARY_DLL ON CACHE BOOL "" FORCE) set(USE_MSVC_RUNTIME_LIBRARY_DLL ON CACHE BOOL "" FORCE)
add_definitions(-DLUA_USE_APPLE)
set(CMAKE_FOLDER "External") set(CMAKE_FOLDER "External")
FetchContent_MakeAvailable(lua)
FetchContent_MakeAvailable(bullet) FetchContent_MakeAvailable(bullet)
FetchContent_MakeAvailable(spirv-cross) FetchContent_MakeAvailable(spirv-cross)
FetchContent_MakeAvailable(glslang) FetchContent_MakeAvailable(glslang)
remove_definitions(LUA_USE_MACOSX)
set(CMAKE_FOLDER "") set(CMAKE_FOLDER "")
endmacro() endmacro()

View file

@ -33,7 +33,7 @@ set(SRC
src/debug.cpp) src/debug.cpp)
if(NOT ENABLE_IOS AND NOT ENABLE_TVOS) if(NOT ENABLE_IOS AND NOT ENABLE_TVOS)
set(EXTRA_LIBRARIES Audio sol) set(EXTRA_LIBRARIES Audio)
endif() endif()
add_library(Core STATIC ${SRC}) add_library(Core STATIC ${SRC})

View file

@ -8,10 +8,6 @@
#include <string> #include <string>
#include <string_view> #include <string_view>
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
#include <sol.hpp>
#endif
#include "scene.hpp" #include "scene.hpp"
#include "renderer.hpp" #include "renderer.hpp"
#include "input.hpp" #include "input.hpp"
@ -323,10 +319,6 @@ public:
/// If physics should upate. This is a control indepentent of the pause state. /// If physics should upate. This is a control indepentent of the pause state.
bool update_physics = true; bool update_physics = true;
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
sol::state lua;
#endif
#if defined(PLATFORM_TVOS) || defined(PLATFORM_IOS) #if defined(PLATFORM_TVOS) || defined(PLATFORM_IOS)
bool debug_enabled = true; bool debug_enabled = true;
#else #else
@ -334,7 +326,6 @@ public:
#endif #endif
private: private:
void create_lua_interface();
void setup_scene(Scene& scene); void setup_scene(Scene& scene);
void on_remove(Object object); void on_remove(Object object);

View file

@ -5,10 +5,6 @@
#include <array> #include <array>
#include <functional> #include <functional>
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
#include <sol.hpp>
#endif
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "vector.hpp" #include "vector.hpp"
@ -254,13 +250,6 @@ public:
std::array<bool, max_environment_probes> environment_dirty; std::array<bool, max_environment_probes> environment_dirty;
GFXTexture *irradianceCubeArray = nullptr, *prefilteredCubeArray = nullptr; GFXTexture *irradianceCubeArray = nullptr, *prefilteredCubeArray = nullptr;
// script
std::string script_path;
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
sol::environment env;
#endif
}; };
/** Positions and rotates a camera to look at a target from a position. /** Positions and rotates a camera to look at a target from a position.

View file

@ -5,10 +5,6 @@
#include <map> #include <map>
#include <functional> #include <functional>
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
#include <sol.hpp>
#endif
#include "uielement.hpp" #include "uielement.hpp"
#include "file.hpp" #include "file.hpp"
@ -42,11 +38,5 @@ namespace ui {
GFXBuffer* glyph_buffer = nullptr; GFXBuffer* glyph_buffer = nullptr;
GFXBuffer* instance_buffer = nullptr; GFXBuffer* instance_buffer = nullptr;
GFXBuffer* elements_buffer = nullptr; GFXBuffer* elements_buffer = nullptr;
std::string script_path;
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
sol::environment env;
#endif
}; };
} }

View file

@ -27,8 +27,6 @@ Engine::Engine(const int argc, char* argv[]) {
_physics = std::make_unique<Physics>(); _physics = std::make_unique<Physics>();
_imgui = std::make_unique<ImGuiLayer>(); _imgui = std::make_unique<ImGuiLayer>();
assetm = std::make_unique<AssetManager>(); assetm = std::make_unique<AssetManager>();
create_lua_interface();
} }
void Engine::set_app(App* app) { void Engine::set_app(App* app) {
@ -122,9 +120,6 @@ Scene* Engine::load_scene(const file::Path path) {
auto scene = std::make_unique<Scene>(); auto scene = std::make_unique<Scene>();
if(j.contains("script"))
scene->script_path = j["script"];
std::map<Object, std::string> parentQueue; std::map<Object, std::string> parentQueue;
for(auto& obj : j["objects"]) { for(auto& obj : j["objects"]) {
@ -147,17 +142,6 @@ Scene* Engine::load_scene(const file::Path path) {
for(auto& [obj, toParent] : parentQueue) for(auto& [obj, toParent] : parentQueue)
scene->get<Data>(obj).parent = scene->find_object(toParent); scene->get<Data>(obj).parent = scene->find_object(toParent);
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
scene->env = sol::environment(lua, sol::create, lua.globals());
scene->env["scene"] = scene.get();
if(!scene->script_path.empty()) {
auto script_file = file::open(file::root_path(path) / scene->script_path);
if(script_file != std::nullopt)
engine->lua.safe_script(script_file->read_as_string(), scene->env);
}
#endif
setup_scene(*scene); setup_scene(*scene);
@ -178,8 +162,6 @@ void Engine::save_scene(const std::string_view path) {
j["objects"].push_back(save_object(obj)); j["objects"].push_back(save_object(obj));
} }
j["script"] = _current_scene->script_path;
std::ofstream out(path.data()); std::ofstream out(path.data());
out << j; out << j;
} }
@ -819,74 +801,6 @@ void Engine::stop_animation(Object target) {
} }
} }
void Engine::create_lua_interface() {
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::table, sol::lib::string, sol::lib::math);
lua.new_usertype<Cutscene>("Cutscene");
lua.new_usertype<InputBindingData>("InputBindingData",
"name", &InputBindingData::name);
lua.new_usertype<Input>("Input",
"get_bindings", sol::readonly_property(&Input::get_bindings));
lua.new_usertype<Engine>("Engine",
"pause", &Engine::pause,
"unpause", &Engine::unpause,
"clear_cutscene", [this] {
cutscene = nullptr;
},
"update_screen", [this] {
get_renderer()->update_screen();
},
"quit", &Engine::quit,
"get_input", sol::readonly_property(&Engine::get_input),
"push_event", &Engine::push_event);
lua["engine"] = this;
lua.new_usertype<ui::Screen>("UIScreen",
"find_element", &ui::Screen::find_element,
"add_element", [](ui::Screen* screen, UIElement& element) {
screen->elements.push_back(element);
});
lua.new_usertype<UIElement::Background>("UIElementBackground",
"image", &UIElement::Background::image);
lua.new_usertype<UIElement::UIElement::Metrics::Metric>("UIElementMetric",
"value", &UIElement::Metrics::Metric::value);
lua.new_usertype<UIElement::UIElement::Metrics>("UIElementMetrics",
"x", &UIElement::Metrics::x,
"y", &UIElement::Metrics::y,
"width", &UIElement::Metrics::width,
"height", &UIElement::Metrics::height);
lua.new_usertype<UIElement>("UIElement",
"id", &UIElement::id,
"text", &UIElement::text,
"=background", &UIElement::background,
"visible", &UIElement::visible,
"metrics", &UIElement::metrics);
lua.new_usertype<Scene>("Scene");
lua["get_transform"] = [](Object o) -> Transform& {
return engine->get_scene()->get<Transform>(o);
};
lua.new_usertype<Transform>("Transform",
"position", &Transform::position);
lua.new_usertype<Vector3>("Vector3",
"x", &Vector3::x,
"y", &Vector3::y,
"z", &Vector3::z);
#endif
}
void Engine::setup_scene(Scene& scene) { void Engine::setup_scene(Scene& scene) {
_physics->reset(); _physics->reset();

View file

@ -77,19 +77,6 @@ void ui::Screen::calculate_sizes() {
void ui::Screen::process_mouse(const int x, const int y) { void ui::Screen::process_mouse(const int x, const int y) {
Expects(x >= 0); Expects(x >= 0);
Expects(y >= 0); Expects(y >= 0);
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
for(auto& element : elements) {
if(x > element.absolute_x &&
y > element.absolute_y &&
x < (element.absolute_x + element.absolute_width) &&
y < (element.absolute_y + element.absolute_height)) {
if(!element.on_click_script.empty())
engine->lua.safe_script(element.on_click_script, env);
}
}
#endif
} }
UIElement* ui::Screen::find_element(const std::string& id) { UIElement* ui::Screen::find_element(const std::string& id) {
@ -116,9 +103,6 @@ ui::Screen::Screen(const file::Path path) {
nlohmann::json j; nlohmann::json j;
file->read_as_stream() >> j; file->read_as_stream() >> j;
if(j.count("script"))
script_path = j["script"];
for(auto& element : j["elements"]) { for(auto& element : j["elements"]) {
UIElement ue; UIElement ue;
ue.id = element["id"]; ue.id = element["id"];
@ -195,17 +179,6 @@ ui::Screen::Screen(const file::Path path) {
elements.push_back(ue); elements.push_back(ue);
} }
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
env = sol::environment(engine->lua, sol::create, engine->lua.globals());
env["screen"] = this;
if(!script_path.empty()) {
auto script_file = file::open(file::app_domain / script_path);
if(script_file != std::nullopt)
engine->lua.safe_script(script_file->read_as_string(), env);
}
#endif
} }
void ui::Screen::add_listener(const std::string& id, std::function<void()> callback) { void ui::Screen::add_listener(const std::string& id, std::function<void()> callback) {
@ -213,8 +186,5 @@ void ui::Screen::add_listener(const std::string& id, std::function<void()> callb
} }
void ui::Screen::process_event(const std::string& type, const std::string data) { void ui::Screen::process_event(const std::string& type, const std::string data) {
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
auto func = env["process_event"];
func(type, data);
#endif
} }

View file

@ -155,7 +155,7 @@ const std::vector<unsigned int> CompileGLSL(const std::string& filename, EShLang
includer.pushExternalLocalDirectory(file::get_domain_path(file::Domain::Internal).string()); includer.pushExternalLocalDirectory(file::get_domain_path(file::Domain::Internal).string());
if (!Shader.parse(&Resources, 100, false, (EShMessages)0, includer)) { if (!Shader.parse(&Resources, 100, false, (EShMessages)0, includer)) {
std::cout << Shader.getInfoLog() << std::endl; console::error(System::Renderer, "{}", Shader.getInfoLog());
return {}; return {};
} }
@ -179,8 +179,8 @@ const std::vector<unsigned int> CompileGLSL(const std::string& filename, EShLang
std::variant<std::string, std::vector<uint32_t>> get_shader(std::string filename, bool skinned, bool cubemap) { std::variant<std::string, std::vector<uint32_t>> get_shader(std::string filename, bool skinned, bool cubemap) {
auto shader_file = file::open(file::internal_domain / filename); auto shader_file = file::open(file::internal_domain / filename);
if(!shader_file) { if(!shader_file.has_value()) {
std::cerr << "Failed to open " << filename << "!!" << std::endl; console::error(System::Renderer, "Failed to open shader file {}!", filename);
return ""; return "";
} }

View file

@ -13,7 +13,6 @@ add_subdirectory(stb)
add_subdirectory(imgui) add_subdirectory(imgui)
add_subdirectory(magic_enum) add_subdirectory(magic_enum)
add_subdirectory(smaa) add_subdirectory(smaa)
add_subdirectory(sol)
add_subdirectory(doctest) add_subdirectory(doctest)
include(FetchContent) include(FetchContent)

View file

@ -1,15 +0,0 @@
if(TARGET liblua_static)
set(LUA_LIBRARY liblua_static)
set(LUA_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/lua-build/include)
else()
find_package(LuaJIT REQUIRED)
endif()
add_library(sol INTERFACE)
target_include_directories(sol SYSTEM INTERFACE include ${LUA_INCLUDE_DIR})
target_link_libraries(sol INTERFACE ${LUA_LIBRARY})
target_compile_definitions(sol INTERFACE SOL_ALL_SAFETIES_ON SOL_EXCEPTIONS_SAFE_PROPAGATION)
if(ENABLE_IOS OR ENABLE_TVOS)
target_compile_definitions(sol INTERFACE LUA_USE_APPLE)
endif()

File diff suppressed because it is too large Load diff

View file

@ -133,7 +133,7 @@ void SceneEditor::draw(CommonEditor* editor) {
if(scene != nullptr) { if(scene != nullptr) {
if(showSceneSettings) { if(showSceneSettings) {
if(begin("Scene Settings", &showSceneSettings)) { if(begin("Scene Settings", &showSceneSettings)) {
ImGui::InputText("Script Path", &scene->script_path);
} }
ImGui::End(); ImGui::End();