From 3eced316aafc41d274afe86d0e2a35504ef19cd8 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Thu, 10 Oct 2024 08:55:41 +0300 Subject: [PATCH 1/6] Move code from C++ to python Use boost python to get a C++ struct/class from python. Implement Graphics2Config (temp name) - has resolution and screen number. Populate struct from config.yaml via config.py. Modify game to take resolution and screen values from config.yaml. Deprecates settings app. Note: Need to document new install step - pip3 install pyyaml somewhere. Implement unit tests in configuration. --- engine/CMakeLists.txt | 39 ++++++- engine/src/configuration/configuration.cpp | 6 + engine/src/configuration/configuration.h | 3 + engine/src/configuration/tests/config.py | 24 ++++ engine/src/configuration/tests/config.yaml | 8 ++ .../tests/python_tests.cpp | 37 +++--- .../tests/python_tests.py | 0 .../src/configuration/tests/vegastrike.config | 32 ----- engine/src/gldrv/winsys.cpp | 7 +- engine/src/main.cpp | 2 + engine/src/python/config/graphics_config.cpp | 30 +++++ .../config/graphics_config.h} | 32 ++--- engine/src/python/config/python_utils.cpp | 109 ++++++++++++++++++ .../config}/python_utils.h | 12 ++ engine/src/vsfilesystem.cpp | 1 + engine/src/vsfilesystem.h | 1 + 16 files changed, 273 insertions(+), 70 deletions(-) create mode 100644 engine/src/configuration/tests/config.py create mode 100644 engine/src/configuration/tests/config.yaml rename engine/src/{resource => configuration}/tests/python_tests.cpp (84%) rename engine/src/{components => configuration}/tests/python_tests.py (100%) delete mode 100644 engine/src/configuration/tests/vegastrike.config create mode 100644 engine/src/python/config/graphics_config.cpp rename engine/src/{resource/python_utils.cpp => python/config/graphics_config.h} (64%) create mode 100644 engine/src/python/config/python_utils.cpp rename engine/src/{resource => python/config}/python_utils.h (78%) diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index f81f8b0c91..8e3fb92de5 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -166,6 +166,7 @@ IF (UNIX) ${Vega_Strike_SOURCE_DIR}/src/damage ${Vega_Strike_SOURCE_DIR}/src/resource ${Vega_Strike_SOURCE_DIR}/src/components + ${Vega_Strike_SOURCE_DIR}/src/python/config ${Vega_Strike_BINARY_DIR} ${Vega_Strike_BINARY_DIR}/src /usr/include/harfbuzz/ @@ -177,6 +178,7 @@ ELSE () ${Vega_Strike_SOURCE_DIR}/src/damage ${Vega_Strike_SOURCE_DIR}/src/resource ${Vega_Strike_SOURCE_DIR}/src/components + ${Vega_Strike_SOURCE_DIR}/src/python/config ${Vega_Strike_BINARY_DIR} ${Vega_Strike_BINARY_DIR}/src ) @@ -374,6 +376,7 @@ IF (Python3_FOUND) SET(TST_INCLUDES ${Python3_INCLUDE_DIRS}) SET(TST_LIBS ${Python3_LIBRARIES}) SET(HAVE_PYTHON 1) + add_compile_definitions(Python_SITELIB=${Python3_SITELIB}) ELSE (Python3_FOUND) MESSAGE(FATAL_ERROR "Can't find python") ENDIF (Python3_FOUND) @@ -712,11 +715,15 @@ SET(LIBRESOURCE src/resource/product.cpp src/resource/cargo.cpp src/resource/manifest.cpp - src/resource/python_utils.cpp src/resource/random_utils.cpp src/cmd/json.cpp ) +SET(LIBPYTHON + src/python/config/python_utils.cpp + src/python/config/graphics_config.cpp +) + SET(LIBCOMPONENT src/components/component.cpp @@ -1130,7 +1137,21 @@ SET(LIBAUDIO_SOURCES ) +ADD_LIBRARY(vegastrike_python SHARED + ${LIBPYTHON} +) + +TARGET_LINK_LIBRARIES( + vegastrike_python + ${Boost_LIBRARIES} + ${Python3_LIBRARIES} +) + +# Name must be witout the lib prefix +SET_TARGET_PROPERTIES(vegastrike_python PROPERTIES PREFIX "") + ADD_LIBRARY(vegastrike-engine_com + ${LIBPYTHON} ${LIBVS_LOGGING} ${LIBCONFIG} ${LIBDAMAGE} @@ -1721,13 +1742,14 @@ IF (USE_GTEST) src/resource/tests/resource_test.cpp src/resource/tests/manifest_tests.cpp src/resource/tests/random_tests.cpp - src/resource/tests/python_tests.cpp + src/configuration/tests/python_tests.cpp src/exit_unit_tests.cpp src/components/tests/energy_container_tests.cpp src/components/tests/balancing_tests.cpp ) ADD_LIBRARY(vegastrike-testing + ${LIBPYTHON} ${LIBCONFIG} ${LIBDAMAGE} ${LIBRESOURCE} @@ -1762,18 +1784,23 @@ IF (USE_GTEST) ENDIF() FILE( - COPY "src/configuration/tests/vegastrike.config" + COPY "src/cmd/tests/units.json" DESTINATION ${CMAKE_BINARY_DIR}/test_assets ) FILE( - COPY "src/cmd/tests/units.json" + COPY "src/configuration/tests/python_tests.py" DESTINATION ${CMAKE_BINARY_DIR}/test_assets ) FILE( - COPY "src/components/tests/python_tests.py" - DESTINATION ${CMAKE_BINARY_DIR} + COPY "src/configuration/tests/config.py" + DESTINATION ${CMAKE_BINARY_DIR}/test_assets + ) + + FILE( + COPY "src/configuration/tests/config.yaml" + DESTINATION ${CMAKE_BINARY_DIR}/test_assets ) INCLUDE(GoogleTest) diff --git a/engine/src/configuration/configuration.cpp b/engine/src/configuration/configuration.cpp index 3ec43ae996..4120fb6126 100644 --- a/engine/src/configuration/configuration.cpp +++ b/engine/src/configuration/configuration.cpp @@ -30,10 +30,16 @@ #endif #include +#include "vsfilesystem.h" + using vega_config::GetGameConfig; Configuration::Configuration() { //logging.verbose_debug = GetGameConfig().GetBool("data.verbose_debug", false); + graphics2_config = GetGraphics2Config( + VSFileSystem::programdir, + VSFileSystem::datadir, + "config", "get_config"); } /* Override the default value(provided by constructor) with the value from the user specified configuration file, if any. diff --git a/engine/src/configuration/configuration.h b/engine/src/configuration/configuration.h index 74838af03e..1c569f90d2 100644 --- a/engine/src/configuration/configuration.h +++ b/engine/src/configuration/configuration.h @@ -30,6 +30,8 @@ #include #include +#include "python/config/graphics_config.h" + namespace vega_config { // Config Structs Declaration @@ -449,6 +451,7 @@ class Configuration { Configuration(); void OverrideDefaultsWithUserConfiguration(); vega_config::GeneralConfig general_config; + Graphics2Config graphics2_config; vega_config::DataConfig data_config; vega_config::AIConfig ai; vega_config::AudioConfig audio_config; diff --git a/engine/src/configuration/tests/config.py b/engine/src/configuration/tests/config.py new file mode 100644 index 0000000000..34385b7e30 --- /dev/null +++ b/engine/src/configuration/tests/config.py @@ -0,0 +1,24 @@ +import yaml +import vegastrike_python + + +def get_config(): + with open('config.yaml', 'r') as file: + yaml_file = yaml.safe_load(file) + print(yaml_file) + + graphics = vegastrike_python.GraphicsConfig() + graphics.screen = yaml_file['graphics']['screen'] + graphics.resolution_x = yaml_file['graphics']['resolution_x'] + graphics.resolution_y = yaml_file['graphics']['resolution_y'] + + + return graphics + + +#gfx = get_config() +#print('screen: ', gfx.screen) +#print('x: ', gfx.resolution_x) +#print('y: ', gfx.resolution_y) + + diff --git a/engine/src/configuration/tests/config.yaml b/engine/src/configuration/tests/config.yaml new file mode 100644 index 0000000000..819b1e7e12 --- /dev/null +++ b/engine/src/configuration/tests/config.yaml @@ -0,0 +1,8 @@ +general: + +graphics: + resolution_x: 2560 + resolution_y: 1600 + screen: 0 + +advanced: diff --git a/engine/src/resource/tests/python_tests.cpp b/engine/src/configuration/tests/python_tests.cpp similarity index 84% rename from engine/src/resource/tests/python_tests.cpp rename to engine/src/configuration/tests/python_tests.cpp index 4f3d39734a..80c74f457f 100644 --- a/engine/src/resource/tests/python_tests.cpp +++ b/engine/src/configuration/tests/python_tests.cpp @@ -30,12 +30,11 @@ #include #include -#include "python_utils.h" +#include "python/config/python_utils.h" +#include "python/config/graphics_config.h" using namespace boost::python; -// This code shows how to call a python file from c++ -// It is not portable struct World { @@ -86,15 +85,6 @@ TEST(Python, Call_Function) { Py_Initialize(); - // Use the following code to figure out your original path, as the above Py_SetPath overrides it. - // Note that Py_GetPath must be called after Py_Initialize and Py_SetPath before. - /*wchar_t* w_path_ptr = Py_GetPath(); - std::wstring w_path_w( w_path_ptr ); - std::string path( w_path_w.begin(), w_path_w.end() ); - std::cout << "Path: " << path << std::endl;*/ - - //PyObject* moduleString = PyUnicode_FromString((char*)"python_tests"); - //PyObject* module = PyImport_Import(moduleString); PyObject* module = PyImport_ImportModule("python_tests"); std::cout << "PyImport_ImportModule did not crash\n" << std::flush; if(!module) { @@ -140,4 +130,25 @@ TEST(Python, Call_Function) { // Uncomment to see prints //EXPECT_FALSE(true); -} \ No newline at end of file +} + +// Test ability to get config file from python +TEST(Python, Config) { + boost::filesystem::path test_path(boost::filesystem::current_path()); + boost::filesystem::path lib_path = test_path.parent_path(); + std::cout << "test_path: " << test_path << std::endl; + std::cout << "lib_path: " << lib_path << std::endl; + + PyObject* object = GetClassFromPython( + lib_path.string(), + test_path.string(), + "config", "get_config"); + + Graphics2Config& cfg2 = extract(object); + EXPECT_EQ(cfg2.screen, 0); + EXPECT_EQ(cfg2.resolution_x, 2560); + EXPECT_EQ(cfg2.resolution_y, 1600); + + // Uncomment to see prints*/ + //EXPECT_FALSE(true); +} diff --git a/engine/src/components/tests/python_tests.py b/engine/src/configuration/tests/python_tests.py similarity index 100% rename from engine/src/components/tests/python_tests.py rename to engine/src/configuration/tests/python_tests.py diff --git a/engine/src/configuration/tests/vegastrike.config b/engine/src/configuration/tests/vegastrike.config deleted file mode 100644 index 3bbacfaa43..0000000000 --- a/engine/src/configuration/tests/vegastrike.config +++ /dev/null @@ -1,32 +0,0 @@ - - -
- - - - - -
- - - - - -
-
-
- - - - - -
- - - - - -
-
-
-
diff --git a/engine/src/gldrv/winsys.cpp b/engine/src/gldrv/winsys.cpp index 4f5e4ce847..eccbeab702 100644 --- a/engine/src/gldrv/winsys.cpp +++ b/engine/src/gldrv/winsys.cpp @@ -251,10 +251,9 @@ static bool setup_sdl_video_mode(int *argc, char **argv) { SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); } //#endif - width = g_game.x_resolution; - height = g_game.y_resolution; - - const int screen_number = configuration()->general_config.screen; + width = configuration()->graphics2_config.resolution_x; + height = configuration()->graphics2_config.resolution_y; + const int screen_number = configuration()->graphics2_config.screen; SDL_Window *window = nullptr; if(screen_number == 0) { window = SDL_CreateWindow("Vegastrike", 0, 0, width, height, video_flags); diff --git a/engine/src/main.cpp b/engine/src/main.cpp index 12b96fd2f3..94d27443d5 100644 --- a/engine/src/main.cpp +++ b/engine/src/main.cpp @@ -247,6 +247,8 @@ int main(int argc, char *argv[]) { const boost::filesystem::path program_name{program_path.filename()}; //canonical_program_path.filename(); const boost::filesystem::path program_directory_path{program_path.parent_path()}; + VSFileSystem::programdir = program_directory_path.string(); + // This will be set later boost::filesystem::path home_subdir_path{}; diff --git a/engine/src/python/config/graphics_config.cpp b/engine/src/python/config/graphics_config.cpp new file mode 100644 index 0000000000..84076135c5 --- /dev/null +++ b/engine/src/python/config/graphics_config.cpp @@ -0,0 +1,30 @@ +#include +#include +#include + +#include "graphics_config.h" +#include "python_utils.h" + + + +BOOST_PYTHON_MODULE(vegastrike_python) { + boost::python::class_("GraphicsConfig", boost::python::init<>()) + .def_readwrite("screen", &Graphics2Config::screen) + .def_readwrite("resolution_x", &Graphics2Config::resolution_x) + .def_readwrite("resolution_y", &Graphics2Config::resolution_y); +} + + + +Graphics2Config GetGraphics2Config( + const std::string build_path, + const std::string path_string, + const std::string file_name, + const std::string function_name) { + PyObject* object = GetClassFromPython( + build_path, path_string, file_name, function_name); + + + Graphics2Config cfg2 = boost::python::extract(object); + return cfg2; +} \ No newline at end of file diff --git a/engine/src/resource/python_utils.cpp b/engine/src/python/config/graphics_config.h similarity index 64% rename from engine/src/resource/python_utils.cpp rename to engine/src/python/config/graphics_config.h index 23590f49cb..2b0b818662 100644 --- a/engine/src/resource/python_utils.cpp +++ b/engine/src/python/config/graphics_config.h @@ -1,5 +1,5 @@ /* - * python_utils.cpp + * graphics_config.h * * Copyright (c) 2001-2002 Daniel Horn * Copyright (c) 2002-2019 pyramid3d and other Vega Strike Contributors @@ -25,21 +25,23 @@ // -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- -#include "python_utils.h" +#ifndef VEGA_STRIKE_ENGINE_PYTHON_CONFIG_GRAPHICS_CONFIG_H +#define VEGA_STRIKE_ENGINE_PYTHON_CONFIG_GRAPHICS_CONFIG_H -#include -#include +// TODO: remove the other GraphicsConfig and rename this +struct Graphics2Config { + int screen{0}; + int resolution_x{1920}; + int resolution_y{1080}; -using namespace boost::python; + Graphics2Config() = default; +}; -const std::string GetPythonPath() { - Py_Initialize(); - wchar_t* w_path_ptr = Py_GetPath(); - Py_Finalize(); - - std::wstring w_path_w( w_path_ptr ); - std::string path( w_path_w.begin(), w_path_w.end() ); - std::cout << "Python path: " << path << std::endl; +Graphics2Config GetGraphics2Config( + const std::string build_path, + const std::string path_string, + const std::string file_name, + const std::string function_name +); - return path; -} \ No newline at end of file +#endif // VEGA_STRIKE_ENGINE_PYTHON_CONFIG_GRAPHICS_CONFIG_H \ No newline at end of file diff --git a/engine/src/python/config/python_utils.cpp b/engine/src/python/config/python_utils.cpp new file mode 100644 index 0000000000..3f0d43d6d0 --- /dev/null +++ b/engine/src/python/config/python_utils.cpp @@ -0,0 +1,109 @@ +/* + * python_utils.cpp + * + * Copyright (c) 2001-2002 Daniel Horn + * Copyright (c) 2002-2019 pyramid3d and other Vega Strike Contributors + * Copyright (c) 2019-2023 Stephen G. Tuggy, Benjamen R. Meyer, Roy Falk and other Vega Strike Contributors + * + * https://github.com/vegastrike/Vega-Strike-Engine-Source + * + * This file is part of Vega Strike. + * + * Vega Strike is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Vega Strike is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Vega Strike. If not, see . + */ + +// -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- + +#include "python_utils.h" + +#include +#include +#include + +using namespace boost::python; +using namespace boost::filesystem; + +#define Q(x) #x +#define QUOTE(x) Q(x) + +// This is a kludge. It runs python before +// just to get the python paths. +const std::string GetPythonPath() { + Py_Initialize(); + wchar_t* w_path_ptr = Py_GetPath(); + Py_Finalize(); + + std::wstring w_path_w( w_path_ptr ); + std::string path( w_path_w.begin(), w_path_w.end() ); + + return path; +} + + + +// A utility function to call a function and get a PyObject as a result +PyObject* GetClassFromPython( + const std::string build_path, + const std::string path_string, + const std::string module_name, + const std::string function_name) { + boost::filesystem::path full_path = boost::filesystem::path(path_string); + boost::filesystem::current_path(full_path); + + if(!boost::filesystem::exists(module_name + ".py")) { + // TODO: throw exception + return nullptr; + } + + const std::string yaml_path = QUOTE(Python_SITELIB); + const std::string python_path_string = GetPythonPath() + + ":" + path_string + + ":" + yaml_path + ":" + build_path; + const std::wstring python_path_wstring = std::wstring(python_path_string.begin(), + python_path_string.end()); + const wchar_t* python_path = python_path_wstring.c_str(); + Py_SetPath(python_path); + Py_Initialize(); + + + PyObject* module = PyImport_ImportModule(module_name.c_str()); + + if(!module) { + std::cerr << "PyImport_ImportModule is null\n" << std::flush; + PyErr_Print(); + Py_Finalize(); + // TODO: throw exception + return nullptr; + } + + PyObject* function = PyObject_GetAttrString(module,function_name.c_str()); + if(!function) { + std::cerr << "PyObject_GetAttrString is null\n" << std::flush; + PyErr_Print(); + Py_Finalize(); + // TODO: throw exception + return nullptr; + } + + + PyObject* pyResult = PyObject_CallObject(function, nullptr); + Py_Finalize(); + + return pyResult; +} + + + + + diff --git a/engine/src/resource/python_utils.h b/engine/src/python/config/python_utils.h similarity index 78% rename from engine/src/resource/python_utils.h rename to engine/src/python/config/python_utils.h index 083f3f1cbd..9c3da9438b 100644 --- a/engine/src/resource/python_utils.h +++ b/engine/src/python/config/python_utils.h @@ -30,6 +30,18 @@ #include +// See https://stackoverflow.com/q/804894/5276890 +struct _object; +typedef _object PyObject; + const std::string GetPythonPath(); +// A utility function to call a function and get a PyObject as a result +PyObject* GetClassFromPython( + const std::string build_path, + const std::string path_string, + const std::string module_name, + const std::string function_name); + + #endif //VEGA_STRIKE_ENGINE_RESOURCE_PYTHON_UTILS_H \ No newline at end of file diff --git a/engine/src/vsfilesystem.cpp b/engine/src/vsfilesystem.cpp index 083930b7e8..00899ce2a2 100644 --- a/engine/src/vsfilesystem.cpp +++ b/engine/src/vsfilesystem.cpp @@ -249,6 +249,7 @@ std::string sharedsprites; std::string savedunitpath; std::string modname; std::string moddir; +std::string programdir; std::string datadir; std::string homedir; diff --git a/engine/src/vsfilesystem.h b/engine/src/vsfilesystem.h index f6624c3059..494dfe3121 100644 --- a/engine/src/vsfilesystem.h +++ b/engine/src/vsfilesystem.h @@ -123,6 +123,7 @@ extern std::string sharedanims; extern std::string sharedsprites; extern std::string savedunitpath; extern std::string moddir; +extern std::string programdir; extern std::string datadir; extern std::string homedir; //User home directory including .vegastrike subdir From bb704d4523a0967ec015fc76ee587f88a6e24827 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Thu, 10 Oct 2024 16:39:19 +0300 Subject: [PATCH 2/6] Restore vegastrike.config file Add prints to identify crashed test --- .../src/configuration/tests/python_tests.cpp | 4 ++- .../src/configuration/tests/vegastrike.config | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 engine/src/configuration/tests/vegastrike.config diff --git a/engine/src/configuration/tests/python_tests.cpp b/engine/src/configuration/tests/python_tests.cpp index 80c74f457f..ca161b0722 100644 --- a/engine/src/configuration/tests/python_tests.cpp +++ b/engine/src/configuration/tests/python_tests.cpp @@ -139,11 +139,13 @@ TEST(Python, Config) { std::cout << "test_path: " << test_path << std::endl; std::cout << "lib_path: " << lib_path << std::endl; + std::cout << "Try to run GetClassFromPython." << std::endl; PyObject* object = GetClassFromPython( lib_path.string(), test_path.string(), "config", "get_config"); - + std::cout << "Ran GetClassFromPython successfully. Got " << object << std::endl; + Graphics2Config& cfg2 = extract(object); EXPECT_EQ(cfg2.screen, 0); EXPECT_EQ(cfg2.resolution_x, 2560); diff --git a/engine/src/configuration/tests/vegastrike.config b/engine/src/configuration/tests/vegastrike.config new file mode 100644 index 0000000000..3bbacfaa43 --- /dev/null +++ b/engine/src/configuration/tests/vegastrike.config @@ -0,0 +1,32 @@ + + +
+ + + + + +
+ + + + + +
+
+
+ + + + + +
+ + + + + +
+
+
+
From 5a78db8b7f75f0e4fd841fa6f66a51a3241280e6 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Sat, 12 Oct 2024 22:12:46 +0300 Subject: [PATCH 3/6] Remove yaml support. Move config loading back to cpp. --- engine/CMakeLists.txt | 11 ++-- engine/src/configuration/configuration.cpp | 11 ++-- engine/src/configuration/tests/config.py | 24 --------- engine/src/configuration/tests/config.yaml | 8 --- .../src/configuration/tests/python_tests.cpp | 23 -------- engine/src/python/config/graphics_config.cpp | 52 +++++++++++++------ engine/src/python/config/graphics_config.h | 8 +-- 7 files changed, 47 insertions(+), 90 deletions(-) delete mode 100644 engine/src/configuration/tests/config.py delete mode 100644 engine/src/configuration/tests/config.yaml diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 8e3fb92de5..06b3278fbd 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -1784,22 +1784,17 @@ IF (USE_GTEST) ENDIF() FILE( - COPY "src/cmd/tests/units.json" - DESTINATION ${CMAKE_BINARY_DIR}/test_assets - ) - - FILE( - COPY "src/configuration/tests/python_tests.py" + COPY "src/configuration/tests/vegastrike.config" DESTINATION ${CMAKE_BINARY_DIR}/test_assets ) FILE( - COPY "src/configuration/tests/config.py" + COPY "src/cmd/tests/units.json" DESTINATION ${CMAKE_BINARY_DIR}/test_assets ) FILE( - COPY "src/configuration/tests/config.yaml" + COPY "src/configuration/tests/python_tests.py" DESTINATION ${CMAKE_BINARY_DIR}/test_assets ) diff --git a/engine/src/configuration/configuration.cpp b/engine/src/configuration/configuration.cpp index 4120fb6126..29aac0c2ad 100644 --- a/engine/src/configuration/configuration.cpp +++ b/engine/src/configuration/configuration.cpp @@ -30,16 +30,17 @@ #endif #include -#include "vsfilesystem.h" +#include using vega_config::GetGameConfig; Configuration::Configuration() { //logging.verbose_debug = GetGameConfig().GetBool("data.verbose_debug", false); - graphics2_config = GetGraphics2Config( - VSFileSystem::programdir, - VSFileSystem::datadir, - "config", "get_config"); + std::ifstream ifs("config.json", std::ifstream::in); + std::stringstream buffer; + buffer << ifs.rdbuf(); + const std::string json_text = buffer.str(); + graphics2_config = Graphics2Config(json_text); } /* Override the default value(provided by constructor) with the value from the user specified configuration file, if any. diff --git a/engine/src/configuration/tests/config.py b/engine/src/configuration/tests/config.py deleted file mode 100644 index 34385b7e30..0000000000 --- a/engine/src/configuration/tests/config.py +++ /dev/null @@ -1,24 +0,0 @@ -import yaml -import vegastrike_python - - -def get_config(): - with open('config.yaml', 'r') as file: - yaml_file = yaml.safe_load(file) - print(yaml_file) - - graphics = vegastrike_python.GraphicsConfig() - graphics.screen = yaml_file['graphics']['screen'] - graphics.resolution_x = yaml_file['graphics']['resolution_x'] - graphics.resolution_y = yaml_file['graphics']['resolution_y'] - - - return graphics - - -#gfx = get_config() -#print('screen: ', gfx.screen) -#print('x: ', gfx.resolution_x) -#print('y: ', gfx.resolution_y) - - diff --git a/engine/src/configuration/tests/config.yaml b/engine/src/configuration/tests/config.yaml deleted file mode 100644 index 819b1e7e12..0000000000 --- a/engine/src/configuration/tests/config.yaml +++ /dev/null @@ -1,8 +0,0 @@ -general: - -graphics: - resolution_x: 2560 - resolution_y: 1600 - screen: 0 - -advanced: diff --git a/engine/src/configuration/tests/python_tests.cpp b/engine/src/configuration/tests/python_tests.cpp index ca161b0722..b508cb2ca9 100644 --- a/engine/src/configuration/tests/python_tests.cpp +++ b/engine/src/configuration/tests/python_tests.cpp @@ -131,26 +131,3 @@ TEST(Python, Call_Function) { // Uncomment to see prints //EXPECT_FALSE(true); } - -// Test ability to get config file from python -TEST(Python, Config) { - boost::filesystem::path test_path(boost::filesystem::current_path()); - boost::filesystem::path lib_path = test_path.parent_path(); - std::cout << "test_path: " << test_path << std::endl; - std::cout << "lib_path: " << lib_path << std::endl; - - std::cout << "Try to run GetClassFromPython." << std::endl; - PyObject* object = GetClassFromPython( - lib_path.string(), - test_path.string(), - "config", "get_config"); - std::cout << "Ran GetClassFromPython successfully. Got " << object << std::endl; - - Graphics2Config& cfg2 = extract(object); - EXPECT_EQ(cfg2.screen, 0); - EXPECT_EQ(cfg2.resolution_x, 2560); - EXPECT_EQ(cfg2.resolution_y, 1600); - - // Uncomment to see prints*/ - //EXPECT_FALSE(true); -} diff --git a/engine/src/python/config/graphics_config.cpp b/engine/src/python/config/graphics_config.cpp index 84076135c5..d165a243dd 100644 --- a/engine/src/python/config/graphics_config.cpp +++ b/engine/src/python/config/graphics_config.cpp @@ -1,30 +1,50 @@ #include -#include #include #include "graphics_config.h" -#include "python_utils.h" +#include "json.h" - - -BOOST_PYTHON_MODULE(vegastrike_python) { +// Exposes the struct to python +// TODO: move this somewhere as the same library should have multiple +// definitions +// Can we spread a boost python module over several files? +/*BOOST_PYTHON_MODULE(vegastrike_python) { boost::python::class_("GraphicsConfig", boost::python::init<>()) .def_readwrite("screen", &Graphics2Config::screen) .def_readwrite("resolution_x", &Graphics2Config::resolution_x) .def_readwrite("resolution_y", &Graphics2Config::resolution_y); +}*/ + +// a temporary helper function until we move to Boost/JSON +// TODO: remove +static const int GetValue( + const std::string key, + const int default_value, + const json::jobject object) { + if(!object.has_key(key)) { + return default_value; + } + + const std::string attribute = object.get(key); + const int value = std::stoi(attribute); + return value; +} + +Graphics2Config::Graphics2Config(const std::string config) { + json::jobject json_root = json::jobject::parse(config); + + if(!json_root.has_key("graphics")) { + return; + } + + const std::string graphics_json = json_root.get("graphics"); + json::jobject json_graphics = json::jobject::parse(config); + + screen = GetValue("screen", 0, json_graphics); + resolution_x = GetValue("resolution_x", 2560, json_graphics); + resolution_y = GetValue("resolution_y", 1600, json_graphics); } -Graphics2Config GetGraphics2Config( - const std::string build_path, - const std::string path_string, - const std::string file_name, - const std::string function_name) { - PyObject* object = GetClassFromPython( - build_path, path_string, file_name, function_name); - - Graphics2Config cfg2 = boost::python::extract(object); - return cfg2; -} \ No newline at end of file diff --git a/engine/src/python/config/graphics_config.h b/engine/src/python/config/graphics_config.h index 2b0b818662..f0df85d55c 100644 --- a/engine/src/python/config/graphics_config.h +++ b/engine/src/python/config/graphics_config.h @@ -35,13 +35,9 @@ struct Graphics2Config { int resolution_y{1080}; Graphics2Config() = default; + Graphics2Config(const std::string config); }; -Graphics2Config GetGraphics2Config( - const std::string build_path, - const std::string path_string, - const std::string file_name, - const std::string function_name -); + #endif // VEGA_STRIKE_ENGINE_PYTHON_CONFIG_GRAPHICS_CONFIG_H \ No newline at end of file From e61c676b8896042f7ea9be5014b72cb3d1d03e22 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Sun, 13 Oct 2024 08:06:22 +0300 Subject: [PATCH 4/6] Fix issue with JSON parsing --- engine/src/python/config/graphics_config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/python/config/graphics_config.cpp b/engine/src/python/config/graphics_config.cpp index d165a243dd..a255b99057 100644 --- a/engine/src/python/config/graphics_config.cpp +++ b/engine/src/python/config/graphics_config.cpp @@ -38,7 +38,7 @@ Graphics2Config::Graphics2Config(const std::string config) { } const std::string graphics_json = json_root.get("graphics"); - json::jobject json_graphics = json::jobject::parse(config); + json::jobject json_graphics = json::jobject::parse(graphics_json); screen = GetValue("screen", 0, json_graphics); resolution_x = GetValue("resolution_x", 2560, json_graphics); From d43403c8e5f173c697135d239c97d43fb16e24e3 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Mon, 14 Oct 2024 23:38:23 +0300 Subject: [PATCH 5/6] Hopefully fix build breaks Move graphics_config from python to configuration folder and out of python library. Remove empty files without code. --- engine/CMakeLists.txt | 6 +-- engine/objconv/CMakeLists.txt | 1 - engine/src/abstract_config.cpp | 16 -------- engine/src/abstract_config.h | 39 ------------------- engine/src/cmd/missile.cpp | 1 - engine/src/cmd/unit_generic.cpp | 1 - engine/src/cmd/unit_generic.h | 1 - engine/src/configuration/configuration.h | 2 +- .../graphics_config.cpp | 0 .../graphics_config.h | 0 .../src/configuration/tests/python_tests.cpp | 1 - engine/src/endianness.cpp | 27 ------------- engine/src/galaxy_utils.cpp | 2 - engine/src/gfx/cockpit_generic.cpp | 1 - engine/src/gfx/radar/sensor.cpp | 2 +- engine/src/hashtable.cpp | 27 ------------- engine/src/libserver.cpp | 1 - engine/src/load_mission.cpp | 1 - engine/src/star_system_generic.cpp | 27 ------------- engine/src/star_system_generic.h | 26 ------------- engine/src/star_system_xml.cpp | 1 - engine/src/universe_util_generic.cpp | 1 - engine/src/universe_util_server.cpp | 1 - 23 files changed, 3 insertions(+), 182 deletions(-) delete mode 100644 engine/src/abstract_config.cpp delete mode 100644 engine/src/abstract_config.h rename engine/src/{python/config => configuration}/graphics_config.cpp (100%) rename engine/src/{python/config => configuration}/graphics_config.h (100%) delete mode 100644 engine/src/endianness.cpp delete mode 100644 engine/src/hashtable.cpp delete mode 100644 engine/src/star_system_generic.cpp delete mode 100644 engine/src/star_system_generic.h diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 06b3278fbd..fbd770524c 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -698,9 +698,9 @@ SET(LIBVS_LOGGING ) SET(LIBCONFIG - src/abstract_config.cpp src/configuration/configuration.cpp src/configuration/game_config.cpp + src/configuration/graphics_config.cpp ) SET(LIBDAMAGE @@ -721,7 +721,6 @@ SET(LIBRESOURCE SET(LIBPYTHON src/python/config/python_utils.cpp - src/python/config/graphics_config.cpp ) SET(LIBCOMPONENT @@ -1041,7 +1040,6 @@ SET(LIBROOTGENERIC_SOURCES src/atmospheric_fog_mesh.cpp src/configxml.cpp src/easydom.cpp - src/endianness.cpp src/macosx_math.cpp src/faction_generic.cpp src/faction_util_generic.cpp @@ -1049,14 +1047,12 @@ SET(LIBROOTGENERIC_SOURCES src/galaxy_gen.cpp src/galaxy_xml.cpp src/galaxy_utils.cpp - src/hashtable.cpp src/lin_time.cpp src/load_mission.cpp src/pk3.cpp src/posh.cpp src/savegame.cpp src/system_factory.cpp - src/star_system_generic.cpp src/star_system_xml.cpp src/stardate.cpp src/universe_globals.cpp diff --git a/engine/objconv/CMakeLists.txt b/engine/objconv/CMakeLists.txt index 8170d5bbfc..aba9e8cdd8 100644 --- a/engine/objconv/CMakeLists.txt +++ b/engine/objconv/CMakeLists.txt @@ -88,7 +88,6 @@ SET(MESHER_SOURCES mesher/Modules/XMesh_to_BFXM.cpp mesher/Modules/XMesh_to_Ogre.cpp mesher/Modules/Wavefront_to_BFXM.cpp - ${Vega_Strike_SOURCE_DIR}/src/hashtable.cpp ${Vega_Strike_SOURCE_DIR}/src/xml_support.cpp ) diff --git a/engine/src/abstract_config.cpp b/engine/src/abstract_config.cpp deleted file mode 100644 index 9be9523f8b..0000000000 --- a/engine/src/abstract_config.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "abstract_config.h" - -// This is probably unique enough to ensure no collision -/*string AbstractConfig::DEFAULT_ERROR_VALUE = "AbstractConfig::_GetVariable DEFAULT_ERROR_VALUE"; - -AbstractConfig::AbstractConfig() -{ - -} - -inline std::string AbstractConfig::ValidateVariable(std::string const &result, - std::string const &default_value) { - if(result == DEFAULT_ERROR_VALUE || result.empty()) { - return default_value; - } -}*/ diff --git a/engine/src/abstract_config.h b/engine/src/abstract_config.h deleted file mode 100644 index c5aad68e16..0000000000 --- a/engine/src/abstract_config.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2001-2023 Daniel Horn, pyramid3d, Stephen G. Tuggy, Benjamen R. Meyer, - * and other Vega Strike contributors. - * - * https://github.com/vegastrike/Vega-Strike-Engine-Source - * - * This file is part of Vega Strike. - * - * Vega Strike is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Vega Strike is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Vega Strike. If not, see . - */ -#ifndef VEGA_STRIKE_ENGINE_ABSTRACT_CONFIG_H -#define VEGA_STRIKE_ENGINE_ABSTRACT_CONFIG_H - -#include - -class AbstractConfig { -private: - static std::string DEFAULT_ERROR_VALUE; - virtual inline std::string _GetStringVariable(std::string const §ion, std::string const &name) = 0; - - //template - //inline T GetVariable(std::string const &result, std::string const &default_value); - -public: - AbstractConfig(); -}; - -#endif //VEGA_STRIKE_ENGINE_ABSTRACT_CONFIG_H diff --git a/engine/src/cmd/missile.cpp b/engine/src/cmd/missile.cpp index 01a2945646..4d708c4638 100644 --- a/engine/src/cmd/missile.cpp +++ b/engine/src/cmd/missile.cpp @@ -32,7 +32,6 @@ #include "configxml.h" #include "images.h" #include "collection.h" -#include "star_system_generic.h" #include "role_bitmask.h" #include "ai/order.h" #include "faction_generic.h" diff --git a/engine/src/cmd/unit_generic.cpp b/engine/src/cmd/unit_generic.cpp index e93efabdf7..ada773aa15 100644 --- a/engine/src/cmd/unit_generic.cpp +++ b/engine/src/cmd/unit_generic.cpp @@ -1025,7 +1025,6 @@ bool Unit::jumpReactToCollision(Unit *smalle) { ))) || forcejump) { //or the jump is being forced? - //NOW done in star_system_generic.cpp before TransferUnitToSystem smalle->warpenergy-=smalle->GetJumpStatus().energy; int dest = smalle->GetJumpStatus().drive; if (dest < 0) { dest = 0; diff --git a/engine/src/cmd/unit_generic.h b/engine/src/cmd/unit_generic.h index 088b887e71..d6eb2226d8 100644 --- a/engine/src/cmd/unit_generic.h +++ b/engine/src/cmd/unit_generic.h @@ -69,7 +69,6 @@ void UncheckUnit( class Unit*un ); #include "collection.h" #include "script/flightgroup.h" #include "faction_generic.h" -#include "star_system_generic.h" #include "gfx/cockpit_generic.h" #include "vsfilesystem.h" #include "collide_map.h" diff --git a/engine/src/configuration/configuration.h b/engine/src/configuration/configuration.h index 1c569f90d2..e515387c54 100644 --- a/engine/src/configuration/configuration.h +++ b/engine/src/configuration/configuration.h @@ -30,7 +30,7 @@ #include #include -#include "python/config/graphics_config.h" +#include "graphics_config.h" namespace vega_config { // Config Structs Declaration diff --git a/engine/src/python/config/graphics_config.cpp b/engine/src/configuration/graphics_config.cpp similarity index 100% rename from engine/src/python/config/graphics_config.cpp rename to engine/src/configuration/graphics_config.cpp diff --git a/engine/src/python/config/graphics_config.h b/engine/src/configuration/graphics_config.h similarity index 100% rename from engine/src/python/config/graphics_config.h rename to engine/src/configuration/graphics_config.h diff --git a/engine/src/configuration/tests/python_tests.cpp b/engine/src/configuration/tests/python_tests.cpp index b508cb2ca9..110a1dcf9d 100644 --- a/engine/src/configuration/tests/python_tests.cpp +++ b/engine/src/configuration/tests/python_tests.cpp @@ -31,7 +31,6 @@ #include #include "python/config/python_utils.h" -#include "python/config/graphics_config.h" using namespace boost::python; diff --git a/engine/src/endianness.cpp b/engine/src/endianness.cpp deleted file mode 100644 index 579766a2ac..0000000000 --- a/engine/src/endianness.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/** -* endianness.cpp -* -* Copyright (c) 2001-2002 Daniel Horn -* Copyright (c) 2002-2019 pyramid3d and other Vega Strike Contributors -* Copyright (c) 2019-2021 Stephen G. Tuggy, and other Vega Strike Contributors -* -* https://github.com/vegastrike/Vega-Strike-Engine-Source -* -* This file is part of Vega Strike. -* -* Vega Strike is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 2 of the License, or -* (at your option) any later version. -* -* Vega Strike is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Vega Strike. If not, see . -*/ - -#include "endianness.h" - diff --git a/engine/src/galaxy_utils.cpp b/engine/src/galaxy_utils.cpp index 19ea68f784..94b296b0c1 100644 --- a/engine/src/galaxy_utils.cpp +++ b/engine/src/galaxy_utils.cpp @@ -20,7 +20,6 @@ * along with Vega Strike. If not, see . */ -#include "star_system_generic.h" #include "cmd/script/mission.h" #include "universe.h" #include "galaxy_xml.h" @@ -30,7 +29,6 @@ #include "vs_globals.h" #include "xml_support.h" #include "lin_time.h" -#include "star_system_generic.h" #include "options.h" diff --git a/engine/src/gfx/cockpit_generic.cpp b/engine/src/gfx/cockpit_generic.cpp index b2ed5a66e0..7eed124d2d 100644 --- a/engine/src/gfx/cockpit_generic.cpp +++ b/engine/src/gfx/cockpit_generic.cpp @@ -30,7 +30,6 @@ #include "vs_globals.h" #include "vegastrike.h" #include "cockpit_generic.h" -#include "star_system_generic.h" #include "cmd/unit_generic.h" #include "cmd/unit_util.h" #include "cmd/collection.h" diff --git a/engine/src/gfx/radar/sensor.cpp b/engine/src/gfx/radar/sensor.cpp index dd9c874fe1..972477522a 100644 --- a/engine/src/gfx/radar/sensor.cpp +++ b/engine/src/gfx/radar/sensor.cpp @@ -34,7 +34,7 @@ #include "sensor.h" #include "universe.h" -extern Unit *getTopLevelOwner(); // WTF... located in star_system_generic.cpp +extern Unit *getTopLevelOwner(); // located in star_system.cpp namespace Radar { diff --git a/engine/src/hashtable.cpp b/engine/src/hashtable.cpp deleted file mode 100644 index 95aec4f40f..0000000000 --- a/engine/src/hashtable.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/** -* hashtable.cpp -* -* Copyright (c) 2001-2002 Daniel Horn -* Copyright (c) 2002-2019 pyramid3d and other Vega Strike Contributors -* Copyright (c) 2019-2021 Stephen G. Tuggy, and other Vega Strike Contributors -* -* https://github.com/vegastrike/Vega-Strike-Engine-Source -* -* This file is part of Vega Strike. -* -* Vega Strike is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 2 of the License, or -* (at your option) any later version. -* -* Vega Strike is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Vega Strike. If not, see . -*/ - -/* removed */ - diff --git a/engine/src/libserver.cpp b/engine/src/libserver.cpp index 88fdd032d8..e2d9f4b7bc 100644 --- a/engine/src/libserver.cpp +++ b/engine/src/libserver.cpp @@ -22,7 +22,6 @@ #include "vs_globals.h" #include "configxml.h" -#include "star_system_generic.h" #include "cmd/unit_generic.h" VegaConfig *createVegaConfig(const char *file) { diff --git a/engine/src/load_mission.cpp b/engine/src/load_mission.cpp index b71826446d..0bdd4230fb 100644 --- a/engine/src/load_mission.cpp +++ b/engine/src/load_mission.cpp @@ -29,7 +29,6 @@ #include "cmd/script/mission.h" #include "cmd/script/pythonmission.h" #include "vs_globals.h" -#include "star_system_generic.h" #include "vsfilesystem.h" #include "vs_logging.h" #include "cmd/unit_generic.h" diff --git a/engine/src/star_system_generic.cpp b/engine/src/star_system_generic.cpp deleted file mode 100644 index d6f1acaa3f..0000000000 --- a/engine/src/star_system_generic.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/** -* star_system_generic.cpp -* -* Copyright (c) 2001-2002 Daniel Horn -* Copyright (c) 2002-2019 pyramid3d and other Vega Strike Contributors -* Copyright (c) 2019-2021 Stephen G. Tuggy, and other Vega Strike Contributors -* -* https://github.com/vegastrike/Vega-Strike-Engine-Source -* -* This file is part of Vega Strike. -* -* Vega Strike is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 2 of the License, or -* (at your option) any later version. -* -* Vega Strike is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Vega Strike. If not, see . -*/ - - - diff --git a/engine/src/star_system_generic.h b/engine/src/star_system_generic.h deleted file mode 100644 index 31705c2fb6..0000000000 --- a/engine/src/star_system_generic.h +++ /dev/null @@ -1,26 +0,0 @@ -/** -* star_system_generic.h -* -* Copyright (c) 2001-2002 Daniel Horn -* Copyright (c) 2002-2019 pyramid3d and other Vega Strike Contributors -* Copyright (c) 2019-2023 Stephen G. Tuggy, Benjamen R. Meyer, and other Vega Strike Contributors -* -* https://github.com/vegastrike/Vega-Strike-Engine-Source -* -* This file is part of Vega Strike. -* -* Vega Strike is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 2 of the License, or -* (at your option) any later version. -* -* Vega Strike is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Vega Strike. If not, see . -*/ -// NO HEADER GUARD - diff --git a/engine/src/star_system_xml.cpp b/engine/src/star_system_xml.cpp index db2272a21c..40cda36b5a 100644 --- a/engine/src/star_system_xml.cpp +++ b/engine/src/star_system_xml.cpp @@ -23,7 +23,6 @@ #include #include "xml_support.h" -#include "star_system_generic.h" #include "cmd/planet.h" #include "vs_globals.h" #include "vsfilesystem.h" diff --git a/engine/src/universe_util_generic.cpp b/engine/src/universe_util_generic.cpp index 6f3aa23764..33322d0895 100644 --- a/engine/src/universe_util_generic.cpp +++ b/engine/src/universe_util_generic.cpp @@ -32,7 +32,6 @@ #include "universe_util.h" #include "cmd/unit_generic.h" #include "cmd/collection.h" -#include "star_system_generic.h" #include #include #include "savegame.h" diff --git a/engine/src/universe_util_server.cpp b/engine/src/universe_util_server.cpp index 1aeee8a723..18546cb8a6 100644 --- a/engine/src/universe_util_server.cpp +++ b/engine/src/universe_util_server.cpp @@ -27,7 +27,6 @@ #include "cmd/unit_factory.h" //for UnitFactory::getMasterPartList() #include "cmd/collection.h" #include "networking/netserver.h" -#include "star_system_generic.h" #include #include "lin_time.h" #include "load_mission.h" From ebacccb9d00f5bf5297cb51110b958fe09df6f32 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Wed, 16 Oct 2024 07:06:16 +0300 Subject: [PATCH 6/6] Try and apply fPIC to python lib compilation --- engine/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index b5db691357..2d414249a9 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -1139,6 +1139,10 @@ ADD_LIBRARY(vegastrike_python SHARED ${LIBPYTHON} ) +TARGET_COMPILE_OPTIONS( + vegastrike_python PRIVATE -fPIC +) + TARGET_LINK_LIBRARIES( vegastrike_python ${Boost_LIBRARIES}