works, no input yet, but renders and loads wad

This commit is contained in:
Green Sky 2024-03-09 14:41:56 +01:00
parent 74ef90e84b
commit 3087e10c5e
No known key found for this signature in database
9 changed files with 226 additions and 51 deletions

3
.gitignore vendored
View File

@ -24,3 +24,6 @@ CMakeCache.txt
*.tox
imgui.ini
*.wad
*.WAD

View File

@ -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()

View File

@ -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
)

View File

@ -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
)
########################################

View File

@ -0,0 +1,69 @@
#include <solanaceae/plugin/solana_plugin_v1.h>
#include <solanaceae/doom_imgui.hpp>
#include <solanaceae/texture_uploader.hpp>
#include <imgui.h>
#include <memory>
#include <limits>
#include <iostream>
static std::unique_ptr<DoomIMGUI> 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<DoomIMGUI>(*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<float>::max();
}
SOLANA_PLUGIN_EXPORT float solana_plugin_render(float time_delta) {
return g_doom_imgui->render(time_delta);
}
} // extern C

View File

@ -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
)

View File

@ -4,9 +4,46 @@
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <iostream>
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<char**>(doom_argv), 0);
doom_init(0, nullptr, 0);
std::vector<uint8_t> 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);

View File

@ -0,0 +1,25 @@
#include "./doom_imgui.hpp"
#include <imgui.h>
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<void*>(_doom.getTexID()), {320, 200});
}
ImGui::End();
return doom_interval;
}

View File

@ -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);
};