diff --git a/.gitignore b/.gitignore index 56f48bf..f6c4767 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ CMakeCache.txt *.tox imgui.ini + +*.wad +*.WAD diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index f3b601d..4285d0b 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -2,16 +2,6 @@ cmake_minimum_required(VERSION 3.24 FATAL_ERROR) include(FetchContent) -# TODO: move entt dep into solanaceae_contact -if (NOT TARGET EnTT::EnTT) - FetchContent_Declare(EnTT - GIT_REPOSITORY https://github.com/skypjack/entt.git - GIT_TAG v3.12.2 - EXCLUDE_FROM_ALL - ) - FetchContent_MakeAvailable(EnTT) -endif() - #if (NOT TARGET solanaceae_util) #FetchContent_Declare(solanaceae_util #GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_util.git @@ -21,14 +11,14 @@ endif() #FetchContent_MakeAvailable(solanaceae_util) #endif() -#if (NOT TARGET solanaceae_contact) - #FetchContent_Declare(solanaceae_contact - #GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_contact.git - #GIT_TAG master - #EXCLUDE_FROM_ALL - #) - #FetchContent_MakeAvailable(solanaceae_contact) -#endif() +if (NOT TARGET solanaceae_contact) + FetchContent_Declare(solanaceae_contact + GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_contact.git + GIT_TAG master + EXCLUDE_FROM_ALL + ) + FetchContent_MakeAvailable(solanaceae_contact) +endif() #if (NOT TARGET solanaceae_message3) #FetchContent_Declare(solanaceae_message3 @@ -64,3 +54,36 @@ if (NOT TARGET PureDOOM) add_subdirectory(./pure_doom) endif() +if (NOT TARGET imgui) + FetchContent_Declare(imgui + GIT_REPOSITORY https://github.com/ocornut/imgui.git + GIT_TAG d6cb3c9 # v1.90.1 + EXCLUDE_FROM_ALL + ) + + # imgui does not provide a cmake + FetchContent_GetProperties(imgui) + if(NOT imgui_POPULATED) + FetchContent_Populate(imgui) + + add_library(imgui STATIC + ${imgui_SOURCE_DIR}/imgui.h + ${imgui_SOURCE_DIR}/imgui_internal.h + + ${imgui_SOURCE_DIR}/imgui.cpp + ${imgui_SOURCE_DIR}/imgui_demo.cpp + ${imgui_SOURCE_DIR}/imgui_draw.cpp + ${imgui_SOURCE_DIR}/imgui_tables.cpp + ${imgui_SOURCE_DIR}/imgui_widgets.cpp + ${imgui_SOURCE_DIR}/imstb_rectpack.h + ${imgui_SOURCE_DIR}/imstb_textedit.h + ${imgui_SOURCE_DIR}/imstb_truetype.h + + ${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.h + ${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp + ) + target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR}) + target_compile_features(imgui PUBLIC cxx_std_11) + endif() +endif() + diff --git a/external/pure_doom/CMakeLists.txt b/external/pure_doom/CMakeLists.txt index 21c5070..de62f95 100644 --- a/external/pure_doom/CMakeLists.txt +++ b/external/pure_doom/CMakeLists.txt @@ -2,4 +2,9 @@ cmake_minimum_required(VERSION 3.24 FATAL_ERROR) add_library(PureDOOM "./PureDOOM/PureDOOM.h" "./PureDOOM.c") target_include_directories(PureDOOM SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}") +target_compile_definitions(PureDOOM + PRIVATE DOOM_IMPLEMENT_FILE_IO=1 + PRIVATE DOOM_IMPLEMENT_MALLOC=1 + #PRIVATE DOOM_IMPLEMENT_GETTIME=1 +) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 54d5b00..065dec3 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,4 +1,13 @@ cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR) -project(solanaceae) +add_library(plugin_doom_imgui SHARED + ./plugin_doom_imgui.cpp +) +target_compile_features(plugin_doom_imgui PUBLIC cxx_std_17) +target_link_libraries(plugin_doom_imgui PUBLIC + solDOOM_imgui + solanaceae_plugin +) + +######################################## diff --git a/plugins/plugin_doom_imgui.cpp b/plugins/plugin_doom_imgui.cpp new file mode 100644 index 0000000..c636da1 --- /dev/null +++ b/plugins/plugin_doom_imgui.cpp @@ -0,0 +1,69 @@ +#include + +#include + +#include +#include + +#include +#include +#include + +static std::unique_ptr g_doom_imgui = nullptr; + +constexpr const char* plugin_name = "DOOMImGui"; + +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* imguic = PLUG_RESOLVE_INSTANCE_VERSIONED(ImGuiContext, ImGui::GetVersion()); + auto* tu = PLUG_RESOLVE_INSTANCE(TextureUploaderI); + + ImGui::SetCurrentContext(imguic); + + // static store, could be anywhere tho + // construct with fetched dependencies + g_doom_imgui = std::make_unique(*tu); + + // register types + PLUG_PROVIDE_INSTANCE(DoomIMGUI, plugin_name, g_doom_imgui.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_doom_imgui.reset(); +} + +SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float) { + return std::numeric_limits::max(); +} + +SOLANA_PLUGIN_EXPORT float solana_plugin_render(float time_delta) { + return g_doom_imgui->render(time_delta); +} + +} // extern C + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5957e13..20ed101 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,8 +15,7 @@ add_library(solDOOM ) target_include_directories(solDOOM PUBLIC .) -#target_compile_features(solanaceae_llama-cpp-web PRIVATE cxx_std_20) -#target_compile_features(solanaceae_llama-cpp-web INTERFACE cxx_std_17) +target_compile_features(solDOOM PUBLIC cxx_std_17) target_link_libraries(solDOOM PUBLIC PureDOOM #httplib::httplib @@ -27,35 +26,14 @@ target_link_libraries(solDOOM PUBLIC ######################################### -#add_executable(test1 - #test1.cpp -#) +add_library(solDOOM_imgui + ./solanaceae/doom_imgui.hpp + ./solanaceae/doom_imgui.cpp +) -#target_link_libraries(test1 PUBLIC - #solanaceae_llama-cpp-web -#) - -######################################### - -#add_library(solanaceae_rpbot - #./solanaceae/rpbot/message_prompt_builder.hpp - #./solanaceae/rpbot/message_prompt_builder.cpp - - #./solanaceae/rpbot/rpbot.hpp - #./solanaceae/rpbot/rpbot_states.hpp - #./solanaceae/rpbot/rpbot.cpp - #./solanaceae/rpbot/rpbot_commands.cpp -#) - -#target_include_directories(solanaceae_rpbot PUBLIC .) -#target_compile_features(solanaceae_rpbot PRIVATE cxx_std_20) -#target_compile_features(solanaceae_rpbot INTERFACE cxx_std_17) -#target_link_libraries(solanaceae_rpbot PUBLIC - #solanaceae_util - #solanaceae_message3 - - #solanaceae_llama-cpp-web - - #fmt::fmt # TODO: switch to header only? -#) +target_include_directories(solDOOM_imgui PUBLIC .) +target_link_libraries(solDOOM_imgui PUBLIC + solDOOM + imgui +) diff --git a/src/solanaceae/doom.cpp b/src/solanaceae/doom.cpp index a781627..17d0e20 100644 --- a/src/solanaceae/doom.cpp +++ b/src/solanaceae/doom.cpp @@ -4,9 +4,46 @@ #include +#include +#include + +#include + +void my_doom_print(const char* str) { + std::printf("%s", str); +} + +// evil global +static volatile double g_time {0}; + +void my_doom_gettime(int* sec, int* usec) { + const int tmp_sec = g_time; // cast to full sec + if (sec != nullptr) { + *sec = tmp_sec; + } + if (usec != nullptr) { + const float rest_time = g_time - tmp_sec; + *usec = rest_time * 1'000 * 1'000; + } +} + +//static const char* doom_argv[] { + //"self.exe", + //"-timedemo", + //"", +//}; + Doom::Doom( TextureUploaderI& tu ) : _tu(tu) { + doom_set_getenv(&std::getenv); + + doom_set_print(&my_doom_print); + + // TODO: replace this with exception? + doom_set_exit(&std::exit); + + doom_set_gettime(&my_doom_gettime); // Change default bindings to modern doom_set_default_int("key_up", DOOM_KEY_W); @@ -16,8 +53,11 @@ Doom::Doom( doom_set_default_int("key_use", DOOM_KEY_E); doom_set_default_int("mouse_move", 0); // Mouse will not move forward + // does not actually work doom_set_resolution(_width, _height); + // HATE + //doom_init(2, const_cast(doom_argv), 0); doom_init(0, nullptr, 0); std::vector tmp_vec(4 * _width * _height, 0x00); // the api requires data for texture creation @@ -31,6 +71,8 @@ Doom::~Doom(void) { } float Doom::render(float time_delta) { + g_time += time_delta; + doom_update(); const uint8_t* new_image = doom_get_framebuffer(4); diff --git a/src/solanaceae/doom_imgui.cpp b/src/solanaceae/doom_imgui.cpp new file mode 100644 index 0000000..127b1de --- /dev/null +++ b/src/solanaceae/doom_imgui.cpp @@ -0,0 +1,25 @@ +#include "./doom_imgui.hpp" + +#include + +DoomIMGUI::DoomIMGUI( + TextureUploaderI& tu +) : _doom(tu) { +} + +DoomIMGUI::~DoomIMGUI(void) { +} + +float DoomIMGUI::render(float time_delta) { + // tick doom either way + // while this is computing, and as such could be run in tick(), its still rendering + const float doom_interval = _doom.render(time_delta); + + if (ImGui::Begin("doom")) { + ImGui::Image(reinterpret_cast(_doom.getTexID()), {320, 200}); + } + ImGui::End(); + + return doom_interval; +} + diff --git a/src/solanaceae/doom_imgui.hpp b/src/solanaceae/doom_imgui.hpp new file mode 100644 index 0000000..ddeaac5 --- /dev/null +++ b/src/solanaceae/doom_imgui.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "./doom.hpp" + +class DoomIMGUI { + // inherit instead? + Doom _doom; + + public: + DoomIMGUI( + TextureUploaderI& tu + ); + ~DoomIMGUI(void); + + // render imgui + float render(float time_delta); + + public: // custom doom api + uint64_t getTexID(void); +}; +