finish buggy dx11 code
This commit is contained in:
@@ -19,3 +19,6 @@ PRIVATE
|
||||
BasaltShared
|
||||
)
|
||||
|
||||
install(TARGETS BasaltPresenter
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
@@ -1,18 +1,67 @@
|
||||
#include "dll_loader.hpp"
|
||||
#include <basalt_char.hpp>
|
||||
#include <stdexcept>
|
||||
#include <filesystem>
|
||||
|
||||
#if defined(BASALT_OS_WINDOWS)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace Basalt::Presenter {
|
||||
|
||||
DllLoader::DllLoader(DllKind kind, const std::basic_string_view<BSCHAR> filename) {
|
||||
// TODO:
|
||||
// Add current executable location supports.
|
||||
// Add sub directories supports.
|
||||
// Fix file name terminal error.
|
||||
static std::filesystem::path get_executable() {
|
||||
#if defined(BASALT_OS_WINDOWS)
|
||||
m_Handle = LoadLibraryW(filename.data());
|
||||
wchar_t buffer[MAX_PATH];
|
||||
DWORD hr = GetModuleFileNameW(NULL, buffer, MAX_PATH);
|
||||
if (hr == 0) {
|
||||
throw std::runtime_error("Failed to get executable path");
|
||||
} else {
|
||||
return std::filesystem::path(buffer);
|
||||
}
|
||||
#else
|
||||
m_Handle = dlopen(filename.data(), RTLD_LAZY);
|
||||
char buffer[PATH_MAX];
|
||||
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
|
||||
if (len != -1) {
|
||||
buffer[len] = '\0';
|
||||
return std::filesystem::path(buffer);
|
||||
} else {
|
||||
throw std::runtime_error("Failed to get executable path");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
DllLoader::DllLoader(DllKind kind, const std::basic_string_view<BSCHAR> filename) {
|
||||
// Build DLL full path
|
||||
auto dll_path = get_executable().parent_path();
|
||||
dll_path /= BSTEXT("plugin");
|
||||
switch (kind) {
|
||||
case DllKind::Engine:
|
||||
dll_path /= BSTEXT("engine");
|
||||
break;
|
||||
case DllKind::Deliver:
|
||||
dll_path /= BSTEXT("deliver");
|
||||
break;
|
||||
case DllKind::ObjectLoader:
|
||||
dll_path /= BSTEXT("object_loader");
|
||||
break;
|
||||
case DllKind::AnimeLoader:
|
||||
dll_path /= BSTEXT("anime_loader");
|
||||
break;
|
||||
}
|
||||
dll_path /= filename;
|
||||
#if defined(BASALT_OS_WINDOWS)
|
||||
dll_path.replace_extension(BSTEXT(".dll"));
|
||||
#endif
|
||||
|
||||
// Load DLL
|
||||
#if defined(BASALT_OS_WINDOWS)
|
||||
m_Handle = LoadLibraryW(dll_path.wstring().c_str());
|
||||
#else
|
||||
m_Handle = dlopen(dll_path.string().c_str(), RTLD_LAZY);
|
||||
#endif
|
||||
// Check loaded DLL
|
||||
if (!m_Handle) throw std::runtime_error("Can not load given dynamic library.");
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,13 @@ namespace Basalt::Presenter {
|
||||
auto fct = (Fct) GetFunctionPointer(EXPOSE_FUNC_NAME);
|
||||
return fct();
|
||||
}
|
||||
template<typename T>
|
||||
void DestroyInstance(T* instance) {
|
||||
using Fct = void (*) (T*);
|
||||
constexpr char EXPOSE_FUNC_NAME[] = "BSDestroyInstance";
|
||||
auto fct = (Fct) GetFunctionPointer(EXPOSE_FUNC_NAME);
|
||||
fct(instance);
|
||||
}
|
||||
|
||||
private:
|
||||
Handle m_Handle;
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
#include "dll_loader.hpp"
|
||||
#include <basalt_char.hpp>
|
||||
#include <engine.hpp>
|
||||
|
||||
namespace Presenter = ::Basalt::Presenter;
|
||||
namespace Shared = ::Basalt::Shared;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
auto engine_dll = Presenter::DllLoader(Presenter::DllKind::Engine, BSTEXT("BasaltDirectX11Engine"));
|
||||
auto* engine = engine_dll.CreateInstance<Shared::Engine::IEngine>();
|
||||
Shared::Engine::EngineConfig engine_config{.is_headless = false, .title = BSTEXT("Fuck You"), .width = 800, .height = 600};
|
||||
engine->Startup(std::move(engine_config));
|
||||
|
||||
while (true) {
|
||||
engine->Tick();
|
||||
}
|
||||
|
||||
engine->Shutdown();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user