From 74ef90e84b38299b00c5bed7050e73fa6331ba0e Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 8 Mar 2024 22:55:34 +0100 Subject: [PATCH] minimal lib (untested) --- .gitignore | 26 ++++++++++++ external/pure_doom/CMakeLists.txt | 2 +- external/pure_doom/PureDOOM.c | 2 + plugins/CMakeLists.txt | 4 ++ src/CMakeLists.txt | 61 +++++++++++++++++++++++++++ src/solanaceae/doom.cpp | 45 ++++++++++++++++++++ src/solanaceae/doom.hpp | 65 +++++++++++++++++++++++++++++ src/solanaceae/texture_uploader.hpp | 30 +++++++++++++ 8 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 external/pure_doom/PureDOOM.c create mode 100644 plugins/CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/solanaceae/doom.cpp create mode 100644 src/solanaceae/doom.hpp create mode 100644 src/solanaceae/texture_uploader.hpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..56f48bf --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +.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 diff --git a/external/pure_doom/CMakeLists.txt b/external/pure_doom/CMakeLists.txt index 86e2004..21c5070 100644 --- a/external/pure_doom/CMakeLists.txt +++ b/external/pure_doom/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.24 FATAL_ERROR) -add_library(PureDOOM INTERFACE "./PureDOOM/PureDOOM.h") +add_library(PureDOOM "./PureDOOM/PureDOOM.h" "./PureDOOM.c") target_include_directories(PureDOOM SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/external/pure_doom/PureDOOM.c b/external/pure_doom/PureDOOM.c new file mode 100644 index 0000000..8f8596b --- /dev/null +++ b/external/pure_doom/PureDOOM.c @@ -0,0 +1,2 @@ +#define DOOM_IMPLEMENTATION +#include "./PureDOOM/PureDOOM.h" diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt new file mode 100644 index 0000000..54d5b00 --- /dev/null +++ b/plugins/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR) + +project(solanaceae) + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..5957e13 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,61 @@ +cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR) + +project(solanaceae) + +# we need: +# - texture uploader (refactor from tomato with streaming) +# - netcode abstraction +# - tox netcode impl? (share with toxic games?) +# - imgui embedded window an inputs? +# - pure doom + +add_library(solDOOM + ./solanaceae/doom.hpp + ./solanaceae/doom.cpp +) + +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_link_libraries(solDOOM PUBLIC + PureDOOM + #httplib::httplib + #nlohmann_json::nlohmann_json + + #solanaceae_util +) + +######################################### + +#add_executable(test1 + #test1.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? +#) + diff --git a/src/solanaceae/doom.cpp b/src/solanaceae/doom.cpp new file mode 100644 index 0000000..a781627 --- /dev/null +++ b/src/solanaceae/doom.cpp @@ -0,0 +1,45 @@ +#include "./doom.hpp" + +#include + +#include + +Doom::Doom( + TextureUploaderI& tu +) : _tu(tu) { + + // Change default bindings to modern + doom_set_default_int("key_up", DOOM_KEY_W); + doom_set_default_int("key_down", DOOM_KEY_S); + doom_set_default_int("key_strafeleft", DOOM_KEY_A); + doom_set_default_int("key_straferight", DOOM_KEY_D); + doom_set_default_int("key_use", DOOM_KEY_E); + doom_set_default_int("mouse_move", 0); // Mouse will not move forward + + doom_set_resolution(_width, _height); + + doom_init(0, nullptr, 0); + + std::vector tmp_vec(4 * _width * _height, 0x00); // the api requires data for texture creation + _render_texture = _tu.uploadRGBA(tmp_vec.data(), _width, _height, TextureUploaderI::NEAREST, TextureUploaderI::STREAMING); +} + +Doom::~Doom(void) { + // no reset? + //doom_ + _tu.destroy(_render_texture); +} + +float Doom::render(float time_delta) { + doom_update(); + + const uint8_t* new_image = doom_get_framebuffer(4); + _tu.updateRGBA(_render_texture, new_image, 4 * _width * _height); + + return 1.f/60.f; +} + +uint64_t Doom::getTexID(void) { + return _render_texture; +} + diff --git a/src/solanaceae/doom.hpp b/src/solanaceae/doom.hpp new file mode 100644 index 0000000..8155d90 --- /dev/null +++ b/src/solanaceae/doom.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include "./texture_uploader.hpp" + +#include + +class Doom { + TextureUploaderI& _tu; + uint32_t _width {320}; + uint32_t _height {200}; + uint64_t _render_texture {0}; + + public: + Doom( + TextureUploaderI& tu + ); + ~Doom(void); + + float render(float time_delta); + + public: // custom doom api + uint64_t getTexID(void); + +// since we dont have an abstraction for this, or wont know what to do with it +// these have to be called from the outside +//void doom_key_down(doom_key_t key); +//void doom_key_up(doom_key_t key); +//void doom_button_down(doom_button_t button); +//void doom_button_up(doom_button_t button); +//void doom_mouse_move(int delta_x, int delta_y); + +//void doom_set_default_int(const char* name, int value); +//void doom_set_default_string(const char* name, const char* value); + + +// TODO: do we implement these? +//typedef void(*doom_print_fn)(const char* str); +//typedef void*(*doom_malloc_fn)(int size); +//typedef void(*doom_free_fn)(void* ptr); +//typedef void*(*doom_open_fn)(const char* filename, const char* mode); +//typedef void(*doom_close_fn)(void* handle); +//typedef int(*doom_read_fn)(void* handle, void *buf, int count); +//typedef int(*doom_write_fn)(void* handle, const void *buf, int count); +//typedef int(*doom_seek_fn)(void* handle, int offset, doom_seek_t origin); +//typedef int(*doom_tell_fn)(void* handle); +//typedef int(*doom_eof_fn)(void* handle); +//typedef void(*doom_gettime_fn)(int* sec, int* usec); +//typedef void(*doom_exit_fn)(int code); +//typedef char*(*doom_getenv_fn)(const char* var); +//// set callbacks +//void doom_set_print(doom_print_fn print_fn); +//void doom_set_malloc(doom_malloc_fn malloc_fn, doom_free_fn free_fn); +//void doom_set_file_io(doom_open_fn open_fn, + //doom_close_fn close_fn, + //doom_read_fn read_fn, + //doom_write_fn write_fn, + //doom_seek_fn seek_fn, + //doom_tell_fn tell_fn, + //doom_eof_fn eof_fn); +//void doom_set_gettime(doom_gettime_fn gettime_fn); +//void doom_set_exit(doom_exit_fn exit_fn); +//void doom_set_getenv(doom_getenv_fn getenv_fn); + +}; + diff --git a/src/solanaceae/texture_uploader.hpp b/src/solanaceae/texture_uploader.hpp new file mode 100644 index 0000000..1c6668c --- /dev/null +++ b/src/solanaceae/texture_uploader.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +struct TextureUploaderI { + static constexpr const char* version {"2"}; + + enum Filter { + NEAREST, + LINEAR, + }; + + enum Access { + STATIC, + STREAMING, + // target? + }; + + virtual ~TextureUploaderI(void) {} + + virtual uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter = LINEAR, Access access = STATIC) = 0; + + // keeps width height filter + // TODO: wh instead of size? + virtual bool updateRGBA(uint64_t tex_id, const uint8_t* data, size_t size) = 0; + + virtual void destroy(uint64_t tex_id) = 0; +}; +