commit bf91297e83792f44beb515dcc68bb24af604f88e Author: Green Sky Date: Mon Jun 10 20:11:25 2024 +0200 setup empty husk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cfa7815 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +.vs/ +*.o +*.swp +~* +*~ +.idea/ +cmake-build-debug/ +cmake-build-debugandtest/ +cmake-build-release/ +*.stackdump +*.coredump +compile_commands.json +/build* +/result* +.clangd +.cache + +.DS_Store +.AppleDouble +.LSOverride + +CMakeLists.txt.user* +CMakeCache.txt + +*.tox +imgui.ini +/out +CMakePresets.json +CMakeUserPresets.json +CMakeSettings.json \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4607f70 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,72 @@ +cmake_minimum_required(VERSION 3.24 FATAL_ERROR) + +# cmake setup begin +project(solanaceae_factorio) + +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(SOLANACEAE_FACTORIO_STANDALONE ON) +else() + set(SOLANACEAE_FACTORIO_STANDALONE OFF) +endif() +message("II SOLANACEAE_FACTORIO_STANDALONE " ${SOLANACEAE_FACTORIO_STANDALONE}) + +option(SOLANACEAE_FACTORIO_BUILD_PLUGINS "Build the factorio plugins" ${SOLANACEAE_FACTORIO_STANDALONE}) + +if (SOLANACEAE_FACTORIO_STANDALONE) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + + # defaulting to debug mode, if not specified + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") + endif() + + # setup my vim ycm :D + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + # more paths + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") +endif() + +# external libs +add_subdirectory(./external EXCLUDE_FROM_ALL) # before increasing warn levels, sad :( + +if (SOLANACEAE_FACTORIO_STANDALONE) + set(CMAKE_CXX_EXTENSIONS OFF) + + # bump up warning levels appropriately for clang, gcc & msvc + if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") + add_compile_options( + -Wall -Wextra # Reasonable and standard + -Wpedantic # Warn if non-standard C++ is used + -Wunused # Warn on anything being unused + #-Wconversion # Warn on type conversions that may lose data + #-Wsign-conversion # Warn on sign conversions + -Wshadow # Warn if a variable declaration shadows one from a parent context + ) + + if (NOT WIN32) + #link_libraries(-fsanitize=address) + #link_libraries(-fsanitize=address,undefined) + #link_libraries(-fsanitize-address-use-after-scope) + #link_libraries(-fsanitize=undefined) + endif() + elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") + if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() + endif() + +endif() + +# cmake setup end + +add_subdirectory(./src) + +if (SOLANACEAE_FACTORIO_BUILD_PLUGINS) + add_subdirectory(./plugins) +endif() + diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt new file mode 100644 index 0000000..a65aa38 --- /dev/null +++ b/external/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.24 FATAL_ERROR) + +include(FetchContent) + +if (NOT TARGET solanaceae_message3) + FetchContent_Declare(solanaceae_message3 + GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_message3.git + GIT_TAG master + EXCLUDE_FROM_ALL + ) + FetchContent_MakeAvailable(solanaceae_message3) +endif() + +if (NOT TARGET solanaceae_plugin) + FetchContent_Declare(solanaceae_plugin + GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_plugin.git + GIT_TAG master + EXCLUDE_FROM_ALL + ) + FetchContent_MakeAvailable(solanaceae_plugin) +endif() + diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt new file mode 100644 index 0000000..efd03ff --- /dev/null +++ b/plugins/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR) + +add_library(plugin_factorio SHARED + ./plugin_factorio.cpp +) + +target_link_libraries(plugin_factorio PUBLIC + solanaceae_plugin + solanaceae_factorio +) + +set_target_properties(plugin_factorio PROPERTIES + C_VISIBILITY_PRESET hidden +) +# probably not enough +target_compile_definitions(plugin_factorio PUBLIC ENTT_API_IMPORT) + diff --git a/plugins/plugin_factorio.cpp b/plugins/plugin_factorio.cpp new file mode 100644 index 0000000..cbf1dcc --- /dev/null +++ b/plugins/plugin_factorio.cpp @@ -0,0 +1,61 @@ +#include + +#include +#include + +#include "factorio.hpp" + +#include + +static std::unique_ptr g_f = nullptr; + +constexpr const char* plugin_name = "Factorio"; + +extern "C" { + +SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) { + return plugin_name; +} + +SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { + return SOLANA_PLUGIN_VERSION; +} + +SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) { + std::cout << "PLUGIN " << plugin_name << " START()\n"; + + if (solana_api == nullptr) { + return 1; + } + + try { + auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1"); + auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel); + + // static store, could be anywhere tho + // construct with fetched dependencies + g_f = std::make_unique(*cr, *rmm); + + // register types + PLUG_PROVIDE_INSTANCE(Factorio, plugin_name, g_f.get()); + } catch (const ResolveException& e) { + std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n"; + return 2; + } + + return 0; +} + +SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) { + std::cout << "PLUGIN " << plugin_name << " STOP()\n"; + + g_f.reset(); +} + +SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float) { + //return g_rpbot->tick(delta); + return 1000.f; +} + +} // extern C + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..4f98e5a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR) + +project(solanaceae) + +add_library(solanaceae_factorio + ./factorio.hpp + ./factorio.cpp +) + +target_include_directories(solanaceae_factorio PUBLIC .) +target_compile_features(solanaceae_factorio PUBLIC cxx_std_17) +target_link_libraries(solanaceae_factorio PUBLIC + solanaceae_message3 +) + +######################################## + diff --git a/src/factorio.cpp b/src/factorio.cpp new file mode 100644 index 0000000..84d325d --- /dev/null +++ b/src/factorio.cpp @@ -0,0 +1,16 @@ +#include "./factorio.hpp" + +#include +#include + +Factorio::Factorio(Contact3Registry& cr, RegistryMessageModel& rmm) : _cr(cr), _rmm(rmm) { + _rmm.subscribe(this, RegistryMessageModel_Event::message_construct); +} + +Factorio::~Factorio(void) { +} + +bool Factorio::onEvent(const Message::Events::MessageConstruct& e) { + return false; +} + diff --git a/src/factorio.hpp b/src/factorio.hpp new file mode 100644 index 0000000..b9a3937 --- /dev/null +++ b/src/factorio.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include + +class Factorio : public RegistryMessageModelEventI { + Contact3Registry& _cr; + RegistryMessageModel& _rmm; + + public: + Factorio(Contact3Registry& cr, RegistryMessageModel& rmm); + virtual ~Factorio(void); + + protected: // rmm + bool onEvent(const Message::Events::MessageConstruct& e) override; + +}; +