minimal lib (untested)
This commit is contained in:
parent
8c797673ca
commit
74ef90e84b
26
.gitignore
vendored
Normal file
26
.gitignore
vendored
Normal file
@ -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
|
2
external/pure_doom/CMakeLists.txt
vendored
2
external/pure_doom/CMakeLists.txt
vendored
@ -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}")
|
||||
|
||||
|
2
external/pure_doom/PureDOOM.c
vendored
Normal file
2
external/pure_doom/PureDOOM.c
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#define DOOM_IMPLEMENTATION
|
||||
#include "./PureDOOM/PureDOOM.h"
|
4
plugins/CMakeLists.txt
Normal file
4
plugins/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)
|
||||
|
||||
project(solanaceae)
|
||||
|
61
src/CMakeLists.txt
Normal file
61
src/CMakeLists.txt
Normal file
@ -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?
|
||||
#)
|
||||
|
45
src/solanaceae/doom.cpp
Normal file
45
src/solanaceae/doom.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "./doom.hpp"
|
||||
|
||||
#include <PureDOOM/PureDOOM.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
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<uint8_t> 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;
|
||||
}
|
||||
|
65
src/solanaceae/doom.hpp
Normal file
65
src/solanaceae/doom.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include "./texture_uploader.hpp"
|
||||
|
||||
#include <PureDOOM/PureDOOM.h>
|
||||
|
||||
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);
|
||||
|
||||
};
|
||||
|
30
src/solanaceae/texture_uploader.hpp
Normal file
30
src/solanaceae/texture_uploader.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user