diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2186c6e..54c2b4f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,18 +43,6 @@ ucm_add_dirs(TO SOURCES "utils/base64") ucm_add_dirs(TO SOURCES "utils/aabb") ucm_add_dirs(TO SOURCES "core/rendering") -message(${SOURCES}) - -if(MSVC) - list(APPEND SOURCES - rcrl/rcrl.h - rcrl/rcrl.cpp - rcrl/rcrl_parser.h - rcrl/rcrl_parser.cpp - rcrl/rcrl_for_plugin.h - ) -endif() - # this cannot go inside the game executable because the doctest header is included by the precompiled header in all source files add_library(doctest_runner SHARED utils/doctest/doctest_runner.cpp utils/doctest/doctest_proxy.h) @@ -68,6 +56,11 @@ add_plugin(NAME camera ${plugin_camera}) # ========= PLUGINS END ========= +if(MSVC AND ${WITH_PLUGINS}) + # add the sources to the game project + ucm_add_dirs(TO SOURCES "rcrl") +endif() + add_executable(game "${SOURCES};${PLUGIN_SOURCES}") add_precompiled_header(game "${CMAKE_CURRENT_SOURCE_DIR}/precompiled.h") @@ -95,6 +88,43 @@ if(WIN32) target_link_libraries(game nativefiledialog) endif() +# ========= REPL ============= + +if(MSVC AND ${WITH_PLUGINS}) + # the file that will + set(plugin_file ${PROJECT_BINARY_DIR}/plugin.cpp) + # touch the file so it exists + file(WRITE ${plugin_file} "") + + # defines needed for RCRL integration + target_compile_definitions(game PRIVATE "RCRL_PLUGIN_FILE=\"${plugin_file}\"") + target_compile_definitions(game PRIVATE "RCRL_PLUGIN_NAME=\"plugin\"") + target_compile_definitions(game PRIVATE "RCRL_BUILD_FOLDER=\"${PROJECT_BINARY_DIR}\"") + target_compile_definitions(game PRIVATE "RCRL_BIN_FOLDER=\"$/\"") + target_compile_definitions(game PRIVATE "RCRL_EXTENSION=\"${CMAKE_SHARED_LIBRARY_SUFFIX}\"") + if(${CMAKE_GENERATOR} MATCHES "Visual Studio" OR ${CMAKE_GENERATOR} MATCHES "Xcode") + target_compile_definitions(game PRIVATE "RCRL_CONFIG=\"$\"") + endif() + + # the plugin target that will be recompiled and loaded by RCRL + add_library(repl_plugin SHARED EXCLUDE_FROM_ALL ${plugin_file}) + # link the RCRL plugin with the host app so we can call stuff from it + target_link_libraries(repl_plugin game) + # exclude it even for Visual Studio when building the whole solution (EXCLUDE_FROM_ALL is not enough) + set_target_properties(repl_plugin PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1) + # no 'lib' prefix for some compilers/platforms - simplifies my code + set_target_properties(repl_plugin PROPERTIES PREFIX "") + # we don't want .pdb files for the plugin because when we are within Visual Studio and debugging the application it locks + # the .pdb for the original .dll and subsequent compiles fail even though we have loaded copies of the original .dll + # can also use /PDBALTPATH - https://blog.molecular-matters.com/2014/05/10/using-runtime-compiled-c-code-as-a-scripting-language-under-the-hood/ + set_target_properties(repl_plugin PROPERTIES LINK_FLAGS /DEBUG:NONE) + + # add a precompiled header + add_precompiled_header(repl_plugin "${CMAKE_CURRENT_SOURCE_DIR}/precompiled.h") +endif() + +# ========= REPL END ========= + if(TOOLCHAIN STREQUAL "js") set_target_properties(game PROPERTIES SUFFIX ".html") else() diff --git a/src/core/Object.h b/src/core/Object.h index 6af182e..95b8d10 100644 --- a/src/core/Object.h +++ b/src/core/Object.h @@ -46,7 +46,8 @@ class ATTRS(export, nomsg) Object : public dynamix::object { friend class ObjectManager; -#include + //#include + HA_EXPORTED_FRIENDS_OF_TYPE(Object); oid m_id; oid m_parent; diff --git a/src/utils/preprocessor.h b/src/utils/preprocessor.h index 599c2b2..6f5f740 100644 --- a/src/utils/preprocessor.h +++ b/src/utils/preprocessor.h @@ -84,7 +84,13 @@ struct print_ct; callback; \ } -//void gather_oids_mixins(std::vector& out); +#define HA_FRIENDS_OF_TYPE_COMMON(export, type) \ + friend export void serialize(const type& src, JsonData& out); \ + friend export size_t deserialize(type& dest, const sajson::value& val); \ + friend export cstr imgui_bind_attributes(Object& e, cstr mixin, type& obj) + +#define HA_FRIENDS_OF_TYPE(type) HA_FRIENDS_OF_TYPE_COMMON(HA_EMPTY(), type) +#define HA_EXPORTED_FRIENDS_OF_TYPE(type) HA_FRIENDS_OF_TYPE_COMMON(HAPI, type) // helpers that don't expand to anything - used by the type parser #define ATTRS(...) // list attributes and tags in a comma-separated fashion using this